runner

decompiled_code:
__int64 __fastcall runner(const char **a1, const char **a2, int a3, const char *a4)
{
unsigned int v8; // er12
__pid_t v9; // eax
int v10; // eax
char *v11; // rdx
char v12; // cl
const char **v13; // r15
const char *v14; // rax
char v15; // dl
const char *v16; // rdi
int v17; // esi
__int64 v18; // rdx
int v19; // er8
__int64 v20; // r9
__int64 v21; // rcx
const char **v22; // rdx
__int64 v23; // rax
__int64 v24; // rcx
const char *v25; // rdx
__int64 v26; // rax
__int64 v27; // rcx
int v28; // ebx
__time_t v29; // rdx
__suseconds_t v30; // rcx
unsigned int v32; // er15
int *v33; // rax
char *v34; // rax
int *v35; // rax
char *v36; // rax
char *v37; // r12
const char **v38; // r15
const char *i; // rdx
__int64 *v40; // [rsp+8h] [rbp-80h]
__int64 v41; // [rsp+10h] [rbp-78h]
int v42; // [rsp+1Ch] [rbp-6Ch]
char stat_loc; // [rsp+2Ch] [rbp-5Ch] BYREF
unsigned __int8 stat_loc_1; // [rsp+2Dh] [rbp-5Bh]
struct timeval stat_loc_4; // [rsp+30h] [rbp-58h] BYREF
struct timeval tv; // [rsp+40h] [rbp-48h] BYREF

if ( show )
{
v37 = (char *)cmdpath_resolve(a1, 0LL);
if ( wrapper )
fprintf(stderr, "WRAPPER='%s' ", wrapper);
v38 = a2 + 1;
fprintf(stderr, "%s ", v37);
for ( i = *a2; i; i = *(v38 - 1) )
{
++v38;
fprintf(stderr, "%s ", i);
}
fputc(10, stderr);
free(v37);
}
v8 = noop;
if ( noop )
return 0;
if ( time_subcmds && gettimeofday(&stat_loc_4, 0LL) < 0 )
{
v33 = _errno_location();
v34 = strerror(*v33);
fprintf(stderr, "gettimeofday(): %s\n", v34);
}
v9 = fork();
if ( v9 == -1 )
{
die("fork():");
LABEL_6:
v10 = dynarray_nochk_count(a2);
v11 = (char *)wrapper;
if ( wrapper )
{
v12 = *wrapper;
++v10;
if ( *wrapper )
{
do
{
++v11;
v10 += v12 == 44;
v12 = *v11;
}
while ( *v11 );
}
}
v13 = (const char **)umalloc(8LL * (v10 + 2));
v14 = (const char *)wrapper;
if ( wrapper && (v15 = *wrapper) != 0 )
{
v16 = (const char *)wrapper;
v17 = 0;
do
{
++v14;
if ( v15 == 44 )
{
v18 = v17;
*((_BYTE *)v14 - 1) = 0;
++v17;
v13[v18] = v16;
v16 = v14;
}
v15 = *v14;
}
while ( *v14 );
v19 = v17 + 1;
v20 = v17;
v21 = v20 * 8 + 8;
v22 = &v13[v20 + 1];
if ( v16 == v14 )
{
v22 = &v13[v20];
}
else
{
v13[v17] = v16;
v19 = v17 + 2;
v21 = v20 * 8 + 16;
}
}
else
{
v22 = v13;
v21 = 8LL;
v19 = 1;
}
v41 = v21;
v40 = (__int64 *)v22;
v42 = v19;
v23 = cmdpath_resolve(a1, &tv);
v24 = v41;
*v40 = v23;
v25 = *a2;
if ( *a2 )
{
v26 = v42 + 1;
do
{
v13[v26 - 1] = v25;
v27 = (int)v26++;
v25 = (&a2[v26])[-v42 - 1];
}
while ( v25 );
v24 = 8 * v27;
}
*(const char **)((char *)v13 + v24) = 0LL;
umask(orig_umask);
((void (__fastcall *)(const char *, const char **))tv.tv_sec)(*v13, v13);
die("execv(\"%s\"):", *v13);
goto LABEL_22;
}
if ( !v9 )
goto LABEL_6;
LABEL_22:
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
die("wait()");
if ( time_subcmds && gettimeofday(&tv, 0LL) < 0 )
{
v35 = _errno_location();
v36 = strerror(*v35);
fprintf(stderr, "gettimeofday(): %s\n", v36);
}
v28 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 || (v32 = stat_loc_1) == 0 )
{
if ( (char)((stat_loc & 0x7F) + 1) > 1 )
{
fprintf(stderr, "%s caught signal %d\n", *a1, stat_loc & 0x7F);
if ( a4 )
remove(a4);
exit(v28 + 128);
}
}
else
{
if ( a4 )
remove(a4);
v8 = v32;
if ( !a3 )
die("%s returned %d", *a1, v32);
}
if ( time_subcmds )
{
v29 = tv.tv_sec - stat_loc_4.tv_sec;
v30 = tv.tv_usec - stat_loc_4.tv_usec;
if ( tv.tv_usec - stat_loc_4.tv_usec < 0 )
{
--v29;
v30 += 1000000LL;
}
printf("# %s %ld.%06ld\n", *a1, v29, v30);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, const char **a2, int a3, const char *a4)
{
unsigned int v8; // er12
__pid_t v9; // eax
int v10; // eax
char *v11; // rdx
char v12; // cl
const char **v13; // r15
const char *v14; // rax
char v15; // dl
const char *v16; // rdi
int v17; // esi
__int64 v18; // rdx
int v19; // er8
__int64 v20; // r9
__int64 v21; // rcx
const char **v22; // rdx
__int64 v23; // rax
__int64 v24; // rcx
const char *v25; // rdx
__int64 v26; // rax
__int64 v27; // rcx
int v28; // ebx
__time_t v29; // rdx
__suseconds_t v30; // rcx
unsigned int v32; // er15
int *v33; // rax
char *v34; // rax
int *v35; // rax
char *v36; // rax
char *v37; // r12
const char **v38; // r15
const char *i; // rdx
__int64 *v40; // [rsp+8h] [rbp-80h]
__int64 v41; // [rsp+10h] [rbp-78h]
int v42; // [rsp+1Ch] [rbp-6Ch]
char stat_loc; // [rsp+2Ch] [rbp-5Ch] BYREF
unsigned __int8 stat_loc_1; // [rsp+2Dh] [rbp-5Bh]
struct timeval stat_loc_4; // [rsp+30h] [rbp-58h] BYREF
struct timeval tv; // [rsp+40h] [rbp-48h] BYREF

if ( show )
{
v37 = (char *)cmdpath_resolve(a1, 0LL);
if ( wrapper )
fprintf(stderr, "WRAPPER='%s' ", wrapper);
v38 = a2 + 1;
fprintf(stderr, "%s ", v37);
for ( i = *a2; i; i = *(v38 - 1) )
{
++v38;
fprintf(stderr, "%s ", i);
}
fputc(10, stderr);
free(v37);
}
v8 = noop;
if ( noop )
return 0;
if ( time_subcmds && gettimeofday(&stat_loc_4, 0LL) < 0 )
{
v33 = _errno_location();
v34 = strerror(*v33);
fprintf(stderr, "gettimeofday(): %s\n", v34);
}
v9 = fork();
if ( v9 == -1 )
{
die("fork():");
LABEL_6:
v10 = dynarray_nochk_count(a2);
v11 = (char *)wrapper;
if ( wrapper )
{
v12 = *wrapper;
++v10;
if ( *wrapper )
{
do
{
++v11;
v10 += v12 == 44;
v12 = *v11;
}
while ( *v11 );
}
}
v13 = (const char **)umalloc(8LL * (v10 + 2));
v14 = (const char *)wrapper;
if ( wrapper && (v15 = *wrapper) != 0 )
{
v16 = (const char *)wrapper;
v17 = 0;
do
{
++v14;
if ( v15 == 44 )
{
v18 = v17;
*((_BYTE *)v14 - 1) = 0;
++v17;
v13[v18] = v16;
v16 = v14;
}
v15 = *v14;
}
while ( *v14 );
v19 = v17 + 1;
v20 = v17;
v21 = v20 * 8 + 8;
v22 = &v13[v20 + 1];
if ( v16 == v14 )
{
v22 = &v13[v20];
}
else
{
v13[v17] = v16;
v19 = v17 + 2;
v21 = v20 * 8 + 16;
}
}
else
{
v22 = v13;
v21 = 8LL;
v19 = 1;
}
v41 = v21;
v40 = (__int64 *)v22;
v42 = v19;
v23 = cmdpath_resolve(a1, &tv);
v24 = v41;
*v40 = v23;
v25 = *a2;
if ( *a2 )
{
v26 = v42 + 1;
do
{
v13[v26 - 1] = v25;
v27 = (int)v26++;
v25 = (&a2[v26])[-v42 - 1];
}
while ( v25 );
v24 = 8 * v27;
}
*(const char **)((char *)v13 + v24) = 0LL;
umask(orig_umask);
((void (__fastcall *)(const char *, const char **))tv.tv_sec)(*v13, v13);
die("execv(\"%s\"):", *v13);
goto LABEL_22;
}
if ( !v9 )
goto LABEL_6;
LABEL_22:
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
die("wait()");
if ( time_subcmds && gettimeofday(&tv, 0LL) < 0 )
{
v35 = _errno_location();
v36 = strerror(*v35);
fprintf(stderr, "gettimeofday(): %s\n", v36);
}
v28 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 || (v32 = stat_loc_1) == 0 )
{
if ( (char)((stat_loc & 0x7F) + 1) > 1 )
{
fprintf(stderr, "%s caught signal %d\n", *a1, stat_loc & 0x7F);
if ( a4 )
remove(a4);
exit(v28 + 128);
}
}
else
{
if ( a4 )
remove(a4);
v8 = v32;
if ( !a3 )
die("%s returned %d", *a1, v32);
}
if ( time_subcmds )
{
v29 = tv.tv_sec - stat_loc_4.tv_sec;
v30 = tv.tv_usec - stat_loc_4.tv_usec;
if ( tv.tv_usec - stat_loc_4.tv_usec < 0 )
{
--v29;
v30 += 1000000LL;
}
printf("# %s %ld.%06ld\n", *a1, v29, v30);
}
return v8;
}

original_code:
static int runner(struct cmdpath *path, char **args, int return_ec, const char *to_remove)
{
 pid_t pid;
 struct timeval time_start, time_end;
 if(show){
  char *resolved = cmdpath_resolve(path, ((void *)0));
  int i;
  if(wrapper)
   fprintf(stderr, "WRAPPER='%s' ", wrapper);
  fprintf(stderr, "%s ", resolved);
  for(i = 0; args[i]; i++)
   fprintf(stderr, "%s ", args[i]);
  fputc('\n', stderr);
  free(resolved);
 }
 if(noop)
  return 0;
 if(time_subcmds && gettimeofday(&time_start, ((void *)0)) < 0)
  fprintf(stderr, "gettimeofday(): %s\n", strerror((*__errno_location ())));
 pid = fork();
 switch(pid){
  case -1:
   die("fork():");
  case 0:
  {
   int nargs = dynarray_nochk_count((void **)args);
   int i_in = 0, i_out = 0;
   char **argv;
   cmdpath_exec_fn *execfn;
   if(wrapper){
    char *p;
    nargs++;
    for(p = wrapper; *p; p++)
     nargs += *p == ',';
   }
   argv = umalloc((2 + nargs) * sizeof *argv);
   if(wrapper){
    char *p, *last;
    for(p = last = wrapper; *p; p++)
     if(*p == ','){
      *p = '\0';
      argv[i_out++] = last;
      last = p + 1;
     }
    if(last != p)
     argv[i_out++] = last;
   }
   argv[i_out++] = cmdpath_resolve(path, &execfn);
   while(args[i_in])
    argv[i_out++] = args[i_in++];
   argv[i_out++] = ((void *)0);
   umask(orig_umask);
   (*execfn)(argv[0], argv);
   die("execv(\"%s\"):", argv[0]);
  }
  default:
  {
   int status, i;
   if(wait(&status) == -1)
    die("wait()");
   if(time_subcmds && gettimeofday(&time_end, ((void *)0)) < 0)
    fprintf(stderr, "gettimeofday(): %s\n", strerror((*__errno_location ())));
   if((((status) & 0x7f) == 0) && (i = (((status) & 0xff00) >> 8)) != 0){
    if(to_remove)
     remove(to_remove);
    if(!return_ec)
     die("%s returned %d", path->path, i);
   }else if((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)){
    int sig = ((status) & 0x7f);
    fprintf(stderr, "%s caught signal %d\n", path->path, sig);
    if(to_remove)
     remove(to_remove);
    exit(128 + sig);
   }
   if(time_subcmds){
    time_t secdiff = time_end.tv_sec - time_start.tv_sec;
    suseconds_t usecdiff = time_end.tv_usec - time_start.tv_usec;
    if(usecdiff < 0){
     secdiff--;
     usecdiff += 1000000L;
    }
    printf("# %s %ld.%06ld\n", path->path, (long)secdiff, (long)usecdiff);
   }
   return i;
  }
 }
}

canonical_original_code:
static int runner(struct cmdpath *path, char **args, int return_ec, char *to_remove)
{
 int pid;
 struct timeval time_start; struct timeval time_end;
 if(show){
  char *resolved = cmdpath_resolve(path, ((void *)0));
  int i;
  if(wrapper)
   fprintf(stderr, "WRAPPER='%s' ", wrapper);
  fprintf(stderr, "%s ", resolved);
  for(i = 0; args[i]; i++)
   fprintf(stderr, "%s ", args[i]);
  fputc('\n', stderr);
  free(resolved);
 }
 if(noop)
  return 0;
 if(time_subcmds && gettimeofday(&time_start, ((void *)0)) < 0)
  fprintf(stderr, "gettimeofday(): %s\n", strerror((*__errno_location ())));
 pid = fork();
 switch(pid){
  case -1:
   die("fork():");
  case 0:
  {
   int nargs = dynarray_nochk_count((void **)args);
   int i_in = 0; int i_out = 0;
   char **argv;
   int (*execfn)(char *, char *[]);
   if(wrapper){
    char *p;
    nargs++;
    for(p = wrapper; *p; p++)
     nargs += *p == ',';
   }
   argv = umalloc((2 + nargs) * sizeof *argv);
   if(wrapper){
    char *p; char *last;
    for(p = last = wrapper; *p; p++)
     if(*p == ','){
      *p = '\0';
      argv[i_out++] = last;
      last = p + 1;
     }
    if(last != p)
     argv[i_out++] = last;
   }
   argv[i_out++] = cmdpath_resolve(path, &execfn);
   while(args[i_in])
    argv[i_out++] = args[i_in++];
   argv[i_out++] = ((void *)0);
   umask(orig_umask);
   (*execfn)(argv[0], argv);
   die("execv(\"%s\"):", argv[0]);
  }
  default:
  {
   int status; int i;
   if(wait(&status) == -1)
    die("wait()");
   if(time_subcmds && gettimeofday(&time_end, ((void *)0)) < 0)
    fprintf(stderr, "gettimeofday(): %s\n", strerror((*__errno_location ())));
   if((((status) & 0x7f) == 0) && (i = (((status) & 0xff00) >> 8)) != 0){
    if(to_remove)
     remove(to_remove);
    if(!return_ec)
     die("%s returned %d", path->path, i);
   }else if((((char) (((status) & 0x7f) + 1) >> 1) > 0)){
    int sig = ((status) & 0x7f);
    fprintf(stderr, "%s caught signal %d\n", path->path, sig);
    if(to_remove)
     remove(to_remove);
    exit(128 + sig);
   }
   if(time_subcmds){
    long secdiff = time_end.tv_sec - time_start.tv_sec;
    long usecdiff = time_end.tv_usec - time_start.tv_usec;
    if(usecdiff < 0){
     secdiff--;
     usecdiff += 1000000L;
    }
    printf("# %s %ld.%06ld\n", path->path, (long)secdiff, (long)usecdiff);
   }
   return i;
  }
 }
}

variable_types: struct cmdpath { char *path; enum cmdpath_type { RELATIVE_TO_UCC=0, USE_PATH=1, FROM_Bprefix=2 } type; } *

variable_types:
args
char **

variable_types: pid int

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

variable_types:
resolved
char *

variable_types: nargs int

variable_types:
argv
char **

variable_types:
execfn
int (*)(char *, char *[])

variable_types:
p
char *

variable_types:
last
char *

variable_types: status int

variable_types: sig int

variable_types: secdiff long

variable_types: usecdiff long


repo: bobrippling/ucc-c-compiler

decompiled_code:
void __fastcall ucc_ext_cmds_show(int a1)
{
show = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
show = a1;
}

original_code:
void ucc_ext_cmds_show(int s)
{ show = s; }

variable_types: s int

return_type: void


decompiled_code:
void __fastcall ucc_ext_cmds_noop(int a1)
{
noop = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
noop = a1;
}

original_code:
void ucc_ext_cmds_noop(int n)
{ noop = n; }

variable_types: n int


execute

decompiled_code:
__int64 __fastcall execute(const char *a1, const char **a2)
{
const char *v3; // [rsp+0h] [rbp-18h] BYREF
int v4; // [rsp+8h] [rbp-10h]

v3 = a1;
v4 = 1;
return runner(&v3, a2, 0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char **a2)
{
const char *v3; // [rsp+0h] [rbp-18h] BYREF
int v4; // [rsp+8h] [rbp-10h]

v3 = a1;
v4 = 1;
return func0(&v3, a2, 0, 0LL);
}

original_code:
void execute(char *path, char **args)
{
 struct cmdpath cmdpath;
 cmdpath.path = path;
 cmdpath.type = USE_PATH;
 runner(&cmdpath, args, 0, ((void *)0));
}

variable_types:
path
char *

variable_types: struct cmdpath { char *path; enum cmdpath_type { RELATIVE_TO_UCC=0, USE_PATH=1, FROM_Bprefix=2 } type; }

user_defined_types: struct cmdpath { char *path; enum cmdpath_type type; }


decompiled_code:
void __fastcall rename_or_move(const char *a1, const char *a2)
{
const char **v2; // rbx
int v3; // eax
int v4; // er13
char *v5; // rbp
const char *v6; // rdi
__int64 v7; // rax
const char *v8; // rdx
char *v9; // rbp
char *v10; // r13
int v11; // eax
const char *v12; // [rsp+0h] [rbp-88h] BYREF
int v13; // [rsp+8h] [rbp-80h]
const char *v14[4]; // [rsp+10h] [rbp-78h] BYREF
char v15; // [rsp+30h] [rbp-58h] BYREF
const char *v16; // [rsp+38h] [rbp-50h]
const char *v17; // [rsp+40h] [rbp-48h]
const char *v18; // [rsp+48h] [rbp-40h]
__int64 v19; // [rsp+50h] [rbp-38h]

v16 = a1;
v17 = ">";
v18 = a2;
v19 = 0LL;
if ( strcmp(a1, a2) )
{
v2 = (const char **)&v15;
v3 = 3;
v4 = 1;
v5 = &v15;
while ( 1 )
{
v6 = (const char *)*((_QWORD *)v5 + 1);
v5 += 8;
v4 += v3 + 1;
if ( !v6 )
break;
v3 = strlen(v6);
}
v7 = umalloc(v4);
v8 = "cat";
v9 = (char *)v7;
v10 = (char *)v7;
do
{
++v2;
v11 = sprintf(v10, "%s ", v8);
v8 = *v2;
v10 += v11;
}
while ( *v2 );
v14[1] = v9;
v14[0] = "-c";
v14[2] = 0LL;
v12 = "sh";
v13 = 1;
runner(&v12, v14, 0, a2);
free(v9);
}
}

original_code:
void rename_or_move(char *old, char *new)
{
 int len, i;
 char *cmd, *p;
 char *args[] = {
  "cat", old, ">", new, ((void *)0)
 };
 char *fixed[3];
 struct cmdpath shpath;
 if(!strcmp(old, new))
  return;
 for(i = 0, len = 1; args[i]; i++)
  len += strlen(args[i]) + 1;
 p = cmd = umalloc(len);
 for(i = 0; args[i]; i++)
  p += sprintf(p, "%s ", args[i]);
 fixed[0] = "-c";
 fixed[1] = cmd;
 fixed[2] = ((void *)0);
 shpath.path = "sh";
 shpath.type = USE_PATH;
 runner(&shpath, fixed, 0, new);
 free(cmd);
}

canonical_original_code:
void rename_or_move(char *old, char *new)
{
 int len; int i;
 char *cmd; char *p;
 char *args[] = {
  "cat", old, ">", new, ((void *)0)
 };
 char *fixed[3];
 struct cmdpath shpath;
 if(!strcmp(old, new))
  return;
 for(i = 0, len = 1; args[i]; i++)
  len += strlen(args[i]) + 1;
 p = cmd = umalloc(len);
 for(i = 0; args[i]; i++)
  p += sprintf(p, "%s ", args[i]);
 fixed[0] = "-c";
 fixed[1] = cmd;
 fixed[2] = ((void *)0);
 shpath.path = "sh";
 shpath.type = USE_PATH;
 runner(&shpath, fixed, 0, new);
 free(cmd);
}

variable_types:
old
char *

variable_types:
new
char *

variable_types: len int

variable_types: i int

variable_types:
cmd
char *

variable_types:
args
char *[]

variable_types:
fixed
char *[3]

user_defined_types: enum cmdpath_type { RELATIVE_TO_UCC=0, USE_PATH=1, FROM_Bprefix=2 }


compile

decompiled_code:
__int64 __fastcall compile(__int64 a1, const char *a2, __int64 a3, int a4)
{
const char *v7[7]; // [rsp+0h] [rbp-38h] BYREF

cmdpath_initrelative(v7, "cc1", "../cc1/cc1");
return runner_single_arg(v7, a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, __int64 a3, int a4)
{
const char *v7[7]; // [rsp+0h] [rbp-38h] BYREF

cmdpath_initrelative(v7, "cc1", "../cc1/cc1");
return func1(v7, a1, a2, a3, a4);
}

original_code:
int compile(char *in, const char *out, char **args, int return_ec)
{
 struct cmdpath cc1path;
 cmdpath_initrelative(&cc1path, "cc1", "../cc1/cc1");
 return runner_single_arg(&cc1path, in, out, args, return_ec);
}

canonical_original_code:
int compile(char *in, char *out, char **args, int return_ec)
{
 struct cmdpath cc1path;
 cmdpath_initrelative(&cc1path, "cc1", "../cc1/cc1");
 return runner_single_arg(&cc1path, in, out, args, return_ec);
}

variable_types:
in
char *

variable_types:
out
char *

variable_types:
args
char **

return_type: int


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

result = 0LL;
if ( a1 && *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

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

result = 0LL;
if ( a1 && *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

original_code:
size_t dynarray_nochk_count(void **ar)
{
 size_t len = 0;
 if(!ar)
  return 0;
 while(ar[len])
  len++;
 return len;
}

canonical_original_code:
unsigned long dynarray_nochk_count(void **ar)
{
 unsigned long len = 0;
 if(!ar)
  return 0;
 while(ar[len])
  len++;
 return len;
}

variable_types:
ar
void **

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall dynarray_nochk_pop(_QWORD **a1)
{
_QWORD *v2; // rdi
__int64 v3; // rax
__int64 *v4; // rdx
__int64 v5; // r12
__int64 result; // rax

v2 = *a1;
v3 = dynarray_nochk_count(v2);
if ( v3 )
{
v4 = &v2[v3 - 1];
v5 = *v4;
*v4 = 0LL;
if ( v3 == 1 )
{
free(v2);
*a1 = 0LL;
}
result = v5;
}
else
{
ice("dynarray.c", 88LL, "dynarray_nochk_pop", "dynarray_nochk_pop(): empty array");
result = dynarray_nochk_prepend();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD **a1)
{
_QWORD *v2; // rdi
__int64 v3; // rax
__int64 *v4; // rdx
__int64 v5; // r12
__int64 result; // rax

v2 = *a1;
v3 = func0(v2);
if ( v3 )
{
v4 = &v2[v3 - 1];
v5 = *v4;
*v4 = 0LL;
if ( v3 == 1 )
{
free(v2);
*a1 = 0LL;
}
result = v5;
}
else
{
ice("dynarray.c", 88LL, "dynarray_nochk_pop", "dynarray_nochk_pop(): empty array");
result = func5();
}
return result;
}

original_code:
void *dynarray_nochk_pop(void ***par)
{
 void **ar = *par;
 void *r;
 size_t n;
 n = dynarray_nochk_count(ar);
 do if(!(n > 0)) ice("dynarray.c", 88, __func__, "dynarray_nochk_pop(): empty array"); while(0);
 r = ar[n - 1];
 ar[n - 1] = ((void *)0);
 if(n == 1){
  free(ar);
  *par = ((void *)0);
 }
 return r;
}

canonical_original_code:
void *dynarray_nochk_pop(void ***par)
{
 void **ar = *par;
 void *r;
 unsigned long n;
 n = dynarray_nochk_count(ar);
 do if(!(n > 0)) ice("dynarray.c", 88, __func__, "dynarray_nochk_pop(): empty array"); while(0);
 r = ar[n - 1];
 ar[n - 1] = ((void *)0);
 if(n == 1){
  free(ar);
  *par = ((void *)0);
 }
 return r;
}

variable_types:
par
void ***

variable_types:
r
void *

variable_types:
n
unsigned long

return_type: void *


decompiled_code:
void __fastcall dynarray_nochk_free(_QWORD **a1, void (*a2)(void))
{
_QWORD *v2; // rbp
__int64 v4; // rdi

v2 = *a1;
if ( *a1 )
{
if ( a2 && *v2 )
{
do
{
a2();
v4 = v2[1];
++v2;
}
while ( v4 );
v2 = *a1;
}
free(v2);
*a1 = 0LL;
}
}

original_code:
void dynarray_nochk_free(void ***par, void (*f)(void *))
{
 void **ar = *par;
 if(ar){
  if(f)
   while(*ar){
    f(*ar);
    ar++;
   }
  free(*par);
  *par = ((void *)0);
 }
}

variable_types:
f
void (*)(void *)


decompiled_code:
void __fastcall dynarray_nochk_add_tmparray(__int64 *a1, _QWORD *a2)
{
_QWORD *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a2;
dynarray_nochk_add_array(a1, a2);
dynarray_nochk_free(&v2, 0LL);
}

canonical_decompiled_code:
void __fastcall func9(__int64 *a1, _QWORD *a2)
{
_QWORD *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a2;
func8(a1, a2);
func7(&v2, 0LL);
}

original_code:
void dynarray_nochk_add_tmparray(void ***par, void **ar2)
{
 dynarray_nochk_add_array(par, ar2);
 dynarray_nochk_free(&ar2, ((void *)0));
}


decompiled_code:
char *__fastcall expand_digraphs(char *haystack)
{
const char *v1; // r13
const char *v2; // r12
char **i; // rbx
char *j; // rbp
size_t v5; // rax

v1 = (const char *)&unk_100C;
v2 = "<:";
for ( i = &map_4; ; v1 = i[2] )
{
for ( j = haystack; ; memmove(j + 1, j + 2, v5 + 1) )
{
j = strstr(j, v2);
if ( !j )
break;
*j = *((_BYTE *)i + 8);
v5 = strlen(j + 2);
}
i += 2;
if ( !v1 )
break;
v2 = v1;
}
return haystack;
}

canonical_decompiled_code:
char *__fastcall func0(char *haystack)
{
const char *v1; // r13
const char *v2; // r12
char **i; // rbx
char *j; // rbp
size_t v5; // rax

v1 = (const char *)&unk_100C;
v2 = "<:";
for ( i = &map_4; ; v1 = i[2] )
{
for ( j = haystack; ; memmove(j + 1, j + 2, v5 + 1) )
{
j = strstr(j, v2);
if ( !j )
break;
*j = *((_BYTE *)i + 8);
v5 = strlen(j + 2);
}
i += 2;
if ( !v1 )
break;
v2 = v1;
}
return haystack;
}

original_code:
static char *expand_digraphs(char *line)
{
 static const struct
 {
  const char *from;
  char to;
 } map[] = {
  { "<:", '[' },
  { ":>", ']' },
  { "<%", '{' },
  { "%>", '}' },
  { "%:", '#' },
  { 0, 0 }
 };
 int i;
 for(i = 0; map[i].from; i++){
  char *pos = line;
  while((pos = strstr(pos, map[i].from))){
   *pos = map[i].to;
   memmove(pos + 1, pos + 2, strlen(pos + 2) + 1);
  }
 }
 return line;
}

canonical_original_code:
static char *expand_digraphs(char *line)
{
 static struct { char *from; char to; } map[] = {
  { "<:", '[' },
  { ":>", ']' },
  { "<%", '{' },
  { "%>", '}' },
  { "%:", '#' },
  { 0, 0 }
 };
 int i;
 for(i = 0; map[i].from; i++){
  char *pos = line;
  while((pos = strstr(pos, map[i].from))){
   *pos = map[i].to;
   memmove(pos + 1, pos + 2, strlen(pos + 2) + 1);
  }
 }
 return line;
}

variable_types:
line
char *

variable_types:
map
struct { char *from; char to; } []

variable_types:
pos
char *

return_type: char *


decompiled_code:
char *__fastcall expand_trigraphs(char *haystack)
{
char *i; // r13
char *v3; // rax
char *v4; // rdi
char v5; // si
char v6; // dl
__int64 v7; // rax
size_t v8; // rax

LABEL_2:
for ( i = haystack; ; memmove(i, v4 + 3, v8 + 1) )
{
v3 = strstr(i, "??");
v4 = v3;
if ( !v3 )
break;
v5 = v3[2];
i = v3 + 1;
v6 = 40;
v7 = 0LL;
while ( v5 != v6 )
{
++v7;
v6 = map_0[2 * v7];
if ( !v6 )
goto LABEL_2;
}
*v4 = byte_11A1[2 * (int)v7];
v8 = strlen(v4 + 3);
}
return haystack;
}

canonical_decompiled_code:
char *__fastcall func1(char *haystack)
{
char *i; // r13
char *v3; // rax
char *v4; // rdi
char v5; // si
char v6; // dl
__int64 v7; // rax
size_t v8; // rax

LABEL_2:
for ( i = haystack; ; memmove(i, v4 + 3, v8 + 1) )
{
v3 = strstr(i, "??");
v4 = v3;
if ( !v3 )
break;
v5 = v3[2];
i = v3 + 1;
v6 = 40;
v7 = 0LL;
while ( v5 != v6 )
{
++v7;
v6 = map_0[2 * v7];
if ( !v6 )
goto LABEL_2;
}
*v4 = byte_11A1[2 * (int)v7];
v8 = strlen(v4 + 3);
}
return haystack;
}

original_code:
static char *expand_trigraphs(char *line)
{
 static const struct
 {
  char from, to;
 } map[] = {
  { '(', '[' },
  { ')', ']' },
  { '<', '{' },
  { '>', '}' },
  { '=', '#' },
  { '/', '\\' },
  { '\'', '^' },
  { '!', '|' },
  { '-', '~' },
  { 0, 0 }
 };
 int i;
 char *anchor = line;
 for(;;){
  char *qmark = strstr(anchor, "??");
  if(!qmark)
   break;
  anchor = qmark + 1;
  for(i = 0; map[i].from; i++){
   if(map[i].from == qmark[2]){
    qmark[0] = map[i].to;
    memmove(qmark + 1, qmark + 3, strlen(qmark + 3) + 1);
    break;
   }
  }
 }
 return line;
}

canonical_original_code:
static char *expand_trigraphs(char *line)
{
 static struct { char from; } map[] = {
  { '(', '[' },
  { ')', ']' },
  { '<', '{' },
  { '>', '}' },
  { '=', '#' },
  { '/', '\\' },
  { '\'', '^' },
  { '!', '|' },
  { '-', '~' },
  { 0, 0 }
 };
 int i;
 char *anchor = line;
 for(;;){
  char *qmark = strstr(anchor, "??");
  if(!qmark)
   break;
  anchor = qmark + 1;
  for(i = 0; map[i].from; i++){
   if(map[i].from == qmark[2]){
    qmark[0] = map[i].to;
    memmove(qmark + 1, qmark + 3, strlen(qmark + 3) + 1);
    break;
   }
  }
 }
 return line;
}

variable_types:
map
struct { char from; } []

variable_types:
anchor
char *

variable_types:
qmark
char *


decompiled_code:
char *__fastcall strip_comment(char *s)
{
char *v1; // r12
char v2; // bp
char v3; // si
char *v4; // rbx
char v5; // al
__int64 v7; // rax
unsigned int v8; // ebp
__int64 v9; // rax

v1 = s;
v2 = *(_BYTE *)str_spc_skip();
if ( strip_in_block == 1 )
{
strip_in_block = 3;
}
else if ( strip_in_block == 2 )
{
strip_in_block = 0;
}
v3 = *s;
v4 = s;
if ( !*s )
return v1;
while ( 1 )
{
while ( 1 )
{
while ( (strip_in_block & 0xFFFFFFFD) == 1 )
{
if ( v3 == 42 )
{
v3 = v4[1];
if ( v3 == 47 )
{
strip_in_block = 2;
if ( strip_comments )
goto LABEL_25;
*v4++ = 32;
LABEL_8:
*v4 = 32;
goto LABEL_9;
}
}
if ( !strip_comments )
goto LABEL_8;
LABEL_9:
v3 = v4[1];
LABEL_10:
++v4;
if ( !v3 )
return v1;
}
if ( v3 == 34 || v3 == 39 )
{
v7 = str_quotefin2(v4 + 1);
if ( v7 )
{
v3 = *(_BYTE *)(v7 + 1);
v4 = (char *)v7;
}
else
{
if ( (*((_BYTE *)&wmode + 1) & 0x10) != 0 )
{
--loc_tok;
warn_at(0LL, "no terminating quote to string");
++loc_tok;
}
v4 = &v4[strlen(v4) - 1];
v3 = v4[1];
}
goto LABEL_10;
}
v5 = v4[1];
if ( v3 == 47 )
break;
v3 = *++v4;
if ( !v5 )
return v1;
}
if ( cpp_std > 1u && v5 == 47 )
break;
v3 = v4[1];
if ( v5 != 42 )
goto LABEL_10;
strip_in_block = 1;
if ( !strip_comments || strip_comments == 1 && v2 == 35 )
{
v3 = v4[2];
*(_WORD *)v4++ = 8224;
goto LABEL_10;
}
LABEL_25:
++v4;
}
switch ( strip_comments )
{
case 1:
if ( v2 == 35 )
{
LABEL_37:
*v4 = 0;
return v1;
}
LABEL_39:
v8 = strlen(s);
v9 = urealloc1(s, v8 + 3);
*(_BYTE *)(v9 + (unsigned int)((_DWORD)v4 - (_DWORD)s) + 1) = 42;
v1 = (char *)v9;
strcpy((char *)(v9 + v8), "*/");
return v1;
case 2:
goto LABEL_39;
case 0:
goto LABEL_37;
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
char *v1; // r12
char v2; // bp
char v3; // si
char *v4; // rbx
char v5; // al
__int64 v7; // rax
unsigned int v8; // ebp
__int64 v9; // rax

v1 = s;
v2 = *(_BYTE *)str_spc_skip();
if ( strip_in_block == 1 )
{
strip_in_block = 3;
}
else if ( strip_in_block == 2 )
{
strip_in_block = 0;
}
v3 = *s;
v4 = s;
if ( !*s )
return v1;
while ( 1 )
{
while ( 1 )
{
while ( (strip_in_block & 0xFFFFFFFD) == 1 )
{
if ( v3 == 42 )
{
v3 = v4[1];
if ( v3 == 47 )
{
strip_in_block = 2;
if ( strip_comments )
goto LABEL_25;
*v4++ = 32;
LABEL_8:
*v4 = 32;
goto LABEL_9;
}
}
if ( !strip_comments )
goto LABEL_8;
LABEL_9:
v3 = v4[1];
LABEL_10:
++v4;
if ( !v3 )
return v1;
}
if ( v3 == 34 || v3 == 39 )
{
v7 = str_quotefin2(v4 + 1);
if ( v7 )
{
v3 = *(_BYTE *)(v7 + 1);
v4 = (char *)v7;
}
else
{
if ( (*((_BYTE *)&wmode + 1) & 0x10) != 0 )
{
--loc_tok;
warn_at(0LL, "no terminating quote to string");
++loc_tok;
}
v4 = &v4[strlen(v4) - 1];
v3 = v4[1];
}
goto LABEL_10;
}
v5 = v4[1];
if ( v3 == 47 )
break;
v3 = *++v4;
if ( !v5 )
return v1;
}
if ( cpp_std > 1u && v5 == 47 )
break;
v3 = v4[1];
if ( v5 != 42 )
goto LABEL_10;
strip_in_block = 1;
if ( !strip_comments || strip_comments == 1 && v2 == 35 )
{
v3 = v4[2];
*(_WORD *)v4++ = 8224;
goto LABEL_10;
}
LABEL_25:
++v4;
}
switch ( strip_comments )
{
case 1:
if ( v2 == 35 )
{
LABEL_37:
*v4 = 0;
return v1;
}
LABEL_39:
v8 = strlen(s);
v9 = urealloc1(s, v8 + 3);
*(_BYTE *)(v9 + (unsigned int)((_DWORD)v4 - (_DWORD)s) + 1) = 42;
v1 = (char *)v9;
strcpy((char *)(v9 + v8), "*/");
return v1;
case 2:
goto LABEL_39;
case 0:
goto LABEL_37;
}
return v1;
}

original_code:
static char *strip_comment(char *line)
{
 const int is_directive = *str_spc_skip(line) == '#';
 char *s;
 if(strip_in_block == IN_BLOCK_BEGIN)
  strip_in_block = IN_BLOCK_FULL;
 else if(strip_in_block == IN_BLOCK_END)
  strip_in_block = NOT_IN_BLOCK;
 for(s = line; *s; s++){
  if(strip_in_block == IN_BLOCK_FULL || strip_in_block == IN_BLOCK_BEGIN){
   const int clear_comments = (strip_comments == STRIP_ALL);
   if(*s == '*' && s[1] == '/'){
    strip_in_block = IN_BLOCK_END;
    if(clear_comments)
     *s++ = ' ';
   }
   if(clear_comments)
    *s = ' ';
  }else if(*s == '"' || *s == '\''){
   char *end = str_quotefin2(s + 1, *s);
   if(!end){
    do{ if(WQUOTE == 0 || WQUOTE & wmode){ loc_tok.line--; warn_at(((void *)0), "no terminating quote to string"); loc_tok.line++; } }while(0);
    s = strchr(s, '\0') - 1;
   }else{
    s = end;
   }
  }else if(*s == '/'){
   if(cpp_std >= STD_C99 && s[1] == '/'){
    switch(strip_comments){
     case STRIP_EXCEPT_DIRECTIVE:
      if(is_directive)
       goto strip_1line;
     case STRIP_NONE:
     {
      const unsigned pos_slash = s - line;
      const unsigned len = strlen(line);
      line = urealloc1(line, len + 2 + 1);
      s = line + pos_slash;
      s[1] = '*';
      strcpy(line + len, "*/");
      break;
     }
strip_1line:
     case STRIP_ALL:
      *s = '\0';
      break;
    }
    break;
   }else if(s[1] == '*'){
    strip_in_block = IN_BLOCK_BEGIN;
    switch(strip_comments){
     case STRIP_EXCEPT_DIRECTIVE:
      if(!is_directive)
       break;
     case STRIP_ALL:
      *s = s[1] = ' ';
      s++;
     case STRIP_NONE:
      break;
    }
   }
  }
 }
 return line;
}

canonical_original_code:
static char *strip_comment(char *line)
{
 int is_directive = *str_spc_skip(line) == '#';
 char *s;
 if(strip_in_block == IN_BLOCK_BEGIN)
  strip_in_block = IN_BLOCK_FULL;
 else if(strip_in_block == IN_BLOCK_END)
  strip_in_block = NOT_IN_BLOCK;
 for(s = line; *s; s++){
  if(strip_in_block == IN_BLOCK_FULL || strip_in_block == IN_BLOCK_BEGIN){
   int clear_comments = (strip_comments == STRIP_ALL);
   if(*s == '*' && s[1] == '/'){
    strip_in_block = IN_BLOCK_END;
    if(clear_comments)
     *s++ = ' ';
   }
   if(clear_comments)
    *s = ' ';
  }else if(*s == '"' || *s == '\''){
   char *end = str_quotefin2(s + 1, *s);
   if(!end){
    do{ if(WQUOTE == 0 || WQUOTE & wmode){ loc_tok.line--; warn_at(((void *)0), "no terminating quote to string"); loc_tok.line++; } }while(0);
    s = strchr(s, '\0') - 1;
   }else{
    s = end;
   }
  }else if(*s == '/'){
   if(cpp_std >= STD_C99 && s[1] == '/'){
    switch(strip_comments){
     case STRIP_EXCEPT_DIRECTIVE:
      if(is_directive)
       goto strip_1line;
     case STRIP_NONE:
     {
      unsigned int pos_slash = s - line;
      unsigned int len = strlen(line);
      line = urealloc1(line, len + 2 + 1);
      s = line + pos_slash;
      s[1] = '*';
      strcpy(line + len, "*/");
      break;
     }
strip_1line:
     case STRIP_ALL:
      *s = '\0';
      break;
    }
    break;
   }else if(s[1] == '*'){
    strip_in_block = IN_BLOCK_BEGIN;
    switch(strip_comments){
     case STRIP_EXCEPT_DIRECTIVE:
      if(!is_directive)
       break;
     case STRIP_ALL:
      *s = s[1] = ' ';
      s++;
     case STRIP_NONE:
      break;
    }
   }
  }
 }
 return line;
}

variable_types:
s
char *

variable_types:
end
char *

variable_types:
len
unsigned int


decompiled_code:
void *__fastcall filter_macros(void *ptr)
{
_BYTE *v1; // rbx

if ( *(_BYTE *)ptr == 35 )
{
v1 = ptr;
LABEL_8:
parse_directive(v1 + 1);
free(ptr);
return 0LL;
}
v1 = (_BYTE *)str_spc_skip();
if ( *v1 == 35 )
{
if ( *(_BYTE *)ptr != 35 && (wmode & 1) != 0 )
{
--loc_tok;
warn_at(0LL, "'#' for directive isn't in the first column");
++loc_tok;
}
goto LABEL_8;
}
if ( !(unsigned int)parse_should_noop() )
return (void *)eval_expand_macros(ptr);
*(_BYTE *)ptr = 0;
return ptr;
}

canonical_decompiled_code:
void *__fastcall func3(void *ptr)
{
_BYTE *v1; // rbx

if ( *(_BYTE *)ptr == 35 )
{
v1 = ptr;
LABEL_8:
parse_directive(v1 + 1);
free(ptr);
return 0LL;
}
v1 = (_BYTE *)str_spc_skip();
if ( *v1 == 35 )
{
if ( *(_BYTE *)ptr != 35 && (wmode & 1) != 0 )
{
--loc_tok;
warn_at(0LL, "'#' for directive isn't in the first column");
++loc_tok;
}
goto LABEL_8;
}
if ( !(unsigned int)parse_should_noop() )
return (void *)eval_expand_macros(ptr);
*(_BYTE *)ptr = 0;
return ptr;
}

original_code:
static char *filter_macros(char *line)
{
 char *hash = line;
 if(*hash == '#' || *(hash = str_spc_skip(hash)) == '#'){
  if(*line != '#')
   do{ if(WTRADITIONAL == 0 || WTRADITIONAL & wmode){ loc_tok.line--; warn_at(((void *)0), "'#' for directive isn't in the first column"); loc_tok.line++; } }while(0);
  parse_directive(hash + 1);
  free(line);
  return ((void *)0);
 }else{
  if(parse_should_noop())
   *line = '\0';
  else
   line = eval_expand_macros(line);
  return line;
 }
}

variable_types:
hash
char *


decompiled_code:
void __fastcall preproc_emit_line_info(unsigned int a1, const char *a2, int a3)
{
unsigned int v3; // eax
unsigned int v4; // eax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a3;
if ( !no_output && option_line_info )
{
printf("# %d \"%s\"", a1, a2);
while ( v5[0] )
{
v3 = extractbottombit(v5);
v4 = log2i(v3);
printf(" %d", v4);
}
putchar(10);
}
}

canonical_decompiled_code:
void __fastcall func5(unsigned int a1, const char *a2, int a3)
{
unsigned int v3; // eax
unsigned int v4; // eax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = a3;
if ( !no_output && option_line_info )
{
printf("# %d \"%s\"", a1, a2);
while ( v5[0] )
{
v3 = extractbottombit(v5);
v4 = log2i(v3);
printf(" %d", v4);
}
putchar(10);
}
}

original_code:
void preproc_emit_line_info(int lineno, const char *fname, enum lineinfo lineinfo)
{
 unsigned lineinfobits = lineinfo;
 if(no_output || !option_line_info)
  return;
 printf("# %d \"%s\"", lineno, fname);
 while(lineinfobits){
  unsigned bit = extractbottombit(&lineinfobits);
  int n = log2i(bit);
  printf(" %d", n);
 }
 putchar('\n');
}

canonical_original_code:
void preproc_emit_line_info(int lineno, char *fname, enum lineinfo lineinfo)
{
 unsigned int lineinfobits = lineinfo;
 if(no_output || !option_line_info)
  return;
 printf("# %d \"%s\"", lineno, fname);
 while(lineinfobits){
  unsigned int bit = extractbottombit(&lineinfobits);
  int n = log2i(bit);
  printf(" %d", n);
 }
 putchar('\n');
}

variable_types: lineno int

variable_types:
fname
char *

variable_types: enum lineinfo { LINEINFO_START_OF_FILE=expr, LINEINFO_RETURN_TO_FILE=expr, LINEINFO_SYSHEADER=expr }

variable_types:
lineinfobits
unsigned int

variable_types:
bit
unsigned int

variable_types: n int


decompiled_code:
void __fastcall preproc_emit_line_info_top(int a1)
{
int v1; // edx

v1 = a1;
if ( HIDWORD(file_stack[3 * file_stack_idx + 2]) )
v1 = a1 | 8;
preproc_emit_line_info(file_stack[3 * file_stack_idx + 2], (const char *)file_stack[3 * file_stack_idx + 1], v1);
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
int v1; // edx

v1 = a1;
if ( HIDWORD(file_stack[3 * file_stack_idx + 2]) )
v1 = a1 | 8;
func5(file_stack[3 * file_stack_idx + 2], (const char *)file_stack[3 * file_stack_idx + 1], v1);
}

original_code:
static void preproc_emit_line_info_top(enum lineinfo lineinfo)
{
 preproc_emit_line_info(
   file_stack[file_stack_idx].line_no,
   file_stack[file_stack_idx].fname,
   lineinfo | (file_stack[file_stack_idx].is_sysh ? LINEINFO_SYSHEADER : 0));
}

user_defined_types: enum lineinfo { LINEINFO_START_OF_FILE=expr, LINEINFO_RETURN_TO_FILE=expr, LINEINFO_SYSHEADER=expr }


decompiled_code:
void preproc_pop()
{
__int64 *v0; // rax
__int64 v1; // rdi

if ( file_stack_idx )
{
free((void *)file_stack[3 * file_stack_idx + 1]);
v0 = &file_stack[3 * --file_stack_idx];
v1 = v0[1];
loc_tok = *((_DWORD *)v0 + 4);
set_current_fname(v1);
preproc_emit_line_info_top(4);
}
else
{
ice("preproc.c", 119LL, "preproc_pop", "file stack idx = 0 on pop()");
read_line();
}
}

canonical_decompiled_code:
void func7()
{
__int64 *v0; // rax
__int64 v1; // rdi

if ( file_stack_idx )
{
free((void *)file_stack[3 * file_stack_idx + 1]);
v0 = &file_stack[3 * --file_stack_idx];
v1 = v0[1];
loc_tok = *((_DWORD *)v0 + 4);
set_current_fname(v1);
func6(4);
}
else
{
ice("preproc.c", 119LL, "preproc_pop", "file stack idx = 0 on pop()");
func8();
}
}

original_code:
static void preproc_pop(void)
{
 if(!file_stack_idx)
  ice("preproc.c", 119, __func__, "file stack idx = 0 on pop()");
 free(file_stack[file_stack_idx].fname);
 file_stack_idx--;
 loc_tok.line = file_stack[file_stack_idx].line_no;
 set_current_fname(file_stack[file_stack_idx].fname);
 preproc_emit_line_info_top(LINEINFO_RETURN_TO_FILE);
}

canonical_original_code:
static void preproc_pop()
{
 if(!file_stack_idx)
  ice("preproc.c", 119, __func__, "file stack idx = 0 on pop()");
 free(file_stack[file_stack_idx].fname);
 file_stack_idx--;
 loc_tok.line = file_stack[file_stack_idx].line_no;
 set_current_fname(file_stack[file_stack_idx].fname);
 preproc_emit_line_info_top(LINEINFO_RETURN_TO_FILE);
}


decompiled_code:
__int64 __fastcall splice_lines(_DWORD *a1)
{
char *v1; // r12
char *v2; // rax
char *v3; // rbx
char *v4; // r13
char *v5; // rax
const char *v6; // rax
char *v7; // r13
signed __int64 v8; // rbx
size_t v9; // rax
__int64 result; // rax

if ( n_nls_3 )
{
--n_nls_3;
result = ustrdup(&unk_10BB);
}
else
{
v1 = (char *)read_line();
if ( v1 )
{
if ( option_trigraphs )
v1 = expand_trigraphs(v1);
v2 = strrchr(v1, 92);
v3 = v2;
if ( !v2 )
return (__int64)v1;
v4 = v2 + 1;
v5 = (char *)str_spc_skip(v2 + 1);
if ( *v5 )
return (__int64)v1;
if ( v4 < v5 && (*((_BYTE *)&wmode + 1) & 0x40) != 0 )
{
--loc_tok;
warn_at(0LL, "backslash and newline separated by space");
++loc_tok;
}
v6 = (const char *)splice_lines(a1);
*v3 = 0;
v7 = (char *)v6;
if ( v6 )
{
v8 = v3 - v1;
v9 = strlen(v6);
++n_nls_3;
v1 = (char *)urealloc1(v1, v8 + v9 + 1);
strcpy(&v1[v8], v7);
free(v7);
return (__int64)v1;
}
if ( (*((_BYTE *)&wmode + 1) & 4) != 0 )
{
--loc_tok;
warn_at(0LL, "backslash-escape at eof");
++loc_tok;
}
}
*a1 = 1;
result = (__int64)v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
char *v1; // r12
char *v2; // rax
char *v3; // rbx
char *v4; // r13
char *v5; // rax
const char *v6; // rax
char *v7; // r13
signed __int64 v8; // rbx
size_t v9; // rax
__int64 result; // rax

if ( n_nls_3 )
{
--n_nls_3;
result = ustrdup(&unk_10BB);
}
else
{
v1 = (char *)func8();
if ( v1 )
{
if ( option_trigraphs )
v1 = func1(v1);
v2 = strrchr(v1, 92);
v3 = v2;
if ( !v2 )
return (__int64)v1;
v4 = v2 + 1;
v5 = (char *)str_spc_skip(v2 + 1);
if ( *v5 )
return (__int64)v1;
if ( v4 < v5 && (*((_BYTE *)&wmode + 1) & 0x40) != 0 )
{
--loc_tok;
warn_at(0LL, "backslash and newline separated by space");
++loc_tok;
}
v6 = (const char *)func9(a1);
*v3 = 0;
v7 = (char *)v6;
if ( v6 )
{
v8 = v3 - v1;
v9 = strlen(v6);
++n_nls_3;
v1 = (char *)urealloc1(v1, v8 + v9 + 1);
strcpy(&v1[v8], v7);
free(v7);
return (__int64)v1;
}
if ( (*((_BYTE *)&wmode + 1) & 4) != 0 )
{
--loc_tok;
warn_at(0LL, "backslash-escape at eof");
++loc_tok;
}
}
*a1 = 1;
result = (__int64)v1;
}
return result;
}

original_code:
static char *splice_lines(int *peof)
{
 static int n_nls;
 char *line;
 char *last_backslash;
 int splice = 0;
 if(n_nls){
  n_nls--;
  return ustrdup("");
 }
 line = read_line();
 if(!line){
  *peof = 1;
  return ((void *)0);
 }
 if(option_trigraphs)
  line = expand_trigraphs(line);
 last_backslash = strrchr(line, '\\');
 if(last_backslash){
  char *i;
  i = str_spc_skip(last_backslash + 1);
  if(*i == '\0'){
   splice = 1;
   if(i > last_backslash + 1){
    do{ if(WBACKSLASH_SPACE_NEWLINE == 0 || WBACKSLASH_SPACE_NEWLINE & wmode){ loc_tok.line--; warn_at(((void *)0), "backslash and newline separated by space"); loc_tok.line++; } }while(0);
   }
  }
 }
 if(splice){
  char *next = splice_lines(peof);
  *last_backslash = '\0';
  if(next){
   const size_t this_len = last_backslash - line;
   const size_t next_len = strlen(next);
   n_nls++;
   line = urealloc1(line, this_len + next_len + 1);
   strcpy(line + this_len, next);
   free(next);
  }else{
   do{ if(WFINALESCAPE == 0 || WFINALESCAPE & wmode){ loc_tok.line--; warn_at(((void *)0), "backslash-escape at eof"); loc_tok.line++; } }while(0);
   *peof = 1;
  }
 }
 return line;
}

canonical_original_code:
static char *splice_lines(int *peof)
{
 static int n_nls;
 char *line;
 char *last_backslash;
 int splice = 0;
 if(n_nls){
  n_nls--;
  return ustrdup("");
 }
 line = read_line();
 if(!line){
  *peof = 1;
  return ((void *)0);
 }
 if(option_trigraphs)
  line = expand_trigraphs(line);
 last_backslash = strrchr(line, '\\');
 if(last_backslash){
  char *i;
  i = str_spc_skip(last_backslash + 1);
  if(*i == '\0'){
   splice = 1;
   if(i > last_backslash + 1){
    do{ if(WBACKSLASH_SPACE_NEWLINE == 0 || WBACKSLASH_SPACE_NEWLINE & wmode){ loc_tok.line--; warn_at(((void *)0), "backslash and newline separated by space"); loc_tok.line++; } }while(0);
   }
  }
 }
 if(splice){
  char *next = splice_lines(peof);
  *last_backslash = '\0';
  if(next){
   unsigned long this_len = last_backslash - line;
   unsigned long next_len = strlen(next);
   n_nls++;
   line = urealloc1(line, this_len + next_len + 1);
   strcpy(line + this_len, next);
   free(next);
  }else{
   do{ if(WFINALESCAPE == 0 || WFINALESCAPE & wmode){ loc_tok.line--; warn_at(((void *)0), "backslash-escape at eof"); loc_tok.line++; } }while(0);
   *peof = 1;
  }
 }
 return line;
}

variable_types:
peof
int *

variable_types: splice int

variable_types:
i
char *

variable_types:
next
char *


decompiled_code:
_BOOL8 preproc_in_include()
{
return file_stack_idx > 0;
}

canonical_decompiled_code:
_BOOL8 func10()
{
return file_stack_idx > 0;
}

original_code:
int preproc_in_include(void)
{
 return file_stack_idx > 0;
}

canonical_original_code:
int preproc_in_include()
{
 return file_stack_idx > 0;
}


preprocess

decompiled_code:
__int64 preprocess()
{
char *v0; // rax
char *v1; // rbp
__int64 v2; // rax
char *v3; // rbp
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
preproc_push((__int64)stdin, current_fname, 0);
LABEL_4:
while ( !v5[0] )
{
v2 = splice_lines(v5);
v3 = (char *)v2;
if ( !v2 )
break;
debug_push_line(v2);
if ( option_digraphs )
v3 = expand_digraphs(v3);
v0 = strip_comment(v3);
v1 = v0;
if ( (unsigned int)strip_in_block <= 2 )
{
v1 = (char *)filter_macros(v0);
debug_pop_line();
if ( !v1 )
goto LABEL_4;
}
else
{
debug_pop_line();
if ( !v1 )
goto LABEL_4;
}
if ( !no_output )
puts(v1);
free(v1);
}
if ( (strip_in_block & 0xFFFFFFFD) == 1 )
{
--loc_tok;
die_at(0LL, "no terminating block comment");
JUMPOUT(0x9DFLL);
}
return parse_end_validate();
}

canonical_decompiled_code:
__int64 func12()
{
char *v0; // rax
char *v1; // rbp
__int64 v2; // rax
char *v3; // rbp
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = 0;
func11((__int64)stdin, current_fname, 0);
LABEL_4:
while ( !v5[0] )
{
v2 = func9(v5);
v3 = (char *)v2;
if ( !v2 )
break;
debug_push_line(v2);
if ( option_digraphs )
v3 = func0(v3);
v0 = func2(v3);
v1 = v0;
if ( (unsigned int)strip_in_block <= 2 )
{
v1 = (char *)func3(v0);
debug_pop_line();
if ( !v1 )
goto LABEL_4;
}
else
{
debug_pop_line();
if ( !v1 )
goto LABEL_4;
}
if ( !no_output )
puts(v1);
free(v1);
}
if ( (strip_in_block & 0xFFFFFFFD) == 1 )
{
--loc_tok;
die_at(0LL, "no terminating block comment");
JUMPOUT(0x9DFLL);
}
return parse_end_validate();
}

original_code:
void preprocess(void)
{
 char *line;
 int eof = 0;
 preproc_push(stdin, current_fname, 0);
 while(!eof && (line = splice_lines(&eof))){
  debug_push_line(line);
  if(option_digraphs)
   line = expand_digraphs(line);
  line = strip_comment(line);
  switch(strip_in_block){
   case NOT_IN_BLOCK:
   case IN_BLOCK_BEGIN:
   case IN_BLOCK_END:
    line = filter_macros(line);
   case IN_BLOCK_FULL:
    break;
  }
  debug_pop_line();
  if(line){
   if(!no_output)
    puts(line);
   free(line);
  }
 }
 switch(strip_in_block){
  case NOT_IN_BLOCK:
  case IN_BLOCK_END:
   break;
  case IN_BLOCK_BEGIN:
  case IN_BLOCK_FULL:
   do{ if(0 == 0 || 0 & wmode){ loc_tok.line--; die_at(((void *)0), "no terminating block comment"); loc_tok.line++; } }while(0);
 }
 parse_end_validate();
}

canonical_original_code:
void preprocess()
{
 char *line;
 int eof = 0;
 preproc_push(stdin, current_fname, 0);
 while(!eof && (line = splice_lines(&eof))){
  debug_push_line(line);
  if(option_digraphs)
   line = expand_digraphs(line);
  line = strip_comment(line);
  switch(strip_in_block){
   case NOT_IN_BLOCK:
   case IN_BLOCK_BEGIN:
   case IN_BLOCK_END:
    line = filter_macros(line);
   case IN_BLOCK_FULL:
    break;
  }
  debug_pop_line();
  if(line){
   if(!no_output)
    puts(line);
   free(line);
  }
 }
 switch(strip_in_block){
  case NOT_IN_BLOCK:
  case IN_BLOCK_END:
   break;
  case IN_BLOCK_BEGIN:
  case IN_BLOCK_FULL:
   do{ if(0 == 0 || 0 & wmode){ loc_tok.line--; die_at(((void *)0), "no terminating block comment"); loc_tok.line++; } }while(0);
 }
 parse_end_validate();
}

variable_types:
line
char *

variable_types: eof int


umalloc

decompiled_code:
void *__fastcall umalloc(size_t size)
{
void *result; // rax

result = calloc(1uLL, size);
if ( !result )
{
ice("alloc.c", 20LL, "umalloc", "calloc %ld bytes:", size);
result = (void *)ucalloc();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t size)
{
void *result; // rax

result = calloc(1uLL, size);
if ( !result )
{
ice("alloc.c", 20LL, "umalloc", "calloc %ld bytes:", size);
result = (void *)func1();
}
return result;
}

original_code:
void *umalloc(size_t l)
{
 void *p = calloc(1, l);
 if(!p)
  ice("alloc.c", 20, __func__, "calloc %ld bytes:", (long)l);
 return p;
}

canonical_original_code:
void *umalloc(unsigned long l)
{
 void *p = calloc(1, l);
 if(!p)
  ice("alloc.c", 20, __func__, "calloc %ld bytes:", (long)l);
 return p;
}

variable_types:
l
unsigned long

variable_types:
p
void *


ucalloc

decompiled_code:
void *__fastcall ucalloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
{
ice("alloc.c", 28LL, "ucalloc", "calloc(%ld, %ld):", a1, a2);
result = (void *)urealloc();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
{
ice("alloc.c", 28LL, "ucalloc", "calloc(%ld, %ld):", a1, a2);
result = (void *)func2();
}
return result;
}

original_code:
void *ucalloc(size_t n, size_t sz)
{
 void *p = calloc(n, sz);
 if(!p)
  ice("alloc.c", 28, __func__, "calloc(%ld, %ld):", n, sz);
 return p;
}

canonical_original_code:
void *ucalloc(unsigned long n, unsigned long sz)
{
 void *p = calloc(n, sz);
 if(!p)
  ice("alloc.c", 28, __func__, "calloc(%ld, %ld):", n, sz);
 return p;
}

variable_types:
n
unsigned long

variable_types:
sz
unsigned long


urealloc

decompiled_code:
char *__fastcall urealloc(void *a1, size_t a2, __int64 a3)
{
size_t v4; // rbx
char *result; // rax
char *v6; // r12

v4 = a2 - a3;
result = (char *)realloc(a1, a2);
if ( result )
{
v6 = result;
if ( v4 )
{
memset(&result[a3], 0, v4);
result = v6;
}
}
else
{
ice("alloc.c", 38LL, "urealloc", "realloc %p by %ld bytes:", a1, v4);
result = (char *)urealloc1();
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(void *a1, size_t a2, __int64 a3)
{
size_t v4; // rbx
char *result; // rax
char *v6; // r12

v4 = a2 - a3;
result = (char *)realloc(a1, a2);
if ( result )
{
v6 = result;
if ( v4 )
{
memset(&result[a3], 0, v4);
result = v6;
}
}
else
{
ice("alloc.c", 38LL, "urealloc", "realloc %p by %ld bytes:", a1, v4);
result = (char *)func3();
}
return result;
}

original_code:
void *urealloc(void *p, size_t new, size_t old)
{
 void *r = realloc(p, new);
 size_t diff = new - old;
 if(!r)
  ice("alloc.c", 38, __func__, "realloc %p by %ld bytes:", p, (long)diff);
 if(diff > 0)
  memset((char *)r + old, 0, diff);
 return r;
}

canonical_original_code:
void *urealloc(void *p, unsigned long new, unsigned long old)
{
 void *r = realloc(p, new);
 unsigned long diff = new - old;
 if(!r)
  ice("alloc.c", 38, __func__, "realloc %p by %ld bytes:", p, (long)diff);
 if(diff > 0)
  memset((char *)r + old, 0, diff);
 return r;
}

variable_types:
new
unsigned long

variable_types:
old
unsigned long

variable_types:
r
void *

variable_types:
diff
unsigned long


decompiled_code:
void *__fastcall urealloc1(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
ice("alloc.c", 51LL, "urealloc1", "realloc %p by %ld bytes:", a1, a2);
result = (void *)ustrdup("alloc.c");
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
ice("alloc.c", 51LL, "urealloc1", "realloc %p by %ld bytes:", a1, a2);
result = (void *)func4("alloc.c");
}
return result;
}

original_code:
void *urealloc1(void *p, size_t l)
{
 char *r = realloc(p, l);
 if(!r)
  ice("alloc.c", 51, __func__, "realloc %p by %ld bytes:", p, (long)l);
 return r;
}

canonical_original_code:
void *urealloc1(void *p, unsigned long l)
{
 char *r = realloc(p, l);
 if(!r)
  ice("alloc.c", 51, __func__, "realloc %p by %ld bytes:", p, (long)l);
 return r;
}

variable_types:
r
char *


ustrdup

decompiled_code:
char *__fastcall ustrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)umalloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *ustrdup(const char *s)
{
 char *r = umalloc(strlen(s) + 1);
 strcpy(r, s);
 return r;
}

canonical_original_code:
char *ustrdup(char *s)
{
 char *r = umalloc(strlen(s) + 1);
 strcpy(r, s);
 return r;
}

variable_types:
s
char *


decompiled_code:
char *__fastcall ustrdup_or_null(char *src)
{
char *result; // rax

if ( src )
result = ustrdup(src);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
char *result; // rax

if ( src )
result = func4(src);
else
result = 0LL;
return result;
}

original_code:
char *ustrdup_or_null(const char *s)
{
 return s ? ustrdup(s) : ((void *)0);
}

canonical_original_code:
char *ustrdup_or_null(char *s)
{
 return s ? ustrdup(s) : ((void *)0);
}


decompiled_code:
char *__fastcall ustrdup2(char *src, unsigned __int64 a2)
{
int v2; // ebx
char *v3; // rax

v2 = a2 - (_DWORD)src;
if ( a2 < (unsigned __int64)src )
_assert_fail("b >= a", "alloc.c", 0x47u, "ustrdup2");
v3 = (char *)umalloc(v2 + 1);
return strncpy(v3, src, v2);
}

canonical_decompiled_code:
char *__fastcall func6(char *src, unsigned __int64 a2)
{
int v2; // ebx
char *v3; // rax

v2 = a2 - (_DWORD)src;
if ( a2 < (unsigned __int64)src )
_assert_fail("b >= a", "alloc.c", 0x47u, "ustrdup2");
v3 = (char *)func0(v2 + 1);
return strncpy(v3, src, v2);
}

original_code:
char *ustrdup2(const char *a, const char *b)
{
 int len = b - a;
 char *ret;
 ((b >= a) ? (void) (0) : __assert_fail ("b >= a", "alloc.c", 71, __extension__ __PRETTY_FUNCTION__));
 ret = umalloc(len + 1);
 strncpy(ret, a, len);
 return ret;
}

canonical_original_code:
char *ustrdup2(char *a, char *b)
{
 int len = b - a;
 char *ret;
 ((b >= a) ? (void) (0) : __assert_fail ("b >= a", "alloc.c", 71, __extension__ __PRETTY_FUNCTION__));
 ret = umalloc(len + 1);
 strncpy(ret, a, len);
 return ret;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types: len int

variable_types:
ret
char *


ustrvprintf

decompiled_code:
char *__fastcall ustrvprintf(char *format, const __m128i *a2)
{
char *v2; // rbp
int v3; // ebx
__int64 v4; // rdx
__int64 v5; // rax
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h]

v2 = 0LL;
v3 = 8;
do
{
v4 = v3;
v3 *= 2;
v2 = urealloc(v2, v3, v4);
v5 = a2[1].m128i_i64[0];
arg = _mm_loadu_si128(a2);
v8 = v5;
}
while ( v3 <= vsnprintf(v2, v3, format, &arg) );
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(char *format, const __m128i *a2)
{
char *v2; // rbp
int v3; // ebx
__int64 v4; // rdx
__int64 v5; // rax
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v8; // [rsp+18h] [rbp-30h]

v2 = 0LL;
v3 = 8;
do
{
v4 = v3;
v3 *= 2;
v2 = func2(v2, v3, v4);
v5 = a2[1].m128i_i64[0];
arg = _mm_loadu_si128(a2);
v8 = v5;
}
while ( v3 <= vsnprintf(v2, v3, format, &arg) );
return v2;
}

original_code:
char *ustrvprintf(const char *fmt, va_list l)
{
 char *buf = ((void *)0);
 int len = 8, ret;
 do{
  va_list lcp;
  int old = len;
  len *= 2;
  buf = urealloc(buf, len, old);
  __builtin_va_copy(lcp,l);
  ret = vsnprintf(buf, len, fmt, lcp);
  __builtin_va_end(lcp);
 }while(ret >= len);
 return buf;
}

canonical_original_code:
char *ustrvprintf(char *fmt, __builtin_va_list l)
{
 char *buf = ((void *)0);
 int len = 8; int ret;
 do{
  __builtin_va_list lcp;
  int old = len;
  len *= 2;
  buf = urealloc(buf, len, old);
  __builtin_va_copy(lcp,l);
  ret = vsnprintf(buf, len, fmt, lcp);
  __builtin_va_end(lcp);
 }while(ret >= len);
 return buf;
}

variable_types:
fmt
char *

variable_types:
buf
char *

variable_types: ret int

variable_types: old int


ustrprintf

decompiled_code:
char *ustrprintf(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return ustrvprintf(a1, (const __m128i *)va);
}

canonical_decompiled_code:
char *func8(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func7(a1, (const __m128i *)va);
}

original_code:
char *ustrprintf(const char *fmt, ...)
{
 va_list l;
 char *r;
 __builtin_va_start(l,fmt);
 r = ustrvprintf(fmt, l);
 __builtin_va_end(l);
 return r;
}

canonical_original_code:
char *ustrprintf(char *fmt, ...)
{
 __builtin_va_list l;
 char *r;
 __builtin_va_start(l,fmt);
 r = ustrvprintf(fmt, l);
 __builtin_va_end(l);
 return r;
}


decompiled_code:
__int64 __fastcall snapshot_take_1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // r8
__int64 i; // rax

if ( !a1 )
return 0LL;
v1 = umalloc(4 * a1);
v2 = macros;
v3 = v1;
for ( i = 0LL; i != a1; ++i )
*(_DWORD *)(v3 + 4 * i) = *(_DWORD *)(*(_QWORD *)(v2 + 8 * i) + 68LL);
return v3;
}

original_code:
static int *snapshot_take_1(size_t n)
{
 int *p;
 size_t i;
 if(!n)
  return ((void *)0);
 p = umalloc(n * sizeof *p);
 for(i = 0; i < n; i++)
  p[i] = macros[i]->use_cnt;
 return p;
}

canonical_original_code:
static int *snapshot_take_1(unsigned long n)
{
 int *p;
 unsigned long i;
 if(!n)
  return ((void *)0);
 p = umalloc(n * sizeof *p);
 for(i = 0; i < n; i++)
  p[i] = macros[i]->use_cnt;
 return p;
}

variable_types:
p
int *

variable_types:
i
unsigned long

return_type: int *


original_code:
void snapshot_restore_used(snapshot *snap)
{
 size_t i;
 for(i = 0; i < snap->n; i++)
  macros[i]->use_cnt = snap->pre[i];
}

canonical_original_code:
void snapshot_restore_used(struct snapshot *snap)
{
 unsigned long i;
 for(i = 0; i < snap->n; i++)
  macros[i]->use_cnt = snap->pre[i];
}

variable_types: struct snapshot { int *pre; unsigned long n; } *


decompiled_code:
void __fastcall snapshot_free(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void snapshot_free(snapshot *snap)
{
 free(snap->pre);
 free(snap->post);
 free(snap);
}

canonical_original_code:
void snapshot_free(struct snapshot *snap)
{
 free(snap->pre);
 free(snap->post);
 free(snap);
}

user_defined_types: struct snapshot { int *pre; unsigned long n; }


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

result = snapshot_take_1(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = func0(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void snapshot_take_post(snapshot *snap)
{
 snap->post = snapshot_take_1(snap->n);
}

canonical_original_code:
void snapshot_take_post(struct snapshot *snap)
{
 snap->post = snapshot_take_1(snap->n);
}


decompiled_code:
void __fastcall cstring_asciify(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
unsigned __int64 v3; // rax

v1 = umalloc(*(_QWORD *)(a1 + 8) + 1LL);
if ( *(_DWORD *)(a1 + 16) != 2 )
_assert_fail("cstr->type == CSTRING_WIDE", "str.c", 0x4Au, "cstring_asciify");
v2 = v1;
v3 = 0LL;
if ( *(_QWORD *)(a1 + 8) != -1LL )
{
do
{
*(_BYTE *)(v2 + v3) = *(_DWORD *)(*(_QWORD *)a1 + 4 * v3);
++v3;
}
while ( *(_QWORD *)(a1 + 8) + 1LL > v3 );
}
free(*(void **)a1);
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 16) = 1;
}

original_code:
static void cstring_asciify(struct cstring *cstr)
{
 char *ascii = umalloc(cstr->count + 1);
 size_t i;
 ((cstr->type == CSTRING_WIDE) ? (void) (0) : __assert_fail ("cstr->type == CSTRING_WIDE", "str.c", 74, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < cstr->count + 1; i++)
  ascii[i] = cstr->bits.wides[i];
 free(cstr->bits.wides);
 cstr->bits.ascii = ascii;
 cstr->type = CSTRING_ASCII;
}

canonical_original_code:
static void cstring_asciify(struct cstring *cstr)
{
 char *ascii = umalloc(cstr->count + 1);
 unsigned long i;
 ((cstr->type == CSTRING_WIDE) ? (void) (0) : __assert_fail ("cstr->type == CSTRING_WIDE", "str.c", 74, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < cstr->count + 1; i++)
  ascii[i] = cstr->bits.wides[i];
 free(cstr->bits.wides);
 cstr->bits.ascii = ascii;
 cstr->type = CSTRING_ASCII;
}

variable_types: struct cstring { union { char *ascii; int *wides; } bits; unsigned long count; enum cstring_type { CSTRING_RAW=0, CSTRING_ASCII=1, CSTRING_WIDE=2 } type; } *

variable_types:
ascii
char *

user_defined_types: struct cstring { union { char *ascii; int *wides; } bits; unsigned long count; enum cstring_type type; }


decompiled_code:
void __fastcall cstring_widen(__int64 *a1)
{
__int64 v2; // rax
char *v3; // rcx
__int64 v4; // rbx
char *v5; // rdi
__int64 v6; // rax
__int64 v7; // rdx

v2 = umalloc(4 * a1[1] + 4);
if ( *((_DWORD *)a1 + 4) > 1u )
_assert_fail("cstr->type == CSTRING_RAW || cstr->type == CSTRING_ASCII", "str.c", 0x3Bu, "cstring_widen");
v3 = (char *)a1[1];
v4 = v2;
v5 = (char *)*a1;
v6 = 0LL;
if ( v3 != (char *)-1LL )
{
do
{
*(_DWORD *)(v4 + 4 * v6) = v5[v6];
v7 = v6++;
}
while ( v3 != (char *)v7 );
}
free(v5);
*a1 = v4;
*((_DWORD *)a1 + 4) = 2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 *a1)
{
__int64 v2; // rax
char *v3; // rcx
__int64 v4; // rbx
char *v5; // rdi
__int64 v6; // rax
__int64 v7; // rdx

v2 = umalloc(4 * a1[1] + 4);
if ( *((_DWORD *)a1 + 4) > 1u )
_assert_fail("cstr->type == CSTRING_RAW || cstr->type == CSTRING_ASCII", "str.c", 0x3Bu, "cstring_widen");
v3 = (char *)a1[1];
v4 = v2;
v5 = (char *)*a1;
v6 = 0LL;
if ( v3 != (char *)-1LL )
{
do
{
*(_DWORD *)(v4 + 4 * v6) = v5[v6];
v7 = v6++;
}
while ( v3 != (char *)v7 );
}
free(v5);
*a1 = v4;
*((_DWORD *)a1 + 4) = 2;
}

original_code:
static void cstring_widen(struct cstring *cstr)
{
 int *wides = umalloc(sizeof(*wides) * (cstr->count + 1));
 size_t i;
 ((cstr->type == CSTRING_RAW || cstr->type == CSTRING_ASCII) ? (void) (0) : __assert_fail ("cstr->type == CSTRING_RAW || cstr->type == CSTRING_ASCII", "str.c", 59, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < cstr->count + 1; i++)
  wides[i] = cstr->bits.ascii[i];
 free(cstr->bits.ascii);
 cstr->bits.wides = wides;
 cstr->type = CSTRING_WIDE;
}

canonical_original_code:
static void cstring_widen(struct cstring *cstr)
{
 int *wides = umalloc(sizeof(*wides) * (cstr->count + 1));
 unsigned long i;
 ((cstr->type == CSTRING_RAW || cstr->type == CSTRING_ASCII) ? (void) (0) : __assert_fail ("cstr->type == CSTRING_RAW || cstr->type == CSTRING_ASCII", "str.c", 59, __extension__ __PRETTY_FUNCTION__));
 for(i = 0; i < cstr->count + 1; i++)
  wides[i] = cstr->bits.ascii[i];
 free(cstr->bits.ascii);
 cstr->bits.wides = wides;
 cstr->type = CSTRING_WIDE;
}

variable_types:
wides
int *

user_defined_types: enum cstring_type { CSTRING_RAW=0, CSTRING_ASCII=1, CSTRING_WIDE=2 }


decompiled_code:
__int64 __fastcall cstring_char_at(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *a1;
if ( *((_DWORD *)a1 + 4) == 2 )
result = *(unsigned int *)(v2 + 4 * a2);
else
result = (unsigned int)*(char *)(v2 + a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *a1;
if ( *((_DWORD *)a1 + 4) == 2 )
result = *(unsigned int *)(v2 + 4 * a2);
else
result = (unsigned int)*(char *)(v2 + a2);
return result;
}

original_code:
int cstring_char_at(const struct cstring *cstr, size_t i)
{
 if(cstr->type == CSTRING_WIDE)
  return cstr->bits.wides[i];
 else
  return cstr->bits.ascii[i];
}

canonical_original_code:
int cstring_char_at(struct cstring *cstr, unsigned long i)
{
 if(cstr->type == CSTRING_WIDE)
  return cstr->bits.wides[i];
 else
  return cstr->bits.ascii[i];
}


original_code:
void cstring_escape(
  struct cstring *cstr, int is_wide,
  void handle_escape_warn_err(int w, int e, int escape_offset, void *),
  void *ctx)
{
 struct cstring tmpout = { 0 };
 size_t i, iout;
 ((cstr->type == CSTRING_RAW) ? (void) (0) : __assert_fail ("cstr->type == CSTRING_RAW", "str.c", 92, __extension__ __PRETTY_FUNCTION__));
 if(is_wide){
  tmpout.bits.wides = umalloc((cstr->count + 1) * sizeof(tmpout.bits.wides[0]));
  tmpout.type = CSTRING_WIDE;
 }else{
  tmpout.bits.ascii = umalloc(cstr->count + 1);
  tmpout.type = CSTRING_ASCII;
 }
 for(i = iout = 0; i < cstr->count; i++){
  unsigned add;
  if(cstr->bits.ascii[i] == '\\'){
   int warn, err;
   const int escape_loc = i + 1;
   char *end;
   warn = err = 0;
   add = escape_char_1(&cstr->bits.ascii[i + 1], &end, is_wide, &warn, &err);
   do if(!(end)) ice("str.c", 114, __func__, "bad parse?"); while(0);
   i = (end - cstr->bits.ascii) - 1;
   handle_escape_warn_err(warn, err, escape_loc, ctx);
  }else{
   add = cstr->bits.ascii[i];
  }
  cstring_char_set(&tmpout, iout++, add);
  ((iout <= cstr->count) ? (void) (0) : __assert_fail ("iout <= cstr->count", "str.c", 125, __extension__ __PRETTY_FUNCTION__));
 }
 free(cstr->bits.ascii);
 if(is_wide)
  cstr->bits.wides = tmpout.bits.wides;
 else
  cstr->bits.ascii = tmpout.bits.ascii;
 cstr->type = tmpout.type;
 cstr->count = iout;
}

canonical_original_code:
void cstring_escape(struct cstring *cstr, int is_wide, void handle_escape_warn_err(int w, int e, int escape_offset, void *), void *ctx)
{
 struct cstring tmpout = { 0 };
 unsigned long i; unsigned long iout;
 ((cstr->type == CSTRING_RAW) ? (void) (0) : __assert_fail ("cstr->type == CSTRING_RAW", "str.c", 92, __extension__ __PRETTY_FUNCTION__));
 if(is_wide){
  tmpout.bits.wides = umalloc((cstr->count + 1) * sizeof(tmpout.bits.wides[0]));
  tmpout.type = CSTRING_WIDE;
 }else{
  tmpout.bits.ascii = umalloc(cstr->count + 1);
  tmpout.type = CSTRING_ASCII;
 }
 for(i = iout = 0; i < cstr->count; i++){
  unsigned int add;
  if(cstr->bits.ascii[i] == '\\'){
   int warn; int err;
   int escape_loc = i + 1;
   char *end;
   warn = err = 0;
   add = escape_char_1(&cstr->bits.ascii[i + 1], &end, is_wide, &warn, &err);
   do if(!(end)) ice("str.c", 114, __func__, "bad parse?"); while(0);
   i = (end - cstr->bits.ascii) - 1;
   handle_escape_warn_err(warn, err, escape_loc, ctx);
  }else{
   add = cstr->bits.ascii[i];
  }
  cstring_char_set(&tmpout, iout++, add);
  ((iout <= cstr->count) ? (void) (0) : __assert_fail ("iout <= cstr->count", "str.c", 125, __extension__ __PRETTY_FUNCTION__));
 }
 free(cstr->bits.ascii);
 if(is_wide)
  cstr->bits.wides = tmpout.bits.wides;
 else
  cstr->bits.ascii = tmpout.bits.ascii;
 cstr->type = tmpout.type;
 cstr->count = iout;
}

variable_types: void (int w, int e, int escape_offset, void *)

variable_types:
ctx
void *

variable_types: struct cstring { union { char *ascii; int *wides; } bits; unsigned long count; enum cstring_type { CSTRING_RAW=0, CSTRING_ASCII=1, CSTRING_WIDE=2 } type; }

variable_types:
iout
unsigned long

variable_types:
add
unsigned int

variable_types: warn int

variable_types: err int

variable_types:
end
char *


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

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

original_code:
void cstring_deinit(struct cstring *cstr)
{
 if(cstr->type == CSTRING_WIDE)
  free(cstr->bits.wides);
 else
  free(cstr->bits.ascii);
}


decompiled_code:
void __fastcall cstring_free(void *ptr)
{
cstring_deinit((void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func6((void **)ptr);
free(ptr);
}

original_code:
void cstring_free(struct cstring *cstr)
{
 cstring_deinit(cstr);
 free(cstr);
}


decompiled_code:
__int64 __fastcall cstring_detach(_DWORD *a1)
{
bool v1; // zf
__int64 v2; // r12

v1 = a1[4] == 2;
v2 = *(_QWORD *)a1;
*(_QWORD *)a1 = 0LL;
if ( v1 )
_assert_fail("cstr->type != CSTRING_WIDE", "str.c", 0x90u, "cstring_detach");
cstring_free(a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
bool v1; // zf
__int64 v2; // r12

v1 = a1[4] == 2;
v2 = *(_QWORD *)a1;
*(_QWORD *)a1 = 0LL;
if ( v1 )
_assert_fail("cstr->type != CSTRING_WIDE", "str.c", 0x90u, "cstring_detach");
func7(a1);
return v2;
}

original_code:
char *cstring_detach(struct cstring *cstr)
{
 char *r = cstr->bits.ascii;
 cstr->bits.ascii = ((void *)0);
 ((cstr->type != CSTRING_WIDE) ? (void) (0) : __assert_fail ("cstr->type != CSTRING_WIDE", "str.c", 144, __extension__ __PRETTY_FUNCTION__));
 cstring_free(cstr);
 return r;
}

variable_types:
r
char *


decompiled_code:
__int64 __fastcall cstring_converting_detach(_DWORD *a1)
{
if ( a1[4] == 2 )
cstring_asciify((__int64)a1);
return cstring_detach(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
if ( a1[4] == 2 )
func0((__int64)a1);
return func8(a1);
}

original_code:
char *cstring_converting_detach(struct cstring *cstr)
{
 switch(cstr->type){
  case CSTRING_WIDE:
   cstring_asciify(cstr);
  default:
   return cstring_detach(cstr);
 }
}


decompiled_code:
int __fastcall cstring_eq(__int64 a1, __int64 a2, __int64 a3, __int64 a4, const void *a5, const void *a6)
{
unsigned int v6; // eax
size_t v7; // rdx

v6 = *(_DWORD *)(a1 + 16);
if ( v6 != *(_DWORD *)(a2 + 16) )
return 1;
v7 = *(_QWORD *)(a1 + 8);
if ( v7 != *(_QWORD *)(a2 + 8) )
return 1;
if ( v6 <= 1 )
{
a5 = *(const void **)a1;
a6 = *(const void **)a2;
}
else if ( v6 == 2 )
{
a5 = *(const void **)a1;
a6 = *(const void **)a2;
v7 *= 4LL;
}
else
{
v7 = 0LL;
}
return memcmp(a5, a6, v7);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2, __int64 a3, __int64 a4, const void *a5, const void *a6)
{
unsigned int v6; // eax
size_t v7; // rdx

v6 = *(_DWORD *)(a1 + 16);
if ( v6 != *(_DWORD *)(a2 + 16) )
return 1;
v7 = *(_QWORD *)(a1 + 8);
if ( v7 != *(_QWORD *)(a2 + 8) )
return 1;
if ( v6 <= 1 )
{
a5 = *(const void **)a1;
a6 = *(const void **)a2;
}
else if ( v6 == 2 )
{
a5 = *(const void **)a1;
a6 = *(const void **)a2;
v7 *= 4LL;
}
else
{
v7 = 0LL;
}
return memcmp(a5, a6, v7);
}

original_code:
int cstring_eq(const struct cstring *a, const struct cstring *b)
{
 enum { EQUAL, NOT_EQUAL };
 size_t sz;
 void *ap, *bp;
 if(a->type != b->type)
  return NOT_EQUAL;
 if(a->count != b->count)
  return NOT_EQUAL;
 switch(a->type){
  case CSTRING_WIDE:
   sz = sizeof(a->bits.wides[0]);
   ap = a->bits.wides;
   bp = b->bits.wides;
   break;
  case CSTRING_ASCII:
  case CSTRING_RAW:
   sz = 1;
   ap = a->bits.ascii;
   bp = b->bits.ascii;
   break;
 }
 return memcmp(ap, bp, sz * a->count);
}

canonical_original_code:
int cstring_eq(struct cstring *a, struct cstring *b)
{
 enum { EQUAL, NOT_EQUAL };
 unsigned long sz;
 void *ap; void *bp;
 if(a->type != b->type)
  return NOT_EQUAL;
 if(a->count != b->count)
  return NOT_EQUAL;
 switch(a->type){
  case CSTRING_WIDE:
   sz = sizeof(a->bits.wides[0]);
   ap = a->bits.wides;
   bp = b->bits.wides;
   break;
  case CSTRING_ASCII:
  case CSTRING_RAW:
   sz = 1;
   ap = a->bits.ascii;
   bp = b->bits.ascii;
   break;
 }
 return memcmp(ap, bp, sz * a->count);
}

variable_types:
b
struct cstring *

variable_types:
sz
unsigned long

variable_types:
ap
void *

variable_types:
bp
void *


decompiled_code:
__int64 __fastcall cstring_hash(__int64 *a1)
{
__int64 v1; // rdx
int v2; // eax
int v3; // er8
unsigned int v4; // er8
__int64 v5; // rcx

if ( !a1[1] )
return 5381LL;
v1 = 0LL;
do
{
v2 = cstring_char_at(a1, v1);
v4 = v2 + 32 * v3 + v3;
}
while ( v1 != v5 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
__int64 v1; // rdx
int v2; // eax
int v3; // er8
unsigned int v4; // er8
__int64 v5; // rcx

if ( !a1[1] )
return 5381LL;
v1 = 0LL;
do
{
v2 = func4(a1, v1);
v4 = v2 + 32 * v3 + v3;
}
while ( v1 != v5 );
return v4;
}

original_code:
unsigned cstring_hash(const struct cstring *cstr)
{
 unsigned hash = 5381;
 size_t i;
 for(i = 0; i < cstr->count; i++)
  hash = ((hash << 5) + hash) + cstring_char_at(cstr, i);
 return hash;
}

canonical_original_code:
unsigned int cstring_hash(struct cstring *cstr)
{
 unsigned int hash = 5381;
 unsigned long i;
 for(i = 0; i < cstr->count; i++)
  hash = ((hash << 5) + hash) + cstring_char_at(cstr, i);
 return hash;
}

variable_types:
hash
unsigned int

variable_types:
i
unsigned long

return_type: unsigned int


original_code:
void cstring_append(struct cstring *out, struct cstring *addend)
{
 const size_t orig_out_count = out->count;
 int last_is_nul;
 if(out->type == CSTRING_WIDE){
  last_is_nul = out->bits.wides[orig_out_count - 1] == '\0';
 }else{
  last_is_nul = out->bits.ascii[orig_out_count - 1] == '\0';
 }
 if(addend->type != out->type){
  ((addend->type == CSTRING_WIDE || out->type == CSTRING_WIDE) ? (void) (0) : __assert_fail ("addend->type == CSTRING_WIDE || out->type == CSTRING_WIDE", "str.c", 230, __extension__ __PRETTY_FUNCTION__));
  if(addend->type == CSTRING_WIDE)
   cstring_widen(out);
  else
   cstring_widen(addend);
 }
 out->count += addend->count;
 if(out->type == CSTRING_WIDE){
  out->bits.wides = urealloc1(
    out->bits.wides,
    sizeof(out->bits.wides[0]) * (out->count + 1));
  memcpy(
    out->bits.wides + out->count - addend->count - !!last_is_nul,
    addend->bits.wides,
    sizeof(addend->bits.wides[0]) * (addend->count + 1));
 }else{
  out->bits.ascii = urealloc1(out->bits.ascii, out->count + 1);
  memcpy(
    out->bits.ascii + out->count - addend->count - !!last_is_nul,
    addend->bits.ascii,
    addend->count + 1);
 }
 if(last_is_nul)
  out->count--;
}

canonical_original_code:
void cstring_append(struct cstring *out, struct cstring *addend)
{
 unsigned long orig_out_count = out->count;
 int last_is_nul;
 if(out->type == CSTRING_WIDE){
  last_is_nul = out->bits.wides[orig_out_count - 1] == '\0';
 }else{
  last_is_nul = out->bits.ascii[orig_out_count - 1] == '\0';
 }
 if(addend->type != out->type){
  ((addend->type == CSTRING_WIDE || out->type == CSTRING_WIDE) ? (void) (0) : __assert_fail ("addend->type == CSTRING_WIDE || out->type == CSTRING_WIDE", "str.c", 230, __extension__ __PRETTY_FUNCTION__));
  if(addend->type == CSTRING_WIDE)
   cstring_widen(out);
  else
   cstring_widen(addend);
 }
 out->count += addend->count;
 if(out->type == CSTRING_WIDE){
  out->bits.wides = urealloc1(
    out->bits.wides,
    sizeof(out->bits.wides[0]) * (out->count + 1));
  memcpy(
    out->bits.wides + out->count - addend->count - !!last_is_nul,
    addend->bits.wides,
    sizeof(addend->bits.wides[0]) * (addend->count + 1));
 }else{
  out->bits.ascii = urealloc1(out->bits.ascii, out->count + 1);
  memcpy(
    out->bits.ascii + out->count - addend->count - !!last_is_nul,
    addend->bits.ascii,
    addend->count + 1);
 }
 if(last_is_nul)
  out->count--;
}

variable_types: struct cstring { union { char *ascii; int *wides; } bits; unsigned long count; enum cstring_type { CSTRING_RAW=0, CSTRING_ASCII=1, CSTRING_WIDE=2 } type; } *

variable_types:
addend
struct cstring *


original_code:
char *str_add_escape(const struct cstring *cstr)
{
 size_t nlen = 0, i;
 char *new, *p;
 for(i = 0; i < cstr->count; i++){
  int v = cstring_char_at(cstr, i);
  if(v == '\\' || v == '"')
   nlen += 3;
  else if(!((*__ctype_b_loc ())[(int) ((v))] & (unsigned short int) _ISprint))
   nlen += 4;
  else
   nlen++;
 }
 p = new = umalloc(nlen + 1);
 for(i = 0; i < cstr->count; i++){
  int v = cstring_char_at(cstr, i);
  if(v == '\\' || v == '"'){
   *p++ = '\\';
   *p++ = v;
  }else if(!((*__ctype_b_loc ())[(int) ((v))] & (unsigned short int) _ISprint)){
   int n = sprintf(p, "\\%03o", (unsigned char)v);
   do if(!(n <= 4)) ice("str.c", 291, __func__, "sprintf(octal), length %d > 4", n); while(0);
   p += n;
  }else{
   *p++ = v;
  }
 }
 return new;
}

canonical_original_code:
char *str_add_escape(struct cstring *cstr)
{
 unsigned long nlen = 0; unsigned long i;
 char *new; char *p;
 for(i = 0; i < cstr->count; i++){
  int v = cstring_char_at(cstr, i);
  if(v == '\\' || v == '"')
   nlen += 3;
  else if(!((*__ctype_b_loc ())[(int) ((v))] & (unsigned short) _ISprint))
   nlen += 4;
  else
   nlen++;
 }
 p = new = umalloc(nlen + 1);
 for(i = 0; i < cstr->count; i++){
  int v = cstring_char_at(cstr, i);
  if(v == '\\' || v == '"'){
   *p++ = '\\';
   *p++ = v;
  }else if(!((*__ctype_b_loc ())[(int) ((v))] & (unsigned short) _ISprint)){
   int n = sprintf(p, "\\%03o", (unsigned char)v);
   do if(!(n <= 4)) ice("str.c", 291, __func__, "sprintf(octal), length %d > 4", n); while(0);
   p += n;
  }else{
   *p++ = v;
  }
 }
 return new;
}

variable_types:
nlen
unsigned long

variable_types:
new
char *

variable_types:
p
char *

variable_types: v int

variable_types: n int


decompiled_code:
_BOOL8 __fastcall type_convertible(unsigned int a1)
{
_BOOL8 result; // rax

if ( a1 > 0xF )
result = a1 == 18;
else
result = a1 != 0;
return result;
}

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

if ( a1 > 0xF )
result = a1 == 18;
else
result = a1 != 0;
return result;
}

original_code:
static int type_convertible(enum type_primitive p)
{
 switch(p){
  case type__Bool:
  case type_nchar: case type_schar: case type_uchar:
  case type_int: case type_uint:
  case type_short: case type_ushort:
  case type_long: case type_ulong:
  case type_llong: case type_ullong:
  case type_float:
  case type_double:
  case type_ldouble:
  case type_enum:
   return 1;
  case type_void:
  case type_struct:
  case type_union:
  case type_unknown:
   break;
 }
 return 0;
}

variable_types: enum type_primitive { type_void=0, type__Bool=1, type_nchar=2, type_schar=3, type_uchar=4, type_int=5, type_uint=6, type_short=7, type_ushort=8, type_long=9, type_ulong=10, type_llong=11, type_ullong=12, type_float=13, type_double=14, type_ldouble=15, type_struct=16, type_union=17, type_enum=18, type_unknown=19 }


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

result = 0xFFFFFFFFLL;
if ( a1 - 2 <= 0xA )
result = a1;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 - 2 <= 0xA )
result = a1;
return result;
}

original_code:
int type_intrank(enum type_primitive p)
{
 switch(p){
  default:
   return -1;
  case type_nchar:
  case type_schar:
  case type_uchar:
  case type_int:
  case type_uint:
  case type_short:
  case type_ushort:
  case type_long:
  case type_ulong:
  case type_llong:
  case type_ullong:
   return p;
 }
}

user_defined_types: enum type_primitive { type_void=0, type__Bool=1, type_nchar=2, type_schar=3, type_uchar=4, type_int=5, type_uint=6, type_short=7, type_ushort=8, type_long=9, type_ulong=10, type_llong=11, type_ullong=12, type_float=13, type_double=14, type_ldouble=15, type_struct=16, type_union=17, type_enum=18, type_unknown=19 }


decompiled_code:
_BOOL8 __fastcall type_floating(int a1)
{
return (unsigned int)(a1 - 13) <= 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return (unsigned int)(a1 - 13) <= 2;
}

original_code:
int type_floating(enum type_primitive p)
{
 switch(p){
  case type_float:
  case type_double:
  case type_ldouble:
   return 1;
  default:
   return 0;
 }
}


decompiled_code:
char *__fastcall type_primitive_to_str(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 0x13 )
result = CSWTCH_16[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 0x13 )
result = CSWTCH_16[a1];
return result;
}

original_code:
const char *type_primitive_to_str(const enum type_primitive p)
{
 switch(p){
  case type_nchar: return "char";
  case type_schar: return "signed char";
  case type_uchar: return "unsigned char";
  case type_void: return "void";
  case type_short: return "short";
  case type_int: return "int";
  case type_long: return "long";
  case type_ushort: return "unsigned short";
  case type_uint: return "unsigned int";
  case type_ulong: return "unsigned long";
  case type_float: return "float";
  case type_double: return "double";
  case type__Bool: return "_Bool";
  case type_llong: return "long long";
  case type_ullong: return "unsigned long long";
  case type_ldouble: return "long double";
  case type_struct: return "struct";
  case type_union: return "union";
  case type_enum: return "enum";
  case type_unknown: return "unknown";
 }
 return ((void *)0);
}

canonical_original_code:
char *type_primitive_to_str(enum type_primitive p)
{
 switch(p){
  case type_nchar: return "char";
  case type_schar: return "signed char";
  case type_uchar: return "unsigned char";
  case type_void: return "void";
  case type_short: return "short";
  case type_int: return "int";
  case type_long: return "long";
  case type_ushort: return "unsigned short";
  case type_uint: return "unsigned int";
  case type_ulong: return "unsigned long";
  case type_float: return "float";
  case type_double: return "double";
  case type__Bool: return "_Bool";
  case type_llong: return "long long";
  case type_ullong: return "unsigned long long";
  case type_ldouble: return "long double";
  case type_struct: return "struct";
  case type_union: return "union";
  case type_enum: return "enum";
  case type_unknown: return "unknown";
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall type_primitive_is_signed(const char *a1, int a2)
{
char *v3; // rax

switch ( (int)a1 )
{
case 0:
case 1:
case 4:
case 6:
case 8:
case 10:
case 12:
case 18:
return 0LL;
case 2:
return cc1_fopt[5] != 0;
case 3:
case 5:
case 7:
case 9:
case 11:
case 13:
case 14:
case 15:
return 1LL;
case 16:
case 17:
if ( a2 )
goto LABEL_7;
return 0LL;
case 19:
a1 = "btype.c";
ice("btype.c", 126LL, "type_primitive_is_signed", "type_unknown in %s", "type_primitive_is_signed");
LABEL_7:
v3 = type_primitive_to_str((unsigned int)a1);
ice("btype.c", 107LL, "type_primitive_is_signed", "%s(%s)", "type_primitive_is_signed", v3);
goto LABEL_8;
default:
LABEL_8:
ice("btype.c", 129LL, "type_primitive_is_signed", "unreachable");
return btype_is_signed();
}
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, int a2)
{
char *v3; // rax

switch ( (int)a1 )
{
case 0:
case 1:
case 4:
case 6:
case 8:
case 10:
case 12:
case 18:
return 0LL;
case 2:
return cc1_fopt[5] != 0;
case 3:
case 5:
case 7:
case 9:
case 11:
case 13:
case 14:
case 15:
return 1LL;
case 16:
case 17:
if ( a2 )
goto LABEL_7;
return 0LL;
case 19:
a1 = "btype.c";
ice("btype.c", 126LL, "type_primitive_is_signed", "type_unknown in %s", "type_primitive_is_signed");
LABEL_7:
v3 = func4((unsigned int)a1);
ice("btype.c", 107LL, "type_primitive_is_signed", "%s(%s)", "type_primitive_is_signed", v3);
goto LABEL_8;
default:
LABEL_8:
ice("btype.c", 129LL, "type_primitive_is_signed", "unreachable");
return func6();
}
}

original_code:
int type_primitive_is_signed(enum type_primitive p, int hard_err_on_su)
{
 switch(p){
  case type_nchar:
   return !!(cc1_fopt.signed_char);
  case type_schar:
  case type_int:
  case type_short:
  case type_long:
  case type_llong:
  case type_float:
  case type_double:
  case type_ldouble:
   return 1;
  case type_struct:
  case type_union:
   if(hard_err_on_su){
    ice("btype.c", 107, __func__, "%s(%s)", __func__, type_primitive_to_str(p));
   }
   return 0;
  case type_enum:
   return 0;
  case type_void:
  case type__Bool:
  case type_uchar:
  case type_uint:
  case type_ushort:
  case type_ulong:
  case type_ullong:
   return 0;
  case type_unknown:
   ice("btype.c", 126, __func__, "type_unknown in %s", __func__);
 }
 do{ ice("btype.c", 129, __func__, "unreachable"); return 0; }while(0);
}


decompiled_code:
__int64 __fastcall type_primitive_size(const char *a1)
{
__int64 result; // rax
char *v2; // rax

switch ( (int)a1 )
{
case 0:
case 1:
case 2:
case 3:
case 4:
result = 1LL;
break;
case 5:
case 6:
case 13:
result = 4LL;
break;
case 7:
case 8:
result = 2LL;
break;
case 9:
case 10:
case 14:
result = platform_word_size();
if ( (_DWORD)result != 4 )
result = 8LL;
break;
case 11:
case 12:
result = 8LL;
break;
case 15:
icw("btype.c", 267LL, "type_primitive_size", "TODO: long double");
result = 4 * (unsigned int)((unsigned int)platform_word_size() != 4) + 12;
break;
case 16:
case 17:
case 18:
a1 = "btype.c";
ice("btype.c", 273LL, "type_primitive_size", "s/u/e size");
goto LABEL_11;
default:
LABEL_11:
v2 = type_primitive_to_str((unsigned int)a1);
ice("btype.c", 279LL, "type_primitive_size", "type %s in %s()", v2, "type_primitive_size");
result = btype_size();
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
__int64 result; // rax
char *v2; // rax

switch ( (int)a1 )
{
case 0:
case 1:
case 2:
case 3:
case 4:
result = 1LL;
break;
case 5:
case 6:
case 13:
result = 4LL;
break;
case 7:
case 8:
result = 2LL;
break;
case 9:
case 10:
case 14:
result = platform_word_size();
if ( (_DWORD)result != 4 )
result = 8LL;
break;
case 11:
case 12:
result = 8LL;
break;
case 15:
icw("btype.c", 267LL, "type_primitive_size", "TODO: long double");
result = 4 * (unsigned int)((unsigned int)platform_word_size() != 4) + 12;
break;
case 16:
case 17:
case 18:
a1 = "btype.c";
ice("btype.c", 273LL, "type_primitive_size", "s/u/e size");
goto LABEL_11;
default:
LABEL_11:
v2 = func4((unsigned int)a1);
ice("btype.c", 279LL, "type_primitive_size", "type %s in %s()", v2, "type_primitive_size");
result = func9();
break;
}
return result;
}

original_code:
unsigned type_primitive_size(enum type_primitive tp)
{
 switch(tp){
  case type__Bool:
  case type_void:
   return 1;
  case type_schar:
  case type_uchar:
  case type_nchar:
   return 1;
  case type_short:
  case type_ushort:
   return 2;
  case type_int:
  case type_uint:
   return 4;
  case type_float:
   return 4;
  case type_long:
  case type_ulong:
   if((platform_word_size() == 4))
    return 4;
   return 8;
  case type_llong:
  case type_ullong:
   return 8;
  case type_double:
   return (platform_word_size() == 4) ? 4 : 8;
  case type_ldouble:
   icw("btype.c", 267, __func__, "TODO: long double");
   return (platform_word_size() == 4) ? 12 : 16;
  case type_enum:
  case type_union:
  case type_struct:
   ice("btype.c", 273, __func__, "s/u/e size");
  case type_unknown:
   break;
 }
 ice("btype.c", 279, __func__, "type %s in %s()", type_primitive_to_str(tp), __func__);
 return -1;
}

canonical_original_code:
unsigned int type_primitive_size(enum type_primitive tp)
{
 switch(tp){
  case type__Bool:
  case type_void:
   return 1;
  case type_schar:
  case type_uchar:
  case type_nchar:
   return 1;
  case type_short:
  case type_ushort:
   return 2;
  case type_int:
  case type_uint:
   return 4;
  case type_float:
   return 4;
  case type_long:
  case type_ulong:
   if((platform_word_size() == 4))
    return 4;
   return 8;
  case type_llong:
  case type_ullong:
   return 8;
  case type_double:
   return (platform_word_size() == 4) ? 4 : 8;
  case type_ldouble:
   icw("btype.c", 267, __func__, "TODO: long double");
   return (platform_word_size() == 4) ? 12 : 16;
  case type_enum:
  case type_union:
  case type_struct:
   ice("btype.c", 273, __func__, "s/u/e size");
  case type_unknown:
   break;
 }
 ice("btype.c", 279, __func__, "type %s in %s()", type_primitive_to_str(tp), __func__);
 return -1;
}


decompiled_code:
__int64 __fastcall type_primitive_max(const char *a1, int a2)
{
__int64 result; // rax
char *v3; // rax

switch ( (int)a1 )
{
case 1:
return 1LL;
case 2:
case 3:
case 4:
result = 127LL;
goto LABEL_3;
case 5:
result = 0x7FFFFFFFLL;
goto LABEL_3;
case 7:
result = 0x7FFFLL;
goto LABEL_3;
case 9:
case 11:
result = 0x7FFFFFFFFFFFFFFFLL;
LABEL_3:
if ( !a2 )
result = 2 * result + 1;
return result;
case 13:
case 14:
case 15:
ice("btype.c", 306LL, "type_primitive_max", "TODO: float max");
goto LABEL_11;
case 16:
case 17:
case 18:
LABEL_11:
a1 = "btype.c";
ice("btype.c", 311LL, "type_primitive_max", "sue max");
break;
default:
break;
}
v3 = type_primitive_to_str((unsigned int)a1);
ice("btype.c", 316LL, "type_primitive_max", "bad primitive %s", v3);
return type_cmp_to_str();
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, int a2)
{
__int64 result; // rax
char *v3; // rax

switch ( (int)a1 )
{
case 1:
return 1LL;
case 2:
case 3:
case 4:
result = 127LL;
goto LABEL_3;
case 5:
result = 0x7FFFFFFFLL;
goto LABEL_3;
case 7:
result = 0x7FFFLL;
goto LABEL_3;
case 9:
case 11:
result = 0x7FFFFFFFFFFFFFFFLL;
LABEL_3:
if ( !a2 )
result = 2 * result + 1;
return result;
case 13:
case 14:
case 15:
ice("btype.c", 306LL, "type_primitive_max", "TODO: float max");
goto LABEL_11;
case 16:
case 17:
case 18:
LABEL_11:
a1 = "btype.c";
ice("btype.c", 311LL, "type_primitive_max", "sue max");
break;
default:
break;
}
v3 = func4((unsigned int)a1);
ice("btype.c", 316LL, "type_primitive_max", "bad primitive %s", v3);
return func12();
}

original_code:
unsigned long long
type_primitive_max(enum type_primitive p, int is_signed)
{
 unsigned long long max;
 switch(p){
  case type__Bool: return 1;
  case type_nchar:
  case type_schar:
  case type_uchar:
   max = 127;
   break;
  case type_short: max = 32767; break;
  case type_int: max = 2147483647; break;
  case type_long: max = 9223372036854775807L; break;
  case type_llong: max = 9223372036854775807LL; break;
  case type_float:
  case type_double:
  case type_ldouble:
   ice("btype.c", 306, __func__, "TODO: float max");
  case type_union:
  case type_struct:
  case type_enum:
   ice("btype.c", 311, __func__, "sue max");
  case type_void:
  case type_unknown:
  default:
   ice("btype.c", 316, __func__, "bad primitive %s", type_primitive_to_str(p));
 }
 return is_signed ? max : max * 2 + 1;
}

variable_types:
max
unsigned long long

return_type: unsigned long long


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

if ( a1 > 0x20 )
{
result = "CONVERTIBLE_EXPLICIT";
if ( a1 != 256 )
{
if ( a1 <= 0x100 )
{
result = "QUAL_NESTED_CHANGE";
if ( a1 != 64 )
{
result = "CONVERTIBLE_IMPLICIT";
if ( a1 != 128 )
result = 0LL;
}
}
else
{
result = "NOT_EQUAL";
if ( a1 != 512 )
result = 0LL;
}
}
}
else
{
result = 0LL;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = "EQUAL";
break;
case 2u:
result = "EQUAL_TYPEDEF";
break;
case 4u:
result = "QUAL_ADD";
break;
case 8u:
result = "QUAL_SUB";
break;
case 0x10u:
result = "QUAL_POINTED_ADD";
break;
case 0x20u:
result = "QUAL_POINTED_SUB";
break;
default:
result = 0LL;
break;
}
}
}
return result;
}

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

if ( a1 > 0x20 )
{
result = "CONVERTIBLE_EXPLICIT";
if ( a1 != 256 )
{
if ( a1 <= 0x100 )
{
result = "QUAL_NESTED_CHANGE";
if ( a1 != 64 )
{
result = "CONVERTIBLE_IMPLICIT";
if ( a1 != 128 )
result = 0LL;
}
}
else
{
result = "NOT_EQUAL";
if ( a1 != 512 )
result = 0LL;
}
}
}
else
{
result = 0LL;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = "EQUAL";
break;
case 2u:
result = "EQUAL_TYPEDEF";
break;
case 4u:
result = "QUAL_ADD";
break;
case 8u:
result = "QUAL_SUB";
break;
case 0x10u:
result = "QUAL_POINTED_ADD";
break;
case 0x20u:
result = "QUAL_POINTED_SUB";
break;
default:
result = 0LL;
break;
}
}
}
return result;
}

original_code:
const char *type_cmp_to_str(enum type_cmp cmp)
{
 switch(cmp){
  case TYPE_EQUAL: return "EQUAL";
  case TYPE_EQUAL_TYPEDEF: return "EQUAL_TYPEDEF";
  case TYPE_QUAL_ADD: return "QUAL_ADD";
  case TYPE_QUAL_SUB: return "QUAL_SUB";
  case TYPE_QUAL_POINTED_ADD: return "QUAL_POINTED_ADD";
  case TYPE_QUAL_POINTED_SUB: return "QUAL_POINTED_SUB";
  case TYPE_QUAL_NESTED_CHANGE: return "QUAL_NESTED_CHANGE";
  case TYPE_CONVERTIBLE_IMPLICIT: return "CONVERTIBLE_IMPLICIT";
  case TYPE_CONVERTIBLE_EXPLICIT: return "CONVERTIBLE_EXPLICIT";
  case TYPE_NOT_EQUAL: return "NOT_EQUAL";
 }
 return ((void *)0);
}

variable_types: enum type_cmp { TYPE_EQUAL=expr, TYPE_EQUAL_TYPEDEF=expr, TYPE_QUAL_ADD=expr, TYPE_QUAL_SUB=expr, TYPE_QUAL_POINTED_ADD=expr, TYPE_QUAL_POINTED_SUB=expr, TYPE_QUAL_NESTED_CHANGE=expr, TYPE_CONVERTIBLE_IMPLICIT=expr, TYPE_CONVERTIBLE_EXPLICIT=expr, TYPE_NOT_EQUAL=expr }


decompiled_code:
char *__fastcall type_qual_to_str(char a1, int a2)
{
const char *v2; // r9
const char *v3; // r8
const char *v4; // rcx
char *v5; // rax

v2 = "restrict ";
if ( (a1 & 4) == 0 )
v2 = (const char *)&unk_862;
v3 = "volatile ";
if ( (a1 & 2) == 0 )
v3 = (const char *)&unk_862;
v4 = "const ";
if ( (a1 & 1) == 0 )
v4 = (const char *)&unk_862;
snprintf(buf_0, 0x20uLL, "%s%s%s", v4, v3, v2);
if ( !a2 )
{
v5 = strrchr(buf_0, 32);
if ( v5 )
*v5 = 0;
}
return buf_0;
}

canonical_decompiled_code:
char *__fastcall func13(char a1, int a2)
{
const char *v2; // r9
const char *v3; // r8
const char *v4; // rcx
char *v5; // rax

v2 = "restrict ";
if ( (a1 & 4) == 0 )
v2 = (const char *)&unk_862;
v3 = "volatile ";
if ( (a1 & 2) == 0 )
v3 = (const char *)&unk_862;
v4 = "const ";
if ( (a1 & 1) == 0 )
v4 = (const char *)&unk_862;
snprintf(buf_0, 0x20uLL, "%s%s%s", v4, v3, v2);
if ( !a2 )
{
v5 = strrchr(buf_0, 32);
if ( v5 )
*v5 = 0;
}
return buf_0;
}

original_code:
const char *type_qual_to_str(const enum type_qualifier qual, int trailing_space)
{
 static char buf[32];
 snprintf(buf, sizeof buf, "%s%s%s",
  qual & qual_const ? "const " : "",
  qual & qual_volatile ? "volatile " : "",
  qual & qual_restrict ? "restrict " : "");
 if(!trailing_space){
  char *last = strrchr(buf, ' ');
  if(last)
   *last = '\0';
 }
 return buf;
}

canonical_original_code:
char *type_qual_to_str(enum type_qualifier qual, int trailing_space)
{
 static char buf[32];
 snprintf(buf, sizeof buf, "%s%s%s",
  qual & qual_const ? "const " : "",
  qual & qual_volatile ? "volatile " : "",
  qual & qual_restrict ? "restrict " : "");
 if(!trailing_space){
  char *last = strrchr(buf, ' ');
  if(last)
   *last = '\0';
 }
 return buf;
}

variable_types: enum type_qualifier { qual_none=0, qual_const=expr, qual_volatile=expr, qual_restrict=expr }

variable_types:
buf
char [32]

variable_types:
last
char *


decompiled_code:
__int64 __fastcall visibility_parse(_DWORD *a1, const char *a2, int a3)
{
__int64 result; // rax
bool v4; // zf

if ( !strcmp(a2, "default") )
{
*a1 = 0;
result = 1LL;
}
else if ( !strcmp(a2, "hidden") )
{
*a1 = 1;
result = 1LL;
}
else
{
v4 = strcmp(a2, "protected") == 0;
if ( a3 && v4 )
{
*a1 = 2;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, const char *a2, int a3)
{
__int64 result; // rax
bool v4; // zf

if ( !strcmp(a2, "default") )
{
*a1 = 0;
result = 1LL;
}
else if ( !strcmp(a2, "hidden") )
{
*a1 = 1;
result = 1LL;
}
else
{
v4 = strcmp(a2, "protected") == 0;
if ( a3 && v4 )
{
*a1 = 2;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int visibility_parse(enum visibility *const e, const char *s, int allow_protected)
{
 if(!strcmp(s, "default"))
  *e = VISIBILITY_DEFAULT;
 else if(!strcmp(s, "hidden"))
  *e = VISIBILITY_HIDDEN;
 else if(!strcmp(s, "protected") && allow_protected)
  *e = VISIBILITY_PROTECTED;
 else
  return 0;
 return 1;
}

canonical_original_code:
int visibility_parse(enum visibility *e, char *s, int allow_protected)
{
 if(!strcmp(s, "default"))
  *e = VISIBILITY_DEFAULT;
 else if(!strcmp(s, "hidden"))
  *e = VISIBILITY_HIDDEN;
 else if(!strcmp(s, "protected") && allow_protected)
  *e = VISIBILITY_PROTECTED;
 else
  return 0;
 return 1;
}

variable_types: enum visibility { VISIBILITY_DEFAULT=0, VISIBILITY_HIDDEN=1, VISIBILITY_PROTECTED=2 } *

variable_types:
s
char *


decompiled_code:
char *__fastcall visibility_to_str(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = CSWTCH_2[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 2 )
result = CSWTCH_2[a1];
return result;
}

original_code:
const char *visibility_to_str(enum visibility v)
{
 switch(v){
  case VISIBILITY_DEFAULT: return "default";
  case VISIBILITY_HIDDEN: return "hidden";
  case VISIBILITY_PROTECTED: return "protected";
 }
 return ((void *)0);
}

variable_types: enum visibility { VISIBILITY_DEFAULT=0, VISIBILITY_HIDDEN=1, VISIBILITY_PROTECTED=2 }


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

result = 1LL;
if ( a1 != 2 )
{
result = 0LL;
if ( a1 > 2 )
result = (unsigned int)-(a1 != 3);
}
return result;
}

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

result = 1LL;
if ( a1 != 2 )
{
result = 0LL;
if ( a1 > 2 )
result = (unsigned int)-(a1 != 3);
}
return result;
}

original_code:
static enum vendor infer_vendor(enum sys sys)
{
 switch(sys){
  case SYS_linux: return VENDOR_pc;
  case SYS_darwin: return VENDOR_apple;
  case SYS_cygwin: return VENDOR_pc;
  case SYS_freebsd: return VENDOR_pc;
 }
 return -1;
}

variable_types: enum sys { SYS_linux=0, SYS_freebsd=1, SYS_darwin=2, SYS_cygwin=3 }

return_type: enum vendor { VENDOR_pc=0, VENDOR_apple=1 }


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

result = 0xFFFFFFFFLL;
if ( a1 <= 3 )
result = (unsigned int)CSWTCH_16[a1];
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 <= 3 )
result = (unsigned int)CSWTCH_16[a1];
return result;
}

original_code:
static enum abi infer_abi(enum sys sys)
{
 switch(sys){
  case SYS_linux: return ABI_gnu;
  case SYS_darwin: return ABI_macho;
  case SYS_cygwin: return ABI_elf;
  case SYS_freebsd: return ABI_elf;
 }
 return -1;
}

return_type: enum abi { ABI_gnu=0, ABI_macho=1, ABI_elf=2 }

user_defined_types: enum sys { SYS_linux=0, SYS_freebsd=1, SYS_darwin=2, SYS_cygwin=3 }


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

result = "x86_64";
if ( a1 )
{
result = "i386";
if ( a1 != 1 )
result = 0LL;
}
return result;
}

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

result = "x86_64";
if ( a1 )
{
result = "i386";
if ( a1 != 1 )
result = 0LL;
}
return result;
}

original_code:
static const char *arch_to_str(enum arch a)
{
 switch(a){
  case ARCH_x86_64: return "x86_64"; case ARCH_i386: return "i386";
 }
 return ((void *)0);
}

canonical_original_code:
static char *arch_to_str(enum arch a)
{
 switch(a){
  case ARCH_x86_64: return "x86_64"; case ARCH_i386: return "i386";
 }
 return ((void *)0);
}

variable_types: enum arch { ARCH_x86_64=0, ARCH_i386=1 }


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

result = "pc";
if ( a1 )
{
result = "apple";
if ( a1 != 1 )
result = 0LL;
}
return result;
}

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

result = "pc";
if ( a1 )
{
result = "apple";
if ( a1 != 1 )
result = 0LL;
}
return result;
}

original_code:
static const char *vendor_to_str(enum vendor v)
{
 switch(v){
  case VENDOR_pc: return "pc"; case VENDOR_apple: return "apple";
 }
 return ((void *)0);
}

canonical_original_code:
static char *vendor_to_str(enum vendor v)
{
 switch(v){
  case VENDOR_pc: return "pc"; case VENDOR_apple: return "apple";
 }
 return ((void *)0);
}

variable_types: enum vendor { VENDOR_pc=0, VENDOR_apple=1 }


decompiled_code:
char *__fastcall sys_to_str(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = CSWTCH_20[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 3 )
result = CSWTCH_20[a1];
return result;
}

original_code:
static const char *sys_to_str(enum sys s)
{
 switch(s){
  case SYS_linux: return "linux"; case SYS_freebsd: return "freebsd"; case SYS_darwin: return "darwin"; case SYS_cygwin: return "cygwin";
 }
 return ((void *)0);
}

canonical_original_code:
static char *sys_to_str(enum sys s)
{
 switch(s){
  case SYS_linux: return "linux"; case SYS_freebsd: return "freebsd"; case SYS_darwin: return "darwin"; case SYS_cygwin: return "cygwin";
 }
 return ((void *)0);
}


decompiled_code:
char *__fastcall abi_to_str(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = CSWTCH_22[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = CSWTCH_22[a1];
return result;
}

original_code:
static const char *abi_to_str(enum abi a)
{
 switch(a){
  case ABI_gnu: return "gnu"; case ABI_macho: return "macho"; case ABI_elf: return "elf";
 }
 return ((void *)0);
}

canonical_original_code:
static char *abi_to_str(enum abi a)
{
 switch(a){
  case ABI_gnu: return "gnu"; case ABI_macho: return "macho"; case ABI_elf: return "elf";
 }
 return ((void *)0);
}

variable_types: enum abi { ABI_gnu=0, ABI_macho=1, ABI_elf=2 }


decompiled_code:
__int64 __fastcall parse_arch(const char *a1, _DWORD *a2)
{
if ( strcmp(a1, "x86_64") )
{
if ( !strcmp(a1, "i386") )
{
LABEL_6:
*a2 = 1;
return 1LL;
}
if ( strcmp(a1, "amd64") )
{
if ( strcmp(a1, "i686") )
return 0LL;
goto LABEL_6;
}
}
*a2 = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, _DWORD *a2)
{
if ( strcmp(a1, "x86_64") )
{
if ( !strcmp(a1, "i386") )
{
LABEL_6:
*a2 = 1;
return 1LL;
}
if ( strcmp(a1, "amd64") )
{
if ( strcmp(a1, "i686") )
return 0LL;
goto LABEL_6;
}
}
*a2 = 0;
return 1LL;
}

original_code:
static int parse_arch(const char *in, enum arch *out)
{
 if(!strcmp(in, "x86_64")){ *out = ARCH_x86_64; return 1; } if(!strcmp(in, "i386")){ *out = ARCH_i386; return 1; } if(!strcmp(in, "amd64")){ *out = ARCH_x86_64; return 1; } if(!strcmp(in, "i686")){ *out = ARCH_i386; return 1; }
 return 0;
}

canonical_original_code:
static int parse_arch(char *in, enum arch *out)
{
 if(!strcmp(in, "x86_64")){ *out = ARCH_x86_64; return 1; } if(!strcmp(in, "i386")){ *out = ARCH_i386; return 1; } if(!strcmp(in, "amd64")){ *out = ARCH_x86_64; return 1; } if(!strcmp(in, "i686")){ *out = ARCH_i386; return 1; }
 return 0;
}

variable_types:
in
char *

variable_types: enum arch { ARCH_x86_64=0, ARCH_i386=1 } *