main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
_QWORD *v4; // rbx
void (__fastcall *v5)(_QWORD, _QWORD); // rax
__int64 v6; // rax
void (__fastcall *v7)(_QWORD, _QWORD); // rax
__int64 v8; // rax
void (__fastcall *v9)(_QWORD, _QWORD); // rax
__int64 v11; // [rsp+8h] [rbp-80h] BYREF
__m128i v12; // [rsp+10h] [rbp-78h] BYREF
__int128 v13[5]; // [rsp+20h] [rbp-68h] BYREF
int v14; // [rsp+70h] [rbp-18h]

v11 = HTTP_URLTree_create_node("/", hello_handler, envp);
(*(void (__fastcall **)(_QWORD, _QWORD))(v11 + 24))(0LL, 0LL);
fprintf(stdout, "handler:\n");
HTTP_URLTree_destroy_node(v11);
v11 = 0LL;
v12 = _mm_load_si128((const __m128i *)&LC9);
v14 = 0;
v13[0] = (__int128)_mm_load_si128((const __m128i *)&LC10);
v13[1] = 0LL;
v13[2] = 0LL;
v13[3] = 0LL;
v13[4] = 0LL;
fwrite("HTTP_insert_node:\t", 1uLL, 0x12uLL, stdout);
v3 = HTTP_URLTree_insert_node(&v11, &v12, index_handler);
(*(void (__fastcall **)(_QWORD, _QWORD))(v3 + 24))(0LL, 0LL);
v4 = (_QWORD *)v11;
if ( v11 )
{
do
{
fprintf(stdout, "key:\t%s\t%d\n", *(const char **)(v4[2] + 32LL), v4[3] == 0LL);
v4 = (_QWORD *)*v4;
}
while ( v4 );
}
fprintf(stdout, "HTTP_node_value:\t%s\t", v12.m128i_i8);
v5 = (void (__fastcall *)(_QWORD, _QWORD))HTTP_URLTree_node_value(v11, &v12);
v5(0LL, 0LL);
strcpy((char *)v13, "ndex.html");
v12 = _mm_load_si128((const __m128i *)&LC11);
fwrite("HTTP_insert_node:\t", 1uLL, 0x12uLL, stdout);
v6 = HTTP_URLTree_insert_node(&v11, &v12, web_index_handler);
(*(void (__fastcall **)(_QWORD, _QWORD))(v6 + 24))(0LL, 0LL);
fprintf(stdout, "HTTP_node_value:\t%s\t", v12.m128i_i8);
v7 = (void (__fastcall *)(_QWORD, _QWORD))HTTP_URLTree_node_value(v11, &v12);
v7(0LL, 0LL);
v12 = _mm_load_si128((const __m128i *)&LC12);
fwrite("HTTP_insert_node:\t", 1uLL, 0x12uLL, stdout);
v8 = HTTP_URLTree_insert_node(&v11, &v12, web_index_handler);
(*(void (__fastcall **)(_QWORD, _QWORD))(v8 + 24))(0LL, 0LL);
fprintf(stdout, "HTTP_node_value:\t%s\t", v12.m128i_i8);
v9 = (void (__fastcall *)(_QWORD, _QWORD))HTTP_URLTree_node_value(v11, &v12);
v9(0LL, 0LL);
fprintf(stdout, "HTTP_node_value:\t%s\t", "/home");
HTTP_URLTree_node_value(v11, "/home");
HTTP_URLTree_destroy(v11);
return 0;
}

original_code:
int main()
{
 HTTP_URLTree_node *head = HTTP_URLTree_create_node("/",hello_handler);
 fprintf(stdout,"handler:\n",head->handler(((void *)0),((void *)0)));
 HTTP_URLTree_destroy_node(head);
 head = ((void *)0);
 char url[100] = "/demo/http/web/server/index.html";
 fprintf(stdout,"HTTP_insert_node:\t");
 HTTP_URLTree_insert_node(&head,url,index_handler)->handler(((void *)0),((void *)0));
 HTTP_URLTree_node *node = head;
 while(node != ((void *)0))
 {
  fprintf(stdout,"key:\t%s\t%d\n",node->key->content,node->handler == ((void *)0));
  node = node->child;
 }
 fprintf(stdout,"HTTP_node_value:\t%s\t",url);
 HTTP_URLTree_node_value(head,url)(((void *)0),((void *)0));
 strcpy(url,"/demo/http/web/index.html");
 fprintf(stdout,"HTTP_insert_node:\t");
 HTTP_URLTree_insert_node(&head,url,web_index_handler)->handler(((void *)0),((void *)0));
 fprintf(stdout,"HTTP_node_value:\t%s\t",url);
 HTTP_URLTree_node_value(head,url)(((void *)0),((void *)0));
 strcpy(url,"/demo/http/web/");
 fprintf(stdout,"HTTP_insert_node:\t");
 HTTP_URLTree_insert_node(&head,url,web_index_handler)->handler(((void *)0),((void *)0));
 fprintf(stdout,"HTTP_node_value:\t%s\t",url);
 HTTP_URLTree_node_value(head,url)(((void *)0),((void *)0));
 fprintf(stdout,"HTTP_node_value:\t%s\t","/home");
 HTTP_URLTree_node_value(head,"/home");
 HTTP_URLTree_destroy(head);
 return 0;
}

canonical_original_code:
int main()
{
 struct HTTP_Tree_node *head = HTTP_URLTree_create_node("/",hello_handler);
 fprintf(stdout,"handler:\n",head->handler(((void *)0),((void *)0)));
 HTTP_URLTree_destroy_node(head);
 head = ((void *)0);
 char url[100] = "/demo/http/web/server/index.html";
 fprintf(stdout,"HTTP_insert_node:\t");
 HTTP_URLTree_insert_node(&head,url,index_handler)->handler(((void *)0),((void *)0));
 struct HTTP_Tree_node *node = head;
 while(node != ((void *)0))
 {
  fprintf(stdout,"key:\t%s\t%d\n",node->key->content,node->handler == ((void *)0));
  node = node->child;
 }
 fprintf(stdout,"HTTP_node_value:\t%s\t",url);
 HTTP_URLTree_node_value(head,url)(((void *)0),((void *)0));
 strcpy(url,"/demo/http/web/index.html");
 fprintf(stdout,"HTTP_insert_node:\t");
 HTTP_URLTree_insert_node(&head,url,web_index_handler)->handler(((void *)0),((void *)0));
 fprintf(stdout,"HTTP_node_value:\t%s\t",url);
 HTTP_URLTree_node_value(head,url)(((void *)0),((void *)0));
 strcpy(url,"/demo/http/web/");
 fprintf(stdout,"HTTP_insert_node:\t");
 HTTP_URLTree_insert_node(&head,url,web_index_handler)->handler(((void *)0),((void *)0));
 fprintf(stdout,"HTTP_node_value:\t%s\t",url);
 HTTP_URLTree_node_value(head,url)(((void *)0),((void *)0));
 fprintf(stdout,"HTTP_node_value:\t%s\t","/home");
 HTTP_URLTree_node_value(head,"/home");
 HTTP_URLTree_destroy(head);
 return 0;
}

variable_types: struct HTTP_Tree_node { struct HTTP_Tree_node *child; struct HTTP_Tree_node *sibling; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *key; int (*handler)(struct HTTP_Socket { int sfd; struct HTTP_String *buffer; } *, struct HTTP_Socket *); } *

variable_types:
url
char [100]

user_defined_types: struct HTTP_Tree_node { struct HTTP_Tree_node *child; struct HTTP_Tree_node *sibling; struct HTTP_String *key; int (*handler)(struct HTTP_Socket *, struct HTTP_Socket *); }


repo: QMonkey/HTTP-Web-Server

decompiled_code:
__int64 __fastcall HTTP_Socket_set_header(__int64 a1, const char *a2)
{
size_t v2; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = strlen(a2);
HTTP_String_writeline(*(_QWORD *)(a1 + 8), a2, v2);
return 0LL;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v2 = strlen(a2);
HTTP_String_writeline(*(_QWORD *)(a1 + 8), a2, v2);
return 0LL;
}

original_code:
int HTTP_Socket_set_header(HTTP_Socket *http_socket,char *header)
{
 if(http_socket == ((void *)0) || header == ((void *)0))
 {
  return -1;
 }
 int32_t length = strlen(header);
 HTTP_String_writeline(http_socket->buffer,header,length);
 return 0;
}

canonical_original_code:
int HTTP_Socket_set_header(struct HTTP_Socket *http_socket, char *header)
{
 if(http_socket == ((void *)0) || header == ((void *)0))
 {
  return -1;
 }
 int length = strlen(header);
 HTTP_String_writeline(http_socket->buffer,header,length);
 return 0;
}

variable_types: struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *

variable_types:
header
char *

variable_types: length int

return_type: int

user_defined_types: struct HTTP_Socket { int sfd; struct HTTP_String *buffer; }


decompiled_code:
__int64 __fastcall HTTP_Socket_get_header(__int64 a1, const char *a2, _BYTE *a3)
{
unsigned int v4; // er14
size_t v5; // rbx
char *v6; // rax
char i; // dl

HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
while ( 1 )
{
v4 = HTTP_String_readline(*(_QWORD *)(a1 + 8), a3);
if ( !v4 )
break;
v5 = (int)strlen(a2);
if ( !memcmp(a2, a3, v5) )
{
v6 = &a3[v5];
for ( i = a3[v5]; i == 32; ++v6 )
i = v6[1];
if ( i == 58 )
{
v4 -= (_DWORD)v6 + 2 - (_DWORD)a3;
memmove(a3, v6 + 2, (int)v4);
return v4;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, _BYTE *a3)
{
unsigned int v4; // er14
size_t v5; // rbx
char *v6; // rax
char i; // dl

HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
while ( 1 )
{
v4 = HTTP_String_readline(*(_QWORD *)(a1 + 8), a3);
if ( !v4 )
break;
v5 = (int)strlen(a2);
if ( !memcmp(a2, a3, v5) )
{
v6 = &a3[v5];
for ( i = a3[v5]; i == 32; ++v6 )
i = v6[1];
if ( i == 58 )
{
v4 -= (_DWORD)v6 + 2 - (_DWORD)a3;
memmove(a3, v6 + 2, (int)v4);
return v4;
}
}
}
return v4;
}

original_code:
int32_t HTTP_Socket_get_header(HTTP_Socket *http_socket,char *key,char *content)
{
 HTTP_String_seek(http_socket->buffer,0,0);
 int32_t rd = 0;
 int32_t hsize = 0;
 while(rd = HTTP_String_readline(http_socket->buffer,content))
 {
  int32_t size = strlen(key);
  if(!memcmp(key,content,size))
  {
   char *scanner = content + size;
   while(*scanner == ' ')
   {
    ++scanner;
   }
   if(*scanner == ':')
   {
    scanner += 2;
    hsize = rd - (scanner - content);
    memmove(content,scanner,hsize);
    break;
   }
  }
 }
 return hsize;
}

canonical_original_code:
int HTTP_Socket_get_header(struct HTTP_Socket *http_socket, char *key, char *content)
{
 HTTP_String_seek(http_socket->buffer,0,0);
 int rd = 0;
 int hsize = 0;
 while(rd = HTTP_String_readline(http_socket->buffer,content))
 {
  int size = strlen(key);
  if(!memcmp(key,content,size))
  {
   char *scanner = content + size;
   while(*scanner == ' ')
   {
    ++scanner;
   }
   if(*scanner == ':')
   {
    scanner += 2;
    hsize = rd - (scanner - content);
    memmove(content,scanner,hsize);
    break;
   }
  }
 }
 return hsize;
}

variable_types:
key
char *

variable_types:
content
char *

variable_types: rd int

variable_types: hsize int

variable_types: size int

variable_types:
scanner
char *

user_defined_types: struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; }


decompiled_code:
__int64 __fastcall HTTP_Socket_set_content(__int64 a1, const char *a2)
{
unsigned int v2; // er12

v2 = strlen(a2);
HTTP_String_writeline(*(_QWORD *)(a1 + 8), &unk_1ED, 0LL);
HTTP_String_write(*(_QWORD *)(a1 + 8), a2, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
unsigned int v2; // er12

v2 = strlen(a2);
HTTP_String_writeline(*(_QWORD *)(a1 + 8), &unk_1ED, 0LL);
HTTP_String_write(*(_QWORD *)(a1 + 8), a2, v2);
return 0LL;
}

original_code:
int HTTP_Socket_set_content(HTTP_Socket *http_socket,char *content)
{
 int32_t length = strlen(content);
 HTTP_String_writeline(http_socket->buffer,"",0);
 HTTP_String_write(http_socket->buffer,content,length);
 return 0;
}

canonical_original_code:
int HTTP_Socket_set_content(struct HTTP_Socket *http_socket, char *content)
{
 int length = strlen(content);
 HTTP_String_writeline(http_socket->buffer,"",0);
 HTTP_String_write(http_socket->buffer,content,length);
 return 0;
}


decompiled_code:
__int64 __fastcall HTTP_Socket_get_content(__int64 a1, __int64 a2)
{
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
while ( (unsigned int)HTTP_String_readline(*(_QWORD *)(a1 + 8), a2) )
;
return HTTP_String_read(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
HTTP_String_seek(*(_QWORD *)(a1 + 8), 0LL, 0LL);
while ( (unsigned int)HTTP_String_readline(*(_QWORD *)(a1 + 8), a2) )
;
return HTTP_String_read(*(_QWORD *)(a1 + 8), a2);
}

original_code:
int32_t HTTP_Socket_get_content(HTTP_Socket *http_socket,char *content)
{
 HTTP_String_seek(http_socket->buffer,0,0);
 while(HTTP_String_readline(http_socket->buffer,content));
 return HTTP_String_read(http_socket->buffer,content);
}

canonical_original_code:
int HTTP_Socket_get_content(struct HTTP_Socket *http_socket, char *content)
{
 HTTP_String_seek(http_socket->buffer,0,0);
 while(HTTP_String_readline(http_socket->buffer,content));
 return HTTP_String_read(http_socket->buffer,content);
}


decompiled_code:
__int64 __fastcall HTTP_Socket_destroy(void *ptr, int a2)
{
if ( !ptr )
return 0xFFFFFFFFLL;
shutdown(*(_DWORD *)ptr, a2);
HTTP_String_destroy(*((_QWORD *)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr, int a2)
{
if ( !ptr )
return 0xFFFFFFFFLL;
shutdown(*(_DWORD *)ptr, a2);
HTTP_String_destroy(*((_QWORD *)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int HTTP_Socket_destroy(HTTP_Socket *http_socket,int how)
{
 if(http_socket == ((void *)0))
 {
  return -1;
 }
 shutdown(http_socket->sfd,how);
 HTTP_String_destroy(http_socket->buffer);
 free(http_socket);
 return 0;
}

canonical_original_code:
int HTTP_Socket_destroy(struct HTTP_Socket *http_socket, int how)
{
 if(http_socket == ((void *)0))
 {
  return -1;
 }
 shutdown(http_socket->sfd,how);
 HTTP_String_destroy(http_socket->buffer);
 free(http_socket);
 return 0;
}

variable_types: how int


decompiled_code:
__int64 __fastcall HTTP_Param_node_value3(_QWORD *a1, __int64 a2, unsigned int a3)
{
_QWORD *v4; // rbx
int v5; // eax

if ( !a1 )
return 0LL;
v4 = a1;
while ( 1 )
{
v5 = HTTP_String_strcmp(*v4, a2, a3);
if ( v5 > 0 )
return 0LL;
if ( !v5 )
break;
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0LL;
}
return v4[1];
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, unsigned int a3)
{
_QWORD *v4; // rbx
int v5; // eax

if ( !a1 )
return 0LL;
v4 = a1;
while ( 1 )
{
v5 = HTTP_String_strcmp(*v4, a2, a3);
if ( v5 > 0 )
return 0LL;
if ( !v5 )
break;
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0LL;
}
return v4[1];
}

original_code:
HTTP_String* HTTP_Param_node_value3(HTTP_Param_node *head,char *key,int32_t size)
{
 if(head == ((void *)0))
 {
  return ((void *)0);
 }
 int res = HTTP_String_strcmp(head->key,key,size);
 if(res > 0)
 {
  return ((void *)0);
 }
 if(res == 0)
 {
  return head->value;
 }
 return HTTP_Param_node_value3(head->next,key,size);
}

canonical_original_code:
struct HTTP_String *HTTP_Param_node_value3(struct HTTP_param_linkedlist_node *head, char *key, int size)
{
 if(head == ((void *)0))
 {
  return ((void *)0);
 }
 int res = HTTP_String_strcmp(head->key,key,size);
 if(res > 0)
 {
  return ((void *)0);
 }
 if(res == 0)
 {
  return head->value;
 }
 return HTTP_Param_node_value3(head->next,key,size);
}

variable_types: struct HTTP_param_linkedlist_node { struct HTTP_String *key; struct HTTP_String *value; struct HTTP_param_linkedlist_node *next; } *

variable_types: res int

return_type: struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *


decompiled_code:
__int64 __fastcall HTTP_Param_node_value(_QWORD *a1, __int64 a2)
{
unsigned int v2; // eax

v2 = HTTP_String_capacity(a2);
return HTTP_Param_node_value3(a1, *(_QWORD *)(a2 + 32), v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
unsigned int v2; // eax

v2 = HTTP_String_capacity(a2);
return func0(a1, *(_QWORD *)(a2 + 32), v2);
}

original_code:
HTTP_String* HTTP_Param_node_value(HTTP_Param_node *head,HTTP_String *key)
{
 return HTTP_Param_node_value3(head,key->content,HTTP_String_capacity(key));
}

canonical_original_code:
struct HTTP_String *HTTP_Param_node_value(struct HTTP_param_linkedlist_node *head, struct HTTP_String *key)
{
 return HTTP_Param_node_value3(head,key->content,HTTP_String_capacity(key));
}

variable_types:
key
struct HTTP_String *

user_defined_types: struct HTTP_param_linkedlist_node { struct HTTP_String *key; struct HTTP_String *value; struct HTTP_param_linkedlist_node *next; }


decompiled_code:
__int64 __fastcall HTTP_Param_destroy_node(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_String_destroy(*(_QWORD *)ptr);
HTTP_String_destroy(*((_QWORD *)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_String_destroy(*(_QWORD *)ptr);
HTTP_String_destroy(*((_QWORD *)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int HTTP_Param_destroy_node(HTTP_Param_node *node)
{
 if(node == ((void *)0))
 {
  return -1;
 }
 HTTP_String_destroy(node->key);
 HTTP_String_destroy(node->value);
 free(node);
 return 0;
}

canonical_original_code:
int HTTP_Param_destroy_node(struct HTTP_param_linkedlist_node *node)
{
 if(node == ((void *)0))
 {
  return -1;
 }
 HTTP_String_destroy(node->key);
 HTTP_String_destroy(node->value);
 free(node);
 return 0;
}

variable_types: struct HTTP_param_linkedlist_node { struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *key; struct HTTP_String *value; struct HTTP_param_linkedlist_node *next; } *


decompiled_code:
__int64 __fastcall HTTP_Param_pop(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = (_QWORD *)v2[2];
HTTP_Param_destroy_node(v2);
result = 0LL;
*a1 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = (_QWORD *)v2[2];
func2(v2);
result = 0LL;
*a1 = v3;
return result;
}

original_code:
int HTTP_Param_pop(HTTP_Param_node **head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_Param_node *node = (*head)->next;
 HTTP_Param_destroy_node(*head);
 *head = node;
 return 0;
}

canonical_original_code:
int HTTP_Param_pop(struct HTTP_param_linkedlist_node **head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 struct HTTP_param_linkedlist_node *node = (*head)->next;
 HTTP_Param_destroy_node(*head);
 *head = node;
 return 0;
}

variable_types: struct HTTP_param_linkedlist_node { struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *key; struct HTTP_String *value; struct HTTP_param_linkedlist_node *next; } **


decompiled_code:
__int64 __fastcall HTTP_Param_destroy(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_Param_destroy(*((void **)ptr + 2));
HTTP_Param_destroy_node(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
func4(*((void **)ptr + 2));
func2(ptr);
return 0LL;
}

original_code:
int HTTP_Param_destroy(HTTP_Param_node *head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_Param_destroy(head->next);
 HTTP_Param_destroy_node(head);
 return 0;
}

canonical_original_code:
int HTTP_Param_destroy(struct HTTP_param_linkedlist_node *head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_Param_destroy(head->next);
 HTTP_Param_destroy_node(head);
 return 0;
}


decompiled_code:
_BOOL8 __fastcall HTTP_File_is_exists(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 != -1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 != -1 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
int HTTP_File_is_exists(char *path)
{
 struct stat st;
 return stat(path,&st) != -1 && ((((st.st_mode)) & 0170000) == (0100000));
}

variable_types:
path
char *

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

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


decompiled_code:
__int64 __fastcall HTTP_File_read_all(__int64 a1, const char *a2)
{
unsigned int v2; // er12
int v3; // er13
int v4; // eax
_BYTE v6[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( !a1 || !HTTP_File_is_exists(a2) )
return (unsigned int)-1;
v2 = 0;
v3 = open(a2, 0);
while ( 1 )
{
v4 = read(v3, v6, 0x1000uLL);
if ( v4 <= 0 )
break;
v2 += v4;
HTTP_String_write(a1, v6, (unsigned int)v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
unsigned int v2; // er12
int v3; // er13
int v4; // eax
_BYTE v6[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( !a1 || !func0(a2) )
return (unsigned int)-1;
v2 = 0;
v3 = open(a2, 0);
while ( 1 )
{
v4 = read(v3, v6, 0x1000uLL);
if ( v4 <= 0 )
break;
v2 += v4;
HTTP_String_write(a1, v6, (unsigned int)v4);
}
return v2;
}

original_code:
int32_t HTTP_File_read_all(HTTP_String *buffer,char *path)
{
 if(buffer == ((void *)0) || !HTTP_File_is_exists(path))
 {
  return -1;
 }
 int32_t sum = 0;
 char buf[4096];
 int fd = open(path,00);
 int rd = 0;
 while((rd = read(fd,buf,4096)) > 0)
 {
  HTTP_String_write(buffer,buf,rd);
  sum += rd;
 }
 return sum;
}

canonical_original_code:
int HTTP_File_read_all(struct HTTP_String *buffer, char *path)
{
 if(buffer == ((void *)0) || !HTTP_File_is_exists(path))
 {
  return -1;
 }
 int sum = 0;
 char buf[4096];
 int fd = open(path,00);
 int rd = 0;
 while((rd = read(fd,buf,4096)) > 0)
 {
  HTTP_String_write(buffer,buf,rd);
  sum += rd;
 }
 return sum;
}

variable_types: struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *

variable_types: sum int

variable_types:
buf
char [4096]

variable_types: fd int


decompiled_code:
__int64 HTTP_Router_init()
{
HTTP_URLTree_insert_node(&head, "/html/", &index_handler);
HTTP_URLTree_insert_node(&head, "/html/index.html", &index_handler);
HTTP_URLTree_insert_node(&head, "/html/signIn.html", &signin_handler);
HTTP_URLTree_insert_node(&head, "/html/signUp.html", &signup_handler);
HTTP_URLTree_insert_node(&head, "/html/verifySignIn", &verify_signin_handler);
return HTTP_URLTree_insert_node(&head, "/html/verifySignUp", &verify_signup_handler);
}

canonical_decompiled_code:
__int64 func0()
{
HTTP_URLTree_insert_node(&head, "/html/", &index_handler);
HTTP_URLTree_insert_node(&head, "/html/index.html", &index_handler);
HTTP_URLTree_insert_node(&head, "/html/signIn.html", &signin_handler);
HTTP_URLTree_insert_node(&head, "/html/signUp.html", &signup_handler);
HTTP_URLTree_insert_node(&head, "/html/verifySignIn", &verify_signin_handler);
return HTTP_URLTree_insert_node(&head, "/html/verifySignUp", &verify_signup_handler);
}

original_code:
int HTTP_Router_init()
{
 HTTP_URLTree_insert_node(&head,"/html/",index_handler);
 HTTP_URLTree_insert_node(&head,"/html/index.html",index_handler);
 HTTP_URLTree_insert_node(&head,"/html/signIn.html",signin_handler);
 HTTP_URLTree_insert_node(&head,"/html/signUp.html",signup_handler);
 HTTP_URLTree_insert_node(&head,"/html/verifySignIn",verify_signin_handler);
 HTTP_URLTree_insert_node(&head,"/html/verifySignUp",verify_signup_handler);
}


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

result = (void *)HTTP_URLTree_node_value(head, a1);
if ( !result )
result = &default_handler;
return result;
}

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

result = (void *)HTTP_URLTree_node_value(head, a1);
if ( !result )
result = &default_handler;
return result;
}

original_code:
HTTP_Handler HTTP_Router_route(char *url)
{
 int (*handler)(HTTP_Socket*,HTTP_Socket*) = HTTP_URLTree_node_value(head,url);
 return handler != ((void *)0) ? handler : default_handler;
}

canonical_original_code:
int (*HTTP_Router_route(char *url))(struct HTTP_Socket *, struct HTTP_Socket *)
{
 int (*handler)(struct HTTP_Socket *, struct HTTP_Socket *) = HTTP_URLTree_node_value(head,url);
 return handler != ((void *)0) ? handler : default_handler;
}

variable_types:
url
char *

variable_types: int (*)(struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *, struct HTTP_Socket *)


decompiled_code:
__int64 HTTP_Router_destroy()
{
return HTTP_URLTree_destroy(head);
}

canonical_decompiled_code:
__int64 func2()
{
return HTTP_URLTree_destroy(head);
}

original_code:
int HTTP_Router_destroy()
{
 return HTTP_URLTree_destroy(head);
}


decompiled_code:
__int64 __fastcall HTTP_Engine_render(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)HTTP_File_read_all(*(_QWORD *)(a1 + 8)) == -1 )
return 0xFFFFFFFFLL;
HTTP_Response_flush(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)HTTP_File_read_all(*(_QWORD *)(a1 + 8)) == -1 )
return 0xFFFFFFFFLL;
HTTP_Response_flush(a1);
return 0LL;
}

original_code:
int HTTP_Engine_render(HTTP_Socket *response,char *path,HTTP_Param_node *args)
{
 if(response == ((void *)0) || path == ((void *)0) || HTTP_File_read_all(response->buffer,path) == -1)
 {
  return -1;
 }
 HTTP_Response_flush(response);
 return 0;
}

canonical_original_code:
int HTTP_Engine_render(struct HTTP_Socket *response, char *path, struct HTTP_param_linkedlist_node *args)
{
 if(response == ((void *)0) || path == ((void *)0) || HTTP_File_read_all(response->buffer,path) == -1)
 {
  return -1;
 }
 HTTP_Response_flush(response);
 return 0;
}

variable_types: struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *


decompiled_code:
__int64 __fastcall HTTP_Response_flush(__int64 a1)
{
int v1; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = HTTP_String_capacity(*(_QWORD *)(a1 + 8));
send(*(_DWORD *)a1, *(const void **)(*(_QWORD *)(a1 + 8) + 32LL), v1, 64);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = HTTP_String_capacity(*(_QWORD *)(a1 + 8));
send(*(_DWORD *)a1, *(const void **)(*(_QWORD *)(a1 + 8) + 32LL), v1, 64);
return 0LL;
}

original_code:
int HTTP_Response_flush(HTTP_Socket *response)
{
 if(response == ((void *)0))
 {
  return -1;
 }
 send(response->sfd,response->buffer->content,HTTP_String_capacity(response->buffer),MSG_DONTWAIT);
 return 0;
}

canonical_original_code:
int HTTP_Response_flush(struct HTTP_Socket *response)
{
 if(response == ((void *)0))
 {
  return -1;
 }
 send(response->sfd,response->buffer->content,HTTP_String_capacity(response->buffer),MSG_DONTWAIT);
 return 0;
}


decompiled_code:
void HTTP_Response_set_param()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
int HTTP_Response_set_param(HTTP_Socket *response,HTTP_String *key,HTTP_String *value)
{
}

canonical_original_code:
int HTTP_Response_set_param(struct HTTP_Socket *response, struct HTTP_String *key, struct HTTP_String *value)
{
}

variable_types:
value
struct HTTP_String *


decompiled_code:
// attributes: thunk
__int64 HTTP_Response_set_header()
{
return HTTP_Socket_set_header();
}

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

original_code:
int HTTP_Response_set_header(HTTP_Socket *response,char *header)
{
 return HTTP_Socket_set_header(response,header);
}

canonical_original_code:
int HTTP_Response_set_header(struct HTTP_Socket *response, char *header)
{
 return HTTP_Socket_set_header(response,header);
}

variable_types:
header
char *


decompiled_code:
// attributes: thunk
__int64 HTTP_Response_set_content()
{
return HTTP_Socket_set_content();
}

canonical_decompiled_code:
__int64 func3()
{
return HTTP_Socket_set_content();
}

original_code:
int HTTP_Response_set_content(HTTP_Socket *response,char *content)
{
 return HTTP_Socket_set_content(response,content);
}

canonical_original_code:
int HTTP_Response_set_content(struct HTTP_Socket *response, char *content)
{
 return HTTP_Socket_set_content(response,content);
}

variable_types:
content
char *


proc

decompiled_code:
void *__fastcall proc(void *a1)
{
__int64 v1; // rbp
int v2; // eax
__int128 v4; // [rsp+0h] [rbp-3F8h] BYREF
char v5[984]; // [rsp+10h] [rbp-3E8h] BYREF

v1 = HTTP_Socket_create(a1);
v4 = 0LL;
memset(v5, 0, sizeof(v5));
HTTP_Request_init(v1);
HTTP_String_read(*(_QWORD *)(v1 + 8), &v4);
write(1, &v4, 0x3E8uLL);
v2 = HTTP_Socket_get_header(v1, "Accept", &v4);
write(1, &v4, v2);
fputc(10, stdout);
HTTP_Socket_destroy(v1, 2LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v1; // rbp
int v2; // eax
__int128 v4; // [rsp+0h] [rbp-3F8h] BYREF
char v5[984]; // [rsp+10h] [rbp-3E8h] BYREF

v1 = HTTP_Socket_create(a1);
v4 = 0LL;
memset(v5, 0, sizeof(v5));
HTTP_Request_init(v1);
HTTP_String_read(*(_QWORD *)(v1 + 8), &v4);
write(1, &v4, 0x3E8uLL);
v2 = HTTP_Socket_get_header(v1, "Accept", &v4);
write(1, &v4, v2);
fputc(10, stdout);
HTTP_Socket_destroy(v1, 2LL);
return 0LL;
}

original_code:
void* proc(void *arg)
{
 int cfd = (int)arg;
 HTTP_Socket *http_socket = HTTP_Socket_create(cfd);
 char content[1000] = {0};
 HTTP_Request_init(http_socket);
 HTTP_String_read(http_socket->buffer,content);
 write(1,content,1000);
 int32_t size = HTTP_Socket_get_header(http_socket,"Accept",content);
 write(1,content,size);
 fprintf(stdout,"\n");
 HTTP_Socket_destroy(http_socket,SHUT_RDWR);
 return ((void *)0);
}

canonical_original_code:
void *proc(void *arg)
{
 int cfd = (int)arg;
 struct HTTP_Socket *http_socket = HTTP_Socket_create(cfd);
 char content[1000] = {0};
 HTTP_Request_init(http_socket);
 HTTP_String_read(http_socket->buffer,content);
 write(1,content,1000);
 int size = HTTP_Socket_get_header(http_socket,"Accept",content);
 write(1,content,size);
 fprintf(stdout,"\n");
 HTTP_Socket_destroy(http_socket,SHUT_RDWR);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: cfd int

variable_types:
content
char [1000]

variable_types: size int

return_type: void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v5; // ebx
pthread_t *v6; // rax
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v3 = socket(2, 1, 0);
if ( v3 != -1 )
{
v4 = v3;
v7[0] = 0LL;
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = _bswap_16_constprop_0("0.0.0.0", &v7[0].sa_data[2]);
inet_aton("0.0.0.0", (struct in_addr *)&v7[0].sa_data[2]);
if ( bind(v4, v7, 0x10u) != -1 )
{
if ( listen(v4, 100) != -1 )
{
while ( 1 )
{
v5 = accept(v4, 0LL, 0LL);
if ( v5 == -1 )
{
perror("accept");
}
else
{
v6 = (pthread_t *)malloc(8uLL);
pthread_create(v6, 0LL, proc, (void *)v5);
}
}
}
perror("listen");
exit(1);
}
perror("bind");
exit(1);
}
perror("socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int v5; // ebx
pthread_t *v6; // rax
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v3 = socket(2, 1, 0);
if ( v3 != -1 )
{
v4 = v3;
v7[0] = 0LL;
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = func1("0.0.0.0", &v7[0].sa_data[2]);
inet_aton("0.0.0.0", (struct in_addr *)&v7[0].sa_data[2]);
if ( bind(v4, v7, 0x10u) != -1 )
{
if ( listen(v4, 100) != -1 )
{
while ( 1 )
{
v5 = accept(v4, 0LL, 0LL);
if ( v5 == -1 )
{
perror("accept");
}
else
{
v6 = (pthread_t *)malloc(8uLL);
pthread_create(v6, 0LL, proc, (void *)v5);
}
}
}
perror("listen");
exit(1);
}
perror("bind");
exit(1);
}
perror("socket");
exit(1);
}

original_code:
int main()
{
 int sfd = socket(2,SOCK_STREAM,0);
 if(sfd == -1)
 {
  perror("socket");
  exit(1);
 }
 struct sockaddr_in addr;
 memset(&addr,0,sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(9999);
 inet_aton("0.0.0.0",&addr.sin_addr);
 if(bind(sfd,(struct sockaddr*)&addr,sizeof(addr)) == -1)
 {
  perror("bind");
  exit(1);
 }
 if(listen(sfd,100) == -1)
 {
  perror("listen");
  exit(1);
 }
 char buffer[1000] = {0};
 while(1)
 {
  int cfd = accept(sfd,((void *)0),((void *)0));
  if(cfd == -1)
  {
   perror("accept");
   continue;
  }
  pthread_create(malloc(sizeof(pthread_t)),((void *)0),proc,(void*)cfd);
 }
 close(sfd);
 return 0;
}

canonical_original_code:
int main()
{
 int sfd = socket(2,SOCK_STREAM,0);
 if(sfd == -1)
 {
  perror("socket");
  exit(1);
 }
 struct sockaddr_in addr;
 memset(&addr,0,sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(9999);
 inet_aton("0.0.0.0",&addr.sin_addr);
 if(bind(sfd,(struct sockaddr *)&addr,sizeof(addr)) == -1)
 {
  perror("bind");
  exit(1);
 }
 if(listen(sfd,100) == -1)
 {
  perror("listen");
  exit(1);
 }
 char buffer[1000] = {0};
 while(1)
 {
  int cfd = accept(sfd,((void *)0),((void *)0));
  if(cfd == -1)
  {
   perror("accept");
   continue;
  }
  pthread_create(malloc(sizeof(pthread_t)),((void *)0),proc,(void *)cfd);
 }
 close(sfd);
 return 0;
}

variable_types: sfd int

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

variable_types:
buffer
char [1000]

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


decompiled_code:
__int64 __fastcall signup_handler(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post_isra_0(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
do_get_constprop_0_isra_0(a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
func1(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
func0(a2);
result = 0LL;
}
return result;
}

original_code:
int signup_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

canonical_original_code:
int signup_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

variable_types:
response
struct HTTP_Socket *


decompiled_code:
__int64 __fastcall HTTP_replacer_insert(_QWORD **a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rdi

if ( !a1 )
return 0LL;
while ( 1 )
{
v4 = *a1;
if ( *v4 == a2 )
break;
a1 = (_QWORD **)(v4 + 3);
}
v4[1] = a3;
HTTP_String_adjust_to(v4[2], a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rdi

if ( !a1 )
return 0LL;
while ( 1 )
{
v4 = *a1;
if ( *v4 == a2 )
break;
a1 = (_QWORD **)(v4 + 3);
}
v4[1] = a3;
HTTP_String_adjust_to(v4[2], a4);
return 0LL;
}

original_code:
HTTP_replacer_node* HTTP_replacer_insert(HTTP_replacer_node **head,
  char *begin,char *end,HTTP_String *value)
{
 if(head == ((void *)0))
 {
  return ((void *)0);
 }
 HTTP_replacer_node *node = ((void *)0);
 if((*head)->begin == begin)
 {
  (*head)->end = end;
  HTTP_String_adjust_to((*head)->value,value);
 }
 else if((*head)->begin < 0)
 {
  node = HTTP_replacer_create(begin,end,value);
  node->next = *head;
  *head = node;
 }
 else
 {
  node = HTTP_replacer_insert(&(*head)->next,begin,end,value);
 }
 return node;
}

canonical_original_code:
struct HTTP_replacer_linkedlist_node *HTTP_replacer_insert(struct HTTP_replacer_linkedlist_node **head, char *begin, char *end, struct HTTP_String *value)
{
 if(head == ((void *)0))
 {
  return ((void *)0);
 }
 struct HTTP_replacer_linkedlist_node *node = ((void *)0);
 if((*head)->begin == begin)
 {
  (*head)->end = end;
  HTTP_String_adjust_to((*head)->value,value);
 }
 else if((*head)->begin < 0)
 {
  node = HTTP_replacer_create(begin,end,value);
  node->next = *head;
  *head = node;
 }
 else
 {
  node = HTTP_replacer_insert(&(*head)->next,begin,end,value);
 }
 return node;
}

variable_types:
head
struct HTTP_replacer_linkedlist_node **

variable_types:
begin
char *

variable_types:
end
char *

variable_types: struct HTTP_replacer_linkedlist_node { char *begin; char *end; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *value; struct HTTP_replacer_linkedlist_node *next; } *

user_defined_types: struct HTTP_replacer_linkedlist_node { char *begin; char *end; struct HTTP_String *value; struct HTTP_replacer_linkedlist_node *next; }


decompiled_code:
__int64 __fastcall HTTP_replacer_destroy_node(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_String_destroy(*((_QWORD *)ptr + 2));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_String_destroy(*((_QWORD *)ptr + 2));
free(ptr);
return 0LL;
}

original_code:
int HTTP_replacer_destroy_node(HTTP_replacer_node *node)
{
 if(node == ((void *)0))
 {
  return -1;
 }
 HTTP_String_destroy(node->value);
 free(node);
 return 0;
}

canonical_original_code:
int HTTP_replacer_destroy_node(struct HTTP_replacer_linkedlist_node *node)
{
 if(node == ((void *)0))
 {
  return -1;
 }
 HTTP_String_destroy(node->value);
 free(node);
 return 0;
}


decompiled_code:
__int64 __fastcall HTTP_replacer_pop(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = (_QWORD *)v2[3];
HTTP_replacer_destroy_node(v2);
result = 0LL;
*a1 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v3 = (_QWORD *)v2[3];
func1(v2);
result = 0LL;
*a1 = v3;
return result;
}

original_code:
int HTTP_replacer_pop(HTTP_replacer_node **head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_replacer_node *node = (*head)->next;
 HTTP_replacer_destroy_node(*head);
 *head = node;
 return 0;
}

canonical_original_code:
int HTTP_replacer_pop(struct HTTP_replacer_linkedlist_node **head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 struct HTTP_replacer_linkedlist_node *node = (*head)->next;
 HTTP_replacer_destroy_node(*head);
 *head = node;
 return 0;
}

variable_types: struct HTTP_replacer_linkedlist_node { char *begin; char *end; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *value; struct HTTP_replacer_linkedlist_node *next; } **


decompiled_code:
__int64 __fastcall HTTP_replacer_destroy(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
HTTP_replacer_destroy(*((void **)ptr + 3));
HTTP_replacer_destroy_node(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
func3(*((void **)ptr + 3));
func1(ptr);
return 0LL;
}

original_code:
int HTTP_replacer_destroy(HTTP_replacer_node *head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_replacer_destroy(head->next);
 HTTP_replacer_destroy_node(head);
 return 0;
}

canonical_original_code:
int HTTP_replacer_destroy(struct HTTP_replacer_linkedlist_node *head)
{
 if(head == ((void *)0))
 {
  return -1;
 }
 HTTP_replacer_destroy(head->next);
 HTTP_replacer_destroy_node(head);
 return 0;
}


decompiled_code:
__int64 __fastcall default_handler(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post_isra_0(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
do_get_isra_0(a1, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
func0(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
func1(a1, a2);
result = 0LL;
}
return result;
}

original_code:
int default_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

canonical_original_code:
int default_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

variable_types: struct HTTP_Socket { int sfd; struct HTTP_String { char *begin; char *current; char *capacity_end; char *end; char *content; } *buffer; } *


decompiled_code:
__int64 __fastcall verify_signin_handler(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post_isra_0(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
do_get_isra_0(a1, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
func1(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
func2(a1, a2);
result = 0LL;
}
return result;
}

original_code:
int verify_signin_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

canonical_original_code:
int verify_signin_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall error404_handler(__int64 a1, __int64 a2)
{
HTTP_Engine_render(a2, "public/html/error404.html", 0LL);
fwrite("error404_handler\n", 1uLL, 0x11uLL, stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
HTTP_Engine_render(a2, "public/html/error404.html", 0LL);
fwrite("error404_handler\n", 1uLL, 0x11uLL, stdout);
return 0LL;
}

original_code:
int error404_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 HTTP_Engine_render(response,"public/html/error404.html",((void *)0));
 fprintf(stdout,"error404_handler\n");
 return 0;
}

canonical_original_code:
int error404_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 HTTP_Engine_render(response,"public/html/error404.html",((void *)0));
 fprintf(stdout,"error404_handler\n");
 return 0;
}


decompiled_code:
__int64 __fastcall verify_signup_handler(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post_isra_0(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
do_get_isra_0(a1, a2);
result = 0LL;
}
return result;
}

original_code:
int verify_signup_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

canonical_original_code:
int verify_signup_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}


substr

decompiled_code:
char *__fastcall substr(__int64 a1, unsigned int a2, int a3)
{
size_t v3; // rbx

v3 = a3 - a2;
strncpy(stbuf_0, (const char *)(a1 + a2), v3);
stbuf_0[v3] = 0;
return stbuf_0;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1, unsigned int a2, int a3)
{
size_t v3; // rbx

v3 = a3 - a2;
strncpy(stbuf_0, (const char *)(a1 + a2), v3);
stbuf_0[v3] = 0;
return stbuf_0;
}

original_code:
static char* substr(const char*str,unsigned start, unsigned end)
{
    unsigned n = end - start;
    static char stbuf[256];
    strncpy(stbuf, str + start, n);
    stbuf[n] = 0;
    return stbuf;
}

canonical_original_code:
static char *substr(char *str, unsigned int start, unsigned int end)
{
    unsigned int n = end - start;
    static char stbuf[256];
    strncpy(stbuf, str + start, n);
    stbuf[n] = 0;
    return stbuf;
}

variable_types:
str
char *

variable_types:
start
unsigned int

variable_types:
end
unsigned int

variable_types:
n
unsigned int

variable_types:
stbuf
char [256]

return_type: char *


decompiled_code:
__int64 __fastcall signin_handler(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post_isra_0(a1, a2);
else
error404_handler(a1, a2);
result = 0LL;
}
else
{
do_get_constprop_0_isra_0(a2);
result = 0LL;
}
return result;
}

original_code:
int signin_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}

canonical_original_code:
int signin_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 switch(HTTP_Request_get_method(request))
 {
 case 0:
  do_get(request,response);
  break;
 case 1:
  do_post(request,response);
  break;
 default:
  error404_handler(request,response);
  break;
 }
 return 0;
}


dispatcher

decompiled_code:
void *__fastcall dispatcher(void *a1)
{
__int64 v1; // r14
__int64 v2; // r15
int v3; // eax
void (__fastcall *v4)(__int64, __int64); // rax
__int64 v6; // [rsp+0h] [rbp-10C8h]
__int64 v7; // [rsp+8h] [rbp-10C0h]
fd_set readfds; // [rsp+10h] [rbp-10B8h] BYREF
__int128 v9; // [rsp+90h] [rbp-1038h] BYREF
char v10[4136]; // [rsp+A0h] [rbp-1028h] BYREF

v6 = ((__int64 (*)(void))HTTP_Socket_create)();
v7 = HTTP_Socket_create((unsigned int)a1);
memset(&readfds, 0, sizeof(readfds));
v1 = (int)a1 / 64;
v2 = 1LL << ((int)a1 % 64);
readfds.fds_bits[v1] |= v2;
do
{
while ( 1 )
{
memset(v10, 0, 8LL * ((_QWORD)&loc_1FB + 3));
v9 = 0LL;
v3 = select((_DWORD)a1 + 1, &readfds, 0LL, 0LL, 0LL);
if ( v3 != -1 )
break;
perror("select");
}
}
while ( !v3 || (readfds.fds_bits[v1] & v2) == 0 );
HTTP_Request_init(v6);
*((_BYTE *)&v9 + (int)HTTP_Request_get_url(v6, &v9)) = 0;
v4 = (void (__fastcall *)(__int64, __int64))HTTP_Router_route(&v9);
v4(v6, v7);
memset(&readfds, 0, sizeof(readfds));
HTTP_Socket_destroy(v6, 0LL);
HTTP_Socket_destroy(v7, 1LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v1; // r14
__int64 v2; // r15
int v3; // eax
void (__fastcall *v4)(__int64, __int64); // rax
__int64 v6; // [rsp+0h] [rbp-10C8h]
__int64 v7; // [rsp+8h] [rbp-10C0h]
fd_set readfds; // [rsp+10h] [rbp-10B8h] BYREF
__int128 v9; // [rsp+90h] [rbp-1038h] BYREF
char v10[4136]; // [rsp+A0h] [rbp-1028h] BYREF

v6 = ((__int64 (*)(void))HTTP_Socket_create)();
v7 = HTTP_Socket_create((unsigned int)a1);
memset(&readfds, 0, sizeof(readfds));
v1 = (int)a1 / 64;
v2 = 1LL << ((int)a1 % 64);
readfds.fds_bits[v1] |= v2;
do
{
while ( 1 )
{
memset(v10, 0, 8LL * ((_QWORD)&loc_1FB + 3));
v9 = 0LL;
v3 = select((_DWORD)a1 + 1, &readfds, 0LL, 0LL, 0LL);
if ( v3 != -1 )
break;
perror("select");
}
}
while ( !v3 || (readfds.fds_bits[v1] & v2) == 0 );
HTTP_Request_init(v6);
*((_BYTE *)&v9 + (int)HTTP_Request_get_url(v6, &v9)) = 0;
v4 = (void (__fastcall *)(__int64, __int64))HTTP_Router_route(&v9);
v4(v6, v7);
memset(&readfds, 0, sizeof(readfds));
HTTP_Socket_destroy(v6, 0LL);
HTTP_Socket_destroy(v7, 1LL);
return 0LL;
}

original_code:
static void* dispatcher(void *arg)
{
 int cfd = (int)arg;
 HTTP_Socket *request = HTTP_Socket_create(cfd);
 HTTP_Socket *response = HTTP_Socket_create(cfd);
 fd_set rfds;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))));
 int flag = 1;
 while(flag)
 {
  char url[4096] = {0};
  int32_t size = 0;
  switch(select(cfd+1,&rfds,((void *)0),((void *)0),((void *)0)))
  {
   case -1:
    perror("select");
    break;
   case 0:
    break;
   default:
    if(((((&rfds)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    {
     HTTP_Request_init(request);
     size = HTTP_Request_get_url(request,url);
     url[size] = 0;
     HTTP_Router_route(url)(request,response);
     flag = 0;
    }
    break;
  }
 }
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 HTTP_Socket_destroy(request,SHUT_RD);
 HTTP_Socket_destroy(response,SHUT_WR);
 return ((void *)0);
}

canonical_original_code:
static void *dispatcher(void *arg)
{
 int cfd = (int)arg;
 struct HTTP_Socket *request = HTTP_Socket_create(cfd);
 struct HTTP_Socket *response = HTTP_Socket_create(cfd);
 struct fd_set rfds;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rfds)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))));
 int flag = 1;
 while(flag)
 {
  char url[4096] = {0};
  int size = 0;
  switch(select(cfd+1,&rfds,((void *)0),((void *)0),((void *)0)))
  {
   case -1:
    perror("select");
    break;
   case 0:
    break;
   default:
    if(((((&rfds)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    {
     HTTP_Request_init(request);
     size = HTTP_Request_get_url(request,url);
     url[size] = 0;
     HTTP_Router_route(url)(request,response);
     flag = 0;
    }
    break;
  }
 }
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
 HTTP_Socket_destroy(request,SHUT_RD);
 HTTP_Socket_destroy(response,SHUT_WR);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: cfd int

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }

variable_types: flag int

variable_types:
url
char [4096]


main

repo: QMonkey/Thread-Pool

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // r12
int v5; // eax
__int64 v6; // rbp
int v7; // ebx
__int64 v8; // rbx
__int64 v9; // rdx
int v10; // eax

if ( argc <= 3 )
{
fwrite("No enough parameter.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v3 = atoi(argv[1]);
v4 = (void *)thread_pool_create(v3);
thread_pool_start(v4);
v5 = atoi(argv[2]);
v6 = v5;
if ( v5 <= 0 )
{
putchar(10);
sleep(5u);
}
else
{
v7 = 0;
do
{
++v7;
thread_pool_execute(v4, callback, &value);
}
while ( (_DWORD)v6 != v7 );
v8 = 0LL;
putchar(10);
sleep(5u);
do
{
v9 = v8++;
thread_pool_execute(v4, callback_function, v9);
}
while ( v8 != v6 );
}
v10 = atoi(argv[3]);
sleep(v10);
thread_pool_destroy(v4);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // r12
int v5; // eax
__int64 v6; // rbp
int v7; // ebx
__int64 v8; // rbx
__int64 v9; // rdx
int v10; // eax

if ( argc <= 3 )
{
fwrite("No enough parameter.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v3 = atoi(argv[1]);
v4 = (void *)func15(v3);
func16(v4);
v5 = atoi(argv[2]);
v6 = v5;
if ( v5 <= 0 )
{
putchar(10);
sleep(5u);
}
else
{
v7 = 0;
do
{
++v7;
func17(v4, callback, &value);
}
while ( (_DWORD)v6 != v7 );
v8 = 0LL;
putchar(10);
sleep(5u);
do
{
v9 = v8++;
func17(v4, callback_function, v9);
}
while ( v8 != v6 );
}
v10 = atoi(argv[3]);
sleep(v10);
func20(v4);
putchar(10);
return 0;
}

original_code:
int main(int argc,char **argv)
{
 if(argc < 4)
 {
  fprintf(stderr,"No enough parameter.\n");
  exit(1);
 }
 thread_pool_t *pool = thread_pool_create(atoi(argv[1]));
 thread_pool_start(pool);
 int i;
 int end = atoi(argv[2]);
 for(i = 0; i < end; ++i)
 {
  thread_pool_execute(pool,callback,&value);
 }
 printf("\n");
 sleep(5);
 for(i = 0; i < end; ++i)
 {
  thread_pool_execute(pool,callback_function,(void*)i);
 }
 sleep(atoi(argv[3]));
 thread_pool_destroy(pool);
 printf("\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(argc < 4)
 {
  fprintf(stderr,"No enough parameter.\n");
  exit(1);
 }
 struct thread_pool_t *pool = thread_pool_create(atoi(argv[1]));
 thread_pool_start(pool);
 int i;
 int end = atoi(argv[2]);
 for(i = 0; i < end; ++i)
 {
  thread_pool_execute(pool,callback,&value);
 }
 printf("\n");
 sleep(5);
 for(i = 0; i < end; ++i)
 {
  thread_pool_execute(pool,callback_function,(void *)i);
 }
 sleep(atoi(argv[3]));
 thread_pool_destroy(pool);
 printf("\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct thread_pool_t { union sem_t { char __size[32]; long __align; } semaphore; 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; unsigned long *tids; struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; } *head; unsigned int size; int flag; } *

variable_types: i int

variable_types: end int

user_defined_types: struct thread_pool_t { union sem_t semaphore; union pthread_mutex_t mutex; unsigned long *tids; struct task_queue_node_t *head; unsigned int size; int flag; }

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

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


decompiled_code:
__int64 __fastcall callback_function(unsigned int a1)
{
printf("Before sleep:\t%d\n", a1);
sleep(5u);
printf("After sleep:\t%d\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
printf("Before sleep:\t%d\n", a1);
sleep(5u);
printf("After sleep:\t%d\n", a1);
return 0LL;
}

original_code:
static void* callback_function(void *arg)
{
 printf("Before sleep:\t%d\n",(int)arg);
 sleep(5);
 printf("After sleep:\t%d\n",(int)arg);
 return ((void *)0);
}

canonical_original_code:
static void *callback_function(void *arg)
{
 printf("Before sleep:\t%d\n",(int)arg);
 sleep(5);
 printf("After sleep:\t%d\n",(int)arg);
 return ((void *)0);
}


callback

decompiled_code:
__int64 __fastcall callback(unsigned int *a1)
{
int v1; // eax

printf("%d ", *a1);
v1 = counter + 1;
*a1 = counter + 1;
counter = v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
int v1; // eax

printf("%d ", *a1);
v1 = counter + 1;
*a1 = counter + 1;
counter = v1;
return 0LL;
}

original_code:
static void* callback(void *arg)
{
 int *ptr = (int*)arg;
 printf("%d ",*ptr);
 *ptr = ++counter;
 return ((void *)0);
}

canonical_original_code:
static void *callback(void *arg)
{
 int *ptr = (int*)arg;
 printf("%d ",*ptr);
 *ptr = ++counter;
 return ((void *)0);
}

variable_types:
ptr
int *


decompiled_code:
int __fastcall task_queue_put(sem_t *sem, __int64 a2, __int64 a3)
{
pthread_mutex_lock((pthread_mutex_t *)&sem[1]);
task_queue_push(&sem[2].__align + 2, a2, a3);
pthread_mutex_unlock((pthread_mutex_t *)&sem[1]);
return sem_post(sem);
}

canonical_decompiled_code:
int __fastcall func9(sem_t *sem, __int64 a2, __int64 a3)
{
pthread_mutex_lock((pthread_mutex_t *)&sem[1]);
task_queue_push(&sem[2].__align + 2, a2, a3);
pthread_mutex_unlock((pthread_mutex_t *)&sem[1]);
return sem_post(sem);
}

original_code:
void task_queue_put(thread_pool_t *pool,void* (*callback)(void*),void *arg)
{
 pthread_mutex_lock(&pool->mutex);
 task_queue_push(&pool->head,callback,arg);
 pthread_mutex_unlock(&pool->mutex);
 sem_post(&pool->semaphore);
}

canonical_original_code:
void task_queue_put(struct thread_pool_t *pool, void *(*callback)(void *), void *arg)
{
 pthread_mutex_lock(&pool->mutex);
 task_queue_push(&pool->head,callback,arg);
 pthread_mutex_unlock(&pool->mutex);
 sem_post(&pool->semaphore);
}

variable_types:
callback
void *(*)(void *)

return_type: void

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

user_defined_types: struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; }

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


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

result = *a1;
*a1 = *(_QWORD *)(*a1 + 16);
*(_QWORD *)(result + 16) = 0LL;
return result;
}

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

result = *a1;
*a1 = *(_QWORD *)(*a1 + 16);
*(_QWORD *)(result + 16) = 0LL;
return result;
}

original_code:
task_queue_node_t* task_queue_pop(task_queue_node_t **head_ptr)
{
 task_queue_node_t *tmp = *head_ptr;
 *head_ptr = tmp->next;
 tmp->next = ((void *)0);
 return tmp;
}

canonical_original_code:
struct task_queue_node_t *task_queue_pop(struct task_queue_node_t **head_ptr)
{
 struct task_queue_node_t *tmp = *head_ptr;
 *head_ptr = tmp->next;
 tmp->next = ((void *)0);
 return tmp;
}

variable_types: struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; } *


decompiled_code:
__int64 __fastcall task_queue_take(__int64 a1)
{
__int64 v1; // r12

sem_wait((sem_t *)a1);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v1 = task_queue_pop((__int64 *)(a1 + 80));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // r12

sem_wait((sem_t *)a1);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v1 = func10((__int64 *)(a1 + 80));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v1;
}

original_code:
task_queue_node_t* task_queue_take(thread_pool_t *pool)
{
 sem_wait(&pool->semaphore);
 pthread_mutex_lock(&pool->mutex);
 task_queue_node_t *node = task_queue_pop(&pool->head);
 pthread_mutex_unlock(&pool->mutex);
 return node;
}

canonical_original_code:
struct task_queue_node_t *task_queue_take(struct thread_pool_t *pool)
{
 sem_wait(&pool->semaphore);
 pthread_mutex_lock(&pool->mutex);
 struct task_queue_node_t *node = task_queue_pop(&pool->head);
 pthread_mutex_unlock(&pool->mutex);
 return node;
}

variable_types: struct thread_pool_t { union sem_t { char __size[32]; long __align; } semaphore; 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; unsigned long *tids; struct task_queue_node_t *head; unsigned int size; int flag; } *

return_type: struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; } *


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

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

original_code:
void task_queue_delete(task_queue_node_t *node)
{
 free(node);
}

canonical_original_code:
void task_queue_delete(struct task_queue_node_t *node)
{
 free(node);
}


decompiled_code:
void __fastcall task_queue_destroy(void **a1)
{
char *v2; // rdi

v2 = (char *)*a1;
if ( v2 )
{
task_queue_destroy(v2 + 16);
task_queue_delete(*a1);
}
}

canonical_decompiled_code:
void __fastcall func13(void **a1)
{
char *v2; // rdi

v2 = (char *)*a1;
if ( v2 )
{
func13(v2 + 16);
func12(*a1);
}
}

original_code:
void task_queue_destroy(task_queue_node_t **head_ptr)
{
 if(*head_ptr != ((void *)0))
 {
  task_queue_destroy(&(*head_ptr)->next);
  task_queue_delete(*head_ptr);
 }
}

canonical_original_code:
void task_queue_destroy(struct task_queue_node_t **head_ptr)
{
 if(*head_ptr != ((void *)0))
 {
  task_queue_destroy(&(*head_ptr)->next);
  task_queue_delete(*head_ptr);
 }
}

variable_types: struct task_queue_node_t { void *(*callback)(void *); void *arg; struct task_queue_node_t *next; } **


decompiled_code:
void __fastcall thread_pool_run(void *a1)
{
_QWORD *v1; // rbp

while ( *((_DWORD *)a1 + 23) )
{
v1 = (_QWORD *)task_queue_take((__int64)a1);
((void (__fastcall *)(_QWORD))*v1)(v1[1]);
task_queue_delete(v1);
}
}

canonical_decompiled_code:
void __fastcall func14(void *a1)
{
_QWORD *v1; // rbp

while ( *((_DWORD *)a1 + 23) )
{
v1 = (_QWORD *)func11((__int64)a1);
((void (__fastcall *)(_QWORD))*v1)(v1[1]);
func12(v1);
}
}

original_code:
void* thread_pool_run(void *arg)
{
 thread_pool_t *pool = (thread_pool_t*)arg;
 while(pool->flag)
 {
  task_queue_node_t *node = task_queue_take(pool);
  node->callback(node->arg);
  task_queue_delete(node);
 }
}

canonical_original_code:
void *thread_pool_run(void *arg)
{
 struct thread_pool_t *pool = (thread_pool_t*)arg;
 while(pool->flag)
 {
  struct task_queue_node_t *node = task_queue_take(pool);
  node->callback(node->arg);
  task_queue_delete(node);
 }
}


decompiled_code:
int __fastcall thread_pool_start(void *arg)
{
int result; // eax
unsigned int v2; // ebp
__int64 v3; // rdx

if ( !*((_DWORD *)arg + 23) )
{
result = *((_DWORD *)arg + 22);
*((_DWORD *)arg + 23) = 1;
if ( result )
{
v2 = 0;
do
{
v3 = v2++;
result = pthread_create(
(pthread_t *)(*((_QWORD *)arg + 9) + 8 * v3),
0LL,
(void *(*)(void *))thread_pool_run,
arg);
}
while ( *((_DWORD *)arg + 22) > v2 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(void *arg)
{
int result; // eax
unsigned int v2; // ebp
__int64 v3; // rdx

if ( !*((_DWORD *)arg + 23) )
{
result = *((_DWORD *)arg + 22);
*((_DWORD *)arg + 23) = 1;
if ( result )
{
v2 = 0;
do
{
v3 = v2++;
result = pthread_create(
(pthread_t *)(*((_QWORD *)arg + 9) + 8 * v3),
0LL,
(void *(*)(void *))thread_pool_run,
arg);
}
while ( *((_DWORD *)arg + 22) > v2 );
}
}
return result;
}

original_code:
void thread_pool_start(thread_pool_t *pool)
{
 if(!pool->flag)
 {
  pool->flag = 1;
  uint32_t i;
  for(i = 0; i < pool->size; ++i)
  {
   pthread_create(pool->tids + i,((void *)0),thread_pool_run,pool);
  }
 }
}

canonical_original_code:
void thread_pool_start(struct thread_pool_t *pool)
{
 if(!pool->flag)
 {
  pool->flag = 1;
  unsigned int i;
  for(i = 0; i < pool->size; ++i)
  {
   pthread_create(pool->tids + i,((void *)0),thread_pool_run,pool);
  }
 }
}

variable_types:
i
unsigned int


decompiled_code:
// attributes: thunk
int __fastcall thread_pool_execute(sem_t *sem, __int64 a2, __int64 a3)
{
return task_queue_put(sem, a2, a3);
}

canonical_decompiled_code:
int __fastcall func17(sem_t *sem, __int64 a2, __int64 a3)
{
return func9(sem, a2, a3);
}

original_code:
void thread_pool_execute(thread_pool_t *pool,void* (*callback)(void*),void *arg)
{
 task_queue_put(pool,callback,arg);
}

canonical_original_code:
void thread_pool_execute(struct thread_pool_t *pool, void *(*callback)(void *), void *arg)
{
 task_queue_put(pool,callback,arg);
}


decompiled_code:
int __fastcall thread_pool_join(__int64 a1)
{
int result; // eax
__int64 v2; // r12
__int64 v4; // rbx
pthread_t v5; // rdi

result = *(_DWORD *)(a1 + 88);
v2 = *(_QWORD *)(a1 + 72);
if ( result )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(v2 + 8 * v4++);
result = pthread_join(v5, 0LL);
}
while ( *(_DWORD *)(a1 + 88) > (unsigned int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
int result; // eax
__int64 v2; // r12
__int64 v4; // rbx
pthread_t v5; // rdi

result = *(_DWORD *)(a1 + 88);
v2 = *(_QWORD *)(a1 + 72);
if ( result )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(v2 + 8 * v4++);
result = pthread_join(v5, 0LL);
}
while ( *(_DWORD *)(a1 + 88) > (unsigned int)v4 );
}
return result;
}

original_code:
void thread_pool_join(thread_pool_t *pool)
{
 int i;
 pthread_t *tids = pool->tids;
 for(i = 0; i < pool->size; ++i)
 {
  pthread_join(tids[i],((void *)0));
 }
}

canonical_original_code:
void thread_pool_join(struct thread_pool_t *pool)
{
 int i;
 unsigned long *tids = pool->tids;
 for(i = 0; i < pool->size; ++i)
 {
  pthread_join(tids[i],((void *)0));
 }
}

variable_types:
tids
unsigned long *


decompiled_code:
void __fastcall thread_pool_stop(__int64 a1)
{
*(_DWORD *)(a1 + 92) = 0;
}

original_code:
void thread_pool_stop(thread_pool_t *pool)
{
 pool->flag = 0;
}

canonical_original_code:
void thread_pool_stop(struct thread_pool_t *pool)
{
 pool->flag = 0;
}


decompiled_code:
void __fastcall thread_pool_destroy(void *ptr)
{
thread_pool_stop((__int64)ptr);
sem_destroy((sem_t *)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
task_queue_destroy((void **)ptr + 10);
free(*((void **)ptr + 9));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func20(void *ptr)
{
func19((__int64)ptr);
sem_destroy((sem_t *)ptr);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
func13((void **)ptr + 10);
free(*((void **)ptr + 9));
free(ptr);
}

original_code:
void thread_pool_destroy(thread_pool_t *pool)
{
 thread_pool_stop(pool);
 sem_destroy(&pool->semaphore);
 pthread_mutex_destroy(&pool->mutex);
 task_queue_destroy(&pool->head);
 free(pool->tids);
 free(pool);
}

canonical_original_code:
void thread_pool_destroy(struct thread_pool_t *pool)
{
 thread_pool_stop(pool);
 sem_destroy(&pool->semaphore);
 pthread_mutex_destroy(&pool->mutex);
 task_queue_destroy(&pool->head);
 free(pool->tids);
 free(pool);
}


repo: QuLogic/travis-test

decompiled_code:
__int64 compile_stdin()
{
char *v0; // rax
char *v1; // rbp
size_t v2; // rbx
char *v3; // rax
int v4; // eax
char v6[536]; // [rsp+0h] [rbp-218h] BYREF

++_gcov0_compile_stdin;
v0 = (char *)malloc(0x200uLL);
if ( !v0 )
{
++qword_768;
perror("Allocation failed");
++qword_770;
exit(1);
}
*v0 = 0;
v1 = v0;
v2 = 1LL;
while ( fgets(v6, 512, stdin) )
{
v2 += strlen(v6);
v3 = (char *)realloc(v1, v2);
if ( !v3 )
{
++qword_778;
perror("Reallocation failed");
++qword_788;
free(v1);
exit(2);
}
++qword_780;
v1 = strcat(v3, v6);
}
++qword_790;
v4 = ferror(stdin);
++qword_798;
if ( v4 )
{
++qword_7A0;
free(v1);
perror("Error reading standard input");
++qword_7A8;
exit(2);
}
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rax
char *v1; // rbp
size_t v2; // rbx
char *v3; // rax
int v4; // eax
char v6[536]; // [rsp+0h] [rbp-218h] BYREF

++_gcov0_compile_stdin;
v0 = (char *)malloc(0x200uLL);
if ( !v0 )
{
++qword_768;
perror("Allocation failed");
++qword_770;
exit(1);
}
*v0 = 0;
v1 = v0;
v2 = 1LL;
while ( fgets(v6, 512, stdin) )
{
v2 += strlen(v6);
v3 = (char *)realloc(v1, v2);
if ( !v3 )
{
++qword_778;
perror("Reallocation failed");
++qword_788;
free(v1);
exit(2);
}
++qword_780;
v1 = strcat(v3, v6);
}
++qword_790;
v4 = ferror(stdin);
++qword_798;
if ( v4 )
{
++qword_7A0;
free(v1);
perror("Error reading standard input");
++qword_7A8;
exit(2);
}
free(v1);
return 0LL;
}

original_code:
int compile_stdin(char* outfile) {
    int ret;
    char buffer[512];
    size_t size = 1;
    char *source_string = malloc(sizeof(char) * 512);
    if(source_string == ((void *)0)) {
        perror("Allocation failed");
        exit(1);
    }
    source_string[0] = '\0';
    while(fgets(buffer, 512, stdin)) {
        char *old = source_string;
        size += strlen(buffer);
        source_string = realloc(source_string, size);
        if(source_string == ((void *)0)) {
            perror("Reallocation failed");
            free(old);
            exit(2);
        }
        strcat(source_string, buffer);
    }
    if(ferror(stdin)) {
        free(source_string);
        perror("Error reading standard input");
        exit(2);
    }
    free(source_string);
    return ret;
}

canonical_original_code:
int compile_stdin(char *outfile) {
    int ret;
    char buffer[512];
    unsigned long size = 1;
    char *source_string = malloc(sizeof(char) * 512);
    if(source_string == ((void *)0)) {
        perror("Allocation failed");
        exit(1);
    }
    source_string[0] = '\0';
    while(fgets(buffer, 512, stdin)) {
        char *old = source_string;
        size += strlen(buffer);
        source_string = realloc(source_string, size);
        if(source_string == ((void *)0)) {
            perror("Reallocation failed");
            free(old);
            exit(2);
        }
        strcat(source_string, buffer);
    }
    if(ferror(stdin)) {
        free(source_string);
        perror("Error reading standard input");
        exit(2);
    }
    free(source_string);
    return ret;
}

variable_types:
outfile
char *

variable_types: ret int

variable_types:
buffer
char [512]

variable_types:
size
unsigned long

variable_types:
old
char *


decompiled_code:
__int64 compile_file()
{
++_gcov0_compile_file;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
++_gcov0_compile_file;
return 0LL;
}

original_code:
int compile_file(char* input_path, char* outfile) {
    int ret;
    return ret;
}

canonical_original_code:
int compile_file(char *input_path, char *outfile) {
    int ret;
    return ret;
}


decompiled_code:
int __fastcall print_usage(const char *a1)
{
const char *v1; // rsi
int result; // eax

++_gcov0_print_usage;
printf("Usage: %s [OPTION]... [FILE]\n\n", a1);
++qword_7C8;
puts("Options:");
++qword_7D0;
puts(" -o OUTFILE Write output to specified file.");
++qword_7D8;
printf(" -t NAME Output style. Can be:");
v1 = *(&style_option_strings + 2);
++qword_7E0;
printf(" %s", v1);
++qword_7F0;
putchar(44);
++qword_7F8;
printf(" %s", style_option_strings);
++qword_7E8;
puts(".");
++qword_7F8;
++qword_800;
puts(" -l Emit comments showing original line numbers.");
++qword_808;
puts(" -g Emit source map.");
++qword_810;
puts(" -I PATH Set Sass import path.");
++qword_818;
puts(" -h Display this help message.");
++qword_820;
result = putchar(10);
++qword_828;
return result;
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
const char *v1; // rsi
int result; // eax

++_gcov0_print_usage;
printf("Usage: %s [OPTION]... [FILE]\n\n", a1);
++qword_7C8;
puts("Options:");
++qword_7D0;
puts(" -o OUTFILE Write output to specified file.");
++qword_7D8;
printf(" -t NAME Output style. Can be:");
v1 = *(&style_option_strings + 2);
++qword_7E0;
printf(" %s", v1);
++qword_7F0;
putchar(44);
++qword_7F8;
printf(" %s", style_option_strings);
++qword_7E8;
puts(".");
++qword_7F8;
++qword_800;
puts(" -l Emit comments showing original line numbers.");
++qword_808;
puts(" -g Emit source map.");
++qword_810;
puts(" -I PATH Set Sass import path.");
++qword_818;
puts(" -h Display this help message.");
++qword_820;
result = putchar(10);
++qword_828;
return result;
}

original_code:
void print_usage(char* argv0) {
    int i;
    printf("Usage: %s [OPTION]... [FILE]\n\n", argv0);
    printf("Options:\n");
    printf("   -o OUTFILE     Write output to specified file.\n");
    printf("   -t NAME        Output style. Can be:");
    for(i = sizeof(style_option_strings) / sizeof(style_option_strings[0]) - 1; i >= 0; i--) {
        printf(" %s", style_option_strings[i].style_string);
        printf(i == 0 ? ".\n" : ",");
    }
    printf("   -l             Emit comments showing original line numbers.\n");
    printf("   -g             Emit source map.\n");
    printf("   -I PATH        Set Sass import path.\n");
    printf("   -h             Display this help message.\n");
    printf("\n");
}

canonical_original_code:
void print_usage(char *argv0) {
    int i;
    printf("Usage: %s [OPTION]... [FILE]\n\n", argv0);
    printf("Options:\n");
    printf("   -o OUTFILE     Write output to specified file.\n");
    printf("   -t NAME        Output style. Can be:");
    for(i = sizeof(style_option_strings) / sizeof(style_option_strings[0]) - 1; i >= 0; i--) {
        printf(" %s", style_option_strings[i].style_string);
        printf(i == 0 ? ".\n" : ",");
    }
    printf("   -l             Emit comments showing original line numbers.\n");
    printf("   -g             Emit source map.\n");
    printf("   -I PATH        Set Sass import path.\n");
    printf("   -h             Display this help message.\n");
    printf("\n");
}


decompiled_code:
void __fastcall __noreturn invalid_usage(const char *a1)
{
++_gcov0_invalid_usage;
fprintf(stderr, "See '%s -h'\n", a1);
++qword_838;
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
++_gcov0_invalid_usage;
fprintf(stderr, "See '%s -h'\n", a1);
++qword_838;
exit(1);
}

original_code:
void invalid_usage(char* argv0) {
    fprintf(stderr, "See '%s -h'\n", argv0);
    exit(1);
}

canonical_original_code:
void invalid_usage(char *argv0) {
    fprintf(stderr, "See '%s -h'\n", argv0);
    exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int result; // eax
char *v6; // r13
__int64 v7; // r12
const char *v8; // rsi
const char *v9; // rdx
const char *v10; // rdi
const char *v11; // rdi
const char *v12; // rdi
const char *v13; // rdi

++_gcov0_main;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "ho:lgt:I:");
if ( v4 != -1 )
{
switch ( v4 )
{
case '?':
v12 = *argv;
++qword_850;
invalid_usage(v12);
case 'I':
case 'g':
case 'l':
case 'o':
goto LABEL_5;
case 'h':
v11 = *argv;
++qword_858;
print_usage(v11);
++qword_8A0;
return 0;
case 't':
v6 = optarg;
if ( strcmp(optarg, style_option_strings) )
{
v7 = qword_868;
v8 = *(&style_option_strings + 2);
++qword_868;
if ( strcmp(v6, v8) )
{
++qword_870;
++qword_878;
qword_868 = v7 + 2;
fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", v6);
++qword_880;
fprintf(stderr, " %s", style_option_strings);
v9 = *(&style_option_strings + 2);
++qword_888;
fprintf(stderr, " %s", v9);
++qword_888;
++qword_890;
fputc(10, stderr);
v10 = *argv;
++qword_898;
invalid_usage(v10);
}
}
++qword_860;
LABEL_5:
++qword_8B0;
continue;
default:
++qword_848;
fwrite("Unknown error while processing arguments\n", 1uLL, 0x29uLL, stderr);
++qword_8A8;
return 2;
}
}
break;
}
++qword_8B8;
result = 0;
if ( argc - 1 > optind )
{
++qword_8C0;
fwrite("Error: Too many arguments.\n", 1uLL, 0x1BuLL, stderr);
v13 = *argv;
++qword_8C8;
invalid_usage(v13);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int result; // eax
char *v6; // r13
__int64 v7; // r12
const char *v8; // rsi
const char *v9; // rdx
const char *v10; // rdi
const char *v11; // rdi
const char *v12; // rdi
const char *v13; // rdi

++_gcov0_main;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "ho:lgt:I:");
if ( v4 != -1 )
{
switch ( v4 )
{
case '?':
v12 = *argv;
++qword_850;
func4(v12);
case 'I':
case 'g':
case 'l':
case 'o':
goto LABEL_5;
case 'h':
v11 = *argv;
++qword_858;
func3(v11);
++qword_8A0;
return 0;
case 't':
v6 = optarg;
if ( strcmp(optarg, style_option_strings) )
{
v7 = qword_868;
v8 = *(&style_option_strings + 2);
++qword_868;
if ( strcmp(v6, v8) )
{
++qword_870;
++qword_878;
qword_868 = v7 + 2;
fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", v6);
++qword_880;
fprintf(stderr, " %s", style_option_strings);
v9 = *(&style_option_strings + 2);
++qword_888;
fprintf(stderr, " %s", v9);
++qword_888;
++qword_890;
fputc(10, stderr);
v10 = *argv;
++qword_898;
func4(v10);
}
}
++qword_860;
LABEL_5:
++qword_8B0;
continue;
default:
++qword_848;
fwrite("Unknown error while processing arguments\n", 1uLL, 0x29uLL, stderr);
++qword_8A8;
return 2;
}
}
break;
}
++qword_8B8;
result = 0;
if ( argc - 1 > optind )
{
++qword_8C0;
fwrite("Error: Too many arguments.\n", 1uLL, 0x1BuLL, stderr);
v13 = *argv;
++qword_8C8;
func4(v13);
}
return result;
}

original_code:
int main(int argc, char** argv) {
    char *outfile = 0;
    int c, i;
    while ((c = getopt(argc, argv, "ho:lgt:I:")) != -1) {
        switch (c) {
        case 'o':
            outfile = optarg;
            break;
        case 'I':
            break;
        case 't':
            for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                if(strcmp(optarg, style_option_strings[i].style_string) == 0) {
                    break;
                }
            }
            if(i == sizeof(style_option_strings) / sizeof(style_option_strings[0])) {
                fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg);
                for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                    fprintf(stderr, " %s", style_option_strings[i].style_string);
                }
                fprintf(stderr, "\n");
                invalid_usage(argv[0]);
            }
            break;
        case 'l':
            break;
        case 'g':
            break;
        case 'h':
            print_usage(argv[0]);
            return 0;
        case '?':
            invalid_usage(argv[0]);
        default:
            fprintf(stderr, "Unknown error while processing arguments\n");
            return 2;
        }
    }
    if(optind < argc - 1) {
        fprintf(stderr, "Error: Too many arguments.\n");
        invalid_usage(argv[0]);
    }
    if(optind < argc && strcmp(argv[optind], "-") != 0) {
    } else {
    }
}

canonical_original_code:
int main(int argc, char **argv) {
    char *outfile = 0;
    int c; int i;
    while ((c = getopt(argc, argv, "ho:lgt:I:")) != -1) {
        switch (c) {
        case 'o':
            outfile = optarg;
            break;
        case 'I':
            break;
        case 't':
            for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                if(strcmp(optarg, style_option_strings[i].style_string) == 0) {
                    break;
                }
            }
            if(i == sizeof(style_option_strings) / sizeof(style_option_strings[0])) {
                fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg);
                for(i = 0; i < sizeof(style_option_strings) / sizeof(style_option_strings[0]); ++i) {
                    fprintf(stderr, " %s", style_option_strings[i].style_string);
                }
                fprintf(stderr, "\n");
                invalid_usage(argv[0]);
            }
            break;
        case 'l':
            break;
        case 'g':
            break;
        case 'h':
            print_usage(argv[0]);
            return 0;
        case '?':
            invalid_usage(argv[0]);
        default:
            fprintf(stderr, "Unknown error while processing arguments\n");
            return 2;
        }
    }
    if(optind < argc - 1) {
        fprintf(stderr, "Error: Too many arguments.\n");
        invalid_usage(argv[0]);
    }
    if(optind < argc && strcmp(argv[optind], "-") != 0) {
    } else {
    }
}

variable_types: argc int

variable_types: c int


repo: Quadra-H/QH-GPU

decompiled_code:
void __fastcall list_add_tail(_QWORD *a1, __int64 *a2)
{
_list_add(a1, *a2, a2);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 *a2)
{
func1(a1, *a2, a2);
}

original_code:
static inline void list_add_tail(struct list_head *new_item, struct list_head *head)
{
    __list_add(new_item, head->prev, head);
}

variable_types: struct list_head { struct list_head *prev; } *

variable_types:
head
struct list_head *


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_QWORD *v1; // rax

_list_del(*(_QWORD *)a1, *(_QWORD **)(a1 + 8));
v1[1] = 0LL;
*v1 = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
    __list_del(entry->prev, entry->next);
    entry->next = ((void *)0);
    entry->prev = ((void *)0);
}

user_defined_types: struct list_head { struct list_head *prev; }


decompiled_code:
__int64 qc_finit()
{
int v0; // ebp

if ( munmap(mmap_address, 0x400000uLL) == -1 )
puts("[qhgpu connector] error : unmap fail.");
v0 = devfd;
ioctl(devfd, 0x6705uLL);
close(v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebp

if ( munmap(mmap_address, 0x400000uLL) == -1 )
puts("[qhgpu connector] error : unmap fail.");
v0 = devfd;
ioctl(devfd, 0x6705uLL);
close(v0);
return 0LL;
}


decompiled_code:
__int64 __fastcall qc_send_response(void *buf)
{
int v1; // eax

v1 = write(devfd, buf, 8uLL);
safe_syscall(v1, "connector.c", 0x360u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(void *buf)
{
int v1; // eax

v1 = write(devfd, buf, 8uLL);
func9(v1, "connector.c", 0x360u);
return 0LL;
}

original_code:
int qc_send_response(struct qhgpu_ku_response *resp) {
 _safe_syscall(write(devfd, resp, sizeof(struct qhgpu_ku_response)), "connector.c", 864);
 return 0;
}

variable_types: struct qhgpu_ku_response { int id; int errcode; } *


decompiled_code:
__int64 qc_main_loop()
{
if ( !qc_loop_continue )
return 0LL;
do
{
_qc_process_request((__int64 (__fastcall *)(__int64))qc_service_done, (__int64)&post_exec_reqs, 0);
_qc_process_request(qc_post_exec, (__int64)&running_reqs, 1);
_qc_process_request((__int64 (__fastcall *)(__int64))qc_launch_exec, (__int64)&init_reqs, 0);
}
while ( (unsigned int)qc_get_next_service_request() != -123 && qc_loop_continue );
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
if ( !qc_loop_continue )
return 0LL;
do
{
func19((__int64 (__fastcall *)(__int64))qc_service_done, (__int64)&post_exec_reqs, 0);
func19(qc_post_exec, (__int64)&running_reqs, 1);
func19((__int64 (__fastcall *)(__int64))qc_launch_exec, (__int64)&init_reqs, 0);
}
while ( (unsigned int)func16() != -123 && qc_loop_continue );
return 0LL;
}

original_code:
int qc_main_loop() {
 while (qc_loop_continue) {
  __qc_process_request(qc_service_done, &post_exec_reqs, 0);
  __qc_process_request(qc_post_exec, &running_reqs, 1);
  __qc_process_request(qc_launch_exec, &init_reqs, 0);
  if (qc_get_next_service_request() == -123) {
   break;
  }
 }
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp

qhgpu_dev_path = "/dev/qhgpu";
service_lib_dir = (__int64)"./";
qc_init(argc, argv, envp);
v3 = (unsigned int)qc_load_all_services(service_lib_dir, context, devices);
printf("service_cnt: %d \n", v3);
if ( !(_DWORD)v3 )
LODWORD(v3) = 1;
if ( ioctl(devfd, 0x80106702uLL, (int)v3) < 0 )
{
perror("device write fail!");
abort();
}
init_mmap_isra_0(v3);
qc_main_loop();
qc_finit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp

qhgpu_dev_path = "/dev/qhgpu";
service_lib_dir = (__int64)"./";
func10(argc, argv, envp);
v3 = (unsigned int)qc_load_all_services(service_lib_dir, context, devices);
printf("service_cnt: %d \n", v3);
if ( !(_DWORD)v3 )
LODWORD(v3) = 1;
if ( ioctl(devfd, 0x80106702uLL, (int)v3) < 0 )
{
perror("device write fail!");
abort();
}
func8(v3);
func20();
func11();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int c;
 qhgpu_dev_path = "/dev/qhgpu";
 service_lib_dir = "./";
 qc_init();
 int service_cnt = qc_load_all_services(service_lib_dir, context, devices);
 printf("service_cnt: %d \n",service_cnt);
 if(service_cnt == 0) service_cnt = 1;
 int r = ioctl(devfd, (((2U) << (((0 +8)+8)+14)) | ((('g')) << (0 +8)) | (((2)) << 0) | ((((sizeof(struct qhgpu_gpu_mem_info[1])))) << ((0 +8)+8))),(unsigned long)service_cnt);
 if (r < 0) {
  perror("device write fail!");
  abort();
 }
 init_mmap(service_cnt);
 qc_main_loop();
 qc_finit();
 return 0;
}

variable_types:
argv
char *[]

variable_types: r int


canonical_original_code:
static inline void list_del(struct list_head *entry)
{
    __list_del(entry->prev, entry->next);
    entry->next = ((void *)0);
    entry->prev = ((void *)0);
}


decompiled_code:
__int64 __fastcall qc_unregister_service(char *a1)
{
__int64 v1; // rax

v1 = lookup_qhgpu_sitem(a1);
return _unregister_service(v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
__int64 v1; // rax

v1 = func3(a1);
return func4(v1);
}

original_code:
int qc_unregister_service(const char *name)
{
 return __unregister_service(lookup_qhgpu_sitem(name));
}

canonical_original_code:
int qc_unregister_service(char *name)
{
 return __unregister_service(lookup_qhgpu_sitem(name));
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall qc_load_all_services(const char *a1)
{
size_t v1; // rbx
unsigned int v2; // er12
const char *v3; // rdi
glob_t v5; // [rsp+0h] [rbp-168h] BYREF
char s[280]; // [rsp+50h] [rbp-118h] BYREF

*(_OWORD *)&v5.gl_pathc = 0LL;
*(_OWORD *)&v5.gl_offs = 0LL;
*(_OWORD *)&v5.gl_closedir = 0LL;
*(_OWORD *)&v5.gl_opendir = 0LL;
v5.gl_stat = 0LL;
snprintf(s, 0x100uLL, "%s/%s*", a1, "libsrv_");
glob(s, 0, 0LL, &v5);
if ( v5.gl_pathc )
{
v1 = 0LL;
do
{
v2 = v1 + 1;
v3 = v5.gl_pathv[v1++];
qc_load_service(v3);
}
while ( v5.gl_pathc > v1 );
}
else
{
v2 = 0;
}
globfree(&v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
size_t v1; // rbx
unsigned int v2; // er12
const char *v3; // rdi
glob_t v5; // [rsp+0h] [rbp-168h] BYREF
char s[280]; // [rsp+50h] [rbp-118h] BYREF

*(_OWORD *)&v5.gl_pathc = 0LL;
*(_OWORD *)&v5.gl_offs = 0LL;
*(_OWORD *)&v5.gl_closedir = 0LL;
*(_OWORD *)&v5.gl_opendir = 0LL;
v5.gl_stat = 0LL;
snprintf(s, 0x100uLL, "%s/%s*", a1, "libsrv_");
glob(s, 0, 0LL, &v5);
if ( v5.gl_pathc )
{
v1 = 0LL;
do
{
v2 = v1 + 1;
v3 = v5.gl_pathv[v1++];
func11(v3);
}
while ( v5.gl_pathc > v1 );
}
else
{
v2 = 0;
}
globfree(&v5);
return v2;
}

original_code:
int qc_load_all_services(const char *dir)
{
 char path[256];
 int i;
 char *libpath;
 int e=0;
 glob_t glb = {0,((void *)0),0};
 snprintf(path, 256, "%s/%s*", dir, "libsrv_");
 glob(path, 0, ((void *)0), &glb);
 for (i=0; i<glb.gl_pathc; i++)
 {
  libpath = glb.gl_pathv[i];
  e += qc_load_service(libpath);
 }
 globfree(&glb);
 return i;
}

canonical_original_code:
int qc_load_all_services(char *dir)
{
 char path[256];
 int i;
 char *libpath;
 int e = 0;
 struct glob_t glb = {0,((void *)0),0};
 snprintf(path, 256, "%s/%s*", dir, "libsrv_");
 glob(path, 0, ((void *)0), &glb);
 for (i=0; i<glb.gl_pathc; i++)
 {
  libpath = glb.gl_pathv[i];
  e += qc_load_service(libpath);
 }
 globfree(&glb);
 return i;
}

variable_types:
dir
char *

variable_types:
path
char [256]

variable_types: i int

variable_types:
libpath
char *

variable_types: e int

variable_types: struct glob_t { unsigned long gl_pathc; char **gl_pathv; unsigned long gl_offs; int gl_flags; void (*gl_closedir)(void *); void *(*gl_readdir)(void *); void *(*gl_opendir)(char *); int (*gl_lstat)(char *, void *); int (*gl_stat)(char *, void *); }


decompiled_code:
__int64 __fastcall qc_unload_service(char *a1)
{
__int64 v1; // rax

v1 = lookup_qhgpu_sitem(a1);
return _unload_service(v1);
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
__int64 v1; // rax

v1 = func3(a1);
return func6(v1);
}

original_code:
int qc_unload_service(const char *name)
{
    return __unload_service(lookup_qhgpu_sitem(name));
}

canonical_original_code:
int qc_unload_service(char *name)
{
    return __unload_service(lookup_qhgpu_sitem(name));
}


decompiled_code:
int qhgpu_log(int a1, const char *a2, const char *a3, __int64 a4, const char *a5, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 == 2 )
{
printf("[%s] %s() %d DEBUG: ", a2, a3, a4);
goto LABEL_6;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
printf("[%s] %s() %d INFO: ", a2, a3, a4);
goto LABEL_6;
}
LABEL_10:
printf("[%s] %s() %d: ", a2, a3, a4);
goto LABEL_6;
}
if ( !a1 )
{
printf("[%s] %s() %d ERROR: ", a2, a3, a4);
goto LABEL_6;
}
if ( a1 != 1 )
goto LABEL_10;
printf("[%s] %s() %d ALERT: ", a2, a3, a4);
LABEL_6:
va_start(arg, a5);
return vprintf(a5, arg);
}

canonical_decompiled_code:
int func0(int a1, const char *a2, const char *a3, __int64 a4, const char *a5, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a1 == 2 )
{
printf("[%s] %s() %d DEBUG: ", a2, a3, a4);
goto LABEL_6;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
printf("[%s] %s() %d INFO: ", a2, a3, a4);
goto LABEL_6;
}
LABEL_10:
printf("[%s] %s() %d: ", a2, a3, a4);
goto LABEL_6;
}
if ( !a1 )
{
printf("[%s] %s() %d ERROR: ", a2, a3, a4);
goto LABEL_6;
}
if ( a1 != 1 )
goto LABEL_10;
printf("[%s] %s() %d ALERT: ", a2, a3, a4);
LABEL_6:
va_start(arg, a5);
return vprintf(a5, arg);
}

original_code:
void qhgpu_log(int level, const char* module, const char *func, int line_num, const char *fmt, ...) {
 va_list args;
 switch(level) {
 case 0:
  printf("[%s] %s() %d ERROR: ", module, func, line_num);
  break;
 case 1:
  printf("[%s] %s() %d ALERT: ", module, func, line_num);
  break;
 case 2:
  printf("[%s] %s() %d DEBUG: ", module, func, line_num);
  break;
 case 3:
  printf("[%s] %s() %d INFO: ", module, func, line_num);
  break;
 case 4:
 default:
  printf("[%s] %s() %d: ", module, func, line_num);
  break;
 }
 __builtin_va_start(args,fmt);
 vprintf(fmt, args);
 __builtin_va_end(args);
}

canonical_original_code:
void qhgpu_log(int level, char *module, char *func, int line_num, char *fmt, ...) {
 __builtin_va_list args;
 switch(level) {
 case 0:
  printf("[%s] %s() %d ERROR: ", module, func, line_num);
  break;
 case 1:
  printf("[%s] %s() %d ALERT: ", module, func, line_num);
  break;
 case 2:
  printf("[%s] %s() %d DEBUG: ", module, func, line_num);
  break;
 case 3:
  printf("[%s] %s() %d INFO: ", module, func, line_num);
  break;
 case 4:
 default:
  printf("[%s] %s() %d: ", module, func, line_num);
  break;
 }
 __builtin_va_start(args,fmt);
 vprintf(fmt, args);
 __builtin_va_end(args);
}

variable_types: level int

variable_types:
module
char *

variable_types:
func
char *

variable_types:
fmt
char *


decompiled_code:
int __fastcall print_ip(unsigned int a1)
{
return printf("%3d.%3d.%3d.%3d", HIBYTE(a1), BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
return printf("%3d.%3d.%3d.%3d", HIBYTE(a1), BYTE2(a1), BYTE1(a1), (unsigned __int8)a1);
}

original_code:
void print_ip(int ip) {
 unsigned char bytes[4];
 bytes[0] = ip & 0xFF;
 bytes[1] = (ip >> 8) & 0xFF;
 bytes[2] = (ip >> 16) & 0xFF;
 bytes[3] = (ip >> 24) & 0xFF;
 printf("%3d.%3d.%3d.%3d", bytes[3], bytes[2], bytes[1], bytes[0]);
}

variable_types: ip int

variable_types:
bytes
unsigned char [4]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
int result; // eax

if ( argc <= 1 )
{
fwrite("Option error\nNF Queue Num default setting 0.\n", 1uLL, 0x2DuLL, _bss_start);
result = netlink_init(0LL);
}
else
{
v3 = (unsigned int)atoi(argv[1]);
result = netlink_init(v3);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
int result; // eax

if ( argc <= 1 )
{
fwrite("Option error\nNF Queue Num default setting 0.\n", 1uLL, 0x2DuLL, _bss_start);
result = func12(0LL);
}
else
{
v3 = (unsigned int)atoi(argv[1]);
result = func12(v3);
}
return result;
}

original_code:
int main(int argc, char **argv) {
 int q_num = 0;
 if (argc < 2) {
  fprintf(stderr, "Option error\nNF Queue Num default setting 0.\n");
  q_num = 0;
 } else
  q_num = atoi(argv[1]);
 return netlink_init(q_num);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall finit_service(__int64 a1, __int64 (__fastcall *a2)(char *))
{
puts("[libsrv_default] Info: finit default service");
return a2(default_srv);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 (__fastcall *a2)(char *))
{
puts("[libsrv_default] Info: finit default service");
return a2(default_srv);
}

original_code:
int finit_service(void *lh, int (*unreg_srv)(const char*))
{
 printf("[libsrv_default] Info: mmap_ioctl_test finit\n");
 return unreg_srv(mmap_ioctl_srv.name);
}

canonical_original_code:
int finit_service(void *lh, int (*unreg_srv)(char *))
{
 printf("[libsrv_default] Info: mmap_ioctl_test finit\n");
 return unreg_srv(mmap_ioctl_srv.name);
}

variable_types:
lh
void *


decompiled_code:
__int64 __fastcall finit_service(__int64 a1, __int64 (__fastcall *a2)(__int128 *))
{
puts("[libsrv_default] Info: mmap_ioctl_test finit");
return a2(&mmap_ioctl_srv);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 (__fastcall *a2)(__int128 *))
{
puts("[libsrv_default] Info: mmap_ioctl_test finit");
return a2(&mmap_ioctl_srv);
}


repo: Queeniebee/Practice

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
gtk_init();
gtk_window_new();
g_type_check_instance_cast();
g_signal_connect_data();
gtk_label_new();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
gtk_widget_show_all();
gtk_main();
return 0;
}

original_code:
int main(void)
{
  printf("Hello World\n");
  return 0;
}

canonical_original_code:
int main()
{
  printf("Hello World\n");
  return 0;
}


repo: QuentinBarrand/ENSIIE-IALP-solitaire

decompiled_code:
int create_color()
{
start_color();
init_pair(1, 7, 0);
init_pair(2, 1, 0);
return init_pair(3, 2, 0);
}

canonical_decompiled_code:
int func0()
{
start_color();
init_pair(1, 7, 0);
init_pair(2, 1, 0);
return init_pair(3, 2, 0);
}

original_code:
static void create_color()
{
    start_color();
    init_pair(1, 7, 0);
    init_pair(2, 1, 0);
    init_pair(3, 2, 0);
}


decompiled_code:
int __fastcall Sgui_Help(int a1, int a2)
{
int v2; // er12
int result; // eax

v2 = 3 * a1 + 16;
if ( a2 == 1 )
{
mvprintw(4, v2, "Aide :");
mvprintw(6, v2, aLnnlnnCoordonn);
mvprintw(7, v2, "\tL : lettre");
mvprintw(8, v2, "\tnn : chiffres");
mvprintw(9, v2, aPRevenirAuCoup);
mvprintw(10, v2, "i : Indication");
mvprintw(12, v2, "? : Cacher cette aide");
result = mvprintw(13, v2, "q : Quitter");
}
else
{
if ( wmove(stdscr, 4, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 6, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 7, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 8, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 9, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 10, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
result = wmove(stdscr, 11, v2);
if ( result != -1 )
result = whline(stdscr, 0x20uLL, COLS - 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
int v2; // er12
int result; // eax

v2 = 3 * a1 + 16;
if ( a2 == 1 )
{
mvprintw(4, v2, "Aide :");
mvprintw(6, v2, aLnnlnnCoordonn);
mvprintw(7, v2, "\tL : lettre");
mvprintw(8, v2, "\tnn : chiffres");
mvprintw(9, v2, aPRevenirAuCoup);
mvprintw(10, v2, "i : Indication");
mvprintw(12, v2, "? : Cacher cette aide");
result = mvprintw(13, v2, "q : Quitter");
}
else
{
if ( wmove(stdscr, 4, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 6, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 7, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 8, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 9, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
if ( wmove(stdscr, 10, v2) != -1 )
whline(stdscr, 0x20uLL, COLS - 1);
result = wmove(stdscr, 11, v2);
if ( result != -1 )
result = whline(stdscr, 0x20uLL, COLS - 1);
}
return result;
}

original_code:
extern void Sgui_Help(int table_width, int print)
{
    int x_offset = 6 + table_width * 3 + 10;
    int y_offset = 4;
    if(print == 1)
    {
        mvprintw(y_offset, x_offset, "Aide :");
        mvprintw(y_offset + 2, x_offset, "LnnLnn : coordonnées");
        mvprintw(y_offset + 3, x_offset, "\tL : lettre");
        mvprintw(y_offset + 4, x_offset, "\tnn : chiffres");
        mvprintw(y_offset + 5, x_offset, "p : Revenir au coup "
            "précédent");
        mvprintw(y_offset + 6, x_offset, "i : Indication");
        mvprintw(y_offset + 8, x_offset, "? : Cacher cette "
            "aide");
        mvprintw(y_offset + 9, x_offset, "q : Quitter");
    }
    else
    {
        (wmove((stdscr),((y_offset)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 2)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 3)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 4)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 5)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 6)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
        (wmove((stdscr),((y_offset + 7)),((x_offset))) == (-1) ? (-1) : whline((stdscr),((' ')),((COLS - 1))));
    }
}

variable_types: print int


decompiled_code:
size_t __fastcall Sgui_ReadCoup(char *s)
{
echo();
mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
wgetnstr(stdscr, s, -1);
noecho();
return strlen(s);
}

canonical_decompiled_code:
size_t __fastcall func3(char *s)
{
echo();
mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
wgetnstr(stdscr, s, -1);
noecho();
return strlen(s);
}

original_code:
extern int Sgui_ReadCoup(char* userinput)
{
    echo();
    mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
    wgetnstr(stdscr, (userinput), -1);
    noecho();
    return strlen(userinput);
}

canonical_original_code:
extern int Sgui_ReadCoup(char *userinput)
{
    echo();
    mvprintw(LINES - 2, 0, "Saisissez un coup (? pour l'aide) : ");
    wgetnstr(stdscr, (userinput), -1);
    noecho();
    return strlen(userinput);
}

variable_types:
userinput
char *


decompiled_code:
int __fastcall Sgui_RuntimeMessage(char *a1, int a2)
{
if ( a2 == 1 )
{
wattr_on(stdscr, 0x300uLL, 0LL);
}
else if ( a2 == 2 )
{
wattr_on(stdscr, 0x200uLL, 0LL);
}
mvprintw(LINES - 1, 0, a1);
wrefresh(stdscr);
create_color();
wattr_on(stdscr, 0x100uLL, 0LL);
sleep(3u);
if ( wmove(stdscr, LINES - 1, 0) != -1 )
whline(stdscr, 0x20uLL, COLS);
if ( wmove(stdscr, LINES - 2, 36) != -1 )
whline(stdscr, 0x20uLL, COLS - 36);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func4(char *a1, int a2)
{
if ( a2 == 1 )
{
wattr_on(stdscr, 0x300uLL, 0LL);
}
else if ( a2 == 2 )
{
wattr_on(stdscr, 0x200uLL, 0LL);
}
mvprintw(LINES - 1, 0, a1);
wrefresh(stdscr);
func0();
wattr_on(stdscr, 0x100uLL, 0LL);
sleep(3u);
if ( wmove(stdscr, LINES - 1, 0) != -1 )
whline(stdscr, 0x20uLL, COLS);
if ( wmove(stdscr, LINES - 2, 36) != -1 )
whline(stdscr, 0x20uLL, COLS - 36);
return wrefresh(stdscr);
}

variable_types:
message
char *

variable_types: enum message_type { INFO=0, SUCCESS=1, ERROR=2 }