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

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

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

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

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

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

variable_types:
prompt
char *

variable_types:
buf
char [1024]


repo: omnister/piglet

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

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

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

return_type: void


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

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

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

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

variable_types: count int

variable_types: xold double

variable_types: yold double

variable_types: debug int

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

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

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_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 opt_parse(const char *a1, const char *a2, __int64 a3)
{
const char *v3; // rbp
char v5; // al
int v6; // er13
void *v7; // rdi
__int64 result; // rax
void *v9; // rdi
int v10; // eax
double v11; // [rsp+0h] [rbp-38h] BYREF
double v12; // [rsp+8h] [rbp-30h] BYREF

v3 = a1;
v5 = *a1;
if ( (*a1 & 0xF7) == 35 || v5 == 45 )
{
weprintf("options must start with a colon: \"%s\"\n", a1);
result = 0xFFFFFFFFLL;
}
else
{
switch ( v5 )
{
case '.':
v7 = *(void **)(a3 + 88);
if ( v7 )
free(v7);
*(_QWORD *)(a3 + 88) = strsave(v3);
result = 1LL;
break;
case '@':
v9 = *(void **)(a3 + 80);
if ( v9 )
free(v9);
*(_QWORD *)(a3 + 80) = strsave(v3);
result = 1LL;
break;
case ':':
v6 = (*_ctype_toupper_loc())[*((unsigned __int8 *)a1 + 1)];
if ( index(a2, v6) )
{
switch ( v6 )
{
case 'B':
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
*(_DWORD *)(a3 + 96) = (int)COERCE_DOUBLE(*(_QWORD *)&v11 & LC4);
break;
case 'F':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("fontsize must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)a3 = v11;
}
break;
case 'H':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("height must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 8) = v11;
}
break;
case 'J':
v3 = a1 + 2;
if ( !strncasecmp(a1 + 2, "SW", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 0;
result = 1LL;
}
else if ( !strncasecmp(v3, "SE", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 2;
result = 1LL;
}
else if ( !strncasecmp(v3, "NE", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 8;
result = 1LL;
}
else if ( !strncasecmp(v3, "NW", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 6;
result = 1LL;
}
else if ( !strncasecmp(v3, "S", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 1;
result = 1LL;
}
else if ( !strncasecmp(v3, "W", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 3;
result = 1LL;
}
else if ( !strncasecmp(v3, "C", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 4;
result = 1LL;
}
else if ( !strncasecmp(v3, "E", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 5;
result = 1LL;
}
else if ( !strncasecmp(v3, "N", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 7;
result = 1LL;
}
else
{
result = _isoc99_sscanf(v3, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 || v11 > 8.0 )
{
weprintf("justification must be between 0 and 8: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a3 + 24) = (int)v11;
}
}
break;
case 'M':
if ( !strncasecmp(a1 + 1, "MXY", 3uLL) )
{
*(_DWORD *)(a3 + 16) = 3;
result = 1LL;
}
else if ( !strncasecmp(a1 + 1, "MY", 2uLL) )
{
*(_DWORD *)(a3 + 16) = 2;
result = 1LL;
}
else if ( !strncasecmp(a1 + 1, "MX", 2uLL) )
{
*(_DWORD *)(a3 + 16) = 1;
result = 1LL;
}
else if ( !strncasecmp(a1 + 1, "M0", 2uLL) || !strncasecmp(a1 + 1, "MOFF", 4uLL) )
{
*(_DWORD *)(a3 + 16) = 0;
result = 1LL;
}
else
{
weprintf("unknown mirror option %s\n", a1);
result = 0xFFFFFFFFLL;
}
break;
case 'N':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( (unsigned int)((int)v11 + 2) > 0x65 )
{
weprintf("font_num must between 0 and 100: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a3 + 20) = (int)v11;
}
break;
case 'R':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 <= -370.0 || v11 >= 370.0 )
{
weprintf("option out of range: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 40) = v11;
}
break;
case 'S':
v3 = a1 + 2;
if ( (unsigned int)_isoc99_sscanf(a1 + 2, "%lf,%lf", &v11, &v12) != 2 )
goto LABEL_52;
v10 = (int)v11;
*(_DWORD *)(a3 + 28) = 1;
*(_DWORD *)(a3 + 36) = v10;
*(_DWORD *)(a3 + 32) = (int)v12;
result = 1LL;
break;
case 'W':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("width must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 48) = v11;
}
break;
case 'X':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("scale must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 56) = v11;
}
break;
case 'Y':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.01 || v11 > 100.0 )
{
weprintf("out of range (0.01 < Y < 100.0): %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 64) = v11;
}
break;
case 'Z':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result == 1 )
{
if ( v11 < -45.0 || v11 > 45.0 )
{
weprintf("out of range (+/-45 degrees): %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 72) = v11;
}
}
else
{
LABEL_52:
weprintf("invalid option argument: %s\n", v3);
result = 0xFFFFFFFFLL;
}
break;
default:
weprintf("unknown option ignored: %s\n", a1);
result = 0xFFFFFFFFLL;
break;
}
}
else
{
weprintf("invalid option (2) %s\n", a1);
result = 0xFFFFFFFFLL;
}
break;
default:
weprintf("unknown option ignored: %s\n", a1);
result = 1LL;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, __int64 a3)
{
const char *v3; // rbp
char v5; // al
int v6; // er13
void *v7; // rdi
__int64 result; // rax
void *v9; // rdi
int v10; // eax
double v11; // [rsp+0h] [rbp-38h] BYREF
double v12; // [rsp+8h] [rbp-30h] BYREF

v3 = a1;
v5 = *a1;
if ( (*a1 & 0xF7) == 35 || v5 == 45 )
{
weprintf("options must start with a colon: \"%s\"\n", a1);
result = 0xFFFFFFFFLL;
}
else
{
switch ( v5 )
{
case '.':
v7 = *(void **)(a3 + 88);
if ( v7 )
free(v7);
*(_QWORD *)(a3 + 88) = strsave(v3);
result = 1LL;
break;
case '@':
v9 = *(void **)(a3 + 80);
if ( v9 )
free(v9);
*(_QWORD *)(a3 + 80) = strsave(v3);
result = 1LL;
break;
case ':':
v6 = (*_ctype_toupper_loc())[*((unsigned __int8 *)a1 + 1)];
if ( index(a2, v6) )
{
switch ( v6 )
{
case 'B':
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
*(_DWORD *)(a3 + 96) = (int)COERCE_DOUBLE(*(_QWORD *)&v11 & LC4);
break;
case 'F':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("fontsize must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)a3 = v11;
}
break;
case 'H':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("height must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 8) = v11;
}
break;
case 'J':
v3 = a1 + 2;
if ( !strncasecmp(a1 + 2, "SW", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 0;
result = 1LL;
}
else if ( !strncasecmp(v3, "SE", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 2;
result = 1LL;
}
else if ( !strncasecmp(v3, "NE", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 8;
result = 1LL;
}
else if ( !strncasecmp(v3, "NW", 2uLL) )
{
*(_DWORD *)(a3 + 24) = 6;
result = 1LL;
}
else if ( !strncasecmp(v3, "S", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 1;
result = 1LL;
}
else if ( !strncasecmp(v3, "W", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 3;
result = 1LL;
}
else if ( !strncasecmp(v3, "C", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 4;
result = 1LL;
}
else if ( !strncasecmp(v3, "E", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 5;
result = 1LL;
}
else if ( !strncasecmp(v3, "N", 1uLL) )
{
*(_DWORD *)(a3 + 24) = 7;
result = 1LL;
}
else
{
result = _isoc99_sscanf(v3, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 || v11 > 8.0 )
{
weprintf("justification must be between 0 and 8: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a3 + 24) = (int)v11;
}
}
break;
case 'M':
if ( !strncasecmp(a1 + 1, "MXY", 3uLL) )
{
*(_DWORD *)(a3 + 16) = 3;
result = 1LL;
}
else if ( !strncasecmp(a1 + 1, "MY", 2uLL) )
{
*(_DWORD *)(a3 + 16) = 2;
result = 1LL;
}
else if ( !strncasecmp(a1 + 1, "MX", 2uLL) )
{
*(_DWORD *)(a3 + 16) = 1;
result = 1LL;
}
else if ( !strncasecmp(a1 + 1, "M0", 2uLL) || !strncasecmp(a1 + 1, "MOFF", 4uLL) )
{
*(_DWORD *)(a3 + 16) = 0;
result = 1LL;
}
else
{
weprintf("unknown mirror option %s\n", a1);
result = 0xFFFFFFFFLL;
}
break;
case 'N':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( (unsigned int)((int)v11 + 2) > 0x65 )
{
weprintf("font_num must between 0 and 100: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(a3 + 20) = (int)v11;
}
break;
case 'R':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 <= -370.0 || v11 >= 370.0 )
{
weprintf("option out of range: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 40) = v11;
}
break;
case 'S':
v3 = a1 + 2;
if ( (unsigned int)_isoc99_sscanf(a1 + 2, "%lf,%lf", &v11, &v12) != 2 )
goto LABEL_52;
v10 = (int)v11;
*(_DWORD *)(a3 + 28) = 1;
*(_DWORD *)(a3 + 36) = v10;
*(_DWORD *)(a3 + 32) = (int)v12;
result = 1LL;
break;
case 'W':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("width must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 48) = v11;
}
break;
case 'X':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.0 )
{
weprintf("scale must be positive: %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 56) = v11;
}
break;
case 'Y':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result != 1 )
goto LABEL_52;
if ( v11 < 0.01 || v11 > 100.0 )
{
weprintf("out of range (0.01 < Y < 100.0): %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 64) = v11;
}
break;
case 'Z':
v3 = a1 + 2;
result = _isoc99_sscanf(a1 + 2, "%lf", &v11);
if ( (_DWORD)result == 1 )
{
if ( v11 < -45.0 || v11 > 45.0 )
{
weprintf("out of range (+/-45 degrees): %s\n", v3);
result = 0xFFFFFFFFLL;
}
else
{
*(double *)(a3 + 72) = v11;
}
}
else
{
LABEL_52:
weprintf("invalid option argument: %s\n", v3);
result = 0xFFFFFFFFLL;
}
break;
default:
weprintf("unknown option ignored: %s\n", a1);
result = 0xFFFFFFFFLL;
break;
}
}
else
{
weprintf("invalid option (2) %s\n", a1);
result = 0xFFFFFFFFLL;
}
break;
default:
weprintf("unknown option ignored: %s\n", a1);
result = 1LL;
break;
}
}
return result;
}

original_code:
int opt_parse(
    char *optstring,
    char *validopts,
    OPTS *popt
) {
    double optval, optval2;
    int i;
    if (optstring[0] == '#' || optstring[0] == '-' || optstring[0] == '+') {
 weprintf("options must start with a colon: \"%s\"\n", optstring);
 return(-1);
    } else if (optstring[0] == '.') {
 if (popt->cname != ((void *)0)) {
    free (popt->cname);
 }
     popt->cname = strsave(optstring);
    } else if (optstring[0] == '@') {
 if (popt->sname != ((void *)0)) {
    free (popt->sname);
 }
     popt->sname = strsave(optstring);
    } else if (optstring[0] == ':') {
 if (index(validopts, toupper((unsigned char)optstring[1])) == ((void *)0)) {
     weprintf("invalid option (2) %s\n", optstring);
     return(-1);
 }
 switch (toupper((unsigned char)optstring[1])) {
     case 'B':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring);
      return(-1);
  }
         popt->bezier=(int) fabs(optval);
  break;
     case 'F':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("fontsize must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->font_size = optval;
  break;
     case 'H':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("height must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->height = optval;
  break;
     case 'J':
  if (strncasecmp(optstring+2,"SW",2) == 0) {
      popt->justification = 0;
  } else if (strncasecmp(optstring+2,"SE",2) == 0) {
      popt->justification = 2;
  } else if (strncasecmp(optstring+2,"NE",2) == 0) {
      popt->justification = 8;
  } else if (strncasecmp(optstring+2,"NW",2) == 0) {
      popt->justification = 6;
  } else if (strncasecmp(optstring+2,"S" ,1) == 0) {
      popt->justification = 1;
  } else if (strncasecmp(optstring+2,"W" ,1) == 0) {
      popt->justification = 3;
  } else if (strncasecmp(optstring+2,"C" ,1) == 0) {
      popt->justification = 4;
  } else if (strncasecmp(optstring+2,"E" ,1) == 0) {
      popt->justification = 5;
  } else if (strncasecmp(optstring+2,"N" ,1) == 0) {
      popt->justification = 7;
  } else {
      if(sscanf(optstring+2, "%lf", &optval) != 1) {
   weprintf("invalid option argument: %s\n", optstring+2);
   return(-1);
      }
      if (optval < 0.0 || optval > 8.0 ) {
           weprintf("justification must be between 0 and 8: %s\n", optstring+2);
           return(-1);
      }
      popt->justification = (int) optval;
  }
  break;
     case 'M':
  if (strncasecmp(optstring+1,"MXY",3) == 0) {
      popt->mirror = 3;
  } else if (strncasecmp(optstring+1,"MY",2) == 0) {
      popt->mirror = 2;
  } else if (strncasecmp(optstring+1,"MX",2) == 0) {
      popt->mirror = 1;
  } else if (strncasecmp(optstring+1,"M0",2) == 0) {
      popt->mirror = 0;
  } else if (strncasecmp(optstring+1,"MOFF",4) == 0) {
      popt->mirror = 0;
  } else {
      weprintf("unknown mirror option %s\n", optstring);
      return(-1);
  }
  break;
     case 'N':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  i = (int) optval;
  if (i <-2 || i >= 100) {
      weprintf("font_num must between 0 and 100: %s\n", optstring+2);
      return(-1);
  }
  popt->font_num = i;
  break;
     case 'R':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval <= -370.0 || optval >= 370.0 ) {
      weprintf("option out of range: %s\n", optstring+2);
      return(-1);
  }
  popt->rotation = optval;
  break;
     case 'S':
  if(sscanf(optstring+2, "%lf,%lf", &optval, &optval2) != 2) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  popt->cols = (int) optval;
  popt->rows = (int) optval2;
  popt->stepflag = 1;
  break;
     case 'W':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("width must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->width = optval;
  break;
     case 'X':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("scale must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->scale = optval;
  break;
     case 'Y':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.01 || optval > 100.0 ) {
      weprintf("out of range (0.01 < Y < 100.0): %s\n", optstring+2);
      return(-1);
  }
  popt->aspect_ratio = optval;
  break;
     case 'Z':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < -45.0 || optval > 45.0 ) {
      weprintf("out of range (+/-45 degrees): %s\n", optstring+2);
      return(-1);
  }
  popt->slant = optval;
  break;
     default:
  weprintf("unknown option ignored: %s\n", optstring);
  return(-1);
  break;
 }
    } else {
 weprintf("unknown option ignored: %s\n", optstring);
    }
    return(1);
}

canonical_original_code:
int opt_parse(char *optstring, char *validopts, struct opt_list *popt) {
    double optval; double optval2;
    int i;
    if (optstring[0] == '#' || optstring[0] == '-' || optstring[0] == '+') {
 weprintf("options must start with a colon: \"%s\"\n", optstring);
 return(-1);
    } else if (optstring[0] == '.') {
 if (popt->cname != ((void *)0)) {
    free (popt->cname);
 }
     popt->cname = strsave(optstring);
    } else if (optstring[0] == '@') {
 if (popt->sname != ((void *)0)) {
    free (popt->sname);
 }
     popt->sname = strsave(optstring);
    } else if (optstring[0] == ':') {
 if (index(validopts, toupper((unsigned char)optstring[1])) == ((void *)0)) {
     weprintf("invalid option (2) %s\n", optstring);
     return(-1);
 }
 switch (toupper((unsigned char)optstring[1])) {
     case 'B':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring);
      return(-1);
  }
         popt->bezier=(int) fabs(optval);
  break;
     case 'F':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("fontsize must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->font_size = optval;
  break;
     case 'H':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("height must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->height = optval;
  break;
     case 'J':
  if (strncasecmp(optstring+2,"SW",2) == 0) {
      popt->justification = 0;
  } else if (strncasecmp(optstring+2,"SE",2) == 0) {
      popt->justification = 2;
  } else if (strncasecmp(optstring+2,"NE",2) == 0) {
      popt->justification = 8;
  } else if (strncasecmp(optstring+2,"NW",2) == 0) {
      popt->justification = 6;
  } else if (strncasecmp(optstring+2,"S" ,1) == 0) {
      popt->justification = 1;
  } else if (strncasecmp(optstring+2,"W" ,1) == 0) {
      popt->justification = 3;
  } else if (strncasecmp(optstring+2,"C" ,1) == 0) {
      popt->justification = 4;
  } else if (strncasecmp(optstring+2,"E" ,1) == 0) {
      popt->justification = 5;
  } else if (strncasecmp(optstring+2,"N" ,1) == 0) {
      popt->justification = 7;
  } else {
      if(sscanf(optstring+2, "%lf", &optval) != 1) {
   weprintf("invalid option argument: %s\n", optstring+2);
   return(-1);
      }
      if (optval < 0.0 || optval > 8.0 ) {
           weprintf("justification must be between 0 and 8: %s\n", optstring+2);
           return(-1);
      }
      popt->justification = (int) optval;
  }
  break;
     case 'M':
  if (strncasecmp(optstring+1,"MXY",3) == 0) {
      popt->mirror = 3;
  } else if (strncasecmp(optstring+1,"MY",2) == 0) {
      popt->mirror = 2;
  } else if (strncasecmp(optstring+1,"MX",2) == 0) {
      popt->mirror = 1;
  } else if (strncasecmp(optstring+1,"M0",2) == 0) {
      popt->mirror = 0;
  } else if (strncasecmp(optstring+1,"MOFF",4) == 0) {
      popt->mirror = 0;
  } else {
      weprintf("unknown mirror option %s\n", optstring);
      return(-1);
  }
  break;
     case 'N':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  i = (int) optval;
  if (i <-2 || i >= 100) {
      weprintf("font_num must between 0 and 100: %s\n", optstring+2);
      return(-1);
  }
  popt->font_num = i;
  break;
     case 'R':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval <= -370.0 || optval >= 370.0 ) {
      weprintf("option out of range: %s\n", optstring+2);
      return(-1);
  }
  popt->rotation = optval;
  break;
     case 'S':
  if(sscanf(optstring+2, "%lf,%lf", &optval, &optval2) != 2) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  popt->cols = (int) optval;
  popt->rows = (int) optval2;
  popt->stepflag = 1;
  break;
     case 'W':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("width must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->width = optval;
  break;
     case 'X':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.0 ) {
      weprintf("scale must be positive: %s\n", optstring+2);
      return(-1);
  }
  popt->scale = optval;
  break;
     case 'Y':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < 0.01 || optval > 100.0 ) {
      weprintf("out of range (0.01 < Y < 100.0): %s\n", optstring+2);
      return(-1);
  }
  popt->aspect_ratio = optval;
  break;
     case 'Z':
  if(sscanf(optstring+2, "%lf", &optval) != 1) {
      weprintf("invalid option argument: %s\n", optstring+2);
      return(-1);
  }
  if (optval < -45.0 || optval > 45.0 ) {
      weprintf("out of range (+/-45 degrees): %s\n", optstring+2);
      return(-1);
  }
  popt->slant = optval;
  break;
     default:
  weprintf("unknown option ignored: %s\n", optstring);
  return(-1);
  break;
 }
    } else {
 weprintf("unknown option ignored: %s\n", optstring);
    }
    return(1);
}

variable_types:
optstring
char *

variable_types:
validopts
char *

variable_types: 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; } *

variable_types: optval double

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall draw_mbox(int a1, double a2, double a3)
{
__int64 v4; // xmm1_8
__int64 v5; // xmm3_8
__int64 v6; // xmm2_8
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

v8[8] = 0;
*(double *)&v4 = a3 + *(double *)&ymin - *(double *)&y3;
*(double *)&v5 = a3 + *(double *)&ymax - *(double *)&y3;
*(double *)&v6 = a2 + *(double *)&xmax - *(double *)&x3;
yy1_10 = v4;
*(double *)&xx1_11 = *(double *)&xmin + a2 - *(double *)&x3;
xx2_9 = v6;
yy2_8 = v5;
if ( a1 )
{
v5 = y2old_7;
v6 = x2old_6;
v4 = y1old_5;
db_drawbounds(1LL, *(double *)&x1old_4);
if ( a1 > 0 )
{
v5 = yy2_8;
v6 = xx2_9;
v4 = yy1_10;
db_drawbounds(1LL, *(double *)&xx1_11);
}
}
else
{
db_drawbounds(1LL, *(double *)&xmin + a2 - *(double *)&x3);
}
x1old_4 = xx1_11;
y1old_5 = yy1_10;
x2old_6 = xx2_9;
y2old_7 = yy2_8;
return jump(v8, 1LL, *(double *)&yy2_8, *(double *)&v4, *(double *)&v6, *(double *)&v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3)
{
__int64 v4; // xmm1_8
__int64 v5; // xmm3_8
__int64 v6; // xmm2_8
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

v8[8] = 0;
*(double *)&v4 = a3 + *(double *)&ymin - *(double *)&y3;
*(double *)&v5 = a3 + *(double *)&ymax - *(double *)&y3;
*(double *)&v6 = a2 + *(double *)&xmax - *(double *)&x3;
yy1_10 = v4;
*(double *)&xx1_11 = *(double *)&xmin + a2 - *(double *)&x3;
xx2_9 = v6;
yy2_8 = v5;
if ( a1 )
{
v5 = y2old_7;
v6 = x2old_6;
v4 = y1old_5;
db_drawbounds(1LL, *(double *)&x1old_4);
if ( a1 > 0 )
{
v5 = yy2_8;
v6 = xx2_9;
v4 = yy1_10;
db_drawbounds(1LL, *(double *)&xx1_11);
}
}
else
{
db_drawbounds(1LL, *(double *)&xmin + a2 - *(double *)&x3);
}
x1old_4 = xx1_11;
y1old_5 = yy1_10;
x2old_6 = xx2_9;
y2old_7 = yy2_8;
return jump(v8, 1LL, *(double *)&yy2_8, *(double *)&v4, *(double *)&v6, *(double *)&v5);
}

original_code:
void draw_mbox(double x, double y, int count)
{
 static double x1old, x2old, y1old, y2old;
 static double xx1, yy1, xx2, yy2;
 BOUNDS bb;
 bb.init=0;
 xx1=xmin+x-x3;
 yy1=ymin+y-y3;
 xx2=xmax+x-x3;
 yy2=ymax+y-y3;
 if (count == 0) {
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else if (count > 0) {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
 }
 x1old=xx1;
 y1old=yy1;
 x2old=xx2;
 y2old=yy2;
 jump(&bb, 1);
}

canonical_original_code:
void draw_mbox(double x, double y, int count)
{
 static double x1old; static double x2old; static double y1old; static double y2old;
 static double xx1; static double yy1; static double xx2; static double yy2;
 struct bounds bb;
 bb.init=0;
 xx1=xmin+x-x3;
 yy1=ymin+y-y3;
 xx2=xmax+x-x3;
 yy2=ymax+y-y3;
 if (count == 0) {
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else if (count > 0) {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
 }
 x1old=xx1;
 y1old=yy1;
 x2old=xx2;
 y2old=yy2;
 jump(&bb, 1);
}

variable_types: x double

variable_types: y double

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


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

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

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

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

original_code:
void move_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,y1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,y1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=y1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}

canonical_original_code:
void move_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,y1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,y1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=y1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}


grid

decompiled_code:
double __fastcall grid(double a1)
{
return (double)(int)(a1 * 100000.0 + 0.5) / 100000.0;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return (double)(int)(a1 * 100000.0 + 0.5) / 100000.0;
}

original_code:
double grid(double num) {
   return ((double)((int)(num*pow(10.0,5)+0.5)))/pow(10.0,5);
}

variable_types: num double

return_type: double


decompiled_code:
__int64 __fastcall draw_dist(int a1, double a2, double a3)
{
double v3; // xmm6_8
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // rbp
__int64 v7; // xmm4_8
double v8; // xmm2_8
double v9; // xmm2_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm4_8
double v13; // xmm5_8
char v14; // dl
double v15; // xmm1_8
char v16; // dl
double v17; // xmm1_8
double v18; // xmm0_8
double v19; // xmm4_8
double v20; // xmm5_8
double v21; // xmm0_8
double v22; // xmm4_8
double v23; // xmm5_8
double v27; // [rsp+10h] [rbp-58h]
double v28; // [rsp+18h] [rbp-50h]
char v29[32]; // [rsp+20h] [rbp-48h] BYREF
int v30; // [rsp+40h] [rbp-28h]

v3 = a3;
dxbuf_9 = 0;
v30 = 0;
dybuf_8 = 0;
v4 = *(double *)&x1 - a2;
dxybuf_7 = 0;
v5 = v4 * v4;
v6 = grid(COERCE_DOUBLE(*(_QWORD *)&v4 & LC6));
v8 = (*(double *)&yy1 - a3) * (*(double *)&yy1 - a3);
grid(COERCE_DOUBLE(v7 & COERCE_UNSIGNED_INT64(*(double *)&yy1 - a3)));
v9 = v8 + v5;
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
v11 = grid(v10);
v13 = v6;
v14 = 1;
v15 = v11;
if ( v6 != 0.0 )
{
if ( v6 == v11 )
v14 = 0;
if ( v14 )
{
v28 = v11;
v11 = v6;
v27 = v12;
snprintf(&dxbuf_9, 0x14uLL, "%g", v6);
v15 = v28;
v12 = v27;
}
}
v16 = 1;
if ( v12 != 0.0 )
{
if ( v12 == v15 )
v16 = 0;
if ( v16 )
{
v11 = v12;
snprintf(&dybuf_8, 0x14uLL, "%g", v12);
}
}
if ( v15 != 0.0 )
{
v11 = v15;
snprintf(&dxybuf_7, 0x14uLL, "%g", v15);
}
if ( a1 )
{
jump(v29, 1LL, v11, v15, v9, 0.0, v12, v13, v3);
draw(v29, 1LL, *(double *)&x1old_5, *(double *)&y1old_6);
draw(v29, 1LL, *(double *)&x2old_3, *(double *)&y2old_4);
draw(v29, 1LL, *(double *)&x2old_3, *(double *)&y1old_6);
draw(v29, 1LL, *(double *)&x1old_5, *(double *)&y1old_6);
xwin_draw_point(*(double *)&x1old_5, *(double *)&y1old_6);
xwin_draw_point(*(double *)&x2old_3, *(double *)&y2old_4);
xwin_draw_text(
dybufold_2,
*(double *)&x2old_3,
(*(double *)&y2old_4 + *(double *)&y2old_4 + *(double *)&y1old_6) / 3.0);
xwin_draw_text(dxbufold_1, (*(double *)&x1old_5 + *(double *)&x2old_3) * 0.5, *(double *)&y1old_6);
v17 = (*(double *)&y1old_6 + *(double *)&y1old_6 + *(double *)&y2old_4) / 3.0;
if ( a1 <= 0 )
{
xwin_draw_text(dxybufold_0, (*(double *)&x1old_5 + *(double *)&x1old_5 + *(double *)&x2old_3) / 3.0, v17);
}
else
{
v18 = (*(double *)&x1old_5 + *(double *)&x1old_5 + *(double *)&x2old_3) / 3.0;
xwin_draw_text(dxybufold_0, v18, v17);
jump(v29, 1LL, v18, v17, v9, 0.0, v19, v20, v3);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
draw(v29, 1LL, a2, a3);
draw(v29, 1LL, a2, *(double *)&yy1);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
xwin_draw_text(&dybuf_8, a2, (a3 + a3 + *(double *)&yy1) / 3.0);
xwin_draw_text(&dxbuf_9, (a2 + *(double *)&x1) * 0.5, *(double *)&yy1);
xwin_draw_text(
&dxybuf_7,
(*(double *)&x1 + *(double *)&x1 + a2) / 3.0,
(*(double *)&yy1 + *(double *)&yy1 + a3) / 3.0);
xwin_draw_point(*(double *)&x1, *(double *)&yy1);
v17 = a3;
xwin_draw_point(a2, a3);
}
}
else
{
jump(v29, 1LL, v11, v15, v9, 0.0, v12, v13, v3);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
draw(v29, 1LL, a2, a3);
draw(v29, 1LL, a2, *(double *)&yy1);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
xwin_draw_point(*(double *)&x1, *(double *)&yy1);
xwin_draw_point(a2, a3);
xwin_draw_text(&dybuf_8, a2, (a3 + a3 + *(double *)&yy1) / 3.0);
xwin_draw_text(&dxbuf_9, (a2 + *(double *)&x1) * 0.5, *(double *)&yy1);
v17 = (*(double *)&yy1 + *(double *)&yy1 + a3) / 3.0;
xwin_draw_text(&dxybuf_7, (*(double *)&x1 + *(double *)&x1 + a2) / 3.0, v17);
}
x2old_3 = *(_QWORD *)&a2;
x1old_5 = x1;
v21 = *(double *)&yy1;
y2old_4 = *(_QWORD *)&a3;
y1old_6 = yy1;
strncpy(dxbufold_1, &dxbuf_9, 0x14uLL);
strncpy(dybufold_2, &dybuf_8, 0x14uLL);
strncpy(dxybufold_0, &dxybuf_7, 0x14uLL);
return jump(v29, 1LL, v21, v17, v9, 0.0, v22, v23, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, double a2, double a3)
{
double v3; // xmm6_8
double v4; // xmm0_8
double v5; // xmm3_8
double v6; // rbp
__int64 v7; // xmm4_8
double v8; // xmm2_8
double v9; // xmm2_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm4_8
double v13; // xmm5_8
char v14; // dl
double v15; // xmm1_8
char v16; // dl
double v17; // xmm1_8
double v18; // xmm0_8
double v19; // xmm4_8
double v20; // xmm5_8
double v21; // xmm0_8
double v22; // xmm4_8
double v23; // xmm5_8
double v27; // [rsp+10h] [rbp-58h]
double v28; // [rsp+18h] [rbp-50h]
char v29[32]; // [rsp+20h] [rbp-48h] BYREF
int v30; // [rsp+40h] [rbp-28h]

v3 = a3;
dxbuf_9 = 0;
v30 = 0;
dybuf_8 = 0;
v4 = *(double *)&x1 - a2;
dxybuf_7 = 0;
v5 = v4 * v4;
v6 = func1(COERCE_DOUBLE(*(_QWORD *)&v4 & LC6));
v8 = (*(double *)&yy1 - a3) * (*(double *)&yy1 - a3);
func1(COERCE_DOUBLE(v7 & COERCE_UNSIGNED_INT64(*(double *)&yy1 - a3)));
v9 = v8 + v5;
if ( v9 < 0.0 )
v10 = sqrt(v9);
else
v10 = sqrt(v9);
v11 = func1(v10);
v13 = v6;
v14 = 1;
v15 = v11;
if ( v6 != 0.0 )
{
if ( v6 == v11 )
v14 = 0;
if ( v14 )
{
v28 = v11;
v11 = v6;
v27 = v12;
snprintf(&dxbuf_9, 0x14uLL, "%g", v6);
v15 = v28;
v12 = v27;
}
}
v16 = 1;
if ( v12 != 0.0 )
{
if ( v12 == v15 )
v16 = 0;
if ( v16 )
{
v11 = v12;
snprintf(&dybuf_8, 0x14uLL, "%g", v12);
}
}
if ( v15 != 0.0 )
{
v11 = v15;
snprintf(&dxybuf_7, 0x14uLL, "%g", v15);
}
if ( a1 )
{
jump(v29, 1LL, v11, v15, v9, 0.0, v12, v13, v3);
draw(v29, 1LL, *(double *)&x1old_5, *(double *)&y1old_6);
draw(v29, 1LL, *(double *)&x2old_3, *(double *)&y2old_4);
draw(v29, 1LL, *(double *)&x2old_3, *(double *)&y1old_6);
draw(v29, 1LL, *(double *)&x1old_5, *(double *)&y1old_6);
xwin_draw_point(*(double *)&x1old_5, *(double *)&y1old_6);
xwin_draw_point(*(double *)&x2old_3, *(double *)&y2old_4);
xwin_draw_text(
dybufold_2,
*(double *)&x2old_3,
(*(double *)&y2old_4 + *(double *)&y2old_4 + *(double *)&y1old_6) / 3.0);
xwin_draw_text(dxbufold_1, (*(double *)&x1old_5 + *(double *)&x2old_3) * 0.5, *(double *)&y1old_6);
v17 = (*(double *)&y1old_6 + *(double *)&y1old_6 + *(double *)&y2old_4) / 3.0;
if ( a1 <= 0 )
{
xwin_draw_text(dxybufold_0, (*(double *)&x1old_5 + *(double *)&x1old_5 + *(double *)&x2old_3) / 3.0, v17);
}
else
{
v18 = (*(double *)&x1old_5 + *(double *)&x1old_5 + *(double *)&x2old_3) / 3.0;
xwin_draw_text(dxybufold_0, v18, v17);
jump(v29, 1LL, v18, v17, v9, 0.0, v19, v20, v3);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
draw(v29, 1LL, a2, a3);
draw(v29, 1LL, a2, *(double *)&yy1);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
xwin_draw_text(&dybuf_8, a2, (a3 + a3 + *(double *)&yy1) / 3.0);
xwin_draw_text(&dxbuf_9, (a2 + *(double *)&x1) * 0.5, *(double *)&yy1);
xwin_draw_text(
&dxybuf_7,
(*(double *)&x1 + *(double *)&x1 + a2) / 3.0,
(*(double *)&yy1 + *(double *)&yy1 + a3) / 3.0);
xwin_draw_point(*(double *)&x1, *(double *)&yy1);
v17 = a3;
xwin_draw_point(a2, a3);
}
}
else
{
jump(v29, 1LL, v11, v15, v9, 0.0, v12, v13, v3);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
draw(v29, 1LL, a2, a3);
draw(v29, 1LL, a2, *(double *)&yy1);
draw(v29, 1LL, *(double *)&x1, *(double *)&yy1);
xwin_draw_point(*(double *)&x1, *(double *)&yy1);
xwin_draw_point(a2, a3);
xwin_draw_text(&dybuf_8, a2, (a3 + a3 + *(double *)&yy1) / 3.0);
xwin_draw_text(&dxbuf_9, (a2 + *(double *)&x1) * 0.5, *(double *)&yy1);
v17 = (*(double *)&yy1 + *(double *)&yy1 + a3) / 3.0;
xwin_draw_text(&dxybuf_7, (*(double *)&x1 + *(double *)&x1 + a2) / 3.0, v17);
}
x2old_3 = *(_QWORD *)&a2;
x1old_5 = x1;
v21 = *(double *)&yy1;
y2old_4 = *(_QWORD *)&a3;
y1old_6 = yy1;
strncpy(dxbufold_1, &dxbuf_9, 0x14uLL);
strncpy(dybufold_2, &dybuf_8, 0x14uLL);
strncpy(dxybufold_0, &dxybuf_7, 0x14uLL);
return jump(v29, 1LL, v21, v17, v9, 0.0, v22, v23, a3);
}

original_code:
void draw_dist(double x2, double y2, int count)
{
 static double x1old, x2old, y1old, y2old;
 static char dxbuf[20];
 static char dybuf[20];
 static char dxybuf[20];
 static char dxbufold[20];
 static char dybufold[20];
 static char dxybufold[20];
 double dxval,dyval,dxyval;
 BOUNDS bb;
 bb.init=0;
        dxbuf[0]='\0';
        dybuf[0]='\0';
        dxybuf[0]='\0';
        dxval=grid(fabs(x1-x2));
 dyval=grid(fabs(yy1-y2));
 dxyval=grid(sqrt(pow((x1-x2),2.0)+pow((yy1-y2),2.0)));
 if (dxval!=0.0 && dxval != dxyval) {
     snprintf(dxbuf, 20, "%g", dxval);
 }
 if (dyval!=0 && dyval != dxyval) {
     snprintf(dybuf, 20, "%g", dyval);
 }
 if (dxyval!=0) {
     snprintf(dxybuf, 20, "%g", dxyval);
 }
 if (count == 0) {
     jump(&bb, 1);
     draw(x1,yy1, &bb, 1);
     draw(x2,y2, &bb, 1);
     draw(x2,yy1, &bb, 1);
     draw(x1,yy1, &bb, 1);
     xwin_draw_point(x1, yy1);
     xwin_draw_point(x2, y2);
     xwin_draw_text(x2, (yy1+2.0*y2)/3.0, dybuf);
     xwin_draw_text((x1+x2)/2.0, yy1, dxbuf);
     xwin_draw_text((2.0*x1+x2)/3.0, (2.0*yy1+y2)/3.0, dxybuf);
 } else if (count > 0) {
     jump(&bb, 1);
     draw(x1old,y1old, &bb, 1);
     draw(x2old,y2old, &bb, 1);
     draw(x2old,y1old, &bb, 1);
     draw(x1old,y1old, &bb, 1);
     xwin_draw_point(x1old, y1old);
     xwin_draw_point(x2old, y2old);
     xwin_draw_text(x2old, (y1old+2.0*y2old)/3.0, dybufold);
     xwin_draw_text((x1old+x2old)/2.0, y1old, dxbufold);
     xwin_draw_text((2.0*x1old+x2old)/3.0, (2.0*y1old+y2old)/3.0, dxybufold);
     jump(&bb, 1);
     draw(x1,yy1, &bb, 1);
     draw(x2,y2, &bb, 1);
     draw(x2,yy1, &bb, 1);
     draw(x1,yy1, &bb, 1);
     xwin_draw_text(x2, (yy1+2.0*y2)/3.0, dybuf);
     xwin_draw_text((x1+x2)/2.0, yy1, dxbuf);
     xwin_draw_text((2.0*x1+x2)/3.0, (2.0*yy1+y2)/3.0, dxybuf);
     xwin_draw_point(x1, yy1);
     xwin_draw_point(x2, y2);
 } else {
     jump(&bb, 1);
     draw(x1old,y1old, &bb, 1);
     draw(x2old,y2old, &bb, 1);
     draw(x2old,y1old, &bb, 1);
     draw(x1old,y1old, &bb, 1);
     xwin_draw_point(x1old, y1old);
     xwin_draw_point(x2old, y2old);
     xwin_draw_text(x2old, (y1old+2.0*y2old)/3.0, dybufold);
     xwin_draw_text((x1old+x2old)/2.0, y1old, dxbufold);
     xwin_draw_text((2.0*x1old+x2old)/3.0, (2.0*y1old+y2old)/3.0, dxybufold);
 }
 x1old=x1;
 y1old=yy1;
 x2old=x2;
 y2old=y2;
 strncpy(dxbufold, dxbuf, 20);
 strncpy(dybufold, dybuf, 20);
 strncpy(dxybufold, dxybuf, 20);
 jump(&bb, 1);
}

canonical_original_code:
void draw_dist(double x2, double y2, int count)
{
 static double x1old; static double x2old; static double y1old; static double y2old;
 static char dxbuf[20];
 static char dybuf[20];
 static char dxybuf[20];
 static char dxbufold[20];
 static char dybufold[20];
 static char dxybufold[20];
 double dxval; double dyval; double dxyval;
 struct bounds bb;
 bb.init=0;
        dxbuf[0]='\0';
        dybuf[0]='\0';
        dxybuf[0]='\0';
        dxval=grid(fabs(x1-x2));
 dyval=grid(fabs(yy1-y2));
 dxyval=grid(sqrt(pow((x1-x2),2.0)+pow((yy1-y2),2.0)));
 if (dxval!=0.0 && dxval != dxyval) {
     snprintf(dxbuf, 20, "%g", dxval);
 }
 if (dyval!=0 && dyval != dxyval) {
     snprintf(dybuf, 20, "%g", dyval);
 }
 if (dxyval!=0) {
     snprintf(dxybuf, 20, "%g", dxyval);
 }
 if (count == 0) {
     jump(&bb, 1);
     draw(x1,yy1, &bb, 1);
     draw(x2,y2, &bb, 1);
     draw(x2,yy1, &bb, 1);
     draw(x1,yy1, &bb, 1);
     xwin_draw_point(x1, yy1);
     xwin_draw_point(x2, y2);
     xwin_draw_text(x2, (yy1+2.0*y2)/3.0, dybuf);
     xwin_draw_text((x1+x2)/2.0, yy1, dxbuf);
     xwin_draw_text((2.0*x1+x2)/3.0, (2.0*yy1+y2)/3.0, dxybuf);
 } else if (count > 0) {
     jump(&bb, 1);
     draw(x1old,y1old, &bb, 1);
     draw(x2old,y2old, &bb, 1);
     draw(x2old,y1old, &bb, 1);
     draw(x1old,y1old, &bb, 1);
     xwin_draw_point(x1old, y1old);
     xwin_draw_point(x2old, y2old);
     xwin_draw_text(x2old, (y1old+2.0*y2old)/3.0, dybufold);
     xwin_draw_text((x1old+x2old)/2.0, y1old, dxbufold);
     xwin_draw_text((2.0*x1old+x2old)/3.0, (2.0*y1old+y2old)/3.0, dxybufold);
     jump(&bb, 1);
     draw(x1,yy1, &bb, 1);
     draw(x2,y2, &bb, 1);
     draw(x2,yy1, &bb, 1);
     draw(x1,yy1, &bb, 1);
     xwin_draw_text(x2, (yy1+2.0*y2)/3.0, dybuf);
     xwin_draw_text((x1+x2)/2.0, yy1, dxbuf);
     xwin_draw_text((2.0*x1+x2)/3.0, (2.0*yy1+y2)/3.0, dxybuf);
     xwin_draw_point(x1, yy1);
     xwin_draw_point(x2, y2);
 } else {
     jump(&bb, 1);
     draw(x1old,y1old, &bb, 1);
     draw(x2old,y2old, &bb, 1);
     draw(x2old,y1old, &bb, 1);
     draw(x1old,y1old, &bb, 1);
     xwin_draw_point(x1old, y1old);
     xwin_draw_point(x2old, y2old);
     xwin_draw_text(x2old, (y1old+2.0*y2old)/3.0, dybufold);
     xwin_draw_text((x1old+x2old)/2.0, y1old, dxbufold);
     xwin_draw_text((2.0*x1old+x2old)/3.0, (2.0*y1old+y2old)/3.0, dxybufold);
 }
 x1old=x1;
 y1old=yy1;
 x2old=x2;
 y2old=y2;
 strncpy(dxbufold, dxbuf, 20);
 strncpy(dybufold, dybuf, 20);
 strncpy(dxybufold, dxybuf, 20);
 jump(&bb, 1);
}

variable_types:
dxbuf
char [20]

variable_types:
dybuf
char [20]

variable_types:
dxybuf
char [20]

variable_types:
dxbufold
char [20]

variable_types:
dybufold
char [20]

variable_types:
dxybufold
char [20]

variable_types: dxval double

variable_types: dyval double

variable_types: dxyval double


decompiled_code:
__int64 __fastcall draw_circle(int a1, double a2, double a3)
{
__int64 v3; // xmm2_8
__int64 v4; // xmm2_8
char v6[32]; // [rsp+10h] [rbp-38h] BYREF
int v7; // [rsp+30h] [rbp-18h]

v3 = x1;
dbtab[541] = (__int64)&dbdeflist;
*((_QWORD *)&dbcirc + 2) = v3;
v4 = y1;
v7 = 0;
dbtab[547] = 0LL;
dbtab[0] = (__int64)"callback";
*((_QWORD *)&dbdeflist + 1) = &dbcirc;
dbdeflist = 4;
dbcirc = 1;
*((_QWORD *)&dbcirc + 1) = &opts;
*((_QWORD *)&dbcirc + 3) = v4;
if ( a1 )
{
if ( a1 <= 0 )
{
jump(v6, 1LL);
goto LABEL_5;
}
jump(v6, 1LL);
do_circ(&dbdeflist, v6, 1LL);
}
jump(v6, 1LL);
*((double *)&dbcirc + 4) = a2;
*((double *)&dbcirc + 5) = a3;
LABEL_5:
do_circ(&dbdeflist, v6, 1LL);
return jump(v6, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3)
{
__int64 v3; // xmm2_8
__int64 v4; // xmm2_8
char v6[32]; // [rsp+10h] [rbp-38h] BYREF
int v7; // [rsp+30h] [rbp-18h]

v3 = x1;
dbtab[541] = (__int64)&dbdeflist;
*((_QWORD *)&dbcirc + 2) = v3;
v4 = y1;
v7 = 0;
dbtab[547] = 0LL;
dbtab[0] = (__int64)"callback";
*((_QWORD *)&dbdeflist + 1) = &dbcirc;
dbdeflist = 4;
dbcirc = 1;
*((_QWORD *)&dbcirc + 1) = &opts;
*((_QWORD *)&dbcirc + 3) = v4;
if ( a1 )
{
if ( a1 <= 0 )
{
jump(v6, 1LL);
goto LABEL_5;
}
jump(v6, 1LL);
do_circ(&dbdeflist, v6, 1LL);
}
jump(v6, 1LL);
*((double *)&dbcirc + 4) = a2;
*((double *)&dbcirc + 5) = a3;
LABEL_5:
do_circ(&dbdeflist, v6, 1LL);
return jump(v6, 1LL);
}

original_code:
void draw_circle(double x2, double y2, int count)
{
 int debug=0;
 BOUNDS bb;
 bb.init=0;
        dbtab.dbhead = &dbdeflist;
        dbtab.next = ((void *)0);
 dbtab.name = "callback";
        dbdeflist.u.c = &dbcirc;
        dbdeflist.type = 4;
        dbcirc.layer=1;
        dbcirc.x1 = x1; dbcirc.y1 = y1;
        dbcirc.opts = &opts;
 if (debug) {printf("in draw_circle\n");}
 if (count == 0) {
     jump(&bb, 1);
     dbcirc.x2 = x2; dbcirc.y2 = y2;
     do_circ(&dbdeflist, &bb, 1);
 } else if (count > 0) {
     jump(&bb, 1);
     do_circ(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     dbcirc.x2 = x2; dbcirc.y2 = y2;
     do_circ(&dbdeflist, &bb, 1);
 } else {
     jump(&bb, 1);
     do_circ(&dbdeflist, &bb, 1);
 }
 jump(&bb, 1);
}

canonical_original_code:
void draw_circle(double x2, double y2, int count)
{
 int debug = 0;
 struct bounds bb;
 bb.init=0;
        dbtab.dbhead = &dbdeflist;
        dbtab.next = ((void *)0);
 dbtab.name = "callback";
        dbdeflist.u.c = &dbcirc;
        dbdeflist.type = 4;
        dbcirc.layer=1;
        dbcirc.x1 = x1; dbcirc.y1 = y1;
        dbcirc.opts = &opts;
 if (debug) {printf("in draw_circle\n");}
 if (count == 0) {
     jump(&bb, 1);
     dbcirc.x2 = x2; dbcirc.y2 = y2;
     do_circ(&dbdeflist, &bb, 1);
 } else if (count > 0) {
     jump(&bb, 1);
     do_circ(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     dbcirc.x2 = x2; dbcirc.y2 = y2;
     do_circ(&dbdeflist, &bb, 1);
 } else {
     jump(&bb, 1);
     do_circ(&dbdeflist, &bb, 1);
 }
 jump(&bb, 1);
}

variable_types: count int

variable_types: debug int

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


decompiled_code:
void __fastcall rubber_set_callback(__int64 a1)
{
count = 0;
rubber_callback = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
count = 0;
rubber_callback = a1;
}

original_code:
void rubber_set_callback(Function *func)
{
    count=0;
    rubber_callback = func;
}

canonical_original_code:
void rubber_set_callback(int (*func)())
{
    count=0;
    rubber_callback = func;
}

variable_types:
func
int (*)()


decompiled_code:
__int64 __fastcall rubber_draw(int a1, double a2)
{
__int64 result; // rax

if ( a1 )
count = 0;
if ( rubber_callback )
{
result = rubber_callback((unsigned int)count, a2);
++count;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, double a2)
{
__int64 result; // rax

if ( a1 )
count = 0;
if ( rubber_callback )
{
result = rubber_callback((unsigned int)count, a2);
++count;
}
return result;
}

original_code:
void rubber_draw(double x,double y, int init)
{
    if (init) count=0;
    int debug=0;
    if (rubber_callback != ((void *)0)) {
 if (debug) printf("rubber_draw: drawing: %g %g %d\n", x,y, count);
 (*(rubber_callback)) (x, y, count);
 count++;
    }
}

canonical_original_code:
void rubber_draw(double x, double y, int init)
{
    if (init) count=0;
    int debug = 0;
    if (rubber_callback != ((void *)0)) {
 if (debug) printf("rubber_draw: drawing: %g %g %d\n", x,y, count);
 (*(rubber_callback)) (x, y, count);
 count++;
    }
}

variable_types: init int


home

decompiled_code:
char *__fastcall home(const char *a1)
{
__uid_t v1; // eax
char *result; // rax
struct passwd *v3; // rdx

if ( a1 && *a1 )
{
v3 = getpwnam(a1);
result = (char *)a1;
if ( v3 )
result = v3->pw_dir;
}
else
{
v1 = getuid();
result = getpwuid(v1)->pw_dir;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
__uid_t v1; // eax
char *result; // rax
struct passwd *v3; // rdx

if ( a1 && *a1 )
{
v3 = getpwnam(a1);
result = (char *)a1;
if ( v3 )
result = v3->pw_dir;
}
else
{
v1 = getuid();
result = getpwuid(v1)->pw_dir;
}
return result;
}

original_code:
char *home(char *name) {
    struct passwd *p;
    if (name == ((void *)0) || strlen(name) == 0) {
 return(getpwuid(getuid())->pw_dir);
    } else {
 if((p=getpwnam(name))==((void *)0)) {
     return(name);
 } else {
     return(p->pw_dir);
 }
    }
}

variable_types:
name
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

return_type: char *


findfile

decompiled_code:
__int64 __fastcall findfile(char *src, char *a2, char *dest, int type)
{
unsigned int v6; // er13
char *v9; // rsi
char *v10; // rax
signed __int64 v11; // rdx
int v12; // eax
char *v13; // rax
char *v14; // rax
char *v15; // rax
char v16[1024]; // [rsp+0h] [rbp-1428h] BYREF
char srca[1024]; // [rsp+400h] [rbp-1028h] BYREF
char s[1024]; // [rsp+800h] [rbp-C28h] BYREF
char v19[1024]; // [rsp+C00h] [rbp-828h] BYREF
char desta[1064]; // [rsp+1000h] [rbp-428h] BYREF

if ( !a2 || !*a2 || (strcpy(v16, src), (v9 = strtok(v16, ":")) == 0LL) )
{
LABEL_3:
v6 = 0;
if ( dest )
*dest = 0;
return v6;
}
while ( 1 )
{
v10 = stpcpy(srca, v9);
if ( !srca[0] )
{
LABEL_8:
strcpy(desta, srca);
goto LABEL_9;
}
*(_WORD *)v10 = 47;
v11 = v10 - srca;
if ( srca[0] == 126 )
{
v12 = v11 + 2;
if ( (unsigned int)(v11 + 2) >= 8 )
{
*(_QWORD *)&s[v12 - 8] = *(_QWORD *)&srca[v12 - 8];
qmemcpy(s, srca, 8LL * ((unsigned int)(v11 + 1) >> 3));
}
else if ( (v12 & 4) != 0 )
{
*(_DWORD *)s = *(_DWORD *)srca;
*(_DWORD *)&s[v12 - 4] = *(_DWORD *)&srca[v12 - 4];
}
else if ( (_DWORD)v11 != -2 )
{
s[0] = srca[0];
if ( (v12 & 2) != 0 )
*(_WORD *)&s[v12 - 2] = *(_WORD *)&srca[v12 - 2];
}
v13 = strchr(s, 47);
if ( v13 )
{
*v13 = 0;
strcpy(v19, v13 + 1);
}
v14 = home(&s[1]);
v15 = stpcpy(desta, v14);
*v15 = 47;
strcpy(v15 + 1, v19);
}
else
{
if ( srca[0] != 46 || srca[1] != 47 )
goto LABEL_8;
getcwd(desta, 0x80uLL);
strcat(desta, &srca[1]);
}
LABEL_9:
strcat(desta, a2);
if ( !access(desta, type) )
break;
v9 = strtok(0LL, ":");
if ( !v9 )
goto LABEL_3;
}
v6 = 1;
if ( dest )
strcpy(dest, desta);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *a2, char *dest, int type)
{
unsigned int v6; // er13
char *v9; // rsi
char *v10; // rax
signed __int64 v11; // rdx
int v12; // eax
char *v13; // rax
char *v14; // rax
char *v15; // rax
char v16[1024]; // [rsp+0h] [rbp-1428h] BYREF
char srca[1024]; // [rsp+400h] [rbp-1028h] BYREF
char s[1024]; // [rsp+800h] [rbp-C28h] BYREF
char v19[1024]; // [rsp+C00h] [rbp-828h] BYREF
char desta[1064]; // [rsp+1000h] [rbp-428h] BYREF

if ( !a2 || !*a2 || (strcpy(v16, src), (v9 = strtok(v16, ":")) == 0LL) )
{
LABEL_3:
v6 = 0;
if ( dest )
*dest = 0;
return v6;
}
while ( 1 )
{
v10 = stpcpy(srca, v9);
if ( !srca[0] )
{
LABEL_8:
strcpy(desta, srca);
goto LABEL_9;
}
*(_WORD *)v10 = 47;
v11 = v10 - srca;
if ( srca[0] == 126 )
{
v12 = v11 + 2;
if ( (unsigned int)(v11 + 2) >= 8 )
{
*(_QWORD *)&s[v12 - 8] = *(_QWORD *)&srca[v12 - 8];
qmemcpy(s, srca, 8LL * ((unsigned int)(v11 + 1) >> 3));
}
else if ( (v12 & 4) != 0 )
{
*(_DWORD *)s = *(_DWORD *)srca;
*(_DWORD *)&s[v12 - 4] = *(_DWORD *)&srca[v12 - 4];
}
else if ( (_DWORD)v11 != -2 )
{
s[0] = srca[0];
if ( (v12 & 2) != 0 )
*(_WORD *)&s[v12 - 2] = *(_WORD *)&srca[v12 - 2];
}
v13 = strchr(s, 47);
if ( v13 )
{
*v13 = 0;
strcpy(v19, v13 + 1);
}
v14 = func0(&s[1]);
v15 = stpcpy(desta, v14);
*v15 = 47;
strcpy(v15 + 1, v19);
}
else
{
if ( srca[0] != 46 || srca[1] != 47 )
goto LABEL_8;
getcwd(desta, 0x80uLL);
strcat(desta, &srca[1]);
}
LABEL_9:
strcat(desta, a2);
if ( !access(desta, type) )
break;
v9 = strtok(0LL, ":");
if ( !v9 )
goto LABEL_3;
}
v6 = 1;
if ( dest )
strcpy(dest, desta);
return v6;
}

original_code:
int findfile(const char *pathlist, const char *filename, char *retbuf, int mode) {
    char path[1024];
    char buf[1024];
    char head[1024];
    char tail[1024];
    char full[1024];
    char *p, *q;
    if (filename != ((void *)0) && filename[0] != '\0') {
 strcpy(path,pathlist);
 for (p=strtok(path, ":"); p!=((void *)0); p=strtok(((void *)0), ":")) {
     strcpy(buf, p);
     if (strlen(buf) > 0) {
        strcat(buf,"/");
     }
     if (buf[0] == '~') {
  strcpy(head,buf);
  if ((q = strchr(head,'/')) != ((void *)0)) {
      *q = '\0';
      strcpy(tail,q+1);
  }
  strcpy(full,home(head+1));
  strcat(full,"/");
  strcat(full,tail);
     } else if (buf[0] == '.' && buf[1] == '/') {
  getcwd(full, 128);
  strcat(full,buf+1);
     } else {
  strcpy(full,buf);
     }
     strcat(full,filename);
     if (access(full, mode) == 0) {
  if (retbuf != ((void *)0)) {
      strcpy(retbuf, full);
  }
  return(1);
     }
 }
    }
    if (retbuf != ((void *)0)) {
 retbuf[0] = '\0';
    }
    return(0);
}

canonical_original_code:
int findfile(char *pathlist, char *filename, char *retbuf, int mode) {
    char path[1024];
    char buf[1024];
    char head[1024];
    char tail[1024];
    char full[1024];
    char *p; char *q;
    if (filename != ((void *)0) && filename[0] != '\0') {
 strcpy(path,pathlist);
 for (p=strtok(path, ":"); p!=((void *)0); p=strtok(((void *)0), ":")) {
     strcpy(buf, p);
     if (strlen(buf) > 0) {
        strcat(buf,"/");
     }
     if (buf[0] == '~') {
  strcpy(head,buf);
  if ((q = strchr(head,'/')) != ((void *)0)) {
      *q = '\0';
      strcpy(tail,q+1);
  }
  strcpy(full,home(head+1));
  strcat(full,"/");
  strcat(full,tail);
     } else if (buf[0] == '.' && buf[1] == '/') {
  getcwd(full, 128);
  strcat(full,buf+1);
     } else {
  strcpy(full,buf);
     }
     strcat(full,filename);
     if (access(full, mode) == 0) {
  if (retbuf != ((void *)0)) {
      strcpy(retbuf, full);
  }
  return(1);
     }
 }
    }
    if (retbuf != ((void *)0)) {
 retbuf[0] = '\0';
    }
    return(0);
}

variable_types:
pathlist
char *

variable_types:
filename
char *

variable_types:
retbuf
char *

variable_types: mode int

variable_types:
path
char [1024]

variable_types:
buf
char [1024]

variable_types:
head
char [1024]

variable_types:
tail
char [1024]

variable_types:
full
char [1024]

variable_types:
p
char *

variable_types:
q
char *


license

decompiled_code:
int license()
{
puts("/* --------------------------------------------------------------------");
puts(" PD_Piglet: an engineering graphical editor with hierarchy.");
puts(" Copyright (C) 2002-2020 by Richard C. Walker.");
putchar(10);
puts(" Author's email: walker AT omnisterra DOT com");
puts(" Homepage: http://www.omnisterra.com/walker/linux/piglet/intro.htm");
putchar(10);
puts(" This program is free software; you can redistribute it and/or");
puts(" modify it under the terms of the GNU General Public License,");
puts(" version 2, which you should have received in the file \"COPYING\"");
puts(" along with this program; if not, write to the Free Software");
puts(" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.");
putchar(10);
puts(" This program is distributed in the hope that it will be useful,");
puts(" but WITHOUT ANY WARRANTY; without even the implied warranty of");
puts(" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
puts("-------------------------------------------------------------------- */");
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("/* --------------------------------------------------------------------");
puts(" PD_Piglet: an engineering graphical editor with hierarchy.");
puts(" Copyright (C) 2002-2020 by Richard C. Walker.");
putchar(10);
puts(" Author's email: walker AT omnisterra DOT com");
puts(" Homepage: http://www.omnisterra.com/walker/linux/piglet/intro.htm");
putchar(10);
puts(" This program is free software; you can redistribute it and/or");
puts(" modify it under the terms of the GNU General Public License,");
puts(" version 2, which you should have received in the file \"COPYING\"");
puts(" along with this program; if not, write to the Free Software");
puts(" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.");
putchar(10);
puts(" This program is distributed in the hope that it will be useful,");
puts(" but WITHOUT ANY WARRANTY; without even the implied warranty of");
puts(" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
puts("-------------------------------------------------------------------- */");
return putchar(10);
}

original_code:
void license() {
    printf("/* --------------------------------------------------------------------\n");
    printf("    PD_Piglet: an engineering graphical editor with hierarchy.\n");
    printf("    Copyright (C) 2002-2020  by Richard C. Walker.\n");
    printf("\n");
    printf("    Author's email: walker AT omnisterra DOT com\n");
    printf("    Homepage: http://www.omnisterra.com/walker/linux/piglet/intro.htm\n");
    printf("\n");
    printf("    This program is free software; you can redistribute it and/or\n");
    printf("    modify it under the terms of the GNU General Public License,\n");
    printf("    version 2, which you should have received in the file \"COPYING\"\n");
    printf("    along with this program; if not, write to the Free Software\n");
    printf("    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n");
    printf("\n");
    printf("    This program is distributed in the hope that it will be useful,\n");
    printf("    but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
    printf("    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
    printf("-------------------------------------------------------------------- */\n");
    printf("\n");
}


decompiled_code:
__int64 __fastcall delete_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 *)&y1, v6, v5, v4, v3);
v7 = *(_QWORD *)&v10;
v8 = *(_QWORD *)&v11;
LABEL_5:
x2old_2 = v7;
y2old_3 = v8;
x1old_0 = x1;
y1old_1 = y1;
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 *)&y1, v6, v5, v4, v3);
v7 = *(_QWORD *)&v10;
v8 = *(_QWORD *)&v11;
LABEL_5:
x2old_2 = v7;
y2old_3 = v8;
x1old_0 = x1;
y1old_1 = y1;
return jump(v12, 1LL);
}

original_code:
void delete_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,y1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,y1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=y1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}

canonical_original_code:
void delete_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,y1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,y1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=y1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}

variable_types: count int


fillable

decompiled_code:
__int64 __fastcall fillable(unsigned int a1)
{
return a1;
}

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

original_code:
int fillable(int fid) {
   return(fid);
}

canonical_original_code:
int fillable(int fid) {
   return(fid);
}

variable_types: fid int


writechar

original_code:
void writechar(
    int c,
    double x,
    double y,
    XFORM *xf,
    int fid,
    BOUNDS *bb,
    int mode
) {
    int i;
    double xp,yp,xt,yt;
    int debug=0;
    if (c==' ') {
 return;
    }
    i = fonttab[fid][c];
    if (debug) fprintf(stderr, "writechar fid=%d, c=%c, font index = %d\n", fid, c, i);
    jump(bb, mode);
    if (fillable(fid)) {
 startpoly(bb,mode);
    }
    while (xdef[fid][i] != -128 || ydef[fid][i] != -128) {
 if (xdef[fid][i] != -128) {
     xp = x + (0.8 * ( (double) xdef[fid][i] / (double) dy[fid]));
     yp = y + (0.8 * ( (double) ydef[fid][i] / (double) dy[fid]));
     xt = xp*xf->r11 + yp*xf->r21 + xf->dx;
     yt = xp*xf->r12 + yp*xf->r22 + xf->dy;
     draw(xt,yt, bb, mode);
 } else {
     if (fillable(fid)) {
  endpoly(bb,mode);
     }
     jump(bb, mode);
     if (fillable(fid)) {
   startpoly(bb,mode);
     }
 }
 i++;
    }
    if (fillable(fid)) {
 endpoly(bb,mode);
    }
}

canonical_original_code:
void writechar(int c, double x, double y, struct xform *xf, int fid, struct bounds *bb, int mode) {
    int i;
    double xp; double yp; double xt; double yt;
    int debug = 0;
    if (c==' ') {
 return;
    }
    i = fonttab[fid][c];
    if (debug) fprintf(stderr, "writechar fid=%d, c=%c, font index = %d\n", fid, c, i);
    jump(bb, mode);
    if (fillable(fid)) {
 startpoly(bb,mode);
    }
    while (xdef[fid][i] != -128 || ydef[fid][i] != -128) {
 if (xdef[fid][i] != -128) {
     xp = x + (0.8 * ( (double) xdef[fid][i] / (double) dy[fid]));
     yp = y + (0.8 * ( (double) ydef[fid][i] / (double) dy[fid]));
     xt = xp*xf->r11 + yp*xf->r21 + xf->dx;
     yt = xp*xf->r12 + yp*xf->r22 + xf->dy;
     draw(xt,yt, bb, mode);
 } else {
     if (fillable(fid)) {
  endpoly(bb,mode);
     }
     jump(bb, mode);
     if (fillable(fid)) {
   startpoly(bb,mode);
     }
 }
 i++;
    }
    if (fillable(fid)) {
 endpoly(bb,mode);
    }
}

variable_types: c int

variable_types: x double

variable_types: y double

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

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

variable_types: i int

variable_types: xp double

variable_types: yp double

variable_types: xt double

variable_types: yt double

variable_types: debug int


writestring

decompiled_code:
void __fastcall writestring(char *s, double *a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6)
{
char *v6; // r14
_BOOL4 v9; // er13
double v10; // xmm0_8
int v12; // edi
double v13; // xmm2_8
double v14; // xmm3_8
double v16; // [rsp+10h] [rbp-48h]
double v17; // [rsp+18h] [rbp-40h]

v6 = s;
v9 = a3 != -1;
if ( a3 + 2 > 1 )
{
if ( (unsigned int)shp_fontexists(a3) )
{
shp_writestring(s, a2, a3, a4, a5, a6);
return;
}
fprintf(stderr, "no font loaded at position %d, defaulting to NOTE\n", a3);
}
v10 = (double)dword_4F348[v9] * 0.8 * (double)(int)strlen(s) / (double)dy[v9];
switch ( a4 )
{
case 0u:
v17 = 0.0;
v16 = 0.0;
break;
case 1u:
v17 = 0.0;
v16 = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC5) * 0.5;
break;
case 2u:
v17 = 0.0;
*(_QWORD *)&v16 = *(_QWORD *)&v10 ^ LC5;
break;
case 3u:
v17 = *(double *)&LC3;
v16 = 0.0;
break;
case 4u:
v17 = *(double *)&LC3;
v16 = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC5) * 0.5;
break;
case 5u:
*(_QWORD *)&v16 = *(_QWORD *)&v10 ^ LC5;
v17 = *(double *)&LC3;
break;
case 6u:
v17 = *(double *)&LC2;
v16 = 0.0;
break;
case 7u:
v17 = *(double *)&LC2;
v16 = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC5) * 0.5;
break;
case 8u:
*(_QWORD *)&v16 = *(_QWORD *)&v10 ^ LC5;
v17 = *(double *)&LC2;
break;
default:
printf("bad justification: %d in writestring()\n", a4);
v17 = 0.0;
v16 = 0.0;
break;
}
v12 = *s;
v13 = 0.0;
v14 = 0.0;
if ( *v6 )
{
do
{
while ( (_BYTE)v12 != 10 )
{
++v6;
writechar(v12, a2, v9, a5, a6, (double)dword_4F348[v9] * 0.8 * v13 / (double)dy[v9] + v16, v17 - v14);
v12 = *v6;
v13 = v13 + 1.0;
if ( !*v6 )
return;
}
v12 = *++v6;
v14 = v14 + 1.0;
v13 = 0.0;
}
while ( (_BYTE)v12 );
}
}

canonical_decompiled_code:
void __fastcall func2(char *s, double *a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6)
{
char *v6; // r14
_BOOL4 v9; // er13
double v10; // xmm0_8
int v12; // edi
double v13; // xmm2_8
double v14; // xmm3_8
double v16; // [rsp+10h] [rbp-48h]
double v17; // [rsp+18h] [rbp-40h]

v6 = s;
v9 = a3 != -1;
if ( a3 + 2 > 1 )
{
if ( (unsigned int)shp_fontexists(a3) )
{
shp_writestring(s, a2, a3, a4, a5, a6);
return;
}
fprintf(stderr, "no font loaded at position %d, defaulting to NOTE\n", a3);
}
v10 = (double)dword_4F348[v9] * 0.8 * (double)(int)strlen(s) / (double)dy[v9];
switch ( a4 )
{
case 0u:
v17 = 0.0;
v16 = 0.0;
break;
case 1u:
v17 = 0.0;
v16 = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC5) * 0.5;
break;
case 2u:
v17 = 0.0;
*(_QWORD *)&v16 = *(_QWORD *)&v10 ^ LC5;
break;
case 3u:
v17 = *(double *)&LC3;
v16 = 0.0;
break;
case 4u:
v17 = *(double *)&LC3;
v16 = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC5) * 0.5;
break;
case 5u:
*(_QWORD *)&v16 = *(_QWORD *)&v10 ^ LC5;
v17 = *(double *)&LC3;
break;
case 6u:
v17 = *(double *)&LC2;
v16 = 0.0;
break;
case 7u:
v17 = *(double *)&LC2;
v16 = COERCE_DOUBLE(*(_QWORD *)&v10 ^ LC5) * 0.5;
break;
case 8u:
*(_QWORD *)&v16 = *(_QWORD *)&v10 ^ LC5;
v17 = *(double *)&LC2;
break;
default:
printf("bad justification: %d in writestring()\n", a4);
v17 = 0.0;
v16 = 0.0;
break;
}
v12 = *s;
v13 = 0.0;
v14 = 0.0;
if ( *v6 )
{
do
{
while ( (_BYTE)v12 != 10 )
{
++v6;
func1(v12, a2, v9, a5, a6, (double)dword_4F348[v9] * 0.8 * v13 / (double)dy[v9] + v16, v17 - v14);
v12 = *v6;
v13 = v13 + 1.0;
if ( !*v6 )
return;
}
v12 = *++v6;
v14 = v14 + 1.0;
v13 = 0.0;
}
while ( (_BYTE)v12 );
}
}

original_code:
void writestring(
    char *s,
    XFORM *xf,
    int id,
    int jf,
    BOUNDS *bb,
    int mode
) {
    double yoffset=0.0;
    double xoffset=0.0;
    double xoff, yoff;
    int fid;
    int debug=0;
    if (id==-1) {
      fid=0;
    } else {
      fid=1;
    }
    if (debug) fprintf(stderr, "writestring %s id=%d\n",s, id);
    if (id==-1 || id ==-2) {
 if (debug) fprintf(stderr, "is legacy font\n");
    ;
    } else if (shp_fontexists(id)) {
     shp_writestring(s,xf,id,jf,bb,mode);
 return;
    } else {
 fprintf(stderr, "no font loaded at position %d, defaulting to NOTE\n", id);
 id = -1;
    }
    if (debug) printf("in writestring fid=%d\n", fid);
    double width=(((double)(dx[fid]))*0.80*strlen(s))/((double)(dy[fid]));
    double height=0.8;
    xoff = yoff = 0.0;
    switch (jf) {
        case 0:
     xoff = 0.0;
     yoff = 0.0;
     break;
        case 1:
     xoff = -width/2.0;
     yoff = 0.0;
     break;
        case 2:
     xoff = -width;
     yoff = 0.0;
     break;
        case 3:
     xoff = 0.0;
     yoff = -height/2.0;
     break;
        case 4:
     xoff = -width/2.0;
     yoff = -height/2.0;
     break;
        case 5:
     xoff = -width;
     yoff = -height/2.0;
     break;
        case 6:
     xoff = 0.0;
     yoff = -height;
     break;
        case 7:
     xoff = -width/2.0;
     yoff = -height;
     break;
        case 8:
     xoff = -width;
     yoff = -height;
     break;
 default:
     printf("bad justification: %d in writestring()\n", jf);
     break;
    }
    while(*s != 0) {
 if (*s != '\n') {
     writechar(*s,
         (((double)(dx[fid]))*0.80*xoffset)/((double)(dy[fid]))+xoff,
  -yoffset+yoff,xf,fid, bb, mode);
     if (debug) printf("writing %c, dx:%d dy:%d fid:%d\n",
      *s, dx[fid], dy[fid], fid);
     xoffset+=1.0;
 } else {
     xoffset=0.0;
     yoffset+=1.0;
 }
 ++s;
    }
}

canonical_original_code:
void writestring(char *s, struct xform *xf, int id, int jf, struct bounds *bb, int mode) {
    double yoffset = 0.0;
    double xoffset = 0.0;
    double xoff; double yoff;
    int fid;
    int debug = 0;
    if (id==-1) {
      fid=0;
    } else {
      fid=1;
    }
    if (debug) fprintf(stderr, "writestring %s id=%d\n",s, id);
    if (id==-1 || id ==-2) {
 if (debug) fprintf(stderr, "is legacy font\n");
    ;
    } else if (shp_fontexists(id)) {
     shp_writestring(s,xf,id,jf,bb,mode);
 return;
    } else {
 fprintf(stderr, "no font loaded at position %d, defaulting to NOTE\n", id);
 id = -1;
    }
    if (debug) printf("in writestring fid=%d\n", fid);
    double width = (((double)(dx[fid]))*0.80*strlen(s))/((double)(dy[fid]));
    double height = 0.8;
    xoff = yoff = 0.0;
    switch (jf) {
        case 0:
     xoff = 0.0;
     yoff = 0.0;
     break;
        case 1:
     xoff = -width/2.0;
     yoff = 0.0;
     break;
        case 2:
     xoff = -width;
     yoff = 0.0;
     break;
        case 3:
     xoff = 0.0;
     yoff = -height/2.0;
     break;
        case 4:
     xoff = -width/2.0;
     yoff = -height/2.0;
     break;
        case 5:
     xoff = -width;
     yoff = -height/2.0;
     break;
        case 6:
     xoff = 0.0;
     yoff = -height;
     break;
        case 7:
     xoff = -width/2.0;
     yoff = -height;
     break;
        case 8:
     xoff = -width;
     yoff = -height;
     break;
 default:
     printf("bad justification: %d in writestring()\n", jf);
     break;
    }
    while(*s != 0) {
 if (*s != '\n') {
     writechar(*s,
         (((double)(dx[fid]))*0.80*xoffset)/((double)(dy[fid]))+xoff,
  -yoffset+yoff,xf,fid, bb, mode);
     if (debug) printf("writing %c, dx:%d dy:%d fid:%d\n",
      *s, dx[fid], dy[fid], fid);
     xoffset+=1.0;
 } else {
     xoffset=0.0;
     yoffset+=1.0;
 }
 ++s;
    }
}

variable_types:
s
char *

variable_types: id int

variable_types: jf int

variable_types: mode int

variable_types: yoffset double

variable_types: xoffset double

variable_types: xoff double

variable_types: yoff double

variable_types: width double

variable_types: height double

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


decompiled_code:
__int64 __fastcall draw_cbox(int a1, double a2, double a3)
{
__int64 v4; // xmm1_8
__int64 v5; // xmm3_8
__int64 v6; // xmm2_8
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

v8[8] = 0;
*(double *)&v4 = a3 + *(double *)&ymin - *(double *)&y3;
*(double *)&v5 = a3 + *(double *)&ymax - *(double *)&y3;
*(double *)&v6 = a2 + *(double *)&xmax - *(double *)&x3;
yy1_10 = v4;
*(double *)&xx1_11 = *(double *)&xmin + a2 - *(double *)&x3;
xx2_9 = v6;
yy2_8 = v5;
if ( a1 )
{
v5 = y2old_7;
v6 = x2old_6;
v4 = y1old_5;
db_drawbounds(1LL, *(double *)&x1old_4);
if ( a1 > 0 )
{
v5 = yy2_8;
v6 = xx2_9;
v4 = yy1_10;
db_drawbounds(1LL, *(double *)&xx1_11);
}
}
else
{
db_drawbounds(1LL, *(double *)&xmin + a2 - *(double *)&x3);
}
x1old_4 = xx1_11;
y1old_5 = yy1_10;
x2old_6 = xx2_9;
y2old_7 = yy2_8;
return jump(v8, 1LL, *(double *)&yy2_8, *(double *)&v4, *(double *)&v6, *(double *)&v5);
}

original_code:
void draw_cbox(double x, double y, int count)
{
 static double x1old, x2old, y1old, y2old;
 static double xx1, yy1, xx2, yy2;
 BOUNDS bb;
 bb.init=0;
 xx1=xmin+x-x3;
 yy1=ymin+y-y3;
 xx2=xmax+x-x3;
 yy2=ymax+y-y3;
 if (count == 0) {
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else if (count > 0) {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
 }
 x1old=xx1;
 y1old=yy1;
 x2old=xx2;
 y2old=yy2;
 jump(&bb, 1);
}

canonical_original_code:
void draw_cbox(double x, double y, int count)
{
 static double x1old; static double x2old; static double y1old; static double y2old;
 static double xx1; static double yy1; static double xx2; static double yy2;
 struct bounds bb;
 bb.init=0;
 xx1=xmin+x-x3;
 yy1=ymin+y-y3;
 xx2=xmax+x-x3;
 yy2=ymax+y-y3;
 if (count == 0) {
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else if (count > 0) {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
     db_drawbounds(xx1, yy1, xx2, yy2, 1);
 } else {
     db_drawbounds(x1old, y1old, x2old, y2old, 1);
 }
 x1old=xx1;
 y1old=yy1;
 x2old=xx2;
 y2old=yy2;
 jump(&bb, 1);
}

variable_types: x double

variable_types: y double

variable_types: count int

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


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

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

original_code:
void copy_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,y1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,y1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=y1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}

canonical_original_code:
void copy_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,y1,x2,y2,1);
        } else if (count > 0) {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
            db_drawbounds(x1,y1,x2,y2,1);
        } else {
            db_drawbounds(x1old,y1old,x2old,y2old,1);
        }
        x1old=x1;
        y1old=y1;
        x2old=x2;
        y2old=y2;
        jump(&bb, 1);
}


original_code:
void selpnt_print(SELPNT **selhead) {
    SELPNT *tmp1;
    int i=0;
    tmp1 = *selhead;
    printf("------------------\n");
    while (tmp1 != ((void *)0)) {
        printf("%d: %g %g %g %g\n", i++,
  (tmp1->xsel == ((void *)0))?0.0:(*(tmp1->xsel)),
  (tmp1->ysel == ((void *)0))?0.0:(*(tmp1->ysel)),
  (tmp1->xselorig), (tmp1->yselorig));
 tmp1 = tmp1->next;
    }
}

canonical_original_code:
void selpnt_print(struct selpnt **selhead) {
    struct selpnt *tmp1;
    int i = 0;
    tmp1 = *selhead;
    printf("------------------\n");
    while (tmp1 != ((void *)0)) {
        printf("%d: %g %g %g %g\n", i++,
  (tmp1->xsel == ((void *)0))?0.0:(*(tmp1->xsel)),
  (tmp1->ysel == ((void *)0))?0.0:(*(tmp1->ysel)),
  (tmp1->xselorig), (tmp1->yselorig));
 tmp1 = tmp1->next;
    }
}

variable_types: struct selpnt { 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; } *p; double *xsel; double *ysel; double xselorig; double yselorig; struct selpnt *next; struct selpnt *prev; } **

variable_types: i int

user_defined_types: struct selpnt { struct db_deflist *p; double *xsel; double *ysel; double xselorig; double yselorig; struct selpnt *next; struct selpnt *prev; }


decompiled_code:
__int64 __fastcall draw_line(int a1, double a2, double a3)
{
__int64 v3; // rax
double v5; // [rsp+0h] [rbp-58h] BYREF
double v6; // [rsp+8h] [rbp-50h] BYREF
char v7[8]; // [rsp+10h] [rbp-48h] BYREF
char v8[8]; // [rsp+18h] [rbp-40h] BYREF
char v9[32]; // [rsp+20h] [rbp-38h] BYREF
int v10; // [rsp+40h] [rbp-18h]

v6 = a2;
v5 = a3;
v10 = 0;
getlockpoint(v7, v8);
lockpoint(&v6, &v5, *(double *)(currep + 4296LL));
v3 = CP;
qword_888 = (__int64)&dbline;
dbdeflist_1 = 64;
dbline = 1;
*((_QWORD *)&dbline + 1) = &lopts;
*((_QWORD *)&dbline + 2) = v3;
if ( !a1 )
{
jump(v9, 1LL);
goto LABEL_8;
}
if ( a1 > 0 )
{
jump(v9, 1LL);
do_line(&dbdeflist_1, v9, 1LL);
jump(v9, 1LL);
coord_edit(CP, 0LL, v6, v5);
LABEL_8:
do_line(&dbdeflist_1, v9, 1LL);
++called_0;
return jump(v9, 1LL);
}
if ( called_0 )
{
jump(v9, 1LL);
do_line(&dbdeflist_1, v9, 1LL);
}
called_0 = 0;
return jump(v9, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3)
{
__int64 v3; // rax
double v5; // [rsp+0h] [rbp-58h] BYREF
double v6; // [rsp+8h] [rbp-50h] BYREF
char v7[8]; // [rsp+10h] [rbp-48h] BYREF
char v8[8]; // [rsp+18h] [rbp-40h] BYREF
char v9[32]; // [rsp+20h] [rbp-38h] BYREF
int v10; // [rsp+40h] [rbp-18h]

v6 = a2;
v5 = a3;
v10 = 0;
getlockpoint(v7, v8);
lockpoint(&v6, &v5, *(double *)(currep + 4296LL));
v3 = CP;
qword_888 = (__int64)&dbline;
dbdeflist_1 = 64;
dbline = 1;
*((_QWORD *)&dbline + 1) = &lopts;
*((_QWORD *)&dbline + 2) = v3;
if ( !a1 )
{
jump(v9, 1LL);
goto LABEL_8;
}
if ( a1 > 0 )
{
jump(v9, 1LL);
do_line(&dbdeflist_1, v9, 1LL);
jump(v9, 1LL);
coord_edit(CP, 0LL, v6, v5);
LABEL_8:
do_line(&dbdeflist_1, v9, 1LL);
++called_0;
return jump(v9, 1LL);
}
if ( called_0 )
{
jump(v9, 1LL);
do_line(&dbdeflist_1, v9, 1LL);
}
called_0 = 0;
return jump(v9, 1LL);
}

original_code:
void draw_line(double x2, double y2, int count)
{
 double xl, yl;
 int debug=0;
 BOUNDS bb;
 static int called = 0;
 bb.init=0;
 static DB_DEFLIST dbdeflist;
 getlockpoint(&xl, &yl);
 lockpoint(&x2, &y2, currep->lock_angle);
        dbdeflist.u.l = &dbline;
        dbdeflist.type = 64;
        dbline.layer=1;
        dbline.opts=&lopts;
        dbline.coords=CP;
 if (debug) {printf("in draw_line\n");}
 if (count == 0) {
     jump(&bb, 1);
     do_line(&dbdeflist, &bb, 1);
     called++;
 } else if (count > 0) {
     jump(&bb, 1);
     do_line(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     coord_edit(CP, 0, x2, y2);
     do_line(&dbdeflist, &bb, 1);
     called++;
 } else {
     if (called) {
  jump(&bb, 1);
  do_line(&dbdeflist, &bb, 1);
     }
     called = 0;
 }
 jump(&bb, 1);
}

canonical_original_code:
void draw_line(double x2, double y2, int count)
{
 double xl; double yl;
 int debug = 0;
 struct bounds bb;
 static int called = 0;
 bb.init=0;
 static struct db_deflist dbdeflist;
 getlockpoint(&xl, &yl);
 lockpoint(&x2, &y2, currep->lock_angle);
        dbdeflist.u.l = &dbline;
        dbdeflist.type = 64;
        dbline.layer=1;
        dbline.opts=&lopts;
        dbline.coords=CP;
 if (debug) {printf("in draw_line\n");}
 if (count == 0) {
     jump(&bb, 1);
     do_line(&dbdeflist, &bb, 1);
     called++;
 } else if (count > 0) {
     jump(&bb, 1);
     do_line(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     coord_edit(CP, 0, x2, y2);
     do_line(&dbdeflist, &bb, 1);
     called++;
 } else {
     if (called) {
  jump(&bb, 1);
  do_line(&dbdeflist, &bb, 1);
     }
     called = 0;
 }
 jump(&bb, 1);
}

variable_types: xl double

variable_types: yl double

variable_types: debug int

variable_types: called int

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


cleanup

decompiled_code:
__int64 __fastcall cleanup(__int64 a1)
{
__int64 result; // rax
int v2; // ebp
int i; // ebx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
char v5[32]; // [rsp+8h] [rbp-20h] BYREF

result = coord_count();
if ( (int)result > 0 )
{
v2 = result;
for ( i = 1; i <= v2; ++i )
result = coord_get(a1, (unsigned int)i, &v4, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int v2; // ebp
int i; // ebx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
char v5[32]; // [rsp+8h] [rbp-20h] BYREF

result = coord_count();
if ( (int)result > 0 )
{
v2 = result;
for ( i = 1; i <= v2; ++i )
result = coord_get(a1, (unsigned int)i, &v4, v5);
}
return result;
}

original_code:
void cleanup(COORDS *CP) {
   int n;
   int i;
   double x,y;
   n=coord_count(CP);
   for (i=1; i<=n; i++) {
      coord_get(CP, i, &x, &y);
   }
}

canonical_original_code:
void cleanup(struct coord_list *CP) {
   int n;
   int i;
   double x; double y;
   n=coord_count(CP);
   for (i=1; i<=n; i++) {
      coord_get(CP, i, &x, &y);
   }
}

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

variable_types: n int


decompiled_code:
__int64 __fastcall 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 *)&y1, v6, v5, v4, v3);
v7 = *(_QWORD *)&v10;
v8 = *(_QWORD *)&v11;
LABEL_5:
x2old_2 = v7;
y2old_3 = v8;
x1old_0 = x1;
y1old_1 = y1;
return jump(v12, 1LL);
}

original_code:
void 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,y1,x2,y2,1);
 } else if (count > 0) {
     db_drawbounds(x1old,y1old,x2old,y2old,1);
     db_drawbounds(x1,y1,x2,y2,1);
 } else {
     db_drawbounds(x1old,y1old,x2old,y2old,1);
 }
 x1old=x1;
 y1old=y1;
 x2old=x2;
 y2old=y2;
 jump(&bb, 1);
}

canonical_original_code:
void 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,y1,x2,y2,1);
 } else if (count > 0) {
     db_drawbounds(x1old,y1old,x2old,y2old,1);
     db_drawbounds(x1,y1,x2,y2,1);
 } else {
     db_drawbounds(x1old,y1old,x2old,y2old,1);
 }
 x1old=x1;
 y1old=y1;
 x2old=x2;
 y2old=y2;
 jump(&bb, 1);
}


decompiled_code:
__int64 __fastcall draw_arc(int a1, double a2, double a3)
{
__int64 v4; // xmm0_8
_DWORD v6[18]; // [rsp-20h] [rbp-48h] BYREF

qword_588 = (__int64)&dbarc;
v6[8] = 0;
*((_QWORD *)&dbarc + 2) = gx1;
dbdeflist_2 = 1;
*((_QWORD *)&dbarc + 3) = gy1;
dbarc = 1;
*((_QWORD *)&dbarc + 4) = x2;
v4 = y2;
*((_QWORD *)&dbarc + 1) = &aopts;
*((_QWORD *)&dbarc + 5) = v4;
if ( a1 )
{
jump(v6, 1LL);
*((_QWORD *)&dbarc + 6) = x3old_1;
*((_QWORD *)&dbarc + 7) = y3old_0;
if ( a1 > 0 )
{
do_arc(&dbdeflist_2, v6, 1LL);
jump(v6, 1LL);
*((double *)&dbarc + 6) = a2;
*((double *)&dbarc + 7) = a3;
}
}
else
{
jump(v6, 1LL);
*((double *)&dbarc + 6) = a2;
*((double *)&dbarc + 7) = a3;
}
do_arc(&dbdeflist_2, v6, 1LL);
x3old_1 = *(_QWORD *)&a2;
y3old_0 = *(_QWORD *)&a3;
return jump(v6, 1LL);
}

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

qword_588 = (__int64)&dbarc;
v6[8] = 0;
*((_QWORD *)&dbarc + 2) = gx1;
dbdeflist_2 = 1;
*((_QWORD *)&dbarc + 3) = gy1;
dbarc = 1;
*((_QWORD *)&dbarc + 4) = x2;
v4 = y2;
*((_QWORD *)&dbarc + 1) = &aopts;
*((_QWORD *)&dbarc + 5) = v4;
if ( a1 )
{
jump(v6, 1LL);
*((_QWORD *)&dbarc + 6) = x3old_1;
*((_QWORD *)&dbarc + 7) = y3old_0;
if ( a1 > 0 )
{
do_arc(&dbdeflist_2, v6, 1LL);
jump(v6, 1LL);
*((double *)&dbarc + 6) = a2;
*((double *)&dbarc + 7) = a3;
}
}
else
{
jump(v6, 1LL);
*((double *)&dbarc + 6) = a2;
*((double *)&dbarc + 7) = a3;
}
do_arc(&dbdeflist_2, v6, 1LL);
x3old_1 = *(_QWORD *)&a2;
y3old_0 = *(_QWORD *)&a3;
return jump(v6, 1LL);
}

original_code:
void draw_arc(double x3, double y3, int count)
{
 static double x3old, y3old;
 int debug=0;
 BOUNDS bb;
 static DB_DEFLIST dbdeflist;
 bb.init=0;
        dbdeflist.u.a = &dbarc;
        dbdeflist.type = 1;
        dbarc.layer=1;
        dbarc.opts=&aopts;
 dbarc.x1 = gx1;
 dbarc.y1 = gy1;
 dbarc.x2 = x2;
 dbarc.y2 = y2;
 if (debug) {printf("in draw_arc\n");}
 if (count == 0) {
     jump(&bb, 1);
     dbarc.x3 = x3;
     dbarc.y3 = y3;
     do_arc(&dbdeflist, &bb, 1);
 } else if (count > 0) {
     jump(&bb, 1);
     dbarc.x3 = x3old;
     dbarc.y3 = y3old;
     do_arc(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     dbarc.x3 = x3;
     dbarc.y3 = y3;
     do_arc(&dbdeflist, &bb, 1);
 } else {
     jump(&bb, 1);
     dbarc.x3 = x3old;
     dbarc.y3 = y3old;
     do_arc(&dbdeflist, &bb, 1);
 }
 x3old=x3;
 y3old=y3;
 jump(&bb, 1);
}

canonical_original_code:
void draw_arc(double x3, double y3, int count)
{
 static double x3old; static double y3old;
 int debug = 0;
 struct bounds bb;
 static struct db_deflist dbdeflist;
 bb.init=0;
        dbdeflist.u.a = &dbarc;
        dbdeflist.type = 1;
        dbarc.layer=1;
        dbarc.opts=&aopts;
 dbarc.x1 = gx1;
 dbarc.y1 = gy1;
 dbarc.x2 = x2;
 dbarc.y2 = y2;
 if (debug) {printf("in draw_arc\n");}
 if (count == 0) {
     jump(&bb, 1);
     dbarc.x3 = x3;
     dbarc.y3 = y3;
     do_arc(&dbdeflist, &bb, 1);
 } else if (count > 0) {
     jump(&bb, 1);
     dbarc.x3 = x3old;
     dbarc.y3 = y3old;
     do_arc(&dbdeflist, &bb, 1);
     jump(&bb, 1);
     dbarc.x3 = x3;
     dbarc.y3 = y3;
     do_arc(&dbdeflist, &bb, 1);
 } else {
     jump(&bb, 1);
     dbarc.x3 = x3old;
     dbarc.y3 = y3old;
     do_arc(&dbdeflist, &bb, 1);
 }
 x3old=x3;
 y3old=y3;
 jump(&bb, 1);
}

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

user_defined_types: struct db_inst { char *name; struct opt_list *opts; double x; double colx; double rowx; }

user_defined_types: struct db_note { int layer; struct opt_list *opts; char *text; double x; }

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

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

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

user_defined_types: struct db_text { int layer; struct opt_list *opts; char *text; double x; }

user_defined_types: 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; }


decompiled_code:
__int64 __fastcall pig_system(__int64 a1)
{
unsigned int v1; // ebp
__pid_t v2; // ebx
void (*v3)(int); // r12
void (*v4)(int); // rbp
__pid_t v5; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

fflush(0LL);
usleep(0x1F4u);
v1 = open("/dev/tty", 2);
if ( v1 == -1 )
{
fwrite("error: can't open /det/tty\n", 1uLL, 0x1BuLL, stderr);
}
else
{
v2 = fork();
if ( !v2 )
{
close(0);
dup(v1);
close(1);
dup(v1);
close(2);
dup(v1);
close(v1);
EVupdate();
execlp("sh", "sh", "-c", a1, 0LL);
exit(127);
}
close(v1);
v3 = signal(2, (__sighandler_t)((char *)pig_system + 1));
v4 = signal(3, (__sighandler_t)((char *)pig_system + 1));
while ( 1 )
{
v5 = wait((__WAIT_STATUS)&stat_loc);
if ( v2 == v5 )
break;
if ( v5 == -1 )
goto LABEL_9;
}
if ( v2 != -1 )
goto LABEL_7;
LABEL_9:
LODWORD(stat_loc.__uptr) = -1;
LABEL_7:
signal(2, v3);
signal(3, v4);
v1 = (unsigned int)stat_loc.__uptr;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebp
__pid_t v2; // ebx
void (*v3)(int); // r12
void (*v4)(int); // rbp
__pid_t v5; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

fflush(0LL);
usleep(0x1F4u);
v1 = open("/dev/tty", 2);
if ( v1 == -1 )
{
fwrite("error: can't open /det/tty\n", 1uLL, 0x1BuLL, stderr);
}
else
{
v2 = fork();
if ( !v2 )
{
close(0);
dup(v1);
close(1);
dup(v1);
close(2);
dup(v1);
close(v1);
EVupdate();
execlp("sh", "sh", "-c", a1, 0LL);
exit(127);
}
close(v1);
v3 = signal(2, (__sighandler_t)((char *)pig_system + 1));
v4 = signal(3, (__sighandler_t)((char *)pig_system + 1));
while ( 1 )
{
v5 = wait((__WAIT_STATUS)&stat_loc);
if ( v2 == v5 )
break;
if ( v5 == -1 )
goto LABEL_9;
}
if ( v2 != -1 )
goto LABEL_7;
LABEL_9:
LODWORD(stat_loc.__uptr) = -1;
LABEL_7:
signal(2, v3);
signal(3, v4);
v1 = (unsigned int)stat_loc.__uptr;
}
return v1;
}

original_code:
int pig_system(char *s) {
   int status, pid, w, tty;
   sighandler_t istat, qstat;
   fflush(((void *)0));
   usleep(500);
   tty = open("/dev/tty", 02);
   if (tty == -1) {
      fprintf(stderr, "error: can't open /det/tty\n");
      return(-1);
   }
   if ((pid = fork()) == 0) {
      close(0); dup(tty);
      close(1); dup(tty);
      close(2); dup(tty);
      close(tty);
      EVupdate();
      execlp("sh", "sh", "-c", s, (char *) 0);
      exit(127);
   }
   close(tty);
   istat = signal(2, ((__sighandler_t) 1));
   qstat = signal(3, ((__sighandler_t) 1));
   while ((w = wait(&status)) != pid && w != -1) {
      ;
   }
   if (w == -1) {
      status = -1;
   }
   signal(2, istat);
   signal(3, qstat);
   return(status);
}

canonical_original_code:
int pig_system(char *s) {
   int status; int pid; int w; int tty;
   void (*istat)(int); void (*qstat)(int);
   fflush(((void *)0));
   usleep(500);
   tty = open("/dev/tty", 02);
   if (tty == -1) {
      fprintf(stderr, "error: can't open /det/tty\n");
      return(-1);
   }
   if ((pid = fork()) == 0) {
      close(0); dup(tty);
      close(1); dup(tty);
      close(2); dup(tty);
      close(tty);
      EVupdate();
      execlp("sh", "sh", "-c", s, (char *) 0);
      exit(127);
   }
   close(tty);
   istat = signal(2, ((void (*)(int)) 1));
   qstat = signal(3, ((void (*)(int)) 1));
   while ((w = wait(&status)) != pid && w != -1) {
      ;
   }
   if (w == -1) {
      status = -1;
   }
   signal(2, istat);
   signal(3, qstat);
   return(status);
}

variable_types:
s
char *

variable_types: status int

variable_types: pid int

variable_types: w int

variable_types: tty int

variable_types:
istat
void (*)(int)

variable_types:
qstat
void (*)(int)