I'm trying to learn more about the x86 assembly. I have the assembly code of a mystery function. All I know about this function is that it must return an integer and has an integer as an argument:
int mystery(int n){}
The assembly for this function is
0000000000400526 <mystery_util>:
400526: 89 f8 mov %edi,%eax
400528: d1 e8 shr %eax
40052a: 83 e7 01 and $0x1,%edi
40052d: 01 f8 add %edi,%eax
40052f: c3 retq
0000000000400530 <mystery>:
400530: 89 f8 mov %edi,%eax
400532: 8d 3c fd 00 00 00 00 lea 0x0(,%rdi,8),%edi
400539: 29 c7 sub %eax,%edi
40053b: 83 c7 04 add $0x4,%edi
40053e: e8 e3 ff ff ff callq 400526 <mystery_util>
400543: f3 c3 repz retq
I don't understand how to write this as a C function. If there is a callq wouldn't it mean there are 2 different functions?
I'm trying to write this out in one function that returns an integer. I see how it could return a boolean but can there be a way to return an integer?