run

decompiled_code:
void run()
{
unsigned __int16 v0; // bx

while ( 1 )
{
v0 = *((_WORD *)&ram + LOWORD(regs[2]));
puts("----- NEW INSTRUCTION -----");
printf("%04x -- o: %x, b: %x, a: %x\n", v0, v0 & 0xF, ((int)v0 >> 4) & 0x3F, (v0 >> 10) & 0x3F);
printRam(0LL, 4LL);
printRegisters();
switch ( v0 & 0xF )
{
case 0:
specialInstruction(v0);
break;
case 1:
setInst(v0);
break;
case 2:
addInst(v0);
break;
case 3:
subInst(v0);
break;
case 4:
mulInst(v0);
break;
case 5:
mliInst(v0);
break;
case 6:
divInst(v0);
break;
case 7:
dviInst(v0);
break;
case 8:
modInst(v0);
break;
case 9:
mdiInst(v0);
break;
case 0xA:
andInst(v0);
break;
case 0xB:
borInst(v0);
break;
case 0xC:
xorInst(v0);
break;
case 0xD:
shrInst(v0);
break;
case 0xE:
asrInst(v0);
break;
case 0xF:
shlInst(v0);
break;
}
++LOWORD(regs[2]);
}
}

canonical_decompiled_code:
void func3()
{
unsigned __int16 v0; // bx

while ( 1 )
{
v0 = *((_WORD *)&ram + LOWORD(regs[2]));
puts("----- NEW INSTRUCTION -----");
printf("%04x -- o: %x, b: %x, a: %x\n", v0, v0 & 0xF, ((int)v0 >> 4) & 0x3F, (v0 >> 10) & 0x3F);
printRam(0LL, 4LL);
func2();
switch ( v0 & 0xF )
{
case 0:
func1(v0);
break;
case 1:
setInst(v0);
break;
case 2:
addInst(v0);
break;
case 3:
subInst(v0);
break;
case 4:
mulInst(v0);
break;
case 5:
mliInst(v0);
break;
case 6:
divInst(v0);
break;
case 7:
dviInst(v0);
break;
case 8:
modInst(v0);
break;
case 9:
mdiInst(v0);
break;
case 0xA:
andInst(v0);
break;
case 0xB:
borInst(v0);
break;
case 0xC:
xorInst(v0);
break;
case 0xD:
shrInst(v0);
break;
case 0xE:
asrInst(v0);
break;
case 0xF:
shlInst(v0);
break;
}
++LOWORD(regs[2]);
}
}

original_code:
void run() {
  uint16_t instruction = 0x0;
  uint8_t opCode = 0x0;
  while (1) {
    instruction = ram[regs.PC];
    opCode = ((instruction & 0b0000000000001111) >> 0);
    printf("----- NEW INSTRUCTION -----\n");
    printf("%04x -- o: %x, b: %x, a: %x\n", instruction, ((instruction & 0b0000000000001111) >> 0), ((instruction & 0b0000001111110000) >> 4) , ((instruction & 0b1111110000000000) >> 10));
    printRam(0,4);
    printRegisters();
    switch (opCode) {
      case 0x00 :
        specialInstruction(instruction);
        break;
      case 0x01 :
        setInst(instruction);
        break;
      case 0x02 :
        addInst(instruction);
        break;
      case 0x03 :
        subInst(instruction);
        break;
      case 0x04 :
        mulInst(instruction);
        break;
      case 0x05 :
        mliInst(instruction);
        break;
      case 0x06 :
        divInst(instruction);
        break;
      case 0x07 :
        dviInst(instruction);
        break;
      case 0x08 :
        modInst(instruction);
        break;
      case 0x09 :
        mdiInst(instruction);
        break;
      case 0x0a :
        andInst(instruction);
        break;
      case 0x0b :
        borInst(instruction);
        break;
      case 0x0c :
        xorInst(instruction);
        break;
      case 0x0d :
        shrInst(instruction);
        break;
      case 0x0e :
        asrInst(instruction);
        break;
      case 0x0f :
        shlInst(instruction);
        break;
      case 0x10 :
        ifbInst(instruction);
        break;
      case 0x11 :
        ifcInst(instruction);
        break;
      case 0x12 :
        ifeInst(instruction);
        break;
      case 0x13 :
        ifnInst(instruction);
        break;
      case 0x14 :
        ifgInst(instruction);
        break;
      case 0x15 :
        ifaInst(instruction);
        break;
      case 0x16 :
        iflInst(instruction);
        break;
      case 0x17 :
        ifuInst(instruction);
        break;
      case 0x18 :
        break;
      case 0x19 :
        break;
      case 0x1a :
        adxInst(instruction);
        break;
      case 0x1b :
        sbxInst(instruction);
        break;
      case 0x1c :
        break;
      case 0x1d :
        break;
      case 0x1e :
        sdiInst(instruction);
        break;
      case 0x1f :
        stdInst(instruction);
        break;
      default :
        printf("Unknown opCode : %x\nExiting\n", opCode);
        exit(1);
        break;
    }
    regs.PC++;
  }
}

canonical_original_code:
void run() {
  unsigned short instruction = 0x0;
  unsigned char opCode = 0x0;
  while (1) {
    instruction = ram[regs.PC];
    opCode = ((instruction & 0b0000000000001111) >> 0);
    printf("----- NEW INSTRUCTION -----\n");
    printf("%04x -- o: %x, b: %x, a: %x\n", instruction, ((instruction & 0b0000000000001111) >> 0), ((instruction & 0b0000001111110000) >> 4) , ((instruction & 0b1111110000000000) >> 10));
    printRam(0,4);
    printRegisters();
    switch (opCode) {
      case 0x00 :
        specialInstruction(instruction);
        break;
      case 0x01 :
        setInst(instruction);
        break;
      case 0x02 :
        addInst(instruction);
        break;
      case 0x03 :
        subInst(instruction);
        break;
      case 0x04 :
        mulInst(instruction);
        break;
      case 0x05 :
        mliInst(instruction);
        break;
      case 0x06 :
        divInst(instruction);
        break;
      case 0x07 :
        dviInst(instruction);
        break;
      case 0x08 :
        modInst(instruction);
        break;
      case 0x09 :
        mdiInst(instruction);
        break;
      case 0x0a :
        andInst(instruction);
        break;
      case 0x0b :
        borInst(instruction);
        break;
      case 0x0c :
        xorInst(instruction);
        break;
      case 0x0d :
        shrInst(instruction);
        break;
      case 0x0e :
        asrInst(instruction);
        break;
      case 0x0f :
        shlInst(instruction);
        break;
      case 0x10 :
        ifbInst(instruction);
        break;
      case 0x11 :
        ifcInst(instruction);
        break;
      case 0x12 :
        ifeInst(instruction);
        break;
      case 0x13 :
        ifnInst(instruction);
        break;
      case 0x14 :
        ifgInst(instruction);
        break;
      case 0x15 :
        ifaInst(instruction);
        break;
      case 0x16 :
        iflInst(instruction);
        break;
      case 0x17 :
        ifuInst(instruction);
        break;
      case 0x18 :
        break;
      case 0x19 :
        break;
      case 0x1a :
        adxInst(instruction);
        break;
      case 0x1b :
        sbxInst(instruction);
        break;
      case 0x1c :
        break;
      case 0x1d :
        break;
      case 0x1e :
        sdiInst(instruction);
        break;
      case 0x1f :
        stdInst(instruction);
        break;
      default :
        printf("Unknown opCode : %x\nExiting\n", opCode);
        exit(1);
        break;
    }
    regs.PC++;
  }
}


decompiled_code:
__int64 __fastcall assstack_find(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
size_t v3; // rbp

v2 = a1;
if ( a1 )
{
v3 = *(_QWORD *)(a2 + 8);
do
{
if ( *(_QWORD *)(v2 + 8) == v3 && !memcmp(*(const void **)v2, *(const void **)a2, v3) )
break;
v2 = *(_QWORD *)(v2 + 32);
}
while ( v2 );
}
return v2;
}

original_code:
struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key) {
    for (; stack; stack = stack->next)
 if (stack->key.len == key->len && !memcmp(stack->key.data, key->data, key->len))
     return stack;
    return ((void *)0);
}

variable_types:
stack
struct assstack_entry *

variable_types:
key
struct string *

return_type: struct assstack_entry { struct string { void *data; unsigned long len; } key; struct string val; struct assstack_entry *next; } *

user_defined_types: struct assstack_entry { struct string key; struct string val; struct assstack_entry *next; }


printsoa

decompiled_code:
int __fastcall printsoa(__int64 *a1)
{
__int64 v2; // rbp
unsigned __int64 v3; // rbx
char v4; // di
unsigned __int64 v5; // rbx
char v6; // di
unsigned __int64 v7; // rbx
char v8; // di
unsigned __int64 v9; // rbx

v2 = *a1;
v3 = 0LL;
while ( a1[1] > v3 )
{
putchar(*(char *)(v2 + v3++));
if ( *(_BYTE *)(v2 + v3 - 1) == 32 )
{
do
{
if ( a1[1] <= v3 )
break;
putchar(*(char *)(v2 + v3++));
}
while ( *(_BYTE *)(v2 + v3 - 1) != 32 );
break;
}
}
printf("(\n\t\t\t\t");
do
{
if ( a1[1] <= v3 )
break;
putchar(*(char *)(v2 + v3++));
}
while ( *(_BYTE *)(v2 + v3 - 1) != 32 );
printf("; Serialnumber\n\t\t\t\t");
while ( a1[1] > v3 )
{
v4 = *(_BYTE *)(v2 + v3);
if ( v4 == 32 )
break;
++v3;
putchar(v4);
}
v5 = v3 + 1;
printf("\t; Refresh\n\t\t\t\t");
while ( a1[1] > v5 )
{
v6 = *(_BYTE *)(v2 + v5);
if ( v6 == 32 )
break;
++v5;
putchar(v6);
}
v7 = v5 + 1;
printf("\t; Retry\n\t\t\t\t");
while ( a1[1] > v7 )
{
v8 = *(_BYTE *)(v2 + v7);
if ( v8 == 32 )
break;
++v7;
putchar(v8);
}
v9 = v7 + 1;
printf("\t; Expire\n\t\t\t\t");
while ( a1[1] > v9 )
{
++v9;
putchar(*(char *)(v2 + v9 - 1));
}
return puts(" )\t; Minimum TTL");
}

canonical_decompiled_code:
int __fastcall func3(__int64 *a1)
{
__int64 v2; // rbp
unsigned __int64 v3; // rbx
char v4; // di
unsigned __int64 v5; // rbx
char v6; // di
unsigned __int64 v7; // rbx
char v8; // di
unsigned __int64 v9; // rbx

v2 = *a1;
v3 = 0LL;
while ( a1[1] > v3 )
{
putchar(*(char *)(v2 + v3++));
if ( *(_BYTE *)(v2 + v3 - 1) == 32 )
{
do
{
if ( a1[1] <= v3 )
break;
putchar(*(char *)(v2 + v3++));
}
while ( *(_BYTE *)(v2 + v3 - 1) != 32 );
break;
}
}
printf("(\n\t\t\t\t");
do
{
if ( a1[1] <= v3 )
break;
putchar(*(char *)(v2 + v3++));
}
while ( *(_BYTE *)(v2 + v3 - 1) != 32 );
printf("; Serialnumber\n\t\t\t\t");
while ( a1[1] > v3 )
{
v4 = *(_BYTE *)(v2 + v3);
if ( v4 == 32 )
break;
++v3;
putchar(v4);
}
v5 = v3 + 1;
printf("\t; Refresh\n\t\t\t\t");
while ( a1[1] > v5 )
{
v6 = *(_BYTE *)(v2 + v5);
if ( v6 == 32 )
break;
++v5;
putchar(v6);
}
v7 = v5 + 1;
printf("\t; Retry\n\t\t\t\t");
while ( a1[1] > v7 )
{
v8 = *(_BYTE *)(v2 + v7);
if ( v8 == 32 )
break;
++v7;
putchar(v8);
}
v9 = v7 + 1;
printf("\t; Expire\n\t\t\t\t");
while ( a1[1] > v9 )
{
++v9;
putchar(*(char *)(v2 + v9 - 1));
}
return puts(" )\t; Minimum TTL");
}

original_code:
void printsoa(struct string *soa) {
    char *s;
    size_t i;
    s = (char *)soa->data;
    i = 0;
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("(\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("; Serialnumber\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Refresh\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Retry\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Expire\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i++]);
    }
    printf(" )\t; Minimum TTL\n");
}

canonical_original_code:
void printsoa(struct string *soa) {
    char *s;
    unsigned long i;
    s = (char *)soa->data;
    i = 0;
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("(\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("; Serialnumber\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Refresh\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Retry\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Expire\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i++]);
    }
    printf(" )\t; Minimum TTL\n");
}

variable_types: struct string { void *data; unsigned long len; } *

variable_types:
s
char *

variable_types:
i
unsigned long

return_type: void


printrrs

decompiled_code:
int __fastcall printrrs(char *s1, __int64 a2)
{
_BYTE *v2; // r12
__int64 v3; // rax
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
int result; // eax
int v7; // er15
__int64 v8; // rbp
const char *v9; // rbx
char *v10; // rax
const char *v11; // r12
__int64 v12; // r12
unsigned __int64 v13; // rbx
char *v14; // rax

v2 = *(_BYTE **)a2;
v3 = *(_QWORD *)(a2 + 8);
if ( v3 != 1 )
{
v4 = 0LL;
if ( !v3 )
{
LABEL_10:
putchar(9);
LABEL_5:
result = putchar(9);
v7 = 0;
goto LABEL_6;
}
do
{
LABEL_3:
putchar((char)v2[v4++]);
v5 = *(_QWORD *)(a2 + 8);
}
while ( v5 > v4 );
if ( v5 > 7 )
goto LABEL_5;
goto LABEL_10;
}
v4 = 0LL;
if ( *v2 != 64 )
goto LABEL_3;
result = printf("@\t");
v7 = 1;
LABEL_6:
v8 = *(_QWORD *)(a2 + 16);
if ( v8 )
{
v9 = *(const char **)v8;
v10 = strchr(*(const char **)v8, 32);
v11 = v10 + 1;
*v10 = 0;
while ( 1 )
{
if ( strcmp(s1, v9) )
printf("%s", v9);
putchar(9);
if ( v7 )
{
printf("IN\t%s\t", v11);
if ( !strcmp(v11, "SOA") )
{
result = printsoa((__int64 *)(v8 + 16));
goto LABEL_16;
}
}
else
{
printf("%s\t", v11);
}
v12 = *(_QWORD *)(v8 + 16);
if ( *(_QWORD *)(v8 + 24) )
{
v13 = 0LL;
do
putchar(*(char *)(v12 + v13++));
while ( *(_QWORD *)(v8 + 24) > v13 );
}
result = putchar(10);
LABEL_16:
v8 = *(_QWORD *)(v8 + 32);
if ( !v8 )
return result;
v9 = *(const char **)v8;
v14 = strchr(*(const char **)v8, 32);
v11 = v14 + 1;
*v14 = 0;
printf("\t\t");
v7 = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *s1, __int64 a2)
{
_BYTE *v2; // r12
__int64 v3; // rax
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
int result; // eax
int v7; // er15
__int64 v8; // rbp
const char *v9; // rbx
char *v10; // rax
const char *v11; // r12
__int64 v12; // r12
unsigned __int64 v13; // rbx
char *v14; // rax

v2 = *(_BYTE **)a2;
v3 = *(_QWORD *)(a2 + 8);
if ( v3 != 1 )
{
v4 = 0LL;
if ( !v3 )
{
LABEL_10:
putchar(9);
LABEL_5:
result = putchar(9);
v7 = 0;
goto LABEL_6;
}
do
{
LABEL_3:
putchar((char)v2[v4++]);
v5 = *(_QWORD *)(a2 + 8);
}
while ( v5 > v4 );
if ( v5 > 7 )
goto LABEL_5;
goto LABEL_10;
}
v4 = 0LL;
if ( *v2 != 64 )
goto LABEL_3;
result = printf("@\t");
v7 = 1;
LABEL_6:
v8 = *(_QWORD *)(a2 + 16);
if ( v8 )
{
v9 = *(const char **)v8;
v10 = strchr(*(const char **)v8, 32);
v11 = v10 + 1;
*v10 = 0;
while ( 1 )
{
if ( strcmp(s1, v9) )
printf("%s", v9);
putchar(9);
if ( v7 )
{
printf("IN\t%s\t", v11);
if ( !strcmp(v11, "SOA") )
{
result = func3((__int64 *)(v8 + 16));
goto LABEL_16;
}
}
else
{
printf("%s\t", v11);
}
v12 = *(_QWORD *)(v8 + 16);
if ( *(_QWORD *)(v8 + 24) )
{
v13 = 0LL;
do
putchar(*(char *)(v12 + v13++));
while ( *(_QWORD *)(v8 + 24) > v13 );
}
result = putchar(10);
LABEL_16:
v8 = *(_QWORD *)(v8 + 32);
if ( !v8 )
return result;
v9 = *(const char **)v8;
v14 = strchr(*(const char **)v8, 32);
v11 = v14 + 1;
*v14 = 0;
printf("\t\t");
v7 = 0;
}
}
return result;
}

original_code:
void printrrs(char *defaultttl, struct assstack_entry *item) {
    struct assstack_entry *stack;
    char *s;
    int first;
    size_t i;
    char *ttl, *type;
    int top;
    s = (char *)item->key.data;
    if (item->key.len == 1 && *s == '@') {
 top = 1;
 printf("@\t");
    } else {
 top = 0;
 for (i = 0; i < item->key.len; i++)
     putchar(s[i]);
 if (item->key.len < 8)
     putchar('\t');
 putchar('\t');
    }
    first = 1;
    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
 ttl = (char *)stack->key.data;
 s = strchr(ttl, ' ');
 *s++ = '\0';
 type = s;
 if (first)
     first = 0;
        else
     printf("\t\t");
 if (strcmp(defaultttl, ttl))
     printf("%s", ttl);
 putchar('\t');
 if (top) {
     top = 0;
     printf("IN\t%s\t", type);
     if (!strcmp(type, "SOA")) {
  printsoa(&stack->val);
  continue;
     }
 } else
     printf("%s\t", type);
 s = (char *)stack->val.data;
 for (i = 0; i < stack->val.len; i++)
     putchar(s[i]);
 putchar('\n');
    }
}

canonical_original_code:
void printrrs(char *defaultttl, struct assstack_entry *item) {
    struct assstack_entry *stack;
    char *s;
    int first;
    unsigned long i;
    char *ttl; char *type;
    int top;
    s = (char *)item->key.data;
    if (item->key.len == 1 && *s == '@') {
 top = 1;
 printf("@\t");
    } else {
 top = 0;
 for (i = 0; i < item->key.len; i++)
     putchar(s[i]);
 if (item->key.len < 8)
     putchar('\t');
 putchar('\t');
    }
    first = 1;
    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
 ttl = (char *)stack->key.data;
 s = strchr(ttl, ' ');
 *s++ = '\0';
 type = s;
 if (first)
     first = 0;
        else
     printf("\t\t");
 if (strcmp(defaultttl, ttl))
     printf("%s", ttl);
 putchar('\t');
 if (top) {
     top = 0;
     printf("IN\t%s\t", type);
     if (!strcmp(type, "SOA")) {
  printsoa(&stack->val);
  continue;
     }
 } else
     printf("%s\t", type);
 s = (char *)stack->val.data;
 for (i = 0; i < stack->val.len; i++)
     putchar(s[i]);
 putchar('\n');
    }
}

variable_types:
defaultttl
char *

variable_types: struct assstack_entry { struct string { void *data; unsigned long len; } key; struct string val; struct assstack_entry *next; } *

variable_types: first int

variable_types:
ttl
char *

variable_types:
type
char *

variable_types: top int


decompiled_code:
int __fastcall print_zone(char *s1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax

v2 = a2;
for ( result = printf("$TTL %s\n", s1); v2; v2 = *(_QWORD *)(v2 + 32) )
result = printrrs(s1, v2);
return result;
}

canonical_decompiled_code:
int __fastcall func5(char *s1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax

v2 = a2;
for ( result = printf("$TTL %s\n", s1); v2; v2 = *(_QWORD *)(v2 + 32) )
result = func4(s1, v2);
return result;
}

original_code:
void print_zone(char *defaultttl, struct assstack_entry *stack) {
    printf("$TTL %s\n", defaultttl);
    for (; stack; stack = stack->next)
 printrrs(defaultttl, stack);
}

user_defined_types: struct string { void *data; unsigned long len; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s [-D BIND DN] [-w BIND PASSWORD] \n <ZONE NAME> <LDAP-URL> <DEFAULT TTL> [SERIAL]\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(const char *a1)
{
fprintf(
stderr,
"Usage: %s [-D BIND DN] [-w BIND PASSWORD] \n <ZONE NAME> <LDAP-URL> <DEFAULT TTL> [SERIAL]\n",
a1);
exit(1);
}

original_code:
void usage(char *name) {
    fprintf(stderr, "Usage: %s "
     "[-D BIND DN] [-w BIND PASSWORD] "
     "\n"
     "       <ZONE NAME> <LDAP-URL> <DEFAULT TTL> [SERIAL]\n", name);
    exit(1);
}

variable_types:
name
char *


err

decompiled_code:
void __fastcall __noreturn err(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s\n", a1, a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s\n", a1, a2);
exit(1);
}

original_code:
void err(char *name, const char *msg) {
    fprintf(stderr, "%s: %s\n", name, msg);
    exit(1);
}

canonical_original_code:
void err(char *name, char *msg) {
    fprintf(stderr, "%s: %s\n", name, msg);
    exit(1);
}

variable_types:
msg
char *


putrr

original_code:
int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val) {
    struct string key;
    struct assstack_entry *rr, *rrdata;
    if (!name->bv_len || !val->bv_len)
 return 0;
    key.len = name->bv_len;
    key.data = name->bv_val;
    rr = assstack_find(*stack, &key);
    if (!rr) {
 rr = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
 if (!rr)
     return -1;
 rr->key.len = name->bv_len;
 rr->key.data = (void *) malloc(rr->key.len);
 if (!rr->key.data) {
     free(rr);
     return -1;
 }
 memcpy(rr->key.data, name->bv_val, name->bv_len);
 rr->val.len = sizeof(void *);
 rr->val.data = ((void *)0);
 if (name->bv_len == 1 && *(char *)name->bv_val == '@')
     assstack_push(stack, rr);
 else
     assstack_insertsorted(stack, rr);
    }
    rrdata = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
    if (!rrdata) {
 free(rr->key.data);
 free(rr);
 return -1;
    }
    rrdata->key.len = strlen(type) + strlen(ttl) + 2;
    rrdata->key.data = (void *) malloc(rrdata->key.len);
    if (!rrdata->key.data) {
 free(rrdata);
 free(rr->key.data);
 free(rr);
 return -1;
    }
    sprintf((char *)rrdata->key.data, "%s %s", ttl, type);
    rrdata->val.len = val->bv_len;
    rrdata->val.data = (void *) malloc(val->bv_len);
    if (!rrdata->val.data) {
 free(rrdata->key.data);
 free(rrdata);
 free(rr->key.data);
 free(rr);
 return -1;
    }
    memcpy(rrdata->val.data, val->bv_val, val->bv_len);
    if (!strcmp(type, "SOA"))
 assstack_push((struct assstack_entry **) &(rr->val.data), rrdata);
    else
 assstack_insertsorted((struct assstack_entry **) &(rr->val.data), rrdata);
    return 0;
}

canonical_original_code:
int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val) {
    struct string key;
    struct assstack_entry *rr; struct assstack_entry *rrdata;
    if (!name->bv_len || !val->bv_len)
 return 0;
    key.len = name->bv_len;
    key.data = name->bv_val;
    rr = assstack_find(*stack, &key);
    if (!rr) {
 rr = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
 if (!rr)
     return -1;
 rr->key.len = name->bv_len;
 rr->key.data = (void *) malloc(rr->key.len);
 if (!rr->key.data) {
     free(rr);
     return -1;
 }
 memcpy(rr->key.data, name->bv_val, name->bv_len);
 rr->val.len = sizeof(void *);
 rr->val.data = ((void *)0);
 if (name->bv_len == 1 && *(char *)name->bv_val == '@')
     assstack_push(stack, rr);
 else
     assstack_insertsorted(stack, rr);
    }
    rrdata = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
    if (!rrdata) {
 free(rr->key.data);
 free(rr);
 return -1;
    }
    rrdata->key.len = strlen(type) + strlen(ttl) + 2;
    rrdata->key.data = (void *) malloc(rrdata->key.len);
    if (!rrdata->key.data) {
 free(rrdata);
 free(rr->key.data);
 free(rr);
 return -1;
    }
    sprintf((char *)rrdata->key.data, "%s %s", ttl, type);
    rrdata->val.len = val->bv_len;
    rrdata->val.data = (void *) malloc(val->bv_len);
    if (!rrdata->val.data) {
 free(rrdata->key.data);
 free(rrdata);
 free(rr->key.data);
 free(rr);
 return -1;
    }
    memcpy(rrdata->val.data, val->bv_val, val->bv_len);
    if (!strcmp(type, "SOA"))
 assstack_push((struct assstack_entry **) &(rr->val.data), rrdata);
    else
 assstack_insertsorted((struct assstack_entry **) &(rr->val.data), rrdata);
    return 0;
}

variable_types: struct assstack_entry { struct string { void *data; unsigned long len; } key; struct string val; struct assstack_entry *next; } **

variable_types: struct berval { unsigned long bv_len; char *bv_val; } *

variable_types:
val
struct berval *

return_type: int


repo: Fredspohr/algoritimos-geneticos

decompiled_code:
__int64 __fastcall random_number(int a1, int a2)
{
int v2; // ebx
int v3; // er12
int v4; // ebp
int v5; // eax

v2 = a1;
v3 = a2 + 1;
if ( a1 >= a2 )
{
v3 = a1;
v2 = a2 + 1;
}
v4 = rand();
v5 = time(0LL);
srand(v5 * v4);
return (unsigned int)(rand() % (v3 - v2) + v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
int v2; // ebx
int v3; // er12
int v4; // ebp
int v5; // eax

v2 = a1;
v3 = a2 + 1;
if ( a1 >= a2 )
{
v3 = a1;
v2 = a2 + 1;
}
v4 = rand();
v5 = time(0LL);
srand(v5 * v4);
return (unsigned int)(rand() % (v3 - v2) + v2);
}

original_code:
int random_number(int min_num, int max_num)
        {
            int result=0,low_num=0,hi_num=0;
            if(min_num<max_num)
            {
                low_num=min_num;
                hi_num=max_num+1;
            }else{
                low_num=max_num+1;
                hi_num=min_num;
            }
            srand(rand()*time(((void *)0)));
            result = (rand()%(hi_num-low_num))+low_num;
            return result;
        }

canonical_original_code:
int random_number(int min_num, int max_num)
        {
            int result = 0; int low_num = 0; int hi_num = 0;
            if(min_num<max_num)
            {
                low_num=min_num;
                hi_num=max_num+1;
            }else{
                low_num=max_num+1;
                hi_num=min_num;
            }
            srand(rand()*time(((void *)0)));
            result = (rand()%(hi_num-low_num))+low_num;
            return result;
        }

variable_types: result int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbp
unsigned int *v4; // r12
unsigned int *v5; // rbx
unsigned int *v6; // rbp
unsigned int *v7; // rbp
unsigned int *v8; // rbx
unsigned int *v9; // rax
unsigned int *v10; // r12

v3 = (unsigned int *)malloc(0x28uLL);
v4 = (unsigned int *)malloc(0x20uLL);
*v3 = 0;
v3[1] = 1;
v3[2] = 2;
v3[3] = 3;
v3[4] = 4;
v3[5] = 5;
v3[6] = 6;
v3[7] = 7;
v5 = v3;
v6 = v3 + 8;
do
printf("Valor: %d\n", *v5++);
while ( v6 != v5 );
v7 = v4 + 7;
v8 = v4;
do
{
*v7 = random_number(0, 1);
v9 = v7--;
}
while ( v4 != v9 );
v10 = v4 + 8;
do
printf("Peso: %d\n", *v8++);
while ( v8 != v10 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbp
unsigned int *v4; // r12
unsigned int *v5; // rbx
unsigned int *v6; // rbp
unsigned int *v7; // rbp
unsigned int *v8; // rbx
unsigned int *v9; // rax
unsigned int *v10; // r12

v3 = (unsigned int *)malloc(0x28uLL);
v4 = (unsigned int *)malloc(0x20uLL);
*v3 = 0;
v3[1] = 1;
v3[2] = 2;
v3[3] = 3;
v3[4] = 4;
v3[5] = 5;
v3[6] = 6;
v3[7] = 7;
v5 = v3;
v6 = v3 + 8;
do
printf("Valor: %d\n", *v5++);
while ( v6 != v5 );
v7 = v4 + 7;
v8 = v4;
do
{
*v7 = func7(0, 1);
v9 = v7--;
}
while ( v4 != v9 );
v10 = v4 + 8;
do
printf("Peso: %d\n", *v8++);
while ( v8 != v10 );
return 0;
}

original_code:
int main(int arg, char* args[]){
 Cromossomo *cromossomo;
 int i;
 cromossomo = malloc(sizeof(Cromossomo));
 cromossomo->genes = malloc(8 * sizeof(Gene));
 for(i = 0;i < 8; i++){
  cromossomo->valor[i] = i;
 }
 for(i = 0;i < 8; i++){
  printf("Valor: %d\n",cromossomo->valor[i]);
 }
 for(i = 7; i >= 0; i--){
  cromossomo->genes[i].peso = random_number(0,1) ;
 }
 for(i = 0;i < 8; i++){
  printf("Peso: %d\n",cromossomo->genes[i].peso);
 }
 return 0;
}

canonical_original_code:
int main(int arg, char *args[]){
 struct Cromossomo *cromossomo;
 int i;
 cromossomo = malloc(sizeof(Cromossomo));
 cromossomo->genes = malloc(8 * sizeof(Gene));
 for(i = 0;i < 8; i++){
  cromossomo->valor[i] = i;
 }
 for(i = 0;i < 8; i++){
  printf("Valor: %d\n",cromossomo->valor[i]);
 }
 for(i = 7; i >= 0; i--){
  cromossomo->genes[i].peso = random_number(0,1) ;
 }
 for(i = 0;i < 8; i++){
  printf("Peso: %d\n",cromossomo->genes[i].peso);
 }
 return 0;
}

variable_types: arg int

variable_types:
args
char *[]

variable_types: struct Cromossomo { int valor[8]; struct Gene { int peso; } *genes; } *

variable_types: i int

user_defined_types: struct Cromossomo { int valor[8]; struct Gene *genes; }


iniciarPopulacao

decompiled_code:
void iniciarPopulacao()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void iniciarPopulacao(int numeroinicial){
}

variable_types: numeroinicial int


crossover

decompiled_code:
void crossover()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void crossover(){
}

canonical_original_code:
void crossover(){
}


mutacao

decompiled_code:
void mutacao()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void mutacao(){
}

canonical_original_code:
void mutacao(){
}


avaliacao

decompiled_code:
void avaliacao()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void avaliacao(){
}

canonical_original_code:
void avaliacao(){
}


imprime

decompiled_code:
int imprime()
{
return puts("Imprime algoritimogenetico.h");
}

canonical_decompiled_code:
int func12()
{
return puts("Imprime algoritimogenetico.h");
}

original_code:
void imprime(){
 printf("Imprime algoritimogenetico.h\n");
}


pollKeyboard

repo: FrostTree-Games/PrinceProtect

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

result = SDL_GetKeyState(0LL);
keyList = result;
return result;
}

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

result = SDL_GetKeyState(0LL);
keyList = result;
return result;
}

original_code:
void pollKeyboard()
{
 keyList = SDL_GetKeyState(((void *)0));
}


setKey

decompiled_code:
void __fastcall setKey(int a1, int a2)
{
switch ( a2 )
{
case 1:
p1_up = a1;
break;
case 2:
p1_down = a1;
break;
case 3:
p1_left = a1;
break;
case 4:
p1_right = a1;
break;
case 5:
p1_a = a1;
break;
case 6:
p1_b = a1;
break;
case 7:
p1_start = a1;
break;
case 8:
p1_select = a1;
break;
case 9:
p2_up = a1;
break;
case 10:
p2_down = a1;
break;
case 11:
p2_left = a1;
break;
case 12:
p2_right = a1;
break;
case 13:
p2_a = a1;
break;
case 14:
p2_b = a1;
break;
case 15:
p2_start = a1;
break;
case 16:
p2_select = a1;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
switch ( a2 )
{
case 1:
p1_up = a1;
break;
case 2:
p1_down = a1;
break;
case 3:
p1_left = a1;
break;
case 4:
p1_right = a1;
break;
case 5:
p1_a = a1;
break;
case 6:
p1_b = a1;
break;
case 7:
p1_start = a1;
break;
case 8:
p1_select = a1;
break;
case 9:
p2_up = a1;
break;
case 10:
p2_down = a1;
break;
case 11:
p2_left = a1;
break;
case 12:
p2_right = a1;
break;
case 13:
p2_a = a1;
break;
case 14:
p2_b = a1;
break;
case 15:
p2_start = a1;
break;
case 16:
p2_select = a1;
break;
default:
return;
}
}

original_code:
void setKey(SDLKey input, gameKey key)
{
 switch (key)
 {
  case P1_UP:
  p1_up = input;
  break;
  case P1_DOWN:
  p1_down = input;
  break;
  case P1_LEFT:
  p1_left = input;
  break;
  case P1_RIGHT:
  p1_right = input;
  break;
  case P1_A:
  p1_a = input;
  break;
  case P1_B:
  p1_b = input;
  break;
  case P1_START:
  p1_start = input;
  break;
  case P1_SELECT:
  p1_select = input;
  break;
  case P2_UP:
  p2_up = input;
  break;
  case P2_DOWN:
  p2_down = input;
  break;
  case P2_LEFT:
  p2_left = input;
  break;
  case P2_RIGHT:
  p2_right = input;
  break;
  case P2_A:
  p2_a = input;
  break;
  case P2_B:
  p2_b = input;
  break;
  case P2_START:
  p2_start = input;
  break;
  case P2_SELECT:
  p2_select = input;
  break;
  default:
  break;
 }
}

canonical_original_code:
void setKey(enum SDLKey input, enum gameKey key)
{
 switch (key)
 {
  case P1_UP:
  p1_up = input;
  break;
  case P1_DOWN:
  p1_down = input;
  break;
  case P1_LEFT:
  p1_left = input;
  break;
  case P1_RIGHT:
  p1_right = input;
  break;
  case P1_A:
  p1_a = input;
  break;
  case P1_B:
  p1_b = input;
  break;
  case P1_START:
  p1_start = input;
  break;
  case P1_SELECT:
  p1_select = input;
  break;
  case P2_UP:
  p2_up = input;
  break;
  case P2_DOWN:
  p2_down = input;
  break;
  case P2_LEFT:
  p2_left = input;
  break;
  case P2_RIGHT:
  p2_right = input;
  break;
  case P2_A:
  p2_a = input;
  break;
  case P2_B:
  p2_b = input;
  break;
  case P2_START:
  p2_start = input;
  break;
  case P2_SELECT:
  p2_select = input;
  break;
  default:
  break;
 }
}

variable_types: enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 }

variable_types: enum gameKey { ESCAPE_KEY=0, P1_UP=1, P1_DOWN=2, P1_LEFT=3, P1_RIGHT=4, P1_A=5, P1_B=6, P1_START=7, P1_SELECT=8, P2_UP=9, P2_DOWN=10, P2_LEFT=11, P2_RIGHT=12, P2_A=13, P2_B=14, P2_START=15, P2_SELECT=16 }


isEnterKey

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

if ( keyList )
result = *(unsigned __int8 *)(keyList + 13);
else
result = 0LL;
return result;
}

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

if ( keyList )
result = *(unsigned __int8 *)(keyList + 13);
else
result = 0LL;
return result;
}

original_code:
int isEnterKey()
{
 if (keyList == ((void *)0))
 {
  return 0;
 }
 return keyList[SDLK_RETURN];
}


getKey

decompiled_code:
__int64 __fastcall getKey(int a1)
{
__int64 result; // rax

if ( !keyList )
return 0LL;
switch ( a1 )
{
case 0:
result = *(unsigned __int8 *)(keyList + 27);
break;
case 1:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_up);
break;
case 2:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_down);
break;
case 3:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_left);
break;
case 4:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_right);
break;
case 5:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_a);
break;
case 6:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_b);
break;
case 7:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_start);
break;
case 8:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_select);
break;
case 9:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_up);
break;
case 10:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_down);
break;
case 11:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_left);
break;
case 12:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_right);
break;
case 13:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_a);
break;
case 14:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_b);
break;
case 15:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_start);
break;
case 16:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_select);
break;
default:
puts("STRANGE KEYBOARD CODE FOUND");
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 result; // rax

if ( !keyList )
return 0LL;
switch ( a1 )
{
case 0:
result = *(unsigned __int8 *)(keyList + 27);
break;
case 1:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_up);
break;
case 2:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_down);
break;
case 3:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_left);
break;
case 4:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_right);
break;
case 5:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_a);
break;
case 6:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_b);
break;
case 7:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_start);
break;
case 8:
result = *(unsigned __int8 *)(keyList + (unsigned int)p1_select);
break;
case 9:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_up);
break;
case 10:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_down);
break;
case 11:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_left);
break;
case 12:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_right);
break;
case 13:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_a);
break;
case 14:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_b);
break;
case 15:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_start);
break;
case 16:
result = *(unsigned __int8 *)(keyList + (unsigned int)p2_select);
break;
default:
puts("STRANGE KEYBOARD CODE FOUND");
result = 0LL;
break;
}
return result;
}

original_code:
int getKey(gameKey key)
{
 if (keyList == ((void *)0))
 {
  return 0;
 }
 switch (key)
 {
  case ESCAPE_KEY:
  return keyList[SDLK_ESCAPE];
  break;
  case P1_UP:
  return keyList[p1_up];
  break;
  case P1_DOWN:
  return keyList[p1_down];
  break;
  case P1_LEFT:
  return keyList[p1_left];
  break;
  case P1_RIGHT:
  return keyList[p1_right];
  break;
  case P1_A:
  return keyList[p1_a];
  break;
  case P1_B:
  return keyList[p1_b];
  break;
  case P1_START:
  return keyList[p1_start];
  break;
  case P1_SELECT:
  return keyList[p1_select];
  break;
  case P2_UP:
  return keyList[p2_up];
  break;
  case P2_DOWN:
  return keyList[p2_down];
  break;
  case P2_LEFT:
  return keyList[p2_left];
  break;
  case P2_RIGHT:
  return keyList[p2_right];
  break;
  case P2_A:
  return keyList[p2_a];
  break;
  case P2_B:
  return keyList[p2_b];
  break;
  case P2_START:
  return keyList[p2_start];
  break;
  case P2_SELECT:
  return keyList[p2_select];
  break;
  default:
  printf("STRANGE KEYBOARD CODE FOUND\n");
  return 0;
 }
 return 0;
}

canonical_original_code:
int getKey(enum gameKey key)
{
 if (keyList == ((void *)0))
 {
  return 0;
 }
 switch (key)
 {
  case ESCAPE_KEY:
  return keyList[SDLK_ESCAPE];
  break;
  case P1_UP:
  return keyList[p1_up];
  break;
  case P1_DOWN:
  return keyList[p1_down];
  break;
  case P1_LEFT:
  return keyList[p1_left];
  break;
  case P1_RIGHT:
  return keyList[p1_right];
  break;
  case P1_A:
  return keyList[p1_a];
  break;
  case P1_B:
  return keyList[p1_b];
  break;
  case P1_START:
  return keyList[p1_start];
  break;
  case P1_SELECT:
  return keyList[p1_select];
  break;
  case P2_UP:
  return keyList[p2_up];
  break;
  case P2_DOWN:
  return keyList[p2_down];
  break;
  case P2_LEFT:
  return keyList[p2_left];
  break;
  case P2_RIGHT:
  return keyList[p2_right];
  break;
  case P2_A:
  return keyList[p2_a];
  break;
  case P2_B:
  return keyList[p2_b];
  break;
  case P2_START:
  return keyList[p2_start];
  break;
  case P2_SELECT:
  return keyList[p2_select];
  break;
  default:
  printf("STRANGE KEYBOARD CODE FOUND\n");
  return 0;
 }
 return 0;
}

user_defined_types: enum gameKey { ESCAPE_KEY=0, P1_UP=1, P1_DOWN=2, P1_LEFT=3, P1_RIGHT=4, P1_A=5, P1_B=6, P1_START=7, P1_SELECT=8, P2_UP=9, P2_DOWN=10, P2_LEFT=11, P2_RIGHT=12, P2_A=13, P2_B=14, P2_START=15, P2_SELECT=16 }


getSDLKeyValue

decompiled_code:
__int64 __fastcall getSDLKeyValue(int a1)
{
__int64 result; // rax

if ( !keyList )
return 0LL;
switch ( a1 )
{
case 0:
result = 27LL;
break;
case 1:
result = (unsigned int)p1_up;
break;
case 2:
result = (unsigned int)p1_down;
break;
case 3:
result = (unsigned int)p1_left;
break;
case 4:
result = (unsigned int)p1_right;
break;
case 5:
result = (unsigned int)p1_a;
break;
case 6:
result = (unsigned int)p1_b;
break;
case 7:
result = (unsigned int)p1_start;
break;
case 8:
result = (unsigned int)p1_select;
break;
case 9:
result = (unsigned int)p2_up;
break;
case 10:
result = (unsigned int)p2_down;
break;
case 11:
result = (unsigned int)p2_left;
break;
case 12:
result = (unsigned int)p2_right;
break;
case 13:
result = (unsigned int)p2_a;
break;
case 14:
result = (unsigned int)p2_b;
break;
case 15:
result = (unsigned int)p2_start;
break;
case 16:
result = (unsigned int)p2_select;
break;
default:
puts("STRANGE KEYBOARD CODE FOUND");
result = 0LL;
break;
}
return result;
}

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

if ( !keyList )
return 0LL;
switch ( a1 )
{
case 0:
result = 27LL;
break;
case 1:
result = (unsigned int)p1_up;
break;
case 2:
result = (unsigned int)p1_down;
break;
case 3:
result = (unsigned int)p1_left;
break;
case 4:
result = (unsigned int)p1_right;
break;
case 5:
result = (unsigned int)p1_a;
break;
case 6:
result = (unsigned int)p1_b;
break;
case 7:
result = (unsigned int)p1_start;
break;
case 8:
result = (unsigned int)p1_select;
break;
case 9:
result = (unsigned int)p2_up;
break;
case 10:
result = (unsigned int)p2_down;
break;
case 11:
result = (unsigned int)p2_left;
break;
case 12:
result = (unsigned int)p2_right;
break;
case 13:
result = (unsigned int)p2_a;
break;
case 14:
result = (unsigned int)p2_b;
break;
case 15:
result = (unsigned int)p2_start;
break;
case 16:
result = (unsigned int)p2_select;
break;
default:
puts("STRANGE KEYBOARD CODE FOUND");
result = 0LL;
break;
}
return result;
}

original_code:
SDLKey getSDLKeyValue(gameKey key)
{
 if (keyList == ((void *)0))
 {
  return 0;
 }
 switch (key)
 {
  case ESCAPE_KEY:
  return SDLK_ESCAPE;
  break;
  case P1_UP:
  return p1_up;
  break;
  case P1_DOWN:
  return p1_down;
  break;
  case P1_LEFT:
  return p1_left;
  break;
  case P1_RIGHT:
  return p1_right;
  break;
  case P1_A:
  return p1_a;
  break;
  case P1_B:
  return p1_b;
  break;
  case P1_START:
  return p1_start;
  break;
  case P1_SELECT:
  return p1_select;
  break;
  case P2_UP:
  return p2_up;
  break;
  case P2_DOWN:
  return p2_down;
  break;
  case P2_LEFT:
  return p2_left;
  break;
  case P2_RIGHT:
  return p2_right;
  break;
  case P2_A:
  return p2_a;
  break;
  case P2_B:
  return p2_b;
  break;
  case P2_START:
  return p2_start;
  break;
  case P2_SELECT:
  return p2_select;
  break;
  default:
  printf("STRANGE KEYBOARD CODE FOUND\n");
  return 0;
 }
 return 0;
}

canonical_original_code:
enum SDLKey getSDLKeyValue(enum gameKey key)
{
 if (keyList == ((void *)0))
 {
  return 0;
 }
 switch (key)
 {
  case ESCAPE_KEY:
  return SDLK_ESCAPE;
  break;
  case P1_UP:
  return p1_up;
  break;
  case P1_DOWN:
  return p1_down;
  break;
  case P1_LEFT:
  return p1_left;
  break;
  case P1_RIGHT:
  return p1_right;
  break;
  case P1_A:
  return p1_a;
  break;
  case P1_B:
  return p1_b;
  break;
  case P1_START:
  return p1_start;
  break;
  case P1_SELECT:
  return p1_select;
  break;
  case P2_UP:
  return p2_up;
  break;
  case P2_DOWN:
  return p2_down;
  break;
  case P2_LEFT:
  return p2_left;
  break;
  case P2_RIGHT:
  return p2_right;
  break;
  case P2_A:
  return p2_a;
  break;
  case P2_B:
  return p2_b;
  break;
  case P2_START:
  return p2_start;
  break;
  case P2_SELECT:
  return p2_select;
  break;
  default:
  printf("STRANGE KEYBOARD CODE FOUND\n");
  return 0;
 }
 return 0;
}

return_type: enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 }


xrand

decompiled_code:
__int64 xrand()
{
int v0; // ebx

v0 = rand();
return (unsigned int)((v0 << 31) + rand());
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx

v0 = rand();
return (unsigned int)((v0 << 31) + rand());
}

original_code:
unsigned int xrand(void)
{
 return rand () * (2147483647 + 1) + rand ();
}

canonical_original_code:
unsigned int xrand()
{
 return rand () * (2147483647 + 1) + rand ();
}

return_type: unsigned int


randomizeWaveTypes

decompiled_code:
__int64 randomizeWaveTypes()
{
int v0; // eax
int v1; // ecx
int v2; // eax
int v3; // ecx
__int64 result; // rax

v0 = xrand() & 3;
waveTypeBlock1 = initalBlockList[v0];
v1 = initalBlockList[3];
initalBlockList[3] = waveTypeBlock1;
initalBlockList[v0] = v1;
waveTypeBlock2 = initalBlockList[(unsigned int)xrand() % 3];
v2 = xrand() & 3;
waveTypeEnemy1 = initalEnemyList[v2];
v3 = initalEnemyList[3];
initalEnemyList[3] = waveTypeEnemy1;
initalEnemyList[v2] = v3;
result = (unsigned int)initalEnemyList[(unsigned int)xrand() % 3];
waveTypeEnemy2 = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // ecx
int v2; // eax
int v3; // ecx
__int64 result; // rax

v0 = func0() & 3;
waveTypeBlock1 = initalBlockList[v0];
v1 = initalBlockList[3];
initalBlockList[3] = waveTypeBlock1;
initalBlockList[v0] = v1;
waveTypeBlock2 = initalBlockList[(unsigned int)func0() % 3];
v2 = func0() & 3;
waveTypeEnemy1 = initalEnemyList[v2];
v3 = initalEnemyList[3];
initalEnemyList[3] = waveTypeEnemy1;
initalEnemyList[v2] = v3;
result = (unsigned int)initalEnemyList[(unsigned int)func0() % 3];
waveTypeEnemy2 = result;
return result;
}

original_code:
void randomizeWaveTypes()
{
 int val = xrand() % 4;
 waveTypeBlock1 = initalBlockList[val];
 BlockType holdType = initalBlockList[3];
 initalBlockList[3] = waveTypeBlock1;
 initalBlockList[val] = holdType;
 val = xrand() % 3;
 waveTypeBlock2 = initalBlockList[val];
 val = xrand() % 4;
 waveTypeEnemy1 = initalEnemyList[val];
 EntityType holdType2 = initalEnemyList[3];
 initalEnemyList[3] = waveTypeEnemy1;
 initalEnemyList[val] = holdType2;
 val = xrand() % 3;
 waveTypeEnemy2 = initalEnemyList[val];
}

canonical_original_code:
void randomizeWaveTypes()
{
 int val = xrand() % 4;
 waveTypeBlock1 = initalBlockList[val];
 enum BlockType holdType = initalBlockList[3];
 initalBlockList[3] = waveTypeBlock1;
 initalBlockList[val] = holdType;
 val = xrand() % 3;
 waveTypeBlock2 = initalBlockList[val];
 val = xrand() % 4;
 waveTypeEnemy1 = initalEnemyList[val];
 enum EntityType holdType2 = initalEnemyList[3];
 initalEnemyList[3] = waveTypeEnemy1;
 initalEnemyList[val] = holdType2;
 val = xrand() % 3;
 waveTypeEnemy2 = initalEnemyList[val];
}

variable_types: val int

variable_types: enum BlockType { NO_BLOCK=0, RED_BLOCK=1, BLUE_BLOCK=2, GREEN_BLOCK=3, YELLOW_BLOCK=4 }

variable_types: enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 }


randomizeBGM

decompiled_code:
__int64 __fastcall randomizeBGM(int a1)
{
__int64 result; // rax

result = 2LL;
if ( (unsigned int)(a1 - 2) <= 2 )
{
if ( a1 == 2 )
{
result = (unsigned int)(xrand() & 1) + 3;
}
else if ( a1 == 3 )
{
result = (xrand() & 1) == 0 ? 2 : 4;
}
else
{
result = (unsigned int)(xrand() & 1) + 2;
}
}
return result;
}

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

result = 2LL;
if ( (unsigned int)(a1 - 2) <= 2 )
{
if ( a1 == 2 )
{
result = (unsigned int)(func0() & 1) + 3;
}
else if ( a1 == 3 )
{
result = (func0() & 1) == 0 ? 2 : 4;
}
else
{
result = (unsigned int)(func0() & 1) + 2;
}
}
return result;
}

original_code:
BGMType randomizeBGM(BGMType bg)
{
 if (bg != BGM_1 && bg != BGM_2 && bg != BGM_3)
 {
  return BGM_1;
 }
 if (bg == BGM_1)
 {
  switch (xrand() % 2)
  {
   case 0:
   return BGM_2;
   case 1:
   return BGM_3;
   default:
   return BGM_1;
  }
 }
 else if (bg == BGM_2)
 {
  switch (xrand() % 2)
  {
   case 0:
   return BGM_1;
   case 1:
   return BGM_3;
   default:
   return BGM_2;
  }
 }
 else if (bg == BGM_3)
 {
  switch (xrand() % 2)
  {
   case 0:
   return BGM_1;
   case 1:
   return BGM_2;
   default:
   return BGM_3;
  }
 }
 return BGM_1;
}

canonical_original_code:
enum BGMType randomizeBGM(enum BGMType bg)
{
 if (bg != BGM_1 && bg != BGM_2 && bg != BGM_3)
 {
  return BGM_1;
 }
 if (bg == BGM_1)
 {
  switch (xrand() % 2)
  {
   case 0:
   return BGM_2;
   case 1:
   return BGM_3;
   default:
   return BGM_1;
  }
 }
 else if (bg == BGM_2)
 {
  switch (xrand() % 2)
  {
   case 0:
   return BGM_1;
   case 1:
   return BGM_3;
   default:
   return BGM_2;
  }
 }
 else if (bg == BGM_3)
 {
  switch (xrand() % 2)
  {
   case 0:
   return BGM_1;
   case 1:
   return BGM_2;
   default:
   return BGM_3;
  }
 }
 return BGM_1;
}

variable_types: enum BGMType { BGM_NONE=0, BGM_ANGSTY=1, BGM_1=2, BGM_2=3, BGM_3=4, BGM_TITLE=5, BGM_KEYCONFIG=6 }


updateRestPeriod

decompiled_code:
__int64 updateRestPeriod()
{
__int64 v0; // rdx
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rbx
_DWORD *v4; // rax
_DWORD *v5; // rax
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !restPeriodStart )
{
result = getTimeSingleton();
restPeriodStart = result;
return result;
}
if ( (!player1Health || !player2Health) && !gameEnding )
{
v2 = getEntityList();
v3 = 0LL;
if ( !v2 )
goto LABEL_7;
while ( 1 )
{
if ( (int)getEntityListSize() <= (int)v3 )
goto LABEL_7;
v5 = *(_DWORD **)(v2 + 8 * v3);
if ( !*v5 )
{
if ( v5[17] != 2 )
goto LABEL_19;
v5[17] = 0;
reloadingHealth = 1;
reloadingDelayEffectTime = getTimeSingleton();
++player1Health;
playSFX(22LL);
}
v4 = *(_DWORD **)(v2 + 8 * v3);
if ( *v4 == 1 && v4[17] == 2 )
{
v4[17] = 0;
reloadingHealth = 2;
reloadingDelayEffectTime = getTimeSingleton();
++player2Health;
playSFX(22LL);
}
LABEL_19:
++v3;
}
}
if ( reloadingHealth == 1 )
{
if ( (unsigned int)getTimeSingleton() - reloadingDelayEffectTime > 0x1F4 )
{
++player1Health;
playSFX(22LL);
reloadingDelayEffectTime = getTimeSingleton();
if ( player1Health == 3 )
reloadingHealth = 0;
}
}
else if ( reloadingHealth == 2 && (unsigned int)getTimeSingleton() - reloadingDelayEffectTime > 0x1F4 )
{
++player2Health;
playSFX(22LL);
reloadingDelayEffectTime = getTimeSingleton();
if ( player2Health == 3 )
reloadingHealth = 0;
}
LABEL_7:
if ( (unsigned int)getTimeSingleton() - restPeriodStart > 0x157C && waveNumber > 0 )
{
v0 = (unsigned int)(waveNumber + 1);
waveNumber = v0;
restPeriod = 0;
enemiesLeftToPush = 10;
if ( (int)v0 > 2 )
maxOnScreenRobots += 3;
goto LABEL_11;
}
result = (unsigned int)getTimeSingleton() - restPeriodStart;
if ( (unsigned int)result > 0x2AF8 && !waveNumber )
{
waveNumber = 1;
restPeriod = 0;
enemiesLeftToPush = 10;
v0 = 1LL;
LABEL_11:
sprintf(v6, "WAVE %.2d", v0);
pushNewMessage(v6);
result = randomizeWaveTypes();
if ( waveNumber > 1 )
{
currentBGM = randomizeBGM(currentBGM);
result = playBGM((unsigned int)currentBGM);
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rbx
_DWORD *v4; // rax
_DWORD *v5; // rax
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !restPeriodStart )
{
result = getTimeSingleton();
restPeriodStart = result;
return result;
}
if ( (!player1Health || !player2Health) && !gameEnding )
{
v2 = getEntityList();
v3 = 0LL;
if ( !v2 )
goto LABEL_7;
while ( 1 )
{
if ( (int)getEntityListSize() <= (int)v3 )
goto LABEL_7;
v5 = *(_DWORD **)(v2 + 8 * v3);
if ( !*v5 )
{
if ( v5[17] != 2 )
goto LABEL_19;
v5[17] = 0;
reloadingHealth = 1;
reloadingDelayEffectTime = getTimeSingleton();
++player1Health;
playSFX(22LL);
}
v4 = *(_DWORD **)(v2 + 8 * v3);
if ( *v4 == 1 && v4[17] == 2 )
{
v4[17] = 0;
reloadingHealth = 2;
reloadingDelayEffectTime = getTimeSingleton();
++player2Health;
playSFX(22LL);
}
LABEL_19:
++v3;
}
}
if ( reloadingHealth == 1 )
{
if ( (unsigned int)getTimeSingleton() - reloadingDelayEffectTime > 0x1F4 )
{
++player1Health;
playSFX(22LL);
reloadingDelayEffectTime = getTimeSingleton();
if ( player1Health == 3 )
reloadingHealth = 0;
}
}
else if ( reloadingHealth == 2 && (unsigned int)getTimeSingleton() - reloadingDelayEffectTime > 0x1F4 )
{
++player2Health;
playSFX(22LL);
reloadingDelayEffectTime = getTimeSingleton();
if ( player2Health == 3 )
reloadingHealth = 0;
}
LABEL_7:
if ( (unsigned int)getTimeSingleton() - restPeriodStart > 0x157C && waveNumber > 0 )
{
v0 = (unsigned int)(waveNumber + 1);
waveNumber = v0;
restPeriod = 0;
enemiesLeftToPush = 10;
if ( (int)v0 > 2 )
maxOnScreenRobots += 3;
goto LABEL_11;
}
result = (unsigned int)getTimeSingleton() - restPeriodStart;
if ( (unsigned int)result > 0x2AF8 && !waveNumber )
{
waveNumber = 1;
restPeriod = 0;
enemiesLeftToPush = 10;
v0 = 1LL;
LABEL_11:
sprintf(v6, "WAVE %.2d", v0);
pushNewMessage(v6);
result = func1();
if ( waveNumber > 1 )
{
currentBGM = func2(currentBGM);
result = playBGM((unsigned int)currentBGM);
}
}
return result;
}

original_code:
void updateRestPeriod()
{
 int i;
 if (restPeriodStart == 0)
 {
  restPeriodStart = getTimeSingleton();
  return;
 }
 if ((player1Health == 0 || player2Health == 0) && gameEnding == 0)
 {
  Entity** entList = getEntityList();
  if (entList != ((void *)0))
  {
   for (i = 0; i < getEntityListSize(); i++)
   {
    if (entList[i]->base.type == PLAYER1)
    {
     if (entList[i]->player.dead == 2)
     {
      entList[i]->player.dead = 0;
      reloadingHealth = 1;
      reloadingDelayEffectTime = getTimeSingleton();
      player1Health++;
      playSFX(SFX_LIFEUP);
     }
    }
    if (entList[i]->base.type == PLAYER2)
    {
     if (entList[i]->player.dead == 2)
     {
      entList[i]->player.dead = 0;
      reloadingHealth = 2;
      reloadingDelayEffectTime = getTimeSingleton();
      player2Health++;
      playSFX(SFX_LIFEUP);
     }
    }
   }
  }
 }
 else if (reloadingHealth == 1)
 {
  if (getTimeSingleton() - reloadingDelayEffectTime > 500)
  {
   player1Health++;
   playSFX(SFX_LIFEUP);
   reloadingDelayEffectTime = getTimeSingleton();
   if (player1Health == 3)
   {
    reloadingHealth = 0;
   }
  }
 }
 else if (reloadingHealth == 2)
 {
  if (getTimeSingleton() - reloadingDelayEffectTime > 500)
  {
   player2Health++;
   playSFX(SFX_LIFEUP);
   reloadingDelayEffectTime = getTimeSingleton();
   if (player2Health == 3)
   {
    reloadingHealth = 0;
   }
  }
 }
 if ((getTimeSingleton() - restPeriodStart > 5500 && waveNumber > 0) || (getTimeSingleton() - restPeriodStart > 2 * 5500 && waveNumber == 0))
 {
  waveNumber++;
  restPeriod = 0;
  enemiesLeftToPush = 10;
  if (waveNumber >= 3)
  {
   maxOnScreenRobots += 3;
  }
  char msg[49];
  sprintf(msg, "WAVE %.2d", waveNumber);
  pushNewMessage(msg);
  randomizeWaveTypes();
  if (waveNumber > 1)
  {
   currentBGM = randomizeBGM(currentBGM);
   playBGM(currentBGM);
  }
 }
}

canonical_original_code:
void updateRestPeriod()
{
 int i;
 if (restPeriodStart == 0)
 {
  restPeriodStart = getTimeSingleton();
  return;
 }
 if ((player1Health == 0 || player2Health == 0) && gameEnding == 0)
 {
  union Entity **entList = getEntityList();
  if (entList != ((void *)0))
  {
   for (i = 0; i < getEntityListSize(); i++)
   {
    if (entList[i]->base.type == PLAYER1)
    {
     if (entList[i]->player.dead == 2)
     {
      entList[i]->player.dead = 0;
      reloadingHealth = 1;
      reloadingDelayEffectTime = getTimeSingleton();
      player1Health++;
      playSFX(SFX_LIFEUP);
     }
    }
    if (entList[i]->base.type == PLAYER2)
    {
     if (entList[i]->player.dead == 2)
     {
      entList[i]->player.dead = 0;
      reloadingHealth = 2;
      reloadingDelayEffectTime = getTimeSingleton();
      player2Health++;
      playSFX(SFX_LIFEUP);
     }
    }
   }
  }
 }
 else if (reloadingHealth == 1)
 {
  if (getTimeSingleton() - reloadingDelayEffectTime > 500)
  {
   player1Health++;
   playSFX(SFX_LIFEUP);
   reloadingDelayEffectTime = getTimeSingleton();
   if (player1Health == 3)
   {
    reloadingHealth = 0;
   }
  }
 }
 else if (reloadingHealth == 2)
 {
  if (getTimeSingleton() - reloadingDelayEffectTime > 500)
  {
   player2Health++;
   playSFX(SFX_LIFEUP);
   reloadingDelayEffectTime = getTimeSingleton();
   if (player2Health == 3)
   {
    reloadingHealth = 0;
   }
  }
 }
 if ((getTimeSingleton() - restPeriodStart > 5500 && waveNumber > 0) || (getTimeSingleton() - restPeriodStart > 2 * 5500 && waveNumber == 0))
 {
  waveNumber++;
  restPeriod = 0;
  enemiesLeftToPush = 10;
  if (waveNumber >= 3)
  {
   maxOnScreenRobots += 3;
  }
  char msg[49];
  sprintf(msg, "WAVE %.2d", waveNumber);
  pushNewMessage(msg);
  randomizeWaveTypes();
  if (waveNumber > 1)
  {
   currentBGM = randomizeBGM(currentBGM);
   playBGM(currentBGM);
  }
 }
}

variable_types: union Entity { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; struct entityBase { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } base; struct Player { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int offsetX; int offsetY; unsigned char direction; unsigned char upKeyDown; unsigned char downKeyDown; unsigned char leftKeyDown; unsigned char rightKeyDown; unsigned char aKeyDown; unsigned char bKeyDown; unsigned int swordTimer; int isThrusting; int thrustHit; struct GameBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int height; unsigned int lastUpdateTime; unsigned int startTime; enum BlockType { NO_BLOCK=0, RED_BLOCK=1, BLUE_BLOCK=2, GREEN_BLOCK=3, YELLOW_BLOCK=4 } bType; } *holding; unsigned int lastUpdate; unsigned char knockBackDirection; unsigned int lastFrameUpdate; int frame; int holdingSuperHammer; int dead; } player; struct PermaBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } permaBlock; struct GameBlock gBlock; struct IceBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int moving; unsigned char direction; int offsetX; int offsetY; unsigned int lastMovementUpdate; int health; unsigned int startTime; } iBlock; struct Explosion { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; } exp; struct Laser { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned char direction; int offsetX; int offsetY; unsigned int lastMovementUpdate; unsigned char allegiance; int frame; unsigned int lastFrameUpdate; } laser; struct TeleBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; int side; struct TeleBlock *twin; unsigned int lastClickTime; int frame; } tBlock; struct IceCream { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int frame; unsigned int lastFrameUpdateTime; int decoy; unsigned int decoyTime; } iceCream; struct SuperHammer { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } hammer; struct Shiruken { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } shiruken; struct FloorGlue { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; int population; } glue; struct Enemy { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int direction; int offsetX; int offsetY; int health; unsigned int lastMovementUpdate; unsigned char knockBackDirection; struct IceCream *cream; int AISlot1; int AISlot2; int AISlot3; unsigned int timer; unsigned int lastFrameUpdate; int frame; } enemy; struct Poof { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; int offsetX; int offsetY; int colour; int birthed; } poof; } **

variable_types:
msg
char [49]

user_defined_types: union Entity { enum EntityType type; struct entityBase base; struct Player player; struct PermaBlock permaBlock; struct GameBlock gBlock; struct IceBlock iBlock; struct Explosion exp; struct Laser laser; struct TeleBlock tBlock; struct IceCream iceCream; struct SuperHammer hammer; struct Shiruken shiruken; struct FloorGlue glue; struct Enemy enemy; struct Poof poof; }

user_defined_types: struct entityBase { enum EntityType type; int x; int y; }

user_defined_types: struct Player { enum EntityType type; int x; int y; int offsetX; int offsetY; unsigned char direction; unsigned char upKeyDown; unsigned char downKeyDown; unsigned char leftKeyDown; unsigned char rightKeyDown; unsigned char aKeyDown; unsigned char bKeyDown; unsigned int swordTimer; int isThrusting; int thrustHit; struct GameBlock *holding; unsigned int lastUpdate; unsigned char knockBackDirection; unsigned int lastFrameUpdate; int frame; int holdingSuperHammer; int dead; }

user_defined_types: struct PermaBlock { enum EntityType type; int x; int y; }

user_defined_types: struct IceBlock { enum EntityType type; int x; int y; int moving; unsigned char direction; int offsetX; int offsetY; unsigned int lastMovementUpdate; int health; unsigned int startTime; }

user_defined_types: struct Explosion { enum EntityType type; int x; int y; unsigned int startTime; }

user_defined_types: struct Laser { enum EntityType type; int x; int y; unsigned char direction; int offsetX; int offsetY; unsigned int lastMovementUpdate; unsigned char allegiance; int frame; unsigned int lastFrameUpdate; }

user_defined_types: struct TeleBlock { enum EntityType type; int x; int y; unsigned int startTime; int side; struct TeleBlock *twin; unsigned int lastClickTime; int frame; }

user_defined_types: struct IceCream { enum EntityType type; int x; int y; int frame; unsigned int lastFrameUpdateTime; int decoy; unsigned int decoyTime; }

user_defined_types: struct SuperHammer { enum EntityType type; int x; int y; }

user_defined_types: struct Shiruken { enum EntityType type; int x; int y; }

user_defined_types: struct FloorGlue { enum EntityType type; int x; int y; unsigned int startTime; int population; }

user_defined_types: struct Enemy { enum EntityType type; int x; int y; int direction; int offsetX; int offsetY; int health; unsigned int lastMovementUpdate; unsigned char knockBackDirection; struct IceCream *cream; int AISlot1; int AISlot2; int AISlot3; unsigned int timer; unsigned int lastFrameUpdate; int frame; }

user_defined_types: struct Poof { enum EntityType type; int x; int y; unsigned int startTime; int offsetX; int offsetY; int colour; int birthed; }

user_defined_types: struct GameBlock { enum EntityType type; int x; int y; int height; unsigned int lastUpdateTime; unsigned int startTime; enum BlockType bType; }


updateWave

decompiled_code:
__int64 updateWave()
{
__int64 v0; // r13
__int64 v1; // rbx
int v2; // er14
int v3; // ebp
int v4; // er12
_DWORD *v5; // rax
int v6; // ebx
__int64 result; // rax
unsigned int v8; // ebx
char v9; // al
__int64 v10; // r13
char v11; // al
int v12; // er13
unsigned int v13; // ebx
__int64 v14; // r12
int v15; // [rsp+Ch] [rbp-5Ch] BYREF
char v16[88]; // [rsp+10h] [rbp-58h] BYREF

v0 = getEntityList();
v1 = 0LL;
v2 = 0;
v3 = 0;
v4 = 0;
while ( (int)getEntityListSize() > (int)v1 )
{
if ( v3 <= 299 && (unsigned int)(**(_DWORD **)(v0 + 8 * v1) - 8) <= 3 )
{
++v3;
}
else if ( v2 <= 29 )
{
v5 = *(_DWORD **)(v0 + 8 * v1);
if ( *v5 == 12 )
{
v2 += v5[5] == 0;
goto LABEL_5;
}
}
if ( v4 <= 299 )
v4 += **(_DWORD **)(v0 + 8 * v1) == 3;
LABEL_5:
++v1;
}
v6 = lastUpdateTime;
result = getTimeSingleton();
if ( (unsigned int)(v6 - result) > 0x3E8 )
{
v8 = (unsigned int)xrand() % 0x2710;
if ( maxOnScreenRobots > v3
&& enemiesLeftToPush > 0
&& (unsigned int)getTimeSingleton() - sinceLastEnemyOutput > enemyPushInterval )
{
if ( (xrand() & 1) != 0 )
{
v9 = xrand();
v10 = pushEntity((unsigned int)waveTypeEnemy1, 0xFFFFFFFFLL, (v9 & 7u) + 6);
}
else
{
v11 = xrand();
v10 = pushEntity((unsigned int)waveTypeEnemy2, 0xFFFFFFFFLL, (v11 & 7u) + 6);
}
*(_DWORD *)(v10 + 12) = 1;
if ( (xrand() & 1) == 0 )
{
*(_DWORD *)(v10 + 4) += 21;
*(_DWORD *)(v10 + 12) = 3;
}
sinceLastEnemyOutput = getTimeSingleton();
--enemiesLeftToPush;
}
if ( v8 <= 0x4F && v4 <= 19 )
{
v12 = 5;
while ( 1 )
{
v13 = (xrand() & 0xF) + 2;
v14 = (unsigned int)(xrand() & 7) + 6;
v15 = 0;
occupyingOnHere(v13, v14, v16, 5LL, &v15);
if ( !v15 )
break;
if ( !--v12 )
goto LABEL_22;
}
if ( (xrand() & 1) != 0 )
*(_DWORD *)(pushEntity(3LL, v13, (unsigned int)v14) + 24) = waveTypeBlock2;
else
*(_DWORD *)(pushEntity(3LL, v13, (unsigned int)v14) + 24) = waveTypeBlock1;
}
LABEL_22:
result = getTimeSingleton();
lastUpdateTime = result;
}
if ( !(enemiesLeftToPush | v3) )
{
restPeriod = 1;
restPeriodStart = getTimeSingleton();
switch ( rand() % 10 )
{
case 0:
pushNewMessage("NICE ONE! WAVE COMPLETE!");
break;
case 1:
pushNewMessage("WAVE COMPLETE! PARTY ROCK!");
break;
case 2:
pushNewMessage("SO MUCH WAVE COMPLETE RIGHT NOW!");
break;
case 3:
pushNewMessage("BOYFRIENDS SAFE! WAVE COMPLETE!");
break;
case 4:
pushNewMessage("WAVE COMPLETE! MOMS LOVE YOU!");
break;
case 5:
pushNewMessage("HARDCORE WAVE COMPLETE!");
break;
case 6:
pushNewMessage("YOU JUST COMPLETED THAT WAVE!");
break;
case 7:
pushNewMessage("WAVE OF BADDIES BUSTED!");
break;
case 8:
pushNewMessage("THIS WAVE IS SO OVER YOU GUYS!");
break;
case 9:
pushNewMessage("WAVE CONQUERED AND STUFF!");
break;
default:
pushNewMessage("WAVE COMPLETE!");
break;
}
result = fadeBGM();
}
if ( numberOfIceCreams > v2 && v2 > 0 )
{
pushNewMessage("PRINCE BOYFRIEND LOST!");
result = playSFX(21LL);
}
numberOfIceCreams = v2;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // r13
__int64 v1; // rbx
int v2; // er14
int v3; // ebp
int v4; // er12
_DWORD *v5; // rax
int v6; // ebx
__int64 result; // rax
unsigned int v8; // ebx
char v9; // al
__int64 v10; // r13
char v11; // al
int v12; // er13
unsigned int v13; // ebx
__int64 v14; // r12
int v15; // [rsp+Ch] [rbp-5Ch] BYREF
char v16[88]; // [rsp+10h] [rbp-58h] BYREF

v0 = getEntityList();
v1 = 0LL;
v2 = 0;
v3 = 0;
v4 = 0;
while ( (int)getEntityListSize() > (int)v1 )
{
if ( v3 <= 299 && (unsigned int)(**(_DWORD **)(v0 + 8 * v1) - 8) <= 3 )
{
++v3;
}
else if ( v2 <= 29 )
{
v5 = *(_DWORD **)(v0 + 8 * v1);
if ( *v5 == 12 )
{
v2 += v5[5] == 0;
goto LABEL_5;
}
}
if ( v4 <= 299 )
v4 += **(_DWORD **)(v0 + 8 * v1) == 3;
LABEL_5:
++v1;
}
v6 = lastUpdateTime;
result = getTimeSingleton();
if ( (unsigned int)(v6 - result) > 0x3E8 )
{
v8 = (unsigned int)func0() % 0x2710;
if ( maxOnScreenRobots > v3
&& enemiesLeftToPush > 0
&& (unsigned int)getTimeSingleton() - sinceLastEnemyOutput > enemyPushInterval )
{
if ( (func0() & 1) != 0 )
{
v9 = func0();
v10 = pushEntity((unsigned int)waveTypeEnemy1, 0xFFFFFFFFLL, (v9 & 7u) + 6);
}
else
{
v11 = func0();
v10 = pushEntity((unsigned int)waveTypeEnemy2, 0xFFFFFFFFLL, (v11 & 7u) + 6);
}
*(_DWORD *)(v10 + 12) = 1;
if ( (func0() & 1) == 0 )
{
*(_DWORD *)(v10 + 4) += 21;
*(_DWORD *)(v10 + 12) = 3;
}
sinceLastEnemyOutput = getTimeSingleton();
--enemiesLeftToPush;
}
if ( v8 <= 0x4F && v4 <= 19 )
{
v12 = 5;
while ( 1 )
{
v13 = (func0() & 0xF) + 2;
v14 = (unsigned int)(func0() & 7) + 6;
v15 = 0;
occupyingOnHere(v13, v14, v16, 5LL, &v15);
if ( !v15 )
break;
if ( !--v12 )
goto LABEL_22;
}
if ( (func0() & 1) != 0 )
*(_DWORD *)(pushEntity(3LL, v13, (unsigned int)v14) + 24) = waveTypeBlock2;
else
*(_DWORD *)(pushEntity(3LL, v13, (unsigned int)v14) + 24) = waveTypeBlock1;
}
LABEL_22:
result = getTimeSingleton();
lastUpdateTime = result;
}
if ( !(enemiesLeftToPush | v3) )
{
restPeriod = 1;
restPeriodStart = getTimeSingleton();
switch ( rand() % 10 )
{
case 0:
pushNewMessage("NICE ONE! WAVE COMPLETE!");
break;
case 1:
pushNewMessage("WAVE COMPLETE! PARTY ROCK!");
break;
case 2:
pushNewMessage("SO MUCH WAVE COMPLETE RIGHT NOW!");
break;
case 3:
pushNewMessage("BOYFRIENDS SAFE! WAVE COMPLETE!");
break;
case 4:
pushNewMessage("WAVE COMPLETE! MOMS LOVE YOU!");
break;
case 5:
pushNewMessage("HARDCORE WAVE COMPLETE!");
break;
case 6:
pushNewMessage("YOU JUST COMPLETED THAT WAVE!");
break;
case 7:
pushNewMessage("WAVE OF BADDIES BUSTED!");
break;
case 8:
pushNewMessage("THIS WAVE IS SO OVER YOU GUYS!");
break;
case 9:
pushNewMessage("WAVE CONQUERED AND STUFF!");
break;
default:
pushNewMessage("WAVE COMPLETE!");
break;
}
result = fadeBGM();
}
if ( numberOfIceCreams > v2 && v2 > 0 )
{
pushNewMessage("PRINCE BOYFRIEND LOST!");
result = playSFX(21LL);
}
numberOfIceCreams = v2;
return result;
}

original_code:
void updateWave()
{
 int i;
 int gameBlockCount = 0;
 int enemyCount = 0;
 int iceCreamCount = 0;
 Entity** entList = getEntityList();
 for (i = 0; i < getEntityListSize(); i++)
 {
  if (enemyCount < 300 && (entList[i]->type == ENEMY_FAST || entList[i]->type == ENEMY_SHOOTER || entList[i]->type == ENEMY_CRAWLER || entList[i]->type == ENEMY_BOXERGREG))
  {
   enemyCount++;
  }
  if (iceCreamCount < 30 && entList[i]->type == ICECREAM && entList[i]->iceCream.decoy == 0)
  {
   iceCreamCount++;
  }
  if (gameBlockCount < 300 && entList[i]->type == GAMEBLOCK)
  {
   gameBlockCount++;
  }
 }
 if (lastUpdateTime - getTimeSingleton() > 1000)
 {
  unsigned int val = xrand() % 10000;
  if (enemyCount < maxOnScreenRobots && enemiesLeftToPush > 0)
  {
   if (getTimeSingleton() - sinceLastEnemyOutput > enemyPushInterval)
   {
    Enemy* en;
    switch (xrand() % 2)
    {
     case 1:
     en = (Enemy*)pushEntity(waveTypeEnemy1, -1, (xrand() % 8) + 6);
     break;
     case 0:
     default:
     en = (Enemy*)pushEntity(waveTypeEnemy2, -1, (xrand() % 8) + 6);
     break;
    }
    en->direction = 1;
    if (xrand() % 2 == 0)
    {
     en->x += 20 + 1;
     en->direction = 3;
    }
    sinceLastEnemyOutput = getTimeSingleton();
    enemiesLeftToPush--;
   }
  }
  if (gameBlockCount < 20)
  {
   if(val / 20 < 4)
   {
    int i;
    int xSpot = -1;
    int ySpot = -1;
    for (i = 0; i < 5; i++)
    {
     xSpot = (xrand() % (20 - 4)) + 2;
     ySpot = (xrand() % 8) + 6;
     Entity* checkList[5];
     int checkResultSize = 0;
     occupyingOnHere(xSpot, ySpot, checkList, 5, &checkResultSize);
     if (checkResultSize == 0)
     {
      Entity* newBlock;
      switch (xrand() % 2)
      {
       case 0:
       newBlock = pushEntity(GAMEBLOCK, xSpot, ySpot);
                     newBlock->gBlock.bType = waveTypeBlock1;
                     break;
       case 1:
       newBlock = pushEntity(GAMEBLOCK, xSpot, ySpot);
                     newBlock->gBlock.bType = waveTypeBlock2;
                     break;
       default:
       break;
      }
      break;
     }
    }
   }
  }
  lastUpdateTime = getTimeSingleton();
 }
 if (enemiesLeftToPush == 0 && enemyCount == 0)
 {
  restPeriod = 1;
  restPeriodStart = getTimeSingleton();
  switch (rand() % 10)
  {
   case 0:
   pushNewMessage("NICE ONE! WAVE COMPLETE!");
   break;
   case 1:
   pushNewMessage("WAVE COMPLETE! PARTY ROCK!");
   break;
   case 2:
   pushNewMessage("SO MUCH WAVE COMPLETE RIGHT NOW!");
   break;
   case 3:
   pushNewMessage("BOYFRIENDS SAFE! WAVE COMPLETE!");
   break;
   case 4:
   pushNewMessage("WAVE COMPLETE! MOMS LOVE YOU!");
   break;
                        case 5:
   pushNewMessage("HARDCORE WAVE COMPLETE!");
   break;
   case 6:
   pushNewMessage("YOU JUST COMPLETED THAT WAVE!");
   break;
   case 7:
   pushNewMessage("WAVE OF BADDIES BUSTED!");
   break;
   case 8:
   pushNewMessage("THIS WAVE IS SO OVER YOU GUYS!");
   break;
   case 9:
   pushNewMessage("WAVE CONQUERED AND STUFF!");
   break;
   default:
   pushNewMessage("WAVE COMPLETE!");
   break;
  }
  fadeBGM();
 }
 if (iceCreamCount < numberOfIceCreams && iceCreamCount > 0)
 {
  pushNewMessage("PRINCE BOYFRIEND LOST!");
  playSFX(SFX_LOSE_PRINCESS);
 }
 numberOfIceCreams = iceCreamCount;
}

canonical_original_code:
void updateWave()
{
 int i;
 int gameBlockCount = 0;
 int enemyCount = 0;
 int iceCreamCount = 0;
 union Entity **entList = getEntityList();
 for (i = 0; i < getEntityListSize(); i++)
 {
  if (enemyCount < 300 && (entList[i]->type == ENEMY_FAST || entList[i]->type == ENEMY_SHOOTER || entList[i]->type == ENEMY_CRAWLER || entList[i]->type == ENEMY_BOXERGREG))
  {
   enemyCount++;
  }
  if (iceCreamCount < 30 && entList[i]->type == ICECREAM && entList[i]->iceCream.decoy == 0)
  {
   iceCreamCount++;
  }
  if (gameBlockCount < 300 && entList[i]->type == GAMEBLOCK)
  {
   gameBlockCount++;
  }
 }
 if (lastUpdateTime - getTimeSingleton() > 1000)
 {
  unsigned int val = xrand() % 10000;
  if (enemyCount < maxOnScreenRobots && enemiesLeftToPush > 0)
  {
   if (getTimeSingleton() - sinceLastEnemyOutput > enemyPushInterval)
   {
    struct Enemy *en;
    switch (xrand() % 2)
    {
     case 1:
     en = (struct Enemy *)pushEntity(waveTypeEnemy1, -1, (xrand() % 8) + 6);
     break;
     case 0:
     default:
     en = (struct Enemy *)pushEntity(waveTypeEnemy2, -1, (xrand() % 8) + 6);
     break;
    }
    en->direction = 1;
    if (xrand() % 2 == 0)
    {
     en->x += 20 + 1;
     en->direction = 3;
    }
    sinceLastEnemyOutput = getTimeSingleton();
    enemiesLeftToPush--;
   }
  }
  if (gameBlockCount < 20)
  {
   if(val / 20 < 4)
   {
    int i;
    int xSpot = -1;
    int ySpot = -1;
    for (i = 0; i < 5; i++)
    {
     xSpot = (xrand() % (20 - 4)) + 2;
     ySpot = (xrand() % 8) + 6;
     union Entity *checkList[5];
     int checkResultSize = 0;
     occupyingOnHere(xSpot, ySpot, checkList, 5, &checkResultSize);
     if (checkResultSize == 0)
     {
      union Entity *newBlock;
      switch (xrand() % 2)
      {
       case 0:
       newBlock = pushEntity(GAMEBLOCK, xSpot, ySpot);
                     newBlock->gBlock.bType = waveTypeBlock1;
                     break;
       case 1:
       newBlock = pushEntity(GAMEBLOCK, xSpot, ySpot);
                     newBlock->gBlock.bType = waveTypeBlock2;
                     break;
       default:
       break;
      }
      break;
     }
    }
   }
  }
  lastUpdateTime = getTimeSingleton();
 }
 if (enemiesLeftToPush == 0 && enemyCount == 0)
 {
  restPeriod = 1;
  restPeriodStart = getTimeSingleton();
  switch (rand() % 10)
  {
   case 0:
   pushNewMessage("NICE ONE! WAVE COMPLETE!");
   break;
   case 1:
   pushNewMessage("WAVE COMPLETE! PARTY ROCK!");
   break;
   case 2:
   pushNewMessage("SO MUCH WAVE COMPLETE RIGHT NOW!");
   break;
   case 3:
   pushNewMessage("BOYFRIENDS SAFE! WAVE COMPLETE!");
   break;
   case 4:
   pushNewMessage("WAVE COMPLETE! MOMS LOVE YOU!");
   break;
                        case 5:
   pushNewMessage("HARDCORE WAVE COMPLETE!");
   break;
   case 6:
   pushNewMessage("YOU JUST COMPLETED THAT WAVE!");
   break;
   case 7:
   pushNewMessage("WAVE OF BADDIES BUSTED!");
   break;
   case 8:
   pushNewMessage("THIS WAVE IS SO OVER YOU GUYS!");
   break;
   case 9:
   pushNewMessage("WAVE CONQUERED AND STUFF!");
   break;
   default:
   pushNewMessage("WAVE COMPLETE!");
   break;
  }
  fadeBGM();
 }
 if (iceCreamCount < numberOfIceCreams && iceCreamCount > 0)
 {
  pushNewMessage("PRINCE BOYFRIEND LOST!");
  playSFX(SFX_LOSE_PRINCESS);
 }
 numberOfIceCreams = iceCreamCount;
}

variable_types: gameBlockCount int

variable_types: enemyCount int

variable_types: iceCreamCount int

variable_types:
val
unsigned int

variable_types: struct Enemy { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int direction; int offsetX; int offsetY; int health; unsigned int lastMovementUpdate; unsigned char knockBackDirection; struct IceCream { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int frame; unsigned int lastFrameUpdateTime; int decoy; unsigned int decoyTime; } *cream; int AISlot1; int AISlot2; int AISlot3; unsigned int timer; unsigned int lastFrameUpdate; int frame; } *

variable_types: xSpot int

variable_types: ySpot int

variable_types: union Entity { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; struct entityBase { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } base; struct Player { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int offsetX; int offsetY; unsigned char direction; unsigned char upKeyDown; unsigned char downKeyDown; unsigned char leftKeyDown; unsigned char rightKeyDown; unsigned char aKeyDown; unsigned char bKeyDown; unsigned int swordTimer; int isThrusting; int thrustHit; struct GameBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int height; unsigned int lastUpdateTime; unsigned int startTime; enum BlockType { NO_BLOCK=0, RED_BLOCK=1, BLUE_BLOCK=2, GREEN_BLOCK=3, YELLOW_BLOCK=4 } bType; } *holding; unsigned int lastUpdate; unsigned char knockBackDirection; unsigned int lastFrameUpdate; int frame; int holdingSuperHammer; int dead; } player; struct PermaBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } permaBlock; struct GameBlock gBlock; struct IceBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int moving; unsigned char direction; int offsetX; int offsetY; unsigned int lastMovementUpdate; int health; unsigned int startTime; } iBlock; struct Explosion { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; } exp; struct Laser { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned char direction; int offsetX; int offsetY; unsigned int lastMovementUpdate; unsigned char allegiance; int frame; unsigned int lastFrameUpdate; } laser; struct TeleBlock { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; int side; struct TeleBlock *twin; unsigned int lastClickTime; int frame; } tBlock; struct IceCream { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int frame; unsigned int lastFrameUpdateTime; int decoy; unsigned int decoyTime; } iceCream; struct SuperHammer { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } hammer; struct Shiruken { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; } shiruken; struct FloorGlue { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; int population; } glue; struct Enemy { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; int direction; int offsetX; int offsetY; int health; unsigned int lastMovementUpdate; unsigned char knockBackDirection; struct IceCream *cream; int AISlot1; int AISlot2; int AISlot3; unsigned int timer; unsigned int lastFrameUpdate; int frame; } enemy; struct Poof { enum EntityType { PLAYER1=0, PLAYER2=1, PERMABLOCK=2, GAMEBLOCK=3, ICEBLOCK=4, EXPLOSION=5, LASER=6, TELEBLOCK=7, ENEMY_CRAWLER=8, ENEMY_SHOOTER=9, ENEMY_BOXERGREG=10, ENEMY_FAST=11, ICECREAM=12, SUPERHAMMER=13, SHIRUKEN=14, GLUE=15, POOF=16, HEART=17, DELETE_ME_PLEASE=18 } type; int x; int y; unsigned int startTime; int offsetX; int offsetY; int colour; int birthed; } poof; } *[5]

variable_types: checkResultSize int


updateGameLogic

decompiled_code:
void updateGameLogic()
{
if ( gameState )
{
if ( !lastUpdateTime )
{
lastUpdateTime = getTimeSingleton();
return;
}
if ( player1Health <= 0 && (!is2PlayerGame || player2Health <= 0 && is2PlayerGame == 1) )
{
if ( gameEnding )
{
if ( gameEnding != 1 )
{
LABEL_5:
if ( restPeriod )
{
if ( restPeriod == 1 )
updateRestPeriod();
}
else
{
updateWave();
}
return;
}
if ( (unsigned int)getTimeSingleton() - endGameDelta > 0x1388 )
gameState = 2;
}
else
{
gameEnding = 1;
endGameDelta = getTimeSingleton();
}
}
if ( numberOfIceCreams <= 0 )
{
if ( gameEnding )
{
if ( gameEnding == 1 && (unsigned int)getTimeSingleton() - endGameDelta > 0x1B58 )
gameState = 3;
}
else
{
pushNewMessage("no more princes!");
gameEnding = 1;
endGameDelta = getTimeSingleton();
}
}
goto LABEL_5;
}
}

canonical_decompiled_code:
void func5()
{
if ( gameState )
{
if ( !lastUpdateTime )
{
lastUpdateTime = getTimeSingleton();
return;
}
if ( player1Health <= 0 && (!is2PlayerGame || player2Health <= 0 && is2PlayerGame == 1) )
{
if ( gameEnding )
{
if ( gameEnding != 1 )
{
LABEL_5:
if ( restPeriod )
{
if ( restPeriod == 1 )
func3();
}
else
{
func4();
}
return;
}
if ( (unsigned int)getTimeSingleton() - endGameDelta > 0x1388 )
gameState = 2;
}
else
{
gameEnding = 1;
endGameDelta = getTimeSingleton();
}
}
if ( numberOfIceCreams <= 0 )
{
if ( gameEnding )
{
if ( gameEnding == 1 && (unsigned int)getTimeSingleton() - endGameDelta > 0x1B58 )
gameState = 3;
}
else
{
pushNewMessage("no more princes!");
gameEnding = 1;
endGameDelta = getTimeSingleton();
}
}
goto LABEL_5;
}
}

original_code:
void updateGameLogic()
{
 if (gameState == 0)
 {
  return;
 }
 if (lastUpdateTime == 0)
 {
  lastUpdateTime = getTimeSingleton();
  return;
 }
 if ( (player1Health < 1 && is2PlayerGame == 0) || (player1Health < 1 && player2Health < 1 && is2PlayerGame == 1) )
 {
  if (gameEnding == 0)
  {
   gameEnding = 1;
   endGameDelta = getTimeSingleton();
  }
  else if (gameEnding == 1)
  {
   if (getTimeSingleton() - endGameDelta > 5 * 1000)
   {
    gameState = 2;
   }
  }
 }
 if (numberOfIceCreams < 1)
 {
  if (gameEnding == 0)
  {
   pushNewMessage("no more princes!");
   gameEnding = 1;
   endGameDelta = getTimeSingleton();
  }
  else if (gameEnding == 1)
  {
   if (getTimeSingleton() - endGameDelta > 7 * 1000)
   {
    gameState = 3;
   }
  }
 }
 if (restPeriod == 0)
 {
  updateWave();
 }
 else if (restPeriod == 1)
 {
  updateRestPeriod();
 }
}


clearResetGame

decompiled_code:
__int64 __fastcall clearResetGame(int a1)
{
unsigned int i; // ebx
unsigned int j; // ebx

gameState = 0;
if ( a1 == 2 )
{
player1Health = 5;
player2Health = 5;
player1MaxHealth = 5;
}
else
{
player1Health = 10;
player2Health = 10;
player1MaxHealth = 10;
}
player2MaxHealth = 5;
gameScore = 0;
gameEnding = 0;
waveNumber = 0;
currentBGM = 0;
maxOnScreenRobots = 5;
enemyPushInterval = 3000;
if ( getEntityList() )
freeEntityList();
initEntityList();
for ( i = -2; i != 23; ++i )
{
pushEntity(2LL, i, 5LL);
pushEntity(2LL, i, 14LL);
}
for ( j = 5; j != 20; ++j )
{
pushEntity(2LL, 4294967294LL, j);
pushEntity(2LL, 21LL, j);
}
pushEntity(12LL, 9LL, 7LL);
pushEntity(12LL, 9LL, 8LL);
pushEntity(12LL, 9LL, 11LL);
pushEntity(12LL, 9LL, 12LL);
pushEntity(12LL, 10LL, 7LL);
pushEntity(12LL, 10LL, 8LL);
pushEntity(12LL, 10LL, 11LL);
pushEntity(12LL, 10LL, 12LL);
if ( a1 == 1 )
{
pushEntity(0LL, 10LL, 9LL);
is2PlayerGame = 0;
}
else if ( a1 == 2 )
{
pushEntity(0LL, 10LL, 9LL);
pushEntity(1LL, 11LL, 9LL);
is2PlayerGame = 1;
}
else
{
printf("ODD PLAYER COUNT; FIX THIS AND MAKE IT ATOMIC");
pushEntity(0LL, 10LL, 9LL);
is2PlayerGame = 0;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned int i; // ebx
unsigned int j; // ebx

gameState = 0;
if ( a1 == 2 )
{
player1Health = 5;
player2Health = 5;
player1MaxHealth = 5;
}
else
{
player1Health = 10;
player2Health = 10;
player1MaxHealth = 10;
}
player2MaxHealth = 5;
gameScore = 0;
gameEnding = 0;
waveNumber = 0;
currentBGM = 0;
maxOnScreenRobots = 5;
enemyPushInterval = 3000;
if ( getEntityList() )
freeEntityList();
initEntityList();
for ( i = -2; i != 23; ++i )
{
pushEntity(2LL, i, 5LL);
pushEntity(2LL, i, 14LL);
}
for ( j = 5; j != 20; ++j )
{
pushEntity(2LL, 4294967294LL, j);
pushEntity(2LL, 21LL, j);
}
pushEntity(12LL, 9LL, 7LL);
pushEntity(12LL, 9LL, 8LL);
pushEntity(12LL, 9LL, 11LL);
pushEntity(12LL, 9LL, 12LL);
pushEntity(12LL, 10LL, 7LL);
pushEntity(12LL, 10LL, 8LL);
pushEntity(12LL, 10LL, 11LL);
pushEntity(12LL, 10LL, 12LL);
if ( a1 == 1 )
{
pushEntity(0LL, 10LL, 9LL);
is2PlayerGame = 0;
}
else if ( a1 == 2 )
{
pushEntity(0LL, 10LL, 9LL);
pushEntity(1LL, 11LL, 9LL);
is2PlayerGame = 1;
}
else
{
printf("ODD PLAYER COUNT; FIX THIS AND MAKE IT ATOMIC");
pushEntity(0LL, 10LL, 9LL);
is2PlayerGame = 0;
}
return 0LL;
}

original_code:
int clearResetGame(int playerCount)
{
 int i;
 gameState = 0;
 if (playerCount == 2)
 {
  player1Health = 5;
  player2Health = 5;
  player1MaxHealth = 5;
  player2MaxHealth = 5;
 }
 else
 {
  player1Health = 10;
  player2Health = 10;
  player1MaxHealth = 10;
  player2MaxHealth = 5;
 }
 gameScore = 0;
 gameEnding = 0;
 waveNumber = 0;
 currentBGM = BGM_NONE;
 maxOnScreenRobots = 5;
 enemyPushInterval = 3000;
 if (getEntityList() != ((void *)0))
 {
  freeEntityList();
 }
 initEntityList();
 for (i = -2; i < 20 + 3; i++)
 {
  pushEntity(PERMABLOCK, i, 5);
  pushEntity(PERMABLOCK, i, 14);
 }
 for (i = 0; i < 13 + 2; i++)
 {
  pushEntity(PERMABLOCK, -2, 5 + i);
  pushEntity(PERMABLOCK, 20 + 1, 5 + i);
 }
 for (i = 0; i < 2; i++)
 {
  pushEntity(ICECREAM, 9 + i, 7);
  pushEntity(ICECREAM, 9 + i, 8);
  pushEntity(ICECREAM, 9 + i, 11);
  pushEntity(ICECREAM, 9 + i, 12);
 }
 switch (playerCount)
 {
  case 1:
  pushEntity(PLAYER1, 20/2, 9);
  is2PlayerGame = 0;
  break;
  case 2:
  pushEntity(PLAYER1, 20/2, 9);
                pushEntity(PLAYER2, 20/2 + 1, 9);
                is2PlayerGame = 1;
                break;
                default:
                printf("ODD PLAYER COUNT; FIX THIS AND MAKE IT ATOMIC");
                pushEntity(PLAYER1, 20/2, 9);
  is2PlayerGame = 0;
  break;
 }
 return 0;
}

variable_types: playerCount int

variable_types: i int


beginGame

decompiled_code:
__int64 beginGame()
{
unsigned int v0; // ebx
unsigned int v2; // eax
unsigned int v3; // eax
const char *v4; // rbp
unsigned int v5; // eax
const char *v6; // rax
unsigned int v7; // eax
const char *v8; // rbp
unsigned int v9; // eax
const char *v10; // rax
char v11[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = gameState;
if ( gameState )
return 1;
gameState = 1;
restPeriod = 1;
numberOfIceCreams = 8;
v2 = SDL_GetTicks();
setTimeSingleton(v2);
pushNewMessage("NINJAS WANT YOUR BOYFRIENDS!");
pushNewMessage("YOU MUST PROTECT THEM!");
v3 = getSDLKeyValue(5LL);
v4 = (const char *)SDL_GetKeyName(v3);
v5 = getSDLKeyValue(6LL);
v6 = (const char *)SDL_GetKeyName(v5);
sprintf(v11, "P1 Keys: %s=Strike, %s=grab block", v6, v4);
pushNewMessage(v11);
if ( is2PlayerGame )
{
v7 = getSDLKeyValue(13LL);
v8 = (const char *)SDL_GetKeyName(v7);
v9 = getSDLKeyValue(14LL);
v10 = (const char *)SDL_GetKeyName(v9);
sprintf(v11, "P2 Keys: %s=Strike, %s=grab block", v10, v8);
pushNewMessage(v11);
}
currentBGM = 2;
playBGM(2LL);
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebx
unsigned int v2; // eax
unsigned int v3; // eax
const char *v4; // rbp
unsigned int v5; // eax
const char *v6; // rax
unsigned int v7; // eax
const char *v8; // rbp
unsigned int v9; // eax
const char *v10; // rax
char v11[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = gameState;
if ( gameState )
return 1;
gameState = 1;
restPeriod = 1;
numberOfIceCreams = 8;
v2 = SDL_GetTicks();
setTimeSingleton(v2);
pushNewMessage("NINJAS WANT YOUR BOYFRIENDS!");
pushNewMessage("YOU MUST PROTECT THEM!");
v3 = getSDLKeyValue(5LL);
v4 = (const char *)SDL_GetKeyName(v3);
v5 = getSDLKeyValue(6LL);
v6 = (const char *)SDL_GetKeyName(v5);
sprintf(v11, "P1 Keys: %s=Strike, %s=grab block", v6, v4);
pushNewMessage(v11);
if ( is2PlayerGame )
{
v7 = getSDLKeyValue(13LL);
v8 = (const char *)SDL_GetKeyName(v7);
v9 = getSDLKeyValue(14LL);
v10 = (const char *)SDL_GetKeyName(v9);
sprintf(v11, "P2 Keys: %s=Strike, %s=grab block", v10, v8);
pushNewMessage(v11);
}
currentBGM = 2;
playBGM(2LL);
return v0;
}

original_code:
int beginGame()
{
 char playerControlsMessage[50];
 if (gameState != 0)
 {
  return 1;
 }
 gameState = 1;
 restPeriod = 1;
 numberOfIceCreams = 8;
 setTimeSingleton(SDL_GetTicks());
 pushNewMessage("NINJAS WANT YOUR BOYFRIENDS!");
 pushNewMessage("YOU MUST PROTECT THEM!");
 sprintf(playerControlsMessage, "P1 Keys: %s=Strike, %s=grab block", SDL_GetKeyName(getSDLKeyValue(P1_B)), SDL_GetKeyName(getSDLKeyValue(P1_A)));
 pushNewMessage(playerControlsMessage);
 if (is2PlayerGame)
 {
  sprintf(playerControlsMessage, "P2 Keys: %s=Strike, %s=grab block", SDL_GetKeyName(getSDLKeyValue(P2_B)), SDL_GetKeyName(getSDLKeyValue(P2_A)));
  pushNewMessage(playerControlsMessage);
 }
 currentBGM = BGM_1;
 playBGM(currentBGM);
 return 0;
}

variable_types:
playerControlsMessage
char [50]