repo: kastnerkyle/deviation

decompiled_code:
void *__fastcall expand_buf(void **a1, unsigned int *a2)
{
void *v4; // rdi
unsigned int v5; // esi
void *result; // rax
signed int v7; // esi

v4 = *a1;
if ( v4 && (v5 = *a2) != 0 )
{
v7 = v5 + 1024;
*a2 = v7;
result = realloc(v4, v7);
*a1 = result;
if ( !result )
{
fprintf(stderr, "Unable to expand CSV field buffer to %d bytes.\n", *a2);
abort();
}
}
else
{
result = malloc(0x100uLL);
*a1 = result;
if ( !result )
{
fprintf(stderr, "Unable to allocate %d byte CSV field buffer.\n", 256LL);
abort();
}
*a2 = 256;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void **a1, unsigned int *a2)
{
void *v4; // rdi
unsigned int v5; // esi
void *result; // rax
signed int v7; // esi

v4 = *a1;
if ( v4 && (v5 = *a2) != 0 )
{
v7 = v5 + 1024;
*a2 = v7;
result = realloc(v4, v7);
*a1 = result;
if ( !result )
{
fprintf(stderr, "Unable to expand CSV field buffer to %d bytes.\n", *a2);
abort();
}
}
else
{
result = malloc(0x100uLL);
*a1 = result;
if ( !result )
{
fprintf(stderr, "Unable to allocate %d byte CSV field buffer.\n", 256LL);
abort();
}
*a2 = 256;
}
return result;
}

original_code:
static void expand_buf(char **b_f, int *b_flen)
{
    if (((*b_f) == ((void *)0)) || ((*b_flen) == 0)) {
     (*b_f) = (char *) malloc(256);
 if ((*b_f) == ((void *)0)) {
     fprintf(stderr, "Unable to allocate %d byte CSV field buffer.\n", 256);
     abort();
     }
 (*b_flen) = 256;
    } else {
     (*b_flen) += 1024;
     (*b_f) = (char *) realloc((*b_f), (*b_flen));
 if ((*b_f) == ((void *)0)) {
     fprintf(stderr, "Unable to expand CSV field buffer to %d bytes.\n", (*b_flen));
     abort();
     }
    }
}


CSVscanInit

decompiled_code:
void __fastcall CSVscanInit(__int64 a1)
{
csptr = a1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
csptr = a1;
}

original_code:
void CSVscanInit(const char *s)
{
    csptr = s;
}

canonical_original_code:
void CSVscanInit(char *s)
{
    csptr = s;
}

variable_types:
s
char *

return_type: void


CSVscanField

original_code:
int CSVscanField(char **b_f, int *b_flen)
{
    int foundfield = 0, quoted = 0;
    CSVfieldLength = 0;
    if (*csptr != '\0') {
 foundfield = 1;
 while ((*csptr != '\0') && ((*__ctype_b_loc ())[(int) ((*csptr))] & (unsigned short int) _ISspace)) {
     csptr++;
 }
        if (*csptr == '"') {
     quoted = 1;
     csptr++;
     while (*csptr != '\0') {
                if (*csptr == '"') {
                    if (csptr[1] == '"') {
                        if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = '"'; CSVfieldLength++;;
   csptr += 2;
      } else {
   csptr++;
   break;
      }
                } else if (*csptr == '\\') {
                    if (csptr[1] == '\\') {
                        if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = '\\'; CSVfieldLength++;;
   csptr += 2;
      } else {
   unsigned int v = 0;
   int i;
               for (i = 0; i < 3; i++) {
       csptr++;
       if ((*csptr >= '0') && (*csptr <= '7')) {
        v = (v << 3) | (*csptr - '0');
       } else {
        csptr--;
                   }
   }
   csptr++;
   if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = (char) v; CSVfieldLength++;;
      }
  } else {
      char c = *csptr++;
      if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = c; CSVfieldLength++;;
  }
     }
 }
        while (*csptr != ',' && *csptr != '\0') {
     char c = *csptr++;
     if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = c; CSVfieldLength++;;
 }
        if (*csptr == ',') {
     csptr++;
 }
    }
    (*b_f)[CSVfieldLength] = '\0';
    if (foundfield && !quoted) {
 while (CSVfieldLength > 0 && ((*__ctype_b_loc ())[(int) (((*b_f)[CSVfieldLength - 1]))] & (unsigned short int) _ISspace)) {
     (*b_f)[--CSVfieldLength] = '\0';
 }
    }
    return foundfield;
}

canonical_original_code:
int CSVscanField(char **b_f, int *b_flen)
{
    int foundfield = 0; int quoted = 0;
    CSVfieldLength = 0;
    if (*csptr != '\0') {
 foundfield = 1;
 while ((*csptr != '\0') && ((*__ctype_b_loc ())[(int) ((*csptr))] & (unsigned short) _ISspace)) {
     csptr++;
 }
        if (*csptr == '"') {
     quoted = 1;
     csptr++;
     while (*csptr != '\0') {
                if (*csptr == '"') {
                    if (csptr[1] == '"') {
                        if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = '"'; CSVfieldLength++;;
   csptr += 2;
      } else {
   csptr++;
   break;
      }
                } else if (*csptr == '\\') {
                    if (csptr[1] == '\\') {
                        if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = '\\'; CSVfieldLength++;;
   csptr += 2;
      } else {
   unsigned int v = 0;
   int i;
               for (i = 0; i < 3; i++) {
       csptr++;
       if ((*csptr >= '0') && (*csptr <= '7')) {
        v = (v << 3) | (*csptr - '0');
       } else {
        csptr--;
                   }
   }
   csptr++;
   if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = (char) v; CSVfieldLength++;;
      }
  } else {
      char c = *csptr++;
      if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = c; CSVfieldLength++;;
  }
     }
 }
        while (*csptr != ',' && *csptr != '\0') {
     char c = *csptr++;
     if (CSVfieldLength >= ((*b_flen) - 1)) { expand_buf(b_f, b_flen); } (*b_f)[CSVfieldLength] = c; CSVfieldLength++;;
 }
        if (*csptr == ',') {
     csptr++;
 }
    }
    (*b_f)[CSVfieldLength] = '\0';
    if (foundfield && !quoted) {
 while (CSVfieldLength > 0 && ((*__ctype_b_loc ())[(int) (((*b_f)[CSVfieldLength - 1]))] & (unsigned short) _ISspace)) {
     (*b_f)[--CSVfieldLength] = '\0';
 }
    }
    return foundfield;
}

variable_types: foundfield int

variable_types: quoted int

variable_types:
v
unsigned int

variable_types: i int

variable_types: c char

return_type: int


Getopt

decompiled_code:
__int64 __fastcall Getopt(int a1, const char **a2, const char *a3)
{
const char *v3; // rax
unsigned int v4; // er12
char *v5; // r13
__int64 v6; // rbp
char *v7; // rax
int v9; // eax
size_t v10; // rdx
FILE *v11; // rcx
const char *v12; // rdi
const char *v13; // rdi

if ( (const char *)lastostr_1 != a3 )
{
lastostr_1 = (__int64)a3;
LABEL_3:
if ( optind < a1
&& (v3 = a2[optind], *v3 == 45)
&& (v4 = v3[1], v5 = (char *)(v3 + 1), place_0 = (void *)(v3 + 1), (_BYTE)v4) )
{
if ( (_BYTE)v4 != 45 )
goto LABEL_7;
if ( v3[2] )
{
v6 = (__int64)(v3 + 2);
v4 = 45;
optopt = 45;
place_0 = (void *)(v3 + 2);
goto LABEL_8;
}
v4 = -1;
++optind;
}
else
{
place_0 = &unk_288;
v4 = -1;
}
return v4;
}
v5 = (char *)place_0;
v4 = *(char *)place_0;
if ( !*(_BYTE *)place_0 )
goto LABEL_3;
LABEL_7:
v6 = (__int64)(v5 + 1);
optopt = v4;
place_0 = v5 + 1;
if ( v4 == 58 )
{
LABEL_19:
if ( !v5[1] )
++optind;
fputs(*a2, stderr);
v10 = 20LL;
v11 = stderr;
v12 = ": illegal option -- ";
goto LABEL_22;
}
LABEL_8:
v7 = strchr(a3, v4);
if ( !v7 )
goto LABEL_19;
if ( v7[1] != 58 )
{
optarg = 0LL;
if ( !v5[1] )
++optind;
return v4;
}
v9 = optind;
if ( v5[1] )
{
optarg = v6;
goto LABEL_18;
}
v9 = optind + 1;
optind = v9;
if ( a1 > v9 )
{
optarg = (__int64)a2[v9];
LABEL_18:
place_0 = &unk_288;
optind = v9 + 1;
return v4;
}
v13 = *a2;
place_0 = &unk_288;
fputs(v13, stderr);
v10 = 33LL;
v11 = stderr;
v12 = ": option requires an argument -- ";
LABEL_22:
fwrite(v12, 1uLL, v10, v11);
fputc(optopt, stderr);
fputc(10, stderr);
return 63LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char **a2, const char *a3)
{
const char *v3; // rax
unsigned int v4; // er12
char *v5; // r13
__int64 v6; // rbp
char *v7; // rax
int v9; // eax
size_t v10; // rdx
FILE *v11; // rcx
const char *v12; // rdi
const char *v13; // rdi

if ( (const char *)lastostr_1 != a3 )
{
lastostr_1 = (__int64)a3;
LABEL_3:
if ( optind < a1
&& (v3 = a2[optind], *v3 == 45)
&& (v4 = v3[1], v5 = (char *)(v3 + 1), place_0 = (void *)(v3 + 1), (_BYTE)v4) )
{
if ( (_BYTE)v4 != 45 )
goto LABEL_7;
if ( v3[2] )
{
v6 = (__int64)(v3 + 2);
v4 = 45;
optopt = 45;
place_0 = (void *)(v3 + 2);
goto LABEL_8;
}
v4 = -1;
++optind;
}
else
{
place_0 = &unk_288;
v4 = -1;
}
return v4;
}
v5 = (char *)place_0;
v4 = *(char *)place_0;
if ( !*(_BYTE *)place_0 )
goto LABEL_3;
LABEL_7:
v6 = (__int64)(v5 + 1);
optopt = v4;
place_0 = v5 + 1;
if ( v4 == 58 )
{
LABEL_19:
if ( !v5[1] )
++optind;
fputs(*a2, stderr);
v10 = 20LL;
v11 = stderr;
v12 = ": illegal option -- ";
goto LABEL_22;
}
LABEL_8:
v7 = strchr(a3, v4);
if ( !v7 )
goto LABEL_19;
if ( v7[1] != 58 )
{
optarg = 0LL;
if ( !v5[1] )
++optind;
return v4;
}
v9 = optind;
if ( v5[1] )
{
optarg = v6;
goto LABEL_18;
}
v9 = optind + 1;
optind = v9;
if ( a1 > v9 )
{
optarg = (__int64)a2[v9];
LABEL_18:
place_0 = &unk_288;
optind = v9 + 1;
return v4;
}
v13 = *a2;
place_0 = &unk_288;
fputs(v13, stderr);
v10 = 33LL;
v11 = stderr;
v12 = ": option requires an argument -- ";
LABEL_22:
fwrite(v12, 1uLL, v10, v11);
fputc(optopt, stderr);
fputc(10, stderr);
return 63LL;
}

original_code:
int Getopt(int nargc, char *nargv[], char *ostr)
{
        static char *place = "";
        static char *lastostr = (char *) 0;
        register char *oli;
        char *index();
        if (ostr != lastostr) {
                lastostr = ostr;
                place = "";
        }
        if(!*place) {
                if((optind >= nargc) || (*(place = nargv[optind]) != '-')
                                || ! *++place) {
                        place = "";
                        return((-1));
                }
                if (*place == '-' && place[1] == 0) {
                        ++optind;
                        return((-1));
                }
        }
        if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr, optopt))) {
                if(!*place) ++optind;
                fputs(*nargv,stderr);fputs(": illegal option -- ",stderr); fputc(optopt,stderr);fputc('\n',stderr);return((int)'?');;
        }
        if (*++oli != ':') {
                optarg = ((void *)0);
                if (!*place) ++optind;
        }
        else {
                if (*place) optarg = place;
                else if (nargc <= ++optind) {
                        place = "";
                        fputs(*nargv,stderr);fputs(": option requires an argument -- ",stderr); fputc(optopt,stderr);fputc('\n',stderr);return((int)'?');;
                }
                else optarg = nargv[optind];
                place = "";
                ++optind;
        }
        return(optopt);
}

variable_types: nargc int

variable_types:
nargv
char *[]

variable_types:
ostr
char *

variable_types:
place
char *

variable_types:
lastostr
char *

variable_types:
oli
char *

variable_types:
index
char *()


getcal

repo: kastur/ECGCS

decompiled_code:
__int64 __fastcall getcal(char *s1, char *a2, __int64 a3)
{
void *v4; // rbx
const char *v5; // r14
size_t v6; // rax
__int64 v7; // r14
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // xmm0_8

v4 = first_cle;
this_cle = (__int64)first_cle;
if ( !first_cle )
return 0xFFFFFFFFLL;
while ( 1 )
{
if ( !s1 || (v5 = (const char *)*((_QWORD *)v4 + 3), v6 = strlen(v5), !strncmp(s1, v5, v6)) )
{
v7 = *((_QWORD *)v4 + 4);
if ( !a2 || !strcmp(a2, *((const char **)v4 + 4)) )
break;
}
v4 = (void *)*((_QWORD *)v4 + 6);
this_cle = (__int64)v4;
if ( !v4 )
return 0xFFFFFFFFLL;
}
v9 = *((_QWORD *)v4 + 3);
*(_QWORD *)a3 = *(_QWORD *)v4;
*(_QWORD *)(a3 + 8) = *((_QWORD *)v4 + 1);
v10 = *((_QWORD *)v4 + 2);
*(_QWORD *)(a3 + 24) = v9;
LODWORD(v9) = *((_DWORD *)v4 + 10);
*(_QWORD *)(a3 + 32) = v7;
*(_DWORD *)(a3 + 40) = v9;
result = 0LL;
*(_QWORD *)(a3 + 16) = v10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, char *a2, __int64 a3)
{
void *v4; // rbx
const char *v5; // r14
size_t v6; // rax
__int64 v7; // r14
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // xmm0_8

v4 = first_cle;
this_cle = (__int64)first_cle;
if ( !first_cle )
return 0xFFFFFFFFLL;
while ( 1 )
{
if ( !s1 || (v5 = (const char *)*((_QWORD *)v4 + 3), v6 = strlen(v5), !strncmp(s1, v5, v6)) )
{
v7 = *((_QWORD *)v4 + 4);
if ( !a2 || !strcmp(a2, *((const char **)v4 + 4)) )
break;
}
v4 = (void *)*((_QWORD *)v4 + 6);
this_cle = (__int64)v4;
if ( !v4 )
return 0xFFFFFFFFLL;
}
v9 = *((_QWORD *)v4 + 3);
*(_QWORD *)a3 = *(_QWORD *)v4;
*(_QWORD *)(a3 + 8) = *((_QWORD *)v4 + 1);
v10 = *((_QWORD *)v4 + 2);
*(_QWORD *)(a3 + 24) = v9;
LODWORD(v9) = *((_DWORD *)v4 + 10);
*(_QWORD *)(a3 + 32) = v7;
*(_DWORD *)(a3 + 40) = v9;
result = 0LL;
*(_QWORD *)(a3 + 16) = v10;
return result;
}

original_code:
FINT getcal(char *desc, char *units, WFDB_Calinfo *cal)
{
    for (this_cle = first_cle; this_cle; this_cle = this_cle->next) {
 if ((desc == ((void *)0) || strncmp(desc, this_cle->sigtype,
         strlen(this_cle->sigtype)) == 0) &&
     (units == ((void *)0) || strcmp(units, this_cle->units) == 0)) {
     cal->low = this_cle->low;
     cal->high = this_cle->high;
     cal->scale = this_cle->scale;
     cal->sigtype = this_cle->sigtype;
     cal->units = this_cle->units;
     cal->caltype = this_cle->caltype;
     return (0);
 }
    }
    return (-1);
}

canonical_original_code:
int getcal(char *desc, char *units, struct WFDB_calinfo *cal)
{
    for (this_cle = first_cle; this_cle; this_cle = this_cle->next) {
 if ((desc == ((void *)0) || strncmp(desc, this_cle->sigtype,
         strlen(this_cle->sigtype)) == 0) &&
     (units == ((void *)0) || strcmp(units, this_cle->units) == 0)) {
     cal->low = this_cle->low;
     cal->high = this_cle->high;
     cal->scale = this_cle->scale;
     cal->sigtype = this_cle->sigtype;
     cal->units = this_cle->units;
     cal->caltype = this_cle->caltype;
     return (0);
 }
    }
    return (-1);
}

variable_types:
desc
char *

variable_types:
units
char *

variable_types: struct WFDB_calinfo { double low; double high; double scale; char *sigtype; char *units; int caltype; } *


putcal

decompiled_code:
__int64 __fastcall putcal(__int64 a1)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
const char *v4; // r12
void *v5; // rdi
size_t v6; // rax
char *v7; // rax
char *v8; // rdi
int v9; // eax
const char *v10; // r12
__int64 v11; // xmm0_8
void *v12; // rdi
size_t v13; // rax
char *v14; // rax
char *v15; // rdi
bool v16; // zf
__int64 v17; // rax
__int64 result; // rax
size_t v19; // rax
size_t v20; // rax

v2 = calloc(1uLL, 0x38uLL);
this_cle = (__int64)v2;
if ( v2 )
{
v3 = v2;
}
else
{
wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", 1LL, 56LL, "this_cle");
if ( (unsigned int)wfdb_me_fatal() )
goto LABEL_22;
v3 = (_QWORD *)this_cle;
}
v4 = *(const char **)(a1 + 24);
if ( v4 )
{
v5 = (void *)v3[3];
if ( v5 )
{
free(v5);
v3[3] = 0LL;
v4 = *(const char **)(a1 + 24);
}
v6 = strlen(v4);
v7 = (char *)calloc(v6 + 1, 1uLL);
v3[3] = v7;
v8 = v7;
if ( !v7 )
{
v20 = strlen(v4);
wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", v20 + 1, 1LL, "this_cle->sigtype");
if ( (unsigned int)wfdb_me_fatal() )
goto LABEL_22;
v3 = (_QWORD *)this_cle;
v4 = *(const char **)(a1 + 24);
v8 = *(char **)(this_cle + 24);
}
strcpy(v8, v4);
}
v9 = *(_DWORD *)(a1 + 40);
v10 = *(const char **)(a1 + 32);
*v3 = *(_QWORD *)a1;
v11 = *(_QWORD *)(a1 + 8);
*((_DWORD *)v3 + 10) = v9;
v3[1] = v11;
v3[2] = *(_QWORD *)(a1 + 16);
if ( !v10 )
goto LABEL_13;
v12 = (void *)v3[4];
if ( v12 )
{
free(v12);
v3[4] = 0LL;
v10 = *(const char **)(a1 + 32);
}
v13 = strlen(v10);
v14 = (char *)calloc(v13 + 1, 1uLL);
v3[4] = v14;
v15 = v14;
if ( !v14 )
{
v19 = strlen(v10);
wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", v19 + 1, 1LL, "this_cle->units");
if ( !(unsigned int)wfdb_me_fatal() )
{
v3 = (_QWORD *)this_cle;
v10 = *(const char **)(a1 + 32);
v15 = *(char **)(this_cle + 32);
goto LABEL_12;
}
LABEL_22:
exit(1);
}
LABEL_12:
strcpy(v15, v10);
LABEL_13:
v16 = first_cle == 0LL;
v3[6] = 0LL;
if ( v16 )
{
prev_cle = (__int64)v3;
result = 0LL;
first_cle = v3;
}
else
{
v17 = prev_cle;
prev_cle = (__int64)v3;
*(_QWORD *)(v17 + 48) = v3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
const char *v4; // r12
void *v5; // rdi
size_t v6; // rax
char *v7; // rax
char *v8; // rdi
int v9; // eax
const char *v10; // r12
__int64 v11; // xmm0_8
void *v12; // rdi
size_t v13; // rax
char *v14; // rax
char *v15; // rdi
bool v16; // zf
__int64 v17; // rax
__int64 result; // rax
size_t v19; // rax
size_t v20; // rax

v2 = calloc(1uLL, 0x38uLL);
this_cle = (__int64)v2;
if ( v2 )
{
v3 = v2;
}
else
{
wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", 1LL, 56LL, "this_cle");
if ( (unsigned int)wfdb_me_fatal() )
goto LABEL_22;
v3 = (_QWORD *)this_cle;
}
v4 = *(const char **)(a1 + 24);
if ( v4 )
{
v5 = (void *)v3[3];
if ( v5 )
{
free(v5);
v3[3] = 0LL;
v4 = *(const char **)(a1 + 24);
}
v6 = strlen(v4);
v7 = (char *)calloc(v6 + 1, 1uLL);
v3[3] = v7;
v8 = v7;
if ( !v7 )
{
v20 = strlen(v4);
wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", v20 + 1, 1LL, "this_cle->sigtype");
if ( (unsigned int)wfdb_me_fatal() )
goto LABEL_22;
v3 = (_QWORD *)this_cle;
v4 = *(const char **)(a1 + 24);
v8 = *(char **)(this_cle + 24);
}
strcpy(v8, v4);
}
v9 = *(_DWORD *)(a1 + 40);
v10 = *(const char **)(a1 + 32);
*v3 = *(_QWORD *)a1;
v11 = *(_QWORD *)(a1 + 8);
*((_DWORD *)v3 + 10) = v9;
v3[1] = v11;
v3[2] = *(_QWORD *)(a1 + 16);
if ( !v10 )
goto LABEL_13;
v12 = (void *)v3[4];
if ( v12 )
{
free(v12);
v3[4] = 0LL;
v10 = *(const char **)(a1 + 32);
}
v13 = strlen(v10);
v14 = (char *)calloc(v13 + 1, 1uLL);
v3[4] = v14;
v15 = v14;
if ( !v14 )
{
v19 = strlen(v10);
wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", v19 + 1, 1LL, "this_cle->units");
if ( !(unsigned int)wfdb_me_fatal() )
{
v3 = (_QWORD *)this_cle;
v10 = *(const char **)(a1 + 32);
v15 = *(char **)(this_cle + 32);
goto LABEL_12;
}
LABEL_22:
exit(1);
}
LABEL_12:
strcpy(v15, v10);
LABEL_13:
v16 = first_cle == 0LL;
v3[6] = 0LL;
if ( v16 )
{
prev_cle = (__int64)v3;
result = 0LL;
first_cle = v3;
}
else
{
v17 = prev_cle;
prev_cle = (__int64)v3;
*(_QWORD *)(v17 + 48) = v3;
result = 0LL;
}
return result;
}

original_code:
FINT putcal(WFDB_Calinfo *cal)
{
    { if (!(this_cle = calloc((1), (sizeof(struct cle))))) { wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", (size_t)(1), (size_t)(sizeof(struct cle)), "this_cle"); if (wfdb_me_fatal()) exit(1); }; };
    { if (cal->sigtype) { { { if (this_cle->sigtype) { free (this_cle->sigtype); this_cle->sigtype = 0; } }; { if (!(this_cle->sigtype = calloc((((size_t)strlen(cal->sigtype)+1)), ((1))))) { wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", (size_t)(((size_t)strlen(cal->sigtype)+1)), (size_t)((1)), "this_cle->sigtype"); if (wfdb_me_fatal()) exit(1); }; } }; strcpy(this_cle->sigtype, cal->sigtype); } };
    this_cle->caltype = cal->caltype;
    this_cle->low = cal->low;
    this_cle->high = cal->high;
    this_cle->scale = cal->scale;
    { if (cal->units) { { { if (this_cle->units) { free (this_cle->units); this_cle->units = 0; } }; { if (!(this_cle->units = calloc((((size_t)strlen(cal->units)+1)), ((1))))) { wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", (size_t)(((size_t)strlen(cal->units)+1)), (size_t)((1)), "this_cle->units"); if (wfdb_me_fatal()) exit(1); }; } }; strcpy(this_cle->units, cal->units); } };
    this_cle->next = ((void *)0);
    if (first_cle) {
 prev_cle->next = this_cle;
 prev_cle = this_cle;
    }
    else
 first_cle = prev_cle = this_cle;
    return (0);
}

canonical_original_code:
int putcal(struct WFDB_calinfo *cal)
{
    { if (!(this_cle = calloc((1), (sizeof(struct cle))))) { wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", (unsigned long)(1), (unsigned long)(sizeof(struct cle)), "this_cle"); if (wfdb_me_fatal()) exit(1); }; };
    { if (cal->sigtype) { { { if (this_cle->sigtype) { free (this_cle->sigtype); this_cle->sigtype = 0; } }; { if (!(this_cle->sigtype = calloc((((unsigned long)strlen(cal->sigtype)+1)), ((1))))) { wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", (unsigned long)(((unsigned long)strlen(cal->sigtype)+1)), (unsigned long)((1)), "this_cle->sigtype"); if (wfdb_me_fatal()) exit(1); }; } }; strcpy(this_cle->sigtype, cal->sigtype); } };
    this_cle->caltype = cal->caltype;
    this_cle->low = cal->low;
    this_cle->high = cal->high;
    this_cle->scale = cal->scale;
    { if (cal->units) { { { if (this_cle->units) { free (this_cle->units); this_cle->units = 0; } }; { if (!(this_cle->units = calloc((((unsigned long)strlen(cal->units)+1)), ((1))))) { wfdb_error("WFDB: can't allocate (%ld*%ld) bytes for %s\n", (unsigned long)(((unsigned long)strlen(cal->units)+1)), (unsigned long)((1)), "this_cle->units"); if (wfdb_me_fatal()) exit(1); }; } }; strcpy(this_cle->units, cal->units); } };
    this_cle->next = ((void *)0);
    if (first_cle) {
 prev_cle->next = this_cle;
 prev_cle = this_cle;
    }
    else
 first_cle = prev_cle = this_cle;
    return (0);
}

user_defined_types: struct cle { double low; double high; double scale; char *sigtype; char *units; int caltype; struct cle *next; }

user_defined_types: struct WFDB_calinfo { double low; double high; double scale; char *sigtype; char *units; int caltype; }


flushcal

decompiled_code:
void flushcal()
{
_QWORD *v0; // rbp
void *v1; // rdi
void *v2; // rdi
void *v3; // rbx

v0 = first_cle;
if ( first_cle )
{
while ( 1 )
{
v1 = (void *)v0[3];
if ( v1 )
free(v1);
v2 = (void *)v0[4];
if ( v2 )
free(v2);
this_cle = v0[6];
v3 = (void *)this_cle;
free(v0);
first_cle = v3;
if ( !v3 )
break;
v0 = v3;
}
}
}

canonical_decompiled_code:
void func3()
{
_QWORD *v0; // rbp
void *v1; // rdi
void *v2; // rdi
void *v3; // rbx

v0 = first_cle;
if ( first_cle )
{
while ( 1 )
{
v1 = (void *)v0[3];
if ( v1 )
free(v1);
v2 = (void *)v0[4];
if ( v2 )
free(v2);
this_cle = v0[6];
v3 = (void *)this_cle;
free(v0);
first_cle = v3;
if ( !v3 )
break;
v0 = v3;
}
}
}

original_code:
FVOID flushcal(void)
{
    while (first_cle) {
 { if (first_cle->sigtype) { free (first_cle->sigtype); first_cle->sigtype = 0; } };
 { if (first_cle->units) { free (first_cle->units); first_cle->units = 0; } };
 this_cle = first_cle->next;
 { if (first_cle) { free (first_cle); first_cle = 0; } };
 first_cle = this_cle;
    }
}

canonical_original_code:
void flushcal()
{
    while (first_cle) {
 { if (first_cle->sigtype) { free (first_cle->sigtype); first_cle->sigtype = 0; } };
 { if (first_cle->units) { free (first_cle->units); first_cle->units = 0; } };
 this_cle = first_cle->next;
 { if (first_cle) { free (first_cle); first_cle = 0; } };
 first_cle = this_cle;
    }
}


wfdbinit

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

result = annopen();
if ( !(_DWORD)result )
result = isigopen(a1, a4, a5);
return result;
}

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

result = annopen();
if ( !(_DWORD)result )
result = isigopen(a1, a4, a5);
return result;
}

original_code:
FINT wfdbinit(char *record, WFDB_Anninfo *aiarray, unsigned int nann,
       WFDB_Siginfo *siarray, unsigned int nsig)
{
    int stat;
    if ((stat = annopen(record, aiarray, nann)) == 0)
 stat = isigopen(record, siarray, (int)nsig);
    return (stat);
}

canonical_original_code:
int wfdbinit(char *record, struct WFDB_anninfo *aiarray, unsigned int nann, struct WFDB_siginfo *siarray, unsigned int nsig)
{
    int stat;
    if ((stat = annopen(record, aiarray, nann)) == 0)
 stat = isigopen(record, siarray, (int)nsig);
    return (stat);
}

variable_types:
record
char *

variable_types: struct WFDB_anninfo { char *name; int stat; } *

variable_types:
nann
unsigned int

variable_types: struct WFDB_siginfo { char *fname; char *desc; char *units; double gain; int initval; unsigned int group; int fmt; int spf; int bsize; int adcres; int adczero; int baseline; long nsamp; int cksum; } *

variable_types:
nsig
unsigned int

variable_types: stat int


wfdbquit

decompiled_code:
__int64 wfdbquit()
{
wfdb_anclose();
wfdb_sigclose();
return wfdb_sampquit();
}

canonical_decompiled_code:
__int64 func1()
{
wfdb_anclose();
wfdb_sigclose();
return wfdb_sampquit();
}

original_code:
FVOID wfdbquit(void)
{
    wfdb_anclose();
    wfdb_sigclose();
    wfdb_sampquit();
}

canonical_original_code:
void wfdbquit()
{
    wfdb_anclose();
    wfdb_sigclose();
    wfdb_sampquit();
}


wfdbflush

decompiled_code:
__int64 wfdbflush()
{
wfdb_oaflush();
return wfdb_osflush();
}

canonical_decompiled_code:
__int64 func2()
{
wfdb_oaflush();
return wfdb_osflush();
}

original_code:
FVOID wfdbflush(void)
{
    wfdb_oaflush();
    wfdb_osflush();
}

canonical_original_code:
void wfdbflush()
{
    wfdb_oaflush();
    wfdb_osflush();
}


decompiled_code:
void __fastcall sig_handler(int a1)
{
if ( a1 == 3 )
{
exit_func(1LL);
}
else if ( a1 == 15 || a1 == 2 )
{
exit_func(0LL);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 3 )
{
exit_func(1LL);
}
else if ( a1 == 15 || a1 == 2 )
{
exit_func(0LL);
}
}

original_code:
void sig_handler(int signal)
{
 switch (signal) {
 case 2:
 case 15:
  exit_func(0);
  break;
 case 3:
  exit_func(1);
  break;
 }
}

variable_types: signal int


decompiled_code:
__sighandler_t __fastcall sig_install(__int64 (__fastcall *a1)(_QWORD))
{
exit_func = a1;
signal(2, sig_handler);
signal(15, sig_handler);
return signal(3, sig_handler);
}

canonical_decompiled_code:
__sighandler_t __fastcall func1(__int64 (__fastcall *a1)(_QWORD))
{
exit_func = a1;
signal(2, sig_handler);
signal(15, sig_handler);
return signal(3, sig_handler);
}

original_code:
void sig_install(exit_func_t exit)
{
 exit_func = exit;
 signal(2, sig_handler);
 signal(15, sig_handler);
 signal(3, sig_handler);
}

canonical_original_code:
void sig_install(void (*exit)(_Bool))
{
 exit_func = exit;
 signal(2, sig_handler);
 signal(15, sig_handler);
 signal(3, sig_handler);
}

variable_types:
exit
void (*)(_Bool)


decompiled_code:
size_t __fastcall indent_for_tag(char *s, char *a2)
{
size_t result; // rax
int v3; // ebx

result = strlen(a2);
*s = 0;
v3 = 14 - result;
if ( 14 - (int)result > 0 )
{
do
{
result = strlen(s);
*(_WORD *)&s[result] = 32;
--v3;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *s, char *a2)
{
size_t result; // rax
int v3; // ebx

result = strlen(a2);
*s = 0;
v3 = 14 - result;
if ( 14 - (int)result > 0 )
{
do
{
result = strlen(s);
*(_WORD *)&s[result] = 32;
--v3;
}
while ( v3 );
}
return result;
}

original_code:
void indent_for_tag(char* indent, const char* tag)
{
 int tag_size = strlen(tag);
 int num_tabs = (14 - tag_size);
 strcpy(indent, "");
 while (num_tabs > 0) {
  strcat(indent, " ");
  num_tabs--;
 }
}

canonical_original_code:
void indent_for_tag(char *indent, char *tag)
{
 int tag_size = strlen(tag);
 int num_tabs = (14 - tag_size);
 strcpy(indent, "");
 while (num_tabs > 0) {
  strcat(indent, " ");
  num_tabs--;
 }
}

variable_types:
indent
char *

variable_types:
tag
char *


decompiled_code:
int log_error(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
indent_for_tag(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;31m", "E", a1, "\x1B[0m", v4, s);
}

canonical_decompiled_code:
int func1(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
func0(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;31m", "E", a1, "\x1B[0m", v4, s);
}

original_code:
void log_error(const char *tag, const char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;31m", "E", tag, "\033[0m", indent, buffer);
}

canonical_original_code:
void log_error(char *tag, char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;31m", "E", tag, "\033[0m", indent, buffer);
}

variable_types:
fmt
char *

variable_types:
buffer
char [512]

variable_types:
indent
char [32]


decompiled_code:
int log_warn(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
indent_for_tag(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;33m", "W", a1, "\x1B[0m", v4, s);
}

canonical_decompiled_code:
int func2(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
func0(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;33m", "W", a1, "\x1B[0m", v4, s);
}

original_code:
void log_warn(const char *tag, const char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;33m", "W", tag, "\033[0m", indent, buffer);
}

canonical_original_code:
void log_warn(char *tag, char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;33m", "W", tag, "\033[0m", indent, buffer);
}


decompiled_code:
int log_info(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
indent_for_tag(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;32m", "I", a1, "\x1B[0m", v4, s);
}

canonical_decompiled_code:
int func3(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
func0(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;32m", "I", a1, "\x1B[0m", v4, s);
}

original_code:
void log_info(const char *tag, const char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;32m", "I", tag, "\033[0m", indent, buffer);
}

canonical_original_code:
void log_info(char *tag, char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;32m", "I", tag, "\033[0m", indent, buffer);
}


decompiled_code:
int log_debug(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
indent_for_tag(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;35m", "D", a1, "\x1B[0m", v4, s);
}

canonical_decompiled_code:
int func4(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
func0(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;35m", "D", a1, "\x1B[0m", v4, s);
}

original_code:
void log_debug(const char *tag, const char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;35m", "D", tag, "\033[0m", indent, buffer);
}

canonical_original_code:
void log_debug(char *tag, char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;35m", "D", tag, "\033[0m", indent, buffer);
}


decompiled_code:
int log_session(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
indent_for_tag(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;34m", "S", a1, "\x1B[0m", v4, s);
}

canonical_decompiled_code:
int func5(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-300h] BYREF
char v4[32]; // [rsp+20h] [rbp-2E8h] BYREF
char s[512]; // [rsp+40h] [rbp-2C8h] BYREF

va_start(arg, a2);
s[0] = 0;
vsprintf(s, a2, arg);
func0(v4, a1);
return fprintf(stderr, "%s%s/%s%s: %s%s\n", "\x1B[1;34m", "S", a1, "\x1B[0m", v4, s);
}

original_code:
void log_session(const char *tag, const char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;34m", "S", tag, "\033[0m", indent, buffer);
}

canonical_original_code:
void log_session(char *tag, char *fmt, ...)
{
 char buffer[512];
 strcpy(buffer, "");
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(buffer, fmt, args);
 __builtin_va_end(args);
 char indent[32];
 indent_for_tag(indent, tag);
 fprintf(stderr, "%s%s/%s%s: %s%s\n", "\033[1;34m", "S", tag, "\033[0m", indent, buffer);
}


decompiled_code:
int print_version()
{
return printf("Geilinor Emulator v%d.%d.%d (gem)\n", 1LL, 1LL, 0LL);
}

canonical_decompiled_code:
int func0()
{
return printf("Geilinor Emulator v%d.%d.%d (gem)\n", 1LL, 1LL, 0LL);
}

original_code:
void print_version()
{
 printf("Geilinor Emulator v%d.%d.%d (gem)\n", 1, 1, 0);
}


decompiled_code:
int print_usage()
{
print_version();
return puts(
"Usage: gem [OPTION]\n"
"\n"
"Optional arguments:\n"
" -b, --bind <address>\t\tspecify the bind address\n"
" -d, --data <directory>\tspecify the game data directory\n"
" -c, --content <directory>\tspecify the content (python script) directory\n"
" --verbose\t\t\tturn on verbose logging\n"
"\n"
" -v, --version\t\toutput version information and exit\n"
" -h, --help\t\tdisplay this help and exit");
}

canonical_decompiled_code:
int func1()
{
func0();
return puts(
"Usage: gem [OPTION]\n"
"\n"
"Optional arguments:\n"
" -b, --bind <address>\t\tspecify the bind address\n"
" -d, --data <directory>\tspecify the game data directory\n"
" -c, --content <directory>\tspecify the content (python script) directory\n"
" --verbose\t\t\tturn on verbose logging\n"
"\n"
" -v, --version\t\toutput version information and exit\n"
" -h, --help\t\tdisplay this help and exit");
}

original_code:
void print_usage()
{
 print_version();
 printf("Usage: gem [OPTION]\n\n"
     "Optional arguments:\n"
     "  -b, --bind <address>\t\tspecify the bind address\n"
     "  -d, --data <directory>\tspecify the game data directory\n"
     "  -c, --content <directory>\tspecify the content (python script) directory\n"
     "      --verbose\t\t\tturn on verbose logging\n\n"
     "  -v, --version\t\toutput version information and exit\n"
     "  -h, --help\t\tdisplay this help and exit\n");
}


decompiled_code:
int __fastcall parse_args(int argc, char **argv)
{
int result; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*(_QWORD *)&inst_args[4] = 0x302E302E302E30LL;
*(_QWORD *)&inst_args[20] = 0x65686361632F2E2ELL;
*(_QWORD *)&inst_args[276] = 0x6E65746E6F632F2ELL;
*(_DWORD *)inst_args = 1;
inst_args[28] = 0;
strcpy(&inst_args[284], "t/");
while ( 1 )
{
longind[0] = 0;
result = getopt_long(argc, argv, "vhb:c:C:", &program_options, longind);
if ( result < 0 )
return result;
switch ( result )
{
case 'b':
strcpy((char *)(unsigned int)((_DWORD)inst_args + 4), optarg);
break;
case 'c':
strcpy((char *)(unsigned int)((_DWORD)inst_args + 276), optarg);
break;
case 'd':
strcpy((char *)(unsigned int)((_DWORD)inst_args + 20), optarg);
break;
case 'h':
print_usage();
exit(1);
case 'v':
print_version();
exit(0);
default:
continue;
}
}
}

canonical_decompiled_code:
int __fastcall func2(int argc, char **argv)
{
int result; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*(_QWORD *)&inst_args[4] = 0x302E302E302E30LL;
*(_QWORD *)&inst_args[20] = 0x65686361632F2E2ELL;
*(_QWORD *)&inst_args[276] = 0x6E65746E6F632F2ELL;
*(_DWORD *)inst_args = 1;
inst_args[28] = 0;
strcpy(&inst_args[284], "t/");
while ( 1 )
{
longind[0] = 0;
result = getopt_long(argc, argv, "vhb:c:C:", &program_options, longind);
if ( result < 0 )
return result;
switch ( result )
{
case 'b':
strcpy((char *)(unsigned int)((_DWORD)inst_args + 4), optarg);
break;
case 'c':
strcpy((char *)(unsigned int)((_DWORD)inst_args + 276), optarg);
break;
case 'd':
strcpy((char *)(unsigned int)((_DWORD)inst_args + 20), optarg);
break;
case 'h':
func1();
exit(1);
case 'v':
func0();
exit(0);
default:
continue;
}
}
}

original_code:
void parse_args(int argc, char **argv)
{
 int c = 0;
 inst_args.verbose_on = 1;
 strcpy(inst_args.bind_addr, "0.0.0.0");
 strcpy(inst_args.cache_dir, "../cache");
 strcpy(inst_args.content_dir, "./content/");
 while (c >= 0) {
  int option_index = 0;
  c = getopt_long(argc, argv, "vhb:c:C:", program_options, &option_index);
  if (c < 0) {
   break;
  }
  switch (c) {
  case 'v':
   print_version();
   exit(0);
   break;
  case 'h':
   print_usage();
   exit(1);
   break;
  case 'b':
   strcpy(inst_args.bind_addr, optarg);
   break;
  case 'd':
   strcpy(inst_args.cache_dir, optarg);
   break;
  case 'c':
   strcpy(inst_args.content_dir, optarg);
   break;
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int


sector

decompiled_code:
unsigned __int64 __fastcall sector(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

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

original_code:
sector_t sector(int x, int y, int z)
{
 sector_t sector = { .x = x, .y = y, .z = z };
 return sector;
}

canonical_original_code:
struct sector sector(int x, int y, int z)
{
 struct sector sector = { .x = x, .y = y, .z = z };
 return sector;
}

variable_types: x int

variable_types: y int

variable_types: z int

variable_types:
sector
struct sector { int x; int y; int z; }

return_type: struct sector { int x; int y; int z; }


decompiled_code:
__int64 __fastcall to_absolute_coord(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, int a9)
{
__int64 v9; // r11

absolute_coord(a1, a7 + 8 * HIDWORD(a8), HIDWORD(a7) + 8 * a9);
return v9;
}

original_code:
location_t to_absolute_coord(region_local_t local)
{
 int x = local.x + (8 * local.region.base.x);
 int y = local.y + (8 * local.region.base.y);
 return absolute_coord(x, y, local.z);
}

canonical_original_code:
struct location to_absolute_coord(struct region_local local)
{
 int x = local.x + (8 * local.region.base.x);
 int y = local.y + (8 * local.region.base.y);
 return absolute_coord(x, y, local.z);
}

variable_types: struct region_local { int x; int y; int z; struct region { struct sector base; } region; }

return_type: struct location { int x; int y; int z; struct sector { int x; int y; int z; } sector; }

user_defined_types: struct region_local { int x; int y; int z; struct region region; }

user_defined_types: struct location { int x; int y; int z; struct sector sector; }


decompiled_code:
__int64 __fastcall center_region_on(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8, int a9)
{
__int64 v10; // [rsp+0h] [rbp-14h]

LODWORD(v10) = HIDWORD(a8) - 6;
HIDWORD(v10) = a9 - 6;
return v10;
}

original_code:
region_t center_region_on(location_t location)
{
 region_t region;
 region.base.x = location.sector.x - ((13 - 1) / 2);
 region.base.y = location.sector.y - ((13 - 1) / 2);
 region.base.z = location.sector.z;
 return region;
}

canonical_original_code:
struct region center_region_on(struct location location)
{
 struct region region;
 region.base.x = location.sector.x - ((13 - 1) / 2);
 region.base.y = location.sector.y - ((13 - 1) / 2);
 region.base.z = location.sector.z;
 return region;
}

variable_types: struct location { int x; int y; int z; struct sector sector; }

variable_types: struct region { struct sector { int x; int y; int z; } base; }


decompiled_code:
unsigned __int64 __fastcall jstring_encode(const char *a1)
{
size_t v2; // rax
size_t v3; // rcx
unsigned __int64 v4; // rdx
size_t v5; // rdi
char v6; // al

v2 = strlen(a1);
v3 = 0LL;
v4 = 0LL;
v5 = v2;
while ( v5 > v3 && v3 != 12 )
{
v4 *= 37LL;
v6 = a1[v3];
if ( (unsigned __int8)(v6 - 65) <= 0x19u )
{
v4 += (char)(v6 - 64);
}
else if ( (unsigned __int8)(v6 - 97) > 0x19u )
{
if ( (unsigned __int8)(v6 - 48) <= 9u )
v4 += (char)(v6 - 21);
}
else
{
v4 += (char)(v6 - 96);
}
++v3;
}
for ( ; 0x14C1BACF914C1BADLL * v4 <= 0x6EB3E45306EB3E4LL && v4; v4 /= 0x25uLL )
;
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1)
{
size_t v2; // rax
size_t v3; // rcx
unsigned __int64 v4; // rdx
size_t v5; // rdi
char v6; // al

v2 = strlen(a1);
v3 = 0LL;
v4 = 0LL;
v5 = v2;
while ( v5 > v3 && v3 != 12 )
{
v4 *= 37LL;
v6 = a1[v3];
if ( (unsigned __int8)(v6 - 65) <= 0x19u )
{
v4 += (char)(v6 - 64);
}
else if ( (unsigned __int8)(v6 - 97) > 0x19u )
{
if ( (unsigned __int8)(v6 - 48) <= 9u )
v4 += (char)(v6 - 21);
}
else
{
v4 += (char)(v6 - 96);
}
++v3;
}
for ( ; 0x14C1BACF914C1BADLL * v4 <= 0x6EB3E45306EB3E4LL && v4; v4 /= 0x25uLL )
;
return v4;
}

original_code:
long jstring_encode(char* s) {
 long encoded = 0;
 for (size_t i = 0; i < strlen(s) && i < 12; i++) {
  encoded *= 37;
  if (s[i] >= 'A' && s[i] <= 'Z') {
   encoded += (1 + s[i]) - 65;
  } else if (s[i] >= 'a' && s[i] <= 'z') {
   encoded += (1 + s[i]) - 97;
  } else if (s[i] >= '0' && s[i] <= '9') {
   encoded += (27 + s[i]) - 48;
  }
 }
 while (encoded % 37 == 0 && encoded != 0) {
  encoded /= 37;
 }
 return encoded;
}

canonical_original_code:
long jstring_encode(char *s) {
 long encoded = 0;
 for (unsigned long i = 0; i < strlen(s) && i < 12; i++) {
  encoded *= 37;
  if (s[i] >= 'A' && s[i] <= 'Z') {
   encoded += (1 + s[i]) - 65;
  } else if (s[i] >= 'a' && s[i] <= 'z') {
   encoded += (1 + s[i]) - 97;
  } else if (s[i] >= '0' && s[i] <= '9') {
   encoded += (27 + s[i]) - 48;
  }
 }
 while (encoded % 37 == 0 && encoded != 0) {
  encoded /= 37;
 }
 return encoded;
}

variable_types:
s
char *

variable_types: encoded long

variable_types:
i
unsigned long

return_type: long


decompiled_code:
__int64 __fastcall jstring_decode(unsigned __int64 a1, char *a2)
{
unsigned __int64 v2; // rdx
char *v3; // rsi
unsigned __int64 v4; // rcx
__int64 result; // rax

v2 = a1;
if ( a1 - 1 > 0x5B5B57F8A98A5DCFLL || 0x14C1BACF914C1BADLL * a1 + 0x3759F22983759F2LL <= 0x6EB3E45306EB3E4LL )
{
result = 0x5F64696C61766E69LL;
strcpy(a2, "invalid_name");
}
else
{
v3 = a2 + 11;
do
{
v4 = v2;
--v3;
v2 /= 0x25uLL;
result = (unsigned __int8)enc_table[v4 - 37 * v2];
v3[1] = result;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, char *a2)
{
unsigned __int64 v2; // rdx
char *v3; // rsi
unsigned __int64 v4; // rcx
__int64 result; // rax

v2 = a1;
if ( a1 - 1 > 0x5B5B57F8A98A5DCFLL || 0x14C1BACF914C1BADLL * a1 + 0x3759F22983759F2LL <= 0x6EB3E45306EB3E4LL )
{
result = 0x5F64696C61766E69LL;
strcpy(a2, "invalid_name");
}
else
{
v3 = a2 + 11;
do
{
v4 = v2;
--v3;
v2 /= 0x25uLL;
result = (unsigned __int8)enc_table[v4 - 37 * v2];
v3[1] = result;
}
while ( v2 );
}
return result;
}

original_code:
void jstring_decode(long l, char* buf) {
 if (l <= 0 || l >= 0x5b5b57f8a98a5dd1) {
  strcpy(buf, "invalid_name");
  return;
 }
 if (!(l % 37)) {
  strcpy(buf, "invalid_name");
  return;
 }
 int i = 0;
 while (l) {
  long tmp = l;
  l /= 37;
  buf[11 - i++] = enc_table[tmp - (l * 37)];
 }
}

canonical_original_code:
void jstring_decode(long l, char *buf) {
 if (l <= 0 || l >= 0x5b5b57f8a98a5dd1) {
  strcpy(buf, "invalid_name");
  return;
 }
 if (!(l % 37)) {
  strcpy(buf, "invalid_name");
  return;
 }
 int i = 0;
 while (l) {
  long tmp = l;
  l /= 37;
  buf[11 - i++] = enc_table[tmp - (l * 37)];
 }
}

variable_types: l long

variable_types:
buf
char *

variable_types: i int

variable_types: tmp long


decompiled_code:
__int64 __fastcall packet_lookup(int a1, int a2)
{
_DWORD *v3; // rcx
_DWORD *v4; // rax
int v5; // edx

if ( a1 )
{
if ( a1 != 1 )
return pkt_null;
v3 = &packet_table_out;
}
else
{
v3 = &packet_table_in;
}
if ( *v3 != -1 )
{
v4 = v3 + 3;
if ( a2 != *v3 )
{
do
{
v5 = *v4;
v3 = v4;
v4 += 3;
}
while ( v5 != -1 && v5 != a2 );
}
}
return *(_QWORD *)v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
_DWORD *v3; // rcx
_DWORD *v4; // rax
int v5; // edx

if ( a1 )
{
if ( a1 != 1 )
return pkt_null;
v3 = &packet_table_out;
}
else
{
v3 = &packet_table_in;
}
if ( *v3 != -1 )
{
v4 = v3 + 3;
if ( a2 != *v3 )
{
do
{
v5 = *v4;
v3 = v4;
v4 += 3;
}
while ( v5 != -1 && v5 != a2 );
}
}
return *(_QWORD *)v3;
}

original_code:
packet_def_t packet_lookup(int type, int opcode)
{
 packet_def_t* lookup_table;
 switch (type) {
 case 0:
  lookup_table = packet_table_in;
  break;
 case 1:
  lookup_table = packet_table_out;
  break;
 default:
  return pkt_null;
 }
 for (int i = 0; ; i++) {
  if (lookup_table[i].opcode == opcode || lookup_table[i].opcode == -1) {
   return lookup_table[i];
  }
 }
 return pkt_null;
}

canonical_original_code:
struct packet_def packet_lookup(int type, int opcode)
{
 struct packet_def *lookup_table;
 switch (type) {
 case 0:
  lookup_table = packet_table_in;
  break;
 case 1:
  lookup_table = packet_table_out;
  break;
 default:
  return pkt_null;
 }
 for (int i = 0; ; i++) {
  if (lookup_table[i].opcode == opcode || lookup_table[i].opcode == -1) {
   return lookup_table[i];
  }
 }
 return pkt_null;
}

variable_types: type int

variable_types: opcode int

variable_types: struct packet_def { int opcode; int type; int len; } *


decompiled_code:
__int64 __fastcall reflect_get(__int64 a1, const char **a2, const char *a3)
{
const char *v4; // rdi
const char **v5; // rbx
const char *v7; // rax
__int64 result; // rax

v4 = *a2;
if ( !*a2 )
goto LABEL_7;
v5 = a2;
while ( strcmp(v4, a3) )
{
v4 = v5[4];
v5 += 4;
if ( !v4 )
goto LABEL_7;
}
v7 = v5[1];
if ( v7 )
result = ((__int64 (__fastcall *)(__int64, const char *))v7)(a1, v5[3]);
else
LABEL_7:
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char **a2, const char *a3)
{
const char *v4; // rdi
const char **v5; // rbx
const char *v7; // rax
__int64 result; // rax

v4 = *a2;
if ( !*a2 )
goto LABEL_7;
v5 = a2;
while ( strcmp(v4, a3) )
{
v4 = v5[4];
v5 += 4;
if ( !v4 )
goto LABEL_7;
}
v7 = v5[1];
if ( v7 )
result = ((__int64 (__fastcall *)(__int64, const char *))v7)(a1, v5[3]);
else
LABEL_7:
result = 0LL;
return result;
}

original_code:
void* reflect_get(void* self, ref_table_entry_t* table, const char* identifier)
{
 ref_table_entry_t* entry = (ref_table_entry_t*)table;
 ref_table_get_t* get_func = ((void *)0);
 void* extra;
 while (entry->identifier != ((void *)0)) {
  if (strcmp(entry->identifier, identifier) == 0) {
   get_func = entry->get_func;
   extra = entry->extra;
   break;
  }
  ++entry;
 }
 if (!get_func) {
  return ((void *)0);
 }
 return get_func(self, extra);
}

canonical_original_code:
void *reflect_get(void *self, struct ref_table_entry *table, char *identifier)
{
 struct ref_table_entry *entry = (ref_table_entry_t*)table;
 void *(*get_func)(void *self, void *extra) = ((void *)0);
 void *extra;
 while (entry->identifier != ((void *)0)) {
  if (strcmp(entry->identifier, identifier) == 0) {
   get_func = entry->get_func;
   extra = entry->extra;
   break;
  }
  ++entry;
 }
 if (!get_func) {
  return ((void *)0);
 }
 return get_func(self, extra);
}

variable_types:
self
void *

variable_types: struct ref_table_entry { char *identifier; void *(*get_func)(void *self, void *extra); int (*set_func)(void *self, void *value, void *extra); void *extra; } *

variable_types:
identifier
char *

variable_types:
extra
void *

return_type: void *


decompiled_code:
__int64 __fastcall reflect_set(__int64 a1, const char **a2, const char *a3, __int64 a4)
{
const char *v5; // rdi
const char **v6; // rbx
const char *v9; // rax
__int64 result; // rax

v5 = *a2;
if ( !*a2 )
goto LABEL_7;
v6 = a2;
while ( strcmp(v5, a3) )
{
v5 = v6[4];
v6 += 4;
if ( !v5 )
goto LABEL_7;
}
v9 = v6[2];
if ( v9 )
result = ((__int64 (__fastcall *)(__int64, __int64, const char *))v9)(a1, a4, v6[3]);
else
LABEL_7:
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char **a2, const char *a3, __int64 a4)
{
const char *v5; // rdi
const char **v6; // rbx
const char *v9; // rax
__int64 result; // rax

v5 = *a2;
if ( !*a2 )
goto LABEL_7;
v6 = a2;
while ( strcmp(v5, a3) )
{
v5 = v6[4];
v6 += 4;
if ( !v5 )
goto LABEL_7;
}
v9 = v6[2];
if ( v9 )
result = ((__int64 (__fastcall *)(__int64, __int64, const char *))v9)(a1, a4, v6[3]);
else
LABEL_7:
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int reflect_set(void* self, ref_table_entry_t* table, const char* identifier, void* value)
{
 ref_table_entry_t* entry = (ref_table_entry_t*)table;
 ref_table_set_t* set_func = ((void *)0);
 void* extra;
 while (entry->identifier != ((void *)0)) {
  if (strcmp(entry->identifier, identifier) == 0) {
   set_func = entry->set_func;
   extra = entry->extra;
   break;
  }
  ++entry;
 }
 if (!set_func) {
  return -1;
 }
 return set_func(self, value, extra);
}

canonical_original_code:
int reflect_set(void *self, struct ref_table_entry *table, char *identifier, void *value)
{
 struct ref_table_entry *entry = (ref_table_entry_t*)table;
 int (*set_func)(void *self, void *value, void *extra) = ((void *)0);
 void *extra;
 while (entry->identifier != ((void *)0)) {
  if (strcmp(entry->identifier, identifier) == 0) {
   set_func = entry->set_func;
   extra = entry->extra;
   break;
  }
  ++entry;
 }
 if (!set_func) {
  return -1;
 }
 return set_func(self, value, extra);
}

variable_types:
value
void *

variable_types: int (*)(void *self, void *value, void *extra)

user_defined_types: struct ref_table_entry { char *identifier; void *(*get_func)(void *self, void *extra); int (*set_func)(void *self, void *value, void *extra); void *extra; }


decompiled_code:
__int64 script_free()
{
hook_free();
return Py_Finalize();
}

canonical_decompiled_code:
__int64 func1()
{
hook_free();
return Py_Finalize();
}

original_code:
void script_free()
{
 hook_free();
 Py_Finalize();
}


decompiled_code:
__int64 item_def_load()
{
__int64 v0; // rax
int v1; // edx

v0 = (unsigned int)((_DWORD)&item_database + 4);
v1 = 0;
do
{
*(_DWORD *)(v0 - 4) = v1++;
v0 += 112LL;
*(_DWORD *)(v0 - 48) = 1;
strcpy((char *)(v0 - 112), "Unknown item");
}
while ( v1 != 7000 );
return 7000LL;
}

original_code:
int item_def_load()
{
 for (int i = 0; i < 7000; i++) {
  item_database[i].id = i;
  item_database[i].equip_slot = 1;
  strcpy(item_database[i].name, "Unknown item");
 }
 return 7000;
}


decompiled_code:
__int64 __fastcall queue_free(__int64 a1)
{
return object_free(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return object_free(a1 + 24);
}

original_code:
static void queue_free(queue_t* queue)
{
 _object_free((object_t*)&queue->list);;
}

canonical_original_code:
static void queue_free(struct queue *queue)
{
 _object_free((struct object *)&queue->list);;
}

variable_types: struct queue { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; struct list { struct object object; struct list_node { struct list_node *prev; struct list_node *next; } *top; struct list_node *bottom; } list; } *

user_defined_types: struct queue { struct object object; struct list list; }

user_defined_types: struct object { struct object_proto prototype; _Bool must_free; }

user_defined_types: struct list { struct object object; struct list_node *top; struct list_node *bottom; }


decompiled_code:
__int64 __fastcall queue_init(__int64 a1)
{
return object_init(list_proto[0], list_proto[1], a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return object_init(list_proto[0], list_proto[1], a1 + 24);
}

original_code:
static void queue_init(queue_t* queue)
{
 _object_init(list_proto, (object_t*)&queue->list);
}

canonical_original_code:
static void queue_init(struct queue *queue)
{
 _object_init(list_proto, (struct object *)&queue->list);
}

user_defined_types: struct object_proto { void (*init)(void *); void (*free)(void *); }

user_defined_types: struct list_node { struct list_node *prev; struct list_node *next; }


decompiled_code:
__int64 __fastcall queue_push(__int64 a1, __int64 a2)
{
if ( !a2 )
_assert_fail("item != NULL", "src/util/queue.c", 0x31u, "queue_push");
return list_push_front(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
if ( !a2 )
_assert_fail("item != NULL", "src/util/queue.c", 0x31u, "queue_push");
return list_push_front(a1 + 24);
}

original_code:
void queue_push(queue_t* queue, list_node_t* item)
{
 ((void) sizeof ((item != ((void *)0)) ? 1 : 0), __extension__ ({ if (item != ((void *)0)) ; else __assert_fail ("item != NULL", "src/util/queue.c", 49, __extension__ __PRETTY_FUNCTION__); }));
 list_push_front(&queue->list, item);
}

canonical_original_code:
void queue_push(struct queue *queue, struct list_node *item)
{
 ((void) sizeof ((item != ((void *)0)) ? 1 : 0), __extension__ ({ if (item != ((void *)0)) ; else __assert_fail ("item != NULL", "src/util/queue.c", 49, __extension__ __PRETTY_FUNCTION__); }));
 list_push_front(&queue->list, item);
}

variable_types:
item
struct list_node *


decompiled_code:
__int64 __fastcall queue_pop(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = list_back(a1 + 24);
if ( !v1 )
_assert_fail("node != NULL", "src/util/queue.c", 0x3Bu, "queue_pop");
v2 = v1;
list_erase(a1 + 24, v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = list_back(a1 + 24);
if ( !v1 )
_assert_fail("node != NULL", "src/util/queue.c", 0x3Bu, "queue_pop");
v2 = v1;
list_erase(a1 + 24, v1);
return v2;
}

original_code:
list_node_t* queue_pop(queue_t* queue)
{
 list_node_t* node = list_back(&queue->list);
 ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/util/queue.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 list_erase(&queue->list, node);
 return node;
}

canonical_original_code:
struct list_node *queue_pop(struct queue *queue)
{
 struct list_node *node = list_back(&queue->list);
 ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/util/queue.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 list_erase(&queue->list, node);
 return node;
}

variable_types: struct queue { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; struct list { struct object object; struct list_node *top; struct list_node *bottom; } list; } *

variable_types: struct list_node { struct list_node *prev; struct list_node *next; } *


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

result = list_back(a1 + 24);
if ( !result )
_assert_fail("node != NULL", "src/util/queue.c", 0x46u, "queue_peek");
return result;
}

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

result = list_back(a1 + 24);
if ( !result )
_assert_fail("node != NULL", "src/util/queue.c", 0x46u, "queue_peek");
return result;
}

original_code:
list_node_t* queue_peek(queue_t* queue)
{
 list_node_t* node = list_back(&queue->list);
 ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/util/queue.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 return node;
}

canonical_original_code:
struct list_node *queue_peek(struct queue *queue)
{
 struct list_node *node = list_back(&queue->list);
 ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/util/queue.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 return node;
}

return_type: struct list_node { struct list_node *prev; struct list_node *next; } *


decompiled_code:
__int64 __fastcall queue_empty(__int64 a1)
{
return list_empty(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return list_empty(a1 + 24);
}

original_code:
_Bool queue_empty(queue_t* queue)
{
 return list_empty(&queue->list);
}

canonical_original_code:
_Bool queue_empty(struct queue *queue)
{
 return list_empty(&queue->list);
}


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

while ( 1 )
{
result = queue_empty(a1);
if ( (_BYTE)result )
break;
queue_pop(a1);
}
return result;
}

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

while ( 1 )
{
result = func5(a1);
if ( (_BYTE)result )
break;
func3(a1);
}
return result;
}

original_code:
void queue_clear(queue_t* queue)
{
 while (!queue_empty(queue)) {
  queue_pop(queue);
 }
}

canonical_original_code:
void queue_clear(struct queue *queue)
{
 while (!queue_empty(queue)) {
  queue_pop(queue);
 }
}


decompiled_code:
void __fastcall list_init(__int64 a1)
{
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
}

original_code:
static void list_init(list_t* list)
{
 list->top = list->bottom = (list_node_t*)((void *)0);
}

canonical_original_code:
static void list_init(struct list *list)
{
 list->top = list->bottom = (struct list_node *)((void *)0);
}

variable_types: struct list { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; struct list_node { struct list_node *prev; struct list_node *next; } *top; struct list_node *bottom; } *


decompiled_code:
void list_free()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static void list_free(list_t* list)
{
}

canonical_original_code:
static void list_free(struct list *list)
{
}


decompiled_code:
bool __fastcall list_empty(__int64 a1)
{
bool result; // al

result = 0;
if ( !*(_QWORD *)(a1 + 24) )
result = *(_QWORD *)(a1 + 32) == 0LL;
return result;
}

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

result = 0;
if ( !*(_QWORD *)(a1 + 24) )
result = *(_QWORD *)(a1 + 32) == 0LL;
return result;
}

original_code:
_Bool list_empty(list_t* list)
{
 return list->top == (list_node_t*)((void *)0) && list->bottom == (list_node_t*)((void *)0);
}

canonical_original_code:
_Bool list_empty(struct list *list)
{
 return list->top == (struct list_node *)((void *)0) && list->bottom == (struct list_node *)((void *)0);
}


decompiled_code:
char __fastcall list_push_front(__int64 a1, _QWORD *a2)
{
char result; // al
_QWORD *v3; // rdx

result = list_empty(a1);
if ( !result )
return list_insert_before(a1, *(__int64 **)(a1 + 24), v3);
*(_QWORD *)(a1 + 32) = a2;
*(_QWORD *)(a1 + 24) = a2;
*a2 = 0LL;
a2[1] = 0LL;
return result;
}

canonical_decompiled_code:
char __fastcall func4(__int64 a1, _QWORD *a2)
{
char result; // al
_QWORD *v3; // rdx

result = func2(a1);
if ( !result )
return func3(a1, *(__int64 **)(a1 + 24), v3);
*(_QWORD *)(a1 + 32) = a2;
*(_QWORD *)(a1 + 24) = a2;
*a2 = 0LL;
a2[1] = 0LL;
return result;
}

original_code:
void list_push_front(list_t* list, list_node_t* node)
{
 if (list_empty(list)) {
  list->top = list->bottom = node;
  node->next = node->prev = (list_node_t*)((void *)0);
 } else {
  list_insert_before(list, list->top, node);
 }
}

canonical_original_code:
void list_push_front(struct list *list, struct list_node *node)
{
 if (list_empty(list)) {
  list->top = list->bottom = node;
  node->next = node->prev = (struct list_node *)((void *)0);
 } else {
  list_insert_before(list, list->top, node);
 }
}

variable_types:
node
struct list_node *


decompiled_code:
__int64 __fastcall list_back(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
list_node_t* list_back(list_t* list)
{
 return list->bottom;
}

canonical_original_code:
struct list_node *list_back(struct list *list)
{
 return list->bottom;
}

variable_types: struct list { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; struct list_node *top; struct list_node *bottom; } *


decompiled_code:
__int64 __fastcall list_front(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
list_node_t* list_front(list_t* list)
{
 return list->top;
}

canonical_original_code:
struct list_node *list_front(struct list *list)
{
 return list->top;
}


decompiled_code:
__int64 __fastcall list_count(__int64 a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = list_front(a1);
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = func7(a1);
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
int list_count(list_t* list)
{
 list_node_t* node = list_front(list);
 int count = 0;
 while (node != 0) {
  count++;
  node = node->next;
 }
 return count;
}

canonical_original_code:
int list_count(struct list *list)
{
 struct list_node *node = list_front(list);
 int count = 0;
 while (node != 0) {
  count++;
  node = node->next;
 }
 return count;
}

variable_types: count int


decompiled_code:
__int64 __fastcall archive_free(__int64 a1)
{
return object_free(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return object_free(a1 + 32);
}

original_code:
static void archive_free(archive_t* archive)
{
 _object_free((object_t*)&archive->files);;
}

canonical_original_code:
static void archive_free(struct archive *archive)
{
 _object_free((struct object *)&archive->files);;
}

variable_types: struct archive { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; unsigned short num_files; struct list { struct object object; struct list_node { struct list_node *prev; struct list_node *next; } *top; struct list_node *bottom; } files; } *

user_defined_types: struct archive { struct object object; unsigned short num_files; struct list files; }


decompiled_code:
__int64 __fastcall bz2_headerless_decompress(void *src, size_t n, __int64 a3, int *a4)
{
int v6; // er8
__int64 result; // rax
_DWORD *v8; // rax
void *v9; // r12
int v10; // eax
int v11; // eax
void *v12; // [rsp+0h] [rbp-88h] BYREF
int v13; // [rsp+8h] [rbp-80h]
__int64 v14; // [rsp+18h] [rbp-70h]
int v15; // [rsp+20h] [rbp-68h]
int v16; // [rsp+24h] [rbp-64h]
__int64 v17; // [rsp+38h] [rbp-50h]
__int64 v18; // [rsp+40h] [rbp-48h]
__int64 v19; // [rsp+48h] [rbp-40h]

v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v6 = BZ2_bzDecompressInit(&v12, 0LL, 0LL);
result = 0LL;
if ( !v6 )
{
v8 = malloc((unsigned int)(n + 4));
*v8 = 828922434;
v9 = v8;
memcpy(v8 + 1, src, (unsigned int)n);
v10 = *a4;
v12 = v9;
v13 = n + 4;
v14 = a3;
v15 = v10;
while ( 1 )
{
v11 = BZ2_bzDecompress(&v12);
if ( (v11 & 0xFFFFFFFB) != 0 )
break;
if ( v11 == 4 )
{
*a4 = v16;
free(v9);
BZ2_bzDecompressEnd(&v12);
return 1LL;
}
}
free(v9);
BZ2_bzDecompressEnd(&v12);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, size_t n, __int64 a3, int *a4)
{
int v6; // er8
__int64 result; // rax
_DWORD *v8; // rax
void *v9; // r12
int v10; // eax
int v11; // eax
void *v12; // [rsp+0h] [rbp-88h] BYREF
int v13; // [rsp+8h] [rbp-80h]
__int64 v14; // [rsp+18h] [rbp-70h]
int v15; // [rsp+20h] [rbp-68h]
int v16; // [rsp+24h] [rbp-64h]
__int64 v17; // [rsp+38h] [rbp-50h]
__int64 v18; // [rsp+40h] [rbp-48h]
__int64 v19; // [rsp+48h] [rbp-40h]

v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v6 = BZ2_bzDecompressInit(&v12, 0LL, 0LL);
result = 0LL;
if ( !v6 )
{
v8 = malloc((unsigned int)(n + 4));
*v8 = 828922434;
v9 = v8;
memcpy(v8 + 1, src, (unsigned int)n);
v10 = *a4;
v12 = v9;
v13 = n + 4;
v14 = a3;
v15 = v10;
while ( 1 )
{
v11 = BZ2_bzDecompress(&v12);
if ( (v11 & 0xFFFFFFFB) != 0 )
break;
if ( v11 == 4 )
{
*a4 = v16;
free(v9);
BZ2_bzDecompressEnd(&v12);
return 1LL;
}
}
free(v9);
BZ2_bzDecompressEnd(&v12);
result = 0LL;
}
return result;
}

original_code:
static _Bool bz2_headerless_decompress(unsigned char* src, uint32_t src_len, unsigned char* dest, uint32_t* dest_len)
{
 bz_stream stream;
 stream.bzalloc = ((void *)0);
 stream.bzfree = ((void *)0);
 stream.opaque = ((void *)0);
 int ret = BZ2_bzDecompressInit(&stream, 0, 0);
 if (ret != 0) {
  return 0;
 }
 unsigned char* bz2_data = (unsigned char*)malloc(src_len+4);
 bz2_data[0] = 'B';
 bz2_data[1] = 'Z';
 bz2_data[2] = 'h';
 bz2_data[3] = '1';
 memcpy(bz2_data+4, src, src_len);
 stream.next_in = (char*)bz2_data;
 stream.avail_in = src_len+4;
 stream.next_out = (char*)dest;
 stream.avail_out = *dest_len;
 while (ret != 4) {
  ret = BZ2_bzDecompress(&stream);
  if (ret != 0 && ret != 4) {
   goto error;
  }
 }
 *dest_len = stream.total_out_lo32;
 goto success;
error:
 free(bz2_data);
 BZ2_bzDecompressEnd(&stream);
 return 0;
success:
 free(bz2_data);
 BZ2_bzDecompressEnd(&stream);
 return 1;
}

canonical_original_code:
static _Bool bz2_headerless_decompress(unsigned char *src, unsigned int src_len, unsigned char *dest, unsigned int *dest_len)
{
 struct bz_stream stream;
 stream.bzalloc = ((void *)0);
 stream.bzfree = ((void *)0);
 stream.opaque = ((void *)0);
 int ret = BZ2_bzDecompressInit(&stream, 0, 0);
 if (ret != 0) {
  return 0;
 }
 unsigned char *bz2_data = (unsigned char*)malloc(src_len+4);
 bz2_data[0] = 'B';
 bz2_data[1] = 'Z';
 bz2_data[2] = 'h';
 bz2_data[3] = '1';
 memcpy(bz2_data+4, src, src_len);
 stream.next_in = (char *)bz2_data;
 stream.avail_in = src_len+4;
 stream.next_out = (char *)dest;
 stream.avail_out = *dest_len;
 while (ret != 4) {
  ret = BZ2_bzDecompress(&stream);
  if (ret != 0 && ret != 4) {
   goto error;
  }
 }
 *dest_len = stream.total_out_lo32;
 goto success;
error:
 free(bz2_data);
 BZ2_bzDecompressEnd(&stream);
 return 0;
success:
 free(bz2_data);
 BZ2_bzDecompressEnd(&stream);
 return 1;
}

variable_types:
src
unsigned char *

variable_types:
dest
unsigned char *

variable_types: struct bz_stream { char *next_in; unsigned int avail_in; unsigned int total_in_lo32; unsigned int total_in_hi32; char *next_out; unsigned int avail_out; unsigned int total_out_lo32; unsigned int total_out_hi32; void *state; void *(*bzalloc)(void *, int, int); void (*bzfree)(void *, void *); void *opaque; }

variable_types: ret int


decompiled_code:
__int64 __fastcall bz2_headerless_compress(__int64 a1, int a2, __int64 a3, int *a4)
{
int v6; // er8
__int64 result; // rax
int v8; // eax
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-78h] BYREF
int v11; // [rsp+8h] [rbp-70h]
__int64 v12; // [rsp+18h] [rbp-60h]
int v13; // [rsp+20h] [rbp-58h]
int v14; // [rsp+24h] [rbp-54h]
__int64 v15; // [rsp+38h] [rbp-40h]
__int64 v16; // [rsp+40h] [rbp-38h]
__int64 v17; // [rsp+48h] [rbp-30h]

v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v6 = BZ2_bzCompressInit(&v10, 1LL, 0LL, 30LL);
result = 0LL;
if ( !v6 )
{
v8 = *a4;
v10 = a1;
v11 = a2;
v12 = a3;
v13 = v8;
if ( (unsigned int)BZ2_bzCompress(&v10, 0LL) == 1 )
{
while ( 1 )
{
v9 = BZ2_bzCompress(&v10, 2LL);
if ( !v13 )
break;
if ( v9 == 4 )
{
memcpy((void *)a3, (const void *)(a3 + 4), (unsigned int)(*a4 - 4));
*a4 = v14 - 4;
BZ2_bzCompressEnd(&v10);
return 1LL;
}
}
}
BZ2_bzCompressEnd(&v10);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3, int *a4)
{
int v6; // er8
__int64 result; // rax
int v8; // eax
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-78h] BYREF
int v11; // [rsp+8h] [rbp-70h]
__int64 v12; // [rsp+18h] [rbp-60h]
int v13; // [rsp+20h] [rbp-58h]
int v14; // [rsp+24h] [rbp-54h]
__int64 v15; // [rsp+38h] [rbp-40h]
__int64 v16; // [rsp+40h] [rbp-38h]
__int64 v17; // [rsp+48h] [rbp-30h]

v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v6 = BZ2_bzCompressInit(&v10, 1LL, 0LL, 30LL);
result = 0LL;
if ( !v6 )
{
v8 = *a4;
v10 = a1;
v11 = a2;
v12 = a3;
v13 = v8;
if ( (unsigned int)BZ2_bzCompress(&v10, 0LL) == 1 )
{
while ( 1 )
{
v9 = BZ2_bzCompress(&v10, 2LL);
if ( !v13 )
break;
if ( v9 == 4 )
{
memcpy((void *)a3, (const void *)(a3 + 4), (unsigned int)(*a4 - 4));
*a4 = v14 - 4;
BZ2_bzCompressEnd(&v10);
return 1LL;
}
}
}
BZ2_bzCompressEnd(&v10);
result = 0LL;
}
return result;
}

original_code:
static _Bool bz2_headerless_compress(unsigned char* src, uint32_t src_len, unsigned char* dest, uint32_t* dest_len)
{
    bz_stream stream;
 stream.bzalloc = ((void *)0);
 stream.bzfree = ((void *)0);
 stream.opaque = ((void *)0);
 int ret = BZ2_bzCompressInit(&stream, 1, 0, 30);
 if (ret != 0) {
  return 0;
 }
 stream.next_in = (char*)src;
 stream.avail_in = src_len;
 stream.next_out = (char*)dest;
 stream.avail_out = *dest_len;
 ret = BZ2_bzCompress(&stream, 0);
 if (ret != 1) {
  goto error;
 }
 while (ret != 4) {
  ret = BZ2_bzCompress(&stream, 2);
  if (stream.avail_out == 0) {
   goto error;
  }
 }
 memcpy(dest, dest+4, *(dest_len)-4);
 *dest_len = (stream.total_out_lo32-4);
 goto success;
error:
 BZ2_bzCompressEnd(&stream);
 return 0;
success:
 BZ2_bzCompressEnd(&stream);
 return 1;
}

canonical_original_code:
static _Bool bz2_headerless_compress(unsigned char *src, unsigned int src_len, unsigned char *dest, unsigned int *dest_len)
{
    struct bz_stream stream;
 stream.bzalloc = ((void *)0);
 stream.bzfree = ((void *)0);
 stream.opaque = ((void *)0);
 int ret = BZ2_bzCompressInit(&stream, 1, 0, 30);
 if (ret != 0) {
  return 0;
 }
 stream.next_in = (char *)src;
 stream.avail_in = src_len;
 stream.next_out = (char *)dest;
 stream.avail_out = *dest_len;
 ret = BZ2_bzCompress(&stream, 0);
 if (ret != 1) {
  goto error;
 }
 while (ret != 4) {
  ret = BZ2_bzCompress(&stream, 2);
  if (stream.avail_out == 0) {
   goto error;
  }
 }
 memcpy(dest, dest+4, *(dest_len)-4);
 *dest_len = (stream.total_out_lo32-4);
 goto success;
error:
 BZ2_bzCompressEnd(&stream);
 return 0;
success:
 BZ2_bzCompressEnd(&stream);
 return 1;
}

user_defined_types: struct bz_stream { char *next_in; unsigned int avail_in; unsigned int total_in_lo32; unsigned int total_in_hi32; char *next_out; unsigned int avail_out; unsigned int total_out_lo32; unsigned int total_out_hi32; void *state; void *(*bzalloc)(void *, int, int); void (*bzfree)(void *, void *); void *opaque; }


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

object_init(list_proto[0], list_proto[1], a1 + 32);
result = 0LL;
*(_WORD *)(a1 + 24) = 0;
return result;
}

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

object_init(list_proto[0], list_proto[1], a1 + 32);
result = 0LL;
*(_WORD *)(a1 + 24) = 0;
return result;
}

original_code:
static void archive_init(archive_t* archive)
{
 _object_init(list_proto, (object_t*)&archive->files);
 archive->num_files = 0;
}

canonical_original_code:
static void archive_init(struct archive *archive)
{
 _object_init(list_proto, (struct object *)&archive->files);
 archive->num_files = 0;
}


decompiled_code:
__int64 __fastcall archive_decompress(__int64 a1, _QWORD *a2)
{
__int64 v3; // r12
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er13
__int64 v7; // r14
char v8; // al
__int64 v9; // rdi
unsigned __int16 v10; // ax
int v11; // er14
char *v12; // rbp
unsigned int v13; // ebx
unsigned int v14; // er13
void *v15; // rax
void *v16; // r8
int v18; // [rsp+Ch] [rbp-5Ch]
int v19; // [rsp+18h] [rbp-50h]
char v20; // [rsp+1Eh] [rbp-4Ah]
int v21[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v3 = object_new(codec_proto[0], codec_proto[1], 64LL);
codec_resize(v3, *a2);
codec_putn(v3, a2[1], *a2);
codec_seek(v3, 0LL);
v4 = codec_get24(v3);
v5 = codec_get24(v3);
if ( v4 == v5 )
{
v20 = 1;
}
else
{
v6 = v5;
v21[0] = v4;
v7 = object_new(codec_proto[0], codec_proto[1], 64LL);
codec_resize(v7, v4);
v8 = bz2_headerless_decompress((void *)(a2[1] + 6LL), v6, *(_QWORD *)(v7 + 24), v21);
if ( v21[0] != v4 || !v8 )
{
object_free(v7);
LABEL_14:
object_free(v3);
return 0LL;
}
v9 = v3;
v3 = v7;
object_free(v9);
v20 = 0;
}
v10 = codec_get16(v3);
v18 = 0;
v19 = v10;
v11 = *(_DWORD *)(v3 + 40) + 10 * v10;
if ( v10 )
{
while ( 1 )
{
v12 = (char *)malloc(0x28uLL);
*((_DWORD *)v12 + 4) = codec_get32(v3);
v13 = codec_get24(v3);
v14 = codec_get24(v3);
if ( v13 != v14 && v20 != 1 )
break;
*(_QWORD *)v12 = v13;
v15 = malloc(v13);
v16 = (void *)(*(_QWORD *)(v3 + 24) + v11);
*((_QWORD *)v12 + 1) = v15;
if ( v20 )
{
v21[0] = v13;
if ( !(unsigned __int8)bz2_headerless_decompress(v16, v14, (__int64)v15, v21) )
{
free(*((void **)v12 + 1));
break;
}
}
else
{
memcpy(v15, v16, v13);
}
v11 += v14;
list_push_back(a1 + 32, v12 + 24);
++v18;
++*(_WORD *)(a1 + 24);
if ( v19 == v18 )
goto LABEL_18;
}
free(v12);
goto LABEL_14;
}
LABEL_18:
object_free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
__int64 v3; // r12
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // er13
__int64 v7; // r14
char v8; // al
__int64 v9; // rdi
unsigned __int16 v10; // ax
int v11; // er14
char *v12; // rbp
unsigned int v13; // ebx
unsigned int v14; // er13
void *v15; // rax
void *v16; // r8
int v18; // [rsp+Ch] [rbp-5Ch]
int v19; // [rsp+18h] [rbp-50h]
char v20; // [rsp+1Eh] [rbp-4Ah]
int v21[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v3 = object_new(codec_proto[0], codec_proto[1], 64LL);
codec_resize(v3, *a2);
codec_putn(v3, a2[1], *a2);
codec_seek(v3, 0LL);
v4 = codec_get24(v3);
v5 = codec_get24(v3);
if ( v4 == v5 )
{
v20 = 1;
}
else
{
v6 = v5;
v21[0] = v4;
v7 = object_new(codec_proto[0], codec_proto[1], 64LL);
codec_resize(v7, v4);
v8 = func1((void *)(a2[1] + 6LL), v6, *(_QWORD *)(v7 + 24), v21);
if ( v21[0] != v4 || !v8 )
{
object_free(v7);
LABEL_14:
object_free(v3);
return 0LL;
}
v9 = v3;
v3 = v7;
object_free(v9);
v20 = 0;
}
v10 = codec_get16(v3);
v18 = 0;
v19 = v10;
v11 = *(_DWORD *)(v3 + 40) + 10 * v10;
if ( v10 )
{
while ( 1 )
{
v12 = (char *)malloc(0x28uLL);
*((_DWORD *)v12 + 4) = codec_get32(v3);
v13 = codec_get24(v3);
v14 = codec_get24(v3);
if ( v13 != v14 && v20 != 1 )
break;
*(_QWORD *)v12 = v13;
v15 = malloc(v13);
v16 = (void *)(*(_QWORD *)(v3 + 24) + v11);
*((_QWORD *)v12 + 1) = v15;
if ( v20 )
{
v21[0] = v13;
if ( !(unsigned __int8)func1(v16, v14, (__int64)v15, v21) )
{
free(*((void **)v12 + 1));
break;
}
}
else
{
memcpy(v15, v16, v13);
}
v11 += v14;
list_push_back(a1 + 32, v12 + 24);
++v18;
++*(_WORD *)(a1 + 24);
if ( v19 == v18 )
goto LABEL_18;
}
free(v12);
goto LABEL_14;
}
LABEL_18:
object_free(v3);
return 1LL;
}

original_code:
_Bool archive_decompress(archive_t* archive, file_t* data)
{
 codec_t* arc_codec = (codec_t*)_object_new(codec_proto, sizeof(codec_t));
 codec_resize(arc_codec, data->length);
 codec_putn(arc_codec, data->data, data->length);
 codec_seek(arc_codec, 0);
 uint32_t final_len = codec_get24(arc_codec);
 uint32_t container_len = codec_get24(arc_codec);
 _Bool compressed = 1;
 if (container_len != final_len) {
  compressed = 0;
  uint32_t decompressed_len = final_len;
  codec_t* new_codec = (codec_t*)_object_new(codec_proto, sizeof(codec_t));
  codec_resize(new_codec, final_len);
  _Bool success = bz2_headerless_decompress(data->data+6, container_len, new_codec->data, &decompressed_len);
  if (decompressed_len != final_len) {
   _object_free((object_t*)new_codec);;
   goto error;
  }
  if (!success) {
   _object_free((object_t*)new_codec);;
   goto error;
  }
  _object_free((object_t*)arc_codec);;
  arc_codec = new_codec;
 }
 int num_files = codec_get16(arc_codec);
 int file_ofs = arc_codec->caret + (num_files * 10);
 for (int i = 0; i < num_files; i++) {
  archive_file_t* file = (archive_file_t*)malloc(sizeof(archive_file_t));
  file->identifier = codec_get32(arc_codec);
  uint32_t final_file_len = codec_get24(arc_codec);
  uint32_t actual_file_len = codec_get24(arc_codec);
  if (!compressed && final_file_len != actual_file_len) {
   free(file);
   goto error;
  }
  file->file.length = final_file_len;
  file->file.data = (unsigned char*)malloc(final_file_len);
  if (compressed) {
   uint32_t decompressed_len = final_file_len;
   _Bool success = bz2_headerless_decompress(arc_codec->data+file_ofs, actual_file_len, file->file.data, &decompressed_len);
   if (!success) {
    free(file->file.data);
    free(file);
    goto error;
   }
  } else {
   memcpy(file->file.data, arc_codec->data+file_ofs, final_file_len);
  }
  list_push_back(&archive->files, &file->node);
  archive->num_files++;
  file_ofs += actual_file_len;
 }
 goto success;
error:
 _object_free((object_t*)arc_codec);;
 return 0;
success:
 _object_free((object_t*)arc_codec);;
 return 1;
}

canonical_original_code:
_Bool archive_decompress(struct archive *archive, struct file *data)
{
 struct codec *arc_codec = (codec_t*)_object_new(codec_proto, sizeof(codec_t));
 codec_resize(arc_codec, data->length);
 codec_putn(arc_codec, data->data, data->length);
 codec_seek(arc_codec, 0);
 unsigned int final_len = codec_get24(arc_codec);
 unsigned int container_len = codec_get24(arc_codec);
 _Bool compressed = 1;
 if (container_len != final_len) {
  compressed = 0;
  unsigned int decompressed_len = final_len;
  struct codec *new_codec = (codec_t*)_object_new(codec_proto, sizeof(codec_t));
  codec_resize(new_codec, final_len);
  _Bool success = bz2_headerless_decompress(data->data+6, container_len, new_codec->data, &decompressed_len);
  if (decompressed_len != final_len) {
   _object_free((struct object *)new_codec);;
   goto error;
  }
  if (!success) {
   _object_free((struct object *)new_codec);;
   goto error;
  }
  _object_free((struct object *)arc_codec);;
  arc_codec = new_codec;
 }
 int num_files = codec_get16(arc_codec);
 int file_ofs = arc_codec->caret + (num_files * 10);
 for (int i = 0; i < num_files; i++) {
  struct archive_file *file = (archive_file_t*)malloc(sizeof(archive_file_t));
  file->identifier = codec_get32(arc_codec);
  unsigned int final_file_len = codec_get24(arc_codec);
  unsigned int actual_file_len = codec_get24(arc_codec);
  if (!compressed && final_file_len != actual_file_len) {
   free(file);
   goto error;
  }
  file->file.length = final_file_len;
  file->file.data = (unsigned char *)malloc(final_file_len);
  if (compressed) {
   unsigned int decompressed_len = final_file_len;
   _Bool success = bz2_headerless_decompress(arc_codec->data+file_ofs, actual_file_len, file->file.data, &decompressed_len);
   if (!success) {
    free(file->file.data);
    free(file);
    goto error;
   }
  } else {
   memcpy(file->file.data, arc_codec->data+file_ofs, final_file_len);
  }
  list_push_back(&archive->files, &file->node);
  archive->num_files++;
  file_ofs += actual_file_len;
 }
 goto success;
error:
 _object_free((struct object *)arc_codec);;
 return 0;
success:
 _object_free((struct object *)arc_codec);;
 return 1;
}

variable_types: struct file { unsigned long length; unsigned char *data; } *

variable_types: struct codec { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; unsigned char *data; unsigned long length; unsigned long caret; _Bool bit_access_mode; unsigned long bit_caret; } *

variable_types: i int

variable_types: struct archive_file { struct file { unsigned long length; unsigned char *data; } file; unsigned int identifier; struct list_node { struct list_node *prev; struct list_node *next; } node; } *

user_defined_types: struct codec { struct object object; unsigned char *data; unsigned long length; unsigned long caret; _Bool bit_access_mode; unsigned long bit_caret; }

user_defined_types: struct archive_file { struct file file; unsigned int identifier; struct list_node node; }


decompiled_code:
void __fastcall archive_remove_file(__int64 a1, __int64 a2)
{
if ( archive_get_file(a1, *(_DWORD *)(a2 + 16)) )
{
list_erase(a1 + 32, a2 + 24);
--*(_WORD *)(a1 + 24);
free(*(void **)(a2 + 8));
free((void *)a2);
}
}

original_code:
void archive_remove_file(archive_t* archive, archive_file_t* file)
{
 if (archive_get_file(archive, file->identifier) == ((void *)0)) {
  return;
 }
 list_erase(&archive->files, &file->node);
 archive->num_files--;
 free(file->file.data);
 free(file);
}

canonical_original_code:
void archive_remove_file(struct archive *archive, struct archive_file *file)
{
 if (archive_get_file(archive, file->identifier) == ((void *)0)) {
  return;
 }
 list_erase(&archive->files, &file->node);
 archive->num_files--;
 free(file->file.data);
 free(file);
}

variable_types: struct archive_file { struct file { unsigned long length; unsigned char *data; } file; unsigned int identifier; struct list_node node; } *


decompiled_code:
__int64 __fastcall sorted_list_free(__int64 a1)
{
return object_free(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return object_free(a1 + 24);
}

original_code:
static void sorted_list_free(sorted_list_t* list)
{
 _object_free((object_t*)&list->list);;
}

canonical_original_code:
static void sorted_list_free(struct sorted_list *list)
{
 _object_free((struct object *)&list->list);;
}

variable_types: struct sorted_list { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; struct list { struct object object; struct list_node { struct list_node *prev; struct list_node *next; } *top; struct list_node *bottom; } list; int (*compare_func)(struct list_node *, struct list_node *); } *

user_defined_types: struct sorted_list { struct object object; struct list list; int (*compare_func)(struct list_node *, struct list_node *); }


decompiled_code:
__int64 __fastcall sorted_list_init(__int64 a1)
{
return object_init(list_proto[0], list_proto[1], a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return object_init(list_proto[0], list_proto[1], a1 + 24);
}

original_code:
static void sorted_list_init(sorted_list_t* list)
{
 _object_init(list_proto, (object_t*)&list->list);
}

canonical_original_code:
static void sorted_list_init(struct sorted_list *list)
{
 _object_init(list_proto, (struct object *)&list->list);
}


decompiled_code:
__int64 __fastcall sorted_list_insert(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 result; // rax
_QWORD *v4; // rbp
int v5; // eax

v2 = a1 + 24;
if ( (unsigned __int8)list_empty(a1 + 24) )
return list_push_front(v2, a2);
result = list_front(v2);
v4 = (_QWORD *)result;
while ( 2 )
{
if ( v4 )
{
while ( 1 )
{
v5 = (*(__int64 (__fastcall **)(__int64, _QWORD *))(a1 + 64))(a2, v4);
if ( !v5 )
return list_insert_after(v2, v4, a2);
if ( v5 < 0 )
break;
if ( !v4[1] )
return list_insert_after(v2, v4, a2);
result = (*(__int64 (__fastcall **)(__int64))(a1 + 64))(a2);
if ( (int)result < 0 )
return list_insert_after(v2, v4, a2);
v4 = (_QWORD *)v4[1];
if ( !v4 )
return result;
}
if ( *v4 )
{
result = (*(__int64 (__fastcall **)(__int64))(a1 + 64))(a2);
if ( (int)result <= 0 )
{
v4 = (_QWORD *)*v4;
continue;
}
}
result = list_insert_before(v2, v4, a2);
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 result; // rax
_QWORD *v4; // rbp
int v5; // eax

v2 = a1 + 24;
if ( (unsigned __int8)list_empty(a1 + 24) )
return list_push_front(v2, a2);
result = list_front(v2);
v4 = (_QWORD *)result;
while ( 2 )
{
if ( v4 )
{
while ( 1 )
{
v5 = (*(__int64 (__fastcall **)(__int64, _QWORD *))(a1 + 64))(a2, v4);
if ( !v5 )
return list_insert_after(v2, v4, a2);
if ( v5 < 0 )
break;
if ( !v4[1] )
return list_insert_after(v2, v4, a2);
result = (*(__int64 (__fastcall **)(__int64))(a1 + 64))(a2);
if ( (int)result < 0 )
return list_insert_after(v2, v4, a2);
v4 = (_QWORD *)v4[1];
if ( !v4 )
return result;
}
if ( *v4 )
{
result = (*(__int64 (__fastcall **)(__int64))(a1 + 64))(a2);
if ( (int)result <= 0 )
{
v4 = (_QWORD *)*v4;
continue;
}
}
result = list_insert_before(v2, v4, a2);
}
break;
}
return result;
}

original_code:
void sorted_list_insert(sorted_list_t* list, list_node_t* node)
{
 if (list_empty(&list->list)) {
  list_push_front(&list->list, node);
  return;
 }
 list_node_t* other_node = list_front(&list->list);
 while (other_node != ((void *)0)) {
  int cmp_result = list->compare_func(node, other_node);
  if (cmp_result == 0) {
   list_insert_after(&list->list, other_node, node);
   return;
  }
  if (cmp_result < 0) {
   if (other_node->prev == ((void *)0)) {
    list_insert_before(&list->list, other_node, node);
    return;
   }
   cmp_result = list->compare_func(node, other_node->prev);
   if (cmp_result > 0) {
    list_insert_before(&list->list, other_node, node);
    return;
   }
   other_node = other_node->prev;
   continue;
  }
  if (cmp_result > 0) {
   if (other_node->next == ((void *)0)) {
    list_insert_after(&list->list, other_node, node);
    return;
   }
   cmp_result = list->compare_func(node, other_node->next);
   if (cmp_result < 0) {
    list_insert_after(&list->list, other_node, node);
    return;
   }
   other_node = other_node->next;
   continue;
  }
 }
}

canonical_original_code:
void sorted_list_insert(struct sorted_list *list, struct list_node *node)
{
 if (list_empty(&list->list)) {
  list_push_front(&list->list, node);
  return;
 }
 struct list_node *other_node = list_front(&list->list);
 while (other_node != ((void *)0)) {
  int cmp_result = list->compare_func(node, other_node);
  if (cmp_result == 0) {
   list_insert_after(&list->list, other_node, node);
   return;
  }
  if (cmp_result < 0) {
   if (other_node->prev == ((void *)0)) {
    list_insert_before(&list->list, other_node, node);
    return;
   }
   cmp_result = list->compare_func(node, other_node->prev);
   if (cmp_result > 0) {
    list_insert_before(&list->list, other_node, node);
    return;
   }
   other_node = other_node->prev;
   continue;
  }
  if (cmp_result > 0) {
   if (other_node->next == ((void *)0)) {
    list_insert_after(&list->list, other_node, node);
    return;
   }
   cmp_result = list->compare_func(node, other_node->next);
   if (cmp_result < 0) {
    list_insert_after(&list->list, other_node, node);
    return;
   }
   other_node = other_node->next;
   continue;
  }
 }
}


decompiled_code:
void __fastcall cache_init(__int64 a1)
{
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
}

original_code:
static void cache_init(cache_t* cache)
{
 cache->num_files = 0;
 cache->files = 0;
}

canonical_original_code:
static void cache_init(struct cache *cache)
{
 cache->num_files = 0;
 cache->files = 0;
}

variable_types: struct cache { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; int num_indices; int *num_files; _Bool must_free; struct file { unsigned long length; unsigned char *data; } **files; } *

user_defined_types: struct cache { struct object object; int num_indices; int *num_files; _Bool must_free; struct file **files; }


original_code:
static void cache_free(cache_t* cache)
{
 if (cache->num_files != 0) {
  free(cache->num_files);
 }
 if (cache->files != 0) {
  for (int i = 0; i < cache->num_indices; i++) {
   for (int x = 0; x < cache->num_files[i]; x++) {
    file_t* file = &cache->files[i][x];
    if (file->data != ((void *)0)) {
     free(file->data);
    }
   }
   free(cache->files[i]);
  }
  free(cache->files);
 }
}

canonical_original_code:
static void cache_free(struct cache *cache)
{
 if (cache->num_files != 0) {
  free(cache->num_files);
 }
 if (cache->files != 0) {
  for (int i = 0; i < cache->num_indices; i++) {
   for (int x = 0; x < cache->num_files[i]; x++) {
    struct file *file = &cache->files[i][x];
    if (file->data != ((void *)0)) {
     free(file->data);
    }
   }
   free(cache->files[i]);
  }
  free(cache->files);
 }
}

variable_types: x int

user_defined_types: struct file { unsigned long length; unsigned char *data; }


original_code:
static void cache_fs_get(codec_t* data_indices, codec_t* data_blocks, int index_id, int file_id, file_t* cache_file)
{
 int num_files = data_indices->length/6;
 if (file_id < 0 || file_id > num_files) {
  goto error;
 }
 codec_seek(data_indices, file_id*6);
 cache_file->length = codec_get24fp(data_indices, ((void *)0), 0);
 int current_block = codec_get24fp(data_indices, ((void *)0), 0);
 int write_caret = 0;
 int to_read = cache_file->length;
 int file_part = 0;
 int num_blocks = data_blocks->length/520;
 cache_file->data = (unsigned char*)malloc(cache_file->length);
 while (current_block != 0) {
  if (current_block <= 0 || current_block > num_blocks) {
   free(cache_file->data);
   return;
  }
  codec_seek(data_blocks, current_block*520);
  int block_file_id = codec_get16(data_blocks);
  int block_file_pos = codec_get16(data_blocks);
  int next_block = codec_get24(data_blocks);
  int block_cache_id = codec_get8(data_blocks);
  int read_this_block = to_read;
  if (read_this_block > 512) {
   read_this_block = 512;
  }
  if (block_file_id != file_id || block_file_pos != file_part || block_cache_id-1 != index_id) {
   free(cache_file->data);
   goto error;
  }
  codec_getn(data_blocks, cache_file->data+(write_caret), read_this_block);
  write_caret += read_this_block;
  to_read -= read_this_block;
  current_block = next_block;
  file_part++;
 }
 if (to_read > 0) {
  free(cache_file->data);
  goto error;
 }
 goto exit;
error:
 cache_file->length = 0;
 cache_file->data = ((void *)0);
exit:
 return;
}

canonical_original_code:
static void cache_fs_get(struct codec *data_indices, struct codec *data_blocks, int index_id, int file_id, struct file *cache_file)
{
 int num_files = data_indices->length/6;
 if (file_id < 0 || file_id > num_files) {
  goto error;
 }
 codec_seek(data_indices, file_id*6);
 cache_file->length = codec_get24fp(data_indices, ((void *)0), 0);
 int current_block = codec_get24fp(data_indices, ((void *)0), 0);
 int write_caret = 0;
 int to_read = cache_file->length;
 int file_part = 0;
 int num_blocks = data_blocks->length/520;
 cache_file->data = (unsigned char *)malloc(cache_file->length);
 while (current_block != 0) {
  if (current_block <= 0 || current_block > num_blocks) {
   free(cache_file->data);
   return;
  }
  codec_seek(data_blocks, current_block*520);
  int block_file_id = codec_get16(data_blocks);
  int block_file_pos = codec_get16(data_blocks);
  int next_block = codec_get24(data_blocks);
  int block_cache_id = codec_get8(data_blocks);
  int read_this_block = to_read;
  if (read_this_block > 512) {
   read_this_block = 512;
  }
  if (block_file_id != file_id || block_file_pos != file_part || block_cache_id-1 != index_id) {
   free(cache_file->data);
   goto error;
  }
  codec_getn(data_blocks, cache_file->data+(write_caret), read_this_block);
  write_caret += read_this_block;
  to_read -= read_this_block;
  current_block = next_block;
  file_part++;
 }
 if (to_read > 0) {
  free(cache_file->data);
  goto error;
 }
 goto exit;
error:
 cache_file->length = 0;
 cache_file->data = ((void *)0);
exit:
 return;
}


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

if ( *(_DWORD *)(a1 + 24) < a2 || *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2) < a3 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * a2) + 16LL * a3;
return result;
}

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

if ( *(_DWORD *)(a1 + 24) < a2 || *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL * a2) < a3 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * a2) + 16LL * a3;
return result;
}

original_code:
file_t* cache_get_file(cache_t* cache, int index, int file)
{
 if (index > cache->num_indices || file > cache->num_files[index]) {
  return ((void *)0);
 }
 return &cache->files[index][file];
}

canonical_original_code:
struct file *cache_get_file(struct cache *cache, int index, int file)
{
 if (index > cache->num_indices || file > cache->num_files[index]) {
  return ((void *)0);
 }
 return &cache->files[index][file];
}

variable_types: struct cache { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; int num_indices; int *num_files; _Bool must_free; struct file **files; } *

variable_types: index int

variable_types: file int

return_type: struct file { unsigned long length; unsigned char *data; } *


decompiled_code:
int __fastcall file_path_join(const char *a1, const char *a2, char *a3)
{
char *v3; // rbx
int result; // eax
char v5; // dl
char *v6; // rdi

v3 = a3;
result = sprintf(a3, "%s/%s", a1, a2);
v5 = *v3;
if ( *v3 )
{
while ( 1 )
{
result = (unsigned __int8)v3[1];
v6 = v3++;
if ( v5 == 47 && (_BYTE)result == 47 )
{
strcpy(v6, v3);
result = (unsigned __int8)*v3;
if ( !(_BYTE)result )
return result;
}
else if ( !(_BYTE)result )
{
return result;
}
v5 = result;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, const char *a2, char *a3)
{
char *v3; // rbx
int result; // eax
char v5; // dl
char *v6; // rdi

v3 = a3;
result = sprintf(a3, "%s/%s", a1, a2);
v5 = *v3;
if ( *v3 )
{
while ( 1 )
{
result = (unsigned __int8)v3[1];
v6 = v3++;
if ( v5 == 47 && (_BYTE)result == 47 )
{
strcpy(v6, v3);
result = (unsigned __int8)*v3;
if ( !(_BYTE)result )
return result;
}
else if ( !(_BYTE)result )
{
return result;
}
v5 = result;
}
}
return result;
}

original_code:
void file_path_join(char* path_a, char* path_b, char* out)
{
 sprintf(out, "%s/%s", path_a, path_b);
 for (char* p = out; *p != '\0'; p++) {
  if (*p == '/' && *(p+1) == '/') {
   strcpy(p, p+1);
  }
 }
}

canonical_original_code:
void file_path_join(char *path_a, char *path_b, char *out)
{
 sprintf(out, "%s/%s", path_a, path_b);
 for (char *p = out; *p != '\0'; p++) {
  if (*p == '/' && *(p+1) == '/') {
   strcpy(p, p+1);
  }
 }
}

variable_types:
out
char *

variable_types:
p
char *


decompiled_code:
void __fastcall stack_init(__int64 a1)
{
*(_DWORD *)(a1 + 152) = 0;
}

original_code:
static void stack_init(int_stack_t* stack)
{
 stack->bottom = 0;
}

canonical_original_code:
static void stack_init(struct int_stack *stack)
{
 stack->bottom = 0;
}

variable_types: struct int_stack { struct object { struct object_proto { void (*init)(void *); void (*free)(void *); } prototype; _Bool must_free; } object; int stack[32]; int bottom; } *

user_defined_types: struct int_stack { struct object object; int stack[32]; int bottom; }


decompiled_code:
void stack_free()
{
;
}

original_code:
static void stack_free(int_stack_t* stack)
{
}

canonical_original_code:
static void stack_free(struct int_stack *stack)
{
}


original_code:
_Bool stack_push(int_stack_t* stack, int i)
{
 if (stack->bottom < 32) {
  stack->stack[stack->bottom++] = i;
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool stack_push(struct int_stack *stack, int i)
{
 if (stack->bottom < 32) {
  stack->stack[stack->bottom++] = i;
  return 1;
 }
 return 0;
}


original_code:
int stack_pop(int_stack_t* stack)
{
 if (stack->bottom > 0) {
  return stack->stack[--stack->bottom];
 }
 return 0;
}

canonical_original_code:
int stack_pop(struct int_stack *stack)
{
 if (stack->bottom > 0) {
  return stack->stack[--stack->bottom];
 }
 return 0;
}


client

repo: kazu-yamamoto/latency-bench

decompiled_code:
__int64 __fastcall client(__int64 a1, int a2)
{
int v3; // eax
int v4; // er12
unsigned int v5; // ebx
double v6; // xmm0_8
__int64 v7; // rsi
double v9; // [rsp+8h] [rbp-20h]

v3 = connect_peer(a1, "8001");
if ( a2 > 0 )
{
v4 = v3;
v5 = 0;
do
{
v9 = timestamp();
if ( !(unsigned int)ping(v4) )
break;
v6 = timestamp();
v7 = v5++;
printf("%i %lf\n", v7, v6 - v9);
}
while ( a2 != v5 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v3; // eax
int v4; // er12
unsigned int v5; // ebx
double v6; // xmm0_8
__int64 v7; // rsi
double v9; // [rsp+8h] [rbp-20h]

v3 = func22(a1, "8001");
if ( a2 > 0 )
{
v4 = v3;
v5 = 0;
do
{
v9 = func25();
if ( !(unsigned int)func23(v4) )
break;
v6 = func25();
v7 = v5++;
printf("%i %lf\n", v7, v6 - v9);
}
while ( a2 != v5 );
}
return 0LL;
}

original_code:
int
client(char *peer, int num) {
  int sock = connect_peer(peer, "8001");
  int i;
  for (i = 0; i < num; i++) {
    double timestamp_before = timestamp();
    if (ping(sock) == 0) { break; }
    double timestamp_after = timestamp();
    printf("%i %lf\n", i, timestamp_after - timestamp_before);
  }
  return 0;
}

variable_types:
peer
char *

variable_types: num int

variable_types: sock int


usage

decompiled_code:
__int64 __fastcall usage(__int64 a1, const char **a2)
{
fprintf(stderr, "usage: %s <server_addr> <#_of_pings>\n", *a2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char **a2)
{
fprintf(stderr, "usage: %s <server_addr> <#_of_pings>\n", *a2);
return 0xFFFFFFFFLL;
}

original_code:
int
usage(int argc, char** argv) {
  char *prog = argv[0];
  fprintf(stderr, "usage: %s <server_addr> <#_of_pings>\n", prog);
  return -1;
}

canonical_original_code:
int usage(int argc, char **argv) {
  char *prog = argv[0];
  fprintf(stderr, "usage: %s <server_addr> <#_of_pings>\n", prog);
  return -1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
prog
char *


decompiled_code:
void __fastcall exit_error(int a1, const char *a2)
{
if ( a1 < 0 )
{
perror(a2);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, const char *a2)
{
if ( a1 < 0 )
{
perror(a2);
exit(1);
}
}

original_code:
void
exit_error(int ret, char *msg) {
  if (ret < 0) {
    perror(msg);
    exit(1);
  }
}

variable_types: ret int

variable_types:
msg
char *


decompiled_code:
void __fastcall exit_gai_error(int a1)
{
const char *v1; // rax

if ( a1 )
{
v1 = gai_strerror(a1);
fprintf(stderr, "%s\n", v1);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
const char *v1; // rax

if ( a1 )
{
v1 = gai_strerror(a1);
fprintf(stderr, "%s\n", v1);
exit(1);
}
}

original_code:
void
exit_gai_error(int ret) {
  if (ret != 0) {
    fprintf(stderr, "%s\n", gai_strerror(ret));
    exit(1);
  }
}