Question
Can you write the corresponding C code for this function. it can go in the function below Here are some input and outputs they are
Can you write the corresponding C code for this function. it can go in the function below Here are some input and outputs they are from 1-30 inclusive
Input 1
Output 4
-----------
Input 5
Output 7
-----------
Input 10
Output 30
-----------
Input 23
Output 69
-----------
Input 30
Output 90
the function has to be derived from the assebly as long as the C code output matches the outputs as shown it will do
unsigned int f5(unsigned int x) { }
00000000004007e4 :
4007e4: 48 83 ec 28 sub $0x28,%rsp
4007e8: 89 7c 24 0c mov %edi,0xc(%rsp)
4007ec: 83 7c 24 0c 05 cmpl $0x5,0xc(%rsp)
4007f1: 77 6f ja 400862
4007f3: 8b 44 24 0c mov 0xc(%rsp),%eax
4007f7: 48 8b 04 c5 30 0a 40 mov 0x400a30(,%rax,8),%rax
4007fe: 00
4007ff: ff e0 jmpq *%rax
400801: 8b 44 24 0c mov 0xc(%rsp),%eax
400805: c1 e8 02 shr $0x2,%eax
400808: 89 44 24 1c mov %eax,0x1c(%rsp)
40080c: eb 63 jmp 400871
40080e: 8b 44 24 0c mov 0xc(%rsp),%eax
400812: c1 e0 02 shl $0x2,%eax
400815: 89 44 24 1c mov %eax,0x1c(%rsp)
400819: eb 56 jmp 400871
40081b: 8b 44 24 0c mov 0xc(%rsp),%eax
40081f: 8d 50 01 lea 0x1(%rax),%edx
400822: 89 54 24 0c mov %edx,0xc(%rsp)
400826: 89 44 24 1c mov %eax,0x1c(%rsp)
40082a: eb 45 jmp 400871
40082c: 8b 44 24 0c mov 0xc(%rsp),%eax
400830: 89 c7 mov %eax,%edi
400832: b8 00 00 00 00 mov $0x0,%eax
400837: e8 3e 00 00 00 callq 40087a
40083c: 89 44 24 1c mov %eax,0x1c(%rsp)
400840: eb 2f jmp 400871
400842: 8b 44 24 0c mov 0xc(%rsp),%eax
400846: 89 c7 mov %eax,%edi
400848: b8 00 00 00 00 mov $0x0,%eax
40084d: e8 55 00 00 00 callq 4008a7
400852: 89 44 24 1c mov %eax,0x1c(%rsp)
400856: eb 19 jmp 400871
400858: c7 44 24 1c 07 00 00 movl $0x7,0x1c(%rsp)
40085f: 00
400860: eb 0f jmp 400871
400862: 8b 54 24 0c mov 0xc(%rsp),%edx
400866: 89 d0 mov %edx,%eax
400868: 01 c0 add %eax,%eax
40086a: 01 d0 add %edx,%eax
40086c: 89 44 24 1c mov %eax,0x1c(%rsp)
400870: 90 nop
400871: 8b 44 24 1c mov 0x1c(%rsp),%eax
400875: 48 83 c4 28 add $0x28,%rsp
400879: c3 retq
000000000040087a :
40087a: 89 7c 24 ec mov %edi,-0x14(%rsp)
40087e: c7 44 24 fc 01 00 00 movl $0x1,-0x4(%rsp)
400885: 00
400886: eb 13 jmp 40089b
400888: 8b 54 24 fc mov -0x4(%rsp),%edx
40088c: 8b 44 24 ec mov -0x14(%rsp),%eax
400890: 01 d0 add %edx,%eax
400892: 89 44 24 fc mov %eax,-0x4(%rsp)
400896: 83 6c 24 ec 01 subl $0x1,-0x14(%rsp)
40089b: 83 7c 24 ec 00 cmpl $0x0,-0x14(%rsp)
4008a0: 75 e6 jne 400888
4008a2: 8b 44 24 fc mov -0x4(%rsp),%eax
4008a6: c3 retq
00000000004008a7 :
4008a7: 89 7c 24 ec mov %edi,-0x14(%rsp)
4008ab: c7 44 24 fc 00 00 00 movl $0x0,-0x4(%rsp)
4008b2: 00
4008b3: eb 11 jmp 4008c6
4008b5: 8b 44 24 ec mov -0x14(%rsp),%eax
4008b9: 83 e0 01 and $0x1,%eax
4008bc: 89 c1 mov %eax,%ecx
4008be: d3 64 24 fc shll %cl,-0x4(%rsp)
4008c2: d1 6c 24 ec shrl -0x14(%rsp)
4008c6: 83 7c 24 ec 00 cmpl $0x0,-0x14(%rsp)
4008cb: 75 e8 jne 4008b5
4008cd: 8b 44 24 fc mov -0x4(%rsp),%eax
4008d1: c3 retq
4008d2: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
4008d9: 00 00 00
4008dc: 0f 1f 40 00 nopl 0x0(%rax)
00000000004007e4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started