decompiled_code:
__int64 __fastcall gtthread_cancel(__int64 a1)
{
__int64 v1; // rbp
__int64 *v2; // rbx

if ( numThreadsCreated <= 0 )
return 0LL;
v1 = 0LL;
v2 = threadList;
do
{
if ( gtthread_equal(v2[2], a1) && !*((_DWORD *)v2 + 3) )
{
free((void *)v2[5]);
*(_DWORD *)v2 = 0;
threadidarray[v1] = -1LL;
atomic_decrement(&activeThreadCount);
*((_DWORD *)v2 + 3) = 1;
}
++v1;
v2 += 125;
}
while ( numThreadsCreated > (int)v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbp
__int64 *v2; // rbx

if ( numThreadsCreated <= 0 )
return 0LL;
v1 = 0LL;
v2 = threadList;
do
{
if ( func4(v2[2], a1) && !*((_DWORD *)v2 + 3) )
{
free((void *)v2[5]);
*(_DWORD *)v2 = 0;
threadidarray[v1] = -1LL;
atomic_decrement(&activeThreadCount);
*((_DWORD *)v2 + 3) = 1;
}
++v1;
v2 += 125;
}
while ( numThreadsCreated > (int)v1 );
return 0LL;
}

original_code:
int gtthread_cancel( unsigned long int thread ){
 int i;
 for( i=0; i<numThreadsCreated; i++ ) {
  if( gtthread_equal( threadList[i].threadid, thread ) && !threadList[i].deleted ){
   free(threadList[i].context.uc_stack.ss_sp);
   threadList[i].active = false;
   threadidarray[i] = -1;
   atomic_decrement( &activeThreadCount );
   threadList[i].deleted = true;
  }
 }
 return 0;
}

canonical_original_code:
int gtthread_cancel(unsigned long thread){
 int i;
 for( i=0; i<numThreadsCreated; i++ ) {
  if( gtthread_equal( threadList[i].threadid, thread ) && !threadList[i].deleted ){
   free(threadList[i].context.uc_stack.ss_sp);
   threadList[i].active = false;
   threadidarray[i] = -1;
   atomic_decrement( &activeThreadCount );
   threadList[i].deleted = true;
  }
 }
 return 0;
}


repo: jedivind/gtthreads

decompiled_code:
int __fastcall gtthread_exit(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi

v1 = 125LL * currentThread;
threadList[v1 + 124] = a1;
v2 = threadList[v1 + 2];
LODWORD(threadList[v1 + 1]) = 1;
gtthread_cancel(v2);
return setcontext(&scheduler_context);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi

v1 = 125LL * currentThread;
threadList[v1 + 124] = a1;
v2 = threadList[v1 + 2];
LODWORD(threadList[v1 + 1]) = 1;
func5(v2);
return setcontext(&scheduler_context);
}

original_code:
void gtthread_exit( void *retval ){
  threadList[currentThread].returnval = retval;
  threadList[currentThread].exited = true;
  gtthread_cancel( threadList[currentThread].threadid );
 setcontext( &scheduler_context );
 return;
}

canonical_original_code:
void gtthread_exit(void *retval){
  threadList[currentThread].returnval = retval;
  threadList[currentThread].exited = true;
  gtthread_cancel( threadList[currentThread].threadid );
 setcontext( &scheduler_context );
 return;
}

variable_types:
retval
void *

return_type: void


decompiled_code:
__int64 gtthread_self()
{
return threadList[125 * currentThread + 2];
}

canonical_decompiled_code:
__int64 func7()
{
return threadList[125 * currentThread + 2];
}

original_code:
unsigned long int gtthread_self( void ){
 return threadList[currentThread].threadid;
}

canonical_original_code:
unsigned long gtthread_self(){
 return threadList[currentThread].threadid;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall gtthread_mutex_init(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 == 1LL )
return 0xFFFFFFFFLL;
result = 0LL;
*a1 = 0LL;
a1[1] = -1LL;
return result;
}

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

if ( *a1 == 1LL )
return 0xFFFFFFFFLL;
result = 0LL;
*a1 = 0LL;
a1[1] = -1LL;
return result;
}

original_code:
int gtthread_mutex_init( gtthread_mutex_t *mutex ) {
 if( mutex->lock == 1 ) return -1;
 __asm__ __volatile__ (
       "mov $0x00, %%rax\n\t"
       "xchg %%rax, %0\n\t"
       "mov $0xFFFFFFFFFFFFFFFF, %%rax\n\t"
       "xchg %%rax, %1\n\t"
       :"=r" (mutex->lock), "=r" (mutex->owner)
       :
       :"%rax"
       );
 return 0;
}

canonical_original_code:
int gtthread_mutex_init(struct gtthread_mutex_t *mutex) {
 if( mutex->lock == 1 ) return -1;
 __asm__ __volatile__ (
       "mov $0x00, %%rax\n\t"
       "xchg %%rax, %0\n\t"
       "mov $0xFFFFFFFFFFFFFFFF, %%rax\n\t"
       "xchg %%rax, %1\n\t"
       :"=r" (mutex->lock), "=r" (mutex->owner)
       :
       :"%rax"
       );
 return 0;
}

variable_types: struct gtthread_mutex_t { long lock; unsigned long owner; } *

return_type: int


decompiled_code:
__int64 __fastcall gtthread_mutex_lock(_QWORD *a1)
{
__int64 result; // rax

if ( a1[1] == threadList[125 * currentThread + 2] )
return 0xFFFFFFFFLL;
if ( *a1 )
{
do
gtthread_yield();
while ( *a1 && a1[1] != threadList[125 * currentThread + 2] );
}
result = 0LL;
*a1 = 1LL;
a1[1] = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax

if ( a1[1] == threadList[125 * currentThread + 2] )
return 0xFFFFFFFFLL;
if ( *a1 )
{
do
gtthread_yield();
while ( *a1 && a1[1] != threadList[125 * currentThread + 2] );
}
result = 0LL;
*a1 = 1LL;
a1[1] = 1LL;
return result;
}

original_code:
int gtthread_mutex_lock( gtthread_mutex_t *mutex ){
 if( ( mutex->owner ) == threadList[currentThread].threadid ){
  return -1;
 }
 while( mutex->lock !=0 && mutex->owner != threadList[currentThread].threadid )
 gtthread_yield();
 __asm__ __volatile__(
      "mov $0x01, %%rax\n\t"
      "xchg %%rax, %0\n\t"
      "mov %2, %%rax\n\t"
      "xchg %%rax, %1\n\t"
      :"=r" (mutex->lock), "=r" (mutex->owner)
      :"r" (threadList[currentThread].threadid)
      :"%rax"
      );
 return 0;
}

canonical_original_code:
int gtthread_mutex_lock(struct gtthread_mutex_t *mutex){
 if( ( mutex->owner ) == threadList[currentThread].threadid ){
  return -1;
 }
 while( mutex->lock !=0 && mutex->owner != threadList[currentThread].threadid )
 gtthread_yield();
 __asm__ __volatile__(
      "mov $0x01, %%rax\n\t"
      "xchg %%rax, %0\n\t"
      "mov %2, %%rax\n\t"
      "xchg %%rax, %1\n\t"
      :"=r" (mutex->lock), "=r" (mutex->owner)
      :"r" (threadList[currentThread].threadid)
      :"%rax"
      );
 return 0;
}

user_defined_types: struct gtthread_mutex_t { long lock; unsigned long owner; }


decompiled_code:
__int64 __fastcall gtthread_mutex_unlock(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 != 1LL || a1[1] != threadList[125 * currentThread + 2] )
return 0xFFFFFFFFLL;
result = 0LL;
*a1 = 0LL;
a1[1] = -1LL;
return result;
}

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

if ( *a1 != 1LL || a1[1] != threadList[125 * currentThread + 2] )
return 0xFFFFFFFFLL;
result = 0LL;
*a1 = 0LL;
a1[1] = -1LL;
return result;
}

original_code:
int gtthread_mutex_unlock( gtthread_mutex_t *mutex ){
 if( mutex->lock == 1 && mutex->owner == threadList[currentThread].threadid ){
  __asm__ __volatile__ (
        "mov $0x00, %%rax\n\t"
        "xchg %%rax, %0\n\t"
        "mov $0xFFFFFFFFFFFFFFFF, %%rax\n\t"
        "xchg %%rax, %1\n\t"
        :"=r" (mutex->lock), "=r" (mutex->owner)
         :
         :"%rax"
        );
  return 0;
 }
 return -1;
}

canonical_original_code:
int gtthread_mutex_unlock(struct gtthread_mutex_t *mutex){
 if( mutex->lock == 1 && mutex->owner == threadList[currentThread].threadid ){
  __asm__ __volatile__ (
        "mov $0x00, %%rax\n\t"
        "xchg %%rax, %0\n\t"
        "mov $0xFFFFFFFFFFFFFFFF, %%rax\n\t"
        "xchg %%rax, %1\n\t"
        :"=r" (mutex->lock), "=r" (mutex->owner)
         :
         :"%rax"
        );
  return 0;
 }
 return -1;
}


sighandler

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

if ( a1 == 14 )
result = swapcontext((ucontext_t *)((char *)&threadList + 1000 * currentThread + 24), &scheduler_context);
return result;
}

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

if ( a1 == 14 )
result = swapcontext((ucontext_t *)((char *)&threadList + 1000 * currentThread + 24), &scheduler_context);
return result;
}

original_code:
void sighandler( int sig_nr, siginfo_t* info, void *old_context ) {
 if ( sig_nr == 14 )
  swapcontext( &threadList[currentThread].context, &scheduler_context );
 else return;
}

canonical_original_code:
void sighandler(int sig_nr, struct siginfo_t *info, void *old_context) {
 if ( sig_nr == 14 )
  swapcontext( &threadList[currentThread].context, &scheduler_context );
 else return;
}

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

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


decompiled_code:
int __fastcall gtthread_block_signal(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return sigprocmask(0, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return sigprocmask(0, &v2, 0LL);
}

original_code:
void gtthread_block_signal( int signo ){
 sigset_t set;
 sigemptyset(&set);
 sigaddset(&set, signo);
 sigprocmask(0, &set, ((void *)0));
return;
}

canonical_original_code:
void gtthread_block_signal(int signo){
 struct __sigset_t set;
 sigemptyset(&set);
 sigaddset(&set, signo);
 sigprocmask(0, &set, ((void *)0));
return;
}

variable_types: signo int

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


decompiled_code:
// attributes: thunk
int __fastcall gtthread_unblock_signal(int signo)
{
return gtthread_block_signal(signo);
}

canonical_decompiled_code:
int __fastcall func2(int signo)
{
return func1(signo);
}

original_code:
void gtthread_unblock_signal( int signo ){
 sigset_t set;
 sigemptyset(&set);
 sigaddset(&set, signo);
 sigprocmask(0, &set, ((void *)0));
return;
}

canonical_original_code:
void gtthread_unblock_signal(int signo){
 struct __sigset_t set;
 sigemptyset(&set);
 sigaddset(&set, signo);
 sigprocmask(0, &set, ((void *)0));
return;
}

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


decompiled_code:
void __fastcall init_itimerval(__suseconds_t a1)
{
timequant.it_value.tv_sec = 0LL;
timequant.it_value.tv_usec = a1;
timequant.it_interval = (timeval)_mm_load_si128((const __m128i *)&timequant.it_value);
}

canonical_decompiled_code:
void __fastcall func3(__suseconds_t a1)
{
timequant.it_value.tv_sec = 0LL;
timequant.it_value.tv_usec = a1;
timequant.it_interval = (timeval)_mm_load_si128((const __m128i *)&timequant.it_value);
}

original_code:
void init_itimerval( long period ){
 timequant.it_value.tv_sec = 0;
 timequant.it_value.tv_usec = (long) period;
 timequant.it_interval = timequant.it_value;
}

canonical_original_code:
void init_itimerval(long period){
 timequant.it_value.tv_sec = 0;
 timequant.it_value.tv_usec = (long) period;
 timequant.it_interval = timequant.it_value;
}

variable_types: period long


decompiled_code:
int init_sigtimer()
{
int result; // eax

result = setitimer(ITIMER_REAL, &timequant, 0LL);
if ( result )
{
puts("\n\tAn error occurred while initializing timer. Please check the value of period to gtthread_init()");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

result = setitimer(ITIMER_REAL, &timequant, 0LL);
if ( result )
{
puts("\n\tAn error occurred while initializing timer. Please check the value of period to gtthread_init()");
exit(-1);
}
return result;
}

original_code:
void init_sigtimer(){
 if( setitimer( ITIMER_REAL, &timequant, ((void *)0) ) == 0) {
 }
 else {
  printf("\n\tAn error occurred while initializing timer. Please check the value of period to gtthread_init()\n");
  exit(-1);
 }
 return;
}


decompiled_code:
int init_sched_preempt_handler()
{
int result; // eax

scheduling_preemption_handler.__val[0] = (unsigned __int64)sighandler;
*((_DWORD *)&scheduling_preemption_handler + 34) = 268435460;
sigemptyset((sigset_t *)(unsigned int)((_DWORD)&scheduling_preemption_handler + 8));
result = sigaction(14, (const struct sigaction *)&scheduling_preemption_handler, 0LL);
if ( result == -1 )
{
puts("\nAn error occurred while initializing the signal handler for swapping to the scheduler context");
exit(-1);
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

scheduling_preemption_handler.__val[0] = (unsigned __int64)sighandler;
*((_DWORD *)&scheduling_preemption_handler + 34) = 268435460;
sigemptyset((sigset_t *)(unsigned int)((_DWORD)&scheduling_preemption_handler + 8));
result = sigaction(14, (const struct sigaction *)&scheduling_preemption_handler, 0LL);
if ( result == -1 )
{
puts("\nAn error occurred while initializing the signal handler for swapping to the scheduler context");
exit(-1);
}
return result;
}

original_code:
void init_sched_preempt_handler(){
 scheduling_preemption_handler.__sigaction_handler.sa_sigaction = sighandler;
 scheduling_preemption_handler.sa_flags = 0x10000000 | 4;
 sigemptyset( &scheduling_preemption_handler.sa_mask );
 if ( sigaction( 14, &scheduling_preemption_handler, ((void *)0) ) == -1 ) {
  printf("\nAn error occurred while initializing the signal handler for swapping to the scheduler context\n");
  exit(-1);
 }
 return;
}


repo: jeffboody/loax

decompiled_code:
char *__fastcall loax_eventkey_keystring(int *a1)
{
__int64 v1; // rax
const char *v2; // r8

v1 = *a1;
if ( (unsigned int)v1 <= 0x7F )
return LOAX_KEYSTRING[v1];
v2 = "UP";
if ( (_DWORD)v1 != 256 )
{
v2 = "DOWN";
if ( (_DWORD)v1 != 257 )
{
v2 = "LEFT";
if ( (_DWORD)v1 != 258 )
{
v2 = "RIGHT";
if ( (_DWORD)v1 != 259 )
{
v2 = "HOME";
if ( (_DWORD)v1 != 260 )
{
v2 = "END";
if ( (_DWORD)v1 != 261 )
{
v2 = "PGUP";
if ( (_DWORD)v1 != 262 )
{
v2 = "PGDOWN";
if ( (_DWORD)v1 != 263 )
{
v2 = "INSERT";
if ( (_DWORD)v1 != 264 )
v2 = "UNKNOWN";
}
}
}
}
}
}
}
}
return (char *)v2;
}

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

v1 = *a1;
if ( (unsigned int)v1 <= 0x7F )
return LOAX_KEYSTRING[v1];
v2 = "UP";
if ( (_DWORD)v1 != 256 )
{
v2 = "DOWN";
if ( (_DWORD)v1 != 257 )
{
v2 = "LEFT";
if ( (_DWORD)v1 != 258 )
{
v2 = "RIGHT";
if ( (_DWORD)v1 != 259 )
{
v2 = "HOME";
if ( (_DWORD)v1 != 260 )
{
v2 = "END";
if ( (_DWORD)v1 != 261 )
{
v2 = "PGUP";
if ( (_DWORD)v1 != 262 )
{
v2 = "PGDOWN";
if ( (_DWORD)v1 != 263 )
{
v2 = "INSERT";
if ( (_DWORD)v1 != 264 )
v2 = "UNKNOWN";
}
}
}
}
}
}
}
}
return (char *)v2;
}

original_code:
const char* loax_eventkey_keystring(loax_eventkey_t* self)
{
 int k = self->keycode;
 if((k >= 0) && (k < 128))
 {
  return LOAX_KEYSTRING[k];
 }
 else if(k == 0x100)
 {
  return "UP";
 }
 else if(k == 0x101)
 {
  return "DOWN";
 }
 else if(k == 0x102)
 {
  return "LEFT";
 }
 else if(k == 0x103)
 {
  return "RIGHT";
 }
 else if(k == 0x104)
 {
  return "HOME";
 }
 else if(k == 0x105)
 {
  return "END";
 }
 else if(k == 0x106)
 {
  return "PGUP";
 }
 else if(k == 0x107)
 {
  return "PGDOWN";
 }
 else if(k == 0x108)
 {
  return "INSERT";
 }
 return LOAX_STRING_UNKNOWN;
}

canonical_original_code:
char *loax_eventkey_keystring(struct loax_eventkey_t *self)
{
 int k = self->keycode;
 if((k >= 0) && (k < 128))
 {
  return LOAX_KEYSTRING[k];
 }
 else if(k == 0x100)
 {
  return "UP";
 }
 else if(k == 0x101)
 {
  return "DOWN";
 }
 else if(k == 0x102)
 {
  return "LEFT";
 }
 else if(k == 0x103)
 {
  return "RIGHT";
 }
 else if(k == 0x104)
 {
  return "HOME";
 }
 else if(k == 0x105)
 {
  return "END";
 }
 else if(k == 0x106)
 {
  return "PGUP";
 }
 else if(k == 0x107)
 {
  return "PGDOWN";
 }
 else if(k == 0x108)
 {
  return "INSERT";
 }
 return LOAX_STRING_UNKNOWN;
}

variable_types: struct loax_eventkey_t { int keycode; int meta; } *

variable_types: k int

return_type: char *


decompiled_code:
const char *__fastcall loax_eventbutton_keystring(int *a1)
{
int v1; // edx
const char *result; // rax

if ( !a1 )
_assert_fail("self", "loax_event.c", 0x10Cu, "loax_eventbutton_keystring");
v1 = *a1;
result = "1";
if ( *a1 != 188 )
{
result = "2";
if ( v1 != 189 )
{
result = "3";
if ( v1 != 190 )
{
result = "4";
if ( v1 != 191 )
{
result = "5";
if ( v1 != 192 )
{
result = "6";
if ( v1 != 193 )
{
result = "7";
if ( v1 != 194 )
{
result = "8";
if ( v1 != 195 )
{
result = "9";
if ( v1 != 196 )
{
result = "10";
if ( v1 != 197 )
{
result = "11";
if ( v1 != 198 )
{
result = "12";
if ( v1 != 199 )
{
result = "13";
if ( v1 != 200 )
{
result = "14";
if ( v1 != 201 )
{
result = "15";
if ( v1 != 202 )
{
result = "16";
if ( v1 != 203 )
{
result = (const char *)aAbc;
if ( v1 != 96 )
{
result = (const char *)&aAbc[1];
if ( v1 != 97 )
{
result = (const char *)&aAbc[2];
if ( v1 != 98 )
{
result = "L1";
if ( v1 != 102 )
{
result = "R1";
if ( v1 != 103 )
{
result = "L2";
if ( v1 != 104 )
{
result = "R2";
if ( v1 != 105 )
{
result = "MODE";
if ( v1 != 110 )
{
result = "SELECT";
if ( v1 != 109 )
{
result = "START";
if ( v1 != 108 )
{
result = "THUMBL";
if ( v1 != 106 )
{
result = "THUMBR";
if ( v1 != 107 )
{
result = "X";
if ( v1 != 99 )
{
result = "Y";
if ( v1 != 100 )
{
switch ( v1 )
{
case 101:
result = "Z";
break;
case 19:
result = "UP";
break;
case 20:
result = "DOWN";
break;
case 21:
result = "LEFT";
break;
case 22:
result = "RIGHT";
break;
default:
result = "CENTER";
if ( v1 != 23 )
result = "UNKNOWN";
break;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int *a1)
{
int v1; // edx
const char *result; // rax

if ( !a1 )
_assert_fail("self", "loax_event.c", 0x10Cu, "loax_eventbutton_keystring");
v1 = *a1;
result = "1";
if ( *a1 != 188 )
{
result = "2";
if ( v1 != 189 )
{
result = "3";
if ( v1 != 190 )
{
result = "4";
if ( v1 != 191 )
{
result = "5";
if ( v1 != 192 )
{
result = "6";
if ( v1 != 193 )
{
result = "7";
if ( v1 != 194 )
{
result = "8";
if ( v1 != 195 )
{
result = "9";
if ( v1 != 196 )
{
result = "10";
if ( v1 != 197 )
{
result = "11";
if ( v1 != 198 )
{
result = "12";
if ( v1 != 199 )
{
result = "13";
if ( v1 != 200 )
{
result = "14";
if ( v1 != 201 )
{
result = "15";
if ( v1 != 202 )
{
result = "16";
if ( v1 != 203 )
{
result = (const char *)aAbc;
if ( v1 != 96 )
{
result = (const char *)&aAbc[1];
if ( v1 != 97 )
{
result = (const char *)&aAbc[2];
if ( v1 != 98 )
{
result = "L1";
if ( v1 != 102 )
{
result = "R1";
if ( v1 != 103 )
{
result = "L2";
if ( v1 != 104 )
{
result = "R2";
if ( v1 != 105 )
{
result = "MODE";
if ( v1 != 110 )
{
result = "SELECT";
if ( v1 != 109 )
{
result = "START";
if ( v1 != 108 )
{
result = "THUMBL";
if ( v1 != 106 )
{
result = "THUMBR";
if ( v1 != 107 )
{
result = "X";
if ( v1 != 99 )
{
result = "Y";
if ( v1 != 100 )
{
switch ( v1 )
{
case 101:
result = "Z";
break;
case 19:
result = "UP";
break;
case 20:
result = "DOWN";
break;
case 21:
result = "LEFT";
break;
case 22:
result = "RIGHT";
break;
default:
result = "CENTER";
if ( v1 != 23 )
result = "UNKNOWN";
break;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
const char* loax_eventbutton_keystring(loax_eventbutton_t* self)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "loax_event.c", 268, __extension__ __PRETTY_FUNCTION__); }));
 ;
 int k = self->keycode;
 if (k == 0xBC) return LOAX_BUTTONSTRING_1;
 else if(k == 0xBD) return LOAX_BUTTONSTRING_2;
 else if(k == 0xBE) return LOAX_BUTTONSTRING_3;
 else if(k == 0xBF) return LOAX_BUTTONSTRING_4;
 else if(k == 0xC0) return LOAX_BUTTONSTRING_5;
 else if(k == 0xC1) return LOAX_BUTTONSTRING_6;
 else if(k == 0xC2) return LOAX_BUTTONSTRING_7;
 else if(k == 0xC3) return LOAX_BUTTONSTRING_8;
 else if(k == 0xC4) return LOAX_BUTTONSTRING_9;
 else if(k == 0xC5) return LOAX_BUTTONSTRING_10;
 else if(k == 0xC6) return LOAX_BUTTONSTRING_11;
 else if(k == 0xC7) return LOAX_BUTTONSTRING_12;
 else if(k == 0xC8) return LOAX_BUTTONSTRING_13;
 else if(k == 0xC9) return LOAX_BUTTONSTRING_14;
 else if(k == 0xCA) return LOAX_BUTTONSTRING_15;
 else if(k == 0xCB) return LOAX_BUTTONSTRING_16;
 else if(k == 0x60) return LOAX_BUTTONSTRING_A;
 else if(k == 0x61) return LOAX_BUTTONSTRING_B;
 else if(k == 0x62) return LOAX_BUTTONSTRING_C;
 else if(k == 0x66) return LOAX_BUTTONSTRING_L1;
 else if(k == 0x67) return LOAX_BUTTONSTRING_R1;
 else if(k == 0x68) return LOAX_BUTTONSTRING_L2;
 else if(k == 0x69) return LOAX_BUTTONSTRING_R2;
 else if(k == 0x6E) return LOAX_BUTTONSTRING_MODE;
 else if(k == 0x6D) return LOAX_BUTTONSTRING_SELECT;
 else if(k == 0x6C) return LOAX_BUTTONSTRING_START;
 else if(k == 0x6A) return LOAX_BUTTONSTRING_THUMBL;
 else if(k == 0x6B) return LOAX_BUTTONSTRING_THUMBR;
 else if(k == 0x63) return LOAX_BUTTONSTRING_X;
 else if(k == 0x64) return LOAX_BUTTONSTRING_Y;
 else if(k == 0x65) return LOAX_BUTTONSTRING_Z;
 else if(k == 0x13) return LOAX_BUTTONSTRING_UP;
 else if(k == 0x14) return LOAX_BUTTONSTRING_DOWN;
 else if(k == 0x15) return LOAX_BUTTONSTRING_LEFT;
 else if(k == 0x16) return LOAX_BUTTONSTRING_RIGHT;
 else if(k == 0x17) return LOAX_BUTTONSTRING_CENTER;
 else return LOAX_STRING_UNKNOWN;
}

canonical_original_code:
char *loax_eventbutton_keystring(struct loax_eventbutton_t *self)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "loax_event.c", 268, __extension__ __PRETTY_FUNCTION__); }));
 ;
 int k = self->keycode;
 if (k == 0xBC) return LOAX_BUTTONSTRING_1;
 else if(k == 0xBD) return LOAX_BUTTONSTRING_2;
 else if(k == 0xBE) return LOAX_BUTTONSTRING_3;
 else if(k == 0xBF) return LOAX_BUTTONSTRING_4;
 else if(k == 0xC0) return LOAX_BUTTONSTRING_5;
 else if(k == 0xC1) return LOAX_BUTTONSTRING_6;
 else if(k == 0xC2) return LOAX_BUTTONSTRING_7;
 else if(k == 0xC3) return LOAX_BUTTONSTRING_8;
 else if(k == 0xC4) return LOAX_BUTTONSTRING_9;
 else if(k == 0xC5) return LOAX_BUTTONSTRING_10;
 else if(k == 0xC6) return LOAX_BUTTONSTRING_11;
 else if(k == 0xC7) return LOAX_BUTTONSTRING_12;
 else if(k == 0xC8) return LOAX_BUTTONSTRING_13;
 else if(k == 0xC9) return LOAX_BUTTONSTRING_14;
 else if(k == 0xCA) return LOAX_BUTTONSTRING_15;
 else if(k == 0xCB) return LOAX_BUTTONSTRING_16;
 else if(k == 0x60) return LOAX_BUTTONSTRING_A;
 else if(k == 0x61) return LOAX_BUTTONSTRING_B;
 else if(k == 0x62) return LOAX_BUTTONSTRING_C;
 else if(k == 0x66) return LOAX_BUTTONSTRING_L1;
 else if(k == 0x67) return LOAX_BUTTONSTRING_R1;
 else if(k == 0x68) return LOAX_BUTTONSTRING_L2;
 else if(k == 0x69) return LOAX_BUTTONSTRING_R2;
 else if(k == 0x6E) return LOAX_BUTTONSTRING_MODE;
 else if(k == 0x6D) return LOAX_BUTTONSTRING_SELECT;
 else if(k == 0x6C) return LOAX_BUTTONSTRING_START;
 else if(k == 0x6A) return LOAX_BUTTONSTRING_THUMBL;
 else if(k == 0x6B) return LOAX_BUTTONSTRING_THUMBR;
 else if(k == 0x63) return LOAX_BUTTONSTRING_X;
 else if(k == 0x64) return LOAX_BUTTONSTRING_Y;
 else if(k == 0x65) return LOAX_BUTTONSTRING_Z;
 else if(k == 0x13) return LOAX_BUTTONSTRING_UP;
 else if(k == 0x14) return LOAX_BUTTONSTRING_DOWN;
 else if(k == 0x15) return LOAX_BUTTONSTRING_LEFT;
 else if(k == 0x16) return LOAX_BUTTONSTRING_RIGHT;
 else if(k == 0x17) return LOAX_BUTTONSTRING_CENTER;
 else return LOAX_STRING_UNKNOWN;
}

variable_types: struct loax_eventbutton_t { int keycode; int id; } *


decompiled_code:
const char *__fastcall loax_eventaxis_axisstring(__int64 a1)
{
int v1; // edx
const char *result; // rax

if ( !a1 )
_assert_fail("self", "loax_event.c", 0x139u, "loax_eventaxis_axisstring");
v1 = *(_DWORD *)(a1 + 4);
result = "AX1";
if ( v1 )
{
result = "AY1";
if ( v1 != 1 )
{
result = "AX2";
if ( v1 != 11 )
{
result = "AY2";
if ( v1 != 14 )
{
result = "AHX";
if ( v1 != 15 )
{
result = "AHY";
if ( v1 != 16 )
result = "UNKNOWN";
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(__int64 a1)
{
int v1; // edx
const char *result; // rax

if ( !a1 )
_assert_fail("self", "loax_event.c", 0x139u, "loax_eventaxis_axisstring");
v1 = *(_DWORD *)(a1 + 4);
result = "AX1";
if ( v1 )
{
result = "AY1";
if ( v1 != 1 )
{
result = "AX2";
if ( v1 != 11 )
{
result = "AY2";
if ( v1 != 14 )
{
result = "AHX";
if ( v1 != 15 )
{
result = "AHY";
if ( v1 != 16 )
result = "UNKNOWN";
}
}
}
}
}
return result;
}

original_code:
const char* loax_eventaxis_axisstring(loax_eventaxis_t* self)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "loax_event.c", 313, __extension__ __PRETTY_FUNCTION__); }));
 ;
 int a = self->axis;
 if (a == 0x00) return LOAX_AXISSTRING_X1;
 else if(a == 0x01) return LOAX_AXISSTRING_Y1;
 else if(a == 0x0B) return LOAX_AXISSTRING_X2;
 else if(a == 0x0E) return LOAX_AXISSTRING_Y2;
 else if(a == 0x0F) return LOAX_AXISSTRING_HX;
 else if(a == 0x10) return LOAX_AXISSTRING_HY;
 else return LOAX_STRING_UNKNOWN;
}

canonical_original_code:
char *loax_eventaxis_axisstring(struct loax_eventaxis_t *self)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "loax_event.c", 313, __extension__ __PRETTY_FUNCTION__); }));
 ;
 int a = self->axis;
 if (a == 0x00) return LOAX_AXISSTRING_X1;
 else if(a == 0x01) return LOAX_AXISSTRING_Y1;
 else if(a == 0x0B) return LOAX_AXISSTRING_X2;
 else if(a == 0x0E) return LOAX_AXISSTRING_Y2;
 else if(a == 0x0F) return LOAX_AXISSTRING_HX;
 else if(a == 0x10) return LOAX_AXISSTRING_HY;
 else return LOAX_STRING_UNKNOWN;
}

variable_types: struct loax_eventaxis_t { int id; int axis; float value; } *

variable_types: a int


decompiled_code:
int loax_log(const char *a1, unsigned int a2, int a3, const char *a4, const char *a5, ...)
{
size_t v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( !a1 )
_assert_fail("func", "loax_log.c", 0x21u, "loax_log");
if ( !a4 )
_assert_fail("tag", "loax_log.c", 0x22u, "loax_log");
if ( !a5 )
_assert_fail("fmt", "loax_log.c", 0x23u, "loax_log");
if ( a3 )
{
switch ( a3 )
{
case 1:
snprintf(s, 0x100uLL, "I/%s: %s@%i ", a4, a1, a2);
break;
case 2:
snprintf(s, 0x100uLL, "W/%s: %s@%i ", a4, a1, a2);
break;
case 3:
snprintf(s, 0x100uLL, "E/%s: %s@%i ", a4, a1, a2);
break;
}
}
else
{
snprintf(s, 0x100uLL, "D/%s: %s@%i ", a4, a1, a2);
}
v6 = strlen(s);
va_start(arg, a5);
vsnprintf(&s[v6], 256 - (int)v6, a5, arg);
puts(s);
return fflush(stdout);
}

canonical_decompiled_code:
int func0(const char *a1, unsigned int a2, int a3, const char *a4, const char *a5, ...)
{
size_t v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( !a1 )
_assert_fail("func", "loax_log.c", 0x21u, "loax_log");
if ( !a4 )
_assert_fail("tag", "loax_log.c", 0x22u, "loax_log");
if ( !a5 )
_assert_fail("fmt", "loax_log.c", 0x23u, "loax_log");
if ( a3 )
{
switch ( a3 )
{
case 1:
snprintf(s, 0x100uLL, "I/%s: %s@%i ", a4, a1, a2);
break;
case 2:
snprintf(s, 0x100uLL, "W/%s: %s@%i ", a4, a1, a2);
break;
case 3:
snprintf(s, 0x100uLL, "E/%s: %s@%i ", a4, a1, a2);
break;
}
}
else
{
snprintf(s, 0x100uLL, "D/%s: %s@%i ", a4, a1, a2);
}
v6 = strlen(s);
va_start(arg, a5);
vsnprintf(&s[v6], 256 - (int)v6, a5, arg);
puts(s);
return fflush(stdout);
}

original_code:
void loax_log(const char* func, int line, int type, const char* tag, const char* fmt, ...)
{
 ((void) sizeof ((func) ? 1 : 0), __extension__ ({ if (func) ; else __assert_fail ("func", "loax_log.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((tag) ? 1 : 0), __extension__ ({ if (tag) ; else __assert_fail ("tag", "loax_log.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fmt) ? 1 : 0), __extension__ ({ if (fmt) ; else __assert_fail ("fmt", "loax_log.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 char buf[256];
  if(type == 0)
   snprintf(buf, 256, "D/%s: %s@%i ", tag, func, line);
  else if(type == 1)
   snprintf(buf, 256, "I/%s: %s@%i ", tag, func, line);
  else if(type == 2)
   snprintf(buf, 256, "W/%s: %s@%i ", tag, func, line);
  else if(type == 3)
   snprintf(buf, 256, "E/%s: %s@%i ", tag, func, line);
 int size = (int) strlen(buf);
 if(size < 256)
 {
  va_list argptr;
  __builtin_va_start(argptr,fmt);
  vsnprintf(&buf[size], 256 - size, fmt, argptr);
  __builtin_va_end(argptr);
 }
  printf("%s\n", buf);
  fflush(stdout);
}

canonical_original_code:
void loax_log(char *func, int line, int type, char *tag, char *fmt, ...)
{
 ((void) sizeof ((func) ? 1 : 0), __extension__ ({ if (func) ; else __assert_fail ("func", "loax_log.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((tag) ? 1 : 0), __extension__ ({ if (tag) ; else __assert_fail ("tag", "loax_log.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fmt) ? 1 : 0), __extension__ ({ if (fmt) ; else __assert_fail ("fmt", "loax_log.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 char buf[256];
  if(type == 0)
   snprintf(buf, 256, "D/%s: %s@%i ", tag, func, line);
  else if(type == 1)
   snprintf(buf, 256, "I/%s: %s@%i ", tag, func, line);
  else if(type == 2)
   snprintf(buf, 256, "W/%s: %s@%i ", tag, func, line);
  else if(type == 3)
   snprintf(buf, 256, "E/%s: %s@%i ", tag, func, line);
 int size = (int) strlen(buf);
 if(size < 256)
 {
  __builtin_va_list argptr;
  __builtin_va_start(argptr,fmt);
  vsnprintf(&buf[size], 256 - size, fmt, argptr);
  __builtin_va_end(argptr);
 }
  printf("%s\n", buf);
  fflush(stdout);
}

variable_types:
func
char *

variable_types: line int

variable_types: type int

variable_types:
tag
char *

variable_types:
fmt
char *

variable_types:
buf
char [256]

variable_types: size int


repo: jeffboody/nedgz

decompiled_code:
void __fastcall nedgz_subtile_set(__int64 a1, int a2, int a3, __int16 a4)
{
if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x4Au, "nedgz_subtile_set");
*(_WORD *)(a1 + 2LL * (a3 + 32 * a2)) = a4;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, int a3, __int16 a4)
{
if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x4Au, "nedgz_subtile_set");
*(_WORD *)(a1 + 2LL * (a3 + 32 * a2)) = a4;
}

original_code:
static void nedgz_subtile_set(nedgz_subtile_t* self, int m, int n, short h)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 ;
 self->data[m*32 + n] = h;
}

canonical_original_code:
static void nedgz_subtile_set(struct nedgz_subtile_t *self, int m, int n, short h)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 74, __extension__ __PRETTY_FUNCTION__); }));
 ;
 self->data[m*32 + n] = h;
}

variable_types: struct nedgz_subtile_t { short data[-1]; } *

variable_types: m int

variable_types: n int

variable_types: h short


decompiled_code:
void *nedgz_subtile_new()
{
void *v0; // r12

v0 = calloc(0x800uLL, 1uLL);
if ( !v0 )
nedgz_log("nedgz_subtile_new", 47LL, 3LL, "nedgz", "malloc failed");
return v0;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // r12

v0 = calloc(0x800uLL, 1uLL);
if ( !v0 )
nedgz_log("nedgz_subtile_new", 47LL, 3LL, "nedgz", "malloc failed");
return v0;
}

original_code:
static nedgz_subtile_t* nedgz_subtile_new(void)
{
 nedgz_subtile_t* self = (nedgz_subtile_t*) malloc(sizeof(nedgz_subtile_t));
 if(self == ((void *)0))
 {
  (nedgz_log(__func__, 47, 3, "nedgz", "malloc failed"));
  return ((void *)0);
 }
 int i;
 for(i = 0; i < 32*32; ++i)
 {
  self->data[i] = 0;
 }
 return self;
}

canonical_original_code:
static struct nedgz_subtile_t *nedgz_subtile_new()
{
 struct nedgz_subtile_t *self = (nedgz_subtile_t*) malloc(sizeof(nedgz_subtile_t));
 if(self == ((void *)0))
 {
  (nedgz_log(__func__, 47, 3, "nedgz", "malloc failed"));
  return ((void *)0);
 }
 int i;
 for(i = 0; i < 32*32; ++i)
 {
  self->data[i] = 0;
 }
 return self;
}

variable_types: i int

return_type: struct nedgz_subtile_t { short data[-1]; } *


decompiled_code:
void __fastcall nedgz_subtile_delete(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

original_code:
static void nedgz_subtile_delete(nedgz_subtile_t** _self)
{
 ((void) sizeof ((_self) ? 1 : 0), __extension__ ({ if (_self) ; else __assert_fail ("_self", "nedgz_tile.c", 61, __extension__ __PRETTY_FUNCTION__); }));
 nedgz_subtile_t* self = *_self;
 if(self)
 {
  ;
  free(self);
  *_self = ((void *)0);
 }
}

canonical_original_code:
static void nedgz_subtile_delete(struct nedgz_subtile_t **_self)
{
 ((void) sizeof ((_self) ? 1 : 0), __extension__ ({ if (_self) ; else __assert_fail ("_self", "nedgz_tile.c", 61, __extension__ __PRETTY_FUNCTION__); }));
 struct nedgz_subtile_t *self = *_self;
 if(self)
 {
  ;
  free(self);
  *_self = ((void *)0);
 }
}

variable_types: struct nedgz_subtile_t { short data[-1]; } **


decompiled_code:
__int64 __fastcall nedgz_tile_getij(__int64 a1, int a2, int a3)
{
if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x173u, "nedgz_tile_getij");
if ( a2 < 0 )
_assert_fail("i >= 0", "nedgz_tile.c", 0x174u, "nedgz_tile_getij");
if ( a2 > 7 )
_assert_fail("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x175u, "nedgz_tile_getij");
if ( a3 < 0 )
_assert_fail("j >= 0", "nedgz_tile.c", 0x176u, "nedgz_tile_getij");
if ( a3 > 7 )
_assert_fail("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x177u, "nedgz_tile_getij");
return *(_QWORD *)(a1 + 8LL * (a3 + 8 * a2) + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x173u, "nedgz_tile_getij");
if ( a2 < 0 )
_assert_fail("i >= 0", "nedgz_tile.c", 0x174u, "nedgz_tile_getij");
if ( a2 > 7 )
_assert_fail("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x175u, "nedgz_tile_getij");
if ( a3 < 0 )
_assert_fail("j >= 0", "nedgz_tile.c", 0x176u, "nedgz_tile_getij");
if ( a3 > 7 )
_assert_fail("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x177u, "nedgz_tile_getij");
return *(_QWORD *)(a1 + 8LL * (a3 + 8 * a2) + 16);
}

original_code:
nedgz_subtile_t* nedgz_tile_getij(nedgz_tile_t* self, int i, int j)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 371, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i >= 0) ? 1 : 0), __extension__ ({ if (i >= 0) ; else __assert_fail ("i >= 0", "nedgz_tile.c", 372, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i < 8) ? 1 : 0), __extension__ ({ if (i < 8) ; else __assert_fail ("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 373, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j >= 0) ? 1 : 0), __extension__ ({ if (j >= 0) ; else __assert_fail ("j >= 0", "nedgz_tile.c", 374, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j < 8) ? 1 : 0), __extension__ ({ if (j < 8) ; else __assert_fail ("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 375, __extension__ __PRETTY_FUNCTION__); }));
 ;
 return self->subtile[i*8 + j];
}

canonical_original_code:
struct nedgz_subtile_t *nedgz_tile_getij(struct nedgz_tile_t *self, int i, int j)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 371, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i >= 0) ? 1 : 0), __extension__ ({ if (i >= 0) ; else __assert_fail ("i >= 0", "nedgz_tile.c", 372, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i < 8) ? 1 : 0), __extension__ ({ if (i < 8) ; else __assert_fail ("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 373, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j >= 0) ? 1 : 0), __extension__ ({ if (j >= 0) ; else __assert_fail ("j >= 0", "nedgz_tile.c", 374, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j < 8) ? 1 : 0), __extension__ ({ if (j < 8) ; else __assert_fail ("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 375, __extension__ __PRETTY_FUNCTION__); }));
 ;
 return self->subtile[i*8 + j];
}

variable_types: struct nedgz_tile_t { int x; int y; int zoom; struct nedgz_subtile_t *subtile[-1]; } *

variable_types: j int

user_defined_types: struct nedgz_subtile_t { short data[-1]; }


decompiled_code:
void __fastcall nedgz_tile_delete(void **a1)
{
void *v1; // r12
int v2; // ebp
int i; // ebx
__int64 v4; // [rsp+8h] [rbp-30h] BYREF

if ( !a1 )
_assert_fail("_self", "nedgz_tile.c", 0x70u, "nedgz_tile_delete");
v1 = *a1;
v2 = 0;
if ( *a1 )
{
do
{
for ( i = 0; i != 8; ++i )
{
v4 = nedgz_tile_getij((__int64)v1, v2, i);
if ( v4 )
nedgz_subtile_delete((void **)&v4);
}
++v2;
}
while ( v2 != 8 );
free(v1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
void *v1; // r12
int v2; // ebp
int i; // ebx
__int64 v4; // [rsp+8h] [rbp-30h] BYREF

if ( !a1 )
_assert_fail("_self", "nedgz_tile.c", 0x70u, "nedgz_tile_delete");
v1 = *a1;
v2 = 0;
if ( *a1 )
{
do
{
for ( i = 0; i != 8; ++i )
{
v4 = func3((__int64)v1, v2, i);
if ( v4 )
func2((void **)&v4);
}
++v2;
}
while ( v2 != 8 );
free(v1);
*a1 = 0LL;
}
}

original_code:
void nedgz_tile_delete(nedgz_tile_t** _self)
{
 ((void) sizeof ((_self) ? 1 : 0), __extension__ ({ if (_self) ; else __assert_fail ("_self", "nedgz_tile.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 nedgz_tile_t* self = *_self;
 if(self)
 {
  ;
  int i;
  int j;
  for(i = 0; i < 8; ++i)
  {
   for(j = 0; j < 8; ++j)
   {
    nedgz_subtile_t* subtile = nedgz_tile_getij(self, i, j);
    if(subtile)
    {
     nedgz_subtile_delete(&subtile);
    }
   }
  }
  free(self);
  *_self = ((void *)0);
 }
}

canonical_original_code:
void nedgz_tile_delete(struct nedgz_tile_t **_self)
{
 ((void) sizeof ((_self) ? 1 : 0), __extension__ ({ if (_self) ; else __assert_fail ("_self", "nedgz_tile.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 struct nedgz_tile_t *self = *_self;
 if(self)
 {
  ;
  int i;
  int j;
  for(i = 0; i < 8; ++i)
  {
   for(j = 0; j < 8; ++j)
   {
    struct nedgz_subtile_t *subtile = nedgz_tile_getij(self, i, j);
    if(subtile)
    {
     nedgz_subtile_delete(&subtile);
    }
   }
  }
  free(self);
  *_self = ((void *)0);
 }
}

variable_types: struct nedgz_tile_t { int x; int y; int zoom; struct nedgz_subtile_t { short data[-1]; } *subtile[-1]; } **

user_defined_types: struct nedgz_tile_t { int x; int y; int zoom; struct nedgz_subtile_t *subtile[-1]; }


decompiled_code:
__int64 __fastcall nedgz_tile_export(unsigned int *a1, const char *a2)
{
int v2; // er14
__int16 v3; // bp
int i; // ebx
__int64 result; // rax
__int64 v6; // rax
__int64 v7; // rbp
unsigned __int8 v8; // r13
unsigned __int8 j; // al
__int64 v10; // rbx
int v11; // er13
int v12; // eax
unsigned __int8 v13; // [rsp+Ch] [rbp-22Ch] BYREF
char v14; // [rsp+Dh] [rbp-22Bh] BYREF
__int16 v15; // [rsp+Eh] [rbp-22Ah] BYREF
char s[256]; // [rsp+10h] [rbp-228h] BYREF
char v17[296]; // [rsp+110h] [rbp-128h] BYREF

if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0xF8u, "nedgz_tile_export");
if ( !a2 )
_assert_fail("base", "nedgz_tile.c", 0xF9u, "nedgz_tile_export");
v2 = 0;
snprintf(s, 0x100uLL, "%s/%i", a2, a1[2]);
v3 = 0;
snprintf(v17, 0x100uLL, "%s/%i_%i.nedgz", s, *a1, a1[1]);
v13 = 0;
v15 = 0;
do
{
v14 = 0;
for ( i = 0; i != 8; v14 = i )
{
if ( nedgz_tile_getij((__int64)a1, v2, i) )
v15 = ++v3;
++i;
}
v13 = ++v2;
}
while ( v2 != 8 );
result = 1LL;
if ( v3 )
{
if ( mkdir(a2, 0x1FDu) == -1 && *_errno_location() != 17 )
{
nedgz_log("nedgz_tile_export", 287LL, 3LL, "nedgz", "mkdir %s failed", a2);
result = 0LL;
}
else if ( mkdir(s, 0x1FDu) == -1 && *_errno_location() != 17 )
{
nedgz_log("nedgz_tile_export", 299LL, 3LL, "nedgz", "mkdir %s failed", s);
result = 0LL;
}
else
{
v6 = gzopen(v17, "wb");
v7 = v6;
if ( v6 )
{
if ( (unsigned int)gzwrite(v6, &v15, 2LL) == 2 )
{
v13 = 0;
v8 = 0;
while ( 2 )
{
v14 = 0;
for ( j = 0; j <= 7u; v14 = j )
{
v10 = nedgz_tile_getij((__int64)a1, v8, j);
if ( v10 )
{
if ( (unsigned int)gzwrite(v7, &v13, 1LL) == 1 )
{
if ( (unsigned int)gzwrite(v7, &v14, 1LL) == 1 )
{
v11 = 2048;
while ( 1 )
{
v12 = gzwrite(v7, v10, (unsigned int)v11);
if ( !v12 )
break;
v11 -= v12;
v10 += v12;
if ( v11 <= 0 )
{
v8 = v13;
goto LABEL_19;
}
}
nedgz_log("nedgz_tile_export", 346LL, 3LL, "nedgz", "failed %s", v17);
}
else
{
nedgz_log("nedgz_tile_export", 335LL, 3LL, "nedgz", "failed %s", v17);
}
}
else
{
nedgz_log("nedgz_tile_export", 330LL, 3LL, "nedgz", "failed %s", v17);
}
goto LABEL_23;
}
LABEL_19:
j = v14 + 1;
}
v13 = ++v8;
if ( v8 <= 7u )
continue;
break;
}
gzclose(v7);
result = 1LL;
}
else
{
nedgz_log("nedgz_tile_export", 313LL, 3LL, "nedgz", "failed to write count");
LABEL_23:
gzclose(v7);
result = 0LL;
}
}
else
{
nedgz_log("nedgz_tile_export", 307LL, 3LL, "nedgz", "gzopen failed");
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, const char *a2)
{
int v2; // er14
__int16 v3; // bp
int i; // ebx
__int64 result; // rax
__int64 v6; // rax
__int64 v7; // rbp
unsigned __int8 v8; // r13
unsigned __int8 j; // al
__int64 v10; // rbx
int v11; // er13
int v12; // eax
unsigned __int8 v13; // [rsp+Ch] [rbp-22Ch] BYREF
char v14; // [rsp+Dh] [rbp-22Bh] BYREF
__int16 v15; // [rsp+Eh] [rbp-22Ah] BYREF
char s[256]; // [rsp+10h] [rbp-228h] BYREF
char v17[296]; // [rsp+110h] [rbp-128h] BYREF

if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0xF8u, "nedgz_tile_export");
if ( !a2 )
_assert_fail("base", "nedgz_tile.c", 0xF9u, "nedgz_tile_export");
v2 = 0;
snprintf(s, 0x100uLL, "%s/%i", a2, a1[2]);
v3 = 0;
snprintf(v17, 0x100uLL, "%s/%i_%i.nedgz", s, *a1, a1[1]);
v13 = 0;
v15 = 0;
do
{
v14 = 0;
for ( i = 0; i != 8; v14 = i )
{
if ( func3((__int64)a1, v2, i) )
v15 = ++v3;
++i;
}
v13 = ++v2;
}
while ( v2 != 8 );
result = 1LL;
if ( v3 )
{
if ( mkdir(a2, 0x1FDu) == -1 && *_errno_location() != 17 )
{
nedgz_log("nedgz_tile_export", 287LL, 3LL, "nedgz", "mkdir %s failed", a2);
result = 0LL;
}
else if ( mkdir(s, 0x1FDu) == -1 && *_errno_location() != 17 )
{
nedgz_log("nedgz_tile_export", 299LL, 3LL, "nedgz", "mkdir %s failed", s);
result = 0LL;
}
else
{
v6 = gzopen(v17, "wb");
v7 = v6;
if ( v6 )
{
if ( (unsigned int)gzwrite(v6, &v15, 2LL) == 2 )
{
v13 = 0;
v8 = 0;
while ( 2 )
{
v14 = 0;
for ( j = 0; j <= 7u; v14 = j )
{
v10 = func3((__int64)a1, v8, j);
if ( v10 )
{
if ( (unsigned int)gzwrite(v7, &v13, 1LL) == 1 )
{
if ( (unsigned int)gzwrite(v7, &v14, 1LL) == 1 )
{
v11 = 2048;
while ( 1 )
{
v12 = gzwrite(v7, v10, (unsigned int)v11);
if ( !v12 )
break;
v11 -= v12;
v10 += v12;
if ( v11 <= 0 )
{
v8 = v13;
goto LABEL_19;
}
}
nedgz_log("nedgz_tile_export", 346LL, 3LL, "nedgz", "failed %s", v17);
}
else
{
nedgz_log("nedgz_tile_export", 335LL, 3LL, "nedgz", "failed %s", v17);
}
}
else
{
nedgz_log("nedgz_tile_export", 330LL, 3LL, "nedgz", "failed %s", v17);
}
goto LABEL_23;
}
LABEL_19:
j = v14 + 1;
}
v13 = ++v8;
if ( v8 <= 7u )
continue;
break;
}
gzclose(v7);
result = 1LL;
}
else
{
nedgz_log("nedgz_tile_export", 313LL, 3LL, "nedgz", "failed to write count");
LABEL_23:
gzclose(v7);
result = 0LL;
}
}
else
{
nedgz_log("nedgz_tile_export", 307LL, 3LL, "nedgz", "gzopen failed");
result = 0LL;
}
}
}
return result;
}

original_code:
int nedgz_tile_export(nedgz_tile_t* self, const char* base)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((base) ? 1 : 0), __extension__ ({ if (base) ; else __assert_fail ("base", "nedgz_tile.c", 249, __extension__ __PRETTY_FUNCTION__); }));
 char dname[256];
 char fname[256];
 snprintf(dname, 256, "%s/%i", base, self->zoom);
 snprintf(fname, 256, "%s/%i_%i.nedgz", dname, self->x, self->y);
 ;
 short count = 0;
 unsigned char i;
 unsigned char j;
 for(i = 0; i < 8; ++i)
 {
  for(j = 0; j < 8; ++j)
  {
   if(nedgz_tile_getij(self, (int) i, (int) j))
   {
    ++count;
   }
  }
 }
 if(count == 0)
 {
  return 1;
 }
 if(mkdir(base, (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) == -1)
 {
  if((*__errno_location ()) == 17)
  {
  }
  else
  {
   (nedgz_log(__func__, 287, 3, "nedgz", "mkdir %s failed", base));
   return 0;
  }
 }
 if(mkdir(dname, (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) == -1)
 {
  if((*__errno_location ()) == 17)
  {
  }
  else
  {
   (nedgz_log(__func__, 299, 3, "nedgz", "mkdir %s failed", dname));
   return 0;
  }
 }
 gzFile f = gzopen(fname, "wb");
 if(f == ((void *)0))
 {
  (nedgz_log(__func__, 307, 3, "nedgz", "gzopen failed"));
  return 0;
 }
 if(gzwrite(f, (const void*) &count, sizeof(short)) != sizeof(short))
 {
  (nedgz_log(__func__, 313, 3, "nedgz", "failed to write count"));
  goto fail_count;
 }
 for(i = 0; i < 8; ++i)
 {
  for(j = 0; j < 8; ++j)
  {
   nedgz_subtile_t* subtile = nedgz_tile_getij(self, (int) i, (int) j);
   if(subtile == ((void *)0))
   {
    continue;
   }
   if(gzwrite(f, (const void*) &i, sizeof(unsigned char)) != sizeof(unsigned char))
   {
    (nedgz_log(__func__, 330, 3, "nedgz", "failed %s", fname));
    goto fail_i;
   }
   if(gzwrite(f, (const void*) &j, sizeof(unsigned char)) != sizeof(unsigned char))
   {
    (nedgz_log(__func__, 335, 3, "nedgz", "failed %s", fname));
    goto fail_j;
   }
   int bytes = 32*32*sizeof(short);
   unsigned char* data = (unsigned char*) subtile->data;
   while(bytes > 0)
   {
    int bytes_written = gzwrite(f, (const void*) data, bytes);
    if(bytes_written == 0)
    {
     (nedgz_log(__func__, 346, 3, "nedgz", "failed %s", fname));
     goto fail_data;
    }
    data += bytes_written;
    bytes -= bytes_written;
   }
  }
 }
 gzclose(f);
 return 1;
 fail_data:
 fail_j:
 fail_i:
 fail_count:
  gzclose(f);
 return 0;
}

canonical_original_code:
int nedgz_tile_export(struct nedgz_tile_t *self, char *base)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((base) ? 1 : 0), __extension__ ({ if (base) ; else __assert_fail ("base", "nedgz_tile.c", 249, __extension__ __PRETTY_FUNCTION__); }));
 char dname[256];
 char fname[256];
 snprintf(dname, 256, "%s/%i", base, self->zoom);
 snprintf(fname, 256, "%s/%i_%i.nedgz", dname, self->x, self->y);
 ;
 short count = 0;
 unsigned char i;
 unsigned char j;
 for(i = 0; i < 8; ++i)
 {
  for(j = 0; j < 8; ++j)
  {
   if(nedgz_tile_getij(self, (int) i, (int) j))
   {
    ++count;
   }
  }
 }
 if(count == 0)
 {
  return 1;
 }
 if(mkdir(base, (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) == -1)
 {
  if((*__errno_location ()) == 17)
  {
  }
  else
  {
   (nedgz_log(__func__, 287, 3, "nedgz", "mkdir %s failed", base));
   return 0;
  }
 }
 if(mkdir(dname, (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) == -1)
 {
  if((*__errno_location ()) == 17)
  {
  }
  else
  {
   (nedgz_log(__func__, 299, 3, "nedgz", "mkdir %s failed", dname));
   return 0;
  }
 }
 struct gzFile_s *f = gzopen(fname, "wb");
 if(f == ((void *)0))
 {
  (nedgz_log(__func__, 307, 3, "nedgz", "gzopen failed"));
  return 0;
 }
 if(gzwrite(f, (void *) &count, sizeof(short)) != sizeof(short))
 {
  (nedgz_log(__func__, 313, 3, "nedgz", "failed to write count"));
  goto fail_count;
 }
 for(i = 0; i < 8; ++i)
 {
  for(j = 0; j < 8; ++j)
  {
   struct nedgz_subtile_t *subtile = nedgz_tile_getij(self, (int) i, (int) j);
   if(subtile == ((void *)0))
   {
    continue;
   }
   if(gzwrite(f, (void *) &i, sizeof(unsigned char)) != sizeof(unsigned char))
   {
    (nedgz_log(__func__, 330, 3, "nedgz", "failed %s", fname));
    goto fail_i;
   }
   if(gzwrite(f, (void *) &j, sizeof(unsigned char)) != sizeof(unsigned char))
   {
    (nedgz_log(__func__, 335, 3, "nedgz", "failed %s", fname));
    goto fail_j;
   }
   int bytes = 32*32*sizeof(short);
   unsigned char *data = (unsigned char*) subtile->data;
   while(bytes > 0)
   {
    int bytes_written = gzwrite(f, (const void*) data, bytes);
    if(bytes_written == 0)
    {
     (nedgz_log(__func__, 346, 3, "nedgz", "failed %s", fname));
     goto fail_data;
    }
    data += bytes_written;
    bytes -= bytes_written;
   }
  }
 }
 gzclose(f);
 return 1;
 fail_data:
 fail_j:
 fail_i:
 fail_count:
  gzclose(f);
 return 0;
}

variable_types: struct nedgz_tile_t { int x; int y; int zoom; struct nedgz_subtile_t { short data[-1]; } *subtile[-1]; } *

variable_types:
base
char *

variable_types:
dname
char [256]

variable_types:
fname
char [256]

variable_types: count short

variable_types:
i
unsigned char

variable_types:
j
unsigned char

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *

variable_types: bytes int

variable_types:
data
unsigned char *


decompiled_code:
__int64 __fastcall nedgz_tile_set(__int64 a1, int a2, int a3, int a4, int a5, __int16 a6)
{
__int64 v11; // rdi

if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x182u, "nedgz_tile_set");
if ( a2 < 0 )
_assert_fail("i >= 0", "nedgz_tile.c", 0x183u, "nedgz_tile_set");
if ( a2 > 7 )
_assert_fail("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x184u, "nedgz_tile_set");
if ( a3 < 0 )
_assert_fail("j >= 0", "nedgz_tile.c", 0x185u, "nedgz_tile_set");
if ( a3 > 7 )
_assert_fail("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x186u, "nedgz_tile_set");
if ( a4 < 0 )
_assert_fail("m >= 0", "nedgz_tile.c", 0x187u, "nedgz_tile_set");
if ( a4 > 31 )
_assert_fail("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x188u, "nedgz_tile_set");
if ( a5 < 0 )
_assert_fail("n >= 0", "nedgz_tile.c", 0x189u, "nedgz_tile_set");
if ( a5 > 31 )
_assert_fail("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x18Au, "nedgz_tile_set");
v11 = nedgz_tile_getij(a1, a2, a3);
if ( v11 )
goto LABEL_11;
v11 = (__int64)nedgz_subtile_new();
if ( v11 )
{
*(_QWORD *)(a1 + 8LL * (a3 + 8 * a2) + 16) = v11;
LABEL_11:
nedgz_subtile_set(v11, a4, a5, a6);
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3, int a4, int a5, __int16 a6)
{
__int64 v11; // rdi

if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x182u, "nedgz_tile_set");
if ( a2 < 0 )
_assert_fail("i >= 0", "nedgz_tile.c", 0x183u, "nedgz_tile_set");
if ( a2 > 7 )
_assert_fail("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x184u, "nedgz_tile_set");
if ( a3 < 0 )
_assert_fail("j >= 0", "nedgz_tile.c", 0x185u, "nedgz_tile_set");
if ( a3 > 7 )
_assert_fail("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x186u, "nedgz_tile_set");
if ( a4 < 0 )
_assert_fail("m >= 0", "nedgz_tile.c", 0x187u, "nedgz_tile_set");
if ( a4 > 31 )
_assert_fail("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x188u, "nedgz_tile_set");
if ( a5 < 0 )
_assert_fail("n >= 0", "nedgz_tile.c", 0x189u, "nedgz_tile_set");
if ( a5 > 31 )
_assert_fail("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x18Au, "nedgz_tile_set");
v11 = func3(a1, a2, a3);
if ( v11 )
goto LABEL_11;
v11 = (__int64)func1();
if ( v11 )
{
*(_QWORD *)(a1 + 8LL * (a3 + 8 * a2) + 16) = v11;
LABEL_11:
func0(v11, a4, a5, a6);
return 1LL;
}
return 0LL;
}

original_code:
int nedgz_tile_set(nedgz_tile_t* self,
                   int i, int j,
                   int m, int n,
                   short h)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 386, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i >= 0) ? 1 : 0), __extension__ ({ if (i >= 0) ; else __assert_fail ("i >= 0", "nedgz_tile.c", 387, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i < 8) ? 1 : 0), __extension__ ({ if (i < 8) ; else __assert_fail ("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 388, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j >= 0) ? 1 : 0), __extension__ ({ if (j >= 0) ; else __assert_fail ("j >= 0", "nedgz_tile.c", 389, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j < 8) ? 1 : 0), __extension__ ({ if (j < 8) ; else __assert_fail ("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 390, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m >= 0) ? 1 : 0), __extension__ ({ if (m >= 0) ; else __assert_fail ("m >= 0", "nedgz_tile.c", 391, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m < 32) ? 1 : 0), __extension__ ({ if (m < 32) ; else __assert_fail ("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 392, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "nedgz_tile.c", 393, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n < 32) ? 1 : 0), __extension__ ({ if (n < 32) ; else __assert_fail ("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 394, __extension__ __PRETTY_FUNCTION__); }));
 ;
 nedgz_subtile_t* subtile = nedgz_tile_getij(self, i, j);
 if(subtile == ((void *)0))
 {
  subtile = nedgz_subtile_new();
  if(subtile == ((void *)0))
  {
   return 0;
  }
  self->subtile[i*8 + j] = subtile;
 }
 nedgz_subtile_set(subtile, m, n, h);
 return 1;
}

canonical_original_code:
int nedgz_tile_set(struct nedgz_tile_t *self, int i, int j, int m, int n, short h)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 386, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i >= 0) ? 1 : 0), __extension__ ({ if (i >= 0) ; else __assert_fail ("i >= 0", "nedgz_tile.c", 387, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i < 8) ? 1 : 0), __extension__ ({ if (i < 8) ; else __assert_fail ("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 388, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j >= 0) ? 1 : 0), __extension__ ({ if (j >= 0) ; else __assert_fail ("j >= 0", "nedgz_tile.c", 389, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j < 8) ? 1 : 0), __extension__ ({ if (j < 8) ; else __assert_fail ("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 390, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m >= 0) ? 1 : 0), __extension__ ({ if (m >= 0) ; else __assert_fail ("m >= 0", "nedgz_tile.c", 391, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m < 32) ? 1 : 0), __extension__ ({ if (m < 32) ; else __assert_fail ("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 392, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "nedgz_tile.c", 393, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n < 32) ? 1 : 0), __extension__ ({ if (n < 32) ; else __assert_fail ("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 394, __extension__ __PRETTY_FUNCTION__); }));
 ;
 struct nedgz_subtile_t *subtile = nedgz_tile_getij(self, i, j);
 if(subtile == ((void *)0))
 {
  subtile = nedgz_subtile_new();
  if(subtile == ((void *)0))
  {
   return 0;
  }
  self->subtile[i*8 + j] = subtile;
 }
 nedgz_subtile_set(subtile, m, n, h);
 return 1;
}

variable_types: m int

variable_types: n int

variable_types: struct nedgz_subtile_t { short data[-1]; } *


decompiled_code:
__int64 __fastcall nedgz_tile_coord(unsigned int *a1, int a2, int a3, int a4, __int64 a5, __int64 a6, __int64 a7)
{
if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x1A3u, "nedgz_tile_coord");
if ( a2 < 0 )
_assert_fail("i >= 0", "nedgz_tile.c", 0x1A4u, "nedgz_tile_coord");
if ( a2 > 7 )
_assert_fail("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x1A5u, "nedgz_tile_coord");
if ( a3 < 0 )
_assert_fail("j >= 0", "nedgz_tile.c", 0x1A6u, "nedgz_tile_coord");
if ( a3 > 7 )
_assert_fail("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x1A7u, "nedgz_tile_coord");
if ( a4 < 0 )
_assert_fail("m >= 0", "nedgz_tile.c", 0x1A8u, "nedgz_tile_coord");
if ( a4 > 31 )
_assert_fail("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x1A9u, "nedgz_tile_coord");
if ( (int)a5 < 0 )
_assert_fail("n >= 0", "nedgz_tile.c", 0x1AAu, "nedgz_tile_coord");
if ( (int)a5 > 31 )
_assert_fail("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x1ABu, "nedgz_tile_coord");
return nedgz_subtile2coord(*a1, a1[1], a1[2], (unsigned int)a2, (unsigned int)a3, (unsigned int)a4, a5, a6, a7);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, int a2, int a3, int a4, __int64 a5, __int64 a6, __int64 a7)
{
if ( !a1 )
_assert_fail("self", "nedgz_tile.c", 0x1A3u, "nedgz_tile_coord");
if ( a2 < 0 )
_assert_fail("i >= 0", "nedgz_tile.c", 0x1A4u, "nedgz_tile_coord");
if ( a2 > 7 )
_assert_fail("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x1A5u, "nedgz_tile_coord");
if ( a3 < 0 )
_assert_fail("j >= 0", "nedgz_tile.c", 0x1A6u, "nedgz_tile_coord");
if ( a3 > 7 )
_assert_fail("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 0x1A7u, "nedgz_tile_coord");
if ( a4 < 0 )
_assert_fail("m >= 0", "nedgz_tile.c", 0x1A8u, "nedgz_tile_coord");
if ( a4 > 31 )
_assert_fail("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x1A9u, "nedgz_tile_coord");
if ( (int)a5 < 0 )
_assert_fail("n >= 0", "nedgz_tile.c", 0x1AAu, "nedgz_tile_coord");
if ( (int)a5 > 31 )
_assert_fail("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 0x1ABu, "nedgz_tile_coord");
return nedgz_subtile2coord(*a1, a1[1], a1[2], (unsigned int)a2, (unsigned int)a3, (unsigned int)a4, a5, a6, a7);
}

original_code:
void nedgz_tile_coord(nedgz_tile_t* self,
                      int i, int j,
                      int m, int n,
                      double* lat, double* lon)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 419, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i >= 0) ? 1 : 0), __extension__ ({ if (i >= 0) ; else __assert_fail ("i >= 0", "nedgz_tile.c", 420, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i < 8) ? 1 : 0), __extension__ ({ if (i < 8) ; else __assert_fail ("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 421, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j >= 0) ? 1 : 0), __extension__ ({ if (j >= 0) ; else __assert_fail ("j >= 0", "nedgz_tile.c", 422, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j < 8) ? 1 : 0), __extension__ ({ if (j < 8) ; else __assert_fail ("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 423, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m >= 0) ? 1 : 0), __extension__ ({ if (m >= 0) ; else __assert_fail ("m >= 0", "nedgz_tile.c", 424, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m < 32) ? 1 : 0), __extension__ ({ if (m < 32) ; else __assert_fail ("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 425, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "nedgz_tile.c", 426, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n < 32) ? 1 : 0), __extension__ ({ if (n < 32) ; else __assert_fail ("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 427, __extension__ __PRETTY_FUNCTION__); }));
 ;
 nedgz_subtile2coord(self->x, self->y, self->zoom,
                     i, j, m, n, lat, lon);
}

canonical_original_code:
void nedgz_tile_coord(struct nedgz_tile_t *self, int i, int j, int m, int n, double *lat, double *lon)
{
 ((void) sizeof ((self) ? 1 : 0), __extension__ ({ if (self) ; else __assert_fail ("self", "nedgz_tile.c", 419, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i >= 0) ? 1 : 0), __extension__ ({ if (i >= 0) ; else __assert_fail ("i >= 0", "nedgz_tile.c", 420, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((i < 8) ? 1 : 0), __extension__ ({ if (i < 8) ; else __assert_fail ("i < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 421, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j >= 0) ? 1 : 0), __extension__ ({ if (j >= 0) ; else __assert_fail ("j >= 0", "nedgz_tile.c", 422, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((j < 8) ? 1 : 0), __extension__ ({ if (j < 8) ; else __assert_fail ("j < NEDGZ_SUBTILE_COUNT", "nedgz_tile.c", 423, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m >= 0) ? 1 : 0), __extension__ ({ if (m >= 0) ; else __assert_fail ("m >= 0", "nedgz_tile.c", 424, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((m < 32) ? 1 : 0), __extension__ ({ if (m < 32) ; else __assert_fail ("m < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 425, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n >= 0) ? 1 : 0), __extension__ ({ if (n >= 0) ; else __assert_fail ("n >= 0", "nedgz_tile.c", 426, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((n < 32) ? 1 : 0), __extension__ ({ if (n < 32) ; else __assert_fail ("n < NEDGZ_SUBTILE_SIZE", "nedgz_tile.c", 427, __extension__ __PRETTY_FUNCTION__); }));
 ;
 nedgz_subtile2coord(self->x, self->y, self->zoom,
                     i, j, m, n, lat, lon);
}

variable_types: i int

variable_types:
lat
double *

variable_types:
lon
double *


decompiled_code:
_QWORD *nedgz_scene_new()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x30uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
v0[4] = 0LL;
*((_DWORD *)v0 + 10) = 0;
}
else
{
nedgz_log("nedgz_scene_new", 201LL, 3LL, "nedgz", "malloc failed");
}
return v1;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x30uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
v0[4] = 0LL;
*((_DWORD *)v0 + 10) = 0;
}
else
{
nedgz_log("nedgz_scene_new", 201LL, 3LL, "nedgz", "malloc failed");
}
return v1;
}

original_code:
nedgz_scene_t* nedgz_scene_new(void)
{
 ;
 nedgz_scene_t* self = (nedgz_scene_t*) malloc(sizeof(nedgz_scene_t));
 if(self == ((void *)0))
 {
  (nedgz_log(__func__, 201, 3, "nedgz", "malloc failed"));
  return ((void *)0);
 }
 self->tl = ((void *)0);
 self->tr = ((void *)0);
 self->bl = ((void *)0);
 self->br = ((void *)0);
 self->exists = 0;
 self->fsize = 0;
 self->min = 0;
 self->max = 0;
 return self;
}

canonical_original_code:
struct nedgz_scene_s *nedgz_scene_new()
{
 ;
 struct nedgz_scene_s *self = (nedgz_scene_t*) malloc(sizeof(nedgz_scene_t));
 if(self == ((void *)0))
 {
  (nedgz_log(__func__, 201, 3, "nedgz", "malloc failed"));
  return ((void *)0);
 }
 self->tl = ((void *)0);
 self->tr = ((void *)0);
 self->bl = ((void *)0);
 self->br = ((void *)0);
 self->exists = 0;
 self->fsize = 0;
 self->min = 0;
 self->max = 0;
 return self;
}

variable_types: struct nedgz_scene_s { struct nedgz_scene_s *tl; struct nedgz_scene_s *tr; struct nedgz_scene_s *bl; struct nedgz_scene_s *br; int exists; int fsize; short min; short max; } *


decompiled_code:
void __fastcall nedgz_scene_delete(_QWORD *a1)
{
char *v1; // rbp

if ( !a1 )
_assert_fail("_self", "nedgz_scene.c", 0xDBu, "nedgz_scene_delete");
v1 = (char *)*a1;
if ( *a1 )
{
nedgz_scene_delete(*a1);
nedgz_scene_delete(v1 + 8);
nedgz_scene_delete(v1 + 16);
nedgz_scene_delete(v1 + 24);
free(v1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
char *v1; // rbp

if ( !a1 )
_assert_fail("_self", "nedgz_scene.c", 0xDBu, "nedgz_scene_delete");
v1 = (char *)*a1;
if ( *a1 )
{
func3(*a1);
func3(v1 + 8);
func3(v1 + 16);
func3(v1 + 24);
free(v1);
*a1 = 0LL;
}
}

original_code:
void nedgz_scene_delete(nedgz_scene_t** _self)
{
 ((void) sizeof ((_self) ? 1 : 0), __extension__ ({ if (_self) ; else __assert_fail ("_self", "nedgz_scene.c", 219, __extension__ __PRETTY_FUNCTION__); }));
 nedgz_scene_t* self = *_self;
 if(self)
 {
  ;
  nedgz_scene_delete(&self->tl);
  nedgz_scene_delete(&self->tr);
  nedgz_scene_delete(&self->bl);
  nedgz_scene_delete(&self->br);
  free(self);
  *_self = ((void *)0);
 }
}

canonical_original_code:
void nedgz_scene_delete(struct nedgz_scene_s **_self)
{
 ((void) sizeof ((_self) ? 1 : 0), __extension__ ({ if (_self) ; else __assert_fail ("_self", "nedgz_scene.c", 219, __extension__ __PRETTY_FUNCTION__); }));
 struct nedgz_scene_s *self = *_self;
 if(self)
 {
  ;
  nedgz_scene_delete(&self->tl);
  nedgz_scene_delete(&self->tr);
  nedgz_scene_delete(&self->bl);
  nedgz_scene_delete(&self->br);
  free(self);
  *_self = ((void *)0);
 }
}

variable_types: struct nedgz_scene_s { struct nedgz_scene_s *tl; struct nedgz_scene_s *tr; struct nedgz_scene_s *bl; struct nedgz_scene_s *br; int exists; int fsize; short min; short max; } **


original_code:
void nedgz_tile2coord(float x, float y, int zoom, double* lat, double* lon)
{
 ((void) sizeof ((lat) ? 1 : 0), __extension__ ({ if (lat) ; else __assert_fail ("lat", "nedgz_util.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((lon) ? 1 : 0), __extension__ ({ if (lon) ; else __assert_fail ("lon", "nedgz_util.c", 36, __extension__ __PRETTY_FUNCTION__); }));
 ;
 double worldu = 8*x/pow(2.0, (double) zoom);
 double worldv = 8*y/pow(2.0, (double) zoom);
 double cartx = 2.0*3.14159265358979323846*worldu;
 double carty = 2.0*3.14159265358979323846*worldv;
 double mercx = cartx - 3.14159265358979323846;
 double mercy = 3.14159265358979323846 - carty;
 double rad_lon = mercx;
 double rad_lat = 2.0*atan(exp(mercy)) - 3.14159265358979323846/2.0;
 *lat = rad_lat/(3.14159265358979323846/180.0);
 *lon = rad_lon/(3.14159265358979323846/180.0);
}

canonical_original_code:
void nedgz_tile2coord(float x, float y, int zoom, double *lat, double *lon)
{
 ((void) sizeof ((lat) ? 1 : 0), __extension__ ({ if (lat) ; else __assert_fail ("lat", "nedgz_util.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((lon) ? 1 : 0), __extension__ ({ if (lon) ; else __assert_fail ("lon", "nedgz_util.c", 36, __extension__ __PRETTY_FUNCTION__); }));
 ;
 double worldu = 8*x/pow(2.0, (double) zoom);
 double worldv = 8*y/pow(2.0, (double) zoom);
 double cartx = 2.0*3.14159265358979323846*worldu;
 double carty = 2.0*3.14159265358979323846*worldv;
 double mercx = cartx - 3.14159265358979323846;
 double mercy = 3.14159265358979323846 - carty;
 double rad_lon = mercx;
 double rad_lat = 2.0*atan(exp(mercy)) - 3.14159265358979323846/2.0;
 *lat = rad_lat/(3.14159265358979323846/180.0);
 *lon = rad_lon/(3.14159265358979323846/180.0);
}

variable_types: x float

variable_types: y float

variable_types: zoom int

variable_types: worldu double

variable_types: worldv double

variable_types: cartx double

variable_types: carty double

variable_types: mercx double

variable_types: mercy double


decompiled_code:
void __fastcall nedgz_subtile2coord(int a1, int a2, int a3, int a4, int a5, int a6, int a7, double *a8, double *a9)
{
if ( !a8 )
_assert_fail("lat", "nedgz_util.c", 0x37u, "nedgz_subtile2coord");
if ( !a9 )
_assert_fail("lon", "nedgz_util.c", 0x38u, "nedgz_subtile2coord");
nedgz_tile2coord(
a3,
a8,
a9,
(float)((float)((float)((float)a7 / 31.0) + (float)a5) * 0.125) + (float)a1,
(float)((float)((float)((float)a6 / 31.0) + (float)a4) * 0.125) + (float)a2);
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2, int a3, int a4, int a5, int a6, int a7, double *a8, double *a9)
{
if ( !a8 )
_assert_fail("lat", "nedgz_util.c", 0x37u, "nedgz_subtile2coord");
if ( !a9 )
_assert_fail("lon", "nedgz_util.c", 0x38u, "nedgz_subtile2coord");
func0(
a3,
a8,
a9,
(float)((float)((float)((float)a7 / 31.0) + (float)a5) * 0.125) + (float)a1,
(float)((float)((float)((float)a6 / 31.0) + (float)a4) * 0.125) + (float)a2);
}

original_code:
void nedgz_subtile2coord(int x, int y, int zoom,
                         int i, int j, int m, int n,
                         double* lat, double* lon)
{
 ((void) sizeof ((lat) ? 1 : 0), __extension__ ({ if (lat) ; else __assert_fail ("lat", "nedgz_util.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((lon) ? 1 : 0), __extension__ ({ if (lon) ; else __assert_fail ("lon", "nedgz_util.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ;
 float s = (float) 32;
 float c = (float) 8;
 float xx = (float) x;
 float yy = (float) y;
 float jj = (float) j;
 float ii = (float) i;
 float nn = (float) n/(s - 1.0f);
 float mm = (float) m/(s - 1.0f);
 nedgz_tile2coord(xx + (jj + nn)/c, yy + (ii + mm)/c,
                  zoom, lat, lon);
}

canonical_original_code:
void nedgz_subtile2coord(int x, int y, int zoom, int i, int j, int m, int n, double *lat, double *lon)
{
 ((void) sizeof ((lat) ? 1 : 0), __extension__ ({ if (lat) ; else __assert_fail ("lat", "nedgz_util.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((lon) ? 1 : 0), __extension__ ({ if (lon) ; else __assert_fail ("lon", "nedgz_util.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ;
 float s = (float) 32;
 float c = (float) 8;
 float xx = (float) x;
 float yy = (float) y;
 float jj = (float) j;
 float ii = (float) i;
 float nn = (float) n/(s - 1.0f);
 float mm = (float) m/(s - 1.0f);
 nedgz_tile2coord(xx + (jj + nn)/c, yy + (ii + mm)/c,
                  zoom, lat, lon);
}

variable_types: x int

variable_types: y int

variable_types: j int

variable_types: m int

variable_types: s float

variable_types: c float

variable_types: xx float

variable_types: yy float

variable_types: jj float

variable_types: ii float

variable_types: nn float

variable_types: mm float


original_code:
void nedgz_coord2tile(double lat, double lon, int zoom, float* x, float* y)
{
 ((void) sizeof ((x) ? 1 : 0), __extension__ ({ if (x) ; else __assert_fail ("x", "nedgz_util.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((y) ? 1 : 0), __extension__ ({ if (y) ; else __assert_fail ("y", "nedgz_util.c", 76, __extension__ __PRETTY_FUNCTION__); }));
 ;
 double rad_lat = (double) lat*3.14159265358979323846/180.0;
 double rad_lon = (double) lon*3.14159265358979323846/180.0;
 double mercx = rad_lon;
 double mercy = log(tan(rad_lat) + 1.0/cos(rad_lat));
 double cartx = mercx + 3.14159265358979323846;
 double carty = 3.14159265358979323846 - mercy;
 double worldu = cartx/(2.0*3.14159265358979323846);
 double worldv = carty/(2.0*3.14159265358979323846);
 *x = (float) worldu*pow(2.0, (double) zoom)/8;
 *y = (float) worldv*pow(2.0, (double) zoom)/8;
}

canonical_original_code:
void nedgz_coord2tile(double lat, double lon, int zoom, float *x, float *y)
{
 ((void) sizeof ((x) ? 1 : 0), __extension__ ({ if (x) ; else __assert_fail ("x", "nedgz_util.c", 75, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((y) ? 1 : 0), __extension__ ({ if (y) ; else __assert_fail ("y", "nedgz_util.c", 76, __extension__ __PRETTY_FUNCTION__); }));
 ;
 double rad_lat = (double) lat*3.14159265358979323846/180.0;
 double rad_lon = (double) lon*3.14159265358979323846/180.0;
 double mercx = rad_lon;
 double mercy = log(tan(rad_lat) + 1.0/cos(rad_lat));
 double cartx = mercx + 3.14159265358979323846;
 double carty = 3.14159265358979323846 - mercy;
 double worldu = cartx/(2.0*3.14159265358979323846);
 double worldv = carty/(2.0*3.14159265358979323846);
 *x = (float) worldu*pow(2.0, (double) zoom)/8;
 *y = (float) worldv*pow(2.0, (double) zoom)/8;
}

variable_types: lat double

variable_types: lon double

variable_types: zoom int

variable_types:
x
float *

variable_types:
y
float *

variable_types: worldu double

variable_types: worldv double


decompiled_code:
float __fastcall nedgz_meters2feet(float a1)
{
return (float)(a1 * 5280.0) / 1609.344;
}

canonical_decompiled_code:
float __fastcall func3(float a1)
{
return (float)(a1 * 5280.0) / 1609.344;
}

original_code:
float nedgz_meters2feet(float m)
{
 return m*5280.0f/1609.344f;
}

variable_types: m float

return_type: float


decompiled_code:
float __fastcall nedgz_feet2meters(float a1)
{
return (float)(a1 * 1609.344) / 5280.0;
}

canonical_decompiled_code:
float __fastcall func4(float a1)
{
return (float)(a1 * 1609.344) / 5280.0;
}

original_code:
float nedgz_feet2meters(float f)
{
 return f*1609.344f/5280.0f;
}

variable_types: f float


decompiled_code:
int nedgz_log(const char *a1, unsigned int a2, int a3, const char *a4, const char *a5, ...)
{
size_t v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( !a1 )
_assert_fail("func", "nedgz_log.c", 0x21u, "nedgz_log");
if ( !a4 )
_assert_fail("tag", "nedgz_log.c", 0x22u, "nedgz_log");
if ( !a5 )
_assert_fail("fmt", "nedgz_log.c", 0x23u, "nedgz_log");
if ( a3 )
{
switch ( a3 )
{
case 1:
snprintf(s, 0x100uLL, "I/%s: %s@%i ", a4, a1, a2);
break;
case 2:
snprintf(s, 0x100uLL, "W/%s: %s@%i ", a4, a1, a2);
break;
case 3:
snprintf(s, 0x100uLL, "E/%s: %s@%i ", a4, a1, a2);
break;
}
}
else
{
snprintf(s, 0x100uLL, "D/%s: %s@%i ", a4, a1, a2);
}
v6 = strlen(s);
va_start(arg, a5);
vsnprintf(&s[v6], 256 - (int)v6, a5, arg);
puts(s);
return fflush(stdout);
}

canonical_decompiled_code:
int func0(const char *a1, unsigned int a2, int a3, const char *a4, const char *a5, ...)
{
size_t v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( !a1 )
_assert_fail("func", "nedgz_log.c", 0x21u, "nedgz_log");
if ( !a4 )
_assert_fail("tag", "nedgz_log.c", 0x22u, "nedgz_log");
if ( !a5 )
_assert_fail("fmt", "nedgz_log.c", 0x23u, "nedgz_log");
if ( a3 )
{
switch ( a3 )
{
case 1:
snprintf(s, 0x100uLL, "I/%s: %s@%i ", a4, a1, a2);
break;
case 2:
snprintf(s, 0x100uLL, "W/%s: %s@%i ", a4, a1, a2);
break;
case 3:
snprintf(s, 0x100uLL, "E/%s: %s@%i ", a4, a1, a2);
break;
}
}
else
{
snprintf(s, 0x100uLL, "D/%s: %s@%i ", a4, a1, a2);
}
v6 = strlen(s);
va_start(arg, a5);
vsnprintf(&s[v6], 256 - (int)v6, a5, arg);
puts(s);
return fflush(stdout);
}

original_code:
void nedgz_log(const char* func, int line, int type, const char* tag, const char* fmt, ...)
{
 ((void) sizeof ((func) ? 1 : 0), __extension__ ({ if (func) ; else __assert_fail ("func", "nedgz_log.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((tag) ? 1 : 0), __extension__ ({ if (tag) ; else __assert_fail ("tag", "nedgz_log.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fmt) ? 1 : 0), __extension__ ({ if (fmt) ; else __assert_fail ("fmt", "nedgz_log.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 char buf[256];
  if(type == 0)
   snprintf(buf, 256, "D/%s: %s@%i ", tag, func, line);
  else if(type == 1)
   snprintf(buf, 256, "I/%s: %s@%i ", tag, func, line);
  else if(type == 2)
   snprintf(buf, 256, "W/%s: %s@%i ", tag, func, line);
  else if(type == 3)
   snprintf(buf, 256, "E/%s: %s@%i ", tag, func, line);
 int size = (int) strlen(buf);
 if(size < 256)
 {
  va_list argptr;
  __builtin_va_start(argptr,fmt);
  vsnprintf(&buf[size], 256 - size, fmt, argptr);
  __builtin_va_end(argptr);
 }
  printf("%s\n", buf);
  fflush(stdout);
}

canonical_original_code:
void nedgz_log(char *func, int line, int type, char *tag, char *fmt, ...)
{
 ((void) sizeof ((func) ? 1 : 0), __extension__ ({ if (func) ; else __assert_fail ("func", "nedgz_log.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((tag) ? 1 : 0), __extension__ ({ if (tag) ; else __assert_fail ("tag", "nedgz_log.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fmt) ? 1 : 0), __extension__ ({ if (fmt) ; else __assert_fail ("fmt", "nedgz_log.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 char buf[256];
  if(type == 0)
   snprintf(buf, 256, "D/%s: %s@%i ", tag, func, line);
  else if(type == 1)
   snprintf(buf, 256, "I/%s: %s@%i ", tag, func, line);
  else if(type == 2)
   snprintf(buf, 256, "W/%s: %s@%i ", tag, func, line);
  else if(type == 3)
   snprintf(buf, 256, "E/%s: %s@%i ", tag, func, line);
 int size = (int) strlen(buf);
 if(size < 256)
 {
  __builtin_va_list argptr;
  __builtin_va_start(argptr,fmt);
  vsnprintf(&buf[size], 256 - size, fmt, argptr);
  __builtin_va_end(argptr);
 }
  printf("%s\n", buf);
  fflush(stdout);
}

variable_types:
func
char *

variable_types: line int

variable_types: type int

variable_types:
tag
char *

variable_types:
fmt
char *

variable_types:
buf
char [256]

variable_types: size int


repo: jeffboody/osm-style

decompiled_code:
int osm_log(const char *a1, unsigned int a2, int a3, const char *a4, const char *a5, ...)
{
size_t v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( !a1 )
_assert_fail("func", "osm_log.c", 0x21u, "osm_log");
if ( !a4 )
_assert_fail("tag", "osm_log.c", 0x22u, "osm_log");
if ( !a5 )
_assert_fail("fmt", "osm_log.c", 0x23u, "osm_log");
if ( a3 )
{
switch ( a3 )
{
case 1:
snprintf(s, 0x100uLL, "I/%s: %s@%i ", a4, a1, a2);
break;
case 2:
snprintf(s, 0x100uLL, "W/%s: %s@%i ", a4, a1, a2);
break;
case 3:
snprintf(s, 0x100uLL, "E/%s: %s@%i ", a4, a1, a2);
break;
}
}
else
{
snprintf(s, 0x100uLL, "D/%s: %s@%i ", a4, a1, a2);
}
v6 = strlen(s);
va_start(arg, a5);
vsnprintf(&s[v6], 256 - (int)v6, a5, arg);
puts(s);
return fflush(stdout);
}

canonical_decompiled_code:
int func0(const char *a1, unsigned int a2, int a3, const char *a4, const char *a5, ...)
{
size_t v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( !a1 )
_assert_fail("func", "osm_log.c", 0x21u, "osm_log");
if ( !a4 )
_assert_fail("tag", "osm_log.c", 0x22u, "osm_log");
if ( !a5 )
_assert_fail("fmt", "osm_log.c", 0x23u, "osm_log");
if ( a3 )
{
switch ( a3 )
{
case 1:
snprintf(s, 0x100uLL, "I/%s: %s@%i ", a4, a1, a2);
break;
case 2:
snprintf(s, 0x100uLL, "W/%s: %s@%i ", a4, a1, a2);
break;
case 3:
snprintf(s, 0x100uLL, "E/%s: %s@%i ", a4, a1, a2);
break;
}
}
else
{
snprintf(s, 0x100uLL, "D/%s: %s@%i ", a4, a1, a2);
}
v6 = strlen(s);
va_start(arg, a5);
vsnprintf(&s[v6], 256 - (int)v6, a5, arg);
puts(s);
return fflush(stdout);
}

original_code:
void osm_log(const char* func, int line, int type, const char* tag, const char* fmt, ...)
{
 ((void) sizeof ((func) ? 1 : 0), __extension__ ({ if (func) ; else __assert_fail ("func", "osm_log.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((tag) ? 1 : 0), __extension__ ({ if (tag) ; else __assert_fail ("tag", "osm_log.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fmt) ? 1 : 0), __extension__ ({ if (fmt) ; else __assert_fail ("fmt", "osm_log.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 char buf[256];
  if(type == 0)
   snprintf(buf, 256, "D/%s: %s@%i ", tag, func, line);
  else if(type == 1)
   snprintf(buf, 256, "I/%s: %s@%i ", tag, func, line);
  else if(type == 2)
   snprintf(buf, 256, "W/%s: %s@%i ", tag, func, line);
  else if(type == 3)
   snprintf(buf, 256, "E/%s: %s@%i ", tag, func, line);
 int size = (int) strlen(buf);
 if(size < 256)
 {
  va_list argptr;
  __builtin_va_start(argptr,fmt);
  vsnprintf(&buf[size], 256 - size, fmt, argptr);
  __builtin_va_end(argptr);
 }
  printf("%s\n", buf);
  fflush(stdout);
}

canonical_original_code:
void osm_log(char *func, int line, int type, char *tag, char *fmt, ...)
{
 ((void) sizeof ((func) ? 1 : 0), __extension__ ({ if (func) ; else __assert_fail ("func", "osm_log.c", 33, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((tag) ? 1 : 0), __extension__ ({ if (tag) ; else __assert_fail ("tag", "osm_log.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((fmt) ? 1 : 0), __extension__ ({ if (fmt) ; else __assert_fail ("fmt", "osm_log.c", 35, __extension__ __PRETTY_FUNCTION__); }));
 char buf[256];
  if(type == 0)
   snprintf(buf, 256, "D/%s: %s@%i ", tag, func, line);
  else if(type == 1)
   snprintf(buf, 256, "I/%s: %s@%i ", tag, func, line);
  else if(type == 2)
   snprintf(buf, 256, "W/%s: %s@%i ", tag, func, line);
  else if(type == 3)
   snprintf(buf, 256, "E/%s: %s@%i ", tag, func, line);
 int size = (int) strlen(buf);
 if(size < 256)
 {
  __builtin_va_list argptr;
  __builtin_va_start(argptr,fmt);
  vsnprintf(&buf[size], 256 - size, fmt, argptr);
  __builtin_va_end(argptr);
 }
  printf("%s\n", buf);
  fflush(stdout);
}


repo: jeffboody/texgz

decompiled_code:
double __fastcall pil_sinc_filter(double a1)
{
double result; // xmm0_8

if ( a1 == 0.0 )
result = *(double *)&LC0;
else
result = sin(3.141592653589793 * a1) / (3.141592653589793 * a1);
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
double result; // xmm0_8

if ( a1 == 0.0 )
result = *(double *)&LC0;
else
result = sin(3.141592653589793 * a1) / (3.141592653589793 * a1);
return result;
}

original_code:
static double
pil_sinc_filter(double x) {
    if (x == 0.0) {
        return 1.0;
    }
    x = x * 3.14159265358979323846;
    return sin(x) / x;
}

variable_types: x double

return_type: double


decompiled_code:
double __fastcall pil_lanczos3_filter(double a1)
{
double v2; // [rsp+0h] [rbp-18h]

if ( a1 < -3.0 || a1 >= 3.0 )
return 0.0;
v2 = pil_sinc_filter(a1);
return pil_sinc_filter(a1 / 3.0) * v2;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
double v2; // [rsp+0h] [rbp-18h]

if ( a1 < -3.0 || a1 >= 3.0 )
return 0.0;
v2 = func0(a1);
return func0(a1 / 3.0) * v2;
}

original_code:
double
pil_lanczos3_filter(double x) {
    if (-3.0 <= x && x < 3.0) {
        return pil_sinc_filter(x) * pil_sinc_filter(x / 3);
    }
    return 0.0;
}


decompiled_code:
void *__fastcall client_process_thread(void *a1)
{
client_process((unsigned int)client_fd);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
client_process((unsigned int)client_fd);
return 0LL;
}

original_code:
void*
client_process_thread()
{
    int fd = client_fd;
    client_process(fd);
    return ((void *)0);
}

canonical_original_code:
void *client_process_thread()
{
    int fd = client_fd;
    client_process(fd);
    return ((void *)0);
}

variable_types: fd int

return_type: void *


decompiled_code:
void __fastcall __noreturn client_process_thread2(void *a1)
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( !pthread_mutex_lock(&mutex) )
{
v1[0] = client_fd;
if ( (unsigned int)irIsEmpty(&ir) && pthread_cond_wait(&buff_not_empty_cond, &mutex) )
{
perror("buff_not_empty_cond error!!");
exit(1);
}
if ( pthread_mutex_unlock(&mutex) )
{
perror("Create WORKER mutex_unlock failed!!");
exit(1);
}
irRead(&ir, v1);
client_process(v1[0]);
if ( !(unsigned int)irIsFull(&ir) )
{
if ( pthread_cond_signal(&buff_not_full_cond) )
{
perror("MASTER buff not empty cond error!");
exit(1);
}
}
}
perror("Create WORKER mutex_lock failed!!");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( !pthread_mutex_lock(&mutex) )
{
v1[0] = client_fd;
if ( (unsigned int)irIsEmpty(&ir) && pthread_cond_wait(&buff_not_empty_cond, &mutex) )
{
perror("buff_not_empty_cond error!!");
exit(1);
}
if ( pthread_mutex_unlock(&mutex) )
{
perror("Create WORKER mutex_unlock failed!!");
exit(1);
}
irRead(&ir, v1);
client_process(v1[0]);
if ( !(unsigned int)irIsFull(&ir) )
{
if ( pthread_cond_signal(&buff_not_full_cond) )
{
perror("MASTER buff not empty cond error!");
exit(1);
}
}
}
perror("Create WORKER mutex_lock failed!!");
exit(1);
}

original_code:
void *client_process_thread2()
{
    while (1)
    {
        int status=pthread_mutex_lock(&mutex);
        if(status!=0)
        {
            perror("Create WORKER mutex_lock failed!!");
            exit(1);
        }
        int new_fd = client_fd;
        if (irIsEmpty(&ir))
        {
            status = pthread_cond_wait(&buff_not_empty_cond, &mutex);
            if(status!=0)
            {
                perror("buff_not_empty_cond error!!");
                exit(1);
            }
        }
        status=pthread_mutex_unlock(&mutex);
        if(status!=0)
        {
            perror("Create WORKER mutex_unlock failed!!");
            exit(1);
        }
    irRead(&ir, &new_fd);
    client_process(new_fd);
        if (!irIsFull(&ir))
        {
            status=pthread_cond_signal(&buff_not_full_cond);
            if(status!=0)
            {
                perror("MASTER buff not empty cond error!");
                exit(1);
            }
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *client_process_thread2()
{
    while (1)
    {
        int status = pthread_mutex_lock(&mutex);
        if(status!=0)
        {
            perror("Create WORKER mutex_lock failed!!");
            exit(1);
        }
        int new_fd = client_fd;
        if (irIsEmpty(&ir))
        {
            status = pthread_cond_wait(&buff_not_empty_cond, &mutex);
            if(status!=0)
            {
                perror("buff_not_empty_cond error!!");
                exit(1);
            }
        }
        status=pthread_mutex_unlock(&mutex);
        if(status!=0)
        {
            perror("Create WORKER mutex_unlock failed!!");
            exit(1);
        }
    irRead(&ir, &new_fd);
    client_process(new_fd);
        if (!irIsFull(&ir))
        {
            status=pthread_cond_signal(&buff_not_full_cond);
            if(status!=0)
            {
                perror("MASTER buff not empty cond error!");
                exit(1);
            }
        }
    }
    return ((void *)0);
}

variable_types: status int


decompiled_code:
__int64 server_single_request()
{
unsigned int v0; // eax

v0 = server_accept();
return client_process(v0);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax

v0 = server_accept();
return client_process(v0);
}

original_code:
void
server_single_request(int accept_fd)
{
 int fd;
        fd = server_accept(accept_fd);
        client_process(fd);
 return;
}


decompiled_code:
void __fastcall __noreturn server_thread_per_req(unsigned int a1)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

while ( 1 )
{
client_fd = server_accept(a1);
if ( pthread_create(newthread, 0LL, client_process_thread, 0LL) )
break;
if ( (unsigned int)rbIsFull(&rb) )
{
rbRead(&rb, newthread);
pthread_join(newthread[0], 0LL);
}
else
{
rbWrite(&rb, newthread);
}
}
puts("Main Thread creation failed");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(unsigned int a1)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

while ( 1 )
{
client_fd = server_accept(a1);
if ( pthread_create(newthread, 0LL, client_process_thread, 0LL) )
break;
if ( (unsigned int)rbIsFull(&rb) )
{
rbRead(&rb, newthread);
pthread_join(newthread[0], 0LL);
}
else
{
rbWrite(&rb, newthread);
}
}
puts("Main Thread creation failed");
exit(1);
}

original_code:
void
server_thread_per_req(int accept_fd)
{
     while (1)
        {
            client_fd = server_accept(accept_fd);
            int res_client;
            pthread_t client_thread;
            res_client = pthread_create(&client_thread, ((void *)0), client_process_thread, ((void *)0));
            if (res_client != 0)
            {
                printf("Main Thread creation failed\n");
                exit(1);
            }
            if (!rbIsFull(&rb))
            {
                rbWrite(&rb, &client_thread);
            }
            else
            {
                rbRead(&rb, &client_thread);
                res_client = pthread_join(client_thread, ((void *)0));
            }
        }
    rbFree(&rb);
    return;
}

canonical_original_code:
void server_thread_per_req(int accept_fd)
{
     while (1)
        {
            client_fd = server_accept(accept_fd);
            int res_client;
            unsigned long client_thread;
            res_client = pthread_create(&client_thread, ((void *)0), client_process_thread, ((void *)0));
            if (res_client != 0)
            {
                printf("Main Thread creation failed\n");
                exit(1);
            }
            if (!rbIsFull(&rb))
            {
                rbWrite(&rb, &client_thread);
            }
            else
            {
                rbRead(&rb, &client_thread);
                res_client = pthread_join(client_thread, ((void *)0));
            }
        }
    rbFree(&rb);
    return;
}


decompiled_code:
void __fastcall __noreturn server_thread_pool_bounded(unsigned int a1)
{
pthread_t _0[4]; // [rsp+0h] [rbp+0h] BYREF
char vars20; // [rsp+20h] [rbp+20h] BYREF

while ( !pthread_create(_0, 0LL, (void *(*)(void *))client_process_thread2, 0LL) )
{
if ( _0 == (pthread_t *)&vars20 )
{
while ( !pthread_mutex_lock(&mutex) )
{
if ( (unsigned int)irIsFull(&ir) && pthread_cond_wait(&buff_not_full_cond, &mutex) )
{
perror("buff_not_full_cond error!!");
exit(1);
}
if ( pthread_mutex_unlock(&mutex) )
{
perror("Create MASTER mutex_unlock failed!!");
exit(1);
}
client_fd = server_accept(a1);
irWrite(&ir, &client_fd);
if ( !(unsigned int)irIsEmpty(&ir) )
{
if ( pthread_cond_signal(&buff_not_empty_cond) )
{
perror("MASTER buff not empty cond error!");
exit(1);
}
}
}
perror("Create MASTER mutex_lock failed!!");
exit(1);
}
}
perror("WORKER Thread creation failed");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(unsigned int a1)
{
pthread_t _0[4]; // [rsp+0h] [rbp+0h] BYREF
char vars20; // [rsp+20h] [rbp+20h] BYREF

while ( !pthread_create(_0, 0LL, (void *(*)(void *))client_process_thread2, 0LL) )
{
if ( _0 == (pthread_t *)&vars20 )
{
while ( !pthread_mutex_lock(&mutex) )
{
if ( (unsigned int)irIsFull(&ir) && pthread_cond_wait(&buff_not_full_cond, &mutex) )
{
perror("buff_not_full_cond error!!");
exit(1);
}
if ( pthread_mutex_unlock(&mutex) )
{
perror("Create MASTER mutex_unlock failed!!");
exit(1);
}
client_fd = server_accept(a1);
irWrite(&ir, &client_fd);
if ( !(unsigned int)irIsEmpty(&ir) )
{
if ( pthread_cond_signal(&buff_not_empty_cond) )
{
perror("MASTER buff not empty cond error!");
exit(1);
}
}
}
perror("Create MASTER mutex_lock failed!!");
exit(1);
}
}
perror("WORKER Thread creation failed");
exit(1);
}

original_code:
void
server_thread_pool_bounded(int accept_fd)
{
    int count_thread = 0;
    int res_client;
    pthread_t client_thread[4];
    while (count_thread<4)
    {
        res_client = pthread_create(&client_thread[count_thread], ((void *)0), client_process_thread2, ((void *)0));
        if (res_client != 0)
        {
            perror("WORKER Thread creation failed");
            exit(1);
        }
        count_thread++;
    }
    while (1)
    {
        int status=pthread_mutex_lock(&mutex);
        if(status!=0)
        {
            perror("Create MASTER mutex_lock failed!!");
            exit(1);
        }
        if (irIsFull(&ir))
        {
            status = pthread_cond_wait(&buff_not_full_cond, &mutex);
            if(status!=0)
            {
                perror("buff_not_full_cond error!!");
                exit(1);
            }
        }
        status=pthread_mutex_unlock(&mutex);
        if(status!=0)
        {
            perror("Create MASTER mutex_unlock failed!!");
            exit(1);
        }
        client_fd = server_accept(accept_fd);
        irWrite(&ir, &client_fd);
        if (!irIsEmpty(&ir))
        {
            status=pthread_cond_signal(&buff_not_empty_cond);
            if(status!=0)
            {
                perror("MASTER buff not empty cond error!");
                exit(1);
            }
        }
    }
 return;
}

canonical_original_code:
void server_thread_pool_bounded(int accept_fd)
{
    int count_thread = 0;
    int res_client;
    unsigned long client_thread[4];
    while (count_thread<4)
    {
        res_client = pthread_create(&client_thread[count_thread], ((void *)0), client_process_thread2, ((void *)0));
        if (res_client != 0)
        {
            perror("WORKER Thread creation failed");
            exit(1);
        }
        count_thread++;
    }
    while (1)
    {
        int status = pthread_mutex_lock(&mutex);
        if(status!=0)
        {
            perror("Create MASTER mutex_lock failed!!");
            exit(1);
        }
        if (irIsFull(&ir))
        {
            status = pthread_cond_wait(&buff_not_full_cond, &mutex);
            if(status!=0)
            {
                perror("buff_not_full_cond error!!");
                exit(1);
            }
        }
        status=pthread_mutex_unlock(&mutex);
        if(status!=0)
        {
            perror("Create MASTER mutex_unlock failed!!");
            exit(1);
        }
        client_fd = server_accept(accept_fd);
        irWrite(&ir, &client_fd);
        if (!irIsEmpty(&ir))
        {
            status=pthread_cond_signal(&buff_not_empty_cond);
            if(status!=0)
            {
                perror("MASTER buff not empty cond error!");
                exit(1);
            }
        }
    }
 return;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
int v4; // ebp
int v5; // eax
int result; // eax

rbInit(&rb, 4LL, envp);
irInit(&ir, 4LL);
if ( argc == 3 )
{
v3 = atoi(argv[1]);
v4 = server_create((unsigned int)v3);
if ( v4 < 0 )
{
result = -1;
}
else
{
v5 = atoi(argv[2]);
if ( v5 )
{
if ( v5 >= 0 )
{
if ( v5 == 1 )
server_thread_per_req(v4);
if ( v5 == 2 )
server_thread_pool_bounded(v4);
}
}
else
{
server_single_request((unsigned int)v4);
}
close(v4);
result = 0;
}
}
else
{
printf(
"Proper usage of http server is:\n"
"%s <port> <#>\n"
"port is the port to serve on, # is either\n"
"0: serve only a single request\n"
"1: serve each request with a new thread\n"
"2: use a thread pool and a _bounded_ buffer with mutexes + condition variables\n",
*argv);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
int v4; // ebp
int v5; // eax
int result; // eax

rbInit(&rb, 4LL, envp);
irInit(&ir, 4LL);
if ( argc == 3 )
{
v3 = atoi(argv[1]);
v4 = server_create((unsigned int)v3);
if ( v4 < 0 )
{
result = -1;
}
else
{
v5 = atoi(argv[2]);
if ( v5 )
{
if ( v5 >= 0 )
{
if ( v5 == 1 )
func3(v4);
if ( v5 == 2 )
func4(v4);
}
}
else
{
func2((unsigned int)v4);
}
close(v4);
result = 0;
}
}
else
{
printf(
"Proper usage of http server is:\n"
"%s <port> <#>\n"
"port is the port to serve on, # is either\n"
"0: serve only a single request\n"
"1: serve each request with a new thread\n"
"2: use a thread pool and a _bounded_ buffer with mutexes + condition variables\n",
*argv);
result = -1;
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 server_type_t server_type;
 short int port;
 int accept_fd;
    rbInit(&rb, 4);
    irInit(&ir, 4);
 if (argc != 3) {
  printf("Proper usage of http server is:\n%s <port> <#>\n"
         "port is the port to serve on, # is either\n"
         "0: serve only a single request\n"
         "1: serve each request with a new thread\n"
         "2: use a thread pool and a _bounded_ buffer with "
         "mutexes + condition variables\n"
         ,argv[0]);
  return -1;
 }
 port = atoi(argv[1]);
 accept_fd = server_create(port);
 if (accept_fd < 0) return -1;
 server_type = atoi(argv[2]);
 switch(server_type) {
 case SERVER_TYPE_ONE:
  server_single_request(accept_fd);
  break;
 case SERVER_TYPE_THREAD_PER_REQUEST:
  server_thread_per_req(accept_fd);
  break;
 case SERVER_TYPE_THREAD_POOL_BOUND:
        server_thread_pool_bounded(accept_fd);
  break;
 }
 close(accept_fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 enum server_type_t server_type;
 short port;
 int accept_fd;
    rbInit(&rb, 4);
    irInit(&ir, 4);
 if (argc != 3) {
  printf("Proper usage of http server is:\n%s <port> <#>\n"
         "port is the port to serve on, # is either\n"
         "0: serve only a single request\n"
         "1: serve each request with a new thread\n"
         "2: use a thread pool and a _bounded_ buffer with "
         "mutexes + condition variables\n"
         ,argv[0]);
  return -1;
 }
 port = atoi(argv[1]);
 accept_fd = server_create(port);
 if (accept_fd < 0) return -1;
 server_type = atoi(argv[2]);
 switch(server_type) {
 case SERVER_TYPE_ONE:
  server_single_request(accept_fd);
  break;
 case SERVER_TYPE_THREAD_PER_REQUEST:
  server_thread_per_req(accept_fd);
  break;
 case SERVER_TYPE_THREAD_POOL_BOUND:
        server_thread_pool_bounded(accept_fd);
  break;
 }
 close(accept_fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: enum server_type_t { SERVER_TYPE_ONE=0, SERVER_TYPE_THREAD_PER_REQUEST=1, SERVER_TYPE_THREAD_POOL_BOUND=2 }

variable_types: port short


irInit

decompiled_code:
void *__fastcall irInit(__int64 a1, int a2)
{
int v2; // esi
void *result; // rax

v2 = a2 + 1;
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(v2, 4uLL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, int a2)
{
int v2; // esi
void *result; // rax

v2 = a2 + 1;
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(v2, 4uLL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void irInit(Int_ring *ir, int size) {
    ir->size = size + 1;
    ir->start = 0;
    ir->end = 0;
    ir->elems = (int *)calloc(ir->size, sizeof(int));
}

canonical_original_code:
void irInit(struct Int_ring *ir, int size) {
    ir->size = size + 1;
    ir->start = 0;
    ir->end = 0;
    ir->elems = (int *)calloc(ir->size, sizeof(int));
}

variable_types: struct Int_ring { int size; int start; int end; int *elems; } *


irFree

decompiled_code:
void __fastcall irFree(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void irFree(Int_ring *ir) {
    free(ir->elems); }

canonical_original_code:
void irFree(struct Int_ring *ir) {
    free(ir->elems); }

user_defined_types: struct Int_ring { int size; int start; int end; int *elems; }


irIsFull

decompiled_code:
_BOOL8 __fastcall irIsFull(_DWORD *a1)
{
return (a1[2] + 1) % *a1 == a1[1];
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1)
{
return (a1[2] + 1) % *a1 == a1[1];
}

original_code:
int irIsFull(Int_ring *ir) {
    return (ir->end + 1) % ir->size == ir->start; }

canonical_original_code:
int irIsFull(struct Int_ring *ir) {
    return (ir->end + 1) % ir->size == ir->start; }


irIsEmpty

decompiled_code:
_BOOL8 __fastcall irIsEmpty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 4);
}

original_code:
int irIsEmpty(Int_ring *ir) {
    return ir->end == ir->start; }

canonical_original_code:
int irIsEmpty(struct Int_ring *ir) {
    return ir->end == ir->start; }


irWrite

original_code:
void irWrite(Int_ring *ir, int *elem) {
    ir->elems[ir->end] = *elem;
    ir->end = (ir->end + 1) % ir->size;
    if (ir->end == ir->start)
        ir->start = (ir->start + 1) % ir->size;
}

canonical_original_code:
void irWrite(struct Int_ring *ir, int *elem) {
    ir->elems[ir->end] = *elem;
    ir->end = (ir->end + 1) % ir->size;
    if (ir->end == ir->start)
        ir->start = (ir->start + 1) % ir->size;
}

variable_types:
elem
int *


numOfItems

decompiled_code:
__int64 __fastcall numOfItems(__int64 a1)
{
return abs32(*(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 4));
}

original_code:
int numOfItems(Int_ring *ir){
    int num;
    num =abs(ir->end - ir->start);
    return num;
}

canonical_original_code:
int numOfItems(struct Int_ring *ir){
    int num;
    num =abs(ir->end - ir->start);
    return num;
}

variable_types: num int


irRead

original_code:
void irRead(Int_ring *ir, int *elem) {
    *elem = ir->elems[ir->start];
    ir->start = (ir->start + 1) % ir->size;
}

canonical_original_code:
void irRead(struct Int_ring *ir, int *elem) {
    *elem = ir->elems[ir->start];
    ir->start = (ir->start + 1) % ir->size;
}