decompiled_code:
char *__fastcall get_zz_mutex(char *src, unsigned __int8 a2)
{
__int64 v2; // r12
char *v3; // rbx

v2 = (unsigned int)hash_func();
v3 = (char *)mutex_hash[v2];
if ( pthread_mutex_lock(&glob_mutex) )
perror("glob_mutex thread_mutex_lock");
puts("now traverse hash_chain");
if ( v3 )
{
while ( 1 )
{
printf("count -- %d file_name -- %s\n", *(unsigned int *)v3, v3 + 48);
if ( !strcmp(src, v3 + 48) )
break;
v3 = (char *)*((_QWORD *)v3 + 40);
if ( !v3 )
goto LABEL_12;
}
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 <= 1u )
{
puts("find a match muutex for lock || try_lock operation ");
++*(_DWORD *)v3;
}
else if ( a2 == 2 )
{
puts("find match mutex for unlock operation");
}
}
else
{
LABEL_12:
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 > 1u )
{
if ( a2 == 2 )
puts("no mutex to unlock!");
v3 = 0LL;
}
else
{
puts("no match mutex for req,now allocate a new mutex ");
v3 = alloc_zz_mutex();
if ( v3 )
{
puts("alloc_mutex success!");
strcpy(v3 + 48, src);
*(_DWORD *)v3 = 1;
*((_QWORD *)v3 + 40) = mutex_hash[(unsigned int)v2];
*((_QWORD *)v3 + 39) = 0LL;
if ( mutex_hash[(unsigned int)v2] )
{
printf("mutex_hash[%d] is null\n", (unsigned int)v2);
*(_QWORD *)(mutex_hash[(unsigned int)v2] + 312) = v3;
}
mutex_hash[(unsigned int)v2] = (__int64)v3;
}
else
{
puts("alloc_zz_mutex fail");
}
}
}
if ( pthread_mutex_unlock(&glob_mutex) )
perror("glob_mutex thread_mutex_unlock");
return v3;
}

canonical_decompiled_code:
char *__fastcall func5(char *src, unsigned __int8 a2)
{
__int64 v2; // r12
char *v3; // rbx

v2 = (unsigned int)hash_func();
v3 = (char *)mutex_hash[v2];
if ( pthread_mutex_lock(&glob_mutex) )
perror("glob_mutex thread_mutex_lock");
puts("now traverse hash_chain");
if ( v3 )
{
while ( 1 )
{
printf("count -- %d file_name -- %s\n", *(unsigned int *)v3, v3 + 48);
if ( !strcmp(src, v3 + 48) )
break;
v3 = (char *)*((_QWORD *)v3 + 40);
if ( !v3 )
goto LABEL_12;
}
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 <= 1u )
{
puts("find a match muutex for lock || try_lock operation ");
++*(_DWORD *)v3;
}
else if ( a2 == 2 )
{
puts("find match mutex for unlock operation");
}
}
else
{
LABEL_12:
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 > 1u )
{
if ( a2 == 2 )
puts("no mutex to unlock!");
v3 = 0LL;
}
else
{
puts("no match mutex for req,now allocate a new mutex ");
v3 = func3();
if ( v3 )
{
puts("alloc_mutex success!");
strcpy(v3 + 48, src);
*(_DWORD *)v3 = 1;
*((_QWORD *)v3 + 40) = mutex_hash[(unsigned int)v2];
*((_QWORD *)v3 + 39) = 0LL;
if ( mutex_hash[(unsigned int)v2] )
{
printf("mutex_hash[%d] is null\n", (unsigned int)v2);
*(_QWORD *)(mutex_hash[(unsigned int)v2] + 312) = v3;
}
mutex_hash[(unsigned int)v2] = (__int64)v3;
}
else
{
puts("alloc_zz_mutex fail");
}
}
}
if ( pthread_mutex_unlock(&glob_mutex) )
perror("glob_mutex thread_mutex_unlock");
return v3;
}

original_code:
zz_mutex * get_zz_mutex(char * file_name,char op_type)
{
 zz_mutex * my_mutex;
 zz_mutex * nmtx;
 unsigned int hash = hash_func(file_name);
 my_mutex = mutex_hash[hash];
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_lock");
 }
 printf("now traverse hash_chain\n");
 while(my_mutex != (zz_mutex*)0)
 {
  printf("count -- %d file_name -- %s\n",my_mutex->count,my_mutex->file_name);
  if(strcmp(file_name,my_mutex->file_name) == 0){break;}
  my_mutex = my_mutex->next;
  continue;
 }
 printf("%s -- hash --%d\n",file_name,hash);
 if(op_type == MD_LOCK || op_type == MD_TRY_LOCK)
 {
  if(my_mutex == (zz_mutex*)0)
  {
   printf("no match mutex for req,now allocate a new mutex \n");
   if((nmtx = alloc_zz_mutex()) == (zz_mutex*)0)
   {
    printf("alloc_zz_mutex fail\n");
   }
   else
   {
    printf("alloc_mutex success!\n");
    my_mutex = nmtx;
    strcpy(nmtx->file_name,file_name);
    nmtx->count = 1;
    nmtx->next = mutex_hash[hash];
    nmtx->pre = (zz_mutex*)0;
    if(mutex_hash[hash] != (zz_mutex*)0)
    {
     printf("mutex_hash[%d] is null\n",hash);
     mutex_hash[hash]->pre = nmtx;
    }
    mutex_hash[hash] = nmtx;
   }
  }
  else
  {
   printf("find a match muutex for lock || try_lock operation \n");
   my_mutex->count++;
  }
 }
 else if(op_type == MD_UNLOCK)
 {
  if(my_mutex == (zz_mutex*)0)
  {
   printf("no mutex to unlock!\n");
  }
  else{printf("find match mutex for unlock operation\n");}
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_unlock");
 }
 return my_mutex;
}

canonical_original_code:
struct _mutex *get_zz_mutex(char *file_name, char op_type)
{
 struct _mutex *my_mutex;
 struct _mutex *nmtx;
 unsigned int hash = hash_func(file_name);
 my_mutex = mutex_hash[hash];
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_lock");
 }
 printf("now traverse hash_chain\n");
 while(my_mutex != (struct _mutex *)0)
 {
  printf("count -- %d file_name -- %s\n",my_mutex->count,my_mutex->file_name);
  if(strcmp(file_name,my_mutex->file_name) == 0){break;}
  my_mutex = my_mutex->next;
  continue;
 }
 printf("%s -- hash --%d\n",file_name,hash);
 if(op_type == MD_LOCK || op_type == MD_TRY_LOCK)
 {
  if(my_mutex == (struct _mutex *)0)
  {
   printf("no match mutex for req,now allocate a new mutex \n");
   if((nmtx = alloc_zz_mutex()) == (struct _mutex *)0)
   {
    printf("alloc_zz_mutex fail\n");
   }
   else
   {
    printf("alloc_mutex success!\n");
    my_mutex = nmtx;
    strcpy(nmtx->file_name,file_name);
    nmtx->count = 1;
    nmtx->next = mutex_hash[hash];
    nmtx->pre = (struct _mutex *)0;
    if(mutex_hash[hash] != (struct _mutex *)0)
    {
     printf("mutex_hash[%d] is null\n",hash);
     mutex_hash[hash]->pre = nmtx;
    }
    mutex_hash[hash] = nmtx;
   }
  }
  else
  {
   printf("find a match muutex for lock || try_lock operation \n");
   my_mutex->count++;
  }
 }
 else if(op_type == MD_UNLOCK)
 {
  if(my_mutex == (struct _mutex *)0)
  {
   printf("no mutex to unlock!\n");
  }
  else{printf("find match mutex for unlock operation\n");}
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_unlock");
 }
 return my_mutex;
}

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall put_zz_mutex(void *ptr)
{
unsigned int v1; // ebp
__int64 v3; // rax
__int64 v4; // rax

v1 = pthread_mutex_lock(&glob_mutex);
if ( v1 )
{
perror("glob_mutex thread_mutex_lock");
v1 = 1;
}
if ( (*(_DWORD *)ptr)-- == 1 )
{
v3 = *((_QWORD *)ptr + 40);
if ( v3 )
*(_QWORD *)(v3 + 312) = *((_QWORD *)ptr + 39);
v4 = *((_QWORD *)ptr + 39);
if ( v4 )
*(_QWORD *)(v4 + 320) = *((_QWORD *)ptr + 40);
else
mutex_hash[(int)hash_func((char *)ptr + 48)] = *((_QWORD *)ptr + 40);
free_zz_mutex(ptr);
}
if ( pthread_mutex_unlock(&glob_mutex) )
{
perror("glob_mutex thread_mutex_unlock");
v1 = 2;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr)
{
unsigned int v1; // ebp
__int64 v3; // rax
__int64 v4; // rax

v1 = pthread_mutex_lock(&glob_mutex);
if ( v1 )
{
perror("glob_mutex thread_mutex_lock");
v1 = 1;
}
if ( (*(_DWORD *)ptr)-- == 1 )
{
v3 = *((_QWORD *)ptr + 40);
if ( v3 )
*(_QWORD *)(v3 + 312) = *((_QWORD *)ptr + 39);
v4 = *((_QWORD *)ptr + 39);
if ( v4 )
*(_QWORD *)(v4 + 320) = *((_QWORD *)ptr + 40);
else
mutex_hash[(int)hash_func((char *)ptr + 48)] = *((_QWORD *)ptr + 40);
func4(ptr);
}
if ( pthread_mutex_unlock(&glob_mutex) )
{
perror("glob_mutex thread_mutex_unlock");
v1 = 2;
}
return v1;
}

original_code:
int put_zz_mutex(zz_mutex * my_mutex)
{
 int r = 0;
 int hash;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 if(--my_mutex->count == 0)
 {
  if(my_mutex->next != (zz_mutex*)0)
  {
   my_mutex->next->pre = my_mutex->pre;
  }
  if(my_mutex->pre != (zz_mutex*)0)
  {
   my_mutex->pre->next = my_mutex->next;
  }
  else
  {
   hash = hash_func(my_mutex->file_name);
   mutex_hash[hash] = my_mutex->next;
  }
  free_zz_mutex(my_mutex);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

canonical_original_code:
int put_zz_mutex(struct _mutex *my_mutex)
{
 int r = 0;
 int hash;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 if(--my_mutex->count == 0)
 {
  if(my_mutex->next != (struct _mutex *)0)
  {
   my_mutex->next->pre = my_mutex->pre;
  }
  if(my_mutex->pre != (struct _mutex *)0)
  {
   my_mutex->pre->next = my_mutex->next;
  }
  else
  {
   hash = hash_func(my_mutex->file_name);
   mutex_hash[hash] = my_mutex->next;
  }
  free_zz_mutex(my_mutex);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

variable_types: struct _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]; struct _mutex *pre; struct _mutex *next; } *

variable_types: r int

variable_types: hash int

return_type: int

user_defined_types: struct _mutex { int count; union pthread_mutex_t p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; }

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:
void __fastcall __noreturn thread_func(void *a1)
{
_DWORD *v1; // rbp
char *v2; // rax
char *v3; // r12
unsigned __int8 v4; // al

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

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
_DWORD *v1; // rbp
char *v2; // rax
char *v3; // r12
unsigned __int8 v4; // al

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

original_code:
void * thread_func(void * arg)
{
 thread_arg * my_arg = (thread_arg *)arg;
 zz_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_zz_mutex(my_arg->file_name,my_arg->op_type)) == (zz_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_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_lock(&my_mutex->p_mutex) != 0)
    {
     printf("Lock fail! put zz_mutex back\n");
     put_zz_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_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_trylock(&my_mutex->p_mutex) != 0)
    {
     printf("Try_Lock fail! put zz_mutex back\n");
     put_zz_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 zz_mutex back\n");
     put_zz_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_hash();
 }
 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 _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_zz_mutex(my_arg->file_name,my_arg->op_type)) == (struct _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_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_lock(&my_mutex->p_mutex) != 0)
    {
     printf("Lock fail! put zz_mutex back\n");
     put_zz_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_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_trylock(&my_mutex->p_mutex) != 0)
    {
     printf("Try_Lock fail! put zz_mutex back\n");
     put_zz_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 zz_mutex back\n");
     put_zz_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_hash();
 }
 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; }

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


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
unsigned int v5; // er13
unsigned int v6; // eax
char *v7; // rbx
struct sockaddr v8; // [rsp+0h] [rbp-178h] BYREF
struct sockaddr buf; // [rsp+10h] [rbp-168h] BYREF
socklen_t addr_len; // [rsp+2Ch] [rbp-14Ch] BYREF
char v11[8]; // [rsp+30h] [rbp-148h] BYREF
__int64 v12; // [rsp+38h] [rbp-140h]
int v13[66]; // [rsp+40h] [rbp-138h] BYREF
pthread_t newthread[6]; // [rsp+148h] [rbp-30h] BYREF

*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = _bswap_16(9378);
v3 = socket(2, 1, 0);
if ( bind(v3, &buf, 0x10u) != -1 )
{
mutex_hash_init();
show_mutex_hash();
listen(v3, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
*(_QWORD *)v11 = 0LL;
v12 = 0LL;
memset(v13, 0, sizeof(v13));
v4 = accept(v3, &v8, &addr_len);
inet_ntop(2, &v8.sa_data[2], v11, 0x10u);
v5 = (unsigned __int16)_bswap_16(*(__int16 *)v8.sa_data);
v6 = read(v4, v13, 0x108uLL);
if ( v6 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v6, v11, v5);
v7 = (char *)malloc(0x10CuLL);
if ( !v7 )
{
perror("malloc");
exit(1);
}
memset(v7, 0, 0x108uLL);
*((_DWORD *)v7 + 66) = 0;
*((_DWORD *)v7 + 1) = v4;
strcpy(v7 + 8, (const char *)&v13[1]);
*v7 = v13[0];
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thread_func, v7) )
{
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; // er12
int v4; // ebp
unsigned int v5; // er13
unsigned int v6; // eax
char *v7; // rbx
struct sockaddr v8; // [rsp+0h] [rbp-178h] BYREF
struct sockaddr buf; // [rsp+10h] [rbp-168h] BYREF
socklen_t addr_len; // [rsp+2Ch] [rbp-14Ch] BYREF
char v11[8]; // [rsp+30h] [rbp-148h] BYREF
__int64 v12; // [rsp+38h] [rbp-140h]
int v13[66]; // [rsp+40h] [rbp-138h] BYREF
pthread_t newthread[6]; // [rsp+148h] [rbp-30h] BYREF

*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = func0(9378);
v3 = socket(2, 1, 0);
if ( bind(v3, &buf, 0x10u) != -1 )
{
func1();
func2();
listen(v3, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
*(_QWORD *)v11 = 0LL;
v12 = 0LL;
memset(v13, 0, sizeof(v13));
v4 = accept(v3, &v8, &addr_len);
inet_ntop(2, &v8.sa_data[2], v11, 0x10u);
v5 = (unsigned __int16)func0(*(__int16 *)v8.sa_data);
v6 = read(v4, v13, 0x108uLL);
if ( v6 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v6, v11, v5);
v7 = (char *)malloc(0x10CuLL);
if ( !v7 )
{
perror("malloc");
exit(1);
}
memset(v7, 0, 0x108uLL);
*((_DWORD *)v7 + 66) = 0;
*((_DWORD *)v7 + 1) = v4;
strcpy(v7 + 8, (const char *)&v13[1]);
*v7 = v13[0];
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thread_func, v7) )
{
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_hash_init();
 show_mutex_hash();
 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_hash_init();
 show_mutex_hash();
 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 atoi_u32(char *a1)
{
char v1; // al
unsigned int v2; // edx
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v2 = v1 + 10 * v2 - 48;
v1 = *++a1;
if ( !*a1 )
goto LABEL_5;
}
fwrite("Invalid character found in u32 string!\n", 1uLL, 0x27uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = 0;
LABEL_5:
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
unsigned int v2; // edx
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v2 = v1 + 10 * v2 - 48;
v1 = *++a1;
if ( !*a1 )
goto LABEL_5;
}
fwrite("Invalid character found in u32 string!\n", 1uLL, 0x27uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = 0;
LABEL_5:
result = v2;
}
return result;
}

original_code:
u32 atoi_u32(char *p)
{
 u32 i = 0;
 u32 j;
 char * ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u32 string!\n");
   return -1;
  }
  j = (u32)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

canonical_original_code:
unsigned int atoi_u32(char *p)
{
 unsigned int i = 0;
 unsigned int j;
 char *ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u32 string!\n");
   return -1;
  }
  j = (u32)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

variable_types:
p
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
ch
char *

return_type: unsigned int


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

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v2 = v1 - 48 + 10 * v2;
v1 = *++a1;
if ( !*a1 )
goto LABEL_5;
}
fwrite("Invalid character found in u64 string!\n", 1uLL, 0x27uLL, stderr);
result = -1LL;
}
else
{
v2 = 0LL;
LABEL_5:
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
__int64 v2; // rdx
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
while ( (unsigned __int8)(v1 - 48) <= 9u )
{
v2 = v1 - 48 + 10 * v2;
v1 = *++a1;
if ( !*a1 )
goto LABEL_5;
}
fwrite("Invalid character found in u64 string!\n", 1uLL, 0x27uLL, stderr);
result = -1LL;
}
else
{
v2 = 0LL;
LABEL_5:
result = v2;
}
return result;
}

original_code:
u64 atoi_u64(char *p)
{
 u64 i = 0;
 u64 j;
 char * ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u64 string!\n");
   return -1;
  }
  j = (u64)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

canonical_original_code:
unsigned long atoi_u64(char *p)
{
 unsigned long i = 0;
 unsigned long j;
 char *ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u64 string!\n");
   return -1;
  }
  j = (u64)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall get_cache_path(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/supercache");
strcpy((char *)(a2 + 15), src);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/supercache");
strcpy((char *)(a2 + 15), src);
return a2;
}

original_code:
char * get_cache_path(char * path,char * cache_path)
{
 char *p = cache_path + strlen("/mnt/supercache");
 memset(cache_path,0,260);
 strcpy(cache_path,"/mnt/supercache");
 strcpy(p,path);
 return cache_path;
}

canonical_original_code:
char *get_cache_path(char *path, char *cache_path)
{
 char *p = cache_path + strlen("/mnt/supercache");
 memset(cache_path,0,260);
 strcpy(cache_path,"/mnt/supercache");
 strcpy(p,path);
 return cache_path;
}

variable_types:
path
char *

return_type: char *


decompiled_code:
__int64 __fastcall get_dtc_path(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/dtcenter");
strcpy((char *)(a2 + 13), src);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/dtcenter");
strcpy((char *)(a2 + 13), src);
return a2;
}

original_code:
char * get_dtc_path(char * path,char * dtc_path)
{
 char *p = dtc_path + strlen("/mnt/dtcenter");
 memset(dtc_path,0,260);
 strcpy(dtc_path,"/mnt/dtcenter");
 strcpy(p,path);
 return dtc_path;
}

canonical_original_code:
char *get_dtc_path(char *path, char *dtc_path)
{
 char *p = dtc_path + strlen("/mnt/dtcenter");
 memset(dtc_path,0,260);
 strcpy(dtc_path,"/mnt/dtcenter");
 strcpy(p,path);
 return dtc_path;
}


decompiled_code:
ssize_t __fastcall get_path_from_fd(unsigned int a1, char *a2)
{
unsigned int v2; // eax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

memset(v4, 0, 0x400uLL);
v2 = getpid();
snprintf(v4, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(v4, a2, 0x104uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func4(unsigned int a1, char *a2)
{
unsigned int v2; // eax
char v4[1048]; // [rsp+0h] [rbp-418h] BYREF

memset(v4, 0, 0x400uLL);
v2 = getpid();
snprintf(v4, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(v4, a2, 0x104uLL);
}

original_code:
int get_path_from_fd(int fd,char * path)
{
 char buf[1024];
 pid_t pid;
 memset(buf,0,1024);
 pid = getpid();
 snprintf(buf,1024,"/proc/%i/fd/%i",pid,fd);
 return readlink(buf,path,260);
}

canonical_original_code:
int get_path_from_fd(int fd, char *path)
{
 char buf[1024];
 int pid;
 memset(buf,0,1024);
 pid = getpid();
 snprintf(buf,1024,"/proc/%i/fd/%i",pid,fd);
 return readlink(buf,path,260);
}

variable_types: fd int

variable_types:
buf
char [1024]

variable_types: pid int


decompiled_code:
__int64 __fastcall pthread_block_sig(int signo)
{
unsigned int v1; // ebx
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(0, &v3, 0LL);
if ( v1 )
printf("Block signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int signo)
{
unsigned int v1; // ebx
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(0, &v3, 0LL);
if ( v1 )
printf("Block signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

original_code:
int pthread_block_sig(int signo)
{
    int rt = 0;
    sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(0,&st,((void *)0));
    if(rt != 0)
    {
        printf("Block signal -- %d fail!\n",signo);
    }
    return rt;
}

canonical_original_code:
int pthread_block_sig(int signo)
{
    int rt = 0;
    struct __sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(0,&st,((void *)0));
    if(rt != 0)
    {
        printf("Block signal -- %d fail!\n",signo);
    }
    return rt;
}

variable_types: signo int

variable_types: rt int

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


decompiled_code:
__int64 __fastcall pthread_unblock_sig(int signo)
{
unsigned int v1; // ebx
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(1, &v3, 0LL);
if ( v1 )
printf("Unblock signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(int signo)
{
unsigned int v1; // ebx
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(1, &v3, 0LL);
if ( v1 )
printf("Unblock signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

original_code:
int pthread_unblock_sig(int signo)
{
    int rt = 0;
    sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(1,&st,((void *)0));
    if(rt != 0)
    {
        printf("Unblock signal -- %d fail!\n",signo);
    }
    return rt;
}

canonical_original_code:
int pthread_unblock_sig(int signo)
{
    int rt = 0;
    struct __sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(1,&st,((void *)0));
    if(rt != 0)
    {
        printf("Unblock signal -- %d fail!\n",signo);
    }
    return rt;
}

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


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

v6.sa_handler = a2;
sigemptyset(&v6.sa_mask);
v2 = 0x20000000;
if ( sig != 14 )
v2 = 0x10000000;
v6.sa_flags = v2;
v3 = sigaction(sig, &v6, &v5) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v5.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

v6.sa_handler = a2;
sigemptyset(&v6.sa_mask);
v2 = 0x20000000;
if ( sig != 14 )
v2 = 0x10000000;
v6.sa_flags = v2;
v3 = sigaction(sig, &v6, &v5) < 0;
result = -1LL;
if ( !v3 )
result = (__int64)v5.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

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

canonical_decompiled_code:
__int64 func8()
{
pthread_mutex_t *v0; // rbx

memset(&mutex_table, 0, 0x9C0uLL);
v0 = &mutex;
do
{
pthread_mutex_init(v0, 0LL);
*((_DWORD *)&v0[-1].__align + 8) = 0;
v0 = (pthread_mutex_t *)((char *)v0 + 312);
}
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]; } *

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


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

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

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

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

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


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

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

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
unsigned int v1; // ebx

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

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)
{
_DWORD *v1; // rbp
pthread_mutex_t *v2; // rax
pthread_mutex_t *v3; // r12
unsigned __int8 v4; // al

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

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
_DWORD *v1; // rbp
pthread_mutex_t *v2; // rax
pthread_mutex_t *v3; // r12
unsigned __int8 v4; // al

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


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
unsigned int v5; // er13
unsigned int v6; // eax
char *v7; // rbx
struct sockaddr v8; // [rsp+0h] [rbp-178h] BYREF
struct sockaddr buf; // [rsp+10h] [rbp-168h] BYREF
socklen_t addr_len; // [rsp+2Ch] [rbp-14Ch] BYREF
char v11[8]; // [rsp+30h] [rbp-148h] BYREF
__int64 v12; // [rsp+38h] [rbp-140h]
int v13[66]; // [rsp+40h] [rbp-138h] BYREF
pthread_t newthread[6]; // [rsp+148h] [rbp-30h] BYREF

*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = _bswap_16(9378);
v3 = socket(2, 1, 0);
if ( bind(v3, &buf, 0x10u) != -1 )
{
mutex_table_init();
show_mutex_table();
listen(v3, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
*(_QWORD *)v11 = 0LL;
v12 = 0LL;
memset(v13, 0, sizeof(v13));
v4 = accept(v3, &v8, &addr_len);
inet_ntop(2, &v8.sa_data[2], v11, 0x10u);
v5 = (unsigned __int16)_bswap_16(*(__int16 *)v8.sa_data);
v6 = read(v4, v13, 0x108uLL);
if ( v6 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v6, v11, v5);
v7 = (char *)malloc(0x10CuLL);
if ( !v7 )
{
perror("malloc");
exit(1);
}
memset(v7, 0, 0x108uLL);
*((_DWORD *)v7 + 66) = 0;
*((_DWORD *)v7 + 1) = v4;
strcpy(v7 + 8, (const char *)&v13[1]);
*v7 = v13[0];
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thread_func, v7) )
{
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; // er12
int v4; // ebp
unsigned int v5; // er13
unsigned int v6; // eax
char *v7; // rbx
struct sockaddr v8; // [rsp+0h] [rbp-178h] BYREF
struct sockaddr buf; // [rsp+10h] [rbp-168h] BYREF
socklen_t addr_len; // [rsp+2Ch] [rbp-14Ch] BYREF
char v11[8]; // [rsp+30h] [rbp-148h] BYREF
__int64 v12; // [rsp+38h] [rbp-140h]
int v13[66]; // [rsp+40h] [rbp-138h] BYREF
pthread_t newthread[6]; // [rsp+148h] [rbp-30h] BYREF

*(_QWORD *)&buf.sa_family = 2LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = func7(9378);
v3 = socket(2, 1, 0);
if ( bind(v3, &buf, 0x10u) != -1 )
{
func8();
func9();
listen(v3, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
*(_QWORD *)v11 = 0LL;
v12 = 0LL;
memset(v13, 0, sizeof(v13));
v4 = accept(v3, &v8, &addr_len);
inet_ntop(2, &v8.sa_data[2], v11, 0x10u);
v5 = (unsigned __int16)func7(*(__int16 *)v8.sa_data);
v6 = read(v4, v13, 0x108uLL);
if ( v6 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v6, v11, v5);
v7 = (char *)malloc(0x10CuLL);
if ( !v7 )
{
perror("malloc");
exit(1);
}
memset(v7, 0, 0x108uLL);
*((_DWORD *)v7 + 66) = 0;
*((_DWORD *)v7 + 1) = v4;
strcpy(v7 + 8, (const char *)&v13[1]);
*v7 = v13[0];
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thread_func, v7) )
{
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]; }


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

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

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

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

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; // rbx
__int64 result; // rax

v4 = malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v4) )
{
puts("Get metadata in read_queue_out error!");
result = 1LL;
}
else
{
v4[444] = (v4[444] + 1) % 0x32u;
*((_QWORD *)v4 + 9) = a3;
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; // rbx
__int64 result; // rax

v4 = malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v4) )
{
puts("Get metadata in read_queue_out error!");
result = 1LL;
}
else
{
v4[444] = (v4[444] + 1) % 0x32u;
*((_QWORD *)v4 + 9) = a3;
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; // rbx
void *v9; // rbp
__int64 result; // rax
char *v11; // rbp
int v12; // eax
char *v13; // rbp
__int64 v14; // r14
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!");
result = 1LL;
}
else
{
*((_DWORD *)v8 + 444) = (*((_DWORD *)v8 + 444) + 1) % 0x32u;
v9 = malloc(0x220uLL);
*(_DWORD *)v9 = a2;
*((_QWORD *)v9 + 1) = a4;
*((_QWORD *)v9 + 2) = a3;
strcpy((char *)v9 + 24, v8 + 2844);
if ( (unsigned int)ion_put(s, v9) )
goto LABEL_11;
free(v9);
if ( strlen(v8 + 2844) > 1 )
{
v11 = (char *)malloc(0x220uLL);
if ( (unsigned int)ion_get(v8 + 2844, v11) )
{
puts("Get io_node in write_queue_out error!");
return 1LL;
}
strcpy(v11 + 284, s);
if ( (unsigned int)ion_put(v8 + 2844, v11) )
{
LABEL_11:
puts("Put io_node in write_queue_out error!");
return 1LL;
}
}
if ( !v8[2584] )
{
strcpy(v8 + 2584, s);
v12 = *((_DWORD *)v8 + 442);
if ( v12 )
{
v13 = v8 + 425;
v14 = (__int64)&v8[541 * (v12 - 1) + 966];
do
{
strcpy(v13, s);
v13 += 541;
}
while ( v13 != (char *)v14 );
}
}
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; // rbx
void *v9; // rbp
__int64 result; // rax
char *v11; // rbp
int v12; // eax
char *v13; // rbp
__int64 v14; // r14
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!");
result = 1LL;
}
else
{
*((_DWORD *)v8 + 444) = (*((_DWORD *)v8 + 444) + 1) % 0x32u;
v9 = malloc(0x220uLL);
*(_DWORD *)v9 = a2;
*((_QWORD *)v9 + 1) = a4;
*((_QWORD *)v9 + 2) = a3;
strcpy((char *)v9 + 24, v8 + 2844);
if ( (unsigned int)ion_put(s, v9) )
goto LABEL_11;
free(v9);
if ( strlen(v8 + 2844) > 1 )
{
v11 = (char *)malloc(0x220uLL);
if ( (unsigned int)ion_get(v8 + 2844, v11) )
{
puts("Get io_node in write_queue_out error!");
return 1LL;
}
strcpy(v11 + 284, s);
if ( (unsigned int)ion_put(v8 + 2844, v11) )
{
LABEL_11:
puts("Put io_node in write_queue_out error!");
return 1LL;
}
}
if ( !v8[2584] )
{
strcpy(v8 + 2584, s);
v12 = *((_DWORD *)v8 + 442);
if ( v12 )
{
v13 = v8 + 425;
v14 = (__int64)&v8[541 * (v12 - 1) + 966];
do
{
strcpy(v13, s);
v13 += 541;
}
while ( v13 != (char *)v14 );
}
}
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; // ebp
int v4; // er13
char *v5; // rbx
char *v6; // rbx
__int64 v7; // rbp
char *v8; // rax
char v9[272]; // [rsp+0h] [rbp-368h] BYREF
char v10[600]; // [rsp+110h] [rbp-258h] BYREF

v2 = (char *)malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v2) )
{
puts("Get metadata in replica_update error!");
return;
}
v3 = 0;
v4 = *((_DWORD *)v2 + 442);
if ( v4 )
{
v5 = v2 + 144;
do
{
qmemcpy(v10, v5, 0x21DuLL);
if ( !strcmp(&v10[1], a2) )
break;
++v3;
v5 += 541;
}
while ( v4 != v3 );
}
else
{
v3 = 0;
}
if ( !v10[281] )
goto LABEL_11;
strcpy(v9, &v10[281]);
v6 = (char *)malloc(8uLL);
if ( !v9[0] )
{
LABEL_10:
free(v6);
v7 = 541LL * v3;
v8 = &v2[v7 + 425];
*(_QWORD *)v8 = 0LL;
*(_QWORD *)(v8 + 252) = 0LL;
memset(
(void *)((unsigned __int64)&v2[v7 + 433] & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v8 - (((_DWORD)v2 + (_DWORD)v7 + 433) & 0xFFFFFFF8) + 260) >> 3));
LABEL_11:
if ( (unsigned int)md_put(a1, v2) )
puts("Put metadata in replica_update error!");
else
free(v2);
return;
}
while ( !(unsigned int)ion_get(v9, v6) )
{
iod_get(v9, 0LL);
strcpy(v9, v6 + 284);
if ( !v9[0] )
goto LABEL_10;
}
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; // ebp
int v4; // er13
char *v5; // rbx
char *v6; // rbx
__int64 v7; // rbp
char *v8; // rax
char v9[272]; // [rsp+0h] [rbp-368h] BYREF
char v10[600]; // [rsp+110h] [rbp-258h] BYREF

v2 = (char *)malloc(0xC20uLL);
if ( (unsigned int)md_get(a1, v2) )
{
puts("Get metadata in replica_update error!");
return;
}
v3 = 0;
v4 = *((_DWORD *)v2 + 442);
if ( v4 )
{
v5 = v2 + 144;
do
{
qmemcpy(v10, v5, 0x21DuLL);
if ( !strcmp(&v10[1], a2) )
break;
++v3;
v5 += 541;
}
while ( v4 != v3 );
}
else
{
v3 = 0;
}
if ( !v10[281] )
goto LABEL_11;
strcpy(v9, &v10[281]);
v6 = (char *)malloc(8uLL);
if ( !v9[0] )
{
LABEL_10:
free(v6);
v7 = 541LL * v3;
v8 = &v2[v7 + 425];
*(_QWORD *)v8 = 0LL;
*(_QWORD *)(v8 + 252) = 0LL;
memset(
(void *)((unsigned __int64)&v2[v7 + 433] & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v8 - (((_DWORD)v2 + (_DWORD)v7 + 433) & 0xFFFFFFF8) + 260) >> 3));
LABEL_11:
if ( (unsigned int)md_put(a1, v2) )
puts("Put metadata in replica_update error!");
else
free(v2);
return;
}
while ( !(unsigned int)ion_get(v9, v6) )
{
iod_get(v9, 0LL);
strcpy(v9, v6 + 284);
if ( !v9[0] )
goto LABEL_10;
}
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; // eax
int v3; // ebp
unsigned int v4; // er12
char *v5; // rbx
int v6; // er13
unsigned int *v7; // rbx
struct sockaddr buf[3]; // [rsp+0h] [rbp-38h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func8(char *src, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
char *v5; // rbx
int v6; // er13
unsigned int *v7; // rbx
struct sockaddr buf[3]; // [rsp+0h] [rbp-38h] BYREF

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

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: struct md_mutex_res_packet { char ok_or_not; enum fail_t why_fail; }

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 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 % 0x65;
}

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

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
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");
}