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]; }


repo: yanshuyuan/siteanalyzer

decompiled_code:
__int64 __fastcall http_do_get(__int64 a1, const char *a2)
{
size_t v3; // rax
int v4; // eax
void *v5; // rdi
int v6; // ebp
int v7; // er13
int v8; // ebx
int v9; // eax
int v10; // er14
void *v11; // rax
_BYTE v13[8192]; // [rsp+0h] [rbp-3028h] BYREF
char s[4136]; // [rsp+2000h] [rbp-1028h] BYREF

bzero(s, 0x1000uLL);
sprintf(
s,
"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(s);
v4 = nsend(a1, s, v3);
if ( v4 < 0 )
{
fprintf(stderr, "Http Request failed, error code: %d\n", (unsigned int)v4);
v8 = 1;
}
else
{
v5 = malloc(0xC8000uLL);
*(_QWORD *)(a1 + 46744) = v5;
if ( v5 )
{
*(_DWORD *)(a1 + 46740) = 819200;
bzero(v5, 0xC8000uLL);
v6 = 0;
v7 = 819200;
while ( 1 )
{
bzero(v13, 0x2000uLL);
v9 = nrecv(a1, v13, 4096LL);
v8 = v9;
if ( v9 <= 0 )
break;
v10 = v6 + v9;
if ( v6 + v9 > v7 )
{
v7 *= 2;
v11 = realloc(*(void **)(a1 + 46744), v7);
*(_QWORD *)(a1 + 46744) = v11;
if ( !v11 )
{
*(_DWORD *)(a1 + 46740) = 0;
return 2;
}
*(_DWORD *)(a1 + 46740) = v7;
}
memcpy((void *)(*(_QWORD *)(a1 + 46744) + v6), v13, v8);
v6 = v10;
}
if ( v9 )
v8 = 2;
else
*(_BYTE *)(*(_QWORD *)(a1 + 46744) + v6) = 0;
}
else
{
*(_DWORD *)(a1 + 46740) = 0;
fwrite("Error: allocate memory failed in func 'do_get'.\n", 1uLL, 0x30uLL, stderr);
v8 = 2;
}
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
size_t v3; // rax
int v4; // eax
void *v5; // rdi
int v6; // ebp
int v7; // er13
int v8; // ebx
int v9; // eax
int v10; // er14
void *v11; // rax
_BYTE v13[8192]; // [rsp+0h] [rbp-3028h] BYREF
char s[4136]; // [rsp+2000h] [rbp-1028h] BYREF

bzero(s, 0x1000uLL);
sprintf(
s,
"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(s);
v4 = nsend(a1, s, v3);
if ( v4 < 0 )
{
fprintf(stderr, "Http Request failed, error code: %d\n", (unsigned int)v4);
v8 = 1;
}
else
{
v5 = malloc(0xC8000uLL);
*(_QWORD *)(a1 + 46744) = v5;
if ( v5 )
{
*(_DWORD *)(a1 + 46740) = 819200;
bzero(v5, 0xC8000uLL);
v6 = 0;
v7 = 819200;
while ( 1 )
{
bzero(v13, 0x2000uLL);
v9 = nrecv(a1, v13, 4096LL);
v8 = v9;
if ( v9 <= 0 )
break;
v10 = v6 + v9;
if ( v6 + v9 > v7 )
{
v7 *= 2;
v11 = realloc(*(void **)(a1 + 46744), v7);
*(_QWORD *)(a1 + 46744) = v11;
if ( !v11 )
{
*(_DWORD *)(a1 + 46740) = 0;
return 2;
}
*(_DWORD *)(a1 + 46740) = v7;
}
memcpy((void *)(*(_QWORD *)(a1 + 46744) + v6), v13, v8);
v6 = v10;
}
if ( v9 )
v8 = 2;
else
*(_BYTE *)(*(_QWORD *)(a1 + 46744) + v6) = 0;
}
else
{
*(_DWORD *)(a1 + 46740) = 0;
fwrite("Error: allocate memory failed in func 'do_get'.\n", 1uLL, 0x30uLL, stderr);
v8 = 2;
}
}
return (unsigned int)v8;
}

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: 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:
path
char *

variable_types: size int

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; } *

return_type: int

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

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; }

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:
__int64 __fastcall http_response_status(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-100Ch] BYREF
char v3; // [rsp+10h] [rbp-1008h] BYREF

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

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

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

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; } *

return_type: void

user_defined_types: struct _thread_count { int count; union pthread_mutex_t 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 __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; // ebx

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; // ebx

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(__int64 a1, int a2)
{
unsigned int v2; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v2 = *(_DWORD *)a1 - a2;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int v2; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v2 = *(_DWORD *)a1 - a2;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v2;
}

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 func2(__int64 a1, unsigned __int64 a2)
{
return (char *)func2(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[]; } *

return_type: void *


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

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 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_7;
}
}
else
{
LABEL_7:
if ( v2 - 1 == a2 )
*(_QWORD *)(a1 + 24) = v4;
*v4 = (_QWORD *)*v5;
--*(_DWORD *)(a1 + 8);
free(v5);
}
}
}
}

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

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 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_7;
}
}
else
{
LABEL_7:
if ( v2 - 1 == a2 )
*(_QWORD *)(a1 + 24) = v4;
*v4 = (_QWORD *)*v5;
--*(_DWORD *)(a1 + 8);
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:
void __fastcall list_clear(__int64 a1)
{
while ( *(_DWORD *)(a1 + 8) )
list_erase(a1, 0LL);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
while ( *(_DWORD *)(a1 + 8) )
func3(a1, 0LL);
}

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:
void __fastcall list_destroy(__int64 a1)
{
list_clear(a1);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
func4(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 func6(__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 func7(__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 func8()
{
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 func9(__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(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3; // rbp
__int64 v4; // rbx

v2 = malloc(104 * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return fwrite("Error: allocate memory failed in func 'thread_pool_init'.\n", 1uLL, 0x3AuLL, stderr);
v3 = 0LL;
v4 = 0LL;
if ( a2 )
{
do
{
thread_init(*(_QWORD *)a1 + v3);
++v4;
v3 += 104LL;
}
while ( a2 != v4 );
}
*(_QWORD *)(a1 + 8) = a2;
ts_queue_init(a1 + 144);
sem_init((sem_t *)(a1 + 16), 0, 0);
thread_counter_init(a1 + 48);
thread_counter_init(a1 + 96);
return thread_counter_set(a1 + 96, (unsigned int)a2);
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3; // rbp
__int64 v4; // rbx

v2 = malloc(104 * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return fwrite("Error: allocate memory failed in func 'thread_pool_init'.\n", 1uLL, 0x3AuLL, stderr);
v3 = 0LL;
v4 = 0LL;
if ( a2 )
{
do
{
thread_init(*(_QWORD *)a1 + v3);
++v4;
v3 += 104LL;
}
while ( a2 != v4 );
}
*(_QWORD *)(a1 + 8) = a2;
ts_queue_init(a1 + 144);
sem_init((sem_t *)(a1 + 16), 0, 0);
thread_counter_init(a1 + 48);
thread_counter_init(a1 + 96);
return thread_counter_set(a1 + 96, (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

if ( *(_QWORD *)(a1 + 8) )
{
v1 = 0LL;
do
thread_destroy(*(_QWORD *)a1 + 104 * v1++);
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

if ( *(_QWORD *)(a1 + 8) )
{
v1 = 0LL;
do
thread_destroy(*(_QWORD *)a1 + 104 * v1++);
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 result; // rax

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

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

if ( a1[1] )
{
v1 = 0LL;
do
result = thread_join(*a1 + 104 * v1++);
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 v2[5]; // [rsp+0h] [rbp-28h] 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);
v2[0] = *((_QWORD *)ptr + 1);
v2[1] = v2[3];
printf("threadID: %d start work\n", *(unsigned int *)(v2[0] + 96));
((void (__fastcall *)(__int64 *))v2[2])(v2);
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 v2[5]; // [rsp+0h] [rbp-28h] 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);
v2[0] = *((_QWORD *)ptr + 1);
v2[1] = v2[3];
printf("threadID: %d start work\n", *(unsigned int *)(v2[0] + 96));
((void (__fastcall *)(__int64 *))v2[2])(v2);
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 v1; // rbx
_QWORD *v2; // rcx
__int64 v3; // rax
unsigned int v4; // eax

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

canonical_decompiled_code:
void __fastcall func8(_QWORD *a1)
{
unsigned __int64 v1; // rbx
_QWORD *v2; // rcx
__int64 v3; // rax
unsigned int v4; // eax

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

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 bloom_init(__int64 a1, int a2, unsigned int a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, ...)
{
void *v13; // rdi
void *v14; // rax
__int64 v15; // rax
__int64 result; // rax
_QWORD *v17; // rcx
gcc_va_list va; // [rsp+8h] [rbp-70h] BYREF

if ( a2 )
{
if ( a3 )
{
*(_QWORD *)(a1 + 24) = 0LL;
v13 = malloc(((unsigned int)(a2 - 1) >> 3) + 1);
*(_QWORD *)(a1 + 8) = v13;
if ( v13 )
{
bzero(v13, ((unsigned int)(a2 - 1) >> 3) + 1);
v14 = malloc(8LL * a3);
*(_QWORD *)(a1 + 24) = v14;
if ( v14 )
{
va_start(va, a11);
v15 = 0LL;
do
{
if ( va[0].gp_offset > 0x2F )
{
v17 = va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
}
else
{
v17 = (char *)va[0].reg_save_area + va[0].gp_offset;
va[0].gp_offset += 8;
}
*(_QWORD *)(*(_QWORD *)(a1 + 24) + v15) = *v17;
v15 += 8LL;
}
while ( 8LL * a3 != v15 );
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 16) = a3;
result = 1LL;
}
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 func0(__int64 a1, int a2, unsigned int a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, ...)
{
void *v13; // rdi
void *v14; // rax
__int64 v15; // rax
__int64 result; // rax
_QWORD *v17; // rcx
gcc_va_list va; // [rsp+8h] [rbp-70h] BYREF

if ( a2 )
{
if ( a3 )
{
*(_QWORD *)(a1 + 24) = 0LL;
v13 = malloc(((unsigned int)(a2 - 1) >> 3) + 1);
*(_QWORD *)(a1 + 8) = v13;
if ( v13 )
{
bzero(v13, ((unsigned int)(a2 - 1) >> 3) + 1);
v14 = malloc(8LL * a3);
*(_QWORD *)(a1 + 24) = v14;
if ( v14 )
{
va_start(va, a11);
v15 = 0LL;
do
{
if ( va[0].gp_offset > 0x2F )
{
v17 = va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
}
else
{
v17 = (char *)va[0].reg_save_area + va[0].gp_offset;
va[0].gp_offset += 8;
}
*(_QWORD *)(*(_QWORD *)(a1 + 24) + v15) = *v17;
v15 += 8LL;
}
while ( 8LL * a3 != v15 );
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 16) = a3;
result = 1LL;
}
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; // er13
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
__int64 result; // rax

if ( !*(_DWORD *)(a1 + 16) )
return 1LL;
v2 = 0;
do
{
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);
result = ((int)v3 >> (((*(unsigned int (__fastcall **)(const char *, size_t))(*(_QWORD *)(a1 + 24) + 8LL * v2))(
a2,
v5)
% *(_DWORD *)a1) & 7)) & 1;
if ( !(_DWORD)result )
break;
++v2;
}
while ( *(_DWORD *)(a1 + 16) > v2 );
return result;
}

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

if ( !*(_DWORD *)(a1 + 16) )
return 1LL;
v2 = 0;
do
{
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);
result = ((int)v3 >> (((*(unsigned int (__fastcall **)(const char *, size_t))(*(_QWORD *)(a1 + 24) + 8LL * v2))(
a2,
v5)
% *(_DWORD *)a1) & 7)) & 1;
if ( !(_DWORD)result )
break;
++v2;
}
while ( *(_DWORD *)(a1 + 16) > v2 );
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 func4(__int64 a1, const void *a2, size_t a3)
{
unsigned int v4; // eax

v4 = func2(a1, (__int64)a2, a3);
func3(*(_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)
{
int v4; // eax
unsigned int v5; // ebp
int v6; // ebx
__int64 v8[2]; // [rsp+0h] [rbp-488h] BYREF
struct sockaddr s; // [rsp+10h] [rbp-478h] BYREF
struct hostent result_buf; // [rsp+20h] [rbp-468h] BYREF
struct hostent *result; // [rsp+48h] [rbp-440h] BYREF
char buf[1036]; // [rsp+50h] [rbp-438h] BYREF
int h_errnop[11]; // [rsp+45Ch] [rbp-2Ch] BYREF

v4 = socket(2, 1, 0);
v5 = 1;
if ( v4 >= 0 )
{
v6 = v4;
v8[0] = 10LL;
v8[1] = 0LL;
setsockopt(v4, 1, 20, v8, 0x10u);
v5 = gethostbyname_r(a2, &result_buf, buf, 0x400uLL, &result, h_errnop);
if ( v5 )
{
v5 = 2;
}
else if ( result )
{
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, 0x10u) < 0 )
{
v5 = 3;
}
else
{
*(_DWORD *)a1 = v6;
*(_DWORD *)(a1 + 264) = 0;
strcpy((char *)(a1 + 4), a2);
*(_DWORD *)(a1 + 260) = a3;
bzero((void *)(a1 + 268), 0x1000uLL);
}
}
else
{
v5 = 2;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
int v4; // eax
unsigned int v5; // ebp
int v6; // ebx
__int64 v8[2]; // [rsp+0h] [rbp-488h] BYREF
struct sockaddr s; // [rsp+10h] [rbp-478h] BYREF
struct hostent result_buf; // [rsp+20h] [rbp-468h] BYREF
struct hostent *result; // [rsp+48h] [rbp-440h] BYREF
char buf[1036]; // [rsp+50h] [rbp-438h] BYREF
int h_errnop[11]; // [rsp+45Ch] [rbp-2Ch] BYREF

v4 = socket(2, 1, 0);
v5 = 1;
if ( v4 >= 0 )
{
v6 = v4;
v8[0] = 10LL;
v8[1] = 0LL;
setsockopt(v4, 1, 20, v8, 0x10u);
v5 = gethostbyname_r(a2, &result_buf, buf, 0x400uLL, &result, h_errnop);
if ( v5 )
{
v5 = 2;
}
else if ( result )
{
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, 0x10u) < 0 )
{
v5 = 3;
}
else
{
*(_DWORD *)a1 = v6;
*(_DWORD *)(a1 + 264) = 0;
strcpy((char *)(a1 + 4), a2);
*(_DWORD *)(a1 + 260) = a3;
bzero((void *)(a1 + 268), 0x1000uLL);
}
}
else
{
v5 = 2;
}
}
return v5;
}

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);
}


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);
*((_DWORD *)s + 151) = 0;
*((_DWORD *)s + 150) = 0;
}
}

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; }


decompiled_code:
__int64 __fastcall http_response_header(__int64 a1, const char *a2)
{
unsigned int v2; // edx
char v4[4096]; // [rsp+0h] [rbp-2018h] BYREF
char s[4120]; // [rsp+1000h] [rbp-1018h] BYREF

bzero(s, 0x1000uLL);
bzero(v4, 0x1000uLL);
sscanf(a2, "%[^:]: %[^\n]", s, v4);
v2 = 0;
if ( !strcmp(s, "Content-Length") )
{
strcpy((char *)(a1 + 344), v4);
*(_BYTE *)(a1 + strlen((const char *)(a1 + 344)) + 343) = 0;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
unsigned int v2; // edx
char v4[4096]; // [rsp+0h] [rbp-2018h] BYREF
char s[4120]; // [rsp+1000h] [rbp-1018h] BYREF

bzero(s, 0x1000uLL);
bzero(v4, 0x1000uLL);
sscanf(a2, "%[^:]: %[^\n]", s, v4);
v2 = 0;
if ( !strcmp(s, "Content-Length") )
{
strcpy((char *)(a1 + 344), v4);
*(_BYTE *)(a1 + strlen((const char *)(a1 + 344)) + 343) = 0;
v2 = 1;
}
return v2;
}

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; }


decompiled_code:
__int64 __fastcall http_create_request(__int64 a1, char *a2)
{
const char *v3; // rsi

sprintf(a2, "%s %s %s\r\n", (const char *)a1, (const char *)(a1 + 8), (const char *)(a1 + 4104));
if ( *(_BYTE *)(a1 + 4120) )
{
strcat(a2, "Date: ");
strcat(a2, (const char *)(a1 + 4120));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4248) )
{
strcat(a2, "User-Agent: ");
strcat(a2, (const char *)(a1 + 4248));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4376) )
{
strcat(a2, "Host: ");
strcat(a2, (const char *)(a1 + 4376));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4504) )
{
strcat(a2, "Accept: ");
strcat(a2, (const char *)(a1 + 4504));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4632) )
{
strcat(a2, "Content-Length: ");
strcat(a2, (const char *)(a1 + 4632));
strcat(a2, "\r\n");
}
strcat(a2, "\r\n");
v3 = *(const char **)(a1 + 4896);
if ( v3 && *v3 )
{
strcat(a2, v3);
strcat(a2, "\r\n");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2)
{
const char *v3; // rsi

sprintf(a2, "%s %s %s\r\n", (const char *)a1, (const char *)(a1 + 8), (const char *)(a1 + 4104));
if ( *(_BYTE *)(a1 + 4120) )
{
strcat(a2, "Date: ");
strcat(a2, (const char *)(a1 + 4120));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4248) )
{
strcat(a2, "User-Agent: ");
strcat(a2, (const char *)(a1 + 4248));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4376) )
{
strcat(a2, "Host: ");
strcat(a2, (const char *)(a1 + 4376));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4504) )
{
strcat(a2, "Accept: ");
strcat(a2, (const char *)(a1 + 4504));
strcat(a2, "\r\n");
}
if ( *(_BYTE *)(a1 + 4632) )
{
strcat(a2, "Content-Length: ");
strcat(a2, (const char *)(a1 + 4632));
strcat(a2, "\r\n");
}
strcat(a2, "\r\n");
v3 = *(const char **)(a1 + 4896);
if ( v3 && *v3 )
{
strcat(a2, v3);
strcat(a2, "\r\n");
}
return 0LL;
}

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]; }


decompiled_code:
__int64 __fastcall crawler_crawl(__int64 a1, const char *a2, __int64 a3)
{
unsigned int v5; // ebx
unsigned int v6; // er14
unsigned int v7; // er15
unsigned int v8; // eax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdi
__int64 v14; // [rsp+0h] [rbp-2198h] BYREF
__int64 v15; // [rsp+8h] [rbp-2190h]
char v16[4080]; // [rsp+10h] [rbp-2188h] BYREF
char v17[16]; // [rsp+1000h] [rbp-1198h] BYREF
char v18[64]; // [rsp+1010h] [rbp-1188h] BYREF
char nptr[8]; // [rsp+1050h] [rbp-1148h] BYREF
char src[256]; // [rsp+1058h] [rbp-1140h] BYREF
char v21[4160]; // [rsp+1158h] [rbp-1040h] BYREF

if ( (unsigned int)http_url_parse_s(v17) == 6 )
{
v5 = 6;
v6 = 80;
if ( nptr[0] )
v6 = atoi(nptr);
v14 = 0LL;
v15 = 0LL;
memset(v16, 0, sizeof(v16));
if ( v21[0] )
sprintf((char *)&v14, "%s?%s", src, v21);
else
strcpy((char *)&v14, src);
if ( (unsigned int)http_connect(a1, v18, v6) )
{
fprintf(stderr, "Http connect %s:%d failed.\n", v18, v6);
v5 = 4;
}
else
{
puts(a2);
v7 = http_do_get(a1, &v14);
switch ( v7 )
{
case 0u:
v8 = http_response_status(a1);
if ( v8 == 200 )
{
v12 = http_response_body(a1, &v14, v9, v10, v11, 200LL, v14, v15);
if ( v12 )
{
extract_absolute_link_s(v12, a3, a2);
v5 = v7;
}
else
{
fprintf(
stderr,
"Request %s:%d%s failed, response body is null.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
v5 = 7;
}
}
else
{
fprintf(
stderr,
"Request %s:%d%s failed, Status code: %d.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14,
v8);
v5 = 1;
}
break;
case 1u:
fprintf(stderr, "Request %s:%d%s do_get request failed.\n", v18, v6, (const char *)&v14);
v5 = 2;
break;
case 2u:
fprintf(
stderr,
"Request %s:%d%s do_get receive break.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
v5 = 3;
break;
case 3u:
fprintf(
stderr,
"Request %s:%d%s do_get receive timeout.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
break;
case 4u:
fprintf(
stderr,
"Request %s:%d%s do_get receive overflow.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
v5 = 8;
break;
default:
fprintf(stderr, "Unknown ecode %d.\n", v7);
v5 = 5;
break;
}
http_disconnect(a1);
}
}
else
{
fprintf(stderr, "Unrecognize url: %s\n", a2);
v5 = 5;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int64 a3)
{
unsigned int v5; // ebx
unsigned int v6; // er14
unsigned int v7; // er15
unsigned int v8; // eax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdi
__int64 v14; // [rsp+0h] [rbp-2198h] BYREF
__int64 v15; // [rsp+8h] [rbp-2190h]
char v16[4080]; // [rsp+10h] [rbp-2188h] BYREF
char v17[16]; // [rsp+1000h] [rbp-1198h] BYREF
char v18[64]; // [rsp+1010h] [rbp-1188h] BYREF
char nptr[8]; // [rsp+1050h] [rbp-1148h] BYREF
char src[256]; // [rsp+1058h] [rbp-1140h] BYREF
char v21[4160]; // [rsp+1158h] [rbp-1040h] BYREF

if ( (unsigned int)http_url_parse_s(v17) == 6 )
{
v5 = 6;
v6 = 80;
if ( nptr[0] )
v6 = atoi(nptr);
v14 = 0LL;
v15 = 0LL;
memset(v16, 0, sizeof(v16));
if ( v21[0] )
sprintf((char *)&v14, "%s?%s", src, v21);
else
strcpy((char *)&v14, src);
if ( (unsigned int)http_connect(a1, v18, v6) )
{
fprintf(stderr, "Http connect %s:%d failed.\n", v18, v6);
v5 = 4;
}
else
{
puts(a2);
v7 = http_do_get(a1, &v14);
switch ( v7 )
{
case 0u:
v8 = http_response_status(a1);
if ( v8 == 200 )
{
v12 = http_response_body(a1, &v14, v9, v10, v11, 200LL, v14, v15);
if ( v12 )
{
extract_absolute_link_s(v12, a3, a2);
v5 = v7;
}
else
{
fprintf(
stderr,
"Request %s:%d%s failed, response body is null.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
v5 = 7;
}
}
else
{
fprintf(
stderr,
"Request %s:%d%s failed, Status code: %d.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14,
v8);
v5 = 1;
}
break;
case 1u:
fprintf(stderr, "Request %s:%d%s do_get request failed.\n", v18, v6, (const char *)&v14);
v5 = 2;
break;
case 2u:
fprintf(
stderr,
"Request %s:%d%s do_get receive break.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
v5 = 3;
break;
case 3u:
fprintf(
stderr,
"Request %s:%d%s do_get receive timeout.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
break;
case 4u:
fprintf(
stderr,
"Request %s:%d%s do_get receive overflow.\n",
(const char *)(a1 + 4),
*(unsigned int *)(a1 + 260),
(const char *)&v14);
v5 = 8;
break;
default:
fprintf(stderr, "Unknown ecode %d.\n", v7);
v5 = 5;
break;
}
http_disconnect(a1);
}
}
else
{
fprintf(stderr, "Unrecognize url: %s\n", a2);
v5 = 5;
}
return v5;
}

original_code:
int crawler_crawl(link_crawler_t *crawler, char *url, list_t *link_list)
{
    http_url_t http_url;
    int status = 7;
    if(http_url_parse_s(&http_url, url) == URL_RECOGNIZED) {
 int port = strlen(http_url.port) != 0 ? atoi(http_url.port) : 80;
 char path[4096] = {""};
 strlen(http_url.search) == 0 ? sprintf(path, "%s", http_url.path) : sprintf(path, "%s?%s", http_url.path, http_url.search);
        if(http_connect(&crawler->http_client, http_url.host, port) == 0) {
            int ecode, response_status;
            const char *page = ((void *)0);
     printf("%s\n", url);
            ecode = http_do_get(&crawler->http_client, path);
            switch(ecode) {
            case 0:
                response_status = http_response_status(&crawler->http_client);
                if(response_status == 200) {
                    page = http_response_body(&crawler->http_client);
      if(page != ((void *)0)) {
                        extract_absolute_link_s(page, link_list, url);
                     status = 0;
      } else {
   status = 7;
                        fprintf(stderr, "Request %s:%d%s failed, response body is null.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
      }
                } else {
                    fprintf(stderr, "Request %s:%d%s failed, Status code: %d.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path, response_status);
                    status = 1;
                }
                break;
            case 4:
                fprintf(stderr, "Request %s:%d%s do_get receive overflow.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
                status = 8;
  break;
            case 2:
                fprintf(stderr, "Request %s:%d%s do_get receive break.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
                status = 3;
                break;
     case 3:
  fprintf(stderr, "Request %s:%d%s do_get receive timeout.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
                status = 6;
  break;
            case 1:
                fprintf(stderr, "Request %s:%d%s do_get request failed.\n",
                  http_url.host, port, path);
                status = 2;
                break;
            default:
                fprintf(stderr, "Unknown ecode %d.\n", ecode);
  status = 5;
                break;
            }
     http_disconnect(&crawler->http_client);
        } else {
            fprintf(stderr, "Http connect %s:%d failed.\n", http_url.host, port);
            status = 4;
        }
    } else {
 fprintf(stderr, "Unrecognize url: %s\n", url);
 status = 5;
    }
    return status;
}

canonical_original_code:
int crawler_crawl(struct _link_crawler *crawler, char *url, struct _list *link_list)
{
    struct _http_url http_url;
    int status = 7;
    if(http_url_parse_s(&http_url, url) == URL_RECOGNIZED) {
 int port = strlen(http_url.port) != 0 ? atoi(http_url.port) : 80;
 char path[4096] = {""};
 strlen(http_url.search) == 0 ? sprintf(path, "%s", http_url.path) : sprintf(path, "%s?%s", http_url.path, http_url.search);
        if(http_connect(&crawler->http_client, http_url.host, port) == 0) {
            int ecode; int response_status;
            char *page = ((void *)0);
     printf("%s\n", url);
            ecode = http_do_get(&crawler->http_client, path);
            switch(ecode) {
            case 0:
                response_status = http_response_status(&crawler->http_client);
                if(response_status == 200) {
                    page = http_response_body(&crawler->http_client);
      if(page != ((void *)0)) {
                        extract_absolute_link_s(page, link_list, url);
                     status = 0;
      } else {
   status = 7;
                        fprintf(stderr, "Request %s:%d%s failed, response body is null.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
      }
                } else {
                    fprintf(stderr, "Request %s:%d%s failed, Status code: %d.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path, response_status);
                    status = 1;
                }
                break;
            case 4:
                fprintf(stderr, "Request %s:%d%s do_get receive overflow.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
                status = 8;
  break;
            case 2:
                fprintf(stderr, "Request %s:%d%s do_get receive break.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
                status = 3;
                break;
     case 3:
  fprintf(stderr, "Request %s:%d%s do_get receive timeout.\n",
                  crawler->http_client.connection.host,
                  crawler->http_client.connection.port, path);
                status = 6;
  break;
            case 1:
                fprintf(stderr, "Request %s:%d%s do_get request failed.\n",
                  http_url.host, port, path);
                status = 2;
                break;
            default:
                fprintf(stderr, "Unknown ecode %d.\n", ecode);
  status = 5;
                break;
            }
     http_disconnect(&crawler->http_client);
        } else {
            fprintf(stderr, "Http connect %s:%d failed.\n", http_url.host, port);
            status = 4;
        }
    } else {
 fprintf(stderr, "Unrecognize url: %s\n", url);
 status = 5;
    }
    return status;
}

variable_types: struct _link_crawler { 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; } http_client; } *

variable_types:
url
char *

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

variable_types: struct _http_url { char protocol[16]; char host[64]; char port[8]; char path[256]; char search[4096]; }

variable_types: status int

variable_types: port int

variable_types:
path
char [4096]

variable_types: ecode int

variable_types:
page
char *

user_defined_types: struct _link_crawler { struct _http_client http_client; }

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

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


decompiled_code:
__int64 __fastcall do_exit(_QWORD *a1)
{
printf("threadId: %d\n", *(unsigned int *)(*a1 + 96LL));
thread_set_idle(*a1, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
printf("threadId: %d\n", *(unsigned int *)(*a1 + 96LL));
thread_set_idle(*a1, 0LL);
return 0LL;
}

original_code:
void *do_exit(void *arg)
{
    job_arg_t *thread_arg = (job_arg_t *)arg;
    printf("threadId: %d\n", thread_arg->thread_item->id);
    thread_set_idle(thread_arg->thread_item, 0);
    return 0;
}

canonical_original_code:
void *do_exit(void *arg)
{
    struct _job_arg *thread_arg = (job_arg_t *)arg;
    printf("threadId: %d\n", thread_arg->thread_item->id);
    thread_set_idle(thread_arg->thread_item, 0);
    return 0;
}

variable_types:
arg
void *

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 { 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; }


check

decompiled_code:
__int64 __fastcall check(void *s1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
__int64 result; // rax
int v5; // edx

v1 = strlen((const char *)s1);
v2 = strlen(&domain);
if ( v1 < v2 || (v3 = memcmp(s1, &domain, v2), result = 0LL, !v3) )
{
if ( v1 > 5 )
{
v5 = memcmp((char *)s1 + v1 - 5, ".html", 5uLL);
result = 1LL;
if ( !v5 )
return result;
return memcmp((char *)s1 + v1 - 4, ".htm", 4uLL) == 0;
}
result = 0LL;
if ( v1 == 5 )
return memcmp((char *)s1 + v1 - 4, ".htm", 4uLL) == 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *s1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
__int64 result; // rax
int v5; // edx

v1 = strlen((const char *)s1);
v2 = strlen(&domain);
if ( v1 < v2 || (v3 = memcmp(s1, &domain, v2), result = 0LL, !v3) )
{
if ( v1 > 5 )
{
v5 = memcmp((char *)s1 + v1 - 5, ".html", 5uLL);
result = 1LL;
if ( !v5 )
return result;
return memcmp((char *)s1 + v1 - 4, ".htm", 4uLL) == 0;
}
result = 0LL;
if ( v1 == 5 )
return memcmp((char *)s1 + v1 - 4, ".htm", 4uLL) == 0;
}
return result;
}

original_code:
int check(char *buf)
{
    int len = strlen(buf);
    const int domain_len = strlen(domain);
    if(len >= domain_len && !memcmp(buf, domain, domain_len) == 0) return 0;
    if((len > 5 && memcmp(buf + len - 5, ".html", 5) == 0)
 || (len > 4 && memcmp(buf + len - 4, ".htm", 4) == 0)) return 1;
    return 0;
}

canonical_original_code:
int check(char *buf)
{
    int len = strlen(buf);
    int domain_len = strlen(domain);
    if(len >= domain_len && !memcmp(buf, domain, domain_len) == 0) return 0;
    if((len > 5 && memcmp(buf + len - 5, ".html", 5) == 0)
 || (len > 4 && memcmp(buf + len - 4, ".htm", 4) == 0)) return 1;
    return 0;
}

variable_types:
buf
char *

variable_types: len int


filter

decompiled_code:
__int64 __fastcall filter(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 i; // rbx
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = list_size();
result = bloom_init(
v5,
(unsigned int)(60 * v2),
6LL,
&sdbm_hash,
&sax_hash,
&elf_hash,
&js_hash,
&bkdr_hash,
&djb_hash);
if ( (_DWORD)result )
{
for ( i = list_first(a1); i != list_end(a1); i = list_next(i) )
{
if ( (unsigned int)check((void *)(i + 12)) )
{
if ( !(unsigned int)bloom_check(v5, i + 12) )
{
list_push_back(a2, i + 12, *(int *)(i + 8));
bloom_add(v5, i + 12);
}
}
}
bloom_destroy(v5);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 i; // rbx
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = list_size();
result = bloom_init(
v5,
(unsigned int)(60 * v2),
6LL,
&sdbm_hash,
&sax_hash,
&elf_hash,
&js_hash,
&bkdr_hash,
&djb_hash);
if ( (_DWORD)result )
{
for ( i = list_first(a1); i != list_end(a1); i = list_next(i) )
{
if ( (unsigned int)func1((void *)(i + 12)) )
{
if ( !(unsigned int)bloom_check(v5, i + 12) )
{
list_push_back(a2, i + 12, *(int *)(i + 8));
bloom_add(v5, i + 12);
}
}
}
bloom_destroy(v5);
result = 1LL;
}
return result;
}

original_code:
int filter(list_t *olist, list_t *nlist)
{
    BF bf;
    if(bloom_init(&bf, list_size(olist) * 60, 6, sdbm_hash, sax_hash, elf_hash, js_hash, bkdr_hash, djb_hash)) {
        elem_t *iter;
        for(iter = list_first(olist); iter != list_end(olist); iter = list_next(iter)) {
            if(check(iter->buffer) && !bloom_check(&bf, iter->buffer)) {
                list_push_back(nlist, iter->buffer, iter->len);
                bloom_add(&bf, iter->buffer);
            }
        }
        bloom_destroy(&bf);
 return 1;
    }
    return 0;
}

canonical_original_code:
int filter(struct _list *olist, struct _list *nlist)
{
    struct BF bf;
    if(bloom_init(&bf, list_size(olist) * 60, 6, sdbm_hash, sax_hash, elf_hash, js_hash, bkdr_hash, djb_hash)) {
        struct _elem *iter;
        for(iter = list_first(olist); iter != list_end(olist); iter = list_next(iter)) {
            if(check(iter->buffer) && !bloom_check(&bf, iter->buffer)) {
                list_push_back(nlist, iter->buffer, iter->len);
                bloom_add(&bf, iter->buffer);
            }
        }
        bloom_destroy(&bf);
 return 1;
    }
    return 0;
}

variable_types:
nlist
struct _list *

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

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