scmp

decompiled_code:
int __fastcall scmp(char *s1, char *s2, int a3, int a4, int a5, int a6)
{
int v8; // ebx
int result; // eax
int v10; // [rsp+0h] [rbp-48h]

v10 = strlen(s1);
v8 = strlen(s2);
result = strncmp(s1, s2, v8);
if ( result )
return -1;
if ( a6 != a4 && a6 != a5 )
return -1;
if ( a3 != -1 || v10 != v8 )
{
if ( v8 + 1 == v10 )
{
result = s1[v8] - 48;
if ( result < 0 || a3 < result )
result = -1;
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s1, char *s2, int a3, int a4, int a5, int a6)
{
int v8; // ebx
int result; // eax
int v10; // [rsp+0h] [rbp-48h]

v10 = strlen(s1);
v8 = strlen(s2);
result = strncmp(s1, s2, v8);
if ( result )
return -1;
if ( a6 != a4 && a6 != a5 )
return -1;
if ( a3 != -1 || v10 != v8 )
{
if ( v8 + 1 == v10 )
{
result = s1[v8] - 48;
if ( result < 0 || a3 < result )
result = -1;
}
else
{
result = -1;
}
}
return result;
}

original_code:
static int scmp(char *s1, char *s2, int max, int p1, int p2, int numpar)
{
int i, s1len, s2len;
 s1len = strlen(s1);
 s2len = strlen(s2);
 if ((strncmp(s1, s2, s2len) == 0)
     && ((numpar == p1) || (numpar == p2)))
 {
   if ((max == -1) && (s1len == s2len))
     return 0;
   else if (s1len == (s2len+1))
   {
     i = (int)s1[s2len] - 48;
     if ((i>=0) && (i<=max))
       return i;
   }
 }
 return -1;
}

canonical_original_code:
static int scmp(char *s1, char *s2, int max, int p1, int p2, int numpar)
{
int i; int s1len; int s2len;
 s1len = strlen(s1);
 s2len = strlen(s2);
 if ((strncmp(s1, s2, s2len) == 0)
     && ((numpar == p1) || (numpar == p2)))
 {
   if ((max == -1) && (s1len == s2len))
     return 0;
   else if (s1len == (s2len+1))
   {
     i = (int)s1[s2len] - 48;
     if ((i>=0) && (i<=max))
       return i;
   }
 }
 return -1;
}

variable_types: max int

variable_types: numpar int

variable_types: i int


repo: CeRiAl/Xhomer

decompiled_code:
__int64 __fastcall assign_serial(char *s1, _QWORD *a2, int *a3)
{
int v4; // eax
__int64 result; // rax

v4 = scmp(s1, "serial", 3, 1, 1, 1);
if ( v4 < 0 )
{
if ( scmp(s1, "la50", -1, 1, 1, 1) < 0 )
{
if ( scmp(s1, "lk201", -1, 1, 1, 1) < 0 )
{
if ( scmp(s1, "digipad", -1, 1, 1, 1) < 0 )
{
if ( scmp(s1, "null", -1, 1, 1, 1) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*a2 = &pro_null;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_digipad;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_lk201;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_la50;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_serial;
*a3 = v4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, _QWORD *a2, int *a3)
{
int v4; // eax
__int64 result; // rax

v4 = func0(s1, "serial", 3, 1, 1, 1);
if ( v4 < 0 )
{
if ( func0(s1, "la50", -1, 1, 1, 1) < 0 )
{
if ( func0(s1, "lk201", -1, 1, 1, 1) < 0 )
{
if ( func0(s1, "digipad", -1, 1, 1, 1) < 0 )
{
if ( func0(s1, "null", -1, 1, 1, 1) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*a2 = &pro_null;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_digipad;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_lk201;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_la50;
*a3 = 0;
result = 0LL;
}
}
else
{
*a2 = &pro_serial;
*a3 = v4;
result = 0LL;
}
return result;
}

original_code:
static int assign_serial(char *s1, struct sercall **dev, int *port)
{
int i, j;
 j = 0;
 if ((i = scmp(s1, "serial\0", 3, 1, 1, 1)) > -1)
 {
   *dev = &pro_serial;
   *port = i;
 }
 else if ((i = scmp(s1, "la50\0", -1, 1, 1, 1)) > -1)
 {
   *dev = &pro_la50;
   *port = 0;
 }
 else if (scmp(s1, "lk201\0", -1, 1, 1, 1) > -1)
 {
   *dev = &pro_lk201;
   *port = 0;
 }
 else if (scmp(s1, "digipad\0", -1, 1, 1, 1) > -1)
 {
   *dev = &pro_digipad;
   *port = 0;
 }
 else if (scmp(s1, "null\0", -1, 1, 1, 1) > -1)
 {
   *dev = &pro_null;
   *port = 0;
 }
 else
   j = -1;
 return j;
}

canonical_original_code:
static int assign_serial(char *s1, struct sercall **dev, int *port)
{
int i; int j;
 j = 0;
 if ((i = scmp(s1, "serial\0", 3, 1, 1, 1)) > -1)
 {
   *dev = &pro_serial;
   *port = i;
 }
 else if ((i = scmp(s1, "la50\0", -1, 1, 1, 1)) > -1)
 {
   *dev = &pro_la50;
   *port = 0;
 }
 else if (scmp(s1, "lk201\0", -1, 1, 1, 1) > -1)
 {
   *dev = &pro_lk201;
   *port = 0;
 }
 else if (scmp(s1, "digipad\0", -1, 1, 1, 1) > -1)
 {
   *dev = &pro_digipad;
   *port = 0;
 }
 else if (scmp(s1, "null\0", -1, 1, 1, 1) > -1)
 {
   *dev = &pro_null;
   *port = 0;
 }
 else
   j = -1;
 return j;
}

variable_types: struct sercall { int (*get)(); int (*put)(); void (*ctrl_get)(); void (*ctrl_put)(); void (*reset)(); void (*exit)(); } **

variable_types:
port
int *

variable_types: j int

return_type: int


decompiled_code:
__int64 pro_ptr_rd()
{
return pro_2661ptr_rd();
}

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

original_code:
int pro_ptr_rd (int pa)
{
 return pro_2661ptr_rd(pa);
}

canonical_original_code:
int pro_ptr_rd(int pa)
{
 return pro_2661ptr_rd(pa);
}

variable_types: pa int


decompiled_code:
__int64 pro_ptr_wr()
{
return pro_2661ptr_wr();
}

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

original_code:
void pro_ptr_wr (int data, int pa, int access)
{
 pro_2661ptr_wr(data, pa, access);
}

canonical_original_code:
void pro_ptr_wr(int data, int pa, int access)
{
 pro_2661ptr_wr(data, pa, access);
}

variable_types: data int

variable_types: access int

return_type: void


decompiled_code:
__int64 pro_ptr_open()
{
return pro_2661ptr_open();
}

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

original_code:
void pro_ptr_open ()
{
 pro_2661ptr_open();
}

canonical_original_code:
void pro_ptr_open()
{
 pro_2661ptr_open();
}


decompiled_code:
__int64 pro_ptr_reset()
{
pro_2661ptr_reset();
return pro_ptr_open();
}

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

original_code:
void pro_ptr_reset ()
{
 pro_2661ptr_reset();
 pro_ptr_open();
}

canonical_original_code:
void pro_ptr_reset()
{
 pro_2661ptr_reset();
 pro_ptr_open();
}


decompiled_code:
__int64 pro_ptr_exit()
{
return (*(__int64 (__fastcall **)(__int64))(pro_ptr + 40LL))(1LL);
}

original_code:
void pro_ptr_exit ()
{
 pro_ptr->exit(1);
}

canonical_original_code:
void pro_ptr_exit()
{
 pro_ptr->exit(1);
}


decompiled_code:
char pro_2661kb_ctrl_get()
{
int v0; // eax

(*(void (__fastcall **)(_QWORD, __int64 *))(pro_kb + 16LL))(0LL, &pro_2661kb_ctrl);
v0 = pro_2661kb_stat;
LOBYTE(v0) = pro_2661kb_stat & 0x7F;
pro_2661kb_stat = v0;
if ( *((_DWORD *)&pro_2661kb_ctrl + 7) == 1 )
{
LOBYTE(v0) = v0 | 0x80;
pro_2661kb_stat = v0;
}
return v0;
}

canonical_decompiled_code:
char func0()
{
int v0; // eax

(*(void (__fastcall **)(_QWORD, __int64 *))(pro_kb + 16LL))(0LL, &pro_2661kb_ctrl);
v0 = pro_2661kb_stat;
LOBYTE(v0) = pro_2661kb_stat & 0x7F;
pro_2661kb_stat = v0;
if ( *((_DWORD *)&pro_2661kb_ctrl + 7) == 1 )
{
LOBYTE(v0) = v0 | 0x80;
pro_2661kb_stat = v0;
}
return v0;
}

original_code:
static void pro_2661kb_ctrl_get ()
{
 pro_kb->ctrl_get(0, &pro_2661kb_ctrl);
 pro_2661kb_stat = (pro_2661kb_stat & ~0200);
 if (pro_2661kb_ctrl.dsr == 1)
   pro_2661kb_stat |= 0200;
}

canonical_original_code:
static void pro_2661kb_ctrl_get()
{
 pro_kb->ctrl_get(0, &pro_2661kb_ctrl);
 pro_2661kb_stat = (pro_2661kb_stat & ~0200);
 if (pro_2661kb_ctrl.dsr == 1)
   pro_2661kb_stat |= 0200;
}


decompiled_code:
__int64 pro_2661kb_poll_sched()
{
return pro_eq_sched(6LL, 10000LL);
}

canonical_decompiled_code:
__int64 func2()
{
return pro_eq_sched(6LL, 10000LL);
}

original_code:
static void pro_2661kb_poll_sched ()
{
 pro_eq_sched(6, 10000);
}

canonical_original_code:
static void pro_2661kb_poll_sched()
{
 pro_eq_sched(6, 10000);
}


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

if ( (pro_2661kb_cmd & 0xC0) == 0
&& (*(unsigned int (__fastcall **)(_QWORD, _QWORD))(pro_kb + 8LL))(0LL, (unsigned int)pro_2661kb_wdata) == -1 )
{
return pro_eq_sched(5LL, 1000LL);
}
pro_2661kb_stat |= 1u;
pro_int_set(4LL);
result = (unsigned __int8)pro_2661kb_cmd & 0xC0;
if ( (_DWORD)result == 128 )
{
pro_2661kb_data = pro_2661kb_wdata;
pro_2661kb_stat |= 2u;
result = pro_int_set(2LL);
}
return result;
}

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

if ( (pro_2661kb_cmd & 0xC0) == 0
&& (*(unsigned int (__fastcall **)(_QWORD, _QWORD))(pro_kb + 8LL))(0LL, (unsigned int)pro_2661kb_wdata) == -1 )
{
return pro_eq_sched(5LL, 1000LL);
}
pro_2661kb_stat |= 1u;
pro_int_set(4LL);
result = (unsigned __int8)pro_2661kb_cmd & 0xC0;
if ( (_DWORD)result == 128 )
{
pro_2661kb_data = pro_2661kb_wdata;
pro_2661kb_stat |= 2u;
result = pro_int_set(2LL);
}
return result;
}


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

v1 = a1 & 6;
if ( v1 == 4 )
{
if ( pro_2661kb_mode_ptr )
{
result = (unsigned int)pro_2661kb_mr2;
pro_2661kb_mode_ptr = 0;
}
else
{
result = (unsigned int)pro_2661kb_mr1;
pro_2661kb_mode_ptr = 1;
}
}
else if ( v1 > 4 )
{
if ( v1 == 6 )
{
result = (unsigned int)pro_2661kb_cmd;
pro_2661kb_mode_ptr = pro_2661kb_mode_ptr == 0;
}
else
{
result = 0LL;
}
}
else if ( v1 )
{
if ( v1 == 2 )
{
pro_2661kb_ctrl_get();
result = (unsigned int)pro_2661kb_stat;
}
else
{
result = 0LL;
}
}
else
{
result = (unsigned int)pro_2661kb_data;
pro_2661kb_stat &= 0xFFFFFFFD;
}
return result;
}

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

v1 = a1 & 6;
if ( v1 == 4 )
{
if ( pro_2661kb_mode_ptr )
{
result = (unsigned int)pro_2661kb_mr2;
pro_2661kb_mode_ptr = 0;
}
else
{
result = (unsigned int)pro_2661kb_mr1;
pro_2661kb_mode_ptr = 1;
}
}
else if ( v1 > 4 )
{
if ( v1 == 6 )
{
result = (unsigned int)pro_2661kb_cmd;
pro_2661kb_mode_ptr = pro_2661kb_mode_ptr == 0;
}
else
{
result = 0LL;
}
}
else if ( v1 )
{
if ( v1 == 2 )
{
func0();
result = (unsigned int)pro_2661kb_stat;
}
else
{
result = 0LL;
}
}
else
{
result = (unsigned int)pro_2661kb_data;
pro_2661kb_stat &= 0xFFFFFFFD;
}
return result;
}

original_code:
int pro_2661kb_rd (int pa)
{
int data;
 switch (pa & 06)
 {
   case 00:
     data = pro_2661kb_data;
     pro_2661kb_stat = pro_2661kb_stat & ~0002;
     break;
   case 02:
     pro_2661kb_ctrl_get();
     data = pro_2661kb_stat;
     break;
   case 04:
     if (pro_2661kb_mode_ptr == 0)
     {
       data = pro_2661kb_mr1;
       pro_2661kb_mode_ptr = 1;
     }
     else
     {
       data = pro_2661kb_mr2;
       pro_2661kb_mode_ptr = 0;
     }
     break;
   case 06:
     data = pro_2661kb_cmd;
     if (pro_2661kb_mode_ptr == 0)
       pro_2661kb_mode_ptr = 1;
     else
       pro_2661kb_mode_ptr = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_2661kb_rd(int pa)
{
int data;
 switch (pa & 06)
 {
   case 00:
     data = pro_2661kb_data;
     pro_2661kb_stat = pro_2661kb_stat & ~0002;
     break;
   case 02:
     pro_2661kb_ctrl_get();
     data = pro_2661kb_stat;
     break;
   case 04:
     if (pro_2661kb_mode_ptr == 0)
     {
       data = pro_2661kb_mr1;
       pro_2661kb_mode_ptr = 1;
     }
     else
     {
       data = pro_2661kb_mr2;
       pro_2661kb_mode_ptr = 0;
     }
     break;
   case 06:
     data = pro_2661kb_cmd;
     if (pro_2661kb_mode_ptr == 0)
       pro_2661kb_mode_ptr = 1;
     else
       pro_2661kb_mode_ptr = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}


decompiled_code:
__int64 __fastcall pro_2661kb_wr(unsigned __int8 a1, char a2, int a3)
{
__int64 result; // rax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax

result = a2 & 6;
if ( (_DWORD)result == 4 )
{
if ( pro_2661kb_mode_ptr )
{
if ( a3 == 4 )
{
v9 = pro_2661kb_mr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v9) = 0;
v9 |= a1;
}
pro_2661kb_mr2 = v9;
}
else
{
v8 = pro_2661kb_mr2;
LOBYTE(v8) = 0;
pro_2661kb_mr2 = v8 | a1;
}
pro_2661kb_mode_ptr = 0;
}
else
{
if ( a3 == 4 )
{
v7 = pro_2661kb_mr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v7) = 0;
v7 |= a1;
}
pro_2661kb_mr1 = v7;
}
else
{
v6 = pro_2661kb_mr1;
LOBYTE(v6) = 0;
pro_2661kb_mr1 = v6 | a1;
}
pro_2661kb_mode_ptr = 1;
}
result = pro_2661kb_ctrl_put();
}
else if ( (_DWORD)result == 6 )
{
if ( a3 == 4 )
{
v12 = pro_2661kb_cmd;
if ( (a2 & 1) == 0 )
{
LOBYTE(v12) = pro_2661kb_cmd & 0x10;
v12 |= a1 & 0xEF;
}
pro_2661kb_cmd = v12;
}
else
{
v10 = pro_2661kb_cmd;
LOBYTE(v10) = pro_2661kb_cmd & 0x10;
pro_2661kb_cmd = v10 | a1 & 0xEF;
}
if ( (pro_2661kb_cmd & 4) == 0 )
pro_2661kb_stat &= 0xFFFFFFFD;
if ( (pro_2661kb_cmd & 1) != 0 )
v11 = pro_2661kb_stat | 1;
else
v11 = pro_2661kb_stat & 0xFFFFFFFE;
pro_2661kb_stat = v11;
result = pro_2661kb_ctrl_put();
}
else if ( (a2 & 6) == 0 && (pro_2661kb_cmd & 1) != 0 )
{
if ( a3 == 4 )
{
v5 = pro_2661kb_wdata;
if ( (a2 & 1) == 0 )
{
LOBYTE(v5) = 0;
v5 |= a1;
}
pro_2661kb_wdata = v5;
}
else
{
v4 = pro_2661kb_wdata;
LOBYTE(v4) = 0;
pro_2661kb_wdata = v4 | a1;
}
pro_2661kb_stat &= 0xFFFFFFFE;
result = pro_eq_sched(5LL, 2LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1, char a2, int a3)
{
__int64 result; // rax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax

result = a2 & 6;
if ( (_DWORD)result == 4 )
{
if ( pro_2661kb_mode_ptr )
{
if ( a3 == 4 )
{
v9 = pro_2661kb_mr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v9) = 0;
v9 |= a1;
}
pro_2661kb_mr2 = v9;
}
else
{
v8 = pro_2661kb_mr2;
LOBYTE(v8) = 0;
pro_2661kb_mr2 = v8 | a1;
}
pro_2661kb_mode_ptr = 0;
}
else
{
if ( a3 == 4 )
{
v7 = pro_2661kb_mr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v7) = 0;
v7 |= a1;
}
pro_2661kb_mr1 = v7;
}
else
{
v6 = pro_2661kb_mr1;
LOBYTE(v6) = 0;
pro_2661kb_mr1 = v6 | a1;
}
pro_2661kb_mode_ptr = 1;
}
result = func1();
}
else if ( (_DWORD)result == 6 )
{
if ( a3 == 4 )
{
v12 = pro_2661kb_cmd;
if ( (a2 & 1) == 0 )
{
LOBYTE(v12) = pro_2661kb_cmd & 0x10;
v12 |= a1 & 0xEF;
}
pro_2661kb_cmd = v12;
}
else
{
v10 = pro_2661kb_cmd;
LOBYTE(v10) = pro_2661kb_cmd & 0x10;
pro_2661kb_cmd = v10 | a1 & 0xEF;
}
if ( (pro_2661kb_cmd & 4) == 0 )
pro_2661kb_stat &= 0xFFFFFFFD;
if ( (pro_2661kb_cmd & 1) != 0 )
v11 = pro_2661kb_stat | 1;
else
v11 = pro_2661kb_stat & 0xFFFFFFFE;
pro_2661kb_stat = v11;
result = func1();
}
else if ( (a2 & 6) == 0 && (pro_2661kb_cmd & 1) != 0 )
{
if ( a3 == 4 )
{
v5 = pro_2661kb_wdata;
if ( (a2 & 1) == 0 )
{
LOBYTE(v5) = 0;
v5 |= a1;
}
pro_2661kb_wdata = v5;
}
else
{
v4 = pro_2661kb_wdata;
LOBYTE(v4) = 0;
pro_2661kb_wdata = v4 | a1;
}
pro_2661kb_stat &= 0xFFFFFFFE;
result = pro_eq_sched(5LL, 2LL);
}
return result;
}


decompiled_code:
char pro_2661kb_open()
{
(*(void (__fastcall **)(_QWORD, _QWORD))(pro_kb + 32LL))(0LL, pro_kb_port);
pro_2661kb_ctrl_put();
return pro_2661kb_ctrl_get();
}

canonical_decompiled_code:
char func8()
{
(*(void (__fastcall **)(_QWORD, _QWORD))(pro_kb + 32LL))(0LL, pro_kb_port);
func1();
return func0();
}

original_code:
void pro_2661kb_open ()
{
 pro_kb->reset(0, pro_kb_port);
 pro_2661kb_ctrl_put();
 pro_2661kb_ctrl_get();
}

canonical_original_code:
void pro_2661kb_open()
{
 pro_kb->reset(0, pro_kb_port);
 pro_2661kb_ctrl_put();
 pro_2661kb_ctrl_get();
}


decompiled_code:
__int64 __fastcall pro_serial_get(int a1)
{
__int64 v2; // rdx
int v3; // eax
int v4; // edi
int v5; // eax
unsigned int v6; // ecx
int v8; // eax

v2 = a1;
v3 = pro_ser_cnt[a1];
pro_ser_cnt[a1] = v3 + 1;
if ( v3 > 14 )
{
v4 = pro_ser_sfd[a1];
if ( v4 != -1 )
{
v8 = read(v4, &pro_ser_rbuf[16 * v2], 0x10uLL);
if ( v8 > 0 )
{
pro_ser_xfer[a1] = v8;
pro_ser_level[a1] = 0;
}
}
pro_ser_cnt[a1] = 0;
}
v5 = pro_ser_level[a1];
v6 = 256;
if ( v5 != pro_ser_xfer[a1] )
{
pro_ser_level[a1] = v5 + 1;
v6 = (unsigned __int8)pro_ser_rbuf[16 * a1 + v5];
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v2; // rdx
int v3; // eax
int v4; // edi
int v5; // eax
unsigned int v6; // ecx
int v8; // eax

v2 = a1;
v3 = pro_ser_cnt[a1];
pro_ser_cnt[a1] = v3 + 1;
if ( v3 > 14 )
{
v4 = pro_ser_sfd[a1];
if ( v4 != -1 )
{
v8 = read(v4, &pro_ser_rbuf[16 * v2], 0x10uLL);
if ( v8 > 0 )
{
pro_ser_xfer[a1] = v8;
pro_ser_level[a1] = 0;
}
}
pro_ser_cnt[a1] = 0;
}
v5 = pro_ser_level[a1];
v6 = 256;
if ( v5 != pro_ser_xfer[a1] )
{
pro_ser_level[a1] = v5 + 1;
v6 = (unsigned __int8)pro_ser_rbuf[16 * a1 + v5];
}
return v6;
}

original_code:
int pro_serial_get (int dev)
{
int schar, sstat;
 if (pro_ser_cnt[dev]++ >= (16 -1))
 {
   if (pro_ser_sfd[dev] != -1)
   {
     sstat = (int)read(pro_ser_sfd[dev], &pro_ser_rbuf[dev], 16);
     if (sstat > 0)
     {
       pro_ser_xfer[dev] = sstat;
       pro_ser_level[dev] = 0;
     }
   }
   pro_ser_cnt[dev] = 0;
 }
 if (pro_ser_level[dev] == pro_ser_xfer[dev])
   schar = 256;
 else
   schar = (int)pro_ser_rbuf[dev][pro_ser_level[dev]++];
 return schar;
}

canonical_original_code:
int pro_serial_get(int dev)
{
int schar; int sstat;
 if (pro_ser_cnt[dev]++ >= (16 -1))
 {
   if (pro_ser_sfd[dev] != -1)
   {
     sstat = (int)read(pro_ser_sfd[dev], &pro_ser_rbuf[dev], 16);
     if (sstat > 0)
     {
       pro_ser_xfer[dev] = sstat;
       pro_ser_level[dev] = 0;
     }
   }
   pro_ser_cnt[dev] = 0;
 }
 if (pro_ser_level[dev] == pro_ser_xfer[dev])
   schar = 256;
 else
   schar = (int)pro_ser_rbuf[dev][pro_ser_level[dev]++];
 return schar;
}

variable_types: dev int

variable_types: schar int

variable_types: sstat int


original_code:
void pro_serial_ctrl_get(int dev, struct serctrl *sctrl)
{
int mlines;
 if (pro_ser_sfd[dev] != -1)
 {
   ioctl(pro_ser_sfd[dev], 0x5415, &mlines);
   sctrl->dsr = ((mlines&0x100) ? 1:0);
   sctrl->cts = ((mlines&0x020) ? 1:0);
   sctrl->ri = ((mlines&0x080) ? 1:0);
   sctrl->cd = ((mlines&0x040) ? 1:0);
   sctrl->perror = 0;
   sctrl->ibrk = 0;
 }
}

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

variable_types: mlines int


decompiled_code:
__int64 __fastcall pro_serial_put(int a1, char a2)
{
int v2; // ebx
__int64 result; // rax
char buf; // [rsp+Bh] [rbp-Dh] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = pro_ser_sfd[a1];
result = 1LL;
if ( v2 != -1 )
{
buf = a2;
if ( pro_lp_workaround == 1 )
{
v5[0] = 0;
return 2 * (unsigned int)(write(v2, &buf, 1uLL) != -1) - 1;
}
ioctl(v2, 0x5411uLL, v5);
if ( v5[0] <= 2 )
return 2 * (unsigned int)(write(v2, &buf, 1uLL) != -1) - 1;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char a2)
{
int v2; // ebx
__int64 result; // rax
char buf; // [rsp+Bh] [rbp-Dh] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = pro_ser_sfd[a1];
result = 1LL;
if ( v2 != -1 )
{
buf = a2;
if ( pro_lp_workaround == 1 )
{
v5[0] = 0;
return 2 * (unsigned int)(write(v2, &buf, 1uLL) != -1) - 1;
}
ioctl(v2, 0x5411uLL, v5);
if ( v5[0] <= 2 )
return 2 * (unsigned int)(write(v2, &buf, 1uLL) != -1) - 1;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int pro_serial_put (int dev, int schar)
{
int stat, bufdepth;
unsigned char c;
 if (pro_ser_sfd[dev] != -1)
 {
   c = (unsigned char)(schar);
   if (pro_lp_workaround != 1)
     ioctl(pro_ser_sfd[dev], 0x5411, &bufdepth);
   else
     bufdepth = 0;
   if (bufdepth > 2)
     stat = -1;
   else
     switch (write(pro_ser_sfd[dev], &c, 1))
     {
       case -1:
         stat = -1;
         break;
       default:
         stat = 1;
     }
 }
 else
   stat = 1;
 return stat;
}

canonical_original_code:
int pro_serial_put(int dev, int schar)
{
int stat; int bufdepth;
unsigned char c;
 if (pro_ser_sfd[dev] != -1)
 {
   c = (unsigned char)(schar);
   if (pro_lp_workaround != 1)
     ioctl(pro_ser_sfd[dev], 0x5411, &bufdepth);
   else
     bufdepth = 0;
   if (bufdepth > 2)
     stat = -1;
   else
     switch (write(pro_ser_sfd[dev], &c, 1))
     {
       case -1:
         stat = -1;
         break;
       default:
         stat = 1;
     }
 }
 else
   stat = 1;
 return stat;
}

variable_types: stat int

variable_types: bufdepth int

variable_types:
c
unsigned char


original_code:
void pro_serial_ctrl_put(int dev, struct serctrl *sctrl)
{
const tcflag_t cs[] = {0000000, 0000020, 0000040, 0000060};
const tcflag_t stop[] = {0, 0, 0, 0000100};
const tcflag_t parity[] = {0001000, 0};
const tcflag_t penable[] = {0, 0000400};
const speed_t baud[] = {0000001, 0000002, 0000003, 0000004, 0000005, 0000007, 0000010, 0000011,
                 0000012, 0000000, 0000013, 0000000, 0000014, 0000000, 0000015, 0000016};
int mlines;
struct termios serpar;
 if (pro_ser_sfd[dev] != -1)
 {
   memset(&serpar, 0, sizeof(serpar));
   mlines = 0;
   serpar.c_iflag = 0000004 | 0000001;
   serpar.c_oflag = 0;
   serpar.c_cflag = 0000200 | 0004000;
   serpar.c_lflag = 0;
   serpar.c_cflag |= cs[(sctrl->cs)&03];
   serpar.c_cflag |= stop[(sctrl->stop)&03];
   serpar.c_cflag |= parity[(sctrl->parity)&01];
   serpar.c_cflag |= penable[(sctrl->penable)&01];
   cfsetispeed(&serpar, baud[(sctrl->ibaud)&017]);
   cfsetospeed(&serpar, baud[(sctrl->obaud)&017]);
   tcsetattr(pro_ser_sfd[dev], 0, &serpar);
   mlines |= ((sctrl->dtr) ? 0x002:0);
   mlines |= ((sctrl->rts) ? 0x004:0);
   ioctl(pro_ser_sfd[dev], 0x5418, &mlines);
   if ((sctrl->obrk) == 1)
     tcsendbreak(pro_ser_sfd[dev], 0);
 }
}

canonical_original_code:
void pro_serial_ctrl_put(int dev, struct serctrl *sctrl)
{
unsigned int cs[] = {0000000, 0000020, 0000040, 0000060};
unsigned int stop[] = {0, 0, 0, 0000100};
unsigned int parity[] = {0001000, 0};
unsigned int penable[] = {0, 0000400};
unsigned int baud[] = {0000001, 0000002, 0000003, 0000004, 0000005, 0000007, 0000010, 0000011,
                 0000012, 0000000, 0000013, 0000000, 0000014, 0000000, 0000015, 0000016};
int mlines;
struct termios serpar;
 if (pro_ser_sfd[dev] != -1)
 {
   memset(&serpar, 0, sizeof(serpar));
   mlines = 0;
   serpar.c_iflag = 0000004 | 0000001;
   serpar.c_oflag = 0;
   serpar.c_cflag = 0000200 | 0004000;
   serpar.c_lflag = 0;
   serpar.c_cflag |= cs[(sctrl->cs)&03];
   serpar.c_cflag |= stop[(sctrl->stop)&03];
   serpar.c_cflag |= parity[(sctrl->parity)&01];
   serpar.c_cflag |= penable[(sctrl->penable)&01];
   cfsetispeed(&serpar, baud[(sctrl->ibaud)&017]);
   cfsetospeed(&serpar, baud[(sctrl->obaud)&017]);
   tcsetattr(pro_ser_sfd[dev], 0, &serpar);
   mlines |= ((sctrl->dtr) ? 0x002:0);
   mlines |= ((sctrl->rts) ? 0x004:0);
   ioctl(pro_ser_sfd[dev], 0x5418, &mlines);
   if ((sctrl->obrk) == 1)
     tcsendbreak(pro_ser_sfd[dev], 0);
 }
}

variable_types:
cs
unsigned int []

variable_types:
stop
unsigned int []

variable_types:
parity
unsigned int []

variable_types:
penable
unsigned int []

variable_types:
baud
unsigned int []

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

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 __fastcall pro_serial_reset(int a1, int a2)
{
int v2; // ebp

if ( pro_ser_sfd[a1] == -1 )
{
v2 = open((const char *)pro_serial_devname[a2], 2050);
pro_ser_sfd[a1] = v2;
if ( v2 == -1 )
{
perror("Serial port failure");
}
else
{
tcgetattr(v2, (struct termios *)&pro_ser_par_save + a1);
ioctl(v2, 0x5415uLL, (char *)&pro_ser_mlines_save + 4 * a1);
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2)
{
int v2; // ebp

if ( pro_ser_sfd[a1] == -1 )
{
v2 = open((const char *)pro_serial_devname[a2], 2050);
pro_ser_sfd[a1] = v2;
if ( v2 == -1 )
{
perror("Serial port failure");
}
else
{
tcgetattr(v2, (struct termios *)&pro_ser_par_save + a1);
ioctl(v2, 0x5415uLL, (char *)&pro_ser_mlines_save + 4 * a1);
}
}
}

original_code:
void pro_serial_reset (int dev, int portnum)
{
 if (pro_ser_sfd[dev] == -1)
 {
   pro_ser_sfd[dev] = open(pro_serial_devname[portnum], 02|04000);
   if (pro_ser_sfd[dev] == -1)
   {
     perror("Serial port failure");
   }
   else
   {
     tcgetattr(pro_ser_sfd[dev], &pro_ser_par_save[dev]);
     ioctl(pro_ser_sfd[dev], 0x5415, &pro_ser_mlines_save[dev]);
   }
 }
}

canonical_original_code:
void pro_serial_reset(int dev, int portnum)
{
 if (pro_ser_sfd[dev] == -1)
 {
   pro_ser_sfd[dev] = open(pro_serial_devname[portnum], 02|04000);
   if (pro_ser_sfd[dev] == -1)
   {
     perror("Serial port failure");
   }
   else
   {
     tcgetattr(pro_ser_sfd[dev], &pro_ser_par_save[dev]);
     ioctl(pro_ser_sfd[dev], 0x5415, &pro_ser_mlines_save[dev]);
   }
 }
}

variable_types: portnum int


decompiled_code:
int __fastcall pro_serial_exit(int a1)
{
int result; // eax
int v2; // ebp

result = a1;
v2 = pro_ser_sfd[a1];
if ( v2 != -1 )
{
tcsetattr(v2, 0, (const struct termios *)&pro_ser_par_save + a1);
ioctl(v2, 0x5418uLL, (char *)&pro_ser_mlines_save + 4 * a1);
result = close(v2);
pro_ser_sfd[a1] = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int result; // eax
int v2; // ebp

result = a1;
v2 = pro_ser_sfd[a1];
if ( v2 != -1 )
{
tcsetattr(v2, 0, (const struct termios *)&pro_ser_par_save + a1);
ioctl(v2, 0x5418uLL, (char *)&pro_ser_mlines_save + 4 * a1);
result = close(v2);
pro_ser_sfd[a1] = -1;
}
return result;
}

original_code:
void pro_serial_exit (int dev)
{
 if (pro_ser_sfd[dev] != -1)
 {
   tcsetattr(pro_ser_sfd[dev], 0, &pro_ser_par_save[dev]);
   ioctl(pro_ser_sfd[dev], 0x5418, &pro_ser_mlines_save[dev]);
   close(pro_ser_sfd[dev]);
   pro_ser_sfd[dev] = -1;
 }
}

canonical_original_code:
void pro_serial_exit(int dev)
{
 if (pro_ser_sfd[dev] != -1)
 {
   tcsetattr(pro_ser_sfd[dev], 0, &pro_ser_par_save[dev]);
   ioctl(pro_ser_sfd[dev], 0x5418, &pro_ser_mlines_save[dev]);
   close(pro_ser_sfd[dev]);
   pro_ser_sfd[dev] = -1;
 }
}


decompiled_code:
__int64 __fastcall pro_maint_rd(char a1)
{
__int64 result; // rax
int v2; // edi

result = 0LL;
if ( pro_maint_mode == 1 )
{
v2 = a1 & 6;
switch ( v2 )
{
case 2:
result = pro_ptr_rd(0LL);
break;
case 4:
result = pro_ptr_rd(2LL) & 1;
if ( (_DWORD)result )
result = 128LL;
break;
case 0:
result = pro_ptr_rd(2LL) & 2;
if ( (_DWORD)result )
result = 128LL;
break;
}
}
return result;
}

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

result = 0LL;
if ( pro_maint_mode == 1 )
{
v2 = a1 & 6;
switch ( v2 )
{
case 2:
result = pro_ptr_rd(0LL);
break;
case 4:
result = pro_ptr_rd(2LL) & 1;
if ( (_DWORD)result )
result = 128LL;
break;
case 0:
result = pro_ptr_rd(2LL) & 2;
if ( (_DWORD)result )
result = 128LL;
break;
}
}
return result;
}

original_code:
int pro_maint_rd (int pa)
{
int data;
 if (pro_maint_mode == 1)
   switch (pa & 06)
   {
     case 00:
       data = (pro_ptr_rd(02) & 0002) ? 0200 : 0;
       break;
     case 02:
       data = pro_ptr_rd(00);
       break;
     case 04:
       data = (pro_ptr_rd(2) & 0001) ? 0200 : 0;
       break;
     case 06:
       data = 0;
       break;
     default:
       data = 0;
       break;
   }
 else
   data = 0;
 return data;
}

canonical_original_code:
int pro_maint_rd(int pa)
{
int data;
 if (pro_maint_mode == 1)
   switch (pa & 06)
   {
     case 00:
       data = (pro_ptr_rd(02) & 0002) ? 0200 : 0;
       break;
     case 02:
       data = pro_ptr_rd(00);
       break;
     case 04:
       data = (pro_ptr_rd(2) & 0001) ? 0200 : 0;
       break;
     case 06:
       data = 0;
       break;
     default:
       data = 0;
       break;
   }
 else
   data = 0;
 return data;
}

variable_types: pa int

variable_types: data int


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

if ( pro_maint_mode == 1 && (a2 & 6) == 6 )
result = pro_ptr_wr(a1, 0LL);
return result;
}

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

if ( pro_maint_mode == 1 && (a2 & 6) == 6 )
result = pro_ptr_wr(a1, 0LL);
return result;
}

original_code:
void pro_maint_wr (int data, int pa, int access)
{
 if (pro_maint_mode == 1)
   switch (pa & 06)
   {
     case 00:
     case 02:
     case 04:
       break;
     case 06:
       pro_ptr_wr(data, 00, access);
       break;
   }
}

canonical_original_code:
void pro_maint_wr(int data, int pa, int access)
{
 if (pro_maint_mode == 1)
   switch (pa & 06)
   {
     case 00:
     case 02:
     case 04:
       break;
     case 06:
       pro_ptr_wr(data, 00, access);
       break;
   }
}

variable_types: access int


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

pro_rx_csr0_s = pro_rx_csr0_c & 0x76 | 8;
pro_rx_csr1_s = 0;
pro_rx_csr2_s = pro_rx_csr1_c;
pro_rx_csr3_s = (4 * pro_rx_ready[(pro_rx_csr0_c >> 1) & 3]) | (8 * pro_rx_wprot[(pro_rx_csr0_c >> 1) & 3]) | pro_rx_exist[(pro_rx_csr0_c >> 1) & 3] | (16 * pro_rx_vchanged) | (32 * dword_9E4) | (dword_9E8 << 6) | (dword_9EC << 7);
result = (4 * dword_A14) | pro_rx_exist[0] | (16 * dword_A18) | (unsigned int)(dword_A1C << 6);
pro_rx_csr4_s = (4 * dword_A14) | pro_rx_exist[0] | (16 * dword_A18) | (dword_A1C << 6);
return result;
}

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

pro_rx_csr0_s = pro_rx_csr0_c & 0x76 | 8;
pro_rx_csr1_s = 0;
pro_rx_csr2_s = pro_rx_csr1_c;
pro_rx_csr3_s = (4 * pro_rx_ready[(pro_rx_csr0_c >> 1) & 3]) | (8 * pro_rx_wprot[(pro_rx_csr0_c >> 1) & 3]) | pro_rx_exist[(pro_rx_csr0_c >> 1) & 3] | (16 * pro_rx_vchanged) | (32 * dword_9E4) | (dword_9E8 << 6) | (dword_9EC << 7);
result = (4 * dword_A14) | pro_rx_exist[0] | (16 * dword_A18) | (unsigned int)(dword_A1C << 6);
pro_rx_csr4_s = (4 * dword_A14) | pro_rx_exist[0] | (16 * dword_A18) | (dword_A1C << 6);
return result;
}

original_code:
static void pro_rx_set_maintstat ()
{
int disknum;
 disknum = (pro_rx_csr0_c & 0006) >> 1;
 pro_rx_csr0_s = (pro_rx_csr0_c & (0160 | 0006)) | 0010;
 pro_rx_csr1_s = 0;
 pro_rx_csr2_s = pro_rx_csr1_c;
 pro_rx_csr3_s = (pro_rx_vchanged[3] << 7)
                 | (pro_rx_vchanged[2] << 6)
                 | (pro_rx_vchanged[1] << 5)
                 | (pro_rx_vchanged[0] << 4)
                 | (pro_rx_wprot[disknum] << 3)
                 | (pro_rx_ready[disknum] << 2)
                 | pro_rx_exist[disknum];
 pro_rx_csr4_s = (pro_rx_exist[3] << 6)
                 | (pro_rx_exist[2] << 4)
                 | (pro_rx_exist[1] << 2)
                 | pro_rx_exist[0];
}

canonical_original_code:
static void pro_rx_set_maintstat()
{
int disknum;
 disknum = (pro_rx_csr0_c & 0006) >> 1;
 pro_rx_csr0_s = (pro_rx_csr0_c & (0160 | 0006)) | 0010;
 pro_rx_csr1_s = 0;
 pro_rx_csr2_s = pro_rx_csr1_c;
 pro_rx_csr3_s = (pro_rx_vchanged[3] << 7)
                 | (pro_rx_vchanged[2] << 6)
                 | (pro_rx_vchanged[1] << 5)
                 | (pro_rx_vchanged[0] << 4)
                 | (pro_rx_wprot[disknum] << 3)
                 | (pro_rx_ready[disknum] << 2)
                 | pro_rx_exist[disknum];
 pro_rx_csr4_s = (pro_rx_exist[3] << 6)
                 | (pro_rx_exist[2] << 4)
                 | (pro_rx_exist[1] << 2)
                 | pro_rx_exist[0];
}

variable_types: disknum int


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

pro_rx_csr0_s = pro_rx_csr0_c & 0x76 | 8;
pro_rx_csr1_s = 0;
pro_rx_csr2_s = pro_rx_csr1_c;
result = (unsigned int)pro_rx_csr2_c;
pro_rx_csr3_s = pro_rx_csr2_c;
pro_rx_csr4_s = 0;
return result;
}

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

pro_rx_csr0_s = pro_rx_csr0_c & 0x76 | 8;
pro_rx_csr1_s = 0;
pro_rx_csr2_s = pro_rx_csr1_c;
result = (unsigned int)pro_rx_csr2_c;
pro_rx_csr3_s = pro_rx_csr2_c;
pro_rx_csr4_s = 0;
return result;
}

original_code:
static void pro_rx_set_rwstat ()
{
 pro_rx_csr0_s = (pro_rx_csr0_c & (0160 | 0006)) | 0010;
 pro_rx_csr1_s = 0;
 pro_rx_csr2_s = pro_rx_csr1_c;
 pro_rx_csr3_s = pro_rx_csr2_c;
 pro_rx_csr4_s = 0;
}

canonical_original_code:
static void pro_rx_set_rwstat()
{
 pro_rx_csr0_s = (pro_rx_csr0_c & (0160 | 0006)) | 0010;
 pro_rx_csr1_s = 0;
 pro_rx_csr2_s = pro_rx_csr1_c;
 pro_rx_csr3_s = pro_rx_csr2_c;
 pro_rx_csr4_s = 0;
}


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

if ( pro_rx_intb_en == 1 )
result = pro_int_set(514LL);
pro_rx_intb_en = 0;
return result;
}

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

if ( pro_rx_intb_en == 1 )
result = pro_int_set(514LL);
pro_rx_intb_en = 0;
return result;
}

original_code:
static void pro_rx_intb ()
{
 if (pro_rx_intb_en == 1)
   pro_int_set(0x0202);
 pro_rx_intb_en = 0;
}

canonical_original_code:
static void pro_rx_intb()
{
 if (pro_rx_intb_en == 1)
   pro_int_set(0x0202);
 pro_rx_intb_en = 0;
}


decompiled_code:
int pro_rx_readsec()
{
int v0; // ebp
int result; // eax
__int64 *v2; // rbx

v0 = (pro_rx_csr0_c >> 1) & 3;
result = v0;
if ( pro_rx_exist[v0] == 1 && (result = (pro_rx_csr0_c >> 1) & 3, pro_rx_ready[v0] == 1) )
{
result = pro_rx_csr1_c;
if ( pro_rx_csr1_c <= 79 )
{
if ( (unsigned int)(pro_rx_csr2_c - 1) <= 9 )
{
fseek((FILE *)pro_rx_fptr[v0], (pro_rx_csr2_c - 1 + 10 * pro_rx_csr1_c) << 9, 0);
v2 = (__int64 *)&PRO_RX_SECBUF;
do
{
result = getc((FILE *)pro_rx_fptr[v0]);
*(_BYTE *)v2 = result;
v2 = (__int64 *)((char *)v2 + 1);
}
while ( v2 != pro_rx_fptr );
}
else
{
pro_rx_csr1_s = 184;
}
}
else
{
pro_rx_csr1_s = 32;
}
}
else
{
pro_rx_csr1_s = 144;
}
return result;
}

canonical_decompiled_code:
int func3()
{
int v0; // ebp
int result; // eax
__int64 *v2; // rbx

v0 = (pro_rx_csr0_c >> 1) & 3;
result = v0;
if ( pro_rx_exist[v0] == 1 && (result = (pro_rx_csr0_c >> 1) & 3, pro_rx_ready[v0] == 1) )
{
result = pro_rx_csr1_c;
if ( pro_rx_csr1_c <= 79 )
{
if ( (unsigned int)(pro_rx_csr2_c - 1) <= 9 )
{
fseek((FILE *)pro_rx_fptr[v0], (pro_rx_csr2_c - 1 + 10 * pro_rx_csr1_c) << 9, 0);
v2 = (__int64 *)&PRO_RX_SECBUF;
do
{
result = getc((FILE *)pro_rx_fptr[v0]);
*(_BYTE *)v2 = result;
v2 = (__int64 *)((char *)v2 + 1);
}
while ( v2 != pro_rx_fptr );
}
else
{
pro_rx_csr1_s = 184;
}
}
else
{
pro_rx_csr1_s = 32;
}
}
else
{
pro_rx_csr1_s = 144;
}
return result;
}

original_code:
static void pro_rx_readsec ()
{
int i, disk, track, sector, offset;
 disk = (pro_rx_csr0_c & 0006) >> 1;
 track = pro_rx_csr1_c;
 sector = pro_rx_csr2_c-1;
 offset = (track*10 +sector)*512;
 if ((pro_rx_exist[disk] != 1) || (pro_rx_ready[disk] != 1))
   pro_rx_csr1_s = 0220;
 else if (track >= 80)
   pro_rx_csr1_s = 0040;
 else if ((sector < 0) || (sector >= 10))
   pro_rx_csr1_s = 0270;
 else
 {
   fseek(pro_rx_fptr[disk], offset, 0);
   for(i=0; i<512; i++)
     PRO_RX_SECBUF[i] = getc(pro_rx_fptr[disk]);
 }
}

canonical_original_code:
static void pro_rx_readsec()
{
int i; int disk; int track; int sector; int offset;
 disk = (pro_rx_csr0_c & 0006) >> 1;
 track = pro_rx_csr1_c;
 sector = pro_rx_csr2_c-1;
 offset = (track*10 +sector)*512;
 if ((pro_rx_exist[disk] != 1) || (pro_rx_ready[disk] != 1))
   pro_rx_csr1_s = 0220;
 else if (track >= 80)
   pro_rx_csr1_s = 0040;
 else if ((sector < 0) || (sector >= 10))
   pro_rx_csr1_s = 0270;
 else
 {
   fseek(pro_rx_fptr[disk], offset, 0);
   for(i=0; i<512; i++)
     PRO_RX_SECBUF[i] = getc(pro_rx_fptr[disk]);
 }
}

variable_types: i int

variable_types: disk int

variable_types: track int

variable_types: sector int

variable_types: offset int


decompiled_code:
int pro_rx_writesec()
{
int v0; // ebp
int result; // eax
__int64 *v2; // rbx

v0 = (pro_rx_csr0_c >> 1) & 3;
result = v0;
if ( pro_rx_exist[v0] == 1 && (result = (pro_rx_csr0_c >> 1) & 3, pro_rx_ready[v0] == 1) )
{
result = (pro_rx_csr0_c >> 1) & 3;
if ( pro_rx_wprot[v0] == 1 )
{
pro_rx_csr1_s = 176;
}
else
{
result = pro_rx_csr1_c;
if ( pro_rx_csr1_c <= 79 )
{
if ( (unsigned int)(pro_rx_csr2_c - 1) <= 9 )
{
fseek((FILE *)pro_rx_fptr[v0], (pro_rx_csr2_c - 1 + 10 * pro_rx_csr1_c) << 9, 0);
v2 = (__int64 *)&PRO_RX_SECBUF;
do
{
putc(*(unsigned __int8 *)v2, (FILE *)pro_rx_fptr[v0]);
v2 = (__int64 *)((char *)v2 + 1);
}
while ( v2 != pro_rx_fptr );
result = fflush((FILE *)pro_rx_fptr[v0]);
}
else
{
pro_rx_csr1_s = 184;
}
}
else
{
pro_rx_csr1_s = 32;
}
}
}
else
{
pro_rx_csr1_s = 144;
}
return result;
}

canonical_decompiled_code:
int func4()
{
int v0; // ebp
int result; // eax
__int64 *v2; // rbx

v0 = (pro_rx_csr0_c >> 1) & 3;
result = v0;
if ( pro_rx_exist[v0] == 1 && (result = (pro_rx_csr0_c >> 1) & 3, pro_rx_ready[v0] == 1) )
{
result = (pro_rx_csr0_c >> 1) & 3;
if ( pro_rx_wprot[v0] == 1 )
{
pro_rx_csr1_s = 176;
}
else
{
result = pro_rx_csr1_c;
if ( pro_rx_csr1_c <= 79 )
{
if ( (unsigned int)(pro_rx_csr2_c - 1) <= 9 )
{
fseek((FILE *)pro_rx_fptr[v0], (pro_rx_csr2_c - 1 + 10 * pro_rx_csr1_c) << 9, 0);
v2 = (__int64 *)&PRO_RX_SECBUF;
do
{
putc(*(unsigned __int8 *)v2, (FILE *)pro_rx_fptr[v0]);
v2 = (__int64 *)((char *)v2 + 1);
}
while ( v2 != pro_rx_fptr );
result = fflush((FILE *)pro_rx_fptr[v0]);
}
else
{
pro_rx_csr1_s = 184;
}
}
else
{
pro_rx_csr1_s = 32;
}
}
}
else
{
pro_rx_csr1_s = 144;
}
return result;
}

original_code:
static void pro_rx_writesec ()
{
int i, disk, track, sector, offset;
 disk = (pro_rx_csr0_c & 0006) >> 1;
 track = pro_rx_csr1_c;
 sector = pro_rx_csr2_c-1;
 offset = (track*10 +sector)*512;
 if ((pro_rx_exist[disk] != 1) || (pro_rx_ready[disk] != 1))
   pro_rx_csr1_s = 0220;
 else if (pro_rx_wprot[disk] == 1)
   pro_rx_csr1_s = 0260;
 else if (track >= 80)
   pro_rx_csr1_s = 0040;
 else if ((sector < 0) || (sector >= 10))
   pro_rx_csr1_s = 0270;
 else
 {
   fseek(pro_rx_fptr[disk], offset, 0);
   for(i=0; i<512; i++)
     putc(PRO_RX_SECBUF[i], pro_rx_fptr[disk]);
   fflush(pro_rx_fptr[disk]);
 }
}

canonical_original_code:
static void pro_rx_writesec()
{
int i; int disk; int track; int sector; int offset;
 disk = (pro_rx_csr0_c & 0006) >> 1;
 track = pro_rx_csr1_c;
 sector = pro_rx_csr2_c-1;
 offset = (track*10 +sector)*512;
 if ((pro_rx_exist[disk] != 1) || (pro_rx_ready[disk] != 1))
   pro_rx_csr1_s = 0220;
 else if (pro_rx_wprot[disk] == 1)
   pro_rx_csr1_s = 0260;
 else if (track >= 80)
   pro_rx_csr1_s = 0040;
 else if ((sector < 0) || (sector >= 10))
   pro_rx_csr1_s = 0270;
 else
 {
   fseek(pro_rx_fptr[disk], offset, 0);
   for(i=0; i<512; i++)
     putc(PRO_RX_SECBUF[i], pro_rx_fptr[disk]);
   fflush(pro_rx_fptr[disk]);
 }
}


decompiled_code:
__int64 pro_rx_start_command()
{
double v1; // xmm0_8

switch ( (pro_rx_csr0_c >> 4) & 7 )
{
case 0:
pro_rx_set_maintstat();
pro_rx_vchanged = 0;
dword_9E4 = 0;
dword_9E8 = 0;
dword_9EC = 0;
pro_rx_intb_en = 1;
break;
case 1:
case 2:
case 3:
pro_rx_set_maintstat();
break;
case 4:
LABEL_6:
pro_rx_set_rwstat();
pro_rx_readsec();
break;
case 5:
switch ( pro_rx_csr5_c & 7 )
{
case 0:
goto LABEL_6;
case 1:
goto LABEL_7;
case 2:
puts("Read format not implemented in RX50!\r");
break;
case 3:
puts("Set format not implemented in RX50!\r");
break;
case 4:
pro_rx_csr2_s = 1;
break;
case 5:
puts("Read and compare not implemented in RX50!\r");
break;
default:
puts("Warning: unknown extended function command in RX50!\r");
break;
}
break;
case 6:
pro_rx_set_rwstat();
v1 = sim_gtime();
printf("%10.0f Warning: read address command not implemented in RX50!\r\n", v1);
break;
case 7:
LABEL_7:
pro_rx_set_rwstat();
pro_rx_writesec();
break;
}
return pro_int_set(258LL);
}

canonical_decompiled_code:
__int64 func5()
{
double v1; // xmm0_8

switch ( (pro_rx_csr0_c >> 4) & 7 )
{
case 0:
func0();
pro_rx_vchanged = 0;
dword_9E4 = 0;
dword_9E8 = 0;
dword_9EC = 0;
pro_rx_intb_en = 1;
break;
case 1:
case 2:
case 3:
func0();
break;
case 4:
LABEL_6:
func1();
func3();
break;
case 5:
switch ( pro_rx_csr5_c & 7 )
{
case 0:
goto LABEL_6;
case 1:
goto LABEL_7;
case 2:
puts("Read format not implemented in RX50!\r");
break;
case 3:
puts("Set format not implemented in RX50!\r");
break;
case 4:
pro_rx_csr2_s = 1;
break;
case 5:
puts("Read and compare not implemented in RX50!\r");
break;
default:
puts("Warning: unknown extended function command in RX50!\r");
break;
}
break;
case 6:
func1();
v1 = sim_gtime();
printf("%10.0f Warning: read address command not implemented in RX50!\r\n", v1);
break;
case 7:
LABEL_7:
func1();
func4();
break;
}
return pro_int_set(258LL);
}

original_code:
static void pro_rx_start_command(void)
{
int i;
 switch ((pro_rx_csr0_c & 0160) >> 4)
 {
   case 00:
     pro_rx_set_maintstat();
     for(i=0; i<4; i++)
       pro_rx_vchanged[i] = 0;
     pro_rx_intb_en = 1;
     break;
   case 01:
     pro_rx_set_maintstat();
     break;
   case 02:
     pro_rx_set_maintstat();
     break;
   case 03:
     pro_rx_set_maintstat();
     break;
   case 04:
     pro_rx_set_rwstat();
     pro_rx_readsec();
     break;
   case 05:
     switch (pro_rx_csr5_c & 0007)
     {
       case 00:
         pro_rx_set_rwstat();
         pro_rx_readsec();
         break;
       case 01:
         pro_rx_set_rwstat();
         pro_rx_writesec();
         break;
       case 02:
         printf("Read format not implemented in RX50!\r\n");
         break;
       case 03:
         printf("Set format not implemented in RX50!\r\n");
         break;
       case 04:
         pro_rx_csr2_s = 0001;
         break;
       case 05:
         printf("Read and compare not implemented in RX50!\r\n");
         break;
       default:
         printf("Warning: unknown extended function command in RX50!\r\n");
         break;
     }
     break;
   case 06:
     pro_rx_set_rwstat();
     printf("%10.0f Warning: read address command not implemented in RX50!\r\n", sim_gtime());
     break;
   case 07:
     pro_rx_set_rwstat();
     pro_rx_writesec();
     break;
   default:
     break;
 }
 pro_int_set(0x0102);
}

canonical_original_code:
static void pro_rx_start_command()
{
int i;
 switch ((pro_rx_csr0_c & 0160) >> 4)
 {
   case 00:
     pro_rx_set_maintstat();
     for(i=0; i<4; i++)
       pro_rx_vchanged[i] = 0;
     pro_rx_intb_en = 1;
     break;
   case 01:
     pro_rx_set_maintstat();
     break;
   case 02:
     pro_rx_set_maintstat();
     break;
   case 03:
     pro_rx_set_maintstat();
     break;
   case 04:
     pro_rx_set_rwstat();
     pro_rx_readsec();
     break;
   case 05:
     switch (pro_rx_csr5_c & 0007)
     {
       case 00:
         pro_rx_set_rwstat();
         pro_rx_readsec();
         break;
       case 01:
         pro_rx_set_rwstat();
         pro_rx_writesec();
         break;
       case 02:
         printf("Read format not implemented in RX50!\r\n");
         break;
       case 03:
         printf("Set format not implemented in RX50!\r\n");
         break;
       case 04:
         pro_rx_csr2_s = 0001;
         break;
       case 05:
         printf("Read and compare not implemented in RX50!\r\n");
         break;
       default:
         printf("Warning: unknown extended function command in RX50!\r\n");
         break;
     }
     break;
   case 06:
     pro_rx_set_rwstat();
     printf("%10.0f Warning: read address command not implemented in RX50!\r\n", sim_gtime());
     break;
   case 07:
     pro_rx_set_rwstat();
     pro_rx_writesec();
     break;
   default:
     break;
 }
 pro_int_set(0x0102);
}


decompiled_code:
int __fastcall pro_rx_open_door(unsigned int a1)
{
if ( pro_rx_ready[a1] != 1 )
return printf("Floppy %d already open!\r\n", a1);
printf("Open floppy %d\r\n", a1);
fclose((FILE *)pro_rx_fptr[a1]);
pro_rx_ready[a1] = 0;
pro_rx_wprot[a1] = 0;
pro_rx_vchanged[a1] = 1;
return pro_rx_intb();
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
if ( pro_rx_ready[a1] != 1 )
return printf("Floppy %d already open!\r\n", a1);
printf("Open floppy %d\r\n", a1);
fclose((FILE *)pro_rx_fptr[a1]);
pro_rx_ready[a1] = 0;
pro_rx_wprot[a1] = 0;
pro_rx_vchanged[a1] = 1;
return func2();
}

original_code:
void pro_rx_open_door (int disknum)
{
 if (pro_rx_ready[disknum] == 1)
 {
   printf("Open floppy %d\r\n", disknum);
   fclose(pro_rx_fptr[disknum]);
   pro_rx_ready[disknum] = 0;
   pro_rx_wprot[disknum] = 0;
   pro_rx_vchanged[disknum] = 1;
   pro_rx_intb();
 }
 else
   printf("Floppy %d already open!\r\n", disknum);
}

canonical_original_code:
void pro_rx_open_door(int disknum)
{
 if (pro_rx_ready[disknum] == 1)
 {
   printf("Open floppy %d\r\n", disknum);
   fclose(pro_rx_fptr[disknum]);
   pro_rx_ready[disknum] = 0;
   pro_rx_wprot[disknum] = 0;
   pro_rx_vchanged[disknum] = 1;
   pro_rx_intb();
 }
 else
   printf("Floppy %d already open!\r\n", disknum);
}


decompiled_code:
void __fastcall pro_rx_close_door(unsigned int a1)
{
const char *v1; // r12
size_t v2; // rbp
const char *v3; // r13
size_t v4; // rax
char *v5; // rbp
struct stat v6; // [rsp+0h] [rbp-B8h] BYREF

if ( pro_rx_ready[a1] )
{
printf("Floppy %d already closed!\r\n", a1);
}
else
{
v1 = (const char *)pro_rx_dir[a1];
v2 = strlen(v1);
v3 = (const char *)pro_rx_file[a1];
v4 = strlen(v3);
v5 = (char *)malloc(v2 + v4 + 1);
strcpy(v5, v1);
strcat(v5, v3);
stat(v5, &v6);
if ( SLOBYTE(v6.st_mode) >= 0 )
{
pro_rx_fptr[a1] = (__int64)fopen(v5, "r");
pro_rx_wprot[a1] = 1;
}
else
{
pro_rx_fptr[a1] = (__int64)fopen(v5, "r+");
}
if ( pro_rx_fptr[a1] )
{
if ( v6.st_size == 409600 )
{
printf("Close floppy %d\r\n", a1);
pro_rx_ready[a1] = 1;
pro_rx_vchanged[a1] = 1;
pro_rx_intb();
}
else
{
printf("Floppy %d image filesize %d incorrect! (should be %d)\r\n", a1, v6.st_size, 409600LL);
pro_rx_wprot[a1] = 0;
fclose((FILE *)pro_rx_fptr[a1]);
}
}
else
{
printf("Floppy %d close failed!\r\n", a1);
pro_rx_wprot[a1] = 0;
}
free(v5);
}
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
const char *v1; // r12
size_t v2; // rbp
const char *v3; // r13
size_t v4; // rax
char *v5; // rbp
struct stat v6; // [rsp+0h] [rbp-B8h] BYREF

if ( pro_rx_ready[a1] )
{
printf("Floppy %d already closed!\r\n", a1);
}
else
{
v1 = (const char *)pro_rx_dir[a1];
v2 = strlen(v1);
v3 = (const char *)pro_rx_file[a1];
v4 = strlen(v3);
v5 = (char *)malloc(v2 + v4 + 1);
strcpy(v5, v1);
strcat(v5, v3);
stat(v5, &v6);
if ( SLOBYTE(v6.st_mode) >= 0 )
{
pro_rx_fptr[a1] = (__int64)fopen(v5, "r");
pro_rx_wprot[a1] = 1;
}
else
{
pro_rx_fptr[a1] = (__int64)fopen(v5, "r+");
}
if ( pro_rx_fptr[a1] )
{
if ( v6.st_size == 409600 )
{
printf("Close floppy %d\r\n", a1);
pro_rx_ready[a1] = 1;
pro_rx_vchanged[a1] = 1;
func2();
}
else
{
printf("Floppy %d image filesize %d incorrect! (should be %d)\r\n", a1, v6.st_size, 409600LL);
pro_rx_wprot[a1] = 0;
fclose((FILE *)pro_rx_fptr[a1]);
}
}
else
{
printf("Floppy %d close failed!\r\n", a1);
pro_rx_wprot[a1] = 0;
}
free(v5);
}
}

original_code:
void pro_rx_close_door (int disknum)
{
struct stat statbuf;
char *fname;
 if (pro_rx_ready[disknum] == 0)
 {
   fname = malloc(strlen(pro_rx_dir[disknum]) + strlen(pro_rx_file[disknum]) + 1);
   strcpy(fname, pro_rx_dir[disknum]);
   strcat(fname, pro_rx_file[disknum]);
   stat(fname, &statbuf);
   if ((statbuf.st_mode & 0200) != 0)
     pro_rx_fptr[disknum] = fopen(fname, "r+");
   else
   {
     pro_rx_fptr[disknum] = fopen(fname, "r");
     pro_rx_wprot[disknum] = 1;
   }
   if (pro_rx_fptr[disknum] != ((void *)0))
   {
     if (statbuf.st_size == (80*10*512))
     {
       printf("Close floppy %d\r\n", disknum);
       pro_rx_ready[disknum] = 1;
       pro_rx_vchanged[disknum] = 1;
       pro_rx_intb();
     }
     else
     {
       printf("Floppy %d image filesize %d incorrect! (should be %d)\r\n",
               disknum, (int)statbuf.st_size, (80*10*512));
       pro_rx_wprot[disknum] = 0;
       fclose(pro_rx_fptr[disknum]);
     }
   }
   else
   {
     printf("Floppy %d close failed!\r\n", disknum);
     pro_rx_wprot[disknum] = 0;
   }
   free(fname);
 }
 else
   printf("Floppy %d already closed!\r\n", disknum);
}

canonical_original_code:
void pro_rx_close_door(int disknum)
{
struct stat statbuf;
char *fname;
 if (pro_rx_ready[disknum] == 0)
 {
   fname = malloc(strlen(pro_rx_dir[disknum]) + strlen(pro_rx_file[disknum]) + 1);
   strcpy(fname, pro_rx_dir[disknum]);
   strcat(fname, pro_rx_file[disknum]);
   stat(fname, &statbuf);
   if ((statbuf.st_mode & 0200) != 0)
     pro_rx_fptr[disknum] = fopen(fname, "r+");
   else
   {
     pro_rx_fptr[disknum] = fopen(fname, "r");
     pro_rx_wprot[disknum] = 1;
   }
   if (pro_rx_fptr[disknum] != ((void *)0))
   {
     if (statbuf.st_size == (80*10*512))
     {
       printf("Close floppy %d\r\n", disknum);
       pro_rx_ready[disknum] = 1;
       pro_rx_vchanged[disknum] = 1;
       pro_rx_intb();
     }
     else
     {
       printf("Floppy %d image filesize %d incorrect! (should be %d)\r\n",
               disknum, (int)statbuf.st_size, (80*10*512));
       pro_rx_wprot[disknum] = 0;
       fclose(pro_rx_fptr[disknum]);
     }
   }
   else
   {
     printf("Floppy %d close failed!\r\n", disknum);
     pro_rx_wprot[disknum] = 0;
   }
   free(fname);
 }
 else
   printf("Floppy %d already closed!\r\n", disknum);
}

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

variable_types:
fname
char *

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


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

switch ( a1 & 0x3FFFFE )
{
case 0x3FF880:
result = 4LL;
break;
case 0x3FF884:
result = (unsigned int)pro_rx_csr0_s;
break;
case 0x3FF886:
result = (unsigned int)pro_rx_csr1_s;
break;
case 0x3FF888:
result = (unsigned int)pro_rx_csr2_s;
break;
case 0x3FF88A:
result = (unsigned int)pro_rx_csr3_s;
break;
case 0x3FF88C:
result = (unsigned int)pro_rx_csr4_s;
break;
case 0x3FF88E:
result = (unsigned int)pro_rx_csr5_c;
break;
case 0x3FF890:
result = (unsigned __int8)PRO_RX_SECBUF[pro_rx_secbuf_addr];
v2 = pro_rx_secbuf_addr + 1;
if ( pro_rx_secbuf_addr == 511 )
v2 = 0;
pro_rx_secbuf_addr = v2;
break;
case 0x3FF892:
pro_rx_secbuf_addr = 0;
result = 0LL;
break;
case 0x3FF894:
pro_rx_start_command();
result = 0LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 & 0x3FFFFE )
{
case 0x3FF880:
result = 4LL;
break;
case 0x3FF884:
result = (unsigned int)pro_rx_csr0_s;
break;
case 0x3FF886:
result = (unsigned int)pro_rx_csr1_s;
break;
case 0x3FF888:
result = (unsigned int)pro_rx_csr2_s;
break;
case 0x3FF88A:
result = (unsigned int)pro_rx_csr3_s;
break;
case 0x3FF88C:
result = (unsigned int)pro_rx_csr4_s;
break;
case 0x3FF88E:
result = (unsigned int)pro_rx_csr5_c;
break;
case 0x3FF890:
result = (unsigned __int8)PRO_RX_SECBUF[pro_rx_secbuf_addr];
v2 = pro_rx_secbuf_addr + 1;
if ( pro_rx_secbuf_addr == 511 )
v2 = 0;
pro_rx_secbuf_addr = v2;
break;
case 0x3FF892:
pro_rx_secbuf_addr = 0;
result = 0LL;
break;
case 0x3FF894:
func5();
result = 0LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int pro_rx_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774200:
     data = 0000004;
     break;
   case 017774204:
     data = pro_rx_csr0_s;
     break;
   case 017774206:
     data = pro_rx_csr1_s;
     break;
   case 017774210:
     data = pro_rx_csr2_s;
     break;
   case 017774212:
     data = pro_rx_csr3_s;
     break;
   case 017774214:
     data = pro_rx_csr4_s;
     break;
   case 017774216:
     data = pro_rx_csr5_c;
     break;
   case 017774220:
     data = PRO_RX_SECBUF[pro_rx_secbuf_addr];
     pro_rx_secbuf_addr++;
     if (pro_rx_secbuf_addr == 512)
       pro_rx_secbuf_addr = 0;
     break;
   case 017774222:
     pro_rx_secbuf_addr = 0;
     data = 0;
     break;
   case 017774224:
     pro_rx_start_command();
     data = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_rx_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774200:
     data = 0000004;
     break;
   case 017774204:
     data = pro_rx_csr0_s;
     break;
   case 017774206:
     data = pro_rx_csr1_s;
     break;
   case 017774210:
     data = pro_rx_csr2_s;
     break;
   case 017774212:
     data = pro_rx_csr3_s;
     break;
   case 017774214:
     data = pro_rx_csr4_s;
     break;
   case 017774216:
     data = pro_rx_csr5_c;
     break;
   case 017774220:
     data = PRO_RX_SECBUF[pro_rx_secbuf_addr];
     pro_rx_secbuf_addr++;
     if (pro_rx_secbuf_addr == 512)
       pro_rx_secbuf_addr = 0;
     break;
   case 017774222:
     pro_rx_secbuf_addr = 0;
     data = 0;
     break;
   case 017774224:
     pro_rx_start_command();
     data = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}


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

LOBYTE(v3) = (a2 & 0xFE) + 124;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF884:
if ( a3 == 4 )
{
v3 = pro_rx_csr0_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr0_c = v3;
}
else
{
v3 = pro_rx_csr0_c;
LOBYTE(v3) = 0;
pro_rx_csr0_c = v3 | a1;
}
break;
case 0x3FF886:
if ( a3 == 4 )
{
v3 = pro_rx_csr1_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr1_c = v3;
}
else
{
v3 = pro_rx_csr1_c;
LOBYTE(v3) = 0;
pro_rx_csr1_c = v3 | a1;
}
break;
case 0x3FF888:
if ( a3 == 4 )
{
v3 = pro_rx_csr2_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr2_c = v3;
}
else
{
v3 = pro_rx_csr2_c;
LOBYTE(v3) = 0;
pro_rx_csr2_c = v3 | a1;
}
break;
case 0x3FF88A:
if ( a3 == 4 )
{
v3 = pro_rx_csr3_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr3_c = v3;
}
else
{
v3 = pro_rx_csr3_c;
LOBYTE(v3) = 0;
pro_rx_csr3_c = v3 | a1;
}
break;
case 0x3FF88E:
if ( a3 == 4 )
{
v3 = pro_rx_csr5_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr5_c = v3;
}
else
{
v3 = pro_rx_csr5_c;
LOBYTE(v3) = 0;
pro_rx_csr5_c = v3 | a1;
}
break;
case 0x3FF890:
case 0x3FF896:
v4 = pro_rx_secbuf_addr;
PRO_RX_SECBUF[pro_rx_secbuf_addr] = a1;
v3 = v4 + 1;
if ( v4 == 511 )
v3 = 0;
pro_rx_secbuf_addr = v3;
break;
case 0x3FF892:
pro_rx_secbuf_addr = 0;
break;
case 0x3FF894:
LOBYTE(v3) = pro_rx_start_command();
break;
default:
return v3;
}
return v3;
}

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

LOBYTE(v3) = (a2 & 0xFE) + 124;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF884:
if ( a3 == 4 )
{
v3 = pro_rx_csr0_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr0_c = v3;
}
else
{
v3 = pro_rx_csr0_c;
LOBYTE(v3) = 0;
pro_rx_csr0_c = v3 | a1;
}
break;
case 0x3FF886:
if ( a3 == 4 )
{
v3 = pro_rx_csr1_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr1_c = v3;
}
else
{
v3 = pro_rx_csr1_c;
LOBYTE(v3) = 0;
pro_rx_csr1_c = v3 | a1;
}
break;
case 0x3FF888:
if ( a3 == 4 )
{
v3 = pro_rx_csr2_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr2_c = v3;
}
else
{
v3 = pro_rx_csr2_c;
LOBYTE(v3) = 0;
pro_rx_csr2_c = v3 | a1;
}
break;
case 0x3FF88A:
if ( a3 == 4 )
{
v3 = pro_rx_csr3_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr3_c = v3;
}
else
{
v3 = pro_rx_csr3_c;
LOBYTE(v3) = 0;
pro_rx_csr3_c = v3 | a1;
}
break;
case 0x3FF88E:
if ( a3 == 4 )
{
v3 = pro_rx_csr5_c;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_rx_csr5_c = v3;
}
else
{
v3 = pro_rx_csr5_c;
LOBYTE(v3) = 0;
pro_rx_csr5_c = v3 | a1;
}
break;
case 0x3FF890:
case 0x3FF896:
v4 = pro_rx_secbuf_addr;
PRO_RX_SECBUF[pro_rx_secbuf_addr] = a1;
v3 = v4 + 1;
if ( v4 == 511 )
v3 = 0;
pro_rx_secbuf_addr = v3;
break;
case 0x3FF892:
pro_rx_secbuf_addr = 0;
break;
case 0x3FF894:
LOBYTE(v3) = func5();
break;
default:
return v3;
}
return v3;
}


decompiled_code:
void pro_rx_reset()
{
__int64 i; // rbx

memset(PRO_RX_SECBUF, 0, sizeof(PRO_RX_SECBUF));
pro_rx_secbuf_addr = 0;
pro_rx_csr0_c = 0;
pro_rx_csr1_c = 0;
pro_rx_csr2_c = 0;
pro_rx_csr3_c = 0;
pro_rx_csr5_c = 0;
pro_rx_csr0_s = 8;
pro_rx_csr1_s = 0;
pro_rx_csr2_s = 0;
pro_rx_csr3_s = 0;
pro_rx_csr4_s = 0;
pro_rx_exist[0] = 1;
dword_A14 = 1;
dword_A18 = 0;
dword_A1C = 0;
pro_rx_vchanged[0] = 0;
dword_9E4 = 0;
dword_9E8 = 0;
dword_9EC = 0;
pro_rx_intb_en = 0;
for ( i = 0LL; i != 4; ++i )
{
if ( pro_rx_closed[i] == 1 )
pro_rx_close_door(i);
}
}

canonical_decompiled_code:
void func10()
{
__int64 i; // rbx

memset(PRO_RX_SECBUF, 0, sizeof(PRO_RX_SECBUF));
pro_rx_secbuf_addr = 0;
pro_rx_csr0_c = 0;
pro_rx_csr1_c = 0;
pro_rx_csr2_c = 0;
pro_rx_csr3_c = 0;
pro_rx_csr5_c = 0;
pro_rx_csr0_s = 8;
pro_rx_csr1_s = 0;
pro_rx_csr2_s = 0;
pro_rx_csr3_s = 0;
pro_rx_csr4_s = 0;
pro_rx_exist[0] = 1;
dword_A14 = 1;
dword_A18 = 0;
dword_A1C = 0;
pro_rx_vchanged[0] = 0;
dword_9E4 = 0;
dword_9E8 = 0;
dword_9EC = 0;
pro_rx_intb_en = 0;
for ( i = 0LL; i != 4; ++i )
{
if ( pro_rx_closed[i] == 1 )
func7(i);
}
}

original_code:
void pro_rx_reset ()
{
int i;
        memset(&PRO_RX_SECBUF, 0, sizeof(PRO_RX_SECBUF));
 pro_rx_secbuf_addr = 0;
 pro_rx_csr0_c = 0;
 pro_rx_csr1_c = 0;
 pro_rx_csr2_c = 0;
 pro_rx_csr3_c = 0;
 pro_rx_csr5_c = 0;
 pro_rx_csr0_s = 0010;
 pro_rx_csr1_s = 0;
 pro_rx_csr2_s = 0;
 pro_rx_csr3_s = 0;
 pro_rx_csr4_s = 0;
 pro_rx_exist[0] = 1;
 pro_rx_exist[1] = 1;
 pro_rx_exist[2] = 0;
 pro_rx_exist[3] = 0;
 pro_rx_vchanged[0] = 0;
 pro_rx_vchanged[1] = 0;
 pro_rx_vchanged[2] = 0;
 pro_rx_vchanged[3] = 0;
 pro_rx_intb_en = 0;
 for(i=0; i<4; i++)
   if (pro_rx_closed[i] == 1)
     pro_rx_close_door(i);
}

canonical_original_code:
void pro_rx_reset()
{
int i;
        memset(&PRO_RX_SECBUF, 0, sizeof(PRO_RX_SECBUF));
 pro_rx_secbuf_addr = 0;
 pro_rx_csr0_c = 0;
 pro_rx_csr1_c = 0;
 pro_rx_csr2_c = 0;
 pro_rx_csr3_c = 0;
 pro_rx_csr5_c = 0;
 pro_rx_csr0_s = 0010;
 pro_rx_csr1_s = 0;
 pro_rx_csr2_s = 0;
 pro_rx_csr3_s = 0;
 pro_rx_csr4_s = 0;
 pro_rx_exist[0] = 1;
 pro_rx_exist[1] = 1;
 pro_rx_exist[2] = 0;
 pro_rx_exist[3] = 0;
 pro_rx_vchanged[0] = 0;
 pro_rx_vchanged[1] = 0;
 pro_rx_vchanged[2] = 0;
 pro_rx_vchanged[3] = 0;
 pro_rx_intb_en = 0;
 for(i=0; i<4; i++)
   if (pro_rx_closed[i] == 1)
     pro_rx_close_door(i);
}


decompiled_code:
int pro_rx_exit()
{
__int64 i; // rbx
int result; // eax

for ( i = 0LL; i != 4; ++i )
{
if ( pro_rx_ready[i] == 1 )
result = pro_rx_open_door(i);
}
return result;
}

canonical_decompiled_code:
int func11()
{
__int64 i; // rbx
int result; // eax

for ( i = 0LL; i != 4; ++i )
{
if ( pro_rx_ready[i] == 1 )
result = func6(i);
}
return result;
}

original_code:
void pro_rx_exit ()
{
int i;
 for(i=0; i<4; i++)
   if (pro_rx_ready[i] == 1)
     pro_rx_open_door(i);
}

canonical_original_code:
void pro_rx_exit()
{
int i;
 for(i=0; i<4; i++)
   if (pro_rx_ready[i] == 1)
     pro_rx_open_door(i);
}


decompiled_code:
__int64 pro_com_ctrl_get()
{
int v0; // eax
int v1; // edx
int v2; // eax
int v3; // edx
int v4; // eax
int v5; // edx
int v6; // eax
int v7; // edx
__int64 result; // rax

(*(void (__fastcall **)(__int64, __int64 *))(pro_com + 16LL))(2LL, &pro_com_ctrl);
v0 = pro_com_mcr1;
v1 = *((_DWORD *)&pro_com_ctrl + 7);
if ( v1 )
v1 = 128;
LOBYTE(v0) = pro_com_mcr1 & 0xF;
v2 = v1 | v0;
v3 = *((_DWORD *)&pro_com_ctrl + 10);
if ( v3 )
v3 = 64;
v4 = v3 | v2;
v5 = *((_DWORD *)&pro_com_ctrl + 9);
if ( v5 )
v5 = 32;
v6 = v5 | v4;
v7 = *((_DWORD *)&pro_com_ctrl + 11);
if ( v7 )
v7 = 16;
result = v7 | (unsigned int)v6;
pro_com_mcr1 = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
int v1; // edx
int v2; // eax
int v3; // edx
int v4; // eax
int v5; // edx
int v6; // eax
int v7; // edx
__int64 result; // rax

(*(void (__fastcall **)(__int64, __int64 *))(pro_com + 16LL))(2LL, &pro_com_ctrl);
v0 = pro_com_mcr1;
v1 = *((_DWORD *)&pro_com_ctrl + 7);
if ( v1 )
v1 = 128;
LOBYTE(v0) = pro_com_mcr1 & 0xF;
v2 = v1 | v0;
v3 = *((_DWORD *)&pro_com_ctrl + 10);
if ( v3 )
v3 = 64;
v4 = v3 | v2;
v5 = *((_DWORD *)&pro_com_ctrl + 9);
if ( v5 )
v5 = 32;
v6 = v5 | v4;
v7 = *((_DWORD *)&pro_com_ctrl + 11);
if ( v7 )
v7 = 16;
result = v7 | (unsigned int)v6;
pro_com_mcr1 = result;
return result;
}

original_code:
static void pro_com_ctrl_get ()
{
 pro_com->ctrl_get(2, &pro_com_ctrl);
 pro_com_mcr1 &= ~(0200 | 0100 | 0040 | 0020);
 pro_com_mcr1 |= pro_com_ctrl.dsr ? 0200 : 0;
 pro_com_mcr1 |= pro_com_ctrl.ri ? 0100 : 0;
 pro_com_mcr1 |= pro_com_ctrl.cts ? 0040 : 0;
 pro_com_mcr1 |= pro_com_ctrl.cd ? 0020 : 0;
}

canonical_original_code:
static void pro_com_ctrl_get()
{
 pro_com->ctrl_get(2, &pro_com_ctrl);
 pro_com_mcr1 &= ~(0200 | 0100 | 0040 | 0020);
 pro_com_mcr1 |= pro_com_ctrl.dsr ? 0200 : 0;
 pro_com_mcr1 |= pro_com_ctrl.ri ? 0100 : 0;
 pro_com_mcr1 |= pro_com_ctrl.cts ? 0040 : 0;
 pro_com_mcr1 |= pro_com_ctrl.cd ? 0020 : 0;
}


decompiled_code:
__int64 pro_com_ctrl_put()
{
char v0; // al
int v1; // eax
int v2; // eax

*((_DWORD *)&pro_com_ctrl + 3) = (pro_com_a_wr3 >> 7) & 1 | (pro_com_a_wr3 >> 5) & 2;
v0 = pro_com_a_wr4;
LODWORD(pro_com_ctrl) = (pro_com_a_wr4 >> 2) & 3;
HIDWORD(pro_com_ctrl) = (pro_com_a_wr4 >> 1) & 1;
*((_DWORD *)&pro_com_ctrl + 2) = v0 & 1;
v1 = pro_com_baud;
*((_DWORD *)&pro_com_ctrl + 4) = pro_com_baud & 0xF;
*((_DWORD *)&pro_com_ctrl + 5) = (v1 >> 4) & 0xF;
v2 = pro_com_mcr0;
*((_DWORD *)&pro_com_ctrl + 6) = (pro_com_mcr0 >> 4) & 1;
*((_DWORD *)&pro_com_ctrl + 8) = (v2 >> 3) & 1;
*((_DWORD *)&pro_com_ctrl + 13) = (pro_com_a_wr5 >> 4) & 1;
return (*(__int64 (__fastcall **)(__int64, __int64 *))(pro_com + 24LL))(2LL, &pro_com_ctrl);
}

canonical_decompiled_code:
__int64 func1()
{
char v0; // al
int v1; // eax
int v2; // eax

*((_DWORD *)&pro_com_ctrl + 3) = (pro_com_a_wr3 >> 7) & 1 | (pro_com_a_wr3 >> 5) & 2;
v0 = pro_com_a_wr4;
LODWORD(pro_com_ctrl) = (pro_com_a_wr4 >> 2) & 3;
HIDWORD(pro_com_ctrl) = (pro_com_a_wr4 >> 1) & 1;
*((_DWORD *)&pro_com_ctrl + 2) = v0 & 1;
v1 = pro_com_baud;
*((_DWORD *)&pro_com_ctrl + 4) = pro_com_baud & 0xF;
*((_DWORD *)&pro_com_ctrl + 5) = (v1 >> 4) & 0xF;
v2 = pro_com_mcr0;
*((_DWORD *)&pro_com_ctrl + 6) = (pro_com_mcr0 >> 4) & 1;
*((_DWORD *)&pro_com_ctrl + 8) = (v2 >> 3) & 1;
*((_DWORD *)&pro_com_ctrl + 13) = (pro_com_a_wr5 >> 4) & 1;
return (*(__int64 (__fastcall **)(__int64, __int64 *))(pro_com + 24LL))(2LL, &pro_com_ctrl);
}

original_code:
static void pro_com_ctrl_put ()
{
 pro_com_ctrl.cs = (pro_com_a_wr3 & 0200) >> 7
                   | (pro_com_a_wr3 & 0100) >> 5;
 pro_com_ctrl.stop = (pro_com_a_wr4 & 0014) >> 2;
 pro_com_ctrl.parity = (pro_com_a_wr4 & 0002) >> 1;
 pro_com_ctrl.penable = pro_com_a_wr4 & 0001;
 pro_com_ctrl.ibaud = pro_com_baud & 0017;
 pro_com_ctrl.obaud = (pro_com_baud & 0360) >> 4;
 pro_com_ctrl.dtr = (pro_com_mcr0 & 0020) >> 4;
 pro_com_ctrl.rts = (pro_com_mcr0 & 0010) >> 3;
 pro_com_ctrl.obrk = (pro_com_a_wr5 & 0020) >> 4;
 pro_com->ctrl_put(2, &pro_com_ctrl);
}

canonical_original_code:
static void pro_com_ctrl_put()
{
 pro_com_ctrl.cs = (pro_com_a_wr3 & 0200) >> 7
                   | (pro_com_a_wr3 & 0100) >> 5;
 pro_com_ctrl.stop = (pro_com_a_wr4 & 0014) >> 2;
 pro_com_ctrl.parity = (pro_com_a_wr4 & 0002) >> 1;
 pro_com_ctrl.penable = pro_com_a_wr4 & 0001;
 pro_com_ctrl.ibaud = pro_com_baud & 0017;
 pro_com_ctrl.obaud = (pro_com_baud & 0360) >> 4;
 pro_com_ctrl.dtr = (pro_com_mcr0 & 0020) >> 4;
 pro_com_ctrl.rts = (pro_com_mcr0 & 0010) >> 3;
 pro_com_ctrl.obrk = (pro_com_a_wr5 & 0020) >> 4;
 pro_com->ctrl_put(2, &pro_com_ctrl);
}


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

v1 = pro_com_dataq_t;
pro_com_dataq[pro_com_dataq_t] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 6 )
result = 0LL;
pro_com_dataq_t = result;
pro_com_a_rr0 |= 1u;
return result;
}

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

v1 = pro_com_dataq_t;
pro_com_dataq[pro_com_dataq_t] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 6 )
result = 0LL;
pro_com_dataq_t = result;
pro_com_a_rr0 |= 1u;
return result;
}

original_code:
static void pro_com_qdata (int data)
{
 pro_com_dataq[pro_com_dataq_t] = data;
 pro_com_dataq_t++;
 if (pro_com_dataq_t == (6 + 1))
   pro_com_dataq_t = 0;
 pro_com_a_rr0 |= 0001;
}

canonical_original_code:
static void pro_com_qdata(int data)
{
 pro_com_dataq[pro_com_dataq_t] = data;
 pro_com_dataq_t++;
 if (pro_com_dataq_t == (6 + 1))
   pro_com_dataq_t = 0;
 pro_com_a_rr0 |= 0001;
}


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

v1 = pro_com_intq_t;
pro_com_intq[pro_com_intq_t] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 16 )
result = 0LL;
pro_com_intq_t = result;
return result;
}

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

v1 = pro_com_intq_t;
pro_com_intq[pro_com_intq_t] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 16 )
result = 0LL;
pro_com_intq_t = result;
return result;
}

original_code:
static void pro_com_qint (int intnum)
{
 pro_com_intq[pro_com_intq_t] = intnum;
 pro_com_intq_t++;
 if (pro_com_intq_t == (16 + 1))
   pro_com_intq_t = 0;
}

canonical_original_code:
static void pro_com_qint(int intnum)
{
 pro_com_intq[pro_com_intq_t] = intnum;
 pro_com_intq_t++;
 if (pro_com_intq_t == (16 + 1))
   pro_com_intq_t = 0;
}

variable_types: intnum int


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

if ( (pro_com_a_wr3 & 1) != 0 && !(pro_com_a_rr0 & 1 | pro_com_mcr0 & 0x80) )
{
v0 = ((__int64 (__fastcall *)(__int64))*pro_com)(2LL);
if ( v0 != 256 )
{
pro_com_qdata(v0);
pro_com_qint(24);
pro_int_set(8LL);
}
}
return pro_eq_sched(10LL, 100LL);
}

original_code:
void pro_com_poll_eq ()
{
int schar;
 if (((pro_com_mcr0 & 0200) == 0)
    && ((pro_com_a_wr3 & 0001) != 0)
    && ((pro_com_a_rr0 & 0001) == 0))
 {
   schar = pro_com->get(2);
   if (schar != 256)
   {
     pro_com_qdata(schar);
     pro_com_qint(0030);
     pro_int_set(0x0008);
   }
 }
 pro_eq_sched(10, 100);
}

canonical_original_code:
void pro_com_poll_eq()
{
int schar;
 if (((pro_com_mcr0 & 0200) == 0)
    && ((pro_com_a_wr3 & 0001) != 0)
    && ((pro_com_a_rr0 & 0001) == 0))
 {
   schar = pro_com->get(2);
   if (schar != 256)
   {
     pro_com_qdata(schar);
     pro_com_qint(0030);
     pro_int_set(0x0008);
   }
 }
 pro_eq_sched(10, 100);
}

variable_types: schar int


decompiled_code:
void pro_com_eq()
{
if ( (pro_com_mcr0 & 0x80u) == 0
&& (*(unsigned int (__fastcall **)(__int64, _QWORD))(pro_com + 8LL))(2LL, (unsigned int)pro_com_wdata) == -1 )
{
pro_eq_sched(9LL, 1000LL);
}
else
{
pro_com_a_rr0 |= 4u;
pro_com_a_rr1 |= 1u;
if ( (pro_com_a_wr5 & 8) != 0 )
{
if ( (pro_com_a_wr1 & 2) != 0 )
{
pro_com_qint(16);
pro_int_set(8LL);
}
if ( (pro_com_mcr0 & 0x80u) != 0 && (pro_com_a_wr3 & 1) != 0 )
{
pro_com_qdata(pro_com_wdata);
pro_com_qint(24);
pro_int_set(8LL);
}
}
}
}

canonical_decompiled_code:
void func5()
{
if ( (pro_com_mcr0 & 0x80u) == 0
&& (*(unsigned int (__fastcall **)(__int64, _QWORD))(pro_com + 8LL))(2LL, (unsigned int)pro_com_wdata) == -1 )
{
pro_eq_sched(9LL, 1000LL);
}
else
{
pro_com_a_rr0 |= 4u;
pro_com_a_rr1 |= 1u;
if ( (pro_com_a_wr5 & 8) != 0 )
{
if ( (pro_com_a_wr1 & 2) != 0 )
{
func3(16);
pro_int_set(8LL);
}
if ( (pro_com_mcr0 & 0x80u) != 0 && (pro_com_a_wr3 & 1) != 0 )
{
func2(pro_com_wdata);
func3(24);
pro_int_set(8LL);
}
}
}
}


decompiled_code:
__int64 __fastcall pro_com_rd(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // ecx
int v4; // esi

switch ( a1 & 0x3FFFFE )
{
case 0x3FF6C0:
result = (unsigned int)pro_com_dataq[pro_com_dataq_h];
if ( pro_com_dataq_h == pro_com_dataq_t )
goto LABEL_6;
v2 = 0;
if ( pro_com_dataq_h != 6 )
v2 = pro_com_dataq_h + 1;
pro_com_dataq_h = v2;
if ( pro_com_dataq_t == v2 )
LABEL_6:
pro_com_a_rr0 &= 0xFFFFFFFE;
break;
case 0x3FF6C2:
v3 = pro_com_a_wr0 & 7;
result = (unsigned int)pro_com_a_rr1;
if ( v3 != 1 )
{
result = (unsigned int)pro_com_a_rr2;
if ( v3 != 2 )
{
result = 0LL;
if ( (pro_com_a_wr0 & 7) == 0 )
result = (unsigned int)pro_com_a_rr0;
}
}
pro_com_a_wr0 &= 0xFFFFFFF8;
break;
case 0x3FF6C6:
result = 0LL;
if ( (pro_com_b_wr0 & 7) == 2 )
{
v4 = 28;
if ( pro_com_intq_h != pro_com_intq_t )
{
v4 = pro_com_intq[pro_com_intq_h];
pro_com_a_rr0 |= 2u;
}
result = v4 | pro_com_b_wr2 & 0xE3u;
}
pro_com_b_wr0 &= 0xFFFFFFF8;
break;
case 0x3FF6C8:
result = (unsigned int)pro_com_mcr0;
break;
case 0x3FF6CA:
pro_com_ctrl_get();
result = (unsigned int)pro_com_mcr1;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // ecx
int v4; // esi

switch ( a1 & 0x3FFFFE )
{
case 0x3FF6C0:
result = (unsigned int)pro_com_dataq[pro_com_dataq_h];
if ( pro_com_dataq_h == pro_com_dataq_t )
goto LABEL_6;
v2 = 0;
if ( pro_com_dataq_h != 6 )
v2 = pro_com_dataq_h + 1;
pro_com_dataq_h = v2;
if ( pro_com_dataq_t == v2 )
LABEL_6:
pro_com_a_rr0 &= 0xFFFFFFFE;
break;
case 0x3FF6C2:
v3 = pro_com_a_wr0 & 7;
result = (unsigned int)pro_com_a_rr1;
if ( v3 != 1 )
{
result = (unsigned int)pro_com_a_rr2;
if ( v3 != 2 )
{
result = 0LL;
if ( (pro_com_a_wr0 & 7) == 0 )
result = (unsigned int)pro_com_a_rr0;
}
}
pro_com_a_wr0 &= 0xFFFFFFF8;
break;
case 0x3FF6C6:
result = 0LL;
if ( (pro_com_b_wr0 & 7) == 2 )
{
v4 = 28;
if ( pro_com_intq_h != pro_com_intq_t )
{
v4 = pro_com_intq[pro_com_intq_h];
pro_com_a_rr0 |= 2u;
}
result = v4 | pro_com_b_wr2 & 0xE3u;
}
pro_com_b_wr0 &= 0xFFFFFFF8;
break;
case 0x3FF6C8:
result = (unsigned int)pro_com_mcr0;
break;
case 0x3FF6CA:
func0();
result = (unsigned int)pro_com_mcr1;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int pro_com_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017773300:
     data = pro_com_dataq[pro_com_dataq_h];
     if (pro_com_dataq_h != pro_com_dataq_t)
     {
       pro_com_dataq_h++;
       if (pro_com_dataq_h == (6 + 1))
         pro_com_dataq_h = 0;
     }
     if (pro_com_dataq_h == pro_com_dataq_t)
       pro_com_a_rr0 &= ~0001;
     break;
   case 017773302:
     switch (pro_com_a_wr0 & 0007)
     {
       case 00:
         data = pro_com_a_rr0;
         break;
       case 01:
         data = pro_com_a_rr1;
         break;
       case 02:
         data = pro_com_a_rr2;
         break;
       default:
         data = 0;
         break;
     }
     pro_com_a_wr0 = pro_com_a_wr0 & ~0007;
     break;
   case 017773306:
     if ((pro_com_b_wr0 & 0007) == 02)
     {
       if (pro_com_intq_h != pro_com_intq_t)
       {
         data = pro_com_intq[pro_com_intq_h];
         pro_com_a_rr0 |= 0002;
       }
       else
         data = 0034;
       data |= (pro_com_b_wr2 & 0343);
     }
       else
         data = 0;
     pro_com_b_wr0 = pro_com_b_wr0 & ~0007;
     break;
   case 017773310:
     data = pro_com_mcr0;
     break;
   case 017773312:
     pro_com_ctrl_get();
     data = pro_com_mcr1;
     break;
   case 017773304:
   case 017773314:
     data = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_com_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017773300:
     data = pro_com_dataq[pro_com_dataq_h];
     if (pro_com_dataq_h != pro_com_dataq_t)
     {
       pro_com_dataq_h++;
       if (pro_com_dataq_h == (6 + 1))
         pro_com_dataq_h = 0;
     }
     if (pro_com_dataq_h == pro_com_dataq_t)
       pro_com_a_rr0 &= ~0001;
     break;
   case 017773302:
     switch (pro_com_a_wr0 & 0007)
     {
       case 00:
         data = pro_com_a_rr0;
         break;
       case 01:
         data = pro_com_a_rr1;
         break;
       case 02:
         data = pro_com_a_rr2;
         break;
       default:
         data = 0;
         break;
     }
     pro_com_a_wr0 = pro_com_a_wr0 & ~0007;
     break;
   case 017773306:
     if ((pro_com_b_wr0 & 0007) == 02)
     {
       if (pro_com_intq_h != pro_com_intq_t)
       {
         data = pro_com_intq[pro_com_intq_h];
         pro_com_a_rr0 |= 0002;
       }
       else
         data = 0034;
       data |= (pro_com_b_wr2 & 0343);
     }
       else
         data = 0;
     pro_com_b_wr0 = pro_com_b_wr0 & ~0007;
     break;
   case 017773310:
     data = pro_com_mcr0;
     break;
   case 017773312:
     pro_com_ctrl_get();
     data = pro_com_mcr1;
     break;
   case 017773304:
   case 017773314:
     data = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}


decompiled_code:
char __fastcall pro_com_wr(unsigned __int8 a1, int a2, int a3)
{
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // ecx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx
int v17; // eax
int v18; // eax

LOBYTE(v3) = (a2 & 0xFE) + 64;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF6C0:
if ( (pro_com_a_wr5 & 8) != 0 )
{
if ( a3 == 4 )
{
v5 = pro_com_wdata;
if ( (a2 & 1) == 0 )
{
LOBYTE(v5) = 0;
v5 |= a1;
}
pro_com_wdata = v5;
}
else
{
v4 = pro_com_wdata;
LOBYTE(v4) = 0;
pro_com_wdata = v4 | a1;
}
pro_com_a_rr0 &= 0xFFFFFFFB;
pro_com_a_rr1 &= 0xFFFFFFFE;
LOBYTE(v3) = pro_eq_sched(9LL, 3LL);
}
break;
case 0x3FF6C2:
v3 = pro_com_a_wr0;
if ( (pro_com_a_wr0 & 7) != 0 )
{
switch ( pro_com_a_wr0 & 7 )
{
case 0:
break;
case 1:
if ( a3 == 4 )
{
v3 = pro_com_a_wr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr1 = v3;
}
else
{
v3 = pro_com_a_wr1;
LOBYTE(v3) = 0;
pro_com_a_wr1 = v3 | a1;
}
break;
case 2:
if ( a3 == 4 )
{
v3 = pro_com_a_wr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr2 = v3;
}
else
{
v3 = pro_com_a_wr2;
LOBYTE(v3) = 0;
pro_com_a_wr2 = v3 | a1;
}
break;
case 3:
if ( a3 == 4 )
{
v7 = pro_com_a_wr3;
if ( (a2 & 1) == 0 )
{
LOBYTE(v7) = 0;
v7 |= a1;
}
pro_com_a_wr3 = v7;
}
else
{
v6 = pro_com_a_wr3;
LOBYTE(v6) = 0;
pro_com_a_wr3 = v6 | a1;
}
goto LABEL_35;
case 4:
if ( a3 == 4 )
{
v9 = pro_com_a_wr4;
if ( (a2 & 1) == 0 )
{
LOBYTE(v9) = 0;
v9 |= a1;
}
pro_com_a_wr4 = v9;
}
else
{
v8 = pro_com_a_wr4;
LOBYTE(v8) = 0;
pro_com_a_wr4 = v8 | a1;
}
goto LABEL_35;
case 5:
if ( a3 == 4 )
{
v11 = pro_com_a_wr5;
if ( (a2 & 1) == 0 )
{
LOBYTE(v11) = 0;
v11 |= a1;
}
pro_com_a_wr5 = v11;
}
else
{
v10 = pro_com_a_wr5;
LOBYTE(v10) = 0;
pro_com_a_wr5 = v10 | a1;
}
LABEL_35:
LOBYTE(v3) = pro_com_ctrl_put();
break;
case 6:
if ( a3 == 4 )
{
v3 = pro_com_a_wr6;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr6 = v3;
}
else
{
v3 = pro_com_a_wr6;
LOBYTE(v3) = 0;
pro_com_a_wr6 = v3 | a1;
}
break;
case 7:
if ( a3 == 4 )
{
v3 = pro_com_a_wr7;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr7 = v3;
}
else
{
v3 = pro_com_a_wr7;
LOBYTE(v3) = 0;
pro_com_a_wr7 = v3 | a1;
}
break;
}
pro_com_a_wr0 &= 0xFFFFFFF8;
}
else
{
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_com_a_wr0 = v3;
}
else
{
LOBYTE(v3) = 0;
pro_com_a_wr0 = v3 | a1;
}
v3 = pro_com_a_wr0 & 0x38;
if ( v3 == 56 )
{
LOBYTE(v3) = pro_com_intq_h;
if ( pro_com_intq_h != pro_com_intq_t )
{
v3 = 0;
if ( pro_com_intq_h != 16 )
v3 = pro_com_intq_h + 1;
pro_com_intq_h = v3;
if ( pro_com_intq_t == v3 )
pro_com_a_rr0 &= 0xFFFFFFFD;
else
LOBYTE(v3) = pro_int_set(8LL);
}
}
}
break;
case 0x3FF6C6:
v3 = pro_com_b_wr0;
v12 = pro_com_b_wr0 & 7;
if ( (pro_com_b_wr0 & 7) != 0 )
{
if ( v12 == 1 )
{
if ( a3 == 4 )
{
v14 = pro_com_b_wr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v14) = 0;
v14 |= a1;
}
pro_com_b_wr1 = v14;
}
else
{
v13 = pro_com_b_wr1;
LOBYTE(v13) = 0;
pro_com_b_wr1 = v13 | a1;
}
}
else if ( v12 == 2 )
{
if ( a3 == 4 )
{
v16 = pro_com_b_wr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v16) = 0;
v16 |= a1;
}
pro_com_b_wr2 = v16;
}
else
{
v15 = pro_com_b_wr2;
LOBYTE(v15) = 0;
pro_com_b_wr2 = v15 | a1;
}
}
LOBYTE(v3) = pro_com_b_wr0 & 0xF8;
pro_com_b_wr0 &= 0xFFFFFFF8;
}
else if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_com_b_wr0 = v3;
}
else
{
LOBYTE(v3) = 0;
pro_com_b_wr0 = v3 | a1;
}
break;
case 0x3FF6C8:
if ( a3 == 4 )
{
v3 = pro_com_mcr0;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_mcr0 = v3;
}
else
{
v3 = pro_com_mcr0;
LOBYTE(v3) = 0;
pro_com_mcr0 = v3 | a1;
}
break;
case 0x3FF6CC:
if ( a3 == 4 )
{
v18 = pro_com_baud;
if ( (a2 & 1) == 0 )
{
LOBYTE(v18) = 0;
v18 |= a1;
}
pro_com_baud = v18;
}
else
{
v17 = pro_com_baud;
LOBYTE(v17) = 0;
pro_com_baud = v17 | a1;
}
LOBYTE(v3) = pro_com_ctrl_put();
break;
default:
return v3;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func7(unsigned __int8 a1, int a2, int a3)
{
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // ecx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx
int v17; // eax
int v18; // eax

LOBYTE(v3) = (a2 & 0xFE) + 64;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF6C0:
if ( (pro_com_a_wr5 & 8) != 0 )
{
if ( a3 == 4 )
{
v5 = pro_com_wdata;
if ( (a2 & 1) == 0 )
{
LOBYTE(v5) = 0;
v5 |= a1;
}
pro_com_wdata = v5;
}
else
{
v4 = pro_com_wdata;
LOBYTE(v4) = 0;
pro_com_wdata = v4 | a1;
}
pro_com_a_rr0 &= 0xFFFFFFFB;
pro_com_a_rr1 &= 0xFFFFFFFE;
LOBYTE(v3) = pro_eq_sched(9LL, 3LL);
}
break;
case 0x3FF6C2:
v3 = pro_com_a_wr0;
if ( (pro_com_a_wr0 & 7) != 0 )
{
switch ( pro_com_a_wr0 & 7 )
{
case 0:
break;
case 1:
if ( a3 == 4 )
{
v3 = pro_com_a_wr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr1 = v3;
}
else
{
v3 = pro_com_a_wr1;
LOBYTE(v3) = 0;
pro_com_a_wr1 = v3 | a1;
}
break;
case 2:
if ( a3 == 4 )
{
v3 = pro_com_a_wr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr2 = v3;
}
else
{
v3 = pro_com_a_wr2;
LOBYTE(v3) = 0;
pro_com_a_wr2 = v3 | a1;
}
break;
case 3:
if ( a3 == 4 )
{
v7 = pro_com_a_wr3;
if ( (a2 & 1) == 0 )
{
LOBYTE(v7) = 0;
v7 |= a1;
}
pro_com_a_wr3 = v7;
}
else
{
v6 = pro_com_a_wr3;
LOBYTE(v6) = 0;
pro_com_a_wr3 = v6 | a1;
}
goto LABEL_35;
case 4:
if ( a3 == 4 )
{
v9 = pro_com_a_wr4;
if ( (a2 & 1) == 0 )
{
LOBYTE(v9) = 0;
v9 |= a1;
}
pro_com_a_wr4 = v9;
}
else
{
v8 = pro_com_a_wr4;
LOBYTE(v8) = 0;
pro_com_a_wr4 = v8 | a1;
}
goto LABEL_35;
case 5:
if ( a3 == 4 )
{
v11 = pro_com_a_wr5;
if ( (a2 & 1) == 0 )
{
LOBYTE(v11) = 0;
v11 |= a1;
}
pro_com_a_wr5 = v11;
}
else
{
v10 = pro_com_a_wr5;
LOBYTE(v10) = 0;
pro_com_a_wr5 = v10 | a1;
}
LABEL_35:
LOBYTE(v3) = func1();
break;
case 6:
if ( a3 == 4 )
{
v3 = pro_com_a_wr6;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr6 = v3;
}
else
{
v3 = pro_com_a_wr6;
LOBYTE(v3) = 0;
pro_com_a_wr6 = v3 | a1;
}
break;
case 7:
if ( a3 == 4 )
{
v3 = pro_com_a_wr7;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_a_wr7 = v3;
}
else
{
v3 = pro_com_a_wr7;
LOBYTE(v3) = 0;
pro_com_a_wr7 = v3 | a1;
}
break;
}
pro_com_a_wr0 &= 0xFFFFFFF8;
}
else
{
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_com_a_wr0 = v3;
}
else
{
LOBYTE(v3) = 0;
pro_com_a_wr0 = v3 | a1;
}
v3 = pro_com_a_wr0 & 0x38;
if ( v3 == 56 )
{
LOBYTE(v3) = pro_com_intq_h;
if ( pro_com_intq_h != pro_com_intq_t )
{
v3 = 0;
if ( pro_com_intq_h != 16 )
v3 = pro_com_intq_h + 1;
pro_com_intq_h = v3;
if ( pro_com_intq_t == v3 )
pro_com_a_rr0 &= 0xFFFFFFFD;
else
LOBYTE(v3) = pro_int_set(8LL);
}
}
}
break;
case 0x3FF6C6:
v3 = pro_com_b_wr0;
v12 = pro_com_b_wr0 & 7;
if ( (pro_com_b_wr0 & 7) != 0 )
{
if ( v12 == 1 )
{
if ( a3 == 4 )
{
v14 = pro_com_b_wr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v14) = 0;
v14 |= a1;
}
pro_com_b_wr1 = v14;
}
else
{
v13 = pro_com_b_wr1;
LOBYTE(v13) = 0;
pro_com_b_wr1 = v13 | a1;
}
}
else if ( v12 == 2 )
{
if ( a3 == 4 )
{
v16 = pro_com_b_wr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v16) = 0;
v16 |= a1;
}
pro_com_b_wr2 = v16;
}
else
{
v15 = pro_com_b_wr2;
LOBYTE(v15) = 0;
pro_com_b_wr2 = v15 | a1;
}
}
LOBYTE(v3) = pro_com_b_wr0 & 0xF8;
pro_com_b_wr0 &= 0xFFFFFFF8;
}
else if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v3) = a1;
pro_com_b_wr0 = v3;
}
else
{
LOBYTE(v3) = 0;
pro_com_b_wr0 = v3 | a1;
}
break;
case 0x3FF6C8:
if ( a3 == 4 )
{
v3 = pro_com_mcr0;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_com_mcr0 = v3;
}
else
{
v3 = pro_com_mcr0;
LOBYTE(v3) = 0;
pro_com_mcr0 = v3 | a1;
}
break;
case 0x3FF6CC:
if ( a3 == 4 )
{
v18 = pro_com_baud;
if ( (a2 & 1) == 0 )
{
LOBYTE(v18) = 0;
v18 |= a1;
}
pro_com_baud = v18;
}
else
{
v17 = pro_com_baud;
LOBYTE(v17) = 0;
pro_com_baud = v17 | a1;
}
LOBYTE(v3) = func1();
break;
default:
return v3;
}
return v3;
}


decompiled_code:
__int64 pro_com_open()
{
(*(void (__fastcall **)(__int64, _QWORD))(pro_com + 32LL))(2LL, pro_com_port);
pro_com_ctrl_put();
return pro_com_ctrl_get();
}

canonical_decompiled_code:
__int64 func8()
{
(*(void (__fastcall **)(__int64, _QWORD))(pro_com + 32LL))(2LL, pro_com_port);
func1();
return func0();
}

original_code:
void pro_com_open ()
{
 pro_com->reset(2, pro_com_port);
 pro_com_ctrl_put();
 pro_com_ctrl_get();
}

canonical_original_code:
void pro_com_open()
{
 pro_com->reset(2, pro_com_port);
 pro_com_ctrl_put();
 pro_com_ctrl_get();
}


decompiled_code:
__int64 pro_com_reset()
{
int *v0; // rax

pro_com_ctrl = 0LL;
*(&pro_com_ctrl + 1) = 0LL;
*(&pro_com_ctrl + 2) = 0LL;
*(&pro_com_ctrl + 3) = 0LL;
*(&pro_com_ctrl + 4) = 0LL;
*(&pro_com_ctrl + 5) = 0LL;
*(&pro_com_ctrl + 6) = 0LL;
*((_DWORD *)&pro_com_ctrl + 14) = 0;
pro_com_dataq_h = 0;
pro_com_dataq_t = 0;
pro_com_dataq[0] = 0;
dword_A74 = 0;
dword_A78 = 0;
dword_A7C = 0;
dword_A80 = 0;
dword_A84 = 0;
pro_com_intq_h = 0;
pro_com_intq_t = 0;
v0 = pro_com_intq;
do
*v0++ = 0;
while ( v0 != (int *)&unk_A60 );
pro_com_a_wr0 = 0;
pro_com_a_wr1 = 0;
pro_com_a_wr2 = 0;
pro_com_a_wr3 = 0;
pro_com_a_wr4 = 0;
pro_com_a_wr5 = 0;
pro_com_a_wr6 = 0;
pro_com_a_wr7 = 0;
pro_com_a_rr0 = 68;
pro_com_a_rr1 = 1;
pro_com_a_rr2 = 0;
pro_com_b_wr0 = 0;
pro_com_b_wr1 = 0;
pro_com_b_wr2 = 0;
pro_com_mcr0 = 0;
pro_com_mcr1 = 0;
pro_com_baud = 0;
pro_com_wdata = 0;
pro_eq_sched(10LL, 100LL);
return pro_com_open();
}

canonical_decompiled_code:
__int64 func9()
{
int *v0; // rax

pro_com_ctrl = 0LL;
*(&pro_com_ctrl + 1) = 0LL;
*(&pro_com_ctrl + 2) = 0LL;
*(&pro_com_ctrl + 3) = 0LL;
*(&pro_com_ctrl + 4) = 0LL;
*(&pro_com_ctrl + 5) = 0LL;
*(&pro_com_ctrl + 6) = 0LL;
*((_DWORD *)&pro_com_ctrl + 14) = 0;
pro_com_dataq_h = 0;
pro_com_dataq_t = 0;
pro_com_dataq[0] = 0;
dword_A74 = 0;
dword_A78 = 0;
dword_A7C = 0;
dword_A80 = 0;
dword_A84 = 0;
pro_com_intq_h = 0;
pro_com_intq_t = 0;
v0 = pro_com_intq;
do
*v0++ = 0;
while ( v0 != (int *)&unk_A60 );
pro_com_a_wr0 = 0;
pro_com_a_wr1 = 0;
pro_com_a_wr2 = 0;
pro_com_a_wr3 = 0;
pro_com_a_wr4 = 0;
pro_com_a_wr5 = 0;
pro_com_a_wr6 = 0;
pro_com_a_wr7 = 0;
pro_com_a_rr0 = 68;
pro_com_a_rr1 = 1;
pro_com_a_rr2 = 0;
pro_com_b_wr0 = 0;
pro_com_b_wr1 = 0;
pro_com_b_wr2 = 0;
pro_com_mcr0 = 0;
pro_com_mcr1 = 0;
pro_com_baud = 0;
pro_com_wdata = 0;
pro_eq_sched(10LL, 100LL);
return func8();
}

original_code:
void pro_com_reset ()
{
int i;
 memset(&pro_com_ctrl, 0, sizeof(pro_com_ctrl));
 pro_com_dataq_h = 0;
 pro_com_dataq_t = 0;
 for(i=0; i<6; i++)
   pro_com_dataq[i] = 0;
 pro_com_intq_h = 0;
 pro_com_intq_t = 0;
 for(i=0; i<16; i++)
   pro_com_intq[i] = 0;
 pro_com_a_wr0 = 0;
 pro_com_a_wr1 = 0;
 pro_com_a_wr2 = 0;
 pro_com_a_wr3 = 0;
 pro_com_a_wr4 = 0;
 pro_com_a_wr5 = 0;
 pro_com_a_wr6 = 0;
 pro_com_a_wr7 = 0;
 pro_com_a_rr0 = 0100 | 0004;
 pro_com_a_rr1 = 0001;
 pro_com_a_rr2 = 0;
 pro_com_b_wr0 = 0;
 pro_com_b_wr1 = 0;
 pro_com_b_wr2 = 0;
 pro_com_mcr0 = 0;
 pro_com_mcr1 = 0;
 pro_com_baud = 0;
 pro_com_wdata = 0;
 pro_eq_sched(10, 100);
 pro_com_open();
}

canonical_original_code:
void pro_com_reset()
{
int i;
 memset(&pro_com_ctrl, 0, sizeof(pro_com_ctrl));
 pro_com_dataq_h = 0;
 pro_com_dataq_t = 0;
 for(i=0; i<6; i++)
   pro_com_dataq[i] = 0;
 pro_com_intq_h = 0;
 pro_com_intq_t = 0;
 for(i=0; i<16; i++)
   pro_com_intq[i] = 0;
 pro_com_a_wr0 = 0;
 pro_com_a_wr1 = 0;
 pro_com_a_wr2 = 0;
 pro_com_a_wr3 = 0;
 pro_com_a_wr4 = 0;
 pro_com_a_wr5 = 0;
 pro_com_a_wr6 = 0;
 pro_com_a_wr7 = 0;
 pro_com_a_rr0 = 0100 | 0004;
 pro_com_a_rr1 = 0001;
 pro_com_a_rr2 = 0;
 pro_com_b_wr0 = 0;
 pro_com_b_wr1 = 0;
 pro_com_b_wr2 = 0;
 pro_com_mcr0 = 0;
 pro_com_mcr1 = 0;
 pro_com_baud = 0;
 pro_com_wdata = 0;
 pro_eq_sched(10, 100);
 pro_com_open();
}


decompiled_code:
__int64 pro_com_exit()
{
return (*(__int64 (__fastcall **)(__int64))(pro_com + 40LL))(2LL);
}

original_code:
void pro_com_exit ()
{
 pro_com->exit(2);
}

canonical_original_code:
void pro_com_exit()
{
 pro_com->exit(2);
}


original_code:
static void pro_overlay_print_char(int x, int y, int xnor, int font, char ch)
{
int sx, sy, sx0, sy0;
int i, pix, pnum, opix, vindex;
int charint;
 charint = ((int)ch) - 24;
 if ((charint < 0) || (charint>(104 -1)))
   charint = 32 - 24;
 sx0 = x * 12;
 sy0 = y * 10;
 for(y=0; y<10; y++)
 {
   sy = sy0 + y;
   for(x=0; x<12; x++)
   {
     sx = sx0 + x;
     if (((pro_overlay_font[font][charint][y] >> (11-x)) & 01) == 0)
       pix = blackpixel;
     else
       pix = whitepixel;
     pnum = sy*1024 +sx;
     if (xnor == 1)
     {
       opix = 0;
       for(i=0; i<pixsize; i++)
         opix |= pro_overlay_data[pixsize*pnum+i] << (i*8);
       if (opix == blackpixel)
       {
         if (pix == blackpixel)
           pix = whitepixel;
         else
           pix = blackpixel;
       }
     }
     if (pix == blackpixel)
       pro_overlay_alpha[sy*1024 +sx] = overlay_a;
     else
       pro_overlay_alpha[sy*1024 +sx] = 128;
     for(i=0; i<pixsize; i++)
       pro_overlay_data[pixsize*pnum+i] = pix >> (i*8);
     vindex = ((((sy<<6) | ((sx>>4)&077)) + pro_vid_y_offset) & 0037777);
     pro_vid_mvalid[((vindex) >> 6)] = 0;
   }
 }
}

canonical_original_code:
static void pro_overlay_print_char(int x, int y, int xnor, int font, char ch)
{
int sx; int sy; int sx0; int sy0;
int i; int pix; int pnum; int opix; int vindex;
int charint;
 charint = ((int)ch) - 24;
 if ((charint < 0) || (charint>(104 -1)))
   charint = 32 - 24;
 sx0 = x * 12;
 sy0 = y * 10;
 for(y=0; y<10; y++)
 {
   sy = sy0 + y;
   for(x=0; x<12; x++)
   {
     sx = sx0 + x;
     if (((pro_overlay_font[font][charint][y] >> (11-x)) & 01) == 0)
       pix = blackpixel;
     else
       pix = whitepixel;
     pnum = sy*1024 +sx;
     if (xnor == 1)
     {
       opix = 0;
       for(i=0; i<pixsize; i++)
         opix |= pro_overlay_data[pixsize*pnum+i] << (i*8);
       if (opix == blackpixel)
       {
         if (pix == blackpixel)
           pix = whitepixel;
         else
           pix = blackpixel;
       }
     }
     if (pix == blackpixel)
       pro_overlay_alpha[sy*1024 +sx] = overlay_a;
     else
       pro_overlay_alpha[sy*1024 +sx] = 128;
     for(i=0; i<pixsize; i++)
       pro_overlay_data[pixsize*pnum+i] = pix >> (i*8);
     vindex = ((((sy<<6) | ((sx>>4)&077)) + pro_vid_y_offset) & 0037777);
     pro_vid_mvalid[((vindex) >> 6)] = 0;
   }
 }
}

variable_types: x int

variable_types: y int

variable_types: xnor int

variable_types: font int

variable_types: ch char

variable_types: sx int

variable_types: sy int

variable_types: pix int

variable_types: pnum int

variable_types: opix int

variable_types: vindex int

variable_types: charint int


decompiled_code:
void __fastcall pro_overlay_print(int a1, int a2, int a3, int a4, const char *a5)
{
int v7; // ebp
char *v8; // rbx
int v9; // eax
__int64 v10; // r15
int v11; // er14
int v12; // [rsp+4h] [rbp-44h]
int v13; // [rsp+8h] [rbp-40h]

v12 = a1;
if ( pro_overlay_open )
{
if ( a1 == -1 )
{
v12 = start_x;
}
else if ( a1 == -2 )
{
v12 = last_x + last_size;
}
else
{
start_x = a1;
}
if ( a2 == -1 )
{
a2 = last_y + 1;
}
else if ( a2 == -2 )
{
a2 = last_y;
}
v7 = 23;
if ( a2 <= 23 )
v7 = a2;
v8 = (char *)a5;
v9 = strlen(a5);
v13 = v9;
if ( v9 > 0 )
{
v10 = (__int64)&v8[v9 - 1 + 1];
v11 = v12 - (_DWORD)v8;
do
{
pro_overlay_print_char(v11 + (_DWORD)v8, v7, a3, a4, *v8);
++v8;
}
while ( v8 != (char *)v10 );
}
last_x = v12;
last_y = v7;
last_size = v13;
}
}

original_code:
void pro_overlay_print(int x, int y, int xnor, int font, char *text)
{
int i, size;
 if (pro_overlay_open)
 {
   if (x == -1)
     x = start_x;
   else if (x == -2)
     x = last_x + last_size;
   else
     start_x = x;
   if (y == -1)
     y = last_y + 1;
   else if (y == -2)
     y = last_y;
   if (y > 23)
     y = 23;
   size = strlen(text);
   for(i=0; i<size; i++)
     pro_overlay_print_char(x+i, y, xnor, font, text[i]);
   last_x = x;
   last_y = y;
   last_size = size;
 }
}

canonical_original_code:
void pro_overlay_print(int x, int y, int xnor, int font, char *text)
{
int i; int size;
 if (pro_overlay_open)
 {
   if (x == -1)
     x = start_x;
   else if (x == -2)
     x = last_x + last_size;
   else
     start_x = x;
   if (y == -1)
     y = last_y + 1;
   else if (y == -2)
     y = last_y;
   if (y > 23)
     y = 23;
   size = strlen(text);
   for(i=0; i<size; i++)
     pro_overlay_print_char(x+i, y, xnor, font, text[i]);
   last_x = x;
   last_y = y;
   last_size = size;
 }
}

variable_types:
text
char *

variable_types: i int

variable_types: size int


decompiled_code:
void pro_overlay_clear()
{
int v0; // er11
int v1; // er8
int v2; // edi
int v3; // er10
__int64 i; // r9
int v5; // ecx
__int64 v6; // rax

if ( pro_overlay_open )
{
v0 = pixsize;
v1 = blackpixel;
v2 = 8 * pixsize;
v3 = 0;
for ( i = 0LL; i != 0x40000; ++i )
{
v6 = v3;
v5 = 0;
if ( v0 > 0 )
{
do
{
*((_BYTE *)pro_overlay_data + v6) = v1 >> v5;
v5 += 8;
++v6;
}
while ( v2 != v5 );
}
*((_BYTE *)pro_overlay_alpha + i) = 0;
v3 += v0;
}
}
}

canonical_decompiled_code:
void func2()
{
int v0; // er11
int v1; // er8
int v2; // edi
int v3; // er10
__int64 i; // r9
int v5; // ecx
__int64 v6; // rax

if ( pro_overlay_open )
{
v0 = pixsize;
v1 = blackpixel;
v2 = 8 * pixsize;
v3 = 0;
for ( i = 0LL; i != 0x40000; ++i )
{
v6 = v3;
v5 = 0;
if ( v0 > 0 )
{
do
{
*((_BYTE *)pro_overlay_data + v6) = v1 >> v5;
v5 += 8;
++v6;
}
while ( v2 != v5 );
}
*((_BYTE *)pro_overlay_alpha + i) = 0;
v3 += v0;
}
}
}

original_code:
void pro_overlay_clear ()
{
int i, j;
 if (pro_overlay_open)
 {
   for(i=0; i<1024*256; i++)
   {
     for(j=0; j<pixsize; j++)
       pro_overlay_data[pixsize*i+j] = blackpixel >> (j*8);
     pro_overlay_alpha[i] = 0;
   }
 }
}

canonical_original_code:
void pro_overlay_clear()
{
int i; int j;
 if (pro_overlay_open)
 {
   for(i=0; i<1024*256; i++)
   {
     for(j=0; j<pixsize; j++)
       pro_overlay_data[pixsize*i+j] = blackpixel >> (j*8);
     pro_overlay_alpha[i] = 0;
   }
 }
}

variable_types: j int


decompiled_code:
void pro_overlay_enable()
{
pro_overlay_clear();
pro_overlay_on = 1;
}

canonical_decompiled_code:
void func3()
{
func2();
pro_overlay_on = 1;
}

original_code:
void pro_overlay_enable ()
{
 pro_overlay_clear();
 pro_overlay_on = 1;
}


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

result = pro_clear_mvalid();
pro_overlay_on = 0;
return result;
}

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

result = pro_clear_mvalid();
pro_overlay_on = 0;
return result;
}

original_code:
void pro_overlay_disable ()
{
 pro_clear_mvalid();
 pro_overlay_on = 0;
}

canonical_original_code:
void pro_overlay_disable()
{
 pro_clear_mvalid();
 pro_overlay_on = 0;
}


decompiled_code:
void __fastcall pro_overlay_init(int a1, int a2, int a3, int a4)
{
int v4; // eax

if ( !pro_overlay_open )
{
start_x = 0;
last_x = 0;
last_y = 0;
last_size = 0;
pixsize = a1;
blackpixel = a3;
whitepixel = a4;
v4 = 128;
if ( a2 != 1 )
v4 = 80;
overlay_a = v4;
pro_overlay_data = malloc(a1 << 18);
pro_overlay_alpha = malloc(0x40000uLL);
pro_overlay_on = 0;
pro_overlay_open = 1;
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2, int a3, int a4)
{
int v4; // eax

if ( !pro_overlay_open )
{
start_x = 0;
last_x = 0;
last_y = 0;
last_size = 0;
pixsize = a1;
blackpixel = a3;
whitepixel = a4;
v4 = 128;
if ( a2 != 1 )
v4 = 80;
overlay_a = v4;
pro_overlay_data = malloc(a1 << 18);
pro_overlay_alpha = malloc(0x40000uLL);
pro_overlay_on = 0;
pro_overlay_open = 1;
}
}

original_code:
void pro_overlay_init (int psize, int cmode, int bpixel, int wpixel)
{
 if (pro_overlay_open == 0)
 {
   start_x = 0;
   last_x = 0;
   last_y = 0;
   last_size = 0;
   clutmode = cmode;
   pixsize = psize;
   blackpixel = bpixel;
   whitepixel = wpixel;
   if (cmode == 1)
     overlay_a = 128;
   else
     overlay_a = 80;
   pro_overlay_data = (char *)malloc(1024*256*pixsize);
   pro_overlay_alpha = (char *)malloc(1024*256);
   pro_overlay_on = 0;
   pro_overlay_open = 1;
 }
}

canonical_original_code:
void pro_overlay_init(int psize, int cmode, int bpixel, int wpixel)
{
 if (pro_overlay_open == 0)
 {
   start_x = 0;
   last_x = 0;
   last_y = 0;
   last_size = 0;
   clutmode = cmode;
   pixsize = psize;
   blackpixel = bpixel;
   whitepixel = wpixel;
   if (cmode == 1)
     overlay_a = 128;
   else
     overlay_a = 80;
   pro_overlay_data = (char *)malloc(1024*256*pixsize);
   pro_overlay_alpha = (char *)malloc(1024*256);
   pro_overlay_on = 0;
   pro_overlay_open = 1;
 }
}

variable_types: psize int

variable_types: cmode int

variable_types: bpixel int

variable_types: wpixel int


decompiled_code:
void pro_overlay_close()
{
if ( pro_overlay_open )
{
free(pro_overlay_data);
free(pro_overlay_alpha);
pro_overlay_on = 0;
pro_overlay_open = 0;
}
}

canonical_decompiled_code:
void func6()
{
if ( pro_overlay_open )
{
free(pro_overlay_data);
free(pro_overlay_alpha);
pro_overlay_on = 0;
pro_overlay_open = 0;
}
}

original_code:
void pro_overlay_close ()
{
 if (pro_overlay_open)
 {
   free(pro_overlay_data);
   free(pro_overlay_alpha);
   pro_overlay_on = 0;
   pro_overlay_open = 0;
 }
}

canonical_original_code:
void pro_overlay_close()
{
 if (pro_overlay_open)
 {
   free(pro_overlay_data);
   free(pro_overlay_alpha);
   pro_overlay_on = 0;
   pro_overlay_open = 0;
 }
}


decompiled_code:
unsigned __int64 __fastcall bigtime_sub(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
unsigned __int64 v4; // rax
unsigned int v5; // edi
int v6; // eax

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

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1, int a2, __int64 a3, int a4)
{
unsigned __int64 v4; // rax
unsigned int v5; // edi
int v6; // eax

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

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


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()
{
int v0; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
pro_time = (__int64)localtime(&timer);
v0 = *(_DWORD *)pro_time;
pro_time_min = *(_DWORD *)(pro_time + 4);
pro_time_hour = *(_DWORD *)(pro_time + 8);
result = 59LL;
if ( v0 >= 60 )
v0 = 59;
pro_time_sec = v0;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
pro_time = (__int64)localtime(&timer);
v0 = *(_DWORD *)pro_time;
pro_time_min = *(_DWORD *)(pro_time + 4);
pro_time_hour = *(_DWORD *)(pro_time + 8);
result = 59LL;
if ( v0 >= 60 )
v0 = 59;
pro_time_sec = v0;
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


decompiled_code:
__int64 pro_time_get()
{
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF
__int64 v2; // [rsp+24h] [rbp-14h]

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

canonical_decompiled_code:
__int64 func4()
{
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF
__int64 v2; // [rsp+24h] [rbp-14h]

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

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 func5()
{
return pro_eq_sched(2LL, 98LL);
}