original_code:
static void setup_cmdline_tag (char *cmdline)
{
 u32 len;
 const char *mtdprefix[] = { "root=/dev/mtdblock", "root=ubi0:rootfs"};
 char *o, *m, *s, *rest;
 int nr, i, j, p, digits;
 unsigned int val;
 for (p = 0; p < sizeof(mtdprefix)/sizeof(mtdprefix[0]); p++) {
  m = strstr(cmdline, mtdprefix[p]);
  if (m)
   break;
 }
 if (!m)
  goto normal_copy;
 ((*(volatile reg32_t *) ((0x80000000 + 0x0005C000) + 0x00000008)) = (0x80000000 | 0x40000000));
 while (((*(volatile hw_rtc_stat_t *) ((0x80000000 + 0x0005C000) + 0x00000010)).U) & (((0x1 << 1) << 16) & 0x00FF0000))
  ;
 val = ((*(volatile hw_rtc_persistent1_t *) ((0x80000000 + 0x0005C000) + 0x00000070)).U);
 if ((val & 0x00000002) == 0)
  goto normal_copy;
 o = params->u.cmdline.cmdline;
 m += strlen(mtdprefix[p]);
 memcpy(o, cmdline, m - cmdline);
 o += m - cmdline;
 s = m;
 while (*s && *s >= '0' && *s <= '9')
  s++;
 rest = s;
 s--;
 nr = 0;
 while (s >= m) {
  nr = nr * 10 + (*s - '0');
  s--;
 }
 nr++;
 digits = 0;
 i = nr;
 while (i > 0) {
  digits++;
  i /= 10;
 }
 i = nr;
 j = digits;
 while (j > 0) {
  o[j - 1] = '0' + (i % 10);
  i /= 10;
  j--;
 }
 o += digits;
 strcpy(o, rest);
 goto done_copy;
normal_copy:
 strcpy(params->u.cmdline.cmdline, cmdline);
done_copy:
 len = strlen(params->u.cmdline.cmdline) + 1;
 params->hdr.tag = 0x54410009;
 params->hdr.size = (sizeof(struct tag_header) + len + 4) >> 2;
 params = ((struct tag *)((u32 *)(params) + (params)->hdr.size));
}

canonical_original_code:
static void setup_cmdline_tag(char *cmdline)
{
 unsigned int len;
 char *mtdprefix[] = { "root=/dev/mtdblock", "root=ubi0:rootfs"};
 char *o; char *m; char *s; char *rest;
 int nr; int i; int j; int p; int digits;
 unsigned int val;
 for (p = 0; p < sizeof(mtdprefix)/sizeof(mtdprefix[0]); p++) {
  m = strstr(cmdline, mtdprefix[p]);
  if (m)
   break;
 }
 if (!m)
  goto normal_copy;
 ((*(unsigned int *) ((0x80000000 + 0x0005C000) + 0x00000008)) = (0x80000000 | 0x40000000));
 while (((*(union hw_rtc_stat_t *) ((0x80000000 + 0x0005C000) + 0x00000010)).U) & (((0x1 << 1) << 16) & 0x00FF0000))
  ;
 val = ((*(union hw_rtc_persistent1_t *) ((0x80000000 + 0x0005C000) + 0x00000070)).U);
 if ((val & 0x00000002) == 0)
  goto normal_copy;
 o = params->u.cmdline.cmdline;
 m += strlen(mtdprefix[p]);
 memcpy(o, cmdline, m - cmdline);
 o += m - cmdline;
 s = m;
 while (*s && *s >= '0' && *s <= '9')
  s++;
 rest = s;
 s--;
 nr = 0;
 while (s >= m) {
  nr = nr * 10 + (*s - '0');
  s--;
 }
 nr++;
 digits = 0;
 i = nr;
 while (i > 0) {
  digits++;
  i /= 10;
 }
 i = nr;
 j = digits;
 while (j > 0) {
  o[j - 1] = '0' + (i % 10);
  i /= 10;
  j--;
 }
 o += digits;
 strcpy(o, rest);
 goto done_copy;
normal_copy:
 strcpy(params->u.cmdline.cmdline, cmdline);
done_copy:
 len = strlen(params->u.cmdline.cmdline) + 1;
 params->hdr.tag = 0x54410009;
 params->hdr.size = (sizeof(struct tag_header) + len + 4) >> 2;
 params = ((struct tag *)((unsigned int *)(params) + (params)->hdr.size));
}

variable_types:
cmdline
char *

variable_types:
len
unsigned int

variable_types:
mtdprefix
char *[]

variable_types:
o
char *

variable_types:
m
char *

variable_types:
s
char *

variable_types:
rest
char *

variable_types: nr int

variable_types: i int

variable_types: j int

variable_types: p int

variable_types: digits int

variable_types:
val
unsigned int

user_defined_types: union hw_rtc_stat_t { unsigned int U; struct { unsigned char RSVD0; unsigned char NEW_REGS; unsigned char STALE_REGS; unsigned int RSVD1; unsigned int XTAL32768_PRESENT; unsigned int XTAL32000_PRESENT; unsigned int WATCHDOG_PRESENT; unsigned int ALARM_PRESENT; unsigned int RTC_PRESENT; } B; }

user_defined_types: union hw_rtc_persistent1_t { unsigned int U; struct { unsigned int GENERAL; } B; }


repo: RobertCNelson/imx-bootlets

decompiled_code:
_DWORD *setup_end_tag()
{
_DWORD *result; // rax

result = (_DWORD *)params;
*(_DWORD *)(params + 4) = 0;
*result = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func12()
{
_DWORD *result; // rax

result = (_DWORD *)params;
*(_DWORD *)(params + 4) = 0;
*result = 0;
return result;
}

original_code:
static void setup_end_tag (void)
{
 params->hdr.tag = 0x00000000;
 params->hdr.size = 0;
}

canonical_original_code:
static void setup_end_tag()
{
 params->hdr.tag = 0x00000000;
 params->hdr.size = 0;
}

return_type: void


decompiled_code:
__int64 get_magic_key()
{
int v0; // eax
unsigned int v1; // edx

v0 = get_pressed_keys();
if ( v0 == magic_keys[1] )
return 1;
if ( v0 == magic_keys[2] )
return 2;
v1 = 0;
if ( magic_keys[3] == v0 )
v1 = 3;
return v1;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // eax
unsigned int v1; // edx

v0 = get_pressed_keys();
if ( v0 == magic_keys[1] )
return 1;
if ( v0 == magic_keys[2] )
return 2;
v1 = 0;
if ( magic_keys[3] == v0 )
v1 = 3;
return v1;
}

original_code:
static enum magic_key get_magic_key (void)
{
 u32 keys;
 int magic;
 keys = get_pressed_keys();
 for (magic = MAGIC_KEY1; magic < MAGIC_KEY_NR; magic++)
  if (magic_keys[magic] == keys)
   return magic;
 return NO_MAGIC_KEY;
}

canonical_original_code:
static enum magic_key get_magic_key()
{
 unsigned int keys;
 int magic;
 keys = get_pressed_keys();
 for (magic = MAGIC_KEY1; magic < MAGIC_KEY_NR; magic++)
  if (magic_keys[magic] == keys)
   return magic;
 return NO_MAGIC_KEY;
}

variable_types:
keys
unsigned int

variable_types: magic int

return_type: enum magic_key { NO_MAGIC_KEY=0, MAGIC_KEY1=1, MAGIC_KEY2=2, MAGIC_KEY3=3, MAGIC_KEY_NR=4 }


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

v0 = get_magic_key();
find_command_lines();
setup_start_tag();
setup_mem_tag();
setup_initrd_tag();
setup_cmdline_tag((char *)cmdlines[v0]);
setup_end_tag();
return 1073742080LL;
}

original_code:
u32 setup_tags (void)
{
 enum magic_key magic_key;
 magic_key = get_magic_key();
 find_command_lines();
 setup_start_tag();
 setup_mem_tag();
 setup_initrd_tag();
 setup_cmdline_tag(cmdlines[magic_key]);
 setup_end_tag();
 return (u32)(0x40000000 + 0x100);
}

canonical_original_code:
unsigned int setup_tags()
{
 enum magic_key magic_key;
 magic_key = get_magic_key();
 find_command_lines();
 setup_start_tag();
 setup_mem_tag();
 setup_initrd_tag();
 setup_cmdline_tag(cmdlines[magic_key]);
 setup_end_tag();
 return (u32)(0x40000000 + 0x100);
}

variable_types: enum magic_key { NO_MAGIC_KEY=0, MAGIC_KEY1=1, MAGIC_KEY2=2, MAGIC_KEY3=3, MAGIC_KEY_NR=4 }

return_type: unsigned int


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

result = a1;
MEMORY[0x80050004] = a1;
return result;
}

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

result = a1;
MEMORY[0x80050004] = a1;
return result;
}

canonical_original_code: static inline void HW_LRADC_CTRL0_SET(unsigned int v) { ((*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000000 + 0x04)) = (v)); }

variable_types:
v
unsigned int


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

result = a1;
MEMORY[0x80050008] = a1;
return result;
}

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

result = a1;
MEMORY[0x80050008] = a1;
return result;
}

canonical_original_code: static inline void HW_LRADC_CTRL0_CLR(unsigned int v) { ((*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000000 + 0x08)) = (v)); }


decompiled_code:
__int64 HW_LRADC_CTRL1_RD()
{
return MEMORY[0x80050010];
}

canonical_original_code: static inline unsigned int HW_LRADC_CTRL1_RD() { return (*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000010)); }


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

result = a1;
MEMORY[0x80050018] = a1;
return result;
}

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

result = a1;
MEMORY[0x80050018] = a1;
return result;
}

canonical_original_code: static inline void HW_LRADC_CTRL1_CLR(unsigned int v) { ((*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000010 + 0x08)) = (v)); }


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

result = a1;
MEMORY[0x80050024] = a1;
return result;
}

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

result = a1;
MEMORY[0x80050024] = a1;
return result;
}

canonical_original_code: static inline void HW_LRADC_CTRL2_SET(unsigned int v) { ((*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000020 + 0x04)) = (v)); }


decompiled_code:
__int64 __fastcall HW_LRADC_CHn_RD(int a1)
{
return *(unsigned int *)(unsigned int)(16 * a1 - 2147155888);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return *(unsigned int *)(unsigned int)(16 * a1 - 2147155888);
}

canonical_original_code: static inline unsigned int HW_LRADC_CHn_RD(int n) { return (*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000050 + n * 0x10)); }

variable_types: n int


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

result = a1;
MEMORY[0x80050144] = a1;
return result;
}

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

result = a1;
MEMORY[0x80050144] = a1;
return result;
}

canonical_original_code: static inline void HW_LRADC_CTRL4_SET(unsigned int v) { ((*(unsigned int *)((0x80000000 + 0x00050000) + 0x00000140 + 0x04)) = (v)); }


decompiled_code:
__int64 get_no_keys()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static u32 get_no_keys (void)
{
 return 0;
}

canonical_original_code:
static unsigned int get_no_keys()
{
 return 0;
}


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

v0 = (*((__int64 (**)(void))keys_drivers + 1))();
return v0 | (*((unsigned int (**)(void))off_38 + 1))();
}

original_code:
u32 get_pressed_keys(void)
{
 int drv;
 u32 keys = 0;
 for (drv = KEYS_DRV_LRADC; drv < KEYS_DRV_NR; drv++)
  keys |= keys_drivers[drv]->get_keys();
 return keys;
}

canonical_original_code:
unsigned int get_pressed_keys()
{
 int drv;
 unsigned int keys = 0;
 for (drv = KEYS_DRV_LRADC; drv < KEYS_DRV_NR; drv++)
  keys |= keys_drivers[drv]->get_keys();
 return keys;
}

variable_types: drv int


decompiled_code:
__int64 __fastcall set_keys_driver(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
*(&keys_drivers + result) = a1;
return result;
}

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

result = *a1;
*(&keys_drivers + result) = a1;
return result;
}

original_code:
void set_keys_driver (struct keys_driver *driver)
{
 keys_drivers[driver->id] = driver;
}

canonical_original_code:
void set_keys_driver(struct keys_driver *driver)
{
 keys_drivers[driver->id] = driver;
}

variable_types: struct keys_driver { enum keys_driver_id { KEYS_DRV_LRADC=0, KEYS_DRV_GPIO=1, KEYS_DRV_NR=2, KEYS_DRV_DEFAULT=3 } id; unsigned int (*get_keys)(); } *

user_defined_types: struct keys_driver { enum keys_driver_id id; unsigned int (*get_keys)(); }


repo: RobertGBryan/TinyMTCPP

original_code:
void tinymt32_init(tinymt32_t * random, uint32_t seed) {
    random->status[0] = seed;
    random->status[1] = random->mat1;
    random->status[2] = random->mat2;
    random->status[3] = random->tmat;
    for (int i = 1; i < 8; i++) {
 random->status[i & 3] ^= i + 1812433253U
     * (random->status[(i - 1) & 3]
        ^ (random->status[(i - 1) & 3] >> 30));
    }
    period_certification(random);
    for (int i = 0; i < 8; i++) {
 tinymt32_next_state(random);
    }
}

canonical_original_code:
void tinymt32_init(struct TINYMT32_T *random, unsigned int seed) {
    random->status[0] = seed;
    random->status[1] = random->mat1;
    random->status[2] = random->mat2;
    random->status[3] = random->tmat;
    for (int i = 1; i < 8; i++) {
 random->status[i & 3] ^= i + 1812433253U
     * (random->status[(i - 1) & 3]
        ^ (random->status[(i - 1) & 3] >> 30));
    }
    period_certification(random);
    for (int i = 0; i < 8; i++) {
 tinymt32_next_state(random);
    }
}

variable_types: struct TINYMT32_T { unsigned int status[4]; unsigned int mat1; unsigned int mat2; unsigned int tmat; } *

variable_types:
seed
unsigned int


original_code:
void tinymt32_init_by_array(tinymt32_t * random, uint32_t init_key[],
       int key_length) {
    const int lag = 1;
    const int mid = 1;
    const int size = 4;
    int i, j;
    int count;
    uint32_t r;
    uint32_t * st = &random->status[0];
    st[0] = 0;
    st[1] = random->mat1;
    st[2] = random->mat2;
    st[3] = random->tmat;
    if (key_length + 1 > 8) {
 count = key_length + 1;
    } else {
 count = 8;
    }
    r = ini_func1(st[0] ^ st[mid % size]
    ^ st[(size - 1) % size]);
    st[mid % size] += r;
    r += key_length;
    st[(mid + lag) % size] += r;
    st[0] = r;
    count--;
    for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += init_key[j] + i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (; j < count; j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (j = 0; j < size; j++) {
 r = ini_func2(st[i] + st[(i + mid) % size] + st[(i + size - 1) % size]);
 st[(i + mid) % size] ^= r;
 r -= i;
 st[(i + mid + lag) % size] ^= r;
 st[i] = r;
 i = (i + 1) % size;
    }
    period_certification(random);
    for (i = 0; i < 8; i++) {
 tinymt32_next_state(random);
    }
}

canonical_original_code:
void tinymt32_init_by_array(struct TINYMT32_T *random, unsigned int init_key[], int key_length) {
    int lag = 1;
    int mid = 1;
    int size = 4;
    int i; int j;
    int count;
    unsigned int r;
    unsigned int *st = &random->status[0];
    st[0] = 0;
    st[1] = random->mat1;
    st[2] = random->mat2;
    st[3] = random->tmat;
    if (key_length + 1 > 8) {
 count = key_length + 1;
    } else {
 count = 8;
    }
    r = ini_func1(st[0] ^ st[mid % size]
    ^ st[(size - 1) % size]);
    st[mid % size] += r;
    r += key_length;
    st[(mid + lag) % size] += r;
    st[0] = r;
    count--;
    for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += init_key[j] + i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (; j < count; j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (j = 0; j < size; j++) {
 r = ini_func2(st[i] + st[(i + mid) % size] + st[(i + size - 1) % size]);
 st[(i + mid) % size] ^= r;
 r -= i;
 st[(i + mid + lag) % size] ^= r;
 st[i] = r;
 i = (i + 1) % size;
    }
    period_certification(random);
    for (i = 0; i < 8; i++) {
 tinymt32_next_state(random);
    }
}

variable_types: lag int

variable_types: mid int

variable_types: size int

variable_types: count int

variable_types:
r
unsigned int

variable_types:
st
unsigned int *

user_defined_types: struct TINYMT32_T { unsigned int status[4]; unsigned int mat1; unsigned int mat2; unsigned int tmat; }


decompiled_code:
__int64 __fastcall ini_func1(unsigned int a1)
{
return 1664525 * (a1 ^ (a1 >> 27));
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1)
{
return 1664525 * (a1 ^ (a1 >> 27));
}

original_code:
static uint32_t ini_func1(uint32_t x) {
    return (x ^ (x >> 27)) * (uint32_t)1664525UL;
}

canonical_original_code:
static unsigned int ini_func1(unsigned int x) {
    return (x ^ (x >> 27)) * (unsigned int)1664525UL;
}

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall ini_func2(unsigned int a1)
{
return 1566083941 * (a1 ^ (a1 >> 27));
}

original_code:
static uint32_t ini_func2(uint32_t x) {
    return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
}

canonical_original_code:
static unsigned int ini_func2(unsigned int x) {
    return (x ^ (x >> 27)) * (unsigned int)1566083941UL;
}


original_code:
static void period_certification(tinymt32_t * random) {
    if ((random->status[0] & 0x7fffffffU) == 0 &&
 random->status[1] == 0 &&
 random->status[2] == 0 &&
 random->status[3] == 0) {
 random->status[0] = 'T';
 random->status[1] = 'I';
 random->status[2] = 'N';
 random->status[3] = 'Y';
    }
}

canonical_original_code:
static void period_certification(struct TINYMT32_T *random) {
    if ((random->status[0] & 0x7fffffffU) == 0 &&
 random->status[1] == 0 &&
 random->status[2] == 0 &&
 random->status[3] == 0) {
 random->status[0] = 'T';
 random->status[1] = 'I';
 random->status[2] = 'N';
 random->status[3] = 'Y';
    }
}


original_code:
void tinymt64_init(tinymt64_t * random, uint64_t seed) {
    random->status[0] = seed ^ ((uint64_t)random->mat1 << 32);
    random->status[1] = random->mat2 ^ random->tmat;
    for (int i = 1; i < 8; i++) {
 random->status[i & 1] ^= i + 6364136223846793005UL
     * (random->status[(i - 1) & 1]
        ^ (random->status[(i - 1) & 1] >> 62));
    }
    period_certification(random);
}

canonical_original_code:
void tinymt64_init(struct TINYMT64_T *random, unsigned long seed) {
    random->status[0] = seed ^ ((unsigned long)random->mat1 << 32);
    random->status[1] = random->mat2 ^ random->tmat;
    for (int i = 1; i < 8; i++) {
 random->status[i & 1] ^= i + 6364136223846793005UL
     * (random->status[(i - 1) & 1]
        ^ (random->status[(i - 1) & 1] >> 62));
    }
    period_certification(random);
}

variable_types: struct TINYMT64_T { unsigned long status[2]; unsigned int mat1; unsigned int mat2; unsigned long tmat; } *

variable_types:
seed
unsigned long

variable_types: i int


original_code:
void tinymt64_init_by_array(tinymt64_t * random, const uint64_t init_key[],
       int key_length) {
    const int lag = 1;
    const int mid = 1;
    const int size = 4;
    int i, j;
    int count;
    uint64_t r;
    uint64_t st[4];
    st[0] = 0;
    st[1] = random->mat1;
    st[2] = random->mat2;
    st[3] = random->tmat;
    if (key_length + 1 > 8) {
 count = key_length + 1;
    } else {
 count = 8;
    }
    r = ini_func1(st[0] ^ st[mid % size]
    ^ st[(size - 1) % size]);
    st[mid % size] += r;
    r += key_length;
    st[(mid + lag) % size] += r;
    st[0] = r;
    count--;
    for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += init_key[j] + i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (; j < count; j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (j = 0; j < size; j++) {
 r = ini_func2(st[i] + st[(i + mid) % size] + st[(i + size - 1) % size]);
 st[(i + mid) % size] ^= r;
 r -= i;
 st[(i + mid + lag) % size] ^= r;
 st[i] = r;
 i = (i + 1) % size;
    }
    random->status[0] = st[0] ^ st[1];
    random->status[1] = st[2] ^ st[3];
    period_certification(random);
}

canonical_original_code:
void tinymt64_init_by_array(struct TINYMT64_T *random, unsigned long init_key[], int key_length) {
    int lag = 1;
    int mid = 1;
    int size = 4;
    int i; int j;
    int count;
    unsigned long r;
    unsigned long st[4];
    st[0] = 0;
    st[1] = random->mat1;
    st[2] = random->mat2;
    st[3] = random->tmat;
    if (key_length + 1 > 8) {
 count = key_length + 1;
    } else {
 count = 8;
    }
    r = ini_func1(st[0] ^ st[mid % size]
    ^ st[(size - 1) % size]);
    st[mid % size] += r;
    r += key_length;
    st[(mid + lag) % size] += r;
    st[0] = r;
    count--;
    for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += init_key[j] + i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (; j < count; j++) {
 r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
 st[(i + mid) % size] += r;
 r += i;
 st[(i + mid + lag) % size] += r;
 st[i] = r;
 i = (i + 1) % size;
    }
    for (j = 0; j < size; j++) {
 r = ini_func2(st[i] + st[(i + mid) % size] + st[(i + size - 1) % size]);
 st[(i + mid) % size] ^= r;
 r -= i;
 st[(i + mid + lag) % size] ^= r;
 st[i] = r;
 i = (i + 1) % size;
    }
    random->status[0] = st[0] ^ st[1];
    random->status[1] = st[2] ^ st[3];
    period_certification(random);
}

variable_types: j int

variable_types:
r
unsigned long

variable_types:
st
unsigned long [4]

user_defined_types: struct TINYMT64_T { unsigned long status[2]; unsigned int mat1; unsigned int mat2; unsigned long tmat; }


decompiled_code:
__int64 __fastcall ini_func1(unsigned __int64 a1)
{
return 0x1FA0259B019LL * (a1 ^ (a1 >> 59));
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int64 a1)
{
return 0x1FA0259B019LL * (a1 ^ (a1 >> 59));
}

canonical_original_code:
static unsigned long ini_func1(unsigned long x) {
    return (x ^ (x >> 59)) * 2173292883993UL;
}

variable_types:
x
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall ini_func2(unsigned __int64 a1)
{
return 0xD1341C13E2FAB1LL * (a1 ^ (a1 >> 59));
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned __int64 a1)
{
return 0xD1341C13E2FAB1LL * (a1 ^ (a1 >> 59));
}

canonical_original_code:
static unsigned long ini_func2(unsigned long x) {
    return (x ^ (x >> 59)) * 58885565329898161UL;
}


decompiled_code:
__int64 __fastcall period_certification(_QWORD *a1)
{
__int64 result; // rax

result = *a1 & 0x7FFFFFFFFFFFFFFFLL;
if ( !result && !a1[1] )
{
*a1 = 84LL;
a1[1] = 77LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1)
{
__int64 result; // rax

result = *a1 & 0x7FFFFFFFFFFFFFFFLL;
if ( !result && !a1[1] )
{
*a1 = 84LL;
a1[1] = 77LL;
}
return result;
}

original_code:
static void period_certification(tinymt64_t * random) {
    if ((random->status[0] & 0x7fffffffffffffffUL) == 0 &&
 random->status[1] == 0) {
 random->status[0] = 'T';
 random->status[1] = 'M';
    }
}

canonical_original_code:
static void period_certification(struct TINYMT64_T *random) {
    if ((random->status[0] & 0x7fffffffffffffffUL) == 0 &&
 random->status[1] == 0) {
 random->status[0] = 'T';
 random->status[1] = 'M';
    }
}


repo: RobertMe/linux-hid-lg-extended

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

result = 0LL;
if ( a2 > 0 )
result = *(unsigned __int8 *)(a1 + a2 - 1);
if ( a2 > 1 )
result = (*(unsigned __int8 *)(a1 + a2 - 2) << 8) + (int)result;
if ( a2 > 2 )
result = (*(unsigned __int8 *)(a1 + a2 - 3) << 16) + (int)result;
return result;
}

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

result = 0LL;
if ( a2 > 0 )
result = *(unsigned __int8 *)(a1 + a2 - 1);
if ( a2 > 1 )
result = (*(unsigned __int8 *)(a1 + a2 - 2) << 8) + (int)result;
if ( a2 > 2 )
result = (*(unsigned __int8 *)(a1 + a2 - 3) << 16) + (int)result;
return result;
}

original_code:
int desc_data(__u8 *value, int data_size)
{
 int data = 0;
 if (data_size >= 1)
  data += value[data_size - 1];
 if (data_size >= 2)
  data += value[data_size - 2] << 8;
 if (data_size >= 3)
  data += value[data_size - 3] << 16;
 return data;
}

canonical_original_code:
int desc_data(unsigned char *value, int data_size)
{
 int data = 0;
 if (data_size >= 1)
  data += value[data_size - 1];
 if (data_size >= 2)
  data += value[data_size - 2] << 8;
 if (data_size >= 3)
  data += value[data_size - 3] << 16;
 return data;
}

variable_types:
value
unsigned char *

variable_types: data int

return_type: int


decompiled_code:
void *__fastcall add_report_id(int a1)
{
void *result; // rax

result = realloc(report_list, report_list_size + 1);
report_list = result;
*((_DWORD *)result + report_list_size++) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
void *result; // rax

result = realloc(report_list, report_list_size + 1);
report_list = result;
*((_DWORD *)result + report_list_size++) = a1;
return result;
}

original_code:
void add_report_id(int report_id)
{
 report_list = realloc(report_list, report_list_size+1);
 report_list[report_list_size] = report_id;
 report_list_size++;
}


original_code:
int fill_report_list(int fd)
{
 int i, res, desc_size, current_usage_page, data_size, data;
 struct hidraw_report_descriptor rpt_desc;
 res = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('H')) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &desc_size);
 if (res < 0)
  return 1;
 memset(&rpt_desc, 0x0, sizeof(rpt_desc));
 rpt_desc.size = desc_size;
 res = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('H')) << (0 +8)) | (((0x02)) << 0) | ((((sizeof(struct hidraw_report_descriptor)))) << ((0 +8)+8))), &rpt_desc);
 if (res < 0)
  return 1;
 report_list = ((void *)0);
 report_list_size = 0;
 for (i = 0; i < rpt_desc.size; i++) {
  data_size = rpt_desc.value[i] & 3;
  if ((rpt_desc.value[i] >> 2) == 1)
   current_usage_page = desc_data(
    &rpt_desc.value[i+1], data_size);
  else if ((rpt_desc.value[i] >> 2) == 33)
   if (current_usage_page == 0xFF) {
    add_report_id(desc_data(
     &rpt_desc.value[i+1], data_size));
   }
  i += data_size;
 }
 return 0;
}

canonical_original_code:
int fill_report_list(int fd)
{
 int i; int res; int desc_size; int current_usage_page; int data_size; int data;
 struct hidraw_report_descriptor rpt_desc;
 res = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('H')) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &desc_size);
 if (res < 0)
  return 1;
 memset(&rpt_desc, 0x0, sizeof(rpt_desc));
 rpt_desc.size = desc_size;
 res = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('H')) << (0 +8)) | (((0x02)) << 0) | ((((sizeof(struct hidraw_report_descriptor)))) << ((0 +8)+8))), &rpt_desc);
 if (res < 0)
  return 1;
 report_list = ((void *)0);
 report_list_size = 0;
 for (i = 0; i < rpt_desc.size; i++) {
  data_size = rpt_desc.value[i] & 3;
  if ((rpt_desc.value[i] >> 2) == 1)
   current_usage_page = desc_data(
    &rpt_desc.value[i+1], data_size);
  else if ((rpt_desc.value[i] >> 2) == 33)
   if (current_usage_page == 0xFF) {
    add_report_id(desc_data(
     &rpt_desc.value[i+1], data_size));
   }
  i += data_size;
 }
 return 0;
}

variable_types: fd int

variable_types: res int

variable_types: struct hidraw_report_descriptor { unsigned int size; unsigned char value[4096]; }


decompiled_code:
__int64 __fastcall valid_report_id(unsigned __int8 a1)
{
_DWORD *v1; // rax

if ( report_list_size <= 0 )
return 0LL;
v1 = report_list;
while ( a1 != *v1 )
{
if ( ++v1 == (_DWORD *)((char *)report_list + 4 * (unsigned int)(report_list_size - 1) + 4) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
_DWORD *v1; // rax

if ( report_list_size <= 0 )
return 0LL;
v1 = report_list;
while ( a1 != *v1 )
{
if ( ++v1 == (_DWORD *)((char *)report_list + 4 * (unsigned int)(report_list_size - 1) + 4) )
return 0LL;
}
return 1LL;
}

original_code:
int valid_report_id(__u8 report_id)
{
 int i;
 for (i = 0; i < report_list_size; i++) {
  if (report_id == report_list[i])
   return 1;
 }
 return 0;
}

canonical_original_code:
int valid_report_id(unsigned char report_id)
{
 int i;
 for (i = 0; i < report_list_size; i++) {
  if (report_id == report_list[i])
   return 1;
 }
 return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int result; // eax
int v6; // ebp
const char *v7; // r13
size_t v8; // r14
size_t v9; // rbp
size_t v10; // rbx
int v11; // eax
bool v12; // dl
int v13; // ebx
unsigned __int8 *v14; // rbx
unsigned __int8 *v15; // rbp
struct timeval timeout; // [rsp+10h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-1B8h] BYREF
unsigned __int8 buf[312]; // [rsp+A0h] [rbp-138h] BYREF

v3 = open(argv[1], 2050, envp);
if ( v3 < 0 )
{
perror("Unable to open device");
result = 1;
}
else
{
v4 = v3;
if ( !(unsigned int)fill_report_list(v3) )
{
using_history();
while ( 1 )
{
v7 = (const char *)readline();
v8 = strlen(v7);
if ( !v8 )
goto LABEL_16;
if ( *v7 != 59 )
{
add_history();
v9 = 0LL;
do
{
v10 = (int)v9 / 3;
v11 = __isoc99_sscanf();
v12 = v8 > v9;
v9 += 3LL;
}
while ( v11 != 0 && v12 );
if ( (int)write(v4, buf, v10) < 0 )
perror("write");
LABEL_16:
v13 = 0;
while ( 1 )
{
if ( !v13 )
{
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
if ( !select(v4 + 1, &readfds, 0LL, 0LL, &timeout) )
break;
}
v6 = read(v4, buf, 0x2EuLL);
if ( v6 <= 0 )
break;
if ( (unsigned int)valid_report_id(buf[0]) )
{
printf("<< ");
v14 = buf;
v15 = &buf[v6 - 1 + 1];
do
printf("%02hhx ", (unsigned int)(char)*v14++);
while ( v14 != v15 );
puts("");
v13 = 1;
}
}
}
}
}
perror("Can't read report descriptor");
close(v4);
result = 2;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int result; // eax
int v6; // ebp
const char *v7; // r13
size_t v8; // r14
size_t v9; // rbp
size_t v10; // rbx
int v11; // eax
bool v12; // dl
int v13; // ebx
unsigned __int8 *v14; // rbx
unsigned __int8 *v15; // rbp
struct timeval timeout; // [rsp+10h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-1B8h] BYREF
unsigned __int8 buf[312]; // [rsp+A0h] [rbp-138h] BYREF

v3 = open(argv[1], 2050, envp);
if ( v3 < 0 )
{
perror("Unable to open device");
result = 1;
}
else
{
v4 = v3;
if ( !(unsigned int)func9(v3) )
{
using_history();
while ( 1 )
{
v7 = (const char *)readline();
v8 = strlen(v7);
if ( !v8 )
goto LABEL_16;
if ( *v7 != 59 )
{
add_history();
v9 = 0LL;
do
{
v10 = (int)v9 / 3;
v11 = __isoc99_sscanf();
v12 = v8 > v9;
v9 += 3LL;
}
while ( v11 != 0 && v12 );
if ( (int)write(v4, buf, v10) < 0 )
perror("write");
LABEL_16:
v13 = 0;
while ( 1 )
{
if ( !v13 )
{
timeout.tv_sec = 1LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
if ( !select(v4 + 1, &readfds, 0LL, 0LL, &timeout) )
break;
}
v6 = read(v4, buf, 0x2EuLL);
if ( v6 <= 0 )
break;
if ( (unsigned int)func10(buf[0]) )
{
printf("<< ");
v14 = buf;
v15 = &buf[v6 - 1 + 1];
do
printf("%02hhx ", (unsigned int)(char)*v14++);
while ( v14 != v15 );
puts("");
v13 = 1;
}
}
}
}
}
perror("Can't read report descriptor");
close(v4);
result = 2;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int fd, one_read;
 int i, res;
 char buf[256], *line;
 size_t length;
 fd_set fds;
 struct timeval timeout;
 fd = open(argv[1], 02|04000);
 if (fd < 0) {
  perror("Unable to open device");
  return 1;
 }
 if (fill_report_list(fd)) {
  perror("Can't read report descriptor");
  close(fd);
  return 2;
 }
 using_history();
 while(1) {
  line = readline(">> ");
  length = strlen(line);
  if(length > 0) {
   if(line[0] == ';') {
    continue;
   }
   add_history(line);
   for(i = 0; sscanf(line + i, "%hx", &buf[i / 3]) && i < length; i += 3);
   res = write(fd, buf, i/3);
   if (res < 0) {
    perror("write");
   }
  }
  one_read = 0;
  do {
   if(!one_read) {
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    if(select(fd+1, &fds, ((void *)0), ((void *)0), &timeout) == 0)
     break;
   }
   res = read(fd, buf, 46);
   if(res <= 0)
    continue;
   if(!valid_report_id(buf[0]))
    continue;
   one_read = 1;
   printf("<< ");
   for (i = 0; i < res; i++) {
    printf("%02hhx ", buf[i]);
   }
   puts("");
  }
  while(res > 0);
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd; int one_read;
 int i; int res;
 char buf[256]; char *line;
 unsigned long length;
 struct fd_set fds;
 struct timeval timeout;
 fd = open(argv[1], 02|04000);
 if (fd < 0) {
  perror("Unable to open device");
  return 1;
 }
 if (fill_report_list(fd)) {
  perror("Can't read report descriptor");
  close(fd);
  return 2;
 }
 using_history();
 while(1) {
  line = readline(">> ");
  length = strlen(line);
  if(length > 0) {
   if(line[0] == ';') {
    continue;
   }
   add_history(line);
   for(i = 0; sscanf(line + i, "%hx", &buf[i / 3]) && i < length; i += 3);
   res = write(fd, buf, i/3);
   if (res < 0) {
    perror("write");
   }
  }
  one_read = 0;
  do {
   if(!one_read) {
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    if(select(fd+1, &fds, ((void *)0), ((void *)0), &timeout) == 0)
     break;
   }
   res = read(fd, buf, 46);
   if(res <= 0)
    continue;
   if(!valid_report_id(buf[0]))
    continue;
   one_read = 1;
   printf("<< ");
   for (i = 0; i < res; i++) {
    printf("%02hhx ", buf[i]);
   }
   puts("");
  }
  while(res > 0);
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char [256]

variable_types:
line
char *

variable_types:
length
unsigned long

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

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


repo: RobinLiu/msg

decompiled_code:
void __fastcall get_time_str(char *s, int a2)
{
time_t timer; // [rsp+0h] [rbp-70h] BYREF
struct tm tp; // [rsp+8h] [rbp-68h] BYREF
struct timeval tv; // [rsp+48h] [rbp-28h] BYREF

if ( s && a2 > 0 )
{
timer = -1LL;
if ( !gettimeofday(&tv, 0LL) )
timer = tv.tv_sec;
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
localtime_r(&timer, &tp);
snprintf(
s,
a2,
"%04d-%02d-%02d %02d:%02d:%02d:%06d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
tv.tv_usec);
}
}

canonical_decompiled_code:
void __fastcall func0(char *s, int a2)
{
time_t timer; // [rsp+0h] [rbp-70h] BYREF
struct tm tp; // [rsp+8h] [rbp-68h] BYREF
struct timeval tv; // [rsp+48h] [rbp-28h] BYREF

if ( s && a2 > 0 )
{
timer = -1LL;
if ( !gettimeofday(&tv, 0LL) )
timer = tv.tv_sec;
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
localtime_r(&timer, &tp);
snprintf(
s,
a2,
"%04d-%02d-%02d %02d:%02d:%02d:%06d",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
tv.tv_usec);
}
}

original_code:
void get_time_str(int8* time_buf, int32 buf_len)
{
 if (((void *)0) == time_buf || buf_len <= 0)
 {
  return;
 }
 struct timeval tv;
 struct tm tm;
 time_t curtime = -1;
 int32 ret = gettimeofday(&tv, ((void *)0));
 if (0 == ret)
 {
  curtime = tv.tv_sec;
 }
 memset(&tm, 0, sizeof(struct tm));
 localtime_r(&curtime, &tm);
 snprintf((void*) time_buf, buf_len, "%04d-%02d-%02d %02d:%02d:%02d:%06d",
   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
   tm.tm_sec, (int) tv.tv_usec);
}

canonical_original_code:
void get_time_str(char *time_buf, int buf_len)
{
 if (((void *)0) == time_buf || buf_len <= 0)
 {
  return;
 }
 struct timeval tv;
 struct tm tm;
 long curtime = -1;
 int ret = gettimeofday(&tv, ((void *)0));
 if (0 == ret)
 {
  curtime = tv.tv_sec;
 }
 memset(&tm, 0, sizeof(struct tm));
 localtime_r(&curtime, &tm);
 snprintf((void *) time_buf, buf_len, "%04d-%02d-%02d %02d:%02d:%02d:%06d",
   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
   tm.tm_sec, (int) tv.tv_usec);
}

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: curtime long

variable_types: ret int

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


decompiled_code:
__int64 get_min_log_level()
{
return (unsigned __int8)g_min_log_level;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int8)g_min_log_level;
}

original_code:
int8 get_min_log_level(void)
{
 return g_min_log_level;
}

canonical_original_code:
char get_min_log_level()
{
 return g_min_log_level;
}

return_type: char


decompiled_code:
void __fastcall set_min_log_level(char a1)
{
g_min_log_level = a1;
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
g_min_log_level = a1;
}

original_code:
void set_min_log_level(int8 log_level)
{
 g_min_log_level = log_level;
}

canonical_original_code:
void set_min_log_level(char log_level)
{
 g_min_log_level = log_level;
}


decompiled_code:
char *__fastcall set_log_filter(char *src)
{
g_filter_log_flag = 1;
memset(g_log_filter, 0, sizeof(g_log_filter));
return strncpy(g_log_filter, src, 0xFFuLL);
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
g_filter_log_flag = 1;
memset(g_log_filter, 0, sizeof(g_log_filter));
return strncpy(g_log_filter, src, 0xFFuLL);
}

original_code:
void set_log_filter(char* log_filter)
{
 g_filter_log_flag = (bool)1;;
 memset(g_log_filter, 0, sizeof(g_log_filter));
 strncpy(g_log_filter, log_filter, (sizeof(g_log_filter) - 1));
 g_log_filter[256 - 1] = '\0';
}

canonical_original_code:
void set_log_filter(char *log_filter)
{
 g_filter_log_flag = (unsigned char)1;;
 memset(g_log_filter, 0, sizeof(g_log_filter));
 strncpy(g_log_filter, log_filter, (sizeof(g_log_filter) - 1));
 g_log_filter[256 - 1] = '\0';
}


decompiled_code:
void clear_log_filter()
{
g_filter_log_flag = 0;
}

canonical_decompiled_code:
void func4()
{
g_filter_log_flag = 0;
}

original_code:
void clear_log_filter()
{
 g_filter_log_flag = (bool)0;;
}

canonical_original_code:
void clear_log_filter()
{
 g_filter_log_flag = (unsigned char)0;;
}


repo: RoboNickBot/c-maze

decompiled_code:
__int64 __fastcall DR_new_position(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
struct DR_position DR_new_position ( int x, int y )
{
    struct DR_position pos;
    pos.x = x;
    pos.y = y;
    return pos;
}

canonical_original_code:
struct DR_position DR_new_position(int x, int y)
{
    struct DR_position pos;
    pos.x = x;
    pos.y = y;
    return pos;
}

variable_types: x int

variable_types: y int

variable_types:
pos
struct DR_position { int x; int y; }

return_type: struct DR_position { int x; int y; }


decompiled_code:
_BOOL8 __fastcall DR_equal_pos(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

original_code:
int DR_equal_pos ( struct DR_position a, struct DR_position b )
{
    return ( a.x == b.x && a.y == b.y );
}

canonical_original_code:
int DR_equal_pos(struct DR_position a, struct DR_position b)
{
    return ( a.x == b.x && a.y == b.y );
}

variable_types:
a
struct DR_position { int x; int y; }

variable_types:
b
struct DR_position


decompiled_code:
unsigned __int64 __fastcall DR_get_adj(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rax
unsigned __int64 v6; // rax
unsigned __int64 v7; // rax
unsigned __int64 v8; // rax
unsigned __int64 v9; // rax
unsigned __int64 v10; // rax
unsigned __int64 v11; // rax
unsigned __int64 v12; // rax

v2 = a1;
v3 = a2;
switch ( a2 )
{
case 0u:
v4 = DR_new_position(a1, (unsigned int)(HIDWORD(a1) - 1));
v2 = v4;
v3 = HIDWORD(v4);
break;
case 1u:
v6 = DR_new_position((int)a1 + 1, (unsigned int)(HIDWORD(a1) - 1));
v2 = v6;
v3 = HIDWORD(v6);
break;
case 2u:
v11 = DR_new_position((int)a1 + 1, HIDWORD(a1));
v2 = v11;
v3 = HIDWORD(v11);
break;
case 3u:
v9 = DR_new_position((int)a1 + 1, (unsigned int)(HIDWORD(a1) + 1));
v2 = v9;
v3 = HIDWORD(v9);
break;
case 4u:
v8 = DR_new_position(a1, (unsigned int)(HIDWORD(a1) + 1));
v2 = v8;
v3 = HIDWORD(v8);
break;
case 5u:
v10 = DR_new_position((int)a1 - 1, (unsigned int)(HIDWORD(a1) + 1));
v2 = v10;
v3 = HIDWORD(v10);
break;
case 6u:
v12 = DR_new_position((int)a1 - 1, HIDWORD(a1));
v2 = v12;
v3 = HIDWORD(v12);
break;
case 7u:
v7 = DR_new_position((int)a1 - 1, (unsigned int)(HIDWORD(a1) - 1));
v2 = v7;
v3 = HIDWORD(v7);
break;
default:
return v2 | (v3 << 32);
}
return v2 | (v3 << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rax
unsigned __int64 v6; // rax
unsigned __int64 v7; // rax
unsigned __int64 v8; // rax
unsigned __int64 v9; // rax
unsigned __int64 v10; // rax
unsigned __int64 v11; // rax
unsigned __int64 v12; // rax

v2 = a1;
v3 = a2;
switch ( a2 )
{
case 0u:
v4 = func0(a1, (unsigned int)(HIDWORD(a1) - 1));
v2 = v4;
v3 = HIDWORD(v4);
break;
case 1u:
v6 = func0((int)a1 + 1, (unsigned int)(HIDWORD(a1) - 1));
v2 = v6;
v3 = HIDWORD(v6);
break;
case 2u:
v11 = func0((int)a1 + 1, HIDWORD(a1));
v2 = v11;
v3 = HIDWORD(v11);
break;
case 3u:
v9 = func0((int)a1 + 1, (unsigned int)(HIDWORD(a1) + 1));
v2 = v9;
v3 = HIDWORD(v9);
break;
case 4u:
v8 = func0(a1, (unsigned int)(HIDWORD(a1) + 1));
v2 = v8;
v3 = HIDWORD(v8);
break;
case 5u:
v10 = func0((int)a1 - 1, (unsigned int)(HIDWORD(a1) + 1));
v2 = v10;
v3 = HIDWORD(v10);
break;
case 6u:
v12 = func0((int)a1 - 1, HIDWORD(a1));
v2 = v12;
v3 = HIDWORD(v12);
break;
case 7u:
v7 = func0((int)a1 - 1, (unsigned int)(HIDWORD(a1) - 1));
v2 = v7;
v3 = HIDWORD(v7);
break;
default:
return v2 | (v3 << 32);
}
return v2 | (v3 << 32);
}

original_code:
struct DR_position DR_get_adj ( struct DR_position this_pos, enum DR_direction dir )
{
    struct DR_position result;
    switch ( dir )
    {
        case NORTH:
            result = DR_new_position ( this_pos.x, this_pos.y-1 );
            break;
        case NORTHEAST:
            result = DR_new_position ( this_pos.x+1, this_pos.y-1 );
            break;
        case NORTHWEST:
            result = DR_new_position ( this_pos.x-1, this_pos.y-1 );
            break;
        case SOUTH:
            result = DR_new_position ( this_pos.x, this_pos.y+1 );
            break;
        case SOUTHEAST:
            result = DR_new_position ( this_pos.x+1, this_pos.y+1 );
            break;
        case SOUTHWEST:
            result = DR_new_position ( this_pos.x-1, this_pos.y+1 );
            break;
        case EAST:
            result = DR_new_position ( this_pos.x+1, this_pos.y );
            break;
        case WEST:
            result = DR_new_position ( this_pos.x-1, this_pos.y );
            break;
        default:
            result = this_pos;
            break;
    }
    return result;
}

canonical_original_code:
struct DR_position DR_get_adj(struct DR_position this_pos, enum DR_direction dir)
{
    struct DR_position result;
    switch ( dir )
    {
        case NORTH:
            result = DR_new_position ( this_pos.x, this_pos.y-1 );
            break;
        case NORTHEAST:
            result = DR_new_position ( this_pos.x+1, this_pos.y-1 );
            break;
        case NORTHWEST:
            result = DR_new_position ( this_pos.x-1, this_pos.y-1 );
            break;
        case SOUTH:
            result = DR_new_position ( this_pos.x, this_pos.y+1 );
            break;
        case SOUTHEAST:
            result = DR_new_position ( this_pos.x+1, this_pos.y+1 );
            break;
        case SOUTHWEST:
            result = DR_new_position ( this_pos.x-1, this_pos.y+1 );
            break;
        case EAST:
            result = DR_new_position ( this_pos.x+1, this_pos.y );
            break;
        case WEST:
            result = DR_new_position ( this_pos.x-1, this_pos.y );
            break;
        default:
            result = this_pos;
            break;
    }
    return result;
}

variable_types: enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 }

variable_types:
result
struct DR_position { int x; int y; }


decompiled_code:
__int64 __fastcall DR_new_direction(int a1)
{
int v1; // eax
__int64 result; // rax

while ( 1 )
{
result = (unsigned int)a1;
if ( (unsigned int)a1 <= 7 )
break;
v1 = a1 + 8;
if ( a1 >= 0 )
v1 = a1 - 8;
a1 = v1;
}
return result;
}

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

while ( 1 )
{
result = (unsigned int)a1;
if ( (unsigned int)a1 <= 7 )
break;
v1 = a1 + 8;
if ( a1 >= 0 )
v1 = a1 - 8;
a1 = v1;
}
return result;
}

original_code:
enum DR_direction DR_new_direction ( int value )
{
    while ( value < 0 || value >= FULL_CYCLE )
    {
        if ( value < 0 )
        {
            value += FULL_CYCLE;
        }
        if ( value >= FULL_CYCLE )
        {
            value -= FULL_CYCLE;
        }
    }
    return value;
}

canonical_original_code:
enum DR_direction DR_new_direction(int value)
{
    while ( value < 0 || value >= FULL_CYCLE )
    {
        if ( value < 0 )
        {
            value += FULL_CYCLE;
        }
        if ( value >= FULL_CYCLE )
        {
            value -= FULL_CYCLE;
        }
    }
    return value;
}

variable_types: value int

return_type: enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 }


decompiled_code:
__int64 __fastcall DR_get_rel(int a1, int a2)
{
return DR_new_direction(a2 + a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
return func3(a2 + a1);
}

original_code:
enum DR_direction DR_get_rel ( enum DR_direction this_dir, enum DR_orientation offset )
{
    enum DR_direction result;
    result = DR_new_direction ( this_dir + offset );
    return result;
}

canonical_original_code:
enum DR_direction DR_get_rel(enum DR_direction this_dir, enum DR_orientation offset)
{
    enum DR_direction result;
    result = DR_new_direction ( this_dir + offset );
    return result;
}

variable_types: enum DR_orientation { FRONT=0, FRONTRIGHT=1, RIGHT=2, BACKRIGHT=3, BACK=4, BACKLEFT=5, LEFT=6, FRONTLEFT=7 }

user_defined_types: enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 }


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

result = a1;
if ( a2 >= 0 )
result = get_path(*(_QWORD *)(a1 + 24), (unsigned int)(a2 - 1));
return result;
}

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

result = a1;
if ( a2 >= 0 )
result = func0(*(_QWORD *)(a1 + 24), (unsigned int)(a2 - 1));
return result;
}

original_code:
struct path_head *get_path ( struct path_head *last, int i )
{
    struct path_head *result;
    if ( i < 0 )
    {
        result = last;
    }
    else
    {
        result = get_path ( last->next, i-1 );
    }
    return result;
}

canonical_original_code:
struct path_head *get_path(struct path_head *last, int i)
{
    struct path_head *result;
    if ( i < 0 )
    {
        result = last;
    }
    else
    {
        result = get_path ( last->next, i-1 );
    }
    return result;
}

variable_types:
last
struct path_head *

variable_types: i int

variable_types: struct path_head { struct DR_position { int x; int y; } p; enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 } d; int g; int still_space; struct path_head *next; } *

user_defined_types: struct path_head { struct DR_position p; enum DR_direction d; int g; int still_space; struct path_head *next; }


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

result = *(_QWORD *)(a1 + 24);
if ( result )
return add_path(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 24);
if ( result )
return func1(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = a2;
return result;
}

original_code:
void add_path ( struct path_head *last, struct path_head *addition )
{
    if ( last->next == ((void *)0) )
    {
        last->next = addition;
    }
    else
    {
        add_path ( last->next, addition );
    }
}

canonical_original_code:
void add_path(struct path_head *last, struct path_head *addition)
{
    if ( last->next == ((void *)0) )
    {
        last->next = addition;
    }
    else
    {
        add_path ( last->next, addition );
    }
}

variable_types:
addition
struct path_head *


decompiled_code:
void __fastcall destroy_paths(_QWORD *a1)
{
if ( a1[3] )
destroy_paths();
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
if ( a1[3] )
func2();
free(a1);
}

original_code:
void destroy_paths ( struct path_head *last )
{
    if ( last->next != ((void *)0) )
    {
        destroy_paths ( last->next );
    }
    free ( last );
}

canonical_original_code:
void destroy_paths(struct path_head *last)
{
    if ( last->next != ((void *)0) )
    {
        destroy_paths ( last->next );
    }
    free ( last );
}


decompiled_code:
__int64 __fastcall check_space(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // er13
unsigned int v7; // er14
int v8; // er15
unsigned int v9; // eax
unsigned int v10; // eax
__int64 v11; // rax
unsigned __int64 v12; // [rsp+8h] [rbp-40h]

v4 = a3;
if ( (_DWORD)a3 )
{
if ( a2 - 1 != HIDWORD(a3) && a2 - 1 != (_DWORD)a3 && HIDWORD(a3) )
{
v7 = 0;
v8 = 1;
v12 = (unsigned __int64)HIDWORD(a3) << 32;
do
{
v9 = DR_get_rel(a4, 6LL);
v10 = DR_get_rel(v9, v7);
v11 = DR_get_adj(v12 | v4, v10);
if ( (unsigned int)get_tiletype(a1, a2, v11) )
v8 = 0;
++v7;
}
while ( v7 != 5 );
v4 = v8;
}
else
{
v4 = 0;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
unsigned int v4; // er13
unsigned int v7; // er14
int v8; // er15
unsigned int v9; // eax
unsigned int v10; // eax
__int64 v11; // rax
unsigned __int64 v12; // [rsp+8h] [rbp-40h]

v4 = a3;
if ( (_DWORD)a3 )
{
if ( a2 - 1 != HIDWORD(a3) && a2 - 1 != (_DWORD)a3 && HIDWORD(a3) )
{
v7 = 0;
v8 = 1;
v12 = (unsigned __int64)HIDWORD(a3) << 32;
do
{
v9 = DR_get_rel(a4, 6LL);
v10 = DR_get_rel(v9, v7);
v11 = DR_get_adj(v12 | v4, v10);
if ( (unsigned int)get_tiletype(a1, a2, v11) )
v8 = 0;
++v7;
}
while ( v7 != 5 );
v4 = v8;
}
else
{
v4 = 0;
}
}
return v4;
}

original_code:
int check_space ( struct mazetile *tiles, int size, struct DR_position pos, enum DR_direction d )
{
    int result = 1;
    int x;
    enum DR_direction check_dir;
    if ( pos.x == 0 || pos.x == size-1 || pos.y == 0 || pos.y == size-1 )
    {
        result = 0;
    }
    else
    {
        for ( x = 0; x < 5; x++ )
        {
            check_dir = DR_get_rel ( DR_get_rel ( d, LEFT ), x );
            if ( get_tiletype ( tiles, size, DR_get_adj ( pos, check_dir ) ) != WALL )
            {
                result = 0;
            }
        }
    }
    return result;
}

canonical_original_code:
int check_space(struct mazetile *tiles, int size, struct DR_position pos, enum DR_direction d)
{
    int result = 1;
    int x;
    enum DR_direction check_dir;
    if ( pos.x == 0 || pos.x == size-1 || pos.y == 0 || pos.y == size-1 )
    {
        result = 0;
    }
    else
    {
        for ( x = 0; x < 5; x++ )
        {
            check_dir = DR_get_rel ( DR_get_rel ( d, LEFT ), x );
            if ( get_tiletype ( tiles, size, DR_get_adj ( pos, check_dir ) ) != WALL )
            {
                result = 0;
            }
        }
    }
    return result;
}

variable_types: struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position { int x; int y; } p; } *

variable_types: size int

variable_types:
pos
struct DR_position

variable_types: result int

user_defined_types: struct mazetile { enum tiletype t; float light; struct DR_position p; }


decompiled_code:
_BOOL8 __fastcall check_all(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rax
int v7; // ebp
unsigned int v8; // er15
unsigned int v9; // eax
__int64 v10; // rax
unsigned int v11; // er15
unsigned int v12; // eax
__int64 v13; // rax
int v15; // [rsp+Ch] [rbp-3Ch]

v6 = DR_get_adj(a3, a4);
v7 = check_space(a1, a2, v6, a4);
v8 = DR_get_rel(a4, 6LL);
v9 = DR_get_rel(a4, 6LL);
v10 = DR_get_adj(a3, v9);
v15 = check_space(a1, a2, v10, v8);
v11 = DR_get_rel(a4, 2LL);
v12 = DR_get_rel(a4, 2LL);
v13 = DR_get_adj(a3, v12);
return ((unsigned int)check_space(a1, a2, v13, v11) | v15 | v7) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rax
int v7; // ebp
unsigned int v8; // er15
unsigned int v9; // eax
__int64 v10; // rax
unsigned int v11; // er15
unsigned int v12; // eax
__int64 v13; // rax
int v15; // [rsp+Ch] [rbp-3Ch]

v6 = DR_get_adj(a3, a4);
v7 = func3(a1, a2, v6, a4);
v8 = DR_get_rel(a4, 6LL);
v9 = DR_get_rel(a4, 6LL);
v10 = DR_get_adj(a3, v9);
v15 = func3(a1, a2, v10, v8);
v11 = DR_get_rel(a4, 2LL);
v12 = DR_get_rel(a4, 2LL);
v13 = DR_get_adj(a3, v12);
return ((unsigned int)func3(a1, a2, v13, v11) | v15 | v7) != 0;
}

original_code:
int check_all ( struct mazetile *tiles, int size, struct DR_position pos, enum DR_direction d )
{
    int result = 0;
    int f, l, r;
    f = check_space ( tiles, size, DR_get_adj ( pos, d ), d );
    l = check_space ( tiles, size, DR_get_adj ( pos, DR_get_rel ( d, LEFT ) ), DR_get_rel ( d, LEFT ) );
    r = check_space ( tiles, size, DR_get_adj ( pos, DR_get_rel ( d, RIGHT ) ), DR_get_rel ( d, RIGHT ) );
    if ( f || l || r )
    {
        result = 1;
    }
    return result;
}

canonical_original_code:
int check_all(struct mazetile *tiles, int size, struct DR_position pos, enum DR_direction d)
{
    int result = 0;
    int f; int l; int r;
    f = check_space ( tiles, size, DR_get_adj ( pos, d ), d );
    l = check_space ( tiles, size, DR_get_adj ( pos, DR_get_rel ( d, LEFT ) ), DR_get_rel ( d, LEFT ) );
    r = check_space ( tiles, size, DR_get_adj ( pos, DR_get_rel ( d, RIGHT ) ), DR_get_rel ( d, RIGHT ) );
    if ( f || l || r )
    {
        result = 1;
    }
    return result;
}

variable_types: f int

variable_types: l int

variable_types: r int


decompiled_code:
__int64 __fastcall try_move(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

result = check_space(a1, a2, a4, a5);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 16LL * (int)(HIDWORD(a4) + a4 * a2)) = 1;
*(_QWORD *)a3 = a4;
*(_DWORD *)(a3 + 8) = a5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

result = func3(a1, a2, a4, a5);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 16LL * (int)(HIDWORD(a4) + a4 * a2)) = 1;
*(_QWORD *)a3 = a4;
*(_DWORD *)(a3 + 8) = a5;
result = 1LL;
}
return result;
}

original_code:
int try_move ( struct mazetile *tiles, int size, struct path_head *last, struct DR_position try_pos, enum DR_direction dir )
{
    int result = 0;
    if ( check_space ( tiles, size, try_pos, dir ) )
    {
        tiles[try_pos.x * size + try_pos.y].t = SPACE;
        last->p = try_pos;
        last->d = dir;
        result = 1;
    }
    return result;
}

canonical_original_code:
int try_move(struct mazetile *tiles, int size, struct path_head *last, struct DR_position try_pos, enum DR_direction dir)
{
    int result = 0;
    if ( check_space ( tiles, size, try_pos, dir ) )
    {
        tiles[try_pos.x * size + try_pos.y].t = SPACE;
        last->p = try_pos;
        last->d = dir;
        result = 1;
    }
    return result;
}

variable_types: struct path_head { struct DR_position p; enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 } d; int g; int still_space; struct path_head *next; } *


decompiled_code:
__int64 __fastcall try_branch(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 a5, int a6)
{
int i; // ebx
int v9; // ebp
__int64 v10; // rax
__int64 result; // rax
_DWORD *v12; // rbp
__int64 v13; // rax
int v14; // eax
unsigned int v15; // er15
__int64 v16; // rax
int v17; // edx
int v18; // eax
int v19; // eax
__int64 v20; // rax
int v21; // eax
unsigned int v22; // er15
__int64 v23; // rax
int v24; // eax
int v25; // eax

for ( i = 1; ; ++i )
{
v17 = rand();
result = (unsigned int)(100 * (v17 / 100));
if ( a6 <= v17 % 100 )
goto LABEL_15;
v9 = rand() % 100;
if ( i == 1 )
{
if ( a4 == 2 )
{
v19 = DR_get_rel(*(unsigned int *)(a3 + 8), 6LL);
v12 = new_path(*(_QWORD *)a3, v19, v9);
}
else if ( a4 == 6 )
{
v18 = DR_get_rel(*(unsigned int *)(a3 + 8), 0LL);
v12 = new_path(*(_QWORD *)a3, v18, v9);
}
else
{
if ( a4 )
{
v13 = DR_get_adj(*(_QWORD *)count_paths, *(&loc_4 + 1));
if ( !(unsigned int)try_move(a1, a2, 0LL, v13, *(&loc_4 + 1)) )
continue;
v12 = 0LL;
goto LABEL_26;
}
v14 = DR_get_rel(*(unsigned int *)(a3 + 8), 2LL);
v12 = new_path(*(_QWORD *)a3, v14, v9);
}
v15 = v12[2];
v16 = DR_get_adj(*(_QWORD *)v12, v15);
if ( !(unsigned int)try_move(a1, a2, (__int64)v12, v16, v15) )
continue;
goto LABEL_26;
}
if ( i != 2 )
{
v10 = DR_get_adj(*(_QWORD *)count_paths, *(&loc_4 + 1));
result = try_move(a1, a2, 0LL, v10, *(&loc_4 + 1));
v12 = 0LL;
if ( !(_DWORD)result )
goto LABEL_15;
goto LABEL_26;
}
if ( a4 == 2 )
{
v25 = DR_get_rel(*(unsigned int *)(a3 + 8), 0LL);
v12 = new_path(*(_QWORD *)a3, v25, v9);
}
else if ( a4 == 6 )
{
v24 = DR_get_rel(*(unsigned int *)(a3 + 8), 2LL);
v12 = new_path(*(_QWORD *)a3, v24, v9);
}
else
{
if ( a4 )
{
v20 = DR_get_adj(*(_QWORD *)count_paths, *(&loc_4 + 1));
result = try_move(a1, a2, 0LL, v20, *(&loc_4 + 1));
if ( !(_DWORD)result )
return result;
v12 = 0LL;
goto LABEL_26;
}
v21 = DR_get_rel(*(unsigned int *)(a3 + 8), 6LL);
v12 = new_path(*(_QWORD *)a3, v21, v9);
}
v22 = v12[2];
v23 = DR_get_adj(*(_QWORD *)v12, v22);
result = try_move(a1, a2, (__int64)v12, v23, v22);
if ( !(_DWORD)result )
break;
LABEL_26:
result = add_path(a3, (__int64)v12);
LABEL_15:
if ( i > 1 )
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 a5, int a6)
{
int i; // ebx
int v9; // ebp
__int64 v10; // rax
__int64 result; // rax
_DWORD *v12; // rbp
__int64 v13; // rax
int v14; // eax
unsigned int v15; // er15
__int64 v16; // rax
int v17; // edx
int v18; // eax
int v19; // eax
__int64 v20; // rax
int v21; // eax
unsigned int v22; // er15
__int64 v23; // rax
int v24; // eax
int v25; // eax

for ( i = 1; ; ++i )
{
v17 = rand();
result = (unsigned int)(100 * (v17 / 100));
if ( a6 <= v17 % 100 )
goto LABEL_15;
v9 = rand() % 100;
if ( i == 1 )
{
if ( a4 == 2 )
{
v19 = DR_get_rel(*(unsigned int *)(a3 + 8), 6LL);
v12 = new_path(*(_QWORD *)a3, v19, v9);
}
else if ( a4 == 6 )
{
v18 = DR_get_rel(*(unsigned int *)(a3 + 8), 0LL);
v12 = new_path(*(_QWORD *)a3, v18, v9);
}
else
{
if ( a4 )
{
v13 = DR_get_adj(*(_QWORD *)count_paths, *(&loc_4 + 1));
if ( !(unsigned int)func5(a1, a2, 0LL, v13, *(&loc_4 + 1)) )
continue;
v12 = 0LL;
goto LABEL_26;
}
v14 = DR_get_rel(*(unsigned int *)(a3 + 8), 2LL);
v12 = new_path(*(_QWORD *)a3, v14, v9);
}
v15 = v12[2];
v16 = DR_get_adj(*(_QWORD *)v12, v15);
if ( !(unsigned int)func5(a1, a2, (__int64)v12, v16, v15) )
continue;
goto LABEL_26;
}
if ( i != 2 )
{
v10 = DR_get_adj(*(_QWORD *)count_paths, *(&loc_4 + 1));
result = func5(a1, a2, 0LL, v10, *(&loc_4 + 1));
v12 = 0LL;
if ( !(_DWORD)result )
goto LABEL_15;
goto LABEL_26;
}
if ( a4 == 2 )
{
v25 = DR_get_rel(*(unsigned int *)(a3 + 8), 0LL);
v12 = new_path(*(_QWORD *)a3, v25, v9);
}
else if ( a4 == 6 )
{
v24 = DR_get_rel(*(unsigned int *)(a3 + 8), 2LL);
v12 = new_path(*(_QWORD *)a3, v24, v9);
}
else
{
if ( a4 )
{
v20 = DR_get_adj(*(_QWORD *)count_paths, *(&loc_4 + 1));
result = func5(a1, a2, 0LL, v20, *(&loc_4 + 1));
if ( !(_DWORD)result )
return result;
v12 = 0LL;
goto LABEL_26;
}
v21 = DR_get_rel(*(unsigned int *)(a3 + 8), 6LL);
v12 = new_path(*(_QWORD *)a3, v21, v9);
}
v22 = v12[2];
v23 = DR_get_adj(*(_QWORD *)v12, v22);
result = func5(a1, a2, (__int64)v12, v23, v22);
if ( !(_DWORD)result )
break;
LABEL_26:
result = func1(a3, (__int64)v12);
LABEL_15:
if ( i > 1 )
return result;
}
return result;
}

original_code:
void try_branch ( struct mazetile *tiles, int size, struct path_head *last, enum DR_orientation o, struct probs probs )
{
    int r;
    int i;
    struct path_head *new_branch;
    for ( i = 0; i < 2; i++ )
    {
    new_branch = ((void *)0);
    r = ( ( int ) rand () ) % 100;
    if ( r < probs.branchy )
    {
        r = ( ( int ) rand () ) % 100;
        switch ( i )
        {
            case 0:
        switch ( o )
        {
            case FRONT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, RIGHT ), r );
                break;
            case LEFT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, FRONT ), r );
                break;
            case RIGHT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, LEFT ), r );
                break;
            default:
                break;
        }
                break;
            case 1:
        switch ( o )
        {
            case FRONT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, LEFT ), r );
                break;
            case LEFT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, RIGHT ), r );
                break;
            case RIGHT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, FRONT ), r );
                break;
            default:
                break;
        }
                break;
            default:
                break;
        }
        if ( try_move ( tiles, size, new_branch, DR_get_adj ( new_branch->p, new_branch->d ), new_branch->d ) )
        {
            add_path ( last, new_branch );
        }
    }
    }
}

canonical_original_code:
void try_branch(struct mazetile *tiles, int size, struct path_head *last, enum DR_orientation o, struct probs probs)
{
    int r;
    int i;
    struct path_head *new_branch;
    for ( i = 0; i < 2; i++ )
    {
    new_branch = ((void *)0);
    r = ( ( int ) rand () ) % 100;
    if ( r < probs.branchy )
    {
        r = ( ( int ) rand () ) % 100;
        switch ( i )
        {
            case 0:
        switch ( o )
        {
            case FRONT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, RIGHT ), r );
                break;
            case LEFT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, FRONT ), r );
                break;
            case RIGHT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, LEFT ), r );
                break;
            default:
                break;
        }
                break;
            case 1:
        switch ( o )
        {
            case FRONT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, LEFT ), r );
                break;
            case LEFT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, RIGHT ), r );
                break;
            case RIGHT:
                new_branch = new_path ( last->p, DR_get_rel ( last->d, FRONT ), r );
                break;
            default:
                break;
        }
                break;
            default:
                break;
        }
        if ( try_move ( tiles, size, new_branch, DR_get_adj ( new_branch->p, new_branch->d ), new_branch->d ) )
        {
            add_path ( last, new_branch );
        }
    }
    }
}

variable_types: struct probs { int twisty; int swirly; int branchy; }

user_defined_types: enum DR_orientation { FRONT=0, FRONTRIGHT=1, RIGHT=2, BACKRIGHT=3, BACK=4, BACKLEFT=5, LEFT=6, FRONTLEFT=7 }


decompiled_code:
_BOOL8 __fastcall advance_path(__int64 a1, unsigned int a2, _QWORD *a3, __int64 a4, int a5)
{
_BOOL8 result; // rax
int v7; // edx
unsigned int v8; // er14
unsigned int v9; // er13
__int64 v10; // r15

result = check_all(a1, a2, *a3, *((_DWORD *)a3 + 2));
if ( result )
{
v7 = rand() % 100;
result = 1LL;
if ( *((_DWORD *)a3 + 3) > v7 )
{
v8 = 0;
if ( (int)a4 <= rand() % 100 )
v8 = 4 * (SHIDWORD(a4) <= rand() % 100) + 2;
v9 = DR_get_rel(*((unsigned int *)a3 + 2), v8);
v10 = DR_get_adj(*a3, v9);
try_branch(a1, a2, (__int64)a3, v8, a4, a5);
try_move(a1, a2, (__int64)a3, v10, v9);
result = 1LL;
}
}
else
{
*((_DWORD *)a3 + 4) = 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1, unsigned int a2, _QWORD *a3, __int64 a4, int a5)
{
_BOOL8 result; // rax
int v7; // edx
unsigned int v8; // er14
unsigned int v9; // er13
__int64 v10; // r15

result = func4(a1, a2, *a3, *((_DWORD *)a3 + 2));
if ( result )
{
v7 = rand() % 100;
result = 1LL;
if ( *((_DWORD *)a3 + 3) > v7 )
{
v8 = 0;
if ( (int)a4 <= rand() % 100 )
v8 = 4 * (SHIDWORD(a4) <= rand() % 100) + 2;
v9 = DR_get_rel(*((unsigned int *)a3 + 2), v8);
v10 = DR_get_adj(*a3, v9);
func6(a1, a2, (__int64)a3, v8, a4, a5);
func5(a1, a2, (__int64)a3, v10, v9);
result = 1LL;
}
}
else
{
*((_DWORD *)a3 + 4) = 0;
}
return result;
}

original_code:
int advance_path ( struct mazetile *tiles, int size, struct path_head *last, struct probs probs )
{
    enum DR_orientation o;
    enum DR_direction dir;
    struct DR_position try_pos;
    int r;
    int result = 0;
    if ( check_all ( tiles, size, last->p, last->d ) )
    {
        result = 1;
        r = ( ( int ) rand () ) % 100;
        if ( r < last->g )
        {
            r = ( ( int ) rand () ) % 100;
            if ( r < probs.twisty )
            {
                o = FRONT;
            }
            else
            {
                r = ( ( int ) rand () ) % 100;
                if ( r < probs.swirly )
                {
                    o = RIGHT;
                }
                else
                {
                    o = LEFT;
                }
            }
            dir = DR_get_rel ( last->d, o );
            try_pos = DR_get_adj ( last->p, dir );
            try_branch ( tiles, size, last, o, probs );
            try_move ( tiles, size, last, try_pos, dir );
        }
    }
    else
    {
        last->still_space = 0;
    }
    return result;
}

canonical_original_code:
int advance_path(struct mazetile *tiles, int size, struct path_head *last, struct probs probs)
{
    enum DR_orientation o;
    enum DR_direction dir;
    struct DR_position try_pos;
    int r;
    int result = 0;
    if ( check_all ( tiles, size, last->p, last->d ) )
    {
        result = 1;
        r = ( ( int ) rand () ) % 100;
        if ( r < last->g )
        {
            r = ( ( int ) rand () ) % 100;
            if ( r < probs.twisty )
            {
                o = FRONT;
            }
            else
            {
                r = ( ( int ) rand () ) % 100;
                if ( r < probs.swirly )
                {
                    o = RIGHT;
                }
                else
                {
                    o = LEFT;
                }
            }
            dir = DR_get_rel ( last->d, o );
            try_pos = DR_get_adj ( last->p, dir );
            try_branch ( tiles, size, last, o, probs );
            try_move ( tiles, size, last, try_pos, dir );
        }
    }
    else
    {
        last->still_space = 0;
    }
    return result;
}

variable_types: enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 }

user_defined_types: struct probs { int twisty; int swirly; int branchy; }


decompiled_code:
_BOOL8 __fastcall iterate_paths(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, unsigned int a5, int *a6)
{
int v8; // er14
__int64 v9; // rdx
int v10; // eax

if ( *a6 > 1000000 )
{
*a6 = 0;
putchar(46);
fflush(stdout);
}
else
{
++*a6;
}
v8 = *(_DWORD *)(a3 + 16);
if ( v8 )
v8 = advance_path(a1, a2, (_QWORD *)a3, a4, a5);
v9 = *(_QWORD *)(a3 + 24);
v10 = 0;
if ( v9 )
v10 = iterate_paths(a1, a2, v9, a4, a5, a6);
return (v10 | v8) != 0;
}

original_code:
int iterate_paths (struct mazetile *tiles, int size, struct path_head *last, struct probs probs, int *count )
{
    int i = 0;
    int j = 0;
    if ( *count > 1000000 )
    {
        *count = 0;
        printf ( "." );
        fflush ( stdout );
    }
    else
    {
        *count += 1;
    }
    if ( last->still_space )
    {
        i = advance_path ( tiles, size, last, probs );
    }
    if ( last->next != ((void *)0) )
    {
        j = iterate_paths ( tiles, size, last->next, probs, count );
    }
    return ( i || j );
}

canonical_original_code:
int iterate_paths(struct mazetile *tiles, int size, struct path_head *last, struct probs probs, int *count)
{
    int i = 0;
    int j = 0;
    if ( *count > 1000000 )
    {
        *count = 0;
        printf ( "." );
        fflush ( stdout );
    }
    else
    {
        *count += 1;
    }
    if ( last->still_space )
    {
        i = advance_path ( tiles, size, last, probs );
    }
    if ( last->next != ((void *)0) )
    {
        j = iterate_paths ( tiles, size, last->next, probs, count );
    }
    return ( i || j );
}

variable_types:
count
int *

variable_types: j int


decompiled_code:
__int64 __fastcall generate_maze(signed int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
_QWORD *v4; // rax
__int64 v5; // r15
_QWORD *v6; // r14
unsigned int i; // er12
_QWORD *v8; // rbp
unsigned int j; // ebx
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // ebx
unsigned int v13; // ebp
__int64 v14; // r12
_QWORD *v15; // rbp
int v16; // ebx
int v17; // ebx
double v18; // xmm1_8
__int64 v19; // rbx
double v21; // [rsp+8h] [rbp-50h]
__int64 v22; // [rsp+10h] [rbp-48h]
int v24[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v24[0] = 0;
v22 = __PAIR64__(a3, a2);
if ( a1 <= 9 )
puts("maze size must be at least 10,\n or else you wouldn't have any space!");
v4 = malloc(16 * a1 * (__int64)a1);
v5 = (__int64)v4;
if ( a1 > 0 )
{
v6 = v4;
for ( i = 0; ; ++i )
{
v8 = v6;
for ( j = 0; j != a1; ++j )
{
*v8 = new_mazetile(0LL, i, j);
v8[1] = v10;
v11 = j;
v8 += 2;
}
v6 += 2 * a1;
if ( i == v11 )
break;
}
}
v21 = (double)a1 - 6.0;
v12 = (int)((double)rand() / 2147483647.0 * v21) + 3;
v13 = (int)((double)rand() / 2147483647.0 * v21) + 3;
v14 = DR_new_position(v12, v13);
printf("Starting position at %d, %d\n", v12, v13);
*(_DWORD *)(v5 + 16LL * (int)(a1 * v12 + v13)) = 1;
v15 = new_path(v14, 4, 80);
puts("root created");
printf("Generating maze ... ");
v16 = 0;
do
++v16;
while ( iterate_paths(v5, a1, (__int64)v15, v22, a4, v24) && v16 <= 4999 );
putchar(10);
v17 = rand();
v18 = (double)(int)count_paths(v15);
v19 = *(_QWORD *)get_path((__int64)v15, (int)((double)v17 / 2147483647.0 * v18) - 1);
puts("finished, destroying paths");
destroy_paths(v15);
return new_maze_pointer((unsigned int)a1, v5, v14, v19);
}

canonical_decompiled_code:
__int64 __fastcall func9(signed int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
_QWORD *v4; // rax
__int64 v5; // r15
_QWORD *v6; // r14
unsigned int i; // er12
_QWORD *v8; // rbp
unsigned int j; // ebx
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // ebx
unsigned int v13; // ebp
__int64 v14; // r12
_QWORD *v15; // rbp
int v16; // ebx
int v17; // ebx
double v18; // xmm1_8
__int64 v19; // rbx
double v21; // [rsp+8h] [rbp-50h]
__int64 v22; // [rsp+10h] [rbp-48h]
int v24[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v24[0] = 0;
v22 = __PAIR64__(a3, a2);
if ( a1 <= 9 )
puts("maze size must be at least 10,\n or else you wouldn't have any space!");
v4 = malloc(16 * a1 * (__int64)a1);
v5 = (__int64)v4;
if ( a1 > 0 )
{
v6 = v4;
for ( i = 0; ; ++i )
{
v8 = v6;
for ( j = 0; j != a1; ++j )
{
*v8 = new_mazetile(0LL, i, j);
v8[1] = v10;
v11 = j;
v8 += 2;
}
v6 += 2 * a1;
if ( i == v11 )
break;
}
}
v21 = (double)a1 - 6.0;
v12 = (int)((double)rand() / 2147483647.0 * v21) + 3;
v13 = (int)((double)rand() / 2147483647.0 * v21) + 3;
v14 = DR_new_position(v12, v13);
printf("Starting position at %d, %d\n", v12, v13);
*(_DWORD *)(v5 + 16LL * (int)(a1 * v12 + v13)) = 1;
v15 = new_path(v14, 4, 80);
puts("root created");
printf("Generating maze ... ");
v16 = 0;
do
++v16;
while ( func8(v5, a1, (__int64)v15, v22, a4, v24) && v16 <= 4999 );
putchar(10);
v17 = rand();
v18 = (double)(int)count_paths(v15);
v19 = *(_QWORD *)func0((__int64)v15, (int)((double)v17 / 2147483647.0 * v18) - 1);
puts("finished, destroying paths");
func2(v15);
return new_maze_pointer((unsigned int)a1, v5, v14, v19);
}

original_code:
struct maze *generate_maze ( int size, int twisty, int swirly, int branchy )
{
    int x;
    int y;
    int r;
    int count = 0;
    int space = 1;
    struct mazetile *tiles;
    struct probs probs;
    struct DR_position start_position;
    struct DR_position goal_position;
    struct path_head *root;
    probs.twisty = twisty;
    probs.swirly = swirly;
    probs.branchy = branchy;
    if ( size < 10 )
    {
        printf ( "maze size must be at least 10,\n or else you wouldn't have any space!\n" );
    }
    tiles = malloc ( sizeof ( struct mazetile ) * size * size );
    for ( x = 0; x < size; x++ )
    {
        for ( y = 0; y < size; y++ )
        {
            tiles[x * size + y] = new_mazetile ( WALL, x, y );
        }
    }
    x = ( int ) ( rand () / ( double ) 2147483647 * ( ( double ) size - 6 ) ) + 3;
    y = ( int ) ( rand () / ( double ) 2147483647 * ( ( double ) size - 6 ) ) + 3;
    start_position = DR_new_position ( x, y );
    printf ( "Starting position at %d, %d\n", x, y );
    tiles[x * size + y].t = SPACE;
    root = new_path ( start_position, SOUTH, 80 );
    printf ( "root created\n" );
    printf ( "Generating maze ... " );
    x=0;
    while ( space && x < 5000 )
    {
        space = iterate_paths ( tiles, size, root, probs, &count );
        x++;
    }
    printf ( "\n" );
    x = ( int ) ( rand () / ( double ) 2147483647 * ( ( double ) count_paths ( root ) ) );
    goal_position = get_path ( root, x-1 )->p;
    printf ( "finished, destroying paths\n" );
    destroy_paths ( root );
    return new_maze_pointer ( size, tiles, start_position, goal_position );
}

canonical_original_code:
struct maze *generate_maze(int size, int twisty, int swirly, int branchy)
{
    int x;
    int y;
    int r;
    int count = 0;
    int space = 1;
    struct mazetile *tiles;
    struct probs probs;
    struct DR_position start_position;
    struct DR_position goal_position;
    struct path_head *root;
    probs.twisty = twisty;
    probs.swirly = swirly;
    probs.branchy = branchy;
    if ( size < 10 )
    {
        printf ( "maze size must be at least 10,\n or else you wouldn't have any space!\n" );
    }
    tiles = malloc ( sizeof ( struct mazetile ) * size * size );
    for ( x = 0; x < size; x++ )
    {
        for ( y = 0; y < size; y++ )
        {
            tiles[x * size + y] = new_mazetile ( WALL, x, y );
        }
    }
    x = ( int ) ( rand () / ( double ) 2147483647 * ( ( double ) size - 6 ) ) + 3;
    y = ( int ) ( rand () / ( double ) 2147483647 * ( ( double ) size - 6 ) ) + 3;
    start_position = DR_new_position ( x, y );
    printf ( "Starting position at %d, %d\n", x, y );
    tiles[x * size + y].t = SPACE;
    root = new_path ( start_position, SOUTH, 80 );
    printf ( "root created\n" );
    printf ( "Generating maze ... " );
    x=0;
    while ( space && x < 5000 )
    {
        space = iterate_paths ( tiles, size, root, probs, &count );
        x++;
    }
    printf ( "\n" );
    x = ( int ) ( rand () / ( double ) 2147483647 * ( ( double ) count_paths ( root ) ) );
    goal_position = get_path ( root, x-1 )->p;
    printf ( "finished, destroying paths\n" );
    destroy_paths ( root );
    return new_maze_pointer ( size, tiles, start_position, goal_position );
}

variable_types: twisty int

variable_types: swirly int

variable_types: branchy int

variable_types: x int

variable_types: y int

variable_types: count int

variable_types: space int

return_type: struct maze { struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position { int x; int y; } p; } *tiles; struct DR_position start_position; struct DR_position goal_position; int size; } *

user_defined_types: struct maze { struct mazetile *tiles; struct DR_position start_position; struct DR_position goal_position; int size; }


decompiled_code:
void __fastcall destroy_maze(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
free(*a1);
}

original_code:
void destroy_maze ( struct maze *maze )
{
    free ( maze->tiles );
}

canonical_original_code:
void destroy_maze(struct maze *maze)
{
    free ( maze->tiles );
}

variable_types: struct maze { struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position { int x; int y; } p; } *tiles; struct DR_position start_position; struct DR_position goal_position; int size; } *


decompiled_code:
void __fastcall destroy_mazegame(__int64 a1)
{
destroy_maze(*(void ***)(a1 + 24));
free(*(void **)(a1 + 24));
}

original_code:
void destroy_mazegame ( struct mazegame *game )
{
    destroy_maze ( game->maze );
    free ( game->maze );
}

canonical_original_code:
void destroy_mazegame(struct mazegame *game)
{
    destroy_maze ( game->maze );
    free ( game->maze );
}

variable_types: struct mazegame { struct player { struct DR_position { int x; int y; } p; enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 } d; int battery; int flashlight_switch; } player; struct maze { struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position p; } *tiles; struct DR_position start_position; struct DR_position goal_position; int size; } *maze; } *

user_defined_types: struct mazegame { struct player player; struct maze *maze; }

user_defined_types: struct player { struct DR_position p; enum DR_direction d; int battery; int flashlight_switch; }


original_code:
struct player new_player ( struct DR_position start_pos )
{
    struct player player;
    player.p = start_pos;
    player.d = SOUTH;
    player.battery = 8000;
    player.flashlight_switch = 1;
    return player;
}

canonical_original_code:
struct player new_player(struct DR_position start_pos)
{
    struct player player;
    player.p = start_pos;
    player.d = SOUTH;
    player.battery = 8000;
    player.flashlight_switch = 1;
    return player;
}

variable_types: struct player { struct DR_position { int x; int y; } p; enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 } d; int battery; int flashlight_switch; }


decompiled_code:
__int64 __fastcall new_mazetile(unsigned int a1, unsigned int a2, unsigned int a3)
{
DR_new_position(a2, a3);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2, unsigned int a3)
{
DR_new_position(a2, a3);
return a1;
}

original_code:
struct mazetile new_mazetile ( enum tiletype type, int x, int y )
{
    struct mazetile mazetile;
    mazetile.t = type;
    mazetile.p = DR_new_position ( x, y );
    mazetile.light = 0;
    return mazetile;
}

canonical_original_code:
struct mazetile new_mazetile(enum tiletype type, int x, int y)
{
    struct mazetile mazetile;
    mazetile.t = type;
    mazetile.p = DR_new_position ( x, y );
    mazetile.light = 0;
    return mazetile;
}

variable_types:
type
enum tiletype { WALL=0, SPACE=1 }

variable_types: struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position { int x; int y; } p; }


decompiled_code:
__int64 __fastcall get_tiletype(__int64 a1, int a2, __int64 a3)
{
return *(unsigned int *)(a1 + 16LL * (HIDWORD(a3) + (int)a3 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3)
{
return *(unsigned int *)(a1 + 16LL * (HIDWORD(a3) + (int)a3 * a2));
}

original_code:
enum tiletype get_tiletype ( struct mazetile *tiles, int size, struct DR_position pos )
{
    return tiles[pos.x * size + pos.y].t;
}

canonical_original_code:
enum tiletype get_tiletype(struct mazetile *tiles, int size, struct DR_position pos)
{
    return tiles[pos.x * size + pos.y].t;
}

variable_types: struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position { int x; int y; } p; } *

variable_types: size int

variable_types:
pos
struct DR_position

return_type: enum tiletype { WALL=0, SPACE=1 }


decompiled_code:
__int64 __fastcall reset_light(__int64 a1)
{
__int64 result; // rax
int v2; // er8
__int64 v3; // rcx
int i; // esi

result = *(_QWORD *)(a1 + 24);
v2 = *(_DWORD *)(result + 24);
if ( v2 > 0 )
{
v3 = 16LL * (unsigned int)v2;
for ( i = 0; i != v2; ++i )
{
result = -16LL * (unsigned int)v2 + v3;
do
{
*(_DWORD *)(**(_QWORD **)(a1 + 24) + result + 4) = 0;
result += 16LL;
}
while ( result != v3 );
v3 += 16LL * v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
int v2; // er8
__int64 v3; // rcx
int i; // esi

result = *(_QWORD *)(a1 + 24);
v2 = *(_DWORD *)(result + 24);
if ( v2 > 0 )
{
v3 = 16LL * (unsigned int)v2;
for ( i = 0; i != v2; ++i )
{
result = -16LL * (unsigned int)v2 + v3;
do
{
*(_DWORD *)(**(_QWORD **)(a1 + 24) + result + 4) = 0;
result += 16LL;
}
while ( result != v3 );
v3 += 16LL * v2;
}
}
return result;
}

original_code:
void reset_light ( struct mazegame *game )
{
    int x;
    int y;
    int s = game->maze->size;
    for ( x = 0; x < s; x++ )
    {
        for ( y = 0; y < s; y++ )
        {
            game->maze->tiles[ x * s + y ].light = 0;
        }
    }
}

canonical_original_code:
void reset_light(struct mazegame *game)
{
    int x;
    int y;
    int s = game->maze->size;
    for ( x = 0; x < s; x++ )
    {
        for ( y = 0; y < s; y++ )
        {
            game->maze->tiles[ x * s + y ].light = 0;
        }
    }
}

variable_types: s int


decompiled_code:
__int64 __fastcall recurse_light(__int64 a1, unsigned int a2, int a3, __int64 a4, __m128i a5)
{
int v7; // esi
__int64 result; // rax
__int64 v10; // rax
unsigned int v11; // eax
__int64 v12; // rax
unsigned int v13; // eax
__int64 v14; // rax
unsigned int v15; // eax
__int64 v16; // rax
unsigned int v17; // eax
__int64 v18; // rax
float v19; // [rsp+Ch] [rbp-2Ch]

v19 = *(float *)a5.m128i_i32;
v7 = *(_DWORD *)(a1 + 24);
result = *(_QWORD *)a1 + 16LL * (HIDWORD(a4) + (int)a4 * v7);
*(float *)(result + 4) = *(float *)a5.m128i_i32 + *(float *)(result + 4);
if ( *(float *)a5.m128i_i32 >= 1.0 )
{
result = get_tiletype(*(_QWORD *)a1, v7, a4);
if ( (_DWORD)result == 1 )
{
switch ( a3 )
{
case 1:
v17 = DR_get_rel(a2, 1LL);
v18 = DR_get_adj(a4, v17);
result = recurse_light(a1, a2, 1LL, v18, *(float *)a5.m128i_i32 / 3.0);
break;
case 2:
v15 = DR_get_rel(a2, 7LL);
v16 = DR_get_adj(a4, v15);
result = recurse_light(a1, a2, 2LL, v16, *(float *)a5.m128i_i32 / 3.0);
break;
case 0:
v10 = DR_get_adj(a4, a2);
recurse_light(a1, a2, 0LL, v10, *(float *)a5.m128i_i32 * 0.5);
v11 = DR_get_rel(a2, 7LL);
v12 = DR_get_adj(a4, v11);
a5 = (__m128i)a5.m128i_u32[0];
*(float *)a5.m128i_i32 = *(float *)a5.m128i_i32 / 3.0;
recurse_light(a1, a2, 2LL, v12, v19 / 3.0);
v13 = DR_get_rel(a2, 1LL);
v14 = DR_get_adj(a4, v13);
result = recurse_light(a1, a2, 1LL, v14, COERCE_FLOAT(_mm_cvtsi128_si32(a5)));
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, int a3, __int64 a4, __m128i a5)
{
int v7; // esi
__int64 result; // rax
__int64 v10; // rax
unsigned int v11; // eax
__int64 v12; // rax
unsigned int v13; // eax
__int64 v14; // rax
unsigned int v15; // eax
__int64 v16; // rax
unsigned int v17; // eax
__int64 v18; // rax
float v19; // [rsp+Ch] [rbp-2Ch]

v19 = *(float *)a5.m128i_i32;
v7 = *(_DWORD *)(a1 + 24);
result = *(_QWORD *)a1 + 16LL * (HIDWORD(a4) + (int)a4 * v7);
*(float *)(result + 4) = *(float *)a5.m128i_i32 + *(float *)(result + 4);
if ( *(float *)a5.m128i_i32 >= 1.0 )
{
result = func5(*(_QWORD *)a1, v7, a4);
if ( (_DWORD)result == 1 )
{
switch ( a3 )
{
case 1:
v17 = DR_get_rel(a2, 1LL);
v18 = DR_get_adj(a4, v17);
result = func7(a1, a2, 1LL, v18, *(float *)a5.m128i_i32 / 3.0);
break;
case 2:
v15 = DR_get_rel(a2, 7LL);
v16 = DR_get_adj(a4, v15);
result = func7(a1, a2, 2LL, v16, *(float *)a5.m128i_i32 / 3.0);
break;
case 0:
v10 = DR_get_adj(a4, a2);
func7(a1, a2, 0LL, v10, *(float *)a5.m128i_i32 * 0.5);
v11 = DR_get_rel(a2, 7LL);
v12 = DR_get_adj(a4, v11);
a5 = (__m128i)a5.m128i_u32[0];
*(float *)a5.m128i_i32 = *(float *)a5.m128i_i32 / 3.0;
func7(a1, a2, 2LL, v12, v19 / 3.0);
v13 = DR_get_rel(a2, 1LL);
v14 = DR_get_adj(a4, v13);
result = func7(a1, a2, 1LL, v14, COERCE_FLOAT(_mm_cvtsi128_si32(a5)));
break;
}
}
}
return result;
}

original_code:
void recurse_light ( float value, struct maze *maze, enum DR_direction d, enum recurse_light_class o, struct DR_position p )
{
    float divisor = 2.0;
    float side_divisor = 3.0;
    int s = maze->size;
    maze->tiles[p.x * s + p.y].light += value;
    if ( value >= 1.0 && get_tiletype ( maze->tiles, s, p ) == SPACE )
    {
        switch ( o )
        {
            case PRIMARY:
                recurse_light ( value / divisor, maze, d, PRIMARY, DR_get_adj ( p, d ) );
                recurse_light ( value / side_divisor, maze, d, SEC_LEFT, DR_get_adj ( p, DR_get_rel ( d, FRONTLEFT ) ) );
                recurse_light ( value / side_divisor, maze, d, SEC_RIGHT, DR_get_adj ( p, DR_get_rel ( d, FRONTRIGHT ) ) );
                break;
            case SEC_LEFT:
                recurse_light ( value / side_divisor, maze, d, SEC_LEFT, DR_get_adj ( p, DR_get_rel ( d, FRONTLEFT ) ) );
                break;
            case SEC_RIGHT:
                recurse_light ( value / side_divisor, maze, d, SEC_RIGHT, DR_get_adj ( p, DR_get_rel ( d, FRONTRIGHT ) ) );
                break;
            default:
                break;
        }
    }
}

canonical_original_code:
void recurse_light(float value, struct maze *maze, enum DR_direction d, enum recurse_light_class o, struct DR_position p)
{
    float divisor = 2.0;
    float side_divisor = 3.0;
    int s = maze->size;
    maze->tiles[p.x * s + p.y].light += value;
    if ( value >= 1.0 && get_tiletype ( maze->tiles, s, p ) == SPACE )
    {
        switch ( o )
        {
            case PRIMARY:
                recurse_light ( value / divisor, maze, d, PRIMARY, DR_get_adj ( p, d ) );
                recurse_light ( value / side_divisor, maze, d, SEC_LEFT, DR_get_adj ( p, DR_get_rel ( d, FRONTLEFT ) ) );
                recurse_light ( value / side_divisor, maze, d, SEC_RIGHT, DR_get_adj ( p, DR_get_rel ( d, FRONTRIGHT ) ) );
                break;
            case SEC_LEFT:
                recurse_light ( value / side_divisor, maze, d, SEC_LEFT, DR_get_adj ( p, DR_get_rel ( d, FRONTLEFT ) ) );
                break;
            case SEC_RIGHT:
                recurse_light ( value / side_divisor, maze, d, SEC_RIGHT, DR_get_adj ( p, DR_get_rel ( d, FRONTRIGHT ) ) );
                break;
            default:
                break;
        }
    }
}

variable_types: value float

variable_types: enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 }

variable_types: enum recurse_light_class { PRIMARY=0, SEC_RIGHT=1, SEC_LEFT=2 }

variable_types:
p
struct DR_position

variable_types: divisor float


assoc

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

if ( a1 == 4 )
return 2LL;
if ( a1 > 4 )
return 3 * (unsigned int)(a1 != 6) + 4;
result = 1LL;
if ( a1 )
result = 4 * (unsigned int)(a1 != 2) + 3;
return result;
}

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

if ( a1 == 4 )
return 2LL;
if ( a1 > 4 )
return 3 * (unsigned int)(a1 != 6) + 4;
result = 1LL;
if ( a1 )
result = 4 * (unsigned int)(a1 != 2) + 3;
return result;
}

original_code:
enum command assoc( enum DR_direction d ) {
  enum command c;
  switch( d ) {
  case NORTH:
    c = MOVE_N;
    break;
  case SOUTH:
    c = MOVE_S;
    break;
  case WEST:
    c = MOVE_W;
    break;
  case EAST:
    c = MOVE_E;
    break;
  default:
    c = NONE;
    break;
  }
  return c;
}

canonical_original_code:
enum command assoc(enum DR_direction d) {
  enum command c;
  switch( d ) {
  case NORTH:
    c = MOVE_N;
    break;
  case SOUTH:
    c = MOVE_S;
    break;
  case WEST:
    c = MOVE_W;
    break;
  case EAST:
    c = MOVE_E;
    break;
  default:
    c = NONE;
    break;
  }
  return c;
}

variable_types: enum command { QUIT=0, MOVE_N=1, MOVE_S=2, MOVE_E=3, MOVE_W=4, RUN=5, FLASHLIGHT=6, NONE=7 }


decompiled_code:
__int64 __fastcall move_player(__int64 a1, __int64 a2)
{
int v2; // er13
__int64 v3; // rax
__int64 result; // rax
__int64 v5; // r12
int v6; // edx

v2 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + 24LL);
v3 = DR_get_adj(*(_QWORD *)a1, a2);
if ( *(_DWORD *)(a1 + 8) == (_DWORD)a2 )
{
v5 = v3;
v6 = get_tiletype(**(_QWORD **)(a1 + 24), v2, v3);
result = 0LL;
if ( v6 == 1 )
{
*(_QWORD *)a1 = v5;
result = 1LL;
}
}
else
{
*(_DWORD *)(a1 + 8) = a2;
result = 1LL;
}
return result;
}

original_code:
int move_player( struct mazegame *g, const enum DR_direction d ) {
  int s = g->maze->size;
  int moved = 0;
  struct DR_position p = DR_get_adj( g->player.p, d );
  enum tiletype t = get_tiletype( g->maze->tiles, s, p );
  if( d != g->player.d ) {
    g->player.d = d;
    moved = 1;
  } else if( SPACE == t ) {
    g->player.p = p;
    moved = 1;
  }
  return moved;
}

canonical_original_code:
int move_player(struct mazegame *g, enum DR_direction d) {
  int s = g->maze->size;
  int moved = 0;
  struct DR_position p = DR_get_adj( g->player.p, d );
  enum tiletype t = get_tiletype( g->maze->tiles, s, p );
  if( d != g->player.d ) {
    g->player.d = d;
    moved = 1;
  } else if( SPACE == t ) {
    g->player.p = p;
    moved = 1;
  }
  return moved;
}

variable_types: moved int

variable_types:
p
struct DR_position { int x; int y; }

variable_types:
t
enum tiletype { WALL=0, SPACE=1 }


decompiled_code:
_BOOL8 __fastcall check_around(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rax
unsigned __int64 v5; // [rsp+0h] [rbp-28h]

v5 = _mm_loadu_si128((const __m128i *)a1).m128i_u64[0];
v2 = DR_get_rel(*(unsigned int *)(a1 + 8), a2);
v3 = DR_get_adj(v5, v2);
return (unsigned int)get_tiletype(**(_QWORD **)(a1 + 24), *(_DWORD *)(*(_QWORD *)(a1 + 24) + 24LL), v3) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rax
unsigned __int64 v5; // [rsp+0h] [rbp-28h]

v5 = _mm_loadu_si128((const __m128i *)a1).m128i_u64[0];
v2 = DR_get_rel(*(unsigned int *)(a1 + 8), a2);
v3 = DR_get_adj(v5, v2);
return (unsigned int)func5(**(_QWORD **)(a1 + 24), *(_DWORD *)(*(_QWORD *)(a1 + 24) + 24LL), v3) == 1;
}

original_code:
int check_around( const struct mazegame *g, const enum DR_orientation o ) {
  struct player p = g->player;
  enum tiletype t =
    get_tiletype( g->maze->tiles, g->maze->size, DR_get_adj( p.p, DR_get_rel( p.d, o ) ) );
  return( SPACE == t );
}

canonical_original_code:
int check_around(struct mazegame *g, enum DR_orientation o) {
  struct player p = g->player;
  enum tiletype t = get_tiletype( g->maze->tiles, g->maze->size, DR_get_adj( p.p, DR_get_rel( p.d, o ) ) );
  return( SPACE == t );
}

variable_types: struct mazegame { struct player { struct DR_position { int x; int y; } p; enum DR_direction { NORTH=0, NORTHEAST=1, EAST=2, SOUTHEAST=3, SOUTH=4, SOUTHWEST=5, WEST=6, NORTHWEST=7, FULL_CYCLE=8 } d; int battery; int flashlight_switch; } player; struct maze { struct mazetile { enum tiletype { WALL=0, SPACE=1 } t; float light; struct DR_position p; } *tiles; struct DR_position start_position; struct DR_position goal_position; int size; } *maze; } *

variable_types: enum DR_orientation { FRONT=0, FRONTRIGHT=1, RIGHT=2, BACKRIGHT=3, BACK=4, BACKLEFT=5, LEFT=6, FRONTLEFT=7 }


decompiled_code:
__int64 __fastcall turn_player(__int64 a1)
{
_BOOL4 v1; // ebp
_BOOL4 v2; // eax
__int64 result; // rax

v1 = check_around(a1, 6LL);
v2 = check_around(a1, 2LL);
if ( v1 && !v2 )
{
*(_DWORD *)(a1 + 8) = DR_get_rel(*(unsigned int *)(a1 + 8), 6LL);
result = 1LL;
}
else if ( v2 && !v1 )
{
*(_DWORD *)(a1 + 8) = DR_get_rel(*(unsigned int *)(a1 + 8), 2LL);
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_BOOL4 v1; // ebp
_BOOL4 v2; // eax
__int64 result; // rax

v1 = func10(a1, 6LL);
v2 = func10(a1, 2LL);
if ( v1 && !v2 )
{
*(_DWORD *)(a1 + 8) = DR_get_rel(*(unsigned int *)(a1 + 8), 6LL);
result = 1LL;
}
else if ( v2 && !v1 )
{
*(_DWORD *)(a1 + 8) = DR_get_rel(*(unsigned int *)(a1 + 8), 2LL);
result = 1LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int turn_player( struct mazegame *g ) {
  int turned = 0;
  int left = check_around( g, LEFT );
  int right = check_around( g, RIGHT );
  if( left && !right ) {
    g->player.d = DR_get_rel( g->player.d, LEFT );
    turned = 1;
  } else if( right && !left ) {
    g->player.d = DR_get_rel( g->player.d, RIGHT );
    turned = 1;
  }
  return turned;
}

canonical_original_code:
int turn_player(struct mazegame *g) {
  int turned = 0;
  int left = check_around( g, LEFT );
  int right = check_around( g, RIGHT );
  if( left && !right ) {
    g->player.d = DR_get_rel( g->player.d, LEFT );
    turned = 1;
  } else if( right && !left ) {
    g->player.d = DR_get_rel( g->player.d, RIGHT );
    turned = 1;
  }
  return turned;
}

variable_types: turned int

variable_types: left int

variable_types: right int


decompiled_code:
void __fastcall set_switch(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

original_code:
void set_switch( struct mazegame *g, int v ) {
  g->player.flashlight_switch = v;
}

canonical_original_code:
void set_switch(struct mazegame *g, int v) {
  g->player.flashlight_switch = v;
}

variable_types: v int


decompiled_code:
void __fastcall flip_switch(__int64 a1)
{
if ( *(_DWORD *)(a1 + 16) == 1 )
set_switch(a1, 8);
else
set_switch(a1, 1);
}

original_code:
void flip_switch( struct mazegame *g ) {
  if( 1 == g->player.flashlight_switch ) {
    set_switch( g, 8 );
  } else {
    set_switch( g, 1 );
  }
}

canonical_original_code:
void flip_switch(struct mazegame *g) {
  if( 1 == g->player.flashlight_switch ) {
    set_switch( g, 8 );
  } else {
    set_switch( g, 1 );
  }
}


decompiled_code:
__int64 __fastcall update_game(__int64 a1, int a2)
{
int v2; // ebp
__m128i v3; // xmm0
__int64 result; // rax

v2 = 4 * *(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 12);
switch ( a2 )
{
case 1:
move_player(a1, 0LL);
break;
case 2:
move_player(a1, 4LL);
break;
case 3:
move_player(a1, 2LL);
break;
case 4:
move_player(a1, 6LL);
break;
case 5:
if ( !(unsigned int)move_player(a1, *(unsigned int *)(a1 + 8)) )
turn_player(a1);
break;
case 6:
flip_switch(a1);
break;
default:
break;
}
reset_light(a1);
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)(v2 / 1600);
recurse_light(*(_QWORD *)(a1 + 24), *(_DWORD *)(a1 + 8), 0, *(_QWORD *)a1, v3);
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 12) -= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
int v2; // ebp
__m128i v3; // xmm0
__int64 result; // rax

v2 = 4 * *(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 12);
switch ( a2 )
{
case 1:
func9(a1, 0LL);
break;
case 2:
func9(a1, 4LL);
break;
case 3:
func9(a1, 2LL);
break;
case 4:
func9(a1, 6LL);
break;
case 5:
if ( !(unsigned int)func9(a1, *(unsigned int *)(a1 + 8)) )
func11(a1);
break;
case 6:
func13(a1);
break;
default:
break;
}
func6(a1);
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)(v2 / 1600);
func7(*(_QWORD *)(a1 + 24), *(_DWORD *)(a1 + 8), 0, *(_QWORD *)a1, v3);
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 12) -= result;
return result;
}

original_code:
void update_game( struct mazegame *g, enum command player_move ) {
  int s = g->maze->size;
  int power = g->player.battery * g->player.flashlight_switch * 4;
  switch( player_move ) {
    case FLASHLIGHT:
      flip_switch( g );
      break;
    case RUN:
      if( !move_player( g, g->player.d ) ) {
        turn_player( g );
      }
      break;
    case MOVE_N:
      move_player( g, NORTH );
      break;
    case MOVE_S:
      move_player( g, SOUTH );
      break;
    case MOVE_W:
      move_player( g, WEST );
      break;
    case MOVE_E:
      move_player( g, EAST );
      break;
    default:
      break;
  }
  reset_light( g );
  recurse_light( power / 1600, g->maze, g->player.d, PRIMARY, g->player.p );
  g->player.battery -= g->player.flashlight_switch;
}

canonical_original_code:
void update_game(struct mazegame *g, enum command player_move) {
  int s = g->maze->size;
  int power = g->player.battery * g->player.flashlight_switch * 4;
  switch( player_move ) {
    case FLASHLIGHT:
      flip_switch( g );
      break;
    case RUN:
      if( !move_player( g, g->player.d ) ) {
        turn_player( g );
      }
      break;
    case MOVE_N:
      move_player( g, NORTH );
      break;
    case MOVE_S:
      move_player( g, SOUTH );
      break;
    case MOVE_W:
      move_player( g, WEST );
      break;
    case MOVE_E:
      move_player( g, EAST );
      break;
    default:
      break;
  }
  reset_light( g );
  recurse_light( power / 1600, g->maze, g->player.d, PRIMARY, g->player.p );
  g->player.battery -= g->player.flashlight_switch;
}

variable_types: power int

user_defined_types: enum command { QUIT=0, MOVE_N=1, MOVE_S=2, MOVE_E=3, MOVE_W=4, RUN=5, FLASHLIGHT=6, NONE=7 }