decompiled_code:
__int64 __fastcall netapp_ping_send(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v11[41]; // [rsp+Fh] [rbp-29h] BYREF

v11[0] = -1;
v6 = tSLInformation[2];
v7 = UINT32_TO_STREAM_f(v6 + 9, *a1);
v8 = UINT32_TO_STREAM_f(v7, a2);
v9 = UINT32_TO_STREAM_f(v8, a3);
UINT32_TO_STREAM_f(v9, a4);
hci_command_send(8194LL, v6, 16LL);
SimpleLinkWaitEvent(8194LL, v11);
return v11[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v11[41]; // [rsp+Fh] [rbp-29h] BYREF

v11[0] = -1;
v6 = tSLInformation[2];
v7 = UINT32_TO_STREAM_f(v6 + 9, *a1);
v8 = UINT32_TO_STREAM_f(v7, a2);
v9 = UINT32_TO_STREAM_f(v8, a3);
UINT32_TO_STREAM_f(v9, a4);
hci_command_send(8194LL, v6, 16LL);
SimpleLinkWaitEvent(8194LL, v11);
return v11[0];
}

original_code:
long
netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout)
{
 signed char scRet;
 unsigned char *ptr, *args;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 args = (UINT32_TO_STREAM_f(args, *ip));
 args = (UINT32_TO_STREAM_f(args, ulPingAttempts));
 args = (UINT32_TO_STREAM_f(args, ulPingSize));
 args = (UINT32_TO_STREAM_f(args, ulPingTimeout));
 hci_command_send((0x0002 + 0x2000), ptr, (16));
 SimpleLinkWaitEvent((0x0002 + 0x2000), &scRet);
 return(scRet);
}

canonical_original_code:
long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout)
{
 char scRet;
 unsigned char *ptr; unsigned char *args;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 args = (ptr + ((5) + (4)));
 args = (UINT32_TO_STREAM_f(args, *ip));
 args = (UINT32_TO_STREAM_f(args, ulPingAttempts));
 args = (UINT32_TO_STREAM_f(args, ulPingSize));
 args = (UINT32_TO_STREAM_f(args, ulPingTimeout));
 hci_command_send((0x0002 + 0x2000), ptr, (16));
 SimpleLinkWaitEvent((0x0002 + 0x2000), &scRet);
 return(scRet);
}

variable_types:
ip
unsigned long *

variable_types:
ulPingAttempts
unsigned long

variable_types:
ulPingSize
unsigned long

variable_types:
ulPingTimeout
unsigned long


decompiled_code:
__int64 netapp_ping_report()
{
__int64 v0; // rsi
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = tSLInformation[2];
v2[0] = -1;
hci_command_send(8195LL, v0, 0LL);
return SimpleLinkWaitEvent(8195LL, v2);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rsi
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = tSLInformation[2];
v2[0] = -1;
hci_command_send(8195LL, v0, 0LL);
return SimpleLinkWaitEvent(8195LL, v2);
}

original_code:
void netapp_ping_report()
{
 unsigned char *ptr;
 ptr = tSLInformation.pucTxCommandBuffer;
 signed char scRet;
 scRet = -1;
 hci_command_send((0x0003 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0003 + 0x2000), &scRet);
}

canonical_original_code:
void netapp_ping_report()
{
 unsigned char *ptr;
 ptr = tSLInformation.pucTxCommandBuffer;
 char scRet;
 scRet = -1;
 hci_command_send((0x0003 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0003 + 0x2000), &scRet);
}

variable_types:
ptr
unsigned char *

variable_types: scRet char

return_type: void


decompiled_code:
__int64 netapp_ping_stop()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

v1[0] = -1;
hci_command_send(8196LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(8196LL, v1);
return v1[0];
}

canonical_decompiled_code:
__int64 func5()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

v1[0] = -1;
hci_command_send(8196LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(8196LL, v1);
return v1[0];
}

original_code:
long netapp_ping_stop()
{
 signed char scRet;
 unsigned char *ptr;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0004 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0004 + 0x2000), &scRet);
 return(scRet);
}

canonical_original_code:
long netapp_ping_stop()
{
 char scRet;
 unsigned char *ptr;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0004 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0004 + 0x2000), &scRet);
 return(scRet);
}

return_type: long


decompiled_code:
__int64 __fastcall netapp_ipconfig(__int64 a1)
{
hci_command_send(8197LL, tSLInformation[2], 0LL);
return SimpleLinkWaitEvent(8197LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
hci_command_send(8197LL, tSLInformation[2], 0LL);
return SimpleLinkWaitEvent(8197LL, a1);
}

original_code:
void netapp_ipconfig( tNetappIpconfigRetArgs * ipconfig )
{
 unsigned char *ptr;
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0005 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0005 + 0x2000), ipconfig );
}

canonical_original_code:
void netapp_ipconfig(struct _netapp_ipconfig_ret_args_t *ipconfig)
{
 unsigned char *ptr;
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0005 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0005 + 0x2000), ipconfig );
}

variable_types: struct _netapp_ipconfig_ret_args_t { unsigned char aucIP[4]; unsigned char aucSubnetMask[4]; unsigned char aucDefaultGateway[4]; unsigned char aucDHCPServer[4]; unsigned char aucDNSServer[4]; unsigned char uaMacAddr[6]; unsigned char uaSSID[32]; } *


decompiled_code:
__int64 netapp_arp_flush()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

v1[0] = -1;
hci_command_send(8198LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(8198LL, v1);
return v1[0];
}

canonical_decompiled_code:
__int64 func7()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

v1[0] = -1;
hci_command_send(8198LL, tSLInformation[2], 0LL);
SimpleLinkWaitEvent(8198LL, v1);
return v1[0];
}

original_code:
long netapp_arp_flush(void)
{
 signed char scRet;
 unsigned char *ptr;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0006 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0006 + 0x2000), &scRet);
 return(scRet);
}

canonical_original_code:
long netapp_arp_flush()
{
 char scRet;
 unsigned char *ptr;
 scRet = -1;
 ptr = tSLInformation.pucTxCommandBuffer;
 hci_command_send((0x0006 + 0x2000), ptr, 0);
 SimpleLinkWaitEvent((0x0006 + 0x2000), &scRet);
 return(scRet);
}


decompiled_code:
__int64 __fastcall netapp_set_debug_level(__int64 a1)
{
__int64 v1; // rbx
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

v3[0] = -1;
v1 = tSLInformation[2];
UINT32_TO_STREAM_f(v1 + 9, a1);
hci_command_send(8200LL, v1, 4LL);
SimpleLinkWaitEvent(8200LL, v3);
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

v3[0] = -1;
v1 = tSLInformation[2];
UINT32_TO_STREAM_f(v1 + 9, a1);
hci_command_send(8200LL, v1, 4LL);
SimpleLinkWaitEvent(8200LL, v3);
return v3[0];
}

original_code:
long netapp_set_debug_level(unsigned long ulLevel)
{
 signed char scRet;
    unsigned char *ptr, *args;
    scRet = -1;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + ((5) + (4)));
    args = (UINT32_TO_STREAM_f(args, ulLevel));
    hci_command_send((0x0008 + 0x2000), ptr, (4));
 SimpleLinkWaitEvent((0x0008 + 0x2000), &scRet);
    return(scRet);
}

canonical_original_code:
long netapp_set_debug_level(unsigned long ulLevel)
{
 char scRet;
    unsigned char *ptr; unsigned char *args;
    scRet = -1;
    ptr = tSLInformation.pucTxCommandBuffer;
    args = (ptr + ((5) + (4)));
    args = (UINT32_TO_STREAM_f(args, ulLevel));
    hci_command_send((0x0008 + 0x2000), ptr, (4));
 SimpleLinkWaitEvent((0x0008 + 0x2000), &scRet);
    return(scRet);
}

variable_types:
ulLevel
unsigned long

variable_types:
args
unsigned char *


decompiled_code:
__int64 __fastcall STREAM_TO_UINT16_f(__int64 a1, unsigned __int16 a2, int a3)
{
int v3; // eax

LOWORD(v3) = *(char *)(a1 + a2 + 1);
LOWORD(a3) = *(char *)(a1 + a2);
return (unsigned int)(a3 + (v3 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int16 a2, int a3)
{
int v3; // eax

LOWORD(v3) = *(char *)(a1 + a2 + 1);
LOWORD(a3) = *(char *)(a1 + a2);
return (unsigned int)(a3 + (v3 << 8));
}

original_code:
unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset)
{
        return (unsigned short)((unsigned short)((unsigned short)
        (*(p + offset + 1)) << 8) + (unsigned short)(*(p + offset)));
}

canonical_original_code:
unsigned short STREAM_TO_UINT16_f(char *p, unsigned short offset)
{
        return (unsigned short)((unsigned short)((unsigned short)
        (*(p + offset + 1)) << 8) + (unsigned short)(*(p + offset)));
}

variable_types:
p
char *

variable_types:
offset
unsigned short

return_type: unsigned short


original_code:
unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset)
{
        return (unsigned long)((unsigned long)((unsigned long)
        (*(p + offset + 3)) << 24) + (unsigned long)((unsigned long)
        (*(p + offset + 2)) << 16) + (unsigned long)((unsigned long)
        (*(p + offset + 1)) << 8) + (unsigned long)(*(p + offset)));
}

canonical_original_code:
unsigned long STREAM_TO_UINT32_f(char *p, unsigned short offset)
{
        return (unsigned long)((unsigned long)((unsigned long)
        (*(p + offset + 3)) << 24) + (unsigned long)((unsigned long)
        (*(p + offset + 2)) << 16) + (unsigned long)((unsigned long)
        (*(p + offset + 1)) << 8) + (unsigned long)(*(p + offset)));
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall hci_command_send(unsigned __int16 a1, __int64 a2, unsigned __int8 a3)
{
*(_BYTE *)(a2 + 5) = 1;
*(_BYTE *)UINT16_TO_STREAM_f(a2 + 6, a1) = a3;
SpiWrite(a2, (unsigned int)a3 + 4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1, __int64 a2, unsigned __int8 a3)
{
*(_BYTE *)(a2 + 5) = 1;
*(_BYTE *)UINT16_TO_STREAM_f(a2 + 6, a1) = a3;
SpiWrite(a2, (unsigned int)a3 + 4);
return 0LL;
}

original_code:
unsigned short
hci_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength)
{
 unsigned char *stream;
 stream = (pucBuff + (5));
 {*(stream)++ = (0x1);};
 stream = (UINT16_TO_STREAM_f(stream, usOpcode));
 {*(stream)++ = (ucArgsLength);};
 SpiWrite(pucBuff, ucArgsLength + (4));
 return(0);
}

variable_types:
usOpcode
unsigned short

variable_types:
pucBuff
unsigned char *

variable_types:
ucArgsLength
unsigned char

variable_types:
stream
unsigned char *


decompiled_code:
__int64 __fastcall hci_data_send(char a1, _BYTE *a2, __int16 a3, __int16 a4, __int64 a5, __int16 a6)
{
unsigned __int16 v6; // bx

a2[5] = 2;
a2[6] = a1;
a2[7] = a3;
v6 = a4 + a6 + a3;
UINT16_TO_STREAM_f(a2 + 8, v6);
SpiWrite(a2, (unsigned __int16)(v6 + 5));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, _BYTE *a2, __int16 a3, __int16 a4, __int64 a5, __int16 a6)
{
unsigned __int16 v6; // bx

a2[5] = 2;
a2[6] = a1;
a2[7] = a3;
v6 = a4 + a6 + a3;
UINT16_TO_STREAM_f(a2 + 8, v6);
SpiWrite(a2, (unsigned __int16)(v6 + 5));
return 0LL;
}

original_code:
long
hci_data_send(unsigned char ucOpcode,
       unsigned char *ucArgs,
       unsigned short usArgsLength,
       unsigned short usDataLength,
       const unsigned char *ucTail,
       unsigned short usTailLength)
{
    ucTail=ucTail;
    unsigned char *stream;
 stream = ((ucArgs) + (5));
 {*(stream)++ = (0x2);};
 {*(stream)++ = (ucOpcode);};
 {*(stream)++ = (usArgsLength);};
 stream = (UINT16_TO_STREAM_f(stream, usArgsLength + usDataLength + usTailLength));
 SpiWrite(ucArgs, (5) + usArgsLength + usDataLength + usTailLength);
 return(0);
}

canonical_original_code:
long hci_data_send(unsigned char ucOpcode, unsigned char *ucArgs, unsigned short usArgsLength, unsigned short usDataLength, unsigned char *ucTail, unsigned short usTailLength)
{
    ucTail=ucTail;
    unsigned char *stream;
 stream = ((ucArgs) + (5));
 {*(stream)++ = (0x2);};
 {*(stream)++ = (ucOpcode);};
 {*(stream)++ = (usArgsLength);};
 stream = (UINT16_TO_STREAM_f(stream, usArgsLength + usDataLength + usTailLength));
 SpiWrite(ucArgs, (5) + usArgsLength + usDataLength + usTailLength);
 return(0);
}

variable_types:
ucOpcode
unsigned char

variable_types:
ucArgs
unsigned char *

variable_types:
usArgsLength
unsigned short

variable_types:
usDataLength
unsigned short

variable_types:
ucTail
unsigned char *

variable_types:
usTailLength
unsigned short


decompiled_code:
__int64 __fastcall hci_data_command_send(char a1, _BYTE *a2, unsigned __int8 a3, __int16 a4)
{
unsigned __int16 v4; // bx

a2[5] = 2;
a2[6] = a1;
a2[7] = a3;
v4 = a3 + a4;
UINT16_TO_STREAM_f(a2 + 8, v4);
return SpiWrite(a2, (unsigned __int16)(v4 + 5));
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, _BYTE *a2, unsigned __int8 a3, __int16 a4)
{
unsigned __int16 v4; // bx

a2[5] = 2;
a2[6] = a1;
a2[7] = a3;
v4 = a3 + a4;
UINT16_TO_STREAM_f(a2 + 8, v4);
return SpiWrite(a2, (unsigned __int16)(v4 + 5));
}

original_code:
void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff,
                     unsigned char ucArgsLength,unsigned short ucDataLength)
{
  unsigned char *stream = (pucBuff + (5));
 {*(stream)++ = (0x2);};
 {*(stream)++ = (usOpcode);};
 {*(stream)++ = (ucArgsLength);};
 stream = (UINT16_TO_STREAM_f(stream, ucArgsLength + ucDataLength));
 SpiWrite(pucBuff, ucArgsLength + ucDataLength + (5));
 return;
}

canonical_original_code:
void hci_data_command_send(unsigned short usOpcode, unsigned char *pucBuff, unsigned char ucArgsLength, unsigned short ucDataLength)
{
  unsigned char *stream = (pucBuff + (5));
 {*(stream)++ = (0x2);};
 {*(stream)++ = (usOpcode);};
 {*(stream)++ = (ucArgsLength);};
 stream = (UINT16_TO_STREAM_f(stream, ucArgsLength + ucDataLength));
 SpiWrite(pucBuff, ucArgsLength + ucDataLength + (5));
 return;
}

variable_types:
ucDataLength
unsigned short


original_code:
void
hci_patch_send(unsigned char ucOpcode, unsigned char *pucBuff, char *patch, unsigned short usDataLength)
{
  unsigned char *data_ptr = (pucBuff + (5));
 unsigned short usTransLength;
 unsigned char *stream = (pucBuff + (5));
 {*(stream)++ = (0x3);};
 {*(stream)++ = (ucOpcode);};
 stream = (UINT16_TO_STREAM_f(stream, usDataLength + (2)));
 if (usDataLength <= (1000))
 {
  (UINT16_TO_STREAM_f(stream, usDataLength));
  stream = (UINT16_TO_STREAM_f(stream, usDataLength));
  memcpy((pucBuff + (5)) + (6), patch, usDataLength);
  SpiWrite(pucBuff, usDataLength + (6));
 }
 else
 {
  usTransLength = (usDataLength/(1000));
  (UINT16_TO_STREAM_f(stream, usDataLength + (2) + usTransLength*(2)));
  stream = (UINT16_TO_STREAM_f(stream, (1000)));
  memcpy(pucBuff + (5) + (6), patch, (1000));
  usDataLength -= (1000);
  patch += (1000);
  SpiWrite(pucBuff, (1000) + (6));
  while (usDataLength)
  {
   if (usDataLength <= (1000))
   {
    usTransLength = usDataLength;
    usDataLength = 0;
   }
   else
   {
    usTransLength = (1000);
    usDataLength -= usTransLength;
   }
   *(unsigned short *)data_ptr = usTransLength;
   memcpy(data_ptr + (2), patch, usTransLength);
   patch += usTransLength;
   SpiWrite((unsigned char *)data_ptr, usTransLength + sizeof(usTransLength));
  }
 }
}

variable_types:
patch
char *

variable_types:
usTransLength
unsigned short


repo: ontologiae/IsaacOS

decompiled_code:
__int64 __fastcall do_syscalls(unsigned int a1)
{
int v1; // ebx
int v2; // eax
__int64 result; // rax
const char *v4; // [rsp+8h] [rbp-10h]

if ( a1 != 1 )
return printk("unknown syscall %d\n", a1);
LODWORD(v4) = v1;
v2 = 100000;
do
--v2;
while ( v2 );
_disable();
result = printk(v4);
_enable();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // ebx
int v2; // eax
__int64 result; // rax
const char *v4; // [rsp+8h] [rbp-10h]

if ( a1 != 1 )
return printk("unknown syscall %d\n", a1);
LODWORD(v4) = v1;
v2 = 100000;
do
--v2;
while ( v2 );
_disable();
result = printk(v4);
_enable();
return result;
}

original_code:
void do_syscalls(int sys_num)
{
 char *u_str;
 int i;
 if (sys_num == 1) {
  asm("mov %%ebx, %0": "=m"(u_str) :);
  for (i = 0; i < 100000; i++);
  asm("cli"::);
  printk(u_str);
  asm("sti"::);
 } else {
  printk("unknown syscall %d\n", sys_num);
 }
 return;
}

variable_types: i int


strlen

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // ecx

if ( !*a1 )
return 0;
v1 = a1 + 1;
do
v2 = (_DWORD)v1++ - (_DWORD)a1;
while ( *(v1 - 1) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // ecx

if ( !*a1 )
return 0;
v1 = a1 + 1;
do
v2 = (_DWORD)v1++ - (_DWORD)a1;
while ( *(v1 - 1) );
return v2;
}

original_code:
int strlen(char *s)
{
 int i = 0;
 while (*s++)
  i++;
 return i;
}

variable_types:
s
char *

return_type: int


itoa

decompiled_code:
unsigned __int64 __fastcall itoa(_BYTE *a1, unsigned __int64 a2, int a3)
{
_BYTE *v3; // r9
int i; // ecx
char v5; // al
unsigned __int64 result; // rax
__int64 v7; // rdx
char v8; // cl

v3 = a1;
for ( i = 0; ; ++i )
{
v5 = a2 % a3 + 87;
if ( a2 % a3 <= 9 )
v5 = a2 % a3 + 48;
*v3 = v5;
result = a2 / a3;
++v3;
if ( a3 > a2 )
break;
a2 /= (unsigned __int64)a3;
}
a1[i + 1] = 0;
if ( i > 0 )
{
result = i;
v7 = 0LL;
do
{
v8 = a1[v7];
a1[v7] = a1[result];
a1[result] = v8;
++v7;
--result;
}
while ( (int)v7 < (int)result );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_BYTE *a1, unsigned __int64 a2, int a3)
{
_BYTE *v3; // r9
int i; // ecx
char v5; // al
unsigned __int64 result; // rax
__int64 v7; // rdx
char v8; // cl

v3 = a1;
for ( i = 0; ; ++i )
{
v5 = a2 % a3 + 87;
if ( a2 % a3 <= 9 )
v5 = a2 % a3 + 48;
*v3 = v5;
result = a2 / a3;
++v3;
if ( a3 > a2 )
break;
a2 /= (unsigned __int64)a3;
}
a1[i + 1] = 0;
if ( i > 0 )
{
result = i;
v7 = 0LL;
do
{
v8 = a1[v7];
a1[v7] = a1[result];
a1[result] = v8;
++v7;
--result;
}
while ( (int)v7 < (int)result );
}
return result;
}

original_code:
void itoa(char *buf, unsigned long int n, int base)
{
 unsigned long int tmp;
 int i, j;
 tmp = n;
 i = 0;
 do {
  tmp = n % base;
  buf[i++] = (tmp < 10) ? (tmp + '0') : (tmp + 'a' - 10);
 } while (n /= base);
 buf[i--] = 0;
 for (j = 0; j < i; j++, i--) {
  tmp = buf[j];
  buf[j] = buf[i];
  buf[i] = tmp;
 }
}

canonical_original_code:
void itoa(char *buf, unsigned long n, int base)
{
 unsigned long tmp;
 int i; int j;
 tmp = n;
 i = 0;
 do {
  tmp = n % base;
  buf[i++] = (tmp < 10) ? (tmp + '0') : (tmp + 'a' - 10);
 } while (n /= base);
 buf[i--] = 0;
 for (j = 0; j < i; j++, i--) {
  tmp = buf[j];
  buf[j] = buf[i];
  buf[i] = tmp;
 }
}

variable_types:
buf
char *

variable_types:
n
unsigned long

variable_types: base int

variable_types:
tmp
unsigned long

variable_types: j int


decompiled_code:
__int64 isr_default_int()
{
return printk("interrupt\n");
}

canonical_decompiled_code:
__int64 func0()
{
return printk("interrupt\n");
}

original_code:
void isr_default_int(void)
{
 printk("interrupt\n");
}

canonical_original_code:
void isr_default_int()
{
 printk("interrupt\n");
}


decompiled_code:
void __noreturn isr_GP_exc()
{
printk("#GP\n");
__halt();
}

canonical_decompiled_code:
void __noreturn func1()
{
printk("#GP\n");
__halt();
}

original_code:
void isr_GP_exc(void)
{
 printk("#GP\n");
 asm("hlt");
}

canonical_original_code:
void isr_GP_exc()
{
 printk("#GP\n");
 asm("hlt");
}


decompiled_code:
void __fastcall __noreturn isr_PF_exc()
{
int v0; // ebp
unsigned __int64 v1; // rax
unsigned int v2; // [rsp+8h] [rbp-10h]

v2 = *(_DWORD *)(unsigned int)(v0 + 60);
v1 = __readcr2();
printk("#PF on eip: %p. cr2: %p\n", (const void *)v2, (const void *)(unsigned int)v1);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func2()
{
int v0; // ebp
unsigned __int64 v1; // rax
unsigned int v2; // [rsp+8h] [rbp-10h]

v2 = *(_DWORD *)(unsigned int)(v0 + 60);
v1 = __readcr2();
printk("#PF on eip: %p. cr2: %p\n", (const void *)v2, (const void *)(unsigned int)v1);
__halt();
}

original_code:
void isr_PF_exc(void)
{
 u32 faulting_addr;
 u32 eip;
  asm(" 	movl 60(%%ebp), %%eax;     		mov %%eax, %0;         		mov %%cr2, %%eax;      		mov %%eax, %1": "=m"(eip), "=m"(faulting_addr): );
 printk("#PF on eip: %p. cr2: %p\n", eip, faulting_addr);
 asm("hlt");
}

canonical_original_code:
void isr_PF_exc()
{
 unsigned int faulting_addr;
 unsigned int eip;
  asm(" 	movl 60(%%ebp), %%eax;     		mov %%eax, %0;         		mov %%cr2, %%eax;      		mov %%eax, %1": "=m"(eip), "=m"(faulting_addr): );
 printk("#PF on eip: %p. cr2: %p\n", eip, faulting_addr);
 asm("hlt");
}

variable_types:
eip
unsigned int


original_code:
void isr_clock_int(void)
{
 static int tic = 0;
 static int sec = 0;
 tic++;
 if (tic % 100 == 0) {
  sec++;
  tic = 0;
 }
 schedule();
}

canonical_original_code:
void isr_clock_int()
{
 static int tic = 0;
 static int sec = 0;
 tic++;
 if (tic % 100 == 0) {
  sec++;
  tic = 0;
 }
 schedule();
}

variable_types: tic int

variable_types: sec int


decompiled_code:
unsigned __int8 isr_kbd_int()
{
unsigned __int8 v0; // al
unsigned __int8 result; // al
unsigned __int8 v2; // dl

do
v0 = __inbyte(0x64u);
while ( (v0 & 1) == 0 );
result = __inbyte(0x60u);
v2 = result - 1;
if ( (char)(result - 1) < 0 )
{
if ( result == 0xAA )
{
lshift_enable_3 = 0;
}
else if ( result == 0xB6 )
{
rshift_enable_2 = 0;
}
}
else
{
if ( result == 54 )
{
rshift_enable_2 = 1;
return result;
}
if ( v2 > 0x35u )
{
if ( result != 56 )
return putcar((unsigned __int8)kbdmap[4 * v2 + (__PAIR64__(lshift_enable_3, rshift_enable_2) != 0)]);
}
else if ( result != 29 )
{
if ( result == 42 )
{
lshift_enable_3 = 1;
return result;
}
return putcar((unsigned __int8)kbdmap[4 * v2 + (__PAIR64__(lshift_enable_3, rshift_enable_2) != 0)]);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int8 func4()
{
unsigned __int8 v0; // al
unsigned __int8 result; // al
unsigned __int8 v2; // dl

do
v0 = __inbyte(0x64u);
while ( (v0 & 1) == 0 );
result = __inbyte(0x60u);
v2 = result - 1;
if ( (char)(result - 1) < 0 )
{
if ( result == 0xAA )
{
lshift_enable_3 = 0;
}
else if ( result == 0xB6 )
{
rshift_enable_2 = 0;
}
}
else
{
if ( result == 54 )
{
rshift_enable_2 = 1;
return result;
}
if ( v2 > 0x35u )
{
if ( result != 56 )
return putcar((unsigned __int8)kbdmap[4 * v2 + (__PAIR64__(lshift_enable_3, rshift_enable_2) != 0)]);
}
else if ( result != 29 )
{
if ( result == 42 )
{
lshift_enable_3 = 1;
return result;
}
return putcar((unsigned __int8)kbdmap[4 * v2 + (__PAIR64__(lshift_enable_3, rshift_enable_2) != 0)]);
}
}
return result;
}

original_code:
void isr_kbd_int(void)
{
 uchar i;
 static int lshift_enable;
 static int rshift_enable;
 static int alt_enable;
 static int ctrl_enable;
 do {
  i = ({ unsigned char _v; asm volatile ("inb %%dx, %%al" : "=a" (_v) : "d" (0x64)); _v; });
 } while ((i & 0x01) == 0);
 i = ({ unsigned char _v; asm volatile ("inb %%dx, %%al" : "=a" (_v) : "d" (0x60)); _v; });
 i--;
 if (i < 0x80) {
  switch (i) {
  case 0x29:
   lshift_enable = 1;
   break;
  case 0x35:
   rshift_enable = 1;
   break;
  case 0x1C:
   ctrl_enable = 1;
   break;
  case 0x37:
   alt_enable = 1;
   break;
  default:
   putcar(kbdmap
          [i * 4 + (lshift_enable || rshift_enable)]);
  }
 } else {
  i -= 0x80;
  switch (i) {
  case 0x29:
   lshift_enable = 0;
   break;
  case 0x35:
   rshift_enable = 0;
   break;
  case 0x1C:
   ctrl_enable = 0;
   break;
  case 0x37:
   alt_enable = 0;
   break;
  }
 }
}

canonical_original_code:
void isr_kbd_int()
{
 unsigned char i;
 static int lshift_enable;
 static int rshift_enable;
 static int alt_enable;
 static int ctrl_enable;
 do {
  i = ({ unsigned char _v; asm volatile ("inb %%dx, %%al" : "=a" (_v) : "d" (0x64)); _v; });
 } while ((i & 0x01) == 0);
 i = ({ unsigned char _v; asm volatile ("inb %%dx, %%al" : "=a" (_v) : "d" (0x60)); _v; });
 i--;
 if (i < 0x80) {
  switch (i) {
  case 0x29:
   lshift_enable = 1;
   break;
  case 0x35:
   rshift_enable = 1;
   break;
  case 0x1C:
   ctrl_enable = 1;
   break;
  case 0x37:
   alt_enable = 1;
   break;
  default:
   putcar(kbdmap
          [i * 4 + (lshift_enable || rshift_enable)]);
  }
 } else {
  i -= 0x80;
  switch (i) {
  case 0x29:
   lshift_enable = 0;
   break;
  case 0x35:
   rshift_enable = 0;
   break;
  case 0x1C:
   ctrl_enable = 0;
   break;
  case 0x37:
   alt_enable = 0;
   break;
  }
 }
}

variable_types:
i
unsigned char


scrollup

decompiled_code:
char __fastcall scrollup(int a1)
{
_BYTE *v1; // rdx
__int64 i; // rax
char result; // al

v1 = (_BYTE *)((unsigned int)(160 * a1) + 753664LL);
for ( i = 753664LL; i != 757664; i += 2LL )
{
if ( (unsigned __int64)v1 > 0xB8F9F )
{
*(_BYTE *)i = 0;
*(_BYTE *)(i + 1) = 7;
}
else
{
*(_BYTE *)i = *v1;
*(_BYTE *)(i + 1) = v1[1];
}
v1 += 2;
}
result = kY - a1;
if ( (char)(kY - a1) < 0 )
result = 0;
kY = result;
return result;
}

canonical_decompiled_code:
char __fastcall func0(int a1)
{
_BYTE *v1; // rdx
__int64 i; // rax
char result; // al

v1 = (_BYTE *)((unsigned int)(160 * a1) + 753664LL);
for ( i = 753664LL; i != 757664; i += 2LL )
{
if ( (unsigned __int64)v1 > 0xB8F9F )
{
*(_BYTE *)i = 0;
*(_BYTE *)(i + 1) = 7;
}
else
{
*(_BYTE *)i = *v1;
*(_BYTE *)(i + 1) = v1[1];
}
v1 += 2;
}
result = kY - a1;
if ( (char)(kY - a1) < 0 )
result = 0;
kY = result;
return result;
}

original_code:
void scrollup(unsigned int n)
{
 unsigned char *video, *tmp;
 for (video = (unsigned char *) 0xB8000;
      video < (unsigned char *) 0xB8FA0; video += 2) {
  tmp = (unsigned char *) (video + n * 160);
  if (tmp < (unsigned char *) 0xB8FA0) {
   *video = *tmp;
   *(video + 1) = *(tmp + 1);
  } else {
   *video = 0;
   *(video + 1) = 0x07;
  }
 }
 kY -= n;
 if (kY < 0)
  kY = 0;
}

canonical_original_code:
void scrollup(unsigned int n)
{
 unsigned char *video; unsigned char *tmp;
 for (video = (unsigned char *) 0xB8000;
      video < (unsigned char *) 0xB8FA0; video += 2) {
  tmp = (unsigned char *) (video + n * 160);
  if (tmp < (unsigned char *) 0xB8FA0) {
   *video = *tmp;
   *(video + 1) = *(tmp + 1);
  } else {
   *video = 0;
   *(video + 1) = 0x07;
  }
 }
 kY -= n;
 if (kY < 0)
  kY = 0;
}

variable_types:
n
unsigned int

variable_types:
video
unsigned char *

variable_types:
tmp
unsigned char *


putcar

decompiled_code:
void __fastcall putcar(char a1)
{
_BYTE *v1; // rax

switch ( a1 )
{
case 10:
kX = 0;
++kY;
break;
case 9:
kX = kX + 8 - kX % 8;
break;
case 13:
kX = 0;
break;
default:
v1 = (_BYTE *)(2 * (kX + 80 * kY + 376832));
*v1 = a1;
v1[1] = kattr;
if ( (char)(kX + 1) > 79 )
{
kX = 0;
++kY;
}
else
{
++kX;
}
break;
}
if ( kY > 24 )
scrollup(kY - 24);
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
_BYTE *v1; // rax

switch ( a1 )
{
case 10:
kX = 0;
++kY;
break;
case 9:
kX = kX + 8 - kX % 8;
break;
case 13:
kX = 0;
break;
default:
v1 = (_BYTE *)(2 * (kX + 80 * kY + 376832));
*v1 = a1;
v1[1] = kattr;
if ( (char)(kX + 1) > 79 )
{
kX = 0;
++kY;
}
else
{
++kX;
}
break;
}
if ( kY > 24 )
func0(kY - 24);
}

original_code:
void putcar(uchar c)
{
 unsigned char *video;
 if (c == 10) {
  kX = 0;
  kY++;
 } else if (c == 9) {
  kX = kX + 8 - (kX % 8);
 } else if (c == 13) {
  kX = 0;
 } else {
  video = (unsigned char *) (0xB8000 + 2 * kX + 160 * kY);
  *video = c;
  *(video + 1) = kattr;
  kX++;
  if (kX > 79) {
   kX = 0;
   kY++;
  }
 }
 if (kY > 24)
  scrollup(kY - 24);
}

canonical_original_code:
void putcar(unsigned char c)
{
 unsigned char *video;
 if (c == 10) {
  kX = 0;
  kY++;
 } else if (c == 9) {
  kX = kX + 8 - (kX % 8);
 } else if (c == 13) {
  kX = 0;
 } else {
  video = (unsigned char *) (0xB8000 + 2 * kX + 160 * kY);
  *video = c;
  *(video + 1) = kattr;
  kX++;
  if (kX > 79) {
   kX = 0;
   kY++;
  }
 }
 if (kY > 24)
  scrollup(kY - 24);
}

variable_types:
c
unsigned char


dump

decompiled_code:
void __fastcall dump(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
unsigned __int8 v3; // al
char v4; // bp

if ( a2 )
{
v2 = a1;
do
{
v3 = *v2;
v4 = byte_1C6[*v2++ & 0xF];
putcar(byte_1C6[v3 >> 4]);
putcar(v4);
}
while ( v2 != &a1[a2] );
}
}

canonical_decompiled_code:
void __fastcall func2(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
unsigned __int8 v3; // al
char v4; // bp

if ( a2 )
{
v2 = a1;
do
{
v3 = *v2;
v4 = byte_1C6[*v2++ & 0xF];
func1(byte_1C6[v3 >> 4]);
func1(v4);
}
while ( v2 != &a1[a2] );
}
}

original_code:
void dump(uchar* addr, int n)
{
 char c1, c2;
 char *tab = "0123456789ABCDEF";
 while(n--) {
  c1 = tab[(*addr & 0xF0)>>4];
  c2 = tab[*addr & 0x0F];
  addr++;
  putcar(c1);
  putcar(c2);
 }
}

canonical_original_code:
void dump(unsigned char *addr, int n)
{
 char c1; char c2;
 char *tab = "0123456789ABCDEF";
 while(n--) {
  c1 = tab[(*addr & 0xF0)>>4];
  c2 = tab[*addr & 0x0F];
  addr++;
  putcar(c1);
  putcar(c2);
 }
}

variable_types:
addr
unsigned char *

variable_types: n int

variable_types:
tab
char *


decompiled_code:
__int16 __fastcall move_cursor(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int16 v2; // di
__int16 result; // ax

v2 = 80 * a2 + a1;
__outbyte(0x3D4u, 0xFu);
__outbyte(0x3D5u, v2);
__outbyte(0x3D4u, 0xEu);
result = HIBYTE(v2);
__outbyte(0x3D5u, HIBYTE(v2));
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(unsigned __int8 a1, unsigned __int8 a2)
{
unsigned __int16 v2; // di
__int16 result; // ax

v2 = 80 * a2 + a1;
__outbyte(0x3D4u, 0xFu);
__outbyte(0x3D5u, v2);
__outbyte(0x3D4u, 0xEu);
result = HIBYTE(v2);
__outbyte(0x3D5u, HIBYTE(v2));
return result;
}

canonical_original_code:
void move_cursor(unsigned char x, unsigned char y)
{
 unsigned short c_pos;
 c_pos = y * 80 + x;
 asm volatile ("outb %%al, %%dx" :: "d" (0x3d4), "a" (0x0f));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x3d5), "a" ((unsigned char) c_pos));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x3d4), "a" (0x0e));;
 asm volatile ("outb %%al, %%dx" :: "d" (0x3d5), "a" ((u8) (c_pos >> 8)));;
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char


decompiled_code:
__int16 show_cursor()
{
return move_cursor(kX, kY);
}

canonical_decompiled_code:
__int16 func4()
{
return func3(kX, kY);
}

original_code:
void show_cursor(void)
{
 move_cursor(kX, kY);
}

canonical_original_code:
void show_cursor()
{
 move_cursor(kX, kY);
}


decompiled_code:
__int16 hide_cursor()
{
return move_cursor(0xFFu, 0xFFu);
}

canonical_decompiled_code:
__int16 func5()
{
return func3(0xFFu, 0xFFu);
}

original_code:
void hide_cursor(void)
{
 move_cursor(-1, -1);
}

canonical_original_code:
void hide_cursor()
{
 move_cursor(-1, -1);
}


decompiled_code:
__int64 __fastcall load_task(void *a1, const void *a2, size_t a3)
{
unsigned int v3; // ebx
unsigned int v4; // edx
__int64 v5; // rsi
int v6; // ebx
__int64 v7; // rax
__int64 v8; // rdx
int v9; // esi
__int64 v10; // rdi
__int64 result; // rax

v3 = a3;
memcpy(a1, a2, a3);
if ( v3 > 0xFFF )
{
v4 = 0;
do
{
*((_BYTE *)&mem_bitmap + ((v4 + ((unsigned int)a1 >> 12)) >> 3)) |= 1 << ((v4 + ((unsigned int)a1 >> 12)) & 7);
++v4;
}
while ( v4 < v3 >> 12 );
}
v5 = v3;
v6 = pd_create(a1, v3);
v7 = get_page_frame();
if ( (unsigned int)v7 > 0x400000 )
return printk("not enough memory to create a kernel stack\n", v5, v8, v7);
v9 = n_proc;
v10 = 17LL * n_proc;
p_list[v10] = n_proc;
HIWORD(p_list[v10 + 11]) = 51;
p_list[v10 + 5] = 1073745904;
p_list[v10 + 10] = 0;
LOWORD(p_list[v10 + 11]) = 35;
p_list[v10 + 9] = 0x40000000;
LOWORD(p_list[v10 + 12]) = 43;
HIWORD(p_list[v10 + 12]) = 43;
LOWORD(p_list[v10 + 13]) = 43;
HIWORD(p_list[v10 + 13]) = 43;
p_list[v10 + 14] = v6;
LOWORD(p_list[v10 + 16]) = 24;
p_list[v10 + 15] = v7 + 4080;
p_list[v10 + 1] = 0;
p_list[v10 + 2] = 0;
p_list[v10 + 3] = 0;
p_list[v10 + 4] = 0;
p_list[v10 + 6] = 0;
p_list[v10 + 7] = 0;
p_list[v10 + 8] = 0;
result = (unsigned int)(v9 + 1);
n_proc = v9 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1, const void *a2, size_t a3)
{
unsigned int v3; // ebx
unsigned int v4; // edx
__int64 v5; // rsi
int v6; // ebx
__int64 v7; // rax
__int64 v8; // rdx
int v9; // esi
__int64 v10; // rdi
__int64 result; // rax

v3 = a3;
memcpy(a1, a2, a3);
if ( v3 > 0xFFF )
{
v4 = 0;
do
{
*((_BYTE *)&mem_bitmap + ((v4 + ((unsigned int)a1 >> 12)) >> 3)) |= 1 << ((v4 + ((unsigned int)a1 >> 12)) & 7);
++v4;
}
while ( v4 < v3 >> 12 );
}
v5 = v3;
v6 = pd_create(a1, v3);
v7 = get_page_frame();
if ( (unsigned int)v7 > 0x400000 )
return printk("not enough memory to create a kernel stack\n", v5, v8, v7);
v9 = n_proc;
v10 = 17LL * n_proc;
p_list[v10] = n_proc;
HIWORD(p_list[v10 + 11]) = 51;
p_list[v10 + 5] = 1073745904;
p_list[v10 + 10] = 0;
LOWORD(p_list[v10 + 11]) = 35;
p_list[v10 + 9] = 0x40000000;
LOWORD(p_list[v10 + 12]) = 43;
HIWORD(p_list[v10 + 12]) = 43;
LOWORD(p_list[v10 + 13]) = 43;
HIWORD(p_list[v10 + 13]) = 43;
p_list[v10 + 14] = v6;
LOWORD(p_list[v10 + 16]) = 24;
p_list[v10 + 15] = v7 + 4080;
p_list[v10 + 1] = 0;
p_list[v10 + 2] = 0;
p_list[v10 + 3] = 0;
p_list[v10 + 4] = 0;
p_list[v10 + 6] = 0;
p_list[v10 + 7] = 0;
p_list[v10 + 8] = 0;
result = (unsigned int)(v9 + 1);
n_proc = v9 + 1;
return result;
}

original_code:
void load_task(u32 * code_phys_addr, u32 * fn, unsigned int code_size)
{
 u32 page_base, kstack_base;
 u32 *pd;
 int i;
 memcpy((char *) code_phys_addr, (char *) fn, code_size);
 page_base = (u32) code_phys_addr / 4096;
 for (i = 0; i < code_size / 4096; i++)
  mem_bitmap[((u32) page_base + i)/8] |= (1 << (((u32) page_base + i)%8));
 pd = pd_create(code_phys_addr, code_size);
 kstack_base = (u32) get_page_frame();
 if (kstack_base > 0x400000) {
  printk("not enough memory to create a kernel stack\n");
  return;
 }
 p_list[n_proc].pid = n_proc;
 p_list[n_proc].regs.ss = 0x33;
 p_list[n_proc].regs.esp = 0x40000FF0;
 p_list[n_proc].regs.eflags = 0x0;
 p_list[n_proc].regs.cs = 0x23;
 p_list[n_proc].regs.eip = 0x40000000;
 p_list[n_proc].regs.ds = 0x2B;
 p_list[n_proc].regs.es = 0x2B;
 p_list[n_proc].regs.fs = 0x2B;
 p_list[n_proc].regs.gs = 0x2B;
 p_list[n_proc].regs.cr3 = (u32) pd;
 p_list[n_proc].kstack.ss0 = 0x18;
 p_list[n_proc].kstack.esp0 = kstack_base + 4096 - 16;
 p_list[n_proc].regs.eax = 0;
 p_list[n_proc].regs.ecx = 0;
 p_list[n_proc].regs.edx = 0;
 p_list[n_proc].regs.ebx = 0;
 p_list[n_proc].regs.ebp = 0;
 p_list[n_proc].regs.esi = 0;
 p_list[n_proc].regs.edi = 0;
 n_proc++;
}

canonical_original_code:
void load_task(unsigned int *code_phys_addr, unsigned int *fn, unsigned int code_size)
{
 unsigned int page_base; unsigned int kstack_base;
 unsigned int *pd;
 int i;
 memcpy((char *) code_phys_addr, (char *) fn, code_size);
 page_base = (unsigned int) code_phys_addr / 4096;
 for (i = 0; i < code_size / 4096; i++)
  mem_bitmap[((unsigned int) page_base + i)/8] |= (1 << (((unsigned int) page_base + i)%8));
 pd = pd_create(code_phys_addr, code_size);
 kstack_base = (unsigned int) get_page_frame();
 if (kstack_base > 0x400000) {
  printk("not enough memory to create a kernel stack\n");
  return;
 }
 p_list[n_proc].pid = n_proc;
 p_list[n_proc].regs.ss = 0x33;
 p_list[n_proc].regs.esp = 0x40000FF0;
 p_list[n_proc].regs.eflags = 0x0;
 p_list[n_proc].regs.cs = 0x23;
 p_list[n_proc].regs.eip = 0x40000000;
 p_list[n_proc].regs.ds = 0x2B;
 p_list[n_proc].regs.es = 0x2B;
 p_list[n_proc].regs.fs = 0x2B;
 p_list[n_proc].regs.gs = 0x2B;
 p_list[n_proc].regs.cr3 = (unsigned int) pd;
 p_list[n_proc].kstack.ss0 = 0x18;
 p_list[n_proc].kstack.esp0 = kstack_base + 4096 - 16;
 p_list[n_proc].regs.eax = 0;
 p_list[n_proc].regs.ecx = 0;
 p_list[n_proc].regs.edx = 0;
 p_list[n_proc].regs.ebx = 0;
 p_list[n_proc].regs.ebp = 0;
 p_list[n_proc].regs.esi = 0;
 p_list[n_proc].regs.edi = 0;
 n_proc++;
}

variable_types:
fn
unsigned int *

variable_types:
pd
unsigned int *

variable_types: i int


decompiled_code:
__int64 ok_msg()
{
__int64 result; // rax

kX = 60;
kattr = 10;
result = printk(&unk_9FE);
kattr = 7;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

kX = 60;
kattr = 10;
result = printk(&unk_9FE);
kattr = 7;
return result;
}

original_code:
void ok_msg(void)
{
 kX = 60;
 kattr = 0x0A;
 printk("OK\n");
 kattr = 0x07;
}

canonical_original_code:
void ok_msg()
{
 kX = 60;
 kattr = 0x0A;
 printk("OK\n");
 kattr = 0x07;
}


kmain

decompiled_code:
void __fastcall __noreturn kmain(__int64 a1)
{
printk("Pepin is booting...\n");
printk("RAM detected : %uk (lower), %uk (upper)\n", *(unsigned int *)(a1 + 4), *(unsigned int *)(a1 + 8));
_disable();
printk("Loading GDT");
init_gdt();
ok_msg();
printk("Loading IDT");
init_idt();
ok_msg();
printk("Configure PIC");
init_pic();
ok_msg();
printk("Loading Task Register");
__asm { ltr ax }
ok_msg();
printk("Enabling paging");
init_mm(*(unsigned int *)(a1 + 8));
ok_msg();
load_task(0x200000LL, task1, 0x2000LL);
load_task(3145728LL, task2, 0x2000LL);
kattr = 71;
printk("Interrupts are enable. System is ready !\n\n");
kattr = 7;
hide_cursor();
_enable();
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1)
{
printk("Pepin is booting...\n");
printk("RAM detected : %uk (lower), %uk (upper)\n", *(unsigned int *)(a1 + 4), *(unsigned int *)(a1 + 8));
_disable();
printk("Loading GDT");
init_gdt();
func2();
printk("Loading IDT");
init_idt();
func2();
printk("Configure PIC");
init_pic();
func2();
printk("Loading Task Register");
__asm { ltr ax }
func2();
printk("Enabling paging");
init_mm(*(unsigned int *)(a1 + 8));
func2();
load_task(0x200000LL, task1, 0x2000LL);
load_task(3145728LL, task2, 0x2000LL);
kattr = 71;
printk("Interrupts are enable. System is ready !\n\n");
kattr = 7;
hide_cursor();
_enable();
while ( 1 )
;
}

original_code:
void kmain(struct multiboot_info *mbi)
{
 printk("Pepin is booting...\n");
 printk("RAM detected : %uk (lower), %uk (upper)\n", mbi->low_mem, mbi->high_mem);
 asm("cli"::);
 printk("Loading GDT");
 init_gdt();
 asm("   movw $0x18, %ax \n                 movw %ax, %ss \n                 movl $0x1FFF0, %esp");
 ok_msg();
 printk("Loading IDT");
 init_idt();
 ok_msg();
 printk("Configure PIC");
 init_pic();
 ok_msg();
 printk("Loading Task Register");
 asm("	movw $0x38, %ax; ltr %ax");
 ok_msg();
 printk("Enabling paging");
 init_mm(mbi->high_mem);
 ok_msg();
 load_task((u32 *) 0x200000, (u32 *) & task1, 0x2000);
 load_task((u32 *) 0x300000, (u32 *) & task2, 0x2000);
 kattr = 0x47;
 printk("Interrupts are enable. System is ready !\n\n");
 kattr = 0x07;
 hide_cursor();
 asm("sti"::);
 while (1);
}

canonical_original_code:
void kmain(struct multiboot_info *mbi)
{
 printk("Pepin is booting...\n");
 printk("RAM detected : %uk (lower), %uk (upper)\n", mbi->low_mem, mbi->high_mem);
 asm("cli"::);
 printk("Loading GDT");
 init_gdt();
 asm("   movw $0x18, %ax \n                 movw %ax, %ss \n                 movl $0x1FFF0, %esp");
 ok_msg();
 printk("Loading IDT");
 init_idt();
 ok_msg();
 printk("Configure PIC");
 init_pic();
 ok_msg();
 printk("Loading Task Register");
 asm("	movw $0x38, %ax; ltr %ax");
 ok_msg();
 printk("Enabling paging");
 init_mm(mbi->high_mem);
 ok_msg();
 load_task((unsigned int *) 0x200000, (unsigned int *) & task1, 0x2000);
 load_task((unsigned int *) 0x300000, (unsigned int *) & task2, 0x2000);
 kattr = 0x47;
 printk("Interrupts are enable. System is ready !\n\n");
 kattr = 0x07;
 hide_cursor();
 asm("sti"::);
 while (1);
}

variable_types: struct multiboot_info { unsigned int flags; unsigned int low_mem; unsigned int high_mem; unsigned int boot_device; unsigned int cmdline; unsigned int mods_count; unsigned int mods_addr; struct { unsigned int num; unsigned int size; unsigned int addr; unsigned int shndx; } elf_sec; } *


decompiled_code:
__int64 get_page_frame()
{
__int64 v0; // rdx
unsigned int v1; // eax
unsigned int v2; // eax
unsigned __int8 v4; // al
int v5; // ecx

v0 = 0LL;
while ( 1 )
{
v4 = mem_bitmap[v0];
if ( v4 != 0xFF )
break;
LABEL_4:
if ( (_UNKNOWN *)++v0 == &unk_20000 )
return -1LL;
}
v5 = v4;
if ( (v4 & 1) != 0 )
{
v1 = 1;
while ( _bittest(&v5, v1) )
{
if ( ++v1 == 8 )
goto LABEL_4;
}
}
else
{
v1 = 0;
}
v2 = v1 + 8 * v0;
mem_bitmap[v2 >> 3] |= 1 << (v2 & 7);
return (int)(v2 << 12);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdx
unsigned int v1; // eax
unsigned int v2; // eax
unsigned __int8 v4; // al
int v5; // ecx

v0 = 0LL;
while ( 1 )
{
v4 = mem_bitmap[v0];
if ( v4 != 0xFF )
break;
LABEL_4:
if ( (_UNKNOWN *)++v0 == &unk_20000 )
return -1LL;
}
v5 = v4;
if ( (v4 & 1) != 0 )
{
v1 = 1;
while ( _bittest(&v5, v1) )
{
if ( ++v1 == 8 )
goto LABEL_4;
}
}
else
{
v1 = 0;
}
v2 = v1 + 8 * v0;
mem_bitmap[v2 >> 3] |= 1 << (v2 & 7);
return (int)(v2 << 12);
}

original_code:
char* get_page_frame(void)
{
 int byte, bit;
 int page = -1;
 for (byte = 0; byte < 0x100000 / 8; byte++)
  if (mem_bitmap[byte] != 0xFF)
   for (bit = 0; bit < 8; bit++)
    if (!(mem_bitmap[byte] & (1 << bit))) {
     page = 8 * byte + bit;
     mem_bitmap[((u32) page)/8] |= (1 << (((u32) page)%8));
     return (char *) (page * 4096);
    }
 return (char *) -1;
}

canonical_original_code:
char *get_page_frame()
{
 int byte; int bit;
 int page = -1;
 for (byte = 0; byte < 0x100000 / 8; byte++)
  if (mem_bitmap[byte] != 0xFF)
   for (bit = 0; bit < 8; bit++)
    if (!(mem_bitmap[byte] & (1 << bit))) {
     page = 8 * byte + bit;
     mem_bitmap[((unsigned int) page)/8] |= (1 << (((unsigned int) page)%8));
     return (char *) (page * 4096);
    }
 return (char *) -1;
}

variable_types: byte int

variable_types: bit int

variable_types: page int

return_type: char *


decompiled_code:
__int64 __fastcall init_mm(int a1)
{
unsigned int v1; // edi
char *v2; // rax
__int64 v3; // rax
unsigned int i; // eax
unsigned int j; // eax
__int64 v6; // rdi
__int64 k; // rax
__int64 l; // rax
unsigned __int64 v9; // rax
__int64 result; // rax

v1 = (unsigned int)(a1 << 10) >> 12;
v2 = mem_bitmap;
do
*v2++ = 0;
while ( v2 != (char *)(unsigned int)((_DWORD)mem_bitmap + 0x20000) );
v3 = v1 >> 3;
do
mem_bitmap[v3++] = -1;
while ( (int)v3 <= (int)&unk_1FFFF );
mem_bitmap[0] |= 1u;
for ( i = 256; i != 512; ++i )
mem_bitmap[i >> 3] |= 1 << (i & 7);
for ( j = 160; j != 256; ++j )
{
v6 = (unsigned int)(1 << (j & 7));
mem_bitmap[j >> 3] |= v6;
}
pd0 = get_page_frame(v6, 1LL);
pt0 = get_page_frame(v6, 1LL);
*(_DWORD *)pd0 = pt0;
*(_DWORD *)pd0 |= 3u;
for ( k = 4LL; k != 4096; k += 4LL )
*(_DWORD *)(pd0 + k) = 0;
for ( l = 0LL; l != 4096; l += 4LL )
{
*(_DWORD *)(pt0 + l) = (_DWORD)l << 10;
*(_DWORD *)(pt0 + l) |= 3u;
}
__writecr3((unsigned int)pd0);
v9 = __readcr0();
result = (unsigned int)v9 | 0x80000000;
__writecr0((unsigned int)result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // edi
char *v2; // rax
__int64 v3; // rax
unsigned int i; // eax
unsigned int j; // eax
__int64 v6; // rdi
__int64 k; // rax
__int64 l; // rax
unsigned __int64 v9; // rax
__int64 result; // rax

v1 = (unsigned int)(a1 << 10) >> 12;
v2 = mem_bitmap;
do
*v2++ = 0;
while ( v2 != (char *)(unsigned int)((_DWORD)mem_bitmap + 0x20000) );
v3 = v1 >> 3;
do
mem_bitmap[v3++] = -1;
while ( (int)v3 <= (int)&unk_1FFFF );
mem_bitmap[0] |= 1u;
for ( i = 256; i != 512; ++i )
mem_bitmap[i >> 3] |= 1 << (i & 7);
for ( j = 160; j != 256; ++j )
{
v6 = (unsigned int)(1 << (j & 7));
mem_bitmap[j >> 3] |= v6;
}
pd0 = func0(v6, 1LL);
pt0 = func0(v6, 1LL);
*(_DWORD *)pd0 = pt0;
*(_DWORD *)pd0 |= 3u;
for ( k = 4LL; k != 4096; k += 4LL )
*(_DWORD *)(pd0 + k) = 0;
for ( l = 0LL; l != 4096; l += 4LL )
{
*(_DWORD *)(pt0 + l) = (_DWORD)l << 10;
*(_DWORD *)(pt0 + l) |= 3u;
}
__writecr3((unsigned int)pd0);
v9 = __readcr0();
result = (unsigned int)v9 | 0x80000000;
__writecr0((unsigned int)result);
return result;
}

canonical_original_code:
void init_mm(unsigned int high_mem)
{
 unsigned int page_addr;
 int i; int pg; int pg_limit;
 pg_limit = (high_mem * 1024) / 4096;
 for (pg = 0; pg < 0x100000 / 8; pg++)
  mem_bitmap[pg] = 0;
 for (pg = pg_limit / 8; pg < 0x100000 / 8; pg++)
  mem_bitmap[pg] = ~0;
 mem_bitmap[((unsigned int) 0)/8] |= (1 << (((unsigned int) 0)%8));
 for (pg = (0x100000) >> 12; pg < (0x200000) >> 12; pg++)
  mem_bitmap[((unsigned int) pg)/8] |= (1 << (((unsigned int) pg)%8));
 for (pg = (0xA0000) >> 12; pg < (0x100000) >> 12; pg++)
  mem_bitmap[((unsigned int) pg)/8] |= (1 << (((unsigned int) pg)%8));
 pd0 = (unsigned int *) get_page_frame();
 pt0 = (unsigned int *) get_page_frame();
 pd0[0] = (unsigned int) pt0;
 pd0[0] |= 3;
 for (i = 1; i < 1024; i++)
  pd0[i] = 0;
 page_addr = 0;
 for (pg = 0; pg < 1024; pg++) {
  pt0[pg] = page_addr;
  pt0[pg] |= 3;
  page_addr += 4096;
 }
 asm("	mov %0, %%eax \n 		mov %%eax, %%cr3 \n 		mov %%cr0, %%eax \n 		or %1, %%eax \n 		mov %%eax, %%cr0"::"m"(pd0), "i"(0x80000000));
}

variable_types: pg int


printk

original_code:
void printk(char *s, ...)
{
 va_list ap;
 char buf[16];
 int i, j, size, buflen, neg;
 unsigned char c;
 int ival;
 unsigned int uival;
 __builtin_va_start(ap,s);
 while ((c = *s++)) {
  size = 0;
  neg = 0;
  if (c == 0)
   break;
  else if (c == '%') {
   c = *s++;
   if (c >= '0' && c <= '9') {
    size = c - '0';
    c = *s++;
   }
   if (c == 'd') {
    ival = __builtin_va_arg(ap,int);
    if (ival < 0) {
     uival = 0 - ival;
     neg++;
    } else
     uival = ival;
    itoa(buf, uival, 10);
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    if (neg)
     printk("-%s", buf);
    else
     printk(buf);
   } else if (c == 'u') {
    uival = __builtin_va_arg(ap,int);
    itoa(buf, uival, 10);
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    printk(buf);
   } else if (c == 'x' || c == 'X') {
    uival = __builtin_va_arg(ap,int);
    itoa(buf, uival, 16);
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    printk("0x%s", buf);
   } else if (c == 'p') {
    uival = __builtin_va_arg(ap,int);
    itoa(buf, uival, 16);
    size = 8;
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    printk("0x%s", buf);
   } else if (c == 's') {
    printk((char *) __builtin_va_arg(ap,int));
   }
  } else
   putcar(c);
 }
 return;
}

canonical_original_code:
void printk(char *s, ...)
{
 __builtin_va_list ap;
 char buf[16];
 int i; int j; int size; int buflen; int neg;
 unsigned char c;
 int ival;
 unsigned int uival;
 __builtin_va_start(ap,s);
 while ((c = *s++)) {
  size = 0;
  neg = 0;
  if (c == 0)
   break;
  else if (c == '%') {
   c = *s++;
   if (c >= '0' && c <= '9') {
    size = c - '0';
    c = *s++;
   }
   if (c == 'd') {
    ival = __builtin_va_arg(ap,int);
    if (ival < 0) {
     uival = 0 - ival;
     neg++;
    } else
     uival = ival;
    itoa(buf, uival, 10);
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    if (neg)
     printk("-%s", buf);
    else
     printk(buf);
   } else if (c == 'u') {
    uival = __builtin_va_arg(ap,int);
    itoa(buf, uival, 10);
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    printk(buf);
   } else if (c == 'x' || c == 'X') {
    uival = __builtin_va_arg(ap,int);
    itoa(buf, uival, 16);
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    printk("0x%s", buf);
   } else if (c == 'p') {
    uival = __builtin_va_arg(ap,int);
    itoa(buf, uival, 16);
    size = 8;
    buflen = strlen(buf);
    if (buflen < size)
     for (i = size, j = buflen; i >= 0;
          i--, j--)
      buf[i] =
          (j >=
           0) ? buf[j] : '0';
    printk("0x%s", buf);
   } else if (c == 's') {
    printk((char *) __builtin_va_arg(ap,int));
   }
  } else
   putcar(c);
 }
 return;
}

variable_types:
s
char *

variable_types:
buf
char [16]

variable_types: j int

variable_types: size int

variable_types: buflen int

variable_types: neg int

variable_types: ival int

variable_types:
uival
unsigned int


repo: ooyala/hastur-c

decompiled_code:
__int64 __fastcall send_error(const char *a1)
{
perror(a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
perror(a1);
return 0xFFFFFFFFLL;
}

original_code:
static int send_error(const char *s)
{
  perror(s);
  return -1;
}

canonical_original_code:
static int send_error(char *s)
{
  perror(s);
  return -1;
}


decompiled_code:
char *get_pid()
{
__pid_t v0; // eax

v0 = getpid();
sprintf(pid_buf, "%ld", v0);
return pid_buf;
}

canonical_decompiled_code:
char *func3()
{
__pid_t v0; // eax

v0 = getpid();
sprintf(pid_buf, "%ld", v0);
return pid_buf;
}

original_code:
static const char *get_pid(void) {
  sprintf(pid_buf, "%ld", (long int)getpid());
  return pid_buf;
}

canonical_original_code:
static char *get_pid() {
  sprintf(pid_buf, "%ld", (long)getpid());
  return pid_buf;
}


decompiled_code:
char *get_tid()
{
int v0; // edx
char *result; // rax
pthread_t v2[2]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = pthread_self();
v0 = pthread_equal(v2[0], _hastur_start_thread);
result = "main";
if ( !v0 )
result = _hastur_buf_to_hex((__int64)v2, 8);
return result;
}

canonical_decompiled_code:
char *func7()
{
int v0; // edx
char *result; // rax
pthread_t v2[2]; // [rsp+8h] [rbp-10h] BYREF

v2[0] = pthread_self();
v0 = pthread_equal(v2[0], _hastur_start_thread);
result = "main";
if ( !v0 )
result = func6((__int64)v2, 8);
return result;
}

original_code:
static const char *get_tid(void) {
  pthread_t cur = pthread_self();
  if(pthread_equal(cur, __hastur_start_thread)) {
    return "main";
  }
  return __hastur_buf_to_hex((const char*)&cur, sizeof(pthread_t));
}

canonical_original_code:
static char *get_tid() {
  unsigned long cur = pthread_self();
  if(pthread_equal(cur, __hastur_start_thread)) {
    return "main";
  }
  return __hastur_buf_to_hex((char *)&cur, sizeof(pthread_t));
}

variable_types:
cur
unsigned long


decompiled_code:
__int64 __fastcall string_builder_start(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char *string_builder_start(string_builder_t *builder) {
  return builder->buf_start;
}

canonical_original_code:
char *string_builder_start(struct string_builder_struct *builder) {
  return builder->buf_start;
}

variable_types: struct string_builder_struct { char *buf_start; char *buf_tail; int buf_len; } *


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

strncpy(*(char **)(a1 + 8), a2, (int)(*(_DWORD *)(a1 + 16) - (*(_QWORD *)(a1 + 8) - *(_DWORD *)a1)));
result = *(_QWORD *)(a1 + 8) + strlen(a2);
if ( result > *(_QWORD *)a1 + *(int *)(a1 + 16) )
result = *(_QWORD *)a1 + *(int *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

strncpy(*(char **)(a1 + 8), a2, (int)(*(_DWORD *)(a1 + 16) - (*(_QWORD *)(a1 + 8) - *(_DWORD *)a1)));
result = *(_QWORD *)(a1 + 8) + strlen(a2);
if ( result > *(_QWORD *)a1 + *(int *)(a1 + 16) )
result = *(_QWORD *)a1 + *(int *)(a1 + 16);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void string_builder_append(string_builder_t *builder, const char *str) {
  int remaining_length = builder->buf_len - (builder->buf_tail - builder->buf_start);
  strncpy(builder->buf_tail, str, remaining_length);
  builder->buf_tail += strlen(str);
  if(builder->buf_tail > builder->buf_start + builder->buf_len) {
    builder->buf_tail = builder->buf_start + builder->buf_len;
  }
}

canonical_original_code:
void string_builder_append(struct string_builder_struct *builder, char *str) {
  int remaining_length = builder->buf_len - (builder->buf_tail - builder->buf_start);
  strncpy(builder->buf_tail, str, remaining_length);
  builder->buf_tail += strlen(str);
  if(builder->buf_tail > builder->buf_start + builder->buf_len) {
    builder->buf_tail = builder->buf_start + builder->buf_len;
  }
}

variable_types:
str
char *

user_defined_types: struct string_builder_struct { char *buf_start; char *buf_tail; int buf_len; }


decompiled_code:
unsigned __int64 __fastcall string_builder_append_chars(__int64 a1, const char *a2, int a3)
{
char *v3; // r14
int v4; // ebx
int v5; // er12
unsigned __int64 v6; // rbx
unsigned __int64 result; // rax

v3 = *(char **)(a1 + 8);
v4 = *(_DWORD *)(a1 + 16) - (*(_DWORD *)(a1 + 8) - *(_DWORD *)a1);
if ( v4 > a3 )
v4 = a3;
v5 = strlen(a2);
strncpy(v3, a2, v4);
if ( v4 >= v5 )
v4 = v5;
v6 = *(_QWORD *)(a1 + 8) + v4;
result = *(_QWORD *)a1 + *(int *)(a1 + 16);
if ( v6 > result )
v6 = *(_QWORD *)a1 + *(int *)(a1 + 16);
*(_QWORD *)(a1 + 8) = v6;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, const char *a2, int a3)
{
char *v3; // r14
int v4; // ebx
int v5; // er12
unsigned __int64 v6; // rbx
unsigned __int64 result; // rax

v3 = *(char **)(a1 + 8);
v4 = *(_DWORD *)(a1 + 16) - (*(_DWORD *)(a1 + 8) - *(_DWORD *)a1);
if ( v4 > a3 )
v4 = a3;
v5 = strlen(a2);
strncpy(v3, a2, v4);
if ( v4 >= v5 )
v4 = v5;
v6 = *(_QWORD *)(a1 + 8) + v4;
result = *(_QWORD *)a1 + *(int *)(a1 + 16);
if ( v6 > result )
v6 = *(_QWORD *)a1 + *(int *)(a1 + 16);
*(_QWORD *)(a1 + 8) = v6;
return result;
}

original_code:
void string_builder_append_chars(string_builder_t *builder, const char *str, int len) {
  int remaining_length = builder->buf_len - (builder->buf_tail - builder->buf_start);
  int length = (len > remaining_length) ? remaining_length : len;
  int str_length = strlen(str);
  strncpy(builder->buf_tail, str, length);
  builder->buf_tail += (length < str_length ? length : str_length);
  if(builder->buf_tail > builder->buf_start + builder->buf_len) {
    builder->buf_tail = builder->buf_start + builder->buf_len;
  }
}

canonical_original_code:
void string_builder_append_chars(struct string_builder_struct *builder, char *str, int len) {
  int remaining_length = builder->buf_len - (builder->buf_tail - builder->buf_start);
  int length = (len > remaining_length) ? remaining_length : len;
  int str_length = strlen(str);
  strncpy(builder->buf_tail, str, length);
  builder->buf_tail += (length < str_length ? length : str_length);
  if(builder->buf_tail > builder->buf_start + builder->buf_len) {
    builder->buf_tail = builder->buf_start + builder->buf_len;
  }
}

variable_types: len int

variable_types: length int


decompiled_code:
unsigned __int64 __fastcall string_builder_append_char(__int64 a1, char a2)
{
_BYTE *v2; // rdx
unsigned __int64 result; // rax

v2 = *(_BYTE **)(a1 + 8);
result = *(_QWORD *)a1 + *(int *)(a1 + 16);
if ( (unsigned __int64)v2 < result )
{
*v2 = a2;
++*(_QWORD *)(a1 + 8);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, char a2)
{
_BYTE *v2; // rdx
unsigned __int64 result; // rax

v2 = *(_BYTE **)(a1 + 8);
result = *(_QWORD *)a1 + *(int *)(a1 + 16);
if ( (unsigned __int64)v2 < result )
{
*v2 = a2;
++*(_QWORD *)(a1 + 8);
}
return result;
}

original_code:
void string_builder_append_char(string_builder_t *builder, char c) {
  if(builder->buf_tail >= builder->buf_start + builder->buf_len) return;
  *builder->buf_tail = c;
  builder->buf_tail++;
}

canonical_original_code:
void string_builder_append_char(struct string_builder_struct *builder, char c) {
  if(builder->buf_tail >= builder->buf_start + builder->buf_len) return;
  *builder->buf_tail = c;
  builder->buf_tail++;
}

variable_types: c char


checkRow

repo: opatut/eight-queens

decompiled_code:
__int64 __fastcall checkRow(int a1)
{
_DWORD *v1; // rax

if ( count <= 0 )
return 1LL;
v1 = (char *)queens + 4;
while ( *v1 != a1 )
{
v1 += 2;
if ( v1 == (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 12) )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
_DWORD *v1; // rax

if ( count <= 0 )
return 1LL;
v1 = (char *)queens + 4;
while ( *v1 != a1 )
{
v1 += 2;
if ( v1 == (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 12) )
return 1LL;
}
return 0LL;
}

original_code:
int checkRow(int y) {
    for(int i = 0; i < count; ++i) {
        if(queens[i*2+1] == y) return 0;
    }
    return 1;
}

variable_types: y int

variable_types: i int


checkColumn

decompiled_code:
__int64 __fastcall checkColumn(int a1)
{
_DWORD *v1; // rax

if ( count <= 0 )
return 1LL;
v1 = queens;
while ( *v1 != a1 )
{
v1 += 2;
if ( v1 == (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 8) )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
_DWORD *v1; // rax

if ( count <= 0 )
return 1LL;
v1 = queens;
while ( *v1 != a1 )
{
v1 += 2;
if ( v1 == (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 8) )
return 1LL;
}
return 0LL;
}

original_code:
int checkColumn(int x) {
    for(int i = 0; i < count; ++i) {
        if(queens[i*2] == x) return 0;
    }
    return 1;
}

variable_types: x int


checkDiagonal

decompiled_code:
__int64 __fastcall checkDiagonal(int a1, int a2)
{
_DWORD *v2; // rax
int v3; // er8
int v4; // edi
int v5; // ecx

if ( count <= 0 )
return 1LL;
v2 = queens;
v3 = a1 - a2;
v4 = a2 + a1;
while ( 1 )
{
v5 = v2[1];
if ( v3 == *v2 - v5 )
return 0LL;
if ( v4 == v5 + *v2 )
break;
v2 += 2;
if ( v2 == (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 8) )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
_DWORD *v2; // rax
int v3; // er8
int v4; // edi
int v5; // ecx

if ( count <= 0 )
return 1LL;
v2 = queens;
v3 = a1 - a2;
v4 = a2 + a1;
while ( 1 )
{
v5 = v2[1];
if ( v3 == *v2 - v5 )
return 0LL;
if ( v4 == v5 + *v2 )
break;
v2 += 2;
if ( v2 == (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 8) )
return 1LL;
}
return 0LL;
}

original_code:
int checkDiagonal(int x, int y) {
    for(int i = 0; i < count; ++i) {
        int qx = queens[i*2];
        int qy = queens[i*2+1];
        if((x - y == qx - qy) || (x + y == qx + qy)) {
            return 0;
        }
    }
    return 1;
}

variable_types: qx int

variable_types: qy int


placeQueen

decompiled_code:
__int64 __fastcall placeQueen(int a1, int a2)
{
__int64 result; // rax

*((_DWORD *)queens + 2 * count) = a1;
result = 2 * count;
*((_DWORD *)queens + result + 1) = a2;
++count;
return result;
}

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

*((_DWORD *)queens + 2 * count) = a1;
result = 2 * count;
*((_DWORD *)queens + result + 1) = a2;
++count;
return result;
}

original_code:
void placeQueen(int x, int y) {
    queens[2*count+0] = x;
    queens[2*count+1] = y;
    count++;
}


removeLastQueen

decompiled_code:
void removeLastQueen()
{
--count;
}

canonical_decompiled_code:
void func11()
{
--count;
}

original_code:
void removeLastQueen() {
    count--;
}

canonical_original_code:
void removeLastQueen() {
    count--;
}


containsQueen

decompiled_code:
__int64 __fastcall containsQueen(int a1, int a2)
{
_DWORD *v2; // rax

if ( count <= 0 )
return 0LL;
v2 = queens;
do
{
if ( *v2 == a1 && v2[1] == a2 )
return 1LL;
v2 += 2;
}
while ( v2 != (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 8) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
_DWORD *v2; // rax

if ( count <= 0 )
return 0LL;
v2 = queens;
do
{
if ( *v2 == a1 && v2[1] == a2 )
return 1LL;
v2 += 2;
}
while ( v2 != (_DWORD *)((char *)queens + 8 * (unsigned int)(count - 1) + 8) );
return 0LL;
}

original_code:
int containsQueen(int x, int y) {
    for(int i = 0; i < count; ++i) {
        if(queens[i*2] == x && queens[i*2+1] == y) {
            return 1;
        }
    }
    return 0;
}


printField

decompiled_code:
int printField()
{
int v0; // ebx
int v1; // ebp
int v2; // ebx
const char *v3; // rdi
int v4; // ebx

putchar(43);
if ( SIZE > 0 )
{
v0 = 0;
do
{
putchar(45);
++v0;
}
while ( SIZE > v0 );
}
puts(&format[4]);
if ( SIZE > 0 )
{
v1 = 0;
do
{
putchar(124);
if ( SIZE > 0 )
{
v2 = 0;
do
{
v3 = format + 2;
if ( (unsigned int)containsQueen(v1, v2) )
v3 = format;
printf(v3);
++v2;
}
while ( SIZE > v2 );
}
puts(&format[6]);
++v1;
}
while ( SIZE > v1 );
}
putchar(43);
if ( SIZE > 0 )
{
v4 = 0;
do
{
putchar(45);
++v4;
}
while ( SIZE > v4 );
}
return puts(&format[4]);
}

canonical_decompiled_code:
int func13()
{
int v0; // ebx
int v1; // ebp
int v2; // ebx
const char *v3; // rdi
int v4; // ebx

putchar(43);
if ( SIZE > 0 )
{
v0 = 0;
do
{
putchar(45);
++v0;
}
while ( SIZE > v0 );
}
puts(&format[4]);
if ( SIZE > 0 )
{
v1 = 0;
do
{
putchar(124);
if ( SIZE > 0 )
{
v2 = 0;
do
{
v3 = format + 2;
if ( (unsigned int)func12(v1, v2) )
v3 = format;
printf(v3);
++v2;
}
while ( SIZE > v2 );
}
puts(&format[6]);
++v1;
}
while ( SIZE > v1 );
}
putchar(43);
if ( SIZE > 0 )
{
v4 = 0;
do
{
putchar(45);
++v4;
}
while ( SIZE > v4 );
}
return puts(&format[4]);
}

original_code:
void printField() {
    printf("+"); for(int i = 0; i < SIZE; ++i) printf("-"); printf("+\n");
    for(int x = 0; x < SIZE; ++x) {
        printf("|");
        for(int y = 0; y < SIZE; ++y) {
            printf(containsQueen(x, y) ? "X" : " ");
        }
        printf("|\n");
    }
    printf("+"); for(int i = 0; i < SIZE; ++i) printf("-"); printf("+\n");
}


next

decompiled_code:
__int64 next()
{
int v0; // ebp
int i; // ebx

if ( SIZE <= 0 )
return 0LL;
v0 = 0;
do
{
if ( (unsigned int)checkColumn(v0) && SIZE > 0 )
{
for ( i = 0; SIZE > i; ++i )
{
if ( (unsigned int)checkRow(i) && (unsigned int)checkDiagonal(v0, i) )
{
placeQueen(v0, i);
if ( count >= SIZE )
return 1LL;
if ( (unsigned int)next() )
return 1LL;
removeLastQueen();
}
}
}
++v0;
}
while ( SIZE > v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebp
int i; // ebx

if ( SIZE <= 0 )
return 0LL;
v0 = 0;
do
{
if ( (unsigned int)func8(v0) && SIZE > 0 )
{
for ( i = 0; SIZE > i; ++i )
{
if ( (unsigned int)func7(i) && (unsigned int)func9(v0, i) )
{
func10(v0, i);
if ( count >= SIZE )
return 1LL;
if ( (unsigned int)func14() )
return 1LL;
func11();
}
}
}
++v0;
}
while ( SIZE > v0 );
return 0LL;
}

original_code:
int next() {
    for(int x = 0; x < SIZE; ++x) {
        if(!checkColumn(x)) continue;
        for(int y = 0; y < SIZE; ++y) {
            if(!checkRow(y)) continue;
            if(checkDiagonal(x, y)) {
                placeQueen(x, y);
                if(count >= SIZE) {
                    return 1;
                }
                if(next()) {
                    return 1;
                }
                removeLastQueen();
            }
        }
    }
    return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
float v5; // xmm0_4

if ( argc > 1 )
SIZE = atoi(argv[1]);
printf("Field size: %d\n", (unsigned int)SIZE);
queens = malloc(8LL * SIZE);
v3 = clock();
v4 = next();
v5 = (float)((float)(int)(clock() - v3) / 1000000.0) * 1000.0;
if ( v4 )
{
printf("Found solution in %.3f ms:\n", v5);
printField();
}
else
{
printf("No solution found after %.3f ms.\n", v5);
if ( (unsigned int)(SIZE - 2) <= 1 )
puts("That's because there is no solution for size 2 or 3.");
else
puts("Too bad, this should only be the case for a size of 2 or 3... Must be a bug :O");
}
free(queens);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
float v5; // xmm0_4

if ( argc > 1 )
SIZE = atoi(argv[1]);
printf("Field size: %d\n", (unsigned int)SIZE);
queens = malloc(8LL * SIZE);
v3 = clock();
v4 = func14();
v5 = (float)((float)(int)(clock() - v3) / 1000000.0) * 1000.0;
if ( v4 )
{
printf("Found solution in %.3f ms:\n", v5);
func13();
}
else
{
printf("No solution found after %.3f ms.\n", v5);
if ( (unsigned int)(SIZE - 2) <= 1 )
puts("That's because there is no solution for size 2 or 3.");
else
puts("Too bad, this should only be the case for a size of 2 or 3... Must be a bug :O");
}
free(queens);
return 0;
}

original_code:
int main(int argc, char** argv) {
    if(argc >= 2) {
        SIZE = atoi(argv[1]);
    }
    printf("Field size: %d\n", SIZE);
    queens = malloc(2 * SIZE * sizeof(int));
    clock_t start = clock();
    int result = next();
    clock_t end = clock();
    float seconds = (float)(end - start) / ((__clock_t) 1000000) * 1000;
    if(result) {
        printf("Found solution in %.3f ms:\n", seconds);
        printField();
    } else {
        printf("No solution found after %.3f ms.\n", seconds);
        if(SIZE != 2 && SIZE != 3) {
            printf("Too bad, this should only be the case for a size of 2 or 3... Must be a bug :O\n");
        } else {
            printf("That's because there is no solution for size 2 or 3.\n");
        }
    }
    free(queens);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if(argc >= 2) {
        SIZE = atoi(argv[1]);
    }
    printf("Field size: %d\n", SIZE);
    queens = malloc(2 * SIZE * sizeof(int));
    long start = clock();
    int result = next();
    long end = clock();
    float seconds = (float)(end - start) / ((__clock_t) 1000000) * 1000;
    if(result) {
        printf("Found solution in %.3f ms:\n", seconds);
        printField();
    } else {
        printf("No solution found after %.3f ms.\n", seconds);
        if(SIZE != 2 && SIZE != 3) {
            printf("Too bad, this should only be the case for a size of 2 or 3... Must be a bug :O\n");
        } else {
            printf("That's because there is no solution for size 2 or 3.\n");
        }
    }
    free(queens);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: start long

variable_types: result int

variable_types: end long

variable_types: seconds float


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

register_serialgate(argc, argv, envp);
register_orc32();
register_help();
while ( 1 )
{
v3 = getchar();
parse_command((unsigned int)v3, 0LL);
}
}

original_code:
int main(int argv, char *argc[]) {
 register_serialgate();
 register_orc32();
 register_help();
 while (1) {
  char c = getchar();
  _Bool res = parse_command(c, 0);
 }
 return 0;
}

variable_types: argv int

variable_types:
argc
char *[]


repo: openETCS/dataDictionary

decompiled_code:
_BOOL8 __fastcall UpperBitsNotSet64(unsigned __int64 a1, int a2)
{
_BOOL8 result; // rax

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

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

result = 1LL;
if ( a2 != 64 )
result = 1LL << a2 > a1;
return result;
}

original_code:
static inline int UpperBitsNotSet64(uint64_t value, uint32_t length)
{
    if (length == 64)
    {
        return 1;
    }
    else
    {
        const uint64_t MaxValue = ((uint64_t) 1) << length;
        return value < MaxValue;
    }
}

canonical_original_code:
static inline int UpperBitsNotSet64(unsigned long value, unsigned int length)
{
    if (length == 64)
    {
        return 1;
    }
    else
    {
        unsigned long MaxValue = ((uint64_t) 1) << length;
        return value < MaxValue;
    }
}

variable_types:
value
unsigned long

variable_types:
length
unsigned int

variable_types:
MaxValue
unsigned long


decompiled_code:
_BOOL8 __fastcall RouteSuitabilityData_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
_BOOL4 v3; // eax
unsigned __int64 v4; // rdx
unsigned int i; // ebx

v1 = UpperBitsNotSet64(a1[2], 2);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[3], 13);
if ( v1 )
{
v1 = UpperBitsNotSet64(a1[4], 2);
if ( v1 )
v1 = UpperBitsNotSet64(a1[5], 1);
}
}
v2 = a1[5];
if ( v2 == 1 )
{
if ( v1 && UpperBitsNotSet64(a1[6], 15) )
goto LABEL_12;
goto LABEL_21;
}
if ( v2 )
{
if ( v1 )
goto LABEL_12;
LABEL_21:
v4 = a1[8];
v3 = 0;
if ( !v4 )
{
v3 = 0;
goto LABEL_16;
}
goto LABEL_23;
}
if ( !v1 )
goto LABEL_21;
v3 = UpperBitsNotSet64(a1[7], 15);
if ( v3 )
LABEL_12:
v3 = UpperBitsNotSet64(a1[8], 2);
v4 = a1[8];
if ( !v4 )
{
if ( v3 )
v3 = UpperBitsNotSet64(a1[9], 8);
LABEL_16:
if ( !v3 )
goto LABEL_18;
goto LABEL_17;
}
LABEL_23:
if ( v4 == 1 )
{
if ( !v3 )
goto LABEL_18;
v3 = UpperBitsNotSet64(a1[10], 7);
if ( !v3 )
goto LABEL_18;
LABEL_17:
v3 = UpperBitsNotSet64(a1[12], 5);
goto LABEL_18;
}
if ( v4 != 2 )
goto LABEL_16;
if ( v3 )
{
v3 = UpperBitsNotSet64(a1[11], 8);
if ( v3 )
goto LABEL_17;
}
LABEL_18:
for ( i = 0; i < a1[12]; ++i )
{
if ( v3 )
v3 = RouteSuitabilityData_1_UpperBitsNotSet(&a1[5 * i + 13]) != 0;
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(unsigned __int64 *a1)
{
_BOOL4 v1; // eax
unsigned __int64 v2; // rdx
_BOOL4 v3; // eax
unsigned __int64 v4; // rdx
unsigned int i; // ebx

v1 = func0(a1[2], 2);
if ( v1 )
{
v1 = func0(a1[3], 13);
if ( v1 )
{
v1 = func0(a1[4], 2);
if ( v1 )
v1 = func0(a1[5], 1);
}
}
v2 = a1[5];
if ( v2 == 1 )
{
if ( v1 && func0(a1[6], 15) )
goto LABEL_12;
goto LABEL_21;
}
if ( v2 )
{
if ( v1 )
goto LABEL_12;
LABEL_21:
v4 = a1[8];
v3 = 0;
if ( !v4 )
{
v3 = 0;
goto LABEL_16;
}
goto LABEL_23;
}
if ( !v1 )
goto LABEL_21;
v3 = func0(a1[7], 15);
if ( v3 )
LABEL_12:
v3 = func0(a1[8], 2);
v4 = a1[8];
if ( !v4 )
{
if ( v3 )
v3 = func0(a1[9], 8);
LABEL_16:
if ( !v3 )
goto LABEL_18;
goto LABEL_17;
}
LABEL_23:
if ( v4 == 1 )
{
if ( !v3 )
goto LABEL_18;
v3 = func0(a1[10], 7);
if ( !v3 )
goto LABEL_18;
LABEL_17:
v3 = func0(a1[12], 5);
goto LABEL_18;
}
if ( v4 != 2 )
goto LABEL_16;
if ( v3 )
{
v3 = func0(a1[11], 8);
if ( v3 )
goto LABEL_17;
}
LABEL_18:
for ( i = 0; i < a1[12]; ++i )
{
if ( v3 )
v3 = RouteSuitabilityData_1_UpperBitsNotSet(&a1[5 * i + 13]) != 0;
}
return v3;
}

original_code:
int RouteSuitabilityData_UpperBitsNotSet(const RouteSuitabilityData* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_TRACKINIT, 1) ;
    if (p->Q_TRACKINIT == 1)
    {
        status = status && UpperBitsNotSet64(p->D_TRACKINIT, 15);
    }
    if (p->Q_TRACKINIT == 0)
    {
        status = status && UpperBitsNotSet64(p->D_SUITABILITY, 15);
    }
    status = status && UpperBitsNotSet64(p->Q_SUITABILITY, 2) ;
    if (p->Q_SUITABILITY == 0)
    {
        status = status && UpperBitsNotSet64(p->M_LOADINGGAUGE, 8) ;
    }
    if (p->Q_SUITABILITY == 1)
    {
        status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    }
    if (p->Q_SUITABILITY == 2)
    {
        status = status && UpperBitsNotSet64(p->M_TRACTION, 8) ;
    }
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && RouteSuitabilityData_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RouteSuitabilityData_UpperBitsNotSet(struct RouteSuitabilityData *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->Q_TRACKINIT, 1) ;
    if (p->Q_TRACKINIT == 1)
    {
        status = status && UpperBitsNotSet64(p->D_TRACKINIT, 15);
    }
    if (p->Q_TRACKINIT == 0)
    {
        status = status && UpperBitsNotSet64(p->D_SUITABILITY, 15);
    }
    status = status && UpperBitsNotSet64(p->Q_SUITABILITY, 2) ;
    if (p->Q_SUITABILITY == 0)
    {
        status = status && UpperBitsNotSet64(p->M_LOADINGGAUGE, 8) ;
    }
    if (p->Q_SUITABILITY == 1)
    {
        status = status && UpperBitsNotSet64(p->M_AXLELOAD, 7) ;
    }
    if (p->Q_SUITABILITY == 2)
    {
        status = status && UpperBitsNotSet64(p->M_TRACTION, 8) ;
    }
    status = status && UpperBitsNotSet64(p->N_ITER_1, 5) ;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        status = status && RouteSuitabilityData_1_UpperBitsNotSet(&(p->sub_1[i]));
    }
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct RouteSuitabilityData { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct RouteSuitabilityData_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; } sub_1[31]; } *

variable_types: status int

variable_types:
i
unsigned int

user_defined_types: struct RouteSuitabilityData { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct RouteSuitabilityData_1 sub_1[31]; }


decompiled_code:
__int64 __fastcall RouteSuitabilityData_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // ebp

if ( !(unsigned int)Bitstream_Normal(a2, 25LL) )
return 0xFFFFFFFFLL;
if ( !RouteSuitabilityData_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 1LL, a1[5]);
if ( a1[5] == 1 )
Bitstream_Write(a2, 15LL, a1[6]);
if ( !a1[5] )
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 2LL, a1[8]);
if ( !a1[8] )
Bitstream_Write(a2, 8LL, a1[9]);
if ( a1[8] == 1 )
Bitstream_Write(a2, 7LL, a1[10]);
if ( a1[8] == 2 )
Bitstream_Write(a2, 8LL, a1[11]);
Bitstream_Write(a2, 5LL, a1[12]);
if ( !a1[12] )
return 1LL;
v2 = 0;
do
RouteSuitabilityData_1_EncodeBit(&a1[5 * v2++ + 13], a2);
while ( v2 < a1[12] );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1, __int64 a2)
{
unsigned int v2; // ebp

if ( !(unsigned int)Bitstream_Normal(a2, 25LL) )
return 0xFFFFFFFFLL;
if ( !func3(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 1LL, a1[5]);
if ( a1[5] == 1 )
Bitstream_Write(a2, 15LL, a1[6]);
if ( !a1[5] )
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 2LL, a1[8]);
if ( !a1[8] )
Bitstream_Write(a2, 8LL, a1[9]);
if ( a1[8] == 1 )
Bitstream_Write(a2, 7LL, a1[10]);
if ( a1[8] == 2 )
Bitstream_Write(a2, 8LL, a1[11]);
Bitstream_Write(a2, 5LL, a1[12]);
if ( !a1[12] )
return 1LL;
v2 = 0;
do
RouteSuitabilityData_1_EncodeBit(&a1[5 * v2++ + 13], a2);
while ( v2 < a1[12] );
return 1LL;
}

original_code:
int RouteSuitabilityData_EncodeBit(const RouteSuitabilityData* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 25))
    {
        if (RouteSuitabilityData_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            if (p->Q_TRACKINIT == 1)
            {
                Bitstream_Write(stream, 15, p->D_TRACKINIT);
            }
            if (p->Q_TRACKINIT == 0)
            {
                Bitstream_Write(stream, 15, p->D_SUITABILITY);
            }
            Bitstream_Write(stream, 2, p->Q_SUITABILITY);
            if (p->Q_SUITABILITY == 0)
            {
                Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            }
            if (p->Q_SUITABILITY == 1)
            {
                Bitstream_Write(stream, 7, p->M_AXLELOAD);
            }
            if (p->Q_SUITABILITY == 2)
            {
                Bitstream_Write(stream, 8, p->M_TRACTION);
            }
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (uint32_t i = 0; i < p->N_ITER_1; ++i)
            {
                RouteSuitabilityData_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int RouteSuitabilityData_EncodeBit(struct RouteSuitabilityData *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 25))
    {
        if (RouteSuitabilityData_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 1, p->Q_TRACKINIT);
            if (p->Q_TRACKINIT == 1)
            {
                Bitstream_Write(stream, 15, p->D_TRACKINIT);
            }
            if (p->Q_TRACKINIT == 0)
            {
                Bitstream_Write(stream, 15, p->D_SUITABILITY);
            }
            Bitstream_Write(stream, 2, p->Q_SUITABILITY);
            if (p->Q_SUITABILITY == 0)
            {
                Bitstream_Write(stream, 8, p->M_LOADINGGAUGE);
            }
            if (p->Q_SUITABILITY == 1)
            {
                Bitstream_Write(stream, 7, p->M_AXLELOAD);
            }
            if (p->Q_SUITABILITY == 2)
            {
                Bitstream_Write(stream, 8, p->M_TRACTION);
            }
            Bitstream_Write(stream, 5, p->N_ITER_1);
            for (unsigned int i = 0; i < p->N_ITER_1; ++i)
            {
                RouteSuitabilityData_1_EncodeBit(&(p->sub_1[i]), stream);
            }
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

variable_types: struct Bitstream { unsigned char *addr; unsigned int size; unsigned int bitpos; } *

user_defined_types: struct PacketHeader { unsigned long NID_PACKET; unsigned long list; }

user_defined_types: struct RouteSuitabilityData_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; }


decompiled_code:
__int64 __fastcall RouteSuitabilityData_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned int v6; // ebp

result = Bitstream_Normal(a2, 25LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
v3 = Bitstream_Read(a2, 1LL);
a1[5] = v3;
if ( v3 == 1 )
a1[6] = Bitstream_Read(a2, 15LL);
if ( !a1[5] )
a1[7] = Bitstream_Read(a2, 15LL);
v4 = Bitstream_Read(a2, 2LL);
a1[8] = v4;
if ( !v4 )
a1[9] = Bitstream_Read(a2, 8LL);
if ( a1[8] == 1LL )
a1[10] = Bitstream_Read(a2, 7LL);
if ( a1[8] == 2LL )
a1[11] = Bitstream_Read(a2, 8LL);
v5 = Bitstream_Read(a2, 5LL);
a1[12] = v5;
if ( v5 )
{
v6 = 0;
do
RouteSuitabilityData_1_DecodeBit(&a1[5 * v6++ + 13], a2);
while ( (unsigned __int64)v6 < a1[12] );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
unsigned int v6; // ebp

result = Bitstream_Normal(a2, 25LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
v3 = Bitstream_Read(a2, 1LL);
a1[5] = v3;
if ( v3 == 1 )
a1[6] = Bitstream_Read(a2, 15LL);
if ( !a1[5] )
a1[7] = Bitstream_Read(a2, 15LL);
v4 = Bitstream_Read(a2, 2LL);
a1[8] = v4;
if ( !v4 )
a1[9] = Bitstream_Read(a2, 8LL);
if ( a1[8] == 1LL )
a1[10] = Bitstream_Read(a2, 7LL);
if ( a1[8] == 2LL )
a1[11] = Bitstream_Read(a2, 8LL);
v5 = Bitstream_Read(a2, 5LL);
a1[12] = v5;
if ( v5 )
{
v6 = 0;
do
RouteSuitabilityData_1_DecodeBit(&a1[5 * v6++ + 13], a2);
while ( (unsigned __int64)v6 < a1[12] );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int RouteSuitabilityData_DecodeBit(RouteSuitabilityData* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 25))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        if (p->Q_TRACKINIT == 1)
        {
            {
                p->D_TRACKINIT = Bitstream_Read(stream, 15);
            }
        }
        if (p->Q_TRACKINIT == 0)
        {
            {
                p->D_SUITABILITY = Bitstream_Read(stream, 15);
            }
        }
        {
            p->Q_SUITABILITY = Bitstream_Read(stream, 2);
        }
        if (p->Q_SUITABILITY == 0)
        {
            {
                p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
            }
        }
        if (p->Q_SUITABILITY == 1)
        {
            {
                p->M_AXLELOAD = Bitstream_Read(stream, 7);
            }
        }
        if (p->Q_SUITABILITY == 2)
        {
            {
                p->M_TRACTION = Bitstream_Read(stream, 8);
            }
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (uint32_t i = 0; i < p->N_ITER_1; ++i)
        {
            RouteSuitabilityData_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int RouteSuitabilityData_DecodeBit(struct RouteSuitabilityData *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 25))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->Q_TRACKINIT = Bitstream_Read(stream, 1);
        }
        if (p->Q_TRACKINIT == 1)
        {
            {
                p->D_TRACKINIT = Bitstream_Read(stream, 15);
            }
        }
        if (p->Q_TRACKINIT == 0)
        {
            {
                p->D_SUITABILITY = Bitstream_Read(stream, 15);
            }
        }
        {
            p->Q_SUITABILITY = Bitstream_Read(stream, 2);
        }
        if (p->Q_SUITABILITY == 0)
        {
            {
                p->M_LOADINGGAUGE = Bitstream_Read(stream, 8);
            }
        }
        if (p->Q_SUITABILITY == 1)
        {
            {
                p->M_AXLELOAD = Bitstream_Read(stream, 7);
            }
        }
        if (p->Q_SUITABILITY == 2)
        {
            {
                p->M_TRACTION = Bitstream_Read(stream, 8);
            }
        }
    {
            p->N_ITER_1 = Bitstream_Read(stream, 5);
        }
        for (unsigned int i = 0; i < p->N_ITER_1; ++i)
        {
            RouteSuitabilityData_1_DecodeBit(&(p->sub_1[i]), stream);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

user_defined_types: struct Bitstream { unsigned char *addr; unsigned int size; unsigned int bitpos; }


original_code:
int RouteSuitabilityData_EncodeInt(const RouteSuitabilityData* p, Metadata* data, kcg_int* stream)
{
    data->nid_packet = 70;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    kcg_int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_TRACKINIT;
    stream[startAddress++] = p->D_TRACKINIT;
    stream[startAddress++] = p->D_SUITABILITY;
    stream[startAddress++] = p->Q_SUITABILITY;
    stream[startAddress++] = p->M_LOADINGGAUGE;
    stream[startAddress++] = p->M_AXLELOAD;
    stream[startAddress++] = p->M_TRACTION;
    stream[startAddress++] = p->N_ITER_1;
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

canonical_original_code:
int RouteSuitabilityData_EncodeInt(struct RouteSuitabilityData *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    data->nid_packet = 70;
    data->q_dir = p->Q_DIR;
    data->valid = 1;
    int startAddress = data->startAddress;
    stream[startAddress++] = p->header.NID_PACKET;
    stream[startAddress++] = p->Q_DIR;
    stream[startAddress++] = p->L_PACKET;
    stream[startAddress++] = p->Q_SCALE;
    stream[startAddress++] = p->Q_TRACKINIT;
    stream[startAddress++] = p->D_TRACKINIT;
    stream[startAddress++] = p->D_SUITABILITY;
    stream[startAddress++] = p->Q_SUITABILITY;
    stream[startAddress++] = p->M_LOADINGGAUGE;
    stream[startAddress++] = p->M_AXLELOAD;
    stream[startAddress++] = p->M_TRACTION;
    stream[startAddress++] = p->N_ITER_1;
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_EncodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    data->endAddress = startAddress-1;
    return 1;
}

variable_types: struct MetadataElement_T_Common_Types_Pkg { int nid_packet; int q_dir; unsigned char valid; int startAddress; int endAddress; } *

variable_types:
stream
int *

variable_types: startAddress int


original_code:
int RouteSuitabilityData_DecodeInt(RouteSuitabilityData* p, const Metadata* data, const kcg_int* stream)
{
    if(data->nid_packet != 70)
    {
         return 0;
    }
    kcg_int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_TRACKINIT = stream[startAddress++];
    p->D_TRACKINIT = stream[startAddress++];
    p->D_SUITABILITY = stream[startAddress++];
    p->Q_SUITABILITY = stream[startAddress++];
    p->M_LOADINGGAUGE = stream[startAddress++];
    p->M_AXLELOAD = stream[startAddress++];
    p->M_TRACTION = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (uint32_t i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

canonical_original_code:
int RouteSuitabilityData_DecodeInt(struct RouteSuitabilityData *p, struct MetadataElement_T_Common_Types_Pkg *data, int *stream)
{
    if(data->nid_packet != 70)
    {
         return 0;
    }
    int startAddress = data->startAddress;
    p->header.NID_PACKET = stream[startAddress++];
    p->Q_DIR = stream[startAddress++];
    p->L_PACKET = stream[startAddress++];
    p->Q_SCALE = stream[startAddress++];
    p->Q_TRACKINIT = stream[startAddress++];
    p->D_TRACKINIT = stream[startAddress++];
    p->D_SUITABILITY = stream[startAddress++];
    p->Q_SUITABILITY = stream[startAddress++];
    p->M_LOADINGGAUGE = stream[startAddress++];
    p->M_AXLELOAD = stream[startAddress++];
    p->M_TRACTION = stream[startAddress++];
    p->N_ITER_1 = stream[startAddress++];
    for (unsigned int i = 0; i < p->N_ITER_1; ++i)
    {
        RouteSuitabilityData_1_DecodeInt(&(p->sub_1[i]), &startAddress, stream);
    }
    if(startAddress-1 != data->endAddress)
    {
         return 0;
    }
    return 1;
}

user_defined_types: struct MetadataElement_T_Common_Types_Pkg { int nid_packet; int q_dir; unsigned char valid; int startAddress; int endAddress; }


decompiled_code:
__int64 *RouteSuitabilityData_New()
{
__int64 *v0; // rbx

if ( RouteSuitabilityDataMemoryFreeList == -1 )
{
if ( (unsigned __int64)RouteSuitabilityDataMemoryTop > 7 )
return 0LL;
v0 = &RouteSuitabilityDataMemory[168 * RouteSuitabilityDataMemoryTop++];
}
else
{
v0 = &RouteSuitabilityDataMemory[168 * RouteSuitabilityDataMemoryFreeList];
RouteSuitabilityDataMemoryFreeList = *v0;
}
RouteSuitabilityData_Init(v0);
return v0;
}

canonical_decompiled_code:
__int64 *func8()
{
__int64 *v0; // rbx

if ( RouteSuitabilityDataMemoryFreeList == -1 )
{
if ( (unsigned __int64)RouteSuitabilityDataMemoryTop > 7 )
return 0LL;
v0 = &RouteSuitabilityDataMemory[168 * RouteSuitabilityDataMemoryTop++];
}
else
{
v0 = &RouteSuitabilityDataMemory[168 * RouteSuitabilityDataMemoryFreeList];
RouteSuitabilityDataMemoryFreeList = *v0;
}
func2(v0);
return v0;
}

original_code:
RouteSuitabilityData* RouteSuitabilityData_New(void)
{
    RouteSuitabilityData* ptr;
    if (RouteSuitabilityDataMemoryFreeList != (-1))
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList];
        RouteSuitabilityDataMemoryFreeList = RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList].header.NID_PACKET;
    }
    else if (RouteSuitabilityDataMemoryTop < 8)
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryTop];
        RouteSuitabilityDataMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RouteSuitabilityData_Init(ptr);
    return ptr;
}

canonical_original_code:
struct RouteSuitabilityData *RouteSuitabilityData_New()
{
    struct RouteSuitabilityData *ptr;
    if (RouteSuitabilityDataMemoryFreeList != (-1))
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList];
        RouteSuitabilityDataMemoryFreeList = RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryFreeList].header.NID_PACKET;
    }
    else if (RouteSuitabilityDataMemoryTop < 8)
    {
        ptr = &RouteSuitabilityDataMemory[RouteSuitabilityDataMemoryTop];
        RouteSuitabilityDataMemoryTop += 1;
    }
    else
    {
        return 0;
    }
    RouteSuitabilityData_Init(ptr);
    return ptr;
}

return_type: struct RouteSuitabilityData { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long Q_TRACKINIT; unsigned long D_TRACKINIT; unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; unsigned long N_ITER_1; struct RouteSuitabilityData_1 { unsigned long D_SUITABILITY; unsigned long Q_SUITABILITY; unsigned long M_LOADINGGAUGE; unsigned long M_AXLELOAD; unsigned long M_TRACTION; } sub_1[31]; } *


decompiled_code:
unsigned __int64 __fastcall RouteSuitabilityData_Delete(char *a1)
{
unsigned __int64 result; // rax

*(_QWORD *)a1 = RouteSuitabilityDataMemoryFreeList;
result = 0xCF3CF3CF3CF3CF3DLL;
RouteSuitabilityDataMemoryFreeList = 0xCF3CF3CF3CF3CF3DLL * ((a1 - (char *)RouteSuitabilityDataMemory) >> 6);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(char *a1)
{
unsigned __int64 result; // rax

*(_QWORD *)a1 = RouteSuitabilityDataMemoryFreeList;
result = 0xCF3CF3CF3CF3CF3DLL;
RouteSuitabilityDataMemoryFreeList = 0xCF3CF3CF3CF3CF3DLL * ((a1 - (char *)RouteSuitabilityDataMemory) >> 6);
return result;
}

original_code:
void RouteSuitabilityData_Delete(RouteSuitabilityData* ptr)
{
    ptr->header.NID_PACKET = RouteSuitabilityDataMemoryFreeList;
    RouteSuitabilityDataMemoryFreeList = ptr - RouteSuitabilityDataMemory;
}

canonical_original_code:
void RouteSuitabilityData_Delete(struct RouteSuitabilityData *ptr)
{
    ptr->header.NID_PACKET = RouteSuitabilityDataMemoryFreeList;
    RouteSuitabilityDataMemoryFreeList = ptr - RouteSuitabilityDataMemory;
}


decompiled_code:
_BOOL8 __fastcall EOLMPacket_UpperBitsNotSet(unsigned __int64 *a1)
{
_BOOL8 result; // rax

result = UpperBitsNotSet64(a1[2], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[3], 13);
if ( result )
{
result = UpperBitsNotSet64(a1[4], 2);
if ( result )
{
result = UpperBitsNotSet64(a1[5], 14);
if ( result )
{
result = UpperBitsNotSet64(a1[6], 15);
if ( result )
{
result = UpperBitsNotSet64(a1[7], 15);
if ( result )
{
result = UpperBitsNotSet64(a1[8], 1);
if ( result )
result = UpperBitsNotSet64(a1[9], 4);
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned __int64 *a1)
{
_BOOL8 result; // rax

result = func0(a1[2], 2);
if ( result )
{
result = func0(a1[3], 13);
if ( result )
{
result = func0(a1[4], 2);
if ( result )
{
result = func0(a1[5], 14);
if ( result )
{
result = func0(a1[6], 15);
if ( result )
{
result = func0(a1[7], 15);
if ( result )
{
result = func0(a1[8], 1);
if ( result )
result = func0(a1[9], 4);
}
}
}
}
}
}
return result;
}

original_code:
int EOLMPacket_UpperBitsNotSet(const EOLMPacket* p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->NID_LOOP, 14);
    status = status && UpperBitsNotSet64(p->D_LOOP, 15);
    status = status && UpperBitsNotSet64(p->L_LOOP, 15);
    status = status && UpperBitsNotSet64(p->Q_LOOPDIR, 1) ;
    status = status && UpperBitsNotSet64(p->Q_SSCODE, 4) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int EOLMPacket_UpperBitsNotSet(struct EOLMPacket *p)
{
    int status = 1;
    status = status && UpperBitsNotSet64(p->Q_DIR, 2) ;
    status = status && UpperBitsNotSet64(p->L_PACKET, 13);
    status = status && UpperBitsNotSet64(p->Q_SCALE, 2) ;
    status = status && UpperBitsNotSet64(p->NID_LOOP, 14);
    status = status && UpperBitsNotSet64(p->D_LOOP, 15);
    status = status && UpperBitsNotSet64(p->L_LOOP, 15);
    status = status && UpperBitsNotSet64(p->Q_LOOPDIR, 1) ;
    status = status && UpperBitsNotSet64(p->Q_SSCODE, 4) ;
    if (status)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: struct EOLMPacket { struct PacketHeader { unsigned long NID_PACKET; unsigned long list; } header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LOOP; unsigned long D_LOOP; unsigned long L_LOOP; unsigned long Q_LOOPDIR; unsigned long Q_SSCODE; } *

user_defined_types: struct EOLMPacket { struct PacketHeader header; unsigned long Q_DIR; unsigned long L_PACKET; unsigned long Q_SCALE; unsigned long NID_LOOP; unsigned long D_LOOP; unsigned long L_LOOP; unsigned long Q_LOOPDIR; unsigned long Q_SSCODE; }


decompiled_code:
__int64 __fastcall EOLMPacket_EncodeBit(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 66LL) )
return 0xFFFFFFFFLL;
if ( !EOLMPacket_UpperBitsNotSet(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 14LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 4LL, a1[9]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, __int64 a2)
{
if ( !(unsigned int)Bitstream_Normal(a2, 66LL) )
return 0xFFFFFFFFLL;
if ( !func2(a1) )
return 4294967294LL;
Bitstream_Write(a2, 2LL, a1[2]);
Bitstream_Write(a2, 13LL, a1[3]);
Bitstream_Write(a2, 2LL, a1[4]);
Bitstream_Write(a2, 14LL, a1[5]);
Bitstream_Write(a2, 15LL, a1[6]);
Bitstream_Write(a2, 15LL, a1[7]);
Bitstream_Write(a2, 1LL, a1[8]);
Bitstream_Write(a2, 4LL, a1[9]);
return 1LL;
}

original_code:
int EOLMPacket_EncodeBit(const EOLMPacket* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        if (EOLMPacket_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 14, p->NID_LOOP);
            Bitstream_Write(stream, 15, p->D_LOOP);
            Bitstream_Write(stream, 15, p->L_LOOP);
            Bitstream_Write(stream, 1, p->Q_LOOPDIR);
            Bitstream_Write(stream, 4, p->Q_SSCODE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}

canonical_original_code:
int EOLMPacket_EncodeBit(struct EOLMPacket *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        if (EOLMPacket_UpperBitsNotSet(p))
        {
            Bitstream_Write(stream, 2, p->Q_DIR);
            Bitstream_Write(stream, 13, p->L_PACKET);
            Bitstream_Write(stream, 2, p->Q_SCALE);
            Bitstream_Write(stream, 14, p->NID_LOOP);
            Bitstream_Write(stream, 15, p->D_LOOP);
            Bitstream_Write(stream, 15, p->L_LOOP);
            Bitstream_Write(stream, 1, p->Q_LOOPDIR);
            Bitstream_Write(stream, 4, p->Q_SSCODE);
            return 1;
        }
        else
        {
            return -2;
        }
    }
    else
    {
        return -1;
    }
}


decompiled_code:
__int64 __fastcall EOLMPacket_DecodeBit(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = Bitstream_Normal(a2, 66LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
a1[5] = Bitstream_Read(a2, 14LL);
a1[6] = Bitstream_Read(a2, 15LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 1LL);
a1[9] = Bitstream_Read(a2, 4LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = Bitstream_Normal(a2, 66LL);
if ( (_DWORD)result )
{
a1[2] = Bitstream_Read(a2, 2LL);
a1[3] = Bitstream_Read(a2, 13LL);
a1[4] = Bitstream_Read(a2, 2LL);
a1[5] = Bitstream_Read(a2, 14LL);
a1[6] = Bitstream_Read(a2, 15LL);
a1[7] = Bitstream_Read(a2, 15LL);
a1[8] = Bitstream_Read(a2, 1LL);
a1[9] = Bitstream_Read(a2, 4LL);
result = 1LL;
}
return result;
}

original_code:
int EOLMPacket_DecodeBit(EOLMPacket* p, Bitstream* stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LOOP = Bitstream_Read(stream, 14);
        }
        {
            p->D_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->L_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LOOPDIR = Bitstream_Read(stream, 1);
        }
        {
            p->Q_SSCODE = Bitstream_Read(stream, 4);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
int EOLMPacket_DecodeBit(struct EOLMPacket *p, struct Bitstream *stream)
{
    if (Bitstream_Normal(stream, 66))
    {
        {
            p->Q_DIR = Bitstream_Read(stream, 2);
        }
        {
            p->L_PACKET = Bitstream_Read(stream, 13);
        }
        {
            p->Q_SCALE = Bitstream_Read(stream, 2);
        }
        {
            p->NID_LOOP = Bitstream_Read(stream, 14);
        }
        {
            p->D_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->L_LOOP = Bitstream_Read(stream, 15);
        }
        {
            p->Q_LOOPDIR = Bitstream_Read(stream, 1);
        }
        {
            p->Q_SSCODE = Bitstream_Read(stream, 4);
        }
        return 1;
    }
    else
    {
        return 0;
    }
}