Signal

decompiled_code:
__int64 __fastcall Signal(int sig, void (*a2)(int))
{
int v2; // eax
bool v3; // sf
__int64 result; // rax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v2 = 0x10000000;
if ( sig == 14 )
v2 = 0x20000000;
v5.sa_flags = v2;
v3 = sigaction(sig, &v5, &v6) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v6.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int sig, void (*a2)(int))
{
int v2; // eax
bool v3; // sf
__int64 result; // rax
struct sigaction v5; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-A8h] BYREF

v5.sa_handler = a2;
sigemptyset(&v5.sa_mask);
v2 = 0x10000000;
if ( sig == 14 )
v2 = 0x20000000;
v5.sa_flags = v2;
v3 = sigaction(sig, &v5, &v6) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v6.sa_handler;
return result;
}

original_code:
Sigfunc * Signal(int signo,Sigfunc * func)
{
 struct sigaction act,oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if(signo == 14){
  act.sa_flags |= 0x20000000;
 }else{
  act.sa_flags |= 0x10000000;
 }
 if(sigaction(signo,&act,&oact) < 0){
  return ((__sighandler_t) -1);
 }
 return oact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*Signal(int signo, void (*func)(int)))(int)
{
 struct sigaction act; struct sigaction oact;
 act.__sigaction_handler.sa_handler = func;
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 if(signo == 14){
  act.sa_flags |= 0x20000000;
 }else{
  act.sa_flags |= 0x10000000;
 }
 if(sigaction(signo,&act,&oact) < 0){
  return ((__sighandler_t) -1);
 }
 return oact.__sigaction_handler.sa_handler;
}

variable_types:
func
void (*)(int)

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

return_type: void (*)(int)

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

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


original_code:
void do_space_in_file_name(u8 *str,u8 *dest)
{
 u8 *p = str;
 u8 *q = dest;
 while(*p != '\0'){
  if(*p == 0x20){
   *q++ = '\\';
  }
  *q++ = *p++;
 }
 return;
}

canonical_original_code:
void do_space_in_file_name(unsigned char *str, unsigned char *dest)
{
 unsigned char *p = str;
 unsigned char *q = dest;
 while(*p != '\0'){
  if(*p == 0x20){
   *q++ = '\\';
  }
  *q++ = *p++;
 }
 return;
}

variable_types:
str
unsigned char *

variable_types:
dest
unsigned char *

variable_types:
p
unsigned char *

variable_types:
q
unsigned char *

return_type: void


decompiled_code:
__int64 mutex_table_init()
{
pthread_mutex_t *v0; // rbx
pthread_mutex_t *v1; // rdi

v0 = &mutex;
memset(&mutex_table, 0, 0x9C0uLL);
do
{
v1 = v0;
v0 = (pthread_mutex_t *)((char *)v0 + 312);
pthread_mutex_init(v1, 0LL);
v0[-8].__lock = 0;
}
while ( v0 != (pthread_mutex_t *)(&glob_mutex.__align + 1) );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
pthread_mutex_t *v0; // rbx
pthread_mutex_t *v1; // rdi

v0 = &mutex;
memset(&mutex_table, 0, 0x9C0uLL);
do
{
v1 = v0;
v0 = (pthread_mutex_t *)((char *)v0 + 312);
pthread_mutex_init(v1, 0LL);
v0[-8].__lock = 0;
}
while ( v0 != (pthread_mutex_t *)(&glob_mutex.__align + 1) );
return 0LL;
}

original_code:
int mutex_table_init()
{
 z_mutex * my_mutex;
 bzero(mutex_table,8*sizeof(z_mutex));
 for(my_mutex = &mutex_table[0];my_mutex < &mutex_table[8];my_mutex++)
 {
  pthread_mutex_init(&my_mutex->p_mutex,((void *)0));
  my_mutex->count = 0;
 }
 return 0;
}

canonical_original_code:
int mutex_table_init()
{
 struct z_mutex *my_mutex;
 bzero(mutex_table,8*sizeof(z_mutex));
 for(my_mutex = &mutex_table[0];my_mutex < &mutex_table[8];my_mutex++)
 {
  pthread_mutex_init(&my_mutex->p_mutex,((void *)0));
  my_mutex->count = 0;
 }
 return 0;
}

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

return_type: int

user_defined_types: struct z_mutex { int count; union pthread_mutex_t p_mutex; char file_name[260]; }

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

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


decompiled_code:
__int64 show_mutex_table()
{
unsigned int v0; // er13
char *v1; // rbx
__int64 i; // rsi
__int64 v3; // rcx
const char *v4; // rdx
char *v5; // r8

v0 = pthread_mutex_lock(&glob_mutex);
if ( v0 )
{
v0 = 1;
perror("glob_mutex thread_mutex_lock");
}
v1 = (char *)&unk_630;
puts("------------------------mutex_table--------------------");
for ( i = 0LL; ; i = (unsigned int)(i + 1) )
{
v3 = *((unsigned int *)v1 - 12);
v4 = "MTX_TAKEN";
v5 = v1;
if ( !(_DWORD)v3 )
v4 = "MTX_FREE";
v1 += 312;
printf("%3d %10s %3d %s\n", i, v4, v3, v5);
if ( "" == v1 )
break;
}
puts("-------------------------------------------------------");
if ( !pthread_mutex_unlock(&glob_mutex) )
return v0;
perror("glob_mutex thread_mutex_unlock");
return 2LL;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er13
char *v1; // rbx
__int64 i; // rsi
__int64 v3; // rcx
const char *v4; // rdx
char *v5; // r8

v0 = pthread_mutex_lock(&glob_mutex);
if ( v0 )
{
v0 = 1;
perror("glob_mutex thread_mutex_lock");
}
v1 = (char *)&unk_630;
puts("------------------------mutex_table--------------------");
for ( i = 0LL; ; i = (unsigned int)(i + 1) )
{
v3 = *((unsigned int *)v1 - 12);
v4 = "MTX_TAKEN";
v5 = v1;
if ( !(_DWORD)v3 )
v4 = "MTX_FREE";
v1 += 312;
printf("%3d %10s %3d %s\n", i, v4, v3, v5);
if ( "" == v1 )
break;
}
puts("-------------------------------------------------------");
if ( !pthread_mutex_unlock(&glob_mutex) )
return v0;
perror("glob_mutex thread_mutex_unlock");
return 2LL;
}

original_code:
int show_mutex_table()
{
 z_mutex * my_mutex;
 int i = 0;
 int r = 0;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_lock");
  r = 1;
 }
 printf("------------------------mutex_table--------------------\n");
 for(my_mutex = &mutex_table[0];my_mutex < &mutex_table[8];my_mutex++)
 {
  printf("%3d %10s %3d   %s\n",i++,((my_mutex->count == 0) ? "MTX_FREE":"MTX_TAKEN"),my_mutex->count,my_mutex->file_name);
 }
 printf("-------------------------------------------------------\n");
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_unlock");
  r = 2;
 }
 return r;
}

canonical_original_code:
int show_mutex_table()
{
 struct z_mutex *my_mutex;
 int i = 0;
 int r = 0;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_lock");
  r = 1;
 }
 printf("------------------------mutex_table--------------------\n");
 for(my_mutex = &mutex_table[0];my_mutex < &mutex_table[8];my_mutex++)
 {
  printf("%3d %10s %3d   %s\n",i++,((my_mutex->count == 0) ? "MTX_FREE":"MTX_TAKEN"),my_mutex->count,my_mutex->file_name);
 }
 printf("-------------------------------------------------------\n");
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_unlock");
  r = 2;
 }
 return r;
}

variable_types: i int

variable_types: r int

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


decompiled_code:
__int64 __fastcall put_z_mutex(_DWORD *a1)
{
unsigned int v1; // er12

v1 = pthread_mutex_lock(&glob_mutex);
if ( v1 )
{
v1 = 1;
perror("glob_mutex pthread_mutex_lock");
}
--*a1;
if ( !pthread_mutex_unlock(&glob_mutex) )
return v1;
perror("glob_mutex pthread_mutex_unlock");
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
unsigned int v1; // er12

v1 = pthread_mutex_lock(&glob_mutex);
if ( v1 )
{
v1 = 1;
perror("glob_mutex pthread_mutex_lock");
}
--*a1;
if ( !pthread_mutex_unlock(&glob_mutex) )
return v1;
perror("glob_mutex pthread_mutex_unlock");
return 2LL;
}

original_code:
int put_z_mutex(z_mutex * my_mutex)
{
 int r = 0;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex pthread_mutex_lock");
  r = 1;
 }
 my_mutex->count--;
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex pthread_mutex_unlock");
  r = 2;
 }
 return r;
}

canonical_original_code:
int put_z_mutex(struct z_mutex *my_mutex)
{
 int r = 0;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex pthread_mutex_lock");
  r = 1;
 }
 my_mutex->count--;
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex pthread_mutex_unlock");
  r = 2;
 }
 return r;
}


decompiled_code:
void __fastcall __noreturn thread_func(void *a1)
{
_BYTE *v1; // rax
unsigned __int8 v2; // si
_DWORD *v3; // r12
pthread_mutex_t *v4; // rax
pthread_mutex_t *v5; // r13
unsigned __int8 v6; // al

v1 = malloc(8uLL);
v2 = *(_BYTE *)a1;
*v1 = 1;
v3 = v1;
v4 = get_z_mutex((char *)a1 + 8, v2);
if ( v4 )
{
v5 = v4;
v6 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 1 )
{
puts("TRY_LOCK operation,after get_z_mutex:");
show_mutex_table();
if ( pthread_mutex_trylock((pthread_mutex_t *)&v5->__size[8]) )
{
puts("Try_Lock fail! put z_mutex back");
put_z_mutex(v5);
*(_BYTE *)v3 = 0;
v3[1] = 4;
}
else
{
puts("Try_Lock success!");
}
}
else if ( v6 == 2 )
{
if ( pthread_mutex_unlock((pthread_mutex_t *)&v5->__size[8]) )
{
puts("Unlock fail!");
*(_BYTE *)v3 = 0;
v3[1] = 5;
}
else
{
puts("Unlock success! put z_mutex back");
put_z_mutex(v5);
}
}
else if ( v6 )
{
v3[1] = 6;
*(_BYTE *)v3 = 0;
}
else
{
puts("LOCK operation,after get_z_mutex:");
show_mutex_table();
if ( pthread_mutex_lock((pthread_mutex_t *)&v5->__size[8]) )
{
puts("Lock fail! put z_mutex back");
put_z_mutex(v5);
*(_BYTE *)v3 = 0;
v3[1] = 3;
}
else
{
puts("Lock success!");
}
}
show_mutex_table();
}
else
{
v3[1] = 2;
*(_BYTE *)v3 = 0;
}
if ( write(*((_DWORD *)a1 + 1), v3, 8uLL) == -1 )
perror("write");
close(*((_DWORD *)a1 + 1));
free(a1);
free(v3);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(void *a1)
{
_BYTE *v1; // rax
unsigned __int8 v2; // si
_DWORD *v3; // r12
pthread_mutex_t *v4; // rax
pthread_mutex_t *v5; // r13
unsigned __int8 v6; // al

v1 = malloc(8uLL);
v2 = *(_BYTE *)a1;
*v1 = 1;
v3 = v1;
v4 = get_z_mutex((char *)a1 + 8, v2);
if ( v4 )
{
v5 = v4;
v6 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 1 )
{
puts("TRY_LOCK operation,after get_z_mutex:");
func2();
if ( pthread_mutex_trylock((pthread_mutex_t *)&v5->__size[8]) )
{
puts("Try_Lock fail! put z_mutex back");
func3(v5);
*(_BYTE *)v3 = 0;
v3[1] = 4;
}
else
{
puts("Try_Lock success!");
}
}
else if ( v6 == 2 )
{
if ( pthread_mutex_unlock((pthread_mutex_t *)&v5->__size[8]) )
{
puts("Unlock fail!");
*(_BYTE *)v3 = 0;
v3[1] = 5;
}
else
{
puts("Unlock success! put z_mutex back");
func3(v5);
}
}
else if ( v6 )
{
v3[1] = 6;
*(_BYTE *)v3 = 0;
}
else
{
puts("LOCK operation,after get_z_mutex:");
func2();
if ( pthread_mutex_lock((pthread_mutex_t *)&v5->__size[8]) )
{
puts("Lock fail! put z_mutex back");
func3(v5);
*(_BYTE *)v3 = 0;
v3[1] = 3;
}
else
{
puts("Lock success!");
}
}
func2();
}
else
{
v3[1] = 2;
*(_BYTE *)v3 = 0;
}
if ( write(*((_DWORD *)a1 + 1), v3, 8uLL) == -1 )
perror("write");
close(*((_DWORD *)a1 + 1));
free(a1);
free(v3);
pthread_exit(0LL);
}

original_code:
void * thread_func(void * arg)
{
 thread_arg * my_arg = (thread_arg *)arg;
 z_mutex * my_mutex;
 md_mutex_res_packet * res_pkt = (md_mutex_res_packet*)malloc(sizeof(md_mutex_res_packet));
 res_pkt->ok_or_not = 01;
 if((my_mutex = get_z_mutex(my_arg->file_name,my_arg->op_type)) == (z_mutex *)0)
 {
  res_pkt->why_fail = ALLOC_MUTEX_FAIL;
  res_pkt->ok_or_not = 00;
 }
 else
 {
  switch(my_arg->op_type)
  {
   case MD_LOCK:
    printf("LOCK operation,after get_z_mutex:\n");
    show_mutex_table();
    if(pthread_mutex_lock(&my_mutex->p_mutex) != 0)
    {
     printf("Lock fail! put z_mutex back\n");
     put_z_mutex(my_mutex);
     res_pkt->why_fail = LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Lock success!\n");}
    break;
   case MD_TRY_LOCK:
    printf("TRY_LOCK operation,after get_z_mutex:\n");
    show_mutex_table();
    if(pthread_mutex_trylock(&my_mutex->p_mutex) != 0)
    {
     printf("Try_Lock fail! put z_mutex back\n");
     put_z_mutex(my_mutex);
     res_pkt->why_fail = TRY_LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Try_Lock success!\n");}
    break;
   case MD_UNLOCK:
    if(pthread_mutex_unlock(&my_mutex->p_mutex) == 0)
    {
     printf("Unlock success! put z_mutex back\n");
     put_z_mutex(my_mutex);
    }
    else
    {
     printf("Unlock fail!\n");
     res_pkt->why_fail = UNLOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    break;
   default:
    res_pkt->why_fail = UNRECOGNIZED_OP_TYPE;
    res_pkt->ok_or_not = 00;
    break;
  }
  show_mutex_table();
 }
 if(write(my_arg->client_sock_fd,res_pkt,sizeof(md_mutex_res_packet)) == -1)
 {
  perror("write");
 }
 close(my_arg->client_sock_fd);
 free((thread_arg *)arg);
 free(res_pkt);
 pthread_exit((void *)0);
}

canonical_original_code:
void *thread_func(void *arg)
{
 struct thread_arg *my_arg = (thread_arg *)arg;
 struct z_mutex *my_mutex;
 struct md_mutex_res_packet *res_pkt = (md_mutex_res_packet*)malloc(sizeof(md_mutex_res_packet));
 res_pkt->ok_or_not = 01;
 if((my_mutex = get_z_mutex(my_arg->file_name,my_arg->op_type)) == (struct z_mutex *)0)
 {
  res_pkt->why_fail = ALLOC_MUTEX_FAIL;
  res_pkt->ok_or_not = 00;
 }
 else
 {
  switch(my_arg->op_type)
  {
   case MD_LOCK:
    printf("LOCK operation,after get_z_mutex:\n");
    show_mutex_table();
    if(pthread_mutex_lock(&my_mutex->p_mutex) != 0)
    {
     printf("Lock fail! put z_mutex back\n");
     put_z_mutex(my_mutex);
     res_pkt->why_fail = LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Lock success!\n");}
    break;
   case MD_TRY_LOCK:
    printf("TRY_LOCK operation,after get_z_mutex:\n");
    show_mutex_table();
    if(pthread_mutex_trylock(&my_mutex->p_mutex) != 0)
    {
     printf("Try_Lock fail! put z_mutex back\n");
     put_z_mutex(my_mutex);
     res_pkt->why_fail = TRY_LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Try_Lock success!\n");}
    break;
   case MD_UNLOCK:
    if(pthread_mutex_unlock(&my_mutex->p_mutex) == 0)
    {
     printf("Unlock success! put z_mutex back\n");
     put_z_mutex(my_mutex);
    }
    else
    {
     printf("Unlock fail!\n");
     res_pkt->why_fail = UNLOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    break;
   default:
    res_pkt->why_fail = UNRECOGNIZED_OP_TYPE;
    res_pkt->ok_or_not = 00;
    break;
  }
  show_mutex_table();
 }
 if(write(my_arg->client_sock_fd,res_pkt,sizeof(md_mutex_res_packet)) == -1)
 {
  perror("write");
 }
 close(my_arg->client_sock_fd);
 free((struct thread_arg *)arg);
 free(res_pkt);
 pthread_exit((void *)0);
}

variable_types:
arg
void *

variable_types: struct thread_arg { char op_type; int client_sock_fd; char file_name[260]; } *

variable_types: struct md_mutex_res_packet { char ok_or_not; enum fail_t { GLOB_MUTEX_LOCK_FAIL=0, GLOB_MUTEX_UNLOCK_FAIL=1, ALLOC_MUTEX_FAIL=2, LOCK_FAIL=3, TRY_LOCK_FAIL=4, UNLOCK_FAIL=5, UNRECOGNIZED_OP_TYPE=6 } why_fail; } *

return_type: void *

user_defined_types: struct md_mutex_res_packet { char ok_or_not; enum fail_t why_fail; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // er13
_BYTE *v5; // rax
_BYTE *v6; // r12
int v7; // ebx
unsigned int v8; // er12
size_t v9; // rdx
unsigned int v10; // eax
socklen_t addr_len; // [rsp+0h] [rbp-174h] BYREF
pthread_t newthread; // [rsp+4h] [rbp-170h] BYREF
char v13[16]; // [rsp+Ch] [rbp-168h] BYREF
struct sockaddr buf; // [rsp+1Ch] [rbp-158h] BYREF
struct sockaddr addr; // [rsp+2Ch] [rbp-148h] BYREF
int v16[78]; // [rsp+3Ch] [rbp-138h] BYREF

buf = 0LL;
buf.sa_family = 2;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = _bswap_16(9378);
v4 = socket(2, 1, v3);
if ( bind(v4, &buf, 0x10u) != -1 )
{
mutex_table_init();
show_mutex_table();
listen(v4, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
memset(v16, 0, 0x108uLL);
*(_OWORD *)v13 = 0LL;
v7 = accept(v4, &addr, &addr_len);
inet_ntop(2, &addr.sa_data[2], v13, 0x10u);
v8 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
v10 = read(v7, v16, v9);
if ( v10 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v10, v13, v8);
v5 = calloc(0x10CuLL, 1uLL);
v6 = v5;
if ( !v5 )
{
perror("malloc");
exit(1);
}
*((_DWORD *)v5 + 1) = v7;
strcpy(v5 + 8, (const char *)&v16[1]);
*v6 = v16[0];
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))thread_func, v6) )
{
perror("lock_thread_create");
exit(1);
}
}
perror("read");
exit(1);
}
perror("bind");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // er13
_BYTE *v5; // rax
_BYTE *v6; // r12
int v7; // ebx
unsigned int v8; // er12
size_t v9; // rdx
unsigned int v10; // eax
socklen_t addr_len; // [rsp+0h] [rbp-174h] BYREF
pthread_t newthread; // [rsp+4h] [rbp-170h] BYREF
char v13[16]; // [rsp+Ch] [rbp-168h] BYREF
struct sockaddr buf; // [rsp+1Ch] [rbp-158h] BYREF
struct sockaddr addr; // [rsp+2Ch] [rbp-148h] BYREF
int v16[78]; // [rsp+3Ch] [rbp-138h] BYREF

buf = 0LL;
buf.sa_family = 2;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = func0(9378);
v4 = socket(2, 1, v3);
if ( bind(v4, &buf, 0x10u) != -1 )
{
func1();
func2();
listen(v4, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
memset(v16, 0, 0x108uLL);
*(_OWORD *)v13 = 0LL;
v7 = accept(v4, &addr, &addr_len);
inet_ntop(2, &addr.sa_data[2], v13, 0x10u);
v8 = (unsigned __int16)func0(*(__int16 *)addr.sa_data);
v10 = read(v7, v16, v9);
if ( v10 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v10, v13, v8);
v5 = calloc(0x10CuLL, 1uLL);
v6 = v5;
if ( !v5 )
{
perror("malloc");
exit(1);
}
*((_DWORD *)v5 + 1) = v7;
strcpy(v5 + 8, (const char *)&v16[1]);
*v6 = v16[0];
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))thread_func, v6) )
{
perror("lock_thread_create");
exit(1);
}
}
perror("read");
exit(1);
}
perror("bind");
exit(1);
}

original_code:
int main()
{
 pthread_t thread_id;
 thread_arg * th_arg;
 md_mutex_req_packet req_pkt;
 char clnt_ip[16];
 int clnt_port;
 int listen_fd,connect_fd,addr_len,clnt_addr_len,n;
 struct sockaddr_in addr,clnt_addr;
 addr_len = sizeof(addr);
 bzero(&addr,addr_len);
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void*)&addr.sin_addr);
 addr.sin_port = htons(9378);
 listen_fd = socket(2,SOCK_STREAM,0);
 if(bind(listen_fd,(struct sockaddr*)&addr,addr_len) == -1)
 {
  perror("bind");
  exit(1);
 }
 mutex_table_init();
 show_mutex_table();
 listen(listen_fd,100);
 for(;;)
 {
  printf("md_concurrent_access_control_server listening...\n");
  bzero(clnt_ip,16);
  bzero(&req_pkt,sizeof(req_pkt));
  connect_fd = accept(listen_fd,(struct sockaddr*)&clnt_addr,&clnt_addr_len);
  inet_ntop(2,(void *)&clnt_addr.sin_addr,clnt_ip,16);
  clnt_port = ntohs(clnt_addr.sin_port);
  if((n = read(connect_fd,&req_pkt,sizeof(req_pkt))) == -1)
  {
   perror("read");
   exit(1);
  }
  printf("%d bytes read from client : ip - %s ^^ port - %d\n",n,clnt_ip,clnt_port);
  th_arg = (thread_arg*)malloc(sizeof(thread_arg));
  if(th_arg == ((void *)0))
  {
   perror("malloc");
   exit(1);
  }
  bzero(th_arg,sizeof(thread_arg));
  th_arg->client_sock_fd = connect_fd;
  strcpy(th_arg->file_name,req_pkt.file_name);
  th_arg->op_type = req_pkt.op_type;
  if(pthread_create(&thread_id,((void *)0),thread_func,(void*)th_arg) != 0)
  {
   perror("lock_thread_create");
   exit(1);
  }
 }
 return 0;
}

canonical_original_code:
int main()
{
 unsigned long thread_id;
 struct thread_arg *th_arg;
 struct md_mutex_req_packet req_pkt;
 char clnt_ip[16];
 int clnt_port;
 int listen_fd; int connect_fd; int addr_len; int clnt_addr_len; int n;
 struct sockaddr_in addr; struct sockaddr_in clnt_addr;
 addr_len = sizeof(addr);
 bzero(&addr,addr_len);
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9378);
 listen_fd = socket(2,SOCK_STREAM,0);
 if(bind(listen_fd,(struct sockaddr *)&addr,addr_len) == -1)
 {
  perror("bind");
  exit(1);
 }
 mutex_table_init();
 show_mutex_table();
 listen(listen_fd,100);
 for(;;)
 {
  printf("md_concurrent_access_control_server listening...\n");
  bzero(clnt_ip,16);
  bzero(&req_pkt,sizeof(req_pkt));
  connect_fd = accept(listen_fd,(struct sockaddr *)&clnt_addr,&clnt_addr_len);
  inet_ntop(2,(void *)&clnt_addr.sin_addr,clnt_ip,16);
  clnt_port = ntohs(clnt_addr.sin_port);
  if((n = read(connect_fd,&req_pkt,sizeof(req_pkt))) == -1)
  {
   perror("read");
   exit(1);
  }
  printf("%d bytes read from client : ip - %s ^^ port - %d\n",n,clnt_ip,clnt_port);
  th_arg = (struct thread_arg *)malloc(sizeof(thread_arg));
  if(th_arg == ((void *)0))
  {
   perror("malloc");
   exit(1);
  }
  bzero(th_arg,sizeof(thread_arg));
  th_arg->client_sock_fd = connect_fd;
  strcpy(th_arg->file_name,req_pkt.file_name);
  th_arg->op_type = req_pkt.op_type;
  if(pthread_create(&thread_id,((void *)0),thread_func,(void *)th_arg) != 0)
  {
   perror("lock_thread_create");
   exit(1);
  }
 }
 return 0;
}

variable_types: struct md_mutex_req_packet { enum op_t { MD_LOCK=0, MD_TRY_LOCK=1, MD_UNLOCK=2 } op_type; char file_name[260]; }

variable_types: n int

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

user_defined_types: struct md_mutex_req_packet { enum op_t op_type; char file_name[260]; }

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

user_defined_types: struct thread_arg { char op_type; int client_sock_fd; char file_name[260]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall queue_in_wait(__int64 a1, int a2, __int64 a3)
{
_DWORD *v4; // r14
int v5; // eax
char *v6; // rdx
unsigned int v7; // er13
__int64 v8; // rax
__int64 v9; // rax
__int64 v11[107]; // [rsp+0h] [rbp-358h] BYREF

v4 = malloc(0xC20uLL);
if ( !(unsigned int)md_get(a1, v4) )
{
v5 = v4[445];
v6 = (char *)&v4[4 * v5];
*((_DWORD *)v6 + 446) = a2;
*((_QWORD *)v6 + 224) = a3;
v4[445] = (v5 + 1) % 0x32u;
if ( (unsigned int)md_put(a1, v4) )
{
v7 = 1;
puts("Put metadata error!");
return v7;
}
while ( 1 )
{
v7 = md_get(a1, v4);
if ( v7 )
break;
v8 = (unsigned int)v4[444];
qmemcpy(v11, v4 + 444, 0x328uLL);
v9 = 2 * v8;
if ( LODWORD(v11[v9 + 1]) == a2 && v11[v9 + 2] == a3 )
{
free(v4);
return v7;
}
}
}
v7 = 1;
puts("Get metadata error!");
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3)
{
_DWORD *v4; // r14
int v5; // eax
char *v6; // rdx
unsigned int v7; // er13
__int64 v8; // rax
__int64 v9; // rax
__int64 v11[107]; // [rsp+0h] [rbp-358h] BYREF

v4 = malloc(0xC20uLL);
if ( !(unsigned int)md_get(a1, v4) )
{
v5 = v4[445];
v6 = (char *)&v4[4 * v5];
*((_DWORD *)v6 + 446) = a2;
*((_QWORD *)v6 + 224) = a3;
v4[445] = (v5 + 1) % 0x32u;
if ( (unsigned int)md_put(a1, v4) )
{
v7 = 1;
puts("Put metadata error!");
return v7;
}
while ( 1 )
{
v7 = md_get(a1, v4);
if ( v7 )
break;
v8 = (unsigned int)v4[444];
qmemcpy(v11, v4 + 444, 0x328uLL);
v9 = 2 * v8;
if ( LODWORD(v11[v9 + 1]) == a2 && v11[v9 + 2] == a3 )
{
free(v4);
return v7;
}
}
}
v7 = 1;
puts("Get metadata error!");
return v7;
}

original_code:
u32 queue_in_wait(const char* filename,IO_Type io_type,time_t arrive_time)
{
    Meta_Data *meta_data=(Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        u32 tail=(*meta_data).ioq.tail;
        (*meta_data).ioq.io_q_node[tail].io_type=io_type;
        (*meta_data).ioq.io_q_node[tail].arrive_time=arrive_time;
        (*meta_data).ioq.tail=((tail+1)%50);
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata error!\n");
            return 1;
        }
    }
    else
    {
        printf("Get metadata error!\n");
        return 1;
    }
  while(1)
    {
        if(md_get(filename,meta_data)==0)
        {
            IO_Q io_q=(*meta_data).ioq;
            u32 head=io_q.head;
            IO_Q_Node io_q_node=io_q.io_q_node[head];
            if((io_q_node.io_type==io_type)&&
                (io_q_node.arrive_time==arrive_time))
            {
                free(meta_data);
                return 0;
            }
        }
        else
        {
            printf("Get metadata error!\n");
            return 1;
        }
    }
}

canonical_original_code:
unsigned int queue_in_wait(char *filename, enum IO_Type io_type, long arrive_time)
{
    struct Meta_Data *meta_data = (Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        unsigned int tail = (*meta_data).ioq.tail;
        (*meta_data).ioq.io_q_node[tail].io_type=io_type;
        (*meta_data).ioq.io_q_node[tail].arrive_time=arrive_time;
        (*meta_data).ioq.tail=((tail+1)%50);
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata error!\n");
            return 1;
        }
    }
    else
    {
        printf("Get metadata error!\n");
        return 1;
    }
  while(1)
    {
        if(md_get(filename,meta_data)==0)
        {
            struct IO_Q io_q = (*meta_data).ioq;
            unsigned int head = io_q.head;
            struct IO_Q_Node io_q_node = io_q.io_q_node[head];
            if((io_q_node.io_type==io_type)&&
                (io_q_node.arrive_time==arrive_time))
            {
                free(meta_data);
                return 0;
            }
        }
        else
        {
            printf("Get metadata error!\n");
            return 1;
        }
    }
}

variable_types:
filename
char *

variable_types: struct Meta_Data { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } stat_info; struct REPLICA { char IS_DTC_FILE; char host_ip[20]; char starting_directory[260]; char io_node_ptr[260]; } my_rep[3]; int replica_num; struct IO_Q { int head; int tail; struct IO_Q_Node { enum IO_Type { READ=0, WRITE=1, REMOVE=2 } io_type; long arrive_time; } io_q_node[50]; } ioq; char io_node_q_head[260]; char io_node_q_tail[260]; } *

variable_types:
tail
unsigned int

variable_types:
head
unsigned int

return_type: unsigned int

user_defined_types: struct IO_Q { int head; int tail; struct IO_Q_Node io_q_node[50]; }

user_defined_types: struct IO_Q_Node { enum IO_Type io_type; long arrive_time; }

user_defined_types: struct Meta_Data { struct stat stat_info; struct REPLICA my_rep[3]; int replica_num; struct IO_Q ioq; char io_node_q_head[260]; char io_node_q_tail[260]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall read_queuue_out(__int64 a1, __int64 a2, __int64 a3)
{
_DWORD *v4; // rbp
int v5; // eax
__int64 result; // rax

v4 = malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v4) )
{
puts("Get metadata in read_queue_out error!");
result = 1LL;
}
else
{
v5 = v4[444];
*((_QWORD *)v4 + 9) = a3;
v4[444] = (v5 + 1) % 0x32u;
result = md_put(a1, v4);
if ( (_DWORD)result )
{
puts("Put metadata in read_queue_out error!");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
_DWORD *v4; // rbp
int v5; // eax
__int64 result; // rax

v4 = malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v4) )
{
puts("Get metadata in read_queue_out error!");
result = 1LL;
}
else
{
v5 = v4[444];
*((_QWORD *)v4 + 9) = a3;
v4[444] = (v5 + 1) % 0x32u;
result = md_put(a1, v4);
if ( (_DWORD)result )
{
puts("Put metadata in read_queue_out error!");
result = 1LL;
}
}
return result;
}

original_code:
u32 read_queuue_out(const char* filename,IO_Type io_type,time_t arrive_time)
{
    Meta_Data *meta_data=(Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        u32 head=(*meta_data).ioq.head;
        (*meta_data).ioq.head=(head+1)%50;
        (*meta_data).stat_info.st_atim.tv_sec=arrive_time;
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata in read_queue_out error!\n");
            return 1;
        }
    }
    else
    {
        printf("Get metadata in read_queue_out error!\n");
        return 1;
    }
    return 0;
}

canonical_original_code:
unsigned int read_queuue_out(char *filename, enum IO_Type io_type, long arrive_time)
{
    struct Meta_Data *meta_data = (Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        unsigned int head = (*meta_data).ioq.head;
        (*meta_data).ioq.head=(head+1)%50;
        (*meta_data).stat_info.st_atim.tv_sec=arrive_time;
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata in read_queue_out error!\n");
            return 1;
        }
    }
    else
    {
        printf("Get metadata in read_queue_out error!\n");
        return 1;
    }
    return 0;
}

variable_types: enum IO_Type { READ=0, WRITE=1, REMOVE=2 }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: struct REPLICA { char IS_DTC_FILE; char host_ip[20]; char starting_directory[260]; char io_node_ptr[260]; }


decompiled_code:
__int64 __fastcall write_queue_out(const char *a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
char *v8; // rbp
char *v9; // rax
char *v10; // r14
__int64 result; // rax
char *v12; // rbx
int v13; // eax
char *v14; // rdx
__int64 v15; // rbx
char s[328]; // [rsp+10h] [rbp-148h] BYREF

sprintf(s, "%s_%ld", a1, a3);
v8 = (char *)malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v8) )
{
puts("Get metadata in write_queue_out error!");
return 1LL;
}
*((_DWORD *)v8 + 444) = (*((_DWORD *)v8 + 444) + 1) % 0x32u;
v9 = (char *)malloc(0x220uLL);
*(_DWORD *)v9 = a2;
v10 = v9;
*((_QWORD *)v9 + 1) = a4;
*((_QWORD *)v9 + 2) = a3;
strcpy(v9 + 24, v8 + 2844);
if ( (unsigned int)ion_put(s, v10) )
goto LABEL_10;
free(v10);
if ( strlen(v8 + 2844) <= 1 )
goto LABEL_21;
v12 = (char *)malloc(0x220uLL);
if ( (unsigned int)ion_get(v8 + 2844, v12) )
{
puts("Get io_node in write_queue_out error!");
return 1LL;
}
strcpy(v12 + 284, s);
if ( (unsigned int)ion_put(v8 + 2844, v12) )
{
LABEL_10:
puts("Put io_node in write_queue_out error!");
result = 1LL;
}
else
{
LABEL_21:
if ( !v8[2584] )
{
strcpy(v8 + 2584, s);
v13 = *((_DWORD *)v8 + 442);
if ( v13 )
{
v14 = v8 + 425;
v15 = (__int64)&v8[541 * (v13 - 1) + 966];
do
v14 = strcpy(v14, s) + 541;
while ( v14 != (char *)v15 );
}
}
strcpy(v8 + 2844, s);
if ( (unsigned int)md_put(a1, v8) )
{
puts("Put metadata in write_queue_out error!");
result = 1LL;
}
else
{
free(v8);
result = iod_put(s, a5, a6);
if ( (_DWORD)result )
{
puts("Put data in write_queue_out error!");
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
char *v8; // rbp
char *v9; // rax
char *v10; // r14
__int64 result; // rax
char *v12; // rbx
int v13; // eax
char *v14; // rdx
__int64 v15; // rbx
char s[328]; // [rsp+10h] [rbp-148h] BYREF

sprintf(s, "%s_%ld", a1, a3);
v8 = (char *)malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v8) )
{
puts("Get metadata in write_queue_out error!");
return 1LL;
}
*((_DWORD *)v8 + 444) = (*((_DWORD *)v8 + 444) + 1) % 0x32u;
v9 = (char *)malloc(0x220uLL);
*(_DWORD *)v9 = a2;
v10 = v9;
*((_QWORD *)v9 + 1) = a4;
*((_QWORD *)v9 + 2) = a3;
strcpy(v9 + 24, v8 + 2844);
if ( (unsigned int)ion_put(s, v10) )
goto LABEL_10;
free(v10);
if ( strlen(v8 + 2844) <= 1 )
goto LABEL_21;
v12 = (char *)malloc(0x220uLL);
if ( (unsigned int)ion_get(v8 + 2844, v12) )
{
puts("Get io_node in write_queue_out error!");
return 1LL;
}
strcpy(v12 + 284, s);
if ( (unsigned int)ion_put(v8 + 2844, v12) )
{
LABEL_10:
puts("Put io_node in write_queue_out error!");
result = 1LL;
}
else
{
LABEL_21:
if ( !v8[2584] )
{
strcpy(v8 + 2584, s);
v13 = *((_DWORD *)v8 + 442);
if ( v13 )
{
v14 = v8 + 425;
v15 = (__int64)&v8[541 * (v13 - 1) + 966];
do
v14 = strcpy(v14, s) + 541;
while ( v14 != (char *)v15 );
}
}
strcpy(v8 + 2844, s);
if ( (unsigned int)md_put(a1, v8) )
{
puts("Put metadata in write_queue_out error!");
result = 1LL;
}
else
{
free(v8);
result = iod_put(s, a5, a6);
if ( (_DWORD)result )
{
puts("Put data in write_queue_out error!");
result = 1LL;
}
}
}
return result;
}

original_code:
u32 write_queue_out(const char* filename,IO_Type io_type,time_t arrive_time,u64 offset,char *data,size_t size)
{
    char path[260];
    sprintf(path, "%s_%ld", filename, arrive_time);
    Meta_Data *meta_data=(Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        u32 head=(*meta_data).ioq.head;
        (*meta_data).ioq.head=(head+1)%50;
        IO_Node *io_node=(IO_Node*)malloc(sizeof(IO_Node));
        (*io_node).io_type=io_type;
        (*io_node).offset=offset;
        (*io_node).io_time=arrive_time;
        strcpy((*io_node).ion_pre,(*meta_data).io_node_q_tail);
        if(ion_put(path,io_node)!=0)
        {
            printf("Put io_node in write_queue_out error!\n");
            return 1;
        }
        free(io_node);
        if(strlen((*meta_data).io_node_q_tail)>1)
        {
            IO_Node *io_node1=(IO_Node*)malloc(sizeof(IO_Node));
            char* tail_path=(*meta_data).io_node_q_tail;
            if(ion_get(tail_path,io_node1)==0)
            {
                strcpy((*io_node1).ion_next,path);
                if(ion_put(tail_path,io_node1)!=0)
                {
                    printf("Put io_node in write_queue_out error!\n");
                    return 1;
                }
            }
            else
            {
                printf("Get io_node in write_queue_out error!\n");
                return 1;
            }
        }
        if(strlen((*meta_data).io_node_q_head)==0)
        {
            strcpy((*meta_data).io_node_q_head,path);
            u32 i, replica_num=(*meta_data).replica_num;
            for(i=0;i<replica_num;i++)
            {
                strcpy((*meta_data).my_rep[i].io_node_ptr,path);
            }
        }
        strcpy((*meta_data).io_node_q_tail,path);
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata in write_queue_out error!\n");
            return 1;
        }
        free(meta_data);
    }
    else
    {
        printf("Get metadata in write_queue_out error!\n");
        return 1;
    }
    if(iod_put(path,data,size)!=0)
    {
        printf("Put data in write_queue_out error!\n");
        return 1;
    }
    return 0;
}

canonical_original_code:
unsigned int write_queue_out(char *filename, enum IO_Type io_type, long arrive_time, unsigned long offset, char *data, unsigned long size)
{
    char path[260];
    sprintf(path, "%s_%ld", filename, arrive_time);
    struct Meta_Data *meta_data = (Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        unsigned int head = (*meta_data).ioq.head;
        (*meta_data).ioq.head=(head+1)%50;
        struct IO_Node *io_node = (IO_Node*)malloc(sizeof(IO_Node));
        (*io_node).io_type=io_type;
        (*io_node).offset=offset;
        (*io_node).io_time=arrive_time;
        strcpy((*io_node).ion_pre,(*meta_data).io_node_q_tail);
        if(ion_put(path,io_node)!=0)
        {
            printf("Put io_node in write_queue_out error!\n");
            return 1;
        }
        free(io_node);
        if(strlen((*meta_data).io_node_q_tail)>1)
        {
            struct IO_Node *io_node1 = (IO_Node*)malloc(sizeof(IO_Node));
            char *tail_path = (*meta_data).io_node_q_tail;
            if(ion_get(tail_path,io_node1)==0)
            {
                strcpy((*io_node1).ion_next,path);
                if(ion_put(tail_path,io_node1)!=0)
                {
                    printf("Put io_node in write_queue_out error!\n");
                    return 1;
                }
            }
            else
            {
                printf("Get io_node in write_queue_out error!\n");
                return 1;
            }
        }
        if(strlen((*meta_data).io_node_q_head)==0)
        {
            strcpy((*meta_data).io_node_q_head,path);
            unsigned int i; unsigned int replica_num = (*meta_data).replica_num;
            for(i=0;i<replica_num;i++)
            {
                strcpy((*meta_data).my_rep[i].io_node_ptr,path);
            }
        }
        strcpy((*meta_data).io_node_q_tail,path);
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata in write_queue_out error!\n");
            return 1;
        }
        free(meta_data);
    }
    else
    {
        printf("Get metadata in write_queue_out error!\n");
        return 1;
    }
    if(iod_put(path,data,size)!=0)
    {
        printf("Put data in write_queue_out error!\n");
        return 1;
    }
    return 0;
}

variable_types:
offset
unsigned long

variable_types:
data
char *

variable_types:
size
unsigned long

variable_types:
path
char [260]

variable_types: struct IO_Node { enum IO_Type { READ=0, WRITE=1, REMOVE=2 } io_type; unsigned long offset; long io_time; char ion_pre[260]; char ion_next[260]; } *

variable_types:
i
unsigned int

user_defined_types: struct IO_Node { enum IO_Type io_type; unsigned long offset; long io_time; char ion_pre[260]; char ion_next[260]; }


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

result = md_out();
if ( (_DWORD)result )
{
puts("Remove metadata in remove_queueout error!");
result = 1LL;
}
return result;
}

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

result = md_out();
if ( (_DWORD)result )
{
puts("Remove metadata in remove_queueout error!");
result = 1LL;
}
return result;
}

original_code:
u32 remove_queuue_out(const char* filename,IO_Type io_type)
{
    if(md_out(filename)!=0)
    {
        printf("Remove metadata in remove_queueout error!\n");
        return 1;
    }
    return 0;
}

canonical_original_code:
unsigned int remove_queuue_out(char *filename, enum IO_Type io_type)
{
    if(md_out(filename)!=0)
    {
        printf("Remove metadata in remove_queueout error!\n");
        return 1;
    }
    return 0;
}

user_defined_types: enum IO_Type { READ=0, WRITE=1, REMOVE=2 }


decompiled_code:
void __fastcall replica_update(__int64 a1, const char *a2)
{
char *v2; // r14
unsigned int v3; // eax
__int64 v4; // rbx
int v5; // er13
char *v6; // r15
const char *v7; // rax
char *v8; // rbp
const char *v9; // r12
__int64 v10; // rbx
char *v11; // rax
char dest[272]; // [rsp+10h] [rbp-368h] BYREF
char v13[600]; // [rsp+120h] [rbp-258h] BYREF

v2 = (char *)malloc(0xC20uLL);
v3 = md_get(a1, v2);
v4 = v3;
if ( v3 )
{
puts("Get metadata in replica_update error!");
return;
}
v5 = *((_DWORD *)v2 + 442);
if ( v5 )
{
v6 = v2 + 144;
do
{
qmemcpy(v13, v6, 0x21DuLL);
if ( !strcmp(&v13[1], a2) )
break;
v4 = (unsigned int)(v4 + 1);
v6 += 541;
}
while ( v5 != (_DWORD)v4 );
}
if ( !v13[281] )
goto LABEL_13;
strcpy(dest, &v13[281]);
v7 = (const char *)malloc(8uLL);
v8 = (char *)v7;
if ( !dest[0] )
{
LABEL_12:
v10 = 541 * v4;
free(v8);
v11 = &v2[v10 + 425];
*(_QWORD *)v11 = 0LL;
*(_QWORD *)(v11 + 252) = 0LL;
memset(
(void *)((unsigned __int64)&v2[v10 + 433] & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v11 - (((_DWORD)v2 + (_DWORD)v10 + 433) & 0xFFFFFFF8) + 260) >> 3));
LABEL_13:
if ( (unsigned int)md_put(a1, v2) )
puts("Put metadata in replica_update error!");
else
free(v2);
return;
}
v9 = v7 + 284;
while ( !(unsigned int)ion_get(dest, v8) )
{
iod_get(dest, 0LL);
strcpy(dest, v9);
if ( !dest[0] )
goto LABEL_12;
}
puts("Get io_node in replica_update error!");
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, const char *a2)
{
char *v2; // r14
unsigned int v3; // eax
__int64 v4; // rbx
int v5; // er13
char *v6; // r15
const char *v7; // rax
char *v8; // rbp
const char *v9; // r12
__int64 v10; // rbx
char *v11; // rax
char dest[272]; // [rsp+10h] [rbp-368h] BYREF
char v13[600]; // [rsp+120h] [rbp-258h] BYREF

v2 = (char *)malloc(0xC20uLL);
v3 = md_get(a1, v2);
v4 = v3;
if ( v3 )
{
puts("Get metadata in replica_update error!");
return;
}
v5 = *((_DWORD *)v2 + 442);
if ( v5 )
{
v6 = v2 + 144;
do
{
qmemcpy(v13, v6, 0x21DuLL);
if ( !strcmp(&v13[1], a2) )
break;
v4 = (unsigned int)(v4 + 1);
v6 += 541;
}
while ( v5 != (_DWORD)v4 );
}
if ( !v13[281] )
goto LABEL_13;
strcpy(dest, &v13[281]);
v7 = (const char *)malloc(8uLL);
v8 = (char *)v7;
if ( !dest[0] )
{
LABEL_12:
v10 = 541 * v4;
free(v8);
v11 = &v2[v10 + 425];
*(_QWORD *)v11 = 0LL;
*(_QWORD *)(v11 + 252) = 0LL;
memset(
(void *)((unsigned __int64)&v2[v10 + 433] & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v11 - (((_DWORD)v2 + (_DWORD)v10 + 433) & 0xFFFFFFF8) + 260) >> 3));
LABEL_13:
if ( (unsigned int)md_put(a1, v2) )
puts("Put metadata in replica_update error!");
else
free(v2);
return;
}
v9 = v7 + 284;
while ( !(unsigned int)ion_get(dest, v8) )
{
iod_get(dest, 0LL);
strcpy(dest, v9);
if ( !dest[0] )
goto LABEL_12;
}
puts("Get io_node in replica_update error!");
}

original_code:
u32 replica_update(const char *filename,const char*host_ip)
{
    Meta_Data *meta_data=(Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        u32 i, replica_num=(*meta_data).replica_num;
        REPLICA replica;
        for(i=0;i<replica_num;i++)
        {
            replica=(*meta_data).my_rep[i];
            if(strcmp(replica.host_ip,host_ip)==0) break;
        }
        if(strlen(replica.io_node_ptr)!=0)
        {
            char io_node_ptr[260];
            strcpy(io_node_ptr,replica.io_node_ptr);
            IO_Node *io_node=(IO_Node*)malloc(sizeof(IO_Node*));
            while(strlen(io_node_ptr)!=0)
            {
                if(ion_get(io_node_ptr,io_node)==0)
                {
                    u64 offset=(*io_node).offset;
                    u32 *data_size;
                    char * real_data=iod_get(io_node_ptr,data_size);
                    strcpy(io_node_ptr,(*io_node).ion_next);
                }
                else
                {
                    printf("Get io_node in replica_update error!\n");
                    return 1;
                }
            }
            free(io_node);
            memset((*meta_data).my_rep[i].io_node_ptr,0,260);
        }
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata in replica_update error!\n");
            return 1;
        }
        free(meta_data);
    }
    else
    {
        printf("Get metadata in replica_update error!\n");
        return 1;
    }
}

canonical_original_code:
unsigned int replica_update(char *filename, char *host_ip)
{
    struct Meta_Data *meta_data = (Meta_Data*)malloc(sizeof(Meta_Data));
    if(md_get(filename,meta_data)==0)
    {
        unsigned int i; unsigned int replica_num = (*meta_data).replica_num;
        struct REPLICA replica;
        for(i=0;i<replica_num;i++)
        {
            replica=(*meta_data).my_rep[i];
            if(strcmp(replica.host_ip,host_ip)==0) break;
        }
        if(strlen(replica.io_node_ptr)!=0)
        {
            char io_node_ptr[260];
            strcpy(io_node_ptr,replica.io_node_ptr);
            struct IO_Node *io_node = (IO_Node*)malloc(sizeof(IO_Node*));
            while(strlen(io_node_ptr)!=0)
            {
                if(ion_get(io_node_ptr,io_node)==0)
                {
                    unsigned long offset = (*io_node).offset;
                    unsigned int *data_size;
                    char *real_data = iod_get(io_node_ptr,data_size);
                    strcpy(io_node_ptr,(*io_node).ion_next);
                }
                else
                {
                    printf("Get io_node in replica_update error!\n");
                    return 1;
                }
            }
            free(io_node);
            memset((*meta_data).my_rep[i].io_node_ptr,0,260);
        }
        if(md_put(filename,meta_data)!=0)
        {
            printf("Put metadata in replica_update error!\n");
            return 1;
        }
        free(meta_data);
    }
    else
    {
        printf("Get metadata in replica_update error!\n");
        return 1;
    }
}

variable_types: struct REPLICA { char IS_DTC_FILE; char host_ip[20]; char starting_directory[260]; char io_node_ptr[260]; }


decompiled_code:
__int64 __fastcall md_mutex_func(char *src, int a2)
{
int v2; // edx
int v3; // eax
int v4; // ebp
unsigned int v5; // er13
char *v6; // rax
char *v7; // r12
int v8; // ebx
unsigned int *v9; // r12
struct sockaddr v11[3]; // [rsp+0h] [rbp-38h] BYREF

v11[0] = 0LL;
v11[0].sa_family = 2;
inet_pton(2, "127.0.0.1", &v11[0].sa_data[2]);
*(_WORD *)v11[0].sa_data = _bswap_16_constprop_0(2LL, 1LL, 0LL);
v3 = socket(2, 1, v2);
if ( v3 == -1 )
{
perror("socket");
exit(1);
}
v4 = v3;
v5 = connect(v3, v11, 0x10u);
if ( v5 )
{
perror("connect");
exit(1);
}
v6 = (char *)calloc(0x108uLL, 1uLL);
*(_DWORD *)v6 = a2;
v7 = v6;
strcpy(v6 + 4, src);
v8 = write(v4, v7, 0x108uLL);
free(v7);
if ( v8 == -1 )
{
perror("md_mutex_func try to send request");
exit(1);
}
v9 = (unsigned int *)calloc(8uLL, 1uLL);
if ( (unsigned int)read(v4, v9, 8uLL) == -1 )
{
perror("md_mutex_func get response from server");
free(v9);
exit(1);
}
close(v4);
if ( *(_BYTE *)v9 != 1 )
{
if ( *(_BYTE *)v9 )
{
v5 = -1;
puts("Unrecognized response from server!");
}
else
{
v5 = 1;
printf("errorno:%d\n", v9[1]);
}
}
free(v9);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src, int a2)
{
int v2; // edx
int v3; // eax
int v4; // ebp
unsigned int v5; // er13
char *v6; // rax
char *v7; // r12
int v8; // ebx
unsigned int *v9; // r12
struct sockaddr v11[3]; // [rsp+0h] [rbp-38h] BYREF

v11[0] = 0LL;
v11[0].sa_family = 2;
inet_pton(2, "127.0.0.1", &v11[0].sa_data[2]);
*(_WORD *)v11[0].sa_data = func7(2LL, 1LL, 0LL);
v3 = socket(2, 1, v2);
if ( v3 == -1 )
{
perror("socket");
exit(1);
}
v4 = v3;
v5 = connect(v3, v11, 0x10u);
if ( v5 )
{
perror("connect");
exit(1);
}
v6 = (char *)calloc(0x108uLL, 1uLL);
*(_DWORD *)v6 = a2;
v7 = v6;
strcpy(v6 + 4, src);
v8 = write(v4, v7, 0x108uLL);
free(v7);
if ( v8 == -1 )
{
perror("md_mutex_func try to send request");
exit(1);
}
v9 = (unsigned int *)calloc(8uLL, 1uLL);
if ( (unsigned int)read(v4, v9, 8uLL) == -1 )
{
perror("md_mutex_func get response from server");
free(v9);
exit(1);
}
close(v4);
if ( *(_BYTE *)v9 != 1 )
{
if ( *(_BYTE *)v9 )
{
v5 = -1;
puts("Unrecognized response from server!");
}
else
{
v5 = 1;
printf("errorno:%d\n", v9[1]);
}
}
free(v9);
return v5;
}

original_code:
int md_mutex_func(md_mutex_t * md_mutex,op_t op_type)
{
 int res = 0;
 int fd,addr_len;
 struct sockaddr_in addr;
 md_mutex_req_packet * req_pkt;
 md_mutex_res_packet * res_pkt;
 bzero(&addr,sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void*)&addr.sin_addr);
 addr.sin_port = htons(9378);
 addr_len = sizeof(addr);
 if((fd = socket(2,SOCK_STREAM,0)) == -1)
 {
  perror("socket");
  exit(1);
 }
 if((res = connect(fd,(struct sockaddr*)&addr,addr_len)) != 0)
 {
  perror("connect");
  exit(1);
 }
 req_pkt = (md_mutex_req_packet*)malloc(sizeof(md_mutex_req_packet));
 bzero(req_pkt,sizeof(md_mutex_req_packet));
 req_pkt->op_type = op_type;
 strcpy(req_pkt->file_name,md_mutex->file_name);
 res = write(fd,req_pkt,sizeof(md_mutex_req_packet));
 free(req_pkt);
 if(res == -1)
 {
  perror("md_mutex_func try to send request");
  exit(1);
 }
 res_pkt = (md_mutex_res_packet*)malloc(sizeof(md_mutex_res_packet));
 bzero(res_pkt,sizeof(md_mutex_res_packet));
 if((res = read(fd,res_pkt,sizeof(md_mutex_res_packet))) == -1)
 {
  perror("md_mutex_func get response from server");
  free(res_pkt);
  exit(1);
 }
 close(fd);
 if(res_pkt->ok_or_not == 01){res = 0;}
 else if(res_pkt->ok_or_not == 00){
  printf("errorno:%d\n",res_pkt->why_fail);
  res = 1;
 }
 else{
  printf("Unrecognized response from server!\n");
  res = -1;
 }
 free(res_pkt);
 return res;
}

canonical_original_code:
int md_mutex_func(struct md_mutex_t *md_mutex, enum op_t op_type)
{
 int res = 0;
 int fd; int addr_len;
 struct sockaddr_in addr;
 struct md_mutex_req_packet *req_pkt;
 struct md_mutex_res_packet *res_pkt;
 bzero(&addr,sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9378);
 addr_len = sizeof(addr);
 if((fd = socket(2,SOCK_STREAM,0)) == -1)
 {
  perror("socket");
  exit(1);
 }
 if((res = connect(fd,(struct sockaddr *)&addr,addr_len)) != 0)
 {
  perror("connect");
  exit(1);
 }
 req_pkt = (struct md_mutex_req_packet *)malloc(sizeof(md_mutex_req_packet));
 bzero(req_pkt,sizeof(md_mutex_req_packet));
 req_pkt->op_type = op_type;
 strcpy(req_pkt->file_name,md_mutex->file_name);
 res = write(fd,req_pkt,sizeof(md_mutex_req_packet));
 free(req_pkt);
 if(res == -1)
 {
  perror("md_mutex_func try to send request");
  exit(1);
 }
 res_pkt = (struct md_mutex_res_packet *)malloc(sizeof(md_mutex_res_packet));
 bzero(res_pkt,sizeof(md_mutex_res_packet));
 if((res = read(fd,res_pkt,sizeof(md_mutex_res_packet))) == -1)
 {
  perror("md_mutex_func get response from server");
  free(res_pkt);
  exit(1);
 }
 close(fd);
 if(res_pkt->ok_or_not == 01){res = 0;}
 else if(res_pkt->ok_or_not == 00){
  printf("errorno:%d\n",res_pkt->why_fail);
  res = 1;
 }
 else{
  printf("Unrecognized response from server!\n");
  res = -1;
 }
 free(res_pkt);
 return res;
}

variable_types: struct md_mutex_t { char file_name[260]; } *

variable_types: res int

variable_types: fd int

variable_types: struct md_mutex_req_packet { enum op_t { MD_LOCK=0, MD_TRY_LOCK=1, MD_UNLOCK=2 } op_type; char file_name[260]; } *

user_defined_types: enum fail_t { GLOB_MUTEX_LOCK_FAIL=0, GLOB_MUTEX_UNLOCK_FAIL=1, ALLOC_MUTEX_FAIL=2, LOCK_FAIL=3, TRY_LOCK_FAIL=4, UNLOCK_FAIL=5, UNRECOGNIZED_OP_TYPE=6 }


decompiled_code:
__int64 __fastcall md_mutex_lock(char *a1)
{
return md_mutex_func(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
return func8(a1, 0);
}

original_code:
int md_mutex_lock(md_mutex_t * md_mutex)
{
 op_t op_type = MD_LOCK;
 return md_mutex_func(md_mutex,op_type);
}

canonical_original_code:
int md_mutex_lock(struct md_mutex_t *md_mutex)
{
 enum op_t op_type = MD_LOCK;
 return md_mutex_func(md_mutex,op_type);
}

variable_types: enum op_t { MD_LOCK=0, MD_TRY_LOCK=1, MD_UNLOCK=2 }

user_defined_types: struct md_mutex_t { char file_name[260]; }


decompiled_code:
__int64 __fastcall md_mutex_try_lock(char *a1)
{
return md_mutex_func(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1)
{
return func8(a1, 1);
}

original_code:
int md_mutex_try_lock(md_mutex_t * md_mutex)
{
 op_t op_type = MD_TRY_LOCK;
 return md_mutex_func(md_mutex,op_type);
}

canonical_original_code:
int md_mutex_try_lock(struct md_mutex_t *md_mutex)
{
 enum op_t op_type = MD_TRY_LOCK;
 return md_mutex_func(md_mutex,op_type);
}

user_defined_types: enum op_t { MD_LOCK=0, MD_TRY_LOCK=1, MD_UNLOCK=2 }


decompiled_code:
__int64 __fastcall md_mutex_unlock(char *a1)
{
return md_mutex_func(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
return func8(a1, 2);
}

original_code:
int md_mutex_unlock(md_mutex_t * md_mutex)
{
 op_t op_type = MD_UNLOCK;
 return md_mutex_func(md_mutex,op_type);
}

canonical_original_code:
int md_mutex_unlock(struct md_mutex_t *md_mutex)
{
 enum op_t op_type = MD_UNLOCK;
 return md_mutex_func(md_mutex,op_type);
}


decompiled_code:
__int64 __fastcall hash_func(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
return v2 % 0x65;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
return v2 % 0x65;
}

original_code:
unsigned int hash_func(char * str)
{
 unsigned int seed = 131;
 unsigned int hash = 0;
 unsigned char * p = (unsigned char *)str;
 while(*p != '\0')
 {
  hash = hash * seed + (*p++);
 }
 return hash % 101;
}

canonical_original_code:
unsigned int hash_func(char *str)
{
 unsigned int seed = 131;
 unsigned int hash = 0;
 unsigned char *p = (unsigned char *)str;
 while(*p != '\0')
 {
  hash = hash * seed + (*p++);
 }
 return hash % 101;
}

variable_types:
str
char *

variable_types:
seed
unsigned int

variable_types:
hash
unsigned int

variable_types:
p
unsigned char *


version

repo: badnack/Yalzi

decompiled_code:
int version()
{
return fprintf(stdout, "Yalzi v%s, (C) 2012-2013 n.redini@gmail.com me@nebirhos.com pelldav@gmail.com\n", "0.1.0");
}

canonical_decompiled_code:
int func0()
{
return fprintf(stdout, "Yalzi v%s, (C) 2012-2013 n.redini@gmail.com me@nebirhos.com pelldav@gmail.com\n", "0.1.0");
}

original_code:
void version()
{
  fprintf(stdout, "Yalzi v%s, (C) 2012-2013 n.redini@gmail.com me@nebirhos.com pelldav@gmail.com\n", "0.1.0");
}


usage

decompiled_code:
size_t usage()
{
fwrite("Usage:\n yalzi -[c|x] FILE [OUT_FILE]\n\n", 1uLL, 0x27uLL, stdout);
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(
" -c, [--compress=FILE] # Compress FILE to OUT_FILE [default OUT_FILE: FILE.ylz]\n",
1uLL,
0x5CuLL,
stdout);
fwrite(" -x, [--extract=FILE] # Extract from FILE to OUT_FILE\n", 1uLL, 0x43uLL, stdout);
fwrite(" -v, [--verbose] # Print useless info\n", 1uLL, 0x38uLL, stdout);
fwrite(" -h, [--help] # Show this help message and quit\n", 1uLL, 0x45uLL, stdout);
return fwrite(" -V, [--version] # Show Yalzi version number and quit\n", 1uLL, 0x48uLL, stdout);
}

canonical_decompiled_code:
size_t func1()
{
fwrite("Usage:\n yalzi -[c|x] FILE [OUT_FILE]\n\n", 1uLL, 0x27uLL, stdout);
fwrite("Options:\n", 1uLL, 9uLL, stdout);
fwrite(
" -c, [--compress=FILE] # Compress FILE to OUT_FILE [default OUT_FILE: FILE.ylz]\n",
1uLL,
0x5CuLL,
stdout);
fwrite(" -x, [--extract=FILE] # Extract from FILE to OUT_FILE\n", 1uLL, 0x43uLL, stdout);
fwrite(" -v, [--verbose] # Print useless info\n", 1uLL, 0x38uLL, stdout);
fwrite(" -h, [--help] # Show this help message and quit\n", 1uLL, 0x45uLL, stdout);
return fwrite(" -V, [--version] # Show Yalzi version number and quit\n", 1uLL, 0x48uLL, stdout);
}

original_code:
void usage()
{
  fprintf(stdout, "Usage:\n  yalzi -[c|x] FILE [OUT_FILE]\n\n");
  fprintf(stdout, "Options:\n");
  fprintf(stdout, "  -c, [--compress=FILE]            # Compress FILE to OUT_FILE [default OUT_FILE: FILE.ylz]\n");
  fprintf(stdout, "  -x, [--extract=FILE]             # Extract from FILE to OUT_FILE\n");
  fprintf(stdout, "  -v, [--verbose]                  # Print useless info\n");
  fprintf(stdout, "  -h, [--help]                     # Show this help message and quit\n");
  fprintf(stdout, "  -V, [--version]                  # Show Yalzi version number and quit\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
int v4; // eax
int v5; // er12
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // r13
char *v10; // rbp
char *v11; // rax
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // r13
__int64 v15; // rbp
__int64 v16; // rax
__int64 v17; // r13
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // r13
char *v21; // rdx
char *v22; // rdi
char *v23; // rdx
int longind; // [rsp+Ch] [rbp-3Ch] BYREF
char *v25; // [rsp+10h] [rbp-38h] BYREF
char *ptr; // [rsp+18h] [rbp-30h] BYREF

v3 = 0;
verbose_flag = 0;
v25 = 0LL;
ptr = 0LL;
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "c:x:vhV", &long_options_0, &longind);
v5 = v4;
if ( v4 == -1 )
break;
if ( v4 == 99 )
{
v3 = 99;
ptr = optarg;
}
else if ( v4 > 99 )
{
if ( v4 == 118 )
{
verbose_flag = 1;
}
else
{
if ( v4 != 120 )
goto LABEL_15;
v3 = 120;
v25 = optarg;
}
}
else if ( v4 )
{
if ( v4 == 86 )
version();
else
LABEL_15:
usage();
return 0;
}
}
if ( verbose_flag )
fwrite("Verbose flag is set\n", 1uLL, 0x14uLL, stdout);
if ( v3 == 99 )
{
if ( optind < argc )
{
v25 = (char *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", ptr, v25);
print_verbose("Compression mode\n");
v15 = bitio_open(ptr, 0LL);
if ( !v15 )
{
LABEL_40:
fprintf(stderr, "Error: cannot open %s!\n", ptr);
return v5;
}
v16 = bitio_open(v25, 1LL);
v17 = v16;
if ( v16 )
{
compress(v15, v16);
bitio_close(v15);
bitio_close(v17);
return 0;
}
goto LABEL_39;
}
if ( asprintf(&v25, "%s.ylz", ptr) != -1 )
{
print_verbose("File path: %s\nArchive path: %s\n", ptr, v25);
print_verbose("Compression mode\n");
v18 = bitio_open(ptr, 0LL);
if ( v18 )
{
v19 = bitio_open(v25, 1LL);
v20 = v19;
if ( v19 )
{
compress(v18, v19);
bitio_close(v18);
bitio_close(v20);
free(v25);
return 0;
}
v23 = v25;
}
else
{
v23 = ptr;
}
fprintf(stderr, "Error: cannot open %s!\n", v23);
free(v25);
return v5;
}
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v22 = v25;
if ( !v25 )
return v5;
LABEL_45:
free(v22);
return -1;
}
if ( v3 != 120 )
{
fwrite("Error: no mode has been specified!\n", 1uLL, 0x23uLL, stderr);
usage();
return v5;
}
if ( optind < argc )
{
ptr = (char *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", ptr, v25);
print_verbose("Deompression mode\n");
v7 = bitio_open(v25, 0LL);
if ( v7 )
{
v8 = bitio_open(ptr, 1LL);
v9 = v8;
if ( v8 )
{
decompress(v7, v8);
bitio_close(v7);
bitio_close(v9);
return 0;
}
goto LABEL_40;
}
LABEL_39:
fprintf(stderr, "Error: cannot open %s!\n", v25);
return v5;
}
if ( asprintf(&ptr, "%s.out", v25) == -1 )
{
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v22 = ptr;
if ( !ptr )
return v5;
goto LABEL_45;
}
v10 = ptr;
v11 = strstr(ptr, ".ylz");
if ( v11 )
{
*v11 = 0;
v10 = ptr;
}
print_verbose("File path: %s\nArchive path: %s\n", v10, v25);
print_verbose("Deompression mode\n");
v12 = bitio_open(v25, 0LL);
if ( v12 )
{
v13 = bitio_open(ptr, 1LL);
v14 = v13;
if ( v13 )
{
decompress(v12, v13);
bitio_close(v12);
bitio_close(v14);
free(ptr);
return 0;
}
v21 = ptr;
}
else
{
v21 = v25;
}
fprintf(stderr, "Error: cannot open %s!\n", v21);
free(ptr);
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
int v4; // eax
int v5; // er12
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // r13
char *v10; // rbp
char *v11; // rax
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // r13
__int64 v15; // rbp
__int64 v16; // rax
__int64 v17; // r13
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // r13
char *v21; // rdx
char *v22; // rdi
char *v23; // rdx
int longind; // [rsp+Ch] [rbp-3Ch] BYREF
char *v25; // [rsp+10h] [rbp-38h] BYREF
char *ptr; // [rsp+18h] [rbp-30h] BYREF

v3 = 0;
verbose_flag = 0;
v25 = 0LL;
ptr = 0LL;
while ( 1 )
{
longind = 0;
v4 = getopt_long(argc, (char *const *)argv, "c:x:vhV", &long_options_0, &longind);
v5 = v4;
if ( v4 == -1 )
break;
if ( v4 == 99 )
{
v3 = 99;
ptr = optarg;
}
else if ( v4 > 99 )
{
if ( v4 == 118 )
{
verbose_flag = 1;
}
else
{
if ( v4 != 120 )
goto LABEL_15;
v3 = 120;
v25 = optarg;
}
}
else if ( v4 )
{
if ( v4 == 86 )
func0();
else
LABEL_15:
func1();
return 0;
}
}
if ( verbose_flag )
fwrite("Verbose flag is set\n", 1uLL, 0x14uLL, stdout);
if ( v3 == 99 )
{
if ( optind < argc )
{
v25 = (char *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", ptr, v25);
print_verbose("Compression mode\n");
v15 = bitio_open(ptr, 0LL);
if ( !v15 )
{
LABEL_40:
fprintf(stderr, "Error: cannot open %s!\n", ptr);
return v5;
}
v16 = bitio_open(v25, 1LL);
v17 = v16;
if ( v16 )
{
compress(v15, v16);
bitio_close(v15);
bitio_close(v17);
return 0;
}
goto LABEL_39;
}
if ( asprintf(&v25, "%s.ylz", ptr) != -1 )
{
print_verbose("File path: %s\nArchive path: %s\n", ptr, v25);
print_verbose("Compression mode\n");
v18 = bitio_open(ptr, 0LL);
if ( v18 )
{
v19 = bitio_open(v25, 1LL);
v20 = v19;
if ( v19 )
{
compress(v18, v19);
bitio_close(v18);
bitio_close(v20);
free(v25);
return 0;
}
v23 = v25;
}
else
{
v23 = ptr;
}
fprintf(stderr, "Error: cannot open %s!\n", v23);
free(v25);
return v5;
}
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v22 = v25;
if ( !v25 )
return v5;
LABEL_45:
free(v22);
return -1;
}
if ( v3 != 120 )
{
fwrite("Error: no mode has been specified!\n", 1uLL, 0x23uLL, stderr);
func1();
return v5;
}
if ( optind < argc )
{
ptr = (char *)argv[optind];
print_verbose("File path: %s\nArchive path: %s\n", ptr, v25);
print_verbose("Deompression mode\n");
v7 = bitio_open(v25, 0LL);
if ( v7 )
{
v8 = bitio_open(ptr, 1LL);
v9 = v8;
if ( v8 )
{
decompress(v7, v8);
bitio_close(v7);
bitio_close(v9);
return 0;
}
goto LABEL_40;
}
LABEL_39:
fprintf(stderr, "Error: cannot open %s!\n", v25);
return v5;
}
if ( asprintf(&ptr, "%s.out", v25) == -1 )
{
fwrite("Error: unable to allocate memory!\n", 1uLL, 0x22uLL, stderr);
v22 = ptr;
if ( !ptr )
return v5;
goto LABEL_45;
}
v10 = ptr;
v11 = strstr(ptr, ".ylz");
if ( v11 )
{
*v11 = 0;
v10 = ptr;
}
print_verbose("File path: %s\nArchive path: %s\n", v10, v25);
print_verbose("Deompression mode\n");
v12 = bitio_open(v25, 0LL);
if ( v12 )
{
v13 = bitio_open(ptr, 1LL);
v14 = v13;
if ( v13 )
{
decompress(v12, v13);
bitio_close(v12);
bitio_close(v14);
free(ptr);
return 0;
}
v21 = ptr;
}
else
{
v21 = v25;
}
fprintf(stderr, "Error: cannot open %s!\n", v21);
free(ptr);
return v5;
}

original_code:
int main(int argc, char *argv[])
{
  char *archive_path = ((void *)0), *file_path = ((void *)0);
  char mode = 0;
  BITIO* in_file = ((void *)0), *out_file = ((void *)0);
  int i;
  int cst_alloc_fp, cst_alloc_ap;
  verbose_flag = 0;
  cst_alloc_fp = 0;
  cst_alloc_ap = 0;
  while (1) {
    static struct option long_options[] = {
      {"compress", 1, 0, 'c'},
      {"extract", 1, 0, 'x'},
      {"help", 0, 0, 'h'},
      {"version", 0, 0, 'V'},
      {"verbose", 0, &verbose_flag, 1},
      {0, 0, 0, 0}
    };
    int option_index = 0;
    i = getopt_long(argc, argv, "c:x:vhV",
                    long_options, &option_index);
    if (i == -1)
      break;
    switch (i) {
    case 0:
      break;
    case 'v':
      verbose_flag = 1;
      break;
    case 'c':
      mode = i;
      file_path = optarg;
      break;
    case 'x':
      mode = i;
      archive_path = optarg;
      break;
    case 'V':
      version();
      return 0;
    case 'h':
    case '?':
    default:
      usage();
      return 0;
    }
  }
  if (verbose_flag)
    fprintf(stdout, "Verbose flag is set\n");
  if (mode == 'c') {
    if (optind < argc)
      archive_path = argv[optind];
    else{
      cst_alloc_ap = 1;
      if (asprintf(&archive_path, "%s.ylz", file_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (archive_path != ((void *)0))
          free(archive_path);
        return -1;
      }
    }
  }
  else if (mode == 'x') {
    if (optind < argc) {
      file_path = argv[optind];
    }
    else {
      cst_alloc_fp = 1;
      if (asprintf(&file_path, "%s.out", archive_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (file_path != ((void *)0))
          free(file_path);
        return -1;
      }
      char* extension = strstr(file_path, ".ylz");
      if (extension)
        *extension = '\0';
    }
  }
  else {
    fprintf(stderr, "Error: no mode has been specified!\n");
    usage();
    return -1;
  }
  print_verbose("File path: %s\nArchive path: %s\n", file_path, archive_path);
  if (mode == 'c') {
    print_verbose("Compression mode\n");
    if ((in_file = bitio_open(file_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    if ((out_file = bitio_open(archive_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    compress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_ap)
      free(archive_path);
  }
  else if (mode == 'x') {
    print_verbose("Deompression mode\n");
    if ((in_file = bitio_open(archive_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    if ((out_file = bitio_open(file_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    decompress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_fp)
      free(file_path);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *archive_path = ((void *)0); char *file_path = ((void *)0);
  char mode = 0;
  struct BITIO *in_file = ((void *)0); struct BITIO *out_file = ((void *)0);
  int i;
  int cst_alloc_fp; int cst_alloc_ap;
  verbose_flag = 0;
  cst_alloc_fp = 0;
  cst_alloc_ap = 0;
  while (1) {
    static struct option long_options[] = {
      {"compress", 1, 0, 'c'},
      {"extract", 1, 0, 'x'},
      {"help", 0, 0, 'h'},
      {"version", 0, 0, 'V'},
      {"verbose", 0, &verbose_flag, 1},
      {0, 0, 0, 0}
    };
    int option_index = 0;
    i = getopt_long(argc, argv, "c:x:vhV",
                    long_options, &option_index);
    if (i == -1)
      break;
    switch (i) {
    case 0:
      break;
    case 'v':
      verbose_flag = 1;
      break;
    case 'c':
      mode = i;
      file_path = optarg;
      break;
    case 'x':
      mode = i;
      archive_path = optarg;
      break;
    case 'V':
      version();
      return 0;
    case 'h':
    case '?':
    default:
      usage();
      return 0;
    }
  }
  if (verbose_flag)
    fprintf(stdout, "Verbose flag is set\n");
  if (mode == 'c') {
    if (optind < argc)
      archive_path = argv[optind];
    else{
      cst_alloc_ap = 1;
      if (asprintf(&archive_path, "%s.ylz", file_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (archive_path != ((void *)0))
          free(archive_path);
        return -1;
      }
    }
  }
  else if (mode == 'x') {
    if (optind < argc) {
      file_path = argv[optind];
    }
    else {
      cst_alloc_fp = 1;
      if (asprintf(&file_path, "%s.out", archive_path) == -1) {
        fprintf(stderr, "Error: unable to allocate memory!\n");
        if (file_path != ((void *)0))
          free(file_path);
        return -1;
      }
      char *extension = strstr(file_path, ".ylz");
      if (extension)
        *extension = '\0';
    }
  }
  else {
    fprintf(stderr, "Error: no mode has been specified!\n");
    usage();
    return -1;
  }
  print_verbose("File path: %s\nArchive path: %s\n", file_path, archive_path);
  if (mode == 'c') {
    print_verbose("Compression mode\n");
    if ((in_file = bitio_open(file_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    if ((out_file = bitio_open(archive_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_ap)
        free(archive_path);
      return -1;
    }
    compress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_ap)
      free(archive_path);
  }
  else if (mode == 'x') {
    print_verbose("Deompression mode\n");
    if ((in_file = bitio_open(archive_path, 00)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", archive_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    if ((out_file = bitio_open(file_path, 01)) == ((void *)0)) {
      fprintf(stderr, "Error: cannot open %s!\n", file_path);
      if (cst_alloc_fp)
        free(file_path);
      return -1;
    }
    decompress(in_file, out_file);
    bitio_close(in_file);
    bitio_close(out_file);
    if (cst_alloc_fp)
      free(file_path);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: mode char

variable_types: struct BITIO { int fd; unsigned int first; unsigned int empty; int mode; unsigned long buf[-1]; } *

variable_types: i int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types:
extension
char *


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
inline static int
min(int x1, int x2)
{
  return (x1 <= x2) ? x1 : x2;
}


original_code:
static int
fix_write(BITIO* bip, env_var src, size_t src_len)
{
  int index;
  int offset;
  int bits_to_write;
  env_var mask;
  if (src_len > (sizeof(env_var) * 8)) {
      (*__errno_location ()) = 22;
      return -1;
  }
  while (src_len > 0) {
    index = (bip->empty) / (sizeof(env_var) * 8);
    offset = (bip->empty) % (sizeof(env_var) * 8);
    bits_to_write = min((sizeof(env_var) * 8) - offset, src_len);
    mask = (bits_to_write == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : ((((env_var)1) << bits_to_write) - 1);
    bip->buf[index] &= (bits_to_write == (sizeof(env_var) * 8)) ? 0 : (((env_var)1) << offset) - 1;
    bip->buf[index] |= (src & mask) << offset;
    src_len -= bits_to_write;
    bip->empty += bits_to_write;
    if (bip->empty >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8)) {
      if (store_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var))) == -1)
        return -1;
      bip->empty = 0;
    }
    src >>= bits_to_write;
  }
  return 0;
}

canonical_original_code:
static int fix_write(struct BITIO *bip, unsigned long src, unsigned long src_len)
{
  int index;
  int offset;
  int bits_to_write;
  unsigned long mask;
  if (src_len > (sizeof(env_var) * 8)) {
      (*__errno_location ()) = 22;
      return -1;
  }
  while (src_len > 0) {
    index = (bip->empty) / (sizeof(env_var) * 8);
    offset = (bip->empty) % (sizeof(env_var) * 8);
    bits_to_write = min((sizeof(env_var) * 8) - offset, src_len);
    mask = (bits_to_write == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : ((((unsigned long)1) << bits_to_write) - 1);
    bip->buf[index] &= (bits_to_write == (sizeof(env_var) * 8)) ? 0 : (((unsigned long)1) << offset) - 1;
    bip->buf[index] |= (src & mask) << offset;
    src_len -= bits_to_write;
    bip->empty += bits_to_write;
    if (bip->empty >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8)) {
      if (store_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var))) == -1)
        return -1;
      bip->empty = 0;
    }
    src >>= bits_to_write;
  }
  return 0;
}

variable_types:
src
unsigned long

variable_types: index int

variable_types: offset int

variable_types:
mask
unsigned long

user_defined_types: struct BITIO { int fd; unsigned int first; unsigned int empty; int mode; unsigned long buf[-1]; }


original_code:
static int
fix_read(BITIO* bip, env_var* dst, size_t dst_len)
{
  int err;
  int bits_to_read;
  int read_bits = 0;
  int index;
  int offset;
  env_var mask;
  if (dst_len > (sizeof(env_var) * 8)) {
    (*__errno_location ()) = 22;
    return -1;
  }
  while (dst_len > 0) {
    if (bip->first >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8) || bip->empty <= bip->first) {
      if ((err = load_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var)))) == -1)
        return -1;
      bip->first = 0;
      bip->empty = err * 8;
      if (bip->empty == 0)
        return read_bits;
    }
    index = (bip->first) / (sizeof(env_var) * 8);
    offset = (bip->first) % (sizeof(env_var) * 8);
    bits_to_read = min((sizeof(env_var) * 8) - offset, min(dst_len, bip->empty - bip->first));
    mask = (bits_to_read == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : (((((env_var)1) << bits_to_read) - 1) << offset);
    *dst &= (bits_to_read == (sizeof(env_var) * 8)) ? 0 : ~((((env_var)1 << bits_to_read) - 1) << read_bits);
    *dst |= (offset - read_bits > 0) ? ((env_var)(bip->buf[index] & mask) >> (offset - read_bits)) : ((env_var)(bip->buf[index] & mask) << (read_bits - offset));
    dst_len -= bits_to_read;
    bip->first += bits_to_read;
    read_bits += bits_to_read;
  }
  return read_bits;
}

canonical_original_code:
static int fix_read(struct BITIO *bip, unsigned long *dst, unsigned long dst_len)
{
  int err;
  int bits_to_read;
  int read_bits = 0;
  int index;
  int offset;
  unsigned long mask;
  if (dst_len > (sizeof(env_var) * 8)) {
    (*__errno_location ()) = 22;
    return -1;
  }
  while (dst_len > 0) {
    if (bip->first >= (4096 / (sizeof(env_var))) * (sizeof(env_var) * 8) || bip->empty <= bip->first) {
      if ((err = load_buffer(bip, ((4096 / (sizeof(env_var))) * sizeof(env_var)))) == -1)
        return -1;
      bip->first = 0;
      bip->empty = err * 8;
      if (bip->empty == 0)
        return read_bits;
    }
    index = (bip->first) / (sizeof(env_var) * 8);
    offset = (bip->first) % (sizeof(env_var) * 8);
    bits_to_read = min((sizeof(env_var) * 8) - offset, min(dst_len, bip->empty - bip->first));
    mask = (bits_to_read == (sizeof(env_var) * 8)) ? 0xFFFFFFFFFFFFFFFF : (((((unsigned long)1) << bits_to_read) - 1) << offset);
    *dst &= (bits_to_read == (sizeof(env_var) * 8)) ? 0 : ~((((unsigned long)1 << bits_to_read) - 1) << read_bits);
    *dst |= (offset - read_bits > 0) ? ((env_var)(bip->buf[index] & mask) >> (offset - read_bits)) : ((env_var)(bip->buf[index] & mask) << (read_bits - offset));
    dst_len -= bits_to_read;
    bip->first += bits_to_read;
    read_bits += bits_to_read;
  }
  return read_bits;
}

variable_types:
dst
unsigned long *

variable_types: err int


decompiled_code:
__int64 __fastcall bitio_write(int *a1, unsigned __int64 *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbp
int v4; // eax
unsigned __int64 *v5; // rbx
__int64 v6; // r13
__int64 v7; // r14
__int64 result; // rax

v3 = a3;
v4 = (a3 >> 6) + ((a3 & 0x3F) != 0);
if ( a2 == 0LL || a1 == 0LL || !a3 )
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else if ( a1[3] == 1 )
{
if ( v4 <= 0 )
{
LABEL_11:
result = 0LL;
}
else
{
v5 = a2;
v6 = (__int64)&a2[(unsigned int)(v4 - 1) + 1];
while ( 1 )
{
v7 = 64LL;
if ( v3 <= 0x40 )
v7 = v3;
result = fix_write(a1, *v5, v7);
if ( (_DWORD)result == -1 )
break;
++v5;
v3 -= v7;
if ( v5 == (unsigned __int64 *)v6 )
goto LABEL_11;
}
}
}
else
{
*_errno_location() = 9;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, unsigned __int64 *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbp
int v4; // eax
unsigned __int64 *v5; // rbx
__int64 v6; // r13
__int64 v7; // r14
__int64 result; // rax

v3 = a3;
v4 = (a3 >> 6) + ((a3 & 0x3F) != 0);
if ( a2 == 0LL || a1 == 0LL || !a3 )
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
else if ( a1[3] == 1 )
{
if ( v4 <= 0 )
{
LABEL_11:
result = 0LL;
}
else
{
v5 = a2;
v6 = (__int64)&a2[(unsigned int)(v4 - 1) + 1];
while ( 1 )
{
v7 = 64LL;
if ( v3 <= 0x40 )
v7 = v3;
result = func3(a1, *v5, v7);
if ( (_DWORD)result == -1 )
break;
++v5;
v3 -= v7;
if ( v5 == (unsigned __int64 *)v6 )
goto LABEL_11;
}
}
}
else
{
*_errno_location() = 9;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
bitio_write(BITIO* bip, env_var* data, size_t src_len)
{
  int b_steps = src_len / (sizeof(env_var) * 8) + ((src_len % (sizeof(env_var) * 8)) > 0);
  int i,size;
  if (bip == ((void *)0) || data == ((void *)0) || src_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 01) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (src_len > (sizeof(env_var) * 8)) ? ((sizeof(env_var) * 8)) : src_len;
    if (fix_write(bip, data[i], size) == -1)
      return -1;
    src_len -= size;
  }
  return 0;
}

canonical_original_code:
int bitio_write(struct BITIO *bip, unsigned long *data, unsigned long src_len)
{
  int b_steps = src_len / (sizeof(env_var) * 8) + ((src_len % (sizeof(env_var) * 8)) > 0);
  int i; int size;
  if (bip == ((void *)0) || data == ((void *)0) || src_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 01) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (src_len > (sizeof(env_var) * 8)) ? ((sizeof(env_var) * 8)) : src_len;
    if (fix_write(bip, data[i], size) == -1)
      return -1;
    src_len -= size;
  }
  return 0;
}

variable_types:
data
unsigned long *

variable_types: size int


original_code:
int
bitio_read(BITIO* bip, env_var* data, size_t dst_len)
{
  int read_bits = 0;
  int b_steps = dst_len / (sizeof(env_var) * 8) + ((dst_len % (sizeof(env_var) * 8)) > 0);
  int i,size;
  if (data == ((void *)0) || bip == ((void *)0) || dst_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 00) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (dst_len > (sizeof(env_var) * 8)) ? (sizeof(env_var) * 8) : dst_len;
    if ((read_bits += fix_read(bip, &data[i], size)) <= 0)
      return -1;
    dst_len -= size;
  }
  return read_bits;
}

canonical_original_code:
int bitio_read(struct BITIO *bip, unsigned long *data, unsigned long dst_len)
{
  int read_bits = 0;
  int b_steps = dst_len / (sizeof(env_var) * 8) + ((dst_len % (sizeof(env_var) * 8)) > 0);
  int i; int size;
  if (data == ((void *)0) || bip == ((void *)0) || dst_len <= 0) {
    (*__errno_location ()) = 22;
    return -1;
  }
  if (bip->mode != 00) {
    (*__errno_location ()) = 9;
    return -1;
  }
  for (i = 0; i < b_steps; i++) {
    size = (dst_len > (sizeof(env_var) * 8)) ? (sizeof(env_var) * 8) : dst_len;
    if ((read_bits += fix_read(bip, &data[i], size)) <= 0)
      return -1;
    dst_len -= size;
  }
  return read_bits;
}


decompiled_code:
__int64 __fastcall bitio_close(void *ptr)
{
unsigned int v1; // er12
unsigned int v3; // eax
unsigned int v4; // edx
int v5; // ecx

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) == 1 )
{
v3 = *((_DWORD *)ptr + 2);
if ( v3 )
{
v4 = v3 >> 6;
v5 = *((_DWORD *)ptr + 2) & 0x3F;
if ( (v3 & 0x3F) != 0 )
*((_QWORD *)ptr + (int)v4 + 2) &= ~(-1LL << v5);
store_buffer((int *)ptr, ((v3 & 7) != 0) + (__int64)(v5 >> 3) + 8LL * v4);
}
}
v1 = close(*(_DWORD *)ptr);
free(ptr);
}
else
{
v1 = -1;
*_errno_location() = 22;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
unsigned int v1; // er12
unsigned int v3; // eax
unsigned int v4; // edx
int v5; // ecx

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) == 1 )
{
v3 = *((_DWORD *)ptr + 2);
if ( v3 )
{
v4 = v3 >> 6;
v5 = *((_DWORD *)ptr + 2) & 0x3F;
if ( (v3 & 0x3F) != 0 )
*((_QWORD *)ptr + (int)v4 + 2) &= ~(-1LL << v5);
func2((int *)ptr, ((v3 & 7) != 0) + (__int64)(v5 >> 3) + 8LL * v4);
}
}
v1 = close(*(_DWORD *)ptr);
free(ptr);
}
else
{
v1 = -1;
*_errno_location() = 22;
}
return v1;
}

original_code:
int
bitio_close(BITIO* bip)
{
  int err, index, offset;
  if (bip == ((void *)0)){
    (*__errno_location ()) = 22;
    return -1;
  }
  err = 0;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((env_var)1 << offset) - 1;
    store_buffer(bip, index * sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
  }
  err = close(bip->fd);
  memset(bip, 0, sizeof(BITIO));
  free(bip);
  return err;
}

canonical_original_code:
int bitio_close(struct BITIO *bip)
{
  int err; int index; int offset;
  if (bip == ((void *)0)){
    (*__errno_location ()) = 22;
    return -1;
  }
  err = 0;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((unsigned long)1 << offset) - 1;
    store_buffer(bip, index * sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
  }
  err = close(bip->fd);
  memset(bip, 0, sizeof(BITIO));
  free(bip);
  return err;
}


original_code:
void
bitio_flush(BITIO* bip)
{
  int index, offset;
  if (bip == ((void *)0))
    return;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((env_var)1 << offset) - 1;
    store_buffer(bip, index*sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
    bip->empty = 0;
    bip->first = 0;
  }
  memset(bip->buf, 0, ((4096 / (sizeof(env_var))) * sizeof(env_var)));
}

canonical_original_code:
void bitio_flush(struct BITIO *bip)
{
  int index; int offset;
  if (bip == ((void *)0))
    return;
  if (bip->mode == 01 && bip->empty > 0) {
    index = bip->empty / (sizeof(env_var) * 8);
    if ((offset = (bip->empty % (sizeof(env_var) * 8))))
      bip->buf[index] &= ((unsigned long)1 << offset) - 1;
    store_buffer(bip, index*sizeof(env_var) + (offset / 8) + ((offset % 8) > 0));
    bip->empty = 0;
    bip->first = 0;
  }
  memset(bip->buf, 0, ((4096 / (sizeof(env_var))) * sizeof(env_var)));
}


decompiled_code:
__int64 __fastcall hashtable_insert(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
int v4; // er13
int v5; // ebp
unsigned int i; // eax
_DWORD *v7; // rdx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = a3;
if ( a3 > 0x3FFFFF )
return 0xFFFFFFFFLL;
v5 = a4;
for ( i = get_hash(a2, a4); ; i = (i + 1) & 0x7FFFFF )
{
v7 = (_DWORD *)(a1 + 12LL * i);
if ( !v7[2] )
break;
}
v7[2] = v4;
result = 0LL;
*v7 = a2;
v7[1] = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
int v4; // er13
int v5; // ebp
unsigned int i; // eax
_DWORD *v7; // rdx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = a3;
if ( a3 > 0x3FFFFF )
return 0xFFFFFFFFLL;
v5 = a4;
for ( i = get_hash(a2, a4); ; i = (i + 1) & 0x7FFFFF )
{
v7 = (_DWORD *)(a1 + 12LL * i);
if ( !v7[2] )
break;
}
v7[2] = v4;
result = 0LL;
*v7 = a2;
v7[1] = v5;
return result;
}

original_code:
int
hashtable_insert(hashtable* ht, env_var f_label, env_var c_label, env_var c_value)
{
  uint32_t index;
  if (ht == ((void *)0) || c_label > 4194303)
    return -1;
  index = get_hash(f_label, c_value);
  while (ht[index].c_label)
    index = (index + 1) % 8388608;
  ht[index].c_label = c_label;
  ht[index].f_label = f_label;
  ht[index].c_value = c_value;
  return 0;
}

canonical_original_code:
int hashtable_insert(struct hashtable_entry *ht, unsigned long f_label, unsigned long c_label, unsigned long c_value)
{
  unsigned int index;
  if (ht == ((void *)0) || c_label > 4194303)
    return -1;
  index = get_hash(f_label, c_value);
  while (ht[index].c_label)
    index = (index + 1) % 8388608;
  ht[index].c_label = c_label;
  ht[index].f_label = f_label;
  ht[index].c_value = c_value;
  return 0;
}

variable_types: struct hashtable_entry { unsigned int f_label; unsigned int c_value; unsigned int c_label; } *

variable_types:
index
unsigned int


decompiled_code:
__int64 __fastcall hashtable_get_index(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int i; // eax
_DWORD *v5; // rdx
unsigned int v6; // ecx

if ( !a1 )
return -1LL;
for ( i = get_hash(a2, a3); ; i = (i + 1) & 0x7FFFFF )
{
v5 = (_DWORD *)(a1 + 12LL * i);
v6 = v5[2];
if ( !v6 )
break;
if ( v5[1] == a3 && *v5 == a2 )
return v6;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int i; // eax
_DWORD *v5; // rdx
unsigned int v6; // ecx

if ( !a1 )
return -1LL;
for ( i = get_hash(a2, a3); ; i = (i + 1) & 0x7FFFFF )
{
v5 = (_DWORD *)(a1 + 12LL * i);
v6 = v5[2];
if ( !v6 )
break;
if ( v5[1] == a3 && *v5 == a2 )
return v6;
}
return 0LL;
}

original_code:
env_var
hashtable_get_index(hashtable* ht, env_var f_label, env_var c_value)
{
  uint32_t h_index;
  if (ht == ((void *)0))
    return -1;
  h_index = get_hash(f_label, c_value);
  while (ht[h_index].c_label && (ht[h_index].c_value != c_value || ht[h_index].f_label != f_label))
    h_index = (h_index + 1) % 8388608;
  return ht[h_index].c_label;
}

canonical_original_code:
unsigned long hashtable_get_index(struct hashtable_entry *ht, unsigned long f_label, unsigned long c_value)
{
  unsigned int h_index;
  if (ht == ((void *)0))
    return -1;
  h_index = get_hash(f_label, c_value);
  while (ht[h_index].c_label && (ht[h_index].c_value != c_value || ht[h_index].f_label != f_label))
    h_index = (h_index + 1) % 8388608;
  return ht[h_index].c_label;
}

return_type: unsigned long

user_defined_types: struct hashtable_entry { unsigned int f_label; unsigned int c_value; unsigned int c_label; }


decompiled_code:
// attributes: thunk
void hashtable_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func2(void *ptr)
{
free(ptr);
}

original_code:
void
hashtable_destroy(hashtable* ht)
{
  memset(ht, 0, 8388608* sizeof(hashtable));
  free(ht);
}

canonical_original_code:
void hashtable_destroy(struct hashtable_entry *ht)
{
  memset(ht, 0, 8388608* sizeof(hashtable));
  free(ht);
}


decompiled_code:
__int64 __fastcall init_dictionary(void *ptr)
{
unsigned __int64 v1; // rbx
__int64 v2; // rcx

if ( !ptr )
return 0xFFFFFFFFLL;
v1 = 0LL;
memset(ptr, 0, 0x6000000uLL);
do
{
v2 = v1++;
if ( (unsigned int)hashtable_insert((__int64)ptr, 0LL, v1, v2) == -1 )
{
hashtable_destroy(ptr);
return 0xFFFFFFFFLL;
}
}
while ( v1 != 256 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
unsigned __int64 v1; // rbx
__int64 v2; // rcx

if ( !ptr )
return 0xFFFFFFFFLL;
v1 = 0LL;
memset(ptr, 0, 0x6000000uLL);
do
{
v2 = v1++;
if ( (unsigned int)func0((__int64)ptr, 0LL, v1, v2) == -1 )
{
func2(ptr);
return 0xFFFFFFFFLL;
}
}
while ( v1 != 256 );
return 0LL;
}

original_code:
static int
init_dictionary(hashtable* ht)
{
  int i;
  if (ht == ((void *)0))
    return -1;
  memset(ht, 0, 8388608 * sizeof(hashtable));
  for (i = 0; i < 257 - 1; i++) {
    if (hashtable_insert(ht, 0, (env_var)i+1, (env_var)i) == -1) {
      hashtable_destroy(ht);
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
static int init_dictionary(struct hashtable_entry *ht)
{
  int i;
  if (ht == ((void *)0))
    return -1;
  memset(ht, 0, 8388608 * sizeof(hashtable));
  for (i = 0; i < 257 - 1; i++) {
    if (hashtable_insert(ht, 0, (unsigned long)i+1, (unsigned long)i) == -1) {
      hashtable_destroy(ht);
      return -1;
    }
  }
  return 0;
}


decompiled_code:
void *hashtable_create()
{
void *v0; // rax
void *v1; // r12

v0 = calloc(0x800000uLL, 0xCuLL);
if ( !v0 || (v1 = v0, (unsigned int)init_dictionary(v0) == -1) )
v1 = 0LL;
return v1;
}

canonical_decompiled_code:
void *func4()
{
void *v0; // rax
void *v1; // r12

v0 = calloc(0x800000uLL, 0xCuLL);
if ( !v0 || (v1 = v0, (unsigned int)func3(v0) == -1) )
v1 = 0LL;
return v1;
}

original_code:
hashtable*
hashtable_create()
{
  hashtable* ht;
  if ((ht = (hashtable_entry*)calloc(8388608, sizeof(hashtable_entry))) == ((void *)0) )
    return ((void *)0);
  if (init_dictionary(ht) == -1)
    return ((void *)0);
  return ht;
}

canonical_original_code:
struct hashtable_entry *hashtable_create()
{
  struct hashtable_entry *ht;
  if ((ht = (struct hashtable_entry *)calloc(8388608, sizeof(hashtable_entry))) == ((void *)0) )
    return ((void *)0);
  if (init_dictionary(ht) == -1)
    return ((void *)0);
  return ht;
}

return_type: struct hashtable_entry { unsigned int f_label; unsigned int c_value; unsigned int c_label; } *


decompiled_code:
// attributes: thunk
__int64 __fastcall hashtable_reset(void *a1)
{
return init_dictionary(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(void *a1)
{
return func3(a1);
}

original_code:
int
hashtable_reset(hashtable* ht)
{
  return init_dictionary(ht);
}

canonical_original_code:
int hashtable_reset(struct hashtable_entry *ht)
{
  return init_dictionary(ht);
}


decompiled_code:
__int64 __fastcall pre_append(__int64 a1, __int64 a2)
{
unsigned int v3; // eax
size_t v4; // rdx
char *v5; // r8
size_t v6; // rsi
__int64 result; // rax
char *v8; // rax

v3 = *(_DWORD *)(a1 + 16);
v4 = *(unsigned int *)(a2 + 16);
v5 = *(char **)(a1 + 8);
v6 = v3 + (unsigned int)v4;
if ( *(_DWORD *)(a1 + 20) < (unsigned int)v6 )
{
*(_DWORD *)(a1 + 20) = v6;
v8 = (char *)realloc(v5, v6);
v4 = *(unsigned int *)(a2 + 16);
*(_QWORD *)(a1 + 8) = v8;
v5 = v8;
v3 = *(_DWORD *)(a1 + 16);
if ( !v3 )
goto LABEL_3;
LABEL_5:
memmove(&v5[v4], v5, v3);
v4 = *(unsigned int *)(a2 + 16);
v5 = *(char **)(a1 + 8);
goto LABEL_3;
}
if ( v3 )
goto LABEL_5;
LABEL_3:
memcpy(v5, *(const void **)(a2 + 8), v4);
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) += result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v3; // eax
size_t v4; // rdx
char *v5; // r8
size_t v6; // rsi
__int64 result; // rax
char *v8; // rax

v3 = *(_DWORD *)(a1 + 16);
v4 = *(unsigned int *)(a2 + 16);
v5 = *(char **)(a1 + 8);
v6 = v3 + (unsigned int)v4;
if ( *(_DWORD *)(a1 + 20) < (unsigned int)v6 )
{
*(_DWORD *)(a1 + 20) = v6;
v8 = (char *)realloc(v5, v6);
v4 = *(unsigned int *)(a2 + 16);
*(_QWORD *)(a1 + 8) = v8;
v5 = v8;
v3 = *(_DWORD *)(a1 + 16);
if ( !v3 )
goto LABEL_3;
LABEL_5:
memmove(&v5[v4], v5, v3);
v4 = *(unsigned int *)(a2 + 16);
v5 = *(char **)(a1 + 8);
goto LABEL_3;
}
if ( v3 )
goto LABEL_5;
LABEL_3:
memcpy(v5, *(const void **)(a2 + 8), v4);
result = *(unsigned int *)(a2 + 16);
*(_DWORD *)(a1 + 16) += result;
return result;
}

original_code:
static void
pre_append(dec_table* current, dec_table* parent)
{
    if (current->word_size < (current->word_length + parent->word_length)) {
      current->word_size = current->word_length + parent->word_length;
      current->word = realloc(current->word, current->word_size);
    }
    if (current->word_length > 0) {
      memmove(current->word + parent->word_length, current->word, current->word_length);
    }
    memcpy(current->word, parent->word, parent->word_length);
    current->word_length += parent->word_length;
}

canonical_original_code:
static void pre_append(struct dec_table_entry *current, struct dec_table_entry *parent)
{
    if (current->word_size < (current->word_length + parent->word_length)) {
      current->word_size = current->word_length + parent->word_length;
      current->word = realloc(current->word, current->word_size);
    }
    if (current->word_length > 0) {
      memmove(current->word + parent->word_length, current->word, current->word_length);
    }
    memcpy(current->word, parent->word, parent->word_length);
    current->word_length += parent->word_length;
}

variable_types: struct dec_table_entry { unsigned int f_label; unsigned char *word; unsigned int word_length; unsigned int word_size; } *

variable_types:
parent
struct dec_table_entry *


decompiled_code:
void __fastcall dec_table_destroy(void *ptr)
{
void **v1; // rbx

if ( ptr )
{
v1 = (void **)((char *)ptr + 100663256);
do
{
if ( *v1 )
free(*v1);
v1 -= 3;
}
while ( v1 != (void **)((char *)ptr - 16) );
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx

if ( ptr )
{
v1 = (void **)((char *)ptr + 100663256);
do
{
if ( *v1 )
free(*v1);
v1 -= 3;
}
while ( v1 != (void **)((char *)ptr - 16) );
free(ptr);
}
}

original_code:
void
dec_table_destroy(dec_table* dt)
{
  int n = 4194303;
  if (dt == ((void *)0))
    return;
  for (; n--;)
    if(dt[n].word != 0)
      free(dt[n].word);
  memset(dt, 0, sizeof(dec_table) * 4194303);
  free(dt);
}

canonical_original_code:
void dec_table_destroy(struct dec_table_entry *dt)
{
  int n = 4194303;
  if (dt == ((void *)0))
    return;
  for (; n--;)
    if(dt[n].word != 0)
      free(dt[n].word);
  memset(dt, 0, sizeof(dec_table) * 4194303);
  free(dt);
}

variable_types: n int

user_defined_types: struct dec_table_entry { unsigned int f_label; unsigned char *word; unsigned int word_length; unsigned int word_size; }


decompiled_code:
char *dec_table_create()
{
char *v0; // rax
char *v1; // r12
char *v2; // rbx
int v3; // ebp
_BYTE *v4; // rax
char *v6; // rdi

v0 = (char *)calloc(0x3FFFFFuLL, 0x18uLL);
v1 = v0;
if ( v0 )
{
v2 = v0 + 24;
v3 = 0;
while ( 1 )
{
*((_DWORD *)v2 + 4) = 1;
*(_DWORD *)v2 = 0;
v4 = malloc(1uLL);
*((_QWORD *)v2 + 1) = v4;
if ( !v4 )
break;
*v4 = v3++;
v2 += 24;
if ( v3 == 256 )
return v1;
}
dec_table_destroy(v1);
v6 = v1;
v1 = 0LL;
free(v6);
}
return v1;
}

original_code:
dec_table*
dec_table_create()
{
  dec_table* dt;
  int i;
  if ((dt = (dec_table*) calloc(4194303, sizeof(dec_table))) == ((void *)0))
    return ((void *)0);
  for (i = 1; i < 257; i++) {
    dt[i].word_length = 1;
    dt[i].f_label = 0;
    if ((dt[i].word = malloc(1 * sizeof(uint8_t))) == ((void *)0)) {
      dec_table_destroy(dt);
      free(dt);
      return ((void *)0);
    }
    dt[i].word[0] = (uint8_t)i - 1;
  }
  return dt;
}

canonical_original_code:
struct dec_table_entry *dec_table_create()
{
  struct dec_table_entry *dt;
  int i;
  if ((dt = (struct dec_table_entry *) calloc(4194303, sizeof(dec_table))) == ((void *)0))
    return ((void *)0);
  for (i = 1; i < 257; i++) {
    dt[i].word_length = 1;
    dt[i].f_label = 0;
    if ((dt[i].word = malloc(1 * sizeof(unsigned char))) == ((void *)0)) {
      dec_table_destroy(dt);
      free(dt);
      return ((void *)0);
    }
    dt[i].word[0] = (unsigned char)i - 1;
  }
  return dt;
}

return_type: struct dec_table_entry { unsigned int f_label; unsigned char *word; unsigned int word_length; unsigned int word_size; } *


repo: baezilisK/micecraft

decompiled_code:
void rng_init()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_sec) * LODWORD(v0.tv_usec));
}

canonical_decompiled_code:
void func0()
{
struct timeval v0; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v0, 0LL);
srand(LODWORD(v0.tv_sec) * LODWORD(v0.tv_usec));
}

original_code:
void rng_init (void) {
  struct timeval tv;
  gettimeofday (&tv, ((void *)0));
  srand (tv.tv_sec * tv.tv_usec);
}

canonical_original_code:
void rng_init() {
  struct timeval tv;
  gettimeofday (&tv, ((void *)0));
  srand (tv.tv_sec * tv.tv_usec);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall rng_i(int a1)
{
return (unsigned int)(rand() / (0x7FFFFFFF / a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(rand() / (0x7FFFFFFF / a1 + 1));
}


decompiled_code:
float rng_f()
{
return (float)rand() * 4.6566129e-10;
}

canonical_decompiled_code:
float func2()
{
return (float)rand() * 4.6566129e-10;
}

original_code:
float rng_f (void) {
  return (float) rand () / 2147483647;
}

canonical_original_code:
float rng_f() {
  return (float) rand () / 2147483647;
}

return_type: float


decompiled_code:
void rng_free()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void rng_free (void) {
}

canonical_original_code:
void rng_free() {
}


getdx

decompiled_code:
void __fastcall getdx(__int64 a1)
{
float v1; // xmm0_4
double v2; // xmm1_8
float v3; // xmm0_4
double v4; // [rsp+0h] [rbp-20h]
double v5; // [rsp+0h] [rbp-20h]
double cosx; // [rsp+8h] [rbp-18h] BYREF
double sinx[2]; // [rsp+10h] [rbp-10h] BYREF

v4 = cos(*(float *)&cam_ti);
v1 = cos(*(float *)&cam_tj) * v4;
*(float *)a1 = v1;
v5 = sin(*(float *)&cam_ti);
sincos(*(float *)&cam_tj, sinx, &cosx);
v2 = v5 * cosx;
v3 = sinx[0];
*(float *)(a1 + 8) = v3;
*(float *)&v2 = v2;
*(_DWORD *)(a1 + 4) = LODWORD(v2);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
float v1; // xmm0_4
double v2; // xmm1_8
float v3; // xmm0_4
double v4; // [rsp+0h] [rbp-20h]
double v5; // [rsp+0h] [rbp-20h]
double cosx; // [rsp+8h] [rbp-18h] BYREF
double sinx[2]; // [rsp+10h] [rbp-10h] BYREF

v4 = cos(*(float *)&cam_ti);
v1 = cos(*(float *)&cam_tj) * v4;
*(float *)a1 = v1;
v5 = sin(*(float *)&cam_ti);
sincos(*(float *)&cam_tj, sinx, &cosx);
v2 = v5 * cosx;
v3 = sinx[0];
*(float *)(a1 + 8) = v3;
*(float *)&v2 = v2;
*(_DWORD *)(a1 + 4) = LODWORD(v2);
}

original_code:
static void getdx (float *dx) {
  dx[0] = cos (cam_ti) * cos (cam_tj);
  dx[1] = sin (cam_ti) * cos (cam_tj);
  dx[2] = sin (cam_tj);
}

canonical_original_code:
static void getdx(float *dx) {
  dx[0] = cos (cam_ti) * cos (cam_tj);
  dx[1] = sin (cam_ti) * cos (cam_tj);
  dx[2] = sin (cam_tj);
}

variable_types:
dx
float *