main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)opt_parse(argc, (char **)argv, "d:f:u:p:n:o:csg") )
{
fwrite("bad cmdline arguments. please retry!\n", 1uLL, 0x25uLL, stderr);
exit(2);
}
if ( get_stdin_passwd )
get_real_passwd();
if ( !conf_filepath )
conf_filepath = "/var/automap.conf";
if ( (unsigned int)get_cond_from_file() )
{
if ( !isvalid_ad_cond() )
{
fwrite("initialize from file failed. please retry!\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
}
else if ( !isvalid_ad_cond() )
{
fwrite(
"can't get fully informations to connect WIN_AD.\nplease specify it again on cmdline or conf_file and retry!\n",
1uLL,
0x6BuLL,
stderr);
exit(2);
}
get_domain_info(&ad);
dump_ad_cond();
free_ad_cond();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func6(argc, (char **)argv, "d:f:u:p:n:o:csg") )
{
fwrite("bad cmdline arguments. please retry!\n", 1uLL, 0x25uLL, stderr);
exit(2);
}
if ( get_stdin_passwd )
func7();
if ( !conf_filepath )
conf_filepath = "/var/automap.conf";
if ( (unsigned int)get_cond_from_file() )
{
if ( !func4() )
{
fwrite("initialize from file failed. please retry!\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
}
else if ( !func4() )
{
fwrite(
"can't get fully informations to connect WIN_AD.\nplease specify it again on cmdline or conf_file and retry!\n",
1uLL,
0x6BuLL,
stderr);
exit(2);
}
get_domain_info(&ad);
func5();
func3();
return 0;
}

original_code:
int main(int argc, char *argv[]){
    int i = 0;
    if(opt_parse(argc, argv, "d:f:u:p:n:o:csg")){
        fprintf(stderr, "bad cmdline arguments. please retry!\n");
        exit(2);
    }
    if(get_stdin_passwd)
        get_real_passwd();
    if(!conf_filepath)
        conf_filepath = "/var/automap.conf";
    if(get_cond_from_file(conf_filepath) && !isvalid_ad_cond()){
        fprintf(stderr, "initialize from file failed. please retry!\n");
        exit(1);
    }
    if(!isvalid_ad_cond()){
        fprintf(stderr, "can't get fully informations to connect WIN_AD.\n"
                        "please specify it again on cmdline or conf_file and retry!\n");
        exit(2);
    }
    get_domain_info(&ad);
    dump_ad_cond();
    free_ad_cond();
    return 0;
}

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
__int64 __fastcall get_dn_with_ad_cond(__int64 a1, int *a2, char *a3, const char *a4)
{
__int64 v6; // rax
const char *v7; // rdx

v6 = *a2;
v7 = *(const char **)(a1 + 8 * v6 + 32);
if ( !v7 )
return 0LL;
*a2 = v6 + 1;
sprintf(a3, "ou=%s,%s", v7, a4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, char *a3, const char *a4)
{
__int64 v6; // rax
const char *v7; // rdx

v6 = *a2;
v7 = *(const char **)(a1 + 8 * v6 + 32);
if ( !v7 )
return 0LL;
*a2 = v6 + 1;
sprintf(a3, "ou=%s,%s", v7, a4);
return 1LL;
}

original_code:
static int get_dn_with_ad_cond(win_ad_cond *cond, int *offset, char *dn, const char *dc_s){
    char *p = cond->ad_org_unitS[*offset];
    if(!p)
        return 0;
    (*offset)++;
    sprintf(dn, "ou=%s,%s", p, dc_s);
    return 1;
}

canonical_original_code:
static int get_dn_with_ad_cond(struct _ldap_cond *cond, int *offset, char *dn, char *dc_s){
    char *p = cond->ad_org_unitS[*offset];
    if(!p)
        return 0;
    (*offset)++;
    sprintf(dn, "ou=%s,%s", p, dc_s);
    return 1;
}

variable_types: struct _ldap_cond { int ad_gflag; int ad_get_udir; int ad_encrypt; char *ad_uri; char *ad_manager; char *ad_passwd; char *ad_org_unitS[1024]; } *

variable_types:
offset
int *

variable_types:
dn
char *

variable_types:
p
char *

return_type: int


decompiled_code:
__int64 __fastcall is_ascii_str(char *a1)
{
char v1; // al
char *v2; // rbx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1 + 1;
do
{
if ( v1 < 0 || isspace(v1) )
return 0LL;
v1 = *v2++;
}
while ( v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v1; // al
char *v2; // rbx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1 + 1;
do
{
if ( v1 < 0 || isspace(v1) )
return 0LL;
v1 = *v2++;
}
while ( v1 );
return 1LL;
}

original_code:
static int is_ascii_str(const char *buf){
    int i;
    for(i = 0; buf[i]; i++){
        if(!isascii(buf[i]) || isspace(buf[i]))
            return 0;
    }
    return 1;
}

canonical_original_code:
static int is_ascii_str(char *buf){
    int i;
    for(i = 0; buf[i]; i++){
        if(!isascii(buf[i]) || isspace(buf[i]))
            return 0;
    }
    return 1;
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall init_ad_cond(const char *a1, const char *a2)
{
char **v2; // rbx
char *v3; // rax
unsigned int v4; // er8
bool v6; // zf
char *v7; // rax
char *v8; // rax
char *v9; // rax
_QWORD v10[129]; // [rsp+0h] [rbp-408h] BYREF

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( !strcmp(a1, "ad_uri") && !*((_QWORD *)&ad + 1) )
{
v10[0] = 0x2F2F3A7061646CLL;
strcpy((char *)v10 + 7, a2);
v7 = strdup((const char *)v10);
*((_QWORD *)&ad + 1) = v7;
v4 = -(v7 == 0LL);
}
else if ( !strcmp(a1, "ad_manager") && !*((_QWORD *)&ad + 2) )
{
v8 = strdup(a2);
*((_QWORD *)&ad + 2) = v8;
v4 = -(v8 == 0LL);
}
else if ( !strcmp(a1, "ad_passwd") && !*((_QWORD *)&ad + 3) )
{
v9 = strdup(a2);
*((_QWORD *)&ad + 3) = v9;
v4 = -(v9 == 0LL);
}
else if ( !strcmp(a1, "ad_org_unitS") )
{
v2 = (char **)(unsigned int)((_DWORD)&ad + 32);
if ( *((_QWORD *)&ad + 4) )
{
do
++v2;
while ( *v2 );
}
v3 = strdup(a2);
*v2 = v3;
v4 = -(v3 == 0LL);
}
else
{
v6 = strcmp(a1, "ad_gflag") == 0;
v4 = !v6;
if ( v6 )
{
if ( (ad & 1) == 0 )
ad |= 1u;
}
else
{
v6 = strcmp(a1, "ad_get_udir") == 0;
v4 = !v6;
if ( v6 )
{
if ( (ad & 2) == 0 )
ad |= 2u;
}
else
{
v6 = strcmp(a1, "ad_encrypt") == 0;
v4 = !v6;
if ( v6 )
ad |= 4u;
else
v4 = 0;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
char **v2; // rbx
char *v3; // rax
unsigned int v4; // er8
bool v6; // zf
char *v7; // rax
char *v8; // rax
char *v9; // rax
_QWORD v10[129]; // [rsp+0h] [rbp-408h] BYREF

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
if ( !strcmp(a1, "ad_uri") && !*((_QWORD *)&ad + 1) )
{
v10[0] = 0x2F2F3A7061646CLL;
strcpy((char *)v10 + 7, a2);
v7 = strdup((const char *)v10);
*((_QWORD *)&ad + 1) = v7;
v4 = -(v7 == 0LL);
}
else if ( !strcmp(a1, "ad_manager") && !*((_QWORD *)&ad + 2) )
{
v8 = strdup(a2);
*((_QWORD *)&ad + 2) = v8;
v4 = -(v8 == 0LL);
}
else if ( !strcmp(a1, "ad_passwd") && !*((_QWORD *)&ad + 3) )
{
v9 = strdup(a2);
*((_QWORD *)&ad + 3) = v9;
v4 = -(v9 == 0LL);
}
else if ( !strcmp(a1, "ad_org_unitS") )
{
v2 = (char **)(unsigned int)((_DWORD)&ad + 32);
if ( *((_QWORD *)&ad + 4) )
{
do
++v2;
while ( *v2 );
}
v3 = strdup(a2);
*v2 = v3;
v4 = -(v3 == 0LL);
}
else
{
v6 = strcmp(a1, "ad_gflag") == 0;
v4 = !v6;
if ( v6 )
{
if ( (ad & 1) == 0 )
ad |= 1u;
}
else
{
v6 = strcmp(a1, "ad_get_udir") == 0;
v4 = !v6;
if ( v6 )
{
if ( (ad & 2) == 0 )
ad |= 2u;
}
else
{
v6 = strcmp(a1, "ad_encrypt") == 0;
v4 = !v6;
if ( v6 )
ad |= 4u;
else
v4 = 0;
}
}
}
return v4;
}

original_code:
int init_ad_cond(const char *key, const char *value){
    char buf[1024];
    char **p;
    if(!key || !value)
        return -1;
    if(!strcmp(key, "ad_uri") && !ad.ad_uri){
        strcpy(buf, "ldap://");
        strcat(buf, value);
        if((ad.ad_uri = strdup(buf)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_manager") && !ad.ad_manager){
        if((ad.ad_manager = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_passwd") && !ad.ad_passwd){
        if((ad.ad_passwd = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_org_unitS")){
        p = ad.ad_org_unitS;
        while(*p) p++;
        if((*p = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_gflag")){
        if(!ad.ad_gflag)
            ad.ad_gflag = 1;
    }else if(!strcmp(key, "ad_get_udir")){
        if(!ad.ad_get_udir)
            ad.ad_get_udir = 1;
    }else if(!strcmp(key, "ad_encrypt")){
        ad.ad_encrypt = 1;
    }
    return 0;
}

canonical_original_code:
int init_ad_cond(char *key, char *value){
    char buf[1024];
    char **p;
    if(!key || !value)
        return -1;
    if(!strcmp(key, "ad_uri") && !ad.ad_uri){
        strcpy(buf, "ldap://");
        strcat(buf, value);
        if((ad.ad_uri = strdup(buf)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_manager") && !ad.ad_manager){
        if((ad.ad_manager = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_passwd") && !ad.ad_passwd){
        if((ad.ad_passwd = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_org_unitS")){
        p = ad.ad_org_unitS;
        while(*p) p++;
        if((*p = strdup(value)) == ((void *)0))
            return -1;
    }else if(!strcmp(key, "ad_gflag")){
        if(!ad.ad_gflag)
            ad.ad_gflag = 1;
    }else if(!strcmp(key, "ad_get_udir")){
        if(!ad.ad_get_udir)
            ad.ad_get_udir = 1;
    }else if(!strcmp(key, "ad_encrypt")){
        ad.ad_encrypt = 1;
    }
    return 0;
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
buf
char [1024]

variable_types:
p
char **


getnext

repo: omnister/piglet

decompiled_code:
__int64 __fastcall getnext(int a1)
{
__int64 i; // rax
unsigned int v2; // er8
int v3; // ecx

for ( i = offset + 1; ; ++i )
{
v2 = *(char *)(pc + i - 1);
v3 = i;
if ( v2 != 32 )
break;
if ( !a1 )
{
offset = v3;
return 32LL;
}
}
offset = i;
if ( !v2 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 i; // rax
unsigned int v2; // er8
int v3; // ecx

for ( i = offset + 1; ; ++i )
{
v2 = *(char *)(pc + i - 1);
v3 = i;
if ( v2 != 32 )
break;
if ( !a1 )
{
offset = v3;
return 32LL;
}
}
offset = i;
if ( !v2 )
v2 = -1;
return v2;
}

original_code:
int getnext(int eatblanks) {
    int c;
 while ((((c = pc[offset++]) == ' ') && eatblanks ) && c!= '\0') {
  ;
 }
    if (c !='\0') {
        return(c);
    } else {
        return((-1));
    }
}

variable_types: eatblanks int

variable_types: c int


ungetnext

decompiled_code:
__int64 ungetnext()
{
__int64 result; // rax

result = (unsigned int)offset;
if ( offset > 0 )
return (unsigned int)--offset;
++errflag;
return result;
}

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

result = (unsigned int)offset;
if ( offset > 0 )
return (unsigned int)--offset;
++errflag;
return result;
}

original_code:
void ungetnext() {
    if (offset > 0) {
        offset--;
    } else {
  errflag++;
 }
}

return_type: void


getval

decompiled_code:
double getval()
{
int v0; // eax
double v1; // xmm1_8
double v2; // xmm0_8
int v3; // esi
double v4; // xmm4_8
double result; // xmm0_8

v0 = getnext(0);
if ( (unsigned int)(v0 - 48) <= 9 || (v1 = *(double *)&LC0, v2 = 0.0, v0 == 46) )
{
v3 = 0;
v2 = 0.0;
v1 = *(double *)&LC0;
while ( v0 != 46 )
{
LABEL_5:
v0 = getnext(0);
v2 = v2 * 10.0 + v4;
if ( (unsigned int)(v0 - 48) > 9 && v0 != 46 )
goto LABEL_13;
if ( v3 )
{
v1 = v1 * 10.0;
goto LABEL_9;
}
}
while ( 1 )
{
++v3;
v0 = getnext(0);
v1 = *(double *)&LC0;
if ( (unsigned int)(v0 - 48) > 9 && v0 != 46 )
break;
v1 = 1.0 * 10.0;
LABEL_9:
if ( v0 != 46 )
goto LABEL_5;
}
}
LABEL_13:
if ( v0 )
result = ungetnext(v2, v1) / v1;
else
result = v2 / v1;
return result;
}

canonical_decompiled_code:
double func2()
{
int v0; // eax
double v1; // xmm1_8
double v2; // xmm0_8
int v3; // esi
double v4; // xmm4_8
double result; // xmm0_8

v0 = func0(0);
if ( (unsigned int)(v0 - 48) <= 9 || (v1 = *(double *)&LC0, v2 = 0.0, v0 == 46) )
{
v3 = 0;
v2 = 0.0;
v1 = *(double *)&LC0;
while ( v0 != 46 )
{
LABEL_5:
v0 = func0(0);
v2 = v2 * 10.0 + v4;
if ( (unsigned int)(v0 - 48) > 9 && v0 != 46 )
goto LABEL_13;
if ( v3 )
{
v1 = v1 * 10.0;
goto LABEL_9;
}
}
while ( 1 )
{
++v3;
v0 = func0(0);
v1 = *(double *)&LC0;
if ( (unsigned int)(v0 - 48) > 9 && v0 != 46 )
break;
v1 = 1.0 * 10.0;
LABEL_9:
if ( v0 != 46 )
goto LABEL_5;
}
}
LABEL_13:
if ( v0 )
result = func1(v2, v1) / v1;
else
result = v2 / v1;
return result;
}

original_code:
double getval()
{
    double val = 0.0;
    double power = 1.0;
    int c;
    int sawpoint = 0;
    c = getnext(0);
    for (val = 0; (c >= '0' && c <= '9') || c == '.'; c = getnext(0)) {
        if (sawpoint) {
            power *= 10.0;
        }
        if (c == '.') {
            power = 1.0;
            sawpoint++;
        } else {
            val = 10 * val + (double) (c - '0');
        }
    }
    if (c != '\0') { ungetnext(); }
    return (val / power);
}

variable_types: val double

variable_types: power double

variable_types: sawpoint int

return_type: double


primary

decompiled_code:
double __fastcall primary(double result, double a2)
{
int v2; // eax

v2 = getnext(1);
if ( (unsigned int)(v2 - 48) <= 9 || v2 == 46 )
{
ungetnext(result, a2);
result = getval();
}
else if ( v2 == 40 )
{
expr();
if ( (unsigned int)getnext(1) != 41 )
++errflag;
}
else
{
result = ungetnext(0.0, a2);
++errflag;
}
return result;
}

canonical_decompiled_code:
double __fastcall func3(double result, double a2)
{
int v2; // eax

v2 = func0(1);
if ( (unsigned int)(v2 - 48) <= 9 || v2 == 46 )
{
func1(result, a2);
result = func2();
}
else if ( v2 == 40 )
{
func6();
if ( (unsigned int)func0(1) != 41 )
++errflag;
}
else
{
result = func1(0.0, a2);
++errflag;
}
return result;
}

original_code:
double primary(void)
{
    double val=0.0;
    int c;
 int debug=0;
    c = getnext(1);
    if ((c >= '0' && c <= '9') || c == '.') {
        ungetnext();
        val = getval();
    } else if (c == '(') {
        val = expr();
        if ((c=getnext(1)) != ')') {
   errflag++;
  }
    } else {
  ungetnext();
     if (debug) printf("error: primary read <%c> = %d\n", c, c);
  errflag++;
 }
    return (val);
}

canonical_original_code:
double primary()
{
    double val = 0.0;
    int c;
 int debug = 0;
    c = getnext(1);
    if ((c >= '0' && c <= '9') || c == '.') {
        ungetnext();
        val = getval();
    } else if (c == '(') {
        val = expr();
        if ((c=getnext(1)) != ')') {
   errflag++;
  }
    } else {
  ungetnext();
     if (debug) printf("error: primary read <%c> = %d\n", c, c);
  errflag++;
 }
    return (val);
}

variable_types: debug int


unary

decompiled_code:
__m128d __fastcall unary(__m128d result, double a2)
{
int v2; // eax
double v3; // xmm0_8

do
v2 = getnext(1);
while ( v2 == 43 );
if ( v2 == 45 )
{
result.m128d_f64[0] = unary();
result = _mm_xor_pd(result, (__m128d)LC3);
}
else
{
v3 = ungetnext(result.m128d_f64[0], a2);
result.m128d_f64[0] = primary(v3, a2);
}
return result;
}

canonical_decompiled_code:
__m128d __fastcall func4(__m128d result, double a2)
{
int v2; // eax
double v3; // xmm0_8

do
v2 = func0(1);
while ( v2 == 43 );
if ( v2 == 45 )
{
result.m128d_f64[0] = func4();
result = _mm_xor_pd(result, (__m128d)LC3);
}
else
{
v3 = func1(result.m128d_f64[0], a2);
result.m128d_f64[0] = func3(v3, a2);
}
return result;
}

original_code:
double unary(void)
{
    double val;
    int c;
    switch (c = getnext(1)) {
    case '+':
        val = unary();
        break;
    case '-':
        val = -unary();
        break;
    default:
        ungetnext();
        val = primary();
        break;
    }
    return (val);
}

canonical_original_code:
double unary()
{
    double val;
    int c;
    switch (c = getnext(1)) {
    case '+':
        val = unary();
        break;
    case '-':
        val = -unary();
        break;
    default:
        ungetnext();
        val = primary();
        break;
    }
    return (val);
}


mulexp

original_code:
double mulexp(void)
{
    double val;
    int c;
    val = unary();
    for (;;) {
        switch (c = getnext(1)) {
        case '*':
            val *= unary();
            break;
        case '/':
            val /= unary();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}

canonical_original_code:
double mulexp()
{
    double val;
    int c;
    val = unary();
    for (;;) {
        switch (c = getnext(1)) {
        case '*':
            val *= unary();
            break;
        case '/':
            val /= unary();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}


expr

original_code:
double expr(void)
{
    double val;
    int c;
    val = mulexp();
    for (;;) {
        switch (c = getnext(1)) {
        case '+':
            val += mulexp();
            break;
        case '-':
            val -= mulexp();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}

canonical_original_code:
double expr()
{
    double val;
    int c;
    val = mulexp();
    for (;;) {
        switch (c = getnext(1)) {
        case '+':
            val += mulexp();
            break;
        case '-':
            val -= mulexp();
            break;
        default:
            ungetnext();
            return (val);
            break;
        }
    }
}


decompiled_code:
__int64 __fastcall parse_exp(double *a1, const char *a2, __m128d a3, double a4)
{
double v4; // xmm0_8
size_t v5; // r8
__int64 result; // rax

pc = (__int64)a2;
errflag = 0;
offset = 0;
v4 = expr(a3, a4);
*a1 = v4;
v5 = strlen(a2);
result = (unsigned int)errflag;
if ( v5 != offset )
result = (unsigned int)++errflag;
if ( (_DWORD)result )
v4 = 0.0;
*a1 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(double *a1, const char *a2, __m128d a3, double a4)
{
double v4; // xmm0_8
size_t v5; // r8
__int64 result; // rax

pc = (__int64)a2;
errflag = 0;
offset = 0;
v4 = func6(a3, a4);
*a1 = v4;
v5 = strlen(a2);
result = (unsigned int)errflag;
if ( v5 != offset )
result = (unsigned int)++errflag;
if ( (_DWORD)result )
v4 = 0.0;
*a1 = v4;
return result;
}

original_code:
int parse_exp(double *val, char * expression) {
        pc = expression;
 errflag=0;
 offset=0;
 *val = expr();
 if (strlen(pc)-offset) errflag++;
 if (errflag) {
  *val = 0.0;
 }
 return(errflag);
}

canonical_original_code:
int parse_exp(double *val, char *expression) {
        pc = expression;
 errflag=0;
 offset=0;
 *val = expr();
 if (strlen(pc)-offset) errflag++;
 if (errflag) {
  *val = 0.0;
 }
 return(errflag);
}

variable_types:
val
double *

variable_types:
expression
char *


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

for ( i = 0LL; i != 1024; ++i )
{
sprintf(v5, "UNDEF%04d", (unsigned int)i);
v1 = strsave(v5);
v2 = i;
v3 = 2LL * (int)i;
equates[2 * v2 + 1] = v1;
LODWORD(equates[v3]) = equates[v3] & 0xFFFE0000 | 0x401;
}
LODWORD(equates[0]) = equates[0] & 0xFFFE0000 | (!(equates[0] & 0x10000) << 16);
return 0LL;
}

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

for ( i = 0LL; i != 1024; ++i )
{
sprintf(v5, "UNDEF%04d", (unsigned int)i);
v1 = strsave(v5);
v2 = i;
v3 = 2LL * (int)i;
equates[2 * v2 + 1] = v1;
LODWORD(equates[v3]) = equates[v3] & 0xFFFE0000 | 0x401;
}
LODWORD(equates[0]) = equates[0] & 0xFFFE0000 | (!(equates[0] & 0x10000) << 16);
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: i int

variable_types:
buf
char [128]


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


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_45F5[a1 % 4];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned int)byte_45F5[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_45F5, (*v1)[a1]);
if ( v2 )
result = v2 - byte_45F5;
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_45F5, (*v1)[a1]);
if ( v2 )
result = v2 - byte_45F5;
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_45FA + a1 % 7);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return (unsigned int)*(&byte_45FA + 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; // rbp
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // rdx

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

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

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


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

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

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

for ( i = 0; i != 1024; ++i )
{
v1 = i;
result = 16 * v1;
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;
    }
}


decompiled_code:
int __fastcall equate_toggle_override(unsigned int a1)
{
char v1; // dl
int result; // eax

if ( a1 > 0x3FF )
return printf("invalid layer %d\n", a1);
v1 = equates[16 * a1];
result = *(_DWORD *)&v1 | 0xFFFFFF80;
if ( v1 < 0 )
result = v1 & 0x7F;
equates[16 * a1] = result;
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
char v1; // dl
int result; // eax

if ( a1 > 0x3FF )
return printf("invalid layer %d\n", a1);
v1 = equates[16 * a1];
result = *(_DWORD *)&v1 | 0xFFFFFF80;
if ( v1 < 0 )
result = v1 & 0x7F;
equates[16 * a1] = result;
return result;
}

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 = equates[16 * a1] >> 7;
return result;
}

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

result = 0LL;
if ( a1 <= 0x3FF )
result = 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, __int16 a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFE1FFF;
*(_DWORD *)&equates[v2] = result | (unsigned __int16)(a2 << 13) | 0x10000;
return result;
}

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

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFE1FFF;
*(_DWORD *)&equates[v2] = result | (unsigned __int16)(a2 << 13) | 0x10000;
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 equates[16 * a1 + 1] >> 5;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return 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, __int16 a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFEFCFF;
*(_DWORD *)&equates[v2] = result | (a2 << 8) & 0x300 | 0x10000;
return result;
}

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

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFEFCFF;
*(_DWORD *)&equates[v2] = result | (a2 << 8) & 0x300 | 0x10000;
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;
result = *(_DWORD *)&equates[v2] & 0xFFFEFF8F;
*(_DWORD *)&equates[v2] = result | (16 * a2) & 0x70 | 0x10000;
return result;
}

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

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFEFF8F;
*(_DWORD *)&equates[v2] = result | (16 * a2) & 0x70 | 0x10000;
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 (equates[16 * a1] >> 4) & 7;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
return (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;
result = *(_DWORD *)&equates[v2] & 0xFFFEFFF0;
*(_DWORD *)&equates[v2] = result | a2 & 0xF | 0x10000;
return result;
}

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

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFEFFF0;
*(_DWORD *)&equates[v2] = result | a2 & 0xF | 0x10000;
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, __int16 a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFEE3FF;
*(_DWORD *)&equates[v2] = result | (a2 << 10) & 0x1C00 | 0x10000;
return result;
}

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

v2 = 16LL * a1;
result = *(_DWORD *)&equates[v2] & 0xFFFEE3FF;
*(_DWORD *)&equates[v2] = result | (a2 << 10) & 0x1C00 | 0x10000;
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 (equates[16 * a1 + 1] >> 2) & 7;
}

canonical_decompiled_code:
__int64 __fastcall func20(int a1)
{
return (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 v2; // rbx
__int64 v3; // rax
void *v4; // rdi
__int64 result; // rax

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

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

v2 = a1;
v3 = 16LL * a1;
v4 = *(void **)&equates[v3 + 8];
equates[v3 + 2] |= 1u;
if ( v4 )
free(v4);
result = strsave(a2);
*(_QWORD *)&equates[16 * v2 + 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; // rdx
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; // rdx
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:
void *__fastcall estrdup(const char *a1)
{
size_t v1; // r12
void *v2; // rax

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

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

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

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:
void *__fastcall setprogname(const char *a1)
{
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func3(const char *a1)
{
void *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; // rdx
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; // rdx
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; // rax
unsigned int v4; // edx
const __int32_t *v5; // rcx
unsigned int v6; // eax

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

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

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1;
v3 = _ctype_toupper_loc();
v4 = 0;
v5 = *v3;
do
{
++v2;
v6 = v5[v1] + 31 * v4;
v1 = *v2;
v4 = v6;
}
while ( *v2 );
return v6 % 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; // r12

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; // r12

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(void **a1, const char *a2)
{
int v3; // eax
void *v4; // rdi
void *v5; // rax
char *v6; // rdi
void *v8; // rax

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

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

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

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:
__int64 __fastcall EVset(char *s, const char *a2)
{
__int64 v2; // r12
_QWORD *v4; // rax
char *v5; // rax
int v6; // eax
__int64 v7; // rdx

v2 = lookup(s);
if ( !v2 )
{
v4 = malloc(0x20uLL);
v4[1] = 0LL;
v2 = (__int64)v4;
v4[2] = 0LL;
v5 = strdup(s);
*(_QWORD *)v2 = v5;
if ( !v5 )
return 0LL;
v6 = hash((unsigned __int8 *)s);
v7 = hashtab[v6];
hashtab[v6] = v2;
*(_QWORD *)(v2 + 24) = v7;
}
assign((void **)(v2 + 8), a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, const char *a2)
{
__int64 v2; // r12
_QWORD *v4; // rax
char *v5; // rax
int v6; // eax
__int64 v7; // rdx

v2 = func1(s);
if ( !v2 )
{
v4 = malloc(0x20uLL);
v4[1] = 0LL;
v2 = (__int64)v4;
v4[2] = 0LL;
v5 = strdup(s);
*(_QWORD *)v2 = v5;
if ( !v5 )
return 0LL;
v6 = func0((unsigned __int8 *)s);
v7 = hashtab[v6];
hashtab[v6] = v2;
*(_QWORD *)(v2 + 24) = v7;
}
func2((void **)(v2 + 8), 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 func6(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 func7(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 func8(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()
{
char **v0; // r12
char *v1; // rbp
__int64 i; // r13
size_t v3; // rbx
char v5[248]; // [rsp+0h] [rbp-F8h] BYREF

v0 = environ;
memset(hashtab, 0, sizeof(hashtab));
v1 = *environ;
if ( !*environ )
return 1LL;
for ( i = 1LL; ; ++i )
{
v3 = (int)strcspn(v1, "=");
strncpy(v5, v1, v3);
v5[v3] = 0;
if ( !EVset(v5, &(*v0)[v3 + 1]) || !(unsigned int)EVexport(v5) )
break;
v0 = &environ[i];
v1 = *v0;
if ( !*v0 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
char **v0; // r12
char *v1; // rbp
__int64 i; // r13
size_t v3; // rbx
char v5[248]; // [rsp+0h] [rbp-F8h] BYREF

v0 = environ;
memset(hashtab, 0, sizeof(hashtab));
v1 = *environ;
if ( !*environ )
return 1LL;
for ( i = 1LL; ; ++i )
{
v3 = (int)strcspn(v1, "=");
strncpy(v5, v1, v3);
v5[v3] = 0;
if ( !func3(v5, &(*v0)[v3 + 1]) || !(unsigned int)func7(v5) )
break;
v0 = &environ[i];
v1 = *v0;
if ( !*v0 )
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()
{
char **v0; // rax
const char *v1; // r14
int v2; // ebp
const char **v3; // rbx
void *v4; // rax
char *v5; // rdi
void **v6; // r13
int v7; // er15
size_t v8; // rsi
void *v9; // rax
const char *v11; // rsi
int v12; // edx
__int64 i; // rax
bool v14; // zf

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

canonical_decompiled_code:
__int64 func10()
{
char **v0; // rax
const char *v1; // r14
int v2; // ebp
const char **v3; // rbx
void *v4; // rax
char *v5; // rdi
void **v6; // r13
int v7; // er15
size_t v8; // rsi
void *v9; // rax
const char *v11; // rsi
int v12; // edx
__int64 i; // rax
bool v14; // zf

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

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)
{
double v3; // xmm5_8
double v4; // xmm4_8
double v5; // xmm3_8
double v6; // xmm2_8
__int64 v7; // xmm5_8
__int64 v8; // xmm4_8
double v10; // [rsp+0h] [rbp-48h]
double v11; // [rsp+8h] [rbp-40h]
char v12[32]; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+30h] [rbp-18h]

v3 = a2;
v4 = a3;
v13 = 0;
if ( a1 )
{
v11 = a3;
v10 = a2;
if ( a1 <= 0 )
{
db_drawbounds(1LL, *(double *)&x1old_0, *(double *)&y1old_1, *(double *)&x2old_2, *(double *)&y2old_3, a3, a2);
v8 = *(_QWORD *)&a3;
v7 = *(_QWORD *)&a2;
goto LABEL_5;
}
db_drawbounds(1LL, *(double *)&x1old_0, *(double *)&y1old_1, *(double *)&x2old_2, *(double *)&y2old_3, a3, a2);
v4 = a3;
v3 = a2;
v5 = a3;
v6 = a2;
}
else
{
v5 = a3;
v11 = a3;
v6 = a2;
v10 = a2;
}
db_drawbounds(1LL, *(double *)&x1, *(double *)&yy1, v6, v5, v4, v3);
v7 = *(_QWORD *)&v10;
v8 = *(_QWORD *)&v11;
LABEL_5:
x2old_2 = v7;
y2old_3 = v8;
x1old_0 = x1;
y1old_1 = yy1;
return jump(v12, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3)
{
double v3; // xmm5_8
double v4; // xmm4_8
double v5; // xmm3_8
double v6; // xmm2_8
__int64 v7; // xmm5_8
__int64 v8; // xmm4_8
double v10; // [rsp+0h] [rbp-48h]
double v11; // [rsp+8h] [rbp-40h]
char v12[32]; // [rsp+10h] [rbp-38h] BYREF
int v13; // [rsp+30h] [rbp-18h]

v3 = a2;
v4 = a3;
v13 = 0;
if ( a1 )
{
v11 = a3;
v10 = a2;
if ( a1 <= 0 )
{
db_drawbounds(1LL, *(double *)&x1old_0, *(double *)&y1old_1, *(double *)&x2old_2, *(double *)&y2old_3, a3, a2);
v8 = *(_QWORD *)&a3;
v7 = *(_QWORD *)&a2;
goto LABEL_5;
}
db_drawbounds(1LL, *(double *)&x1old_0, *(double *)&y1old_1, *(double *)&x2old_2, *(double *)&y2old_3, a3, a2);
v4 = a3;
v3 = a2;
v5 = a3;
v6 = a2;
}
else
{
v5 = a3;
v11 = a3;
v6 = a2;
v10 = a2;
}
db_drawbounds(1LL, *(double *)&x1, *(double *)&yy1, v6, v5, v4, v3);
v7 = *(_QWORD *)&v10;
v8 = *(_QWORD *)&v11;
LABEL_5:
x2old_2 = v7;
y2old_3 = v8;
x1old_0 = x1;
y1old_1 = yy1;
return jump(v12, 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; // rbx
__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;
++need_redraw;
++*(_DWORD *)(currep + 4308LL);
}
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; // rbx
__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;
++need_redraw;
++*(_DWORD *)(currep + 4308LL);
}
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
__int64 v7; // xmm0_8

if ( a2 > 0 )
{
v4 = 1;
if ( a2 == 1 )
goto LABEL_7;
while ( 1 )
{
a1 = (_QWORD *)a1[2];
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
if ( a2 == v4 )
{
LABEL_7:
result = 0LL;
*a3 = *a1;
*a4 = a1[1];
return result;
}
return 0xFFFFFFFFLL;
}
v6 = (_QWORD *)a1[3];
if ( a2 )
{
do
{
v6 = (_QWORD *)v6[3];
if ( !v6 )
return 0xFFFFFFFFLL;
}
while ( ++a2 );
}
*a3 = *v6;
v7 = v6[1];
result = 0LL;
*a4 = v7;
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
__int64 v7; // xmm0_8

if ( a2 > 0 )
{
v4 = 1;
if ( a2 == 1 )
goto LABEL_7;
while ( 1 )
{
a1 = (_QWORD *)a1[2];
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
if ( a2 == v4 )
{
LABEL_7:
result = 0LL;
*a3 = *a1;
*a4 = a1[1];
return result;
}
return 0xFFFFFFFFLL;
}
v6 = (_QWORD *)a1[3];
if ( a2 )
{
do
{
v6 = (_QWORD *)v6[3];
if ( !v6 )
return 0xFFFFFFFFLL;
}
while ( ++a2 );
}
*a3 = *v6;
v7 = v6[1];
result = 0LL;
*a4 = v7;
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 )
{
v4 = 1;
if ( a2 == 1 )
goto LABEL_7;
while ( 1 )
{
a1 = *(_QWORD *)(a1 + 16);
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
if ( a2 == v4 )
{
LABEL_7:
*(double *)a1 = a3;
result = 0LL;
*(double *)(a1 + 8) = a4;
return result;
}
return 0xFFFFFFFFLL;
}
v6 = *(_QWORD *)(a1 + 24);
if ( a2 )
{
do
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
return 0xFFFFFFFFLL;
}
while ( ++a2 );
}
*(double *)v6 = a3;
*(double *)(v6 + 8) = a4;
return 0LL;
}

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 )
{
v4 = 1;
if ( a2 == 1 )
goto LABEL_7;
while ( 1 )
{
a1 = *(_QWORD *)(a1 + 16);
if ( !a1 )
break;
if ( a2 == ++v4 )
goto LABEL_7;
}
if ( a2 == v4 )
{
LABEL_7:
*(double *)a1 = a3;
result = 0LL;
*(double *)(a1 + 8) = a4;
return result;
}
return 0xFFFFFFFFLL;
}
v6 = *(_QWORD *)(a1 + 24);
if ( a2 )
{
do
{
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
return 0xFFFFFFFFLL;
}
while ( ++a2 );
}
*(double *)v6 = a3;
*(double *)(v6 + 8) = a4;
return 0LL;
}

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 i; // er8

v1 = *(_QWORD *)(a1 + 16);
for ( i = 1; v1; ++i )
v1 = *(_QWORD *)(v1 + 16);
return i;
}

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

v1 = *(_QWORD *)(a1 + 16);
for ( i = 1; v1; ++i )
v1 = *(_QWORD *)(v1 + 16);
return i;
}

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:
__int64 __fastcall coord_copy(__int64 a1, __int64 a2)
{
double v2; // xmm1_8
double *v3; // rax
__int64 *v4; // rbx
__int64 i; // r12
double *v7; // rax
__int64 v8; // rbx
double v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a2 )
{
i = 0LL;
puts("coord_copy: can't copy null coordinate list");
return i;
}
v2 = *(double *)(a2 + 8);
if ( a1 )
{
v9 = *(double *)a2;
*(double *)v10 = v2;
xform_point(a1, &v9, v10);
v3 = coord_new(v9, *(double *)v10);
v4 = *(__int64 **)(a2 + 16);
for ( i = (__int64)v3; v4; v4 = (__int64 *)v4[2] )
{
v9 = *(double *)v4;
v10[0] = v4[1];
xform_point(a1, &v9, v10);
coord_append(v9, *(double *)v10, i);
}
return i;
}
v7 = coord_new(*(double *)a2, v2);
v8 = *(_QWORD *)(a2 + 16);
i = (__int64)v7;
if ( !v8 )
return i;
do
{
coord_append(*(double *)v8, *(double *)(v8 + 8), i);
v8 = *(_QWORD *)(v8 + 16);
}
while ( v8 );
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
double v2; // xmm1_8
double *v3; // rax
__int64 *v4; // rbx
__int64 i; // r12
double *v7; // rax
__int64 v8; // rbx
double v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a2 )
{
i = 0LL;
puts("coord_copy: can't copy null coordinate list");
return i;
}
v2 = *(double *)(a2 + 8);
if ( a1 )
{
v9 = *(double *)a2;
*(double *)v10 = v2;
xform_point(a1, &v9, v10);
v3 = func3(v9, *(double *)v10);
v4 = *(__int64 **)(a2 + 16);
for ( i = (__int64)v3; v4; v4 = (__int64 *)v4[2] )
{
v9 = *(double *)v4;
v10[0] = v4[1];
xform_point(a1, &v9, v10);
func4(v9, *(double *)v10, i);
}
return i;
}
v7 = func3(*(double *)a2, v2);
v8 = *(_QWORD *)(a2 + 16);
i = (__int64)v7;
if ( !v8 )
return i;
do
{
func4(*(double *)v8, *(double *)(v8 + 8), i);
v8 = *(_QWORD *)(v8 + 16);
}
while ( v8 );
return i;
}

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 func4(__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
const char *v1; // rdx
__int64 v2; // r13
unsigned __int64 v3; // r12
char *v4; // rbp
int v5; // ebx
int v6; // ebx
int v7; // ebx
const char *v8; // rdx
Pixmap result; // rax

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

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

for ( i = 0LL; i != 50; stipple[i - 1] = XCreateBitmapFromData(dpy, win, v1, 8u, 8u) )
{
v1 = (char *)&stip_src + i * 8;
++i;
}
v2 = (unsigned int)((_DWORD)stipple + 400);
v3 = (unsigned int)((_DWORD)&stip_src + 408);
do
{
v4 = (char *)(v3 - 8);
do
{
++v4;
v5 = (int)(drand48() * 255.0);
v6 = (int)(drand48() * 255.0) & v5;
v7 = (int)(drand48() * 255.0) & v6;
*(v4 - 1) = (int)(drand48() * 255.0) & v7;
}
while ( v4 != (char *)v3 );
v8 = (const char *)(v3 - 8);
v2 += 8LL;
v3 = (unsigned __int64)(v4 + 8);
result = XCreateBitmapFromData(dpy, win, v8, 8u, 8u);
*(_QWORD *)(v2 - 8) = result;
}
while ( v4 != (char *)&stip_src + 800 );
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 = (char *)&stip_src + 8 * a1;
return result;
}

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

result = 0LL;
if ( a1 <= 98 )
result = (char *)&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:
char *__fastcall get_hpgl_fill(int a1)
{
__int64 v1; // rdi
char *result; // rax

v1 = (unsigned int)(a1 % 8);
result = 0LL;
if ( (unsigned int)v1 <= 7 )
result = CSWTCH_8[v1];
return result;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
__int64 v1; // rdi
char *result; // rax

v1 = (unsigned int)(a1 % 8);
result = 0LL;
if ( (unsigned int)v1 <= 7 )
result = CSWTCH_8[v1];
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; // xmm0_8
char **v6; // rbx
int v7; // ebp
__int64 result; // rax

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

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

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

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, &v1, v2) )
printf("\t%g %g\n", v1, v2[0]);
else
printf("\tnot found: %g %g\n", v1, v2[0]);
}
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, &v1, v2) )
printf("\t%g %g\n", v1, v2[0]);
else
printf("\tnot found: %g %g\n", v1, v2[0]);
}
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()
{
void *result; // rax

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

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

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

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 && prompt )
free(prompt);
result = (void *)estrdup();
prompt = result;
return result;
}

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

if ( saveprompt && prompt )
free(prompt);
result = (void *)estrdup();
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:
void *__fastcall expdupstr(void *src, int a2)
{
size_t v2; // rbp
void *v3; // rax

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

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

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

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)
{
__int64 v1; // rbx
_BYTE *v2; // rbp
const unsigned __int16 **v3; // rdx

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

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

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

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