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; }


repo: RobertGBryan/TinyMTCPP

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

canonical_decompiled_code:
__int64 __fastcall func0(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 func1(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 func2(_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';
    }
}

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

return_type: void


main

canonical_name: main

repo: RobertMe/linux-hid-lg-extended

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
const char *v5; // rbx
size_t v6; // r15
size_t v7; // r13
int v8; // eax
bool v9; // dl
int v10; // ebx
int v11; // er13
char *v12; // r15
__int64 v13; // rsi
int result; // eax
unsigned __int64 n; // [rsp+8h] [rbp-1E0h]
struct timeval timeout; // [rsp+20h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+B0h] [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 )
{
v5 = (const char *)readline();
v6 = strlen(v5);
if ( !v6 )
goto LABEL_10;
if ( *v5 != 59 )
{
v7 = 0LL;
add_history();
do
{
n = (unsigned int)v7 / 3uLL;
v8 = __isoc99_sscanf();
v9 = v6 > v7;
v7 += 3LL;
}
while ( v8 != 0 && v9 );
if ( (int)write(v4, buf, n) < 0 )
perror("write");
LABEL_10:
v10 = 0;
LABEL_11:
if ( v10
|| (timeout.tv_sec = 1LL,
timeout.tv_usec = 0LL,
memset(&readfds, 0, sizeof(readfds)),
readfds.fds_bits[v4 >> 6] |= 1LL << v4,
select(v4 + 1, &readfds, 0LL, 0LL, &timeout)) )
{
while ( 1 )
{
v11 = read(v4, buf, 0x2EuLL);
if ( v11 <= 0 )
break;
if ( !(unsigned int)valid_report_id((unsigned __int8)buf[0]) )
goto LABEL_11;
printf("<< ");
v12 = buf;
do
{
v13 = (unsigned int)*v12++;
printf("%02hhx ", v13);
}
while ( &buf[v11 - 1 + 1] != v12 );
v10 = 1;
puts("");
}
}
}
}
}
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
const char *v5; // rbx
size_t v6; // r15
size_t v7; // r13
int v8; // eax
bool v9; // dl
int v10; // ebx
int v11; // er13
char *v12; // r15
__int64 v13; // rsi
int result; // eax
unsigned __int64 n; // [rsp+8h] [rbp-1E0h]
struct timeval timeout; // [rsp+20h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+B0h] [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 )
{
v5 = (const char *)readline();
v6 = strlen(v5);
if ( !v6 )
goto LABEL_10;
if ( *v5 != 59 )
{
v7 = 0LL;
add_history();
do
{
n = (unsigned int)v7 / 3uLL;
v8 = __isoc99_sscanf();
v9 = v6 > v7;
v7 += 3LL;
}
while ( v8 != 0 && v9 );
if ( (int)write(v4, buf, n) < 0 )
perror("write");
LABEL_10:
v10 = 0;
LABEL_11:
if ( v10
|| (timeout.tv_sec = 1LL,
timeout.tv_usec = 0LL,
memset(&readfds, 0, sizeof(readfds)),
readfds.fds_bits[v4 >> 6] |= 1LL << v4,
select(v4 + 1, &readfds, 0LL, 0LL, &timeout)) )
{
while ( 1 )
{
v11 = read(v4, buf, 0x2EuLL);
if ( v11 <= 0 )
break;
if ( !(unsigned int)func10((unsigned __int8)buf[0]) )
goto LABEL_11;
printf("<< ");
v12 = buf;
do
{
v13 = (unsigned int)*v12++;
printf("%02hhx ", v13);
}
while ( &buf[v11 - 1 + 1] != v12 );
v10 = 1;
puts("");
}
}
}
}
}
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: fd int

variable_types: i int

variable_types: res int

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; }

return_type: int


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


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: 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 ( *v1 != a1 )
{
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 ( *v1 != a1 )
{
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;
}


repo: RobinLiu/msg

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

if ( s && a2 > 0 )
{
timer = -1LL;
if ( !gettimeofday(&tv, 0LL) )
timer = tv.tv_sec;
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 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 timeval tv; // [rsp+8h] [rbp-68h] BYREF
struct tm tp; // [rsp+18h] [rbp-58h] BYREF

if ( s && a2 > 0 )
{
timer = -1LL;
if ( !gettimeofday(&tv, 0LL) )
timer = tv.tv_sec;
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 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)
{
__int64 v2; // rdx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rax
unsigned __int64 result; // 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 = (unsigned int)a1;
v3 = a2;
switch ( a2 )
{
case 0u:
v4 = DR_new_position(a1, (unsigned int)(HIDWORD(a1) - 1));
v2 = (unsigned int)v4;
v3 = HIDWORD(v4);
goto LABEL_3;
case 1u:
v8 = DR_new_position((int)a1 + 1, (unsigned int)(HIDWORD(a1) - 1));
result = (unsigned int)v8 | (HIDWORD(v8) << 32);
break;
case 2u:
v9 = DR_new_position((int)a1 + 1, HIDWORD(a1));
result = (unsigned int)v9 | (HIDWORD(v9) << 32);
break;
case 3u:
v10 = DR_new_position((int)a1 + 1, (unsigned int)(HIDWORD(a1) + 1));
result = (unsigned int)v10 | (HIDWORD(v10) << 32);
break;
case 4u:
v11 = DR_new_position(a1, (unsigned int)(HIDWORD(a1) + 1));
result = (unsigned int)v11 | (HIDWORD(v11) << 32);
break;
case 5u:
v12 = DR_new_position((int)a1 - 1, (unsigned int)(HIDWORD(a1) + 1));
result = (unsigned int)v12 | (HIDWORD(v12) << 32);
break;
case 6u:
v6 = DR_new_position((int)a1 - 1, HIDWORD(a1));
result = (unsigned int)v6 | (HIDWORD(v6) << 32);
break;
case 7u:
v7 = DR_new_position((int)a1 - 1, (unsigned int)(HIDWORD(a1) - 1));
result = (unsigned int)v7 | (HIDWORD(v7) << 32);
break;
default:
LABEL_3:
result = v2 | (v3 << 32);
break;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rax
unsigned __int64 result; // 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 = (unsigned int)a1;
v3 = a2;
switch ( a2 )
{
case 0u:
v4 = func0(a1, (unsigned int)(HIDWORD(a1) - 1));
v2 = (unsigned int)v4;
v3 = HIDWORD(v4);
goto LABEL_3;
case 1u:
v8 = func0((int)a1 + 1, (unsigned int)(HIDWORD(a1) - 1));
result = (unsigned int)v8 | (HIDWORD(v8) << 32);
break;
case 2u:
v9 = func0((int)a1 + 1, HIDWORD(a1));
result = (unsigned int)v9 | (HIDWORD(v9) << 32);
break;
case 3u:
v10 = func0((int)a1 + 1, (unsigned int)(HIDWORD(a1) + 1));
result = (unsigned int)v10 | (HIDWORD(v10) << 32);
break;
case 4u:
v11 = func0(a1, (unsigned int)(HIDWORD(a1) + 1));
result = (unsigned int)v11 | (HIDWORD(v11) << 32);
break;
case 5u:
v12 = func0((int)a1 - 1, (unsigned int)(HIDWORD(a1) + 1));
result = (unsigned int)v12 | (HIDWORD(v12) << 32);
break;
case 6u:
v6 = func0((int)a1 - 1, HIDWORD(a1));
result = (unsigned int)v6 | (HIDWORD(v6) << 32);
break;
case 7u:
v7 = func0((int)a1 - 1, (unsigned int)(HIDWORD(a1) - 1));
result = (unsigned int)v7 | (HIDWORD(v7) << 32);
break;
default:
LABEL_3:
result = v2 | (v3 << 32);
break;
}
return result;
}

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(unsigned int a1)
{
__int64 result; // rax

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

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

result = a1;
if ( a1 > 7 )
{
do
{
while ( (int)result >= 0 )
{
result = (unsigned int)(result - 8);
if ( (unsigned int)result <= 7 )
return result;
}
result = (unsigned int)(result + 8);
}
while ( (unsigned int)result > 7 );
}
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 )
{
do
{
--a2;
result = *(_QWORD *)(result + 24);
}
while ( a2 != -1 );
}
return result;
}

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

result = a1;
if ( a2 >= 0 )
{
do
{
--a2;
result = *(_QWORD *)(result + 24);
}
while ( 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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
*(_QWORD *)(result + 24) = a2;
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
*(_QWORD *)(result + 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 func3(_QWORD *a1)
{
if ( a1[3] )
func3();
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)
{
__int64 result; // rax
int v7; // edi
__int64 v8; // rdx
__int64 v9; // r14
unsigned int v10; // er15
unsigned int v11; // er13
unsigned int v12; // eax
unsigned int v13; // eax
__int64 v14; // rax
__int64 v15; // [rsp+0h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4)
{
__int64 result; // rax
int v7; // edi
__int64 v8; // rdx
__int64 v9; // r14
unsigned int v10; // er15
unsigned int v11; // er13
unsigned int v12; // eax
unsigned int v13; // eax
__int64 v14; // rax
__int64 v15; // [rsp+0h] [rbp-40h]

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

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; // ebx
unsigned int v8; // er15
unsigned int v9; // eax
__int64 v10; // rax
int v11; // er15
unsigned int v12; // eax
__int64 v13; // rax
unsigned 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);
v11 = check_space(a1, a2, v10, v8);
v15 = 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, v15) | v11 | v7) != 0;
}

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

v6 = DR_get_adj(a3, a4);
v7 = func4(a1, a2, v6, a4);
v8 = DR_get_rel(a4, 6LL);
v9 = DR_get_rel(a4, 6LL);
v10 = DR_get_adj(a3, v9);
v11 = func4(a1, a2, v10, v8);
v15 = DR_get_rel(a4, 2LL);
v12 = DR_get_rel(a4, 2LL);
v13 = DR_get_adj(a3, v12);
return ((unsigned int)func4(a1, a2, v13, v15) | v11 | 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 )
{
result = 1LL;
*(_DWORD *)(a1 + 16LL * (int)(HIDWORD(a4) + a4 * a2)) = 1;
*(_QWORD *)a3 = a4;
*(_DWORD *)(a3 + 8) = a5;
}
return result;
}

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

result = func4(a1, a2, a4, a5);
if ( (_DWORD)result )
{
result = 1LL;
*(_DWORD *)(a1 + 16LL * (int)(HIDWORD(a4) + a4 * a2)) = 1;
*(_QWORD *)a3 = a4;
*(_DWORD *)(a3 + 8) = a5;
}
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; // er12
int v11; // edx
__int64 result; // rax
__int64 v13; // rdi
__int64 v14; // rsi
int v15; // eax
_DWORD *v16; // r14
__int64 v17; // rax
int v18; // er14
__int64 v19; // rdi
__int64 v20; // rsi
int v21; // eax
__int64 v22; // rax
unsigned int v24; // [rsp+Ch] [rbp-4Ch]
unsigned int v25; // [rsp+Ch] [rbp-4Ch]

for ( i = 0; ; i = 1 )
{
v11 = rand();
result = (unsigned int)(100 * (v11 / 100));
if ( v11 % 100 >= a6 )
goto LABEL_3;
v18 = rand() % 100;
if ( i == 1 )
break;
if ( a4 == 2 )
{
v19 = *(unsigned int *)(a3 + 8);
v20 = 6LL;
}
else if ( a4 == 6 )
{
v19 = *(unsigned int *)(a3 + 8);
v20 = 0LL;
}
else
{
if ( a4 )
goto LABEL_22;
v19 = *(unsigned int *)(a3 + 8);
v20 = 2LL;
}
v21 = DR_get_rel(v19, v20);
v16 = new_path(*(_QWORD *)a3, v21, v18);
v25 = v16[2];
v22 = DR_get_adj(*(_QWORD *)v16, v25);
result = try_move(a1, a2, (__int64)v16, v22, v25);
if ( (_DWORD)result )
goto LABEL_17;
LABEL_3:
if ( i == 1 )
return result;
}
if ( a4 == 2 )
{
v13 = *(unsigned int *)(a3 + 8);
v14 = 0LL;
}
else if ( a4 == 6 )
{
v13 = *(unsigned int *)(a3 + 8);
v14 = 2LL;
}
else
{
if ( a4 )
LABEL_22:
try_branch_cold();
v13 = *(unsigned int *)(a3 + 8);
v14 = 6LL;
}
v15 = DR_get_rel(v13, v14);
v16 = new_path(*(_QWORD *)a3, v15, v18);
v24 = v16[2];
v17 = DR_get_adj(*(_QWORD *)v16, v24);
result = try_move(a1, a2, (__int64)v16, v17, v24);
if ( (_DWORD)result )
{
LABEL_17:
result = add_path(a3, (__int64)v16);
goto LABEL_3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, __int64 a3, int a4, __int64 a5, int a6)
{
int i; // er12
int v11; // edx
__int64 result; // rax
__int64 v13; // rdi
__int64 v14; // rsi
int v15; // eax
_DWORD *v16; // r14
__int64 v17; // rax
int v18; // er14
__int64 v19; // rdi
__int64 v20; // rsi
int v21; // eax
__int64 v22; // rax
unsigned int v24; // [rsp+Ch] [rbp-4Ch]
unsigned int v25; // [rsp+Ch] [rbp-4Ch]

for ( i = 0; ; i = 1 )
{
v11 = rand();
result = (unsigned int)(100 * (v11 / 100));
if ( v11 % 100 >= a6 )
goto LABEL_3;
v18 = rand() % 100;
if ( i == 1 )
break;
if ( a4 == 2 )
{
v19 = *(unsigned int *)(a3 + 8);
v20 = 6LL;
}
else if ( a4 == 6 )
{
v19 = *(unsigned int *)(a3 + 8);
v20 = 0LL;
}
else
{
if ( a4 )
goto LABEL_22;
v19 = *(unsigned int *)(a3 + 8);
v20 = 2LL;
}
v21 = DR_get_rel(v19, v20);
v16 = new_path(*(_QWORD *)a3, v21, v18);
v25 = v16[2];
v22 = DR_get_adj(*(_QWORD *)v16, v25);
result = func6(a1, a2, (__int64)v16, v22, v25);
if ( (_DWORD)result )
goto LABEL_17;
LABEL_3:
if ( i == 1 )
return result;
}
if ( a4 == 2 )
{
v13 = *(unsigned int *)(a3 + 8);
v14 = 0LL;
}
else if ( a4 == 6 )
{
v13 = *(unsigned int *)(a3 + 8);
v14 = 2LL;
}
else
{
if ( a4 )
LABEL_22:
func11();
v13 = *(unsigned int *)(a3 + 8);
v14 = 6LL;
}
v15 = DR_get_rel(v13, v14);
v16 = new_path(*(_QWORD *)a3, v15, v18);
v24 = v16[2];
v17 = DR_get_adj(*(_QWORD *)v16, v24);
result = func6(a1, a2, (__int64)v16, v17, v24);
if ( (_DWORD)result )
{
LABEL_17:
result = func2(a3, (__int64)v16);
goto LABEL_3;
}
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; // er15
unsigned int v9; // ebx
__int64 v10; // r14

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 func8(__int64 a1, unsigned int a2, _QWORD *a3, __int64 a4, int a5)
{
_BOOL8 result; // rax
int v7; // edx
unsigned int v8; // er15
unsigned int v9; // ebx
__int64 v10; // r14

result = func5(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);
func7(a1, a2, (__int64)a3, v8, a4, a5);
func6(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; // er12
__int64 v9; // rdx

if ( *a6 > 1000000 )
{
*a6 = 0;
putchar(46);
fflush(stdout);
v8 = *(_DWORD *)(a3 + 16);
if ( !v8 )
goto LABEL_3;
}
else
{
++*a6;
v8 = *(_DWORD *)(a3 + 16);
if ( !v8 )
goto LABEL_3;
}
v8 = advance_path(a1, a2, (_QWORD *)a3, a4, a5);
LABEL_3:
v9 = *(_QWORD *)(a3 + 24);
if ( v9 )
v8 |= iterate_paths(a1, a2, v9, a4, a5, a6);
return 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)
{
__int64 v4; // r15
_DWORD *v5; // r14
_DWORD *v6; // r13
unsigned int i; // er15
_DWORD *v8; // rbp
unsigned int j; // ebx
unsigned int v10; // eax
__int64 v11; // rdx
unsigned int v12; // ebx
unsigned int v13; // ebp
__int64 v14; // r13
unsigned int v15; // eax
int v16; // ebx
_QWORD *v17; // rbp
int v18; // ecx
double v19; // xmm1_8
__int64 v20; // r15
__int64 v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+10h] [rbp-48h] BYREF
__int64 v24; // [rsp+14h] [rbp-44h]
unsigned int v25; // [rsp+1Ch] [rbp-3Ch]

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

canonical_decompiled_code:
__int64 __fastcall func10(signed int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v4; // r15
_DWORD *v5; // r14
_DWORD *v6; // r13
unsigned int i; // er15
_DWORD *v8; // rbp
unsigned int j; // ebx
unsigned int v10; // eax
__int64 v11; // rdx
unsigned int v12; // ebx
unsigned int v13; // ebp
__int64 v14; // r13
unsigned int v15; // eax
int v16; // ebx
_QWORD *v17; // rbp
int v18; // ecx
double v19; // xmm1_8
__int64 v20; // r15
__int64 v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+10h] [rbp-48h] BYREF
__int64 v24; // [rsp+14h] [rbp-44h]
unsigned int v25; // [rsp+1Ch] [rbp-3Ch]

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

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; }


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

*(_QWORD *)a1 = a2;
result = a1;
*(_QWORD *)(a1 + 8) = 0x1F4000000004LL;
*(_DWORD *)(a1 + 16) = 1;
return result;
}

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; // esi
int v3; // ecx
__int64 v4; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
int v2; // esi
int v3; // ecx
__int64 v4; // rdx

result = *(_QWORD *)(a1 + 24);
v2 = *(_DWORD *)(result + 24);
if ( v2 > 0 )
{
v3 = 0;
v4 = *(_QWORD *)result + 16LL * (unsigned int)(v2 - 1) + 16;
do
{
result = -16LL * (unsigned int)v2 + v4;
do
{
*(_DWORD *)(result + 4) = 0;
result += 16LL;
}
while ( result != v4 );
++v3;
v4 += 16LL * v2;
}
while ( v2 != v3 );
}
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, float a3, __int64 a4, __int64 a5)
{
__int64 v5; // r13
unsigned int v6; // ebp
int v7; // esi
__int64 v8; // rdi
__int64 result; // rax
__int64 v10; // r12
__int64 v11; // rcx
int v12; // er8
__int64 v13; // rax
unsigned int v14; // eax
__int64 v15; // rax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax

while ( 1 )
{
v5 = a1;
v6 = a2;
v7 = *(_DWORD *)(a1 + 24);
v8 = *(_QWORD *)a1;
result = v8 + 16LL * (HIDWORD(a5) + (int)a5 * v7);
*(float *)(result + 4) = a3 + *(float *)(result + 4);
if ( a3 < 1.0 )
return result;
v10 = a5;
result = get_tiletype(v8, v7, a5);
if ( (_DWORD)result != 1 )
return result;
if ( v12 == 1 )
{
v18 = DR_get_rel(v6, 1LL);
a5 = DR_get_adj(v10, v18);
a3 = a3 / 3.0;
LABEL_9:
a2 = v6;
a1 = v5;
}
else
{
if ( v12 == 2 )
{
v17 = DR_get_rel(v6, 7LL);
a5 = DR_get_adj(v10, v17);
a3 = a3 / 3.0;
goto LABEL_9;
}
if ( v12 )
return result;
v13 = DR_get_adj(v11, v6);
recurse_light(v5, v6, 0LL, v13, 0.5 * a3);
v14 = DR_get_rel(v6, 7LL);
v15 = DR_get_adj(v10, v14);
recurse_light(v5, v6, 2LL, v15, a3 / 3.0);
v16 = DR_get_rel(v6, 1LL);
a3 = a3 / 3.0;
a2 = v6;
a1 = v5;
a5 = DR_get_adj(v10, v16);
}
}
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, float a3, __int64 a4, __int64 a5)
{
__int64 v5; // r13
unsigned int v6; // ebp
int v7; // esi
__int64 v8; // rdi
__int64 result; // rax
__int64 v10; // r12
__int64 v11; // rcx
int v12; // er8
__int64 v13; // rax
unsigned int v14; // eax
__int64 v15; // rax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax

while ( 1 )
{
v5 = a1;
v6 = a2;
v7 = *(_DWORD *)(a1 + 24);
v8 = *(_QWORD *)a1;
result = v8 + 16LL * (HIDWORD(a5) + (int)a5 * v7);
*(float *)(result + 4) = a3 + *(float *)(result + 4);
if ( a3 < 1.0 )
return result;
v10 = a5;
result = func5(v8, v7, a5);
if ( (_DWORD)result != 1 )
return result;
if ( v12 == 1 )
{
v18 = DR_get_rel(v6, 1LL);
a5 = DR_get_adj(v10, v18);
a3 = a3 / 3.0;
LABEL_9:
a2 = v6;
a1 = v5;
}
else
{
if ( v12 == 2 )
{
v17 = DR_get_rel(v6, 7LL);
a5 = DR_get_adj(v10, v17);
a3 = a3 / 3.0;
goto LABEL_9;
}
if ( v12 )
return result;
v13 = DR_get_adj(v11, v6);
func7(v5, v6, 0LL, v13, 0.5 * a3);
v14 = DR_get_rel(v6, 7LL);
v15 = DR_get_adj(v10, v14);
func7(v5, v6, 2LL, v15, a3 / 3.0);
v16 = DR_get_rel(v6, 1LL);
a3 = a3 / 3.0;
a2 = v6;
a1 = v5;
a5 = DR_get_adj(v10, v16);
}
}
}

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

result = 7LL;
if ( a1 <= 6 )
result = (unsigned int)CSWTCH_20[a1];
return result;
}

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

result = 7LL;
if ( a1 <= 6 )
result = (unsigned int)CSWTCH_20[a1];
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; // er12
__int64 v3; // rax
__int64 result; // rax
__int64 v5; // rcx
int v6; // er8

v2 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + 24LL);
v3 = DR_get_adj(*(_QWORD *)a1, a2);
if ( *(_DWORD *)(a1 + 8) == (_DWORD)a2 )
{
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

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

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

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

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
__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);
recurse_light(*(_QWORD *)(a1 + 24), *(_DWORD *)(a1 + 8), (float)(v2 / 1600), 0LL, *(_QWORD *)a1);
result = *(unsigned int *)(a1 + 16);
*(_DWORD *)(a1 + 12) -= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
int v2; // ebp
__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);
func7(*(_QWORD *)(a1 + 24), *(_DWORD *)(a1 + 8), (float)(v2 / 1600), 0LL, *(_QWORD *)a1);
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 }


decompiled_code:
int __fastcall print_info(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8)
{
return printf("player at %d, %d with direction %d\n", (unsigned int)a7, HIDWORD(a7), a8);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8)
{
return printf("player at %d, %d with direction %d\n", (unsigned int)a7, HIDWORD(a7), a8);
}

original_code:
void print_info ( struct mazegame game )
{
    printf ( "player at %d, %d with direction %d\n", game.player.p.x, game.player.p.y, game.player.d );
}

canonical_original_code:
void print_info(struct mazegame game)
{
    printf ( "player at %d, %d with direction %d\n", game.player.p.x, game.player.p.y, game.player.d );
}

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; }


repo: RoboticLtd/pico-ros

decompiled_code:
__int64 __fastcall sapi_respond_getBusInfo(unsigned int a1, __int64 a2, __int64 a3)
{
_QWORD *i; // rbx
_QWORD *j; // rbx
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(_QWORD **)(a2 + 8); i; i = (_QWORD *)i[1] )
xmlmsg_add_topic(sapi_body, *i);
for ( j = *(_QWORD **)(a3 + 8); j; j = (_QWORD *)j[1] )
xmlmsg_add_topic(sapi_body, *j);
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v6 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v6);
v7 = strlen(sapi_header);
comms_send(a1, sapi_header, v7);
v8 = strlen(sapi_body);
return comms_send(a1, sapi_body, v8);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, __int64 a3)
{
_QWORD *i; // rbx
_QWORD *j; // rbx
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(_QWORD **)(a2 + 8); i; i = (_QWORD *)i[1] )
xmlmsg_add_topic(sapi_body, *i);
for ( j = *(_QWORD **)(a3 + 8); j; j = (_QWORD *)j[1] )
xmlmsg_add_topic(sapi_body, *j);
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v6 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v6);
v7 = strlen(sapi_header);
comms_send(a1, sapi_header, v7);
v8 = strlen(sapi_body);
return comms_send(a1, sapi_body, v8);
}

original_code:
void sapi_respond_getBusInfo(int client_socket, list_t* sub, list_t* pub)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    list_item_t* it;
    for(it = sub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (topic_t*)it->data);
    for(it = pub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (topic_t*)it->data);
    xmlmsg_close_tag(sapi_body, "data");
   xmlmsg_close_tag(sapi_body, "array");
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

canonical_original_code:
void sapi_respond_getBusInfo(int client_socket, struct list_t *sub, struct list_t *pub)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    struct list_item_t *it;
    for(it = sub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (struct topic_t *)it->data);
    for(it = pub->begin; it != ((void *)0); it = it->next)
     xmlmsg_add_topic(sapi_body, (struct topic_t *)it->data);
    xmlmsg_close_tag(sapi_body, "data");
   xmlmsg_close_tag(sapi_body, "array");
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

variable_types: struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *

variable_types:
pub
struct list_t *

user_defined_types: struct list_t { int size; struct list_item_t *begin; struct list_item_t *end; }

user_defined_types: struct topic_t { char *name; enum direction_t dir; struct message_type_t *msg_type; void (*callback)(void *); struct list_t *conns; }

user_defined_types: enum direction_t { INBOUND=0, OUTBOUND=1, UNKNOWN=2 }

user_defined_types: struct message_type_t { char *type; char *md5sum; int (*serialize)(char *, void *); void *(*deserialize)(char *buf); void (*free_msg)(void *msg); }


decompiled_code:
__int64 __fastcall sapi_respond_getPid(unsigned int a1, unsigned int a2)
{
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_uint(sapi_body, "i4", a2);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v2 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v2);
v3 = strlen(sapi_header);
comms_send(a1, sapi_header, v3);
v4 = strlen(sapi_body);
return comms_send(a1, sapi_body, v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_uint(sapi_body, "i4", a2);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v2 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v2);
v3 = strlen(sapi_header);
comms_send(a1, sapi_header, v3);
v4 = strlen(sapi_body);
return comms_send(a1, sapi_body, v4);
}

original_code:
void sapi_respond_getPid(int client_socket, unsigned int pid)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_uint(sapi_body, "i4", pid);
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

variable_types:
pid
unsigned int


decompiled_code:
__int64 __fastcall sapi_respond_getPublications_getSubscriptions(unsigned int a1, __int64 a2)
{
__int64 *i; // rbx
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(__int64 **)(a2 + 8); i; i = (__int64 *)i[1] )
{
v3 = *i;
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_add_tag_with_string(sapi_body, "value", *(_QWORD *)v3);
xmlmsg_add_tag_with_string(sapi_body, "value", **(_QWORD **)(v3 + 16));
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
}
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v4 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v4);
v5 = strlen(sapi_header);
comms_send(a1, sapi_header, v5);
v6 = strlen(sapi_body);
return comms_send(a1, sapi_body, v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
__int64 *i; // rbx
__int64 v3; // rbp
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
for ( i = *(__int64 **)(a2 + 8); i; i = (__int64 *)i[1] )
{
v3 = *i;
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "array");
xmlmsg_open_tag(sapi_body, "data");
xmlmsg_add_tag_with_string(sapi_body, "value", *(_QWORD *)v3);
xmlmsg_add_tag_with_string(sapi_body, "value", **(_QWORD **)(v3 + 16));
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
}
xmlmsg_close_tag(sapi_body, "data");
xmlmsg_close_tag(sapi_body, "array");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v4 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v4);
v5 = strlen(sapi_header);
comms_send(a1, sapi_header, v5);
v6 = strlen(sapi_body);
return comms_send(a1, sapi_body, v6);
}

original_code:
void sapi_respond_getPublications_getSubscriptions(int client_socket, list_t* pub)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    list_item_t* it;
    for(it = pub->begin; it != ((void *)0); it = it->next)
    {
     topic_t* t = it->data;
     xmlmsg_open_tag(sapi_body, "value");
      xmlmsg_open_tag(sapi_body, "array");
       xmlmsg_open_tag(sapi_body, "data");
        xmlmsg_add_tag_with_string(sapi_body, "value", t->name);
        xmlmsg_add_tag_with_string(sapi_body, "value", (string)(t->msg_type->type));
       xmlmsg_close_tag(sapi_body, "data");
      xmlmsg_close_tag(sapi_body, "array");
     xmlmsg_close_tag(sapi_body, "value");
    }
    xmlmsg_close_tag(sapi_body, "data");
   xmlmsg_close_tag(sapi_body, "array");
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

canonical_original_code:
void sapi_respond_getPublications_getSubscriptions(int client_socket, struct list_t *pub)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_open_tag(sapi_body, "array");
    xmlmsg_open_tag(sapi_body, "data");
    struct list_item_t *it;
    for(it = pub->begin; it != ((void *)0); it = it->next)
    {
     struct topic_t *t = it->data;
     xmlmsg_open_tag(sapi_body, "value");
      xmlmsg_open_tag(sapi_body, "array");
       xmlmsg_open_tag(sapi_body, "data");
        xmlmsg_add_tag_with_string(sapi_body, "value", t->name);
        xmlmsg_add_tag_with_string(sapi_body, "value", (string)(t->msg_type->type));
       xmlmsg_close_tag(sapi_body, "data");
      xmlmsg_close_tag(sapi_body, "array");
     xmlmsg_close_tag(sapi_body, "value");
    }
    xmlmsg_close_tag(sapi_body, "data");
   xmlmsg_close_tag(sapi_body, "array");
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}

variable_types: struct topic_t { char *name; enum direction_t { INBOUND=0, OUTBOUND=1, UNKNOWN=2 } dir; struct message_type_t { char *type; char *md5sum; int (*serialize)(char *, void *); void *(*deserialize)(char *buf); void (*free_msg)(void *msg); } *msg_type; void (*callback)(void *); struct list_t { int size; struct list_item_t { void *data; struct list_item_t *next; } *begin; struct list_item_t *end; } *conns; } *


decompiled_code:
__int64 __fastcall sapi_respond_publisherUpdate(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v1 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v1);
v2 = strlen(sapi_header);
comms_send(a1, sapi_header, v2);
v3 = strlen(sapi_body);
return comms_send(a1, sapi_body, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax

xmlmsg_init(sapi_body);
xmlmsg_open_method_response(sapi_body);
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_open_tag(sapi_body, "value");
xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0LL);
xmlmsg_close_tag(sapi_body, "value");
xmlmsg_close_method_response(sapi_body);
v1 = strlen(sapi_body);
sprintf(sapi_header, "HTTP/1.1 200 OK\nContent-Type: text/xml\nContent-length: %d\n\n", v1);
v2 = strlen(sapi_header);
comms_send(a1, sapi_header, v2);
v3 = strlen(sapi_body);
return comms_send(a1, sapi_body, v3);
}

original_code:
void sapi_respond_publisherUpdate(int client_socket)
{
 xmlmsg_init(sapi_body);
 xmlmsg_open_method_response(sapi_body);
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 1);
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
  xmlmsg_close_tag(sapi_body, "value");
  xmlmsg_open_tag(sapi_body, "value");
   xmlmsg_add_tag_with_ushort(sapi_body, "i4", 0);
  xmlmsg_close_tag(sapi_body, "value");
 xmlmsg_close_method_response(sapi_body);
 sprintf(sapi_header, response_header_prototype, strlen(sapi_body));
 comms_send(client_socket, sapi_header, strlen(sapi_header));
 comms_send(client_socket, sapi_body, strlen(sapi_body));
}