Its actually not that complicated
input_player1_a_btn="" input_player1_b_btn="" input_player1_x_btn="" input_player1_y_btn=""
to your /opt/retropie/configs/%system%/retroarch.cfg
(for snes /opt/retropie/configs/snes/retroarch.cfg)
That overwrites the button layout for the first player.
For the second player you have to obviously replace the 1 with a 2.
And of course you have to add the corresponding button number in between the quotation marks.