decompiled_code:
void __noreturn task1()
{
while ( 1 )
video_puts(&unk_6648);
}

canonical_decompiled_code:
void __noreturn func1()
{
while ( 1 )
video_puts(&unk_6648);
}

original_code:
int task1(int argc, char **argv)
{
 while(1) video_puts("1");
}

variable_types: argc int

variable_types:
argv
char **


repo: dakk/spiderpig-os

decompiled_code:
void __noreturn task2()
{
while ( 1 )
video_puts(&unk_664A);
}

canonical_decompiled_code:
void __noreturn func2()
{
while ( 1 )
video_puts(&unk_664A);
}

original_code:
int task2(int argc, char **argv)
{
 while(1) video_puts("2");
}

return_type: int


decompiled_code:
void task_switch_priority()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void task_switch_priority()
{
}

canonical_original_code:
void task_switch_priority()
{
}

return_type: void


decompiled_code:
__int64 __fastcall task_init(char a1)
{
__int64 result; // rax

result = debug_puts("task_init()\n");
if ( a1 != 1 )
{
video_puts("Panic!\n");
while ( 1 )
;
}
task_switch_f = task_switch_round_robin;
task_list = 0LL;
task_current = 0LL;
task_cur_pid = 0;
return result;
}

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

result = debug_puts("task_init()\n");
if ( a1 != 1 )
{
video_puts("Panic!\n");
while ( 1 )
;
}
task_switch_f = task_switch_round_robin;
task_list = 0LL;
task_current = 0LL;
task_cur_pid = 0;
return result;
}

original_code:
void task_init(uint8_t st)
{
 debug_puts("task_init()\n");
 switch(st)
 {
  case 1:
   task_switch_f = &task_switch_round_robin;
   break;
  default:
   video_puts("Panic!\n");
   while(1);
 }
 task_list = 0;
 task_current = 0;
 task_cur_pid = 0;
}

canonical_original_code:
void task_init(unsigned char st)
{
 debug_puts("task_init()\n");
 switch(st)
 {
  case 1:
   task_switch_f = &task_switch_round_robin;
   break;
  default:
   video_puts("Panic!\n");
   while(1);
 }
 task_list = 0;
 task_current = 0;
 task_cur_pid = 0;
}

variable_types:
st
unsigned char


decompiled_code:
__int64 task_get_pid()
{
return *(unsigned int *)(task_current + 56);
}

canonical_decompiled_code:
__int64 func6()
{
return *(unsigned int *)(task_current + 56);
}

original_code: uint32_t task_get_pid(){ return task_current->pid; }

canonical_original_code: unsigned int task_get_pid(){ return task_current->pid; }

return_type: unsigned int


decompiled_code:
__int64 __fastcall task_get_from_pid(int a1)
{
__int64 result; // rax

for ( result = task_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_DWORD *)(result + 56) == a1 )
break;
}
return result;
}

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

for ( result = task_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_DWORD *)(result + 56) == a1 )
break;
}
return result;
}

original_code:
task_t *task_get_from_pid(pid_t pid)
{
 task_t *t = task_list;
 while(t != 0)
 {
  if(t->pid == pid) return t;
  t = t->next;
 }
 return (task_t *) 0;
}

canonical_original_code:
struct task_p *task_get_from_pid(int pid)
{
 struct task_p *t = task_list;
 while(t != 0)
 {
  if(t->pid == pid) return t;
  t = t->next;
 }
 return (struct task_p *) 0;
}

variable_types: pid int

variable_types: struct task_p { char name[16]; unsigned char state; unsigned char priority; unsigned int ms_sleep; unsigned int msg_num; struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *msg_start; struct message_p *msg_end; struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; } *term; int pid; int uid; struct task_p *next; } *

user_defined_types: struct task_p { char name[16]; unsigned char state; unsigned char priority; unsigned int ms_sleep; unsigned int msg_num; struct message_p *msg_start; struct message_p *msg_end; struct term_p *term; int pid; int uid; struct task_p *next; }


decompiled_code:
__int64 __fastcall show_task_message_list(unsigned int a1)
{
__int64 result; // rax
_QWORD *v2; // rbx

result = task_get_from_pid(a1);
if ( result )
{
v2 = *(_QWORD **)(result + 32);
video_puts_colored(9LL, "\t-> ");
video_puts("Msg List of ");
video_putint(a1);
for ( result = video_puts("\n"); v2; v2 = (_QWORD *)v2[2] )
{
video_puts_colored(9LL, "\t\t-> ");
video_puts("Msg: ");
video_puts(*v2);
result = video_puts("\n");
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 result; // rax
_QWORD *v2; // rbx

result = func7(a1);
if ( result )
{
v2 = *(_QWORD **)(result + 32);
video_puts_colored(9LL, "\t-> ");
video_puts("Msg List of ");
video_putint(a1);
for ( result = video_puts("\n"); v2; v2 = (_QWORD *)v2[2] )
{
video_puts_colored(9LL, "\t\t-> ");
video_puts("Msg: ");
video_puts(*v2);
result = video_puts("\n");
}
}
return result;
}

original_code:
void show_task_message_list(pid_t pid)
{
 if(task_get_from_pid(pid) == 0) return;
 message_t *msg = task_get_from_pid(pid)->msg_start;
 video_puts_colored(0x09, "\t-> ");
 video_puts("Msg List of ");
 video_putint(pid);
 video_puts("\n");
 while(msg != 0)
 {
  video_puts_colored(0x09, "\t\t-> ");
  video_puts("Msg: ");
  video_puts(msg->data);
  video_puts("\n");
  msg = msg->next;
 }
}

canonical_original_code:
void show_task_message_list(int pid)
{
 if(task_get_from_pid(pid) == 0) return;
 struct message_p *msg = task_get_from_pid(pid)->msg_start;
 video_puts_colored(0x09, "\t-> ");
 video_puts("Msg List of ");
 video_putint(pid);
 video_puts("\n");
 while(msg != 0)
 {
  video_puts_colored(0x09, "\t\t-> ");
  video_puts("Msg: ");
  video_puts(msg->data);
  video_puts("\n");
  msg = msg->next;
 }
}

variable_types: struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *


decompiled_code:
// attributes: thunk
__int64 __fastcall task_get_name(int a1)
{
return task_get_from_pid(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return func7(a1);
}

original_code:
char *task_get_name(pid_t pid)
{
 task_t *t = task_get_from_pid(pid);
 if(t == 0) return (char *) 0;
 return t->name;
}

canonical_original_code:
char *task_get_name(int pid)
{
 struct task_p *t = task_get_from_pid(pid);
 if(t == 0) return (char *) 0;
 return t->name;
}

return_type: char *

user_defined_types: struct message_p { char *data; unsigned int size; int pid; struct message_p *next; }

user_defined_types: struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; }


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

v1 = task_get_from_pid(a1);
if ( v1 )
result = *(unsigned int *)(v1 + 56);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v1 = func7(a1);
if ( v1 )
result = *(unsigned int *)(v1 + 56);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
uid_t task_get_uid(pid_t pid)
{
 task_t *t = task_get_from_pid(pid);
 if(t == 0) return -1;
 return t->pid;
}

canonical_original_code:
int task_get_uid(int pid)
{
 struct task_p *t = task_get_from_pid(pid);
 if(t == 0) return -1;
 return t->pid;
}


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

v1 = task_get_from_pid(a1);
if ( v1 )
result = *(unsigned __int8 *)(v1 + 16);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v1 = func7(a1);
if ( v1 )
result = *(unsigned __int8 *)(v1 + 16);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
uint8_t task_get_state(pid_t pid)
{
 task_t *t = task_get_from_pid(pid);
 if(t == 0) return -1;
 return t->state;
}

canonical_original_code:
unsigned char task_get_state(int pid)
{
 struct task_p *t = task_get_from_pid(pid);
 if(t == 0) return -1;
 return t->state;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall task_pause(int a1)
{
__int64 result; // rax

result = task_get_from_pid(a1);
if ( result )
*(_BYTE *)(result + 16) = 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 result; // rax

result = func7(a1);
if ( result )
*(_BYTE *)(result + 16) = 2;
return result;
}

original_code:
uint32_t task_pause(pid_t pid)
{
 task_t *t = task_get_from_pid(pid);
 if(t != 0) t->state = 2;
}

canonical_original_code:
unsigned int task_pause(int pid)
{
 struct task_p *t = task_get_from_pid(pid);
 if(t != 0) t->state = 2;
}


decompiled_code:
__int64 __fastcall task_resume(int a1)
{
__int64 result; // rax

result = task_get_from_pid(a1);
if ( result )
*(_BYTE *)(result + 16) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
__int64 result; // rax

result = func7(a1);
if ( result )
*(_BYTE *)(result + 16) = 0;
return result;
}

original_code:
uint32_t task_resume(pid_t pid)
{
 task_t *t = task_get_from_pid(pid);
 if(t != 0) t->state = 0;
}

canonical_original_code:
unsigned int task_resume(int pid)
{
 struct task_p *t = task_get_from_pid(pid);
 if(t != 0) t->state = 0;
}


decompiled_code:
void task_kill()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
uint32_t task_kill(pid_t pid)
{
}

canonical_original_code:
unsigned int task_kill(int pid)
{
}


decompiled_code:
__int64 task_create()
{
int v0; // eax
__int64 v1; // r12
int v2; // eax
__int64 v3; // rax
__int64 v4; // rax
bool v5; // zf

if ( (unsigned int)task_num > 0x3E6 )
return 0LL;
_disable();
v0 = mm_kalloc(720LL);
if ( !v0 )
return 0LL;
v1 = v0;
v2 = task_cur_pid;
++task_num;
*(_BYTE *)(v1 + 16) = 0;
*(_QWORD *)(v1 + 32) = 0LL;
task_cur_pid = v2 + 1;
*(_DWORD *)(v1 + 56) = v2 + 1;
v3 = task_list;
*(_QWORD *)(v1 + 40) = 0LL;
*(_QWORD *)(v1 + 20) = 0LL;
*(_QWORD *)(v1 + 64) = v3;
task_list = v1;
v4 = term_new(1024LL);
v5 = task_current == 0;
*(_QWORD *)(v1 + 48) = v4;
if ( v5 )
task_current = task_list;
_enable();
return v1;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // eax
__int64 v1; // r12
int v2; // eax
__int64 v3; // rax
__int64 v4; // rax
bool v5; // zf

if ( (unsigned int)task_num > 0x3E6 )
return 0LL;
_disable();
v0 = mm_kalloc(720LL);
if ( !v0 )
return 0LL;
v1 = v0;
v2 = task_cur_pid;
++task_num;
*(_BYTE *)(v1 + 16) = 0;
*(_QWORD *)(v1 + 32) = 0LL;
task_cur_pid = v2 + 1;
*(_DWORD *)(v1 + 56) = v2 + 1;
v3 = task_list;
*(_QWORD *)(v1 + 40) = 0LL;
*(_QWORD *)(v1 + 20) = 0LL;
*(_QWORD *)(v1 + 64) = v3;
task_list = v1;
v4 = term_new(1024LL);
v5 = task_current == 0;
*(_QWORD *)(v1 + 48) = v4;
if ( v5 )
task_current = task_list;
_enable();
return v1;
}

original_code:
task_t *task_create()
{
 task_t *taskn;
 if(task_num >= 999)
  return (task_t *) 0;
 asm("cli");
 taskn = (task_t *) mm_kalloc(sizeof(task_t)*10);
 if(taskn == 0) return (task_t *) 0;
 task_cur_pid++;
 taskn->pid = task_cur_pid;
 taskn->state = 0;
 task_num++;
 taskn->ms_sleep = 0;
 taskn->msg_end = taskn->msg_start = 0;
 taskn->msg_num = 0;
 taskn->next = task_list;
 task_list = taskn;
 taskn->term = term_new(1024);
 if(task_current == 0) task_current = task_list;
 asm("sti");
 return (task_t *) taskn;
}

canonical_original_code:
struct task_p *task_create()
{
 struct task_p *taskn;
 if(task_num >= 999)
  return (struct task_p *) 0;
 asm("cli");
 taskn = (struct task_p *) mm_kalloc(sizeof(task_t)*10);
 if(taskn == 0) return (struct task_p *) 0;
 task_cur_pid++;
 taskn->pid = task_cur_pid;
 taskn->state = 0;
 task_num++;
 taskn->ms_sleep = 0;
 taskn->msg_end = taskn->msg_start = 0;
 taskn->msg_num = 0;
 taskn->next = task_list;
 task_list = taskn;
 taskn->term = term_new(1024);
 if(task_current == 0) task_current = task_list;
 asm("sti");
 return (struct task_p *) taskn;
}

return_type: struct task_p { char name[16]; unsigned char state; unsigned char priority; unsigned int ms_sleep; unsigned int msg_num; struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *msg_start; struct message_p *msg_end; struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; } *term; int pid; int uid; struct task_p *next; } *


decompiled_code:
__int64 __fastcall task_exec(__int64 a1, const char **a2)
{
unsigned int v2; // er12
__int64 v3; // rbp
__int64 v4; // r14
unsigned __int64 v5; // rbx
__int64 v6; // rax
const char *v7; // rsi
char v9[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v2 = 0;
v3 = fs_open(a1, "r");
if ( v3 )
{
while ( (unsigned int)fs_read(v3, v9, 1LL) )
++v2;
v4 = (int)malloc(v2);
fs_seek(v3, 0LL, 0LL);
fs_read(v3, v4, v2);
if ( (unsigned int)elf_check(v4) )
{
v5 = (unsigned int)(*(_DWORD *)(v4 + 28) + v4);
if ( *(_DWORD *)(v4 + 28) + (_DWORD)v4 )
{
v6 = task_create();
v7 = *a2;
*(_DWORD *)(v6 + 60) = 1;
strcpy((char *)v6, v7);
((void (*)(void))v5)();
while ( 1 )
;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, const char **a2)
{
unsigned int v2; // er12
__int64 v3; // rbp
__int64 v4; // r14
unsigned __int64 v5; // rbx
__int64 v6; // rax
const char *v7; // rsi
char v9[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v2 = 0;
v3 = fs_open(a1, "r");
if ( v3 )
{
while ( (unsigned int)fs_read(v3, v9, 1LL) )
++v2;
v4 = (int)malloc(v2);
fs_seek(v3, 0LL, 0LL);
fs_read(v3, v4, v2);
if ( (unsigned int)elf_check(v4) )
{
v5 = (unsigned int)(*(_DWORD *)(v4 + 28) + v4);
if ( *(_DWORD *)(v4 + 28) + (_DWORD)v4 )
{
v6 = func15();
v7 = *a2;
*(_DWORD *)(v6 + 60) = 1;
strcpy((char *)v6, v7);
((void (*)(void))v5)();
while ( 1 )
;
}
}
}
return 0LL;
}

original_code:
pid_t task_exec(char *path, char **argv, int argc, char **env)
{
 task_t *taskn;
 void (*v)();
 char *buf;
 uint32_t point;
 file_t *t;
 point = 0;
 t = fs_open(path, "r");
 if(t != 0)
 {
  char ch[3];
  while(fs_read(t, ch, 1) != 0)
   point++;
  buf = (char *) malloc(point);
  fs_seek(t, 0, 0);
  fs_read(t, buf, point);
 }
 else
  return 0;
 v = 0;
  if(!elf_check(buf))
  {
   return 0;
  }
  elf_header_t *header = (elf_header_t *) buf;
  v = (void *) ((uint32_t) buf + (uint32_t) header->phoff);
 if(v == 0)
  return 0;
 taskn = task_create();
 taskn->uid = 1;
 strcpy(taskn->name, argv[0]);
 v();
 while(1);
 printf("end\n");
while(1);
 return taskn->pid;
}

canonical_original_code:
int task_exec(char *path, char **argv, int argc, char **env)
{
 struct task_p *taskn;
 void (*v)();
 char *buf;
 unsigned int point;
 struct file_p *t;
 point = 0;
 t = fs_open(path, "r");
 if(t != 0)
 {
  char ch[3];
  while(fs_read(t, ch, 1) != 0)
   point++;
  buf = (char *) malloc(point);
  fs_seek(t, 0, 0);
  fs_read(t, buf, point);
 }
 else
  return 0;
 v = 0;
  if(!elf_check(buf))
  {
   return 0;
  }
  struct elf_header_t *header = (elf_header_t *) buf;
  v = (void *) ((unsigned int) buf + (unsigned int) header->phoff);
 if(v == 0)
  return 0;
 taskn = task_create();
 taskn->uid = 1;
 strcpy(taskn->name, argv[0]);
 v();
 while(1);
 printf("end\n");
while(1);
 return taskn->pid;
}

variable_types:
path
char *

variable_types:
env
char **

variable_types:
v
void (*)()

variable_types:
buf
char *

variable_types:
point
unsigned int

variable_types: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *node; void *drv; struct file_p *next; } *

variable_types:
ch
char [3]

variable_types: struct elf_header_t { char ident[16]; unsigned short type; unsigned short machine; unsigned int version; unsigned int entry; unsigned int phoff; unsigned int shoff; unsigned int flags; unsigned short ehsize; unsigned short phentsize; unsigned short phnum; unsigned short shentsize; unsigned short shnum; unsigned short shstrndx; } *

user_defined_types: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p *node; void *drv; struct file_p *next; }


decompiled_code:
__int64 __fastcall task_sleep_ms(int a1)
{
__int64 result; // rax

result = task_current;
*(_DWORD *)(task_current + 20) = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
__int64 result; // rax

result = task_current;
*(_DWORD *)(task_current + 20) = a1;
return result;
}

original_code:
void task_sleep_ms(uint32_t tts)
{
 task_current->ms_sleep = tts;
}

canonical_original_code:
void task_sleep_ms(unsigned int tts)
{
 task_current->ms_sleep = tts;
}

variable_types:
tts
unsigned int


decompiled_code:
__int64 video_gety()
{
return (unsigned __int8)video_y;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned __int8)video_y;
}

original_code:
uint8_t video_gety()
{
 return video_y;
}

canonical_original_code:
unsigned char video_gety()
{
 return video_y;
}


decompiled_code:
__int64 video_getx()
{
return (unsigned __int8)video_x;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int8)video_x;
}

original_code:
uint8_t video_getx()
{
 return video_x;
}

canonical_original_code:
unsigned char video_getx()
{
 return video_x;
}


decompiled_code:
__int64 __fastcall video_backspace(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
char v3; // al
__int64 result; // rax

v2 = 2 * ((unsigned __int8)video_x + 80 * (unsigned int)(unsigned __int8)video_y);
if ( video_x )
{
v3 = video_x - 1;
}
else
{
video_x = 79;
video_y = video_gety(a1, a2, v2) - 1;
v3 = 78;
}
video_x = v3;
*(_BYTE *)((unsigned int)(v2 - 2) + 0xB8000LL) = 32;
result = (unsigned int)(v2 - 1);
*(_BYTE *)(result + 0xB8000) = video_std_color;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
char v3; // al
__int64 result; // rax

v2 = 2 * ((unsigned __int8)video_x + 80 * (unsigned int)(unsigned __int8)video_y);
if ( video_x )
{
v3 = video_x - 1;
}
else
{
video_x = 79;
video_y = func0(a1, a2, v2) - 1;
v3 = 78;
}
video_x = v3;
*(_BYTE *)((unsigned int)(v2 - 2) + 0xB8000LL) = 32;
result = (unsigned int)(v2 - 1);
*(_BYTE *)(result + 0xB8000) = video_std_color;
return result;
}

original_code:
void video_backspace()
{
 char *vidmem = (char *) 0xB8000;
 unsigned int i = 0;
 int x;
 i = (video_y * 80 * 2) + (video_x * 2);
 if(video_x == 0)
  {
    video_x = 80 -1;
    video_y = video_gety()-1;
   }
   video_x--;
   vidmem[i-2] = ' ';
   vidmem[i-1] = video_std_color;
}

variable_types:
vidmem
char *

variable_types:
i
unsigned int

variable_types: x int


original_code:
void video_scroll_dw()
{
 char *vidmem = (char *) 0xB8000;
 unsigned int x;
 unsigned int y;
 unsigned int i;
 unsigned int j;
 for(x = 0; x < 80; x++)
 {
  for(y = 0; y <= 25; y++)
  {
   i = (y * 80 * 2) + (x * 2);
   j = ((y+1) * 80 * 2) + (x * 2);
   vidmem[i] = vidmem[j];
   i++; j++;
   vidmem[i] = vidmem[j];
   }
 }
 video_y--;
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall video_move_cursor(unsigned __int8 a1, unsigned __int8 a2)
{
return arch_video_move_cursor(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, unsigned __int8 a2)
{
return arch_video_move_cursor(a1, a2);
}

original_code:
void video_move_cursor(uint8_t x, uint8_t y)
{
 arch_video_move_cursor(x, y);
}

canonical_original_code:
void video_move_cursor(unsigned char x, unsigned char y)
{
 arch_video_move_cursor(x, y);
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char


decompiled_code:
__int64 __fastcall video_putchar(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
unsigned __int8 v3; // si
unsigned __int8 v4; // di
char v6; // cl

v1 = (unsigned __int8)video_y;
if ( (_BYTE)a1 == 9 )
{
video_putchar(32LL, (unsigned __int8)video_y);
video_putchar(32LL, v1);
video_putchar(32LL, v1);
video_putchar(32LL, v1);
video_putchar(32LL, v1);
goto LABEL_5;
}
if ( (_BYTE)a1 != 10 )
{
v2 = 2 * ((unsigned __int8)video_x + 80 * (unsigned int)(unsigned __int8)video_y);
if ( (_BYTE)a1 == 8 )
{
if ( video_x )
{
v6 = video_x - 1;
}
else
{
video_x = 79;
video_y = video_gety(a1, (unsigned __int8)video_y, v2) - 1;
}
video_x = v6;
*(_BYTE *)((unsigned int)(v2 - 2) + 0xB8000LL) = 32;
*(_BYTE *)((unsigned int)(v2 - 1) + 0xB8000LL) = video_std_color;
}
else
{
*(_BYTE *)((int)v2 + 0xB8000LL) = a1;
*(_BYTE *)((unsigned int)(v2 + 1) + 0xB8000LL) = video_std_color;
++video_x;
}
LABEL_5:
v3 = video_y;
if ( (unsigned __int8)video_y <= 0x18u )
goto LABEL_6;
goto LABEL_10;
}
v3 = video_y + 1;
video_x = 0;
v4 = 0;
video_y = v3;
if ( v3 <= 0x18u )
return video_move_cursor(v4, v3);
LABEL_10:
video_scroll_dw();
v3 = video_y;
LABEL_6:
v4 = video_x;
if ( (unsigned __int8)video_x > 0x4Fu )
{
++v3;
video_x = 0;
v4 = 0;
video_y = v3;
}
return video_move_cursor(v4, v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
unsigned __int8 v3; // si
unsigned __int8 v4; // di
char v6; // cl

v1 = (unsigned __int8)video_y;
if ( (_BYTE)a1 == 9 )
{
func5(32LL, (unsigned __int8)video_y);
func5(32LL, v1);
func5(32LL, v1);
func5(32LL, v1);
func5(32LL, v1);
goto LABEL_5;
}
if ( (_BYTE)a1 != 10 )
{
v2 = 2 * ((unsigned __int8)video_x + 80 * (unsigned int)(unsigned __int8)video_y);
if ( (_BYTE)a1 == 8 )
{
if ( video_x )
{
v6 = video_x - 1;
}
else
{
video_x = 79;
video_y = func0(a1, (unsigned __int8)video_y, v2) - 1;
}
video_x = v6;
*(_BYTE *)((unsigned int)(v2 - 2) + 0xB8000LL) = 32;
*(_BYTE *)((unsigned int)(v2 - 1) + 0xB8000LL) = video_std_color;
}
else
{
*(_BYTE *)((int)v2 + 0xB8000LL) = a1;
*(_BYTE *)((unsigned int)(v2 + 1) + 0xB8000LL) = video_std_color;
++video_x;
}
LABEL_5:
v3 = video_y;
if ( (unsigned __int8)video_y <= 0x18u )
goto LABEL_6;
goto LABEL_10;
}
v3 = video_y + 1;
video_x = 0;
v4 = 0;
video_y = v3;
if ( v3 <= 0x18u )
return func4(v4, v3);
LABEL_10:
func3();
v3 = video_y;
LABEL_6:
v4 = video_x;
if ( (unsigned __int8)video_x > 0x4Fu )
{
++v3;
video_x = 0;
v4 = 0;
video_y = v3;
}
return func4(v4, v3);
}

original_code:
void video_putchar(uint8_t ch)
{
 char *vidmem = (char *) 0xB8000;
 unsigned int i = 0;
 int x;
 i = (video_y * 80 * 2) + (video_x * 2);
 switch(ch)
 {
  case '\n':
   video_y++;
   video_x = 0;
   break;
  case '\b':
   if(video_x == 0)
   {
    video_x = 80 -1;
    video_y = video_gety()-1;
   }
   video_x--;
   vidmem[i-2] = ' ';
   vidmem[i-1] = video_std_color;
   break;
  case '\t':
   for(x = 0; x < 5; x++)
    video_putchar(' ');
   break;
  default:
   vidmem[i] = ch;
   i++;
   vidmem[i] = video_std_color;
   video_x++;
   break;
 }
 if(video_y >= 25)
  video_scroll_dw();
 if(video_x >= 80)
 {
  video_y++;
  video_x = 0;
 }
 video_move_cursor(video_x, video_y);
}

canonical_original_code:
void video_putchar(unsigned char ch)
{
 char *vidmem = (char *) 0xB8000;
 unsigned int i = 0;
 int x;
 i = (video_y * 80 * 2) + (video_x * 2);
 switch(ch)
 {
  case '\n':
   video_y++;
   video_x = 0;
   break;
  case '\b':
   if(video_x == 0)
   {
    video_x = 80 -1;
    video_y = video_gety()-1;
   }
   video_x--;
   vidmem[i-2] = ' ';
   vidmem[i-1] = video_std_color;
   break;
  case '\t':
   for(x = 0; x < 5; x++)
    video_putchar(' ');
   break;
  default:
   vidmem[i] = ch;
   i++;
   vidmem[i] = video_std_color;
   video_x++;
   break;
 }
 if(video_y >= 25)
  video_scroll_dw();
 if(video_x >= 80)
 {
  video_y++;
  video_x = 0;
 }
 video_move_cursor(video_x, video_y);
}

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall video_puts(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // di
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 v2; // di
__int64 result; // rax

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

original_code:
void video_puts(uint8_t *str)
{
 while(*str != '\0')
 {
  video_putchar(*str);
  str++;
 }
}

canonical_original_code:
void video_puts(unsigned char *str)
{
 while(*str != '\0')
 {
  video_putchar(*str);
  str++;
 }
}

variable_types:
str
unsigned char *


decompiled_code:
__int64 video_putint()
{
unsigned __int8 *v0; // rax

v0 = (unsigned __int8 *)itoa();
return video_puts(v0);
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int8 *v0; // rax

v0 = (unsigned __int8 *)itoa();
return func6(v0);
}

original_code:
void video_putint(int num)
{
 video_puts(itoa(num));
}

variable_types: num int


decompiled_code:
__int64 __fastcall video_gotoxy(unsigned __int8 a1, unsigned __int8 a2)
{
video_x = a1;
video_y = a2;
return video_move_cursor(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, unsigned __int8 a2)
{
video_x = a1;
video_y = a2;
return func4(a1, a2);
}

original_code:
void video_gotoxy(uint8_t x, uint8_t y)
{
 video_x = x;
 video_y = y;
 video_move_cursor(video_x, video_y);
}

canonical_original_code:
void video_gotoxy(unsigned char x, unsigned char y)
{
 video_x = x;
 video_y = y;
 video_move_cursor(video_x, video_y);
}


decompiled_code:
__int64 video_clear()
{
__int64 i; // rax

for ( i = 753664LL; i != 757664; *(_BYTE *)(i - 1) = video_std_color )
{
*(_BYTE *)i = 32;
i += 2LL;
}
return video_gotoxy(0, 0);
}

original_code:
void video_clear()
{
 unsigned char *vidmem = (unsigned char *) 0xB8000;
 int i = 0;
 while(i < (80 * 25 * 2))
 {
  vidmem[i] = ' ';
  i++;
  vidmem[i] = video_std_color;
  i++;
 }
 video_gotoxy(0,0);
}

variable_types:
vidmem
unsigned char *

variable_types: i int


decompiled_code:
void __fastcall video_set_color(char a1)
{
video_std_color = a1;
}

canonical_decompiled_code:
void __fastcall func10(char a1)
{
video_std_color = a1;
}

original_code:
void video_set_color(vcolor_t cl)
{
 video_std_color = cl;
}

canonical_original_code:
void video_set_color(unsigned char cl)
{
 video_std_color = cl;
}

variable_types:
cl
unsigned char


decompiled_code:
void __fastcall video_puts_colored(char a1, unsigned __int8 *a2)
{
char v2; // bl

v2 = video_std_color;
video_set_color(a1);
video_puts(a2);
video_set_color(v2);
}

canonical_decompiled_code:
void __fastcall func11(char a1, unsigned __int8 *a2)
{
char v2; // bl

v2 = video_std_color;
func10(a1);
func6(a2);
func10(v2);
}

original_code:
void video_puts_colored(vcolor_t cl, uint8_t *str)
{
 uint8_t dc = video_std_color;
 video_set_color(cl);
 video_puts(str);
 video_set_color(dc);
}

canonical_original_code:
void video_puts_colored(unsigned char cl, unsigned char *str)
{
 unsigned char dc = video_std_color;
 video_set_color(cl);
 video_puts(str);
 video_set_color(dc);
}

variable_types:
dc
unsigned char


decompiled_code:
__int64 modem_free()
{
state = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
state = 0;
return 0LL;
}

original_code:
uint32_t modem_free()
{
 state = 0;
 return 0;
}

canonical_original_code:
unsigned int modem_free()
{
 state = 0;
 return 0;
}


decompiled_code:
__int64 modem_init()
{
driver_initd("rs232");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
driver_initd("rs232");
return 0LL;
}

original_code:
uint32_t modem_init()
{
 driver_initd("rs232");
 return 0;
}

canonical_original_code:
unsigned int modem_init()
{
 driver_initd("rs232");
 return 0;
}


decompiled_code:
__int64 __fastcall modem_read(unsigned int *a1, _BYTE *a2, int a3)
{
_BYTE *v4; // rbx
unsigned int v5; // er12
_BYTE *v6; // r14
char v7; // al

if ( a3 )
{
v4 = a2;
v5 = 0;
while ( 1 )
{
v6 = v4;
do
{
v7 = rs232_receive(*a1);
*v4 = v7;
}
while ( !v7 );
if ( v7 == 13 )
break;
++v5;
++v4;
if ( a3 == v5 )
{
v6 = &a2[v5];
break;
}
}
}
else
{
v6 = a2;
v5 = 0;
}
*v6 = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, _BYTE *a2, int a3)
{
_BYTE *v4; // rbx
unsigned int v5; // er12
_BYTE *v6; // r14
char v7; // al

if ( a3 )
{
v4 = a2;
v5 = 0;
while ( 1 )
{
v6 = v4;
do
{
v7 = rs232_receive(*a1);
*v4 = v7;
}
while ( !v7 );
if ( v7 == 13 )
break;
++v5;
++v4;
if ( a3 == v5 )
{
v6 = &a2[v5];
break;
}
}
}
else
{
v6 = a2;
v5 = 0;
}
*v6 = 0;
return v5;
}

original_code:
uint32_t modem_read(device_t *dev, char *frame, uint32_t size, uint64_t of)
{
 uint32_t i;
 uint64_t e;
 uint32_t t;
 for(i = 0; i < size; i++)
 {
  e = 1000000000;
  aq:
   e--;
   frame[i] = rs232_receive(dev->io_base);
   if(frame[i] == 0)
    goto aq;
   else if(frame[i] == 13)
    break;
 }
 frame[i] = '\0';
 return i;
}

canonical_original_code:
unsigned int modem_read(struct device_p *dev, char *frame, unsigned int size, unsigned long long of)
{
 unsigned int i;
 unsigned long long e;
 unsigned int t;
 for(i = 0; i < size; i++)
 {
  e = 1000000000;
  aq:
   e--;
   frame[i] = rs232_receive(dev->io_base);
   if(frame[i] == 0)
    goto aq;
   else if(frame[i] == 13)
    break;
 }
 frame[i] = '\0';
 return i;
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *

variable_types:
frame
char *

variable_types:
size
unsigned int

variable_types:
of
unsigned long long

variable_types:
e
unsigned long long

variable_types:
t
unsigned int


decompiled_code:
__int64 __fastcall modem_write(unsigned int *a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned __int8 *v4; // rbx
__int64 v5; // r12
__int64 v6; // rsi

if ( a3 )
{
v4 = a2;
v5 = (__int64)&a2[a3];
do
{
v6 = *v4++;
rs232_send(*a1, v6);
}
while ( v4 != (unsigned __int8 *)v5 );
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned __int8 *v4; // rbx
__int64 v5; // r12
__int64 v6; // rsi

if ( a3 )
{
v4 = a2;
v5 = (__int64)&a2[a3];
do
{
v6 = *v4++;
rs232_send(*a1, v6);
}
while ( v4 != (unsigned __int8 *)v5 );
}
return a3;
}

original_code:
uint32_t modem_write(device_t *dev, char *frame, uint32_t size, uint64_t off)
{
 uint32_t i;
 for(i = 0; i < size; i++)
 {
  rs232_send(dev->io_base, frame[i]);
 }
 return i;
}

canonical_original_code:
unsigned int modem_write(struct device_p *dev, char *frame, unsigned int size, unsigned long long off)
{
 unsigned int i;
 for(i = 0; i < size; i++)
 {
  rs232_send(dev->io_base, frame[i]);
 }
 return i;
}

variable_types:
off
unsigned long long

variable_types:
i
unsigned int

user_defined_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; }


decompiled_code:
__int64 __fastcall modem_connect(unsigned int *a1, const char *a2)
{
unsigned int v2; // eax
__int64 result; // rax
char v4[536]; // [rsp+0h] [rbp-218h] BYREF

driver_initd("rs232");
driver_puts(driver_modem, 1LL, "trying connection");
modem_write(a1, "\rat\r", 5u);
if ( !(unsigned int)modem_read(a1, v4, 5) )
goto LABEL_12;
if ( !strcmp(v4, "ABORT") || !strcmp(v4, "ERROR") || !strcmp(v4, "DIAL") )
{
driver_puts(driver_modem, 2LL, "error");
return 10LL;
}
driver_puts(driver_modem, 1LL, "sending number");
strcpy(v4, "atdt");
strcat(v4, a2);
strcat(v4, "\r");
v2 = strlen(v4);
modem_write(a1, (unsigned __int8 *)v4, v2);
if ( (unsigned int)modem_read(a1, v4, 8) )
{
if ( !strcmp(v4, "ABORT") || !strcmp(v4, "ERROR") )
{
driver_puts(driver_modem, 2LL, "connect error");
result = 10LL;
}
else if ( !strcmp(v4, "DIAL") )
{
driver_puts(driver_modem, 2LL, "dial error");
result = 10LL;
}
else if ( !strcmp(v4, "CONNECT") )
{
driver_puts(driver_modem, 1LL, "connected");
devfs_reg_device(0LL, 0LL, "modem0");
state = 1;
result = 0LL;
}
else
{
driver_puts(driver_modem, 2LL, "unknown error");
result = 10LL;
}
}
else
{
LABEL_12:
driver_puts(driver_modem, 3LL, "timeout");
result = 10LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, const char *a2)
{
unsigned int v2; // eax
__int64 result; // rax
char v4[536]; // [rsp+0h] [rbp-218h] BYREF

driver_initd("rs232");
driver_puts(driver_modem, 1LL, "trying connection");
func3(a1, "\rat\r", 5u);
if ( !(unsigned int)func2(a1, v4, 5) )
goto LABEL_12;
if ( !strcmp(v4, "ABORT") || !strcmp(v4, "ERROR") || !strcmp(v4, "DIAL") )
{
driver_puts(driver_modem, 2LL, "error");
return 10LL;
}
driver_puts(driver_modem, 1LL, "sending number");
strcpy(v4, "atdt");
strcat(v4, a2);
strcat(v4, "\r");
v2 = strlen(v4);
func3(a1, (unsigned __int8 *)v4, v2);
if ( (unsigned int)func2(a1, v4, 8) )
{
if ( !strcmp(v4, "ABORT") || !strcmp(v4, "ERROR") )
{
driver_puts(driver_modem, 2LL, "connect error");
result = 10LL;
}
else if ( !strcmp(v4, "DIAL") )
{
driver_puts(driver_modem, 2LL, "dial error");
result = 10LL;
}
else if ( !strcmp(v4, "CONNECT") )
{
driver_puts(driver_modem, 1LL, "connected");
devfs_reg_device(0LL, 0LL, "modem0");
state = 1;
result = 0LL;
}
else
{
driver_puts(driver_modem, 2LL, "unknown error");
result = 10LL;
}
}
else
{
LABEL_12:
driver_puts(driver_modem, 3LL, "timeout");
result = 10LL;
}
return result;
}

original_code:
uint32_t modem_connect(device_t *dev, char *num)
{
 char buf[512];
 driver_initd("rs232");
 driver_puts(&driver_modem, 0x1, "trying connection");
 modem_write(dev, "\rat\r", sizeof("\rat\r"), 0);
 if(modem_read(dev, buf, 5, 0) == 0)
 {
  driver_puts(&driver_modem, 0x3, "timeout");
  return 10;
 }
 if( (strcmp(buf, "ABORT") == 0) || (strcmp(buf, "ERROR") == 0) ||
  (strcmp(buf, "DIAL") == 0))
 {
  driver_puts(&driver_modem, 0x2, "error");
  return 10;
 }
 driver_puts(&driver_modem, 0x1, "sending number");
 strcpy(buf, "atdt");
 strcat(buf, num);
 strcat(buf, "\r");
 modem_write(dev, buf, strlen(buf), 0);
 if(modem_read(dev, buf, 8, 0) == 0)
 {
  driver_puts(&driver_modem, 0x3,"timeout");
  return 10;
 }
 if( (strcmp(buf, "ABORT") == 0) || (strcmp(buf, "ERROR") == 0))
 {
  driver_puts(&driver_modem, 0x2, "connect error");
  return 10;
 }
 else if(strcmp(buf, "DIAL") == 0)
 {
  driver_puts(&driver_modem, 0x2, "dial error");
  return 10;
 }
 else if(strcmp(buf, "CONNECT") == 0)
 {
  driver_puts(&driver_modem, 0x1, "connected");
  devfs_reg_device(0, 0, "modem0");
  state = 1;
  return 0;
 }
 else
 {
  driver_puts(&driver_modem, 0x2, "unknown error");
  return 10;
 }
}

canonical_original_code:
unsigned int modem_connect(struct device_p *dev, char *num)
{
 char buf[512];
 driver_initd("rs232");
 driver_puts(&driver_modem, 0x1, "trying connection");
 modem_write(dev, "\rat\r", sizeof("\rat\r"), 0);
 if(modem_read(dev, buf, 5, 0) == 0)
 {
  driver_puts(&driver_modem, 0x3, "timeout");
  return 10;
 }
 if( (strcmp(buf, "ABORT") == 0) || (strcmp(buf, "ERROR") == 0) ||
  (strcmp(buf, "DIAL") == 0))
 {
  driver_puts(&driver_modem, 0x2, "error");
  return 10;
 }
 driver_puts(&driver_modem, 0x1, "sending number");
 strcpy(buf, "atdt");
 strcat(buf, num);
 strcat(buf, "\r");
 modem_write(dev, buf, strlen(buf), 0);
 if(modem_read(dev, buf, 8, 0) == 0)
 {
  driver_puts(&driver_modem, 0x3,"timeout");
  return 10;
 }
 if( (strcmp(buf, "ABORT") == 0) || (strcmp(buf, "ERROR") == 0))
 {
  driver_puts(&driver_modem, 0x2, "connect error");
  return 10;
 }
 else if(strcmp(buf, "DIAL") == 0)
 {
  driver_puts(&driver_modem, 0x2, "dial error");
  return 10;
 }
 else if(strcmp(buf, "CONNECT") == 0)
 {
  driver_puts(&driver_modem, 0x1, "connected");
  devfs_reg_device(0, 0, "modem0");
  state = 1;
  return 0;
 }
 else
 {
  driver_puts(&driver_modem, 0x2, "unknown error");
  return 10;
 }
}

variable_types:
num
char *

variable_types:
buf
char [512]


decompiled_code:
__int64 modem_disconnect()
{
driver_puts(driver_modem, 1LL, "disconnected");
state = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
driver_puts(driver_modem, 1LL, "disconnected");
state = 0;
return 0LL;
}

original_code:
uint32_t modem_disconnect(device_t *dev)
{
 driver_puts(&driver_modem, 0x1, "disconnected");
 state = 0;
 return 0;
}

canonical_original_code:
unsigned int modem_disconnect(struct device_p *dev)
{
 driver_puts(&driver_modem, 0x1, "disconnected");
 state = 0;
 return 0;
}


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

if ( (_DWORD)a2 == 3 )
return modem_read(a1, (_BYTE *)(unsigned int)a3, a4);
if ( (unsigned int)a2 > 3 )
{
if ( (_DWORD)a2 == 4 )
result = modem_write(a1, (unsigned __int8 *)(unsigned int)a3, a4);
}
else if ( (_DWORD)a2 == 1 )
{
result = modem_connect(a1, (const char *)(unsigned int)a3);
}
else if ( (_DWORD)a2 == 2 )
{
result = modem_disconnect(a1, a2, a3, a4, (unsigned int)a4);
}
return result;
}

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

if ( (_DWORD)a2 == 3 )
return func2(a1, (_BYTE *)(unsigned int)a3, a4);
if ( (unsigned int)a2 > 3 )
{
if ( (_DWORD)a2 == 4 )
result = func3(a1, (unsigned __int8 *)(unsigned int)a3, a4);
}
else if ( (_DWORD)a2 == 1 )
{
result = func4(a1, (const char *)(unsigned int)a3);
}
else if ( (_DWORD)a2 == 2 )
{
result = func5(a1, a2, a3, a4, (unsigned int)a4);
}
return result;
}

original_code:
uint32_t modem_ioctl(device_t *d, uint32_t call, uint32_t a, uint32_t b)
{
 switch(call)
 {
  case 0x01:
   return modem_connect(d, (char *) a);
  case 0x02:
   return modem_disconnect(d);
  case 0x04:
   return modem_write(d, (char *) a, b, 0);
  case 0x03:
   return modem_read(d, (char *) a, b, 0);
  default:
   break;
 }
}

canonical_original_code:
unsigned int modem_ioctl(struct device_p *d, unsigned int call, unsigned int a, unsigned int b)
{
 switch(call)
 {
  case 0x01:
   return modem_connect(d, (char *) a);
  case 0x02:
   return modem_disconnect(d);
  case 0x04:
   return modem_write(d, (char *) a, b, 0);
  case 0x03:
   return modem_read(d, (char *) a, b, 0);
  default:
   break;
 }
}

variable_types:
call
unsigned int

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
void modem_callback()
{
char v0; // r8
int v1; // esi
bool v2; // zf
__int64 v3; // rax

if ( state )
{
v0 = rs232_receive(1016LL);
v1 = buf_p;
buff[buf_p] = v0;
v2 = ++v1 == ppp_linkproto[8];
buf_p = v1;
if ( v2 )
{
v3 = packet_create(buff);
ppp_handle_frame(0LL, v3);
buf_p = 0;
}
}
}

canonical_decompiled_code:
void func7()
{
char v0; // r8
int v1; // esi
bool v2; // zf
__int64 v3; // rax

if ( state )
{
v0 = rs232_receive(1016LL);
v1 = buf_p;
buff[buf_p] = v0;
v2 = ++v1 == ppp_linkproto[8];
buf_p = v1;
if ( v2 )
{
v3 = packet_create(buff);
ppp_handle_frame(0LL, v3);
buf_p = 0;
}
}
}

original_code:
uint32_t modem_callback(regs_t *reg)
{
 if(state)
 {
  buff[buf_p] = rs232_receive(0x3f8);
  buf_p++;
  if(buf_p == ppp_linkproto.frame_min_size)
  {
   packet_t *p = packet_create(buff, buf_p);
   ppp_handle_frame(0, p);
   buf_p = 0;
  }
 }
}

canonical_original_code:
unsigned int modem_callback(struct regs_t *reg)
{
 if(state)
 {
  buff[buf_p] = rs232_receive(0x3f8);
  buf_p++;
  if(buf_p == ppp_linkproto.frame_min_size)
  {
   struct packet_t *p = packet_create(buff, buf_p);
   ppp_handle_frame(0, p);
   buf_p = 0;
  }
 }
}

variable_types: struct regs_t { unsigned int edi; unsigned int ds; unsigned int which_int; unsigned int eip; } *

variable_types: struct packet_t { unsigned int size; char *data; } *


decompiled_code:
__int64 bt_handle_frame()
{
return 0LL;
}

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

original_code:
uint32_t bt_handle_frame(network_iface_t *iface, packet_t *p)
{
 return 0;
}

canonical_original_code:
unsigned int bt_handle_frame(struct network_iface_p *iface, struct packet_t *p)
{
 return 0;
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

user_defined_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; }

user_defined_types: struct packet_t { unsigned int size; char *data; }

user_defined_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t fs; struct driver_video_t video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; }

user_defined_types: struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; }


decompiled_code:
void bt_up()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
uint32_t bt_up(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int bt_up(struct network_iface_p *iface)
{
}

user_defined_types: struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); }

user_defined_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; }

user_defined_types: struct dirent { char name[255]; unsigned int inode; }

user_defined_types: struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; }


decompiled_code:
// attributes: thunk
void bt_down()
{
bt_up();
}

canonical_decompiled_code:
void func2()
{
func1();
}

original_code:
uint32_t bt_down(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int bt_down(struct network_iface_p *iface)
{
}


decompiled_code:
__int64 __fastcall debug_putchar(unsigned __int8 a1)
{
return io_outb(233LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return io_outb(233LL, a1);
}

original_code:
void debug_putchar(char c)
{
 io_outb(0xe9, c);
}

variable_types: c char


decompiled_code:
__int64 __fastcall debug_puts(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 i; // di

v1 = a1;
for ( i = *a1; i; ++v1 )
{
debug_putchar(i);
i = v1[1];
}
return log_stat();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
unsigned __int8 i; // di

v1 = a1;
for ( i = *a1; i; ++v1 )
{
func0(i);
i = v1[1];
}
return log_stat();
}

original_code:
void debug_puts(char *str)
{
 while(*str != '\0')
 {
  debug_putchar(*str);
  str++;
 }
  if(log_stat())
   return;
}

variable_types:
str
char *


decompiled_code:
__int64 debug_init()
{
return io_outw(35328LL, 35328LL);
}

original_code:
void debug_init()
{
 io_outw(0x8A00, 0x8A00);
}


decompiled_code:
__int64 __fastcall debug_ist_trace(char a1)
{
__int64 result; // rax

if ( a1 )
result = io_outw(35328LL, 35555LL);
else
result = io_outw(35328LL, 35554LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
__int64 result; // rax

if ( a1 )
result = io_outw(35328LL, 35555LL);
else
result = io_outw(35328LL, 35554LL);
return result;
}

original_code:
void debug_ist_trace(uint8_t status)
{
 if(status) io_outw(0x8A00, 0x8AE3);
 else io_outw(0x8A00, 0x8AE2);
}

canonical_original_code:
void debug_ist_trace(unsigned char status)
{
 if(status) io_outw(0x8A00, 0x8AE3);
 else io_outw(0x8A00, 0x8AE2);
}

variable_types:
status
unsigned char


decompiled_code:
__int64 __fastcall debug_reg_trace(char a1)
{
__int64 result; // rax

if ( a1 )
{
debug_ist_trace(1);
result = io_outw(35328LL, 35557LL);
}
else
{
debug_ist_trace(0);
result = io_outw(35328LL, 35556LL);
}
return result;
}

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

if ( a1 )
{
func3(1);
result = io_outw(35328LL, 35557LL);
}
else
{
func3(0);
result = io_outw(35328LL, 35556LL);
}
return result;
}

original_code:
void debug_reg_trace(uint8_t status)
{
 if(status)
 {
  debug_ist_trace(1);
  io_outw(0x8A00, 0x8AE5);
 }
 else
 {
  debug_ist_trace(0);
  io_outw(0x8A00,0x8AE4);
 }
}

canonical_original_code:
void debug_reg_trace(unsigned char status)
{
 if(status)
 {
  debug_ist_trace(1);
  io_outw(0x8A00, 0x8AE5);
 }
 else
 {
  debug_ist_trace(0);
  io_outw(0x8A00,0x8AE4);
 }
}


decompiled_code:
void debug_ioctl()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
uint32_t debug_ioctl(uint32_t func, char *buf, uint32_t size)
{
 switch(func)
 {
  case 0x01:
   break;
  default:
   break;
 };
}

canonical_original_code:
unsigned int debug_ioctl(unsigned int func, char *buf, unsigned int size)
{
 switch(func)
 {
  case 0x01:
   break;
  default:
   break;
 };
}

variable_types:
func
unsigned int

variable_types:
buf
char *

variable_types:
size
unsigned int


decompiled_code:
void lo_up()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
uint32_t lo_up(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int lo_up(struct network_iface_p *iface)
{
}


decompiled_code:
// attributes: thunk
void lo_down()
{
lo_up();
}

canonical_decompiled_code:
void func1()
{
func0();
}

original_code:
uint32_t lo_down(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int lo_down(struct network_iface_p *iface)
{
}


decompiled_code:
__int64 __fastcall lo_handle_frame(__int64 a1, unsigned int *a2)
{
unsigned __int16 v2; // r12

v2 = **((_WORD **)a2 + 1);
packet_del_header(a2, 2LL);
if ( (unsigned int)video_getx() )
printf("\n");
printf("lo: received packet (sizeof %d) of protocol %x\n", *a2, v2);
ip_handle_packet(a1, a2);
if ( v2 == 33 )
ip_handle_packet(a1, a2);
*(_DWORD *)(a1 + 60) += *a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned __int16 v2; // r12

v2 = **((_WORD **)a2 + 1);
packet_del_header(a2, 2LL);
if ( (unsigned int)video_getx() )
printf("\n");
printf("lo: received packet (sizeof %d) of protocol %x\n", *a2, v2);
ip_handle_packet(a1, a2);
if ( v2 == 33 )
ip_handle_packet(a1, a2);
*(_DWORD *)(a1 + 60) += *a2;
return 0LL;
}

original_code:
uint32_t lo_handle_frame(network_iface_t *iface, packet_t *p)
{
 uint16_t protocol;
 lo_header_t *lohead = (lo_header_t *) p->data;
 protocol = lohead->protocol;
 packet_del_header(p, sizeof(lo_header_t));
 if(video_getx() != 0)
  printf("\n");
 printf("lo: received packet (sizeof %d) of protocol %x\n", p->size, protocol);
 ip_handle_packet(iface, p);
 switch(protocol)
 {
  case 0x0021:
   ip_handle_packet(iface, p);
   break;
 }
 iface->rx_bytes = iface->rx_bytes + p->size;
 return 0;
}

canonical_original_code:
unsigned int lo_handle_frame(struct network_iface_p *iface, struct packet_t *p)
{
 unsigned short protocol;
 struct lo_header_t *lohead = (lo_header_t *) p->data;
 protocol = lohead->protocol;
 packet_del_header(p, sizeof(lo_header_t));
 if(video_getx() != 0)
  printf("\n");
 printf("lo: received packet (sizeof %d) of protocol %x\n", p->size, protocol);
 ip_handle_packet(iface, p);
 switch(protocol)
 {
  case 0x0021:
   ip_handle_packet(iface, p);
   break;
 }
 iface->rx_bytes = iface->rx_bytes + p->size;
 return 0;
}

variable_types:
protocol
unsigned short

variable_types: struct lo_header_t { unsigned short protocol; } *


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

lo_handle_frame(a1, a2);
result = *a2;
*(_DWORD *)(a1 + 56) += result;
return result;
}

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

func2(a1, a2);
result = *a2;
*(_DWORD *)(a1 + 56) += result;
return result;
}

original_code:
uint32_t lo_send_frame(network_iface_t *iface, packet_t *p)
{
 lo_handle_frame(iface, p);
 iface->tx_bytes = iface->tx_bytes + p->size;
 return p->size;
}

canonical_original_code:
unsigned int lo_send_frame(struct network_iface_p *iface, struct packet_t *p)
{
 lo_handle_frame(iface, p);
 iface->tx_bytes = iface->tx_bytes + p->size;
 return p->size;
}


decompiled_code:
void __fastcall packet_add_header(const void **a1, int a2)
{
char *v2; // r12

v2 = (char *)malloc((unsigned int)(a2 + *(_DWORD *)a1));
memcpy(&v2[a2], a1[1], *(unsigned int *)a1);
free((void *)a1[1]);
*(_DWORD *)a1 += a2;
a1[1] = v2;
}

canonical_decompiled_code:
void __fastcall func0(const void **a1, int a2)
{
char *v2; // r12

v2 = (char *)malloc((unsigned int)(a2 + *(_DWORD *)a1));
memcpy(&v2[a2], a1[1], *(unsigned int *)a1);
free((void *)a1[1]);
*(_DWORD *)a1 += a2;
a1[1] = v2;
}

original_code:
void packet_add_header(packet_t *p, uint32_t h_size)
{
 char *data = (char *) malloc(p->size + h_size);
 memcpy(data + h_size, p->data, p->size);
 free(p->data);
 p->data = data;
 p->size = p->size + h_size;
}

canonical_original_code:
void packet_add_header(struct packet_t *p, unsigned int h_size)
{
 char *data = (char *) malloc(p->size + h_size);
 memcpy(data + h_size, p->data, p->size);
 free(p->data);
 p->data = data;
 p->size = p->size + h_size;
}

variable_types:
data
char *


decompiled_code:
void __fastcall packet_del_header(__int64 a1, unsigned int a2)
{
void *v2; // r12

v2 = malloc(*(_DWORD *)a1 - a2);
memcpy(v2, (const void *)(*(_QWORD *)(a1 + 8) + a2), *(_DWORD *)a1 - a2);
free(*(void **)(a1 + 8));
*(_DWORD *)a1 -= a2;
*(_QWORD *)(a1 + 8) = v2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
void *v2; // r12

v2 = malloc(*(_DWORD *)a1 - a2);
memcpy(v2, (const void *)(*(_QWORD *)(a1 + 8) + a2), *(_DWORD *)a1 - a2);
free(*(void **)(a1 + 8));
*(_DWORD *)a1 -= a2;
*(_QWORD *)(a1 + 8) = v2;
}

original_code:
void packet_del_header(packet_t *p, uint32_t h_size)
{
 char *data = (char *) malloc(p->size - h_size);
 memcpy(data, p->data + h_size, p->size - h_size);
 free(p->data);
 p->data = data;
 p->size = p->size - h_size;
}

canonical_original_code:
void packet_del_header(struct packet_t *p, unsigned int h_size)
{
 char *data = (char *) malloc(p->size - h_size);
 memcpy(data, p->data + h_size, p->size - h_size);
 free(p->data);
 p->data = data;
 p->size = p->size - h_size;
}


decompiled_code:
__int64 packet_checksum()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
uint32_t packet_checksum(packet_t *p, uint32_t len)
{
 return 0;
}

canonical_original_code:
unsigned int packet_checksum(struct packet_t *p, unsigned int len)
{
 return 0;
}

variable_types:
len
unsigned int


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

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

original_code:
uint32_t keyboard_probe(device_t *dev)
{
 return 1;
}

canonical_original_code:
unsigned int keyboard_probe(struct device_p *dev)
{
 return 1;
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *


decompiled_code:
__int64 keyboard_init()
{
handler_reg(1LL, keyboard_callback);
numlock = 0;
capslock = 0;
control = 0;
alt = 0;
shift = 0;
bufpoint = 0;
bufsize = 0;
bufwhere = 0;
devfs_reg_device(0LL, driver_keyboard, "keyb0");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
handler_reg(1LL, keyboard_callback);
numlock = 0;
capslock = 0;
control = 0;
alt = 0;
shift = 0;
bufpoint = 0;
bufsize = 0;
bufwhere = 0;
devfs_reg_device(0LL, driver_keyboard, "keyb0");
return 0LL;
}

original_code:
uint32_t keyboard_init()
{
 handler_reg(1, &keyboard_callback);
 shift = alt = control = capslock = numlock = 0;
 bufwhere = bufsize = bufpoint = 0;
 devfs_reg_device(0, &driver_keyboard, "keyb0");
 return 0;
}

canonical_original_code:
unsigned int keyboard_init()
{
 handler_reg(1, &keyboard_callback);
 shift = alt = control = capslock = numlock = 0;
 bufwhere = bufsize = bufpoint = 0;
 devfs_reg_device(0, &driver_keyboard, "keyb0");
 return 0;
}


decompiled_code:
__int64 keyboard_free()
{
handler_unreg(1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
handler_unreg(1LL);
return 0LL;
}

original_code:
uint32_t keyboard_free()
{
 handler_unreg(1);
 return 0;
}

canonical_original_code:
unsigned int keyboard_free()
{
 handler_unreg(1);
 return 0;
}


decompiled_code:
__int64 keyboard_getchar()
{
unsigned int v0; // er8

v0 = 0;
if ( bufsize )
{
--bufsize;
v0 = (unsigned __int8)buf[(unsigned __int8)bufwhere++];
}
return v0;
}

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

v0 = 0;
if ( bufsize )
{
--bufsize;
v0 = (unsigned __int8)buf[(unsigned __int8)bufwhere++];
}
return v0;
}

original_code:
char keyboard_getchar()
{
 if(bufsize > 0)
 {
  char ch = buf[bufwhere];
  bufwhere++;
  bufsize--;
  return ch;
 }
 else return 0;
}

variable_types: ch char

return_type: char


decompiled_code:
__int64 __fastcall keyboard_update_leds(unsigned __int8 a1)
{
while ( (io_inb(100LL) & 2) != 0 )
;
io_outb(96LL, 237LL);
while ( (io_inb(100LL) & 2) != 0 )
;
return io_outb(96LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
while ( (io_inb(100LL) & 2) != 0 )
;
io_outb(96LL, 237LL);
while ( (io_inb(100LL) & 2) != 0 )
;
return io_outb(96LL, a1);
}

original_code:
void keyboard_update_leds(uint8_t status)
{
  uint8_t tmp;
  while((io_inb(0x64)&2)!=0){}
  io_outb(0x60,0xED);
  while((io_inb(0x64)&2)!=0){}
  io_outb(0x60,status);
 }

canonical_original_code:
void keyboard_update_leds(unsigned char status)
{
  unsigned char tmp;
  while((io_inb(0x64)&2)!=0){}
  io_outb(0x60,0xED);
  while((io_inb(0x64)&2)!=0){}
  io_outb(0x60,status);
 }

variable_types:
tmp
unsigned char


decompiled_code:
__int64 keyboard_callback()
{
__int64 result; // rax
char v1; // cl
char v2; // dl

result = io_inb(96LL);
if ( (result & 0x80u) == 0LL )
{
if ( (_BYTE)result == 58 )
{
capslock = capslock == 0;
return keyboard_update_leds(6u);
}
if ( (unsigned __int8)result > 0x3Au )
{
if ( (_BYTE)result == 69 )
{
numlock = numlock == 0;
return keyboard_update_leds(6u);
}
}
else if ( (_BYTE)result == 42 || (_BYTE)result == 54 )
{
shift = 1;
return result;
}
if ( shift )
{
if ( capslock )
goto LABEL_15;
}
else if ( !capslock )
{
LABEL_15:
v1 = bufpoint;
result = (unsigned __int8)keyboard_standard_charset[(unsigned __int8)result];
buf[(unsigned __int8)bufpoint] = result;
v2 = v1;
LABEL_16:
++bufsize;
bufpoint = v2 + 1;
return result;
}
result = (unsigned __int8)keyboard_standard_charset_shifted[(unsigned __int8)result];
v2 = bufpoint;
buf[(unsigned __int8)bufpoint] = result;
goto LABEL_16;
}
result &= 0x7Fu;
if ( (_BYTE)result == 42 || (_BYTE)result == 54 )
shift = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
char v1; // cl
char v2; // dl

result = io_inb(96LL);
if ( (result & 0x80u) == 0LL )
{
if ( (_BYTE)result == 58 )
{
capslock = capslock == 0;
return func4(6u);
}
if ( (unsigned __int8)result > 0x3Au )
{
if ( (_BYTE)result == 69 )
{
numlock = numlock == 0;
return func4(6u);
}
}
else if ( (_BYTE)result == 42 || (_BYTE)result == 54 )
{
shift = 1;
return result;
}
if ( shift )
{
if ( capslock )
goto LABEL_15;
}
else if ( !capslock )
{
LABEL_15:
v1 = bufpoint;
result = (unsigned __int8)keyboard_standard_charset[(unsigned __int8)result];
buf[(unsigned __int8)bufpoint] = result;
v2 = v1;
LABEL_16:
++bufsize;
bufpoint = v2 + 1;
return result;
}
result = (unsigned __int8)keyboard_standard_charset_shifted[(unsigned __int8)result];
v2 = bufpoint;
buf[(unsigned __int8)bufpoint] = result;
goto LABEL_16;
}
result &= 0x7Fu;
if ( (_BYTE)result == 42 || (_BYTE)result == 54 )
shift = 0;
return result;
}

original_code:
static void keyboard_callback(regs_t *reg)
{
 unsigned code = io_inb(0x60);
    if (code & 0x80)
    {
  code &= 0x7F;
  switch(code)
  {
   case 0x2A:
   case 0x36:
    shift = 0;
    break;
  }
    }
    else
    {
  switch(code)
  {
   case 0x3A:
    capslock = !capslock;
    keyboard_update_leds(4 | 2);
    break;
   case 0x45:
    numlock = !numlock;
    keyboard_update_leds(4 | 2);
    break;
   case 0x2A:
   case 0x36:
    shift = 1;
    break;
   default:
    if((shift && !capslock) || (!shift && capslock)) buf[bufpoint] = keyboard_standard_charset_shifted[code];
    else buf[bufpoint] = keyboard_standard_charset[code];
    bufsize++;
    bufpoint++;
    break;
  }
    }
}

canonical_original_code:
static void keyboard_callback(struct regs_t *reg)
{
 unsigned int code = io_inb(0x60);
    if (code & 0x80)
    {
  code &= 0x7F;
  switch(code)
  {
   case 0x2A:
   case 0x36:
    shift = 0;
    break;
  }
    }
    else
    {
  switch(code)
  {
   case 0x3A:
    capslock = !capslock;
    keyboard_update_leds(4 | 2);
    break;
   case 0x45:
    numlock = !numlock;
    keyboard_update_leds(4 | 2);
    break;
   case 0x2A:
   case 0x36:
    shift = 1;
    break;
   default:
    if((shift && !capslock) || (!shift && capslock)) buf[bufpoint] = keyboard_standard_charset_shifted[code];
    else buf[bufpoint] = keyboard_standard_charset[code];
    bufsize++;
    bufpoint++;
    break;
  }
    }
}

variable_types:
code
unsigned int

user_defined_types: struct regs_t { unsigned int edi; unsigned int ds; unsigned int which_int; unsigned int eip; }


decompiled_code:
__int64 __fastcall keyboard_read(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v6; // rdi
__int64 i; // rsi
char v8; // al

v6 = a2;
for ( i = 0LL; ; ++i )
{
v8 = keyboard_getchar(v6, i, a3, a4, a5, a1);
a5 = (unsigned int)i;
if ( !v8 || i == v6 )
break;
*(_BYTE *)(a1 + i) = v8;
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v6; // rdi
__int64 i; // rsi
char v8; // al

v6 = a2;
for ( i = 0LL; ; ++i )
{
v8 = func3(v6, i, a3, a4, a5, a1);
a5 = (unsigned int)i;
if ( !v8 || i == v6 )
break;
*(_BYTE *)(a1 + i) = v8;
}
return (unsigned int)i;
}

original_code:
uint32_t keyboard_read(char *data, uint32_t size, uint64_t off)
{
 int i = 0;
 char c;
 while(((c = keyboard_getchar()) != 0) && (i < size))
 {
  data[i] = c;
  i++;
 }
 return i;
}

canonical_original_code:
unsigned int keyboard_read(char *data, unsigned int size, unsigned long long off)
{
 int i = 0;
 char c;
 while(((c = keyboard_getchar()) != 0) && (i < size))
 {
  data[i] = c;
  i++;
 }
 return i;
}

variable_types:
off
unsigned long long

variable_types: i int


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

original_code:
uint32_t mouse_probe(device_t *dev)
{
 return 1;
}

canonical_original_code:
unsigned int mouse_probe(struct device_p *dev)
{
 return 1;
}


decompiled_code:
__int64 mouse_callback()
{
__int64 result; // rax
int v1; // edx

result = (unsigned __int8)mouse_cycle;
switch ( mouse_cycle )
{
case 1:
result = io_inw(96LL);
++mouse_cycle;
*(&mouse_byte + 1) = result;
break;
case 2:
LOBYTE(result) = io_inw(96LL);
v1 = (unsigned __int8)*(&mouse_byte + 1);
mouse_cycle = 0;
*(&mouse_byte + 2) = result;
result = (unsigned __int8)result;
mouse_x = v1;
mouse_y = (unsigned __int8)result;
break;
case 0:
result = io_inb(96LL);
++mouse_cycle;
mouse_byte = result;
break;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // edx

result = (unsigned __int8)mouse_cycle;
switch ( mouse_cycle )
{
case 1:
result = io_inw(96LL);
++mouse_cycle;
*(&mouse_byte + 1) = result;
break;
case 2:
LOBYTE(result) = io_inw(96LL);
v1 = (unsigned __int8)*(&mouse_byte + 1);
mouse_cycle = 0;
*(&mouse_byte + 2) = result;
result = (unsigned __int8)result;
mouse_x = v1;
mouse_y = (unsigned __int8)result;
break;
case 0:
result = io_inb(96LL);
++mouse_cycle;
mouse_byte = result;
break;
}
return result;
}

original_code:
static void mouse_callback(regs_t *reg)
{
 switch(mouse_cycle)
 {
  case 0:
   mouse_byte[0]=io_inb(0x60);
   mouse_cycle++;
   break;
  case 1:
   mouse_byte[1]=io_inw(0x60);
   mouse_cycle++;
   break;
  case 2:
   mouse_byte[2] = io_inw(0x60);
   mouse_x = mouse_byte[1];
   mouse_y = mouse_byte[2];
   mouse_cycle = 0;
   break;
 }
}

canonical_original_code:
static void mouse_callback(struct regs_t *reg)
{
 switch(mouse_cycle)
 {
  case 0:
   mouse_byte[0]=io_inb(0x60);
   mouse_cycle++;
   break;
  case 1:
   mouse_byte[1]=io_inw(0x60);
   mouse_cycle++;
   break;
  case 2:
   mouse_byte[2] = io_inw(0x60);
   mouse_x = mouse_byte[1];
   mouse_y = mouse_byte[2];
   mouse_cycle = 0;
   break;
 }
}

variable_types: struct regs_t { unsigned int edi; unsigned int ds; unsigned int which_int; unsigned int eip; } *


decompiled_code:
__int64 __fastcall mouse_wait(char a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 100000;
if ( a1 )
{
do
{
result = io_inb(100LL);
if ( (result & 2) == 0 )
break;
--v1;
}
while ( v1 );
}
else
{
do
{
result = io_inb(100LL);
if ( (result & 1) != 0 )
break;
--v1;
}
while ( v1 );
}
return result;
}

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

v1 = 100000;
if ( a1 )
{
do
{
result = io_inb(100LL);
if ( (result & 2) == 0 )
break;
--v1;
}
while ( v1 );
}
else
{
do
{
result = io_inb(100LL);
if ( (result & 1) != 0 )
break;
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void mouse_wait(uint8_t a_type)
{
 uint32_t time_out = 100000;
 if(a_type == 0)
 {
  while(time_out--)
   if((io_inb(0x64) & 1) == 1) return;
  return;
 }
 else
 {
  while(time_out--)
    if((io_inb(0x64) & 2) == 0) return;
  return;
 }
}

canonical_original_code:
void mouse_wait(unsigned char a_type)
{
 unsigned int time_out = 100000;
 if(a_type == 0)
 {
  while(time_out--)
   if((io_inb(0x64) & 1) == 1) return;
  return;
 }
 else
 {
  while(time_out--)
    if((io_inb(0x64) & 2) == 0) return;
  return;
 }
}


decompiled_code:
__int64 __fastcall mouse_write(unsigned __int8 a1)
{
mouse_wait(1);
io_outb(100LL, 212LL);
mouse_wait(1);
return io_outb(96LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
func2(1);
io_outb(100LL, 212LL);
func2(1);
return io_outb(96LL, a1);
}

original_code:
void mouse_write(uint8_t a_write)
{
 mouse_wait(1);
 io_outb(0x64, 0xD4);
 mouse_wait(1);
 io_outb(0x60, a_write);
}

canonical_original_code:
void mouse_write(unsigned char a_write)
{
 mouse_wait(1);
 io_outb(0x64, 0xD4);
 mouse_wait(1);
 io_outb(0x60, a_write);
}


decompiled_code:
__int64 mouse_read()
{
mouse_wait(0);
return io_inb(96LL);
}

canonical_decompiled_code:
__int64 func4()
{
func2(0);
return io_inb(96LL);
}

original_code:
uint8_t mouse_read()
{
 mouse_wait(0);
 return io_inb(0x60);
}

canonical_original_code:
unsigned char mouse_read()
{
 mouse_wait(0);
 return io_inb(0x60);
}


decompiled_code:
__int64 mouse_init()
{
unsigned __int8 v0; // bl

mouse_wait(1);
io_outb(100LL, 168LL);
mouse_wait(1);
io_outb(100LL, 32LL);
mouse_wait(0);
v0 = io_inb(96LL);
mouse_wait(1);
io_outb(100LL, 96LL);
mouse_wait(1);
io_outb(96LL, v0 | 2u);
mouse_write(0xF6u);
mouse_read();
mouse_write(0xF4u);
mouse_read();
mouse_write(0xE6u);
mouse_read();
return handler_reg(12LL, mouse_callback);
}

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

func2(1);
io_outb(100LL, 168LL);
func2(1);
io_outb(100LL, 32LL);
func2(0);
v0 = io_inb(96LL);
func2(1);
io_outb(100LL, 96LL);
func2(1);
io_outb(96LL, v0 | 2u);
func3(0xF6u);
func4();
func3(0xF4u);
func4();
func3(0xE6u);
func4();
return handler_reg(12LL, mouse_callback);
}

original_code:
uint32_t mouse_init()
{
 uint8_t status;
 mouse_wait(1);
 io_outb(0x64, 0xA8);
 mouse_wait(1);
 io_outb(0x64, 0x20);
 mouse_wait(0);
 status = (io_inb(0x60) | 2);
 mouse_wait(1);
 io_outb(0x64, 0x60);
 mouse_wait(1);
 io_outb(0x60, status);
 mouse_write(0xF6);
 mouse_read();
 mouse_write(0xF4);
 mouse_read();
 mouse_write(0xE6);
 mouse_read();
 handler_reg(12, &mouse_callback);
}

canonical_original_code:
unsigned int mouse_init()
{
 unsigned char status;
 mouse_wait(1);
 io_outb(0x64, 0xA8);
 mouse_wait(1);
 io_outb(0x64, 0x20);
 mouse_wait(0);
 status = (io_inb(0x60) | 2);
 mouse_wait(1);
 io_outb(0x64, 0x60);
 mouse_wait(1);
 io_outb(0x60, status);
 mouse_write(0xF6);
 mouse_read();
 mouse_write(0xF4);
 mouse_read();
 mouse_write(0xE6);
 mouse_read();
 handler_reg(12, &mouse_callback);
}


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

result = (unsigned int)mouse_x;
mouse_x = 0;
if ( (mouse_byte & 8) == 0 )
result = (unsigned int)-(int)result;
return result;
}

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

result = (unsigned int)mouse_x;
mouse_x = 0;
if ( (mouse_byte & 8) == 0 )
result = (unsigned int)-(int)result;
return result;
}

original_code:
int32_t mouse_get_x()
{
 int32_t a = mouse_x;
 mouse_x = 0;
 if(((mouse_packet_t *) &mouse_byte[0])->x_sign_bit)
  return a;
 else
  return -a;
}

canonical_original_code:
int mouse_get_x()
{
 int a = mouse_x;
 mouse_x = 0;
 if(((struct mouse_packet_t *) &mouse_byte[0])->x_sign_bit)
  return a;
 else
  return -a;
}

variable_types: a int

user_defined_types: struct mouse_packet_t { unsigned char y_overflow; unsigned char x_overflow; unsigned char y_sign_bit; unsigned char x_sign_bit; unsigned char alw_1; unsigned char middle_btn; unsigned char right_btn; unsigned char left_btn; }


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

result = (unsigned int)mouse_y;
mouse_y = 0;
if ( (mouse_byte & 4) == 0 )
result = (unsigned int)-(int)result;
return result;
}

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

result = (unsigned int)mouse_y;
mouse_y = 0;
if ( (mouse_byte & 4) == 0 )
result = (unsigned int)-(int)result;
return result;
}

original_code:
int32_t mouse_get_y()
{
 int32_t a = mouse_y;
 mouse_y = 0;
 if(((mouse_packet_t *) &mouse_byte[0])->y_sign_bit)
  return a;
 else
  return -a;
}

canonical_original_code:
int mouse_get_y()
{
 int a = mouse_y;
 mouse_y = 0;
 if(((struct mouse_packet_t *) &mouse_byte[0])->y_sign_bit)
  return a;
 else
  return -a;
}


decompiled_code:
void __fastcall mouse_ioctl(__int64 a1, unsigned int a2, unsigned __int8 a3)
{
if ( a2 == 3 )
{
mouse_read();
}
else if ( a2 > 3 )
{
if ( a2 == 4 )
mouse_write(a3);
}
else if ( a2 == 1 )
{
mouse_get_x();
}
else if ( a2 == 2 )
{
mouse_get_y();
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned int a2, unsigned __int8 a3)
{
if ( a2 == 3 )
{
func4();
}
else if ( a2 > 3 )
{
if ( a2 == 4 )
func3(a3);
}
else if ( a2 == 1 )
{
func6();
}
else if ( a2 == 2 )
{
func7();
}
}

original_code:
uint32_t mouse_ioctl(device_t *d, uint32_t call, uint32_t a, uint32_t b)
{
 switch(call)
 {
  case 0x01:
   return mouse_get_x();
  case 0x02:
   return mouse_get_y();
  case 0x03:
   return mouse_read();
  case 0x04:
   mouse_write(a);
   return 0;
  default:
   break;
 }
}

canonical_original_code:
unsigned int mouse_ioctl(struct device_p *d, unsigned int call, unsigned int a, unsigned int b)
{
 switch(call)
 {
  case 0x01:
   return mouse_get_x();
  case 0x02:
   return mouse_get_y();
  case 0x03:
   return mouse_read();
  case 0x04:
   mouse_write(a);
   return 0;
  default:
   break;
 }
}

variable_types:
call
unsigned int

variable_types:
a
unsigned int

variable_types:
b
unsigned int


decompiled_code:
__int64 clock_get_seconds()
{
unsigned __int8 v0; // al

io_outb(112LL, 0LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int8 v0; // al

io_outb(112LL, 0LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

original_code:
uint8_t clock_get_seconds()
{
 io_outb(0x70,0);
 return (uint8_t) bcd2bin(io_inb(0x71));
}

canonical_original_code:
unsigned char clock_get_seconds()
{
 io_outb(0x70,0);
 return (unsigned char) bcd2bin(io_inb(0x71));
}


decompiled_code:
__int64 clock_get_minutes()
{
unsigned __int8 v0; // al

io_outb(112LL, 2LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

canonical_decompiled_code:
__int64 func1()
{
unsigned __int8 v0; // al

io_outb(112LL, 2LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

original_code:
uint8_t clock_get_minutes()
{
 io_outb(0x70,0x02);
 return (uint8_t) bcd2bin(io_inb(0x71));
}

canonical_original_code:
unsigned char clock_get_minutes()
{
 io_outb(0x70,0x02);
 return (unsigned char) bcd2bin(io_inb(0x71));
}


decompiled_code:
__int64 clock_get_hours()
{
unsigned __int8 v0; // al

io_outb(112LL, 4LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned __int8 v0; // al

io_outb(112LL, 4LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

original_code:
uint8_t clock_get_hours()
{
 io_outb(0x70,0x04);
 return (uint8_t) bcd2bin(io_inb(0x71));
}

canonical_original_code:
unsigned char clock_get_hours()
{
 io_outb(0x70,0x04);
 return (unsigned char) bcd2bin(io_inb(0x71));
}


decompiled_code:
__int64 clock_get_day()
{
unsigned __int8 v0; // al

io_outb(112LL, 7LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int8 v0; // al

io_outb(112LL, 7LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

original_code:
uint8_t clock_get_day()
{
 io_outb(0x70,0x07);
 return (uint8_t) bcd2bin(io_inb(0x71));
}

canonical_original_code:
unsigned char clock_get_day()
{
 io_outb(0x70,0x07);
 return (unsigned char) bcd2bin(io_inb(0x71));
}


decompiled_code:
__int64 clock_get_month()
{
unsigned __int8 v0; // al

io_outb(112LL, 8LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int8 v0; // al

io_outb(112LL, 8LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

original_code:
uint8_t clock_get_month()
{
 io_outb(0x70,0x08);
 return (uint8_t) bcd2bin(io_inb(0x71));
}

canonical_original_code:
unsigned char clock_get_month()
{
 io_outb(0x70,0x08);
 return (unsigned char) bcd2bin(io_inb(0x71));
}


decompiled_code:
__int64 clock_get_year()
{
unsigned __int8 v0; // al

io_outb(112LL, 9LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int8 v0; // al

io_outb(112LL, 9LL);
v0 = io_inb(113LL);
return bcd2bin(v0);
}

original_code:
uint8_t clock_get_year()
{
 io_outb(0x70,0x09);
 return (uint8_t) bcd2bin(io_inb(0x71));
}

canonical_original_code:
unsigned char clock_get_year()
{
 io_outb(0x70,0x09);
 return (unsigned char) bcd2bin(io_inb(0x71));
}


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

clock_data = clock_get_hours();
*(&clock_data + 1) = clock_get_minutes();
*(&clock_data + 2) = clock_get_seconds();
*(&clock_data + 3) = clock_get_month();
*(&clock_data + 5) = clock_get_year();
result = clock_get_day();
*(&clock_data + 4) = result;
return result;
}

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

clock_data = func2();
*(&clock_data + 1) = func1();
*(&clock_data + 2) = func0();
*(&clock_data + 3) = func4();
*(&clock_data + 5) = func5();
result = func3();
*(&clock_data + 4) = result;
return result;
}

original_code:
static void clock_callback(regs_t *r)
{
 clock_data.hours = clock_get_hours();
 clock_data.minutes = clock_get_minutes();
 clock_data.seconds = clock_get_seconds();
 clock_data.month = clock_get_month();
 clock_data.year = clock_get_year();
 clock_data.day = clock_get_day();
}

canonical_original_code:
static void clock_callback(struct regs_t *r)
{
 clock_data.hours = clock_get_hours();
 clock_data.minutes = clock_get_minutes();
 clock_data.seconds = clock_get_seconds();
 clock_data.month = clock_get_month();
 clock_data.year = clock_get_year();
 clock_data.day = clock_get_day();
}


decompiled_code:
__int64 clock_init()
{
unsigned __int8 v0; // bl

io_outb(112LL, 11LL);
v0 = io_inb(113LL);
io_outb(112LL, 11LL);
io_outb(113LL, v0 | 0x40u);
return handler_reg(8LL, clock_callback);
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int8 v0; // bl

io_outb(112LL, 11LL);
v0 = io_inb(113LL);
io_outb(112LL, 11LL);
io_outb(113LL, v0 | 0x40u);
return handler_reg(8LL, clock_callback);
}

original_code:
void clock_init()
{
 char prev;
 io_outb(0x70, 0x0B);
 prev = io_inb(0x71);
 io_outb(0x70, 0x0B);
 io_outb(0x71, prev | 0x40);
 handler_reg(8, &clock_callback);
}

variable_types: prev char


decompiled_code:
__int64 arch_get_clock()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 0LL;
}

original_code:
uint32_t arch_get_clock()
{
 return 0;
}

canonical_original_code:
unsigned int arch_get_clock()
{
 return 0;
}


usage

decompiled_code:
int usage()
{
return puts("Usage: mkfs.pfs [-V volume-name] device");
}

canonical_decompiled_code:
int func0()
{
return puts("Usage: mkfs.pfs [-V volume-name] device");
}

original_code:
void usage()
{
 printf("Usage: mkfs.pfs [-V volume-name] device\n");
}


decompiled_code:
__int64 __fastcall mm_init(int a1, int a2)
{
debug_puts("mm_init()\n");
return phys_init((unsigned int)(a1 + a2));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
debug_puts("mm_init()\n");
return phys_init((unsigned int)(a1 + a2));
}

original_code:
void mm_init(uint32_t low, uint32_t high)
{
 debug_puts("mm_init()\n");
 phys_init(low + high);
}

canonical_original_code:
void mm_init(unsigned int low, unsigned int high)
{
 debug_puts("mm_init()\n");
 phys_init(low + high);
}

variable_types:
low
unsigned int

variable_types:
high
unsigned int


decompiled_code:
__int64 __fastcall mm_kalloc(int a1)
{
return phys_alloc(((unsigned int)(a1 + 1) >> 12) + 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return phys_alloc(((unsigned int)(a1 + 1) >> 12) + 1);
}

original_code:
void *mm_kalloc(size_t size)
{
 unsigned bnum = (unsigned) ((size + 1) / (4 * 1024)) + 1;
 return (void *)phys_alloc(bnum);
}

canonical_original_code:
void *mm_kalloc(unsigned int size)
{
 unsigned int bnum = (unsigned) ((size + 1) / (4 * 1024)) + 1;
 return (void *)phys_alloc(bnum);
}

variable_types:
size
unsigned int

variable_types:
bnum
unsigned int

return_type: void *


decompiled_code:
// attributes: thunk
__int64 mm_kfree()
{
return phys_free();
}

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

original_code:
void mm_kfree(void *addr)
{
 phys_free(addr);
}

variable_types:
addr
void *


decompiled_code:
__int64 mm_get_total_mem()
{
return (unsigned int)phys_total;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)phys_total;
}

original_code: uint32_t mm_get_total_mem(){ return phys_total; }

canonical_original_code: unsigned int mm_get_total_mem(){ return phys_total; }


decompiled_code:
__int64 mm_get_used_mem()
{
int v0; // ebx

v0 = phys_page_number;
return 4 * (v0 - (unsigned int)phys_get_free_pages());
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx

v0 = phys_page_number;
return 4 * (v0 - (unsigned int)phys_get_free_pages());
}

original_code:
uint32_t mm_get_used_mem()
{
 return ((phys_page_number - phys_get_free_pages()) * 4);
}

canonical_original_code:
unsigned int mm_get_used_mem()
{
 return ((phys_page_number - phys_get_free_pages()) * 4);
}


decompiled_code:
int show_used_memory()
{
unsigned int v0; // eax
unsigned int v1; // eax
int v2; // edx
unsigned int v3; // er12
__int64 v4; // rsi
unsigned int v5; // eax

video_puts_colored(9LL, "\t-> ");
v0 = ((__int64 (*)(void))mm_get_used_mem)();
v1 = mm_get_total_mem((_BYTE *)&loc_6 + 3, "\t-> ", v0);
v3 = 100 * v2 / v1;
v4 = (unsigned int)mm_get_used_mem(9LL, "\t-> ", 100 * v2 % v1);
printf("used: %dkb (%d%%); ", v4, v3);
v5 = mm_get_total_mem("total: %dkb\n", v4);
return printf("total: %dkb\n", v5);
}

canonical_decompiled_code:
int func5()
{
unsigned int v0; // eax
unsigned int v1; // eax
int v2; // edx
unsigned int v3; // er12
__int64 v4; // rsi
unsigned int v5; // eax

video_puts_colored(9LL, "\t-> ");
v0 = ((__int64 (*)(void))mm_get_used_mem)();
v1 = func3((_BYTE *)&loc_6 + 3, "\t-> ", v0);
v3 = 100 * v2 / v1;
v4 = (unsigned int)func4(9LL, "\t-> ", 100 * v2 % v1);
printf("used: %dkb (%d%%); ", v4, v3);
v5 = func3("total: %dkb\n", v4);
return printf("total: %dkb\n", v5);
}

original_code:
void show_used_memory()
{
 video_puts_colored(0x09, "\t-> ");
 printf("used: %dkb (%d%%);  ", mm_get_used_mem(), mm_get_used_mem() * 100 / mm_get_total_mem());
 printf("total: %dkb\n", mm_get_total_mem());
}


decompiled_code:
int mm_test()
{
__int64 v0; // rbp

debug_puts("mm_test()\n");
show_used_memory();
video_puts("Alloc 1000 blocks of 4*1024 bytes\n");
v0 = phys_alloc(1000LL);
show_used_memory();
video_puts("Delloc 1000 blocks of 4*1024 bytes\n");
phys_free(v0);
return show_used_memory();
}

canonical_decompiled_code:
int func6()
{
__int64 v0; // rbp

debug_puts("mm_test()\n");
func5();
video_puts("Alloc 1000 blocks of 4*1024 bytes\n");
v0 = phys_alloc(1000LL);
func5();
video_puts("Delloc 1000 blocks of 4*1024 bytes\n");
phys_free(v0);
return func5();
}

original_code:
void mm_test()
{
 debug_puts("mm_test()\n");
 show_used_memory();
 video_puts("Alloc 1000 blocks of 4*1024 bytes\n");
 char *data = phys_alloc(1000);
 show_used_memory();
 video_puts("Delloc 1000 blocks of 4*1024 bytes\n");
 phys_free(data);
 show_used_memory();
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall mm_get_usable_size(__int64 a1)
{
__int64 i; // rax

for ( i = 0LL; i != 0x8000; ++i )
{
if ( phys_allocated[2 * i] == a1 )
return LODWORD(phys_allocated[2 * (int)i + 1]);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 i; // rax

for ( i = 0LL; i != 0x8000; ++i )
{
if ( phys_allocated[2 * i] == a1 )
return LODWORD(phys_allocated[2 * (int)i + 1]);
}
return 0LL;
}

original_code:
uint32_t mm_get_usable_size(void *addr)
{
 int i = 0;
 for(i = 0; i < (1048576 / 32); i++)
  if(phys_allocated[i].address == addr)
   return phys_allocated[i].dim;
 return 0;
}

canonical_original_code:
unsigned int mm_get_usable_size(void *addr)
{
 int i = 0;
 for(i = 0; i < (1048576 / 32); i++)
  if(phys_allocated[i].address == addr)
   return phys_allocated[i].dim;
 return 0;
}


realloc

decompiled_code:
void *__fastcall realloc(void *src, size_t n)
{
void *v2; // r12

v2 = (void *)mm_kalloc((unsigned int)n);
memcpy(v2, src, (unsigned int)n);
free(src);
return v2;
}

canonical_decompiled_code:
void *__fastcall func2(void *src, size_t n)
{
void *v2; // r12

v2 = (void *)mm_kalloc((unsigned int)n);
memcpy(v2, src, (unsigned int)n);
func1(src);
return v2;
}

original_code:
void *realloc(void *adr, size_t size)
{
 void *new = (void *) mm_kalloc(size);
 memcpy(new, adr, size);
 free(adr);
 return (void *) new;
}

canonical_original_code:
void *realloc(void *adr, unsigned int size)
{
 void *new = (void *) mm_kalloc(size);
 memcpy(new, adr, size);
 free(adr);
 return (void *) new;
}

variable_types:
adr
void *

variable_types:
new
void *


malloc

decompiled_code:
__int64 malloc()
{
++allocazioni;
return mm_kalloc();
}

canonical_decompiled_code:
__int64 func0()
{
++allocazioni;
return mm_kalloc();
}

original_code:
void *malloc(size_t size)
{
 allocazioni++;
 return (void *) mm_kalloc(size);
}

canonical_original_code:
void *malloc(unsigned int size)
{
 allocazioni++;
 return (void *) mm_kalloc(size);
}


free

decompiled_code:
__int64 free()
{
--allocazioni;
return mm_kfree();
}

canonical_decompiled_code:
__int64 func1()
{
--allocazioni;
return mm_kfree();
}

original_code:
void free(void *adr)
{
 allocazioni--;
 mm_kfree(adr);
}


decompiled_code:
__int64 pci_probe()
{
return 0LL;
}

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

original_code:
uint32_t pci_probe()
{
 return 0;
}

canonical_original_code:
unsigned int pci_probe()
{
 return 0;
}


decompiled_code:
__int64 __fastcall pci_read(int a1, int a2, int a3, int a4, char a5)
{
char v6; // bp
__int64 result; // rax

v6 = a4;
io_outd(3320LL, (a2 << 11) | (a3 << 8) | a4 & 0xFFFFFFFC | (a1 << 16) | 0x80000000);
if ( a5 == 2 )
return (unsigned __int16)io_inw((v6 & 2u) + 3324);
if ( a5 == 4 )
return io_ind(3324LL);
result = 255LL;
if ( a5 == 1 )
result = (unsigned __int8)io_inb((v6 & 3u) + 3324);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4, char a5)
{
char v6; // bp
__int64 result; // rax

v6 = a4;
io_outd(3320LL, (a2 << 11) | (a3 << 8) | a4 & 0xFFFFFFFC | (a1 << 16) | 0x80000000);
if ( a5 == 2 )
return (unsigned __int16)io_inw((v6 & 2u) + 3324);
if ( a5 == 4 )
return io_ind(3324LL);
result = 255LL;
if ( a5 == 1 )
result = (unsigned __int8)io_inb((v6 & 3u) + 3324);
return result;
}

original_code:
uint32_t pci_read(uint32_t bus, uint32_t device, uint32_t function, uint32_t offset, uint8_t size)
{
 uint32_t value;
 io_outd(0xCF8, 0x80000000 | (bus << 16) | (device << 11) | (function << 8) | (offset & ~3));
 switch (size)
 {
  case 1:
   value = io_inb(0xCFC + (offset & 3)); break;
  case 2:
   value = io_inw(0xCFC + (offset & 2)); break;
  case 4:
   value = io_ind(0xCFC); break;
  default:
   return 0xFF;
 }
 return value;
}

canonical_original_code:
unsigned int pci_read(unsigned int bus, unsigned int device, unsigned int function, unsigned int offset, unsigned char size)
{
 unsigned int value;
 io_outd(0xCF8, 0x80000000 | (bus << 16) | (device << 11) | (function << 8) | (offset & ~3));
 switch (size)
 {
  case 1:
   value = io_inb(0xCFC + (offset & 3)); break;
  case 2:
   value = io_inw(0xCFC + (offset & 2)); break;
  case 4:
   value = io_ind(0xCFC); break;
  default:
   return 0xFF;
 }
 return value;
}

variable_types:
bus
unsigned int

variable_types:
device
unsigned int

variable_types:
function
unsigned int

variable_types:
offset
unsigned int

variable_types:
size
unsigned char

variable_types:
value
unsigned int


original_code:
uint32_t pci_get(uint32_t bus, uint32_t slot, uint32_t func, device_t *dev)
{
 uint32_t tmp = pci_read(bus, slot, func, 0x00, 2);
 if ((tmp == 0xFFFF) || (tmp == 0x0000)) return 0;
 pci_device_t *pci_dev = (pci_device_t *) malloc(sizeof(pci_device_t));
 int i;
 pci_dev->bus = bus;
 pci_dev->device = slot;
 pci_dev->function = func;
 pci_dev->vendor_id = pci_read(bus, slot, func, 0x00, 2);
 pci_dev->device_id = pci_read(bus, slot, func, 0x02, 2);
 pci_dev->class_id = pci_read(bus, slot, func, 0x0B, 1);
 pci_dev->subclass_id = pci_read(bus, slot, func, 0x0A, 1);
 for(i=0;i<6;i++)
 {
  pci_dev->bar[i] = pci_read(bus, slot, func, 0x10 + (i * 4), 4);
 }
 pci_dev->int_line = pci_read(bus, slot, func, 0x3C, 1);
 pci_dev->int_pin = pci_read(bus, slot, func, 0x3D, 1);
 for(i = 0; i < (sizeof(pci_class_code_table)/sizeof(pci_classtable_t)); i++)
  if( (pci_class_code_table[i].class_base == pci_dev->class_id) &&
   (pci_class_code_table[i].class_sub == pci_dev->subclass_id))
  {
   int j;
   strcpy(dev->class, pci_class_code_table[i].desc_base);
   strcpy(dev->class_desc, pci_class_code_table[i].desc_sub);
   strcpy(dev->file, pci_class_code_table[i].file);
   break;
  }
 dev->pci_dev = (void *) pci_dev;
 return 1;
}

canonical_original_code:
unsigned int pci_get(unsigned int bus, unsigned int slot, unsigned int func, struct device_p *dev)
{
 unsigned int tmp = pci_read(bus, slot, func, 0x00, 2);
 if ((tmp == 0xFFFF) || (tmp == 0x0000)) return 0;
 struct pci_device_t *pci_dev = (pci_device_t *) malloc(sizeof(pci_device_t));
 int i;
 pci_dev->bus = bus;
 pci_dev->device = slot;
 pci_dev->function = func;
 pci_dev->vendor_id = pci_read(bus, slot, func, 0x00, 2);
 pci_dev->device_id = pci_read(bus, slot, func, 0x02, 2);
 pci_dev->class_id = pci_read(bus, slot, func, 0x0B, 1);
 pci_dev->subclass_id = pci_read(bus, slot, func, 0x0A, 1);
 for(i=0;i<6;i++)
 {
  pci_dev->bar[i] = pci_read(bus, slot, func, 0x10 + (i * 4), 4);
 }
 pci_dev->int_line = pci_read(bus, slot, func, 0x3C, 1);
 pci_dev->int_pin = pci_read(bus, slot, func, 0x3D, 1);
 for(i = 0; i < (sizeof(pci_class_code_table)/sizeof(pci_classtable_t)); i++)
  if( (pci_class_code_table[i].class_base == pci_dev->class_id) &&
   (pci_class_code_table[i].class_sub == pci_dev->subclass_id))
  {
   int j;
   strcpy(dev->class, pci_class_code_table[i].desc_base);
   strcpy(dev->class_desc, pci_class_code_table[i].desc_sub);
   strcpy(dev->file, pci_class_code_table[i].file);
   break;
  }
 dev->pci_dev = (void *) pci_dev;
 return 1;
}

variable_types:
slot
unsigned int

variable_types:
func
unsigned int

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *

variable_types:
tmp
unsigned int

variable_types: struct pci_device_t { unsigned int bus; unsigned int function; unsigned int device; unsigned int command; unsigned int status; unsigned int rev_id; unsigned int iface; unsigned int vendor_id; unsigned int device_id; unsigned int class_id; unsigned int subclass_id; unsigned int bar[6]; unsigned int int_line; unsigned int int_pin; } *

variable_types: i int

variable_types: j int


original_code:
void pci_update(device_t **list)
{
 int bus, slot, func;
 device_t *dev = 0;
 device_t *newdev = 0;
 for(bus = 0; bus < 16; bus++)
  for(slot = 0; slot < 12; slot++)
   for(func = 0; func < 12; func++)
   {
    newdev = (device_t *) malloc(sizeof(device_t));
    if(pci_get(bus, slot, func, newdev))
    {
     newdev->bus_type = 0x01;
     newdev->next = 0;
     device_t *l = *list;
     while(l != 0)
     {
      if( (((pci_device_t * )(l->pci_dev))->bus == ((pci_device_t * )(newdev->pci_dev))->bus) &&
       (((pci_device_t * )(l->pci_dev))->device == ((pci_device_t * )(newdev->pci_dev))->device) &&
       (((pci_device_t * )(l->pci_dev))->function == ((pci_device_t * )(newdev->pci_dev))->function))
      {
       goto free_dev;
      }
      l = l->next;
     }
     if(*list == 0)
      *list = newdev;
     else
      dev->next = newdev;
     dev = newdev;
    }
    else
    {
     free_dev:
      free(newdev);
    }
   }
}

canonical_original_code:
void pci_update(struct device_p **list)
{
 int bus; int slot; int func;
 struct device_p *dev = 0;
 struct device_p *newdev = 0;
 for(bus = 0; bus < 16; bus++)
  for(slot = 0; slot < 12; slot++)
   for(func = 0; func < 12; func++)
   {
    newdev = (struct device_p *) malloc(sizeof(device_t));
    if(pci_get(bus, slot, func, newdev))
    {
     newdev->bus_type = 0x01;
     newdev->next = 0;
     struct device_p *l = *list;
     while(l != 0)
     {
      if( (((struct pci_device_t * )(l->pci_dev))->bus == ((struct pci_device_t * )(newdev->pci_dev))->bus) &&
       (((struct pci_device_t * )(l->pci_dev))->device == ((struct pci_device_t * )(newdev->pci_dev))->device) &&
       (((struct pci_device_t * )(l->pci_dev))->function == ((struct pci_device_t * )(newdev->pci_dev))->function))
      {
       goto free_dev;
      }
      l = l->next;
     }
     if(*list == 0)
      *list = newdev;
     else
      dev->next = newdev;
     dev = newdev;
    }
    else
    {
     free_dev:
      free(newdev);
    }
   }
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } **

variable_types: bus int

variable_types: slot int

variable_types: func int

user_defined_types: struct pci_device_t { unsigned int bus; unsigned int function; unsigned int device; unsigned int command; unsigned int status; unsigned int rev_id; unsigned int iface; unsigned int vendor_id; unsigned int device_id; unsigned int class_id; unsigned int subclass_id; unsigned int bar[6]; unsigned int int_line; unsigned int int_pin; }


decompiled_code:
__int64 __fastcall term_new(unsigned int a1)
{
__int64 v1; // rbx
int v2; // eax
char *v3; // rdi

v1 = (int)mm_kalloc(104LL);
*(_QWORD *)(v1 + 64) = (int)mm_kalloc(a1);
v2 = mm_kalloc(a1);
v3 = *(char **)(v1 + 64);
*(_QWORD *)(v1 + 72) = v2;
strcpy(v3, src);
*(_DWORD *)(v1 + 80) = 0;
*(_BYTE *)(v1 + 84) = 15;
devfs_find_freen(&unk_6303, v1 + 32);
return devfs_reg_device(0LL, 0LL, v1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 v1; // rbx
int v2; // eax
char *v3; // rdi

v1 = (int)mm_kalloc(104LL);
*(_QWORD *)(v1 + 64) = (int)mm_kalloc(a1);
v2 = mm_kalloc(a1);
v3 = *(char **)(v1 + 64);
*(_QWORD *)(v1 + 72) = v2;
strcpy(v3, src);
*(_DWORD *)(v1 + 80) = 0;
*(_BYTE *)(v1 + 84) = 15;
devfs_find_freen(&unk_6303, v1 + 32);
return devfs_reg_device(0LL, 0LL, v1 + 32);
}

original_code:
term_t *term_new(size_t size)
{
 term_t *t = (term_t *) mm_kalloc(sizeof(term_t));
 t->data = (char *) mm_kalloc(sizeof(char) * size);
 t->input = (char *) mm_kalloc(sizeof(char) * size);
 strcpy(t->data, "\0");
 t->cursor_pos = 0;
 t->color = 0x0F;
 devfs_find_freen("tty", t->dfile);
 devfs_reg_device(0,0, t->dfile);
}

canonical_original_code:
struct term_p *term_new(unsigned int size)
{
 struct term_p *t = (term_t *) mm_kalloc(sizeof(term_t));
 t->data = (char *) mm_kalloc(sizeof(char) * size);
 t->input = (char *) mm_kalloc(sizeof(char) * size);
 strcpy(t->data, "\0");
 t->cursor_pos = 0;
 t->color = 0x0F;
 devfs_find_freen("tty", t->dfile);
 devfs_reg_device(0,0, t->dfile);
}

variable_types:
size
unsigned int

variable_types: struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; } *


decompiled_code:
__int64 __fastcall term_delete(__int64 a1)
{
devfs_unreg_device(a1 + 32);
mm_kfree(*(_QWORD *)(a1 + 64));
return mm_kfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
devfs_unreg_device(a1 + 32);
mm_kfree(*(_QWORD *)(a1 + 64));
return mm_kfree(a1);
}

original_code:
void term_delete(term_t *t)
{
 devfs_unreg_device(t->dfile);
 mm_kfree(t->data);
 mm_kfree(t);
}

canonical_original_code:
void term_delete(struct term_p *t)
{
 devfs_unreg_device(t->dfile);
 mm_kfree(t->data);
 mm_kfree(t);
}


decompiled_code:
char *__fastcall term_set_title(char *dest, const char *src)
{
return strcpy(dest, src);
}

canonical_decompiled_code:
char *__fastcall func2(char *dest, const char *src)
{
return strcpy(dest, src);
}

original_code:
void term_set_title(term_t *t, char *title)
{
 strcpy(t->name, title);
}

canonical_original_code:
void term_set_title(struct term_p *t, char *title)
{
 strcpy(t->name, title);
}

variable_types:
title
char *


decompiled_code:
__int64 message_clear()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

v0 = task_current;
for ( i = *(_QWORD *)(task_current + 32); i; --*(_DWORD *)(v0 + 24) )
{
v2 = i;
i = *(_QWORD *)(i + 16);
result = mm_kfree(v2);
}
*(_QWORD *)(v0 + 32) = 0LL;
*(_QWORD *)(v0 + 40) = 0LL;
*(_DWORD *)(v0 + 24) = 0;
return result;
}

original_code:
void message_clear()
{
 task_t *t = task_current;
 message_t *first;
 message_t *second = t->msg_start;
 while(second != 0)
 {
  first = second->next;
  mm_kfree(second);
  t->msg_num--;
  second = first;
 }
 t->msg_end = t->msg_start = 0;
 t->msg_num = 0;
}

canonical_original_code:
void message_clear()
{
 struct task_p *t = task_current;
 struct message_p *first;
 struct message_p *second = t->msg_start;
 while(second != 0)
 {
  first = second->next;
  mm_kfree(second);
  t->msg_num--;
  second = first;
 }
 t->msg_end = t->msg_start = 0;
 t->msg_num = 0;
}

variable_types: struct task_p { char name[16]; unsigned char state; unsigned char priority; unsigned int ms_sleep; unsigned int msg_num; struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *msg_start; struct message_p *msg_end; struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; } *term; int pid; int uid; struct task_p *next; } *


original_code:
uint32_t message_send(pid_t to, char *buf, uint32_t size)
{
 uint32_t x;
 task_t *t = task_get_from_pid(to);
 if(t == 0) return -1;
 if(t->msg_num > 255) return -2;
 if(size >= 255) return -3;
 message_t *tm = (message_t *) mm_kalloc(sizeof(message_t));
 for(x = 0; x < size && x < 255; x++)
  tm->data[x] = buf[x];
 tm->pid = task_get_pid();
 tm->size = size;
 tm->next = 0;
 if(t->msg_start == 0 || t->msg_end == 0)
 {
  t->msg_start = tm;
  t->msg_end = tm;
 }
 else
 {
  t->msg_end->next = tm;
  t->msg_end = tm;
 }
 t->msg_num++;
 return 1;
}

canonical_original_code:
unsigned int message_send(int to, char *buf, unsigned int size)
{
 unsigned int x;
 struct task_p *t = task_get_from_pid(to);
 if(t == 0) return -1;
 if(t->msg_num > 255) return -2;
 if(size >= 255) return -3;
 struct message_p *tm = (message_t *) mm_kalloc(sizeof(message_t));
 for(x = 0; x < size && x < 255; x++)
  tm->data[x] = buf[x];
 tm->pid = task_get_pid();
 tm->size = size;
 tm->next = 0;
 if(t->msg_start == 0 || t->msg_end == 0)
 {
  t->msg_start = tm;
  t->msg_end = tm;
 }
 else
 {
  t->msg_end->next = tm;
  t->msg_end = tm;
 }
 t->msg_num++;
 return 1;
}

variable_types: to int

variable_types:
buf
char *

variable_types:
x
unsigned int

variable_types: struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *


decompiled_code:
__int64 __fastcall message_recv(char *a1, _DWORD *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
const char **v4; // rax
__int64 v5; // rdi
__int64 v6; // rbp
bool v7; // zf

v2 = task_current;
if ( !task_current )
return 0LL;
v3 = *(_DWORD *)(task_current + 24);
if ( v3 )
{
v4 = *(const char ***)(task_current + 32);
v3 = 0;
if ( v4 )
{
strcpy(a1, *v4);
v5 = *(_QWORD *)(v2 + 32);
v3 = *(_DWORD *)(v5 + 8);
*a2 = *(_DWORD *)(v5 + 12);
v6 = *(_QWORD *)(v5 + 16);
mm_kfree(v5);
v7 = *(_QWORD *)(v2 + 40) == 0LL;
*(_QWORD *)(v2 + 32) = v6;
if ( v7 )
*(_QWORD *)(v2 + 40) = v6;
--*(_DWORD *)(v2 + 24);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _DWORD *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
const char **v4; // rax
__int64 v5; // rdi
__int64 v6; // rbp
bool v7; // zf

v2 = task_current;
if ( !task_current )
return 0LL;
v3 = *(_DWORD *)(task_current + 24);
if ( v3 )
{
v4 = *(const char ***)(task_current + 32);
v3 = 0;
if ( v4 )
{
strcpy(a1, *v4);
v5 = *(_QWORD *)(v2 + 32);
v3 = *(_DWORD *)(v5 + 8);
*a2 = *(_DWORD *)(v5 + 12);
v6 = *(_QWORD *)(v5 + 16);
mm_kfree(v5);
v7 = *(_QWORD *)(v2 + 40) == 0LL;
*(_QWORD *)(v2 + 32) = v6;
if ( v7 )
*(_QWORD *)(v2 + 40) = v6;
--*(_DWORD *)(v2 + 24);
}
}
return v3;
}

original_code:
uint32_t message_recv(char *data, pid_t *pid)
{
 task_t *t = task_current;
 if(t == 0) return 0;
 if(t->msg_num < 1) return 0;
 if(t->msg_start == 0) return 0;
 strcpy(data, t->msg_start->data);
 uint32_t size = t->msg_start->size;
 *pid = t->msg_start->pid;
 message_t *msg = t->msg_start->next;
 mm_kfree(t->msg_start);
 t->msg_start = msg;
 if(t->msg_end == 0) t->msg_end = t->msg_start;
 t->msg_num--;
 return size;
}

canonical_original_code:
unsigned int message_recv(char *data, int *pid)
{
 struct task_p *t = task_current;
 if(t == 0) return 0;
 if(t->msg_num < 1) return 0;
 if(t->msg_start == 0) return 0;
 strcpy(data, t->msg_start->data);
 unsigned int size = t->msg_start->size;
 *pid = t->msg_start->pid;
 struct message_p *msg = t->msg_start->next;
 mm_kfree(t->msg_start);
 t->msg_start = msg;
 if(t->msg_end == 0) t->msg_end = t->msg_start;
 t->msg_num--;
 return size;
}

variable_types:
data
char *

variable_types:
pid
int *