decompiled_code:
size_t setup_escape_seqs()
{
char *v0; // rax
size_t result; // rax

K_DELETE = tigetstr("kdch1");
S_DELETE = strlen(K_DELETE);
K_HOME = (__int64)tigetstr("khome");
S_HOME = strlen((const char *)K_HOME);
K_END = tigetstr("kend");
S_END = strlen(K_END);
v0 = tigetstr("kent");
K_ENTER = v0;
if ( v0 )
{
S_ENTER = strlen(v0);
}
else
{
K_ENTER = strdup("\r");
S_ENTER = 1;
}
K_UP = tigetstr("kcuu1");
S_UP = strlen(K_UP);
K_DOWN = tigetstr("kcud1");
S_DOWN = strlen(K_DOWN);
K_LEFT = tigetstr("kcub1");
S_LEFT = strlen(K_LEFT);
K_RIGHT = tigetstr("kcuf1");
result = strlen(K_RIGHT);
S_RIGHT = result;
return result;
}

canonical_decompiled_code:
size_t func12()
{
char *v0; // rax
size_t result; // rax

K_DELETE = tigetstr("kdch1");
S_DELETE = strlen(K_DELETE);
K_HOME = (__int64)tigetstr("khome");
S_HOME = strlen((const char *)K_HOME);
K_END = tigetstr("kend");
S_END = strlen(K_END);
v0 = tigetstr("kent");
K_ENTER = v0;
if ( v0 )
{
S_ENTER = strlen(v0);
}
else
{
K_ENTER = strdup("\r");
S_ENTER = 1;
}
K_UP = tigetstr("kcuu1");
S_UP = strlen(K_UP);
K_DOWN = tigetstr("kcud1");
S_DOWN = strlen(K_DOWN);
K_LEFT = tigetstr("kcub1");
S_LEFT = strlen(K_LEFT);
K_RIGHT = tigetstr("kcuf1");
result = strlen(K_RIGHT);
S_RIGHT = result;
return result;
}

original_code:
void setup_escape_seqs()
{
 K_DELETE = tigetstr("kdch1"); S_DELETE = strlen(K_DELETE);
 K_HOME = tigetstr("khome"); S_HOME = strlen(K_HOME);
 K_END = tigetstr("kend"); S_END = strlen(K_END);
 K_ENTER = tigetstr("kent");
 if(K_ENTER <= (char *)0) {
  K_ENTER = strdup("\r");
  S_ENTER = 1;
 }
 else
  S_ENTER = strlen(K_ENTER);
 K_UP = tigetstr("kcuu1"); S_UP = strlen(K_UP);
 K_DOWN = tigetstr("kcud1"); S_DOWN = strlen(K_DOWN);
 K_LEFT = tigetstr("kcub1"); S_LEFT = strlen(K_LEFT);
 K_RIGHT = tigetstr("kcuf1"); S_RIGHT = strlen(K_RIGHT);
 return;
}


main

canonical_name: main

repo: jgreco/vindication

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v5; // ebp
int v6; // er13
__int64 v7; // r12
int v8; // edi
int v9; // eax
int v10; // eax
fd_set v11; // [rsp+0h] [rbp-6E8h] BYREF
fd_set writefds; // [rsp+80h] [rbp-668h] BYREF
fd_set exceptfds; // [rsp+100h] [rbp-5E8h] BYREF
char buf[1024]; // [rsp+180h] [rbp-568h] BYREF
struct sigaction v15; // [rsp+580h] [rbp-168h] BYREF
struct sigaction v16; // [rsp+620h] [rbp-C8h] BYREF

memset(&v16.sa_mask, 0, 0x90uLL);
memset(&v15.sa_mask, 0, 0x90uLL);
v16.sa_handler = (__sighandler_t)sigchld_handler;
v15.sa_handler = (__sighandler_t)sigwinch_handler;
term = getenv("TERM");
state = 0;
mangled_len = 0;
command_count = 0;
v3 = open("/dev/null", 2);
if ( setupterm(0LL, v3, 0LL) == -1 )
{
fwrite("could not get terminfo.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
close(v3);
setup_escape_seqs();
master_controlling_tty = open("/dev/tty", 258);
ioctl(master_controlling_tty, 0x5413uLL, &term_size);
if ( argc <= 1 )
{
fwrite("Improper number of arguments.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
pid = pty_fork();
if ( pid )
{
v5 = dup(0);
tcgetattr(master_controlling_tty, &term_settings);
tcgetattr(master_controlling_tty, &orig_settings);
cfmakeraw(&term_settings);
term_settings.c_cc[6] = 1;
term_settings.c_cc[5] = 1;
tcsetattr(master_controlling_tty, 0, &term_settings);
sigaction(17, &v16, 0LL);
sigaction(28, &v15, 0LL);
v6 = v5 / 64;
v7 = 1LL << (v5 % 64);
while ( 1 )
{
memset(&v11, 0, sizeof(v11));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
v11.fds_bits[v6] |= v7;
v8 = master_pty;
v11.fds_bits[master_pty / 64] |= 1LL << (master_pty % 64);
if ( v8 < 0 )
v8 = 0;
if ( v8 < v5 )
v8 = v5;
if ( select(v8 + 1, &v11, &writefds, &exceptfds, 0LL) != -1 )
{
if ( (v11.fds_bits[v6] & v7) != 0 )
{
v10 = read(v5, buf, 0x400uLL);
input_mangle(buf, v10);
write(master_pty, mangled_in, mangled_len);
}
if ( (v11.fds_bits[master_pty / 64] & (1LL << (master_pty % 64))) != 0 )
{
v9 = read(master_pty, buf, 0x400uLL);
write(1, buf, v9);
}
}
}
}
setenv("TERM", term, 1);
execvp(argv[1], (char *const *)argv + 1);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v5; // ebp
int v6; // er13
__int64 v7; // r12
int v8; // edi
int v9; // eax
int v10; // eax
fd_set v11; // [rsp+0h] [rbp-6E8h] BYREF
fd_set writefds; // [rsp+80h] [rbp-668h] BYREF
fd_set exceptfds; // [rsp+100h] [rbp-5E8h] BYREF
char buf[1024]; // [rsp+180h] [rbp-568h] BYREF
struct sigaction v15; // [rsp+580h] [rbp-168h] BYREF
struct sigaction v16; // [rsp+620h] [rbp-C8h] BYREF

memset(&v16.sa_mask, 0, 0x90uLL);
memset(&v15.sa_mask, 0, 0x90uLL);
v16.sa_handler = (__sighandler_t)sigchld_handler;
v15.sa_handler = (__sighandler_t)sigwinch_handler;
term = getenv("TERM");
state = 0;
mangled_len = 0;
command_count = 0;
v3 = open("/dev/null", 2);
if ( setupterm(0LL, v3, 0LL) == -1 )
{
fwrite("could not get terminfo.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
close(v3);
func12();
master_controlling_tty = open("/dev/tty", 258);
ioctl(master_controlling_tty, 0x5413uLL, &term_size);
if ( argc <= 1 )
{
fwrite("Improper number of arguments.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
pid = func10();
if ( pid )
{
v5 = dup(0);
tcgetattr(master_controlling_tty, &term_settings);
tcgetattr(master_controlling_tty, &orig_settings);
cfmakeraw(&term_settings);
term_settings.c_cc[6] = 1;
term_settings.c_cc[5] = 1;
tcsetattr(master_controlling_tty, 0, &term_settings);
sigaction(17, &v16, 0LL);
sigaction(28, &v15, 0LL);
v6 = v5 / 64;
v7 = 1LL << (v5 % 64);
while ( 1 )
{
memset(&v11, 0, sizeof(v11));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
v11.fds_bits[v6] |= v7;
v8 = master_pty;
v11.fds_bits[master_pty / 64] |= 1LL << (master_pty % 64);
if ( v8 < 0 )
v8 = 0;
if ( v8 < v5 )
v8 = v5;
if ( select(v8 + 1, &v11, &writefds, &exceptfds, 0LL) != -1 )
{
if ( (v11.fds_bits[v6] & v7) != 0 )
{
v10 = read(v5, buf, 0x400uLL);
func11(buf, v10);
write(master_pty, mangled_in, mangled_len);
}
if ( (v11.fds_bits[master_pty / 64] & (1LL << (master_pty % 64))) != 0 )
{
v9 = read(master_pty, buf, 0x400uLL);
write(1, buf, v9);
}
}
}
}
setenv("TERM", term, 1);
execvp(argv[1], (char *const *)argv + 1);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct sigaction chld;
 struct sigaction winch;
 int STUPID;
 memset(&chld, 0, sizeof(chld));
 memset(&winch, 0, sizeof(winch));
 chld.__sigaction_handler.sa_handler = &sigchld_handler;
 winch.__sigaction_handler.sa_handler = &sigwinch_handler;
 term = getenv("TERM");
 state = INSERT;
 mangled_len = 0;
 command_count = 0;
 STUPID = open("/dev/null", 02);
 if(setupterm((char *)0, STUPID, (int *)0) == (-1)) {
  fprintf(stderr, "could not get terminfo.\n");
  exit(1);
 }
 close(STUPID);
 setup_escape_seqs();
 master_controlling_tty = open("/dev/tty", 02 | 0400);
 ioctl(master_controlling_tty, 0x5413, &term_size);
 if(argc < 2) {
  fprintf(stderr, "Improper number of arguments.\n");
  exit(1);
 }
 if((pid = pty_fork()) == 0) {
  setenv("TERM", term, 1);
  execvp(argv[1], argv+1);
 } else {
  char in[1024];
  int ret;
  int standard_in = dup(0);
  tcgetattr(master_controlling_tty, &term_settings);
  tcgetattr(master_controlling_tty, &orig_settings);
  cfmakeraw(&term_settings);
  term_settings.c_cc[6] = 1;
  term_settings.c_cc[5] = 1;
  tcsetattr(master_controlling_tty, 0, &term_settings);
  sigaction(17, &chld, ((void *)0));
  sigaction(28, &winch, ((void *)0));
  while(1) {
   int nfds=0;
   int r;
   fd_set rd, wr, er;
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->fds_bits)[0]) : "memory"); } while (0);
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wr)->fds_bits)[0]) : "memory"); } while (0);
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&er)->fds_bits)[0]) : "memory"); } while (0);
   nfds = ((nfds) > (standard_in) ? (nfds) : (standard_in));
   ((void) (((&rd)->fds_bits)[((standard_in) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((standard_in) % (8 * (int) sizeof (__fd_mask)))))));
   nfds = ((nfds) > (master_pty) ? (nfds) : (master_pty));
   ((void) (((&rd)->fds_bits)[((master_pty) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((master_pty) % (8 * (int) sizeof (__fd_mask)))))));
   r = select(nfds+1, &rd, &wr, &er, ((void *)0));
   if(r == -1)
    continue;
   if(((((&rd)->fds_bits)[((standard_in) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((standard_in) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    ret = read(standard_in, in, 1024*sizeof(char));
    input_mangle(in, ret);
    write(master_pty, mangled_in, mangled_len*sizeof(char));
   }
   if(((((&rd)->fds_bits)[((master_pty) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((master_pty) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    ret = read(master_pty, in, 1024*sizeof(char));
    write(1, in, ret*sizeof(char));
   }
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct sigaction chld;
 struct sigaction winch;
 int STUPID;
 memset(&chld, 0, sizeof(chld));
 memset(&winch, 0, sizeof(winch));
 chld.__sigaction_handler.sa_handler = &sigchld_handler;
 winch.__sigaction_handler.sa_handler = &sigwinch_handler;
 term = getenv("TERM");
 state = INSERT;
 mangled_len = 0;
 command_count = 0;
 STUPID = open("/dev/null", 02);
 if(setupterm((char *)0, STUPID, (int *)0) == (-1)) {
  fprintf(stderr, "could not get terminfo.\n");
  exit(1);
 }
 close(STUPID);
 setup_escape_seqs();
 master_controlling_tty = open("/dev/tty", 02 | 0400);
 ioctl(master_controlling_tty, 0x5413, &term_size);
 if(argc < 2) {
  fprintf(stderr, "Improper number of arguments.\n");
  exit(1);
 }
 if((pid = pty_fork()) == 0) {
  setenv("TERM", term, 1);
  execvp(argv[1], argv+1);
 } else {
  char in[1024];
  int ret;
  int standard_in = dup(0);
  tcgetattr(master_controlling_tty, &term_settings);
  tcgetattr(master_controlling_tty, &orig_settings);
  cfmakeraw(&term_settings);
  term_settings.c_cc[6] = 1;
  term_settings.c_cc[5] = 1;
  tcsetattr(master_controlling_tty, 0, &term_settings);
  sigaction(17, &chld, ((void *)0));
  sigaction(28, &winch, ((void *)0));
  while(1) {
   int nfds = 0;
   int r;
   struct fd_set rd; struct fd_set wr; struct fd_set er;
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->fds_bits)[0]) : "memory"); } while (0);
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wr)->fds_bits)[0]) : "memory"); } while (0);
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&er)->fds_bits)[0]) : "memory"); } while (0);
   nfds = ((nfds) > (standard_in) ? (nfds) : (standard_in));
   ((void) (((&rd)->fds_bits)[((standard_in) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((standard_in) % (8 * (int) sizeof (__fd_mask)))))));
   nfds = ((nfds) > (master_pty) ? (nfds) : (master_pty));
   ((void) (((&rd)->fds_bits)[((master_pty) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((master_pty) % (8 * (int) sizeof (__fd_mask)))))));
   r = select(nfds+1, &rd, &wr, &er, ((void *)0));
   if(r == -1)
    continue;
   if(((((&rd)->fds_bits)[((standard_in) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((standard_in) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    ret = read(standard_in, in, 1024*sizeof(char));
    input_mangle(in, ret);
    write(master_pty, mangled_in, mangled_len*sizeof(char));
   }
   if(((((&rd)->fds_bits)[((master_pty) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((master_pty) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    ret = read(master_pty, in, 1024*sizeof(char));
    write(1, in, ret*sizeof(char));
   }
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, 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; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: STUPID int

variable_types:
in
char [1024]

variable_types: ret int

variable_types: nfds int

variable_types: r int

variable_types:
rd
struct fd_set { long fds_bits[-1]; }

variable_types:
wr
struct fd_set { long fds_bits[-1]; }

variable_types:
er
struct fd_set { long fds_bits[-1]; }

return_type: int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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; }


repo: jgunthorpe/ibsim

decompiled_code:
char *__fastcall get_name(struct in_addr *a1)
{
char *result; // rax

result = (char *)&a1->s_addr + 3;
if ( remote_mode )
result = inet_ntoa(a1[1]);
return result;
}

canonical_decompiled_code:
char *__fastcall func6(struct in_addr *a1)
{
char *result; // rax

result = (char *)&a1->s_addr + 3;
if ( remote_mode )
result = inet_ntoa(a1[1]);
return result;
}

original_code:
static char *get_name(union name_t *name)
{
 if (remote_mode)
  return inet_ntoa(name->name_i.sin_addr);
 else
  return name->name_u.sun_path + 1;
}

variable_types: union name_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } name; struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } name_u; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } name_i; } *

return_type: char *

user_defined_types: union name_t { struct sockaddr name; struct sockaddr_un name_u; struct sockaddr_in name_i; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 __fastcall sim_init(int *a1, const char *a2)
{
char *v2; // r14
char *v3; // r13
char *v4; // rax
int v5; // er12
int v6; // ebx
int v7; // er12
__int16 v8; // ax
socklen_t v9; // eax
int v10; // er12
__int16 v11; // ax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v19; // [rsp+4h] [rbp-C4h]
socklen_t len; // [rsp+1Ch] [rbp-ACh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF

v19 = getpid();
v2 = getenv("IBSIM_SERVER_PORT");
v3 = getenv("IBSIM_SERVER_NAME");
v4 = getenv("IBSIM_SOCKNAME");
if ( !v4 )
v4 = "sim";
socket_basename = (__int64)v4;
if ( v3 && *v3 )
{
remote_mode = 1;
v5 = 2;
}
else
{
v5 = 1 - ((remote_mode == 0) - 1);
}
v6 = socket(v5, 2, 0);
if ( v6 < 0 )
{
v13 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't get socket (fd): %m\n", v13, "sim_init");
exit(-1);
}
v7 = socket(v5, 2, 0);
if ( v7 < 0 )
{
v14 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't get socket (ctlfd): %m\n", v14, "sim_init");
exit(-1);
}
len = make_name((__int64)&addr, 0LL, 0, "%s:ctl%d", (const char *)socket_basename, v19);
if ( bind(v7, &addr, len) < 0 )
{
v15 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't bind ctl socket: %m\n", v15, "sim_init");
exit(-1);
}
v8 = 7070;
if ( v2 )
v8 = atoi(v2);
v9 = make_name((__int64)&addr, v3, v8, "%s:ctl", (const char *)socket_basename);
sim_attach(v7, &addr, v9);
a1[3] = v7;
len = make_name((__int64)&addr, 0LL, 0, "%s:in%d", (const char *)socket_basename, v19);
if ( bind(v6, &addr, len) < 0 )
{
v16 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't bind input socket: %m\n", v16, "sim_init");
exit(-1);
}
if ( getsockname(v6, &addr, &len) < 0 )
{
v17 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't read data from bound socket: %m\n", v17, "sim_init");
exit(-1);
}
if ( remote_mode )
v19 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
v10 = sim_connect(a1, v19, 0, a2);
*a1 = v10;
if ( v10 < 0 )
{
v18 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: connect failed: %m\n", v18, "sim_init");
exit(-1);
}
v11 = 7070;
if ( v2 )
v11 = atoi(v2);
len = make_name(
(__int64)&addr,
v3,
(unsigned __int16)v10 + v11 + 1,
"%s:out%d",
(const char *)socket_basename,
(unsigned int)v10);
sim_attach(v6, &addr, len);
a1[1] = v6;
a1[2] = v6;
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, const char *a2)
{
char *v2; // r14
char *v3; // r13
char *v4; // rax
int v5; // er12
int v6; // ebx
int v7; // er12
__int16 v8; // ax
socklen_t v9; // eax
int v10; // er12
__int16 v11; // ax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax
unsigned int v19; // [rsp+4h] [rbp-C4h]
socklen_t len; // [rsp+1Ch] [rbp-ACh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A8h] BYREF

v19 = getpid();
v2 = getenv("IBSIM_SERVER_PORT");
v3 = getenv("IBSIM_SERVER_NAME");
v4 = getenv("IBSIM_SOCKNAME");
if ( !v4 )
v4 = "sim";
socket_basename = (__int64)v4;
if ( v3 && *v3 )
{
remote_mode = 1;
v5 = 2;
}
else
{
v5 = 1 - ((remote_mode == 0) - 1);
}
v6 = socket(v5, 2, 0);
if ( v6 < 0 )
{
v13 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't get socket (fd): %m\n", v13, "sim_init");
exit(-1);
}
v7 = socket(v5, 2, 0);
if ( v7 < 0 )
{
v14 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't get socket (ctlfd): %m\n", v14, "sim_init");
exit(-1);
}
len = func5((__int64)&addr, 0LL, 0, "%s:ctl%d", (const char *)socket_basename, v19);
if ( bind(v7, &addr, len) < 0 )
{
v15 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't bind ctl socket: %m\n", v15, "sim_init");
exit(-1);
}
v8 = 7070;
if ( v2 )
v8 = atoi(v2);
v9 = func5((__int64)&addr, v3, v8, "%s:ctl", (const char *)socket_basename);
func7(v7, &addr, v9);
a1[3] = v7;
len = func5((__int64)&addr, 0LL, 0, "%s:in%d", (const char *)socket_basename, v19);
if ( bind(v6, &addr, len) < 0 )
{
v16 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't bind input socket: %m\n", v16, "sim_init");
exit(-1);
}
if ( getsockname(v6, &addr, &len) < 0 )
{
v17 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: can't read data from bound socket: %m\n", v17, "sim_init");
exit(-1);
}
if ( remote_mode )
v19 = (unsigned __int16)func2(*(__int16 *)addr.sa_data);
v10 = func3(a1, v19, 0, a2);
*a1 = v10;
if ( v10 < 0 )
{
v18 = getpid();
fprintf(stderr, "ibpanic: [%d] %s: connect failed: %m\n", v18, "sim_init");
exit(-1);
}
v11 = 7070;
if ( v2 )
v11 = atoi(v2);
len = func5(
(__int64)&addr,
v3,
(unsigned __int16)v10 + v11 + 1,
"%s:out%d",
(const char *)socket_basename,
(unsigned int)v10);
func7(v6, &addr, len);
a1[1] = v6;
a1[2] = v6;
return (unsigned int)v6;
}

original_code:
static int sim_init(struct sim_client *sc, char *nodeid)
{
 union name_t name;
 socklen_t size;
 int fd, ctlfd;
 int pid = getpid();
 char *connect_port;
 char *connect_host;
 unsigned short port;
 connect_port = getenv("IBSIM_SERVER_PORT");
 connect_host = getenv("IBSIM_SERVER_NAME");
 socket_basename = getenv("IBSIM_SOCKNAME");
 if(!socket_basename)
  socket_basename = "sim";
 if (connect_host && *connect_host)
  remote_mode = 1;
 ;
 if ((fd = socket(remote_mode ? 2 : 1, SOCK_DGRAM, 0)) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't get socket (fd)" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 if ((ctlfd = socket(remote_mode ? 2 : 1, SOCK_DGRAM, 0)) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't get socket (ctlfd)" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 size = make_name(&name, ((void *)0), 0, "%s:ctl%d", socket_basename, pid);
 if (bind(ctlfd, (struct sockaddr *)&name, size) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't bind ctl socket" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 ;
 port = connect_port ? atoi(connect_port) : 7070;
 size = make_name(&name, connect_host, port, "%s:ctl", socket_basename);
 sim_attach(ctlfd, &name, size);
 sc->fd_ctl = ctlfd;
 size = make_name(&name, ((void *)0), 0, "%s:in%d", socket_basename, pid);
 if (bind(fd, (struct sockaddr *)&name, size) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't bind input socket" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 ;
 if (getsockname(fd, (struct sockaddr *)&name, &size) < 0 )
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't read data from bound socket" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 port = ntohs(name.name_i.sin_port);
 sc->clientid = sim_connect(sc, remote_mode ? port : pid, 0, nodeid);
 if (sc->clientid < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "connect failed" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 port = connect_port ? atoi(connect_port) : 7070;
 size = make_name(&name, connect_host, port + sc->clientid + 1,
    "%s:out%d", socket_basename, sc->clientid);
 sim_attach(fd, &name, size);
 ;
 sc->fd_pktin = fd;
 sc->fd_pktout = fd;
 return fd;
}

canonical_original_code:
static int sim_init(struct sim_client *sc, char *nodeid)
{
 union name_t name;
 unsigned int size;
 int fd; int ctlfd;
 int pid = getpid();
 char *connect_port;
 char *connect_host;
 unsigned short port;
 connect_port = getenv("IBSIM_SERVER_PORT");
 connect_host = getenv("IBSIM_SERVER_NAME");
 socket_basename = getenv("IBSIM_SOCKNAME");
 if(!socket_basename)
  socket_basename = "sim";
 if (connect_host && *connect_host)
  remote_mode = 1;
 ;
 if ((fd = socket(remote_mode ? 2 : 1, SOCK_DGRAM, 0)) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't get socket (fd)" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 if ((ctlfd = socket(remote_mode ? 2 : 1, SOCK_DGRAM, 0)) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't get socket (ctlfd)" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 size = make_name(&name, ((void *)0), 0, "%s:ctl%d", socket_basename, pid);
 if (bind(ctlfd, (struct sockaddr *)&name, size) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't bind ctl socket" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 ;
 port = connect_port ? atoi(connect_port) : 7070;
 size = make_name(&name, connect_host, port, "%s:ctl", socket_basename);
 sim_attach(ctlfd, &name, size);
 sc->fd_ctl = ctlfd;
 size = make_name(&name, ((void *)0), 0, "%s:in%d", socket_basename, pid);
 if (bind(fd, (struct sockaddr *)&name, size) < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't bind input socket" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 ;
 if (getsockname(fd, (struct sockaddr *)&name, &size) < 0 )
  do { fprintf(stderr, "ibpanic: [%d] %s: " "can't read data from bound socket" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 port = ntohs(name.name_i.sin_port);
 sc->clientid = sim_connect(sc, remote_mode ? port : pid, 0, nodeid);
 if (sc->clientid < 0)
  do { fprintf(stderr, "ibpanic: [%d] %s: " "connect failed" ": %m\n", (int)getpid(), __func__); exit(-1); } while(0);
 port = connect_port ? atoi(connect_port) : 7070;
 size = make_name(&name, connect_host, port + sc->clientid + 1,
    "%s:out%d", socket_basename, sc->clientid);
 sim_attach(fd, &name, size);
 ;
 sc->fd_pktin = fd;
 sc->fd_pktout = fd;
 return fd;
}

variable_types: struct sim_client { int clientid; int fd_pktin; struct sim_vendor { unsigned int vendor_id; unsigned int vendor_part_id; unsigned int hw_ver; unsigned long fw_ver; } vendor; unsigned char nodeinfo[64]; unsigned char portinfo[64]; unsigned short pkeys[-1]; } *

variable_types:
nodeid
char *

variable_types: union name_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } name; struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } name_u; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } name_i; }

variable_types:
size
unsigned int

variable_types: fd int

variable_types: ctlfd int

variable_types: pid int

variable_types:
port
unsigned short

user_defined_types: struct sim_client { int clientid; int fd_pktin; struct sim_vendor vendor; unsigned char nodeinfo[64]; unsigned char portinfo[64]; unsigned short pkeys[-1]; }


decompiled_code:
__int64 __fastcall sim_client_set_sm(_DWORD *a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return sim_ctl(a1, 9u, v3, 4);
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func0(a1, 9u, v3, 4);
}

original_code:
int sim_client_set_sm(struct sim_client *sc, unsigned issm)
{
 ;
 return sim_ctl(sc, SIM_CTL_SET_ISSM, &issm, sizeof(int));
}

canonical_original_code:
int sim_client_set_sm(struct sim_client *sc, unsigned int issm)
{
 ;
 return sim_ctl(sc, SIM_CTL_SET_ISSM, &issm, sizeof(int));
}

variable_types:
issm
unsigned int

user_defined_types: struct sim_vendor { unsigned int vendor_id; unsigned int vendor_part_id; unsigned int hw_ver; unsigned long fw_ver; }


decompiled_code:
__int64 __fastcall sim_client_init(__int64 a1)
{
char *v1; // rax
char *v2; // rdx
__int64 result; // rax

v1 = getenv("SIM_HOST");
if ( (int)sim_init((int *)a1, v1) < 0 )
return 0xFFFFFFFFLL;
if ( (int)sim_ctl((_DWORD *)a1, 4u, (void *)(a1 + 16), 24) < 0
|| (int)sim_ctl((_DWORD *)a1, 7u, (void *)(a1 + 40), 64) < 0
|| (*(_BYTE *)(a1 + 104) = 0, (int)sim_ctl((_DWORD *)a1, 8u, (void *)(a1 + 104), 64) < 0)
|| (int)sim_ctl((_DWORD *)a1, 0xAu, (void *)(a1 + 168), 64) < 0 )
{
sim_disconnect((_DWORD *)a1);
*(_DWORD *)(a1 + 8) = -1;
*(_DWORD *)(a1 + 4) = -1;
*(_DWORD *)(a1 + 12) = -1;
result = 0xFFFFFFFFLL;
}
else
{
v2 = getenv("SIM_SET_ISSM");
result = 0LL;
if ( v2 )
{
sim_client_set_sm((_DWORD *)a1, 1);
result = 0LL;
}
}
return result;
}

original_code:
int sim_client_init(struct sim_client *sc)
{
 char *nodeid;
 nodeid = getenv("SIM_HOST");
 if (sim_init(sc, nodeid) < 0)
  return -1;
 if (sim_ctl(sc, SIM_CTL_GET_VENDOR, &sc->vendor,
      sizeof(sc->vendor)) < 0)
  goto _exit;
 if (sim_ctl(sc, SIM_CTL_GET_NODEINFO, sc->nodeinfo,
      sizeof(sc->nodeinfo)) < 0)
  goto _exit;
 sc->portinfo[0] = 0;
 if (sim_ctl(sc, SIM_CTL_GET_PORTINFO, sc->portinfo,
      sizeof(sc->portinfo)) < 0)
  goto _exit;
 if (sim_ctl(sc, SIM_CTL_GET_PKEYS, sc->pkeys, sizeof(sc->pkeys)) < 0)
  goto _exit;
 if (getenv("SIM_SET_ISSM"))
  sim_client_set_sm(sc, 1);
 return 0;
  _exit:
 sim_disconnect(sc);
 sc->fd_ctl = sc->fd_pktin = sc->fd_pktout = -1;
 return -1;
}


decompiled_code:
__int64 __fastcall sim_client_exit(_DWORD *a1)
{
__int64 result; // rax

result = sim_disconnect(a1);
a1[2] = -1;
a1[1] = -1;
a1[3] = -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
__int64 result; // rax

result = func1(a1);
a1[2] = -1;
a1[1] = -1;
a1[3] = -1;
return result;
}

original_code:
void sim_client_exit(struct sim_client *sc)
{
 sim_disconnect(sc);
 sc->fd_ctl = sc->fd_pktin = sc->fd_pktout = -1;
}

return_type: void


decompiled_code:
char *__fastcall print_path(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
int v3; // ebp
unsigned __int8 *v4; // rax
char *result; // rax

v2 = a1;
v3 = 0;
do
{
v3 += snprintf(&buf_0[v3], 256LL - v3, "%u,", *v2);
v4 = v2++;
}
while ( &a1[a2] != v4 );
result = buf_0;
buf_0[v3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
int v3; // ebp
unsigned __int8 *v4; // rax
char *result; // rax

v2 = a1;
v3 = 0;
do
{
v3 += snprintf(&buf_0[v3], 256LL - v3, "%u,", *v2);
v4 = v2++;
}
while ( &a1[a2] != v4 );
result = buf_0;
buf_0[v3] = 0;
return result;
}

original_code:
static const char *print_path(uint8_t path[], size_t path_cnt)
{
 static char buf[256];
 int i, n = 0;
 for (i = 0; i <= path_cnt; i++)
  n += snprintf(buf + n, sizeof(buf) - n, "%u,", path[i]);
 buf[n] = '\0';
 return buf;
}

canonical_original_code:
static char *print_path(unsigned char path[], unsigned long path_cnt)
{
 static char buf[256];
 int i; int n = 0;
 for (i = 0; i <= path_cnt; i++)
  n += snprintf(buf + n, sizeof(buf) - n, "%u,", path[i]);
 buf[n] = '\0';
 return buf;
}

variable_types:
path
unsigned char []

variable_types:
buf
char [256]

variable_types: i int

variable_types: n int


query

decompiled_code:
__int64 __fastcall query(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
void *v7; // rax
void *v8; // r12
__int64 v9; // rbx
__int64 v10; // rcx
unsigned int v11; // ebp
int v12; // ebx
__int64 v14[15]; // [rsp+0h] [rbp-78h] BYREF

v14[2] = 0LL;
v14[3] = 0LL;
v14[4] = 0LL;
v14[5] = 0LL;
v14[6] = 0LL;
v14[7] = 0LL;
v6 = umad_size(a1, a2, a3, a4, a5, a6, 0LL, 0LL);
v7 = malloc(v6 + 256);
if ( v7 )
{
v8 = v7;
if ( number_queries )
{
v9 = 537460736LL;
do
{
v10 = v9++;
send_query(a1, a2, v8, v10, dr_path, dr_path_size, attribute_id, attribute_mod);
}
while ( number_queries > (unsigned int)(v9 - 537460736) );
}
v11 = 0;
do
{
v12 = recv_response(a1, a2, (__int64)v8, (unsigned __int8 *)v14);
if ( v12 < 0 )
break;
++v11;
}
while ( number_queries > v11 );
free(v8);
}
else
{
v12 = -12;
}
return (unsigned int)v12;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
void *v7; // rax
void *v8; // r12
__int64 v9; // rbx
__int64 v10; // rcx
unsigned int v11; // ebp
int v12; // ebx
__int64 v14[15]; // [rsp+0h] [rbp-78h] BYREF

v14[2] = 0LL;
v14[3] = 0LL;
v14[4] = 0LL;
v14[5] = 0LL;
v14[6] = 0LL;
v14[7] = 0LL;
v6 = umad_size(a1, a2, a3, a4, a5, a6, 0LL, 0LL);
v7 = malloc(v6 + 256);
if ( v7 )
{
v8 = v7;
if ( number_queries )
{
v9 = 537460736LL;
do
{
v10 = v9++;
func4(a1, a2, v8, v10, dr_path, dr_path_size, attribute_id, attribute_mod);
}
while ( number_queries > (unsigned int)(v9 - 537460736) );
}
v11 = 0;
do
{
v12 = func5(a1, a2, (__int64)v8, (unsigned __int8 *)v14);
if ( v12 < 0 )
break;
++v11;
}
while ( number_queries > v11 );
free(v8);
}
else
{
v12 = -12;
}
return (unsigned int)v12;
}

original_code:
static int query(int fd, int agent)
{
 uint8_t path[64] = { 0 };
 uint64_t trid = 0x20090000;
 void *umad;
 unsigned n = 0;
 int ret = 0;
 umad = malloc(256 + umad_size());
 if (!umad)
  return -12;
 while (n++ < number_queries)
  send_query(fd, agent, umad, trid++, dr_path, dr_path_size,
      attribute_id, attribute_mod);
 n = 0;
 do {
  ret = recv_response(fd, agent, umad, path);
 } while (ret >= 0 && ++n < number_queries);
 free(umad);
 return ret;
}

canonical_original_code:
static int query(int fd, int agent)
{
 unsigned char path[64] = { 0 };
 unsigned long trid = 0x20090000;
 void *umad;
 unsigned int n = 0;
 int ret = 0;
 umad = malloc(256 + umad_size());
 if (!umad)
  return -12;
 while (n++ < number_queries)
  send_query(fd, agent, umad, trid++, dr_path, dr_path_size,
      attribute_id, attribute_mod);
 n = 0;
 do {
  ret = recv_response(fd, agent, umad, path);
 } while (ret >= 0 && ++n < number_queries);
 free(umad);
 return ret;
}

variable_types: agent int

variable_types:
path
unsigned char [64]

variable_types:
trid
unsigned long

variable_types:
umad
void *

variable_types:
n
unsigned int

variable_types: ret int


decompiled_code:
__int64 __fastcall umad_query(const char *a1, unsigned int a2)
{
const char *v2; // r12
int v3; // eax
unsigned int v4; // ebx
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
unsigned int v10; // ebp
unsigned int v11; // er12
int *v13; // rax
char *v14; // r8
int *v15; // rax
char *v16; // r8

v2 = a1;
if ( (unsigned int)umad_init() )
{
fwrite("ERR: cannot init umad\n", 1uLL, 0x16uLL, stderr);
v11 = -1;
}
else
{
v3 = umad_open_port(a1, a2);
v4 = v3;
if ( v3 < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
if ( !a1 )
v2 = "NULL";
fprintf(stderr, "ERR: cannot open umad port %s:%u: %s\n", v2, a2, v14);
v11 = -1;
}
else
{
v5 = umad_register((unsigned int)v3, 129LL, 1LL, 0LL, 0LL);
v10 = v5;
if ( v5 < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
if ( !a1 )
v2 = "NULL";
fprintf(stderr, "ERR: cannot register SMI DR class for umad port %s:%u: %s\n", v2, a2, v16);
v11 = -1;
}
else
{
v11 = query(v4, (unsigned int)v5, v6, v7, v8, v9);
if ( v11 )
fwrite("ERR: Failed.\n", 1uLL, 0xDuLL, stderr);
umad_unregister(v4, v10);
umad_close_port(v4);
umad_done();
}
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, unsigned int a2)
{
const char *v2; // r12
int v3; // eax
unsigned int v4; // ebx
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
unsigned int v10; // ebp
unsigned int v11; // er12
int *v13; // rax
char *v14; // r8
int *v15; // rax
char *v16; // r8

v2 = a1;
if ( (unsigned int)umad_init() )
{
fwrite("ERR: cannot init umad\n", 1uLL, 0x16uLL, stderr);
v11 = -1;
}
else
{
v3 = umad_open_port(a1, a2);
v4 = v3;
if ( v3 < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
if ( !a1 )
v2 = "NULL";
fprintf(stderr, "ERR: cannot open umad port %s:%u: %s\n", v2, a2, v14);
v11 = -1;
}
else
{
v5 = umad_register((unsigned int)v3, 129LL, 1LL, 0LL, 0LL);
v10 = v5;
if ( v5 < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
if ( !a1 )
v2 = "NULL";
fprintf(stderr, "ERR: cannot register SMI DR class for umad port %s:%u: %s\n", v2, a2, v16);
v11 = -1;
}
else
{
v11 = func6(v4, (unsigned int)v5, v6, v7, v8, v9);
if ( v11 )
fwrite("ERR: Failed.\n", 1uLL, 0xDuLL, stderr);
umad_unregister(v4, v10);
umad_close_port(v4);
umad_done();
}
}
}
return v11;
}

original_code:
static int umad_query(char *card_name, unsigned int port_num)
{
 int fd, agent, ret;
 ret = umad_init();
 if (ret) {
  fprintf(stderr, "ERR: " "cannot init umad\n");
  return -1;
 }
 fd = umad_open_port(card_name, port_num);
 if (fd < 0) {
  fprintf(stderr, "ERR: " "cannot open umad port %s:%u: %s\n", card_name ? card_name : "NULL", port_num, strerror((*__errno_location ())));
  return -1;
 }
 agent = umad_register(fd, IB_SMI_DIRECT_CLASS, 1, 0, ((void *)0));
 if (agent < 0) {
  fprintf(stderr, "ERR: " "cannot register SMI DR class for umad port %s:%u: %s\n", card_name ? card_name : "NULL", port_num, strerror((*__errno_location ())));
  return -1;
 }
 ret = query(fd, agent);
 if (ret)
  fprintf(stderr, "ERR: " "Failed.\n");
 umad_unregister(fd, agent);
 umad_close_port(fd);
 umad_done();
 return ret;
}

canonical_original_code:
static int umad_query(char *card_name, unsigned int port_num)
{
 int fd; int agent; int ret;
 ret = umad_init();
 if (ret) {
  fprintf(stderr, "ERR: " "cannot init umad\n");
  return -1;
 }
 fd = umad_open_port(card_name, port_num);
 if (fd < 0) {
  fprintf(stderr, "ERR: " "cannot open umad port %s:%u: %s\n", card_name ? card_name : "NULL", port_num, strerror((*__errno_location ())));
  return -1;
 }
 agent = umad_register(fd, IB_SMI_DIRECT_CLASS, 1, 0, ((void *)0));
 if (agent < 0) {
  fprintf(stderr, "ERR: " "cannot register SMI DR class for umad port %s:%u: %s\n", card_name ? card_name : "NULL", port_num, strerror((*__errno_location ())));
  return -1;
 }
 ret = query(fd, agent);
 if (ret)
  fprintf(stderr, "ERR: " "Failed.\n");
 umad_unregister(fd, agent);
 umad_close_port(fd);
 umad_done();
 return ret;
}


decompiled_code:
__int64 __fastcall c_rev(const char *a1)
{
__int64 result; // rax
__int64 v2; // rdx
char v3; // cl

result = (unsigned int)strlen(a1) - 1;
if ( (int)result > 0 )
{
result = (int)result;
v2 = 0LL;
do
{
v3 = a1[result];
a1[result] = a1[v2];
a1[v2++] = v3;
--result;
}
while ( (int)result > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
__int64 result; // rax
__int64 v2; // rdx
char v3; // cl

result = (unsigned int)strlen(a1) - 1;
if ( (int)result > 0 )
{
result = (int)result;
v2 = 0LL;
do
{
v3 = a1[result];
a1[result] = a1[v2];
a1[v2++] = v3;
--result;
}
while ( (int)result > (int)v2 );
}
return result;
}

original_code:
void c_rev(char *in)
{
  int len = strlen(in);
  len--;
  int i;
  for(i = 0; i < len; i++){
    char tmp;
    tmp = in[len];
    in[len] = in[i];
    in[i] = tmp;
    len--;
  }
  return;
}

variable_types:
in
char *

variable_types: len int

variable_types: tmp char


itohexs

decompiled_code:
char *__fastcall itohexs(unsigned int a1)
{
char *v1; // rbx

v1 = (char *)malloc(0x400uLL);
sprintf(v1, "%x", a1);
return v1;
}

canonical_decompiled_code:
char *__fastcall func9(unsigned int a1)
{
char *v1; // rbx

v1 = (char *)malloc(0x400uLL);
sprintf(v1, "%x", a1);
return v1;
}

original_code:
char *itohexs(int b)
{
  char *new =(char *)malloc(sizeof(char)*1024);
  sprintf(new, "%x", b);
  return new;
}

canonical_original_code:
char *itohexs(int b)
{
  char *new = (char *)malloc(sizeof(char)*1024);
  sprintf(new, "%x", b);
  return new;
}

variable_types: b int

variable_types:
new
char *


itoocts

decompiled_code:
const char *__fastcall itoocts(int a1)
{
int v1; // ebx
const char *v2; // rbp
__int64 v3; // rcx
int v4; // eax

v1 = a1;
v2 = (const char *)malloc(0x400uLL);
if ( a1 )
{
v3 = 1LL;
do
{
v2[v3 - 1] = v1 % 8 + 48;
v4 = v3++;
v1 >>= 3;
}
while ( v1 );
}
else
{
v4 = 0;
}
v2[v4] = 0;
c_rev(v2);
return v2;
}

canonical_decompiled_code:
const char *__fastcall func10(int a1)
{
int v1; // ebx
const char *v2; // rbp
__int64 v3; // rcx
int v4; // eax

v1 = a1;
v2 = (const char *)malloc(0x400uLL);
if ( a1 )
{
v3 = 1LL;
do
{
v2[v3 - 1] = v1 % 8 + 48;
v4 = v3++;
v1 >>= 3;
}
while ( v1 );
}
else
{
v4 = 0;
}
v2[v4] = 0;
func7(v2);
return v2;
}

original_code:
char *itoocts(int b)
{
  char *new = (char *)malloc(sizeof(char)*1024);
  int i = 0;
  while(b){
    new[i] = (char)(((int)'0')+(b%8));
    b >>=3;
    i++;
  }
  new[i] = '\0';
  c_rev(new);
  return new;
}


decompiled_code:
char *__fastcall trim_newline(char *s)
{
char *v1; // rbp
char *result; // rax

v1 = &s[(int)strlen(s) - 1];
if ( *v1 != 10 )
return strdup(s);
*v1 = 0;
result = strdup(s);
*v1 = 10;
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char *s)
{
char *v1; // rbp
char *result; // rax

v1 = &s[(int)strlen(s) - 1];
if ( *v1 != 10 )
return strdup(s);
*v1 = 0;
result = strdup(s);
*v1 = 10;
return result;
}

original_code:
char *trim_newline(char *s)
{
  char *t;
  int n = strlen(s);
  int must_change = (s[n-1]=='\n');
  if (must_change)
    s[n-1] = '\0';
  t = strdup(s);
  if (must_change)
    s[n-1] = '\n';
  return t;
}

variable_types:
s
char *

variable_types:
t
char *


godown

decompiled_code:
__int64 __fastcall godown(unsigned int a1)
{
__int64 result; // rax

result = a1 + 32;
if ( (unsigned int)((char)a1 - 65) >= 0x1A )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
__int64 result; // rax

result = a1 + 32;
if ( (unsigned int)((char)a1 - 65) >= 0x1A )
result = a1;
return result;
}

original_code:
char godown(char in)
{
  int final = (int)in;
  if(final <= 90 && final >= 65){
    return (char)(final + 32);
  }
  else
    return in;
}

variable_types: in char

variable_types: final int

return_type: char


decompiled_code:
size_t __fastcall tolower_s(const char *a1)
{
size_t result; // rax
char *v2; // rbx
__int64 v3; // rbp

result = strlen(a1);
if ( (int)result > 0 )
{
v2 = (char *)a1;
v3 = (__int64)&a1[(unsigned int)(result - 1) + 1];
do
{
result = godown(*v2);
*v2++ = result;
}
while ( v2 != (char *)v3 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func13(const char *a1)
{
size_t result; // rax
char *v2; // rbx
__int64 v3; // rbp

result = strlen(a1);
if ( (int)result > 0 )
{
v2 = (char *)a1;
v3 = (__int64)&a1[(unsigned int)(result - 1) + 1];
do
{
result = func12(*v2);
*v2++ = result;
}
while ( v2 != (char *)v3 );
}
return result;
}

original_code:
void tolower_s(char *in)
{
  int len = strlen(in);
  int i;
  for(i = 0; i < len; i++){
    in[i] = godown(in[i]);
  }
}

variable_types: i int


decompiled_code:
int __fastcall dec_to_etc(char *s2, const char *a2, unsigned int a3)
{
char *v5; // rbx
char v6[1064]; // [rsp+0h] [rbp-428h] BYREF

while ( 1 )
{
fprintf(_bss_start, "What is the %s representation of %d?\n", a2, a3);
fwrite("Answer: ", 1uLL, 8uLL, _bss_start);
fgets(v6, 1024, stdin);
v5 = trim_newline(v6);
tolower_s(v5);
if ( !strcmp("give", v5) )
{
fprintf(_bss_start, "\nThe correct response was: %s\n", s2);
fwrite("Press enter to continue.", 1uLL, 0x18uLL, _bss_start);
fgetc(stdin);
return putchar(10);
}
if ( !strcmp(v5, s2) )
break;
fwrite("Incorrect. Please try again or type 'give' to give up\n\n", 1uLL, 0x37uLL, _bss_start);
}
fwrite("Correct!\n", 1uLL, 9uLL, _bss_start);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func14(char *s2, const char *a2, unsigned int a3)
{
char *v5; // rbx
char v6[1064]; // [rsp+0h] [rbp-428h] BYREF

while ( 1 )
{
fprintf(_bss_start, "What is the %s representation of %d?\n", a2, a3);
fwrite("Answer: ", 1uLL, 8uLL, _bss_start);
fgets(v6, 1024, stdin);
v5 = func11(v6);
func13(v5);
if ( !strcmp("give", v5) )
{
fprintf(_bss_start, "\nThe correct response was: %s\n", s2);
fwrite("Press enter to continue.", 1uLL, 0x18uLL, _bss_start);
fgetc(stdin);
return putchar(10);
}
if ( !strcmp(v5, s2) )
break;
fwrite("Incorrect. Please try again or type 'give' to give up\n\n", 1uLL, 0x37uLL, _bss_start);
}
fwrite("Correct!\n", 1uLL, 9uLL, _bss_start);
return putchar(10);
}

original_code:
void dec_to_etc(char *ans, char *type, int dec_val)
{
  char new0[1024];
  while(1){
    fprintf(stdout, "What is the %s representation of %d?\n", type, dec_val);
    fprintf(stdout, "Answer: ");
    fgets(new0, 1024, stdin);
    char *new = trim_newline(new0);
    tolower_s(new);
    if(!strcmp("give", new)){
      fprintf(stdout, "\nThe correct response was: %s\n", ans);
      fprintf(stdout, "Press enter to continue.");
      fgetc(stdin);
      putchar('\n');
      break;
    }
    if(!strcmp(new, ans)){
      fprintf(stdout, "Correct!\n");
      putchar('\n');
      break;
    }
    else{
      fprintf(stdout, "Incorrect. Please try again or type 'give' to give up\n\n");
    }
  }
  return;
}

variable_types:
ans
char *

variable_types:
type
char *


decompiled_code:
char *__fastcall extract_arg(__int64 a1, _DWORD *a2)
{
char *v2; // rax
char v4[100]; // [rsp+0h] [rbp-78h] BYREF
char v5; // [rsp+64h] [rbp-14h] BYREF

v2 = v4;
do
*v2++ = 0;
while ( v2 != &v5 );
__isoc99_sscanf();
*a2 = v4[0] != 0;
return strdup(v4);
}

canonical_decompiled_code:
char *__fastcall func15(__int64 a1, _DWORD *a2)
{
char *v2; // rax
char v4[100]; // [rsp+0h] [rbp-78h] BYREF
char v5; // [rsp+64h] [rbp-14h] BYREF

v2 = v4;
do
*v2++ = 0;
while ( v2 != &v5 );
__isoc99_sscanf();
*a2 = v4[0] != 0;
return strdup(v4);
}

original_code:
char *extract_arg(char *cmd, int *parse_succeeded)
{
  int i;
  char cmdbuf[2];
  char argbuf[100];
  for (i=0; i<100; i++)
    argbuf[i] = '\0';
  sscanf(cmd,"%s %s",cmdbuf,argbuf);
  *parse_succeeded = strlen(argbuf)>0;
  return strdup(argbuf);
}

variable_types:
cmd
char *

variable_types:
cmdbuf
char [2]

variable_types:
argbuf
char [100]


decompiled_code:
int __fastcall set_cmd_vars(__int64 a1, _DWORD *a2, int *a3)
{
char *v4; // rax
int result; // eax
unsigned int v6; // eax
int v7; // edx

v4 = extract_arg(a1, a2);
if ( *a2 )
{
result = atoi(v4);
*a3 = result;
}
else
{
v6 = time(0LL);
srand(v6);
v7 = rand();
result = 100 * (v7 / 100);
*a3 = v7 % 100;
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, _DWORD *a2, int *a3)
{
char *v4; // rax
int result; // eax
unsigned int v6; // eax
int v7; // edx

v4 = func15(a1, a2);
if ( *a2 )
{
result = atoi(v4);
*a3 = result;
}
else
{
v6 = time(0LL);
srand(v6);
v7 = rand();
result = 100 * (v7 / 100);
*a3 = v7 % 100;
}
return result;
}

original_code:
void set_cmd_vars(char *cmd, int *parse_succeeded, int *num)
{
  char *optnum = extract_arg(cmd, parse_succeeded);
  if (*parse_succeeded) {
    *num = atoi(optnum);
  }
  else{
    srand(time(((void *)0)));
    *num = rand()%100;
  }
}

variable_types:
num
int *

variable_types:
optnum
char *


decompiled_code:
__int64 __fastcall process_cmd(const char *a1, _DWORD *a2)
{
char v2; // al
__int64 result; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
unsigned int v8; // [rsp+8h] [rbp-10h] BYREF
_DWORD v9[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8 = 0;
v2 = *a1;
if ( *a1 == 104 )
{
set_cmd_vars((__int64)a1, v9, (int *)&v8);
v6 = itohexs(v8);
dec_to_etc(v6, "hexadecimal", v8);
result = 1LL;
}
else if ( v2 <= 104 )
{
if ( v2 == 63 )
{
fwrite("-\tEntering b, h, or o asks you to write a decimal number ", 1uLL, 0x39uLL, _bss_start);
fwrite("in binary, hexadecimal, and octal respectively\n", 1uLL, 0x2FuLL, _bss_start);
fwrite("-\tWriting a number next to an option will replace ", 1uLL, 0x32uLL, _bss_start);
fwrite("a random number with the number you specify.\n\n", 1uLL, 0x2EuLL, _bss_start);
result = 1LL;
}
else if ( v2 == 98 )
{
set_cmd_vars((__int64)a1, v9, (int *)&v8);
v4 = bsint(v8);
v5 = trun_binary_int(v4);
dec_to_etc(v5, "binary", v8);
result = 1LL;
}
else
{
result = 0LL;
}
}
else if ( v2 == 111 )
{
set_cmd_vars((__int64)a1, v9, (int *)&v8);
v7 = (char *)itoocts(v8);
dec_to_etc(v7, "octal", v8);
result = 1LL;
}
else if ( v2 == 113 )
{
result = 0LL;
if ( !strcmp(a1, "q") )
{
*a2 = 1;
result = 1LL;
}
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1, _DWORD *a2)
{
char v2; // al
__int64 result; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
unsigned int v8; // [rsp+8h] [rbp-10h] BYREF
_DWORD v9[3]; // [rsp+Ch] [rbp-Ch] BYREF

v8 = 0;
v2 = *a1;
if ( *a1 == 104 )
{
func16((__int64)a1, v9, (int *)&v8);
v6 = func9(v8);
func14(v6, "hexadecimal", v8);
result = 1LL;
}
else if ( v2 <= 104 )
{
if ( v2 == 63 )
{
fwrite("-\tEntering b, h, or o asks you to write a decimal number ", 1uLL, 0x39uLL, _bss_start);
fwrite("in binary, hexadecimal, and octal respectively\n", 1uLL, 0x2FuLL, _bss_start);
fwrite("-\tWriting a number next to an option will replace ", 1uLL, 0x32uLL, _bss_start);
fwrite("a random number with the number you specify.\n\n", 1uLL, 0x2EuLL, _bss_start);
result = 1LL;
}
else if ( v2 == 98 )
{
func16((__int64)a1, v9, (int *)&v8);
v4 = func8(v8);
v5 = trun_binary_int(v4);
func14(v5, "binary", v8);
result = 1LL;
}
else
{
result = 0LL;
}
}
else if ( v2 == 111 )
{
func16((__int64)a1, v9, (int *)&v8);
v7 = (char *)func10(v8);
func14(v7, "octal", v8);
result = 1LL;
}
else if ( v2 == 113 )
{
result = 0LL;
if ( !strcmp(a1, "q") )
{
*a2 = 1;
result = 1LL;
}
}
else
{
result = 0LL;
}
return result;
}

original_code:
int process_cmd(char *cmd, int *quit)
{
  int parse_succeeded;
  char *ans;
  int num = 0;
  switch (cmd[0]) {
  case 'q':
    if (strcmp(cmd,"q")==0) {
      *quit = 1;
      return 1;
    }
    return 0;
  case 'b':
    set_cmd_vars(cmd, &parse_succeeded, &num);
    ans = trun_binary_int(bsint(num));
    dec_to_etc(ans, "binary", num);
    return 1;
  case 'h':
    set_cmd_vars(cmd, &parse_succeeded, &num);
    ans = itohexs(num);
    dec_to_etc(ans, "hexadecimal", num);
    return 1;
  case 'o':
    set_cmd_vars(cmd, &parse_succeeded, &num);
    ans = itoocts(num);
    dec_to_etc(ans, "octal", num);
    return 1;
  case '?':
    fprintf(stdout, "-\tEntering b, h, or o asks you to write a decimal number ");
    fprintf(stdout, "in binary, hexadecimal, and octal respectively\n");
    fprintf(stdout, "-\tWriting a number next to an option will replace ");
    fprintf(stdout, "a random number with the number you specify.\n\n");
    return 1;
  default:
    return 0;
  }
}

variable_types:
quit
int *

variable_types: num int


prompt

decompiled_code:
int prompt()
{
fwrite(
"Enter b [opt#] (binary), h [opt#] (hex), o [opt#] (octal), ? (help), q (quit):\n> ",
1uLL,
0x51uLL,
_bss_start);
return fflush(_bss_start);
}

canonical_decompiled_code:
int func18()
{
fwrite(
"Enter b [opt#] (binary), h [opt#] (hex), o [opt#] (octal), ? (help), q (quit):\n> ",
1uLL,
0x51uLL,
_bss_start);
return fflush(_bss_start);
}

original_code:
void prompt()
{
  char *p =
    "Enter b [opt#] (binary), h [opt#] (hex), o [opt#] (octal), ? (help), q (quit):\n> ";
  fprintf(stdout,"%s",p);
  fflush(stdout);
  return;
}

variable_types:
p
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
char v6[268]; // [rsp+0h] [rbp-118h] BYREF
int v7[3]; // [rsp+10Ch] [rbp-Ch] BYREF

v7[0] = 0;
while ( 1 )
{
prompt();
v3 = fgets(v6, 256, stdin);
v4 = trim_newline(v3);
putchar(10);
if ( !(unsigned int)process_cmd(v4, v7) )
{
fprintf(_bss_start, "unknown command: \"%s\"\n", v4);
goto LABEL_3;
}
if ( v7[0] )
break;
LABEL_3:
free(v4);
}
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
char v6[268]; // [rsp+0h] [rbp-118h] BYREF
int v7[3]; // [rsp+10Ch] [rbp-Ch] BYREF

v7[0] = 0;
while ( 1 )
{
func18();
v3 = fgets(v6, 256, stdin);
v4 = func11(v3);
putchar(10);
if ( !(unsigned int)func17(v4, v7) )
{
fprintf(_bss_start, "unknown command: \"%s\"\n", v4);
goto LABEL_3;
}
if ( v7[0] )
break;
LABEL_3:
free(v4);
}
free(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int quit = 0;
  char buf[256];
  while (1) {
    char *cmd;
    prompt();
    cmd = fgets(buf, 256, stdin);
    cmd = trim_newline(cmd);
    putchar('\n');
    if (!process_cmd(cmd, &quit))
      fprintf(stdout, "unknown command: \"%s\"\n", cmd);
    else
      if (quit){
        free(cmd);
        break;
      }
    free(cmd);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: quit int

variable_types:
buf
char [256]


printheader

repo: jhncl/LNA

original_code:
void printheader(struct struct_data *D){
  int l,m,mm;
for (l=0;l<D->L;l++){
 for (m=0;m<D->NoORF[l];m++){
  mm=D->NoSUM[l]+m;printf ("K_lm[%i] ",mm);
 }
}
for (l=0;l<D->L;l++){
 printf ("tau_K_l[%i] ",l);
}
for (l=0;l<D->L;l++){
 printf ("K_o_l[%i] ",l);
}
printf ("sigma_K_o ");
printf ("K_p ");
printf ("P ");
for (l=0;l<D->L;l++){
 for (m=0;m<D->NoORF[l];m++){
  mm=D->NoSUM[l]+m;
  printf ("r_lm[%i] ",mm);
 }
}
for (l=0;l<D->L;l++){
 printf ("tau_r_l[%i] ",l);
}
for (l=0;l<D->L;l++){
 printf ("r_o_l[%i] ",l);
}
printf ("sigma_r_o ");
printf ("r_p ");
for (l=0;l<D->L;l++){
 printf ("nu_l[%i] ",l);
}
printf ("sigma_nu ");
printf ("nu_p ");
 printf ("tau_K_p ");
 printf ("sigma_tau_K ");
 printf ("tau_r_p ");
 printf ("sigma_tau_r ");
 for (l=0;l<D->L;l++){
   for (m=0;m<D->NoORF[l];m++){
     mm=D->NoSUM[l]+m;printf ("zeta_lm[%i] ",mm);
   }
 }
printf ("\n");
}

canonical_original_code:
void printheader(struct struct_data *D){
  int l; int m; int mm;
for (l=0;l<D->L;l++){
 for (m=0;m<D->NoORF[l];m++){
  mm=D->NoSUM[l]+m;printf ("K_lm[%i] ",mm);
 }
}
for (l=0;l<D->L;l++){
 printf ("tau_K_l[%i] ",l);
}
for (l=0;l<D->L;l++){
 printf ("K_o_l[%i] ",l);
}
printf ("sigma_K_o ");
printf ("K_p ");
printf ("P ");
for (l=0;l<D->L;l++){
 for (m=0;m<D->NoORF[l];m++){
  mm=D->NoSUM[l]+m;
  printf ("r_lm[%i] ",mm);
 }
}
for (l=0;l<D->L;l++){
 printf ("tau_r_l[%i] ",l);
}
for (l=0;l<D->L;l++){
 printf ("r_o_l[%i] ",l);
}
printf ("sigma_r_o ");
printf ("r_p ");
for (l=0;l<D->L;l++){
 printf ("nu_l[%i] ",l);
}
printf ("sigma_nu ");
printf ("nu_p ");
 printf ("tau_K_p ");
 printf ("sigma_tau_K ");
 printf ("tau_r_p ");
 printf ("sigma_tau_r ");
 for (l=0;l<D->L;l++){
   for (m=0;m<D->NoORF[l];m++){
     mm=D->NoSUM[l]+m;printf ("zeta_lm[%i] ",mm);
   }
 }
printf ("\n");
}

variable_types: struct struct_data { double *y; int L; char latentfilename[50]; } *

variable_types: l int

variable_types: m int

variable_types: mm int


printdata

original_code:
void printdata(struct struct_data *D,struct struct_para *D_para,struct struct_MH *D_MH){
 int l,m,mm;
 for (l=0;l<D->L;l++){
  for (m=0;m<D->NoORF[l];m++){
   mm=D->NoSUM[l]+m;
   printf ("%g ",D_para->K_lm[mm]);
  }
 }
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->tau_K_l[l]);}
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->K_o_l[l]);}
  printf ("%g ",D_para->sigma_K_o);
  printf ("%g ",D_para->K_p);
  printf ("%g ",D_para->P);
  for (l=0;l<D->L;l++){for (m=0;m<D->NoORF[l];m++){mm=D->NoSUM[l]+m;printf ("%g ",D_para->r_lm[mm]);}}
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->tau_r_l[l]);}
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->r_o_l[l]);}
  printf ("%g ",D_para->sigma_r_o);
  printf ("%g ",D_para->r_p);
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->nu_l[l]);}
  printf ("%g ",D_para->sigma_nu);
  printf ("%g ",D_para->nu_p);
  printf ("%g ",D_para->tau_K_p);
  printf ("%g ",D_para->sigma_tau_K);
  printf ("%g ",D_para->tau_r_p);
  printf ("%g ",D_para->sigma_tau_r);
  for (l=0;l<D->L;l++){
    for (m=0;m<D->NoORF[l];m++){
      mm=D->NoSUM[l]+m;
      printf ("%g ",D_para->zeta_lm[mm]);
    }
  }
  printf ("\n");
}

canonical_original_code:
void printdata(struct struct_data *D, struct struct_para *D_para, struct struct_MH *D_MH){
 int l; int m; int mm;
 for (l=0;l<D->L;l++){
  for (m=0;m<D->NoORF[l];m++){
   mm=D->NoSUM[l]+m;
   printf ("%g ",D_para->K_lm[mm]);
  }
 }
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->tau_K_l[l]);}
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->K_o_l[l]);}
  printf ("%g ",D_para->sigma_K_o);
  printf ("%g ",D_para->K_p);
  printf ("%g ",D_para->P);
  for (l=0;l<D->L;l++){for (m=0;m<D->NoORF[l];m++){mm=D->NoSUM[l]+m;printf ("%g ",D_para->r_lm[mm]);}}
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->tau_r_l[l]);}
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->r_o_l[l]);}
  printf ("%g ",D_para->sigma_r_o);
  printf ("%g ",D_para->r_p);
  for (l=0;l<D->L;l++) {printf ("%g ",D_para->nu_l[l]);}
  printf ("%g ",D_para->sigma_nu);
  printf ("%g ",D_para->nu_p);
  printf ("%g ",D_para->tau_K_p);
  printf ("%g ",D_para->sigma_tau_K);
  printf ("%g ",D_para->tau_r_p);
  printf ("%g ",D_para->sigma_tau_r);
  for (l=0;l<D->L;l++){
    for (m=0;m<D->NoORF[l];m++){
      mm=D->NoSUM[l]+m;
      printf ("%g ",D_para->zeta_lm[mm]);
    }
  }
  printf ("\n");
}

user_defined_types: struct struct_data { double *y; int L; char latentfilename[50]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
void *v4; // rbp
void *v5; // r14
__int64 v6; // r13
time_t v7; // r15
__pid_t v8; // eax
__int64 v9; // r12
void *v11; // [rsp+0h] [rbp-48h]
unsigned int v12; // [rsp+8h] [rbp-40h]
unsigned int v13; // [rsp+Ch] [rbp-3Ch]

v3 = (char *)malloc(0x80uLL);
v11 = malloc(0xE0uLL);
v4 = malloc(0x118uLL);
v5 = malloc(0x40uLL);
testargc((unsigned int)argc);
gsl_rng_env_setup();
v6 = gsl_rng_alloc(gsl_rng_default);
v7 = time(0LL);
v8 = getpid();
gsl_rng_set(v6, v7 * v8);
LODWORD(v7) = atoi(argv[1]);
v12 = atoi(argv[2]);
v13 = atoi(argv[3]);
v9 = (unsigned int)atoi(argv[4]);
inzstruct_data(v3);
inzstruct_priors(v4);
inzstruct_para(v11, v3, v4);
inzstruct_MH(v5);
sprintf(v3 + 76, "latent_variable_%i_%i_%i_%i.txt", (unsigned int)v7, v12, v13, (unsigned int)v9);
gibbsandMHloop((unsigned int)v7, 1LL, v6, v3, v11, v4, v5, v9, 0LL);
gibbsandMHloop(v12, v13, v6, v3, v11, v4, v5, v9, 1LL);
gsl_rng_free(v6);
return 0;
}

original_code:
int
     main (int argc,char *argv[])
     {
 struct_data *data= malloc(sizeof(struct_data));
 struct_para *para= malloc(sizeof(struct_para));
 struct_priors *priors= malloc(sizeof(struct_priors));
 struct_MH *MH = malloc(sizeof(struct_MH));
 int burn,iters,thin, CAPL;
 long seed;
 const gsl_rng_type * T;
 gsl_rng * RNG;
 testargc(argc);
 gsl_rng_env_setup ();
 T = gsl_rng_default;
 RNG = gsl_rng_alloc (T);
 seed = time (((void *)0)) * getpid();
   gsl_rng_set (RNG, seed);
 burn=atoi(argv[1]);
 iters=atoi(argv[2]);
 thin=atoi(argv[3]);
 CAPL=atoi(argv[4]);
        inzstruct_data(data);
 inzstruct_priors(priors);
 inzstruct_para(para,data,priors);
 inzstruct_MH(MH);
 sprintf(data->latentfilename,"latent_variable_%i_%i_%i_%i.txt",burn,iters,thin,CAPL);
 gibbsandMHloop(burn,1,RNG,data,para,priors,MH,CAPL,0);
 gibbsandMHloop(iters,thin,RNG,data,para,priors,MH,CAPL,1);
        gsl_rng_free(RNG);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
     {
 struct struct_data *data = malloc(sizeof(struct_data));
 struct struct_para *para = malloc(sizeof(struct_para));
 struct struct_priors *priors = malloc(sizeof(struct_priors));
 struct struct_MH *MH = malloc(sizeof(struct_MH));
 int burn; int iters; int thin; int CAPL;
 long seed;
 struct gsl_rng_type *T;
 struct gsl_rng *RNG;
 testargc(argc);
 gsl_rng_env_setup ();
 T = gsl_rng_default;
 RNG = gsl_rng_alloc (T);
 seed = time (((void *)0)) * getpid();
   gsl_rng_set (RNG, seed);
 burn=atoi(argv[1]);
 iters=atoi(argv[2]);
 thin=atoi(argv[3]);
 CAPL=atoi(argv[4]);
        inzstruct_data(data);
 inzstruct_priors(priors);
 inzstruct_para(para,data,priors);
 inzstruct_MH(MH);
 sprintf(data->latentfilename,"latent_variable_%i_%i_%i_%i.txt",burn,iters,thin,CAPL);
 gibbsandMHloop(burn,1,RNG,data,para,priors,MH,CAPL,0);
 gibbsandMHloop(iters,thin,RNG,data,para,priors,MH,CAPL,1);
        gsl_rng_free(RNG);
 return 0;
}

variable_types:
para
struct struct_para { double *K_lm; } *

variable_types: struct struct_priors { double eta_K_o; } *

variable_types:
MH
struct struct_MH { double hP; } *

variable_types: burn int

variable_types: iters int

variable_types: thin int

variable_types: CAPL int

variable_types: seed long

variable_types: struct gsl_rng { struct gsl_rng_type { char *name; unsigned long max; unsigned long min; unsigned long size; void (*set)(void *state, unsigned long seed); unsigned long (*get)(void *state); double (*get_double)(void *state); } *type; void *state; } *

user_defined_types: struct gsl_rng { struct gsl_rng_type *type; void *state; }


original_code:
unsigned char avg_sse2(unsigned char *buf, int len)
{
 int i = len, j;
 __m128i a, b, zero, sum_vect16, sum_vect32;
 int __attribute__ ((aligned(16))) sum[4];
 zero = _mm_set1_epi32(0);
 sum_vect32 = zero;
 while (i) {
  i -= 2048;
  sum_vect16 = zero;
  for (j = 0; j < 128; j++) {
   a = _mm_load_si128((__m128i *)buf);
   buf += 16;
   b = a;
   b = _mm_unpackhi_epi8(b, zero);
   a = _mm_unpacklo_epi8(a, zero);
   sum_vect16 = _mm_add_epi16(sum_vect16, b);
   sum_vect16 = _mm_add_epi16(sum_vect16, a);
  }
  a = sum_vect16;
  b = a;
  b = _mm_unpackhi_epi16(b, zero);
  a = _mm_unpacklo_epi16(a, zero);
  sum_vect32 = _mm_add_epi32(sum_vect32, b);
  sum_vect32 = _mm_add_epi32(sum_vect32, a);
 }
 _mm_store_si128((__m128i *)sum, sum_vect32);
 return (sum[0] + sum[1] + sum[2] + sum[3]) / len;
}

canonical_original_code:
unsigned char avg_sse2(unsigned char *buf, int len)
{
 int i = len; int j;
 long long a; long long b; long long zero; long long sum_vect16; long long sum_vect32;
 int sum[4];
 zero = _mm_set1_epi32(0);
 sum_vect32 = zero;
 while (i) {
  i -= 2048;
  sum_vect16 = zero;
  for (j = 0; j < 128; j++) {
   a = _mm_load_si128((long long *)buf);
   buf += 16;
   b = a;
   b = _mm_unpackhi_epi8(b, zero);
   a = _mm_unpacklo_epi8(a, zero);
   sum_vect16 = _mm_add_epi16(sum_vect16, b);
   sum_vect16 = _mm_add_epi16(sum_vect16, a);
  }
  a = sum_vect16;
  b = a;
  b = _mm_unpackhi_epi16(b, zero);
  a = _mm_unpacklo_epi16(a, zero);
  sum_vect32 = _mm_add_epi32(sum_vect32, b);
  sum_vect32 = _mm_add_epi32(sum_vect32, a);
 }
 _mm_store_si128((long long *)sum, sum_vect32);
 return (sum[0] + sum[1] + sum[2] + sum[3]) / len;
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: i int

variable_types: j int

variable_types:
a
long long

variable_types:
b
long long

variable_types:
zero
long long

variable_types:
sum
int [4]

return_type: unsigned char


slCreateNode

repo: jiabai/skiplist---c

decompiled_code:
double *__fastcall slCreateNode(int a1, double a2)
{
double *result; // rax

result = (double *)malloc(8LL * a1 + 16);
*result = a2;
return result;
}

canonical_decompiled_code:
double *__fastcall func7(int a1, double a2)
{
double *result; // rax

result = (double *)malloc(8LL * a1 + 16);
*result = a2;
return result;
}

original_code:
skiplistNode *slCreateNode(int level, double score) {
 skiplistNode *sn = malloc(sizeof(*sn) + level*sizeof(struct skiplistLevel));
 sn->score = score;
 return sn;
}

canonical_original_code:
struct skiplistNode *slCreateNode(int level, double score) {
 struct skiplistNode *sn = malloc(sizeof(*sn) + level*sizeof(struct skiplistLevel));
 sn->score = score;
 return sn;
}

variable_types: level int

variable_types: score double

variable_types: struct skiplistNode { double score; struct skiplistNode *backward; struct skiplistLevel { struct skiplistNode *forward; } level[]; } *

user_defined_types: struct skiplistNode { double score; struct skiplistNode *backward; struct skiplistLevel level[]; }


slCreate

original_code:
skiplist *slCreate(void) {
 int j;
 skiplist *sl;
 sl = malloc(sizeof(*sl));
 sl->level = 1;
 sl->length = 0;
 sl->header = slCreateNode(8, 0);
 for(j = 0; j < 8; j++) {
  sl->header->level[j].forward = ((void *)0);
 }
 sl->header->backward = ((void *)0);
 sl->tail = ((void *)0);
 return sl;
}

canonical_original_code:
struct skiplist *slCreate() {
 int j;
 struct skiplist *sl;
 sl = malloc(sizeof(*sl));
 sl->level = 1;
 sl->length = 0;
 sl->header = slCreateNode(8, 0);
 for(j = 0; j < 8; j++) {
  sl->header->level[j].forward = ((void *)0);
 }
 sl->header->backward = ((void *)0);
 sl->tail = ((void *)0);
 return sl;
}

variable_types: struct skiplist { struct skiplistNode { double score; struct skiplistNode *backward; struct skiplistLevel { struct skiplistNode *forward; } level[]; } *header; unsigned long length; int level; } *

user_defined_types: struct skiplist { struct skiplistNode *header; unsigned long length; int level; }


slFreeNode

decompiled_code:
void __fastcall slFreeNode(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
free(a1);
}

original_code:
void slFreeNode(skiplistNode *sn) {
 free(sn);
}

canonical_original_code:
void slFreeNode(struct skiplistNode *sn) {
 free(sn);
}

user_defined_types: struct skiplistLevel { struct skiplistNode *forward; }


slFree

decompiled_code:
void __fastcall slFree(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
v3 = (_QWORD *)v2[2];
free(v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
slFreeNode(v4);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
v3 = (_QWORD *)v2[2];
free(v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
func9(v4);
}
free(ptr);
}

original_code:
void slFree(skiplist *sl) {
 skiplistNode *node = sl->header->level[0].forward, *next;
 free(sl->header);
 while(node) {
  next = node->level[0].forward;
  slFreeNode(node);
  node = next;
 }
 free(sl);
}

canonical_original_code:
void slFree(struct skiplist *sl) {
 struct skiplistNode *node = sl->header->level[0].forward; struct skiplistNode *next;
 free(sl->header);
 while(node) {
  next = node->level[0].forward;
  slFreeNode(node);
  node = next;
 }
 free(sl);
}


slRandomLevel

decompiled_code:
__int64 slRandomLevel()
{
int v0; // ebx
__int64 result; // rax

v0 = 1;
while ( (((unsigned __int16)rand() >> 8) & 0x80u) == 0 )
++v0;
result = 8LL;
if ( v0 <= 8 )
result = (unsigned int)v0;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
__int64 result; // rax

v0 = 1;
while ( (((unsigned __int16)rand() >> 8) & 0x80u) == 0 )
++v0;
result = 8LL;
if ( v0 <= 8 )
result = (unsigned int)v0;
return result;
}

original_code:
int slRandomLevel(void) {
 int level = 1;
 while((rand()&0xFFFF) < (0.5 * 0xFFFF))
  level += 1;
 return (level < 8) ? level : 8;
}

canonical_original_code:
int slRandomLevel() {
 int level = 1;
 while((rand()&0xFFFF) < (0.5 * 0xFFFF))
  level += 1;
 return (level < 8) ? level : 8;
}


slInsert

original_code:
skiplistNode *slInsert(skiplist *sl, double score) {
 skiplistNode *update[8];
 skiplistNode *node;
 node = sl->header;
 int i, level;
 for ( i = sl->level-1; i >= 0; i--) {
  while(node->level[i].forward && node->level[i].forward->score < score) {
   node = node->level[i].forward;
  }
  update[i] = node;
 }
 level = slRandomLevel();
 if (level > sl->level) {
  for (i = sl->level; i< level ;i++) {
   update[i] = sl->header;
  }
  sl->level = level;
 }
 node = slCreateNode(level, score);
 for (i = 0; i < level; i++) {
  node->level[i].forward = update[i]->level[i].forward;
  update[i]->level[i].forward = node;
 }
 node->backward = (update[0] == sl->header? ((void *)0) : update[0]);
 if (node->level[0].forward)
  node->level[0].forward->backward = node;
 else
  sl->tail = node;
 sl->length++;
 return node;
}

canonical_original_code:
struct skiplistNode *slInsert(struct skiplist *sl, double score) {
 struct skiplistNode *update[8];
 struct skiplistNode *node;
 node = sl->header;
 int i; int level;
 for ( i = sl->level-1; i >= 0; i--) {
  while(node->level[i].forward && node->level[i].forward->score < score) {
   node = node->level[i].forward;
  }
  update[i] = node;
 }
 level = slRandomLevel();
 if (level > sl->level) {
  for (i = sl->level; i< level ;i++) {
   update[i] = sl->header;
  }
  sl->level = level;
 }
 node = slCreateNode(level, score);
 for (i = 0; i < level; i++) {
  node->level[i].forward = update[i]->level[i].forward;
  update[i]->level[i].forward = node;
 }
 node->backward = (update[0] == sl->header? ((void *)0) : update[0]);
 if (node->level[0].forward)
  node->level[0].forward->backward = node;
 else
  sl->tail = node;
 sl->length++;
 return node;
}

variable_types: struct skiplist { struct skiplistNode *header; unsigned long length; int level; } *

variable_types: struct skiplistNode { double score; struct skiplistNode *backward; struct skiplistLevel { struct skiplistNode *forward; } level[]; } *[8]


slDeleteNode

original_code:
void slDeleteNode(skiplist *sl, skiplistNode *x, skiplistNode **update){
 int i;
 for (i = 0; i < sl->level; i++) {
  if (update[i]->level[i].forward == x) {
   update[i]->level[i].forward = x->level[i].forward;
  }
 }
 if (x->level[0].forward) {
  x->level[0].forward->backward = x->backward;
 } else {
  sl->tail = x->backward;
 }
 while (sl->level > 1 && sl->header->level[sl->level-1].forward == ((void *)0))
  sl->level--;
 sl->length--;
}

canonical_original_code:
void slDeleteNode(struct skiplist *sl, struct skiplistNode *x, struct skiplistNode **update){
 int i;
 for (i = 0; i < sl->level; i++) {
  if (update[i]->level[i].forward == x) {
   update[i]->level[i].forward = x->level[i].forward;
  }
 }
 if (x->level[0].forward) {
  x->level[0].forward->backward = x->backward;
 } else {
  sl->tail = x->backward;
 }
 while (sl->level > 1 && sl->header->level[sl->level-1].forward == ((void *)0))
  sl->level--;
 sl->length--;
}

variable_types:
x
struct skiplistNode *

variable_types:
update
struct skiplistNode **


slDelete

decompiled_code:
__int64 __fastcall slDelete(__int64 a1, double a2)
{
__int64 v2; // rcx
__int64 v3; // rsi
double *v4; // rax
double *v5; // rbx
__int64 v7[9]; // [rsp+0h] [rbp-48h] BYREF

v2 = *(_QWORD *)a1;
LODWORD(v3) = *(_DWORD *)(a1 + 24) - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
v4 = (double *)v2;
do
{
v2 = (__int64)v4;
v4 = *(double **)&v4[(int)v3 + 2];
}
while ( v4 && a2 > *v4 );
v7[v3--] = v2;
}
while ( (int)v3 >= 0 );
}
v5 = *(double **)(v2 + 16);
if ( !v5 )
return 0LL;
if ( a2 != *v5 )
return 0LL;
slDeleteNode((__int64 *)a1, *(_QWORD *)(v2 + 16), (__int64)v7);
slFreeNode(v5);
return 1LL;
}

original_code:
int slDelete(skiplist *sl, double score) {
 skiplistNode *update[8], *node;
 int i;
 node = sl->header;
 for(i = sl->level-1; i >= 0; i--) {
  while (node->level[i].forward && node->level[i].forward->score < score) {
   node = node->level[i].forward;
  }
  update[i] = node;
 }
 node = node->level[0].forward;
 if (node && score == node->score) {
  slDeleteNode(sl, node, update);
  slFreeNode(node);
  return 1;
 } else {
  return 0;
 }
 return 0;
}

canonical_original_code:
int slDelete(struct skiplist *sl, double score) {
 struct skiplistNode *update[8]; struct skiplistNode *node;
 int i;
 node = sl->header;
 for(i = sl->level-1; i >= 0; i--) {
  while (node->level[i].forward && node->level[i].forward->score < score) {
   node = node->level[i].forward;
  }
  update[i] = node;
 }
 node = node->level[0].forward;
 if (node && score == node->score) {
  slDeleteNode(sl, node, update);
  slFreeNode(node);
  return 1;
 } else {
  return 0;
 }
 return 0;
}


slSearch

decompiled_code:
__int64 __fastcall slSearch(__int64 a1, double a2)
{
double *v2; // rcx
int v3; // esi
double *v4; // rax
double v5; // xmm1_8
__int64 result; // rax
double *v7; // rax

v2 = *(double **)a1;
v3 = *(_DWORD *)(a1 + 24) - 1;
if ( v3 >= 0 )
{
do
{
v7 = v2;
do
{
v2 = v7;
v7 = *(double **)&v7[v3 + 2];
}
while ( v7 && a2 > *v7 );
--v3;
}
while ( v3 != -1 );
}
v4 = (double *)*((_QWORD *)v2 + 2);
if ( v4 && (v5 = *v4, v5 == a2) )
{
printf("Found %d\n", (unsigned int)(int)v5);
result = 1LL;
}
else
{
printf("Not found %d\n", (unsigned int)(int)a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, double a2)
{
double *v2; // rcx
int v3; // esi
double *v4; // rax
double v5; // xmm1_8
__int64 result; // rax
double *v7; // rax

v2 = *(double **)a1;
v3 = *(_DWORD *)(a1 + 24) - 1;
if ( v3 >= 0 )
{
do
{
v7 = v2;
do
{
v2 = v7;
v7 = *(double **)&v7[v3 + 2];
}
while ( v7 && a2 > *v7 );
--v3;
}
while ( v3 != -1 );
}
v4 = (double *)*((_QWORD *)v2 + 2);
if ( v4 && (v5 = *v4, v5 == a2) )
{
printf("Found %d\n", (unsigned int)(int)v5);
result = 1LL;
}
else
{
printf("Not found %d\n", (unsigned int)(int)a2);
result = 0LL;
}
return result;
}

original_code:
int slSearch(skiplist *sl, double score) {
 skiplistNode *node;
 int i;
 node = sl->header;
 for (i = sl->level-1; i >= 0 ;i--) {
  while(node->level[i].forward && node->level[i].forward->score < score) {
   node = node->level[i].forward;
  }
 }
 node = node->level[0].forward;
 if (node && score == node->score) {
  printf("Found %d\n",(int)node->score);
  return 1;
 } else {
  printf("Not found %d\n", (int)score);
  return 0;
 }
}

canonical_original_code:
int slSearch(struct skiplist *sl, double score) {
 struct skiplistNode *node;
 int i;
 node = sl->header;
 for (i = sl->level-1; i >= 0 ;i--) {
  while(node->level[i].forward && node->level[i].forward->score < score) {
   node = node->level[i].forward;
  }
 }
 node = node->level[0].forward;
 if (node && score == node->score) {
  printf("Found %d\n",(int)node->score);
  return 1;
 } else {
  printf("Not found %d\n", (int)score);
  return 0;
 }
}


slPrint

decompiled_code:
int __fastcall slPrint(_QWORD *a1)
{
unsigned int i; // er12
double *j; // rbx
int result; // eax

for ( i = 0; i != 8; ++i )
{
printf("LEVEL[%d]: ", i);
for ( j = *(double **)(*a1 + 8LL * (int)i + 16); j; j = *(double **)&j[(int)i + 2] )
printf("%d -> ", (unsigned int)(int)*j);
result = puts("NULL");
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(_QWORD *a1)
{
unsigned int i; // er12
double *j; // rbx
int result; // eax

for ( i = 0; i != 8; ++i )
{
printf("LEVEL[%d]: ", i);
for ( j = *(double **)(*a1 + 8LL * (int)i + 16); j; j = *(double **)&j[(int)i + 2] )
printf("%d -> ", (unsigned int)(int)*j);
result = puts("NULL");
}
return result;
}

original_code:
void slPrint(skiplist *sl) {
 skiplistNode *node;
 int i;
 for (i = 0; i < 8; i++) {
  printf("LEVEL[%d]: ", i);
  node = sl->header->level[i].forward;
  while(node) {
   printf("%d -> ", (int)(node->score));
   node = node->level[i].forward;
  }
  printf("NULL\n");
 }
}

canonical_original_code:
void slPrint(struct skiplist *sl) {
 struct skiplistNode *node;
 int i;
 for (i = 0; i < 8; i++) {
  printf("LEVEL[%d]: ", i);
  node = sl->header->level[i].forward;
  while(node) {
   printf("%d -> ", (int)(node->score));
   node = node->level[i].forward;
  }
  printf("NULL\n");
 }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdx
_QWORD *v5; // rbp
int i; // ebx
int v7; // eax
int j; // ebx
int v9; // eax
const char *v10; // rdx

v3 = time(0LL);
srand(v3);
puts("### Function Test ###");
puts("=== Init Skip List ===");
v5 = slCreate();
for ( i = 0; i != 20; ++i )
slInsert((__int64)v5, (double)i, (__int64)argv, v4);
puts("=== Print Skip List ===");
slPrint(v5);
puts("=== Search Skip List ===");
do
{
v7 = rand();
slSearch((__int64)v5, (double)(v7 % 30));
--i;
}
while ( i );
puts("=== Delete Skip List ===");
for ( j = 0; j != 30; j += 2 )
{
v9 = slDelete((__int64)v5, (double)j);
v10 = "NOT FOUND";
if ( v9 )
v10 = "SUCCESS";
printf("Delete[%d]: %s\n", (unsigned int)j, v10);
}
slPrint(v5);
slFree(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdx
_QWORD *v5; // rbp
int i; // ebx
int v7; // eax
int j; // ebx
int v9; // eax
const char *v10; // rdx

v3 = time(0LL);
srand(v3);
puts("### Function Test ###");
puts("=== Init Skip List ===");
v5 = func8();
for ( i = 0; i != 20; ++i )
func12((__int64)v5, (double)i, (__int64)argv, v4);
puts("=== Print Skip List ===");
func16(v5);
puts("=== Search Skip List ===");
do
{
v7 = rand();
func15((__int64)v5, (double)(v7 % 30));
--i;
}
while ( i );
puts("=== Delete Skip List ===");
for ( j = 0; j != 30; j += 2 )
{
v9 = func14((__int64)v5, (double)j);
v10 = "NOT FOUND";
if ( v9 )
v10 = "SUCCESS";
printf("Delete[%d]: %s\n", (unsigned int)j, v10);
}
func16(v5);
func10(v5);
return 0;
}

original_code:
int main() {
 srand((unsigned)time(0));
 int count = 20, i;
 printf("### Function Test ###\n");
 printf("=== Init Skip List ===\n");
 skiplist * sl = slCreate();
 for (i = 0; i < count; i++) {
  slInsert(sl,i);
 }
 printf("=== Print Skip List ===\n");
 slPrint(sl);
 printf("=== Search Skip List ===\n");
 for (i = 0; i < count; i++) {
  int value = rand()%(count+10);
  slSearch(sl, value);
 }
 printf("=== Delete Skip List ===\n");
 for (i = 0; i < count+10; i+=2) {
  printf("Delete[%d]: %s\n", i, slDelete(sl, i)?"SUCCESS":"NOT FOUND");
 }
 slPrint(sl);
 slFree(sl);
 sl = ((void *)0);
}

canonical_original_code:
int main() {
 srand((unsigned int)time(0));
 int count = 20; int i;
 printf("### Function Test ###\n");
 printf("=== Init Skip List ===\n");
 struct skiplist *sl = slCreate();
 for (i = 0; i < count; i++) {
  slInsert(sl,i);
 }
 printf("=== Print Skip List ===\n");
 slPrint(sl);
 printf("=== Search Skip List ===\n");
 for (i = 0; i < count; i++) {
  int value = rand()%(count+10);
  slSearch(sl, value);
 }
 printf("=== Delete Skip List ===\n");
 for (i = 0; i < count+10; i+=2) {
  printf("Delete[%d]: %s\n", i, slDelete(sl, i)?"SUCCESS":"NOT FOUND");
 }
 slPrint(sl);
 slFree(sl);
 sl = ((void *)0);
}

variable_types: count int

variable_types: value int


decompiled_code:
__int64 __fastcall row2letter(unsigned int a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 <= 8 )
result = (unsigned __int8)letters_2[a1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 <= 8 )
result = (unsigned __int8)letters_2[a1];
return result;
}

original_code:
char row2letter( int i )
{
    static char letters[ 8 ] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
    if( i < 0 || i > 8 )
        return 0;
    return letters[i];
}

canonical_original_code:
char row2letter(int i)
{
    static char letters[8] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
    if( i < 0 || i > 8 )
        return 0;
    return letters[i];
}

variable_types:
letters
char [8]


decompiled_code:
char *__fastcall translate_first_move(_DWORD *a1)
{
__int64 v1; // rax
char *v2; // rbx
char v3; // al

v1 = Calloc(12LL, 1LL);
if ( !v1 )
_assert_fail("human_readable", "move.c", 0x57u, "translate_first_move");
v2 = (char *)v1;
v3 = row2letter(a1[1]);
snprintf(v2, 0xCuLL, "%c%d", (unsigned int)v3, (unsigned int)(8 - *a1));
return v2;
}

canonical_decompiled_code:
char *__fastcall func3(_DWORD *a1)
{
__int64 v1; // rax
char *v2; // rbx
char v3; // al

v1 = Calloc(12LL, 1LL);
if ( !v1 )
_assert_fail("human_readable", "move.c", 0x57u, "translate_first_move");
v2 = (char *)v1;
v3 = func1(a1[1]);
snprintf(v2, 0xCuLL, "%c%d", (unsigned int)v3, (unsigned int)(8 - *a1));
return v2;
}

original_code:
char * translate_first_move( const struct Move * move )
{
    char * human_readable = Calloc( 12, sizeof( char ) );
    ((human_readable) ? (void) (0) : __assert_fail ("human_readable", "move.c", 87, __extension__ __PRETTY_FUNCTION__));
    snprintf( human_readable, 12, "%c%d",
                row2letter( move->start_col ),
                8 - move->start_row );
    return human_readable;
}

canonical_original_code:
char *translate_first_move(struct Move *move)
{
    char *human_readable = Calloc( 12, sizeof( char ) );
    ((human_readable) ? (void) (0) : __assert_fail ("human_readable", "move.c", 87, __extension__ __PRETTY_FUNCTION__));
    snprintf( human_readable, 12, "%c%d",
                row2letter( move->start_col ),
                8 - move->start_row );
    return human_readable;
}

variable_types: struct Move { int start_row; int start_col; int end_row; int end_col; } *


decompiled_code:
_BOOL8 __fastcall compare_move(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 && a1[1] == a2[1] && a1[2] == a2[2] )
result = a1[3] == a2[3];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 && a1[1] == a2[1] && a1[2] == a2[2] )
result = a1[3] == a2[3];
return result;
}

original_code:
int compare_move( const struct Move * a, const struct Move * b )
{
    return ( a->start_row == b->start_row &&
             a->start_col == b->start_col &&
             a->end_row == b->end_row &&
             a->end_col == b->end_col );
}

canonical_original_code:
int compare_move(struct Move *a, struct Move *b)
{
    return ( a->start_row == b->start_row &&
             a->start_col == b->start_col &&
             a->end_row == b->end_row &&
             a->end_col == b->end_col );
}

variable_types:
b
struct Move *

user_defined_types: struct Move { int start_row; int start_col; int end_row; int end_col; }


decompiled_code:
__int64 __fastcall print_single_move(_DWORD *a1)
{
char *v1; // rbx

v1 = translate_first_move(a1);
printf("%s", v1);
return Free(v1, 12LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
char *v1; // rbx

v1 = func3(a1);
printf("%s", v1);
return Free(v1, 12LL);
}

original_code:
void print_single_move( const struct Move * move )
{
    char * human_readable = translate_first_move( move );
    printf( "%s", human_readable );
    Free( human_readable, sizeof( char ) * 12 );
}

canonical_original_code:
void print_single_move(struct Move *move)
{
    char *human_readable = translate_first_move( move );
    printf( "%s", human_readable );
    Free( human_readable, sizeof( char ) * 12 );
}


decompiled_code:
__int64 new_list()
{
__int64 result; // rax

result = Calloc(1LL, 24LL);
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = 0LL;
*(_DWORD *)(result + 16) = 0;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = Calloc(1LL, 24LL);
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 8) = 0LL;
*(_DWORD *)(result + 16) = 0;
return result;
}

original_code:
struct List * new_list( void )
{
  struct List * list = Calloc( 1, sizeof( struct List ) );
  list->head = ((void *)0);
  list->tail = ((void *)0);
  list->count = 0;
  return list;
}

canonical_original_code:
struct List *new_list()
{
  struct List *list = Calloc( 1, sizeof( struct List ) );
  list->head = ((void *)0);
  list->tail = ((void *)0);
  list->count = 0;
  return list;
}

variable_types: struct List { struct ListNode { void *data; struct ListNode *next; } *head; struct ListNode *tail; int count; } *

user_defined_types: struct List { struct ListNode *head; struct ListNode *tail; int count; }


decompiled_code:
__int64 __fastcall compare_state(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rax

result = 0LL;
if ( *a1 == *a2 )
{
v3 = 9LL;
while ( 2 )
{
v4 = v3 - 8;
do
{
if ( a1[v4] != a2[v4] )
return 0LL;
++v4;
}
while ( v4 != v3 );
v3 += 8LL;
if ( v3 != 73 )
continue;
break;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rax

result = 0LL;
if ( *a1 == *a2 )
{
v3 = 9LL;
while ( 2 )
{
v4 = v3 - 8;
do
{
if ( a1[v4] != a2[v4] )
return 0LL;
++v4;
}
while ( v4 != v3 );
v3 += 8LL;
if ( v3 != 73 )
continue;
break;
}
result = 1LL;
}
return result;
}

original_code:
int compare_state( const struct State * a, const struct State * b )
{
    if( a->player != b->player )
        return 0;
    for( int i = 0; i < 8; i++ )
        for( int j = 0; j < 8; j++ )
            if( a->board[i][j] != b->board[i][j] )
                return 0;
    return 1;
}

canonical_original_code:
int compare_state(struct State *a, struct State *b)
{
    if( a->player != b->player )
        return 0;
    for( int i = 0; i < 8; i++ )
        for( int j = 0; j < 8; j++ )
            if( a->board[i][j] != b->board[i][j] )
                return 0;
    return 1;
}

variable_types: struct State { char player; char board[8][8]; } *

variable_types:
b
struct State *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall add_child_game_node(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 8) = a1;
return add_front(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
*(_QWORD *)(a2 + 8) = a1;
return add_front(a1 + 40);
}

original_code:
void add_child_game_node( struct GameNode * parent, struct GameNode * child )
{
    child->parent = parent;
    add_front( &parent->children, child );
}

canonical_original_code:
void add_child_game_node(struct GameNode *parent, struct GameNode *child)
{
    child->parent = parent;
    add_front( &parent->children, child );
}

variable_types: struct GameNode { short utility_val; short child_count; struct GameNode *parent; struct State { char player; char board[8][8]; } *state; struct List { struct ListNode { void *data; struct ListNode *next; } *head; struct ListNode *tail; int count; } *children; struct Move { int start_row; int start_col; int end_row; int end_col; } *best_move; short best_util_val; } *

variable_types:
child
struct GameNode *

user_defined_types: struct GameNode { short utility_val; short child_count; struct GameNode *parent; struct State *state; struct List *children; struct Move *best_move; short best_util_val; }


WriteCallback

decompiled_code:
__int64 __fastcall WriteCallback(__int64 a1, __int64 a2, __int64 a3)
{
return a3 * a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return a3 * a2;
}

original_code:
static size_t WriteCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
  (void)ptr;
  (void)data;
  return (size_t)(size * nmemb);
}

canonical_original_code:
static unsigned long WriteCallback(void *ptr, unsigned long size, unsigned long nmemb, void *data)
{
  (void)ptr;
  (void)data;
  return (unsigned long)(size * nmemb);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
data
void *

return_type: unsigned long


repo: jiiksteri/gbr

decompiled_code:
__int64 __fastcall dump_info(const char *a1, const char *a2, int a3, int a4)
{
__int64 v5; // rsi
__int64 v6; // rax
const char *v7; // rcx
unsigned int v8; // er10
const char *v9; // r9
bool v10; // cc

if ( a3 )
{
v8 = a4 > 0;
v5 = 100LL;
if ( a4 <= 100 )
v5 = (unsigned int)a4;
v10 = a4 < 101;
v7 = (const char *)&unk_5FE;
if ( !v10 )
v7 = ">";
v6 = 100LL;
if ( a3 <= 100 )
v6 = (unsigned int)a3;
v9 = ">";
if ( a3 <= 100 )
v9 = (const char *)&unk_5FE;
}
else if ( a4 )
{
v5 = 100LL;
if ( a4 <= 100 )
v5 = (unsigned int)a4;
v6 = 0LL;
if ( a4 <= 100 )
v7 = (const char *)&unk_5FE;
else
v7 = ">";
v8 = 3;
v9 = (const char *)&unk_5FE;
}
else
{
v6 = 0LL;
v5 = 0LL;
v7 = (const char *)&unk_5FE;
v8 = 2;
v9 = (const char *)&unk_5FE;
}
return c_fprintf(v8, stdout, " %s:%s:%s%d/%s%d", a1, a2, v9, v6, v7, v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2, int a3, int a4)
{
__int64 v5; // rsi
__int64 v6; // rax
const char *v7; // rcx
unsigned int v8; // er10
const char *v9; // r9
bool v10; // cc

if ( a3 )
{
v8 = a4 > 0;
v5 = 100LL;
if ( a4 <= 100 )
v5 = (unsigned int)a4;
v10 = a4 < 101;
v7 = (const char *)&unk_5FE;
if ( !v10 )
v7 = ">";
v6 = 100LL;
if ( a3 <= 100 )
v6 = (unsigned int)a3;
v9 = ">";
if ( a3 <= 100 )
v9 = (const char *)&unk_5FE;
}
else if ( a4 )
{
v5 = 100LL;
if ( a4 <= 100 )
v5 = (unsigned int)a4;
v6 = 0LL;
if ( a4 <= 100 )
v7 = (const char *)&unk_5FE;
else
v7 = ">";
v8 = 3;
v9 = (const char *)&unk_5FE;
}
else
{
v6 = 0LL;
v5 = 0LL;
v7 = (const char *)&unk_5FE;
v8 = 2;
v9 = (const char *)&unk_5FE;
}
return c_fprintf(v8, stdout, " %s:%s:%s%d/%s%d", a1, a2, v9, v6, v7, v5);
}

original_code:
static void dump_info(const char *remote, const char *sha, int c0, int c1)
{
 int div0, div1;
 enum color c = NONE;
 div0 = c0 > 100;
 div1 = c1 > 100;
        if (c0 == 0) {
                if (c1 == 0) {
                        c = GREEN;
                } else {
                        c = YELLOW;
                }
        } else if (c1 > 0) {
                c = RED;
        }
 c_fprintf(c, stdout, " %s:%s:%s%d/%s%d",
    remote, sha,
    div0 ? ">" : "",
    div0 ? 100 : c0,
    div1 ? ">" : "",
    div1 ? 100 : c1);
}

canonical_original_code:
static void dump_info(char *remote, char *sha, int c0, int c1)
{
 int div0; int div1;
 enum color c = NONE;
 div0 = c0 > 100;
 div1 = c1 > 100;
        if (c0 == 0) {
                if (c1 == 0) {
                        c = GREEN;
                } else {
                        c = YELLOW;
                }
        } else if (c1 > 0) {
                c = RED;
        }
 c_fprintf(c, stdout, " %s:%s:%s%d/%s%d",
    remote, sha,
    div0 ? ">" : "",
    div0 ? 100 : c0,
    div1 ? ">" : "",
    div1 ? 100 : c1);
}

variable_types:
remote
char *

variable_types:
sha
char *

variable_types: enum color { NONE=0, RED=1, GREEN=2, YELLOW=3, _C_MAX=4 }


decompiled_code:
__int64 __fastcall gbr_sha(__int64 a1, __int64 a2, int a3)
{
return git_oid_tostr(a1, a3 + 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3)
{
return git_oid_tostr(a1, a3 + 1, a2);
}

original_code:
static const char *gbr_sha(struct gbr_sha *sha, const git_oid *oid, int abbrev_commit)
{
 return git_oid_tostr(sha->sha, abbrev_commit+1, oid);
}

canonical_original_code:
static char *gbr_sha(struct gbr_sha *sha, struct git_oid *oid, int abbrev_commit)
{
 return git_oid_tostr(sha->sha, abbrev_commit+1, oid);
}

variable_types:
sha
struct gbr_sha { char sha[-1]; } *

variable_types: struct git_oid { unsigned char id[20]; } *


decompiled_code:
int dump_version()
{
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

git_libgit2_version(v3, &v2, &v1);
return printf("gbr using libgit2 %d.%d.%d\n", v3[0], v2, v1);
}

canonical_decompiled_code:
int func0()
{
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

git_libgit2_version(v3, &v2, &v1);
return printf("gbr using libgit2 %d.%d.%d\n", v3[0], v2, v1);
}

original_code:
static void dump_version(void)
{
 int major, minor, rev;
 git_libgit2_version(&major, &minor, &rev);
 printf("gbr using libgit2 %d.%d.%d\n",
        major, minor, rev);
}

canonical_original_code:
static void dump_version()
{
 int major; int minor; int rev;
 git_libgit2_version(&major, &minor, &rev);
 printf("gbr using libgit2 %d.%d.%d\n",
        major, minor, rev);
}

variable_types: major int

variable_types: minor int

variable_types: rev int


decompiled_code:
char *__fastcall ctime_ts(char *s, int a2, time_t a3)
{
struct tm *v3; // rax
size_t v4; // rax
int *v6; // rax
char *v7; // rax
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

timer = a3;
v3 = localtime_r(&timer, &tp);
v4 = strftime(s, a2, "%F %H:%M:%S %z", v3);
s[v4] = 0;
if ( !v4 )
{
v6 = _errno_location();
v7 = strerror(*v6);
snprintf(s, a2, "%s", v7);
}
return s;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, int a2, time_t a3)
{
struct tm *v3; // rax
size_t v4; // rax
int *v6; // rax
char *v7; // rax
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

timer = a3;
v3 = localtime_r(&timer, &tp);
v4 = strftime(s, a2, "%F %H:%M:%S %z", v3);
s[v4] = 0;
if ( !v4 )
{
v6 = _errno_location();
v7 = strerror(*v6);
snprintf(s, a2, "%s", v7);
}
return s;
}

original_code:
static char *ctime_ts(char *buf, int sz, git_time_t ts)
{
 struct tm tm;
 size_t len;
 buf[len = strftime(buf, sz, "%F %H:%M:%S %z", localtime_r(&ts, &tm))] = '\0';
 if (len == 0) {
  snprintf(buf, sz, "%s", strerror((*__errno_location ())));
 }
 return buf;
}

canonical_original_code:
static char *ctime_ts(char *buf, int sz, long ts)
{
 struct tm tm;
 unsigned long len;
 buf[len = strftime(buf, sz, "%F %H:%M:%S %z", localtime_r(&ts, &tm))] = '\0';
 if (len == 0) {
  snprintf(buf, sz, "%s", strerror((*__errno_location ())));
 }
 return buf;
}

variable_types:
buf
char *

variable_types: sz int

variable_types: ts long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types:
len
unsigned long


decompiled_code:
int __fastcall gbr_perror(const char *a1)
{
const char **v1; // rax

v1 = (const char **)giterr_last();
return fprintf(stderr, "%s: %s\n", a1, *v1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
const char **v1; // rax

v1 = (const char **)giterr_last();
return fprintf(stderr, "%s: %s\n", a1, *v1);
}

original_code:
void gbr_perror(const char *prefix)
{
 fprintf(stderr, "%s: %s\n", prefix, giterr_last()->message);
}

canonical_original_code:
void gbr_perror(char *prefix)
{
 fprintf(stderr, "%s: %s\n", prefix, giterr_last()->message);
}

variable_types:
prefix
char *


decompiled_code:
__int64 __fastcall find_cdata_target(const char *a1)
{
unsigned int v1; // ecx

v1 = 4;
if ( strcmp(a1, "updated") )
{
v1 = 5;
if ( strcmp(a1, "published") )
v1 = -(strcmp(a1, "title") != 0);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // ecx

v1 = 4;
if ( strcmp(a1, "updated") )
{
v1 = 5;
if ( strcmp(a1, "published") )
v1 = -(strcmp(a1, "title") != 0);
}
return v1;
}

original_code:
static int find_cdata_target(const char *element)
{
 int ret;
 if (strcmp(element, "updated") == 0) {
  ret = F_UPDATED;
 } else if (strcmp(element, "published") == 0) {
  ret = F_PUBLISHED;
 } else if (strcmp(element, "title") == 0) {
  ret = F_TITLE;
 } else {
  ret = -1;
 }
 return ret;
}

canonical_original_code:
static int find_cdata_target(char *element)
{
 int ret;
 if (strcmp(element, "updated") == 0) {
  ret = F_UPDATED;
 } else if (strcmp(element, "published") == 0) {
  ret = F_PUBLISHED;
 } else if (strcmp(element, "title") == 0) {
  ret = F_TITLE;
 } else {
  ret = -1;
 }
 return ret;
}

variable_types:
element
char *

variable_types: ret int


decompiled_code:
const char *__fastcall find_attribute_value(const char **a1, const char *a2)
{
const char *v3; // rdi
__int64 v4; // rbx

v3 = *a1;
if ( v3 )
{
v4 = 0LL;
while ( strcmp(v3, a2) )
{
v4 += 2LL;
v3 = a1[v4];
if ( !v3 )
return v3;
}
v3 = a1[v4 + 1];
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func2(const char **a1, const char *a2)
{
const char *v3; // rdi
__int64 v4; // rbx

v3 = *a1;
if ( v3 )
{
v4 = 0LL;
while ( strcmp(v3, a2) )
{
v4 += 2LL;
v3 = a1[v4];
if ( !v3 )
return v3;
}
v3 = a1[v4 + 1];
}
return v3;
}

original_code:
static const char *find_attribute_value(const char **attrs, const char *name)
{
 int i;
 const char *value;
 for (i = 0, value = ((void *)0); attrs[i]; i += 2) {
  if (strcmp(attrs[i], name) == 0) {
   value = attrs[i+1];
   break;
  }
 }
 return value;
}

canonical_original_code:
static char *find_attribute_value(char **attrs, char *name)
{
 int i;
 char *value;
 for (i = 0, value = ((void *)0); attrs[i]; i += 2) {
  if (strcmp(attrs[i], name) == 0) {
   value = attrs[i+1];
   break;
  }
 }
 return value;
}

variable_types:
attrs
char **

variable_types:
name
char *

variable_types: i int

variable_types:
value
char *


decompiled_code:
char *__fastcall copy_attribute_override(void **a1, const char **a2, const char *a3)
{
char *result; // rax
const char *v4; // rbx

result = (char *)find_attribute_value(a2, a3);
if ( result )
{
v4 = result;
if ( *a1 )
free(*a1);
result = strdup(v4);
*a1 = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(void **a1, const char **a2, const char *a3)
{
char *result; // rax
const char *v4; // rbx

result = (char *)func2(a2, a3);
if ( result )
{
v4 = result;
if ( *a1 )
free(*a1);
result = strdup(v4);
*a1 = result;
}
return result;
}

original_code:
static void copy_attribute_override(char **tgt, const char **attrs, const char *name)
{
 const char *new_value;
 new_value = find_attribute_value(attrs, name);
 if (new_value != ((void *)0)) {
  if (*tgt != ((void *)0)) {
   free(*tgt);
  }
  *tgt = strdup(new_value);
 }
}

canonical_original_code:
static void copy_attribute_override(char **tgt, char **attrs, char *name)
{
 char *new_value;
 new_value = find_attribute_value(attrs, name);
 if (new_value != ((void *)0)) {
  if (*tgt != ((void *)0)) {
   free(*tgt);
  }
  *tgt = strdup(new_value);
 }
}

variable_types:
tgt
char **


decompiled_code:
char *__fastcall copy_attribute_keep_old(void **a1, const char **a2, const char *a3)
{
char *result; // rax

if ( !*a1 )
result = copy_attribute_override(a1, a2, a3);
return result;
}

canonical_decompiled_code:
char *__fastcall func12(void **a1, const char **a2, const char *a3)
{
char *result; // rax

if ( !*a1 )
result = func11(a1, a2, a3);
return result;
}

original_code:
static void copy_attribute_keep_old(char **tgt, const char **attrs, const char *name)
{
 if (*tgt == ((void *)0)) {
  copy_attribute_override(tgt, attrs, name);
 }
}

canonical_original_code:
static void copy_attribute_keep_old(char **tgt, char **attrs, char *name)
{
 if (*tgt == ((void *)0)) {
  copy_attribute_override(tgt, attrs, name);
 }
}


decompiled_code:
__int64 __fastcall tangle_node(__int64 *a1, _QWORD *a2)
{
__int64 result; // rax

if ( *a1 )
*(_QWORD *)(*a1 + 8) = a2;
result = *a1;
*a2 = *a1;
*a1 = (__int64)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, _QWORD *a2)
{
__int64 result; // rax

if ( *a1 )
*(_QWORD *)(*a1 + 8) = a2;
result = *a1;
*a2 = *a1;
*a1 = (__int64)a2;
return result;
}

original_code:
static void tangle_node(struct node **head, struct node *node)
{
 if (*head) {
  (*head)->prev = node;
 }
 node->next = *head;
 *head = node;
}

variable_types: struct node { struct node *next; struct node *prev; char data[]; } **

variable_types:
node
struct node *


decompiled_code:
__int64 __fastcall kvnode_key(__int64 a1)
{
return a1 + 24;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1 + 24;
}

original_code:
static const char *kvnode_key(struct node *node)
{
 return node->data + sizeof(size_t);
}

canonical_original_code:
static char *kvnode_key(struct node *node)
{
 return node->data + sizeof(unsigned long);
}

variable_types: struct node { struct node *next; struct node *prev; char data[]; } *


decompiled_code:
__int64 __fastcall kvnode_value(__int64 a1)
{
return *(_QWORD *)(a1 + 16) + a1 + 16;
}

original_code:
static const char *kvnode_value(struct node *node)
{
 return node->data + *(size_t *)node->data;
}

canonical_original_code:
static char *kvnode_value(struct node *node)
{
 return node->data + *(unsigned long *)node->data;
}

user_defined_types: struct node { struct node *next; struct node *prev; char data[]; }


decompiled_code:
void *__fastcall alloc_node(__int64 a1)
{
void *v1; // rax
void *v2; // rbx

v1 = malloc(a1 + 16);
v2 = v1;
if ( v1 )
memset(v1, 0, a1 + 16);
return v2;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
void *v1; // rax
void *v2; // rbx

v1 = malloc(a1 + 16);
v2 = v1;
if ( v1 )
memset(v1, 0, a1 + 16);
return v2;
}

original_code:
static struct node *alloc_node(size_t sz)
{
 struct node *node;
 node = malloc(sizeof(*node) + sz);
 if (node != ((void *)0)) {
  memset(node, 0, sizeof(*node) + sz);
 }
 return node;
}

canonical_original_code:
static struct node *alloc_node(unsigned long sz)
{
 struct node *node;
 node = malloc(sizeof(*node) + sz);
 if (node != ((void *)0)) {
  memset(node, 0, sizeof(*node) + sz);
 }
 return node;
}

variable_types:
sz
unsigned long

return_type: struct node { struct node *next; struct node *prev; char data[]; } *