decompiled_code:
__int64 __fastcall store_definite_bstr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
signed __int64 v5; // r13
_BYTE *v6; // rax
void *v7; // r12
_QWORD *v8; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v5 = cbor_value_uint(a2, a3);
v6 = malloc(v5);
v7 = v6;
if ( v6 )
{
*v6 = 0;
if ( read(a3, v6, v5) < v5 )
{
free(v7);
result = 3LL;
}
else
{
v8 = malloc(0x20uLL);
if ( v8 )
{
*(_DWORD *)v8 = 64;
v8[1] = 0LL;
v8[2] = v5;
v8[3] = v7;
*(_QWORD *)(a1 + 8) = v8;
result = 0LL;
}
else
{
free(v7);
result = 1LL;
}
}
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
signed __int64 v5; // r13
_BYTE *v6; // rax
void *v7; // r12
_QWORD *v8; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v5 = cbor_value_uint(a2, a3);
v6 = malloc(v5);
v7 = v6;
if ( v6 )
{
*v6 = 0;
if ( read(a3, v6, v5) < v5 )
{
free(v7);
result = 3LL;
}
else
{
v8 = malloc(0x20uLL);
if ( v8 )
{
*(_DWORD *)v8 = 64;
v8[1] = 0LL;
v8[2] = v5;
v8[3] = v7;
*(_QWORD *)(a1 + 8) = v8;
result = 0LL;
}
else
{
free(v7);
result = 1LL;
}
}
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static int store_definite_bstr( struct cbor_t*storage,const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  size_t length=cbor_value_uint(additional,stream);
  uint8_t*const string=malloc(length);
  if(string==((void *)0))return 1;
  *string=0;
  if(read(stream,string,length)<(ssize_t)length)
  {
   free(string);
   return 3;
  }
  {
   struct cbor_bstr_t b= {
    .base= {
     .major=cbor_major_bstr,
     .next=((void *)0),
    },
    .length=length,
    .string=string,
   } , *fresh=malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(string);
    return 1;
   }
   memcpy(fresh,&b,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

canonical_original_code:
static int store_definite_bstr(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  unsigned long length = cbor_value_uint(additional,stream);
  unsigned char *string = malloc(length);
  if(string==((void *)0))return 1;
  *string=0;
  if(read(stream,string,length)<(long)length)
  {
   free(string);
   return 3;
  }
  {
   struct cbor_bstr_t b = {
    .base= {
     .major=cbor_major_bstr,
     .next=((void *)0),
    },
    .length=length,
    .string=string,
   }; struct cbor_bstr_t *fresh = malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(string);
    return 1;
   }
   memcpy(fresh,&b,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

variable_types:
additional
unsigned char

variable_types: stream int

variable_types:
string
unsigned char *

variable_types: struct cbor_bstr_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long length; unsigned char *string; } *

user_defined_types: struct cbor_bstr_t { struct cbor_t base; unsigned long length; unsigned char *string; }


repo: upwhere/ccbor

decompiled_code:
__int64 __fastcall store_definite_tstr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
signed __int64 v5; // r12
void *v6; // rax
void *v7; // r13
signed __int64 v8; // r12
_QWORD *v9; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( *(_QWORD *)(a1 + 8) )
return result;
v5 = cbor_value_uint(a2, a3);
v6 = calloc(v5 + 1, 1uLL);
v7 = v6;
if ( v6 )
{
if ( read(a3, v6, v5) < v5 )
{
free(v7);
return 3LL;
}
v8 = v5 + 4;
v9 = malloc(0x20uLL);
if ( v9 )
{
*(_DWORD *)v9 = 96;
v9[1] = 0LL;
v9[2] = v8;
v9[3] = v7;
*(_QWORD *)(a1 + 8) = v9;
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
signed __int64 v5; // r12
void *v6; // rax
void *v7; // r13
signed __int64 v8; // r12
_QWORD *v9; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( *(_QWORD *)(a1 + 8) )
return result;
v5 = cbor_value_uint(a2, a3);
v6 = calloc(v5 + 1, 1uLL);
v7 = v6;
if ( v6 )
{
if ( read(a3, v6, v5) < v5 )
{
free(v7);
return 3LL;
}
v8 = v5 + 4;
v9 = malloc(0x20uLL);
if ( v9 )
{
*(_DWORD *)v9 = 96;
v9[1] = 0LL;
v9[2] = v8;
v9[3] = v7;
*(_QWORD *)(a1 + 8) = v9;
return 0LL;
}
}
return 1LL;
}

original_code:
static int store_definite_tstr(struct cbor_t*storage,const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  size_t length=cbor_value_uint(additional,stream);
  uint8_t*bytestring=calloc(length+1,sizeof*bytestring);
  if(bytestring==((void *)0))return 1;
  if(read(stream,bytestring,length)<(ssize_t)length)
  {
   free(bytestring);
   return 3;
  }
  {
   struct cbor_tstr_t t= {
    .base= {
     .major=cbor_major_tstr,
     .next=((void *)0),
    },
    .length=length+sizeof'\0',
    .string=(char*)bytestring,
   },*fresh=malloc(sizeof*fresh);
   if(fresh==((void *)0))return 1;
   memcpy(fresh,&t,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

canonical_original_code:
static int store_definite_tstr(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  unsigned long length = cbor_value_uint(additional,stream);
  unsigned char *bytestring = calloc(length+1,sizeof*bytestring);
  if(bytestring==((void *)0))return 1;
  if(read(stream,bytestring,length)<(long)length)
  {
   free(bytestring);
   return 3;
  }
  {
   struct cbor_tstr_t t = {
    .base= {
     .major=cbor_major_tstr,
     .next=((void *)0),
    },
    .length=length+sizeof'\0',
    .string=(char*)bytestring,
   }; struct cbor_tstr_t *fresh = malloc(sizeof*fresh);
   if(fresh==((void *)0))return 1;
   memcpy(fresh,&t,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

variable_types: struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } *

variable_types:
length
unsigned long

variable_types:
bytestring
unsigned char *

variable_types: struct cbor_tstr_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long length; char *string; } *

return_type: int

user_defined_types: struct cbor_tstr_t { struct cbor_t base; unsigned long length; char *string; }

user_defined_types: struct cbor_t { enum cbor_major_t major; struct cbor_t *next; }


decompiled_code:
__int64 __fastcall cbor_store_bstr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
int *v5; // rbx
size_t v6; // rbp
unsigned __int8 v7; // al
__int64 result; // rax
char *v9; // rbx
_QWORD *v10; // r12
void *v11; // r15
size_t v12; // r14
void *v13; // rdi
_QWORD *v14; // rax
char *ptr; // [rsp+0h] [rbp-60h]
unsigned __int8 buf; // [rsp+17h] [rbp-49h] BYREF
int v17; // [rsp+18h] [rbp-48h] BYREF
_QWORD *v18; // [rsp+20h] [rbp-40h]

if ( !a1 )
return 2LL;
if ( *(_QWORD *)(a1 + 8) )
return 2LL;
if ( a2 != 31 )
return store_definite_bstr(a1, a2, a3);
v17 = 255;
v5 = &v17;
v6 = 0LL;
v18 = 0LL;
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of() != 2 )
return 3LL;
v7 = cbor_additional_of(buf);
result = store_definite_bstr((__int64)v5, v7, a3);
if ( (_DWORD)result )
return result;
v5 = (int *)*((_QWORD *)v5 + 1);
if ( !v5 )
return 2LL;
v6 += *((_QWORD *)v5 + 2);
}
ptr = (char *)malloc(v6);
v9 = ptr;
if ( !ptr )
return 1LL;
v10 = v18;
if ( v18 )
{
do
{
v11 = (void *)v10[3];
v12 = v10[2];
v13 = v9;
v9 += v12;
memcpy(v13, v11, v12);
free(v11);
v10 = (_QWORD *)v10[1];
}
while ( v10 );
v10 = v18;
}
recursive_naive_cbor_free(v10);
v14 = malloc(0x20uLL);
if ( v14 )
{
*(_DWORD *)v14 = 64;
v14[1] = 0LL;
v14[2] = v6;
v14[3] = ptr;
*(_QWORD *)(a1 + 8) = v14;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
int *v5; // rbx
size_t v6; // rbp
unsigned __int8 v7; // al
__int64 result; // rax
char *v9; // rbx
_QWORD *v10; // r12
void *v11; // r15
size_t v12; // r14
void *v13; // rdi
_QWORD *v14; // rax
char *ptr; // [rsp+0h] [rbp-60h]
unsigned __int8 buf; // [rsp+17h] [rbp-49h] BYREF
int v17; // [rsp+18h] [rbp-48h] BYREF
_QWORD *v18; // [rsp+20h] [rbp-40h]

if ( !a1 )
return 2LL;
if ( *(_QWORD *)(a1 + 8) )
return 2LL;
if ( a2 != 31 )
return func0(a1, a2, a3);
v17 = 255;
v5 = &v17;
v6 = 0LL;
v18 = 0LL;
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of() != 2 )
return 3LL;
v7 = cbor_additional_of(buf);
result = func0((__int64)v5, v7, a3);
if ( (_DWORD)result )
return result;
v5 = (int *)*((_QWORD *)v5 + 1);
if ( !v5 )
return 2LL;
v6 += *((_QWORD *)v5 + 2);
}
ptr = (char *)malloc(v6);
v9 = ptr;
if ( !ptr )
return 1LL;
v10 = v18;
if ( v18 )
{
do
{
v11 = (void *)v10[3];
v12 = v10[2];
v13 = v9;
v9 += v12;
memcpy(v13, v11, v12);
free(v11);
v10 = (_QWORD *)v10[1];
}
while ( v10 );
v10 = v18;
}
recursive_naive_cbor_free(v10);
v14 = malloc(0x20uLL);
if ( v14 )
{
*(_DWORD *)v14 = 64;
v14[1] = 0LL;
v14[2] = v6;
v14[3] = ptr;
*(_QWORD *)(a1 + 8) = v14;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
return result;
}

original_code: int cbor_store_bstr(struct cbor_t*storage,const uint8_t additional,const int stream) { if(storage==((void *)0) || storage->next!=((void *)0))return 2; if(additional!=cbor_additional_indefinite) { return store_definite_bstr(storage,additional,stream); } else { size_t total_length=0; uint8_t *str,*strindex; struct cbor_t indefinite={.major=0xFF,.next=((void *)0),},*next=&indefinite; while(1) { int store_attempt_ret; uint8_t item=0; if(read(stream,&item,sizeof item) < (ssize_t) sizeof item)return 3; if(item==0xff)break; if(cbor_major_of(item)!=(cbor_major_bstr>>5))return 3; if((store_attempt_ret=store_definite_bstr(next,cbor_additional_of(item),stream))!=0)return store_attempt_ret; if(next->next==((void *)0))return 2; next=next->next; total_length+=((struct cbor_bstr_t*)next)->length; } if((strindex=str=malloc(total_length+ (0?sizeof'\0' :0) ) ) ==((void *)0))return 1; next=&indefinite; while((next=next->next)!=((void *)0)) { uint8_t const*const stringpart = ((struct cbor_bstr_t*)next)->string; const size_t partlength = ((struct cbor_bstr_t*)next)->length; memcpy(strindex,stringpart,partlength); free((uint8_t*)stringpart); strindex+=partlength; } if(0)*strindex='\0'; recursive_naive_cbor_free(indefinite.next); { struct cbor_bstr_t s={ .base={ .major=cbor_major_bstr, .next=((void *)0), }, .length=total_length, .string=str, },*fresh=malloc(sizeof*fresh); if(fresh==((void *)0)) { free(str); return 1; } memcpy(fresh,&s,sizeof*fresh); storage->next=&fresh->base; } return 0; } }

canonical_original_code: int cbor_store_bstr(struct cbor_t *storage, unsigned char additional, int stream) { if(storage==((void *)0) || storage->next!=((void *)0))return 2; if(additional!=cbor_additional_indefinite) { return store_definite_bstr(storage,additional,stream); } else { unsigned long total_length = 0; unsigned char *str; unsigned char *strindex; struct cbor_t indefinite = {.major=0xFF,.next=((void *)0),}; struct cbor_t *next = &indefinite; while(1) { int store_attempt_ret; unsigned char item = 0; if(read(stream,&item,sizeof item) < (long) sizeof item)return 3; if(item==0xff)break; if(cbor_major_of(item)!=(cbor_major_bstr>>5))return 3; if((store_attempt_ret=store_definite_bstr(next,cbor_additional_of(item),stream))!=0)return store_attempt_ret; if(next->next==((void *)0))return 2; next=next->next; total_length+=((struct cbor_bstr_t *)next)->length; } if((strindex=str=malloc(total_length+ (0?sizeof'\0' :0) ) ) ==((void *)0))return 1; next=&indefinite; while((next=next->next)!=((void *)0)) { unsigned char *stringpart = ((struct cbor_bstr_t*)next)->string; unsigned long partlength = ((struct cbor_bstr_t*)next)->length; memcpy(strindex,stringpart,partlength); free((unsigned char *)stringpart); strindex+=partlength; } if(0)*strindex='\0'; recursive_naive_cbor_free(indefinite.next); { struct cbor_bstr_t s = { .base={ .major=cbor_major_bstr, .next=((void *)0), }, .length=total_length, .string=str, }; struct cbor_bstr_t *fresh = malloc(sizeof*fresh); if(fresh==((void *)0)) { free(str); return 1; } memcpy(fresh,&s,sizeof*fresh); storage->next=&fresh->base; } return 0; } }

variable_types:
str
unsigned char *

variable_types:
strindex
unsigned char *

variable_types:
item
unsigned char

variable_types:
stringpart
unsigned char *

variable_types:
partlength
unsigned long

variable_types: struct cbor_bstr_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long length; unsigned char *string; }


decompiled_code:
__int64 __fastcall cbor_store_tstr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
int *v5; // rbx
__int64 v6; // rbp
unsigned __int8 v7; // al
__int64 result; // rax
_BYTE *v9; // rbx
_QWORD *v10; // r12
void *v11; // r15
void *v12; // rdi
size_t v13; // rdx
_QWORD *v14; // rax
_BYTE *ptr; // [rsp+0h] [rbp-60h]
unsigned __int8 buf; // [rsp+17h] [rbp-49h] BYREF
int v17; // [rsp+18h] [rbp-48h] BYREF
_QWORD *v18; // [rsp+20h] [rbp-40h]

if ( !a1 )
return 2LL;
if ( *(_QWORD *)(a1 + 8) )
return 2LL;
if ( a2 != 31 )
return store_definite_tstr(a1, a2, a3);
v17 = 255;
v5 = &v17;
v6 = 0LL;
v18 = 0LL;
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of() != 3 )
return 3LL;
v7 = cbor_additional_of(buf);
result = store_definite_bstr((__int64)v5, v7, a3);
if ( (_DWORD)result )
return result;
v5 = (int *)*((_QWORD *)v5 + 1);
if ( !v5 )
return 2LL;
v6 += *((_QWORD *)v5 + 2);
}
ptr = malloc(v6 + 4);
v9 = ptr;
if ( !ptr )
return 1LL;
v10 = v18;
if ( v18 )
{
do
{
v11 = (void *)v10[3];
v12 = v9;
v13 = v10[2];
v9 += v13;
memcpy(v12, v11, v13);
free(v11);
v10 = (_QWORD *)v10[1];
}
while ( v10 );
v10 = v18;
}
else
{
v9 = ptr;
}
*v9 = 0;
recursive_naive_cbor_free(v10);
v14 = malloc(0x20uLL);
if ( v14 )
{
*(_DWORD *)v14 = 96;
v14[1] = 0LL;
v14[2] = v6;
v14[3] = ptr;
*(_QWORD *)(a1 + 8) = v14;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
int *v5; // rbx
__int64 v6; // rbp
unsigned __int8 v7; // al
__int64 result; // rax
_BYTE *v9; // rbx
_QWORD *v10; // r12
void *v11; // r15
void *v12; // rdi
size_t v13; // rdx
_QWORD *v14; // rax
_BYTE *ptr; // [rsp+0h] [rbp-60h]
unsigned __int8 buf; // [rsp+17h] [rbp-49h] BYREF
int v17; // [rsp+18h] [rbp-48h] BYREF
_QWORD *v18; // [rsp+20h] [rbp-40h]

if ( !a1 )
return 2LL;
if ( *(_QWORD *)(a1 + 8) )
return 2LL;
if ( a2 != 31 )
return func1(a1, a2, a3);
v17 = 255;
v5 = &v17;
v6 = 0LL;
v18 = 0LL;
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of() != 3 )
return 3LL;
v7 = cbor_additional_of(buf);
result = func0((__int64)v5, v7, a3);
if ( (_DWORD)result )
return result;
v5 = (int *)*((_QWORD *)v5 + 1);
if ( !v5 )
return 2LL;
v6 += *((_QWORD *)v5 + 2);
}
ptr = malloc(v6 + 4);
v9 = ptr;
if ( !ptr )
return 1LL;
v10 = v18;
if ( v18 )
{
do
{
v11 = (void *)v10[3];
v12 = v9;
v13 = v10[2];
v9 += v13;
memcpy(v12, v11, v13);
free(v11);
v10 = (_QWORD *)v10[1];
}
while ( v10 );
v10 = v18;
}
else
{
v9 = ptr;
}
*v9 = 0;
recursive_naive_cbor_free(v10);
v14 = malloc(0x20uLL);
if ( v14 )
{
*(_DWORD *)v14 = 96;
v14[1] = 0LL;
v14[2] = v6;
v14[3] = ptr;
*(_QWORD *)(a1 + 8) = v14;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
return result;
}

original_code: int cbor_store_tstr(struct cbor_t*storage,const uint8_t additional,const int stream) { if(storage==((void *)0) || storage->next!=((void *)0))return 2; if(additional!=cbor_additional_indefinite) { return store_definite_tstr(storage,additional,stream); } else { size_t total_length=0; char *str,*strindex; struct cbor_t indefinite={.major=0xFF,.next=((void *)0),},*next=&indefinite; while(1) { int store_attempt_ret; uint8_t item=0; if(read(stream,&item,sizeof item) < (ssize_t) sizeof item)return 3; if(item==0xff)break; if(cbor_major_of(item)!=(cbor_major_tstr>>5))return 3; if((store_attempt_ret=store_definite_bstr(next,cbor_additional_of(item),stream))!=0)return store_attempt_ret; if(next->next==((void *)0))return 2; next=next->next; total_length+=((struct cbor_bstr_t*)next)->length; } if((strindex=str=malloc(total_length+ (1?sizeof'\0' :0) ) ) ==((void *)0))return 1; next=&indefinite; while((next=next->next)!=((void *)0)) { char const*const stringpart = ((struct cbor_tstr_t*)next)->string; const size_t partlength = ((struct cbor_tstr_t*)next)->length; memcpy(strindex,stringpart,partlength); free((char*)stringpart); strindex+=partlength; } if(1)*strindex='\0'; recursive_naive_cbor_free(indefinite.next); { struct cbor_tstr_t s={ .base={ .major=cbor_major_tstr, .next=((void *)0), }, .length=total_length, .string=str, },*fresh=malloc(sizeof*fresh); if(fresh==((void *)0)) { free(str); return 1; } memcpy(fresh,&s,sizeof*fresh); storage->next=&fresh->base; } return 0; } }

canonical_original_code: int cbor_store_tstr(struct cbor_t *storage, unsigned char additional, int stream) { if(storage==((void *)0) || storage->next!=((void *)0))return 2; if(additional!=cbor_additional_indefinite) { return store_definite_tstr(storage,additional,stream); } else { unsigned long total_length = 0; char *str; char *strindex; struct cbor_t indefinite = {.major=0xFF,.next=((void *)0),}; struct cbor_t *next = &indefinite; while(1) { int store_attempt_ret; unsigned char item = 0; if(read(stream,&item,sizeof item) < (long) sizeof item)return 3; if(item==0xff)break; if(cbor_major_of(item)!=(cbor_major_tstr>>5))return 3; if((store_attempt_ret=store_definite_bstr(next,cbor_additional_of(item),stream))!=0)return store_attempt_ret; if(next->next==((void *)0))return 2; next=next->next; total_length+=((struct cbor_bstr_t *)next)->length; } if((strindex=str=malloc(total_length+ (1?sizeof'\0' :0) ) ) ==((void *)0))return 1; next=&indefinite; while((next=next->next)!=((void *)0)) { char *stringpart = ((struct cbor_tstr_t*)next)->string; unsigned long partlength = ((struct cbor_tstr_t*)next)->length; memcpy(strindex,stringpart,partlength); free((char *)stringpart); strindex+=partlength; } if(1)*strindex='\0'; recursive_naive_cbor_free(indefinite.next); { struct cbor_tstr_t s = { .base={ .major=cbor_major_tstr, .next=((void *)0), }, .length=total_length, .string=str, }; struct cbor_tstr_t *fresh = malloc(sizeof*fresh); if(fresh==((void *)0)) { free(str); return 1; } memcpy(fresh,&s,sizeof*fresh); storage->next=&fresh->base; } return 0; } }

variable_types:
str
char *

variable_types:
strindex
char *

variable_types:
stringpart
char *

variable_types: struct cbor_tstr_t { struct cbor_t { enum cbor_major_t { cbor_major_uint=expr, cbor_major_nint=expr, cbor_major_bstr=expr, cbor_major_tstr=expr, cbor_major_arr=expr, cbor_major_map=expr, cbor_major_tag=expr, cbor_major_flt=expr } major; struct cbor_t *next; } base; unsigned long length; char *string; }


repo: urbo-escom/c-ip-subnetting

decompiled_code:
__int64 __fastcall Subnet_subnet_id(__int64 a1, char a2, __int64 a3)
{
return (a3 << ((unsigned __int8)IP_host_bits() - a2)) + a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, __int64 a3)
{
return (a3 << ((unsigned __int8)IP_host_bits() - a2)) + a1;
}

original_code:
extern IP_T Subnet_subnet_id(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 int host_bits = IP_host_bits(ip);
 return
  ip +
  (subnet_number << (host_bits - subnet_bits));
}

canonical_original_code:
extern unsigned long Subnet_subnet_id(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 int host_bits = IP_host_bits(ip);
 return
  ip +
  (subnet_number << (host_bits - subnet_bits));
}

variable_types:
ip
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall Subnet_broadcast(__int64 a1, char a2, __int64 a3)
{
return a1 + ((a3 + 1) << ((unsigned __int8)IP_host_bits() - a2)) - 1;
}

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

original_code:
extern IP_T Subnet_broadcast(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 int host_bits = IP_host_bits(ip);
 return ip +
  ((subnet_number + 1L) << (host_bits - subnet_bits)) - 1L;
}

canonical_original_code:
extern unsigned long Subnet_broadcast(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 int host_bits = IP_host_bits(ip);
 return ip +
  ((subnet_number + 1L) << (host_bits - subnet_bits)) - 1L;
}


decompiled_code:
__int64 __fastcall Subnet_host_start(__int64 a1, char a2, __int64 a3)
{
return Subnet_subnet_id(a1, a2, a3) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2, __int64 a3)
{
return func0(a1, a2, a3) + 1;
}

original_code:
extern IP_T Subnet_host_start(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 return Subnet_subnet_id(ip, subnet_bits,
                     subnet_number) + 1L;
}

canonical_original_code:
extern unsigned long Subnet_host_start(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 return Subnet_subnet_id(ip, subnet_bits,
                     subnet_number) + 1L;
}


decompiled_code:
__int64 __fastcall Subnet_host_end(__int64 a1, char a2, __int64 a3)
{
return Subnet_broadcast(a1, a2, a3) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2, __int64 a3)
{
return func1(a1, a2, a3) - 1;
}

original_code:
extern IP_T Subnet_host_end(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 return Subnet_broadcast(ip, subnet_bits,
                     subnet_number) - 1L;
}

canonical_original_code:
extern unsigned long Subnet_host_end(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 return Subnet_broadcast(ip, subnet_bits,
                     subnet_number) - 1L;
}


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

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

original_code:
extern IP_T Subnet_mask(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 int host_bits = IP_host_bits(ip);
 return
  (-1L) << (host_bits - subnet_bits);
}

canonical_original_code:
extern unsigned long Subnet_mask(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 int host_bits = IP_host_bits(ip);
 return
  (-1L) << (host_bits - subnet_bits);
}


decompiled_code:
_BOOL8 __fastcall Subnet_is_used(__int64 a1, char a2, __int64 a3)
{
__int64 v4; // r8
_BOOL8 result; // rax
__int64 v6; // r12

v4 = Subnet_subnet_id(a1, a2, a3);
result = 0LL;
if ( v4 != a1 )
{
v6 = Subnet_broadcast(a1, a2, a3);
result = v6 != IP_broadcast(a1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, char a2, __int64 a3)
{
__int64 v4; // r8
_BOOL8 result; // rax
__int64 v6; // r12

v4 = func0(a1, a2, a3);
result = 0LL;
if ( v4 != a1 )
{
v6 = func1(a1, a2, a3);
result = v6 != IP_broadcast(a1);
}
return result;
}

original_code:
extern int Subnet_is_used(
  IP_T ip, int subnet_bits, Subnet subnet_number) {
 return Subnet_subnet_id(ip, subnet_bits, subnet_number) != ip &&
        Subnet_broadcast(ip, subnet_bits, subnet_number) !=
        IP_broadcast(ip);
}

canonical_original_code:
extern int Subnet_is_used(unsigned long ip, int subnet_bits, unsigned long subnet_number) {
 return Subnet_subnet_id(ip, subnet_bits, subnet_number) != ip &&
        Subnet_broadcast(ip, subnet_bits, subnet_number) !=
        IP_broadcast(ip);
}


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

v2 = IP_subnet_bits_by_total_hosts();
if ( v2 != -1 )
return (char *)SubnetCalcUtil_get_info(a1, v2);
sprintf(info, "error Too many hosts (%lu) for %lx", a2, a1);
return info;
}

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

v2 = IP_subnet_bits_by_total_hosts();
if ( v2 != -1 )
return (char *)SubnetCalcUtil_get_info(a1, v2);
sprintf(info, "error Too many hosts (%lu) for %lx", a2, a1);
return info;
}

original_code:
extern char* SubnetCalc_get_info_by_ip_and_hosts(
  IP_T ip, host_size_t hosts) {
 int subnet_bits = IP_subnet_bits_by_total_hosts(ip, hosts);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many hosts (%lu) for %lx", hosts, ip); return info; } } while(0);
 return SubnetCalcUtil_get_info(ip, subnet_bits);
}

canonical_original_code:
extern char *SubnetCalc_get_info_by_ip_and_hosts(unsigned long ip, unsigned long hosts) {
 int subnet_bits = IP_subnet_bits_by_total_hosts(ip, hosts);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many hosts (%lu) for %lx", hosts, ip); return info; } } while(0);
 return SubnetCalcUtil_get_info(ip, subnet_bits);
}

variable_types:
hosts
unsigned long

return_type: char *


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

v2 = IP_subnet_bits_by_hosts_per_subnet();
if ( v2 != -1 )
return (char *)SubnetCalcUtil_get_info(a1, v2);
sprintf(info, "error Too many hosts per subnet (%lu) for %lx", a2, a1);
return info;
}

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

v2 = IP_subnet_bits_by_hosts_per_subnet();
if ( v2 != -1 )
return (char *)SubnetCalcUtil_get_info(a1, v2);
sprintf(info, "error Too many hosts per subnet (%lu) for %lx", a2, a1);
return info;
}

original_code:
extern char* SubnetCalc_get_info_by_ip_and_hosts_per_subnet(
  IP_T ip, host_size_t hosts_per_subnet) {
 int subnet_bits =
  IP_subnet_bits_by_hosts_per_subnet(ip, hosts_per_subnet);
 do{ if(subnet_bits == -1) { sprintf(info, "error " "Too many hosts per subnet (%lu) for %lx", hosts_per_subnet, ip); return info; } } while(0);
 return SubnetCalcUtil_get_info(ip, subnet_bits);
}

canonical_original_code:
extern char *SubnetCalc_get_info_by_ip_and_hosts_per_subnet(unsigned long ip, unsigned long hosts_per_subnet) {
 int subnet_bits = IP_subnet_bits_by_hosts_per_subnet(ip, hosts_per_subnet);
 do{ if(subnet_bits == -1) { sprintf(info, "error " "Too many hosts per subnet (%lu) for %lx", hosts_per_subnet, ip); return info; } } while(0);
 return SubnetCalcUtil_get_info(ip, subnet_bits);
}


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

v2 = IP_subnet_bits_by_subnets();
if ( v2 != -1 )
return (char *)SubnetCalcUtil_get_info(a1, v2);
sprintf(info, "error Too many subnets (%lu) for %lx", a2, a1);
return info;
}

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

v2 = IP_subnet_bits_by_subnets();
if ( v2 != -1 )
return (char *)SubnetCalcUtil_get_info(a1, v2);
sprintf(info, "error Too many subnets (%lu) for %lx", a2, a1);
return info;
}

original_code:
extern char* SubnetCalc_get_info_by_ip_and_subnets(
  IP_T ip, subnet_size_t subnets) {
 int subnet_bits = IP_subnet_bits_by_subnets(ip, subnets);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many subnets (%lu) for %lx", subnets, ip); return info; } } while(0);
 return SubnetCalcUtil_get_info(ip, subnet_bits);
}

canonical_original_code:
extern char *SubnetCalc_get_info_by_ip_and_subnets(unsigned long ip, unsigned long subnets) {
 int subnet_bits = IP_subnet_bits_by_subnets(ip, subnets);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many subnets (%lu) for %lx", subnets, ip); return info; } } while(0);
 return SubnetCalcUtil_get_info(ip, subnet_bits);
}

variable_types:
subnets
unsigned long


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

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

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

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

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

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

variable_types: timer long

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


decompiled_code:
__int64 __fastcall IP_host_bits(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx
char *v2; // rax
__int64 result; // rax

v1 = a1 >> 24;
v2 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Getting host bits %lx -> %lx\n", v2, "src/subnetting/ip.c", 7LL, a1, a1 >> 24);
result = 24LL;
if ( a1 >> 24 > 0x7F )
{
result = 16LL;
if ( v1 - 128 > 0x3F )
{
result = 8LL;
if ( v1 - 192 > 0x1F )
{
IP_set_strerror("Unkown class %lx", a1);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx
char *v2; // rax
__int64 result; // rax

v1 = a1 >> 24;
v2 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Getting host bits %lx -> %lx\n", v2, "src/subnetting/ip.c", 7LL, a1, a1 >> 24);
result = 24LL;
if ( a1 >> 24 > 0x7F )
{
result = 16LL;
if ( v1 - 128 > 0x3F )
{
result = 8LL;
if ( v1 - 192 > 0x1F )
{
IP_set_strerror("Unkown class %lx", a1);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
extern int IP_host_bits(IP_T ip) {
 IP_T prefix = ip >> 24;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Getting host bits %lx -> %lx" "\n", get_time(), "src/subnetting/ip.c", 7, ip, prefix);
 if ( 0UL <= prefix && prefix < 128UL)
  return 24;
 if (128UL <= prefix && prefix < 192UL)
  return 16;
 if (192UL <= prefix && prefix < 224UL)
  return 8;
 IP_set_strerror("Unkown class %lx", ip);
 return -1;
}

canonical_original_code:
extern int IP_host_bits(unsigned long ip) {
 unsigned long prefix = ip >> 24;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Getting host bits %lx -> %lx" "\n", get_time(), "src/subnetting/ip.c", 7, ip, prefix);
 if ( 0UL <= prefix && prefix < 128UL)
  return 24;
 if (128UL <= prefix && prefix < 192UL)
  return 16;
 if (192UL <= prefix && prefix < 224UL)
  return 8;
 IP_set_strerror("Unkown class %lx", ip);
 return -1;
}

variable_types:
prefix
unsigned long


decompiled_code:
__int64 __fastcall IP_class(unsigned __int64 a1)
{
int v1; // eax
unsigned int v2; // er8
__int64 v3; // rax

v1 = IP_host_bits(a1);
v2 = -1;
v3 = (unsigned int)(v1 - 8);
if ( (unsigned int)v3 <= 0x10 )
v2 = (unsigned __int8)CSWTCH_7[v3];
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
int v1; // eax
unsigned int v2; // er8
__int64 v3; // rax

v1 = func1(a1);
v2 = -1;
v3 = (unsigned int)(v1 - 8);
if ( (unsigned int)v3 <= 0x10 )
v2 = (unsigned __int8)CSWTCH_7[v3];
return v2;
}

original_code:
extern char IP_class(IP_T ip) {
 switch(IP_host_bits(ip)) {
  case 24: return 'A';
  case 16: return 'B';
  case 8: return 'C';
  default: return -1;
 }
}

canonical_original_code:
extern char IP_class(unsigned long ip) {
 switch(IP_host_bits(ip)) {
  case 24: return 'A';
  case 16: return 'B';
  case 8: return 'C';
  default: return -1;
 }
}

return_type: char


decompiled_code:
__int64 __fastcall IP_mask(unsigned __int64 a1)
{
int v1; // ebx
__int64 v2; // r12
char *v3; // rax

v1 = IP_host_bits(a1);
v2 = -1LL << v1;
v3 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) %lx-mask-%lx\n", v3, "src/subnetting/ip.c", 30LL, a1, -1LL << v1);
if ( v1 == -1 )
v2 = 0LL;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1)
{
int v1; // ebx
__int64 v2; // r12
char *v3; // rax

v1 = func1(a1);
v2 = -1LL << v1;
v3 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) %lx-mask-%lx\n", v3, "src/subnetting/ip.c", 30LL, a1, -1LL << v1);
if ( v1 == -1 )
v2 = 0LL;
return v2;
}

original_code:
extern IP_T IP_mask(IP_T ip) {
 int host_bits = IP_host_bits(ip);
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "%lx-mask-%lx" "\n", get_time(), "src/subnetting/ip.c", 30, ip, (-1L) << (host_bits));
 return host_bits == -1? 0UL:(-1L) << (host_bits);
}

canonical_original_code:
extern unsigned long IP_mask(unsigned long ip) {
 int host_bits = IP_host_bits(ip);
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "%lx-mask-%lx" "\n", get_time(), "src/subnetting/ip.c", 30, ip, (-1L) << (host_bits));
 return host_bits == -1? 0UL:(-1L) << (host_bits);
}


decompiled_code:
__int64 __fastcall IP_broadcast(unsigned __int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = IP_host_bits(a1);
result = -1LL;
if ( v1 != -1 )
result = (1 << v1) + (a1 & IP_mask(a1)) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = func1(a1);
result = -1LL;
if ( v1 != -1 )
result = (1 << v1) + (a1 & func3(a1)) - 1;
return result;
}

original_code:
extern IP_T IP_broadcast(IP_T ip) {
 int host_bits = IP_host_bits(ip);
 return host_bits == -1? -1:(ip & IP_mask(ip)) + (1 << host_bits) - 1;
}

canonical_original_code:
extern unsigned long IP_broadcast(unsigned long ip) {
 int host_bits = IP_host_bits(ip);
 return host_bits == -1? -1:(ip & IP_mask(ip)) + (1 << host_bits) - 1;
}


decompiled_code:
_BOOL8 __fastcall IP_is_valid_id(unsigned __int64 a1)
{
return (a1 & IP_mask(a1)) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int64 a1)
{
return (a1 & func3(a1)) == a1;
}

original_code:
extern int IP_is_valid_id(IP_T ip) {
 return ip == (ip & IP_mask(ip));
}

canonical_original_code:
extern int IP_is_valid_id(unsigned long ip) {
 return ip == (ip & IP_mask(ip));
}


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


decompiled_code:
char *__fastcall Socket_new(const char *a1, const char *a2)
{
void *v2; // r12
char *v4; // rax
char *v5; // rax
const char *v6; // r12
char *v7; // rax
_QWORD *v8; // rdi
char *v9; // rax
char *v10; // rax
char *v12; // r12
const char *v13; // rbp
int *v14; // rax
int *v15; // rbx
char *v16; // rax
int v17; // edi
char *v18; // rbx
char *v19; // rax
char *v20; // rbx
int v21; // edi
char *v22; // rax
char *v23; // [rsp+8h] [rbp-20h] BYREF

v2 = 0LL;
v4 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Creating new socket\n", v4, "src/network/bsd-win-sock-new.c", 10LL);
if ( (int)Socket_startup() < 0 )
return (char *)v2;
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Mallocing Socket_T\n", v5, "src/network/bsd-win-sock-new.c", 14LL);
v23 = (char *)malloc(0x78uLL);
v2 = v23;
if ( !v23 )
{
v20 = "None";
Socket_set_errno(4294967293LL);
v21 = *_errno_location();
if ( v21 )
v20 = strerror(v21);
v22 = get_time();
fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) Malloc failed\n", v22, "src/network/bsd-win-sock-new.c", 19LL, v20);
return (char *)v2;
}
v6 = "ANY";
if ( a1 )
v6 = a1;
v7 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Initializing Socket_T: %s:%s\n",
v7,
"src/network/bsd-win-sock-new.c",
23LL,
v6,
a2);
v8 = v23;
*(_QWORD *)v23 = -1LL;
v8[7] = 0LL;
*((_BYTE *)v8 + 64) = 0;
*((_BYTE *)v8 + 84) = 0;
v8[13] = a1;
v8[14] = a2;
Socket_set_hints();
v9 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Getting addrinfo\n", v9, "src/network/bsd-win-sock-new.c", 34LL);
if ( !getaddrinfo(
*((const char **)v23 + 13),
*((const char **)v23 + 14),
(const struct addrinfo *)(v23 + 8),
(struct addrinfo **)v23 + 7) )
{
v10 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket creation succeded\n", v10, "src/network/bsd-win-sock-new.c", 44LL);
return v23;
}
v12 = "None";
Socket_set_errno(4294967292LL);
v13 = (const char *)((__int64 (__fastcall *)(__int64))Socket_strerror)(4294967292LL);
v14 = _errno_location();
v15 = v14;
if ( *v14 )
v12 = strerror(*v14);
v16 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Getaddrinfo failed: %s\n",
v16,
"src/network/bsd-win-sock-new.c",
38LL,
v12,
v13);
Socket_free(&v23);
v17 = *v15;
v18 = "None";
if ( v17 )
v18 = strerror(v17);
v19 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Socket creation failed\n",
v19,
"src/network/bsd-win-sock-new.c",
40LL,
v18);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, const char *a2)
{
void *v2; // r12
char *v4; // rax
char *v5; // rax
const char *v6; // r12
char *v7; // rax
_QWORD *v8; // rdi
char *v9; // rax
char *v10; // rax
char *v12; // r12
const char *v13; // rbp
int *v14; // rax
int *v15; // rbx
char *v16; // rax
int v17; // edi
char *v18; // rbx
char *v19; // rax
char *v20; // rbx
int v21; // edi
char *v22; // rax
char *v23; // [rsp+8h] [rbp-20h] BYREF

v2 = 0LL;
v4 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Creating new socket\n", v4, "src/network/bsd-win-sock-new.c", 10LL);
if ( (int)Socket_startup() < 0 )
return (char *)v2;
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Mallocing Socket_T\n", v5, "src/network/bsd-win-sock-new.c", 14LL);
v23 = (char *)malloc(0x78uLL);
v2 = v23;
if ( !v23 )
{
v20 = "None";
Socket_set_errno(4294967293LL);
v21 = *_errno_location();
if ( v21 )
v20 = strerror(v21);
v22 = func0();
fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) Malloc failed\n", v22, "src/network/bsd-win-sock-new.c", 19LL, v20);
return (char *)v2;
}
v6 = "ANY";
if ( a1 )
v6 = a1;
v7 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Initializing Socket_T: %s:%s\n",
v7,
"src/network/bsd-win-sock-new.c",
23LL,
v6,
a2);
v8 = v23;
*(_QWORD *)v23 = -1LL;
v8[7] = 0LL;
*((_BYTE *)v8 + 64) = 0;
*((_BYTE *)v8 + 84) = 0;
v8[13] = a1;
v8[14] = a2;
Socket_set_hints();
v9 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Getting addrinfo\n", v9, "src/network/bsd-win-sock-new.c", 34LL);
if ( !getaddrinfo(
*((const char **)v23 + 13),
*((const char **)v23 + 14),
(const struct addrinfo *)(v23 + 8),
(struct addrinfo **)v23 + 7) )
{
v10 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket creation succeded\n", v10, "src/network/bsd-win-sock-new.c", 44LL);
return v23;
}
v12 = "None";
Socket_set_errno(4294967292LL);
v13 = (const char *)((__int64 (__fastcall *)(__int64))Socket_strerror)(4294967292LL);
v14 = _errno_location();
v15 = v14;
if ( *v14 )
v12 = strerror(*v14);
v16 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Getaddrinfo failed: %s\n",
v16,
"src/network/bsd-win-sock-new.c",
38LL,
v12,
v13);
Socket_free(&v23);
v17 = *v15;
v18 = "None";
if ( v17 )
v18 = strerror(v17);
v19 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Socket creation failed\n",
v19,
"src/network/bsd-win-sock-new.c",
40LL,
v18);
return 0LL;
}

original_code:
extern Socket_T* Socket_new(const char* address, const char* portnum) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Creating new socket" "\n", get_time(), "src/network/bsd-win-sock-new.c", 10);
 if (Socket_startup() < 0)
  return ((void *)0);
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Mallocing Socket_T" "\n", get_time(), "src/network/bsd-win-sock-new.c", 14);
 Socket_T* sock = (Socket_T*)malloc(sizeof(Socket_T));
 if (sock == ((void *)0)) {
  Socket_set_errno(-3);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Malloc failed" "\n", get_time(), "src/network/bsd-win-sock-new.c", 19, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
  return ((void *)0);
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Initializing Socket_T: %s:%s" "\n", get_time(), "src/network/bsd-win-sock-new.c", 23, address != ((void *)0)?address:"ANY", portnum);
 sock->sockfd_src = -1;
 sock->sockfd_dest = -1;
 sock->result = ((void *)0);
 sock->peer_ip[0] = '\0';
 sock->peer_port[0] = '\0';
 sock->address = address;
 sock->portnum = portnum;
 Socket_set_hints(sock);
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Getting addrinfo" "\n", get_time(), "src/network/bsd-win-sock-new.c", 34);
 if (getaddrinfo(sock->address, sock->portnum,
                 &(sock->hints), &(sock->result)) != 0) {
  Socket_set_errno(-4);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Getaddrinfo failed: %s" "\n", get_time(), "src/network/bsd-win-sock-new.c", 38, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  Socket_free(&sock);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Socket creation failed" "\n", get_time(), "src/network/bsd-win-sock-new.c", 40, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
  return ((void *)0);
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket creation succeded" "\n", get_time(), "src/network/bsd-win-sock-new.c", 44);
 return sock;
}

canonical_original_code:
extern struct Socket_T *Socket_new(char *address, char *portnum) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Creating new socket" "\n", get_time(), "src/network/bsd-win-sock-new.c", 10);
 if (Socket_startup() < 0)
  return ((void *)0);
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Mallocing Socket_T" "\n", get_time(), "src/network/bsd-win-sock-new.c", 14);
 struct Socket_T *sock = (Socket_T*)malloc(sizeof(Socket_T));
 if (sock == ((void *)0)) {
  Socket_set_errno(-3);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Malloc failed" "\n", get_time(), "src/network/bsd-win-sock-new.c", 19, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
  return ((void *)0);
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Initializing Socket_T: %s:%s" "\n", get_time(), "src/network/bsd-win-sock-new.c", 23, address != ((void *)0)?address:"ANY", portnum);
 sock->sockfd_src = -1;
 sock->sockfd_dest = -1;
 sock->result = ((void *)0);
 sock->peer_ip[0] = '\0';
 sock->peer_port[0] = '\0';
 sock->address = address;
 sock->portnum = portnum;
 Socket_set_hints(sock);
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Getting addrinfo" "\n", get_time(), "src/network/bsd-win-sock-new.c", 34);
 if (getaddrinfo(sock->address, sock->portnum,
                 &(sock->hints), &(sock->result)) != 0) {
  Socket_set_errno(-4);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Getaddrinfo failed: %s" "\n", get_time(), "src/network/bsd-win-sock-new.c", 38, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  Socket_free(&sock);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Socket creation failed" "\n", get_time(), "src/network/bsd-win-sock-new.c", 40, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
  return ((void *)0);
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket creation succeded" "\n", get_time(), "src/network/bsd-win-sock-new.c", 44);
 return sock;
}

variable_types:
address
char *

variable_types:
portnum
char *

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

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

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


decompiled_code:
char *IP_strerror()
{
return error;
}

canonical_decompiled_code:
char *func0()
{
return error;
}

original_code:
extern char* IP_strerror(void) {
 return error;
}

canonical_original_code:
extern char *IP_strerror() {
 return error;
}


decompiled_code:
int IP_set_strerror(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vsprintf(error, format, arg);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vsprintf(error, format, arg);
}

original_code:
extern void IP_set_strerror(const char* format, ...) {
 va_list arglist;
 __builtin_va_start(arglist,format);
 vsprintf(error, format, arglist);
 __builtin_va_end(arglist);
 return;
}

canonical_original_code:
extern void IP_set_strerror(char *format, ...) {
 __builtin_va_list arglist;
 __builtin_va_start(arglist,format);
 vsprintf(error, format, arglist);
 __builtin_va_end(arglist);
 return;
}

variable_types:
format
char *

return_type: void


decompiled_code:
__int64 __fastcall Socket_send(int *a1, const char *a2, unsigned int a3)
{
__int64 v3; // rbp
char *v4; // rax
unsigned int v5; // ebx
int v6; // er12
__int64 v7; // r15
char *v8; // rax
char *v9; // rax
char *v10; // rax
int v11; // eax
int v12; // er15
char *v13; // rbx
const char *v14; // rbp
int v15; // edi
char *v16; // rax
char *v17; // rax

v3 = a3;
v4 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Sending %d chars, message: %.*s\n",
v4,
"src/network/bsd-win-sock-send.c",
15LL,
(unsigned int)v3,
v3,
a2);
if ( (int)v3 <= 0 )
{
v6 = 0;
LABEL_9:
v17 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Send succeded\n", v17, "src/network/bsd-win-sock-send.c", 33LL);
}
else
{
v5 = v3;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v11 = send(*a1, &a2[v7], (int)v5, 0);
v12 = v11;
if ( v11 == -1 )
break;
v6 += v11;
v5 -= v11;
v8 = get_time();
v7 = v6;
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---send: %d/%d\n",
v8,
"src/network/bsd-win-sock-send.c",
22LL,
(unsigned int)v6,
v3);
v9 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---bytes left: %d\n", v9, "src/network/bsd-win-sock-send.c", 23LL, v5);
v10 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---message left: %.*s\n",
v10,
"src/network/bsd-win-sock-send.c",
24LL,
v5,
&a2[v6]);
if ( (int)v3 <= v6 )
goto LABEL_9;
}
v13 = "None";
Socket_set_errno(4294967285LL);
v14 = (const char *)Socket_strerror();
v15 = *_errno_location();
if ( v15 )
v13 = strerror(v15);
v6 = v12;
v16 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Send failed: %s\n",
v16,
"src/network/bsd-win-sock-send.c",
29LL,
v13,
v14);
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const char *a2, unsigned int a3)
{
__int64 v3; // rbp
char *v4; // rax
unsigned int v5; // ebx
int v6; // er12
__int64 v7; // r15
char *v8; // rax
char *v9; // rax
char *v10; // rax
int v11; // eax
int v12; // er15
char *v13; // rbx
const char *v14; // rbp
int v15; // edi
char *v16; // rax
char *v17; // rax

v3 = a3;
v4 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Sending %d chars, message: %.*s\n",
v4,
"src/network/bsd-win-sock-send.c",
15LL,
(unsigned int)v3,
v3,
a2);
if ( (int)v3 <= 0 )
{
v6 = 0;
LABEL_9:
v17 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Send succeded\n", v17, "src/network/bsd-win-sock-send.c", 33LL);
}
else
{
v5 = v3;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v11 = send(*a1, &a2[v7], (int)v5, 0);
v12 = v11;
if ( v11 == -1 )
break;
v6 += v11;
v5 -= v11;
v8 = func0();
v7 = v6;
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---send: %d/%d\n",
v8,
"src/network/bsd-win-sock-send.c",
22LL,
(unsigned int)v6,
v3);
v9 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---bytes left: %d\n", v9, "src/network/bsd-win-sock-send.c", 23LL, v5);
v10 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) ---message left: %.*s\n",
v10,
"src/network/bsd-win-sock-send.c",
24LL,
v5,
&a2[v6]);
if ( (int)v3 <= v6 )
goto LABEL_9;
}
v13 = "None";
Socket_set_errno(4294967285LL);
v14 = (const char *)Socket_strerror();
v15 = *_errno_location();
if ( v15 )
v13 = strerror(v15);
v6 = v12;
v16 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Send failed: %s\n",
v16,
"src/network/bsd-win-sock-send.c",
29LL,
v13,
v14);
}
return (unsigned int)v6;
}

original_code:
extern int Socket_send(Socket_T* sock, const char* msg, int len) {
 int total = 0;
 int bytesleft = len;
 int n;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Sending %d chars, message: %.*s" "\n", get_time(), "src/network/bsd-win-sock-send.c", 15, len, len, msg);
 while (total < len) {
  n = send(sock->sockfd_dest, msg + total, bytesleft, 0);
  if (n == -1)
   break;
  total += n;
  bytesleft -= n;
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---send: %d/%d" "\n", get_time(), "src/network/bsd-win-sock-send.c", 22, total, len);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---bytes left: %d" "\n", get_time(), "src/network/bsd-win-sock-send.c", 23, bytesleft);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---message left: %.*s" "\n", get_time(), "src/network/bsd-win-sock-send.c", 24, bytesleft, msg + total);
 }
 if (n == -1) {
  Socket_set_errno(-11);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Send failed: %s" "\n", get_time(), "src/network/bsd-win-sock-send.c", 29, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Send succeded" "\n", get_time(), "src/network/bsd-win-sock-send.c", 33);
 return total;
}

canonical_original_code:
extern int Socket_send(struct Socket_T *sock, char *msg, int len) {
 int total = 0;
 int bytesleft = len;
 int n;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Sending %d chars, message: %.*s" "\n", get_time(), "src/network/bsd-win-sock-send.c", 15, len, len, msg);
 while (total < len) {
  n = send(sock->sockfd_dest, msg + total, bytesleft, 0);
  if (n == -1)
   break;
  total += n;
  bytesleft -= n;
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---send: %d/%d" "\n", get_time(), "src/network/bsd-win-sock-send.c", 22, total, len);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---bytes left: %d" "\n", get_time(), "src/network/bsd-win-sock-send.c", 23, bytesleft);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---message left: %.*s" "\n", get_time(), "src/network/bsd-win-sock-send.c", 24, bytesleft, msg + total);
 }
 if (n == -1) {
  Socket_set_errno(-11);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Send failed: %s" "\n", get_time(), "src/network/bsd-win-sock-send.c", 29, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Send succeded" "\n", get_time(), "src/network/bsd-win-sock-send.c", 33);
 return total;
}

variable_types:
msg
char *

variable_types: len int

variable_types: total int

variable_types: bytesleft int

variable_types: n int

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


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

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


decompiled_code:
__int64 __fastcall IP_host_bits_by_total_hosts(unsigned __int64 a1)
{
unsigned int v1; // er12
char *v3; // rbx
char *v4; // rax
char *v5; // rax
char *v6; // rbx
int v7; // edi
char *v8; // rax
char *v10; // rax
char v11; // [rsp+4h] [rbp-34h] BYREF
__int64 v12; // [rsp+8h] [rbp-30h]
char v13; // [rsp+10h] [rbp-28h] BYREF

v1 = 8;
v12 = 0x1800000010LL;
v3 = &v11;
v4 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable Class for %lu hosts\n",
v4,
"src/subnetting/ip_util_total_hosts.c",
13LL,
a1);
while ( 1 )
{
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---%d bits\n", v5, "src/subnetting/ip_util_total_hosts.c", 16LL, v1);
if ( max_hosts(v1) >= a1 )
{
v10 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Found with %d bits\n", v10, "src/subnetting/ip_util_total_hosts.c", 18LL, v1);
return v1;
}
v3 += 4;
if ( v3 == &v13 )
break;
v1 = *(_DWORD *)v3;
}
v6 = "None";
IP_set_strerror("Too many hosts: %lu", a1);
v7 = *_errno_location();
if ( v7 )
v6 = strerror(v7);
v8 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Too many hosts: %lu\n",
v8,
"src/subnetting/ip_util_total_hosts.c",
24LL,
v6,
a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
unsigned int v1; // er12
char *v3; // rbx
char *v4; // rax
char *v5; // rax
char *v6; // rbx
int v7; // edi
char *v8; // rax
char *v10; // rax
char v11; // [rsp+4h] [rbp-34h] BYREF
__int64 v12; // [rsp+8h] [rbp-30h]
char v13; // [rsp+10h] [rbp-28h] BYREF

v1 = 8;
v12 = 0x1800000010LL;
v3 = &v11;
v4 = func1();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable Class for %lu hosts\n",
v4,
"src/subnetting/ip_util_total_hosts.c",
13LL,
a1);
while ( 1 )
{
v5 = func1();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---%d bits\n", v5, "src/subnetting/ip_util_total_hosts.c", 16LL, v1);
if ( func0(v1) >= a1 )
{
v10 = func1();
fprintf(stderr, "[DEBUG]%s (%s:%d) Found with %d bits\n", v10, "src/subnetting/ip_util_total_hosts.c", 18LL, v1);
return v1;
}
v3 += 4;
if ( v3 == &v13 )
break;
v1 = *(_DWORD *)v3;
}
v6 = "None";
IP_set_strerror("Too many hosts: %lu", a1);
v7 = *_errno_location();
if ( v7 )
v6 = strerror(v7);
v8 = func1();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Too many hosts: %lu\n",
v8,
"src/subnetting/ip_util_total_hosts.c",
24LL,
v6,
a1);
return 0xFFFFFFFFLL;
}

original_code:
extern int IP_host_bits_by_total_hosts(host_size_t total_hosts) {
 int hosts[3] = {8, 16, 24};
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable Class for %lu hosts" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 13, total_hosts);
 int i;
 for(i = 0; i < sizeof(hosts)/sizeof(int); i++) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---%d bits" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 16, hosts[i]);
  if (total_hosts <= max_hosts(hosts[i])) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found with %d bits" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 18, hosts[i]);
   return hosts[i];
  }
 }
 IP_set_strerror("Too many hosts: %lu", total_hosts);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Too many hosts: %lu" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), total_hosts);
 return -1;
}

canonical_original_code:
extern int IP_host_bits_by_total_hosts(unsigned long total_hosts) {
 int hosts[3] = {8, 16, 24};
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable Class for %lu hosts" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 13, total_hosts);
 int i;
 for(i = 0; i < sizeof(hosts)/sizeof(int); i++) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---%d bits" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 16, hosts[i]);
  if (total_hosts <= max_hosts(hosts[i])) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found with %d bits" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 18, hosts[i]);
   return hosts[i];
  }
 }
 IP_set_strerror("Too many hosts: %lu", total_hosts);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Too many hosts: %lu" "\n", get_time(), "src/subnetting/ip_util_total_hosts.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), total_hosts);
 return -1;
}

variable_types:
hosts
int [3]

variable_types: i int


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

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

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

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

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

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

variable_types: id int

variable_types:
ip
unsigned long


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
subnets
unsigned long


decompiled_code:
__int64 __fastcall IP_ip_to_dot_decimal(__int64 a1, char *a2)
{
char *v2; // rax
unsigned __int64 v3; // rax
__int64 v4; // r8
__int64 v5; // r9
__int64 v6; // r10
char *v7; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2)
{
char *v2; // rax
unsigned __int64 v3; // rax
__int64 v4; // r8
__int64 v5; // r9
__int64 v6; // r10
char *v7; // rax

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall IP_subnet_bits_by_total_hosts(__int64 a1, unsigned __int64 a2)
{
int v2; // er15
char *v3; // rax
int v4; // er15
unsigned int v5; // er12
__int64 v6; // rbp
__int64 v7; // rax
unsigned __int64 v8; // r13
__int64 v9; // rbx
char *v10; // rax
char *v11; // rax
char *v12; // rax
char *v13; // rbx
int v14; // edi
char *v15; // rax
char *v17; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
int v2; // er15
char *v3; // rax
int v4; // er15
unsigned int v5; // er12
__int64 v6; // rbp
__int64 v7; // rax
unsigned __int64 v8; // r13
__int64 v9; // rbx
char *v10; // rax
char *v11; // rax
char *v12; // rax
char *v13; // rbx
int v14; // edi
char *v15; // rax
char *v17; // rax

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

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

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

variable_types:
total
unsigned long


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

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

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

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


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

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

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

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

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

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

variable_types: yes int

variable_types: value int


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

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

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

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

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

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

variable_types:
hosts
unsigned long


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
broadcast
unsigned long

variable_types:
mask
unsigned long

variable_types:
aux
char [65]


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

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

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

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

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

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

variable_types: timer long

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


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

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

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

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

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

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

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


repo: QMonkey/HTTP-Web-Server

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

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

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

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

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

variable_types:
response
struct HTTP_Socket *

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


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

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

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

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

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


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

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

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

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