original_code:
long big_send(long src, long * dest, long * msg)
{
  struct msg_struct * msg_p = big_receive_head;
  struct msg_struct * msg_t = ((void *) 0);
  if(src < 0 || src >= 64)
    return -1;
  if(*dest < 0 || *dest >= 64)
    return -1;
  while(msg_p)
    {
      if(*dest==msg_p->dest &&
  (src==*((long *)(msg_p->src)) || *((long *)(msg_p->src))==-1))
 break;
      msg_t = msg_p;
      msg_p = msg_p->next;
    }
  if(msg_p)
    {
      share_page((unsigned long)(*msg), (unsigned long)(msg_p->msg));
      if(*((long *)(msg_p->src)) == -1)
 *((long *)(msg_p->src)) = src;
      if(!msg_t)
        big_receive_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        big_receive_tail = msg_t;
      proc[msg_p->dest]->state = 0;
      schedule();
      return 1;
    }
  msg_p = small_send_head;
  while(msg_p)
    {
      if(dest==msg_p->src && src==msg_p->dest)
        return -1;
      msg_p = msg_p->next;
    }
  msg_p = small_receive_head;
  while(msg_p)
    {
      if(dest==msg_p->dest && src==*((long *)(msg_p->src)))
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_send_head;
  while(msg_p)
    {
      if(dest==msg_p->src && src==msg_p->dest)
        return -1;
      msg_p = msg_p->next;
    }
  struct msg_struct new_msg;
  msg_p = &new_msg;
  msg_p->src = src;
  msg_p->dest = *dest;
  msg_p->msg = *msg;
  msg_p->next = ((void *) 0);
  if(!big_send_head)
    big_send_head = big_send_tail = msg_p;
  else
    {
      big_send_tail->next = msg_p;
      big_send_tail = msg_p;
    }
  proc[src]->state = 1;
  schedule();
  return 1;
}

canonical_original_code:
long big_send(long src, long *dest, long *msg)
{
  struct msg_struct *msg_p = big_receive_head;
  struct msg_struct *msg_t = ((void *) 0);
  if(src < 0 || src >= 64)
    return -1;
  if(*dest < 0 || *dest >= 64)
    return -1;
  while(msg_p)
    {
      if(*dest==msg_p->dest &&
  (src==*((long *)(msg_p->src)) || *((long *)(msg_p->src))==-1))
 break;
      msg_t = msg_p;
      msg_p = msg_p->next;
    }
  if(msg_p)
    {
      share_page((unsigned long)(*msg), (unsigned long)(msg_p->msg));
      if(*((long *)(msg_p->src)) == -1)
 *((long *)(msg_p->src)) = src;
      if(!msg_t)
        big_receive_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        big_receive_tail = msg_t;
      proc[msg_p->dest]->state = 0;
      schedule();
      return 1;
    }
  msg_p = small_send_head;
  while(msg_p)
    {
      if(dest==msg_p->src && src==msg_p->dest)
        return -1;
      msg_p = msg_p->next;
    }
  msg_p = small_receive_head;
  while(msg_p)
    {
      if(dest==msg_p->dest && src==*((long *)(msg_p->src)))
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_send_head;
  while(msg_p)
    {
      if(dest==msg_p->src && src==msg_p->dest)
        return -1;
      msg_p = msg_p->next;
    }
  struct msg_struct new_msg;
  msg_p = &new_msg;
  msg_p->src = src;
  msg_p->dest = *dest;
  msg_p->msg = *msg;
  msg_p->next = ((void *) 0);
  if(!big_send_head)
    big_send_head = big_send_tail = msg_p;
  else
    {
      big_send_tail->next = msg_p;
      big_send_tail = msg_p;
    }
  proc[src]->state = 1;
  schedule();
  return 1;
}

user_defined_types: struct msg_struct { long src; long dest; long msg; struct msg_struct *next; }


repo: Cassidy/mks

decompiled_code:
__int64 __fastcall big_receive(_QWORD *a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rdx
_QWORD *v5; // rcx
__int64 result; // rax
_QWORD *v8; // rbx
__int64 v9; // r12
__int64 v10; // rdi
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // r8
_QWORD *v15; // rax
_QWORD *v16; // rax
_QWORD *v17; // rax
_QWORD *v18; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v19; // [rsp+8h] [rbp-30h]
__int64 v20; // [rsp+10h] [rbp-28h]
__int64 v21; // [rsp+18h] [rbp-20h]

v4 = *a1;
v5 = (_QWORD *)(*a1 + 1LL);
result = -1LL;
if ( (unsigned __int64)v5 <= 0x40 && a2 <= 0x3F )
{
v8 = (_QWORD *)big_send_head;
if ( big_send_head )
{
v9 = 0LL;
while ( v8[1] != a2 || *v8 != v4 && v4 != -1 )
{
v9 = (__int64)v8;
if ( !v8[3] )
goto LABEL_33;
v8 = (_QWORD *)v8[3];
}
v10 = v8[2];
v11 = *a3;
share_page(v10, *a3);
if ( *a1 == -1LL )
*a1 = *v8;
if ( v9 )
*(_QWORD *)(v9 + 24) = v8[3];
else
big_send_head = v8[3];
if ( !v8[3] )
big_send_tail = v9;
*(_QWORD *)(*((_QWORD *)&proc + *v8) + 8LL) = 0LL;
schedule(v10, v11, v12, v13, v14);
result = 1LL;
}
else
{
LABEL_33:
v15 = (_QWORD *)small_send_head;
if ( small_send_head )
{
while ( v15[1] != a2 || v4 != *v15 )
{
v15 = (_QWORD *)v15[3];
if ( !v15 )
goto LABEL_34;
}
result = -1LL;
}
else
{
LABEL_34:
v16 = (_QWORD *)small_receive_head;
if ( small_receive_head )
{
while ( 1 )
{
v5 = (_QWORD *)*v16;
if ( *(_QWORD *)*v16 == a2 && v4 == v16[1] )
break;
v16 = (_QWORD *)v16[3];
if ( !v16 )
goto LABEL_35;
}
result = -1LL;
}
else
{
LABEL_35:
v17 = (_QWORD *)big_receive_head;
if ( big_receive_head )
{
do
{
v5 = (_QWORD *)*v17;
if ( *(_QWORD *)*v17 == a2 && v4 == v17[1] )
return -1LL;
v17 = (_QWORD *)v17[3];
}
while ( v17 );
v18 = a1;
v19 = a2;
v20 = *a3;
v21 = 0LL;
*(_QWORD *)(big_receive_tail + 24) = &v18;
big_receive_tail = (__int64)&v18;
}
else
{
v18 = a1;
v19 = a2;
v20 = *a3;
v21 = 0LL;
big_receive_tail = (__int64)&v18;
big_receive_head = (__int64)&v18;
}
*(_QWORD *)(*((_QWORD *)&proc + a2) + 8LL) = 1LL;
schedule(a1, a2, v4, v5, a3);
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rdx
_QWORD *v5; // rcx
__int64 result; // rax
_QWORD *v8; // rbx
__int64 v9; // r12
__int64 v10; // rdi
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // r8
_QWORD *v15; // rax
_QWORD *v16; // rax
_QWORD *v17; // rax
_QWORD *v18; // [rsp+0h] [rbp-38h] BYREF
unsigned __int64 v19; // [rsp+8h] [rbp-30h]
__int64 v20; // [rsp+10h] [rbp-28h]
__int64 v21; // [rsp+18h] [rbp-20h]

v4 = *a1;
v5 = (_QWORD *)(*a1 + 1LL);
result = -1LL;
if ( (unsigned __int64)v5 <= 0x40 && a2 <= 0x3F )
{
v8 = (_QWORD *)big_send_head;
if ( big_send_head )
{
v9 = 0LL;
while ( v8[1] != a2 || *v8 != v4 && v4 != -1 )
{
v9 = (__int64)v8;
if ( !v8[3] )
goto LABEL_33;
v8 = (_QWORD *)v8[3];
}
v10 = v8[2];
v11 = *a3;
share_page(v10, *a3);
if ( *a1 == -1LL )
*a1 = *v8;
if ( v9 )
*(_QWORD *)(v9 + 24) = v8[3];
else
big_send_head = v8[3];
if ( !v8[3] )
big_send_tail = v9;
*(_QWORD *)(*((_QWORD *)&proc + *v8) + 8LL) = 0LL;
schedule(v10, v11, v12, v13, v14);
result = 1LL;
}
else
{
LABEL_33:
v15 = (_QWORD *)small_send_head;
if ( small_send_head )
{
while ( v15[1] != a2 || v4 != *v15 )
{
v15 = (_QWORD *)v15[3];
if ( !v15 )
goto LABEL_34;
}
result = -1LL;
}
else
{
LABEL_34:
v16 = (_QWORD *)small_receive_head;
if ( small_receive_head )
{
while ( 1 )
{
v5 = (_QWORD *)*v16;
if ( *(_QWORD *)*v16 == a2 && v4 == v16[1] )
break;
v16 = (_QWORD *)v16[3];
if ( !v16 )
goto LABEL_35;
}
result = -1LL;
}
else
{
LABEL_35:
v17 = (_QWORD *)big_receive_head;
if ( big_receive_head )
{
do
{
v5 = (_QWORD *)*v17;
if ( *(_QWORD *)*v17 == a2 && v4 == v17[1] )
return -1LL;
v17 = (_QWORD *)v17[3];
}
while ( v17 );
v18 = a1;
v19 = a2;
v20 = *a3;
v21 = 0LL;
*(_QWORD *)(big_receive_tail + 24) = &v18;
big_receive_tail = (__int64)&v18;
}
else
{
v18 = a1;
v19 = a2;
v20 = *a3;
v21 = 0LL;
big_receive_tail = (__int64)&v18;
big_receive_head = (__int64)&v18;
}
*(_QWORD *)(*((_QWORD *)&proc + a2) + 8LL) = 1LL;
schedule(a1, a2, v4, v5, a3);
result = 1LL;
}
}
}
}
return result;
}

original_code:
long big_receive(long * src, long dest, long * msg)
{
  struct msg_struct * msg_p = big_send_head;
  struct msg_struct * msg_t = ((void *) 0);
  if((*src<0 && *src!=-1) || *src>=64)
    return -1;
  if(dest < 0 || dest >= 64)
    return -1;
  while(msg_p)
    {
      if(dest==msg_p->dest && (*src==msg_p->src || *src==-1))
 break;
      msg_t = msg_p;
      msg_p = msg_p->next;
    }
  if(msg_p)
    {
      share_page((unsigned long)(msg_p->msg), (unsigned long)(*msg));
      if(*src == -1)
 *src = msg_p->src;
      if(!msg_t)
        big_send_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        big_send_tail = msg_t;
      proc[msg_p->src]->state = 0;
      schedule();
      return 1;
    }
  msg_p = small_send_head;
  while(msg_p)
    {
      if(dest==msg_p->dest && *src==msg_p->src)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = small_receive_head;
  while(msg_p)
    {
      if(dest==*((long *)(msg_p->src)) && *src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_receive_head;
  while(msg_p)
    {
      if(dest==*((long *)(msg_p->src)) && *src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  struct msg_struct new_msg;
  msg_p = &new_msg;
  msg_p->src = (long)src;
  msg_p->dest = dest;
  msg_p->msg = *msg;
  msg_p->next = ((void *) 0);
  if(!big_receive_head)
    big_receive_head = big_receive_tail = msg_p;
  else
    {
      big_receive_tail->next = msg_p;
      big_receive_tail = msg_p;
    }
  proc[dest]->state = 1;
  schedule();
  return 1;
}

canonical_original_code:
long big_receive(long *src, long dest, long *msg)
{
  struct msg_struct *msg_p = big_send_head;
  struct msg_struct *msg_t = ((void *) 0);
  if((*src<0 && *src!=-1) || *src>=64)
    return -1;
  if(dest < 0 || dest >= 64)
    return -1;
  while(msg_p)
    {
      if(dest==msg_p->dest && (*src==msg_p->src || *src==-1))
 break;
      msg_t = msg_p;
      msg_p = msg_p->next;
    }
  if(msg_p)
    {
      share_page((unsigned long)(msg_p->msg), (unsigned long)(*msg));
      if(*src == -1)
 *src = msg_p->src;
      if(!msg_t)
        big_send_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        big_send_tail = msg_t;
      proc[msg_p->src]->state = 0;
      schedule();
      return 1;
    }
  msg_p = small_send_head;
  while(msg_p)
    {
      if(dest==msg_p->dest && *src==msg_p->src)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = small_receive_head;
  while(msg_p)
    {
      if(dest==*((long *)(msg_p->src)) && *src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  msg_p = big_receive_head;
  while(msg_p)
    {
      if(dest==*((long *)(msg_p->src)) && *src==msg_p->dest)
 return -1;
      msg_p = msg_p->next;
    }
  struct msg_struct new_msg;
  msg_p = &new_msg;
  msg_p->src = (long)src;
  msg_p->dest = dest;
  msg_p->msg = *msg;
  msg_p->next = ((void *) 0);
  if(!big_receive_head)
    big_receive_head = big_receive_tail = msg_p;
  else
    {
      big_receive_tail->next = msg_p;
      big_receive_tail = msg_p;
    }
  proc[dest]->state = 1;
  schedule();
  return 1;
}

variable_types:
src
long *

variable_types: dest long

variable_types:
msg
long *

variable_types: struct msg_struct { long src; long dest; long msg; struct msg_struct *next; } *

return_type: long


decompiled_code:
__int64 __fastcall do_intr_msg(__int64 a1, __int64 *a2, __int64 *a3, __int64 a4, __int64 a5)
{
unsigned __int64 v5; // rcx
__int64 result; // rax
__int64 v7[2]; // [rsp+0h] [rbp-10h] BYREF

v5 = *(_QWORD *)(proc_current + 72LL);
if ( *a2 == v5 )
return -1LL;
switch ( a1 )
{
case 1LL:
return small_send(*(_QWORD *)(proc_current + 72LL), a2, a3);
case 2LL:
return small_receive(a2, *(_QWORD *)(proc_current + 72LL), a3);
case 3LL:
v7[0] = (*a3 & 0xFFFFF000LL) + (v5 << 26) + 4096;
result = big_send((__int64 *)v5, a2, v7, v5, a5);
break;
case 4LL:
v7[0] = (*a3 & 0xFFFFF000LL) + (v5 << 26) + 4096;
result = big_receive(a2, v5, v7);
break;
default:
result = -1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 *a2, __int64 *a3, __int64 a4, __int64 a5)
{
unsigned __int64 v5; // rcx
__int64 result; // rax
__int64 v7[2]; // [rsp+0h] [rbp-10h] BYREF

v5 = *(_QWORD *)(proc_current + 72LL);
if ( *a2 == v5 )
return -1LL;
switch ( a1 )
{
case 1LL:
return func1(*(_QWORD *)(proc_current + 72LL), a2, a3);
case 2LL:
return func2(a2, *(_QWORD *)(proc_current + 72LL), a3);
case 3LL:
v7[0] = (*a3 & 0xFFFFF000LL) + (v5 << 26) + 4096;
result = func3((__int64 *)v5, a2, v7, v5, a5);
break;
case 4LL:
v7[0] = (*a3 & 0xFFFFF000LL) + (v5 << 26) + 4096;
result = func4(a2, v5, v7);
break;
default:
result = -1LL;
break;
}
return result;
}

original_code:
long do_intr_msg(long function, long * src_dest, long * msg)
{
  long a;
  long cur_pid = proc_current->pid;
  long entry;
  if(cur_pid == *src_dest)
    return -1;
  if(function == 1)
    a = small_send(cur_pid, src_dest, msg);
  else if(function == 2)
    a = small_receive(src_dest, cur_pid, msg);
  else if(function == 3)
    {
      entry = *msg;
      entry = (entry & 0xFFFFF000) + 0x1000;
      entry += cur_pid * 0x4000000;
      a = big_send(cur_pid, src_dest, &entry);
    }
  else if(function == 4)
    {
      entry = *msg;
      entry = (entry & 0xFFFFF000) + 0x1000;
      entry += cur_pid * 0x4000000;
      a = big_receive(src_dest, cur_pid, &entry);
    }
  else
    return -1;
  return a;
}

canonical_original_code:
long do_intr_msg(long function, long *src_dest, long *msg)
{
  long a;
  long cur_pid = proc_current->pid;
  long entry;
  if(cur_pid == *src_dest)
    return -1;
  if(function == 1)
    a = small_send(cur_pid, src_dest, msg);
  else if(function == 2)
    a = small_receive(src_dest, cur_pid, msg);
  else if(function == 3)
    {
      entry = *msg;
      entry = (entry & 0xFFFFF000) + 0x1000;
      entry += cur_pid * 0x4000000;
      a = big_send(cur_pid, src_dest, &entry);
    }
  else if(function == 4)
    {
      entry = *msg;
      entry = (entry & 0xFFFFF000) + 0x1000;
      entry += cur_pid * 0x4000000;
      a = big_receive(src_dest, cur_pid, &entry);
    }
  else
    return -1;
  return a;
}

variable_types: function long

variable_types: a long

variable_types: entry long


variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; } *

variable_types: res long

variable_types: year int


decompiled_code:
__int64 time_init()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // di
unsigned __int8 v2; // al
unsigned __int8 v3; // bp
unsigned __int8 v4; // al
unsigned __int8 v5; // bl
unsigned __int8 v6; // al
unsigned __int8 v7; // r11
unsigned __int8 v8; // al
unsigned __int8 v9; // r9
unsigned __int8 v10; // al
unsigned __int8 v11; // r10
unsigned __int8 v12; // al
unsigned __int8 v13; // al
__int64 result; // rax
int v15[24]; // [rsp+0h] [rbp-60h] BYREF

do
{
__outbyte(0x70u, 0x80u);
v0 = __inbyte(0x71u);
v1 = v0;
__outbyte(0x70u, 0x82u);
v2 = __inbyte(0x71u);
v3 = v2;
__outbyte(0x70u, 0x84u);
v4 = __inbyte(0x71u);
v5 = v4;
__outbyte(0x70u, 0x87u);
v6 = __inbyte(0x71u);
v7 = v6;
__outbyte(0x70u, 0x88u);
v8 = __inbyte(0x71u);
v9 = v8;
__outbyte(0x70u, 0x89u);
v10 = __inbyte(0x71u);
v11 = v10;
__outbyte(0x70u, 0x80u);
v12 = __inbyte(0x71u);
}
while ( v1 != v12 );
v15[0] = (v1 & 0xF) + 10 * ((int)v12 >> 4);
v15[1] = (v3 & 0xF) + 10 * ((int)v3 >> 4);
v15[2] = (v5 & 0xF) + 10 * ((int)v5 >> 4);
v15[3] = (v7 & 0xF) + 10 * ((int)v7 >> 4);
v15[5] = (v11 & 0xF) + 10 * ((int)v11 >> 4);
v15[4] = (v9 & 0xF) + 10 * ((int)v9 >> 4) - 1;
startup_time = kernel_mktime(v15);
jiffies = 0LL;
__outbyte(0x43u, 0x36u);
__outbyte(0x40u, 0x9Bu);
__outbyte(0x40u, 0x2Eu);
v13 = __inbyte(0x21u);
result = v13 & 0xFE;
__outbyte(0x21u, result);
return result;
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }

return_type: void


decompiled_code:
__int64 __fastcall do_intr_clock(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rdx

++jiffies;
__outbyte(0x20u, 0x20u);
if ( a3 )
{
result = proc_current;
++*(_QWORD *)(proc_current + 144LL);
v4 = *(_QWORD *)(result + 16) - 1LL;
if ( v4 > 0 )
{
*(_QWORD *)(result + 16) = v4;
}
else
{
*(_QWORD *)(result + 16) = 0LL;
result = schedule();
}
}
else
{
v5 = proc_current;
++*(_QWORD *)(proc_current + 152LL);
result = *(_QWORD *)(v5 + 16) - 1LL;
if ( result <= 0 )
result = 0LL;
*(_QWORD *)(v5 + 16) = result;
}
return result;
}

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

++jiffies;
__outbyte(0x20u, 0x20u);
if ( a3 )
{
result = proc_current;
++*(_QWORD *)(proc_current + 144LL);
v4 = *(_QWORD *)(result + 16) - 1LL;
if ( v4 > 0 )
{
*(_QWORD *)(result + 16) = v4;
}
else
{
*(_QWORD *)(result + 16) = 0LL;
result = schedule();
}
}
else
{
v5 = proc_current;
++*(_QWORD *)(proc_current + 152LL);
result = *(_QWORD *)(v5 + 16) - 1LL;
if ( result <= 0 )
result = 0LL;
*(_QWORD *)(v5 + 16) = result;
}
return result;
}

original_code:
void do_intr_clock(long *eip, long error_code, long cpl)
{
  jiffies++;
  __asm__("outb %%al, %%dx"::"a"(0x20), "d"(0x20));
  if (cpl != 0)
    proc_current->utime++;
  else
    proc_current->stime++;
  if((--(proc_current->counter)) > 0)
    return;
  proc_current->counter = 0;
  if(cpl == 0)
    return;
  schedule();
}

variable_types:
eip
long *

variable_types: cpl long


decompiled_code:
__int64 __fastcall get_msg_entry(int a1)
{
return (a1 & 0xFFFFF000) + 4096LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (a1 & 0xFFFFF000) + 4096LL;
}

original_code:
long * get_msg_entry(struct Msg * msgpt)
{
  long entry;
  entry = (long)msgpt;
  entry = (entry & 0xFFFFF000) + 0x1000;
  return (long *)entry;
}

canonical_original_code:
long *get_msg_entry(struct Msg *msgpt)
{
  long entry;
  entry = (long)msgpt;
  entry = (entry & 0xFFFFF000) + 0x1000;
  return (long *)entry;
}

variable_types:
msgpt
struct Msg { char a[-1]; } *

return_type: long *


decompiled_code:
void __noreturn small_msg_send()
{
__asm { int 80h; LINUX - sys_exit }
}

canonical_decompiled_code:
void __noreturn func1()
{
__asm { int 80h; LINUX - sys_exit }
}

original_code:
long small_msg_send(long * destination, long * msgpt)
{
  long res = 1;
  __asm__ volatile
    ( "int $0x80" :"=a"(res) :"0"(res), "b"(*destination), "c"(*msgpt));
  if(res == 1)
    return 1;
  return -1;
}

canonical_original_code:
long small_msg_send(long *destination, long *msgpt)
{
  long res = 1;
  __asm__ volatile
    ( "int $0x80" :"=a"(res) :"0"(res), "b"(*destination), "c"(*msgpt));
  if(res == 1)
    return 1;
  return -1;
}

variable_types:
destination
long *

variable_types:
msgpt
long *


decompiled_code:
__int64 small_msg_receive()
{
__asm { int 80h; LINUX - sys_fork }
return -1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__asm { int 80h; LINUX - sys_fork }
return -1LL;
}

original_code:
long small_msg_receive(long * source, long * msgpt)
{
  long res = 2;
  long msg;
  long src;
  __asm__ volatile
    ( "int $0x80" :"=a"(res), "=b"(src), "=c"(msg) :"0"(res), "b"(*source));
  if(res == 1)
    {
      *msgpt = msg;
      *source = src;
      return 1;
    }
  return -1;
}

canonical_original_code:
long small_msg_receive(long *source, long *msgpt)
{
  long res = 2;
  long msg;
  long src;
  __asm__ volatile
    ( "int $0x80" :"=a"(res), "=b"(src), "=c"(msg) :"0"(res), "b"(*source));
  if(res == 1)
    {
      *msgpt = msg;
      *source = src;
      return 1;
    }
  return -1;
}

variable_types:
source
long *

variable_types: msg long

variable_types: src long


decompiled_code:
__int64 big_msg_send()
{
__asm { int 80h; LINUX - sys_read }
return -1LL;
}

canonical_decompiled_code:
__int64 func3()
{
__asm { int 80h; LINUX - sys_read }
return -1LL;
}

original_code:
long big_msg_send(long * destination, struct Msg * msgpt)
{
  long res = 3;
  __asm__ volatile
    ( "int $0x80" :"=a"(res) :"0"(res), "b"(*destination), "c"((long)msgpt));
  if(res == 1)
    return 1;
  return -1;
}

canonical_original_code:
long big_msg_send(long *destination, struct Msg *msgpt)
{
  long res = 3;
  __asm__ volatile
    ( "int $0x80" :"=a"(res) :"0"(res), "b"(*destination), "c"((long)msgpt));
  if(res == 1)
    return 1;
  return -1;
}


decompiled_code:
__int64 big_msg_receive()
{
__asm { int 80h; LINUX - sys_write }
return -1LL;
}

canonical_decompiled_code:
__int64 func4()
{
__asm { int 80h; LINUX - sys_write }
return -1LL;
}

original_code:
long big_msg_receive(long * source, struct Msg * msgpt)
{
  long res = 4;
  long src;
  __asm__ volatile
    ( "int $0x80" :"=a"(res), "=b"(src) :"0"(res), "b"(*source), "c"((long)msgpt));
  if(res == 1)
    {
      *source = src;
      return 1;
    }
  return -1;
}

canonical_original_code:
long big_msg_receive(long *source, struct Msg *msgpt)
{
  long res = 4;
  long src;
  __asm__ volatile
    ( "int $0x80" :"=a"(res), "=b"(src) :"0"(res), "b"(*source), "c"((long)msgpt));
  if(res == 1)
    {
      *source = src;
      return 1;
    }
  return -1;
}


decompiled_code:
void __noreturn system_task()
{
__int64 i; // [rsp+8h] [rbp-2010h] BYREF
char v1[8200]; // [rsp+10h] [rbp-2008h] BYREF

for ( i = -1LL; ; i = -1LL )
big_msg_receive(&i, v1);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 i; // [rsp+8h] [rbp-2010h] BYREF
char v1[8200]; // [rsp+10h] [rbp-2008h] BYREF

for ( i = -1LL; ; i = -1LL )
big_msg_receive(&i, v1);
}

original_code:
void system_task(void)
{
  struct Msg msg;
  long src = -1;
  while(1)
    {
      big_msg_receive(&src, &msg);
      src = -1;
    }
}

canonical_original_code:
void system_task()
{
  struct Msg msg;
  long src = -1;
  while(1)
    {
      big_msg_receive(&src, &msg);
      src = -1;
    }
}

variable_types:
msg
struct Msg { char a[-1]; }


decompiled_code:
// attributes: thunk
void __noreturn init_proc()
{
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func0()
{
while ( 1 )
;
}

original_code:
void init_proc(void)
{
  for(;;)
    ;
}

canonical_original_code:
void init_proc()
{
  for(;;)
    ;
}


repo: CeRiAl/Xhomer

decompiled_code:
__int64 pro_rd_intb()
{
pro_rd_status |= 0x80u;
pro_rd_s2c |= 0x800u;
return pro_int_set(513LL);
}

canonical_decompiled_code:
__int64 func0()
{
pro_rd_status |= 0x80u;
pro_rd_s2c |= 0x800u;
return pro_int_set(513LL);
}

original_code:
static void pro_rd_intb ()
{
 pro_rd_status = pro_rd_status | 0000200;
 pro_rd_s2c = pro_rd_s2c | 0004000;
 pro_int_set(0x0201);
}

canonical_original_code:
static void pro_rd_intb()
{
 pro_rd_status = pro_rd_status | 0000200;
 pro_rd_s2c = pro_rd_s2c | 0004000;
 pro_int_set(0x0201);
}


decompiled_code:
__int64 pro_rd_inta()
{
pro_rd_status |= 1u;
return pro_int_set(257LL);
}

canonical_decompiled_code:
__int64 func1()
{
pro_rd_status |= 1u;
return pro_int_set(257LL);
}

original_code:
static void pro_rd_inta ()
{
 pro_rd_status = pro_rd_status | 0000001;
 pro_int_set(0x0101);
}

canonical_original_code:
static void pro_rd_inta()
{
 pro_rd_status = pro_rd_status | 0000001;
 pro_int_set(0x0101);
}


decompiled_code:
__int64 pro_rd_error()
{
pro_rd_status &= 0xFFFF7FFF;
pro_rd_s2c |= 0x100u;
pro_rd_ep |= 0x1000u;
return pro_rd_inta();
}

canonical_decompiled_code:
__int64 func2()
{
pro_rd_status &= 0xFFFF7FFF;
pro_rd_s2c |= 0x100u;
pro_rd_ep |= 0x1000u;
return func1();
}

original_code:
static void pro_rd_error ()
{
 pro_rd_status = pro_rd_status & (~0100000);
 pro_rd_s2c = pro_rd_s2c | 0000400;
 pro_rd_ep = pro_rd_ep | 0010000;
 pro_rd_inta();
}

canonical_original_code:
static void pro_rd_error()
{
 pro_rd_status = pro_rd_status & (~0100000);
 pro_rd_s2c = pro_rd_s2c | 0000400;
 pro_rd_ep = pro_rd_ep | 0010000;
 pro_rd_inta();
}


decompiled_code:
__int64 pro_rd_sched()
{
return pro_eq_sched(11LL, 5LL);
}

canonical_decompiled_code:
__int64 func3()
{
return pro_eq_sched(11LL, 5LL);
}

original_code:
static void pro_rd_sched ()
{
 pro_eq_sched(11, 5);
}

canonical_original_code:
static void pro_rd_sched()
{
 pro_eq_sched(11, 5);
}


decompiled_code:
__int64 pro_rd_eq()
{
return pro_rd_intb();
}

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

original_code:
void pro_rd_eq ()
{
 pro_rd_intb();
}

canonical_original_code:
void pro_rd_eq()
{
 pro_rd_intb();
}


decompiled_code:
__int64 __fastcall pro_rd_rd(int a1)
{
unsigned int v1; // ebx
int v3; // edx

switch ( a1 & 0x3FFFFE )
{
case 0x3FF800:
v1 = 257;
break;
case 0x3FF804:
v1 = pro_rd_ep;
break;
case 0x3FF806:
v1 = pro_rd_sec;
break;
case 0x3FF808:
v1 = (unsigned __int8)PRO_RD_SECBUF[pro_rd_secbuf_ptr]
+ ((unsigned __int8)PRO_RD_SECBUF[pro_rd_secbuf_ptr + 1] << 8);
v3 = pro_rd_status;
if ( (pro_rd_status & 0x80u) != 0 )
{
if ( pro_rd_secbuf_ptr > 509 )
{
LOBYTE(v3) = pro_rd_status & 0x7F;
pro_rd_status = v3;
pro_rd_s2c &= 0xFFFFF7FF;
pro_rd_inta();
}
else
{
pro_rd_secbuf_ptr += 2;
pro_rd_intb();
}
}
break;
case 0x3FF80A:
v1 = pro_rd_cyl;
break;
case 0x3FF80C:
v1 = pro_rd_head;
break;
case 0x3FF80E:
v1 = pro_rd_s2c;
pro_rd_status &= 0xFFFFFFFE;
break;
case 0x3FF810:
v1 = pro_rd_status;
break;
default:
v1 = 0;
break;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
unsigned int v1; // ebx
int v3; // edx

switch ( a1 & 0x3FFFFE )
{
case 0x3FF800:
v1 = 257;
break;
case 0x3FF804:
v1 = pro_rd_ep;
break;
case 0x3FF806:
v1 = pro_rd_sec;
break;
case 0x3FF808:
v1 = (unsigned __int8)PRO_RD_SECBUF[pro_rd_secbuf_ptr]
+ ((unsigned __int8)PRO_RD_SECBUF[pro_rd_secbuf_ptr + 1] << 8);
v3 = pro_rd_status;
if ( (pro_rd_status & 0x80u) != 0 )
{
if ( pro_rd_secbuf_ptr > 509 )
{
LOBYTE(v3) = pro_rd_status & 0x7F;
pro_rd_status = v3;
pro_rd_s2c &= 0xFFFFF7FF;
func1();
}
else
{
pro_rd_secbuf_ptr += 2;
func0();
}
}
break;
case 0x3FF80A:
v1 = pro_rd_cyl;
break;
case 0x3FF80C:
v1 = pro_rd_head;
break;
case 0x3FF80E:
v1 = pro_rd_s2c;
pro_rd_status &= 0xFFFFFFFE;
break;
case 0x3FF810:
v1 = pro_rd_status;
break;
default:
v1 = 0;
break;
}
return v1;
}

original_code:
int pro_rd_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774000:
     data = 0000401;
     break;
   case 017774004:
     data = pro_rd_ep;
     break;
   case 017774006:
     data = pro_rd_sec;
     break;
   case 017774010:
     data = PRO_RD_SECBUF[pro_rd_secbuf_ptr+1] * 256
            + PRO_RD_SECBUF[pro_rd_secbuf_ptr];
     if ((pro_rd_status & 0000200) != 0)
     {
       if (pro_rd_secbuf_ptr < 510)
       {
         pro_rd_secbuf_ptr += 2;
         pro_rd_intb();
       }
       else
       {
         pro_rd_status = pro_rd_status & (~0000200);
         pro_rd_s2c = pro_rd_s2c & (~0004000);
         pro_rd_inta();
       }
     }
     break;
   case 017774012:
     data = pro_rd_cyl;
     break;
   case 017774014:
     data = pro_rd_head;
     break;
   case 017774016:
     data = pro_rd_s2c;
     pro_rd_status = pro_rd_status & (~0000001);
     break;
   case 017774020:
     data = pro_rd_status;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_rd_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774000:
     data = 0000401;
     break;
   case 017774004:
     data = pro_rd_ep;
     break;
   case 017774006:
     data = pro_rd_sec;
     break;
   case 017774010:
     data = PRO_RD_SECBUF[pro_rd_secbuf_ptr+1] * 256
            + PRO_RD_SECBUF[pro_rd_secbuf_ptr];
     if ((pro_rd_status & 0000200) != 0)
     {
       if (pro_rd_secbuf_ptr < 510)
       {
         pro_rd_secbuf_ptr += 2;
         pro_rd_intb();
       }
       else
       {
         pro_rd_status = pro_rd_status & (~0000200);
         pro_rd_s2c = pro_rd_s2c & (~0004000);
         pro_rd_inta();
       }
     }
     break;
   case 017774012:
     data = pro_rd_cyl;
     break;
   case 017774014:
     data = pro_rd_head;
     break;
   case 017774016:
     data = pro_rd_s2c;
     pro_rd_status = pro_rd_status & (~0000001);
     break;
   case 017774020:
     data = pro_rd_status;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

variable_types: pa int

variable_types: data int

return_type: int


decompiled_code:
void __fastcall pro_rd_wr(FILE *a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rsi
int v7; // eax
int v8; // eax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // rdx
int v12; // ebx
char *v13; // rbx
int v14; // eax
__int64 v15; // rdi
int v16; // eax
FILE **v17; // rbx

v6 = (a2 & 0x3FFFFEu) - 4192260;
switch ( (int)v6 )
{
case 0:
v7 = pro_rd_ep;
LOBYTE(v7) = 0;
pro_rd_ep = v7 | (unsigned __int8)a1;
return;
case 2:
pro_rd_sec = pro_rd_sec & 0xFFFF00E0 | (unsigned __int16)a1 & 0xFF1F;
return;
case 4:
if ( (pro_rd_status & 0x80u) == 0 )
return;
v8 = pro_rd_secbuf_ptr;
PRO_RD_SECBUF[pro_rd_secbuf_ptr] = (char)a1;
v9 = v8 + 1;
PRO_RD_SECBUF[v9] = BYTE1(a1);
if ( v8 > 509 )
{
v10 = (unsigned int)pro_rd_head;
v11 = (unsigned __int8)pro_rd_s2c;
if ( (unsigned __int8)pro_rd_s2c == 48 )
{
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9,
0);
v13 = PRO_RD_SECBUF;
do
{
putc((unsigned __int8)*v13, pro_rd_fptr);
v6 = (__int64)pro_rd_fptr;
putc((unsigned __int8)v13[1], pro_rd_fptr);
v13 += 2;
}
while ( &pro_rd_fptr != (FILE **)v13 );
}
else
{
if ( (unsigned __int8)pro_rd_s2c != 80 )
{
LABEL_13:
pro_rd_status &= 0xFFFFFF7F;
pro_rd_s2c &= 0xFFFFF7FF;
pro_rd_inta(a1, v6, v11, v10, a5, a6);
return;
}
v6 = (pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9;
fseek(pro_rd_fptr, v6, 0);
if ( pro_rd_secs > 0 )
{
v12 = 0;
do
{
v6 = (__int64)pro_rd_fptr;
putc((unsigned __int8)PRO_RD_SECBUF[511], pro_rd_fptr);
++v12;
}
while ( pro_rd_secs << 9 > v12 );
}
}
a1 = pro_rd_fptr;
fflush(pro_rd_fptr);
goto LABEL_13;
}
pro_rd_secbuf_ptr = v8 + 2;
pro_rd_intb(a1, v6, v9, BYTE1(a1), a5, a6);
return;
case 6:
pro_rd_cyl = pro_rd_cyl & 0xFFFFFC00 | (unsigned __int16)a1 & 0x3FF;
return;
case 8:
pro_rd_head = pro_rd_head & 0xFFFFFFF8 | (unsigned __int8)a1 & 7;
return;
case 10:
v14 = pro_rd_s2c;
LOBYTE(v14) = 0;
v15 = v14 | (unsigned int)(unsigned __int8)a1;
pro_rd_ep &= 0xFFFF00FF;
v16 = v15;
BYTE1(v16) = BYTE1(v15) & 0xF6;
pro_rd_s2c = v16;
pro_rd_status &= 0xFFFFFF7E;
if ( (_BYTE)v15 == 48 )
{
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl || pro_rd_secs <= (unsigned __int8)pro_rd_sec )
goto LABEL_31;
pro_rd_secbuf_ptr = 0;
((void (*)(void))pro_rd_intb)();
return;
}
if ( (unsigned __int8)v15 > 0x30u )
{
if ( (unsigned __int8)v15 == 80 )
{
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl )
goto LABEL_31;
pro_rd_secbuf_ptr = 0;
pro_rd_intb(
v15,
(unsigned int)pro_rd_cyl,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_head,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
LABEL_42:
puts("RD illegal command\r");
return;
}
if ( (unsigned __int8)v15 == 16 )
{
pro_rd_inta(
v15,
(unsigned int)pro_rd_cyl,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_head,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
if ( (unsigned __int8)v15 != 32 )
goto LABEL_42;
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl || pro_rd_secs <= (unsigned __int8)pro_rd_sec )
{
LABEL_31:
pro_rd_error(
v15,
(unsigned int)pro_rd_cyl,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_head,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_head + pro_rd_cyl * pro_rd_heads)) << 9,
0);
v17 = (FILE **)PRO_RD_SECBUF;
do
{
*(_BYTE *)v17 = getc(pro_rd_fptr);
v17 = (FILE **)((char *)v17 + 1);
}
while ( v17 != &pro_rd_fptr );
pro_rd_secbuf_ptr = 0;
pro_rd_sched();
return;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func6(FILE *a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rsi
int v7; // eax
int v8; // eax
__int64 v9; // rdx
__int64 v10; // rcx
__int64 v11; // rdx
int v12; // ebx
char *v13; // rbx
int v14; // eax
__int64 v15; // rdi
int v16; // eax
FILE **v17; // rbx

v6 = (a2 & 0x3FFFFEu) - 4192260;
switch ( (int)v6 )
{
case 0:
v7 = pro_rd_ep;
LOBYTE(v7) = 0;
pro_rd_ep = v7 | (unsigned __int8)a1;
return;
case 2:
pro_rd_sec = pro_rd_sec & 0xFFFF00E0 | (unsigned __int16)a1 & 0xFF1F;
return;
case 4:
if ( (pro_rd_status & 0x80u) == 0 )
return;
v8 = pro_rd_secbuf_ptr;
PRO_RD_SECBUF[pro_rd_secbuf_ptr] = (char)a1;
v9 = v8 + 1;
PRO_RD_SECBUF[v9] = BYTE1(a1);
if ( v8 > 509 )
{
v10 = (unsigned int)pro_rd_head;
v11 = (unsigned __int8)pro_rd_s2c;
if ( (unsigned __int8)pro_rd_s2c == 48 )
{
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9,
0);
v13 = PRO_RD_SECBUF;
do
{
putc((unsigned __int8)*v13, pro_rd_fptr);
v6 = (__int64)pro_rd_fptr;
putc((unsigned __int8)v13[1], pro_rd_fptr);
v13 += 2;
}
while ( &pro_rd_fptr != (FILE **)v13 );
}
else
{
if ( (unsigned __int8)pro_rd_s2c != 80 )
{
LABEL_13:
pro_rd_status &= 0xFFFFFF7F;
pro_rd_s2c &= 0xFFFFF7FF;
func1(a1, v6, v11, v10, a5, a6);
return;
}
v6 = (pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9;
fseek(pro_rd_fptr, v6, 0);
if ( pro_rd_secs > 0 )
{
v12 = 0;
do
{
v6 = (__int64)pro_rd_fptr;
putc((unsigned __int8)PRO_RD_SECBUF[511], pro_rd_fptr);
++v12;
}
while ( pro_rd_secs << 9 > v12 );
}
}
a1 = pro_rd_fptr;
fflush(pro_rd_fptr);
goto LABEL_13;
}
pro_rd_secbuf_ptr = v8 + 2;
func0(a1, v6, v9, BYTE1(a1), a5, a6);
return;
case 6:
pro_rd_cyl = pro_rd_cyl & 0xFFFFFC00 | (unsigned __int16)a1 & 0x3FF;
return;
case 8:
pro_rd_head = pro_rd_head & 0xFFFFFFF8 | (unsigned __int8)a1 & 7;
return;
case 10:
v14 = pro_rd_s2c;
LOBYTE(v14) = 0;
v15 = v14 | (unsigned int)(unsigned __int8)a1;
pro_rd_ep &= 0xFFFF00FF;
v16 = v15;
BYTE1(v16) = BYTE1(v15) & 0xF6;
pro_rd_s2c = v16;
pro_rd_status &= 0xFFFFFF7E;
if ( (_BYTE)v15 == 48 )
{
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl || pro_rd_secs <= (unsigned __int8)pro_rd_sec )
goto LABEL_31;
pro_rd_secbuf_ptr = 0;
((void (*)(void))pro_rd_intb)();
return;
}
if ( (unsigned __int8)v15 > 0x30u )
{
if ( (unsigned __int8)v15 == 80 )
{
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl )
goto LABEL_31;
pro_rd_secbuf_ptr = 0;
func0(
v15,
(unsigned int)pro_rd_cyl,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_head,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
LABEL_42:
puts("RD illegal command\r");
return;
}
if ( (unsigned __int8)v15 == 16 )
{
func1(
v15,
(unsigned int)pro_rd_cyl,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_head,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
if ( (unsigned __int8)v15 != 32 )
goto LABEL_42;
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl || pro_rd_secs <= (unsigned __int8)pro_rd_sec )
{
LABEL_31:
func2(
v15,
(unsigned int)pro_rd_cyl,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_head,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_head + pro_rd_cyl * pro_rd_heads)) << 9,
0);
v17 = (FILE **)PRO_RD_SECBUF;
do
{
*(_BYTE *)v17 = getc(pro_rd_fptr);
v17 = (FILE **)((char *)v17 + 1);
}
while ( v17 != &pro_rd_fptr );
pro_rd_secbuf_ptr = 0;
func3();
return;
default:
return;
}
}

original_code:
void pro_rd_wr (int data, int pa, int access)
{
int i, head, cyl, sec, offset;
 switch (pa & 017777776)
 {
   case 017774004:
     pro_rd_ep = ((pro_rd_ep) & ~(0000377)) | (data & (0000377));
     break;
   case 017774006:
     pro_rd_sec = ((pro_rd_sec) & ~(0177437)) | (data & (0177437));
     break;
   case 017774010:
     if ((pro_rd_status & 0000200) != 0)
     {
       PRO_RD_SECBUF[pro_rd_secbuf_ptr] = data & 0377;
       PRO_RD_SECBUF[pro_rd_secbuf_ptr+1] = (data & 0177400) >> 8;
       if (pro_rd_secbuf_ptr < 510)
       {
         pro_rd_secbuf_ptr += 2;
         pro_rd_intb();
       }
       else
       {
         head = pro_rd_head;
         cyl = pro_rd_cyl;
         sec = pro_rd_sec & 0000377;
         switch (pro_rd_s2c & 0377)
         {
           case 0120:
             offset = (cyl * pro_rd_heads * pro_rd_secs + head * pro_rd_secs) * 512;
             fseek(pro_rd_fptr, offset, 0);
             for(i=0; i<(512*pro_rd_secs); i++)
               putc(PRO_RD_SECBUF[511], pro_rd_fptr);
             fflush(pro_rd_fptr);
             break;
           case 0060:
             offset = (cyl * pro_rd_heads * pro_rd_secs + head * pro_rd_secs + sec) * 512;
             fseek(pro_rd_fptr, offset, 0);
             for(i=0; i<512; i+=2)
             {
               putc(PRO_RD_SECBUF[i], pro_rd_fptr);
               putc(PRO_RD_SECBUF[i+1], pro_rd_fptr);
             }
             fflush(pro_rd_fptr);
             break;
           default:
             break;
         }
         pro_rd_status = pro_rd_status & (~0000200);
         pro_rd_s2c = pro_rd_s2c & (~0004000);
         pro_rd_inta();
       }
     }
     break;
   case 017774012:
     pro_rd_cyl = ((pro_rd_cyl) & ~(0001777)) | (data & (0001777));
     break;
   case 017774014:
     pro_rd_head = ((pro_rd_head) & ~(0000007)) | (data & (0000007));
     break;
   case 017774016:
     pro_rd_s2c = ((pro_rd_s2c) & ~(0000377)) | (data & (0000377));
     head = pro_rd_head;
     cyl = pro_rd_cyl;
     sec = pro_rd_sec & 0000377;
     offset = (cyl * pro_rd_heads * pro_rd_secs + head * pro_rd_secs + sec) * 512;
     pro_rd_s2c = pro_rd_s2c & (~0000400);
     pro_rd_ep = pro_rd_ep & (~0177400);
     pro_rd_s2c = pro_rd_s2c & (~0004000);
     pro_rd_status = pro_rd_status & (~0000200);
     pro_rd_status = pro_rd_status & (~0000001);
     switch (pro_rd_s2c & 0377)
     {
       case 0020:
         pro_rd_inta();
         break;
       case 0040:
         if ((head >= pro_rd_heads) || (cyl >= pro_rd_cyls) || (sec >= pro_rd_secs))
           pro_rd_error();
         else
         {
           fseek(pro_rd_fptr, offset, 0);
           for(i=0; i<512; i++)
             PRO_RD_SECBUF[i] = getc(pro_rd_fptr);
           pro_rd_secbuf_ptr = 0;
           pro_rd_sched();
         }
         break;
       case 0060:
         if ((head >= pro_rd_heads) || (cyl >= pro_rd_cyls) || (sec >= pro_rd_secs))
           pro_rd_error();
         else
         {
           pro_rd_secbuf_ptr = 0;
           pro_rd_intb();
         }
         break;
       case 0120:
         if ((head >= pro_rd_heads) || (cyl >= pro_rd_cyls))
           pro_rd_error();
         else
         {
           pro_rd_secbuf_ptr = 0;
           pro_rd_intb();
         }
         break;
       default:
         printf("RD illegal command\r\n");
         break;
     }
     break;
   case 017774020:
     break;
   default:
     break;
 }
}

canonical_original_code:
void pro_rd_wr(int data, int pa, int access)
{
int i; int head; int cyl; int sec; int offset;
 switch (pa & 017777776)
 {
   case 017774004:
     pro_rd_ep = ((pro_rd_ep) & ~(0000377)) | (data & (0000377));
     break;
   case 017774006:
     pro_rd_sec = ((pro_rd_sec) & ~(0177437)) | (data & (0177437));
     break;
   case 017774010:
     if ((pro_rd_status & 0000200) != 0)
     {
       PRO_RD_SECBUF[pro_rd_secbuf_ptr] = data & 0377;
       PRO_RD_SECBUF[pro_rd_secbuf_ptr+1] = (data & 0177400) >> 8;
       if (pro_rd_secbuf_ptr < 510)
       {
         pro_rd_secbuf_ptr += 2;
         pro_rd_intb();
       }
       else
       {
         head = pro_rd_head;
         cyl = pro_rd_cyl;
         sec = pro_rd_sec & 0000377;
         switch (pro_rd_s2c & 0377)
         {
           case 0120:
             offset = (cyl * pro_rd_heads * pro_rd_secs + head * pro_rd_secs) * 512;
             fseek(pro_rd_fptr, offset, 0);
             for(i=0; i<(512*pro_rd_secs); i++)
               putc(PRO_RD_SECBUF[511], pro_rd_fptr);
             fflush(pro_rd_fptr);
             break;
           case 0060:
             offset = (cyl * pro_rd_heads * pro_rd_secs + head * pro_rd_secs + sec) * 512;
             fseek(pro_rd_fptr, offset, 0);
             for(i=0; i<512; i+=2)
             {
               putc(PRO_RD_SECBUF[i], pro_rd_fptr);
               putc(PRO_RD_SECBUF[i+1], pro_rd_fptr);
             }
             fflush(pro_rd_fptr);
             break;
           default:
             break;
         }
         pro_rd_status = pro_rd_status & (~0000200);
         pro_rd_s2c = pro_rd_s2c & (~0004000);
         pro_rd_inta();
       }
     }
     break;
   case 017774012:
     pro_rd_cyl = ((pro_rd_cyl) & ~(0001777)) | (data & (0001777));
     break;
   case 017774014:
     pro_rd_head = ((pro_rd_head) & ~(0000007)) | (data & (0000007));
     break;
   case 017774016:
     pro_rd_s2c = ((pro_rd_s2c) & ~(0000377)) | (data & (0000377));
     head = pro_rd_head;
     cyl = pro_rd_cyl;
     sec = pro_rd_sec & 0000377;
     offset = (cyl * pro_rd_heads * pro_rd_secs + head * pro_rd_secs + sec) * 512;
     pro_rd_s2c = pro_rd_s2c & (~0000400);
     pro_rd_ep = pro_rd_ep & (~0177400);
     pro_rd_s2c = pro_rd_s2c & (~0004000);
     pro_rd_status = pro_rd_status & (~0000200);
     pro_rd_status = pro_rd_status & (~0000001);
     switch (pro_rd_s2c & 0377)
     {
       case 0020:
         pro_rd_inta();
         break;
       case 0040:
         if ((head >= pro_rd_heads) || (cyl >= pro_rd_cyls) || (sec >= pro_rd_secs))
           pro_rd_error();
         else
         {
           fseek(pro_rd_fptr, offset, 0);
           for(i=0; i<512; i++)
             PRO_RD_SECBUF[i] = getc(pro_rd_fptr);
           pro_rd_secbuf_ptr = 0;
           pro_rd_sched();
         }
         break;
       case 0060:
         if ((head >= pro_rd_heads) || (cyl >= pro_rd_cyls) || (sec >= pro_rd_secs))
           pro_rd_error();
         else
         {
           pro_rd_secbuf_ptr = 0;
           pro_rd_intb();
         }
         break;
       case 0120:
         if ((head >= pro_rd_heads) || (cyl >= pro_rd_cyls))
           pro_rd_error();
         else
         {
           pro_rd_secbuf_ptr = 0;
           pro_rd_intb();
         }
         break;
       default:
         printf("RD illegal command\r\n");
         break;
     }
     break;
   case 017774020:
     break;
   default:
     break;
 }
}

variable_types: access int

variable_types: i int

variable_types: head int

variable_types: cyl int

variable_types: sec int

variable_types: offset int


decompiled_code:
void pro_rd_reset()
{
const char *v0; // r12
size_t v1; // rbx
const char *v2; // rbp
size_t v3; // rax
char *v4; // rbx
const char *v5; // rax
int v6; // esi
int v7; // ecx
struct stat v8; // [rsp+0h] [rbp-A8h] BYREF

v0 = pro_rd_dir;
v1 = strlen(pro_rd_dir);
v2 = pro_rd_file;
v3 = strlen(pro_rd_file);
v4 = (char *)malloc(v1 + v3 + 1);
strcpy(v4, v0);
strcat(v4, v2);
memset(PRO_RD_SECBUF, 0, sizeof(PRO_RD_SECBUF));
if ( pro_rd_fptr )
fclose(pro_rd_fptr);
pro_rd_fptr = fopen(v4, "r+");
if ( !pro_rd_fptr )
{
printf("Unable to open rd image %s\n", v4);
LABEL_8:
pro_rd_heads = 0;
pro_rd_cyls = 0;
pro_rd_secs = 0;
goto LABEL_9;
}
stat(v4, &v8);
if ( pro_rd_secs | pro_rd_cyls | pro_rd_heads )
{
if ( (pro_rd_secs * pro_rd_cyls * pro_rd_heads) << 9 != LODWORD(v8.st_size) )
{
printf(
"Geometry %d %d %d does not match rd filesize %d\n",
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_cyls,
(unsigned int)pro_rd_secs,
v8.st_size);
LABEL_7:
fclose(pro_rd_fptr);
goto LABEL_8;
}
}
else
{
v5 = (const char *)&pro_rd_geom;
while ( 1 )
{
v6 = *((_DWORD *)v5 + 1);
v7 = *((_DWORD *)v5 + 2);
if ( (v7 * v6 * *(_DWORD *)v5) << 9 == LODWORD(v8.st_size) )
break;
v5 += 12;
if ( v5 == "RD illegal command\r" )
{
printf("Unable to determine rd geometry for filesize %d bytes\n", LODWORD(v8.st_size));
goto LABEL_7;
}
}
pro_rd_heads = *(_DWORD *)v5;
pro_rd_cyls = v6;
pro_rd_secs = v7;
}
LABEL_9:
pro_rd_secbuf_ptr = 0;
pro_rd_ep = 0;
pro_rd_sec = 0;
pro_rd_cyl = 0;
pro_rd_head = 0;
pro_rd_s2c = 20480;
pro_rd_status = 1;
free(v4);
}

canonical_decompiled_code:
void func7()
{
const char *v0; // r12
size_t v1; // rbx
const char *v2; // rbp
size_t v3; // rax
char *v4; // rbx
const char *v5; // rax
int v6; // esi
int v7; // ecx
struct stat v8; // [rsp+0h] [rbp-A8h] BYREF

v0 = pro_rd_dir;
v1 = strlen(pro_rd_dir);
v2 = pro_rd_file;
v3 = strlen(pro_rd_file);
v4 = (char *)malloc(v1 + v3 + 1);
strcpy(v4, v0);
strcat(v4, v2);
memset(PRO_RD_SECBUF, 0, sizeof(PRO_RD_SECBUF));
if ( pro_rd_fptr )
fclose(pro_rd_fptr);
pro_rd_fptr = fopen(v4, "r+");
if ( !pro_rd_fptr )
{
printf("Unable to open rd image %s\n", v4);
LABEL_8:
pro_rd_heads = 0;
pro_rd_cyls = 0;
pro_rd_secs = 0;
goto LABEL_9;
}
stat(v4, &v8);
if ( pro_rd_secs | pro_rd_cyls | pro_rd_heads )
{
if ( (pro_rd_secs * pro_rd_cyls * pro_rd_heads) << 9 != LODWORD(v8.st_size) )
{
printf(
"Geometry %d %d %d does not match rd filesize %d\n",
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_cyls,
(unsigned int)pro_rd_secs,
v8.st_size);
LABEL_7:
fclose(pro_rd_fptr);
goto LABEL_8;
}
}
else
{
v5 = (const char *)&pro_rd_geom;
while ( 1 )
{
v6 = *((_DWORD *)v5 + 1);
v7 = *((_DWORD *)v5 + 2);
if ( (v7 * v6 * *(_DWORD *)v5) << 9 == LODWORD(v8.st_size) )
break;
v5 += 12;
if ( v5 == "RD illegal command\r" )
{
printf("Unable to determine rd geometry for filesize %d bytes\n", LODWORD(v8.st_size));
goto LABEL_7;
}
}
pro_rd_heads = *(_DWORD *)v5;
pro_rd_cyls = v6;
pro_rd_secs = v7;
}
LABEL_9:
pro_rd_secbuf_ptr = 0;
pro_rd_ep = 0;
pro_rd_sec = 0;
pro_rd_cyl = 0;
pro_rd_head = 0;
pro_rd_s2c = 20480;
pro_rd_status = 1;
free(v4);
}

original_code:
void pro_rd_reset ()
{
struct stat statbuf;
int i, fsize, gfound;
char *fname;
 fname = malloc(strlen(pro_rd_dir) + strlen(pro_rd_file) + 1);
 strcpy(fname, pro_rd_dir);
 strcat(fname, pro_rd_file);
        memset(&PRO_RD_SECBUF, 0, sizeof(PRO_RD_SECBUF));
        if (pro_rd_fptr) fclose(pro_rd_fptr);
 pro_rd_fptr = fopen(fname, "r+");
 gfound = 0;
 if (pro_rd_fptr == ((void *)0))
   printf("Unable to open rd image %s\n", fname);
 else
 {
   stat(fname, &statbuf);
   fsize = (int)statbuf.st_size;
   if ((pro_rd_heads != 0) || (pro_rd_cyls != 0) || (pro_rd_secs != 0))
   {
     if (pro_rd_heads*pro_rd_cyls*pro_rd_secs*512 == fsize)
       gfound = 1;
     else
       printf("Geometry %d %d %d does not match rd filesize %d\n",
               pro_rd_heads, pro_rd_cyls, pro_rd_secs, fsize);
   }
   else
   {
     for(i=0; i<12; i++)
       if (pro_rd_geom[i][0]*pro_rd_geom[i][1]
           *pro_rd_geom[i][2]*512 == fsize)
       {
         pro_rd_heads = pro_rd_geom[i][0];
         pro_rd_cyls = pro_rd_geom[i][1];
         pro_rd_secs = pro_rd_geom[i][2];
         gfound = 1;
         break;
       }
     if (gfound == 0)
       printf("Unable to determine rd geometry for filesize %d bytes\n", fsize);
   }
   if (gfound == 0)
     fclose(pro_rd_fptr);
 }
 if (gfound == 0)
 {
   pro_rd_heads = 0;
   pro_rd_cyls = 0;
   pro_rd_secs = 0;
 }
 pro_rd_secbuf_ptr = 0;
 pro_rd_ep = 0;
 pro_rd_sec = 0;
 pro_rd_cyl = 0;
 pro_rd_head = 0;
 pro_rd_s2c = 0040000 | 0010000;
 pro_rd_status = 0000001;
 free(fname);
}

canonical_original_code:
void pro_rd_reset()
{
struct stat statbuf;
int i; int fsize; int gfound;
char *fname;
 fname = malloc(strlen(pro_rd_dir) + strlen(pro_rd_file) + 1);
 strcpy(fname, pro_rd_dir);
 strcat(fname, pro_rd_file);
        memset(&PRO_RD_SECBUF, 0, sizeof(PRO_RD_SECBUF));
        if (pro_rd_fptr) fclose(pro_rd_fptr);
 pro_rd_fptr = fopen(fname, "r+");
 gfound = 0;
 if (pro_rd_fptr == ((void *)0))
   printf("Unable to open rd image %s\n", fname);
 else
 {
   stat(fname, &statbuf);
   fsize = (int)statbuf.st_size;
   if ((pro_rd_heads != 0) || (pro_rd_cyls != 0) || (pro_rd_secs != 0))
   {
     if (pro_rd_heads*pro_rd_cyls*pro_rd_secs*512 == fsize)
       gfound = 1;
     else
       printf("Geometry %d %d %d does not match rd filesize %d\n",
               pro_rd_heads, pro_rd_cyls, pro_rd_secs, fsize);
   }
   else
   {
     for(i=0; i<12; i++)
       if (pro_rd_geom[i][0]*pro_rd_geom[i][1]
           *pro_rd_geom[i][2]*512 == fsize)
       {
         pro_rd_heads = pro_rd_geom[i][0];
         pro_rd_cyls = pro_rd_geom[i][1];
         pro_rd_secs = pro_rd_geom[i][2];
         gfound = 1;
         break;
       }
     if (gfound == 0)
       printf("Unable to determine rd geometry for filesize %d bytes\n", fsize);
   }
   if (gfound == 0)
     fclose(pro_rd_fptr);
 }
 if (gfound == 0)
 {
   pro_rd_heads = 0;
   pro_rd_cyls = 0;
   pro_rd_secs = 0;
 }
 pro_rd_secbuf_ptr = 0;
 pro_rd_ep = 0;
 pro_rd_sec = 0;
 pro_rd_cyl = 0;
 pro_rd_head = 0;
 pro_rd_s2c = 0040000 | 0010000;
 pro_rd_status = 0000001;
 free(fname);
}

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: fsize int

variable_types: gfound int

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:
int pro_rd_exit()
{
int result; // eax

if ( pro_rd_fptr )
{
result = fclose(pro_rd_fptr);
pro_rd_fptr = 0LL;
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax

if ( pro_rd_fptr )
{
result = fclose(pro_rd_fptr);
pro_rd_fptr = 0LL;
}
return result;
}

original_code:
void pro_rd_exit ()
{
        if (pro_rd_fptr!=((void *)0))
        {
          fclose(pro_rd_fptr);
          pro_rd_fptr = ((void *)0);
 }
}

canonical_original_code:
void pro_rd_exit()
{
        if (pro_rd_fptr!=((void *)0))
        {
          fclose(pro_rd_fptr);
          pro_rd_fptr = ((void *)0);
 }
}


decompiled_code:
__int64 __fastcall pro_int_check(char a1, char a2)
{
unsigned __int8 v2; // di
__int64 result; // rax
int v4; // edx

v2 = a1 & ~a2;
result = 255LL;
if ( v2 )
{
v4 = (int)v2 >> 1;
result = 1LL;
if ( (v2 & 1) != 0 )
{
result = 0LL;
}
else
{
do
{
if ( (v4 & 1) != 0 )
break;
v4 >>= 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 8 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, char a2)
{
unsigned __int8 v2; // di
__int64 result; // rax
int v4; // edx

v2 = a1 & ~a2;
result = 255LL;
if ( v2 )
{
v4 = (int)v2 >> 1;
result = 1LL;
if ( (v2 & 1) != 0 )
{
result = 0LL;
}
else
{
do
{
if ( (v4 & 1) != 0 )
break;
v4 >>= 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 8 );
}
}
return result;
}

original_code:
static int pro_int_check(int irr, int imr)
{
int i, intreqs;
 intreqs = irr & ((~imr) & 0377);
 if (intreqs == 0)
   i = 255;
 else
 {
   for(i=0; i<=7; i++)
   {
     if ((intreqs & 01) == 1)
       break;
     intreqs = intreqs >> 1;
   }
 }
 return i;
}

canonical_original_code:
static int pro_int_check(int irr, int imr)
{
int i; int intreqs;
 intreqs = irr & ((~imr) & 0377);
 if (intreqs == 0)
   i = 255;
 else
 {
   for(i=0; i<=7; i++)
   {
     if ((intreqs & 01) == 1)
       break;
     intreqs = intreqs >> 1;
   }
 }
 return i;
}

variable_types: irr int

variable_types: imr int

variable_types: intreqs int


decompiled_code:
__int64 pro_int_update()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // eax
__int64 result; // rax

v0 = 0LL;
v1 = 0;
do
{
if ( (unsigned int)pro_int_check(pro_int_irr[v0], pro_int_imr[v0]) != 255 )
{
v2 = pro_int_mode[v0];
if ( (v2 & 0x80u) != 0 && (v2 & 4) == 0 )
v1 = 1;
}
++v0;
}
while ( v0 != 4 );
result = int_req & 0xEFFFFFFF;
if ( v1 == 1 )
result = int_req | 0x10000000u;
int_req = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // eax
__int64 result; // rax

v0 = 0LL;
v1 = 0;
do
{
if ( (unsigned int)func0(pro_int_irr[v0], pro_int_imr[v0]) != 255 )
{
v2 = pro_int_mode[v0];
if ( (v2 & 0x80u) != 0 && (v2 & 4) == 0 )
v1 = 1;
}
++v0;
}
while ( v0 != 4 );
result = int_req & 0xEFFFFFFF;
if ( v1 == 1 )
result = int_req | 0x10000000u;
int_req = result;
return result;
}

original_code:
static void pro_int_update(void)
{
int intset, cnum, intnum;
 intset = 0;
 for(cnum=0; cnum<=3; cnum++)
 {
   intnum = pro_int_check(pro_int_irr[cnum], pro_int_imr[cnum]);
   if ((intnum != 255) && ((pro_int_mode[cnum] & 0200) != 0)
      && ((pro_int_mode[cnum] & 0004) == 0))
     intset = 1;
 }
 if (intset == 1)
   int_req = int_req | (1u << 28);
 else
   int_req = int_req & ~(1u << 28);
}

canonical_original_code:
static void pro_int_update()
{
int intset; int cnum; int intnum;
 intset = 0;
 for(cnum=0; cnum<=3; cnum++)
 {
   intnum = pro_int_check(pro_int_irr[cnum], pro_int_imr[cnum]);
   if ((intnum != 255) && ((pro_int_mode[cnum] & 0200) != 0)
      && ((pro_int_mode[cnum] & 0004) == 0))
     intset = 1;
 }
 if (intset == 1)
   int_req = int_req | (1u << 28);
 else
   int_req = int_req & ~(1u << 28);
}

variable_types: intset int

variable_types: cnum int

variable_types: intnum int


decompiled_code:
__int64 __fastcall pro_int_rd(int a1)
{
int v1; // ebx
int v2; // edx
__int64 result; // rax
int v4; // edi

v1 = (a1 >> 2) & 3;
if ( (a1 & 2) != 0 )
{
v4 = pro_int_check(pro_int_irr[v1], pro_int_imr[v1]);
if ( v4 == 255 )
v4 = 128;
result = v4 | (pro_int_mode[v1] >> 4) & 8 | (4 * (unsigned __int8)pro_int_mode[v1]) & 0x10 | (32
* (unsigned __int8)pro_int_mode[v1]) & 0x20u;
}
else
{
v2 = (pro_int_mode[v1] >> 5) & 3;
if ( v2 == 2 )
{
result = (unsigned int)pro_int_irr[v1];
}
else if ( ((pro_int_mode[v1] >> 5) & 3) == 3 )
{
result = (unsigned int)pro_int_acr[v1];
}
else if ( v2 )
{
result = (unsigned int)pro_int_imr[v1];
}
else
{
result = (unsigned int)pro_int_isr[v1];
}
}
return result;
}

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

v1 = (a1 >> 2) & 3;
if ( (a1 & 2) != 0 )
{
v4 = func0(pro_int_irr[v1], pro_int_imr[v1]);
if ( v4 == 255 )
v4 = 128;
result = v4 | (pro_int_mode[v1] >> 4) & 8 | (4 * (unsigned __int8)pro_int_mode[v1]) & 0x10 | (32
* (unsigned __int8)pro_int_mode[v1]) & 0x20u;
}
else
{
v2 = (pro_int_mode[v1] >> 5) & 3;
if ( v2 == 2 )
{
result = (unsigned int)pro_int_irr[v1];
}
else if ( ((pro_int_mode[v1] >> 5) & 3) == 3 )
{
result = (unsigned int)pro_int_acr[v1];
}
else if ( v2 )
{
result = (unsigned int)pro_int_imr[v1];
}
else
{
result = (unsigned int)pro_int_isr[v1];
}
}
return result;
}

original_code:
int pro_int_rd (int pa)
{
int data, i, cnum;
 cnum = (pa >> 2) & 03;
 switch (pa & 02)
 {
   case 00:
     switch ((pro_int_mode[cnum] >> 5) & 03)
     {
       case 00:
         data = pro_int_isr[cnum];
         break;
       case 01:
         data = pro_int_imr[cnum];
         break;
       case 02:
         data = pro_int_irr[cnum];
         break;
       case 03:
         data = pro_int_acr[cnum];
         break;
       default:
         data = 0;
         break;
     }
     break;
   case 02:
     i = pro_int_check(pro_int_irr[cnum], pro_int_imr[cnum]);
     if (i == 255)
       data = 0200;
     else
       data = i;
     data = data | ((pro_int_mode[cnum] & 0001) << 5)
                 | ((pro_int_mode[cnum] & 0004) << 2)
                 | ((pro_int_mode[cnum] & 0200) >> 4);
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_int_rd(int pa)
{
int data; int i; int cnum;
 cnum = (pa >> 2) & 03;
 switch (pa & 02)
 {
   case 00:
     switch ((pro_int_mode[cnum] >> 5) & 03)
     {
       case 00:
         data = pro_int_isr[cnum];
         break;
       case 01:
         data = pro_int_imr[cnum];
         break;
       case 02:
         data = pro_int_irr[cnum];
         break;
       case 03:
         data = pro_int_acr[cnum];
         break;
       default:
         data = 0;
         break;
     }
     break;
   case 02:
     i = pro_int_check(pro_int_irr[cnum], pro_int_imr[cnum]);
     if (i == 255)
       data = 0200;
     else
       data = i;
     data = data | ((pro_int_mode[cnum] & 0001) << 5)
                 | ((pro_int_mode[cnum] & 0004) << 2)
                 | ((pro_int_mode[cnum] & 0200) >> 4);
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

variable_types: pa int

variable_types: data int


decompiled_code:
int __fastcall pro_int_wr(int a1, int a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // ecx

LODWORD(v2) = (a2 >> 2) & 3;
if ( (a2 & 2) != 0 )
{
if ( (_BYTE)a1 )
{
if ( (a1 & 0xF8u) > 0xC8 )
{
if ( (a1 & 0xF8) == 224 )
{
pro_int_presel[(int)v2] = 2;
pro_int_presel_vec[(int)v2] = a1 & 7;
}
}
else if ( (a1 & 0xF8u) > 0xF )
{
switch ( a1 & 0xF8 )
{
case 0x10:
pro_int_irr[(int)v2] = 0;
pro_int_imr[(int)v2] = 0;
LODWORD(v2) = pro_int_update();
break;
case 0x18:
v4 = __ROL4__(-2, a1 & 7);
pro_int_irr[(int)v2] &= v4;
pro_int_imr[(int)v2] &= v4;
LODWORD(v2) = pro_int_update();
break;
case 0x20:
pro_int_imr[(int)v2] = 0;
LODWORD(v2) = pro_int_update();
break;
case 0x28:
pro_int_imr[(int)v2] &= __ROL4__(-2, a1 & 7);
LODWORD(v2) = pro_int_update();
break;
case 0x30:
pro_int_imr[(int)v2] = 255;
LODWORD(v2) = pro_int_update();
break;
case 0x38:
pro_int_imr[(int)v2] |= 1 << (a1 & 7);
LODWORD(v2) = pro_int_update();
break;
case 0x40:
pro_int_irr[(int)v2] = 0;
LODWORD(v2) = pro_int_update();
break;
case 0x48:
pro_int_irr[(int)v2] &= __ROL4__(-2, a1 & 7);
LODWORD(v2) = pro_int_update();
break;
case 0x50:
pro_int_irr[(int)v2] = 255;
LODWORD(v2) = pro_int_update();
break;
case 0x58:
pro_int_irr[(int)v2] |= 1 << (a1 & 7);
LODWORD(v2) = pro_int_update();
break;
case 0x60:
case 0x68:
LODWORD(v2) = puts("clear highest priority isr bit!!!!!!!\r");
break;
case 0x70:
pro_int_isr[(int)v2] = 0;
break;
case 0x78:
pro_int_isr[(int)v2] &= __ROL4__(-2, a1 & 7);
break;
case 0x80:
case 0x88:
case 0x90:
case 0x98:
pro_int_mode[(int)v2] = pro_int_mode[(int)v2] & 0xE0 | a1 & 0x1F;
LODWORD(v2) = pro_int_update();
break;
case 0xA0:
case 0xA8:
v5 = (8 * (_BYTE)a1) & 0x60 | pro_int_mode[(int)v2] & 0x9F;
v6 = a1 & 3;
if ( v6 == 1 )
{
LOBYTE(v5) = v5 | 0x80;
pro_int_mode[(int)v2] = v5;
}
else
{
if ( v6 == 2 )
LOBYTE(v5) = v5 & 0x7F;
pro_int_mode[(int)v2] = v5;
}
LODWORD(v2) = pro_int_update();
break;
case 0xB0:
case 0xB8:
pro_int_presel[(int)v2] = 0;
break;
case 0xC0:
case 0xC8:
pro_int_presel[(int)v2] = 1;
break;
default:
return v2;
}
}
}
else
{
pro_int_presel[(int)v2] = 0;
pro_int_irr[(int)v2] = 0;
pro_int_isr[(int)v2] = 0;
pro_int_imr[(int)v2] = 255;
pro_int_acr[(int)v2] = 0;
pro_int_mode[(int)v2] = 0;
LODWORD(v2) = pro_int_update();
}
}
else
{
v3 = pro_int_presel[(int)v2];
switch ( v3 )
{
case 1:
pro_int_acr[(int)v2] = a1;
break;
case 2:
v2 = pro_int_presel_vec[(int)v2] + 8LL * (int)v2;
pro_int_vec[v2] = a1;
break;
case 0:
pro_int_imr[(int)v2] = a1;
LODWORD(v2) = pro_int_update();
break;
}
}
return v2;
}

canonical_decompiled_code:
int __fastcall func3(int a1, int a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // ecx

LODWORD(v2) = (a2 >> 2) & 3;
if ( (a2 & 2) != 0 )
{
if ( (_BYTE)a1 )
{
if ( (a1 & 0xF8u) > 0xC8 )
{
if ( (a1 & 0xF8) == 224 )
{
pro_int_presel[(int)v2] = 2;
pro_int_presel_vec[(int)v2] = a1 & 7;
}
}
else if ( (a1 & 0xF8u) > 0xF )
{
switch ( a1 & 0xF8 )
{
case 0x10:
pro_int_irr[(int)v2] = 0;
pro_int_imr[(int)v2] = 0;
LODWORD(v2) = func1();
break;
case 0x18:
v4 = __ROL4__(-2, a1 & 7);
pro_int_irr[(int)v2] &= v4;
pro_int_imr[(int)v2] &= v4;
LODWORD(v2) = func1();
break;
case 0x20:
pro_int_imr[(int)v2] = 0;
LODWORD(v2) = func1();
break;
case 0x28:
pro_int_imr[(int)v2] &= __ROL4__(-2, a1 & 7);
LODWORD(v2) = func1();
break;
case 0x30:
pro_int_imr[(int)v2] = 255;
LODWORD(v2) = func1();
break;
case 0x38:
pro_int_imr[(int)v2] |= 1 << (a1 & 7);
LODWORD(v2) = func1();
break;
case 0x40:
pro_int_irr[(int)v2] = 0;
LODWORD(v2) = func1();
break;
case 0x48:
pro_int_irr[(int)v2] &= __ROL4__(-2, a1 & 7);
LODWORD(v2) = func1();
break;
case 0x50:
pro_int_irr[(int)v2] = 255;
LODWORD(v2) = func1();
break;
case 0x58:
pro_int_irr[(int)v2] |= 1 << (a1 & 7);
LODWORD(v2) = func1();
break;
case 0x60:
case 0x68:
LODWORD(v2) = puts("clear highest priority isr bit!!!!!!!\r");
break;
case 0x70:
pro_int_isr[(int)v2] = 0;
break;
case 0x78:
pro_int_isr[(int)v2] &= __ROL4__(-2, a1 & 7);
break;
case 0x80:
case 0x88:
case 0x90:
case 0x98:
pro_int_mode[(int)v2] = pro_int_mode[(int)v2] & 0xE0 | a1 & 0x1F;
LODWORD(v2) = func1();
break;
case 0xA0:
case 0xA8:
v5 = (8 * (_BYTE)a1) & 0x60 | pro_int_mode[(int)v2] & 0x9F;
v6 = a1 & 3;
if ( v6 == 1 )
{
LOBYTE(v5) = v5 | 0x80;
pro_int_mode[(int)v2] = v5;
}
else
{
if ( v6 == 2 )
LOBYTE(v5) = v5 & 0x7F;
pro_int_mode[(int)v2] = v5;
}
LODWORD(v2) = func1();
break;
case 0xB0:
case 0xB8:
pro_int_presel[(int)v2] = 0;
break;
case 0xC0:
case 0xC8:
pro_int_presel[(int)v2] = 1;
break;
default:
return v2;
}
}
}
else
{
pro_int_presel[(int)v2] = 0;
pro_int_irr[(int)v2] = 0;
pro_int_isr[(int)v2] = 0;
pro_int_imr[(int)v2] = 255;
pro_int_acr[(int)v2] = 0;
pro_int_mode[(int)v2] = 0;
LODWORD(v2) = func1();
}
}
else
{
v3 = pro_int_presel[(int)v2];
switch ( v3 )
{
case 1:
pro_int_acr[(int)v2] = a1;
break;
case 2:
v2 = pro_int_presel_vec[(int)v2] + 8LL * (int)v2;
pro_int_vec[v2] = a1;
break;
case 0:
pro_int_imr[(int)v2] = a1;
LODWORD(v2) = func1();
break;
}
}
return v2;
}

original_code:
void pro_int_wr (int data, int pa, int access)
{
int cnum;
 cnum = (pa >> 2) & 03;
 switch (pa & 02)
 {
   case 00:
     switch (pro_int_presel[cnum])
     {
       case 0:
         pro_int_imr[cnum] = data;
         pro_int_update();
         break;
       case 1:
         pro_int_acr[cnum] = data;
         break;
       case 2:
         pro_int_vec[cnum][pro_int_presel_vec[cnum]] = data;
         break;
       default:
         break;
     }
     break;
   case 02:
     if ((data & 0377) == 0)
     {
       pro_int_presel[cnum] = 0;
       pro_int_irr[cnum] = 0;
       pro_int_isr[cnum] = 0;
       pro_int_imr[cnum] = 0377;
       pro_int_acr[cnum] = 0;
       pro_int_mode[cnum] = 0;
       pro_int_update();
       break;
     }
     else
       switch (data & 0370)
       {
         case 0020:
           pro_int_irr[cnum] = 0;
           pro_int_imr[cnum] = 0;
           pro_int_update();
           break;
         case 0030:
           pro_int_irr[cnum] = pro_int_irr[cnum] & ~(1 << (data & 07));
           pro_int_imr[cnum] = pro_int_imr[cnum] & ~(1 << (data & 07));
           pro_int_update();
           break;
         case 0040:
           pro_int_imr[cnum] = 0;
           pro_int_update();
           break;
         case 0050:
           pro_int_imr[cnum] = pro_int_imr[cnum] & ~(1 << (data & 07));
           pro_int_update();
           break;
         case 0060:
           pro_int_imr[cnum] = 0377;
           pro_int_update();
           break;
         case 0070:
           pro_int_imr[cnum] = pro_int_imr[cnum] | (1 << (data & 07));
           pro_int_update();
           break;
         case 0100:
           pro_int_irr[cnum] = 0;
           pro_int_update();
           break;
         case 0110:
           pro_int_irr[cnum] = pro_int_irr[cnum] & ~(1 << (data & 07));
           pro_int_update();
           break;
         case 0120:
           pro_int_irr[cnum] = 0377;
           pro_int_update();
           break;
         case 0130:
           pro_int_irr[cnum] = pro_int_irr[cnum] | (1 << (data & 07));
           pro_int_update();
           break;
         case 0140:
         case 0150:
           printf("clear highest priority isr bit!!!!!!!\r\n");
           break;
         case 0160:
           pro_int_isr[cnum] = 0;
           break;
         case 0170:
           pro_int_isr[cnum] = pro_int_isr[cnum] & ~(1 << (data & 07));
           break;
         case 0200:
         case 0210:
         case 0220:
         case 0230:
           pro_int_mode[cnum] = (pro_int_mode[cnum] & 0340) | (data & 0037);
           pro_int_update();
           break;
         case 0240:
         case 0250:
           pro_int_mode[cnum] = (pro_int_mode[cnum] & 0237) | ((data << 3) & 0140);
           if ((data & 03) == 01)
             pro_int_mode[cnum] = pro_int_mode[cnum] | (1 << 7);
           else if ((data & 03) == 02)
             pro_int_mode[cnum] = pro_int_mode[cnum] & ~(1 << 7);
           pro_int_update();
           break;
         case 0260:
         case 0270:
           pro_int_presel[cnum] = 0;
           break;
         case 0300:
         case 0310:
           pro_int_presel[cnum] = 1;
           break;
         case 0340:
           pro_int_presel[cnum] = 2;
           pro_int_presel_vec[cnum] = (data & 07);
           break;
         default:
           break;
       }
     break;
   default:
     break;
 }
}

canonical_original_code:
void pro_int_wr(int data, int pa, int access)
{
int cnum;
 cnum = (pa >> 2) & 03;
 switch (pa & 02)
 {
   case 00:
     switch (pro_int_presel[cnum])
     {
       case 0:
         pro_int_imr[cnum] = data;
         pro_int_update();
         break;
       case 1:
         pro_int_acr[cnum] = data;
         break;
       case 2:
         pro_int_vec[cnum][pro_int_presel_vec[cnum]] = data;
         break;
       default:
         break;
     }
     break;
   case 02:
     if ((data & 0377) == 0)
     {
       pro_int_presel[cnum] = 0;
       pro_int_irr[cnum] = 0;
       pro_int_isr[cnum] = 0;
       pro_int_imr[cnum] = 0377;
       pro_int_acr[cnum] = 0;
       pro_int_mode[cnum] = 0;
       pro_int_update();
       break;
     }
     else
       switch (data & 0370)
       {
         case 0020:
           pro_int_irr[cnum] = 0;
           pro_int_imr[cnum] = 0;
           pro_int_update();
           break;
         case 0030:
           pro_int_irr[cnum] = pro_int_irr[cnum] & ~(1 << (data & 07));
           pro_int_imr[cnum] = pro_int_imr[cnum] & ~(1 << (data & 07));
           pro_int_update();
           break;
         case 0040:
           pro_int_imr[cnum] = 0;
           pro_int_update();
           break;
         case 0050:
           pro_int_imr[cnum] = pro_int_imr[cnum] & ~(1 << (data & 07));
           pro_int_update();
           break;
         case 0060:
           pro_int_imr[cnum] = 0377;
           pro_int_update();
           break;
         case 0070:
           pro_int_imr[cnum] = pro_int_imr[cnum] | (1 << (data & 07));
           pro_int_update();
           break;
         case 0100:
           pro_int_irr[cnum] = 0;
           pro_int_update();
           break;
         case 0110:
           pro_int_irr[cnum] = pro_int_irr[cnum] & ~(1 << (data & 07));
           pro_int_update();
           break;
         case 0120:
           pro_int_irr[cnum] = 0377;
           pro_int_update();
           break;
         case 0130:
           pro_int_irr[cnum] = pro_int_irr[cnum] | (1 << (data & 07));
           pro_int_update();
           break;
         case 0140:
         case 0150:
           printf("clear highest priority isr bit!!!!!!!\r\n");
           break;
         case 0160:
           pro_int_isr[cnum] = 0;
           break;
         case 0170:
           pro_int_isr[cnum] = pro_int_isr[cnum] & ~(1 << (data & 07));
           break;
         case 0200:
         case 0210:
         case 0220:
         case 0230:
           pro_int_mode[cnum] = (pro_int_mode[cnum] & 0340) | (data & 0037);
           pro_int_update();
           break;
         case 0240:
         case 0250:
           pro_int_mode[cnum] = (pro_int_mode[cnum] & 0237) | ((data << 3) & 0140);
           if ((data & 03) == 01)
             pro_int_mode[cnum] = pro_int_mode[cnum] | (1 << 7);
           else if ((data & 03) == 02)
             pro_int_mode[cnum] = pro_int_mode[cnum] & ~(1 << 7);
           pro_int_update();
           break;
         case 0260:
         case 0270:
           pro_int_presel[cnum] = 0;
           break;
         case 0300:
         case 0310:
           pro_int_presel[cnum] = 1;
           break;
         case 0340:
           pro_int_presel[cnum] = 2;
           pro_int_presel_vec[cnum] = (data & 07);
           break;
         default:
           break;
       }
     break;
   default:
     break;
 }
}

variable_types: access int


decompiled_code:
__int64 pro_int_ack()
{
__int64 i; // rbx
int v1; // ebp
unsigned int v2; // ecx
int v3; // eax
unsigned int v4; // ebx
int v5; // eax

for ( i = 0LL; i != 4; ++i )
{
v1 = i;
v2 = pro_int_check(pro_int_irr[i], pro_int_imr[i]);
if ( v2 != 255 )
{
v3 = pro_int_mode[i];
if ( (v3 & 0x80u) != 0 && (v3 & 4) == 0 )
break;
}
v1 = i + 1;
}
if ( (pro_int_mode[v1] & 2) != 0 )
v4 = pro_int_vec[8 * v1];
else
v4 = pro_int_vec[8 * v1 + v2];
pro_int_irr[v1] &= ~(1 << v2);
v5 = pro_int_acr[v1];
if ( !_bittest(&v5, v2) )
pro_int_isr[v1] |= 1 << v2;
pro_int_update();
return v4;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 i; // rbx
int v1; // ebp
unsigned int v2; // ecx
int v3; // eax
unsigned int v4; // ebx
int v5; // eax

for ( i = 0LL; i != 4; ++i )
{
v1 = i;
v2 = func0(pro_int_irr[i], pro_int_imr[i]);
if ( v2 != 255 )
{
v3 = pro_int_mode[i];
if ( (v3 & 0x80u) != 0 && (v3 & 4) == 0 )
break;
}
v1 = i + 1;
}
if ( (pro_int_mode[v1] & 2) != 0 )
v4 = pro_int_vec[8 * v1];
else
v4 = pro_int_vec[8 * v1 + v2];
pro_int_irr[v1] &= ~(1 << v2);
v5 = pro_int_acr[v1];
if ( !_bittest(&v5, v2) )
pro_int_isr[v1] |= 1 << v2;
func1();
return v4;
}

original_code:
int pro_int_ack (void)
{
int cnum, intnum, vec;
 for(cnum=0; cnum<=3; cnum++)
 {
   intnum = pro_int_check(pro_int_irr[cnum], pro_int_imr[cnum]);
   if ((intnum != 255) && ((pro_int_mode[cnum] & 0200) != 0)
      && ((pro_int_mode[cnum] & 0004) == 0))
     break;
 }
 if ((pro_int_mode[cnum] & 0002) != 0)
   vec = pro_int_vec[cnum][0];
 else
   vec = pro_int_vec[cnum][intnum];
 pro_int_irr[cnum] = pro_int_irr[cnum] & ~(1 << intnum);
 if (((pro_int_acr[cnum] >> intnum) & 01) == 0)
   pro_int_isr[cnum] = pro_int_isr[cnum] | (1 << intnum);
 pro_int_update();
 return vec;
}

canonical_original_code:
int pro_int_ack()
{
int cnum; int intnum; int vec;
 for(cnum=0; cnum<=3; cnum++)
 {
   intnum = pro_int_check(pro_int_irr[cnum], pro_int_imr[cnum]);
   if ((intnum != 255) && ((pro_int_mode[cnum] & 0200) != 0)
      && ((pro_int_mode[cnum] & 0004) == 0))
     break;
 }
 if ((pro_int_mode[cnum] & 0002) != 0)
   vec = pro_int_vec[cnum][0];
 else
   vec = pro_int_vec[cnum][intnum];
 pro_int_irr[cnum] = pro_int_irr[cnum] & ~(1 << intnum);
 if (((pro_int_acr[cnum] >> intnum) & 01) == 0)
   pro_int_isr[cnum] = pro_int_isr[cnum] | (1 << intnum);
 pro_int_update();
 return vec;
}

variable_types: vec int


decompiled_code:
__int64 __fastcall pro_int_set(__int16 a1)
{
pro_int_irr[HIBYTE(a1)] |= (unsigned __int8)a1;
return pro_int_update();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1)
{
pro_int_irr[HIBYTE(a1)] |= (unsigned __int8)a1;
return func1();
}

original_code:
void pro_int_set (int intnum)
{
int cnum, intbit;
 cnum = (intnum >> 8) & 0377;
 intbit = intnum & 0377;
 pro_int_irr[cnum] |= intbit;
 pro_int_update();
}

canonical_original_code:
void pro_int_set(int intnum)
{
int cnum; int intbit;
 cnum = (intnum >> 8) & 0377;
 intbit = intnum & 0377;
 pro_int_irr[cnum] |= intbit;
 pro_int_update();
}

variable_types: intbit int


decompiled_code:
__int64 pro_int_reset()
{
unsigned __int64 i; // rax

for ( i = 0LL; i != 16; i += 4LL )
{
pro_int_presel[i / 4] = 0;
pro_int_irr[i / 4] = 0;
pro_int_isr[i / 4] = 0;
pro_int_imr[i / 4] = 255;
pro_int_acr[i / 4] = 0;
pro_int_mode[i / 4] = 0;
pro_int_presel_vec[i / 4] = 0;
pro_int_vec[2 * i] = 0;
dword_624[2 * i] = 0;
dword_628[2 * i] = 0;
dword_62C[2 * i] = 0;
dword_630[2 * i] = 0;
dword_634[2 * i] = 0;
dword_638[2 * i] = 0;
dword_63C[2 * i] = 0;
}
return pro_int_update();
}

original_code:
void pro_int_reset ()
{
int cnum;
 for(cnum=0; cnum<=3; cnum++)
 {
   pro_int_presel[cnum] = 0;
   pro_int_irr[cnum] = 0;
   pro_int_isr[cnum] = 0;
   pro_int_imr[cnum] = 0377;
   pro_int_acr[cnum] = 0;
   pro_int_mode[cnum] = 0;
   pro_int_presel_vec[cnum] = 0;
   pro_int_vec[cnum][0] = 0;
   pro_int_vec[cnum][1] = 0;
   pro_int_vec[cnum][2] = 0;
   pro_int_vec[cnum][3] = 0;
   pro_int_vec[cnum][4] = 0;
   pro_int_vec[cnum][5] = 0;
   pro_int_vec[cnum][6] = 0;
   pro_int_vec[cnum][7] = 0;
 }
 pro_int_update();
}

canonical_original_code:
void pro_int_reset()
{
int cnum;
 for(cnum=0; cnum<=3; cnum++)
 {
   pro_int_presel[cnum] = 0;
   pro_int_irr[cnum] = 0;
   pro_int_isr[cnum] = 0;
   pro_int_imr[cnum] = 0377;
   pro_int_acr[cnum] = 0;
   pro_int_mode[cnum] = 0;
   pro_int_presel_vec[cnum] = 0;
   pro_int_vec[cnum][0] = 0;
   pro_int_vec[cnum][1] = 0;
   pro_int_vec[cnum][2] = 0;
   pro_int_vec[cnum][3] = 0;
   pro_int_vec[cnum][4] = 0;
   pro_int_vec[cnum][5] = 0;
   pro_int_vec[cnum][6] = 0;
   pro_int_vec[cnum][7] = 0;
 }
 pro_int_update();
}


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

(*(void (__fastcall **)(__int64, __int64 *))(pro_ptr + 16LL))(1LL, &pro_2661ptr_ctrl);
v0 = pro_2661ptr_stat;
LOBYTE(v0) = pro_2661ptr_stat & 0x7F;
pro_2661ptr_stat = v0;
if ( *((_DWORD *)&pro_2661ptr_ctrl + 7) == 1 )
{
LOBYTE(v0) = v0 | 0x80;
pro_2661ptr_stat = v0;
}
return v0;
}

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

(*(void (__fastcall **)(__int64, __int64 *))(pro_ptr + 16LL))(1LL, &pro_2661ptr_ctrl);
v0 = pro_2661ptr_stat;
LOBYTE(v0) = pro_2661ptr_stat & 0x7F;
pro_2661ptr_stat = v0;
if ( *((_DWORD *)&pro_2661ptr_ctrl + 7) == 1 )
{
LOBYTE(v0) = v0 | 0x80;
pro_2661ptr_stat = v0;
}
return v0;
}

original_code:
static void pro_2661ptr_ctrl_get ()
{
 pro_ptr->ctrl_get(1, &pro_2661ptr_ctrl);
 pro_2661ptr_stat = (pro_2661ptr_stat & ~0200);
 if (pro_2661ptr_ctrl.dsr == 1)
   pro_2661ptr_stat |= 0200;
}

canonical_original_code:
static void pro_2661ptr_ctrl_get()
{
 pro_ptr->ctrl_get(1, &pro_2661ptr_ctrl);
 pro_2661ptr_stat = (pro_2661ptr_stat & ~0200);
 if (pro_2661ptr_ctrl.dsr == 1)
   pro_2661ptr_stat |= 0200;
}


original_code:
static void pro_2661ptr_ctrl_put ()
{
 pro_2661ptr_ctrl.cs = (pro_2661ptr_mr1 & 0014) >> 2;
 pro_2661ptr_ctrl.stop = (pro_2661ptr_mr1 & 0300) >> 6;
 pro_2661ptr_ctrl.parity = (pro_2661ptr_mr1 & 0040) >> 5;
 pro_2661ptr_ctrl.penable = (pro_2661ptr_mr1 & 0020) >> 4;
 pro_2661ptr_ctrl.ibaud = pro_2661ptr_mr2 & 0017;
 pro_2661ptr_ctrl.obaud = pro_2661ptr_mr2 & 0017;
 pro_2661ptr_ctrl.dtr = (pro_2661ptr_cmd & 0002) >> 1;
 pro_2661ptr_ctrl.obrk = (pro_2661ptr_cmd & 0010) >> 3;
 pro_2661ptr_ctrl.rts = 1;
 pro_ptr->ctrl_put(1, &pro_2661ptr_ctrl);
}

canonical_original_code:
static void pro_2661ptr_ctrl_put()
{
 pro_2661ptr_ctrl.cs = (pro_2661ptr_mr1 & 0014) >> 2;
 pro_2661ptr_ctrl.stop = (pro_2661ptr_mr1 & 0300) >> 6;
 pro_2661ptr_ctrl.parity = (pro_2661ptr_mr1 & 0040) >> 5;
 pro_2661ptr_ctrl.penable = (pro_2661ptr_mr1 & 0020) >> 4;
 pro_2661ptr_ctrl.ibaud = pro_2661ptr_mr2 & 0017;
 pro_2661ptr_ctrl.obaud = pro_2661ptr_mr2 & 0017;
 pro_2661ptr_ctrl.dtr = (pro_2661ptr_cmd & 0002) >> 1;
 pro_2661ptr_ctrl.obrk = (pro_2661ptr_cmd & 0010) >> 3;
 pro_2661ptr_ctrl.rts = 1;
 pro_ptr->ctrl_put(1, &pro_2661ptr_ctrl);
}


decompiled_code:
__int64 pro_2661ptr_poll_sched()
{
return pro_eq_sched(8LL, 100LL);
}

canonical_decompiled_code:
__int64 func2()
{
return pro_eq_sched(8LL, 100LL);
}

original_code:
static void pro_2661ptr_poll_sched ()
{
 pro_eq_sched(8, 100);
}

canonical_original_code:
static void pro_2661ptr_poll_sched()
{
 pro_eq_sched(8, 100);
}


decompiled_code:
__int64 pro_2661ptr_poll_eq()
{
int v1; // eax

if ( (pro_2661ptr_cmd & 0xC4) == 4 && (pro_2661ptr_stat & 2) == 0 )
{
v1 = ((__int64 (__fastcall *)(__int64))*pro_ptr)(1LL);
if ( v1 != 256 )
{
pro_2661ptr_data = v1;
pro_2661ptr_stat |= 2u;
pro_int_set(32LL);
}
}
return pro_2661ptr_poll_sched();
}

variable_types: schar int


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

if ( (pro_2661ptr_cmd & 0xC0) == 0
&& (*(unsigned int (__fastcall **)(__int64, _QWORD))(pro_ptr + 8LL))(1LL, (unsigned int)pro_2661ptr_wdata) == -1 )
{
return pro_eq_sched(7LL, 1000LL);
}
pro_2661ptr_stat |= 1u;
pro_int_set(64LL);
result = (unsigned __int8)pro_2661ptr_cmd & 0xC0;
if ( (_DWORD)result == 128 )
{
pro_2661ptr_data = pro_2661ptr_wdata;
pro_2661ptr_stat |= 2u;
result = pro_int_set(32LL);
}
return result;
}

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

if ( (pro_2661ptr_cmd & 0xC0) == 0
&& (*(unsigned int (__fastcall **)(__int64, _QWORD))(pro_ptr + 8LL))(1LL, (unsigned int)pro_2661ptr_wdata) == -1 )
{
return pro_eq_sched(7LL, 1000LL);
}
pro_2661ptr_stat |= 1u;
pro_int_set(64LL);
result = (unsigned __int8)pro_2661ptr_cmd & 0xC0;
if ( (_DWORD)result == 128 )
{
pro_2661ptr_data = pro_2661ptr_wdata;
pro_2661ptr_stat |= 2u;
result = pro_int_set(32LL);
}
return result;
}


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

v1 = a1 & 6;
if ( v1 == 4 )
{
if ( pro_2661ptr_mode_ptr )
{
result = (unsigned int)pro_2661ptr_mr2;
pro_2661ptr_mode_ptr = 0;
}
else
{
result = (unsigned int)pro_2661ptr_mr1;
pro_2661ptr_mode_ptr = 1;
}
}
else if ( v1 > 4 )
{
if ( v1 == 6 )
{
result = (unsigned int)pro_2661ptr_cmd;
pro_2661ptr_mode_ptr = pro_2661ptr_mode_ptr == 0;
}
else
{
result = 0LL;
}
}
else if ( v1 )
{
if ( v1 == 2 )
{
pro_2661ptr_ctrl_get();
result = (unsigned int)pro_2661ptr_stat;
}
else
{
result = 0LL;
}
}
else
{
result = (unsigned int)pro_2661ptr_data;
pro_2661ptr_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_2661ptr_mode_ptr )
{
result = (unsigned int)pro_2661ptr_mr2;
pro_2661ptr_mode_ptr = 0;
}
else
{
result = (unsigned int)pro_2661ptr_mr1;
pro_2661ptr_mode_ptr = 1;
}
}
else if ( v1 > 4 )
{
if ( v1 == 6 )
{
result = (unsigned int)pro_2661ptr_cmd;
pro_2661ptr_mode_ptr = pro_2661ptr_mode_ptr == 0;
}
else
{
result = 0LL;
}
}
else if ( v1 )
{
if ( v1 == 2 )
{
func0();
result = (unsigned int)pro_2661ptr_stat;
}
else
{
result = 0LL;
}
}
else
{
result = (unsigned int)pro_2661ptr_data;
pro_2661ptr_stat &= 0xFFFFFFFD;
}
return result;
}

original_code:
int pro_2661ptr_rd (int pa)
{
int data;
 switch (pa & 06)
 {
   case 00:
     data = pro_2661ptr_data;
     pro_2661ptr_stat = pro_2661ptr_stat & ~0002;
     break;
   case 02:
     pro_2661ptr_ctrl_get();
     data = pro_2661ptr_stat;
     break;
   case 04:
     if (pro_2661ptr_mode_ptr == 0)
     {
       data = pro_2661ptr_mr1;
       pro_2661ptr_mode_ptr = 1;
     }
     else
     {
       data = pro_2661ptr_mr2;
       pro_2661ptr_mode_ptr = 0;
     }
     break;
   case 06:
     data = pro_2661ptr_cmd;
     if (pro_2661ptr_mode_ptr == 0)
       pro_2661ptr_mode_ptr = 1;
     else
       pro_2661ptr_mode_ptr = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_2661ptr_rd(int pa)
{
int data;
 switch (pa & 06)
 {
   case 00:
     data = pro_2661ptr_data;
     pro_2661ptr_stat = pro_2661ptr_stat & ~0002;
     break;
   case 02:
     pro_2661ptr_ctrl_get();
     data = pro_2661ptr_stat;
     break;
   case 04:
     if (pro_2661ptr_mode_ptr == 0)
     {
       data = pro_2661ptr_mr1;
       pro_2661ptr_mode_ptr = 1;
     }
     else
     {
       data = pro_2661ptr_mr2;
       pro_2661ptr_mode_ptr = 0;
     }
     break;
   case 06:
     data = pro_2661ptr_cmd;
     if (pro_2661ptr_mode_ptr == 0)
       pro_2661ptr_mode_ptr = 1;
     else
       pro_2661ptr_mode_ptr = 0;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}


decompiled_code:
__int64 __fastcall pro_2661ptr_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_2661ptr_mode_ptr )
{
if ( a3 == 4 )
{
v9 = pro_2661ptr_mr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v9) = 0;
v9 |= a1;
}
pro_2661ptr_mr2 = v9;
}
else
{
v8 = pro_2661ptr_mr2;
LOBYTE(v8) = 0;
pro_2661ptr_mr2 = v8 | a1;
}
pro_2661ptr_mode_ptr = 0;
}
else
{
if ( a3 == 4 )
{
v7 = pro_2661ptr_mr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v7) = 0;
v7 |= a1;
}
pro_2661ptr_mr1 = v7;
}
else
{
v6 = pro_2661ptr_mr1;
LOBYTE(v6) = 0;
pro_2661ptr_mr1 = v6 | a1;
}
pro_2661ptr_mode_ptr = 1;
}
result = pro_2661ptr_ctrl_put();
}
else if ( (_DWORD)result == 6 )
{
if ( a3 == 4 )
{
v12 = pro_2661ptr_cmd;
if ( (a2 & 1) == 0 )
{
LOBYTE(v12) = pro_2661ptr_cmd & 0x10;
v12 |= a1 & 0xEF;
}
pro_2661ptr_cmd = v12;
}
else
{
v10 = pro_2661ptr_cmd;
LOBYTE(v10) = pro_2661ptr_cmd & 0x10;
pro_2661ptr_cmd = v10 | a1 & 0xEF;
}
if ( (pro_2661ptr_cmd & 4) == 0 )
pro_2661ptr_stat &= 0xFFFFFFFD;
if ( (pro_2661ptr_cmd & 1) != 0 )
v11 = pro_2661ptr_stat | 1;
else
v11 = pro_2661ptr_stat & 0xFFFFFFFE;
pro_2661ptr_stat = v11;
result = pro_2661ptr_ctrl_put();
}
else if ( (a2 & 6) == 0 && (pro_2661ptr_cmd & 1) != 0 )
{
if ( a3 == 4 )
{
v5 = pro_2661ptr_wdata;
if ( (a2 & 1) == 0 )
{
LOBYTE(v5) = 0;
v5 |= a1;
}
pro_2661ptr_wdata = v5;
}
else
{
v4 = pro_2661ptr_wdata;
LOBYTE(v4) = 0;
pro_2661ptr_wdata = v4 | a1;
}
pro_2661ptr_stat &= 0xFFFFFFFE;
result = pro_eq_sched(7LL, 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_2661ptr_mode_ptr )
{
if ( a3 == 4 )
{
v9 = pro_2661ptr_mr2;
if ( (a2 & 1) == 0 )
{
LOBYTE(v9) = 0;
v9 |= a1;
}
pro_2661ptr_mr2 = v9;
}
else
{
v8 = pro_2661ptr_mr2;
LOBYTE(v8) = 0;
pro_2661ptr_mr2 = v8 | a1;
}
pro_2661ptr_mode_ptr = 0;
}
else
{
if ( a3 == 4 )
{
v7 = pro_2661ptr_mr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v7) = 0;
v7 |= a1;
}
pro_2661ptr_mr1 = v7;
}
else
{
v6 = pro_2661ptr_mr1;
LOBYTE(v6) = 0;
pro_2661ptr_mr1 = v6 | a1;
}
pro_2661ptr_mode_ptr = 1;
}
result = func1();
}
else if ( (_DWORD)result == 6 )
{
if ( a3 == 4 )
{
v12 = pro_2661ptr_cmd;
if ( (a2 & 1) == 0 )
{
LOBYTE(v12) = pro_2661ptr_cmd & 0x10;
v12 |= a1 & 0xEF;
}
pro_2661ptr_cmd = v12;
}
else
{
v10 = pro_2661ptr_cmd;
LOBYTE(v10) = pro_2661ptr_cmd & 0x10;
pro_2661ptr_cmd = v10 | a1 & 0xEF;
}
if ( (pro_2661ptr_cmd & 4) == 0 )
pro_2661ptr_stat &= 0xFFFFFFFD;
if ( (pro_2661ptr_cmd & 1) != 0 )
v11 = pro_2661ptr_stat | 1;
else
v11 = pro_2661ptr_stat & 0xFFFFFFFE;
pro_2661ptr_stat = v11;
result = func1();
}
else if ( (a2 & 6) == 0 && (pro_2661ptr_cmd & 1) != 0 )
{
if ( a3 == 4 )
{
v5 = pro_2661ptr_wdata;
if ( (a2 & 1) == 0 )
{
LOBYTE(v5) = 0;
v5 |= a1;
}
pro_2661ptr_wdata = v5;
}
else
{
v4 = pro_2661ptr_wdata;
LOBYTE(v4) = 0;
pro_2661ptr_wdata = v4 | a1;
}
pro_2661ptr_stat &= 0xFFFFFFFE;
result = pro_eq_sched(7LL, 2LL);
}
return result;
}


original_code:
void pro_2661ptr_reset ()
{
 pro_2661ptr_data = 0000;
 pro_2661ptr_stat = 0100 | 0001;
 pro_2661ptr_mr1 = 0000;
 pro_2661ptr_mr2 = 0000;
 pro_2661ptr_cmd = 0000;
 pro_2661ptr_mode_ptr = 0;
 memset(&pro_2661ptr_ctrl, 0, sizeof(pro_2661ptr_ctrl));
 pro_2661ptr_poll_sched();
}

canonical_original_code:
void pro_2661ptr_reset()
{
 pro_2661ptr_data = 0000;
 pro_2661ptr_stat = 0100 | 0001;
 pro_2661ptr_mr1 = 0000;
 pro_2661ptr_mr2 = 0000;
 pro_2661ptr_cmd = 0000;
 pro_2661ptr_mode_ptr = 0;
 memset(&pro_2661ptr_ctrl, 0, sizeof(pro_2661ptr_ctrl));
 pro_2661ptr_poll_sched();
}


decompiled_code:
char pro_2661ptr_open()
{
(*(void (__fastcall **)(__int64, _QWORD))(pro_ptr + 32LL))(1LL, pro_ptr_port);
pro_2661ptr_ctrl_put();
return pro_2661ptr_ctrl_get();
}

canonical_decompiled_code:
char func8()
{
(*(void (__fastcall **)(__int64, _QWORD))(pro_ptr + 32LL))(1LL, pro_ptr_port);
func1();
return func0();
}

original_code:
void pro_2661ptr_open ()
{
 pro_ptr->reset(1, pro_ptr_port);
 pro_2661ptr_ctrl_put();
 pro_2661ptr_ctrl_get();
}

canonical_original_code:
void pro_2661ptr_open()
{
 pro_ptr->reset(1, pro_ptr_port);
 pro_2661ptr_ctrl_put();
 pro_2661ptr_ctrl_get();
}


decompiled_code:
__int64 pro_la50_ctrl_get()
{
return (*(__int64 (**)(void))(pro_la50device + 16LL))();
}

original_code:
void pro_la50_ctrl_get (int dev, struct serctrl *sctrl)
{
 pro_la50device->ctrl_get(dev, sctrl);
}

canonical_original_code:
void pro_la50_ctrl_get(int dev, struct serctrl *sctrl)
{
 pro_la50device->ctrl_get(dev, sctrl);
}

variable_types: dev int

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


decompiled_code:
__int64 pro_la50_ctrl_put()
{
return (*(__int64 (**)(void))(pro_la50device + 24LL))();
}

original_code:
void pro_la50_ctrl_put (int dev, struct serctrl *sctrl)
{
 pro_la50device->ctrl_put(dev, sctrl);
}

canonical_original_code:
void pro_la50_ctrl_put(int dev, struct serctrl *sctrl)
{
 pro_la50device->ctrl_put(dev, sctrl);
}

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:
__int64 __fastcall pro_la50_reset(__int64 a1)
{
state = 0;
ptr_fifo_h = 0;
ptr_fifo_t = 0;
ptr_fifo_level = 0;
maxpos = 85 * pro_la50_dpi / 10;
return (*(__int64 (__fastcall **)(__int64, _QWORD))(pro_la50device + 32LL))(a1, pro_la50device_port);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
state = 0;
ptr_fifo_h = 0;
ptr_fifo_t = 0;
ptr_fifo_level = 0;
maxpos = 85 * pro_la50_dpi / 10;
return (*(__int64 (__fastcall **)(__int64, _QWORD))(pro_la50device + 32LL))(a1, pro_la50device_port);
}

original_code:
void pro_la50_reset (int dev, int portnum)
{
 state = 0;
 ptr_fifo_h = 0;
 ptr_fifo_t = 0;
 ptr_fifo_level = 0;
 maxpos = (85*pro_la50_dpi/10);
 pro_la50device->reset(dev, pro_la50device_port);
}

canonical_original_code:
void pro_la50_reset(int dev, int portnum)
{
 state = 0;
 ptr_fifo_h = 0;
 ptr_fifo_t = 0;
 ptr_fifo_level = 0;
 maxpos = (85*pro_la50_dpi/10);
 pro_la50device->reset(dev, pro_la50device_port);
}

variable_types: portnum int


decompiled_code:
__int64 pro_la50_exit()
{
return (*(__int64 (**)(void))(pro_la50device + 40LL))();
}

original_code:
void pro_la50_exit (int dev)
{
 pro_la50device->exit(dev);
}

canonical_original_code:
void pro_la50_exit(int dev)
{
 pro_la50device->exit(dev);
}


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

v1 = ptr_fifo_h;
ptr_fifo[ptr_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 30623 )
result = 0LL;
ptr_fifo_h = result;
++ptr_fifo_level;
return result;
}

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

v1 = ptr_fifo_h;
ptr_fifo[ptr_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 30623 )
result = 0LL;
ptr_fifo_h = result;
++ptr_fifo_level;
return result;
}

original_code:
void ptr_fifo_put (int c)
{
 ptr_fifo[ptr_fifo_h] = (unsigned char)c;
 ptr_fifo_h++;
 if (ptr_fifo_h == ((((85*600/10)+7)/8)*6*8))
   ptr_fifo_h = 0;
 ptr_fifo_level++;
}

canonical_original_code:
void ptr_fifo_put(int c)
{
 ptr_fifo[ptr_fifo_h] = (unsigned char)c;
 ptr_fifo_h++;
 if (ptr_fifo_h == ((((85*600/10)+7)/8)*6*8))
   ptr_fifo_h = 0;
 ptr_fifo_level++;
}

variable_types: c int


decompiled_code:
__int64 __fastcall ptr_fifo_printf(char *a1)
{
char *v1; // rbx
char v2; // di
__int64 result; // rax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
result = ptr_fifo_put(v2);
v2 = *++v1;
}
while ( *v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char *v1; // rbx
char v2; // di
__int64 result; // rax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
result = func4(v2);
v2 = *++v1;
}
while ( *v1 );
}
return result;
}

original_code:
void ptr_fifo_printf (unsigned char *s)
{
 while(*s != '\0')
 {
   ptr_fifo_put((int)*s);
   s++;
 }
}

canonical_original_code:
void ptr_fifo_printf(unsigned char *s)
{
 while(*s != '\0')
 {
   ptr_fifo_put((int)*s);
   s++;
 }
}

variable_types:
s
unsigned char *


decompiled_code:
__int64 ptr_fifo_get()
{
unsigned int v0; // edx

v0 = 256;
if ( ptr_fifo_h != ptr_fifo_t )
{
v0 = (unsigned __int8)ptr_fifo[ptr_fifo_t];
--ptr_fifo_level;
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // edx

v0 = 256;
if ( ptr_fifo_h != ptr_fifo_t )
{
v0 = (unsigned __int8)ptr_fifo[ptr_fifo_t];
--ptr_fifo_level;
}
return v0;
}

original_code:
int ptr_fifo_get ()
{
 int c;
 if (ptr_fifo_h == ptr_fifo_t)
   c = 256;
 else
 {
   c = (int)ptr_fifo[ptr_fifo_t];
   ptr_fifo_level--;
 }
 return c;
}

canonical_original_code:
int ptr_fifo_get()
{
 int c;
 if (ptr_fifo_h == ptr_fifo_t)
   c = 256;
 else
 {
   c = (int)ptr_fifo[ptr_fifo_t];
   ptr_fifo_level--;
 }
 return c;
}


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

result = (unsigned int)(ptr_fifo_t + 1);
if ( ptr_fifo_t == 30623 )
result = 0LL;
ptr_fifo_t = result;
return result;
}

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

result = (unsigned int)(ptr_fifo_t + 1);
if ( ptr_fifo_t == 30623 )
result = 0LL;
ptr_fifo_t = result;
return result;
}


decompiled_code:
__int64 __fastcall pro_la50_get(unsigned int a1)
{
int v1; // ebx
unsigned int v2; // eax
__int64 v3; // rsi

v1 = 10;
do
{
v2 = ptr_fifo_get();
v3 = v2;
if ( v2 == 256 )
break;
if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD))(pro_la50device + 8LL))(a1, v2) == -1 )
break;
ptr_fifo_advance();
--v1;
}
while ( v1 );
return ((__int64 (__fastcall *)(_QWORD, __int64))*pro_la50device)(a1, v3);
}

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

v1 = 10;
do
{
v2 = func6();
v3 = v2;
if ( v2 == 256 )
break;
if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD))(pro_la50device + 8LL))(a1, v2) == -1 )
break;
func7();
--v1;
}
while ( v1 );
return ((__int64 (__fastcall *)(_QWORD, __int64))*pro_la50device)(a1, v3);
}

original_code:
int pro_la50_get (int dev)
{
int i, schar;
 for(i=0; i<10; i++)
 {
   schar = ptr_fifo_get();
   if (schar == 256)
     break;
   else
   {
     if (pro_la50device->put(dev, schar) == -1)
       break;
     else
       ptr_fifo_advance();
   }
 }
 return pro_la50device->get(dev);
}

canonical_original_code:
int pro_la50_get(int dev)
{
int i; int schar;
 for(i=0; i<10; i++)
 {
   schar = ptr_fifo_get();
   if (schar == 256)
     break;
   else
   {
     if (pro_la50device->put(dev, schar) == -1)
       break;
     else
       ptr_fifo_advance();
   }
 }
 return pro_la50device->get(dev);
}

variable_types: i int


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

sprintf(tmpstr, "%c*t%dR%c*r0A", 27LL, (unsigned int)pro_la50_dpi, 27LL);
ptr_fifo_printf(tmpstr);
colrcnt = 0;
rowrcnt = 0;
col = 0;
maxcols = 0;
result = 0LL;
memset(pic, 0, 0xEF0uLL);
pic[956] = 0;
return result;
}

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

sprintf(tmpstr, "%c*t%dR%c*r0A", 27LL, (unsigned int)pro_la50_dpi, 27LL);
func5(tmpstr);
colrcnt = 0;
rowrcnt = 0;
col = 0;
maxcols = 0;
result = 0LL;
memset(pic, 0, 0xEF0uLL);
pic[956] = 0;
return result;
}

original_code:
void start_pcl()
{
 sprintf(tmpstr, "%c*t%dR%c*r0A", 0x1b, pro_la50_dpi, 0x1b);
 ptr_fifo_printf(tmpstr);
 colrcnt = 0;
 rowrcnt = 0;
 col = 0;
 maxcols = 0;
 memset(pic, 0, 6*(((85*600/10)+7)/8));
}


decompiled_code:
__int64 end_pcl()
{
sprintf(tmpstr, "%c*rB", 27LL);
return ptr_fifo_printf(tmpstr);
}

canonical_decompiled_code:
__int64 func10()
{
sprintf(tmpstr, "%c*rB", 27LL);
return func5(tmpstr);
}

original_code:
void end_pcl()
{
 sprintf(tmpstr, "%c*rB", 0x1b);
 ptr_fifo_printf(tmpstr);
}


original_code:
void output_pcl()
{
int ocol8, ocolmax, orow;
int ipos, opos, pix;
int rep, res;
unsigned char oline[(((85*600/10)+7)/8)];
int colrep[2][2] = {{1, 2}, {3, 3}};
int rowrep[2][4] = {{4, 4, 4, 3}, {8, 7, 8, 7}};
 if (pro_la50_dpi == 300)
   res = 0;
 else
   res = 1;
 for(orow=0; orow<6; orow++)
 {
   opos = 0;
   memset(oline, 0, (((85*600/10)+7)/8));
   for(ipos=0; ipos<(85*600/10); ipos++)
   {
     pix = (pic[orow][ipos/8] >> (7-(ipos%8))) & 1;
     for(rep=0; rep<colrep[res][colrcnt]; rep++)
     {
       if (opos<maxpos)
         oline[opos/8] |= pix << (7-(opos%8));
       opos++;
     }
     colrcnt++;
     if (colrcnt == 2)
       colrcnt = 0;
   }
   for(ocolmax=(((85*600/10)+7)/8)-1; ocolmax>0; ocolmax--)
     if (oline[ocolmax] != 0)
       break;
   ocolmax++;
   for(rep=0; rep<rowrep[res][rowrcnt]; rep++)
   {
       sprintf(tmpstr, "%c*b%dW", 0x1b, ocolmax);
     ptr_fifo_printf(tmpstr);
       for(ocol8=0; ocol8<ocolmax; ocol8++)
       ptr_fifo_put((int)oline[ocol8]);
   }
   rowrcnt++;
   if (rowrcnt == 4)
     rowrcnt = 0;
 }
}

canonical_original_code:
void output_pcl()
{
int ocol8; int ocolmax; int orow;
int ipos; int opos; int pix;
int rep; int res;
unsigned char oline[-1];
int colrep[2][2] = {{1, 2}, {3, 3}};
int rowrep[2][4] = {{4, 4, 4, 3}, {8, 7, 8, 7}};
 if (pro_la50_dpi == 300)
   res = 0;
 else
   res = 1;
 for(orow=0; orow<6; orow++)
 {
   opos = 0;
   memset(oline, 0, (((85*600/10)+7)/8));
   for(ipos=0; ipos<(85*600/10); ipos++)
   {
     pix = (pic[orow][ipos/8] >> (7-(ipos%8))) & 1;
     for(rep=0; rep<colrep[res][colrcnt]; rep++)
     {
       if (opos<maxpos)
         oline[opos/8] |= pix << (7-(opos%8));
       opos++;
     }
     colrcnt++;
     if (colrcnt == 2)
       colrcnt = 0;
   }
   for(ocolmax=(((85*600/10)+7)/8)-1; ocolmax>0; ocolmax--)
     if (oline[ocolmax] != 0)
       break;
   ocolmax++;
   for(rep=0; rep<rowrep[res][rowrcnt]; rep++)
   {
       sprintf(tmpstr, "%c*b%dW", 0x1b, ocolmax);
     ptr_fifo_printf(tmpstr);
       for(ocol8=0; ocol8<ocolmax; ocol8++)
       ptr_fifo_put((int)oline[ocol8]);
   }
   rowrcnt++;
   if (rowrcnt == 4)
     rowrcnt = 0;
 }
}

variable_types: ocolmax int

variable_types: orow int

variable_types: ipos int

variable_types: opos int

variable_types: pix int

variable_types: rep int

variable_types: res int

variable_types:
oline
unsigned char [-1]

variable_types:
colrep
int [2][2]

variable_types:
rowrep
int [2][4]


decompiled_code:
void __fastcall plot_six(int a1, int a2)
{
int v3; // edi
int v4; // esi
int v5; // er8
int v6; // er9
_BYTE *v7; // rdx
int i; // ebx

v3 = a1 - 63;
v4 = col;
v5 = col + a2;
if ( col >= v5 )
{
LABEL_12:
col = v5;
}
else
{
v6 = maxcols;
while ( v4 > 5099 )
{
if ( ++v4 == v5 )
goto LABEL_12;
}
LABEL_6:
v7 = (char *)pic + v4 / 8;
for ( i = 0; i != 6; ++i )
{
*v7 |= ((v3 >> i) & 1) << (7 - v4 % 8);
v7 += 638;
}
++v6;
while ( ++v4 != v5 )
{
if ( v4 <= 5099 )
goto LABEL_6;
}
maxcols = v6;
col = v5;
}
}

original_code:
void plot_six(int c, int rep)
{
int sixel, prow, pcol, pcolb, pcolb_r;
 sixel = c - 0x3f;
 for(pcol=col; pcol<(col+rep); pcol++)
 {
   if (pcol < (85*600/10))
   {
     pcolb = pcol / 8;
     pcolb_r = pcol % 8;
     for(prow=0; prow<6; prow++)
     {
       pic[prow][pcolb] |= ((sixel >> prow) & 1) << (7-pcolb_r);
     }
     maxcols++;
   }
 }
 col += rep;
}

canonical_original_code:
void plot_six(int c, int rep)
{
int sixel; int prow; int pcol; int pcolb; int pcolb_r;
 sixel = c - 0x3f;
 for(pcol=col; pcol<(col+rep); pcol++)
 {
   if (pcol < (85*600/10))
   {
     pcolb = pcol / 8;
     pcolb_r = pcol % 8;
     for(prow=0; prow<6; prow++)
     {
       pic[prow][pcolb] |= ((sixel >> prow) & 1) << (7-pcolb_r);
     }
     maxcols++;
   }
 }
 col += rep;
}

variable_types: sixel int

variable_types: prow int

variable_types: pcol int

variable_types: pcolb int


decompiled_code:
void __fastcall six_filter(int a1)
{
switch ( state )
{
case 0:
if ( a1 == 27 )
state = 1;
else
ptr_fifo_put(a1);
return;
case 1:
if ( a1 > 31 )
{
esc_cmd = a1;
state = 2;
}
else
{
state = 0;
}
return;
case 2:
if ( (a1 & 0xFFFFFFDF) - 65 <= 0x19 || a1 == 60 || a1 == 125 )
{
if ( a1 == 113 && esc_cmd == 80 )
{
start_pcl();
state = 3;
}
else
{
state = 0;
}
}
return;
case 3:
if ( (unsigned int)(a1 - 63) <= 0x3F )
{
plot_six(a1, 1);
}
else
{
switch ( a1 )
{
case 27:
state = 4;
break;
case 33:
rpt = 0;
state = 5;
break;
case 45:
output_pcl();
col = 0;
maxcols = 0;
memset(pic, 0, 0xEF0uLL);
pic[956] = 0;
break;
case 36:
col = 0;
break;
case 26:
plot_six(63, 1);
break;
default:
goto LABEL_21;
}
}
return;
case 4:
LABEL_21:
end_pcl();
state = 0;
return;
case 5:
if ( a1 == 27 )
{
state = 4;
}
else
{
if ( (unsigned int)(a1 - 48) > 9 )
{
if ( a1 == 26 )
{
a1 = 63;
}
else if ( (unsigned int)(a1 - 63) > 0x3F )
{
LABEL_33:
state = 3;
return;
}
plot_six(a1, rpt);
goto LABEL_33;
}
rpt = a1 + 10 * rpt - 48;
}
return;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
switch ( state )
{
case 0:
if ( a1 == 27 )
state = 1;
else
func4(a1);
return;
case 1:
if ( a1 > 31 )
{
esc_cmd = a1;
state = 2;
}
else
{
state = 0;
}
return;
case 2:
if ( (a1 & 0xFFFFFFDF) - 65 <= 0x19 || a1 == 60 || a1 == 125 )
{
if ( a1 == 113 && esc_cmd == 80 )
{
func9();
state = 3;
}
else
{
state = 0;
}
}
return;
case 3:
if ( (unsigned int)(a1 - 63) <= 0x3F )
{
func12(a1, 1);
}
else
{
switch ( a1 )
{
case 27:
state = 4;
break;
case 33:
rpt = 0;
state = 5;
break;
case 45:
func11();
col = 0;
maxcols = 0;
memset(pic, 0, 0xEF0uLL);
pic[956] = 0;
break;
case 36:
col = 0;
break;
case 26:
func12(63, 1);
break;
default:
goto LABEL_21;
}
}
return;
case 4:
LABEL_21:
func10();
state = 0;
return;
case 5:
if ( a1 == 27 )
{
state = 4;
}
else
{
if ( (unsigned int)(a1 - 48) > 9 )
{
if ( a1 == 26 )
{
a1 = 63;
}
else if ( (unsigned int)(a1 - 63) > 0x3F )
{
LABEL_33:
state = 3;
return;
}
func12(a1, rpt);
goto LABEL_33;
}
rpt = a1 + 10 * rpt - 48;
}
return;
default:
return;
}
}

original_code:
void six_filter(int c)
{
 switch(state)
 {
   case 0:
     if (c == 0x1b)
       state = 1;
     else
       ptr_fifo_put(c);
     break;
   case 1:
     if (c < 32)
       state = 0;
     else
     {
       esc_cmd = c;
       state = 2;
     }
     break;
   case 2:
     if (((c >= (int)'A') && (c <= (int)'Z'))
        || ((c >= (int)'a') && (c <= (int)'z'))
        || (c == (int)'<') || (c == (int)'}'))
     {
       if ((c == (int)'q') && (esc_cmd == (int)'P'))
       {
         start_pcl();
         state = 3;
       }
       else
         state = 0;
     }
     break;
   case 3:
     if ((c>=0x3f) && (c<=0x7e))
     {
       plot_six(c, 1);
       break;
     }
     else if (c == 0x1b)
     {
       state = 4;
       break;
     }
     else if (c == 0x21)
     {
       rpt = 0;
       state = 5;
       break;
     }
     else if (c == 0x2d)
     {
       output_pcl();
       col = 0;
       maxcols = 0;
       memset(pic, 0, 6*(((85*600/10)+7)/8));
       break;
     }
     else if (c == 0x24)
     {
       col = 0;
       break;
     }
     else if (c == 0x1a)
     {
       plot_six(0x3f, 1);
       break;
     }
   case 4:
     end_pcl();
     state = 0;
     break;
   case 5:
     if (c == 0x1b)
     {
       state = 4;
       break;
     }
     else if ((c>(int)'9') || (c<(int)'0'))
     {
       if (c == 0x1a)
         c = 0x3f;
       if ((c>=0x3f) && (c<=0x7e))
         plot_six(c, rpt);
       state = 3;
       break;
     }
     else
     {
       rpt = 10*rpt + c - (int)'0';
       break;
     }
 }
}

variable_types: c int


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

result = 0xFFFFFFFFLL;
if ( ptr_fifo_level <= 15311 )
{
six_filter(a2);
result = 1LL;
}
return result;
}

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

result = 0xFFFFFFFFLL;
if ( ptr_fifo_level <= 15311 )
{
func13(a2);
result = 1LL;
}
return result;
}

original_code:
int pro_la50_put (int dev, int schar)
{
int stat;
 if (ptr_fifo_level<((((85*600/10)+7)/8)*6*8)/2)
 {
   six_filter(schar);
   stat = 1;
 }
 else
   stat = -1;
 return stat;
}

canonical_original_code:
int pro_la50_put(int dev, int schar)
{
int stat;
 if (ptr_fifo_level<((((85*600/10)+7)/8)*6*8)/2)
 {
   six_filter(schar);
   stat = 1;
 }
 else
   stat = -1;
 return stat;
}

variable_types: dev int

variable_types: schar int

variable_types: stat int