quicksort

decompiled_code:
__int64 __fastcall quicksort(__int64 a1, int a2, int a3)
{
int v5; // ebx

if ( a2 < a3 )
{
v5 = partition(a1, a2, a3);
quicksort(a1, (unsigned int)a2, (unsigned int)(v5 - 1));
quicksort(a1, (unsigned int)(v5 + 1), (unsigned int)a3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3)
{
int v5; // ebx

if ( a2 < a3 )
{
v5 = func9(a1, a2, a3);
func10(a1, (unsigned int)a2, (unsigned int)(v5 - 1));
func10(a1, (unsigned int)(v5 + 1), (unsigned int)a3);
}
return 0LL;
}

original_code:
int quicksort(int * A, int begin, int end)
{
    int p;
    if(begin < end) {
        p = partition(A, begin, end);
        quicksort(A, begin, p - 1);
        quicksort(A, p + 1, end);
    }
    return 0;
}

canonical_original_code:
int quicksort(int *A, int begin, int end)
{
    int p;
    if(begin < end) {
        p = partition(A, begin, end);
        quicksort(A, begin, p - 1);
        quicksort(A, p + 1, end);
    }
    return 0;
}

variable_types: begin int

variable_types: end int

variable_types: p int


swap

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(int *a, int *b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: tmp int

return_type: void


partition

decompiled_code:
__int64 __fastcall partition(__int64 a1, int a2, int a3)
{
int v4; // er8
int *v5; // rbp
int v6; // er10
_DWORD *v7; // rcx
unsigned __int64 v8; // r11
unsigned int v9; // er10

v4 = a2 - 1;
v5 = (int *)(a1 + 4LL * a3);
v6 = *v5;
if ( a2 < a3 )
{
v7 = (_DWORD *)(a1 + 4LL * a2);
v8 = a1 + 4 * (a2 + (unsigned __int64)(unsigned int)(a3 - 1 - a2)) + 4;
do
{
while ( *v7 >= v6 )
{
if ( ++v7 == (_DWORD *)v8 )
goto LABEL_6;
}
swap((_DWORD *)(a1 + 4LL * (v4 + 1)), v7);
}
while ( v7 != (_DWORD *)v8 );
}
LABEL_6:
swap((_DWORD *)(a1 + 4LL * v4 + 4), v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // er8
int *v5; // rbp
int v6; // er10
_DWORD *v7; // rcx
unsigned __int64 v8; // r11
unsigned int v9; // er10

v4 = a2 - 1;
v5 = (int *)(a1 + 4LL * a3);
v6 = *v5;
if ( a2 < a3 )
{
v7 = (_DWORD *)(a1 + 4LL * a2);
v8 = a1 + 4 * (a2 + (unsigned __int64)(unsigned int)(a3 - 1 - a2)) + 4;
do
{
while ( *v7 >= v6 )
{
if ( ++v7 == (_DWORD *)v8 )
goto LABEL_6;
}
func8((_DWORD *)(a1 + 4LL * (v4 + 1)), v7);
}
while ( v7 != (_DWORD *)v8 );
}
LABEL_6:
func8((_DWORD *)(a1 + 4LL * v4 + 4), v5);
return v9;
}

original_code:
int partition(int * A, int begin, int end)
{
    int i,j;
    int x;
    i = begin - 1;
    x = A[end];
    for(j = begin; j < end; j++) {
        if(A[j] < x){
            i = i + 1;
            swap(A + i, A + j);
        }
    }
    swap(A + i + 1, A + end);
    return (i+1);
}

canonical_original_code:
int partition(int *A, int begin, int end)
{
    int i; int j;
    int x;
    i = begin - 1;
    x = A[end];
    for(j = begin; j < end; j++) {
        if(A[j] < x){
            i = i + 1;
            swap(A + i, A + j);
        }
    }
    swap(A + i + 1, A + end);
    return (i+1);
}

variable_types:
A
int *

variable_types: i int

variable_types: j int

variable_types: x int

return_type: int


decompiled_code:
__int64 __fastcall printf_array(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi

if ( a2 <= 0 )
return 0LL;
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
printf("%dth:%d\n", v5, v4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi

if ( a2 <= 0 )
return 0LL;
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
printf("%dth:%d\n", v5, v4);
}
return 0LL;
}

original_code:
int printf_array(int *A, int len)
{
    int i;
    for(i = 0; i < len; i++) {
        printf("%dth:%d\n", i, A[i]);
    }
    return 0;
}

variable_types: len int


decompiled_code:
__int64 __fastcall bubble_sort(_DWORD *a1, int a2)
{
int v3; // eax
_DWORD *v4; // r11
_DWORD *v5; // rcx
int v6; // er9
_DWORD *v7; // r8
_DWORD *v8; // rsi

if ( a2 > 0 )
{
v3 = a2 - 1;
v4 = a1 + 1;
if ( a2 != 1 )
{
do
{
v5 = a1;
v6 = v3 - 1;
v7 = &v4[v3 - 1];
do
{
while ( 1 )
{
v8 = v5++;
if ( *v8 > v8[1] )
break;
if ( v5 == v7 )
goto LABEL_7;
}
swap(v5, v8);
}
while ( v5 != v7 );
LABEL_7:
v3 = v6;
}
while ( v6 );
}
}
return 0LL;
}

original_code:
int bubble_sort(int *array,int len)
{
    int i,j;
    for(i = 0; i < len; i++) {
        for(j = 0; j < len - i -1; j++) {
            if (array[j] > array[j+1]) {
                swap(array+j+1,array+j);
            }
        }
    }
    return 0;
}

canonical_original_code:
int bubble_sort(int *array, int len)
{
    int i; int j;
    for(i = 0; i < len; i++) {
        for(j = 0; j < len - i -1; j++) {
            if (array[j] > array[j+1]) {
                swap(array+j+1,array+j);
            }
        }
    }
    return 0;
}

variable_types:
array
int *


swap

original_code:
void swap(int *a, int *b)
{
    int tmp ;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

canonical_original_code:
void swap(int *a, int *b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}


original_code:
int insertion_sort(int *A, int len)
{
    int i, j;
    int tmp;
    for (i = 1; i < len; i++) {
        tmp = A[i];
        for(j = i; j > 0; j--){
            if(tmp < A[j-1]){
                A[j] = A[j-1];
            }else{
                break;
            }
        }
        A[j] = tmp;
    }
    return 0;
}

canonical_original_code:
int insertion_sort(int *A, int len)
{
    int i; int j;
    int tmp;
    for (i = 1; i < len; i++) {
        tmp = A[i];
        for(j = i; j > 0; j--){
            if(tmp < A[j-1]){
                A[j] = A[j-1];
            }else{
                break;
            }
        }
        A[j] = tmp;
    }
    return 0;
}


repo: yanshuyuan/siteanalyzer

decompiled_code:
__int64 __fastcall sax_hash(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
unsigned int v3; // er8

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = 0;
do
v3 ^= *a1++ + (v3 >> 2) + 32 * v3;
while ( a1 != v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
unsigned int v3; // er8

if ( !a2 )
return 0LL;
v2 = &a1[a2];
v3 = 0;
do
v3 ^= *a1++ + (v3 >> 2) + 32 * v3;
while ( a1 != v2 );
return v3;
}

original_code:
unsigned int sax_hash(const char *key, size_t bytes)
{
    unsigned int h=0;
    while(bytes--) {
 h ^= (h<<5)+(h>>2)+(unsigned char)*key++;
    }
    return h;
}

canonical_original_code:
unsigned int sax_hash(char *key, unsigned long bytes)
{
    unsigned int h = 0;
    while(bytes--) {
 h ^= (h<<5)+(h>>2)+(unsigned char)*key++;
    }
    return h;
}

variable_types:
key
char *

variable_types:
bytes
unsigned long

variable_types:
h
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall sdbm_hash(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = (unsigned int)(v4 + 65599 * result);
}
while ( a1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rsi
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = (unsigned int)(v4 + 65599 * result);
}
while ( a1 != v2 );
return result;
}

original_code:
unsigned int sdbm_hash(const char *key, size_t bytes)
{
    unsigned int h=0;
    while(bytes--) {
  h=(unsigned char)*key++ + (h<<6) + (h<<16) - h;
    }
    return h;
}

canonical_original_code:
unsigned int sdbm_hash(char *key, unsigned long bytes)
{
    unsigned int h = 0;
    while(bytes--) {
  h=(unsigned char)*key++ + (h<<6) + (h<<16) - h;
    }
    return h;
}


decompiled_code:
__int64 __fastcall elf_hash(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = (unsigned int)(v4 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ~(result & 0xF0000000) & ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result);
}
while ( v2 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = (unsigned int)(v4 + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ~(result & 0xF0000000) & ((((unsigned int)result & 0xF0000000) >> 24) ^ (unsigned int)result);
}
while ( v2 != a1 );
return result;
}

original_code:
unsigned int elf_hash(const char *str, size_t bytes)
{
    unsigned int hash = 0;
    unsigned int x = 0;
    while (bytes--) {
        hash = (hash << 4) + (*str++);
        if((x = hash & 0xF0000000L) != 0) {
            hash ^= (x >> 24);
            hash &= ~x;
        }
    }
    return hash;
}

canonical_original_code:
unsigned int elf_hash(char *str, unsigned long bytes)
{
    unsigned int hash = 0;
    unsigned int x = 0;
    while (bytes--) {
        hash = (hash << 4) + (*str++);
        if((x = hash & 0xF0000000L) != 0) {
            hash ^= (x >> 24);
            hash &= ~x;
        }
    }
    return hash;
}

variable_types:
str
char *

variable_types:
hash
unsigned int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall djb_hash(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned int v3; // er8
int v4; // edx

if ( !a2 )
return 5381LL;
v2 = &a1[a2];
v3 = 5381;
do
{
v4 = *a1++;
v3 += v4 + 32 * v3;
}
while ( a1 != v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned int v3; // er8
int v4; // edx

if ( !a2 )
return 5381LL;
v2 = &a1[a2];
v3 = 5381;
do
{
v4 = *a1++;
v3 += v4 + 32 * v3;
}
while ( a1 != v2 );
return v3;
}

original_code:
unsigned int djb_hash(const char * str, size_t bytes)
{
    unsigned int hash = 5381 ;
    while(bytes--) {
        hash += (hash << 5) + (*str++ );
    }
    return hash;
}

canonical_original_code:
unsigned int djb_hash(char *str, unsigned long bytes)
{
    unsigned int hash = 5381;
    while(bytes--) {
        hash += (hash << 5) + (*str++ );
    }
    return hash;
}


decompiled_code:
__int64 __fastcall bkdr_hash(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = (unsigned int)(v4 + 131 * result);
}
while ( v2 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, __int64 a2)
{
char *v2; // rsi
__int64 result; // rax
int v4; // edx

if ( !a2 )
return 0LL;
v2 = &a1[a2];
LODWORD(result) = 0;
do
{
v4 = *a1++;
result = (unsigned int)(v4 + 131 * result);
}
while ( v2 != a1 );
return result;
}

original_code:
unsigned int bkdr_hash(const char * str, size_t bytes)
{
    unsigned int seed = 131 ;
    unsigned int hash = 0 ;
    while(bytes--) {
        hash = hash * seed + (*str++);
    }
    return hash;
}

canonical_original_code:
unsigned int bkdr_hash(char *str, unsigned long bytes)
{
    unsigned int seed = 131;
    unsigned int hash = 0;
    while(bytes--) {
        hash = hash * seed + (*str++);
    }
    return hash;
}

variable_types:
seed
unsigned int


original_code:
unsigned int js_hash(const char *str, size_t bytes)
{
    unsigned int hash = 1315423911;
    while(bytes--) {
        hash^=((hash << 5) + (*str++) + (hash >> 2));
    }
    return hash;
}

canonical_original_code:
unsigned int js_hash(char *str, unsigned long bytes)
{
    unsigned int hash = 1315423911;
    while(bytes--) {
        hash^=((hash << 5) + (*str++) + (hash >> 2));
    }
    return hash;
}


decompiled_code:
int __fastcall thread_init(__int64 a1)
{
__int64 v2; // rdi

v2 = a1 + 48;
*(_QWORD *)(v2 - 48) = 0LL;
*(_QWORD *)(v2 + 48) = 0xFFFFFFFFLL;
thread_counter_init();
return pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v2; // rdi

v2 = a1 + 48;
*(_QWORD *)(v2 - 48) = 0LL;
*(_QWORD *)(v2 + 48) = 0xFFFFFFFFLL;
thread_counter_init();
return pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL);
}

original_code:
void thread_init(thread_t *thread_item)
{
    thread_item->threadinfo = 0;
    thread_item->id = -1;
    thread_item->idle = 0;
    thread_counter_init(&thread_item->job_done);
    pthread_mutex_init(&thread_item->waitlock, ((void *)0));
}

canonical_original_code:
void thread_init(struct _thread *thread_item)
{
    thread_item->threadinfo = 0;
    thread_item->id = -1;
    thread_item->idle = 0;
    thread_counter_init(&thread_item->job_done);
    pthread_mutex_init(&thread_item->waitlock, ((void *)0));
}

variable_types: struct _thread { unsigned long threadinfo; 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; } waitlock; struct _thread_count { int count; union pthread_mutex_t lock; } job_done; int id; int idle; } *

user_defined_types: struct _thread { unsigned long threadinfo; union pthread_mutex_t waitlock; struct _thread_count job_done; int id; int idle; }

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

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


decompiled_code:
int __fastcall thread_destroy(__int64 a1)
{
thread_counter_destroy(a1 + 48);
return pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
thread_counter_destroy(a1 + 48);
return pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
}

original_code:
void thread_destroy(thread_t *thread_item)
{
    thread_counter_destroy(&thread_item->job_done);
    pthread_mutex_destroy(&thread_item->waitlock);
}

canonical_original_code:
void thread_destroy(struct _thread *thread_item)
{
    thread_counter_destroy(&thread_item->job_done);
    pthread_mutex_destroy(&thread_item->waitlock);
}

user_defined_types: struct _thread_count { int count; union pthread_mutex_t lock; }

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


decompiled_code:
int __fastcall thread_set_idle(__int64 a1, int a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 100) = a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)(a1 + 100) = a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

original_code:
void thread_set_idle(thread_t *thread_item, int idle)
{
    pthread_mutex_lock(&thread_item->waitlock);
    thread_item->idle = idle;
    pthread_mutex_unlock(&thread_item->waitlock);
}

canonical_original_code:
void thread_set_idle(struct _thread *thread_item, int idle)
{
    pthread_mutex_lock(&thread_item->waitlock);
    thread_item->idle = idle;
    pthread_mutex_unlock(&thread_item->waitlock);
}

variable_types: idle int


decompiled_code:
__int64 __fastcall thread_get_idle(__int64 a1)
{
unsigned int v1; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v1 = *(_DWORD *)(a1 + 100);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v1;
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v1 = *(_DWORD *)(a1 + 100);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v1;
}

original_code:
int thread_get_idle(thread_t *thread_item)
{
    int idle;
    pthread_mutex_lock(&thread_item->waitlock);
    idle = thread_item->idle;
    pthread_mutex_unlock(&thread_item->waitlock);
    return idle;
}

canonical_original_code:
int thread_get_idle(struct _thread *thread_item)
{
    int idle;
    pthread_mutex_lock(&thread_item->waitlock);
    idle = thread_item->idle;
    pthread_mutex_unlock(&thread_item->waitlock);
    return idle;
}


decompiled_code:
int __fastcall thread_join(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(pthread_t *a1)
{
return pthread_join(*a1, 0LL);
}

original_code:
void thread_join(thread_t *thread_item)
{
    pthread_join(thread_item->threadinfo, ((void *)0));
}

canonical_original_code:
void thread_join(struct _thread *thread_item)
{
    pthread_join(thread_item->threadinfo, ((void *)0));
}


decompiled_code:
// attributes: thunk
int thread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
{
return pthread_create(newthread, attr, start_routine, arg);
}

canonical_decompiled_code:
int func5(pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
{
return pthread_create(newthread, attr, start_routine, arg);
}

original_code:
int thread_create(thread_t *thread_item, const thread_attr_t *attr, void *(*start_routine) (void *), void *arg)
{
    return pthread_create(&thread_item->threadinfo, attr, start_routine, arg);
}

canonical_original_code:
int thread_create(struct _thread *thread_item, union pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
{
    return pthread_create(&thread_item->threadinfo, attr, start_routine, arg);
}

variable_types: union pthread_attr_t { char __size[56]; long __align; } *

variable_types:
arg
void *


original_code:
void queue_init(queue_t *q)
{
   q->meta.len = 0;
   q->meta.next = ((void *)0);
   q->head = &q->meta;
   q->tail = q->head;
}

canonical_original_code:
void queue_init(struct _queue *q)
{
   q->meta.len = 0;
   q->meta.next = ((void *)0);
   q->head = &q->meta;
   q->tail = q->head;
}

variable_types: struct _queue { struct _elem { struct _elem *next; int len; char buffer[]; } meta; struct _elem *head; struct _elem *tail; } *

user_defined_types: struct _queue { struct _elem meta; struct _elem *head; struct _elem *tail; }


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

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

original_code:
int queue_size(queue_t *q)
{
    return q->meta.len;
}

canonical_original_code:
int queue_size(struct _queue *q)
{
    return q->meta.len;
}

user_defined_types: struct _elem { struct _elem *next; int len; char buffer[]; }


decompiled_code:
__int64 __fastcall queue_front(__int64 a1)
{
return **(_QWORD **)(a1 + 16) + 12LL;
}

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

original_code:
const void *queue_front(queue_t *q)
{
    return q->head->next->buffer;
}

canonical_original_code:
void *queue_front(struct _queue *q)
{
    return q->head->next->buffer;
}

return_type: void *


original_code:
void queue_pop(queue_t *q)
{
    elem_t *_p_elem = q->head->next;
    q->head->next = _p_elem->next;
    free(_p_elem);
    q->meta.len--;
    if(q->meta.len == 0) { q->tail = &q->meta; }
}

canonical_original_code:
void queue_pop(struct _queue *q)
{
    struct _elem *_p_elem = q->head->next;
    q->head->next = _p_elem->next;
    free(_p_elem);
    q->meta.len--;
    if(q->meta.len == 0) { q->tail = &q->meta; }
}

variable_types: struct _elem { struct _elem *next; int len; char buffer[]; } *


decompiled_code:
void __fastcall queue_top(__int64 a1, void *a2)
{
memcpy(a2, (const void *)(**(_QWORD **)(a1 + 16) + 12LL), *(int *)(**(_QWORD **)(a1 + 16) + 8LL));
queue_pop(a1);
}

original_code:
void queue_top(queue_t *q, void *element)
{
    elem_t *_p_elem = q->head->next;
    memcpy(element, _p_elem->buffer, _p_elem->len);
    queue_pop(q);
}

canonical_original_code:
void queue_top(struct _queue *q, void *element)
{
    struct _elem *_p_elem = q->head->next;
    memcpy(element, _p_elem->buffer, _p_elem->len);
    queue_pop(q);
}

variable_types:
element
void *


decompiled_code:
__int64 __fastcall ts_queue_init(pthread_mutex_t *a1)
{
pthread_mutex_init(a1, 0LL);
return queue_init(&a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func0(pthread_mutex_t *a1)
{
pthread_mutex_init(a1, 0LL);
return queue_init(&a1[1]);
}

original_code:
void ts_queue_init(ts_queue_t *ts_queue)
{
    pthread_mutex_init(&ts_queue->mutex_lock, ((void *)0));
    queue_init(&ts_queue->queue);
}

canonical_original_code:
void ts_queue_init(struct _thread_safe_queue *ts_queue)
{
    pthread_mutex_init(&ts_queue->mutex_lock, ((void *)0));
    queue_init(&ts_queue->queue);
}

variable_types: struct _thread_safe_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; } mutex_lock; struct _queue { struct _elem { struct _elem *next; int len; char buffer[]; } meta; struct _elem *head; struct _elem *tail; } queue; } *

user_defined_types: struct _thread_safe_queue { union pthread_mutex_t mutex_lock; struct _queue queue; }


decompiled_code:
__int64 __fastcall ts_queue_destroy(pthread_mutex_t *a1)
{
pthread_mutex_destroy(a1);
return queue_destroy(&a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_mutex_t *a1)
{
pthread_mutex_destroy(a1);
return queue_destroy(&a1[1]);
}

original_code:
void ts_queue_destroy(ts_queue_t *ts_queue)
{
    pthread_mutex_destroy(&ts_queue->mutex_lock);
    queue_destroy(&ts_queue->queue);
}

canonical_original_code:
void ts_queue_destroy(struct _thread_safe_queue *ts_queue)
{
    pthread_mutex_destroy(&ts_queue->mutex_lock);
    queue_destroy(&ts_queue->queue);
}


decompiled_code:
int __fastcall ts_queue_push(pthread_mutex_t *mutex, __int64 a2, __int64 a3)
{
queue_lock(mutex);
queue_push(&mutex[1], a2, a3);
return queue_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func4(pthread_mutex_t *mutex, __int64 a2, __int64 a3)
{
func2(mutex);
queue_push(&mutex[1], a2, a3);
return func3(mutex);
}

original_code:
void ts_queue_push(ts_queue_t *ts_queue, void *element, size_t bytes)
{
    _queue_lock(ts_queue);
    queue_push(&ts_queue->queue, element, bytes);
    _queue_unlock(ts_queue);
}

canonical_original_code:
void ts_queue_push(struct _thread_safe_queue *ts_queue, void *element, unsigned long bytes)
{
    _queue_lock(ts_queue);
    queue_push(&ts_queue->queue, element, bytes);
    _queue_unlock(ts_queue);
}


decompiled_code:
int __fastcall ts_queue_pop(pthread_mutex_t *mutex)
{
queue_lock(mutex);
queue_pop(&mutex[1]);
return queue_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func5(pthread_mutex_t *mutex)
{
func2(mutex);
queue_pop(&mutex[1]);
return func3(mutex);
}

original_code:
void ts_queue_pop(ts_queue_t *ts_queue)
{
    _queue_lock(ts_queue);
    queue_pop(&ts_queue->queue);
    _queue_unlock(ts_queue);
}

canonical_original_code:
void ts_queue_pop(struct _thread_safe_queue *ts_queue)
{
    _queue_lock(ts_queue);
    queue_pop(&ts_queue->queue);
    _queue_unlock(ts_queue);
}


decompiled_code:
__int64 __fastcall ts_queue_front(pthread_mutex_t *mutex)
{
__int64 v1; // r12

queue_lock(mutex);
v1 = queue_front(&mutex[1]);
queue_unlock(mutex);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(pthread_mutex_t *mutex)
{
__int64 v1; // r12

func2(mutex);
v1 = queue_front(&mutex[1]);
func3(mutex);
return v1;
}

original_code:
const void *ts_queue_front(ts_queue_t *ts_queue)
{
    const void *elem = ((void *)0);
    _queue_lock(ts_queue);
    elem = queue_front(&ts_queue->queue);
    _queue_unlock(ts_queue);
    return elem;
}

canonical_original_code:
void *ts_queue_front(struct _thread_safe_queue *ts_queue)
{
    void *elem = ((void *)0);
    _queue_lock(ts_queue);
    elem = queue_front(&ts_queue->queue);
    _queue_unlock(ts_queue);
    return elem;
}

variable_types:
elem
void *


decompiled_code:
int __fastcall ts_queue_top(pthread_mutex_t *mutex, __int64 a2)
{
queue_lock(mutex);
queue_top(&mutex[1], a2);
return queue_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func7(pthread_mutex_t *mutex, __int64 a2)
{
func2(mutex);
queue_top(&mutex[1], a2);
return func3(mutex);
}

original_code:
void ts_queue_top(ts_queue_t *ts_queue, void *element)
{
    _queue_lock(ts_queue);
    queue_top(&ts_queue->queue, element);
    _queue_unlock(ts_queue);
}

canonical_original_code:
void ts_queue_top(struct _thread_safe_queue *ts_queue, void *element)
{
    _queue_lock(ts_queue);
    queue_top(&ts_queue->queue, element);
    _queue_unlock(ts_queue);
}


decompiled_code:
int __fastcall ts_queue_clear(pthread_mutex_t *mutex)
{
queue_lock(mutex);
queue_clear(&mutex[1]);
return queue_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func8(pthread_mutex_t *mutex)
{
func2(mutex);
queue_clear(&mutex[1]);
return func3(mutex);
}

original_code:
void ts_queue_clear(ts_queue_t *ts_queue)
{
    _queue_lock(ts_queue);
    queue_clear(&ts_queue->queue);
    _queue_unlock(ts_queue);
}

canonical_original_code:
void ts_queue_clear(struct _thread_safe_queue *ts_queue)
{
    _queue_lock(ts_queue);
    queue_clear(&ts_queue->queue);
    _queue_unlock(ts_queue);
}


decompiled_code:
__int64 __fastcall ts_queue_size(pthread_mutex_t *mutex)
{
unsigned int v1; // er12

queue_lock(mutex);
v1 = queue_size(&mutex[1]);
queue_unlock(mutex);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_mutex_t *mutex)
{
unsigned int v1; // er12

func2(mutex);
v1 = queue_size(&mutex[1]);
func3(mutex);
return v1;
}

original_code:
int ts_queue_size(ts_queue_t *ts_queue)
{
    int size;
    _queue_lock(ts_queue);
    size = queue_size(&ts_queue->queue);
    _queue_unlock(ts_queue);
    return size;
}

canonical_original_code:
int ts_queue_size(struct _thread_safe_queue *ts_queue)
{
    int size;
    _queue_lock(ts_queue);
    size = queue_size(&ts_queue->queue);
    _queue_unlock(ts_queue);
    return size;
}

variable_types: size int


decompiled_code:
__int64 __fastcall http_connect(__int64 a1, const char *a2, unsigned int a3)
{
http_request_init(a1 + 41232);
http_response_init(a1 + 46136);
strcpy((char *)(a1 + 45608), a2);
return open_tcp(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, unsigned int a3)
{
http_request_init(a1 + 41232);
http_response_init(a1 + 46136);
strcpy((char *)(a1 + 45608), a2);
return open_tcp(a1, a2, a3);
}

original_code:
int http_connect(http_client_t *http_client, char *hostname, int port)
{
    http_request_init(&http_client->request);
    http_response_init(&http_client->response);
    sprintf(http_client->request.req_header.host, "%s", hostname);
    return open_tcp(&http_client->connection, hostname, port);
}

canonical_original_code:
int http_connect(struct _http_client *http_client, char *hostname, int port)
{
    http_request_init(&http_client->request);
    http_response_init(&http_client->response);
    sprintf(http_client->request.req_header.host, "%s", hostname);
    return open_tcp(&http_client->connection, hostname, port);
}

variable_types: struct _http_client { struct _network { int socketfd; char host[256]; int port; int len; char buffer[-1]; } connection; struct _http_request { struct _http_request_line { char method[8]; char request_uri[4096]; char http_version[16]; } req_line; struct _http_general_header { char date[128]; } gen_header; struct _http_request_header { char user_agent[128]; char host[128]; char accept[128]; } req_header; struct _http_entity_header { char content_length[128]; char content_type[128]; } enti_header; struct _http_entity_body { int used; int len; char *buffer; } enti_body; } request; struct _http_response { struct _http_response_line { char http_version[16]; char status_code[8]; char reason_phrase[64]; } res_line; struct _http_general_header gen_header; struct _http_response_header { char server[128]; } res_header; struct _http_entity_header enti_header; struct _http_entity_body enti_body; } response; } *

variable_types:
hostname
char *

variable_types: port int

user_defined_types: struct _http_client { struct _network connection; struct _http_request request; struct _http_response response; }

user_defined_types: struct _http_request { struct _http_request_line req_line; struct _http_general_header gen_header; struct _http_request_header req_header; struct _http_entity_header enti_header; struct _http_entity_body enti_body; }

user_defined_types: struct _http_response { struct _http_response_line res_line; struct _http_general_header gen_header; struct _http_response_header res_header; struct _http_entity_header enti_header; struct _http_entity_body enti_body; }


decompiled_code:
__int64 __fastcall http_disconnect(__int64 a1)
{
http_request_destroy(a1 + 41232);
http_response_destroy(a1 + 46136);
return close_tcp(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
http_request_destroy(a1 + 41232);
http_response_destroy(a1 + 46136);
return close_tcp(a1);
}

original_code:
void http_disconnect(http_client_t *http_client)
{
    http_request_destroy(&http_client->request);
    http_response_destroy(&http_client->response);
    close_tcp(&http_client->connection);
}

canonical_original_code:
void http_disconnect(struct _http_client *http_client)
{
    http_request_destroy(&http_client->request);
    http_response_destroy(&http_client->response);
    close_tcp(&http_client->connection);
}

user_defined_types: struct _network { int socketfd; char host[256]; int port; int len; char buffer[-1]; }

user_defined_types: struct _http_request_line { char method[8]; char request_uri[4096]; char http_version[16]; }

user_defined_types: struct _http_general_header { char date[128]; }

user_defined_types: struct _http_request_header { char user_agent[128]; char host[128]; char accept[128]; }

user_defined_types: struct _http_entity_header { char content_length[128]; char content_type[128]; }

user_defined_types: struct _http_entity_body { int used; int len; char *buffer; }

user_defined_types: struct _http_response_line { char http_version[16]; char status_code[8]; char reason_phrase[64]; }

user_defined_types: struct _http_response_header { char server[128]; }


decompiled_code:
__int64 __fastcall http_do_get(__int64 a1, const char *a2)
{
size_t v3; // rax
int v4; // eax
void *v5; // rax
__int64 v6; // rbx
int v7; // er13
int v8; // er14
char *v9; // rdi
char *v10; // rax
char *v11; // rdi
int v12; // eax
int v13; // er12
char v15[4096]; // [rsp+0h] [rbp-3028h] BYREF
char src[8232]; // [rsp+1000h] [rbp-2028h] BYREF

bzero(v15, 0x1000uLL);
sprintf(
v15,
"GET %s HTTP/1.0\r\n"
"Host: %s\r\n"
"User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KH| TML, like Gecko) Ubuntu/11.10 Chromium/17.0.963.79"
" Chrome/17.0.963.79 Saf | ari/535.11\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"\r\n",
a2,
(const char *)(a1 + 4));
v3 = strlen(v15);
v4 = nsend(a1, v15, v3);
if ( v4 < 0 )
{
v13 = 1;
fprintf(stderr, "Http Request failed, error code: %d\n", (unsigned int)v4);
}
else
{
v5 = malloc(0xC8000uLL);
*(_QWORD *)(a1 + 46744) = v5;
if ( v5 )
{
v6 = 0LL;
v7 = 819200;
*(_DWORD *)(a1 + 46740) = 819200;
bzero(v5, 0xC8000uLL);
while ( 1 )
{
bzero(src, 0x2000uLL);
v12 = nrecv(a1, src, 4096LL);
v13 = v12;
if ( v12 <= 0 )
break;
v8 = v6 + v12;
v9 = *(char **)(a1 + 46744);
if ( (int)v6 + v12 > v7 )
{
v7 *= 2;
v10 = (char *)realloc(v9, v7);
*(_QWORD *)(a1 + 46744) = v10;
v9 = v10;
if ( !v10 )
{
*(_DWORD *)(a1 + 46740) = 0;
return 2;
}
*(_DWORD *)(a1 + 46740) = v7;
}
v11 = &v9[v6];
v6 = v8;
memcpy(v11, src, v13);
}
if ( v12 )
v13 = 2;
else
*(_BYTE *)(*(_QWORD *)(a1 + 46744) + v6) = 0;
}
else
{
*(_DWORD *)(a1 + 46740) = 0;
v13 = 2;
fwrite("Error: allocate memory failed in func 'do_get'.\n", 1uLL, 0x30uLL, stderr);
}
}
return (unsigned int)v13;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
size_t v3; // rax
int v4; // eax
void *v5; // rax
__int64 v6; // rbx
int v7; // er13
int v8; // er14
char *v9; // rdi
char *v10; // rax
char *v11; // rdi
int v12; // eax
int v13; // er12
char v15[4096]; // [rsp+0h] [rbp-3028h] BYREF
char src[8232]; // [rsp+1000h] [rbp-2028h] BYREF

bzero(v15, 0x1000uLL);
sprintf(
v15,
"GET %s HTTP/1.0\r\n"
"Host: %s\r\n"
"User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KH| TML, like Gecko) Ubuntu/11.10 Chromium/17.0.963.79"
" Chrome/17.0.963.79 Saf | ari/535.11\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"\r\n",
a2,
(const char *)(a1 + 4));
v3 = strlen(v15);
v4 = nsend(a1, v15, v3);
if ( v4 < 0 )
{
v13 = 1;
fprintf(stderr, "Http Request failed, error code: %d\n", (unsigned int)v4);
}
else
{
v5 = malloc(0xC8000uLL);
*(_QWORD *)(a1 + 46744) = v5;
if ( v5 )
{
v6 = 0LL;
v7 = 819200;
*(_DWORD *)(a1 + 46740) = 819200;
bzero(v5, 0xC8000uLL);
while ( 1 )
{
bzero(src, 0x2000uLL);
v12 = nrecv(a1, src, 4096LL);
v13 = v12;
if ( v12 <= 0 )
break;
v8 = v6 + v12;
v9 = *(char **)(a1 + 46744);
if ( (int)v6 + v12 > v7 )
{
v7 *= 2;
v10 = (char *)realloc(v9, v7);
*(_QWORD *)(a1 + 46744) = v10;
v9 = v10;
if ( !v10 )
{
*(_DWORD *)(a1 + 46740) = 0;
return 2;
}
*(_DWORD *)(a1 + 46740) = v7;
}
v11 = &v9[v6];
v6 = v8;
memcpy(v11, src, v13);
}
if ( v12 )
v13 = 2;
else
*(_BYTE *)(*(_QWORD *)(a1 + 46744) + v6) = 0;
}
else
{
*(_DWORD *)(a1 + 46740) = 0;
v13 = 2;
fwrite("Error: allocate memory failed in func 'do_get'.\n", 1uLL, 0x30uLL, stderr);
}
}
return (unsigned int)v13;
}

original_code:
int http_do_get(http_client_t *http_client, char *path)
{
    char http_request[4096];
    bzero(http_request, 4096);
    int size;
    sprintf(http_request, "GET %s HTTP/1.0\r\n"
   "Host: %s\r\n"
   "User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 "
    "(KH| TML, like Gecko) Ubuntu/11.10 Chromium/17.0.963.79 Chrome/17.0.963.79 Saf "
    "| ari/535.11\r\n"
   "Content-Type: application/x-www-form-urlencoded\r\n\r\n", path, http_client->connection.host);
    size = nsend(&http_client->connection, http_request, strlen(http_request));
    if(size < 0) {
 fprintf(stderr, "Http Request failed, error code: %d\n", size);
 return 1;
    }
    char buf[8192];
    http_res_t *response = &http_client->response;
    int entity_body_size, recv_body_length = 0;
    entity_body_size = 819200;
    response->enti_body.buffer = (char *) malloc(819200);
    if(response->enti_body.buffer == ((void *)0)) {
        response->enti_body.len = 0;
        fprintf(stderr, "Error: allocate memory failed in func 'do_get'.\n");
        return 2;
    } else {
        response->enti_body.len = entity_body_size;
        bzero(response->enti_body.buffer, entity_body_size);
        do {
            bzero(buf, 8192);
            size = nrecv(&http_client->connection, buf, 4096);
            if(size > 0) {
                if(recv_body_length + size > entity_body_size) {
      entity_body_size *= 2;
      response->enti_body.buffer = (char *)realloc(response->enti_body.buffer, entity_body_size);
      if(response->enti_body.buffer == ((void *)0)) {
   response->enti_body.len = 0;
                        return 2;
      } else {
   response->enti_body.len =entity_body_size;
      }
                }
                memcpy(response->enti_body.buffer + recv_body_length, buf, size);
                recv_body_length += size;
            } else if(size == 0) {
  response->enti_body.buffer[recv_body_length] = '\0';
  return 0;
            }else {
  return 2;
            }
        } while(1);
    }
    return 2;
}

canonical_original_code:
int http_do_get(struct _http_client *http_client, char *path)
{
    char http_request[4096];
    bzero(http_request, 4096);
    int size;
    sprintf(http_request, "GET %s HTTP/1.0\r\n"
   "Host: %s\r\n"
   "User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 "
    "(KH| TML, like Gecko) Ubuntu/11.10 Chromium/17.0.963.79 Chrome/17.0.963.79 Saf "
    "| ari/535.11\r\n"
   "Content-Type: application/x-www-form-urlencoded\r\n\r\n", path, http_client->connection.host);
    size = nsend(&http_client->connection, http_request, strlen(http_request));
    if(size < 0) {
 fprintf(stderr, "Http Request failed, error code: %d\n", size);
 return 1;
    }
    char buf[8192];
    struct _http_response *response = &http_client->response;
    int entity_body_size; int recv_body_length = 0;
    entity_body_size = 819200;
    response->enti_body.buffer = (char *) malloc(819200);
    if(response->enti_body.buffer == ((void *)0)) {
        response->enti_body.len = 0;
        fprintf(stderr, "Error: allocate memory failed in func 'do_get'.\n");
        return 2;
    } else {
        response->enti_body.len = entity_body_size;
        bzero(response->enti_body.buffer, entity_body_size);
        do {
            bzero(buf, 8192);
            size = nrecv(&http_client->connection, buf, 4096);
            if(size > 0) {
                if(recv_body_length + size > entity_body_size) {
      entity_body_size *= 2;
      response->enti_body.buffer = (char *)realloc(response->enti_body.buffer, entity_body_size);
      if(response->enti_body.buffer == ((void *)0)) {
   response->enti_body.len = 0;
                        return 2;
      } else {
   response->enti_body.len =entity_body_size;
      }
                }
                memcpy(response->enti_body.buffer + recv_body_length, buf, size);
                recv_body_length += size;
            } else if(size == 0) {
  response->enti_body.buffer[recv_body_length] = '\0';
  return 0;
            }else {
  return 2;
            }
        } while(1);
    }
    return 2;
}

variable_types:
path
char *

variable_types:
buf
char [8192]

variable_types: struct _http_response { struct _http_response_line { char http_version[16]; char status_code[8]; char reason_phrase[64]; } res_line; struct _http_general_header { char date[128]; } gen_header; struct _http_response_header { char server[128]; } res_header; struct _http_entity_header { char content_length[128]; char content_type[128]; } enti_header; struct _http_entity_body { int used; int len; char *buffer; } enti_body; } *


decompiled_code:
__int64 __fastcall http_response_status(__int64 a1)
{
const char *v1; // rdi
unsigned int v3; // [rsp+Ch] [rbp-100Ch] BYREF
char v4; // [rsp+10h] [rbp-1008h] BYREF

v1 = *(const char **)(a1 + 46744);
v3 = 0;
sscanf(v1, "%s%d", &v4, &v3);
printf("status code: %d\n", v3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char *v1; // rdi
unsigned int v3; // [rsp+Ch] [rbp-100Ch] BYREF
char v4; // [rsp+10h] [rbp-1008h] BYREF

v1 = *(const char **)(a1 + 46744);
v3 = 0;
sscanf(v1, "%s%d", &v4, &v3);
printf("status code: %d\n", v3);
return v3;
}

original_code:
int http_response_status(http_client_t *http_client)
{
    char buffer[4096];
    int status_code = 0;
    http_res_t *response = &http_client->response;
    sscanf(response->enti_body.buffer, "%s%d", buffer, &status_code);
    printf("status code: %d\n", status_code);
    return status_code;
}

canonical_original_code:
int http_response_status(struct _http_client *http_client)
{
    char buffer[4096];
    int status_code = 0;
    struct _http_response *response = &http_client->response;
    sscanf(response->enti_body.buffer, "%s%d", buffer, &status_code);
    printf("status code: %d\n", status_code);
    return status_code;
}

variable_types:
buffer
char [4096]


decompiled_code:
__int64 __fastcall http_response_body(__int64 a1)
{
return *(_QWORD *)(a1 + 46744);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 46744);
}

original_code:
const char * http_response_body(http_client_t *http_client)
{
    return http_client->response.enti_body.buffer;
}

canonical_original_code:
char *http_response_body(struct _http_client *http_client)
{
    return http_client->response.enti_body.buffer;
}

return_type: char *


decompiled_code:
int __fastcall thread_counter_init(__int64 a1)
{
*(_DWORD *)a1 = 0;
return pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
*(_DWORD *)a1 = 0;
return pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL);
}

original_code:
void thread_counter_init(thread_counter_t *thread_counter)
{
    thread_counter->count = 0;
    pthread_mutex_init(&thread_counter->lock, ((void *)0));
}

canonical_original_code:
void thread_counter_init(struct _thread_count *thread_counter)
{
    thread_counter->count = 0;
    pthread_mutex_init(&thread_counter->lock, ((void *)0));
}

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

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

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


decompiled_code:
int __fastcall thread_counter_destroy(__int64 a1)
{
return pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
return pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
}

original_code:
void thread_counter_destroy(thread_counter_t *thread_counter)
{
    pthread_mutex_destroy(&thread_counter->lock);
}

canonical_original_code:
void thread_counter_destroy(struct _thread_count *thread_counter)
{
    pthread_mutex_destroy(&thread_counter->lock);
}

user_defined_types: struct _thread_count { int count; union pthread_mutex_t lock; }

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


decompiled_code:
int __fastcall thread_counter_increase(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
++*(_DWORD *)a1;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
++*(_DWORD *)a1;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

original_code:
void thread_counter_increase(thread_counter_t *thread_counter)
{
    pthread_mutex_lock(&thread_counter->lock);
    thread_counter->count++;
    pthread_mutex_unlock(&thread_counter->lock);
}

canonical_original_code:
void thread_counter_increase(struct _thread_count *thread_counter)
{
    pthread_mutex_lock(&thread_counter->lock);
    thread_counter->count++;
    pthread_mutex_unlock(&thread_counter->lock);
}


decompiled_code:
int __fastcall thread_counter_decrease(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
--*(_DWORD *)a1;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
--*(_DWORD *)a1;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

original_code:
void thread_counter_decrease(thread_counter_t *thread_counter)
{
    pthread_mutex_lock(&thread_counter->lock);
    thread_counter->count--;
    pthread_mutex_unlock(&thread_counter->lock);
}

canonical_original_code:
void thread_counter_decrease(struct _thread_count *thread_counter)
{
    pthread_mutex_lock(&thread_counter->lock);
    thread_counter->count--;
    pthread_mutex_unlock(&thread_counter->lock);
}


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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
v1 = *a1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 2));
return v1;
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
v1 = *a1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 2));
return v1;
}

original_code:
int thread_counter_get(thread_counter_t *thread_counter)
{
    int c;
    pthread_mutex_lock(&thread_counter->lock);
    c = thread_counter->count;
    pthread_mutex_unlock(&thread_counter->lock);
    return c;
}

canonical_original_code:
int thread_counter_get(struct _thread_count *thread_counter)
{
    int c;
    pthread_mutex_lock(&thread_counter->lock);
    c = thread_counter->count;
    pthread_mutex_unlock(&thread_counter->lock);
    return c;
}

variable_types: c int


decompiled_code:
int __fastcall thread_counter_set(__int64 a1, int a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)a1 = a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
*(_DWORD *)a1 = a2;
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

original_code:
void thread_counter_set(thread_counter_t *thread_counter, int count)
{
    pthread_mutex_lock(&thread_counter->lock);
    thread_counter->count = count;
    pthread_mutex_unlock(&thread_counter->lock);
}

canonical_original_code:
void thread_counter_set(struct _thread_count *thread_counter, int count)
{
    pthread_mutex_lock(&thread_counter->lock);
    thread_counter->count = count;
    pthread_mutex_unlock(&thread_counter->lock);
}

variable_types: count int


decompiled_code:
__int64 __fastcall thread_counter_compare(int *a1, int a2)
{
int v2; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
v2 = *a1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 2));
return (unsigned int)(v2 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, int a2)
{
int v2; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
v2 = *a1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 2));
return (unsigned int)(v2 - a2);
}

original_code:
int thread_counter_compare(thread_counter_t *thread_counter, int count)
{
    int r;
    pthread_mutex_lock(&thread_counter->lock);
    r = thread_counter->count - count;
    pthread_mutex_unlock(&thread_counter->lock);
    return r;
}

canonical_original_code:
int thread_counter_compare(struct _thread_count *thread_counter, int count)
{
    int r;
    pthread_mutex_lock(&thread_counter->lock);
    r = thread_counter->count - count;
    pthread_mutex_unlock(&thread_counter->lock);
    return r;
}

variable_types: r int


original_code:
void list_init(list_t *l)
{
    l->meta.len = 0;
    l->meta.next = ((void *)0);
    l->head = &l->meta;
    l->tail = l->head;
}

canonical_original_code:
void list_init(struct _list *l)
{
    l->meta.len = 0;
    l->meta.next = ((void *)0);
    l->head = &l->meta;
    l->tail = l->head;
}

variable_types: struct _list { struct _elem { struct _elem *next; int len; char buffer[]; } meta; struct _elem *head; struct _elem *tail; } *

user_defined_types: struct _list { struct _elem meta; struct _elem *head; struct _elem *tail; }


decompiled_code:
char *__fastcall list_index_of(__int64 a1, unsigned __int64 a2)
{
return (char *)list_index_of(a1, a2) + 12;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, unsigned __int64 a2)
{
return (char *)func1(a1, a2) + 12;
}

original_code:
void *list_index_of(list_t *l, size_t index)
{
    elem_t *elem = _list_index_of(l, index);
    return elem->buffer;
}

canonical_original_code:
void *list_index_of(struct _list *l, unsigned long index)
{
    struct _elem *elem = _list_index_of(l, index);
    return elem->buffer;
}

variable_types:
index
unsigned long

variable_types: struct _elem { struct _elem *next; int len; char buffer[]; } *


decompiled_code:
void __fastcall list_erase(__int64 a1, unsigned __int64 a2)
{
int v3; // er8
_QWORD **v4; // rdx
_QWORD *v5; // rdi
__int64 v6; // rax
int v7; // er8

v3 = *(_DWORD *)(a1 + 8);
if ( v3 <= a2 )
{
fwrite("Error: index out of list in func 'list_erase'.\n", 1uLL, 0x2FuLL, stderr);
}
else
{
v4 = *(_QWORD ***)(a1 + 16);
v5 = *v4;
if ( *v4 )
{
if ( a2 )
{
v6 = 0LL;
while ( 1 )
{
v4 = (_QWORD **)v5;
v5 = (_QWORD *)*v5;
++v6;
if ( !v5 )
break;
if ( a2 == v6 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v7 = v3 - 1;
if ( v7 == a2 )
*(_QWORD *)(a1 + 24) = v4;
*v4 = (_QWORD *)*v5;
*(_DWORD *)(a1 + 8) = v7;
free(v5);
}
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, unsigned __int64 a2)
{
int v3; // er8
_QWORD **v4; // rdx
_QWORD *v5; // rdi
__int64 v6; // rax
int v7; // er8

v3 = *(_DWORD *)(a1 + 8);
if ( v3 <= a2 )
{
fwrite("Error: index out of list in func 'list_erase'.\n", 1uLL, 0x2FuLL, stderr);
}
else
{
v4 = *(_QWORD ***)(a1 + 16);
v5 = *v4;
if ( *v4 )
{
if ( a2 )
{
v6 = 0LL;
while ( 1 )
{
v4 = (_QWORD **)v5;
v5 = (_QWORD *)*v5;
++v6;
if ( !v5 )
break;
if ( a2 == v6 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v7 = v3 - 1;
if ( v7 == a2 )
*(_QWORD *)(a1 + 24) = v4;
*v4 = (_QWORD *)*v5;
*(_DWORD *)(a1 + 8) = v7;
free(v5);
}
}
}
}

original_code:
void list_erase(list_t *l, size_t index)
{
    if(index >= 0 && index < l->meta.len) {
        size_t ix = 0;
        elem_t *_c_elem = l->head->next;
        elem_t *_p_elem = l->head;
        while(_c_elem != ((void *)0)) {
            if(index == ix) {
  if(index == l->meta.len - 1) { l->tail = _p_elem; }
                _p_elem->next = _c_elem->next;
                l->meta.len--;
                free(_c_elem);
  return;
            } else {
                _p_elem = _c_elem;
                _c_elem = _c_elem->next;
  ix++;
            }
        }
    } else {
 fprintf(stderr, "Error: index out of list in func 'list_erase'.\n");
    }
}

canonical_original_code:
void list_erase(struct _list *l, unsigned long index)
{
    if(index >= 0 && index < l->meta.len) {
        unsigned long ix = 0;
        struct _elem *_c_elem = l->head->next;
        struct _elem *_p_elem = l->head;
        while(_c_elem != ((void *)0)) {
            if(index == ix) {
  if(index == l->meta.len - 1) { l->tail = _p_elem; }
                _p_elem->next = _c_elem->next;
                l->meta.len--;
                free(_c_elem);
  return;
            } else {
                _p_elem = _c_elem;
                _c_elem = _c_elem->next;
  ix++;
            }
        }
    } else {
 fprintf(stderr, "Error: index out of list in func 'list_erase'.\n");
    }
}

variable_types:
ix
unsigned long

user_defined_types: struct _elem { struct _elem *next; int len; char buffer[]; }


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

if ( *(_DWORD *)(a1 + 8) )
{
do
{
list_erase(a1, 0LL);
result = *(unsigned int *)(a1 + 8);
}
while ( (_DWORD)result );
}
return result;
}

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

if ( *(_DWORD *)(a1 + 8) )
{
do
{
func2(a1, 0LL);
result = *(unsigned int *)(a1 + 8);
}
while ( (_DWORD)result );
}
return result;
}

original_code:
void list_clear(list_t *l)
{
    while(l->meta.len != 0) {
 list_erase(l, 0);
    }
}

canonical_original_code:
void list_clear(struct _list *l)
{
    while(l->meta.len != 0) {
 list_erase(l, 0);
    }
}


decompiled_code:
// attributes: thunk
__int64 __fastcall list_destroy(__int64 a1)
{
return list_clear(a1);
}

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

original_code:
void list_destroy(list_t *l)
{
    list_clear(l);
}

canonical_original_code:
void list_destroy(struct _list *l)
{
    list_clear(l);
}


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

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

original_code:
int list_size(list_t *l)
{
    return l->meta.len;
}

canonical_original_code:
int list_size(struct _list *l)
{
    return l->meta.len;
}


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

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

original_code:
elem_t* list_first(list_t *l)
{
    return l->head->next;
}

canonical_original_code:
struct _elem *list_first(struct _list *l)
{
    return l->head->next;
}

variable_types: struct _list { struct _elem meta; struct _elem *head; struct _elem *tail; } *

return_type: struct _elem { struct _elem *next; int len; char buffer[]; } *


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

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

original_code:
elem_t* list_end(list_t *l)
{
    return ((void *)0);
}

canonical_original_code:
struct _elem *list_end(struct _list *l)
{
    return ((void *)0);
}


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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
elem_t* list_next(elem_t *iter)
{
    return iter == ((void *)0) ? ((void *)0) : iter->next;
}

canonical_original_code:
struct _elem *list_next(struct _elem *iter)
{
    return iter == ((void *)0) ? ((void *)0) : iter->next;
}

variable_types:
iter
struct _elem *


decompiled_code:
size_t __fastcall thread_pool_init(char **a1, char *a2)
{
char *v3; // rax
__int64 v4; // r13
char *v5; // rbx
char *v6; // rdi
char **v7; // rdi
char **v8; // rbp

v3 = (char *)malloc(104LL * (_QWORD)a2);
*a1 = v3;
if ( !v3 )
return fwrite("Error: allocate memory failed in func 'thread_pool_init'.\n", 1uLL, 0x3AuLL, stderr);
v4 = 0LL;
v5 = 0LL;
if ( a2 )
{
while ( 1 )
{
v6 = &v3[v4];
++v5;
v4 += 104LL;
thread_init(v6);
if ( a2 == v5 )
break;
v3 = *a1;
}
}
a1[1] = a2;
ts_queue_init(a1 + 18);
sem_init((sem_t *)(a1 + 2), 0, 0);
v7 = a1 + 6;
v8 = a1 + 12;
thread_counter_init(v7);
thread_counter_init(v8);
return thread_counter_set(v8, (unsigned int)a2);
}

canonical_decompiled_code:
size_t __fastcall func0(char **a1, char *a2)
{
char *v3; // rax
__int64 v4; // r13
char *v5; // rbx
char *v6; // rdi
char **v7; // rdi
char **v8; // rbp

v3 = (char *)malloc(104LL * (_QWORD)a2);
*a1 = v3;
if ( !v3 )
return fwrite("Error: allocate memory failed in func 'thread_pool_init'.\n", 1uLL, 0x3AuLL, stderr);
v4 = 0LL;
v5 = 0LL;
if ( a2 )
{
while ( 1 )
{
v6 = &v3[v4];
++v5;
v4 += 104LL;
thread_init(v6);
if ( a2 == v5 )
break;
v3 = *a1;
}
}
a1[1] = a2;
ts_queue_init(a1 + 18);
sem_init((sem_t *)(a1 + 2), 0, 0);
v7 = a1 + 6;
v8 = a1 + 12;
thread_counter_init(v7);
thread_counter_init(v8);
return thread_counter_set(v8, (unsigned int)a2);
}

original_code:
void thread_pool_init(thread_pool_t *thread_pool, size_t thread_count)
{
    if((thread_pool->thread_items = (thread_t *) malloc(sizeof(thread_t) * thread_count)) == ((void *)0)) {
 fprintf(stderr, "Error: allocate memory failed in func 'thread_pool_init'.\n");
    } else {
 size_t i;
 for(i = 0; i < thread_count; i++) {
     thread_init(&thread_pool->thread_items[i]);
        }
 thread_pool->thread_count = thread_count;
 ts_queue_init(&thread_pool->job_queue);
 sem_init(&thread_pool->job_sem, 0, 0);
 thread_counter_init(&thread_pool->job_done);
 thread_counter_init(&thread_pool->thread_idle);
 thread_counter_set(&thread_pool->thread_idle, thread_count);
    }
}

canonical_original_code:
void thread_pool_init(struct _thread_pool *thread_pool, unsigned long thread_count)
{
    if((thread_pool->thread_items = (struct _thread *) malloc(sizeof(thread_t) * thread_count)) == ((void *)0)) {
 fprintf(stderr, "Error: allocate memory failed in func 'thread_pool_init'.\n");
    } else {
 unsigned long i;
 for(i = 0; i < thread_count; i++) {
     thread_init(&thread_pool->thread_items[i]);
        }
 thread_pool->thread_count = thread_count;
 ts_queue_init(&thread_pool->job_queue);
 sem_init(&thread_pool->job_sem, 0, 0);
 thread_counter_init(&thread_pool->job_done);
 thread_counter_init(&thread_pool->thread_idle);
 thread_counter_set(&thread_pool->thread_idle, thread_count);
    }
}

variable_types: struct _thread_pool { struct _thread { unsigned long threadinfo; 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; } waitlock; struct _thread_count { int count; union pthread_mutex_t lock; } job_done; int id; int idle; } *thread_items; unsigned long thread_count; union sem_t { char __size[32]; long __align; } job_sem; struct _thread_count job_done; struct _thread_count thread_idle; struct _thread_safe_queue { union pthread_mutex_t mutex_lock; struct _queue { struct _elem { struct _elem *next; int len; char buffer[]; } meta; struct _elem *head; struct _elem *tail; } queue; } job_queue; } *

variable_types:
i
unsigned long

user_defined_types: struct _thread_pool { struct _thread *thread_items; unsigned long thread_count; union sem_t job_sem; struct _thread_count job_done; struct _thread_count thread_idle; struct _thread_safe_queue job_queue; }

user_defined_types: struct _thread { unsigned long threadinfo; union pthread_mutex_t waitlock; struct _thread_count job_done; int id; int idle; }

user_defined_types: struct _thread_safe_queue { union pthread_mutex_t mutex_lock; struct _queue queue; }

user_defined_types: struct _queue { struct _elem meta; struct _elem *head; struct _elem *tail; }


decompiled_code:
__int64 __fastcall thread_pool_destroy(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rdx

if ( *(_QWORD *)(a1 + 8) )
{
v1 = 0LL;
do
{
v2 = 13 * v1++;
thread_destroy(*(_QWORD *)a1 + 8 * v2);
}
while ( *(_QWORD *)(a1 + 8) > v1 );
}
free(*(void **)a1);
ts_queue_destroy(a1 + 144);
sem_destroy((sem_t *)(a1 + 16));
thread_counter_destroy(a1 + 48);
return thread_counter_destroy(a1 + 96);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rdx

if ( *(_QWORD *)(a1 + 8) )
{
v1 = 0LL;
do
{
v2 = 13 * v1++;
thread_destroy(*(_QWORD *)a1 + 8 * v2);
}
while ( *(_QWORD *)(a1 + 8) > v1 );
}
free(*(void **)a1);
ts_queue_destroy(a1 + 144);
sem_destroy((sem_t *)(a1 + 16));
thread_counter_destroy(a1 + 48);
return thread_counter_destroy(a1 + 96);
}

original_code:
void thread_pool_destroy(thread_pool_t *thread_pool)
{
    size_t i;
    for(i = 0; i < thread_pool->thread_count; i++) {
 thread_destroy(&thread_pool->thread_items[i]);
    }
    free(thread_pool->thread_items);
    ts_queue_destroy(&thread_pool->job_queue);
    sem_destroy(&thread_pool->job_sem);
    thread_counter_destroy(&thread_pool->job_done);
    thread_counter_destroy(&thread_pool->thread_idle);
}

canonical_original_code:
void thread_pool_destroy(struct _thread_pool *thread_pool)
{
    unsigned long i;
    for(i = 0; i < thread_pool->thread_count; i++) {
 thread_destroy(&thread_pool->thread_items[i]);
    }
    free(thread_pool->thread_items);
    ts_queue_destroy(&thread_pool->job_queue);
    sem_destroy(&thread_pool->job_sem);
    thread_counter_destroy(&thread_pool->job_done);
    thread_counter_destroy(&thread_pool->thread_idle);
}

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


decompiled_code:
__int64 __fastcall thread_pool_join(_QWORD *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rdx
__int64 result; // rax

if ( a1[1] )
{
v1 = 0LL;
do
{
v2 = 13 * v1++;
result = thread_join(*a1 + 8 * v2);
}
while ( a1[1] > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
unsigned __int64 v1; // rbx
__int64 v2; // rdx
__int64 result; // rax

if ( a1[1] )
{
v1 = 0LL;
do
{
v2 = 13 * v1++;
result = thread_join(*a1 + 8 * v2);
}
while ( a1[1] > v1 );
}
return result;
}

original_code:
void thread_pool_join(thread_pool_t *thread_pool)
{
    size_t i;
    for(i = 0; i < thread_pool->thread_count; i++) {
     thread_join(&thread_pool->thread_items[i]);
    }
}

canonical_original_code:
void thread_pool_join(struct _thread_pool *thread_pool)
{
    unsigned long i;
    for(i = 0; i < thread_pool->thread_count; i++) {
     thread_join(&thread_pool->thread_items[i]);
    }
}


decompiled_code:
int __fastcall thread_pool_wait_job_semaphare(__int64 a1)
{
return sem_wait((sem_t *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
return sem_wait((sem_t *)(a1 + 16));
}

original_code:
void thread_pool_wait_job_semaphare(thread_pool_t *thread_pool)
{
    sem_wait(&thread_pool->job_sem);
}

canonical_original_code:
void thread_pool_wait_job_semaphare(struct _thread_pool *thread_pool)
{
    sem_wait(&thread_pool->job_sem);
}


decompiled_code:
int __fastcall thread_pool_post_job_semaphare(__int64 a1)
{
return sem_post((sem_t *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
return sem_post((sem_t *)(a1 + 16));
}

original_code:
void thread_pool_post_job_semaphare(thread_pool_t *thread_pool)
{
    sem_post(&thread_pool->job_sem);
}

canonical_original_code:
void thread_pool_post_job_semaphare(struct _thread_pool *thread_pool)
{
    sem_post(&thread_pool->job_sem);
}


decompiled_code:
__int64 __fastcall thread_pool_get_job(__int64 a1)
{
return ts_queue_top(a1 + 144);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return ts_queue_top(a1 + 144);
}

original_code:
void thread_pool_get_job(thread_pool_t *thread_pool, job_t *job)
{
    ts_queue_top(&thread_pool->job_queue, job);
}

canonical_original_code:
void thread_pool_get_job(struct _thread_pool *thread_pool, struct _job *job)
{
    ts_queue_top(&thread_pool->job_queue, job);
}

variable_types: struct _job { void *(*run)(void *); void *arg; } *


decompiled_code:
__int64 __fastcall thread_do_job(void *ptr)
{
__int64 v1; // rsi
void (__fastcall *v3)(__int64 *); // [rsp+0h] [rbp-28h]
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5[3]; // [rsp+10h] [rbp-18h] BYREF

thread_set_idle(*((_QWORD *)ptr + 1), 1LL);
while ( (unsigned int)thread_get_idle(*((_QWORD *)ptr + 1)) == 1 )
{
thread_pool_wait_job_semaphare(*(_QWORD *)ptr);
thread_counter_decrease(*(_QWORD *)ptr + 96LL);
thread_pool_get_job(*(_QWORD *)ptr);
v1 = *(unsigned int *)(*((_QWORD *)ptr + 1) + 96LL);
v5[0] = *((_QWORD *)ptr + 1);
v5[1] = v4;
printf("threadID: %d start work\n", v1);
v3(v5);
printf("threadID: %d work end\n", *(unsigned int *)(*((_QWORD *)ptr + 1) + 96LL));
thread_counter_increase(*(_QWORD *)ptr + 96LL);
thread_counter_increase(*(_QWORD *)ptr + 48LL);
thread_counter_increase(*((_QWORD *)ptr + 1) + 48LL);
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr)
{
__int64 v1; // rsi
void (__fastcall *v3)(__int64 *); // [rsp+0h] [rbp-28h]
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5[3]; // [rsp+10h] [rbp-18h] BYREF

thread_set_idle(*((_QWORD *)ptr + 1), 1LL);
while ( (unsigned int)thread_get_idle(*((_QWORD *)ptr + 1)) == 1 )
{
func3(*(_QWORD *)ptr);
thread_counter_decrease(*(_QWORD *)ptr + 96LL);
func5(*(_QWORD *)ptr);
v1 = *(unsigned int *)(*((_QWORD *)ptr + 1) + 96LL);
v5[0] = *((_QWORD *)ptr + 1);
v5[1] = v4;
printf("threadID: %d start work\n", v1);
v3(v5);
printf("threadID: %d work end\n", *(unsigned int *)(*((_QWORD *)ptr + 1) + 96LL));
thread_counter_increase(*(_QWORD *)ptr + 96LL);
thread_counter_increase(*(_QWORD *)ptr + 48LL);
thread_counter_increase(*((_QWORD *)ptr + 1) + 48LL);
}
free(ptr);
return 0LL;
}

original_code:
void *thread_do_job(void *arg)
{
    thread_info_t *thread_info = (thread_info_t *) arg;
    job_t job;
    thread_set_idle(thread_info->thread_item, 1);
    while(thread_get_idle(thread_info->thread_item) == 1) {
 thread_pool_wait_job_semaphare(thread_info->thread_pool);
 thread_counter_decrease(&thread_info->thread_pool->thread_idle);
        thread_pool_get_job(thread_info->thread_pool, &job);
 job_arg_t job_arg;
 job_arg.thread_item = thread_info->thread_item;
 job_arg.arg = job.arg;
 printf("threadID: %d start work\n", thread_info->thread_item->id);
 job.run(&job_arg);
 printf("threadID: %d work end\n", thread_info->thread_item->id);
 thread_counter_increase(&thread_info->thread_pool->thread_idle);
 thread_counter_increase(&thread_info->thread_pool->job_done);
 thread_counter_increase(&thread_info->thread_item->job_done);
    }
    free(thread_info);
    return 0;
}

canonical_original_code:
void *thread_do_job(void *arg)
{
    struct _thread_info *thread_info = (thread_info_t *) arg;
    struct _job job;
    thread_set_idle(thread_info->thread_item, 1);
    while(thread_get_idle(thread_info->thread_item) == 1) {
 thread_pool_wait_job_semaphare(thread_info->thread_pool);
 thread_counter_decrease(&thread_info->thread_pool->thread_idle);
        thread_pool_get_job(thread_info->thread_pool, &job);
 struct _job_arg job_arg;
 job_arg.thread_item = thread_info->thread_item;
 job_arg.arg = job.arg;
 printf("threadID: %d start work\n", thread_info->thread_item->id);
 job.run(&job_arg);
 printf("threadID: %d work end\n", thread_info->thread_item->id);
 thread_counter_increase(&thread_info->thread_pool->thread_idle);
 thread_counter_increase(&thread_info->thread_pool->job_done);
 thread_counter_increase(&thread_info->thread_item->job_done);
    }
    free(thread_info);
    return 0;
}

variable_types:
arg
void *

variable_types: struct _thread_info { struct _thread_pool { struct _thread { unsigned long threadinfo; 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; } waitlock; struct _thread_count { int count; union pthread_mutex_t lock; } job_done; int id; int idle; } *thread_items; unsigned long thread_count; union sem_t { char __size[32]; long __align; } job_sem; struct _thread_count job_done; struct _thread_count thread_idle; struct _thread_safe_queue { union pthread_mutex_t mutex_lock; struct _queue { struct _elem { struct _elem *next; int len; char buffer[]; } meta; struct _elem *head; struct _elem *tail; } queue; } job_queue; } *thread_pool; struct _thread *thread_item; } *

variable_types: struct _job { void *(*run)(void *); void *arg; }

variable_types: struct _job_arg { struct _thread { unsigned long threadinfo; 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; } waitlock; struct _thread_count { int count; union pthread_mutex_t lock; } job_done; int id; int idle; } *thread_item; void *arg; }

user_defined_types: struct _job_arg { struct _thread *thread_item; void *arg; }

user_defined_types: struct _thread_info { struct _thread_pool *thread_pool; struct _thread *thread_item; }


decompiled_code:
__int64 __fastcall thread_pool_set_job(__int64 a1, __int64 a2)
{
return ts_queue_push(a1 + 144, a2, 16LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return ts_queue_push(a1 + 144, a2, 16LL);
}

original_code:
void thread_pool_set_job(thread_pool_t *thread_pool, job_t *job)
{
    ts_queue_push(&thread_pool->job_queue, job, sizeof(job_t));
}

canonical_original_code:
void thread_pool_set_job(struct _thread_pool *thread_pool, struct _job *job)
{
    ts_queue_push(&thread_pool->job_queue, job, sizeof(job_t));
}

user_defined_types: struct _job { void *(*run)(void *); void *arg; }


decompiled_code:
void __fastcall thread_pool_run(_QWORD *a1)
{
unsigned __int64 v2; // rbx
_QWORD *v3; // rax
__int64 v4; // rdi
unsigned int v5; // eax
__int64 v6; // rdx

if ( a1[1] )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = malloc(0x10uLL);
v4 = *a1 + 104 * v2;
v3[1] = v4;
*(_DWORD *)(v4 + 96) = v2;
*v3 = a1;
v5 = thread_create(v4, 0LL, thread_do_job);
if ( v5 )
break;
if ( a1[1] <= ++v2 )
return;
}
v6 = v2++;
fprintf(stderr, "thread_pool's thread %d create failed, retval: %d.\n", v6, v5);
}
while ( a1[1] > v2 );
}
}

canonical_decompiled_code:
void __fastcall func8(_QWORD *a1)
{
unsigned __int64 v2; // rbx
_QWORD *v3; // rax
__int64 v4; // rdi
unsigned int v5; // eax
__int64 v6; // rdx

if ( a1[1] )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = malloc(0x10uLL);
v4 = *a1 + 104 * v2;
v3[1] = v4;
*(_DWORD *)(v4 + 96) = v2;
*v3 = a1;
v5 = thread_create(v4, 0LL, thread_do_job);
if ( v5 )
break;
if ( a1[1] <= ++v2 )
return;
}
v6 = v2++;
fprintf(stderr, "thread_pool's thread %d create failed, retval: %d.\n", v6, v5);
}
while ( a1[1] > v2 );
}
}

original_code:
void thread_pool_run(thread_pool_t *thread_pool)
{
    size_t i;
    thread_info_t *thread_info;
    for(i = 0; i < thread_pool->thread_count; i++) {
 thread_info = (thread_info_t *)malloc(sizeof(thread_info_t));
 thread_info->thread_item = &thread_pool->thread_items[i];
 thread_info->thread_item->id = i;
 thread_info->thread_pool = thread_pool;
 int ret = thread_create(&thread_pool->thread_items[i], ((void *)0), thread_do_job, thread_info);
 if(ret != 0) {
     fprintf(stderr, "thread_pool's thread %d create failed, retval: %d.\n", i, ret);
 }
    }
}

canonical_original_code:
void thread_pool_run(struct _thread_pool *thread_pool)
{
    unsigned long i;
    struct _thread_info *thread_info;
    for(i = 0; i < thread_pool->thread_count; i++) {
 thread_info = (struct _thread_info *)malloc(sizeof(thread_info_t));
 thread_info->thread_item = &thread_pool->thread_items[i];
 thread_info->thread_item->id = i;
 thread_info->thread_pool = thread_pool;
 int ret = thread_create(&thread_pool->thread_items[i], ((void *)0), thread_do_job, thread_info);
 if(ret != 0) {
     fprintf(stderr, "thread_pool's thread %d create failed, retval: %d.\n", i, ret);
 }
    }
}

variable_types: ret int


decompiled_code:
__int64 __fastcall bloom_init(__int64 a1, int a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
void *v10; // rax
_QWORD *v11; // rax
unsigned int v12; // ecx
__int64 v13; // rdi
char *v14; // rsi
__int64 v15; // rdx
char *v16; // rdx
__int64 result; // rax
char v18[24]; // [rsp+20h] [rbp-58h]
__int64 v19; // [rsp+38h] [rbp-40h]
__int64 v20; // [rsp+40h] [rbp-38h]
__int64 v21; // [rsp+48h] [rbp-30h]

v19 = a4;
v20 = a5;
v21 = a6;
if ( a2 )
{
if ( a3 )
{
*(_QWORD *)(a1 + 24) = 0LL;
v10 = malloc(((unsigned int)(a2 - 1) >> 3) + 1);
*(_QWORD *)(a1 + 8) = v10;
if ( v10 )
{
bzero(v10, ((unsigned int)(a2 - 1) >> 3) + 1);
v11 = malloc(8LL * a3);
*(_QWORD *)(a1 + 24) = v11;
if ( v11 )
{
v12 = 24;
v13 = (__int64)&v11[a3];
v14 = &a7;
do
{
while ( v12 <= 0x2F )
{
v15 = v12;
++v11;
v12 += 8;
*(v11 - 1) = *(_QWORD *)&v18[v15];
if ( v11 == (_QWORD *)v13 )
goto LABEL_9;
}
v16 = v14;
++v11;
v14 += 8;
*(v11 - 1) = *(_QWORD *)v16;
}
while ( v11 != (_QWORD *)v13 );
LABEL_9:
*(_DWORD *)a1 = a2;
result = 1LL;
*(_DWORD *)(a1 + 16) = a3;
}
else
{
fwrite("Allocate memory for bf->func failed", 1uLL, 0x23uLL, stderr);
free(*(void **)(a1 + 8));
result = 0LL;
}
}
else
{
fwrite("Allocate memory for bf->bits failed", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("Hash function can't be none", 1uLL, 0x1BuLL, stderr);
result = 0LL;
}
}
else
{
fwrite("Bloom filter size can't be zero", 1uLL, 0x1FuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
void *v10; // rax
_QWORD *v11; // rax
unsigned int v12; // ecx
__int64 v13; // rdi
char *v14; // rsi
__int64 v15; // rdx
char *v16; // rdx
__int64 result; // rax
char v18[24]; // [rsp+20h] [rbp-58h]
__int64 v19; // [rsp+38h] [rbp-40h]
__int64 v20; // [rsp+40h] [rbp-38h]
__int64 v21; // [rsp+48h] [rbp-30h]

v19 = a4;
v20 = a5;
v21 = a6;
if ( a2 )
{
if ( a3 )
{
*(_QWORD *)(a1 + 24) = 0LL;
v10 = malloc(((unsigned int)(a2 - 1) >> 3) + 1);
*(_QWORD *)(a1 + 8) = v10;
if ( v10 )
{
bzero(v10, ((unsigned int)(a2 - 1) >> 3) + 1);
v11 = malloc(8LL * a3);
*(_QWORD *)(a1 + 24) = v11;
if ( v11 )
{
v12 = 24;
v13 = (__int64)&v11[a3];
v14 = &a7;
do
{
while ( v12 <= 0x2F )
{
v15 = v12;
++v11;
v12 += 8;
*(v11 - 1) = *(_QWORD *)&v18[v15];
if ( v11 == (_QWORD *)v13 )
goto LABEL_9;
}
v16 = v14;
++v11;
v14 += 8;
*(v11 - 1) = *(_QWORD *)v16;
}
while ( v11 != (_QWORD *)v13 );
LABEL_9:
*(_DWORD *)a1 = a2;
result = 1LL;
*(_DWORD *)(a1 + 16) = a3;
}
else
{
fwrite("Allocate memory for bf->func failed", 1uLL, 0x23uLL, stderr);
free(*(void **)(a1 + 8));
result = 0LL;
}
}
else
{
fwrite("Allocate memory for bf->bits failed", 1uLL, 0x23uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("Hash function can't be none", 1uLL, 0x1BuLL, stderr);
result = 0LL;
}
}
else
{
fwrite("Bloom filter size can't be zero", 1uLL, 0x1FuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int bloom_init(BF *bf, unsigned int bsize, unsigned int fsize, ...)
{
    if(bsize == 0) {
        fprintf(stderr, "Bloom filter size can't be zero");
 return 0;
    }
    if(fsize == 0) {
        fprintf(stderr, "Hash function can't be none");
 return 0;
    }
    bf->bits = ((void *)0);
    bf->func = ((void *)0);
    bf->bits = (char *)malloc((((bsize - 1) / 8) + 1) * sizeof(char));
    if(bf->bits == ((void *)0)) {
 fprintf(stderr, "Allocate memory for bf->bits failed");
 return 0;
    }
    bzero(bf->bits, (((bsize - 1) / 8) + 1) * sizeof(char));
    bf->func = (hashfunc_t *)malloc(fsize * sizeof(hashfunc_t));
    if(bf->func == ((void *)0)) {
 fprintf(stderr, "Allocate memory for bf->func failed");
 free(bf->bits);
 return 0;
    }
    va_list func_list;
    __builtin_va_start(func_list,fsize);
    int i;
    for(i = 0; i < fsize; i++) {
        bf->func[i] = __builtin_va_arg(func_list,hashfunc_t);
    }
    __builtin_va_end(func_list);
    bf->bsize = bsize;
    bf->fsize = fsize;
    return 1;
}

canonical_original_code:
int bloom_init(struct BF *bf, unsigned int bsize, unsigned int fsize, ...)
{
    if(bsize == 0) {
        fprintf(stderr, "Bloom filter size can't be zero");
 return 0;
    }
    if(fsize == 0) {
        fprintf(stderr, "Hash function can't be none");
 return 0;
    }
    bf->bits = ((void *)0);
    bf->func = ((void *)0);
    bf->bits = (char *)malloc((((bsize - 1) / 8) + 1) * sizeof(char));
    if(bf->bits == ((void *)0)) {
 fprintf(stderr, "Allocate memory for bf->bits failed");
 return 0;
    }
    bzero(bf->bits, (((bsize - 1) / 8) + 1) * sizeof(char));
    bf->func = (unsigned int (**)(char *, unsigned long bytes))malloc(fsize * sizeof(hashfunc_t));
    if(bf->func == ((void *)0)) {
 fprintf(stderr, "Allocate memory for bf->func failed");
 free(bf->bits);
 return 0;
    }
    __builtin_va_list func_list;
    __builtin_va_start(func_list,fsize);
    int i;
    for(i = 0; i < fsize; i++) {
        bf->func[i] = __builtin_va_arg(func_list,hashfunc_t);
    }
    __builtin_va_end(func_list);
    bf->bsize = bsize;
    bf->fsize = fsize;
    return 1;
}

variable_types: struct BF { unsigned int bsize; char *bits; unsigned int fsize; unsigned int (**func)(char *, unsigned long bytes); } *

variable_types:
bsize
unsigned int

variable_types:
fsize
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall bloom_destroy(__int64 a1)
{
void *v2; // rdi
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 24);
if ( v3 )
free(v3);
return 0LL;
}

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

if ( !a1 )
return 0LL;
v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
v3 = *(void **)(a1 + 24);
if ( v3 )
free(v3);
return 0LL;
}

original_code:
int bloom_destroy(BF *bf)
{
    if(bf != ((void *)0)) {
        if(bf->bits != ((void *)0)) {
            free(bf->bits);
        }
        if(bf->func != ((void *)0)) {
            free(bf->func);
        }
    }
    return 0;
}

canonical_original_code:
int bloom_destroy(struct BF *bf)
{
    if(bf != ((void *)0)) {
        if(bf->bits != ((void *)0)) {
            free(bf->bits);
        }
        if(bf->func != ((void *)0)) {
            free(bf->func);
        }
    }
    return 0;
}

user_defined_types: struct BF { unsigned int bsize; char *bits; unsigned int fsize; unsigned int (**func)(char *, unsigned long bytes); }


original_code:
int bloom_add(BF *bf, char *str)
{
    unsigned int i;
    for(i = 0; i < bf->fsize; i++) {
 (bf->bits[bf->func[i](str, strlen(str)) % bf->bsize/8] |= (1<<(bf->func[i](str, strlen(str)) % bf->bsize%8)));
    }
    return 0;
}

canonical_original_code:
int bloom_add(struct BF *bf, char *str)
{
    unsigned int i;
    for(i = 0; i < bf->fsize; i++) {
 (bf->bits[bf->func[i](str, strlen(str)) % bf->bsize/8] |= (1<<(bf->func[i](str, strlen(str)) % bf->bsize%8)));
    }
    return 0;
}

variable_types:
str
char *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall bloom_check(__int64 a1, const char *a2)
{
unsigned int v2; // er14
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
char v6; // dl
__int64 result; // rax

if ( !*(_DWORD *)(a1 + 16) )
return 1LL;
v2 = 0;
while ( 1 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = strlen(a2);
LODWORD(v3) = *(char *)(v3
+ (((*(unsigned int (__fastcall **)(const char *, size_t))(*(_QWORD *)(a1 + 24) + 8LL * v2))(
a2,
v4)
% *(_DWORD *)a1) >> 3));
v5 = strlen(a2);
v6 = ((*(unsigned int (__fastcall **)(const char *, size_t))(*(_QWORD *)(a1 + 24) + 8LL * v2))(a2, v5)
% *(_DWORD *)a1) & 7;
result = ((int)v3 >> v6) & 1;
if ( (((int)v3 >> v6) & 1) == 0 )
break;
if ( *(_DWORD *)(a1 + 16) <= ++v2 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
unsigned int v2; // er14
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
char v6; // dl
__int64 result; // rax

if ( !*(_DWORD *)(a1 + 16) )
return 1LL;
v2 = 0;
while ( 1 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = strlen(a2);
LODWORD(v3) = *(char *)(v3
+ (((*(unsigned int (__fastcall **)(const char *, size_t))(*(_QWORD *)(a1 + 24) + 8LL * v2))(
a2,
v4)
% *(_DWORD *)a1) >> 3));
v5 = strlen(a2);
v6 = ((*(unsigned int (__fastcall **)(const char *, size_t))(*(_QWORD *)(a1 + 24) + 8LL * v2))(a2, v5)
% *(_DWORD *)a1) & 7;
result = ((int)v3 >> v6) & 1;
if ( (((int)v3 >> v6) & 1) == 0 )
break;
if ( *(_DWORD *)(a1 + 16) <= ++v2 )
return 1LL;
}
return result;
}

original_code:
int bloom_check(BF *bf, char *str)
{
    unsigned int i;
    for(i = 0; i < bf->fsize; i++) {
 if(!(bf->bits[bf->func[i](str, strlen(str)) % bf->bsize/8] & (1<<(bf->func[i](str, strlen(str)) % bf->bsize%8)))) return 0;
    }
    return 1;
}

canonical_original_code:
int bloom_check(struct BF *bf, char *str)
{
    unsigned int i;
    for(i = 0; i < bf->fsize; i++) {
 if(!(bf->bits[bf->func[i](str, strlen(str)) % bf->bsize/8] & (1<<(bf->func[i](str, strlen(str)) % bf->bsize%8)))) return 0;
    }
    return 1;
}


original_code:
void dict_destroy(dict_t *dict)
{
    size_t i = 0;
    bucket_elem_t *_c_elem;
    for(i = 0; i < dict->size; i++) {
 _c_elem = dict->table[i].next;
 while(_c_elem != ((void *)0) && dict->table[i].size > 0) {
     dict->table[i].next = _c_elem->next;
     free(_c_elem);
     dict->table[i].size--;
     _c_elem = dict->table[i].next;
 }
    }
    free(dict->table);
}

canonical_original_code:
void dict_destroy(struct _dict *dict)
{
    unsigned long i = 0;
    struct _bucket_elem *_c_elem;
    for(i = 0; i < dict->size; i++) {
 _c_elem = dict->table[i].next;
 while(_c_elem != ((void *)0) && dict->table[i].size > 0) {
     dict->table[i].next = _c_elem->next;
     free(_c_elem);
     dict->table[i].size--;
     _c_elem = dict->table[i].next;
 }
    }
    free(dict->table);
}

variable_types: struct _dict { unsigned long size; struct _bucket { int size; struct _bucket_elem { struct _bucket_elem *next; int klen; void *key; int vlen; void *value; char buffer[]; } *next; } *table; unsigned int (*hash_func)(char *, unsigned long bytes); } *

user_defined_types: struct _dict { unsigned long size; struct _bucket *table; unsigned int (*hash_func)(char *, unsigned long bytes); }

user_defined_types: struct _bucket { int size; struct _bucket_elem *next; }


decompiled_code:
void __fastcall dict_remove(__int64 a1, const void *a2, size_t a3)
{
unsigned int v4; // eax

v4 = dict_index(a1, (__int64)a2, a3);
bucket_remove(*(_QWORD *)(a1 + 8) + 16LL * v4, a2, a3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, const void *a2, size_t a3)
{
unsigned int v4; // eax

v4 = func1(a1, (__int64)a2, a3);
func2(*(_QWORD *)(a1 + 8) + 16LL * v4, a2, a3);
}

original_code:
void dict_remove(dict_t *dict, void *key, size_t bytes)
{
    unsigned int index = _dict_index(dict, key, bytes);
    _bucket_remove(&dict->table[index], key, bytes);
}

canonical_original_code:
void dict_remove(struct _dict *dict, void *key, unsigned long bytes)
{
    unsigned int index = _dict_index(dict, key, bytes);
    _bucket_remove(&dict->table[index], key, bytes);
}

variable_types:
key
void *

variable_types:
bytes
unsigned long

variable_types:
index
unsigned int

user_defined_types: struct _bucket_elem { struct _bucket_elem *next; int klen; void *key; int vlen; void *value; char buffer[]; }


decompiled_code:
__int64 __fastcall open_tcp(__int64 a1, const char *a2, int a3)
{
unsigned int v4; // er12
int v5; // eax
int v6; // ebx
socklen_t v7; // edx
int h_errnop; // [rsp+4h] [rbp-474h] BYREF
struct hostent *result; // [rsp+8h] [rbp-470h] BYREF
struct sockaddr s; // [rsp+10h] [rbp-468h] BYREF
__int64 optval[2]; // [rsp+20h] [rbp-458h] BYREF
struct hostent result_buf; // [rsp+30h] [rbp-448h] BYREF
char buf[1064]; // [rsp+50h] [rbp-428h] BYREF

v4 = 1;
v5 = socket(2, 1, 0);
if ( v5 >= 0 )
{
v6 = v5;
optval[0] = 10LL;
optval[1] = 0LL;
setsockopt(v5, 1, 20, optval, 0x10u);
v4 = gethostbyname_r(a2, &result_buf, buf, 0x400uLL, &result, &h_errnop);
if ( v4 || !result )
{
v4 = 2;
}
else
{
bzero(&s, 0x10uLL);
s.sa_family = 2;
bcopy(*(const void **)result->h_addr_list, &s.sa_data[2], result->h_length);
*(_WORD *)s.sa_data = _bswap_16(a3);
if ( connect(v6, &s, v7) < 0 )
{
v4 = 3;
}
else
{
*(_DWORD *)a1 = v6;
*(_DWORD *)(a1 + 264) = 0;
strcpy((char *)(a1 + 4), a2);
*(_DWORD *)(a1 + 260) = a3;
bzero((void *)(a1 + 268), 0x1000uLL);
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
unsigned int v4; // er12
int v5; // eax
int v6; // ebx
socklen_t v7; // edx
int h_errnop; // [rsp+4h] [rbp-474h] BYREF
struct hostent *result; // [rsp+8h] [rbp-470h] BYREF
struct sockaddr s; // [rsp+10h] [rbp-468h] BYREF
__int64 optval[2]; // [rsp+20h] [rbp-458h] BYREF
struct hostent result_buf; // [rsp+30h] [rbp-448h] BYREF
char buf[1064]; // [rsp+50h] [rbp-428h] BYREF

v4 = 1;
v5 = socket(2, 1, 0);
if ( v5 >= 0 )
{
v6 = v5;
optval[0] = 10LL;
optval[1] = 0LL;
setsockopt(v5, 1, 20, optval, 0x10u);
v4 = gethostbyname_r(a2, &result_buf, buf, 0x400uLL, &result, &h_errnop);
if ( v4 || !result )
{
v4 = 2;
}
else
{
bzero(&s, 0x10uLL);
s.sa_family = 2;
bcopy(*(const void **)result->h_addr_list, &s.sa_data[2], result->h_length);
*(_WORD *)s.sa_data = func0(a3);
if ( connect(v6, &s, v7) < 0 )
{
v4 = 3;
}
else
{
*(_DWORD *)a1 = v6;
*(_DWORD *)(a1 + 264) = 0;
strcpy((char *)(a1 + 4), a2);
*(_DWORD *)(a1 + 260) = a3;
bzero((void *)(a1 + 268), 0x1000uLL);
}
}
}
return v4;
}

original_code:
int open_tcp(network_t *network, char *hostname, int port)
{
    int clientfd, ret, res;
    char buffer[1024];
    struct hostent *hp, hostbuf;
    struct sockaddr_in serveraddr;
    if ((clientfd = socket(2, SOCK_STREAM, 0)) < 0) {
        return 1;
    }
    struct timeval timeout = {10, 0};
    setsockopt(clientfd, 1, 20, (char *)&timeout, sizeof(struct timeval));
    res = gethostbyname_r(hostname, &hostbuf, buffer, sizeof(buffer), &hp, &ret);
    if(res || hp == ((void *)0)) {
        return 2;
    }
    bzero((char *)&serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = 2;
    bcopy((char *)hp->h_addr_list[0], (char *)&serveraddr.sin_addr.s_addr, hp->h_length);
    serveraddr.sin_port = htons(port);
    if (connect(clientfd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0) {
        return 3;
    }
    network->socketfd = clientfd;
    network->len = 0;
    strcpy(network->host, hostname);
    network->port = port;
    bzero(network->buffer, 4096);
    return 0;
}

canonical_original_code:
int open_tcp(struct _network *network, char *hostname, int port)
{
    int clientfd; int ret; int res;
    char buffer[1024];
    struct hostent *hp; struct hostent hostbuf;
    struct sockaddr_in serveraddr;
    if ((clientfd = socket(2, SOCK_STREAM, 0)) < 0) {
        return 1;
    }
    struct timeval timeout = {10, 0};
    setsockopt(clientfd, 1, 20, (char *)&timeout, sizeof(struct timeval));
    res = gethostbyname_r(hostname, &hostbuf, buffer, sizeof(buffer), &hp, &ret);
    if(res || hp == ((void *)0)) {
        return 2;
    }
    bzero((char *)&serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = 2;
    bcopy((char *)hp->h_addr_list[0], (char *)&serveraddr.sin_addr.s_addr, hp->h_length);
    serveraddr.sin_port = htons(port);
    if (connect(clientfd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0) {
        return 3;
    }
    network->socketfd = clientfd;
    network->len = 0;
    strcpy(network->host, hostname);
    network->port = port;
    bzero(network->buffer, 4096);
    return 0;
}

variable_types: struct _network { int socketfd; char host[256]; int port; int len; char buffer[-1]; } *

variable_types:
hostname
char *

variable_types: port int

variable_types: clientfd int

variable_types: res int

variable_types:
buffer
char [1024]

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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

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

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

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


nsend

decompiled_code:
ssize_t __fastcall nsend(int *a1, const void *a2, int a3)
{
return send(*a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int *a1, const void *a2, int a3)
{
return send(*a1, a2, a3, 0);
}

original_code:
int nsend(network_t *network, char *buf, int bytes)
{
    return send(network->socketfd, buf, bytes, 0);
}

canonical_original_code:
int nsend(struct _network *network, char *buf, int bytes)
{
    return send(network->socketfd, buf, bytes, 0);
}

variable_types:
buf
char *

variable_types: bytes int

user_defined_types: struct _network { int socketfd; char host[256]; int port; int len; char buffer[-1]; }


nrecv

decompiled_code:
ssize_t __fastcall nrecv(int *a1, void *a2, int a3)
{
return recv(*a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int *a1, void *a2, int a3)
{
return recv(*a1, a2, a3, 0);
}

original_code:
int nrecv(network_t *network, char *buf, int bytes)
{
    return recv(network->socketfd, buf, bytes, 0);
}

canonical_original_code:
int nrecv(struct _network *network, char *buf, int bytes)
{
    return recv(network->socketfd, buf, bytes, 0);
}


original_code:
int recv_line(network_t *network, char *buf, int limit)
{
    char *p_delm = ((void *)0), *s_offset = ((void *)0);
    int size = 0, b_size = network->len, rest, offset;
    int i;
    bzero(buf, limit);
    do {
        p_delm = strchr(network->buffer, '\n');
        offset = p_delm != ((void *)0) ? (p_delm - network->buffer + 1 > limit - size ? limit - size : p_delm - network->buffer + 1)
    : (network->len > limit - size ? limit - size : network->len);
        rest = network->len - offset;
        if(size > limit) {
            return -1;
        }
        memcpy(buf + size, network->buffer, offset);
 s_offset = network->buffer + offset;
        memmove(network->buffer, s_offset, rest);
        network->buffer[rest] = '\0';
        network->len = rest;
        size += offset;
 ((size <= limit) ? (void) (0) : __assert_fail ("size <= limit", "network.c", 100, __extension__ __PRETTY_FUNCTION__));
        if(size == limit || rest > 0) { return size; }
        bzero(network->buffer, 4096);
        b_size = nrecv(network, network->buffer, 4096);
        network->len = b_size > 0 ? b_size : 0;
    } while(b_size > 0);
    return b_size < 0 ? b_size : size;
}

canonical_original_code:
int recv_line(struct _network *network, char *buf, int limit)
{
    char *p_delm = ((void *)0); char *s_offset = ((void *)0);
    int size = 0; int b_size = network->len; int rest; int offset;
    int i;
    bzero(buf, limit);
    do {
        p_delm = strchr(network->buffer, '\n');
        offset = p_delm != ((void *)0) ? (p_delm - network->buffer + 1 > limit - size ? limit - size : p_delm - network->buffer + 1)
    : (network->len > limit - size ? limit - size : network->len);
        rest = network->len - offset;
        if(size > limit) {
            return -1;
        }
        memcpy(buf + size, network->buffer, offset);
 s_offset = network->buffer + offset;
        memmove(network->buffer, s_offset, rest);
        network->buffer[rest] = '\0';
        network->len = rest;
        size += offset;
 ((size <= limit) ? (void) (0) : __assert_fail ("size <= limit", "network.c", 100, __extension__ __PRETTY_FUNCTION__));
        if(size == limit || rest > 0) { return size; }
        bzero(network->buffer, 4096);
        b_size = nrecv(network, network->buffer, 4096);
        network->len = b_size > 0 ? b_size : 0;
    } while(b_size > 0);
    return b_size < 0 ? b_size : size;
}

variable_types: limit int

variable_types: size int

variable_types: rest int

variable_types: offset int

variable_types: i int


decompiled_code:
int __fastcall close_tcp(int *a1)
{
return close(*a1);
}

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

original_code:
void close_tcp(network_t *network)
{
    close(network->socketfd);
}

canonical_original_code:
void close_tcp(struct _network *network)
{
    close(network->socketfd);
}


decompiled_code:
void __fastcall http_request_destroy(void *s)
{
if ( *((_DWORD *)s + 1223) )
{
free(*((void **)s + 612));
bzero(s, 0x1328uLL);
*((_QWORD *)s + 611) = 0LL;
}
}

original_code:
void http_request_destroy(http_req_t *request)
{
    if(request->enti_body.len != 0) {
 free(request->enti_body.buffer);
 bzero(request, sizeof(http_req_t));
 request->enti_body.len = 0;
        request->enti_body.used = 0;
    }
}

canonical_original_code:
void http_request_destroy(struct _http_request *request)
{
    if(request->enti_body.len != 0) {
 free(request->enti_body.buffer);
 bzero(request, sizeof(http_req_t));
 request->enti_body.len = 0;
        request->enti_body.used = 0;
    }
}

variable_types: struct _http_request { struct _http_request_line { char method[8]; char request_uri[4096]; char http_version[16]; } req_line; struct _http_general_header { char date[128]; } gen_header; struct _http_request_header { char user_agent[128]; char host[128]; char accept[128]; } req_header; struct _http_entity_header { char content_length[128]; char content_type[128]; } enti_header; struct _http_entity_body { int used; int len; char *buffer; } enti_body; } *

user_defined_types: struct _http_request { struct _http_request_line req_line; struct _http_general_header gen_header; struct _http_request_header req_header; struct _http_entity_header enti_header; struct _http_entity_body enti_body; }


decompiled_code:
void __fastcall http_response_destroy(void *s)
{
if ( *((_DWORD *)s + 151) )
{
free(*((void **)s + 76));
bzero(s, 0x268uLL);
*((_QWORD *)s + 75) = 0LL;
}
}

original_code:
void http_response_destroy(http_res_t *response)
{
    if(response->enti_body.len != 0) {
 free(response->enti_body.buffer);
 bzero(response, sizeof(http_res_t));
     response->enti_body.len = 0;
        response->enti_body.used = 0;
    }
}

canonical_original_code:
void http_response_destroy(struct _http_response *response)
{
    if(response->enti_body.len != 0) {
 free(response->enti_body.buffer);
 bzero(response, sizeof(http_res_t));
     response->enti_body.len = 0;
        response->enti_body.used = 0;
    }
}

variable_types: struct _http_response { struct _http_response_line { char http_version[16]; char status_code[8]; char reason_phrase[64]; } res_line; struct _http_general_header { char date[128]; } gen_header; struct _http_response_header { char server[128]; } res_header; struct _http_entity_header { char content_length[128]; char content_type[128]; } enti_header; struct _http_entity_body { int used; int len; char *buffer; } enti_body; } *

user_defined_types: struct _http_response { struct _http_response_line res_line; struct _http_general_header gen_header; struct _http_response_header res_header; struct _http_entity_header enti_header; struct _http_entity_body enti_body; }


original_code:
int http_response_header(http_res_t *res_s, char *header)
{
    char attr[4096], value[4096];
    bzero(attr, 4096);
    bzero(value, 4096);
    sscanf(header, "%[^:]: %[^\n]", attr, value);
    if(strcmp(attr, "Content-Length") == 0) { strcpy(res_s->enti_header.content_length, value); res_s->enti_header.content_length[strlen(res_s->enti_header.content_length) - 1] = '\0'; return 1;};
    return 0;
}

canonical_original_code:
int http_response_header(struct _http_response *res_s, char *header)
{
    char attr[4096]; char value[4096];
    bzero(attr, 4096);
    bzero(value, 4096);
    sscanf(header, "%[^:]: %[^\n]", attr, value);
    if(strcmp(attr, "Content-Length") == 0) { strcpy(res_s->enti_header.content_length, value); res_s->enti_header.content_length[strlen(res_s->enti_header.content_length) - 1] = '\0'; return 1;};
    return 0;
}

variable_types:
header
char *

variable_types:
attr
char [4096]

variable_types:
value
char [4096]

user_defined_types: struct _http_response_line { char http_version[16]; char status_code[8]; char reason_phrase[64]; }

user_defined_types: struct _http_general_header { char date[128]; }

user_defined_types: struct _http_response_header { char server[128]; }

user_defined_types: struct _http_entity_header { char content_length[128]; char content_type[128]; }

user_defined_types: struct _http_entity_body { int used; int len; char *buffer; }


original_code:
int http_create_request(http_req_t *req_s, char *request)
{
    sprintf(request, "%s %s %s\r\n", req_s->req_line.method,
  req_s->req_line.request_uri, req_s->req_line.http_version);
    { if(req_s->gen_header.date != ((void *)0) && strlen(req_s->gen_header.date) != 0) { strcat(request, "Date: "); strcat(request, req_s->gen_header.date); strcat(request, "\r\n"); }};
    { if(req_s->req_header.user_agent != ((void *)0) && strlen(req_s->req_header.user_agent) != 0) { strcat(request, "User-Agent: "); strcat(request, req_s->req_header.user_agent); strcat(request, "\r\n"); }};
    { if(req_s->req_header.host != ((void *)0) && strlen(req_s->req_header.host) != 0) { strcat(request, "Host: "); strcat(request, req_s->req_header.host); strcat(request, "\r\n"); }};
    { if(req_s->req_header.accept != ((void *)0) && strlen(req_s->req_header.accept) != 0) { strcat(request, "Accept: "); strcat(request, req_s->req_header.accept); strcat(request, "\r\n"); }};
    { if(req_s->enti_header.content_length != ((void *)0) && strlen(req_s->enti_header.content_length) != 0) { strcat(request, "Content-Length: "); strcat(request, req_s->enti_header.content_length); strcat(request, "\r\n"); }};
    strcat(request, "\r\n");
    { if(req_s->enti_body.buffer != ((void *)0) && strlen(req_s->enti_body.buffer) != 0) { strcat(request, ""); strcat(request, req_s->enti_body.buffer); strcat(request, "\r\n"); }};
    return 0;
}

canonical_original_code:
int http_create_request(struct _http_request *req_s, char *request)
{
    sprintf(request, "%s %s %s\r\n", req_s->req_line.method,
  req_s->req_line.request_uri, req_s->req_line.http_version);
    { if(req_s->gen_header.date != ((void *)0) && strlen(req_s->gen_header.date) != 0) { strcat(request, "Date: "); strcat(request, req_s->gen_header.date); strcat(request, "\r\n"); }};
    { if(req_s->req_header.user_agent != ((void *)0) && strlen(req_s->req_header.user_agent) != 0) { strcat(request, "User-Agent: "); strcat(request, req_s->req_header.user_agent); strcat(request, "\r\n"); }};
    { if(req_s->req_header.host != ((void *)0) && strlen(req_s->req_header.host) != 0) { strcat(request, "Host: "); strcat(request, req_s->req_header.host); strcat(request, "\r\n"); }};
    { if(req_s->req_header.accept != ((void *)0) && strlen(req_s->req_header.accept) != 0) { strcat(request, "Accept: "); strcat(request, req_s->req_header.accept); strcat(request, "\r\n"); }};
    { if(req_s->enti_header.content_length != ((void *)0) && strlen(req_s->enti_header.content_length) != 0) { strcat(request, "Content-Length: "); strcat(request, req_s->enti_header.content_length); strcat(request, "\r\n"); }};
    strcat(request, "\r\n");
    { if(req_s->enti_body.buffer != ((void *)0) && strlen(req_s->enti_body.buffer) != 0) { strcat(request, ""); strcat(request, req_s->enti_body.buffer); strcat(request, "\r\n"); }};
    return 0;
}

variable_types:
request
char *

user_defined_types: struct _http_request_line { char method[8]; char request_uri[4096]; char http_version[16]; }

user_defined_types: struct _http_request_header { char user_agent[128]; char host[128]; char accept[128]; }