decompiled_code:
__int16 *vm_reset()
{
__int16 *result; // rax

reg[0] = 0;
reg[1] = 251;
reg[2] = 0;
result = intr;
do
*result++ = 0;
while ( result != (__int16 *)(unsigned int)((_DWORD)intr + 66) );
return result;
}

canonical_decompiled_code:
__int16 *func6()
{
__int16 *result; // rax

reg[0] = 0;
reg[1] = 251;
reg[2] = 0;
result = intr;
do
*result++ = 0;
while ( result != (__int16 *)(unsigned int)((_DWORD)intr + 66) );
return result;
}

variable_types:
i
unsigned char


repo: Darksecond/Landmine

original_code:
void vm_step()
{
 printf("PC=0x%04X ", reg[0]);
 if(reg_u32[127] && (reg[2] & 4))
 {
  int i;
  for(i = 0; i < 32; i++)
  {
   if(reg_u32[127] & (1 << i))
   {
    reg_u32[127] = (reg_u32[127] & (~(1 << i)));
    push(reg[2]);
    push(reg[0]);
    reg[0] = intr[i];
    reg[2] = reg[2] & ~(4);
    break;
   }
  }
 }
 uint8_t num_args;
 uint8_t a1, a2, a3, a4;
 uint8_t opcode = vmext_getbyte(reg[0]++);
 uint16_t pp;
 int32_t tmp32;
 if (opcode < 0x50) num_args = 3;
 if (opcode < 0x40) num_args = 2;
 if (opcode < 0x20) num_args = 1;
 if (opcode < 0x10) num_args = 0;
 if (num_args >= 1) a1 = vmext_getbyte(reg[0]++);
 if (num_args >= 2) a2 = vmext_getbyte(reg[0]++);
 if (num_args >= 3) a3 = vmext_getbyte(reg[0]++);
 if (num_args >= 4) a4 = vmext_getbyte(reg[0]++);
 printf("opcode=0x%02hhX", opcode);
 if (num_args >= 1) printf(" a1=0x%02hhi", a1);
 if (num_args >= 2) printf(" a2=0x%02hhi", a2);
 if (num_args >= 3) printf(" a3=0x%02hhi", a3);
 if (num_args >= 4) printf(" a4=0x%02hhi", a4);
 printf("\n");
 if (num_args == 2) pp = (a1 << 8) + a2;
 if (num_args == 3) pp = (a2 << 8) + a3;
 if (num_args == 4) pp = (a3 << 8) + a4;
 switch(opcode)
 {
  case 0x01:
   break;
  case 0x02:
   reg[0] = pop();
   break;
  case 0x03:
   reg[0] = pop();
   reg[2] = pop();
   break;
  case 0x04:
   reg[2] = reg[2] & (~4);
   break;
  case 0x05:
   reg[2] = reg[2]|4;
   break;
  case 0x06:
   reg[2] = reg[2]|8;
   break;
  case 0x10:
   tmp32 = reg[a1] + 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x11:
   tmp32 = reg[a1] - 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x12:
   push(reg[a1]);
   break;
  case 0x13:
   reg[a1] = pop();
   break;
  case 0x20:
   reg[a1] = reg[a2];
   break;
  case 0x21:
   reg[a1] = reg[(uint8_t)(reg[a2] & 255)];
   break;
  case 0x22:
   reg[(uint8_t)(reg[a1] & 255)] = reg[a2];
   break;
  case 0x23:
   reg[a1] = (int8_t)a2;
   break;
  case 0x24:
   reg[a1] = reg[a1] & reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x25:
   reg[a1] = reg[a1] | reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x26:
   reg[a1] = reg[a1] ^ reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x27:
   tmp32 = reg[a1] * reg[a2];
   reg[a1] = tmp32;
   chkcarry(tmp32 & 0xf0000);
   chkzero(tmp32);
   break;
  case 0x28:
   reg[a1] = reg[a1] / reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x29:
   tmp32 = reg[a1] + reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x2A:
   tmp32 = reg[a1] - reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   chkzero(reg[a1]);
   break;
  case 0x2B:
   reg[0] = pp;
   break;
  case 0x2C:
   push(reg[0]);
   reg[0] = pp;
   break;
  case 0x2D:
   if ((reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2E:
   if (!(reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2F:
   if((reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x30:
   if(!(reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x31:
   tmp32 = reg[a1] - reg[a2];
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x32:
   tmp32 = reg[a1] - (int16_t)a2;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x40:
   reg[a1] = (vmext_getbyte(pp) << 8) + vmext_getbyte(pp+1);
   break;
  case 0x41:
   reg[a1] = reg[a1] & (int16_t)pp;
   chkzero(reg[a1]);
   break;
  case 0x42:
   reg[a1] = reg[a1] | (int16_t)pp;
   chkzero(reg[a1]);
   break;
  case 0x43:
   reg[a1] = reg[a1] ^ (int16_t)pp;
   chkzero(reg[a1]);
   break;
  case 0x44:
   tmp32 = reg[a1] + (int16_t)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x45:
   tmp32 = reg[a1] - (int16_t)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x46:
   tmp32 = reg[a1] - (int16_t)pp;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x47:
   if (a1 <= 32)
   {
    intr[a1] = pp;
   }
   break;
  case 0x48:
   reg[a1] = (int16_t)pp;
   break;
 }
}

canonical_original_code:
void vm_step()
{
 printf("PC=0x%04X ", reg[0]);
 if(reg_u32[127] && (reg[2] & 4))
 {
  int i;
  for(i = 0; i < 32; i++)
  {
   if(reg_u32[127] & (1 << i))
   {
    reg_u32[127] = (reg_u32[127] & (~(1 << i)));
    push(reg[2]);
    push(reg[0]);
    reg[0] = intr[i];
    reg[2] = reg[2] & ~(4);
    break;
   }
  }
 }
 unsigned char num_args;
 unsigned char a1; unsigned char a2; unsigned char a3; unsigned char a4;
 unsigned char opcode = vmext_getbyte(reg[0]++);
 unsigned short pp;
 int tmp32;
 if (opcode < 0x50) num_args = 3;
 if (opcode < 0x40) num_args = 2;
 if (opcode < 0x20) num_args = 1;
 if (opcode < 0x10) num_args = 0;
 if (num_args >= 1) a1 = vmext_getbyte(reg[0]++);
 if (num_args >= 2) a2 = vmext_getbyte(reg[0]++);
 if (num_args >= 3) a3 = vmext_getbyte(reg[0]++);
 if (num_args >= 4) a4 = vmext_getbyte(reg[0]++);
 printf("opcode=0x%02hhX", opcode);
 if (num_args >= 1) printf(" a1=0x%02hhi", a1);
 if (num_args >= 2) printf(" a2=0x%02hhi", a2);
 if (num_args >= 3) printf(" a3=0x%02hhi", a3);
 if (num_args >= 4) printf(" a4=0x%02hhi", a4);
 printf("\n");
 if (num_args == 2) pp = (a1 << 8) + a2;
 if (num_args == 3) pp = (a2 << 8) + a3;
 if (num_args == 4) pp = (a3 << 8) + a4;
 switch(opcode)
 {
  case 0x01:
   break;
  case 0x02:
   reg[0] = pop();
   break;
  case 0x03:
   reg[0] = pop();
   reg[2] = pop();
   break;
  case 0x04:
   reg[2] = reg[2] & (~4);
   break;
  case 0x05:
   reg[2] = reg[2]|4;
   break;
  case 0x06:
   reg[2] = reg[2]|8;
   break;
  case 0x10:
   tmp32 = reg[a1] + 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x11:
   tmp32 = reg[a1] - 1;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x12:
   push(reg[a1]);
   break;
  case 0x13:
   reg[a1] = pop();
   break;
  case 0x20:
   reg[a1] = reg[a2];
   break;
  case 0x21:
   reg[a1] = reg[(unsigned char)(reg[a2] & 255)];
   break;
  case 0x22:
   reg[(unsigned char)(reg[a1] & 255)] = reg[a2];
   break;
  case 0x23:
   reg[a1] = (char)a2;
   break;
  case 0x24:
   reg[a1] = reg[a1] & reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x25:
   reg[a1] = reg[a1] | reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x26:
   reg[a1] = reg[a1] ^ reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x27:
   tmp32 = reg[a1] * reg[a2];
   reg[a1] = tmp32;
   chkcarry(tmp32 & 0xf0000);
   chkzero(tmp32);
   break;
  case 0x28:
   reg[a1] = reg[a1] / reg[a2];
   chkzero(reg[a1]);
   break;
  case 0x29:
   tmp32 = reg[a1] + reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x2A:
   tmp32 = reg[a1] - reg[a2];
   reg[a1] = tmp32 & 0xffff;
   chkcarry(tmp32 & 0xf0000);
   chkzero(reg[a1]);
   break;
  case 0x2B:
   reg[0] = pp;
   break;
  case 0x2C:
   push(reg[0]);
   reg[0] = pp;
   break;
  case 0x2D:
   if ((reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2E:
   if (!(reg[2] & 1))
   {
    reg[0] = pp;
   }
   break;
  case 0x2F:
   if((reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x30:
   if(!(reg[2] & 2))
   {
    reg[0] = pp;
   }
   break;
  case 0x31:
   tmp32 = reg[a1] - reg[a2];
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x32:
   tmp32 = reg[a1] - (short)a2;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x40:
   reg[a1] = (vmext_getbyte(pp) << 8) + vmext_getbyte(pp+1);
   break;
  case 0x41:
   reg[a1] = reg[a1] & (short)pp;
   chkzero(reg[a1]);
   break;
  case 0x42:
   reg[a1] = reg[a1] | (short)pp;
   chkzero(reg[a1]);
   break;
  case 0x43:
   reg[a1] = reg[a1] ^ (short)pp;
   chkzero(reg[a1]);
   break;
  case 0x44:
   tmp32 = reg[a1] + (short)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x45:
   tmp32 = reg[a1] - (short)pp;
   reg[a1] = tmp32 & 0xffff;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x46:
   tmp32 = reg[a1] - (short)pp;
   chkzero(tmp32);
   chkcarry(tmp32 & 0xf0000);
   break;
  case 0x47:
   if (a1 <= 32)
   {
    intr[a1] = pp;
   }
   break;
  case 0x48:
   reg[a1] = (short)pp;
   break;
 }
}

variable_types: i int

variable_types:
opcode
unsigned char

variable_types:
pp
unsigned short

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
int v4; // eax

if ( argc == 1 )
{
printf("Usage: %s firmware.bin\n", *argv);
exit(0);
}
v3 = open(argv[1], 0, envp);
if ( v3 <= 0 )
{
perror("opening firmware file");
exit(1);
}
v4 = read(v3, &firmware, (size_t)&unk_10000);
if ( v4 <= 0 )
{
perror("reading firmware file");
exit(1);
}
printf("Firmware: loaded %i bytes.\n", (unsigned int)v4);
vm_reset();
while ( (unsigned __int8)vm_running() == 1 )
vm_step();
return 0;
}

original_code:
int main(int argc, char** argv)
{
 if (argc == 1)
 {
  printf("Usage: %s firmware.bin\n", argv[0]);
  exit(0);
 }
 int i,f;
 f = open(argv[1],00);
 if ( f < 1)
 {
  perror("opening firmware file");
  exit(1);
 }
 i = read(f, firmware, 64*1024);
 if (i < 1)
 {
  perror("reading firmware file");
  exit(1);
 }
 printf("Firmware: loaded %i bytes.\n",i);
 vm_reset();
 while(vm_running() == 1)
 {
  vm_step();
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 if (argc == 1)
 {
  printf("Usage: %s firmware.bin\n", argv[0]);
  exit(0);
 }
 int i; int f;
 f = open(argv[1],00);
 if ( f < 1)
 {
  perror("opening firmware file");
  exit(1);
 }
 i = read(f, firmware, 64*1024);
 if (i < 1)
 {
  perror("reading firmware file");
  exit(1);
 }
 printf("Firmware: loaded %i bytes.\n",i);
 vm_reset();
 while(vm_running() == 1)
 {
  vm_step();
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: f int

return_type: int


decompiled_code:
__int64 __fastcall vmext_getbyte(unsigned __int16 a1)
{
return (unsigned __int8)firmware[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
return (unsigned __int8)firmware[a1];
}

original_code:
uint8_t vmext_getbyte(uint16_t addr)
{
 return firmware[addr];
}

canonical_original_code:
unsigned char vmext_getbyte(unsigned short addr)
{
 return firmware[addr];
}

variable_types:
addr
unsigned short

return_type: unsigned char


freemakeargv

decompiled_code:
void __fastcall freemakeargv(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void freemakeargv(char **argv) {
 if (argv == ((void *)0))
  return;
 if (*argv != ((void *)0))
  free(*argv);
 free(argv);
}


makeargv

decompiled_code:
__int64 __fastcall makeargv(const char *a1, const char *a2, _QWORD *a3)
{
const char *v4; // r14
size_t v5; // rax
char *v6; // rax
char *v7; // r12
int v8; // ebx
void *v9; // rax
_QWORD *v11; // r15
__int64 v12; // r12
char **v13; // r14

if ( a3 == 0LL || a2 == 0LL || !a1 )
{
*__errno_location() = 22;
return (unsigned int)-1;
}
*a3 = 0LL;
v4 = &a1[strspn(a1, a2)];
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
strcpy(v6, v4);
v8 = 1;
if ( !strtok(v7, a2) )
{
v9 = malloc(8uLL);
*a3 = v9;
if ( v9 )
{
v8 = 0;
goto LABEL_7;
}
LABEL_19:
free(v7);
return (unsigned int)-1;
}
while ( strtok(0LL, a2) )
++v8;
v11 = malloc(8LL * (v8 + 1));
*a3 = v11;
if ( !v11 )
goto LABEL_19;
if ( v8 )
{
strcpy(v7, v4);
*v11 = strtok(v7, a2);
if ( v8 > 1 )
{
v12 = 8LL;
do
{
v13 = (char **)(*a3 + v12);
*v13 = strtok(0LL, a2);
v12 += 8LL;
}
while ( v12 != 8LL * (unsigned int)(v8 - 2) + 16 );
}
goto LABEL_8;
}
LABEL_7:
free(v7);
LABEL_8:
*(_QWORD *)(*a3 + 8LL * v8) = 0LL;
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2, _QWORD *a3)
{
const char *v4; // r14
size_t v5; // rax
char *v6; // rax
char *v7; // r12
int v8; // ebx
void *v9; // rax
_QWORD *v11; // r15
__int64 v12; // r12
char **v13; // r14

if ( a3 == 0LL || a2 == 0LL || !a1 )
{
*__errno_location() = 22;
return (unsigned int)-1;
}
*a3 = 0LL;
v4 = &a1[strspn(a1, a2)];
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
strcpy(v6, v4);
v8 = 1;
if ( !strtok(v7, a2) )
{
v9 = malloc(8uLL);
*a3 = v9;
if ( v9 )
{
v8 = 0;
goto LABEL_7;
}
LABEL_19:
free(v7);
return (unsigned int)-1;
}
while ( strtok(0LL, a2) )
++v8;
v11 = malloc(8LL * (v8 + 1));
*a3 = v11;
if ( !v11 )
goto LABEL_19;
if ( v8 )
{
strcpy(v7, v4);
*v11 = strtok(v7, a2);
if ( v8 > 1 )
{
v12 = 8LL;
do
{
v13 = (char **)(*a3 + v12);
*v13 = strtok(0LL, a2);
v12 += 8LL;
}
while ( v12 != 8LL * (unsigned int)(v8 - 2) + 16 );
}
goto LABEL_8;
}
LABEL_7:
free(v7);
LABEL_8:
*(_QWORD *)(*a3 + 8LL * v8) = 0LL;
return (unsigned int)v8;
}

original_code:
int makeargv(const char *s, const char *delimiters, char ***argvp) {
 int error;
 int i;
 int numtokens;
 const char *snew;
 char *t;
 if ((s == ((void *)0)) || (delimiters == ((void *)0)) || (argvp == ((void *)0))) {
  (*__errno_location ()) = 22;
  return -1;
 }
 *argvp = ((void *)0);
 snew = s + strspn(s, delimiters);
 if ((t = malloc(strlen(snew) + 1)) == ((void *)0))
  return -1;
 strcpy(t,snew);
 numtokens = 0;
 if (strtok(t, delimiters) != ((void *)0))
  for (numtokens = 1; strtok(((void *)0), delimiters) != ((void *)0); numtokens++) ;
 if ((*argvp = malloc((numtokens + 1)*sizeof(char *))) == ((void *)0)) {
  error = (*__errno_location ());
  free(t);
  (*__errno_location ()) = error;
  return -1;
 }
 if (numtokens == 0)
  free(t);
 else {
  strcpy(t,snew);
  **argvp = strtok(t,delimiters);
  for (i=1; i<numtokens; i++)
   *((*argvp) +i) = strtok(((void *)0),delimiters);
 }
 *((*argvp) + numtokens) = ((void *)0);
 return numtokens;
}

canonical_original_code:
int makeargv(char *s, char *delimiters, char ***argvp) {
 int error;
 int i;
 int numtokens;
 char *snew;
 char *t;
 if ((s == ((void *)0)) || (delimiters == ((void *)0)) || (argvp == ((void *)0))) {
  (*__errno_location ()) = 22;
  return -1;
 }
 *argvp = ((void *)0);
 snew = s + strspn(s, delimiters);
 if ((t = malloc(strlen(snew) + 1)) == ((void *)0))
  return -1;
 strcpy(t,snew);
 numtokens = 0;
 if (strtok(t, delimiters) != ((void *)0))
  for (numtokens = 1; strtok(((void *)0), delimiters) != ((void *)0); numtokens++) ;
 if ((*argvp = malloc((numtokens + 1)*sizeof(char *))) == ((void *)0)) {
  error = (*__errno_location ());
  free(t);
  (*__errno_location ()) = error;
  return -1;
 }
 if (numtokens == 0)
  free(t);
 else {
  strcpy(t,snew);
  **argvp = strtok(t,delimiters);
  for (i=1; i<numtokens; i++)
   *((*argvp) +i) = strtok(((void *)0),delimiters);
 }
 *((*argvp) + numtokens) = ((void *)0);
 return numtokens;
}

variable_types:
s
char *

variable_types:
delimiters
char *

variable_types:
argvp
char ***

variable_types: error int

variable_types: numtokens int

variable_types:
snew
char *

variable_types:
t
char *


decompiled_code:
__int64 __fastcall parse_input_line(const char *a1, int a2, __int64 a3)
{
int v4; // er13
__int64 result; // rax
int v6; // edx
__int64 v7; // r13
__int64 v8; // rbp
char *v9; // rax
const char **v10; // r13
const char **v11; // r12
const char *v12; // rax
__int64 i; // rbp
const char **v14; // [rsp+0h] [rbp-38h] BYREF
void *ptr; // [rsp+8h] [rbp-30h] BYREF

v4 = makeargv(a1, ":", &ptr);
result = 0LL;
if ( v4 != -1 )
{
v6 = makeargv(*((const char **)ptr + 1), " ", &v14);
result = 0LL;
if ( v6 != -1 )
{
if ( v4 > 0 )
{
v7 = 8LL * (unsigned int)v4;
v8 = 0LL;
do
{
v9 = strpbrk(*(const char **)((char *)ptr + v8), "\n\r");
if ( v9 )
*v9 = 0;
v8 += 8LL;
}
while ( v8 != v7 );
}
v10 = (const char **)ptr;
strcpy((char *)(a3 + 4), *(const char **)ptr);
strcpy((char *)(a3 + 1028), v10[2]);
strcpy((char *)(a3 + 2052), v10[3]);
*(_DWORD *)a3 = a2;
*(_DWORD *)(a3 + 3316) = 0;
v11 = v14;
v12 = *v14;
for ( i = 1LL; v12; v12 = v11[i - 1] )
{
if ( !strcmp(v12, "none") )
break;
*(_DWORD *)(a3 + 4 * i + 3072) = atoi(v12);
++*(_DWORD *)(a3 + 3316);
++i;
}
freemakeargv(v10);
result = 1LL;
}
}
return result;
}

original_code:
int parse_input_line(char *s, int id, node_t *node) {
 char **strings;
 char **child_list;
    char* line_location;
 int count = 0;
    int i;
    int tok_count = makeargv(s, ":", &strings);
 if (tok_count == -1) return 0;
 if(makeargv(strings[1], " ", &child_list) == -1) return 0;
    for (i = 0; i < tok_count; i++) {
  if((line_location = strpbrk(strings[i], "\n\r"))){
   *line_location = '\0';
        }
 }
 strcpy(node->prog,strings[0]);
 strcpy(node->input,strings[2]);
 strcpy(node->output,strings[3]);
 node->id = id;
 node->num_children = 0;
 while (child_list[count] != ((void *)0) && strcmp(child_list[count],"none")!=0) {
  node->children[count] = atoi(child_list[count]);
  node->num_children++;
  count++;
 }
    freemakeargv(strings);
 return 1;
}

canonical_original_code:
int parse_input_line(char *s, int id, struct node *node) {
 char **strings;
 char **child_list;
    char *line_location;
 int count = 0;
    int i;
    int tok_count = makeargv(s, ":", &strings);
 if (tok_count == -1) return 0;
 if(makeargv(strings[1], " ", &child_list) == -1) return 0;
    for (i = 0; i < tok_count; i++) {
  if((line_location = strpbrk(strings[i], "\n\r"))){
   *line_location = '\0';
        }
 }
 strcpy(node->prog,strings[0]);
 strcpy(node->input,strings[2]);
 strcpy(node->output,strings[3]);
 node->id = id;
 node->num_children = 0;
 while (child_list[count] != ((void *)0) && strcmp(child_list[count],"none")!=0) {
  node->children[count] = atoi(child_list[count]);
  node->num_children++;
  count++;
 }
    freemakeargv(strings);
 return 1;
}

variable_types: id int

variable_types: struct node { int id; char prog[1024]; char input[1024]; char output[1024]; int children[10]; int parents[50]; int num_children; int num_parents; int status; int pid; } *

variable_types:
strings
char **

variable_types: count int


original_code:
void add_parent(node_t * node, int parent_id) {
 int parent_count = node->num_parents;
    _Bool already_parent = 0;
    int i;
    for (i = 0; i < parent_count; i++)
        if(node->parents[i] == parent_id){
            already_parent = 1;
            break;
        }
    if (already_parent = 0){
        node->parents[node->num_parents++] = parent_id;
    }
}

canonical_original_code:
void add_parent(struct node *node, int parent_id) {
 int parent_count = node->num_parents;
    _Bool already_parent = 0;
    int i;
    for (i = 0; i < parent_count; i++)
        if(node->parents[i] == parent_id){
            already_parent = 1;
            break;
        }
    if (already_parent = 0){
        node->parents[node->num_parents++] = parent_id;
    }
}

variable_types: i int

user_defined_types: struct node { int id; char prog[1024]; char input[1024]; char output[1024]; int children[10]; int parents[50]; int num_children; int num_parents; int status; int pid; }


original_code:
void link_nodes(node_t * nodes[], int node_count) {
 int parent_id;
 int child_id;
 int child_index;
 int child_count;
 node_t * temp;
 for (parent_id = 0; parent_id < node_count; parent_id++) {
  temp = nodes[parent_id];
  child_count = temp->num_children;
  for (child_index = 0; child_index < child_count; child_index++) {
   child_id = temp->children[child_index];
   if (child_id < node_count) {
    add_parent(nodes[child_id], parent_id);
   }
  }
 }
}

canonical_original_code:
void link_nodes(struct node *nodes[], int node_count) {
 int parent_id;
 int child_id;
 int child_index;
 int child_count;
 struct node *temp;
 for (parent_id = 0; parent_id < node_count; parent_id++) {
  temp = nodes[parent_id];
  child_count = temp->num_children;
  for (child_index = 0; child_index < child_count; child_index++) {
   child_id = temp->children[child_index];
   if (child_id < node_count) {
    add_parent(nodes[child_id], parent_id);
   }
  }
 }
}

variable_types: struct node { int id; char prog[1024]; char input[1024]; char output[1024]; int children[10]; int parents[50]; int num_children; int num_parents; int status; int pid; } *[]


decompiled_code:
__int64 __fastcall determine_eligible(__int64 *a1, int a2)
{
__int64 result; // rax
__int64 *v4; // rsi
__int64 v5; // r10
__int64 v6; // rdx
__int64 v7; // r8
int v8; // er9

if ( a2 > 0 )
{
v4 = a1;
v5 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
do
{
v7 = *v4;
if ( !*(_DWORD *)(*v4 + 3324) )
{
v8 = *(_DWORD *)(v7 + 3320);
if ( v8 > (int)result )
{
v6 = v7 + 4LL * (int)result;
do
{
if ( *(_DWORD *)(a1[*(int *)(v6 + 3116)] + 3324) != 3 )
{
result = (unsigned int)(result + 1);
goto LABEL_6;
}
LODWORD(result) = result + 1;
v6 += 4LL;
}
while ( v8 != (_DWORD)result );
result = (unsigned int)v8;
}
*(_DWORD *)(v7 + 3324) = 1;
}
LABEL_6:
++v4;
}
while ( v4 != (__int64 *)v5 );
}
return result;
}

original_code:
void determine_eligible(node_t * nodes[], int count) {
 int i, j, parent_count;
    _Bool is_ready;
    node_t * node = (node_t*)malloc(sizeof(node_t));
 for (i = 0; i < count; i++) {
        node = nodes[i];
        parent_count = node->num_parents;
        is_ready = 1;
        if (node->status == 0) {
            while(j < parent_count && is_ready) {
                int parent_id = node->parents[j];
                if (nodes[parent_id]->status != 3) {
                    is_ready = 0;
                }
                j++;
            }
            if (is_ready) node->status = 1;
        }
 }
}

canonical_original_code:
void determine_eligible(struct node *nodes[], int count) {
 int i; int j; int parent_count;
    _Bool is_ready;
    struct node *node = (node_t*)malloc(sizeof(node_t));
 for (i = 0; i < count; i++) {
        node = nodes[i];
        parent_count = node->num_parents;
        is_ready = 1;
        if (node->status == 0) {
            while(j < parent_count && is_ready) {
                int parent_id = node->parents[j];
                if (nodes[parent_id]->status != 3) {
                    is_ready = 0;
                }
                j++;
            }
            if (is_ready) node->status = 1;
        }
 }
}

variable_types: j int


decompiled_code:
__int64 __fastcall run_node(__int64 a1)
{
unsigned int v1; // ebp
int v2; // er12
int v3; // er13
int v4; // er14
__pid_t v5; // eax
_DWORD stat_loc[17]; // [rsp+4h] [rbp-44h] BYREF

fflush(_bss_start);
v1 = dup(0);
if ( v1 == -1 )
{
perror("Failed to back-up stdin");
}
else
{
v2 = dup(1);
if ( v2 == -1 )
{
perror("Failed to back-up stdout");
v1 = -1;
}
else
{
v3 = open((const char *)(a1 + 1028), 64, 420LL);
if ( v3 == -1 )
{
perror("Failed to open input file");
v1 = -1;
}
else
{
v4 = open((const char *)(a1 + 2052), 65, 420LL);
if ( v4 == -1 )
{
perror("Failed to open output file");
v1 = -1;
}
else
{
fflush(_bss_start);
if ( dup2(v3, 0) == -1 )
{
perror("Failed to redirect stdin");
v1 = -1;
}
else if ( dup2(v4, 1) == -1 )
{
perror("Failed to redirect stdout");
v1 = -1;
}
else
{
makeargv((const char *)(a1 + 4), " ", &stat_loc[1]);
*(_DWORD *)(a1 + 3324) = 2;
v5 = fork();
*(_DWORD *)(a1 + 3328) = v5;
if ( v5 )
wait((__WAIT_STATUS)stat_loc);
else
execvp(**(const char ***)&stat_loc[1], *(char *const *__attribute__((__org_arrdim(0,0))) *)&stat_loc[1]);
freemakeargv(*(void **)&stat_loc[1]);
*(_DWORD *)(a1 + 3324) = 3;
fflush(_bss_start);
if ( dup2(v2, 1) == -1 )
{
perror("Failed to redirect stdout to original stdout");
v1 = -1;
}
else if ( dup2(v1, 0) == -1 )
{
perror("Failed to redirect stdin to original stdin");
v1 = -1;
}
else
{
if ( close(v3) )
perror("Failed to close input_fd");
if ( close(v4) )
perror("Failed to close output_fd");
if ( close(v1) )
perror("Failed to close oldstdin");
if ( close(v2) )
perror("Failed to close oldstdout");
v1 = *(_DWORD *)(a1 + 3324);
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned int v1; // ebp
int v2; // er12
int v3; // er13
int v4; // er14
__pid_t v5; // eax
_DWORD stat_loc[17]; // [rsp+4h] [rbp-44h] BYREF

fflush(_bss_start);
v1 = dup(0);
if ( v1 == -1 )
{
perror("Failed to back-up stdin");
}
else
{
v2 = dup(1);
if ( v2 == -1 )
{
perror("Failed to back-up stdout");
v1 = -1;
}
else
{
v3 = open((const char *)(a1 + 1028), 64, 420LL);
if ( v3 == -1 )
{
perror("Failed to open input file");
v1 = -1;
}
else
{
v4 = open((const char *)(a1 + 2052), 65, 420LL);
if ( v4 == -1 )
{
perror("Failed to open output file");
v1 = -1;
}
else
{
fflush(_bss_start);
if ( dup2(v3, 0) == -1 )
{
perror("Failed to redirect stdin");
v1 = -1;
}
else if ( dup2(v4, 1) == -1 )
{
perror("Failed to redirect stdout");
v1 = -1;
}
else
{
func8((const char *)(a1 + 4), " ", &stat_loc[1]);
*(_DWORD *)(a1 + 3324) = 2;
v5 = fork();
*(_DWORD *)(a1 + 3328) = v5;
if ( v5 )
wait((__WAIT_STATUS)stat_loc);
else
execvp(**(const char ***)&stat_loc[1], *(char *const *__attribute__((__org_arrdim(0,0))) *)&stat_loc[1]);
func7(*(void **)&stat_loc[1]);
*(_DWORD *)(a1 + 3324) = 3;
fflush(_bss_start);
if ( dup2(v2, 1) == -1 )
{
perror("Failed to redirect stdout to original stdout");
v1 = -1;
}
else if ( dup2(v1, 0) == -1 )
{
perror("Failed to redirect stdin to original stdin");
v1 = -1;
}
else
{
if ( close(v3) )
perror("Failed to close input_fd");
if ( close(v4) )
perror("Failed to close output_fd");
if ( close(v1) )
perror("Failed to close oldstdin");
if ( close(v2) )
perror("Failed to close oldstdout");
v1 = *(_DWORD *)(a1 + 3324);
}
}
}
}
}
}
return v1;
}

original_code:
int run_node(node_t * node) {
 char ** child_argv;
 int child_argc;
 int oldstdin, oldstdout;
 int input_fd, output_fd;
 int status;
 pid_t child_pid;
 fflush(stdout);
 if ((oldstdin = dup(0)) == -1) {
  perror("Failed to back-up stdin");
        return -1;
    }
 if ((oldstdout = dup(1)) == -1) {
  perror("Failed to back-up stdout");
  return -1;
 }
 if ((input_fd = open(node->input, 00 | 0100, 0644)) == -1) {
  perror("Failed to open input file");
        return -1;
    }
 if ((output_fd = open(node->output, 01 | 0100, 0644)) == -1) {
  perror("Failed to open output file");
        return -1;
    }
 fflush(stdout);
 if (dup2(input_fd, 0) == -1) {
  perror("Failed to redirect stdin");
        return -1;
    }
 if (dup2(output_fd, 1) == -1) {
  perror("Failed to redirect stdout");
        return -1;
    }
 child_argc = makeargv(node->prog, " ", &child_argv);
    node->status = 2;
 node->pid = child_pid = fork();
 if (child_pid) wait(&status);
 else execvp(child_argv[0], &child_argv[0]);
 freemakeargv(child_argv);
 node->status = 3;
 fflush(stdout);
 if (dup2(oldstdout, 1) == -1) {
  perror("Failed to redirect stdout to original stdout");
        return -1;
    }
 if (dup2(oldstdin, 0) == -1) {
  perror("Failed to redirect stdin to original stdin");
        return -1;
    }
 if (close(input_fd)) perror("Failed to close input_fd");
 if (close(output_fd)) perror("Failed to close output_fd");
 if (close(oldstdin)) perror("Failed to close oldstdin");
 if (close(oldstdout)) perror("Failed to close oldstdout");
 return node->status;
}

canonical_original_code:
int run_node(struct node *node) {
 char **child_argv;
 int child_argc;
 int oldstdin; int oldstdout;
 int input_fd; int output_fd;
 int status;
 int child_pid;
 fflush(stdout);
 if ((oldstdin = dup(0)) == -1) {
  perror("Failed to back-up stdin");
        return -1;
    }
 if ((oldstdout = dup(1)) == -1) {
  perror("Failed to back-up stdout");
  return -1;
 }
 if ((input_fd = open(node->input, 00 | 0100, 0644)) == -1) {
  perror("Failed to open input file");
        return -1;
    }
 if ((output_fd = open(node->output, 01 | 0100, 0644)) == -1) {
  perror("Failed to open output file");
        return -1;
    }
 fflush(stdout);
 if (dup2(input_fd, 0) == -1) {
  perror("Failed to redirect stdin");
        return -1;
    }
 if (dup2(output_fd, 1) == -1) {
  perror("Failed to redirect stdout");
        return -1;
    }
 child_argc = makeargv(node->prog, " ", &child_argv);
    node->status = 2;
 node->pid = child_pid = fork();
 if (child_pid) wait(&status);
 else execvp(child_argv[0], &child_argv[0]);
 freemakeargv(child_argv);
 node->status = 3;
 fflush(stdout);
 if (dup2(oldstdout, 1) == -1) {
  perror("Failed to redirect stdout to original stdout");
        return -1;
    }
 if (dup2(oldstdin, 0) == -1) {
  perror("Failed to redirect stdin to original stdin");
        return -1;
    }
 if (close(input_fd)) perror("Failed to close input_fd");
 if (close(output_fd)) perror("Failed to close output_fd");
 if (close(oldstdin)) perror("Failed to close oldstdin");
 if (close(oldstdout)) perror("Failed to close oldstdout");
 return node->status;
}

variable_types: oldstdin int

variable_types: oldstdout int

variable_types: status int


decompiled_code:
void __fastcall free_array(void **a1, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func15(void **a1, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void free_array(node_t * nodes[], int count) {
 int i;
 for(i = 0; i < count; i++) {
  if (nodes[i]) free(nodes[i]);
 }
}

canonical_original_code:
void free_array(struct node *nodes[], int count) {
 int i;
 for(i = 0; i < count; i++) {
  if (nodes[i]) free(nodes[i]);
 }
}


main

repo: Datera/lio-utils

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
const char *v4; // rbp
int v5; // eax
int v6; // ebx
int v7; // eax
int v8; // er12
unsigned __int8 *v9; // rbx
char *v10; // rax
char *v11; // rax
int result; // eax
int v13; // eax
char v14[16]; // [rsp+0h] [rbp-358h] BYREF
char buf[16]; // [rsp+10h] [rbp-348h] BYREF
__int64 v16[2]; // [rsp+20h] [rbp-338h] BYREF
char v17[88]; // [rsp+30h] [rbp-328h] BYREF
__int64 v18; // [rsp+88h] [rbp-2D0h] BYREF
struct utsname name; // [rsp+90h] [rbp-2C8h] BYREF
struct timeval tv; // [rsp+220h] [rbp-138h] BYREF
char s[256]; // [rsp+230h] [rbp-128h] BYREF
char v22; // [rsp+330h] [rbp-28h]

memset(s, 0, sizeof(s));
v22 = 0;
v16[0] = 0LL;
v16[1] = 0LL;
memset(v17, 0, sizeof(v17));
MD5Init(v17);
if ( argc <= 1 )
{
v4 = "iqn.2003-01.org.linux-iscsi";
}
else
{
v3 = argv[1];
if ( v3 )
{
if ( !strcmp(argv[1], "-h") || !strcmp(v3, "--help") )
{
puts("\nDisplays the iSCSI initiator name");
exit(0);
}
if ( strcmp(v3, "-p") )
{
puts("\nUsage: iscsi-iname [-h | --help | -p <prefix>]");
exit(0);
}
v4 = argv[2];
}
else
{
v4 = "iqn.2003-01.org.linux-iscsi";
}
}
v5 = open("/dev/urandom", 0);
v6 = v5;
if ( v5 )
{
v13 = read(v5, buf, 0x10uLL);
if ( v13 > 0 )
MD5Update(v17, buf, (unsigned int)v13);
close(v6);
}
if ( gettimeofday(&tv, 0LL) < 0 )
{
perror("error: gettimeofday failed");
result = 1;
}
else
{
MD5Update(v17, &tv, 8LL);
MD5Update(v17, &tv.tv_usec, 8LL);
v18 = gethostid();
MD5Update(v17, &v18, 8LL);
if ( uname(&name) < 0 )
{
perror("error: uname failed");
result = 1;
}
else
{
MD5Update(v17, &name, 65LL);
MD5Update(v17, name.nodename, 65LL);
MD5Update(v17, name.release, 65LL);
MD5Update(v17, name.version, 65LL);
MD5Update(v17, name.machine, 65LL);
MD5Final(v16, v17);
v7 = open("/dev/urandom", 0);
v8 = v7;
v9 = (unsigned __int8 *)v16;
if ( v7 )
{
if ( read(v7, buf, 1uLL) == 1 )
v9 = (unsigned __int8 *)v16 + buf[0] % 0xAu;
close(v8);
}
v10 = strchr(name.nodename, 46);
if ( v10 )
*v10 = 0;
snprintf(v14, 0x10uLL, "%s", name.machine);
v11 = strchr(v14, 95);
if ( v11 )
*v11 = 0;
sprintf(s, "%s.%s.%s:sn.%x%x%x%x%x%x", v4, name.nodename, v14, *v9, v9[1], v9[2], v9[3], v9[4], v9[5]);
v22 = 0;
puts(s);
result = 0;
}
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 char iname[256 + 1], *ptr;
 struct timeval time;
 struct utsname system_info;
 long hostid;
 struct MD5Context context;
 unsigned char digest[16];
 unsigned char *bytes = digest;
 unsigned char entropy[16], machine[16];
 int e;
 int fd;
 char *prefix;
 memset(iname, 0, sizeof (iname));
 memset(digest, 0, sizeof (digest));
 memset(&context, 0, sizeof (context));
 MD5Init(&context);
 if (argc > 1 && argv[1]) {
  prefix = argv[1];
  if (( strcmp(prefix, "-h") == 0 ) ||
      ( strcmp(prefix, "--help") == 0 )) {
   printf("\nDisplays the iSCSI initiator name\n");
   exit(0);
  } else if ( strcmp(prefix, "-p") == 0 ) {
   prefix = argv[2];
  } else {
   printf("\nUsage: iscsi-iname [-h | --help | "
          "-p <prefix>]\n");
   exit(0);
  }
 } else {
  prefix = "iqn.2003-01.org.linux-iscsi";
 }
 if ((fd = open("/dev/urandom", 00))) {
  e = read(fd, &entropy, 16);
  if (e >= 1)
   MD5Update(&context, (unsigned char *)entropy, e);
  close(fd);
 }
 if (gettimeofday(&time, ((void *)0)) < 0) {
  perror("error: gettimeofday failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) & time.tv_sec, sizeof (time.tv_sec));
 MD5Update(&context, (unsigned char *) & time.tv_usec, sizeof (time.tv_usec));
 hostid = gethostid();
 MD5Update(&context, (unsigned char *) & hostid, sizeof (hostid));
 if (uname(&system_info) < 0) {
  perror("error: uname failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) system_info.sysname,
    sizeof (system_info.sysname));
 MD5Update(&context, (unsigned char *) system_info.nodename,
    sizeof (system_info.nodename));
 MD5Update(&context, (unsigned char *) system_info.release,
    sizeof (system_info.release));
 MD5Update(&context, (unsigned char *) system_info.version,
    sizeof (system_info.version));
 MD5Update(&context, (unsigned char *) system_info.machine,
    sizeof (system_info.machine));
 MD5Final(digest, &context);
 if ((fd = open("/dev/urandom", 00))) {
  if (read(fd, entropy, 1) == 1)
   bytes = &digest[(entropy[0] % (sizeof(digest) - 6))];
  close(fd);
 }
 if ((ptr = strstr(system_info.nodename, ".")))
  (*ptr) = '\0';
 snprintf(machine, 16, "%s", system_info.machine);
 if ((ptr = strstr(machine, "_")))
  *ptr = '\0';
 sprintf(iname, "%s.%s.%s:sn.%x%x%x%x%x%x", prefix, system_info.nodename, machine,
  bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
 iname[sizeof (iname) - 1] = '\0';
 printf("%s\n", iname);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char iname[-1]; char *ptr;
 struct timeval time;
 struct utsname system_info;
 long hostid;
 struct MD5Context context;
 unsigned char digest[16];
 unsigned char *bytes = digest;
 unsigned char entropy[16]; unsigned char machine[16];
 int e;
 int fd;
 char *prefix;
 memset(iname, 0, sizeof (iname));
 memset(digest, 0, sizeof (digest));
 memset(&context, 0, sizeof (context));
 MD5Init(&context);
 if (argc > 1 && argv[1]) {
  prefix = argv[1];
  if (( strcmp(prefix, "-h") == 0 ) ||
      ( strcmp(prefix, "--help") == 0 )) {
   printf("\nDisplays the iSCSI initiator name\n");
   exit(0);
  } else if ( strcmp(prefix, "-p") == 0 ) {
   prefix = argv[2];
  } else {
   printf("\nUsage: iscsi-iname [-h | --help | "
          "-p <prefix>]\n");
   exit(0);
  }
 } else {
  prefix = "iqn.2003-01.org.linux-iscsi";
 }
 if ((fd = open("/dev/urandom", 00))) {
  e = read(fd, &entropy, 16);
  if (e >= 1)
   MD5Update(&context, (unsigned char *)entropy, e);
  close(fd);
 }
 if (gettimeofday(&time, ((void *)0)) < 0) {
  perror("error: gettimeofday failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) & time.tv_sec, sizeof (time.tv_sec));
 MD5Update(&context, (unsigned char *) & time.tv_usec, sizeof (time.tv_usec));
 hostid = gethostid();
 MD5Update(&context, (unsigned char *) & hostid, sizeof (hostid));
 if (uname(&system_info) < 0) {
  perror("error: uname failed");
  return 1;
 }
 MD5Update(&context, (unsigned char *) system_info.sysname,
    sizeof (system_info.sysname));
 MD5Update(&context, (unsigned char *) system_info.nodename,
    sizeof (system_info.nodename));
 MD5Update(&context, (unsigned char *) system_info.release,
    sizeof (system_info.release));
 MD5Update(&context, (unsigned char *) system_info.version,
    sizeof (system_info.version));
 MD5Update(&context, (unsigned char *) system_info.machine,
    sizeof (system_info.machine));
 MD5Final(digest, &context);
 if ((fd = open("/dev/urandom", 00))) {
  if (read(fd, entropy, 1) == 1)
   bytes = &digest[(entropy[0] % (sizeof(digest) - 6))];
  close(fd);
 }
 if ((ptr = strstr(system_info.nodename, ".")))
  (*ptr) = '\0';
 snprintf(machine, 16, "%s", system_info.machine);
 if ((ptr = strstr(machine, "_")))
  *ptr = '\0';
 sprintf(iname, "%s.%s.%s:sn.%x%x%x%x%x%x", prefix, system_info.nodename, machine,
  bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
 iname[sizeof (iname) - 1] = '\0';
 printf("%s\n", iname);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
iname
char [-1]

variable_types:
ptr
char *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types: hostid long

variable_types: struct MD5Context { unsigned int buf[4]; unsigned int bytes[2]; unsigned int in[16]; }

variable_types:
digest
unsigned char [16]

variable_types:
bytes
unsigned char *

variable_types:
entropy
unsigned char [16]

variable_types:
machine
unsigned char [16]

variable_types: e int

variable_types: fd int

variable_types:
prefix
char *


power

repo: DePierre/big-int

decompiled_code:
__int64 __fastcall power(unsigned int a1, int a2)
{
unsigned int v2; // edx
int i; // eax

if ( a2 <= 1 )
return a1;
v2 = a1;
for ( i = 1; i != a2; ++i )
v2 *= a1;
return v2;
}

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

if ( a2 <= 1 )
return a1;
v2 = a1;
for ( i = 1; i != a2; ++i )
v2 *= a1;
return v2;
}

original_code:
int power(int n, int p)
{
    int i, current = n;
    for(i = 1; i < p; i = i + 1)
        current = current*n;
    return current;
}

canonical_original_code:
int power(int n, int p)
{
    int i; int current = n;
    for(i = 1; i < p; i = i + 1)
        current = current*n;
    return current;
}

variable_types: n int

variable_types: p int

variable_types: i int

variable_types: current int


decompiled_code:
int clean_stdin()
{
int result; // eax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
result = scanf("%c", v1);
if ( result != 1 )
break;
result = (unsigned __int8)v1[0];
if ( v1[0] == 13 )
break;
}
while ( v1[0] != 10 );
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
result = scanf("%c", v1);
if ( result != 1 )
break;
result = (unsigned __int8)v1[0];
if ( v1[0] == 13 )
break;
}
while ( v1[0] != 10 );
return result;
}

original_code:
void clean_stdin()
{
    char c;
    while (scanf("%c",&c)==1 && c!=10 && c!=13);
}

variable_types: c char


decompiled_code:
__int64 display_menu()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0;
puts("Menu: ");
puts("1. Define the first big integer");
puts("2. Define the second big integer");
puts("3. Swap the two big integers");
puts("\n4. Sum big integers");
puts("5. Diff big integers");
puts("6. Mul big integers");
puts("\n7. Factorial");
puts("\n8. Print the big integers");
puts("\n9. Quit");
printf("\nChoice : ");
scanf("%d", v1);
putchar(10);
return v1[0];
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 0;
puts("Menu: ");
puts("1. Define the first big integer");
puts("2. Define the second big integer");
puts("3. Swap the two big integers");
puts("\n4. Sum big integers");
puts("5. Diff big integers");
puts("6. Mul big integers");
puts("\n7. Factorial");
puts("\n8. Print the big integers");
puts("\n9. Quit");
printf("\nChoice : ");
scanf("%d", v1);
putchar(10);
return v1[0];
}

original_code:
int display_menu()
{
    int choice = 0;
    printf("Menu: \n");
    printf("1. Define the first big integer\n");
    printf("2. Define the second big integer\n");
    printf("3. Swap the two big integers\n");
    printf("\n4. Sum big integers\n");
    printf("5. Diff big integers\n");
    printf("6. Mul big integers\n");
    printf("\n7. Factorial\n");
    printf("\n8. Print the big integers\n");
    printf("\n9. Quit\n");
    printf("\nChoice : ");
    scanf("%d", &choice);
    printf("\n");
    return choice;
}

variable_types: choice int


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
__int64 v4; // rbp
const char **v5; // r12
__int64 v6; // r13
unsigned int v7; // er15
_BYTE *v8; // rbx
int v9; // ebx
_BYTE *v10; // rbx
const char **v12; // [rsp+8h] [rbp-40h] BYREF

v12 = 0LL;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0;
while ( 1 )
{
v9 = display_menu(*(_QWORD *)&argc, argv, envp);
switch ( v9 )
{
case 1:
clean_stdin();
v8 = new_str_of_big_int(1u);
v6 = newBigInteger(v8);
free(v8);
break;
case 2:
clean_stdin();
v10 = new_str_of_big_int(2u);
v5 = (const char **)newBigInteger(v10);
free(v10);
break;
case 3:
v3 = fromBigIntegerToBigInteger(v6);
v6 = fromBigIntegerToBigInteger(v5);
v5 = (const char **)fromBigIntegerToBigInteger(v3);
break;
case 4:
argv = v5;
v4 = sumBigInt(v6, v5);
v7 = 43;
break;
case 5:
argv = v5;
v4 = diffBigInt(v6, v5);
v7 = 45;
break;
case 6:
argv = v5;
v4 = mulBigInt(v6, v5);
v7 = 42;
break;
case 7:
printf("Enter the number :\t");
scanf("%lu", &v12);
v4 = factorial(v12);
argv = v12;
printf("(%ld)! = ", v12);
printBigInteger(v4);
break;
case 8:
printf("BigInteger 1 :\t");
printBigInteger(v6);
printf("BigInteger 2:\t");
printBigInteger(v5);
if ( v7 )
{
argv = (const char **)v7;
printf("\n(1) %c (2) = ", v7);
printBigInteger(v4);
}
break;
default:
*(_QWORD *)&argc = 10LL;
putchar(10);
if ( v9 != 9 )
continue;
delete_big_int(v6);
delete_big_int(v5);
delete_big_int(v4);
delete_big_int(v3);
return 0;
}
*(_QWORD *)&argc = 10LL;
putchar(10);
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
__int64 v4; // rbp
const char **v5; // r12
__int64 v6; // r13
unsigned int v7; // er15
_BYTE *v8; // rbx
int v9; // ebx
_BYTE *v10; // rbx
const char **v12; // [rsp+8h] [rbp-40h] BYREF

v12 = 0LL;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0;
while ( 1 )
{
v9 = func0(*(_QWORD *)&argc, argv, envp);
switch ( v9 )
{
case 1:
clean_stdin();
v8 = new_str_of_big_int(1u);
v6 = newBigInteger(v8);
free(v8);
break;
case 2:
clean_stdin();
v10 = new_str_of_big_int(2u);
v5 = (const char **)newBigInteger(v10);
free(v10);
break;
case 3:
v3 = fromBigIntegerToBigInteger(v6);
v6 = fromBigIntegerToBigInteger(v5);
v5 = (const char **)fromBigIntegerToBigInteger(v3);
break;
case 4:
argv = v5;
v4 = sumBigInt(v6, v5);
v7 = 43;
break;
case 5:
argv = v5;
v4 = diffBigInt(v6, v5);
v7 = 45;
break;
case 6:
argv = v5;
v4 = mulBigInt(v6, v5);
v7 = 42;
break;
case 7:
printf("Enter the number :\t");
scanf("%lu", &v12);
v4 = factorial(v12);
argv = v12;
printf("(%ld)! = ", v12);
printBigInteger(v4);
break;
case 8:
printf("BigInteger 1 :\t");
printBigInteger(v6);
printf("BigInteger 2:\t");
printBigInteger(v5);
if ( v7 )
{
argv = (const char **)v7;
printf("\n(1) %c (2) = ", v7);
printBigInteger(v4);
}
break;
default:
*(_QWORD *)&argc = 10LL;
putchar(10);
if ( v9 != 9 )
continue;
delete_big_int(v6);
delete_big_int(v5);
delete_big_int(v4);
delete_big_int(v3);
return 0;
}
*(_QWORD *)&argc = 10LL;
putchar(10);
}
}

original_code:
int main(void)
{
    int choice = 0, lastOpe = 0;
    unsigned long fact = 0;
    char *str = ((void *)0);
    BigInteger biOne = ((void *)0), biTwo = ((void *)0), res = ((void *)0), temp = ((void *)0);
    do
    {
        choice = display_menu();
        switch(choice)
        {
            case 1:
                clean_stdin();
                str = new_str_of_big_int(1);
                biOne = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 2:
                clean_stdin();
                str = new_str_of_big_int(2);
                biTwo = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 3:
                temp = fromBigIntegerToBigInteger(biOne);
                biOne = fromBigIntegerToBigInteger(biTwo);
                biTwo = fromBigIntegerToBigInteger(temp);
                break;
            case 4:
                lastOpe = '+';
                res = sumBigInt(biOne, biTwo);
                break;
            case 5:
                lastOpe = '-';
                res = diffBigInt(biOne, biTwo);
                break;
            case 6:
                lastOpe = '*';
                res = mulBigInt(biOne, biTwo);
                break;
            case 7:
                printf("Enter the number :\t");
                scanf("%lu", &fact);
                res = factorial(fact);
                printf("(%ld)! = ", fact);
                printBigInteger(res);
                break;
            case 8:
                printf("BigInteger 1 :\t");
                printBigInteger(biOne);
                printf("BigInteger 2:\t");
                printBigInteger(biTwo);
                if(lastOpe != 0)
                {
                    printf("\n(1) %c (2) = ", lastOpe);
                    printBigInteger(res);
                }
                break;
        }
        printf("\n");
    }while (choice != 9);
    delete_big_int(biOne);
    delete_big_int(biTwo);
    delete_big_int(res);
    delete_big_int(temp);
    return 0;
}

canonical_original_code:
int main()
{
    int choice = 0; int lastOpe = 0;
    unsigned long fact = 0;
    char *str = ((void *)0);
    struct Struct_big_integer *biOne = ((void *)0); struct Struct_big_integer *biTwo = ((void *)0); struct Struct_big_integer *res = ((void *)0); struct Struct_big_integer *temp = ((void *)0);
    do
    {
        choice = display_menu();
        switch(choice)
        {
            case 1:
                clean_stdin();
                str = new_str_of_big_int(1);
                biOne = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 2:
                clean_stdin();
                str = new_str_of_big_int(2);
                biTwo = newBigInteger(str);
                free(str);
                str = ((void *)0);
                break;
            case 3:
                temp = fromBigIntegerToBigInteger(biOne);
                biOne = fromBigIntegerToBigInteger(biTwo);
                biTwo = fromBigIntegerToBigInteger(temp);
                break;
            case 4:
                lastOpe = '+';
                res = sumBigInt(biOne, biTwo);
                break;
            case 5:
                lastOpe = '-';
                res = diffBigInt(biOne, biTwo);
                break;
            case 6:
                lastOpe = '*';
                res = mulBigInt(biOne, biTwo);
                break;
            case 7:
                printf("Enter the number :\t");
                scanf("%lu", &fact);
                res = factorial(fact);
                printf("(%ld)! = ", fact);
                printBigInteger(res);
                break;
            case 8:
                printf("BigInteger 1 :\t");
                printBigInteger(biOne);
                printf("BigInteger 2:\t");
                printBigInteger(biTwo);
                if(lastOpe != 0)
                {
                    printf("\n(1) %c (2) = ", lastOpe);
                    printBigInteger(res);
                }
                break;
        }
        printf("\n");
    }while (choice != 9);
    delete_big_int(biOne);
    delete_big_int(biTwo);
    delete_big_int(res);
    delete_big_int(temp);
    return 0;
}

variable_types: lastOpe int

variable_types:
fact
unsigned long

variable_types:
str
char *

variable_types: struct Struct_big_integer { int sign; struct struct_dlist { unsigned int length; struct element { int key; struct element *next; struct element *prev; } *head; struct element *tail; } *list; } *

user_defined_types: struct Struct_big_integer { int sign; struct struct_dlist *list; }

user_defined_types: struct struct_dlist { unsigned int length; struct element *head; struct element *tail; }


repo: Detegr/dtgconf

decompiled_code:
void __fastcall item_free(__int64 a1)
{
void *v1; // rdi

free(*(void **)a1);
v1 = *(void **)(a1 + 8);
if ( v1 )
free(v1);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v1; // rdi

free(*(void **)a1);
v1 = *(void **)(a1 + 8);
if ( v1 )
free(v1);
}

original_code:
static void item_free(struct configitem *item)
{
 free(item->key);
 if(item->val) free(item->val);
}

variable_types: struct configitem { char *key; char *val; } *


original_code:
static void section_free(struct configsection *sect)
{
 free(sect->name);
 for(unsigned int i=0; i<sect->itemcount; ++i)
 {
  item_free(sect->items[i]);
  free(sect->items[i]);
 }
 free(sect->items);
}

canonical_original_code:
static void section_free(struct configsection *sect)
{
 free(sect->name);
 for(unsigned int i = 0; i<sect->itemcount; ++i)
 {
  item_free(sect->items[i]);
  free(sect->items[i]);
 }
 free(sect->items);
}

variable_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } *

variable_types:
i
unsigned int

user_defined_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem **items; }


decompiled_code:
__int64 __fastcall item_find(__int64 a1, __int64 a2)
{
int v2; // ecx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
result = binarysearch(*(_QWORD *)(a1 + 16), a2, 8LL, v2 - 1, (int (__fastcall *)(__int64, __int64))item_compare);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // ecx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
result = func2(*(_QWORD *)(a1 + 16), a2, 8LL, v2 - 1, (int (__fastcall *)(__int64, __int64))item_compare);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int item_find(struct configsection *haystack, const char *needle)
{
 if(haystack->itemcount)
 {
  return binarysearch(haystack->items, needle, sizeof(struct configitem*), haystack->itemcount-1, item_compare);
 }
 return -1;
}

canonical_original_code:
static int item_find(struct configsection *haystack, char *needle)
{
 if(haystack->itemcount)
 {
  return binarysearch(haystack->items, needle, sizeof(struct configitem *), haystack->itemcount-1, item_compare);
 }
 return -1;
}

variable_types:
needle
char *

user_defined_types: struct configitem { char *key; char *val; }


decompiled_code:
void __fastcall item_add(__int64 a1, const char *a2, const char *a3)
{
unsigned int v5; // eax
unsigned int v6; // esi
void *v7; // rax
_QWORD *v8; // r13
__int64 v9; // rdx
unsigned int v10; // eax

v5 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) >= v5 )
{
v6 = 2 * v5;
if ( !v5 )
v6 = 8;
*(_DWORD *)(a1 + 12) = v6;
v7 = realloc(*(void **)(a1 + 16), 8LL * v6);
if ( !v7 )
_assert_fail("newitems != NULL", "src/config.c", 0x58u, "item_add");
*(_QWORD *)(a1 + 16) = v7;
}
v8 = malloc(0x10uLL);
*v8 = strndup(a2, 0xFFuLL);
if ( a3 )
v8[1] = strndup(a3, 0xFFuLL);
else
v8[1] = 0LL;
v9 = *(_QWORD *)(a1 + 16);
v10 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v10 + 1;
*(_QWORD *)(v9 + 8LL * v10) = v8;
qsort(*(void **)(a1 + 16), *(unsigned int *)(a1 + 8), 8uLL, item_sort);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, const char *a2, const char *a3)
{
unsigned int v5; // eax
unsigned int v6; // esi
void *v7; // rax
_QWORD *v8; // r13
__int64 v9; // rdx
unsigned int v10; // eax

v5 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) >= v5 )
{
v6 = 2 * v5;
if ( !v5 )
v6 = 8;
*(_DWORD *)(a1 + 12) = v6;
v7 = realloc(*(void **)(a1 + 16), 8LL * v6);
if ( !v7 )
_assert_fail("newitems != NULL", "src/config.c", 0x58u, "item_add");
*(_QWORD *)(a1 + 16) = v7;
}
v8 = malloc(0x10uLL);
*v8 = strndup(a2, 0xFFuLL);
if ( a3 )
v8[1] = strndup(a3, 0xFFuLL);
else
v8[1] = 0LL;
v9 = *(_QWORD *)(a1 + 16);
v10 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = v10 + 1;
*(_QWORD *)(v9 + 8LL * v10) = v8;
qsort(*(void **)(a1 + 16), *(unsigned int *)(a1 + 8), 8uLL, item_sort);
}

original_code:
static void item_add(struct configsection *section, const char *key, const char *val)
{
 if(section->itemcount >= section->size)
 {
  section->size = section->size?section->size*2:8;
  struct configitem **newitems = (struct configitem**)realloc(section->items, section->size *sizeof(struct configitem*));
  ((newitems != ((void *)0)) ? (void) (0) : __assert_fail ("newitems != NULL", "src/config.c", 88, __extension__ __PRETTY_FUNCTION__));
  section->items=newitems;
 }
 struct configitem *newitem = (struct configitem*)malloc(sizeof(struct configitem));
 newitem->key = strndup(key, 255);
 if(val) newitem->val = strndup(val, 255);
 else newitem->val = ((void *)0);
 section->items[section->itemcount++] = newitem;
 qsort(section->items, section->itemcount, sizeof(struct configitem*), item_sort);
}

canonical_original_code:
static void item_add(struct configsection *section, char *key, char *val)
{
 if(section->itemcount >= section->size)
 {
  section->size = section->size?section->size*2:8;
  struct configitem **newitems = (struct configitem**)realloc(section->items, section->size *sizeof(struct configitem*));
  ((newitems != ((void *)0)) ? (void) (0) : __assert_fail ("newitems != NULL", "src/config.c", 88, __extension__ __PRETTY_FUNCTION__));
  section->items=newitems;
 }
 struct configitem *newitem = (struct configitem*)malloc(sizeof(struct configitem));
 newitem->key = strndup(key, 255);
 if(val) newitem->val = strndup(val, 255);
 else newitem->val = ((void *)0);
 section->items[section->itemcount++] = newitem;
 qsort(section->items, section->itemcount, sizeof(struct configitem *), item_sort);
}

variable_types:
key
char *

variable_types:
val
char *

variable_types: struct configitem { char *key; char *val; } **


decompiled_code:
int __fastcall item_sort(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func6(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

original_code:
static int item_sort(const void *a, const void *b)
{
 return strncmp((*(struct configitem**)a)->key,(*(struct configitem**)b)->key,255);
}

canonical_original_code:
static int item_sort(void *a, void *b)
{
 return strncmp((*(struct configitem **)a)->key,(*(struct configitem **)b)->key,255);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
int __fastcall section_sort(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
return strncmp(**(const char ***)a1, **(const char ***)a2, 0xFFuLL);
}

original_code:
static int section_sort(const void *a, const void *b)
{
 return strncmp((*(struct configsection**)a)->name,(*(struct configsection**)b)->name,255);
}

canonical_original_code:
static int section_sort(void *a, void *b)
{
 return strncmp((*(struct configsection **)a)->name,(*(struct configsection **)b)->name,255);
}


decompiled_code:
int __fastcall section_compare(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

original_code:
static int section_compare(const void *a, const void *b)
{
 return strncmp((const char*)a,(*(struct configsection**)b)->name,255);
}

canonical_original_code:
static int section_compare(void *a, void *b)
{
 return strncmp((char *)a,(*(struct configsection **)b)->name,255);
}


decompiled_code:
int __fastcall item_compare(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char ***a2)
{
return strncmp(a1, **a2, 0xFFuLL);
}

original_code:
static int item_compare(const void *a, const void *b)
{
 return strncmp((const char*)a,(*(struct configitem**)b)->key,255);
}

canonical_original_code:
static int item_compare(void *a, void *b)
{
 return strncmp((char *)a,(*(struct configitem **)b)->key,255);
}


decompiled_code:
void __fastcall config_free(__int64 a1)
{
unsigned int v1; // ebx

if ( *(_DWORD *)a1 )
{
v1 = 0;
do
{
section_free(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v1));
free(*(void **)(*(_QWORD *)(a1 + 8) + 8LL * v1++));
}
while ( *(_DWORD *)a1 > v1 );
}
free(*(void **)(a1 + 8));
}

original_code:
void config_free(struct config *conf)
{
 for(unsigned int i=0; i<conf->sectioncount; ++i)
 {
  section_free(conf->sections[i]);
  free(conf->sections[i]);
 }
 free(conf->sections);
}

canonical_original_code:
void config_free(struct config *conf)
{
 for(unsigned int i = 0; i<conf->sectioncount; ++i)
 {
  section_free(conf->sections[i]);
  free(conf->sections[i]);
 }
 free(conf->sections);
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } **sections; } *

user_defined_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection **sections; }


original_code:
void config_init(struct config *conf)
{
 conf->sectioncount = 0;
 conf->size = 0;
 conf->sections=((void *)0);
}


decompiled_code:
__int64 __fastcall config_find_section(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx

if ( !*(_DWORD *)a1 )
return 0LL;
v2 = binarysearch(
*(_QWORD *)(a1 + 8),
a2,
8LL,
*(_DWORD *)a1 - 1,
(int (__fastcall *)(__int64, __int64))section_compare);
v3 = 0LL;
if ( v2 >= 0 )
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx

if ( !*(_DWORD *)a1 )
return 0LL;
v2 = func2(
*(_QWORD *)(a1 + 8),
a2,
8LL,
*(_DWORD *)a1 - 1,
(int (__fastcall *)(__int64, __int64))section_compare);
v3 = 0LL;
if ( v2 >= 0 )
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v2);
return v3;
}

original_code:
struct configsection *config_find_section(struct config *haystack, const char *needle)
{
 if(haystack->sectioncount)
 {
  int i = binarysearch(haystack->sections, needle, sizeof(struct configsection*), haystack->sectioncount-1, section_compare);
  if(i>=0) return haystack->sections[i];
 }
 return ((void *)0);
}

canonical_original_code:
struct configsection *config_find_section(struct config *haystack, char *needle)
{
 if(haystack->sectioncount)
 {
  int i = binarysearch(haystack->sections, needle, sizeof(struct configsection*), haystack->sectioncount-1, section_compare);
  if(i>=0) return haystack->sections[i];
 }
 return ((void *)0);
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection **sections; } *

variable_types: i int

return_type: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } *


original_code:
struct configitem *config_find_item(struct config *haystack, const char *needle, const char *section)
{
 if(section)
 {
  struct configsection *sect;
  if((sect=config_find_section(haystack, section)))
  {
   int item=item_find(sect, needle);
   if(item != -1) return sect->items[item];
  }
 }
 else
 {
  for(unsigned int i=0; i<haystack->sectioncount; ++i)
  {
   int item=item_find(haystack->sections[i], needle);
   if(item != -1) return haystack->sections[i]->items[item];
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct configitem *config_find_item(struct config *haystack, char *needle, char *section)
{
 if(section)
 {
  struct configsection *sect;
  if((sect=config_find_section(haystack, section)))
  {
   int item = item_find(sect, needle);
   if(item != -1) return sect->items[item];
  }
 }
 else
 {
  for(unsigned int i = 0; i<haystack->sectioncount; ++i)
  {
   int item = item_find(haystack->sections[i], needle);
   if(item != -1) return haystack->sections[i]->items[item];
  }
 }
 return ((void *)0);
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem **items; } **sections; } *

variable_types:
section
char *

variable_types: item int

return_type: struct configitem { char *key; char *val; } *


decompiled_code:
__int64 random_char()
{
return (unsigned int)(rand() % 58 + 64);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)(rand() % 58 + 64);
}

original_code:
char random_char()
{
 int c = rand() % 58;
 if(c<64) c+=64;
 return (char)c;
}

variable_types: c int

return_type: char


original_code:
int main()
{
 struct config conf;
 if(config_load(&conf, "../example.conf"))
 {
  error("Failed to load example.conf\n");
 }
 for(unsigned i=0; i<conf.sectioncount; ++i)
 {
  printf("[%s]\n", conf.sections[i]->name);
  for(unsigned j=0; j<conf.sections[i]->itemcount; ++j)
  {
   char* key=conf.sections[i]->items[j]->key;
   char* val=conf.sections[i]->items[j]->val;
   printf("\t%s=%s\n", key, val?val:"NO VALUE");
  }
 }
 struct configsection* sect=config_find_section(&conf, "Second section");
 if(!sect) error("Second section not found\n");
 else
 {
  printf("Keys from %s:\n", sect->name);
  for(unsigned i=0; i<sect->itemcount; ++i)
  {
   printf("\t%s\n", sect->items[i]->key);
  }
 }
 struct configitem* item=config_find_item(&conf, "Key2", ((void *)0));
 printf("Item:\n\t%s=%s\n", item->key, item->val);
 srand(time(((void *)0)));
 int rnd=rand();
 char rndstr[12];
 snprintf(rndstr, 12, "%d", rnd);
 config_add(&conf, "First section", "Random value from example", rndstr);
 config_save(&conf, "../example.conf");
}

canonical_original_code:
int main()
{
 struct config conf;
 if(config_load(&conf, "../example.conf"))
 {
  error("Failed to load example.conf\n");
 }
 for(unsigned int i = 0; i<conf.sectioncount; ++i)
 {
  printf("[%s]\n", conf.sections[i]->name);
  for(unsigned int j = 0; j<conf.sections[i]->itemcount; ++j)
  {
   char *key = conf.sections[i]->items[j]->key;
   char *val = conf.sections[i]->items[j]->val;
   printf("\t%s=%s\n", key, val?val:"NO VALUE");
  }
 }
 struct configsection *sect = config_find_section(&conf, "Second section");
 if(!sect) error("Second section not found\n");
 else
 {
  printf("Keys from %s:\n", sect->name);
  for(unsigned int i = 0; i<sect->itemcount; ++i)
  {
   printf("\t%s\n", sect->items[i]->key);
  }
 }
 struct configitem *item = config_find_item(&conf, "Key2", ((void *)0));
 printf("Item:\n\t%s=%s\n", item->key, item->val);
 srand(time(((void *)0)));
 int rnd = rand();
 char rndstr[12];
 snprintf(rndstr, 12, "%d", rnd);
 config_add(&conf, "First section", "Random value from example", rndstr);
 config_save(&conf, "../example.conf");
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } **sections; }

variable_types:
j
unsigned int

variable_types: rnd int

variable_types:
rndstr
char [12]


error

decompiled_code:
void __fastcall __noreturn error(char *format)
{
fprintf(stderr, format);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *format)
{
fprintf(stderr, format);
exit(1);
}

original_code:
void error(const char* msg)
{
 fprintf(stderr, msg);
 exit(1);
}

canonical_original_code:
void error(char *msg)
{
 fprintf(stderr, msg);
 exit(1);
}

variable_types:
msg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // er13
const char **v4; // rax
const char *v5; // rdx
unsigned int v6; // ebx
__int64 v7; // rax
const char **v8; // rax
const char **v9; // rbp
unsigned int v10; // ebx
const char **v11; // rax
unsigned int v12; // eax
unsigned int v13; // eax
char s[12]; // [rsp+4h] [rbp-44h] BYREF
unsigned int v16; // [rsp+10h] [rbp-38h] BYREF
__int64 v17; // [rsp+18h] [rbp-30h]

if ( (unsigned int)config_load(&v16, "../example.conf", envp) )
error("Failed to load example.conf\n");
if ( v16 )
{
for ( i = 0; i < v16; ++i )
{
printf("[%s]\n", **(const char ***)(v17 + 8LL * i));
v7 = *(_QWORD *)(v17 + 8LL * i);
if ( *(_DWORD *)(v7 + 8) )
{
v6 = 0;
do
{
v4 = *(const char ***)(*(_QWORD *)(v7 + 16) + 8LL * v6);
v5 = v4[1];
if ( !v5 )
v5 = "NO VALUE";
printf("\t%s=%s\n", *v4, v5);
++v6;
v7 = *(_QWORD *)(v17 + 8LL * i);
}
while ( *(_DWORD *)(v7 + 8) > v6 );
}
}
}
v8 = (const char **)config_find_section(&v16, "Second section");
v9 = v8;
if ( !v8 )
error("Second section not found\n");
printf("Keys from %s:\n", *v8);
if ( *((_DWORD *)v9 + 2) )
{
v10 = 0;
do
printf("\t%s\n", **(const char ***)&v9[2][8 * v10++]);
while ( *((_DWORD *)v9 + 2) > v10 );
}
v11 = (const char **)config_find_item(&v16, "Key2", 0LL);
printf("Item:\n\t%s=%s\n", *v11, v11[1]);
v12 = time(0LL);
srand(v12);
v13 = rand();
snprintf(s, 0xCuLL, "%d", v13);
config_add(&v16, "First section", "Random value from example", s);
config_save(&v16, "../example.conf");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // er13
const char **v4; // rax
const char *v5; // rdx
unsigned int v6; // ebx
__int64 v7; // rax
const char **v8; // rax
const char **v9; // rbp
unsigned int v10; // ebx
const char **v11; // rax
unsigned int v12; // eax
unsigned int v13; // eax
char s[12]; // [rsp+4h] [rbp-44h] BYREF
unsigned int v16; // [rsp+10h] [rbp-38h] BYREF
__int64 v17; // [rsp+18h] [rbp-30h]

if ( (unsigned int)config_load(&v16, "../example.conf", envp) )
func0("Failed to load example.conf\n");
if ( v16 )
{
for ( i = 0; i < v16; ++i )
{
printf("[%s]\n", **(const char ***)(v17 + 8LL * i));
v7 = *(_QWORD *)(v17 + 8LL * i);
if ( *(_DWORD *)(v7 + 8) )
{
v6 = 0;
do
{
v4 = *(const char ***)(*(_QWORD *)(v7 + 16) + 8LL * v6);
v5 = v4[1];
if ( !v5 )
v5 = "NO VALUE";
printf("\t%s=%s\n", *v4, v5);
++v6;
v7 = *(_QWORD *)(v17 + 8LL * i);
}
while ( *(_DWORD *)(v7 + 8) > v6 );
}
}
}
v8 = (const char **)config_find_section(&v16, "Second section");
v9 = v8;
if ( !v8 )
func0("Second section not found\n");
printf("Keys from %s:\n", *v8);
if ( *((_DWORD *)v9 + 2) )
{
v10 = 0;
do
printf("\t%s\n", **(const char ***)&v9[2][8 * v10++]);
while ( *((_DWORD *)v9 + 2) > v10 );
}
v11 = (const char **)config_find_item(&v16, "Key2", 0LL);
printf("Item:\n\t%s=%s\n", *v11, v11[1]);
v12 = time(0LL);
srand(v12);
v13 = rand();
snprintf(s, 0xCuLL, "%d", v13);
config_add(&v16, "First section", "Random value from example", s);
config_save(&v16, "../example.conf");
return 0;
}

variable_types:
i
unsigned int

variable_types:
key
char *

variable_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **i; // rbp
std::ostream *v4; // r12
__int64 v5; // rax
_BYTE *v6; // r14
char v7; // si
std::ostream *v8; // rax
_QWORD *v9; // rbx
void **v10; // r12
void **v11; // r15
void **v12; // rdi
__int64 v13; // rax
__int64 v14; // rax
std::ostream *v15; // rax
_QWORD *v16; // rbx
char v17; // si
std::ostream *v18; // rax
std::ostream *v19; // rbp
__int64 v20; // rax
_BYTE *v21; // r12
__int64 (__fastcall *v22)(__int64, unsigned int); // rax
__int64 (__fastcall *v23)(__int64, unsigned int); // rax
unsigned int v24; // eax
unsigned int v25; // ebp
void **v27; // [rsp+10h] [rbp-2E8h] BYREF
void **v28; // [rsp+18h] [rbp-2E0h]
void *v29[2]; // [rsp+30h] [rbp-2C8h] BYREF
char v30; // [rsp+40h] [rbp-2B8h] BYREF
void *v31[2]; // [rsp+50h] [rbp-2A8h] BYREF
char v32[16]; // [rsp+60h] [rbp-298h] BYREF
void *v33[2]; // [rsp+70h] [rbp-288h] BYREF
char v34; // [rsp+80h] [rbp-278h] BYREF
void *v35[2]; // [rsp+90h] [rbp-268h] BYREF
char v36; // [rsp+A0h] [rbp-258h] BYREF
char v37[64]; // [rsp+B0h] [rbp-248h] BYREF
void *v38; // [rsp+F0h] [rbp-208h] BYREF
_QWORD *v39; // [rsp+F8h] [rbp-200h]
char v40; // [rsp+100h] [rbp-1F8h] BYREF
void *v41; // [rsp+130h] [rbp-1C8h] BYREF
void *v42; // [rsp+138h] [rbp-1C0h]
char v43[440]; // [rsp+140h] [rbp-1B8h] BYREF

std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v29,
"../../example/example.conf");
DtgConf::Config::Config(v37, v29);
DtgConf::Config::GetConfig((DtgConf::Config *)&v27);
for ( i = v27; v28 != i; i += 5 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[", 1LL);
v4 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *i, i[1]);
std::__ostream_insert<char,std::char_traits<char>>(v4, "]", 1LL);
v5 = *(_QWORD *)(*(_QWORD *)v4 - 24LL);
v6 = *(_BYTE **)((char *)v4 + v5 + 240);
if ( !v6 )
std::__throw_bad_cast();
if ( v6[56] )
{
v7 = v6[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v4 + v5 + 240));
v7 = 10;
v23 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v6 + 48LL);
if ( v23 != std::ctype<char>::do_widen )
v7 = v23((__int64)v6, 10u);
}
v8 = (std::ostream *)std::ostream::put(v4, v7);
std::ostream::flush(v8);
DtgConf::ConfigSection::Items[abi:cxx11](&v41, i);
v9 = v41;
v10 = (void **)v42;
if ( v41 != v42 )
{
do
{
PrintItem(v9);
v11 = (void **)v42;
v9 += 8;
}
while ( v42 != v9 );
v10 = (void **)v41;
if ( v9 != v41 )
{
do
{
v12 = (void **)v10[4];
if ( v12 != v10 + 6 )
operator delete(v12);
if ( *v10 != v10 + 2 )
operator delete(*v10);
v10 += 8;
}
while ( v11 != v10 );
v10 = (void **)v41;
}
}
if ( v10 )
operator delete(v10);
}
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)&v38,
"Second section");
DtgConf::Config::GetSection(&v41, v37, &v38);
if ( v38 != &v40 )
operator delete(v38);
v13 = std::operator<<<std::char_traits<char>>(&std::cout, "Keys from ");
v14 = std::__ostream_insert<char,std::char_traits<char>>(v13, v41, v42);
v15 = (std::ostream *)std::operator<<<std::char_traits<char>>(v14, ":");
std::endl<char,std::char_traits<char>>(v15);
DtgConf::ConfigSection::Items[abi:cxx11](&v38, &v41);
v16 = v38;
if ( v38 != v39 )
{
do
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "\t", 1LL);
v19 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *v16, v16[1]);
v20 = *(_QWORD *)(*(_QWORD *)v19 - 24LL);
v21 = *(_BYTE **)((char *)v19 + v20 + 240);
if ( !v21 )
std::__throw_bad_cast();
if ( v21[56] )
{
v17 = v21[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v19 + v20 + 240));
v17 = 10;
v22 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v21 + 48LL);
if ( v22 != std::ctype<char>::do_widen )
v17 = v22((__int64)v21, 10u);
}
v18 = (std::ostream *)std::ostream::put(v19, v17);
std::ostream::flush(v18);
v16 += 8;
}
while ( v39 != v16 );
}
std::vector<std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::~vector((__int64 *)&v38);
if ( v41 != v43 )
operator delete(v41);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string((__int64 *)&v41, "Key2");
DtgConf::Config::GetItem(&v38, v37, &v41);
if ( v41 != v43 )
operator delete(v41);
PrintItem(&v38);
v24 = time(0LL);
srand(v24);
v25 = rand();
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream(&v41);
std::ostream::operator<<(v43, v25);
v31[1] = 0LL;
v31[0] = v32;
v32[0] = 0;
std::operator>><char>(&v41, v31);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v35,
"Random value from example");
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v33,
"First section");
DtgConf::Config::Add(v37, v33, v35, v31);
if ( v33[0] != &v34 )
operator delete(v33[0]);
if ( v35[0] != &v36 )
operator delete(v35[0]);
DtgConf::Config::Save((DtgConf::Config *)v37);
if ( v31[0] != v32 )
operator delete(v31[0]);
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::~basic_stringstream(&v41);
std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>::~pair((__int64)&v38);
std::vector<DtgConf::ConfigSection>::~vector(&v27);
DtgConf::Config::~Config((DtgConf::Config *)v37);
if ( v29[0] != &v30 )
operator delete(v29[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **i; // rbp
std::ostream *v4; // r12
__int64 v5; // rax
_BYTE *v6; // r14
char v7; // si
std::ostream *v8; // rax
_QWORD *v9; // rbx
void **v10; // r12
void **v11; // r15
void **v12; // rdi
__int64 v13; // rax
__int64 v14; // rax
std::ostream *v15; // rax
_QWORD *v16; // rbx
char v17; // si
std::ostream *v18; // rax
std::ostream *v19; // rbp
__int64 v20; // rax
_BYTE *v21; // r12
__int64 (__fastcall *v22)(__int64, unsigned int); // rax
__int64 (__fastcall *v23)(__int64, unsigned int); // rax
unsigned int v24; // eax
unsigned int v25; // ebp
void **v27; // [rsp+10h] [rbp-2E8h] BYREF
void **v28; // [rsp+18h] [rbp-2E0h]
void *v29[2]; // [rsp+30h] [rbp-2C8h] BYREF
char v30; // [rsp+40h] [rbp-2B8h] BYREF
void *v31[2]; // [rsp+50h] [rbp-2A8h] BYREF
char v32[16]; // [rsp+60h] [rbp-298h] BYREF
void *v33[2]; // [rsp+70h] [rbp-288h] BYREF
char v34; // [rsp+80h] [rbp-278h] BYREF
void *v35[2]; // [rsp+90h] [rbp-268h] BYREF
char v36; // [rsp+A0h] [rbp-258h] BYREF
char v37[64]; // [rsp+B0h] [rbp-248h] BYREF
void *v38; // [rsp+F0h] [rbp-208h] BYREF
_QWORD *v39; // [rsp+F8h] [rbp-200h]
char v40; // [rsp+100h] [rbp-1F8h] BYREF
void *v41; // [rsp+130h] [rbp-1C8h] BYREF
void *v42; // [rsp+138h] [rbp-1C0h]
char v43[440]; // [rsp+140h] [rbp-1B8h] BYREF

std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v29,
"../../example/example.conf");
DtgConf::Config::Config(v37, v29);
DtgConf::Config::GetConfig((DtgConf::Config *)&v27);
for ( i = v27; v28 != i; i += 5 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[", 1LL);
v4 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *i, i[1]);
std::__ostream_insert<char,std::char_traits<char>>(v4, "]", 1LL);
v5 = *(_QWORD *)(*(_QWORD *)v4 - 24LL);
v6 = *(_BYTE **)((char *)v4 + v5 + 240);
if ( !v6 )
std::__throw_bad_cast();
if ( v6[56] )
{
v7 = v6[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v4 + v5 + 240));
v7 = 10;
v23 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v6 + 48LL);
if ( v23 != std::ctype<char>::do_widen )
v7 = v23((__int64)v6, 10u);
}
v8 = (std::ostream *)std::ostream::put(v4, v7);
std::ostream::flush(v8);
DtgConf::ConfigSection::Items[abi:cxx11](&v41, i);
v9 = v41;
v10 = (void **)v42;
if ( v41 != v42 )
{
do
{
func0(v9);
v11 = (void **)v42;
v9 += 8;
}
while ( v42 != v9 );
v10 = (void **)v41;
if ( v9 != v41 )
{
do
{
v12 = (void **)v10[4];
if ( v12 != v10 + 6 )
operator delete(v12);
if ( *v10 != v10 + 2 )
operator delete(*v10);
v10 += 8;
}
while ( v11 != v10 );
v10 = (void **)v41;
}
}
if ( v10 )
operator delete(v10);
}
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)&v38,
"Second section");
DtgConf::Config::GetSection(&v41, v37, &v38);
if ( v38 != &v40 )
operator delete(v38);
v13 = std::operator<<<std::char_traits<char>>(&std::cout, "Keys from ");
v14 = std::__ostream_insert<char,std::char_traits<char>>(v13, v41, v42);
v15 = (std::ostream *)std::operator<<<std::char_traits<char>>(v14, ":");
std::endl<char,std::char_traits<char>>(v15);
DtgConf::ConfigSection::Items[abi:cxx11](&v38, &v41);
v16 = v38;
if ( v38 != v39 )
{
do
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "\t", 1LL);
v19 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *v16, v16[1]);
v20 = *(_QWORD *)(*(_QWORD *)v19 - 24LL);
v21 = *(_BYTE **)((char *)v19 + v20 + 240);
if ( !v21 )
std::__throw_bad_cast();
if ( v21[56] )
{
v17 = v21[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v19 + v20 + 240));
v17 = 10;
v22 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v21 + 48LL);
if ( v22 != std::ctype<char>::do_widen )
v17 = v22((__int64)v21, 10u);
}
v18 = (std::ostream *)std::ostream::put(v19, v17);
std::ostream::flush(v18);
v16 += 8;
}
while ( v39 != v16 );
}
std::vector<std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::~func2((__int64 *)&v38);
if ( v41 != v43 )
operator delete(v41);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string((__int64 *)&v41, "Key2");
DtgConf::Config::GetItem(&v38, v37, &v41);
if ( v41 != v43 )
operator delete(v41);
func0(&v38);
v24 = time(0LL);
srand(v24);
v25 = rand();
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream(&v41);
std::ostream::operator<<(v43, v25);
v31[1] = 0LL;
v31[0] = v32;
v32[0] = 0;
std::operator>><char>(&v41, v31);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v35,
"Random value from example");
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v33,
"First section");
DtgConf::Config::Add(v37, v33, v35, v31);
if ( v33[0] != &v34 )
operator delete(v33[0]);
if ( v35[0] != &v36 )
operator delete(v35[0]);
DtgConf::Config::Save((DtgConf::Config *)v37);
if ( v31[0] != v32 )
operator delete(v31[0]);
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::~basic_stringstream(&v41);
std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>::~pair((__int64)&v38);
std::vector<DtgConf::ConfigSection>::~func2(&v27);
DtgConf::Config::~Config((DtgConf::Config *)v37);
if ( v29[0] != &v30 )
operator delete(v29[0]);
return 0;
}

variable_types:
val
char *

variable_types: struct configitem { char *key; char *val; } *


area

decompiled_code:
double __fastcall area(double (*a1)(void), double a2, double a3, double a4)
{
double v4; // r14
double v5; // r14
double v6; // r12
int v7; // er13
double v8; // r15
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]
double v12; // [rsp+10h] [rbp-58h]

v4 = a1();
v5 = (v4 + ((double (__fastcall *)(double))a1)(a3)) * 0.5 * (a3 - a2);
v6 = v5;
v7 = 2;
while ( 1 )
{
v12 = (a3 - a2) / (double)v7;
v10 = a2;
v11 = 0.0;
if ( a3 <= a2 )
{
v11 = 0.0;
}
else
{
do
{
v8 = ((double (__fastcall *)(double))a1)(v10);
v10 = v10 + v12;
v11 = (((double (__fastcall *)(double))a1)(v10) + v8) * 0.5 * v12 + v11;
}
while ( a3 > v10 );
}
v7 *= 2;
printf("area: %f, var: %f\n", v11, v6);
*(_QWORD *)&v6 = COERCE_UNSIGNED_INT64(v5 - v11) & LC3;
if ( v6 <= a4 )
break;
v5 = v11;
}
return v11;
}

canonical_decompiled_code:
double __fastcall func0(double (*a1)(void), double a2, double a3, double a4)
{
double v4; // r14
double v5; // r14
double v6; // r12
int v7; // er13
double v8; // r15
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]
double v12; // [rsp+10h] [rbp-58h]

v4 = a1();
v5 = (v4 + ((double (__fastcall *)(double))a1)(a3)) * 0.5 * (a3 - a2);
v6 = v5;
v7 = 2;
while ( 1 )
{
v12 = (a3 - a2) / (double)v7;
v10 = a2;
v11 = 0.0;
if ( a3 <= a2 )
{
v11 = 0.0;
}
else
{
do
{
v8 = ((double (__fastcall *)(double))a1)(v10);
v10 = v10 + v12;
v11 = (((double (__fastcall *)(double))a1)(v10) + v8) * 0.5 * v12 + v11;
}
while ( a3 > v10 );
}
v7 *= 2;
printf("area: %f, var: %f\n", v11, v6);
*(_QWORD *)&v6 = COERCE_UNSIGNED_INT64(v5 - v11) & LC3;
if ( v6 <= a4 )
break;
v5 = v11;
}
return v11;
}

original_code:
double area(double a, double b, double tolerance, double (*f)(double)){
 double h;
 int it = 2;
 double area = ((f(a) + f(b))/2.0)*(b-a);
 double var = area;
 do{
  double aux = area;
  area = 0.0;
  h = (b-a)/it;
  double step;
  for(step = a; step < b; step += h){
   area += ((f(step)+f(step+h))/2.0)*h;
  }
  it*=2;
  printf("area: %f, var: %f\n", area, var);
  var = fabs(aux - area);
 }while(var > tolerance);
 return area;
}

variable_types: a double

variable_types: b double

variable_types: tolerance double

variable_types:
f
double (*)(double)

variable_types: h double

variable_types: it int

variable_types: area double

variable_types: var double

variable_types: aux double

variable_types: step double

return_type: double


f

decompiled_code:
double __fastcall f(double a1)
{
return a1 * a1;
}

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

original_code:
double f(double x){
 return x*x;
}

canonical_original_code:
double f(double x){
 return x*x;
}

variable_types: x double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
area(f, argv, envp, 1.0, 5.0, 0.1);
printf("%f\n", *(double *)&LC2);
return 0;
}

original_code:
int main(){
 double tolerance = 0.1;
 double a = 1.0, b = 5.0;
 double integral = area(a, b, tolerance, f);
 printf("%f\n", integral);
 return 0;
}

canonical_original_code:
int main(){
 double tolerance = 0.1;
 double a = 1.0; double b = 5.0;
 double integral = area(a, b, tolerance, f);
 printf("%f\n", integral);
 return 0;
}

variable_types: integral double


ttinit

repo: DigitalMars/Empire-for-VMS

decompiled_code:
__int64 ttinit()
{
int v0; // edx
__int64 result; // rax

initscr();
noecho();
cbreak();
init_colors();
v0 = LINES;
result = (unsigned int)COLS;
if ( LINES >= 65 )
v0 = 64;
lines = v0;
if ( COLS >= 107 )
result = 106LL;
cols = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edx
__int64 result; // rax

initscr();
noecho();
cbreak();
init_colors();
v0 = LINES;
result = (unsigned int)COLS;
if ( LINES >= 65 )
v0 = 64;
lines = v0;
if ( COLS >= 107 )
result = 106LL;
cols = result;
return result;
}

original_code:
void
ttinit()
{
 (void) initscr();
 (void) noecho();
 (void) cbreak();
 init_colors();
 lines = LINES;
 cols = COLS;
 if (lines > 60 + 3 + 1)
  lines = 60 + 3 + 1;
 if (cols > 100 + 6)
  cols = 100 + 6;
}


decompiled_code:
__int64 clear_screen()
{
wclear(stdscr);
wrefresh(stdscr);
return kill_display();
}

canonical_decompiled_code:
__int64 func4()
{
wclear(stdscr);
wrefresh(stdscr);
return kill_display();
}

original_code:
void
clear_screen () {
 (void) wclear(stdscr);
 (void) wrefresh(stdscr);
 kill_display ();
}

canonical_original_code:
void clear_screen() {
 (void) wclear(stdscr);
 (void) wrefresh(stdscr);
 kill_display ();
}


redraw

decompiled_code:
int redraw()
{
clearok(curscr, 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func5()
{
clearok(curscr, 1);
return wrefresh(stdscr);
}

original_code:
void
redraw () {
 (void) clearok (curscr, 1);
 (void) wrefresh(stdscr);
}

canonical_original_code:
void redraw() {
 (void) clearok (curscr, 1);
 (void) wrefresh(stdscr);
}


delay

decompiled_code:
int delay()
{
wrefresh(stdscr);
return napms(delay_time);
}

canonical_decompiled_code:
int func6()
{
wrefresh(stdscr);
return napms(delay_time);
}

original_code:
void
delay () {
 (void) wrefresh(stdscr);
 (void) napms (delay_time);
}

canonical_original_code:
void delay() {
 (void) wrefresh(stdscr);
 (void) napms (delay_time);
}


decompiled_code:
int close_disp()
{
wmove(stdscr, LINES - 1, 0);
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

canonical_decompiled_code:
int func7()
{
wmove(stdscr, LINES - 1, 0);
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

original_code:
void
close_disp()
{
 (void) wmove(stdscr,(LINES - 1),(0));
 (void) wclrtoeol(stdscr);
 (void) wrefresh(stdscr);
 (void) endwin ();
}


empend

decompiled_code:
void __noreturn empend()
{
close_disp();
exit(0);
}

canonical_decompiled_code:
void __noreturn func14()
{
func7();
exit(0);
}

original_code:
void
empend ()
{
 close_disp ();
 exit (0);
}

canonical_original_code:
void empend()
{
 close_disp ();
 exit (0);
}


ver

decompiled_code:
int ver()
{
return waddnstr(stdscr, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988", -1);
}

canonical_decompiled_code:
int func15()
{
return waddnstr(stdscr, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988", -1);
}

original_code:
void
ver ()
{
        (void) waddnstr(stdscr,("EMPIRE, Version 5.00 site Amdahl 1-Apr-1988"),-1);
}

canonical_original_code:
void ver()
{
        (void) waddnstr(stdscr,("EMPIRE, Version 5.00 site Amdahl 1-Apr-1988"),-1);
}


check

decompiled_code:
__int64 check()
{
__int64 i; // rax
__int64 j; // rbp
_QWORD *v2; // rax
unsigned __int64 v3; // r14
__int64 k; // r12
__int64 l; // rbx
__int64 v6; // rax
_QWORD *v7; // rbx
__int64 m; // rbx
__int64 result; // rax

for ( i = 0LL; i != 5000; ++i )
{
in_free[i] = 0;
in_obj[i] = 0;
in_loc[i] = 0;
in_cargo[i] = 0;
}
for ( j = free_list; j; j = *(_QWORD *)j )
{
if ( in_free[0xEC4EC4EC4EC4EC5LL * ((j - (__int64)&object) >> 3)] )
assert("x", "util.c", 0x120u);
in_free[0xEC4EC4EC4EC4EC5LL * ((j - (__int64)&object) >> 3)] = 1;
if ( *(_WORD *)(j + 72) )
assert("x", "util.c", 0x122u);
v2 = *(_QWORD **)(j + 8);
if ( v2 && *v2 != j )
assert("x", "util.c", 0x124u);
}
v3 = (unsigned int)((_DWORD)map + 8);
for ( k = 0LL; k != 6000; ++k )
{
if ( *(_QWORD *)v3 && **(_QWORD **)v3 != k )
assert("x", "util.c", 0x12Du);
for ( l = *(_QWORD *)(v3 + 8); l; l = *(_QWORD *)(l + 16) )
{
if ( *(_QWORD *)(l + 56) != k )
assert("x", "util.c", 0x130u);
if ( *(__int16 *)(l + 72) <= 0 )
assert("x", "util.c", 0x131u);
if ( (unsigned int)(*(_DWORD *)(l + 48) - 1) > 1 )
assert("x", "util.c", 0x132u);
if ( in_loc[0xEC4EC4EC4EC4EC5LL * ((l - (__int64)&object) >> 3)] )
assert("x", "util.c", 0x135u);
in_loc[0xEC4EC4EC4EC4EC5LL * ((l - (__int64)&object) >> 3)] = 1;
v6 = *(_QWORD *)(l + 24);
if ( v6 && *(_QWORD *)(v6 + 16) != l )
assert("x", "util.c", 0x139u);
}
v3 += 24LL;
}
v7 = &city;
do
{
if ( (_QWORD *)map[3 * *v7 + 1] != v7 )
assert("x", "util.c", 0x140u);
v7 += 13;
}
while ( v7 != (_QWORD *)(unsigned int)((_DWORD)&city + 7280) );
check_obj((__int64)&comp_obj, 2);
check_obj((__int64)&user_obj, 1);
check_cargo(*((__int64 **)&user_obj + 5), 0);
check_cargo(*((__int64 **)&comp_obj + 5), 0);
check_cargo(*((__int64 **)&user_obj + 6), 1);
check_cargo(*((__int64 **)&comp_obj + 6), 1);
check_obj_cargo((char **)&comp_obj);
check_obj_cargo((char **)&user_obj);
for ( m = 0LL; m != 5000; ++m )
{
result = (unsigned int)in_loc[m];
if ( (_DWORD)result )
result = in_obj[m] != 0;
if ( in_free[m] == (_DWORD)result )
assert("x", "util.c", 0x156u);
}
return result;
}

original_code:
void
check () {
 void check_cargo(), check_obj(), check_obj_cargo();
 long i, j;
 piece_info_t *p;
 for (i = 0; i < 5000; i++) {
  in_free[i] = 0;
  in_obj[i] = 0;
  in_loc[i] = 0;
  in_cargo[i] = 0;
 }
 for (p = free_list; p != ((void *)0); p = p->piece_link.next) {
  i = p - object;
  if (!(!in_free[i])) assert ("x", "util.c", 288);;
  in_free[i] = 1;
  if (!(p->hits == 0)) assert ("x", "util.c", 290);;
  if (p->piece_link.prev)
   if (!(p->piece_link.prev->piece_link.next == p)) assert ("x", "util.c", 292);;
 }
 for (i = 0; i < (100 * 60); i++) {
  if (map[i].cityp) if (!(map[i].cityp->loc == i)) assert ("x", "util.c", 301);;
  for (p = map[i].objp; p != ((void *)0); p = p->loc_link.next) {
   if (!(p->loc == i)) assert ("x", "util.c", 304);;
   if (!(p->hits > 0)) assert ("x", "util.c", 305);;
   if (!(p->owner == 1 || p->owner == 2)) assert ("x", "util.c", 306);;
   j = p - object;
   if (!(!in_loc[j])) assert ("x", "util.c", 309);;
   in_loc[j] = 1;
   if (p->loc_link.prev)
    if (!(p->loc_link.prev->loc_link.next == p)) assert ("x", "util.c", 313);;
  }
 }
 for (i = 0; i < 70; i++)
  if (!(map[city[i].loc].cityp == &(city[i]))) assert ("x", "util.c", 320);;
 check_obj (comp_obj, 2);
 check_obj (user_obj, 1);
 check_cargo (user_obj[5], 0);
 check_cargo (comp_obj[5], 0);
 check_cargo (user_obj[6], 1);
 check_cargo (comp_obj[6], 1);
 check_obj_cargo (comp_obj);
 check_obj_cargo (user_obj);
 for (i = 0; i < 5000; i++)
  if (!(in_free[i] != (in_loc[i] && in_obj[i]))) assert ("x", "util.c", 342);;
}

canonical_original_code:
void check() {
 void check_cargo(); void check_obj(); void check_obj_cargo();
 long i; long j;
 struct piece_info *p;
 for (i = 0; i < 5000; i++) {
  in_free[i] = 0;
  in_obj[i] = 0;
  in_loc[i] = 0;
  in_cargo[i] = 0;
 }
 for (p = free_list; p != ((void *)0); p = p->piece_link.next) {
  i = p - object;
  if (!(!in_free[i])) assert ("x", "util.c", 288);;
  in_free[i] = 1;
  if (!(p->hits == 0)) assert ("x", "util.c", 290);;
  if (p->piece_link.prev)
   if (!(p->piece_link.prev->piece_link.next == p)) assert ("x", "util.c", 292);;
 }
 for (i = 0; i < (100 * 60); i++) {
  if (map[i].cityp) if (!(map[i].cityp->loc == i)) assert ("x", "util.c", 301);;
  for (p = map[i].objp; p != ((void *)0); p = p->loc_link.next) {
   if (!(p->loc == i)) assert ("x", "util.c", 304);;
   if (!(p->hits > 0)) assert ("x", "util.c", 305);;
   if (!(p->owner == 1 || p->owner == 2)) assert ("x", "util.c", 306);;
   j = p - object;
   if (!(!in_loc[j])) assert ("x", "util.c", 309);;
   in_loc[j] = 1;
   if (p->loc_link.prev)
    if (!(p->loc_link.prev->loc_link.next == p)) assert ("x", "util.c", 313);;
  }
 }
 for (i = 0; i < 70; i++)
  if (!(map[city[i].loc].cityp == &(city[i]))) assert ("x", "util.c", 320);;
 check_obj (comp_obj, 2);
 check_obj (user_obj, 1);
 check_cargo (user_obj[5], 0);
 check_cargo (comp_obj[5], 0);
 check_cargo (user_obj[6], 1);
 check_cargo (comp_obj[6], 1);
 check_obj_cargo (comp_obj);
 check_obj_cargo (user_obj);
 for (i = 0; i < 5000; i++)
  if (!(in_free[i] != (in_loc[i] && in_obj[i]))) assert ("x", "util.c", 342);;
}

variable_types: i long

variable_types: j long

variable_types: struct piece_info { struct link_t { struct piece_info *next; struct piece_info *prev; } piece_link; struct link_t loc_link; struct link_t cargo_link; int owner; int type; long loc; long func; short hits; int moved; struct piece_info *ship; struct piece_info *cargo; short count; short range; } *

user_defined_types: struct piece_info { struct link_t piece_link; struct link_t loc_link; struct link_t cargo_link; int owner; int type; long loc; long func; short hits; int moved; struct piece_info *ship; struct piece_info *cargo; short count; short range; }


decompiled_code:
__int64 __fastcall c_give(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdi
__int64 i; // rax
__int64 *v5; // rcx
__int64 result; // rax
int v7[74]; // [rsp+0h] [rbp-128h]

v2 = (unsigned int)((_DWORD)city + 8);
v3 = 0LL;
for ( i = 0LL; i != 70; ++i )
{
if ( !*(_BYTE *)v2 )
v7[v3++] = i;
v2 += 104LL;
}
if ( v3 )
{
v5 = &city[13 * v7[irand(v3, a2, v2)]];
*((_BYTE *)v5 + 8) = 2;
*((_BYTE *)v5 + 96) = -1;
v5[11] = 0LL;
result = scan(&comp_map, *v5);
}
else
{
error((int)"There are no unowned cities.", 0, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
result = ksend("There are no unowned cities.", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdi
__int64 i; // rax
__int64 *v5; // rcx
__int64 result; // rax
int v7[74]; // [rsp+0h] [rbp-128h]

v2 = (unsigned int)((_DWORD)city + 8);
v3 = 0LL;
for ( i = 0LL; i != 70; ++i )
{
if ( !*(_BYTE *)v2 )
v7[v3++] = i;
v2 += 104LL;
}
if ( v3 )
{
v5 = &city[13 * v7[irand(v3, a2, v2)]];
*((_BYTE *)v5 + 8) = 2;
*((_BYTE *)v5 + 96) = -1;
v5[11] = 0LL;
result = scan(&comp_map, *v5);
}
else
{
error((int)"There are no unowned cities.", 0, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
result = ksend("There are no unowned cities.", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return result;
}

original_code:
void
c_give () {
 int unowned[70];
 long i, count;
 count = 0;
 for (i = 0; i < 70; i++) {
  if (city[i].owner == 0) {
   unowned[count] = i;
   count += 1;
  }
 }
 if (count == 0) {
  error ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  ksend ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  return;
 }
 i = irand (count);
 i = unowned[i];
 city[i].owner = 2;
 city[i].prod = ((char)255);
 city[i].work = 0;
 scan (comp_map, city[i].loc);
}

canonical_original_code:
void c_give() {
 int unowned[70];
 long i; long count;
 count = 0;
 for (i = 0; i < 70; i++) {
  if (city[i].owner == 0) {
   unowned[count] = i;
   count += 1;
  }
 }
 if (count == 0) {
  error ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  ksend ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  return;
 }
 i = irand (count);
 i = unowned[i];
 city[i].owner = 2;
 city[i].prod = ((char)255);
 city[i].work = 0;
 scan (comp_map, city[i].loc);
}

variable_types:
unowned
int [70]

variable_types: count long


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

result = getyn("QUIT - Are you sure? ");
if ( (_DWORD)result )
result = empend();
return result;
}

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

result = getyn("QUIT - Are you sure? ");
if ( (_DWORD)result )
result = empend();
return result;
}

original_code:
void
c_quit () {
 if (getyn ("QUIT - Are you sure? ")) {
     empend ();
 }
}

canonical_original_code:
void c_quit() {
 if (getyn ("QUIT - Are you sure? ")) {
     empend ();
 }
}


decompiled_code:
__int64 c_sector()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(1LL, &user_map, v0);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(1LL, &user_map, v0);
}

original_code:
void
c_sector () {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(1,user_map,num);
}

canonical_original_code:
void c_sector() {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(1,user_map,num);
}

variable_types: num int


decompiled_code:
__int64 c_examine()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(2LL, &comp_map, v0);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(2LL, &comp_map, v0);
}

original_code:
void
c_examine () {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(2,comp_map,num);
}

canonical_original_code:
void c_examine() {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(2,comp_map,num);
}


decompiled_code:
void __noreturn c_movie()
{
wclear(stdscr);
while ( 1 )
{
comp_move(1LL);
print_zoom(&comp_map);
save_game();
}
}

canonical_decompiled_code:
void __noreturn func5()
{
wclear(stdscr);
while ( 1 )
{
comp_move(1LL);
print_zoom(&comp_map);
save_game();
}
}

original_code:
void
c_movie () {
 (void) wclear(stdscr);
 for (;;) {
  comp_move (1);
  print_zoom (comp_map);
  save_game ();
 }
}

canonical_original_code:
void c_movie() {
 (void) wclear(stdscr);
 for (;;) {
  comp_move (1);
  print_zoom (comp_map);
  save_game ();
 }
}


empire

decompiled_code:
void __noreturn empire()
{
int v0; // ebx
char v1; // al

ttinit();
rndini();
clear_screen();
wmove(stdscr, 7, 0);
ver();
pos_str(8LL, 0LL, "Detailed directions are in EMPIRE.DOC\n", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
if ( !(unsigned int)restore_game() )
init_game();
v0 = 0;
while ( 1 )
{
if ( automove )
{
user_move();
comp_move(1LL);
if ( !(++v0 % save_interval) )
save_game();
}
else
{
prompt(0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
prompt("Your orders? ", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
v1 = get_chx();
do_command((unsigned int)v1, 0LL);
}
}
}

canonical_decompiled_code:
void __noreturn func8()
{
int v0; // ebx
char v1; // al

ttinit();
rndini();
clear_screen();
wmove(stdscr, 7, 0);
ver();
pos_str(8LL, 0LL, "Detailed directions are in EMPIRE.DOC\n", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
if ( !(unsigned int)restore_game() )
init_game();
v0 = 0;
while ( 1 )
{
if ( automove )
{
user_move();
comp_move(1LL);
if ( !(++v0 % save_interval) )
save_game();
}
else
{
prompt(0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
prompt("Your orders? ", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
v1 = get_chx();
func7((unsigned int)v1, 0LL);
}
}
}

original_code:
void
empire () {
 void do_command();
 void print_zoom();
 char order;
 int turn = 0;
 ttinit ();
 rndini ();
 clear_screen ();
 (void) wmove(stdscr,(7),(0));
 ver ();
 pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n",0,0,0,0,0,0,0,0);
 (void) wrefresh(stdscr);
 if (!restore_game ())
  init_game ();
 for (;;) {
     if (automove) {
  user_move ();
  comp_move (1);
  if (++turn % save_interval == 0)
   save_game ();
     }
     else {
  prompt (0,0,0,0,0,0,0,0,0);
  (void) wrefresh(stdscr);
         prompt ("Your orders? ",0,0,0,0,0,0,0,0);
         order = get_chx ();
  do_command (order);
     }
 }
}

canonical_original_code:
void empire() {
 void do_command();
 void print_zoom();
 char order;
 int turn = 0;
 ttinit ();
 rndini ();
 clear_screen ();
 (void) wmove(stdscr,(7),(0));
 ver ();
 pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n",0,0,0,0,0,0,0,0);
 (void) wrefresh(stdscr);
 if (!restore_game ())
  init_game ();
 for (;;) {
     if (automove) {
  user_move ();
  comp_move (1);
  if (++turn % save_interval == 0)
   save_game ();
     }
     else {
  prompt (0,0,0,0,0,0,0,0,0);
  (void) wrefresh(stdscr);
         prompt ("Your orders? ",0,0,0,0,0,0,0,0);
         order = get_chx ();
  do_command (order);
     }
 }
}

variable_types: order char

variable_types: turn int


rndini

decompiled_code:
void rndini()
{
unsigned __int16 v0; // ax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned __int16 v0; // ax

v0 = time(0LL);
srand(v0);
}

original_code:
void rndini()
{
 srand((unsigned)(time(0) & 0xFFFF));
}

canonical_original_code:
void rndini()
{
 srand((unsigned int)(time(0) & 0xFFFF));
}