decompiled_code:
__int64 initialize_equates()
{
__int64 i; // rbx
__int64 v1; // rax
char v3[136]; // [rsp+0h] [rbp-88h] BYREF

for ( i = 0LL; i != 1024; ++i )
{
sprintf(v3, "UNDEF%04d", (unsigned int)i);
equates[2 * i + 1] = strsave(v3);
v1 = 2LL * (int)i;
LOBYTE(equates[v1]) = 1;
BYTE1(equates[v1]) = 4;
BYTE2(equates[v1]) &= 0xFEu;
}
BYTE2(equates[0]) ^= 1u;
BYTE1(equates[0]) = 0;
LOBYTE(equates[0]) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 i; // rbx
__int64 v1; // rax
char v3[136]; // [rsp+0h] [rbp-88h] BYREF

for ( i = 0LL; i != 1024; ++i )
{
sprintf(v3, "UNDEF%04d", (unsigned int)i);
equates[2 * i + 1] = strsave(v3);
v1 = 2LL * (int)i;
LOBYTE(equates[v1]) = 1;
BYTE1(equates[v1]) = 4;
BYTE2(equates[v1]) &= 0xFEu;
}
BYTE2(equates[0]) ^= 1u;
BYTE1(equates[0]) = 0;
LOBYTE(equates[0]) = 0;
return 0LL;
}

original_code:
int initialize_equates() {
    int i;
    char buf[128];
    for (i=0; i<1024; i++) {
 sprintf(buf,"UNDEF%04d", i);
     equates[i].label=strsave(buf);
 equates[i].flags.fill=0;
 equates[i].flags.override=0;
 equates[i].flags.masktype=0;
 equates[i].flags.pen=1;
 equates[i].flags.color=1;
 equates[i].flags.linetype=0;
 equates[i].flags.used=0;
    }
    for (i=0; i<=0; i++) {
 equates[i].flags.linetype=i%6;
 equates[i].flags.used++;
 equates[i].flags.color=i;
 equates[i].flags.pen=i;
 equates[i].flags.masktype=i%2;
 equates[i].flags.fill=i%2;
 equates[i].flags.override=0;
    }
    return(0);
}

variable_types:
buf
char [128]


repo: omnister/piglet

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

result = (unsigned int)(a1 + 48);
if ( a1 <= 9 )
result = (unsigned int)*(&s + a1);
return result;
}

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

result = (unsigned int)(a1 + 48);
if ( a1 <= 9 )
result = (unsigned int)*(&s + a1);
return result;
}

original_code:
int equate2color(int c) {
    if (c <= 9) {
        return(COLORTAB[c]);
    } else {
     return(c+'0');
    }
}

variable_types: c int

return_type: int


decompiled_code:
__int64 __fastcall color2equate(unsigned __int8 a1)
{
const __int32_t **v1; // rax
char *v2; // rax
__int64 result; // rax

if ( ((*_ctype_b_loc())[a1] & 0x800) != 0 )
return (unsigned int)((char)a1 - 48);
v1 = _ctype_toupper_loc();
v2 = strchr("WRGBCMYWLD", (*v1)[a1]);
if ( v2 )
result = v2 - "WRGBCMYWLD";
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
const __int32_t **v1; // rax
char *v2; // rax
__int64 result; // rax

if ( ((*_ctype_b_loc())[a1] & 0x800) != 0 )
return (unsigned int)((char)a1 - 48);
v1 = _ctype_toupper_loc();
v2 = strchr("WRGBCMYWLD", (*v1)[a1]);
if ( v2 )
result = v2 - "WRGBCMYWLD";
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int color2equate(char c) {
   char *i;
   if (((*__ctype_b_loc ())[(int) (((unsigned char)c))] & (unsigned short int) _ISdigit)) {
       return((c-'0'));
   } else if ((i=strchr(COLORTAB, toupper((unsigned char)c)))) {
       return((int)(i-COLORTAB));
   } else {
       return(-1);
   }
}

canonical_original_code:
int color2equate(char c) {
   char *i;
   if (((*__ctype_b_loc ())[(int) (((unsigned char)c))] & (unsigned short) _ISdigit)) {
       return((c-'0'));
   } else if ((i=strchr(COLORTAB, toupper((unsigned char)c)))) {
       return((int)(i-COLORTAB));
   } else {
       return(-1);
   }
}

variable_types: c char

variable_types:
i
char *


decompiled_code:
__int64 __fastcall equate2masktype(int a1)
{
return (unsigned int)byte_4535[a1 % 4];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned int)byte_4535[a1 % 4];
}

original_code:
int equate2masktype(int c) {
   return(MASKTYPE[c%4]);
}


decompiled_code:
__int64 __fastcall masktype2equate(unsigned __int8 a1)
{
const __int32_t **v1; // rax
char *v2; // rax
__int64 result; // rax

v1 = _ctype_toupper_loc();
v2 = strchr(byte_4535, (*v1)[a1]);
if ( v2 )
result = v2 - byte_4535;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
const __int32_t **v1; // rax
char *v2; // rax
__int64 result; // rax

v1 = _ctype_toupper_loc();
v2 = strchr(byte_4535, (*v1)[a1]);
if ( v2 )
result = v2 - byte_4535;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int masktype2equate(char c) {
   char *i;
   if ((i=strchr(MASKTYPE, toupper((unsigned char)c)))) {
       return((int)(i-MASKTYPE));
   } else {
       return(-1);
   }
}


decompiled_code:
__int64 __fastcall equate2linetype(int a1)
{
return (unsigned int)*(&byte_453A + a1 % 7);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return (unsigned int)*(&byte_453A + a1 % 7);
}

original_code:
int equate2linetype(int c) {
   return(LINETYPE[c%7]);
}


decompiled_code:
__int64 __fastcall linetype2equate(unsigned __int8 a1)
{
const __int32_t **v1; // rax
char *v2; // rax
__int64 result; // rax

if ( ((*_ctype_b_loc())[a1] & 0x800) != 0 )
return (unsigned int)(((char)a1 - 48) % 7);
v1 = _ctype_toupper_loc();
v2 = strchr("SDB34567", (*v1)[a1]);
if ( v2 )
result = v2 - "SDB34567";
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
const __int32_t **v1; // rax
char *v2; // rax
__int64 result; // rax

if ( ((*_ctype_b_loc())[a1] & 0x800) != 0 )
return (unsigned int)(((char)a1 - 48) % 7);
v1 = _ctype_toupper_loc();
v2 = strchr("SDB34567", (*v1)[a1]);
if ( v2 )
result = v2 - "SDB34567";
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int linetype2equate(char c) {
   char *i;
   if (((*__ctype_b_loc ())[(int) (((unsigned char)c))] & (unsigned short int) _ISdigit)) {
 return((c-'0')%7);
   } else if ((i=strchr(LINETYPE, toupper((unsigned char)c)))) {
       return((int)(i-LINETYPE));
   } else {
       return(-1);
   }
}

canonical_original_code:
int linetype2equate(char c) {
   char *i;
   if (((*__ctype_b_loc ())[(int) (((unsigned char)c))] & (unsigned short) _ISdigit)) {
 return((c-'0')%7);
   } else if ((i=strchr(LINETYPE, toupper((unsigned char)c)))) {
       return((int)(i-LINETYPE));
   } else {
       return(-1);
   }
}


decompiled_code:
__int64 equate_print()
{
__int64 i; // rbx
__int64 v1; // rbp
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

for ( i = 0LL; i != 1024; ++i )
{
if ( (equates[16 * (int)i + 2] & 1) != 0 )
{
v1 = 16LL * (int)i;
v2 = equate2color(equates[v1] & 0xF);
printf("EQUATE :C%c ", v2);
printf(":P%d ", ((unsigned __int8)equates[v1 + 1] >> 2) & 7);
v3 = equate2linetype((unsigned __int8)equates[v1 + 1] >> 5);
printf(":M%c ", v3);
v4 = equate2masktype(equates[v1 + 1] & 3);
printf(":%c ", v4);
printf(":F%d ", ((unsigned __int8)equates[v1] >> 4) & 7);
if ( equates[v1] < 0 )
printf(":O ");
printf("%s %d;\n", *(const char **)&equates[16 * i + 8], (unsigned int)i);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 i; // rbx
__int64 v1; // rbp
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

for ( i = 0LL; i != 1024; ++i )
{
if ( (equates[16 * (int)i + 2] & 1) != 0 )
{
v1 = 16LL * (int)i;
v2 = func1(equates[v1] & 0xF);
printf("EQUATE :C%c ", v2);
printf(":P%d ", ((unsigned __int8)equates[v1 + 1] >> 2) & 7);
v3 = func5((unsigned __int8)equates[v1 + 1] >> 5);
printf(":M%c ", v3);
v4 = func3(equates[v1 + 1] & 3);
printf(":%c ", v4);
printf(":F%d ", ((unsigned __int8)equates[v1] >> 4) & 7);
if ( equates[v1] < 0 )
printf(":O ");
printf("%s %d;\n", *(const char **)&equates[16 * i + 8], (unsigned int)i);
}
}
return 0LL;
}

original_code:
int equate_print() {
    int i;
    for (i=0; i<1024; i++) {
 if (equates[i].flags.used) {
     printf("EQUATE :C%c ", equate2color(equates[i].flags.color));
     printf(":P%d ", equates[i].flags.pen);
     printf(":M%c ", equate2linetype(equates[i].flags.linetype));
     printf(":%c ", equate2masktype(equates[i].flags.masktype));
     printf(":F%d ", equates[i].flags.fill);
     if (equates[i].flags.override) {
      printf(":O ");
     }
     printf("%s %d;\n", equates[i].label, i);
 }
    };
    return(0);
}

variable_types: i int


decompiled_code:
__int64 equate_clear_overrides()
{
int i; // edx
__int64 result; // rax

for ( i = 0; i != 1024; ++i )
{
result = 16LL * i;
equates[result] &= 0x7Fu;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int i; // edx
__int64 result; // rax

for ( i = 0; i != 1024; ++i )
{
result = 16LL * i;
equates[result] &= 0x7Fu;
}
return result;
}

original_code:
void equate_clear_overrides(void) {
    int i;
    for (i=0; i<1024; i++) {
 equates[i].flags.override=0;
    }
}

canonical_original_code:
void equate_clear_overrides() {
    int i;
    for (i=0; i<1024; i++) {
 equates[i].flags.override=0;
    }
}

return_type: void


decompiled_code:
int __fastcall equate_toggle_override(unsigned int a1)
{
__int64 v1; // rax

if ( a1 > 0x3FF )
{
LODWORD(v1) = printf("invalid layer %d\n", a1);
}
else
{
v1 = 16LL * (int)a1;
if ( equates[v1] < 0 )
equates[16 * a1] &= 0x7Fu;
else
equates[16 * a1] |= 0x80u;
}
return v1;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
__int64 v1; // rax

if ( a1 > 0x3FF )
{
LODWORD(v1) = printf("invalid layer %d\n", a1);
}
else
{
v1 = 16LL * (int)a1;
if ( equates[v1] < 0 )
equates[16 * a1] &= 0x7Fu;
else
equates[16 * a1] |= 0x80u;
}
return v1;
}

original_code:
void equate_toggle_override(int layer) {
    if (layer < 1024 && layer >= 0) {
 if (equates[layer].flags.override==0) {
     equates[layer].flags.override=1;
 } else {
     equates[layer].flags.override=0;
 }
    } else {
        printf("invalid layer %d\n", layer);
    }
}

variable_types: layer int


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

result = 0LL;
if ( a1 <= 0x3FF )
result = (unsigned __int8)equates[16 * a1] >> 7;
return result;
}

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

result = 0LL;
if ( a1 <= 0x3FF )
result = (unsigned __int8)equates[16 * a1] >> 7;
return result;
}

original_code:
int equate_get_override(int layer) {
    if (layer < 1024 && layer >= 0) {
        return(equates[layer].flags.override);
    }
    return(0);
}


decompiled_code:
__int64 __fastcall equate_set_linetype(int a1, int a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = (unsigned int)(32 * a2);
equates[v2 + 1] = (32 * a2) | equates[v2 + 1] & 0x1F;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = (unsigned int)(32 * a2);
equates[v2 + 1] = (32 * a2) | equates[v2 + 1] & 0x1F;
return result;
}

original_code:
void equate_set_linetype(int layer, int linetype) {
    equates[layer].flags.used=1;
    equates[layer].flags.linetype = linetype;
}

variable_types: linetype int


decompiled_code:
__int64 __fastcall equate_get_linetype(int a1)
{
return (unsigned __int8)equates[16 * a1 + 1] >> 5;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return (unsigned __int8)equates[16 * a1 + 1] >> 5;
}

original_code:
int equate_get_linetype(int layer) {
    return(equates[layer].flags.linetype);
}


decompiled_code:
__int64 __fastcall equate_set_masktype(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = a2 & 3;
equates[v2 + 1] = result | equates[v2 + 1] & 0xFC;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = a2 & 3;
equates[v2 + 1] = result | equates[v2 + 1] & 0xFC;
return result;
}

original_code:
void equate_set_masktype(int layer, int masktype) {
    equates[layer].flags.used=1;
    equates[layer].flags.masktype = masktype;
}

variable_types: masktype int


decompiled_code:
__int64 __fastcall equate_get_masktype(int a1)
{
return equates[16 * a1 + 1] & 3;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return equates[16 * a1 + 1] & 3;
}

original_code:
int equate_get_masktype(int layer) {
    return(equates[layer].flags.masktype);
}


decompiled_code:
__int64 __fastcall equate_set_fill(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = 16 * (a2 & 7u);
equates[v2] = (16 * (a2 & 7)) | equates[v2] & 0x8F;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = 16 * (a2 & 7u);
equates[v2] = (16 * (a2 & 7)) | equates[v2] & 0x8F;
return result;
}

original_code:
void equate_set_fill(int layer, int fill) {
    equates[layer].flags.used=1;
    equates[layer].flags.fill = fill;
}

variable_types: fill int


decompiled_code:
__int64 __fastcall equate_get_fill(int a1)
{
return ((unsigned __int8)equates[16 * a1] >> 4) & 7;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
return ((unsigned __int8)equates[16 * a1] >> 4) & 7;
}

original_code:
int equate_get_fill(int layer) {
    return(equates[layer].flags.fill);
}


decompiled_code:
__int64 __fastcall equate_set_color(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = a2 & 0xF;
equates[v2] = result | equates[v2] & 0xF0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = a2 & 0xF;
equates[v2] = result | equates[v2] & 0xF0;
return result;
}

original_code:
void equate_set_color(int layer, int color) {
    equates[layer].flags.used=1;
    equates[layer].flags.color = color;
}

variable_types: color int


decompiled_code:
__int64 __fastcall equate_get_color(int a1)
{
return equates[16 * a1] & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
return equates[16 * a1] & 0xF;
}

original_code:
int equate_get_color(int layer) {
    return(equates[layer].flags.color);
}


decompiled_code:
__int64 __fastcall equate_set_pen(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = 4 * (a2 & 7u);
equates[v2 + 1] = (4 * (a2 & 7)) | equates[v2 + 1] & 0xE3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
equates[v2 + 2] |= 1u;
result = 4 * (a2 & 7u);
equates[v2 + 1] = (4 * (a2 & 7)) | equates[v2 + 1] & 0xE3;
return result;
}

original_code:
void equate_set_pen(int layer, int pen) {
    equates[layer].flags.used=1;
    equates[layer].flags.pen = pen;
}

variable_types: pen int


decompiled_code:
__int64 __fastcall equate_get_pen(int a1)
{
return ((unsigned __int8)equates[16 * a1 + 1] >> 2) & 7;
}

canonical_decompiled_code:
__int64 __fastcall func20(int a1)
{
return ((unsigned __int8)equates[16 * a1 + 1] >> 2) & 7;
}

original_code:
int equate_get_pen(int layer) {
    return(equates[layer].flags.pen);
}


decompiled_code:
__int64 __fastcall equate_set_label(int a1, __int64 a2)
{
__int64 v3; // rax
void *v4; // rdi
__int64 result; // rax

v3 = 16LL * a1;
equates[v3 + 2] |= 1u;
v4 = *(void **)&equates[v3 + 8];
if ( v4 )
free(v4);
result = strsave(a2);
*(_QWORD *)&equates[16 * a1 + 8] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1, __int64 a2)
{
__int64 v3; // rax
void *v4; // rdi
__int64 result; // rax

v3 = 16LL * a1;
equates[v3 + 2] |= 1u;
v4 = *(void **)&equates[v3 + 8];
if ( v4 )
free(v4);
result = strsave(a2);
*(_QWORD *)&equates[16 * a1 + 8] = result;
return result;
}

original_code:
void equate_set_label(int layer, char *label) {
    equates[layer].flags.used=1;
    if (equates[layer].label != ((void *)0)) {
     free(equates[layer].label);
    }
    equates[layer].label = strsave(label);
}

variable_types:
label
char *


decompiled_code:
__int64 __fastcall equate_get_label(int a1)
{
return *(_QWORD *)&equates[16 * a1 + 8];
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1)
{
return *(_QWORD *)&equates[16 * a1 + 8];
}

original_code:
char *equate_get_label(int layer) {
    return(equates[layer].label);
}

return_type: char *


progname

decompiled_code:
__int64 progname()
{
return name;
}

canonical_decompiled_code:
__int64 func0()
{
return name;
}

original_code:
char *progname(void)
{
    return(name);
}

canonical_original_code:
char *progname()
{
    return(name);
}


eprintf

decompiled_code:
void __noreturn eprintf(char *s, ...)
{
const char *v1; // rax
int *v2; // rax
char *v3; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fflush(stdout);
v1 = (const char *)progname();
if ( v1 )
fprintf(stderr, "%s: ", v1);
va_start(arg, s);
vfprintf(stderr, s, arg);
if ( *s )
{
if ( s[strlen(s) - 1] == 58 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, " %s", v3);
}
}
fputc(10, stderr);
exit(2);
}

canonical_decompiled_code:
void __noreturn func1(char *s, ...)
{
const char *v1; // rax
int *v2; // rax
char *v3; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fflush(stdout);
v1 = (const char *)func0();
if ( v1 )
fprintf(stderr, "%s: ", v1);
va_start(arg, s);
vfprintf(stderr, s, arg);
if ( *s )
{
if ( s[strlen(s) - 1] == 58 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, " %s", v3);
}
}
fputc(10, stderr);
exit(2);
}

original_code:
void eprintf(char *fmt, ...)
{
    va_list args;
    fflush(stdout);
    if(progname() != ((void *)0))
 fprintf(stderr, "%s: ", progname());
    __builtin_va_start(args,fmt);
    vfprintf(stderr, fmt, args);
    __builtin_va_end(args);
    if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
 fprintf(stderr, " %s", strerror((*__errno_location ())));
    fprintf(stderr, "\n");
    exit(2);
}

canonical_original_code:
void eprintf(char *fmt, ...)
{
    __builtin_va_list args;
    fflush(stdout);
    if(progname() != ((void *)0))
 fprintf(stderr, "%s: ", progname());
    __builtin_va_start(args,fmt);
    vfprintf(stderr, fmt, args);
    __builtin_va_end(args);
    if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
 fprintf(stderr, " %s", strerror((*__errno_location ())));
    fprintf(stderr, "\n");
    exit(2);
}

variable_types:
fmt
char *


estrdup

decompiled_code:
char *__fastcall estrdup(const char *a1)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(a1);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
eprintf("estrdup(\"%.20s\") failed:", a1);
return strcpy(v2, a1);
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(a1);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
func1("estrdup(\"%.20s\") failed:", a1);
return strcpy(v2, a1);
}

original_code:
char *estrdup(const char *s)
{
    char *t;
    t = (char *) malloc(strlen(s)+1);
    if (t == ((void *)0))
 eprintf("estrdup(\"%.20s\") failed:", s);
    strcpy(t,s);
    return(t);
}

canonical_original_code:
char *estrdup(char *s)
{
    char *t;
    t = (char *) malloc(strlen(s)+1);
    if (t == ((void *)0))
 eprintf("estrdup(\"%.20s\") failed:", s);
    strcpy(t,s);
    return(t);
}

variable_types:
s
char *

variable_types:
t
char *


setprogname

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

result = estrdup(a1);
name = (__int64)result;
return result;
}

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

result = func2(a1);
name = (__int64)result;
return result;
}

original_code:
void setprogname(const char *str)
{
    name = estrdup(str);
}

canonical_original_code:
void setprogname(char *str)
{
    name = estrdup(str);
}

variable_types:
str
char *


emalloc

decompiled_code:
void *__fastcall emalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
eprintf("malloc of %u bytes failed:", a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func4(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func1("malloc of %u bytes failed:", a1);
return result;
}

original_code:
void *emalloc(size_t n)
{
    void *p;
    p = (void *) malloc(n);
    if (p == ((void *)0))
 eprintf("malloc of %u bytes failed:", n);
    return(p);
}

canonical_original_code:
void *emalloc(unsigned long n)
{
    void *p;
    p = (void *) malloc(n);
    if (p == ((void *)0))
 eprintf("malloc of %u bytes failed:", n);
    return(p);
}

variable_types:
n
unsigned long

variable_types:
p
void *

return_type: void *


erealloc

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

result = realloc(a1, a2);
if ( !result )
eprintf("eralloc of %u bytes failed:", a2);
return result;
}

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

result = realloc(a1, a2);
if ( !result )
func1("eralloc of %u bytes failed:", a2);
return result;
}

original_code:
void *erealloc(void *p, size_t n)
{
    void *newp;
    newp = (void *) realloc(p, n);
    if (newp == ((void *)0))
 eprintf("eralloc of %u bytes failed:", n);
    return(newp);
}

canonical_original_code:
void *erealloc(void *p, unsigned long n)
{
    void *newp;
    newp = (void *) realloc(p, n);
    if (newp == ((void *)0))
 eprintf("eralloc of %u bytes failed:", n);
    return(newp);
}

variable_types:
newp
void *


weprintf

decompiled_code:
int weprintf(char *s, ...)
{
const char *v1; // rax
int *v3; // rax
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fflush(stdout);
v1 = (const char *)progname();
if ( v1 )
fprintf(stderr, "%s: ", v1);
va_start(arg, s);
vfprintf(stderr, s, arg);
if ( *s && s[strlen(s) - 1] == 58 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, " %s", v4);
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int func6(char *s, ...)
{
const char *v1; // rax
int *v3; // rax
char *v4; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

fflush(stdout);
v1 = (const char *)func0();
if ( v1 )
fprintf(stderr, "%s: ", v1);
va_start(arg, s);
vfprintf(stderr, s, arg);
if ( *s && s[strlen(s) - 1] == 58 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, " %s", v4);
}
return fputc(10, stderr);
}

original_code:
void weprintf(char *fmt, ...)
{
    va_list args;
    fflush(stdout);
    if(progname() != ((void *)0))
 fprintf(stderr, "%s: ", progname());
    __builtin_va_start(args,fmt);
    vfprintf(stderr, fmt, args);
    __builtin_va_end(args);
    if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
 fprintf(stderr, " %s", strerror((*__errno_location ())));
    fprintf(stderr, "\n");
}

canonical_original_code:
void weprintf(char *fmt, ...)
{
    __builtin_va_list args;
    fflush(stdout);
    if(progname() != ((void *)0))
 fprintf(stderr, "%s: ", progname());
    __builtin_va_start(args,fmt);
    vfprintf(stderr, fmt, args);
    __builtin_va_end(args);
    if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
 fprintf(stderr, " %s", strerror((*__errno_location ())));
    fprintf(stderr, "\n");
}


hash

decompiled_code:
__int64 __fastcall hash(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl
unsigned __int8 *v2; // rbp
const __int32_t *v3; // rcx
unsigned int v4; // edx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = *_ctype_toupper_loc();
v4 = 0;
do
{
v4 = v3[v1] + 31 * v4;
v1 = *++v2;
}
while ( *v2 );
}
else
{
v4 = 0;
}
return v4 % 0x65;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl
unsigned __int8 *v2; // rbp
const __int32_t *v3; // rcx
unsigned int v4; // edx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = *_ctype_toupper_loc();
v4 = 0;
do
{
v4 = v3[v1] + 31 * v4;
v1 = *++v2;
}
while ( *v2 );
}
else
{
v4 = 0;
}
return v4 % 0x65;
}

original_code:
unsigned int hash(char *s)
{
    unsigned int hashval;
    for (hashval = 0; *s != '\0'; s++)
     hashval = toupper((unsigned char)*s)+31*hashval;
    return (hashval%101);
}

variable_types:
hashval
unsigned int

return_type: unsigned int


lookup

decompiled_code:
__int64 __fastcall lookup(char *s1)
{
__int64 i; // rbx

for ( i = hashtab[(unsigned int)hash((unsigned __int8 *)s1)]; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 i; // rbx

for ( i = hashtab[(unsigned int)func0((unsigned __int8 *)s1)]; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

original_code:
static struct varslot *lookup(char *s)
{
    struct varslot *vp;
    for (vp=hashtab[hash(s)]; vp!=((void *)0); vp=vp->next) {
 if (strcmp(s,vp->name) == 0) {
    return(vp);
 }
    }
    return ((void *)0);
}

variable_types: struct varslot { char *name; char *defn; enum BOOLEAN { FALSE=0, TRUE=1 } macro; enum BOOLEAN { FALSE=0, TRUE=1 } exported; struct varslot *next; } *

user_defined_types: struct varslot { char *name; char *defn; enum BOOLEAN macro; enum BOOLEAN exported; struct varslot *next; }


assign

decompiled_code:
__int64 __fastcall assign(char **a1, const char *a2)
{
int v3; // eax
char *v4; // rdi
char *v5; // rax
__int64 result; // rax
char *v7; // rax

v3 = strlen(a2) + 1;
v4 = *a1;
if ( v4 )
{
v5 = (char *)realloc(v4, v3);
*a1 = v5;
if ( v5 )
{
LABEL_3:
strcpy(*a1, a2);
return 1LL;
}
result = 0LL;
}
else
{
v7 = (char *)malloc(v3);
*a1 = v7;
if ( v7 )
goto LABEL_3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1, const char *a2)
{
int v3; // eax
char *v4; // rdi
char *v5; // rax
__int64 result; // rax
char *v7; // rax

v3 = strlen(a2) + 1;
v4 = *a1;
if ( v4 )
{
v5 = (char *)realloc(v4, v3);
*a1 = v5;
if ( v5 )
{
LABEL_3:
strcpy(*a1, a2);
return 1LL;
}
result = 0LL;
}
else
{
v7 = (char *)malloc(v3);
*a1 = v7;
if ( v7 )
goto LABEL_3;
result = 0LL;
}
return result;
}

canonical_original_code:
enum BOOLEAN assign(char **p, char *s)
{
    int size;
    size = strlen(s) + 1;
    if (*p == ((void *)0)) {
        if ((*p = malloc(size)) == ((void *)0)) {
     return(FALSE);
 }
    } else if ((*p = realloc(*p,size)) == ((void *)0)) {
        return(FALSE);
    }
    strcpy(*p, s);
    return(TRUE);
}

variable_types:
p
char **

variable_types: size int

return_type: enum BOOLEAN { FALSE=0, TRUE=1 }


EVset

decompiled_code:
void *__fastcall EVset(char *s, const char *a2)
{
void *v2; // rbx
char *v4; // rax
int v5; // eax

v2 = (void *)lookup(s);
if ( !v2 )
{
v2 = malloc(0x20uLL);
*((_DWORD *)v2 + 5) = 0;
*((_DWORD *)v2 + 4) = 0;
*((_QWORD *)v2 + 1) = 0LL;
v4 = strdup(s);
*(_QWORD *)v2 = v4;
if ( !v4 )
return 0LL;
v5 = hash((unsigned __int8 *)s);
*((_QWORD *)v2 + 3) = hashtab[v5];
hashtab[v5] = (__int64)v2;
}
assign((char **)v2 + 1, a2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(char *s, const char *a2)
{
void *v2; // rbx
char *v4; // rax
int v5; // eax

v2 = (void *)func1(s);
if ( !v2 )
{
v2 = malloc(0x20uLL);
*((_DWORD *)v2 + 5) = 0;
*((_DWORD *)v2 + 4) = 0;
*((_QWORD *)v2 + 1) = 0LL;
v4 = strdup(s);
*(_QWORD *)v2 = v4;
if ( !v4 )
return 0LL;
v5 = func0((unsigned __int8 *)s);
*((_QWORD *)v2 + 3) = hashtab[v5];
hashtab[v5] = (__int64)v2;
}
func2((char **)v2 + 1, a2);
return v2;
}

original_code:
struct varslot *EVset(char *name, char *defn)
{
    struct varslot *vp;
    unsigned hashval;
    if((vp=lookup(name)) == ((void *)0)) {
        vp = (struct varslot *) malloc(sizeof(*vp));
 vp->exported = FALSE;
 vp->macro=FALSE;
 vp->defn = ((void *)0);
 if ((vp == ((void *)0)) || (vp->name = strdup(name)) == ((void *)0)) {
     return(((void *)0));
 }
 hashval = hash(name);
 vp->next = hashtab[hashval];
 hashtab[hashval] = vp;
    }
    assign(&(vp->defn), defn);
    return(vp);
}

canonical_original_code:
struct varslot *EVset(char *name, char *defn)
{
    struct varslot *vp;
    unsigned int hashval;
    if((vp=lookup(name)) == ((void *)0)) {
        vp = (struct varslot *) malloc(sizeof(*vp));
 vp->exported = FALSE;
 vp->macro=FALSE;
 vp->defn = ((void *)0);
 if ((vp == ((void *)0)) || (vp->name = strdup(name)) == ((void *)0)) {
     return(((void *)0));
 }
 hashval = hash(name);
 vp->next = hashtab[hashval];
 hashtab[hashval] = vp;
    }
    assign(&(vp->defn), defn);
    return(vp);
}

variable_types:
name
char *

variable_types:
defn
char *

return_type: struct varslot { char *name; char *defn; enum BOOLEAN { FALSE=0, TRUE=1 } macro; enum BOOLEAN { FALSE=0, TRUE=1 } exported; struct varslot *next; } *


strtoupper

decompiled_code:
void __fastcall strtoupper(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl
unsigned __int8 *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl
unsigned __int8 *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void strtoupper(char *name) {
    char *p;
    for (p=name; *p!='\0'; p++) {
       *p = toupper((unsigned char)*p);
    }
}

variable_types:
p
char *


Macroget

decompiled_code:
__int64 __fastcall Macroget(char *s1)
{
__int64 result; // rax

strtoupper((unsigned __int8 *)s1);
result = lookup(s1);
if ( result )
{
if ( *(_DWORD *)(result + 16) )
result = *(_QWORD *)(result + 8);
else
result = 0LL;
}
return result;
}

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

func4((unsigned __int8 *)s1);
result = func1(s1);
if ( result )
{
if ( *(_DWORD *)(result + 16) )
result = *(_QWORD *)(result + 8);
else
result = 0LL;
}
return result;
}

original_code:
char *Macroget(char *name)
{
    struct varslot *vp;
    strtoupper(name);
    if (((vp=lookup(name)) == ((void *)0)) || !(vp->macro)) {
        return(((void *)0));
    }
    return(vp->defn);
}


EVexport

decompiled_code:
__int64 __fastcall EVexport(char *a1)
{
__int64 v1; // rax

v1 = lookup(a1);
if ( !v1 )
return 0LL;
*(_DWORD *)(v1 + 20) = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
__int64 v1; // rax

v1 = func1(a1);
if ( !v1 )
return 0LL;
*(_DWORD *)(v1 + 20) = 1;
return 1LL;
}

canonical_original_code:
enum BOOLEAN EVexport(char *name)
{
    struct varslot *vp;
    if ((vp=lookup(name)) == ((void *)0)) {
        return(FALSE);
    }
    vp->exported = TRUE;
    return(TRUE);
}


EVget

decompiled_code:
__int64 __fastcall EVget(char *a1)
{
__int64 result; // rax

result = lookup(a1);
if ( result )
{
if ( *(_DWORD *)(result + 16) )
result = 0LL;
else
result = *(_QWORD *)(result + 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
__int64 result; // rax

result = func1(a1);
if ( result )
{
if ( *(_DWORD *)(result + 16) )
result = 0LL;
else
result = *(_QWORD *)(result + 8);
}
return result;
}

original_code:
char *EVget(char *name)
{
    struct varslot *vp;
    if (((vp=lookup(name)) == ((void *)0)) || vp->macro) {
        return(((void *)0));
    }
    return(vp->defn);
}


EVinit

decompiled_code:
__int64 EVinit()
{
const char *v0; // rax
char **v1; // r13
char *v2; // rbp
__int64 i; // r12
size_t v4; // rbx
__int64 result; // rax
char v6[248]; // [rsp+0h] [rbp-F8h] BYREF

v0 = (const char *)hashtab;
do
{
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != "=" );
v1 = environ;
v2 = *environ;
if ( !*environ )
return 1LL;
for ( i = 1LL; ; ++i )
{
v4 = (int)strcspn(v2, "=");
strncpy(v6, v2, v4);
v6[v4] = 0;
if ( !EVset(v6, &(*v1)[v4 + 1]) )
break;
result = EVexport(v6);
if ( !(_DWORD)result )
return result;
v1 = &environ[i];
v2 = environ[i];
if ( !v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
const char *v0; // rax
char **v1; // r13
char *v2; // rbp
__int64 i; // r12
size_t v4; // rbx
__int64 result; // rax
char v6[248]; // [rsp+0h] [rbp-F8h] BYREF

v0 = (const char *)hashtab;
do
{
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != "=" );
v1 = environ;
v2 = *environ;
if ( !*environ )
return 1LL;
for ( i = 1LL; ; ++i )
{
v4 = (int)strcspn(v2, "=");
strncpy(v6, v2, v4);
v6[v4] = 0;
if ( !func3(v6, &(*v1)[v4 + 1]) )
break;
result = func6(v6);
if ( !(_DWORD)result )
return result;
v1 = &environ[i];
v2 = environ[i];
if ( !v2 )
return 1LL;
}
return 0LL;
}

original_code:
BOOLEAN EVinit()
{
    int i, namelen;
    char name[200];
    for (i=0; i<101; i++) {
       hashtab[i]=((void *)0);
    }
    for (i=0; environ[i] != ((void *)0); i++) {
        namelen = strcspn(environ[i], "=");
 strncpy(name,environ[i],namelen);
 name[namelen] = '\0';
 if (!EVset(name, &environ[i][namelen+1]) || !EVexport(name)) {
     return(FALSE);
 }
    }
    return(TRUE);
}

canonical_original_code:
enum BOOLEAN EVinit()
{
    int i; int namelen;
    char name[200];
    for (i=0; i<101; i++) {
       hashtab[i]=((void *)0);
    }
    for (i=0; environ[i] != ((void *)0); i++) {
        namelen = strcspn(environ[i], "=");
 strncpy(name,environ[i],namelen);
 name[namelen] = '\0';
 if (!EVset(name, &environ[i][namelen+1]) || !EVexport(name)) {
     return(FALSE);
 }
    }
    return(TRUE);
}

variable_types: i int

variable_types: namelen int

variable_types:
name
char [200]


EVupdate

decompiled_code:
__int64 EVupdate()
{
unsigned int v0; // er12
const char *v1; // rsi
int v2; // edx
__int64 i; // rax
const char *v4; // r13
int v5; // ebp
void **v6; // r12
void *v7; // rax
const char **v8; // rbx
int v9; // er12
int v10; // esi
char **v11; // r15
char *v12; // rax

v0 = updated_0;
if ( updated_0 )
goto LABEL_8;
v1 = (const char *)hashtab;
v2 = 0;
do
{
for ( i = *(_QWORD *)v1; i; i = *(_QWORD *)(i + 24) )
v2 += *(_DWORD *)(i + 20) == 1;
v1 += 8;
}
while ( "=" != v1 );
environ = (char **)malloc(8LL * (v2 + 1));
if ( environ )
{
LABEL_8:
v4 = (const char *)hashtab;
v5 = 0;
do
{
v8 = *(const char ***)v4;
if ( *(_QWORD *)v4 )
{
do
{
if ( *((_DWORD *)v8 + 5) )
{
v9 = strlen(*v8);
v10 = v9 + strlen(v8[1]) + 2;
v0 = updated_0;
if ( updated_0 )
{
v6 = (void **)&environ[v5];
v7 = realloc(*v6, v10);
*v6 = v7;
if ( !v7 )
return 0;
}
else
{
v11 = &environ[v5];
v12 = (char *)malloc(v10);
*v11 = v12;
if ( !v12 )
return v0;
}
sprintf(environ[v5++], "%s=%s", *v8, v8[1]);
}
v8 = (const char **)v8[3];
}
while ( v8 );
}
v4 += 8;
}
while ( "=" != v4 );
environ[v5] = 0LL;
updated_0 = 1;
v0 = 1;
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er12
const char *v1; // rsi
int v2; // edx
__int64 i; // rax
const char *v4; // r13
int v5; // ebp
void **v6; // r12
void *v7; // rax
const char **v8; // rbx
int v9; // er12
int v10; // esi
char **v11; // r15
char *v12; // rax

v0 = updated_0;
if ( updated_0 )
goto LABEL_8;
v1 = (const char *)hashtab;
v2 = 0;
do
{
for ( i = *(_QWORD *)v1; i; i = *(_QWORD *)(i + 24) )
v2 += *(_DWORD *)(i + 20) == 1;
v1 += 8;
}
while ( "=" != v1 );
environ = (char **)malloc(8LL * (v2 + 1));
if ( environ )
{
LABEL_8:
v4 = (const char *)hashtab;
v5 = 0;
do
{
v8 = *(const char ***)v4;
if ( *(_QWORD *)v4 )
{
do
{
if ( *((_DWORD *)v8 + 5) )
{
v9 = strlen(*v8);
v10 = v9 + strlen(v8[1]) + 2;
v0 = updated_0;
if ( updated_0 )
{
v6 = (void **)&environ[v5];
v7 = realloc(*v6, v10);
*v6 = v7;
if ( !v7 )
return 0;
}
else
{
v11 = &environ[v5];
v12 = (char *)malloc(v10);
*v11 = v12;
if ( !v12 )
return v0;
}
sprintf(environ[v5++], "%s=%s", *v8, v8[1]);
}
v8 = (const char **)v8[3];
}
while ( v8 );
}
v4 += 8;
}
while ( "=" != v4 );
environ[v5] = 0LL;
updated_0 = 1;
v0 = 1;
}
return v0;
}

original_code:
BOOLEAN EVupdate()
{
    int i, envi, nvlen;
    struct varslot *vp;
    static BOOLEAN updated = FALSE;
    int count;
    if (!updated) {
 count = 0;
 for (i=0; i<101; i++) {
     for (vp = hashtab[i]; vp != ((void *)0); vp = vp->next) {
  if (vp->exported == TRUE) {
      count++;
  }
     }
 }
        if ((environ = (char **) malloc((count + 1) * sizeof(char *))) == ((void *)0)) {
     return(FALSE);
 }
    }
    envi = 0;
    for (i=0; i<101; i++) {
 for (vp = hashtab[i]; vp != ((void *)0); vp = vp->next) {
     if (!vp->exported) {
  continue;
     }
     nvlen = strlen(vp->name) + strlen(vp->defn) + 2;
     if (!updated) {
  if ((environ[envi] = malloc(nvlen)) == ((void *)0)) {
      return(FALSE);
  }
     } else if ((environ[envi] = realloc(environ[envi], nvlen)) == ((void *)0)) {
  return(FALSE);
     }
     sprintf(environ[envi], "%s=%s", vp->name, vp->defn);
     envi++;
 }
    }
   environ[envi]=((void *)0);
   updated = TRUE;
   return(TRUE);
}

canonical_original_code:
enum BOOLEAN EVupdate()
{
    int i; int envi; int nvlen;
    struct varslot *vp;
    static enum BOOLEAN updated = FALSE;
    int count;
    if (!updated) {
 count = 0;
 for (i=0; i<101; i++) {
     for (vp = hashtab[i]; vp != ((void *)0); vp = vp->next) {
  if (vp->exported == TRUE) {
      count++;
  }
     }
 }
        if ((environ = (char **) malloc((count + 1) * sizeof(char *))) == ((void *)0)) {
     return(FALSE);
 }
    }
    envi = 0;
    for (i=0; i<101; i++) {
 for (vp = hashtab[i]; vp != ((void *)0); vp = vp->next) {
     if (!vp->exported) {
  continue;
     }
     nvlen = strlen(vp->name) + strlen(vp->defn) + 2;
     if (!updated) {
  if ((environ[envi] = malloc(nvlen)) == ((void *)0)) {
      return(FALSE);
  }
     } else if ((environ[envi] = realloc(environ[envi], nvlen)) == ((void *)0)) {
  return(FALSE);
     }
     sprintf(environ[envi], "%s=%s", vp->name, vp->defn);
     envi++;
 }
    }
   environ[envi]=((void *)0);
   updated = TRUE;
   return(TRUE);
}

variable_types: envi int

variable_types: nvlen int

variable_types:
updated
enum BOOLEAN { FALSE=0, TRUE=1 }

variable_types: count int


EVprint

original_code:
void EVprint(int mode)
{
    struct varslot *vp;
    int i;
    char *flag;
    for (i=0; i<101; i++) {
 for (vp = hashtab[i]; vp != ((void *)0); vp = vp->next) {
     if (((mode & 1) && vp->exported) ||
                ((mode & 2) && !vp->exported) ||
                ((mode & 4) && vp->macro)) {
      if (vp->macro) {
   flag="M";
      } else if (vp->exported) {
   flag="E";
      } else {
   flag="P";
      }
         printf("[%s] %s=\"%s\"\n", flag, vp->name, vp->defn);
     }
 }
    }
}

variable_types: mode int

variable_types:
flag
char *


decompiled_code:
__int64 __fastcall smash_draw_box(int a1, double a2, double a3)
{
_DWORD v4[18]; // [rsp+0h] [rbp-48h] BYREF

v4[8] = 0;
if ( !a1
|| (db_drawbounds(1LL, *(double *)&x1old_0, *(double *)&y1old_1, *(double *)&x2old_2, *(double *)&y2old_3), a1 > 0) )
{
db_drawbounds(1LL, *(double *)&x1, *(double *)&yy1, a2, a3);
}
x1old_0 = x1;
y1old_1 = yy1;
x2old_2 = *(_QWORD *)&a2;
y2old_3 = *(_QWORD *)&a3;
return jump(v4, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3)
{
_DWORD v4[18]; // [rsp+0h] [rbp-48h] BYREF

v4[8] = 0;
if ( !a1
|| (db_drawbounds(1LL, *(double *)&x1old_0, *(double *)&y1old_1, *(double *)&x2old_2, *(double *)&y2old_3), a1 > 0) )
{
db_drawbounds(1LL, *(double *)&x1, *(double *)&yy1, a2, a3);
}
x1old_0 = x1;
y1old_1 = yy1;
x2old_2 = *(_QWORD *)&a2;
y2old_3 = *(_QWORD *)&a3;
return jump(v4, 1LL);
}

original_code:
void smash_draw_box(double x2, double y2, int count)
{
        static double x1old, x2old, y1old, y2old;
        BOUNDS bb;
        bb.init=0;
        if (count == 0) {
            db_drawbounds(x1,yy1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,yy1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=yy1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}

canonical_original_code:
void smash_draw_box(double x2, double y2, int count)
{
        static double x1old; static double x2old; static double y1old; static double y2old;
        struct bounds bb;
        bb.init=0;
        if (count == 0) {
            db_drawbounds(x1,yy1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,yy1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=yy1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}

variable_types: struct bounds { double xmin; double ymin; double xmax; double ymax; int init; }


smashrep

decompiled_code:
int __fastcall smashrep(__int64 a1)
{
_QWORD *v1; // rdx
double *v2; // rax
__int64 v3; // rax
int result; // eax
__int64 i; // rbp
__int64 v6; // rax

if ( !a1 )
return puts("nothing here to smash, try SHO #e command?");
v1 = *(_QWORD **)(a1 + 8);
v2 = (double *)v1[1];
if ( 1.0 == v2[8] && v2[9] == 0.0 )
{
for ( i = *(_QWORD *)(db_lookup(*v1) + 4328); i; i = *(_QWORD *)(i + 48) )
{
v6 = db_copy_component(i, a1);
db_insert_component(currep, v6);
}
db_unlink_component(currep, a1);
result = currep;
++*(_DWORD *)(currep + 4308LL);
++need_redraw;
}
else if ( fmod(v2[5], 90.0) == 0.0 )
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
if ( 1.0 == *(double *)(v3 + 64) )
{
if ( *(double *)(v3 + 72) == 0.0 )
result = puts("can't smash this instance");
else
result = puts("can't smash slanted instances");
}
else
{
result = puts("can't smash instances with non-unity aspect ratios");
}
}
else
{
result = puts("can't smash instances with non-orthogonal rotations");
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
_QWORD *v1; // rdx
double *v2; // rax
__int64 v3; // rax
int result; // eax
__int64 i; // rbp
__int64 v6; // rax

if ( !a1 )
return puts("nothing here to smash, try SHO #e command?");
v1 = *(_QWORD **)(a1 + 8);
v2 = (double *)v1[1];
if ( 1.0 == v2[8] && v2[9] == 0.0 )
{
for ( i = *(_QWORD *)(db_lookup(*v1) + 4328); i; i = *(_QWORD *)(i + 48) )
{
v6 = db_copy_component(i, a1);
db_insert_component(currep, v6);
}
db_unlink_component(currep, a1);
result = currep;
++*(_DWORD *)(currep + 4308LL);
++need_redraw;
}
else if ( fmod(v2[5], 90.0) == 0.0 )
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL);
if ( 1.0 == *(double *)(v3 + 64) )
{
if ( *(double *)(v3 + 72) == 0.0 )
result = puts("can't smash this instance");
else
result = puts("can't smash slanted instances");
}
else
{
result = puts("can't smash instances with non-unity aspect ratios");
}
}
else
{
result = puts("can't smash instances with non-orthogonal rotations");
}
return result;
}

original_code:
void smashrep(DB_DEFLIST *p_best) {
    DB_TAB *smashrep;
    DB_DEFLIST *p;
    DB_DEFLIST *dp;
    if ( p_best != ((void *)0) &&
 (p_best->u.i->opts->aspect_ratio == 1.0) &&
 (p_best->u.i->opts->slant == 0.0)) {
 smashrep=db_lookup(p_best->u.i->name);
 for (p=smashrep->dbhead; p!=(struct db_deflist *)0; p=p->next) {
     dp=db_copy_component(p, p_best);
     db_insert_component(currep, dp);
 }
 db_unlink_component(currep, p_best);
 currep->modified++;
 need_redraw++;
    } else {
 if (p_best != ((void *)0)) {
     if (fmod(p_best->u.i->opts->rotation, 90.0) != 0.0 ) {
        printf("can't smash instances with non-orthogonal rotations\n");
     } else if (p_best->u.i->opts->aspect_ratio != 1.0) {
        printf("can't smash instances with non-unity aspect ratios\n");
     } else if (p_best->u.i->opts->slant != 0.0) {
        printf("can't smash slanted instances\n");
     } else {
        printf("can't smash this instance\n");
     }
 } else {
    printf("nothing here to smash, try SHO #e command?\n");
 }
    }
}

canonical_original_code:
void smashrep(struct db_deflist *p_best) {
    struct db_tab *smashrep;
    struct db_deflist *p;
    struct db_deflist *dp;
    if ( p_best != ((void *)0) &&
 (p_best->u.i->opts->aspect_ratio == 1.0) &&
 (p_best->u.i->opts->slant == 0.0)) {
 smashrep=db_lookup(p_best->u.i->name);
 for (p=smashrep->dbhead; p!=(struct db_deflist *)0; p=p->next) {
     dp=db_copy_component(p, p_best);
     db_insert_component(currep, dp);
 }
 db_unlink_component(currep, p_best);
 currep->modified++;
 need_redraw++;
    } else {
 if (p_best != ((void *)0)) {
     if (fmod(p_best->u.i->opts->rotation, 90.0) != 0.0 ) {
        printf("can't smash instances with non-orthogonal rotations\n");
     } else if (p_best->u.i->opts->aspect_ratio != 1.0) {
        printf("can't smash instances with non-unity aspect ratios\n");
     } else if (p_best->u.i->opts->slant != 0.0) {
        printf("can't smash slanted instances\n");
     } else {
        printf("can't smash this instance\n");
     }
 } else {
    printf("nothing here to smash, try SHO #e command?\n");
 }
    }
}

variable_types: struct db_tab { char *name; double minx; double maxx; int seqflag; double vp_xmin; double vp_ymin; double old_xmin; double old_ymin; double scale; double xoffset; int show[1024]; int physical; int nestlevel; double grid_xd; double grid_yd; double grid_xs; double grid_ys; double grid_xo; double grid_yo; int grid_color; int logical_level; double lock_angle; int display_state; int modified; int being_edited; int flag; int is_tmp_rep; struct db_deflist { int type; union { struct db_arc { int layer; struct opt_list { double font_size; double height; int mirror; int font_num; int justification; int stepflag; int rows; int cols; double rotation; double width; double scale; double aspect_ratio; double slant; char *sname; char *cname; int bezier; } *opts; double x1; } *a; struct db_circ { int layer; struct opt_list *opts; double x1; } *c; struct db_inst { char *name; struct opt_list *opts; double x; double colx; double rowx; } *i; struct db_line { int layer; struct opt_list *opts; struct coord_list { struct coord_pair { double x; } coord; struct coord_list *next; struct coord_list *prev; } *coords; } *l; struct db_note { int layer; struct opt_list *opts; char *text; double x; } *n; struct db_oval { int layer; struct opt_list *opts; double x1; } *o; struct db_poly { int layer; struct opt_list *opts; struct coord_list *coords; } *p; struct db_rect { int layer; struct opt_list *opts; double x1; } *r; struct db_text { int layer; struct opt_list *opts; char *text; double x; } *t; } u; double xmin; struct db_deflist *next; struct db_deflist *prev; } *dbhead; struct stack { char *saved; int count; struct stack *next; } *undo; struct stack *redo; int chksum; char *background; int prims; struct db_tab *next; struct db_tab *prev; } *

user_defined_types: struct db_deflist { int type; union { struct db_arc *a; struct db_circ *c; struct db_inst *i; struct db_line *l; struct db_note *n; struct db_oval *o; struct db_poly *p; struct db_rect *r; struct db_text *t; } u; double xmin; struct db_deflist *next; struct db_deflist *prev; }

user_defined_types: struct db_tab { char *name; double minx; double maxx; int seqflag; double vp_xmin; double vp_ymin; double old_xmin; double old_ymin; double scale; double xoffset; int show[1024]; int physical; int nestlevel; double grid_xd; double grid_yd; double grid_xs; double grid_ys; double grid_xo; double grid_yo; int grid_color; int logical_level; double lock_angle; int display_state; int modified; int being_edited; int flag; int is_tmp_rep; struct db_deflist *dbhead; struct stack *undo; struct stack *redo; int chksum; char *background; int prims; struct db_tab *next; struct db_tab *prev; }

user_defined_types: struct db_arc { int layer; struct opt_list *opts; double x1; }

user_defined_types: struct db_line { int layer; struct opt_list *opts; struct coord_list *coords; }

user_defined_types: struct coord_list { struct coord_pair coord; struct coord_list *next; struct coord_list *prev; }


decompiled_code:
__int64 __fastcall coord_get(_QWORD *a1, int a2, _QWORD *a3, _QWORD *a4)
{
int v4; // eax
__int64 result; // rax
_QWORD *v6; // rax

if ( a2 <= 0 )
{
v6 = (_QWORD *)a1[3];
if ( a2 < 0 )
{
while ( 1 )
{
v6 = (_QWORD *)v6[3];
if ( !v6 )
break;
if ( !++a2 )
goto LABEL_13;
}
}
if ( a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
LABEL_13:
*a3 = *v6;
*a4 = v6[1];
result = 0LL;
}
}
else
{
v4 = 1;
if ( a2 > 1 )
{
while ( 1 )
{
a1 = (_QWORD *)a1[2];
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
}
if ( a2 == v4 )
{
LABEL_7:
*a3 = *a1;
*a4 = a1[1];
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2, _QWORD *a3, _QWORD *a4)
{
int v4; // eax
__int64 result; // rax
_QWORD *v6; // rax

if ( a2 <= 0 )
{
v6 = (_QWORD *)a1[3];
if ( a2 < 0 )
{
while ( 1 )
{
v6 = (_QWORD *)v6[3];
if ( !v6 )
break;
if ( !++a2 )
goto LABEL_13;
}
}
if ( a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
LABEL_13:
*a3 = *v6;
*a4 = v6[1];
result = 0LL;
}
}
else
{
v4 = 1;
if ( a2 > 1 )
{
while ( 1 )
{
a1 = (_QWORD *)a1[2];
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
}
if ( a2 == v4 )
{
LABEL_7:
*a3 = *a1;
*a4 = a1[1];
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int coord_get(COORDS *CP, int n, NUM *px, NUM *py)
{
    COORDS *tmp;
    int i;
    int err=0;
    if (n>0) {
 i=1;
 tmp = CP;
 while(i<n && (tmp = tmp->next) != ((void *)0)) {
     i++;
 }
 if (i!=n) {
     err = -1;
 } else {
     *px = tmp->coord.x;
     *py = tmp->coord.y;
 }
    } else {
 i=n;
 tmp = CP->prev;
 while(i<0 && (tmp = tmp->prev) != ((void *)0)) {
     i++;
 }
 if (i!=0) {
     err = -1;
 } else {
     *px = tmp->coord.x;
     *py = tmp->coord.y;
 }
    }
    return(err);
}

canonical_original_code:
int coord_get(struct coord_list *CP, int n, double *px, double *py)
{
    struct coord_list *tmp;
    int i;
    int err = 0;
    if (n>0) {
 i=1;
 tmp = CP;
 while(i<n && (tmp = tmp->next) != ((void *)0)) {
     i++;
 }
 if (i!=n) {
     err = -1;
 } else {
     *px = tmp->coord.x;
     *py = tmp->coord.y;
 }
    } else {
 i=n;
 tmp = CP->prev;
 while(i<0 && (tmp = tmp->prev) != ((void *)0)) {
     i++;
 }
 if (i!=0) {
     err = -1;
 } else {
     *px = tmp->coord.x;
     *py = tmp->coord.y;
 }
    }
    return(err);
}

variable_types: struct coord_list { struct coord_pair { double x; } coord; struct coord_list *next; struct coord_list *prev; } *

variable_types: n int

variable_types:
px
double *

variable_types:
py
double *

variable_types: err int


decompiled_code:
__int64 __fastcall coord_edit(__int64 a1, int a2, double a3, double a4)
{
int v4; // eax
__int64 result; // rax
__int64 v6; // rax

if ( a2 <= 0 )
{
v6 = *(_QWORD *)(a1 + 24);
if ( a2 < 0 )
{
while ( 1 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
break;
if ( !++a2 )
goto LABEL_13;
}
}
if ( a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
LABEL_13:
*(double *)v6 = a3;
*(double *)(v6 + 8) = a4;
result = 0LL;
}
}
else
{
v4 = 1;
if ( a2 > 1 )
{
while ( 1 )
{
a1 = *(_QWORD *)(a1 + 16);
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
}
if ( a2 == v4 )
{
LABEL_7:
*(double *)a1 = a3;
*(double *)(a1 + 8) = a4;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, double a3, double a4)
{
int v4; // eax
__int64 result; // rax
__int64 v6; // rax

if ( a2 <= 0 )
{
v6 = *(_QWORD *)(a1 + 24);
if ( a2 < 0 )
{
while ( 1 )
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
break;
if ( !++a2 )
goto LABEL_13;
}
}
if ( a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
LABEL_13:
*(double *)v6 = a3;
*(double *)(v6 + 8) = a4;
result = 0LL;
}
}
else
{
v4 = 1;
if ( a2 > 1 )
{
while ( 1 )
{
a1 = *(_QWORD *)(a1 + 16);
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
}
if ( a2 == v4 )
{
LABEL_7:
*(double *)a1 = a3;
*(double *)(a1 + 8) = a4;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int coord_edit(COORDS *CP, int n, NUM x, NUM y)
{
    COORDS *tmp;
    int i;
    int err=0;
    if (n>0) {
 i=1;
 tmp = CP;
 while(i<n && (tmp = tmp->next) != ((void *)0)) {
     i++;
 }
 if (i!=n) {
     err = -1;
 } else {
     tmp->coord.x = x;
     tmp->coord.y = y;
 }
    } else {
 i=n;
 tmp = CP->prev;
 while(i<0 && (tmp = tmp->prev) != ((void *)0)) {
     i++;
 }
 if (i!=0) {
     err = -1;
 } else {
     tmp->coord.x = x;
     tmp->coord.y = y;
 }
    }
    return(err);
}

canonical_original_code:
int coord_edit(struct coord_list *CP, int n, double x, double y)
{
    struct coord_list *tmp;
    int i;
    int err = 0;
    if (n>0) {
 i=1;
 tmp = CP;
 while(i<n && (tmp = tmp->next) != ((void *)0)) {
     i++;
 }
 if (i!=n) {
     err = -1;
 } else {
     tmp->coord.x = x;
     tmp->coord.y = y;
 }
    } else {
 i=n;
 tmp = CP->prev;
 while(i<0 && (tmp = tmp->prev) != ((void *)0)) {
     i++;
 }
 if (i!=0) {
     err = -1;
 } else {
     tmp->coord.x = x;
     tmp->coord.y = y;
 }
    }
    return(err);
}

variable_types: x double

variable_types: y double


decompiled_code:
__int64 __fastcall coord_count(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
return 1;
v2 = 1;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
return 1;
v2 = 1;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return v2;
}

original_code:
int coord_count(COORDS *CP)
{
    COORDS *tmp;
    int i;
    i=1;
    tmp = CP;
    while((tmp = tmp->next) != ((void *)0)) {
 i++;
    }
    return(i);
}

canonical_original_code:
int coord_count(struct coord_list *CP)
{
    struct coord_list *tmp;
    int i;
    i=1;
    tmp = CP;
    while((tmp = tmp->next) != ((void *)0)) {
 i++;
    }
    return(i);
}

variable_types: i int


original_code:
void coord_drop(COORDS *CP)
{
    COORDS *tmp;
    tmp = CP->prev;
    CP->prev = tmp->prev;
    tmp->prev->next = ((void *)0);
    free((COORDS *) tmp);
}

canonical_original_code:
void coord_drop(struct coord_list *CP)
{
    struct coord_list *tmp;
    tmp = CP->prev;
    CP->prev = tmp->prev;
    tmp->prev->next = ((void *)0);
    free((struct coord_list *) tmp);
}


original_code:
void coord_print(COORDS *CP)
{
    COORDS *tmp;
    int i;
    i=1;
    tmp = CP;
    while(tmp != ((void *)0)) {
 printf(" %g,%g", tmp->coord.x, tmp->coord.y);
 if ((tmp = tmp->next) != ((void *)0) && (++i)%4 == 0) {
     printf("\n");
 }
    }
    printf(";\n");
}

canonical_original_code:
void coord_print(struct coord_list *CP)
{
    struct coord_list *tmp;
    int i;
    i=1;
    tmp = CP;
    while(tmp != ((void *)0)) {
 printf(" %g,%g", tmp->coord.x, tmp->coord.y);
 if ((tmp = tmp->next) != ((void *)0) && (++i)%4 == 0) {
     printf("\n");
 }
    }
    printf(";\n");
}


decompiled_code:
double *__fastcall coord_copy(__int64 a1, __int64 a2)
{
double *v2; // rbp
__int64 *i; // rbx
__int64 j; // rbx
double v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 )
{
if ( a1 )
{
v7[0] = *(_QWORD *)a2;
v6 = *(double *)(a2 + 8);
xform_point(a1, v7, &v6);
v2 = coord_new(*(double *)v7, v6);
for ( i = *(__int64 **)(a2 + 16); i; i = (__int64 *)i[2] )
{
v7[0] = *i;
v6 = *((double *)i + 1);
xform_point(a1, v7, &v6);
coord_append((__int64)v2, *(double *)v7, v6);
}
}
else
{
v2 = coord_new(*(double *)a2, *(double *)(a2 + 8));
for ( j = *(_QWORD *)(a2 + 16); j; j = *(_QWORD *)(j + 16) )
coord_append((__int64)v2, *(double *)j, *(double *)(j + 8));
}
}
else
{
puts("coord_copy: can't copy null coordinate list");
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
double *__fastcall func8(__int64 a1, __int64 a2)
{
double *v2; // rbp
__int64 *i; // rbx
__int64 j; // rbx
double v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a2 )
{
if ( a1 )
{
v7[0] = *(_QWORD *)a2;
v6 = *(double *)(a2 + 8);
xform_point(a1, v7, &v6);
v2 = func3(*(double *)v7, v6);
for ( i = *(__int64 **)(a2 + 16); i; i = (__int64 *)i[2] )
{
v7[0] = *i;
v6 = *((double *)i + 1);
xform_point(a1, v7, &v6);
func4((__int64)v2, *(double *)v7, v6);
}
}
else
{
v2 = func3(*(double *)a2, *(double *)(a2 + 8));
for ( j = *(_QWORD *)(a2 + 16); j; j = *(_QWORD *)(j + 16) )
func4((__int64)v2, *(double *)j, *(double *)(j + 8));
}
}
else
{
puts("coord_copy: can't copy null coordinate list");
v2 = 0LL;
}
return v2;
}

original_code:
COORDS *coord_copy(XFORM *xp, COORDS *CP)
{
    COORDS *p;
    COORDS *new_coords=((void *)0);
    double x,y;
    if (CP == ((void *)0)) {
     printf("coord_copy: can't copy null coordinate list\n");
    } else if (xp == ((void *)0)) {
 p=CP;
 new_coords = coord_new(p->coord.x,p->coord.y);
 p=p->next;
 while(p != ((void *)0)) {
     coord_append(new_coords, p->coord.x, p->coord.y);
     p=p->next;
 }
    } else {
 p=CP;
 x = p->coord.x; y = p->coord.y; xform_point(xp, &x, &y);
 new_coords = coord_new(x, y);
 p=p->next;
 while(p != ((void *)0)) {
     x = p->coord.x; y = p->coord.y; xform_point(xp, &x, &y);
     coord_append(new_coords, x, y);
     p=p->next;
 }
    }
    return(new_coords);
}

canonical_original_code:
struct coord_list *coord_copy(struct xform *xp, struct coord_list *CP)
{
    struct coord_list *p;
    struct coord_list *new_coords = ((void *)0);
    double x; double y;
    if (CP == ((void *)0)) {
     printf("coord_copy: can't copy null coordinate list\n");
    } else if (xp == ((void *)0)) {
 p=CP;
 new_coords = coord_new(p->coord.x,p->coord.y);
 p=p->next;
 while(p != ((void *)0)) {
     coord_append(new_coords, p->coord.x, p->coord.y);
     p=p->next;
 }
    } else {
 p=CP;
 x = p->coord.x; y = p->coord.y; xform_point(xp, &x, &y);
 new_coords = coord_new(x, y);
 p=p->next;
 while(p != ((void *)0)) {
     x = p->coord.x; y = p->coord.y; xform_point(xp, &x, &y);
     coord_append(new_coords, x, y);
     p=p->next;
 }
    }
    return(new_coords);
}

variable_types: struct xform { double r11; double r12; double r21; double r22; double dx; double dy; } *

variable_types:
CP
struct coord_list *

return_type: struct coord_list { struct coord_pair { double x; } coord; struct coord_list *next; struct coord_list *prev; } *


decompiled_code:
_QWORD *stack_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 2) = 0;
return result;
}

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

result = malloc(0x18uLL);
*result = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 2) = 0;
return result;
}

original_code:
STACK *stack_new()
{
    STACK *tmp;
    tmp = (STACK *) malloc(sizeof(STACK));
    tmp->saved = ((void *)0);
    tmp->next = ((void *)0);
    tmp->count = 0;
    return(tmp);
}

canonical_original_code:
struct stack *stack_new()
{
    struct stack *tmp;
    tmp = (struct stack *) malloc(sizeof(STACK));
    tmp->saved = ((void *)0);
    tmp->next = ((void *)0);
    tmp->count = 0;
    return(tmp);
}

variable_types: struct stack { char *saved; int count; struct stack *next; } *


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

result = 0LL;
if ( *(_QWORD *)a1 )
result = *(unsigned int *)(*(_QWORD *)a1 + 8LL);
return result;
}

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

result = 0LL;
if ( *(_QWORD *)a1 )
result = *(unsigned int *)(*(_QWORD *)a1 + 8LL);
return result;
}

original_code:
int stack_depth(STACK **stack)
{
    if (*stack == ((void *)0)) {
        return(0);
    } else {
 return((*stack)->count);
    }
}

canonical_original_code:
int stack_depth(struct stack **stack)
{
    if (*stack == ((void *)0)) {
        return(0);
    } else {
 return((*stack)->count);
    }
}

variable_types: struct stack { char *saved; int count; struct stack *next; } **


decompiled_code:
__int64 __fastcall stack_print(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
do
{
if ( *(_QWORD *)v1 )
{
printf("stack #%d: %s\n", v2, *(const char **)v1);
v2 = (unsigned int)(v2 + 1);
}
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
do
{
if ( *(_QWORD *)v1 )
{
printf("stack #%d: %s\n", v2, *(const char **)v1);
v2 = (unsigned int)(v2 + 1);
}
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return 0LL;
}

original_code:
int stack_print(STACK **stack)
{
     int i=0;
     STACK *sp;
     if (stack == ((void *)0)) {
      return(0);
     }
     sp = *stack;
     while(sp != ((void *)0)) {
  if (sp->saved != ((void *)0)) {
      printf("stack #%d: %s\n", i++, sp->saved);
  }
  sp = sp->next;
     }
     return(0);
}

canonical_original_code:
int stack_print(struct stack **stack)
{
     int i = 0;
     struct stack *sp;
     if (stack == ((void *)0)) {
      return(0);
     }
     sp = *stack;
     while(sp != ((void *)0)) {
  if (sp->saved != ((void *)0)) {
      printf("stack #%d: %s\n", i++, sp->saved);
  }
  sp = sp->next;
     }
     return(0);
}

user_defined_types: struct stack { char *saved; int count; struct stack *next; }


original_code:
char *stack_walk(STACK **stack)
{
     char *p;
     if (*stack == ((void *)0)) {
      return ((void *)0);
     }
     if (*stack != ((void *)0)) {
  p = (*stack)->saved;
  *stack = (*stack)->next;
     }
     return p;
}

canonical_original_code:
char *stack_walk(struct stack **stack)
{
     char *p;
     if (*stack == ((void *)0)) {
      return ((void *)0);
     }
     if (*stack != ((void *)0)) {
  p = (*stack)->saved;
  *stack = (*stack)->next;
     }
     return p;
}

variable_types:
p
char *


decompiled_code:
Pixmap init_stipples()
{
__int64 i; // rbx
Pixmap *v1; // r13
char *v2; // r12
Pixmap result; // rax
char *v4; // rbp
int v5; // ebx
int v6; // ebx
int v7; // ebx

for ( i = 0LL; i != 50; ++i )
stipple[i] = XCreateBitmapFromData(dpy, win, &stip_src[i * 8], 8u, 8u);
v1 = (Pixmap *)(unsigned int)((_DWORD)stipple + 400);
v2 = &stip_src[408];
do
{
v4 = v2 - 8;
do
{
v5 = (int)(drand48() * 255.0);
v6 = (int)(drand48() * 255.0) & v5;
v7 = (int)(drand48() * 255.0) & v6;
*v4++ = (int)(drand48() * 255.0) & v7;
}
while ( v4 != v2 );
result = XCreateBitmapFromData(dpy, win, v2 - 8, 8u, 8u);
*v1++ = result;
v2 += 8;
}
while ( v2 != &stip_src[808] );
return result;
}

canonical_decompiled_code:
Pixmap func0()
{
__int64 i; // rbx
Pixmap *v1; // r13
char *v2; // r12
Pixmap result; // rax
char *v4; // rbp
int v5; // ebx
int v6; // ebx
int v7; // ebx

for ( i = 0LL; i != 50; ++i )
stipple[i] = XCreateBitmapFromData(dpy, win, &stip_src[i * 8], 8u, 8u);
v1 = (Pixmap *)(unsigned int)((_DWORD)stipple + 400);
v2 = &stip_src[408];
do
{
v4 = v2 - 8;
do
{
v5 = (int)(drand48() * 255.0);
v6 = (int)(drand48() * 255.0) & v5;
v7 = (int)(drand48() * 255.0) & v6;
*v4++ = (int)(drand48() * 255.0) & v7;
}
while ( v4 != v2 );
result = XCreateBitmapFromData(dpy, win, v2 - 8, 8u, 8u);
*v1++ = result;
v2 += 8;
}
while ( v2 != &stip_src[808] );
return result;
}

original_code:
void init_stipples() {
    int i,j;
    unsigned char a;
    for (i=0; i<50; i++) {
 stipple[i] = XCreateBitmapFromData(dpy, win, (const char *)stip_src[i],
     (unsigned int) 8, (unsigned int) 8);
    }
    for (; i<100; i++) {
     for (j=0; j<8; j++) {
     a = (unsigned char) (drand48()*255.0);
     a &= (unsigned char) (drand48()*255.0);
     a &= (unsigned char) (drand48()*255.0);
     a &= (unsigned char) (drand48()*255.0);
     stip_src[i][j] = (unsigned char) a;
 }
 stipple[i] = XCreateBitmapFromData(dpy, win, (const char *)stip_src[i],
     (unsigned int) 8, (unsigned int) 8);
    }
}

canonical_original_code:
void init_stipples() {
    int i; int j;
    unsigned char a;
    for (i=0; i<50; i++) {
 stipple[i] = XCreateBitmapFromData(dpy, win, (char *)stip_src[i],
     (unsigned int) 8, (unsigned int) 8);
    }
    for (; i<100; i++) {
     for (j=0; j<8; j++) {
     a = (unsigned char) (drand48()*255.0);
     a &= (unsigned char) (drand48()*255.0);
     a &= (unsigned char) (drand48()*255.0);
     a &= (unsigned char) (drand48()*255.0);
     stip_src[i][j] = (unsigned char) a;
 }
 stipple[i] = XCreateBitmapFromData(dpy, win, (char *)stip_src[i],
     (unsigned int) 8, (unsigned int) 8);
    }
}

variable_types: j int

variable_types:
a
unsigned char


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

result = a1;
if ( a1 )
result = a2 + 2 * (5 * a1 - 5);
return result;
}

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

result = a1;
if ( a1 )
result = a2 + 2 * (5 * a1 - 5);
return result;
}

original_code:
int get_stipple_index(int fill, int pen) {
   int debug=0;
   if (debug) printf("fill %d, pen %d, index %d\n", fill, pen, (fill-1)*10+pen);
   if (fill==0) {
      return(0);
   } else {
       return((fill-1)*10+pen);
   }
}

canonical_original_code:
int get_stipple_index(int fill, int pen) {
   int debug = 0;
   if (debug) printf("fill %d, pen %d, index %d\n", fill, pen, (fill-1)*10+pen);
   if (fill==0) {
      return(0);
   } else {
       return((fill-1)*10+pen);
   }
}

variable_types: fill int

variable_types: pen int

variable_types: debug int


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

result = 0LL;
if ( a1 <= 98 )
result = &stip_src[8 * a1];
return result;
}

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

result = 0LL;
if ( a1 <= 98 )
result = &stip_src[8 * a1];
return result;
}

original_code:
unsigned char *get_stipple_bits(int i) {
   if (i >= 100 -1) {
      return ((void *)0);
   } else {
       return(&stip_src[i][0]);
   }
}

return_type: unsigned char *


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

switch ( a1 % 8 )
{
case 0:
result = "FT10,0;";
break;
case 1:
result = "FT10,50;";
break;
case 2:
result = "FT3,3,45;";
break;
case 3:
result = "FT3,4,135;";
break;
case 4:
result = "FT3,5,0;";
break;
case 5:
result = "FT3,4,90;";
break;
case 6:
result = "FT4,3,0;";
break;
case 7:
result = "FT4,4,45;";
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 % 8 )
{
case 0:
result = "FT10,0;";
break;
case 1:
result = "FT10,50;";
break;
case 2:
result = "FT3,3,45;";
break;
case 3:
result = "FT3,4,135;";
break;
case 4:
result = "FT3,5,0;";
break;
case 5:
result = "FT3,4,90;";
break;
case 6:
result = "FT4,3,0;";
break;
case 7:
result = "FT4,4,45;";
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
const char * get_hpgl_fill(int fill)
{
    switch (fill % 8) {
    case 0:
 return ("FT10,0;");
 break;
    case 1:
 return ("FT10,50;");
 break;
    case 2:
 return ("FT3,3,45;");
 break;
    case 3:
 return ("FT3,4,135;");
 break;
    case 4:
 return ("FT3,5,0;");
 break;
    case 5:
 return ("FT3,4,90;");
 break;
    case 6:
 return ("FT4,3,0;");
 break;
    case 7:
 return ("FT4,4,45;");
 break;
    }
    return ((void *)0);
}

canonical_original_code:
char *get_hpgl_fill(int fill)
{
    switch (fill % 8) {
    case 0:
 return ("FT10,0;");
 break;
    case 1:
 return ("FT10,50;");
 break;
    case 2:
 return ("FT3,3,45;");
 break;
    case 3:
 return ("FT3,4,135;");
 break;
    case 4:
 return ("FT3,5,0;");
 break;
    case 5:
 return ("FT3,4,90;");
 break;
    case 6:
 return ("FT4,3,0;");
 break;
    case 7:
 return ("FT4,4,45;");
 break;
    }
    return ((void *)0);
}


setlockpoint

decompiled_code:
void __fastcall setlockpoint(double a1, double a2)
{
xsnap = *(_QWORD *)&a1;
ysnap = *(_QWORD *)&a2;
}

canonical_decompiled_code:
void __fastcall func0(double a1, double a2)
{
xsnap = *(_QWORD *)&a1;
ysnap = *(_QWORD *)&a2;
}

original_code:
void setlockpoint(double x,double y)
{
    int debug = 0;
    if (debug) printf("setting snap to %g %g\n", x, y);
    xsnap = x;
    ysnap = y;
}

canonical_original_code:
void setlockpoint(double x, double y)
{
    int debug = 0;
    if (debug) printf("setting snap to %g %g\n", x, y);
    xsnap = x;
    ysnap = y;
}


lockpoint

original_code:
void lockpoint(double *px, double *py, double lock)
{
    double dx, dy;
    double theta;
    double locktheta;
    double snaptheta;
    double radius;
    if (lock != 0.0) {
 dx = *px - xsnap;
 dy = *py - ysnap;
 radius = sqrt(dx*dx + dy*dy);
 theta = atan2(dy,dx);
 if (theta < 0.0) {
     theta += 2.0*3.14159265358979323846;
 }
 locktheta = 2.0*3.14159265358979323846*lock/360.0;
 snaptheta = locktheta*floor((theta+(locktheta/2.0))/locktheta);
 *px = xsnap+radius*cos(snaptheta);
 *py = ysnap+radius*sin(snaptheta);
 snapxy(px, py);
    }
}

canonical_original_code:
void lockpoint(double *px, double *py, double lock)
{
    double dx; double dy;
    double theta;
    double locktheta;
    double snaptheta;
    double radius;
    if (lock != 0.0) {
 dx = *px - xsnap;
 dy = *py - ysnap;
 radius = sqrt(dx*dx + dy*dy);
 theta = atan2(dy,dx);
 if (theta < 0.0) {
     theta += 2.0*3.14159265358979323846;
 }
 locktheta = 2.0*3.14159265358979323846*lock/360.0;
 snaptheta = locktheta*floor((theta+(locktheta/2.0))/locktheta);
 *px = xsnap+radius*cos(snaptheta);
 *py = ysnap+radius*sin(snaptheta);
 snapxy(px, py);
    }
}

variable_types: lock double

variable_types: dx double

variable_types: dy double

variable_types: theta double

variable_types: locktheta double

variable_types: snaptheta double

variable_types: radius double


pnametosize

decompiled_code:
__int64 __fastcall pnametosize(char *s1, double *a2, _QWORD *a3)
{
unsigned __int16 v4; // ax
double v5; // rbp
char **v6; // rbx
int v7; // er12
__int64 result; // rax
int v9; // edx
int v10; // edx

v4 = (*_ctype_b_loc())[(unsigned __int8)*s1];
if ( (v4 & 0x400) == 0 )
{
if ( (v4 & 0x800) != 0 )
{
v9 = _isoc99_sscanf(s1, "%lfx%lf", a2, a3);
result = 1LL;
if ( v9 == 2 )
return result;
v10 = _isoc99_sscanf(s1, "%lf*%lf", a2, a3);
result = 1LL;
if ( v10 == 2 )
return result;
}
LABEL_9:
*(_QWORD *)a2 = LC3;
*a3 = LC4;
return 0LL;
}
v5 = *((double *)&psizes + 1);
if ( v5 == 0.0 )
goto LABEL_9;
v6 = &psizes;
v7 = 0;
while ( strncasecmp(s1, *v6, 0x80uLL) )
{
++v7;
v6 += 3;
v5 = *((double *)v6 + 1);
if ( v5 == 0.0 )
goto LABEL_9;
}
*a2 = v5;
*a3 = (&psizes)[3 * v7 + 2];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, double *a2, _QWORD *a3)
{
unsigned __int16 v4; // ax
double v5; // rbp
char **v6; // rbx
int v7; // er12
__int64 result; // rax
int v9; // edx
int v10; // edx

v4 = (*_ctype_b_loc())[(unsigned __int8)*s1];
if ( (v4 & 0x400) == 0 )
{
if ( (v4 & 0x800) != 0 )
{
v9 = _isoc99_sscanf(s1, "%lfx%lf", a2, a3);
result = 1LL;
if ( v9 == 2 )
return result;
v10 = _isoc99_sscanf(s1, "%lf*%lf", a2, a3);
result = 1LL;
if ( v10 == 2 )
return result;
}
LABEL_9:
*(_QWORD *)a2 = LC3;
*a3 = LC4;
return 0LL;
}
v5 = *((double *)&psizes + 1);
if ( v5 == 0.0 )
goto LABEL_9;
v6 = &psizes;
v7 = 0;
while ( strncasecmp(s1, *v6, 0x80uLL) )
{
++v7;
v6 += 3;
v5 = *((double *)v6 + 1);
if ( v5 == 0.0 )
goto LABEL_9;
}
*a2 = v5;
*a3 = (&psizes)[3 * v7 + 2];
return 1LL;
}

original_code:
int pnametosize(char *name, double *px, double *py)
{
    int debug=0;
    int i;
    int matched = 0;
    if (debug) printf("pnametosize called with <%s>\n", name);
    if (((*__ctype_b_loc ())[(int) (((unsigned char)name[0]))] & (unsigned short int) _ISalpha)) {
 for (i = 0; psizes[i].x != 0.0; i++) {
     if (debug) printf("checking %s %s\n", name, psizes[i].name);
     if (strncasecmp(name, psizes[i].name, 128) == 0) {
  matched++;
  *px = psizes[i].x;
  *py = psizes[i].y;
  break;
     }
 }
    } else if (((*__ctype_b_loc ())[(int) (((unsigned char)name[0]))] & (unsigned short int) _ISdigit)) {
 if (sscanf(name, "%lfx%lf", px, py) == 2) {
     matched++;
 } else if (sscanf(name, "%lf*%lf", px, py) == 2) {
     matched++;
 }
    }
    if (!matched) {
 *px=8.5; *py=11.0;
    }
    if (debug) printf("pnametosize returning %d\n", matched);
    return(matched);
}

canonical_original_code:
int pnametosize(char *name, double *px, double *py)
{
    int debug = 0;
    int i;
    int matched = 0;
    if (debug) printf("pnametosize called with <%s>\n", name);
    if (((*__ctype_b_loc ())[(int) (((unsigned char)name[0]))] & (unsigned short) _ISalpha)) {
 for (i = 0; psizes[i].x != 0.0; i++) {
     if (debug) printf("checking %s %s\n", name, psizes[i].name);
     if (strncasecmp(name, psizes[i].name, 128) == 0) {
  matched++;
  *px = psizes[i].x;
  *py = psizes[i].y;
  break;
     }
 }
    } else if (((*__ctype_b_loc ())[(int) (((unsigned char)name[0]))] & (unsigned short) _ISdigit)) {
 if (sscanf(name, "%lfx%lf", px, py) == 2) {
     matched++;
 } else if (sscanf(name, "%lf*%lf", px, py) == 2) {
     matched++;
 }
    }
    if (!matched) {
 *px=8.5; *py=11.0;
    }
    if (debug) printf("pnametosize returning %d\n", matched);
    return(matched);
}

variable_types:
name
char *

variable_types:
px
double *

variable_types:
py
double *

variable_types: i int

variable_types: matched int


testpapermain

decompiled_code:
__int64 testpapermain()
{
double v1; // [rsp+0h] [rbp-18h] BYREF
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

while ( fgets(&buf, 128, stdin) )
{
*(&buf + strlen(&buf) - 1) = 0;
if ( (unsigned int)pnametosize(&buf, v2, &v1) )
printf("\t%g %g\n", v2[0], v1);
else
printf("\tnot found: %g %g\n", v2[0], v1);
}
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
double v1; // [rsp+0h] [rbp-18h] BYREF
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

while ( fgets(&buf, 128, stdin) )
{
*(&buf + strlen(&buf) - 1) = 0;
if ( (unsigned int)func0(&buf, v2, &v1) )
printf("\t%g %g\n", v2[0], v1);
else
printf("\tnot found: %g %g\n", v2[0], v1);
}
return 1LL;
}

original_code:
int testpapermain()
{
    double x, y;
    while (fgets(buf, 128, stdin) != ((void *)0)) {
 buf[strlen(buf) - 1] = '\0';
 if (pnametosize(buf, &x, &y)) {
     printf("\t%g %g\n", x, y);
 } else {
     printf("\tnot found: %g %g\n", x, y);
 }
    }
    return(1);
}

canonical_original_code:
int testpapermain()
{
    double x; double y;
    while (fgets(buf, 128, stdin) != ((void *)0)) {
 buf[strlen(buf) - 1] = '\0';
 if (pnametosize(buf, &x, &y)) {
     printf("\t%g %g\n", x, y);
 } else {
     printf("\tnot found: %g %g\n", x, y);
 }
    }
    return(1);
}

variable_types: x double

variable_types: y double


decompiled_code:
void *rl_saveprompt()
{
if ( prompt )
{
if ( saveprompt )
free(saveprompt);
saveprompt = (void *)estrdup(prompt);
}
else
{
saveprompt = (void *)estrdup(&unk_520);
}
return saveprompt;
}

canonical_decompiled_code:
void *func0()
{
if ( prompt )
{
if ( saveprompt )
free(saveprompt);
saveprompt = (void *)estrdup(prompt);
}
else
{
saveprompt = (void *)estrdup(&unk_520);
}
return saveprompt;
}

original_code:
char *rl_saveprompt() {
    if (prompt != (char *) ((void *)0)) {
  if (saveprompt != (char *) ((void *)0)) {
      free(saveprompt);
  }
  saveprompt = (char *) estrdup(prompt);
    } else {
 saveprompt = (char *) estrdup(">");
    }
    return(saveprompt);
}


decompiled_code:
void *rl_restoreprompt()
{
void *result; // rax

if ( saveprompt )
{
if ( prompt )
free(prompt);
result = (void *)estrdup(saveprompt);
prompt = result;
}
else
{
result = (void *)estrdup(&unk_520);
prompt = result;
}
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

if ( saveprompt )
{
if ( prompt )
free(prompt);
result = (void *)estrdup(saveprompt);
prompt = result;
}
else
{
result = (void *)estrdup(&unk_520);
prompt = result;
}
return result;
}

original_code:
void rl_restoreprompt() {
    if (saveprompt != (char *) ((void *)0)) {
 if (prompt != (char *) ((void *)0)) {
     free(prompt);
 }
        prompt = (char *) estrdup(saveprompt);
    } else {
 prompt = (char *) estrdup(">");
    }
}


decompiled_code:
void *__fastcall rl_setprompt(__int64 a1)
{
void *result; // rax

if ( prompt )
free(prompt);
result = (void *)estrdup(a1);
prompt = result;
return result;
}

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

if ( prompt )
free(prompt);
result = (void *)estrdup(a1);
prompt = result;
return result;
}

original_code:
void rl_setprompt(char *str)
{
    if (prompt != (char *) ((void *)0)) {
 free(prompt);
    }
    prompt = (char *) estrdup(str);
}

variable_types:
str
char *


expdupstr

decompiled_code:
char *__fastcall expdupstr(char *src, int a2)
{
size_t v2; // rax
char *v3; // rax

v2 = strlen(src);
v3 = (char *)malloc(a2 + v2);
return strcpy(v3, src);
}

canonical_decompiled_code:
char *__fastcall func5(char *src, int a2)
{
size_t v2; // rax
char *v3; // rax

v2 = strlen(src);
v3 = (char *)malloc(a2 + v2);
return strcpy(v3, src);
}

original_code:
char * expdupstr(char *s, int n)
{
    char *r;
    r = (char *) malloc(strlen( (char *) s) + n);
    strcpy(r, (char *) s);
    return (r);
}

canonical_original_code:
char *expdupstr(char *s, int n)
{
    char *r;
    r = (char *) malloc(strlen( (char *) s) + n);
    strcpy(r, (char *) s);
    return (r);
}

variable_types:
s
char *

variable_types: n int

variable_types:
r
char *


rmctrls

decompiled_code:
void __fastcall rmctrls(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl
unsigned __int8 *v2; // rbp
const unsigned __int16 **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_b_loc();
do
{
if ( ((*v3)[v1] & 0x4000) == 0 )
*v2 = 32;
v1 = *++v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl
unsigned __int8 *v2; // rbp
const unsigned __int16 **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_b_loc();
do
{
if ( ((*v3)[v1] & 0x4000) == 0 )
*v2 = 32;
v1 = *++v2;
}
while ( *v2 );
}
}

original_code:
void rmctrls(char *s) {
   while (*s != '\0') {
       if (!((*__ctype_b_loc ())[(int) (((unsigned char)*s))] & (unsigned short int) _ISprint)) {
          *s = ' ';
       }
       s++;
   }
}

canonical_original_code:
void rmctrls(char *s) {
   while (*s != '\0') {
       if (!((*__ctype_b_loc ())[(int) (((unsigned char)*s))] & (unsigned short) _ISprint)) {
          *s = ' ';
       }
       s++;
   }
}


decompiled_code:
char *__fastcall rl_gets(__int64 a1)
{
char *v1; // rbx
char *result; // rax
char *v3; // rbp
char *v4; // rbx
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( lineread )
{
free(lineread);
lineread = 0LL;
}
if ( pigrcfp )
{
if ( fgets(v5, 1023, pigrcfp) )
{
v1 = expdupstr(v5, 3);
strcat(v1, ";\n");
}
else
{
pigrcfp = 0LL;
v1 = expdupstr(";\n", 3);
}
rmctrls((unsigned __int8 *)v1);
lineread = v1;
return lineread;
}
result = (char *)readline(a1);
lineread = result;
if ( result )
{
if ( *result )
{
add_history(result);
write_history(".pighist");
}
v3 = lineread;
v4 = expdupstr(lineread, 3);
*(_WORD *)&v4[strlen(v4)] = 10;
free(v3);
lineread = v4;
return lineread;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(__int64 a1)
{
char *v1; // rbx
char *result; // rax
char *v3; // rbp
char *v4; // rbx
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( lineread )
{
free(lineread);
lineread = 0LL;
}
if ( pigrcfp )
{
if ( fgets(v5, 1023, pigrcfp) )
{
v1 = func5(v5, 3);
strcat(v1, ";\n");
}
else
{
pigrcfp = 0LL;
v1 = func5(";\n", 3);
}
func9((unsigned __int8 *)v1);
lineread = v1;
return lineread;
}
result = (char *)readline(a1);
lineread = result;
if ( result )
{
if ( *result )
{
add_history(result);
write_history(".pighist");
}
v3 = lineread;
v4 = func5(lineread, 3);
*(_WORD *)&v4[strlen(v4)] = 10;
free(v3);
lineread = v4;
return lineread;
}
return result;
}

original_code:
char * rl_gets (char *prompt)
{
    char *s;
    char buf[1024];
    if (lineread) {
        free (lineread);
        lineread = (char *) ((void *)0);
    }
    if (pigrcfp == ((void *)0)) {
 lineread = readline (prompt);
 if (lineread == ((void *)0)) {
     return(((void *)0));
 }
 if (lineread && *lineread) {
     add_history (lineread);
     write_history(".pighist");
 }
 s = expdupstr(lineread,3);
 strcat(s,"\n");
 free (lineread);
 lineread = s;
    } else {
 if (fgets(buf, 1023, pigrcfp) == ((void *)0)) {
     pigrcfp=((void *)0);
     s = expdupstr(";\n",3);
 } else {
     s = expdupstr(buf,3);
     strcat(s,";\n");
 }
 rmctrls(s);
 lineread = s;
    }
    return (lineread);
}

canonical_original_code:
char *rl_gets(char *prompt)
{
    char *s;
    char buf[1024];
    if (lineread) {
        free (lineread);
        lineread = (char *) ((void *)0);
    }
    if (pigrcfp == ((void *)0)) {
 lineread = readline (prompt);
 if (lineread == ((void *)0)) {
     return(((void *)0));
 }
 if (lineread && *lineread) {
     add_history (lineread);
     write_history(".pighist");
 }
 s = expdupstr(lineread,3);
 strcat(s,"\n");
 free (lineread);
 lineread = s;
    } else {
 if (fgets(buf, 1023, pigrcfp) == ((void *)0)) {
     pigrcfp=((void *)0);
     s = expdupstr(";\n",3);
 } else {
     s = expdupstr(buf,3);
     strcat(s,";\n");
 }
 rmctrls(s);
 lineread = s;
    }
    return (lineread);
}

variable_types:
prompt
char *

variable_types:
buf
char [1024]


decompiled_code:
__int64 initialize_readline()
{
rl_getc_function = &procXevent;
stifle_history(1024LL);
return read_history(".pighist");
}

canonical_decompiled_code:
__int64 func11()
{
rl_getc_function = &procXevent;
stifle_history(1024LL);
return read_history(".pighist");
}

original_code:
void initialize_readline()
{
    rl_getc_function = procXevent;
    stifle_history(1024);
    read_history(".pighist");
}


decompiled_code:
__int64 __fastcall draw_text(int a1, double a2, double a3)
{
dword_B40 = 0;
qword_AE8 = (__int64)&dbtext;
dbdeflist_2 = 0x10000;
dbtext = 1;
*((_QWORD *)&dbtext + 1) = &topts;
*((_QWORD *)&dbtext + 2) = &str;
if ( a1 )
{
jump(&bb_3, 1LL);
*((_QWORD *)&dbtext + 3) = xold_1;
*((_QWORD *)&dbtext + 4) = yold_0;
if ( a1 > 0 )
{
do_text(&dbdeflist_2, &bb_3, 1LL);
jump(&bb_3, 1LL);
*((double *)&dbtext + 3) = a2;
*((double *)&dbtext + 4) = a3;
}
do_text(&dbdeflist_2, &bb_3, 1LL);
}
else
{
jump(&bb_3, 1LL);
*((double *)&dbtext + 3) = a2;
*((double *)&dbtext + 4) = a3;
do_text(&dbdeflist_2, &bb_3, 1LL);
}
xold_1 = *(_QWORD *)&a2;
yold_0 = *(_QWORD *)&a3;
return jump(&bb_3, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3)
{
dword_B40 = 0;
qword_AE8 = (__int64)&dbtext;
dbdeflist_2 = 0x10000;
dbtext = 1;
*((_QWORD *)&dbtext + 1) = &topts;
*((_QWORD *)&dbtext + 2) = &str;
if ( a1 )
{
jump(&bb_3, 1LL);
*((_QWORD *)&dbtext + 3) = xold_1;
*((_QWORD *)&dbtext + 4) = yold_0;
if ( a1 > 0 )
{
do_text(&dbdeflist_2, &bb_3, 1LL);
jump(&bb_3, 1LL);
*((double *)&dbtext + 3) = a2;
*((double *)&dbtext + 4) = a3;
}
do_text(&dbdeflist_2, &bb_3, 1LL);
}
else
{
jump(&bb_3, 1LL);
*((double *)&dbtext + 3) = a2;
*((double *)&dbtext + 4) = a3;
do_text(&dbdeflist_2, &bb_3, 1LL);
}
xold_1 = *(_QWORD *)&a2;
yold_0 = *(_QWORD *)&a3;
return jump(&bb_3, 1LL);
}

original_code:
void draw_text(double x2, double y2, int count)
{
 static double xold, yold;
 int debug=0;
 static BOUNDS bb;
 static DB_DEFLIST dbdeflist;
 bb.init=0;
        dbdeflist.u.t = &dbtext;
        dbdeflist.type = 65536;
        dbtext.layer=1;
        dbtext.opts=&topts;
 dbtext.text=str;
 if (debug) {printf("in draw_text\n");}
 if (count == 0) {
     jump(&bb, 1);
     dbtext.x=x2;
     dbtext.y=y2;
     do_text(&dbdeflist, &bb, 1);
 } else if (count > 0) {
     jump(&bb, 1);
     dbtext.x=xold;
     dbtext.y=yold;
     do_text(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     dbtext.x=x2;
     dbtext.y=y2;
     do_text(&dbdeflist, &bb, 1);
 } else {
     jump(&bb, 1);
     dbtext.x=xold;
     dbtext.y=yold;
     do_text(&dbdeflist, &bb, 1);
 }
 xold=x2;
 yold=y2;
 jump(&bb, 1);
}

canonical_original_code:
void draw_text(double x2, double y2, int count)
{
 static double xold; static double yold;
 int debug = 0;
 static struct bounds bb;
 static struct db_deflist dbdeflist;
 bb.init=0;
        dbdeflist.u.t = &dbtext;
        dbdeflist.type = 65536;
        dbtext.layer=1;
        dbtext.opts=&topts;
 dbtext.text=str;
 if (debug) {printf("in draw_text\n");}
 if (count == 0) {
     jump(&bb, 1);
     dbtext.x=x2;
     dbtext.y=y2;
     do_text(&dbdeflist, &bb, 1);
 } else if (count > 0) {
     jump(&bb, 1);
     dbtext.x=xold;
     dbtext.y=yold;
     do_text(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     dbtext.x=x2;
     dbtext.y=y2;
     do_text(&dbdeflist, &bb, 1);
 } else {
     jump(&bb, 1);
     dbtext.x=xold;
     dbtext.y=yold;
     do_text(&dbdeflist, &bb, 1);
 }
 xold=x2;
 yold=y2;
 jump(&bb, 1);
}

variable_types: count int

variable_types: xold double

variable_types: yold double

variable_types: debug int

variable_types: struct bounds { double xmin; double ymin; double xmax; double ymax; int init; }

variable_types: struct db_deflist { int type; union { struct db_arc { int layer; struct opt_list { double font_size; double height; int mirror; int font_num; int justification; int stepflag; int rows; int cols; double rotation; double width; double scale; double aspect_ratio; double slant; char *sname; char *cname; int bezier; } *opts; double x1; } *a; struct db_circ { int layer; struct opt_list *opts; double x1; } *c; struct db_inst { char *name; struct opt_list *opts; double x; double colx; double rowx; } *i; struct db_line { int layer; struct opt_list *opts; struct coord_list { struct coord_pair { double x; } coord; struct coord_list *next; struct coord_list *prev; } *coords; } *l; struct db_note { int layer; struct opt_list *opts; char *text; double x; } *n; struct db_oval { int layer; struct opt_list *opts; double x1; } *o; struct db_poly { int layer; struct opt_list *opts; struct coord_list *coords; } *p; struct db_rect { int layer; struct opt_list *opts; double x1; } *r; struct db_text { int layer; struct opt_list *opts; char *text; double x; } *t; } u; double xmin; struct db_deflist *next; struct db_deflist *prev; }