decompiled_code:
__int64 mythread_self()
{
return _mythread_gettid();
}

canonical_decompiled_code:
__int64 func0()
{
return _mythread_gettid();
}

original_code:
mythread_t mythread_self()
{
 pid_t tid;
 mythread_t self_tcb;
 tid = __mythread_gettid();
 self_tcb.tid = tid;
 return (self_tcb);
}

canonical_original_code:
struct mythread mythread_self()
{
 int tid;
 struct mythread self_tcb;
 tid = __mythread_gettid();
 self_tcb.tid = tid;
 return (self_tcb);
}

variable_types: tid int

return_type: struct mythread { int tid; }


decompiled_code:
__int64 __fastcall mythread_exit(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rax

v2 = _mythread_selfptr();
*(_DWORD *)(v2 + 4) = 3;
*(_QWORD *)(v2 + 24) = a1;
v3 = *(_QWORD *)(v2 + 32);
if ( v3 )
*(_DWORD *)(v3 + 4) = 1;
_mythread_dispatcher(v2);
return _mythread_do_exit();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rax

v2 = _mythread_selfptr();
*(_DWORD *)(v2 + 4) = 3;
*(_QWORD *)(v2 + 24) = a1;
v3 = *(_QWORD *)(v2 + 32);
if ( v3 )
*(_DWORD *)(v3 + 4) = 1;
_mythread_dispatcher(v2);
return func0();
}

original_code:
void mythread_exit(void *return_val)
{
 mythread_private_t *self_ptr;
 self_ptr = __mythread_selfptr();
 self_ptr->state = 3;
 self_ptr->returnValue = return_val;
 if (self_ptr->blockedForJoin != ((void *)0))
  self_ptr->blockedForJoin->state = 1;
 __mythread_dispatcher(self_ptr);
 __mythread_do_exit();
}

canonical_original_code:
void mythread_exit(void *return_val)
{
 struct mythread_private *self_ptr;
 self_ptr = __mythread_selfptr();
 self_ptr->state = 3;
 self_ptr->returnValue = return_val;
 if (self_ptr->blockedForJoin != ((void *)0))
  self_ptr->blockedForJoin->state = 1;
 __mythread_dispatcher(self_ptr);
 __mythread_do_exit();
}

variable_types: struct mythread_private { int tid; int state; void *(*start_func)(void *); void *args; void *returnValue; struct mythread_private *blockedForJoin; struct futex { int count; } sched_futex; struct mythread_private *prev; } *

return_type: void

user_defined_types: struct mythread_private { int tid; int state; void *(*start_func)(void *); void *args; void *returnValue; struct mythread_private *blockedForJoin; struct futex sched_futex; struct mythread_private *prev; }


decompiled_code:
void __fastcall mythread_q_init(__int64 a1)
{
*(_QWORD *)(a1 + 48) = a1;
*(_QWORD *)(a1 + 56) = a1;
mythread_q_head = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 48) = a1;
*(_QWORD *)(a1 + 56) = a1;
mythread_q_head = a1;
}

original_code:
void mythread_q_init(mythread_private_t * node)
{
 node->prev = node;
 node->next = node;
 mythread_q_head = node;
}

canonical_original_code:
void mythread_q_init(struct mythread_private *node)
{
 node->prev = node;
 node->next = node;
 mythread_q_head = node;
}


decompiled_code:
void __fastcall mythread_q_add(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = mythread_q_head;
if ( mythread_q_head )
{
*(_QWORD *)(a1 + 56) = mythread_q_head;
v2 = *(_QWORD *)(v1 + 48);
*(_QWORD *)(a1 + 48) = v2;
*(_QWORD *)(v2 + 56) = a1;
*(_QWORD *)(v1 + 48) = a1;
}
else
{
mythread_q_init(a1);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

v1 = mythread_q_head;
if ( mythread_q_head )
{
*(_QWORD *)(a1 + 56) = mythread_q_head;
v2 = *(_QWORD *)(v1 + 48);
*(_QWORD *)(a1 + 48) = v2;
*(_QWORD *)(v2 + 56) = a1;
*(_QWORD *)(v1 + 48) = a1;
}
else
{
func0(a1);
}
}

original_code:
void mythread_q_add(mythread_private_t * node)
{
 if (mythread_q_head == ((void *)0)) {
  mythread_q_init(node);
  return;
 }
 node->next = mythread_q_head;
 node->prev = mythread_q_head->prev;
 mythread_q_head->prev->next = node;
 mythread_q_head->prev = node;
 return;
}

canonical_original_code:
void mythread_q_add(struct mythread_private *node)
{
 if (mythread_q_head == ((void *)0)) {
  mythread_q_init(node);
  return;
 }
 node->next = mythread_q_head;
 node->prev = mythread_q_head->prev;
 mythread_q_head->prev->next = node;
 mythread_q_head->prev = node;
 return;
}


decompiled_code:
__int64 __fastcall mythread_q_delete(__int64 a1)
{
__int64 result; // rax

if ( mythread_q_head == a1 )
{
if ( *(_QWORD *)(a1 + 56) == a1 )
{
puts("The Q is now Empty!");
mythread_q_head = 0LL;
}
else
{
mythread_q_head = *(_QWORD *)(a1 + 56);
}
}
result = *(_QWORD *)(a1 + 48);
*(_QWORD *)(result + 56) = *(_QWORD *)(a1 + 56);
*(_QWORD *)(*(_QWORD *)(a1 + 56) + 48LL) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

if ( mythread_q_head == a1 )
{
if ( *(_QWORD *)(a1 + 56) == a1 )
{
puts("The Q is now Empty!");
mythread_q_head = 0LL;
}
else
{
mythread_q_head = *(_QWORD *)(a1 + 56);
}
}
result = *(_QWORD *)(a1 + 48);
*(_QWORD *)(result + 56) = *(_QWORD *)(a1 + 56);
*(_QWORD *)(*(_QWORD *)(a1 + 56) + 48LL) = result;
return result;
}

original_code:
void mythread_q_delete(mythread_private_t * node)
{
 mythread_private_t *p;
 if (node == mythread_q_head && node->next == mythread_q_head) {
  printf("The Q is now Empty!\n");
  mythread_q_head = ((void *)0);
 }
 if (node == mythread_q_head)
  mythread_q_head = node->next;
 p = node->prev;
 p->next = node->next;
 node->next->prev = p;
 return;
}

canonical_original_code:
void mythread_q_delete(struct mythread_private *node)
{
 struct mythread_private *p;
 if (node == mythread_q_head && node->next == mythread_q_head) {
  printf("The Q is now Empty!\n");
  mythread_q_head = ((void *)0);
 }
 if (node == mythread_q_head)
  mythread_q_head = node->next;
 p = node->prev;
 p->next = node->next;
 node->next->prev = p;
 return;
}


decompiled_code:
int mythread_q_state_display()
{
__int64 v0; // rbx
int result; // eax

if ( mythread_q_head )
{
puts("\n The Q contents are -> ");
v0 = mythread_q_head;
do
{
result = printf(" %d\n", *(unsigned int *)(v0 + 4));
v0 = *(_QWORD *)(v0 + 56);
}
while ( mythread_q_head != v0 );
}
return result;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rbx
int result; // eax

if ( mythread_q_head )
{
puts("\n The Q contents are -> ");
v0 = mythread_q_head;
do
{
result = printf(" %d\n", *(unsigned int *)(v0 + 4));
v0 = *(_QWORD *)(v0 + 56);
}
while ( mythread_q_head != v0 );
}
return result;
}

original_code:
void mythread_q_state_display()
{
 if (mythread_q_head != ((void *)0)) {
  printf("\n The Q contents are -> \n");
  mythread_private_t *p;
  p = mythread_q_head;
  do {
   printf(" %d\n", p->state);
   p = p->next;
  } while (p != mythread_q_head);
 }
}

canonical_original_code:
void mythread_q_state_display()
{
 if (mythread_q_head != ((void *)0)) {
  printf("\n The Q contents are -> \n");
  struct mythread_private *p;
  p = mythread_q_head;
  do {
   printf(" %d\n", p->state);
   p = p->next;
  } while (p != mythread_q_head);
 }
}


decompiled_code:
__int64 __fastcall mythread_q_search(__int64 a1)
{
__int64 result; // rax

if ( !mythread_q_head )
return mythread_q_head;
result = mythread_q_head;
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 56);
if ( mythread_q_head == result )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( !mythread_q_head )
return mythread_q_head;
result = mythread_q_head;
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 56);
if ( mythread_q_head == result )
return 0LL;
}
return result;
}

original_code:
mythread_private_t *mythread_q_search(unsigned long new_tid)
{
 mythread_private_t *p;
 if (mythread_q_head != ((void *)0)) {
  p = mythread_q_head;
  do {
   if (p->tid == new_tid)
    return p;
   p = p->next;
  } while (p != mythread_q_head);
 }
 return ((void *)0);
}

canonical_original_code:
struct mythread_private *mythread_q_search(unsigned long new_tid)
{
 struct mythread_private *p;
 if (mythread_q_head != ((void *)0)) {
  p = mythread_q_head;
  do {
   if (p->tid == new_tid)
    return p;
   p = p->next;
  } while (p != mythread_q_head);
 }
 return ((void *)0);
}

return_type: struct mythread_private { int tid; int state; void *(*start_func)(void *); void *args; void *returnValue; struct mythread_private *blockedForJoin; struct futex { int count; } sched_futex; struct mythread_private *prev; } *


decompiled_code:
__int64 __fastcall mythread_wrapper(__int64 a1)
{
futex_down((volatile signed __int64 *)(a1 + 40));
(*(void (__fastcall **)(_QWORD))(a1 + 8))(*(_QWORD *)(a1 + 16));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
func2((volatile signed __int64 *)(a1 + 40));
(*(void (__fastcall **)(_QWORD))(a1 + 8))(*(_QWORD *)(a1 + 16));
return 0LL;
}

original_code:
int mythread_wrapper(void *thread_tcb)
{
 mythread_private_t *new_tcb;
 new_tcb = (mythread_private_t *) thread_tcb;
 do {} while(0);;
 futex_down(&new_tcb->sched_futex);
 do {} while(0);;
 new_tcb->start_func(new_tcb->args);
 return 0;
}

canonical_original_code:
int mythread_wrapper(void *thread_tcb)
{
 struct mythread_private *new_tcb;
 new_tcb = (struct mythread_private *) thread_tcb;
 do {} while(0);;
 futex_down(&new_tcb->sched_futex);
 do {} while(0);;
 new_tcb->start_func(new_tcb->args);
 return 0;
}

return_type: int


decompiled_code:
void __noreturn mythread_idle()
{
__int64 v0; // rax
int v1; // ecx
int *v2; // rax
int v3; // edx

while ( 1 )
{
v0 = _mythread_selfptr();
v1 = *(_DWORD *)v0;
v2 = *(int **)(v0 + 56);
v3 = *v2;
if ( v1 == *v2 )
break;
while ( v2[1] == 3 )
{
v2 = (int *)*((_QWORD *)v2 + 7);
v3 = *v2;
if ( *v2 == v1 )
goto LABEL_7;
}
if ( v1 == v3 )
break;
mythread_yield();
}
LABEL_7:
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // rax
int v1; // ecx
int *v2; // rax
int v3; // edx

while ( 1 )
{
v0 = _mythread_selfptr();
v1 = *(_DWORD *)v0;
v2 = *(int **)(v0 + 56);
v3 = *v2;
if ( v1 == *v2 )
break;
while ( v2[1] == 3 )
{
v2 = (int *)*((_QWORD *)v2 + 7);
v3 = *v2;
if ( *v2 == v1 )
goto LABEL_7;
}
if ( v1 == v3 )
break;
mythread_yield();
}
LABEL_7:
exit(0);
}

original_code:
void *mythread_idle(void *phony)
{
 mythread_private_t *traverse_tcb;
 pid_t idle_tcb_tid;
 while (1) {
  do {} while(0);;
  traverse_tcb = __mythread_selfptr();
  idle_tcb_tid = traverse_tcb->tid;
  traverse_tcb = traverse_tcb->next;
  while (traverse_tcb->tid != idle_tcb_tid) {
   if (traverse_tcb->state != 3) {
    break;
   }
   traverse_tcb = traverse_tcb->next;
  }
  if (traverse_tcb->tid == idle_tcb_tid)
   exit(0);
  mythread_yield();
 }
}

canonical_original_code:
void *mythread_idle(void *phony)
{
 struct mythread_private *traverse_tcb;
 int idle_tcb_tid;
 while (1) {
  do {} while(0);;
  traverse_tcb = __mythread_selfptr();
  idle_tcb_tid = traverse_tcb->tid;
  traverse_tcb = traverse_tcb->next;
  while (traverse_tcb->tid != idle_tcb_tid) {
   if (traverse_tcb->state != 3) {
    break;
   }
   traverse_tcb = traverse_tcb->next;
  }
  if (traverse_tcb->tid == idle_tcb_tid)
   exit(0);
  mythread_yield();
 }
}

variable_types:
phony
void *

return_type: void *


decompiled_code:
__int64 mythread_yield()
{
__int64 v0; // rbx

v0 = _mythread_selfptr();
futex_down((volatile signed __int64 *)&gfutex);
if ( (unsigned int)_mythread_dispatcher(v0) == -1 )
{
futex_up((volatile signed __int64 *)&gfutex);
}
else
{
if ( *(int *)(v0 + 40) > 0 )
futex_down((volatile signed __int64 *)(v0 + 40));
futex_up((volatile signed __int64 *)&gfutex);
futex_down((volatile signed __int64 *)(v0 + 40));
}
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx

v0 = _mythread_selfptr();
func4((volatile signed __int64 *)&gfutex);
if ( (unsigned int)func5(v0) == -1 )
{
func2((volatile signed __int64 *)&gfutex);
}
else
{
if ( *(int *)(v0 + 40) > 0 )
func4((volatile signed __int64 *)(v0 + 40));
func2((volatile signed __int64 *)&gfutex);
func4((volatile signed __int64 *)(v0 + 40));
}
return 0LL;
}

original_code:
int mythread_yield()
{
 mythread_private_t *self;
 int retval;
 self = __mythread_selfptr();
 futex_down(&gfutex);
 retval = __mythread_dispatcher(self);
 if (retval == -1) {
  futex_up(&gfutex);
  return 0;
 }
 do {} while(0);;
 if (self->sched_futex.count > 0)
  futex_down(&self->sched_futex);
 futex_up(&gfutex);
 do {} while(0);;
 futex_down(&self->sched_futex);
 return 0;
}

canonical_original_code:
int mythread_yield()
{
 struct mythread_private *self;
 int retval;
 self = __mythread_selfptr();
 futex_down(&gfutex);
 retval = __mythread_dispatcher(self);
 if (retval == -1) {
  futex_up(&gfutex);
  return 0;
 }
 do {} while(0);;
 if (self->sched_futex.count > 0)
  futex_down(&self->sched_futex);
 futex_up(&gfutex);
 do {} while(0);;
 futex_down(&self->sched_futex);
 return 0;
}

variable_types: retval int


decompiled_code:
__int64 __fastcall mythread_join(int a1, _QWORD *a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
__int64 result; // rax

v2 = _mythread_selfptr();
v3 = mythread_q_search(a1);
v4 = v3;
if ( *(_DWORD *)(v3 + 4) == 3 )
{
*a2 = *(_QWORD *)(v3 + 24);
result = 0LL;
}
else if ( *(_QWORD *)(v3 + 32) )
{
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(v3 + 32) = v2;
*(_DWORD *)(v2 + 4) = 2;
mythread_yield();
*a2 = *(_QWORD *)(v4 + 24);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, _QWORD *a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
__int64 result; // rax

v2 = _mythread_selfptr();
v3 = mythread_q_search(a1);
v4 = v3;
if ( *(_DWORD *)(v3 + 4) == 3 )
{
*a2 = *(_QWORD *)(v3 + 24);
result = 0LL;
}
else if ( *(_QWORD *)(v3 + 32) )
{
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(v3 + 32) = v2;
*(_DWORD *)(v2 + 4) = 2;
mythread_yield();
*a2 = *(_QWORD *)(v4 + 24);
result = 0LL;
}
return result;
}

original_code:
int mythread_join(mythread_t target_thread, void **status)
{
 mythread_private_t *target, *self_ptr;
 self_ptr = __mythread_selfptr();
 do {} while(0);;
 target = mythread_q_search(target_thread.tid);
 if (target->state == 3) {
  *status = target->returnValue;
  return 0;
 }
 do {} while(0);;
 if (target->blockedForJoin != ((void *)0))
  return -1;
 target->blockedForJoin = self_ptr;
 do {} while(0);;
 self_ptr->state = 2;
 mythread_yield();
 *status = target->returnValue;
 return 0;
}

canonical_original_code:
int mythread_join(struct mythread target_thread, void **status)
{
 struct mythread_private *target; struct mythread_private *self_ptr;
 self_ptr = __mythread_selfptr();
 do {} while(0);;
 target = mythread_q_search(target_thread.tid);
 if (target->state == 3) {
  *status = target->returnValue;
  return 0;
 }
 do {} while(0);;
 if (target->blockedForJoin != ((void *)0))
  return -1;
 target->blockedForJoin = self_ptr;
 do {} while(0);;
 self_ptr->state = 2;
 mythread_yield();
 *status = target->returnValue;
 return 0;
}

variable_types:
status
void **


sigHandler

repo: jitrc/eklavya-ros-pkg

decompiled_code:
__int64 __fastcall sigHandler(int a1)
{
signal(a1, (__sighandler_t)((char *)sigHandler + 1));
return vn200_disconnect(&vn200);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
signal(a1, (__sighandler_t)((char *)sigHandler + 1));
return vn200_disconnect(&vn200);
}

original_code:
void sigHandler(int sig) {
  signal(sig, ((__sighandler_t) 1));
  vn200_disconnect(&vn200);
}

canonical_original_code:
void sigHandler(int sig) {
  signal(sig, ((void (*)(int)) 1));
  vn200_disconnect(&vn200);
}

variable_types: sig int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 i; // rsi
double v4; // xmm0_8
double v5; // r14
double v6; // xmm0_8
double v7; // xmm1_8
double v8; // rbp
double v9; // xmm0_8
double v10; // [rsp+38h] [rbp-C0h]
double v11; // [rsp+38h] [rbp-C0h]
double v12; // [rsp+48h] [rbp-B0h]
double v13; // [rsp+50h] [rbp-A8h]
double v14; // [rsp+58h] [rbp-A0h]
float v15; // [rsp+64h] [rbp-94h] BYREF
float v16; // [rsp+68h] [rbp-90h] BYREF
float v17; // [rsp+6Ch] [rbp-8Ch] BYREF
__int64 v18[4]; // [rsp+70h] [rbp-88h] BYREF
double v19; // [rsp+90h] [rbp-68h] BYREF
double v20; // [rsp+98h] [rbp-60h]
double v21; // [rsp+A0h] [rbp-58h]
__int64 v22[4]; // [rsp+B0h] [rbp-48h] BYREF
unsigned __int16 v23; // [rsp+D4h] [rbp-24h] BYREF
unsigned __int16 v24; // [rsp+D6h] [rbp-22h] BYREF
double v25[4]; // [rsp+D8h] [rbp-20h] BYREF

vn200_connect(&vn200, "/dev/serial/by-id/usb-FTDI_USB-RS232_Cable_FTUTUVO5-if00-port0", 115200LL);
for ( i = 0LL; ; i = (unsigned int)(i + 1) )
{
printf("Iter: %d\n", i);
vn200_getInsSolution(&vn200, v25, &v24, &v23, v22, &v19, v18, &v17, &v16, &v15);
v11 = 3.141592653589793 * v19 / 180.0;
v7 = 3.141592653589793 * v20 / 180.0;
v8 = v21;
v12 = 1.0 - pow(0.9966471893352525, v7);
v14 = sin(v11);
v9 = 1.0 - pow(v14 * v12, v7);
if ( v9 < 0.0 )
v4 = sqrt(v9);
else
v4 = sqrt(v9);
v13 = 6378137.0 / v4;
v10 = (v8 + 6378137.0 / v4) * sin(v11 + 1.570796326794897);
v5 = sin(v7 + 1.570796326794897);
v6 = sin(v7);
printf(
"INS Solution:\n"
" GPS Time: %f\n"
" GPS Week: %u\n"
" INS Status: %.4X\n"
" YPR.Yaw: %+#7.2f\n"
" YPR.Pitch: %+#7.2f\n"
" YPR.Roll: %+#7.2f\n"
" LLA.Lattitude: %+#7.8f\n"
" LLA.Longitude: %+#7.8f\n"
" LLA.Altitude: %+#7.8f\n"
" Velocity.North: %+#7.2f\n"
" Velocity.East: %+#7.2f\n"
" Velocity.Down: %+#7.2f\n"
" Attitude Uncertainty: %+#7.2f\n"
" Position Uncertainty: %+#7.2f\n"
" Velocity Uncertainty: %+#7.2f\n"
" Cartesian X: %+#lf\n"
" Cartesian Y: %+#lf\n"
" Cartesian Z: %+#lf\n",
v24,
v23,
v25[0],
*(double *)v22,
*(double *)&v22[1],
*(double *)&v22[2],
v19,
v20,
v21,
*(double *)v18,
v18[1],
v18[2],
v17,
v16,
v15,
v10 * v5,
v6 * v10,
((1.0 - v12) * v13 + v8) * v14);
puts("\n");
sleep(1u);
}
}

original_code:
int main()
{
 double gpsTime;
 unsigned short gpsWeek, status;
 VnVector3 ypr, latitudeLognitudeAltitude, nedVelocity;
 float attitudeUncertainty, positionUncertainty, velocityUncertainty;
  double x,y,z,a,f,b,e2,Nphi,latitude,longitude,altitude;
 int i = 0;
 vn200_connect(&vn200, COM_PORT, BAUD_RATE);
  while(1) {
    printf("Iter: %d\n", i++);
  vn200_getInsSolution(
   &vn200,
   &gpsTime,
      &gpsWeek,
   &status,
   &ypr,
   &latitudeLognitudeAltitude,
   &nedVelocity,
   &attitudeUncertainty,
   &positionUncertainty,
   &velocityUncertainty);
    latitude = latitudeLognitudeAltitude.c0*3.141592653589793238462643/180;
    longitude =latitudeLognitudeAltitude.c1*3.141592653589793238462643/180;
    altitude = latitudeLognitudeAltitude.c2;
    a = 6378137; f = 1/298.257223563;
    b = a*(1 - f);
    e2 = 1 - pow((b/a),2);
    Nphi = a/sqrt(1 - pow(e2*sin(latitude),2));
    x = (Nphi + altitude)*(sin(latitude+1.57079632679489661923))*(sin(longitude+1.57079632679489661923));
    y = (Nphi + altitude)*(sin(latitude+1.57079632679489661923))*sin(longitude);
    z = (Nphi*(1 - e2) + altitude)*sin(latitude);
  printf("INS Solution:\n"
   "  GPS Time:               %f\n"
   "  GPS Week:               %u\n"
   "  INS Status:             %.4X\n"
   "  YPR.Yaw:                %+#7.2f\n"
   "  YPR.Pitch:              %+#7.2f\n"
   "  YPR.Roll:               %+#7.2f\n"
   "  LLA.Lattitude:          %+#7.8f\n"
   "  LLA.Longitude:          %+#7.8f\n"
   "  LLA.Altitude:           %+#7.8f\n"
   "  Velocity.North:         %+#7.2f\n"
   "  Velocity.East:          %+#7.2f\n"
   "  Velocity.Down:          %+#7.2f\n"
   "  Attitude Uncertainty:   %+#7.2f\n"
   "  Position Uncertainty:   %+#7.2f\n"
   "  Velocity Uncertainty:   %+#7.2f\n"
      "  Cartesian X:            %+#lf\n"
      "  Cartesian Y:            %+#lf\n"
      "  Cartesian Z:            %+#lf\n",
   gpsTime,
   gpsWeek,
   status,
   ypr.c0,
   ypr.c1,
   ypr.c2,
   latitudeLognitudeAltitude.c0,
   latitudeLognitudeAltitude.c1,
   latitudeLognitudeAltitude.c2,
   nedVelocity.c0,
   nedVelocity.c1,
   nedVelocity.c2,
   attitudeUncertainty,
   positionUncertainty,
   velocityUncertainty,
      x,
      y,
      z);
  printf("\n\n");
  sleep(1);
 }
 vn200_disconnect(&vn200);
 return 0;
}

canonical_original_code:
int main()
{
 double gpsTime;
 unsigned short gpsWeek; unsigned short status;
 struct VnVector3 ypr; struct VnVector3 latitudeLognitudeAltitude; struct VnVector3 nedVelocity;
 float attitudeUncertainty; float positionUncertainty; float velocityUncertainty;
  double x; double y; double z; double a; double f; double b; double e2; double Nphi; double latitude; double longitude; double altitude;
 int i = 0;
 vn200_connect(&vn200, COM_PORT, BAUD_RATE);
  while(1) {
    printf("Iter: %d\n", i++);
  vn200_getInsSolution(
   &vn200,
   &gpsTime,
      &gpsWeek,
   &status,
   &ypr,
   &latitudeLognitudeAltitude,
   &nedVelocity,
   &attitudeUncertainty,
   &positionUncertainty,
   &velocityUncertainty);
    latitude = latitudeLognitudeAltitude.c0*3.141592653589793238462643/180;
    longitude =latitudeLognitudeAltitude.c1*3.141592653589793238462643/180;
    altitude = latitudeLognitudeAltitude.c2;
    a = 6378137; f = 1/298.257223563;
    b = a*(1 - f);
    e2 = 1 - pow((b/a),2);
    Nphi = a/sqrt(1 - pow(e2*sin(latitude),2));
    x = (Nphi + altitude)*(sin(latitude+1.57079632679489661923))*(sin(longitude+1.57079632679489661923));
    y = (Nphi + altitude)*(sin(latitude+1.57079632679489661923))*sin(longitude);
    z = (Nphi*(1 - e2) + altitude)*sin(latitude);
  printf("INS Solution:\n"
   "  GPS Time:               %f\n"
   "  GPS Week:               %u\n"
   "  INS Status:             %.4X\n"
   "  YPR.Yaw:                %+#7.2f\n"
   "  YPR.Pitch:              %+#7.2f\n"
   "  YPR.Roll:               %+#7.2f\n"
   "  LLA.Lattitude:          %+#7.8f\n"
   "  LLA.Longitude:          %+#7.8f\n"
   "  LLA.Altitude:           %+#7.8f\n"
   "  Velocity.North:         %+#7.2f\n"
   "  Velocity.East:          %+#7.2f\n"
   "  Velocity.Down:          %+#7.2f\n"
   "  Attitude Uncertainty:   %+#7.2f\n"
   "  Position Uncertainty:   %+#7.2f\n"
   "  Velocity Uncertainty:   %+#7.2f\n"
      "  Cartesian X:            %+#lf\n"
      "  Cartesian Y:            %+#lf\n"
      "  Cartesian Z:            %+#lf\n",
   gpsTime,
   gpsWeek,
   status,
   ypr.c0,
   ypr.c1,
   ypr.c2,
   latitudeLognitudeAltitude.c0,
   latitudeLognitudeAltitude.c1,
   latitudeLognitudeAltitude.c2,
   nedVelocity.c0,
   nedVelocity.c1,
   nedVelocity.c2,
   attitudeUncertainty,
   positionUncertainty,
   velocityUncertainty,
      x,
      y,
      z);
  printf("\n\n");
  sleep(1);
 }
 vn200_disconnect(&vn200);
 return 0;
}

variable_types: gpsTime double

variable_types:
gpsWeek
unsigned short

variable_types:
status
unsigned short

variable_types: struct VnVector3 { double c0; double c1; double c2; }

variable_types: attitudeUncertainty float

variable_types: positionUncertainty float

variable_types: velocityUncertainty float

variable_types: x double

variable_types: y double

variable_types: z double

variable_types: a double

variable_types: f double

variable_types: b double

variable_types: Nphi double

variable_types: latitude double

variable_types: longitude double

variable_types: altitude double

variable_types: i int


getEnvPairMine

decompiled_code:
__int64 getEnvPairMine()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
char* getEnvPairMine(int i) {
    return ((void *)0);
}

canonical_original_code:
char *getEnvPairMine(int i) {
    return ((void *)0);
}

return_type: char *


repo: jjlin/edln

decompiled_code:
__int64 init_rl_line_buffer()
{
rl_replace_line();
rl_point = rl_end;
rl_redisplay();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
rl_replace_line();
rl_point = rl_end;
rl_redisplay();
return 0LL;
}

original_code:
int init_rl_line_buffer(void)
{
    rl_replace_line(orig_target, 0);
    rl_point = rl_end;
    rl_redisplay();
    return 0;
}

canonical_original_code:
int init_rl_line_buffer()
{
    rl_replace_line(orig_target, 0);
    rl_point = rl_end;
    rl_redisplay();
    return 0;
}


decompiled_code:
__int64 edln_rl_filename_completion_function()
{
rl_completion_append_character = 0;
return rl_filename_completion_function();
}

canonical_decompiled_code:
__int64 func8()
{
rl_completion_append_character = 0;
return rl_filename_completion_function();
}

original_code:
char* edln_rl_filename_completion_function(const char* text, int state)
{
    rl_completion_append_character = '\0';
    return rl_filename_completion_function(text, state);
}

canonical_original_code:
char *edln_rl_filename_completion_function(char *text, int state)
{
    rl_completion_append_character = '\0';
    return rl_filename_completion_function(text, state);
}

variable_types:
text
char *

variable_types: state int


decompiled_code:
void customize_rl_completion_behavior()
{
rl_completer_word_break_characters = (__int64)"";
rl_completion_entry_function = (__int64)edln_rl_filename_completion_function;
}

canonical_decompiled_code:
void func9()
{
rl_completer_word_break_characters = (__int64)"";
rl_completion_entry_function = (__int64)edln_rl_filename_completion_function;
}

original_code:
void customize_rl_completion_behavior(void)
{
    rl_completer_word_break_characters = "";
    rl_completion_entry_function = &edln_rl_filename_completion_function;
}

canonical_original_code:
void customize_rl_completion_behavior()
{
    rl_completer_word_break_characters = "";
    rl_completion_entry_function = &edln_rl_filename_completion_function;
}


decompiled_code:
void __fastcall change_to_symlink_dir(char *path)
{
int v1; // ecx
char *v2; // rax
__int64 v3; // rdx
char *v4; // rbx

v1 = strlen(path);
if ( v1 - 1 > 0 )
{
v2 = &path[v1 - 1];
v3 = (__int64)&v2[-(v1 - 2) - 1];
while ( 1 )
{
v4 = v2;
if ( *v2 == 47 )
break;
if ( --v2 == (char *)v3 )
return;
}
*v2 = 0;
if ( chdir(path) < 0 )
{
fprintf(stderr, "Warning: Couldn't chdir() to '%s': ", path);
perror(0LL);
}
*v4 = 47;
}
}

canonical_decompiled_code:
void __fastcall func10(char *path)
{
int v1; // ecx
char *v2; // rax
__int64 v3; // rdx
char *v4; // rbx

v1 = strlen(path);
if ( v1 - 1 > 0 )
{
v2 = &path[v1 - 1];
v3 = (__int64)&v2[-(v1 - 2) - 1];
while ( 1 )
{
v4 = v2;
if ( *v2 == 47 )
break;
if ( --v2 == (char *)v3 )
return;
}
*v2 = 0;
if ( chdir(path) < 0 )
{
fprintf(stderr, "Warning: Couldn't chdir() to '%s': ", path);
perror(0LL);
}
*v4 = 47;
}
}

original_code:
void change_to_symlink_dir(char* link_path)
{
    int i;
    for (i = strlen(link_path) - 1; i > 0; --i) {
        if (link_path[i] == '/') {
            link_path[i] = '\0';
            if (chdir(link_path) < 0) {
                fprintf(stderr, "Warning: Couldn't chdir() to '%s': ", link_path);
                perror(((void *)0));
            }
            link_path[i] = '/';
            break;
        }
    }
}

canonical_original_code:
void change_to_symlink_dir(char *link_path)
{
    int i;
    for (i = strlen(link_path) - 1; i > 0; --i) {
        if (link_path[i] == '/') {
            link_path[i] = '\0';
            if (chdir(link_path) < 0) {
                fprintf(stderr, "Warning: Couldn't chdir() to '%s': ", link_path);
                perror(((void *)0));
            }
            link_path[i] = '/';
            break;
        }
    }
}


decompiled_code:
const char *__fastcall remove_trailing_slashes(const char *a1)
{
const char *result; // rax

result = &a1[strlen(a1) - 1];
if ( a1 < result )
{
do
{
if ( *result != 47 )
break;
*result-- = 0;
}
while ( a1 != result );
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(const char *a1)
{
const char *result; // rax

result = &a1[strlen(a1) - 1];
if ( a1 < result )
{
do
{
if ( *result != 47 )
break;
*result-- = 0;
}
while ( a1 != result );
}
return result;
}

original_code:
void remove_trailing_slashes(char* path)
{
    char* last_char = path + strlen(path) - 1;
    while (last_char > path && *last_char == '/') {
        *last_char-- = '\0';
    }
}

canonical_original_code:
void remove_trailing_slashes(char *path)
{
    char *last_char = path + strlen(path) - 1;
    while (last_char > path && *last_char == '/') {
        *last_char-- = '\0';
    }
}

variable_types:
path
char *


decompiled_code:
void __noreturn fatal_error(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[4096]; // [rsp+20h] [rbp-10B8h] BYREF

if ( format )
{
va_start(arg, format);
vsnprintf(s, 0x1000uLL, format, arg);
fprintf(stderr, "%s\n", s);
}
else
{
perror(0LL);
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func12(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[4096]; // [rsp+20h] [rbp-10B8h] BYREF

if ( format )
{
va_start(arg, format);
vsnprintf(s, 0x1000uLL, format, arg);
fprintf(stderr, "%s\n", s);
}
else
{
perror(0LL);
}
exit(1);
}

original_code:
void fatal_error(const char* fmt, ...)
{
    char msg[4096];
    va_list ap;
    if (fmt) {
        __builtin_va_start(ap,fmt);
        vsnprintf(msg, sizeof(msg), fmt, ap);
        __builtin_va_end(ap);
        fprintf(stderr, "%s\n", msg);
    } else {
        perror(((void *)0));
    }
    exit(1);
}

canonical_original_code:
void fatal_error(char *fmt, ...)
{
    char msg[4096];
    __builtin_va_list ap;
    if (fmt) {
        __builtin_va_start(ap,fmt);
        vsnprintf(msg, sizeof(msg), fmt, ap);
        __builtin_va_end(ap);
        fprintf(stderr, "%s\n", msg);
    } else {
        perror(((void *)0));
    }
    exit(1);
}

variable_types:
fmt
char *

variable_types:
msg
char [4096]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // rbx
const char *v6; // rax
int v7; // eax

if ( argc == 2 )
{
v4 = (char *)argv[1];
remove_trailing_slashes(v4);
if ( readlink(v4, orig_target, 0xFFFuLL) >= 0 )
goto LABEL_13;
LABEL_24:
v7 = *__errno_location();
if ( v7 != 2 )
{
if ( v7 == 22 )
fatal_error("'%s' is not a symlink.", v4);
fatal_error(0LL);
}
fatal_error("'%s' does not exist.", v4);
}
if ( argc != 3 )
{
fprintf(stderr, "usage: %s symlink_to_edit [new_target]\n", *argv);
return 0;
}
v3 = argv[2];
v4 = (char *)argv[1];
remove_trailing_slashes(v4);
if ( readlink(v4, orig_target, 0xFFFuLL) < 0 )
goto LABEL_24;
if ( !v3 )
{
LABEL_13:
if ( !getcwd(orig_wd, 0x1000uLL) )
fatal_error("getcwd() failed (buffer too small).");
change_to_symlink_dir(v4);
customize_rl_completion_behavior();
rl_extend_line_buffer();
rl_pre_input_hook = (__int64)init_rl_line_buffer;
v6 = (const char *)readline();
v3 = v6;
if ( !v6 )
fatal_error("No input received, aborting.");
remove_trailing_slashes(v6);
if ( !strcmp(v3, orig_target) )
exit(0);
if ( !*v3 )
fatal_error("Can't symlink to an empty target.");
}
if ( chdir(orig_wd) < 0 )
{
fprintf(stderr, "Warning: Couldn't chdir() back to '%s': ", orig_wd);
perror(0LL);
}
if ( unlink(v4) < 0 )
fatal_error(0LL);
if ( symlink(v3, v4) < 0 )
fatal_error(0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // rbx
const char *v6; // rax
int v7; // eax

if ( argc == 2 )
{
v4 = (char *)argv[1];
func11(v4);
if ( readlink(v4, orig_target, 0xFFFuLL) >= 0 )
goto LABEL_13;
LABEL_24:
v7 = *__errno_location();
if ( v7 != 2 )
{
if ( v7 == 22 )
func12("'%s' is not a symlink.", v4);
func12(0LL);
}
func12("'%s' does not exist.", v4);
}
if ( argc != 3 )
{
fprintf(stderr, "usage: %s symlink_to_edit [new_target]\n", *argv);
return 0;
}
v3 = argv[2];
v4 = (char *)argv[1];
func11(v4);
if ( readlink(v4, orig_target, 0xFFFuLL) < 0 )
goto LABEL_24;
if ( !v3 )
{
LABEL_13:
if ( !getcwd(orig_wd, 0x1000uLL) )
func12("getcwd() failed (buffer too small).");
func10(v4);
func9();
rl_extend_line_buffer();
rl_pre_input_hook = (__int64)init_rl_line_buffer;
v6 = (const char *)readline();
v3 = v6;
if ( !v6 )
func12("No input received, aborting.");
func11(v6);
if ( !strcmp(v3, orig_target) )
exit(0);
if ( !*v3 )
func12("Can't symlink to an empty target.");
}
if ( chdir(orig_wd) < 0 )
{
fprintf(stderr, "Warning: Couldn't chdir() back to '%s': ", orig_wd);
perror(0LL);
}
if ( unlink(v4) < 0 )
func12(0LL);
if ( symlink(v3, v4) < 0 )
func12(0LL);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    char* link_path = ((void *)0);
    char* new_target = ((void *)0);
    switch (argc) {
    case 3:
        new_target = argv[2];
    case 2:
        link_path = argv[1];
        break;
    default:
        fprintf(stderr, "usage: %s symlink_to_edit [new_target]\n", argv[0]);
        return 0;
    }
    remove_trailing_slashes(link_path);
    if (readlink(link_path, orig_target, sizeof(orig_target)-1) < 0) {
        switch ((*__errno_location ())) {
        case 2:
            fatal_error("'%s' does not exist.", link_path);
            break;
        case 22:
            fatal_error("'%s' is not a symlink.", link_path);
            break;
        default:
            fatal_error(((void *)0));
            break;
        }
    }
    if (new_target == ((void *)0)) {
        if (!getcwd(orig_wd, sizeof(orig_wd))) {
            fatal_error("getcwd() failed (buffer too small).");
        }
        change_to_symlink_dir(link_path);
        customize_rl_completion_behavior();
        rl_extend_line_buffer(4096 +1);
        rl_pre_input_hook = &init_rl_line_buffer;
        new_target = readline("New target: ");
        if (new_target == ((void *)0))
            fatal_error("No input received, aborting.");
        remove_trailing_slashes(new_target);
        if (!strcmp(new_target, orig_target)) {
            exit(0);
        } else if (*new_target == '\0') {
            fatal_error("Can't symlink to an empty target.");
        }
    }
    if (chdir(orig_wd) < 0) {
        fprintf(stderr, "Warning: Couldn't chdir() back to '%s': ", orig_wd);
        perror(((void *)0));
    }
    if (unlink(link_path) < 0)
        fatal_error(((void *)0));
    if (symlink(new_target, link_path) < 0)
        fatal_error(((void *)0));
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *link_path = ((void *)0);
    char *new_target = ((void *)0);
    switch (argc) {
    case 3:
        new_target = argv[2];
    case 2:
        link_path = argv[1];
        break;
    default:
        fprintf(stderr, "usage: %s symlink_to_edit [new_target]\n", argv[0]);
        return 0;
    }
    remove_trailing_slashes(link_path);
    if (readlink(link_path, orig_target, sizeof(orig_target)-1) < 0) {
        switch ((*__errno_location ())) {
        case 2:
            fatal_error("'%s' does not exist.", link_path);
            break;
        case 22:
            fatal_error("'%s' is not a symlink.", link_path);
            break;
        default:
            fatal_error(((void *)0));
            break;
        }
    }
    if (new_target == ((void *)0)) {
        if (!getcwd(orig_wd, sizeof(orig_wd))) {
            fatal_error("getcwd() failed (buffer too small).");
        }
        change_to_symlink_dir(link_path);
        customize_rl_completion_behavior();
        rl_extend_line_buffer(4096 +1);
        rl_pre_input_hook = &init_rl_line_buffer;
        new_target = readline("New target: ");
        if (new_target == ((void *)0))
            fatal_error("No input received, aborting.");
        remove_trailing_slashes(new_target);
        if (!strcmp(new_target, orig_target)) {
            exit(0);
        } else if (*new_target == '\0') {
            fatal_error("Can't symlink to an empty target.");
        }
    }
    if (chdir(orig_wd) < 0) {
        fprintf(stderr, "Warning: Couldn't chdir() back to '%s': ", orig_wd);
        perror(((void *)0));
    }
    if (unlink(link_path) < 0)
        fatal_error(((void *)0));
    if (symlink(new_target, link_path) < 0)
        fatal_error(((void *)0));
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


usage

repo: jjolly/anagram

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "%s: Anagrammer\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "%s: Anagrammer\n", a1);
}

original_code:
void usage(const char *name)
{
  fprintf(stderr, "%s: Anagrammer\n", name);
}

canonical_original_code:
void usage(char *name)
{
  fprintf(stderr, "%s: Anagrammer\n", name);
}

variable_types:
name
char *


decompiled_code:
void __fastcall __noreturn error_usage(const char *a1, int a2)
{
usage(a1);
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1, int a2)
{
func7(a1);
exit(a2);
}

original_code:
void error_usage(const char *name, int err)
{
  usage(name);
  exit(err);
}

canonical_original_code:
void error_usage(char *name, int err)
{
  usage(name);
  exit(err);
}

variable_types: err int


main

original_code:
int main(int argc, char *argv[])
{
  char *srch, match[(64)], word[(64)];
  int count[26], ci, wild = 0, finding = 1, pos = 0;
  if ( argc < 2 )
    error_usage(argv[0], 1);
  for(ci = 0; ci < 26; ci++) count[ci] = 0;
  srch = argv[1];
  while(*srch != '\0')
  {
    ci = 1;
    if ( *srch >= '0' && *srch <= '9' )
    {
      ci = 0;
      while(*srch >= '0' && *srch <= '9')
        ci = ci * 10 + *(srch++) - '0';
    }
    if ( *srch >= 'a' && *srch <= 'z' ) count[*srch - 'a'] += ci;
    else if ( *srch >= 'A' && *srch <= 'Z' ) count[*srch - 'A'] += ci;
    else if ( *srch == '.' || *srch == '_' ) wild += ci;
    else error_usage(argv[0], 1);
    srch++;
  }
  match[0] = '\0';
  word[0] = '\0';
  while((ci = fgetc(stdin)) != (-1))
  {
    if ( ci & 0x80 )
      while ( (ci<<=1) & 0x80 ) fgetc(stdin);
    else if ( ci == '\n' || ci == '\r' )
    {
      if ( *word != '\0' && finding == 1 )
        fprintf(stdout, "%s\n", word);
      srch = match;
      while(*srch != '\0')
      {
        if ( *srch == '.' ) wild++;
        else count[*srch - 'a']++;
        srch++;
      }
      match[0] = '\0';
      word[0] = '\0';
      pos = 0;
      finding = 1;
    }
    else if ( finding == 1 )
    {
      if ( ci >= 'A' && ci <= 'Z' ) ci += 'a' - 'A';
      if ( ci >= 'a' && ci <= 'z' )
      {
        if ( count[ci - 'a'] > 0 )
        {
          count[ci - 'a']--;
          match[pos] = ci;
        }
        else if ( wild > 0 )
        {
          wild--;
          match[pos] = '.';
        }
        else finding = 0;
        if ( finding == 1 )
        {
          if ( pos < (64) - 1 )
          {
            word[pos++] = ci;
            word[pos] = '\0';
            match[pos] = '\0';
          }
          else finding = 0;
        }
      }
      else finding = 0;
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *srch; char match[-1]; char word[-1];
  int count[26]; int ci; int wild = 0; int finding = 1; int pos = 0;
  if ( argc < 2 )
    error_usage(argv[0], 1);
  for(ci = 0; ci < 26; ci++) count[ci] = 0;
  srch = argv[1];
  while(*srch != '\0')
  {
    ci = 1;
    if ( *srch >= '0' && *srch <= '9' )
    {
      ci = 0;
      while(*srch >= '0' && *srch <= '9')
        ci = ci * 10 + *(srch++) - '0';
    }
    if ( *srch >= 'a' && *srch <= 'z' ) count[*srch - 'a'] += ci;
    else if ( *srch >= 'A' && *srch <= 'Z' ) count[*srch - 'A'] += ci;
    else if ( *srch == '.' || *srch == '_' ) wild += ci;
    else error_usage(argv[0], 1);
    srch++;
  }
  match[0] = '\0';
  word[0] = '\0';
  while((ci = fgetc(stdin)) != (-1))
  {
    if ( ci & 0x80 )
      while ( (ci<<=1) & 0x80 ) fgetc(stdin);
    else if ( ci == '\n' || ci == '\r' )
    {
      if ( *word != '\0' && finding == 1 )
        fprintf(stdout, "%s\n", word);
      srch = match;
      while(*srch != '\0')
      {
        if ( *srch == '.' ) wild++;
        else count[*srch - 'a']++;
        srch++;
      }
      match[0] = '\0';
      word[0] = '\0';
      pos = 0;
      finding = 1;
    }
    else if ( finding == 1 )
    {
      if ( ci >= 'A' && ci <= 'Z' ) ci += 'a' - 'A';
      if ( ci >= 'a' && ci <= 'z' )
      {
        if ( count[ci - 'a'] > 0 )
        {
          count[ci - 'a']--;
          match[pos] = ci;
        }
        else if ( wild > 0 )
        {
          wild--;
          match[pos] = '.';
        }
        else finding = 0;
        if ( finding == 1 )
        {
          if ( pos < (64) - 1 )
          {
            word[pos++] = ci;
            word[pos] = '\0';
            match[pos] = '\0';
          }
          else finding = 0;
        }
      }
      else finding = 0;
    }
  }
  return 0;
}

variable_types:
argv
char *[]

variable_types:
srch
char *

variable_types:
match
char [-1]

variable_types:
word
char [-1]

variable_types:
count
int [26]

variable_types: ci int

variable_types: wild int

variable_types: finding int

variable_types: pos int


decompiled_code:
__int64 __fastcall r_wait(__WAIT_STATUS stat_loc)
{
unsigned int v1; // ebx

do
v1 = wait(stat_loc);
while ( v1 == -1 && *__errno_location() == 4 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__WAIT_STATUS stat_loc)
{
unsigned int v1; // ebx

do
v1 = wait(stat_loc);
while ( v1 == -1 && *__errno_location() == 4 );
return v1;
}

original_code:
pid_t r_wait (int* status_loc)
{
   int retval;
   while ( (retval = wait(status_loc) ) == -1 && ((*__errno_location ()) == 4) );
   return retval;
}

canonical_original_code:
int r_wait(int *status_loc)
{
   int retval;
   while ( (retval = wait(status_loc) ) == -1 && ((*__errno_location ()) == 4) );
   return retval;
}

variable_types: retval int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
unsigned int i; // ebx
__pid_t v6; // er12
__pid_t v7; // ebp
__pid_t v8; // eax

v3 = atoi(argv[1]);
if ( v3 <= 1 )
{
i = 1;
v6 = 0;
}
else
{
v4 = v3;
for ( i = 1; i != v4; ++i )
{
v6 = fork();
if ( v6 <= 0 )
break;
}
}
while ( (int)r_wait(0LL) > 0 )
;
v7 = getppid();
v8 = getpid();
fprintf(_bss_start, "i:%d process ID:%ld parent ID: %ld child ID %ld\n", i, v8, v7, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
unsigned int i; // ebx
__pid_t v6; // er12
__pid_t v7; // ebp
__pid_t v8; // eax

v3 = atoi(argv[1]);
if ( v3 <= 1 )
{
i = 1;
v6 = 0;
}
else
{
v4 = v3;
for ( i = 1; i != v4; ++i )
{
v6 = fork();
if ( v6 <= 0 )
break;
}
}
while ( (int)func7(0LL) > 0 )
;
v7 = getppid();
v8 = getpid();
fprintf(_bss_start, "i:%d process ID:%ld parent ID: %ld child ID %ld\n", i, v8, v7, v6);
return 0;
}

original_code:
int main(int argc, char *argv[ ] )
{
   pid_t childpid = 0;
   int i, n;
   n = atoi ( argv[1] );
   for ( i = 1; i < n; i++)
        if ((childpid = fork( )) <= 0 )
             break;
   while (r_wait(((void *)0)) > 0);
   fprintf(stderr, "i:%d process ID:%ld  parent ID: %ld child ID %ld\n",
        i, (long)getpid( ), (long)getppid( ), (long)childpid );
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int childpid = 0;
   int i; int n;
   n = atoi ( argv[1] );
   for ( i = 1; i < n; i++)
        if ((childpid = fork( )) <= 0 )
             break;
   while (r_wait(((void *)0)) > 0);
   fprintf(stderr, "i:%d process ID:%ld  parent ID: %ld child ID %ld\n",
        i, (long)getpid( ), (long)getppid( ), (long)childpid );
   return 0;
}

variable_types: childpid int

variable_types: i int

variable_types: n int


isPrime

decompiled_code:
__int64 __fastcall isPrime(int a1)
{
__int64 result; // rax
int v2; // ecx

result = 0LL;
if ( a1 > 1 )
{
if ( a1 <= 3 )
{
result = 1LL;
}
else
{
v2 = 2;
while ( 1 )
{
result = (unsigned int)(a1 % v2);
if ( !(a1 % v2) )
break;
v2 += (v2 != 2) + 1;
if ( v2 * v2 > a1 )
return 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax
int v2; // ecx

result = 0LL;
if ( a1 > 1 )
{
if ( a1 <= 3 )
{
result = 1LL;
}
else
{
v2 = 2;
while ( 1 )
{
result = (unsigned int)(a1 % v2);
if ( !(a1 % v2) )
break;
v2 += (v2 != 2) + 1;
if ( v2 * v2 > a1 )
return 1LL;
}
}
}
return result;
}

original_code:
int isPrime(int number) {
 int i, result = (1);
 if ( number < 2 ) result = (0);
 else
  for ( i = 2; result == (1) && i * i <= number; i += (i == 2) ? 1 : 2 )
   if ( number % i == 0 ) result = (0);
 return result;
}

canonical_original_code:
int isPrime(int number) {
 int i; int result = (1);
 if ( number < 2 ) result = (0);
 else
  for ( i = 2; result == (1) && i * i <= number; i += (i == 2) ? 1 : 2 )
   if ( number % i == 0 ) result = (0);
 return result;
}

variable_types: number int

variable_types: result int


printIsPrime

decompiled_code:
size_t __fastcall printIsPrime(unsigned int a1)
{
fprintf(stdout, "%d is ", a1);
if ( !(unsigned int)isPrime(a1) )
fwrite("not ", 1uLL, 4uLL, stdout);
return fwrite("prime\n", 1uLL, 6uLL, stdout);
}

canonical_decompiled_code:
size_t __fastcall func8(unsigned int a1)
{
fprintf(stdout, "%d is ", a1);
if ( !(unsigned int)func7(a1) )
fwrite("not ", 1uLL, 4uLL, stdout);
return fwrite("prime\n", 1uLL, 6uLL, stdout);
}

original_code:
void printIsPrime(int number) {
 fprintf(stdout, "%d is ", number);
 if ( isPrime(number) == (0) ) fprintf(stdout, "not ");
 fprintf(stdout, "prime\n");
}


isPrimeConsumer

decompiled_code:
void *__fastcall isPrimeConsumer(void *a1)
{
int v1; // ebp
int v2; // er12
int v3; // eax
unsigned int v4; // er13

v1 = 0;
v2 = 0;
while ( 1 )
{
while ( !*((_DWORD *)a1 + 21) )
{
v3 = *((_DWORD *)a1 + 20);
if ( v3 > 0 )
goto LABEL_5;
}
v3 = *((_DWORD *)a1 + 20);
if ( v3 <= 0 )
return 0LL;
LABEL_5:
v4 = *((_DWORD *)a1 + v1);
v1 = (v1 + 1) % 20;
*((_DWORD *)a1 + 20) = v3 - 1;
fprintf(stdout, "%d :", (unsigned int)++v2);
printIsPrime(v4);
}
}

original_code:
void *isPrimeConsumer(void *ptr) {
 int count = 0, number, next_out = 0;
 struct primecheck_data *data = (struct primecheck_data *)ptr;
 while(data->done == (0) || data->count > 0) {
  if ( data->count > 0 ) {
   number = data->buffer[next_out];
   next_out = (next_out + 1) % (20);
   data->count--;
   fprintf(stdout, "%d :", ++count);
   printIsPrime(number);
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *isPrimeConsumer(void *ptr) {
 int count = 0; int number; int next_out = 0;
 struct primecheck_data *data = (struct primecheck_data *)ptr;
 while(data->done == (0) || data->count > 0) {
  if ( data->count > 0 ) {
   number = data->buffer[next_out];
   next_out = (next_out + 1) % (20);
   data->count--;
   fprintf(stdout, "%d :", ++count);
   printIsPrime(number);
  }
 }
 return ((void *)0);
}

variable_types:
ptr
void *

variable_types: count int

variable_types: struct primecheck_data { int buffer[-1]; int count; int done; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
_DWORD *v4; // rbp
int v5; // er12
int v6; // ebx
int v7; // eax
int v9; // [rsp+4h] [rbp-24h]
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = malloc(0x58uLL);
if ( v3 )
{
v4 = v3;
v3[20] = 0;
v3[21] = 0;
v5 = pthread_create(newthread, 0LL, isPrimeConsumer, v3);
v6 = v5;
if ( v5 )
{
fwrite("Failure to create consumer thread\n", 1uLL, 0x22uLL, stderr);
v5 = 1;
}
else
{
while ( (unsigned int)__isoc99_fscanf() == 1 )
{
v7 = v4[20];
while ( v7 == 20 )
;
v4[v6] = v9;
v6 = (v6 + 1) % 20;
v4[20] = v7 + 1;
}
v4[21] = 1;
pthread_join(newthread[0], 0LL);
free(v4);
}
}
else
{
perror("Unable to allocate shared data structure");
v5 = 1;
}
return v5;
}

original_code:
int main() {
 pthread_t consumer;
 int number, next_in = 0;
 struct primecheck_data *data = malloc(sizeof(struct primecheck_data));
 if ( data == ((void *)0) ) {
  perror("Unable to allocate shared data structure");
  return(1);
 }
 data->count = 0;
 data->done = (0);
 if ( pthread_create(&consumer, ((void *)0), isPrimeConsumer, data) != 0 ) {
  fprintf(stderr, "Failure to create consumer thread\n");
  return(1);
 }
 while ( fscanf(stdin, "%d", &number) == 1 ) {
  while ( data->count == (20) );
  data->buffer[next_in] = number;
  next_in = (next_in + 1) % (20);
  data->count++;
 }
 data->done = (1);
 pthread_join(consumer, ((void *)0));
 free(data);
 return 0;
}

canonical_original_code:
int main() {
 unsigned long consumer;
 int number; int next_in = 0;
 struct primecheck_data *data = malloc(sizeof(struct primecheck_data));
 if ( data == ((void *)0) ) {
  perror("Unable to allocate shared data structure");
  return(1);
 }
 data->count = 0;
 data->done = (0);
 if ( pthread_create(&consumer, ((void *)0), isPrimeConsumer, data) != 0 ) {
  fprintf(stderr, "Failure to create consumer thread\n");
  return(1);
 }
 while ( fscanf(stdin, "%d", &number) == 1 ) {
  while ( data->count == (20) );
  data->buffer[next_in] = number;
  next_in = (next_in + 1) % (20);
  data->count++;
 }
 data->done = (1);
 pthread_join(consumer, ((void *)0));
 free(data);
 return 0;
}

variable_types:
consumer
unsigned long

user_defined_types: struct primecheck_data { int buffer[-1]; int count; int done; }


decompiled_code:
size_t p1sig()
{
return fwrite("Ping...\n", 1uLL, 8uLL, stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite("Ping...\n", 1uLL, 8uLL, stderr);
}

original_code:
void p1sig(int signo)
{
 fprintf(stderr, "Ping...\n");
}

variable_types: signo int


decompiled_code:
size_t p2sig()
{
return fwrite("Pong...\n", 1uLL, 8uLL, stderr);
}

canonical_decompiled_code:
size_t func8()
{
return fwrite("Pong...\n", 1uLL, 8uLL, stderr);
}

original_code:
void p2sig(int signo)
{
 fprintf(stderr, "Pong...\n");
}


parent

decompiled_code:
void __fastcall __noreturn parent(__pid_t pid)
{
sigset_t v1; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v2; // [rsp+80h] [rbp-A8h] BYREF

v2.sa_handler = (__sighandler_t)p1sig;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
while ( 1 )
{
sigfillset(&v1);
sigdelset(&v1, 10);
sigdelset(&v1, 2);
sigsuspend(&v1);
sleep(1u);
kill(pid, 10);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(__pid_t pid)
{
sigset_t v1; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v2; // [rsp+80h] [rbp-A8h] BYREF

v2.sa_handler = (__sighandler_t)p1sig;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
while ( 1 )
{
sigfillset(&v1);
sigdelset(&v1, 10);
sigdelset(&v1, 2);
sigsuspend(&v1);
sleep(1u);
kill(pid, 10);
}
}

original_code:
void parent(int childpid)
{
 struct sigaction sa;
 sigset_t sigmask;
 sa.__sigaction_handler.sa_handler = p1sig;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = 0;
 sigaction(10, &sa, ((void *)0));
 while(1)
 {
  sigfillset(&sigmask);
  sigdelset(&sigmask,10);
  sigdelset(&sigmask,2);
  sigsuspend(&sigmask);
  sleep(1);
  kill(childpid, 10);
 }
}

canonical_original_code:
void parent(int childpid)
{
 struct sigaction sa;
 struct __sigset_t sigmask;
 sa.__sigaction_handler.sa_handler = p1sig;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = 0;
 sigaction(10, &sa, ((void *)0));
 while(1)
 {
  sigfillset(&sigmask);
  sigdelset(&sigmask,10);
  sigdelset(&sigmask,2);
  sigsuspend(&sigmask);
  sleep(1);
  kill(childpid, 10);
 }
}

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

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


child

decompiled_code:
void __noreturn child()
{
__pid_t v0; // eax
sigset_t v1; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v2; // [rsp+80h] [rbp-A8h] BYREF

v2.sa_handler = (__sighandler_t)p2sig;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
while ( 1 )
{
sleep(1u);
v0 = getppid();
kill(v0, 10);
sigfillset(&v1);
sigdelset(&v1, 10);
sigdelset(&v1, 2);
sigsuspend(&v1);
}
}

canonical_decompiled_code:
void __noreturn func10()
{
__pid_t v0; // eax
sigset_t v1; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v2; // [rsp+80h] [rbp-A8h] BYREF

v2.sa_handler = (__sighandler_t)p2sig;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
sigaction(10, &v2, 0LL);
while ( 1 )
{
sleep(1u);
v0 = getppid();
kill(v0, 10);
sigfillset(&v1);
sigdelset(&v1, 10);
sigdelset(&v1, 2);
sigsuspend(&v1);
}
}

original_code:
void child()
{
 struct sigaction sa;
 sigset_t sigmask;
 sa.__sigaction_handler.sa_handler = p2sig;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = 0;
 sigaction(10, &sa, ((void *)0));
 while(1)
 {
  sleep(1);
  kill(getppid(), 10);
  sigfillset(&sigmask);
  sigdelset(&sigmask,10);
  sigdelset(&sigmask,2);
  sigsuspend(&sigmask);
 }
}

canonical_original_code:
void child()
{
 struct sigaction sa;
 struct __sigset_t sigmask;
 sa.__sigaction_handler.sa_handler = p2sig;
 sigemptyset(&sa.sa_mask);
 sa.sa_flags = 0;
 sigaction(10, &sa, ((void *)0));
 while(1)
 {
  sleep(1);
  kill(getppid(), 10);
  sigfillset(&sigmask);
  sigdelset(&sigmask,10);
  sigdelset(&sigmask,2);
  sigsuspend(&sigmask);
 }
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax

v3 = fork();
if ( !v3 )
child(argc, argv);
parent(v3);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax

v3 = fork();
if ( !v3 )
func10(argc, argv);
func9(v3);
}

original_code:
int main()
{
 int childpid = fork();
 if ( childpid == 0 )
 {
  child();
 }
 else
 {
  parent(childpid);
 }
 return 0;
}


producer

decompiled_code:
void __fastcall __noreturn producer(void *a1)
{
int i; // ecx

for ( i = 1; ; ++i )
{
while ( counter == 20 )
;
*(_DWORD *)(buffer + 4LL * in) = i;
in = (in + 1) % 20;
++counter;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int i; // ecx

for ( i = 1; ; ++i )
{
while ( counter == 20 )
;
*(_DWORD *)(buffer + 4LL * in) = i;
in = (in + 1) % 20;
++counter;
}
}

original_code:
void *producer(void *ptr) {
 int value = 1;
 while(1) {
  while(counter == (20))
   ;
  buffer[in] = value++;
  in = (in + 1) % (20);
  counter++;
 }
}

variable_types: value int


consumer

decompiled_code:
__int64 consumer()
{
unsigned int v0; // esi
unsigned int v1; // ecx
__int64 result; // rax

v0 = 0;
do
{
while ( !counter )
;
++v0;
v1 = *(_DWORD *)(buffer + 4LL * out);
if ( v1 != v0 )
{
printf("Error at value %d! I was expecting %d\n", v1, v0);
exit(-1);
}
out = (out + 1) % 20;
result = (unsigned int)--counter;
}
while ( v0 != 0x10000 );
return result;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // esi
unsigned int v1; // ecx
__int64 result; // rax

v0 = 0;
do
{
while ( !counter )
;
++v0;
v1 = *(_DWORD *)(buffer + 4LL * out);
if ( v1 != v0 )
{
printf("Error at value %d! I was expecting %d\n", v1, v0);
exit(-1);
}
out = (out + 1) % 20;
result = (unsigned int)--counter;
}
while ( v0 != 0x10000 );
return result;
}

original_code:
void consumer() {
 int last = 0;
 while(last < 65536) {
  while(counter == 0)
   ;
  last++;
  if ( last != buffer[out] ) {
   printf("Error at value %d! I was expecting %d\n", buffer[out], last);
   exit(-1);
  }
  out = (out + 1) % (20);
  counter--;
 }
}

variable_types: last int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

buffer = (__int64)malloc(0x50uLL);
counter = 0;
in = 0;
out = 0;
pthread_create(newthread, 0LL, (void *(*)(void *))producer, 0LL);
consumer();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

buffer = (__int64)malloc(0x50uLL);
counter = 0;
in = 0;
out = 0;
pthread_create(newthread, 0LL, (void *(*)(void *))producer, 0LL);
func8();
return 0;
}

original_code:
int main() {
 pthread_t child;
 buffer = malloc(sizeof(int) * (20));
 counter = 0;
 in = 0;
 out = 0;
 pthread_create(&child, ((void *)0), producer, ((void *)0));
 consumer();
 return 0;
}

canonical_original_code:
int main() {
 unsigned long child;
 buffer = malloc(sizeof(int) * (20));
 counter = 0;
 in = 0;
 out = 0;
 pthread_create(&child, ((void *)0), producer, ((void *)0));
 consumer();
 return 0;
}

variable_types:
child
unsigned long


decompiled_code:
int __fastcall mutex_lock(pthread_mutex_t *a1)
{
int result; // eax

result = pthread_mutex_lock(a1);
if ( result )
{
fwrite("Failed to lock mutex\n", 1uLL, 0x15uLL, _bss_start);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(pthread_mutex_t *a1)
{
int result; // eax

result = pthread_mutex_lock(a1);
if ( result )
{
fwrite("Failed to lock mutex\n", 1uLL, 0x15uLL, _bss_start);
exit(-1);
}
return result;
}

original_code:
void mutex_lock(pthread_mutex_t *lock) {
  int ret = pthread_mutex_lock(lock);
  if(ret != 0) {
    fprintf(stderr, "Failed to lock mutex\n");
    exit(-1);
  }
}

canonical_original_code:
void mutex_lock(union pthread_mutex_t *lock) {
  int ret = pthread_mutex_lock(lock);
  if(ret != 0) {
    fprintf(stderr, "Failed to lock mutex\n");
    exit(-1);
  }
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

variable_types: ret int

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall mutex_unlock(pthread_mutex_t *a1)
{
int result; // eax

result = pthread_mutex_unlock(a1);
if ( result )
{
fwrite("Failed to unlock mutex\n", 1uLL, 0x17uLL, _bss_start);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(pthread_mutex_t *a1)
{
int result; // eax

result = pthread_mutex_unlock(a1);
if ( result )
{
fwrite("Failed to unlock mutex\n", 1uLL, 0x17uLL, _bss_start);
exit(-1);
}
return result;
}

original_code:
void mutex_unlock(pthread_mutex_t *lock) {
  int ret = pthread_mutex_unlock(lock);
  if(ret != 0) {
    fprintf(stderr, "Failed to unlock mutex\n");
    exit(-1);
  }
}

canonical_original_code:
void mutex_unlock(union pthread_mutex_t *lock) {
  int ret = pthread_mutex_unlock(lock);
  if(ret != 0) {
    fprintf(stderr, "Failed to unlock mutex\n");
    exit(-1);
  }
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
void *__fastcall inc_thread_func(void *a1)
{
int v1; // ebx

v1 = 1000000;
do
{
mutex_lock(&lock_var);
++*(_DWORD *)a1;
mutex_unlock(&lock_var);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
int v1; // ebx

v1 = 1000000;
do
{
func7(&lock_var);
++*(_DWORD *)a1;
func8(&lock_var);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *inc_thread_func(void *p) {
  int *num = (int *)p;
  int i, tid = 0;
  for(i = 0; i < (1000000); i++) {
    mutex_lock(&lock_var);
    (*num)++;
    mutex_unlock(&lock_var);
  }
  return ((void *)0);
}

canonical_original_code:
void *inc_thread_func(void *p) {
  int *num = (int *)p;
  int i; int tid = 0;
  for(i = 0; i < (1000000); i++) {
    mutex_lock(&lock_var);
    (*num)++;
    mutex_unlock(&lock_var);
  }
  return ((void *)0);
}

variable_types:
p
void *

variable_types:
num
int *

variable_types: tid int


decompiled_code:
void *__fastcall dec_thread_func(void *a1)
{
int v1; // ebx

v1 = 1000000;
do
{
mutex_lock(&lock_var);
--*(_DWORD *)a1;
mutex_unlock(&lock_var);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int v1; // ebx

v1 = 1000000;
do
{
func7(&lock_var);
--*(_DWORD *)a1;
func8(&lock_var);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *dec_thread_func(void *p) {
  int *num = (int *)p;
  int i, tid = 1;
  for(i = 0; i < (1000000); i++) {
    mutex_lock(&lock_var);
    (*num)--;
    mutex_unlock(&lock_var);
  }
  return ((void *)0);
}

canonical_original_code:
void *dec_thread_func(void *p) {
  int *num = (int *)p;
  int i; int tid = 1;
  for(i = 0; i < (1000000); i++) {
    mutex_lock(&lock_var);
    (*num)--;
    mutex_unlock(&lock_var);
  }
  return ((void *)0);
}

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int arg; // [rsp+Ch] [rbp-1Ch] BYREF
pthread_t th; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

arg = 0;
if ( pthread_create(newthread, 0LL, inc_thread_func, &arg) )
{
fwrite("Unable to create increment thread\n", 1uLL, 0x22uLL, _bss_start);
v3 = -1;
}
else if ( pthread_create(&th, 0LL, dec_thread_func, &arg) )
{
fwrite("Unable to create decrement thread\n", 1uLL, 0x22uLL, _bss_start);
v3 = -1;
}
else if ( pthread_join(newthread[0], 0LL) )
{
fwrite("Unable to join increment thread\n", 1uLL, 0x20uLL, _bss_start);
v3 = -1;
}
else
{
v3 = pthread_join(th, 0LL);
if ( v3 )
{
fwrite("Unable to join decrement thread\n", 1uLL, 0x20uLL, _bss_start);
v3 = -1;
}
else
{
printf("Final result: %d\n", arg);
}
}
return v3;
}

original_code:
int main(int argc, char *argv[]) {
  pthread_t ith, dth;
  int ret, num = 0;
  ret = pthread_create(&ith, ((void *)0), inc_thread_func, &num);
  if(ret != 0) {
    fprintf(stderr, "Unable to create increment thread\n");
    return -1;
  }
  ret = pthread_create(&dth, ((void *)0), dec_thread_func, &num);
  if(ret != 0) {
    fprintf(stderr, "Unable to create decrement thread\n");
    return -1;
  }
  ret = pthread_join(ith, ((void *)0));
  if(ret != 0) {
    fprintf(stderr, "Unable to join increment thread\n");
    return -1;
  }
  ret = pthread_join(dth, ((void *)0));
  if(ret != 0) {
    fprintf(stderr, "Unable to join decrement thread\n");
    return -1;
  }
  printf("Final result: %d\n", num);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  unsigned long ith; unsigned long dth;
  int ret; int num = 0;
  ret = pthread_create(&ith, ((void *)0), inc_thread_func, &num);
  if(ret != 0) {
    fprintf(stderr, "Unable to create increment thread\n");
    return -1;
  }
  ret = pthread_create(&dth, ((void *)0), dec_thread_func, &num);
  if(ret != 0) {
    fprintf(stderr, "Unable to create decrement thread\n");
    return -1;
  }
  ret = pthread_join(ith, ((void *)0));
  if(ret != 0) {
    fprintf(stderr, "Unable to join increment thread\n");
    return -1;
  }
  ret = pthread_join(dth, ((void *)0));
  if(ret != 0) {
    fprintf(stderr, "Unable to join decrement thread\n");
    return -1;
  }
  printf("Final result: %d\n", num);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ith
unsigned long

variable_types:
dth
unsigned long

variable_types: num int


decompiled_code:
void *__fastcall add_thread_func(void *a1)
{
int v1; // ebx

v1 = 0xFFFF;
do
{
pthread_mutex_lock((pthread_mutex_t *)a1);
++count;
pthread_mutex_unlock((pthread_mutex_t *)a1);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebx

v1 = 0xFFFF;
do
{
pthread_mutex_lock((pthread_mutex_t *)a1);
++count;
pthread_mutex_unlock((pthread_mutex_t *)a1);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *add_thread_func(void *p) {
 pthread_mutex_t *pmutex = (pthread_mutex_t *)p;
 int i;
 for(i = 0; i < (0xFFFF); i++) {
  pthread_mutex_lock(pmutex);
  count++;
  pthread_mutex_unlock(pmutex);
 }
 return ((void *)0);
}

canonical_original_code:
void *add_thread_func(void *p) {
 union pthread_mutex_t *pmutex = (pthread_mutex_t *)p;
 int i;
 for(i = 0; i < (0xFFFF); i++) {
  pthread_mutex_lock(pmutex);
  count++;
  pthread_mutex_unlock(pmutex);
 }
 return ((void *)0);
}


decompiled_code:
void *__fastcall sub_thread_func(void *a1)
{
int v1; // ebx

v1 = 0xFFFF;
do
{
pthread_mutex_lock((pthread_mutex_t *)a1);
--count;
pthread_mutex_unlock((pthread_mutex_t *)a1);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebx

v1 = 0xFFFF;
do
{
pthread_mutex_lock((pthread_mutex_t *)a1);
--count;
pthread_mutex_unlock((pthread_mutex_t *)a1);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *sub_thread_func(void *p) {
 pthread_mutex_t *pmutex = (pthread_mutex_t *)p;
 int i;
 for(i = 0; i < (0xFFFF); i++) {
  pthread_mutex_lock(pmutex);
  count--;
  pthread_mutex_unlock(pmutex);
 }
 return ((void *)0);
}

canonical_original_code:
void *sub_thread_func(void *p) {
 union pthread_mutex_t *pmutex = (pthread_mutex_t *)p;
 int i;
 for(i = 0; i < (0xFFFF); i++) {
  pthread_mutex_lock(pmutex);
  count--;
  pthread_mutex_unlock(pmutex);
 }
 return ((void *)0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
pthread_t *v4; // rbp
__int64 i; // rbx
__int64 v7[6]; // [rsp+0h] [rbp-188h] BYREF
pthread_t th[20]; // [rsp+30h] [rbp-158h] BYREF
pthread_t newthread[20]; // [rsp+D0h] [rbp-B8h] BYREF
char v10; // [rsp+170h] [rbp-18h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
puts("Main thread started");
v3 = newthread;
v4 = th;
do
{
pthread_create(v3, 0LL, add_thread_func, v7);
pthread_create(v4, 0LL, sub_thread_func, v7);
++v3;
++v4;
}
while ( v3 != (pthread_t *)&v10 );
puts("Main thread created child threads");
for ( i = 0LL; i != 20; ++i )
{
pthread_join(newthread[i], 0LL);
pthread_join(th[i], 0LL);
}
printf("Main thread count is %d\n", (unsigned int)count);
return 0;
}

original_code:
int main() {
 pthread_t add_threads[(20)];
 pthread_t sub_threads[(20)];
 int i;
 pthread_mutex_t count_mutex = { { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
 printf("Main thread started\n");
 for ( i = 0; i < (20); i++ ) {
  pthread_create(&add_threads[i], ((void *)0), add_thread_func, &count_mutex);
  pthread_create(&sub_threads[i], ((void *)0), sub_thread_func, &count_mutex);
 }
 printf("Main thread created child threads\n");
 for ( i = 0; i < (20); i++ ) {
  pthread_join(add_threads[i], ((void *)0));
  pthread_join(sub_threads[i], ((void *)0));
 }
 printf("Main thread count is %d\n", count);
 return 0;
}

canonical_original_code:
int main() {
 unsigned long add_threads[-1];
 unsigned long sub_threads[-1];
 int i;
 union pthread_mutex_t count_mutex = { { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
 printf("Main thread started\n");
 for ( i = 0; i < (20); i++ ) {
  pthread_create(&add_threads[i], ((void *)0), add_thread_func, &count_mutex);
  pthread_create(&sub_threads[i], ((void *)0), sub_thread_func, &count_mutex);
 }
 printf("Main thread created child threads\n");
 for ( i = 0; i < (20); i++ ) {
  pthread_join(add_threads[i], ((void *)0));
  pthread_join(sub_threads[i], ((void *)0));
 }
 printf("Main thread count is %d\n", count);
 return 0;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; }


decompiled_code:
__int64 see_more()
{
int v0; // eax

printf("more?");
while ( 1 )
{
v0 = getchar();
if ( v0 == 113 || v0 == -1 )
return 0LL;
if ( v0 == 32 )
break;
if ( v0 == 10 )
return 1LL;
}
return 24LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax

printf("more?");
while ( 1 )
{
v0 = getchar();
if ( v0 == 113 || v0 == -1 )
return 0LL;
if ( v0 == 32 )
break;
if ( v0 == 10 )
return 1LL;
}
return 24LL;
}

original_code:
int see_more()
{
 int c;
 printf("more?");
 while((c = getchar()) != (-1))
 {
  if (c == 'q')
   return 0;
  if (c == ' ')
   return 24;
  if (c == '\n')
   return 1;
 }
 return 0;
}

variable_types: c int


decompiled_code:
int __fastcall factor1(int a1)
{
int v1; // ebp
int v2; // ebx

v1 = a1;
printf("%d:", (unsigned int)a1);
if ( a1 > 3 )
{
v2 = 2;
while ( v1 % v2 )
{
if ( v2 != 2 )
{
v2 += 2;
if ( v2 > 7 )
{
while ( v2 == 3 * (v2 / 3) || v2 == 5 * (v2 / 5) || v2 == 7 * (v2 / 7) )
{
v2 += 2;
if ( v2 <= 7 )
goto LABEL_5;
}
}
LABEL_4:
if ( v2 > 0xFFFF )
return printf(" %d\n", (unsigned int)v1);
goto LABEL_5;
}
v2 = 3;
LABEL_5:
if ( v2 * v2 > v1 )
return printf(" %d\n", (unsigned int)v1);
}
printf(" %d", (unsigned int)v2);
v1 /= v2;
goto LABEL_4;
}
return printf(" %d\n", (unsigned int)v1);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
int v1; // ebp
int v2; // ebx

v1 = a1;
printf("%d:", (unsigned int)a1);
if ( a1 > 3 )
{
v2 = 2;
while ( v1 % v2 )
{
if ( v2 != 2 )
{
v2 += 2;
if ( v2 > 7 )
{
while ( v2 == 3 * (v2 / 3) || v2 == 5 * (v2 / 5) || v2 == 7 * (v2 / 7) )
{
v2 += 2;
if ( v2 <= 7 )
goto LABEL_5;
}
}
LABEL_4:
if ( v2 > 0xFFFF )
return printf(" %d\n", (unsigned int)v1);
goto LABEL_5;
}
v2 = 3;
LABEL_5:
if ( v2 * v2 > v1 )
return printf(" %d\n", (unsigned int)v1);
}
printf(" %d", (unsigned int)v2);
v1 /= v2;
goto LABEL_4;
}
return printf(" %d\n", (unsigned int)v1);
}

variable_types: n int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi

if ( argc <= 1 || (v3 = atoi(argv[1]), v3 <= 1) )
{
printf("Usage: %s <positive integer>\n", *argv);
exit(-1);
}
factor1(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi

if ( argc <= 1 || (v3 = atoi(argv[1]), v3 <= 1) )
{
printf("Usage: %s <positive integer>\n", *argv);
exit(-1);
}
func7(v3);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int n;
 if (argc < 2 || (n = atoi(argv[1])) < 2) {
  printf("Usage: %s <positive integer>\n", argv[0]);
  exit(-1);
 }
 factor1(n);
 return 0;
}


decompiled_code:
void __fastcall __noreturn pthread_ret_error(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(-1);
}

original_code:
void pthread_ret_error(const char *msg) {
  fprintf(stderr, "%s\n", msg);
  exit(-1);
}

canonical_original_code:
void pthread_ret_error(char *msg) {
  fprintf(stderr, "%s\n", msg);
  exit(-1);
}

variable_types:
msg
char *


original_code:
void *producer_thread_func(void *p) {
  struct pc_buff *pcb = (struct pc_buff *)p;
  int i, pi = 0;
  for(i = 0; i < (1000000); i++) {
    sem_wait(&pcb->empty);
    pcb->buffer[pi] = 1;
    pi = (pi + 1) % (20);
    sem_post(&pcb->items);
  }
  sem_wait(&pcb->empty);
  pcb->buffer[pi] = (-1);
  pi = (pi + 1) % (20);
  sem_post(&pcb->items);
  return ((void *)0);
}

canonical_original_code:
void *producer_thread_func(void *p) {
  struct pc_buff *pcb = (struct pc_buff *)p;
  int i; int pi = 0;
  for(i = 0; i < (1000000); i++) {
    sem_wait(&pcb->empty);
    pcb->buffer[pi] = 1;
    pi = (pi + 1) % (20);
    sem_post(&pcb->items);
  }
  sem_wait(&pcb->empty);
  pcb->buffer[pi] = (-1);
  pi = (pi + 1) % (20);
  sem_post(&pcb->items);
  return ((void *)0);
}

variable_types: struct pc_buff { int buffer[-1]; union sem_t { char __size[32]; long __align; } items; } *

variable_types: pi int

user_defined_types: struct pc_buff { int buffer[-1]; union sem_t items; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
void *thread_return; // [rsp+8h] [rbp-20h] BYREF
pthread_t th; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

v3 = (char *)malloc(0x90uLL);
sem_init((sem_t *)(v3 + 80), 0, 0);
sem_init((sem_t *)(v3 + 112), 0, 0x14u);
if ( pthread_create(newthread, 0LL, producer_thread_func, v3) )
pthread_ret_error("Unable to create producer thread");
if ( pthread_create(&th, 0LL, (void *(*)(void *))consumer_thread_func, v3) )
pthread_ret_error("Unable to create consumer thread");
if ( pthread_join(newthread[0], 0LL) )
pthread_ret_error("Unable to join producer thread");
if ( pthread_join(th, &thread_return) )
pthread_ret_error("Unable to join consumer thread");
printf("Sum result: %d\n", *(unsigned int *)thread_return);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
void *thread_return; // [rsp+8h] [rbp-20h] BYREF
pthread_t th; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

v3 = (char *)malloc(0x90uLL);
sem_init((sem_t *)(v3 + 80), 0, 0);
sem_init((sem_t *)(v3 + 112), 0, 0x14u);
if ( pthread_create(newthread, 0LL, producer_thread_func, v3) )
func8("Unable to create producer thread");
if ( pthread_create(&th, 0LL, (void *(*)(void *))consumer_thread_func, v3) )
func8("Unable to create consumer thread");
if ( pthread_join(newthread[0], 0LL) )
func8("Unable to join producer thread");
if ( pthread_join(th, &thread_return) )
func8("Unable to join consumer thread");
printf("Sum result: %d\n", *(unsigned int *)thread_return);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  pthread_t pth, cth;
  int sum, ret, i;
  void *result;
  struct pc_buff *pcb = malloc(sizeof(struct pc_buff));
  sem_init(&pcb->items, 0, 0);
  sem_init(&pcb->empty, 0, (20));
  ret = pthread_create(&pth, ((void *)0), producer_thread_func, pcb);
  if(ret != 0) pthread_ret_error("Unable to create producer thread");
  ret = pthread_create(&cth, ((void *)0), consumer_thread_func, pcb);
  if(ret != 0) pthread_ret_error("Unable to create consumer thread");
  ret = pthread_join(pth, ((void *)0));
  if(ret != 0) pthread_ret_error("Unable to join producer thread");
  sum = 0;
  ret = pthread_join(cth, &result);
  if(ret != 0) pthread_ret_error("Unable to join consumer thread");
  sum += *(int *)result;
  printf("Sum result: %d\n", sum);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  unsigned long pth; unsigned long cth;
  int sum; int ret; int i;
  void *result;
  struct pc_buff *pcb = malloc(sizeof(struct pc_buff));
  sem_init(&pcb->items, 0, 0);
  sem_init(&pcb->empty, 0, (20));
  ret = pthread_create(&pth, ((void *)0), producer_thread_func, pcb);
  if(ret != 0) pthread_ret_error("Unable to create producer thread");
  ret = pthread_create(&cth, ((void *)0), consumer_thread_func, pcb);
  if(ret != 0) pthread_ret_error("Unable to create consumer thread");
  ret = pthread_join(pth, ((void *)0));
  if(ret != 0) pthread_ret_error("Unable to join producer thread");
  sum = 0;
  ret = pthread_join(cth, &result);
  if(ret != 0) pthread_ret_error("Unable to join consumer thread");
  sum += *(int *)result;
  printf("Sum result: %d\n", sum);
  return 0;
}

variable_types:
pth
unsigned long

variable_types:
cth
unsigned long

variable_types: sum int

variable_types:
result
void *

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
void *__fastcall funny_add(void *a1)
{
int v1; // ebp
int v2; // ebx

v1 = 10;
do
{
v2 = globalValue + 1;
sleep(1u);
globalValue = v2;
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebp
int v2; // ebx

v1 = 10;
do
{
v2 = globalValue + 1;
sleep(1u);
globalValue = v2;
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *funny_add(void * m)
{
 int j;
 for ( j = 0; j < 10; j++ )
 {
  int temp = globalValue + 1;
  sleep(1);
  globalValue = temp;
 }
 return ((void *)0);
}

canonical_original_code:
void *funny_add(void *m)
{
 int j;
 for ( j = 0; j < 10; j++ )
 {
  int temp = globalValue + 1;
  sleep(1);
  globalValue = temp;
 }
 return ((void *)0);
}

variable_types:
m
void *

variable_types: j int

variable_types: temp int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, funny_add, 0LL);
v3 = 10;
do
{
++globalValue;
sleep(1u);
--v3;
}
while ( v3 );
pthread_join(newthread[0], 0LL);
printf("\nDone ...global value = %d\n", (unsigned int)globalValue);
return 0;
}

original_code:
int main()
{
 int i;
 pthread_t mythread;
 pthread_create(&mythread, ((void *)0), funny_add, ((void *)0));
 for ( i = 0; i < 10; i++ )
 {
  globalValue++;
  sleep(1);
 }
 pthread_join(mythread, ((void *)0));
 printf("\nDone ...global value = %d\n", globalValue);
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 unsigned long mythread;
 pthread_create(&mythread, ((void *)0), funny_add, ((void *)0));
 for ( i = 0; i < 10; i++ )
 {
  globalValue++;
  sleep(1);
 }
 pthread_join(mythread, ((void *)0));
 printf("\nDone ...global value = %d\n", globalValue);
 return 0;
}

variable_types: i int

variable_types:
mythread
unsigned long


decompiled_code:
void *__fastcall char_print(void *a1)
{
int v1; // ebx

if ( *((int *)a1 + 1) <= 0 )
return 0LL;
v1 = 0;
do
{
fputc(*(char *)a1, _bss_start);
++v1;
}
while ( *((_DWORD *)a1 + 1) > v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebx

if ( *((int *)a1 + 1) <= 0 )
return 0LL;
v1 = 0;
do
{
fputc(*(char *)a1, _bss_start);
++v1;
}
while ( *((_DWORD *)a1 + 1) > v1 );
return 0LL;
}

original_code:
void *char_print(void *params) {
  struct char_print_params *p;
  p = (struct char_print_params *) params;
  int i;
  for (i = 0; i < p->number_to_print; i++)
    fputc(p->print_char, stderr);
  return ((void *)0);
}

variable_types:
params
void *

variable_types: struct char_print_params { char print_char; int number_to_print; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[4]; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+4h] [rbp-24h]
char arg[4]; // [rsp+8h] [rbp-20h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch]
pthread_t th; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

arg[0] = 120;
v7 = 3000;
pthread_create(newthread, 0LL, char_print, arg);
v4[0] = 121;
v5 = 5000;
pthread_create(&th, 0LL, char_print, v4);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  pthread_t thread1_handle;
  pthread_t thread2_handle;
  struct char_print_params thread1_args;
  struct char_print_params thread2_args;
  thread1_args.print_char = 'x';
  thread1_args.number_to_print = 3000;
  pthread_create(&thread1_handle, ((void *)0), char_print, &thread1_args);
  thread2_args.print_char = 'y';
  thread2_args.number_to_print = 5000;
  pthread_create(&thread2_handle, ((void *)0), char_print, &thread2_args);
  pthread_join(thread1_handle, ((void *)0));
  pthread_join(thread2_handle, ((void *)0));
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  unsigned long thread1_handle;
  unsigned long thread2_handle;
  struct char_print_params thread1_args;
  struct char_print_params thread2_args;
  thread1_args.print_char = 'x';
  thread1_args.number_to_print = 3000;
  pthread_create(&thread1_handle, ((void *)0), char_print, &thread1_args);
  thread2_args.print_char = 'y';
  thread2_args.number_to_print = 5000;
  pthread_create(&thread2_handle, ((void *)0), char_print, &thread2_args);
  pthread_join(thread1_handle, ((void *)0));
  pthread_join(thread2_handle, ((void *)0));
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct char_print_params { char print_char; int number_to_print; }


f

decompiled_code:
void f()
{
printf("\nOUCH");
}

canonical_decompiled_code:
void func7()
{
printf("\nOUCH");
}

original_code:
void f ( int signum )
{
    printf("\nOUCH");
}

canonical_original_code:
void f(int signum)
{
    printf("\nOUCH");
}

variable_types: signum int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

signal(2, (__sighandler_t)f);
v3 = 10;
do
{
puts("hello");
sleep(1u);
--v3;
}
while ( v3 );
return 0;
}

original_code:
int main ( )
{
    int i;
    signal ( 2, f);
    for (i = 0; i < 10; i++)
    {
        printf("hello\n");
        sleep(1);
    }
    return 0;
}

canonical_original_code:
int main()
{
    int i;
    signal ( 2, f);
    for (i = 0; i < 10; i++)
    {
        printf("hello\n");
        sleep(1);
    }
    return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int arg; // [rsp+Ch] [rbp-1Ch] BYREF
void *thread_return; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

arg = 10;
if ( pthread_create(newthread, 0LL, (void *(*)(void *))child_thread_func, &arg) )
{
fwrite("Error creating child thread\n", 1uLL, 0x1CuLL, _bss_start);
v3 = -1;
}
else
{
v3 = pthread_join(newthread[0], &thread_return);
if ( v3 )
{
fwrite("Error joining child thread\n", 1uLL, 0x1BuLL, _bss_start);
v3 = -1;
}
else
{
printf("Result of %d squared is %d\n", arg, *(unsigned int *)thread_return);
free(thread_return);
}
}
return v3;
}

original_code:
int main(int argc, char *argv[]) {
  pthread_t thread_handle;
  void *result;
  int ret;
  int number = 10;
  ret = pthread_create(&thread_handle, ((void *)0), child_thread_func, &number);
  if(ret != 0) {
    fprintf(stderr, "Error creating child thread\n");
    return -1;
  }
  ret = pthread_join(thread_handle, &result);
  if(ret != 0) {
    fprintf(stderr, "Error joining child thread\n");
    return -1;
  }
  printf("Result of %d squared is %d\n", number, *(int *)result);
  free(result);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  unsigned long thread_handle;
  void *result;
  int ret;
  int number = 10;
  ret = pthread_create(&thread_handle, ((void *)0), child_thread_func, &number);
  if(ret != 0) {
    fprintf(stderr, "Error creating child thread\n");
    return -1;
  }
  ret = pthread_join(thread_handle, &result);
  if(ret != 0) {
    fprintf(stderr, "Error joining child thread\n");
    return -1;
  }
  printf("Result of %d squared is %d\n", number, *(int *)result);
  free(result);
  return 0;
}

variable_types: ret int

variable_types: number int


repo: jjonir/alchem

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned __int64 v4; // rax
unsigned int v5; // edx
__int64 v6; // rbp
unsigned __int64 v7; // rax
unsigned int v8; // edx
unsigned __int64 v9; // rax
unsigned int v10; // edx
__int64 v11; // rbp
unsigned __int64 v12; // rax
unsigned int v13; // edx
unsigned __int64 v14; // rax
unsigned int v15; // edx
__int64 v16; // rbp
unsigned __int64 v17; // rax
unsigned int v18; // edx
unsigned __int64 v19; // rax
unsigned int v20; // edx
__int64 v21; // rbp
unsigned __int64 v22; // rax
unsigned int v23; // edx

init_io(argc, argv, envp);
v3 = new_workspace(5LL, 5LL, 5LL);
v4 = position(1u, 0);
v6 = new_manipulator(0LL, 2LL, v4, v5);
inst_add(v6, 9LL);
inst_add(v6, 2LL);
inst_add(v6, 8LL);
inst_add(v6, 5LL);
v7 = position(1u, 0);
add_manipulator(v3, v6, v7, v8);
v9 = position(0, 2u);
v11 = new_manipulator(0LL, 2LL, v9, v10);
inst_add(v11, 8LL);
inst_add(v11, 7LL);
inst_add(v11, 9LL);
inst_add(v11, 6LL);
v12 = position(0, 2u);
add_manipulator(v3, v11, v12, v13);
v14 = position(3u, 0);
v16 = new_glyph(2LL, 5LL, v14, v15);
v17 = position(3u, 0);
add_glyph(v3, v16, v17, v18);
v19 = position(1u, 2u);
v21 = new_glyph(0LL, 0LL, v19, v20);
v22 = position(1u, 2u);
add_glyph(v3, v21, v22, v23);
edit_workspace_loop(v3);
end_io();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned __int64 v4; // rax
unsigned int v5; // edx
__int64 v6; // rbp
unsigned __int64 v7; // rax
unsigned int v8; // edx
unsigned __int64 v9; // rax
unsigned int v10; // edx
__int64 v11; // rbp
unsigned __int64 v12; // rax
unsigned int v13; // edx
unsigned __int64 v14; // rax
unsigned int v15; // edx
__int64 v16; // rbp
unsigned __int64 v17; // rax
unsigned int v18; // edx
unsigned __int64 v19; // rax
unsigned int v20; // edx
__int64 v21; // rbp
unsigned __int64 v22; // rax
unsigned int v23; // edx

init_io(argc, argv, envp);
v3 = new_workspace(5LL, 5LL, 5LL);
v4 = func0(1u, 0);
v6 = new_manipulator(0LL, 2LL, v4, v5);
inst_add(v6, 9LL);
inst_add(v6, 2LL);
inst_add(v6, 8LL);
inst_add(v6, 5LL);
v7 = func0(1u, 0);
add_manipulator(v3, v6, v7, v8);
v9 = func0(0, 2u);
v11 = new_manipulator(0LL, 2LL, v9, v10);
inst_add(v11, 8LL);
inst_add(v11, 7LL);
inst_add(v11, 9LL);
inst_add(v11, 6LL);
v12 = func0(0, 2u);
add_manipulator(v3, v11, v12, v13);
v14 = func0(3u, 0);
v16 = new_glyph(2LL, 5LL, v14, v15);
v17 = func0(3u, 0);
add_glyph(v3, v16, v17, v18);
v19 = func0(1u, 2u);
v21 = new_glyph(0LL, 0LL, v19, v20);
v22 = func0(1u, 2u);
add_glyph(v3, v21, v22, v23);
edit_workspace_loop(v3);
end_io();
return 0;
}

original_code:
int main() {
 struct workspace *w;
 struct manipulator *m;
 struct glyph *g;
 init_io();
 w = new_workspace(5, 5, 5);
 m = new_manipulator(PX, 2, position(1, 0, 0));
 inst_add(m, CLOSE_HEAD);
 inst_add(m, ROT_PZ);
 inst_add(m, OPEN_HEAD);
 inst_add(m, ROT_NZ);
 add_manipulator(w, m, position(1, 0, 0));
 m = new_manipulator(PX, 2, position(0, 2, 0));
 inst_add(m, OPEN_HEAD);
 inst_add(m, RETRACT);
 inst_add(m, CLOSE_HEAD);
 inst_add(m, EXTEND);
 add_manipulator(w, m, position(0, 2, 0));
 g = new_glyph(SOURCE, (int)ATOM_AL, position(3, 0, 0));
 add_glyph(w, g, position(3, 0, 0));
 g = new_glyph(BOND, (int)PX, position(1, 2, 0));
 add_glyph(w, g, position(1, 2, 0));
 edit_workspace_loop(w);
 end_io();
 return 0;
}

variable_types: struct workspace { struct position { int x; } size; struct item { enum item_type { ITEM_NONE=0, ITEM_ATOM=1, ITEM_MANIPULATOR=2, ITEM_GLYPH=3 } type; void *item; } *items; struct position pos; } *

variable_types: struct manipulator { struct position { int x; } pos; enum orientation { PX=0, NX=1, PY=2, NY=3, PZ=4, NZ=5, ORIENTATION_NUM=6 } orient; int length; enum head_state { HEAD_OPEN=0, HEAD_CLOSED=1 } head_state; int grabbed; struct list_head { struct list_head *next; } inst_list; struct inst { struct list_head list; enum op { ROT_PX=0, ROT_PY=1, ROT_PZ=2, ROT_NX=3, ROT_NY=4, ROT_NZ=5, EXTEND=6, RETRACT=7, OPEN_HEAD=8, CLOSE_HEAD=9, NOP=10 } op; } *pc; } *

variable_types: struct glyph { struct position { int x; } pos; enum glyph_op { BOND=0, UNBOND=1, SOURCE=2, TRANSMUTE=3 } op; int type; struct atom { struct list_head { struct list_head *next; } compound; int bonds[-1]; struct position pos; enum element { ATOM_NONE=0, ATOM_H=1, ATOM_HE=2, ATOM_LI=3, ATOM_BE=4, ATOM_AL=5, ATOM_C=6, ATOM_N=7, ATOM_O=8, ATOM_F=9, ATOM_AR=10, ATOM_END=11 } element; } *a; } *

user_defined_types: struct workspace { struct position size; struct item *items; struct position pos; }

user_defined_types: struct manipulator { struct position pos; enum orientation orient; int length; enum head_state head_state; int grabbed; struct list_head inst_list; struct inst *pc; }

user_defined_types: struct glyph { struct position pos; enum glyph_op op; int type; struct atom *a; }

user_defined_types: struct item { enum item_type type; void *item; }

user_defined_types: struct inst { struct list_head list; enum op op; }

user_defined_types: struct atom { struct list_head compound; int bonds[-1]; struct position pos; enum element element; }


decompiled_code:
void sim_stop()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void sim_stop(struct workspace *w)
{
}

canonical_original_code:
void sim_stop(struct workspace *w)
{
}

user_defined_types: enum item_type { ITEM_NONE=0, ITEM_ATOM=1, ITEM_MANIPULATOR=2, ITEM_GLYPH=3 }


decompiled_code:
__int64 __fastcall add_atom(__int64 a1, __int64 a2, __int64 a3, int a4)
{
return add_item(a1, a2, a3, a4, 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, int a4)
{
return func2(a1, a2, a3, a4, 1);
}

original_code:
int add_atom(struct workspace *w, struct atom *a, struct position pos)
{
 return add_item(w, (void *)a, pos, ITEM_ATOM);
}

variable_types: struct atom { struct list_head { struct list_head *next; } compound; int bonds[-1]; struct position pos; enum element { ATOM_NONE=0, ATOM_H=1, ATOM_HE=2, ATOM_LI=3, ATOM_BE=4, ATOM_AL=5, ATOM_C=6, ATOM_N=7, ATOM_O=8, ATOM_F=9, ATOM_AR=10, ATOM_END=11 } element; } *

variable_types:
pos
struct position


decompiled_code:
__int64 __fastcall add_manipulator(__int64 a1, __int64 a2, __int64 a3, int a4)
{
return add_item(a1, a2, a3, a4, 2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4)
{
return func2(a1, a2, a3, a4, 2);
}

original_code:
int add_manipulator(struct workspace *w, struct manipulator *m, struct position pos)
{
 return add_item(w, (void *)m, pos, ITEM_MANIPULATOR);
}

variable_types: struct manipulator { struct position pos; enum orientation { PX=0, NX=1, PY=2, NY=3, PZ=4, NZ=5, ORIENTATION_NUM=6 } orient; int length; enum head_state { HEAD_OPEN=0, HEAD_CLOSED=1 } head_state; int grabbed; struct list_head { struct list_head *next; } inst_list; struct inst { struct list_head list; enum op { ROT_PX=0, ROT_PY=1, ROT_PZ=2, ROT_NX=3, ROT_NY=4, ROT_NZ=5, EXTEND=6, RETRACT=7, OPEN_HEAD=8, CLOSE_HEAD=9, NOP=10 } op; } *pc; } *


decompiled_code:
__int64 __fastcall add_glyph(__int64 a1, __int64 a2, __int64 a3, int a4)
{
return add_item(a1, a2, a3, a4, 3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, int a4)
{
return func2(a1, a2, a3, a4, 3);
}

original_code:
int add_glyph(struct workspace *w, struct glyph *g, struct position pos)
{
 return add_item(w, (void *)g, pos, ITEM_GLYPH);
}

variable_types: struct glyph { struct position pos; enum glyph_op { BOND=0, UNBOND=1, SOURCE=2, TRANSMUTE=3 } op; int type; struct atom { struct list_head { struct list_head *next; } compound; int bonds[-1]; struct position pos; enum element { ATOM_NONE=0, ATOM_H=1, ATOM_HE=2, ATOM_LI=3, ATOM_BE=4, ATOM_AL=5, ATOM_C=6, ATOM_N=7, ATOM_O=8, ATOM_F=9, ATOM_AR=10, ATOM_END=11 } element; } *a; } *


decompiled_code:
__int64 __fastcall remove_atom(__int64 a1, __int64 a2, int a3)
{
return remove_item(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, int a3)
{
return func3(a1, a2, a3, 1);
}

original_code:
struct atom *remove_atom(struct workspace *w, struct position pos)
{
 return (struct atom *)remove_item(w, pos, ITEM_ATOM);
}

variable_types: struct workspace { struct position size; struct item { enum item_type { ITEM_NONE=0, ITEM_ATOM=1, ITEM_MANIPULATOR=2, ITEM_GLYPH=3 } type; void *item; } *items; struct position pos; } *

return_type: struct atom { struct list_head { struct list_head *next; } compound; int bonds[-1]; struct position { int x; } pos; enum element { ATOM_NONE=0, ATOM_H=1, ATOM_HE=2, ATOM_LI=3, ATOM_BE=4, ATOM_AL=5, ATOM_C=6, ATOM_N=7, ATOM_O=8, ATOM_F=9, ATOM_AR=10, ATOM_END=11 } element; } *


decompiled_code:
__int64 __fastcall remove_manipulator(__int64 a1, __int64 a2, int a3)
{
return remove_item(a1, a2, a3, 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3)
{
return func3(a1, a2, a3, 2);
}

original_code:
struct manipulator *remove_manipulator(struct workspace *w, struct position pos)
{
 return (struct manipulator *)remove_item(w, pos, ITEM_MANIPULATOR);
}

return_type: struct manipulator { struct position { int x; } pos; enum orientation { PX=0, NX=1, PY=2, NY=3, PZ=4, NZ=5, ORIENTATION_NUM=6 } orient; int length; enum head_state { HEAD_OPEN=0, HEAD_CLOSED=1 } head_state; int grabbed; struct list_head { struct list_head *next; } inst_list; struct inst { struct list_head list; enum op { ROT_PX=0, ROT_PY=1, ROT_PZ=2, ROT_NX=3, ROT_NY=4, ROT_NZ=5, EXTEND=6, RETRACT=7, OPEN_HEAD=8, CLOSE_HEAD=9, NOP=10 } op; } *pc; } *


decompiled_code:
__int64 __fastcall remove_glyph(__int64 a1, __int64 a2, int a3)
{
return remove_item(a1, a2, a3, 3);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
return func3(a1, a2, a3, 3);
}

original_code:
struct glyph *remove_glyph(struct workspace *w, struct position pos)
{
 return (struct glyph *)remove_item(w, pos, ITEM_GLYPH);
}

return_type: struct glyph { struct position { int x; } pos; enum glyph_op { BOND=0, UNBOND=1, SOURCE=2, TRANSMUTE=3 } op; int type; struct atom { struct list_head { struct list_head *next; } compound; int bonds[-1]; struct position pos; enum element { ATOM_NONE=0, ATOM_H=1, ATOM_HE=2, ATOM_LI=3, ATOM_BE=4, ATOM_AL=5, ATOM_C=6, ATOM_N=7, ATOM_O=8, ATOM_F=9, ATOM_AR=10, ATOM_END=11 } element; } *a; } *


original_code:
struct atom *atom_at(struct workspace *w, struct position pos)
{
 struct item *i = item_at(w, pos);
 if (i->type == ITEM_ATOM)
  return (struct atom *)i->item;
 else if (i->type == ITEM_GLYPH)
  return ((struct glyph *)i->item)->a;
 else
  return ((void *)0);
}

variable_types: struct item { enum item_type { ITEM_NONE=0, ITEM_ATOM=1, ITEM_MANIPULATOR=2, ITEM_GLYPH=3 } type; void *item; } *

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: enum element { ATOM_NONE=0, ATOM_H=1, ATOM_HE=2, ATOM_LI=3, ATOM_BE=4, ATOM_AL=5, ATOM_C=6, ATOM_N=7, ATOM_O=8, ATOM_F=9, ATOM_AR=10, ATOM_END=11 }

user_defined_types: enum glyph_op { BOND=0, UNBOND=1, SOURCE=2, TRANSMUTE=3 }


decompiled_code:
__int64 __fastcall manipulator_at(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rdx

v3 = item_at(a1, a2, a3);
v4 = 0LL;
if ( *(_DWORD *)v3 == 2 )
v4 = *(_QWORD *)(v3 + 8);
return v4;
}

original_code:
struct manipulator *manipulator_at(struct workspace *w, struct position pos)
{
 struct item *i = item_at(w, pos);
 if (i->type == ITEM_MANIPULATOR)
  return (struct manipulator *)i->item;
 else
  return ((void *)0);
}

user_defined_types: enum orientation { PX=0, NX=1, PY=2, NY=3, PZ=4, NZ=5, ORIENTATION_NUM=6 }

user_defined_types: enum head_state { HEAD_OPEN=0, HEAD_CLOSED=1 }

user_defined_types: enum op { ROT_PX=0, ROT_PY=1, ROT_PZ=2, ROT_NX=3, ROT_NY=4, ROT_NZ=5, EXTEND=6, RETRACT=7, OPEN_HEAD=8, CLOSE_HEAD=9, NOP=10 }


decompiled_code:
void __fastcall sim_start(signed int *a1)
{
int i; // er15
signed int k; // ebx
__int64 v3; // rax
signed int j; // er14

for ( i = 0; a1[2] > i; ++i )
{
for ( j = 0; a1[1] > j; ++j )
{
for ( k = 0; *a1 > k; ++k )
{
v3 = manipulator_at((__int64)a1, __SPAIR64__(j, k), i);
if ( v3 )
*(_QWORD *)(v3 + 48) = *(_QWORD *)(v3 + 32);
}
}
}
}

original_code:
void sim_start(struct workspace *w)
{
 struct position pos;
 struct manipulator *m;
 for (pos.z = 0; pos.z < w->size.z; pos.z++) for (pos.y = 0; pos.y < w->size.y; pos.y++) for (pos.x = 0; pos.x < w->size.x; pos.x++) {
  if ((m = manipulator_at(w, pos)) != ((void *)0))
   m->pc = ((struct inst *)((char *)(m->inst_list.next)-(unsigned long)(&((struct inst *)0)->list)));
 }
}

variable_types:
pos
struct position { int x; }


original_code:
struct glyph *glyph_at(struct workspace *w, struct position pos)
{
 struct item *i = item_at(w, pos);
 if (i->type == ITEM_GLYPH)
  return (struct glyph *)i->item;
 else
  return ((void *)0);
}


decompiled_code:
void __fastcall sim_step(__int64 a1)
{
int v1; // er15
signed int j; // ebp
__int64 v3; // rax
signed int i; // er14
int v5; // eax
int v6; // er15
signed int l; // ebp
const char *v8; // rax
signed int k; // er14

v1 = 0;
if ( *(int *)(a1 + 8) > 0 )
{
do
{
for ( i = 0; *(_DWORD *)(a1 + 4) > i; ++i )
{
for ( j = 0; *(_DWORD *)a1 > j; ++j )
{
v3 = glyph_at(a1, __SPAIR64__(i, j), v1);
if ( v3 )
act(a1, v3);
}
}
v5 = *(_DWORD *)(a1 + 8);
++v1;
}
while ( v5 > v1 );
if ( v5 > 0 )
{
v6 = 0;
do
{
for ( k = 0; *(_DWORD *)(a1 + 4) > k; ++k )
{
for ( l = 0; *(_DWORD *)a1 > l; ++l )
{
v8 = (const char *)manipulator_at(a1, __SPAIR64__(k, l), v6);
if ( v8 )
step((const char *)a1, v8);
}
}
++v6;
}
while ( *(_DWORD *)(a1 + 8) > v6 );
}
}
}

original_code:
void sim_step(struct workspace *w)
{
 struct position pos;
 struct manipulator *m;
 struct glyph *g;
 for (pos.z = 0; pos.z < w->size.z; pos.z++) for (pos.y = 0; pos.y < w->size.y; pos.y++) for (pos.x = 0; pos.x < w->size.x; pos.x++) {
  if ((g = glyph_at(w, pos)) != ((void *)0))
   act(w, g);
 }
 for (pos.z = 0; pos.z < w->size.z; pos.z++) for (pos.y = 0; pos.y < w->size.y; pos.y++) for (pos.x = 0; pos.x < w->size.x; pos.x++) {
  if ((m = manipulator_at(w, pos)) != ((void *)0))
   step(w, m);
 }
}


decompiled_code:
__int64 __fastcall move_manipulator(__int64 a1, __int64 a2, int a3, __int64 a4, int a5)
{
__int64 v5; // rax
__int64 v6; // rbx
__int64 result; // rax

v5 = remove_manipulator(a1, a2, a3);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = v5;
result = add_manipulator(a1, v5, a4, a5);
if ( (_DWORD)result )
{
add_manipulator(a1, v6, a2, a3);
result = 4294967294LL;
}
else
{
*(_QWORD *)v6 = a4;
*(_DWORD *)(v6 + 8) = a5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, int a3, __int64 a4, int a5)
{
__int64 v5; // rax
__int64 v6; // rbx
__int64 result; // rax

v5 = func9(a1, a2, a3);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = v5;
result = func6(a1, v5, a4, a5);
if ( (_DWORD)result )
{
func6(a1, v6, a2, a3);
result = 4294967294LL;
}
else
{
*(_QWORD *)v6 = a4;
*(_DWORD *)(v6 + 8) = a5;
}
return result;
}

original_code:
int move_manipulator(struct workspace *w, struct position from, struct position to)
{
 struct manipulator *m = remove_manipulator(w, from);
 if (m != ((void *)0)) {
  if (add_manipulator(w, m, to) == 0) {
   m->pos = to;
   return 0;
  } else {
   add_manipulator(w, m, from);
   return -2;
  }
 } else {
  return -1;
 }
}

variable_types:
from
struct position

variable_types:
to
struct position


decompiled_code:
__int64 __fastcall pos_add(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+0h] [rbp-14h]

LODWORD(v4) = a1 + a3;
HIDWORD(v4) = HIDWORD(a3) + HIDWORD(a1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+0h] [rbp-14h]

LODWORD(v4) = a1 + a3;
HIDWORD(v4) = HIDWORD(a3) + HIDWORD(a1);
return v4;
}

original_code:
static inline struct position pos_add(struct position a, struct position b)
{
 struct position p = {
  a.x + b.x,
  a.y + b.y,
  a.z + b.z
 };
 return p;
}

variable_types:
a
struct position

variable_types:
b
struct position

variable_types:
p
struct position { int x; }

return_type: struct position { int x; }