decompiled_code:
__int64 __fastcall sha256_write(__int64 a1, char *a2, unsigned __int64 a3)
{
char *v3; // rbp
unsigned __int64 v4; // r13
__int64 result; // rax
int v6; // eax
unsigned __int64 v7; // rsi
char *v8; // r12
char *v9; // r14
char *v10; // rdx

v3 = a2;
v4 = a3;
result = *(unsigned int *)(a1 + 100);
if ( (_DWORD)result == 64 )
{
result = transform((int *)a1, (char *)(a1 + 36));
*(_DWORD *)(a1 + 100) = 0;
++*(_DWORD *)(a1 + 32);
if ( !a2 )
return result;
LABEL_9:
v7 = v4;
if ( v4 <= 0x3F )
goto LABEL_13;
goto LABEL_10;
}
if ( !a2 )
return result;
if ( !(_DWORD)result )
goto LABEL_9;
if ( !a3 )
return sha256_write(a1, 0LL, 0LL);
while ( 1 )
{
v6 = *(_DWORD *)(a1 + 100);
if ( v6 > 63 )
break;
++v3;
*(_DWORD *)(a1 + 100) = v6 + 1;
*(_BYTE *)(a1 + v6 + 36) = *(v3 - 1);
if ( !--v4 )
return sha256_write(a1, 0LL, 0LL);
}
result = sha256_write(a1, 0LL, 0LL);
if ( v4 )
{
v7 = v4;
if ( v4 <= 0x3F )
{
LABEL_14:
v10 = v3;
do
{
result = *(unsigned int *)(a1 + 100);
if ( (int)result > 63 )
break;
++v10;
*(_DWORD *)(a1 + 100) = result + 1;
*(_BYTE *)(a1 + (int)result + 36) = *(v10 - 1);
result = (__int64)&v3[v7 - (_QWORD)v10];
}
while ( result );
return result;
}
LABEL_10:
v8 = v3;
v9 = &v3[v4];
do
{
transform((int *)a1, v8);
*(_DWORD *)(a1 + 100) = 0;
++*(_DWORD *)(a1 + 32);
v8 += 64;
result = v9 - v8;
}
while ( (unsigned __int64)(v9 - v8) > 0x3F );
v7 = v4 & 0x3F;
v3 += ((v4 - 64) & 0xFFFFFFFFFFFFFFC0LL) + 64;
LABEL_13:
if ( !v7 )
return result;
goto LABEL_14;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, unsigned __int64 a3)
{
char *v3; // rbp
unsigned __int64 v4; // r13
__int64 result; // rax
int v6; // eax
unsigned __int64 v7; // rsi
char *v8; // r12
char *v9; // r14
char *v10; // rdx

v3 = a2;
v4 = a3;
result = *(unsigned int *)(a1 + 100);
if ( (_DWORD)result == 64 )
{
result = func0((int *)a1, (char *)(a1 + 36));
*(_DWORD *)(a1 + 100) = 0;
++*(_DWORD *)(a1 + 32);
if ( !a2 )
return result;
LABEL_9:
v7 = v4;
if ( v4 <= 0x3F )
goto LABEL_13;
goto LABEL_10;
}
if ( !a2 )
return result;
if ( !(_DWORD)result )
goto LABEL_9;
if ( !a3 )
return func2(a1, 0LL, 0LL);
while ( 1 )
{
v6 = *(_DWORD *)(a1 + 100);
if ( v6 > 63 )
break;
++v3;
*(_DWORD *)(a1 + 100) = v6 + 1;
*(_BYTE *)(a1 + v6 + 36) = *(v3 - 1);
if ( !--v4 )
return func2(a1, 0LL, 0LL);
}
result = func2(a1, 0LL, 0LL);
if ( v4 )
{
v7 = v4;
if ( v4 <= 0x3F )
{
LABEL_14:
v10 = v3;
do
{
result = *(unsigned int *)(a1 + 100);
if ( (int)result > 63 )
break;
++v10;
*(_DWORD *)(a1 + 100) = result + 1;
*(_BYTE *)(a1 + (int)result + 36) = *(v10 - 1);
result = (__int64)&v3[v7 - (_QWORD)v10];
}
while ( result );
return result;
}
LABEL_10:
v8 = v3;
v9 = &v3[v4];
do
{
func0((int *)a1, v8);
*(_DWORD *)(a1 + 100) = 0;
++*(_DWORD *)(a1 + 32);
v8 += 64;
result = v9 - v8;
}
while ( (unsigned __int64)(v9 - v8) > 0x3F );
v7 = v4 & 0x3F;
v3 += ((v4 - 64) & 0xFFFFFFFFFFFFFFC0LL) + 64;
LABEL_13:
if ( !v7 )
return result;
goto LABEL_14;
}
return result;
}

original_code:
void sha256_write(SHA256_CONTEXT * hd, unsigned char *inbuf, size_t inlen)
{
 if (hd->count == 64) {
  transform(hd, hd->buf);
  hd->count = 0;
  hd->nblocks++;
 }
 if (!inbuf)
  return;
 if (hd->count) {
  for (; inlen && hd->count < 64; inlen--)
   hd->buf[hd->count++] = *inbuf++;
  sha256_write(hd, ((void *)0), 0);
  if (!inlen)
   return;
 }
 while (inlen >= 64) {
  transform(hd, inbuf);
  hd->count = 0;
  hd->nblocks++;
  inlen -= 64;
  inbuf += 64;
 }
 for (; inlen && hd->count < 64; inlen--)
  hd->buf[hd->count++] = *inbuf++;
}

canonical_original_code:
void sha256_write(struct SHA256_CONTEXT *hd, unsigned char *inbuf, unsigned long inlen)
{
 if (hd->count == 64) {
  transform(hd, hd->buf);
  hd->count = 0;
  hd->nblocks++;
 }
 if (!inbuf)
  return;
 if (hd->count) {
  for (; inlen && hd->count < 64; inlen--)
   hd->buf[hd->count++] = *inbuf++;
  sha256_write(hd, ((void *)0), 0);
  if (!inlen)
   return;
 }
 while (inlen >= 64) {
  transform(hd, inbuf);
  hd->count = 0;
  hd->nblocks++;
  inlen -= 64;
  inbuf += 64;
 }
 for (; inlen && hd->count < 64; inlen--)
  hd->buf[hd->count++] = *inbuf++;
}

variable_types:
inbuf
unsigned char *

variable_types:
inlen
unsigned long

user_defined_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; }


repo: bernarpa/PAES

variable_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; } *

variable_types:
t
unsigned int

variable_types:
msb
unsigned int

variable_types:
lsb
unsigned int

variable_types:
p
unsigned char *

return_type: void


decompiled_code:
__int64 __fastcall sha256_read(__int64 a1)
{
return a1 + 36;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return a1 + 36;
}

original_code:
unsigned char *sha256_read(SHA256_CONTEXT * hd)
{
 return hd->buf;
}

canonical_original_code:
unsigned char *sha256_read(struct SHA256_CONTEXT *hd)
{
 return hd->buf;
}

return_type: unsigned char *


printarray

decompiled_code:
int __fastcall printarray(const char *a1, __int64 a2, __int64 a3)
{
unsigned __int64 i; // rbx
const char *v5; // rdx

printf("%s[", a1);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v5 = (const char *)&unk_402004;
if ( a2 - 1 <= i )
v5 = "";
printf("%lu%s", *(_QWORD *)(a3 + 8 * i), v5);
}
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, __int64 a2, __int64 a3)
{
unsigned __int64 i; // rbx
const char *v5; // rdx

printf("%s[", a1);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v5 = (const char *)&unk_402004;
if ( a2 - 1 <= i )
v5 = "";
printf("%lu%s", *(_QWORD *)(a3 + 8 * i), v5);
}
}
return puts("]");
}

original_code:
void printarray(char *msg, size_t size, size_t array[size])
{
 printf("%s[", msg);
 for (size_t i = 0; i < size; ++i)
  printf("%lu%s", (long unsigned)array[i], i < size -1 ? ", " : "");
 printf("]\n");
}

canonical_original_code:
void printarray(char *msg, unsigned long size, unsigned long array[-1])
{
 printf("%s[", msg);
 for (unsigned long i = 0; i < size; ++i)
  printf("%lu%s", (unsigned long)array[i], i < size -1 ? ", " : "");
 printf("]\n");
}

variable_types:
msg
char *

variable_types:
size
unsigned long

variable_types:
array
unsigned long [-1]

variable_types:
i
unsigned long


printfreq

decompiled_code:
int __fastcall printfreq(const char *a1, unsigned __int64 a2)
{
double v2; // xmm0_8

printf("%s", a1);
if ( a2 <= 0x3E7 )
return printf("%lu MHz\n", a2);
if ( (a2 & 0x8000000000000000LL) != 0LL )
v2 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v2 = (double)(int)a2;
return printf("%.2f GHz\n", v2 / 1000.0);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, unsigned __int64 a2)
{
double v2; // xmm0_8

printf("%s", a1);
if ( a2 <= 0x3E7 )
return printf("%lu MHz\n", a2);
if ( (a2 & 0x8000000000000000LL) != 0LL )
v2 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v2 = (double)(int)a2;
return printf("%.2f GHz\n", v2 / 1000.0);
}

original_code:
void printfreq(char *msg, cl_ulong freq)
{
 printf("%s", msg);
 if (freq >= 1000)
  printf("%.2f GHz\n", (unsigned long)freq / 1000.0);
 else
  printf("%lu MHz\n", (unsigned long)freq);
}

canonical_original_code:
void printfreq(char *msg, unsigned long freq)
{
 printf("%s", msg);
 if (freq >= 1000)
  printf("%.2f GHz\n", (unsigned long)freq / 1000.0);
 else
  printf("%lu MHz\n", (unsigned long)freq);
}

variable_types:
freq
unsigned long


printsize

decompiled_code:
int __fastcall printsize(const char *a1, unsigned __int64 a2)
{
printf("%s", a1);
if ( a2 <= 0x3FF )
return printf("%lu\n", a2);
if ( a2 <= 0xFFFFF )
{
printf("%lu Kb", a2 >> 10);
}
else if ( a2 > 0x3FFFFFFF )
{
printf("%lu Gb", a2 >> 30);
}
else
{
printf("%lu Mb", a2 >> 20);
}
return printf(" (%lu)\n", a2);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, unsigned __int64 a2)
{
printf("%s", a1);
if ( a2 <= 0x3FF )
return printf("%lu\n", a2);
if ( a2 <= 0xFFFFF )
{
printf("%lu Kb", a2 >> 10);
}
else if ( a2 > 0x3FFFFFFF )
{
printf("%lu Gb", a2 >> 30);
}
else
{
printf("%lu Mb", a2 >> 20);
}
return printf(" (%lu)\n", a2);
}

original_code:
void printsize(char *msg, cl_ulong size)
{
 printf("%s", msg);
 if (size < 1024)
  printf("%lu\n", (unsigned long)size);
 else if (size < 1024 * 1024)
  printf("%lu Kb", (unsigned long)size / 1024);
 else if (size < 1024 * 1024 * 1024)
  printf("%lu Mb", (unsigned long)size / 1024 / 1024);
 else
  printf("%lu Gb", (unsigned long)size / 1024 / 1024 / 1024);
 if (size >= 1024)
  printf(" (%lu)\n", (unsigned long) size);
}

canonical_original_code:
void printsize(char *msg, unsigned long size)
{
 printf("%s", msg);
 if (size < 1024)
  printf("%lu\n", (unsigned long)size);
 else if (size < 1024 * 1024)
  printf("%lu Kb", (unsigned long)size / 1024);
 else if (size < 1024 * 1024 * 1024)
  printf("%lu Mb", (unsigned long)size / 1024 / 1024);
 else
  printf("%lu Gb", (unsigned long)size / 1024 / 1024 / 1024);
 if (size >= 1024)
  printf(" (%lu)\n", (unsigned long) size);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 *v4; // r12
void *v5; // rbx
void *v6; // rsp
const char *v7; // rsi
const char *v8; // rsi
_DWORD v10[4]; // [rsp+0h] [rbp-260h] BYREF
unsigned __int64 v11; // [rsp+10h] [rbp-250h]
unsigned int v12; // [rsp+1Ch] [rbp-244h]
unsigned __int64 v13; // [rsp+20h] [rbp-240h]
unsigned __int64 v14; // [rsp+28h] [rbp-238h]
unsigned __int64 v15; // [rsp+30h] [rbp-230h]
unsigned int v16; // [rsp+38h] [rbp-228h]
unsigned int v17; // [rsp+3Ch] [rbp-224h]
__int64 v18; // [rsp+40h] [rbp-220h]
unsigned int v19; // [rsp+48h] [rbp-218h]
unsigned int v20; // [rsp+4Ch] [rbp-214h]
char v21[112]; // [rsp+50h] [rbp-210h] BYREF
char v22[112]; // [rsp+C0h] [rbp-1A0h] BYREF
char v23[112]; // [rsp+130h] [rbp-130h] BYREF
char v24[112]; // [rsp+1A0h] [rbp-C0h] BYREF
size_t size; // [rsp+210h] [rbp-50h]
__int64 v26; // [rsp+220h] [rbp-40h]
__int64 v27; // [rsp+228h] [rbp-38h]
__int64 v28; // [rsp+230h] [rbp-30h]
unsigned int v29; // [rsp+23Ch] [rbp-24h]

puts("\n***** OpenCL device informations *****\n");
if ( argc <= 1 )
{
printf("Usage: %s <cpu|gpu>\n\n", *argv);
exit(1);
}
v3 = strcmp(argv[1], s2);
printf("Device type: %s\n", (&opencl_device_str)[v3 == 0]);
clGetPlatformIDs();
printf("Number of platforms: %u\n", v29);
v4 = (__int64 *)malloc(8LL * v29);
clGetPlatformIDs();
v26 = 4228LL;
v27 = *v4;
v28 = 0LL;
clCreateContextFromType();
clGetContextInfo();
v5 = malloc(size);
clGetContextInfo();
clGetDeviceInfo();
printf("Name: %s\n", v24);
clGetDeviceInfo();
printf("Vendor: %s\n", v23);
clGetDeviceInfo();
printf("Driver version: %s\n", v22);
clGetDeviceInfo();
printf("Version: %s\n", v21);
clGetDeviceInfo();
printf("Max compute units: %u\n", v20);
clGetDeviceInfo();
printf("Max work item dimensions: %u\n", v19);
v6 = alloca(16 * ((8 * (unsigned __int64)v19 + 15) >> 4));
clGetDeviceInfo();
printarray("Max work item sizes: ", v19, (__int64)v10);
clGetDeviceInfo();
printf("Max work group size: %lu\n", v18);
clGetDeviceInfo();
printfreq("Max clock frequency: ", v17);
clGetDeviceInfo();
printf("Address bits: %u\n", v16);
clGetDeviceInfo();
printsize("Max memory allocation size: ", v15);
clGetDeviceInfo();
printsize("Global memory size: ", v14);
clGetDeviceInfo();
printsize("Max constant buffer size: ", v13);
clGetDeviceInfo();
printf("Max constant arguments: %d\n", v12);
clGetDeviceInfo();
printsize("Local memory size: ", v11);
clGetDeviceInfo();
v7 = "YES";
if ( v10[3] != 1 )
v7 = "NO";
printf("Error correction support: %s\n", v7);
clGetDeviceInfo();
v8 = "little endian";
if ( v10[2] != 1 )
v8 = "big endian";
printf("Endianness: %s\n", v8);
putchar(10);
clReleaseContext();
free(v5);
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 *v4; // r12
void *v5; // rbx
void *v6; // rsp
const char *v7; // rsi
const char *v8; // rsi
_DWORD v10[4]; // [rsp+0h] [rbp-260h] BYREF
unsigned __int64 v11; // [rsp+10h] [rbp-250h]
unsigned int v12; // [rsp+1Ch] [rbp-244h]
unsigned __int64 v13; // [rsp+20h] [rbp-240h]
unsigned __int64 v14; // [rsp+28h] [rbp-238h]
unsigned __int64 v15; // [rsp+30h] [rbp-230h]
unsigned int v16; // [rsp+38h] [rbp-228h]
unsigned int v17; // [rsp+3Ch] [rbp-224h]
__int64 v18; // [rsp+40h] [rbp-220h]
unsigned int v19; // [rsp+48h] [rbp-218h]
unsigned int v20; // [rsp+4Ch] [rbp-214h]
char v21[112]; // [rsp+50h] [rbp-210h] BYREF
char v22[112]; // [rsp+C0h] [rbp-1A0h] BYREF
char v23[112]; // [rsp+130h] [rbp-130h] BYREF
char v24[112]; // [rsp+1A0h] [rbp-C0h] BYREF
size_t size; // [rsp+210h] [rbp-50h]
__int64 v26; // [rsp+220h] [rbp-40h]
__int64 v27; // [rsp+228h] [rbp-38h]
__int64 v28; // [rsp+230h] [rbp-30h]
unsigned int v29; // [rsp+23Ch] [rbp-24h]

puts("\n***** OpenCL device informations *****\n");
if ( argc <= 1 )
{
printf("Usage: %s <cpu|gpu>\n\n", *argv);
exit(1);
}
v3 = strcmp(argv[1], s2);
printf("Device type: %s\n", (&opencl_device_str)[v3 == 0]);
clGetPlatformIDs();
printf("Number of platforms: %u\n", v29);
v4 = (__int64 *)malloc(8LL * v29);
clGetPlatformIDs();
v26 = 4228LL;
v27 = *v4;
v28 = 0LL;
clCreateContextFromType();
clGetContextInfo();
v5 = malloc(size);
clGetContextInfo();
clGetDeviceInfo();
printf("Name: %s\n", v24);
clGetDeviceInfo();
printf("Vendor: %s\n", v23);
clGetDeviceInfo();
printf("Driver version: %s\n", v22);
clGetDeviceInfo();
printf("Version: %s\n", v21);
clGetDeviceInfo();
printf("Max compute units: %u\n", v20);
clGetDeviceInfo();
printf("Max work item dimensions: %u\n", v19);
v6 = alloca(16 * ((8 * (unsigned __int64)v19 + 15) >> 4));
clGetDeviceInfo();
func7("Max work item sizes: ", v19, (__int64)v10);
clGetDeviceInfo();
printf("Max work group size: %lu\n", v18);
clGetDeviceInfo();
func8("Max clock frequency: ", v17);
clGetDeviceInfo();
printf("Address bits: %u\n", v16);
clGetDeviceInfo();
func9("Max memory allocation size: ", v15);
clGetDeviceInfo();
func9("Global memory size: ", v14);
clGetDeviceInfo();
func9("Max constant buffer size: ", v13);
clGetDeviceInfo();
printf("Max constant arguments: %d\n", v12);
clGetDeviceInfo();
func9("Local memory size: ", v11);
clGetDeviceInfo();
v7 = "YES";
if ( v10[3] != 1 )
v7 = "NO";
printf("Error correction support: %s\n", v7);
clGetDeviceInfo();
v8 = "little endian";
if ( v10[2] != 1 )
v8 = "big endian";
printf("Endianness: %s\n", v8);
putchar(10);
clReleaseContext();
free(v5);
free(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *input_file_name = ((void *)0), *output_file_name = ((void *)0);
 aes_mode mode;
 unsigned short key_size_bits;
 char *password = ((void *)0);
 cl_uchar *password_hash = ((void *)0);
 opencl_device device;
 cl_uchar *buffer = ((void *)0);
 printf("\n\n-------- PAES --------\n\n\n");
 parse_command_line(argc, argv, &input_file_name, &output_file_name, &mode, &key_size_bits, &password, &device);
 check_arguments(mode, key_size_bits, device);
 size_t size = read_file(input_file_name, &buffer);
 if (password == ((void *)0)) {
  char *getpass(const char *prompt);
  password = getpass("\nPlease type the password: ");
 }
 password_hash = hash_password(password, key_size_bits / 8);
 printf("PARAMETERS:\n");
 printf("   Input file: %s\n", input_file_name);
 printf("   Output file: %s\n", output_file_name);
 printf("   AES mode: %s\n", get_aes_mode_name(mode));
 printf("   Key size: %u\n", key_size_bits);
 printf("   Device: %s\n", get_opencl_device_name(device));
 printf("   File size: %u bytes\n", (unsigned) size);
 printf("\n\n");
 if (apply_aes(buffer, size, device, mode, password_hash, key_size_bits) != -1)
  write_file(output_file_name, buffer, size);
 if (buffer)
  free(buffer);
 if (input_file_name)
  free(input_file_name);
 if (output_file_name)
  free(output_file_name);
 if (password)
  free(password);
 if (password_hash)
  free(password_hash);
 printf("\n\n----- It ends here... -----\n\n\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *input_file_name = ((void *)0); char *output_file_name = ((void *)0);
 unsigned int mode;
 unsigned short key_size_bits;
 char *password = ((void *)0);
 unsigned char *password_hash = ((void *)0);
 unsigned int device;
 unsigned char *buffer = ((void *)0);
 printf("\n\n-------- PAES --------\n\n\n");
 parse_command_line(argc, argv, &input_file_name, &output_file_name, &mode, &key_size_bits, &password, &device);
 check_arguments(mode, key_size_bits, device);
 unsigned long size = read_file(input_file_name, &buffer);
 if (password == ((void *)0)) {
  char *getpass(char *prompt);
  password = getpass("\nPlease type the password: ");
 }
 password_hash = hash_password(password, key_size_bits / 8);
 printf("PARAMETERS:\n");
 printf("   Input file: %s\n", input_file_name);
 printf("   Output file: %s\n", output_file_name);
 printf("   AES mode: %s\n", get_aes_mode_name(mode));
 printf("   Key size: %u\n", key_size_bits);
 printf("   Device: %s\n", get_opencl_device_name(device));
 printf("   File size: %u bytes\n", (unsigned int) size);
 printf("\n\n");
 if (apply_aes(buffer, size, device, mode, password_hash, key_size_bits) != -1)
  write_file(output_file_name, buffer, size);
 if (buffer)
  free(buffer);
 if (input_file_name)
  free(input_file_name);
 if (output_file_name)
  free(output_file_name);
 if (password)
  free(password);
 if (password_hash)
  free(password_hash);
 printf("\n\n----- It ends here... -----\n\n\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
mode
unsigned int

variable_types:
password
char *

variable_types:
device
unsigned int

variable_types:
buffer
unsigned char *

variable_types:
getpass
char *(char *prompt)

return_type: int


decompiled_code:
void __fastcall __noreturn show_help(const char **a1)
{
const char *v1; // rax

printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", *a1);
puts(" -i INPUT the input file");
puts(" -o OUTPUT the output file");
puts(" -m MODE MODE can be encrypt or decrypt");
printf(" -k KEY_SIZE the key size can be 128, 192 or 256 (default is %d)\n", 128LL);
puts(" -p PASSWD the password; if unspecified the user will be asked to type it");
v1 = (const char *)get_opencl_device_name(0LL);
printf(" -d DEV DEV can be cpu or gpu (default is %s)\n", v1);
puts(" -g GSIZE the OpenCL global work size (default is decided by OpenCL)");
printf(" -l LSIZE the OpenCL local work size (default is %u)\n", 8LL);
putchar(10);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char **a1)
{
const char *v1; // rax

printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", *a1);
puts(" -i INPUT the input file");
puts(" -o OUTPUT the output file");
puts(" -m MODE MODE can be encrypt or decrypt");
printf(" -k KEY_SIZE the key size can be 128, 192 or 256 (default is %d)\n", 128LL);
puts(" -p PASSWD the password; if unspecified the user will be asked to type it");
v1 = (const char *)get_opencl_device_name(0LL);
printf(" -d DEV DEV can be cpu or gpu (default is %s)\n", v1);
puts(" -g GSIZE the OpenCL global work size (default is decided by OpenCL)");
printf(" -l LSIZE the OpenCL local work size (default is %u)\n", 8LL);
putchar(10);
exit(0);
}

original_code:
void show_help(char *argv[])
{
 printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", argv[0]);
 printf("  -i INPUT         the input file\n");
 printf("  -o OUTPUT        the output file\n");
 printf("  -m MODE          MODE can be encrypt or decrypt\n");
 printf("  -k KEY_SIZE      the key size can be 128, 192 or 256 (default is %d)\n", default_key_size_bits);
 printf("  -p PASSWD        the password; if unspecified the user will be asked to type it\n");
 printf("  -d DEV           DEV can be cpu or gpu (default is %s)\n", get_opencl_device_name(0));
 printf("  -g GSIZE         the OpenCL global work size (default is decided by OpenCL)\n");
 printf("  -l LSIZE         the OpenCL local work size (default is %u)\n", (unsigned) 8);
 printf("\n");
 exit(0);
}

canonical_original_code:
void show_help(char *argv[])
{
 printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", argv[0]);
 printf("  -i INPUT         the input file\n");
 printf("  -o OUTPUT        the output file\n");
 printf("  -m MODE          MODE can be encrypt or decrypt\n");
 printf("  -k KEY_SIZE      the key size can be 128, 192 or 256 (default is %d)\n", default_key_size_bits);
 printf("  -p PASSWD        the password; if unspecified the user will be asked to type it\n");
 printf("  -d DEV           DEV can be cpu or gpu (default is %s)\n", get_opencl_device_name(0));
 printf("  -g GSIZE         the OpenCL global work size (default is decided by OpenCL)\n");
 printf("  -l LSIZE         the OpenCL local work size (default is %u)\n", (unsigned int) 8);
 printf("\n");
 exit(0);
}


decompiled_code:
__int64 __fastcall parse_command_line(int argc, char **argv, char **a3, char **a4, _DWORD *a5, _WORD *a6, __int64 a7, __int64 a8)
{
size_t v12; // rax
char *v13; // rax
int v14; // edx
__int64 result; // rax
size_t v16; // rax
char *v17; // rax
size_t v18; // rax
char *v19; // rax

if ( argc == 1 )
show_help((const char **)argv);
*a6 = 128;
*(_QWORD *)a7 = 0LL;
*(_DWORD *)a8 = 0;
*a5 = 2;
while ( 2 )
{
v14 = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
result = (unsigned int)(v14 - 100);
switch ( v14 )
{
case 'd':
if ( !strcmp(optarg, "cpu") )
*(_DWORD *)a8 = 0;
else
*(_DWORD *)a8 = 1 - ((strcmp(optarg, "gpu") == 0) - 1);
continue;
case 'h':
show_help((const char **)argv);
case 'i':
v12 = strlen(optarg);
v13 = (char *)malloc(v12 + 1);
*a3 = v13;
strcpy(v13, optarg);
continue;
case 'k':
*a6 = atoi(optarg);
continue;
case 'm':
if ( !strcmp(optarg, "encrypt") )
*a5 = 0;
else
*a5 = 1 - ((strcmp(optarg, "decrypt") == 0) - 1);
continue;
case 'o':
v16 = strlen(optarg);
v17 = (char *)malloc(v16 + 1);
*a4 = v17;
strcpy(v17, optarg);
continue;
case 'p':
v18 = strlen(optarg);
v19 = (char *)malloc(v18 + 1);
*(_QWORD *)a7 = v19;
strcpy(v19, optarg);
continue;
default:
if ( v14 != -1 )
continue;
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv, char **a3, char **a4, _DWORD *a5, _WORD *a6, __int64 a7, __int64 a8)
{
size_t v12; // rax
char *v13; // rax
int v14; // edx
__int64 result; // rax
size_t v16; // rax
char *v17; // rax
size_t v18; // rax
char *v19; // rax

if ( argc == 1 )
func0((const char **)argv);
*a6 = 128;
*(_QWORD *)a7 = 0LL;
*(_DWORD *)a8 = 0;
*a5 = 2;
while ( 2 )
{
v14 = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
result = (unsigned int)(v14 - 100);
switch ( v14 )
{
case 'd':
if ( !strcmp(optarg, "cpu") )
*(_DWORD *)a8 = 0;
else
*(_DWORD *)a8 = 1 - ((strcmp(optarg, "gpu") == 0) - 1);
continue;
case 'h':
func0((const char **)argv);
case 'i':
v12 = strlen(optarg);
v13 = (char *)malloc(v12 + 1);
*a3 = v13;
strcpy(v13, optarg);
continue;
case 'k':
*a6 = atoi(optarg);
continue;
case 'm':
if ( !strcmp(optarg, "encrypt") )
*a5 = 0;
else
*a5 = 1 - ((strcmp(optarg, "decrypt") == 0) - 1);
continue;
case 'o':
v16 = strlen(optarg);
v17 = (char *)malloc(v16 + 1);
*a4 = v17;
strcpy(v17, optarg);
continue;
case 'p':
v18 = strlen(optarg);
v19 = (char *)malloc(v18 + 1);
*(_QWORD *)a7 = v19;
strcpy(v19, optarg);
continue;
default:
if ( v14 != -1 )
continue;
return result;
}
}
}

original_code:
void parse_command_line(int argc, char *argv[], char **input_file_name, char **output_file_name, aes_mode * mode, unsigned short *key_size_bits, char **password, opencl_device * device)
{
 if (argc == 1)
  show_help(argv);
 int c;
 *key_size_bits = default_key_size_bits;
 *password = ((void *)0);
 *device = 0;
 *mode = 2;
 do {
  c = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
  switch (c) {
  case 'i':
   *input_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*input_file_name, optarg);
   break;
  case 'o':
   *output_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*output_file_name, optarg);
   break;
  case 'd':
   if (strcmp(optarg, "cpu") == 0)
    *device = 0;
   else if (strcmp(optarg, "gpu") == 0)
    *device = 1;
   else
    *device = 2;
   break;
  case 'k':
   *key_size_bits = atoi(optarg);
   break;
  case 'p':
   *password = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*password, optarg);
   break;
  case 'm':
   if (strcmp(optarg, "encrypt") == 0)
    *mode = 0;
   else if (strcmp(optarg, "decrypt") == 0)
    *mode = 1;
   else
    *mode = 2;
   break;
  case 'h':
   show_help(argv);
  }
 } while (c != -1);
}

canonical_original_code:
void parse_command_line(int argc, char *argv[], char **input_file_name, char **output_file_name, unsigned int *mode, unsigned short *key_size_bits, char **password, unsigned int *device)
{
 if (argc == 1)
  show_help(argv);
 int c;
 *key_size_bits = default_key_size_bits;
 *password = ((void *)0);
 *device = 0;
 *mode = 2;
 do {
  c = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
  switch (c) {
  case 'i':
   *input_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*input_file_name, optarg);
   break;
  case 'o':
   *output_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*output_file_name, optarg);
   break;
  case 'd':
   if (strcmp(optarg, "cpu") == 0)
    *device = 0;
   else if (strcmp(optarg, "gpu") == 0)
    *device = 1;
   else
    *device = 2;
   break;
  case 'k':
   *key_size_bits = atoi(optarg);
   break;
  case 'p':
   *password = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*password, optarg);
   break;
  case 'm':
   if (strcmp(optarg, "encrypt") == 0)
    *mode = 0;
   else if (strcmp(optarg, "decrypt") == 0)
    *mode = 1;
   else
    *mode = 2;
   break;
  case 'h':
   show_help(argv);
  }
 } while (c != -1);
}

variable_types:
mode
unsigned int *

variable_types:
password
char **

variable_types:
device
unsigned int *

variable_types: c int


decompiled_code:
__int64 __fastcall check_arguments(int a1, int a2, int a3)
{
__int64 result; // rax

if ( a1 == 2 )
{
fwrite("ERROR: wrong AES mode, it should be encrypt or decrypt.\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
result = a2 & 0xFFFFFFBF;
if ( (a2 & 0xFFBF) != 128 && (_WORD)a2 != 256 )
{
fwrite("ERROR: wrong key size, it should be 128, 192 or 256.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
if ( a3 == 2 )
{
fwrite("ERROR: wrong OpenCL device, it should be cpu or gpu.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
return result;
}

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

if ( a1 == 2 )
{
fwrite("ERROR: wrong AES mode, it should be encrypt or decrypt.\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
result = a2 & 0xFFFFFFBF;
if ( (a2 & 0xFFBF) != 128 && (_WORD)a2 != 256 )
{
fwrite("ERROR: wrong key size, it should be 128, 192 or 256.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
if ( a3 == 2 )
{
fwrite("ERROR: wrong OpenCL device, it should be cpu or gpu.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
return result;
}

original_code:
void check_arguments(aes_mode mode, unsigned short key_size_bits, opencl_device device)
{
 if (mode == 2) {
  fprintf(stderr, "ERROR: wrong AES mode, it should be encrypt or decrypt.\n");
  exit(1);
 }
 if (key_size_bits != 128 && key_size_bits != 192 && key_size_bits != 256) {
  fprintf(stderr, "ERROR: wrong key size, it should be 128, 192 or 256.\n");
  exit(1);
 }
 if (device == 2) {
  fprintf(stderr, "ERROR: wrong OpenCL device, it should be cpu or gpu.\n");
  exit(1);
 }
}

canonical_original_code:
void check_arguments(unsigned int mode, unsigned short key_size_bits, unsigned int device)
{
 if (mode == 2) {
  fprintf(stderr, "ERROR: wrong AES mode, it should be encrypt or decrypt.\n");
  exit(1);
 }
 if (key_size_bits != 128 && key_size_bits != 192 && key_size_bits != 256) {
  fprintf(stderr, "ERROR: wrong key size, it should be 128, 192 or 256.\n");
  exit(1);
 }
 if (device == 2) {
  fprintf(stderr, "ERROR: wrong OpenCL device, it should be cpu or gpu.\n");
  exit(1);
 }
}


decompiled_code:
void *__fastcall hash_password(char *s, size_t n)
{
void *v2; // rbx
size_t v3; // rax
const void *v4; // rax
_BYTE v6[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = malloc(n);
sha256_init(v6);
v3 = strlen(s);
sha256_write(v6, s, v3);
sha256_final(v6);
v4 = (const void *)sha256_read(v6);
return memcpy(v2, v4, n);
}

canonical_decompiled_code:
void *__fastcall func3(char *s, size_t n)
{
void *v2; // rbx
size_t v3; // rax
const void *v4; // rax
_BYTE v6[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = malloc(n);
sha256_init(v6);
v3 = strlen(s);
sha256_write(v6, s, v3);
sha256_final(v6);
v4 = (const void *)sha256_read(v6);
return memcpy(v2, v4, n);
}

original_code:
cl_uchar *hash_password(char *password, size_t size)
{
 cl_uchar *hash = (cl_uchar *) malloc(size * sizeof(cl_uchar));
 SHA256_CONTEXT context;
 sha256_init(&context);
 sha256_write(&context, (unsigned char *) password, strlen(password));
 sha256_final(&context);
 memcpy(hash, sha256_read(&context), size);
 return hash;
}

canonical_original_code:
unsigned char *hash_password(char *password, unsigned long size)
{
 unsigned char *hash = (cl_uchar *) malloc(size * sizeof(cl_uchar));
 struct SHA256_CONTEXT context;
 sha256_init(&context);
 sha256_write(&context, (unsigned char *) password, strlen(password));
 sha256_final(&context);
 memcpy(hash, sha256_read(&context), size);
 return hash;
}

variable_types:
hash
unsigned char *

variable_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
void *v4; // rbx
const char *v5; // rax
const char *v6; // rax
void *ptr; // [rsp+0h] [rbp-48h] BYREF
unsigned int s[3]; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int16 v10; // [rsp+1Ah] [rbp-2Eh] BYREF
unsigned int v11; // [rsp+1Ch] [rbp-2Ch] BYREF
void *v12; // [rsp+20h] [rbp-28h] BYREF
void *v13; // [rsp+28h] [rbp-20h] BYREF

v13 = 0LL;
v12 = 0LL;
*(_QWORD *)&s[1] = 0LL;
ptr = 0LL;
puts("\n\n-------- PAES --------\n\n");
parse_command_line(argc, (char **)argv, (char **)&v13, (char **)&v12, &v11, &v10, (__int64)&s[1], (__int64)s);
check_arguments(v11, v10, s[0]);
v3 = read_file(v13, &ptr);
if ( !*(_QWORD *)&s[1] )
*(_QWORD *)&s[1] = getpass("\nPlease type the password: ");
v4 = hash_password(*(char **)&s[1], v10 >> 3);
puts("PARAMETERS:");
printf(" Input file: %s\n", (const char *)v13);
printf(" Output file: %s\n", (const char *)v12);
v5 = (const char *)get_aes_mode_name(v11);
printf(" AES mode: %s\n", v5);
printf(" Key size: %u\n", v10);
v6 = (const char *)get_opencl_device_name(s[0]);
printf(" Device: %s\n", v6);
printf(" File size: %u bytes\n", (unsigned int)v3);
puts("\n");
if ( (unsigned int)apply_aes(ptr, v3, s[0], v11, v4, v10) != -1 )
write_file(v12, ptr, v3);
if ( ptr )
free(ptr);
if ( v13 )
free(v13);
if ( v12 )
free(v12);
if ( *(_QWORD *)&s[1] )
free(*(void **)&s[1]);
if ( v4 )
free(v4);
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; // rbp
void *v4; // rbx
const char *v5; // rax
const char *v6; // rax
void *ptr; // [rsp+0h] [rbp-48h] BYREF
unsigned int s[3]; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int16 v10; // [rsp+1Ah] [rbp-2Eh] BYREF
unsigned int v11; // [rsp+1Ch] [rbp-2Ch] BYREF
void *v12; // [rsp+20h] [rbp-28h] BYREF
void *v13; // [rsp+28h] [rbp-20h] BYREF

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

variable_types:
size
unsigned long


draw

decompiled_code:
void *__fastcall draw(__m128i a1, __m128i a2, __m128i a3)
{
int v3; // ebp
int v4; // er12
int v5; // er13
void *result; // rax
_DWORD *v7; // rax
unsigned int v8; // er12
__int64 v9; // rbp
int v10[14]; // [rsp+0h] [rbp-38h] BYREF

if ( !vdevice )
{
verror("draw: vogl not initialised");
goto LABEL_10;
}
v5 = _mm_cvtsi128_si32(a1);
v4 = _mm_cvtsi128_si32(a2);
v3 = _mm_cvtsi128_si32(a3);
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_10:
v7 = (_DWORD *)newtokens(4LL);
*v7 = 8;
v7[1] = v5;
v7[2] = v4;
v7[3] = v3;
result = &vdevice;
*((_DWORD *)&vdevice + 14) = v5;
*((_DWORD *)&vdevice + 15) = v4;
*((_DWORD *)&vdevice + 16) = v3;
*((_BYTE *)&vdevice + 5) = 0;
return result;
}
if ( !*((_BYTE *)&vdevice + 5) )
multvector((char *)&vdevice + 72, (char *)&vdevice + 56, *((_QWORD *)&vdevice + 3));
*((_DWORD *)&vdevice + 14) = v5;
*((_DWORD *)&vdevice + 15) = v4;
*((_DWORD *)&vdevice + 16) = v3;
multvector(v10, (char *)&vdevice + 56, *((_QWORD *)&vdevice + 3));
if ( *((_BYTE *)&vdevice + 1) )
{
v8 = WtoVx(v10);
v9 = (unsigned int)WtoVy(v10);
(*((void (__fastcall **)(_QWORD, __int64))&vdevice + 27))(v8, v9);
*((_DWORD *)&vdevice + 35) = v8;
*((_DWORD *)&vdevice + 36) = v9;
*((_BYTE *)&vdevice + 5) = 0;
}
else if ( *((_BYTE *)&vdevice + 5) )
{
quickclip((char *)&vdevice + 72, v10);
}
else
{
clip((char *)&vdevice + 72, v10);
}
result = &vdevice;
*((_DWORD *)&vdevice + 18) = v10[0];
*((_DWORD *)&vdevice + 19) = v10[1];
*((_DWORD *)&vdevice + 20) = v10[2];
*((_DWORD *)&vdevice + 21) = v10[3];
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__m128i a1, __m128i a2, __m128i a3)
{
int v3; // ebp
int v4; // er12
int v5; // er13
void *result; // rax
_DWORD *v7; // rax
unsigned int v8; // er12
__int64 v9; // rbp
int v10[14]; // [rsp+0h] [rbp-38h] BYREF

if ( !vdevice )
{
verror("draw: vogl not initialised");
goto LABEL_10;
}
v5 = _mm_cvtsi128_si32(a1);
v4 = _mm_cvtsi128_si32(a2);
v3 = _mm_cvtsi128_si32(a3);
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_10:
v7 = (_DWORD *)newtokens(4LL);
*v7 = 8;
v7[1] = v5;
v7[2] = v4;
v7[3] = v3;
result = &vdevice;
*((_DWORD *)&vdevice + 14) = v5;
*((_DWORD *)&vdevice + 15) = v4;
*((_DWORD *)&vdevice + 16) = v3;
*((_BYTE *)&vdevice + 5) = 0;
return result;
}
if ( !*((_BYTE *)&vdevice + 5) )
multvector((char *)&vdevice + 72, (char *)&vdevice + 56, *((_QWORD *)&vdevice + 3));
*((_DWORD *)&vdevice + 14) = v5;
*((_DWORD *)&vdevice + 15) = v4;
*((_DWORD *)&vdevice + 16) = v3;
multvector(v10, (char *)&vdevice + 56, *((_QWORD *)&vdevice + 3));
if ( *((_BYTE *)&vdevice + 1) )
{
v8 = WtoVx(v10);
v9 = (unsigned int)WtoVy(v10);
(*((void (__fastcall **)(_QWORD, __int64))&vdevice + 27))(v8, v9);
*((_DWORD *)&vdevice + 35) = v8;
*((_DWORD *)&vdevice + 36) = v9;
*((_BYTE *)&vdevice + 5) = 0;
}
else if ( *((_BYTE *)&vdevice + 5) )
{
quickclip((char *)&vdevice + 72, v10);
}
else
{
clip((char *)&vdevice + 72, v10);
}
result = &vdevice;
*((_DWORD *)&vdevice + 18) = v10[0];
*((_DWORD *)&vdevice + 19) = v10[1];
*((_DWORD *)&vdevice + 20) = v10[2];
*((_DWORD *)&vdevice + 21) = v10[3];
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]


draws

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:
void *__fastcall drawi(int a1, int a2, int a3)
{
__m128i v3; // xmm0
__m128i v4; // xmm2
__m128i v5; // xmm1

v3 = 0LL;
*(float *)v3.m128i_i32 = (float)a1;
v4 = 0LL;
*(float *)v4.m128i_i32 = (float)a3;
v5 = 0LL;
*(float *)v5.m128i_i32 = (float)a2;
return draw(v3, v5, v4);
}

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:
void *__fastcall draw2(__m128i a1, __m128i a2)
{
if ( vdevice )
return draw(a1, a2, (__m128i)0LL);
verror("draw2: vogl not initialised");
return (void *)draw2s();
}

canonical_decompiled_code:
void *__fastcall func3(__m128i a1, __m128i a2)
{
if ( vdevice )
return func0(a1, a2, (__m128i)0LL);
verror("draw2: vogl not initialised");
return (void *)func4();
}

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


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:
void *__fastcall draw2i(int a1, int a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm1

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)a1;
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)a2;
return draw2(v2, v3);
}

canonical_decompiled_code:
void *__fastcall func5(int a1, int a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm1

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)a1;
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)a2;
return func3(v2, v3);
}

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:
void *__fastcall rdr(__m128i a1, __m128i a2, __m128i a3)
{
void *result; // rax

if ( vdevice )
{
*(float *)a1.m128i_i32 = *(float *)a1.m128i_i32 + *((float *)&vdevice + 14);
*(float *)a3.m128i_i32 = *(float *)a3.m128i_i32 + *((float *)&vdevice + 16);
*(float *)a2.m128i_i32 = *(float *)a2.m128i_i32 + *((float *)&vdevice + 15);
result = draw(a1, a2, a3);
}
else
{
verror("rdr: vogl not initialised");
result = (void *)rdrs();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__m128i a1, __m128i a2, __m128i a3)
{
void *result; // rax

if ( vdevice )
{
*(float *)a1.m128i_i32 = *(float *)a1.m128i_i32 + *((float *)&vdevice + 14);
*(float *)a3.m128i_i32 = *(float *)a3.m128i_i32 + *((float *)&vdevice + 16);
*(float *)a2.m128i_i32 = *(float *)a2.m128i_i32 + *((float *)&vdevice + 15);
result = func0(a1, a2, a3);
}
else
{
verror("rdr: vogl not initialised");
result = (void *)func7();
}
return result;
}

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

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

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:
void *__fastcall rdr2(__m128i a1, __m128i a2)
{
void *result; // rax

if ( vdevice )
{
*(float *)a1.m128i_i32 = *(float *)a1.m128i_i32 + *((float *)&vdevice + 14);
*(float *)a2.m128i_i32 = *(float *)a2.m128i_i32 + *((float *)&vdevice + 15);
result = draw(a1, a2, (__m128i)0LL);
}
else
{
verror("rdr2: vogl not initialised");
result = (void *)rdr2s();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(__m128i a1, __m128i a2)
{
void *result; // rax

if ( vdevice )
{
*(float *)a1.m128i_i32 = *(float *)a1.m128i_i32 + *((float *)&vdevice + 14);
*(float *)a2.m128i_i32 = *(float *)a2.m128i_i32 + *((float *)&vdevice + 15);
result = func0(a1, a2, (__m128i)0LL);
}
else
{
verror("rdr2: vogl not initialised");
result = (void *)func10();
}
return result;
}

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


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:
void *__fastcall rdr2i(int a1, int a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm1

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)a1;
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)a2;
return rdr2(v2, v3);
}

canonical_decompiled_code:
void *__fastcall func11(int a1, int a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm1

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)a1;
v3 = 0LL;
*(float *)v3.m128i_i32 = (float)a2;
return func9(v2, v3);
}

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()
{
__int64 result; // rax

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

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

if ( *((_BYTE *)&vdevice + 348) )
{
verror("vogl: bgnline mode already belongs to some other bgn routine");
result = func13();
}
else
{
*((_BYTE *)&vdevice + 348) = 2;
*((_DWORD *)&vdevice + 88) = 1;
sync = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
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

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

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

if ( *((_BYTE *)&vdevice + 348) )
{
verror("vogl: bgncloseline mode already belongs to some other bgn routine");
result = (void *)func15();
}
else
{
result = &vdevice;
*((_BYTE *)&vdevice + 348) = 3;
*((_DWORD *)&vdevice + 88) = 1;
sync = *((char *)&vdevice + 6);
*((_BYTE *)&vdevice + 6) = 0;
}
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:
void *endclosedline()
{
*((_BYTE *)&vdevice + 348) = 0;
*((_BYTE *)&vdevice + 6) = sync;
return draw(
(__m128i)*((unsigned int *)&vdevice + 84),
(__m128i)*((unsigned int *)&vdevice + 85),
(__m128i)*((unsigned int *)&vdevice + 86));
}

canonical_decompiled_code:
void *func15()
{
*((_BYTE *)&vdevice + 348) = 0;
*((_BYTE *)&vdevice + 6) = sync;
return func0(
(__m128i)*((unsigned int *)&vdevice + 84),
(__m128i)*((unsigned int *)&vdevice + 85),
(__m128i)*((unsigned int *)&vdevice + 86));
}

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

decompiled_code:
__int64 __fastcall getdevice(const char *a1)
{
bool v1; // cf
bool v2; // zf
__int64 v4; // rcx
const char *v5; // rdi
const char *v6; // rsi
char v7; // al
bool v8; // cf
bool v9; // zf
__int64 v10; // rcx
const char *v11; // rdi
const char *v12; // rsi
char v13; // al
bool v14; // cf
bool v15; // zf
__int64 v16; // rcx
const char *v17; // rdi
const char *v18; // rsi
char v19; // al
bool v20; // cf
bool v21; // zf
__int64 v22; // rcx
const char *v23; // rdi
const char *v24; // rsi
char v25; // al
bool v26; // cf
bool v27; // zf
__int64 v28; // rcx
const char *v29; // rdi
const char *v30; // rsi
char v31; // al
bool v32; // cf
bool v33; // zf
__int64 v34; // rcx
const char *v35; // rdi
const char *v36; // rsi
char v37; // al
bool v38; // cf
bool v39; // zf
__int64 v40; // rcx
const char *v41; // rdi
const char *v42; // rsi
char v43; // al
bool v44; // cf
bool v45; // zf
__int64 v46; // rcx
const char *v47; // rdi
const char *v48; // rsi
char v49; // al
bool v50; // cf
bool v51; // zf
__int64 v52; // rcx
const char *v53; // rdi
const char *v54; // rsi
char v55; // al
bool v56; // cf
bool v57; // zf
__int64 v58; // rcx
char v59; // al
bool v60; // cf
bool v61; // zf
__int64 v63; // rcx
const char *v64; // rdi
const char *v65; // rsi
char v66[120]; // [rsp+0h] [rbp-78h] BYREF

v1 = 0;
v2 = 0;
v4 = 3LL;
v5 = (const char *)&LC0;
v6 = a1;
do
{
if ( !v4 )
break;
v1 = *v6 < (unsigned int)*v5;
v2 = *v6++ == *v5++;
--v4;
}
while ( v2 );
v7 = (!v1 && !v2) - v1;
v8 = 0;
v9 = v7 == 0;
if ( !v7 )
return X11_devcpy(v5, v6);
v10 = 10LL;
v11 = "postscript";
v12 = a1;
do
{
if ( !v10 )
break;
v8 = *v12 < (unsigned int)*v11;
v9 = *v12++ == *v11++;
--v10;
}
while ( v9 );
v13 = (!v8 && !v9) - v8;
v14 = 0;
v15 = v13 == 0;
if ( !v13 )
return PS_devcpy(v11, v12);
v16 = 11LL;
v17 = "ppostscript";
v18 = a1;
do
{
if ( !v16 )
break;
v14 = *v18 < (unsigned int)*v17;
v15 = *v18++ == *v17++;
--v16;
}
while ( v15 );
v19 = (!v14 && !v15) - v14;
v20 = 0;
v21 = v19 == 0;
if ( !v19 )
return PSP_devcpy(v17, v18);
v22 = 3LL;
v23 = "cps";
v24 = a1;
do
{
if ( !v22 )
break;
v20 = *v24 < (unsigned int)*v23;
v21 = *v24++ == *v23++;
--v22;
}
while ( v21 );
v25 = (!v20 && !v21) - v20;
v26 = 0;
v27 = v25 == 0;
if ( !v25 )
return CPS_devcpy(v23, v24);
v28 = 4LL;
v29 = "pcps";
v30 = a1;
do
{
if ( !v28 )
break;
v26 = *v30 < (unsigned int)*v29;
v27 = *v30++ == *v29++;
--v28;
}
while ( v27 );
v31 = (!v26 && !v27) - v26;
v32 = 0;
v33 = v31 == 0;
if ( !v31 )
return PCPS_devcpy(v29, v30);
v34 = 6LL;
v35 = "hpgla1";
v36 = a1;
do
{
if ( !v34 )
break;
v32 = *v36 < (unsigned int)*v35;
v33 = *v36++ == *v35++;
--v34;
}
while ( v33 );
v37 = (!v32 && !v33) - v32;
v38 = 0;
v39 = v37 == 0;
if ( !v37 )
return HPGL_A1_devcpy(v35, v36);
v40 = 6LL;
v41 = "hpgla3";
v42 = a1;
do
{
if ( !v40 )
break;
v38 = *v42 < (unsigned int)*v41;
v39 = *v42++ == *v41++;
--v40;
}
while ( v39 );
v43 = (!v38 && !v39) - v38;
v44 = 0;
v45 = v43 == 0;
if ( !v43 )
return HPGL_A3_devcpy(v41, v42);
v46 = 6LL;
v47 = "hpgla4";
v48 = a1;
do
{
if ( !v46 )
break;
v44 = *v48 < (unsigned int)*v47;
v45 = *v48++ == *v47++;
--v46;
}
while ( v45 );
v49 = (!v44 && !v45) - v44;
v50 = 0;
v51 = v49 == 0;
if ( !v49 )
return HPGL_A4_devcpy(v47, v48);
v52 = 6LL;
v53 = "hpgla2";
v54 = a1;
do
{
if ( !v52 )
break;
v50 = *v54 < (unsigned int)*v53;
v51 = *v54++ == *v53++;
--v52;
}
while ( v51 );
v55 = (!v50 && !v51) - v50;
v56 = 0;
v57 = v55 == 0;
if ( !v55 )
return HPGL_A2_devcpy(v53, v54);
v58 = 4LL;
v53 = "hpgl";
v54 = a1;
do
{
if ( !v58 )
break;
v56 = *v54 < (unsigned int)*v53;
v57 = *v54++ == *v53++;
--v58;
}
while ( v57 );
v59 = (!v56 && !v57) - v56;
v60 = 0;
v61 = v59 == 0;
if ( !v59 )
return HPGL_A2_devcpy(v53, v54);
v63 = 3LL;
v64 = "tek";
v65 = a1;
do
{
if ( !v63 )
break;
v60 = *v65 < (unsigned int)*v64;
v61 = *v65++ == *v64++;
--v63;
}
while ( v61 );
if ( (!v60 && !v61) != v60 )
{
if ( *a1 )
sprintf(v66, "vogl: %s is an invalid device type\n", a1);
else
strcpy(v66, "vogl: expected the enviroment variable VDEVICE to be set to the desired device.\n");
fputs(v66, stderr);
fwrite("The devices compiled into this library are:\n", 1uLL, 0x2CuLL, stderr);
fwrite("X11\n", 1uLL, 4uLL, stderr);
fwrite("postscript\n", 1uLL, 0xBuLL, stderr);
fwrite("ppostscript\n", 1uLL, 0xCuLL, stderr);
fwrite("cps\n", 1uLL, 4uLL, stderr);
fwrite("pcps\n", 1uLL, 5uLL, stderr);
fwrite("hpgla1\n", 1uLL, 7uLL, stderr);
fwrite("hpgla2 (or hpgl)\n", 1uLL, 0x11uLL, stderr);
fwrite("hpgla3\n", 1uLL, 7uLL, stderr);
fwrite("hpgla4\n", 1uLL, 7uLL, stderr);
fwrite("tek\n", 1uLL, 4uLL, stderr);
exit(1);
}
return TEK_devcpy(v64, v65);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
bool v1; // cf
bool v2; // zf
__int64 v4; // rcx
const char *v5; // rdi
const char *v6; // rsi
char v7; // al
bool v8; // cf
bool v9; // zf
__int64 v10; // rcx
const char *v11; // rdi
const char *v12; // rsi
char v13; // al
bool v14; // cf
bool v15; // zf
__int64 v16; // rcx
const char *v17; // rdi
const char *v18; // rsi
char v19; // al
bool v20; // cf
bool v21; // zf
__int64 v22; // rcx
const char *v23; // rdi
const char *v24; // rsi
char v25; // al
bool v26; // cf
bool v27; // zf
__int64 v28; // rcx
const char *v29; // rdi
const char *v30; // rsi
char v31; // al
bool v32; // cf
bool v33; // zf
__int64 v34; // rcx
const char *v35; // rdi
const char *v36; // rsi
char v37; // al
bool v38; // cf
bool v39; // zf
__int64 v40; // rcx
const char *v41; // rdi
const char *v42; // rsi
char v43; // al
bool v44; // cf
bool v45; // zf
__int64 v46; // rcx
const char *v47; // rdi
const char *v48; // rsi
char v49; // al
bool v50; // cf
bool v51; // zf
__int64 v52; // rcx
const char *v53; // rdi
const char *v54; // rsi
char v55; // al
bool v56; // cf
bool v57; // zf
__int64 v58; // rcx
char v59; // al
bool v60; // cf
bool v61; // zf
__int64 v63; // rcx
const char *v64; // rdi
const char *v65; // rsi
char v66[120]; // [rsp+0h] [rbp-78h] BYREF

v1 = 0;
v2 = 0;
v4 = 3LL;
v5 = (const char *)&LC0;
v6 = a1;
do
{
if ( !v4 )
break;
v1 = *v6 < (unsigned int)*v5;
v2 = *v6++ == *v5++;
--v4;
}
while ( v2 );
v7 = (!v1 && !v2) - v1;
v8 = 0;
v9 = v7 == 0;
if ( !v7 )
return X11_devcpy(v5, v6);
v10 = 10LL;
v11 = "postscript";
v12 = a1;
do
{
if ( !v10 )
break;
v8 = *v12 < (unsigned int)*v11;
v9 = *v12++ == *v11++;
--v10;
}
while ( v9 );
v13 = (!v8 && !v9) - v8;
v14 = 0;
v15 = v13 == 0;
if ( !v13 )
return PS_devcpy(v11, v12);
v16 = 11LL;
v17 = "ppostscript";
v18 = a1;
do
{
if ( !v16 )
break;
v14 = *v18 < (unsigned int)*v17;
v15 = *v18++ == *v17++;
--v16;
}
while ( v15 );
v19 = (!v14 && !v15) - v14;
v20 = 0;
v21 = v19 == 0;
if ( !v19 )
return PSP_devcpy(v17, v18);
v22 = 3LL;
v23 = "cps";
v24 = a1;
do
{
if ( !v22 )
break;
v20 = *v24 < (unsigned int)*v23;
v21 = *v24++ == *v23++;
--v22;
}
while ( v21 );
v25 = (!v20 && !v21) - v20;
v26 = 0;
v27 = v25 == 0;
if ( !v25 )
return CPS_devcpy(v23, v24);
v28 = 4LL;
v29 = "pcps";
v30 = a1;
do
{
if ( !v28 )
break;
v26 = *v30 < (unsigned int)*v29;
v27 = *v30++ == *v29++;
--v28;
}
while ( v27 );
v31 = (!v26 && !v27) - v26;
v32 = 0;
v33 = v31 == 0;
if ( !v31 )
return PCPS_devcpy(v29, v30);
v34 = 6LL;
v35 = "hpgla1";
v36 = a1;
do
{
if ( !v34 )
break;
v32 = *v36 < (unsigned int)*v35;
v33 = *v36++ == *v35++;
--v34;
}
while ( v33 );
v37 = (!v32 && !v33) - v32;
v38 = 0;
v39 = v37 == 0;
if ( !v37 )
return HPGL_A1_devcpy(v35, v36);
v40 = 6LL;
v41 = "hpgla3";
v42 = a1;
do
{
if ( !v40 )
break;
v38 = *v42 < (unsigned int)*v41;
v39 = *v42++ == *v41++;
--v40;
}
while ( v39 );
v43 = (!v38 && !v39) - v38;
v44 = 0;
v45 = v43 == 0;
if ( !v43 )
return HPGL_A3_devcpy(v41, v42);
v46 = 6LL;
v47 = "hpgla4";
v48 = a1;
do
{
if ( !v46 )
break;
v44 = *v48 < (unsigned int)*v47;
v45 = *v48++ == *v47++;
--v46;
}
while ( v45 );
v49 = (!v44 && !v45) - v44;
v50 = 0;
v51 = v49 == 0;
if ( !v49 )
return HPGL_A4_devcpy(v47, v48);
v52 = 6LL;
v53 = "hpgla2";
v54 = a1;
do
{
if ( !v52 )
break;
v50 = *v54 < (unsigned int)*v53;
v51 = *v54++ == *v53++;
--v52;
}
while ( v51 );
v55 = (!v50 && !v51) - v50;
v56 = 0;
v57 = v55 == 0;
if ( !v55 )
return HPGL_A2_devcpy(v53, v54);
v58 = 4LL;
v53 = "hpgl";
v54 = a1;
do
{
if ( !v58 )
break;
v56 = *v54 < (unsigned int)*v53;
v57 = *v54++ == *v53++;
--v58;
}
while ( v57 );
v59 = (!v56 && !v57) - v56;
v60 = 0;
v61 = v59 == 0;
if ( !v59 )
return HPGL_A2_devcpy(v53, v54);
v63 = 3LL;
v64 = "tek";
v65 = a1;
do
{
if ( !v63 )
break;
v60 = *v65 < (unsigned int)*v64;
v61 = *v65++ == *v64++;
--v63;
}
while ( v61 );
if ( (!v60 && !v61) != v60 )
{
if ( *a1 )
sprintf(v66, "vogl: %s is an invalid device type\n", a1);
else
strcpy(v66, "vogl: expected the enviroment variable VDEVICE to be set to the desired device.\n");
fputs(v66, stderr);
fwrite("The devices compiled into this library are:\n", 1uLL, 0x2CuLL, stderr);
fwrite("X11\n", 1uLL, 4uLL, stderr);
fwrite("postscript\n", 1uLL, 0xBuLL, stderr);
fwrite("ppostscript\n", 1uLL, 0xCuLL, stderr);
fwrite("cps\n", 1uLL, 4uLL, stderr);
fwrite("pcps\n", 1uLL, 5uLL, stderr);
fwrite("hpgla1\n", 1uLL, 7uLL, stderr);
fwrite("hpgla2 (or hpgl)\n", 1uLL, 0x11uLL, stderr);
fwrite("hpgla3\n", 1uLL, 7uLL, stderr);
fwrite("hpgla4\n", 1uLL, 7uLL, stderr);
fwrite("tek\n", 1uLL, 4uLL, stderr);
exit(1);
}
return TEK_devcpy(v64, v65);
}

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))();
*((_QWORD *)&vdevice + 46) = 0LL;
vdevice = 0;
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))();
*((_QWORD *)&vdevice + 46) = 0LL;
vdevice = 0;
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 i; // rax
_BYTE *v4; // rdx
__int64 v5; // rsi
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

v2 = (char *)vdevice[46];
if ( v2 || (v2 = getenv("VDEVICE")) != 0LL )
{
getdevice(v2);
}
else
{
v2 = (char *)&LC29;
getdevice((const char *)&LC29);
}
if ( LOBYTE(vdevice[0]) )
gexit();
if ( !allocated )
{
allocated = 1;
a2 = 0xFFFFLL;
deflinestyle(0LL, 0xFFFFLL);
v7 = vallocate(72LL);
vdevice[3] = v7;
*(_QWORD *)(v7 + 64) = 0LL;
v8 = vallocate(24LL);
vdevice[4] = v8;
*(_QWORD *)(v8 + 16) = 0LL;
v9 = vallocate(24LL);
vdevice[5] = v9;
*(_QWORD *)(v9 + 16) = 0LL;
vdevice[63] = vallocate(640LL);
v2 = (_BYTE *)(&loc_20 + 2);
vdevice[64] = vallocate(34LL);
}
for ( i = 0LL; i != 34; ++i )
*(_BYTE *)(vdevice[64] + i) = 0;
BYTE4(vdevice[65]) = 1;
HIDWORD(vdevice[66]) = 0;
LODWORD(vdevice[66]) = 261;
*(_BYTE *)(vdevice[64] + 32LL) |= 0x20u;
HIBYTE(vdevice[65]) = 0;
BYTE6(vdevice[65]) = 0;
BYTE5(vdevice[65]) = 0;
LODWORD(vdevice[67]) = 0;
BYTE1(vdevice[0]) = 0;
BYTE6(vdevice[0]) = 1;
HIDWORD(vdevice[8]) = 1065353216;
LODWORD(vdevice[65]) = 2;
*(_WORD *)(vdevice[4] + 14LL) = 1;
*(_DWORD *)(vdevice[4] + 8LL) = 0;
*(_BYTE *)(vdevice[4] + 1LL) = 0;
v4 = (_BYTE *)vdevice[4];
*v4 = 0;
if ( !((unsigned int (__fastcall *)(char *, __int64, _BYTE *, _QWORD *))vdevice[33])(v2, a2, v4, vdevice) )
{
fwrite("vogl: error while setting up device\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
LOBYTE(vdevice[0]) = 1;
BYTE2(vdevice[0]) = 0;
BYTE3(vdevice[0]) = 0;
v5 = (unsigned int)(__int16)(WORD2(vdevice[16]) - 1);
viewport(0LL, v5, 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, v5);
font(0LL, 0.0, 0.0);
return setlinestyle(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
char *v2; // rdi
__int64 i; // rax
_BYTE *v4; // rdx
__int64 v5; // rsi
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

v2 = (char *)vdevice[46];
if ( v2 || (v2 = getenv("VDEVICE")) != 0LL )
{
func0(v2);
}
else
{
v2 = (char *)&LC29;
func0((const char *)&LC29);
}
if ( LOBYTE(vdevice[0]) )
func2();
if ( !allocated )
{
allocated = 1;
a2 = 0xFFFFLL;
deflinestyle(0LL, 0xFFFFLL);
v7 = vallocate(72LL);
vdevice[3] = v7;
*(_QWORD *)(v7 + 64) = 0LL;
v8 = vallocate(24LL);
vdevice[4] = v8;
*(_QWORD *)(v8 + 16) = 0LL;
v9 = vallocate(24LL);
vdevice[5] = v9;
*(_QWORD *)(v9 + 16) = 0LL;
vdevice[63] = vallocate(640LL);
v2 = (_BYTE *)(&loc_20 + 2);
vdevice[64] = vallocate(34LL);
}
for ( i = 0LL; i != 34; ++i )
*(_BYTE *)(vdevice[64] + i) = 0;
BYTE4(vdevice[65]) = 1;
HIDWORD(vdevice[66]) = 0;
LODWORD(vdevice[66]) = 261;
*(_BYTE *)(vdevice[64] + 32LL) |= 0x20u;
HIBYTE(vdevice[65]) = 0;
BYTE6(vdevice[65]) = 0;
BYTE5(vdevice[65]) = 0;
LODWORD(vdevice[67]) = 0;
BYTE1(vdevice[0]) = 0;
BYTE6(vdevice[0]) = 1;
HIDWORD(vdevice[8]) = 1065353216;
LODWORD(vdevice[65]) = 2;
*(_WORD *)(vdevice[4] + 14LL) = 1;
*(_DWORD *)(vdevice[4] + 8LL) = 0;
*(_BYTE *)(vdevice[4] + 1LL) = 0;
v4 = (_BYTE *)vdevice[4];
*v4 = 0;
if ( !((unsigned int (__fastcall *)(char *, __int64, _BYTE *, _QWORD *))vdevice[33])(v2, a2, v4, vdevice) )
{
fwrite("vogl: error while setting up device\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
LOBYTE(vdevice[0]) = 1;
BYTE2(vdevice[0]) = 0;
BYTE3(vdevice[0]) = 0;
v5 = (unsigned int)(__int16)(WORD2(vdevice[16]) - 1);
viewport(0LL, v5, 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, v5);
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, double a2, double a3)
{
double v3; // xmm0_8

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

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, double a2, double a3)
{
double v3; // xmm0_8

if ( !LOBYTE(vdevice[0]) )
func3("vnewdev: vogl not initialised\n");
pushviewport();
((void (*)(void))vdevice[28])();
LOBYTE(vdevice[0]) = 0;
func0(a1);
v3 = ((double (*)(void))vdevice[33])();
LOBYTE(vdevice[0]) = 1;
font((unsigned int)*(__int16 *)(vdevice[4] + 8LL), v3, a3);
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 )
strcpy(a1, v1);
else
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 )
strcpy(a1, v1);
else
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])(v3, &v2) == -1 )
return -1LL;
if ( a1 == 1 )
return v3[0];
return v2;
}

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])(v3, &v2) == -1 )
return -1LL;
if ( a1 == 1 )
return v3[0];
return v2;
}

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])(v5, v4);
if ( (v3 & 1) != 0 && a1 == 260 )
{
result = 1LL;
}
else if ( (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])(v5, v4);
if ( (v3 & 1) != 0 && a1 == 260 )
{
result = 1LL;
}
else if ( (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

decompiled_code:
void __fastcall getdev(__int64 a1, __int16 *a2, _WORD *a3)
{
__int16 *v3; // rbx

if ( a1 > 0 )
{
v3 = a2;
do
*a3++ = getvaluator(*v3++);
while ( v3 != &a2[a1] );
}
}

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 v0; // rcx
_DWORD *v1; // rdx
__int64 result; // rax
_DWORD *v3; // rcx

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

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rcx
_DWORD *v1; // rdx
__int64 result; // rax
_DWORD *v3; // rcx

if ( !vdevice )
{
verror("pushviewport: vogl not initialised");
goto LABEL_6;
}
if ( *((_BYTE *)&vdevice + 2) )
{
LABEL_6:
result = newtokens(1LL);
*(_DWORD *)result = 27;
return result;
}
v0 = vsfree;
if ( vsfree )
{
v1 = (_DWORD *)*((_QWORD *)&vdevice + 5);
*((_QWORD *)&vdevice + 5) = vsfree;
vsfree = *(_QWORD *)(v0 + 16);
*(_QWORD *)(v0 + 16) = v1;
**((_DWORD **)&vdevice + 5) = *v1;
*(_DWORD *)(*((_QWORD *)&vdevice + 5) + 4LL) = v1[1];
*(_DWORD *)(*((_QWORD *)&vdevice + 5) + 8LL) = v1[2];
result = *((_QWORD *)&vdevice + 5);
*(_DWORD *)(result + 12) = v1[3];
}
else
{
result = vallocate(24LL);
v3 = (_DWORD *)*((_QWORD *)&vdevice + 5);
*(_QWORD *)(result + 16) = v3;
*(_DWORD *)result = *v3;
*(_DWORD *)(result + 4) = *(_DWORD *)(*((_QWORD *)&vdevice + 5) + 4LL);
*(_DWORD *)(result + 8) = *(_DWORD *)(*((_QWORD *)&vdevice + 5) + 8LL);
*(_DWORD *)(result + 12) = *(_DWORD *)(*((_QWORD *)&vdevice + 5) + 12LL);
*((_QWORD *)&vdevice + 5) = result;
}
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; // rdx
__int64 v1; // rcx
float *v2; // rdx
float v3; // xmm1_4
float v4; // xmm0_4
_DWORD *result; // rax

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

canonical_decompiled_code:
_DWORD *func1()
{
__int64 v0; // rdx
__int64 v1; // rcx
float *v2; // rdx
float v3; // xmm1_4
float v4; // xmm0_4
_DWORD *result; // rax

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

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, float a2, float a3, float a4, float a5, float a6, float a7)
{
__int64 result; // rax

if ( vdevice )
{
rotate((unsigned int)(__int16)-a1, 122LL);
normallookat(a2, (__m128i)LODWORD(a3), a4, a5, a6, a7);
result = translate(
COERCE_DOUBLE(LODWORD(a2) ^ (unsigned __int64)(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, float a2, float a3, float a4, float a5, float a6, float a7)
{
__int64 result; // rax

if ( vdevice )
{
rotate((unsigned int)(__int16)-a1, 122LL);
func0(a2, (__m128i)LODWORD(a3), a4, a5, a6, a7);
result = translate(
COERCE_DOUBLE(LODWORD(a2) ^ (unsigned __int64)(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)
{
bool v5; // zf
bool v6; // zf
float v7; // xmm0_4
int v8; // xmm0_4
int v9; // xmm0_4
float v12; // [rsp+Ch] [rbp-6Ch]
double cosx; // [rsp+10h] [rbp-68h] BYREF
double sinx; // [rsp+18h] [rbp-60h] BYREF
int v15[22]; // [rsp+20h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1, float a2, float a3, float a4)
{
bool v5; // zf
bool v6; // zf
float v7; // xmm0_4
int v8; // xmm0_4
int v9; // xmm0_4
float v12; // [rsp+Ch] [rbp-6Ch]
double cosx; // [rsp+10h] [rbp-68h] BYREF
double sinx; // [rsp+18h] [rbp-60h] BYREF
int v15[22]; // [rsp+20h] [rbp-58h] BYREF

if ( vdevice )
v5 = a2 == 0.0;
else
verror("perspective: vogl not initialised");
if ( v5 )
{
verror("perspective: can't have zero aspect ratio!");
}
else
{
v12 = a4 - a3;
v6 = (float)(a4 - a3) == 0.0;
}
if ( v6 )
{
verror("perspective: near clipping plane same as far one.");
}
else if ( a1 && a1 != 1800 )
{
identmatrix(v15);
v7 = (double)a1 / 10.0;
sincos(v7 * 0.01745329251994328 * 0.5, &sinx, &cosx);
*(float *)&v8 = cosx / sinx;
*(float *)v15 = *(float *)&v8 / a2;
v15[5] = v8;
*(float *)&v15[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a4 + a3) ^ LC1) / v12;
v15[11] = -1082130432;
*(float *)&v9 = a4 * -2.0 * a3 / v12;
v15[14] = v9;
v15[15] = 0;
return loadmatrix(v15);
}
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)
{
bool v6; // zf
bool v7; // zf
bool v8; // zf
double v9; // xmm2_8
float v10; // xmm0_4
int v11; // xmm1_4
int v12; // xmm0_4
__int64 result; // rax
float v19; // [rsp+24h] [rbp-54h]
float v20; // [rsp+28h] [rbp-50h]
float v21; // [rsp+2Ch] [rbp-4Ch]
int v22[18]; // [rsp+30h] [rbp-48h] BYREF

if ( vdevice )
{
v19 = a2 - a1;
v6 = (float)(a2 - a1) == 0.0;
}
else
{
verror("window: vogl not initialised");
}
if ( v6 )
{
verror("window: left clipping plane same as right one.");
}
else
{
v20 = a4 - a3;
v7 = (float)(a4 - a3) == 0.0;
}
if ( v7 )
{
verror("window: bottom clipping plane same as top one.");
}
else
{
v21 = a6 - a5;
v8 = (float)(a6 - a5) == 0.0;
}
if ( v8 )
{
verror("window: near clipping plane same as far one.");
result = ortho();
}
else
{
identmatrix(v22);
v9 = a5;
v10 = (v9 + v9) / v19;
*(float *)v22 = v10;
*(float *)&v11 = (v9 + v9) / v20;
v22[5] = v11;
*(float *)&v22[8] = (float)(a2 + a1) / v19;
*(float *)&v22[9] = (float)(a4 + a3) / v20;
*(float *)&v22[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a5 + a6) ^ LC1) / v21;
v22[11] = -1082130432;
*(float *)&v12 = a6 * -2.0 * a5 / v21;
v22[14] = v12;
v22[15] = 0;
result = loadmatrix(v22);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(float a1, float a2, float a3, float a4, float a5, float a6)
{
bool v6; // zf
bool v7; // zf
bool v8; // zf
double v9; // xmm2_8
float v10; // xmm0_4
int v11; // xmm1_4
int v12; // xmm0_4
__int64 result; // rax
float v19; // [rsp+24h] [rbp-54h]
float v20; // [rsp+28h] [rbp-50h]
float v21; // [rsp+2Ch] [rbp-4Ch]
int v22[18]; // [rsp+30h] [rbp-48h] BYREF

if ( vdevice )
{
v19 = a2 - a1;
v6 = (float)(a2 - a1) == 0.0;
}
else
{
verror("window: vogl not initialised");
}
if ( v6 )
{
verror("window: left clipping plane same as right one.");
}
else
{
v20 = a4 - a3;
v7 = (float)(a4 - a3) == 0.0;
}
if ( v7 )
{
verror("window: bottom clipping plane same as top one.");
}
else
{
v21 = a6 - a5;
v8 = (float)(a6 - a5) == 0.0;
}
if ( v8 )
{
verror("window: near clipping plane same as far one.");
result = func5();
}
else
{
identmatrix(v22);
v9 = a5;
v10 = (v9 + v9) / v19;
*(float *)v22 = v10;
*(float *)&v11 = (v9 + v9) / v20;
v22[5] = v11;
*(float *)&v22[8] = (float)(a2 + a1) / v19;
*(float *)&v22[9] = (float)(a4 + a3) / v20;
*(float *)&v22[10] = COERCE_FLOAT(COERCE_UNSIGNED_INT(a5 + a6) ^ LC1) / v21;
v22[11] = -1082130432;
*(float *)&v12 = a6 * -2.0 * a5 / v21;
v22[14] = v12;
v22[15] = 0;
result = loadmatrix(v22);
}
return result;
}

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