decompiled_code:
__int64 __fastcall ms_queue_pop(volatile signed __int64 *a1)
{
__int64 *v1; // rax
__int64 v2; // rbx
unsigned int v3; // er8
__int64 *v4; // rtt
int v6; // [rsp+0h] [rbp-Ch]

while ( 1 )
{
while ( 1 )
{
v1 = (__int64 *)*a1;
v2 = **(_QWORD **)a1;
if ( *a1 == *((_QWORD *)a1 + 2) )
break;
v3 = *(_DWORD *)(v2 + 16);
v4 = (__int64 *)*a1;
LOBYTE(v6) = v4 == (__int64 *)_InterlockedCompareExchange64(
a1,
__SPAIR64__(*((_DWORD *)a1 + 2) + 1, v2),
(signed __int64)v1);
if ( v6 )
return v3;
}
if ( !v2 )
break;
_InterlockedCompareExchange64(a1 + 2, __SPAIR64__(*((_DWORD *)a1 + 6) + 1, v2), (signed __int64)v1);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(volatile signed __int64 *a1)
{
__int64 *v1; // rax
__int64 v2; // rbx
unsigned int v3; // er8
__int64 *v4; // rtt
int v6; // [rsp+0h] [rbp-Ch]

while ( 1 )
{
while ( 1 )
{
v1 = (__int64 *)*a1;
v2 = **(_QWORD **)a1;
if ( *a1 == *((_QWORD *)a1 + 2) )
break;
v3 = *(_DWORD *)(v2 + 16);
v4 = (__int64 *)*a1;
LOBYTE(v6) = v4 == (__int64 *)_InterlockedCompareExchange64(
a1,
__SPAIR64__(*((_DWORD *)a1 + 2) + 1, v2),
(signed __int64)v1);
if ( v6 )
return v3;
}
if ( !v2 )
break;
_InterlockedCompareExchange64(a1 + 2, __SPAIR64__(*((_DWORD *)a1 + 6) + 1, v2), (signed __int64)v1);
}
return 0xFFFFFFFFLL;
}

original_code:
int ms_queue_pop(struct ms_queue * q)
{
 int ret = -1;
 struct ms_pointer head, tail, next, tmp;
 while(1) {
  head = q->head;
  tail = q->tail;
  next = head.ptr->next;
  if((((&head)->ptr == (&q->head)->ptr) && ((&head)->tag == (&q->head)->tag))) {
   if(head.ptr == tail.ptr) {
    if(next.ptr == ((void *)0)) {
     return -1;
    }
    (&tmp)->ptr = next.ptr; (&tmp)->tag = tail.tag+1;
    ({ struct ms_pointer * __ptr = &q->tail; struct ms_pointer __old = (tail); struct ms_pointer __new = (tmp); int __ret; asm volatile("lock cmpxchg8b %1; sete %0" :"=m"(__ret),"+m"(*(volatile struct ms_pointer *)__ptr) :"a"(__old.ptr),"d"(__old.tag),"b"(__new.ptr),"c"(__new.tag) :"memory"); __ret; });
   } else {
    ret = next.ptr->ival;
    (&tmp)->ptr = next.ptr; (&tmp)->tag = head.tag+1;
    if(({ struct ms_pointer * __ptr = &q->head; struct ms_pointer __old = (head); struct ms_pointer __new = (tmp); int __ret; asm volatile("lock cmpxchg8b %1; sete %0" :"=m"(__ret),"+m"(*(volatile struct ms_pointer *)__ptr) :"a"(__old.ptr),"d"(__old.tag),"b"(__new.ptr),"c"(__new.tag) :"memory"); __ret; })) {
     break;
    }
   }
  }
 }
 _free_node(head.ptr);
 return ret;
}

canonical_original_code:
int ms_queue_pop(struct ms_queue *q)
{
 int ret = -1;
 struct ms_pointer head; struct ms_pointer tail; struct ms_pointer next; struct ms_pointer tmp;
 while(1) {
  head = q->head;
  tail = q->tail;
  next = head.ptr->next;
  if((((&head)->ptr == (&q->head)->ptr) && ((&head)->tag == (&q->head)->tag))) {
   if(head.ptr == tail.ptr) {
    if(next.ptr == ((void *)0)) {
     return -1;
    }
    (&tmp)->ptr = next.ptr; (&tmp)->tag = tail.tag+1;
    ({ struct ms_pointer *__ptr = &q->tail; struct ms_pointer __old = (tail); struct ms_pointer __new = (tmp); int __ret; asm volatile("lock cmpxchg8b %1; sete %0" :"=m"(__ret),"+m"(*(struct ms_pointer *)__ptr) :"a"(__old.ptr),"d"(__old.tag),"b"(__new.ptr),"c"(__new.tag) :"memory"); __ret; });
   } else {
    ret = next.ptr->ival;
    (&tmp)->ptr = next.ptr; (&tmp)->tag = head.tag+1;
    if(({ struct ms_pointer *__ptr = &q->head; struct ms_pointer __old = (head); struct ms_pointer __new = (tmp); int __ret; asm volatile("lock cmpxchg8b %1; sete %0" :"=m"(__ret),"+m"(*(struct ms_pointer *)__ptr) :"a"(__old.ptr),"d"(__old.tag),"b"(__new.ptr),"c"(__new.tag) :"memory"); __ret; })) {
     break;
    }
   }
  }
 }
 _free_node(head.ptr);
 return ret;
}

variable_types: ret int

variable_types: struct ms_pointer { struct ms_node { struct ms_pointer next; union { void *pval; int ival; double fval; }; } *ptr; unsigned int tag; }


decompiled_code:
int ms_queue_dump_stat()
{
return printf("[CAS Failed] %d\n", 0LL);
}

canonical_decompiled_code:
int func6()
{
return printf("[CAS Failed] %d\n", 0LL);
}

original_code:
void ms_queue_dump_stat(struct ms_queue * q)
{
 printf("[CAS Failed] %d""\n", cas_failed);
}

canonical_original_code:
void ms_queue_dump_stat(struct ms_queue *q)
{
 printf("[CAS Failed] %d""\n", cas_failed);
}

variable_types: struct ms_queue { struct ms_pointer { struct ms_node { struct ms_pointer next; union { void *pval; int ival; double fval; }; } *ptr; unsigned int tag; } head; struct ms_pointer tail; } *

return_type: void

user_defined_types: struct ms_queue { struct ms_pointer head; struct ms_pointer tail; }

user_defined_types: struct ms_pointer { struct ms_node *ptr; unsigned int tag; }


decompiled_code:
void *__fastcall s_lockq_write(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
__time_t v3; // rsi
__suseconds_t v4; // rdx
struct timeval v6; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

sync_thread_constprop_0(a1, 0LL);
gettimeofday(&v6, 0LL);
if ( LOOP > 0 )
{
v1 = 1LL;
do
{
v2 = v1++;
s_lock_queue_push(a1, v2);
}
while ( LOOP >= (int)v1 );
}
gettimeofday(&tv, 0LL);
v3 = tv.tv_sec - v6.tv_sec;
v4 = tv.tv_usec - v6.tv_usec;
if ( tv.tv_usec - v6.tv_usec < 0 )
{
--v3;
v4 += 1000000LL;
}
printf("[lockq write] time comsume : %ld s %ld us\n", v3, v4);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
__time_t v3; // rsi
__suseconds_t v4; // rdx
struct timeval v6; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

func0(a1, 0LL);
gettimeofday(&v6, 0LL);
if ( LOOP > 0 )
{
v1 = 1LL;
do
{
v2 = v1++;
s_lock_queue_push(a1, v2);
}
while ( LOOP >= (int)v1 );
}
gettimeofday(&tv, 0LL);
v3 = tv.tv_sec - v6.tv_sec;
v4 = tv.tv_usec - v6.tv_usec;
if ( tv.tv_usec - v6.tv_usec < 0 )
{
--v3;
v4 += 1000000LL;
}
printf("[lockq write] time comsume : %ld s %ld us\n", v3, v4);
return 0LL;
}

original_code:
void * s_lockq_write(void * d)
{
 struct timeval start_tv;
 gettimeofday(&start_tv, ((void *)0));
 struct ms_queue * q = (struct ms_queue *)d;
 int i;
 for(i = 1; i <= 1000; ++i) {
  ms_queue_push(q, i);
 }
 struct timeval end_tv;
 gettimeofday(&end_tv, ((void *)0));
 struct timeval tv;
 do { (&tv)->tv_sec = (&end_tv)->tv_sec - (&start_tv)->tv_sec; (&tv)->tv_usec = (&end_tv)->tv_usec - (&start_tv)->tv_usec; if ((&tv)->tv_usec < 0) { --(&tv)->tv_sec; (&tv)->tv_usec += 1000000; } } while (0);
 printf("[msq write] time comsume : %ld s %ld us""\n", tv.tv_sec, tv.tv_usec);
 return ((void *)0);
}

canonical_original_code:
void *s_lockq_write(void *d)
{
 struct timeval start_tv;
 gettimeofday(&start_tv, ((void *)0));
 struct ms_queue *q = (struct ms_queue *)d;
 int i;
 for(i = 1; i <= 1000; ++i) {
  ms_queue_push(q, i);
 }
 struct timeval end_tv;
 gettimeofday(&end_tv, ((void *)0));
 struct timeval tv;
 do { (&tv)->tv_sec = (&end_tv)->tv_sec - (&start_tv)->tv_sec; (&tv)->tv_usec = (&end_tv)->tv_usec - (&start_tv)->tv_usec; if ((&tv)->tv_usec < 0) { --(&tv)->tv_sec; (&tv)->tv_usec += 1000000; } } while (0);
 printf("[msq write] time comsume : %ld s %ld us""\n", tv.tv_sec, tv.tv_usec);
 return ((void *)0);
}

variable_types:
d
void *

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

variable_types: i int

return_type: void *

user_defined_types: struct ms_node { struct ms_pointer next; union { void *pval; int ival; double fval; }; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
{
C = *argv[1] - 48;
if ( argc != 2 )
LOOP = 1000000 * atoi(argv[2]);
}
test_3();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
{
C = *argv[1] - 48;
if ( argc != 2 )
LOOP = 1000000 * atoi(argv[2]);
}
func9();
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 {
  struct ms_queue * q = ms_queue_create();
  pthread_t s_lockq_read_t, s_lockq_write_t;
  pthread_create(&s_lockq_write_t, ((void *)0), &s_lockq_write, q);
  pthread_create(&s_lockq_read_t, ((void *)0), &s_lockq_read, q);
  pthread_join(s_lockq_read_t, ((void *)0));
  pthread_join(s_lockq_write_t, ((void *)0));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 {
  struct ms_queue *q = ms_queue_create();
  unsigned long s_lockq_read_t; unsigned long s_lockq_write_t;
  pthread_create(&s_lockq_write_t, ((void *)0), &s_lockq_write, q);
  pthread_create(&s_lockq_read_t, ((void *)0), &s_lockq_read, q);
  pthread_join(s_lockq_read_t, ((void *)0));
  pthread_join(s_lockq_write_t, ((void *)0));
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
__int64 __fastcall iget_free_packet(int a1)
{
char *v2; // rax
int v3; // ecx
int v4; // edi
__int64 v5; // rax
__int64 v6; // rdx
_QWORD *v7; // rsi
int v8; // ecx
__int64 result; // rax
int v10; // [rsp+Ch] [rbp-Ch]

if ( !g_init )
{
g_init = 1;
v2 = (char *)&g_free;
do
s_list_init(v2);
while ( v2 != "too big packet size:%d\n" );
}
if ( a1 > 0x400000 )
{
printf("too big packet size:%d\n", (unsigned int)a1);
result = 0LL;
}
else
{
v3 = 4;
if ( a1 <= 16 )
{
v6 = 64LL;
v4 = 16;
v5 = 4LL;
}
else
{
do
v4 = 1 << ++v3;
while ( 1 << v3 < a1 );
v5 = v3;
v6 = 16LL * v3;
}
v7 = (_QWORD *)qword_908[2 * v5];
if ( v7 == (_QWORD *)((char *)&g_free + v6) )
{
v10 = v3;
result = _s_malloc((unsigned int)(v4 + 44));
v8 = v10;
}
else
{
s_list_del(v7);
result = (__int64)(v7 - 2);
}
*(_DWORD *)(result + 12) = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
char *v2; // rax
int v3; // ecx
int v4; // edi
__int64 v5; // rax
__int64 v6; // rdx
_QWORD *v7; // rsi
int v8; // ecx
__int64 result; // rax
int v10; // [rsp+Ch] [rbp-Ch]

if ( !g_init )
{
g_init = 1;
v2 = (char *)&g_free;
do
func0(v2);
while ( v2 != "too big packet size:%d\n" );
}
if ( a1 > 0x400000 )
{
printf("too big packet size:%d\n", (unsigned int)a1);
result = 0LL;
}
else
{
v3 = 4;
if ( a1 <= 16 )
{
v6 = 64LL;
v4 = 16;
v5 = 4LL;
}
else
{
do
v4 = 1 << ++v3;
while ( 1 << v3 < a1 );
v5 = v3;
v6 = 16LL * v3;
}
v7 = (_QWORD *)qword_908[2 * v5];
if ( v7 == (_QWORD *)((char *)&g_free + v6) )
{
v10 = v3;
result = _s_malloc((unsigned int)(v4 + 44));
v8 = v10;
}
else
{
func2(v7);
result = (__int64)(v7 - 2);
}
*(_DWORD *)(result + 12) = v8;
}
return result;
}

original_code:
static struct s_packet * iget_free_packet(int size)
{
 if(!g_init) {
  g_init = 1;
  int i;
  for(i = 0; i < 32; ++i) {
   struct s_list * list = &g_free[i];
   s_list_init(list);
  }
 }
 if(size > (1 << 22)) {
  printf("too big packet size:%d""\n", size);
  return ((void *)0);
 }
 int i;
 i = 4;
 while((1 << i) < size) i++;
 struct s_packet * pkt;
 struct s_list * list = &g_free[i];
 if(!((list)->next == (list))) {
  struct s_list * p = ((list)->next);
  s_list_del(p);
  pkt = (struct s_packet*)((size_t)(p) - (size_t)(&((struct s_packet*)0)->list));
 } else {
  int real_sz = sizeof(struct s_packet) + (4 + 4 + 4) + (1 << i);
  pkt = (struct s_packet *)(char*)__s_malloc(sizeof(char) * (real_sz));
 }
 pkt->exp = i;
 return pkt;
}

canonical_original_code:
static struct s_packet *iget_free_packet(int size)
{
 if(!g_init) {
  g_init = 1;
  int i;
  for(i = 0; i < 32; ++i) {
   struct s_list *list = &g_free[i];
   s_list_init(list);
  }
 }
 if(size > (1 << 22)) {
  printf("too big packet size:%d""\n", size);
  return ((void *)0);
 }
 int i;
 i = 4;
 while((1 << i) < size) i++;
 struct s_packet *pkt;
 struct s_list *list = &g_free[i];
 if(!((list)->next == (list))) {
  struct s_list *p = ((list)->next);
  s_list_del(p);
  pkt = (struct s_packet *)((unsigned long)(p) - (unsigned long)(&((struct s_packet *)0)->list));
 } else {
  int real_sz = sizeof(struct s_packet) + (4 + 4 + 4) + (1 << i);
  pkt = (struct s_packet *)(char *)__s_malloc(sizeof(char) * (real_sz));
 }
 pkt->exp = i;
 return pkt;
}

variable_types: size int

variable_types: struct s_list { struct s_list *prev; struct s_list *next; } *

variable_types: struct s_packet { int size; int pos; int ref_count; int exp; struct s_list { struct s_list *prev; struct s_list *next; } list; } *

user_defined_types: struct s_packet { int size; int pos; int ref_count; int exp; struct s_list list; }


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

result = iget_free_packet(a1);
if ( result )
{
*(_DWORD *)result = a1 + 12;
*(_QWORD *)(result + 4) = 0x10000000CLL;
*(_DWORD *)(result + 32) = a1 + 12;
}
return result;
}

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

result = func3(a1);
if ( result )
{
*(_DWORD *)result = a1 + 12;
*(_QWORD *)(result + 4) = 0x10000000CLL;
*(_DWORD *)(result + 32) = a1 + 12;
}
return result;
}

original_code:
struct s_packet * s_packet_create(int size)
{
 struct s_packet * pkt = iget_free_packet(size);
 if(!pkt) {
  return ((void *)0);
 }
 size += (4 + 4 + 4);
 pkt->size = size;
 pkt->pos = (4 + 4 + 4);
 pkt->ref_count = 1;
 char * p = (char *)(pkt + 1);
 p[0] = size & 0xFF;
 p[1] = (size >> 8) & 0xFF;
 p[2] = (size >> 16) & 0xFF;
 p[3] = (size >> 24) & 0xFF;
 return pkt;
}

canonical_original_code:
struct s_packet *s_packet_create(int size)
{
 struct s_packet *pkt = iget_free_packet(size);
 if(!pkt) {
  return ((void *)0);
 }
 size += (4 + 4 + 4);
 pkt->size = size;
 pkt->pos = (4 + 4 + 4);
 pkt->ref_count = 1;
 char *p = (char *)(pkt + 1);
 p[0] = size & 0xFF;
 p[1] = (size >> 8) & 0xFF;
 p[2] = (size >> 16) & 0xFF;
 p[3] = (size >> 24) & 0xFF;
 return pkt;
}

variable_types:
p
char *

return_type: struct s_packet { int size; int pos; int ref_count; int exp; struct s_list { struct s_list *prev; struct s_list *next; } list; } *


decompiled_code:
__int64 __fastcall s_packet_size(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
return *a1;
}

original_code:
int s_packet_size(struct s_packet * pkt)
{
 return pkt->size;
}

canonical_original_code:
int s_packet_size(struct s_packet *pkt)
{
 return pkt->size;
}

user_defined_types: struct s_list { struct s_list *prev; struct s_list *next; }


decompiled_code:
__int64 __fastcall s_packet_data_p(__int64 a1)
{
return a1 + 32;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return a1 + 32;
}

original_code:
char * s_packet_data_p(struct s_packet * pkt)
{
 return (char*)(pkt + 1);
}

canonical_original_code:
char *s_packet_data_p(struct s_packet *pkt)
{
 return (char *)(pkt + 1);
}

return_type: char *


decompiled_code:
__int64 __fastcall s_packet_seek(_DWORD *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = (unsigned int)(*a1 - 12);
if ( (int)a2 < 0 || (int)v2 < (int)a2 )
{
printf("seek offset:%d of %d not valid!\n", a2, v2);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
a1[1] = a2 + 12;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = (unsigned int)(*a1 - 12);
if ( (int)a2 < 0 || (int)v2 < (int)a2 )
{
printf("seek offset:%d of %d not valid!\n", a2, v2);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
a1[1] = a2 + 12;
}
return result;
}

original_code:
int s_packet_seek(struct s_packet * pkt, int offset)
{
 int sz_can_rw = pkt->size - (4 + 4 + 4);
 if(offset < 0 || offset > sz_can_rw) {
  printf("seek offset:%d of %d not valid!""\n", offset, sz_can_rw);
  return -1;
 }
 pkt->pos = offset + (4 + 4 + 4);
 return 0;
}

canonical_original_code:
int s_packet_seek(struct s_packet *pkt, int offset)
{
 int sz_can_rw = pkt->size - (4 + 4 + 4);
 if(offset < 0 || offset > sz_can_rw) {
  printf("seek offset:%d of %d not valid!""\n", offset, sz_can_rw);
  return -1;
 }
 pkt->pos = offset + (4 + 4 + 4);
 return 0;
}

variable_types: offset int


decompiled_code:
__int64 __fastcall s_packet_read_char(_DWORD *a1, _BYTE *a2)
{
int v2; // edx
unsigned int v3; // er8
__int64 v4; // rax
__int64 v5; // rdx

v2 = a1[1];
if ( v2 >= *a1 )
{
puts("no data for read_char!");
v3 = -1;
}
else
{
v3 = 0;
if ( a2 )
{
a1[1] = v2 + 1;
v4 = s_packet_data_p((__int64)a1);
*a2 = *(_BYTE *)(v4 + v5);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, _BYTE *a2)
{
int v2; // edx
unsigned int v3; // er8
__int64 v4; // rax
__int64 v5; // rdx

v2 = a1[1];
if ( v2 >= *a1 )
{
puts("no data for read_char!");
v3 = -1;
}
else
{
v3 = 0;
if ( a2 )
{
a1[1] = v2 + 1;
v4 = func7((__int64)a1);
*a2 = *(_BYTE *)(v4 + v5);
}
}
return v3;
}

original_code:
int s_packet_read_char(struct s_packet * pkt, char * c)
{
 if(pkt->pos + 1 > pkt->size) {
  printf("no data for read_char!""\n");
  return -1;
 }
 char * p = s_packet_data_p(pkt);
 if(c) {
  *c = p[pkt->pos++];
 }
 return 0;
}

canonical_original_code:
int s_packet_read_char(struct s_packet *pkt, char *c)
{
 if(pkt->pos + 1 > pkt->size) {
  printf("no data for read_char!""\n");
  return -1;
 }
 char *p = s_packet_data_p(pkt);
 if(c) {
  *c = p[pkt->pos++];
 }
 return 0;
}

variable_types:
c
char *


decompiled_code:
__int64 __fastcall s_packet_read_short(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_WORD *v5; // rdx
__int64 result; // rax

v3 = a1[1];
if ( (int)v3 + 1 >= (int)*a1 )
{
printf("no data for read_short(pos:%d, size:%d!\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = s_packet_data_p((__int64)a1);
*v5 = *(_WORD *)(v4 + (int)v3);
}
result = 0LL;
a1[1] = v3 + 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_WORD *v5; // rdx
__int64 result; // rax

v3 = a1[1];
if ( (int)v3 + 1 >= (int)*a1 )
{
printf("no data for read_short(pos:%d, size:%d!\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = func7((__int64)a1);
*v5 = *(_WORD *)(v4 + (int)v3);
}
result = 0LL;
a1[1] = v3 + 2;
}
return result;
}

original_code:
int s_packet_read_short(struct s_packet * pkt, short * s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no data for read_short(pos:%d, size:%d!""\n", pkt->pos, pkt->size);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 if(s) {
  *s = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00);
 }
 pkt->pos += 2;
 return 0;
}

canonical_original_code:
int s_packet_read_short(struct s_packet *pkt, short *s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no data for read_short(pos:%d, size:%d!""\n", pkt->pos, pkt->size);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 if(s) {
  *s = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00);
 }
 pkt->pos += 2;
 return 0;
}

variable_types:
s
short *


decompiled_code:
__int64 __fastcall s_packet_read_ushort(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_WORD *v5; // rdx
__int64 result; // rax

v3 = a1[1];
if ( (int)v3 + 1 >= (int)*a1 )
{
printf("no data for read_ushort(pos:%d, size:%d)!\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = s_packet_data_p((__int64)a1);
*v5 = *(_WORD *)(v4 + (int)v3);
}
result = 0LL;
a1[1] = v3 + 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_WORD *v5; // rdx
__int64 result; // rax

v3 = a1[1];
if ( (int)v3 + 1 >= (int)*a1 )
{
printf("no data for read_ushort(pos:%d, size:%d)!\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = func7((__int64)a1);
*v5 = *(_WORD *)(v4 + (int)v3);
}
result = 0LL;
a1[1] = v3 + 2;
}
return result;
}

original_code:
int s_packet_read_ushort(struct s_packet * pkt, unsigned short * s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no data for read_ushort(pos:%d, size:%d)!""\n", pkt->pos, pkt->size);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 if(s) {
  *s = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00);
 }
 pkt->pos += 2;
 return 0;
}

canonical_original_code:
int s_packet_read_ushort(struct s_packet *pkt, unsigned short *s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no data for read_ushort(pos:%d, size:%d)!""\n", pkt->pos, pkt->size);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 if(s) {
  *s = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00);
 }
 pkt->pos += 2;
 return 0;
}

variable_types:
s
unsigned short *


decompiled_code:
__int64 __fastcall s_packet_read_int(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_DWORD *v5; // rdx
__int64 result; // rax

v3 = (int)a1[1];
if ( (int)v3 + 3 >= (int)*a1 )
{
printf("no data for read_int!(pos:%d, size:%d)\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = s_packet_data_p((__int64)a1);
*v5 = *(_DWORD *)(v4 + v3);
LODWORD(v3) = a1[1];
}
result = 0LL;
a1[1] = v3 + 4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_DWORD *v5; // rdx
__int64 result; // rax

v3 = (int)a1[1];
if ( (int)v3 + 3 >= (int)*a1 )
{
printf("no data for read_int!(pos:%d, size:%d)\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = func7((__int64)a1);
*v5 = *(_DWORD *)(v4 + v3);
LODWORD(v3) = a1[1];
}
result = 0LL;
a1[1] = v3 + 4;
}
return result;
}

original_code:
int s_packet_read_int(struct s_packet * pkt, int * i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no data for read_int!(pos:%d, size:%d)""\n", pkt->pos, pkt->size);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 if(i) {
  *i = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00) | (p[2] << 16 & 0xFF0000) | (p[3] << 24 & 0xFF000000);
 }
 pkt->pos += 4;
 return 0;
}

canonical_original_code:
int s_packet_read_int(struct s_packet *pkt, int *i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no data for read_int!(pos:%d, size:%d)""\n", pkt->pos, pkt->size);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 if(i) {
  *i = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00) | (p[2] << 16 & 0xFF0000) | (p[3] << 24 & 0xFF000000);
 }
 pkt->pos += 4;
 return 0;
}

variable_types:
i
int *


decompiled_code:
__int64 __fastcall s_packet_read_uint(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_DWORD *v5; // rdx
__int64 result; // rax

v3 = (int)a1[1];
if ( (int)v3 + 3 >= (int)*a1 )
{
printf("no data for read_uint!(pos:%d, size:%d)\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = s_packet_data_p((__int64)a1);
*v5 = *(_DWORD *)(v4 + v3);
LODWORD(v3) = a1[1];
}
result = 0LL;
a1[1] = v3 + 4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, __int64 a2)
{
__int64 v3; // rsi
__int64 v4; // rax
_DWORD *v5; // rdx
__int64 result; // rax

v3 = (int)a1[1];
if ( (int)v3 + 3 >= (int)*a1 )
{
printf("no data for read_uint!(pos:%d, size:%d)\n", v3, *a1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a2 )
{
v4 = func7((__int64)a1);
*v5 = *(_DWORD *)(v4 + v3);
LODWORD(v3) = a1[1];
}
result = 0LL;
a1[1] = v3 + 4;
}
return result;
}

original_code:
int s_packet_read_uint(struct s_packet * pkt, unsigned int * i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no data for read_uint!(pos:%d, size:%d)""\n", pkt->pos, pkt->size);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 if(i) {
  *i = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00) | (p[2] << 16 & 0xFF0000) | (p[3] << 24 & 0xFF000000);
 }
 pkt->pos += 4;
 return 0;
}

canonical_original_code:
int s_packet_read_uint(struct s_packet *pkt, unsigned int *i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no data for read_uint!(pos:%d, size:%d)""\n", pkt->pos, pkt->size);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 if(i) {
  *i = (p[0] & 0xFF) | (p[1] << 8 & 0xFF00) | (p[2] << 16 & 0xFF0000) | (p[3] << 24 & 0xFF000000);
 }
 pkt->pos += 4;
 return 0;
}

variable_types:
i
unsigned int *


decompiled_code:
__int64 __fastcall s_packet_get_fun(unsigned int *a1)
{
unsigned int v1; // ebp
__int64 result; // rax
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (int)*a1 <= 11 )
{
puts("[Error] get_fun:Packet size is less then Head size!");
result = 0LL;
}
else
{
v1 = a1[1];
a1[1] = 4;
s_packet_read_uint(a1, (__int64)v3);
a1[1] = v1;
result = v3[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int *a1)
{
unsigned int v1; // ebp
__int64 result; // rax
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (int)*a1 <= 11 )
{
puts("[Error] get_fun:Packet size is less then Head size!");
result = 0LL;
}
else
{
v1 = a1[1];
a1[1] = 4;
func13(a1, (__int64)v3);
a1[1] = v1;
result = v3[0];
}
return result;
}

original_code:
unsigned int s_packet_get_fun(struct s_packet * pkt)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] get_fun:Packet size is less then Head size!""\n");
  return 0;
 }
 unsigned int fun;
 int pos = pkt->pos;
 pkt->pos = (0 + 4);
 s_packet_read_uint(pkt, &fun);
 pkt->pos = pos;
 return fun;
}

canonical_original_code:
unsigned int s_packet_get_fun(struct s_packet *pkt)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] get_fun:Packet size is less then Head size!""\n");
  return 0;
 }
 unsigned int fun;
 int pos = pkt->pos;
 pkt->pos = (0 + 4);
 s_packet_read_uint(pkt, &fun);
 pkt->pos = pos;
 return fun;
}

variable_types:
fun
unsigned int

variable_types: pos int

return_type: unsigned int


decompiled_code:
__int64 __fastcall s_packet_get_req(unsigned int *a1)
{
unsigned int v1; // ebp
__int64 result; // rax
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (int)*a1 <= 11 )
{
puts("[Error] get_req:Packet size is less then Head size!");
result = 0LL;
}
else
{
v1 = a1[1];
a1[1] = 8;
s_packet_read_uint(a1, (__int64)v3);
a1[1] = v1;
result = v3[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int *a1)
{
unsigned int v1; // ebp
__int64 result; // rax
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (int)*a1 <= 11 )
{
puts("[Error] get_req:Packet size is less then Head size!");
result = 0LL;
}
else
{
v1 = a1[1];
a1[1] = 8;
func13(a1, (__int64)v3);
a1[1] = v1;
result = v3[0];
}
return result;
}

original_code:
unsigned int s_packet_get_req(struct s_packet * pkt)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] get_req:Packet size is less then Head size!""\n");
  return 0;
 }
 unsigned int req;
 int pos = pkt->pos;
 pkt->pos = ((0 + 4) + 4);
 s_packet_read_uint(pkt, &req);
 pkt->pos = pos;
 return req;
}

canonical_original_code:
unsigned int s_packet_get_req(struct s_packet *pkt)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] get_req:Packet size is less then Head size!""\n");
  return 0;
 }
 unsigned int req;
 int pos = pkt->pos;
 pkt->pos = ((0 + 4) + 4);
 s_packet_read_uint(pkt, &req);
 pkt->pos = pos;
 return req;
}

variable_types:
req
unsigned int


decompiled_code:
_BOOL8 __fastcall s_packet_eof(_DWORD *a1)
{
return a1[1] >= *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(_DWORD *a1)
{
return a1[1] >= *a1;
}

original_code:
int s_packet_eof(struct s_packet * pkt)
{
 if(pkt->pos >= pkt->size) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int s_packet_eof(struct s_packet *pkt)
{
 if(pkt->pos >= pkt->size) {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall s_packet_write_char(_DWORD *a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] >= *a1 )
{
printf("no room for write char(%c)!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = s_packet_data_p((__int64)a1);
a1[1] = v3 + 1;
*(_BYTE *)(v2 + v3) = a2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_DWORD *a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] >= *a1 )
{
printf("no room for write char(%c)!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = func7((__int64)a1);
a1[1] = v3 + 1;
*(_BYTE *)(v2 + v3) = a2;
result = 0LL;
}
return result;
}

original_code:
int s_packet_write_char(struct s_packet * pkt, char c)
{
 if(pkt->pos + 1 > pkt->size) {
  printf("no room for write char(%c)!""\n", c);
  return -1;
 }
 char * p = s_packet_data_p(pkt);
 p[pkt->pos++] = c;
 return 0;
}

canonical_original_code:
int s_packet_write_char(struct s_packet *pkt, char c)
{
 if(pkt->pos + 1 > pkt->size) {
  printf("no room for write char(%c)!""\n", c);
  return -1;
 }
 char *p = s_packet_data_p(pkt);
 p[pkt->pos++] = c;
 return 0;
}

variable_types: c char


decompiled_code:
__int64 __fastcall s_packet_write_short(_DWORD *a1, __int16 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 1 >= *a1 )
{
printf("no room for write short(%d)!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = s_packet_data_p((__int64)a1);
*(_WORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(_DWORD *a1, __int16 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 1 >= *a1 )
{
printf("no room for write short(%d)!\n", (unsigned int)a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = func7((__int64)a1);
*(_WORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 2;
}
return result;
}

original_code:
int s_packet_write_short(struct s_packet * pkt, short s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no room for write short(%d)!""\n", s);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = s & 0xFF;
 p[1] = (s >> 8) & 0xFF;
 pkt->pos += 2;
 return 0;
}

canonical_original_code:
int s_packet_write_short(struct s_packet *pkt, short s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no room for write short(%d)!""\n", s);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = s & 0xFF;
 p[1] = (s >> 8) & 0xFF;
 pkt->pos += 2;
 return 0;
}

variable_types: s short


decompiled_code:
__int64 __fastcall s_packet_write_ushort(_DWORD *a1, unsigned __int16 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 1 >= *a1 )
{
printf("no room for write short(%d)!\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = s_packet_data_p((__int64)a1);
*(_WORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(_DWORD *a1, unsigned __int16 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 1 >= *a1 )
{
printf("no room for write short(%d)!\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = func7((__int64)a1);
*(_WORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 2;
}
return result;
}

original_code:
int s_packet_write_ushort(struct s_packet * pkt, unsigned short s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no room for write short(%d)!""\n", s);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = s & 0xFF;
 p[1] = (s >> 8) & 0xFF;
 pkt->pos += 2;
 return 0;
}

canonical_original_code:
int s_packet_write_ushort(struct s_packet *pkt, unsigned short s)
{
 if(pkt->pos + 2 > pkt->size) {
  printf("no room for write short(%d)!""\n", s);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = s & 0xFF;
 p[1] = (s >> 8) & 0xFF;
 pkt->pos += 2;
 return 0;
}

variable_types:
s
unsigned short


decompiled_code:
__int64 __fastcall s_packet_write_int(_DWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 3 >= *a1 )
{
printf("no room for write int(%d)!\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = s_packet_data_p((__int64)a1);
*(_DWORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(_DWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 3 >= *a1 )
{
printf("no room for write int(%d)!\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = func7((__int64)a1);
*(_DWORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 4;
}
return result;
}

original_code:
int s_packet_write_int(struct s_packet * pkt, int i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no room for write int(%d)!""\n", i);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = i & 0xFF;
 p[1] = (i >> 8) & 0xFF;
 p[2] = (i >> 16) & 0xFF;
 p[3] = (i >> 24) & 0xFF;
 pkt->pos += 4;
 return 0;
}

canonical_original_code:
int s_packet_write_int(struct s_packet *pkt, int i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no room for write int(%d)!""\n", i);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = i & 0xFF;
 p[1] = (i >> 8) & 0xFF;
 p[2] = (i >> 16) & 0xFF;
 p[3] = (i >> 24) & 0xFF;
 pkt->pos += 4;
 return 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall s_packet_write_uint(_DWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 3 >= *a1 )
{
printf("no room for write int(%d)!\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = s_packet_data_p((__int64)a1);
*(_DWORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(_DWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( a1[1] + 3 >= *a1 )
{
printf("no room for write int(%d)!\n", a2);
result = 0xFFFFFFFFLL;
}
else
{
v2 = func7((__int64)a1);
*(_DWORD *)(v2 + v3) = a2;
result = 0LL;
a1[1] += 4;
}
return result;
}

original_code:
int s_packet_write_uint(struct s_packet * pkt, unsigned int i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no room for write int(%d)!""\n", i);
  return -1;
 }
 char * p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = i & 0xFF;
 p[1] = (i >> 8) & 0xFF;
 p[2] = (i >> 16) & 0xFF;
 p[3] = (i >> 24) & 0xFF;
 pkt->pos += 4;
 return 0;
}

canonical_original_code:
int s_packet_write_uint(struct s_packet *pkt, unsigned int i)
{
 if(pkt->pos + 4 > pkt->size) {
  printf("no room for write int(%d)!""\n", i);
  return -1;
 }
 char *p = s_packet_data_p(pkt) + pkt->pos;
 p[0] = i & 0xFF;
 p[1] = (i >> 8) & 0xFF;
 p[2] = (i >> 16) & 0xFF;
 p[3] = (i >> 24) & 0xFF;
 pkt->pos += 4;
 return 0;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall s_packet_set_fun(int *a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax

if ( *a1 <= 11 )
{
puts("[Error] set_fun:Packet size is less then Head size!");
result = 0xFFFFFFFFLL;
}
else
{
v2 = a1[1];
a1[1] = 4;
s_packet_write_uint(a1, a2);
a1[1] = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(int *a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax

if ( *a1 <= 11 )
{
puts("[Error] set_fun:Packet size is less then Head size!");
result = 0xFFFFFFFFLL;
}
else
{
v2 = a1[1];
a1[1] = 4;
func22(a1, a2);
a1[1] = v2;
result = 0LL;
}
return result;
}

original_code:
int s_packet_set_fun(struct s_packet * pkt, unsigned int fun)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] set_fun:Packet size is less then Head size!""\n");
  return -1;
 }
 int pos = pkt->pos;
 pkt->pos = (0 + 4);
 s_packet_write_uint(pkt, fun);
 pkt->pos = pos;
 return 0;
}

canonical_original_code:
int s_packet_set_fun(struct s_packet *pkt, unsigned int fun)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] set_fun:Packet size is less then Head size!""\n");
  return -1;
 }
 int pos = pkt->pos;
 pkt->pos = (0 + 4);
 s_packet_write_uint(pkt, fun);
 pkt->pos = pos;
 return 0;
}


decompiled_code:
__int64 __fastcall s_packet_set_req(int *a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax

if ( *a1 <= 11 )
{
puts("[Error] set_req:Packet size is less then Head size!");
result = 0xFFFFFFFFLL;
}
else
{
v2 = a1[1];
a1[1] = 8;
s_packet_write_uint(a1, a2);
a1[1] = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(int *a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax

if ( *a1 <= 11 )
{
puts("[Error] set_req:Packet size is less then Head size!");
result = 0xFFFFFFFFLL;
}
else
{
v2 = a1[1];
a1[1] = 8;
func22(a1, a2);
a1[1] = v2;
result = 0LL;
}
return result;
}

original_code:
int s_packet_set_req(struct s_packet * pkt, unsigned int req)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] set_req:Packet size is less then Head size!""\n");
  return -1;
 }
 int pos = pkt->pos;
 pkt->pos = ((0 + 4) + 4);
 s_packet_write_uint(pkt, req);
 pkt->pos = pos;
 return 0;
}

canonical_original_code:
int s_packet_set_req(struct s_packet *pkt, unsigned int req)
{
 if(pkt->size < (4 + 4 + 4)) {
  printf("[Error] set_req:Packet size is less then Head size!""\n");
  return -1;
 }
 int pos = pkt->pos;
 pkt->pos = ((0 + 4) + 4);
 s_packet_write_uint(pkt, req);
 pkt->pos = pos;
 return 0;
}


decompiled_code:
__int64 __fastcall s_packet_write_s(_DWORD *a1, const char *a2, int a3)
{
__int64 v4; // rax
size_t v5; // rdx
__int64 result; // rax

if ( a3 > 0x7FFF )
{
printf("string is too long(%d) for write in packet!\n", (unsigned int)a3);
result = 0xFFFFFFFFLL;
}
else if ( a3 + a1[1] + 2 > *a1 )
{
printf("no room for write string:%s\n", a2);
result = 0xFFFFFFFFLL;
}
else if ( (int)s_packet_write_short(a1, a3) < 0 )
{
puts("write len error?");
result = 0xFFFFFFFFLL;
}
else
{
v4 = s_packet_data_p((__int64)a1);
memcpy((void *)(v4 + (int)a1[1]), a2, v5);
a1[1] += a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func25(_DWORD *a1, const char *a2, int a3)
{
__int64 v4; // rax
size_t v5; // rdx
__int64 result; // rax

if ( a3 > 0x7FFF )
{
printf("string is too long(%d) for write in packet!\n", (unsigned int)a3);
result = 0xFFFFFFFFLL;
}
else if ( a3 + a1[1] + 2 > *a1 )
{
printf("no room for write string:%s\n", a2);
result = 0xFFFFFFFFLL;
}
else if ( (int)func19(a1, a3) < 0 )
{
puts("write len error?");
result = 0xFFFFFFFFLL;
}
else
{
v4 = func7((__int64)a1);
memcpy((void *)(v4 + (int)a1[1]), a2, v5);
a1[1] += a3;
result = 0LL;
}
return result;
}

original_code:
int s_packet_write_s(struct s_packet * pkt, const char * pstr, int len)
{
 if(len >= (1 << 15)) {
  printf("string is too long(%d) for write in packet!""\n", len);
  return -1;
 }
 if(pkt->pos + 2 + len > pkt->size) {
  printf("no room for write string:%s""\n", pstr);
  return -1;
 }
 if(s_packet_write_short(pkt, len) < 0) {
  printf("write len error?""\n");
  return -1;
 }
 char * p = (char*)s_packet_data_p(pkt) + pkt->pos;
 memcpy(p, pstr, len);
 pkt->pos += len;
 return 0;
}

canonical_original_code:
int s_packet_write_s(struct s_packet *pkt, char *pstr, int len)
{
 if(len >= (1 << 15)) {
  printf("string is too long(%d) for write in packet!""\n", len);
  return -1;
 }
 if(pkt->pos + 2 + len > pkt->size) {
  printf("no room for write string:%s""\n", pstr);
  return -1;
 }
 if(s_packet_write_short(pkt, len) < 0) {
  printf("write len error?""\n");
  return -1;
 }
 char *p = (char*)s_packet_data_p(pkt) + pkt->pos;
 memcpy(p, pstr, len);
 pkt->pos += len;
 return 0;
}

variable_types:
pstr
char *

variable_types: len int


decompiled_code:
__int64 __fastcall s_packet_read_to_end(_DWORD *a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // rsi
unsigned int v5; // er12
__int64 v6; // rax
void *v7; // r8
__int64 result; // rax

v4 = (int)a1[1];
v5 = *a1 - v4;
if ( !a3 )
return v5;
if ( a2 )
{
if ( (int)*a3 < (int)v5 )
return (unsigned int)-1;
v6 = s_packet_data_p((__int64)a1);
memcpy(v7, (const void *)(v6 + v4), (int)v5);
return v5;
}
result = v5;
*a3 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func27(_DWORD *a1, __int64 a2, unsigned int *a3)
{
__int64 v4; // rsi
unsigned int v5; // er12
__int64 v6; // rax
void *v7; // r8
__int64 result; // rax

v4 = (int)a1[1];
v5 = *a1 - v4;
if ( !a3 )
return v5;
if ( a2 )
{
if ( (int)*a3 < (int)v5 )
return (unsigned int)-1;
v6 = func7((__int64)a1);
memcpy(v7, (const void *)(v6 + v4), (int)v5);
return v5;
}
result = v5;
*a3 = v5;
return result;
}

original_code:
int s_packet_read_to_end(struct s_packet * pkt, char * buf, int * size)
{
 int sz = pkt->size - pkt->pos;
 if(!size) {
  return sz;
 }
 if(!buf) {
  *size = sz;
  return sz;
 }
 if(sz > *size) {
  return -1;
 }
 char * p = (char*)s_packet_data_p(pkt) + pkt->pos;
 memcpy(buf, p, sz);
 return sz;
}

canonical_original_code:
int s_packet_read_to_end(struct s_packet *pkt, char *buf, int *size)
{
 int sz = pkt->size - pkt->pos;
 if(!size) {
  return sz;
 }
 if(!buf) {
  *size = sz;
  return sz;
 }
 if(sz > *size) {
  return -1;
 }
 char *p = (char*)s_packet_data_p(pkt) + pkt->pos;
 memcpy(buf, p, sz);
 return sz;
}

variable_types: struct s_packet { int size; int pos; int ref_count; int exp; struct s_list { struct s_list *prev; struct s_list *next; } list; } *

variable_types:
buf
char *

variable_types:
size
int *

variable_types: sz int

variable_types:
p
char *


decompiled_code:
void __fastcall s_packet_grab(__int64 a1)
{
++*(_DWORD *)(a1 + 8);
}

canonical_decompiled_code:
void __fastcall func28(__int64 a1)
{
++*(_DWORD *)(a1 + 8);
}

original_code:
void s_packet_grab(struct s_packet * pkt)
{
 pkt->ref_count++;
}

canonical_original_code:
void s_packet_grab(struct s_packet *pkt)
{
 pkt->ref_count++;
}


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

result = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = result;
if ( !result )
{
idrop_free_packet(a1);
result = *(_DWORD *)(a1 + 8);
if ( result >= 0 )
return result;
return puts("double-free packet!");
}
if ( result < 0 )
return puts("double-free packet!");
return result;
}

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

result = *(_DWORD *)(a1 + 8) - 1;
*(_DWORD *)(a1 + 8) = result;
if ( !result )
{
func4(a1);
result = *(_DWORD *)(a1 + 8);
if ( result >= 0 )
return result;
return puts("double-free packet!");
}
if ( result < 0 )
return puts("double-free packet!");
return result;
}

original_code:
void s_packet_drop(struct s_packet * pkt)
{
 pkt->ref_count--;
 if(pkt->ref_count == 0) {
  idrop_free_packet(pkt);
 }
 if(pkt->ref_count < 0) {
  printf("double-free packet!""\n");
 }
}

canonical_original_code:
void s_packet_drop(struct s_packet *pkt)
{
 pkt->ref_count--;
 if(pkt->ref_count == 0) {
  idrop_free_packet(pkt);
 }
 if(pkt->ref_count < 0) {
  printf("double-free packet!""\n");
 }
}


decompiled_code:
int __fastcall s_packet_dump(unsigned int *a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rsi

printf("dump packet, size:%d\n", *a1);
v1 = s_packet_data_p((__int64)a1);
if ( (int)*a1 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
v4 = (unsigned int)*(char *)(v2 + v3++);
LODWORD(v1) = printf("%x\n", v4);
}
while ( (int)*a1 > (int)v3 );
}
return v1;
}

canonical_decompiled_code:
int __fastcall func30(unsigned int *a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rsi

printf("dump packet, size:%d\n", *a1);
v1 = func7((__int64)a1);
if ( (int)*a1 > 0 )
{
v2 = v1;
v3 = 0LL;
do
{
v4 = (unsigned int)*(char *)(v2 + v3++);
LODWORD(v1) = printf("%x\n", v4);
}
while ( (int)*a1 > (int)v3 );
}
return v1;
}

original_code:
void s_packet_dump(struct s_packet * pkt)
{
 printf("dump packet, size:%d""\n", pkt->size);
 int i;
 char * p = s_packet_data_p(pkt);
 for(i = 0; i < pkt->size; ++i) {
  printf("%x""\n", p[i]);
 }
}

canonical_original_code:
void s_packet_dump(struct s_packet *pkt)
{
 printf("dump packet, size:%d""\n", pkt->size);
 int i;
 char *p = s_packet_data_p(pkt);
 for(i = 0; i < pkt->size; ++i) {
  printf("%x""\n", p[i]);
 }
}


decompiled_code:
__int64 __fastcall s_file_reader_create(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
void *v4; // r14
__int64 v5; // r12
struct stat v7; // [rsp+0h] [rbp-C8h] BYREF

v1 = open(a1, 0);
if ( v1 < 0 )
{
v5 = 0LL;
printf("open %s failed!\n", a1);
}
else
{
v2 = v1;
if ( fstat(v1, &v7) < 0 )
{
v5 = 0LL;
close(v2);
printf("fstat %s failed!\n", a1);
}
else
{
v3 = v7.st_size;
if ( SLODWORD(v7.st_size) <= 0 )
{
v5 = 0LL;
close(v2);
printf("open empty file:%s!\n", a1);
}
else
{
v4 = mmap(0LL, SLODWORD(v7.st_size), 1, 2, v2, 0LL);
if ( v4 )
{
v5 = _s_malloc(16LL);
close(v2);
if ( v5 )
{
*(_QWORD *)v5 = v4;
*(_DWORD *)(v5 + 8) = v3;
}
else
{
munmap(v4, v3);
printf("no mem for s_file_reader:%s!\n", a1);
}
}
else
{
v5 = 0LL;
close(v2);
printf("mmap %s failed!\n", a1);
}
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
void *v4; // r14
__int64 v5; // r12
struct stat v7; // [rsp+0h] [rbp-C8h] BYREF

v1 = open(a1, 0);
if ( v1 < 0 )
{
v5 = 0LL;
printf("open %s failed!\n", a1);
}
else
{
v2 = v1;
if ( fstat(v1, &v7) < 0 )
{
v5 = 0LL;
close(v2);
printf("fstat %s failed!\n", a1);
}
else
{
v3 = v7.st_size;
if ( SLODWORD(v7.st_size) <= 0 )
{
v5 = 0LL;
close(v2);
printf("open empty file:%s!\n", a1);
}
else
{
v4 = mmap(0LL, SLODWORD(v7.st_size), 1, 2, v2, 0LL);
if ( v4 )
{
v5 = _s_malloc(16LL);
close(v2);
if ( v5 )
{
*(_QWORD *)v5 = v4;
*(_DWORD *)(v5 + 8) = v3;
}
else
{
munmap(v4, v3);
printf("no mem for s_file_reader:%s!\n", a1);
}
}
else
{
v5 = 0LL;
close(v2);
printf("mmap %s failed!\n", a1);
}
}
}
}
return v5;
}

original_code:
struct s_file_reader * s_file_reader_create(const char * filename)
{
 int fd = open(filename, 00);
 if(fd < 0) {
  printf("open %s failed!""\n", filename);
  return ((void *)0);
 }
 struct stat s;
 if(fstat(fd, &s) < 0) {
  close(fd);
  printf("fstat %s failed!""\n", filename);
  return ((void *)0);
 }
 int sz = s.st_size;
 if(sz <= 0) {
  close(fd);
  printf("open empty file:%s!""\n", filename);
  return ((void *)0);
 }
 char * p = mmap(((void *)0), sz, 0x1, 0x02, fd, 0);
 if(!p) {
  close(fd);
  printf("mmap %s failed!""\n", filename);
  return ((void *)0);
 }
 struct s_file_reader * fr = (struct s_file_reader*)__s_malloc(sizeof(struct s_file_reader) * (1));
 if(!fr) {
  close(fd);
  munmap(p, sz);
  printf("no mem for s_file_reader:%s!""\n", filename);
  return ((void *)0);
 }
 close(fd);
 fr->p = p;
 fr->len = sz;
 return fr;
}

canonical_original_code:
struct s_file_reader *s_file_reader_create(char *filename)
{
 int fd = open(filename, 00);
 if(fd < 0) {
  printf("open %s failed!""\n", filename);
  return ((void *)0);
 }
 struct stat s;
 if(fstat(fd, &s) < 0) {
  close(fd);
  printf("fstat %s failed!""\n", filename);
  return ((void *)0);
 }
 int sz = s.st_size;
 if(sz <= 0) {
  close(fd);
  printf("open empty file:%s!""\n", filename);
  return ((void *)0);
 }
 char *p = mmap(((void *)0), sz, 0x1, 0x02, fd, 0);
 if(!p) {
  close(fd);
  printf("mmap %s failed!""\n", filename);
  return ((void *)0);
 }
 struct s_file_reader *fr = (struct s_file_reader*)__s_malloc(sizeof(struct s_file_reader) * (1));
 if(!fr) {
  close(fd);
  munmap(p, sz);
  printf("no mem for s_file_reader:%s!""\n", filename);
  return ((void *)0);
 }
 close(fd);
 fr->p = p;
 fr->len = sz;
 return fr;
}

variable_types:
filename
char *

variable_types: fd int

variable_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 { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: struct s_file_reader { char *p; int len; } *

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 s_file_reader_destroy(__int64 a1)
{
munmap(*(void **)a1, *(int *)(a1 + 8));
return _s_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
munmap(*(void **)a1, *(int *)(a1 + 8));
return _s_free(a1);
}

original_code:
void s_file_reader_destroy(struct s_file_reader * fr)
{
 munmap(fr->p, fr->len);
 __s_free(fr);
}

canonical_original_code:
void s_file_reader_destroy(struct s_file_reader *fr)
{
 munmap(fr->p, fr->len);
 __s_free(fr);
}

user_defined_types: struct s_file_reader { char *p; int len; }


decompiled_code:
__int64 __fastcall s_file_reader_data_p(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char * s_file_reader_data_p(struct s_file_reader * fr)
{
 return fr->p;
}

canonical_original_code:
char *s_file_reader_data_p(struct s_file_reader *fr)
{
 return fr->p;
}


decompiled_code:
__int64 __fastcall s_file_reader_data_len(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int s_file_reader_data_len(struct s_file_reader * fr)
{
 return fr->len;
}

canonical_original_code:
int s_file_reader_data_len(struct s_file_reader *fr)
{
 return fr->len;
}


expand

decompiled_code:
__int64 __fastcall expand(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
const void *v4; // rbp
void *v5; // rax

v2 = 0;
if ( *(_DWORD *)(a1 + 20) >= (signed int)a2 )
return v2;
v4 = *(const void **)(a1 + 8);
v5 = (void *)_s_malloc(a2 * *(_DWORD *)(a1 + 4));
*(_QWORD *)(a1 + 8) = v5;
if ( !v5 )
{
v2 = -1;
printf(
"no mem for array expand(curr size:%d/%d, to :%d)\n",
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
a2);
return v2;
}
memcpy(v5, v4, *(_DWORD *)(a1 + 4) * *(_DWORD *)(a1 + 16));
_s_free(v4);
*(_DWORD *)(a1 + 20) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
const void *v4; // rbp
void *v5; // rax

v2 = 0;
if ( *(_DWORD *)(a1 + 20) >= (signed int)a2 )
return v2;
v4 = *(const void **)(a1 + 8);
v5 = (void *)_s_malloc(a2 * *(_DWORD *)(a1 + 4));
*(_QWORD *)(a1 + 8) = v5;
if ( !v5 )
{
v2 = -1;
printf(
"no mem for array expand(curr size:%d/%d, to :%d)\n",
*(unsigned int *)(a1 + 16),
*(unsigned int *)(a1 + 20),
a2);
return v2;
}
memcpy(v5, v4, *(_DWORD *)(a1 + 4) * *(_DWORD *)(a1 + 16));
_s_free(v4);
*(_DWORD *)(a1 + 20) = a2;
return 0LL;
}

original_code:
static int expand(struct s_array * array, int sz)
{
 if(array->total >= sz) {
  return 0;
 }
 char * old = array->p;
 array->p = (char*)__s_malloc(sizeof(char) * (sz * array->elem_size));
 if(!array->p) {
  printf("no mem for array expand(curr size:%d/%d, to :%d)""\n", array->nelem, array->total, sz);
  return -1;
 }
 memcpy(array->p, old, array->nelem * array->elem_size);
 __s_free(old);
 array->total = sz;
 return 0;
}

canonical_original_code:
static int expand(struct s_array *array, int sz)
{
 if(array->total >= sz) {
  return 0;
 }
 char *old = array->p;
 array->p = (char *)__s_malloc(sizeof(char) * (sz * array->elem_size));
 if(!array->p) {
  printf("no mem for array expand(curr size:%d/%d, to :%d)""\n", array->nelem, array->total, sz);
  return -1;
 }
 memcpy(array->p, old, array->nelem * array->elem_size);
 __s_free(old);
 array->total = sz;
 return 0;
}

variable_types: struct s_array { int ref_count; int elem_size; char *p; int nelem; int total; } *

variable_types:
old
char *


decompiled_code:
__int64 __fastcall s_array_len(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int s_array_len(struct s_array * array)
{
 return array->nelem;
}

canonical_original_code:
int s_array_len(struct s_array *array)
{
 return array->nelem;
}

user_defined_types: struct s_array { int ref_count; int elem_size; char *p; int nelem; int total; }


original_code:
void *
s_array_push(struct s_array * array)
{
 if(array->nelem >= array->total) {
  int sz = array->total * 2;
  if(expand(array, sz) < 0) {
   return ((void *)0);
  }
 }
 array->nelem++;
 return (((char *)(array->p)) + (array->elem_size) * (array->nelem-1));
}

canonical_original_code:
void *s_array_push(struct s_array *array)
{
 if(array->nelem >= array->total) {
  int sz = array->total * 2;
  if(expand(array, sz) < 0) {
   return ((void *)0);
  }
 }
 array->nelem++;
 return (((char *)(array->p)) + (array->elem_size) * (array->nelem-1));
}


decompiled_code:
__int64 __fastcall s_array_at(__int64 a1, __int64 a2)
{
if ( (int)a2 >= 0 && *(_DWORD *)(a1 + 16) > (int)a2 )
return *(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * (int)a2;
printf("invalid index:%d\n", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( (int)a2 >= 0 && *(_DWORD *)(a1 + 16) > (int)a2 )
return *(_QWORD *)(a1 + 8) + *(_DWORD *)(a1 + 4) * (int)a2;
printf("invalid index:%d\n", a2);
return 0LL;
}

original_code:
void *
s_array_at(struct s_array * array, int index)
{
 if(index < 0 || index >= array->nelem) {
  printf("invalid index:%d""\n", index);
  return ((void *)0);
 }
 return (((char *)(array->p)) + (array->elem_size) * (index));
}

canonical_original_code:
void *s_array_at(struct s_array *array, int index)
{
 if(index < 0 || index >= array->nelem) {
  printf("invalid index:%d""\n", index);
  return ((void *)0);
 }
 return (((char *)(array->p)) + (array->elem_size) * (index));
}

variable_types: index int


decompiled_code:
int __fastcall s_array_rm(__int64 a1, int a2)
{
int v2; // ebp
__int64 v3; // rdx
int v4; // edx
size_t v5; // rdx
int v6; // eax
int result; // eax

v2 = a2;
v3 = *(unsigned int *)(a1 + 16);
if ( a2 < 0 || a2 >= (int)v3 )
return printf("invalid index:%d, nelem:%d\n", (unsigned int)a2, v3);
v4 = v3 - 1;
if ( a2 < v4 )
{
do
{
v5 = *(int *)(a1 + 4);
v6 = v2 * v5;
++v2;
memcpy((void *)(*(_QWORD *)(a1 + 8) + v6), (const void *)(*(_QWORD *)(a1 + 8) + v6 + *(_DWORD *)(a1 + 4)), v5);
result = *(_DWORD *)(a1 + 16);
v4 = result - 1;
}
while ( v2 < result - 1 );
}
*(_DWORD *)(a1 + 16) = v4;
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, int a2)
{
int v2; // ebp
__int64 v3; // rdx
int v4; // edx
size_t v5; // rdx
int v6; // eax
int result; // eax

v2 = a2;
v3 = *(unsigned int *)(a1 + 16);
if ( a2 < 0 || a2 >= (int)v3 )
return printf("invalid index:%d, nelem:%d\n", (unsigned int)a2, v3);
v4 = v3 - 1;
if ( a2 < v4 )
{
do
{
v5 = *(int *)(a1 + 4);
v6 = v2 * v5;
++v2;
memcpy((void *)(*(_QWORD *)(a1 + 8) + v6), (const void *)(*(_QWORD *)(a1 + 8) + v6 + *(_DWORD *)(a1 + 4)), v5);
result = *(_DWORD *)(a1 + 16);
v4 = result - 1;
}
while ( v2 < result - 1 );
}
*(_DWORD *)(a1 + 16) = v4;
return result;
}

original_code:
void
s_array_rm(struct s_array * array, int index)
{
 if(index < 0 || index >= array->nelem) {
  printf("invalid index:%d, nelem:%d""\n", index, array->nelem);
  return;
 }
 int i;
 for(i = index; i < array->nelem - 1; ++i) {
  char * dst = (((char *)(array->p)) + (array->elem_size) * (i));
  char * src = (((char *)(array->p)) + (array->elem_size) * (i+1));
  memcpy(dst, src, array->elem_size);
 }
 array->nelem--;
}

canonical_original_code:
void s_array_rm(struct s_array *array, int index)
{
 if(index < 0 || index >= array->nelem) {
  printf("invalid index:%d, nelem:%d""\n", index, array->nelem);
  return;
 }
 int i;
 for(i = index; i < array->nelem - 1; ++i) {
  char *dst = (((char *)(array->p)) + (array->elem_size) * (i));
  char *src = (((char *)(array->p)) + (array->elem_size) * (i+1));
  memcpy(dst, src, array->elem_size);
 }
 array->nelem--;
}

variable_types:
dst
char *

variable_types:
src
char *


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

result = (unsigned int)(*a1 - 1);
*a1 = result;
if ( !(_DWORD)result )
return _s_free(a1);
if ( (int)result <= 0 )
_assert_fail("array->ref_count > 0", "s_array.c", 0x7Fu, "s_array_drop");
return result;
}

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

result = (unsigned int)(*a1 - 1);
*a1 = result;
if ( !(_DWORD)result )
return _s_free(a1);
if ( (int)result <= 0 )
_assert_fail("array->ref_count > 0", "s_array.c", 0x7Fu, "s_array_drop");
return result;
}

original_code:
void s_array_drop(struct s_array * array)
{
 array->ref_count--;
 if(array->ref_count == 0) {
  __s_free(array);
  return;
 }
 ((void) sizeof ((array->ref_count > 0) ? 1 : 0), __extension__ ({ if (array->ref_count > 0) ; else __assert_fail ("array->ref_count > 0", "s_array.c", 127, __extension__ __PRETTY_FUNCTION__); }));
 if(array->ref_count < 0) {
  printf("double free s_array!""\n");
  return;
 }
}

canonical_original_code:
void s_array_drop(struct s_array *array)
{
 array->ref_count--;
 if(array->ref_count == 0) {
  __s_free(array);
  return;
 }
 ((void) sizeof ((array->ref_count > 0) ? 1 : 0), __extension__ ({ if (array->ref_count > 0) ; else __assert_fail ("array->ref_count > 0", "s_array.c", 127, __extension__ __PRETTY_FUNCTION__); }));
 if(array->ref_count < 0) {
  printf("double free s_array!""\n");
  return;
 }
}


decompiled_code:
__int64 s_spinlock_queue_create()
{
__int64 v0; // r12
_QWORD *v1; // rax
__int64 v2; // rcx
__int64 result; // rax

v0 = _s_malloc(24672LL);
pthread_spin_init((pthread_spinlock_t *)v0, 0);
s_list_init((_QWORD *)(v0 + 8));
s_list_init((_QWORD *)(v0 + 24600));
do
{
v1[2] = 0LL;
s_list_insert(v2, v1);
}
while ( v1 != (_QWORD *)v2 );
pthread_mutex_init((pthread_mutex_t *)(v0 + 24616), 0LL);
result = v0;
*(_QWORD *)(v0 + 24656) = 0LL;
*(_DWORD *)(v0 + 24664) = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // r12
_QWORD *v1; // rax
__int64 v2; // rcx
__int64 result; // rax

v0 = _s_malloc(24672LL);
pthread_spin_init((pthread_spinlock_t *)v0, 0);
func0((_QWORD *)(v0 + 8));
func0((_QWORD *)(v0 + 24600));
do
{
v1[2] = 0LL;
func1(v2, v1);
}
while ( v1 != (_QWORD *)v2 );
pthread_mutex_init((pthread_mutex_t *)(v0 + 24616), 0LL);
result = v0;
*(_QWORD *)(v0 + 24656) = 0LL;
*(_DWORD *)(v0 + 24664) = 0;
return result;
}

original_code:
struct s_spinlock_queue *
s_spinlock_queue_create()
{
 struct s_spinlock_queue * q = (struct s_spinlock_queue*)__s_malloc(sizeof(struct s_spinlock_queue) * (1));
 pthread_spin_init(&q->sl, 0);
 s_list_init(&q->elem_head);
 s_list_init(&q->elem_free_head);
 int i;
 for(i = 0; i < 1024; ++i) {
  struct s_slockq_elem * elem = &q->elem_pool[i];
  elem->data = ((void *)0);
  s_list_insert(&q->elem_free_head, &elem->link);
 }
 pthread_mutex_init(&q->free_m, ((void *)0));
 q->nmalloc = q->nget = q->nfree = 0;
 return q;
}

canonical_original_code:
struct s_spinlock_queue *s_spinlock_queue_create()
{
 struct s_spinlock_queue *q = (struct s_spinlock_queue*)__s_malloc(sizeof(struct s_spinlock_queue) * (1));
 pthread_spin_init(&q->sl, 0);
 s_list_init(&q->elem_head);
 s_list_init(&q->elem_free_head);
 int i;
 for(i = 0; i < 1024; ++i) {
  struct s_slockq_elem *elem = &q->elem_pool[i];
  elem->data = ((void *)0);
  s_list_insert(&q->elem_free_head, &elem->link);
 }
 pthread_mutex_init(&q->free_m, ((void *)0));
 q->nmalloc = q->nget = q->nfree = 0;
 return q;
}

variable_types: struct s_spinlock_queue { int sl; struct s_list { struct s_list *prev; struct s_list *next; } elem_head; struct s_slockq_elem { struct s_list link; void *data; } elem_pool[1024]; struct s_list elem_free_head; 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; } free_m; int nmalloc; int nget; int nfree; } *

variable_types: i int

variable_types: struct s_slockq_elem { struct s_list { struct s_list *prev; struct s_list *next; } link; void *data; } *

user_defined_types: struct s_spinlock_queue { int sl; struct s_list elem_head; struct s_slockq_elem elem_pool[1024]; struct s_list elem_free_head; union pthread_mutex_t free_m; int nmalloc; int nget; int nfree; }

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:
// attributes: thunk
__int64 s_spinlock_queue_destroy()
{
return _s_free();
}

canonical_decompiled_code:
__int64 func6()
{
return _s_free();
}

original_code:
void
s_spinlock_queue_destroy( struct s_spinlock_queue * q )
{
 __s_free(q);
}

canonical_original_code:
void s_spinlock_queue_destroy(struct s_spinlock_queue *q)
{
 __s_free(q);
}

user_defined_types: struct s_slockq_elem { struct s_list link; void *data; }

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


decompiled_code:
int __fastcall s_spinlock_queue_push(pthread_spinlock_t *lock, __int64 a2)
{
char *v2; // rax

pthread_spin_lock(lock);
v2 = iget_free_elem_constprop_0();
*((_QWORD *)v2 + 2) = a2;
s_list_insert_tail((__int64 *)lock + 1, v2);
return pthread_spin_unlock(lock);
}

canonical_decompiled_code:
int __fastcall func7(pthread_spinlock_t *lock, __int64 a2)
{
char *v2; // rax

pthread_spin_lock(lock);
v2 = func4();
*((_QWORD *)v2 + 2) = a2;
func2((__int64 *)lock + 1, v2);
return pthread_spin_unlock(lock);
}

original_code:
void s_spinlock_queue_push(struct s_spinlock_queue * q, void * d)
{
 pthread_spin_lock(&q->sl);
 struct s_slockq_elem * elem = iget_free_elem(q);
 elem->data = d;
 s_list_insert_tail(&q->elem_head, &elem->link);
 pthread_spin_unlock(&q->sl);
}

canonical_original_code:
void s_spinlock_queue_push(struct s_spinlock_queue *q, void *d)
{
 pthread_spin_lock(&q->sl);
 struct s_slockq_elem *elem = iget_free_elem(q);
 elem->data = d;
 s_list_insert_tail(&q->elem_head, &elem->link);
 pthread_spin_unlock(&q->sl);
}

variable_types:
d
void *


decompiled_code:
__int64 __fastcall s_spinlock_queue_pop(pthread_spinlock_t *lock)
{
__int64 v1; // r12
__int64 v2; // rcx

v1 = 0LL;
pthread_spin_lock(lock);
if ( *((pthread_spinlock_t **)lock + 2) != lock + 2 )
{
s_list_del(*((_QWORD **)lock + 2));
v1 = *(_QWORD *)(v2 + 16);
}
pthread_spin_unlock(lock);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(pthread_spinlock_t *lock)
{
__int64 v1; // r12
__int64 v2; // rcx

v1 = 0LL;
pthread_spin_lock(lock);
if ( *((pthread_spinlock_t **)lock + 2) != lock + 2 )
{
func3(*((_QWORD **)lock + 2));
v1 = *(_QWORD *)(v2 + 16);
}
pthread_spin_unlock(lock);
return v1;
}

original_code:
void * s_spinlock_queue_pop(struct s_spinlock_queue * q)
{
 pthread_spin_lock(&q->sl);
 void * data = ((void *)0);
 if(!((&q->elem_head)->next == (&q->elem_head))) {
  struct s_slockq_elem * elem = (struct s_slockq_elem*)((size_t)(((&q->elem_head)->next)) - (size_t)(&((struct s_slockq_elem*)0)->link));
  s_list_del(&elem->link);
  data = elem->data;
  ifree_elem(q, elem);
 }
 pthread_spin_unlock(&q->sl);
 return data;
}

canonical_original_code:
void *s_spinlock_queue_pop(struct s_spinlock_queue *q)
{
 pthread_spin_lock(&q->sl);
 void *data = ((void *)0);
 if(!((&q->elem_head)->next == (&q->elem_head))) {
  struct s_slockq_elem *elem = (struct s_slockq_elem*)((size_t)(((&q->elem_head)->next)) - (size_t)(&((struct s_slockq_elem*)0)->link));
  s_list_del(&elem->link);
  data = elem->data;
  ifree_elem(q, elem);
 }
 pthread_spin_unlock(&q->sl);
 return data;
}

variable_types:
data
void *


decompiled_code:
int __fastcall s_spinlock_queue_dump_stat(unsigned int *a1)
{
return printf("[lockq] nmalloc:%d, nget:%d, nfree:%d\n", a1[6164], a1[6165], a1[6166]);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1)
{
return printf("[lockq] nmalloc:%d, nget:%d, nfree:%d\n", a1[6164], a1[6165], a1[6166]);
}

original_code:
void s_spinlock_queue_dump_stat(struct s_spinlock_queue * q)
{
 printf("[lockq] nmalloc:%d, nget:%d, nfree:%d""\n", q->nmalloc, q->nget, q->nfree);
}

canonical_original_code:
void s_spinlock_queue_dump_stat(struct s_spinlock_queue *q)
{
 printf("[lockq] nmalloc:%d, nget:%d, nfree:%d""\n", q->nmalloc, q->nget, q->nfree);
}


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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_s_free(*(_QWORD *)(a1 + 16));
return _s_free(a1);
}

original_code:
void s_queue_destroy(struct s_queue * q)
{
 __s_free(q->p);
 __s_free(q);
}

canonical_original_code:
void s_queue_destroy(struct s_queue *q)
{
 __s_free(q->p);
 __s_free(q);
}

variable_types: struct s_queue { int elem_size; int total; int first; int last; char *p; } *


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

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

original_code:
int s_queue_empty(struct s_queue * q)
{
 if(q->last == q->first) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int s_queue_empty(struct s_queue *q)
{
 if(q->last == q->first) {
  return 1;
 }
 return 0;
}

user_defined_types: struct s_queue { int elem_size; int total; int first; int last; char *p; }


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

if ( s_queue_empty(a1) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * *(_DWORD *)a1;
return result;
}

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

if ( func3(a1) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * *(_DWORD *)a1;
return result;
}

original_code:
void * s_queue_peek(struct s_queue * q)
{
 if(s_queue_empty(q)) {
  return ((void *)0);
 }
 return ((char*)(q->p) + (q->elem_size) * (q->first));
}

canonical_original_code:
void *s_queue_peek(struct s_queue *q)
{
 if(s_queue_empty(q)) {
  return ((void *)0);
 }
 return ((char *)(q->p) + (q->elem_size) * (q->first));
}


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

if ( s_queue_empty(a1) )
return 0LL;
result = s_queue_peek(a1);
*(_DWORD *)(a1 + 8) = (*(_DWORD *)(a1 + 8) + 1) % *(_DWORD *)(a1 + 4);
return result;
}

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

if ( func3(a1) )
return 0LL;
result = func4(a1);
*(_DWORD *)(a1 + 8) = (*(_DWORD *)(a1 + 8) + 1) % *(_DWORD *)(a1 + 4);
return result;
}

original_code:
void * s_queue_pop(struct s_queue * q)
{
 if(s_queue_empty(q)) {
  return ((void *)0);
 }
 void * p = s_queue_peek(q);
 q->first = (q->first + 1) % q->total;
 return p;
}

canonical_original_code:
void *s_queue_pop(struct s_queue *q)
{
 if(s_queue_empty(q)) {
  return ((void *)0);
 }
 void *p = s_queue_peek(q);
 q->first = (q->first + 1) % q->total;
 return p;
}

variable_types:
p
void *


decompiled_code:
void __fastcall s_queue_clear(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void s_queue_clear(struct s_queue * q)
{
 q->first = q->last = 0;
}

canonical_original_code:
void s_queue_clear(struct s_queue *q)
{
 q->first = q->last = 0;
}


decompiled_code:
// attributes: thunk
__int64 s_lock_queue_destroy()
{
return _s_free();
}

original_code:
void
s_lock_queue_destroy( struct s_lock_queue * q )
{
 __s_free(q);
}

canonical_original_code:
void s_lock_queue_destroy(struct s_lock_queue *q)
{
 __s_free(q);
}

variable_types: struct s_lock_queue { 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; } m; int sl; int use_mutex; struct s_list { struct s_list *prev; struct s_list *next; } elem_head; struct s_lockq_elem { struct s_list link; void *data; } elem_pool[1024]; struct s_list elem_free_head; union pthread_mutex_t free_m; int nmalloc; int nget; int nfree; } *

user_defined_types: struct s_lock_queue { union pthread_mutex_t m; int sl; int use_mutex; struct s_list elem_head; struct s_lockq_elem elem_pool[1024]; struct s_list elem_free_head; union pthread_mutex_t free_m; int nmalloc; int nget; int nfree; }


decompiled_code:
int __fastcall s_lock_queue_push(pthread_mutex_t *mutex, __int64 a2)
{
char *v2; // rax
int result; // eax

if ( mutex[1].__count )
pthread_mutex_lock(mutex);
else
pthread_spin_lock(&mutex[1].__lock);
v2 = iget_free_elem_constprop_0();
*((_QWORD *)v2 + 2) = a2;
s_list_insert_tail(&mutex[1].__align + 1, v2);
if ( mutex[1].__count )
result = pthread_mutex_unlock(mutex);
else
result = pthread_spin_unlock(&mutex[1].__lock);
return result;
}

canonical_decompiled_code:
int __fastcall func7(pthread_mutex_t *mutex, __int64 a2)
{
char *v2; // rax
int result; // eax

if ( mutex[1].__count )
pthread_mutex_lock(mutex);
else
pthread_spin_lock(&mutex[1].__lock);
v2 = func4();
*((_QWORD *)v2 + 2) = a2;
func2(&mutex[1].__align + 1, v2);
if ( mutex[1].__count )
result = pthread_mutex_unlock(mutex);
else
result = pthread_spin_unlock(&mutex[1].__lock);
return result;
}

original_code:
void s_lock_queue_push(struct s_lock_queue * q, void * d)
{
 if(q->use_mutex) {
  pthread_mutex_lock(&q->m);
 } else {
  pthread_spin_lock(&q->sl);
 }
 struct s_lockq_elem * elem = iget_free_elem(q);
 elem->data = d;
 s_list_insert_tail(&q->elem_head, &elem->link);
 if(q->use_mutex) {
  pthread_mutex_unlock(&q->m);
 } else {
  pthread_spin_unlock(&q->sl);
 }
}

canonical_original_code:
void s_lock_queue_push(struct s_lock_queue *q, void *d)
{
 if(q->use_mutex) {
  pthread_mutex_lock(&q->m);
 } else {
  pthread_spin_lock(&q->sl);
 }
 struct s_lockq_elem *elem = iget_free_elem(q);
 elem->data = d;
 s_list_insert_tail(&q->elem_head, &elem->link);
 if(q->use_mutex) {
  pthread_mutex_unlock(&q->m);
 } else {
  pthread_spin_unlock(&q->sl);
 }
}

variable_types: struct s_lockq_elem { struct s_list { struct s_list *prev; struct s_list *next; } link; void *data; } *

user_defined_types: struct s_lockq_elem { struct s_list link; void *data; }


decompiled_code:
__int64 __fastcall s_lock_queue_pop(pthread_mutex_t *mutex)
{
__int64 v1; // r12
__int64 v2; // rcx

if ( mutex[1].__count )
pthread_mutex_lock(mutex);
else
pthread_spin_lock(&mutex[1].__lock);
v1 = 0LL;
if ( *((pthread_mutex_t **)&mutex[1].__align + 2) != (pthread_mutex_t *)(&mutex[1].__align + 1) )
{
s_list_del(*((_QWORD **)&mutex[1].__align + 2));
v1 = *(_QWORD *)(v2 + 16);
}
if ( mutex[1].__count )
pthread_mutex_unlock(mutex);
else
pthread_spin_unlock(&mutex[1].__lock);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(pthread_mutex_t *mutex)
{
__int64 v1; // r12
__int64 v2; // rcx

if ( mutex[1].__count )
pthread_mutex_lock(mutex);
else
pthread_spin_lock(&mutex[1].__lock);
v1 = 0LL;
if ( *((pthread_mutex_t **)&mutex[1].__align + 2) != (pthread_mutex_t *)(&mutex[1].__align + 1) )
{
func3(*((_QWORD **)&mutex[1].__align + 2));
v1 = *(_QWORD *)(v2 + 16);
}
if ( mutex[1].__count )
pthread_mutex_unlock(mutex);
else
pthread_spin_unlock(&mutex[1].__lock);
return v1;
}

original_code:
void * s_lock_queue_pop(struct s_lock_queue * q)
{
 if(q->use_mutex) {
  pthread_mutex_lock(&q->m);
 } else {
  pthread_spin_lock(&q->sl);
 }
 void * data = ((void *)0);
 if(!((&q->elem_head)->next == (&q->elem_head))) {
  struct s_lockq_elem * elem = (struct s_lockq_elem*)((size_t)(((&q->elem_head)->next)) - (size_t)(&((struct s_lockq_elem*)0)->link));
  s_list_del(&elem->link);
  data = elem->data;
  ifree_elem(q, elem);
 }
 if(q->use_mutex) {
  pthread_mutex_unlock(&q->m);
 } else {
  pthread_spin_unlock(&q->sl);
 }
 return data;
}

canonical_original_code:
void *s_lock_queue_pop(struct s_lock_queue *q)
{
 if(q->use_mutex) {
  pthread_mutex_lock(&q->m);
 } else {
  pthread_spin_lock(&q->sl);
 }
 void *data = ((void *)0);
 if(!((&q->elem_head)->next == (&q->elem_head))) {
  struct s_lockq_elem *elem = (struct s_lockq_elem*)((size_t)(((&q->elem_head)->next)) - (size_t)(&((struct s_lockq_elem*)0)->link));
  s_list_del(&elem->link);
  data = elem->data;
  ifree_elem(q, elem);
 }
 if(q->use_mutex) {
  pthread_mutex_unlock(&q->m);
 } else {
  pthread_spin_unlock(&q->sl);
 }
 return data;
}


decompiled_code:
int __fastcall s_lock_queue_dump_stat(unsigned int *a1)
{
return printf("[lockq] nmalloc:%d, nget:%d, nfree:%d\n", a1[6174], a1[6175], a1[6176]);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1)
{
return printf("[lockq] nmalloc:%d, nget:%d, nfree:%d\n", a1[6174], a1[6175], a1[6176]);
}

original_code:
void s_lock_queue_dump_stat(struct s_lock_queue * q)
{
 printf("[lockq] nmalloc:%d, nget:%d, nfree:%d""\n", q->nmalloc, q->nget, q->nfree);
}

canonical_original_code:
void s_lock_queue_dump_stat(struct s_lock_queue *q)
{
 printf("[lockq] nmalloc:%d, nget:%d, nfree:%d""\n", q->nmalloc, q->nget, q->nfree);
}


ihash

decompiled_code:
__int64 __fastcall ihash(__int64 a1, unsigned int a2)
{
unsigned int v2; // er8
unsigned int v3; // esi
__int64 v4; // rdx
unsigned int v5; // ecx
int v6; // eax

v2 = a2;
v3 = (a2 >> 5) + 1;
v4 = (int)v2;
if ( v2 >= v3 )
{
v5 = v2;
do
{
v5 -= v3;
v6 = *(unsigned __int8 *)(a1 + v4 - 1) + (v2 >> 2) + 32 * v2;
v4 = (int)v5;
v2 ^= v6;
}
while ( v5 >= v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // er8
unsigned int v3; // esi
__int64 v4; // rdx
unsigned int v5; // ecx
int v6; // eax

v2 = a2;
v3 = (a2 >> 5) + 1;
v4 = (int)v2;
if ( v2 >= v3 )
{
v5 = v2;
do
{
v5 -= v3;
v6 = *(unsigned __int8 *)(a1 + v4 - 1) + (v2 >> 2) + 32 * v2;
v4 = (int)v5;
v2 ^= v6;
}
while ( v5 >= v3 );
}
return v2;
}

original_code:
unsigned int static inline ihash(const char * p, unsigned int len)
{
 unsigned int h = len;
 unsigned int step = (h >> 5) + 1;
 int i = h;
 for(i = h; i >= step; i -= step) {
  h = h ^ ((h<<5) + (h>>2) + (unsigned char)(p[i-1]));
 }
 return h;
}

canonical_original_code:
static inline unsigned int ihash(char *p, unsigned int len)
{
 unsigned int h = len;
 unsigned int step = (h >> 5) + 1;
 int i = h;
 for(i = h; i >= step; i -= step) {
  h = h ^ ((h<<5) + (h>>2) + (unsigned char)(p[i-1]));
 }
 return h;
}

variable_types:
p
char *

variable_types:
len
unsigned int

variable_types:
h
unsigned int

variable_types:
step
unsigned int


decompiled_code:
_BOOL8 __fastcall s_string_equal(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

if ( a1 == a2 )
return 1LL;
result = 0LL;
if ( *(_QWORD *)a1 == *(_QWORD *)a2 )
result = strncmp((const char *)(a1 + 12), (const char *)(a2 + 12), *(unsigned int *)(a1 + 4)) == 0;
return result;
}

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

if ( a1 == a2 )
return 1LL;
result = 0LL;
if ( *(_QWORD *)a1 == *(_QWORD *)a2 )
result = strncmp((const char *)(a1 + 12), (const char *)(a2 + 12), *(unsigned int *)(a1 + 4)) == 0;
return result;
}

original_code:
int s_string_equal(struct s_string * a, struct s_string * b)
{
 if(a == b) {
  return 1;
 }
 if(a->len == b->len && a->hash == b->hash &&
   strncmp((char *)(((struct s_string *)(a)) + 1), (char *)(((struct s_string *)(b)) + 1), a->len) == 0) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int s_string_equal(struct s_string *a, struct s_string *b)
{
 if(a == b) {
  return 1;
 }
 if(a->len == b->len && a->hash == b->hash &&
   strncmp((char *)(((struct s_string *)(a)) + 1), (char *)(((struct s_string *)(b)) + 1), a->len) == 0) {
  return 1;
 }
 return 0;
}

variable_types: struct s_string { unsigned int hash; unsigned int len; int ref_count; } *

variable_types:
b
struct s_string *


decompiled_code:
__int64 __fastcall s_string_data_p(__int64 a1)
{
return a1 + 12;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1 + 12;
}

original_code:
const char * s_string_data_p(struct s_string * str)
{
 return (char *)(((struct s_string *)(str)) + 1);
}

canonical_original_code:
char *s_string_data_p(struct s_string *str)
{
 return (char *)(((struct s_string *)(str)) + 1);
}

user_defined_types: struct s_string { unsigned int hash; unsigned int len; int ref_count; }


decompiled_code:
__int64 __fastcall s_string_len(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int s_string_len(struct s_string * str)
{
 return str->len;
}

canonical_original_code:
int s_string_len(struct s_string *str)
{
 return str->len;
}


decompiled_code:
__int64 __fastcall s_string_get_hash(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned int s_string_get_hash(struct s_string * str)
{
 return str->hash;
}

canonical_original_code:
unsigned int s_string_get_hash(struct s_string *str)
{
 return str->hash;
}


decompiled_code:
__int64 __fastcall s_string_grab(__int64 a1)
{
++*(_DWORD *)(a1 + 8);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
++*(_DWORD *)(a1 + 8);
return a1;
}

original_code:
struct s_string * s_string_grab(struct s_string * str)
{
 str->ref_count++;
 return str;
}

canonical_original_code:
struct s_string *s_string_grab(struct s_string *str)
{
 str->ref_count++;
 return str;
}

variable_types:
str
struct s_string *

return_type: struct s_string { unsigned int hash; unsigned int len; int ref_count; } *


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

result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
*(_DWORD *)(a1 + 8) = result;
if ( !(_DWORD)result )
return _s_free();
if ( (int)result < 0 )
{
puts("double free string!");
result = *(unsigned int *)(a1 + 8);
}
if ( (int)result <= 0 )
_assert_fail("str->ref_count > 0", "s_string.c", 0x9Fu, "s_string_drop");
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
*(_DWORD *)(a1 + 8) = result;
if ( !(_DWORD)result )
return _s_free();
if ( (int)result < 0 )
{
puts("double free string!");
result = *(unsigned int *)(a1 + 8);
}
if ( (int)result <= 0 )
_assert_fail("str->ref_count > 0", "s_string.c", 0x9Fu, "s_string_drop");
return result;
}

original_code:
void s_string_drop(struct s_string * str)
{
 str->ref_count--;
 if(str->ref_count == 0) {
  __s_free(str);
  return;
 }
 if(str->ref_count < 0) {
  printf("double free string!""\n");
 }
 ((void) sizeof ((str->ref_count > 0) ? 1 : 0), __extension__ ({ if (str->ref_count > 0) ; else __assert_fail ("str->ref_count > 0", "s_string.c", 159, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void s_string_drop(struct s_string *str)
{
 str->ref_count--;
 if(str->ref_count == 0) {
  __s_free(str);
  return;
 }
 if(str->ref_count < 0) {
  printf("double free string!""\n");
 }
 ((void) sizeof ((str->ref_count > 0) ? 1 : 0), __extension__ ({ if (str->ref_count > 0) ; else __assert_fail ("str->ref_count > 0", "s_string.c", 159, __extension__ __PRETTY_FUNCTION__); }));
}


original_code:
struct s_1r1w_queue * s_1r1w_queue_create( void )
{
 struct s_1r1w_queue * q = (struct s_1r1w_queue*)__s_malloc(sizeof(struct s_1r1w_queue) * (1));
 q->head = q->tail = q->last = ((void *)0);
 q->elem_free = ((void *)0);
 int i;
 for(i = 0; i < 1024; ++i) {
  struct s_1r1w_elem * e = &q->elem_pool[i];
  e->prev = q->elem_free;
  q->elem_free = e;
 }
 pthread_mutex_init(&q->free_m, ((void *)0));
 q->nmalloc = 0;
 q->nget = 0;
 q->nfree = 0;
 return q;
}

canonical_original_code:
struct s_1r1w_queue *s_1r1w_queue_create()
{
 struct s_1r1w_queue *q = (struct s_1r1w_queue*)__s_malloc(sizeof(struct s_1r1w_queue) * (1));
 q->head = q->tail = q->last = ((void *)0);
 q->elem_free = ((void *)0);
 int i;
 for(i = 0; i < 1024; ++i) {
  struct s_1r1w_elem *e = &q->elem_pool[i];
  e->prev = q->elem_free;
  q->elem_free = e;
 }
 pthread_mutex_init(&q->free_m, ((void *)0));
 q->nmalloc = 0;
 q->nget = 0;
 q->nfree = 0;
 return q;
}

variable_types: struct s_1r1w_queue { struct s_1r1w_elem { struct s_1r1w_elem *prev; void *data; } *head; struct s_1r1w_elem *tail; struct s_1r1w_elem *last; struct s_1r1w_elem elem_pool[1024]; struct s_1r1w_elem *elem_free; 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; } free_m; int nmalloc; int nfree; int nget; } *

user_defined_types: struct s_1r1w_queue { struct s_1r1w_elem *head; struct s_1r1w_elem *tail; struct s_1r1w_elem *last; struct s_1r1w_elem elem_pool[1024]; struct s_1r1w_elem *elem_free; union pthread_mutex_t free_m; int nmalloc; int nfree; int nget; }


decompiled_code:
// attributes: thunk
__int64 s_1r1w_queue_destroy()
{
return _s_free();
}

canonical_decompiled_code:
__int64 func2()
{
return _s_free();
}

original_code:
void s_1r1w_queue_destroy( struct s_1r1w_queue * q )
{
 __s_free(q);
}

canonical_original_code:
void s_1r1w_queue_destroy(struct s_1r1w_queue *q)
{
 __s_free(q);
}

user_defined_types: struct s_1r1w_elem { struct s_1r1w_elem *prev; void *data; }


decompiled_code:
char *__fastcall s_1r1w_queue_push(__int64 a1, __int64 a2)
{
char *result; // rax
char **v3; // rdx

do
result = iget_free_elem_constprop_0();
while ( !result );
v3 = *(char ***)a1;
*((_QWORD *)result + 1) = a2;
if ( v3 )
{
*v3 = result;
*(_QWORD *)a1 = result;
}
else
{
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2)
{
char *result; // rax
char **v3; // rdx

do
result = func0();
while ( !result );
v3 = *(char ***)a1;
*((_QWORD *)result + 1) = a2;
if ( v3 )
{
*v3 = result;
*(_QWORD *)a1 = result;
}
else
{
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
void s_1r1w_queue_push(struct s_1r1w_queue * q, void * d)
{
 struct s_1r1w_elem * elem = iget_free_elem(q);
 while(!elem) {
  elem = iget_free_elem(q);
 }
 elem->data = d;
 if(__builtin_expect(!!(!q->head), 0)) {
  q->head = elem;
  q->tail = elem;
  return;
 }
 q->head->prev = elem;
 q->head = elem;
 return;
}

canonical_original_code:
void s_1r1w_queue_push(struct s_1r1w_queue *q, void *d)
{
 struct s_1r1w_elem *elem = iget_free_elem(q);
 while(!elem) {
  elem = iget_free_elem(q);
 }
 elem->data = d;
 if(__builtin_expect(!!(!q->head), 0)) {
  q->head = elem;
  q->tail = elem;
  return;
 }
 q->head->prev = elem;
 q->head = elem;
 return;
}

variable_types: struct s_1r1w_elem { struct s_1r1w_elem *prev; void *data; } *


decompiled_code:
int __fastcall s_1r1w_queue_dump_stat(unsigned int *a1)
{
return printf("[1r1wq] nmallc:%d, nget:%d, nfree:%d\n", a1[4114], a1[4116], a1[4115]);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
return printf("[1r1wq] nmallc:%d, nget:%d, nfree:%d\n", a1[4114], a1[4116], a1[4115]);
}

original_code:
void s_1r1w_queue_dump_stat(struct s_1r1w_queue * q)
{
 printf("[1r1wq] nmallc:%d, nget:%d, nfree:%d""\n", q->nmalloc, q->nget, q->nfree);
}

canonical_original_code:
void s_1r1w_queue_dump_stat(struct s_1r1w_queue *q)
{
 printf("[1r1wq] nmallc:%d, nget:%d, nfree:%d""\n", q->nmalloc, q->nget, q->nfree);
}


decompiled_code:
char *__fastcall s_int_to_string(unsigned int a1)
{
char *result; // rax
int v2; // er10
__int64 v3; // rdx
int v4; // er8
int v5; // er11
unsigned int v6; // eax
char v7; // cl
int v8; // esi
int v9; // ecx
bool v10; // cl

byte_FF = 0;
result = (char *)&unk_100;
if ( a1 )
{
v2 = 0;
if ( (a1 & 0x80000000) != 0 )
{
a1 = -a1;
v2 = 1;
}
v3 = 61LL;
do
{
v4 = v3 + 1;
v5 = v3;
v6 = a1 / 0xA;
v7 = a1 % 0xA;
v8 = a1;
a1 /= 0xAu;
byte_C1[v3] = v7 + 48;
v9 = v3--;
v10 = v9 >= 0;
}
while ( v8 > 9 && v10 );
if ( v6 )
{
puts("num is to big!!");
result = 0LL;
}
else
{
if ( v2 )
{
if ( v10 )
{
v4 = v5;
buf_0[v5] = 45;
}
}
result = &buf_0[v4];
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
char *result; // rax
int v2; // er10
__int64 v3; // rdx
int v4; // er8
int v5; // er11
unsigned int v6; // eax
char v7; // cl
int v8; // esi
int v9; // ecx
bool v10; // cl

byte_FF = 0;
result = (char *)&unk_100;
if ( a1 )
{
v2 = 0;
if ( (a1 & 0x80000000) != 0 )
{
a1 = -a1;
v2 = 1;
}
v3 = 61LL;
do
{
v4 = v3 + 1;
v5 = v3;
v6 = a1 / 0xA;
v7 = a1 % 0xA;
v8 = a1;
a1 /= 0xAu;
byte_C1[v3] = v7 + 48;
v9 = v3--;
v10 = v9 >= 0;
}
while ( v8 > 9 && v10 );
if ( v6 )
{
puts("num is to big!!");
result = 0LL;
}
else
{
if ( v2 )
{
if ( v10 )
{
v4 = v5;
buf_0[v5] = 45;
}
}
result = &buf_0[v4];
}
}
return result;
}

original_code:
const char * s_int_to_string(int i)
{
 static char buf[64];
 buf[64 - 1] = 0;
 int pos = 64 - 2;
 if(i == 0) {
  return "0";
 }
 int sign = 0;
 if(i < 0) {
  sign = 1;
  i *= -1;
 }
 while(i > 0 && pos >= 0) {
  int c = i % 10;
  i /= 10;
  buf[pos--] = c + '0';
 }
 if(i > 0) {
  printf("num is to big!!""\n");
  return ((void *)0);
 }
 if(sign && pos >= 0) {
  buf[pos--] = '-';
 }
 return &buf[pos+1];
}

canonical_original_code:
char *s_int_to_string(int i)
{
 static char buf[64];
 buf[64 - 1] = 0;
 int pos = 64 - 2;
 if(i == 0) {
  return "0";
 }
 int sign = 0;
 if(i < 0) {
  sign = 1;
  i *= -1;
 }
 while(i > 0 && pos >= 0) {
  int c = i % 10;
  i /= 10;
  buf[pos--] = c + '0';
 }
 if(i > 0) {
  printf("num is to big!!""\n");
  return ((void *)0);
 }
 if(sign && pos >= 0) {
  buf[pos--] = '-';
 }
 return &buf[pos+1];
}

variable_types: i int

variable_types:
buf
char [64]

variable_types: pos int

variable_types: sign int

variable_types: c int


decompiled_code:
int __fastcall s_util_get_serv_id(const char *a1, char a2)
{
char *v2; // rax

v2 = strrchr(a1, a2);
if ( v2 )
return atoi(v2 + 1);
puts("miss id!");
return -1;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, char a2)
{
char *v2; // rax

v2 = strrchr(a1, a2);
if ( v2 )
return atoi(v2 + 1);
puts("miss id!");
return -1;
}

original_code:
int s_util_get_serv_id(const char * p, char sep)
{
 char * p_ = strrchr(p, sep);
 if(!p_) {
  printf("miss id!""\n");
  return -1;
 }
 int id = atoi(p_ + 1);
 return id;
}

canonical_original_code:
int s_util_get_serv_id(char *p, char sep)
{
 char *p_ = strrchr(p, sep);
 if(!p_) {
  printf("miss id!""\n");
  return -1;
 }
 int id = atoi(p_ + 1);
 return id;
}

variable_types: sep char

variable_types: id int


decompiled_code:
__int64 __fastcall s_core_fsize_to_block_num(_DWORD *a1)
{
return (*a1 >> 22) - ((unsigned int)((*a1 & 0x3FFFFF) == 0) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
return (*a1 >> 22) - ((unsigned int)((*a1 & 0x3FFFFF) == 0) - 1);
}

original_code:
int s_core_fsize_to_block_num(struct s_file_size * size)
{
 unsigned long bits = sizeof(unsigned int) - 22;
 unsigned int num = (((size->low) >> (sizeof(unsigned int) - (bits))) & ((1 << (bits)) - 1));
 if(sizeof(unsigned int) < 42) {
  unsigned int high_bits = 42 - sizeof(unsigned int);
  num |= size->high << bits & (((1 << (high_bits)) - 1) << bits);
 }
 if(size->low & ((1 << (22)) - 1)) {
  num++;
 }
 return num;
}

canonical_original_code:
int s_core_fsize_to_block_num(struct s_file_size *size)
{
 unsigned long bits = sizeof(unsigned int) - 22;
 unsigned int num = (((size->low) >> (sizeof(unsigned int) - (bits))) & ((1 << (bits)) - 1));
 if(sizeof(unsigned int) < 42) {
  unsigned int high_bits = 42 - sizeof(unsigned int);
  num |= size->high << bits & (((1 << (high_bits)) - 1) << bits);
 }
 if(size->low & ((1 << (22)) - 1)) {
  num++;
 }
 return num;
}

variable_types: struct s_file_size { unsigned int low; unsigned int high; } *

variable_types:
bits
unsigned long

variable_types:
num
unsigned int


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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
void*
s_thread_get_udata(struct s_thread * t)
{
 return t->udata;
}

canonical_original_code:
void *s_thread_get_udata(struct s_thread *t)
{
 return t->udata;
}

variable_types: struct s_thread { unsigned long ptid; void (**start_routine)(struct s_thread *t); void *udata; } *


decompiled_code:
void create_back()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void create_back(void * udata)
{
}

canonical_original_code:
static void create_back(void *udata)
{
}

variable_types:
udata
void *


decompiled_code:
__int64 s_mem_used()
{
return (unsigned int)g_mem;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)g_mem;
}

original_code:
unsigned int s_mem_used( void )
{
 return g_mem;
}

canonical_original_code:
unsigned int s_mem_used()
{
 return g_mem;
}


repo: zhoupj/Deduper

decompiled_code:
__int64 __fastcall sdbm_hash(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
__int64 result; // rax
int v3; // edx

v1 = a1 + 19;
LODWORD(result) = 0;
do
{
v3 = *a1++;
result = (unsigned int)(v3 + 65599 * result);
}
while ( a1 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
__int64 result; // rax
int v3; // edx

v1 = a1 + 19;
LODWORD(result) = 0;
do
{
v3 = *a1++;
result = (unsigned int)(v3 + 65599 * result);
}
while ( a1 != v1 );
return result;
}

original_code:
unsigned int sdbm_hash( unsigned char *key)
{
 unsigned int h = 0;
 int i=0;
 while(i<20 -1) {
  h = *(key++) + (h<<6) + (h<<16) - h;
  i++;
 }
 return h;
}

canonical_original_code:
unsigned int sdbm_hash(unsigned char *key)
{
 unsigned int h = 0;
 int i = 0;
 while(i<20 -1) {
  h = *(key++) + (h<<6) + (h<<16) - h;
  i++;
 }
 return h;
}

variable_types:
key
unsigned char *

variable_types:
h
unsigned int


decompiled_code:
void rb_init()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
rb_node * rb_init(){
}

canonical_original_code:
struct rb_node_t *rb_init(){
}

return_type: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; } *


original_code:
void rb_free(rb_node** root){
     if(*root==((void *)0))
  return;
    if((*root)->lchild != ((void *)0)){
      rb_free(&((*root)->lchild));
     }
     if((*root)->rchild != ((void *)0)){
     rb_free(&((*root)->rchild));
     }
    free((*root));
   (*root)=((void *)0);
}

canonical_original_code:
void rb_free(struct rb_node_t **root){
     if(*root==((void *)0))
  return;
    if((*root)->lchild != ((void *)0)){
      rb_free(&((*root)->lchild));
     }
     if((*root)->rchild != ((void *)0)){
     rb_free(&((*root)->rchild));
     }
    free((*root));
   (*root)=((void *)0);
}

variable_types: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; } **


original_code:
rb_node* clock_wise(rb_node** root,rb_node* node){
    if(node == ((void *)0) || node->lchild == ((void *)0))
    return ((void *)0);
    rb_node *rb_1=node, *rb_2=node->lchild, *rb_3=node->lchild->rchild;
    if(rb_1->parent != ((void *)0)){
    if(rb_1->parent->lchild == rb_1)
        rb_1->parent->lchild = rb_2;
    else
        rb_1->parent->rchild = rb_2;
    }else if(rb_1 == *root){
 *root = rb_2;
    }
    rb_2->parent = rb_1->parent;
    rb_1->parent = rb_2;
    rb_2->rchild = rb_1;
    rb_1->lchild = rb_3;
    if(rb_3 != ((void *)0))rb_3->parent = rb_1;
    return rb_2;
}

canonical_original_code:
struct rb_node_t *clock_wise(struct rb_node_t **root, struct rb_node_t *node){
    if(node == ((void *)0) || node->lchild == ((void *)0))
    return ((void *)0);
    struct rb_node_t *rb_1 = node; struct rb_node_t *rb_2 = node->lchild; struct rb_node_t *rb_3 = node->lchild->rchild;
    if(rb_1->parent != ((void *)0)){
    if(rb_1->parent->lchild == rb_1)
        rb_1->parent->lchild = rb_2;
    else
        rb_1->parent->rchild = rb_2;
    }else if(rb_1 == *root){
 *root = rb_2;
    }
    rb_2->parent = rb_1->parent;
    rb_1->parent = rb_2;
    rb_2->rchild = rb_1;
    rb_1->lchild = rb_3;
    if(rb_3 != ((void *)0))rb_3->parent = rb_1;
    return rb_2;
}

variable_types:
root
struct rb_node_t **

variable_types:
node
struct rb_node_t *

variable_types: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; } *


decompiled_code:
__int64 __fastcall counter_clock_wise(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx

if ( !a2 )
return 0LL;
result = *(_QWORD *)(a2 + 40);
if ( result )
{
v3 = *(_QWORD *)(a2 + 48);
v4 = *(_QWORD *)(result + 32);
if ( v3 )
{
if ( *(_QWORD *)(v3 + 32) == a2 )
*(_QWORD *)(v3 + 32) = result;
else
*(_QWORD *)(v3 + 40) = result;
}
else if ( *a1 == a2 )
{
*a1 = result;
v3 = *(_QWORD *)(a2 + 48);
}
*(_QWORD *)(result + 48) = v3;
*(_QWORD *)(a2 + 48) = result;
*(_QWORD *)(result + 32) = a2;
*(_QWORD *)(a2 + 40) = v4;
if ( v4 )
*(_QWORD *)(v4 + 48) = a2;
}
return result;
}

original_code:
rb_node* counter_clock_wise(rb_node**root,rb_node* node){
    if(node == ((void *)0) || node->rchild == ((void *)0))
    return ((void *)0);
    rb_node *rb_1=node, *rb_2=node->rchild, *rb_3=node->rchild->lchild;
    if(rb_1->parent != ((void *)0)){
    if(rb_1->parent->lchild == rb_1)
        rb_1->parent->lchild = rb_2;
    else
        rb_1->parent->rchild = rb_2;
    }
    else if(rb_1 == *root){
    *root = rb_2;
}
    rb_2->parent = rb_1->parent;
    rb_1->parent = rb_2;
      rb_2->lchild = rb_1;
      rb_1->rchild = rb_3;
      if(rb_3 != ((void *)0))rb_3->parent = rb_1;
      return rb_2;
  }

canonical_original_code:
struct rb_node_t *counter_clock_wise(struct rb_node_t **root, struct rb_node_t *node){
    if(node == ((void *)0) || node->rchild == ((void *)0))
    return ((void *)0);
    struct rb_node_t *rb_1 = node; struct rb_node_t *rb_2 = node->rchild; struct rb_node_t *rb_3 = node->rchild->lchild;
    if(rb_1->parent != ((void *)0)){
    if(rb_1->parent->lchild == rb_1)
        rb_1->parent->lchild = rb_2;
    else
        rb_1->parent->rchild = rb_2;
    }
    else if(rb_1 == *root){
    *root = rb_2;
}
    rb_2->parent = rb_1->parent;
    rb_1->parent = rb_2;
      rb_2->lchild = rb_1;
      rb_1->rchild = rb_3;
      if(rb_3 != ((void *)0))rb_3->parent = rb_1;
      return rb_2;
  }

user_defined_types: struct rb_node_t { unsigned char key[20]; unsigned int hash; int colour; struct rb_node_t *lchild; void *data; }


original_code:
void rb_insert(rb_node **root,unsigned char key[],void *data){
    rb_node *p=*root, *q=((void *)0);
   int left=1;
   unsigned int hash;
   hash=sdbm_hash(key);
   if(*root == ((void *)0)){
    *root = get_node(((void *)0), key,hash,data);
    (*root)->colour = BLACK;
    return;
    }
    while(p != ((void *)0)){
     q = p;
     if(hash < p->hash)
        { p = p->lchild;left=1;}
     else if(hash > p->hash)
         {p = p->rchild;left=0;}
     else{
          if(memcmp(key,p->key,20)<0)
       { p = p->lchild;left=1;}
   else if (memcmp(key,p->key,20)>0)
         {p = p->rchild;left=0;}
   else
    {
    printf("%s:%d same key\n","libs/rbtree.c",142);
    return;
    }
   }
    }
    if(left)
     q->lchild = get_node(q, key,hash,data);
    else
      q->rchild = get_node(q, key,hash,data);
     while(q != ((void *)0) && q->colour == RED){
      p = q->parent;
      if(p->lchild == q){
          if(q->rchild != ((void *)0) && q->rchild->colour == RED)
          counter_clock_wise(root,q);
          q = clock_wise(root,p);
          q->lchild->colour = BLACK;
      }
      else{
          if(q->lchild != ((void *)0) && q->lchild->colour == RED)
          clock_wise(root,q);
          q = counter_clock_wise(root,p);
          q->rchild->colour = BLACK;
      }
      q = q->parent;
     }
     (*root)->colour = BLACK;
 }

canonical_original_code:
void rb_insert(struct rb_node_t **root, unsigned char key[], void *data){
    struct rb_node_t *p = *root; struct rb_node_t *q = ((void *)0);
   int left = 1;
   unsigned int hash;
   hash=sdbm_hash(key);
   if(*root == ((void *)0)){
    *root = get_node(((void *)0), key,hash,data);
    (*root)->colour = BLACK;
    return;
    }
    while(p != ((void *)0)){
     q = p;
     if(hash < p->hash)
        { p = p->lchild;left=1;}
     else if(hash > p->hash)
         {p = p->rchild;left=0;}
     else{
          if(memcmp(key,p->key,20)<0)
       { p = p->lchild;left=1;}
   else if (memcmp(key,p->key,20)>0)
         {p = p->rchild;left=0;}
   else
    {
    printf("%s:%d same key\n","libs/rbtree.c",142);
    return;
    }
   }
    }
    if(left)
     q->lchild = get_node(q, key,hash,data);
    else
      q->rchild = get_node(q, key,hash,data);
     while(q != ((void *)0) && q->colour == RED){
      p = q->parent;
      if(p->lchild == q){
          if(q->rchild != ((void *)0) && q->rchild->colour == RED)
          counter_clock_wise(root,q);
          q = clock_wise(root,p);
          q->lchild->colour = BLACK;
      }
      else{
          if(q->lchild != ((void *)0) && q->lchild->colour == RED)
          clock_wise(root,q);
          q = counter_clock_wise(root,p);
          q->rchild->colour = BLACK;
      }
      q = q->parent;
     }
     (*root)->colour = BLACK;
 }

variable_types:
key
unsigned char []

variable_types:
data
void *

variable_types: left int

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall show_rb_tree(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
if ( *(_QWORD *)(v1 + 32) )
result = show_rb_tree();
v1 = *(_QWORD *)(v1 + 40);
++g_count;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
if ( *(_QWORD *)(v1 + 32) )
result = func7();
v1 = *(_QWORD *)(v1 + 40);
++g_count;
}
while ( v1 );
}
return result;
}

original_code:
void show_rb_tree(rb_node* node){
     if(node == ((void *)0))
      return;
    if(node->lchild != ((void *)0)){
     show_rb_tree(node->lchild);
     }
      g_count++;
     if(node->rchild != ((void *)0)){
     show_rb_tree(node->rchild);
     }
 }

canonical_original_code:
void show_rb_tree(struct rb_node_t *node){
     if(node == ((void *)0))
      return;
    if(node->lchild != ((void *)0)){
     show_rb_tree(node->lchild);
     }
      g_count++;
     if(node->rchild != ((void *)0)){
     show_rb_tree(node->rchild);
     }
 }