decompiled_code:
__int64 ali_test()
{
int v0; // ebx
unsigned int v1; // ebx

ali_unlock();
_svgalib_port_in(_svgalib_CRT_I);
v0 = GETB(_svgalib_CRT_I, 0x1Au);
_svgalib_port_out(v0 & 0xEF, _svgalib_CRT_D);
if ( cwg() )
{
ali_lock();
v1 = 0;
}
else
{
_svgalib_port_out(v0 | 0x10u, _svgalib_CRT_D);
v1 = cwg();
if ( v1 )
v1 = ali_init(0, 0LL, 0);
else
ali_lock();
}
return v1;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx
unsigned int v1; // ebx

func12();
_svgalib_port_in(_svgalib_CRT_I);
v0 = func8(_svgalib_CRT_I, 0x1Au);
_svgalib_port_out(v0 & 0xEF, _svgalib_CRT_D);
if ( func13() )
{
func11();
v1 = 0;
}
else
{
_svgalib_port_out(v0 | 0x10u, _svgalib_CRT_D);
v1 = func13();
if ( v1 )
v1 = func10(0, 0LL, 0);
else
func11();
}
return v1;
}

original_code:
static int ali_test(void)
{
    int tmp, ov;
    ali_unlock();
    tmp = __svgalib_port_in(__svgalib_CRT_I);
    ov = GETB(__svgalib_CRT_I, 0x1a);
    __svgalib_port_out(ov & 0xef, __svgalib_CRT_D);
    if (cwg()) {
 ali_lock();
 return 0;
    }
    __svgalib_port_out(ov | 0x10, __svgalib_CRT_D);
    if (!cwg()) {
 ali_lock();
 return 0;
    }
    return ali_init(0, 0, 0);
}

canonical_original_code:
static int ali_test()
{
    int tmp; int ov;
    ali_unlock();
    tmp = __svgalib_port_in(__svgalib_CRT_I);
    ov = GETB(__svgalib_CRT_I, 0x1a);
    __svgalib_port_out(ov & 0xef, __svgalib_CRT_D);
    if (cwg()) {
 ali_lock();
 return 0;
    }
    __svgalib_port_out(ov | 0x10, __svgalib_CRT_D);
    if (!cwg()) {
 ali_lock();
 return 0;
    }
    return ali_init(0, 0, 0);
}

variable_types: ov int


decompiled_code:
__int64 __fastcall ali_setregs(unsigned __int8 *a1)
{
int v1; // eax

ali_unlock();
v1 = GETB(0x3CEu, 0xFu);
_svgalib_port_out(v1 | 4u, 975LL);
_svgalib_port_out(0LL, 982LL);
_svgalib_port_out(0LL, 983LL);
SETB(_svgalib_CRT_I, 0x19u, a1[60]);
SETB(_svgalib_CRT_I, 0x1Au, a1[61] | 0x10);
SETB(0x3CEu, 0xBu, a1[64]);
SETB(0x3CEu, 0xCu, a1[65]);
SETB(_svgalib_CRT_I, 0x28u, a1[62]);
SETB(_svgalib_CRT_I, 0x2Au, a1[63]);
_svgalib_port_in(968LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_out(a1[66], 966LL);
_svgalib_port_out(a1[67], 982LL);
return _svgalib_port_out(a1[68], 983LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int8 *a1)
{
int v1; // eax

func12();
v1 = func8(0x3CEu, 0xFu);
_svgalib_port_out(v1 | 4u, 975LL);
_svgalib_port_out(0LL, 982LL);
_svgalib_port_out(0LL, 983LL);
func7(_svgalib_CRT_I, 0x19u, a1[60]);
func7(_svgalib_CRT_I, 0x1Au, a1[61] | 0x10);
func7(0x3CEu, 0xBu, a1[64]);
func7(0x3CEu, 0xCu, a1[65]);
func7(_svgalib_CRT_I, 0x28u, a1[62]);
func7(_svgalib_CRT_I, 0x2Au, a1[63]);
_svgalib_port_in(968LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_out(a1[66], 966LL);
_svgalib_port_out(a1[67], 982LL);
return _svgalib_port_out(a1[68], 983LL);
}

variable_types:
regs
unsigned char []

variable_types: mode int

variable_types: tmp int

return_type: void


decompiled_code:
__int64 __fastcall ali_setmode(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
const __m128i *v3; // rbp
int v4; // edx
__int64 result; // rax
__int128 v6[3]; // [rsp+0h] [rbp-68h] BYREF
__m128i v7; // [rsp+30h] [rbp-38h]
int v8; // [rsp+40h] [rbp-28h]
char v9; // [rsp+44h] [rbp-24h]

v2 = _svgalib_mode_in_table(&ali_modes, a1);
if ( !v2 )
return ((__int64 (__fastcall *)(_QWORD, _QWORD))_svgalib_vga_driverspecs[9])(a1, a2);
v3 = (const __m128i *)v2;
if ( a1 == 3 )
return ((__int64 (__fastcall *)(_QWORD, _QWORD))_svgalib_vga_driverspecs[9])(a1, a2);
v4 = ali_modeavailable(a1);
result = 1LL;
if ( v4 )
{
v6[0] = (__int128)_mm_loadu_si128(v3);
v6[1] = (__int128)_mm_loadu_si128(v3 + 1);
v6[2] = (__int128)_mm_loadu_si128(v3 + 2);
v7 = _mm_loadu_si128(v3 + 3);
v8 = v3[4].m128i_i32[0];
v9 = v3[4].m128i_i8[4];
if ( _svgalib_infotable[5 * a1 + 2] == 16 )
v7.m128i_i8[10] &= 0xF7u;
_svgalib_setregs(v6);
ali_setregs((unsigned __int8 *)v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
const __m128i *v3; // rbp
int v4; // edx
__int64 result; // rax
__int128 v6[3]; // [rsp+0h] [rbp-68h] BYREF
__m128i v7; // [rsp+30h] [rbp-38h]
int v8; // [rsp+40h] [rbp-28h]
char v9; // [rsp+44h] [rbp-24h]

v2 = _svgalib_mode_in_table(&ali_modes, a1);
if ( !v2 )
return ((__int64 (__fastcall *)(_QWORD, _QWORD))_svgalib_vga_driverspecs[9])(a1, a2);
v3 = (const __m128i *)v2;
if ( a1 == 3 )
return ((__int64 (__fastcall *)(_QWORD, _QWORD))_svgalib_vga_driverspecs[9])(a1, a2);
v4 = func4(a1);
result = 1LL;
if ( v4 )
{
v6[0] = (__int128)_mm_loadu_si128(v3);
v6[1] = (__int128)_mm_loadu_si128(v3 + 1);
v6[2] = (__int128)_mm_loadu_si128(v3 + 2);
v7 = _mm_loadu_si128(v3 + 3);
v8 = v3[4].m128i_i32[0];
v9 = v3[4].m128i_i8[4];
if ( _svgalib_infotable[5 * a1 + 2] == 16 )
v7.m128i_i8[10] &= 0xF7u;
_svgalib_setregs(v6);
func15((unsigned __int8 *)v6);
result = 0LL;
}
return result;
}

original_code:
static int ali_setmode(int mode, int prv_mode)
{
    const unsigned char *rp;
    unsigned char regs[sizeof(g640x480x256_regs)];
    rp = __svgalib_mode_in_table(ali_modes, mode);
    if (rp == ((void *)0) || mode == 3)
 return (int) (__svgalib_vga_driverspecs.setmode(mode, prv_mode));
    if (!ali_modeavailable(mode))
 return 1;
    memcpy(regs, rp, sizeof(regs));
    if (__svgalib_infotable[mode].colors == 16) {
 regs[(((0 +24)+21)+9) + 4] &= 0xf7;
    }
    __svgalib_setregs(regs);
    ali_setregs(regs, mode);
    return 0;
}

canonical_original_code:
static int ali_setmode(int mode, int prv_mode)
{
    unsigned char *rp;
    unsigned char regs[-1];
    rp = __svgalib_mode_in_table(ali_modes, mode);
    if (rp == ((void *)0) || mode == 3)
 return (int) (__svgalib_vga_driverspecs.setmode(mode, prv_mode));
    if (!ali_modeavailable(mode))
 return 1;
    memcpy(regs, rp, sizeof(regs));
    if (__svgalib_infotable[mode].colors == 16) {
 regs[(((0 +24)+21)+9) + 4] &= 0xf7;
    }
    __svgalib_setregs(regs);
    ali_setregs(regs, mode);
    return 0;
}

variable_types:
rp
unsigned char *

variable_types:
regs
unsigned char [-1]

return_type: int


decompiled_code:
__int64 __fastcall ali_saveregs(_BYTE *a1)
{
char v1; // r12

ali_unlock();
v1 = GETB(0x3CEu, 0xCu);
a1[67] = _svgalib_port_in(982LL);
a1[68] = _svgalib_port_in(983LL);
_svgalib_port_out(0LL, 982LL);
a1[60] = GETB(_svgalib_CRT_I, 0x19u);
a1[61] = GETB(_svgalib_CRT_I, 0x1Au);
a1[62] = GETB(_svgalib_CRT_I, 0x28u);
a1[63] = GETB(_svgalib_CRT_I, 0x2Au);
a1[64] = GETB(0x3CEu, 0xBu);
a1[65] = v1;
_svgalib_port_in(968LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
a1[66] = _svgalib_port_in(966LL);
return 9LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(_BYTE *a1)
{
char v1; // r12

func12();
v1 = func8(0x3CEu, 0xCu);
a1[67] = _svgalib_port_in(982LL);
a1[68] = _svgalib_port_in(983LL);
_svgalib_port_out(0LL, 982LL);
a1[60] = func8(_svgalib_CRT_I, 0x19u);
a1[61] = func8(_svgalib_CRT_I, 0x1Au);
a1[62] = func8(_svgalib_CRT_I, 0x28u);
a1[63] = func8(_svgalib_CRT_I, 0x2Au);
a1[64] = func8(0x3CEu, 0xBu);
a1[65] = v1;
_svgalib_port_in(968LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
a1[66] = _svgalib_port_in(966LL);
return 9LL;
}


mag

decompiled_code:
double __fastcall mag(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v9; // xmm0_8
double result; // xmm0_8

v9 = a10 * a10 + a9 * a9 + a11 * a11;
if ( v9 < 0.0 )
result = sqrt(v9);
else
result = sqrt(v9);
if ( result == 0.0 )
result = *(double *)&LC1;
return result;
}

canonical_decompiled_code:
double __fastcall func12(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v9; // xmm0_8
double result; // xmm0_8

v9 = a10 * a10 + a9 * a9 + a11 * a11;
if ( v9 < 0.0 )
result = sqrt(v9);
else
result = sqrt(v9);
if ( result == 0.0 )
result = *(double *)&LC1;
return result;
}

original_code:
double mag (Vec v)
{
    double r;
    if ((r = sqrt (v.x * v.x + v.y * v.y + v.z * v.z)) == 0)
 return 1;
    return r;
}

canonical_original_code:
double mag(struct Vec v)
{
    double r;
    if ((r = sqrt (v.x * v.x + v.y * v.y + v.z * v.z)) == 0)
 return 1;
    return r;
}

variable_types:
v
struct Vec { double x; }

variable_types: r double

return_type: double


original_code:
void norm_vec (TD_Surface * surf, int i, int j, Vec * v, int d)
{
    int i1 = 0, i2 = 0, j1 = 0, j2 = 0, w = surf->w;
    double x, y, z, r;
    double x1, y1, z1;
    double x2, y2, z2;
    Vec u;
    switch (d & 3) {
    case 0:
 j1 = -1;
 i2 = -1;
 break;
    case 1:
 i1 = -1;
 j2 = 1;
 break;
    case 2:
 j1 = 1;
 i2 = 1;
 break;
    case 3:
 i1 = 1;
 j2 = -1;
 break;
    }
    x = surf->point[i + j * w].x;
    y = surf->point[i + j * w].y;
    z = surf->point[i + j * w].z;
    x1 = surf->point[i + i1 + (j + j1) * w].x - x;
    y1 = surf->point[i + i1 + (j + j1) * w].y - y;
    z1 = surf->point[i + i1 + (j + j1) * w].z - z;
    x2 = surf->point[i + i2 + (j + j2) * w].x - x;
    y2 = surf->point[i + i2 + (j + j2) * w].y - y;
    z2 = surf->point[i + i2 + (j + j2) * w].z - z;
    u.x = y1 * z2 - z1 * y2;
    u.y = z1 * x2 - x1 * z2;
    u.z = x1 * y2 - y1 * x2;
    r = mag(u);
    v->x += u.x / r;
    v->y += u.y / r;
    v->z += u.z / r;
}

canonical_original_code:
void norm_vec(struct TD_Surface *surf, int i, int j, struct Vec *v, int d)
{
    int i1 = 0; int i2 = 0; int j1 = 0; int j2 = 0; int w = surf->w;
    double x; double y; double z; double r;
    double x1; double y1; double z1;
    double x2; double y2; double z2;
    struct Vec u;
    switch (d & 3) {
    case 0:
 j1 = -1;
 i2 = -1;
 break;
    case 1:
 i1 = -1;
 j2 = 1;
 break;
    case 2:
 j1 = 1;
 i2 = 1;
 break;
    case 3:
 i1 = 1;
 j2 = -1;
 break;
    }
    x = surf->point[i + j * w].x;
    y = surf->point[i + j * w].y;
    z = surf->point[i + j * w].z;
    x1 = surf->point[i + i1 + (j + j1) * w].x - x;
    y1 = surf->point[i + i1 + (j + j1) * w].y - y;
    z1 = surf->point[i + i1 + (j + j1) * w].z - z;
    x2 = surf->point[i + i2 + (j + j2) * w].x - x;
    y2 = surf->point[i + i2 + (j + j2) * w].y - y;
    z2 = surf->point[i + i2 + (j + j2) * w].z - z;
    u.x = y1 * z2 - z1 * y2;
    u.y = z1 * x2 - x1 * z2;
    u.z = x1 * y2 - y1 * x2;
    r = mag(u);
    v->x += u.x / r;
    v->y += u.y / r;
    v->z += u.z / r;
}

variable_types: struct TD_Surface { int w; int l; int bitmapwidth; int bitmaplength; int maxcolor; int shadow; int depth_per_color; int mesh_color; int render; int backfacing; unsigned char *bitmap1; unsigned char *bitmap2; struct TD_Point { int x; int y; int z; int dirx; int diry; int dirz; } *point; } *

variable_types: i int

variable_types: j int

variable_types:
v
struct Vec { double x; } *

variable_types: d int

variable_types: w int

variable_types: x double

variable_types: y double

variable_types: z double

variable_types:
u
struct Vec { double x; }

user_defined_types: struct TD_Surface { int w; int l; int bitmapwidth; int bitmaplength; int maxcolor; int shadow; int depth_per_color; int mesh_color; int render; int backfacing; unsigned char *bitmap1; unsigned char *bitmap2; struct TD_Point *point; }


original_code:
void TD_initcolor (TD_Surface * surf, int n)
{
    int i, j, k, w = surf->w, l = surf->l, m;
    double r, ru;
    int w0, ww;
    int l0, ll;
    Vec v, u;
    if (w > 2) {
 w0 = 1;
 ww = w - 1;
    } else {
 w0 = 0;
 ww = w;
    }
    if (l > 2) {
 l0 = 1;
 ll = l - 1;
    } else {
 l0 = 0;
 ll = l;
    }
    for (j = 0; j < l; j++)
 for (i = 0; i < w; i++) {
     v.x = v.y = v.z = 0;
     u.x = u.y = u.z = 0;
     m = 0;
     if (i == 0) {
  m = 1;
  if (j != 0) {
      norm_vec (surf, i, j, &v, 3);
      norm_vec (surf, w0, j, &u, 3);
  }
  if (j != (l - 1)) {
      norm_vec (surf, i, j, &v, 2);
      norm_vec (surf, w0, j, &u, 2);
  }
     }
     if (i == (w - 1)) {
  m = 1;
  if (j != 0) {
      norm_vec (surf, i, j, &v, 0);
      norm_vec (surf, ww, j, &u, 0);
  }
  if (j != (l - 1)) {
      norm_vec (surf, i, j, &v, 1);
      norm_vec (surf, ww, j, &u, 1);
  }
     }
     if (j == 0) {
  m = 1;
  if (i != 0) {
      norm_vec (surf, i, j, &v, 1);
      norm_vec (surf, i, l0, &u, 1);
  }
  if (i != (w - 1)) {
      norm_vec (surf, i, j, &v, 2);
      norm_vec (surf, i, l0, &u, 2);
  }
     }
     if (j == (l - 1)) {
  m = 1;
  if (i != 0) {
      norm_vec (surf, i, j, &v, 0);
      norm_vec (surf, i, ll, &u, 0);
  }
  if (i != (w - 1)) {
      norm_vec (surf, i, j, &v, 3);
      norm_vec (surf, i, ll, &u, 3);
  }
     }
     if (m) {
  r = mag (v);
  ru = mag (u);
  v.x = (float) 3 * v.x / (2 * r) - u.x / (2 * ru);
  v.y = (float) 3 * v.y / (2 * r) - u.y / (2 * ru);
  v.z = (float) 3 * v.z / (2 * r) - u.z / (2 * ru);
     } else {
  for (k = 0; k < 4; k++)
      norm_vec (surf, i, j, &v, k);
     }
     r = mag (v);
     surf->point[i + j * w].dirx = (double) v.x * n / r;
     surf->point[i + j * w].diry = (double) v.y * n / r;
     surf->point[i + j * w].dirz = (double) v.z * n / r;
 }
}

canonical_original_code:
void TD_initcolor(struct TD_Surface *surf, int n)
{
    int i; int j; int k; int w = surf->w; int l = surf->l; int m;
    double r; double ru;
    int w0; int ww;
    int l0; int ll;
    struct Vec v; struct Vec u;
    if (w > 2) {
 w0 = 1;
 ww = w - 1;
    } else {
 w0 = 0;
 ww = w;
    }
    if (l > 2) {
 l0 = 1;
 ll = l - 1;
    } else {
 l0 = 0;
 ll = l;
    }
    for (j = 0; j < l; j++)
 for (i = 0; i < w; i++) {
     v.x = v.y = v.z = 0;
     u.x = u.y = u.z = 0;
     m = 0;
     if (i == 0) {
  m = 1;
  if (j != 0) {
      norm_vec (surf, i, j, &v, 3);
      norm_vec (surf, w0, j, &u, 3);
  }
  if (j != (l - 1)) {
      norm_vec (surf, i, j, &v, 2);
      norm_vec (surf, w0, j, &u, 2);
  }
     }
     if (i == (w - 1)) {
  m = 1;
  if (j != 0) {
      norm_vec (surf, i, j, &v, 0);
      norm_vec (surf, ww, j, &u, 0);
  }
  if (j != (l - 1)) {
      norm_vec (surf, i, j, &v, 1);
      norm_vec (surf, ww, j, &u, 1);
  }
     }
     if (j == 0) {
  m = 1;
  if (i != 0) {
      norm_vec (surf, i, j, &v, 1);
      norm_vec (surf, i, l0, &u, 1);
  }
  if (i != (w - 1)) {
      norm_vec (surf, i, j, &v, 2);
      norm_vec (surf, i, l0, &u, 2);
  }
     }
     if (j == (l - 1)) {
  m = 1;
  if (i != 0) {
      norm_vec (surf, i, j, &v, 0);
      norm_vec (surf, i, ll, &u, 0);
  }
  if (i != (w - 1)) {
      norm_vec (surf, i, j, &v, 3);
      norm_vec (surf, i, ll, &u, 3);
  }
     }
     if (m) {
  r = mag (v);
  ru = mag (u);
  v.x = (float) 3 * v.x / (2 * r) - u.x / (2 * ru);
  v.y = (float) 3 * v.y / (2 * r) - u.y / (2 * ru);
  v.z = (float) 3 * v.z / (2 * r) - u.z / (2 * ru);
     } else {
  for (k = 0; k < 4; k++)
      norm_vec (surf, i, j, &v, k);
     }
     r = mag (v);
     surf->point[i + j * w].dirx = (double) v.x * n / r;
     surf->point[i + j * w].diry = (double) v.y * n / r;
     surf->point[i + j * w].dirz = (double) v.z * n / r;
 }
}

variable_types: n int

variable_types: k int

variable_types: l int

variable_types: m int

variable_types: ru double

variable_types: ww int

variable_types: ll int

user_defined_types: struct TD_Point { int x; int y; int z; int dirx; int diry; int dirz; }


decompiled_code:
__int64 __fastcall TD_initellipsoidpart(__int64 a1, int a2, int a3, int a4, int a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, int a13, int a14, int a15, int a16)
{
int v16; // eax
__int64 result; // rax
int v18; // er14
unsigned int v19; // xmm5_4
int v20; // ebx
double v21; // xmm0_8
double v22; // xmm1_8
double v23; // xmm0_8
int v24; // er12
double v25; // xmm7_8
double v26; // xmm6_8
float v27; // [rsp+8h] [rbp-80h]
int v32; // [rsp+28h] [rbp-60h]
int v33; // [rsp+2Ch] [rbp-5Ch]
double v34; // [rsp+30h] [rbp-58h] BYREF
double v35; // [rsp+38h] [rbp-50h] BYREF
__int64 v36[9]; // [rsp+40h] [rbp-48h] BYREF

v16 = 2 * a14 + 1;
*(_DWORD *)(a1 + 4) = v16;
*(_DWORD *)a1 = v16;
result = (unsigned int)-a14;
v33 = result;
v32 = -a14;
if ( ((a14 & 0x40000000) != 0) == __OFSUB__(a14, (_DWORD)result) )
{
v18 = 0;
do
{
v27 = (float)a14;
*(_QWORD *)&v26 = COERCE_UNSIGNED_INT64((float)((float)v32 / (float)a14)) ^ LC4;
v24 = v33;
do
{
v34 = (float)((float)v24 / v27);
v25 = (float)((float)v32 / (float)a14);
v35 = v25;
v36[0] = LC1;
switch ( a15 )
{
case 0:
v36[0] = LC2;
fxchg((__int64 *)&v34, (__int64 *)&v35);
break;
case 1:
*(_QWORD *)&v25 = COERCE_UNSIGNED_INT64((float)((float)v32 / (float)a14)) ^ LC4;
v35 = v25;
fxchg((__int64 *)&v34, v36);
break;
case 2:
v26 = *(double *)&LC2;
v36[0] = LC2;
fxchg((__int64 *)&v34, v36);
break;
case 3:
*(_QWORD *)&v25 = COERCE_UNSIGNED_INT64((float)((float)v32 / (float)a14)) ^ LC4;
v35 = v25;
fxchg((__int64 *)&v35, v36);
break;
case 4:
v26 = *(double *)&LC2;
v36[0] = LC2;
fxchg((__int64 *)&v35, v36);
break;
default:
break;
}
*(float *)&v19 = mag((float)((float)v24 / v27), a8, a9, a10, a11, a12, v26, v25, v34, v35, *(double *)v36);
v34 = (float)((float)a5 / *(float *)&v19) * v34;
v35 = (float)((float)a6 / *(float *)&v19) * v35;
*(double *)v36 = (float)((float)a13 / *(float *)&v19) * *(double *)v36;
v20 = v24 + a14;
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL * (v18 + *(_DWORD *)a1 * (v24 + a14))) = (int)(v34 + (double)a2);
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL * (v18 + *(_DWORD *)a1 * (v24 + a14)) + 4) = (int)((double)a3 + v35);
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL * (v18 + *(_DWORD *)a1 * (v24 + a14)) + 8) = (int)((double)a4
+ *(double *)v36);
v34 = v34 / (float)((float)a5 * (float)a5);
a10 = v34;
v35 = v35 / (float)((float)a6 * (float)a6);
v21 = (float)((float)a13 * (float)a13);
*(double *)v36 = *(double *)v36 / v21;
v22 = mag(
v21,
*(double *)v36,
v35,
v34,
(double)a2,
COERCE_DOUBLE((unsigned __int64)v19),
v26,
v25,
v34,
v35,
*(double *)v36);
v23 = (float)a16;
*(float *)&v22 = v22;
a8 = *(float *)&v22;
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL * (v18 + *(_DWORD *)a1 * v20) + 12) = (int)(v23 * v34 / a8);
a9 = v23 * v35 / a8;
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL * (v18 + *(_DWORD *)a1 * v20) + 16) = (int)a9;
*(_DWORD *)(*(_QWORD *)(a1 + 56) + 24LL * (v18 + *(_DWORD *)a1 * v20) + 20) = (int)(v23 * *(double *)v36 / a8);
++v24;
}
while ( a14 >= v24 );
result = (unsigned int)++v32;
++v18;
}
while ( a14 >= v32 );
}
return result;
}

original_code:
void TD_initellipsoidpart (TD_Surface * surf, int x, int y, int z,
        int a, int b, int c, int w, int dir, int col)
{
    int i, j;
    Vec v;
    float r;
    surf->w = surf->l = 2 * w + 1;
    for (i = -w; i <= w; i++)
 for (j = -w; j <= w; j++) {
     v.x = (float) j / w;
     v.y = (float) i / w;
     v.z = 1;
     switch (dir) {
     case 0:
  v.z = -v.z;
  fxchg (&v.x, &v.y);
  break;
     case 1:
  v.y = -v.y;
  fxchg (&v.x, &v.z);
  break;
     case 2:
  v.z = -v.z;
  fxchg (&v.x, &v.z);
  break;
     case 3:
  v.y = -v.y;
  fxchg (&v.y, &v.z);
  break;
     case 4:
  v.z = -v.z;
  fxchg (&v.y, &v.z);
  break;
     }
     r = mag (v);
     v.x *= (float) a / r;
     v.y *= (float) b / r;
     v.z *= (float) c / r;
     surf->point[i + w + (j + w) * surf->w].x = v.x + x;
     surf->point[i + w + (j + w) * surf->w].y = v.y + y;
     surf->point[i + w + (j + w) * surf->w].z = v.z + z;
     v.x /= (float) a * a;
     v.y /= (float) b * b;
     v.z /= (float) c * c;
     r = mag (v);
     surf->point[i + w + (j + w) * surf->w].dirx = (float) col * v.x / r;
     surf->point[i + w + (j + w) * surf->w].diry = (float) col * v.y / r;
     surf->point[i + w + (j + w) * surf->w].dirz = (float) col * v.z / r;
 }
}

canonical_original_code:
void TD_initellipsoidpart(struct TD_Surface *surf, int x, int y, int z, int a, int b, int c, int w, int dir, int col)
{
    int i; int j;
    struct Vec v;
    float r;
    surf->w = surf->l = 2 * w + 1;
    for (i = -w; i <= w; i++)
 for (j = -w; j <= w; j++) {
     v.x = (float) j / w;
     v.y = (float) i / w;
     v.z = 1;
     switch (dir) {
     case 0:
  v.z = -v.z;
  fxchg (&v.x, &v.y);
  break;
     case 1:
  v.y = -v.y;
  fxchg (&v.x, &v.z);
  break;
     case 2:
  v.z = -v.z;
  fxchg (&v.x, &v.z);
  break;
     case 3:
  v.y = -v.y;
  fxchg (&v.y, &v.z);
  break;
     case 4:
  v.z = -v.z;
  fxchg (&v.y, &v.z);
  break;
     }
     r = mag (v);
     v.x *= (float) a / r;
     v.y *= (float) b / r;
     v.z *= (float) c / r;
     surf->point[i + w + (j + w) * surf->w].x = v.x + x;
     surf->point[i + w + (j + w) * surf->w].y = v.y + y;
     surf->point[i + w + (j + w) * surf->w].z = v.z + z;
     v.x /= (float) a * a;
     v.y /= (float) b * b;
     v.z /= (float) c * c;
     r = mag (v);
     surf->point[i + w + (j + w) * surf->w].dirx = (float) col * v.x / r;
     surf->point[i + w + (j + w) * surf->w].diry = (float) col * v.y / r;
     surf->point[i + w + (j + w) * surf->w].dirz = (float) col * v.z / r;
 }
}

variable_types: struct TD_Surface { int w; int l; int bitmapwidth; int bitmaplength; int maxcolor; int shadow; int depth_per_color; int mesh_color; int render; int backfacing; unsigned char *bitmap1; unsigned char *bitmap2; struct TD_Point { int x; int y; int z; int dirx; int diry; int dirz; } *point; } *

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: dir int

variable_types: col int

variable_types:
v
struct Vec { double x; }

variable_types: r float


original_code:
void TD_initellipsoid (TD_Surface * surf1, TD_Surface * surf2, TD_Surface * surf3,
 TD_Surface * surf4, TD_Surface * surf5, TD_Surface * surf6, int x,
 int y, int z, int a, int b, int c, int w, int col)
{
    TD_initellipsoidpart (surf1, x, y, z, a, b, c, w, 0, col);
    TD_initellipsoidpart (surf2, x, y, z, a, b, c, w, 1, col);
    TD_initellipsoidpart (surf3, x, y, z, a, b, c, w, 2, col);
    TD_initellipsoidpart (surf4, x, y, z, a, b, c, w, 3, col);
    TD_initellipsoidpart (surf5, x, y, z, a, b, c, w, 4, col);
    TD_initellipsoidpart (surf6, x, y, z, a, b, c, w, 5, col);
}

canonical_original_code:
void TD_initellipsoid(struct TD_Surface *surf1, struct TD_Surface *surf2, struct TD_Surface *surf3, struct TD_Surface *surf4, struct TD_Surface *surf5, struct TD_Surface *surf6, int x, int y, int z, int a, int b, int c, int w, int col)
{
    TD_initellipsoidpart (surf1, x, y, z, a, b, c, w, 0, col);
    TD_initellipsoidpart (surf2, x, y, z, a, b, c, w, 1, col);
    TD_initellipsoidpart (surf3, x, y, z, a, b, c, w, 2, col);
    TD_initellipsoidpart (surf4, x, y, z, a, b, c, w, 3, col);
    TD_initellipsoidpart (surf5, x, y, z, a, b, c, w, 4, col);
    TD_initellipsoidpart (surf6, x, y, z, a, b, c, w, 5, col);
}

variable_types: w int


original_code:
void TD_initsellipsoid (TD_Solid *s, int n, int x,
 int y, int z, int a, int b, int c, int w, int col)
{
    TD_initellipsoid(&s->surf[n], &s->surf[n+1], &s->surf[n+2],
 &s->surf[n+3], &s->surf[n+4], &s->surf[n+5], x, y, z,
 a, b, c, w, col);
}

canonical_original_code:
void TD_initsellipsoid(struct TD_Solid *s, int n, int x, int y, int z, int a, int b, int c, int w, int col)
{
    TD_initellipsoid(&s->surf[n], &s->surf[n+1], &s->surf[n+2],
 &s->surf[n+3], &s->surf[n+4], &s->surf[n+5], x, y, z,
 a, b, c, w, col);
}

variable_types: struct TD_Solid { int num_surfaces; struct TD_Surface { int w; int l; int bitmapwidth; int bitmaplength; int maxcolor; int shadow; int depth_per_color; int mesh_color; int render; int backfacing; unsigned char *bitmap1; unsigned char *bitmap2; struct TD_Point { int x; int y; int z; int dirx; int diry; int dirz; } *point; } *surf; int a11; int a21; int a31; float alpha; int xlight; int xscale; int yscale; int distance; int x_cam; int y_cam; int z_cam; int s_cam; int posx; int posy; int option_flags; int render; void (*draw_point)(int, int, int); void (*draw_wtriangle)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, struct TD_tridata { unsigned char *bitmap1; unsigned char *bitmap2; int bf; } *); void (*draw_swtriangle)(int, int, int, int, int, int, int, int, int, int, int, int, int, struct TD_tridata *); void (*draw_striangle)(int, int, int, int, int, int, int, int); void (*draw_triangle)(int, int, int, int, int, int, int, int, int, int); void (*draw_line)(int, int, int, int, int); } *

variable_types: n int

user_defined_types: struct TD_Solid { int num_surfaces; struct TD_Surface *surf; int a11; int a21; int a31; float alpha; int xlight; int xscale; int yscale; int distance; int x_cam; int y_cam; int z_cam; int s_cam; int posx; int posy; int option_flags; int render; void (*draw_point)(int, int, int); void (*draw_wtriangle)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, struct TD_tridata *); void (*draw_swtriangle)(int, int, int, int, int, int, int, int, int, int, int, int, int, struct TD_tridata *); void (*draw_striangle)(int, int, int, int, int, int, int, int); void (*draw_triangle)(int, int, int, int, int, int, int, int, int, int); void (*draw_line)(int, int, int, int, int); }


fsqr

decompiled_code:
double __fastcall fsqr(double a1)
{
return a1 * a1;
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return a1 * a1;
}

original_code:
extern inline double fsqr (double x)
{
    return x * x;
}

canonical_original_code:
extern inline double fsqr(double x)
{
    return x * x;
}

variable_types: x double


lsqr

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

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

original_code:
extern inline int lsqr (int x)
{
    return (int) x *x;
}

canonical_original_code:
extern inline int lsqr(int x)
{
    return (int) x *x;
}


fmax

decompiled_code:
double __fastcall fmax(double a1, double a2)
{
return fmax(a1, a2);
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2)
{
return func3(a1, a2);
}

original_code:
extern inline double fmax (double a, double b)
{
    return (((a) > (b)) ? (a) : (b));
}

canonical_original_code:
extern inline double fmax(double a, double b)
{
    return (((a) > (b)) ? (a) : (b));
}

variable_types: a double

variable_types: b double


fmin

decompiled_code:
double __fastcall fmin(double a1, double a2)
{
return fmin(a1, a2);
}

canonical_decompiled_code:
double __fastcall func4(double a1, double a2)
{
return func4(a1, a2);
}

original_code:
extern inline double fmin (double a, double b)
{
    return (((a) < (b)) ? (a) : (b));
}

canonical_original_code:
extern inline double fmin(double a, double b)
{
    return (((a) < (b)) ? (a) : (b));
}


dot

decompiled_code:
double __fastcall dot(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_decompiled_code:
double __fastcall func6(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

original_code:
extern inline double dot (Vec a, Vec b)
{
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

canonical_original_code:
extern inline double dot(struct Vec a, struct Vec b)
{
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

variable_types:
a
struct Vec { double x; }

variable_types:
b
struct Vec


cross

decompiled_code:
double *__fastcall cross(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15)
{
double *result; // rax

result = a1;
*a1 = a11 * a15 - a12 * a14;
a1[1] = a12 * a13 - a15 * a10;
a1[2] = a10 * a14 - a11 * a13;
return result;
}

canonical_decompiled_code:
double *__fastcall func7(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15)
{
double *result; // rax

result = a1;
*a1 = a11 * a15 - a12 * a14;
a1[1] = a12 * a13 - a15 * a10;
a1[2] = a10 * a14 - a11 * a13;
return result;
}

original_code:
extern inline Vec cross (Vec a, Vec b)
{
    Vec c;
    c.x = a.y * b.z - a.z * b.y;
    c.y = a.z * b.x - a.x * b.z;
    c.z = a.x * b.y - a.y * b.x;
    return c;
}

canonical_original_code:
extern inline struct Vec cross(struct Vec a, struct Vec b)
{
    struct Vec c;
    c.x = a.y * b.z - a.z * b.y;
    c.y = a.z * b.x - a.x * b.z;
    c.z = a.x * b.y - a.y * b.x;
    return c;
}

variable_types:
a
struct Vec

variable_types:
c
struct Vec { double x; }

return_type: struct Vec { double x; }


norm

decompiled_code:
double __fastcall norm(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v9; // xmm0_8
double result; // xmm0_8

v9 = a10 * a10 + a9 * a9 + a11 * a11;
if ( v9 < 0.0 )
result = sqrt(v9);
else
result = sqrt(v9);
return result;
}

canonical_decompiled_code:
double __fastcall func11(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v9; // xmm0_8
double result; // xmm0_8

v9 = a10 * a10 + a9 * a9 + a11 * a11;
if ( v9 < 0.0 )
result = sqrt(v9);
else
result = sqrt(v9);
return result;
}

original_code:
extern inline double norm (Vec a)
{
    return sqrt (((a.x)*(a.x)) + ((a.y)*(a.y)) + ((a.z)*(a.z)));
}

canonical_original_code:
extern inline double norm(struct Vec a)
{
    return sqrt (((a.x)*(a.x)) + ((a.y)*(a.y)) + ((a.z)*(a.z)));
}


inb

decompiled_code:
unsigned __int8 __fastcall inb(unsigned __int16 a1)
{
return __inbyte(a1);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func0(unsigned __int16 a1)
{
return __inbyte(a1);
}

original_code:
static __inline unsigned char
inb (unsigned short int __port)
{
  unsigned char _v;
  __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
  return _v;
}

canonical_original_code:
static __inline unsigned char inb(unsigned short __port)
{
  unsigned char _v;
  __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
  return _v;
}

return_type: unsigned char


inw

decompiled_code:
unsigned __int16 __fastcall inw(unsigned __int16 a1)
{
return __inword(a1);
}

canonical_decompiled_code:
unsigned __int16 __fastcall func1(unsigned __int16 a1)
{
return __inword(a1);
}

original_code:
static __inline unsigned short int
inw (unsigned short int __port)
{
  unsigned short _v;
  __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
  return _v;
}

canonical_original_code:
static __inline unsigned short inw(unsigned short __port)
{
  unsigned short _v;
  __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
  return _v;
}

return_type: unsigned short


inl

decompiled_code:
unsigned __int32 __fastcall inl(unsigned __int16 a1)
{
return __indword(a1);
}

canonical_decompiled_code:
unsigned __int32 __fastcall func2(unsigned __int16 a1)
{
return __indword(a1);
}

original_code:
static __inline unsigned int
inl (unsigned short int __port)
{
  unsigned int _v;
  __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
  return _v;
}

canonical_original_code:
static __inline unsigned int inl(unsigned short __port)
{
  unsigned int _v;
  __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
  return _v;
}

return_type: unsigned int


outb

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

result = a1;
__outbyte(a2, a1);
return result;
}

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

result = a1;
__outbyte(a2, a1);
return result;
}

original_code:
static __inline void
outb (unsigned char __value, unsigned short int __port)
{
  __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
}

canonical_original_code:
static __inline void outb(unsigned char __value, unsigned short __port)
{
  __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
}


outw

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

result = a1;
__outword(a2, a1);
return result;
}

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

result = a1;
__outword(a2, a1);
return result;
}

original_code:
static __inline void
outw (unsigned short int __value, unsigned short int __port)
{
  __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
}

canonical_original_code:
static __inline void outw(unsigned short __value, unsigned short __port)
{
  __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
}


outl

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

result = a1;
__outdword(a2, a1);
return result;
}

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

result = a1;
__outdword(a2, a1);
return result;
}

original_code:
static __inline void
outl (unsigned int __value, unsigned short int __port)
{
  __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
}

canonical_original_code:
static __inline void outl(unsigned int __value, unsigned short __port)
{
  __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
}


outsb

decompiled_code:
void __fastcall outsb(unsigned __int16 a1, unsigned __int8 *a2, unsigned int a3)
{
__outbytestring(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func6(unsigned __int16 a1, unsigned __int8 *a2, unsigned int a3)
{
__outbytestring(a1, a2, a3);
}

original_code:
static __inline void
outsb (unsigned short int __port, const void *__addr,
       unsigned long int __count)
{
  __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
   :"d" (__port), "0" (__addr), "1" (__count));
}

canonical_original_code:
static __inline void outsb(unsigned short __port, void *__addr, unsigned long __count)
{
  __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
   :"d" (__port), "0" (__addr), "1" (__count));
}


nothing

decompiled_code:
void nothing()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void nothing(void)
{
}

canonical_original_code:
static void nothing()
{
}


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

if ( !paradise_modes )
{
result = &paradise_modes_512;
paradise_modes = (__int64)&paradise_modes_512;
}
return result;
}

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

if ( !paradise_modes )
{
result = &paradise_modes_512;
paradise_modes = (__int64)&paradise_modes_512;
}
return result;
}

original_code:
static void setup_registers(void)
{
    if (paradise_modes == ((void *)0)) {
     paradise_modes = paradise_modes_512;
    }
}

canonical_original_code:
static void setup_registers()
{
    if (paradise_modes == ((void *)0)) {
     paradise_modes = paradise_modes_512;
    }
}


decompiled_code:
__int64 paradise_lock()
{
_svgalib_port_outw(15LL, 974LL);
_svgalib_port_outw(41LL, 980LL);
return _svgalib_port_outw(6LL, 964LL);
}

canonical_decompiled_code:
__int64 func3()
{
_svgalib_port_outw(15LL, 974LL);
_svgalib_port_outw(41LL, 980LL);
return _svgalib_port_outw(6LL, 964LL);
}

original_code:
static void paradise_lock(void)
{
__svgalib_port_outw(0x000f, 0x3CE);
__svgalib_port_outw(0x0029, 0x3D4);
__svgalib_port_outw(0x0006, 0x3C4);
}

canonical_original_code:
static void paradise_lock()
{
__svgalib_port_outw(0x000f, 0x3CE);
__svgalib_port_outw(0x0029, 0x3D4);
__svgalib_port_outw(0x0006, 0x3C4);
}


outb

decompiled_code:
void outb(unsigned __int8 value, unsigned __int16 port)
{
_svgalib_port_out(port, value);
}

canonical_decompiled_code:
void func4(unsigned __int8 value, unsigned __int16 port)
{
_svgalib_port_out(port, value);
}


decompiled_code:
__int64 paradise_unlock()
{
unsigned __int8 v0; // bl
char v1; // bl
unsigned __int8 v2; // bl

_svgalib_port_outw(1295LL, 974LL);
_svgalib_port_outw(34089LL, 980LL);
_svgalib_port_outw(18438LL, 964LL);
_svgalib_port_out(13LL, 974LL);
v0 = _svgalib_port_in(975LL) & 0x1E;
_svgalib_port_out(13LL, 974LL);
_svgalib_port_out(v0 | 2u, 975LL);
_svgalib_port_out(14LL, 974LL);
v1 = _svgalib_port_in(975LL);
_svgalib_port_out(14LL, 974LL);
_svgalib_port_out(v1 & 0xFB, 975LL);
_svgalib_port_out(42LL, 980LL);
v2 = _svgalib_port_in(981LL);
_svgalib_port_out(42LL, 980LL);
return _svgalib_port_out(v2 & 0xF8, 981LL);
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int8 v0; // bl
char v1; // bl
unsigned __int8 v2; // bl

_svgalib_port_outw(1295LL, 974LL);
_svgalib_port_outw(34089LL, 980LL);
_svgalib_port_outw(18438LL, 964LL);
_svgalib_port_out(13LL, 974LL);
v0 = _svgalib_port_in(975LL) & 0x1E;
_svgalib_port_out(13LL, 974LL);
_svgalib_port_out(v0 | 2u, 975LL);
_svgalib_port_out(14LL, 974LL);
v1 = _svgalib_port_in(975LL);
_svgalib_port_out(14LL, 974LL);
_svgalib_port_out(v1 & 0xFB, 975LL);
_svgalib_port_out(42LL, 980LL);
v2 = _svgalib_port_in(981LL);
_svgalib_port_out(42LL, 980LL);
return _svgalib_port_out(v2 & 0xF8, 981LL);
}

original_code:
static void paradise_unlock(void)
{
unsigned char b;
__svgalib_port_outw(0x050f, 0x3CE);
__svgalib_port_outw(0x8529, 0x3D4);
__svgalib_port_outw(0x4806, 0x3C4);
__svgalib_port_out(0xd, 0x3CE);
b=__svgalib_port_in (0x3CF);
b&=30;
b|=2;
__svgalib_port_out(0xd, 0x3CE);
__svgalib_port_out(b, 0x3CF);
__svgalib_port_out(0xe, 0x3CE);
b=__svgalib_port_in(0x3CF);
b&=251;
__svgalib_port_out(0xe, 0x3CE);
__svgalib_port_out(b, 0x3CF);
__svgalib_port_out(0x2a, 0x3D4);
b=__svgalib_port_in(0x3D5);
b&=248;
__svgalib_port_out(0x2a, 0x3D4);
__svgalib_port_out(b, 0x3D5);
}

canonical_original_code:
static void paradise_unlock()
{
unsigned char b;
__svgalib_port_outw(0x050f, 0x3CE);
__svgalib_port_outw(0x8529, 0x3D4);
__svgalib_port_outw(0x4806, 0x3C4);
__svgalib_port_out(0xd, 0x3CE);
b=__svgalib_port_in (0x3CF);
b&=30;
b|=2;
__svgalib_port_out(0xd, 0x3CE);
__svgalib_port_out(b, 0x3CF);
__svgalib_port_out(0xe, 0x3CE);
b=__svgalib_port_in(0x3CF);
b&=251;
__svgalib_port_out(0xe, 0x3CE);
__svgalib_port_out(b, 0x3CF);
__svgalib_port_out(0x2a, 0x3D4);
b=__svgalib_port_in(0x3D5);
b&=248;
__svgalib_port_out(0x2a, 0x3D4);
__svgalib_port_out(b, 0x3D5);
}

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall paradise_setlogicalwidth(int a1)
{
paradise_unlock();
return _svgalib_port_outw((unsigned int)((a1 >> 3 << 8) + 19), 980LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
func5();
return _svgalib_port_outw((unsigned int)((a1 >> 3 << 8) + 19), 980LL);
}

original_code:
static void paradise_setlogicalwidth(int width)
{
paradise_unlock();
    __svgalib_port_outw(0x13 + (width >> 3) * 256, 0x3D4);
}

variable_types: width int


decompiled_code:
__int64 __fastcall paradise_setdisplaystart(int a1)
{
char v1; // al

paradise_unlock();
_svgalib_port_out(47LL, 980LL);
v1 = _svgalib_port_in(981LL);
return _svgalib_port_out((unsigned __int8)((a1 >> 13) ^ ((a1 >> 13) ^ v1) & 0xE7), 981LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
char v1; // al

func5();
_svgalib_port_out(47LL, 980LL);
v1 = _svgalib_port_in(981LL);
return _svgalib_port_out((unsigned __int8)((a1 >> 13) ^ ((a1 >> 13) ^ v1) & 0xE7), 981LL);
}

original_code:
static void paradise_setdisplaystart(int address)
{unsigned char bits,orig;
paradise_unlock();
__svgalib_port_out(0x2f, 0x3D4);
bits=address>>13;
orig=__svgalib_port_in(0x3D5);
orig^=bits;
orig&=0xe7;
orig^=bits;
__svgalib_port_out(orig, 0x3D5);
}

canonical_original_code:
static void paradise_setdisplaystart(int address)
{unsigned char bits; unsigned char orig;
paradise_unlock();
__svgalib_port_out(0x2f, 0x3D4);
bits=address>>13;
orig=__svgalib_port_in(0x3D5);
orig^=bits;
orig&=0xe7;
orig^=bits;
__svgalib_port_out(orig, 0x3D5);
}

variable_types: address int

variable_types:
bits
unsigned char

variable_types:
orig
unsigned char


decompiled_code:
__int64 __fastcall paradise_setpage(int a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

paradise_unlock();
_svgalib_port_out(17LL, 964LL);
v1 = _svgalib_port_in(965LL);
LOBYTE(v1) = v1 | 0x80;
_svgalib_port_out(v1, 965LL);
_svgalib_port_out(11LL, 974LL);
v2 = _svgalib_port_in(975LL);
LOBYTE(v2) = v2 | 0x80;
_svgalib_port_out(v2, 975LL);
_svgalib_port_out(9LL, 974LL);
_svgalib_port_out((unsigned int)(16 * a1), 975LL);
_svgalib_port_out(10LL, 974LL);
return _svgalib_port_out((unsigned int)(16 * a1), 975LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

func5();
_svgalib_port_out(17LL, 964LL);
v1 = _svgalib_port_in(965LL);
LOBYTE(v1) = v1 | 0x80;
_svgalib_port_out(v1, 965LL);
_svgalib_port_out(11LL, 974LL);
v2 = _svgalib_port_in(975LL);
LOBYTE(v2) = v2 | 0x80;
_svgalib_port_out(v2, 975LL);
_svgalib_port_out(9LL, 974LL);
_svgalib_port_out((unsigned int)(16 * a1), 975LL);
_svgalib_port_out(10LL, 974LL);
return _svgalib_port_out((unsigned int)(16 * a1), 975LL);
}

original_code:
static void paradise_setpage(int page)
{
paradise_unlock();
__svgalib_port_out(0x11, 0x3C4);
__svgalib_port_out(__svgalib_port_in(0x3C5)|0x80, 0x3C5);
__svgalib_port_out(0x0b, 0x3CE);
__svgalib_port_out(__svgalib_port_in(0x3CF)|0x80, 0x3CF);
__svgalib_port_out(0x09, 0x3CE);
__svgalib_port_out(page<<4, 0x3CF);
__svgalib_port_out(0x0a, 0x3CE);
__svgalib_port_out(page<<4, 0x3CF);
}

variable_types: page int


decompiled_code:
__int64 __fastcall paradise_modeavailable(int a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = _svgalib_mode_in_table(paradise_modes, (unsigned int)a1);
if ( !v1 || a1 == 3 )
return _svgalib_vga_driverspecs[10]((unsigned int)a1);
if ( v1 == 1 || a1 <= 0 )
return 0LL;
v2 = vga_lastmodenumber();
result = 0LL;
if ( v2 >= a1 )
result = 2
* (unsigned int)(paradise_memory << 10 >= _svgalib_infotable[5 * a1 + 3] * _svgalib_infotable[5 * a1 + 1]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = _svgalib_mode_in_table(paradise_modes, (unsigned int)a1);
if ( !v1 || a1 == 3 )
return _svgalib_vga_driverspecs[10]((unsigned int)a1);
if ( v1 == 1 || a1 <= 0 )
return 0LL;
v2 = vga_lastmodenumber();
result = 0LL;
if ( v2 >= a1 )
result = 2
* (unsigned int)(paradise_memory << 10 >= _svgalib_infotable[5 * a1 + 3] * _svgalib_infotable[5 * a1 + 1]);
return result;
}

original_code:
static int paradise_modeavailable(int mode)
{
    const unsigned char *regs;
    struct vgainfo *info;
    regs = __svgalib_mode_in_table(paradise_modes, mode);
    if (regs == ((void *)0) || mode == 3)
 return __svgalib_vga_driverspecs.modeavailable(mode);
    if (regs == ((unsigned char *)1) || mode <= 0 || mode > vga_lastmodenumber())
 return 0;
    info = &__svgalib_infotable[mode];
    if (paradise_memory * 1024 < info->ydim * info->xbytes)
 return 0;
    return 2;
}

canonical_original_code:
static int paradise_modeavailable(int mode)
{
    unsigned char *regs;
    struct vgainfo *info;
    regs = __svgalib_mode_in_table(paradise_modes, mode);
    if (regs == ((void *)0) || mode == 3)
 return __svgalib_vga_driverspecs.modeavailable(mode);
    if (regs == ((unsigned char *)1) || mode <= 0 || mode > vga_lastmodenumber())
 return 0;
    info = &__svgalib_infotable[mode];
    if (paradise_memory * 1024 < info->ydim * info->xbytes)
 return 0;
    return 2;
}

variable_types: mode int

variable_types:
regs
unsigned char *

variable_types: struct vgainfo { int xdim; int ydim; int colors; int xbytes; int bytesperpixel; } *


decompiled_code:
__int64 __fastcall paradise_init(int a1, int a2)
{
int v3; // eax

if ( a1 )
{
paradise_memory = a2;
goto LABEL_3;
}
_svgalib_port_out(11LL, 974LL);
v3 = (int)_svgalib_port_in(975LL) >> 6;
if ( v3 == 2 )
{
paradise_memory = 512;
}
else
{
if ( v3 > 2 )
{
if ( v3 == 3 )
{
paradise_memory = 1024;
goto LABEL_3;
}
}
else if ( (unsigned int)v3 <= 1 )
{
paradise_memory = 256;
goto LABEL_3;
}
paradise_memory = v3;
}
LABEL_3:
if ( _svgalib_driver_report )
fprintf(stderr, "Using WD90C31 Paradise driver (%dK non-interlaced).\n", (unsigned int)paradise_memory);
_svgalib_driverspecs = _svgalib_paradise_driverspecs;
setup_registers();
_svgalib_banked_mem_base = 655360LL;
_svgalib_banked_mem_size = 0x10000LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v3; // eax

if ( a1 )
{
paradise_memory = a2;
goto LABEL_3;
}
_svgalib_port_out(11LL, 974LL);
v3 = (int)_svgalib_port_in(975LL) >> 6;
if ( v3 == 2 )
{
paradise_memory = 512;
}
else
{
if ( v3 > 2 )
{
if ( v3 == 3 )
{
paradise_memory = 1024;
goto LABEL_3;
}
}
else if ( (unsigned int)v3 <= 1 )
{
paradise_memory = 256;
goto LABEL_3;
}
paradise_memory = v3;
}
LABEL_3:
if ( _svgalib_driver_report )
fprintf(stderr, "Using WD90C31 Paradise driver (%dK non-interlaced).\n", (unsigned int)paradise_memory);
_svgalib_driverspecs = _svgalib_paradise_driverspecs;
func2();
_svgalib_banked_mem_base = 655360LL;
_svgalib_banked_mem_size = 0x10000LL;
return 0LL;
}

original_code:
static int paradise_init(int force, int par1, int par2)
{
    if (force) {
 paradise_memory = par1;
    } else {
 __svgalib_port_out(0x0b, 0x3CE);
 paradise_memory=(__svgalib_port_in(0x3CF)>>6);
 switch (paradise_memory)
  {
  case 0:
  case 1:
  paradise_memory=256;
  break;
  case 2:
  paradise_memory=512;
  break;
  case 3:
  paradise_memory=1024;
  break;
  }
    }
    if (__svgalib_driver_report) {
 fprintf(stderr,"Using WD90C31 Paradise driver (%dK non-interlaced).\n",
        paradise_memory);
    }
    __svgalib_driverspecs = &__svgalib_paradise_driverspecs;
    setup_registers();
    __svgalib_banked_mem_base=0xa0000;
    __svgalib_banked_mem_size=0x10000;
    return 0;
}

variable_types: force int


decompiled_code:
_BOOL8 paradise_test()
{
unsigned __int8 v0; // r12
char *v1; // rbx
bool v2; // zf
_BOOL4 v3; // ebx
int v4; // eax
int v5; // eax
char v7[5]; // [rsp+Ah] [rbp-2Eh] BYREF
char v8; // [rsp+Fh] [rbp-29h] BYREF

v8 = 0;
v0 = _svgalib_port_in(980LL);
v1 = v7;
do
{
_svgalib_port_out(49 - (unsigned int)v7 + (unsigned int)v1, 980LL);
*v1++ = _svgalib_port_in(981LL);
}
while ( v1 != &v8 );
v2 = strcmp(v7, "WD90C") == 0;
v3 = !v2;
if ( v2 )
{
_svgalib_port_out(54LL, 980LL);
v4 = _svgalib_port_in(981LL);
if ( v4 == 50 )
{
_svgalib_port_out(55LL, 980LL);
if ( (_svgalib_port_in(981LL) & 0xFFFFFFFD) == 52 )
goto LABEL_14;
}
else if ( v4 == 51 )
{
_svgalib_port_out(55LL, 980LL);
_svgalib_port_out(55LL, 980LL);
v5 = _svgalib_port_in(981LL);
if ( v5 > 49 )
{
if ( v5 == 51 )
{
LABEL_14:
paradise_init(0, 0);
return 1;
}
}
else if ( v5 > 47 )
{
goto LABEL_14;
}
}
}
else
{
_svgalib_port_out(v0, 980LL);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
_BOOL8 func11()
{
unsigned __int8 v0; // r12
char *v1; // rbx
bool v2; // zf
_BOOL4 v3; // ebx
int v4; // eax
int v5; // eax
char v7[5]; // [rsp+Ah] [rbp-2Eh] BYREF
char v8; // [rsp+Fh] [rbp-29h] BYREF

v8 = 0;
v0 = _svgalib_port_in(980LL);
v1 = v7;
do
{
_svgalib_port_out(49 - (unsigned int)v7 + (unsigned int)v1, 980LL);
*v1++ = _svgalib_port_in(981LL);
}
while ( v1 != &v8 );
v2 = strcmp(v7, "WD90C") == 0;
v3 = !v2;
if ( v2 )
{
_svgalib_port_out(54LL, 980LL);
v4 = _svgalib_port_in(981LL);
if ( v4 == 50 )
{
_svgalib_port_out(55LL, 980LL);
if ( (_svgalib_port_in(981LL) & 0xFFFFFFFD) == 52 )
goto LABEL_14;
}
else if ( v4 == 51 )
{
_svgalib_port_out(55LL, 980LL);
_svgalib_port_out(55LL, 980LL);
v5 = _svgalib_port_in(981LL);
if ( v5 > 49 )
{
if ( v5 == 51 )
{
LABEL_14:
func10(0, 0);
return 1;
}
}
else if ( v5 > 47 )
{
goto LABEL_14;
}
}
}
else
{
_svgalib_port_out(v0, 980LL);
v3 = 0;
}
return v3;
}

original_code:
static int paradise_test(void)
{
    int a;
    unsigned char old_value;
    unsigned char txt[6];
    txt[5]=0;
    old_value=__svgalib_port_in(0x3D4);
    for (a=0;a<5;a++)
     {
     __svgalib_port_out(0x31+a, 0x3D4);
     txt[a]=__svgalib_port_in(0x3D5);
     }
    if (strcmp((char *)txt,"WD90C"))
    {
 __svgalib_port_out(old_value, 0x3D4);
 return 0;
    }
    __svgalib_port_out(0x36, 0x3D4);
    switch (__svgalib_port_in(0x3D5))
    {
    case 0x32:
    __svgalib_port_out(0x37, 0x3D4);
    switch (__svgalib_port_in(0x3D5))
     {
     case 0x34:
     case 0x36:
     break;
     default:
     return 0;
     }
    break;
    case 0x33:
    __svgalib_port_out(0x37, 0x3D4);
    __svgalib_port_out(0x37, 0x3D4);
    switch (__svgalib_port_in(0x3D5))
     {
     case 0x30:
     case 0x31:
     case 0x33:
     break;
     default:
     return 0;
     }
    break;
    default:
    return 0;
    }
    paradise_init(0, 0, 0);
    return 1;
}

canonical_original_code:
static int paradise_test()
{
    int a;
    unsigned char old_value;
    unsigned char txt[6];
    txt[5]=0;
    old_value=__svgalib_port_in(0x3D4);
    for (a=0;a<5;a++)
     {
     __svgalib_port_out(0x31+a, 0x3D4);
     txt[a]=__svgalib_port_in(0x3D5);
     }
    if (strcmp((char *)txt,"WD90C"))
    {
 __svgalib_port_out(old_value, 0x3D4);
 return 0;
    }
    __svgalib_port_out(0x36, 0x3D4);
    switch (__svgalib_port_in(0x3D5))
    {
    case 0x32:
    __svgalib_port_out(0x37, 0x3D4);
    switch (__svgalib_port_in(0x3D5))
     {
     case 0x34:
     case 0x36:
     break;
     default:
     return 0;
     }
    break;
    case 0x33:
    __svgalib_port_out(0x37, 0x3D4);
    __svgalib_port_out(0x37, 0x3D4);
    switch (__svgalib_port_in(0x3D5))
     {
     case 0x30:
     case 0x31:
     case 0x33:
     break;
     default:
     return 0;
     }
    break;
    default:
    return 0;
    }
    paradise_init(0, 0, 0);
    return 1;
}

variable_types: a int

variable_types:
txt
unsigned char [6]


decompiled_code:
void __fastcall paradise_setregs(__int64 a1)
{
int v1; // eax
int v2; // ebp
int i; // ebx
int j; // ebp
int v5; // ebx
int v6; // ebp
int v7; // er12

paradise_unlock();
v1 = 0;
v2 = 3;
while ( 2 )
{
for ( i = v1; ; ++i )
{
outb(0xC4u, v2);
outb(0xC5u, *(unsigned __int8 *)(a1 + (unsigned int)(i + 60)));
v1 = i + 1;
if ( v2 == 3 )
{
v2 = 6;
continue;
}
if ( v2 == 7 )
{
v2 = 16;
continue;
}
if ( v2 != 18 )
break;
v2 = 20;
}
if ( (unsigned int)++v2 <= 0x15 )
continue;
break;
}
for ( j = 9; j != 16; ++j )
{
outb(0xCEu, j);
outb(0xCFu, *(unsigned __int8 *)(a1 + (unsigned int)(i + 52 + j)));
}
v5 = i + 8;
v6 = 41;
while ( 2 )
{
v7 = v5;
while ( 2 )
{
outb(0xD4u, v6);
outb(0xD5u, *(unsigned __int8 *)(a1 + (unsigned int)(v7 + 60)));
v5 = v7 + 1;
switch ( v6 )
{
case '0':
v6 = 50;
LABEL_17:
++v7;
continue;
case '2':
v6 = 52;
goto LABEL_17;
case '4':
v6 = 62;
goto LABEL_17;
}
}
if ( (unsigned int)++v6 <= 0x3E )
continue;
break;
}
outb(0xD4u, 0x18u);
outb(0xD5u, *(unsigned __int8 *)(a1 + (unsigned int)(v7 + 62)));
outb(0xDAu, 0x100u);
outb(0xC0u, 0x20u);
_svgalib_delay();
outb(0xC0u, *(unsigned __int8 *)(a1 + (unsigned int)(v7 + 63)));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
int v1; // eax
int v2; // ebp
int i; // ebx
int j; // ebp
int v5; // ebx
int v6; // ebp
int v7; // er12

func5();
v1 = 0;
v2 = 3;
while ( 2 )
{
for ( i = v1; ; ++i )
{
func4(0xC4u, v2);
func4(0xC5u, *(unsigned __int8 *)(a1 + (unsigned int)(i + 60)));
v1 = i + 1;
if ( v2 == 3 )
{
v2 = 6;
continue;
}
if ( v2 == 7 )
{
v2 = 16;
continue;
}
if ( v2 != 18 )
break;
v2 = 20;
}
if ( (unsigned int)++v2 <= 0x15 )
continue;
break;
}
for ( j = 9; j != 16; ++j )
{
func4(0xCEu, j);
func4(0xCFu, *(unsigned __int8 *)(a1 + (unsigned int)(i + 52 + j)));
}
v5 = i + 8;
v6 = 41;
while ( 2 )
{
v7 = v5;
while ( 2 )
{
func4(0xD4u, v6);
func4(0xD5u, *(unsigned __int8 *)(a1 + (unsigned int)(v7 + 60)));
v5 = v7 + 1;
switch ( v6 )
{
case '0':
v6 = 50;
LABEL_17:
++v7;
continue;
case '2':
v6 = 52;
goto LABEL_17;
case '4':
v6 = 62;
goto LABEL_17;
}
}
if ( (unsigned int)++v6 <= 0x3E )
continue;
break;
}
func4(0xD4u, 0x18u);
func4(0xD5u, *(unsigned __int8 *)(a1 + (unsigned int)(v7 + 62)));
func4(0xDAu, 0x100u);
func4(0xC0u, 0x20u);
_svgalib_delay();
func4(0xC0u, *(unsigned __int8 *)(a1 + (unsigned int)(v7 + 63)));
}

variable_types:
regs
unsigned char []

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall paradise_setmode(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbp
int v4; // edx
__int64 result; // rax

v2 = _svgalib_mode_in_table(paradise_modes, a1);
if ( !v2 )
return ((__int64 (__fastcall *)(_QWORD, _QWORD))_svgalib_vga_driverspecs[9])(a1, a2);
v3 = v2;
v4 = paradise_modeavailable(a1);
result = 1LL;
if ( v4 )
{
paradise_unlock();
_svgalib_setregs(v3);
paradise_setregs(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbp
int v4; // edx
__int64 result; // rax

v2 = _svgalib_mode_in_table(paradise_modes, a1);
if ( !v2 )
return ((__int64 (__fastcall *)(_QWORD, _QWORD))_svgalib_vga_driverspecs[9])(a1, a2);
v3 = v2;
v4 = func9(a1);
result = 1LL;
if ( v4 )
{
func5();
_svgalib_setregs(v3);
func12(v3);
result = 0LL;
}
return result;
}

original_code:
static int paradise_setmode(int mode, int prv_mode)
{
    const unsigned char *regs;
    regs = __svgalib_mode_in_table(paradise_modes, mode);
    if (regs == ((void *)0))
 return (int) (__svgalib_vga_driverspecs.setmode(mode, prv_mode));
    if (!paradise_modeavailable(mode))
 return 1;
    paradise_unlock();
    __svgalib_setregs(regs);
    paradise_setregs(regs, mode);
    return 0;
}

canonical_original_code:
static int paradise_setmode(int mode, int prv_mode)
{
    unsigned char *regs;
    regs = __svgalib_mode_in_table(paradise_modes, mode);
    if (regs == ((void *)0))
 return (int) (__svgalib_vga_driverspecs.setmode(mode, prv_mode));
    if (!paradise_modeavailable(mode))
 return 1;
    paradise_unlock();
    __svgalib_setregs(regs);
    paradise_setregs(regs, mode);
    return 0;
}


decompiled_code:
__int64 __fastcall paradise_saveregs(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
int i; // ebx
unsigned int j; // ebp
int v5; // ebx
unsigned int v6; // ebp
int v7; // er12

paradise_unlock();
v1 = 0;
v2 = 3;
while ( 2 )
{
for ( i = v1; ; ++i )
{
_svgalib_port_out(v2, 964LL);
*(_BYTE *)(a1 + (unsigned int)(i + 60)) = _svgalib_port_in(965LL);
v1 = i + 1;
if ( v2 == 3 )
{
v2 = 6;
continue;
}
if ( v2 == 7 )
{
v2 = 16;
continue;
}
if ( v2 != 18 )
break;
v2 = 20;
}
if ( ++v2 <= 0x15 )
continue;
break;
}
for ( j = 9; j != 16; ++j )
{
_svgalib_port_out(j, 974LL);
*(_BYTE *)(a1 + i + 52 + j) = _svgalib_port_in(975LL);
}
v5 = i + 8;
v6 = 41;
while ( 2 )
{
v7 = v5;
while ( 2 )
{
_svgalib_port_out(v6, 980LL);
*(_BYTE *)(a1 + (unsigned int)(v7 + 60)) = _svgalib_port_in(981LL);
v5 = v7 + 1;
switch ( v6 )
{
case '0':
v6 = 50;
LABEL_17:
++v7;
continue;
case '2':
v6 = 52;
goto LABEL_17;
case '4':
v6 = 62;
goto LABEL_17;
}
}
if ( ++v6 <= 0x3E )
continue;
break;
}
_svgalib_port_out(24LL, 980LL);
*(_BYTE *)(a1 + (unsigned int)(v7 + 62)) = _svgalib_port_in(981LL);
_svgalib_port_out(32LL, 960LL);
_svgalib_delay();
*(_BYTE *)(a1 + (unsigned int)(v7 + 63)) = _svgalib_port_in(960LL);
return 28LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp
int i; // ebx
unsigned int j; // ebp
int v5; // ebx
unsigned int v6; // ebp
int v7; // er12

func5();
v1 = 0;
v2 = 3;
while ( 2 )
{
for ( i = v1; ; ++i )
{
_svgalib_port_out(v2, 964LL);
*(_BYTE *)(a1 + (unsigned int)(i + 60)) = _svgalib_port_in(965LL);
v1 = i + 1;
if ( v2 == 3 )
{
v2 = 6;
continue;
}
if ( v2 == 7 )
{
v2 = 16;
continue;
}
if ( v2 != 18 )
break;
v2 = 20;
}
if ( ++v2 <= 0x15 )
continue;
break;
}
for ( j = 9; j != 16; ++j )
{
_svgalib_port_out(j, 974LL);
*(_BYTE *)(a1 + i + 52 + j) = _svgalib_port_in(975LL);
}
v5 = i + 8;
v6 = 41;
while ( 2 )
{
v7 = v5;
while ( 2 )
{
_svgalib_port_out(v6, 980LL);
*(_BYTE *)(a1 + (unsigned int)(v7 + 60)) = _svgalib_port_in(981LL);
v5 = v7 + 1;
switch ( v6 )
{
case '0':
v6 = 50;
LABEL_17:
++v7;
continue;
case '2':
v6 = 52;
goto LABEL_17;
case '4':
v6 = 62;
goto LABEL_17;
}
}
if ( ++v6 <= 0x3E )
continue;
break;
}
_svgalib_port_out(24LL, 980LL);
*(_BYTE *)(a1 + (unsigned int)(v7 + 62)) = _svgalib_port_in(981LL);
_svgalib_port_out(32LL, 960LL);
_svgalib_delay();
*(_BYTE *)(a1 + (unsigned int)(v7 + 63)) = _svgalib_port_in(960LL);
return 28LL;
}


decompiled_code:
void GENDAC_init()
{
;
}

original_code:
static void GENDAC_init(void)
{
}

canonical_original_code:
static void GENDAC_init()
{
}


decompiled_code:
__int64 __fastcall GENDAC_match_programmable_clock(int a1)
{
__int64 result; // rax
int v2; // [rsp+4h] [rbp-Ch] BYREF
int v3; // [rsp+8h] [rbp-8h] BYREF
int v4; // [rsp+Ch] [rbp-4h] BYREF

result = S3dacsFindClock(a1, 0, 100000, 250000, &v4, &v3, &v2);
if ( (_DWORD)result )
result = (unsigned int)(int)((float)((float)((float)v4 / (float)v3) / (float)(1 << v2)) * 14.31818 * 1000.0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax
int v2; // [rsp+4h] [rbp-Ch] BYREF
int v3; // [rsp+8h] [rbp-8h] BYREF
int v4; // [rsp+Ch] [rbp-4h] BYREF

result = func1(a1, 0, 100000, 250000, &v4, &v3, &v2);
if ( (_DWORD)result )
result = (unsigned int)(int)((float)((float)((float)v4 / (float)v3) / (float)(1 << v2)) * 14.31818 * 1000.0);
return result;
}

original_code:
static int GENDAC_match_programmable_clock(int desiredclock)
{
    int min_m, min_n1, n2;
    if (!S3dacsFindClock(desiredclock, 0, 100000, 250000, &min_m, &min_n1, &n2))
 return 0;
    return ((float) (min_m) / (float) (min_n1) / (1 << n2)) * 14.31818 * 1000;
}

canonical_original_code:
static int GENDAC_match_programmable_clock(int desiredclock)
{
    int min_m; int min_n1; int n2;
    if (!S3dacsFindClock(desiredclock, 0, 100000, 250000, &min_m, &min_n1, &n2))
 return 0;
    return ((float) (min_m) / (float) (min_n1) / (1 << n2)) * 14.31818 * 1000;
}

variable_types: desiredclock int


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

if ( a1 == 16 )
return 2 * a2;
if ( a1 == 24 )
return 3 * a2;
result = 4 * a2;
if ( a1 != 32 )
result = a2;
return result;
}

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

if ( a1 == 16 )
return 2 * a2;
if ( a1 == 24 )
return 3 * a2;
result = 4 * a2;
if ( a1 != 32 )
result = a2;
return result;
}

original_code:
static int GENDAC_map_clock(int bpp, int pixelclock)
{
    if (bpp == 16)
 return pixelclock * 2;
    if (bpp == 24)
 return pixelclock * 3;
    if (bpp == 32)
 return pixelclock * 4;
    return pixelclock;
}

variable_types: bpp int

variable_types: pixelclock int


decompiled_code:
__int64 __fastcall GENDAC_map_horizontal_crtc(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // edx

result = a3;
if ( a1 == 24 )
return 3 * a3;
v4 = 2 * a3;
if ( a1 == 16 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // edx

result = a3;
if ( a1 == 24 )
return 3 * a3;
v4 = 2 * a3;
if ( a1 == 16 )
result = v4;
return result;
}

original_code:
static int GENDAC_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
{
    if (bpp == 24)
 return htiming * 3;
    if (bpp == 16)
 return htiming * 2;
    return htiming;
}

variable_types: htiming int


decompiled_code:
int __fastcall GENDAC_initialize_clock_state(__int64 a1, int a2)
{
int result; // eax
int v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !(unsigned int)S3dacsFindClock(a2, 0, 100000, 250000, v5, &v4, &v3) )
return fprintf(stderr, "Bad dot clock %0.3f MHz.\n", (double)a2 / 1000.0);
result = (32 * v3) | (v4 - 2);
*(_BYTE *)(a1 + 3) = LOBYTE(v5[0]) - 2;
*(_BYTE *)(a1 + 4) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
int result; // eax
int v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !(unsigned int)func1(a2, 0, 100000, 250000, v5, &v4, &v3) )
return fprintf(stderr, "Bad dot clock %0.3f MHz.\n", (double)a2 / 1000.0);
result = (32 * v3) | (v4 - 2);
*(_BYTE *)(a1 + 3) = LOBYTE(v5[0]) - 2;
*(_BYTE *)(a1 + 4) = result;
return result;
}

original_code:
static void GENDAC_initialize_clock_state(unsigned char *regs, int freq)
{
    int min_m, min_n1, n2;
    int n, m;
    if (!S3dacsFindClock(freq, 0, 100000, 250000, &min_m, &min_n1, &n2)) {
 fprintf(stderr,"Bad dot clock %0.3f MHz.\n", freq / 1000.0);
 return;
    }
    n = (min_n1 - 2) | (n2 << 5);
    m = min_m - 2;
    regs[3] = m;
    regs[4] = n;
}

canonical_original_code:
static void GENDAC_initialize_clock_state(unsigned char *regs, int freq)
{
    int min_m; int min_n1; int n2;
    int n; int m;
    if (!S3dacsFindClock(freq, 0, 100000, 250000, &min_m, &min_n1, &n2)) {
 fprintf(stderr,"Bad dot clock %0.3f MHz.\n", freq / 1000.0);
 return;
    }
    n = (min_n1 - 2) | (n2 << 5);
    m = min_m - 2;
    regs[3] = m;
    regs[4] = n;
}

variable_types: freq int

variable_types: n int

variable_types: m int


decompiled_code:
__int64 __fastcall GENDAC_restorestate(unsigned __int8 *a1)
{
unsigned __int8 v1; // bp

v1 = _svgalib_inseq(28LL);
_svgalib_outseq(28LL, v1 | 0x80u);
_svgalib_port_out(*a1, 966LL);
_svgalib_port_out(2LL, 968LL);
_svgalib_port_out(a1[3], 969LL);
_svgalib_port_out(a1[4], 969LL);
_svgalib_port_out(14LL, 968LL);
_svgalib_port_out(a1[5], 969LL);
_svgalib_port_out(a1[1], 968LL);
_svgalib_port_out(a1[2], 967LL);
return _svgalib_outseq(28LL, v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
unsigned __int8 v1; // bp

v1 = _svgalib_inseq(28LL);
_svgalib_outseq(28LL, v1 | 0x80u);
_svgalib_port_out(*a1, 966LL);
_svgalib_port_out(2LL, 968LL);
_svgalib_port_out(a1[3], 969LL);
_svgalib_port_out(a1[4], 969LL);
_svgalib_port_out(14LL, 968LL);
_svgalib_port_out(a1[5], 969LL);
_svgalib_port_out(a1[1], 968LL);
_svgalib_port_out(a1[2], 967LL);
return _svgalib_outseq(28LL, v1);
}

original_code:
static void GENDAC_restorestate(const unsigned char *regs)
{
    unsigned char tmp;
    tmp = __svgalib_inseq(0x1c);
    __svgalib_outseq(0x1c, tmp | 0x80);
    __svgalib_port_out(regs[0], 0x3c6);
    __svgalib_port_out(2, 0x3c8);
    __svgalib_port_out(regs[3], 0x3c9);
    __svgalib_port_out(regs[4], 0x3c9);
    __svgalib_port_out(0x0e, 0x3c8);
    __svgalib_port_out(regs[5], 0x3c9);
    __svgalib_port_out(regs[1], 0x3c8);
    __svgalib_port_out(regs[2], 0x3c7);
    __svgalib_outseq(0x1c, tmp);
}

canonical_original_code:
static void GENDAC_restorestate(unsigned char *regs)
{
    unsigned char tmp;
    tmp = __svgalib_inseq(0x1c);
    __svgalib_outseq(0x1c, tmp | 0x80);
    __svgalib_port_out(regs[0], 0x3c6);
    __svgalib_port_out(2, 0x3c8);
    __svgalib_port_out(regs[3], 0x3c9);
    __svgalib_port_out(regs[4], 0x3c9);
    __svgalib_port_out(0x0e, 0x3c8);
    __svgalib_port_out(regs[5], 0x3c9);
    __svgalib_port_out(regs[1], 0x3c8);
    __svgalib_port_out(regs[2], 0x3c7);
    __svgalib_outseq(0x1c, tmp);
}

variable_types:
tmp
unsigned char


decompiled_code:
__int64 __fastcall GENDAC_savestate(_BYTE *a1)
{
unsigned __int8 v1; // bp

v1 = _svgalib_inseq(28LL);
_svgalib_outseq(28LL, v1 | 0x80u);
*a1 = _svgalib_port_in(966LL);
a1[1] = _svgalib_port_in(968LL);
a1[2] = _svgalib_port_in(967LL);
_svgalib_port_out(2LL, 967LL);
a1[3] = _svgalib_port_in(969LL);
a1[4] = _svgalib_port_in(969LL);
_svgalib_port_out(14LL, 967LL);
a1[5] = _svgalib_port_in(969LL);
return _svgalib_outseq(28LL, v1 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1)
{
unsigned __int8 v1; // bp

v1 = _svgalib_inseq(28LL);
_svgalib_outseq(28LL, v1 | 0x80u);
*a1 = _svgalib_port_in(966LL);
a1[1] = _svgalib_port_in(968LL);
a1[2] = _svgalib_port_in(967LL);
_svgalib_port_out(2LL, 967LL);
a1[3] = _svgalib_port_in(969LL);
a1[4] = _svgalib_port_in(969LL);
_svgalib_port_out(14LL, 967LL);
a1[5] = _svgalib_port_in(969LL);
return _svgalib_outseq(28LL, v1 & 0x7F);
}

original_code:
static void GENDAC_savestate(unsigned char *regs)
{
    unsigned char tmp;
    tmp = __svgalib_inseq(0x1c);
    __svgalib_outseq(0x1c, tmp | 0x80);
    regs[0] = __svgalib_port_in(0x3c6);
    regs[1] = __svgalib_port_in(0x3c8);
    regs[2] = __svgalib_port_in(0x3c7);
    __svgalib_port_out(2, 0x3c7);
    regs[3] = __svgalib_port_in(0x3c9);
    regs[4] = __svgalib_port_in(0x3c9);
    __svgalib_port_out(0x0e, 0x3c7);
    regs[5] = __svgalib_port_in(0x3c9);
    __svgalib_outseq(0x1c, tmp & ~0x80);
}


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

result = a2;
if ( a1 == 16 )
result = 2 * a2;
return result;
}

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

result = a2;
if ( a1 == 16 )
result = 2 * a2;
return result;
}

original_code:
static int Sierra_32K_map_clock(int bpp, int pixelclock)
{
    if (bpp == 16)
 return pixelclock * 2;
    return pixelclock;
}


decompiled_code:
__int64 __fastcall Sierra_32K_map_horizontal_crtc(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // edx

result = a3;
v4 = 2 * a3;
if ( a1 == 16 )
result = v4;
return result;
}

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

result = a3;
v4 = 2 * a3;
if ( a1 == 16 )
result = v4;
return result;
}

original_code:
static int Sierra_32K_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
{
    if (bpp == 16)
 return htiming * 2;
    return htiming;
}


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

result = a2;
if ( a1 == 32 )
result = 2 * a2;
return result;
}

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

result = a2;
if ( a1 == 32 )
result = 2 * a2;
return result;
}

original_code:
static int SC15025_map_clock(int bpp, int pixelclock)
{
    if (bpp == 32)
 return pixelclock * 2;
    return pixelclock;
}


decompiled_code:
__int64 __fastcall SC15025_map_horizontal_crtc(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // edx

result = a3;
if ( a1 == 16 )
return 2 * a3;
v4 = 4 * a3;
if ( a1 == 32 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // edx

result = a3;
if ( a1 == 16 )
return 2 * a3;
v4 = 4 * a3;
if ( a1 == 32 )
result = v4;
return result;
}

original_code:
static int SC15025_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
{
    if (bpp == 16)
 return htiming * 2;
    if (bpp == 32)
 return htiming * 4;
    return htiming;
}


decompiled_code:
__int64 __fastcall SC15025_restorestate(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl

ramdac_dactocomm();
v1 = _svgalib_port_in(966LL);
ramdac_setcomm(v1 | 0x10);
ramdac_dactocomm();
_svgalib_port_out(8LL, 967LL);
_svgalib_port_out(a1[1], 968LL);
_svgalib_port_out(16LL, 967LL);
_svgalib_port_out(a1[2], 968LL);
ramdac_setcomm(v1);
return ramdac_setcomm(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 *a1)
{
unsigned __int8 v1; // bl

func7();
v1 = _svgalib_port_in(966LL);
func11(v1 | 0x10);
func7();
_svgalib_port_out(8LL, 967LL);
_svgalib_port_out(a1[1], 968LL);
_svgalib_port_out(16LL, 967LL);
_svgalib_port_out(a1[2], 968LL);
func11(v1);
return func11(*a1);
}

original_code:
static void SC15025_restorestate(const unsigned char *regs)
{
    unsigned char c;
    _ramdac_dactocomm();
    c = __svgalib_port_in(0x3C6);
    _ramdac_setcomm(c | 0x10);
    _ramdac_dactocomm();
    __svgalib_port_out(8, 0x3C7);
    __svgalib_port_out(regs[1], 0x3C8);
    __svgalib_port_out(16, 0x3C7);
    __svgalib_port_out(regs[2], 0x3C8);
    _ramdac_setcomm(c);
    _ramdac_setcomm(regs[0]);
}

canonical_original_code:
static void SC15025_restorestate(unsigned char *regs)
{
    unsigned char c;
    _ramdac_dactocomm();
    c = __svgalib_port_in(0x3C6);
    _ramdac_setcomm(c | 0x10);
    _ramdac_dactocomm();
    __svgalib_port_out(8, 0x3C7);
    __svgalib_port_out(regs[1], 0x3C8);
    __svgalib_port_out(16, 0x3C7);
    __svgalib_port_out(regs[2], 0x3C8);
    _ramdac_setcomm(c);
    _ramdac_setcomm(regs[0]);
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall SC15025_savestate(unsigned __int8 *a1)
{
unsigned __int8 v1; // al

ramdac_dactocomm();
v1 = _svgalib_port_in(966LL);
*a1 = v1;
ramdac_setcomm(v1 | 0x10);
ramdac_dactocomm();
_svgalib_port_out(8LL, 967LL);
a1[1] = _svgalib_port_in(968LL);
_svgalib_port_out(16LL, 967LL);
a1[2] = _svgalib_port_in(968LL);
return ramdac_setcomm(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 *a1)
{
unsigned __int8 v1; // al

func7();
v1 = _svgalib_port_in(966LL);
*a1 = v1;
func11(v1 | 0x10);
func7();
_svgalib_port_out(8LL, 967LL);
a1[1] = _svgalib_port_in(968LL);
_svgalib_port_out(16LL, 967LL);
a1[2] = _svgalib_port_in(968LL);
return func11(*a1);
}

original_code:
static void SC15025_savestate(unsigned char *regs)
{
    _ramdac_dactocomm();
    regs[0] = __svgalib_port_in(0x3C6);
    _ramdac_setcomm(regs[0] | 0x10);
    _ramdac_dactocomm();
    __svgalib_port_out(8, 0x3C7);
    regs[1] = __svgalib_port_in(0x3C8);
    __svgalib_port_out(16, 0x3C7);
    regs[2] = __svgalib_port_in(0x3C8);
    _ramdac_setcomm(regs[0]);
}

variable_types:
regs
unsigned char *


decompiled_code:
__int64 SC15025_probe()
{
unsigned __int8 v0; // bp
char *v1; // rbx
__int64 result; // rax
char v3[4]; // [rsp+Ch] [rbp-2Ch] BYREF
char v4; // [rsp+10h] [rbp-28h] BYREF

ramdac_dactocomm();
v0 = _svgalib_port_in(966LL);
ramdac_setcomm(v0 | 0x10);
v1 = v3;
do
{
_svgalib_port_out(9 - (unsigned int)v3 + (unsigned int)v1, 967LL);
*v1++ = _svgalib_port_in(968LL);
}
while ( v1 != &v4 );
ramdac_setcomm(v0);
ramdac_dactopel();
result = 0LL;
if ( v3[0] == 83 )
{
result = 0LL;
if ( ((unsigned __int8)v3[2] | ((unsigned __int8)v3[1] << 8)) == 15025 )
{
SC15025_Rev = v3[3];
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned __int8 v0; // bp
char *v1; // rbx
__int64 result; // rax
char v3[4]; // [rsp+Ch] [rbp-2Ch] BYREF
char v4; // [rsp+10h] [rbp-28h] BYREF

func7();
v0 = _svgalib_port_in(966LL);
func11(v0 | 0x10);
v1 = v3;
do
{
_svgalib_port_out(9 - (unsigned int)v3 + (unsigned int)v1, 967LL);
*v1++ = _svgalib_port_in(968LL);
}
while ( v1 != &v4 );
func11(v0);
func9();
result = 0LL;
if ( v3[0] == 83 )
{
result = 0LL;
if ( ((unsigned __int8)v3[2] | ((unsigned __int8)v3[1] << 8)) == 15025 )
{
SC15025_Rev = v3[3];
result = 1LL;
}
}
return result;
}

original_code:
static int SC15025_probe(void)
{
    unsigned char c, id[4];
    int i, flag = 0;
    _ramdac_dactocomm();
    c = __svgalib_port_in(0x3C6);
    _ramdac_setcomm(c | 0x10);
    for (i = 0; i < 4; i++) {
 __svgalib_port_out(0x9 + i, 0x3C7);
 id[i] = __svgalib_port_in(0x3C8);
    }
    _ramdac_setcomm(c);
    _ramdac_dactopel();
    if (id[0] == 'S' &&
 ((id[1] << 8) | id[2]) == 15025) {
 flag = 1;
 SC15025_Rev = id[3];
    }
    return flag;
}

canonical_original_code:
static int SC15025_probe()
{
    unsigned char c; unsigned char id[4];
    int i; int flag = 0;
    _ramdac_dactocomm();
    c = __svgalib_port_in(0x3C6);
    _ramdac_setcomm(c | 0x10);
    for (i = 0; i < 4; i++) {
 __svgalib_port_out(0x9 + i, 0x3C7);
 id[i] = __svgalib_port_in(0x3C8);
    }
    _ramdac_setcomm(c);
    _ramdac_dactopel();
    if (id[0] == 'S' &&
 ((id[1] << 8) | id[2]) == 15025) {
 flag = 1;
 SC15025_Rev = id[3];
    }
    return flag;
}

variable_types:
id
unsigned char [4]

variable_types: i int

variable_types: flag int


decompiled_code:
_BOOL8 SC1148X_probe()
{
char v0; // bl
char v1; // al
char v2; // dl
char v3; // bl
char v4; // dl
unsigned __int8 v5; // bp
unsigned __int8 v6; // bl
unsigned __int8 v7; // r12
_BOOL4 v8; // er13
unsigned __int8 v10; // r12

ramdac_dactopel();
v0 = _svgalib_port_in(966LL);
do
{
v1 = _svgalib_port_in(966LL);
v2 = v0;
v0 = v1;
}
while ( v2 != v1 );
_svgalib_port_in(968LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
if ( v0 == -114 )
goto LABEL_15;
v3 = 9;
do
{
v4 = _svgalib_port_in(966LL);
--v3;
}
while ( v4 != -114 && v3 );
if ( v4 == -114 )
{
LABEL_15:
ramdac_dactopel();
v8 = 0;
}
else
{
ramdac_dactocomm();
v5 = _svgalib_port_in(966LL);
ramdac_dactopel();
v6 = _svgalib_port_in(966LL);
_svgalib_port_out((unsigned __int8)~v5, 966LL);
ramdac_dactocomm();
v7 = _svgalib_port_in(966LL);
v8 = 0;
if ( ~v5 != v7 )
{
if ( (((unsigned __int8)ramdac_setcomm(v5 ^ 0x60u) ^ v7) & 0xE0) != 0 )
{
_svgalib_SC1148X_methods = 5;
*((_QWORD *)&_svgalib_SC1148X_methods + 1) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 1);
*((_QWORD *)&_svgalib_SC1148X_methods + 4) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 4);
*((_QWORD *)&_svgalib_SC1148X_methods + 5) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 5);
*((_QWORD *)&_svgalib_SC1148X_methods + 8) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 8);
v8 = 1;
}
else
{
v10 = _svgalib_port_in(966LL);
ramdac_dactopel();
v8 = v10 != (unsigned int)_svgalib_port_in(966LL);
}
ramdac_dactocomm();
_svgalib_port_out(v5, 966LL);
}
ramdac_dactopel();
_svgalib_port_out(v6, 966LL);
}
return v8;
}

canonical_decompiled_code:
_BOOL8 func15()
{
char v0; // bl
char v1; // al
char v2; // dl
char v3; // bl
char v4; // dl
unsigned __int8 v5; // bp
unsigned __int8 v6; // bl
unsigned __int8 v7; // r12
_BOOL4 v8; // er13
unsigned __int8 v10; // r12

func9();
v0 = _svgalib_port_in(966LL);
do
{
v1 = _svgalib_port_in(966LL);
v2 = v0;
v0 = v1;
}
while ( v2 != v1 );
_svgalib_port_in(968LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
_svgalib_port_in(966LL);
if ( v0 == -114 )
goto LABEL_15;
v3 = 9;
do
{
v4 = _svgalib_port_in(966LL);
--v3;
}
while ( v4 != -114 && v3 );
if ( v4 == -114 )
{
LABEL_15:
func9();
v8 = 0;
}
else
{
func7();
v5 = _svgalib_port_in(966LL);
func9();
v6 = _svgalib_port_in(966LL);
_svgalib_port_out((unsigned __int8)~v5, 966LL);
func7();
v7 = _svgalib_port_in(966LL);
v8 = 0;
if ( ~v5 != v7 )
{
if ( (((unsigned __int8)func11(v5 ^ 0x60u) ^ v7) & 0xE0) != 0 )
{
_svgalib_SC1148X_methods = 5;
*((_QWORD *)&_svgalib_SC1148X_methods + 1) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 1);
*((_QWORD *)&_svgalib_SC1148X_methods + 4) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 4);
*((_QWORD *)&_svgalib_SC1148X_methods + 5) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 5);
*((_QWORD *)&_svgalib_SC1148X_methods + 8) = *((_QWORD *)&_svgalib_Sierra_32K_methods + 8);
v8 = 1;
}
else
{
v10 = _svgalib_port_in(966LL);
func9();
v8 = v10 != (unsigned int)_svgalib_port_in(966LL);
}
func7();
_svgalib_port_out(v5, 966LL);
}
func9();
_svgalib_port_out(v6, 966LL);
}
return v8;
}

original_code:
static int SC1148X_probe(void)
{
    unsigned char oc, op, tmp, tmp2;
    int flag = 0;
    _ramdac_dactopel();
    tmp = __svgalib_port_in(0x3C6);
    do {
 tmp2 = tmp;
 tmp = __svgalib_port_in(0x3C6);
    } while (tmp2 != tmp);
    __svgalib_port_in(0x3C8);
    __svgalib_port_in(0x3C6);
    __svgalib_port_in(0x3C6);
    __svgalib_port_in(0x3C6);
    for (tmp2 = 9; tmp != 0x8E && tmp2 > 0; tmp2--)
 tmp = __svgalib_port_in(0x3C6);
    if (tmp != 0x8E) {
        _ramdac_dactocomm();
        oc = __svgalib_port_in(0x3C6);
        _ramdac_dactopel();
        op = __svgalib_port_in(0x3C6);
        tmp = oc ^ 0xFF;
        __svgalib_port_out(tmp, 0x3C6);
        _ramdac_dactocomm();
        tmp2 = __svgalib_port_in(0x3C6);
        if (tmp2 != tmp) {
            tmp = _ramdac_setcomm(tmp = oc ^ 0x60);
            if ((tmp & 0xe0) == (tmp2 & 0xe0)) {
                tmp = __svgalib_port_in(0x3C6);
                _ramdac_dactopel();
                if (tmp != __svgalib_port_in(0x3C6))
      flag = 1;
     } else {
  flag = 1;
  __svgalib_SC1148X_methods.id = 5;
  __svgalib_SC1148X_methods.name = __svgalib_Sierra_32K_methods.name;
  __svgalib_SC1148X_methods.initialize = __svgalib_Sierra_32K_methods.initialize;
  __svgalib_SC1148X_methods.qualifyCardSpecs = __svgalib_Sierra_32K_methods.qualifyCardSpecs ;
  __svgalib_SC1148X_methods.initializeState = __svgalib_Sierra_32K_methods.initializeState ;
     }
     _ramdac_dactocomm();
     __svgalib_port_out(oc, 0x3C6);
 }
 _ramdac_dactopel();
 __svgalib_port_out(op, 0x3C6);
    } else {
 _ramdac_dactopel();
    }
    return flag;
}

canonical_original_code:
static int SC1148X_probe()
{
    unsigned char oc; unsigned char op; unsigned char tmp; unsigned char tmp2;
    int flag = 0;
    _ramdac_dactopel();
    tmp = __svgalib_port_in(0x3C6);
    do {
 tmp2 = tmp;
 tmp = __svgalib_port_in(0x3C6);
    } while (tmp2 != tmp);
    __svgalib_port_in(0x3C8);
    __svgalib_port_in(0x3C6);
    __svgalib_port_in(0x3C6);
    __svgalib_port_in(0x3C6);
    for (tmp2 = 9; tmp != 0x8E && tmp2 > 0; tmp2--)
 tmp = __svgalib_port_in(0x3C6);
    if (tmp != 0x8E) {
        _ramdac_dactocomm();
        oc = __svgalib_port_in(0x3C6);
        _ramdac_dactopel();
        op = __svgalib_port_in(0x3C6);
        tmp = oc ^ 0xFF;
        __svgalib_port_out(tmp, 0x3C6);
        _ramdac_dactocomm();
        tmp2 = __svgalib_port_in(0x3C6);
        if (tmp2 != tmp) {
            tmp = _ramdac_setcomm(tmp = oc ^ 0x60);
            if ((tmp & 0xe0) == (tmp2 & 0xe0)) {
                tmp = __svgalib_port_in(0x3C6);
                _ramdac_dactopel();
                if (tmp != __svgalib_port_in(0x3C6))
      flag = 1;
     } else {
  flag = 1;
  __svgalib_SC1148X_methods.id = 5;
  __svgalib_SC1148X_methods.name = __svgalib_Sierra_32K_methods.name;
  __svgalib_SC1148X_methods.initialize = __svgalib_Sierra_32K_methods.initialize;
  __svgalib_SC1148X_methods.qualifyCardSpecs = __svgalib_Sierra_32K_methods.qualifyCardSpecs ;
  __svgalib_SC1148X_methods.initializeState = __svgalib_Sierra_32K_methods.initializeState ;
     }
     _ramdac_dactocomm();
     __svgalib_port_out(oc, 0x3C6);
 }
 _ramdac_dactopel();
 __svgalib_port_out(op, 0x3C6);
    } else {
 _ramdac_dactopel();
    }
    return flag;
}

variable_types:
oc
unsigned char

variable_types:
op
unsigned char


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

result = &_svgalib_driver_report;
if ( _svgalib_driver_report )
result = (_DWORD *)fwrite("svgalib: Using Sierra 32K DAC.\n", 1uLL, 0x1FuLL, stderr);
return result;
}

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

result = &_svgalib_driver_report;
if ( _svgalib_driver_report )
result = (_DWORD *)fwrite("svgalib: Using Sierra 32K DAC.\n", 1uLL, 0x1FuLL, stderr);
return result;
}

original_code:
static void Sierra_32K_init(void)
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using Sierra 32K DAC.\n");
}

canonical_original_code:
static void Sierra_32K_init()
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using Sierra 32K DAC.\n");
}


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

result = &_svgalib_driver_report;
if ( _svgalib_driver_report )
result = (_DWORD *)fwrite("svgalib: Using Sierra 1148x series 32K DAC.\n", 1uLL, 0x2CuLL, stderr);
return result;
}

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

result = &_svgalib_driver_report;
if ( _svgalib_driver_report )
result = (_DWORD *)fwrite("svgalib: Using Sierra 1148x series 32K DAC.\n", 1uLL, 0x2CuLL, stderr);
return result;
}

original_code:
static void SC1148X_init(void)
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using Sierra 1148x series 32K DAC.\n");
}

canonical_original_code:
static void SC1148X_init()
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using Sierra 1148x series 32K DAC.\n");
}


decompiled_code:
int SC15025_init()
{
_DWORD *v0; // rax

v0 = &_svgalib_driver_report;
if ( _svgalib_driver_report )
LODWORD(v0) = fprintf(stderr, "svgalib: Using Sierra 15025/26%c truecolor DAC.\n", (unsigned __int8)SC15025_Rev);
return (int)v0;
}

canonical_decompiled_code:
int func18()
{
_DWORD *v0; // rax

v0 = &_svgalib_driver_report;
if ( _svgalib_driver_report )
LODWORD(v0) = fprintf(stderr, "svgalib: Using Sierra 15025/26%c truecolor DAC.\n", (unsigned __int8)SC15025_Rev);
return (int)v0;
}

original_code:
static void SC15025_init(void)
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using Sierra 15025/26%c truecolor DAC.\n", SC15025_Rev);
}

canonical_original_code:
static void SC15025_init()
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using Sierra 15025/26%c truecolor DAC.\n", SC15025_Rev);
}


setcursor

decompiled_code:
__int64 __fastcall setcursor(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebp
unsigned int v5; // er12

v4 = a3;
v5 = a4;
if ( init_0 )
{
init_0 = 0;
if ( a2 )
{
vga_setcursorimage(a2, 0LL, a3, a4, a1);
}
else
{
vga_setmousesupport(1LL);
vga_initcursor((unsigned int)software);
}
}
vga_setcursorimage(a2, 0LL, v4, v5, a1);
vga_selectcursor(a2);
mouse_setposition(0LL, 0LL);
mouse_setxrange(4294967291LL, (unsigned int)(psiz - 1));
return mouse_setyrange(0LL, (unsigned int)(psiz - 1));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebp
unsigned int v5; // er12

v4 = a3;
v5 = a4;
if ( init_0 )
{
init_0 = 0;
if ( a2 )
{
vga_setcursorimage(a2, 0LL, a3, a4, a1);
}
else
{
vga_setmousesupport(1LL);
vga_initcursor((unsigned int)software);
}
}
vga_setcursorimage(a2, 0LL, v4, v5, a1);
vga_selectcursor(a2);
mouse_setposition(0LL, 0LL);
mouse_setxrange(4294967291LL, (unsigned int)(psiz - 1));
return mouse_setyrange(0LL, (unsigned int)(psiz - 1));
}

original_code:
void setcursor(int *arrow,int cursor, int color0, int color1)
{
  static int init = 1;
  if(init)
    {
      init = 0;
      if(cursor != 0)
 vga_setcursorimage(cursor,0,color0,color1,(void *)arrow);
      else
 {
   vga_setmousesupport(1);
   vga_initcursor(software);
 }
    }
      vga_setcursorimage(cursor,0,color0,color1,(void *) arrow);
  vga_selectcursor(cursor);
  mouse_setposition(0,0);
  mouse_setxrange(-5,psiz - 1);
  mouse_setyrange(0,psiz - 1);
  return;
}

canonical_original_code:
void setcursor(int *arrow, int cursor, int color0, int color1)
{
  static int init = 1;
  if(init)
    {
      init = 0;
      if(cursor != 0)
 vga_setcursorimage(cursor,0,color0,color1,(void *)arrow);
      else
 {
   vga_setmousesupport(1);
   vga_initcursor(software);
 }
    }
      vga_setcursorimage(cursor,0,color0,color1,(void *) arrow);
  vga_selectcursor(cursor);
  mouse_setposition(0,0);
  mouse_setxrange(-5,psiz - 1);
  mouse_setyrange(0,psiz - 1);
  return;
}

variable_types:
arrow
int *

variable_types: cursor int

variable_types: init int


usage

decompiled_code:
void __noreturn usage()
{
puts(
"Usage:\n"
"buildcsr -p<sprite> -b<sprite> -m<mode> -s\n"
"\tDraw sprite by holding down the left mouse button.\n"
"\tDraw color 2 type 2 and use left button.\n"
"\tRight mouse button to erase pixels.\n"
"\t-p print out the sprite as a header file to be compiled\n"
"\t-b print out the sprite as a binary file to be read by a program\n"
"\t-m to use any mode. Default is vga_default mode or G640x480x256.\n"
"\t-s to use software cursor. Default is to use hardware cursor if it\n"
"\t exits.");
exit(2);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts(
"Usage:\n"
"buildcsr -p<sprite> -b<sprite> -m<mode> -s\n"
"\tDraw sprite by holding down the left mouse button.\n"
"\tDraw color 2 type 2 and use left button.\n"
"\tRight mouse button to erase pixels.\n"
"\t-p print out the sprite as a header file to be compiled\n"
"\t-b print out the sprite as a binary file to be read by a program\n"
"\t-m to use any mode. Default is vga_default mode or G640x480x256.\n"
"\t-s to use software cursor. Default is to use hardware cursor if it\n"
"\t exits.");
exit(2);
}

original_code:
void usage(void)
{
  puts("Usage:\n"
       "buildcsr -p<sprite> -b<sprite> -m<mode> -s\n"
       "\tDraw sprite by holding down the left mouse button.\n"
       "\tDraw color 2 type 2 and use left button.\n"
       "\tRight mouse button to erase pixels.\n"
       "\t-p print out the sprite as a header file to be compiled\n"
       "\t-b print out the sprite as a binary file to be read by a program\n"
       "\t-m to use any mode. Default is vga_default mode or G640x480x256.\n"
       "\t-s to use software cursor. Default is to use hardware cursor if it\n"
       "\t exits."
       );
    exit(2);
}

canonical_original_code:
void usage()
{
  puts("Usage:\n"
       "buildcsr -p<sprite> -b<sprite> -m<mode> -s\n"
       "\tDraw sprite by holding down the left mouse button.\n"
       "\tDraw color 2 type 2 and use left button.\n"
       "\tRight mouse button to erase pixels.\n"
       "\t-p print out the sprite as a header file to be compiled\n"
       "\t-b print out the sprite as a binary file to be read by a program\n"
       "\t-m to use any mode. Default is vga_default mode or G640x480x256.\n"
       "\t-s to use software cursor. Default is to use hardware cursor if it\n"
       "\t exits."
       );
    exit(2);
}


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

if ( a1 == 8 && a2 > 80000 )
return (unsigned int)(a2 / 2);
result = (unsigned int)a2;
if ( a1 != 16 )
{
if ( a1 == 24 )
{
result = (unsigned int)(3 * a2 / 2);
}
else
{
result = (unsigned int)(2 * a2);
if ( a1 != 32 )
result = (unsigned int)a2;
}
}
return result;
}

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

if ( a1 == 8 && a2 > 80000 )
return (unsigned int)(a2 / 2);
result = (unsigned int)a2;
if ( a1 != 16 )
{
if ( a1 == 24 )
{
result = (unsigned int)(3 * a2 / 2);
}
else
{
result = (unsigned int)(2 * a2);
if ( a1 != 32 )
result = (unsigned int)a2;
}
}
return result;
}

original_code:
static int ICW_map_clock(int bpp, int pixelclock)
{
    if (bpp == 8 && pixelclock > 80000)
 return pixelclock / 2;
    if (bpp == 16)
 return pixelclock;
    if (bpp == 24)
 return pixelclock * 3 / 2;
    if (bpp == 32)
 return pixelclock * 2;
    return pixelclock;
}

variable_types: bpp int


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

if ( a1 == 8 && a2 > 80000 )
return (unsigned int)((int)a3 / 2);
if ( a1 == 24 )
return (unsigned int)((int)(3 * a3) / 2);
result = 2 * a3;
if ( a1 != 32 )
result = a3;
return result;
}

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

if ( a1 == 8 && a2 > 80000 )
return (unsigned int)((int)a3 / 2);
if ( a1 == 24 )
return (unsigned int)((int)(3 * a3) / 2);
result = 2 * a3;
if ( a1 != 32 )
result = a3;
return result;
}

original_code:
static int ICW_map_horizontal_crtc(int bpp, int pixelclock, int htiming)
{
    if (bpp == 8 && pixelclock > 80000)
 return htiming / 2;
    if (bpp == 24)
 return htiming * 3 / 2;
    if (bpp == 32)
 return htiming * 2;
    return htiming;
}

variable_types: pixelclock int


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

result = &_svgalib_driver_report;
if ( _svgalib_driver_report )
result = (_DWORD *)fwrite("svgalib: Using IC Works DAC (AT&T20C498-compatible).\n", 1uLL, 0x35uLL, stderr);
return result;
}

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

result = &_svgalib_driver_report;
if ( _svgalib_driver_report )
result = (_DWORD *)fwrite("svgalib: Using IC Works DAC (AT&T20C498-compatible).\n", 1uLL, 0x35uLL, stderr);
return result;
}

original_code:
static void ICW_init(void)
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using IC Works DAC (AT&T20C498-compatible).\n");
}

canonical_original_code:
static void ICW_init()
{
    if (__svgalib_driver_report)
 fprintf(stderr,"svgalib: Using IC Works DAC (AT&T20C498-compatible).\n");
}


decompiled_code:
__int64 fat_type()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 2LL;
}

original_code:
int fat_type(BPB_struct *s) {
 return 2;
}

canonical_original_code:
int fat_type(struct struct_BPB_struct *s) {
 return 2;
}

variable_types: struct struct_BPB_struct { unsigned char BS_JumpBoot[3]; unsigned char BS_OEMName[8]; unsigned short BytesPerSector; unsigned char SectorsPerCluster; unsigned short ReservedSectorCount; unsigned char NumFATs; unsigned short RootEntryCount; unsigned short TotalSectors16; unsigned char Media; unsigned short FATSize16; unsigned short SectorsPerTrack; unsigned short NumberOfHeads; unsigned int HiddenSectors; unsigned int TotalSectors32; union { struct struct_BPBFAT1216_struct { unsigned char BS_DriveNumber; unsigned char BS_Reserved1; unsigned char BS_BootSig; unsigned int BS_VolumeID; unsigned char BS_VolumeLabel[11]; unsigned char BS_FileSystemType[8]; } fat16; struct struct_BPBFAT32_struct { unsigned int FATSize; unsigned short ExtFlags; unsigned short FSVersion; unsigned int RootCluster; unsigned short FSInfo; unsigned short BkBootSec; unsigned char Reserved[12]; unsigned char BS_DriveNumber; unsigned char BS_Reserved1; unsigned char BS_BootSig; unsigned int BS_VolumeID; unsigned char BS_VolumeLabel[11]; unsigned char BS_FileSystemType[8]; } fat32; } FSTypeSpecificData; } *

user_defined_types: struct struct_BPB_struct { unsigned char BS_JumpBoot[3]; unsigned char BS_OEMName[8]; unsigned short BytesPerSector; unsigned char SectorsPerCluster; unsigned short ReservedSectorCount; unsigned char NumFATs; unsigned short RootEntryCount; unsigned short TotalSectors16; unsigned char Media; unsigned short FATSize16; unsigned short SectorsPerTrack; unsigned short NumberOfHeads; unsigned int HiddenSectors; unsigned int TotalSectors32; union { struct struct_BPBFAT1216_struct fat16; struct struct_BPBFAT32_struct fat32; } FSTypeSpecificData; }


decompiled_code:
int __fastcall print_media(unsigned __int8 a1)
{
int result; // eax

if ( a1 < 0xF0u )
return printf("Unknown (0x%02x)", a1);
switch ( a1 )
{
case 0xF0:
result = printf("Generic media type (0xf0)");
break;
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4:
case 0xF5:
case 0xF6:
case 0xF7:
return printf("Unknown (0x%02x)", a1);
case 0xF8:
result = printf("Hard disk (0xf8)");
break;
case 0xF9:
result = printf("3.5\" double sided 720k or 5.25 double sided 1.2MB (0xf9)");
break;
case 0xFA:
result = printf("5.25\" single sided 320k (0xfa)");
break;
case 0xFB:
result = printf("3.5\" double sided 640k (0xfb)");
break;
case 0xFC:
result = printf("5.25\" single sided 180k (0xfc)");
break;
case 0xFD:
result = printf("5.25\" double sided 360k (0xfd)");
break;
case 0xFE:
result = printf("5.25\" single sided 180k (0xfe)");
break;
case 0xFF:
result = printf("5.25\" double sided 320k (0xff)");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int8 a1)
{
int result; // eax

if ( a1 < 0xF0u )
return printf("Unknown (0x%02x)", a1);
switch ( a1 )
{
case 0xF0:
result = printf("Generic media type (0xf0)");
break;
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4:
case 0xF5:
case 0xF6:
case 0xF7:
return printf("Unknown (0x%02x)", a1);
case 0xF8:
result = printf("Hard disk (0xf8)");
break;
case 0xF9:
result = printf("3.5\" double sided 720k or 5.25 double sided 1.2MB (0xf9)");
break;
case 0xFA:
result = printf("5.25\" single sided 320k (0xfa)");
break;
case 0xFB:
result = printf("3.5\" double sided 640k (0xfb)");
break;
case 0xFC:
result = printf("5.25\" single sided 180k (0xfc)");
break;
case 0xFD:
result = printf("5.25\" double sided 360k (0xfd)");
break;
case 0xFE:
result = printf("5.25\" single sided 180k (0xfe)");
break;
case 0xFF:
result = printf("5.25\" double sided 320k (0xff)");
break;
}
return result;
}

original_code:
void print_media(unsigned char mediatype) {
 switch(mediatype) {
  case 0xf0: printf("Generic media type (0xf0)"); break;
  case 0xf8: printf("Hard disk (0xf8)"); break;
  case 0xf9: printf("3.5\" double sided 720k or 5.25 double sided 1.2MB (0xf9)"); break;
  case 0xfa: printf("5.25\" single sided 320k (0xfa)"); break;
  case 0xfb: printf("3.5\" double sided 640k (0xfb)"); break;
  case 0xfc: printf("5.25\" single sided 180k (0xfc)"); break;
  case 0xfd: printf("5.25\" double sided 360k (0xfd)"); break;
  case 0xfe: printf("5.25\" single sided 180k (0xfe)"); break;
  case 0xff: printf("5.25\" double sided 320k (0xff)"); break;
  default: printf("Unknown (0x%02x)",mediatype); break;
 }
}

variable_types:
mediatype
unsigned char