decompiled_code:
unsigned __int64 __fastcall bigtime_sub(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v5; // edi
unsigned __int64 v6; // rax
int v7; // eax
__int64 v9; // [rsp+0h] [rbp-14h]

v5 = a1 - a3;
v6 = HIDWORD(a1);
if ( (int)v6 < SHIDWORD(a3) )
{
--v5;
v7 = v6 - HIDWORD(a3) + 100000;
if ( a2 >= a4 )
return __PAIR64__(v7, v5);
}
else
{
v7 = v6 - HIDWORD(a3);
if ( a2 >= a4 )
return __PAIR64__(v7, v5);
}
if ( v7 <= 0 )
{
LODWORD(v9) = v5 - 1;
HIDWORD(v9) = 99999;
}
else
{
LODWORD(v9) = v5;
HIDWORD(v9) = v7 - 1;
}
return v9;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v5; // edi
unsigned __int64 v6; // rax
int v7; // eax
__int64 v9; // [rsp+0h] [rbp-14h]

v5 = a1 - a3;
v6 = HIDWORD(a1);
if ( (int)v6 < SHIDWORD(a3) )
{
--v5;
v7 = v6 - HIDWORD(a3) + 100000;
if ( a2 >= a4 )
return __PAIR64__(v7, v5);
}
else
{
v7 = v6 - HIDWORD(a3);
if ( a2 >= a4 )
return __PAIR64__(v7, v5);
}
if ( v7 <= 0 )
{
LODWORD(v9) = v5 - 1;
HIDWORD(v9) = 99999;
}
else
{
LODWORD(v9) = v5;
HIDWORD(v9) = v7 - 1;
}
return v9;
}

original_code:
static bigtime bigtime_sub(bigtime op1, bigtime op2)
{
 bigtime res;
 res.hi = op1.hi - op2.hi;
 if (op1.mid >= op2.mid)
   res.mid = op1.mid - op2.mid;
 else
 {
   res.mid = 100000 - op2.mid + op1.mid;
   res.hi--;
 }
 if (op1.lo >= op2.lo)
   res.lo = op1.lo - op2.lo;
 else
 {
   res.lo = 100000 - op2.lo + op1.lo;
          if (res.mid > 0)
     res.mid--;
          else
          {
            res.mid = 99999;
     res.hi--;
          }
 }
 return res;
}

canonical_original_code:
static struct bigtime bigtime_sub(struct bigtime op1, struct bigtime op2)
{
 struct bigtime res;
 res.hi = op1.hi - op2.hi;
 if (op1.mid >= op2.mid)
   res.mid = op1.mid - op2.mid;
 else
 {
   res.mid = 100000 - op2.mid + op1.mid;
   res.hi--;
 }
 if (op1.lo >= op2.lo)
   res.lo = op1.lo - op2.lo;
 else
 {
   res.lo = 100000 - op2.lo + op1.lo;
          if (res.mid > 0)
     res.mid--;
          else
          {
            res.mid = 99999;
     res.hi--;
          }
 }
 return res;
}

variable_types: struct bigtime { int hi; int mid; int lo; }


repo: CeRiAl/Xhomer

original_code:
static bigtime bigtime_mul(bigtime op1, int op2)
{
 bigtime res, tmp;
 tmp.hi = op1.hi * op2;
 tmp.mid = op1.mid * op2;
 tmp.lo = op1.lo * op2;
 res.lo = tmp.lo % 100000;
 res.mid = ((tmp.lo / 100000) + tmp.mid) % 100000;
 res.hi = ((tmp.lo / 100000) + tmp.mid) / 100000 + tmp.hi;
 return res;
}

canonical_original_code:
static struct bigtime bigtime_mul(struct bigtime op1, int op2)
{
 struct bigtime res; struct bigtime tmp;
 tmp.hi = op1.hi * op2;
 tmp.mid = op1.mid * op2;
 tmp.lo = op1.lo * op2;
 res.lo = tmp.lo % 100000;
 res.mid = ((tmp.lo / 100000) + tmp.mid) % 100000;
 res.hi = ((tmp.lo / 100000) + tmp.mid) / 100000 + tmp.hi;
 return res;
}

return_type: struct bigtime { int hi; int mid; int lo; }


decompiled_code:
__int64 pro_time_update()
{
struct tm *v0; // rax
int v1; // edx
int v2; // ecx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = v0->tm_sec;
v2 = v0->tm_min;
pro_time = (__int64)v0;
LODWORD(v0) = v0->tm_hour;
pro_time_min = v2;
pro_time_hour = (int)v0;
result = 59LL;
if ( v1 >= 60 )
v1 = 59;
pro_time_sec = v1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
struct tm *v0; // rax
int v1; // edx
int v2; // ecx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = v0->tm_sec;
v2 = v0->tm_min;
pro_time = (__int64)v0;
LODWORD(v0) = v0->tm_hour;
pro_time_min = v2;
pro_time_hour = (int)v0;
result = 59LL;
if ( v1 >= 60 )
v1 = 59;
pro_time_sec = v1;
return result;
}

original_code:
static void pro_time_update()
{
 time_t t;
 t = time(((void *)0));
 pro_time = localtime(&t);
 pro_time_sec = pro_time->tm_sec;
 pro_time_min = pro_time->tm_min;
 pro_time_hour = pro_time->tm_hour;
 if (pro_time_sec > 59)
   pro_time_sec = 59;
}

canonical_original_code:
static void pro_time_update()
{
 long t;
 t = time(((void *)0));
 pro_time = localtime(&t);
 pro_time_sec = pro_time->tm_sec;
 pro_time_min = pro_time->tm_min;
 pro_time_hour = pro_time->tm_hour;
 if (pro_time_sec > 59)
   pro_time_sec = 59;
}

variable_types: t long

return_type: void


decompiled_code:
__int64 pro_time_get()
{
__int64 v1; // [rsp+14h] [rbp-24h]
struct timeval tv; // [rsp+20h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
LODWORD(v1) = tv.tv_sec / 100000;
HIDWORD(v1) = tv.tv_sec % 100000;
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v1; // [rsp+14h] [rbp-24h]
struct timeval tv; // [rsp+20h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
LODWORD(v1) = tv.tv_sec / 100000;
HIDWORD(v1) = tv.tv_sec % 100000;
return v1;
}

original_code:
static bigtime pro_time_get()
{
 struct timeval tv;
 bigtime res;
 gettimeofday(&tv, ((void *)0));
 res.lo = tv.tv_usec/10;
 res.mid = tv.tv_sec % 100000;
 res.hi = tv.tv_sec / 100000;
 return res;
}

canonical_original_code:
static struct bigtime pro_time_get()
{
 struct timeval tv;
 struct bigtime res;
 gettimeofday(&tv, ((void *)0));
 res.lo = tv.tv_usec/10;
 res.mid = tv.tv_sec % 100000;
 res.hi = tv.tv_sec / 100000;
 return res;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: struct bigtime { int hi; int mid; int lo; }


decompiled_code:
__int64 pro_clk_uf_sched()
{
return pro_eq_sched(2LL, 98LL);
}

canonical_decompiled_code:
__int64 func4()
{
return pro_eq_sched(2LL, 98LL);
}


decompiled_code:
__int64 pro_clk_sched()
{
int v0; // ebx
__int64 v1; // rax
int v2; // edx
__int64 v3; // rax
int v4; // edx
__int64 v5; // rsi

v0 = pro_clk_freq;
if ( pro_clk_rs != (pro_clk_csr0 & 0xF) )
{
pro_clk_rs = pro_clk_csr0 & 0xF;
pro_clk_freq = pro_clk_intf[pro_clk_csr0 & 0xF];
v0 = pro_clk_freq;
v1 = pro_time_get();
v3 = bigtime_mul(v1, v2, v0);
pro_clk_numint = 0;
pro_time_start = v3;
dword_8E0 = v4;
pro_clk_int_cnt = 0;
}
v5 = (unsigned int)(327680 / v0);
if ( pro_int_throttle && pro_clk_realtime && pro_clk_numint >= 3 )
v5 = 1000LL;
return pro_eq_sched(1LL, v5);
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ebx
__int64 v1; // rax
int v2; // edx
__int64 v3; // rax
int v4; // edx
__int64 v5; // rsi

v0 = pro_clk_freq;
if ( pro_clk_rs != (pro_clk_csr0 & 0xF) )
{
pro_clk_rs = pro_clk_csr0 & 0xF;
pro_clk_freq = pro_clk_intf[pro_clk_csr0 & 0xF];
v0 = pro_clk_freq;
v1 = func3();
v3 = func1(v1, v2, v0);
pro_clk_numint = 0;
pro_time_start = v3;
dword_8E0 = v4;
pro_clk_int_cnt = 0;
}
v5 = (unsigned int)(327680 / v0);
if ( pro_int_throttle && pro_clk_realtime && pro_clk_numint >= 3 )
v5 = 1000LL;
return pro_eq_sched(1LL, v5);
}

original_code:
static void pro_clk_sched ()
{
int interval, rs;
 rs = pro_clk_csr0 & 0017;
 if (rs != pro_clk_rs)
 {
   pro_clk_rs = rs;
   pro_clk_freq = pro_clk_intf[pro_clk_rs];
   pro_time_start = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_clk_numint = 0;
   pro_clk_int_cnt = 0;
 }
 interval = (40*8192) / pro_clk_freq;
 if (pro_int_throttle && pro_clk_realtime && (pro_clk_numint > 2))
   interval = 1000;
 pro_eq_sched(1, interval);
}

canonical_original_code:
static void pro_clk_sched()
{
int interval; int rs;
 rs = pro_clk_csr0 & 0017;
 if (rs != pro_clk_rs)
 {
   pro_clk_rs = rs;
   pro_clk_freq = pro_clk_intf[pro_clk_rs];
   pro_time_start = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_clk_numint = 0;
   pro_clk_int_cnt = 0;
 }
 interval = (40*8192) / pro_clk_freq;
 if (pro_int_throttle && pro_clk_realtime && (pro_clk_numint > 2))
   interval = 1000;
 pro_eq_sched(1, interval);
}

variable_types: interval int

variable_types: rs int


decompiled_code:
__int64 pro_clk_uf_eq()
{
int v0; // eax
__int64 result; // rax

pro_time_update();
v0 = pro_clk_csr2;
pro_clk_csr0 &= 0xFFFFFF7F;
pro_clk_csr2 |= 0x10u;
if ( (pro_clk_csr1 & 0x10) != 0 )
{
LOBYTE(v0) = v0 | 0x90;
pro_clk_csr2 = v0;
pro_int_set(128LL);
}
if ( pro_time_sec == pro_clk_al_sec || (result = (unsigned __int8)pro_clk_al_sec & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_min == pro_clk_al_min || (result = (unsigned __int8)pro_clk_al_min & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_hour == pro_clk_al_hour || (result = (unsigned __int8)pro_clk_al_hour & 0xC0, (_DWORD)result == 192) )
{
result = (unsigned int)pro_clk_csr2;
pro_clk_csr2 |= 0x20u;
if ( (pro_clk_csr1 & 0x20) != 0 )
{
LOBYTE(result) = result | 0xA0;
pro_clk_csr2 = result;
result = pro_int_set(128LL);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
__int64 result; // rax

func2();
v0 = pro_clk_csr2;
pro_clk_csr0 &= 0xFFFFFF7F;
pro_clk_csr2 |= 0x10u;
if ( (pro_clk_csr1 & 0x10) != 0 )
{
LOBYTE(v0) = v0 | 0x90;
pro_clk_csr2 = v0;
pro_int_set(128LL);
}
if ( pro_time_sec == pro_clk_al_sec || (result = (unsigned __int8)pro_clk_al_sec & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_min == pro_clk_al_min || (result = (unsigned __int8)pro_clk_al_min & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_hour == pro_clk_al_hour || (result = (unsigned __int8)pro_clk_al_hour & 0xC0, (_DWORD)result == 192) )
{
result = (unsigned int)pro_clk_csr2;
pro_clk_csr2 |= 0x20u;
if ( (pro_clk_csr1 & 0x20) != 0 )
{
LOBYTE(result) = result | 0xA0;
pro_clk_csr2 = result;
result = pro_int_set(128LL);
}
}
}
}
return result;
}

original_code:
void pro_clk_uf_eq ()
{
 pro_time_update();
 pro_clk_csr0 = pro_clk_csr0 & ~0200;
 pro_clk_csr2 = pro_clk_csr2 | 0020;
 if ((pro_clk_csr1 & 0020) != 0)
 {
   pro_clk_csr2 = pro_clk_csr2 | 0200;
   pro_int_set(0x0080);
 }
 if (((pro_time_sec == pro_clk_al_sec)
    || ((pro_clk_al_sec & 0300) == 0300))
    && ((pro_time_min == pro_clk_al_min)
    || ((pro_clk_al_min & 0300) == 0300))
    && ((pro_time_hour == pro_clk_al_hour)
    || ((pro_clk_al_hour & 0300) == 0300)))
 {
   pro_clk_csr2 = pro_clk_csr2 | 0040;
   if ((pro_clk_csr1 & 0040) != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0200;
     pro_int_set(0x0080);
   }
 }
}

canonical_original_code:
void pro_clk_uf_eq()
{
 pro_time_update();
 pro_clk_csr0 = pro_clk_csr0 & ~0200;
 pro_clk_csr2 = pro_clk_csr2 | 0020;
 if ((pro_clk_csr1 & 0020) != 0)
 {
   pro_clk_csr2 = pro_clk_csr2 | 0200;
   pro_int_set(0x0080);
 }
 if (((pro_time_sec == pro_clk_al_sec)
    || ((pro_clk_al_sec & 0300) == 0300))
    && ((pro_time_min == pro_clk_al_min)
    || ((pro_clk_al_min & 0300) == 0300))
    && ((pro_time_hour == pro_clk_al_hour)
    || ((pro_clk_al_hour & 0300) == 0300)))
 {
   pro_clk_csr2 = pro_clk_csr2 | 0040;
   if ((pro_clk_csr1 & 0040) != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0200;
     pro_int_set(0x0080);
   }
 }
}


decompiled_code:
__int64 pro_clk_eq()
{
int v0; // eax
int v2; // er12
__int64 v3; // rax
int v4; // edx
__int64 v5; // rax
int v6; // edx
__int64 v7; // r8
int v8; // edx
int v9; // edx

if ( pro_clk_realtime )
{
v2 = pro_clk_freq;
v3 = pro_time_get();
v5 = bigtime_mul(v3, v4, v2);
dword_8D0 = v6;
pro_time_current = v5;
pro_time_tmp = bigtime_sub(v5, v6, pro_time_start, dword_8E0);
dword_8C0 = v8;
pro_clk_numint = HIDWORD(pro_time_tmp) + 100000 * pro_time_tmp;
if ( pro_int_throttle && (pro_clk_csr2 & 0x40) != 0 && pro_int_irr < 0
|| HIDWORD(pro_time_tmp) + 100000 * (int)pro_time_tmp <= 0 )
{
return pro_clk_sched();
}
pro_time_start = bigtime_add_constprop_0(v7, dword_8E0);
dword_8E0 = v9;
if ( !pro_clk_rs )
goto LABEL_7;
goto LABEL_5;
}
if ( sim_gtime() > 6000000.0 )
pro_clk_realtime = 1;
if ( pro_clk_rs )
{
LABEL_5:
v0 = pro_clk_csr2;
pro_clk_csr2 |= 0x40u;
if ( (pro_clk_csr1 & 0x40) != 0 )
{
LOBYTE(v0) = v0 | 0xC0;
pro_clk_csr2 = v0;
pro_int_set(128LL);
}
}
LABEL_7:
if ( ++pro_clk_int_cnt < pro_clk_freq )
return pro_clk_sched();
pro_clk_int_cnt = 0;
if ( (pro_clk_csr1 & 0x80u) != 0 )
return pro_clk_sched();
pro_clk_csr0 |= 0x80u;
pro_clk_uf_sched();
return pro_clk_sched();
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v2; // er12
__int64 v3; // rax
int v4; // edx
__int64 v5; // rax
int v6; // edx
__int64 v7; // r8
int v8; // edx
int v9; // edx

if ( pro_clk_realtime )
{
v2 = pro_clk_freq;
v3 = func3();
v5 = func1(v3, v4, v2);
dword_8D0 = v6;
pro_time_current = v5;
pro_time_tmp = func0(v5, v6, pro_time_start, dword_8E0);
dword_8C0 = v8;
pro_clk_numint = HIDWORD(pro_time_tmp) + 100000 * pro_time_tmp;
if ( pro_int_throttle && (pro_clk_csr2 & 0x40) != 0 && pro_int_irr < 0
|| HIDWORD(pro_time_tmp) + 100000 * (int)pro_time_tmp <= 0 )
{
return func5();
}
pro_time_start = func6(v7, dword_8E0);
dword_8E0 = v9;
if ( !pro_clk_rs )
goto LABEL_7;
goto LABEL_5;
}
if ( sim_gtime() > 6000000.0 )
pro_clk_realtime = 1;
if ( pro_clk_rs )
{
LABEL_5:
v0 = pro_clk_csr2;
pro_clk_csr2 |= 0x40u;
if ( (pro_clk_csr1 & 0x40) != 0 )
{
LOBYTE(v0) = v0 | 0xC0;
pro_clk_csr2 = v0;
pro_int_set(128LL);
}
}
LABEL_7:
if ( ++pro_clk_int_cnt < pro_clk_freq )
return func5();
pro_clk_int_cnt = 0;
if ( (pro_clk_csr1 & 0x80u) != 0 )
return func5();
pro_clk_csr0 |= 0x80u;
func4();
return func5();
}

original_code:
void pro_clk_eq ()
{
int set_int;
 if (pro_clk_realtime == 0)
 {
   set_int = 1;
   if (sim_gtime() > 6000000)
     pro_clk_realtime = 1;
 }
 else
 {
   pro_time_current = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_time_tmp = bigtime_sub(pro_time_current, pro_time_start);
   pro_clk_numint = pro_time_tmp.hi * 100000 + pro_time_tmp.mid;
   if (pro_int_throttle && ((pro_clk_csr2 & 0100) != 0)
      && ((pro_int_irr[(0x0080 >> 8) & 0377] & (0x0080 & 0377)) != 0))
     set_int = 0;
   else
   if (pro_clk_numint < 1)
     set_int = 0;
   else
   {
     set_int = 1;
     pro_time_start = bigtime_add(pro_time_start, 100000);
   }
 }
 if (set_int == 1)
 {
   if (pro_clk_rs != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0100;
     if ((pro_clk_csr1 & 0100) != 0)
     {
       pro_clk_csr2 = pro_clk_csr2 | 0200;
       pro_int_set(0x0080);
     }
   }
   pro_clk_int_cnt++;
   if (pro_clk_int_cnt >= pro_clk_freq)
   {
     pro_clk_int_cnt = 0;
     if ((pro_clk_csr1 & 0200) == 0)
     {
       pro_clk_csr0 = pro_clk_csr0 | 0200;
       pro_clk_uf_sched ();
     }
   }
 }
 pro_clk_sched();
}

canonical_original_code:
void pro_clk_eq()
{
int set_int;
 if (pro_clk_realtime == 0)
 {
   set_int = 1;
   if (sim_gtime() > 6000000)
     pro_clk_realtime = 1;
 }
 else
 {
   pro_time_current = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_time_tmp = bigtime_sub(pro_time_current, pro_time_start);
   pro_clk_numint = pro_time_tmp.hi * 100000 + pro_time_tmp.mid;
   if (pro_int_throttle && ((pro_clk_csr2 & 0100) != 0)
      && ((pro_int_irr[(0x0080 >> 8) & 0377] & (0x0080 & 0377)) != 0))
     set_int = 0;
   else
   if (pro_clk_numint < 1)
     set_int = 0;
   else
   {
     set_int = 1;
     pro_time_start = bigtime_add(pro_time_start, 100000);
   }
 }
 if (set_int == 1)
 {
   if (pro_clk_rs != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0100;
     if ((pro_clk_csr1 & 0100) != 0)
     {
       pro_clk_csr2 = pro_clk_csr2 | 0200;
       pro_int_set(0x0080);
     }
   }
   pro_clk_int_cnt++;
   if (pro_clk_int_cnt >= pro_clk_freq)
   {
     pro_clk_int_cnt = 0;
     if ((pro_clk_csr1 & 0200) == 0)
     {
       pro_clk_csr0 = pro_clk_csr0 | 0200;
       pro_clk_uf_sched ();
     }
   }
 }
 pro_clk_sched();
}


decompiled_code:
__int64 __fastcall pro_clk_rd(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // edx

switch ( a1 & 0x3FFFFE )
{
case 0x3FF600:
result = (unsigned int)pro_time_sec;
break;
case 0x3FF602:
result = (unsigned int)pro_clk_al_sec;
break;
case 0x3FF604:
result = (unsigned int)pro_time_min;
break;
case 0x3FF606:
result = (unsigned int)pro_clk_al_min;
break;
case 0x3FF608:
result = (unsigned int)pro_time_hour;
break;
case 0x3FF60A:
result = (unsigned int)pro_clk_al_hour;
break;
case 0x3FF60C:
result = (unsigned int)(*(_DWORD *)(pro_time + 24) + 1);
break;
case 0x3FF60E:
result = *(unsigned int *)(pro_time + 12);
break;
case 0x3FF610:
result = (unsigned int)(*(_DWORD *)(pro_time + 16) + 1);
break;
case 0x3FF612:
result = (unsigned int)pro_force_year;
if ( pro_force_year < 0 )
result = (unsigned int)(*(_DWORD *)(pro_time + 20) % 100);
break;
case 0x3FF614:
result = (unsigned int)pro_clk_csr0;
break;
case 0x3FF616:
result = (unsigned int)pro_clk_csr1;
break;
case 0x3FF618:
result = (unsigned int)pro_clk_csr2;
v3 = pro_clk_csr2;
LOBYTE(v3) = pro_clk_csr2 & 0xF;
pro_clk_csr2 = v3;
break;
case 0x3FF61A:
result = (unsigned int)pro_clk_csr3;
v2 = pro_clk_csr3;
LOBYTE(v2) = pro_clk_csr3 | 0x80;
pro_clk_csr3 = v2;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 & 0x3FFFFE )
{
case 0x3FF600:
result = (unsigned int)pro_time_sec;
break;
case 0x3FF602:
result = (unsigned int)pro_clk_al_sec;
break;
case 0x3FF604:
result = (unsigned int)pro_time_min;
break;
case 0x3FF606:
result = (unsigned int)pro_clk_al_min;
break;
case 0x3FF608:
result = (unsigned int)pro_time_hour;
break;
case 0x3FF60A:
result = (unsigned int)pro_clk_al_hour;
break;
case 0x3FF60C:
result = (unsigned int)(*(_DWORD *)(pro_time + 24) + 1);
break;
case 0x3FF60E:
result = *(unsigned int *)(pro_time + 12);
break;
case 0x3FF610:
result = (unsigned int)(*(_DWORD *)(pro_time + 16) + 1);
break;
case 0x3FF612:
result = (unsigned int)pro_force_year;
if ( pro_force_year < 0 )
result = (unsigned int)(*(_DWORD *)(pro_time + 20) % 100);
break;
case 0x3FF614:
result = (unsigned int)pro_clk_csr0;
break;
case 0x3FF616:
result = (unsigned int)pro_clk_csr1;
break;
case 0x3FF618:
result = (unsigned int)pro_clk_csr2;
v3 = pro_clk_csr2;
LOBYTE(v3) = pro_clk_csr2 & 0xF;
pro_clk_csr2 = v3;
break;
case 0x3FF61A:
result = (unsigned int)pro_clk_csr3;
v2 = pro_clk_csr3;
LOBYTE(v2) = pro_clk_csr3 | 0x80;
pro_clk_csr3 = v2;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int pro_clk_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017773000:
     data = pro_time_sec;
     break;
   case 017773002:
     data = pro_clk_al_sec;
     break;
   case 017773004:
     data = pro_time_min;
     break;
   case 017773006:
     data = pro_clk_al_min;
     break;
   case 017773010:
     data = pro_time_hour;
     break;
   case 017773012:
     data = pro_clk_al_hour;
     break;
   case 017773014:
     data = pro_time->tm_wday + 1;
     break;
   case 017773016:
     data = pro_time->tm_mday;
     break;
   case 017773020:
     data = pro_time->tm_mon + 1;
     break;
   case 017773022:
     if (pro_force_year > -1)
       data = pro_force_year;
     else
       data = pro_time->tm_year % 100;
     break;
   case 017773024:
     data = pro_clk_csr0;
     break;
   case 017773026:
     data = pro_clk_csr1;
     break;
   case 017773030:
     data = pro_clk_csr2;
     pro_clk_csr2 = pro_clk_csr2 & ~(0200 | 0100
                                    | 0040 | 0020);
     break;
   case 017773032:
     data = pro_clk_csr3;
     pro_clk_csr3 = pro_clk_csr3 | 0200;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_clk_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017773000:
     data = pro_time_sec;
     break;
   case 017773002:
     data = pro_clk_al_sec;
     break;
   case 017773004:
     data = pro_time_min;
     break;
   case 017773006:
     data = pro_clk_al_min;
     break;
   case 017773010:
     data = pro_time_hour;
     break;
   case 017773012:
     data = pro_clk_al_hour;
     break;
   case 017773014:
     data = pro_time->tm_wday + 1;
     break;
   case 017773016:
     data = pro_time->tm_mday;
     break;
   case 017773020:
     data = pro_time->tm_mon + 1;
     break;
   case 017773022:
     if (pro_force_year > -1)
       data = pro_force_year;
     else
       data = pro_time->tm_year % 100;
     break;
   case 017773024:
     data = pro_clk_csr0;
     break;
   case 017773026:
     data = pro_clk_csr1;
     break;
   case 017773030:
     data = pro_clk_csr2;
     pro_clk_csr2 = pro_clk_csr2 & ~(0200 | 0100
                                    | 0040 | 0020);
     break;
   case 017773032:
     data = pro_clk_csr3;
     pro_clk_csr3 = pro_clk_csr3 | 0200;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

variable_types: pa int

variable_types: data int

return_type: int


decompiled_code:
char __fastcall pro_clk_wr(unsigned __int8 a1, int a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = (a2 & 0xFE) - 2;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF602:
v3 = pro_clk_al_sec;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_al_sec = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_al_sec = v3 | a1;
}
break;
case 0x3FF606:
v3 = pro_clk_al_min;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_al_min = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_al_min = v3 | a1;
}
break;
case 0x3FF60A:
v3 = pro_clk_al_hour;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_al_hour = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_al_hour = v3 | a1;
}
break;
case 0x3FF614:
v3 = pro_clk_csr0;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
v3 = a1 & 0x7F | pro_clk_csr0 & 0xFFFFFF80;
pro_clk_csr0 = v3;
}
else
{
LOBYTE(v3) = pro_clk_csr0 & 0x80;
pro_clk_csr0 = pro_clk_csr0 & 0xFFFFFF80 | a1 & 0x7F;
}
break;
case 0x3FF616:
v3 = pro_clk_csr1;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_csr1 = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_csr1 = v3 | a1;
}
break;
default:
return v3;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func10(unsigned __int8 a1, int a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = (a2 & 0xFE) - 2;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF602:
v3 = pro_clk_al_sec;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_al_sec = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_al_sec = v3 | a1;
}
break;
case 0x3FF606:
v3 = pro_clk_al_min;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_al_min = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_al_min = v3 | a1;
}
break;
case 0x3FF60A:
v3 = pro_clk_al_hour;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_al_hour = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_al_hour = v3 | a1;
}
break;
case 0x3FF614:
v3 = pro_clk_csr0;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
v3 = a1 & 0x7F | pro_clk_csr0 & 0xFFFFFF80;
pro_clk_csr0 = v3;
}
else
{
LOBYTE(v3) = pro_clk_csr0 & 0x80;
pro_clk_csr0 = pro_clk_csr0 & 0xFFFFFF80 | a1 & 0x7F;
}
break;
case 0x3FF616:
v3 = pro_clk_csr1;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_clk_csr1 = v3;
}
else
{
LOBYTE(v3) = 0;
pro_clk_csr1 = v3 | a1;
}
break;
default:
return v3;
}
return v3;
}

variable_types: access int


decompiled_code:
__int64 pro_clk_reset()
{
pro_clk_csr0 = 0;
pro_clk_csr1 = 6;
pro_clk_csr2 = 0;
pro_clk_csr3 = 128;
pro_clk_al_sec = 0;
pro_clk_al_min = 0;
pro_clk_al_hour = 0;
pro_clk_realtime = 0;
pro_clk_numint = 0;
pro_clk_freq = 0;
pro_clk_int_cnt = 0;
pro_time_start = 0LL;
dword_8E0 = 0;
pro_time_current = 0LL;
dword_8D0 = 0;
pro_time_update();
pro_clk_rs = -1;
return pro_clk_sched();
}

canonical_decompiled_code:
__int64 func11()
{
pro_clk_csr0 = 0;
pro_clk_csr1 = 6;
pro_clk_csr2 = 0;
pro_clk_csr3 = 128;
pro_clk_al_sec = 0;
pro_clk_al_min = 0;
pro_clk_al_hour = 0;
pro_clk_realtime = 0;
pro_clk_numint = 0;
pro_clk_freq = 0;
pro_clk_int_cnt = 0;
pro_time_start = 0LL;
dword_8E0 = 0;
pro_time_current = 0LL;
dword_8D0 = 0;
func2();
pro_clk_rs = -1;
return func5();
}

original_code:
void pro_clk_reset ()
{
 pro_clk_csr0 = 0000;
 pro_clk_csr1 = 0004 | 0002;
 pro_clk_csr2 = 0000;
 pro_clk_csr3 = 0200;
 pro_clk_al_sec = 0;
 pro_clk_al_min = 0;
 pro_clk_al_hour = 0;
 pro_clk_realtime = 0;
 pro_clk_numint = 0;
 pro_clk_freq = 0;
 pro_clk_int_cnt = 0;
 pro_time_start.hi = 0;
 pro_time_start.mid = 0;
 pro_time_start.lo = 0;
 pro_time_current.hi = 0;
 pro_time_current.mid = 0;
 pro_time_current.lo = 0;
 pro_time_update();
 pro_clk_rs = -1;
 pro_clk_sched();
}

canonical_original_code:
void pro_clk_reset()
{
 pro_clk_csr0 = 0000;
 pro_clk_csr1 = 0004 | 0002;
 pro_clk_csr2 = 0000;
 pro_clk_csr3 = 0200;
 pro_clk_al_sec = 0;
 pro_clk_al_min = 0;
 pro_clk_al_hour = 0;
 pro_clk_realtime = 0;
 pro_clk_numint = 0;
 pro_clk_freq = 0;
 pro_clk_int_cnt = 0;
 pro_time_start.hi = 0;
 pro_time_start.mid = 0;
 pro_time_start.lo = 0;
 pro_time_current.hi = 0;
 pro_time_current.mid = 0;
 pro_time_current.lo = 0;
 pro_time_update();
 pro_clk_rs = -1;
 pro_clk_sched();
}


decompiled_code:
__int64 pro_null_get()
{
return 256LL;
}

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

original_code:
int pro_null_get (int dev)
{
 return 256;
}

canonical_original_code:
int pro_null_get(int dev)
{
 return 256;
}

variable_types: dev int


decompiled_code:
__int64 pro_null_put()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
int pro_null_put (int dev, int schar)
{
 return 1;
}

canonical_original_code:
int pro_null_put(int dev, int schar)
{
 return 1;
}

variable_types: schar int


decompiled_code:
void pro_null_ctrl_put()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void pro_null_ctrl_put (int dev, struct serctrl *sctrl)
{
}

canonical_original_code:
void pro_null_ctrl_put(int dev, struct serctrl *sctrl)
{
}

variable_types: struct serctrl { int stop; int parity; int penable; int cs; int ibaud; int obaud; int dtr; int dsr; int rts; int cts; int ri; int cd; int ibrk; int obrk; int perror; } *


decompiled_code:
void pro_null_reset()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void pro_null_reset (int dev, int portnum)
{
}

canonical_original_code:
void pro_null_reset(int dev, int portnum)
{
}

variable_types: portnum int


decompiled_code:
void pro_null_exit()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void pro_null_exit (int dev)
{
}

canonical_original_code:
void pro_null_exit(int dev)
{
}


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

v1 = pro_lk201_fifo_h;
v2 = pro_lk201_fifo_h;
pro_lk201_fifo[pro_lk201_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v2 == 1023 )
result = 0LL;
pro_lk201_fifo_h = result;
return result;
}

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

v1 = pro_lk201_fifo_h;
v2 = pro_lk201_fifo_h;
pro_lk201_fifo[pro_lk201_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v2 == 1023 )
result = 0LL;
pro_lk201_fifo_h = result;
return result;
}

original_code:
static void pro_lk201_fifo_put (int key)
{
 pro_lk201_fifo[pro_lk201_fifo_h] = key;
 pro_lk201_fifo_h++;
 if (pro_lk201_fifo_h == 1024)
   pro_lk201_fifo_h = 0;
}

canonical_original_code:
static void pro_lk201_fifo_put(int key)
{
 pro_lk201_fifo[pro_lk201_fifo_h] = key;
 pro_lk201_fifo_h++;
 if (pro_lk201_fifo_h == 1024)
   pro_lk201_fifo_h = 0;
}

variable_types: key int


decompiled_code:
__int64 pro_lk201_fifo_get()
{
unsigned int v0; // er8
int v1; // eax

v0 = 256;
if ( pro_lk201_fifo_h != pro_lk201_fifo_t )
{
v0 = pro_lk201_fifo[pro_lk201_fifo_t];
v1 = 0;
if ( pro_lk201_fifo_t != 1023 )
v1 = pro_lk201_fifo_t + 1;
pro_lk201_fifo_t = v1;
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er8
int v1; // eax

v0 = 256;
if ( pro_lk201_fifo_h != pro_lk201_fifo_t )
{
v0 = pro_lk201_fifo[pro_lk201_fifo_t];
v1 = 0;
if ( pro_lk201_fifo_t != 1023 )
v1 = pro_lk201_fifo_t + 1;
pro_lk201_fifo_t = v1;
}
return v0;
}

original_code:
static int pro_lk201_fifo_get ()
{
 int key;
 if (pro_lk201_fifo_h == pro_lk201_fifo_t)
   key = 256;
 else
 {
   key = pro_lk201_fifo[pro_lk201_fifo_t];
   pro_lk201_fifo_t++;
   if (pro_lk201_fifo_t == 1024)
     pro_lk201_fifo_t = 0;
 }
 return key;
}

canonical_original_code:
static int pro_lk201_fifo_get()
{
 int key;
 if (pro_lk201_fifo_h == pro_lk201_fifo_t)
   key = 256;
 else
 {
   key = pro_lk201_fifo[pro_lk201_fifo_t];
   pro_lk201_fifo_t++;
   if (pro_lk201_fifo_t == 1024)
     pro_lk201_fifo_t = 0;
 }
 return key;
}


decompiled_code:
void __fastcall pro_lk201_ctrl_get(__int64 a1, __int64 a2)
{
*(_DWORD *)(a2 + 28) = 1;
}

original_code:
void pro_lk201_ctrl_get (int dev, struct serctrl *sctrl)
{
 sctrl->dsr = 1;
}

canonical_original_code:
void pro_lk201_ctrl_get(int dev, struct serctrl *sctrl)
{
 sctrl->dsr = 1;
}

user_defined_types: struct serctrl { int stop; int parity; int penable; int cs; int ibaud; int obaud; int dtr; int dsr; int rts; int cts; int ri; int cd; int ibrk; int obrk; int perror; }


decompiled_code:
void pro_lk201_ctrl_put()
{
;
}

original_code:
void pro_lk201_ctrl_put (int dev, struct serctrl *sctrl)
{
}

canonical_original_code:
void pro_lk201_ctrl_put(int dev, struct serctrl *sctrl)
{
}


decompiled_code:
void pro_lk201_reset()
{
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
pro_lk201_locked = 0;
pro_lk201_bell_dis = 0;
pro_lk201_param = 0;
pro_lk201_last_cmd = -1;
pro_lk201_fifo_h = 0;
pro_lk201_fifo_t = 0;
}

canonical_decompiled_code:
void func4()
{
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
pro_lk201_locked = 0;
pro_lk201_bell_dis = 0;
pro_lk201_param = 0;
pro_lk201_last_cmd = -1;
pro_lk201_fifo_h = 0;
pro_lk201_fifo_t = 0;
}

original_code:
void pro_lk201_reset (int dev, int portnum)
{
 pro_lk201_shift = 0;
 pro_lk201_ctrl = 0;
 pro_lk201_locked = 0;
 pro_lk201_bell_dis = 0;
 pro_lk201_click_dis = 0;
 pro_lk201_param = 0;
 pro_lk201_last_cmd = -1;
 pro_lk201_fifo_h = 0;
 pro_lk201_fifo_t = 0;
}

canonical_original_code:
void pro_lk201_reset(int dev, int portnum)
{
 pro_lk201_shift = 0;
 pro_lk201_ctrl = 0;
 pro_lk201_locked = 0;
 pro_lk201_bell_dis = 0;
 pro_lk201_click_dis = 0;
 pro_lk201_param = 0;
 pro_lk201_last_cmd = -1;
 pro_lk201_fifo_h = 0;
 pro_lk201_fifo_t = 0;
}


decompiled_code:
void pro_lk201_exit()
{
;
}

original_code:
void pro_lk201_exit (int dev)
{
}

canonical_original_code:
void pro_lk201_exit(int dev)
{
}


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

if ( pro_lk201_locked )
return 256LL;
result = pro_lk201_fifo_get();
if ( (_DWORD)result == 256 )
{
result = pro_keyboard_get();
switch ( (_DWORD)result )
{
case 0x100:
result = 256LL;
break;
case 0xAE:
pro_lk201_shift = 1;
break;
case 0xAF:
pro_lk201_ctrl = 1;
break;
case 0xB3:
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
break;
case 0xED:
if ( pro_lk201_shift == 1 )
result = 201LL;
break;
case 0xE8:
if ( pro_lk201_shift == 1 )
{
pro_lk201_fifo_put(201);
pro_lk201_fifo_put(174);
result = 179LL;
}
break;
case 0x57:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(161);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x59:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(162);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x5A:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(163);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x58:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(164);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x64:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(128);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x65:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(129);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x66:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(130);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
default:
if ( (_DWORD)result == 103 && pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(131);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
}
}
return result;
}

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

if ( pro_lk201_locked )
return 256LL;
result = func1();
if ( (_DWORD)result == 256 )
{
result = pro_keyboard_get();
switch ( (_DWORD)result )
{
case 0x100:
result = 256LL;
break;
case 0xAE:
pro_lk201_shift = 1;
break;
case 0xAF:
pro_lk201_ctrl = 1;
break;
case 0xB3:
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
break;
case 0xED:
if ( pro_lk201_shift == 1 )
result = 201LL;
break;
case 0xE8:
if ( pro_lk201_shift == 1 )
{
func0(201);
func0(174);
result = 179LL;
}
break;
case 0x57:
if ( pro_lk201_ctrl == 1 )
{
func0(161);
func0(175);
result = 179LL;
}
break;
case 0x59:
if ( pro_lk201_ctrl == 1 )
{
func0(162);
func0(175);
result = 179LL;
}
break;
case 0x5A:
if ( pro_lk201_ctrl == 1 )
{
func0(163);
func0(175);
result = 179LL;
}
break;
case 0x58:
if ( pro_lk201_ctrl == 1 )
{
func0(164);
func0(175);
result = 179LL;
}
break;
case 0x64:
if ( pro_lk201_ctrl == 1 )
{
func0(128);
func0(175);
result = 179LL;
}
break;
case 0x65:
if ( pro_lk201_ctrl == 1 )
{
func0(129);
func0(175);
result = 179LL;
}
break;
case 0x66:
if ( pro_lk201_ctrl == 1 )
{
func0(130);
func0(175);
result = 179LL;
}
break;
default:
if ( (_DWORD)result == 103 && pro_lk201_ctrl == 1 )
{
func0(131);
func0(175);
result = 179LL;
}
break;
}
}
return result;
}


decompiled_code:
__int64 __fastcall pro_lk201_put(__int64 a1, int a2)
{
if ( pro_lk201_param )
{
if ( pro_lk201_last_cmd == 35 )
{
pro_lk201_bell_dis = 0;
pro_keyboard_bell_vol(a2 & 7);
pro_lk201_last_cmd = -1;
}
}
else
{
pro_lk201_last_cmd = -1;
if ( a2 > 171 )
{
if ( a2 == 253 )
{
pro_lk201_fifo_put(1);
pro_lk201_fifo_put(0);
pro_lk201_fifo_put(0);
pro_lk201_fifo_put(0);
goto LABEL_6;
}
if ( a2 <= 253 )
{
if ( a2 == 225 )
{
pro_keyboard_auto_off();
goto LABEL_6;
}
if ( a2 == 227 )
{
pro_keyboard_auto_on();
goto LABEL_6;
}
}
else if ( a2 == 254 )
{
pro_lk201_fifo_put(182);
goto LABEL_6;
}
goto LABEL_17;
}
if ( a2 <= 136 )
{
if ( a2 == 27 )
{
pro_keyboard_click_on();
goto LABEL_6;
}
LABEL_17:
pro_lk201_last_cmd = a2;
goto LABEL_6;
}
switch ( a2 )
{
case 137:
pro_lk201_locked = 1;
pro_lk201_fifo_put(183);
break;
case 139:
pro_lk201_locked = 0;
break;
case 153:
pro_keyboard_click_off();
break;
case 161:
pro_lk201_bell_dis = 1;
break;
case 167:
if ( !pro_lk201_bell_dis )
pro_keyboard_bell();
break;
case 171:
pro_lk201_fifo_put(1);
pro_lk201_fifo_put(0);
break;
default:
goto LABEL_17;
}
}
LABEL_6:
pro_lk201_param = (a2 & 0x80) == 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
if ( pro_lk201_param )
{
if ( pro_lk201_last_cmd == 35 )
{
pro_lk201_bell_dis = 0;
pro_keyboard_bell_vol(a2 & 7);
pro_lk201_last_cmd = -1;
}
}
else
{
pro_lk201_last_cmd = -1;
if ( a2 > 171 )
{
if ( a2 == 253 )
{
func0(1);
func0(0);
func0(0);
func0(0);
goto LABEL_6;
}
if ( a2 <= 253 )
{
if ( a2 == 225 )
{
pro_keyboard_auto_off();
goto LABEL_6;
}
if ( a2 == 227 )
{
pro_keyboard_auto_on();
goto LABEL_6;
}
}
else if ( a2 == 254 )
{
func0(182);
goto LABEL_6;
}
goto LABEL_17;
}
if ( a2 <= 136 )
{
if ( a2 == 27 )
{
pro_keyboard_click_on();
goto LABEL_6;
}
LABEL_17:
pro_lk201_last_cmd = a2;
goto LABEL_6;
}
switch ( a2 )
{
case 137:
pro_lk201_locked = 1;
func0(183);
break;
case 139:
pro_lk201_locked = 0;
break;
case 153:
pro_keyboard_click_off();
break;
case 161:
pro_lk201_bell_dis = 1;
break;
case 167:
if ( !pro_lk201_bell_dis )
pro_keyboard_bell();
break;
case 171:
func0(1);
func0(0);
break;
default:
goto LABEL_17;
}
}
LABEL_6:
pro_lk201_param = (a2 & 0x80) == 0;
return 1LL;
}

original_code:
int pro_lk201_put (int dev, int key)
{
 if (pro_lk201_param == 0)
 {
   pro_lk201_last_cmd = -1;
   switch(key)
   {
     case 139:
       pro_lk201_locked = 0;
       break;
     case 137:
       pro_lk201_locked = 1;
       pro_lk201_fifo_put(183);
       break;
     case 27:
       pro_lk201_click_dis = 0;
       pro_keyboard_click_on();
       break;
     case 153:
       pro_lk201_click_dis = 1;
       pro_keyboard_click_off();
       break;
     case 161:
       pro_lk201_bell_dis = 1;
       break;
     case 167:
       if (pro_lk201_bell_dis == 0)
         pro_keyboard_bell();
       break;
     case 225:
       pro_keyboard_auto_off();
       break;
     case 227:
       pro_keyboard_auto_on();
       break;
     case 171:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       break;
     case 253:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       break;
     case 254:
       pro_lk201_fifo_put(0xb6);
       break;
     default:
       pro_lk201_last_cmd = key;
       break;
   }
 }
 else
 {
   switch(pro_lk201_last_cmd)
   {
     case 35:
       pro_lk201_bell_dis = 0;
       pro_keyboard_bell_vol(key & 0x07);
       pro_lk201_last_cmd = -1;
       break;
     default:
       break;
   }
 }
 if ((key & 0x80) != 0)
   pro_lk201_param = 0;
 else
   pro_lk201_param = 1;
 return 1;
}

canonical_original_code:
int pro_lk201_put(int dev, int key)
{
 if (pro_lk201_param == 0)
 {
   pro_lk201_last_cmd = -1;
   switch(key)
   {
     case 139:
       pro_lk201_locked = 0;
       break;
     case 137:
       pro_lk201_locked = 1;
       pro_lk201_fifo_put(183);
       break;
     case 27:
       pro_lk201_click_dis = 0;
       pro_keyboard_click_on();
       break;
     case 153:
       pro_lk201_click_dis = 1;
       pro_keyboard_click_off();
       break;
     case 161:
       pro_lk201_bell_dis = 1;
       break;
     case 167:
       if (pro_lk201_bell_dis == 0)
         pro_keyboard_bell();
       break;
     case 225:
       pro_keyboard_auto_off();
       break;
     case 227:
       pro_keyboard_auto_on();
       break;
     case 171:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       break;
     case 253:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       break;
     case 254:
       pro_lk201_fifo_put(0xb6);
       break;
     default:
       pro_lk201_last_cmd = key;
       break;
   }
 }
 else
 {
   switch(pro_lk201_last_cmd)
   {
     case 35:
       pro_lk201_bell_dis = 0;
       pro_keyboard_bell_vol(key & 0x07);
       pro_lk201_last_cmd = -1;
       break;
     default:
       break;
   }
 }
 if ((key & 0x80) != 0)
   pro_lk201_param = 0;
 else
   pro_lk201_param = 1;
 return 1;
}


decompiled_code:
__int64 __fastcall pro_digipad_fifo_put(int a1)
{
__int64 result; // rax
bool v2; // zf
unsigned int v3; // edx

result = (unsigned int)pro_digipad_fifo_h;
if ( pro_digipad_fifo_h - pro_digipad_fifo_t <= 1023 )
{
v2 = pro_digipad_fifo_h == 1023;
pro_digipad_fifo[pro_digipad_fifo_h] = a1;
v3 = result + 1;
result = 0LL;
if ( !v2 )
result = v3;
pro_digipad_fifo_h = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
bool v2; // zf
unsigned int v3; // edx

result = (unsigned int)pro_digipad_fifo_h;
if ( pro_digipad_fifo_h - pro_digipad_fifo_t <= 1023 )
{
v2 = pro_digipad_fifo_h == 1023;
pro_digipad_fifo[pro_digipad_fifo_h] = a1;
v3 = result + 1;
result = 0LL;
if ( !v2 )
result = v3;
pro_digipad_fifo_h = result;
}
return result;
}

original_code:
static void pro_digipad_fifo_put (int schar)
{
int fullness;
 fullness = pro_digipad_fifo_h - pro_digipad_fifo_t;
 if (fullness < 0)
   fullness += 1024;
 if (fullness < 1024)
 {
   pro_digipad_fifo[pro_digipad_fifo_h] = schar;
   pro_digipad_fifo_h++;
   if (pro_digipad_fifo_h == 1024)
     pro_digipad_fifo_h = 0;
 }
}

canonical_original_code:
static void pro_digipad_fifo_put(int schar)
{
int fullness;
 fullness = pro_digipad_fifo_h - pro_digipad_fifo_t;
 if (fullness < 0)
   fullness += 1024;
 if (fullness < 1024)
 {
   pro_digipad_fifo[pro_digipad_fifo_h] = schar;
   pro_digipad_fifo_h++;
   if (pro_digipad_fifo_h == 1024)
     pro_digipad_fifo_h = 0;
 }
}

variable_types: fullness int


decompiled_code:
void pro_digipad_ctrl_put()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void pro_digipad_ctrl_put (int dev, struct serctrl *sctrl)
{
}

canonical_original_code:
void pro_digipad_ctrl_put(int dev, struct serctrl *sctrl)
{
}


decompiled_code:
void pro_digipad_reset()
{
;
}

original_code:
void pro_digipad_reset (int dev, int portnum)
{
}

canonical_original_code:
void pro_digipad_reset(int dev, int portnum)
{
}


decompiled_code:
void pro_digipad_exit()
{
;
}

original_code:
void pro_digipad_exit (int dev)
{
}

canonical_original_code:
void pro_digipad_exit(int dev)
{
}


decompiled_code:
__int64 pro_digipad_coord()
{
int v0; // edi
int v1; // er11
int v2; // er9
int v3; // er10
int v4; // er8

v0 = pro_mouse_l == 0 ? 64 : 96;
if ( pro_mouse_m )
v0 = (pro_mouse_l == 0 ? 64 : 96) | 0x10;
if ( pro_mouse_r )
v0 |= 8u;
if ( !pro_mouse_in )
v0 |= 4u;
LOBYTE(v0) = v0 | 0x80;
pro_digipad_fifo_put(v0);
pro_digipad_fifo_put(v1);
pro_digipad_fifo_put(v2);
pro_digipad_fifo_put(v3);
return pro_digipad_fifo_put(v4);
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // edi
int v1; // er11
int v2; // er9
int v3; // er10
int v4; // er8

v0 = pro_mouse_l == 0 ? 64 : 96;
if ( pro_mouse_m )
v0 = (pro_mouse_l == 0 ? 64 : 96) | 0x10;
if ( pro_mouse_r )
v0 |= 8u;
if ( !pro_mouse_in )
v0 |= 4u;
LOBYTE(v0) = v0 | 0x80;
func0(v0);
func0(v1);
func0(v2);
func0(v3);
return func0(v4);
}

original_code:
void pro_digipad_coord ()
{
int mb, tx, ty;
 if (pro_digipad_remote)
 {
   tx = 2*(pro_mouse_x-32);
   ty = 2100 - 2*(600*pro_mouse_y/240);
 }
 else
 {
   tx = (2200*(pro_mouse_x-32))/960;
   ty = 2200 - (600*2200*pro_mouse_y/960)/240;
 }
 if (tx < 0)
   tx = 0;
 mb = 0x40;
 if (pro_mouse_l)
   mb |= 0x20;
 if (pro_mouse_m)
   mb |= 0x10;
 if (pro_mouse_r)
   mb |= 0x08;
 if (!pro_mouse_in)
 {
   mb |= 0x04;
   tx = 0;
   ty = 0;
 }
 pro_digipad_fifo_put(mb|0x80);
 pro_digipad_fifo_put((tx&0x3f)|0x80);
 pro_digipad_fifo_put(((tx>>6)&0x3f)|0x80);
 pro_digipad_fifo_put((ty&0x3f)|0x80);
 pro_digipad_fifo_put(((ty>>6)&0x3f)|0x80);
}

canonical_original_code:
void pro_digipad_coord()
{
int mb; int tx; int ty;
 if (pro_digipad_remote)
 {
   tx = 2*(pro_mouse_x-32);
   ty = 2100 - 2*(600*pro_mouse_y/240);
 }
 else
 {
   tx = (2200*(pro_mouse_x-32))/960;
   ty = 2200 - (600*2200*pro_mouse_y/960)/240;
 }
 if (tx < 0)
   tx = 0;
 mb = 0x40;
 if (pro_mouse_l)
   mb |= 0x20;
 if (pro_mouse_m)
   mb |= 0x10;
 if (pro_mouse_r)
   mb |= 0x08;
 if (!pro_mouse_in)
 {
   mb |= 0x04;
   tx = 0;
   ty = 0;
 }
 pro_digipad_fifo_put(mb|0x80);
 pro_digipad_fifo_put((tx&0x3f)|0x80);
 pro_digipad_fifo_put(((tx>>6)&0x3f)|0x80);
 pro_digipad_fifo_put((ty&0x3f)|0x80);
 pro_digipad_fifo_put(((ty>>6)&0x3f)|0x80);
}

variable_types: mb int

variable_types: tx int

variable_types: ty int


decompiled_code:
__int64 pro_digipad_get()
{
int v0; // ebx
__int64 result; // rax
int v2; // edx

v0 = pro_digipad_fifo_t;
if ( !pro_digipad_suppressed )
{
if ( pro_digipad_fifo_h != pro_digipad_fifo_t && pro_digipad_enable )
goto LABEL_7;
return 256LL;
}
result = 256LL;
if ( !pro_digipad_enable )
return result;
if ( pro_mouse_x != pro_digipad_last_x
|| pro_mouse_y != pro_digipad_last_y
|| pro_mouse_l != pro_digipad_last_l
|| pro_mouse_m != pro_digipad_last_m
|| pro_mouse_r != pro_digipad_last_r
|| pro_mouse_in != pro_digipad_last_in )
{
pro_digipad_coord();
pro_digipad_last_x = pro_mouse_x;
pro_digipad_last_y = pro_mouse_y;
pro_digipad_last_l = pro_mouse_l;
pro_digipad_last_m = pro_mouse_m;
pro_digipad_last_r = pro_mouse_r;
pro_digipad_last_in = pro_mouse_in;
}
if ( v0 == pro_digipad_fifo_h )
return 256LL;
LABEL_7:
v2 = v0 + 1;
if ( v0 == 1023 )
v2 = 0;
result = (unsigned int)pro_digipad_fifo[v0];
pro_digipad_fifo_t = v2;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // ebx
__int64 result; // rax
int v2; // edx

v0 = pro_digipad_fifo_t;
if ( !pro_digipad_suppressed )
{
if ( pro_digipad_fifo_h != pro_digipad_fifo_t && pro_digipad_enable )
goto LABEL_7;
return 256LL;
}
result = 256LL;
if ( !pro_digipad_enable )
return result;
if ( pro_mouse_x != pro_digipad_last_x
|| pro_mouse_y != pro_digipad_last_y
|| pro_mouse_l != pro_digipad_last_l
|| pro_mouse_m != pro_digipad_last_m
|| pro_mouse_r != pro_digipad_last_r
|| pro_mouse_in != pro_digipad_last_in )
{
func5();
pro_digipad_last_x = pro_mouse_x;
pro_digipad_last_y = pro_mouse_y;
pro_digipad_last_l = pro_mouse_l;
pro_digipad_last_m = pro_mouse_m;
pro_digipad_last_r = pro_mouse_r;
pro_digipad_last_in = pro_mouse_in;
}
if ( v0 == pro_digipad_fifo_h )
return 256LL;
LABEL_7:
v2 = v0 + 1;
if ( v0 == 1023 )
v2 = 0;
result = (unsigned int)pro_digipad_fifo[v0];
pro_digipad_fifo_t = v2;
return result;
}

original_code:
int pro_digipad_get (int dev)
{
 int schar;
 if ((pro_digipad_suppressed)
    && (pro_digipad_enable)
    && ((pro_mouse_x != pro_digipad_last_x)
       || (pro_mouse_y != pro_digipad_last_y)
       || (pro_mouse_l != pro_digipad_last_l)
       || (pro_mouse_m != pro_digipad_last_m)
       || (pro_mouse_r != pro_digipad_last_r)
       || (pro_mouse_in != pro_digipad_last_in)))
 {
   pro_digipad_coord();
   pro_digipad_last_x = pro_mouse_x;
   pro_digipad_last_y = pro_mouse_y;
   pro_digipad_last_l = pro_mouse_l;
   pro_digipad_last_m = pro_mouse_m;
   pro_digipad_last_r = pro_mouse_r;
   pro_digipad_last_in = pro_mouse_in;
 }
 if ((pro_digipad_fifo_h == pro_digipad_fifo_t)
    || (!pro_digipad_enable))
   schar = 256;
 else
 {
   schar = pro_digipad_fifo[pro_digipad_fifo_t];
   pro_digipad_fifo_t++;
   if (pro_digipad_fifo_t == 1024)
     pro_digipad_fifo_t = 0;
 }
 return schar;
}

canonical_original_code:
int pro_digipad_get(int dev)
{
 int schar;
 if ((pro_digipad_suppressed)
    && (pro_digipad_enable)
    && ((pro_mouse_x != pro_digipad_last_x)
       || (pro_mouse_y != pro_digipad_last_y)
       || (pro_mouse_l != pro_digipad_last_l)
       || (pro_mouse_m != pro_digipad_last_m)
       || (pro_mouse_r != pro_digipad_last_r)
       || (pro_mouse_in != pro_digipad_last_in)))
 {
   pro_digipad_coord();
   pro_digipad_last_x = pro_mouse_x;
   pro_digipad_last_y = pro_mouse_y;
   pro_digipad_last_l = pro_mouse_l;
   pro_digipad_last_m = pro_mouse_m;
   pro_digipad_last_r = pro_mouse_r;
   pro_digipad_last_in = pro_mouse_in;
 }
 if ((pro_digipad_fifo_h == pro_digipad_fifo_t)
    || (!pro_digipad_enable))
   schar = 256;
 else
 {
   schar = pro_digipad_fifo[pro_digipad_fifo_t];
   pro_digipad_fifo_t++;
   if (pro_digipad_fifo_t == 1024)
     pro_digipad_fifo_t = 0;
 }
 return schar;
}


decompiled_code:
__int64 __fastcall pro_digipad_put(__int64 a1, int a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // edi

v2 = pro_digipad_s0;
if ( a2 == 19 )
{
pro_digipad_enable = 0;
}
else if ( a2 == 17 )
{
pro_digipad_enable = 1;
}
else
{
v4 = a2;
LOBYTE(v4) = a2 | 0x80;
pro_digipad_fifo_put(v4);
if ( a2 == 2 && pro_digipad_remote )
{
pro_digipad_coord();
}
else if ( pro_digipad_s1 == 1 )
{
if ( v2 == 82 )
{
if ( a2 == 83 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
pro_digipad_last_x = -1;
pro_digipad_last_y = -1;
pro_digipad_enable = 1;
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
}
else if ( a2 == 77 )
{
pro_digipad_remote = 1;
pro_digipad_suppressed = 0;
}
}
else if ( v2 == 83 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 1;
}
else if ( (unsigned int)(v2 - 67) <= 1 || v2 == 76 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
}
}
}
pro_digipad_s1 = v2;
result = 1LL;
pro_digipad_s0 = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // edi

v2 = pro_digipad_s0;
if ( a2 == 19 )
{
pro_digipad_enable = 0;
}
else if ( a2 == 17 )
{
pro_digipad_enable = 1;
}
else
{
v4 = a2;
LOBYTE(v4) = a2 | 0x80;
func0(v4);
if ( a2 == 2 && pro_digipad_remote )
{
func5();
}
else if ( pro_digipad_s1 == 1 )
{
if ( v2 == 82 )
{
if ( a2 == 83 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
pro_digipad_last_x = -1;
pro_digipad_last_y = -1;
pro_digipad_enable = 1;
func0(255);
func0(255);
func0(255);
func0(255);
func0(255);
}
else if ( a2 == 77 )
{
pro_digipad_remote = 1;
pro_digipad_suppressed = 0;
}
}
else if ( v2 == 83 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 1;
}
else if ( (unsigned int)(v2 - 67) <= 1 || v2 == 76 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
}
}
}
pro_digipad_s1 = v2;
result = 1LL;
pro_digipad_s0 = a2;
return result;
}

original_code:
int pro_digipad_put (int dev, int schar)
{
 if (schar == 19)
   pro_digipad_enable = 0;
 else if (schar == 17)
   pro_digipad_enable = 1;
 else
 {
   pro_digipad_fifo_put(schar|0x80);
   if ((schar == 2) && pro_digipad_remote)
     pro_digipad_coord();
   else if (pro_digipad_s1 == 1)
   {
     if ((pro_digipad_s0 == 82) && (schar == 83))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
       pro_digipad_last_x = -1;
       pro_digipad_last_y = -1;
       pro_digipad_enable = 1;
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
     }
     else if ((pro_digipad_s0 == 82) && (schar == 77))
     {
       pro_digipad_remote = 1;
       pro_digipad_suppressed = 0;
     }
     else if (pro_digipad_s0 == 83)
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 1;
     }
     else if ((pro_digipad_s0 == 67) || (pro_digipad_s0 == 68)
             || (pro_digipad_s0 == 76))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
     }
   }
 }
 pro_digipad_s1 = pro_digipad_s0;
 pro_digipad_s0 = schar;
 return 1;
}

canonical_original_code:
int pro_digipad_put(int dev, int schar)
{
 if (schar == 19)
   pro_digipad_enable = 0;
 else if (schar == 17)
   pro_digipad_enable = 1;
 else
 {
   pro_digipad_fifo_put(schar|0x80);
   if ((schar == 2) && pro_digipad_remote)
     pro_digipad_coord();
   else if (pro_digipad_s1 == 1)
   {
     if ((pro_digipad_s0 == 82) && (schar == 83))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
       pro_digipad_last_x = -1;
       pro_digipad_last_y = -1;
       pro_digipad_enable = 1;
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
     }
     else if ((pro_digipad_s0 == 82) && (schar == 77))
     {
       pro_digipad_remote = 1;
       pro_digipad_suppressed = 0;
     }
     else if (pro_digipad_s0 == 83)
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 1;
     }
     else if ((pro_digipad_s0 == 67) || (pro_digipad_s0 == 68)
             || (pro_digipad_s0 == 76))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
     }
   }
 }
 pro_digipad_s1 = pro_digipad_s0;
 pro_digipad_s0 = schar;
 return 1;
}


ttinit

decompiled_code:
__int64 ttinit()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
__m128i v2; // xmm2
speed_t v3; // eax
__int64 result; // rax

if ( tcgetattr(0, &cmdtty) < 0 )
return 47LL;
v0 = _mm_load_si128((const __m128i *)&cmdtty);
v1 = _mm_load_si128((const __m128i *)&cmdtty.c_line);
v2 = _mm_load_si128((const __m128i *)&cmdtty.c_cc[15]);
*(_QWORD *)&runtty.c_cc[31] = *(_QWORD *)&cmdtty.c_cc[31];
v3 = cmdtty.c_ospeed;
*(__m128i *)&runtty.c_iflag = v0;
runtty.c_ospeed = v3;
*(_QWORD *)&runtty.c_iflag &= 0xFFFFFFFEFFFFFEFFLL;
LOBYTE(v3) = sim_int_char;
*(__m128i *)&runtty.c_line = v1;
runtty.c_cc[0] = v3;
*(_WORD *)&runtty.c_cc[1] = 0;
result = 0LL;
*(__m128i *)&runtty.c_cc[15] = v2;
runtty.c_lflag &= 0xFFFFFFF5;
*(_QWORD *)&runtty.c_cc[8] = 0LL;
*(_DWORD *)&runtty.c_cc[3] = 0;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
__m128i v2; // xmm2
speed_t v3; // eax
__int64 result; // rax

if ( tcgetattr(0, &cmdtty) < 0 )
return 47LL;
v0 = _mm_load_si128((const __m128i *)&cmdtty);
v1 = _mm_load_si128((const __m128i *)&cmdtty.c_line);
v2 = _mm_load_si128((const __m128i *)&cmdtty.c_cc[15]);
*(_QWORD *)&runtty.c_cc[31] = *(_QWORD *)&cmdtty.c_cc[31];
v3 = cmdtty.c_ospeed;
*(__m128i *)&runtty.c_iflag = v0;
runtty.c_ospeed = v3;
*(_QWORD *)&runtty.c_iflag &= 0xFFFFFFFEFFFFFEFFLL;
LOBYTE(v3) = sim_int_char;
*(__m128i *)&runtty.c_line = v1;
runtty.c_cc[0] = v3;
*(_WORD *)&runtty.c_cc[1] = 0;
result = 0LL;
*(__m128i *)&runtty.c_cc[15] = v2;
runtty.c_lflag &= 0xFFFFFFF5;
*(_QWORD *)&runtty.c_cc[8] = 0LL;
*(_DWORD *)&runtty.c_cc[3] = 0;
return result;
}

original_code:
t_stat ttinit (void)
{
if (tcgetattr (0, &cmdtty) < 0) return (32 + 15);
runtty = cmdtty;
runtty.c_lflag = runtty.c_lflag & ~(0000010 | 0000002);
runtty.c_oflag = runtty.c_oflag & ~0000001;
runtty.c_iflag = runtty.c_iflag & ~0000400;
runtty.c_cc[0] = sim_int_char;
runtty.c_cc[1] = 0;
runtty.c_cc[2] = 0;
runtty.c_cc[3] = 0;
runtty.c_cc[4] = 0;
runtty.c_cc[11] = 0;
runtty.c_cc[8] = 0;
runtty.c_cc[10] = 0;
runtty.c_cc[9] = 0;
runtty.c_cc[12] = 0;
runtty.c_cc[13] = 0;
runtty.c_cc[14] = 0;
runtty.c_cc[15] = 0;
runtty.c_cc[6] = 0;
runtty.c_cc[5] = 0;
return 0;
}

canonical_original_code:
int ttinit()
{
if (tcgetattr (0, &cmdtty) < 0) return (32 + 15);
runtty = cmdtty;
runtty.c_lflag = runtty.c_lflag & ~(0000010 | 0000002);
runtty.c_oflag = runtty.c_oflag & ~0000001;
runtty.c_iflag = runtty.c_iflag & ~0000400;
runtty.c_cc[0] = sim_int_char;
runtty.c_cc[1] = 0;
runtty.c_cc[2] = 0;
runtty.c_cc[3] = 0;
runtty.c_cc[4] = 0;
runtty.c_cc[11] = 0;
runtty.c_cc[8] = 0;
runtty.c_cc[10] = 0;
runtty.c_cc[9] = 0;
runtty.c_cc[12] = 0;
runtty.c_cc[13] = 0;
runtty.c_cc[14] = 0;
runtty.c_cc[15] = 0;
runtty.c_cc[6] = 0;
runtty.c_cc[5] = 0;
return 0;
}


ttrunstate

decompiled_code:
__int64 ttrunstate()
{
runtty.c_cc[0] = sim_int_char;
return (tcsetattr(0, 2, &runtty) >> 31) & 0x2F;
}

canonical_decompiled_code:
__int64 func1()
{
runtty.c_cc[0] = sim_int_char;
return (tcsetattr(0, 2, &runtty) >> 31) & 0x2F;
}

original_code:
t_stat ttrunstate (void)
{
runtty.c_cc[0] = sim_int_char;
if (tcsetattr (0, 2, &runtty) < 0) return (32 + 15);
return 0;
}

canonical_original_code:
int ttrunstate()
{
runtty.c_cc[0] = sim_int_char;
if (tcsetattr (0, 2, &runtty) < 0) return (32 + 15);
return 0;
}


ttcmdstate

decompiled_code:
__int64 ttcmdstate()
{
return (tcsetattr(0, 2, &cmdtty) >> 31) & 0x2F;
}

canonical_decompiled_code:
__int64 func2()
{
return (tcsetattr(0, 2, &cmdtty) >> 31) & 0x2F;
}

original_code:
t_stat ttcmdstate (void)
{
if (tcsetattr (0, 2, &cmdtty) < 0) return (32 + 15);
return 0;
}

canonical_original_code:
int ttcmdstate()
{
if (tcsetattr (0, 2, &cmdtty) < 0) return (32 + 15);
return 0;
}


ttclose

decompiled_code:
// attributes: thunk
__int64 ttclose()
{
return ttcmdstate();
}

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

original_code:
t_stat ttclose (void)
{
return ttcmdstate ();
}

canonical_original_code:
int ttclose()
{
return ttcmdstate ();
}


decompiled_code:
__int16 sim_poll_kbd()
{
int v0; // er8
__int16 result; // ax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = read(0, buf, 1uLL);
result = 0;
if ( v0 == 1 )
{
LOBYTE(result) = buf[0];
HIBYTE(result) = 2;
}
return result;
}

canonical_decompiled_code:
__int16 func4()
{
int v0; // er8
__int16 result; // ax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = read(0, buf, 1uLL);
result = 0;
if ( v0 == 1 )
{
LOBYTE(result) = buf[0];
HIBYTE(result) = 2;
}
return result;
}

original_code:
t_stat sim_poll_kbd (void)
{
int status;
unsigned char buf[1];
status = read (0, buf, 1);
if (status != 1) return 0;
else return (buf[0] | 01000);
}

canonical_original_code:
int sim_poll_kbd()
{
int status;
unsigned char buf[1];
status = read (0, buf, 1);
if (status != 1) return 0;
else return (buf[0] | 01000);
}

variable_types: status int

variable_types:
buf
unsigned char [1]


decompiled_code:
__int64 __fastcall sim_putchar(char a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 0LL;
}

original_code:
t_stat sim_putchar (int out)
{
char c;
c = out;
write (1, &c, 1);
return 0;
}

canonical_original_code:
int sim_putchar(int out)
{
char c;
c = out;
write (1, &c, 1);
return 0;
}

variable_types: out int

variable_types: c char


decompiled_code:
__int64 pro_kb_get()
{
unsigned int v0; // eax
__int64 result; // rax

v0 = (*(__int64 (__fastcall **)(_QWORD))pro_kb_orig)(0LL);
if ( v0 == 256 )
result = 256LL;
else
result = pro_menu(v0);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
__int64 result; // rax

v0 = (*(__int64 (__fastcall **)(_QWORD))pro_kb_orig)(0LL);
if ( v0 == 256 )
result = 256LL;
else
result = pro_menu(v0);
return result;
}

original_code:
int pro_kb_get ()
{
int key;
 key = pro_kb_orig->get(0);
 if (key != 256)
   key = pro_menu(key);
 return key;
}

canonical_original_code:
int pro_kb_get()
{
int key;
 key = pro_kb_orig->get(0);
 if (key != 256)
   key = pro_menu(key);
 return key;
}


decompiled_code:
// attributes: thunk
__int64 pro_kb_rd()
{
return pro_2661kb_rd();
}

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

original_code:
int pro_kb_rd (int pa)
{
 return pro_2661kb_rd(pa);
}

canonical_original_code:
int pro_kb_rd(int pa)
{
 return pro_2661kb_rd(pa);
}


decompiled_code:
// attributes: thunk
__int64 pro_kb_wr()
{
return pro_2661kb_wr();
}

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

original_code:
void pro_kb_wr (int data, int pa, int access)
{
 pro_2661kb_wr(data, pa, access);
}

canonical_original_code:
void pro_kb_wr(int data, int pa, int access)
{
 pro_2661kb_wr(data, pa, access);
}


decompiled_code:
_QWORD *pro_kb_filter()
{
_QWORD *result; // rax
__int64 v1; // rdx

result = (_QWORD *)pro_kb;
pro_kb_new = (__int64)pro_kb_get;
pro_kb = &pro_kb_new;
v1 = result[1];
pro_kb_orig = (__int64)result;
qword_148 = v1;
qword_150 = result[2];
qword_158 = result[3];
qword_160 = result[4];
qword_168 = result[5];
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax
__int64 v1; // rdx

result = (_QWORD *)pro_kb;
pro_kb_new = (__int64)pro_kb_get;
pro_kb = &pro_kb_new;
v1 = result[1];
pro_kb_orig = (__int64)result;
qword_148 = v1;
qword_150 = result[2];
qword_158 = result[3];
qword_160 = result[4];
qword_168 = result[5];
return result;
}

original_code:
void pro_kb_filter ()
{
 pro_kb_new.get = &pro_kb_get;
 pro_kb_new.put = pro_kb->put;
 pro_kb_new.ctrl_get = pro_kb->ctrl_get;
 pro_kb_new.ctrl_put = pro_kb->ctrl_put;
 pro_kb_new.reset = pro_kb->reset;
 pro_kb_new.exit = pro_kb->exit;
 pro_kb_orig = pro_kb;
 pro_kb = &pro_kb_new;
}

canonical_original_code:
void pro_kb_filter()
{
 pro_kb_new.get = &pro_kb_get;
 pro_kb_new.put = pro_kb->put;
 pro_kb_new.ctrl_get = pro_kb->ctrl_get;
 pro_kb_new.ctrl_put = pro_kb->ctrl_put;
 pro_kb_new.reset = pro_kb->reset;
 pro_kb_new.exit = pro_kb->exit;
 pro_kb_orig = pro_kb;
 pro_kb = &pro_kb_new;
}


decompiled_code:
__int64 pro_kb_open()
{
pro_kb_filter();
return pro_2661kb_open();
}

canonical_decompiled_code:
__int64 func4()
{
func3();
return pro_2661kb_open();
}

original_code:
void pro_kb_open ()
{
 pro_kb_filter();
 pro_2661kb_open();
}

canonical_original_code:
void pro_kb_open()
{
 pro_kb_filter();
 pro_2661kb_open();
}


decompiled_code:
__int64 pro_kb_reset()
{
pro_2661kb_reset();
return pro_kb_open();
}

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

original_code:
void pro_kb_reset ()
{
 pro_2661kb_reset();
 pro_kb_open();
}

canonical_original_code:
void pro_kb_reset()
{
 pro_2661kb_reset();
 pro_kb_open();
}


decompiled_code:
__int64 pro_kb_exit()
{
return (*(__int64 (__fastcall **)(_QWORD))(pro_kb + 40LL))(0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return (*(__int64 (__fastcall **)(_QWORD))(pro_kb + 40LL))(0LL);
}

original_code:
void pro_kb_exit ()
{
 pro_kb->exit(0);
}

canonical_original_code:
void pro_kb_exit()
{
 pro_kb->exit(0);
}


decompiled_code:
__int64 __fastcall pro_vid_pixop(int a1, int a2, __int16 a3, int a4, int a5)
{
char v6; // cl
int v7; // er10
__int16 v8; // ax
__int64 v9; // rdx
int v10; // eax
int v11; // er9
__int64 result; // rax

v6 = a2 & 0xF;
v7 = a4 << (a2 & 0xF);
v8 = pro_vid_y_offset + ((a3 << 6) | (a2 >> 4) & 0x3F);
v9 = v8 & 0x3FFF;
v10 = v8 & 0x3FFF;
v11 = (unsigned __int16)PRO_VRAM[0x4000 * (__int64)a1 + v9];
LOWORD(a2) = PRO_VRAM[0x4000 * (__int64)a1 + v9];
switch ( a5 )
{
case 3:
LOWORD(a2) = v11 & ~(_WORD)v7;
break;
case 4:
a2 = v7 | v11 & ((1 << v6) ^ 0xFFFF);
break;
case 1:
LOWORD(a2) = v11 ^ v7;
break;
case 2:
LOWORD(a2) = v11 | v7;
break;
}
result = v10 >> 6;
PRO_VRAM[0x4000 * (__int64)a1 + v9] = a2;
pro_vid_mvalid[result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, __int16 a3, int a4, int a5)
{
char v6; // cl
int v7; // er10
__int16 v8; // ax
__int64 v9; // rdx
int v10; // eax
int v11; // er9
__int64 result; // rax

v6 = a2 & 0xF;
v7 = a4 << (a2 & 0xF);
v8 = pro_vid_y_offset + ((a3 << 6) | (a2 >> 4) & 0x3F);
v9 = v8 & 0x3FFF;
v10 = v8 & 0x3FFF;
v11 = (unsigned __int16)PRO_VRAM[0x4000 * (__int64)a1 + v9];
LOWORD(a2) = PRO_VRAM[0x4000 * (__int64)a1 + v9];
switch ( a5 )
{
case 3:
LOWORD(a2) = v11 & ~(_WORD)v7;
break;
case 4:
a2 = v7 | v11 & ((1 << v6) ^ 0xFFFF);
break;
case 1:
LOWORD(a2) = v11 ^ v7;
break;
case 2:
LOWORD(a2) = v11 | v7;
break;
}
result = v10 >> 6;
PRO_VRAM[0x4000 * (__int64)a1 + v9] = a2;
pro_vid_mvalid[result] = 0;
return result;
}

original_code:
static void pro_vid_pixop(int pnum, int x, int y, int data, int pixop)
{
int vindex, vbit, vmask, vdata, bit;
 vindex = ((((y << 6) | ((x >> 4) & 077)) + pro_vid_y_offset) & 0037777);
 vbit = x & 017;
 vmask = ~(01 << vbit) & 0177777;
 bit = data << vbit;
 vdata = PRO_VRAM[pnum][vindex];
 switch (pixop)
 {
   case 001:
     vdata = vdata ^ bit;
     break;
   case 002:
     vdata = vdata | bit;
     break;
   case 003:
     vdata = vdata & (~bit & 0177777);
     break;
   case 004:
     vdata = (vdata & vmask) | bit;
     break;
   default:
     break;
 }
 PRO_VRAM[pnum][vindex] = vdata;
 pro_vid_mvalid[((vindex) >> 6)] = 0;
}

canonical_original_code:
static void pro_vid_pixop(int pnum, int x, int y, int data, int pixop)
{
int vindex; int vbit; int vmask; int vdata; int bit;
 vindex = ((((y << 6) | ((x >> 4) & 077)) + pro_vid_y_offset) & 0037777);
 vbit = x & 017;
 vmask = ~(01 << vbit) & 0177777;
 bit = data << vbit;
 vdata = PRO_VRAM[pnum][vindex];
 switch (pixop)
 {
   case 001:
     vdata = vdata ^ bit;
     break;
   case 002:
     vdata = vdata | bit;
     break;
   case 003:
     vdata = vdata & (~bit & 0177777);
     break;
   case 004:
     vdata = (vdata & vmask) | bit;
     break;
   default:
     break;
 }
 PRO_VRAM[pnum][vindex] = vdata;
 pro_vid_mvalid[((vindex) >> 6)] = 0;
}

variable_types: pnum int

variable_types: x int

variable_types: y int

variable_types: pixop int

variable_types: vindex int

variable_types: vbit int

variable_types: vmask int

variable_types: vdata int

variable_types: bit int


decompiled_code:
__int64 pro_vid_sched()
{
return pro_eq_sched(3LL, (pro_vid_csr & 1) == 0 ? 7500 : 9000);
}

original_code:
static void pro_vid_sched ()
{
int interval;
 if ((pro_vid_csr & 0000001) == 0)
   interval = 7500;
 else
   interval = 9000;
 pro_eq_sched(3, interval);
}

canonical_original_code:
static void pro_vid_sched()
{
int interval;
 if ((pro_vid_csr & 0000001) == 0)
   interval = 7500;
 else
   interval = 9000;
 pro_eq_sched(3, interval);
}

variable_types: interval int


decompiled_code:
__int64 pro_vid_eq()
{
int v0; // eax

if ( (pro_vid_csr & 0x40) != 0 )
{
pro_int_set(260LL);
v0 = pro_vid_skip;
if ( pro_vid_skip )
goto LABEL_3;
}
else
{
v0 = pro_vid_skip;
if ( pro_vid_skip )
{
LABEL_3:
pro_vid_skip = v0 + 1;
return pro_vid_sched();
}
}
pro_screen_update();
pro_vid_skip = 0;
return pro_vid_sched();
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax

if ( (pro_vid_csr & 0x40) != 0 )
{
pro_int_set(260LL);
v0 = pro_vid_skip;
if ( pro_vid_skip )
goto LABEL_3;
}
else
{
v0 = pro_vid_skip;
if ( pro_vid_skip )
{
LABEL_3:
pro_vid_skip = v0 + 1;
return func1();
}
}
pro_screen_update();
pro_vid_skip = 0;
return func1();
}

original_code:
void pro_vid_eq ()
{
 if ((pro_vid_csr & 0000100) != 0)
   pro_int_set(0x0104);
 if (pro_vid_skip == 0)
 {
   pro_screen_update();
   pro_vid_skip = 0;
 }
 else
   pro_vid_skip++;
 pro_vid_sched();
}

canonical_original_code:
void pro_vid_eq()
{
 if ((pro_vid_csr & 0000100) != 0)
   pro_int_set(0x0104);
 if (pro_vid_skip == 0)
 {
   pro_screen_update();
   pro_vid_skip = 0;
 }
 else
   pro_vid_skip++;
 pro_vid_sched();
}


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

result = (unsigned int)pro_vid_csr;
if ( (pro_vid_csr & 0x4000) != 0 )
{
pro_int_set(516LL);
result = (unsigned int)pro_vid_csr;
}
pro_vid_cnt = 0;
BYTE1(result) |= 0x80u;
pro_vid_csr = result;
return result;
}

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

result = (unsigned int)pro_vid_csr;
if ( (pro_vid_csr & 0x4000) != 0 )
{
pro_int_set(516LL);
result = (unsigned int)pro_vid_csr;
}
pro_vid_cnt = 0;
BYTE1(result) |= 0x80u;
pro_vid_csr = result;
return result;
}

original_code:
void pro_vid_cmd_eq ()
{
 if ((pro_vid_csr & 0040000) != 0)
   pro_int_set(0x0204);
 pro_vid_csr = pro_vid_csr | 0100000;
 pro_vid_cnt = 0;
}

canonical_original_code:
void pro_vid_cmd_eq()
{
 if ((pro_vid_csr & 0040000) != 0)
   pro_int_set(0x0204);
 pro_vid_csr = pro_vid_csr | 0100000;
 pro_vid_cnt = 0;
}


decompiled_code:
__int64 __fastcall pro_vram_rd(_DWORD *a1, int a2)
{
int v2; // esi
double v3; // xmm0_8
__int64 result; // rax

if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v2 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - (a2 & 0x3F8000)) >> 1)) & 0x3FFF;
switch ( pro_vid_plane_en )
{
case 1:
case 3:
case 5:
case 7:
*a1 = (unsigned __int16)PRO_VRAM[v2];
result = 0LL;
break;
case 2:
case 6:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x4000];
result = 0LL;
break;
case 4:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x8000];
result = 0LL;
break;
default:
*a1 = 0xFFFF;
result = 0LL;
break;
}
}
else
{
*a1 = 0;
v3 = sim_gtime();
printf("%10f Warning: video memory (R) not at default location!\r\n", v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2)
{
int v2; // esi
double v3; // xmm0_8
__int64 result; // rax

if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v2 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - (a2 & 0x3F8000)) >> 1)) & 0x3FFF;
switch ( pro_vid_plane_en )
{
case 1:
case 3:
case 5:
case 7:
*a1 = (unsigned __int16)PRO_VRAM[v2];
result = 0LL;
break;
case 2:
case 6:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x4000];
result = 0LL;
break;
case 4:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x8000];
result = 0LL;
break;
default:
*a1 = 0xFFFF;
result = 0LL;
break;
}
}
else
{
*a1 = 0;
v3 = sim_gtime();
printf("%10f Warning: video memory (R) not at default location!\r\n", v3);
result = 0LL;
}
return result;
}

original_code:
int pro_vram_rd (int *data, int pa, int access)
{
int vindex;
 if ((pa & 017700000) == pro_vid_mem_base)
 {
   vindex = ((((pa-pro_vid_mem_base) >> 1) + pro_vid_y_offset) & 0037777);
   switch (pro_vid_plane_en)
   {
     case 00:
       *data = 0177777;
       break;
     case 01:
     case 03:
     case 05:
     case 07:
       *data = PRO_VRAM[0][vindex];
       break;
     case 02:
     case 06:
       *data = PRO_VRAM[1][vindex];
       break;
     case 04:
       *data = PRO_VRAM[2][vindex];
       break;
     default:
       *data = 0177777;
       break;
   }
 }
 else
 {
   *data = 0;
   printf("%10f Warning: video memory (R) not at default location!\r\n", sim_gtime());
 }
 return 0;
}

canonical_original_code:
int pro_vram_rd(int *data, int pa, int access)
{
int vindex;
 if ((pa & 017700000) == pro_vid_mem_base)
 {
   vindex = ((((pa-pro_vid_mem_base) >> 1) + pro_vid_y_offset) & 0037777);
   switch (pro_vid_plane_en)
   {
     case 00:
       *data = 0177777;
       break;
     case 01:
     case 03:
     case 05:
     case 07:
       *data = PRO_VRAM[0][vindex];
       break;
     case 02:
     case 06:
       *data = PRO_VRAM[1][vindex];
       break;
     case 04:
       *data = PRO_VRAM[2][vindex];
       break;
     default:
       *data = 0177777;
       break;
   }
 }
 else
 {
   *data = 0;
   printf("%10f Warning: video memory (R) not at default location!\r\n", sim_gtime());
 }
 return 0;
}

variable_types:
data
int *

variable_types: pa int

variable_types: access int


decompiled_code:
__int64 __fastcall pro_vram_wr(__int16 a1, int a2, int a3)
{
int v3; // ecx
int v4; // eax
int v5; // er8
int v6; // er9
__int64 v7; // rdx
__int16 v8; // cx
double v10; // xmm0_8
__int64 v11; // rdx
__int16 v12; // cx
__int16 v13; // si
__int16 v14; // di
__int16 v15; // si
__int16 v16; // di
__int16 v17; // cx

v3 = a2 & 0x3F8000;
if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v4 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v5 = pro_vid_plane_en & 2;
v6 = pro_vid_plane_en & 4;
if ( (pro_vid_plane_en & 1) != 0 )
{
if ( a3 != 4 )
{
v7 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v8 = a1;
PRO_VRAM[v4] = a1;
if ( !v5 )
{
if ( !v6 )
goto LABEL_12;
goto LABEL_11;
}
goto LABEL_10;
}
v11 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v12 = PRO_VRAM[v11];
if ( (a2 & 1) != 0 )
{
v13 = a1 << 8;
PRO_VRAM[v4] = (a1 << 8) | (unsigned __int8)v12;
if ( !v5 )
{
if ( !v6 )
goto LABEL_12;
LABEL_20:
v13 = a1 << 8;
LABEL_21:
v14 = v13 | LOBYTE(PRO_VRAM[v11 + 0x8000]);
LABEL_22:
PRO_VRAM[v11 + 0x8000] = v14;
goto LABEL_12;
}
LABEL_34:
HIBYTE(PRO_VRAM[v11 + 0x4000]) = HIBYTE(v13);
if ( !v6 )
goto LABEL_12;
goto LABEL_21;
}
a1 = (unsigned __int8)a1;
LOBYTE(v12) = 0;
v15 = (unsigned __int8)a1;
PRO_VRAM[v4] = (unsigned __int8)a1 | v12;
if ( !v5 )
{
if ( !v6 )
goto LABEL_12;
LABEL_25:
v15 = a1;
LABEL_26:
v16 = PRO_VRAM[v11 + 0x8000];
LOBYTE(v16) = 0;
v14 = v15 | v16;
goto LABEL_22;
}
}
else
{
if ( (pro_vid_plane_en & 2) == 0 )
{
if ( (pro_vid_plane_en & 4) == 0 )
goto LABEL_12;
if ( a3 != 4 )
{
v8 = a1;
v7 = v4;
goto LABEL_11;
}
v11 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
if ( (a2 & 1) != 0 )
goto LABEL_20;
a1 = (unsigned __int8)a1;
goto LABEL_25;
}
if ( a3 != 4 )
{
v8 = a1;
v7 = v4;
LABEL_10:
PRO_VRAM[v7 + 0x4000] = v8;
if ( !v6 )
{
LABEL_12:
pro_vid_mvalid[v4 >> 6] = 0;
return 0LL;
}
LABEL_11:
PRO_VRAM[v7 + 0x8000] = v8;
goto LABEL_12;
}
if ( (a2 & 1) != 0 )
{
v11 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v13 = a1 << 8;
goto LABEL_34;
}
v15 = (unsigned __int8)a1;
v11 = v4;
}
v17 = PRO_VRAM[v11 + 0x4000];
LOBYTE(v17) = 0;
PRO_VRAM[v11 + 0x4000] = v15 | v17;
if ( !v6 )
goto LABEL_12;
goto LABEL_26;
}
v10 = sim_gtime();
printf("%10f Warning: video memory (W) not at default location!\r\n", v10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1, int a2, int a3)
{
int v3; // ecx
int v4; // eax
int v5; // er8
int v6; // er9
__int64 v7; // rdx
__int16 v8; // cx
double v10; // xmm0_8
__int64 v11; // rdx
__int16 v12; // cx
__int16 v13; // si
__int16 v14; // di
__int16 v15; // si
__int16 v16; // di
__int16 v17; // cx

v3 = a2 & 0x3F8000;
if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v4 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v5 = pro_vid_plane_en & 2;
v6 = pro_vid_plane_en & 4;
if ( (pro_vid_plane_en & 1) != 0 )
{
if ( a3 != 4 )
{
v7 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v8 = a1;
PRO_VRAM[v4] = a1;
if ( !v5 )
{
if ( !v6 )
goto LABEL_12;
goto LABEL_11;
}
goto LABEL_10;
}
v11 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v12 = PRO_VRAM[v11];
if ( (a2 & 1) != 0 )
{
v13 = a1 << 8;
PRO_VRAM[v4] = (a1 << 8) | (unsigned __int8)v12;
if ( !v5 )
{
if ( !v6 )
goto LABEL_12;
LABEL_20:
v13 = a1 << 8;
LABEL_21:
v14 = v13 | LOBYTE(PRO_VRAM[v11 + 0x8000]);
LABEL_22:
PRO_VRAM[v11 + 0x8000] = v14;
goto LABEL_12;
}
LABEL_34:
HIBYTE(PRO_VRAM[v11 + 0x4000]) = HIBYTE(v13);
if ( !v6 )
goto LABEL_12;
goto LABEL_21;
}
a1 = (unsigned __int8)a1;
LOBYTE(v12) = 0;
v15 = (unsigned __int8)a1;
PRO_VRAM[v4] = (unsigned __int8)a1 | v12;
if ( !v5 )
{
if ( !v6 )
goto LABEL_12;
LABEL_25:
v15 = a1;
LABEL_26:
v16 = PRO_VRAM[v11 + 0x8000];
LOBYTE(v16) = 0;
v14 = v15 | v16;
goto LABEL_22;
}
}
else
{
if ( (pro_vid_plane_en & 2) == 0 )
{
if ( (pro_vid_plane_en & 4) == 0 )
goto LABEL_12;
if ( a3 != 4 )
{
v8 = a1;
v7 = v4;
goto LABEL_11;
}
v11 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
if ( (a2 & 1) != 0 )
goto LABEL_20;
a1 = (unsigned __int8)a1;
goto LABEL_25;
}
if ( a3 != 4 )
{
v8 = a1;
v7 = v4;
LABEL_10:
PRO_VRAM[v7 + 0x4000] = v8;
if ( !v6 )
{
LABEL_12:
pro_vid_mvalid[v4 >> 6] = 0;
return 0LL;
}
LABEL_11:
PRO_VRAM[v7 + 0x8000] = v8;
goto LABEL_12;
}
if ( (a2 & 1) != 0 )
{
v11 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - v3) >> 1)) & 0x3FFF;
v13 = a1 << 8;
goto LABEL_34;
}
v15 = (unsigned __int8)a1;
v11 = v4;
}
v17 = PRO_VRAM[v11 + 0x4000];
LOBYTE(v17) = 0;
PRO_VRAM[v11 + 0x4000] = v15 | v17;
if ( !v6 )
goto LABEL_12;
goto LABEL_26;
}
v10 = sim_gtime();
printf("%10f Warning: video memory (W) not at default location!\r\n", v10);
return 0LL;
}

variable_types: data int


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

result = 0LL;
memset(pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
return result;
}

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

result = 0LL;
memset(pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
return result;
}

original_code:
void pro_clear_mvalid ()
{
   memset(&pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
}

canonical_original_code:
void pro_clear_mvalid()
{
   memset(&pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
}


decompiled_code:
__int64 __fastcall pro_vid_rd(int a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3FFFFE;
if ( v1 > 4192534 )
{
result = 0xFFFFLL;
if ( v1 == 4192640 )
result = 65283LL;
}
else if ( v1 <= 4192511 )
{
LABEL_4:
result = 0xFFFFLL;
}
else
{
switch ( v1 )
{
case 4192512:
result = 65282LL;
break;
case 4192516:
result = (unsigned int)pro_vid_csr;
break;
case 4192518:
result = (unsigned int)pro_vid_p1c;
break;
case 4192520:
result = (unsigned int)pro_vid_opc;
break;
case 4192524:
result = (unsigned int)pro_vid_scl;
break;
case 4192526:
result = (unsigned int)pro_vid_x;
break;
case 4192528:
result = (unsigned int)pro_vid_y;
break;
case 4192530:
case 4192532:
case 4192534:
result = 65407LL;
break;
default:
goto LABEL_4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3FFFFE;
if ( v1 > 4192534 )
{
result = 0xFFFFLL;
if ( v1 == 4192640 )
result = 65283LL;
}
else if ( v1 <= 4192511 )
{
LABEL_4:
result = 0xFFFFLL;
}
else
{
switch ( v1 )
{
case 4192512:
result = 65282LL;
break;
case 4192516:
result = (unsigned int)pro_vid_csr;
break;
case 4192518:
result = (unsigned int)pro_vid_p1c;
break;
case 4192520:
result = (unsigned int)pro_vid_opc;
break;
case 4192524:
result = (unsigned int)pro_vid_scl;
break;
case 4192526:
result = (unsigned int)pro_vid_x;
break;
case 4192528:
result = (unsigned int)pro_vid_y;
break;
case 4192530:
case 4192532:
case 4192534:
result = 65407LL;
break;
default:
goto LABEL_4;
}
}
return result;
}

original_code:
int pro_vid_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774400:
     data = 0177402;
     break;
   case 017774404:
     data = pro_vid_csr;
     break;
   case 017774406:
     data = pro_vid_p1c;
     break;
   case 017774410:
     data = pro_vid_opc;
     break;
   case 017774414:
     data = pro_vid_scl;
     break;
   case 017774416:
     data = pro_vid_x;
     break;
   case 017774420:
     data = pro_vid_y;
     break;
   case 017774422:
     data = 0177577;
     break;
   case 017774424:
     data = 0177577;
     break;
   case 017774426:
     data = 0177577;
     break;
   case 017774600:
     data = 0177403;
     break;
   default:
     data = 0177777;
     break;
 }
 return data;
}

canonical_original_code:
int pro_vid_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774400:
     data = 0177402;
     break;
   case 017774404:
     data = pro_vid_csr;
     break;
   case 017774406:
     data = pro_vid_p1c;
     break;
   case 017774410:
     data = pro_vid_opc;
     break;
   case 017774414:
     data = pro_vid_scl;
     break;
   case 017774416:
     data = pro_vid_x;
     break;
   case 017774420:
     data = pro_vid_y;
     break;
   case 017774422:
     data = 0177577;
     break;
   case 017774424:
     data = 0177577;
     break;
   case 017774426:
     data = 0177577;
     break;
   case 017774600:
     data = 0177403;
     break;
   default:
     data = 0177777;
     break;
 }
 return data;
}


decompiled_code:
__int16 __fastcall pro_vid_wr(int a1, int a2, int a3)
{
int v3; // eax
unsigned __int16 v4; // bx
int v5; // edi
int v6; // er12
__int16 v7; // r15
int v8; // eax
int v9; // er12
int *v10; // r14
int v11; // edi
int v12; // er9
int v13; // eax
int v14; // er15
int v15; // er11
int v16; // er10
int v17; // ebp
int v18; // ebx
int v19; // er12
int v20; // er13
int v21; // er8
int v22; // eax
int v23; // edx
int v24; // ecx
char v25; // cl
__int64 v26; // rdx
int v27; // esi
unsigned __int16 v28; // cx
__int64 v29; // rdx
int v30; // esi
__int64 v31; // rdx
int v32; // esi
__int16 v33; // cx
__int16 v34; // cx
__int16 v35; // cx
int v37; // [rsp+10h] [rbp-68h]
int v38; // [rsp+18h] [rbp-60h]
int v39; // [rsp+1Ch] [rbp-5Ch]
int v40; // [rsp+20h] [rbp-58h]
int v41; // [rsp+24h] [rbp-54h]
int v42; // [rsp+28h] [rbp-50h]
int v43; // [rsp+2Ch] [rbp-4Ch]
int v44[17]; // [rsp+34h] [rbp-44h] BYREF

LOWORD(v3) = (a2 & 0xFFFE) + 1788;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF904:
v4 = pro_vid_csr;
if ( a3 == 4 )
{
if ( (a2 & 1) != 0 )
{
v3 = pro_vid_csr;
BYTE1(v3) = BYTE1(pro_vid_csr) & 0xB8;
v5 = v3 | ((_WORD)a1 << 8) & 0x4743;
}
else
{
LOWORD(v3) = pro_vid_csr & 0xFFBC;
v5 = pro_vid_csr & 0xFFFFFFBC | a1 & 0x43;
}
}
else
{
v5 = pro_vid_csr & 0xFFFFB8BC | a1 & 0x4743;
}
pro_vid_csr = v5;
if ( (v5 & 0x4000) != 0 && (v4 & 0x4000) == 0 && (v5 & 0x8000) != 0 )
{
LOWORD(v3) = pro_int_set(516LL);
LOWORD(v5) = pro_vid_csr;
}
if ( ((v4 ^ (unsigned __int16)v5) & 0x400) != 0 )
LOWORD(v3) = pro_mapchange();
break;
case 0x3FF906:
pro_vid_p1c = pro_vid_p1c & 0xFFFFFFC0 | a1 & 0x3F;
v3 = (pro_vid_opc >> 4) & 2 | (pro_vid_opc >> 11) & 4;
pro_vid_plane_en = v3 | (pro_vid_p1c >> 5) & 1;
break;
case 0x3FF908:
pro_vid_opc = pro_vid_opc & 0xFFFFC0C0 | a1 & 0x3F3F;
v3 = (pro_vid_p1c >> 5) & 1;
pro_vid_plane_en = v3 | (pro_vid_opc >> 11) & 4 | (pro_vid_opc >> 4) & 2;
break;
case 0x3FF90A:
LOWORD(v3) = pro_colormap_write((a1 >> 8) & 7, (unsigned __int8)a1);
break;
case 0x3FF90C:
v22 = pro_vid_scl;
v23 = pro_vid_scl;
LOBYTE(v23) = 0;
pro_vid_scl = v23 | (unsigned __int8)a1;
if ( pro_vid_scl != v22 )
{
pro_scroll();
LOWORD(v22) = pro_vid_scl;
}
v3 = ((_WORD)v22 << 6) & 0x3FC0;
pro_vid_y_offset = v3;
break;
case 0x3FF90E:
LOWORD(v3) = pro_vid_x & 0xFC00;
pro_vid_x = pro_vid_x & 0xFFFFFC00 | a1 & 0x3FF;
break;
case 0x3FF910:
LOBYTE(pro_vid_y) = a1;
break;
case 0x3FF912:
HIWORD(v6) = HIWORD(pro_vid_cnt);
v7 = pro_vid_csr;
LOWORD(v6) = 0;
v8 = pro_vid_csr;
v9 = (unsigned __int16)a1 | v6;
BYTE1(v8) = BYTE1(pro_vid_csr) & 0x7F;
pro_vid_cnt = v9;
pro_vid_csr = v8;
if ( v9 )
{
v10 = v44;
v11 = 0;
v43 = pro_vid_x;
v44[0] = pro_vid_p1c & 7;
v42 = pro_vid_y;
v41 = pro_vid_pat;
v44[1] = pro_vid_opc & 7;
v44[2] = (pro_vid_opc >> 8) & 7;
v12 = v7 & 0x100;
v13 = v7 & 0x200;
v14 = v9;
v40 = (pro_vid_y << 6) | (pro_vid_x >> 4) & 0x3F;
v39 = (unsigned __int16)-(pro_vid_pat & 1);
do
{
v15 = ((_WORD)pro_vid_y_offset + (_WORD)v40) & 0x3FFF;
if ( v14 <= 0 )
{
v17 = v41;
}
else
{
v16 = v39;
v17 = v41;
v18 = 0;
v19 = v42;
v20 = v43;
do
{
v21 = *v10;
if ( v13 )
{
switch ( v21 )
{
case 1:
PRO_VRAM[0x4000 * (__int64)v11 + v15] = ~PRO_VRAM[0x4000 * (__int64)v11 + v15];
goto LABEL_54;
case 2:
PRO_VRAM[0x4000 * (__int64)v11 + v15] = v39;
goto LABEL_54;
case 3:
PRO_VRAM[0x4000 * (__int64)v11 + v15] = ~(_WORD)v39;
goto LABEL_54;
case 5:
v31 = ((__int64)v11 << 14) + v15;
v32 = (unsigned __int16)PRO_VRAM[v31];
if ( !v12 )
{
PRO_VRAM[v31] = (2 * v32) | (v16 >> 15);
v16 = v32;
goto LABEL_47;
}
v34 = ((_WORD)v16 << 15) | ((unsigned __int16)PRO_VRAM[v31] >> 1);
v16 = (unsigned __int16)PRO_VRAM[v31];
PRO_VRAM[v31] = v34;
goto LABEL_63;
case 6:
v29 = ((__int64)v11 << 14) + v15;
v30 = (unsigned __int16)PRO_VRAM[v29];
if ( !v12 )
{
PRO_VRAM[v29] = (4 * v30) | (v16 >> 14);
v16 = v30;
goto LABEL_47;
}
v33 = ((_WORD)v16 << 14) | ((unsigned __int16)PRO_VRAM[v29] >> 2);
v16 = (unsigned __int16)PRO_VRAM[v29];
PRO_VRAM[v29] = v33;
goto LABEL_63;
case 7:
v26 = ((__int64)v11 << 14) + v15;
v27 = (unsigned __int16)PRO_VRAM[v26];
v28 = PRO_VRAM[v26];
if ( v12 )
{
v35 = ((_WORD)v16 << 12) | (v28 >> 4);
v16 = (unsigned __int16)PRO_VRAM[v26];
PRO_VRAM[v26] = v35;
LABEL_63:
pro_vid_mvalid[v15 >> 6] = 0;
LABEL_55:
v15 = ((_WORD)v15 - 1) & 0x3FFF;
}
else
{
PRO_VRAM[v26] = (16 * v28) | (v16 >> 12);
v16 = v27;
LABEL_47:
pro_vid_mvalid[v15 >> 6] = 0;
LABEL_48:
v15 = ((_WORD)v15 + 1) & 0x3FFF;
}
break;
default:
LABEL_54:
pro_vid_mvalid[v15 >> 6] = 0;
if ( v12 )
goto LABEL_55;
goto LABEL_48;
}
}
else
{
switch ( v21 )
{
case 1:
v24 = v17 & 1;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 2:
v25 = v17;
goto LABEL_42;
case 3:
v25 = ~(_BYTE)v17;
LABEL_42:
v24 = v25 & 1;
v21 = 4;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 4:
v21 = 2;
v24 = v17 & 1;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 5:
v21 = 3;
v24 = v17 & 1;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 6:
v24 = 1;
v21 = 3;
goto LABEL_28;
case 7:
v24 = 1;
v21 = 2;
LABEL_28:
v38 = v12;
v37 = v16;
pro_vid_pixop(v11, v20, v19, v24, v21);
v12 = v38;
v13 = 0;
v16 = v37;
break;
default:
break;
}
if ( v12 )
{
if ( ++v19 == 256 )
{
++v20;
v19 = 0;
if ( v20 == 1024 )
v20 = 0;
}
}
else if ( ++v20 == 1024 )
{
++v19;
v20 = 0;
if ( v19 == 256 )
v19 = 0;
}
}
++v18;
}
while ( v14 != v18 );
}
++v11;
++v10;
}
while ( v11 != 3 );
pro_vid_pat = v17;
}
LOWORD(v3) = pro_eq_sched(4LL, 1LL);
break;
case 0x3FF914:
LOWORD(pro_vid_pat) = a1;
break;
case 0x3FF916:
pro_vid_mbr = pro_vid_mbr & 0xFFFFFF80 | a1 & 0x7F;
pro_vid_mem_base = pro_vid_mbr << 15;
iotable = pro_vid_mbr << 15;
*((_DWORD *)&iotable + 1) = (pro_vid_mbr << 15) + 0x7FFF;
break;
default:
return v3;
}
return v3;
}

canonical_decompiled_code:
__int16 __fastcall func8(int a1, int a2, int a3)
{
int v3; // eax
unsigned __int16 v4; // bx
int v5; // edi
int v6; // er12
__int16 v7; // r15
int v8; // eax
int v9; // er12
int *v10; // r14
int v11; // edi
int v12; // er9
int v13; // eax
int v14; // er15
int v15; // er11
int v16; // er10
int v17; // ebp
int v18; // ebx
int v19; // er12
int v20; // er13
int v21; // er8
int v22; // eax
int v23; // edx
int v24; // ecx
char v25; // cl
__int64 v26; // rdx
int v27; // esi
unsigned __int16 v28; // cx
__int64 v29; // rdx
int v30; // esi
__int64 v31; // rdx
int v32; // esi
__int16 v33; // cx
__int16 v34; // cx
__int16 v35; // cx
int v37; // [rsp+10h] [rbp-68h]
int v38; // [rsp+18h] [rbp-60h]
int v39; // [rsp+1Ch] [rbp-5Ch]
int v40; // [rsp+20h] [rbp-58h]
int v41; // [rsp+24h] [rbp-54h]
int v42; // [rsp+28h] [rbp-50h]
int v43; // [rsp+2Ch] [rbp-4Ch]
int v44[17]; // [rsp+34h] [rbp-44h] BYREF

LOWORD(v3) = (a2 & 0xFFFE) + 1788;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF904:
v4 = pro_vid_csr;
if ( a3 == 4 )
{
if ( (a2 & 1) != 0 )
{
v3 = pro_vid_csr;
BYTE1(v3) = BYTE1(pro_vid_csr) & 0xB8;
v5 = v3 | ((_WORD)a1 << 8) & 0x4743;
}
else
{
LOWORD(v3) = pro_vid_csr & 0xFFBC;
v5 = pro_vid_csr & 0xFFFFFFBC | a1 & 0x43;
}
}
else
{
v5 = pro_vid_csr & 0xFFFFB8BC | a1 & 0x4743;
}
pro_vid_csr = v5;
if ( (v5 & 0x4000) != 0 && (v4 & 0x4000) == 0 && (v5 & 0x8000) != 0 )
{
LOWORD(v3) = pro_int_set(516LL);
LOWORD(v5) = pro_vid_csr;
}
if ( ((v4 ^ (unsigned __int16)v5) & 0x400) != 0 )
LOWORD(v3) = pro_mapchange();
break;
case 0x3FF906:
pro_vid_p1c = pro_vid_p1c & 0xFFFFFFC0 | a1 & 0x3F;
v3 = (pro_vid_opc >> 4) & 2 | (pro_vid_opc >> 11) & 4;
pro_vid_plane_en = v3 | (pro_vid_p1c >> 5) & 1;
break;
case 0x3FF908:
pro_vid_opc = pro_vid_opc & 0xFFFFC0C0 | a1 & 0x3F3F;
v3 = (pro_vid_p1c >> 5) & 1;
pro_vid_plane_en = v3 | (pro_vid_opc >> 11) & 4 | (pro_vid_opc >> 4) & 2;
break;
case 0x3FF90A:
LOWORD(v3) = pro_colormap_write((a1 >> 8) & 7, (unsigned __int8)a1);
break;
case 0x3FF90C:
v22 = pro_vid_scl;
v23 = pro_vid_scl;
LOBYTE(v23) = 0;
pro_vid_scl = v23 | (unsigned __int8)a1;
if ( pro_vid_scl != v22 )
{
pro_scroll();
LOWORD(v22) = pro_vid_scl;
}
v3 = ((_WORD)v22 << 6) & 0x3FC0;
pro_vid_y_offset = v3;
break;
case 0x3FF90E:
LOWORD(v3) = pro_vid_x & 0xFC00;
pro_vid_x = pro_vid_x & 0xFFFFFC00 | a1 & 0x3FF;
break;
case 0x3FF910:
LOBYTE(pro_vid_y) = a1;
break;
case 0x3FF912:
HIWORD(v6) = HIWORD(pro_vid_cnt);
v7 = pro_vid_csr;
LOWORD(v6) = 0;
v8 = pro_vid_csr;
v9 = (unsigned __int16)a1 | v6;
BYTE1(v8) = BYTE1(pro_vid_csr) & 0x7F;
pro_vid_cnt = v9;
pro_vid_csr = v8;
if ( v9 )
{
v10 = v44;
v11 = 0;
v43 = pro_vid_x;
v44[0] = pro_vid_p1c & 7;
v42 = pro_vid_y;
v41 = pro_vid_pat;
v44[1] = pro_vid_opc & 7;
v44[2] = (pro_vid_opc >> 8) & 7;
v12 = v7 & 0x100;
v13 = v7 & 0x200;
v14 = v9;
v40 = (pro_vid_y << 6) | (pro_vid_x >> 4) & 0x3F;
v39 = (unsigned __int16)-(pro_vid_pat & 1);
do
{
v15 = ((_WORD)pro_vid_y_offset + (_WORD)v40) & 0x3FFF;
if ( v14 <= 0 )
{
v17 = v41;
}
else
{
v16 = v39;
v17 = v41;
v18 = 0;
v19 = v42;
v20 = v43;
do
{
v21 = *v10;
if ( v13 )
{
switch ( v21 )
{
case 1:
PRO_VRAM[0x4000 * (__int64)v11 + v15] = ~PRO_VRAM[0x4000 * (__int64)v11 + v15];
goto LABEL_54;
case 2:
PRO_VRAM[0x4000 * (__int64)v11 + v15] = v39;
goto LABEL_54;
case 3:
PRO_VRAM[0x4000 * (__int64)v11 + v15] = ~(_WORD)v39;
goto LABEL_54;
case 5:
v31 = ((__int64)v11 << 14) + v15;
v32 = (unsigned __int16)PRO_VRAM[v31];
if ( !v12 )
{
PRO_VRAM[v31] = (2 * v32) | (v16 >> 15);
v16 = v32;
goto LABEL_47;
}
v34 = ((_WORD)v16 << 15) | ((unsigned __int16)PRO_VRAM[v31] >> 1);
v16 = (unsigned __int16)PRO_VRAM[v31];
PRO_VRAM[v31] = v34;
goto LABEL_63;
case 6:
v29 = ((__int64)v11 << 14) + v15;
v30 = (unsigned __int16)PRO_VRAM[v29];
if ( !v12 )
{
PRO_VRAM[v29] = (4 * v30) | (v16 >> 14);
v16 = v30;
goto LABEL_47;
}
v33 = ((_WORD)v16 << 14) | ((unsigned __int16)PRO_VRAM[v29] >> 2);
v16 = (unsigned __int16)PRO_VRAM[v29];
PRO_VRAM[v29] = v33;
goto LABEL_63;
case 7:
v26 = ((__int64)v11 << 14) + v15;
v27 = (unsigned __int16)PRO_VRAM[v26];
v28 = PRO_VRAM[v26];
if ( v12 )
{
v35 = ((_WORD)v16 << 12) | (v28 >> 4);
v16 = (unsigned __int16)PRO_VRAM[v26];
PRO_VRAM[v26] = v35;
LABEL_63:
pro_vid_mvalid[v15 >> 6] = 0;
LABEL_55:
v15 = ((_WORD)v15 - 1) & 0x3FFF;
}
else
{
PRO_VRAM[v26] = (16 * v28) | (v16 >> 12);
v16 = v27;
LABEL_47:
pro_vid_mvalid[v15 >> 6] = 0;
LABEL_48:
v15 = ((_WORD)v15 + 1) & 0x3FFF;
}
break;
default:
LABEL_54:
pro_vid_mvalid[v15 >> 6] = 0;
if ( v12 )
goto LABEL_55;
goto LABEL_48;
}
}
else
{
switch ( v21 )
{
case 1:
v24 = v17 & 1;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 2:
v25 = v17;
goto LABEL_42;
case 3:
v25 = ~(_BYTE)v17;
LABEL_42:
v24 = v25 & 1;
v21 = 4;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 4:
v21 = 2;
v24 = v17 & 1;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 5:
v21 = 3;
v24 = v17 & 1;
v17 = (v17 >> 1) | (unsigned __int16)((_WORD)v17 << 15);
goto LABEL_28;
case 6:
v24 = 1;
v21 = 3;
goto LABEL_28;
case 7:
v24 = 1;
v21 = 2;
LABEL_28:
v38 = v12;
v37 = v16;
func0(v11, v20, v19, v24, v21);
v12 = v38;
v13 = 0;
v16 = v37;
break;
default:
break;
}
if ( v12 )
{
if ( ++v19 == 256 )
{
++v20;
v19 = 0;
if ( v20 == 1024 )
v20 = 0;
}
}
else if ( ++v20 == 1024 )
{
++v19;
v20 = 0;
if ( v19 == 256 )
v19 = 0;
}
}
++v18;
}
while ( v14 != v18 );
}
++v11;
++v10;
}
while ( v11 != 3 );
pro_vid_pat = v17;
}
LOWORD(v3) = pro_eq_sched(4LL, 1LL);
break;
case 0x3FF914:
LOWORD(pro_vid_pat) = a1;
break;
case 0x3FF916:
pro_vid_mbr = pro_vid_mbr & 0xFFFFFF80 | a1 & 0x7F;
pro_vid_mem_base = pro_vid_mbr << 15;
iotable = pro_vid_mbr << 15;
*((_DWORD *)&iotable + 1) = (pro_vid_mbr << 15) + 0x7FFF;
break;
default:
return v3;
}
return v3;
}

variable_types: vplane int

variable_types: vcount int

variable_types: vpixpat int

variable_types: vwordpat int

variable_types: vsi int

variable_types: pixdata int

variable_types:
vop
int [3]


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

memset(PRO_VRAM, 0, (size_t)&unk_18000);
pro_vid_csr = 0x8000;
pro_vid_p1c = 0;
pro_vid_opc = 0;
pro_vid_scl = 65280;
pro_vid_x = 0;
pro_vid_y = 0;
pro_vid_cnt = 0;
pro_vid_pat = 0;
pro_vid_mbr = 0;
pro_vid_mem_base = 0;
pro_vid_plane_en = 0;
pro_vid_y_offset = 0;
pro_vid_skip = 0;
pro_vid_sched();
pro_screen_reset();
result = pro_screen_init();
if ( (_DWORD)result == -1 )
result = pro_exit();
return result;
}

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

memset(PRO_VRAM, 0, (size_t)&unk_18000);
pro_vid_csr = 0x8000;
pro_vid_p1c = 0;
pro_vid_opc = 0;
pro_vid_scl = 65280;
pro_vid_x = 0;
pro_vid_y = 0;
pro_vid_cnt = 0;
pro_vid_pat = 0;
pro_vid_mbr = 0;
pro_vid_mem_base = 0;
pro_vid_plane_en = 0;
pro_vid_y_offset = 0;
pro_vid_skip = 0;
func1();
pro_screen_reset();
result = pro_screen_init();
if ( (_DWORD)result == -1 )
result = pro_exit();
return result;
}

original_code:
void pro_vid_reset ()
{
        memset(&PRO_VRAM, 0, sizeof(PRO_VRAM));
 pro_vid_csr = 0000000 | 0100000;
 pro_vid_p1c = 0;
 pro_vid_opc = 0;
 pro_vid_scl = 0177400;
 pro_vid_x = 0;
 pro_vid_y = 0;
 pro_vid_cnt = 0;
 pro_vid_pat = 0;
 pro_vid_mbr = 0;
 pro_vid_mem_base = 0;
 pro_vid_plane_en = 0;
 pro_vid_y_offset = 0;
 pro_vid_skip = 0;
 pro_vid_sched();
 pro_screen_reset();
 if (pro_screen_init() == -1)
   pro_exit();
}

canonical_original_code:
void pro_vid_reset()
{
        memset(&PRO_VRAM, 0, sizeof(PRO_VRAM));
 pro_vid_csr = 0000000 | 0100000;
 pro_vid_p1c = 0;
 pro_vid_opc = 0;
 pro_vid_scl = 0177400;
 pro_vid_x = 0;
 pro_vid_y = 0;
 pro_vid_cnt = 0;
 pro_vid_pat = 0;
 pro_vid_mbr = 0;
 pro_vid_mem_base = 0;
 pro_vid_plane_en = 0;
 pro_vid_y_offset = 0;
 pro_vid_skip = 0;
 pro_vid_sched();
 pro_screen_reset();
 if (pro_screen_init() == -1)
   pro_exit();
}


decompiled_code:
// attributes: thunk
__int64 pro_vid_exit()
{
return pro_screen_close();
}

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

original_code:
void pro_vid_exit ()
{
 pro_screen_close();
}

canonical_original_code:
void pro_vid_exit()
{
 pro_screen_close();
}


decompiled_code:
__int64 __fastcall rom_rd(_DWORD *a1, int a2)
{
*a1 = (unsigned __int16)ROM[(a2 - 4173824) >> 1];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2)
{
*a1 = (unsigned __int16)ROM[(a2 - 4173824) >> 1];
return 0LL;
}

original_code:
int rom_rd (int *data, int pa, int access)
{
 *data = ROM[(pa-017730000) >> 1];
 return 0;
}

canonical_original_code:
int rom_rd(int *data, int pa, int access)
{
 *data = ROM[(pa-017730000) >> 1];
 return 0;
}


decompiled_code:
__int64 rom_wr()
{
return 32LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 32LL;
}

original_code:
int rom_wr (int data, int pa, int access)
{
 return (32 + 0);
}

canonical_original_code:
int rom_wr(int data, int pa, int access)
{
 return (32 + 0);
}


decompiled_code:
__int64 __fastcall pro_mem_rd(int a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3FFFFE;
result = 16LL;
if ( v1 != 4192772 )
{
result = (unsigned int)pro_mem_cmd;
if ( v1 != 4192774 )
{
result = 0LL;
if ( v1 == 4192768 )
{
result = (unsigned __int16)MEMROM[pro_mem_ptr];
pro_mem_ptr = ((_WORD)pro_mem_ptr + 1) & 0x3FF;
}
}
}
return result;
}

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

v1 = a1 & 0x3FFFFE;
result = 16LL;
if ( v1 != 4192772 )
{
result = (unsigned int)pro_mem_cmd;
if ( v1 != 4192774 )
{
result = 0LL;
if ( v1 == 4192768 )
{
result = (unsigned __int16)MEMROM[pro_mem_ptr];
pro_mem_ptr = ((_WORD)pro_mem_ptr + 1) & 0x3FF;
}
}
}
return result;
}

original_code:
int pro_mem_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017775000:
     data = MEMROM[pro_mem_ptr++];
     pro_mem_ptr &= 01777;
     break;
   case 017775004:
     data = 020;
     break;
   case 017775006:
     data = pro_mem_cmd;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_mem_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017775000:
     data = MEMROM[pro_mem_ptr++];
     pro_mem_ptr &= 01777;
     break;
   case 017775004:
     data = 020;
     break;
   case 017775006:
     data = pro_mem_cmd;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}


decompiled_code:
char __fastcall pro_mem_wr(char a1, int a2, int a3)
{
int v3; // eax

v3 = a2 & 0x3FFFFE;
if ( (a2 & 0x3FFFFE) == 4192770 )
{
pro_mem_ptr = 0;
}
else if ( v3 == 4192774 )
{
v3 = pro_mem_cmd;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = pro_mem_cmd & 0x78;
v3 |= a1 & 0x87;
}
pro_mem_cmd = v3;
}
else
{
LOBYTE(v3) = pro_mem_cmd & 0x78;
pro_mem_cmd = v3 | a1 & 0x87;
}
}
return v3;
}

canonical_decompiled_code:
char __fastcall func1(char a1, int a2, int a3)
{
int v3; // eax

v3 = a2 & 0x3FFFFE;
if ( (a2 & 0x3FFFFE) == 4192770 )
{
pro_mem_ptr = 0;
}
else if ( v3 == 4192774 )
{
v3 = pro_mem_cmd;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = pro_mem_cmd & 0x78;
v3 |= a1 & 0x87;
}
pro_mem_cmd = v3;
}
else
{
LOBYTE(v3) = pro_mem_cmd & 0x78;
pro_mem_cmd = v3 | a1 & 0x87;
}
}
return v3;
}


decompiled_code:
void pro_mem_reset()
{
pro_mem_ptr = 0;
pro_mem_cmd = 32;
}

canonical_decompiled_code:
void func2()
{
pro_mem_ptr = 0;
pro_mem_cmd = 32;
}

original_code:
void pro_mem_reset ()
{
 pro_mem_ptr = 0;
 pro_mem_cmd = 040;
}

canonical_original_code:
void pro_mem_reset()
{
 pro_mem_ptr = 0;
 pro_mem_cmd = 040;
}


decompiled_code:
void pro_mem_exit()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void pro_mem_exit ()
{
}

canonical_original_code:
void pro_mem_exit()
{
}


decompiled_code:
__int64 __fastcall pro_eq_sched(char a1, int a2)
{
int v2; // esi
int v3; // edx
__int64 result; // rax

v2 = pro_eq_ptr + a2;
v3 = v2 + 11;
while ( 1 )
{
result = v2 & 0x7FFFF;
if ( !PRO_EQ[result] )
break;
if ( ++v2 == v3 )
return result;
}
PRO_EQ[result] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2)
{
int v2; // esi
int v3; // edx
__int64 result; // rax

v2 = pro_eq_ptr + a2;
v3 = v2 + 11;
while ( 1 )
{
result = v2 & 0x7FFFF;
if ( !PRO_EQ[result] )
break;
if ( ++v2 == v3 )
return result;
}
PRO_EQ[result] = a1;
return result;
}

original_code:
void pro_eq_sched (int eventnum, int interval)
{
int i, j;
 for(i=0; i<11; i++)
 {
   j = (pro_eq_ptr + interval + i) & ((1<<19) - 1);
   if (PRO_EQ[j] == 0)
   {
     PRO_EQ[j] = eventnum;
     break;
   }
 }
}

canonical_original_code:
void pro_eq_sched(int eventnum, int interval)
{
int i; int j;
 for(i=0; i<11; i++)
 {
   j = (pro_eq_ptr + interval + i) & ((1<<19) - 1);
   if (PRO_EQ[j] == 0)
   {
     PRO_EQ[j] = eventnum;
     break;
   }
 }
}

variable_types: eventnum int

variable_types: i int

variable_types: j int


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

result = memset(PRO_EQ, 0, (size_t)&unk_80000);
pro_eq_ptr = 0;
return result;
}

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

result = memset(PRO_EQ, 0, (size_t)&unk_80000);
pro_eq_ptr = 0;
return result;
}

original_code:
void pro_eq_reset ()
{
 memset(&PRO_EQ, 0, sizeof(PRO_EQ));
 pro_eq_ptr = 0;
}

canonical_original_code:
void pro_eq_reset()
{
 memset(&PRO_EQ, 0, sizeof(PRO_EQ));
 pro_eq_ptr = 0;
}


jenkins

repo: Cecca/gdem

original_code:
unsigned long long int jenkins(unsigned long long int x, unsigned long long int seed ) {
  unsigned long long int a = seed + x;
  unsigned long long int b = seed;
  unsigned long long int c = 0x9e3779b97f4a7c13L;
  a -= b; a -= c; a ^= c >> 43;
  b -= c; b -= a; b ^= a << 9;
  c -= a; c -= b; c ^= b >> 8;
  a -= b; a -= c; a ^= c >> 38;
  b -= c; b -= a; b ^= a << 23;
  c -= a; c -= b; c ^= b >> 5;
  a -= b; a -= c; a ^= c >> 35;
  b -= c; b -= a; b ^= a << 49;
  c -= a; c -= b; c ^= b >> 11;
  a -= b; a -= c; a ^= c >> 12;
  b -= c; b -= a; b ^= a << 18;
  c -= a; c -= b; c ^= b >> 22;
  return c;
}

canonical_original_code:
unsigned long long jenkins(unsigned long long x, unsigned long long seed) {
  unsigned long long a = seed + x;
  unsigned long long b = seed;
  unsigned long long c = 0x9e3779b97f4a7c13L;
  a -= b; a -= c; a ^= c >> 43;
  b -= c; b -= a; b ^= a << 9;
  c -= a; c -= b; c ^= b >> 8;
  a -= b; a -= c; a ^= c >> 38;
  b -= c; b -= a; b ^= a << 23;
  c -= a; c -= b; c ^= b >> 5;
  a -= b; a -= c; a ^= c >> 35;
  b -= c; b -= a; b ^= a << 49;
  c -= a; c -= b; c ^= b >> 11;
  a -= b; a -= c; a ^= c >> 12;
  b -= c; b -= a; b ^= a << 18;
  c -= a; c -= b; c ^= b >> 22;
  return c;
}

variable_types:
x
unsigned long long

variable_types:
seed
unsigned long long

variable_types:
a
unsigned long long

variable_types:
b
unsigned long long

variable_types:
c
unsigned long long

return_type: unsigned long long


decompiled_code:
void *__fastcall hll_cnt_init(__int64 a1, __int64 a2)
{
int v3; // eax
size_t v4; // rdi
void *result; // rax

v3 = -1;
*(_DWORD *)(a1 + 8) = a2;
v4 = 1 << a2;
*(_QWORD *)a1 = v4;
if ( a2 )
v3 = ~(-1 << (32 - a2));
*(_DWORD *)(a1 + 12) = v3;
result = calloc(v4, 1uLL);
*(_QWORD *)(a1 + 16) = result;
if ( !result )
{
fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58LL);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2)
{
int v3; // eax
size_t v4; // rdi
void *result; // rax

v3 = -1;
*(_DWORD *)(a1 + 8) = a2;
v4 = 1 << a2;
*(_QWORD *)a1 = v4;
if ( a2 )
v3 = ~(-1 << (32 - a2));
*(_DWORD *)(a1 + 12) = v3;
result = calloc(v4, 1uLL);
*(_QWORD *)(a1 + 16) = result;
if ( !result )
{
fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58LL);
exit(1);
}
return result;
}

original_code:
inline void hll_cnt_init (hll_counter_t *counter, size_t bits) {
  ((void) (0));
  counter->b = bits;
  counter->m = 1 << bits;
  if (bits != 0) {
    counter->mask = ~(~0 << (sizeof(hll_hash_t)*8 - bits));
  } else {
    counter->mask = ~0;
  }
  size_t mem = counter->m*sizeof(hll_reg_t);
  counter->registers = (hll_reg_t*) malloc(mem);
  if(counter->registers == 0) { fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58); exit(1); };
  memset(counter->registers, 0, mem);
}

canonical_original_code:
inline void hll_cnt_init(struct hll_counter *counter, unsigned long bits) {
  ((void) (0));
  counter->b = bits;
  counter->m = 1 << bits;
  if (bits != 0) {
    counter->mask = ~(~0 << (sizeof(hll_hash_t)*8 - bits));
  } else {
    counter->mask = ~0;
  }
  unsigned long mem = counter->m*sizeof(hll_reg_t);
  counter->registers = (unsigned char *) malloc(mem);
  if(counter->registers == 0) { fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58); exit(1); };
  memset(counter->registers, 0, mem);
}

variable_types: struct hll_counter { unsigned long m; unsigned int b; unsigned int mask; unsigned char *registers; } *

variable_types:
bits
unsigned long

variable_types:
mem
unsigned long


decompiled_code:
void __fastcall hll_cnt_free(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
inline void hll_cnt_free (hll_counter_t * counter) {
  ((void) (0));
  free(counter->registers);
}

canonical_original_code:
inline void hll_cnt_free(struct hll_counter *counter) {
  ((void) (0));
  free(counter->registers);
}

user_defined_types: struct hll_counter { unsigned long m; unsigned int b; unsigned int mask; unsigned char *registers; }