prompt

decompiled_code:
__int64 prompt()
{
puts("imma run the interpreter.");
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
puts("imma run the interpreter.");
return 0LL;
}

original_code:
int prompt(void) {
  printf("imma run the interpreter.\n");
  return 0;
}

canonical_original_code:
int prompt() {
  printf("imma run the interpreter.\n");
  return 0;
}


script

repo: geekofhearts/lang

decompiled_code:
__int64 __fastcall script(int a1, const char **a2)
{
const char **v2; // rbx
__int64 v3; // rbp
const char *v4; // rsi

printf("imma run script called %s now with args ", *a2);
if ( a1 > 1 )
{
v2 = a2 + 1;
v3 = (__int64)&a2[(unsigned int)(a1 - 2) + 2];
do
{
v4 = *v2++;
printf("%s, ", v4);
}
while ( v2 != (const char **)v3 );
}
puts(" aaaand that's all.");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, const char **a2)
{
const char **v2; // rbx
__int64 v3; // rbp
const char *v4; // rsi

printf("imma run script called %s now with args ", *a2);
if ( a1 > 1 )
{
v2 = a2 + 1;
v3 = (__int64)&a2[(unsigned int)(a1 - 2) + 2];
do
{
v4 = *v2++;
printf("%s, ", v4);
}
while ( v2 != (const char **)v3 );
}
puts(" aaaand that's all.");
return 0LL;
}

original_code:
int script(int argc, char** argv) {
  printf("imma run script called %s now with args ", argv[0]);
  int i;
  for (i = 1; i < argc; i++) {
    printf("%s, ", argv[i]);
  }
  printf(" aaaand that's all.\n");
  return 0;
}

canonical_original_code:
int script(int argc, char **argv) {
  printf("imma run script called %s now with args ", argv[0]);
  int i;
  for (i = 1; i < argc; i++) {
    printf("%s, ", argv[i]);
  }
  printf(" aaaand that's all.\n");
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

return_type: int


decompiled_code:
void __fastcall ctype_variable_destructor(void **a1)
{
free(*a1);
free(a1[1]);
}

canonical_decompiled_code:
void __fastcall func16(void **a1)
{
free(*a1);
free(a1[1]);
}

original_code:
void ctype_variable_destructor(void* var) {
  variable_t* typed_var = (variable_t*)var;
  free(typed_var->name);
  free(typed_var->value);
}

canonical_original_code:
void ctype_variable_destructor(void *var) {
  struct variable_t *typed_var = (variable_t*)var;
  free(typed_var->name);
  free(typed_var->value);
}

variable_types:
var
void *

variable_types: struct variable_t { char *name; void *value; void (*destructor)(void *); } *

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
struct hostent *v4; // rax
char *v5; // r13
size_t v6; // rax
void *v7; // rax
__m128i v8; // xmm0
const void *v9; // r12
__m128i *v10; // rax
char *v11; // rdx
int v12; // ebp
__int16 v14; // [rsp+6h] [rbp-822h]
char *v15; // [rsp+8h] [rbp-820h]
struct sockaddr addr; // [rsp+10h] [rbp-818h] BYREF
char buf[2056]; // [rsp+20h] [rbp-808h] BYREF

puts("OpenWRT smart home v1.00a");
puts("http://smarthome.russemotto.com\n");
if ( argc <= 1 )
{
puts("\nI need a hostname");
}
else
{
v3 = argv[1];
v4 = gethostbyname(v3);
if ( v4 )
{
v5 = inet_ntoa((struct in_addr)(*(struct in_addr **)v4->h_addr_list)->s_addr);
pinMode(29LL, 0LL);
v14 = _bswap_16_constprop_0();
while ( 1 )
{
v12 = socket(2, 1, 0);
if ( v12 == -1 )
printf("Could not create socket");
*(_DWORD *)&addr.sa_data[2] = inet_addr(v5);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = v14;
if ( connect(v12, &addr, 0x10u) < 0 )
perror(" Error: connection failed.");
puts("Connected");
v6 = strlen(v3);
v7 = malloc(v6 + 54);
v8 = _mm_load_si128((const __m128i *)&xmmword_4020F0);
*((_QWORD *)v7 + 2) = 0x203A74736F480A0DLL;
v9 = v7;
*(__m128i *)v7 = v8;
v10 = (__m128i *)stpcpy((char *)v7 + 24, v3);
strcpy(v10[1].m128i_i8, "arthome\r\n\r\n");
*v10 = _mm_load_si128((const __m128i *)&xmmword_402100);
if ( send(v12, v9, (char *)v10 - (_BYTE *)v9 + 27, 0) < 0 )
printf("Error: Send failed");
if ( recv(v12, buf, 0x7D0uLL, 0) >= 0 )
{
puts("Server reply :");
puts(buf);
v11 = strstr(buf, "\r\n\r\n");
if ( v11 )
v11 += 4;
if ( *v11 == 111 && v11[1] == 110 )
{
v15 = v11;
printf("Turning on");
turnOn(2LL);
v11 = v15;
}
if ( *v11 == 111 && v11[1] == 102 && v11[2] == 102 )
{
printf("Turning off");
turnOff(2LL);
}
}
close(v12);
}
}
herror("gethostbyname");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
struct hostent *v4; // rax
char *v5; // r13
size_t v6; // rax
void *v7; // rax
__m128i v8; // xmm0
const void *v9; // r12
__m128i *v10; // rax
char *v11; // rdx
int v12; // ebp
__int16 v14; // [rsp+6h] [rbp-822h]
char *v15; // [rsp+8h] [rbp-820h]
struct sockaddr addr; // [rsp+10h] [rbp-818h] BYREF
char buf[2056]; // [rsp+20h] [rbp-808h] BYREF

puts("OpenWRT smart home v1.00a");
puts("http://smarthome.russemotto.com\n");
if ( argc <= 1 )
{
puts("\nI need a hostname");
}
else
{
v3 = argv[1];
v4 = gethostbyname(v3);
if ( v4 )
{
v5 = inet_ntoa((struct in_addr)(*(struct in_addr **)v4->h_addr_list)->s_addr);
func11(29LL, 0LL);
v14 = func7();
while ( 1 )
{
v12 = socket(2, 1, 0);
if ( v12 == -1 )
printf("Could not create socket");
*(_DWORD *)&addr.sa_data[2] = inet_addr(v5);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = v14;
if ( connect(v12, &addr, 0x10u) < 0 )
perror(" Error: connection failed.");
puts("Connected");
v6 = strlen(v3);
v7 = malloc(v6 + 54);
v8 = _mm_load_si128((const __m128i *)&xmmword_4020F0);
*((_QWORD *)v7 + 2) = 0x203A74736F480A0DLL;
v9 = v7;
*(__m128i *)v7 = v8;
v10 = (__m128i *)stpcpy((char *)v7 + 24, v3);
strcpy(v10[1].m128i_i8, "arthome\r\n\r\n");
*v10 = _mm_load_si128((const __m128i *)&xmmword_402100);
if ( send(v12, v9, (char *)v10 - (_BYTE *)v9 + 27, 0) < 0 )
printf("Error: Send failed");
if ( recv(v12, buf, 0x7D0uLL, 0) >= 0 )
{
puts("Server reply :");
puts(buf);
v11 = strstr(buf, "\r\n\r\n");
if ( v11 )
v11 += 4;
if ( *v11 == 111 && v11[1] == 110 )
{
v15 = v11;
printf("Turning on");
func18(2LL);
v11 = v15;
}
if ( *v11 == 111 && v11[1] == 102 && v11[2] == 102 )
{
printf("Turning off");
func17(2LL);
}
}
close(v12);
}
}
herror("gethostbyname");
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 char *ip;
 char *host;
 int sock;
 struct sockaddr_in server;
 char server_reply[2000];
 printf("OpenWRT smart home v1.00a\n");
 printf("http://smarthome.russemotto.com\n\n");
 if(argc <2)
 {
  printf("\nI need a hostname\n");
  return 0;
 }
 host = argv[1];
 struct hostent *h;
 if ((h=gethostbyname(host)) == ((void *)0)) {
  herror("gethostbyname");
  return 0;
 }
 ip = inet_ntoa(*((struct in_addr *)h->h_addr_list[0]));
 pinMode(29, 0);
 while(1) {
  sock = socket(2 , SOCK_STREAM , 0);
  if (sock == -1)
  {
   printf("Could not create socket");
  }
  server.sin_addr.s_addr = inet_addr(ip);
  server.sin_family = 2;
  server.sin_port = htons(80);
  if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
  {
   perror(" Error: connection failed.");
  }
  printf("Connected\n");
  char *message = malloc(26+strlen(host)+28);
  strcpy(message, "GET /LP HTTP/1.0\r\nHost: ");
  strcat(message, host);
  strcat(message, "\r\nUser-Agent: smarthome\r\n\r\n");
  if( send(sock , message , strlen(message) , 0) < 0)
  {
   printf("Error: Send failed");
  }
  if( recv(sock , server_reply , 2000 , 0) >= 0)
  {
   puts("Server reply :");
   puts(server_reply);
   int htmlstart = 0;
     char * htmlcontent;
   if(htmlstart == 0)
   {
          htmlcontent = strstr(server_reply, "\r\n\r\n");
    if(htmlcontent != ((void *)0)){
    htmlstart = 1;
    htmlcontent += 4;
   }
      }
  if (strncmp(htmlcontent, "on", 2) == 0) {
   printf("Turning on");
   turnOn(2);
  }
  if (strncmp(htmlcontent, "off", 3) == 0) {
   printf("Turning off");
   turnOff(2);
  }
  }
 close(sock);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char *ip;
 char *host;
 int sock;
 struct sockaddr_in server;
 char server_reply[2000];
 printf("OpenWRT smart home v1.00a\n");
 printf("http://smarthome.russemotto.com\n\n");
 if(argc <2)
 {
  printf("\nI need a hostname\n");
  return 0;
 }
 host = argv[1];
 struct hostent *h;
 if ((h=gethostbyname(host)) == ((void *)0)) {
  herror("gethostbyname");
  return 0;
 }
 ip = inet_ntoa(*((struct in_addr *)h->h_addr_list[0]));
 pinMode(29, 0);
 while(1) {
  sock = socket(2 , SOCK_STREAM , 0);
  if (sock == -1)
  {
   printf("Could not create socket");
  }
  server.sin_addr.s_addr = inet_addr(ip);
  server.sin_family = 2;
  server.sin_port = htons(80);
  if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
  {
   perror(" Error: connection failed.");
  }
  printf("Connected\n");
  char *message = malloc(26+strlen(host)+28);
  strcpy(message, "GET /LP HTTP/1.0\r\nHost: ");
  strcat(message, host);
  strcat(message, "\r\nUser-Agent: smarthome\r\n\r\n");
  if( send(sock , message , strlen(message) , 0) < 0)
  {
   printf("Error: Send failed");
  }
  if( recv(sock , server_reply , 2000 , 0) >= 0)
  {
   puts("Server reply :");
   puts(server_reply);
   int htmlstart = 0;
     char *htmlcontent;
   if(htmlstart == 0)
   {
          htmlcontent = strstr(server_reply, "\r\n\r\n");
    if(htmlcontent != ((void *)0)){
    htmlstart = 1;
    htmlcontent += 4;
   }
      }
  if (strncmp(htmlcontent, "on", 2) == 0) {
   printf("Turning on");
   turnOn(2);
  }
  if (strncmp(htmlcontent, "off", 3) == 0) {
   printf("Turning off");
   turnOff(2);
  }
  }
 close(sock);
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types:
ip
char *

variable_types:
host
char *

variable_types: sock 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: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
message
char *

variable_types: htmlstart int

variable_types:
htmlcontent
char *

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


usDelay

decompiled_code:
void __fastcall usDelay(unsigned int a1)
{
unsigned int i; // eax

if ( a1 )
{
for ( i = 1; i <= a1; ++i )
;
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1)
{
unsigned int i; // eax

if ( a1 )
{
for ( i = 1; i <= a1; ++i )
;
}
}

original_code:
void usDelay(int d) {
 unsigned int i;
 for ( i = 1 ; i <= d ; i++ )
 {
  asm("");
 }
}

variable_types: d int

variable_types:
i
unsigned int


A

decompiled_code:
void A()
{
digitalWrite_constprop_0(1u);
usDelay(0x1B58u);
digitalWrite_constprop_0(0);
usDelay(0x1B58u);
digitalWrite_constprop_0(1u);
usDelay(0x1B58u);
digitalWrite_constprop_0(0);
usDelay(0x1B58u);
digitalWrite_constprop_0(1u);
usDelay(0x1B58u);
digitalWrite_constprop_0(0);
usDelay(0xC738u);
}

original_code:
void A(void) {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}

canonical_original_code:
void A() {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}


B

decompiled_code:
void B()
{
digitalWrite_constprop_0(1u);
usDelay(0x1B58u);
digitalWrite_constprop_0(0);
usDelay(0x1B58u);
digitalWrite_constprop_0(1u);
usDelay(0x1B58u);
digitalWrite_constprop_0(0);
usDelay(0xC738u);
}

original_code:
void B(void) {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}

canonical_original_code:
void B() {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(7000);
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}


C

decompiled_code:
void C()
{
digitalWrite_constprop_0(1u);
usDelay(0x1B58u);
digitalWrite_constprop_0(0);
usDelay(0xC738u);
}

original_code:
void C(void) {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}

canonical_original_code:
void C() {
 digitalWrite(29, 1);
 usDelay(7000);
 digitalWrite(29, 0);
 usDelay(51000);
}


turnOff

decompiled_code:
void __fastcall turnOff(int a1)
{
int v1; // ebx

v1 = 5;
do
{
sendInit();
B();
B();
setChannel(a1);
usDelay(0x7C830u);
--v1;
}
while ( v1 );
}

canonical_decompiled_code:
void __fastcall func17(int a1)
{
int v1; // ebx

v1 = 5;
do
{
func15();
func13();
func13();
func16(a1);
func9(0x7C830u);
--v1;
}
while ( v1 );
}

original_code:
void turnOff(int k) {
 unsigned int i;
 for ( i = 1 ; i <= 5 ; i++ ) {
  sendInit();
  B();B();
  setChannel(k);
  usDelay(510000);
 }
}

variable_types: k int


turnOn

decompiled_code:
void __fastcall turnOn(int a1)
{
int v1; // ebx

v1 = 5;
do
{
sendInit();
C();
A();
setChannel(a1);
usDelay(0x7C830u);
--v1;
}
while ( v1 );
}

canonical_decompiled_code:
void __fastcall func18(int a1)
{
int v1; // ebx

v1 = 5;
do
{
func15();
func14();
func12();
func16(a1);
func9(0x7C830u);
--v1;
}
while ( v1 );
}

original_code:
void turnOn(int k) {
 unsigned int i;
 for ( i = 1 ; i <= 5 ; i++ ) {
  sendInit();
  C();A();
  setChannel(k);
  usDelay(510000);
 }
}


passivesocket

repo: gekalogiros/proxy-server

decompiled_code:
__int64 __fastcall passivesocket(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0
|| (v2 = v1, v5 = 0LL, v5.sa_family = 2, *(_WORD *)v5.sa_data = _bswap_16(a1), bind(v2, &v5, v3) < 0)
|| listen(v2, 5) < 0 )
{
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t v3; // edx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0
|| (v2 = v1, v5 = 0LL, v5.sa_family = 2, *(_WORD *)v5.sa_data = func0(a1), bind(v2, &v5, v3) < 0)
|| listen(v2, 5) < 0 )
{
v2 = -1;
}
return v2;
}

original_code:
int passivesocket(int portnumber)
{
  struct sockaddr_in addr;
  int x;
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  addr.sin_port = htons(portnumber);
  if(bind(x, (struct sockaddr*) &addr, sizeof(addr)) < 0)
    return -1;
  if(listen(x, 5) < 0)
    return -1;
  return x;
}

canonical_original_code:
int passivesocket(int portnumber)
{
  struct sockaddr_in addr;
  int x;
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
  addr.sin_port = htons(portnumber);
  if(bind(x, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    return -1;
  if(listen(x, 5) < 0)
    return -1;
  return x;
}

variable_types: portnumber int

variable_types: x int


activesocket

decompiled_code:
__int64 __fastcall activesocket(const char *a1, __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbx
int v4; // er12
socklen_t v5; // edx
struct sockaddr v7; // [rsp+0h] [rbp-28h] BYREF

v2 = gethostbyname(a1);
if ( v2 )
{
v3 = v2;
v4 = socket(2, 1, 0);
if ( v4 < 0
|| (v7 = 0LL,
v7.sa_family = 2,
*(_DWORD *)&v7.sa_data[2] = **(_DWORD **)v3->h_addr_list,
*(_WORD *)v7.sa_data = _bswap_16(a2),
connect(v4, &v7, v5) < 0) )
{
v4 = -1;
}
}
else
{
v4 = -1;
fprintf(stderr, "%s: doesn't exist!\n", a1);
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbx
int v4; // er12
socklen_t v5; // edx
struct sockaddr v7; // [rsp+0h] [rbp-28h] BYREF

v2 = gethostbyname(a1);
if ( v2 )
{
v3 = v2;
v4 = socket(2, 1, 0);
if ( v4 < 0
|| (v7 = 0LL,
v7.sa_family = 2,
*(_DWORD *)&v7.sa_data[2] = **(_DWORD **)v3->h_addr_list,
*(_WORD *)v7.sa_data = func0(a2),
connect(v4, &v7, v5) < 0) )
{
v4 = -1;
}
}
else
{
v4 = -1;
fprintf(stderr, "%s: doesn't exist!\n", a1);
}
return (unsigned int)v4;
}

original_code:
int activesocket(char *hostname, int portnumber)
{
  struct sockaddr_in addr;
  struct hostent *h;
  int x;
  h = gethostbyname(hostname);
  if(h == ((void *)0)) {
    fprintf(stderr, "%s: doesn't exist!\n", hostname);
    return -1;
  }
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  memcpy(&addr.sin_addr.s_addr, h -> h_addr_list[0], sizeof(int));
  addr.sin_port = htons(portnumber);
  if(connect(x, (struct sockaddr*) &addr, sizeof(addr)) < 0)
    return -1;
  return x;
}

canonical_original_code:
int activesocket(char *hostname, int portnumber)
{
  struct sockaddr_in addr;
  struct hostent *h;
  int x;
  h = gethostbyname(hostname);
  if(h == ((void *)0)) {
    fprintf(stderr, "%s: doesn't exist!\n", hostname);
    return -1;
  }
  x = socket(2, SOCK_STREAM, 0);
  if(x < 0)
    return -1;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  memcpy(&addr.sin_addr.s_addr, h -> h_addr_list[0], sizeof(int));
  addr.sin_port = htons(portnumber);
  if(connect(x, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    return -1;
  return x;
}

variable_types:
hostname
char *

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


acceptfrom

decompiled_code:
__int64 __fastcall acceptfrom(int a1, char *a2, int a3)
{
size_t v3; // rbx
int v4; // eax
unsigned int v5; // er12
char *v6; // rax
socklen_t addr_len; // [rsp+4h] [rbp-34h] BYREF
__int64 optval; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = a3;
addr_len = 16;
v4 = accept(a1, &addr, &addr_len);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
optval = 0x500000001LL;
setsockopt(v4, 1, 13, &optval, 8u);
v6 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strncpy(a2, v6, v3);
a2[v3 - 1] = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, char *a2, int a3)
{
size_t v3; // rbx
int v4; // eax
unsigned int v5; // er12
char *v6; // rax
socklen_t addr_len; // [rsp+4h] [rbp-34h] BYREF
__int64 optval; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = a3;
addr_len = 16;
v4 = accept(a1, &addr, &addr_len);
if ( v4 < 0 )
return (unsigned int)-1;
v5 = v4;
optval = 0x500000001LL;
setsockopt(v4, 1, 13, &optval, 8u);
v6 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strncpy(a2, v6, v3);
a2[v3 - 1] = 0;
return v5;
}

original_code:
int acceptfrom(int socket, char *client, int size)
{
  struct sockaddr_in addr;
  struct linger l;
  int s, i;
  i = sizeof(addr);
  s = accept(socket, (struct sockaddr *)&addr, &i);
  if(s < 0)
    return -1;
  l.l_linger = 5;
  l.l_onoff = 1;
  setsockopt(s, 1, 13, (char *)&l, sizeof(l));
  strncpy(client, inet_ntoa(addr.sin_addr), size);
  client[size-1] = '\0';
  return s;
}

canonical_original_code:
int acceptfrom(int socket, char *client, int size)
{
  struct sockaddr_in addr;
  struct linger l;
  int s; int i;
  i = sizeof(addr);
  s = accept(socket, (struct sockaddr *)&addr, &i);
  if(s < 0)
    return -1;
  l.l_linger = 5;
  l.l_onoff = 1;
  setsockopt(s, 1, 13, (char *)&l, sizeof(l));
  strncpy(client, inet_ntoa(addr.sin_addr), size);
  client[size-1] = '\0';
  return s;
}

variable_types: socket int

variable_types:
client
char *

variable_types: size int

variable_types: struct linger { int l_onoff; int l_linger; }

variable_types: s int

variable_types: i int


acceptconnection

decompiled_code:
__int64 __fastcall acceptconnection(int a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

return acceptfrom(a1, v2, 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

return func3(a1, v2, 40);
}

original_code:
int acceptconnection(int socket)
{
  char client[40];
  return acceptfrom(socket, client, 40);
}

variable_types:
client
char [40]


TCPreadline

decompiled_code:
__int64 __fastcall TCPreadline(int fd, void *buf, int a3)
{
char *v3; // r14
unsigned int v4; // er12
char *v5; // rbp
__int64 result; // rax

v3 = (char *)buf;
v4 = 0;
v5 = (char *)buf + (unsigned int)(a3 - 2);
while ( 1 )
{
LODWORD(result) = read(fd, v3, 1uLL);
if ( (int)result <= 0 )
break;
++v4;
if ( *v3 == 10 || v3 == v5 )
goto LABEL_8;
++v3;
}
if ( (_DWORD)result )
return (unsigned int)result;
LABEL_8:
*((_BYTE *)buf + (int)v4) = 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, int a3)
{
char *v3; // r14
unsigned int v4; // er12
char *v5; // rbp
__int64 result; // rax

v3 = (char *)buf;
v4 = 0;
v5 = (char *)buf + (unsigned int)(a3 - 2);
while ( 1 )
{
LODWORD(result) = read(fd, v3, 1uLL);
if ( (int)result <= 0 )
break;
++v4;
if ( *v3 == 10 || v3 == v5 )
goto LABEL_8;
++v3;
}
if ( (_DWORD)result )
return (unsigned int)result;
LABEL_8:
*((_BYTE *)buf + (int)v4) = 0;
return v4;
}

original_code:
int TCPreadline(int s, char *buffer, int size)
{
  char *b;
  int n, count;
  b = buffer;
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if (*b == '\n' || count == size-1)
      break;
    b ++;
  }
  if (n < 0) return n;
  buffer[count] = '\0';
  return count;
}

canonical_original_code:
int TCPreadline(int s, char *buffer, int size)
{
  char *b;
  int n; int count;
  b = buffer;
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if (*b == '\n' || count == size-1)
      break;
    b ++;
  }
  if (n < 0) return n;
  buffer[count] = '\0';
  return count;
}

variable_types:
buffer
char *

variable_types:
b
char *

variable_types: n int

variable_types: count int


HTTPreadheader

decompiled_code:
__int64 __fastcall HTTPreadheader(int fd, void *buf, int a3)
{
char v3; // r15
char *v4; // r14
unsigned int v5; // er12
char *v6; // rbp
int v7; // eax

v3 = 10;
v4 = (char *)buf;
v5 = 0;
v6 = (char *)buf + (unsigned int)(a3 - 2);
while ( 1 )
{
v7 = read(fd, v4, 1uLL);
if ( v7 <= 0 )
break;
++v5;
if ( *v4 == 10 && v3 == 10 || v4 == v6 )
goto LABEL_11;
if ( *v4 != 13 )
v3 = *v4;
++v4;
}
if ( v7 )
return (unsigned int)v7;
LABEL_11:
*((_BYTE *)buf + (int)v5) = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, void *buf, int a3)
{
char v3; // r15
char *v4; // r14
unsigned int v5; // er12
char *v6; // rbp
int v7; // eax

v3 = 10;
v4 = (char *)buf;
v5 = 0;
v6 = (char *)buf + (unsigned int)(a3 - 2);
while ( 1 )
{
v7 = read(fd, v4, 1uLL);
if ( v7 <= 0 )
break;
++v5;
if ( *v4 == 10 && v3 == 10 || v4 == v6 )
goto LABEL_11;
if ( *v4 != 13 )
v3 = *v4;
++v4;
}
if ( v7 )
return (unsigned int)v7;
LABEL_11:
*((_BYTE *)buf + (int)v5) = 0;
return v5;
}

original_code:
int HTTPreadheader(int s, char *buffer, int size)
{
  char *b;
  char last;
  int n, count;
  b = buffer;
  last = '\n';
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if ((*b == '\n' && last == '\n') || count == size-1)
      break;
    if (*b != '\r') last = *b;
    b ++;
  }
  if (n < 0)
    return n;
  buffer[count] = '\0';
  return count;
}

canonical_original_code:
int HTTPreadheader(int s, char *buffer, int size)
{
  char *b;
  char last;
  int n; int count;
  b = buffer;
  last = '\n';
  count = 0;
  while ((n = read(s, b, 1)) > 0) {
    count ++;
    if ((*b == '\n' && last == '\n') || count == size-1)
      break;
    if (*b != '\r') last = *b;
    b ++;
  }
  if (n < 0)
    return n;
  buffer[count] = '\0';
  return count;
}

variable_types: last char


HTTPheadervalue

decompiled_code:
__int64 __fastcall HTTPheadervalue(const char *a1, const char *a2, char *a3)
{
char *v4; // rbp
char v5; // al
char *v6; // rax
char *v7; // rbx
const char *i; // rbp
size_t v10; // rbx

v4 = (char *)a1;
while ( 1 )
{
v6 = strstr(a1, a2);
v7 = v6;
if ( !v6 )
return 0LL;
if ( v4 == v6 )
break;
v5 = *(v6 - 1);
if ( v5 == 13 || v5 == 10 )
break;
a1 = v7 + 1;
}
for ( i = &v7[strlen(a2) + 1]; *i == 32; ++i )
;
v10 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v10);
a3[v10] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2, char *a3)
{
char *v4; // rbp
char v5; // al
char *v6; // rax
char *v7; // rbx
const char *i; // rbp
size_t v10; // rbx

v4 = (char *)a1;
while ( 1 )
{
v6 = strstr(a1, a2);
v7 = v6;
if ( !v6 )
return 0LL;
if ( v4 == v6 )
break;
v5 = *(v6 - 1);
if ( v5 == 13 || v5 == 10 )
break;
a1 = v7 + 1;
}
for ( i = &v7[strlen(a2) + 1]; *i == 32; ++i )
;
v10 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v10);
a3[v10] = 0;
return 1LL;
}

original_code:
int HTTPheadervalue(char *header, char *key, char *value)
{
  char *b = header;
  int i;
  while (1) {
    b = strstr(b, key);
    if (b == ((void *)0)) return 0;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  b += strlen(key)+1;
  while (*b == ' ')
    b++;
  i = strcspn(b, "\n\r");
  strncpy(value, b, i);
  value[i] = '\0';
  return 1;
}

variable_types:
header
char *

variable_types:
key
char *

variable_types:
value
char *


HTTPheaderremove

decompiled_code:
char *__fastcall HTTPheaderremove(const char *a1, const char *a2)
{
char *v2; // rbx
char *v3; // rdx
char v4; // cl
char *result; // rax
char *i; // rcx
char *v7; // rsi
char v8; // cl

v2 = (char *)a1;
while ( 1 )
{
result = strstr(a1, a2);
if ( !result )
break;
v3 = result + 1;
a1 = result + 1;
if ( v2 != result )
{
v4 = *(result - 1);
if ( v4 != 10 && v4 != 13 )
continue;
}
for ( i = result; *i != 10; ++i )
;
v7 = i + 1;
v8 = i[1];
if ( v8 )
{
while ( 1 )
{
++v7;
*(v3 - 1) = v8;
result = v3;
v8 = *v7;
if ( !*v7 )
break;
++v3;
}
}
*result = 0;
return result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1, const char *a2)
{
char *v2; // rbx
char *v3; // rdx
char v4; // cl
char *result; // rax
char *i; // rcx
char *v7; // rsi
char v8; // cl

v2 = (char *)a1;
while ( 1 )
{
result = strstr(a1, a2);
if ( !result )
break;
v3 = result + 1;
a1 = result + 1;
if ( v2 != result )
{
v4 = *(result - 1);
if ( v4 != 10 && v4 != 13 )
continue;
}
for ( i = result; *i != 10; ++i )
;
v7 = i + 1;
v8 = i[1];
if ( v8 )
{
while ( 1 )
{
++v7;
*(v3 - 1) = v8;
result = v3;
v8 = *v7;
if ( !*v7 )
break;
++v3;
}
}
*result = 0;
return result;
}
return result;
}

original_code:
void HTTPheaderremove(char *header, char *key)
{
  char *b = header;
  char *nextline;
  while (1) {
    b = strstr(b, key);
    if (b == ((void *)0)) return;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  nextline = b;
  while (*nextline != '\n')
    nextline++;
  nextline++;
  while (*nextline != '\0')
    *b++ = *nextline++;
  *b = '\0';
}

variable_types:
nextline
char *


decompiled_code:
char *__fastcall strstr_case(char *s1, char *s2)
{
char *v2; // r12
int v3; // eax
size_t v4; // rbx

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncasecmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func9(char *s1, char *s2)
{
char *v2; // r12
int v3; // eax
size_t v4; // rbx

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncasecmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

original_code:
char *strstr_case(char *p, char *key)
{
  int len = strlen(key);
  while (*p != '\0')
    if (strncasecmp(p, key, len) == 0)
      return p;
    else
      p++;
  return ((void *)0);
}

variable_types:
p
char *

variable_types: len int

return_type: char *


decompiled_code:
__int64 __fastcall HTTPheadervalue_case(char *a1, char *a2, char *a3)
{
char *v4; // rbp
char v5; // al
char *v6; // rax
char *v7; // rbx
const char *i; // rbp
size_t v10; // rbx

v4 = a1;
while ( 1 )
{
v6 = strstr_case(a1, a2);
v7 = v6;
if ( !v6 )
return 0LL;
if ( v4 == v6 )
break;
v5 = *(v6 - 1);
if ( v5 == 13 || v5 == 10 )
break;
a1 = v7 + 1;
}
for ( i = &v7[strlen(a2) + 1]; *i == 32; ++i )
;
v10 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v10);
a3[v10] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, char *a2, char *a3)
{
char *v4; // rbp
char v5; // al
char *v6; // rax
char *v7; // rbx
const char *i; // rbp
size_t v10; // rbx

v4 = a1;
while ( 1 )
{
v6 = func9(a1, a2);
v7 = v6;
if ( !v6 )
return 0LL;
if ( v4 == v6 )
break;
v5 = *(v6 - 1);
if ( v5 == 13 || v5 == 10 )
break;
a1 = v7 + 1;
}
for ( i = &v7[strlen(a2) + 1]; *i == 32; ++i )
;
v10 = (int)strcspn(i, "\n\r");
strncpy(a3, i, v10);
a3[v10] = 0;
return 1LL;
}

original_code:
int HTTPheadervalue_case(char *header, char *key, char *value)
{
  char *b = header;
  int i;
  while (1) {
    b = strstr_case(b, key);
    if (b == ((void *)0)) return 0;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  b += strlen(key)+1;
  while (*b == ' ')
    b++;
  i = strcspn(b, "\n\r");
  strncpy(value, b, i);
  value[i] = '\0';
  return 1;
}


decompiled_code:
char *__fastcall HTTPheaderremove_case(char *a1, char *a2)
{
char *v2; // rbx
char *v3; // rdx
char v4; // cl
char *result; // rax
char *i; // rcx
char *v7; // rsi
char v8; // cl

v2 = a1;
while ( 1 )
{
result = strstr_case(a1, a2);
if ( !result )
break;
v3 = result + 1;
a1 = result + 1;
if ( v2 != result )
{
v4 = *(result - 1);
if ( v4 != 10 && v4 != 13 )
continue;
}
for ( i = result; *i != 10; ++i )
;
v7 = i + 1;
v8 = i[1];
if ( v8 )
{
while ( 1 )
{
++v7;
*(v3 - 1) = v8;
result = v3;
v8 = *v7;
if ( !*v7 )
break;
++v3;
}
}
*result = 0;
return result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func11(char *a1, char *a2)
{
char *v2; // rbx
char *v3; // rdx
char v4; // cl
char *result; // rax
char *i; // rcx
char *v7; // rsi
char v8; // cl

v2 = a1;
while ( 1 )
{
result = func9(a1, a2);
if ( !result )
break;
v3 = result + 1;
a1 = result + 1;
if ( v2 != result )
{
v4 = *(result - 1);
if ( v4 != 10 && v4 != 13 )
continue;
}
for ( i = result; *i != 10; ++i )
;
v7 = i + 1;
v8 = i[1];
if ( v8 )
{
while ( 1 )
{
++v7;
*(v3 - 1) = v8;
result = v3;
v8 = *v7;
if ( !*v7 )
break;
++v3;
}
}
*result = 0;
return result;
}
return result;
}

original_code:
void HTTPheaderremove_case(char *header, char *key)
{
  char *b = header;
  char *nextline;
  while (1) {
    b = strstr_case(b, key);
    if (b == ((void *)0)) return;
    if (b == header || *(b-1) == '\r' || *(b-1) == '\n') break;
    b++;
  }
  nextline = b;
  while (*nextline != '\n')
    nextline++;
  nextline++;
  while (*nextline != '\0')
    *b++ = *nextline++;
  *b = '\0';
}


contentlength

decompiled_code:
__int64 __fastcall contentlength(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-A0Ch] BYREF
char v3[2568]; // [rsp+10h] [rbp-A08h] BYREF

v2 = 0x7FFFFFFF;
if ( (unsigned int)HTTPheadervalue_case(a1, "Content-Length", v3) )
_isoc99_sscanf(v3, "%d", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-A0Ch] BYREF
char v3[2568]; // [rsp+10h] [rbp-A08h] BYREF

v2 = 0x7FFFFFFF;
if ( (unsigned int)HTTPheadervalue_case(a1, "Content-Length", v3) )
_isoc99_sscanf(v3, "%d", &v2);
return v2;
}

original_code:
int contentlength(char *header)
{
  int len=0x7fffffff;
  char line[2560];
  if (HTTPheadervalue_case(header, "Content-Length", line))
    sscanf(line, "%d", &len);
  return len;
}

canonical_original_code:
int contentlength(char *header)
{
  int len = 0x7fffffff;
  char line[2560];
  if (HTTPheadervalue_case(header, "Content-Length", line))
    sscanf(line, "%d", &len);
  return len;
}

variable_types:
line
char [2560]


parserequest

decompiled_code:
int __fastcall parserequest(__int64 a1, _DWORD *a2, __int64 a3, int *a4, __int64 a5)
{
int result; // eax
__int128 v9; // [rsp+0h] [rbp-2828h] BYREF
char v10[2544]; // [rsp+10h] [rbp-2818h] BYREF
char s1[16]; // [rsp+A00h] [rbp-1E28h] BYREF
char v12[2544]; // [rsp+A10h] [rbp-1E18h] BYREF
__int128 v13; // [rsp+1400h] [rbp-1428h] BYREF
char v14[2544]; // [rsp+1410h] [rbp-1418h] BYREF
char nptr[16]; // [rsp+1E00h] [rbp-A28h] BYREF
char v16[2544]; // [rsp+1E10h] [rbp-A18h] BYREF

v9 = 0LL;
memset(v10, 0, sizeof(v10));
*(_OWORD *)s1 = 0LL;
memset(v12, 0, sizeof(v12));
v13 = 0LL;
memset(v14, 0, sizeof(v14));
*(_OWORD *)nptr = 0LL;
memset(v16, 0, sizeof(v16));
_isoc99_sscanf(a1, "%[^ ] %[^ ] HTTP/1.1", s1, &v9);
if ( !strcmp(s1, methods) )
*a2 = 0;
if ( !strcmp(s1, *(&methods + 1)) )
*a2 = 1;
_isoc99_sscanf(&v9, "http://%[^\n\r/]%[^\n\r]", &v13, a5);
_isoc99_sscanf(&v13, "%[^:]:%[^\n\r]", a3, nptr);
result = 80;
if ( nptr[0] )
result = atoi(nptr);
*a4 = result;
return result;
}

original_code:
void parserequest(char *request, int *method, char *host, int *pn, char *path)
{
 char url[2560] = "";
 char m[2560] = "";
 char hostport[2560] = "";
 char port[2560] = "";
 int i;
 sscanf(request, "%[^ ] %[^ ] HTTP/1.1", m, url);
 for (i=0; i<2; i++)
 {
  if (strcmp(m, methods[i]) == 0)
  *method = i;
 }
 sscanf(url, "http://%[^\n\r/]%[^\n\r]", hostport, path);
 sscanf(hostport, "%[^:]:%[^\n\r]", host, port);
 if (*port == '\0')
 {
  *pn = 80;
 }
 else
 {
  *pn = atoi(port);
 }
}

variable_types:
request
char *

variable_types:
method
int *

variable_types:
host
char *

variable_types:
pn
int *

variable_types:
path
char *

variable_types:
url
char [2560]

variable_types:
hostport
char [2560]

variable_types:
port
char [2560]


serviceconn

decompiled_code:
void *__fastcall serviceconn(void *a1)
{
unsigned int v1; // ebx
unsigned int v2; // er12
char *v3; // r13
char *v4; // rbp
int v5; // eax
int v6; // eax
__int64 v7; // rsi
int v9; // [rsp+Ch] [rbp-6E3Ch] BYREF
int v10; // [rsp+10h] [rbp-6E38h] BYREF
int v11; // [rsp+14h] [rbp-6E34h] BYREF
struct pollfd fds; // [rsp+18h] [rbp-6E30h] BYREF
char v13[2560]; // [rsp+20h] [rbp-6E28h] BYREF
char v14[2560]; // [rsp+A20h] [rbp-6428h] BYREF
char v15[2560]; // [rsp+1420h] [rbp-5A28h] BYREF
char src[20520]; // [rsp+1E20h] [rbp-5028h] BYREF

v1 = 0;
v2 = *(_DWORD *)a1;
v9 = 0;
fds.fd = v2;
fds.events = 192;
v3 = (char *)malloc(0x16EC87C00uLL);
while ( 1 )
{
if ( poll(&fds, 1uLL, 10000) <= 0 )
{
puts("Connection Timeout");
goto LABEL_7;
}
if ( !(unsigned int)TCPreadline(v2, v13, 2560LL) )
break;
parserequest((__int64)v13, &v10, (__int64)v14, &v11, (__int64)v15);
if ( !(unsigned int)HTTPreadheader(v2, src, 20480LL) )
break;
printf("%s%s", v13, src);
HTTPheaderremove_case(src, "Connection");
v4 = &v3[61536 * (v1 % 0x186A0)];
*((_DWORD *)v4 + 15) = v1 % 0x186A0;
v5 = v10;
*((_DWORD *)v4 + 14) = v1;
*((_DWORD *)v4 + 17) = v5;
v6 = v11;
*((_DWORD *)v4 + 16) = v2;
*((_DWORD *)v4 + 18) = v6;
*((_DWORD *)v4 + 19) = 0;
*((_QWORD *)v4 + 10) = &v9;
*((_QWORD *)v4 + 7691) = v3;
pthread_cond_init((pthread_cond_t *)(v4 + 8), 0LL);
strcpy(v4 + 88, src);
strcpy(v4 + 20568, v14);
strcpy(v4 + 41048, v15);
pthread_create((pthread_t *)v4, 0LL, processRequest, v4);
v7 = v1++;
printf("I created the %d request in order to serve the client %d \n", v7, v2);
if ( v9 )
goto LABEL_7;
}
puts("Asynchronous closed by the client");
LABEL_7:
close(v2);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
unsigned int v1; // ebx
unsigned int v2; // er12
char *v3; // r13
char *v4; // rbp
int v5; // eax
int v6; // eax
__int64 v7; // rsi
int v9; // [rsp+Ch] [rbp-6E3Ch] BYREF
int v10; // [rsp+10h] [rbp-6E38h] BYREF
int v11; // [rsp+14h] [rbp-6E34h] BYREF
struct pollfd fds; // [rsp+18h] [rbp-6E30h] BYREF
char v13[2560]; // [rsp+20h] [rbp-6E28h] BYREF
char v14[2560]; // [rsp+A20h] [rbp-6428h] BYREF
char v15[2560]; // [rsp+1420h] [rbp-5A28h] BYREF
char src[20520]; // [rsp+1E20h] [rbp-5028h] BYREF

v1 = 0;
v2 = *(_DWORD *)a1;
v9 = 0;
fds.fd = v2;
fds.events = 192;
v3 = (char *)malloc(0x16EC87C00uLL);
while ( 1 )
{
if ( poll(&fds, 1uLL, 10000) <= 0 )
{
puts("Connection Timeout");
goto LABEL_7;
}
if ( !(unsigned int)TCPreadline(v2, v13, 2560LL) )
break;
func1((__int64)v13, &v10, (__int64)v14, &v11, (__int64)v15);
if ( !(unsigned int)HTTPreadheader(v2, src, 20480LL) )
break;
printf("%s%s", v13, src);
HTTPheaderremove_case(src, "Connection");
v4 = &v3[61536 * (v1 % 0x186A0)];
*((_DWORD *)v4 + 15) = v1 % 0x186A0;
v5 = v10;
*((_DWORD *)v4 + 14) = v1;
*((_DWORD *)v4 + 17) = v5;
v6 = v11;
*((_DWORD *)v4 + 16) = v2;
*((_DWORD *)v4 + 18) = v6;
*((_DWORD *)v4 + 19) = 0;
*((_QWORD *)v4 + 10) = &v9;
*((_QWORD *)v4 + 7691) = v3;
pthread_cond_init((pthread_cond_t *)(v4 + 8), 0LL);
strcpy(v4 + 88, src);
strcpy(v4 + 20568, v14);
strcpy(v4 + 41048, v15);
pthread_create((pthread_t *)v4, 0LL, processRequest, v4);
v7 = v1++;
printf("I created the %d request in order to serve the client %d \n", v7, v2);
if ( v9 )
goto LABEL_7;
}
puts("Asynchronous closed by the client");
LABEL_7:
close(v2);
return 0LL;
}

original_code:
void *serviceconn(void *socketDescriptor)
{
 int cli = *(int*)socketDescriptor;
 char reqline[2560];
 char reqhead[20480];
 char host[2560], path[2560];
 int closeCliConn = 0, requestIndex=0;
 int method, portno, adaptedIndex;
        REQUEST *reqThreadArray;
 reqThreadArray=(REQUEST*)malloc(sizeof(REQUEST)*100000);
 int timeOutSecs=10000;
 struct pollfd fds[1];
 fds[0].fd = cli;
 fds[0].events = 0x040 | 0x080;
 while(closeCliConn == 0)
 {
  if ( poll(fds, 1, timeOutSecs) <= 0 )
  {
   printf("Connection Timeout\n");
   break;
  }
  if ( TCPreadline(cli, reqline, 2560) == 0 )
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  parserequest(reqline, &method, host, &portno, path);
  if (HTTPreadheader(cli, reqhead, 20480) == 0)
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  printf("%s%s", reqline, reqhead);
  HTTPheaderremove_case(reqhead, "Connection");
  adaptedIndex=requestIndex%100000;
  reqThreadArray[adaptedIndex].requestID=requestIndex;
  reqThreadArray[adaptedIndex].adaptedID=adaptedIndex;
  reqThreadArray[adaptedIndex].socketDescriptor=cli;
  reqThreadArray[adaptedIndex].method=method;
  reqThreadArray[adaptedIndex].served=0;
  reqThreadArray[adaptedIndex].portNumber=portno;
  reqThreadArray[adaptedIndex].breakCliConn=&closeCliConn;
  reqThreadArray[adaptedIndex].arrayAddress=reqThreadArray;
  pthread_cond_init( &(reqThreadArray[adaptedIndex].cond), ((void *)0));
  strcpy(reqThreadArray[adaptedIndex].reqhead, reqhead);
  strcpy(reqThreadArray[adaptedIndex].hostName, host);
  strcpy(reqThreadArray[adaptedIndex].pathName, path);
  pthread_create(&(reqThreadArray[adaptedIndex].reqThread), ((void *)0), processRequest, &reqThreadArray[adaptedIndex]);
  printf("I created the %d request in order to serve the client %d \n", requestIndex, cli);
  requestIndex++;
 }
 close(cli);
 return 0;
}

canonical_original_code:
void *serviceconn(void *socketDescriptor)
{
 int cli = *(int*)socketDescriptor;
 char reqline[2560];
 char reqhead[20480];
 char host[2560]; char path[2560];
 int closeCliConn = 0; int requestIndex = 0;
 int method; int portno; int adaptedIndex;
        struct req *reqThreadArray;
 reqThreadArray=(struct req *)malloc(sizeof(REQUEST)*100000);
 int timeOutSecs = 10000;
 struct pollfd fds[1];
 fds[0].fd = cli;
 fds[0].events = 0x040 | 0x080;
 while(closeCliConn == 0)
 {
  if ( poll(fds, 1, timeOutSecs) <= 0 )
  {
   printf("Connection Timeout\n");
   break;
  }
  if ( TCPreadline(cli, reqline, 2560) == 0 )
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  parserequest(reqline, &method, host, &portno, path);
  if (HTTPreadheader(cli, reqhead, 20480) == 0)
  {
   printf("Asynchronous closed by the client\n");
   break;
  }
  printf("%s%s", reqline, reqhead);
  HTTPheaderremove_case(reqhead, "Connection");
  adaptedIndex=requestIndex%100000;
  reqThreadArray[adaptedIndex].requestID=requestIndex;
  reqThreadArray[adaptedIndex].adaptedID=adaptedIndex;
  reqThreadArray[adaptedIndex].socketDescriptor=cli;
  reqThreadArray[adaptedIndex].method=method;
  reqThreadArray[adaptedIndex].served=0;
  reqThreadArray[adaptedIndex].portNumber=portno;
  reqThreadArray[adaptedIndex].breakCliConn=&closeCliConn;
  reqThreadArray[adaptedIndex].arrayAddress=reqThreadArray;
  pthread_cond_init( &(reqThreadArray[adaptedIndex].cond), ((void *)0));
  strcpy(reqThreadArray[adaptedIndex].reqhead, reqhead);
  strcpy(reqThreadArray[adaptedIndex].hostName, host);
  strcpy(reqThreadArray[adaptedIndex].pathName, path);
  pthread_create(&(reqThreadArray[adaptedIndex].reqThread), ((void *)0), processRequest, &reqThreadArray[adaptedIndex]);
  printf("I created the %d request in order to serve the client %d \n", requestIndex, cli);
  requestIndex++;
 }
 close(cli);
 return 0;
}

variable_types:
socketDescriptor
void *

variable_types: cli int

variable_types:
reqline
char [2560]

variable_types:
reqhead
char [20480]

variable_types:
host
char [2560]

variable_types:
path
char [2560]

variable_types: closeCliConn int

variable_types: requestIndex int

variable_types: method int

variable_types: portno int

variable_types: adaptedIndex int

variable_types: struct req { unsigned long reqThread; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int requestID; int adaptedID; int socketDescriptor; int method; int portNumber; int served; int *breakCliConn; char reqhead[20480]; char hostName[20480]; char pathName[20480]; struct req *arrayAddress; } *

variable_types: timeOutSecs int

variable_types: struct pollfd { int fd; short events; short revents; } [1]

return_type: void *

user_defined_types: struct req { unsigned long reqThread; union pthread_cond_t cond; int requestID; int adaptedID; int socketDescriptor; int method; int portNumber; int served; int *breakCliConn; char reqhead[20480]; char hostName[20480]; char pathName[20480]; struct req *arrayAddress; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


copydata

decompiled_code:
__int64 __fastcall copydata(int fd, int a2, int a3)
{
int i; // ebp
int v4; // eax
int v5; // ebx
_BYTE v7[8232]; // [rsp-2028h] [rbp-2028h] BYREF

if ( a3 <= 0 )
return 0LL;
for ( i = a3; i > 0; i -= v5 )
{
v4 = read(fd, v7, 0x2000uLL);
v5 = v4;
if ( v4 <= 0 || write(a2, v7, v4) < v4 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2, int a3)
{
int i; // ebp
int v4; // eax
int v5; // ebx
_BYTE v7[8232]; // [rsp-2028h] [rbp-2028h] BYREF

if ( a3 <= 0 )
return 0LL;
for ( i = a3; i > 0; i -= v5 )
{
v4 = read(fd, v7, 0x2000uLL);
v5 = v4;
if ( v4 <= 0 || write(a2, v7, v4) < v4 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int copydata(int from, int to, int len)
{
 char tbuff[8192];
 int n;
 while (len > 0)
 {
  if ((n = read(from, tbuff, 8192)) <= 0)
  {
   return -1;
  }
  if (write(to, tbuff, n) < n)
  {
   return -1;
  }
  len -= n;
 }
 return 0;
}

variable_types: from int

variable_types: to int

variable_types: len int

variable_types:
tbuff
char [8192]

variable_types: n int


closeClientConn

decompiled_code:
__int64 __fastcall closeClientConn(__int64 a1, __int64 a2)
{
bool v2; // bl
__int64 result; // rax
int v4; // [rsp+0h] [rbp-5018h] BYREF
__int16 v5; // [rsp+4h] [rbp-5014h]
char v6; // [rsp+6h] [rbp-5012h]

v2 = (unsigned int)HTTPheadervalue_case(a2, "Content-Length", &v4) == 0;
result = HTTPheadervalue_case(a1, "Connection: ", &v4);
if ( (_DWORD)result != 1 || (v4 != 1936682083 || v5 != 101) && (v4 != 1936682083 || v5 != 3429 || v6) )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
bool v2; // bl
__int64 result; // rax
int v4; // [rsp+0h] [rbp-5018h] BYREF
__int16 v5; // [rsp+4h] [rbp-5014h]
char v6; // [rsp+6h] [rbp-5012h]

v2 = (unsigned int)HTTPheadervalue_case(a2, "Content-Length", &v4) == 0;
result = HTTPheadervalue_case(a1, "Connection: ", &v4);
if ( (_DWORD)result != 1 || (v4 != 1936682083 || v5 != 101) && (v4 != 1936682083 || v5 != 3429 || v6) )
result = v2;
return result;
}

original_code:
int closeClientConn(char *reqHeader, char *resHeader){
 char value[20480];
 _Bool closeConn1 = 0;
 _Bool closeConn2 = 0;
        _Bool closeConn;
 if ( HTTPheadervalue_case(resHeader, "Content-Length", value) == 0 )
 {
  closeConn1 = 1;
 }
 if ( HTTPheadervalue_case(reqHeader, "Connection: ", value) == 1)
 {
  if ( strcmp(value, "close") == 0 || strcmp(value, "close\r") == 0 )
  {
   closeConn2 = 1;
  }
 }
 closeConn = (closeConn1 || closeConn2);
 return (int)closeConn;
}

variable_types:
reqHeader
char *

variable_types:
resHeader
char *

variable_types:
value
char [20480]


processRequest

decompiled_code:
void *__fastcall processRequest(void *a1)
{
unsigned int v1; // ebp
__int64 v2; // r13
int v3; // er14
int v4; // er12
int v5; // ebx
int v6; // eax
unsigned int v7; // ebp
size_t v8; // rax
__m128i v9; // xmm0
char *v10; // rdx
char *v11; // rax
__int64 v12; // rbx
__int64 v13; // r15
size_t v14; // rax
size_t v15; // rax
size_t v16; // rax
int v17; // eax
int v18; // eax
size_t v19; // rax
_DWORD *v21; // rax
int v22; // [rsp+Ch] [rbp-1FEACh]
char v23; // [rsp+18h] [rbp-1FEA0h] BYREF
int v24; // [rsp+1Ch] [rbp-1FE9Ch] BYREF
char buf[16]; // [rsp+20h] [rbp-1FE98h] BYREF
char v26[16]; // [rsp+30h] [rbp-1FE88h] BYREF
char v27[2560]; // [rsp+A20h] [rbp-1F498h] BYREF
char v28[2560]; // [rsp+1420h] [rbp-1EA98h] BYREF
char v29[20480]; // [rsp+1E20h] [rbp-1E098h] BYREF
char s[20480]; // [rsp+6E20h] [rbp-19098h] BYREF
char v31[16]; // [rsp+BE20h] [rbp-14098h] BYREF
__m128i v32; // [rsp+BE30h] [rbp-14088h]
__m128i v33; // [rsp+BE40h] [rbp-14078h]
__m128i v34; // [rsp+BE50h] [rbp-14068h]
int v35; // [rsp+BE60h] [rbp-14058h]
__int64 dest[7699]; // [rsp+10E20h] [rbp-F098h] BYREF

memcpy(dest, a1, 0xF060uLL);
v1 = dest[9];
v2 = dest[7691];
v22 = dest[7];
v3 = HIDWORD(dest[7]);
v4 = dest[8];
v5 = HIDWORD(dest[8]);
strcpy(v29, (const char *)&dest[11]);
strcpy(v27, (const char *)&dest[2571]);
strcpy(v28, (const char *)&dest[5131]);
printf("%s", v29);
v6 = activesocket(v27, v1);
if ( v6 >= 0 )
{
v7 = v6;
sprintf(s, "%s %s HTTP/1.1\r\n", (&methods)[v5], v28);
v8 = strlen(s);
v9 = _mm_load_si128((const __m128i *)&LC21);
v10 = &s[v8];
*((_DWORD *)v10 + 4) = 658789;
*(__m128i *)v10 = v9;
v11 = stpcpy(&s[v8 + 19], v29);
write(v7, s, v11 - s);
printf("%s", s);
if ( v5 == 1 )
{
v18 = contentlength((__int64)v29);
if ( (int)copydata(v4, v7, v18) < 0 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v2 + 61536 * (v3 + 1LL) + 8));
close(v7);
**(_DWORD **)(v2 + 61536LL * v3 + 80) = 1;
return 0LL;
}
}
TCPreadline(v7, buf, 2560LL);
_isoc99_sscanf(buf, "HTTP/1.%d %d ", &v23, &v24);
v12 = 61536LL * v3;
HTTPreadheader(v7, v31, 20480LL);
HTTPheaderremove_case(v31, "Connection");
pthread_mutex_lock(&checkOrder);
v13 = v2 + v12;
if ( v22 && !*(_DWORD *)(v2 + v12 - 61460) )
pthread_cond_wait((pthread_cond_t *)(v2 + v12 + 8), &checkOrder);
pthread_mutex_unlock(&checkOrder);
v14 = strlen(buf);
if ( write(v4, buf, v14) != -1 )
{
printf("%s", buf);
if ( (unsigned int)closeClientConn((__int64)v29, (__int64)v31) == 1 )
{
v21 = *(_DWORD **)(v13 + 80);
strcpy(v26, "e\r\n");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC21);
*v21 = 1;
}
else
{
strcpy(v26, "-alive\r\n");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC22);
}
v15 = strlen(buf);
if ( write(v4, buf, v15) == -1 || (v16 = strlen(v31), write(v4, v31, v16) == -1) )
{
puts("Asynchronous closed by the client");
if ( v3 != 99999 )
goto LABEL_24;
goto LABEL_28;
}
printf("%s%s", buf, v31);
if ( v24 == 204 || v24 == 304 || (v17 = contentlength((__int64)v31), (int)copydata(v7, v4, v17) >= 0) )
{
close(v7);
*(_DWORD *)(v13 + 76) = 1;
pthread_mutex_lock(&checkOrder);
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v2 + v12 + 61544));
pthread_mutex_unlock(&checkOrder);
return 0LL;
}
}
puts("Asynchronous closed by the client.");
if ( v3 != 99999 )
{
LABEL_24:
pthread_cond_signal((pthread_cond_t *)(v2 + v12 + 61544));
LABEL_25:
close(v7);
**(_DWORD **)(v13 + 80) = 1;
return 0LL;
}
LABEL_28:
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
goto LABEL_25;
}
v35 = 7630437;
*(__m128i *)v31 = _mm_load_si128((const __m128i *)&LC17);
v32 = _mm_load_si128((const __m128i *)&LC18);
v33 = _mm_load_si128((const __m128i *)&LC19);
v34 = _mm_load_si128((const __m128i *)&LC20);
v19 = strlen(v31);
if ( write(v4, v31, v19) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v2 + 61536 * (v3 + 1LL) + 8));
**(_DWORD **)(v2 + 61536LL * v3 + 80) = 1;
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func5(void *a1)
{
unsigned int v1; // ebp
__int64 v2; // r13
int v3; // er14
int v4; // er12
int v5; // ebx
int v6; // eax
unsigned int v7; // ebp
size_t v8; // rax
__m128i v9; // xmm0
char *v10; // rdx
char *v11; // rax
__int64 v12; // rbx
__int64 v13; // r15
size_t v14; // rax
size_t v15; // rax
size_t v16; // rax
int v17; // eax
int v18; // eax
size_t v19; // rax
_DWORD *v21; // rax
int v22; // [rsp+Ch] [rbp-1FEACh]
char v23; // [rsp+18h] [rbp-1FEA0h] BYREF
int v24; // [rsp+1Ch] [rbp-1FE9Ch] BYREF
char buf[16]; // [rsp+20h] [rbp-1FE98h] BYREF
char v26[16]; // [rsp+30h] [rbp-1FE88h] BYREF
char v27[2560]; // [rsp+A20h] [rbp-1F498h] BYREF
char v28[2560]; // [rsp+1420h] [rbp-1EA98h] BYREF
char v29[20480]; // [rsp+1E20h] [rbp-1E098h] BYREF
char s[20480]; // [rsp+6E20h] [rbp-19098h] BYREF
char v31[16]; // [rsp+BE20h] [rbp-14098h] BYREF
__m128i v32; // [rsp+BE30h] [rbp-14088h]
__m128i v33; // [rsp+BE40h] [rbp-14078h]
__m128i v34; // [rsp+BE50h] [rbp-14068h]
int v35; // [rsp+BE60h] [rbp-14058h]
__int64 dest[7699]; // [rsp+10E20h] [rbp-F098h] BYREF

memcpy(dest, a1, 0xF060uLL);
v1 = dest[9];
v2 = dest[7691];
v22 = dest[7];
v3 = HIDWORD(dest[7]);
v4 = dest[8];
v5 = HIDWORD(dest[8]);
strcpy(v29, (const char *)&dest[11]);
strcpy(v27, (const char *)&dest[2571]);
strcpy(v28, (const char *)&dest[5131]);
printf("%s", v29);
v6 = activesocket(v27, v1);
if ( v6 >= 0 )
{
v7 = v6;
sprintf(s, "%s %s HTTP/1.1\r\n", (&methods)[v5], v28);
v8 = strlen(s);
v9 = _mm_load_si128((const __m128i *)&LC21);
v10 = &s[v8];
*((_DWORD *)v10 + 4) = 658789;
*(__m128i *)v10 = v9;
v11 = stpcpy(&s[v8 + 19], v29);
write(v7, s, v11 - s);
printf("%s", s);
if ( v5 == 1 )
{
v18 = func0((__int64)v29);
if ( (int)func3(v4, v7, v18) < 0 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v2 + 61536 * (v3 + 1LL) + 8));
close(v7);
**(_DWORD **)(v2 + 61536LL * v3 + 80) = 1;
return 0LL;
}
}
TCPreadline(v7, buf, 2560LL);
_isoc99_sscanf(buf, "HTTP/1.%d %d ", &v23, &v24);
v12 = 61536LL * v3;
HTTPreadheader(v7, v31, 20480LL);
HTTPheaderremove_case(v31, "Connection");
pthread_mutex_lock(&checkOrder);
v13 = v2 + v12;
if ( v22 && !*(_DWORD *)(v2 + v12 - 61460) )
pthread_cond_wait((pthread_cond_t *)(v2 + v12 + 8), &checkOrder);
pthread_mutex_unlock(&checkOrder);
v14 = strlen(buf);
if ( write(v4, buf, v14) != -1 )
{
printf("%s", buf);
if ( (unsigned int)func4((__int64)v29, (__int64)v31) == 1 )
{
v21 = *(_DWORD **)(v13 + 80);
strcpy(v26, "e\r\n");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC21);
*v21 = 1;
}
else
{
strcpy(v26, "-alive\r\n");
*(__m128i *)buf = _mm_load_si128((const __m128i *)&LC22);
}
v15 = strlen(buf);
if ( write(v4, buf, v15) == -1 || (v16 = strlen(v31), write(v4, v31, v16) == -1) )
{
puts("Asynchronous closed by the client");
if ( v3 != 99999 )
goto LABEL_24;
goto LABEL_28;
}
printf("%s%s", buf, v31);
if ( v24 == 204 || v24 == 304 || (v17 = func0((__int64)v31), (int)func3(v7, v4, v17) >= 0) )
{
close(v7);
*(_DWORD *)(v13 + 76) = 1;
pthread_mutex_lock(&checkOrder);
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v2 + v12 + 61544));
pthread_mutex_unlock(&checkOrder);
return 0LL;
}
}
puts("Asynchronous closed by the client.");
if ( v3 != 99999 )
{
LABEL_24:
pthread_cond_signal((pthread_cond_t *)(v2 + v12 + 61544));
LABEL_25:
close(v7);
**(_DWORD **)(v13 + 80) = 1;
return 0LL;
}
LABEL_28:
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
goto LABEL_25;
}
v35 = 7630437;
*(__m128i *)v31 = _mm_load_si128((const __m128i *)&LC17);
v32 = _mm_load_si128((const __m128i *)&LC18);
v33 = _mm_load_si128((const __m128i *)&LC19);
v34 = _mm_load_si128((const __m128i *)&LC20);
v19 = strlen(v31);
if ( write(v4, v31, v19) == -1 )
{
puts("Asynchronous closed by the client");
if ( v3 == 99999 )
pthread_cond_signal((pthread_cond_t *)(v2 + 8));
else
pthread_cond_signal((pthread_cond_t *)(v2 + 61536 * (v3 + 1LL) + 8));
**(_DWORD **)(v2 + 61536LL * v3 + 80) = 1;
}
return 0LL;
}

original_code:
void *processRequest(void *args){
 char resline[2560];
 char reqhead[20480], reqhead1[20480], reshead[20480];
 char host[2560], path[2560];
 int srv, v, status;
 REQUEST currentReq=*(REQUEST*)args;
 REQUEST *arrayHead = currentReq.arrayAddress;
 int reqID = currentReq.requestID;
 int adaptID = currentReq.adaptedID;
 int cli = currentReq.socketDescriptor;
 int method = currentReq.method;
 int portno = currentReq.portNumber;
 strcpy(reqhead, currentReq.reqhead);
 strcpy(host, currentReq.hostName);
 strcpy(path, currentReq.pathName);
 printf("%s", reqhead);
 if ((srv = activesocket(host, portno)) < 0)
 {
  sprintf(reshead, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
  if ( write(cli, reshead, strlen(reshead)) == -1 )
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
 }
 else
 {
  sprintf(reqhead1, "%s %s HTTP/1.1\r\n", methods[method], path);
  strcat(reqhead1, "Connection: close\r\n");
  strcat(reqhead1, reqhead);
  write(srv, reqhead1, strlen(reqhead1));
  printf("%s", reqhead1);
  if (method == 1)
  {
   if ( copydata(cli, srv, contentlength(reqhead)) < 0 )
   {
    printf("Asynchronous closed by the client\n");
    if (adaptID==100000 -1){
     pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  TCPreadline(srv, resline, 2560);
  sscanf(resline, "HTTP/1.%d %d ", &v, &status);
  HTTPreadheader(srv, reshead, 20480);
  HTTPheaderremove_case(reshead, "Connection");
  pthread_mutex_lock(&checkOrder);
  if( reqID==0 && (arrayHead[100000 -1].served) == 0 && reqID>100000)
  {
   pthread_cond_wait( &(arrayHead[adaptID].cond), &checkOrder);
  }
  else if( reqID!=0 && (arrayHead[adaptID-1].served)==0)
  {
   pthread_cond_wait(&(arrayHead[adaptID].cond), &checkOrder);
  }
  pthread_mutex_unlock(&checkOrder);
  if ( write(cli, resline, strlen(resline)) == -1 )
  {
   printf("Asynchronous closed by the client.\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s", resline);
  if ( closeClientConn(reqhead, reshead) == 1)
  {
   strcpy(resline, "Connection: close\r\n");
   *(arrayHead[adaptID].breakCliConn) = 1;
  }
  else
  {
   strcpy(resline, "Connection: keep-alive\r\n");
  }
  if ( write(cli, resline, strlen(resline)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  if( write(cli, reshead, strlen(reshead)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s%s", resline, reshead);
  if (status != 204 && status != 304)
  {
   if ( copydata(srv, cli, contentlength(reshead)) < 0 ){
    printf("Asynchronous closed by the client.\n");
    if (adaptID==100000 -1){
    pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  close(srv);
  arrayHead[adaptID].served = 1;
  pthread_mutex_lock(&checkOrder);
  if (adaptID==100000 -1)
  {
   pthread_cond_signal(&(arrayHead[0].cond));
  }
  else
  {
   pthread_cond_signal(&(arrayHead[adaptID+1].cond));
  }
  pthread_mutex_unlock(&checkOrder);
 }
 return ((void *)0);
}

canonical_original_code:
void *processRequest(void *args){
 char resline[2560];
 char reqhead[20480]; char reqhead1[20480]; char reshead[20480];
 char host[2560]; char path[2560];
 int srv; int v; int status;
 struct req currentReq = *(REQUEST*)args;
 struct req *arrayHead = currentReq.arrayAddress;
 int reqID = currentReq.requestID;
 int adaptID = currentReq.adaptedID;
 int cli = currentReq.socketDescriptor;
 int method = currentReq.method;
 int portno = currentReq.portNumber;
 strcpy(reqhead, currentReq.reqhead);
 strcpy(host, currentReq.hostName);
 strcpy(path, currentReq.pathName);
 printf("%s", reqhead);
 if ((srv = activesocket(host, portno)) < 0)
 {
  sprintf(reshead, "HTTP/1.1 503\r\nContent-Length: 12\r\nConnection: close\r\n\r\nNon-existent");
  if ( write(cli, reshead, strlen(reshead)) == -1 )
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
 }
 else
 {
  sprintf(reqhead1, "%s %s HTTP/1.1\r\n", methods[method], path);
  strcat(reqhead1, "Connection: close\r\n");
  strcat(reqhead1, reqhead);
  write(srv, reqhead1, strlen(reqhead1));
  printf("%s", reqhead1);
  if (method == 1)
  {
   if ( copydata(cli, srv, contentlength(reqhead)) < 0 )
   {
    printf("Asynchronous closed by the client\n");
    if (adaptID==100000 -1){
     pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  TCPreadline(srv, resline, 2560);
  sscanf(resline, "HTTP/1.%d %d ", &v, &status);
  HTTPreadheader(srv, reshead, 20480);
  HTTPheaderremove_case(reshead, "Connection");
  pthread_mutex_lock(&checkOrder);
  if( reqID==0 && (arrayHead[100000 -1].served) == 0 && reqID>100000)
  {
   pthread_cond_wait( &(arrayHead[adaptID].cond), &checkOrder);
  }
  else if( reqID!=0 && (arrayHead[adaptID-1].served)==0)
  {
   pthread_cond_wait(&(arrayHead[adaptID].cond), &checkOrder);
  }
  pthread_mutex_unlock(&checkOrder);
  if ( write(cli, resline, strlen(resline)) == -1 )
  {
   printf("Asynchronous closed by the client.\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s", resline);
  if ( closeClientConn(reqhead, reshead) == 1)
  {
   strcpy(resline, "Connection: close\r\n");
   *(arrayHead[adaptID].breakCliConn) = 1;
  }
  else
  {
   strcpy(resline, "Connection: keep-alive\r\n");
  }
  if ( write(cli, resline, strlen(resline)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  if( write(cli, reshead, strlen(reshead)) == -1)
  {
   printf("Asynchronous closed by the client\n");
   if (adaptID==100000 -1){
   pthread_cond_signal(&(arrayHead[0].cond));
   }else{
    pthread_cond_signal(&(arrayHead[adaptID+1].cond));
   }
   close(srv);
   *(arrayHead[adaptID].breakCliConn) = 1;
   return ((void *)0);
  }
  printf("%s%s", resline, reshead);
  if (status != 204 && status != 304)
  {
   if ( copydata(srv, cli, contentlength(reshead)) < 0 ){
    printf("Asynchronous closed by the client.\n");
    if (adaptID==100000 -1){
    pthread_cond_signal(&(arrayHead[0].cond));
    }else{
     pthread_cond_signal(&(arrayHead[adaptID+1].cond));
    }
    close(srv);
    *(arrayHead[adaptID].breakCliConn) = 1;
    return ((void *)0);
   }
  }
  close(srv);
  arrayHead[adaptID].served = 1;
  pthread_mutex_lock(&checkOrder);
  if (adaptID==100000 -1)
  {
   pthread_cond_signal(&(arrayHead[0].cond));
  }
  else
  {
   pthread_cond_signal(&(arrayHead[adaptID+1].cond));
  }
  pthread_mutex_unlock(&checkOrder);
 }
 return ((void *)0);
}

variable_types:
args
void *

variable_types:
resline
char [2560]

variable_types:
reqhead
char [20480]

variable_types:
reshead
char [20480]

variable_types:
host
char [2560]

variable_types:
path
char [2560]

variable_types: srv int

variable_types: v int

variable_types: status int

variable_types: struct req { unsigned long reqThread; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int requestID; int adaptedID; int socketDescriptor; int method; int portNumber; int served; int *breakCliConn; char reqhead[20480]; char hostName[20480]; char pathName[20480]; struct req *arrayAddress; }

variable_types: reqID int

variable_types: adaptID int

variable_types: cli int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // ebx
pthread_t *v5; // rbp
int arg[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = atoi(argv[1]);
v4 = passivesocket(v3);
signal(13, (__sighandler_t)((char *)contentlength + 1));
while ( 1 )
{
do
arg[0] = acceptconnection(v4);
while ( arg[0] == -1 );
v5 = (pthread_t *)malloc(8uLL);
pthread_mutex_lock(&accessCLI);
pthread_create(v5, 0LL, serviceconn, arg);
pthread_mutex_unlock(&accessCLI);
}
}

original_code:
int main(int argc, char *argv[])
{
 int socketDescriptor;
 int s = passivesocket(atoi(argv[1]));
 signal(13, ((__sighandler_t) 1));
 while(1){
  socketDescriptor= acceptconnection(s);
  if (socketDescriptor != -1)
  {
   pthread_t *client;
   client=(pthread_t*)malloc(sizeof(pthread_t));
   pthread_mutex_lock(&accessCLI);
   pthread_create(client, ((void *)0), serviceconn, &socketDescriptor);
   pthread_mutex_unlock(&accessCLI);
  }
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int socketDescriptor;
 int s = passivesocket(atoi(argv[1]));
 signal(13, ((void (*)(int)) 1));
 while(1){
  socketDescriptor= acceptconnection(s);
  if (socketDescriptor != -1)
  {
   unsigned long *client;
   client=(unsigned long *)malloc(sizeof(pthread_t));
   pthread_mutex_lock(&accessCLI);
   pthread_create(client, ((void *)0), serviceconn, &socketDescriptor);
   pthread_mutex_unlock(&accessCLI);
  }
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: socketDescriptor int

variable_types: s int

variable_types:
client
unsigned long *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
_BYTE v5[24]; // [rsp+0h] [rbp-18h] BYREF

parse_args(argc, (char **)argv);
v3 = (unsigned int)dlt;
if ( (unsigned int)pcap_compile_nopcap() )
{
fwrite("Syntax error in expression\n", 1uLL, 0x1BuLL, stderr);
exit(64);
}
switch ( format )
{
case 1:
print_hexstring(v5, v3);
break;
case 2:
print_ng_bpf(v5, v3);
break;
case 0:
print_raw(v5, v3);
break;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rsi
_BYTE v5[24]; // [rsp+0h] [rbp-18h] BYREF

func8(argc, (char **)argv);
v3 = (unsigned int)dlt;
if ( (unsigned int)pcap_compile_nopcap() )
{
fwrite("Syntax error in expression\n", 1uLL, 0x1BuLL, stderr);
exit(64);
}
switch ( format )
{
case 1:
func10(v5, v3);
break;
case 2:
func11(v5, v3);
break;
case 0:
func9(v5, v3);
break;
}
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 struct bpf_program prog;
 parse_args(argc, argv);
 if (pcap_compile_nopcap(snaplen, dlt, &prog, expr, 1, 0))
 {
  fprintf(stderr, "Syntax error in expression\n");
  exit(64);
 }
 switch(format)
 {
 case RAW:
  print_raw(&prog);
  break;
 case HEXSTRING:
  print_hexstring(&prog);
  break;
 case NG_BPF:
  print_ng_bpf(&prog);
  break;
 }
 return 0;
}

variable_types: struct bpf_program { unsigned int bf_len; struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *bf_insns; }

user_defined_types: struct bpf_program { unsigned int bf_len; struct bpf_insn *bf_insns; }


decompiled_code:
char *__fastcall parse_args(int argc, char **argv)
{
char *v3; // r12
char v4; // al
int v5; // edi
char *v6; // rax
char v7; // al
int v8; // ebp
const char **v9; // r13
size_t v10; // r12
const char **v11; // rbx
const char *v12; // rdi
char *v13; // rax
const char *v14; // r12
char *result; // rax
const char **v16; // rbx
__int64 v17; // rbp

v3 = *argv;
while ( 1 )
{
v4 = getopt(argc, argv, "hl:s:o:");
if ( v4 == -1 )
break;
if ( v4 == 111 )
{
v7 = *optarg;
if ( *optarg == 110 )
{
format = 2;
}
else if ( v7 == 114 )
{
format = 0;
}
else
{
if ( v7 != 104 )
{
fprintf(stderr, "Unknown format: %c\n", (unsigned int)v7);
goto LABEL_17;
}
format = 1;
}
}
else
{
if ( v4 > 111 )
{
if ( v4 != 115 )
goto LABEL_17;
}
else
{
if ( v4 == 104 )
{
usage(stdout, v3);
exit(0);
}
if ( v4 != 108 )
goto LABEL_17;
}
dlt = strtol(optarg, 0LL, 0);
if ( !dlt )
{
v5 = *__errno_location();
if ( v5 )
{
v6 = strerror(v5);
fprintf(stderr, "Failed to parse %s: %s\n", optarg, v6);
exit(64);
}
}
}
}
v8 = argc - optind;
v9 = (const char **)&argv[optind];
if ( !v8 )
{
fwrite("Expression expected\n", 1uLL, 0x14uLL, stderr);
LABEL_17:
usage(stderr, v3);
exit(64);
}
v10 = v8;
if ( v8 > 0 )
{
v11 = (const char **)&argv[optind];
do
{
v12 = *v11++;
v10 += strlen(v12);
}
while ( v11 != &v9[(unsigned int)(v8 - 1) + 1] );
}
v13 = (char *)malloc(v10);
expr = v13;
v14 = v13;
if ( !v13 )
exit(70);
*v13 = 0;
result = strcpy(v13, *v9);
if ( v8 > 1 )
{
v16 = v9 + 1;
v17 = (__int64)&v9[(unsigned int)(v8 - 2) + 2];
while ( 1 )
{
++v16;
*(_WORD *)&v14[strlen(v14)] = 32;
result = strcat(expr, *(v16 - 1));
if ( v16 == (const char **)v17 )
break;
v14 = expr;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(int argc, char **argv)
{
char *v3; // r12
char v4; // al
int v5; // edi
char *v6; // rax
char v7; // al
int v8; // ebp
const char **v9; // r13
size_t v10; // r12
const char **v11; // rbx
const char *v12; // rdi
char *v13; // rax
const char *v14; // r12
char *result; // rax
const char **v16; // rbx
__int64 v17; // rbp

v3 = *argv;
while ( 1 )
{
v4 = getopt(argc, argv, "hl:s:o:");
if ( v4 == -1 )
break;
if ( v4 == 111 )
{
v7 = *optarg;
if ( *optarg == 110 )
{
format = 2;
}
else if ( v7 == 114 )
{
format = 0;
}
else
{
if ( v7 != 104 )
{
fprintf(stderr, "Unknown format: %c\n", (unsigned int)v7);
goto LABEL_17;
}
format = 1;
}
}
else
{
if ( v4 > 111 )
{
if ( v4 != 115 )
goto LABEL_17;
}
else
{
if ( v4 == 104 )
{
func7(stdout, v3);
exit(0);
}
if ( v4 != 108 )
goto LABEL_17;
}
dlt = strtol(optarg, 0LL, 0);
if ( !dlt )
{
v5 = *__errno_location();
if ( v5 )
{
v6 = strerror(v5);
fprintf(stderr, "Failed to parse %s: %s\n", optarg, v6);
exit(64);
}
}
}
}
v8 = argc - optind;
v9 = (const char **)&argv[optind];
if ( !v8 )
{
fwrite("Expression expected\n", 1uLL, 0x14uLL, stderr);
LABEL_17:
func7(stderr, v3);
exit(64);
}
v10 = v8;
if ( v8 > 0 )
{
v11 = (const char **)&argv[optind];
do
{
v12 = *v11++;
v10 += strlen(v12);
}
while ( v11 != &v9[(unsigned int)(v8 - 1) + 1] );
}
v13 = (char *)malloc(v10);
expr = v13;
v14 = v13;
if ( !v13 )
exit(70);
*v13 = 0;
result = strcpy(v13, *v9);
if ( v8 > 1 )
{
v16 = v9 + 1;
v17 = (__int64)&v9[(unsigned int)(v8 - 2) + 2];
while ( 1 )
{
++v16;
*(_WORD *)&v14[strlen(v14)] = 32;
result = strcat(expr, *(v16 - 1));
if ( v16 == (const char **)v17 )
break;
v14 = expr;
}
}
return result;
}

original_code:
void
parse_args(int argc, char *argv[])
{
 char c;
 char *progname = argv[0];
 int i;
 size_t len;
 while((c = getopt(argc, argv, "hl:s:o:")) != -1)
 {
  switch(c)
  {
  case 'h':
   usage(stdout, progname);
   exit(0);
   break;
  case 'l':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 's':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 'o':
   switch(optarg[0])
   {
   case 'r':
    format = RAW;
    break;
   case 'h':
    format = HEXSTRING;
    break;
   case 'n':
    format = NG_BPF;
    break;
   default:
    fprintf(stderr, "Unknown format: %c\n", optarg[0]);
    usage(stderr, progname);
    exit(64);
    break;
   }
   break;
  default:
   usage(stderr, progname);
   exit(64);
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0)
 {
  fprintf(stderr, "Expression expected\n");
  usage(stderr, progname);
  exit(64);
 }
 len = argc;
 for(i = 0; i < argc; i++)
  len += strlen(argv[i]);
 expr = malloc(len);
 if (expr == ((void *)0))
  exit(70);
 expr[0] = '\0';
 strcat(expr, argv[0]);
 for(i = 1; i < argc; i++)
 {
  strcat(expr, " ");
  strcat(expr, argv[i]);
 }
}

canonical_original_code:
void parse_args(int argc, char *argv[])
{
 char c;
 char *progname = argv[0];
 int i;
 unsigned long len;
 while((c = getopt(argc, argv, "hl:s:o:")) != -1)
 {
  switch(c)
  {
  case 'h':
   usage(stdout, progname);
   exit(0);
   break;
  case 'l':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 's':
   if ((dlt = strtol(optarg, ((void *)0), 0)) == 0 && (*__errno_location ()) != 0)
   {
    fprintf(stderr, "Failed to parse %s: %s\n", optarg, strerror((*__errno_location ())));
    exit(64);
   }
   break;
  case 'o':
   switch(optarg[0])
   {
   case 'r':
    format = RAW;
    break;
   case 'h':
    format = HEXSTRING;
    break;
   case 'n':
    format = NG_BPF;
    break;
   default:
    fprintf(stderr, "Unknown format: %c\n", optarg[0]);
    usage(stderr, progname);
    exit(64);
    break;
   }
   break;
  default:
   usage(stderr, progname);
   exit(64);
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc == 0)
 {
  fprintf(stderr, "Expression expected\n");
  usage(stderr, progname);
  exit(64);
 }
 len = argc;
 for(i = 0; i < argc; i++)
  len += strlen(argv[i]);
 expr = malloc(len);
 if (expr == ((void *)0))
  exit(70);
 expr[0] = '\0';
 strcat(expr, argv[0]);
 for(i = 1; i < argc; i++)
 {
  strcat(expr, " ");
  strcat(expr, argv[i]);
 }
}

variable_types: c char

variable_types:
progname
char *

variable_types: i int

variable_types:
len
unsigned long


decompiled_code:
unsigned __int64 __fastcall print_raw(unsigned int *a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r12
__int64 v4; // rbp
int v5; // edi

result = *a1;
if ( (_DWORD)result )
{
v2 = 0LL;
do
{
v4 = 8 * v2;
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v2 + 1));
v5 = *(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v2++);
putchar(v5);
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 2));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 3));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 7));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 6));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 5));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 4));
result = *a1;
}
while ( result > v2 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned int *a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r12
__int64 v4; // rbp
int v5; // edi

result = *a1;
if ( (_DWORD)result )
{
v2 = 0LL;
do
{
v4 = 8 * v2;
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v2 + 1));
v5 = *(unsigned __int8 *)(*((_QWORD *)a1 + 1) + 8 * v2++);
putchar(v5);
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 2));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 3));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 7));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 6));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 5));
putchar(*(unsigned __int8 *)(*((_QWORD *)a1 + 1) + v4 + 4));
result = *a1;
}
while ( result > v2 );
}
return result;
}

original_code:
void
print_raw(const struct bpf_program *prog)
{
 size_t i;
 for(i = 0; i < prog->bf_len; i++)
 {
  putchar(prog->bf_insns[i].code >> 8);
  putchar(prog->bf_insns[i].code & 0xff);
  putchar(prog->bf_insns[i].jt);
  putchar(prog->bf_insns[i].jf);
  putchar(prog->bf_insns[i].k >> 24);
  putchar((prog->bf_insns[i].k >> 16) & 0xff);
  putchar((prog->bf_insns[i].k >> 8) & 0xff);
  putchar(prog->bf_insns[i].k & 0xff);
 }
}

canonical_original_code:
void print_raw(struct bpf_program *prog)
{
 unsigned long i;
 for(i = 0; i < prog->bf_len; i++)
 {
  putchar(prog->bf_insns[i].code >> 8);
  putchar(prog->bf_insns[i].code & 0xff);
  putchar(prog->bf_insns[i].jt);
  putchar(prog->bf_insns[i].jf);
  putchar(prog->bf_insns[i].k >> 24);
  putchar((prog->bf_insns[i].k >> 16) & 0xff);
  putchar((prog->bf_insns[i].k >> 8) & 0xff);
  putchar(prog->bf_insns[i].k & 0xff);
 }
}

variable_types: struct bpf_program { unsigned int bf_len; struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *bf_insns; } *

variable_types:
i
unsigned long


original_code:
void
print_hexstring(const struct bpf_program *prog)
{
 size_t i;
 for(i = 0; i < prog->bf_len; i++)
 {
  printf("%02X", prog->bf_insns[i].code >> 8);
  printf("%02X", prog->bf_insns[i].code & 0xff);
  printf("%02X", prog->bf_insns[i].jt);
  printf("%02X", prog->bf_insns[i].jf);
  printf("%02X", prog->bf_insns[i].k >> 24);
  printf("%02X", (prog->bf_insns[i].k >> 16) & 0xff);
  printf("%02X", (prog->bf_insns[i].k >> 8) & 0xff);
  printf("%02X", prog->bf_insns[i].k & 0xff);
 }
 printf("\n");
}

canonical_original_code:
void print_hexstring(struct bpf_program *prog)
{
 unsigned long i;
 for(i = 0; i < prog->bf_len; i++)
 {
  printf("%02X", prog->bf_insns[i].code >> 8);
  printf("%02X", prog->bf_insns[i].code & 0xff);
  printf("%02X", prog->bf_insns[i].jt);
  printf("%02X", prog->bf_insns[i].jf);
  printf("%02X", prog->bf_insns[i].k >> 24);
  printf("%02X", (prog->bf_insns[i].k >> 16) & 0xff);
  printf("%02X", (prog->bf_insns[i].k >> 8) & 0xff);
  printf("%02X", prog->bf_insns[i].k & 0xff);
 }
 printf("\n");
}

user_defined_types: struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; }


decompiled_code:
int __fastcall print_ng_bpf(unsigned int *a1)
{
unsigned __int64 v1; // rbx
unsigned __int16 *v2; // rax

printf("bpf_prog_len=%d bpf_prog=[ ", *a1);
if ( *a1 )
{
v1 = 0LL;
do
{
v2 = (unsigned __int16 *)(*((_QWORD *)a1 + 1) + 8 * v1++);
printf(
"{ code=%d jt=%d jf=%d k=%d } ",
*v2,
*((unsigned __int8 *)v2 + 2),
*((unsigned __int8 *)v2 + 3),
*((unsigned int *)v2 + 1));
}
while ( *a1 > v1 );
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
unsigned __int64 v1; // rbx
unsigned __int16 *v2; // rax

printf("bpf_prog_len=%d bpf_prog=[ ", *a1);
if ( *a1 )
{
v1 = 0LL;
do
{
v2 = (unsigned __int16 *)(*((_QWORD *)a1 + 1) + 8 * v1++);
printf(
"{ code=%d jt=%d jf=%d k=%d } ",
*v2,
*((unsigned __int8 *)v2 + 2),
*((unsigned __int8 *)v2 + 3),
*((unsigned int *)v2 + 1));
}
while ( *a1 > v1 );
}
return puts("]");
}

original_code:
void
print_ng_bpf(const struct bpf_program *prog)
{
 size_t i;
 printf("bpf_prog_len=%d bpf_prog=[ ", prog->bf_len);
 for (i = 0; i < prog->bf_len; i++)
 {
  printf("{ code=%d jt=%d jf=%d k=%d } ", prog->bf_insns[i].code, prog->bf_insns[i].jt, prog->bf_insns[i].jf, prog->bf_insns[i].k);
 }
 printf("]\n");
}

canonical_original_code:
void print_ng_bpf(struct bpf_program *prog)
{
 unsigned long i;
 printf("bpf_prog_len=%d bpf_prog=[ ", prog->bf_len);
 for (i = 0; i < prog->bf_len; i++)
 {
  printf("{ code=%d jt=%d jf=%d k=%d } ", prog->bf_insns[i].code, prog->bf_insns[i].jt, prog->bf_insns[i].jf, prog->bf_insns[i].k);
 }
 printf("]\n");
}


RangeDestroy

decompiled_code:
void __fastcall RangeDestroy(void *a1)
{
if ( a1 )
free(a1);
}

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

original_code:
void RangeDestroy(Range *r) {
    if (r) {
        free(r);
        r = ((void *)0);
    }
}

canonical_original_code:
void RangeDestroy(struct Range *r) {
    if (r) {
        free(r);
        r = ((void *)0);
    }
}

variable_types: struct Range { unsigned long max; unsigned long min; } *


WriteSetCreate

decompiled_code:
_QWORD *WriteSetCreate()
{
_QWORD *v0; // r12

v0 = malloc(8uLL);
*v0 = al_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // r12

v0 = malloc(8uLL);
*v0 = al_new();
return v0;
}

original_code:
WriteSet *WriteSetCreate() {
    WriteSet *new = malloc(sizeof(WriteSet));
    new->ranges = al_new();
    return (new);
}

canonical_original_code:
struct WriteSet *WriteSetCreate() {
    struct WriteSet *new = malloc(sizeof(WriteSet));
    new->ranges = al_new();
    return (new);
}

variable_types: struct WriteSet { struct ArrayList { void **al_elements; int al_size; int al_capacity; enum ATYPE { AL_LIST_UNSORTED=0, AL_LIST_SORTED=1, AL_LIST_SET=2 } al_type; int al_lock; unsigned int flags; int (*al_compare)(void *, void *); void (*al_print)(void *); void (*al_free)(void *); } *ranges; } *

user_defined_types: struct WriteSet { struct ArrayList *ranges; }

user_defined_types: struct ArrayList { void **al_elements; int al_size; int al_capacity; enum ATYPE al_type; int al_lock; unsigned int flags; int (*al_compare)(void *, void *); void (*al_print)(void *); void (*al_free)(void *); }


WriteSetDestroy

decompiled_code:
void __fastcall WriteSetDestroy(void *ptr)
{
if ( ptr )
{
al_freeWithElements(*(_QWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
al_freeWithElements(*(_QWORD *)ptr);
free(ptr);
}
}

original_code:
void WriteSetDestroy(WriteSet *ws) {
    if(ws != ((void *)0)) {
        al_freeWithElements(ws->ranges);
        free(ws);
    }
    ws = ((void *)0);
}

canonical_original_code:
void WriteSetDestroy(struct WriteSet *ws) {
    if(ws != ((void *)0)) {
        al_freeWithElements(ws->ranges);
        free(ws);
    }
    ws = ((void *)0);
}

user_defined_types: enum ATYPE { AL_LIST_UNSORTED=0, AL_LIST_SORTED=1, AL_LIST_SET=2 }


AddRangeToWriteSet

decompiled_code:
void __fastcall AddRangeToWriteSet(_QWORD *a1, unsigned __int64 *a2)
{
unsigned int v4; // ebx
int v5; // er13
unsigned __int64 *v6; // rbp
unsigned __int64 v7; // rax
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rsi
__int64 v10; // rdi

if ( a2 )
{
if ( *a2 < a2[1] )
{
free(a2);
}
else
{
v4 = 0;
v5 = al_size(*a1);
if ( v5 > 0 )
{
do
{
v6 = (unsigned __int64 *)al_get(*a1, v4);
v7 = *a2;
v8 = v6[1];
if ( *a2 + 1 < v8 || (v9 = a2[1], v9 - 1 > *v6) )
{
++v4;
}
else
{
v10 = *a1;
if ( v8 > v9 )
v8 = a2[1];
if ( v7 < *v6 )
v7 = *v6;
a2[1] = v8;
*a2 = v7;
al_removeAt(v10, v4);
free(v6);
v5 = al_size(*a1);
}
}
while ( v5 > (int)v4 );
}
al_add(*a1, a2);
}
}
}

original_code:
void AddRangeToWriteSet(WriteSet *ws, Range *r) {
 if(r == ((void *)0)) {
  return;
 }
    if(r->max < r->min) {
     free(r);
        return;
    }
    int i;
    ADDRESS min, max;
    int len = al_size(ws->ranges);
    Range *temp = r;
    i = 0;
    while(i < len) {
        Range *next = (Range *)al_get(ws->ranges, i);
        if( ((temp->max+1) >= next->min) && ((temp->min-1) <= next->max) ) {
            min = temp->min;
            if(next->min < min) {
                min = next->min;
            }
            max = temp->max;
            if(next->max > max) {
                max = next->max;
            }
            temp->min = min;
            temp->max = max;
            al_removeAt(ws->ranges, i);
            free(next);
            len = al_size(ws->ranges);
        } else {
            i++;
        }
    }
    al_add(ws->ranges, temp);
}

canonical_original_code:
void AddRangeToWriteSet(struct WriteSet *ws, struct Range *r) {
 if(r == ((void *)0)) {
  return;
 }
    if(r->max < r->min) {
     free(r);
        return;
    }
    int i;
    unsigned long min; unsigned long max;
    int len = al_size(ws->ranges);
    struct Range *temp = r;
    i = 0;
    while(i < len) {
        struct Range *next = (Range *)al_get(ws->ranges, i);
        if( ((temp->max+1) >= next->min) && ((temp->min-1) <= next->max) ) {
            min = temp->min;
            if(next->min < min) {
                min = next->min;
            }
            max = temp->max;
            if(next->max > max) {
                max = next->max;
            }
            temp->min = min;
            temp->max = max;
            al_removeAt(ws->ranges, i);
            free(next);
            len = al_size(ws->ranges);
        } else {
            i++;
        }
    }
    al_add(ws->ranges, temp);
}

variable_types:
min
unsigned long

variable_types:
max
unsigned long

variable_types: len int

user_defined_types: struct Range { unsigned long max; unsigned long min; }


ValInWriteSet

decompiled_code:
__int64 __fastcall ValInWriteSet(_QWORD *a1, unsigned __int64 a2)
{
__int64 v2; // rbp
unsigned __int64 *v3; // rax

v2 = al_iterator(*a1);
while ( (*(unsigned int (__fastcall **)(__int64))(v2 + 40))(v2) )
{
v3 = (unsigned __int64 *)(*(__int64 (__fastcall **)(__int64))(v2 + 32))(v2);
if ( v3[1] <= a2 && *v3 >= a2 )
{
free((void *)v2);
return 1LL;
}
}
free((void *)v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, unsigned __int64 a2)
{
__int64 v2; // rbp
unsigned __int64 *v3; // rax

v2 = al_iterator(*a1);
while ( (*(unsigned int (__fastcall **)(__int64))(v2 + 40))(v2) )
{
v3 = (unsigned __int64 *)(*(__int64 (__fastcall **)(__int64))(v2 + 32))(v2);
if ( v3[1] <= a2 && *v3 >= a2 )
{
free((void *)v2);
return 1LL;
}
}
free((void *)v2);
return 0LL;
}

original_code:
_Bool ValInWriteSet(WriteSet *ws, ADDRESS val) {
    _Bool valInWS = 0;
    Iterator *itr = al_iterator(ws->ranges);
    while (!valInWS && itr->it_hasNext(itr)) {
        Range *r = (Range *)itr->it_next(itr);
        if ((val >= r->min) && (val <= r->max) ) {
            valInWS = 1;
        }
    }
    free(itr);
    return (valInWS);
}

canonical_original_code:
_Bool ValInWriteSet(struct WriteSet *ws, unsigned long val) {
    _Bool valInWS = 0;
    struct Iterator *itr = al_iterator(ws->ranges);
    while (!valInWS && itr->it_hasNext(itr)) {
        struct Range *r = (Range *)itr->it_next(itr);
        if ((val >= r->min) && (val <= r->max) ) {
            valInWS = 1;
        }
    }
    free(itr);
    return (valInWS);
}

variable_types:
val
unsigned long

variable_types: struct Iterator { void *it_dataStructure; void *it_current; void *it_opaque1; void *it_opaque2; void *(*it_next)(struct Iterator *); int (*it_hasNext)(struct Iterator *); void *(*it_remove)(struct Iterator *); } *


WriteSetIsEmpty

decompiled_code:
bool __fastcall WriteSetIsEmpty(_QWORD *a1)
{
_QWORD *v2; // rax

if ( !a1 )
return 1;
if ( !(unsigned int)al_size(*a1) )
return 1;
v2 = (_QWORD *)al_get(*a1, 0LL);
return *v2 < v2[1];
}

canonical_decompiled_code:
bool __fastcall func5(_QWORD *a1)
{
_QWORD *v2; // rax

if ( !a1 )
return 1;
if ( !(unsigned int)al_size(*a1) )
return 1;
v2 = (_QWORD *)al_get(*a1, 0LL);
return *v2 < v2[1];
}

original_code:
_Bool WriteSetIsEmpty(WriteSet *ws) {
 if(ws == ((void *)0)) {
  return (1);
 }
    int len = al_size(ws->ranges);
    if(len == 0) {
        return (1);
    }
    _Bool isEmpty = 0;
    Range *r = al_get(ws->ranges,0);
    if(r->max < r->min) {
        isEmpty = 1;
    }
    return (isEmpty);
}

canonical_original_code:
_Bool WriteSetIsEmpty(struct WriteSet *ws) {
 if(ws == ((void *)0)) {
  return (1);
 }
    int len = al_size(ws->ranges);
    if(len == 0) {
        return (1);
    }
    _Bool isEmpty = 0;
    struct Range *r = al_get(ws->ranges,0);
    if(r->max < r->min) {
        isEmpty = 1;
    }
    return (isEmpty);
}


WriteSetEquals

decompiled_code:
__int64 __fastcall WriteSetEquals(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax
unsigned __int64 v4; // r15
unsigned __int64 *j; // rbx
__int64 v6; // rax
unsigned __int64 v7; // r15
unsigned __int64 *l; // rbx
unsigned int i; // [rsp+4h] [rbp-44h]
unsigned int k; // [rsp+4h] [rbp-44h]
int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]

v2 = 1;
v13 = al_size(*a1);
v12 = al_size(*a2);
if ( v13 > 0 )
{
for ( i = 0; i != v13; ++i )
{
v3 = al_get(*a1, i);
v4 = *(_QWORD *)(v3 + 8);
for ( j = (unsigned __int64 *)v3; *j >= v4; ++v4 )
{
if ( !(unsigned __int8)ValInWriteSet(a2, v4) )
v2 = 0;
}
}
}
if ( v12 > 0 )
{
for ( k = 0; k != v12; ++k )
{
v6 = al_get(*a2, k);
v7 = *(_QWORD *)(v6 + 8);
for ( l = (unsigned __int64 *)v6; *l >= v7; ++v7 )
{
if ( !(unsigned __int8)ValInWriteSet(a1, v7) )
v2 = 0;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax
unsigned __int64 v4; // r15
unsigned __int64 *j; // rbx
__int64 v6; // rax
unsigned __int64 v7; // r15
unsigned __int64 *l; // rbx
unsigned int i; // [rsp+4h] [rbp-44h]
unsigned int k; // [rsp+4h] [rbp-44h]
int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]

v2 = 1;
v13 = al_size(*a1);
v12 = al_size(*a2);
if ( v13 > 0 )
{
for ( i = 0; i != v13; ++i )
{
v3 = al_get(*a1, i);
v4 = *(_QWORD *)(v3 + 8);
for ( j = (unsigned __int64 *)v3; *j >= v4; ++v4 )
{
if ( !(unsigned __int8)func4(a2, v4) )
v2 = 0;
}
}
}
if ( v12 > 0 )
{
for ( k = 0; k != v12; ++k )
{
v6 = al_get(*a2, k);
v7 = *(_QWORD *)(v6 + 8);
for ( l = (unsigned __int64 *)v6; *l >= v7; ++v7 )
{
if ( !(unsigned __int8)func4(a1, v7) )
v2 = 0;
}
}
}
return v2;
}

original_code:
_Bool WriteSetEquals(WriteSet *ws1, WriteSet *ws2) {
    int i = 0;
    ADDRESS j = 0;
    _Bool same = 1;
    int sz1 = al_size(ws1->ranges);
    int sz2 = al_size(ws2->ranges);
    for (i = 0; i < sz1; i++) {
        Range *next1 = (Range *) al_get(ws1->ranges, i);
        for(j = next1->min; j <= next1->max; j++) {
            if(!ValInWriteSet(ws2, j)) {
                same = 0;
            }
        }
    }
    for (i = 0; i < sz2; i++) {
        Range *next2 = (Range *) al_get(ws2->ranges, i);
        for(j = next2->min; j <= next2->max; j++) {
            if(!ValInWriteSet(ws1, j)) {
                same = 0;
            }
        }
    }
    return (same);
}

canonical_original_code:
_Bool WriteSetEquals(struct WriteSet *ws1, struct WriteSet *ws2) {
    int i = 0;
    unsigned long j = 0;
    _Bool same = 1;
    int sz1 = al_size(ws1->ranges);
    int sz2 = al_size(ws2->ranges);
    for (i = 0; i < sz1; i++) {
        struct Range *next1 = (Range *) al_get(ws1->ranges, i);
        for(j = next1->min; j <= next1->max; j++) {
            if(!ValInWriteSet(ws2, j)) {
                same = 0;
            }
        }
    }
    for (i = 0; i < sz2; i++) {
        struct Range *next2 = (Range *) al_get(ws2->ranges, i);
        for(j = next2->min; j <= next2->max; j++) {
            if(!ValInWriteSet(ws1, j)) {
                same = 0;
            }
        }
    }
    return (same);
}

variable_types:
j
unsigned long


WriteSetsOverlap

decompiled_code:
__int64 __fastcall WriteSetsOverlap(_QWORD *a1, _QWORD *a2)
{
int v3; // eax
int v4; // ebp
unsigned int v5; // er13
unsigned __int64 *v6; // rax
unsigned __int64 v7; // r14
unsigned __int64 v8; // r12
unsigned int v9; // er15
unsigned __int64 *v10; // rax
unsigned __int64 v11; // rsi
unsigned __int64 v12; // rdx
int v14; // [rsp+Ch] [rbp-3Ch]

v14 = al_size(*a1);
v3 = al_size(*a2);
if ( v14 <= 0 )
return 0LL;
v4 = v3;
v5 = 0;
while ( 1 )
{
v6 = (unsigned __int64 *)al_get(*a1, v5);
v7 = *v6;
v8 = v6[1];
if ( v4 > 0 )
break;
LABEL_12:
if ( v14 == ++v5 )
return 0LL;
}
v9 = 0;
while ( 1 )
{
v10 = (unsigned __int64 *)al_get(*a2, v9);
v11 = v7;
v12 = v8;
if ( *v10 <= v7 )
v11 = *v10;
if ( v10[1] >= v8 )
v12 = v10[1];
if ( v11 >= v12 )
return 1LL;
if ( v4 == ++v9 )
goto LABEL_12;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD *a2)
{
int v3; // eax
int v4; // ebp
unsigned int v5; // er13
unsigned __int64 *v6; // rax
unsigned __int64 v7; // r14
unsigned __int64 v8; // r12
unsigned int v9; // er15
unsigned __int64 *v10; // rax
unsigned __int64 v11; // rsi
unsigned __int64 v12; // rdx
int v14; // [rsp+Ch] [rbp-3Ch]

v14 = al_size(*a1);
v3 = al_size(*a2);
if ( v14 <= 0 )
return 0LL;
v4 = v3;
v5 = 0;
while ( 1 )
{
v6 = (unsigned __int64 *)al_get(*a1, v5);
v7 = *v6;
v8 = v6[1];
if ( v4 > 0 )
break;
LABEL_12:
if ( v14 == ++v5 )
return 0LL;
}
v9 = 0;
while ( 1 )
{
v10 = (unsigned __int64 *)al_get(*a2, v9);
v11 = v7;
v12 = v8;
if ( *v10 <= v7 )
v11 = *v10;
if ( v10[1] >= v8 )
v12 = v10[1];
if ( v11 >= v12 )
return 1LL;
if ( v4 == ++v9 )
goto LABEL_12;
}
}

original_code:
_Bool WriteSetsOverlap(WriteSet *ws1, WriteSet *ws2)
{
  Range *r1, *r2;
  int sz1 = al_size(ws1->ranges), sz2 = al_size(ws2->ranges);
  int i, j;
  ADDRESS max1, min1, max2, min2, newMax, newMin;
    for (i = 0; i < sz1; i++) {
      r1 = (Range *) al_get(ws1->ranges, i);
      max1 = r1->max;
      min1 = r1->min;
      for (j = 0; j < sz2; j++) {
        r2 = (Range *) al_get(ws2->ranges, j);
        max2 = r2->max;
        min2 = r2->min;
        newMax = (max1 < max2 ? max1 : max2);
        newMin = (min1 > min2 ? min1 : min2);
        if (newMin <= newMax) {
          return 1;
        }
      }
    }
    return 0;
}

canonical_original_code:
_Bool WriteSetsOverlap(struct WriteSet *ws1, struct WriteSet *ws2)
{
  struct Range *r1; struct Range *r2;
  int sz1 = al_size(ws1->ranges); int sz2 = al_size(ws2->ranges);
  int i; int j;
  unsigned long max1; unsigned long min1; unsigned long max2; unsigned long min2; unsigned long newMax; unsigned long newMin;
    for (i = 0; i < sz1; i++) {
      r1 = (struct Range *) al_get(ws1->ranges, i);
      max1 = r1->max;
      min1 = r1->min;
      for (j = 0; j < sz2; j++) {
        r2 = (struct Range *) al_get(ws2->ranges, j);
        max2 = r2->max;
        min2 = r2->min;
        newMax = (max1 < max2 ? max1 : max2);
        newMin = (min1 > min2 ? min1 : min2);
        if (newMin <= newMax) {
          return 1;
        }
      }
    }
    return 0;
}

variable_types: j int

variable_types:
newMax
unsigned long

variable_types:
newMin
unsigned long


RangeIsEmpty

decompiled_code:
bool __fastcall RangeIsEmpty(_QWORD *a1)
{
bool result; // al

result = 1;
if ( a1 )
result = *a1 < a1[1];
return result;
}

canonical_decompiled_code:
bool __fastcall func8(_QWORD *a1)
{
bool result; // al

result = 1;
if ( a1 )
result = *a1 < a1[1];
return result;
}

original_code:
_Bool RangeIsEmpty(Range *r) {
    _Bool isEmpty = 1;
    if(r && r->max >= r->min) {
        isEmpty = 0;
    }
    return (isEmpty);
}

canonical_original_code:
_Bool RangeIsEmpty(struct Range *r) {
    _Bool isEmpty = 1;
    if(r && r->max >= r->min) {
        isEmpty = 0;
    }
    return (isEmpty);
}


ScrubWriteSet

decompiled_code:
char __fastcall ScrubWriteSet(_QWORD *a1)
{
int v1; // eax
int v2; // er12
unsigned int v3; // ebx
_QWORD *v4; // rbp

v1 = al_size(*a1);
if ( v1 > 0 )
{
v2 = v1;
v3 = 0;
do
{
while ( 1 )
{
v4 = (_QWORD *)al_get(*a1, v3);
LOBYTE(v1) = RangeIsEmpty(v4);
if ( (_BYTE)v1 )
break;
if ( (int)++v3 >= v2 )
return v1;
}
al_removeAt(*a1, v3);
free(v4);
v1 = al_size(*a1);
v2 = v1;
}
while ( (int)v3 < v1 );
}
return v1;
}

canonical_decompiled_code:
char __fastcall func9(_QWORD *a1)
{
int v1; // eax
int v2; // er12
unsigned int v3; // ebx
_QWORD *v4; // rbp

v1 = al_size(*a1);
if ( v1 > 0 )
{
v2 = v1;
v3 = 0;
do
{
while ( 1 )
{
v4 = (_QWORD *)al_get(*a1, v3);
LOBYTE(v1) = func8(v4);
if ( (_BYTE)v1 )
break;
if ( (int)++v3 >= v2 )
return v1;
}
al_removeAt(*a1, v3);
free(v4);
v1 = al_size(*a1);
v2 = v1;
}
while ( (int)v3 < v1 );
}
return v1;
}

original_code:
void ScrubWriteSet(WriteSet *ws) {
    int size = al_size(ws->ranges);
    int cur = 0;
    while(cur < size) {
        Range *next = (Range *)al_get(ws->ranges, cur);
        if(RangeIsEmpty(next)) {
            al_removeAt(ws->ranges, cur);
            free(next);
            size = al_size(ws->ranges);
        } else {
            cur++;
        }
    }
}

canonical_original_code:
void ScrubWriteSet(struct WriteSet *ws) {
    int size = al_size(ws->ranges);
    int cur = 0;
    while(cur < size) {
        struct Range *next = (Range *)al_get(ws->ranges, cur);
        if(RangeIsEmpty(next)) {
            al_removeAt(ws->ranges, cur);
            free(next);
            size = al_size(ws->ranges);
        } else {
            cur++;
        }
    }
}

variable_types: size int

variable_types: cur int


RangeInWriteSet

decompiled_code:
__int64 __fastcall RangeInWriteSet(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er8
int v4; // er13
int v5; // ebx
unsigned __int64 v6; // rax
bool v7; // al
unsigned __int64 *v8; // rax

if ( !a2 )
return 0LL;
if ( *a2 < a2[1] )
return 0;
v4 = al_size(*a1);
if ( v4 <= 0 )
return 0;
v5 = 0;
do
{
v8 = (unsigned __int64 *)al_get(*a1, (unsigned int)v5);
if ( *a2 >= v8[1] )
{
v6 = *v8;
LOBYTE(v2) = a2[1] <= v6;
v7 = a2[1] > v6;
}
else
{
v7 = 1;
v2 = 0;
}
++v5;
}
while ( v4 > v5 && v7 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // er8
int v4; // er13
int v5; // ebx
unsigned __int64 v6; // rax
bool v7; // al
unsigned __int64 *v8; // rax

if ( !a2 )
return 0LL;
if ( *a2 < a2[1] )
return 0;
v4 = al_size(*a1);
if ( v4 <= 0 )
return 0;
v5 = 0;
do
{
v8 = (unsigned __int64 *)al_get(*a1, (unsigned int)v5);
if ( *a2 >= v8[1] )
{
v6 = *v8;
LOBYTE(v2) = a2[1] <= v6;
v7 = a2[1] > v6;
}
else
{
v7 = 1;
v2 = 0;
}
++v5;
}
while ( v4 > v5 && v7 );
return v2;
}

original_code:
_Bool RangeInWriteSet(WriteSet *ws, Range *r) {
  int i, sz;
    if((r == ((void *)0)) || (r->max < r->min)) {
        return (0);
    }
    _Bool inWS = 0;
    sz = al_size(ws->ranges);
    for (i = 0; i < sz && !inWS; i++) {
      Range *next = (Range *) al_get(ws->ranges, i);
        if( (r->max >= next->min) && (r->min <= next->max) ) {
            inWS = 1;
        }
    }
    return (inWS);
}

canonical_original_code:
_Bool RangeInWriteSet(struct WriteSet *ws, struct Range *r) {
  int i; int sz;
    if((r == ((void *)0)) || (r->max < r->min)) {
        return (0);
    }
    _Bool inWS = 0;
    sz = al_size(ws->ranges);
    for (i = 0; i < sz && !inWS; i++) {
      struct Range *next = (Range *) al_get(ws->ranges, i);
        if( (r->max >= next->min) && (r->min <= next->max) ) {
            inWS = 1;
        }
    }
    return (inWS);
}

variable_types: i int

variable_types: sz int


PrintWriteSet

decompiled_code:
int __fastcall PrintWriteSet(_QWORD *a1)
{
fPrintWriteSet(stdout, a1);
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func12(_QWORD *a1)
{
func11(stdout, a1);
return fputc(10, stdout);
}

original_code:
void PrintWriteSet(WriteSet *ws) {
    fPrintWriteSet(stdout, ws);
    fprintf(stdout, "\n");
}

canonical_original_code:
void PrintWriteSet(struct WriteSet *ws) {
    fPrintWriteSet(stdout, ws);
    fprintf(stdout, "\n");
}


WriteSetSubsetOfWriteSet

decompiled_code:
__int64 __fastcall WriteSetSubsetOfWriteSet(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
int v5; // er13
unsigned int v6; // er14
_QWORD *v7; // rax

LOBYTE(v2) = WriteSetIsEmpty(a1);
if ( (_BYTE)v2 )
return 1;
v3 = v2;
if ( WriteSetIsEmpty(a2) )
return v3;
v5 = al_size(*a1);
if ( v5 <= 0 )
return 1;
v6 = 0;
while ( 1 )
{
v7 = (_QWORD *)al_get(*a1, v6);
if ( !(unsigned __int8)RangeInWriteSet(a2, v7) )
break;
if ( v5 == ++v6 )
return 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, _QWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
int v5; // er13
unsigned int v6; // er14
_QWORD *v7; // rax

LOBYTE(v2) = func5(a1);
if ( (_BYTE)v2 )
return 1;
v3 = v2;
if ( func5(a2) )
return v3;
v5 = al_size(*a1);
if ( v5 <= 0 )
return 1;
v6 = 0;
while ( 1 )
{
v7 = (_QWORD *)al_get(*a1, v6);
if ( !(unsigned __int8)func10(a2, v7) )
break;
if ( v5 == ++v6 )
return 1;
}
return v3;
}

original_code:
_Bool WriteSetSubsetOfWriteSet(WriteSet *ws_sub, WriteSet *ws_super) {
  int i, sz;
  if (WriteSetIsEmpty(ws_sub)) {
    return 1;
  }
  if (WriteSetIsEmpty(ws_super)) {
    return 0;
  }
  sz = al_size(ws_sub->ranges);
  for (i = 0; i < sz; i++) {
    Range *r = (Range *) al_get(ws_sub->ranges, i);
    if (!RangeInWriteSet(ws_super, r)) {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
_Bool WriteSetSubsetOfWriteSet(struct WriteSet *ws_sub, struct WriteSet *ws_super) {
  int i; int sz;
  if (WriteSetIsEmpty(ws_sub)) {
    return 1;
  }
  if (WriteSetIsEmpty(ws_super)) {
    return 0;
  }
  sz = al_size(ws_sub->ranges);
  for (i = 0; i < sz; i++) {
    struct Range *r = (Range *) al_get(ws_sub->ranges, i);
    if (!RangeInWriteSet(ws_super, r)) {
      return 0;
    }
  }
  return 1;
}


alloc

decompiled_code:
void *__fastcall alloc(int a1)
{
void *v1; // r12

v1 = malloc(a1);
if ( !v1 )
fwrite("ALLOC: Out of memory\n", 1uLL, 0x15uLL, stderr);
return v1;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *v1; // r12

v1 = malloc(a1);
if ( !v1 )
fwrite("ALLOC: Out of memory\n", 1uLL, 0x15uLL, stderr);
return v1;
}

original_code:
void *alloc(int size) {
    void *new = malloc(size);
    if(new == ((void *)0)) {
        fprintf(stderr,"ALLOC: Out of memory\n");
    }
    return (new);
}

variable_types:
new
void *


dealloc

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

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

original_code:
void dealloc(void *ptr) {
    free(ptr);
}

canonical_original_code:
void dealloc(void *ptr) {
    free(ptr);
}

variable_types:
ptr
void *


resize

decompiled_code:
void *__fastcall resize(void *a1, int a2)
{
void *v2; // r12

v2 = realloc(a1, a2);
if ( !v2 )
fwrite("RESIZE: Out of memory\n", 1uLL, 0x16uLL, stderr);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, int a2)
{
void *v2; // r12

v2 = realloc(a1, a2);
if ( !v2 )
fwrite("RESIZE: Out of memory\n", 1uLL, 0x16uLL, stderr);
return v2;
}

original_code:
void *resize(void *address, int newsize) {
    void *mem;
    mem = realloc(address, newsize);
    if (mem == ((void *)0)) {
        fprintf(stderr,"RESIZE: Out of memory\n");
    }
    return (mem);
}

variable_types:
address
void *

variable_types: newsize int

variable_types:
mem
void *