repo: StaticFiend/TestRL

decompiled_code:
__int64 __fastcall cave_walk(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rdx
unsigned __int8 v6; // dl
unsigned __int8 v7; // dl

if ( a1 > 5 )
{
if ( (unsigned int)(a1 - 6) > 2 )
goto LABEL_15;
v6 = *(_BYTE *)(a3 + 4);
result = *(unsigned __int8 *)(a3 + 5);
if ( v6 <= 0x4Cu )
*(_BYTE *)(a3 + 4) = v6 + 1;
}
else if ( a1 > 2 )
{
v7 = *(_BYTE *)(a3 + 4);
result = *(unsigned __int8 *)(a3 + 5);
if ( v7 > 2u )
*(_BYTE *)(a3 + 4) = v7 - 1;
}
else
{
if ( a1 != 1 )
{
if ( a1 == 2 )
{
result = *(unsigned __int8 *)(a3 + 5);
if ( (unsigned __int8)result <= 0x24u )
{
result = (unsigned int)(result + 1);
*(_BYTE *)(a3 + 5) = result;
}
goto LABEL_7;
}
LABEL_15:
puts("[Console] Invalid direction, how'd you manage this?");
printf(
"[Console] walker.x: %i walker.y: %i direction: %i\n",
*(unsigned __int8 *)(a3 + 4),
*(unsigned __int8 *)(a3 + 5),
(unsigned int)a1);
result = *(unsigned __int8 *)(a3 + 5);
goto LABEL_7;
}
result = *(unsigned __int8 *)(a3 + 5);
if ( (unsigned __int8)result > 2u )
{
result = (unsigned int)(result - 1);
*(_BYTE *)(a3 + 5) = result;
}
}
LABEL_7:
if ( (unsigned __int8)(result - 2) <= 0x23u )
{
v5 = *(unsigned __int8 *)(a3 + 4);
if ( (unsigned __int8)(v5 - 2) <= 0x4Bu )
{
result = (unsigned __int8)result;
*(_BYTE *)(a2 + 80LL * (unsigned __int8)result + v5) = 46;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rdx
unsigned __int8 v6; // dl
unsigned __int8 v7; // dl

if ( a1 > 5 )
{
if ( (unsigned int)(a1 - 6) > 2 )
goto LABEL_15;
v6 = *(_BYTE *)(a3 + 4);
result = *(unsigned __int8 *)(a3 + 5);
if ( v6 <= 0x4Cu )
*(_BYTE *)(a3 + 4) = v6 + 1;
}
else if ( a1 > 2 )
{
v7 = *(_BYTE *)(a3 + 4);
result = *(unsigned __int8 *)(a3 + 5);
if ( v7 > 2u )
*(_BYTE *)(a3 + 4) = v7 - 1;
}
else
{
if ( a1 != 1 )
{
if ( a1 == 2 )
{
result = *(unsigned __int8 *)(a3 + 5);
if ( (unsigned __int8)result <= 0x24u )
{
result = (unsigned int)(result + 1);
*(_BYTE *)(a3 + 5) = result;
}
goto LABEL_7;
}
LABEL_15:
puts("[Console] Invalid direction, how'd you manage this?");
printf(
"[Console] walker.x: %i walker.y: %i direction: %i\n",
*(unsigned __int8 *)(a3 + 4),
*(unsigned __int8 *)(a3 + 5),
(unsigned int)a1);
result = *(unsigned __int8 *)(a3 + 5);
goto LABEL_7;
}
result = *(unsigned __int8 *)(a3 + 5);
if ( (unsigned __int8)result > 2u )
{
result = (unsigned int)(result - 1);
*(_BYTE *)(a3 + 5) = result;
}
}
LABEL_7:
if ( (unsigned __int8)(result - 2) <= 0x23u )
{
v5 = *(unsigned __int8 *)(a3 + 4);
if ( (unsigned __int8)(v5 - 2) <= 0x4Bu )
{
result = (unsigned __int8)result;
*(_BYTE *)(a2 + 80LL * (unsigned __int8)result + v5) = 46;
}
}
return result;
}

original_code:
void cave_walk(int dir, char map[][80], tile_t *walker) {
 switch(dir) {
  case 1:
   if ((walker->y - 1) > 1)
    walker->y -= 1;
    break;
  case 2:
    if ((walker->y + 1) < (40 - 2))
    walker->y += 1;
    break;
  case 3:
  case 4:
  case 5:
    if ((walker->x - 1) > 1)
     walker->x -= 1;
    break;
  case 6:
  case 7:
  case 8:
    if ((walker->x + 1) < (80 - 2))
     walker->x += 1;
    break;
  default:
    printf("[Console] Invalid direction, how'd you manage this?\n");
    printf("[Console] walker.x: %i  walker.y: %i  direction: %i\n", walker->x, walker->y, dir);
    break;
 }
 if ((walker->y > 1) && (walker->y < 40 - 2) && (walker->x > 1) && (walker->x < 80 - 2))
  map[walker->y][walker->x] = 46;
}

canonical_original_code:
void cave_walk(int dir, char map[][80], struct tile_s *walker) {
 switch(dir) {
  case 1:
   if ((walker->y - 1) > 1)
    walker->y -= 1;
    break;
  case 2:
    if ((walker->y + 1) < (40 - 2))
    walker->y += 1;
    break;
  case 3:
  case 4:
  case 5:
    if ((walker->x - 1) > 1)
     walker->x -= 1;
    break;
  case 6:
  case 7:
  case 8:
    if ((walker->x + 1) < (80 - 2))
     walker->x += 1;
    break;
  default:
    printf("[Console] Invalid direction, how'd you manage this?\n");
    printf("[Console] walker.x: %i  walker.y: %i  direction: %i\n", walker->x, walker->y, dir);
    break;
 }
 if ((walker->y > 1) && (walker->y < 40 - 2) && (walker->x > 1) && (walker->x < 80 - 2))
  map[walker->y][walker->x] = 46;
}

variable_types: dir int

variable_types:
map
char [][80]

variable_types: struct tile_s { int index; unsigned char x; unsigned char y; } *


decompiled_code:
__int64 __fastcall cave_place_player(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // al
__int64 v3; // rdx
unsigned __int8 v4; // cl
__int64 result; // rax

do
{
*a2 = TCOD_random_get_int(0LL, 0LL, 79LL);
v2 = TCOD_random_get_int(0LL, 0LL, 39LL);
v3 = *a2;
a2[1] = v2;
v4 = v2;
result = a1 + 80LL * v2;
}
while ( *(_BYTE *)(result + v3) != 46 );
a2[1] = v4 + 5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // al
__int64 v3; // rdx
unsigned __int8 v4; // cl
__int64 result; // rax

do
{
*a2 = TCOD_random_get_int(0LL, 0LL, 79LL);
v2 = TCOD_random_get_int(0LL, 0LL, 39LL);
v3 = *a2;
a2[1] = v2;
v4 = v2;
result = a1 + 80LL * v2;
}
while ( *(_BYTE *)(result + v3) != 46 );
a2[1] = v4 + 5;
return result;
}

original_code:
void cave_place_player(char map[][80], object_t *player) {
 int player_placed = 0;
 while (player_placed == 0) {
  player->x = TCOD_random_get_int(((void *)0), 0, 80 - 1);
  player->y = TCOD_random_get_int(((void *)0), 0, 40 - 1);
  if (map[player->y][player->x] == 46)
   player_placed = 1;
 }
 player->y += 5;
}

canonical_original_code:
void cave_place_player(char map[][80], struct object_s *player) {
 int player_placed = 0;
 while (player_placed == 0) {
  player->x = TCOD_random_get_int(((void *)0), 0, 80 - 1);
  player->y = TCOD_random_get_int(((void *)0), 0, 40 - 1);
  if (map[player->y][player->x] == 46)
   player_placed = 1;
 }
 player->y += 5;
}

variable_types: struct object_s { unsigned char x; unsigned char y; unsigned char radius; unsigned char torch_life; unsigned char torch_lit; unsigned char currentHP; unsigned char currentMP; unsigned char maxHP; unsigned char maxMP; float hpPct; float mpPct; unsigned char color[3]; unsigned char symbol; unsigned char dlvl; unsigned char state; unsigned int turns; struct item_s { unsigned char x; unsigned char type; unsigned char sub_type; unsigned char quantity; unsigned char effect; unsigned char throwable; unsigned char min_dmg; unsigned char max_dmg; unsigned char plus_hit; unsigned char plus_dmg; unsigned char special_dmg; unsigned char ac; unsigned char currently_equipped; unsigned char discovered; } inventory[24]; } *

return_type: void

user_defined_types: struct object_s { unsigned char x; unsigned char y; unsigned char radius; unsigned char torch_life; unsigned char torch_lit; unsigned char currentHP; unsigned char currentMP; unsigned char maxHP; unsigned char maxMP; float hpPct; float mpPct; unsigned char color[3]; unsigned char symbol; unsigned char dlvl; unsigned char state; unsigned int turns; struct item_s inventory[24]; }


original_code:
void cave_place_stairs(char map[][80], object_t player, tile_t *stairs) {
 int stairs_placed = 0;
 int largest_x = 0, largest_y = 0;
 int cur_dist, largest_dist = 0;
 int times_run = 0;
 while (stairs_placed == 0) {
  stairs->x = TCOD_random_get_int(((void *)0), 0, 80 - 1);
  stairs->y = TCOD_random_get_int(((void *)0), 0, 40 - 1);
  if (map[stairs->y][stairs->x] != 46)
   continue;
  cur_dist = distance(player.x, player.y, stairs->x, stairs->y);
  times_run++;
  if (cur_dist > largest_dist) {
   largest_x = stairs->x;
   largest_y = stairs->y;
   largest_dist = cur_dist;
  }
  if (times_run == 20) {
   stairs->x = largest_x;
   stairs->y = largest_y;
   map[largest_y][largest_x] = 62;
   stairs_placed = 1;
  }
 }
}

canonical_original_code:
void cave_place_stairs(char map[][80], struct object_s player, struct tile_s *stairs) {
 int stairs_placed = 0;
 int largest_x = 0; int largest_y = 0;
 int cur_dist; int largest_dist = 0;
 int times_run = 0;
 while (stairs_placed == 0) {
  stairs->x = TCOD_random_get_int(((void *)0), 0, 80 - 1);
  stairs->y = TCOD_random_get_int(((void *)0), 0, 40 - 1);
  if (map[stairs->y][stairs->x] != 46)
   continue;
  cur_dist = distance(player.x, player.y, stairs->x, stairs->y);
  times_run++;
  if (cur_dist > largest_dist) {
   largest_x = stairs->x;
   largest_y = stairs->y;
   largest_dist = cur_dist;
  }
  if (times_run == 20) {
   stairs->x = largest_x;
   stairs->y = largest_y;
   map[largest_y][largest_x] = 62;
   stairs_placed = 1;
  }
 }
}

variable_types: struct object_s { unsigned char x; unsigned char y; unsigned char radius; unsigned char torch_life; unsigned char torch_lit; unsigned char currentHP; unsigned char currentMP; unsigned char maxHP; unsigned char maxMP; float hpPct; float mpPct; unsigned char color[3]; unsigned char symbol; unsigned char dlvl; unsigned char state; unsigned int turns; struct item_s { unsigned char x; unsigned char type; unsigned char sub_type; unsigned char quantity; unsigned char effect; unsigned char throwable; unsigned char min_dmg; unsigned char max_dmg; unsigned char plus_hit; unsigned char plus_dmg; unsigned char special_dmg; unsigned char ac; unsigned char currently_equipped; unsigned char discovered; } inventory[24]; }

user_defined_types: struct tile_s { int index; unsigned char x; unsigned char y; }


decompiled_code:
__int64 __fastcall generate_cave(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
int v6; // eax
int v7; // ebx
int i; // er15
int v9; // eax
__int64 v10; // rdx
__int64 v11; // r8
__int64 v12; // r9
__int16 v14[196]; // [rsp-190h] [rbp-1D8h] BYREF
char v15[4]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int8 v16; // [rsp+Ch] [rbp-3Ch]
unsigned __int8 v17; // [rsp+Dh] [rbp-3Bh]

v16 = TCOD_random_get_int(0LL, 0LL, 79LL);
v17 = TCOD_random_get_int(0LL, 0LL, 39LL);
fill_map(a1, 35LL);
*(_BYTE *)(a1 + 80LL * v17 + v16) = 46;
v6 = TCOD_random_get_int(0LL, 4000LL, 6000LL);
if ( v6 > 0 )
{
v7 = v6;
for ( i = 0; i != v7; ++i )
{
v9 = TCOD_random_get_int(0LL, 1LL, 8LL);
cave_walk(v9, a1, (__int64)v15);
}
}
cave_place_player(a1, a3);
qmemcpy(v14, a3, sizeof(v14));
cave_place_stairs(a1, a4, v10, 0LL, v11, v12, v14[0]);
return random_get_colors(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
int v6; // eax
int v7; // ebx
int i; // er15
int v9; // eax
__int64 v10; // rdx
__int64 v11; // r8
__int64 v12; // r9
__int16 v14[196]; // [rsp-190h] [rbp-1D8h] BYREF
char v15[4]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int8 v16; // [rsp+Ch] [rbp-3Ch]
unsigned __int8 v17; // [rsp+Dh] [rbp-3Bh]

v16 = TCOD_random_get_int(0LL, 0LL, 79LL);
v17 = TCOD_random_get_int(0LL, 0LL, 39LL);
fill_map(a1, 35LL);
*(_BYTE *)(a1 + 80LL * v17 + v16) = 46;
v6 = TCOD_random_get_int(0LL, 4000LL, 6000LL);
if ( v6 > 0 )
{
v7 = v6;
for ( i = 0; i != v7; ++i )
{
v9 = TCOD_random_get_int(0LL, 1LL, 8LL);
func0(v9, a1, (__int64)v15);
}
}
func1(a1, a3);
qmemcpy(v14, a3, sizeof(v14));
func2(a1, a4, v10, 0LL, v11, v12, v14[0]);
return random_get_colors(a1, a2);
}

original_code:
void generate_cave(char map[][80], TCOD_color_t color_map[][80],
  object_t *player, tile_t *stairs) {
 int count = 0, limit, direction = 0;
 tile_t walker;
 walker.x = TCOD_random_get_int(((void *)0), 0, 80 - 1);
 walker.y = TCOD_random_get_int(((void *)0), 0, 40 - 1);
 fill_map(map, 35);
 map[walker.y][walker.x] = 46;
 limit = TCOD_random_get_int(((void *)0), 4000, 6000);
 while (count < limit) {
  direction = TCOD_random_get_int(((void *)0), 1, 8);
  cave_walk(direction, map, &walker);
  count++;
 }
 cave_place_player(map, player);
 cave_place_stairs(map, *player, stairs);
 random_get_colors(map, color_map);
}

canonical_original_code:
void generate_cave(char map[][80], struct TCOD_color_t color_map[][80], struct object_s *player, struct tile_s *stairs) {
 int count = 0; int limit; int direction = 0;
 struct tile_s walker;
 walker.x = TCOD_random_get_int(((void *)0), 0, 80 - 1);
 walker.y = TCOD_random_get_int(((void *)0), 0, 40 - 1);
 fill_map(map, 35);
 map[walker.y][walker.x] = 46;
 limit = TCOD_random_get_int(((void *)0), 4000, 6000);
 while (count < limit) {
  direction = TCOD_random_get_int(((void *)0), 1, 8);
  cave_walk(direction, map, &walker);
  count++;
 }
 cave_place_player(map, player);
 cave_place_stairs(map, *player, stairs);
 random_get_colors(map, color_map);
}

variable_types: struct TCOD_color_t { unsigned char r; } [][80]

variable_types: count int

variable_types: limit int

variable_types: direction int

variable_types: struct tile_s { int index; unsigned char x; unsigned char y; }

user_defined_types: struct item_s { unsigned char x; unsigned char type; unsigned char sub_type; unsigned char quantity; unsigned char effect; unsigned char throwable; unsigned char min_dmg; unsigned char max_dmg; unsigned char plus_hit; unsigned char plus_dmg; unsigned char special_dmg; unsigned char ac; unsigned char currently_equipped; unsigned char discovered; }


decompiled_code:
void __fastcall monster_change_state(__int64 a1, int a2, char a3)
{
*(_BYTE *)(392LL * a2 + a1 + 25) = a3;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, char a3)
{
*(_BYTE *)(392LL * a2 + a1 + 25) = a3;
}

original_code:
void monster_change_state(object_t *monster, int index, uint8_t new_state) {
 monster[index].state = new_state;
}

canonical_original_code:
void monster_change_state(struct object_s *monster, int index, unsigned char new_state) {
 monster[index].state = new_state;
}

variable_types: index int


decompiled_code:
void __fastcall ai_move(unsigned __int8 *a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int16 a7)
{
unsigned __int8 *v8; // rbx
__int64 v9; // rbp
unsigned __int8 v10; // al
int v11; // eax
int v12; // er15
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx

if ( a2 > 0 )
{
v8 = a1;
v9 = (__int64)&a1[392 * (a2 - 1) + 392];
while ( 1 )
{
v10 = v8[25];
if ( v10 == 3 )
break;
if ( v10 <= 3u )
{
if ( (unsigned __int8)(v10 - 1) > 1u )
goto LABEL_4;
LABEL_5:
v8 += 392;
if ( v8 == (unsigned __int8 *)v9 )
return;
}
else
{
if ( v10 != 4 )
{
LABEL_4:
puts("[Console] ERROR: Unknown monster state, dunno how you managed this!");
goto LABEL_5;
}
v8 += 392;
if ( v8 == (unsigned __int8 *)v9 )
return;
}
}
do
{
v11 = TCOD_random_get_int(0LL, 0LL, 3LL);
v12 = v11;
}
while ( last_dir_0 == v11 );
if ( v11 )
{
switch ( v11 )
{
case 1:
if ( (unsigned __int8)TCOD_map_is_walkable(a3, (unsigned int)*v8 + 1, (unsigned int)v8[1] - 5) )
{
v16 = *v8;
if ( v16 + 1 != (unsigned __int8)a7 && v8[1] != HIBYTE(a7) )
{
last_dir_0 = v12;
*v8 = v16 + 1;
goto LABEL_5;
}
}
break;
case 2:
if ( (unsigned __int8)TCOD_map_is_walkable(a3, *v8, (unsigned int)v8[1] - 4) )
{
v15 = v8[1];
if ( v15 + 1 != HIBYTE(a7) && *v8 != (_BYTE)a7 )
{
last_dir_0 = v12;
v8[1] = v15 + 1;
goto LABEL_5;
}
}
break;
case 3:
if ( (unsigned __int8)TCOD_map_is_walkable(a3, (unsigned int)*v8 - 1, (unsigned int)v8[1] - 5) )
{
v13 = *v8;
if ( v13 - 1 != (unsigned __int8)a7 && v8[1] != HIBYTE(a7) )
*v8 = v13 - 1;
}
break;
}
}
else if ( (unsigned __int8)TCOD_map_is_walkable(a3, *v8, (unsigned int)v8[1] - 6) )
{
v14 = v8[1];
if ( v14 - 1 != HIBYTE(a7) && *v8 != (_BYTE)a7 )
{
last_dir_0 = v12;
v8[1] = v14 - 1;
goto LABEL_5;
}
}
last_dir_0 = v12;
goto LABEL_5;
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int8 *a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int16 a7)
{
unsigned __int8 *v8; // rbx
__int64 v9; // rbp
unsigned __int8 v10; // al
int v11; // eax
int v12; // er15
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx

if ( a2 > 0 )
{
v8 = a1;
v9 = (__int64)&a1[392 * (a2 - 1) + 392];
while ( 1 )
{
v10 = v8[25];
if ( v10 == 3 )
break;
if ( v10 <= 3u )
{
if ( (unsigned __int8)(v10 - 1) > 1u )
goto LABEL_4;
LABEL_5:
v8 += 392;
if ( v8 == (unsigned __int8 *)v9 )
return;
}
else
{
if ( v10 != 4 )
{
LABEL_4:
puts("[Console] ERROR: Unknown monster state, dunno how you managed this!");
goto LABEL_5;
}
v8 += 392;
if ( v8 == (unsigned __int8 *)v9 )
return;
}
}
do
{
v11 = TCOD_random_get_int(0LL, 0LL, 3LL);
v12 = v11;
}
while ( last_dir_0 == v11 );
if ( v11 )
{
switch ( v11 )
{
case 1:
if ( (unsigned __int8)TCOD_map_is_walkable(a3, (unsigned int)*v8 + 1, (unsigned int)v8[1] - 5) )
{
v16 = *v8;
if ( v16 + 1 != (unsigned __int8)a7 && v8[1] != HIBYTE(a7) )
{
last_dir_0 = v12;
*v8 = v16 + 1;
goto LABEL_5;
}
}
break;
case 2:
if ( (unsigned __int8)TCOD_map_is_walkable(a3, *v8, (unsigned int)v8[1] - 4) )
{
v15 = v8[1];
if ( v15 + 1 != HIBYTE(a7) && *v8 != (_BYTE)a7 )
{
last_dir_0 = v12;
v8[1] = v15 + 1;
goto LABEL_5;
}
}
break;
case 3:
if ( (unsigned __int8)TCOD_map_is_walkable(a3, (unsigned int)*v8 - 1, (unsigned int)v8[1] - 5) )
{
v13 = *v8;
if ( v13 - 1 != (unsigned __int8)a7 && v8[1] != HIBYTE(a7) )
*v8 = v13 - 1;
}
break;
}
}
else if ( (unsigned __int8)TCOD_map_is_walkable(a3, *v8, (unsigned int)v8[1] - 6) )
{
v14 = v8[1];
if ( v14 - 1 != HIBYTE(a7) && *v8 != (_BYTE)a7 )
{
last_dir_0 = v12;
v8[1] = v14 - 1;
goto LABEL_5;
}
}
last_dir_0 = v12;
goto LABEL_5;
}
}

original_code:
void ai_move(object_t *monster, int mon_num, TCOD_map_t fov_map, object_t player) {
 int i;
 int rand_dir = 0;
 static int last_dir;
 for (i = 0; i < mon_num; i++) {
  switch(monster[i].state) {
   case 1:
    break;
   case 3:
    do {
    rand_dir = TCOD_random_get_int(((void *)0), 0, 3);
    } while (rand_dir == last_dir);
    if (rand_dir == 0 && TCOD_map_is_walkable(fov_map, monster[i].x, monster[i].y - 6)) {
     if (monster[i].y - 1 != player.y && monster[i].x != player.x)
      monster[i].y -= 1;
    }
    if (rand_dir == 1 && TCOD_map_is_walkable(fov_map, monster[i].x + 1, monster[i].y - 5)) {
     if (monster[i].x + 1 != player.x && monster[i].y != player.y)
      monster[i].x += 1;
    }
    if (rand_dir == 2 && TCOD_map_is_walkable(fov_map, monster[i].x, monster[i].y - 4)) {
     if (monster[i].y + 1 != player.y && monster[i].x != player.x)
      monster[i].y += 1;
    }
    if (rand_dir == 3 && TCOD_map_is_walkable(fov_map, monster[i].x - 1, monster[i].y - 5)) {
     if (monster[i].x - 1 != player.x && monster[i].y != player.y)
      monster[i].x -= 1;
    }
    last_dir = rand_dir;
    break;
   case 2:
    break;
   case 4:
    break;
   default:
    printf("[Console] ERROR: Unknown monster state, dunno how you managed this!\n");
    break;
  }
 }
}

canonical_original_code:
void ai_move(struct object_s *monster, int mon_num, void *fov_map, struct object_s player) {
 int i;
 int rand_dir = 0;
 static int last_dir;
 for (i = 0; i < mon_num; i++) {
  switch(monster[i].state) {
   case 1:
    break;
   case 3:
    do {
    rand_dir = TCOD_random_get_int(((void *)0), 0, 3);
    } while (rand_dir == last_dir);
    if (rand_dir == 0 && TCOD_map_is_walkable(fov_map, monster[i].x, monster[i].y - 6)) {
     if (monster[i].y - 1 != player.y && monster[i].x != player.x)
      monster[i].y -= 1;
    }
    if (rand_dir == 1 && TCOD_map_is_walkable(fov_map, monster[i].x + 1, monster[i].y - 5)) {
     if (monster[i].x + 1 != player.x && monster[i].y != player.y)
      monster[i].x += 1;
    }
    if (rand_dir == 2 && TCOD_map_is_walkable(fov_map, monster[i].x, monster[i].y - 4)) {
     if (monster[i].y + 1 != player.y && monster[i].x != player.x)
      monster[i].y += 1;
    }
    if (rand_dir == 3 && TCOD_map_is_walkable(fov_map, monster[i].x - 1, monster[i].y - 5)) {
     if (monster[i].x - 1 != player.x && monster[i].y != player.y)
      monster[i].x -= 1;
    }
    last_dir = rand_dir;
    break;
   case 2:
    break;
   case 4:
    break;
   default:
    printf("[Console] ERROR: Unknown monster state, dunno how you managed this!\n");
    break;
  }
 }
}

variable_types:
player
struct object_s

variable_types: i int


distance

decompiled_code:
__int64 __fastcall distance(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
__int64 result; // rax

v4 = (double)(a4 - a2) * (double)(a4 - a2) + (double)(a3 - a1) * (double)(a3 - a1);
if ( v4 < 0.0 )
result = (unsigned int)(int)sqrt(v4);
else
result = (unsigned int)(int)sqrt(v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, int a4)
{
double v4; // xmm0_8
__int64 result; // rax

v4 = (double)(a4 - a2) * (double)(a4 - a2) + (double)(a3 - a1) * (double)(a3 - a1);
if ( v4 < 0.0 )
result = (unsigned int)(int)sqrt(v4);
else
result = (unsigned int)(int)sqrt(v4);
return result;
}

original_code:
int distance(int x1, int y1, int x2, int y2) {
 return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

return_type: int


createMonster

original_code:
void createMonster(object_t *monster, int mon_num, TCOD_map_t map) {
 int i;
 for (i = 0; i < mon_num; i++) {
  do {
   monster[i].x = TCOD_random_get_int(((void *)0), 0, 79);
   monster[i].y = TCOD_random_get_int(((void *)0), 0, 39);
  } while (TCOD_map_is_walkable(map, monster[i].x, monster[i].y) == ((bool)0));
  if (TCOD_map_is_walkable(map, monster[i].x, monster[i].y) == ((bool)0)) {
   printf("[Console] Monster spawned out of bounds.\n");
  }
  monster[i].y += 5;
  monster[i].maxHP = 30;
  monster[i].currentHP = 30;
  monster[i].color[0] = 200;
  monster[i].color[1] = 20;
  monster[i].color[2] = 20;
  monster[i].state = 3;
  monster[i].symbol = 107;
 }
}

canonical_original_code:
void createMonster(struct object_s *monster, int mon_num, void *map) {
 int i;
 for (i = 0; i < mon_num; i++) {
  do {
   monster[i].x = TCOD_random_get_int(((void *)0), 0, 79);
   monster[i].y = TCOD_random_get_int(((void *)0), 0, 39);
  } while (TCOD_map_is_walkable(map, monster[i].x, monster[i].y) == ((unsigned char)0));
  if (TCOD_map_is_walkable(map, monster[i].x, monster[i].y) == ((unsigned char)0)) {
   printf("[Console] Monster spawned out of bounds.\n");
  }
  monster[i].y += 5;
  monster[i].maxHP = 30;
  monster[i].currentHP = 30;
  monster[i].color[0] = 200;
  monster[i].color[1] = 20;
  monster[i].color[2] = 20;
  monster[i].state = 3;
  monster[i].symbol = 107;
 }
}

variable_types:
map
void *


decompiled_code:
__int64 __fastcall random_get_colors(_BYTE *a1, __int64 a2)
{
_BYTE *v3; // rbx
_BYTE *v4; // r13
_BYTE *v5; // r14
__int64 result; // rax

v3 = (_BYTE *)(a2 + 9600);
do
{
v4 = v3 - 9600;
v5 = a1;
while ( 1 )
{
LABEL_3:
while ( 1 )
{
result = (unsigned __int8)*v5;
if ( (char)result <= 62 )
break;
switch ( (_BYTE)result )
{
case '`':
*v5 = 46;
v4 += 240;
v5 += 80;
result = TCOD_random_get_int(0LL, 130LL, 200LL);
*(v4 - 239) = 20;
*(v4 - 240) = result;
*(v4 - 238) = 20;
if ( v4 == v3 )
goto LABEL_10;
break;
case '~':
*v4 = 0;
v4[1] = 60;
result = TCOD_random_get_int(0LL, 150LL, 250LL);
v4[2] = result;
goto LABEL_9;
case '^':
*v4 = 40;
v5 += 80;
v4 += 240;
result = TCOD_random_get_int(0LL, 180LL, 230LL);
*(v4 - 238) = 40;
*(v4 - 239) = result;
if ( v4 == v3 )
goto LABEL_10;
break;
default:
goto LABEL_9;
}
}
if ( (char)result > 34 )
break;
LABEL_9:
v4 += 240;
v5 += 80;
if ( v4 == v3 )
goto LABEL_10;
}
result = (unsigned __int8)(result - 35);
switch ( (char)result )
{
case 0:
v5 += 80;
*v4 = TCOD_random_get_int(0LL, 59LL, 85LL);
v4 += 240;
*(v4 - 239) = TCOD_random_get_int(0LL, 68LL, 94LL);
result = TCOD_random_get_int(0LL, 75LL, 101LL);
*(v4 - 238) = result;
if ( v4 != v3 )
goto LABEL_3;
break;
case 4:
v5 += 80;
*v4 = TCOD_random_get_int(0LL, 180LL, 200LL);
v4 += 240;
result = TCOD_random_get_int(0LL, 32LL, 128LL);
*(v4 - 238) = 16;
*(v4 - 239) = result;
if ( v4 != v3 )
goto LABEL_3;
break;
case 9:
*v4 = 0;
v5 += 80;
v4 += 240;
result = TCOD_random_get_int(0LL, 100LL, 170LL);
*(_WORD *)(v4 - 239) = (unsigned __int8)result;
if ( v4 != v3 )
goto LABEL_3;
break;
case 11:
case 27:
*v4 = -1;
v4 += 240;
v5 += 80;
*(v4 - 239) = -1;
*(v4 - 238) = -1;
if ( v4 != v3 )
goto LABEL_3;
break;
default:
goto LABEL_9;
}
LABEL_10:
v3 = v4 + 3;
++a1;
}
while ( v4 + 3 != (_BYTE *)(a2 + 9840) );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2)
{
_BYTE *v3; // rbx
_BYTE *v4; // r13
_BYTE *v5; // r14
__int64 result; // rax

v3 = (_BYTE *)(a2 + 9600);
do
{
v4 = v3 - 9600;
v5 = a1;
while ( 1 )
{
LABEL_3:
while ( 1 )
{
result = (unsigned __int8)*v5;
if ( (char)result <= 62 )
break;
switch ( (_BYTE)result )
{
case '`':
*v5 = 46;
v4 += 240;
v5 += 80;
result = TCOD_random_get_int(0LL, 130LL, 200LL);
*(v4 - 239) = 20;
*(v4 - 240) = result;
*(v4 - 238) = 20;
if ( v4 == v3 )
goto LABEL_10;
break;
case '~':
*v4 = 0;
v4[1] = 60;
result = TCOD_random_get_int(0LL, 150LL, 250LL);
v4[2] = result;
goto LABEL_9;
case '^':
*v4 = 40;
v5 += 80;
v4 += 240;
result = TCOD_random_get_int(0LL, 180LL, 230LL);
*(v4 - 238) = 40;
*(v4 - 239) = result;
if ( v4 == v3 )
goto LABEL_10;
break;
default:
goto LABEL_9;
}
}
if ( (char)result > 34 )
break;
LABEL_9:
v4 += 240;
v5 += 80;
if ( v4 == v3 )
goto LABEL_10;
}
result = (unsigned __int8)(result - 35);
switch ( (char)result )
{
case 0:
v5 += 80;
*v4 = TCOD_random_get_int(0LL, 59LL, 85LL);
v4 += 240;
*(v4 - 239) = TCOD_random_get_int(0LL, 68LL, 94LL);
result = TCOD_random_get_int(0LL, 75LL, 101LL);
*(v4 - 238) = result;
if ( v4 != v3 )
goto LABEL_3;
break;
case 4:
v5 += 80;
*v4 = TCOD_random_get_int(0LL, 180LL, 200LL);
v4 += 240;
result = TCOD_random_get_int(0LL, 32LL, 128LL);
*(v4 - 238) = 16;
*(v4 - 239) = result;
if ( v4 != v3 )
goto LABEL_3;
break;
case 9:
*v4 = 0;
v5 += 80;
v4 += 240;
result = TCOD_random_get_int(0LL, 100LL, 170LL);
*(_WORD *)(v4 - 239) = (unsigned __int8)result;
if ( v4 != v3 )
goto LABEL_3;
break;
case 11:
case 27:
*v4 = -1;
v4 += 240;
v5 += 80;
*(v4 - 239) = -1;
*(v4 - 238) = -1;
if ( v4 != v3 )
goto LABEL_3;
break;
default:
goto LABEL_9;
}
LABEL_10:
v3 = v4 + 3;
++a1;
}
while ( v4 + 3 != (_BYTE *)(a2 + 9840) );
return result;
}

original_code:
void random_get_colors(char map[][80], TCOD_color_t map_colors[][80]) {
 int x, y;
 for (x = 0; x < 80; x++) {
  for (y = 0; y < 40; y++) {
    switch((int)map[y][x]) {
    case 35:
     map_colors[y][x].r = TCOD_random_get_int(((void *)0), 59, 85);
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 68, 94);
     map_colors[y][x].b = TCOD_random_get_int(((void *)0), 75, 101);
     break;
    case 39:
     map_colors[y][x].r = TCOD_random_get_int(((void *)0), 180, 200);
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 32, 128);
     map_colors[y][x].b = 16;
     break;
    case 46:
    case 62:
     map_colors[y][x].r = 255;
     map_colors[y][x].g = 255;
     map_colors[y][x].b = 255;
     break;
    case 94:
     map_colors[y][x].r = 40;
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 180, 230);
     map_colors[y][x].b = 40;
     break;
    case 96:
     map[y][x] = 46;
     map_colors[y][x].r = TCOD_random_get_int(((void *)0), 130, 200);
     map_colors[y][x].g = 20;
     map_colors[y][x].b = 20;
     break;
    case 44:
     map_colors[y][x].r = 0;
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 100, 170);
     map_colors[y][x].b = 0;
     break;
    case 126:
     map_colors[y][x].r = 0;
     map_colors[y][x].g = 60;
     map_colors[y][x].b = TCOD_random_get_int(((void *)0), 150, 250);
     break;
   }
  }
 }
}

canonical_original_code:
void random_get_colors(char map[][80], struct TCOD_color_t map_colors[][80]) {
 int x; int y;
 for (x = 0; x < 80; x++) {
  for (y = 0; y < 40; y++) {
    switch((int)map[y][x]) {
    case 35:
     map_colors[y][x].r = TCOD_random_get_int(((void *)0), 59, 85);
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 68, 94);
     map_colors[y][x].b = TCOD_random_get_int(((void *)0), 75, 101);
     break;
    case 39:
     map_colors[y][x].r = TCOD_random_get_int(((void *)0), 180, 200);
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 32, 128);
     map_colors[y][x].b = 16;
     break;
    case 46:
    case 62:
     map_colors[y][x].r = 255;
     map_colors[y][x].g = 255;
     map_colors[y][x].b = 255;
     break;
    case 94:
     map_colors[y][x].r = 40;
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 180, 230);
     map_colors[y][x].b = 40;
     break;
    case 96:
     map[y][x] = 46;
     map_colors[y][x].r = TCOD_random_get_int(((void *)0), 130, 200);
     map_colors[y][x].g = 20;
     map_colors[y][x].b = 20;
     break;
    case 44:
     map_colors[y][x].r = 0;
     map_colors[y][x].g = TCOD_random_get_int(((void *)0), 100, 170);
     map_colors[y][x].b = 0;
     break;
    case 126:
     map_colors[y][x].r = 0;
     map_colors[y][x].g = 60;
     map_colors[y][x].b = TCOD_random_get_int(((void *)0), 150, 250);
     break;
   }
  }
 }
}

variable_types: x int

variable_types: y int

user_defined_types: struct TCOD_color_t { unsigned char r; }


decompiled_code:
__int64 __fastcall create_tcod_map(__int64 a1, __int64 a2)
{
unsigned int v4; // ebp
__int64 v5; // r14
__int64 i; // rbx
char v7; // al

v4 = 0;
v5 = TCOD_map_new(80LL, 40LL);
do
{
for ( i = 0LL; i != 80; ++i )
{
while ( 1 )
{
*(_BYTE *)(a2 + i) = 0;
v7 = *(_BYTE *)(a1 + i);
if ( v7 == 94 )
{
TCOD_map_set_properties(v5, (unsigned int)i, v4, 0LL, 1LL);
goto LABEL_4;
}
if ( v7 <= 94 && ((v7 & 0xF7) == 35 || v7 == 32) )
break;
TCOD_map_set_properties(v5, (unsigned int)i, v4, 1LL, 1LL);
LABEL_4:
if ( ++i == 80 )
goto LABEL_10;
}
TCOD_map_set_properties(v5, (unsigned int)i, v4, 0LL, 0LL);
}
LABEL_10:
++v4;
a2 += 80LL;
a1 += 80LL;
}
while ( v4 != 40 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v4; // ebp
__int64 v5; // r14
__int64 i; // rbx
char v7; // al

v4 = 0;
v5 = TCOD_map_new(80LL, 40LL);
do
{
for ( i = 0LL; i != 80; ++i )
{
while ( 1 )
{
*(_BYTE *)(a2 + i) = 0;
v7 = *(_BYTE *)(a1 + i);
if ( v7 == 94 )
{
TCOD_map_set_properties(v5, (unsigned int)i, v4, 0LL, 1LL);
goto LABEL_4;
}
if ( v7 <= 94 && ((v7 & 0xF7) == 35 || v7 == 32) )
break;
TCOD_map_set_properties(v5, (unsigned int)i, v4, 1LL, 1LL);
LABEL_4:
if ( ++i == 80 )
goto LABEL_10;
}
TCOD_map_set_properties(v5, (unsigned int)i, v4, 0LL, 0LL);
}
LABEL_10:
++v4;
a2 += 80LL;
a1 += 80LL;
}
while ( v4 != 40 );
return v5;
}

original_code:
TCOD_map_t create_tcod_map(char map[40][80], uint8_t discovered[][80]) {
 TCOD_map_t tc_map = TCOD_map_new(80, 40);
 int x, y;
 for (y = 0; y < 40; y++) {
  for (x = 0; x < 80; x++) {
   discovered[y][x] = 0;
   switch((int)map[y][x]) {
    case 32:
    case 43:
    case 35:
     TCOD_map_set_properties(tc_map, x, y, ((bool)0), ((bool)0));
     break;
    case 94:
     TCOD_map_set_properties(tc_map, x, y, ((bool)0), ((bool)1));
     break;
    default:
     TCOD_map_set_properties(tc_map, x, y, ((bool)1), ((bool)1));
     break;
   }
  }
 }
 return tc_map;
}

canonical_original_code:
void *create_tcod_map(char map[40][80], unsigned char discovered[][80]) {
 void *tc_map = TCOD_map_new(80, 40);
 int x; int y;
 for (y = 0; y < 40; y++) {
  for (x = 0; x < 80; x++) {
   discovered[y][x] = 0;
   switch((int)map[y][x]) {
    case 32:
    case 43:
    case 35:
     TCOD_map_set_properties(tc_map, x, y, ((unsigned char)0), ((unsigned char)0));
     break;
    case 94:
     TCOD_map_set_properties(tc_map, x, y, ((unsigned char)0), ((unsigned char)1));
     break;
    default:
     TCOD_map_set_properties(tc_map, x, y, ((unsigned char)1), ((unsigned char)1));
     break;
   }
  }
 }
 return tc_map;
}

variable_types:
discovered
unsigned char [][80]

return_type: void *


original_code:
void use_door(int direction, object_t player, tile_t *door, TCOD_map_t *fov_map,
  char map[40][80], int door_count, int open) {
 int i;
 if (direction == 0) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x && door[i].y == player.y - 1 - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 6, ((bool)1), ((bool)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 6, ((bool)0), ((bool)0));
    }
   }
  }
 }
 else if (direction == 2) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x && door[i].y == player.y + 1 - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 4, ((bool)1), ((bool)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 4, ((bool)0), ((bool)0));
    }
   }
  }
 }
 else if (direction == 1) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x + 1 && door[i].y == player.y - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x + 1, player.y - 5, ((bool)1), ((bool)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x + 1, player.y - 5, ((bool)0), ((bool)0));
    }
   }
  }
 }
 else if (direction == 3) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x - 1 && door[i].y == player.y - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x - 1, player.y - 5, ((bool)1), ((bool)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x - 1, player.y - 5, ((bool)0), ((bool)0));
    }
   }
  }
 }
}

canonical_original_code:
void use_door(int direction, struct object_s player, struct tile_s *door, void **fov_map, char map[40][80], int door_count, int open) {
 int i;
 if (direction == 0) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x && door[i].y == player.y - 1 - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 6, ((unsigned char)1), ((unsigned char)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 6, ((unsigned char)0), ((unsigned char)0));
    }
   }
  }
 }
 else if (direction == 2) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x && door[i].y == player.y + 1 - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 4, ((unsigned char)1), ((unsigned char)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x, player.y - 4, ((unsigned char)0), ((unsigned char)0));
    }
   }
  }
 }
 else if (direction == 1) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x + 1 && door[i].y == player.y - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x + 1, player.y - 5, ((unsigned char)1), ((unsigned char)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x + 1, player.y - 5, ((unsigned char)0), ((unsigned char)0));
    }
   }
  }
 }
 else if (direction == 3) {
  for (i = 0; i < door_count; i++) {
   if (door[i].x == player.x - 1 && door[i].y == player.y - 5) {
    if (open == 1) {
     map[door[i].y][door[i].x] = 45;
     TCOD_map_set_properties(*fov_map, player.x - 1, player.y - 5, ((unsigned char)1), ((unsigned char)1));
    }
    else if (open == 0) {
     map[door[i].y][door[i].x] = 43;
     TCOD_map_set_properties(*fov_map, player.x - 1, player.y - 5, ((unsigned char)0), ((unsigned char)0));
    }
   }
  }
 }
}

variable_types: open int


repo: StephenNi/expression-compiler

original_code:
void test_static(void) {
  node_t t;
  node_t q;
  node_t r;
  t.kind = INTEGER;
  t.value = 42;
  node_dump(&t);
  q.kind = INTEGER;
  q.value = 10;
  node_dump(&q);
  r.kind = PLUS;
  r.left = &t;
  r.right = &q;
  node_dump(&r);
}

canonical_original_code:
void test_static() {
  struct node t;
  struct node q;
  struct node r;
  t.kind = INTEGER;
  t.value = 42;
  node_dump(&t);
  q.kind = INTEGER;
  q.value = 10;
  node_dump(&q);
  r.kind = PLUS;
  r.left = &t;
  r.right = &q;
  node_dump(&r);
}

variable_types: struct node { enum token_kind_t { _FIRST=-1, PLUS=0, MINUS=1, TIMES=2, SLASH=3, OPEN=4, CLOSE=5, INTEGER=6, _LAST=7 } kind; int value; struct node *left; struct node *right; }

user_defined_types: struct node { enum token_kind_t kind; int value; struct node *left; struct node *right; }


decompiled_code:
__int64 test_dynamic()
{
_QWORD *v0; // rbp
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rax

v0 = (_QWORD *)node_new(0LL);
v1 = node_new(6LL);
*(_DWORD *)(v1 + 4) = 42;
v2 = v1;
v3 = node_new(6LL);
*(_DWORD *)(v3 + 4) = 10;
v0[1] = v2;
v0[2] = v3;
node_dump(v0);
return node_delete(v0);
}

original_code:
void test_dynamic(void) {
  node_t *p, *l, *r;
  p = node_new(PLUS);
  l = node_new(INTEGER);
  l->value = 42;
  r = node_new(INTEGER);
  r->value = 10;
  p->left = l;
  p->right = r;
  node_dump(p);
  node_delete(p);
}

canonical_original_code:
void test_dynamic() {
  struct node *p; struct node *l; struct node *r;
  p = node_new(PLUS);
  l = node_new(INTEGER);
  l->value = 42;
  r = node_new(INTEGER);
  r->value = 10;
  p->left = l;
  p->right = r;
  node_dump(p);
  node_delete(p);
}

variable_types: struct node { enum token_kind_t { _FIRST=-1, PLUS=0, MINUS=1, TIMES=2, SLASH=3, OPEN=4, CLOSE=5, INTEGER=6, _LAST=7 } kind; int value; struct node *left; struct node *right; } *


decompiled_code:
int __fastcall real_dump(int *a1, int a2)
{
int *v2; // r12
__int64 v4; // rax
int v5; // ebx

if ( !a1 )
LABEL_9:
__assert_fail("t != NULL && (_FIRST < t->kind && t->kind < _LAST)", "nodes.c", 0x15u, "real_dump");
v2 = a1;
while ( 1 )
{
v4 = *v2;
if ( (unsigned int)v4 > 6 )
goto LABEL_9;
v5 = 0;
if ( a2 > 0 )
{
do
{
++v5;
printf(" ");
}
while ( v5 != a2 );
v4 = *v2;
}
if ( (_DWORD)v4 == 6 )
return printf("integer<%d>\n", (unsigned int)v2[1]);
++a2;
printf("operator<%c>\n", (unsigned int)mapping[v4]);
real_dump(*((_QWORD *)v2 + 1), (unsigned int)a2);
v2 = (int *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_9;
}
}

canonical_decompiled_code:
int __fastcall func9(int *a1, int a2)
{
int *v2; // r12
__int64 v4; // rax
int v5; // ebx

if ( !a1 )
LABEL_9:
__assert_fail("t != NULL && (_FIRST < t->kind && t->kind < _LAST)", "nodes.c", 0x15u, "real_dump");
v2 = a1;
while ( 1 )
{
v4 = *v2;
if ( (unsigned int)v4 > 6 )
goto LABEL_9;
v5 = 0;
if ( a2 > 0 )
{
do
{
++v5;
printf(" ");
}
while ( v5 != a2 );
v4 = *v2;
}
if ( (_DWORD)v4 == 6 )
return printf("integer<%d>\n", (unsigned int)v2[1]);
++a2;
printf("operator<%c>\n", (unsigned int)mapping[v4]);
func9(*((_QWORD *)v2 + 1), (unsigned int)a2);
v2 = (int *)*((_QWORD *)v2 + 2);
if ( !v2 )
goto LABEL_9;
}
}

original_code:
static void real_dump(const node_t *t, int level) {
  int i;
  ((t != ((void *)0) && (_FIRST < t->kind && t->kind < _LAST)) ? (void) (0) : __assert_fail ("t != NULL && (_FIRST < t->kind && t->kind < _LAST)", "nodes.c", 21, __extension__ __PRETTY_FUNCTION__));
  for (i = 0; i < level; i++) {
    printf("  ");
  }
  if (t->kind == INTEGER) {
    printf("integer<%d>\n", t->value);
  }
  else {
    printf("operator<%c>\n", mapping[t->kind]);
    real_dump(t->left, level+1);
    real_dump(t->right, level+1);
  }
}

canonical_original_code:
static void real_dump(struct node *t, int level) {
  int i;
  ((t != ((void *)0) && (_FIRST < t->kind && t->kind < _LAST)) ? (void) (0) : __assert_fail ("t != NULL && (_FIRST < t->kind && t->kind < _LAST)", "nodes.c", 21, __extension__ __PRETTY_FUNCTION__));
  for (i = 0; i < level; i++) {
    printf("  ");
  }
  if (t->kind == INTEGER) {
    printf("integer<%d>\n", t->value);
  }
  else {
    printf("operator<%c>\n", mapping[t->kind]);
    real_dump(t->left, level+1);
    real_dump(t->right, level+1);
  }
}

variable_types: level int

user_defined_types: enum token_kind_t { _FIRST=-1, PLUS=0, MINUS=1, TIMES=2, SLASH=3, OPEN=4, CLOSE=5, INTEGER=6, _LAST=7 }


decompiled_code:
int __fastcall node_dump(int *a1)
{
return real_dump(a1, 0);
}

canonical_decompiled_code:
int __fastcall func10(int *a1)
{
return func9(a1, 0);
}

original_code:
void node_dump(const node_t *t) {
  real_dump(t, 0);
}

canonical_original_code:
void node_dump(struct node *t) {
  real_dump(t, 0);
}


decompiled_code:
void __fastcall node_delete(void *ptr)
{
if ( ptr )
{
node_delete(*((void **)ptr + 1));
*((_QWORD *)ptr + 1) = 0LL;
node_delete(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
func11(*((void **)ptr + 1));
*((_QWORD *)ptr + 1) = 0LL;
func11(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void node_delete(node_t *node) {
  if (node != ((void *)0)) {
    node_delete(node->left);
    node->left = ((void *)0);
    node_delete(node->right);
    node->left = ((void *)0);
    free(node);
  }
}

canonical_original_code:
void node_delete(struct node *node) {
  if (node != ((void *)0)) {
    node_delete(node->left);
    node->left = ((void *)0);
    node_delete(node->right);
    node->left = ((void *)0);
    free(node);
  }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_static(argc, argv, envp);
test_dynamic();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
func8();
return 0;
}

original_code:
int main(void) {
  test_static();
  test_dynamic();
  return 0;
}

canonical_original_code:
int main() {
  test_static();
  test_dynamic();
  return 0;
}


operator

decompiled_code:
bool __fastcall operator(unsigned int a1)
{
return a1 <= 3;
}

canonical_decompiled_code:
bool __fastcall func0(unsigned int a1)
{
return a1 <= 3;
}

original_code:
static _Bool operator(node_kind_t kind) {
  return (PLUS <= kind && kind <= SLASH);
}

canonical_original_code:
static _Bool operator(enum token_kind_t kind) {
  return (PLUS <= kind && kind <= SLASH);
}

variable_types: enum token_kind_t { _FIRST=-1, PLUS=0, MINUS=1, TIMES=2, SLASH=3, OPEN=4, CLOSE=5, INTEGER=6, _LAST=7 }


instruction

decompiled_code:
__int64 __fastcall instruction(__int64 a1, __int64 a2)
{
string_append_char(a1, 9LL);
string_append_chars(a1, a2);
return string_append_char(a1, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
string_append_char(a1, 9LL);
string_append_chars(a1, a2);
return string_append_char(a1, 10LL);
}

original_code:
static void instruction(string_t *buffer, const char *inst) {
  string_append_char(buffer, '\t');
  string_append_chars(buffer, inst);
  string_append_char(buffer, '\n');
}

canonical_original_code:
static void instruction(struct vector_t *buffer, char *inst) {
  string_append_char(buffer, '\t');
  string_append_chars(buffer, inst);
  string_append_char(buffer, '\n');
}

variable_types: struct vector_t { unsigned long element; unsigned long length; unsigned long capacity; char *data; } *

variable_types:
inst
char *


label

decompiled_code:
__int64 __fastcall label(__int64 a1, __int64 a2)
{
string_append_chars(a1, a2);
return string_append_chars(a1, &unk_3D1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
string_append_chars(a1, a2);
return string_append_chars(a1, &unk_3D1);
}

original_code:
static void label(string_t *buffer, const char *lab) {
  string_append_chars(buffer, lab);
  string_append_chars(buffer, ":\n");
}

canonical_original_code:
static void label(struct vector_t *buffer, char *lab) {
  string_append_chars(buffer, lab);
  string_append_chars(buffer, ":\n");
}

variable_types:
lab
char *

user_defined_types: struct vector_t { unsigned long element; unsigned long length; unsigned long capacity; char *data; }


prologue

decompiled_code:
__int64 __fastcall prologue(__int64 a1)
{
instruction(a1, (__int64)".data");
label(a1, (__int64)"newline");
instruction(a1, (__int64)".asciiz \"\\n\"");
instruction(a1, (__int64)".text");
return label(a1, (__int64)"main");
}

original_code:
static void prologue(string_t *buffer) {
  instruction(buffer, ".data");
  label(buffer, "newline");
  instruction(buffer, ".asciiz \"\\n\"");
  instruction(buffer, ".text");
  label(buffer, "main");
}

canonical_original_code:
static void prologue(struct vector_t *buffer) {
  instruction(buffer, ".data");
  label(buffer, "newline");
  instruction(buffer, ".asciiz \"\\n\"");
  instruction(buffer, ".text");
  label(buffer, "main");
}


pop

decompiled_code:
__int64 __fastcall pop(__int64 a1, const char *a2)
{
__int128 v3[3]; // [rsp+0h] [rbp-38h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
if ( strlen(a2) != 3 )
_assert_fail("strlen(reg) == 3", "spim.c", 0x2Eu, "pop");
snprintf((char *)v3, 0x20uLL, "lw %s, ($sp)", a2);
instruction(a1, (__int64)v3);
return instruction(a1, (__int64)"addi $sp, $sp, 4");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int128 v3[3]; // [rsp+0h] [rbp-38h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
if ( strlen(a2) != 3 )
_assert_fail("strlen(reg) == 3", "spim.c", 0x2Eu, "pop");
snprintf((char *)v3, 0x20uLL, "lw %s, ($sp)", a2);
func1(a1, (__int64)v3);
return func1(a1, (__int64)"addi $sp, $sp, 4");
}

original_code:
static void pop(string_t *buffer, const char *reg) {
  int res;
  char inst[32] = "";
  ((strlen(reg) == 3) ? (void) (0) : __assert_fail ("strlen(reg) == 3", "spim.c", 46, __extension__ __PRETTY_FUNCTION__));
  res = snprintf(inst, 32, "lw %s, ($sp)", reg);
  ((res < 32) ? (void) (0) : __assert_fail ("res < LEN", "spim.c", 48, __extension__ __PRETTY_FUNCTION__));
  instruction(buffer, inst);
  instruction(buffer, "addi $sp, $sp, 4");
}

canonical_original_code:
static void pop(struct vector_t *buffer, char *reg) {
  int res;
  char inst[32] = "";
  ((strlen(reg) == 3) ? (void) (0) : __assert_fail ("strlen(reg) == 3", "spim.c", 46, __extension__ __PRETTY_FUNCTION__));
  res = snprintf(inst, 32, "lw %s, ($sp)", reg);
  ((res < 32) ? (void) (0) : __assert_fail ("res < LEN", "spim.c", 48, __extension__ __PRETTY_FUNCTION__));
  instruction(buffer, inst);
  instruction(buffer, "addi $sp, $sp, 4");
}

variable_types:
reg
char *

variable_types: res int

variable_types:
inst
char [32]


epilogue

decompiled_code:
__int64 __fastcall epilogue(__int64 a1)
{
label(a1, (__int64)"print");
pop(a1, "$a0");
instruction(a1, (__int64)"li $v0, 1");
instruction(a1, (__int64)"syscall");
instruction(a1, (__int64)"la $a0, newline");
instruction(a1, (__int64)"li $v0, 4");
instruction(a1, (__int64)"syscall");
label(a1, (__int64)"exit");
instruction(a1, (__int64)"li $v0, 10");
instruction(a1, (__int64)"syscall");
return instruction(a1, (__int64)".end");
}

original_code:
static void epilogue(string_t *buffer) {
  label(buffer, "print");
  pop(buffer, "$a0");
  instruction(buffer, "li $v0, 1");
  instruction(buffer, "syscall");
  instruction(buffer, "la $a0, newline");
  instruction(buffer, "li $v0, 4");
  instruction(buffer, "syscall");
  label(buffer, "exit");
  instruction(buffer, "li $v0, 10");
  instruction(buffer, "syscall");
  instruction(buffer, ".end");
}

canonical_original_code:
static void epilogue(struct vector_t *buffer) {
  label(buffer, "print");
  pop(buffer, "$a0");
  instruction(buffer, "li $v0, 1");
  instruction(buffer, "syscall");
  instruction(buffer, "la $a0, newline");
  instruction(buffer, "li $v0, 4");
  instruction(buffer, "syscall");
  label(buffer, "exit");
  instruction(buffer, "li $v0, 10");
  instruction(buffer, "syscall");
  instruction(buffer, ".end");
}


operation

decompiled_code:
__int64 __fastcall operation(__int64 a1, unsigned int a2)
{
__int128 v3[3]; // [rsp+0h] [rbp-38h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
if ( !operator(a2) )
_assert_fail("operator(kind)", "spim.c", 0x47u, "operation");
pop(a1, "$s1");
pop(a1, "$s0");
if ( snprintf((char *)v3, 0x20uLL, "%s $s0, $s0, $s1", mapping[a2]) > 31 )
_assert_fail("res < LEN", "spim.c", 0x4Bu, "operation");
instruction(a1, (__int64)v3);
return push_constprop_0(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int128 v3[3]; // [rsp+0h] [rbp-38h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
if ( !func0(a2) )
_assert_fail("operator(kind)", "spim.c", 0x47u, "operation");
func4(a1, "$s1");
func4(a1, "$s0");
if ( snprintf((char *)v3, 0x20uLL, "%s $s0, $s0, $s1", mapping[a2]) > 31 )
_assert_fail("res < LEN", "spim.c", 0x4Bu, "operation");
func1(a1, (__int64)v3);
return func6(a1);
}

original_code:
static void operation(string_t *buffer, node_kind_t kind) {
  int res;
  char inst[32] = "";
  ((operator(kind)) ? (void) (0) : __assert_fail ("operator(kind)", "spim.c", 71, __extension__ __PRETTY_FUNCTION__));
  pop(buffer, "$s1");
  pop(buffer, "$s0");
  res = snprintf(inst, 32, "%s $s0, $s0, $s1", mapping[kind]);
  ((res < 32) ? (void) (0) : __assert_fail ("res < LEN", "spim.c", 75, __extension__ __PRETTY_FUNCTION__));
  instruction(buffer, inst);
  push(buffer, "$s0");
}

canonical_original_code:
static void operation(struct vector_t *buffer, enum token_kind_t kind) {
  int res;
  char inst[32] = "";
  ((operator(kind)) ? (void) (0) : __assert_fail ("operator(kind)", "spim.c", 71, __extension__ __PRETTY_FUNCTION__));
  pop(buffer, "$s1");
  pop(buffer, "$s0");
  res = snprintf(inst, 32, "%s $s0, $s0, $s1", mapping[kind]);
  ((res < 32) ? (void) (0) : __assert_fail ("res < LEN", "spim.c", 75, __extension__ __PRETTY_FUNCTION__));
  instruction(buffer, inst);
  push(buffer, "$s0");
}


recurse

decompiled_code:
__int64 __fastcall recurse(__int64 a1, __int64 a2)
{
unsigned int v3; // edi

v3 = *(_DWORD *)a1;
if ( v3 == 6 )
return load_constprop_0(a2, *(_DWORD *)(a1 + 4));
if ( !operator(v3) )
_assert_fail("0", "spim.c", 0x71u, "recurse");
recurse(*(_QWORD *)(a1 + 8));
recurse(*(_QWORD *)(a1 + 16));
return operation(a2, *(_DWORD *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
unsigned int v3; // edi

v3 = *(_DWORD *)a1;
if ( v3 == 6 )
return func7(a2, *(_DWORD *)(a1 + 4));
if ( !func0(v3) )
_assert_fail("0", "spim.c", 0x71u, "recurse");
func9(*(_QWORD *)(a1 + 8));
func9(*(_QWORD *)(a1 + 16));
return func8(a2, *(_DWORD *)a1);
}

original_code:
static void recurse(const node_t *ast, string_t *buffer) {
  if (ast->kind == INTEGER) {
    load(buffer, ast->value, "$s0");
  }
  else if (operator(ast->kind)) {
    recurse(ast->left, buffer);
    recurse(ast->right, buffer);
    operation(buffer, ast->kind);
  }
  else {
    ((0) ? (void) (0) : __assert_fail ("0", "spim.c", 113, __extension__ __PRETTY_FUNCTION__));
  }
}

canonical_original_code:
static void recurse(struct node *ast, struct vector_t *buffer) {
  if (ast->kind == INTEGER) {
    load(buffer, ast->value, "$s0");
  }
  else if (operator(ast->kind)) {
    recurse(ast->left, buffer);
    recurse(ast->right, buffer);
    operation(buffer, ast->kind);
  }
  else {
    ((0) ? (void) (0) : __assert_fail ("0", "spim.c", 113, __extension__ __PRETTY_FUNCTION__));
  }
}


generate

decompiled_code:
__int64 __fastcall generate(__int64 a1, __int64 a2)
{
prologue(a2);
recurse(a1, a2);
return epilogue(a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
func3(a2);
func9(a1, a2);
return func5(a2);
}

original_code:
void generate(const node_t *ast, string_t *buffer) {
  prologue(buffer);
  recurse(ast, buffer);
  epilogue(buffer);
}

canonical_original_code:
void generate(struct node *ast, struct vector_t *buffer) {
  prologue(buffer);
  recurse(ast, buffer);
  epilogue(buffer);
}


blank

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

v3 = a1 - 9;
LOBYTE(v3) = (unsigned __int8)(a1 - 9) <= 4u;
LOBYTE(a3) = (_BYTE)a1 == 32;
return a3 | v3;
}

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

v3 = a1 - 9;
LOBYTE(v3) = (unsigned __int8)(a1 - 9) <= 4u;
LOBYTE(a3) = (_BYTE)a1 == 32;
return a3 | v3;
}

variable_types: c char


digit

decompiled_code:
bool __fastcall digit(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
bool __fastcall func1(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
static _Bool digit(char c) {
  return ('0' <= c) && (c <= '9');
}


symbol

decompiled_code:
bool __fastcall symbol(char a1)
{
bool result; // al

result = 1;
if ( (a1 & 0xFD) != 45 )
result = (unsigned __int8)(a1 - 40) <= 3u;
return result;
}

canonical_decompiled_code:
bool __fastcall func2(char a1)
{
bool result; // al

result = 1;
if ( (a1 & 0xFD) != 45 )
result = (unsigned __int8)(a1 - 40) <= 3u;
return result;
}


valid

decompiled_code:
bool valid()
{
return position < (unsigned __int64)length;
}

canonical_decompiled_code:
bool func0()
{
return position < (unsigned __int64)length;
}

original_code:
static _Bool valid(void) {
  return position < length;
}

canonical_original_code:
static _Bool valid() {
  return position < length;
}


next

decompiled_code:
char next()
{
char result; // al

result = valid();
if ( result )
{
result = vector_get(tokens, position, &current);
++position;
}
return result;
}

canonical_decompiled_code:
char func1()
{
char result; // al

result = func0();
if ( result )
{
result = vector_get(tokens, position, &current);
++position;
}
return result;
}

original_code:
static void next(void) {
  if (valid()) {
    vector_get(tokens, position, &current);
    position += 1;
  }
}

canonical_original_code:
static void next() {
  if (valid()) {
    vector_get(tokens, position, &current);
    position += 1;
  }
}


Factor

decompiled_code:
__int64 Factor()
{
__int64 v0; // r12

if ( current == 4 )
{
next();
v0 = Expression();
if ( current != 5 )
{
puts(") expected!");
exit(1);
}
}
else
{
if ( current != 6 )
{
puts("( or integer expected!");
exit(1);
}
v0 = node_new(6LL);
*(_DWORD *)(v0 + 4) = dword_1D4;
}
next();
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r12

if ( current == 4 )
{
func1();
v0 = func4();
if ( current != 5 )
{
puts(") expected!");
exit(1);
}
}
else
{
if ( current != 6 )
{
puts("( or integer expected!");
exit(1);
}
v0 = node_new(6LL);
*(_DWORD *)(v0 + 4) = dword_1D4;
}
func1();
return v0;
}

original_code:
static node_t *Factor(void) {
  node_t *expr = ((void *)0);
  switch (current.kind) {
    case OPEN:
      next();
      expr = Expression();
      if (current.kind != CLOSE) {
        puts(") expected!");
        exit(1);
      }
      else {
        next();
      }
      break;
    case INTEGER:
      expr = node_new(INTEGER);
      expr->value = current.value;
      next();
      break;
    default:
      puts("( or integer expected!");
      exit(1);
      break;
  }
  return expr;
}

canonical_original_code:
static struct node *Factor() {
  struct node *expr = ((void *)0);
  switch (current.kind) {
    case OPEN:
      next();
      expr = Expression();
      if (current.kind != CLOSE) {
        puts(") expected!");
        exit(1);
      }
      else {
        next();
      }
      break;
    case INTEGER:
      expr = node_new(INTEGER);
      expr->value = current.value;
      next();
      break;
    default:
      puts("( or integer expected!");
      exit(1);
      break;
  }
  return expr;
}

return_type: struct node { enum token_kind_t { _FIRST=-1, PLUS=0, MINUS=1, TIMES=2, SLASH=3, OPEN=4, CLOSE=5, INTEGER=6, _LAST=7 } kind; int value; struct node *left; struct node *right; } *


Term

decompiled_code:
__int64 Term()
{
__int64 v0; // rax
unsigned int v1; // ebp
__int64 i; // r12
__int64 v3; // rbx
__int64 v4; // rax

v0 = Factor();
v1 = current;
for ( i = v0; v1 - 2 <= 1; *(_QWORD *)(v4 + 16) = v3 )
{
next();
v3 = Factor();
v4 = node_new(v1);
v1 = current;
*(_QWORD *)(v4 + 8) = i;
i = v4;
}
return i;
}

original_code:
static node_t *Term(void) {
  node_t *left = Factor();
  node_t *right, *new;
  while (current.kind == TIMES || current.kind == SLASH) {
    node_kind_t op = current.kind;
    next();
    right = Factor();
    new = node_new(op);
    new->left = left;
    new->right = right;
    left = new;
  }
  return left;
}

canonical_original_code:
static struct node *Term() {
  struct node *left = Factor();
  struct node *right; struct node *new;
  while (current.kind == TIMES || current.kind == SLASH) {
    enum token_kind_t op = current.kind;
    next();
    right = Factor();
    new = node_new(op);
    new->left = left;
    new->right = right;
    left = new;
  }
  return left;
}


Expression

decompiled_code:
__int64 Expression()
{
__int64 v0; // rax
unsigned int v1; // ebp
__int64 i; // r12
__int64 v3; // rbx
__int64 v4; // rax

v0 = Term();
v1 = current;
for ( i = v0; v1 <= 1; *(_QWORD *)(v4 + 16) = v3 )
{
next();
v3 = Term();
v4 = node_new(v1);
v1 = current;
*(_QWORD *)(v4 + 8) = i;
i = v4;
}
return i;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
unsigned int v1; // ebp
__int64 i; // r12
__int64 v3; // rbx
__int64 v4; // rax

v0 = func3();
v1 = current;
for ( i = v0; v1 <= 1; *(_QWORD *)(v4 + 16) = v3 )
{
func1();
v3 = func3();
v4 = node_new(v1);
v1 = current;
*(_QWORD *)(v4 + 8) = i;
i = v4;
}
return i;
}

original_code:
static node_t *Expression(void) {
  node_t *left = Term();
  node_t *right, *new;
  while (current.kind == PLUS || current.kind == MINUS) {
    node_kind_t op = current.kind;
    next();
    right = Term();
    new = node_new(op);
    new->left = left;
    new->right = right;
    left = new;
  }
  return left;
}

canonical_original_code:
static struct node *Expression() {
  struct node *left = Term();
  struct node *right; struct node *new;
  while (current.kind == PLUS || current.kind == MINUS) {
    enum token_kind_t op = current.kind;
    next();
    right = Term();
    new = node_new(op);
    new->left = left;
    new->right = right;
    left = new;
  }
  return left;
}


parse

decompiled_code:
__int64 __fastcall parse(__int64 a1)
{
__int64 v1; // rax

v1 = *(_QWORD *)(a1 + 8);
tokens = a1;
position = 0LL;
length = v1;
next();
return Expression();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax

v1 = *(_QWORD *)(a1 + 8);
tokens = a1;
position = 0LL;
length = v1;
func1();
return func4();
}

original_code:
node_t *parse(vector_t *ts) {
  tokens = ts;
  length = ts->length;
  position = 0;
  next();
  return Expression();
}

canonical_original_code:
struct node *parse(struct vector_t *ts) {
  tokens = ts;
  length = ts->length;
  position = 0;
  next();
  return Expression();
}


operator

decompiled_code:
bool __fastcall operator(unsigned int a1)
{
return a1 <= 3;
}


eval

decompiled_code:
__int64 __fastcall eval(__int64 a1)
{
signed int v1; // ebx
int v2; // er12
int v3; // eax
__int64 result; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 6 )
return *(unsigned int *)(a1 + 4);
if ( !operator(v1) )
_assert_fail("0", "interpreter.c", 0x20u, "eval");
v2 = eval(*(_QWORD *)(a1 + 8));
v3 = eval(*(_QWORD *)(a1 + 16));
if ( v1 == 2 )
return (unsigned int)(v3 * v2);
if ( v1 > 2 )
{
if ( v1 != 3 )
goto LABEL_13;
result = (unsigned int)(v2 / v3);
}
else
{
if ( v1 )
{
if ( v1 == 1 )
return (unsigned int)(v2 - v3);
LABEL_13:
_assert_fail("0", "interpreter.c", 0x1Bu, "eval");
}
result = (unsigned int)(v2 + v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
signed int v1; // ebx
int v2; // er12
int v3; // eax
__int64 result; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 6 )
return *(unsigned int *)(a1 + 4);
if ( !func0(v1) )
_assert_fail("0", "interpreter.c", 0x20u, "eval");
v2 = func1(*(_QWORD *)(a1 + 8));
v3 = func1(*(_QWORD *)(a1 + 16));
if ( v1 == 2 )
return (unsigned int)(v3 * v2);
if ( v1 > 2 )
{
if ( v1 != 3 )
goto LABEL_13;
result = (unsigned int)(v2 / v3);
}
else
{
if ( v1 )
{
if ( v1 == 1 )
return (unsigned int)(v2 - v3);
LABEL_13:
_assert_fail("0", "interpreter.c", 0x1Bu, "eval");
}
result = (unsigned int)(v2 + v3);
}
return result;
}

original_code:
int eval(const node_t *ast) {
  int left, right;
  if (ast->kind == INTEGER) {
    return ast->value;
  }
  else if (operator(ast->kind)) {
    left = eval(ast->left);
    right = eval(ast->right);
    switch (ast->kind) {
      case PLUS: return left + right;
      case MINUS: return left - right;
      case TIMES: return left * right;
      case SLASH: return left / right;
      default: ((0) ? (void) (0) : __assert_fail ("0", "interpreter.c", 27, __extension__ __PRETTY_FUNCTION__));
    }
  }
  else {
    ((0) ? (void) (0) : __assert_fail ("0", "interpreter.c", 32, __extension__ __PRETTY_FUNCTION__));
  }
}

canonical_original_code:
int eval(struct node *ast) {
  int left; int right;
  if (ast->kind == INTEGER) {
    return ast->value;
  }
  else if (operator(ast->kind)) {
    left = eval(ast->left);
    right = eval(ast->right);
    switch (ast->kind) {
      case PLUS: return left + right;
      case MINUS: return left - right;
      case TIMES: return left * right;
      case SLASH: return left / right;
      default: ((0) ? (void) (0) : __assert_fail ("0", "interpreter.c", 27, __extension__ __PRETTY_FUNCTION__));
    }
  }
  else {
    ((0) ? (void) (0) : __assert_fail ("0", "interpreter.c", 32, __extension__ __PRETTY_FUNCTION__));
  }
}

variable_types: left int

variable_types: right int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v4; // r13
char v5; // al
unsigned int v6; // eax
unsigned int v7; // ebp
unsigned int v8; // eax
unsigned int v10; // ebp
unsigned int v11; // eax

if ( getuid() )
{
v3 = 1;
puts("You need to run this tool as root.");
return v3;
}
if ( argc <= 1 )
{
v3 = 2;
printf("Usage: %s <i2c_dev> <read|write> <reg> [value]\nFor example: %s /dev/i2c-0 r 3a\n", *argv, *argv);
printf("Usage: %s <i2c_dev> <set|clr> <reg> [bit]\nFor example: %s /dev/i2c-0 s 3a 1\n", *argv, *argv);
return v3;
}
fd = open(argv[1], 2);
if ( fd == -1 )
{
v3 = 3;
perror("i2c device open");
return v3;
}
if ( ioctl(fd, 0x704uLL, 0LL) )
{
v3 = 4;
perror("I2C_TEN");
return v3;
}
v3 = ioctl(fd, 0x703uLL, 60LL);
if ( v3 )
{
v3 = 5;
perror("I2C_SLAVE");
return v3;
}
if ( argc == 2 )
{
init();
return v3;
}
v4 = argv[2];
v5 = *v4;
if ( *v4 == 115 )
goto LABEL_23;
if ( v5 > 115 )
{
if ( v5 != 119 )
goto LABEL_22;
if ( argc == 5 )
{
v7 = hex_value(argv[3]);
if ( v7 != -1 )
{
v8 = hex_value(argv[4]);
if ( v8 != -1 )
{
p_write(v7, v8);
return v3;
}
return 9;
}
return 8;
}
return -1;
}
if ( v5 == 99 )
{
LABEL_23:
if ( argc == 5 )
{
v10 = hex_value(argv[3]);
if ( v10 != -1 )
{
v11 = dec_value(argv[4]);
if ( v11 <= 0xF )
{
p_ch_bit(v10, v11, *v4 == 115);
return v3;
}
return 9;
}
return 8;
}
return -1;
}
if ( v5 != 114 )
{
LABEL_22:
v3 = 6;
puts("Unknown command");
return v3;
}
v6 = hex_value(argv[3]);
if ( v6 == -1 )
return 7;
p_read(v6);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v4; // r13
char v5; // al
unsigned int v6; // eax
unsigned int v7; // ebp
unsigned int v8; // eax
unsigned int v10; // ebp
unsigned int v11; // eax

if ( getuid() )
{
v3 = 1;
puts("You need to run this tool as root.");
return v3;
}
if ( argc <= 1 )
{
v3 = 2;
printf("Usage: %s <i2c_dev> <read|write> <reg> [value]\nFor example: %s /dev/i2c-0 r 3a\n", *argv, *argv);
printf("Usage: %s <i2c_dev> <set|clr> <reg> [bit]\nFor example: %s /dev/i2c-0 s 3a 1\n", *argv, *argv);
return v3;
}
fd = open(argv[1], 2);
if ( fd == -1 )
{
v3 = 3;
perror("i2c device open");
return v3;
}
if ( ioctl(fd, 0x704uLL, 0LL) )
{
v3 = 4;
perror("I2C_TEN");
return v3;
}
v3 = ioctl(fd, 0x703uLL, 60LL);
if ( v3 )
{
v3 = 5;
perror("I2C_SLAVE");
return v3;
}
if ( argc == 2 )
{
func9();
return v3;
}
v4 = argv[2];
v5 = *v4;
if ( *v4 == 115 )
goto LABEL_23;
if ( v5 > 115 )
{
if ( v5 != 119 )
goto LABEL_22;
if ( argc == 5 )
{
v7 = func11(argv[3]);
if ( v7 != -1 )
{
v8 = func11(argv[4]);
if ( v8 != -1 )
{
func13(v7, v8);
return v3;
}
return 9;
}
return 8;
}
return -1;
}
if ( v5 == 99 )
{
LABEL_23:
if ( argc == 5 )
{
v10 = func11(argv[3]);
if ( v10 != -1 )
{
v11 = func12(argv[4]);
if ( v11 <= 0xF )
{
func15(v10, v11, *v4 == 115);
return v3;
}
return 9;
}
return 8;
}
return -1;
}
if ( v5 != 114 )
{
LABEL_22:
v3 = 6;
puts("Unknown command");
return v3;
}
v6 = func11(argv[3]);
if ( v6 == -1 )
return 7;
func14(v6);
return v3;
}

original_code:
int main(int argc, char **argv, char **envp) {
 uid_t uid = getuid();
 if (uid != 0)
 {
  printf("You need to run this tool as root.\n");
  return 1;
 }
 if (argc < 2)
 {
  printf("Usage: %s <i2c_dev> <read|write> <reg> [value]\nFor example: %s /dev/i2c-0 r 3a\n",
    argv[0], argv[0]);
  printf("Usage: %s <i2c_dev> <set|clr> <reg> [bit]\nFor example: %s /dev/i2c-0 s 3a 1\n",
    argv[0], argv[0]);
  return 2;
 }
 fd=open(argv[1], 02);
 if (fd == -1)
 {
  perror("i2c device open");
  return 3;
 }
 int err;
 err=ioctl(fd, 0x0704, 0);
 if(err) {
  perror("I2C_TEN");
  return 4;
 }
 err=ioctl(fd, 0x0703, 0x3C);
 if(err) {
  perror("I2C_SLAVE");
  return 5;
 }
 if (argc == 2)
 {
  init();
  return 0;
 }
 const char* cmd = argv[2];
 switch (cmd[0])
 {
  case 'r':
  {
   int reg = hex_value(argv[3]);
   if (reg == -1)
    return 7;
   p_read(reg);
  }
  break;
  case 'w':
  {
   if (argc != 5)
    return -1;
   int reg = hex_value(argv[3]);
   if (reg == -1)
    return 8;
   int val = hex_value(argv[4]);
   if (val == -1)
    return 9;
   p_write(reg, val);
  }
  break;
  case 's':
  case 'c':
  {
   if (argc != 5)
    return -1;
   int reg = hex_value(argv[3]);
   if (reg == -1)
    return 8;
   int bit = dec_value(argv[4]);
   if (bit == -1 || (bit < 0 || bit > 15))
    return 9;
   p_ch_bit(reg, bit, cmd[0] == 's');
  }
  break;
  default:
   printf ("Unknown command\n");
   return 6;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv, char **envp) {
 unsigned int uid = getuid();
 if (uid != 0)
 {
  printf("You need to run this tool as root.\n");
  return 1;
 }
 if (argc < 2)
 {
  printf("Usage: %s <i2c_dev> <read|write> <reg> [value]\nFor example: %s /dev/i2c-0 r 3a\n",
    argv[0], argv[0]);
  printf("Usage: %s <i2c_dev> <set|clr> <reg> [bit]\nFor example: %s /dev/i2c-0 s 3a 1\n",
    argv[0], argv[0]);
  return 2;
 }
 fd=open(argv[1], 02);
 if (fd == -1)
 {
  perror("i2c device open");
  return 3;
 }
 int err;
 err=ioctl(fd, 0x0704, 0);
 if(err) {
  perror("I2C_TEN");
  return 4;
 }
 err=ioctl(fd, 0x0703, 0x3C);
 if(err) {
  perror("I2C_SLAVE");
  return 5;
 }
 if (argc == 2)
 {
  init();
  return 0;
 }
 char *cmd = argv[2];
 switch (cmd[0])
 {
  case 'r':
  {
   int reg = hex_value(argv[3]);
   if (reg == -1)
    return 7;
   p_read(reg);
  }
  break;
  case 'w':
  {
   if (argc != 5)
    return -1;
   int reg = hex_value(argv[3]);
   if (reg == -1)
    return 8;
   int val = hex_value(argv[4]);
   if (val == -1)
    return 9;
   p_write(reg, val);
  }
  break;
  case 's':
  case 'c':
  {
   if (argc != 5)
    return -1;
   int reg = hex_value(argv[3]);
   if (reg == -1)
    return 8;
   int bit = dec_value(argv[4]);
   if (bit == -1 || (bit < 0 || bit > 15))
    return 9;
   p_ch_bit(reg, bit, cmd[0] == 's');
  }
  break;
  default:
   printf ("Unknown command\n");
   return 6;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
envp
char **

variable_types:
uid
unsigned int

variable_types: err int

variable_types:
cmd
char *

variable_types: reg int

variable_types: val int

variable_types: bit int


original_code:
unsigned short read_i2c(unsigned char reg) {
 int err;
 struct i2c_rdwr_ioctl_data dat;
 unsigned addr=0x3C>>1;
 unsigned short data;
 struct i2c_msg msgs[]= {
  {
   .addr = addr,
   .flags = 0,
   .len = 1,
   .buf = &reg,
  },
  {
   .addr = addr,
   .flags = 0x0001,
   .len = 2,
   .buf =(unsigned char*) &data,
  }
 };
 dat.msgs=msgs;
 dat.nmsgs=2;
 err=ioctl(fd, 0x0707, &dat);
 if(err==-1) {
  perror("I2C_RDWR");
  return 0;
 }
 data=data<<8 | (data&0xff00)>>8;
 return data;
}

canonical_original_code:
unsigned short read_i2c(unsigned char reg) {
 int err;
 struct i2c_rdwr_ioctl_data dat;
 unsigned int addr = 0x3C>>1;
 unsigned short data;
 struct i2c_msg msgs[] = {
  {
   .addr = addr,
   .flags = 0,
   .len = 1,
   .buf = &reg,
  },
  {
   .addr = addr,
   .flags = 0x0001,
   .len = 2,
   .buf =(unsigned char*) &data,
  }
 };
 dat.msgs=msgs;
 dat.nmsgs=2;
 err=ioctl(fd, 0x0707, &dat);
 if(err==-1) {
  perror("I2C_RDWR");
  return 0;
 }
 data=data<<8 | (data&0xff00)>>8;
 return data;
}

variable_types:
reg
unsigned char

variable_types: struct i2c_rdwr_ioctl_data { struct i2c_msg { unsigned short addr; unsigned short flags; unsigned short len; unsigned char *buf; } *msgs; unsigned int nmsgs; }

variable_types:
addr
unsigned int

variable_types:
data
unsigned short

variable_types: struct i2c_msg { unsigned short addr; unsigned short flags; unsigned short len; unsigned char *buf; } []

return_type: unsigned short

user_defined_types: struct i2c_rdwr_ioctl_data { struct i2c_msg *msgs; unsigned int nmsgs; }


original_code:
void write_i2c(unsigned char reg, unsigned short value) {
 int err;
 struct i2c_rdwr_ioctl_data dat;
 unsigned addr=0x3C>>1;
 unsigned short data;
 unsigned char buf[3];
 buf[0]=reg;
 buf[2]=value&0xff;
 buf[1]=value>>8;
 struct i2c_msg msgs[]= {
  {
   .addr = addr,
   .flags = 0,
   .len = 3,
   .buf = buf,
  }
 };
 dat.msgs=msgs;
 dat.nmsgs=1;
 err=ioctl(fd, 0x0707, &dat);
 if(err==-1) {
  perror("I2C_RDWR");
  return;
 }
}

canonical_original_code:
void write_i2c(unsigned char reg, unsigned short value) {
 int err;
 struct i2c_rdwr_ioctl_data dat;
 unsigned int addr = 0x3C>>1;
 unsigned short data;
 unsigned char buf[3];
 buf[0]=reg;
 buf[2]=value&0xff;
 buf[1]=value>>8;
 struct i2c_msg msgs[] = {
  {
   .addr = addr,
   .flags = 0,
   .len = 3,
   .buf = buf,
  }
 };
 dat.msgs=msgs;
 dat.nmsgs=1;
 err=ioctl(fd, 0x0707, &dat);
 if(err==-1) {
  perror("I2C_RDWR");
  return;
 }
}

variable_types:
value
unsigned short

variable_types:
buf
unsigned char [3]

user_defined_types: struct i2c_msg { unsigned short addr; unsigned short flags; unsigned short len; unsigned char *buf; }


decompiled_code:
__int64 __fastcall hex_digit(char a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
result = (unsigned int)(char)(a1 - 87);
if ( (unsigned __int8)((a1 & 0xDF) - 65) >= 6u )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(char)(a1 - 48);
result = (unsigned int)(char)(a1 - 87);
if ( (unsigned __int8)((a1 & 0xDF) - 65) >= 6u )
result = 0xFFFFFFFFLL;
return result;
}

variable_types: c char


decompiled_code:
__int64 __fastcall hex_value(char *a1)
{
unsigned int v2; // eax
char v3; // di
unsigned int v4; // er8
int v5; // eax
__int64 v6; // rcx
int v7; // er8

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = hex_digit(*a1);
v3 = a1[1];
v4 = v2;
if ( v3 )
{
while ( 1 )
{
v5 = hex_digit(v3);
if ( v5 == -1 )
break;
v3 = *(_BYTE *)(v6 + 1);
v4 = v5 | (16 * v7);
if ( !v3 )
return v4;
}
printf("Incorrect value: %s\n", a1);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
unsigned int v2; // eax
char v3; // di
unsigned int v4; // er8
int v5; // eax
__int64 v6; // rcx
int v7; // er8

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = func10(*a1);
v3 = a1[1];
v4 = v2;
if ( v3 )
{
while ( 1 )
{
v5 = func10(v3);
if ( v5 == -1 )
break;
v3 = *(_BYTE *)(v6 + 1);
v4 = v5 | (16 * v7);
if ( !v3 )
return v4;
}
printf("Incorrect value: %s\n", a1);
v4 = -1;
}
return v4;
}

original_code:
int hex_value(const char* sval)
{
 int x = -1;
 int val = 0;
 const char* ptr = sval;
 if (!sval)
  return -1;
 val = hex_digit(*ptr);
 ++ptr;
 while (*ptr != '\0')
 {
  int x = hex_digit(*ptr);
  if (x == -1)
  {
   printf("Incorrect value: %s\n", sval);
   return -1;
  }
  ++ptr;
  val = ((val << 4) | x);
 }
 return val;
}

canonical_original_code:
int hex_value(char *sval)
{
 int x = -1;
 int val = 0;
 char *ptr = sval;
 if (!sval)
  return -1;
 val = hex_digit(*ptr);
 ++ptr;
 while (*ptr != '\0')
 {
  int x = hex_digit(*ptr);
  if (x == -1)
  {
   printf("Incorrect value: %s\n", sval);
   return -1;
  }
  ++ptr;
  val = ((val << 4) | x);
 }
 return val;
}

variable_types:
sval
char *

variable_types: x int

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall dec_value(const char *a1)
{
int v1; // eax
const char *v2; // rdx
unsigned int v3; // er8
unsigned int v4; // eax

if ( !a1 )
return (unsigned int)-1;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = 0;
while ( 1 )
{
v4 = v1 - 48;
if ( v4 > 9 )
break;
++v2;
v3 = v4 + 10 * v3;
v1 = *v2;
if ( !*v2 )
return v3;
}
printf("Incorrect value: %s\n", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
int v1; // eax
const char *v2; // rdx
unsigned int v3; // er8
unsigned int v4; // eax

if ( !a1 )
return (unsigned int)-1;
v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1;
v3 = 0;
while ( 1 )
{
v4 = v1 - 48;
if ( v4 > 9 )
break;
++v2;
v3 = v4 + 10 * v3;
v1 = *v2;
if ( !*v2 )
return v3;
}
printf("Incorrect value: %s\n", a1);
return 0xFFFFFFFFLL;
}

original_code:
int dec_value(const char* sval)
{
 int x = -1;
 int val = 0;
 const char* ptr = sval;
 if (!sval)
  return -1;
 while (*ptr != '\0')
 {
  int x = *ptr - '0';
  if (x < 0 || x > 9)
  {
   printf("Incorrect value: %s\n", sval);
   return -1;
  }
  ++ptr;
  val = (val * 10 + x);
 }
 return val;
}

canonical_original_code:
int dec_value(char *sval)
{
 int x = -1;
 int val = 0;
 char *ptr = sval;
 if (!sval)
  return -1;
 while (*ptr != '\0')
 {
  int x = *ptr - '0';
  if (x < 0 || x > 9)
  {
   printf("Incorrect value: %s\n", sval);
   return -1;
  }
  ++ptr;
  val = (val * 10 + x);
 }
 return val;
}


decompiled_code:
void __fastcall p_write(unsigned int a1, unsigned int a2)
{
printf("-> %02x: %04x\n", a1, a2);
write_i2c(a1, a2);
}

canonical_decompiled_code:
void __fastcall func13(unsigned int a1, unsigned int a2)
{
printf("-> %02x: %04x\n", a1, a2);
func8(a1, a2);
}

original_code:
int p_write(int reg, int val)
{
 printf("-> %02x: %04x\n", reg, val);
 write_i2c(reg, val);
}


decompiled_code:
int __fastcall p_read(unsigned int a1)
{
unsigned __int16 v1; // ax

v1 = read_i2c(a1);
return printf("%02x: %04x\n", a1, v1);
}

canonical_decompiled_code:
int __fastcall func14(unsigned int a1)
{
unsigned __int16 v1; // ax

v1 = func7(a1);
return printf("%02x: %04x\n", a1, v1);
}

original_code:
int p_read(int reg)
{
 unsigned int val = read_i2c(reg);
 printf("%02x: %04x\n", reg, val);
}

variable_types:
val
unsigned int


decompiled_code:
void __fastcall p_ch_bit(unsigned int a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
__int64 v5; // rdx
__int16 v6; // bp

printf("-> %02x: %d to %d\n", a1, a2, a3);
printf("-> %02x: %04x before\n", a1, 8LL);
v4 = 1 << a2;
if ( a3 )
{
v5 = v4 | 8u;
v6 = v4 | 8;
}
else
{
v5 = ~(_BYTE)v4 & 8;
v6 = ~(_BYTE)v4 & 8;
}
printf("-> %02x: %04x after\n", a1, v5);
write_i2c(a1, v6);
}

canonical_decompiled_code:
void __fastcall func15(unsigned int a1, unsigned int a2, unsigned int a3)
{
int v4; // eax
__int64 v5; // rdx
__int16 v6; // bp

printf("-> %02x: %d to %d\n", a1, a2, a3);
printf("-> %02x: %04x before\n", a1, 8LL);
v4 = 1 << a2;
if ( a3 )
{
v5 = v4 | 8u;
v6 = v4 | 8;
}
else
{
v5 = ~(_BYTE)v4 & 8;
v6 = ~(_BYTE)v4 & 8;
}
printf("-> %02x: %04x after\n", a1, v5);
func8(a1, v6);
}

original_code:
int p_ch_bit(int reg, int bit, int set)
{
 printf("-> %02x: %d to %d\n", reg, bit, set);
 unsigned int val = 0x8;
 printf("-> %02x: %04x before\n", reg, val);
 if (set)
  val = val | (1 << bit);
 else
  val = val & (~(1 << bit));
 printf("-> %02x: %04x after\n", reg, val);
 write_i2c(reg, val);
}

variable_types: set int


BeginStatusReport

repo: Subsentient/epoch

decompiled_code:
unsigned __int64 __fastcall BeginStatusReport(const char *a1)
{
char *v1; // rax
char *v2; // rbx
char *v3; // rcx
char v5[4096]; // [rsp+0h] [rbp-3828h] BYREF
char dest[10248]; // [rsp+1000h] [rbp-2828h] BYREF
unsigned __int64 v7; // [rsp+3808h] [rbp-20h]

v7 = __readfsqword(0x28u);
memcpy(dest, StatusReportFormat, 0x2800uLL);
v1 = strstr(dest, "!TITLE!");
v2 = v1;
if ( v1 )
{
*v1 = 0;
memset(v5, 0, sizeof(v5));
strcpy(v5, dest);
v3 = strcpy(&v5[2048], v2 + 7);
}
else
{
memset(v5, 0, sizeof(v5));
strcpy(v5, dest);
v3 = &v5[2048];
}
printf("%s%s%s", v5, a1, v3);
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1)
{
char *v1; // rax
char *v2; // rbx
char *v3; // rcx
char v5[4096]; // [rsp+0h] [rbp-3828h] BYREF
char dest[10248]; // [rsp+1000h] [rbp-2828h] BYREF
unsigned __int64 v7; // [rsp+3808h] [rbp-20h]

v7 = __readfsqword(0x28u);
memcpy(dest, StatusReportFormat, 0x2800uLL);
v1 = strstr(dest, "!TITLE!");
v2 = v1;
if ( v1 )
{
*v1 = 0;
memset(v5, 0, sizeof(v5));
strcpy(v5, dest);
v3 = strcpy(&v5[2048], v2 + 7);
}
else
{
memset(v5, 0, sizeof(v5));
strcpy(v5, dest);
v3 = &v5[2048];
}
printf("%s%s%s", v5, a1, v3);
return v7 - __readfsqword(0x28u);
}

original_code:
void BeginStatusReport(const char *InReport)
{
 struct _StatusReportFormat TempStats = StatusReportFormat;
 char *TitleBegin = strstr(TempStats.StartFormat, "!TITLE!");
 char *TitleEnd = TitleBegin ? TitleBegin + sizeof "!TITLE!" - 1 : ((void *)0);
 char Halves[2][sizeof TempStats.StartFormat] = { { '\0' } };
 if (TitleBegin) *TitleBegin = '\0';
 strcpy(Halves[0], TempStats.StartFormat);
 if (TitleEnd) strcpy(Halves[1], TitleEnd);
 printf("%s%s%s", Halves[0], InReport, Halves[1]);
}

canonical_original_code:
void BeginStatusReport(char *InReport)
{
 struct _StatusReportFormat TempStats = StatusReportFormat;
 char *TitleBegin = strstr(TempStats.StartFormat, "!TITLE!");
 char *TitleEnd = TitleBegin ? TitleBegin + sizeof "!TITLE!" - 1 : ((void *)0);
 char Halves[2][-1] = { { '\0' } };
 if (TitleBegin) *TitleBegin = '\0';
 strcpy(Halves[0], TempStats.StartFormat);
 if (TitleEnd) strcpy(Halves[1], TitleEnd);
 printf("%s%s%s", Halves[0], InReport, Halves[1]);
}

variable_types:
InReport
char *

variable_types: struct _StatusReportFormat { char StartFormat[2048]; char FinishFormat[2048]; char StatusFormats[3][2048]; }

variable_types:
TitleBegin
char *

variable_types:
TitleEnd
char *

variable_types:
Halves
char [2][-1]


CompleteStatusReport

decompiled_code:
unsigned __int64 __fastcall CompleteStatusReport(const char *a1, unsigned int a2, char a3)
{
char *v3; // rbp
const char *v4; // r14
char *v5; // rbx
char *v6; // r15
bool v7; // cl
bool v8; // dl
const char *v9; // r13
const char *v11; // [rsp+0h] [rbp-3058h]
bool v12; // [rsp+Bh] [rbp-304Dh]
char s[2048]; // [rsp+10h] [rbp-3048h] BYREF
char dest[10248]; // [rsp+810h] [rbp-2848h] BYREF
unsigned __int64 v16; // [rsp+3018h] [rbp-40h]

v3 = 0LL;
v4 = &dest[2048];
v16 = __readfsqword(0x28u);
memcpy(dest, StatusReportFormat, 0x2800uLL);
v11 = &StatusReportFormat[2048 * (unsigned __int64)a2 + 4096];
while ( 1 )
{
v5 = strstr(v4, "!TITLE!");
v6 = strstr(v4, "!STATUS!");
v7 = v6 != 0LL;
v8 = v6 != 0LL && v5 != 0LL;
if ( !v8 )
break;
if ( v5 < v6 )
goto LABEL_10;
*v6 = 0;
v8 = v5 == v6;
v9 = v6 + 8;
if ( *v4 )
{
v5 = v6;
goto LABEL_27;
}
if ( v5 == v6 )
goto LABEL_11;
LABEL_6:
v3 = v6;
v4 = v9;
printf("%s", v11);
LABEL_7:
if ( !v9 )
goto LABEL_21;
}
if ( v5 )
{
LABEL_10:
*v5 = 0;
v9 = v5 + 7;
if ( !*v4 )
goto LABEL_11;
v8 = 1;
goto LABEL_27;
}
if ( v6 )
{
v9 = v6 + 8;
v5 = v6;
goto LABEL_14;
}
if ( v3 )
{
v5 = v3;
v9 = 0LL;
LABEL_14:
*v5 = 0;
if ( !*v4 )
{
LABEL_15:
if ( v6 != v5 || !v7 )
{
v3 = v5;
v4 = v9;
goto LABEL_7;
}
v6 = v5;
goto LABEL_6;
}
LABEL_27:
v12 = v8;
printf("%s", v4);
v7 = v6 != 0LL;
if ( v12 )
{
LABEL_11:
v3 = v5;
printf("%s", a1);
v4 = v9;
goto LABEL_7;
}
goto LABEL_15;
}
if ( *v4 )
printf("%s", v4);
LABEL_21:
snprintf(s, 0x800uLL, "%s (%s)", a1, v11);
if ( a3 && a1 && EnableLogging )
WriteLogLine(s, 1LL);
return v16 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(const char *a1, unsigned int a2, char a3)
{
char *v3; // rbp
const char *v4; // r14
char *v5; // rbx
char *v6; // r15
bool v7; // cl
bool v8; // dl
const char *v9; // r13
const char *v11; // [rsp+0h] [rbp-3058h]
bool v12; // [rsp+Bh] [rbp-304Dh]
char s[2048]; // [rsp+10h] [rbp-3048h] BYREF
char dest[10248]; // [rsp+810h] [rbp-2848h] BYREF
unsigned __int64 v16; // [rsp+3018h] [rbp-40h]

v3 = 0LL;
v4 = &dest[2048];
v16 = __readfsqword(0x28u);
memcpy(dest, StatusReportFormat, 0x2800uLL);
v11 = &StatusReportFormat[2048 * (unsigned __int64)a2 + 4096];
while ( 1 )
{
v5 = strstr(v4, "!TITLE!");
v6 = strstr(v4, "!STATUS!");
v7 = v6 != 0LL;
v8 = v6 != 0LL && v5 != 0LL;
if ( !v8 )
break;
if ( v5 < v6 )
goto LABEL_10;
*v6 = 0;
v8 = v5 == v6;
v9 = v6 + 8;
if ( *v4 )
{
v5 = v6;
goto LABEL_27;
}
if ( v5 == v6 )
goto LABEL_11;
LABEL_6:
v3 = v6;
v4 = v9;
printf("%s", v11);
LABEL_7:
if ( !v9 )
goto LABEL_21;
}
if ( v5 )
{
LABEL_10:
*v5 = 0;
v9 = v5 + 7;
if ( !*v4 )
goto LABEL_11;
v8 = 1;
goto LABEL_27;
}
if ( v6 )
{
v9 = v6 + 8;
v5 = v6;
goto LABEL_14;
}
if ( v3 )
{
v5 = v3;
v9 = 0LL;
LABEL_14:
*v5 = 0;
if ( !*v4 )
{
LABEL_15:
if ( v6 != v5 || !v7 )
{
v3 = v5;
v4 = v9;
goto LABEL_7;
}
v6 = v5;
goto LABEL_6;
}
LABEL_27:
v12 = v8;
printf("%s", v4);
v7 = v6 != 0LL;
if ( v12 )
{
LABEL_11:
v3 = v5;
printf("%s", a1);
v4 = v9;
goto LABEL_7;
}
goto LABEL_15;
}
if ( *v4 )
printf("%s", v4);
LABEL_21:
snprintf(s, 0x800uLL, "%s (%s)", a1, v11);
if ( a3 && a1 && EnableLogging )
WriteLogLine(s, 1LL);
return v16 - __readfsqword(0x28u);
}

original_code:
void CompleteStatusReport(const char *InReport, ReturnCode ExitStatus, Bool LogReport)
{
 struct _StatusReportFormat TempStats = StatusReportFormat;
 char *Worker = TempStats.FinishFormat;
 char OBuf[2048];
 char *SubEnd = ((void *)0), *SubBegin = ((void *)0);
 do
 {
  char *Find1 = ((void *)0), *Find2 = ((void *)0);
  SubEnd = ((void *)0);
  Find1 = strstr(Worker, "!TITLE!");
  Find2 = strstr(Worker, "!STATUS!");
  if (Find1 && Find2)
  {
   if (Find2 > Find1)
   {
    SubBegin = Find1;
    SubEnd = Find1 + sizeof "!TITLE!" - 1;
   }
   else
   {
    SubBegin = Find2;
    SubEnd = Find2 + sizeof "!STATUS!" - 1;
   }
  }
  else
  {
   if (Find1)
   {
    SubBegin = Find1;
    SubEnd = Find1 + sizeof "!TITLE!" - 1;
   }
   else if (Find2)
   {
    SubBegin = Find2;
    SubEnd = Find2 + sizeof "!STATUS!" - 1;
   }
  }
  if (SubBegin) *SubBegin = '\0';
  if (*Worker) printf("%s", Worker);
  if (Find1 && SubBegin == Find1)
  {
   printf("%s", InReport);
  }
  else if (Find2 && SubBegin == Find2)
  {
   printf("%s", StatusReportFormat.StatusFormats[ExitStatus]);
  }
 } while((Worker = SubEnd) != ((void *)0));
 snprintf(OBuf, sizeof OBuf, "%s (%s)", InReport, StatusReportFormat.StatusFormats[ExitStatus]);
 if (LogReport && InReport != ((void *)0) && EnableLogging)
 {
  WriteLogLine(OBuf, true);
 }
}

canonical_original_code:
void CompleteStatusReport(char *InReport, enum ReturnCode ExitStatus, char LogReport)
{
 struct _StatusReportFormat TempStats = StatusReportFormat;
 char *Worker = TempStats.FinishFormat;
 char OBuf[2048];
 char *SubEnd = ((void *)0); char *SubBegin = ((void *)0);
 do
 {
  char *Find1 = ((void *)0); char *Find2 = ((void *)0);
  SubEnd = ((void *)0);
  Find1 = strstr(Worker, "!TITLE!");
  Find2 = strstr(Worker, "!STATUS!");
  if (Find1 && Find2)
  {
   if (Find2 > Find1)
   {
    SubBegin = Find1;
    SubEnd = Find1 + sizeof "!TITLE!" - 1;
   }
   else
   {
    SubBegin = Find2;
    SubEnd = Find2 + sizeof "!STATUS!" - 1;
   }
  }
  else
  {
   if (Find1)
   {
    SubBegin = Find1;
    SubEnd = Find1 + sizeof "!TITLE!" - 1;
   }
   else if (Find2)
   {
    SubBegin = Find2;
    SubEnd = Find2 + sizeof "!STATUS!" - 1;
   }
  }
  if (SubBegin) *SubBegin = '\0';
  if (*Worker) printf("%s", Worker);
  if (Find1 && SubBegin == Find1)
  {
   printf("%s", InReport);
  }
  else if (Find2 && SubBegin == Find2)
  {
   printf("%s", StatusReportFormat.StatusFormats[ExitStatus]);
  }
 } while((Worker = SubEnd) != ((void *)0));
 snprintf(OBuf, sizeof OBuf, "%s (%s)", InReport, StatusReportFormat.StatusFormats[ExitStatus]);
 if (LogReport && InReport != ((void *)0) && EnableLogging)
 {
  WriteLogLine(OBuf, true);
 }
}

variable_types: enum ReturnCode { FAILURE=0, SUCCESS=1, WARNING=2 }

variable_types: LogReport char

variable_types:
Worker
char *

variable_types:
OBuf
char [2048]

variable_types:
SubEnd
char *

variable_types:
SubBegin
char *

user_defined_types: struct _StatusReportFormat { char StartFormat[2048]; char FinishFormat[2048]; char StatusFormats[3][2048]; }


SpitError

decompiled_code:
int __fastcall SpitError(const char *a1)
{
char v2[16]; // [rsp+0h] [rbp-78h] BYREF
char v3[16]; // [rsp+10h] [rbp-68h] BYREF
char v4[16]; // [rsp+20h] [rbp-58h] BYREF
char v5[16]; // [rsp+30h] [rbp-48h] BYREF
char v6[16]; // [rsp+40h] [rbp-38h] BYREF
char v7[40]; // [rsp+50h] [rbp-28h] BYREF

GetCurrentTime(v2, v3, v4, v5, v6, v7);
return fprintf(stderr, "[%s:%s:%s | %s-%s-%s] \x1B[31mEpoch: ERROR:\n\x1B[0m%s\n\n", v2, v3, v4, v5, v6, v7, a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
char v2[16]; // [rsp+0h] [rbp-78h] BYREF
char v3[16]; // [rsp+10h] [rbp-68h] BYREF
char v4[16]; // [rsp+20h] [rbp-58h] BYREF
char v5[16]; // [rsp+30h] [rbp-48h] BYREF
char v6[16]; // [rsp+40h] [rbp-38h] BYREF
char v7[40]; // [rsp+50h] [rbp-28h] BYREF

GetCurrentTime(v2, v3, v4, v5, v6, v7);
return fprintf(stderr, "[%s:%s:%s | %s-%s-%s] \x1B[31mEpoch: ERROR:\n\x1B[0m%s\n\n", v2, v3, v4, v5, v6, v7, a1);
}

original_code:
void SpitError(const char *INErr)
{
 char HMS[3][16], MDY[3][16];
 GetCurrentTime(HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2]);
 fprintf(stderr, "[%s:%s:%s | %s-%s-%s] " "\033[31m" "Epoch: ERROR:\n" "\033[0m" "%s\n\n",
   HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2], INErr);
}

canonical_original_code:
void SpitError(char *INErr)
{
 char HMS[3][16]; char MDY[3][16];
 GetCurrentTime(HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2]);
 fprintf(stderr, "[%s:%s:%s | %s-%s-%s] " "\033[31m" "Epoch: ERROR:\n" "\033[0m" "%s\n\n",
   HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2], INErr);
}

variable_types:
INErr
char *

variable_types:
HMS
char [3][16]

variable_types:
MDY
char [3][16]


SmallError

decompiled_code:
int __fastcall SmallError(const char *a1)
{
return fprintf(stderr, "\x1B[31m* \x1B[0m%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return fprintf(stderr, "\x1B[31m* \x1B[0m%s\n", a1);
}

original_code:
void SmallError(const char *INErr)
{
 fprintf(stderr, "\033[31m" "* " "\033[0m" "%s\n", INErr);
}

canonical_original_code:
void SmallError(char *INErr)
{
 fprintf(stderr, "\033[31m" "* " "\033[0m" "%s\n", INErr);
}


SpitWarning

decompiled_code:
int __fastcall SpitWarning(const char *a1)
{
char v2[16]; // [rsp+0h] [rbp-78h] BYREF
char v3[16]; // [rsp+10h] [rbp-68h] BYREF
char v4[16]; // [rsp+20h] [rbp-58h] BYREF
char v5[16]; // [rsp+30h] [rbp-48h] BYREF
char v6[16]; // [rsp+40h] [rbp-38h] BYREF
char v7[40]; // [rsp+50h] [rbp-28h] BYREF

GetCurrentTime(v2, v3, v4, v5, v6, v7);
return fprintf(stderr, "[%s:%s:%s | %s-%s-%s] \x1B[33mEpoch: WARNING:\n\x1B[0m%s\n\n", v2, v3, v4, v5, v6, v7, a1);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
char v2[16]; // [rsp+0h] [rbp-78h] BYREF
char v3[16]; // [rsp+10h] [rbp-68h] BYREF
char v4[16]; // [rsp+20h] [rbp-58h] BYREF
char v5[16]; // [rsp+30h] [rbp-48h] BYREF
char v6[16]; // [rsp+40h] [rbp-38h] BYREF
char v7[40]; // [rsp+50h] [rbp-28h] BYREF

GetCurrentTime(v2, v3, v4, v5, v6, v7);
return fprintf(stderr, "[%s:%s:%s | %s-%s-%s] \x1B[33mEpoch: WARNING:\n\x1B[0m%s\n\n", v2, v3, v4, v5, v6, v7, a1);
}

original_code:
void SpitWarning(const char *INWarning)
{
 char HMS[3][16], MDY[3][16];
 GetCurrentTime(HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2]);
 fprintf(stderr, "[%s:%s:%s | %s-%s-%s] " "\033[33m" "Epoch: WARNING:\n" "\033[0m" "%s\n\n",
   HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2], INWarning);
}

canonical_original_code:
void SpitWarning(char *INWarning)
{
 char HMS[3][16]; char MDY[3][16];
 GetCurrentTime(HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2]);
 fprintf(stderr, "[%s:%s:%s | %s-%s-%s] " "\033[33m" "Epoch: WARNING:\n" "\033[0m" "%s\n\n",
   HMS[0], HMS[1], HMS[2], MDY[0], MDY[1], MDY[2], INWarning);
}

variable_types:
INWarning
char *


SetBannerColor

decompiled_code:
unsigned __int64 __fastcall SetBannerColor(const char *a1)
{
const char *v1; // rsi
char v3[1032]; // [rsp+0h] [rbp-418h] BYREF
unsigned __int64 v4; // [rsp+408h] [rbp-10h]

v4 = __readfsqword(0x28u);
if ( !strcmp(a1, "BLACK") )
{
v1 = "\x1B[30m";
}
else if ( !strcmp(a1, "BLUE") )
{
v1 = "\x1B[34m";
}
else if ( !strcmp(a1, "RED") )
{
v1 = "\x1B[31m";
}
else if ( !strcmp(a1, "GREEN") )
{
v1 = "\x1B[32m";
}
else if ( !strcmp(a1, "YELLOW") )
{
v1 = "\x1B[33m";
}
else if ( !strcmp(a1, "MAGENTA") )
{
v1 = "\x1B[35m";
}
else if ( !strcmp(a1, "CYAN") )
{
v1 = "\x1B[36m";
}
else
{
v1 = "\x1B[37m";
if ( strcmp(a1, "WHITE") )
{
BootBanner[2049] = 0;
snprintf(v3, 0x400uLL, "Bad color value \"%s\" specified for boot banner. Setting no color.", a1);
SpitWarning(v3);
return v4 - __readfsqword(0x28u);
}
}
strncpy((char *)(unsigned int)((_DWORD)BootBanner + 2049), v1, 0x3FuLL);
BootBanner[2112] = 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(const char *a1)
{
const char *v1; // rsi
char v3[1032]; // [rsp+0h] [rbp-418h] BYREF
unsigned __int64 v4; // [rsp+408h] [rbp-10h]

v4 = __readfsqword(0x28u);
if ( !strcmp(a1, "BLACK") )
{
v1 = "\x1B[30m";
}
else if ( !strcmp(a1, "BLUE") )
{
v1 = "\x1B[34m";
}
else if ( !strcmp(a1, "RED") )
{
v1 = "\x1B[31m";
}
else if ( !strcmp(a1, "GREEN") )
{
v1 = "\x1B[32m";
}
else if ( !strcmp(a1, "YELLOW") )
{
v1 = "\x1B[33m";
}
else if ( !strcmp(a1, "MAGENTA") )
{
v1 = "\x1B[35m";
}
else if ( !strcmp(a1, "CYAN") )
{
v1 = "\x1B[36m";
}
else
{
v1 = "\x1B[37m";
if ( strcmp(a1, "WHITE") )
{
BootBanner[2049] = 0;
snprintf(v3, 0x400uLL, "Bad color value \"%s\" specified for boot banner. Setting no color.", a1);
func4(v3);
return v4 - __readfsqword(0x28u);
}
}
strncpy((char *)(unsigned int)((_DWORD)BootBanner + 2049), v1, 0x3FuLL);
BootBanner[2112] = 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void SetBannerColor(const char *InChoice)
{
 const char *Color = ((void *)0);
 if (!strcmp(InChoice, "BLACK"))
 {
  Color = "\033[30m";
 }
 else if (!strcmp(InChoice, "BLUE"))
 {
  Color = "\033[34m";
 }
 else if (!strcmp(InChoice, "RED"))
 {
  Color = "\033[31m";
 }
 else if (!strcmp(InChoice, "GREEN"))
 {
  Color = "\033[32m";
 }
 else if (!strcmp(InChoice, "YELLOW"))
 {
  Color = "\033[33m";
 }
 else if (!strcmp(InChoice, "MAGENTA"))
 {
  Color = "\033[35m";
 }
 else if (!strcmp(InChoice, "CYAN"))
 {
  Color = "\033[36m";
 }
 else if (!strcmp(InChoice, "WHITE"))
 {
  Color = "\033[37m";
 }
 else
 {
  char TmpBuf[1024];
  BootBanner.BannerColor[0] = '\0';
  snprintf(TmpBuf, sizeof TmpBuf, "Bad color value \"%s\" specified for boot banner. Setting no color.", InChoice);
  SpitWarning(TmpBuf);
  return;
 }
 strncpy(BootBanner.BannerColor, Color, sizeof BootBanner.BannerColor - 1);
 BootBanner.BannerColor[sizeof BootBanner.BannerColor - 1] = '\0';
}

canonical_original_code:
void SetBannerColor(char *InChoice)
{
 char *Color = ((void *)0);
 if (!strcmp(InChoice, "BLACK"))
 {
  Color = "\033[30m";
 }
 else if (!strcmp(InChoice, "BLUE"))
 {
  Color = "\033[34m";
 }
 else if (!strcmp(InChoice, "RED"))
 {
  Color = "\033[31m";
 }
 else if (!strcmp(InChoice, "GREEN"))
 {
  Color = "\033[32m";
 }
 else if (!strcmp(InChoice, "YELLOW"))
 {
  Color = "\033[33m";
 }
 else if (!strcmp(InChoice, "MAGENTA"))
 {
  Color = "\033[35m";
 }
 else if (!strcmp(InChoice, "CYAN"))
 {
  Color = "\033[36m";
 }
 else if (!strcmp(InChoice, "WHITE"))
 {
  Color = "\033[37m";
 }
 else
 {
  char TmpBuf[1024];
  BootBanner.BannerColor[0] = '\0';
  snprintf(TmpBuf, sizeof TmpBuf, "Bad color value \"%s\" specified for boot banner. Setting no color.", InChoice);
  SpitWarning(TmpBuf);
  return;
 }
 strncpy(BootBanner.BannerColor, Color, sizeof BootBanner.BannerColor - 1);
 BootBanner.BannerColor[sizeof BootBanner.BannerColor - 1] = '\0';
}

variable_types:
InChoice
char *

variable_types:
Color
char *

variable_types:
TmpBuf
char [1024]


AllNumeric

decompiled_code:
__int64 __fastcall AllNumeric(char *a1)
{
__int64 v1; // r12
char *v2; // rbx
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !(_BYTE)v1 )
return (unsigned int)v1;
v2 = a1;
v3 = *_ctype_b_loc();
do
{
if ( (v3[v1] & 0x800) == 0 )
{
LODWORD(v1) = 0;
return (unsigned int)v1;
}
v1 = *++v2;
}
while ( (_BYTE)v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
__int64 v1; // r12
char *v2; // rbx
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !(_BYTE)v1 )
return (unsigned int)v1;
v2 = a1;
v3 = *_ctype_b_loc();
do
{
if ( (v3[v1] & 0x800) == 0 )
{
LODWORD(v1) = 0;
return (unsigned int)v1;
}
v1 = *++v2;
}
while ( (_BYTE)v1 );
return 1LL;
}

original_code:
Bool AllNumeric(const char *InStream)
{
 if (!*InStream)
 {
  return false;
 }
 for (; *InStream != '\0'; ++InStream)
 {
  if (!((*__ctype_b_loc ())[(int) ((*InStream))] & (unsigned short int) _ISdigit))
  {
   return false;
  }
 }
 return true;
}

canonical_original_code:
char AllNumeric(char *InStream)
{
 if (!*InStream)
 {
  return false;
 }
 for (; *InStream != '\0'; ++InStream)
 {
  if (!((*__ctype_b_loc ())[(int) ((*InStream))] & (unsigned short) _ISdigit))
  {
   return false;
  }
 }
 return true;
}

variable_types:
InStream
char *

return_type: char


DateDiff

decompiled_code:
int *__fastcall DateDiff(unsigned int a1, unsigned int a2, int *a3, int *a4, int *a5)
{
int v10; // ecx
int v11; // edx
int v12; // eax
int v13; // edi
int v14; // esi
time_t v15; // rax
time_t v16; // rcx
int *result; // rax
time_t timer; // [rsp+8h] [rbp-B0h] BYREF
struct tm tp; // [rsp+10h] [rbp-A8h] BYREF
struct tm v20; // [rsp+50h] [rbp-68h] BYREF

timer = 0LL;
time(&timer);
localtime_r(&timer, &tp);
v10 = tp.tm_mon;
v11 = tp.tm_mday;
v12 = tp.tm_year + 1900;
v13 = tp.tm_mon + 1;
if ( tp.tm_hour > a1 || (v14 = tp.tm_mday, tp.tm_hour == a1) && tp.tm_min > a2 )
{
v14 = tp.tm_mday + 1;
if ( tp.tm_mday + 1 <= (unsigned int)(unsigned __int8)MDays[tp.tm_mon] )
{
v11 = tp.tm_mday + 1;
}
else
{
v13 = tp.tm_mon + 2;
if ( (unsigned int)(tp.tm_mon + 2) <= 0xC )
{
v10 = tp.tm_mon + 1;
v11 = 1;
v14 = 1;
}
else
{
v12 = tp.tm_year + 1901;
v11 = 1;
v10 = 0;
v14 = 1;
v13 = 1;
}
}
}
if ( a4 )
*a4 = v14;
if ( a3 )
*a3 = v13;
if ( a5 )
*a5 = v12;
v20.tm_hour = a1;
v20.tm_min = a2;
v20.tm_mon = v10;
v20.tm_mday = v11;
v20.tm_year = v12 - 1900;
v15 = mktime(&v20);
RetVal_0 = (v15 - timer) / 60;
v16 = (v15 - timer) % 60;
result = &RetVal_0;
dword_12B4 = v16;
return result;
}

canonical_decompiled_code:
int *__fastcall func2(unsigned int a1, unsigned int a2, int *a3, int *a4, int *a5)
{
int v10; // ecx
int v11; // edx
int v12; // eax
int v13; // edi
int v14; // esi
time_t v15; // rax
time_t v16; // rcx
int *result; // rax
time_t timer; // [rsp+8h] [rbp-B0h] BYREF
struct tm tp; // [rsp+10h] [rbp-A8h] BYREF
struct tm v20; // [rsp+50h] [rbp-68h] BYREF

timer = 0LL;
time(&timer);
localtime_r(&timer, &tp);
v10 = tp.tm_mon;
v11 = tp.tm_mday;
v12 = tp.tm_year + 1900;
v13 = tp.tm_mon + 1;
if ( tp.tm_hour > a1 || (v14 = tp.tm_mday, tp.tm_hour == a1) && tp.tm_min > a2 )
{
v14 = tp.tm_mday + 1;
if ( tp.tm_mday + 1 <= (unsigned int)(unsigned __int8)MDays[tp.tm_mon] )
{
v11 = tp.tm_mday + 1;
}
else
{
v13 = tp.tm_mon + 2;
if ( (unsigned int)(tp.tm_mon + 2) <= 0xC )
{
v10 = tp.tm_mon + 1;
v11 = 1;
v14 = 1;
}
else
{
v12 = tp.tm_year + 1901;
v11 = 1;
v10 = 0;
v14 = 1;
v13 = 1;
}
}
}
if ( a4 )
*a4 = v14;
if ( a3 )
*a3 = v13;
if ( a5 )
*a5 = v12;
v20.tm_hour = a1;
v20.tm_min = a2;
v20.tm_mon = v10;
v20.tm_mday = v11;
v20.tm_year = v12 - 1900;
v15 = mktime(&v20);
RetVal_0 = (v15 - timer) / 60;
v16 = (v15 - timer) % 60;
result = &RetVal_0;
dword_12B4 = v16;
return result;
}

original_code:
unsigned *DateDiff(unsigned InHr, unsigned InMin, unsigned *OutMonth,
      unsigned *OutDay, unsigned *OutYear)
{
 struct tm TimeStruct, TS2;
 time_t CoreClock = 0, Clock2 = 0;
 unsigned Hr, Min, Month, Day, Year;
 static unsigned RetVal[2];
 time(&CoreClock);
 localtime_r(&CoreClock, &TimeStruct);
 Hr = TimeStruct.tm_hour;
 Min = TimeStruct.tm_min;
 Month = TimeStruct.tm_mon + 1;
 Day = TimeStruct.tm_mday;
 Year = TimeStruct.tm_year + 1900;
 if (InHr < Hr || (InHr == Hr && InMin < Min))
 {
  if (Day + 1 > MDays[Month - 1])
  {
   Day = 1;
   if (Month + 1 > 12)
   {
    Month = 1;
    ++Year;
   }
   else
   {
    ++Month;
   }
  }
  else
  {
   ++Day;
  }
 }
 if (OutDay) *OutDay = Day;
 if (OutMonth) *OutMonth = Month;
 if (OutYear) *OutYear = Year;
 TS2.tm_hour = InHr;
 TS2.tm_min = InMin;
 TS2.tm_mon = Month - 1;
 TS2.tm_mday = Day;
 TS2.tm_year = Year - 1900;
 Clock2 = mktime(&TS2);
 RetVal[0] = (Clock2 - CoreClock) / 60;
 RetVal[1] = (Clock2 - CoreClock) % 60;
 return RetVal;
}

canonical_original_code:
unsigned int *DateDiff(unsigned int InHr, unsigned int InMin, unsigned int *OutMonth, unsigned int *OutDay, unsigned int *OutYear)
{
 struct tm TimeStruct; struct tm TS2;
 long CoreClock = 0; long Clock2 = 0;
 unsigned int Hr; unsigned int Min; unsigned int Month; unsigned int Day; unsigned int Year;
 static unsigned int RetVal[2];
 time(&CoreClock);
 localtime_r(&CoreClock, &TimeStruct);
 Hr = TimeStruct.tm_hour;
 Min = TimeStruct.tm_min;
 Month = TimeStruct.tm_mon + 1;
 Day = TimeStruct.tm_mday;
 Year = TimeStruct.tm_year + 1900;
 if (InHr < Hr || (InHr == Hr && InMin < Min))
 {
  if (Day + 1 > MDays[Month - 1])
  {
   Day = 1;
   if (Month + 1 > 12)
   {
    Month = 1;
    ++Year;
   }
   else
   {
    ++Month;
   }
  }
  else
  {
   ++Day;
  }
 }
 if (OutDay) *OutDay = Day;
 if (OutMonth) *OutMonth = Month;
 if (OutYear) *OutYear = Year;
 TS2.tm_hour = InHr;
 TS2.tm_min = InMin;
 TS2.tm_mon = Month - 1;
 TS2.tm_mday = Day;
 TS2.tm_year = Year - 1900;
 Clock2 = mktime(&TS2);
 RetVal[0] = (Clock2 - CoreClock) / 60;
 RetVal[1] = (Clock2 - CoreClock) % 60;
 return RetVal;
}

variable_types:
InHr
unsigned int

variable_types:
InMin
unsigned int

variable_types:
OutMonth
unsigned int *

variable_types:
OutDay
unsigned int *

variable_types:
OutYear
unsigned int *

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

variable_types: CoreClock long

variable_types:
Hr
unsigned int

variable_types:
Min
unsigned int

variable_types:
Month
unsigned int

variable_types:
Day
unsigned int

variable_types:
Year
unsigned int

variable_types:
RetVal
unsigned int [2]

return_type: unsigned int *