decompiled_code:
__int64 __fastcall small_receive(_QWORD *a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax
_QWORD *v6; // rdx
_QWORD *v7; // rax
__int64 v9; // rdi
__int64 v10; // rdx
_QWORD *v11; // rax
_QWORD *v12; // rax
_QWORD *v13; // rax
__int64 v14; // rax
__int64 v15[5]; // [rsp+0h] [rbp-28h] BYREF

v3 = *a1;
result = -1LL;
v6 = (_QWORD *)(*a1 + 2LL);
if ( (unsigned __int64)v6 <= 0x41 && a2 <= 0x3F )
{
v7 = (_QWORD *)small_send_head;
if ( small_send_head )
{
v9 = 0LL;
while ( v7[1] != a2 || *v7 != v3 && v3 != -1 )
{
v6 = (_QWORD *)v7[3];
v9 = (__int64)v7;
if ( !v6 )
goto LABEL_21;
v7 = (_QWORD *)v7[3];
}
*a3 = v7[2];
if ( *a1 == -1LL )
*a1 = *v7;
v10 = v7[3];
if ( v9 )
{
*(_QWORD *)(v9 + 24) = v10;
v10 = v7[3];
}
else
{
small_send_head = v7[3];
}
if ( !v10 )
small_send_tail = v9;
v6 = (_QWORD *)*v7;
if ( *v7 == -2LL )
*v7 = 0LL;
else
*(_QWORD *)(*((_QWORD *)&proc + (_QWORD)v6) + 8LL) = 0LL;
goto LABEL_18;
}
LABEL_21:
v9 = small_receive_head;
v11 = (_QWORD *)small_receive_head;
if ( small_receive_head )
{
while ( 1 )
{
v6 = (_QWORD *)*v11;
if ( *(_QWORD *)*v11 == a2 && v3 == v11[1] )
break;
v11 = (_QWORD *)v11[3];
if ( !v11 )
goto LABEL_27;
}
}
else
{
LABEL_27:
v12 = (_QWORD *)big_send_head;
if ( big_send_head )
{
while ( 1 )
{
while ( v12[1] != a2 )
{
v12 = (_QWORD *)v12[3];
if ( !v12 )
goto LABEL_33;
}
if ( v3 == *v12 )
break;
v12 = (_QWORD *)v12[3];
if ( !v12 )
goto LABEL_33;
}
}
else
{
LABEL_33:
v13 = (_QWORD *)big_receive_head;
if ( !big_receive_head )
{
LABEL_39:
v15[0] = (__int64)a1;
v15[1] = a2;
v15[2] = (__int64)a3;
v15[3] = 0LL;
if ( small_receive_head )
{
v14 = small_receive_tail;
small_receive_tail = (__int64)v15;
*(_QWORD *)(v14 + 24) = v15;
}
else
{
small_receive_tail = (__int64)v15;
small_receive_head = (__int64)v15;
}
*(_QWORD *)(*((_QWORD *)&proc + a2) + 8LL) = 1LL;
LABEL_18:
schedule(v9, a2, v6, v3, a1);
return 1LL;
}
while ( 1 )
{
v6 = (_QWORD *)*v13;
if ( *(_QWORD *)*v13 == a2 && v3 == v13[1] )
break;
v13 = (_QWORD *)v13[3];
if ( !v13 )
goto LABEL_39;
}
}
}
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax
_QWORD *v6; // rdx
_QWORD *v7; // rax
__int64 v9; // rdi
__int64 v10; // rdx
_QWORD *v11; // rax
_QWORD *v12; // rax
_QWORD *v13; // rax
__int64 v14; // rax
__int64 v15[5]; // [rsp+0h] [rbp-28h] BYREF

v3 = *a1;
result = -1LL;
v6 = (_QWORD *)(*a1 + 2LL);
if ( (unsigned __int64)v6 <= 0x41 && a2 <= 0x3F )
{
v7 = (_QWORD *)small_send_head;
if ( small_send_head )
{
v9 = 0LL;
while ( v7[1] != a2 || *v7 != v3 && v3 != -1 )
{
v6 = (_QWORD *)v7[3];
v9 = (__int64)v7;
if ( !v6 )
goto LABEL_21;
v7 = (_QWORD *)v7[3];
}
*a3 = v7[2];
if ( *a1 == -1LL )
*a1 = *v7;
v10 = v7[3];
if ( v9 )
{
*(_QWORD *)(v9 + 24) = v10;
v10 = v7[3];
}
else
{
small_send_head = v7[3];
}
if ( !v10 )
small_send_tail = v9;
v6 = (_QWORD *)*v7;
if ( *v7 == -2LL )
*v7 = 0LL;
else
*(_QWORD *)(*((_QWORD *)&proc + (_QWORD)v6) + 8LL) = 0LL;
goto LABEL_18;
}
LABEL_21:
v9 = small_receive_head;
v11 = (_QWORD *)small_receive_head;
if ( small_receive_head )
{
while ( 1 )
{
v6 = (_QWORD *)*v11;
if ( *(_QWORD *)*v11 == a2 && v3 == v11[1] )
break;
v11 = (_QWORD *)v11[3];
if ( !v11 )
goto LABEL_27;
}
}
else
{
LABEL_27:
v12 = (_QWORD *)big_send_head;
if ( big_send_head )
{
while ( 1 )
{
while ( v12[1] != a2 )
{
v12 = (_QWORD *)v12[3];
if ( !v12 )
goto LABEL_33;
}
if ( v3 == *v12 )
break;
v12 = (_QWORD *)v12[3];
if ( !v12 )
goto LABEL_33;
}
}
else
{
LABEL_33:
v13 = (_QWORD *)big_receive_head;
if ( !big_receive_head )
{
LABEL_39:
v15[0] = (__int64)a1;
v15[1] = a2;
v15[2] = (__int64)a3;
v15[3] = 0LL;
if ( small_receive_head )
{
v14 = small_receive_tail;
small_receive_tail = (__int64)v15;
*(_QWORD *)(v14 + 24) = v15;
}
else
{
small_receive_tail = (__int64)v15;
small_receive_head = (__int64)v15;
}
*(_QWORD *)(*((_QWORD *)&proc + a2) + 8LL) = 1LL;
LABEL_18:
schedule(v9, a2, v6, v3, a1);
return 1LL;
}
while ( 1 )
{
v6 = (_QWORD *)*v13;
if ( *(_QWORD *)*v13 == a2 && v3 == v13[1] )
break;
v13 = (_QWORD *)v13[3];
if ( !v13 )
goto LABEL_39;
}
}
}
result = -1LL;
}
return result;
}

original_code:
long small_receive(long * src, long dest, long * msg)
{
  struct msg_struct * msg_p = small_send_head;
  struct msg_struct * msg_t = ((void *) 0);
  if((*src<0 && *src!=-1 && *src!=-2) || *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)
    {
      *msg = msg_p->msg;
      if(*src == -1)
 *src = msg_p->src;
      if(!msg_t)
        small_send_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        small_send_tail = msg_t;
      if(msg_p->src == -2)
        msg_p->src = 0;
      else
        proc[msg_p->src]->state = 0;
      schedule();
      return 1;
    }
  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_send_head;
  while(msg_p)
    {
      if(dest==msg_p->dest && *src==msg_p->src)
 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 = (long)msg;
  msg_p->next = ((void *) 0);
  if(!small_receive_head)
    small_receive_head = small_receive_tail = msg_p;
  else
    {
      small_receive_tail->next = msg_p;
      small_receive_tail = msg_p;
    }
  proc[dest]->state = 1;
  schedule();
  return 1;
}

canonical_original_code:
long small_receive(long *src, long dest, long *msg)
{
  struct msg_struct *msg_p = small_send_head;
  struct msg_struct *msg_t = ((void *) 0);
  if((*src<0 && *src!=-1 && *src!=-2) || *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)
    {
      *msg = msg_p->msg;
      if(*src == -1)
 *src = msg_p->src;
      if(!msg_t)
        small_send_head = msg_p->next;
      else
        msg_t->next = msg_p->next;
      if(!msg_p->next)
        small_send_tail = msg_t;
      if(msg_p->src == -2)
        msg_p->src = 0;
      else
        proc[msg_p->src]->state = 0;
      schedule();
      return 1;
    }
  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_send_head;
  while(msg_p)
    {
      if(dest==msg_p->dest && *src==msg_p->src)
 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 = (long)msg;
  msg_p->next = ((void *) 0);
  if(!small_receive_head)
    small_receive_head = small_receive_tail = msg_p;
  else
    {
      small_receive_tail->next = msg_p;
      small_receive_tail = msg_p;
    }
  proc[dest]->state = 1;
  schedule();
  return 1;
}

variable_types:
src
long *

variable_types: dest long

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


repo: Cassidy/mks

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

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


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

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


decompiled_code:
__int64 __fastcall do_intr_msg(__int64 a1, __int64 *a2, __int64 *a3, __int64 a4)
{
__int64 v4; // r9
unsigned __int64 v6; // rsi
__int64 result; // rax
__int64 *v8; // rdi
__int64 v9[2]; // [rsp+0h] [rbp-10h] BYREF

v4 = *(_QWORD *)(proc_current + 72LL);
if ( *a2 == v4 )
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:
v8 = *(__int64 **)(proc_current + 72LL);
v9[0] = (*a3 & 0xFFFFF000LL) + (v4 << 26) + 4096;
result = big_send(v8, a2, v9, a4, (__int64)a2);
break;
case 4LL:
v6 = *(_QWORD *)(proc_current + 72LL);
v9[0] = (*a3 & 0xFFFFF000LL) + (v4 << 26) + 4096;
result = big_receive(a2, v6, v9, a4, (__int64)a2);
break;
default:
result = -1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 *a2, __int64 *a3, __int64 a4)
{
__int64 v4; // r9
unsigned __int64 v6; // rsi
__int64 result; // rax
__int64 *v8; // rdi
__int64 v9[2]; // [rsp+0h] [rbp-10h] BYREF

v4 = *(_QWORD *)(proc_current + 72LL);
if ( *a2 == v4 )
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:
v8 = *(__int64 **)(proc_current + 72LL);
v9[0] = (*a3 & 0xFFFFF000LL) + (v4 << 26) + 4096;
result = func3(v8, a2, v9, a4, (__int64)a2);
break;
case 4LL:
v6 = *(_QWORD *)(proc_current + 72LL);
v9[0] = (*a3 & 0xFFFFF000LL) + (v4 << 26) + 4096;
result = func4(a2, v6, v9, a4, (__int64)a2);
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


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 v5; // rdx

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

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

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


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

variable_types: src long


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; // er12
int v3; // edx

switch ( a1 & 0x3FFFFE )
{
case 0x3FF800:
return 257;
case 0x3FF804:
return (unsigned int)pro_rd_ep;
case 0x3FF806:
return (unsigned int)pro_rd_sec;
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 )
{
pro_rd_s2c &= 0xFFFFF7FF;
LOBYTE(v3) = pro_rd_status & 0x7F;
pro_rd_status = v3;
pro_rd_inta();
}
else
{
pro_rd_secbuf_ptr += 2;
pro_rd_intb();
}
}
return v1;
case 0x3FF80A:
return (unsigned int)pro_rd_cyl;
case 0x3FF80C:
return (unsigned int)pro_rd_head;
case 0x3FF80E:
pro_rd_status &= 0xFFFFFFFE;
return (unsigned int)pro_rd_s2c;
case 0x3FF810:
return (unsigned int)pro_rd_status;
default:
return 0;
}
}

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

switch ( a1 & 0x3FFFFE )
{
case 0x3FF800:
return 257;
case 0x3FF804:
return (unsigned int)pro_rd_ep;
case 0x3FF806:
return (unsigned int)pro_rd_sec;
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 )
{
pro_rd_s2c &= 0xFFFFF7FF;
LOBYTE(v3) = pro_rd_status & 0x7F;
pro_rd_status = v3;
func1();
}
else
{
pro_rd_secbuf_ptr += 2;
func0();
}
}
return v1;
case 0x3FF80A:
return (unsigned int)pro_rd_cyl;
case 0x3FF80C:
return (unsigned int)pro_rd_head;
case 0x3FF80E:
pro_rd_status &= 0xFFFFFFFE;
return (unsigned int)pro_rd_s2c;
case 0x3FF810:
return (unsigned int)pro_rd_status;
default:
return 0;
}
}

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(__int16 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rcx
__int64 v9; // rdx
unsigned __int64 v10; // rdi
int v11; // eax
FILE **v12; // rbx
int v13; // eax
int v14; // ecx
int v15; // ebx
FILE **v16; // rbx
int v17; // edi

switch ( a2 & 0x3FFFFE )
{
case 0x3FF804:
LOBYTE(pro_rd_ep) = a1;
return;
case 0x3FF806:
pro_rd_sec = pro_rd_sec & 0xFFFF00E0 | a1 & 0xFF1F;
return;
case 0x3FF808:
v13 = pro_rd_status;
if ( (pro_rd_status & 0x80u) == 0 )
return;
v14 = pro_rd_secbuf_ptr;
PRO_RD_SECBUF[pro_rd_secbuf_ptr] = a1;
PRO_RD_SECBUF[v14 + 1] = HIBYTE(a1);
if ( v14 > 509 )
{
v9 = (unsigned int)pro_rd_s2c;
v10 = (unsigned int)pro_rd_head;
v8 = (unsigned int)pro_rd_cyl;
v7 = (unsigned __int8)pro_rd_s2c;
if ( (_BYTE)pro_rd_s2c == 48 )
{
v16 = (FILE **)PRO_RD_SECBUF;
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9,
0);
do
{
v17 = *(unsigned __int8 *)v16;
v16 = (FILE **)((char *)v16 + 2);
putc(v17, pro_rd_fptr);
v7 = (__int64)pro_rd_fptr;
putc(*((unsigned __int8 *)v16 - 1), pro_rd_fptr);
}
while ( &pro_rd_fptr != v16 );
}
else
{
if ( (unsigned __int8)pro_rd_s2c != 80 )
{
LABEL_23:
LOBYTE(v13) = v13 & 0x7F;
BYTE1(v9) &= 0xF7u;
pro_rd_status = v13;
pro_rd_s2c = v9;
goto LABEL_24;
}
v15 = 0;
v7 = (pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9;
fseek(pro_rd_fptr, v7, 0);
if ( pro_rd_secs > 0 )
{
do
{
v7 = (__int64)pro_rd_fptr;
++v15;
putc((unsigned __int8)byte_99F, pro_rd_fptr);
}
while ( pro_rd_secs << 9 > v15 );
}
}
v10 = (unsigned __int64)pro_rd_fptr;
fflush(pro_rd_fptr);
v13 = pro_rd_status;
v9 = (unsigned int)pro_rd_s2c;
goto LABEL_23;
}
pro_rd_secbuf_ptr = v14 + 2;
goto LABEL_30;
case 0x3FF80A:
pro_rd_cyl = pro_rd_cyl & 0xFFFFFC00 | a1 & 0x3FF;
return;
case 0x3FF80C:
pro_rd_head = pro_rd_head & 0xFFFFFFF8 | a1 & 7;
return;
case 0x3FF80E:
v6 = pro_rd_s2c;
pro_rd_ep &= 0xFFFF00FF;
pro_rd_status &= 0xFFFFFF7E;
v7 = (unsigned int)pro_rd_head;
LOBYTE(v6) = 0;
v8 = (unsigned int)pro_rd_cyl;
a5 = (unsigned __int8)pro_rd_sec;
v9 = (unsigned int)pro_rd_heads;
a6 = (unsigned int)pro_rd_secs;
v11 = v6 | (unsigned __int8)a1;
v10 = (unsigned __int8)v11;
BYTE1(v11) &= 0xF6u;
pro_rd_s2c = v11;
if ( (unsigned __int8)v11 == 48 )
{
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl || pro_rd_secs <= (unsigned __int8)pro_rd_sec )
goto LABEL_28;
}
else
{
if ( (unsigned __int8)v11 <= 0x30u )
{
if ( (unsigned __int8)v11 == 16 )
{
LABEL_24:
pro_rd_inta(v10, v7, v9, v8, a5, a6);
return;
}
if ( (unsigned __int8)v11 == 32 )
{
if ( pro_rd_heads > pro_rd_head && pro_rd_cyls > pro_rd_cyl && pro_rd_secs > (unsigned __int8)pro_rd_sec )
{
v12 = (FILE **)PRO_RD_SECBUF;
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_cyl * pro_rd_heads + pro_rd_head)) << 9,
0);
do
{
v12 = (FILE **)((char *)v12 + 1);
*((_BYTE *)v12 - 1) = getc(pro_rd_fptr);
}
while ( v12 != &pro_rd_fptr );
pro_rd_secbuf_ptr = 0;
pro_rd_sched();
return;
}
LABEL_28:
pro_rd_error(
(unsigned __int8)v11,
(unsigned int)pro_rd_head,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_cyl,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
LABEL_37:
puts("RD illegal command\r");
return;
}
if ( (unsigned __int8)v11 != 80 )
goto LABEL_37;
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl )
goto LABEL_28;
}
pro_rd_secbuf_ptr = 0;
LABEL_30:
pro_rd_intb();
return;
default:
return;
}
}

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

switch ( a2 & 0x3FFFFE )
{
case 0x3FF804:
LOBYTE(pro_rd_ep) = a1;
return;
case 0x3FF806:
pro_rd_sec = pro_rd_sec & 0xFFFF00E0 | a1 & 0xFF1F;
return;
case 0x3FF808:
v13 = pro_rd_status;
if ( (pro_rd_status & 0x80u) == 0 )
return;
v14 = pro_rd_secbuf_ptr;
PRO_RD_SECBUF[pro_rd_secbuf_ptr] = a1;
PRO_RD_SECBUF[v14 + 1] = HIBYTE(a1);
if ( v14 > 509 )
{
v9 = (unsigned int)pro_rd_s2c;
v10 = (unsigned int)pro_rd_head;
v8 = (unsigned int)pro_rd_cyl;
v7 = (unsigned __int8)pro_rd_s2c;
if ( (_BYTE)pro_rd_s2c == 48 )
{
v16 = (FILE **)PRO_RD_SECBUF;
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9,
0);
do
{
v17 = *(unsigned __int8 *)v16;
v16 = (FILE **)((char *)v16 + 2);
putc(v17, pro_rd_fptr);
v7 = (__int64)pro_rd_fptr;
putc(*((unsigned __int8 *)v16 - 1), pro_rd_fptr);
}
while ( &pro_rd_fptr != v16 );
}
else
{
if ( (unsigned __int8)pro_rd_s2c != 80 )
{
LABEL_23:
LOBYTE(v13) = v13 & 0x7F;
BYTE1(v9) &= 0xF7u;
pro_rd_status = v13;
pro_rd_s2c = v9;
goto LABEL_24;
}
v15 = 0;
v7 = (pro_rd_secs * (pro_rd_head + pro_rd_heads * pro_rd_cyl)) << 9;
fseek(pro_rd_fptr, v7, 0);
if ( pro_rd_secs > 0 )
{
do
{
v7 = (__int64)pro_rd_fptr;
++v15;
putc((unsigned __int8)byte_99F, pro_rd_fptr);
}
while ( pro_rd_secs << 9 > v15 );
}
}
v10 = (unsigned __int64)pro_rd_fptr;
fflush(pro_rd_fptr);
v13 = pro_rd_status;
v9 = (unsigned int)pro_rd_s2c;
goto LABEL_23;
}
pro_rd_secbuf_ptr = v14 + 2;
goto LABEL_30;
case 0x3FF80A:
pro_rd_cyl = pro_rd_cyl & 0xFFFFFC00 | a1 & 0x3FF;
return;
case 0x3FF80C:
pro_rd_head = pro_rd_head & 0xFFFFFFF8 | a1 & 7;
return;
case 0x3FF80E:
v6 = pro_rd_s2c;
pro_rd_ep &= 0xFFFF00FF;
pro_rd_status &= 0xFFFFFF7E;
v7 = (unsigned int)pro_rd_head;
LOBYTE(v6) = 0;
v8 = (unsigned int)pro_rd_cyl;
a5 = (unsigned __int8)pro_rd_sec;
v9 = (unsigned int)pro_rd_heads;
a6 = (unsigned int)pro_rd_secs;
v11 = v6 | (unsigned __int8)a1;
v10 = (unsigned __int8)v11;
BYTE1(v11) &= 0xF6u;
pro_rd_s2c = v11;
if ( (unsigned __int8)v11 == 48 )
{
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl || pro_rd_secs <= (unsigned __int8)pro_rd_sec )
goto LABEL_28;
}
else
{
if ( (unsigned __int8)v11 <= 0x30u )
{
if ( (unsigned __int8)v11 == 16 )
{
LABEL_24:
func1(v10, v7, v9, v8, a5, a6);
return;
}
if ( (unsigned __int8)v11 == 32 )
{
if ( pro_rd_heads > pro_rd_head && pro_rd_cyls > pro_rd_cyl && pro_rd_secs > (unsigned __int8)pro_rd_sec )
{
v12 = (FILE **)PRO_RD_SECBUF;
fseek(
pro_rd_fptr,
((unsigned __int8)pro_rd_sec + pro_rd_secs * (pro_rd_cyl * pro_rd_heads + pro_rd_head)) << 9,
0);
do
{
v12 = (FILE **)((char *)v12 + 1);
*((_BYTE *)v12 - 1) = getc(pro_rd_fptr);
}
while ( v12 != &pro_rd_fptr );
pro_rd_secbuf_ptr = 0;
func3();
return;
}
LABEL_28:
func2(
(unsigned __int8)v11,
(unsigned int)pro_rd_head,
(unsigned int)pro_rd_heads,
(unsigned int)pro_rd_cyl,
(unsigned __int8)pro_rd_sec,
(unsigned int)pro_rd_secs);
return;
}
LABEL_37:
puts("RD illegal command\r");
return;
}
if ( (unsigned __int8)v11 != 80 )
goto LABEL_37;
if ( pro_rd_heads <= pro_rd_head || pro_rd_cyls <= pro_rd_cyl )
goto LABEL_28;
}
pro_rd_secbuf_ptr = 0;
LABEL_30:
func0();
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()
{
char *v0; // r13
size_t v1; // rax
const char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
void *v5; // rbp
int *v6; // rdx
int v7; // ecx
int v8; // esi
int v9; // edi
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v0 = pro_rd_dir;
v1 = strlen(pro_rd_dir);
v2 = pro_rd_file;
v3 = v1;
v4 = strlen(pro_rd_file);
v5 = malloc(v3 + v4 + 1);
memcpy(v5, v0, v3);
strcpy((char *)v5 + v3, v2);
memset(PRO_RD_SECBUF, 0, 0x200uLL);
if ( pro_rd_fptr )
fclose(pro_rd_fptr);
pro_rd_fptr = fopen((const char *)v5, "r+");
if ( !pro_rd_fptr )
{
printf("Unable to open rd image %s\n", (const char *)v5);
goto LABEL_13;
}
stat((const char *)v5, &v10);
if ( pro_rd_secs | pro_rd_cyls | pro_rd_heads )
{
if ( (pro_rd_secs * pro_rd_cyls * pro_rd_heads) << 9 == LODWORD(v10.st_size) )
goto LABEL_11;
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,
v10.st_size);
fclose(pro_rd_fptr);
LABEL_13:
pro_rd_heads = 0;
pro_rd_cyls = 0;
pro_rd_secs = 0;
goto LABEL_11;
}
v6 = (int *)&unk_AAC;
v7 = 16;
v8 = 615;
v9 = 4;
while ( (v7 * v8 * v9) << 9 != LODWORD(v10.st_size) )
{
if ( v6 == (int *)"RD illegal command\r" )
{
printf("Unable to determine rd geometry for filesize %d bytes\n", LODWORD(v10.st_size));
fclose(pro_rd_fptr);
goto LABEL_13;
}
v9 = *v6;
v8 = v6[1];
v6 += 3;
v7 = *(v6 - 1);
}
pro_rd_heads = v9;
pro_rd_cyls = v8;
pro_rd_secs = v7;
LABEL_11:
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(v5);
}

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

v0 = pro_rd_dir;
v1 = strlen(pro_rd_dir);
v2 = pro_rd_file;
v3 = v1;
v4 = strlen(pro_rd_file);
v5 = malloc(v3 + v4 + 1);
memcpy(v5, v0, v3);
strcpy((char *)v5 + v3, v2);
memset(PRO_RD_SECBUF, 0, 0x200uLL);
if ( pro_rd_fptr )
fclose(pro_rd_fptr);
pro_rd_fptr = fopen((const char *)v5, "r+");
if ( !pro_rd_fptr )
{
printf("Unable to open rd image %s\n", (const char *)v5);
goto LABEL_13;
}
stat((const char *)v5, &v10);
if ( pro_rd_secs | pro_rd_cyls | pro_rd_heads )
{
if ( (pro_rd_secs * pro_rd_cyls * pro_rd_heads) << 9 == LODWORD(v10.st_size) )
goto LABEL_11;
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,
v10.st_size);
fclose(pro_rd_fptr);
LABEL_13:
pro_rd_heads = 0;
pro_rd_cyls = 0;
pro_rd_secs = 0;
goto LABEL_11;
}
v6 = (int *)&unk_AAC;
v7 = 16;
v8 = 615;
v9 = 4;
while ( (v7 * v8 * v9) << 9 != LODWORD(v10.st_size) )
{
if ( v6 == (int *)"RD illegal command\r" )
{
printf("Unable to determine rd geometry for filesize %d bytes\n", LODWORD(v10.st_size));
fclose(pro_rd_fptr);
goto LABEL_13;
}
v9 = *v6;
v8 = v6[1];
v6 += 3;
v7 = *(v6 - 1);
}
pro_rd_heads = v9;
pro_rd_cyls = v8;
pro_rd_secs = v7;
LABEL_11:
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(v5);
}

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)
{
__int64 result; // rax
int v3; // edi

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

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

result = 255LL;
v3 = (unsigned __int8)(a1 & ~a2);
if ( v3 )
{
result = 0LL;
do
{
if ( (v3 & 1) != 0 )
break;
result = (unsigned int)(result + 1);
v3 >>= 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 i; // rdx
__int64 v1; // rdx
int v2; // ecx
int v3; // er9
int v4; // eax
__int64 result; // rax

for ( i = 0LL; i != 16; i = v1 + 4 )
{
if ( (unsigned int)pro_int_check(*(_DWORD *)((char *)&pro_int_irr + i), *(int *)((char *)&pro_int_imr + i)) != 255 )
{
v4 = *(_DWORD *)((char *)&pro_int_mode + v1);
if ( (v4 & 0x80u) != 0 && (v4 & 4) == 0 )
v2 = v3;
}
}
result = int_req & 0xEFFFFFFF;
if ( v2 == 1 )
result = int_req | 0x10000000u;
int_req = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rdx
__int64 v1; // rdx
int v2; // ecx
int v3; // er9
int v4; // eax
__int64 result; // rax

for ( i = 0LL; i != 16; i = v1 + 4 )
{
if ( (unsigned int)func0(*(_DWORD *)((char *)&pro_int_irr + i), *(int *)((char *)&pro_int_imr + i)) != 255 )
{
v4 = *(_DWORD *)((char *)&pro_int_mode + v1);
if ( (v4 & 0x80u) != 0 && (v4 & 4) == 0 )
v2 = v3;
}
}
result = int_req & 0xEFFFFFFF;
if ( v2 == 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; // eax
int v2; // eax
__int64 v3; // rdx
int v4; // edx
int v5; // ecx
__int64 result; // rax
int v7; // edx

v1 = (a1 >> 2) & 3;
if ( (a1 & 2) != 0 )
{
v2 = pro_int_check(*((_DWORD *)&pro_int_irr + v1), pro_int_imr[v1]);
v4 = *((_DWORD *)&pro_int_mode + v3);
v5 = v2;
if ( v2 == 255 )
v5 = 128;
result = v5 | (v4 >> 4) & 8 | (4 * (_BYTE)v4) & 0x10 | (32 * (_BYTE)v4) & 0x20u;
}
else
{
v7 = (*((int *)&pro_int_mode + v1) >> 5) & 3;
switch ( v7 )
{
case 2:
result = *((unsigned int *)&pro_int_irr + v1);
break;
case 3:
result = *((unsigned int *)&pro_int_acr + v1);
break;
case 1:
result = (unsigned int)pro_int_imr[v1];
break;
default:
result = *((unsigned int *)&pro_int_isr + v1);
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax
int v2; // eax
__int64 v3; // rdx
int v4; // edx
int v5; // ecx
__int64 result; // rax
int v7; // edx

v1 = (a1 >> 2) & 3;
if ( (a1 & 2) != 0 )
{
v2 = func0(*((_DWORD *)&pro_int_irr + v1), pro_int_imr[v1]);
v4 = *((_DWORD *)&pro_int_mode + v3);
v5 = v2;
if ( v2 == 255 )
v5 = 128;
result = v5 | (v4 >> 4) & 8 | (4 * (_BYTE)v4) & 0x10 | (32 * (_BYTE)v4) & 0x20u;
}
else
{
v7 = (*((int *)&pro_int_mode + v1) >> 5) & 3;
switch ( v7 )
{
case 2:
result = *((unsigned int *)&pro_int_irr + v1);
break;
case 3:
result = *((unsigned int *)&pro_int_acr + v1);
break;
case 1:
result = (unsigned int)pro_int_imr[v1];
break;
default:
result = *((unsigned int *)&pro_int_isr + v1);
break;
}
}
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
char v4; // cl
int v5; // edi
int v6; // edx
int v7; // ecx
int v8; // edx

LODWORD(v2) = (a2 >> 2) & 3;
if ( (a2 & 2) != 0 )
{
if ( (_BYTE)a1 )
{
if ( (a1 & 0xF8u) > 0xC8 )
{
if ( (a1 & 0xF8) == 224 )
{
*((_DWORD *)&pro_int_presel + (int)v2) = 2;
*((_DWORD *)&pro_int_presel_vec + (int)v2) = a1 & 7;
}
}
else if ( (a1 & 0xF8u) > 0xF )
{
switch ( a1 & 0xF8 )
{
case 0x10:
*((_DWORD *)&pro_int_irr + (int)v2) = 0;
pro_int_imr[(int)v2] = 0;
LODWORD(v2) = pro_int_update();
break;
case 0x18:
v8 = __ROL4__(-2, a1 & 7);
*((_DWORD *)&pro_int_irr + (int)v2) &= v8;
pro_int_imr[(int)v2] &= v8;
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:
*((_DWORD *)&pro_int_irr + (int)v2) = 0;
LODWORD(v2) = pro_int_update();
break;
case 0x48:
*((_DWORD *)&pro_int_irr + (int)v2) &= __ROL4__(-2, a1 & 7);
LODWORD(v2) = pro_int_update();
break;
case 0x50:
*((_DWORD *)&pro_int_irr + (int)v2) = 255;
LODWORD(v2) = pro_int_update();
break;
case 0x58:
*((_DWORD *)&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:
*((_DWORD *)&pro_int_isr + (int)v2) = 0;
break;
case 0x78:
*((_DWORD *)&pro_int_isr + (int)v2) &= __ROL4__(-2, a1 & 7);
break;
case 0x80:
case 0x88:
case 0x90:
case 0x98:
*((_DWORD *)&pro_int_mode + (int)v2) = *((_DWORD *)&pro_int_mode + (int)v2) & 0xE0 | a1 & 0x1F;
LODWORD(v2) = pro_int_update();
break;
case 0xA0:
case 0xA8:
v4 = 8 * a1;
v5 = a1 & 3;
v6 = v4 & 0x60 | *((_DWORD *)&pro_int_mode + (int)v2) & 0x9F;
if ( v5 == 1 )
{
LOBYTE(v6) = v6 | 0x80;
*((_DWORD *)&pro_int_mode + (int)v2) = v6;
}
else
{
v7 = v4 & 0x60 | *((_DWORD *)&pro_int_mode + (int)v2) & 0x9F;
if ( v5 == 2 )
{
LOBYTE(v7) = v6 & 0x7F;
v6 = v7;
}
*((_DWORD *)&pro_int_mode + (int)v2) = v6;
}
LODWORD(v2) = pro_int_update();
break;
case 0xB0:
case 0xB8:
*((_DWORD *)&pro_int_presel + (int)v2) = 0;
break;
case 0xC0:
case 0xC8:
*((_DWORD *)&pro_int_presel + (int)v2) = 1;
break;
default:
return v2;
}
}
}
else
{
*((_DWORD *)&pro_int_presel + (int)v2) = 0;
*((_DWORD *)&pro_int_irr + (int)v2) = 0;
*((_DWORD *)&pro_int_isr + (int)v2) = 0;
pro_int_imr[(int)v2] = 255;
*((_DWORD *)&pro_int_acr + (int)v2) = 0;
*((_DWORD *)&pro_int_mode + (int)v2) = 0;
LODWORD(v2) = pro_int_update();
}
}
else
{
v3 = *((_DWORD *)&pro_int_presel + (int)v2);
switch ( v3 )
{
case 1:
*((_DWORD *)&pro_int_acr + (int)v2) = a1;
break;
case 2:
v2 = *((int *)&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
char v4; // cl
int v5; // edi
int v6; // edx
int v7; // ecx
int v8; // edx

LODWORD(v2) = (a2 >> 2) & 3;
if ( (a2 & 2) != 0 )
{
if ( (_BYTE)a1 )
{
if ( (a1 & 0xF8u) > 0xC8 )
{
if ( (a1 & 0xF8) == 224 )
{
*((_DWORD *)&pro_int_presel + (int)v2) = 2;
*((_DWORD *)&pro_int_presel_vec + (int)v2) = a1 & 7;
}
}
else if ( (a1 & 0xF8u) > 0xF )
{
switch ( a1 & 0xF8 )
{
case 0x10:
*((_DWORD *)&pro_int_irr + (int)v2) = 0;
pro_int_imr[(int)v2] = 0;
LODWORD(v2) = func1();
break;
case 0x18:
v8 = __ROL4__(-2, a1 & 7);
*((_DWORD *)&pro_int_irr + (int)v2) &= v8;
pro_int_imr[(int)v2] &= v8;
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:
*((_DWORD *)&pro_int_irr + (int)v2) = 0;
LODWORD(v2) = func1();
break;
case 0x48:
*((_DWORD *)&pro_int_irr + (int)v2) &= __ROL4__(-2, a1 & 7);
LODWORD(v2) = func1();
break;
case 0x50:
*((_DWORD *)&pro_int_irr + (int)v2) = 255;
LODWORD(v2) = func1();
break;
case 0x58:
*((_DWORD *)&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:
*((_DWORD *)&pro_int_isr + (int)v2) = 0;
break;
case 0x78:
*((_DWORD *)&pro_int_isr + (int)v2) &= __ROL4__(-2, a1 & 7);
break;
case 0x80:
case 0x88:
case 0x90:
case 0x98:
*((_DWORD *)&pro_int_mode + (int)v2) = *((_DWORD *)&pro_int_mode + (int)v2) & 0xE0 | a1 & 0x1F;
LODWORD(v2) = func1();
break;
case 0xA0:
case 0xA8:
v4 = 8 * a1;
v5 = a1 & 3;
v6 = v4 & 0x60 | *((_DWORD *)&pro_int_mode + (int)v2) & 0x9F;
if ( v5 == 1 )
{
LOBYTE(v6) = v6 | 0x80;
*((_DWORD *)&pro_int_mode + (int)v2) = v6;
}
else
{
v7 = v4 & 0x60 | *((_DWORD *)&pro_int_mode + (int)v2) & 0x9F;
if ( v5 == 2 )
{
LOBYTE(v7) = v6 & 0x7F;
v6 = v7;
}
*((_DWORD *)&pro_int_mode + (int)v2) = v6;
}
LODWORD(v2) = func1();
break;
case 0xB0:
case 0xB8:
*((_DWORD *)&pro_int_presel + (int)v2) = 0;
break;
case 0xC0:
case 0xC8:
*((_DWORD *)&pro_int_presel + (int)v2) = 1;
break;
default:
return v2;
}
}
}
else
{
*((_DWORD *)&pro_int_presel + (int)v2) = 0;
*((_DWORD *)&pro_int_irr + (int)v2) = 0;
*((_DWORD *)&pro_int_isr + (int)v2) = 0;
pro_int_imr[(int)v2] = 255;
*((_DWORD *)&pro_int_acr + (int)v2) = 0;
*((_DWORD *)&pro_int_mode + (int)v2) = 0;
LODWORD(v2) = func1();
}
}
else
{
v3 = *((_DWORD *)&pro_int_presel + (int)v2);
switch ( v3 )
{
case 1:
*((_DWORD *)&pro_int_acr + (int)v2) = a1;
break;
case 2:
v2 = *((int *)&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 v0; // rdx
__int64 v1; // rdx
unsigned int v2; // ecx
__int64 v3; // r9
int v4; // er10
int v5; // eax
int v6; // edx
unsigned int v7; // er11

v0 = 0LL;
while ( 1 )
{
v2 = pro_int_check(*((_DWORD *)pro_int_irr + v0), pro_int_imr[v0]);
if ( v2 != 255 )
{
v5 = *((_DWORD *)&pro_int_mode + v1);
if ( (v5 & 0x80u) != 0 && (v5 & 4) == 0 )
break;
}
v0 = v1 + 1;
if ( v0 == 4 )
{
v4 = pro_int_irr[1];
v3 = 1LL;
break;
}
}
v6 = pro_int_acr[v3];
LODWORD(pro_int_irr[v3]) = ~(1 << v2) & v4;
if ( !_bittest(&v6, v2) )
LODWORD(pro_int_isr[v3]) |= 1 << v2;
pro_int_update();
return v7;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rdx
__int64 v1; // rdx
unsigned int v2; // ecx
__int64 v3; // r9
int v4; // er10
int v5; // eax
int v6; // edx
unsigned int v7; // er11

v0 = 0LL;
while ( 1 )
{
v2 = func0(*((_DWORD *)pro_int_irr + v0), pro_int_imr[v0]);
if ( v2 != 255 )
{
v5 = *((_DWORD *)&pro_int_mode + v1);
if ( (v5 & 0x80u) != 0 && (v5 & 4) == 0 )
break;
}
v0 = v1 + 1;
if ( v0 == 4 )
{
v4 = pro_int_irr[1];
v3 = 1LL;
break;
}
}
v6 = pro_int_acr[v3];
LODWORD(pro_int_irr[v3]) = ~(1 << v2) & v4;
if ( !_bittest(&v6, v2) )
LODWORD(pro_int_isr[v3]) |= 1 << v2;
func1();
return v7;
}

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)
{
*((_DWORD *)pro_int_irr + HIBYTE(a1)) |= (unsigned __int8)a1;
return pro_int_update();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1)
{
*((_DWORD *)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()
{
int *v0; // rdx
__int128 *v1; // rax

v0 = pro_int_imr;
v1 = (__int128 *)pro_int_vec;
pro_int_presel = 0LL;
pro_int_irr[0] = 0LL;
pro_int_isr[0] = 0LL;
do
{
*(_DWORD *)v1 = 0;
v1 += 2;
*v0++ = 255;
*((_DWORD *)v1 - 7) = 0;
*((_DWORD *)v1 - 6) = 0;
*((_DWORD *)v1 - 5) = 0;
*((_DWORD *)v1 - 4) = 0;
*((_DWORD *)v1 - 3) = 0;
*((_DWORD *)v1 - 2) = 0;
*((_DWORD *)v1 - 1) = 0;
}
while ( v1 != &pro_int_presel_vec );
pro_int_acr[0] = 0LL;
pro_int_mode = 0LL;
pro_int_presel_vec = 0LL;
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
bool v1; // zf

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

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

(*(void (__fastcall **)(__int64, __int128 *))(pro_ptr + 16LL))(1LL, &pro_2661ptr_ctrl);
v0 = pro_2661ptr_stat;
LOBYTE(v0) = pro_2661ptr_stat & 0x7F;
v1 = *((_DWORD *)&pro_2661ptr_ctrl + 7) == 1;
pro_2661ptr_stat = v0;
if ( v1 )
{
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 v0; // eax

if ( (pro_2661ptr_cmd & 0xC4) == 4 && (pro_2661ptr_stat & 2) == 0 )
{
v0 = ((__int64 (__fastcall *)(__int64))*pro_ptr)(1LL);
if ( v0 != 256 )
{
pro_2661ptr_stat |= 2u;
pro_2661ptr_data = v0;
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_stat |= 2u;
pro_2661ptr_data = pro_2661ptr_wdata;
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_stat |= 2u;
pro_2661ptr_data = pro_2661ptr_wdata;
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 )
{
pro_2661ptr_mode_ptr = 0;
result = (unsigned int)pro_2661ptr_mr2;
}
else
{
pro_2661ptr_mode_ptr = 1;
result = (unsigned int)pro_2661ptr_mr1;
}
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
{
result = (unsigned int)pro_2661ptr_cmd;
pro_2661ptr_mode_ptr = pro_2661ptr_mode_ptr == 0;
return result;
}
return 0LL;
}
if ( v1 )
{
if ( v1 == 2 )
{
pro_2661ptr_ctrl_get();
return (unsigned int)pro_2661ptr_stat;
}
return 0LL;
}
pro_2661ptr_stat &= 0xFFFFFFFD;
result = (unsigned int)pro_2661ptr_data;
}
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 )
{
pro_2661ptr_mode_ptr = 0;
result = (unsigned int)pro_2661ptr_mr2;
}
else
{
pro_2661ptr_mode_ptr = 1;
result = (unsigned int)pro_2661ptr_mr1;
}
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
{
result = (unsigned int)pro_2661ptr_cmd;
pro_2661ptr_mode_ptr = pro_2661ptr_mode_ptr == 0;
return result;
}
return 0LL;
}
if ( v1 )
{
if ( v1 == 2 )
{
func0();
return (unsigned int)pro_2661ptr_stat;
}
return 0LL;
}
pro_2661ptr_stat &= 0xFFFFFFFD;
result = (unsigned int)pro_2661ptr_data;
}
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; // ecx
unsigned int v6; // eax
unsigned int v7; // edx
int v8; // eax
unsigned int v9; // edx
int v10; // eax
int v11; // eax

result = a2 & 6;
if ( (_DWORD)result == 4 )
{
if ( pro_2661ptr_mode_ptr )
{
v11 = pro_2661ptr_mr2;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v11) = a1;
pro_2661ptr_mr2 = v11;
}
else
{
LOBYTE(v11) = 0;
pro_2661ptr_mr2 = v11 | a1;
}
pro_2661ptr_mode_ptr = 0;
result = pro_2661ptr_ctrl_put();
}
else
{
v10 = pro_2661ptr_mr1;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v10) = a1;
pro_2661ptr_mr1 = v10;
}
else
{
LOBYTE(v10) = 0;
pro_2661ptr_mr1 = v10 | a1;
}
pro_2661ptr_mode_ptr = 1;
result = pro_2661ptr_ctrl_put();
}
}
else if ( (_DWORD)result == 6 )
{
v5 = pro_2661ptr_cmd;
if ( a3 != 4 || (a2 & 1) == 0 )
{
LOBYTE(v5) = pro_2661ptr_cmd & 0x10;
v5 |= a1 & 0xEF;
}
v6 = pro_2661ptr_stat;
pro_2661ptr_cmd = v5;
if ( (v5 & 4) == 0 )
v6 = pro_2661ptr_stat & 0xFFFFFFFD;
v7 = v6;
v8 = v6 | 1;
v9 = v7 & 0xFFFFFFFE;
if ( (v5 & 1) == 0 )
v8 = v9;
pro_2661ptr_stat = v8;
result = pro_2661ptr_ctrl_put();
}
else if ( (a2 & 6) == 0 && (pro_2661ptr_cmd & 1) != 0 )
{
v4 = pro_2661ptr_wdata;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v4) = a1;
pro_2661ptr_wdata = v4;
}
else
{
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; // ecx
unsigned int v6; // eax
unsigned int v7; // edx
int v8; // eax
unsigned int v9; // edx
int v10; // eax
int v11; // eax

result = a2 & 6;
if ( (_DWORD)result == 4 )
{
if ( pro_2661ptr_mode_ptr )
{
v11 = pro_2661ptr_mr2;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v11) = a1;
pro_2661ptr_mr2 = v11;
}
else
{
LOBYTE(v11) = 0;
pro_2661ptr_mr2 = v11 | a1;
}
pro_2661ptr_mode_ptr = 0;
result = func1();
}
else
{
v10 = pro_2661ptr_mr1;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v10) = a1;
pro_2661ptr_mr1 = v10;
}
else
{
LOBYTE(v10) = 0;
pro_2661ptr_mr1 = v10 | a1;
}
pro_2661ptr_mode_ptr = 1;
result = func1();
}
}
else if ( (_DWORD)result == 6 )
{
v5 = pro_2661ptr_cmd;
if ( a3 != 4 || (a2 & 1) == 0 )
{
LOBYTE(v5) = pro_2661ptr_cmd & 0x10;
v5 |= a1 & 0xEF;
}
v6 = pro_2661ptr_stat;
pro_2661ptr_cmd = v5;
if ( (v5 & 4) == 0 )
v6 = pro_2661ptr_stat & 0xFFFFFFFD;
v7 = v6;
v8 = v6 | 1;
v9 = v7 & 0xFFFFFFFE;
if ( (v5 & 1) == 0 )
v8 = v9;
pro_2661ptr_stat = v8;
result = func1();
}
else if ( (a2 & 6) == 0 && (pro_2661ptr_cmd & 1) != 0 )
{
v4 = pro_2661ptr_wdata;
if ( a3 == 4 )
{
if ( (a2 & 1) == 0 )
LOBYTE(v4) = a1;
pro_2661ptr_wdata = v4;
}
else
{
LOBYTE(v4) = 0;
pro_2661ptr_wdata = v4 | a1;
}
pro_2661ptr_stat &= 0xFFFFFFFE;
result = pro_eq_sched(7LL, 2LL);
}
return result;
}


decompiled_code:
__int64 pro_2661ptr_reset()
{
pro_2661ptr_data = 0;
pro_2661ptr_stat = 65;
pro_2661ptr_mr1 = 0;
pro_2661ptr_mr2 = 0;
pro_2661ptr_cmd = 0;
pro_2661ptr_mode_ptr = 0;
*((_QWORD *)&pro_2661ptr_ctrl + 6) = 0LL;
*((_DWORD *)&pro_2661ptr_ctrl + 14) = 0;
pro_2661ptr_ctrl = 0LL;
*(&pro_2661ptr_ctrl + 1) = 0LL;
*(&pro_2661ptr_ctrl + 2) = 0LL;
return pro_2661ptr_poll_sched();
}

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; // eax
int v2; // edx
__int64 result; // rax

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

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

v1 = ptr_fifo_h;
v2 = ptr_fifo_h;
ptr_fifo[ptr_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v2 == 30623 )
result = 0LL;
++ptr_fifo_level;
ptr_fifo_h = result;
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; // di
__int64 result; // rax
char *v3; // rcx

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

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

v1 = *a1;
if ( v1 )
{
do
{
result = func4(v1);
v1 = *v3;
}
while ( *v3 );
}
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; // er8

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

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

v0 = 256;
if ( ptr_fifo_h != ptr_fifo_t )
{
--ptr_fifo_level;
v0 = (unsigned __int8)ptr_fifo[ptr_fifo_t];
}
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);
result = 0LL;
colrcnt = 0;
memset(pic, 0, 0xEF0uLL);
rowrcnt = 0;
col = 0;
maxcols = 0;
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);
result = 0LL;
colrcnt = 0;
memset(pic, 0, 0xEF0uLL);
rowrcnt = 0;
col = 0;
maxcols = 0;
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:
__int64 __fastcall plot_six(int a1, int a2)
{
int v3; // esi
int v4; // er10
int v5; // edi
int v6; // er9
__int64 result; // rax
int v8; // ebx
_BYTE *v9; // rdx
char v10; // cl

v3 = col;
v4 = maxcols;
v5 = a1 - 63;
v6 = col + a2;
if ( v6 <= col )
{
LABEL_11:
col = v6;
}
else
{
result = 0LL;
while ( v3 > 5099 )
{
if ( v6 == ++v3 )
goto LABEL_11;
}
while ( 1 )
{
v8 = 0;
v9 = (char *)pic + v3 / 8;
do
{
v10 = v8++;
*v9 |= ((v5 >> v10) & 1) << (7 - v3 % 8);
v9 += 638;
}
while ( v8 != 6 );
++v3;
++v4;
result = 1LL;
if ( v6 == v3 )
break;
while ( v3 > 5099 )
{
if ( v6 == ++v3 )
goto LABEL_10;
}
}
LABEL_10:
maxcols = v4;
col = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
int v3; // esi
int v4; // er10
int v5; // edi
int v6; // er9
__int64 result; // rax
int v8; // ebx
_BYTE *v9; // rdx
char v10; // cl

v3 = col;
v4 = maxcols;
v5 = a1 - 63;
v6 = col + a2;
if ( v6 <= col )
{
LABEL_11:
col = v6;
}
else
{
result = 0LL;
while ( v3 > 5099 )
{
if ( v6 == ++v3 )
goto LABEL_11;
}
while ( 1 )
{
v8 = 0;
v9 = (char *)pic + v3 / 8;
do
{
v10 = v8++;
*v9 |= ((v5 >> v10) & 1) << (7 - v3 % 8);
v9 += 638;
}
while ( v8 != 6 );
++v3;
++v4;
result = 1LL;
if ( v6 == v3 )
break;
while ( v3 > 5099 )
{
if ( v6 == ++v3 )
goto LABEL_10;
}
}
LABEL_10:
maxcols = v4;
col = v6;
}
return result;
}

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