decompiled_code:
char *__fastcall SubnetCalc_get_info_by_subnets(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = (unsigned int)IP_host_bits_by_subnets();
v3 = IP_private_ip(v2, a2);
if ( (_DWORD)v2 != -1 && v3 != -1 )
return (char *)SubnetCalc_get_info_by_ip_and_subnets(v3, a1);
sprintf(info, "error Too many subnets, %lu for %lx or IP private failed", a1, v3);
return info;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = (unsigned int)IP_host_bits_by_subnets();
v3 = IP_private_ip(v2, a2);
if ( (_DWORD)v2 != -1 && v3 != -1 )
return (char *)SubnetCalc_get_info_by_ip_and_subnets(v3, a1);
sprintf(info, "error Too many subnets, %lu for %lx or IP private failed", a1, v3);
return info;
}

original_code:
extern char* SubnetCalc_get_info_by_subnets(
  subnet_size_t subnets, int id) {
 int host_bits = IP_host_bits_by_subnets(subnets);
 IP_T ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many subnets, %lu for %lx or IP private failed", subnets, ip); return info; } } while(0);
 return SubnetCalc_get_info_by_ip_and_subnets(ip, subnets);
}

canonical_original_code:
extern char *SubnetCalc_get_info_by_subnets(unsigned long subnets, int id) {
 int host_bits = IP_host_bits_by_subnets(subnets);
 unsigned long ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many subnets, %lu for %lx or IP private failed", subnets, ip); return info; } } while(0);
 return SubnetCalc_get_info_by_ip_and_subnets(ip, subnets);
}

variable_types:
subnets
unsigned long


repo: urbo-escom/c-ip-subnetting

decompiled_code:
char *get_time()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

canonical_decompiled_code:
char *func1()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

original_code:
static char* get_time() {
 time_t timer;
 struct tm* tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

canonical_original_code:
static char *get_time() {
 long timer;
 struct tm *tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

variable_types: timer long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

return_type: char *


decompiled_code:
__int64 __fastcall IP_ip_to_dot_decimal(__int64 a1, char *a2)
{
char *v2; // rax
unsigned __int64 v3; // r14
unsigned __int64 v4; // r13
unsigned __int64 v5; // r12
unsigned __int64 v6; // rax
char *v7; // rax

v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Adress to be written: %lx\n",
v2,
"src/subnetting/ip_util_ip_to_dot_decimal.c",
14LL,
a1);
v3 = octect(a1, 0);
v4 = octect(a1, 1);
v5 = octect(a1, 2);
v6 = octect(a1, 3);
sprintf(a2, "%lu.%lu.%lu.%lu", v6, v5, v4, v3);
v7 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Address written: %s\n", v7, "src/subnetting/ip_util_ip_to_dot_decimal.c", 21LL, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2)
{
char *v2; // rax
unsigned __int64 v3; // r14
unsigned __int64 v4; // r13
unsigned __int64 v5; // r12
unsigned __int64 v6; // rax
char *v7; // rax

v2 = func1();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Adress to be written: %lx\n",
v2,
"src/subnetting/ip_util_ip_to_dot_decimal.c",
14LL,
a1);
v3 = func0(a1, 0);
v4 = func0(a1, 1);
v5 = func0(a1, 2);
v6 = func0(a1, 3);
sprintf(a2, "%lu.%lu.%lu.%lu", v6, v5, v4, v3);
v7 = func1();
fprintf(stderr, "[DEBUG]%s (%s:%d) Address written: %s\n", v7, "src/subnetting/ip_util_ip_to_dot_decimal.c", 21LL, a2);
return 0LL;
}

original_code:
extern int IP_ip_to_dot_decimal(IP_T ip, char* address) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Adress to be written: %lx" "\n", get_time(), "src/subnetting/ip_util_ip_to_dot_decimal.c", 14, ip);
 sprintf(address, "%lu.%lu.%lu.%lu",
         octect(ip, 3),
  octect(ip, 2),
  octect(ip, 1),
  octect(ip, 0));
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Address written: %s" "\n", get_time(), "src/subnetting/ip_util_ip_to_dot_decimal.c", 21, address);
 return 0;
}

canonical_original_code:
extern int IP_ip_to_dot_decimal(unsigned long ip, char *address) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Adress to be written: %lx" "\n", get_time(), "src/subnetting/ip_util_ip_to_dot_decimal.c", 14, ip);
 sprintf(address, "%lu.%lu.%lu.%lu",
         octect(ip, 3),
  octect(ip, 2),
  octect(ip, 1),
  octect(ip, 0));
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Address written: %s" "\n", get_time(), "src/subnetting/ip_util_ip_to_dot_decimal.c", 21, address);
 return 0;
}

variable_types:
ip
unsigned long

variable_types:
address
char *

return_type: int


decompiled_code:
__int64 __fastcall get_hosts_per_subnet(__int64 a1, char a2)
{
return (1LL << ((unsigned __int8)IP_host_bits() - a2)) - 2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
return (1LL << ((unsigned __int8)IP_host_bits() - a2)) - 2;
}

original_code:
static host_size_t get_hosts_per_subnet(IP_T ip, int subnet_bits) {
 return (1L << (IP_host_bits(ip) - subnet_bits)) - 2;
}

canonical_original_code:
static unsigned long get_hosts_per_subnet(unsigned long ip, int subnet_bits) {
 return (1L << (IP_host_bits(ip) - subnet_bits)) - 2;
}

return_type: unsigned long


canonical_decompiled_code:
char *func2()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
__int64 __fastcall IP_subnet_bits_by_total_hosts(__int64 a1, unsigned __int64 a2)
{
int v2; // ebx
char *v3; // rax
unsigned int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbp
char *v7; // rax
char *v8; // rax
char *v9; // rax
int v10; // edi
char *v11; // rbx
char *v12; // rax
char *v14; // rax
signed int v15; // [rsp+Ch] [rbp-3Ch]

v2 = IP_host_bits();
v3 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Searching suitable subnetting for %lx with %lu total hosts\n",
v3,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
21LL,
a1,
a2);
v15 = v2 - 1;
if ( a2 && v2 - 1 > 2 )
{
v4 = 2;
while ( 1 )
{
v5 = get_hosts_per_subnet(a1, v4);
v6 = get_total_subnets(a1, v4);
v7 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---hosts/subnet: %lu\n",
v7,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
29LL,
v5);
v8 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---total subnets: %lu\n",
v8,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
30LL,
v6);
v9 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---total hosts: %lu\n",
v9,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
31LL,
v6 * v5);
if ( a2 <= v6 * v5 )
break;
if ( (int)++v4 >= v15 )
goto LABEL_6;
}
v14 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found with %d bits\n",
v14,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
33LL,
v4);
}
else
{
LABEL_6:
IP_set_strerror("IP %lx can't handle %lu total hosts", a1, a2);
v10 = *_errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
v12 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Subnetting bits failed\n",
v12,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
41LL,
v11);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
int v2; // ebx
char *v3; // rax
unsigned int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbp
char *v7; // rax
char *v8; // rax
char *v9; // rax
int v10; // edi
char *v11; // rbx
char *v12; // rax
char *v14; // rax
signed int v15; // [rsp+Ch] [rbp-3Ch]

v2 = IP_host_bits();
v3 = func2();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Searching suitable subnetting for %lx with %lu total hosts\n",
v3,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
21LL,
a1,
a2);
v15 = v2 - 1;
if ( a2 && v2 - 1 > 2 )
{
v4 = 2;
while ( 1 )
{
v5 = func1(a1, v4);
v6 = func0(a1, v4);
v7 = func2();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---hosts/subnet: %lu\n",
v7,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
29LL,
v5);
v8 = func2();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---total subnets: %lu\n",
v8,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
30LL,
v6);
v9 = func2();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---total hosts: %lu\n",
v9,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
31LL,
v6 * v5);
if ( a2 <= v6 * v5 )
break;
if ( (int)++v4 >= v15 )
goto LABEL_6;
}
v14 = func2();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found with %d bits\n",
v14,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
33LL,
v4);
}
else
{
LABEL_6:
IP_set_strerror("IP %lx can't handle %lu total hosts", a1, a2);
v10 = *_errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
v12 = func2();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Subnetting bits failed\n",
v12,
"src/subnetting/ip_util_subnet_bits_by_total_hosts.c",
41LL,
v11);
v4 = -1;
}
return v4;
}

original_code:
extern int IP_subnet_bits_by_total_hosts(
  IP_T ip, host_size_t total_hosts) {
 int i;
 int host_bits = IP_host_bits(ip);
 host_size_t hosts_per_subnet;
 host_size_t total_subnets;
 host_size_t total;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Searching suitable subnetting for %lx with %lu total hosts" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 21, ip, total_hosts);
 for(i = 2; (i < host_bits - 1) && (0UL < total_hosts); i++) {
  hosts_per_subnet = get_hosts_per_subnet(ip, i);
  total_subnets = get_total_subnets(ip, i);
  total = hosts_per_subnet*total_subnets;
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---hosts/subnet: %lu" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 29, hosts_per_subnet);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---total subnets: %lu" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 30, total_subnets);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---total hosts: %lu" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 31, total);
  if (total_hosts <= total) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found with %d bits" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 33, i);
   return i;
  }
 }
 IP_set_strerror(
  "IP %lx can't handle %lu total hosts",
  ip, total_hosts);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Subnetting bits failed" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 41, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
 return -1;
}

canonical_original_code:
extern int IP_subnet_bits_by_total_hosts(unsigned long ip, unsigned long total_hosts) {
 int i;
 int host_bits = IP_host_bits(ip);
 unsigned long hosts_per_subnet;
 unsigned long total_subnets;
 unsigned long total;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Searching suitable subnetting for %lx with %lu total hosts" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 21, ip, total_hosts);
 for(i = 2; (i < host_bits - 1) && (0UL < total_hosts); i++) {
  hosts_per_subnet = get_hosts_per_subnet(ip, i);
  total_subnets = get_total_subnets(ip, i);
  total = hosts_per_subnet*total_subnets;
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---hosts/subnet: %lu" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 29, hosts_per_subnet);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---total subnets: %lu" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 30, total_subnets);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---total hosts: %lu" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 31, total);
  if (total_hosts <= total) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found with %d bits" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 33, i);
   return i;
  }
 }
 IP_set_strerror(
  "IP %lx can't handle %lu total hosts",
  ip, total_hosts);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Subnetting bits failed" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_total_hosts.c", 41, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
 return -1;
}

variable_types: i int

variable_types:
total
unsigned long


decompiled_code:
__int64 __fastcall IP_subnets_size(char a1)
{
return (1LL << a1) - 2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return (1LL << a1) - 2;
}

original_code:
extern subnet_size_t IP_subnets_size(int subnet_bits) {
 return (1L << subnet_bits) - 2;
}

canonical_original_code:
extern unsigned long IP_subnets_size(int subnet_bits) {
 return (1L << subnet_bits) - 2;
}


canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}


decompiled_code:
__int64 __fastcall Socket_bind(__int64 a1)
{
char *v2; // rax
int v3; // eax
char *v4; // rax
char *v5; // rax
unsigned int v6; // ebx
char *v7; // rax
const char *v9; // rbp
int v10; // edi
char *v11; // r12
char *v12; // rax
const char *v13; // rbx
int v14; // edi
char *v15; // r12
char *v16; // rax
const char *v17; // rbp
int v18; // edi
char *v19; // r12
char *v20; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Obtaining socket\n", v2, "src/network/bsd-win-sock-bind.c", 9LL);
v3 = socket(
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 4LL),
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 8LL),
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 12LL));
*(_DWORD *)(a1 + 4) = v3;
if ( v3 == -1 )
{
v6 = -1;
Socket_set_errno(4294967291LL);
v9 = (const char *)Socket_strerror();
v10 = *_errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
v12 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Got an invalid socket: %s\n",
v12,
"src/network/bsd-win-sock-bind.c",
16LL,
v11,
v9);
}
else
{
optval[0] = 1;
v4 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting socket for reuse address\n", v4, "src/network/bsd-win-sock-bind.c", 28LL);
if ( setsockopt(*(_DWORD *)(a1 + 4), 1, 2, optval, 4u) == -1 )
{
Socket_set_errno(4294967281LL);
v13 = (const char *)Socket_strerror();
v14 = *_errno_location();
v15 = "None";
if ( v14 )
v15 = strerror(v14);
v16 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Can't reuse address: %s\n",
v16,
"src/network/bsd-win-sock-bind.c",
32LL,
v15,
v13);
}
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Binding socket\n", v5, "src/network/bsd-win-sock-bind.c", 35LL);
v6 = bind(
*(_DWORD *)(a1 + 4),
*(const struct sockaddr **)(*(_QWORD *)(a1 + 56) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 16LL));
if ( v6 == -1 )
{
Socket_set_errno(4294967289LL);
v17 = (const char *)Socket_strerror();
v18 = *_errno_location();
v19 = "None";
if ( v18 )
v19 = strerror(v18);
v20 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Bind failed: %s\n",
v20,
"src/network/bsd-win-sock-bind.c",
41LL,
v19,
v17);
}
else
{
v7 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket bind succeded\n", v7, "src/network/bsd-win-sock-bind.c", 46LL);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v2; // rax
int v3; // eax
char *v4; // rax
char *v5; // rax
unsigned int v6; // ebx
char *v7; // rax
const char *v9; // rbp
int v10; // edi
char *v11; // r12
char *v12; // rax
const char *v13; // rbx
int v14; // edi
char *v15; // r12
char *v16; // rax
const char *v17; // rbp
int v18; // edi
char *v19; // r12
char *v20; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Obtaining socket\n", v2, "src/network/bsd-win-sock-bind.c", 9LL);
v3 = socket(
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 4LL),
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 8LL),
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 12LL));
*(_DWORD *)(a1 + 4) = v3;
if ( v3 == -1 )
{
v6 = -1;
Socket_set_errno(4294967291LL);
v9 = (const char *)Socket_strerror();
v10 = *_errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
v12 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Got an invalid socket: %s\n",
v12,
"src/network/bsd-win-sock-bind.c",
16LL,
v11,
v9);
}
else
{
optval[0] = 1;
v4 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting socket for reuse address\n", v4, "src/network/bsd-win-sock-bind.c", 28LL);
if ( setsockopt(*(_DWORD *)(a1 + 4), 1, 2, optval, 4u) == -1 )
{
Socket_set_errno(4294967281LL);
v13 = (const char *)Socket_strerror();
v14 = *_errno_location();
v15 = "None";
if ( v14 )
v15 = strerror(v14);
v16 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Can't reuse address: %s\n",
v16,
"src/network/bsd-win-sock-bind.c",
32LL,
v15,
v13);
}
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Binding socket\n", v5, "src/network/bsd-win-sock-bind.c", 35LL);
v6 = bind(
*(_DWORD *)(a1 + 4),
*(const struct sockaddr **)(*(_QWORD *)(a1 + 56) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 16LL));
if ( v6 == -1 )
{
Socket_set_errno(4294967289LL);
v17 = (const char *)Socket_strerror();
v18 = *_errno_location();
v19 = "None";
if ( v18 )
v19 = strerror(v18);
v20 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Bind failed: %s\n",
v20,
"src/network/bsd-win-sock-bind.c",
41LL,
v19,
v17);
}
else
{
v7 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket bind succeded\n", v7, "src/network/bsd-win-sock-bind.c", 46LL);
}
}
return v6;
}

original_code:
extern int Socket_bind(Socket_T* sock) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Obtaining socket" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 9);
 sock->sockfd_src = socket(sock->result->ai_family,
                           sock->result->ai_socktype,
                           sock->result->ai_protocol);
 if (sock->sockfd_src == -1) {
  Socket_set_errno(-5);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Got an invalid socket: %s" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 16, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 int yes = 1;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting socket for reuse address" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 28);
 if (setsockopt(sock->sockfd_src, 1, 2,
                (&yes), sizeof(yes)) == -1) {
  Socket_set_errno(-15);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Can't reuse address: %s" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 32, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Binding socket" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 35);
 int value = bind(sock->sockfd_src, sock->result->ai_addr,
                  (socklen_t)(sock->result->ai_addrlen));
 if (value == -1) {
  Socket_set_errno(-7);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Bind failed: %s" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 41, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket bind succeded" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 46);
 return value;
}

canonical_original_code:
extern int Socket_bind(struct Socket_T *sock) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Obtaining socket" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 9);
 sock->sockfd_src = socket(sock->result->ai_family,
                           sock->result->ai_socktype,
                           sock->result->ai_protocol);
 if (sock->sockfd_src == -1) {
  Socket_set_errno(-5);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Got an invalid socket: %s" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 16, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 int yes = 1;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting socket for reuse address" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 28);
 if (setsockopt(sock->sockfd_src, 1, 2,
                (&yes), sizeof(yes)) == -1) {
  Socket_set_errno(-15);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Can't reuse address: %s" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 32, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Binding socket" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 35);
 int value = bind(sock->sockfd_src, sock->result->ai_addr,
                  (socklen_t)(sock->result->ai_addrlen));
 if (value == -1) {
  Socket_set_errno(-7);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Bind failed: %s" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 41, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket bind succeded" "\n", get_time(), "src/network/bsd-win-sock-bind.c", 46);
 return value;
}

variable_types: struct Socket_T { int sockfd_dest; int sockfd_src; struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; } *

variable_types: yes int

variable_types: value int

user_defined_types: struct Socket_T { int sockfd_dest; int sockfd_src; struct addrinfo hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
char *__fastcall SubnetCalc_subnetting_by_hosts(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

v4 = (unsigned int)IP_host_bits_by_total_hosts();
v5 = IP_private_ip(v4, a2);
if ( (_DWORD)v4 != -1 && v5 != -1 )
return (char *)SubnetCalc_subnetting_by_ip_and_hosts(v5, a1, a3);
sprintf(info, "error Too many hosts, %lu for %lx or private ip failed", v5, a1);
return info;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

v4 = (unsigned int)IP_host_bits_by_total_hosts();
v5 = IP_private_ip(v4, a2);
if ( (_DWORD)v4 != -1 && v5 != -1 )
return (char *)SubnetCalc_subnetting_by_ip_and_hosts(v5, a1, a3);
sprintf(info, "error Too many hosts, %lu for %lx or private ip failed", v5, a1);
return info;
}

original_code:
extern char* SubnetCalc_subnetting_by_hosts(
  host_size_t hosts, int id, Subnet subnet_number) {
 int host_bits = IP_host_bits_by_total_hosts(hosts);
 IP_T ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many hosts, %lu for %lx or private ip failed", ip, hosts); return info; } } while(0);
 return SubnetCalc_subnetting_by_ip_and_hosts(
  ip, hosts, subnet_number);
}

canonical_original_code:
extern char *SubnetCalc_subnetting_by_hosts(unsigned long hosts, int id, unsigned long subnet_number) {
 int host_bits = IP_host_bits_by_total_hosts(hosts);
 unsigned long ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many hosts, %lu for %lx or private ip failed", ip, hosts); return info; } } while(0);
 return SubnetCalc_subnetting_by_ip_and_hosts(
  ip, hosts, subnet_number);
}

variable_types:
hosts
unsigned long

variable_types: id int


decompiled_code:
char *__fastcall SubnetCalc_subnetting_by_hosts_per_subnet(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

v4 = (unsigned int)IP_host_bits_by_hosts_per_subnet();
v5 = IP_private_ip(v4, a2);
if ( (_DWORD)v4 != -1 && v5 != -1 )
return (char *)SubnetCalc_subnetting_by_ip_and_hosts(v5, a1, a3);
sprintf(info, "error Too many hosts/subnet, %lu for %lx or private ip failed", v5, a1);
return info;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

v4 = (unsigned int)IP_host_bits_by_hosts_per_subnet();
v5 = IP_private_ip(v4, a2);
if ( (_DWORD)v4 != -1 && v5 != -1 )
return (char *)SubnetCalc_subnetting_by_ip_and_hosts(v5, a1, a3);
sprintf(info, "error Too many hosts/subnet, %lu for %lx or private ip failed", v5, a1);
return info;
}

original_code:
extern char* SubnetCalc_subnetting_by_hosts_per_subnet(
  host_size_t hosts_per_subnet, int id, Subnet subnet_number) {
 int host_bits = IP_host_bits_by_hosts_per_subnet(hosts_per_subnet);
 IP_T ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many hosts/subnet, %lu for %lx or private ip failed", ip, hosts_per_subnet); return info; } } while(0);
 return SubnetCalc_subnetting_by_ip_and_hosts(
  ip, hosts_per_subnet, subnet_number);
}

canonical_original_code:
extern char *SubnetCalc_subnetting_by_hosts_per_subnet(unsigned long hosts_per_subnet, int id, unsigned long subnet_number) {
 int host_bits = IP_host_bits_by_hosts_per_subnet(hosts_per_subnet);
 unsigned long ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many hosts/subnet, %lu for %lx or private ip failed", ip, hosts_per_subnet); return info; } } while(0);
 return SubnetCalc_subnetting_by_ip_and_hosts(
  ip, hosts_per_subnet, subnet_number);
}


decompiled_code:
char *__fastcall SubnetCalc_subnetting_by_subnets(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

v4 = (unsigned int)IP_host_bits_by_subnets();
v5 = IP_private_ip(v4, a2);
if ( (_DWORD)v4 != -1 && v5 != -1 )
return (char *)SubnetCalc_subnetting_by_ip_and_subnets(v5, a1, a3);
sprintf(info, "error Too many subnets, %lu for %lx or private ip failed", v5, a1);
return info;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

v4 = (unsigned int)IP_host_bits_by_subnets();
v5 = IP_private_ip(v4, a2);
if ( (_DWORD)v4 != -1 && v5 != -1 )
return (char *)SubnetCalc_subnetting_by_ip_and_subnets(v5, a1, a3);
sprintf(info, "error Too many subnets, %lu for %lx or private ip failed", v5, a1);
return info;
}

original_code:
extern char* SubnetCalc_subnetting_by_subnets(
  subnet_size_t subnets, int id, Subnet subnet_number) {
 int host_bits = IP_host_bits_by_subnets(subnets);
 IP_T ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many subnets, %lu for %lx or private ip failed", ip, subnets); return info; } } while(0);
 return SubnetCalc_subnetting_by_ip_and_subnets(
  ip, subnets, subnet_number);
}

canonical_original_code:
extern char *SubnetCalc_subnetting_by_subnets(unsigned long subnets, int id, unsigned long subnet_number) {
 int host_bits = IP_host_bits_by_subnets(subnets);
 unsigned long ip = IP_private_ip(host_bits, id);
 do{ if(host_bits == -1 || ip == -1) { sprintf(info, "error Too many subnets, %lu for %lx or private ip failed", ip, subnets); return info; } } while(0);
 return SubnetCalc_subnetting_by_ip_and_subnets(
  ip, subnets, subnet_number);
}


decompiled_code:
char *__fastcall SubnetCalcUtil_subnetting(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v5; // r15
__int64 v6; // r14
__int64 v7; // r13
int v8; // eax
const char *v9; // rdx
__int64 v10; // [rsp+0h] [rbp-98h]
__int64 v11; // [rsp+8h] [rbp-90h]
char s[2]; // [rsp+10h] [rbp-88h] BYREF

if ( (unsigned int)IP_is_valid_id() )
{
if ( (int)a2 > 1 && (int)(IP_host_bits(a1) - 1) > (int)a2 )
{
v5 = Subnet_subnet_id(a1, a2, a3);
v6 = Subnet_broadcast(a1, a2, a3);
v7 = Subnet_mask(a1, a2, a3);
v10 = Subnet_host_start(a1, a2, a3);
v11 = Subnet_host_end(a1, a2, a3);
sprintf(::s, "%lu ", a3);
v8 = Subnet_is_used(a1, a2, a3);
v9 = (const char *)&unk_641;
if ( !v8 )
v9 = (const char *)&unk_645;
sprintf(s, "%s ", v9);
strcat(::s, s);
IP_ip_to_dot_decimal(v5, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v6, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v7, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v10, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v11, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
}
else
{
sprintf(::s, "error Inadequate subnet bits (%d bits) for %lx", a2, a1);
}
}
else
{
sprintf(::s, "error Invalid ID for %lx", a1);
}
return ::s;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v5; // r15
__int64 v6; // r14
__int64 v7; // r13
int v8; // eax
const char *v9; // rdx
__int64 v10; // [rsp+0h] [rbp-98h]
__int64 v11; // [rsp+8h] [rbp-90h]
char s[2]; // [rsp+10h] [rbp-88h] BYREF

if ( (unsigned int)IP_is_valid_id() )
{
if ( (int)a2 > 1 && (int)(IP_host_bits(a1) - 1) > (int)a2 )
{
v5 = Subnet_subnet_id(a1, a2, a3);
v6 = Subnet_broadcast(a1, a2, a3);
v7 = Subnet_mask(a1, a2, a3);
v10 = Subnet_host_start(a1, a2, a3);
v11 = Subnet_host_end(a1, a2, a3);
sprintf(::s, "%lu ", a3);
v8 = Subnet_is_used(a1, a2, a3);
v9 = (const char *)&unk_641;
if ( !v8 )
v9 = (const char *)&unk_645;
sprintf(s, "%s ", v9);
strcat(::s, s);
IP_ip_to_dot_decimal(v5, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v6, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v7, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v10, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
IP_ip_to_dot_decimal(v11, s);
strcat(::s, s);
strcpy(s, " ");
strcat(::s, s);
}
else
{
sprintf(::s, "error Inadequate subnet bits (%d bits) for %lx", a2, a1);
}
}
else
{
sprintf(::s, "error Invalid ID for %lx", a1);
}
return ::s;
}

original_code:
extern char* SubnetCalcUtil_subnetting(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 if (!IP_is_valid_id(ip)) {
  sprintf(s, "error Invalid ID for %lx", ip);
  return s;
 } else if (!(1 < subnet_bits && subnet_bits < IP_host_bits(ip) - 1)) {
  sprintf(s, "error "
   "Inadequate subnet bits (%d bits) for %lx",
   subnet_bits, ip);
  return s;
 }
 IP_T net_id = Subnet_subnet_id(ip, subnet_bits, subnet_number);
 IP_T broadcast = Subnet_broadcast(ip, subnet_bits, subnet_number);
 IP_T mask = Subnet_mask(ip, subnet_bits, subnet_number);
 IP_T host_start = Subnet_host_start(ip, subnet_bits, subnet_number);
 IP_T host_end = Subnet_host_end(ip, subnet_bits, subnet_number);
 char aux[65];
 sprintf(s, "%lu ", subnet_number);
 sprintf(aux, "%s ", Subnet_is_used(ip, subnet_bits, subnet_number)?
  "yes":"no");
 strcat(s, aux);
 do{ IP_ip_to_dot_decimal(net_id, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(broadcast, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(mask, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(host_start, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(host_end, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 return s;
}

canonical_original_code:
extern char *SubnetCalcUtil_subnetting(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 if (!IP_is_valid_id(ip)) {
  sprintf(s, "error Invalid ID for %lx", ip);
  return s;
 } else if (!(1 < subnet_bits && subnet_bits < IP_host_bits(ip) - 1)) {
  sprintf(s, "error "
   "Inadequate subnet bits (%d bits) for %lx",
   subnet_bits, ip);
  return s;
 }
 unsigned long net_id = Subnet_subnet_id(ip, subnet_bits, subnet_number);
 unsigned long broadcast = Subnet_broadcast(ip, subnet_bits, subnet_number);
 unsigned long mask = Subnet_mask(ip, subnet_bits, subnet_number);
 unsigned long host_start = Subnet_host_start(ip, subnet_bits, subnet_number);
 unsigned long host_end = Subnet_host_end(ip, subnet_bits, subnet_number);
 char aux[65];
 sprintf(s, "%lu ", subnet_number);
 sprintf(aux, "%s ", Subnet_is_used(ip, subnet_bits, subnet_number)?
  "yes":"no");
 strcat(s, aux);
 do{ IP_ip_to_dot_decimal(net_id, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(broadcast, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(mask, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(host_start, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 do{ IP_ip_to_dot_decimal(host_end, aux); strcat(s, aux); sprintf(aux, " "); strcat(s, aux); } while(0);
 return s;
}

variable_types:
broadcast
unsigned long

variable_types:
mask
unsigned long

variable_types:
aux
char [65]


decompiled_code:
void __fastcall Socket_free(int **a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax

v1 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Freeing socket\n", v1, "src/network/bsd-win-sock-free.c", 10LL);
if ( (*a1)[1] != -1 )
{
v4 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Closing Socket fd src\n", v4, "src/network/bsd-win-sock-free.c", 12LL);
close((*a1)[1]);
(*a1)[1] = -1;
}
if ( **a1 != -1 )
{
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Closing Socket fd dest\n", v5, "src/network/bsd-win-sock-free.c", 18LL);
close(**a1);
**a1 = -1;
}
if ( *((_QWORD *)*a1 + 7) )
{
v2 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Freeing result\n", v2, "src/network/bsd-win-sock-free.c", 24LL);
freeaddrinfo(*((struct addrinfo **)*a1 + 7));
*((_QWORD *)*a1 + 7) = 0LL;
}
v3 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Freeing and nulling Socket_T pointer\n",
v3,
"src/network/bsd-win-sock-free.c",
29LL);
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(int **a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax

v1 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Freeing socket\n", v1, "src/network/bsd-win-sock-free.c", 10LL);
if ( (*a1)[1] != -1 )
{
v4 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Closing Socket fd src\n", v4, "src/network/bsd-win-sock-free.c", 12LL);
close((*a1)[1]);
(*a1)[1] = -1;
}
if ( **a1 != -1 )
{
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Closing Socket fd dest\n", v5, "src/network/bsd-win-sock-free.c", 18LL);
close(**a1);
**a1 = -1;
}
if ( *((_QWORD *)*a1 + 7) )
{
v2 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Freeing result\n", v2, "src/network/bsd-win-sock-free.c", 24LL);
freeaddrinfo(*((struct addrinfo **)*a1 + 7));
*((_QWORD *)*a1 + 7) = 0LL;
}
v3 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Freeing and nulling Socket_T pointer\n",
v3,
"src/network/bsd-win-sock-free.c",
29LL);
free(*a1);
*a1 = 0LL;
}

original_code:
extern void Socket_free(Socket_T** sock) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Freeing socket" "\n", get_time(), "src/network/bsd-win-sock-free.c", 10);
 if ((*sock)->sockfd_src != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Closing Socket fd src" "\n", get_time(), "src/network/bsd-win-sock-free.c", 12);
  close((*sock)->sockfd_src);
  (*sock)->sockfd_src = -1;
 }
 if ((*sock)->sockfd_dest != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Closing Socket fd dest" "\n", get_time(), "src/network/bsd-win-sock-free.c", 18);
  close((*sock)->sockfd_dest);
  (*sock)->sockfd_dest = -1;
 }
 if ((*sock)->result != ((void *)0)) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Freeing result" "\n", get_time(), "src/network/bsd-win-sock-free.c", 24);
  freeaddrinfo((*sock)->result);
  (*sock)->result = ((void *)0);
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Freeing and nulling Socket_T pointer" "\n", get_time(), "src/network/bsd-win-sock-free.c", 29);
 free(*sock);
 *sock = ((void *)0);
}

canonical_original_code:
extern void Socket_free(struct Socket_T **sock) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Freeing socket" "\n", get_time(), "src/network/bsd-win-sock-free.c", 10);
 if ((*sock)->sockfd_src != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Closing Socket fd src" "\n", get_time(), "src/network/bsd-win-sock-free.c", 12);
  close((*sock)->sockfd_src);
  (*sock)->sockfd_src = -1;
 }
 if ((*sock)->sockfd_dest != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Closing Socket fd dest" "\n", get_time(), "src/network/bsd-win-sock-free.c", 18);
  close((*sock)->sockfd_dest);
  (*sock)->sockfd_dest = -1;
 }
 if ((*sock)->result != ((void *)0)) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Freeing result" "\n", get_time(), "src/network/bsd-win-sock-free.c", 24);
  freeaddrinfo((*sock)->result);
  (*sock)->result = ((void *)0);
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Freeing and nulling Socket_T pointer" "\n", get_time(), "src/network/bsd-win-sock-free.c", 29);
 free(*sock);
 *sock = ((void *)0);
}

variable_types: struct Socket_T { int sockfd_dest; int sockfd_src; struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; } **

return_type: void


repo: QMonkey/HTTP-Web-Server

decompiled_code:
__int64 hello_handler()
{
fwrite("Hello world!\n", 1uLL, 0xDuLL, stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
fwrite("Hello world!\n", 1uLL, 0xDuLL, stdout);
return 0LL;
}

original_code:
int hello_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 fprintf(stdout,"Hello world!\n");
 return 0;
}

canonical_original_code:
int hello_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 fprintf(stdout,"Hello world!\n");
 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:
response
struct HTTP_Socket *

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


decompiled_code:
__int64 web_index_handler()
{
fwrite("Web Index\n", 1uLL, 0xAuLL, stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
fwrite("Web Index\n", 1uLL, 0xAuLL, stdout);
return 0LL;
}

original_code:
int web_index_handler(HTTP_Socket *request,HTTP_Socket *response)
{
 fprintf(stdout,"Web Index\n");
 return 0;
}

canonical_original_code:
int web_index_handler(struct HTTP_Socket *request, struct HTTP_Socket *response)
{
 fprintf(stdout,"Web Index\n");
 return 0;
}

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


decompiled_code:
__int64 index_handler()
{
fwrite("Index\n", 1uLL, 6uLL, stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
fwrite("Index\n", 1uLL, 6uLL, stdout);
return 0LL;
}

original_code:
int index_handler(HTTP_Socket *requdst,HTTP_Socket *response)
{
 fprintf(stdout,"Index\n");
 return 0;
}

canonical_original_code:
int index_handler(struct HTTP_Socket *requdst, struct HTTP_Socket *response)
{
 fprintf(stdout,"Index\n");
 return 0;
}


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
char v11[40]; // [rsp+0h] [rbp-78h] BYREF
__int64 v12; // [rsp+28h] [rbp-50h]
__int64 v13; // [rsp+30h] [rbp-48h]
__int64 v14; // [rsp+38h] [rbp-40h]
__int64 v15; // [rsp+40h] [rbp-38h]
__int64 v16; // [rsp+48h] [rbp-30h]
__int64 v17; // [rsp+50h] [rbp-28h]
__int64 v18; // [rsp+58h] [rbp-20h]
int v19; // [rsp+60h] [rbp-18h]
__int64 v20[2]; // [rsp+68h] [rbp-10h] BYREF

v20[0] = HTTP_URLTree_create_node("/", hello_handler, envp);
(*(void (__fastcall **)(_QWORD, _QWORD))(v20[0] + 24))(0LL, 0LL);
fprintf(stdout, "handler:\n");
HTTP_URLTree_destroy_node(v20[0]);
v20[0] = 0LL;
strcpy(v11, "/demo/http/web/server/index.html");
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0;
fwrite("HTTP_insert_node:\t", 1uLL, 0x12uLL, stdout);
v3 = HTTP_URLTree_insert_node(v20, v11, index_handler);
(*(void (__fastcall **)(_QWORD, _QWORD))(v3 + 24))(0LL, 0LL);
v4 = (_QWORD *)v20[0];
if ( v20[0] )
{
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", v11);
v5 = (void (__fastcall *)(_QWORD, _QWORD))HTTP_URLTree_node_value(v20[0], v11);
v5(0LL, 0LL);
strcpy(v11, "/demo/http/web/index.html");
fwrite("HTTP_insert_node:\t", 1uLL, 0x12uLL, stdout);
v6 = HTTP_URLTree_insert_node(v20, v11, web_index_handler);
(*(void (__fastcall **)(_QWORD, _QWORD))(v6 + 24))(0LL, 0LL);
fprintf(stdout, "HTTP_node_value:\t%s\t", v11);
v7 = (void (__fastcall *)(_QWORD, _QWORD))HTTP_URLTree_node_value(v20[0], v11);
v7(0LL, 0LL);
strcpy(v11, "/demo/http/web/");
fwrite("HTTP_insert_node:\t", 1uLL, 0x12uLL, stdout);
v8 = HTTP_URLTree_insert_node(v20, v11, web_index_handler);
(*(void (__fastcall **)(_QWORD, _QWORD))(v8 + 24))(0LL, 0LL);
fprintf(stdout, "HTTP_node_value:\t%s\t", v11);
v9 = (void (__fastcall *)(_QWORD, _QWORD))HTTP_URLTree_node_value(v20[0], v11);
v9(0LL, 0LL);
fprintf(stdout, "HTTP_node_value:\t%s\t", "/home");
HTTP_URLTree_node_value(v20[0], "/home");
HTTP_URLTree_destroy(v20[0]);
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 *); }


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

variable_types: length int


decompiled_code:
__int64 __fastcall HTTP_Socket_get_header(__int64 a1, const char *a2, _BYTE *a3)
{
unsigned int v4; // ebp
size_t v5; // rbx
_BYTE *v6; // rax
char v7; // 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];
v7 = a3[v5];
if ( v7 == 32 )
{
do
v7 = *++v6;
while ( *v6 == 32 );
}
if ( v7 == 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; // ebp
size_t v5; // rbx
_BYTE *v6; // rax
char v7; // 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];
v7 = a3[v5];
if ( v7 == 32 )
{
do
v7 = *++v6;
while ( *v6 == 32 );
}
if ( v7 == 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 *


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_1BE, 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_1BE, 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)
{
int v4; // eax
__int64 v5; // rdx

if ( !a1 )
return 0LL;
v4 = HTTP_String_strcmp(*a1);
v5 = 0LL;
if ( v4 <= 0 )
{
if ( v4 )
v5 = HTTP_Param_node_value3(a1[2], a2, a3);
else
v5 = a1[1];
}
return v5;
}

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

if ( !a1 )
return 0LL;
v4 = HTTP_String_strcmp(*a1);
v5 = 0LL;
if ( v4 <= 0 )
{
if ( v4 )
v5 = func0(a1[2], a2, a3);
else
v5 = a1[1];
}
return v5;
}

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

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

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

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

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; // edx
_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; // edx
_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)
{
int v2; // er13
unsigned int i; // ebp
int v4; // eax
int v5; // ebx
_BYTE v7[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( !a1 )
return (unsigned int)-1;
if ( !HTTP_File_is_exists(a2) )
return (unsigned int)-1;
v2 = open(a2, 0);
for ( i = 0; ; i += v5 )
{
v4 = read(v2, v7, 0x1000uLL);
v5 = v4;
if ( v4 <= 0 )
break;
HTTP_String_write(a1, v7, (unsigned int)v4);
}
return i;
}

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

if ( !a1 )
return (unsigned int)-1;
if ( !func0(a2) )
return (unsigned int)-1;
v2 = open(a2, 0);
for ( i = 0; ; i += v5 )
{
v4 = read(v2, v7, 0x1000uLL);
v5 = v4;
if ( v4 <= 0 )
break;
HTTP_String_write(a1, v7, (unsigned int)v4);
}
return i;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = HTTP_File_read_all(*(_QWORD *)(a1 + 8));
if ( (_DWORD)result != -1 )
{
HTTP_Response_flush(a1);
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = HTTP_File_read_all(*(_QWORD *)(a1 + 8));
if ( (_DWORD)result != -1 )
{
HTTP_Response_flush(a1);
result = 0LL;
}
return result;
}

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:
__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:
__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; // rbx
int v2; // eax
__int64 v4[2]; // [rsp+0h] [rbp-3F8h] BYREF
char v5[984]; // [rsp+10h] [rbp-3E8h] BYREF

v1 = HTTP_Socket_create(a1);
v4[0] = 0LL;
v4[1] = 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; // rbx
int v2; // eax
__int64 v4[2]; // [rsp+0h] [rbp-3F8h] BYREF
char v5[984]; // [rsp+10h] [rbp-3E8h] BYREF

v1 = HTTP_Socket_create(a1);
v4[0] = 0LL;
v4[1] = 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 inp[2]; // [rsp+0h] [rbp-28h] BYREF

v3 = socket(2, 1, 0);
if ( v3 != -1 )
{
v4 = v3;
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
*(_WORD *)inp[0].sa_data = _bswap_16(9999);
inet_aton("0.0.0.0", (struct in_addr *)&inp[0].sa_data[2]);
if ( bind(v4, inp, 0x10u) != -1 )
{
if ( listen(v4, 100) == -1 )
{
perror("listen");
exit(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("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 inp[2]; // [rsp+0h] [rbp-28h] BYREF

v3 = socket(2, 1, 0);
if ( v3 != -1 )
{
v4 = v3;
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
*(_WORD *)inp[0].sa_data = func1(9999);
inet_aton("0.0.0.0", (struct in_addr *)&inp[0].sa_data[2]);
if ( bind(v4, inp, 0x10u) != -1 )
{
if ( listen(v4, 100) == -1 )
{
perror("listen");
exit(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("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

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post(a1, a2);
else
error404_handler(a1, a2);
}
else
{
do_get(a1, a2);
}
return 0LL;
}

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

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

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(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rax

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

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

if ( !a1 )
return 0LL;
v4 = *(_QWORD **)a1;
if ( **(_QWORD **)a1 != a2 )
return func0(v4 + 3);
v4[1] = a3;
HTTP_String_adjust_to(*(_QWORD *)(*(_QWORD *)a1 + 16LL), 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

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

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

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

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

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post(a1, a2);
else
error404_handler(a1, a2);
}
else
{
do_get(a1, a2);
}
return 0LL;
}

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

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post(a1, a2);
else
error404_handler(a1, a2);
}
else
{
do_get(a1, a2);
}
return 0LL;
}

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

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

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

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post(a1, a2);
else
error404_handler(a1, a2);
}
else
{
do_get(a1, a2);
}
return 0LL;
}

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]


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

v2 = HTTP_Request_get_method();
if ( v2 )
{
if ( v2 == 1 )
do_post(a1, a2);
else
error404_handler(a1, a2);
}
else
{
do_get(a1, a2);
}
return 0LL;
}

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
__int64 v3; // r13
int v4; // eax
void (__fastcall *v5)(__int64, __int64); // rax
__int64 v7[2]; // [rsp+0h] [rbp-10B8h] BYREF
char v8[4080]; // [rsp+10h] [rbp-10A8h] BYREF
fd_set readfds; // [rsp+1000h] [rbp-B8h] BYREF

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

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v1; // r14
__int64 v2; // r15
__int64 v3; // r13
int v4; // eax
void (__fastcall *v5)(__int64, __int64); // rax
__int64 v7[2]; // [rsp+0h] [rbp-10B8h] BYREF
char v8[4080]; // [rsp+10h] [rbp-10A8h] BYREF
fd_set readfds; // [rsp+1000h] [rbp-B8h] BYREF

v1 = ((__int64 (*)(void))HTTP_Socket_create)();
v2 = HTTP_Socket_create((unsigned int)a1);
memset(&readfds, 0, sizeof(readfds));
v3 = 1LL << ((int)a1 % 64);
readfds.fds_bits[(int)a1 / 64] |= v3;
do
{
while ( 1 )
{
v7[0] = 0LL;
v7[1] = 0LL;
memset(v8, 0, sizeof(v8));
v4 = select((_DWORD)a1 + 1, &readfds, 0LL, 0LL, 0LL);
if ( v4 != -1 )
break;
perror("select");
}
}
while ( !v4 || (readfds.fds_bits[(int)a1 / 64] & v3) == 0 );
HTTP_Request_init(v1);
*((_BYTE *)v7 + (int)HTTP_Request_get_url(v1, v7)) = 0;
v5 = (void (__fastcall *)(__int64, __int64))HTTP_Router_route(v7);
v5(v1, v2);
memset(&readfds, 0, sizeof(readfds));
HTTP_Socket_destroy(v1, 0LL);
HTTP_Socket_destroy(v2, 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]


repo: QMonkey/Thread-Pool

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)
{
printf("%d ", *a1);
*a1 = ++counter;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
printf("%d ", *a1);
*a1 = ++counter;
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 *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // rbp
int v5; // er14
int i; // ebx
int v7; // er12
__int64 v8; // rbx
__int64 v9; // rax
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]);
if ( v5 <= 0 )
{
putchar(10);
sleep(5u);
}
else
{
for ( i = 0; i != v5; ++i )
{
thread_pool_execute(v4, callback, &value);
v7 = i;
}
putchar(10);
sleep(5u);
v8 = 0LL;
do
{
thread_pool_execute(v4, callback_function, v8);
v9 = v8++;
}
while ( v9 != v7 );
}
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; // rbp
int v5; // er14
int i; // ebx
int v7; // er12
__int64 v8; // rbx
__int64 v9; // rax
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]);
if ( v5 <= 0 )
{
putchar(10);
sleep(5u);
}
else
{
for ( i = 0; i != v5; ++i )
{
func17(v4, callback, &value);
v7 = i;
}
putchar(10);
sleep(5u);
v8 = 0LL;
do
{
func17(v4, callback_function, v8);
v9 = v8++;
}
while ( v9 != v7 );
}
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:
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 *)

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

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

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:
void __fastcall task_queue_delete(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func12(void *a1)
{
free(a1);
}

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