I have the following code:
0000000000400526 <main>:
400526: 55 push rbp
400527: 48 89 e5 mov rbp,rsp
40052a: 48 83 ec 20 sub rsp,0x20
40052e: 89 7d ec mov DWORD PTR [rbp-0x14],edi
400531: 48 89 75 e0 mov QWORD PTR [rbp-0x20],rsi
400535: c7 45 f4 4d 3c 2b 1a mov DWORD PTR [rbp-0xc],0x1a2b3c4d
40053c: 48 8d 45 f4 lea rax,[rbp-0xc]
400540: 48 89 45 f8 mov QWORD PTR [rbp-0x8],rax
400544: c7 45 f0 00 00 00 00 mov DWORD PTR [rbp-0x10],0x0
40054b: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
40054f: 0f b6 00 movzx eax,BYTE PTR [rax]
400552: 0f be c0 movsx eax,al
400555: c1 e0 18 shl eax,0x18
400558: 89 c2 mov edx,eax
40055a: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
40055e: 48 83 c0 01 add rax,0x1
400562: 0f b6 00 movzx eax,BYTE PTR [rax]
400565: 0f be c0 movsx eax,al
400568: c1 e0 10 shl eax,0x10
40056b: 09 c2 or edx,eax
40056d: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
400571: 48 83 c0 02 add rax,0x2
400575: 0f b6 00 movzx eax,BYTE PTR [rax]
400578: 0f be c0 movsx eax,al
40057b: c1 e0 08 shl eax,0x8
40057e: 09 c2 or edx,eax
400580: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
400584: 48 83 c0 03 add rax,0x3
400588: 0f b6 00 movzx eax,BYTE PTR [rax]
40058b: 0f be c0 movsx eax,al
40058e: 09 d0 or eax,edx
400590: 89 45 f0 mov DWORD PTR [rbp-0x10],eax
400593: 8b 55 f0 mov edx,DWORD PTR [rbp-0x10]
400596: 8b 45 f4 mov eax,DWORD PTR [rbp-0xc]
400599: 89 c6 mov esi,eax
40059b: bf 44 06 40 00 mov edi,0x400644 ; "a = %#x\nb = %#x\n"
4005a0: b8 00 00 00 00 mov eax,0x0
4005a5: e8 56 fe ff ff call 400400 <printf@plt>
4005aa: b8 00 00 00 00 mov eax,0x0
4005af: c9 leave
4005b0: c3 ret
4005b1: 66 2e 0f 1f 84 00 00 nop WORD PTR cs:[rax+rax*1+0x0]
4005b8: 00 00 00
4005bb: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0]
This is a segment of x64 assembly code, and I would like to rewrite this code into C. I've been reading Assembly books all day, and I'm still having some difficulty. I just want to understand what this code is doing. From messing around, I think that it performs some operations on an int (that's why I think the DWORD is there) and a long (that's why the QWORD is there). I think that this is true because I recompiled C code with those data structures and those words appeared in the Assembly equivalent, but I could be wrong.
Any help is appreciated in decoding this code.'
For Amigag: second segment of code
0000000000400966 <my_tolower>:
400966: 55 push rbp
400967: 48 89 e5 mov rbp,rsp
40096a: 48 89 7d f8 mov QWORD PTR [rbp-0x8],rdi
40096e: eb 2d jmp 40099d <my_tolower+0x37>
400970: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
400974: 0f b6 00 movzx eax,BYTE PTR [rax]
400977: 3c 40 cmp al,0x40
400979: 7e 1d jle 400998 <my_tolower+0x32>
40097b: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
40097f: 0f b6 00 movzx eax,BYTE PTR [rax]
400982: 3c 5a cmp al,0x5a
400984: 7f 12 jg 400998 <my_tolower+0x32>
400986: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
40098a: 0f b6 00 movzx eax,BYTE PTR [rax]
40098d: 83 c0 20 add eax,0x20
400990: 89 c2 mov edx,eax
400992: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
400996: 88 10 mov BYTE PTR [rax],dl
400998: 48 83 45 f8 01 add QWORD PTR [rbp-0x8],0x1
40099d: 48 8b 45 f8 mov rax,QWORD PTR [rbp-0x8]
4009a1: 0f b6 00 movzx eax,BYTE PTR [rax]
4009a4: 84 c0 test al,al
4009a6: 75 c8 jne 400970 <my_tolower+0xa>
4009a8: 90 nop
4009a9: 5d pop rbp
4009aa: c3 ret
4009ab: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0]