main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
char *v4; // rdi
__int64 v5; // r12
void *v6; // rbp
const char *v7; // rax
const char *v8; // rax
unsigned __int16 v10; // [rsp+6h] [rbp-42h] BYREF
unsigned int v11; // [rsp+8h] [rbp-40h] BYREF
int v12[3]; // [rsp+Ch] [rbp-3Ch] BYREF
void *v13; // [rsp+18h] [rbp-30h] BYREF
char *s; // [rsp+20h] [rbp-28h] BYREF
void *ptr; // [rsp+28h] [rbp-20h] BYREF

*(_QWORD *)&v12[1] = 0LL;
v13 = 0LL;
s = 0LL;
ptr = 0LL;
puts("\n\n-------- PAES --------\n\n");
parse_command_line(argc, (char **)argv, (char **)&v12[1], (char **)&v13, &v11, &v10, (__int64)&s, (__int64)v12);
check_arguments(v11, v10, v12[0]);
v3 = read_file(*(_QWORD *)&v12[1], &ptr);
v4 = s;
v5 = v3;
if ( !s )
{
s = getpass("\nPlease type the password: ");
v4 = s;
}
v6 = hash_password(v4, v10 >> 3);
puts("PARAMETERS:");
printf(" Input file: %s\n", *(const char **)&v12[1]);
printf(" Output file: %s\n", (const char *)v13);
v7 = (const char *)get_aes_mode_name(v11);
printf(" AES mode: %s\n", v7);
printf(" Key size: %u\n", v10);
v8 = (const char *)get_opencl_device_name((unsigned int)v12[0]);
printf(" Device: %s\n", v8);
printf(" File size: %u bytes\n", (unsigned int)v5);
puts("\n");
if ( (unsigned int)apply_aes(ptr, v5, (unsigned int)v12[0], v11, v6, v10) != -1 )
write_file(v13, ptr, v5);
if ( ptr )
free(ptr);
if ( *(_QWORD *)&v12[1] )
free(*(void **)&v12[1]);
if ( v13 )
free(v13);
if ( s )
free(s);
if ( v6 )
free(v6);
puts("\n\n----- It ends here... -----\n\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
char *v4; // rdi
__int64 v5; // r12
void *v6; // rbp
const char *v7; // rax
const char *v8; // rax
unsigned __int16 v10; // [rsp+6h] [rbp-42h] BYREF
unsigned int v11; // [rsp+8h] [rbp-40h] BYREF
int v12[3]; // [rsp+Ch] [rbp-3Ch] BYREF
void *v13; // [rsp+18h] [rbp-30h] BYREF
char *s; // [rsp+20h] [rbp-28h] BYREF
void *ptr; // [rsp+28h] [rbp-20h] BYREF

*(_QWORD *)&v12[1] = 0LL;
v13 = 0LL;
s = 0LL;
ptr = 0LL;
puts("\n\n-------- PAES --------\n\n");
func1(argc, (char **)argv, (char **)&v12[1], (char **)&v13, &v11, &v10, (__int64)&s, (__int64)v12);
func2(v11, v10, v12[0]);
v3 = read_file(*(_QWORD *)&v12[1], &ptr);
v4 = s;
v5 = v3;
if ( !s )
{
s = getpass("\nPlease type the password: ");
v4 = s;
}
v6 = func3(v4, v10 >> 3);
puts("PARAMETERS:");
printf(" Input file: %s\n", *(const char **)&v12[1]);
printf(" Output file: %s\n", (const char *)v13);
v7 = (const char *)get_aes_mode_name(v11);
printf(" AES mode: %s\n", v7);
printf(" Key size: %u\n", v10);
v8 = (const char *)get_opencl_device_name((unsigned int)v12[0]);
printf(" Device: %s\n", v8);
printf(" File size: %u bytes\n", (unsigned int)v5);
puts("\n");
if ( (unsigned int)apply_aes(ptr, v5, (unsigned int)v12[0], v11, v6, v10) != -1 )
write_file(v13, ptr, v5);
if ( ptr )
free(ptr);
if ( *(_QWORD *)&v12[1] )
free(*(void **)&v12[1]);
if ( v13 )
free(v13);
if ( s )
free(s);
if ( v6 )
free(v6);
puts("\n\n----- It ends here... -----\n\n");
return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


draw

decompiled_code:
__int64 __fastcall draw(float a1, float a2, float a3)
{
__int64 v3; // rdx
char *v4; // rdi
__int64 result; // rax
unsigned int v6; // er12
__int64 v7; // rbp
__int64 v8; // [rsp+10h] [rbp-28h] BYREF
__int64 v9; // [rsp+18h] [rbp-20h]

if ( vdevice )
{
if ( *((_BYTE *)&vdevice + 2) )
{
result = newtokens(4LL);
*(_DWORD *)result = 8;
*(float *)(result + 4) = a1;
*(float *)(result + 8) = a2;
*(float *)(result + 12) = a3;
*((_BYTE *)&vdevice + 5) = 0;
*((float *)&vdevice + 14) = a1;
*((float *)&vdevice + 15) = a2;
*((float *)&vdevice + 16) = a3;
}
else
{
if ( !*((_BYTE *)&vdevice + 5) )
multvector((char *)&vdevice + 72, (char *)&vdevice + 56, *((_QWORD *)&vdevice + 3));
v3 = *((_QWORD *)&vdevice + 3);
*((float *)&vdevice + 14) = a1;
*((float *)&vdevice + 15) = a2;
*((float *)&vdevice + 16) = a3;
multvector(&v8, (char *)&vdevice + 56, v3);
if ( *((_BYTE *)&vdevice + 1) )
{
v6 = WtoVx(&v8);
v7 = (unsigned int)WtoVy(&v8);
(*((void (__fastcall **)(_QWORD, __int64))&vdevice + 27))(v6, v7);
*((_DWORD *)&vdevice + 35) = v6;
*((_DWORD *)&vdevice + 36) = v7;
*((_BYTE *)&vdevice + 5) = 0;
}
else
{
v4 = (char *)&vdevice + 72;
if ( *((_BYTE *)&vdevice + 5) )
quickclip(v4, &v8);
else
clip(v4, &v8);
}
*((_QWORD *)&vdevice + 9) = v8;
result = v9;
*((_QWORD *)&vdevice + 10) = v9;
}
}
else
{
verror("draw: vogl not initialised");
result = draws();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(float a1, float a2, float a3)
{
__int64 v3; // rdx
char *v4; // rdi
__int64 result; // rax
unsigned int v6; // er12
__int64 v7; // rbp
__int64 v8; // [rsp+10h] [rbp-28h] BYREF
__int64 v9; // [rsp+18h] [rbp-20h]

if ( vdevice )
{
if ( *((_BYTE *)&vdevice + 2) )
{
result = newtokens(4LL);
*(_DWORD *)result = 8;
*(float *)(result + 4) = a1;
*(float *)(result + 8) = a2;
*(float *)(result + 12) = a3;
*((_BYTE *)&vdevice + 5) = 0;
*((float *)&vdevice + 14) = a1;
*((float *)&vdevice + 15) = a2;
*((float *)&vdevice + 16) = a3;
}
else
{
if ( !*((_BYTE *)&vdevice + 5) )
multvector((char *)&vdevice + 72, (char *)&vdevice + 56, *((_QWORD *)&vdevice + 3));
v3 = *((_QWORD *)&vdevice + 3);
*((float *)&vdevice + 14) = a1;
*((float *)&vdevice + 15) = a2;
*((float *)&vdevice + 16) = a3;
multvector(&v8, (char *)&vdevice + 56, v3);
if ( *((_BYTE *)&vdevice + 1) )
{
v6 = WtoVx(&v8);
v7 = (unsigned int)WtoVy(&v8);
(*((void (__fastcall **)(_QWORD, __int64))&vdevice + 27))(v6, v7);
*((_DWORD *)&vdevice + 35) = v6;
*((_DWORD *)&vdevice + 36) = v7;
*((_BYTE *)&vdevice + 5) = 0;
}
else
{
v4 = (char *)&vdevice + 72;
if ( *((_BYTE *)&vdevice + 5) )
quickclip(v4, &v8);
else
clip(v4, &v8);
}
*((_QWORD *)&vdevice + 9) = v8;
result = v9;
*((_QWORD *)&vdevice + 10) = v9;
}
}
else
{
verror("draw: vogl not initialised");
result = func1();
}
return result;
}

original_code:
void
draw(float x, float y, float z)
{
 Token *tok;
 int vx, vy;
 Vector res;
 if (!vdevice.initialised)
  verror("draw: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(4);
  tok[0].i = 8;
  tok[1].f = x;
  tok[2].f = y;
  tok[3].f = z;
  vdevice.cpW[0] = x;
  vdevice.cpW[1] = y;
  vdevice.cpW[2] = z;
  vdevice.cpVvalid = 0;
  return;
 }
 if (!vdevice.cpVvalid)
  multvector(vdevice.cpWtrans, vdevice.cpW, vdevice.transmat->m);
 vdevice.cpW[0] = x;
 vdevice.cpW[1] = y;
 vdevice.cpW[2] = z;
 multvector(res, vdevice.cpW, vdevice.transmat->m);
 if (vdevice.clipoff) {
  vx = WtoVx(res);
  vy = WtoVy(res);
  (*vdevice.dev.Vdraw)(vx, vy);
  vdevice.cpVx = vx;
  vdevice.cpVy = vy;
  vdevice.cpVvalid = 0;
 } else {
  if (vdevice.cpVvalid)
   quickclip(vdevice.cpWtrans, res);
  else
   clip(vdevice.cpWtrans, res);
 }
 vdevice.cpWtrans[0] = res[0];
 vdevice.cpWtrans[1] = res[1];
 vdevice.cpWtrans[2] = res[2];
 vdevice.cpWtrans[3] = res[3];
}

canonical_original_code:
void draw(float x, float y, float z)
{
 union tk *tok;
 int vx; int vy;
 float res[4];
 if (!vdevice.initialised)
  verror("draw: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(4);
  tok[0].i = 8;
  tok[1].f = x;
  tok[2].f = y;
  tok[3].f = z;
  vdevice.cpW[0] = x;
  vdevice.cpW[1] = y;
  vdevice.cpW[2] = z;
  vdevice.cpVvalid = 0;
  return;
 }
 if (!vdevice.cpVvalid)
  multvector(vdevice.cpWtrans, vdevice.cpW, vdevice.transmat->m);
 vdevice.cpW[0] = x;
 vdevice.cpW[1] = y;
 vdevice.cpW[2] = z;
 multvector(res, vdevice.cpW, vdevice.transmat->m);
 if (vdevice.clipoff) {
  vx = WtoVx(res);
  vy = WtoVy(res);
  (*vdevice.dev.Vdraw)(vx, vy);
  vdevice.cpVx = vx;
  vdevice.cpVy = vy;
  vdevice.cpVvalid = 0;
 } else {
  if (vdevice.cpVvalid)
   quickclip(vdevice.cpWtrans, res);
  else
   clip(vdevice.cpWtrans, res);
 }
 vdevice.cpWtrans[0] = res[0];
 vdevice.cpWtrans[1] = res[1];
 vdevice.cpWtrans[2] = res[2];
 vdevice.cpWtrans[3] = res[3];
}

variable_types: x float

variable_types: y float

variable_types: z float

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

variable_types: vx int

variable_types: vy int

variable_types:
res
float [4]

return_type: void


draws

decompiled_code:
__int64 __fastcall draws(__int16 a1, __int16 a2, __int16 a3)
{
return draw((float)a1, (float)a2, (float)a3);
}

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

original_code:
void
draws(Scoord x, Scoord y, Scoord z)
{
 draw((Coord)x, (Coord)y, (Coord)z);
}

canonical_original_code:
void draws(short x, short y, short z)
{
 draw((float)x, (float)y, (float)z);
}

variable_types: x short

variable_types: y short

variable_types: z short


drawi

decompiled_code:
__int64 __fastcall drawi(int a1, int a2, int a3)
{
return draw((float)a1, (float)a2, (float)a3);
}

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

original_code:
void
drawi(Icoord x, Icoord y, Icoord z)
{
 draw((Coord)x, (Coord)y, (Coord)z);
}

canonical_original_code:
void drawi(long x, long y, long z)
{
 draw((float)x, (float)y, (float)z);
}

variable_types: x long

variable_types: y long

variable_types: z long


decompiled_code:
__int64 __fastcall draw2(float a1, float a2)
{
if ( vdevice )
return draw(a1, a2, 0.0);
verror("draw2: vogl not initialised");
return draw2s();
}

canonical_decompiled_code:
__int64 __fastcall func3(float a1, float a2)
{
if ( vdevice )
return func0(a1, a2, 0.0);
verror("draw2: vogl not initialised");
return func4();
}

original_code:
void
draw2(float x, float y)
{
 if (!vdevice.initialised)
  verror("draw2: vogl not initialised");
 draw(x, y, 0.0);
}


decompiled_code:
__int64 __fastcall draw2s(__int16 a1, __int16 a2)
{
return draw2((float)a1, (float)a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1, __int16 a2)
{
return func3((float)a1, (float)a2);
}

original_code:
void
draw2s(Scoord x, Scoord y)
{
 draw2((Coord)x, (Coord)y);
}

canonical_original_code:
void draw2s(short x, short y)
{
 draw2((float)x, (float)y);
}


decompiled_code:
__int64 __fastcall draw2i(int a1, int a2)
{
return draw2((float)a1, (float)a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
return func3((float)a1, (float)a2);
}

original_code:
void
draw2i(Icoord x, Icoord y)
{
 draw2((Coord)x, (Coord)y);
}

canonical_original_code:
void draw2i(long x, long y)
{
 draw2((float)x, (float)y);
}


rdr

decompiled_code:
__int64 __fastcall rdr(float a1, float a2, float a3)
{
if ( vdevice )
return draw(a1 + *((float *)&vdevice + 14), a2 + *((float *)&vdevice + 15), a3 + *((float *)&vdevice + 16));
verror("rdr: vogl not initialised");
return rdrs();
}

canonical_decompiled_code:
__int64 __fastcall func6(float a1, float a2, float a3)
{
if ( vdevice )
return func0(a1 + *((float *)&vdevice + 14), a2 + *((float *)&vdevice + 15), a3 + *((float *)&vdevice + 16));
verror("rdr: vogl not initialised");
return func7();
}

original_code:
void
rdr(float dx, float dy, float dz)
{
 if (!vdevice.initialised)
  verror("rdr: vogl not initialised");
 draw((vdevice.cpW[0] + dx), (vdevice.cpW[1] + dy), (vdevice.cpW[2] + dz));
}

variable_types: dx float

variable_types: dy float

variable_types: dz float


rdrs

decompiled_code:
__int64 __fastcall rdrs(__int16 a1, __int16 a2, __int16 a3)
{
return rdr((float)a1, (float)a2, (float)a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1, __int16 a2, __int16 a3)
{
return func6((float)a1, (float)a2, (float)a3);
}

original_code:
void
rdrs(Scoord dx, Scoord dy, Scoord dz)
{
 rdr((Coord)dx, (Coord)dy, (Coord)dz);
}

canonical_original_code:
void rdrs(short dx, short dy, short dz)
{
 rdr((float)dx, (float)dy, (float)dz);
}

variable_types: dx short

variable_types: dy short

variable_types: dz short


rdri

decompiled_code:
__int64 __fastcall rdri(int a1, int a2, int a3)
{
return rdr((float)a1, (float)a2, (float)a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3)
{
return func6((float)a1, (float)a2, (float)a3);
}

original_code:
void
rdri(Icoord dx, Icoord dy, Icoord dz)
{
 rdr((Coord)dx, (Coord)dy, (Coord)dz);
}

canonical_original_code:
void rdri(long dx, long dy, long dz)
{
 rdr((float)dx, (float)dy, (float)dz);
}

variable_types: dx long

variable_types: dy long

variable_types: dz long


decompiled_code:
__int64 __fastcall rdr2(float a1, float a2)
{
if ( vdevice )
return draw(a1 + *((float *)&vdevice + 14), a2 + *((float *)&vdevice + 15), 0.0);
verror("rdr2: vogl not initialised");
return rdr2s();
}

canonical_decompiled_code:
__int64 __fastcall func9(float a1, float a2)
{
if ( vdevice )
return func0(a1 + *((float *)&vdevice + 14), a2 + *((float *)&vdevice + 15), 0.0);
verror("rdr2: vogl not initialised");
return func10();
}

original_code:
void
rdr2(float dx, float dy)
{
 if (!vdevice.initialised)
  verror("rdr2: vogl not initialised");
 draw((vdevice.cpW[0] + dx), (vdevice.cpW[1] + dy), 0.0);
}


decompiled_code:
__int64 __fastcall rdr2s(__int16 a1, __int16 a2)
{
return rdr2((float)a1, (float)a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int16 a1, __int16 a2)
{
return func9((float)a1, (float)a2);
}

original_code:
void
rdr2s(Scoord dx, Scoord dy)
{
 rdr2((Coord)dx, (Coord)dy);
}

canonical_original_code:
void rdr2s(short dx, short dy)
{
 rdr2((float)dx, (float)dy);
}


decompiled_code:
__int64 __fastcall rdr2i(int a1, int a2)
{
return rdr2((float)a1, (float)a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
return func9((float)a1, (float)a2);
}

original_code:
void
rdr2i(Icoord dx, Icoord dy)
{
 rdr2((Coord)dx, (Coord)dy);
}

canonical_original_code:
void rdr2i(long dx, long dy)
{
 rdr2((float)dx, (float)dy);
}


bgnline

decompiled_code:
__int64 bgnline()
{
int v0; // edx
__int64 result; // rax

if ( *((_BYTE *)&vdevice + 348) )
{
verror("vogl: bgnline mode already belongs to some other bgn routine");
result = endline();
}
else
{
v0 = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
*((_BYTE *)&vdevice + 348) = 2;
*((_DWORD *)&vdevice + 88) = 1;
sync = v0;
result = (*((__int64 (**)(void))&vdevice + 40))();
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // edx
__int64 result; // rax

if ( *((_BYTE *)&vdevice + 348) )
{
verror("vogl: bgnline mode already belongs to some other bgn routine");
result = func13();
}
else
{
v0 = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
*((_BYTE *)&vdevice + 348) = 2;
*((_DWORD *)&vdevice + 88) = 1;
sync = v0;
result = (*((__int64 (**)(void))&vdevice + 40))();
}
return result;
}

original_code:
void
bgnline(void)
{
 if (vdevice.bgnmode != 0)
  verror("vogl: bgnline mode already belongs to some other bgn routine");
 vdevice.bgnmode = 2;
 vdevice.save = 1;
 sync = vdevice.sync;
 vdevice.sync = 0;
 (*vdevice.dev.Vbegin)();
}

canonical_original_code:
void bgnline()
{
 if (vdevice.bgnmode != 0)
  verror("vogl: bgnline mode already belongs to some other bgn routine");
 vdevice.bgnmode = 2;
 vdevice.save = 1;
 sync = vdevice.sync;
 vdevice.sync = 0;
 (*vdevice.dev.Vbegin)();
}


endline

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

*((_DWORD *)&vdevice + 88) = 0;
result = (*((__int64 (**)(void))&vdevice + 41))();
*((_BYTE *)&vdevice + 348) = 0;
return result;
}

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

*((_DWORD *)&vdevice + 88) = 0;
result = (*((__int64 (**)(void))&vdevice + 41))();
*((_BYTE *)&vdevice + 348) = 0;
return result;
}

original_code:
void
endline(void)
{
 vdevice.save = 0;
  (*vdevice.dev.Vsync)();
 vdevice.bgnmode = 0;
}

canonical_original_code:
void endline()
{
 vdevice.save = 0;
  (*vdevice.dev.Vsync)();
 vdevice.bgnmode = 0;
}


bgnclosedline

decompiled_code:
void *bgnclosedline()
{
void *result; // rax
int v1; // edx

result = &vdevice;
if ( *((_BYTE *)&vdevice + 348) )
{
verror("vogl: bgncloseline mode already belongs to some other bgn routine");
result = (void *)endclosedline();
}
else
{
v1 = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
*((_BYTE *)&vdevice + 348) = 3;
*((_DWORD *)&vdevice + 88) = 1;
sync = v1;
}
return result;
}

canonical_decompiled_code:
void *func14()
{
void *result; // rax
int v1; // edx

result = &vdevice;
if ( *((_BYTE *)&vdevice + 348) )
{
verror("vogl: bgncloseline mode already belongs to some other bgn routine");
result = (void *)func15();
}
else
{
v1 = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
*((_BYTE *)&vdevice + 348) = 3;
*((_DWORD *)&vdevice + 88) = 1;
sync = v1;
}
return result;
}

original_code:
void
bgnclosedline(void)
{
 if (vdevice.bgnmode != 0)
  verror("vogl: bgncloseline mode already belongs to some other bgn routine");
 vdevice.bgnmode = 3;
 vdevice.save = 1;
 sync = vdevice.sync;
 vdevice.sync = 0;
}

canonical_original_code:
void bgnclosedline()
{
 if (vdevice.bgnmode != 0)
  verror("vogl: bgncloseline mode already belongs to some other bgn routine");
 vdevice.bgnmode = 3;
 vdevice.save = 1;
 sync = vdevice.sync;
 vdevice.sync = 0;
}


endclosedline

decompiled_code:
__int64 endclosedline()
{
float v0; // xmm0_4
float v1; // xmm2_4
float v2; // xmm1_4

v0 = *((float *)&vdevice + 84);
v1 = *((float *)&vdevice + 86);
*((_BYTE *)&vdevice + 6) = sync;
v2 = *((float *)&vdevice + 85);
*((_BYTE *)&vdevice + 348) = 0;
return draw(v0, v2, v1);
}

canonical_decompiled_code:
__int64 func15()
{
float v0; // xmm0_4
float v1; // xmm2_4
float v2; // xmm1_4

v0 = *((float *)&vdevice + 84);
v1 = *((float *)&vdevice + 86);
*((_BYTE *)&vdevice + 6) = sync;
v2 = *((float *)&vdevice + 85);
*((_BYTE *)&vdevice + 348) = 0;
return func0(v0, v2, v1);
}

original_code:
void
endclosedline(void)
{
 vdevice.bgnmode = 0;
 vdevice.sync = sync;
 draw(vdevice.savex, vdevice.savey, vdevice.savez);
}

canonical_original_code:
void endclosedline()
{
 vdevice.bgnmode = 0;
 vdevice.sync = sync;
 draw(vdevice.savex, vdevice.savey, vdevice.savez);
}


getdevice

original_code:
static void
getdevice(char *device)
{
 char buf[100];
 if (strncmp(device, "X11", 3) == 0)
  _X11_devcpy();
 else
 if (strncmp(device, "postscript", 10) == 0) {
  _PS_devcpy();
 } else
 if (strncmp(device, "ppostscript", 11) == 0) {
  _PSP_devcpy();
 } else
 if (strncmp(device, "cps", 3) == 0) {
  _CPS_devcpy();
 } else
 if (strncmp(device, "pcps", 4) == 0) {
  _PCPS_devcpy();
 } else
 if (strncmp(device, "hpgla1", 6) == 0)
  _HPGL_A1_devcpy();
 else if (strncmp(device, "hpgla3", 6) == 0)
  _HPGL_A3_devcpy();
 else if (strncmp(device, "hpgla4", 6) == 0)
  _HPGL_A4_devcpy();
 else if (strncmp(device, "hpgla2", 6) == 0 || strncmp(device, "hpgl", 4) == 0)
  _HPGL_A2_devcpy();
 else
 if (strncmp(device, "tek", 3) == 0)
  _TEK_devcpy();
 else
 {
  if (*device == 0)
   sprintf(buf, "vogl: expected the enviroment variable VDEVICE to be set to the desired device.\n");
  else
   sprintf(buf, "vogl: %s is an invalid device type\n", device);
  fputs(buf, stderr);
  fprintf(stderr, "The devices compiled into this library are:\n");
  fprintf(stderr, "X11\n");
  fprintf(stderr, "postscript\n");
  fprintf(stderr, "ppostscript\n");
  fprintf(stderr, "cps\n");
  fprintf(stderr, "pcps\n");
  fprintf(stderr, "hpgla1\n");
  fprintf(stderr, "hpgla2 (or hpgl)\n");
  fprintf(stderr, "hpgla3\n");
  fprintf(stderr, "hpgla4\n");
  fprintf(stderr, "tek\n");
  exit(1);
 }
}

variable_types:
device
char *

variable_types:
buf
char [100]


gexit

decompiled_code:
struct _IO_FILE *gexit()
{
struct _IO_FILE *result; // rax

if ( !vdevice )
verror("gexit: vogl not initialised");
(*((void (**)(void))&vdevice + 28))();
vdevice = 0;
*((_QWORD *)&vdevice + 46) = 0LL;
result = stdout;
fp = (__int64)stdout;
return result;
}

canonical_decompiled_code:
struct _IO_FILE *func2()
{
struct _IO_FILE *result; // rax

if ( !vdevice )
func3("gexit: vogl not initialised");
(*((void (**)(void))&vdevice + 28))();
vdevice = 0;
*((_QWORD *)&vdevice + 46) = 0LL;
result = stdout;
fp = (__int64)stdout;
return result;
}

original_code:
void
gexit(void)
{
 if (!vdevice.initialised)
  verror("gexit: vogl not initialised");
 (*vdevice.dev.Vexit)();
 vdevice.devname = (char *)((void *)0);
 vdevice.initialised = 0;
 fp = stdout;
}

canonical_original_code:
void gexit()
{
 if (!vdevice.initialised)
  verror("gexit: vogl not initialised");
 (*vdevice.dev.Vexit)();
 vdevice.devname = (char *)((void *)0);
 vdevice.initialised = 0;
 fp = stdout;
}


verror

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

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

original_code:
void
verror(char *str)
{
 if (vdevice.initialised)
  gexit();
 fprintf(stderr, "%s\n", str);
 exit(1);
}

variable_types:
str
char *


ginit

decompiled_code:
__int64 __fastcall ginit(__int64 a1, __int64 a2)
{
char *v2; // rdi
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rsi
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax

v2 = (char *)vdevice[46];
if ( v2 || (v2 = getenv("VDEVICE")) != 0LL )
getdevice(v2, a2);
else
getdevice((const char *)&LC26, a2);
if ( LOBYTE(vdevice[0]) )
{
gexit();
if ( allocated )
goto LABEL_5;
LABEL_12:
allocated = 1;
deflinestyle(0LL, 0xFFFFLL);
v9 = vallocate(72LL);
*(_QWORD *)(v9 + 64) = 0LL;
vdevice[3] = v9;
v10 = vallocate(24LL);
vdevice[4] = v10;
*(_QWORD *)(v10 + 16) = 0LL;
v11 = vallocate(24LL);
vdevice[5] = v11;
*(_QWORD *)(v11 + 16) = 0LL;
vdevice[63] = vallocate(640LL);
v12 = vallocate(34LL);
vdevice[64] = v12;
v3 = v12;
goto LABEL_6;
}
if ( !allocated )
goto LABEL_12;
LABEL_5:
v3 = vdevice[64];
LABEL_6:
v4 = 0LL;
while ( 1 )
{
*(_BYTE *)(v3 + v4++) = 0;
if ( v4 == 34 )
break;
v3 = vdevice[64];
}
v5 = vdevice[64];
BYTE4(vdevice[65]) = 1;
vdevice[66] = 261LL;
*(_BYTE *)(v5 + 32) |= 0x20u;
v6 = vdevice[4];
BYTE5(vdevice[65]) = 0;
HIWORD(vdevice[65]) = 0;
LODWORD(vdevice[67]) = 0;
HIDWORD(vdevice[8]) = 1065353216;
LODWORD(vdevice[65]) = 2;
BYTE1(vdevice[0]) = 0;
BYTE6(vdevice[0]) = 1;
*(_WORD *)(v6 + 14) = 1;
*(_DWORD *)(v6 + 8) = 0;
*(_WORD *)v6 = 0;
if ( !((unsigned int (*)(void))vdevice[33])() )
{
fwrite("vogl: error while setting up device\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
LOBYTE(vdevice[0]) = 1;
WORD1(vdevice[0]) = 0;
v7 = (unsigned int)(__int16)(WORD2(vdevice[16]) - 1);
viewport(0LL, v7, 0LL, (unsigned int)(__int16)(LOWORD(vdevice[17]) - 1));
ortho2(0.0, (float)(HIDWORD(vdevice[16]) - 1), 0.0, (float)(LODWORD(vdevice[17]) - 1));
move(0, v7);
font(0LL, 0.0, 0.0);
return setlinestyle(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
char *v2; // rdi
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rsi
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax

v2 = (char *)vdevice[46];
if ( v2 || (v2 = getenv("VDEVICE")) != 0LL )
func0(v2, a2);
else
func0((const char *)&LC26, a2);
if ( LOBYTE(vdevice[0]) )
{
func2();
if ( allocated )
goto LABEL_5;
LABEL_12:
allocated = 1;
deflinestyle(0LL, 0xFFFFLL);
v9 = vallocate(72LL);
*(_QWORD *)(v9 + 64) = 0LL;
vdevice[3] = v9;
v10 = vallocate(24LL);
vdevice[4] = v10;
*(_QWORD *)(v10 + 16) = 0LL;
v11 = vallocate(24LL);
vdevice[5] = v11;
*(_QWORD *)(v11 + 16) = 0LL;
vdevice[63] = vallocate(640LL);
v12 = vallocate(34LL);
vdevice[64] = v12;
v3 = v12;
goto LABEL_6;
}
if ( !allocated )
goto LABEL_12;
LABEL_5:
v3 = vdevice[64];
LABEL_6:
v4 = 0LL;
while ( 1 )
{
*(_BYTE *)(v3 + v4++) = 0;
if ( v4 == 34 )
break;
v3 = vdevice[64];
}
v5 = vdevice[64];
BYTE4(vdevice[65]) = 1;
vdevice[66] = 261LL;
*(_BYTE *)(v5 + 32) |= 0x20u;
v6 = vdevice[4];
BYTE5(vdevice[65]) = 0;
HIWORD(vdevice[65]) = 0;
LODWORD(vdevice[67]) = 0;
HIDWORD(vdevice[8]) = 1065353216;
LODWORD(vdevice[65]) = 2;
BYTE1(vdevice[0]) = 0;
BYTE6(vdevice[0]) = 1;
*(_WORD *)(v6 + 14) = 1;
*(_DWORD *)(v6 + 8) = 0;
*(_WORD *)v6 = 0;
if ( !((unsigned int (*)(void))vdevice[33])() )
{
fwrite("vogl: error while setting up device\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
LOBYTE(vdevice[0]) = 1;
WORD1(vdevice[0]) = 0;
v7 = (unsigned int)(__int16)(WORD2(vdevice[16]) - 1);
viewport(0LL, v7, 0LL, (unsigned int)(__int16)(LOWORD(vdevice[17]) - 1));
ortho2(0.0, (float)(HIDWORD(vdevice[16]) - 1), 0.0, (float)(LODWORD(vdevice[17]) - 1));
move(0, v7);
font(0LL, 0.0, 0.0);
return setlinestyle(0LL);
}

original_code:
void
ginit(void)
{
 char *dev;
 int i;
 if (vdevice.devname == (char *)((void *)0)) {
  if ((dev = getenv("VDEVICE")) == (char *)((void *)0))
   getdevice("");
  else
   getdevice(dev);
 } else
  getdevice(vdevice.devname);
 if (vdevice.initialised)
  gexit();
 if (!allocated) {
  allocated = 1;
  deflinestyle(0, 0xffff);
  vdevice.transmat = (Mstack *)vallocate(sizeof(Mstack));
  vdevice.transmat->back = (Mstack *)((void *)0);
  vdevice.attr = (Astack *)vallocate(sizeof(Astack));
  vdevice.attr->back = (Astack *)((void *)0);
  vdevice.viewport = (Vstack *)vallocate(sizeof(Vstack));
  vdevice.viewport->back = (Vstack *)((void *)0);
  vdevice.bases = (Matrix *)vallocate(sizeof(Matrix) * 10);
  vdevice.enabled = (char *)vallocate(34);
 }
 for (i = 0; i < 34; i++)
  vdevice.enabled[i] = 0;
 vdevice.alreadyread = 1;
 vdevice.data = 0;
 vdevice.devno = 261;
 vdevice.enabled[261 / 8] |= (1 << (261 & 0x7));
 vdevice.kbdmode = vdevice.mouseevents = vdevice.kbdevents = 0;
 vdevice.concave = 0;
 vdevice.clipoff = 0;
 vdevice.sync = 1;
 vdevice.cpW[3] = 1.0;
 vdevice.maxfontnum = 2;
 vdevice.attr->a.lw = 1;
 vdevice.attr->a.fontnum = 0;
 vdevice.attr->a.mode = 0;
 vdevice.attr->a.backface = 0;
 if ((*vdevice.dev.Vinit)()) {
  vdevice.initialised = 1;
  vdevice.inobject = 0;
  vdevice.inpolygon = 0;
  viewport((Screencoord)0, (Screencoord)vdevice.sizeSx - 1,
   (Screencoord)0, (Screencoord)vdevice.sizeSy - 1);
  ortho2(0.0, (Coord)(vdevice.sizeSx - 1), 0.0, (Coord)(vdevice.sizeSy - 1));
  move(0.0, 0.0, 0.0);
  font(0);
 } else {
  fprintf(stderr, "vogl: error while setting up device\n");
  exit(1);
 }
 setlinestyle(0);
}

canonical_original_code:
void ginit()
{
 char *dev;
 int i;
 if (vdevice.devname == (char *)((void *)0)) {
  if ((dev = getenv("VDEVICE")) == (char *)((void *)0))
   getdevice("");
  else
   getdevice(dev);
 } else
  getdevice(vdevice.devname);
 if (vdevice.initialised)
  gexit();
 if (!allocated) {
  allocated = 1;
  deflinestyle(0, 0xffff);
  vdevice.transmat = (struct ms *)vallocate(sizeof(Mstack));
  vdevice.transmat->back = (struct ms *)((void *)0);
  vdevice.attr = (struct as *)vallocate(sizeof(Astack));
  vdevice.attr->back = (struct as *)((void *)0);
  vdevice.viewport = (struct vs *)vallocate(sizeof(Vstack));
  vdevice.viewport->back = (struct vs *)((void *)0);
  vdevice.bases = (float (*)[4][4])vallocate(sizeof(Matrix) * 10);
  vdevice.enabled = (char *)vallocate(34);
 }
 for (i = 0; i < 34; i++)
  vdevice.enabled[i] = 0;
 vdevice.alreadyread = 1;
 vdevice.data = 0;
 vdevice.devno = 261;
 vdevice.enabled[261 / 8] |= (1 << (261 & 0x7));
 vdevice.kbdmode = vdevice.mouseevents = vdevice.kbdevents = 0;
 vdevice.concave = 0;
 vdevice.clipoff = 0;
 vdevice.sync = 1;
 vdevice.cpW[3] = 1.0;
 vdevice.maxfontnum = 2;
 vdevice.attr->a.lw = 1;
 vdevice.attr->a.fontnum = 0;
 vdevice.attr->a.mode = 0;
 vdevice.attr->a.backface = 0;
 if ((*vdevice.dev.Vinit)()) {
  vdevice.initialised = 1;
  vdevice.inobject = 0;
  vdevice.inpolygon = 0;
  viewport((short)0, (short)vdevice.sizeSx - 1,
   (short)0, (short)vdevice.sizeSy - 1);
  ortho2(0.0, (Coord)(vdevice.sizeSx - 1), 0.0, (Coord)(vdevice.sizeSy - 1));
  move(0.0, 0.0, 0.0);
  font(0);
 } else {
  fprintf(stderr, "vogl: error while setting up device\n");
  exit(1);
 }
 setlinestyle(0);
}

variable_types:
dev
char *

variable_types: i int

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

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

user_defined_types: struct vs { struct vp v; struct vs *back; }

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

user_defined_types: struct vp { float left; float right; float bottom; float top; }


winopen

decompiled_code:
__int64 __fastcall winopen(__int64 a1, __int64 a2)
{
vdevice[45] = a1;
ginit(a1, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
vdevice[45] = a1;
func4(a1, a2);
return 1LL;
}

original_code:
long
winopen(char *title)
{
 vdevice.wintitle = title;
 ginit();
 return(1L);
}

variable_types:
title
char *

return_type: long


gconfig

decompiled_code:
void gconfig()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void
gconfig(void)
{
}

canonical_original_code:
void gconfig()
{
}


vnewdev

decompiled_code:
__int64 __fastcall vnewdev(const char *a1, __int64 a2, double a3, double a4)
{
double v4; // xmm0_8
__int64 v5; // rax

if ( !LOBYTE(vdevice[0]) )
verror("vnewdev: vogl not initialised\n");
pushviewport();
((void (*)(void))vdevice[28])();
LOBYTE(vdevice[0]) = 0;
getdevice(a1, a2);
v4 = ((double (*)(void))vdevice[33])();
v5 = vdevice[4];
LOBYTE(vdevice[0]) = 1;
font((unsigned int)*(__int16 *)(v5 + 8), v4, a4);
return popviewport();
}

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

if ( !LOBYTE(vdevice[0]) )
func3("vnewdev: vogl not initialised\n");
pushviewport();
((void (*)(void))vdevice[28])();
LOBYTE(vdevice[0]) = 0;
func0(a1, a2);
v4 = ((double (*)(void))vdevice[33])();
v5 = vdevice[4];
LOBYTE(vdevice[0]) = 1;
font((unsigned int)*(__int16 *)(v5 + 8), v4, a4);
return popviewport();
}

original_code:
void
vnewdev(char *device)
{
 if (!vdevice.initialised)
  verror("vnewdev: vogl not initialised\n");
 pushviewport();
 (*vdevice.dev.Vexit)();
 vdevice.initialised = 0;
 getdevice(device);
 (*vdevice.dev.Vinit)();
 vdevice.initialised = 1;
 font(vdevice.attr->a.fontnum);
 popviewport();
}


vgetdev

decompiled_code:
char *__fastcall vgetdev(char *a1)
{
const char *v1; // rsi

v1 = (const char *)vdevice[19];
if ( v1 )
return strcpy(a1, v1);
strcpy(a1, "(no device)");
return a1;
}

canonical_decompiled_code:
char *__fastcall func8(char *a1)
{
const char *v1; // rsi

v1 = (const char *)vdevice[19];
if ( v1 )
return strcpy(a1, v1);
strcpy(a1, "(no device)");
return a1;
}

original_code:
char *
vgetdev(char *buf)
{
 if (vdevice.dev.devname)
  strcpy(buf, vdevice.dev.devname);
 else
  strcpy(buf, "(no device)");
 return(&buf[0]);
}

canonical_original_code:
char *vgetdev(char *buf)
{
 if (vdevice.dev.devname)
  strcpy(buf, vdevice.dev.devname);
 else
  strcpy(buf, "(no device)");
 return(&buf[0]);
}

variable_types:
buf
char *

return_type: char *


getvaluator

decompiled_code:
__int64 __fastcall getvaluator(__int16 a1)
{
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !LOBYTE(vdevice[0]) )
verror("getvaluator: vogl not initialised");
if ( ((unsigned int (__fastcall *)(int *, int *))vdevice[34])(&v2, v3) == -1 )
return -1LL;
if ( a1 == 1 )
return v2;
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func9(__int16 a1)
{
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !LOBYTE(vdevice[0]) )
func3("getvaluator: vogl not initialised");
if ( ((unsigned int (__fastcall *)(int *, int *))vdevice[34])(&v2, v3) == -1 )
return -1LL;
if ( a1 == 1 )
return v2;
return v3[0];
}

original_code:
long
getvaluator(Device dev)
{
 int a, b, c;
 if (!vdevice.initialised)
  verror("getvaluator: vogl not initialised");
 c = (*vdevice.dev.Vlocator)(&a, &b);
 if (c != -1) {
  if (dev == 1)
   return((long)a);
  else
   return((long)b);
 }
 return(-1);
}

canonical_original_code:
long getvaluator(unsigned short dev)
{
 int a; int b; int c;
 if (!vdevice.initialised)
  verror("getvaluator: vogl not initialised");
 c = (*vdevice.dev.Vlocator)(&a, &b);
 if (c != -1) {
  if (dev == 1)
   return((long)a);
  else
   return((long)b);
 }
 return(-1);
}

variable_types:
dev
unsigned short

variable_types: a int

variable_types: b int

variable_types: c int


getbutton

decompiled_code:
__int64 __fastcall getbutton(unsigned __int16 a1)
{
int v1; // eax
__int64 result; // rax
unsigned int v3; // eax
char v4[4]; // [rsp+8h] [rbp-10h] BYREF
char v5[12]; // [rsp+Ch] [rbp-Ch] BYREF

if ( a1 > 0xFFu )
{
result = -1LL;
if ( a1 <= 0x104u )
{
v3 = ((__int64 (__fastcall *)(char *, char *))vdevice[34])(v4, v5);
if ( a1 == 260 && (v3 & 1) != 0 || (v3 & 2) != 0 && a1 == 259 )
result = 1LL;
else
result = (v3 >> 2) & (unsigned __int64)(a1 == 258);
}
}
else
{
v1 = ((__int64 (*)(void))vdevice[24])();
if ( (unsigned int)(v1 - 97) < 0x1A )
v1 -= 32;
result = a1 == v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 a1)
{
int v1; // eax
__int64 result; // rax
unsigned int v3; // eax
char v4[4]; // [rsp+8h] [rbp-10h] BYREF
char v5[12]; // [rsp+Ch] [rbp-Ch] BYREF

if ( a1 > 0xFFu )
{
result = -1LL;
if ( a1 <= 0x104u )
{
v3 = ((__int64 (__fastcall *)(char *, char *))vdevice[34])(v4, v5);
if ( a1 == 260 && (v3 & 1) != 0 || (v3 & 2) != 0 && a1 == 259 )
result = 1LL;
else
result = (v3 >> 2) & (unsigned __int64)(a1 == 258);
}
}
else
{
v1 = ((__int64 (*)(void))vdevice[24])();
if ( (unsigned int)(v1 - 97) < 0x1A )
v1 -= 32;
result = a1 == v1;
}
return result;
}

original_code:
Boolean
getbutton(Device dev)
{
 int a, b, c;
 if (dev < 256) {
  c = (*vdevice.dev.Vcheckkey)();
  if (c >= 'a' && c <= 'z')
   c = c - 'a' + 'A';
  if (c == dev)
   return(1);
  return(0);
 } else if (dev < 261) {
  c = (*vdevice.dev.Vlocator)(&a, &b);
  if (c & 0x01 && dev == 260)
   return(1);
  if (c & 0x02 && dev == 259)
   return(1);
  if (c & 0x04 && dev == 258)
   return(1);
  return(0);
 }
 return(-1);
}

canonical_original_code:
long getbutton(unsigned short dev)
{
 int a; int b; int c;
 if (dev < 256) {
  c = (*vdevice.dev.Vcheckkey)();
  if (c >= 'a' && c <= 'z')
   c = c - 'a' + 'A';
  if (c == dev)
   return(1);
  return(0);
 } else if (dev < 261) {
  c = (*vdevice.dev.Vlocator)(&a, &b);
  if (c & 0x01 && dev == 260)
   return(1);
  if (c & 0x02 && dev == 259)
   return(1);
  if (c & 0x04 && dev == 258)
   return(1);
  return(0);
 }
 return(-1);
}


getdev

original_code:
void
getdev(long int n, Device *devs, short int *vals)
{
 int i;
 for( i=0; i < n; i++)
  vals[i] = (short)getvaluator(devs[i]);
}

canonical_original_code:
void getdev(long n, unsigned short *devs, short *vals)
{
 int i;
 for( i=0; i < n; i++)
  vals[i] = (short)getvaluator(devs[i]);
}

variable_types: n long

variable_types:
devs
unsigned short *

variable_types:
vals
short *


clear

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

if ( !LOBYTE(vdevice[0]) )
verror("clear: vogl not initialised");
if ( !BYTE2(vdevice[0]) )
return (_DWORD *)((__int64 (*)(void))vdevice[25])();
result = (_DWORD *)newtokens(1LL);
*result = 6;
return result;
}

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

if ( !LOBYTE(vdevice[0]) )
func3("clear: vogl not initialised");
if ( !BYTE2(vdevice[0]) )
return (_DWORD *)((__int64 (*)(void))vdevice[25])();
result = (_DWORD *)newtokens(1LL);
*result = 6;
return result;
}

original_code:
void
clear(void)
{
 Token *tok;
 if (!vdevice.initialised)
  verror("clear: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 6;
  return;
 }
 (*vdevice.dev.Vclear)();
}

canonical_original_code:
void clear()
{
 union tk *tok;
 if (!vdevice.initialised)
  verror("clear: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 6;
  return;
 }
 (*vdevice.dev.Vclear)();
}

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


getplanes

decompiled_code:
__int64 getplanes()
{
if ( !LOBYTE(vdevice[0]) )
verror("getdepth: vogl not initialised\n");
return SLODWORD(vdevice[13]);
}

canonical_decompiled_code:
__int64 func13()
{
if ( !LOBYTE(vdevice[0]) )
func3("getdepth: vogl not initialised\n");
return SLODWORD(vdevice[13]);
}

original_code:
long
getplanes(void)
{
 if (!vdevice.initialised)
  verror("getdepth: vogl not initialised\n");
 return((long)vdevice.depth);
}

canonical_original_code:
long getplanes()
{
 if (!vdevice.initialised)
  verror("getdepth: vogl not initialised\n");
 return((long)vdevice.depth);
}


reshapeviewport

decompiled_code:
__int64 reshapeviewport()
{
return viewport(
0LL,
(unsigned int)(__int16)(HIDWORD(vdevice[16]) - 1),
0LL,
(unsigned int)(__int16)(LOWORD(vdevice[17]) - 1));
}

canonical_decompiled_code:
__int64 func14()
{
return viewport(
0LL,
(unsigned int)(__int16)(HIDWORD(vdevice[16]) - 1),
0LL,
(unsigned int)(__int16)(LOWORD(vdevice[17]) - 1));
}

original_code:
void
reshapeviewport(void)
{
 viewport(0, vdevice.sizeSx - 1, 0, vdevice.sizeSy - 1);
}

canonical_original_code:
void reshapeviewport()
{
 viewport(0, vdevice.sizeSx - 1, 0, vdevice.sizeSy - 1);
}


getgdesc

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

if ( a1 == 1 )
{
result = 500LL;
if ( LOBYTE(vdevice[0]) )
result = SHIDWORD(vdevice[16]);
}
else if ( a1 == 2 )
{
result = 500LL;
if ( LOBYTE(vdevice[0]) )
result = SLODWORD(vdevice[17]);
}
else
{
result = -1LL;
}
return result;
}

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

if ( a1 == 1 )
{
result = 500LL;
if ( LOBYTE(vdevice[0]) )
result = SHIDWORD(vdevice[16]);
}
else if ( a1 == 2 )
{
result = 500LL;
if ( LOBYTE(vdevice[0]) )
result = SLODWORD(vdevice[17]);
}
else
{
result = -1LL;
}
return result;
}

original_code:
long
getgdesc(long int inq)
{
 switch (inq) {
 case 1:
  if (vdevice.initialised)
   return((long)vdevice.sizeSx);
  else
   return(500L);
 case 2:
  if (vdevice.initialised)
   return((long)vdevice.sizeSy);
  else
   return(500L);
 default:
  return(-1L);
 }
}

canonical_original_code:
long getgdesc(long inq)
{
 switch (inq) {
 case 1:
  if (vdevice.initialised)
   return((long)vdevice.sizeSx);
  else
   return(500L);
 case 2:
  if (vdevice.initialised)
   return((long)vdevice.sizeSy);
  else
   return(500L);
 default:
  return(-1L);
 }
}

variable_types: inq long


vflush

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

if ( !LOBYTE(vdevice[0]) )
verror("vflush: vogl not initialised");
if ( !BYTE2(vdevice[0]) )
return (_DWORD *)((__int64 (*)(void))vdevice[41])();
result = (_DWORD *)newtokens(1LL);
*result = 70;
return result;
}

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

if ( !LOBYTE(vdevice[0]) )
func3("vflush: vogl not initialised");
if ( !BYTE2(vdevice[0]) )
return (_DWORD *)((__int64 (*)(void))vdevice[41])();
result = (_DWORD *)newtokens(1LL);
*result = 70;
return result;
}

original_code:
void
vflush(void)
{
 Token *tok;
 if (!vdevice.initialised)
  verror("vflush: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 70;
  return;
 }
 (*vdevice.dev.Vsync)();
}

canonical_original_code:
void vflush()
{
 union tk *tok;
 if (!vdevice.initialised)
  verror("vflush: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 70;
  return;
 }
 (*vdevice.dev.Vsync)();
}


pushviewport

decompiled_code:
__int64 pushviewport()
{
__int64 result; // rax
int *v1; // rdx
__int64 v2; // rcx
int v3; // xmm0_4
int *v4; // rdx
int v5; // xmm0_4

if ( vdevice )
{
if ( *((_BYTE *)&vdevice + 2) )
{
result = newtokens(1LL);
*(_DWORD *)result = 27;
}
else
{
result = vsfree;
if ( vsfree )
{
v1 = (int *)*((_QWORD *)&vdevice + 5);
v2 = *(_QWORD *)(vsfree + 16);
*((_QWORD *)&vdevice + 5) = vsfree;
v3 = *v1;
*(_QWORD *)(result + 16) = v1;
vsfree = v2;
*(_DWORD *)result = v3;
*(_DWORD *)(result + 4) = v1[1];
*(_DWORD *)(result + 8) = v1[2];
*(_DWORD *)(result + 12) = v1[3];
}
else
{
result = vallocate(24LL);
v4 = (int *)*((_QWORD *)&vdevice + 5);
v5 = *v4;
*(_QWORD *)(result + 16) = v4;
*(_DWORD *)result = v5;
*(_DWORD *)(result + 4) = v4[1];
*(_DWORD *)(result + 8) = v4[2];
*(_DWORD *)(result + 12) = v4[3];
*((_QWORD *)&vdevice + 5) = result;
}
}
}
else
{
verror("pushviewport: vogl not initialised");
result = popviewport();
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int *v1; // rdx
__int64 v2; // rcx
int v3; // xmm0_4
int *v4; // rdx
int v5; // xmm0_4

if ( vdevice )
{
if ( *((_BYTE *)&vdevice + 2) )
{
result = newtokens(1LL);
*(_DWORD *)result = 27;
}
else
{
result = vsfree;
if ( vsfree )
{
v1 = (int *)*((_QWORD *)&vdevice + 5);
v2 = *(_QWORD *)(vsfree + 16);
*((_QWORD *)&vdevice + 5) = vsfree;
v3 = *v1;
*(_QWORD *)(result + 16) = v1;
vsfree = v2;
*(_DWORD *)result = v3;
*(_DWORD *)(result + 4) = v1[1];
*(_DWORD *)(result + 8) = v1[2];
*(_DWORD *)(result + 12) = v1[3];
}
else
{
result = vallocate(24LL);
v4 = (int *)*((_QWORD *)&vdevice + 5);
v5 = *v4;
*(_QWORD *)(result + 16) = v4;
*(_DWORD *)result = v5;
*(_DWORD *)(result + 4) = v4[1];
*(_DWORD *)(result + 8) = v4[2];
*(_DWORD *)(result + 12) = v4[3];
*((_QWORD *)&vdevice + 5) = result;
}
}
}
else
{
verror("pushviewport: vogl not initialised");
result = func1();
}
return result;
}

original_code:
void
pushviewport(void)
{
 Vstack *nvport;
 Token *tok;
 if (!vdevice.initialised)
  verror("pushviewport: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 27;
  return;
 }
 if (vsfree != (Vstack *)((void *)0)) {
  nvport = vdevice.viewport;
  vdevice.viewport = vsfree;
  vsfree = vsfree->back;
  vdevice.viewport->back = nvport;
  vdevice.viewport->v.left = nvport->v.left;
  vdevice.viewport->v.right = nvport->v.right;
  vdevice.viewport->v.bottom = nvport->v.bottom;
  vdevice.viewport->v.top = nvport->v.top;
 } else {
  nvport = (Vstack *)vallocate(sizeof(Vstack));
  nvport->back = vdevice.viewport;
  nvport->v.left = vdevice.viewport->v.left;
  nvport->v.right = vdevice.viewport->v.right;
  nvport->v.bottom = vdevice.viewport->v.bottom;
  nvport->v.top = vdevice.viewport->v.top;
  vdevice.viewport = nvport;
 }
}

canonical_original_code:
void pushviewport()
{
 struct vs *nvport;
 union tk *tok;
 if (!vdevice.initialised)
  verror("pushviewport: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 27;
  return;
 }
 if (vsfree != (struct vs *)((void *)0)) {
  nvport = vdevice.viewport;
  vdevice.viewport = vsfree;
  vsfree = vsfree->back;
  vdevice.viewport->back = nvport;
  vdevice.viewport->v.left = nvport->v.left;
  vdevice.viewport->v.right = nvport->v.right;
  vdevice.viewport->v.bottom = nvport->v.bottom;
  vdevice.viewport->v.top = nvport->v.top;
 } else {
  nvport = (struct vs *)vallocate(sizeof(Vstack));
  nvport->back = vdevice.viewport;
  nvport->v.left = vdevice.viewport->v.left;
  nvport->v.right = vdevice.viewport->v.right;
  nvport->v.bottom = vdevice.viewport->v.bottom;
  nvport->v.top = vdevice.viewport->v.top;
  vdevice.viewport = nvport;
 }
}

variable_types: struct vs { struct vp { float left; float right; float bottom; float top; } v; struct vs *back; } *


popviewport

decompiled_code:
_DWORD *popviewport()
{
__int64 v0; // rcx
float *v1; // rdx
float v2; // xmm0_4
__int64 v3; // rsi
float v4; // xmm1_4
float v5; // xmm2_4
float v6; // xmm0_4
float v7; // xmm1_4
int v8; // ecx
float v9; // xmm0_4
float v10; // xmm2_4
float v11; // xmm0_4
_DWORD *result; // rax

if ( vdevice )
{
if ( *((_BYTE *)&vdevice + 2) )
{
result = (_DWORD *)newtokens(1LL);
*result = 24;
return result;
}
v0 = *((_QWORD *)&vdevice + 5);
v1 = *(float **)(v0 + 16);
if ( v1 )
{
v2 = v1[1];
v3 = vsfree;
*((_QWORD *)&vdevice + 5) = v1;
v4 = (float)*((int *)&vdevice + 33);
vsfree = v0;
v5 = v1[3];
*(_QWORD *)(v0 + 16) = v3;
v6 = v2 * v4;
v7 = v4 * *v1;
v8 = (int)v6;
v9 = (float)*((int *)&vdevice + 34);
*((_DWORD *)&vdevice + 27) = v8;
v10 = v5 * v9;
v11 = v9 * v1[2];
*((_DWORD *)&vdevice + 29) = (int)v10;
*((_DWORD *)&vdevice + 30) = (int)v11;
*((_DWORD *)&vdevice + 28) = (int)v7;
return (_DWORD *)CalcW2Vcoeffs();
}
}
else
{
verror("popviewport: vogl not initialised");
}
verror("popviewport: viewport stack underflow");
return (_DWORD *)viewport();
}

canonical_decompiled_code:
_DWORD *func1()
{
__int64 v0; // rcx
float *v1; // rdx
float v2; // xmm0_4
__int64 v3; // rsi
float v4; // xmm1_4
float v5; // xmm2_4
float v6; // xmm0_4
float v7; // xmm1_4
int v8; // ecx
float v9; // xmm0_4
float v10; // xmm2_4
float v11; // xmm0_4
_DWORD *result; // rax

if ( vdevice )
{
if ( *((_BYTE *)&vdevice + 2) )
{
result = (_DWORD *)newtokens(1LL);
*result = 24;
return result;
}
v0 = *((_QWORD *)&vdevice + 5);
v1 = *(float **)(v0 + 16);
if ( v1 )
{
v2 = v1[1];
v3 = vsfree;
*((_QWORD *)&vdevice + 5) = v1;
v4 = (float)*((int *)&vdevice + 33);
vsfree = v0;
v5 = v1[3];
*(_QWORD *)(v0 + 16) = v3;
v6 = v2 * v4;
v7 = v4 * *v1;
v8 = (int)v6;
v9 = (float)*((int *)&vdevice + 34);
*((_DWORD *)&vdevice + 27) = v8;
v10 = v5 * v9;
v11 = v9 * v1[2];
*((_DWORD *)&vdevice + 29) = (int)v10;
*((_DWORD *)&vdevice + 30) = (int)v11;
*((_DWORD *)&vdevice + 28) = (int)v7;
return (_DWORD *)CalcW2Vcoeffs();
}
}
else
{
verror("popviewport: vogl not initialised");
}
verror("popviewport: viewport stack underflow");
return (_DWORD *)viewport();
}

original_code:
void
popviewport(void)
{
 Token *tok;
 Vstack *nvport;
 if (!vdevice.initialised)
  verror("popviewport: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 24;
  return;
 }
 if (vdevice.viewport->back == (Vstack *)((void *)0))
  verror("popviewport: viewport stack underflow");
 else {
  nvport = vdevice.viewport;
  vdevice.viewport = vdevice.viewport->back;
  nvport->back = vsfree;
  vsfree = nvport;
 }
 vdevice.maxVx = vdevice.viewport->v.right * vdevice.sizeSx;
 vdevice.maxVy = vdevice.viewport->v.top * vdevice.sizeSy;
 vdevice.minVx = vdevice.viewport->v.left * vdevice.sizeSx;
 vdevice.minVy = vdevice.viewport->v.bottom * vdevice.sizeSy;
 CalcW2Vcoeffs();
}

canonical_original_code:
void popviewport()
{
 union tk *tok;
 struct vs *nvport;
 if (!vdevice.initialised)
  verror("popviewport: vogl not initialised");
 if (vdevice.inobject) {
  tok = newtokens(1);
  tok->i = 24;
  return;
 }
 if (vdevice.viewport->back == (struct vs *)((void *)0))
  verror("popviewport: viewport stack underflow");
 else {
  nvport = vdevice.viewport;
  vdevice.viewport = vdevice.viewport->back;
  nvport->back = vsfree;
  vsfree = nvport;
 }
 vdevice.maxVx = vdevice.viewport->v.right * vdevice.sizeSx;
 vdevice.maxVy = vdevice.viewport->v.top * vdevice.sizeSy;
 vdevice.minVx = vdevice.viewport->v.left * vdevice.sizeSx;
 vdevice.minVy = vdevice.viewport->v.bottom * vdevice.sizeSy;
 CalcW2Vcoeffs();
}


normallookat

original_code:
static void
normallookat(float vx, float vy, float vz, float px, float py, float pz)
{
 float l2, l3, sintheta, sinphi, costheta, cosphi;
 Matrix tmp;
 l2 = sqrt((double)((((px - vx))*((px - vx))) + (((pz - vz))*((pz - vz)))));
 l3 = sqrt((double)((((px - vx))*((px - vx))) + (((py - vy))*((py - vy))) + (((pz - vz))*((pz - vz)))));
 if (l3 != 0.0) {
  sinphi = (vy - py) / l3;
  cosphi = l2 / l3;
  identmatrix(tmp);
  tmp[1][1] = tmp[2][2] = cosphi;
  tmp[1][2] = sinphi;
  tmp[2][1] = -sinphi;
  multmatrix(tmp);
 }
 if (l2 != 0.0) {
  sintheta = (px - vx) / l2;
  costheta = (vz - pz) / l2;
  identmatrix(tmp);
  tmp[0][0] = tmp[2][2] = costheta;
  tmp[0][2] = -sintheta;
  tmp[2][0] = sintheta;
  multmatrix(tmp);
 }
}

canonical_original_code:
static void normallookat(float vx, float vy, float vz, float px, float py, float pz)
{
 float l2; float l3; float sintheta; float sinphi; float costheta; float cosphi;
 float tmp[4][4];
 l2 = sqrt((double)((((px - vx))*((px - vx))) + (((pz - vz))*((pz - vz)))));
 l3 = sqrt((double)((((px - vx))*((px - vx))) + (((py - vy))*((py - vy))) + (((pz - vz))*((pz - vz)))));
 if (l3 != 0.0) {
  sinphi = (vy - py) / l3;
  cosphi = l2 / l3;
  identmatrix(tmp);
  tmp[1][1] = tmp[2][2] = cosphi;
  tmp[1][2] = sinphi;
  tmp[2][1] = -sinphi;
  multmatrix(tmp);
 }
 if (l2 != 0.0) {
  sintheta = (px - vx) / l2;
  costheta = (vz - pz) / l2;
  identmatrix(tmp);
  tmp[0][0] = tmp[2][2] = costheta;
  tmp[0][2] = -sintheta;
  tmp[2][0] = sintheta;
  multmatrix(tmp);
 }
}

variable_types: vx float

variable_types: vy float

variable_types: vz float

variable_types: px float

variable_types: py float

variable_types: pz float

variable_types: sintheta float

variable_types: sinphi float

variable_types: costheta float

variable_types: cosphi float

variable_types:
tmp
float [4][4]


polarview

decompiled_code:
__int64 __fastcall polarview(__int16 a1, __int16 a2, __int16 a3, double a4)
{
__int64 result; // rax

if ( vdevice )
{
translate(0.0, 0.0, COERCE_DOUBLE(*(_QWORD *)&a4 ^ LC1));
rotate((unsigned int)(__int16)-a3, 122LL);
rotate((unsigned int)(__int16)-a2, 120LL);
result = rotate((unsigned int)(__int16)-a1, 122LL);
}
else
{
verror("polarview: vogl not initialised");
result = lookat();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1, __int16 a2, __int16 a3, double a4)
{
__int64 result; // rax

if ( vdevice )
{
translate(0.0, 0.0, COERCE_DOUBLE(*(_QWORD *)&a4 ^ LC1));
rotate((unsigned int)(__int16)-a3, 122LL);
rotate((unsigned int)(__int16)-a2, 120LL);
result = rotate((unsigned int)(__int16)-a1, 122LL);
}
else
{
verror("polarview: vogl not initialised");
result = func2();
}
return result;
}

original_code:
void
polarview(Coord dist, Angle azim, Angle inc, Angle twist)
{
 if (!vdevice.initialised)
  verror("polarview: vogl not initialised");
 translate(0.0, 0.0, -dist);
 rotate(-twist, 'z');
 rotate(-inc, 'x');
 rotate(-azim, 'z');
}

canonical_original_code:
void polarview(float dist, short azim, short inc, short twist)
{
 if (!vdevice.initialised)
  verror("polarview: vogl not initialised");
 translate(0.0, 0.0, -dist);
 rotate(-twist, 'z');
 rotate(-inc, 'x');
 rotate(-azim, 'z');
}

variable_types: dist float

variable_types: azim short

variable_types: inc short

variable_types: twist short


lookat

decompiled_code:
__int64 __fastcall lookat(__int16 a1, __m128i a2, float a3, float a4, float a5, float a6, float a7)
{
unsigned int v7; // ebx
__int64 result; // rax

if ( vdevice )
{
v7 = _mm_cvtsi128_si32(a2);
rotate((unsigned int)(__int16)-a1, 122LL);
normallookat(*(float *)&v7, a3, a4, a5, a6, a7);
result = translate(
COERCE_DOUBLE(_mm_cvtsi32_si128(v7).m128i_u64[0] ^ (unsigned int)LC1),
COERCE_DOUBLE(LODWORD(a3) ^ (unsigned __int64)(unsigned int)LC1),
COERCE_DOUBLE(LODWORD(a4) ^ (unsigned __int64)(unsigned int)LC1));
}
else
{
verror("lookat: vogl not initialised");
result = perspective();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __m128i a2, float a3, float a4, float a5, float a6, float a7)
{
unsigned int v7; // ebx
__int64 result; // rax

if ( vdevice )
{
v7 = _mm_cvtsi128_si32(a2);
rotate((unsigned int)(__int16)-a1, 122LL);
func0(*(float *)&v7, a3, a4, a5, a6, a7);
result = translate(
COERCE_DOUBLE(_mm_cvtsi32_si128(v7).m128i_u64[0] ^ (unsigned int)LC1),
COERCE_DOUBLE(LODWORD(a3) ^ (unsigned __int64)(unsigned int)LC1),
COERCE_DOUBLE(LODWORD(a4) ^ (unsigned __int64)(unsigned int)LC1));
}
else
{
verror("lookat: vogl not initialised");
result = func3();
}
return result;
}

original_code:
void
lookat(Coord vx, Coord vy, Coord vz, Coord px, Coord py, Coord pz, Angle twist)
{
 if (!vdevice.initialised)
  verror("lookat: vogl not initialised");
 rotate(-twist, 'z');
 normallookat(vx, vy, vz, px, py, pz);
 translate(-vx, -vy, -vz);
}

canonical_original_code:
void lookat(float vx, float vy, float vz, float px, float py, float pz, short twist)
{
 if (!vdevice.initialised)
  verror("lookat: vogl not initialised");
 rotate(-twist, 'z');
 normallookat(vx, vy, vz, px, py, pz);
 translate(-vx, -vy, -vz);
}


perspective

decompiled_code:
__int64 __fastcall perspective(__int16 a1, float a2, float a3, float a4, float a5)
{
bool v6; // zf
float v7; // xmm0_4
int v8; // xmm0_4
int v9; // xmm2_4
float v11; // [rsp+4h] [rbp-74h]
double cosx; // [rsp+10h] [rbp-68h] BYREF
double sinx; // [rsp+18h] [rbp-60h] BYREF
int v14[22]; // [rsp+20h] [rbp-58h] BYREF

if ( !vdevice )
goto LABEL_11;
if ( a2 == 0.0 )
{
verror("perspective: can't have zero aspect ratio!");
}
else
{
a5 = a4 - a3;
v6 = (float)(a4 - a3) == 0.0;
}
if ( v6 )
{
verror("perspective: near clipping plane same as far one.");
LABEL_11:
verror("perspective: vogl not initialised");
goto LABEL_12;
}
if ( a1 && a1 != 1800 )
{
v11 = a2;
identmatrix(v14);
v7 = (double)a1 / 10.0;
sincos(v7 * 0.01745329251994328 * 0.5, &sinx, &cosx);
*(float *)&v8 = cosx / sinx;
v14[5] = v8;
v14[11] = -1082130432;
v14[15] = 0;
*(float *)v14 = *(float *)&v8 / v11;
*(float *)&v14[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / a5;
*(float *)&v9 = a4 * -2.0 * a3 / a5;
v14[14] = v9;
return loadmatrix(v14);
}
LABEL_12:
verror("perspective: bad field of view passed.");
return window();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1, float a2, float a3, float a4, float a5)
{
bool v6; // zf
float v7; // xmm0_4
int v8; // xmm0_4
int v9; // xmm2_4
float v11; // [rsp+4h] [rbp-74h]
double cosx; // [rsp+10h] [rbp-68h] BYREF
double sinx; // [rsp+18h] [rbp-60h] BYREF
int v14[22]; // [rsp+20h] [rbp-58h] BYREF

if ( !vdevice )
goto LABEL_11;
if ( a2 == 0.0 )
{
verror("perspective: can't have zero aspect ratio!");
}
else
{
a5 = a4 - a3;
v6 = (float)(a4 - a3) == 0.0;
}
if ( v6 )
{
verror("perspective: near clipping plane same as far one.");
LABEL_11:
verror("perspective: vogl not initialised");
goto LABEL_12;
}
if ( a1 && a1 != 1800 )
{
v11 = a2;
identmatrix(v14);
v7 = (double)a1 / 10.0;
sincos(v7 * 0.01745329251994328 * 0.5, &sinx, &cosx);
*(float *)&v8 = cosx / sinx;
v14[5] = v8;
v14[11] = -1082130432;
v14[15] = 0;
*(float *)v14 = *(float *)&v8 / v11;
*(float *)&v14[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / a5;
*(float *)&v9 = a4 * -2.0 * a3 / a5;
v14[14] = v9;
return loadmatrix(v14);
}
LABEL_12:
verror("perspective: bad field of view passed.");
return func4();
}

original_code:
void
perspective(Angle ifov, float aspect, Coord hither, Coord yon)
{
 Matrix mat;
 float fov;
 if (!vdevice.initialised)
  verror("perspective: vogl not initialised");
 if (aspect == 0.0)
  verror("perspective: can't have zero aspect ratio!");
 if ((yon - hither) == 0.0)
  verror("perspective: near clipping plane same as far one.");
 if (ifov == 0 || ifov == 1800)
  verror("perspective: bad field of view passed.");
 fov = ifov / 10.0;
 identmatrix(mat);
 mat[0][0] = ((float)(cos((double)(((3.14159265358979 / 180.0) * fov / 2.0))) / sin((double)(((3.14159265358979 / 180.0) * fov / 2.0))))) / aspect;
 mat[1][1] = ((float)(cos((double)(((3.14159265358979 / 180.0) * fov / 2.0))) / sin((double)(((3.14159265358979 / 180.0) * fov / 2.0)))));
 mat[2][2] = -(yon + hither) / (yon - hither);
 mat[2][3] = -1;
 mat[3][2] = -2.0 * yon * hither / (yon - hither);
 mat[3][3] = 0;
 loadmatrix(mat);
}

canonical_original_code:
void perspective(short ifov, float aspect, float hither, float yon)
{
 float mat[4][4];
 float fov;
 if (!vdevice.initialised)
  verror("perspective: vogl not initialised");
 if (aspect == 0.0)
  verror("perspective: can't have zero aspect ratio!");
 if ((yon - hither) == 0.0)
  verror("perspective: near clipping plane same as far one.");
 if (ifov == 0 || ifov == 1800)
  verror("perspective: bad field of view passed.");
 fov = ifov / 10.0;
 identmatrix(mat);
 mat[0][0] = ((float)(cos((double)(((3.14159265358979 / 180.0) * fov / 2.0))) / sin((double)(((3.14159265358979 / 180.0) * fov / 2.0))))) / aspect;
 mat[1][1] = ((float)(cos((double)(((3.14159265358979 / 180.0) * fov / 2.0))) / sin((double)(((3.14159265358979 / 180.0) * fov / 2.0)))));
 mat[2][2] = -(yon + hither) / (yon - hither);
 mat[2][3] = -1;
 mat[3][2] = -2.0 * yon * hither / (yon - hither);
 mat[3][3] = 0;
 loadmatrix(mat);
}

variable_types: ifov short

variable_types: aspect float

variable_types: hither float

variable_types: yon float

variable_types:
mat
float [4][4]

variable_types: fov float


window

decompiled_code:
__int64 __fastcall window(float a1, float a2, float a3, float a4, float a5, float a6, double a7, float a8)
{
float v8; // xmm9_4
float v9; // xmm10_4
bool v10; // zf
bool v11; // zf
double v12; // xmm8_8
float v13; // xmm11_4
int v14; // xmm5_4
int v15; // xmm6_4
float v17; // [rsp+28h] [rbp-50h]
float v18; // [rsp+2Ch] [rbp-4Ch]
int v19[18]; // [rsp+30h] [rbp-48h] BYREF

if ( vdevice )
{
v9 = a2 - a1;
if ( (float)(a2 - a1) != 0.0 )
{
v8 = a4 - a3;
v10 = (float)(a4 - a3) == 0.0;
goto LABEL_10;
}
verror("window: left clipping plane same as right one.");
while ( 1 )
{
if ( !v11 )
{
v18 = a6;
v17 = a5;
identmatrix(v19);
v12 = v17;
v19[11] = -1082130432;
v19[15] = 0;
*(float *)&v19[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(v17 + v18) ^ LC1) / a8;
v13 = (v12 + v12) / v9;
*(float *)v19 = v13;
*(float *)&v14 = v18 * -2.0 * v17 / a8;
v19[14] = v14;
*(float *)&v15 = (v12 + v12) / v8;
v19[5] = v15;
*(float *)&v19[8] = (float)(a2 + a1) / v9;
*(float *)&v19[9] = (float)(a4 + a3) / v8;
return loadmatrix(v19);
}
verror("window: near clipping plane same as far one.");
LABEL_10:
if ( v10 )
break;
a8 = a6 - a5;
v11 = (float)(a6 - a5) == 0.0;
}
verror("window: bottom clipping plane same as top one.");
}
verror("window: vogl not initialised");
return ortho();
}

canonical_decompiled_code:
__int64 __fastcall func4(float a1, float a2, float a3, float a4, float a5, float a6, double a7, float a8)
{
float v8; // xmm9_4
float v9; // xmm10_4
bool v10; // zf
bool v11; // zf
double v12; // xmm8_8
float v13; // xmm11_4
int v14; // xmm5_4
int v15; // xmm6_4
float v17; // [rsp+28h] [rbp-50h]
float v18; // [rsp+2Ch] [rbp-4Ch]
int v19[18]; // [rsp+30h] [rbp-48h] BYREF

if ( vdevice )
{
v9 = a2 - a1;
if ( (float)(a2 - a1) != 0.0 )
{
v8 = a4 - a3;
v10 = (float)(a4 - a3) == 0.0;
goto LABEL_10;
}
verror("window: left clipping plane same as right one.");
while ( 1 )
{
if ( !v11 )
{
v18 = a6;
v17 = a5;
identmatrix(v19);
v12 = v17;
v19[11] = -1082130432;
v19[15] = 0;
*(float *)&v19[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(v17 + v18) ^ LC1) / a8;
v13 = (v12 + v12) / v9;
*(float *)v19 = v13;
*(float *)&v14 = v18 * -2.0 * v17 / a8;
v19[14] = v14;
*(float *)&v15 = (v12 + v12) / v8;
v19[5] = v15;
*(float *)&v19[8] = (float)(a2 + a1) / v9;
*(float *)&v19[9] = (float)(a4 + a3) / v8;
return loadmatrix(v19);
}
verror("window: near clipping plane same as far one.");
LABEL_10:
if ( v10 )
break;
a8 = a6 - a5;
v11 = (float)(a6 - a5) == 0.0;
}
verror("window: bottom clipping plane same as top one.");
}
verror("window: vogl not initialised");
return func5();
}

original_code:
void
window(Coord left, Coord right, Coord bottom, Coord top, Coord hither, Coord yon)
{
 Matrix mat;
 if (!vdevice.initialised)
  verror("window: vogl not initialised");
 if ((right - left) == 0.0)
  verror("window: left clipping plane same as right one.");
 if ((top - bottom) == 0.0)
  verror("window: bottom clipping plane same as top one.");
 if ((yon - hither) == 0.0)
  verror("window: near clipping plane same as far one.");
 identmatrix(mat);
 mat[0][0] = 2.0 * hither / (right - left);
 mat[1][1] = 2.0 * hither / (top - bottom);
 mat[2][0] = (right + left) / (right - left);
 mat[2][1] = (top + bottom) / (top - bottom);
 mat[2][2] = -(yon + hither) / (yon - hither);
 mat[2][3] = -1.0;
 mat[3][2] = -2.0 * yon * hither / (yon - hither);
 mat[3][3] = 0.0;
 loadmatrix(mat);
}

canonical_original_code:
void window(float left, float right, float bottom, float top, float hither, float yon)
{
 float mat[4][4];
 if (!vdevice.initialised)
  verror("window: vogl not initialised");
 if ((right - left) == 0.0)
  verror("window: left clipping plane same as right one.");
 if ((top - bottom) == 0.0)
  verror("window: bottom clipping plane same as top one.");
 if ((yon - hither) == 0.0)
  verror("window: near clipping plane same as far one.");
 identmatrix(mat);
 mat[0][0] = 2.0 * hither / (right - left);
 mat[1][1] = 2.0 * hither / (top - bottom);
 mat[2][0] = (right + left) / (right - left);
 mat[2][1] = (top + bottom) / (top - bottom);
 mat[2][2] = -(yon + hither) / (yon - hither);
 mat[2][3] = -1.0;
 mat[3][2] = -2.0 * yon * hither / (yon - hither);
 mat[3][3] = 0.0;
 loadmatrix(mat);
}

variable_types: left float

variable_types: right float

variable_types: bottom float

variable_types: top float


ortho

decompiled_code:
__int64 __fastcall ortho(float a1, float a2, float a3, float a4, float a5, float a6, float a7)
{
float v7; // xmm8_4
float v8; // xmm9_4
bool v9; // zf
bool v10; // zf
float v12; // [rsp+28h] [rbp-50h]
float v13; // [rsp+2Ch] [rbp-4Ch]
int v14[18]; // [rsp+30h] [rbp-48h] BYREF

if ( vdevice )
{
v8 = a2 - a1;
if ( (float)(a2 - a1) != 0.0 )
{
v7 = a4 - a3;
v9 = (float)(a4 - a3) == 0.0;
goto LABEL_10;
}
verror("ortho: left clipping plane same as right one.");
while ( 1 )
{
if ( !v10 )
{
v13 = a6;
v12 = a5;
identmatrix(v14);
*(float *)&v14[5] = 2.0 / v7;
*(float *)v14 = 2.0 / v8;
*(float *)&v14[12] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 + a1) ^ LC1) / v8;
*(float *)&v14[10] = -2.0 / a7;
*(float *)&v14[13] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / v7;
*(float *)&v14[14] = COERCE_FLOAT(COERCE_UNSIGNED_INT(v13 + v12) ^ LC1) / a7;
return loadmatrix(v14);
}
verror("ortho: near clipping plane same as far one.");
LABEL_10:
if ( v9 )
break;
a7 = a6 - a5;
v10 = (float)(a6 - a5) == 0.0;
}
verror("ortho: bottom clipping plane same as top one.");
}
verror("ortho: vogl not initialised");
return ortho2();
}

canonical_decompiled_code:
__int64 __fastcall func5(float a1, float a2, float a3, float a4, float a5, float a6, float a7)
{
float v7; // xmm8_4
float v8; // xmm9_4
bool v9; // zf
bool v10; // zf
float v12; // [rsp+28h] [rbp-50h]
float v13; // [rsp+2Ch] [rbp-4Ch]
int v14[18]; // [rsp+30h] [rbp-48h] BYREF

if ( vdevice )
{
v8 = a2 - a1;
if ( (float)(a2 - a1) != 0.0 )
{
v7 = a4 - a3;
v9 = (float)(a4 - a3) == 0.0;
goto LABEL_10;
}
verror("ortho: left clipping plane same as right one.");
while ( 1 )
{
if ( !v10 )
{
v13 = a6;
v12 = a5;
identmatrix(v14);
*(float *)&v14[5] = 2.0 / v7;
*(float *)v14 = 2.0 / v8;
*(float *)&v14[12] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 + a1) ^ LC1) / v8;
*(float *)&v14[10] = -2.0 / a7;
*(float *)&v14[13] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / v7;
*(float *)&v14[14] = COERCE_FLOAT(COERCE_UNSIGNED_INT(v13 + v12) ^ LC1) / a7;
return loadmatrix(v14);
}
verror("ortho: near clipping plane same as far one.");
LABEL_10:
if ( v9 )
break;
a7 = a6 - a5;
v10 = (float)(a6 - a5) == 0.0;
}
verror("ortho: bottom clipping plane same as top one.");
}
verror("ortho: vogl not initialised");
return func6();
}

original_code:
void
ortho(Coord left, Coord right, Coord bottom, Coord top, Coord hither, Coord yon)
{
 Matrix mat;
 if (!vdevice.initialised)
  verror("ortho: vogl not initialised");
 if ((right - left) == 0.0)
  verror("ortho: left clipping plane same as right one.");
 if ((top - bottom) == 0.0)
  verror("ortho: bottom clipping plane same as top one.");
 if ((yon - hither) == 0.0)
  verror("ortho: near clipping plane same as far one.");
 identmatrix(mat);
 mat[0][0] = 2.0 / (right - left);
 mat[1][1] = 2.0 / (top - bottom);
 mat[2][2] = -2.0 / (yon - hither);
 mat[3][0] = -(right + left) / (right - left);
 mat[3][1] = -(top + bottom) / (top - bottom);
 mat[3][2] = -(yon + hither) / (yon - hither);
 loadmatrix(mat);
}

canonical_original_code:
void ortho(float left, float right, float bottom, float top, float hither, float yon)
{
 float mat[4][4];
 if (!vdevice.initialised)
  verror("ortho: vogl not initialised");
 if ((right - left) == 0.0)
  verror("ortho: left clipping plane same as right one.");
 if ((top - bottom) == 0.0)
  verror("ortho: bottom clipping plane same as top one.");
 if ((yon - hither) == 0.0)
  verror("ortho: near clipping plane same as far one.");
 identmatrix(mat);
 mat[0][0] = 2.0 / (right - left);
 mat[1][1] = 2.0 / (top - bottom);
 mat[2][2] = -2.0 / (yon - hither);
 mat[3][0] = -(right + left) / (right - left);
 mat[3][1] = -(top + bottom) / (top - bottom);
 mat[3][2] = -(yon + hither) / (yon - hither);
 loadmatrix(mat);
}


decompiled_code:
__int64 __fastcall ortho2(float a1, float a2, float a3, float a4)
{
float v4; // xmm6_4
float v5; // xmm5_4
bool v6; // zf
int v8[18]; // [rsp+10h] [rbp-48h] BYREF

if ( !vdevice )
{
LABEL_9:
verror("ortho2: vogl not initialised");
JUMPOUT(0x96ALL);
}
identmatrix(v8);
v4 = a2 - a1;
if ( (float)(a2 - a1) == 0.0 )
{
verror("ortho2: left clipping plane same as right one.");
}
else
{
v5 = a4 - a3;
v6 = (float)(a4 - a3) == 0.0;
}
if ( v6 )
{
verror("ortho2: bottom clipping plane same as top one.");
goto LABEL_9;
}
v8[10] = -1082130432;
*(float *)v8 = 2.0 / v4;
*(float *)&v8[5] = 2.0 / v5;
*(float *)&v8[12] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 + a1) ^ LC1) / v4;
*(float *)&v8[13] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / v5;
return loadmatrix(v8);
}

canonical_decompiled_code:
__int64 __fastcall func6(float a1, float a2, float a3, float a4)
{
float v4; // xmm6_4
float v5; // xmm5_4
bool v6; // zf
int v8[18]; // [rsp+10h] [rbp-48h] BYREF

if ( !vdevice )
{
LABEL_9:
verror("ortho2: vogl not initialised");
JUMPOUT(0x96ALL);
}
identmatrix(v8);
v4 = a2 - a1;
if ( (float)(a2 - a1) == 0.0 )
{
verror("ortho2: left clipping plane same as right one.");
}
else
{
v5 = a4 - a3;
v6 = (float)(a4 - a3) == 0.0;
}
if ( v6 )
{
verror("ortho2: bottom clipping plane same as top one.");
goto LABEL_9;
}
v8[10] = -1082130432;
*(float *)v8 = 2.0 / v4;
*(float *)&v8[5] = 2.0 / v5;
*(float *)&v8[12] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a2 + a1) ^ LC1) / v4;
*(float *)&v8[13] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / v5;
return loadmatrix(v8);
}

original_code:
void
ortho2(Coord left, Coord right, Coord bottom, Coord top)
{
 Matrix mat;
 if (!vdevice.initialised)
  verror("ortho2: vogl not initialised");
 identmatrix(mat);
 if ((right - left) == 0.0)
  verror("ortho2: left clipping plane same as right one.");
 if ((top - bottom) == 0.0)
  verror("ortho2: bottom clipping plane same as top one.");
 mat[0][0] = 2.0 / (right - left);
 mat[1][1] = 2.0 / (top - bottom);
 mat[2][2] = -1.0;
 mat[3][0] = -(right + left) / (right - left);
 mat[3][1] = -(top + bottom) / (top - bottom);
 loadmatrix(mat);
}

canonical_original_code:
void ortho2(float left, float right, float bottom, float top)
{
 float mat[4][4];
 if (!vdevice.initialised)
  verror("ortho2: vogl not initialised");
 identmatrix(mat);
 if ((right - left) == 0.0)
  verror("ortho2: left clipping plane same as right one.");
 if ((top - bottom) == 0.0)
  verror("ortho2: bottom clipping plane same as top one.");
 mat[0][0] = 2.0 / (right - left);
 mat[1][1] = 2.0 / (top - bottom);
 mat[2][2] = -1.0;
 mat[3][0] = -(right + left) / (right - left);
 mat[3][1] = -(top + bottom) / (top - bottom);
 loadmatrix(mat);
}


newtokens

decompiled_code:
void *__fastcall newtokens(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdx
void *v4; // rax
__int64 v5; // rbx
__int64 v6; // rdi
void *result; // rax
__int64 v8; // rax
void *v9; // rax

v1 = a1;
if ( !vdevice[2] )
{
v9 = malloc(0x18uLL);
v5 = (__int64)v9;
if ( !v9 )
goto LABEL_12;
vdevice[2] = v9;
goto LABEL_5;
}
v2 = current;
v3 = *(int *)current;
if ( 100 - (int)v3 <= a1 )
{
v4 = malloc(0x18uLL);
if ( !v4 )
goto LABEL_12;
*(_QWORD *)(v2 + 16) = v4;
v5 = (__int64)v4;
LABEL_5:
v6 = 100LL;
*(_DWORD *)v5 = 0;
if ( (int)v1 >= 100 )
v6 = v1;
*(_QWORD *)(v5 + 16) = 0LL;
result = malloc(4 * v6);
*(_QWORD *)(v5 + 8) = result;
if ( result )
{
*(_DWORD *)v5 = v1;
current = v5;
return result;
}
LABEL_12:
verror("newtokens: malloc returns NULL");
JUMPOUT(0xBDLL);
}
v8 = *(_QWORD *)(current + 8);
*(_DWORD *)current = v3 + a1;
return (void *)(v8 + 4 * v3);
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdx
void *v4; // rax
__int64 v5; // rbx
__int64 v6; // rdi
void *result; // rax
__int64 v8; // rax
void *v9; // rax

v1 = a1;
if ( !vdevice[2] )
{
v9 = malloc(0x18uLL);
v5 = (__int64)v9;
if ( !v9 )
goto LABEL_12;
vdevice[2] = v9;
goto LABEL_5;
}
v2 = current;
v3 = *(int *)current;
if ( 100 - (int)v3 <= a1 )
{
v4 = malloc(0x18uLL);
if ( !v4 )
goto LABEL_12;
*(_QWORD *)(v2 + 16) = v4;
v5 = (__int64)v4;
LABEL_5:
v6 = 100LL;
*(_DWORD *)v5 = 0;
if ( (int)v1 >= 100 )
v6 = v1;
*(_QWORD *)(v5 + 16) = 0LL;
result = malloc(4 * v6);
*(_QWORD *)(v5 + 8) = result;
if ( result )
{
*(_DWORD *)v5 = v1;
current = v5;
return result;
}
LABEL_12:
verror("newtokens: malloc returns NULL");
JUMPOUT(0xBDLL);
}
v8 = *(_QWORD *)(current + 8);
*(_DWORD *)current = v3 + a1;
return (void *)(v8 + 4 * v3);
}

original_code:
Token *
newtokens(int num)
{
 TokList *tl;
 Token *addr;
 int size;
 if (vdevice.tokens == (TokList *)((void *)0) || num >= 100 - current->count) {
  if ((tl = (TokList *)malloc(sizeof(TokList))) == (TokList *)((void *)0))
   verror("newtokens: malloc returns NULL");
  if (vdevice.tokens != (TokList *)((void *)0))
   current->next = tl;
  else
   vdevice.tokens = tl;
  tl->count = 0;
  tl->next = (TokList *)((void *)0);
  if (num > 100)
   size = num;
  else
   size = 100;
  if ((tl->toks = (Token *)malloc(size * sizeof(Token))) == (Token *)((void *)0))
   verror("newtokens: malloc returns NULL");
  current = tl;
 }
 addr = &current->toks[current->count];
 current->count += num;
 return(addr);
}

canonical_original_code:
union tk *newtokens(int num)
{
 struct tls *tl;
 union tk *addr;
 int size;
 if (vdevice.tokens == (struct tls *)((void *)0) || num >= 100 - current->count) {
  if ((tl = (struct tls *)malloc(sizeof(TokList))) == (struct tls *)((void *)0))
   verror("newtokens: malloc returns NULL");
  if (vdevice.tokens != (struct tls *)((void *)0))
   current->next = tl;
  else
   vdevice.tokens = tl;
  tl->count = 0;
  tl->next = (struct tls *)((void *)0);
  if (num > 100)
   size = num;
  else
   size = 100;
  if ((tl->toks = (union tk *)malloc(size * sizeof(Token))) == (union tk *)((void *)0))
   verror("newtokens: malloc returns NULL");
  current = tl;
 }
 addr = &current->toks[current->count];
 current->count += num;
 return(addr);
}

variable_types: num int

variable_types: struct tls { int count; union tk { int i; float f; } *toks; struct tls *next; } *

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

variable_types: size int

return_type: union tk { int i; float f; } *

user_defined_types: struct tls { int count; union tk *toks; struct tls *next; }


decompiled_code:
__int64 bgnpoi_()
{
return bgnpoint__localalias();
}

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

original_code:
void
bgnpoi_()
{
 bgnpoint();
}

canonical_original_code:
void bgnpoi_()
{
 bgnpoint();
}


decompiled_code:
__int64 bgnlin_()
{
return bgnline__localalias();
}

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

original_code:
void
bgnlin_()
{
 bgnline();
}

canonical_original_code:
void bgnlin_()
{
 bgnline();
}


decompiled_code:
__int64 bgnclo_()
{
return bgnclosedline__localalias();
}

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

original_code:
void
bgnclo_()
{
 bgnclosedline();
}

canonical_original_code:
void bgnclo_()
{
 bgnclosedline();
}


decompiled_code:
__int64 bgnpol_()
{
return bgnpolygon__localalias();
}

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

original_code:
void
bgnpol_()
{
 bgnpolygon();
}

canonical_original_code:
void bgnpol_()
{
 bgnpolygon();
}


decompiled_code:
__int64 endpoi_()
{
return endpoint__localalias();
}

canonical_decompiled_code:
__int64 func9()
{
return func8();
}

original_code:
void
endpoi_()
{
 endpoint();
}

canonical_original_code:
void endpoi_()
{
 endpoint();
}


decompiled_code:
__int64 endlin_()
{
return endline__localalias();
}

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

original_code:
void
endlin_()
{
 endline();
}

canonical_original_code:
void endlin_()
{
 endline();
}


decompiled_code:
__int64 endclo_()
{
return endclosedline__localalias();
}

canonical_decompiled_code:
__int64 func13()
{
return func12();
}

original_code:
void
endclo_()
{
 endclosedline();
}

canonical_original_code:
void endclo_()
{
 endclosedline();
}


decompiled_code:
__int64 endpol_()
{
return endpolygon__localalias();
}

canonical_decompiled_code:
__int64 func15()
{
return func14();
}

original_code:
void
endpol_()
{
 endpolygon();
}

canonical_original_code:
void endpol_()
{
 endpolygon();
}


decompiled_code:
__int64 endtme_()
{
return endtmesh__localalias();
}

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

original_code:
void
endtme_()
{
        endtmesh();
}

canonical_original_code:
void endtme_()
{
        endtmesh();
}


decompiled_code:
__int64 endqst_()
{
return endqstrip__localalias();
}

canonical_decompiled_code:
__int64 func19()
{
return func18();
}

original_code:
void
endqst_()
{
        endqstrip();
}

canonical_original_code:
void endqst_()
{
        endqstrip();
}


decompiled_code:
__int64 bgntme_()
{
return bgntmesh__localalias();
}

canonical_decompiled_code:
__int64 func21()
{
return func20();
}

original_code:
void
bgntme_()
{
         bgntmesh();
}

canonical_original_code:
void bgntme_()
{
         bgntmesh();
}


decompiled_code:
__int64 bgnqst_()
{
return bgnqstrip__localalias();
}

canonical_decompiled_code:
__int64 func23()
{
return func22();
}

original_code:
void
bgnqst_()
{
         bgnqstrip();
}

canonical_original_code:
void bgnqst_()
{
         bgnqstrip();
}


decompiled_code:
__int64 swaptm_()
{
return swaptmesh__localalias();
}

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

original_code:
void
swaptm_()
{
        swaptmesh();
}

canonical_original_code:
void swaptm_()
{
        swaptmesh();
}


prefposition

decompiled_code:
__int64 __fastcall prefposition(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rcx
__int64 result; // rax

if ( a1 < 0 || a2 < 0 )
goto LABEL_9;
if ( a3 < 0 || a4 < 0 )
{
LABEL_8:
verror("prefposition: bad y value");
LABEL_9:
verror("prefposition: bad x value");
return prefsize();
}
v4 = a4 - a3;
px = a1;
py = a3;
pxs = a2 - a1;
pys = v4;
if ( a2 - a1 <= 0 || v4 <= 0 )
{
verror("prefposition: bad window size");
goto LABEL_8;
}
return result;
}

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

if ( a1 < 0 || a2 < 0 )
goto LABEL_9;
if ( a3 < 0 || a4 < 0 )
{
LABEL_8:
verror("prefposition: bad y value");
LABEL_9:
verror("prefposition: bad x value");
return func1();
}
v4 = a4 - a3;
px = a1;
py = a3;
pxs = a2 - a1;
pys = v4;
if ( a2 - a1 <= 0 || v4 <= 0 )
{
verror("prefposition: bad window size");
goto LABEL_8;
}
return result;
}

original_code:
void
prefposition(long int x1, long int x2, long int y1, long int y2)
{
 if (x1 < 0 || x2 < 0)
  verror("prefposition: bad x value");
 if (y1 < 0 || y2 < 0)
  verror("prefposition: bad y value");
 px = x1;
 py = y1;
 pxs = x2 - x1;
 pys = y2 - y1;
 if (pxs <= 0 || pys <= 0)
  verror("prefposition: bad window size");
}

canonical_original_code:
void prefposition(long x1, long x2, long y1, long y2)
{
 if (x1 < 0 || x2 < 0)
  verror("prefposition: bad x value");
 if (y1 < 0 || y2 < 0)
  verror("prefposition: bad y value");
 px = x1;
 py = y1;
 pxs = x2 - x1;
 pys = y2 - y1;
 if (pxs <= 0 || pys <= 0)
  verror("prefposition: bad window size");
}


prefsize

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

if ( a1 < 0 )
{
verror("prefsize: bad x value");
}
else if ( a2 >= 0 )
{
pxs = a1;
pys = a2;
return result;
}
verror("prefsize: bad y value");
return getprefposandsize();
}

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

if ( a1 < 0 )
{
verror("prefsize: bad x value");
}
else if ( a2 >= 0 )
{
pxs = a1;
pys = a2;
return result;
}
verror("prefsize: bad y value");
return func2();
}

original_code:
void
prefsize(long int x, long int y)
{
 if (x < 0)
  verror("prefsize: bad x value");
 if (y < 0)
  verror("prefsize: bad y value");
 pxs = x;
 pys = y;
}

canonical_original_code:
void prefsize(long x, long y)
{
 if (x < 0)
  verror("prefsize: bad x value");
 if (y < 0)
  verror("prefsize: bad y value");
 pxs = x;
 pys = y;
}

variable_types: x long

variable_types: y long


qdevice

decompiled_code:
void __fastcall qdevice(int a1)
{
__int64 v1; // rdx
__int64 v2; // rax
char v3; // cl
_BYTE *v4; // rax
int v5; // edx
_BYTE *v6; // rax
_BYTE *v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rdx

if ( !vdevice )
goto LABEL_25;
if ( (unsigned __int16)a1 > 0x106u )
{
verror("qdevice: bad device number passed\n");
LABEL_25:
verror("qdevice: vogl not initialised\n");
unqdevice();
return;
}
if ( (unsigned __int16)a1 <= 0x5Du )
{
if ( (unsigned __int16)a1 > 0x2Cu )
{
switch ( (__int16)a1 )
{
case '-':
v8 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v8 + 5) |= 0x20u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) |= 0x80u;
break;
case '=':
v9 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v9 + 7) |= 0x20u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 5LL) |= 8u;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
*((_BYTE *)&vdevice + 527) = 1;
v4 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
v5 = 1 << (a1 & 7);
*v4 |= v5;
v6 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int64)(unsigned int)(a1 + 32) << 48 >> 51));
*v6 |= v5;
break;
case '[':
v10 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v10 + 11) |= 8u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) |= 8u;
break;
case '\\':
v11 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v11 + 11) |= 0x10u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) |= 0x10u;
break;
case ']':
v12 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v12 + 11) |= 0x20u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) |= 0x20u;
break;
default:
goto LABEL_17;
}
return;
}
LABEL_17:
*((_BYTE *)&vdevice + 527) = 1;
v7 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
*v7 |= 1 << (a1 & 7);
return;
}
if ( (unsigned __int16)a1 > 0x104u )
{
if ( (_WORD)a1 == 262 )
return;
goto LABEL_17;
}
if ( (unsigned __int16)a1 > 0x101u )
{
v13 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 526) = 1;
*(_BYTE *)(v13 + 32) |= 1 << (a1 & 7);
return;
}
if ( (_WORD)a1 != 257 )
goto LABEL_17;
v1 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 525) = 1;
v2 = 0LL;
*((_BYTE *)&vdevice + 527) = 1;
v3 = *(_BYTE *)(v1 + 32) & 0x20;
while ( 1 )
{
*(_BYTE *)(v1 + v2++) = -1;
if ( v2 == 34 )
break;
v1 = *((_QWORD *)&vdevice + 64);
}
**((_BYTE **)&vdevice + 64) &= 0xFEu;
if ( !v3 )
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 32LL) &= 0xDFu;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
__int64 v1; // rdx
__int64 v2; // rax
char v3; // cl
_BYTE *v4; // rax
int v5; // edx
_BYTE *v6; // rax
_BYTE *v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rdx

if ( !vdevice )
goto LABEL_25;
if ( (unsigned __int16)a1 > 0x106u )
{
verror("qdevice: bad device number passed\n");
LABEL_25:
verror("qdevice: vogl not initialised\n");
func1();
return;
}
if ( (unsigned __int16)a1 <= 0x5Du )
{
if ( (unsigned __int16)a1 > 0x2Cu )
{
switch ( (__int16)a1 )
{
case '-':
v8 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v8 + 5) |= 0x20u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) |= 0x80u;
break;
case '=':
v9 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v9 + 7) |= 0x20u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 5LL) |= 8u;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
*((_BYTE *)&vdevice + 527) = 1;
v4 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
v5 = 1 << (a1 & 7);
*v4 |= v5;
v6 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int64)(unsigned int)(a1 + 32) << 48 >> 51));
*v6 |= v5;
break;
case '[':
v10 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v10 + 11) |= 8u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) |= 8u;
break;
case '\\':
v11 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v11 + 11) |= 0x10u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) |= 0x10u;
break;
case ']':
v12 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 527) = 1;
*(_BYTE *)(v12 + 11) |= 0x20u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) |= 0x20u;
break;
default:
goto LABEL_17;
}
return;
}
LABEL_17:
*((_BYTE *)&vdevice + 527) = 1;
v7 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
*v7 |= 1 << (a1 & 7);
return;
}
if ( (unsigned __int16)a1 > 0x104u )
{
if ( (_WORD)a1 == 262 )
return;
goto LABEL_17;
}
if ( (unsigned __int16)a1 > 0x101u )
{
v13 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 526) = 1;
*(_BYTE *)(v13 + 32) |= 1 << (a1 & 7);
return;
}
if ( (_WORD)a1 != 257 )
goto LABEL_17;
v1 = *((_QWORD *)&vdevice + 64);
*((_BYTE *)&vdevice + 525) = 1;
v2 = 0LL;
*((_BYTE *)&vdevice + 527) = 1;
v3 = *(_BYTE *)(v1 + 32) & 0x20;
while ( 1 )
{
*(_BYTE *)(v1 + v2++) = -1;
if ( v2 == 34 )
break;
v1 = *((_QWORD *)&vdevice + 64);
}
**((_BYTE **)&vdevice + 64) &= 0xFEu;
if ( !v3 )
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 32LL) &= 0xDFu;
}

original_code:
void
qdevice(Device dev)
{
 int i, redraw_enabled;
 if (!vdevice.initialised)
  verror("qdevice: vogl not initialised\n");
 if (dev > (Device)262)
  verror("qdevice: bad device number passed\n");
 switch (dev) {
 case 'A':
 case 'B':
 case 'C':
 case 'D':
 case 'E':
 case 'F':
 case 'G':
 case 'H':
 case 'I':
 case 'J':
 case 'K':
 case 'L':
 case 'M':
 case 'N':
 case 'O':
 case 'P':
 case 'Q':
 case 'R':
 case 'S':
 case 'T':
 case 'U':
 case 'V':
 case 'W':
 case 'X':
 case 'Y':
 case 'Z':
  vdevice.kbdevents = 1;
  vdevice.enabled[dev / 8] |= 1 << (dev & 0x7);
  vdevice.enabled[(int)(dev - 'A' + 'a') / 8] |= 1 << ((dev - 'A' + 'a') & 0x7);
  break;
 case 257:
  vdevice.kbdmode = 1;
  vdevice.kbdevents = 1;
  redraw_enabled = (vdevice.enabled[261 / 8] & (1 << (261 & 0x7)));
  for (i = 0; i != 34; i++)
   vdevice.enabled[i] = 0xff;
  vdevice.enabled[0] &= 0xfe;
  if (!redraw_enabled)
   vdevice.enabled[261 / 8] &= ~(1 << (261 & 0x7));
  break;
 case 258:
 case 259:
 case 260:
  vdevice.mouseevents = 1;
  vdevice.enabled[dev / 8] |= 1 << (dev & 0x7);
  break;
 case '-':
  vdevice.kbdevents = 1;
  vdevice.enabled['-' / 8] |= 1 << ('-' & 0x7);
  vdevice.enabled['_' / 8] |= 1 << ('_' & 0x7);
  break;
 case '\\':
  vdevice.kbdevents = 1;
  vdevice.enabled['\\' / 8] |= 1 << ('\\' & 0x7);
  vdevice.enabled['|' / 8] |= 1 << ('|' & 0x7);
  break;
 case '=':
  vdevice.kbdevents = 1;
  vdevice.enabled['=' / 8] |= 1 << ('=' & 0x7);
  vdevice.enabled['+' / 8] |= 1 << ('+' & 0x7);
  break;
 case '[':
  vdevice.kbdevents = 1;
  vdevice.enabled['[' / 8] |= 1 << ('[' & 0x7);
  vdevice.enabled['{' / 8] |= 1 << ('{' & 0x7);
  break;
 case ']':
  vdevice.kbdevents = 1;
  vdevice.enabled[']' / 8] |= 1 << (']' & 0x7);
  vdevice.enabled['}' / 8] |= 1 << ('}' & 0x7);
  break;
 case 262:
  break;
 case 261:
 default:
  vdevice.kbdevents = 1;
  vdevice.enabled[dev / 8] |= 1 << (dev & 0x7);
 }
}

canonical_original_code:
void qdevice(unsigned short dev)
{
 int i; int redraw_enabled;
 if (!vdevice.initialised)
  verror("qdevice: vogl not initialised\n");
 if (dev > (unsigned short)262)
  verror("qdevice: bad device number passed\n");
 switch (dev) {
 case 'A':
 case 'B':
 case 'C':
 case 'D':
 case 'E':
 case 'F':
 case 'G':
 case 'H':
 case 'I':
 case 'J':
 case 'K':
 case 'L':
 case 'M':
 case 'N':
 case 'O':
 case 'P':
 case 'Q':
 case 'R':
 case 'S':
 case 'T':
 case 'U':
 case 'V':
 case 'W':
 case 'X':
 case 'Y':
 case 'Z':
  vdevice.kbdevents = 1;
  vdevice.enabled[dev / 8] |= 1 << (dev & 0x7);
  vdevice.enabled[(int)(dev - 'A' + 'a') / 8] |= 1 << ((dev - 'A' + 'a') & 0x7);
  break;
 case 257:
  vdevice.kbdmode = 1;
  vdevice.kbdevents = 1;
  redraw_enabled = (vdevice.enabled[261 / 8] & (1 << (261 & 0x7)));
  for (i = 0; i != 34; i++)
   vdevice.enabled[i] = 0xff;
  vdevice.enabled[0] &= 0xfe;
  if (!redraw_enabled)
   vdevice.enabled[261 / 8] &= ~(1 << (261 & 0x7));
  break;
 case 258:
 case 259:
 case 260:
  vdevice.mouseevents = 1;
  vdevice.enabled[dev / 8] |= 1 << (dev & 0x7);
  break;
 case '-':
  vdevice.kbdevents = 1;
  vdevice.enabled['-' / 8] |= 1 << ('-' & 0x7);
  vdevice.enabled['_' / 8] |= 1 << ('_' & 0x7);
  break;
 case '\\':
  vdevice.kbdevents = 1;
  vdevice.enabled['\\' / 8] |= 1 << ('\\' & 0x7);
  vdevice.enabled['|' / 8] |= 1 << ('|' & 0x7);
  break;
 case '=':
  vdevice.kbdevents = 1;
  vdevice.enabled['=' / 8] |= 1 << ('=' & 0x7);
  vdevice.enabled['+' / 8] |= 1 << ('+' & 0x7);
  break;
 case '[':
  vdevice.kbdevents = 1;
  vdevice.enabled['[' / 8] |= 1 << ('[' & 0x7);
  vdevice.enabled['{' / 8] |= 1 << ('{' & 0x7);
  break;
 case ']':
  vdevice.kbdevents = 1;
  vdevice.enabled[']' / 8] |= 1 << (']' & 0x7);
  vdevice.enabled['}' / 8] |= 1 << ('}' & 0x7);
  break;
 case 262:
  break;
 case 261:
 default:
  vdevice.kbdevents = 1;
  vdevice.enabled[dev / 8] |= 1 << (dev & 0x7);
 }
}

variable_types:
dev
unsigned short

variable_types: i int


unqdevice

decompiled_code:
void __fastcall unqdevice(int a1)
{
__int64 i; // rax
__int64 v2; // rdx
unsigned __int64 j; // rax
_BYTE *v4; // rax
_BYTE *v5; // rax
_BYTE *v6; // rax

if ( !vdevice )
{
verror("qdevice: vogl not initialised\n");
goto LABEL_30;
}
if ( (unsigned __int16)a1 > 0x106u )
{
LABEL_30:
verror("qdevice: bad device number passed\n");
qread();
return;
}
if ( (unsigned __int16)a1 <= 0x5Du )
{
if ( (unsigned __int16)a1 > 0x2Cu )
{
switch ( (__int16)a1 )
{
case '-':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 5LL) &= 0xDFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0x7Fu;
break;
case '=':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 7LL) &= 0xDFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 5LL) &= 0xF7u;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
v5 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
*v5 &= ~(1 << (a1 & 7));
v6 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int64)(unsigned int)(a1 + 32) << 48 >> 51));
*v6 &= ~(1 << (a1 & 7));
break;
case '[':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0xF7u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) &= 0xF7u;
break;
case '\\':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0xEFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) &= 0xEFu;
break;
case ']':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0xDFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) &= 0xDFu;
break;
default:
goto LABEL_19;
}
goto LABEL_11;
}
goto LABEL_19;
}
if ( (unsigned __int16)a1 <= 0x104u )
{
if ( (unsigned __int16)a1 > 0x101u )
{
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 32LL) &= ~(1 << (a1 & 7));
goto LABEL_11;
}
if ( (_WORD)a1 == 257 )
{
*((_BYTE *)&vdevice + 525) = 0;
for ( i = 0LL; i != 34; ++i )
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + i) = 0;
goto LABEL_11;
}
LABEL_19:
v4 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
*v4 &= ~(1 << (a1 & 7));
LABEL_11:
v2 = *((_QWORD *)&vdevice + 64);
*((_WORD *)&vdevice + 263) = 0;
for ( j = 0LL; ; ++j )
{
if ( *(_BYTE *)(v2 + j) )
{
if ( j > 0x1F )
{
*((_BYTE *)&vdevice + 526) = 1;
if ( j == 33 )
return;
}
else
{
*((_BYTE *)&vdevice + 527) = 1;
}
}
else if ( j == 33 )
{
return;
}
}
}
if ( (_WORD)a1 != 262 )
goto LABEL_19;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
__int64 i; // rax
__int64 v2; // rdx
unsigned __int64 j; // rax
_BYTE *v4; // rax
_BYTE *v5; // rax
_BYTE *v6; // rax

if ( !vdevice )
{
verror("qdevice: vogl not initialised\n");
goto LABEL_30;
}
if ( (unsigned __int16)a1 > 0x106u )
{
LABEL_30:
verror("qdevice: bad device number passed\n");
func2();
return;
}
if ( (unsigned __int16)a1 <= 0x5Du )
{
if ( (unsigned __int16)a1 > 0x2Cu )
{
switch ( (__int16)a1 )
{
case '-':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 5LL) &= 0xDFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0x7Fu;
break;
case '=':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 7LL) &= 0xDFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 5LL) &= 0xF7u;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
v5 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
*v5 &= ~(1 << (a1 & 7));
v6 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int64)(unsigned int)(a1 + 32) << 48 >> 51));
*v6 &= ~(1 << (a1 & 7));
break;
case '[':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0xF7u;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) &= 0xF7u;
break;
case '\\':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0xEFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) &= 0xEFu;
break;
case ']':
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 11LL) &= 0xDFu;
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 15LL) &= 0xDFu;
break;
default:
goto LABEL_19;
}
goto LABEL_11;
}
goto LABEL_19;
}
if ( (unsigned __int16)a1 <= 0x104u )
{
if ( (unsigned __int16)a1 > 0x101u )
{
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + 32LL) &= ~(1 << (a1 & 7));
goto LABEL_11;
}
if ( (_WORD)a1 == 257 )
{
*((_BYTE *)&vdevice + 525) = 0;
for ( i = 0LL; i != 34; ++i )
*(_BYTE *)(*((_QWORD *)&vdevice + 64) + i) = 0;
goto LABEL_11;
}
LABEL_19:
v4 = (_BYTE *)(*((_QWORD *)&vdevice + 64) + ((unsigned __int16)a1 >> 3));
*v4 &= ~(1 << (a1 & 7));
LABEL_11:
v2 = *((_QWORD *)&vdevice + 64);
*((_WORD *)&vdevice + 263) = 0;
for ( j = 0LL; ; ++j )
{
if ( *(_BYTE *)(v2 + j) )
{
if ( j > 0x1F )
{
*((_BYTE *)&vdevice + 526) = 1;
if ( j == 33 )
return;
}
else
{
*((_BYTE *)&vdevice + 527) = 1;
}
}
else if ( j == 33 )
{
return;
}
}
}
if ( (_WORD)a1 != 262 )
goto LABEL_19;
}

original_code:
void
unqdevice(Device dev)
{
 int i;
 if (!vdevice.initialised)
  verror("qdevice: vogl not initialised\n");
 if (dev > (Device)262)
  verror("qdevice: bad device number passed\n");
 switch (dev) {
 case 'A':
 case 'B':
 case 'C':
 case 'D':
 case 'E':
 case 'F':
 case 'G':
 case 'H':
 case 'I':
 case 'J':
 case 'K':
 case 'L':
 case 'M':
 case 'N':
 case 'O':
 case 'P':
 case 'Q':
 case 'R':
 case 'S':
 case 'T':
 case 'U':
 case 'V':
 case 'W':
 case 'X':
 case 'Y':
 case 'Z':
  vdevice.enabled[dev / 8] &= ~(1 << (dev & 0x7));
  vdevice.enabled[(int)(dev - 'A' + 'a') / 8] &= ~(1 << ((dev - 'A' + 'a') & 0x7));
  break;
 case 257:
  vdevice.kbdmode = 0;
  for (i = 0; i != 34; i++)
   vdevice.enabled[i] = 0x00;
  break;
 case 258:
 case 259:
 case 260:
  vdevice.enabled[dev / 8] &= ~(1 << (dev & 0x7));
  break;
 case '-':
  vdevice.enabled['-' / 8] &= ~(1 << ('-' & 0x7));
  vdevice.enabled['_' / 8] &= ~(1 << ('_' & 0x7));
  break;
 case '\\':
  vdevice.enabled['\\' / 8] &= ~(1 << ('\\' & 0x7));
  vdevice.enabled['|' / 8] &= ~(1 << ('|' & 0x7));
  break;
 case '=':
  vdevice.enabled['=' / 8] &= ~(1 << ('=' & 0x7));
  vdevice.enabled['+' / 8] &= ~(1 << ('+' & 0x7));
  break;
 case '[':
  vdevice.enabled['[' / 8] &= ~(1 << ('[' & 0x7));
  vdevice.enabled['{' / 8] &= ~(1 << ('{' & 0x7));
  break;
 case ']':
  vdevice.enabled[']' / 8] &= ~(1 << (']' & 0x7));
  vdevice.enabled['}' / 8] &= ~(1 << ('}' & 0x7));
  break;
 case 262:
  return;
 default:
  vdevice.enabled[dev / 8] &= ~(1 << (dev & 0x7));
 }
 vdevice.mouseevents = vdevice.kbdevents = 0;
 for (i = 0; i != 34; i++)
  if (vdevice.enabled[i] != 0) {
   if (i < 32)
    vdevice.kbdevents = 1;
   else
    vdevice.mouseevents = 1;
  }
}

canonical_original_code:
void unqdevice(unsigned short dev)
{
 int i;
 if (!vdevice.initialised)
  verror("qdevice: vogl not initialised\n");
 if (dev > (unsigned short)262)
  verror("qdevice: bad device number passed\n");
 switch (dev) {
 case 'A':
 case 'B':
 case 'C':
 case 'D':
 case 'E':
 case 'F':
 case 'G':
 case 'H':
 case 'I':
 case 'J':
 case 'K':
 case 'L':
 case 'M':
 case 'N':
 case 'O':
 case 'P':
 case 'Q':
 case 'R':
 case 'S':
 case 'T':
 case 'U':
 case 'V':
 case 'W':
 case 'X':
 case 'Y':
 case 'Z':
  vdevice.enabled[dev / 8] &= ~(1 << (dev & 0x7));
  vdevice.enabled[(int)(dev - 'A' + 'a') / 8] &= ~(1 << ((dev - 'A' + 'a') & 0x7));
  break;
 case 257:
  vdevice.kbdmode = 0;
  for (i = 0; i != 34; i++)
   vdevice.enabled[i] = 0x00;
  break;
 case 258:
 case 259:
 case 260:
  vdevice.enabled[dev / 8] &= ~(1 << (dev & 0x7));
  break;
 case '-':
  vdevice.enabled['-' / 8] &= ~(1 << ('-' & 0x7));
  vdevice.enabled['_' / 8] &= ~(1 << ('_' & 0x7));
  break;
 case '\\':
  vdevice.enabled['\\' / 8] &= ~(1 << ('\\' & 0x7));
  vdevice.enabled['|' / 8] &= ~(1 << ('|' & 0x7));
  break;
 case '=':
  vdevice.enabled['=' / 8] &= ~(1 << ('=' & 0x7));
  vdevice.enabled['+' / 8] &= ~(1 << ('+' & 0x7));
  break;
 case '[':
  vdevice.enabled['[' / 8] &= ~(1 << ('[' & 0x7));
  vdevice.enabled['{' / 8] &= ~(1 << ('{' & 0x7));
  break;
 case ']':
  vdevice.enabled[']' / 8] &= ~(1 << (']' & 0x7));
  vdevice.enabled['}' / 8] &= ~(1 << ('}' & 0x7));
  break;
 case 262:
  return;
 default:
  vdevice.enabled[dev / 8] &= ~(1 << (dev & 0x7));
 }
 vdevice.mouseevents = vdevice.kbdevents = 0;
 for (i = 0; i != 34; i++)
  if (vdevice.enabled[i] != 0) {
   if (i < 32)
    vdevice.kbdevents = 1;
   else
    vdevice.mouseevents = 1;
  }
}


qread

original_code:
long
qread(short int *ret)
{
 int a, b, c1, c2, val;
 int eventind, eventmask, retvalue;
 if (!vdevice.initialised)
  verror("qread: vogl not initialised\n");
 if (vdevice.alreadyread) {
  eventind = vdevice.devno / 8;
  eventmask = 1 << (vdevice.devno & 0x7);
  if (vdevice.enabled[eventind] & eventmask) {
   *ret = vdevice.data;
   if (!vdevice.kbdmode && vdevice.data == 1)
    vdevice.data = 0;
   else
    vdevice.alreadyread = 0;
   return(vdevice.devno);
  }
 }
 val = c1 = c2 = 0;
 eventind = 0;
 eventmask = 0;
 if (!vdevice.mouseevents && vdevice.kbdevents) {
  while (!(vdevice.enabled[eventind] & eventmask)) {
   if ((val = c1 = (*vdevice.dev.Vgetkey)()) < 0)
    return(val);
   eventind = c1 / 8;
   eventmask = 1 << (c1 & 0x7);
   *ret = c1;
   if (c1 >= 'a' && c1 <= 'z')
    retvalue = c1 - 'a' + 'A';
   else
    retvalue = c1;
  }
 } else if (vdevice.mouseevents && !vdevice.kbdevents) {
  while (!(vdevice.enabled[eventind] & eventmask)) {
   if ((c2 = (*vdevice.dev.Vlocator)(&a, &b)) < 0)
    return(c2);
   if (c2 != 0) {
    if (c2 & 0x01)
     c2 = 260;
    else if (c2 & 0x02)
     c2 = 259;
    else if (c2 & 0x04)
     c2 = 258;
    eventind = c2 / 8;
    eventmask = 1 << (c2 & 0x7);
    *ret = c2;
    retvalue = c2;
   }
  }
 } else if (vdevice.mouseevents && vdevice.kbdevents) {
  while (!(vdevice.enabled[eventind] & eventmask)) {
   while (c1 == 0 && c2 == 0) {
    val = c1 = (*vdevice.dev.Vcheckkey)();
    c2 = (*vdevice.dev.Vlocator)(&a, &b);
   }
   if (c1 < 0 && c2 < 0)
    return(-1);
   if (c1 != 0) {
    eventind = c1 / 8;
    eventmask = 1 << (c1 & 0x7);
    *ret = c1;
    if (c1 >= 'a' && c1 <= 'z')
     retvalue = c1 - 'a' + 'A';
    else
     retvalue = c1;
   } else {
    if (c2 & 0x01)
     c2 = 260;
    else if (c2 & 0x02)
     c2 = 259;
    else if (c2 & 0x04)
     c2 = 258;
    eventind = c2 / 8;
    eventmask = 1 << (c2 & 0x7);
    *ret = c2;
    retvalue = c2;
   }
   c1 = c2 = 0;
  }
 } else
  return(-1);
 if (vdevice.kbdmode && val != 0) {
  *ret = val;
  return(257);
 } else {
  *ret = 1;
  vdevice.data = 0;
  vdevice.devno = retvalue;
  vdevice.alreadyread = 1;
 }
 return(retvalue);
}

canonical_original_code:
long qread(short *ret)
{
 int a; int b; int c1; int c2; int val;
 int eventind; int eventmask; int retvalue;
 if (!vdevice.initialised)
  verror("qread: vogl not initialised\n");
 if (vdevice.alreadyread) {
  eventind = vdevice.devno / 8;
  eventmask = 1 << (vdevice.devno & 0x7);
  if (vdevice.enabled[eventind] & eventmask) {
   *ret = vdevice.data;
   if (!vdevice.kbdmode && vdevice.data == 1)
    vdevice.data = 0;
   else
    vdevice.alreadyread = 0;
   return(vdevice.devno);
  }
 }
 val = c1 = c2 = 0;
 eventind = 0;
 eventmask = 0;
 if (!vdevice.mouseevents && vdevice.kbdevents) {
  while (!(vdevice.enabled[eventind] & eventmask)) {
   if ((val = c1 = (*vdevice.dev.Vgetkey)()) < 0)
    return(val);
   eventind = c1 / 8;
   eventmask = 1 << (c1 & 0x7);
   *ret = c1;
   if (c1 >= 'a' && c1 <= 'z')
    retvalue = c1 - 'a' + 'A';
   else
    retvalue = c1;
  }
 } else if (vdevice.mouseevents && !vdevice.kbdevents) {
  while (!(vdevice.enabled[eventind] & eventmask)) {
   if ((c2 = (*vdevice.dev.Vlocator)(&a, &b)) < 0)
    return(c2);
   if (c2 != 0) {
    if (c2 & 0x01)
     c2 = 260;
    else if (c2 & 0x02)
     c2 = 259;
    else if (c2 & 0x04)
     c2 = 258;
    eventind = c2 / 8;
    eventmask = 1 << (c2 & 0x7);
    *ret = c2;
    retvalue = c2;
   }
  }
 } else if (vdevice.mouseevents && vdevice.kbdevents) {
  while (!(vdevice.enabled[eventind] & eventmask)) {
   while (c1 == 0 && c2 == 0) {
    val = c1 = (*vdevice.dev.Vcheckkey)();
    c2 = (*vdevice.dev.Vlocator)(&a, &b);
   }
   if (c1 < 0 && c2 < 0)
    return(-1);
   if (c1 != 0) {
    eventind = c1 / 8;
    eventmask = 1 << (c1 & 0x7);
    *ret = c1;
    if (c1 >= 'a' && c1 <= 'z')
     retvalue = c1 - 'a' + 'A';
    else
     retvalue = c1;
   } else {
    if (c2 & 0x01)
     c2 = 260;
    else if (c2 & 0x02)
     c2 = 259;
    else if (c2 & 0x04)
     c2 = 258;
    eventind = c2 / 8;
    eventmask = 1 << (c2 & 0x7);
    *ret = c2;
    retvalue = c2;
   }
   c1 = c2 = 0;
  }
 } else
  return(-1);
 if (vdevice.kbdmode && val != 0) {
  *ret = val;
  return(257);
 } else {
  *ret = 1;
  vdevice.data = 0;
  vdevice.devno = retvalue;
  vdevice.alreadyread = 1;
 }
 return(retvalue);
}

variable_types:
ret
short *

variable_types: a int

variable_types: b int

variable_types: val int

variable_types: eventind int

variable_types: eventmask int

variable_types: retvalue int


qreset

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

do
result = (*((__int64 (**)(void))&vdevice + 24))();
while ( (_DWORD)result );
*((_BYTE *)&vdevice + 524) = 0;
return result;
}

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

do
result = (*((__int64 (**)(void))&vdevice + 24))();
while ( (_DWORD)result );
*((_BYTE *)&vdevice + 524) = 0;
return result;
}

original_code:
void
qreset(void)
{
 while (((*vdevice.dev.Vcheckkey)()))
  ;
 vdevice.alreadyread = 0;
}

canonical_original_code:
void qreset()
{
 while (((*vdevice.dev.Vcheckkey)()))
  ;
 vdevice.alreadyread = 0;
}