CreateThread

decompiled_code:
__int64 __fastcall CreateThread(int a1, int a2, unsigned int a3)
{
unsigned int v4; // ebx
_DWORD *v6; // rax

v4 = getTid();
if ( v4 )
{
if ( malloc(0x2000uLL) )
{
v6 = CreateTD(v4);
v6[6] = a3;
*((_QWORD *)v6 + 5) = ReadyQ;
v6[4] = a1;
v6[3] = a2;
myprint("CreateThread ");
v4 = 6;
if ( *(_DWORD *)(Active + 24) < a3 )
Yield();
}
else
{
v4 = 1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func26(int a1, int a2, unsigned int a3)
{
unsigned int v4; // ebx
_DWORD *v6; // rax

v4 = func20();
if ( v4 )
{
if ( malloc(0x2000uLL) )
{
v6 = CreateTD(v4);
v6[6] = a3;
*((_QWORD *)v6 + 5) = ReadyQ;
v6[4] = a1;
v6[3] = a2;
func7("CreateThread ");
v4 = 6;
if ( *(_DWORD *)(Active + 24) < a3 )
func24();
}
else
{
v4 = 1;
}
}
return v4;
}

original_code:
T_RC CreateThread(uval32 pc, uval32 sp, uval32 priority) {
 int *ptr, tid;
 TD *thread;
 if ((priority < 1) & (priority > 128)) {
  return PRIORITY_ERROR;
 } else if (!(tid = getTid())) {
  return RESOURCE_ERROR;
 } else if ((ptr = malloc(8192)) == 0) {
  return STACK_ERROR;
 }
 thread = CreateTD(tid);
    thread->priority = priority;
    thread->inlist = ReadyQ;
    thread->regs.pc = pc;
    thread->regs.sp = sp;
 myprint("CreateThread ");
 if (priority > Active->priority) {
     Yield();
    }
 return OK;
}

canonical_original_code:
enum T_RC CreateThread(unsigned int pc, unsigned int sp, unsigned int priority) {
 int *ptr; int tid;
 struct type_TD *thread;
 if ((priority < 1) & (priority > 128)) {
  return PRIORITY_ERROR;
 } else if (!(tid = getTid())) {
  return RESOURCE_ERROR;
 } else if ((ptr = malloc(8192)) == 0) {
  return STACK_ERROR;
 }
 thread = CreateTD(tid);
    thread->priority = priority;
    thread->inlist = ReadyQ;
    thread->regs.pc = pc;
    thread->regs.sp = sp;
 myprint("CreateThread ");
 if (priority > Active->priority) {
     Yield();
    }
 return OK;
}

variable_types:
ptr
int *

variable_types: tid int


ResumeThread

decompiled_code:
__int64 __fastcall ResumeThread(int a1)
{
int v1; // edx
__int64 result; // rax
__int64 *v3; // rdx

v1 = tidInUse(a1);
result = 3LL;
if ( v1 )
{
v3 = getTD(a1);
if ( v3 )
{
result = 4LL;
if ( v3[5] == BlockedQ )
{
v3[5] = ReadyQ;
result = 6LL;
if ( *((_DWORD *)v3 + 6) > *(_DWORD *)(Active + 24) )
{
Yield();
result = 6LL;
}
}
}
else
{
result = 3LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func27(int a1)
{
int v1; // edx
__int64 result; // rax
__int64 *v3; // rdx

v1 = func21(a1);
result = 3LL;
if ( v1 )
{
v3 = getTD(a1);
if ( v3 )
{
result = 4LL;
if ( v3[5] == BlockedQ )
{
v3[5] = ReadyQ;
result = 6LL;
if ( *((_DWORD *)v3 + 6) > *(_DWORD *)(Active + 24) )
{
func24();
result = 6LL;
}
}
}
else
{
result = 3LL;
}
}
return result;
}

original_code:
T_RC ResumeThread(ThreadId tid) {
 TD * td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else if ((td = getTD(tid)) == ((void *)0)) {
  return TID_ERROR;
 } else {
  if (td->inlist != BlockedQ) {
   return NOT_BLOCKED;
  } else {
   td->inlist = ReadyQ;
  }
  if (td->priority > Active->priority) {
   Yield();
  }
  return OK;
 }
}

canonical_original_code:
enum T_RC ResumeThread(unsigned int tid) {
 struct type_TD *td;
 if (!tidInUse(tid)) {
  return TID_ERROR;
 } else if ((td = getTD(tid)) == ((void *)0)) {
  return TID_ERROR;
 } else {
  if (td->inlist != BlockedQ) {
   return NOT_BLOCKED;
  } else {
   td->inlist = ReadyQ;
  }
  if (td->priority > Active->priority) {
   Yield();
  }
  return OK;
 }
}

variable_types:
tid
unsigned int

variable_types: struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS { unsigned int sp; unsigned int pc; unsigned int sr; } regs; unsigned int priority; int waittime; enum RC { RC_SUCCESS=0, RC_FAILED=1 } returnCode; struct type_LL { struct type_TD *head; struct type_TD *tail; enum ListType { UNDEF=0, L_PRIORITY=1, L_LIFO=2, L_WAITING=3, L_CIRCULAR=4 } type; } *inlist; } *

return_type: enum T_RC { RESOURCE_ERROR=0, STACK_ERROR=1, PRIORITY_ERROR=2, TID_ERROR=3, NOT_BLOCKED=4, FAILED=5, OK=6 }

user_defined_types: struct type_TD { struct type_TD *link; unsigned int tid; struct type_REGS regs; unsigned int priority; int waittime; enum RC returnCode; struct type_LL *inlist; }

user_defined_types: struct type_LL { struct type_TD *head; struct type_TD *tail; enum ListType type; }


Idle

decompiled_code:
void __noreturn Idle()
{
while ( 1 )
{
myprint("CPU is idle\n");
Yield();
}
}

canonical_decompiled_code:
void __noreturn func28()
{
while ( 1 )
{
func7("CPU is idle\n");
func24();
}
}

original_code:
void Idle() {
  int i;
  while( 1 )
  {
   myprint( "CPU is idle\n" );
   for( i = 0; i < 5; i++ )
   {
   }
   Yield();
  }
}

variable_types: i int

return_type: void


Suspend

decompiled_code:
__int64 Suspend()
{
EnqueueAtHead((_QWORD *)Active, BlockedQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_decompiled_code:
__int64 func29()
{
func14((_QWORD *)Active, BlockedQ);
Active = (__int64)DequeueHead((_QWORD **)ReadyQ);
return 6LL;
}

canonical_original_code:
enum T_RC Suspend() {
 EnqueueAtHead(Active, BlockedQ);
 Active = DequeueHead(ReadyQ);
 return OK;
}

user_defined_types: enum T_RC { RESOURCE_ERROR=0, STACK_ERROR=1, PRIORITY_ERROR=2, TID_ERROR=3, NOT_BLOCKED=4, FAILED=5, OK=6 }


decompiled_code:
int __fastcall K_SysCall(unsigned int a1, int a2, unsigned int a3, unsigned int a4)
{
int result; // eax

switch ( a1 )
{
case 0u:
result = CreateThread(a2, a3, a4);
break;
case 1u:
result = DestroyThread(a2);
break;
case 2u:
result = Yield(a1, a3);
break;
case 3u:
result = Suspend(a1, a3);
break;
case 4u:
result = ResumeThread(a2);
break;
case 5u:
result = ChangeThreadPriority(a2, a3);
break;
default:
result = myprint("Invalid SysCall type\n");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func30(unsigned int a1, int a2, unsigned int a3, unsigned int a4)
{
int result; // eax

switch ( a1 )
{
case 0u:
result = func26(a2, a3, a4);
break;
case 1u:
result = func23(a2);
break;
case 2u:
result = func24(a1, a3);
break;
case 3u:
result = func29(a1, a3);
break;
case 4u:
result = func27(a2);
break;
case 5u:
result = func22(a2, a3);
break;
default:
result = func7("Invalid SysCall type\n");
break;
}
return result;
}

original_code:
void K_SysCall(SysCallType type, uval32 arg0, uval32 arg1, uval32 arg2) {
 RC returnCode;
 switch (type) {
 case SYS_CREATE:
  returnCode = CreateThread(arg0, arg1, arg2);
  break;
 case SYS_DIST:
  returnCode = DestroyThread(arg0);
  break;
 case SYS_YIELD:
  returnCode = Yield();
  break;
 case SYS_SUSP:
  returnCode = Suspend();
  break;
 case SYS_RESUME:
  returnCode = ResumeThread((ThreadId)arg0);
  break;
 case SYS_CHANGE_PRI:
  returnCode = ChangeThreadPriority(arg0, arg1);
  break;
 default:
  myprint("Invalid SysCall type\n");
  returnCode = FAILED;
  break;
 }
}

canonical_original_code:
void K_SysCall(enum SysCallType type, unsigned int arg0, unsigned int arg1, unsigned int arg2) {
 enum RC returnCode;
 switch (type) {
 case SYS_CREATE:
  returnCode = CreateThread(arg0, arg1, arg2);
  break;
 case SYS_DIST:
  returnCode = DestroyThread(arg0);
  break;
 case SYS_YIELD:
  returnCode = Yield();
  break;
 case SYS_SUSP:
  returnCode = Suspend();
  break;
 case SYS_RESUME:
  returnCode = ResumeThread((unsigned int)arg0);
  break;
 case SYS_CHANGE_PRI:
  returnCode = ChangeThreadPriority(arg0, arg1);
  break;
 default:
  myprint("Invalid SysCall type\n");
  returnCode = FAILED;
  break;
 }
}

variable_types: enum SysCallType { SYS_CREATE=0, SYS_DIST=1, SYS_YIELD=2, SYS_SUSP=3, SYS_RESUME=4, SYS_CHANGE_PRI=5 }

variable_types:
returnCode
enum RC { RC_SUCCESS=0, RC_FAILED=1 }


decompiled_code:
void interrupt_handler()
{
;
}

canonical_decompiled_code:
void func31()
{
;
}

original_code:
void interrupt_handler(void)
{
}

canonical_original_code:
void interrupt_handler()
{
}


repo: upwhere/ccbor

decompiled_code:
__int64 __fastcall cbor_store_tag(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 192;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

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

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 192;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static int cbor_store_tag(struct cbor_t*storage,const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_tag_t t= {
   .base= {
    .major=cbor_major_tag,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  },*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 cbor_store_tag(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_tag_t t = {
   .base= {
    .major=cbor_major_tag,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  }; struct cbor_tag_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:
additional
unsigned char

variable_types: stream int

variable_types: struct cbor_tag_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 value; } *

return_type: int

user_defined_types: struct cbor_tag_t { struct cbor_t base; unsigned long value; }

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


decompiled_code:
char __fastcall cbor_major_of(unsigned __int8 a1)
{
return a1 >> 5;
}

canonical_decompiled_code:
char __fastcall func1(unsigned __int8 a1)
{
return a1 >> 5;
}

original_code:
uint8_t cbor_major_of(uint8_t item)
{
 return (item& (cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt))>>5;
}

canonical_original_code:
unsigned char cbor_major_of(unsigned char item)
{
 return (item& (cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt))>>5;
}

variable_types:
item
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall cbor_additional_of(char a1)
{
return a1 & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return a1 & 0x1F;
}

original_code:
uint8_t cbor_additional_of(uint8_t item)
{
 return item& ~(cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt);
}

canonical_original_code:
unsigned char cbor_additional_of(unsigned char item)
{
 return item& ~(cbor_major_uint | cbor_major_nint | cbor_major_bstr | cbor_major_tstr | cbor_major_arr | cbor_major_map | cbor_major_tag | cbor_major_flt);
}


decompiled_code:
void __fastcall recursive_naive_cbor_free(void *ptr)
{
if ( ptr )
{
recursive_naive_cbor_free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
func3(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void recursive_naive_cbor_free(struct cbor_t*listitem)
{
 if(listitem==((void *)0))return;
 recursive_naive_cbor_free(listitem->next);
 free(listitem);
 return;
}

canonical_original_code:
void recursive_naive_cbor_free(struct cbor_t *listitem)
{
 if(listitem==((void *)0))return;
 recursive_naive_cbor_free(listitem->next);
 free(listitem);
 return;
}

user_defined_types: 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 }


decode

decompiled_code:
__int64 __fastcall decode(int fd, __int64 a2)
{
__int64 v2; // rbp
char v3; // r13
unsigned __int8 v4; // bl
unsigned __int8 v5; // al
__int64 result; // rax
unsigned __int8 buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v2 = a2;
if ( !a2 )
return 2LL;
while ( 1 )
{
buf[0] = 0;
if ( read(fd, buf, 1uLL) <= 0 )
break;
v3 = buf[0];
v4 = cbor_major_of(buf[0]);
v5 = cbor_additional_of(v3);
result = (*(&cbor_store + v4))(v2, v5, (unsigned int)fd);
if ( (_DWORD)result )
return result;
if ( v2 )
v2 = *(_QWORD *)(v2 + 8);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2)
{
__int64 v2; // rbp
char v3; // r13
unsigned __int8 v4; // bl
unsigned __int8 v5; // al
__int64 result; // rax
unsigned __int8 buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v2 = a2;
if ( !a2 )
return 2LL;
while ( 1 )
{
buf[0] = 0;
if ( read(fd, buf, 1uLL) <= 0 )
break;
v3 = buf[0];
v4 = func1(buf[0]);
v5 = func2(v3);
result = (*(&cbor_store + v4))(v2, v5, (unsigned int)fd);
if ( (_DWORD)result )
return result;
if ( v2 )
v2 = *(_QWORD *)(v2 + 8);
}
return 0LL;
}

original_code:
int decode(const int stream,struct cbor_t*storage)
{
 if(storage==((void *)0))return 2;
 {
  int store_status=0;
  struct cbor_t*store=storage;
  do
  {
   uint8_t item=0;
   if(read(stream,&item,sizeof item) < 1 )
   {
    break;
   }
   store_status=cbor_store[cbor_major_of(item)](store,cbor_additional_of(item),stream);
   if(store_status!=0)
   {
    return store_status;
   }
   if(store!=((void *)0))store=store->next;
  }
  while(1);
  return 0;
 }
}

canonical_original_code:
int decode(int stream, struct cbor_t *storage)
{
 if(storage==((void *)0))return 2;
 {
  int store_status = 0;
  struct cbor_t *store = storage;
  do
  {
   unsigned char item = 0;
   if(read(stream,&item,sizeof item) < 1 )
   {
    break;
   }
   store_status=cbor_store[cbor_major_of(item)](store,cbor_additional_of(item),stream);
   if(store_status!=0)
   {
    return store_status;
   }
   if(store!=((void *)0))store=store->next;
  }
  while(1);
  return 0;
 }
}


decompiled_code:
__int16 __fastcall be16to_h(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static uint16_t be16to_h(const uint16_t bigendian)
{
 return ((bigendian&0x00ff) <<8) |
  ((bigendian&0xff00) >>8);
 return bigendian;
}

canonical_original_code:
static unsigned short be16to_h(unsigned short bigendian)
{
 return ((bigendian&0x00ff) <<8) |
  ((bigendian&0xff00) >>8);
 return bigendian;
}

variable_types:
bigendian
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall be32to_h(unsigned int a1)
{
return (a1 >> 8) & 0xFF00 | (a1 << 8) & 0xFF0000 | HIBYTE(a1) | (a1 << 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return (a1 >> 8) & 0xFF00 | (a1 << 8) & 0xFF0000 | HIBYTE(a1) | (a1 << 24);
}

original_code:
static uint32_t be32to_h(const uint32_t bigendian)
{
 return ((bigendian&0x000000ff) <<24) |
  ((bigendian&0x0000ff00) <<8) |
  ((bigendian&0x00ff0000) >>8) |
  ((bigendian&0xff000000) >>24);
 return bigendian;
}

canonical_original_code:
static unsigned int be32to_h(unsigned int bigendian)
{
 return ((bigendian&0x000000ff) <<24) |
  ((bigendian&0x0000ff00) <<8) |
  ((bigendian&0x00ff0000) >>8) |
  ((bigendian&0xff000000) >>24);
 return bigendian;
}

variable_types:
bigendian
unsigned int

return_type: unsigned int


variable_types:
bigendian
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall cbor_value_uint(unsigned __int8 a1, int a2)
{
__int64 result; // rax
unsigned __int64 v3; // [rsp+0h] [rbp-18h] BYREF
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = 0LL;
switch ( a1 )
{
case 0x18u:
read(a2, &buf, 1uLL);
goto LABEL_4;
case 0x19u:
LOWORD(v3) = 0;
read(a2, &v3, 2uLL);
buf = (unsigned __int16)be16to_h(v3);
goto LABEL_4;
case 0x1Au:
LODWORD(v3) = 0;
read(a2, &v3, 4uLL);
buf = (unsigned int)be32to_h(v3);
goto LABEL_4;
case 0x1Bu:
v3 = 0LL;
read(a2, &v3, 8uLL);
buf = be64to_h(v3);
goto LABEL_4;
case 0x1Cu:
case 0x1Eu:
case 0x1Fu:
LABEL_4:
result = buf;
break;
default:
result = a1;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, int a2)
{
__int64 result; // rax
unsigned __int64 v3; // [rsp+0h] [rbp-18h] BYREF
__int64 buf; // [rsp+8h] [rbp-10h] BYREF

buf = 0LL;
switch ( a1 )
{
case 0x18u:
read(a2, &buf, 1uLL);
goto LABEL_4;
case 0x19u:
LOWORD(v3) = 0;
read(a2, &v3, 2uLL);
buf = (unsigned __int16)func0(v3);
goto LABEL_4;
case 0x1Au:
LODWORD(v3) = 0;
read(a2, &v3, 4uLL);
buf = (unsigned int)func1(v3);
goto LABEL_4;
case 0x1Bu:
v3 = 0LL;
read(a2, &v3, 8uLL);
buf = func2(v3);
goto LABEL_4;
case 0x1Cu:
case 0x1Eu:
case 0x1Fu:
LABEL_4:
result = buf;
break;
default:
result = a1;
break;
}
return result;
}

original_code:
uint64_t cbor_value_uint(const uint8_t additional,const int stream)
{
 uint64_t v=0;
 switch(additional) {
  default:
   return additional;
  case 24:
   (void)read(stream,&v,sizeof(uint8_t));
   break;
  case 25:
  {
   uint16_t v16=0;
   (void)read(stream,&v16,sizeof(uint16_t));
   v=be16to_h(v16);
   break;
  }
  case 26:
  {
   uint32_t v32=0;
   (void)read(stream,&v32,sizeof(uint32_t));
   v=be32to_h(v32);
   break;
  }
  case 27:
  {
   uint64_t v64=0;
   (void)read(stream,&v64,sizeof(uint64_t));
   v=be64to_h(v64);
   break;
  }
  case 28:
  case 30:
  case 31:
   break;
 }
 return v;
}

canonical_original_code:
unsigned long cbor_value_uint(unsigned char additional, int stream)
{
 unsigned long v = 0;
 switch(additional) {
  default:
   return additional;
  case 24:
   (void)read(stream,&v,sizeof(unsigned char));
   break;
  case 25:
  {
   unsigned short v16 = 0;
   (void)read(stream,&v16,sizeof(unsigned short));
   v=be16to_h(v16);
   break;
  }
  case 26:
  {
   unsigned int v32 = 0;
   (void)read(stream,&v32,sizeof(unsigned int));
   v=be32to_h(v32);
   break;
  }
  case 27:
  {
   unsigned long v64 = 0;
   (void)read(stream,&v64,sizeof(unsigned long));
   v=be64to_h(v64);
   break;
  }
  case 28:
  case 30:
  case 31:
   break;
 }
 return v;
}

variable_types:
v
unsigned long


decompiled_code:
__int64 __fastcall cbor_store_uint(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
__int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 0;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
__int64 v4; // rbp
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = func3(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
*(_DWORD *)v5 = 0;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int cbor_store_uint(struct cbor_t*storage,const uint8_t additional,const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_uint_t c= {
   .base= {
    .major=cbor_major_uint,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  },*fresh=malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  memcpy(fresh,&c,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

canonical_original_code:
int cbor_store_uint(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_uint_t c = {
   .base= {
    .major=cbor_major_uint,
    .next=((void *)0),
   },
   .value=cbor_value_uint(additional,stream),
  }; struct cbor_uint_t *fresh = malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  memcpy(fresh,&c,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

variable_types: struct cbor_uint_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 value; } *

user_defined_types: struct cbor_uint_t { struct cbor_t base; unsigned long value; }


decompiled_code:
__int64 __fastcall cbor_store_nint(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
__int64 v4; // r12
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = cbor_value_uint(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
if ( a2 != 1 && v4 == -1 )
{
free(v5);
result = 3LL;
}
else
{
*(_DWORD *)v5 = 32;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
__int64 v4; // r12
_QWORD *v5; // rax

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = func3(a2, a3);
v5 = malloc(0x18uLL);
if ( v5 )
{
if ( a2 != 1 && v4 == -1 )
{
free(v5);
result = 3LL;
}
else
{
*(_DWORD *)v5 = 32;
v5[1] = 0LL;
v5[2] = v4;
*(_QWORD *)(a1 + 8) = v5;
result = 0LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int cbor_store_nint(struct cbor_t*storage,const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_nint_t n= {
   .base= {
    .major=cbor_major_nint,
    .next=((void *)0),
   },
   .nvalue=cbor_value_uint(additional,stream),
  },*fresh=malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  if(n.nvalue==(uint64_t)-1&&additional!=1)
  {
   free(fresh);
   return 3;
  }
  memcpy(fresh,&n,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

canonical_original_code:
int cbor_store_nint(struct cbor_t *storage, unsigned char additional, int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  struct cbor_nint_t n = {
   .base= {
    .major=cbor_major_nint,
    .next=((void *)0),
   },
   .nvalue=cbor_value_uint(additional,stream),
  }; struct cbor_nint_t *fresh = malloc(sizeof*fresh);
  if(fresh==((void *)0))return 1;
  if(n.nvalue==(unsigned long)-1&&additional!=1)
  {
   free(fresh);
   return 3;
  }
  memcpy(fresh,&n,sizeof*fresh);
  storage->next=&fresh->base;
  return 0;
 }
}

variable_types: struct cbor_nint_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 nvalue; } *

user_defined_types: struct cbor_nint_t { struct cbor_t base; unsigned long nvalue; }


decompiled_code:
__int64 __fastcall cbor_store_mapentry(_QWORD *a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 (__fastcall *v5)(int *, _QWORD, _QWORD); // r13
unsigned __int8 v6; // al
ssize_t v7; // rdx
__int64 v8; // rbx
__int64 (__fastcall *v9)(__int64, _QWORD, _QWORD); // r13
unsigned __int8 v10; // al
__int64 v11; // rcx
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v13; // [rsp+2h] [rbp-38h] BYREF
__int64 v14; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
result = 3LL;
if ( a2 != 0xFF )
{
v13 = 255;
v14 = 0LL;
buf = 0;
v5 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(a2));
v6 = cbor_additional_of(a2);
result = v5(&v13, v6, a3);
if ( !(_DWORD)result )
{
result = 2LL;
if ( v14 )
{
v7 = read(a3, &buf, 1uLL);
result = 3LL;
if ( v7 > 0 && buf != 0xFF )
{
v8 = v14;
v9 = *(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v10 = cbor_additional_of(buf);
result = v9(v8, v10, a3);
if ( !(_DWORD)result )
{
v11 = *(_QWORD *)(v14 + 8);
*a1 = v14;
a1[1] = v11;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
__int64 (__fastcall *v5)(int *, _QWORD, _QWORD); // r13
unsigned __int8 v6; // al
ssize_t v7; // rdx
__int64 v8; // rbx
__int64 (__fastcall *v9)(__int64, _QWORD, _QWORD); // r13
unsigned __int8 v10; // al
__int64 v11; // rcx
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v13; // [rsp+2h] [rbp-38h] BYREF
__int64 v14; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
result = 3LL;
if ( a2 != 0xFF )
{
v13 = 255;
v14 = 0LL;
buf = 0;
v5 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(a2));
v6 = cbor_additional_of(a2);
result = v5(&v13, v6, a3);
if ( !(_DWORD)result )
{
result = 2LL;
if ( v14 )
{
v7 = read(a3, &buf, 1uLL);
result = 3LL;
if ( v7 > 0 && buf != 0xFF )
{
v8 = v14;
v9 = *(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v10 = cbor_additional_of(buf);
result = v9(v8, v10, a3);
if ( !(_DWORD)result )
{
v11 = *(_QWORD *)(v14 + 8);
*a1 = v14;
a1[1] = v11;
}
}
}
}
}
return result;
}

original_code:
static int cbor_store_mapentry( struct cbor_mapentry_t*storage,const uint8_t key,const int stream)
{
 if(storage==((void *)0))return 2;
 if(key==0xff)return 3;
 {
  struct cbor_t head= {
   .major=0xFF,
   .next=((void *)0),
  };
  struct cbor_t*pair=&head;
  int store_attempt_ret;
  uint8_t item=0;
  if( (store_attempt_ret=cbor_store[cbor_major_of(key) ] (pair,cbor_additional_of(key),stream) ) !=0)return store_attempt_ret;
  if(pair->next==((void *)0))return 2;
  if(read(stream,&item,sizeof item) < (ssize_t) sizeof item)return 3;
  if(item==0xff)
  {
   store_attempt_ret=3;
   goto free;
  }
  pair=pair->next;
  if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (pair,cbor_additional_of(item) ,stream) ) !=0)goto free;
  pair=&head;
  {
   struct cbor_mapentry_t e= {
    .key=pair->next,
    .value=pair->next->next,
   };
   memcpy(storage,&e,sizeof*storage);
  }
  return 0;free:
  {
   return store_attempt_ret;
  }
 }
}

canonical_original_code:
static int cbor_store_mapentry(struct cbor_mapentry_t *storage, unsigned char key, int stream)
{
 if(storage==((void *)0))return 2;
 if(key==0xff)return 3;
 {
  struct cbor_t head = {
   .major=0xFF,
   .next=((void *)0),
  };
  struct cbor_t *pair = &head;
  int store_attempt_ret;
  unsigned char item = 0;
  if( (store_attempt_ret=cbor_store[cbor_major_of(key) ] (pair,cbor_additional_of(key),stream) ) !=0)return store_attempt_ret;
  if(pair->next==((void *)0))return 2;
  if(read(stream,&item,sizeof item) < (long) sizeof item)return 3;
  if(item==0xff)
  {
   store_attempt_ret=3;
   goto free;
  }
  pair=pair->next;
  if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (pair,cbor_additional_of(item) ,stream) ) !=0)goto free;
  pair=&head;
  {
   struct cbor_mapentry_t e = {
    .key=pair->next,
    .value=pair->next->next,
   };
   memcpy(storage,&e,sizeof*storage);
  }
  return 0;free:
  {
   return store_attempt_ret;
  }
 }
}

variable_types: struct cbor_mapentry_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; } *key; struct cbor_t *value; } *

variable_types:
key
unsigned char

user_defined_types: struct cbor_mapentry_t { struct cbor_t *key; struct cbor_t *value; }


decompiled_code:
__int64 __fastcall cbor_store_definite_arr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
unsigned int v4; // ebx
__int64 v6; // r13
void *v7; // r14
__int64 v8; // rbp
__int64 (__fastcall *v9)(int *, _QWORD, _QWORD); // rbx
unsigned __int8 v10; // al
_QWORD *v11; // rax
unsigned __int8 buf; // [rsp+Fh] [rbp-49h] BYREF
int v13; // [rsp+10h] [rbp-48h] BYREF
__int64 v14; // [rsp+18h] [rbp-40h]

if ( !a1 )
return 2;
v4 = 2;
if ( !*(_QWORD *)(a1 + 8) )
{
v6 = cbor_value_uint(a2, a3);
v7 = malloc(8 * v6);
v13 = 255;
v14 = 0LL;
if ( !v7 )
return 1;
v8 = 0LL;
if ( v6 )
{
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
break;
v9 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v10 = cbor_additional_of(buf);
v4 = v9(&v13, v10, a3);
if ( v4 )
{
free(v7);
return v4;
}
if ( !v14 )
{
free(v7);
return 2;
}
*((_QWORD *)v7 + v8) = v14;
v14 = 0LL;
if ( v6 == ++v8 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v11 = malloc(0x20uLL);
if ( v11 )
{
*(_DWORD *)v11 = 128;
v11[1] = 0LL;
v11[2] = v6;
v11[3] = v7;
*(_QWORD *)(a1 + 8) = v11;
return 0;
}
}
free(v7);
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
unsigned int v4; // ebx
__int64 v6; // r13
void *v7; // r14
__int64 v8; // rbp
__int64 (__fastcall *v9)(int *, _QWORD, _QWORD); // rbx
unsigned __int8 v10; // al
_QWORD *v11; // rax
unsigned __int8 buf; // [rsp+Fh] [rbp-49h] BYREF
int v13; // [rsp+10h] [rbp-48h] BYREF
__int64 v14; // [rsp+18h] [rbp-40h]

if ( !a1 )
return 2;
v4 = 2;
if ( !*(_QWORD *)(a1 + 8) )
{
v6 = cbor_value_uint(a2, a3);
v7 = malloc(8 * v6);
v13 = 255;
v14 = 0LL;
if ( !v7 )
return 1;
v8 = 0LL;
if ( v6 )
{
while ( 1 )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
break;
v9 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v10 = cbor_additional_of(buf);
v4 = v9(&v13, v10, a3);
if ( v4 )
{
free(v7);
return v4;
}
if ( !v14 )
{
free(v7);
return 2;
}
*((_QWORD *)v7 + v8) = v14;
v14 = 0LL;
if ( v6 == ++v8 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v11 = malloc(0x20uLL);
if ( v11 )
{
*(_DWORD *)v11 = 128;
v11[1] = 0LL;
v11[2] = v6;
v11[3] = v7;
*(_QWORD *)(a1 + 8) = v11;
return 0;
}
}
free(v7);
v4 = 1;
}
return v4;
}

original_code:
static int cbor_store_definite_arr(struct cbor_t*storage, const uint8_t additional, const int stream)
{
 if(storage==((void *)0) || storage->next!=((void *)0))return 2;
 {
  const size_t length=cbor_value_uint(additional,stream);
  struct cbor_t **array = malloc(length*sizeof(struct cbor_t const *));
  struct cbor_t head= {
   .major=0xFF,
   .next=((void *)0),
  } , *element= &head;
  int store_status;
  size_t i;
  if(array==((void *)0))
  {
   return 1;
  }
  for(i=0;i<length;i++)
  {
   uint8_t item=0;
   if(read(stream,&item,sizeof item)<(ssize_t)sizeof item)
   {
    free(array);
    return 1;
   }
   if((store_status=cbor_store[cbor_major_of(item)](element,cbor_additional_of(item),stream))!=0)
   {
    free(array);
    return store_status;
   }
   if(element->next==((void *)0))
   {
    free(array);
    return 2;
   }
   array[i]=element->next;
   element->next=((void *)0);
  }
  {
   struct cbor_arr_t a= {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=length,
    .array=array,
   } , *fresh= malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(array);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

canonical_original_code:
static int cbor_store_definite_arr(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);
  struct cbor_t **array = malloc(length*sizeof(struct cbor_t const *));
  struct cbor_t head = {
   .major=0xFF,
   .next=((void *)0),
  }; struct cbor_t *element = &head;
  int store_status;
  unsigned long i;
  if(array==((void *)0))
  {
   return 1;
  }
  for(i=0;i<length;i++)
  {
   unsigned char item = 0;
   if(read(stream,&item,sizeof item)<(long)sizeof item)
   {
    free(array);
    return 1;
   }
   if((store_status=cbor_store[cbor_major_of(item)](element,cbor_additional_of(item),stream))!=0)
   {
    free(array);
    return store_status;
   }
   if(element->next==((void *)0))
   {
    free(array);
    return 2;
   }
   array[i]=element->next;
   element->next=((void *)0);
  }
  {
   struct cbor_arr_t a = {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=length,
    .array=array,
   }; struct cbor_arr_t *fresh = malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(array);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
  return 0;
 }
}

variable_types:
length
unsigned long

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:
i
unsigned long

variable_types: struct cbor_arr_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; struct cbor_t **array; } *

user_defined_types: struct cbor_arr_t { struct cbor_t base; unsigned long length; struct cbor_t **array; }


decompiled_code:
__int64 __fastcall cbor_store_arr(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
int *v5; // rbp
__int64 i; // r12
__int64 (__fastcall *v7)(int *, _QWORD, _QWORD); // r14
unsigned __int8 v8; // al
__int64 *v9; // rbx
__int64 v10; // rax
__int64 *v11; // rdx
_QWORD *v12; // rax
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v14; // [rsp+2h] [rbp-38h] BYREF
__int64 v15; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
if ( a2 == 31 )
{
v14 = 255;
v15 = 0LL;
v5 = &v14;
for ( i = 0LL; ; ++i )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
v7 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v8 = cbor_additional_of(buf);
result = v7(v5, v8, a3);
if ( (_DWORD)result )
return result;
v5 = (int *)*((_QWORD *)v5 + 1);
}
v9 = (__int64 *)malloc(8 * i);
if ( v9 )
{
v10 = v15;
if ( v15 )
{
v11 = v9;
do
{
*v11++ = v10;
v10 = *(_QWORD *)(v10 + 8);
}
while ( v10 );
}
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 128;
v12[1] = 0LL;
v12[2] = i;
v12[3] = v9;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(v9);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = cbor_store_definite_arr(a1, a2, a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 a2, unsigned int a3)
{
__int64 result; // rax
int *v5; // rbp
__int64 i; // r12
__int64 (__fastcall *v7)(int *, _QWORD, _QWORD); // r14
unsigned __int8 v8; // al
__int64 *v9; // rbx
__int64 v10; // rax
__int64 *v11; // rdx
_QWORD *v12; // rax
unsigned __int8 buf; // [rsp+1h] [rbp-39h] BYREF
int v14; // [rsp+2h] [rbp-38h] BYREF
__int64 v15; // [rsp+Ah] [rbp-30h]

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
if ( a2 == 31 )
{
v14 = 255;
v15 = 0LL;
v5 = &v14;
for ( i = 0LL; ; ++i )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
v7 = (__int64 (__fastcall *)(int *, _QWORD, _QWORD))*(&cbor_store + (unsigned __int8)cbor_major_of(buf));
v8 = cbor_additional_of(buf);
result = v7(v5, v8, a3);
if ( (_DWORD)result )
return result;
v5 = (int *)*((_QWORD *)v5 + 1);
}
v9 = (__int64 *)malloc(8 * i);
if ( v9 )
{
v10 = v15;
if ( v15 )
{
v11 = v9;
do
{
*v11++ = v10;
v10 = *(_QWORD *)(v10 + 8);
}
while ( v10 );
}
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 128;
v12[1] = 0LL;
v12[2] = i;
v12[3] = v9;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(v9);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = func0(a1, a2, a3);
}
}
return result;
}

original_code:
int cbor_store_arr(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 cbor_store_definite_arr(storage,additional,stream);
 }
 {
  size_t total_length=0;
  struct cbor_t head= {
   .major=0xFF,
   .next=((void *)0),
  } , *element= &head;
  struct cbor_t**assembled,**assembled_index;
  while(1)
  {
   uint8_t item=0;
   int store_attempt_ret;
   if(read(stream,&item,sizeof item) < (ssize_t) sizeof item)return 3;
   if(item==0xff)break;
   if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (element,cbor_additional_of(item) ,stream) ) !=0)
   {
    return store_attempt_ret;
   }
   element=element->next;
   total_length++;
  }
  if( (assembled=malloc(total_length* (sizeof(struct cbor_t const * ) ) ) ) ==((void *)0))return 1;
  element= &head;
  assembled_index= assembled;
  while( (element=element->next) !=((void *)0))
  {
   *assembled_index= element;
   assembled_index++;
  }
  {
   struct cbor_arr_t a= {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=total_length,
    .array=assembled,
   } , *fresh= malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(assembled);
    return 1;
   }
   memcpy(fresh, &a,sizeof*fresh);
   storage->next=&fresh->base;
  }
 }
 return 0;
}

canonical_original_code:
int cbor_store_arr(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 cbor_store_definite_arr(storage,additional,stream);
 }
 {
  unsigned long total_length = 0;
  struct cbor_t head = {
   .major=0xFF,
   .next=((void *)0),
  }; struct cbor_t *element = &head;
  struct cbor_t **assembled; struct cbor_t **assembled_index;
  while(1)
  {
   unsigned char item = 0;
   int store_attempt_ret;
   if(read(stream,&item,sizeof item) < (long) sizeof item)return 3;
   if(item==0xff)break;
   if( (store_attempt_ret=cbor_store[cbor_major_of(item) ] (element,cbor_additional_of(item) ,stream) ) !=0)
   {
    return store_attempt_ret;
   }
   element=element->next;
   total_length++;
  }
  if( (assembled=malloc(total_length* (sizeof(struct cbor_t * ) ) ) ) ==((void *)0))return 1;
  element= &head;
  assembled_index= assembled;
  while( (element=element->next) !=((void *)0))
  {
   *assembled_index= element;
   assembled_index++;
  }
  {
   struct cbor_arr_t a = {
    .base= {
     .major=cbor_major_arr,
     .next=((void *)0),
    } ,
    .length=total_length,
    .array=assembled,
   }; struct cbor_arr_t *fresh = malloc(sizeof*fresh);
   if(fresh==((void *)0))
   {
    free(assembled);
    return 1;
   }
   memcpy(fresh, &a,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: struct cbor_arr_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; struct cbor_t **array; }


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


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

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

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

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


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

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
if ( a2 == 31 )
{
v15 = 255;
v16 = 0LL;
v5 = &v15;
for ( i = 0LL; ; i += *((_QWORD *)v5 + 2) )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of(buf) != 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;
}
ptr = (char *)malloc(i);
v8 = ptr;
if ( ptr )
{
for ( j = v16; j; j = (_QWORD *)j[1] )
{
v10 = (void *)j[3];
v11 = j[2];
memcpy(v8, v10, v11);
free(v10);
v8 += v11;
}
recursive_naive_cbor_free(v16);
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 64;
v12[1] = 0LL;
v12[2] = i;
v12[3] = ptr;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = store_definite_bstr(a1, a2, a3);
}
}
return result;
}

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

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
if ( a2 == 31 )
{
v15 = 255;
v16 = 0LL;
v5 = &v15;
for ( i = 0LL; ; i += *((_QWORD *)v5 + 2) )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of(buf) != 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;
}
ptr = (char *)malloc(i);
v8 = ptr;
if ( ptr )
{
for ( j = v16; j; j = (_QWORD *)j[1] )
{
v10 = (void *)j[3];
v11 = j[2];
memcpy(v8, v10, v11);
free(v10);
v8 += v11;
}
recursive_naive_cbor_free(v16);
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 64;
v12[1] = 0LL;
v12[2] = i;
v12[3] = ptr;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = func0(a1, a2, a3);
}
}
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)
{
__int64 result; // rax
int *v5; // r12
__int64 i; // rbx
unsigned __int8 v7; // al
_BYTE *v8; // r13
_QWORD *v9; // r12
void *v10; // r15
size_t v11; // r14
_QWORD *v12; // rax
_BYTE *ptr; // [rsp+0h] [rbp-60h]
unsigned __int8 buf; // [rsp+17h] [rbp-49h] BYREF
int v15; // [rsp+18h] [rbp-48h] BYREF
_QWORD *v16; // [rsp+20h] [rbp-40h]

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
if ( a2 == 31 )
{
v15 = 255;
v16 = 0LL;
v5 = &v15;
for ( i = 0LL; ; i += *((_QWORD *)v5 + 2) )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of(buf) != 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;
}
ptr = malloc(i + 4);
v8 = ptr;
if ( ptr )
{
v9 = v16;
if ( v16 )
{
do
{
v10 = (void *)v9[3];
v11 = v9[2];
memcpy(v8, v10, v11);
free(v10);
v8 += v11;
v9 = (_QWORD *)v9[1];
}
while ( v9 );
}
else
{
v8 = ptr;
}
*v8 = 0;
recursive_naive_cbor_free(v16);
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 96;
v12[1] = 0LL;
v12[2] = i;
v12[3] = ptr;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = store_definite_tstr(a1, a2, a3);
}
}
return result;
}

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

if ( !a1 )
return 2LL;
result = 2LL;
if ( !*(_QWORD *)(a1 + 8) )
{
if ( a2 == 31 )
{
v15 = 255;
v16 = 0LL;
v5 = &v15;
for ( i = 0LL; ; i += *((_QWORD *)v5 + 2) )
{
buf = 0;
if ( read(a3, &buf, 1uLL) <= 0 )
return 3LL;
if ( buf == 0xFF )
break;
if ( (unsigned __int8)cbor_major_of(buf) != 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;
}
ptr = malloc(i + 4);
v8 = ptr;
if ( ptr )
{
v9 = v16;
if ( v16 )
{
do
{
v10 = (void *)v9[3];
v11 = v9[2];
memcpy(v8, v10, v11);
free(v10);
v8 += v11;
v9 = (_QWORD *)v9[1];
}
while ( v9 );
}
else
{
v8 = ptr;
}
*v8 = 0;
recursive_naive_cbor_free(v16);
v12 = malloc(0x20uLL);
if ( v12 )
{
*(_DWORD *)v12 = 96;
v12[1] = 0LL;
v12[2] = i;
v12[3] = ptr;
*(_QWORD *)(a1 + 8) = v12;
result = 0LL;
}
else
{
free(ptr);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = func1(a1, a2, a3);
}
}
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


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; // rdx
_BOOL8 result; // rax
__int64 v6; // rbp

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; // rdx
_BOOL8 result; // rax
__int64 v6; // rbp

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

v1 = IP_host_bits(a1);
result = 66LL;
if ( v1 != 16 )
{
result = 65LL;
if ( v1 != 24 )
{
result = 0xFFFFFFFFLL;
if ( v1 == 8 )
result = 67LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
int v1; // edx
__int64 result; // rax

v1 = func1(a1);
result = 66LL;
if ( v1 != 16 )
{
result = 65LL;
if ( v1 != 24 )
{
result = 0xFFFFFFFFLL;
if ( v1 == 8 )
result = 67LL;
}
}
return result;
}

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; // ebp
char *v2; // rax
__int64 v3; // rbx

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

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

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

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)
{
char *v3; // rax
char *v4; // rbx
char *v5; // rax
const char *v6; // rbx
char *v7; // rax
__int64 v8; // rdi
char *v9; // rax
char *v10; // rax
int v12; // edi
char *v13; // rbp
char *v14; // rax
const char *v15; // rbp
int *v16; // rbx
char *v17; // r12
char *v18; // rax
int v19; // edi
char *v20; // rbx
char *v21; // rax
char *v22; // [rsp+8h] [rbp-20h] BYREF

v3 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Creating new socket\n", v3, "src/network/bsd-win-sock-new.c", 10LL);
v4 = 0LL;
if ( (int)Socket_startup() >= 0 )
{
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Mallocing Socket_T\n", v5, "src/network/bsd-win-sock-new.c", 14LL);
v4 = (char *)malloc(0x78uLL);
v22 = v4;
if ( v4 )
{
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);
*((_DWORD *)v22 + 1) = -1;
*(_DWORD *)v22 = -1;
v8 = (__int64)v22;
*((_QWORD *)v22 + 7) = 0LL;
*(_BYTE *)(v8 + 64) = 0;
*(_BYTE *)(v8 + 84) = 0;
*(_QWORD *)(v8 + 104) = a1;
*(_QWORD *)(v8 + 112) = 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 **)v22 + 13),
*((const char **)v22 + 14),
(const struct addrinfo *)(v22 + 8),
(struct addrinfo **)v22 + 7) )
{
Socket_set_errno(4294967292LL);
v15 = (const char *)Socket_strerror();
v16 = _errno_location();
v17 = "None";
if ( *v16 )
v17 = strerror(*v16);
v18 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Getaddrinfo failed: %s\n",
v18,
"src/network/bsd-win-sock-new.c",
38LL,
v17,
v15);
Socket_free(&v22);
v19 = *v16;
v20 = "None";
if ( v19 )
v20 = strerror(v19);
v21 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Socket creation failed\n",
v21,
"src/network/bsd-win-sock-new.c",
40LL,
v20);
v4 = 0LL;
}
else
{
v10 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket creation succeded\n", v10, "src/network/bsd-win-sock-new.c", 44LL);
v4 = v22;
}
}
else
{
Socket_set_errno(4294967293LL);
v12 = *_errno_location();
v13 = "None";
if ( v12 )
v13 = strerror(v12);
v14 = get_time();
fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) Malloc failed\n", v14, "src/network/bsd-win-sock-new.c", 19LL, v13);
}
}
return v4;
}

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

v3 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Creating new socket\n", v3, "src/network/bsd-win-sock-new.c", 10LL);
v4 = 0LL;
if ( (int)Socket_startup() >= 0 )
{
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Mallocing Socket_T\n", v5, "src/network/bsd-win-sock-new.c", 14LL);
v4 = (char *)malloc(0x78uLL);
v22 = v4;
if ( v4 )
{
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);
*((_DWORD *)v22 + 1) = -1;
*(_DWORD *)v22 = -1;
v8 = (__int64)v22;
*((_QWORD *)v22 + 7) = 0LL;
*(_BYTE *)(v8 + 64) = 0;
*(_BYTE *)(v8 + 84) = 0;
*(_QWORD *)(v8 + 104) = a1;
*(_QWORD *)(v8 + 112) = 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 **)v22 + 13),
*((const char **)v22 + 14),
(const struct addrinfo *)(v22 + 8),
(struct addrinfo **)v22 + 7) )
{
Socket_set_errno(4294967292LL);
v15 = (const char *)Socket_strerror();
v16 = _errno_location();
v17 = "None";
if ( *v16 )
v17 = strerror(*v16);
v18 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Getaddrinfo failed: %s\n",
v18,
"src/network/bsd-win-sock-new.c",
38LL,
v17,
v15);
Socket_free(&v22);
v19 = *v16;
v20 = "None";
if ( v19 )
v20 = strerror(v19);
v21 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Socket creation failed\n",
v21,
"src/network/bsd-win-sock-new.c",
40LL,
v20);
v4 = 0LL;
}
else
{
v10 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket creation succeded\n", v10, "src/network/bsd-win-sock-new.c", 44LL);
v4 = v22;
}
}
else
{
Socket_set_errno(4294967293LL);
v12 = *_errno_location();
v13 = "None";
if ( v12 )
v13 = strerror(v12);
v14 = func0();
fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) Malloc failed\n", v14, "src/network/bsd-win-sock-new.c", 19LL, v13);
}
}
return v4;
}

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 *


decompiled_code:
__int64 __fastcall Socket_send(int *a1, const char *a2, unsigned int a3)
{
__int64 v3; // r12
char *v4; // rax
unsigned int v5; // ebp
int v6; // ebx
int v7; // eax
char *v8; // rax
char *v9; // rax
char *v10; // rax
const char *v11; // rbp
int v12; // edi
char *v13; // rbx
char *v14; // rax
char *v15; // 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_10:
v15 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Send succeded\n", v15, "src/network/bsd-win-sock-send.c", 33LL);
}
else
{
v5 = v3;
v6 = 0;
while ( 1 )
{
v7 = send(*a1, &a2[v6], (int)v5, 0);
if ( v7 == -1 )
break;
v6 += v7;
v5 -= v7;
v8 = get_time();
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_10;
}
Socket_set_errno(4294967285LL);
v11 = (const char *)Socket_strerror();
v12 = *_errno_location();
v13 = "None";
if ( v12 )
v13 = strerror(v12);
v14 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Send failed: %s\n",
v14,
"src/network/bsd-win-sock-send.c",
29LL,
v13,
v11);
v6 = -1;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const char *a2, unsigned int a3)
{
__int64 v3; // r12
char *v4; // rax
unsigned int v5; // ebp
int v6; // ebx
int v7; // eax
char *v8; // rax
char *v9; // rax
char *v10; // rax
const char *v11; // rbp
int v12; // edi
char *v13; // rbx
char *v14; // rax
char *v15; // 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_10:
v15 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Send succeded\n", v15, "src/network/bsd-win-sock-send.c", 33LL);
}
else
{
v5 = v3;
v6 = 0;
while ( 1 )
{
v7 = send(*a1, &a2[v6], (int)v5, 0);
if ( v7 == -1 )
break;
v6 += v7;
v5 -= v7;
v8 = func0();
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_10;
}
Socket_set_errno(4294967285LL);
v11 = (const char *)Socket_strerror();
v12 = *_errno_location();
v13 = "None";
if ( v12 )
v13 = strerror(v12);
v14 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Send failed: %s\n",
v14,
"src/network/bsd-win-sock-send.c",
29LL,
v13,
v11);
v6 = -1;
}
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)
{
char *v2; // rax
char *v3; // rbx
unsigned int v4; // ebp
char *v5; // rax
int v6; // edi
char *v7; // rbx
char *v8; // rax
char *v10; // rax
int v11[3]; // [rsp+4h] [rbp-34h] BYREF
char v12; // [rsp+10h] [rbp-28h] BYREF

v11[0] = 8;
v11[1] = 16;
v11[2] = 24;
v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable Class for %lu hosts\n",
v2,
"src/subnetting/ip_util_total_hosts.c",
13LL,
a1);
v3 = (char *)v11;
do
{
v4 = *(_DWORD *)v3;
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---%d bits\n", v5, "src/subnetting/ip_util_total_hosts.c", 16LL, v4);
if ( max_hosts(v4) >= a1 )
{
v10 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Found with %d bits\n", v10, "src/subnetting/ip_util_total_hosts.c", 18LL, v4);
return v4;
}
v3 += 4;
}
while ( v3 != &v12 );
IP_set_strerror("Too many hosts: %lu", a1);
v6 = *_errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
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,
v7,
a1);
return (unsigned int)-1;
}

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

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

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; // rbp
__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; // rbp
__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; // rbp
__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; // rbp
__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);
}