original_code:
static int
TEK_getkey(void)
{
 struct termio oldtty, newtty;
 char c;
 ioctl(0, 0x5405, &oldtty);
 newtty = oldtty;
 newtty.c_iflag = 0000002 | 0002000 | 0000040;
 newtty.c_lflag = 0;
 newtty.c_cc[4] = 1;
 ioctl(0, 0x5406, &newtty);
 read(0, &c, 1);
 ioctl(0, 0x5406, &oldtty);
 return(c);
}

canonical_original_code:
static int TEK_getkey()
{
 struct termio oldtty; struct termio newtty;
 char c;
 ioctl(0, 0x5405, &oldtty);
 newtty = oldtty;
 newtty.c_iflag = 0000002 | 0002000 | 0000040;
 newtty.c_lflag = 0;
 newtty.c_cc[4] = 1;
 ioctl(0, 0x5406, &newtty);
 read(0, &c, 1);
 ioctl(0, 0x5406, &oldtty);
 return(c);
}

user_defined_types: struct termio { unsigned short c_iflag; unsigned short c_oflag; unsigned short c_cflag; unsigned short c_lflag; unsigned char c_line; unsigned char c_cc[8]; }


decompiled_code:
__int64 __fastcall TEK_font(const char *a1)
{
unsigned int v1; // edx

if ( !strcmp(a1, "small") )
{
fwrite("\x1B:", 1uLL, 2uLL, fp);
vdevice[13] = 1090519040;
vdevice[12] = 1097859072;
goto LABEL_5;
}
v1 = 0;
if ( !strcmp(a1, "large") )
{
fwrite("\x1B8", 1uLL, 2uLL, fp);
vdevice[13] = 1096810496;
vdevice[12] = 1099431936;
LABEL_5:
tlsty = -1;
tlstx = -1;
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
unsigned int v1; // edx

if ( !strcmp(a1, "small") )
{
fwrite("\x1B:", 1uLL, 2uLL, fp);
vdevice[13] = 1090519040;
vdevice[12] = 1097859072;
goto LABEL_5;
}
v1 = 0;
if ( !strcmp(a1, "large") )
{
fwrite("\x1B8", 1uLL, 2uLL, fp);
vdevice[13] = 1096810496;
vdevice[12] = 1099431936;
LABEL_5:
tlsty = -1;
tlstx = -1;
v1 = 1;
}
return v1;
}

original_code:
static int
TEK_font(char *tekfont)
{
 if (strcmp(tekfont, "small") == 0) {
  fprintf(fp, "\033:");
  vdevice.hwidth = 8.0;
  vdevice.hheight = 15.0;
 } else if (strcmp(tekfont, "large") == 0) {
  fprintf(fp, "\0338");
  vdevice.hwidth = 14.0;
  vdevice.hheight = 17.0;
 } else
  return(0);
 tlstx = tlsty = -1;
 return(1);
}

variable_types:
tekfont
char *

return_type: int


decompiled_code:
__int64 TEK_exit()
{
fputc(31, fp);
fputc(24, fp);
if ( fp != stdout )
fclose(fp);
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
fputc(31, fp);
fputc(24, fp);
if ( fp != stdout )
fclose(fp);
return 0LL;
}

original_code:
static int
TEK_exit(void)
{
 fputc('\037', fp);
 fputc('\030', fp);
 if (fp != stdout)
  fclose(fp);
 return(0);
}

canonical_original_code:
static int TEK_exit()
{
 fputc('\037', fp);
 fputc('\030', fp);
 if (fp != stdout)
  fclose(fp);
 return(0);
}


decompiled_code:
__int64 TEK_clear()
{
int v0; // ebx

fputc(31, fp);
fputc(27, fp);
fputc(12, fp);
fflush(fp);
tlsty = -1;
tlstx = -1;
if ( fp == stdout )
{
sleep(2u);
}
else
{
v0 = 960;
do
{
fputc(0, fp);
--v0;
}
while ( v0 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx

fputc(31, fp);
fputc(27, fp);
fputc(12, fp);
fflush(fp);
tlsty = -1;
tlstx = -1;
if ( fp == stdout )
{
sleep(2u);
}
else
{
v0 = 960;
do
{
fputc(0, fp);
--v0;
}
while ( v0 );
}
return 0LL;
}

original_code:
static int
TEK_clear(void)
{
 fputc('\037', fp);
 fputc('\033', fp);
 fputc('\014', fp);
 fflush(fp);
 tlstx = tlsty = -1;
 if (fp != stdout) {
  int i;
  for (i = 0; i < 960; i++)
   fputc(0, fp);
 } else
  sleep(2);
 return(0);
}

canonical_original_code:
static int TEK_clear()
{
 fputc('\037', fp);
 fputc('\033', fp);
 fputc('\014', fp);
 fflush(fp);
 tlstx = tlsty = -1;
 if (fp != stdout) {
  int i;
  for (i = 0; i < 960; i++)
   fputc(0, fp);
 } else
  sleep(2);
 return(0);
}

variable_types: i int


noop

decompiled_code:
__int64 noop()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
static int
noop()
{
 return(-1);
}

canonical_original_code:
static int noop()
{
 return(-1);
}


decompiled_code:
__int64 popdev_()
{
return popdev();
}

canonical_decompiled_code:
__int64 func7()
{
return popdev();
}

original_code:
void
popdev_()
{
 popdev();
}

canonical_original_code:
void popdev_()
{
 popdev();
}

return_type: void


decompiled_code:
__int64 gexit_()
{
return gexit();
}

canonical_decompiled_code:
__int64 func10()
{
return gexit();
}

original_code:
void
gexit_()
{
 gexit();
}

canonical_original_code:
void gexit_()
{
 gexit();
}


decompiled_code:
int clear_()
{
return clear();
}

canonical_decompiled_code:
int func11()
{
return clear();
}

original_code:
void
clear_()
{
 clear();
}

canonical_original_code:
void clear_()
{
 clear();
}


decompiled_code:
__int64 getpla_()
{
return getplanes();
}

canonical_decompiled_code:
__int64 func17()
{
return getplanes();
}

original_code:
int
getpla_()
{
 return((int)getplanes());
}


decompiled_code:
void gconfi_()
{
;
}

canonical_decompiled_code:
void func23()
{
;
}

original_code:
int
gconfi_()
{ }

canonical_original_code:
int gconfi_()
{ }


decompiled_code:
__int64 reshap_()
{
return reshapeviewport();
}

canonical_decompiled_code:
__int64 func25()
{
return reshapeviewport();
}

original_code:
int
reshap_()
{
 reshapeviewport();
}

canonical_original_code:
int reshap_()
{
 reshapeviewport();
}


decompiled_code:
void wincon_()
{
;
}

canonical_decompiled_code:
void func27()
{
;
}

original_code:
void
wincon_()
{ }

canonical_original_code:
void wincon_()
{ }


decompiled_code:
void foreground_()
{
;
}

canonical_decompiled_code:
void func34()
{
;
}

original_code:
void
foreground_()
{
}

canonical_original_code:
void foreground_()
{
}


decompiled_code:
void foregr_()
{
;
}

canonical_decompiled_code:
void func35()
{
;
}

original_code:
void
foregr_()
{
}

canonical_original_code:
void foregr_()
{
}


decompiled_code:
__int64 vflush_()
{
return vdevice[41]();
}

canonical_decompiled_code:
__int64 func36()
{
return vdevice[41]();
}

original_code:
void
vflush_()
{
 (*vdevice.dev.Vsync)();
}


rect

decompiled_code:
__int64 __fastcall rect(float a1, float a2, float a3, float a4)
{
__int64 result; // rax

if ( vdevice )
{
move2(a1, a2);
draw2(a3, a2);
draw2(a3, a4);
draw2(a1, a4);
result = draw2(a1, a2);
}
else
{
verror("rect: vogl not initialised");
result = recti();
}
return result;
}

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

if ( vdevice )
{
move2(a1, a2);
draw2(a3, a2);
draw2(a3, a4);
draw2(a1, a4);
result = draw2(a1, a2);
}
else
{
verror("rect: vogl not initialised");
result = func1();
}
return result;
}

original_code:
void
rect(Coord x1, Coord y1, Coord x2, Coord y2)
{
 if (!vdevice.initialised)
  verror("rect: vogl not initialised");
 move2(x1, y1);
 draw2(x2, y1);
 draw2(x2, y2);
 draw2(x1, y2);
 draw2(x1, y1);
}

canonical_original_code:
void rect(float x1, float y1, float x2, float y2)
{
 if (!vdevice.initialised)
  verror("rect: vogl not initialised");
 move2(x1, y1);
 draw2(x2, y1);
 draw2(x2, y2);
 draw2(x1, y2);
 draw2(x1, y1);
}


recti

decompiled_code:
__int64 __fastcall recti(int a1, int a2, int a3, int a4)
{
return rect((float)a1, (float)a2, (float)a3, (float)a4);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4)
{
return func0((float)a1, (float)a2, (float)a3, (float)a4);
}

original_code:
void
recti(Icoord x1, Icoord y1, Icoord x2, Icoord y2)
{
 rect((Coord)x1, (Coord)y1, (Coord)x2, (Coord)y2);
}

canonical_original_code:
void recti(long x1, long y1, long x2, long y2)
{
 rect((float)x1, (float)y1, (float)x2, (float)y2);
}


rects

decompiled_code:
__int64 __fastcall rects(__int16 a1, __int16 a2, __int16 a3, __int16 a4)
{
return rect((float)a1, (float)a2, (float)a3, (float)a4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __int16 a2, __int16 a3, __int16 a4)
{
return func0((float)a1, (float)a2, (float)a3, (float)a4);
}

original_code:
void
rects(Scoord x1, Scoord y1, Scoord x2, Scoord y2)
{
 rect((Coord)x1, (Coord)y1, (Coord)x2, (Coord)y2);
}

canonical_original_code:
void rects(short x1, short y1, short x2, short y2)
{
 rect((float)x1, (float)y1, (float)x2, (float)y2);
}


frontbuffer

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

if ( !vdevice )
{
verror("frontbuffer: vogl not initialised.");
goto LABEL_8;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_8:
result = newtokens(2LL);
*(_DWORD *)result = 35;
*(_DWORD *)(result + 4) = a1;
return result;
}
result = *((_QWORD *)&vdevice + 4);
if ( *(_BYTE *)(result + 1) != 1 )
{
if ( a1 )
{
(*((void (**)(void))&vdevice + 31))();
*((_BYTE *)&vdevice + 7) = 0;
result = (unsigned int)sync;
*((_BYTE *)&vdevice + 6) = sync;
}
else
{
result = (__int64)backbuffer(1);
}
}
return result;
}

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

if ( !vdevice )
{
verror("frontbuffer: vogl not initialised.");
goto LABEL_8;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_8:
result = newtokens(2LL);
*(_DWORD *)result = 35;
*(_DWORD *)(result + 4) = a1;
return result;
}
result = *((_QWORD *)&vdevice + 4);
if ( *(_BYTE *)(result + 1) != 1 )
{
if ( a1 )
{
(*((void (**)(void))&vdevice + 31))();
*((_BYTE *)&vdevice + 7) = 0;
result = (unsigned int)sync;
*((_BYTE *)&vdevice + 6) = sync;
}
else
{
result = (__int64)backbuffer(1);
}
}
return result;
}

original_code:
void
frontbuffer(int yes)
{
 Token *tok;
 if (!vdevice.initialised)
  verror("frontbuffer: vogl not initialised.");
 if (vdevice.inobject) {
  tok = newtokens(2);
  tok[0].i = 35;
  tok[1].i = yes;
  return;
 }
 if (vdevice.attr->a.mode == 1)
  return;
 if (yes) {
  (*vdevice.dev.Vfrontb)();
  vdevice.inbackbuffer = 0;
  vdevice.sync = sync;
 } else
  backbuffer(1);
}

canonical_original_code:
void frontbuffer(int yes)
{
 union tk *tok;
 if (!vdevice.initialised)
  verror("frontbuffer: vogl not initialised.");
 if (vdevice.inobject) {
  tok = newtokens(2);
  tok[0].i = 35;
  tok[1].i = yes;
  return;
 }
 if (vdevice.attr->a.mode == 1)
  return;
 if (yes) {
  (*vdevice.dev.Vfrontb)();
  vdevice.inbackbuffer = 0;
  vdevice.sync = sync;
 } else
  backbuffer(1);
}

variable_types: yes int

variable_types:
tok
union tk { int i; float f; } *


swapbuffers

decompiled_code:
_DWORD *swapbuffers()
{
_DWORD *result; // rax

if ( *((_BYTE *)&vdevice + 2) )
{
result = (_DWORD *)newtokens(1LL);
*result = 36;
}
else if ( vdevice )
{
result = (_DWORD *)(*((__int64 (**)(void))&vdevice + 39))();
}
else
{
verror("swapbuffers: vogl not initialised.");
result = (_DWORD *)doublebuffer();
}
return result;
}

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

if ( *((_BYTE *)&vdevice + 2) )
{
result = (_DWORD *)newtokens(1LL);
*result = 36;
}
else if ( vdevice )
{
result = (_DWORD *)(*((__int64 (**)(void))&vdevice + 39))();
}
else
{
verror("swapbuffers: vogl not initialised.");
result = (_DWORD *)func2();
}
return result;
}

original_code:
void
swapbuffers(void)
{
 Token *tok;
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok[0].i = 36;
  return;
 }
 if (!vdevice.initialised)
  verror("swapbuffers: vogl not initialised.");
 (*vdevice.dev.Vswapb)();
}

canonical_original_code:
void swapbuffers()
{
 union tk *tok;
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok[0].i = 36;
  return;
 }
 if (!vdevice.initialised)
  verror("swapbuffers: vogl not initialised.");
 (*vdevice.dev.Vswapb)();
}


doublebuffer

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

if ( vdevice )
{
result = (void *)(*((__int64 (**)(void))&vdevice + 22))();
if ( (int)result >= 0 )
{
result = &vdevice;
*((_BYTE *)&vdevice + 7) = 1;
sync = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
}
}
else
{
verror("doublebuffer: vogl not initialised.");
result = (void *)singlebuffer();
}
return result;
}

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

if ( vdevice )
{
result = (void *)(*((__int64 (**)(void))&vdevice + 22))();
if ( (int)result >= 0 )
{
result = &vdevice;
*((_BYTE *)&vdevice + 7) = 1;
sync = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
}
}
else
{
verror("doublebuffer: vogl not initialised.");
result = (void *)func3();
}
return result;
}

original_code:
void
doublebuffer(void)
{
 if (!vdevice.initialised)
  verror("doublebuffer: vogl not initialised.");
 if ((*vdevice.dev.Vbackb)() >= 0) {
  vdevice.inbackbuffer = 1;
  sync = vdevice.sync;
  vdevice.sync = 0;
 }
}

canonical_original_code:
void doublebuffer()
{
 if (!vdevice.initialised)
  verror("doublebuffer: vogl not initialised.");
 if ((*vdevice.dev.Vbackb)() >= 0) {
  vdevice.inbackbuffer = 1;
  sync = vdevice.sync;
  vdevice.sync = 0;
 }
}


singlebuffer

decompiled_code:
_BYTE *singlebuffer()
{
_BYTE *result; // rax

result = (_BYTE *)*((_QWORD *)&vdevice + 4);
if ( result[1] != 1 )
{
result = (_BYTE *)(*((__int64 (**)(void))&vdevice + 31))();
*((_BYTE *)&vdevice + 7) = 0;
if ( sync )
{
result = &vdevice;
*((_BYTE *)&vdevice + 6) = 1;
}
}
return result;
}

canonical_decompiled_code:
_BYTE *func3()
{
_BYTE *result; // rax

result = (_BYTE *)*((_QWORD *)&vdevice + 4);
if ( result[1] != 1 )
{
result = (_BYTE *)(*((__int64 (**)(void))&vdevice + 31))();
*((_BYTE *)&vdevice + 7) = 0;
if ( sync )
{
result = &vdevice;
*((_BYTE *)&vdevice + 6) = 1;
}
}
return result;
}

original_code:
void
singlebuffer(void)
{
 if (vdevice.attr->a.mode == 1)
  return;
 (*vdevice.dev.Vfrontb)();
 vdevice.inbackbuffer = 0;
 if (sync)
  vdevice.sync = 1;
}

canonical_original_code:
void singlebuffer()
{
 if (vdevice.attr->a.mode == 1)
  return;
 (*vdevice.dev.Vfrontb)();
 vdevice.inbackbuffer = 0;
 if (sync)
  vdevice.sync = 1;
}


pushattributes

decompiled_code:
_DWORD *pushattributes()
{
__int64 v0; // rax
unsigned __int8 *v1; // rsi
_DWORD *result; // rax
__int64 v3; // rbx
unsigned __int8 *v4; // rsi

if ( !vdevice )
{
verror("pushattributes: vogl not initialised");
goto LABEL_6;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_6:
result = (_DWORD *)newtokens(1LL);
*result = 25;
return result;
}
v0 = asfree;
if ( asfree )
{
v1 = (unsigned __int8 *)*((_QWORD *)&vdevice + 4);
*((_QWORD *)&vdevice + 4) = asfree;
asfree = *(_QWORD *)(v0 + 16);
*(_QWORD *)(v0 + 16) = v1;
result = (_DWORD *)copyattributes(*((_QWORD *)&vdevice + 4), v1);
}
else
{
v3 = vallocate(24LL);
v4 = (unsigned __int8 *)*((_QWORD *)&vdevice + 4);
*(_QWORD *)(v3 + 16) = v4;
result = (_DWORD *)copyattributes(v3, v4);
*((_QWORD *)&vdevice + 4) = v3;
}
return result;
}

canonical_decompiled_code:
_DWORD *func1()
{
__int64 v0; // rax
unsigned __int8 *v1; // rsi
_DWORD *result; // rax
__int64 v3; // rbx
unsigned __int8 *v4; // rsi

if ( !vdevice )
{
verror("pushattributes: vogl not initialised");
goto LABEL_6;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_6:
result = (_DWORD *)newtokens(1LL);
*result = 25;
return result;
}
v0 = asfree;
if ( asfree )
{
v1 = (unsigned __int8 *)*((_QWORD *)&vdevice + 4);
*((_QWORD *)&vdevice + 4) = asfree;
asfree = *(_QWORD *)(v0 + 16);
*(_QWORD *)(v0 + 16) = v1;
result = (_DWORD *)func0(*((_QWORD *)&vdevice + 4), v1);
}
else
{
v3 = vallocate(24LL);
v4 = (unsigned __int8 *)*((_QWORD *)&vdevice + 4);
*(_QWORD *)(v3 + 16) = v4;
result = (_DWORD *)func0(v3, v4);
*((_QWORD *)&vdevice + 4) = v3;
}
return result;
}

original_code:
void
pushattributes(void)
{
 Astack *nattr;
 Token *p;
 if (!vdevice.initialised)
  verror("pushattributes:  vogl not initialised");
 if (vdevice.inobject) {
  p = newtokens(1);
  p[0].i = 25;
  return;
 }
 if (asfree != (Astack *)((void *)0)) {
  nattr = vdevice.attr;
  vdevice.attr = asfree;
  asfree = asfree->back;
  vdevice.attr->back = nattr;
  copyattributes(&vdevice.attr->a, &nattr->a);
 } else {
  nattr = (Astack *)vallocate(sizeof(Astack));
  nattr->back = vdevice.attr;
  copyattributes(&nattr->a, &vdevice.attr->a);
  vdevice.attr = nattr;
 }
}

canonical_original_code:
void pushattributes()
{
 struct as *nattr;
 union tk *p;
 if (!vdevice.initialised)
  verror("pushattributes:  vogl not initialised");
 if (vdevice.inobject) {
  p = newtokens(1);
  p[0].i = 25;
  return;
 }
 if (asfree != (struct as *)((void *)0)) {
  nattr = vdevice.attr;
  vdevice.attr = asfree;
  asfree = asfree->back;
  vdevice.attr->back = nattr;
  copyattributes(&vdevice.attr->a, &nattr->a);
 } else {
  nattr = (struct as *)vallocate(sizeof(Astack));
  nattr->back = vdevice.attr;
  copyattributes(&nattr->a, &vdevice.attr->a);
  vdevice.attr = nattr;
 }
}

variable_types: struct as { struct Attribute { char backface; int color; int fontnum; unsigned short ls; short lw; } a; struct as *back; } *

variable_types:
p
union tk { int i; float f; } *

user_defined_types: struct as { struct Attribute a; struct as *back; }


popattributes

decompiled_code:
_DWORD *popattributes()
{
__int64 v0; // rax
__int64 v1; // rax
_DWORD *result; // rax

if ( !vdevice )
{
verror("popattributes: vogl not initialised");
goto LABEL_6;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_6:
result = (_DWORD *)newtokens(1LL);
*result = 22;
return result;
}
v0 = *(_QWORD *)(*((_QWORD *)&vdevice + 4) + 16LL);
if ( !v0 )
{
verror("popattributes: attribute stack is empty");
JUMPOUT(0x173LL);
}
font((unsigned int)*(__int16 *)(v0 + 8));
v1 = *((_QWORD *)&vdevice + 4);
*((_QWORD *)&vdevice + 4) = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v1 + 16) = asfree;
asfree = v1;
(*((void (__fastcall **)(_QWORD))&vdevice + 36))(*(unsigned __int16 *)(*((_QWORD *)&vdevice + 4) + 12LL));
(*((void (__fastcall **)(_QWORD))&vdevice + 37))((unsigned int)*(__int16 *)(*((_QWORD *)&vdevice + 4) + 14LL));
return (_DWORD *)color(*(unsigned int *)(*((_QWORD *)&vdevice + 4) + 4LL));
}

canonical_decompiled_code:
_DWORD *func2()
{
__int64 v0; // rax
__int64 v1; // rax
_DWORD *result; // rax

if ( !vdevice )
{
verror("popattributes: vogl not initialised");
goto LABEL_6;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_6:
result = (_DWORD *)newtokens(1LL);
*result = 22;
return result;
}
v0 = *(_QWORD *)(*((_QWORD *)&vdevice + 4) + 16LL);
if ( !v0 )
{
verror("popattributes: attribute stack is empty");
JUMPOUT(0x173LL);
}
font((unsigned int)*(__int16 *)(v0 + 8));
v1 = *((_QWORD *)&vdevice + 4);
*((_QWORD *)&vdevice + 4) = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v1 + 16) = asfree;
asfree = v1;
(*((void (__fastcall **)(_QWORD))&vdevice + 36))(*(unsigned __int16 *)(*((_QWORD *)&vdevice + 4) + 12LL));
(*((void (__fastcall **)(_QWORD))&vdevice + 37))((unsigned int)*(__int16 *)(*((_QWORD *)&vdevice + 4) + 14LL));
return (_DWORD *)color(*(unsigned int *)(*((_QWORD *)&vdevice + 4) + 4LL));
}

original_code:
void
popattributes(void)
{
 Astack *nattr;
 Token *p;
 if (!vdevice.initialised)
  verror("popattributes: vogl not initialised");
 if (vdevice.inobject) {
  p = newtokens(1);
  p[0].i = 22;
  return;
 }
 if (vdevice.attr->back == (Astack *)((void *)0))
  verror("popattributes: attribute stack is empty");
 else {
  font(vdevice.attr->back->a.fontnum);
  nattr = vdevice.attr;
  vdevice.attr = vdevice.attr->back;
  nattr->back = asfree;
  asfree = nattr;
 }
 (*vdevice.dev.Vsetls)(vdevice.attr->a.ls);
 (*vdevice.dev.Vsetlw)(vdevice.attr->a.lw);
 color(vdevice.attr->a.color);
}

canonical_original_code:
void popattributes()
{
 struct as *nattr;
 union tk *p;
 if (!vdevice.initialised)
  verror("popattributes: vogl not initialised");
 if (vdevice.inobject) {
  p = newtokens(1);
  p[0].i = 22;
  return;
 }
 if (vdevice.attr->back == (struct as *)((void *)0))
  verror("popattributes: attribute stack is empty");
 else {
  font(vdevice.attr->back->a.fontnum);
  nattr = vdevice.attr;
  vdevice.attr = vdevice.attr->back;
  nattr->back = asfree;
  asfree = nattr;
 }
 (*vdevice.dev.Vsetls)(vdevice.attr->a.ls);
 (*vdevice.dev.Vsetlw)(vdevice.attr->a.lw);
 color(vdevice.attr->a.color);
}

user_defined_types: struct Attribute { char backface; int color; int fontnum; unsigned short ls; short lw; }


decompiled_code:
__int64 CalcW2Vcoeffs()
{
int v0; // edx
int v1; // esi
int v2; // eax
int v3; // ecx
__int64 result; // rax

v0 = vdevice[27];
v1 = vdevice[28];
*(float *)&Vcx = (float)(v0 + v1) * 0.5;
v2 = vdevice[29];
v3 = vdevice[30];
*(float *)&Vcy = (float)(v2 + v3) * 0.5;
*(float *)&Vsx = (float)(v0 - v1) * 0.5;
result = (unsigned int)(v2 - v3);
*(float *)&Vsy = 0.5 * (float)(int)result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edx
int v1; // esi
int v2; // eax
int v3; // ecx
__int64 result; // rax

v0 = vdevice[27];
v1 = vdevice[28];
*(float *)&Vcx = (float)(v0 + v1) * 0.5;
v2 = vdevice[29];
v3 = vdevice[30];
*(float *)&Vcy = (float)(v2 + v3) * 0.5;
*(float *)&Vsx = (float)(v0 - v1) * 0.5;
result = (unsigned int)(v2 - v3);
*(float *)&Vsy = 0.5 * (float)(int)result;
return result;
}

original_code:
void
CalcW2Vcoeffs(void)
{
 Vcx = (float)(vdevice.maxVx + vdevice.minVx) * 0.5;
 Vcy = (float)(vdevice.maxVy + vdevice.minVy) * 0.5;
 Vsx = (float)(vdevice.maxVx - vdevice.minVx) * 0.5;
 Vsy = (float)(vdevice.maxVy - vdevice.minVy) * 0.5;
}

canonical_original_code:
void CalcW2Vcoeffs()
{
 Vcx = (float)(vdevice.maxVx + vdevice.minVx) * 0.5;
 Vcy = (float)(vdevice.maxVy + vdevice.minVy) * 0.5;
 Vsx = (float)(vdevice.maxVx - vdevice.minVx) * 0.5;
 Vsy = (float)(vdevice.maxVy - vdevice.minVy) * 0.5;
}


WtoVx

decompiled_code:
__int64 __fastcall WtoVx(float *a1)
{
return (unsigned int)(int)((float)((float)((float)(*a1 * *(float *)&Vsx) / a1[3]) + *(float *)&Vcx) + 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1)
{
return (unsigned int)(int)((float)((float)((float)(*a1 * *(float *)&Vsx) / a1[3]) + *(float *)&Vcx) + 0.5);
}

original_code:
int
WtoVx(float *p)
{
 return((int)(p[0] * Vsx / p[3] + Vcx + 0.5));
}

variable_types:
p
float *


WtoVy

decompiled_code:
__int64 __fastcall WtoVy(__int64 a1)
{
return (unsigned int)(int)((float)((float)((float)(*(float *)(a1 + 4) * *(float *)&Vsy) / *(float *)(a1 + 12))
+ *(float *)&Vcy)
+ 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return (unsigned int)(int)((float)((float)((float)(*(float *)(a1 + 4) * *(float *)&Vsy) / *(float *)(a1 + 12))
+ *(float *)&Vcy)
+ 0.5);
}

original_code:
int
WtoVy(float *p)
{
 return((int)(p[1] * Vsy / p[3] + Vcy + 0.5));
}


decompiled_code:
__int64 pushat_()
{
return pushattributes();
}

canonical_decompiled_code:
__int64 func1()
{
return pushattributes();
}

original_code:
void
pushat_()
{
 pushattributes();
}

canonical_original_code:
void pushat_()
{
 pushattributes();
}


decompiled_code:
__int64 popatt_()
{
return popattributes();
}

canonical_decompiled_code:
__int64 func3()
{
return popattributes();
}

original_code:
void
popatt_()
{
 popattributes();
}

canonical_original_code:
void popatt_()
{
 popattributes();
}


hnumchars

decompiled_code:
__int64 hnumchars()
{
check_loaded("hnumchars");
return (unsigned int)nchars;
}

canonical_decompiled_code:
__int64 func3()
{
check_loaded("hnumchars");
return (unsigned int)nchars;
}

original_code:
int
hnumchars()
{
 check_loaded("hnumchars");
 return((int)nchars);
}


hgetfontwidth

decompiled_code:
float hgetfontwidth()
{
float v0; // xmm0_4

check_loaded("hgetfontwidth");
if ( dword_D28 >= ftab - dword_D24 )
v0 = (float)dword_D28;
else
v0 = (float)(ftab - dword_D24);
return v0 * *(float *)&SCSIZEX;
}

canonical_decompiled_code:
float func8()
{
float v0; // xmm0_4

check_loaded("hgetfontwidth");
if ( dword_D28 >= ftab - dword_D24 )
v0 = (float)dword_D28;
else
v0 = (float)(ftab - dword_D24);
return v0 * *(float *)&SCSIZEX;
}

original_code:
float
hgetfontwidth()
{
 check_loaded("hgetfontwidth");
 return((float)(SCSIZEX * (((int)ftab.mw) < ((int)(ftab.as - ftab.dec)) ? ((int)(ftab.as - ftab.dec)) : ((int)ftab.mw))));
}

return_type: float


hgetfontheight

decompiled_code:
float hgetfontheight()
{
float v0; // xmm0_4

check_loaded("hgetfontheight");
if ( dword_D28 >= ftab - dword_D24 )
v0 = (float)dword_D28;
else
v0 = (float)(ftab - dword_D24);
return v0 * *(float *)&SCSIZEY;
}

canonical_decompiled_code:
float func9()
{
float v0; // xmm0_4

check_loaded("hgetfontheight");
if ( dword_D28 >= ftab - dword_D24 )
v0 = (float)dword_D28;
else
v0 = (float)(ftab - dword_D24);
return v0 * *(float *)&SCSIZEY;
}

original_code:
float
hgetfontheight()
{
 check_loaded("hgetfontheight");
 return((float)(SCSIZEY * (((int)ftab.mw) < ((int)(ftab.as - ftab.dec)) ? ((int)(ftab.as - ftab.dec)) : ((int)ftab.mw))));
}


hgetdecender

decompiled_code:
float hgetdecender()
{
check_loaded("hgetdecender");
return (float)dword_D24 * *(float *)&SCSIZEY;
}

canonical_decompiled_code:
float func11()
{
check_loaded("hgetdecender");
return (float)dword_D24 * *(float *)&SCSIZEY;
}

original_code:
float
hgetdecender()
{
 check_loaded("hgetdecender");
 return((float)ftab.dec * SCSIZEY);
}


hgetascender

decompiled_code:
float hgetascender()
{
check_loaded("hgetascender");
return (float)ftab * *(float *)&SCSIZEY;
}

canonical_decompiled_code:
float func12()
{
check_loaded("hgetascender");
return (float)ftab * *(float *)&SCSIZEY;
}

original_code:
float
hgetascender()
{
 check_loaded("hgetascender");
 return((float)ftab.as * SCSIZEY);
}


pushmatrix

decompiled_code:
_DWORD *pushmatrix()
{
__int64 v0; // rdi
__int64 v1; // rsi
_DWORD *result; // rax
__int64 v3; // rbx
__int64 v4; // rsi

if ( BYTE2(vdevice[0]) )
{
result = (_DWORD *)newtokens(1LL);
*result = 26;
}
else
{
v0 = msfree;
if ( msfree )
{
v1 = vdevice[3];
vdevice[3] = msfree;
msfree = *(_QWORD *)(v0 + 64);
*(_QWORD *)(v0 + 64) = v1;
result = (_DWORD *)copymatrix(v0, v1);
}
else
{
v3 = vallocate(72LL);
v4 = vdevice[3];
*(_QWORD *)(v3 + 64) = v4;
result = (_DWORD *)copymatrix(v3, v4);
vdevice[3] = v3;
}
}
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
__int64 v0; // rdi
__int64 v1; // rsi
_DWORD *result; // rax
__int64 v3; // rbx
__int64 v4; // rsi

if ( BYTE2(vdevice[0]) )
{
result = (_DWORD *)newtokens(1LL);
*result = 26;
}
else
{
v0 = msfree;
if ( msfree )
{
v1 = vdevice[3];
vdevice[3] = msfree;
msfree = *(_QWORD *)(v0 + 64);
*(_QWORD *)(v0 + 64) = v1;
result = (_DWORD *)func1(v0, v1);
}
else
{
v3 = vallocate(72LL);
v4 = vdevice[3];
*(_QWORD *)(v3 + 64) = v4;
result = (_DWORD *)func1(v3, v4);
vdevice[3] = v3;
}
}
return result;
}

original_code:
void
pushmatrix(void)
{
 Mstack *tmpmat;
 Token *p;
 if (vdevice.inobject) {
  p = newtokens(1);
  p->i = 26;
  return;
 }
 if (msfree != (Mstack *)((void *)0)) {
  tmpmat = vdevice.transmat;
  vdevice.transmat = msfree;
  msfree = msfree->back;
  vdevice.transmat->back = tmpmat;
  copymatrix(vdevice.transmat->m, tmpmat->m);
 } else {
  tmpmat = (Mstack *)vallocate(sizeof(Mstack));
  tmpmat->back = vdevice.transmat;
  copymatrix(tmpmat->m, vdevice.transmat->m);
  vdevice.transmat = tmpmat;
 }
}

canonical_original_code:
void pushmatrix()
{
 struct ms *tmpmat;
 union tk *p;
 if (vdevice.inobject) {
  p = newtokens(1);
  p->i = 26;
  return;
 }
 if (msfree != (struct ms *)((void *)0)) {
  tmpmat = vdevice.transmat;
  vdevice.transmat = msfree;
  msfree = msfree->back;
  vdevice.transmat->back = tmpmat;
  copymatrix(vdevice.transmat->m, tmpmat->m);
 } else {
  tmpmat = (struct ms *)vallocate(sizeof(Mstack));
  tmpmat->back = vdevice.transmat;
  copymatrix(tmpmat->m, vdevice.transmat->m);
  vdevice.transmat = tmpmat;
 }
}

variable_types: struct ms { float m[4][4]; struct ms *back; } *


popmatrix

decompiled_code:
__int64 popmatrix()
{
__int64 result; // rax
__int64 v1; // rcx

if ( BYTE2(vdevice[0]) )
{
result = newtokens(1LL);
*(_DWORD *)result = 23;
}
else
{
result = vdevice[3];
v1 = *(_QWORD *)(result + 64);
if ( v1 )
{
vdevice[3] = v1;
*(_QWORD *)(result + 64) = msfree;
msfree = result;
BYTE5(vdevice[0]) = 0;
}
else
{
verror("popmatrix: matrix stack empty");
result = loadmatrix();
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // rcx

if ( BYTE2(vdevice[0]) )
{
result = newtokens(1LL);
*(_DWORD *)result = 23;
}
else
{
result = vdevice[3];
v1 = *(_QWORD *)(result + 64);
if ( v1 )
{
vdevice[3] = v1;
*(_QWORD *)(result + 64) = msfree;
msfree = result;
BYTE5(vdevice[0]) = 0;
}
else
{
verror("popmatrix: matrix stack empty");
result = loadmatrix();
}
}
return result;
}

original_code:
void
popmatrix(void)
{
 Token *p;
 Mstack *oldtop;
 if (vdevice.inobject) {
  p = newtokens(1);
  p->i = 23;
  return;
 }
 if (vdevice.transmat->back == (Mstack *)((void *)0))
  verror("popmatrix: matrix stack empty");
 else {
  oldtop = vdevice.transmat;
  vdevice.transmat = vdevice.transmat->back;
  oldtop->back = msfree;
  msfree = oldtop;
 }
 vdevice.cpVvalid = 0;
}

canonical_original_code:
void popmatrix()
{
 union tk *p;
 struct ms *oldtop;
 if (vdevice.inobject) {
  p = newtokens(1);
  p->i = 23;
  return;
 }
 if (vdevice.transmat->back == (struct ms *)((void *)0))
  verror("popmatrix: matrix stack empty");
 else {
  oldtop = vdevice.transmat;
  vdevice.transmat = vdevice.transmat->back;
  oldtop->back = msfree;
  msfree = oldtop;
 }
 vdevice.cpVvalid = 0;
}

user_defined_types: struct ms { float m[4][4]; struct ms *back; }


variable_types:
a
float (*)[4]

variable_types:
b
float (*)[4]

variable_types:
c
float (*)[4]


decompiled_code:
__int64 pclos_()
{
return pclos();
}

canonical_decompiled_code:
__int64 func38()
{
return pclos();
}

original_code:
void
pclos_()
{
 pclos();
}

canonical_original_code:
void pclos_()
{
 pclos();
}


deflinestyle

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

result = ls_table[(__int16)a1 % 11];
if ( result )
{
while ( *(_WORD *)result != (_WORD)a1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
goto LABEL_4;
}
if ( (_WORD)a1 )
{
*(_DWORD *)(result + 4) = (unsigned __int16)a2;
}
else
{
verror("vogl: deflinestyle can't redefine 0");
result = setlinestyle();
}
}
else
{
LABEL_4:
result = vallocate(16LL, a2, a1);
*(_WORD *)result = a1;
*(_DWORD *)(result + 4) = (unsigned __int16)a2;
*(_QWORD *)(result + 8) = ls_table[(__int16)a1 % 11];
ls_table[(__int16)a1 % 11] = result;
}
return result;
}

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

result = ls_table[(__int16)a1 % 11];
if ( result )
{
while ( *(_WORD *)result != (_WORD)a1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
goto LABEL_4;
}
if ( (_WORD)a1 )
{
*(_DWORD *)(result + 4) = (unsigned __int16)a2;
}
else
{
verror("vogl: deflinestyle can't redefine 0");
result = setlinestyle();
}
}
else
{
LABEL_4:
result = vallocate(16LL, a2, a1);
*(_WORD *)result = a1;
*(_DWORD *)(result + 4) = (unsigned __int16)a2;
*(_QWORD *)(result + 8) = ls_table[(__int16)a1 % 11];
ls_table[(__int16)a1 % 11] = result;
}
return result;
}

original_code:
void
deflinestyle(short int n, Linestyle ls)
{
 LT *l;
 for (l = ls_table[n % 11]; l != (LT *)((void *)0); l = l->next)
  if (l->n == n) {
   if (n == 0)
    verror("vogl: deflinestyle can't redefine 0");
   l->ls = ls;
   return;
  }
 l = (LT *)vallocate(sizeof(LT));
 l->n = n;
 l->ls = ls;
 l->next = ls_table[n % 11];
 ls_table[n % 11] = l;
}

canonical_original_code:
void deflinestyle(short n, unsigned short ls)
{
 struct l *l;
 for (l = ls_table[n % 11]; l != (struct l *)((void *)0); l = l->next)
  if (l->n == n) {
   if (n == 0)
    verror("vogl: deflinestyle can't redefine 0");
   l->ls = ls;
   return;
  }
 l = (struct l *)vallocate(sizeof(LT));
 l->n = n;
 l->ls = ls;
 l->next = ls_table[n % 11];
 ls_table[n % 11] = l;
}

variable_types: n short

variable_types:
ls
unsigned short

variable_types: struct l { short n; unsigned int ls; struct l *next; } *


decompiled_code:
__int64 gethei_()
{
return getheight();
}

canonical_decompiled_code:
__int64 func10()
{
return getheight();
}

original_code:
int
gethei_()
{
 return((int)getheight());
}


decompiled_code:
__int64 pushma_()
{
return pushmatrix();
}

canonical_decompiled_code:
__int64 func1()
{
return pushmatrix();
}

original_code:
void
pushma_()
{
 pushmatrix();
}

canonical_original_code:
void pushma_()
{
 pushmatrix();
}


decompiled_code:
__int64 popmat_()
{
return popmatrix();
}

canonical_decompiled_code:
__int64 func3()
{
return popmatrix();
}

original_code:
void
popmat_()
{
 popmatrix();
}

canonical_original_code:
void popmat_()
{
 popmatrix();
}


decompiled_code:
__int64 qtest_()
{
return qtest();
}

canonical_decompiled_code:
__int64 func5()
{
return qtest();
}

original_code:
int
qtest_()
{
 int ret = qtest();
 return(ret);
}

variable_types: ret int


decompiled_code:
__int64 qreset_()
{
return qreset();
}

canonical_decompiled_code:
__int64 func6()
{
return qreset();
}

original_code:
void
qreset_()
{
 qreset();
}

canonical_original_code:
void qreset_()
{
 qreset();
}


vallocate

decompiled_code:
void *__fastcall vallocate(size_t size)
{
void *result; // rax
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

result = malloc((unsigned int)size);
if ( !result )
{
sprintf(v2, "vallocate: request for %d bytes returned NULL", (unsigned int)size);
verror(v2);
JUMPOUT(0x37LL);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t size)
{
void *result; // rax
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

result = malloc((unsigned int)size);
if ( !result )
{
sprintf(v2, "vallocate: request for %d bytes returned NULL", (unsigned int)size);
verror(v2);
JUMPOUT(0x37LL);
}
return result;
}

original_code:
char *
vallocate(unsigned int size)
{
 char *p, buf[60];
 if ((p = (char *)malloc(size)) == (char *)0) {
  sprintf(buf,"vallocate: request for %d bytes returned NULL", size);
  verror(buf);
 }
 return (p);
}

canonical_original_code:
char *vallocate(unsigned int size)
{
 char *p; char buf[60];
 if ((p = (char *)malloc(size)) == (char *)0) {
  sprintf(buf,"vallocate: request for %d bytes returned NULL", size);
  verror(buf);
 }
 return (p);
}

variable_types:
size
unsigned int

variable_types:
p
char *

variable_types:
buf
char [60]

return_type: char *


decompiled_code:
__int64 closeo_()
{
return closeobj();
}

canonical_decompiled_code:
__int64 func3()
{
return closeobj();
}

original_code:
void
closeo_()
{
 closeobj();
}

canonical_original_code:
void closeo_()
{
 closeobj();
}


decompiled_code:
__int64 genobj_()
{
return genobj();
}

canonical_decompiled_code:
__int64 func5()
{
return genobj();
}

original_code:
int
genobj_()
{
 return(genobj());
}

canonical_original_code:
int genobj_()
{
 return(genobj());
}


decompiled_code:
__int64 getope_()
{
return getopenobj();
}

canonical_decompiled_code:
__int64 func7()
{
return getopenobj();
}

original_code:
int
getope_()
{
 return(getopenobj());
}

canonical_original_code:
int getope_()
{
 return(getopenobj());
}


repo: bert/fped

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

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

original_code:
void bitset_free(struct bitset *set)
{
 free(set->v);
 free(set);
}

variable_types: struct bitset { int v_n; unsigned int *v; } *


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

if ( a2 >= (unsigned __int64)(32LL * *a1) )
_assert_fail("n < set->v_n*BITS", "bitset.c", 0x41u, "bitset_set");
result = (unsigned __int64)a2 >> 5;
*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * result) |= 1 << a2;
return result;
}

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

if ( a2 >= (unsigned __int64)(32LL * *a1) )
_assert_fail("n < set->v_n*BITS", "bitset.c", 0x41u, "bitset_set");
result = (unsigned __int64)a2 >> 5;
*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * result) |= 1 << a2;
return result;
}

original_code:
void bitset_set(struct bitset *set, int n)
{
 ((void) sizeof ((n < set->v_n*(sizeof(unsigned)*8)) ? 1 : 0), __extension__ ({ if (n < set->v_n*(sizeof(unsigned)*8)) ; else __assert_fail ("n < set->v_n*BITS", "bitset.c", 65, __extension__ __PRETTY_FUNCTION__); }));
 set->v[n/(sizeof(unsigned)*8)] |= 1U << (n % (sizeof(unsigned)*8));
}

canonical_original_code:
void bitset_set(struct bitset *set, int n)
{
 ((void) sizeof ((n < set->v_n*(sizeof(unsigned int)*8)) ? 1 : 0), __extension__ ({ if (n < set->v_n*(sizeof(unsigned int)*8)) ; else __assert_fail ("n < set->v_n*BITS", "bitset.c", 65, __extension__ __PRETTY_FUNCTION__); }));
 set->v[n/(sizeof(unsigned int)*8)] |= 1U << (n % (sizeof(unsigned int)*8));
}

variable_types: n int

user_defined_types: struct bitset { int v_n; unsigned int *v; }


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

if ( a2 >= (unsigned __int64)(32LL * *a1) )
_assert_fail("n < set->v_n*BITS", "bitset.c", 0x48u, "bitset_clear");
result = (unsigned __int64)a2 >> 5;
*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * result) &= ~(1 << a2);
return result;
}

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

if ( a2 >= (unsigned __int64)(32LL * *a1) )
_assert_fail("n < set->v_n*BITS", "bitset.c", 0x48u, "bitset_clear");
result = (unsigned __int64)a2 >> 5;
*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * result) &= ~(1 << a2);
return result;
}

original_code:
void bitset_clear(struct bitset *set, int n)
{
 ((void) sizeof ((n < set->v_n*(sizeof(unsigned)*8)) ? 1 : 0), __extension__ ({ if (n < set->v_n*(sizeof(unsigned)*8)) ; else __assert_fail ("n < set->v_n*BITS", "bitset.c", 72, __extension__ __PRETTY_FUNCTION__); }));
 set->v[n/(sizeof(unsigned)*8)] &= ~(1U << (n % (sizeof(unsigned)*8)));
}

canonical_original_code:
void bitset_clear(struct bitset *set, int n)
{
 ((void) sizeof ((n < set->v_n*(sizeof(unsigned int)*8)) ? 1 : 0), __extension__ ({ if (n < set->v_n*(sizeof(unsigned int)*8)) ; else __assert_fail ("n < set->v_n*BITS", "bitset.c", 72, __extension__ __PRETTY_FUNCTION__); }));
 set->v[n/(sizeof(unsigned int)*8)] &= ~(1U << (n % (sizeof(unsigned int)*8)));
}


decompiled_code:
__int64 __fastcall bitset_pick(int *a1, int a2)
{
if ( a2 >= (unsigned __int64)(32LL * *a1) )
_assert_fail("n < set->v_n*BITS", "bitset.c", 0x4Fu, "bitset_pick");
return (*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * ((unsigned __int64)a2 >> 5)) >> a2) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, int a2)
{
if ( a2 >= (unsigned __int64)(32LL * *a1) )
_assert_fail("n < set->v_n*BITS", "bitset.c", 0x4Fu, "bitset_pick");
return (*(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * ((unsigned __int64)a2 >> 5)) >> a2) & 1;
}

original_code:
int bitset_pick(const struct bitset *set, int n)
{
 ((void) sizeof ((n < set->v_n*(sizeof(unsigned)*8)) ? 1 : 0), __extension__ ({ if (n < set->v_n*(sizeof(unsigned)*8)) ; else __assert_fail ("n < set->v_n*BITS", "bitset.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 return !!(set->v[n/(sizeof(unsigned)*8)] & (1U << (n % (sizeof(unsigned)*8))));
}

canonical_original_code:
int bitset_pick(struct bitset *set, int n)
{
 ((void) sizeof ((n < set->v_n*(sizeof(unsigned int)*8)) ? 1 : 0), __extension__ ({ if (n < set->v_n*(sizeof(unsigned int)*8)) ; else __assert_fail ("n < set->v_n*BITS", "bitset.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 return !!(set->v[n/(sizeof(unsigned int)*8)] & (1U << (n % (sizeof(unsigned int)*8))));
}


decompiled_code:
__int64 __fastcall bitset_is_empty(__int64 a1)
{
_DWORD *v1; // rax
__int64 v2; // rdx

if ( !*(_DWORD *)a1 )
return 1LL;
v1 = *(_DWORD **)(a1 + 8);
v2 = (__int64)&v1[*(_DWORD *)a1 - 1 + 1];
while ( !*v1 )
{
if ( ++v1 == (_DWORD *)v2 )
return 1LL;
}
return 0LL;
}

original_code:
int bitset_is_empty(const struct bitset *set)
{
 int i;
 for (i = 0; i != set->v_n; i++)
  if (set->v[i])
   return 0;
 return 1;
}

canonical_original_code:
int bitset_is_empty(struct bitset *set)
{
 int i;
 for (i = 0; i != set->v_n; i++)
  if (set->v[i])
   return 0;
 return 1;
}

variable_types: i int


decompiled_code:
void __fastcall bitset_zero(__int64 a1)
{
__int64 v1; // rax

if ( *(_DWORD *)a1 )
{
v1 = 0LL;
do
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * v1++) = 0;
while ( *(_DWORD *)a1 != (_DWORD)v1 );
}
}

original_code:
void bitset_zero(struct bitset *a)
{
 int i;
 for (i = 0; i != a->v_n; i++)
  a->v[i] = 0;
}


decompiled_code:
__int64 __fastcall bitset_and(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x6Cu, "bitset_and");
result = 0LL;
if ( *(_DWORD *)a1 )
{
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * result) &= *(_DWORD *)(*(_QWORD *)(a2 + 8) + 4 * result);
++result;
}
while ( *(_DWORD *)a1 != (_DWORD)result );
}
return result;
}

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

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x6Cu, "bitset_and");
result = 0LL;
if ( *(_DWORD *)a1 )
{
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * result) &= *(_DWORD *)(*(_QWORD *)(a2 + 8) + 4 * result);
++result;
}
while ( *(_DWORD *)a1 != (_DWORD)result );
}
return result;
}

original_code:
void bitset_and(struct bitset *a, const struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 108, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  a->v[i] &= b->v[i];
}

canonical_original_code:
void bitset_and(struct bitset *a, struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 108, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  a->v[i] &= b->v[i];
}

variable_types:
b
struct bitset *


decompiled_code:
__int64 __fastcall bitset_or(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x76u, "bitset_or");
result = 0LL;
if ( *(_DWORD *)a1 )
{
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * result) |= *(_DWORD *)(*(_QWORD *)(a2 + 8) + 4 * result);
++result;
}
while ( *(_DWORD *)a1 != (_DWORD)result );
}
return result;
}

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

if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x76u, "bitset_or");
result = 0LL;
if ( *(_DWORD *)a1 )
{
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4 * result) |= *(_DWORD *)(*(_QWORD *)(a2 + 8) + 4 * result);
++result;
}
while ( *(_DWORD *)a1 != (_DWORD)result );
}
return result;
}

original_code:
void bitset_or(struct bitset *a, const struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  a->v[i] |= b->v[i];
}

canonical_original_code:
void bitset_or(struct bitset *a, struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  a->v[i] |= b->v[i];
}


decompiled_code:
__int64 __fastcall bitset_ge(int *a1, __int64 a2)
{
int v2; // edx
__int64 v4; // rsi
__int64 v5; // rdi
__int64 i; // rdx

v2 = *a1;
if ( *a1 != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x80u, "bitset_ge");
if ( !v2 )
return 1LL;
v4 = *((_QWORD *)a1 + 1);
v5 = (unsigned int)(v2 - 1);
for ( i = 0LL; (*(_DWORD *)(*(_QWORD *)(a2 + 8) + 4 * i) & ~*(_DWORD *)(v4 + 4 * i)) == 0; ++i )
{
if ( i == v5 )
return 1LL;
}
return 0LL;
}

original_code:
int bitset_ge(const struct bitset *a, const struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 128, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  if (~a->v[i] & b->v[i])
   return 0;
 return 1;
}

canonical_original_code:
int bitset_ge(struct bitset *a, struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 128, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  if (~a->v[i] & b->v[i])
   return 0;
 return 1;
}


decompiled_code:
_BOOL8 __fastcall coord_eq(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

original_code:
static inline int coord_eq(struct coord a, struct coord b)
{
 return a.x == b.x && a.y == b.y;
}

variable_types:
a
struct coord { int x; }

variable_types:
b
struct coord


decompiled_code:
__int64 meas_highlight_b()
{
return inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

canonical_decompiled_code:
__int64 func2()
{
return inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

original_code:
static void meas_highlight_b(void)
{
 inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

canonical_original_code:
static void meas_highlight_b()
{
 inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}


decompiled_code:
__int64 meas_highlight_a()
{
return inst_highlight_vecs(meas_pick_vec_a, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return inst_highlight_vecs(meas_pick_vec_a, 0LL);
}

original_code:
static void meas_highlight_a(void)
{
 inst_highlight_vecs(meas_pick_vec_a, ((void *)0));
}

canonical_original_code:
static void meas_highlight_a()
{
 inst_highlight_vecs(meas_pick_vec_a, ((void *)0));
}


decompiled_code:
__int64 cancel_drag_new_meas()
{
meas_inst = 0LL;
highlight = 0LL;
return redraw();
}

canonical_decompiled_code:
__int64 func12()
{
meas_inst = 0LL;
highlight = 0LL;
return redraw();
}

original_code:
static void cancel_drag_new_meas(void)
{
 meas_inst = ((void *)0);
 highlight = ((void *)0);
 redraw();
}

canonical_original_code:
static void cancel_drag_new_meas()
{
 meas_inst = ((void *)0);
 highlight = ((void *)0);
 redraw();
}


decompiled_code:
__int64 tool_deselected_meas()
{
highlight = 0LL;
return redraw();
}

canonical_decompiled_code:
__int64 func14()
{
highlight = 0LL;
return redraw();
}

original_code:
static void tool_deselected_meas(void)
{
 highlight = ((void *)0);
 redraw();
}

canonical_original_code:
static void tool_deselected_meas()
{
 highlight = ((void *)0);
 redraw();
}


decompiled_code:
__int64 tool_selected_meas()
{
highlight = meas_highlight_a;
return redraw();
}

canonical_decompiled_code:
__int64 func15()
{
highlight = meas_highlight_a;
return redraw();
}

original_code:
static void tool_selected_meas(void)
{
 highlight = meas_highlight_a;
 redraw();
}

canonical_original_code:
static void tool_selected_meas()
{
 highlight = meas_highlight_a;
 redraw();
}


decompiled_code:
__int64 tool_selected_meas_xy()
{
meas_dsc = (__int64)&meas_dsc_xy;
return tool_selected_meas();
}

canonical_decompiled_code:
__int64 func16()
{
meas_dsc = (__int64)&meas_dsc_xy;
return func15();
}

original_code:
static void tool_selected_meas_xy(void)
{
 meas_dsc = &meas_dsc_xy;
 tool_selected_meas();
}

canonical_original_code:
static void tool_selected_meas_xy()
{
 meas_dsc = &meas_dsc_xy;
 tool_selected_meas();
}


decompiled_code:
__int64 tool_selected_meas_x()
{
meas_dsc = (__int64)&meas_dsc_x;
return tool_selected_meas();
}

canonical_decompiled_code:
__int64 func17()
{
meas_dsc = (__int64)&meas_dsc_x;
return func15();
}

original_code:
static void tool_selected_meas_x(void)
{
 meas_dsc = &meas_dsc_x;
 tool_selected_meas();
}

canonical_original_code:
static void tool_selected_meas_x()
{
 meas_dsc = &meas_dsc_x;
 tool_selected_meas();
}


decompiled_code:
__int64 tool_selected_meas_y()
{
meas_dsc = (__int64)&meas_dsc_y;
return tool_selected_meas();
}

canonical_decompiled_code:
__int64 func18()
{
meas_dsc = (__int64)&meas_dsc_y;
return func15();
}

original_code:
static void tool_selected_meas_y(void)
{
 meas_dsc = &meas_dsc_y;
 tool_selected_meas();
}

canonical_original_code:
static void tool_selected_meas_y()
{
 meas_dsc = &meas_dsc_y;
 tool_selected_meas();
}


decompiled_code:
__int64 end_drag_move_meas()
{
highlight = 0LL;
return redraw();
}

canonical_decompiled_code:
__int64 func23()
{
highlight = 0LL;
return redraw();
}

original_code:
void end_drag_move_meas(void)
{
 highlight = ((void *)0);
 redraw();
}

canonical_original_code:
void end_drag_move_meas()
{
 highlight = ((void *)0);
 redraw();
}


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

result = over_D_save_and_draw(over_D_user, over_pos);
buf_D = result;
return result;
}

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

result = over_D_save_and_draw(over_D_user, over_pos);
buf_D = result;
return result;
}

original_code:
static void draw_D(void)
{
 buf_D = over_D_save_and_draw(over_D_user, over_pos);
 ;
}

canonical_original_code:
static void draw_D()
{
 buf_D = over_D_save_and_draw(over_D_user, over_pos);
 ;
}


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

result = over_H_save_and_draw(over_H_user);
buf_H = result;
return result;
}

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

result = over_H_save_and_draw(over_H_user);
buf_H = result;
return result;
}

original_code:
static void draw_H(void)
{
 buf_H = over_H_save_and_draw(over_H_user);
 ;
}

canonical_original_code:
static void draw_H()
{
 buf_H = over_H_save_and_draw(over_H_user);
 ;
}


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

if ( state == 1 )
{
result = restore_pix_buf(buf_H);
state = 0;
}
else
{
if ( state != 3 )
abort();
restore_pix_buf(buf_D);
restore_pix_buf(buf_H);
result = draw_D();
state = 2;
}
return result;
}

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

if ( state == 1 )
{
result = restore_pix_buf(buf_H);
state = 0;
}
else
{
if ( state != 3 )
abort();
restore_pix_buf(buf_D);
restore_pix_buf(buf_H);
result = func0();
state = 2;
}
return result;
}

original_code:
void over_leave(void)
{
 ;
 switch (state) {
 case HOVER:
  ; restore_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; restore_pix_buf(buf_H);
  ;
  ; draw_D();
  ; state = DRAG; break;;
 default:
  abort();
 }
}

canonical_original_code:
void over_leave()
{
 ;
 switch (state) {
 case HOVER:
  ; restore_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; restore_pix_buf(buf_H);
  ;
  ; draw_D();
  ; state = DRAG; break;;
 default:
  abort();
 }
}


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

over_pos = a1;
result = (unsigned int)state;
if ( state == 2 )
{
restore_pix_buf(buf_D);
over_pos = a1;
result = draw_D();
state = 2;
}
else if ( (unsigned int)state > 2 )
{
if ( state != 3 )
abort();
restore_pix_buf(buf_D);
over_pos = a1;
result = draw_D();
state = 3;
}
return result;
}

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

over_pos = a1;
result = (unsigned int)state;
if ( state == 2 )
{
restore_pix_buf(buf_D);
over_pos = a1;
result = func0();
state = 2;
}
else if ( (unsigned int)state > 2 )
{
if ( state != 3 )
abort();
restore_pix_buf(buf_D);
over_pos = a1;
result = func0();
state = 3;
}
return result;
}

original_code:
void over_move(struct coord pos)
{
 over_pos = pos;
 ;
 switch (state) {
 case NOTHING:
  break;
 case HOVER:
  break;
 case DRAG:
  ; restore_pix_buf(buf_D);
  ; over_pos = pos;
  ;
  ; draw_D();
  ; state = DRAG; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; over_pos = pos;
  ;
  ; draw_D();
  ; state = BOTH; break;;
 default:
  abort();
 }
}

variable_types:
pos
struct coord { int x; }


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

if ( state == 2 )
{
result = restore_pix_buf(buf_D);
state = 0;
}
else
{
if ( state != 3 )
abort();
result = restore_pix_buf(buf_D);
state = 1;
}
return result;
}

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

if ( state == 2 )
{
result = restore_pix_buf(buf_D);
state = 0;
}
else
{
if ( state != 3 )
abort();
result = restore_pix_buf(buf_D);
state = 1;
}
return result;
}

original_code:
void over_end(void)
{
 ;
 switch (state) {
 case DRAG:
  ; restore_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; state = HOVER; break;;
 default:
  abort();
 }
}

canonical_original_code:
void over_end()
{
 ;
 switch (state) {
 case DRAG:
  ; restore_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; state = HOVER; break;;
 default:
  abort();
 }
}


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

result = (unsigned int)state;
if ( state == 2 )
{
result = free_pix_buf(buf_D);
state = 0;
}
else if ( (unsigned int)state > 2 )
{
if ( state != 3 )
abort();
free_pix_buf(buf_D);
result = free_pix_buf(buf_H);
state = 0;
}
else if ( state )
{
result = free_pix_buf(buf_H);
state = 0;
}
return result;
}

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

result = (unsigned int)state;
if ( state == 2 )
{
result = free_pix_buf(buf_D);
state = 0;
}
else if ( (unsigned int)state > 2 )
{
if ( state != 3 )
abort();
free_pix_buf(buf_D);
result = free_pix_buf(buf_H);
state = 0;
}
else if ( state )
{
result = free_pix_buf(buf_H);
state = 0;
}
return result;
}

original_code:
void over_reset(void)
{
 ;
 switch (state) {
 case NOTHING:
  break;
 case HOVER:
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case DRAG:
  ; free_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; free_pix_buf(buf_D);
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 default:
  abort();
 }
}

canonical_original_code:
void over_reset()
{
 ;
 switch (state) {
 case NOTHING:
  break;
 case HOVER:
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case DRAG:
  ; free_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; free_pix_buf(buf_D);
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 default:
  abort();
 }
}


decompiled_code:
char *__fastcall stralloc_vprintf(char *format, __gnuc_va_list arg)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // rbp
__m128i arga; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

arga = _mm_loadu_si128((const __m128i *)arg);
v7 = *((_QWORD *)arg + 2);
v2 = vsnprintf(0LL, 0LL, format, &arga) + 1;
v3 = (char *)malloc(v2);
if ( !v3 )
abort();
v4 = v3;
vsnprintf(v3, v2, format, arg);
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *format, __gnuc_va_list arg)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // rbp
__m128i arga; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

arga = _mm_loadu_si128((const __m128i *)arg);
v7 = *((_QWORD *)arg + 2);
v2 = vsnprintf(0LL, 0LL, format, &arga) + 1;
v3 = (char *)malloc(v2);
if ( !v3 )
abort();
v4 = v3;
vsnprintf(v3, v2, format, arg);
return v4;
}

original_code:
char *stralloc_vprintf(const char *fmt, va_list ap)
{
 va_list aq;
 char *buf;
 int n;
 __builtin_va_copy(aq,ap);
 n = vsnprintf(((void *)0), 0, fmt, aq);
 __builtin_va_end(aq);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 vsnprintf(buf, n+1, fmt, ap);
 return buf;
}

canonical_original_code:
char *stralloc_vprintf(char *fmt, __builtin_va_list ap)
{
 __builtin_va_list aq;
 char *buf;
 int n;
 __builtin_va_copy(aq,ap);
 n = vsnprintf(((void *)0), 0, fmt, aq);
 __builtin_va_end(aq);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 vsnprintf(buf, n+1, fmt, ap);
 return buf;
}

variable_types:
fmt
char *

variable_types:
buf
char *


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

va_start(arg, a1);
return stralloc_vprintf(a1, arg);
}

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

va_start(arg, a1);
return func0(a1, arg);
}

original_code:
char *stralloc_printf(const char *fmt, ...)
{
 va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 return s;
}

canonical_original_code:
char *stralloc_printf(char *fmt, ...)
{
 __builtin_va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 return s;
}

variable_types:
s
char *


decompiled_code:
_BOOL8 __fastcall is_id_char(char a1, int a2)
{
_BOOL8 result; // rax

if ( (unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u || a1 == 95 )
return 1LL;
result = 0LL;
if ( !a2 )
result = (unsigned __int8)(a1 - 48) <= 9u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char a1, int a2)
{
_BOOL8 result; // rax

if ( (unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u || a1 == 95 )
return 1LL;
result = 0LL;
if ( !a2 )
result = (unsigned __int8)(a1 - 48) <= 9u;
return result;
}

original_code:
int is_id_char(char c, int first)
{
 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
  return 1;
 if (first)
  return 0;
 return c >= '0' && c <= '9';
}

variable_types: c char

variable_types: first int


decompiled_code:
_BOOL8 __fastcall is_id(char *a1)
{
char v2; // di
_BOOL8 result; // rax
char *v4; // rbx

v2 = *a1;
result = 0LL;
if ( v2 )
{
v4 = a1;
while ( 1 )
{
result = is_id_char(v2, a1 == v4);
if ( !result )
break;
v2 = *++v4;
if ( !*v4 )
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *a1)
{
char v2; // di
_BOOL8 result; // rax
char *v4; // rbx

v2 = *a1;
result = 0LL;
if ( v2 )
{
v4 = a1;
while ( 1 )
{
result = func2(v2, a1 == v4);
if ( !result )
break;
v2 = *++v4;
if ( !*v4 )
return 1LL;
}
}
return result;
}

original_code:
int is_id(const char *s)
{
 const char *p;
 if (!*s)
  return 0;
 for (p = s; *p; p++)
  if (!is_id_char(*p, s == p))
   return 0;
 return 1;
}

canonical_original_code:
int is_id(char *s)
{
 char *p;
 if (!*s)
  return 0;
 for (p = s; *p; p++)
  if (!is_id_char(*p, s == p))
   return 0;
 return 1;
}


unique

decompiled_code:
const char *__fastcall unique(char *s)
{
char *v1; // rbx
void **v2; // rbx
const char *v3; // rbp
char **v4; // rax
char **v5; // rbp
char *v6; // rax

v1 = (char *)uniques;
if ( uniques )
{
while ( 1 )
{
v3 = *(const char **)v1;
if ( !strcmp(s, *(const char **)v1) )
break;
if ( !*((_QWORD *)v1 + 1) )
{
v2 = (void **)(v1 + 8);
goto LABEL_7;
}
v1 = (char *)*((_QWORD *)v1 + 1);
}
}
else
{
v2 = &uniques;
LABEL_7:
v4 = (char **)malloc(0x10uLL);
v5 = v4;
if ( !v4 )
abort();
*v2 = v4;
v6 = strdup(s);
if ( !v6 )
abort();
*v5 = v6;
*((_QWORD *)*v2 + 1) = 0LL;
v3 = *(const char **)*v2;
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func4(char *s)
{
char *v1; // rbx
void **v2; // rbx
const char *v3; // rbp
char **v4; // rax
char **v5; // rbp
char *v6; // rax

v1 = (char *)uniques;
if ( uniques )
{
while ( 1 )
{
v3 = *(const char **)v1;
if ( !strcmp(s, *(const char **)v1) )
break;
if ( !*((_QWORD *)v1 + 1) )
{
v2 = (void **)(v1 + 8);
goto LABEL_7;
}
v1 = (char *)*((_QWORD *)v1 + 1);
}
}
else
{
v2 = &uniques;
LABEL_7:
v4 = (char **)malloc(0x10uLL);
v5 = v4;
if ( !v4 )
abort();
*v2 = v4;
v6 = strdup(s);
if ( !v6 )
abort();
*v5 = v6;
*((_QWORD *)*v2 + 1) = 0LL;
v3 = *(const char **)*v2;
}
return v3;
}

original_code:
const char *unique(const char *s)
{
 struct unique **walk;
 for (walk = &uniques; *walk; walk = &(*walk)->next)
  if (!strcmp(s, (*walk)->s))
   return (*walk)->s;
 *walk = ((struct unique *) ({ void *alloc_size_tmp = malloc(sizeof(struct unique)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 (*walk)->s = ({ char *stralloc_tmp = strdup(s); if (!stralloc_tmp) abort(); stralloc_tmp; });
 (*walk)->next = ((void *)0);
 return (*walk)->s;
}

canonical_original_code:
char *unique(char *s)
{
 struct unique **walk;
 for (walk = &uniques; *walk; walk = &(*walk)->next)
  if (!strcmp(s, (*walk)->s))
   return (*walk)->s;
 *walk = ((struct unique *) ({ void *alloc_size_tmp = malloc(sizeof(struct unique)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 (*walk)->s = ({ char *stralloc_tmp = strdup(s); if (!stralloc_tmp) abort(); stralloc_tmp; });
 (*walk)->next = ((void *)0);
 return (*walk)->s;
}

variable_types: struct unique { char *s; struct unique *next; } **


decompiled_code:
void unique_cleanup()
{
void **v0; // rbx
void **v1; // rax

v0 = (void **)uniques;
if ( uniques )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(uniques);
uniques = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func5()
{
void **v0; // rbx
void **v1; // rax

v0 = (void **)uniques;
if ( uniques )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(uniques);
uniques = v0;
}
while ( v0 );
}
}

original_code:
void unique_cleanup(void)
{
 struct unique *next;
 while (uniques) {
  next = uniques->next;
  free(uniques->s);
  free(uniques);
  uniques = next;
 }
}

canonical_original_code:
void unique_cleanup()
{
 struct unique *next;
 while (uniques) {
  next = uniques->next;
  free(uniques->s);
  free(uniques);
  uniques = next;
 }
}

variable_types: struct unique { char *s; struct unique *next; } *


decompiled_code:
void kill_cpp(void)
{
if ( cpp_pid )
kill(cpp_pid, 15);
}

canonical_decompiled_code:
void func0(void)
{
if ( cpp_pid )
kill(cpp_pid, 15);
}

original_code:
static void kill_cpp(void)
{
    if (cpp_pid)
 (void) kill(cpp_pid,15);
}

canonical_original_code:
static void kill_cpp()
{
    if (cpp_pid)
 (void) kill(cpp_pid,15);
}


decompiled_code:
char **__fastcall add_cpp_arg(char *s)
{
char *v1; // rbx
int v2; // ebp
char **v3; // r12
int v4; // er13
char **result; // rax

v1 = s;
v2 = cpp_argc;
if ( cpp_argc )
{
v4 = cpp_argc + 1;
result = (char **)realloc(cpp_argv, 8LL * (cpp_argc + 1));
v3 = result;
cpp_argv = result;
if ( result )
{
if ( v2 != 1 )
goto LABEL_7;
goto LABEL_4;
}
LABEL_10:
perror("realloc");
exit(1);
}
cpp_argc = 1;
v3 = (char **)realloc(cpp_argv, 0x10uLL);
cpp_argv = v3;
if ( !v3 )
goto LABEL_10;
v4 = 2;
v2 = 1;
LABEL_4:
result = (char **)cpp_command;
*v3 = cpp_command;
LABEL_7:
if ( s )
{
result = (char **)strdup(s);
v1 = (char *)result;
if ( !result )
{
perror("strdup");
exit(1);
}
}
cpp_argc = v4;
v3[v2] = v1;
return result;
}

canonical_decompiled_code:
char **__fastcall func1(char *s)
{
char *v1; // rbx
int v2; // ebp
char **v3; // r12
int v4; // er13
char **result; // rax

v1 = s;
v2 = cpp_argc;
if ( cpp_argc )
{
v4 = cpp_argc + 1;
result = (char **)realloc(cpp_argv, 8LL * (cpp_argc + 1));
v3 = result;
cpp_argv = result;
if ( result )
{
if ( v2 != 1 )
goto LABEL_7;
goto LABEL_4;
}
LABEL_10:
perror("realloc");
exit(1);
}
cpp_argc = 1;
v3 = (char **)realloc(cpp_argv, 0x10uLL);
cpp_argv = v3;
if ( !v3 )
goto LABEL_10;
v4 = 2;
v2 = 1;
LABEL_4:
result = (char **)cpp_command;
*v3 = cpp_command;
LABEL_7:
if ( s )
{
result = (char **)strdup(s);
v1 = (char *)result;
if ( !result )
{
perror("strdup");
exit(1);
}
}
cpp_argc = v4;
v3[v2] = v1;
return result;
}

original_code:
void add_cpp_arg(const char *arg)
{
    if (!cpp_argc)
 cpp_argc = 1;
    cpp_argv = realloc(cpp_argv,sizeof(const char *)*(cpp_argc+1));
    if (!cpp_argv) {
 perror("realloc");
 exit(1);
    }
    if (cpp_argc == 1)
 cpp_argv[0] = cpp_command;
    if (arg) {
 arg = strdup(arg);
 if (!arg) {
     perror("strdup");
     exit(1);
 }
    }
    cpp_argv[cpp_argc++] = arg;
}

canonical_original_code:
void add_cpp_arg(char *arg)
{
    if (!cpp_argc)
 cpp_argc = 1;
    cpp_argv = realloc(cpp_argv,sizeof(char *)*(cpp_argc+1));
    if (!cpp_argv) {
 perror("realloc");
 exit(1);
    }
    if (cpp_argc == 1)
 cpp_argv[0] = cpp_command;
    if (arg) {
 arg = strdup(arg);
 if (!arg) {
     perror("strdup");
     exit(1);
 }
    }
    cpp_argv[cpp_argc++] = arg;
}

variable_types:
arg
char *


decompiled_code:
void __fastcall run_cpp(char *s, int fd, int a3)
{
__pid_t v4; // eax
char **v5; // rbp
char **v6; // rbx
char *v7; // rdi
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
if ( s )
add_cpp_arg(s);
add_cpp_arg(0LL);
v4 = fork();
cpp_pid = v4;
if ( v4 < 0 )
{
perror("fork");
exit(1);
}
if ( !v4 )
{
if ( close(pipedes[0]) < 0 )
{
perror("close");
exit(1);
}
if ( a3 != -1 && close(a3) < 0 )
{
perror("close");
exit(1);
}
if ( fd != -1 && dup2(fd, 0) < 0 )
{
perror("dup2");
exit(1);
}
if ( dup2(pipedes[1], 1) < 0 )
{
perror("dup2");
exit(1);
}
if ( execvp(cpp_command, cpp_argv) < 0 )
{
perror(cpp_command);
exit(1);
}
}
if ( close(pipedes[1]) < 0 )
{
perror("close");
exit(1);
}
real_stdin = dup(0);
if ( real_stdin < 0 )
{
perror("dup");
exit(1);
}
if ( fd != -1 && close(fd) < 0 )
{
perror("close");
exit(1);
}
if ( dup2(pipedes[0], 0) < 0 )
{
perror("dup2");
exit(1);
}
v5 = cpp_argv;
v6 = cpp_argv + 1;
v7 = cpp_argv[1];
if ( v7 )
{
do
{
free(v7);
v7 = *++v6;
}
while ( *v6 );
}
free(v5);
cpp_argv = 0LL;
cpp_argc = 0;
}

canonical_decompiled_code:
void __fastcall func2(char *s, int fd, int a3)
{
__pid_t v4; // eax
char **v5; // rbp
char **v6; // rbx
char *v7; // rdi
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
if ( s )
func1(s);
func1(0LL);
v4 = fork();
cpp_pid = v4;
if ( v4 < 0 )
{
perror("fork");
exit(1);
}
if ( !v4 )
{
if ( close(pipedes[0]) < 0 )
{
perror("close");
exit(1);
}
if ( a3 != -1 && close(a3) < 0 )
{
perror("close");
exit(1);
}
if ( fd != -1 && dup2(fd, 0) < 0 )
{
perror("dup2");
exit(1);
}
if ( dup2(pipedes[1], 1) < 0 )
{
perror("dup2");
exit(1);
}
if ( execvp(cpp_command, cpp_argv) < 0 )
{
perror(cpp_command);
exit(1);
}
}
if ( close(pipedes[1]) < 0 )
{
perror("close");
exit(1);
}
real_stdin = dup(0);
if ( real_stdin < 0 )
{
perror("dup");
exit(1);
}
if ( fd != -1 && close(fd) < 0 )
{
perror("close");
exit(1);
}
if ( dup2(pipedes[0], 0) < 0 )
{
perror("dup2");
exit(1);
}
v5 = cpp_argv;
v6 = cpp_argv + 1;
v7 = cpp_argv[1];
if ( v7 )
{
do
{
free(v7);
v7 = *++v6;
}
while ( *v6 );
}
free(v5);
cpp_argv = 0LL;
cpp_argc = 0;
}

original_code:
static void run_cpp(const char *name,int fd,int close_fd)
{
    char **arg;
    int fds[2];
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    if (name)
 add_cpp_arg(name);
    add_cpp_arg(((void *)0));
    cpp_pid = fork();
    if (cpp_pid < 0) {
        perror("fork");
        exit(1);
    }
    if (!cpp_pid) {
 if (close(fds[0]) < 0) {
     perror("close");
     exit(1);
 }
 if (close_fd != -1 && close(close_fd) < 0) {
     perror("close");
     exit(1);
 }
 if (fd != -1 && dup2(fd,0) < 0) {
     perror("dup2");
     exit(1);
 }
 if (dup2(fds[1],1) < 0) {
     perror("dup2");
     exit(1);
 }
 if (execvp(cpp_command,(char **) cpp_argv) < 0) {
     perror(cpp_command);
     exit(1);
 }
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    real_stdin = dup(0);
    if (real_stdin < 0) {
 perror("dup");
 exit(1);
    }
    if (fd != -1 && close(fd) < 0) {
 perror("close");
 exit(1);
    }
    if (dup2(fds[0],0) < 0) {
 perror("dup2");
 exit(1);
    }
    for (arg = (char **) cpp_argv+1; *arg; arg++)
 free(*arg);
    free(cpp_argv);
    cpp_argv = ((void *)0);
    cpp_argc = 0;
}

canonical_original_code:
static void run_cpp(char *name, int fd, int close_fd)
{
    char **arg;
    int fds[2];
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    if (name)
 add_cpp_arg(name);
    add_cpp_arg(((void *)0));
    cpp_pid = fork();
    if (cpp_pid < 0) {
        perror("fork");
        exit(1);
    }
    if (!cpp_pid) {
 if (close(fds[0]) < 0) {
     perror("close");
     exit(1);
 }
 if (close_fd != -1 && close(close_fd) < 0) {
     perror("close");
     exit(1);
 }
 if (fd != -1 && dup2(fd,0) < 0) {
     perror("dup2");
     exit(1);
 }
 if (dup2(fds[1],1) < 0) {
     perror("dup2");
     exit(1);
 }
 if (execvp(cpp_command,(char **) cpp_argv) < 0) {
     perror(cpp_command);
     exit(1);
 }
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    real_stdin = dup(0);
    if (real_stdin < 0) {
 perror("dup");
 exit(1);
    }
    if (fd != -1 && close(fd) < 0) {
 perror("close");
 exit(1);
    }
    if (dup2(fds[0],0) < 0) {
 perror("dup2");
 exit(1);
    }
    for (arg = (char **) cpp_argv+1; *arg; arg++)
 free(*arg);
    free(cpp_argv);
    cpp_argv = ((void *)0);
    cpp_argc = 0;
}

variable_types:
name
char *

variable_types: fd int

variable_types:
arg
char **

variable_types:
fds
int [2]


decompiled_code:
void __fastcall add_cpp_Wp(const char *a1)
{
char *v1; // rax
char *v2; // r12
char *i; // rbx
char *v4; // rbp
char *v5; // rax

v1 = strdup(a1);
if ( !v1 )
{
perror("strdup");
exit(1);
}
v2 = v1;
for ( i = v1; ; i = v4 )
{
v5 = strchr(i, 44);
if ( !v5 )
break;
v4 = v5 + 1;
*v5 = 0;
add_cpp_arg(i);
}
add_cpp_arg(i);
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(const char *a1)
{
char *v1; // rax
char *v2; // r12
char *i; // rbx
char *v4; // rbp
char *v5; // rax

v1 = strdup(a1);
if ( !v1 )
{
perror("strdup");
exit(1);
}
v2 = v1;
for ( i = v1; ; i = v4 )
{
v5 = strchr(i, 44);
if ( !v5 )
break;
v4 = v5 + 1;
*v5 = 0;
func1(i);
}
func1(i);
free(v2);
}

original_code:
void add_cpp_Wp(const char *arg)
{
    char *tmp = strdup(arg);
    char *curr,*end;
    if (!tmp) {
 perror("strdup");
 exit(1);
    }
    curr = tmp;
    do {
 end = strchr(curr,',');
 if (end)
     *end++ = 0;
 add_cpp_arg(curr);
 curr = end;
    }
    while (end);
    free(tmp);
}

canonical_original_code:
void add_cpp_Wp(char *arg)
{
    char *tmp = strdup(arg);
    char *curr; char *end;
    if (!tmp) {
 perror("strdup");
 exit(1);
    }
    curr = tmp;
    do {
 end = strchr(curr,',');
 if (end)
     *end++ = 0;
 add_cpp_arg(curr);
 curr = end;
    }
    while (end);
    free(tmp);
}

variable_types:
tmp
char *

variable_types:
curr
char *

variable_types:
end
char *


decompiled_code:
int __fastcall run_cpp_on_file(char *a1)
{
run_cpp(a1, -(a1 != 0LL), -1);
return atexit(kill_cpp);
}

canonical_decompiled_code:
int __fastcall func4(char *a1)
{
func2(a1, -(a1 != 0LL), -1);
return atexit(kill_cpp);
}

original_code:
void run_cpp_on_file(const char *name)
{
    run_cpp(name,name ? -1 : 0,-1);
    atexit(kill_cpp);
}

canonical_original_code:
void run_cpp_on_file(char *name)
{
    run_cpp(name,name ? -1 : 0,-1);
    atexit(kill_cpp);
}


decompiled_code:
int __fastcall run_cpp_on_string(void *buf)
{
char *v1; // rbp
__pid_t v2; // eax
int i; // ebx
int v4; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)buf;
if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
run_cpp(0LL, pipedes[0], pipedes[1]);
v2 = fork();
if ( v2 < 0 )
{
perror("fork");
exit(1);
}
if ( !v2 )
{
for ( i = strlen((const char *)buf); i; i -= v4 )
{
v4 = write(pipedes[1], v1, i);
if ( v4 < 0 )
break;
v1 += v4;
}
exit(0);
}
if ( close(pipedes[1]) < 0 )
{
perror("close");
exit(1);
}
return atexit(kill_cpp);
}

canonical_decompiled_code:
int __fastcall func5(void *buf)
{
char *v1; // rbp
__pid_t v2; // eax
int i; // ebx
int v4; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)buf;
if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
func2(0LL, pipedes[0], pipedes[1]);
v2 = fork();
if ( v2 < 0 )
{
perror("fork");
exit(1);
}
if ( !v2 )
{
for ( i = strlen((const char *)buf); i; i -= v4 )
{
v4 = write(pipedes[1], v1, i);
if ( v4 < 0 )
break;
v1 += v4;
}
exit(0);
}
if ( close(pipedes[1]) < 0 )
{
perror("close");
exit(1);
}
return atexit(kill_cpp);
}

original_code:
void run_cpp_on_string(const char *str)
{
    int fds[2];
    pid_t pid;
    int left,wrote;
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    run_cpp(((void *)0),fds[0],fds[1]);
    pid = fork();
    if (pid < 0) {
 perror("fork");
 exit(1);
    }
    if (!pid) {
 for (left = strlen(str); left; left -= wrote) {
     wrote = write(fds[1],str,left);
     if (wrote < 0)
  break;
     str += wrote;
 }
 exit(0);
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    atexit(kill_cpp);
}

canonical_original_code:
void run_cpp_on_string(char *str)
{
    int fds[2];
    int pid;
    int left; int wrote;
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    run_cpp(((void *)0),fds[0],fds[1]);
    pid = fork();
    if (pid < 0) {
 perror("fork");
 exit(1);
    }
    if (!pid) {
 for (left = strlen(str); left; left -= wrote) {
     wrote = write(fds[1],str,left);
     if (wrote < 0)
  break;
     str += wrote;
 }
 exit(0);
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    atexit(kill_cpp);
}

variable_types:
str
char *

variable_types: pid int

variable_types: left int

variable_types: wrote int


decompiled_code:
int reap_cpp()
{
int result; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

cpp_pid = 0;
if ( waitpid(0, &stat_loc, 0) < 0 )
{
perror("waitpid");
exit(1);
}
if ( stat_loc )
{
if ( (stat_loc & 0x7F) != 0 )
{
if ( __OFSUB__((stat_loc & 0x7F) + 1, 1) || (stat_loc & 0x7F) == 0 )
fprintf(stderr, "cpp terminated with incomprehensible status %d\n", (unsigned int)stat_loc);
else
fprintf(stderr, "cpp terminated with signal %d\n", stat_loc & 0x7F);
exit(1);
}
exit(BYTE1(stat_loc));
}
result = dup2(real_stdin, 0);
if ( result < 0 )
{
perror("dup2");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

cpp_pid = 0;
if ( waitpid(0, &stat_loc, 0) < 0 )
{
perror("waitpid");
exit(1);
}
if ( stat_loc )
{
if ( (stat_loc & 0x7F) != 0 )
{
if ( __OFSUB__((stat_loc & 0x7F) + 1, 1) || (stat_loc & 0x7F) == 0 )
fprintf(stderr, "cpp terminated with incomprehensible status %d\n", (unsigned int)stat_loc);
else
fprintf(stderr, "cpp terminated with signal %d\n", stat_loc & 0x7F);
exit(1);
}
exit(BYTE1(stat_loc));
}
result = dup2(real_stdin, 0);
if ( result < 0 )
{
perror("dup2");
exit(1);
}
return result;
}

original_code:
void reap_cpp(void)
{
    int status;
    cpp_pid = 0;
    if (waitpid(cpp_pid,&status,0) < 0) {
 perror("waitpid");
 exit(1);
    }
    if (!status) {
 if (dup2(real_stdin,0) < 0) {
     perror("dup2");
     exit(1);
 }
 return;
    }
    if ((((status) & 0x7f) == 0))
 exit((((status) & 0xff00) >> 8));
    if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0))
 fprintf(stderr,"cpp terminated with signal %d\n",((status) & 0x7f));
    else
 fprintf(stderr,"cpp terminated with incomprehensible status %d\n",
   status);
    exit(1);
}

canonical_original_code:
void reap_cpp()
{
    int status;
    cpp_pid = 0;
    if (waitpid(cpp_pid,&status,0) < 0) {
 perror("waitpid");
 exit(1);
    }
    if (!status) {
 if (dup2(real_stdin,0) < 0) {
     perror("dup2");
     exit(1);
 }
 return;
    }
    if ((((status) & 0x7f) == 0))
 exit((((status) & 0xff00) >> 8));
    if ((((char) (((status) & 0x7f) + 1) >> 1) > 0))
 fprintf(stderr,"cpp terminated with signal %d\n",((status) & 0x7f));
    else
 fprintf(stderr,"cpp terminated with incomprehensible status %d\n",
   status);
    exit(1);
}

variable_types: status int


decompiled_code:
char *__fastcall merge3(void *ptr, char *s, void *a3)
{
size_t v4; // r14
size_t v5; // rbx
size_t v6; // rax
char *v7; // rax
char *v8; // rbx

v4 = strlen(s);
v5 = strlen((const char *)ptr);
v6 = strlen((const char *)a3);
v7 = (char *)malloc(v6 + v4 + v5 + 1);
if ( !v7 )
abort();
v8 = v7;
sprintf(v7, "%s%s%s", (const char *)ptr, s, (const char *)a3);
free(ptr);
free(a3);
return v8;
}

canonical_decompiled_code:
char *__fastcall func2(void *ptr, char *s, void *a3)
{
size_t v4; // r14
size_t v5; // rbx
size_t v6; // rax
char *v7; // rax
char *v8; // rbx

v4 = strlen(s);
v5 = strlen((const char *)ptr);
v6 = strlen((const char *)a3);
v7 = (char *)malloc(v6 + v4 + v5 + 1);
if ( !v7 )
abort();
v8 = v7;
sprintf(v7, "%s%s%s", (const char *)ptr, s, (const char *)a3);
free(ptr);
free(a3);
return v8;
}

original_code:
static char *merge3(char *a, const char *op, char *b)
{
 char *buf;
 buf = ({ void *alloc_size_tmp = malloc(strlen(op)+strlen(a)+strlen(b)+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 sprintf(buf, "%s%s%s", a, op, b);
 free(a);
 free(b);
 return buf;
}

canonical_original_code:
static char *merge3(char *a, char *op, char *b)
{
 char *buf;
 buf = ({ void *alloc_size_tmp = malloc(strlen(op)+strlen(a)+strlen(b)+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 sprintf(buf, "%s%s%s", a, op, b);
 free(a);
 free(b);
 return buf;
}

variable_types:
a
char *

variable_types:
op
char *

variable_types:
b
char *

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall set_extension(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rdi
char *v5; // rax
__int64 v6; // rbp

v2 = strdup(a1);
if ( !v2 )
abort();
v3 = v2;
v4 = strrchr(v2, 47);
if ( !v4 )
v4 = v3;
v5 = strrchr(v4, 46);
if ( v5 )
*v5 = 0;
v6 = stralloc_printf("%s.%s", v3, a2);
free(v3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
char *v4; // rdi
char *v5; // rax
__int64 v6; // rbp

v2 = strdup(a1);
if ( !v2 )
abort();
v3 = v2;
v4 = strrchr(v2, 47);
if ( !v4 )
v4 = v3;
v5 = strrchr(v4, 46);
if ( v5 )
*v5 = 0;
v6 = stralloc_printf("%s.%s", v3, a2);
free(v3);
return v6;
}

original_code:
char *set_extension(const char *name, const char *ext)
{
 char *s = ({ char *stralloc_tmp = strdup(name); if (!stralloc_tmp) abort(); stralloc_tmp; });
 char *slash, *dot;
 char *res;
 slash = strrchr(s, '/');
 dot = strrchr(slash ? slash : s, '.');
 if (dot)
  *dot = 0;
 res = stralloc_printf("%s.%s", s, ext);
 free(s);
 return res;
}

canonical_original_code:
char *set_extension(char *name, char *ext)
{
 char *s = ({ char *stralloc_tmp = strdup(name); if (!stralloc_tmp) abort(); stralloc_tmp; });
 char *slash; char *dot;
 char *res;
 slash = strrchr(s, '/');
 dot = strrchr(slash ? slash : s, '.');
 if (dot)
  *dot = 0;
 res = stralloc_printf("%s.%s", s, ext);
 free(s);
 return res;
}

variable_types:
ext
char *

variable_types:
s
char *

variable_types:
slash
char *

variable_types:
dot
char *

variable_types:
res
char *


decompiled_code:
__int64 __fastcall file_exists(char *s)
{
int v1; // edx
__int64 result; // rax
int *v3; // rdx
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(s, &v4);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
result = 0LL;
if ( *v3 != 2 )
{
perror(s);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s)
{
int v1; // edx
__int64 result; // rax
int *v3; // rdx
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(s, &v4);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
result = 0LL;
if ( *v3 != 2 )
{
perror(s);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int file_exists(const char *name)
{
 struct stat st;
 if (stat(name, &st) >= 0)
  return 1;
 if ((*__errno_location ()) == 2)
  return 0;
 perror(name);
 return -1;
}

canonical_original_code:
int file_exists(char *name)
{
 struct stat st;
 if (stat(name, &st) >= 0)
  return 1;
 if ((*__errno_location ()) == 2)
  return 0;
 perror(name);
 return -1;
}

variable_types:
name
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void save_fpd()
{
if ( save_file_name )
{
save_with_backup(save_file_name, (__int64 (__fastcall *)(FILE *, __int64))&dump, 0LL);
}
else if ( !(unsigned int)dump(stdout, 0LL) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void func6()
{
if ( save_file_name )
{
func5(save_file_name, (__int64 (__fastcall *)(FILE *, __int64))&dump, 0LL);
}
else if ( !(unsigned int)dump(stdout, 0LL) )
{
perror("stdout");
}
}

original_code:
void save_fpd(void)
{
 if (save_file_name) {
  save_with_backup(save_file_name, dump, ((void *)0));
 } else {
  if (!dump(stdout, ((void *)0)))
   perror("stdout");
 }
}

canonical_original_code:
void save_fpd()
{
 if (save_file_name) {
  save_with_backup(save_file_name, dump, ((void *)0));
 } else {
  if (!dump(stdout, ((void *)0)))
   perror("stdout");
 }
}


decompiled_code:
void write_kicad()
{
char *v0; // rbx

if ( save_file_name )
{
v0 = (char *)set_extension(save_file_name, "mod");
save_to(v0, (__int64 (__fastcall *)(FILE *, __int64))&kicad, 0LL);
free(v0);
}
else if ( !(unsigned int)kicad(stdout, 0LL) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void func7()
{
char *v0; // rbx

if ( save_file_name )
{
v0 = (char *)func0(save_file_name, "mod");
func2(v0, (__int64 (__fastcall *)(FILE *, __int64))&kicad, 0LL);
free(v0);
}
else if ( !(unsigned int)kicad(stdout, 0LL) )
{
perror("stdout");
}
}

original_code:
void write_kicad(void)
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "mod");
  save_to(name, kicad, ((void *)0));
  free(name);
 } else {
  if (!kicad(stdout, ((void *)0)))
   perror("stdout");
 }
}

canonical_original_code:
void write_kicad()
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "mod");
  save_to(name, kicad, ((void *)0));
  free(name);
 } else {
  if (!kicad(stdout, ((void *)0)))
   perror("stdout");
 }
}


decompiled_code:
void write_pcb()
{
char *v0; // rbx

if ( save_file_name )
{
v0 = (char *)set_extension(save_file_name, "fp");
pcb_save_to(v0, (__int64 (__fastcall *)(FILE *))&pcb);
free(v0);
}
else if ( !(unsigned int)pcb(stdout) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void func8()
{
char *v0; // rbx

if ( save_file_name )
{
v0 = (char *)func0(save_file_name, "fp");
func4(v0, (__int64 (__fastcall *)(FILE *))&pcb);
free(v0);
}
else if ( !(unsigned int)pcb(stdout) )
{
perror("stdout");
}
}

original_code:
void write_pcb (void)
{
        char *name;
        if (save_file_name)
        {
                name = set_extension (save_file_name, "fp");
                pcb_save_to (name, pcb);
                free (name);
        }
        else
        {
                if (!pcb (stdout))
                {
                        perror ("stdout");
                }
        }
}

canonical_original_code:
void write_pcb()
{
        char *name;
        if (save_file_name)
        {
                name = set_extension (save_file_name, "fp");
                pcb_save_to (name, pcb);
                free (name);
        }
        else
        {
                if (!pcb (stdout))
                {
                        perror ("stdout");
                }
        }
}


decompiled_code:
void __fastcall write_ps(__int64 a1)
{
do_write_ps((__int64 (__fastcall *)(FILE *, __int64))&postscript, a1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
func3((__int64 (__fastcall *)(FILE *, __int64))&postscript, a1);
}

original_code:
void write_ps(const char *one)
{
 do_write_ps(postscript, one);
}

canonical_original_code:
void write_ps(char *one)
{
 do_write_ps(postscript, one);
}

variable_types:
one
char *


decompiled_code:
void __fastcall write_ps_fullpage(__int64 a1)
{
do_write_ps((__int64 (__fastcall *)(FILE *, __int64))&postscript_fullpage, a1);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
func3((__int64 (__fastcall *)(FILE *, __int64))&postscript_fullpage, a1);
}

original_code:
void write_ps_fullpage(const char *one)
{
 do_write_ps(postscript_fullpage, one);
}

canonical_original_code:
void write_ps_fullpage(char *one)
{
 do_write_ps(postscript_fullpage, one);
}


decompiled_code:
void __fastcall write_gnuplot(__int64 a1)
{
char *v1; // rbp

if ( save_file_name )
{
v1 = (char *)set_extension(save_file_name, "gp");
save_to(v1, (__int64 (__fastcall *)(FILE *, __int64))&gnuplot, a1);
free(v1);
}
else if ( !(unsigned int)gnuplot(stdout, a1) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
char *v1; // rbp

if ( save_file_name )
{
v1 = (char *)func0(save_file_name, "gp");
func2(v1, (__int64 (__fastcall *)(FILE *, __int64))&gnuplot, a1);
free(v1);
}
else if ( !(unsigned int)gnuplot(stdout, a1) )
{
perror("stdout");
}
}

original_code:
void write_gnuplot(const char *one)
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "gp");
  save_to(name, gnuplot, one);
  free(name);
 } else {
  if (!gnuplot(stdout, one))
   perror("stdout");
 }
}

canonical_original_code:
void write_gnuplot(char *one)
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "gp");
  save_to(name, gnuplot, one);
  free(name);
 } else {
  if (!gnuplot(stdout, one))
   perror("stdout");
 }
}


decompiled_code:
void __fastcall __noreturn report_to_stderr(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void report_to_stderr(const char *s)
{
 fprintf(stderr, "%s\n", s);
 exit(1);
}

canonical_original_code:
void report_to_stderr(char *s)
{
 fprintf(stderr, "%s\n", s);
 exit(1);
}


yywarn

decompiled_code:
int __fastcall yywarn(const char *a1)
{
return fprintf(stderr, "%d: warning: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%d: warning: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
}

original_code:
void yywarn(const char *s)
{
 fprintf(stderr, "%d: warning: %s near \"%s\"\n", lineno, s, yytext);
}

canonical_original_code:
void yywarn(char *s)
{
 fprintf(stderr, "%d: warning: %s near \"%s\"\n", lineno, s, yytext);
}


decompiled_code:
void __fastcall __noreturn report_parse_error(const char *a1)
{
fprintf(stderr, "%d: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "%d: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
exit(1);
}

original_code:
void report_parse_error(const char *s)
{
 fprintf(stderr, "%d: %s near \"%s\"\n", lineno, s, yytext);
 exit(1);
}

canonical_original_code:
void report_parse_error(char *s)
{
 fprintf(stderr, "%d: %s near \"%s\"\n", lineno, s, yytext);
 exit(1);
}


fail

decompiled_code:
void __noreturn fail(__int64 a1, ...)
{
__int64 v1; // rbx
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = stralloc_vprintf(a1, va);
reporter(v1);
}

canonical_decompiled_code:
void __noreturn func3(__int64 a1, ...)
{
__int64 v1; // rbx
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = stralloc_vprintf(a1, va);
reporter(v1);
}

original_code:
void fail(const char *fmt, ...)
{
 va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 reporter(s);
 free(s);
}

canonical_original_code:
void fail(char *fmt, ...)
{
 __builtin_va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 reporter(s);
 free(s);
}

variable_types:
fmt
char *


yyerrorf

decompiled_code:
void __noreturn yyerrorf(const char *a1, ...)
{
size_t v1; // rbp
char *v2; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a1);
v1 = vsnprintf(0LL, 0LL, a1, arg) + 1;
v2 = (char *)malloc(v1);
if ( v2 )
{
va_end(arg);
va_start(arg, a1);
vsnprintf(v2, v1, a1, arg);
fail((__int64)"%s", v2);
}
abort();
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
size_t v1; // rbp
char *v2; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a1);
v1 = vsnprintf(0LL, 0LL, a1, arg) + 1;
v2 = (char *)malloc(v1);
if ( v2 )
{
va_end(arg);
va_start(arg, a1);
vsnprintf(v2, v1, a1, arg);
func3((__int64)"%s", v2);
}
abort();
}

original_code:
void yyerrorf(const char *fmt, ...)
{
 va_list ap;
 char *buf;
 int n;
 __builtin_va_start(ap,fmt);
 n = vsnprintf(((void *)0), 0, fmt, ap);
 __builtin_va_end(ap);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, n+1, fmt, ap);
 __builtin_va_end(ap);
 fail("%s", buf);
 free(buf);
}

canonical_original_code:
void yyerrorf(char *fmt, ...)
{
 __builtin_va_list ap;
 char *buf;
 int n;
 __builtin_va_start(ap,fmt);
 n = vsnprintf(((void *)0), 0, fmt, ap);
 __builtin_va_end(ap);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, n+1, fmt, ap);
 __builtin_va_end(ap);
 fail("%s", buf);
 free(buf);
}

variable_types: n int


yyerror

decompiled_code:
void __fastcall __noreturn yyerror(const char *a1)
{
yyerrorf("%s", a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
func4("%s", a1);
}

original_code:
void yyerror(const char *s)
{
 yyerrorf("%s", s);
}

canonical_original_code:
void yyerror(char *s)
{
 yyerrorf("%s", s);
}


decompiled_code:
double __fastcall units_to_mm(int a1)
{
return (double)a1 / 10000.0;
}

canonical_decompiled_code:
double __fastcall func0(int a1)
{
return (double)a1 / 10000.0;
}

original_code:
static inline double units_to_mm(unit_type u)
{
 return (double) u/(1000.0*10);
}

canonical_original_code:
static inline double units_to_mm(int u)
{
 return (double) u/(1000.0*10);
}

variable_types: u int

return_type: double


decompiled_code:
double __fastcall units_to_mil(int a1)
{
return (double)a1 / 254.0;
}

canonical_decompiled_code:
double __fastcall func1(int a1)
{
return (double)a1 / 254.0;
}

original_code:
static inline double units_to_mil(unit_type u)
{
 return (double) u/(25.4*10);
}

canonical_original_code:
static inline double units_to_mil(int u)
{
 return (double) u/(25.4*10);
}


original_code:
static unit_type dist_line_xy(unit_type px, unit_type py,
    unit_type ax, unit_type ay, unit_type bx, unit_type by)
{
 unit_type d_min, d;
 double a, f;
 d_min = hypot(ax-px, ay-py);
 d = hypot(bx-px, by-py);
 if (d < d_min)
  d_min = d;
 if (ax != bx || ay != by) {
  ax -= bx;
  ay -= by;
  bx = px-bx;
  by = py-by;
  a = hypot(ax, ay);
  f = ((double) ax*bx+(double) ay*by)/a/a;
  if (f >= 0 && f <= 1) {
   bx -= f*ax;
   by -= f*ay;
   d = hypot(bx, by);
   if (d < d_min)
    d_min = d;
  }
 }
 return d_min;
}

canonical_original_code:
static int dist_line_xy(int px, int py, int ax, int ay, int bx, int by)
{
 int d_min; int d;
 double a; double f;
 d_min = hypot(ax-px, ay-py);
 d = hypot(bx-px, by-py);
 if (d < d_min)
  d_min = d;
 if (ax != bx || ay != by) {
  ax -= bx;
  ay -= by;
  bx = px-bx;
  by = py-by;
  a = hypot(ax, ay);
  f = ((double) ax*bx+(double) ay*by)/a/a;
  if (f >= 0 && f <= 1) {
   bx -= f*ax;
   by -= f*ay;
   d = hypot(bx, by);
   if (d < d_min)
    d_min = d;
  }
 }
 return d_min;
}

variable_types: px int

variable_types: py int

variable_types: ax int

variable_types: ay int

variable_types: bx int

variable_types: by int

variable_types: d int

variable_types: a double

variable_types: f double


decompiled_code:
double __fastcall mm_to_mil(int a1, double a2)
{
return pow(0.0254, (double)-a1) * a2;
}

canonical_decompiled_code:
double __fastcall func3(int a1, double a2)
{
return pow(0.0254, (double)-a1) * a2;
}

original_code:
double mm_to_mil(double mm, int exponent)
{
 return mm*pow(0.0254, -exponent);
}

variable_types: mm double

variable_types: exponent int


decompiled_code:
double __fastcall mil_to_mm(int a1, double a2)
{
return pow(0.0254, (double)a1) * a2;
}

canonical_decompiled_code:
double __fastcall func4(int a1, double a2)
{
return pow(0.0254, (double)a1) * a2;
}

original_code:
double mil_to_mm(double mil, int exponent)
{
 return mil*pow(0.0254, exponent);
}

variable_types: mil double


normalize

decompiled_code:
unsigned __int64 __fastcall normalize(__int64 a1, int a2)
{
double v2; // xmm1_8

v2 = hypot((double)(int)a1, (double)SHIDWORD(a1));
return ((unsigned __int64)(unsigned int)(int)((double)a2 / v2 * (double)SHIDWORD(a1)) << 32) | (unsigned int)(int)((double)(int)a1 * ((double)a2 / v2));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, int a2)
{
double v2; // xmm1_8

v2 = hypot((double)(int)a1, (double)SHIDWORD(a1));
return ((unsigned __int64)(unsigned int)(int)((double)a2 / v2 * (double)SHIDWORD(a1)) << 32) | (unsigned int)(int)((double)(int)a1 * ((double)a2 / v2));
}

original_code:
struct coord normalize(struct coord v, unit_type len)
{
 double f;
 f = len/hypot(v.x, v.y);
 v.x *= f;
 v.y *= f;
 return v;
}

canonical_original_code:
struct coord normalize(struct coord v, int len)
{
 double f;
 f = len/hypot(v.x, v.y);
 v.x *= f;
 v.y *= f;
 return v;
}

variable_types:
v
struct coord

variable_types: len int

return_type: struct coord { int x; }


rotate

decompiled_code:
unsigned __int64 __fastcall rotate(__int64 a1, double a2)
{
double v3; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2 * 3.141592653589793 / 180.0, sinx, &v3);
return ((unsigned __int64)(unsigned int)(int)(v3 * (double)SHIDWORD(a1) + (double)(int)a1 * sinx[0]) << 32) | (unsigned int)(int)((double)(int)a1 * v3 - (double)SHIDWORD(a1) * sinx[0]);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, double a2)
{
double v3; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2 * 3.141592653589793 / 180.0, sinx, &v3);
return ((unsigned __int64)(unsigned int)(int)(v3 * (double)SHIDWORD(a1) + (double)(int)a1 * sinx[0]) << 32) | (unsigned int)(int)((double)(int)a1 * v3 - (double)SHIDWORD(a1) * sinx[0]);
}

original_code:
struct coord rotate(struct coord v, double angle)
{
 double rad = 3.14159265358979323846*angle/180.0;
 struct coord res;
 res.x = v.x*cos(rad)-v.y*sin(rad);
 res.y = v.y*cos(rad)+v.x*sin(rad);
 return res;
}

variable_types: angle double

variable_types: rad double

variable_types:
res
struct coord { int x; }


decompiled_code:
unsigned __int64 __fastcall add_vec(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(HIDWORD(a2) + HIDWORD(a1)) << 32) | (unsigned int)(a2 + a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(HIDWORD(a2) + HIDWORD(a1)) << 32) | (unsigned int)(a2 + a1);
}

original_code:
struct coord add_vec(struct coord a, struct coord b)
{
 a.x += b.x;
 a.y += b.y;
 return a;
}

variable_types:
a
struct coord

variable_types:
b
struct coord


decompiled_code:
unsigned __int64 __fastcall sub_vec(__int64 a1, __int64 a2)
{
return (unsigned int)(a1 - a2) | ((unsigned __int64)(unsigned int)(HIDWORD(a1) - HIDWORD(a2)) << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, __int64 a2)
{
return (unsigned int)(a1 - a2) | ((unsigned __int64)(unsigned int)(HIDWORD(a1) - HIDWORD(a2)) << 32);
}

original_code:
struct coord sub_vec(struct coord a, struct coord b)
{
 a.x -= b.x;
 a.y -= b.y;
 return a;
}


decompiled_code:
__int64 __fastcall neg_vec(__int64 a1)
{
return -a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return -a1;
}

original_code:
struct coord neg_vec(struct coord v)
{
 v.x = -v.x;
 v.y = -v.y;
 return v;
}


decompiled_code:
unsigned __int64 __fastcall rotate_r(__int64 a1, int a2, double a3)
{
double v4; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a3 / 180.0 * 3.141592653589793, sinx, &v4);
return ((unsigned __int64)(unsigned int)(int)((double)SHIDWORD(a1) + (double)a2 * sinx[0]) << 32) | (unsigned int)(int)((double)a2 * v4 + (double)(int)a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, int a2, double a3)
{
double v4; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a3 / 180.0 * 3.141592653589793, sinx, &v4);
return ((unsigned __int64)(unsigned int)(int)((double)SHIDWORD(a1) + (double)a2 * sinx[0]) << 32) | (unsigned int)(int)((double)a2 * v4 + (double)(int)a1);
}

original_code:
struct coord rotate_r(struct coord c, unit_type r, double angle)
{
 struct coord p;
 angle = angle/180.0*3.14159265358979323846;
 p.x = c.x+r*cos(angle);
 p.y = c.y+r*sin(angle);
 return p;
}

canonical_original_code:
struct coord rotate_r(struct coord c, int r, double angle)
{
 struct coord p;
 angle = angle/180.0*3.14159265358979323846;
 p.x = c.x+r*cos(angle);
 p.y = c.y+r*sin(angle);
 return p;
}

variable_types:
c
struct coord

variable_types: r int

variable_types:
p
struct coord { int x; }


decompiled_code:
double __fastcall theta_vec(__int64 a1)
{
double result; // xmm0_8

result = atan2((double)SHIDWORD(a1), (double)(int)a1) / 3.141592653589793 * 180.0;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

canonical_decompiled_code:
double __fastcall func12(__int64 a1)
{
double result; // xmm0_8

result = atan2((double)SHIDWORD(a1), (double)(int)a1) / 3.141592653589793 * 180.0;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

variable_types:
v
struct coord { int x; }


theta

decompiled_code:
double __fastcall theta(__int64 a1, __int64 a2)
{
return theta_vec((unsigned int)(a2 - a1) | ((unsigned __int64)(unsigned int)(HIDWORD(a2) - HIDWORD(a1)) << 32));
}

canonical_decompiled_code:
double __fastcall func13(__int64 a1, __int64 a2)
{
return func12((unsigned int)(a2 - a1) | ((unsigned __int64)(unsigned int)(HIDWORD(a2) - HIDWORD(a1)) << 32));
}

original_code:
double theta(struct coord c, struct coord p)
{
 p.x -= c.x;
 p.y -= c.y;
 return theta_vec(p);
}

variable_types:
c
struct coord { int x; }

variable_types:
p
struct coord


decompiled_code:
__int64 __fastcall dist_point(__int64 a1, __int64 a2)
{
return (unsigned int)(int)hypot((double)((int)a1 - (int)a2), (double)(HIDWORD(a1) - HIDWORD(a2)));
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return (unsigned int)(int)hypot((double)((int)a1 - (int)a2), (double)(HIDWORD(a1) - HIDWORD(a2)));
}

original_code:
unit_type dist_point(struct coord a, struct coord b)
{
 return hypot(a.x-b.x, a.y-b.y);
}

canonical_original_code:
int dist_point(struct coord a, struct coord b)
{
 return hypot(a.x-b.x, a.y-b.y);
}

variable_types:
a
struct coord { int x; }


decompiled_code:
__int64 __fastcall dist_line(__int64 a1, __int64 a2, __int64 a3)
{
return dist_line_xy(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a3));
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3)
{
return func2(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a3));
}

original_code:
unit_type dist_line(struct coord p, struct coord a, struct coord b)
{
 return dist_line_xy(p.x, p.y, a.x, a.y, b.x, b.y);
}

canonical_original_code:
int dist_line(struct coord p, struct coord a, struct coord b)
{
 return dist_line_xy(p.x, p.y, a.x, a.y, b.x, b.y);
}