decompiled_code:
__int64 __fastcall spt_copyenv(char **a1)
{
unsigned int v1; // er13
int v4; // eax
char *v5; // rdi
const char **v6; // rbp
char *v7; // rax
char *v8; // rbx

v1 = 0;
if ( environ == a1 )
{
v4 = spt_clearenv();
v1 = v4;
if ( v4 )
{
LABEL_11:
environ = a1;
v1 = v4;
}
else
{
v5 = *a1;
if ( *a1 )
{
v6 = (const char **)a1;
do
{
v7 = strchr(v5, 61);
v8 = v7;
if ( v7 )
{
*v7 = 0;
if ( setenv(*v6, v7 + 1, 1) )
{
v4 = *_errno_location();
*v8 = 61;
if ( v4 )
goto LABEL_11;
}
else
{
*v8 = 61;
}
}
v5 = (char *)*++v6;
}
while ( *v6 );
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1)
{
unsigned int v1; // er13
int v4; // eax
char *v5; // rdi
const char **v6; // rbp
char *v7; // rax
char *v8; // rbx

v1 = 0;
if ( environ == a1 )
{
v4 = func2();
v1 = v4;
if ( v4 )
{
LABEL_11:
environ = a1;
v1 = v4;
}
else
{
v5 = *a1;
if ( *a1 )
{
v6 = (const char **)a1;
do
{
v7 = strchr(v5, 61);
v8 = v7;
if ( v7 )
{
*v7 = 0;
if ( setenv(*v6, v7 + 1, 1) )
{
v4 = *_errno_location();
*v8 = 61;
if ( v4 )
goto LABEL_11;
}
else
{
*v8 = 61;
}
}
v5 = (char *)*++v6;
}
while ( *v6 );
}
}
}
return v1;
}

original_code:
static int spt_copyenv(char *oldenv[]) {
 extern char **environ;
 char *eq;
 int i, error;
 if (environ != oldenv)
  return 0;
 if ((error = spt_clearenv()))
  goto error;
 for (i = 0; oldenv[i]; i++) {
  if (!(eq = strchr(oldenv[i], '=')))
   continue;
  *eq = '\0';
  error = (0 != setenv(oldenv[i], eq + 1, 1))? (*__errno_location ()) : 0;
  *eq = '=';
  if (error)
   goto error;
 }
 return 0;
error:
 environ = oldenv;
 return error;
}

canonical_original_code:
static int spt_copyenv(char *oldenv[]) {
 extern char **environ;
 char *eq;
 int i; int error;
 if (environ != oldenv)
  return 0;
 if ((error = spt_clearenv()))
  goto error;
 for (i = 0; oldenv[i]; i++) {
  if (!(eq = strchr(oldenv[i], '=')))
   continue;
  *eq = '\0';
  error = (0 != setenv(oldenv[i], eq + 1, 1))? (*__errno_location ()) : 0;
  *eq = '=';
  if (error)
   goto error;
 }
 return 0;
error:
 environ = oldenv;
 return error;
}

variable_types:
oldenv
char *[]

variable_types:
environ
char **

variable_types:
eq
char *

variable_types: error int


decompiled_code:
void __fastcall spt_init(int a1, const char **a2, char **a3)
{
const char *v3; // r15
size_t v4; // r12
__int64 i; // rbx
const char *v6; // rbp
const char *v7; // rbx
char **v8; // rbp
char *v9; // rax
char *v10; // rax
int v11; // eax
__int64 v13; // [rsp+8h] [rbp-40h]

v3 = *a2;
if ( *a2 )
{
v13 = (__int64)&v3[strlen(*a2)];
v4 = v13 + 1;
for ( i = 0LL; a1 > (int)i || a2[i]; ++i )
{
v6 = a2[i];
if ( (unsigned __int64)v6 >= v4 )
{
if ( v6 )
v4 = (size_t)&v6[strlen(a2[i]) + 1];
}
}
v7 = *a3;
if ( *a3 )
{
v8 = a3 + 1;
do
{
if ( (unsigned __int64)v7 >= v4 )
v4 = (size_t)&v7[strlen(v7) + 1];
v7 = *v8++;
}
while ( v7 );
}
SPT = (__int64)strdup(v3);
if ( SPT
&& (v9 = strdup(program_invocation_name)) != 0LL
&& (program_invocation_name = v9, (v10 = strdup(program_invocation_short_name)) != 0LL) )
{
program_invocation_short_name = v10;
v11 = spt_copyenv(a3);
if ( !v11 )
{
v11 = spt_copyargs(a1, (__int64)a2);
if ( !v11 )
{
qword_458 = v13;
dest = (void *)v3;
qword_450 = v4;
return;
}
}
}
else
{
v11 = *_errno_location();
}
dword_464 = v11;
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, const char **a2, char **a3)
{
const char *v3; // r15
size_t v4; // r12
__int64 i; // rbx
const char *v6; // rbp
const char *v7; // rbx
char **v8; // rbp
char *v9; // rax
char *v10; // rax
int v11; // eax
__int64 v13; // [rsp+8h] [rbp-40h]

v3 = *a2;
if ( *a2 )
{
v13 = (__int64)&v3[strlen(*a2)];
v4 = v13 + 1;
for ( i = 0LL; a1 > (int)i || a2[i]; ++i )
{
v6 = a2[i];
if ( (unsigned __int64)v6 >= v4 )
{
if ( v6 )
v4 = (size_t)&v6[strlen(a2[i]) + 1];
}
}
v7 = *a3;
if ( *a3 )
{
v8 = a3 + 1;
do
{
if ( (unsigned __int64)v7 >= v4 )
v4 = (size_t)&v7[strlen(v7) + 1];
v7 = *v8++;
}
while ( v7 );
}
SPT = (__int64)strdup(v3);
if ( SPT
&& (v9 = strdup(program_invocation_name)) != 0LL
&& (program_invocation_name = v9, (v10 = strdup(program_invocation_short_name)) != 0LL) )
{
program_invocation_short_name = v10;
v11 = func3(a3);
if ( !v11 )
{
v11 = func1(a1, (__int64)a2);
if ( !v11 )
{
qword_458 = v13;
dest = (void *)v3;
qword_450 = v4;
return;
}
}
}
else
{
v11 = *_errno_location();
}
dword_464 = v11;
}
}

original_code:
void spt_init(int argc, char *argv[], char *envp[]) {
 char *base, *end, *nul, *tmp;
 int i, error;
 if (!(base = argv[0]))
  return;
 nul = &base[strlen(base)];
 end = nul + 1;
 for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
  if (!argv[i] || argv[i] < end)
   continue;
  end = argv[i] + strlen(argv[i]) + 1;
 }
 for (i = 0; envp[i]; i++) {
  if (envp[i] < end)
   continue;
  end = envp[i] + strlen(envp[i]) + 1;
 }
 if (!(SPT.arg0 = strdup(argv[0])))
  goto syerr;
 if (!(tmp = strdup(program_invocation_name)))
  goto syerr;
 program_invocation_name = tmp;
 if (!(tmp = strdup(program_invocation_short_name)))
  goto syerr;
 program_invocation_short_name = tmp;
 if ((error = spt_copyenv(envp)))
  goto error;
 if ((error = spt_copyargs(argc, argv)))
  goto error;
 SPT.nul = nul;
 SPT.base = base;
 SPT.end = end;
 return;
syerr:
 error = (*__errno_location ());
error:
 SPT.error = error;
}

canonical_original_code:
void spt_init(int argc, char *argv[], char *envp[]) {
 char *base; char *end; char *nul; char *tmp;
 int i; int error;
 if (!(base = argv[0]))
  return;
 nul = &base[strlen(base)];
 end = nul + 1;
 for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
  if (!argv[i] || argv[i] < end)
   continue;
  end = argv[i] + strlen(argv[i]) + 1;
 }
 for (i = 0; envp[i]; i++) {
  if (envp[i] < end)
   continue;
  end = envp[i] + strlen(envp[i]) + 1;
 }
 if (!(SPT.arg0 = strdup(argv[0])))
  goto syerr;
 if (!(tmp = strdup(program_invocation_name)))
  goto syerr;
 program_invocation_name = tmp;
 if (!(tmp = strdup(program_invocation_short_name)))
  goto syerr;
 program_invocation_short_name = tmp;
 if ((error = spt_copyenv(envp)))
  goto error;
 if ((error = spt_copyargs(argc, argv)))
  goto error;
 SPT.nul = nul;
 SPT.base = base;
 SPT.end = end;
 return;
syerr:
 error = (*__errno_location ());
error:
 SPT.error = error;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
envp
char *[]

variable_types:
base
char *

variable_types:
end
char *

variable_types:
nul
char *

variable_types:
tmp
char *

variable_types: i int

return_type: void


setproctitle

decompiled_code:
void setproctitle(char *format, ...)
{
int v1; // ebx
unsigned __int64 v2; // r12
char *v3; // rbp
unsigned __int64 v4; // rax
size_t v5; // rbx
char *v6; // rax
void *v7; // rbp
unsigned __int64 v8; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( dest )
{
if ( format )
{
va_start(arg, format);
v1 = vsnprintf(s, 0x100uLL, format, arg);
}
else
{
v1 = snprintf(s, 0x100uLL, "%s", (const char *)SPT);
}
if ( v1 <= 0 )
{
dword_464 = *_errno_location();
}
else
{
if ( byte_460 )
{
v7 = dest;
v8 = spt_min(0x100uLL, qword_450 - (_QWORD)dest);
memset(v7, 0, v8);
}
else
{
memset(dest, 0, qword_450 - (_QWORD)dest);
byte_460 = 1;
}
v2 = qword_450;
v3 = (char *)dest;
v4 = spt_min(0x100uLL, qword_450 - (_QWORD)dest);
v5 = (int)spt_min(v1, v4 - 1);
memcpy(v3, s, v5);
v6 = &v3[v5];
if ( qword_458 <= (unsigned __int64)&v3[v5] )
{
if ( (char *)qword_458 == &v3[v5] && v2 > (unsigned __int64)(v6 + 1) )
{
*(_BYTE *)qword_458 = 32;
v6[1] = 0;
}
}
else
{
*(_BYTE *)qword_458 = 46;
}
}
}
}

canonical_decompiled_code:
void func5(char *format, ...)
{
int v1; // ebx
unsigned __int64 v2; // r12
char *v3; // rbp
unsigned __int64 v4; // rax
size_t v5; // rbx
char *v6; // rax
void *v7; // rbp
unsigned __int64 v8; // rax
gcc_va_list arg; // [rsp+8h] [rbp-1E0h] BYREF
char s[256]; // [rsp+20h] [rbp-1C8h] BYREF

if ( dest )
{
if ( format )
{
va_start(arg, format);
v1 = vsnprintf(s, 0x100uLL, format, arg);
}
else
{
v1 = snprintf(s, 0x100uLL, "%s", (const char *)SPT);
}
if ( v1 <= 0 )
{
dword_464 = *_errno_location();
}
else
{
if ( byte_460 )
{
v7 = dest;
v8 = func0(0x100uLL, qword_450 - (_QWORD)dest);
memset(v7, 0, v8);
}
else
{
memset(dest, 0, qword_450 - (_QWORD)dest);
byte_460 = 1;
}
v2 = qword_450;
v3 = (char *)dest;
v4 = func0(0x100uLL, qword_450 - (_QWORD)dest);
v5 = (int)func0(v1, v4 - 1);
memcpy(v3, s, v5);
v6 = &v3[v5];
if ( qword_458 <= (unsigned __int64)&v3[v5] )
{
if ( (char *)qword_458 == &v3[v5] && v2 > (unsigned __int64)(v6 + 1) )
{
*(_BYTE *)qword_458 = 32;
v6[1] = 0;
}
}
else
{
*(_BYTE *)qword_458 = 46;
}
}
}
}

original_code:
void setproctitle(const char *fmt, ...) {
 char buf[255 + 1];
 va_list ap;
 char *nul;
 int len, error;
 if (!SPT.base)
  return;
 if (fmt) {
  __builtin_va_start(ap,fmt);
  len = vsnprintf(buf, sizeof buf, fmt, ap);
  __builtin_va_end(ap);
 } else {
  len = snprintf(buf, sizeof buf, "%s", SPT.arg0);
 }
 if (len <= 0)
  { error = (*__errno_location ()); goto error; }
 if (!SPT.reset) {
  memset(SPT.base, 0, SPT.end - SPT.base);
  SPT.reset = 1;
 } else {
  memset(SPT.base, 0, spt_min(sizeof buf, SPT.end - SPT.base));
 }
 len = spt_min(len, spt_min(sizeof buf, SPT.end - SPT.base) - 1);
 memcpy(SPT.base, buf, len);
 nul = &SPT.base[len];
 if (nul < SPT.nul) {
  *SPT.nul = '.';
 } else if (nul == SPT.nul && &nul[1] < SPT.end) {
  *SPT.nul = ' ';
  *++nul = '\0';
 }
 return;
error:
 SPT.error = error;
}

canonical_original_code:
void setproctitle(char *fmt, ...) {
 char buf[-1];
 __builtin_va_list ap;
 char *nul;
 int len; int error;
 if (!SPT.base)
  return;
 if (fmt) {
  __builtin_va_start(ap,fmt);
  len = vsnprintf(buf, sizeof buf, fmt, ap);
  __builtin_va_end(ap);
 } else {
  len = snprintf(buf, sizeof buf, "%s", SPT.arg0);
 }
 if (len <= 0)
  { error = (*__errno_location ()); goto error; }
 if (!SPT.reset) {
  memset(SPT.base, 0, SPT.end - SPT.base);
  SPT.reset = 1;
 } else {
  memset(SPT.base, 0, spt_min(sizeof buf, SPT.end - SPT.base));
 }
 len = spt_min(len, spt_min(sizeof buf, SPT.end - SPT.base) - 1);
 memcpy(SPT.base, buf, len);
 nul = &SPT.base[len];
 if (nul < SPT.nul) {
  *SPT.nul = '.';
 } else if (nul == SPT.nul && &nul[1] < SPT.end) {
  *SPT.nul = ' ';
  *++nul = '\0';
 }
 return;
error:
 SPT.error = error;
}

variable_types:
fmt
char *

variable_types:
buf
char [-1]

variable_types: len int


decompiled_code:
int __fastcall report_metro_type_stats(__int64 *a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
bool v3; // zf
__int64 v4; // rdx

v1 = *a1;
v2 = a1[1] + *a1;
v3 = a1[2] + v2 == 0;
v4 = a1[2] + v2;
a1[3] = v4;
if ( v3 )
return puts("# None.");
if ( v1 )
printf("# Metropolis selves: %9lld / %9lld (%7.3lf%%)\n", v1, v4, (double)(int)v1 * 100.0 / (double)(int)v4);
printf(
"# Metropolis keeps: %9lld / %9lld (%7.3lf%%)\n",
a1[1],
a1[3],
(double)(int)a1[1] * 100.0 / (double)(int)a1[3]);
return printf(
"# Metropolis changes: %9lld / %9lld (%7.3lf%%)\n",
a1[2],
a1[3],
(double)(int)a1[2] * 100.0 / (double)(int)a1[3]);
}

original_code:
void report_metro_type_stats(metro_type_stats_t* pstats)
{
 pstats->num_total = pstats->num_self
  + pstats->num_keep + pstats->num_change;
 if (pstats->num_total == 0) {
  printf("#   None.\n");
  return;
 }
 if (pstats->num_self != 0) {
  printf("#   Metropolis selves:  %9lld / %9lld (%7.3lf%%)\n",
   pstats->num_self, pstats->num_total,
   (double)pstats->num_self*100.0/(double)pstats->num_total);
 }
 printf("#   Metropolis keeps:   %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_keep, pstats->num_total,
  (double)pstats->num_keep*100.0/(double)pstats->num_total);
 printf("#   Metropolis changes: %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_change, pstats->num_total,
  (double)pstats->num_change*100.0/(double)pstats->num_total);
}

canonical_original_code:
void report_metro_type_stats(struct _metro_type_stats_t *pstats)
{
 pstats->num_total = pstats->num_self
  + pstats->num_keep + pstats->num_change;
 if (pstats->num_total == 0) {
  printf("#   None.\n");
  return;
 }
 if (pstats->num_self != 0) {
  printf("#   Metropolis selves:  %9lld / %9lld (%7.3lf%%)\n",
   pstats->num_self, pstats->num_total,
   (double)pstats->num_self*100.0/(double)pstats->num_total);
 }
 printf("#   Metropolis keeps:   %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_keep, pstats->num_total,
  (double)pstats->num_keep*100.0/(double)pstats->num_total);
 printf("#   Metropolis changes: %9lld / %9lld (%7.3lf%%)\n",
  pstats->num_change, pstats->num_total,
  (double)pstats->num_change*100.0/(double)pstats->num_total);
}

variable_types: struct _metro_type_stats_t { long long num_self; long long num_keep; long long num_change; long long num_total; } *


decompiled_code:
int __fastcall report_metro_stats(__int64 *a1)
{
puts("# OPENS:");
report_metro_type_stats(a1);
puts("# CLOSES:");
report_metro_type_stats(a1 + 4);
puts("# HS:");
report_metro_type_stats(a1 + 8);
puts("# TS:");
report_metro_type_stats(a1 + 12);
puts("# SO:");
return report_metro_type_stats(a1 + 16);
}

canonical_decompiled_code:
int __fastcall func3(__int64 *a1)
{
puts("# OPENS:");
func1(a1);
puts("# CLOSES:");
func1(a1 + 4);
puts("# HS:");
func1(a1 + 8);
puts("# TS:");
func1(a1 + 12);
puts("# SO:");
return func1(a1 + 16);
}

original_code:
void report_metro_stats(metro_stats_t* pmetro_stats)
{
 printf("# OPENS:\n"); report_metro_type_stats(&pmetro_stats->open_stats);
 printf("# CLOSES:\n"); report_metro_type_stats(&pmetro_stats->close_stats);
 printf("# HS:\n"); report_metro_type_stats(&pmetro_stats->HS_stats);
 printf("# TS:\n"); report_metro_type_stats(&pmetro_stats->TS_stats);
 printf("# SO:\n"); report_metro_type_stats(&pmetro_stats->SO_stats);
}

canonical_original_code:
void report_metro_stats(struct _metro_stats_t *pmetro_stats)
{
 printf("# OPENS:\n"); report_metro_type_stats(&pmetro_stats->open_stats);
 printf("# CLOSES:\n"); report_metro_type_stats(&pmetro_stats->close_stats);
 printf("# HS:\n"); report_metro_type_stats(&pmetro_stats->HS_stats);
 printf("# TS:\n"); report_metro_type_stats(&pmetro_stats->TS_stats);
 printf("# SO:\n"); report_metro_type_stats(&pmetro_stats->SO_stats);
}

variable_types: struct _metro_stats_t { struct _metro_type_stats_t { long long num_self; long long num_keep; long long num_change; long long num_total; } open_stats; struct _metro_type_stats_t close_stats; struct _metro_type_stats_t HS_stats; struct _metro_type_stats_t TS_stats; struct _metro_type_stats_t SO_stats; } *

user_defined_types: struct _metro_stats_t { struct _metro_type_stats_t open_stats; struct _metro_type_stats_t close_stats; struct _metro_type_stats_t HS_stats; struct _metro_type_stats_t TS_stats; struct _metro_type_stats_t SO_stats; }


decompiled_code:
void __fastcall check_magic_number(unsigned int a1, const char *a2, const char *a3)
{
if ( a1 != 558711634 )
{
fprintf(stderr, "%s: expected %s 0x%08x; got 0x%08x.\n", a3, a2, 558711634LL, a1);
fwrite("Incorrect file format, or file format has changed?\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1, const char *a2, const char *a3)
{
if ( a1 != 558711634 )
{
fprintf(stderr, "%s: expected %s 0x%08x; got 0x%08x.\n", a3, a2, 558711634LL, a1);
fwrite("Incorrect file format, or file format has changed?\n", 1uLL, 0x33uLL, stderr);
exit(1);
}
}

original_code:
static void check_magic_number(unsigned file_value,
 char* var_name, char* func_name)
{
 if (file_value != 0x214d4352) {
  fprintf(stderr,
  "%s:  expected %s 0x%08x; got 0x%08x.\n",
   func_name, var_name,
   0x214d4352, file_value);
  fprintf(stderr, "Incorrect file format, or file format has changed?\n");
  exit(1);
 }
}

canonical_original_code:
static void check_magic_number(unsigned int file_value, char *var_name, char *func_name)
{
 if (file_value != 0x214d4352) {
  fprintf(stderr,
  "%s:  expected %s 0x%08x; got 0x%08x.\n",
   func_name, var_name,
   0x214d4352, file_value);
  fprintf(stderr, "Incorrect file format, or file format has changed?\n");
  exit(1);
 }
}


decompiled_code:
int __fastcall print_mcmc_params(__int64 a1)
{
const char *v1; // rax
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rsi
const char *v5; // rsi
__int64 v6; // rsi
__int64 v7; // rsi
const char *v8; // rdx
__int64 v9; // rsi
const char *v10; // rcx
const char *v11; // rdx
__int64 v12; // rsi
const char *v13; // rdx

v1 = (const char *)get_rng_type_desc(*(unsigned int *)(a1 + 4));
printf("# RNG = %s\n", v1);
if ( *(_DWORD *)(a1 + 12) )
printf("# RNG seed = 0x%08x\n", *(unsigned int *)(a1 + 8));
v2 = ipow(*(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
printf("# L = %d d = %d N = %d\n", *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20), v2);
puts("# Boundary conditions: periodic.");
printf(
"# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
1.0 / *(double *)(a1 + 24),
*(double *)(a1 + 24),
*(double *)(a1 + 32));
printf("# gamma = %11.7lf\n", *(double *)(a1 + 48));
v3 = (const char *)get_interaction_type_desc(*(unsigned int *)(a1 + 40));
printf("# Interactions: %s.\n", v3);
v4 = "uniform random";
if ( !*(_DWORD *)(a1 + 72) )
{
v4 = "Wx=1";
if ( !*(_DWORD *)(a1 + 76) )
{
v4 = "Wy=1";
if ( !*(_DWORD *)(a1 + 80) )
{
v4 = "Wz=1";
if ( !*(_DWORD *)(a1 + 84) )
v4 = "identity";
}
}
}
printf("# Initial permutation: %s.\n", v4);
v5 = "random";
if ( !*(_DWORD *)(a1 + 88) )
v5 = "sequential";
printf("# Site selection for Metropolis sweeps: %s.\n", v5);
v6 = *(unsigned int *)(a1 + 108);
if ( (_DWORD)v6 == -1 )
{
printf("# Thermalization is detected by %d turning points of system energy\n", *(unsigned int *)(a1 + 116));
printf("# smoothed over a %d-point window.\n", *(unsigned int *)(a1 + 112));
}
else
{
printf("# %d pre-accumulation sweeps having occurred.\n", v6);
}
v7 = *(unsigned int *)(a1 + 104);
v8 = (const char *)&unk_782;
if ( (_DWORD)v7 != 1 )
v8 = "s";
printf("# Terminate after %d accumulation%s:\n", v7, v8);
v9 = *(unsigned int *)(a1 + 96);
v10 = (const char *)&unk_782;
if ( (_DWORD)v9 != 1 )
v10 = "s";
v11 = "SAR";
if ( !*(_DWORD *)(a1 + 92) )
v11 = "SO";
printf("# * %d %s sweep%s per accumulation.\n", v9, v11, v10);
v12 = *(unsigned int *)(a1 + 100);
v13 = (const char *)&unk_782;
if ( (_DWORD)v12 != 1 )
v13 = "s";
return printf("# * %d worm sweep%s per accumulation.\n", v12, v13);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
const char *v1; // rax
unsigned int v2; // eax
const char *v3; // rax
const char *v4; // rsi
const char *v5; // rsi
__int64 v6; // rsi
__int64 v7; // rsi
const char *v8; // rdx
__int64 v9; // rsi
const char *v10; // rcx
const char *v11; // rdx
__int64 v12; // rsi
const char *v13; // rdx

v1 = (const char *)get_rng_type_desc(*(unsigned int *)(a1 + 4));
printf("# RNG = %s\n", v1);
if ( *(_DWORD *)(a1 + 12) )
printf("# RNG seed = 0x%08x\n", *(unsigned int *)(a1 + 8));
v2 = ipow(*(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20));
printf("# L = %d d = %d N = %d\n", *(unsigned int *)(a1 + 16), *(unsigned int *)(a1 + 20), v2);
puts("# Boundary conditions: periodic.");
printf(
"# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
1.0 / *(double *)(a1 + 24),
*(double *)(a1 + 24),
*(double *)(a1 + 32));
printf("# gamma = %11.7lf\n", *(double *)(a1 + 48));
v3 = (const char *)get_interaction_type_desc(*(unsigned int *)(a1 + 40));
printf("# Interactions: %s.\n", v3);
v4 = "uniform random";
if ( !*(_DWORD *)(a1 + 72) )
{
v4 = "Wx=1";
if ( !*(_DWORD *)(a1 + 76) )
{
v4 = "Wy=1";
if ( !*(_DWORD *)(a1 + 80) )
{
v4 = "Wz=1";
if ( !*(_DWORD *)(a1 + 84) )
v4 = "identity";
}
}
}
printf("# Initial permutation: %s.\n", v4);
v5 = "random";
if ( !*(_DWORD *)(a1 + 88) )
v5 = "sequential";
printf("# Site selection for Metropolis sweeps: %s.\n", v5);
v6 = *(unsigned int *)(a1 + 108);
if ( (_DWORD)v6 == -1 )
{
printf("# Thermalization is detected by %d turning points of system energy\n", *(unsigned int *)(a1 + 116));
printf("# smoothed over a %d-point window.\n", *(unsigned int *)(a1 + 112));
}
else
{
printf("# %d pre-accumulation sweeps having occurred.\n", v6);
}
v7 = *(unsigned int *)(a1 + 104);
v8 = (const char *)&unk_782;
if ( (_DWORD)v7 != 1 )
v8 = "s";
printf("# Terminate after %d accumulation%s:\n", v7, v8);
v9 = *(unsigned int *)(a1 + 96);
v10 = (const char *)&unk_782;
if ( (_DWORD)v9 != 1 )
v10 = "s";
v11 = "SAR";
if ( !*(_DWORD *)(a1 + 92) )
v11 = "SO";
printf("# * %d %s sweep%s per accumulation.\n", v9, v11, v10);
v12 = *(unsigned int *)(a1 + 100);
v13 = (const char *)&unk_782;
if ( (_DWORD)v12 != 1 )
v13 = "s";
return printf("# * %d worm sweep%s per accumulation.\n", v12, v13);
}

original_code:
void print_mcmc_params(mcmc_params_t* p)
{
 printf("# RNG = %s\n", get_rng_type_desc(p->rng_type));
 if (p->do_seed)
  printf("# RNG seed = 0x%08x\n", p->seed);
 printf("# L = %d d = %d N = %d\n", p->L, p->d, ipow(p->L, p->d));
 printf("# Boundary conditions: periodic.\n");
 printf("# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
  1.0 / p->beta, p->beta, p->alpha0);
 printf("# gamma = %11.7lf\n", p->gamma);
 printf("# Interactions:  %s.\n",
  get_interaction_type_desc(p->interaction_type));
 printf("# Initial permutation: %s.\n",
  p->rand_init_pi ? "uniform random" :
  p->wx1_init_pi ? "Wx=1" :
  p->wy1_init_pi ? "Wy=1" :
  p->wz1_init_pi ? "Wz=1" :
  "identity");
 printf("# Site selection for Metropolis sweeps: %s.\n",
  p->do_random_sweep ? "random" : "sequential");
 if (p->force_therm == -1) {
  printf("# Thermalization is detected by %d turning points of system "
   "energy\n", p->therm_ntp);
  printf("# smoothed over a %d-point window.\n",
   p->smoothing_window_size);
 }
 else {
  printf("# %d pre-accumulation sweeps having occurred.\n",
   p->force_therm);
 }
 printf("# Terminate after %d accumulation%s:\n",
  p->termination_num_acc,
  p->termination_num_acc == 1 ? "" : "s");
 printf("# * %d %s  sweep%s per accumulation.\n",
  p->gsweeps_per_acc,
  p->allow_cycle_reversals ? "SAR" : "SO",
  p->gsweeps_per_acc == 1 ? "" : "s");
 printf("# * %d worm sweep%s per accumulation.\n",
  p->wsweeps_per_acc, p->wsweeps_per_acc == 1 ? "" : "s");
}

canonical_original_code:
void print_mcmc_params(struct _mcmc_params_t *p)
{
 printf("# RNG = %s\n", get_rng_type_desc(p->rng_type));
 if (p->do_seed)
  printf("# RNG seed = 0x%08x\n", p->seed);
 printf("# L = %d d = %d N = %d\n", p->L, p->d, ipow(p->L, p->d));
 printf("# Boundary conditions: periodic.\n");
 printf("# T = %11.7lf beta = %11.7lf alpha0 = %11.7lf\n",
  1.0 / p->beta, p->beta, p->alpha0);
 printf("# gamma = %11.7lf\n", p->gamma);
 printf("# Interactions:  %s.\n",
  get_interaction_type_desc(p->interaction_type));
 printf("# Initial permutation: %s.\n",
  p->rand_init_pi ? "uniform random" :
  p->wx1_init_pi ? "Wx=1" :
  p->wy1_init_pi ? "Wy=1" :
  p->wz1_init_pi ? "Wz=1" :
  "identity");
 printf("# Site selection for Metropolis sweeps: %s.\n",
  p->do_random_sweep ? "random" : "sequential");
 if (p->force_therm == -1) {
  printf("# Thermalization is detected by %d turning points of system "
   "energy\n", p->therm_ntp);
  printf("# smoothed over a %d-point window.\n",
   p->smoothing_window_size);
 }
 else {
  printf("# %d pre-accumulation sweeps having occurred.\n",
   p->force_therm);
 }
 printf("# Terminate after %d accumulation%s:\n",
  p->termination_num_acc,
  p->termination_num_acc == 1 ? "" : "s");
 printf("# * %d %s  sweep%s per accumulation.\n",
  p->gsweeps_per_acc,
  p->allow_cycle_reversals ? "SAR" : "SO",
  p->gsweeps_per_acc == 1 ? "" : "s");
 printf("# * %d worm sweep%s per accumulation.\n",
  p->wsweeps_per_acc, p->wsweeps_per_acc == 1 ? "" : "s");
}

variable_types: struct _mcmc_params_t { unsigned int magic_number; int rng_type; unsigned int seed; int do_seed; int L; int d; double beta; double alpha0; int interaction_type; int pad; double gamma; int tbd1; int tbd2; int tbd3; int tbd4; int rand_init_pi; int wx1_init_pi; int wy1_init_pi; int wz1_init_pi; int do_random_sweep; int allow_cycle_reversals; int gsweeps_per_acc; int wsweeps_per_acc; int termination_num_acc; int force_therm; int smoothing_window_size; int therm_ntp; unsigned int magic_number2; } *


decompiled_code:
int __fastcall display_footer(double *a1)
{
report_metro_stats(a1 + 4);
printf("# Elapsed thermalization seconds: %.6lf\n", a1[2] - a1[1]);
printf("# Elapsed accumulation seconds: %.6lf\n", a1[3] - a1[2]);
return printf("# Elapsed total seconds: %.6lf\n", a1[3] - a1[1]);
}

canonical_decompiled_code:
int __fastcall func7(double *a1)
{
report_metro_stats(a1 + 4);
printf("# Elapsed thermalization seconds: %.6lf\n", a1[2] - a1[1]);
printf("# Elapsed accumulation seconds: %.6lf\n", a1[3] - a1[2]);
return printf("# Elapsed total seconds: %.6lf\n", a1[3] - a1[1]);
}

original_code:
void display_footer(mcmc_footer_t* pfooter)
{
 report_metro_stats(&pfooter->metro_stats);
 printf("# Elapsed thermalization seconds: %.6lf\n",
  pfooter->therm_time - pfooter->start_time);
 printf("# Elapsed accumulation   seconds: %.6lf\n",
  pfooter->end_time - pfooter->therm_time);
 printf("# Elapsed total seconds:          %.6lf\n",
  pfooter->end_time - pfooter->start_time);
}

canonical_original_code:
void display_footer(struct _mcmc_footer_t *pfooter)
{
 report_metro_stats(&pfooter->metro_stats);
 printf("# Elapsed thermalization seconds: %.6lf\n",
  pfooter->therm_time - pfooter->start_time);
 printf("# Elapsed accumulation   seconds: %.6lf\n",
  pfooter->end_time - pfooter->therm_time);
 printf("# Elapsed total seconds:          %.6lf\n",
  pfooter->end_time - pfooter->start_time);
}

variable_types: struct _mcmc_footer_t { unsigned int magic_number; int pad; double start_time; double therm_time; double end_time; struct _metro_stats_t { struct _metro_type_stats_t { long long num_self; long long num_keep; long long num_change; long long num_total; } open_stats; struct _metro_type_stats_t close_stats; struct _metro_type_stats_t HS_stats; struct _metro_type_stats_t TS_stats; struct _metro_type_stats_t SO_stats; } metro_stats; int tbd[4]; unsigned int magic_number2; } *

user_defined_types: struct _mcmc_footer_t { unsigned int magic_number; int pad; double start_time; double therm_time; double end_time; struct _metro_stats_t metro_stats; int tbd[4]; unsigned int magic_number2; }


decompiled_code:
const char *__fastcall get_interaction_type_desc(int a1)
{
const char *result; // rax

if ( a1 == 33 )
return "constant r_ell";
if ( a1 <= 33 )
{
result = "none";
if ( a1 != 11 )
{
result = "(undefined interaction type)";
if ( a1 == 22 )
result = "r2";
}
}
else
{
result = "Vzw lower";
if ( a1 != 44 )
{
result = "(undefined interaction type)";
if ( a1 == 55 )
result = "Vzw upper";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

if ( a1 == 33 )
return "constant r_ell";
if ( a1 <= 33 )
{
result = "none";
if ( a1 != 11 )
{
result = "(undefined interaction type)";
if ( a1 == 22 )
result = "r2";
}
}
else
{
result = "Vzw lower";
if ( a1 != 44 )
{
result = "(undefined interaction type)";
if ( a1 == 55 )
result = "Vzw upper";
}
}
return result;
}

original_code:
char* get_interaction_type_desc(int interaction_type)
{
 switch (interaction_type) {
 case 11: return "none"; break;
 case 22: return "r2"; break;
 case 33: return "constant r_ell"; break;
 case 44: return "Vzw lower"; break;
 case 55: return "Vzw upper"; break;
 default:
  return "(undefined interaction type)";
  break;
 }
}

canonical_original_code:
char *get_interaction_type_desc(int interaction_type)
{
 switch (interaction_type) {
 case 11: return "none"; break;
 case 22: return "r2"; break;
 case 33: return "constant r_ell"; break;
 case 44: return "Vzw lower"; break;
 case 55: return "Vzw upper"; break;
 default:
  return "(undefined interaction type)";
  break;
 }
}

return_type: char *


decompiled_code:
double *__fastcall get_alphas(int a1, int a2, double a3)
{
double *v3; // rax
double *v4; // rcx
double *v5; // rdx
double *v7; // rax

v3 = (double *)double_malloc_or_die((unsigned int)(a2 + 1));
v4 = v3;
if ( a2 >= 0 )
{
v5 = &v3[a2 + 1];
do
*v3++ = 0.0;
while ( v3 != v5 );
}
if ( a1 == 33 )
{
if ( a2 > 0 )
{
v7 = v4 + 1;
do
*v7++ = a3;
while ( v7 != &v4[(unsigned int)(a2 - 1) + 2] );
}
}
else
{
if ( a1 > 33 )
{
if ( a1 == 44 )
{
v4[2] = a3;
return v4;
}
if ( a1 == 55 )
{
v4[2] = a3;
return v4;
}
goto LABEL_18;
}
if ( a1 != 11 )
{
if ( a1 == 22 )
{
v4[2] = a3;
return v4;
}
LABEL_18:
fprintf(stderr, "get_alphas: undefined interaction type %d.\n", (unsigned int)a1);
exit(1);
}
}
return v4;
}

canonical_decompiled_code:
double *__fastcall func1(int a1, int a2, double a3)
{
double *v3; // rax
double *v4; // rcx
double *v5; // rdx
double *v7; // rax

v3 = (double *)double_malloc_or_die((unsigned int)(a2 + 1));
v4 = v3;
if ( a2 >= 0 )
{
v5 = &v3[a2 + 1];
do
*v3++ = 0.0;
while ( v3 != v5 );
}
if ( a1 == 33 )
{
if ( a2 > 0 )
{
v7 = v4 + 1;
do
*v7++ = a3;
while ( v7 != &v4[(unsigned int)(a2 - 1) + 2] );
}
}
else
{
if ( a1 > 33 )
{
if ( a1 == 44 )
{
v4[2] = a3;
return v4;
}
if ( a1 == 55 )
{
v4[2] = a3;
return v4;
}
goto LABEL_18;
}
if ( a1 != 11 )
{
if ( a1 == 22 )
{
v4[2] = a3;
return v4;
}
LABEL_18:
fprintf(stderr, "get_alphas: undefined interaction type %d.\n", (unsigned int)a1);
exit(1);
}
}
return v4;
}

original_code:
double* get_alphas(int interaction_type, int N, double alpha0)
{
 double* alphas = double_malloc_or_die(N+1);
 int k;
 for (k = 0; k <= N; k++)
  alphas[k] = 0.0;
 switch (interaction_type) {
 case 11:
  break;
 case 22:
  alphas[2] = alpha0;
  break;
 case 33:
  for (k = 1; k <= N; k++)
   alphas[k] = alpha0;
  break;
 case 44:
  alphas[2] = alpha0;
  break;
 case 55:
  alphas[2] = alpha0;
  break;
 default:
  fprintf(stderr, "get_alphas: undefined interaction type %d.\n",
   interaction_type);
  exit(1);
  break;
 }
 return alphas;
}

canonical_original_code:
double *get_alphas(int interaction_type, int N, double alpha0)
{
 double *alphas = double_malloc_or_die(N+1);
 int k;
 for (k = 0; k <= N; k++)
  alphas[k] = 0.0;
 switch (interaction_type) {
 case 11:
  break;
 case 22:
  alphas[2] = alpha0;
  break;
 case 33:
  for (k = 1; k <= N; k++)
   alphas[k] = alpha0;
  break;
 case 44:
  alphas[2] = alpha0;
  break;
 case 55:
  alphas[2] = alpha0;
  break;
 default:
  fprintf(stderr, "get_alphas: undefined interaction type %d.\n",
   interaction_type);
  exit(1);
  break;
 }
 return alphas;
}

variable_types: N int

variable_types:
alphas
double *

variable_types: k int

return_type: double *


decompiled_code:
__int64 __fastcall mtrand_init(int a1)
{
__int64 i; // rdx
__int64 result; // rax

mt[0] = a1;
for ( i = 1LL; i != 624; ++i )
{
result = (unsigned int)(i + 1812433253 * (*(_DWORD *)(4 * i + 0x2DC) ^ (*(_DWORD *)(4 * i + 0x2DC) >> 30)));
mt[i] = result;
}
mti = 624;
return result;
}

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

mt[0] = a1;
for ( i = 1LL; i != 624; ++i )
{
result = (unsigned int)(i + 1812433253 * (*(_DWORD *)(4 * i + 0x2DC) ^ (*(_DWORD *)(4 * i + 0x2DC) >> 30)));
mt[i] = result;
}
mti = 624;
return result;
}

original_code:
void mtrand_init(unsigned s)
{
    mt[0]= s & 0xffffffff;
    for (mti=1; mti<624; mti++) {
        mt[mti] =
     (1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
        mt[mti] &= 0xffffffff;
    }
}

canonical_original_code:
void mtrand_init(unsigned int s)
{
    mt[0]= s & 0xffffffff;
    for (mti=1; mti<624; mti++) {
        mt[mti] =
     (1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
        mt[mti] &= 0xffffffff;
    }
}

variable_types:
s
unsigned int


decompiled_code:
__int64 get_mtrand_int31()
{
return (unsigned int)get_mtrand_int32() >> 1;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)func2() >> 1;
}

original_code:
int get_mtrand_int31(void)
{
    return (int)(get_mtrand_int32()>>1);
}

canonical_original_code:
int get_mtrand_int31()
{
    return (int)(get_mtrand_int32()>>1);
}

return_type: int


decompiled_code:
double get_mtrand_float()
{
return (double)(int)get_mtrand_int32() * 2.328306436538696e-10;
}

original_code:
double get_mtrand_float(void)
{
    return get_mtrand_int32()*(1.0/4294967296.0);
}

canonical_original_code:
double get_mtrand_float()
{
    return get_mtrand_int32()*(1.0/4294967296.0);
}

return_type: double


decompiled_code:
double get_mtrand_double()
{
unsigned int v0; // ebx

v0 = get_mtrand_int32();
return ((double)(v0 >> 5) * 67108864.0 + (double)((unsigned int)get_mtrand_int32() >> 6)) * 1.110223024625157e-16;
}

original_code:
double get_mtrand_double(void)
{
    unsigned a = get_mtrand_int32() >> 5;
 unsigned b = get_mtrand_int32() >> 6;
    return (a*67108864.0+b) * (1.0/9007199254740992.0);
}

canonical_original_code:
double get_mtrand_double()
{
    unsigned int a = get_mtrand_int32() >> 5;
 unsigned int b = get_mtrand_int32() >> 6;
    return (a*67108864.0+b) * (1.0/9007199254740992.0);
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int


original_code:
void therm_ctl_init(therm_ctl_t* ptherm, int smoothing_window_size,
 int therm_ntp, int force_therm)
{
 int k;
 ptherm->smoothing_window_size = smoothing_window_size;
 ptherm->therm_ntp = therm_ntp;
 ptherm->force_therm = force_therm;
 ptherm->sweepi = 0;
 ptherm->H_lagger = 0.0;
 ptherm->ssH = 0.0;
 ptherm->smoothed_H = 0.0;
 ptherm->smoothed_Hm1 = 0.0;
 ptherm->smoothed_Hm2 = 0.0;
 ptherm->smoothed_H_diff1 = 0.0;
 ptherm->smoothed_H_diff2 = 0.0;
 ptherm->smoothing_scale = 0;
 ptherm->H_window = double_malloc_or_die(ptherm->smoothing_window_size);
 for (k = 0; k < ptherm->smoothing_window_size; k++)
  ptherm->H_window[k] = 0.0;
 ptherm->ntp = 0;
 ptherm->thermalized = 0;
}

canonical_original_code:
void therm_ctl_init(struct _therm_ctl_t *ptherm, int smoothing_window_size, int therm_ntp, int force_therm)
{
 int k;
 ptherm->smoothing_window_size = smoothing_window_size;
 ptherm->therm_ntp = therm_ntp;
 ptherm->force_therm = force_therm;
 ptherm->sweepi = 0;
 ptherm->H_lagger = 0.0;
 ptherm->ssH = 0.0;
 ptherm->smoothed_H = 0.0;
 ptherm->smoothed_Hm1 = 0.0;
 ptherm->smoothed_Hm2 = 0.0;
 ptherm->smoothed_H_diff1 = 0.0;
 ptherm->smoothed_H_diff2 = 0.0;
 ptherm->smoothing_scale = 0;
 ptherm->H_window = double_malloc_or_die(ptherm->smoothing_window_size);
 for (k = 0; k < ptherm->smoothing_window_size; k++)
  ptherm->H_window[k] = 0.0;
 ptherm->ntp = 0;
 ptherm->thermalized = 0;
}

variable_types: struct _therm_ctl_t { int smoothing_window_size; int therm_ntp; int force_therm; int sweepi; double H_lagger; double ssH; double smoothed_H; double smoothed_Hm1; double smoothed_Hm2; double smoothed_H_diff1; double smoothed_H_diff2; int smoothing_scale; double *H_window; int ntp; int thermalized; } *


original_code:
void therm_ctl_update(therm_ctl_t* ptherm, double H)
{
 int idx = ptherm->sweepi % ptherm->smoothing_window_size;
 if (ptherm->thermalized)
  return;
 ptherm->sweepi++;
 ptherm->H_lagger = ptherm->H_window[idx];
 ptherm->H_window[idx] = H;
 ptherm->smoothed_H_diff1 = ptherm->smoothed_H - ptherm->smoothed_Hm1;
 ptherm->smoothed_H_diff2 = ptherm->smoothed_Hm1 - ptherm->smoothed_Hm2;
 ptherm->smoothed_Hm2 = ptherm->smoothed_Hm1;
 ptherm->smoothed_Hm1 = ptherm->smoothed_H;
 if (ptherm->sweepi < ptherm->smoothing_window_size) {
  ptherm->smoothed_H += H;
  ptherm->smoothing_scale++;
 }
 else {
  ptherm->smoothed_H -= ptherm->H_lagger;
  ptherm->smoothed_H += H;
 }
 ptherm->ssH = ptherm->smoothed_H / ptherm->smoothing_scale;
 if (ptherm->sweepi >= ptherm->smoothing_window_size) {
  if (ptherm->smoothed_H_diff1 * ptherm->smoothed_H_diff2 < 0.0) {
   ptherm->ntp++;
   if (ptherm->ntp >= ptherm->therm_ntp)
    ptherm->thermalized = 1;
  }
 }
 if (ptherm->sweepi == ptherm->force_therm)
  ptherm->thermalized = 1;
}

canonical_original_code:
void therm_ctl_update(struct _therm_ctl_t *ptherm, double H)
{
 int idx = ptherm->sweepi % ptherm->smoothing_window_size;
 if (ptherm->thermalized)
  return;
 ptherm->sweepi++;
 ptherm->H_lagger = ptherm->H_window[idx];
 ptherm->H_window[idx] = H;
 ptherm->smoothed_H_diff1 = ptherm->smoothed_H - ptherm->smoothed_Hm1;
 ptherm->smoothed_H_diff2 = ptherm->smoothed_Hm1 - ptherm->smoothed_Hm2;
 ptherm->smoothed_Hm2 = ptherm->smoothed_Hm1;
 ptherm->smoothed_Hm1 = ptherm->smoothed_H;
 if (ptherm->sweepi < ptherm->smoothing_window_size) {
  ptherm->smoothed_H += H;
  ptherm->smoothing_scale++;
 }
 else {
  ptherm->smoothed_H -= ptherm->H_lagger;
  ptherm->smoothed_H += H;
 }
 ptherm->ssH = ptherm->smoothed_H / ptherm->smoothing_scale;
 if (ptherm->sweepi >= ptherm->smoothing_window_size) {
  if (ptherm->smoothed_H_diff1 * ptherm->smoothed_H_diff2 < 0.0) {
   ptherm->ntp++;
   if (ptherm->ntp >= ptherm->therm_ntp)
    ptherm->thermalized = 1;
  }
 }
 if (ptherm->sweepi == ptherm->force_therm)
  ptherm->thermalized = 1;
}

variable_types: H double

variable_types: idx int

user_defined_types: struct _therm_ctl_t { int smoothing_window_size; int therm_ntp; int force_therm; int sweepi; double H_lagger; double ssH; double smoothed_H; double smoothed_Hm1; double smoothed_Hm2; double smoothed_H_diff1; double smoothed_H_diff2; int smoothing_scale; double *H_window; int ntp; int thermalized; }


decompiled_code:
void __fastcall therm_ctl_free(__int64 a1)
{
free(*(void **)(a1 + 80));
*(_QWORD *)(a1 + 80) = 0LL;
}

original_code:
void therm_ctl_free(therm_ctl_t* ptherm)
{
 free(ptherm->H_window);
 ptherm->H_window = 0;
}

canonical_original_code:
void therm_ctl_free(struct _therm_ctl_t *ptherm)
{
 free(ptherm->H_window);
 ptherm->H_window = 0;
}


decompiled_code:
int __fastcall print_points_and_cycles(__int64 a1)
{
return print_points_and_cycles_aux(a1, 0, -1, *(_DWORD *)(a1 + 12) + 1);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
return func0(a1, 0, -1, *(_DWORD *)(a1 + 12) + 1);
}

original_code:
void print_points_and_cycles(points_t* ppoints)
{
 print_points_and_cycles_aux(ppoints, 0, -1, ppoints->N+1);
}

canonical_original_code:
void print_points_and_cycles(struct _points_t *ppoints)
{
 print_points_and_cycles_aux(ppoints, 0, -1, ppoints->N+1);
}

variable_types: struct _points_t { struct _dims_t { int nx; int ny; int nz; } dims; int N; struct _point_t { struct _coord_t { int selfi; int selfj; int selfk; } c; struct _point_t *pfwd; struct _point_t *pbwd; int fwd_dsq; double fwd_d; struct _cycinfo_t { struct _cycinfo_t *pprev; struct _cycinfo_t *pnext; struct _point_t *psite; int cyclen; } *pcycinfo; int mark; } ***lattice; struct _point_t wormhole; struct _cycinfo_t *pcycinfo_list_head; struct _cycinfo_t *pcycinfo_list_tail; } *

user_defined_types: struct _points_t { struct _dims_t dims; int N; struct _point_t ***lattice; struct _point_t wormhole; struct _cycinfo_t *pcycinfo_list_head; struct _cycinfo_t *pcycinfo_list_tail; }

user_defined_types: struct _point_t { struct _coord_t c; struct _point_t *pfwd; struct _point_t *pbwd; int fwd_dsq; double fwd_d; struct _cycinfo_t *pcycinfo; int mark; }


decompiled_code:
int __fastcall print_points_and_cycles_min_max(__int64 a1, int a2, int a3)
{
return print_points_and_cycles_aux(a1, 1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, int a3)
{
return func0(a1, 1, a2, a3);
}

original_code:
void print_points_and_cycles_min_max(points_t* ppoints,
 int min_ell, int max_ell)
{
 print_points_and_cycles_aux(ppoints, 1, min_ell, max_ell);
}

canonical_original_code:
void print_points_and_cycles_min_max(struct _points_t *ppoints, int min_ell, int max_ell)
{
 print_points_and_cycles_aux(ppoints, 1, min_ell, max_ell);
}

user_defined_types: struct _dims_t { int nx; int ny; int nz; }

user_defined_types: struct _coord_t { int selfi; int selfj; int selfk; }

user_defined_types: struct _cycinfo_t { struct _cycinfo_t *pprev; struct _cycinfo_t *pnext; struct _point_t *psite; int cyclen; }


decompiled_code:
__int64 get_urandom()
{
unsigned int v0; // edx
int v1; // eax
unsigned int v3; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
if ( !bufpos_1 )
{
v3 = read(fd_3, buf_0, 0x2000uLL);
if ( v3 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v3);
exit(1);
}
}
v0 = buf_0[bufpos_1];
v1 = bufpos_1 + 1;
if ( bufpos_1 + 1 > 2047 )
v1 = 0;
bufpos_1 = v1;
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // edx
int v1; // eax
unsigned int v3; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
if ( !bufpos_1 )
{
v3 = read(fd_3, buf_0, 0x2000uLL);
if ( v3 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v3);
exit(1);
}
}
v0 = buf_0[bufpos_1];
v1 = bufpos_1 + 1;
if ( bufpos_1 + 1 > 2047 )
v1 = 0;
bufpos_1 = v1;
return v0;
}

original_code:
int get_urandom(void)
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char * dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

canonical_original_code:
int get_urandom()
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char *dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

variable_types: fd int

variable_types:
buf
int [2048]

variable_types: bufpos int

variable_types: rv int


decompiled_code:
double get_urandomu()
{
return (double)(int)get_urandom() * 2.328306436538696e-10;
}

original_code:
double get_urandomu(void)
{
 unsigned u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

canonical_original_code:
double get_urandomu()
{
 unsigned int u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

variable_types:
u
unsigned int

variable_types: numer double

variable_types: denom double


gasdev

decompiled_code:
double gasdev()
{
double v0; // xmm0_8
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm0_8
double result; // xmm0_8
double v6; // [rsp+0h] [rbp-20h]
double v7; // [rsp+10h] [rbp-10h]

if ( iset_1 )
{
iset_1 = 0;
result = *(double *)&gset_0;
}
else
{
do
{
do
{
v0 = get_mtrand_double();
v6 = v0 + v0 - 1.0;
v1 = get_mtrand_double();
v7 = v1 + v1 - 1.0;
v2 = v6 * v6 + v7 * v7;
}
while ( v2 >= 1.0 );
}
while ( v2 == 0.0 );
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*(double *)&gset_0 = v6 * v4;
iset_1 = 1;
result = v4 * v7;
}
return result;
}

canonical_decompiled_code:
double func0()
{
double v0; // xmm0_8
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm0_8
double result; // xmm0_8
double v6; // [rsp+0h] [rbp-20h]
double v7; // [rsp+10h] [rbp-10h]

if ( iset_1 )
{
iset_1 = 0;
result = *(double *)&gset_0;
}
else
{
do
{
do
{
v0 = get_mtrand_double();
v6 = v0 + v0 - 1.0;
v1 = get_mtrand_double();
v7 = v1 + v1 - 1.0;
v2 = v6 * v6 + v7 * v7;
}
while ( v2 >= 1.0 );
}
while ( v2 == 0.0 );
v3 = log(v2) * -2.0 / v2;
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*(double *)&gset_0 = v6 * v4;
iset_1 = 1;
result = v4 * v7;
}
return result;
}

original_code:
double gasdev(void)
{
 static int iset = 0;
 static double gset;
 double fac, rsq, v1, v2;
 if (iset == 0) {
  do {
   v1 = 2.0 * get_mtrand_double() - 1.0;
   v2 = 2.0 * get_mtrand_double() - 1.0;
   rsq = v1*v1 + v2*v2;
  } while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrt(-2.0 * log(rsq) / rsq);
  gset = v1 * fac;
  iset = 1;
  return v2 * fac;
 }
 else {
  iset = 0;
  return gset;
 }
}

canonical_original_code:
double gasdev()
{
 static int iset = 0;
 static double gset;
 double fac; double rsq; double v1; double v2;
 if (iset == 0) {
  do {
   v1 = 2.0 * get_mtrand_double() - 1.0;
   v2 = 2.0 * get_mtrand_double() - 1.0;
   rsq = v1*v1 + v2*v2;
  } while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrt(-2.0 * log(rsq) / rsq);
  gset = v1 * fac;
  iset = 1;
  return v2 * fac;
 }
 else {
  iset = 0;
  return gset;
 }
}

variable_types: iset int

variable_types: gset double

variable_types: fac double

variable_types: rsq double


decompiled_code:
double __fastcall gasdev_ms(double a1, double a2)
{
return gasdev() * a2 + a1;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
return func0() * a2 + a1;
}

original_code:
double gasdev_ms(double mean, double stddev)
{
 return mean + stddev * gasdev();
}

variable_types: mean double

variable_types: stddev double


decompiled_code:
const char *__fastcall get_rng_type_desc(int a1)
{
const char *result; // rax

if ( a1 == 3 )
return "rand48";
if ( a1 > 3 )
{
result = "Unrecognized RNG type";
if ( a1 == 4 )
result = "Mersenne twister";
}
else
{
result = "psdes";
if ( a1 != 1 )
{
result = "Unrecognized RNG type";
if ( a1 == 2 )
result = "/dev/urandom";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

if ( a1 == 3 )
return "rand48";
if ( a1 > 3 )
{
result = "Unrecognized RNG type";
if ( a1 == 4 )
result = "Mersenne twister";
}
else
{
result = "psdes";
if ( a1 != 1 )
{
result = "Unrecognized RNG type";
if ( a1 == 2 )
result = "/dev/urandom";
}
}
return result;
}

original_code:
char* get_rng_type_desc(int rng_type)
{
 char* rv = "Unrecognized RNG type";
 switch (rng_type) {
 case 1: rv = "psdes"; break;
 case 2: rv = "/dev/urandom"; break;
 case 3: rv = "rand48"; break;
 case 4: rv = "Mersenne twister"; break;
 }
 return rv;
}

canonical_original_code:
char *get_rng_type_desc(int rng_type)
{
 char *rv = "Unrecognized RNG type";
 switch (rng_type) {
 case 1: rv = "psdes"; break;
 case 2: rv = "/dev/urandom"; break;
 case 3: rv = "rand48"; break;
 case 4: rv = "Mersenne twister"; break;
 }
 return rv;
}

variable_types:
rv
char *


decompiled_code:
__int64 __fastcall get_rho_L_pi(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // er12
__int64 result; // rax
double v7; // xmm0_8

v5 = *(_DWORD *)(a1 + 12);
result = pmt_get_cycle_counts_and_lmax(a1, a3, a4);
if ( v5 >= 0 )
{
result = 0LL;
v7 = 0.0;
do
{
v7 = v7 + (double)(*(_DWORD *)(a3 + 4 * result) * (int)result);
*(double *)(a2 + 8 * result++) = 1.0 / (double)v5 * v7;
}
while ( result != v5 + 1 );
}
return result;
}

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

v5 = *(_DWORD *)(a1 + 12);
result = pmt_get_cycle_counts_and_lmax(a1, a3, a4);
if ( v5 >= 0 )
{
result = 0LL;
v7 = 0.0;
do
{
v7 = v7 + (double)(*(_DWORD *)(a3 + 4 * result) * (int)result);
*(double *)(a2 + 8 * result++) = 1.0 / (double)v5 * v7;
}
while ( result != v5 + 1 );
}
return result;
}

original_code:
void get_rho_L_pi(points_t* ppoints, double* rho, int* counts, int *plmax)
{
 int N = ppoints->N;
 double recip_N = 1.0 / N;
 int j;
 double rhoval;
 pmt_get_cycle_counts_and_lmax(ppoints, counts, plmax);
 rhoval = 0.0;
 for (j = 0; j <= N; j++) {
  rhoval += j * counts[j];
  rho[j] = rhoval * recip_N;
 }
}

canonical_original_code:
void get_rho_L_pi(struct _points_t *ppoints, double *rho, int *counts, int *plmax)
{
 int N = ppoints->N;
 double recip_N = 1.0 / N;
 int j;
 double rhoval;
 pmt_get_cycle_counts_and_lmax(ppoints, counts, plmax);
 rhoval = 0.0;
 for (j = 0; j <= N; j++) {
  rhoval += j * counts[j];
  rho[j] = rhoval * recip_N;
 }
}

variable_types:
rho
double *

variable_types:
counts
int *

variable_types:
plmax
int *

variable_types: N int

variable_types: j int

variable_types: rhoval double


original_code:
double compute_rho_infty(double* rho_fit, double* rho_avg, double* rho,
 int N, int verbose)
{
 int k;
 int maxk = 0;
 double dev;
 double maxdev = 0.0;
 double rho_finite_T;
 double rho_infty_T;
 for (k = 1; k <= N; k++) {
  dev = rho_avg[k] - (double)k/(double)N;
  if (dev > maxdev) {
   maxdev = dev;
   maxk = k;
  }
 }
 rho_finite_T = rho_avg[maxk] - (double)maxk/(double)N;
 rho_infty_T = 1.0 - rho_finite_T;
 printf("# rho_infty max dev = %11.7lf at k = %d\n", maxdev, maxk);
 for (k = 0; k <= N; k++) {
  rho_fit[k] = (double)k/(double)N + rho_finite_T;
  if (rho_fit[k] > 1.0)
   rho_fit[k] = 1.0;
 }
 return rho_infty_T;
}

canonical_original_code:
double compute_rho_infty(double *rho_fit, double *rho_avg, double *rho, int N, int verbose)
{
 int k;
 int maxk = 0;
 double dev;
 double maxdev = 0.0;
 double rho_finite_T;
 double rho_infty_T;
 for (k = 1; k <= N; k++) {
  dev = rho_avg[k] - (double)k/(double)N;
  if (dev > maxdev) {
   maxdev = dev;
   maxk = k;
  }
 }
 rho_finite_T = rho_avg[maxk] - (double)maxk/(double)N;
 rho_infty_T = 1.0 - rho_finite_T;
 printf("# rho_infty max dev = %11.7lf at k = %d\n", maxdev, maxk);
 for (k = 0; k <= N; k++) {
  rho_fit[k] = (double)k/(double)N + rho_finite_T;
  if (rho_fit[k] > 1.0)
   rho_fit[k] = 1.0;
 }
 return rho_infty_T;
}

variable_types: verbose int

variable_types: k int

variable_types: maxk int

variable_types: dev double

variable_types: maxdev double


decompiled_code:
const char *__fastcall worm_move_to_desc(int a1)
{
const char *result; // rax

if ( a1 == 444 )
return "head swap";
if ( a1 > 444 )
{
result = (const char *)&unk_49;
if ( a1 == 555 )
result = "tail swap";
}
else
{
result = "open";
if ( a1 != 222 )
{
result = (const char *)&unk_49;
if ( a1 == 333 )
result = "close";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

if ( a1 == 444 )
return "head swap";
if ( a1 > 444 )
{
result = (const char *)&unk_49;
if ( a1 == 555 )
result = "tail swap";
}
else
{
result = "open";
if ( a1 != 222 )
{
result = (const char *)&unk_49;
if ( a1 == 333 )
result = "close";
}
}
return result;
}

original_code:
char* worm_move_to_desc(int worm_move)
{
 switch (worm_move) {
 case 222: return "open"; break;
 case 333: return "close"; break;
 case 444: return "head swap"; break;
 case 555: return "tail swap"; break;
 default: return "???"; break;
 }
}

canonical_original_code:
char *worm_move_to_desc(int worm_move)
{
 switch (worm_move) {
 case 222: return "open"; break;
 case 333: return "close"; break;
 case 444: return "head swap"; break;
 case 555: return "tail swap"; break;
 default: return "???"; break;
 }
}


repo: johnkerl/percolation

decompiled_code:
__int64 __fastcall allocate_rgb_matrix(int a1, int a2, char a3, char a4, char a5)
{
__int64 v9; // rbp
_QWORD *v10; // rsi
__int64 v11; // rax
__int64 v12; // rdx
__int64 v14; // [rsp+8h] [rbp-50h]

if ( a1 <= 0 || a2 <= 0 )
{
fprintf(
stderr,
"allocate_rgb_matrix: dimensions must be positive; got (%d,%d).\n",
(unsigned int)a1,
(unsigned int)a2);
exit(1);
}
v9 = malloc_or_die(16LL);
*(_DWORD *)v9 = a1;
*(_DWORD *)(v9 + 4) = a2;
*(_QWORD *)(v9 + 8) = malloc_or_die((unsigned int)(8 * a1));
v14 = 0LL;
do
{
v10 = (_QWORD *)(*(_QWORD *)(v9 + 8) + 8 * v14);
*v10 = malloc_or_die((unsigned int)(3 * a2));
v11 = 0LL;
do
{
v12 = 3 * v11;
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v9 + 8) + 8 * v14) + v12) = a3;
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v9 + 8) + 8 * v14) + v12 + 1) = a4;
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v9 + 8) + 8 * v14) + v12 + 2) = a5;
++v11;
}
while ( a2 > (int)v11 );
++v14;
}
while ( a1 > (int)v14 );
return v9;
}

original_code:
rgb_matrix_t* allocate_rgb_matrix(int height, int width,
 int r_fill, int g_fill, int b_fill)
{
 rgb_matrix_t* pmatrix;
 int i, j;
 if ((height < 1) || (width < 1)) {
  fprintf(stderr,
  "allocate_rgb_matrix:  dimensions must be positive; got (%d,%d).\n",
   height, width);
  exit(1);
 }
 pmatrix = (rgb_matrix_t *)malloc_or_die(sizeof(rgb_matrix_t));
 pmatrix->height = height;
 pmatrix->width = width;
 pmatrix->data = (rgb_pixel_t **)malloc_or_die(
  height * sizeof(rgb_pixel_t *));
 for (i = 0; i < height; i++) {
  pmatrix->data[i] = (rgb_pixel_t*)malloc_or_die(
   width * sizeof(rgb_pixel_t));
  for (j = 0; j < width; j++) {
   pmatrix->data[i][j].r = r_fill;
   pmatrix->data[i][j].g = g_fill;
   pmatrix->data[i][j].b = b_fill;
  }
 }
 return pmatrix;
}

canonical_original_code:
struct _rgb_matrix_t *allocate_rgb_matrix(int height, int width, int r_fill, int g_fill, int b_fill)
{
 struct _rgb_matrix_t *pmatrix;
 int i; int j;
 if ((height < 1) || (width < 1)) {
  fprintf(stderr,
  "allocate_rgb_matrix:  dimensions must be positive; got (%d,%d).\n",
   height, width);
  exit(1);
 }
 pmatrix = (struct _rgb_matrix_t *)malloc_or_die(sizeof(rgb_matrix_t));
 pmatrix->height = height;
 pmatrix->width = width;
 pmatrix->data = (struct _rgb_pixel_t **)malloc_or_die(
  height * sizeof(struct _rgb_pixel_t *));
 for (i = 0; i < height; i++) {
  pmatrix->data[i] = (struct _rgb_pixel_t *)malloc_or_die(
   width * sizeof(rgb_pixel_t));
  for (j = 0; j < width; j++) {
   pmatrix->data[i][j].r = r_fill;
   pmatrix->data[i][j].g = g_fill;
   pmatrix->data[i][j].b = b_fill;
  }
 }
 return pmatrix;
}

variable_types: height int

variable_types: width int

variable_types: struct _rgb_matrix_t { int height; int width; struct _rgb_pixel_t { unsigned char r; unsigned char g; unsigned char b; } **data; } *

variable_types: i int

user_defined_types: struct _rgb_matrix_t { int height; int width; struct _rgb_pixel_t **data; }


decompiled_code:
void __fastcall free_rgb_matrix(void *ptr)
{
__int64 v1; // rbx

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

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx

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

original_code:
void free_rgb_matrix(rgb_matrix_t* prgb_matrix)
{
 int i;
 for (i = 0; i < prgb_matrix->height; i++)
  free(prgb_matrix->data[i]);
 free(prgb_matrix->data);
 free(prgb_matrix);
}

canonical_original_code:
void free_rgb_matrix(struct _rgb_matrix_t *prgb_matrix)
{
 int i;
 for (i = 0; i < prgb_matrix->height; i++)
  free(prgb_matrix->data[i]);
 free(prgb_matrix->data);
 free(prgb_matrix);
}

user_defined_types: struct _rgb_pixel_t { unsigned char r; unsigned char g; unsigned char b; }


decompiled_code:
__int64 __fastcall psdes_hash_64(_DWORD *a1, int *a2)
{
__int64 i; // rdi
int v4; // er8
unsigned int v5; // ecx
__int64 result; // rax

for ( i = 0LL; i != 4; ++i )
{
v4 = *a2;
v5 = c1_1[i] ^ *a2;
result = *a1 ^ ((unsigned __int16)v5 * HIWORD(v5)
+ (c2_0[i] ^ __ROL4__((unsigned __int16)v5 * (unsigned __int16)v5 - 1 - HIWORD(v5) * HIWORD(v5), 16)));
*a2 = result;
*a1 = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int *a2)
{
__int64 i; // rdi
int v4; // er8
unsigned int v5; // ecx
__int64 result; // rax

for ( i = 0LL; i != 4; ++i )
{
v4 = *a2;
v5 = c1_1[i] ^ *a2;
result = *a1 ^ ((unsigned __int16)v5 * HIWORD(v5)
+ (c2_0[i] ^ __ROL4__((unsigned __int16)v5 * (unsigned __int16)v5 - 1 - HIWORD(v5) * HIWORD(v5), 16)));
*a2 = result;
*a1 = v4;
}
return result;
}

original_code:
void psdes_hash_64(
 unsigned * pword0,
 unsigned * pword1)
{
 unsigned i;
 unsigned iswap, ia, iah, ial, ib, ic;
 static unsigned c1[4] = {
  0xbaa96887, 0x1e17d32c, 0x03bcdc3c, 0x0f33d1b2 };
 static unsigned c2[4] = {
  0x4b0f3b58, 0xe874f0c3, 0x6955c5a6, 0x55a7ca46 };
 for (i = 0; i < 4; i++) {
  iswap = *pword1;
  ia = iswap ^ c1[i];
  ial = ia & 0xffff;
  iah = ia >> 16;
  ib = ial * ial + ~(iah * iah);
  ic = (ib >> 16) | ((ib & 0xffff) << 16);
  *pword1 = (*pword0) ^ ((ic ^ c2[i]) + ial * iah);
  *pword0 = iswap;
 }
}

canonical_original_code:
void psdes_hash_64(unsigned int *pword0, unsigned int *pword1)
{
 unsigned int i;
 unsigned int iswap; unsigned int ia; unsigned int iah; unsigned int ial; unsigned int ib; unsigned int ic;
 static unsigned int c1[4] = {
  0xbaa96887, 0x1e17d32c, 0x03bcdc3c, 0x0f33d1b2 };
 static unsigned int c2[4] = {
  0x4b0f3b58, 0xe874f0c3, 0x6955c5a6, 0x55a7ca46 };
 for (i = 0; i < 4; i++) {
  iswap = *pword1;
  ia = iswap ^ c1[i];
  ial = ia & 0xffff;
  iah = ia >> 16;
  ib = ial * ial + ~(iah * iah);
  ic = (ib >> 16) | ((ib & 0xffff) << 16);
  *pword1 = (*pword0) ^ ((ic ^ c2[i]) + ial * iah);
  *pword0 = iswap;
 }
}

variable_types:
i
unsigned int

variable_types:
iswap
unsigned int

variable_types:
ia
unsigned int

variable_types:
iah
unsigned int

variable_types:
ial
unsigned int

variable_types:
ib
unsigned int

variable_types:
ic
unsigned int


decompiled_code:
void __fastcall sran32(int a1)
{
non_reentrant_state0 = 0;
non_reentrant_state1 = a1;
non_reentrant_seeded = 1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
non_reentrant_state0 = 0;
non_reentrant_state1 = a1;
non_reentrant_seeded = 1;
}

original_code:
void sran32(unsigned s)
{
 non_reentrant_state0 = 0;
 non_reentrant_state1 = s;
 non_reentrant_seeded = 1;
}

canonical_original_code:
void sran32(unsigned int s)
{
 non_reentrant_state0 = 0;
 non_reentrant_state1 = s;
 non_reentrant_seeded = 1;
}

variable_types:
s
unsigned int


decompiled_code:
void __fastcall sran32b(int a1, int a2)
{
non_reentrant_state0 = a1;
non_reentrant_state1 = a2;
non_reentrant_seeded = 1;
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
non_reentrant_state0 = a1;
non_reentrant_state1 = a2;
non_reentrant_seeded = 1;
}

original_code:
void sran32b(unsigned s0, unsigned s1)
{
 non_reentrant_state0 = s0;
 non_reentrant_state1 = s1;
 non_reentrant_seeded = 1;
}

canonical_original_code:
void sran32b(unsigned int s0, unsigned int s1)
{
 non_reentrant_state0 = s0;
 non_reentrant_state1 = s1;
 non_reentrant_seeded = 1;
}


decompiled_code:
__int64 sran32_tod()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
non_reentrant_state0 = LODWORD(v1.tv_usec) ^ getpid();
result = LODWORD(v1.tv_sec) ^ (unsigned int)(LODWORD(v1.tv_usec) * LODWORD(v1.tv_usec) + 1);
non_reentrant_state1 = LODWORD(v1.tv_sec) ^ (LODWORD(v1.tv_usec) * LODWORD(v1.tv_usec) + 1);
non_reentrant_seeded = 1;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
non_reentrant_state0 = LODWORD(v1.tv_usec) ^ getpid();
result = LODWORD(v1.tv_sec) ^ (unsigned int)(LODWORD(v1.tv_usec) * LODWORD(v1.tv_usec) + 1);
non_reentrant_state1 = LODWORD(v1.tv_sec) ^ (LODWORD(v1.tv_usec) * LODWORD(v1.tv_usec) + 1);
non_reentrant_seeded = 1;
return result;
}

original_code:
void sran32_tod(void)
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 non_reentrant_state0 = getpid() ^ tod.tv_usec;
 non_reentrant_state1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
 non_reentrant_seeded = 1;
}

canonical_original_code:
void sran32_tod()
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 non_reentrant_state0 = getpid() ^ tod.tv_usec;
 non_reentrant_state1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
 non_reentrant_seeded = 1;
}

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


decompiled_code:
__int64 __fastcall iran32_r(int *a1, int *a2)
{
unsigned int v4; // [rsp+8h] [rbp-18h] BYREF
int v5[5]; // [rsp+Ch] [rbp-14h] BYREF

v5[0] = *a1;
v4 = *a2;
psdes_hash_64(v5, (int *)&v4);
if ( (*a2)++ == -1 )
++*a1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, int *a2)
{
unsigned int v4; // [rsp+8h] [rbp-18h] BYREF
int v5[5]; // [rsp+Ch] [rbp-14h] BYREF

v5[0] = *a1;
v4 = *a2;
func0(v5, (int *)&v4);
if ( (*a2)++ == -1 )
++*a1;
return v4;
}

original_code:
unsigned iran32_r(unsigned * pstate0, unsigned * pstate1)
{
 unsigned word0 = *pstate0;
 unsigned word1 = *pstate1;
 psdes_hash_64(&word0, &word1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
 return word1;
}

canonical_original_code:
unsigned int iran32_r(unsigned int *pstate0, unsigned int *pstate1)
{
 unsigned int word0 = *pstate0;
 unsigned int word1 = *pstate1;
 psdes_hash_64(&word0, &word1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
 return word1;
}

return_type: unsigned int


decompiled_code:
__int64 iran32()
{
if ( !non_reentrant_seeded )
sran32_tod();
return iran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_decompiled_code:
__int64 func5()
{
if ( !non_reentrant_seeded )
func3();
return func4(&non_reentrant_state0, &non_reentrant_state1);
}

original_code:
unsigned iran32(void)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_original_code:
unsigned int iran32()
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran32_r(&non_reentrant_state0, &non_reentrant_state1);
}


decompiled_code:
__int64 __fastcall iran64_r(_DWORD *a1, int *a2, _DWORD *a3, int *a4)
{
bool v6; // zf
__int64 result; // rax

*a1 = *a3;
*a2 = *a4;
psdes_hash_64(a1, a2);
v6 = *a4 == -1;
result = (unsigned int)(*a4 + 1);
*a4 = result;
if ( v6 )
++*a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, int *a2, _DWORD *a3, int *a4)
{
bool v6; // zf
__int64 result; // rax

*a1 = *a3;
*a2 = *a4;
func0(a1, a2);
v6 = *a4 == -1;
result = (unsigned int)(*a4 + 1);
*a4 = result;
if ( v6 )
++*a3;
return result;
}

original_code:
void iran64_r(unsigned * pout0, unsigned * pout1,
 unsigned * pstate0, unsigned * pstate1)
{
 *pout0 = *pstate0;
 *pout1 = *pstate1;
 psdes_hash_64(pout0, pout1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
}

canonical_original_code:
void iran64_r(unsigned int *pout0, unsigned int *pout1, unsigned int *pstate0, unsigned int *pstate1)
{
 *pout0 = *pstate0;
 *pout1 = *pstate1;
 psdes_hash_64(pout0, pout1);
 (*pstate1)++;
 if (*pstate1 == 0)
  (*pstate0)++;
}


decompiled_code:
__int64 __fastcall iran64(_DWORD *a1, int *a2)
{
if ( !non_reentrant_seeded )
sran32_tod();
return iran64_r(a1, a2, &non_reentrant_state0, &non_reentrant_state1);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int *a2)
{
if ( !non_reentrant_seeded )
func3();
return func6(a1, a2, &non_reentrant_state0, &non_reentrant_state1);
}

original_code:
void iran64(unsigned * pout0, unsigned * pout1)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran64_r(pout0, pout1,
  &non_reentrant_state0, &non_reentrant_state1);
}

canonical_original_code:
void iran64(unsigned int *pout0, unsigned int *pout1)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return iran64_r(pout0, pout1,
  &non_reentrant_state0, &non_reentrant_state1);
}


decompiled_code:
double __fastcall fran32_r(int *a1, int *a2)
{
return (double)(int)iran32_r(a1, a2) * 2.328306436538696e-10;
}

canonical_decompiled_code:
double __fastcall func8(int *a1, int *a2)
{
return (double)(int)func4(a1, a2) * 2.328306436538696e-10;
}

original_code:
double fran32_r(unsigned * pstate0, unsigned * pstate1)
{
 unsigned word = iran32_r(pstate0, pstate1);
 return (double)( (double)word / (double)4294967296.0 );
}

canonical_original_code:
double fran32_r(unsigned int *pstate0, unsigned int *pstate1)
{
 unsigned int word = iran32_r(pstate0, pstate1);
 return (double)( (double)word / (double)4294967296.0 );
}

variable_types:
word
unsigned int


decompiled_code:
double fran32()
{
if ( !non_reentrant_seeded )
sran32_tod();
return fran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_decompiled_code:
double func9()
{
if ( !non_reentrant_seeded )
func3();
return func8(&non_reentrant_state0, &non_reentrant_state1);
}

original_code:
double fran32(void)
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return fran32_r(&non_reentrant_state0, &non_reentrant_state1);
}

canonical_original_code:
double fran32()
{
 if (!non_reentrant_seeded)
  sran32_tod();
 return fran32_r(&non_reentrant_state0, &non_reentrant_state1);
}


decompiled_code:
__int64 __fastcall sran32_tod_r(int *a1, _DWORD *a2)
{
__pid_t v2; // edx
int v3; // eax
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v5, 0LL);
v2 = getpid();
v3 = v5.tv_usec;
*a1 = LODWORD(v5.tv_usec) ^ v2;
result = LODWORD(v5.tv_sec) ^ (unsigned int)(v3 * v3 + 1);
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, _DWORD *a2)
{
__pid_t v2; // edx
int v3; // eax
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v5, 0LL);
v2 = getpid();
v3 = v5.tv_usec;
*a1 = LODWORD(v5.tv_usec) ^ v2;
result = LODWORD(v5.tv_sec) ^ (unsigned int)(v3 * v3 + 1);
*a2 = result;
return result;
}

original_code:
void sran32_tod_r(unsigned * pstate0, unsigned * pstate1)
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 *pstate0 = getpid() ^ tod.tv_usec;
 *pstate1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
}

canonical_original_code:
void sran32_tod_r(unsigned int *pstate0, unsigned int *pstate1)
{
 struct timeval tod;
 (void)gettimeofday(&tod, 0);
 *pstate0 = getpid() ^ tod.tv_usec;
 *pstate1 = tod.tv_sec ^ (tod.tv_usec * tod.tv_usec + 1);
}

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


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

result = malloc((int)a1);
if ( !result )
{
fprintf(stderr, "malloc(%d) failed.\n", a1);
exit(1);
}
return result;
}

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

result = malloc((int)a1);
if ( !result )
{
fprintf(stderr, "malloc(%d) failed.\n", a1);
exit(1);
}
return result;
}

original_code:
void* malloc_or_die(int num_bytes)
{
 void* rv = malloc(num_bytes);
 if (rv == 0) {
  fprintf(stderr, "malloc(%d) failed.\n", num_bytes);
  exit(1);
 }
 return rv;
}

canonical_original_code:
void *malloc_or_die(int num_bytes)
{
 void *rv = malloc(num_bytes);
 if (rv == 0) {
  fprintf(stderr, "malloc(%d) failed.\n", num_bytes);
  exit(1);
 }
 return rv;
}

variable_types:
rv
void *

return_type: void *


decompiled_code:
char *get_sys_time_string()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) < 0 )
{
perror("gettimeofday");
exit(1);
}
return ctime(&v1.tv_sec);
}

canonical_decompiled_code:
char *func1()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) < 0 )
{
perror("gettimeofday");
exit(1);
}
return ctime(&v1.tv_sec);
}

original_code:
char* get_sys_time_string(void)
{
 struct timeval now;
 if (gettimeofday(&now, 0) < 0) {
  perror("gettimeofday");
  exit(1);
 }
 return ctime(&now.tv_sec);
}

canonical_original_code:
char *get_sys_time_string()
{
 struct timeval now;
 if (gettimeofday(&now, 0) < 0) {
  perror("gettimeofday");
  exit(1);
 }
 return ctime(&now.tv_sec);
}


decompiled_code:
int check_stop()
{
int result; // eax
char *v1; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat("./__stop__", &v2);
if ( !result )
{
v1 = get_sys_time_string();
printf("Exiting due to __stop__ file. Time: %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
char *v1; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat("./__stop__", &v2);
if ( !result )
{
v1 = func1();
printf("Exiting due to __stop__ file. Time: %s", v1);
exit(1);
}
return result;
}

original_code:
void check_stop(void)
{
 struct stat statbuf;
 if (stat("./__stop__", &statbuf) == 0) {
  printf("Exiting due to __stop__ file.  Time:  %s",
   get_sys_time_string());
  exit(1);
 }
}

canonical_original_code:
void check_stop()
{
 struct stat statbuf;
 if (stat("./__stop__", &statbuf) == 0) {
  printf("Exiting due to __stop__ file.  Time:  %s",
   get_sys_time_string());
  exit(1);
 }
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 get_urandom()
{
unsigned int v0; // edx
int v1; // eax
unsigned int v3; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
if ( !bufpos_1 )
{
v3 = read(fd_3, buf_0, 0x2000uLL);
if ( v3 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v3);
exit(1);
}
}
v0 = buf_0[bufpos_1];
v1 = bufpos_1 + 1;
if ( bufpos_1 + 1 > 2047 )
v1 = 0;
bufpos_1 = v1;
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // edx
int v1; // eax
unsigned int v3; // ebx

if ( fd_3 == -1 )
{
fd_3 = open("/dev/urandom", 0);
if ( fd_3 < 0 )
{
perror("open");
fprintf(stderr, "Couldn't open %s.\n", "/dev/urandom");
exit(1);
}
}
if ( !bufpos_1 )
{
v3 = read(fd_3, buf_0, 0x2000uLL);
if ( v3 != 0x2000 )
{
perror("read");
fprintf(stderr, "Couldn't read %s.\n", "/dev/urandom");
fprintf(stderr, "Expected %d byte(s); got %d.\n", 0x2000LL, v3);
exit(1);
}
}
v0 = buf_0[bufpos_1];
v1 = bufpos_1 + 1;
if ( bufpos_1 + 1 > 2047 )
v1 = 0;
bufpos_1 = v1;
return v0;
}

original_code:
int get_urandom(void)
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char * dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

canonical_original_code:
int get_urandom()
{
 static int fd = -1;
 static int buf[2048];
 static int bufpos = 0;
 static char *dev_name = "/dev/urandom";
 int bytes_wanted;
 int bytes_read;
 int rv;
 if (fd == -1) {
  fd = open(dev_name, 00);
  if (fd < 0) {
   perror("open");
   fprintf(stderr, "Couldn't open %s.\n", dev_name);
   exit(1);
  }
 }
 if (bufpos == 0) {
  bytes_wanted = 2048 * sizeof(int);
  bytes_read = read(fd, buf, 2048 * sizeof(int));
  if (bytes_read != bytes_wanted) {
   perror("read");
   fprintf(stderr, "Couldn't read %s.\n", dev_name);
   fprintf(stderr, "Expected %d byte(s); got %d.\n",
    bytes_wanted, bytes_read);
   exit(1);
  }
 }
 rv = buf[bufpos];
 bufpos++;
 if (bufpos >= 2048)
  bufpos = 0;
 return rv;
}

variable_types: fd int

variable_types:
buf
int [2048]

variable_types: bufpos int

variable_types: rv int


decompiled_code:
double get_urandomu()
{
return (double)(int)get_urandom() * 2.328306436538696e-10;
}

original_code:
double get_urandomu(void)
{
 unsigned u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

canonical_original_code:
double get_urandomu()
{
 unsigned int u = get_urandom();
 double numer = (double)u;
 double denom = 4294967296.0;
 return (double)(numer/denom);
}

variable_types:
u
unsigned int

variable_types: numer double

variable_types: denom double


decompiled_code:
int __fastcall print_lattice(_QWORD *a1, _QWORD *a2, _QWORD *a3, int a4, int a5, _DWORD *a6, _DWORD *a7)
{
int i; // ebx
int v11; // ebp
int v12; // ebx
int v13; // eax
int v14; // ebp
__int64 j; // rbx
__int64 v16; // rbx
int v17; // ebx
__int64 v20; // [rsp+8h] [rbp-50h]

if ( a5 <= 0 )
{
puts("ooo");
printf("o ");
puts("o");
if ( a4 <= 0 )
return puts("ooo");
}
else
{
for ( i = 0; i != a5; ++i )
{
printf("oooo");
v11 = i;
}
puts("ooo");
printf("o ");
v12 = 0;
do
{
printf(" ");
v13 = v12++;
}
while ( v11 != v13 );
puts("o");
if ( a4 <= 0 )
{
LABEL_25:
v17 = 0;
do
{
printf("oooo");
++v17;
}
while ( a5 != v17 );
return puts("ooo");
}
}
v20 = (unsigned int)(a5 - 1);
v14 = 0;
do
{
printf("o ");
if ( a5 <= 0 )
{
puts("o");
printf("o ");
}
else
{
for ( j = 0LL; ; ++j )
{
if ( *a6 == v14 && a6[1] == (_DWORD)j )
{
putchar(65);
}
else if ( *a7 == v14 && a7[1] == (_DWORD)j )
{
putchar(66);
}
else
{
putchar(*(_DWORD *)(*a1 + 4 * j));
}
if ( *(_DWORD *)(*a3 + 4 * j) )
printf(" - ");
else
printf(" ");
if ( v20 == j )
break;
}
puts("o");
printf("o ");
v16 = 0LL;
do
{
if ( *(_DWORD *)(*a2 + v16) )
putchar(124);
else
putchar(32);
printf(" ");
v16 += 4LL;
}
while ( v16 != 4 * v20 + 4 );
}
puts("o");
++v14;
++a2;
++a3;
++a1;
}
while ( a4 != v14 );
if ( a5 > 0 )
goto LABEL_25;
return puts("ooo");
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1, _QWORD *a2, _QWORD *a3, int a4, int a5, _DWORD *a6, _DWORD *a7)
{
int i; // ebx
int v11; // ebp
int v12; // ebx
int v13; // eax
int v14; // ebp
__int64 j; // rbx
__int64 v16; // rbx
int v17; // ebx
__int64 v20; // [rsp+8h] [rbp-50h]

if ( a5 <= 0 )
{
puts("ooo");
printf("o ");
puts("o");
if ( a4 <= 0 )
return puts("ooo");
}
else
{
for ( i = 0; i != a5; ++i )
{
printf("oooo");
v11 = i;
}
puts("ooo");
printf("o ");
v12 = 0;
do
{
printf(" ");
v13 = v12++;
}
while ( v11 != v13 );
puts("o");
if ( a4 <= 0 )
{
LABEL_25:
v17 = 0;
do
{
printf("oooo");
++v17;
}
while ( a5 != v17 );
return puts("ooo");
}
}
v20 = (unsigned int)(a5 - 1);
v14 = 0;
do
{
printf("o ");
if ( a5 <= 0 )
{
puts("o");
printf("o ");
}
else
{
for ( j = 0LL; ; ++j )
{
if ( *a6 == v14 && a6[1] == (_DWORD)j )
{
putchar(65);
}
else if ( *a7 == v14 && a7[1] == (_DWORD)j )
{
putchar(66);
}
else
{
putchar(*(_DWORD *)(*a1 + 4 * j));
}
if ( *(_DWORD *)(*a3 + 4 * j) )
printf(" - ");
else
printf(" ");
if ( v20 == j )
break;
}
puts("o");
printf("o ");
v16 = 0LL;
do
{
if ( *(_DWORD *)(*a2 + v16) )
putchar(124);
else
putchar(32);
printf(" ");
v16 += 4LL;
}
while ( v16 != 4 * v20 + 4 );
}
puts("o");
++v14;
++a2;
++a3;
++a1;
}
while ( a4 != v14 );
if ( a5 > 0 )
goto LABEL_25;
return puts("ooo");
}

original_code:
void print_lattice(int** site_marks, int** vbonds, int** hbonds,
 int M, int N, int A1[2], int A2[2])
{
 int i, j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   if ((((ij)[0]==(A1)[0])&&((ij)[1]==(A1)[1])))
    printf("A");
   else if ((((ij)[0]==(A2)[0])&&((ij)[1]==(A2)[1])))
    printf("B");
   else
    printf("%c", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}

canonical_original_code:
void print_lattice(int **site_marks, int **vbonds, int **hbonds, int M, int N, int A1[2], int A2[2])
{
 int i; int j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   if ((((ij)[0]==(A1)[0])&&((ij)[1]==(A1)[1])))
    printf("A");
   else if ((((ij)[0]==(A2)[0])&&((ij)[1]==(A2)[1])))
    printf("B");
   else
    printf("%c", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}

variable_types:
vbonds
int **

variable_types:
hbonds
int **

variable_types: M int

variable_types: N int

variable_types: i int

variable_types: j int

variable_types:
ij
int [2]


original_code:
void print_lattice_and_cluster_numbers(int** site_marks,
 int** vbonds, int** hbonds, int M, int N)
{
 int i, j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   printf("%d", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}

canonical_original_code:
void print_lattice_and_cluster_numbers(int **site_marks, int **vbonds, int **hbonds, int M, int N)
{
 int i; int j;
 int ij[2];
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
 printf("o ");
 for (j = 0; j < N; j++)
  printf("    ");
 printf("o\n");
 for (i = 0; i < M; i++) {
  printf("o ");
  for (j = 0; j < N; j++) {
   ij[0] = i;
   ij[1] = j;
   printf("%d", site_marks[i][j]);
   if (j < N) {
    if (hbonds[i][j])
     printf(" - ");
    else
     printf("   ");
   }
  }
  printf("o\n");
  if (i < M) {
   printf("o ");
   for (j = 0; j < N; j++) {
    if (vbonds[i][j])
     printf("|");
    else
     printf(" ");
    if (j < N)
     printf("   ");
   }
   printf("o\n");
  }
 }
 for (j = 0; j < N; j++)
  printf("oooo");
 printf("ooo\n");
}


decompiled_code:
int show_usage()
{
return puts(
"\n"
"Usage: ascii-only [-r replacement] [-l log_file ] [-i input_file] [-o output_file]\n"
"\n"
" Missing input/output files default to stdin/stdout.\n"
" Replacement is one of the following: \n"
" character\n"
" hex constant ( i.e., 0x3F )\n"
" integer from 0 to 255 with decimal point ( i.e., 132. )\n");
}

canonical_decompiled_code:
int func7()
{
return puts(
"\n"
"Usage: ascii-only [-r replacement] [-l log_file ] [-i input_file] [-o output_file]\n"
"\n"
" Missing input/output files default to stdin/stdout.\n"
" Replacement is one of the following: \n"
" character\n"
" hex constant ( i.e., 0x3F )\n"
" integer from 0 to 255 with decimal point ( i.e., 132. )\n");
}

original_code:
void show_usage()
{
    printf("\nUsage: "
           "ascii-only [-r replacement] [-l log_file ] [-i input_file] [-o output_file]\n\n"
           "  Missing input/output files default to stdin/stdout.\n"
           "  Replacement is one of the following: \n"
           "   character\n"
           "   hex constant ( i.e., 0x3F )\n"
           "   integer from 0 to 255 with decimal point ( i.e., 132. )\n\n");
}


decompiled_code:
__int64 __fastcall determine_replacement(int a1, __int64 a2, __int64 a3)
{
const char **v3; // rbx
const char *v4; // rdi
const char *v5; // rbp
unsigned int v6; // ebx
const char *v7; // rbp
unsigned int v9; // [rsp+8h] [rbp-20h]
int v10; // [rsp+Ch] [rbp-1Ch]

v3 = (const char **)(a3 + 8LL * a1);
v4 = *v3;
if ( !*v3 )
return (unsigned int)-1;
if ( (v4[1] & 0xDF) == 88 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v7 = *v3;
if ( **v3 == 48 )
{
v6 = v9;
if ( v9 > 0xFF )
{
v6 = -1;
}
else if ( strlen(v7) > 4 )
{
v6 = -1;
}
else if ( v7[v10] )
{
v6 = -1;
}
}
else
{
v6 = -1;
}
}
else
{
v6 = -1;
}
}
else if ( v4[1] )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v5 = *v3;
if ( strlen(*v3) > 4 )
{
v6 = -1;
}
else
{
v6 = v9;
if ( v9 > 0xFF )
{
v6 = -1;
}
else if ( v5[v10] )
{
v6 = -1;
}
}
}
else
{
v6 = -1;
}
}
else
{
v6 = *v4;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2, __int64 a3)
{
const char **v3; // rbx
const char *v4; // rdi
const char *v5; // rbp
unsigned int v6; // ebx
const char *v7; // rbp
unsigned int v9; // [rsp+8h] [rbp-20h]
int v10; // [rsp+Ch] [rbp-1Ch]

v3 = (const char **)(a3 + 8LL * a1);
v4 = *v3;
if ( !*v3 )
return (unsigned int)-1;
if ( (v4[1] & 0xDF) == 88 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v7 = *v3;
if ( **v3 == 48 )
{
v6 = v9;
if ( v9 > 0xFF )
{
v6 = -1;
}
else if ( strlen(v7) > 4 )
{
v6 = -1;
}
else if ( v7[v10] )
{
v6 = -1;
}
}
else
{
v6 = -1;
}
}
else
{
v6 = -1;
}
}
else if ( v4[1] )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v5 = *v3;
if ( strlen(*v3) > 4 )
{
v6 = -1;
}
else
{
v6 = v9;
if ( v9 > 0xFF )
{
v6 = -1;
}
else if ( v5[v10] )
{
v6 = -1;
}
}
}
else
{
v6 = -1;
}
}
else
{
v6 = *v4;
}
return v6;
}

original_code:
int determine_replacement(int i, int argc, char **argv)
{
    int n, R, res;
    if (argv[i]) {
        switch(argv[i][1]) {
            case 'X':
            case 'x':
                res = sscanf(argv[i],"%x%n", &R,&n);
                if ((res != 1) || (argv[i][0] != '0') ||
                    (R < 0) || (R > 255) ||
                    (strlen(argv[i]) > 4) || (argv[i][n]))
                    break;
                 return R;
            case 0 :
                R = argv[i][0];
                return R;
            default :
                res = sscanf(argv[i],"%d.%n", &R,&n);
                if ((res != 1) || (strlen(argv[i]) > 4) ||
                    (R < 0) || (R > 255) || (argv[i][n]))
                    break;
                return R;
        }
    }
    return -1;
}

canonical_original_code:
int determine_replacement(int i, int argc, char **argv)
{
    int n; int R; int res;
    if (argv[i]) {
        switch(argv[i][1]) {
            case 'X':
            case 'x':
                res = sscanf(argv[i],"%x%n", &R,&n);
                if ((res != 1) || (argv[i][0] != '0') ||
                    (R < 0) || (R > 255) ||
                    (strlen(argv[i]) > 4) || (argv[i][n]))
                    break;
                 return R;
            case 0 :
                R = argv[i][0];
                return R;
            default :
                res = sscanf(argv[i],"%d.%n", &R,&n);
                if ((res != 1) || (strlen(argv[i]) > 4) ||
                    (R < 0) || (R > 255) || (argv[i][n]))
                    break;
                return R;
        }
    }
    return -1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: n int

variable_types: R int

variable_types: res int


option

decompiled_code:
__int64 __fastcall option(char *s1, int a2, __int64 a3, int *a4)
{
__int64 v6; // rbx
unsigned int v7; // er15

if ( a2 <= 1 )
return 0;
v6 = 2LL;
v7 = 0;
do
{
if ( !strcmp(s1, *(const char **)(a3 + 8 * v6 - 8)) )
{
if ( v7 )
{
*a4 = a2;
}
else
{
v7 = v6;
*a4 += 2;
}
}
++v6;
}
while ( v6 != a2 + 1 );
return v7;
}

original_code:
int option(char *s, int argc, char **argv, int *flags)
{
    int i, j;
    for (i = 0, j = 1; j < argc; j++) {
        if (!strcmp(s, argv[j])) {
            if (i)
                *flags = argc;
            else {
                i = j+1;
                *flags += 2;
            }
        }
    }
    return i;
}

canonical_original_code:
int option(char *s, int argc, char **argv, int *flags)
{
    int i; int j;
    for (i = 0, j = 1; j < argc; j++) {
        if (!strcmp(s, argv[j])) {
            if (i)
                *flags = argc;
            else {
                i = j+1;
                *flags += 2;
            }
        }
    }
    return i;
}

variable_types:
s
char *

variable_types:
flags
int *


main

canonical_name: main

repo: johnpeck/boxcom

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("bignum is %u\r\n", 4233600LL);
return 0;
}

original_code:
int main(void) {
  uint32_t bignum = 4233600;
  printf("bignum is %u\r\n",bignum);
  return 0;
}

canonical_original_code:
int main() {
  unsigned int bignum = 4233600;
  printf("bignum is %u\r\n",bignum);
  return 0;
}

variable_types:
bignum
unsigned int


p

repo: johnpmayer/makerbardrumset

decompiled_code:
int __fastcall p(const char *a1)
{
puts(a1);
return fflush(_bss_start);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
puts(a1);
return fflush(_bss_start);
}

original_code:
void p(char* s) {
  printf("%s\n",s);
  fflush(stdout);
}

canonical_original_code:
void p(char *s) {
  printf("%s\n",s);
  fflush(stdout);
}


playShit

decompiled_code:
int __fastcall playShit(unsigned __int8 a1)
{
int *v1; // rbp
int v2; // er12
int result; // eax
__pid_t v4; // eax
int v5; // er12
int v6; // ebp
const char *v7; // rbx
__pid_t v8; // ebx
char *v9[11]; // [rsp+0h] [rbp-78h] BYREF
int stat_loc[7]; // [rsp+5Ch] [rbp-1Ch] BYREF

v1 = __errno_location();
v2 = *v1;
while ( 1 )
{
v4 = waitpid(-1, stat_loc, 1);
if ( v4 < 0 )
break;
if ( !v4 )
goto LABEL_3;
printf("Pid terminated %d\n", (unsigned int)v4);
fflush(_bss_start);
++finished;
}
perror("waitpid");
LABEL_3:
*v1 = v2;
if ( started - finished > 7 )
return puts("Too many");
result = a1 - 48;
switch ( a1 )
{
case '0':
if ( shakeMode && shakePid > 0 )
{
kill(shakePid, 9);
shakeMode = 0;
p("killed track");
shakePid = 0;
v5 = 0;
v6 = 0;
v7 = "Samples/pickupneedle.mp3";
goto LABEL_12;
}
return result;
case '1':
if ( shakeMode != 1 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
shakeMode = 1;
v5 = 0;
v6 = 1;
v7 = "Samples/shake1.mp3";
goto LABEL_12;
}
return result;
case '2':
if ( shakeMode != 2 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
shakeMode = 2;
v5 = 0;
v6 = 1;
v7 = "Samples/shake2.mp3";
goto LABEL_12;
}
return result;
case 'F':
fp1 = 0;
return p("DS1 Foot Pedal up");
case 'T':
case 't':
v5 = 0;
v6 = 0;
v7 = "Samples/rimshot.mp3";
goto LABEL_12;
case 'X':
redButton = 0;
return result;
case 'Y':
greenButton = 0;
return result;
case 'Z':
blueButton = 0;
return result;
case 'a':
v5 = 0;
v6 = 0;
v7 = "Samples/chip snare.mp3";
goto LABEL_12;
case 'b':
v5 = 0;
v6 = 0;
v7 = "Samples/chip kick.mp3";
goto LABEL_12;
case 'c':
v5 = 0;
v6 = 0;
v7 = "Samples/chip boom.mp3";
goto LABEL_12;
case 'd':
v5 = 0;
v6 = 0;
v7 = "Samples/bleep.mp3";
goto LABEL_12;
case 'e':
v6 = fp1;
if ( fp1 )
{
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 42 CHH 2.mp3";
}
else
{
v5 = fp1;
v7 = "Samples/TR8-808CX 46 OHH 2.mp3";
}
goto LABEL_12;
case 'f':
fp1 = 1;
return result;
case 'g':
v5 = 0;
v6 = 0;
v7 = "Samples/808 wet snare.mp3";
goto LABEL_12;
case 'h':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 48 HTL 1.mp3";
goto LABEL_12;
case 'i':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 45 MTL 2.mp3";
goto LABEL_12;
case 'j':
v5 = 0;
v6 = 0;
v7 = "Samples/COWBELL.mp3";
goto LABEL_12;
case 'k':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 52 CYH 5.mp3";
goto LABEL_12;
case 'l':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 36 BD2 4.mp3";
goto LABEL_12;
case 'm':
v5 = 0;
v6 = 0;
v7 = "Samples/click.mp3";
goto LABEL_12;
case 'n':
v5 = 0;
v6 = 0;
v7 = "Samples/bongo.mp3";
goto LABEL_12;
case 'o':
v5 = 0;
v6 = 0;
v7 = "Samples/explosion.mp3";
goto LABEL_12;
case 'p':
v5 = 0;
v6 = 0;
v7 = "Samples/laser.mp3";
goto LABEL_12;
case 'q':
v5 = 0;
v6 = 0;
v7 = "Samples/clap.mp3";
goto LABEL_12;
case 'r':
v5 = 0;
v6 = 0;
v7 = "Samples/gong.mp3";
goto LABEL_12;
case 's':
if ( airhornPid > 0 )
{
kill(airhornPid, 9);
airhornPid = 0;
}
v5 = 1;
v6 = 0;
v7 = "Samples/airhorn.mp3";
goto LABEL_12;
case 'u':
v5 = 0;
v6 = 0;
v7 = "Samples/robot 1.mp3";
goto LABEL_12;
case 'w':
v5 = 0;
v6 = 0;
v7 = "Samples/robot 2.mp3";
LABEL_12:
printf("%s\r\n", v7);
fflush(_bss_start);
v9[3] = 0LL;
v9[4] = 0LL;
v9[5] = 0LL;
v9[6] = 0LL;
v9[7] = 0LL;
v9[8] = 0LL;
v9[9] = 0LL;
v9[0] = mpg;
v9[1] = "--quiet";
v9[2] = (char *)v7;
v8 = fork();
if ( v8 )
{
printf("Children: %d\n", (unsigned int)(++started - finished));
result = fflush(_bss_start);
}
else
{
result = execv(mpg, v9);
}
if ( v6 == 1 )
shakePid = v8;
if ( v5 == 1 )
airhornPid = v8;
break;
case 'x':
redButton = 1;
break;
case 'y':
greenButton = 1;
break;
case 'z':
blueButton = 1;
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned __int8 a1)
{
int *v1; // rbp
int v2; // er12
int result; // eax
__pid_t v4; // eax
int v5; // er12
int v6; // ebp
const char *v7; // rbx
__pid_t v8; // ebx
char *v9[11]; // [rsp+0h] [rbp-78h] BYREF
int stat_loc[7]; // [rsp+5Ch] [rbp-1Ch] BYREF

v1 = __errno_location();
v2 = *v1;
while ( 1 )
{
v4 = waitpid(-1, stat_loc, 1);
if ( v4 < 0 )
break;
if ( !v4 )
goto LABEL_3;
printf("Pid terminated %d\n", (unsigned int)v4);
fflush(_bss_start);
++finished;
}
perror("waitpid");
LABEL_3:
*v1 = v2;
if ( started - finished > 7 )
return puts("Too many");
result = a1 - 48;
switch ( a1 )
{
case '0':
if ( shakeMode && shakePid > 0 )
{
kill(shakePid, 9);
shakeMode = 0;
func7("killed track");
shakePid = 0;
v5 = 0;
v6 = 0;
v7 = "Samples/pickupneedle.mp3";
goto LABEL_12;
}
return result;
case '1':
if ( shakeMode != 1 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
shakeMode = 1;
v5 = 0;
v6 = 1;
v7 = "Samples/shake1.mp3";
goto LABEL_12;
}
return result;
case '2':
if ( shakeMode != 2 )
{
if ( shakePid > 0 )
kill(shakePid, 9);
shakeMode = 2;
v5 = 0;
v6 = 1;
v7 = "Samples/shake2.mp3";
goto LABEL_12;
}
return result;
case 'F':
fp1 = 0;
return func7("DS1 Foot Pedal up");
case 'T':
case 't':
v5 = 0;
v6 = 0;
v7 = "Samples/rimshot.mp3";
goto LABEL_12;
case 'X':
redButton = 0;
return result;
case 'Y':
greenButton = 0;
return result;
case 'Z':
blueButton = 0;
return result;
case 'a':
v5 = 0;
v6 = 0;
v7 = "Samples/chip snare.mp3";
goto LABEL_12;
case 'b':
v5 = 0;
v6 = 0;
v7 = "Samples/chip kick.mp3";
goto LABEL_12;
case 'c':
v5 = 0;
v6 = 0;
v7 = "Samples/chip boom.mp3";
goto LABEL_12;
case 'd':
v5 = 0;
v6 = 0;
v7 = "Samples/bleep.mp3";
goto LABEL_12;
case 'e':
v6 = fp1;
if ( fp1 )
{
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 42 CHH 2.mp3";
}
else
{
v5 = fp1;
v7 = "Samples/TR8-808CX 46 OHH 2.mp3";
}
goto LABEL_12;
case 'f':
fp1 = 1;
return result;
case 'g':
v5 = 0;
v6 = 0;
v7 = "Samples/808 wet snare.mp3";
goto LABEL_12;
case 'h':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 48 HTL 1.mp3";
goto LABEL_12;
case 'i':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 45 MTL 2.mp3";
goto LABEL_12;
case 'j':
v5 = 0;
v6 = 0;
v7 = "Samples/COWBELL.mp3";
goto LABEL_12;
case 'k':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 52 CYH 5.mp3";
goto LABEL_12;
case 'l':
v5 = 0;
v6 = 0;
v7 = "Samples/TR8-808CX 36 BD2 4.mp3";
goto LABEL_12;
case 'm':
v5 = 0;
v6 = 0;
v7 = "Samples/click.mp3";
goto LABEL_12;
case 'n':
v5 = 0;
v6 = 0;
v7 = "Samples/bongo.mp3";
goto LABEL_12;
case 'o':
v5 = 0;
v6 = 0;
v7 = "Samples/explosion.mp3";
goto LABEL_12;
case 'p':
v5 = 0;
v6 = 0;
v7 = "Samples/laser.mp3";
goto LABEL_12;
case 'q':
v5 = 0;
v6 = 0;
v7 = "Samples/clap.mp3";
goto LABEL_12;
case 'r':
v5 = 0;
v6 = 0;
v7 = "Samples/gong.mp3";
goto LABEL_12;
case 's':
if ( airhornPid > 0 )
{
kill(airhornPid, 9);
airhornPid = 0;
}
v5 = 1;
v6 = 0;
v7 = "Samples/airhorn.mp3";
goto LABEL_12;
case 'u':
v5 = 0;
v6 = 0;
v7 = "Samples/robot 1.mp3";
goto LABEL_12;
case 'w':
v5 = 0;
v6 = 0;
v7 = "Samples/robot 2.mp3";
LABEL_12:
printf("%s\r\n", v7);
fflush(_bss_start);
v9[3] = 0LL;
v9[4] = 0LL;
v9[5] = 0LL;
v9[6] = 0LL;
v9[7] = 0LL;
v9[8] = 0LL;
v9[9] = 0LL;
v9[0] = mpg;
v9[1] = "--quiet";
v9[2] = (char *)v7;
v8 = fork();
if ( v8 )
{
printf("Children: %d\n", (unsigned int)(++started - finished));
result = fflush(_bss_start);
}
else
{
result = execv(mpg, v9);
}
if ( v6 == 1 )
shakePid = v8;
if ( v5 == 1 )
airhornPid = v8;
break;
case 'x':
redButton = 1;
break;
case 'y':
greenButton = 1;
break;
case 'z':
blueButton = 1;
break;
default:
return result;
}
return result;
}

original_code:
void playShit(int keyCode) {
  int pid, status, serrno;
  serrno = (*__errno_location ());
  while (1)
  {
    pid = waitpid ((-1), &status, 1);
    if (pid < 0)
    {
      perror ("waitpid");
      break;
    }
    if (pid == 0)
      break;
    printf("Pid terminated %d\n",pid);
    fflush(stdout);
    finished++;
  }
  (*__errno_location ()) = serrno;
  if ((started - finished) >= 8) {
    printf("Too many\n");
    return;
  }
  char* fname = ((void *)0);
  int setShakePid = 0;
  int setAirhornPid = 0;
  switch((char)keyCode & 0xFF) {
    case 'a':
      fname = "Samples/chip snare.mp3";
      break;
    case 'b':
      fname = "Samples/chip kick.mp3";
      break;
    case 'c':
      fname = "Samples/chip boom.mp3";
      break;
    case 'd':
      fname = "Samples/bleep.mp3";
      break;
    case 'e':
      fname = fp1 ? "Samples/TR8-808CX 42 CHH 2.mp3"
        : "Samples/TR8-808CX 46 OHH 2.mp3";
      break;
    case 'f':
      fp1 = 1;
      break;
    case 'F':
      fp1 = 0;
      p("DS1 Foot Pedal up");
      return;
    case 'g':
      fname = "Samples/808 wet snare.mp3";
      break;
    case 'h':
      fname = "Samples/TR8-808CX 48 HTL 1.mp3";
      break;
    case 'i':
      fname = "Samples/TR8-808CX 45 MTL 2.mp3";
      break;
    case 'j':
      fname = "Samples/COWBELL.mp3";
      break;
    case 'k':
      fname = "Samples/TR8-808CX 52 CYH 5.mp3";
      break;
    case 'l':
      fname = "Samples/TR8-808CX 36 BD2 4.mp3";
      break;
    case 'm':
      fname = "Samples/click.mp3";
      break;
    case 'n':
      fname = "Samples/bongo.mp3";
      break;
    case 'o':
      fname = "Samples/explosion.mp3";
      break;
    case 'p':
      fname = "Samples/laser.mp3";
      break;
    case 'q':
      fname = "Samples/clap.mp3";
      break;
    case 'r':
      fname = "Samples/gong.mp3";
      break;
    case 's':
      if (airhornPid > 0) {
        kill(airhornPid, 9);
        airhornPid = 0;
      }
      fname = "Samples/airhorn.mp3";
      setAirhornPid = 1;
      break;
    case 't':
    case 'T':
      fname = "Samples/rimshot.mp3";
      break;
    case 'u':
      fname = "Samples/robot 1.mp3";
      break;
    case 'w':
      fname = "Samples/robot 2.mp3";
      break;
    case 'x':
      redButton = 1;
      break;
    case 'X':
      redButton = 0;
      break;
    case 'y':
      greenButton = 1;
      break;
    case 'Y':
      greenButton = 0;
      break;
    case 'z':
      blueButton = 1;
      break;
    case 'Z':
      blueButton = 0;
      break;
    case '0':
      if (shakeMode != 0 && shakePid > 0) {
        kill(shakePid, 9);
        shakeMode = 0;
        p("killed track");
        fname = "Samples/pickupneedle.mp3";
        shakePid = 0;
      }
      break;
    case '1':
      if (shakeMode != 1) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake1.mp3";
        setShakePid = 1;
        shakeMode = 1;
      }
      break;
    case '2':
      if (shakeMode != 2) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake2.mp3";
        setShakePid = 1;
        shakeMode = 2;
      }
      break;
  }
  if (fname != ((void *)0))
  {
    printf("%s\r\n", fname);
    fflush(stdout);
    char* const args[10] = { (char*)mpg, "--quiet", (char*)fname, ((void *)0) };
    int pid = fork();
    if (pid == 0) {
      execv(mpg, args);
    } else {
      started++;
      printf("Children: %d\n", (started - finished));
      fflush(stdout);
    }
    if (setShakePid == 1) {
      shakePid = pid;
    }
    if (setAirhornPid == 1) {
      airhornPid = pid;
    }
  }
}

canonical_original_code:
void playShit(int keyCode) {
  int pid; int status; int serrno;
  serrno = (*__errno_location ());
  while (1)
  {
    pid = waitpid ((-1), &status, 1);
    if (pid < 0)
    {
      perror ("waitpid");
      break;
    }
    if (pid == 0)
      break;
    printf("Pid terminated %d\n",pid);
    fflush(stdout);
    finished++;
  }
  (*__errno_location ()) = serrno;
  if ((started - finished) >= 8) {
    printf("Too many\n");
    return;
  }
  char *fname = ((void *)0);
  int setShakePid = 0;
  int setAirhornPid = 0;
  switch((char)keyCode & 0xFF) {
    case 'a':
      fname = "Samples/chip snare.mp3";
      break;
    case 'b':
      fname = "Samples/chip kick.mp3";
      break;
    case 'c':
      fname = "Samples/chip boom.mp3";
      break;
    case 'd':
      fname = "Samples/bleep.mp3";
      break;
    case 'e':
      fname = fp1 ? "Samples/TR8-808CX 42 CHH 2.mp3"
        : "Samples/TR8-808CX 46 OHH 2.mp3";
      break;
    case 'f':
      fp1 = 1;
      break;
    case 'F':
      fp1 = 0;
      p("DS1 Foot Pedal up");
      return;
    case 'g':
      fname = "Samples/808 wet snare.mp3";
      break;
    case 'h':
      fname = "Samples/TR8-808CX 48 HTL 1.mp3";
      break;
    case 'i':
      fname = "Samples/TR8-808CX 45 MTL 2.mp3";
      break;
    case 'j':
      fname = "Samples/COWBELL.mp3";
      break;
    case 'k':
      fname = "Samples/TR8-808CX 52 CYH 5.mp3";
      break;
    case 'l':
      fname = "Samples/TR8-808CX 36 BD2 4.mp3";
      break;
    case 'm':
      fname = "Samples/click.mp3";
      break;
    case 'n':
      fname = "Samples/bongo.mp3";
      break;
    case 'o':
      fname = "Samples/explosion.mp3";
      break;
    case 'p':
      fname = "Samples/laser.mp3";
      break;
    case 'q':
      fname = "Samples/clap.mp3";
      break;
    case 'r':
      fname = "Samples/gong.mp3";
      break;
    case 's':
      if (airhornPid > 0) {
        kill(airhornPid, 9);
        airhornPid = 0;
      }
      fname = "Samples/airhorn.mp3";
      setAirhornPid = 1;
      break;
    case 't':
    case 'T':
      fname = "Samples/rimshot.mp3";
      break;
    case 'u':
      fname = "Samples/robot 1.mp3";
      break;
    case 'w':
      fname = "Samples/robot 2.mp3";
      break;
    case 'x':
      redButton = 1;
      break;
    case 'X':
      redButton = 0;
      break;
    case 'y':
      greenButton = 1;
      break;
    case 'Y':
      greenButton = 0;
      break;
    case 'z':
      blueButton = 1;
      break;
    case 'Z':
      blueButton = 0;
      break;
    case '0':
      if (shakeMode != 0 && shakePid > 0) {
        kill(shakePid, 9);
        shakeMode = 0;
        p("killed track");
        fname = "Samples/pickupneedle.mp3";
        shakePid = 0;
      }
      break;
    case '1':
      if (shakeMode != 1) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake1.mp3";
        setShakePid = 1;
        shakeMode = 1;
      }
      break;
    case '2':
      if (shakeMode != 2) {
        if (shakePid > 0) kill(shakePid, 9);
        fname = "Samples/shake2.mp3";
        setShakePid = 1;
        shakeMode = 2;
      }
      break;
  }
  if (fname != ((void *)0))
  {
    printf("%s\r\n", fname);
    fflush(stdout);
    char *args[10] = { (char*)mpg, "--quiet", (char*)fname, ((void *)0) };
    int pid = fork();
    if (pid == 0) {
      execv(mpg, args);
    } else {
      started++;
      printf("Children: %d\n", (started - finished));
      fflush(stdout);
    }
    if (setShakePid == 1) {
      shakePid = pid;
    }
    if (setAirhornPid == 1) {
      airhornPid = pid;
    }
  }
}

variable_types: keyCode int

variable_types: pid int

variable_types: status int

variable_types: serrno int

variable_types:
fname
char *

variable_types: setShakePid int

variable_types: setAirhornPid int

variable_types:
args
char *[10]