I need help interpreting this assembly code.
Given that it resembles a triply-nested if-block. Let num=0x708, flag=-1;
The first condition is straightforward, if(num& 0x3 == 0)
. However, the next second and third conditions are lengthy; the operations are the same, but the numbers are different.
Is there anything meaningful these two conditions do, or are they just a litany of random commands?
<+0>: push %rbp
<+1>: mov %rsp,%rbp
<+4>: movl $0x708,-0x8(%rbp)
<+11>: movl $0xffffffff,-0x4(%rbp)
<+18>: mov -0x8(%rbp),%eax
<+21>: and $0x3,%eax
<+24>: test %eax,%eax <====first condition
<+26>: jne <main+128>
<+28>: mov -0x8(%rbp),%ecx
<+31>: mov $0x51eb851f,%edx
<+36>: mov %ecx,%eax
<+38>: imul %edx
<+40>: sar $0x5,%edx
<+43>: mov %ecx,%eax
<+45>: sar $0x1f,%eax
<+48>: sub %eax,%edx
<+50>: mov %edx,%eax
<+52>: imul $0x64,%eax,%eax
<+55>: sub %eax,%ecx
<+57>: mov %ecx,%eax
<+59>: test %eax,%eax <====second condition
<+61>: jne <main+119>
<+63>: mov -0x8(%rbp),%ecx
<+66>: mov $0x51eb851f,%edx
<+71>: mov %ecx,%eax
<+73>: imul %edx
<+75>: sar $0x7,%edx
<+78>: mov %ecx,%eax
<+80>: sar $0x1f,%eax
<+83>: sub %eax,%edx
<+85>: mov %edx,%eax
<+87>: imul $0x190,%eax,%eax
<+93>: sub %eax,%ecx
<+95>: mov %ecx,%eax
<+97>: test %eax,%eax <========third condition
<+99>: jne <main+110>
…