decompiled_code:
__int64 __fastcall unseize_task(__pid_t pid, unsigned int a2)
{
print_on_level(4LL, "\tUnseizing %d into %d\n", (unsigned int)pid, a2);
if ( a2 == 2 )
{
kill(pid, 9);
}
else if ( a2 == 3 )
{
kill(pid, 19);
}
else if ( a2 != 1 )
{
print_on_level(1LL, "Error (%s:%d): Unknown final state %d\n", "src/lib/ptrace.c", 31LL, a2);
}
return ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__pid_t pid, unsigned int a2)
{
print_on_level(4LL, "\tUnseizing %d into %d\n", (unsigned int)pid, a2);
if ( a2 == 2 )
{
kill(pid, 9);
}
else if ( a2 == 3 )
{
kill(pid, 19);
}
else if ( a2 != 1 )
{
print_on_level(1LL, "Error (%s:%d): Unknown final state %d\n", "src/lib/ptrace.c", 31LL, a2);
}
return ptrace(PTRACE_DETACH, (unsigned int)pid, 0LL, 0LL);
}

original_code:
int unseize_task(pid_t pid, int state)
{
 print_on_level((4), "\tUnseizing %d into %d\n", pid, state);
 if (state == 0x2)
  kill(pid, 9);
 else if (state == 0x3)
  kill(pid, 19);
 else if (state == 0x1)
                   ;
 else
  print_on_level((1), "Error (%s:%d): " "Unknown final state %d\n", "src/lib/ptrace.c", 31, state);
 return ptrace(PTRACE_DETACH, pid, ((void *)0), ((void *)0));
}

canonical_original_code:
int unseize_task(int pid, int state)
{
 print_on_level((4), "\tUnseizing %d into %d\n", pid, state);
 if (state == 0x2)
  kill(pid, 9);
 else if (state == 0x3)
  kill(pid, 19);
 else if (state == 0x1)
                   ;
 else
  print_on_level((1), "Error (%s:%d): " "Unknown final state %d\n", "src/lib/ptrace.c", 31, state);
 return ptrace(PTRACE_DETACH, pid, ((void *)0), ((void *)0));
}

variable_types: pid int

variable_types: state int


repo: cyrillos/compel

decompiled_code:
__int64 __fastcall seize_task(__pid_t pid)
{
__pid_t v1; // eax
unsigned int v2; // ebx
__int64 v3; // r8
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // r9
__int64 v7; // r8
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // rcx
__pid_t v11; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-ACh] BYREF
char v13; // [rsp+19h] [rbp-9Fh]

if ( (int)ptrace(PTRACE_SEIZE, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't seize task: %m\n", "src/lib/ptrace.c", 50LL, (unsigned int)pid);
return 0xFFFFFFFFLL;
}
if ( (int)ptrace(PTRACE_INTERRUPT, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't interrupt task: %m\n",
"src/lib/ptrace.c",
56LL,
(unsigned int)pid);
goto LABEL_12;
}
while ( 1 )
{
v1 = wait4(pid, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
v2 = v1;
if ( v1 < 0 )
{
v3 = (unsigned int)pid;
v4 = 63LL;
LABEL_11:
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't wait task: %m\n", "src/lib/ptrace.c", v4, v3);
goto LABEL_12;
}
if ( pid != v1 )
{
v6 = (unsigned int)v1;
v7 = (unsigned int)pid;
v8 = 68LL;
LABEL_15:
print_on_level(1LL, "Error (%s:%d): SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", v8, v7, v6);
goto LABEL_12;
}
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
v9 = (unsigned int)pid;
v10 = 73LL;
LABEL_17:
print_on_level(1LL, "Error (%s:%d): SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", v10, v9);
goto LABEL_12;
}
if ( (int)ptrace(PTRACE_GETSIGINFO, (unsigned int)pid, 0LL, (char *)&stat_loc.__iptr + 4) < 0 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't read signfo: %m\n",
"src/lib/ptrace.c",
79LL,
(unsigned int)pid);
goto LABEL_12;
}
if ( v13 == (char)0x80 )
break;
if ( ptrace(PTRACE_CONT, (unsigned int)pid, 0LL, SHIDWORD(stat_loc.__iptr)) )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't continue signal handling. Aborting: %m\n",
"src/lib/ptrace.c",
91LL,
(unsigned int)pid);
LABEL_12:
unseize_task(pid, 3u);
return 0xFFFFFFFFLL;
}
}
result = 1LL;
if ( HIDWORD(stat_loc.__iptr) == 5 )
return result;
if ( HIDWORD(stat_loc.__iptr) != 19 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: unsupported stop signal %d\n",
"src/lib/ptrace.c",
132LL,
(unsigned int)pid,
HIDWORD(stat_loc.__iptr));
goto LABEL_12;
}
if ( (unsigned int)ptrace(PTRACE_CONT, (unsigned int)pid, 0LL, 0LL) )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: unable to start process: %m\n",
"src/lib/ptrace.c",
109LL,
(unsigned int)pid);
goto LABEL_12;
}
v11 = wait4(pid, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
if ( v11 < 0 )
{
v3 = (unsigned int)pid;
v4 = 115LL;
goto LABEL_11;
}
if ( pid != v11 )
{
v6 = (unsigned int)v11;
v7 = v2;
v8 = 120LL;
goto LABEL_15;
}
result = 3LL;
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
v9 = v2;
v10 = 125LL;
goto LABEL_17;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__pid_t pid)
{
__pid_t v1; // eax
unsigned int v2; // ebx
__int64 v3; // r8
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // r9
__int64 v7; // r8
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // rcx
__pid_t v11; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-ACh] BYREF
char v13; // [rsp+19h] [rbp-9Fh]

if ( (int)ptrace(PTRACE_SEIZE, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't seize task: %m\n", "src/lib/ptrace.c", 50LL, (unsigned int)pid);
return 0xFFFFFFFFLL;
}
if ( (int)ptrace(PTRACE_INTERRUPT, (unsigned int)pid, 0LL, 0LL) < 0 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't interrupt task: %m\n",
"src/lib/ptrace.c",
56LL,
(unsigned int)pid);
goto LABEL_12;
}
while ( 1 )
{
v1 = wait4(pid, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
v2 = v1;
if ( v1 < 0 )
{
v3 = (unsigned int)pid;
v4 = 63LL;
LABEL_11:
print_on_level(1LL, "Error (%s:%d): SEIZE %d: can't wait task: %m\n", "src/lib/ptrace.c", v4, v3);
goto LABEL_12;
}
if ( pid != v1 )
{
v6 = (unsigned int)v1;
v7 = (unsigned int)pid;
v8 = 68LL;
LABEL_15:
print_on_level(1LL, "Error (%s:%d): SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", v8, v7, v6);
goto LABEL_12;
}
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
v9 = (unsigned int)pid;
v10 = 73LL;
LABEL_17:
print_on_level(1LL, "Error (%s:%d): SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", v10, v9);
goto LABEL_12;
}
if ( (int)ptrace(PTRACE_GETSIGINFO, (unsigned int)pid, 0LL, (char *)&stat_loc.__iptr + 4) < 0 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't read signfo: %m\n",
"src/lib/ptrace.c",
79LL,
(unsigned int)pid);
goto LABEL_12;
}
if ( v13 == (char)0x80 )
break;
if ( ptrace(PTRACE_CONT, (unsigned int)pid, 0LL, SHIDWORD(stat_loc.__iptr)) )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: can't continue signal handling. Aborting: %m\n",
"src/lib/ptrace.c",
91LL,
(unsigned int)pid);
LABEL_12:
func0(pid, 3u);
return 0xFFFFFFFFLL;
}
}
result = 1LL;
if ( HIDWORD(stat_loc.__iptr) == 5 )
return result;
if ( HIDWORD(stat_loc.__iptr) != 19 )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: unsupported stop signal %d\n",
"src/lib/ptrace.c",
132LL,
(unsigned int)pid,
HIDWORD(stat_loc.__iptr));
goto LABEL_12;
}
if ( (unsigned int)ptrace(PTRACE_CONT, (unsigned int)pid, 0LL, 0LL) )
{
print_on_level(
1LL,
"Error (%s:%d): SEIZE %d: unable to start process: %m\n",
"src/lib/ptrace.c",
109LL,
(unsigned int)pid);
goto LABEL_12;
}
v11 = wait4(pid, (__WAIT_STATUS)&stat_loc, 0x40000000, 0LL);
if ( v11 < 0 )
{
v3 = (unsigned int)pid;
v4 = 115LL;
goto LABEL_11;
}
if ( pid != v11 )
{
v6 = (unsigned int)v11;
v7 = v2;
v8 = 120LL;
goto LABEL_15;
}
result = 3LL;
if ( LOBYTE(stat_loc.__uptr) != 127 )
{
v9 = v2;
v10 = 125LL;
goto LABEL_17;
}
return result;
}

original_code:
int seize_task(pid_t pid)
{
 int status, ret;
 siginfo_t si;
 ret = ptrace(PTRACE_SEIZE, pid, ((void *)0), 0);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't seize task" ": %m\n", "src/lib/ptrace.c", 50, pid);
  return -1;
 }
 ret = ptrace(PTRACE_INTERRUPT, pid, ((void *)0), ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't interrupt task" ": %m\n", "src/lib/ptrace.c", 56, pid);
  goto err;
 }
try_again:
 ret = wait4(pid, &status, 0x40000000, ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 63, pid);
  goto err;
 }
 if (ret != pid) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 68, pid, ret);
  goto err;
 }
 if (!(((status) & 0xff) == 0x7f)) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 73, pid);
  goto err;
 }
 ret = ptrace(PTRACE_GETSIGINFO, pid, ((void *)0), &si);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't read signfo" ": %m\n", "src/lib/ptrace.c", 79, pid);
  goto err;
 }
 if ((((si.si_code) & 0xFFFF) >> 8) != 128) {
  if (ptrace(PTRACE_CONT, pid, ((void *)0), (void *)(unsigned long)si.si_signo)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't continue signal handling. Aborting" ": %m\n", "src/lib/ptrace.c", 91, pid);
   goto err;
  }
  goto try_again;
 }
 if (si.si_signo == 5)
  return 0x1;
 else if (si.si_signo == 19) {
  ret = ptrace(PTRACE_CONT, pid, 0, 0);
  if (ret) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: unable to start process" ": %m\n", "src/lib/ptrace.c", 109, pid);
   goto err;
  }
  ret = wait4(pid, &status, 0x40000000, ((void *)0));
  if (ret < 0) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 115, pid);
   goto err;
  }
  if (ret != pid) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 120, pid, ret);
   goto err;
  }
  if (!(((status) & 0xff) == 0x7f)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 125, pid);
   goto err;
  }
  return 0x3;
 }
 print_on_level((1), "Error (%s:%d): " "SEIZE %d: unsupported stop signal %d\n", "src/lib/ptrace.c", 132, pid, si.si_signo);
err:
 unseize_task(pid, 0x3);
 return -1;
}

canonical_original_code:
int seize_task(int pid)
{
 int status; int ret;
 struct siginfo_t si;
 ret = ptrace(PTRACE_SEIZE, pid, ((void *)0), 0);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't seize task" ": %m\n", "src/lib/ptrace.c", 50, pid);
  return -1;
 }
 ret = ptrace(PTRACE_INTERRUPT, pid, ((void *)0), ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't interrupt task" ": %m\n", "src/lib/ptrace.c", 56, pid);
  goto err;
 }
try_again:
 ret = wait4(pid, &status, 0x40000000, ((void *)0));
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 63, pid);
  goto err;
 }
 if (ret != pid) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 68, pid, ret);
  goto err;
 }
 if (!(((status) & 0xff) == 0x7f)) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 73, pid);
  goto err;
 }
 ret = ptrace(PTRACE_GETSIGINFO, pid, ((void *)0), &si);
 if (ret < 0) {
  print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't read signfo" ": %m\n", "src/lib/ptrace.c", 79, pid);
  goto err;
 }
 if ((((si.si_code) & 0xFFFF) >> 8) != 128) {
  if (ptrace(PTRACE_CONT, pid, ((void *)0), (void *)(unsigned long)si.si_signo)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't continue signal handling. Aborting" ": %m\n", "src/lib/ptrace.c", 91, pid);
   goto err;
  }
  goto try_again;
 }
 if (si.si_signo == 5)
  return 0x1;
 else if (si.si_signo == 19) {
  ret = ptrace(PTRACE_CONT, pid, 0, 0);
  if (ret) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: unable to start process" ": %m\n", "src/lib/ptrace.c", 109, pid);
   goto err;
  }
  ret = wait4(pid, &status, 0x40000000, ((void *)0));
  if (ret < 0) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: can't wait task" ": %m\n", "src/lib/ptrace.c", 115, pid);
   goto err;
  }
  if (ret != pid) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: wrong task attached (%d)\n", "src/lib/ptrace.c", 120, pid, ret);
   goto err;
  }
  if (!(((status) & 0xff) == 0x7f)) {
   print_on_level((1), "Error (%s:%d): " "SEIZE %d: task not stopped after seize\n", "src/lib/ptrace.c", 125, pid);
   goto err;
  }
  return 0x3;
 }
 print_on_level((1), "Error (%s:%d): " "SEIZE %d: unsupported stop signal %d\n", "src/lib/ptrace.c", 132, pid, si.si_signo);
err:
 unseize_task(pid, 0x3);
 return -1;
}

variable_types: status int

variable_types: ret int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }

return_type: int

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 __fastcall ptrace_peek_area(unsigned int a1, __int64 *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rcx
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rax

if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v4 = a4 >> 3;
if ( !v4 )
return 0LL;
v6 = a3 + 8 * v4;
v7 = a3;
do
{
v8 = ptrace(PTRACE_PEEKDATA, a1, v7, 0LL);
*a2 = v8;
if ( v8 == 0xFFFFFFFFLL && *_errno_location() )
return 4294967294LL;
v7 += 8LL;
++a2;
}
while ( v7 != v6 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rcx
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rax

if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v4 = a4 >> 3;
if ( !v4 )
return 0LL;
v6 = a3 + 8 * v4;
v7 = a3;
do
{
v8 = ptrace(PTRACE_PEEKDATA, a1, v7, 0LL);
*a2 = v8;
if ( v8 == 0xFFFFFFFFLL && *_errno_location() )
return 4294967294LL;
v7 += 8LL;
++a2;
}
while ( v7 != v6 );
return 0LL;
}

original_code:
int ptrace_peek_area(pid_t pid, void *dst, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *d = dst, *a = addr;
  d[w] = ptrace(PTRACE_PEEKDATA, pid, a + w, ((void *)0));
  if (d[w] == -1U && (*__errno_location ()))
   goto err;
 }
 return 0;
err:
 return -2;
}

canonical_original_code:
int ptrace_peek_area(int pid, void *dst, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *d = dst; unsigned long *a = addr;
  d[w] = ptrace(PTRACE_PEEKDATA, pid, a + w, ((void *)0));
  if (d[w] == -1U && (*__errno_location ()))
   goto err;
 }
 return 0;
err:
 return -2;
}

variable_types:
dst
void *

variable_types:
addr
void *

variable_types:
bytes
unsigned long

variable_types:
w
unsigned long

variable_types:
d
unsigned long *

variable_types:
a
unsigned long *


decompiled_code:
__int64 __fastcall ptrace_poke_area(unsigned int a1, _QWORD *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rcx
_QWORD *v5; // r13
_QWORD *v7; // rbx

if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v4 = a4 >> 3;
if ( !v4 )
return 0LL;
v5 = &a2[v4];
v7 = a2;
do
{
if ( ptrace(PTRACE_POKEDATA, a1, a3, *v7) )
return 4294967294LL;
++v7;
a3 += 8LL;
}
while ( v7 != v5 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, _QWORD *a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rcx
_QWORD *v5; // r13
_QWORD *v7; // rbx

if ( (a4 & 7) != 0 )
return 0xFFFFFFFFLL;
v4 = a4 >> 3;
if ( !v4 )
return 0LL;
v5 = &a2[v4];
v7 = a2;
do
{
if ( ptrace(PTRACE_POKEDATA, a1, a3, *v7) )
return 4294967294LL;
++v7;
a3 += 8LL;
}
while ( v7 != v5 );
return 0LL;
}

original_code:
int ptrace_poke_area(pid_t pid, void *src, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *s = src, *a = addr;
  if (ptrace(PTRACE_POKEDATA, pid, a + w, s[w]))
   goto err;
 }
 return 0;
err:
 return -2;
}

canonical_original_code:
int ptrace_poke_area(int pid, void *src, void *addr, unsigned long bytes)
{
 unsigned long w;
 if (bytes & (sizeof(long) - 1))
  return -1;
 for (w = 0; w < bytes / sizeof(long); w++) {
  unsigned long *s = src; unsigned long *a = addr;
  if (ptrace(PTRACE_POKEDATA, pid, a + w, s[w]))
   goto err;
 }
 return 0;
err:
 return -2;
}

variable_types:
src
void *

variable_types:
s
unsigned long *


decompiled_code:
__int64 __fastcall ptrace_swap_area(unsigned int a1, __int64 a2, _QWORD *a3, unsigned __int64 a4)
{
void *v6; // rsp
unsigned int v7; // er13
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
void *dest; // [rsp+8h] [rbp-38h]

dest = a3;
v6 = alloca(a4 + 8);
if ( (unsigned int)ptrace_peek_area(a1, &v9, a2, a4) )
return -1;
v7 = ptrace_poke_area(a1, a3, a2, a4);
if ( !v7 )
{
memcpy(dest, &v9, a4);
return v7;
}
v7 = -2;
if ( !(unsigned int)ptrace_poke_area(a1, &v9, a2, a4) )
return -1;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, _QWORD *a3, unsigned __int64 a4)
{
void *v6; // rsp
unsigned int v7; // er13
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
void *dest; // [rsp+8h] [rbp-38h]

dest = a3;
v6 = alloca(a4 + 8);
if ( (unsigned int)func2(a1, &v9, a2, a4) )
return -1;
v7 = func3(a1, a3, a2, a4);
if ( !v7 )
{
memcpy(dest, &v9, a4);
return v7;
}
v7 = -2;
if ( !(unsigned int)func3(a1, &v9, a2, a4) )
return -1;
return v7;
}

original_code:
int ptrace_swap_area(pid_t pid, void *dst, void *src, unsigned long bytes)
{
 void *t = __builtin_alloca (bytes);
 if (ptrace_peek_area(pid, t, dst, bytes))
  return -1;
 if (ptrace_poke_area(pid, src, dst, bytes)) {
  if (ptrace_poke_area(pid, t, dst, bytes))
   return -2;
  return -1;
 }
 memcpy(src, t, bytes);
 return 0;
}

canonical_original_code:
int ptrace_swap_area(int pid, void *dst, void *src, unsigned long bytes)
{
 void *t = __builtin_alloca (bytes);
 if (ptrace_peek_area(pid, t, dst, bytes))
  return -1;
 if (ptrace_poke_area(pid, src, dst, bytes)) {
  if (ptrace_poke_area(pid, t, dst, bytes))
   return -2;
  return -1;
 }
 memcpy(src, t, bytes);
 return 0;
}

variable_types:
t
void *


decompiled_code:
__int64 __fastcall ptrace_get_regs(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_GETREGSET, a1, 1LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_GETREGSET, a1, 1LL, v3);
}

original_code:
int ptrace_get_regs(int pid, user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_GETREGSET, pid, 1, &iov);
}

canonical_original_code:
int ptrace_get_regs(int pid, struct user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_GETREGSET, pid, 1, &iov);
}

variable_types: struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; } *

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }


decompiled_code:
__int64 __fastcall ptrace_set_regs(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_SETREGSET, a1, 1LL, v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 216LL;
return ptrace(PTRACE_SETREGSET, a1, 1LL, v3);
}

original_code:
int ptrace_set_regs(int pid, user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_SETREGSET, pid, 1, &iov);
}

canonical_original_code:
int ptrace_set_regs(int pid, struct user_regs_struct_t *regs)
{
 struct iovec iov = {
  .iov_base = regs,
  .iov_len = sizeof(*regs),
 };
 return ptrace(PTRACE_SETREGSET, pid, 1, &iov);
}

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }

user_defined_types: struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; }


decompiled_code:
__int64 __fastcall ptrace_get_thread_ctx(unsigned int a1, __int64 a2)
{
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKDATA, a1, 8LL, a2) )
{
print_on_level(1LL, "Error (%s:%d): can't get signal blocking mask for %d: %m\n", "src/lib/ptrace.c", 208LL, a1);
}
else
{
if ( !(unsigned int)ptrace_get_regs(a1, a2 + 8) )
return ptrace_get_fpu(a1, a2 + 256);
print_on_level(1LL, "Error (%s:%d): Can't obtain registers (pid: %d): %m\n", "src/lib/ptrace.c", 213LL, a1);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2)
{
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKDATA, a1, 8LL, a2) )
{
print_on_level(1LL, "Error (%s:%d): can't get signal blocking mask for %d: %m\n", "src/lib/ptrace.c", 208LL, a1);
}
else
{
if ( !(unsigned int)func5(a1, a2 + 8) )
return ptrace_get_fpu(a1, a2 + 256);
print_on_level(1LL, "Error (%s:%d): Can't obtain registers (pid: %d): %m\n", "src/lib/ptrace.c", 213LL, a1);
}
return 0xFFFFFFFFLL;
}

original_code:
int ptrace_get_thread_ctx(pid_t pid, thread_ctx_t *ctx)
{
 if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "can't get signal blocking mask for %d" ": %m\n", "src/lib/ptrace.c", 208, pid);
  return -1;
 }
 if (ptrace_get_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't obtain registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 213, pid);
  return -1;
 }
 return ptrace_get_fpu(pid, &ctx->fpu);
}

canonical_original_code:
int ptrace_get_thread_ctx(int pid, struct thread_ctx_t *ctx)
{
 if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "can't get signal blocking mask for %d" ": %m\n", "src/lib/ptrace.c", 208, pid);
  return -1;
 }
 if (ptrace_get_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't obtain registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 213, pid);
  return -1;
 }
 return ptrace_get_fpu(pid, &ctx->fpu);
}

variable_types: struct thread_ctx_t { struct k_rtsigset_t { unsigned long sig[-1]; } sigmask; struct user_regs_struct_t { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long bp; unsigned long bx; unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long ax; unsigned long cx; unsigned long dx; unsigned long si; unsigned long di; unsigned long orig_ax; unsigned long ip; unsigned long cs; unsigned long flags; unsigned long sp; unsigned long ss; unsigned long fs_base; unsigned long gs_base; unsigned long ds; unsigned long es; unsigned long fs; unsigned long gs; } regs; struct fpu_state_t { union { struct xsave_struct { struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; } i387; struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; } xsave_hdr; struct ymmh_struct { unsigned int ymmh_space[64]; } ymmh; } xsave; unsigned char __pad[-1]; }; _Bool has_xsave; } fpu; } *

user_defined_types: struct thread_ctx_t { struct k_rtsigset_t sigmask; struct user_regs_struct_t regs; struct fpu_state_t fpu; }

user_defined_types: struct fpu_state_t { union { struct xsave_struct xsave; unsigned char __pad[-1]; }; _Bool has_xsave; }

user_defined_types: struct xsave_struct { struct i387_fxsave_struct i387; struct xsave_hdr_struct xsave_hdr; struct ymmh_struct ymmh; }


decompiled_code:
__int64 __fastcall ptrace_set_thread_ctx(unsigned int a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned int)ptrace_set_regs(a1, a2 + 8) )
{
print_on_level(1LL, "Error (%s:%d): Can't restore registers (pid: %d): %m\n", "src/lib/ptrace.c", 225LL, a1);
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
else
{
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
{
LABEL_3:
print_on_level(1LL, "Error (%s:%d): Can't block signals: %m\n", "src/lib/ptrace.c", 230LL);
return 0xFFFFFFFFLL;
}
result = ptrace_set_fpu(a1, a2 + 256);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned int)func6(a1, a2 + 8) )
{
print_on_level(1LL, "Error (%s:%d): Can't restore registers (pid: %d): %m\n", "src/lib/ptrace.c", 225LL, a1);
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
else
{
if ( ptrace(PTRACE_LISTEN|PTRACE_PEEKUSER, a1, 8LL, a2) )
{
LABEL_3:
print_on_level(1LL, "Error (%s:%d): Can't block signals: %m\n", "src/lib/ptrace.c", 230LL);
return 0xFFFFFFFFLL;
}
result = ptrace_set_fpu(a1, a2 + 256);
}
return result;
}

original_code:
int ptrace_set_thread_ctx(pid_t pid, thread_ctx_t *ctx)
{
 int ret = 0;
 if (ptrace_set_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't restore registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 225, pid);
  ret = -1;
 }
 if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "Can't block signals" ": %m\n", "src/lib/ptrace.c", 230);
  ret = -1;
 }
 if (!ret)
  ret = ptrace_set_fpu(pid, &ctx->fpu);
 return ret;
}

canonical_original_code:
int ptrace_set_thread_ctx(int pid, struct thread_ctx_t *ctx)
{
 int ret = 0;
 if (ptrace_set_regs(pid, &ctx->regs)) {
  print_on_level((1), "Error (%s:%d): " "Can't restore registers (pid: %d)" ": %m\n", "src/lib/ptrace.c", 225, pid);
  ret = -1;
 }
 if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(ctx->sigmask), &ctx->sigmask)) {
  print_on_level((1), "Error (%s:%d): " "Can't block signals" ": %m\n", "src/lib/ptrace.c", 230);
  ret = -1;
 }
 if (!ret)
  ret = ptrace_set_fpu(pid, &ctx->fpu);
 return ret;
}

variable_types: pid int

user_defined_types: struct k_rtsigset_t { unsigned long sig[-1]; }

user_defined_types: struct i387_fxsave_struct { unsigned short cwd; unsigned short swd; unsigned short twd; unsigned short fop; union { struct { unsigned long rip; unsigned long rdp; }; struct { unsigned int fip; unsigned int fcs; unsigned int foo; unsigned int fos; }; }; unsigned int mxcsr; unsigned int mxcsr_mask; unsigned int st_space[32]; unsigned int xmm_space[64]; unsigned int padding[12]; union { unsigned int padding1[12]; unsigned int sw_reserved[12]; }; }

user_defined_types: struct xsave_hdr_struct { unsigned long xstate_bv; unsigned long reserved1[2]; unsigned long reserved2[5]; }

user_defined_types: struct ymmh_struct { unsigned int ymmh_space[64]; }


original_code:
int libcompel_pack_argv(char *blob, int argc, char **argv, void **arg_p, unsigned int *arg_s)
{
 int i, *argc_packed;
 char *args_mem;
 unsigned total_len;
 unsigned long *argv_packed;
 total_len = sizeof(int);
 total_len += sizeof(unsigned long) + strlen(blob) + 1;
 for (i = 0; i < argc; i++)
  total_len += sizeof(unsigned long) + strlen(argv[i]) + 1;
 argc_packed = malloc(total_len);
 if (!argc_packed)
  return -1;
 *argc_packed = argc + 1;
 argv_packed = (unsigned long *)(argc_packed + 1);
 args_mem = (char *)(argv_packed + argc + 1);
 argv_packed[0] = (void *)args_mem - (void *)argc_packed;
 args_mem = stpcpy(args_mem, blob) + 1;
 for (i = 0; i < argc; i++) {
  argv_packed[i + 1] = (void *)args_mem - (void *)argc_packed;
  args_mem = stpcpy(args_mem, argv[i]) + 1;
 }
 *arg_p = argc_packed;
 *arg_s = total_len;
 return 0;
}

canonical_original_code:
int libcompel_pack_argv(char *blob, int argc, char **argv, void **arg_p, unsigned int *arg_s)
{
 int i; int *argc_packed;
 char *args_mem;
 unsigned int total_len;
 unsigned long *argv_packed;
 total_len = sizeof(int);
 total_len += sizeof(unsigned long) + strlen(blob) + 1;
 for (i = 0; i < argc; i++)
  total_len += sizeof(unsigned long) + strlen(argv[i]) + 1;
 argc_packed = malloc(total_len);
 if (!argc_packed)
  return -1;
 *argc_packed = argc + 1;
 argv_packed = (unsigned long *)(argc_packed + 1);
 args_mem = (char *)(argv_packed + argc + 1);
 argv_packed[0] = (void *)args_mem - (void *)argc_packed;
 args_mem = stpcpy(args_mem, blob) + 1;
 for (i = 0; i < argc; i++) {
  argv_packed[i + 1] = (void *)args_mem - (void *)argc_packed;
  args_mem = stpcpy(args_mem, argv[i]) + 1;
 }
 *arg_p = argc_packed;
 *arg_s = total_len;
 return 0;
}

variable_types:
blob
char *

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


decompiled_code:
void __fastcall loglevel_set(int a1)
{
current_loglevel = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
current_loglevel = a1;
}

original_code:
static void loglevel_set(unsigned int loglevel)
{
 current_loglevel = loglevel;
}

variable_types:
loglevel
unsigned int

return_type: void


decompiled_code:
bool __fastcall pr_quelled(unsigned int a1)
{
bool result; // al

result = 0;
if ( a1 )
result = current_loglevel < a1;
return result;
}

canonical_decompiled_code:
bool __fastcall func1(unsigned int a1)
{
bool result; // al

result = 0;
if ( a1 )
result = current_loglevel < a1;
return result;
}

original_code:
static inline _Bool pr_quelled(unsigned int loglevel)
{
 return loglevel != (0) && loglevel > current_loglevel;
}


decompiled_code:
int __fastcall log_set_fd(int a1)
{
int result; // eax

if ( logfd != -1 )
result = close(logfd);
logfd = a1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int result; // eax

if ( logfd != -1 )
result = close(logfd);
logfd = a1;
return result;
}

original_code:
static void log_set_fd(int fd)
{
 if (logfd != -1)
  close(logfd);
 logfd = fd;
}

variable_types: fd int


decompiled_code:
void __fastcall libcompel_log_init(int a1, int a2)
{
log_set_fd(a1);
loglevel_set(a2);
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2)
{
func2(a1);
func0(a2);
}

original_code:
void libcompel_log_init(int fd, unsigned int level)
{
 log_set_fd(fd);
 loglevel_set(level);
}

variable_types:
level
unsigned int


decompiled_code:
char print_on_level(unsigned int a1, __int64 a2, ...)
{
char result; // al
char *v3; // r10
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = pr_quelled(a1);
if ( !result )
{
va_start(arg, a2);
result = _print_on_level_constprop_0(v3, arg);
}
return result;
}

canonical_decompiled_code:
char func5(unsigned int a1, __int64 a2, ...)
{
char result; // al
char *v3; // r10
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = func1(a1);
if ( !result )
{
va_start(arg, a2);
result = func3(v3, arg);
}
return result;
}

original_code:
void print_on_level(unsigned int loglevel, const char *format, ...)
{
 va_list params;
 if (pr_quelled(loglevel))
  return;
 __builtin_va_start(params,format);
 __print_on_level(loglevel, format, params);
 __builtin_va_end(params);
}

canonical_original_code:
void print_on_level(unsigned int loglevel, char *format, ...)
{
 __builtin_va_list params;
 if (pr_quelled(loglevel))
  return;
 __builtin_va_start(params,format);
 __print_on_level(loglevel, format, params);
 __builtin_va_end(params);
}

variable_types:
format
char *


decompiled_code:
__int64 __fastcall PTR_ERR(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
static inline long PTR_ERR(const void *ptr)
{
 return (long)ptr;
}

canonical_original_code:
static inline long PTR_ERR(void *ptr)
{
 return (long)ptr;
}

variable_types:
ptr
void *

return_type: long


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
return a1 > 0xFFFFFFFFFFFFF000LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int64 a1)
{
return a1 > 0xFFFFFFFFFFFFF000LL;
}

original_code:
static inline long IS_ERR(const void *ptr)
{
 return __builtin_expect(!!(((unsigned long)ptr) >= (unsigned long)-4095), 0);
}

canonical_original_code:
static inline long IS_ERR(void *ptr)
{
 return __builtin_expect(!!(((unsigned long)ptr) >= (unsigned long)-4095), 0);
}


decompiled_code:
__int64 libcompel_exec()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = parasite_start();
if ( IS_ERR(v0) )
result = PTR_ERR(v0);
else
result = parasite_end();
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = parasite_start();
if ( func1(v0) )
result = func0(v0);
else
result = parasite_end();
return result;
}

original_code:
int libcompel_exec(pid_t pid, char *path, void *arg_p, unsigned int arg_s)
{
 void *p;
 p = parasite_start(pid, path, arg_p, arg_s);
 if (IS_ERR(p))
  return PTR_ERR(p);
 return parasite_end(p);
}

canonical_original_code:
int libcompel_exec(int pid, char *path, void *arg_p, unsigned int arg_s)
{
 void *p;
 p = parasite_start(pid, path, arg_p, arg_s);
 if (IS_ERR(p))
  return PTR_ERR(p);
 return parasite_end(p);
}

variable_types:
path
char *

variable_types:
p
void *


decompiled_code:
// attributes: thunk
__int64 libcompel_verify_packed()
{
return verify_elf_packed();
}

canonical_decompiled_code:
__int64 func6()
{
return verify_elf_packed();
}

original_code:
int libcompel_verify_packed(char *path)
{
 return verify_elf_packed(path);
}


decompiled_code:
int __fastcall print_forwarding(unsigned int a1, unsigned int a2)
{
return printf("O %u %d\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, unsigned int a2)
{
return printf("O %u %d\n", a1, a2);
}

original_code:
static inline void print_forwarding(unsigned int packet_id, int nic) {
  printf("O %u %d\n", packet_id, nic);
}

variable_types: nic int


decompiled_code:
_BOOL8 __fastcall key_compare(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) > BYTE4(a2);
else
result = (unsigned int)a1 > (unsigned int)a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) > BYTE4(a2);
else
result = (unsigned int)a1 > (unsigned int)a2;
return result;
}

original_code:
int key_compare (node_key key1, node_key key2){
 if (key1.ip == key2.ip){
  return key1.netsize > key2.netsize;
 }
 return key1.ip > key2.ip;
}

canonical_original_code:
int key_compare(struct node_key key1, struct node_key key2){
 if (key1.ip == key2.ip){
  return key1.netsize > key2.netsize;
 }
 return key1.ip > key2.ip;
}

variable_types: struct node_key { unsigned int ip; unsigned char netsize; }


decompiled_code:
_BOOL8 __fastcall check_match(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 8) >> *(_BYTE *)(a1 + 12) == a2 >> *(_BYTE *)(a1 + 12);
}

original_code:
int check_match(node * n, uint32_t ip){
 node_key data = n->key;
 uint32_t block = data.ip;
 uint8_t bitshift = data.netsize;
 uint32_t shift_ip = ip >> bitshift;
 uint32_t shift_block = block >> bitshift;
 return shift_ip == shift_block;
}

canonical_original_code:
int check_match(struct node *n, unsigned int ip){
 struct node_key data = n->key;
 unsigned int block = data.ip;
 unsigned char bitshift = data.netsize;
 unsigned int shift_ip = ip >> bitshift;
 unsigned int shift_block = block >> bitshift;
 return shift_ip == shift_block;
}

variable_types: struct node { struct node *next; struct node_key { unsigned int ip; unsigned char netsize; } key; int value; } *

variable_types:
ip
unsigned int

variable_types:
block
unsigned int

variable_types:
bitshift
unsigned char

user_defined_types: struct node { struct node *next; struct node_key key; int value; }


decompiled_code:
__int64 __fastcall find_longest_prefix_match(__int64 a1, unsigned int a2)
{
unsigned int i; // er8

for ( i = -1; a1; a1 = *(_QWORD *)a1 )
{
if ( check_match(a1, a2) )
i = *(_DWORD *)(a1 + 16);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
unsigned int i; // er8

for ( i = -1; a1; a1 = *(_QWORD *)a1 )
{
if ( func8(a1, a2) )
i = *(_DWORD *)(a1 + 16);
}
return i;
}

original_code:
int find_longest_prefix_match(node * head, uint32_t ip){
 node * walker = head;
 int foundSomething = 0;
 int best_nic_found = -1;
 while(walker != ((void *)0)){
  if(check_match(walker, ip)){
   best_nic_found = walker->value;
  }else{
   if(foundSomething){
    return best_nic_found;
   }
  }
  walker = walker->next;
 }
 return best_nic_found;
}

canonical_original_code:
int find_longest_prefix_match(struct node *head, unsigned int ip){
 struct node *walker = head;
 int foundSomething = 0;
 int best_nic_found = -1;
 while(walker != ((void *)0)){
  if(check_match(walker, ip)){
   best_nic_found = walker->value;
  }else{
   if(foundSomething){
    return best_nic_found;
   }
  }
  walker = walker->next;
 }
 return best_nic_found;
}

variable_types: foundSomething int

user_defined_types: struct node_key { unsigned int ip; unsigned char netsize; }


decompiled_code:
int __fastcall forward_packet(__int64 *a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // er9

v2 = find_longest_prefix_match(*a1, a2);
return print_forwarding(v3, v2);
}

canonical_decompiled_code:
int __fastcall func10(__int64 *a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // er9

v2 = func9(*a1, a2);
return func0(v3, v2);
}

original_code:
void forward_packet(router_state state, uint32_t ip, unsigned int packet_id) {
 int nic = find_longest_prefix_match(state->head, ip);
 print_forwarding(packet_id, nic);
}

canonical_original_code:
void forward_packet(struct router_state *state, unsigned int ip, unsigned int packet_id) {
 int nic = find_longest_prefix_match(state->head, ip);
 print_forwarding(packet_id, nic);
}

variable_types: struct router_state { struct node { struct node *next; struct node_key { unsigned int ip; unsigned char netsize; } key; int value; } *head; } *

user_defined_types: struct router_state { struct node *head; }


print

decompiled_code:
int __fastcall print(__int64 **a1)
{
__int64 **v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
result = printf(
"BLOCK: %d, MASK: %d, PORT: %d\n",
*((unsigned int *)v1 + 2),
*((unsigned __int8 *)v1 + 12),
*((unsigned int *)v1 + 4));
v1 = (__int64 **)*v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 **a1)
{
__int64 **v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
result = printf(
"BLOCK: %d, MASK: %d, PORT: %d\n",
*((unsigned int *)v1 + 2),
*((unsigned __int8 *)v1 + 12),
*((unsigned int *)v1 + 4));
v1 = (__int64 **)*v1;
}
while ( v1 );
}
return result;
}

original_code:
void print(node * n){
 if(n==((void *)0)){
  return;
 }
 printf("BLOCK: %d, MASK: %d, PORT: %d\n", n->key.ip, n->key.netsize, n->value);
 print(n->next);
}

canonical_original_code:
void print(struct node *n){
 if(n==((void *)0)){
  return;
 }
 printf("BLOCK: %d, MASK: %d, PORT: %d\n", n->key.ip, n->key.netsize, n->value);
 print(n->next);
}


decompiled_code:
_BOOL8 __fastcall key_equals(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) == BYTE4(a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) == BYTE4(a2);
return result;
}

original_code:
int key_equals(node_key key1, node_key key2){
 return key1.ip == key2.ip && key1.netsize == key2.netsize;
}

canonical_original_code:
int key_equals(struct node_key key1, struct node_key key2){
 return key1.ip == key2.ip && key1.netsize == key2.netsize;
}


decompiled_code:
__int64 __fastcall http_parse_method(char *s1)
{
const unsigned __int16 *v2; // r15
__int64 v3; // rbp
const char *v4; // r13
unsigned int v5; // er14
size_t v6; // r12

v2 = *_ctype_b_loc();
while ( (v2[*s1] & 0x2000) != 0 )
++s1;
v3 = 0LL;
while ( 1 )
{
v4 = (&http_method_str)[v3];
v5 = v3;
v6 = strlen(v4);
if ( !strncasecmp(s1, v4, v6) && (v2[s1[v6]] & 0x2000) != 0 )
break;
if ( ++v3 == 8 )
return 8;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
const unsigned __int16 *v2; // r15
__int64 v3; // rbp
const char *v4; // r13
unsigned int v5; // er14
size_t v6; // r12

v2 = *_ctype_b_loc();
while ( (v2[*s1] & 0x2000) != 0 )
++s1;
v3 = 0LL;
while ( 1 )
{
v4 = (&http_method_str)[v3];
v5 = v3;
v6 = strlen(v4);
if ( !strncasecmp(s1, v4, v6) && (v2[s1[v6]] & 0x2000) != 0 )
break;
if ( ++v3 == 8 )
return 8;
}
return v5;
}

original_code:
http_method http_parse_method(const char *request) {
    http_method m;
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short int) _ISspace)) request++;
    for(m = 0; m < METHOD_UNKNOWN; m++)
        if (!strncasecmp(request, http_method_str[m], strlen(http_method_str[m])) &&
            ((*__ctype_b_loc ())[(int) ((request[strlen(http_method_str[m])]))] & (unsigned short int) _ISspace))
            return m;
    return METHOD_UNKNOWN;
}

canonical_original_code:
enum http_method http_parse_method(char *request) {
    enum http_method m;
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short) _ISspace)) request++;
    for(m = 0; m < METHOD_UNKNOWN; m++)
        if (!strncasecmp(request, http_method_str[m], strlen(http_method_str[m])) &&
            ((*__ctype_b_loc ())[(int) ((request[strlen(http_method_str[m])]))] & (unsigned short) _ISspace))
            return m;
    return METHOD_UNKNOWN;
}

variable_types:
request
char *

variable_types: enum http_method { METHOD_GET=0, METHOD_POST=1, METHOD_HEAD=2, METHOD_OPTIONS=3, METHOD_PUT=4, METHOD_DELETE=5, METHOD_TRACE=6, METHOD_CONNECT=7, METHOD_UNKNOWN=8 }


decompiled_code:
char *__fastcall http_parse_uri(char *a1)
{
const unsigned __int16 *v2; // rcx
__int64 v3; // rdx
char *result; // rax
__int64 v5; // rdx
__int64 v6; // rdx
char v7; // di
unsigned __int16 v8; // dx
char *v9; // rsi
__int64 v10; // rdx

v2 = *_ctype_b_loc();
do
{
v3 = *a1;
result = a1++;
}
while ( (v2[v3] & 0x2000) != 0 );
do
v5 = *++result;
while ( (v2[v5] & 0x2000) == 0 );
do
{
v6 = *++result;
v7 = v6;
v8 = v2[v6];
}
while ( (v8 & 0x2000) != 0 );
v9 = result;
if ( v7 )
{
while ( (v8 & 0x2000) == 0 )
{
v10 = *++v9;
if ( !(_BYTE)v10 )
break;
v8 = v2[v10];
}
}
*v9 = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
const unsigned __int16 *v2; // rcx
__int64 v3; // rdx
char *result; // rax
__int64 v5; // rdx
__int64 v6; // rdx
char v7; // di
unsigned __int16 v8; // dx
char *v9; // rsi
__int64 v10; // rdx

v2 = *_ctype_b_loc();
do
{
v3 = *a1;
result = a1++;
}
while ( (v2[v3] & 0x2000) != 0 );
do
v5 = *++result;
while ( (v2[v5] & 0x2000) == 0 );
do
{
v6 = *++result;
v7 = v6;
v8 = v2[v6];
}
while ( (v8 & 0x2000) != 0 );
v9 = result;
if ( v7 )
{
while ( (v8 & 0x2000) == 0 )
{
v10 = *++v9;
if ( !(_BYTE)v10 )
break;
v8 = v2[v10];
}
}
*v9 = 0;
return result;
}

original_code:
char *http_parse_uri(char *request) {
    char *start, *end;
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short int) _ISspace)) request++;
    for (start = request; !((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short int) _ISspace); start++);
    for ( ; ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short int) _ISspace); start++);
    for (end = start; *end && !((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace); end++);
    *end = '\0';
    return start;
}

canonical_original_code:
char *http_parse_uri(char *request) {
    char *start; char *end;
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short) _ISspace)) request++;
    for (start = request; !((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short) _ISspace); start++);
    for ( ; ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short) _ISspace); start++);
    for (end = start; *end && !((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace); end++);
    *end = '\0';
    return start;
}

variable_types:
start
char *

variable_types:
end
char *

return_type: char *


decompiled_code:
const char *__fastcall http_parse_path(const char *a1)
{
const char *v1; // r12
char *v2; // rax
char v4; // al

v1 = a1;
if ( *a1 == 47 )
return v1;
v2 = strchr(a1, 58);
if ( !v2 )
return v1;
if ( *v2 != 58 )
return v1;
if ( v2[1] != 47 )
return v1;
if ( v2[2] != 47 )
return v1;
v1 = v2 + 3;
v4 = v2[3];
if ( !v4 )
return v1;
while ( v4 != 47 )
{
v4 = *++v1;
if ( !v4 )
return v1;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
const char *v1; // r12
char *v2; // rax
char v4; // al

v1 = a1;
if ( *a1 == 47 )
return v1;
v2 = strchr(a1, 58);
if ( !v2 )
return v1;
if ( *v2 != 58 )
return v1;
if ( v2[1] != 47 )
return v1;
if ( v2[2] != 47 )
return v1;
v1 = v2 + 3;
v4 = v2[3];
if ( !v4 )
return v1;
while ( v4 != 47 )
{
v4 = *++v1;
if ( !v4 )
return v1;
}
return v1;
}

original_code:
const char *http_parse_path(const char *uri) {
    if (*uri == '/') return uri;
    char *s = strchr(uri, ':');
    if (!s || strncmp(s, "://", 3)) return uri;
    for(s += 3; *s && *s != '/'; s++);
    return s;
}

canonical_original_code:
char *http_parse_path(char *uri) {
    if (*uri == '/') return uri;
    char *s = strchr(uri, ':');
    if (!s || strncmp(s, "://", 3)) return uri;
    for(s += 3; *s && *s != '/'; s++);
    return s;
}

variable_types:
uri
char *

variable_types:
s
char *


original_code:
char *http_parse_header_field(char *request, int length, const char *header_field) {
    char *oldlf, *newlf, *newnull, *start;
    int len = strlen(header_field);
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short int) _ISspace) && length > 0) request++, length--;
    for (oldlf = memchr(request, '\n', length); oldlf; oldlf = newlf) {
        newlf = memchr(oldlf + 1, '\n', request + length - 1 - oldlf);
        newnull = memchr(oldlf + 1, '\0', request + length - 1 - oldlf);
        if (newnull && newnull < newlf) newlf = newnull;
        if (newlf == oldlf + 1) return ((void *)0);
        if (newlf == oldlf + 2 && oldlf[1] == '\r') return ((void *)0);
        for(start = oldlf + 1; ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short int) _ISspace); start++);
        if (!strncasecmp(start, header_field, len) && start[len] == ':') {
            for(start += len + 1; ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short int) _ISspace); start++);
            for(; ((*__ctype_b_loc ())[(int) ((*newlf))] & (unsigned short int) _ISspace); newlf--) *newlf = '\0';
            return start;
        } else if (!*newlf) {
            for(; !newlf[1]; newlf++);
        }
    }
    return ((void *)0);
}

canonical_original_code:
char *http_parse_header_field(char *request, int length, char *header_field) {
    char *oldlf; char *newlf; char *newnull; char *start;
    int len = strlen(header_field);
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short) _ISspace) && length > 0) request++, length--;
    for (oldlf = memchr(request, '\n', length); oldlf; oldlf = newlf) {
        newlf = memchr(oldlf + 1, '\n', request + length - 1 - oldlf);
        newnull = memchr(oldlf + 1, '\0', request + length - 1 - oldlf);
        if (newnull && newnull < newlf) newlf = newnull;
        if (newlf == oldlf + 1) return ((void *)0);
        if (newlf == oldlf + 2 && oldlf[1] == '\r') return ((void *)0);
        for(start = oldlf + 1; ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short) _ISspace); start++);
        if (!strncasecmp(start, header_field, len) && start[len] == ':') {
            for(start += len + 1; ((*__ctype_b_loc ())[(int) ((*start))] & (unsigned short) _ISspace); start++);
            for(; ((*__ctype_b_loc ())[(int) ((*newlf))] & (unsigned short) _ISspace); newlf--) *newlf = '\0';
            return start;
        } else if (!*newlf) {
            for(; !newlf[1]; newlf++);
        }
    }
    return ((void *)0);
}

variable_types: length int

variable_types:
oldlf
char *

variable_types:
newlf
char *

variable_types:
newnull
char *

variable_types: len int


original_code:
const char *http_parse_body(const char *request, int length) {
    const char *oldlf, *newlf, *newnull;
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short int) _ISspace) && length > 0) request++, length--;
    for (oldlf = memchr(request, '\n', length);
         oldlf && (newlf = memchr(oldlf + 1, '\n', request + length - 1 - oldlf));
         oldlf = newlf) {
        newnull = memchr(oldlf + 1, '\0', request + length - 1 - oldlf);
        if (newnull && newnull < newlf) newlf = newnull;
        if (newlf == oldlf + 1) return newlf + 1;
        if (newlf == oldlf + 2 && oldlf[1] == '\r') return newlf + 1;
        if (!*newlf) {
            for(; !newlf[1]; newlf++);
        }
    }
    return ((void *)0);
}

canonical_original_code:
char *http_parse_body(char *request, int length) {
    char *oldlf; char *newlf; char *newnull;
    while (((*__ctype_b_loc ())[(int) ((*request))] & (unsigned short) _ISspace) && length > 0) request++, length--;
    for (oldlf = memchr(request, '\n', length);
         oldlf && (newlf = memchr(oldlf + 1, '\n', request + length - 1 - oldlf));
         oldlf = newlf) {
        newnull = memchr(oldlf + 1, '\0', request + length - 1 - oldlf);
        if (newnull && newnull < newlf) newlf = newnull;
        if (newlf == oldlf + 1) return newlf + 1;
        if (newlf == oldlf + 2 && oldlf[1] == '\r') return newlf + 1;
        if (!*newlf) {
            for(; !newlf[1]; newlf++);
        }
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall http_header_complete(void *s, int a2)
{
char *v2; // rax
unsigned int v3; // ebx
bool v4; // zf
__int64 result; // rax

v2 = http_parse_body(s, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = (_DWORD)v2 - (_DWORD)s;
v4 = memchr(s, 0, v2 - (_BYTE *)s) == 0LL;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *s, int a2)
{
char *v2; // rax
unsigned int v3; // ebx
bool v4; // zf
__int64 result; // rax

v2 = func4(s, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = (_DWORD)v2 - (_DWORD)s;
v4 = memchr(s, 0, v2 - (_BYTE *)s) == 0LL;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
return result;
}

original_code:
int http_header_complete(const char *request, int length) {
    const char *body = http_parse_body(request, length);
    if (body && !memchr(request, '\0', body - request))
        return body - request;
    else
        return -1;
}

canonical_original_code:
int http_header_complete(char *request, int length) {
    char *body = http_parse_body(request, length);
    if (body && !memchr(request, '\0', body - request))
        return body - request;
    else
        return -1;
}

variable_types:
body
char *


encode

original_code:
char *encode(const char *original, char *encoded) {
    char *e = encoded;
    for(;*original; original++, encoded++) {
        if (((*__ctype_b_loc ())[(int) ((*original))] & (unsigned short int) _ISalnum))
            *encoded = *original;
        else if (*original == ' ')
            *encoded = '+';
        else {
            sprintf(encoded, "%%%02X", *original);
            encoded += 2;
        }
    }
    *encoded = '\0';
    return e;
}

canonical_original_code:
char *encode(char *original, char *encoded) {
    char *e = encoded;
    for(;*original; original++, encoded++) {
        if (((*__ctype_b_loc ())[(int) ((*original))] & (unsigned short) _ISalnum))
            *encoded = *original;
        else if (*original == ' ')
            *encoded = '+';
        else {
            sprintf(encoded, "%%%02X", *original);
            encoded += 2;
        }
    }
    *encoded = '\0';
    return e;
}

variable_types:
original
char *

variable_types:
encoded
char *

variable_types:
e
char *


decompiled_code:
__int64 __fastcall map_key_cmp(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

original_code:
int map_key_cmp(map_key key1, map_key key2) {
  return key1 - key2;
}

canonical_original_code:
int map_key_cmp(int key1, int key2) {
  return key1 - key2;
}


decompiled_code:
// attributes: thunk
int str_to_map_key(const char *nptr)
{
return atoi(nptr);
}

canonical_decompiled_code:
int func8(const char *nptr)
{
return atoi(nptr);
}

original_code:
map_key str_to_map_key(char *s) {
  return atoi(s);
}

canonical_original_code:
int str_to_map_key(char *s) {
  return atoi(s);
}


decompiled_code:
void *__fastcall str_to_map_value(void *src)
{
size_t v1; // r12
void *v2; // rax

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func9(void *src)
{
size_t v1; // r12
void *v2; // rax

if ( !src )
return 0LL;
v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

original_code:
map_value str_to_map_value(char *s) {
  if (!s) return s;
  map_value v = (map_value) malloc(strlen(s)+1);
  strcpy(v, s);
  return v;
}

canonical_original_code:
char *str_to_map_value(char *s) {
  if (!s) return s;
  char *v = (map_value) malloc(strlen(s)+1);
  strcpy(v, s);
  return v;
}

variable_types:
v
char *


decompiled_code:
int __fastcall print_mapping(unsigned int a1, const char *a2)
{
return printf("\t<%d, %s>\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, const char *a2)
{
return printf("\t<%d, %s>\n", a1, a2);
}

original_code:
void print_mapping(map_key key, map_value value) {
  printf("\t<%d, %s>\n", key, value);
}

canonical_original_code:
void print_mapping(int key, char *value) {
  printf("\t<%d, %s>\n", key, value);
}

variable_types: key int

variable_types:
value
char *


decompiled_code:
_QWORD *map_create()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func11()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
map map_create(void) {
 map myMap = malloc(sizeof(struct map));
 myMap->head = ((void *)0);
 return myMap;
}

canonical_original_code:
struct map *map_create() {
 struct map *myMap = malloc(sizeof(struct map));
 myMap->head = ((void *)0);
 return myMap;
}

variable_types: struct map { struct node { struct node *next; int key; char *value; } *head; } *


insertNode

decompiled_code:
__int64 __fastcall insertNode(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( !a1 )
return a2;
v2 = *(_DWORD *)(a1 + 8);
if ( *(_DWORD *)(a2 + 8) == v2 )
{
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a2 + 16);
result = a1;
}
else if ( *(_DWORD *)(a2 + 8) <= v2 )
{
*(_QWORD *)a1 = insertNode(*(_QWORD *)a1);
result = a1;
}
else
{
result = a2;
*(_QWORD *)a2 = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

if ( !a1 )
return a2;
v2 = *(_DWORD *)(a1 + 8);
if ( *(_DWORD *)(a2 + 8) == v2 )
{
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a2 + 16);
result = a1;
}
else if ( *(_DWORD *)(a2 + 8) <= v2 )
{
*(_QWORD *)a1 = func12(*(_QWORD *)a1);
result = a1;
}
else
{
result = a2;
*(_QWORD *)a2 = a1;
}
return result;
}

original_code:
node * insertNode(node * n, node * newNode){
 if(n == ((void *)0)){
  return newNode;
 }
 if(newNode->key == n->key){
  n->value = newNode->value;
  return n;
 }
 if(newNode->key > n->key){
  newNode->next = n;
  return newNode;
 }
 n->next = insertNode(n->next, newNode);
 return n;
}

canonical_original_code:
struct node *insertNode(struct node *n, struct node *newNode){
 if(n == ((void *)0)){
  return newNode;
 }
 if(newNode->key == n->key){
  n->value = newNode->value;
  return n;
 }
 if(newNode->key > n->key){
  newNode->next = n;
  return newNode;
 }
 n->next = insertNode(n->next, newNode);
 return n;
}

variable_types:
n
struct node *

variable_types:
newNode
struct node *

return_type: struct node { struct node *next; int key; char *value; } *


decompiled_code:
__int64 __fastcall map_lookup(__int64 **a1, int a2, _QWORD *a3)
{
__int64 *v3; // rax
__int64 v5; // rdx
__int64 result; // rax

v3 = *a1;
if ( *a1 )
{
while ( 1 )
{
if ( *((_DWORD *)v3 + 2) == a2 )
{
v5 = v3[2];
if ( v5 )
break;
}
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_7;
}
*a3 = v5;
result = 1LL;
}
else
{
LABEL_7:
*a3 = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 **a1, int a2, _QWORD *a3)
{
__int64 *v3; // rax
__int64 v5; // rdx
__int64 result; // rax

v3 = *a1;
if ( *a1 )
{
while ( 1 )
{
if ( *((_DWORD *)v3 + 2) == a2 )
{
v5 = v3[2];
if ( v5 )
break;
}
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_7;
}
*a3 = v5;
result = 1LL;
}
else
{
LABEL_7:
*a3 = 0LL;
result = 0LL;
}
return result;
}

original_code:
int map_lookup(map m, map_key key, map_value *value) {
 node * node = m->head;
 while(node != ((void *)0)){
  if(node->key == key){
   if(node->value != ((void *)0)){
    *value = node->value;
    return 1;
   }
  }
  node = node->next;
 }
 *value = ((void *)0);
 return 0;
}

canonical_original_code:
int map_lookup(struct map *m, int key, char **value) {
 struct node *node = m->head;
 while(node != ((void *)0)){
  if(node->key == key){
   if(node->value != ((void *)0)){
    *value = node->value;
    return 1;
   }
  }
  node = node->next;
 }
 *value = ((void *)0);
 return 0;
}

variable_types:
value
char **

variable_types: struct node { struct node *next; int key; char *value; } *


original_code:
int map_insert(map *m, map_key key, map_value value, map_value *old_value) {
 map_lookup(m, key, old_value);
 node * newNode = malloc(sizeof(struct node));
 newNode->key = key;
 newNode->value = value;
 node * head = (*m)->head;
 if(head == ((void *)0) || head->key > newNode->key){
  (*m)->head = newNode;
  newNode->next = head;
 }else if(head->key == newNode->key){
  head->value = newNode->value;
 }else{
  while(head->next != ((void *)0) && head->next->key < newNode->key && head->next->key != newNode->key){
   head = head->next;
  }
  if(head->next == ((void *)0)){
   head->next = newNode;
  }
  else if( head->next->key == newNode->key ){
    head->next->value = newNode->value;
  } else {
    newNode->next = head->next;
    head->next = newNode;
  }
 }
 return 1;
}

canonical_original_code:
int map_insert(struct map **m, int key, char *value, char **old_value) {
 map_lookup(m, key, old_value);
 struct node *newNode = malloc(sizeof(struct node));
 newNode->key = key;
 newNode->value = value;
 struct node *head = (*m)->head;
 if(head == ((void *)0) || head->key > newNode->key){
  (*m)->head = newNode;
  newNode->next = head;
 }else if(head->key == newNode->key){
  head->value = newNode->value;
 }else{
  while(head->next != ((void *)0) && head->next->key < newNode->key && head->next->key != newNode->key){
   head = head->next;
  }
  if(head->next == ((void *)0)){
   head->next = newNode;
  }
  else if( head->next->key == newNode->key ){
    head->next->value = newNode->value;
  } else {
    newNode->next = head->next;
    head->next = newNode;
  }
 }
 return 1;
}

variable_types: struct map { struct node { struct node *next; int key; char *value; } *head; } **


decompiled_code:
__int64 __fastcall map_delete(__int64 **a1, int a2, _QWORD *a3)
{
unsigned int v3; // eax
__int64 *v4; // rbx
unsigned int v5; // er12

v3 = map_lookup(a1, a2, a3);
v4 = *a1;
v5 = v3;
*v4 = (__int64)deleteNode((_DWORD *)**a1, a2);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 **a1, int a2, _QWORD *a3)
{
unsigned int v3; // eax
__int64 *v4; // rbx
unsigned int v5; // er12

v3 = func13(a1, a2, a3);
v4 = *a1;
v5 = v3;
*v4 = (__int64)deleteNode((_DWORD *)**a1, a2);
return v5;
}

original_code:
int map_delete(map *m, map_key key, map_value *value) {
 int retValue = map_lookup(m, key, value);
 (*m)->head = deleteNode((*m)->head, key);
 return retValue;
}

canonical_original_code:
int map_delete(struct map **m, int key, char **value) {
 int retValue = map_lookup(m, key, value);
 (*m)->head = deleteNode((*m)->head, key);
 return retValue;
}

variable_types: retValue int

user_defined_types: struct node { struct node *next; int key; char *value; }


destroyNode

decompiled_code:
void __fastcall destroyNode(void *ptr)
{
if ( ptr )
{
destroyNode(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
if ( ptr )
{
func17(*(void **)ptr);
free(ptr);
}
}

original_code:
void destroyNode(node * n){
 if(n==((void *)0)){
  return;
 }
 destroyNode(n->next);
 free(n);
}

canonical_original_code:
void destroyNode(struct node *n){
 if(n==((void *)0)){
  return;
 }
 destroyNode(n->next);
 free(n);
}


decompiled_code:
void __fastcall map_destroy(void *ptr)
{
destroyNode(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func18(void *ptr)
{
func17(*(void **)ptr);
free(ptr);
}

original_code:
void map_destroy(map m) {
 node * n = m->head;
 destroyNode(n);
 free(m);
}

canonical_original_code:
void map_destroy(struct map *m) {
 struct node *n = m->head;
 destroyNode(n);
 free(m);
}


decompiled_code:
int __fastcall print_advertisement(unsigned int a1, unsigned __int8 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
return printf(
"A %u.%u.%u.%u/%u %u %u\nT %u.%u.%u.%u/%u %d\n",
HIBYTE(a1),
BYTE2(a1),
BYTE1(a1),
(unsigned __int8)a1,
a2,
a4,
a5,
HIBYTE(a1),
BYTE2(a1),
BYTE1(a1),
(unsigned __int8)a1,
a2,
a3);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, unsigned __int8 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
return printf(
"A %u.%u.%u.%u/%u %u %u\nT %u.%u.%u.%u/%u %d\n",
HIBYTE(a1),
BYTE2(a1),
BYTE1(a1),
(unsigned __int8)a1,
a2,
a4,
a5,
HIBYTE(a1),
BYTE2(a1),
BYTE1(a1),
(unsigned __int8)a1,
a2,
a3);
}

original_code:
static inline void print_advertisement(uint32_t ip, uint8_t netsize, int nic,
                                       unsigned int metric, unsigned int update_id) {
  printf("A %u.%u.%u.%u/%u %u %u\n"
         "T %u.%u.%u.%u/%u %d\n",
         (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF, netsize, metric, update_id,
         (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF, netsize, nic);
}

canonical_original_code:
static inline void print_advertisement(unsigned int ip, unsigned char netsize, int nic, unsigned int metric, unsigned int update_id) {
  printf("A %u.%u.%u.%u/%u %u %u\n"
         "T %u.%u.%u.%u/%u %d\n",
         (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF, netsize, metric, update_id,
         (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF, netsize, nic);
}

variable_types:
ip
unsigned int

variable_types:
netsize
unsigned char

variable_types: nic int

variable_types:
metric
unsigned int


original_code:
int find_shortest_nic(node * n, int * best_nic){
 if(n == ((void *)0)){
  return -1;
 }
 node_value node_value = n->value;
 int i;
 int best = 1000;
 for(i= 0; i < 16; i++){
  if (node_value.nic_distances[i] < best) {
   best = node_value.nic_distances[i];
   *best_nic = i;
  }
 }
 return best;
}

canonical_original_code:
int find_shortest_nic(struct node *n, int *best_nic){
 if(n == ((void *)0)){
  return -1;
 }
 struct node_value node_value = n->value;
 int i;
 int best = 1000;
 for(i= 0; i < 16; i++){
  if (node_value.nic_distances[i] < best) {
   best = node_value.nic_distances[i];
   *best_nic = i;
  }
 }
 return best;
}

variable_types: struct node { struct node *next; struct node_key { unsigned int ip; unsigned char netsize; } key; struct node_value { int nic_distances[16]; } value; } *

variable_types: i int

variable_types: best int

user_defined_types: struct node { struct node *next; struct node_key key; struct node_value value; }


canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) == BYTE4(a2);
return result;
}

original_code:
int key_equals(node_key key1, node_key key2){
 return key1.ip == key2.ip && key1.netsize == key2.netsize;
}

canonical_original_code:
int key_equals(struct node_key key1, struct node_key key2){
 return key1.ip == key2.ip && key1.netsize == key2.netsize;
}

variable_types: struct node_key { unsigned int ip; unsigned char netsize; }


decompiled_code:
_BOOL8 __fastcall key_compare(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) > BYTE4(a2);
else
result = (unsigned int)a1 > (unsigned int)a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

if ( (_DWORD)a1 == (_DWORD)a2 )
result = BYTE4(a1) > BYTE4(a2);
else
result = (unsigned int)a1 > (unsigned int)a2;
return result;
}

original_code:
int key_compare (node_key key1, node_key key2){
 if (key1.ip == key2.ip){
  return key1.netsize > key2.netsize;
 }
 return key1.ip > key2.ip;
}

canonical_original_code:
int key_compare(struct node_key key1, struct node_key key2){
 if (key1.ip == key2.ip){
  return key1.netsize > key2.netsize;
 }
 return key1.ip > key2.ip;
}


decompiled_code:
unsigned int __fastcall process_update(__int64 **a1, unsigned int a2, unsigned __int8 a3, __int64 a4, __int64 a5, unsigned int a6)
{
__int64 *v8; // r14
const __m128i *v9; // rax
int v10; // er8
__m128i *v11; // r9
__int64 v12; // r10
unsigned int v13; // er11
const __m128i *v14; // r15
int v15; // eax
__int64 *v16; // rbx
unsigned int v17; // er11
int v18; // er14
__int32 v19; // ecx
unsigned int result; // eax
const __m128i *v21; // rax
unsigned int v22; // ecx
__int64 v23; // [rsp+8h] [rbp-50h]
unsigned int v24[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v8 = *a1;
v9 = (const __m128i *)node_find_subnet(**a1, ((unsigned __int64)a3 << 32) | a2);
if ( !v9 )
{
v23 = v12;
*v8 = (__int64)node_insert(v11, a2, a3, v13, v10 + 1);
v21 = (const __m128i *)node_find_subnet(**a1, v23);
v22 = find_shortest_nic(v21, v24);
if ( v22 != 1000 )
return print_advertisement(a2, a3, v24[0], v22, a6);
return print_advertisement(a2, a3, 0xFFFFFFFF, 0x3E8u, a6);
}
v14 = v9;
v15 = find_shortest_nic(v9, v24);
v16 = *a1;
v18 = v15;
*v16 = (__int64)node_insert((__m128i *)*v16, a2, a3, v17, v19);
result = find_shortest_nic(v14, v24);
if ( v18 == result )
return result;
if ( result == 1000 )
return print_advertisement(a2, a3, 0xFFFFFFFF, 0x3E8u, a6);
return print_advertisement(a2, a3, v24[0], result, a6);
}

canonical_decompiled_code:
unsigned int __fastcall func7(__int64 **a1, unsigned int a2, unsigned __int8 a3, __int64 a4, __int64 a5, unsigned int a6)
{
__int64 *v8; // r14
const __m128i *v9; // rax
int v10; // er8
__m128i *v11; // r9
__int64 v12; // r10
unsigned int v13; // er11
const __m128i *v14; // r15
int v15; // eax
__int64 *v16; // rbx
unsigned int v17; // er11
int v18; // er14
__int32 v19; // ecx
unsigned int result; // eax
const __m128i *v21; // rax
unsigned int v22; // ecx
__int64 v23; // [rsp+8h] [rbp-50h]
unsigned int v24[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v8 = *a1;
v9 = (const __m128i *)node_find_subnet(**a1, ((unsigned __int64)a3 << 32) | a2);
if ( !v9 )
{
v23 = v12;
*v8 = (__int64)node_insert(v11, a2, a3, v13, v10 + 1);
v21 = (const __m128i *)node_find_subnet(**a1, v23);
v22 = func4(v21, v24);
if ( v22 != 1000 )
return func0(a2, a3, v24[0], v22, a6);
return func0(a2, a3, 0xFFFFFFFF, 0x3E8u, a6);
}
v14 = v9;
v15 = func4(v9, v24);
v16 = *a1;
v18 = v15;
*v16 = (__int64)node_insert((__m128i *)*v16, a2, a3, v17, v19);
result = func4(v14, v24);
if ( v18 == result )
return result;
if ( result == 1000 )
return func0(a2, a3, 0xFFFFFFFF, 0x3E8u, a6);
return func0(a2, a3, v24[0], result, a6);
}

original_code:
void process_update(router_state *state, uint32_t ip, uint8_t netsize,
      int nic, unsigned int metric, unsigned int update_id) {
 int distance;
 int new_distance;
 int best_nic;
 node_key node_key;
 node_key.ip = ip;
 node_key.netsize = netsize;
 node * n = node_find_subnet((*state)->head, node_key);
 if(n) distance = find_shortest_nic(n, &best_nic);
 (*state)->head = node_insert((*state)->head, ip, netsize, nic, metric + 1);
 if(!n){
  node * new_node = node_find_subnet((*state)->head, node_key);
  new_distance = find_shortest_nic(new_node, &best_nic);
  if(new_distance == 1000){
   print_advertisement(ip, netsize, -1, new_distance, update_id);
   return;
  }
  print_advertisement(ip, netsize, best_nic, new_distance, update_id );
  return;
 }else{
 new_distance = find_shortest_nic(n, &best_nic);
  if (distance != new_distance){
   if(new_distance == 1000){
    print_advertisement(ip, netsize, -1, new_distance, update_id);
    return;
   }
   print_advertisement(ip, netsize, best_nic, new_distance, update_id );
  }
 }
}

canonical_original_code:
void process_update(struct router_state **state, unsigned int ip, unsigned char netsize, int nic, unsigned int metric, unsigned int update_id) {
 int distance;
 int new_distance;
 int best_nic;
 struct node_key node_key;
 node_key.ip = ip;
 node_key.netsize = netsize;
 struct node *n = node_find_subnet((*state)->head, node_key);
 if(n) distance = find_shortest_nic(n, &best_nic);
 (*state)->head = node_insert((*state)->head, ip, netsize, nic, metric + 1);
 if(!n){
  struct node *new_node = node_find_subnet((*state)->head, node_key);
  new_distance = find_shortest_nic(new_node, &best_nic);
  if(new_distance == 1000){
   print_advertisement(ip, netsize, -1, new_distance, update_id);
   return;
  }
  print_advertisement(ip, netsize, best_nic, new_distance, update_id );
  return;
 }else{
 new_distance = find_shortest_nic(n, &best_nic);
  if (distance != new_distance){
   if(new_distance == 1000){
    print_advertisement(ip, netsize, -1, new_distance, update_id);
    return;
   }
   print_advertisement(ip, netsize, best_nic, new_distance, update_id );
  }
 }
}

variable_types: struct router_state { struct node { struct node *next; struct node_key { unsigned int ip; unsigned char netsize; } key; struct node_value { int nic_distances[16]; } value; } *head; } **

variable_types: distance int


decompiled_code:
__pid_t sigchld_handler()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

original_code:
static void sigchld_handler(int s) {
    while(waitpid(-1, ((void *)0), 1) > 0);
}

variable_types: s int


decompiled_code:
__int64 __fastcall create_server_socket(char *service)
{
int v1; // eax
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // er12
const char *v6; // rax
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo(0LL, service, &req, &pai);
if ( v1 )
{
v6 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo: %s\n", v6);
exit(1);
}
v2 = pai;
if ( !pai )
{
LABEL_10:
fwrite("server: failed to bind\n", 1uLL, 0x17uLL, stderr);
exit(2);
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
perror("server: socket");
LABEL_9:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_10;
}
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 )
{
perror("setsockopt");
exit(1);
}
if ( bind(v4, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v4);
perror("server: bind");
goto LABEL_9;
}
freeaddrinfo(pai);
if ( listen(v4, 10) == -1 )
{
perror("listen");
exit(1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *service)
{
int v1; // eax
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // er12
const char *v6; // rax
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo(0LL, service, &req, &pai);
if ( v1 )
{
v6 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo: %s\n", v6);
exit(1);
}
v2 = pai;
if ( !pai )
{
LABEL_10:
fwrite("server: failed to bind\n", 1uLL, 0x17uLL, stderr);
exit(2);
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
perror("server: socket");
LABEL_9:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_10;
}
if ( setsockopt(v3, 1, 2, &optval, 4u) == -1 )
{
perror("setsockopt");
exit(1);
}
if ( bind(v4, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v4);
perror("server: bind");
goto LABEL_9;
}
freeaddrinfo(pai);
if ( listen(v4, 10) == -1 )
{
perror("listen");
exit(1);
}
return v4;
}

original_code:
static int create_server_socket(char *port) {
    int lst_socket;
    struct addrinfo hints, *servinfo, *p;
    int yes = 1;
    int rv;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((rv = getaddrinfo(((void *)0), port, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        exit(1);
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((lst_socket = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
            perror("server: socket");
            continue;
        }
        if (setsockopt(lst_socket, 1, 2, &yes, sizeof(int)) == -1) {
            perror("setsockopt");
            exit(1);
        }
        if (bind(lst_socket, p->ai_addr, p->ai_addrlen) == -1) {
            close(lst_socket);
            perror("server: bind");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "server: failed to bind\n");
        exit(2);
    }
    freeaddrinfo(servinfo);
    if (listen(lst_socket, 10) == -1) {
        perror("listen");
        exit(1);
    }
    return lst_socket;
}

canonical_original_code:
static int create_server_socket(char *port) {
    int lst_socket;
    struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
    int yes = 1;
    int rv;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((rv = getaddrinfo(((void *)0), port, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        exit(1);
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((lst_socket = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
            perror("server: socket");
            continue;
        }
        if (setsockopt(lst_socket, 1, 2, &yes, sizeof(int)) == -1) {
            perror("setsockopt");
            exit(1);
        }
        if (bind(lst_socket, p->ai_addr, p->ai_addrlen) == -1) {
            close(lst_socket);
            perror("server: bind");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "server: failed to bind\n");
        exit(2);
    }
    freeaddrinfo(servinfo);
    if (listen(lst_socket, 10) == -1) {
        perror("listen");
        exit(1);
    }
    return lst_socket;
}

variable_types:
port
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: yes int

variable_types: rv int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall send_string(int fd, __int64 a2, int a3)
{
int v3; // er14
int v4; // er13
int v6; // eax

if ( a3 <= 0 )
return 1LL;
v3 = a3;
v4 = 0;
do
{
v6 = send(fd, (const void *)(a2 + v4), v3, 0);
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v4 += v6;
v3 -= v6;
}
while ( a3 > v4 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2, int a3)
{
int v3; // er14
int v4; // er13
int v6; // eax

if ( a3 <= 0 )
return 1LL;
v3 = a3;
v4 = 0;
do
{
v6 = send(fd, (const void *)(a2 + v4), v3, 0);
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v4 += v6;
v3 -= v6;
}
while ( a3 > v4 );
return 1LL;
}

original_code:
int send_string(int socket, char * string, int size){
 int bytes_remaining = size;
 int bytes_sent = 0;
 while(bytes_sent < size){
  int bytes = send(socket, string + bytes_sent, bytes_remaining, 0);
  if(bytes == -1){
   return -1;
  }
  bytes_sent += bytes;
  bytes_remaining -= bytes;
 }
 return 1;
}

canonical_original_code:
int send_string(int socket, char *string, int size){
 int bytes_remaining = size;
 int bytes_sent = 0;
 while(bytes_sent < size){
  int bytes = send(socket, string + bytes_sent, bytes_remaining, 0);
  if(bytes == -1){
   return -1;
  }
  bytes_sent += bytes;
  bytes_remaining -= bytes;
 }
 return 1;
}

variable_types: socket int

variable_types:
string
char *

variable_types: size int

variable_types: bytes int