dm

decompiled_code:
__int64 dm()
{
_QWORD *v0; // rbx
__int64 result; // rax

if ( qword_540 )
{
v0 = cache_cache;
do
{
result = kprintf("- %s %x -", v0 + 10);
v0 = (_QWORD *)v0[12];
}
while ( v0[12] );
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
_QWORD *v0; // rbx
__int64 result; // rax

if ( qword_540 )
{
v0 = cache_cache;
do
{
result = kprintf("- %s %x -", v0 + 10);
v0 = (_QWORD *)v0[12];
}
while ( v0[12] );
}
return result;
}

original_code:
void dm()
{
 kmem_cache_t ch = &cache_cache;
 while(ch->next_cache)
 {
  kprintf("- %s %x -", ch->name, ch->partial.next);
  ch = ch->next_cache;
 }
}

canonical_original_code:
void dm()
{
 struct kmem_cache *ch = &cache_cache;
 while(ch->next_cache)
 {
  kprintf("- %s %x -", ch->name, ch->partial.next);
  ch = ch->next_cache;
 }
}


repo: mregmi/manrix

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

result = 13LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

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

result = 13LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

original_code:
static inline int syscall_get_tid()
{
 register int tid;
 asm volatile (
  "int $0x30\n\t"
  :"=a"(tid)
  :"0"(13)
  );
 return tid;
}

variable_types: tid int

return_type: int


decompiled_code:
__int64 get_pinternal()
{
return syscall_get_ustack();
}

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

original_code:
static inline struct pthread_internal *get_pinternal()
{
 struct pthread_internal *internal;
 internal = (struct pthread_internal *)syscall_get_ustack();
 return internal;
}

variable_types: struct pthread_internal { struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } attr; struct fork_handler { void (*prepare)(); void (*parent)(); void (*child)(); } pt_fork; void *(*entry)(void *); void *arg; int tid; } *

user_defined_types: struct pthread_internal { struct pthread_attr attr; struct fork_handler pt_fork; void *(*entry)(void *); void *arg; int tid; }

user_defined_types: struct pthread_attr { int flags; struct sched_param prio; void *stackaddr; unsigned int stack_size; int policy; }


original_code:
static inline void check_attr(pthread_attr_t *nattr, const pthread_attr_t *attr)
{
 struct pthread_internal *inter;
 if(attr == ((void *) 0))
 {
  pthread_attr_init(nattr);
  return;
 }
 if(attr->flags & 0x0001)
 {
  *nattr = *attr;
 }
 else
 {
  inter = get_pinternal();
  *nattr = inter->attr;
  nattr->stackaddr = ((void *) 0);
  nattr->stack_size = 0;
 }
}

canonical_original_code:
static inline void check_attr(struct pthread_attr *nattr, struct pthread_attr *attr)
{
 struct pthread_internal *inter;
 if(attr == ((void *) 0))
 {
  pthread_attr_init(nattr);
  return;
 }
 if(attr->flags & 0x0001)
 {
  *nattr = *attr;
 }
 else
 {
  inter = get_pinternal();
  *nattr = inter->attr;
  nattr->stackaddr = ((void *) 0);
  nattr->stack_size = 0;
 }
}

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } *

variable_types:
attr
struct pthread_attr *

return_type: void

user_defined_types: struct fork_handler { void (*prepare)(); void (*parent)(); void (*child)(); }


original_code:
static inline pthread_t pthread_internal_create(pthread_attr_t *attr,
         void *(* start_routine)(void *), void *arg)
{
 struct pthread_internal *pint;
 if(attr->stackaddr == ((void *) 0))
 {
  attr->stackaddr = malloc(0x2000);
  if(!attr->stackaddr)
   return -0x31;
  attr->stack_size = 0x2000;
 }
 pint = (struct pthread_internal *)attr->stackaddr;
 pint->attr = *attr;
 pint->pt_fork.prepare = ((void *) 0);
 pint->pt_fork.parent = ((void *) 0);
 pint->pt_fork.child = ((void *) 0);
 pint->entry = start_routine;
 pint->arg = arg;
 pint->tid = syscall_create_thread(attr, common_entry);
 return pint->tid;
}

canonical_original_code:
static inline int pthread_internal_create(struct pthread_attr *attr, void *(*start_routine)(void *), void *arg)
{
 struct pthread_internal *pint;
 if(attr->stackaddr == ((void *) 0))
 {
  attr->stackaddr = malloc(0x2000);
  if(!attr->stackaddr)
   return -0x31;
  attr->stack_size = 0x2000;
 }
 pint = (struct pthread_internal *)attr->stackaddr;
 pint->attr = *attr;
 pint->pt_fork.prepare = ((void *) 0);
 pint->pt_fork.parent = ((void *) 0);
 pint->pt_fork.child = ((void *) 0);
 pint->entry = start_routine;
 pint->arg = arg;
 pint->tid = syscall_create_thread(attr, common_entry);
 return pint->tid;
}

variable_types:
arg
void *

user_defined_types: struct sched_param { int sched_priority; }


decompiled_code:
__int64 pthread_self()
{
return syscall_get_tid();
}

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

original_code:
pthread_t pthread_self(void)
{
 return syscall_get_tid();
}

canonical_original_code:
int pthread_self()
{
 return syscall_get_tid();
}


decompiled_code:
void __fastcall __noreturn pthread_exit(unsigned int *a1)
{
syscall_destroy_thread_isra_0(*a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(unsigned int *a1)
{
func7(*a1);
}

original_code:
void pthread_exit(void *value_ptr)
{
 int *val = (int *)value_ptr;
 syscall_destroy_thread(*val);
}

variable_types:
val
int *


decompiled_code:
void __noreturn common_entry()
{
__int64 v0; // rax
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = get_pinternal();
(*(void (__fastcall **)(_QWORD))(v0 + 48))(*(_QWORD *)(v0 + 56));
pthread_exit(v1);
}

canonical_decompiled_code:
void __noreturn func10()
{
__int64 v0; // rax
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = func2();
(*(void (__fastcall **)(_QWORD))(v0 + 48))(*(_QWORD *)(v0 + 56));
func9(v1);
}

original_code:
void common_entry()
{
 struct pthread_internal *inter;
 int value;
 inter = get_pinternal();
 inter->entry(inter->arg);
 pthread_exit(&value);
}

variable_types: value int


decompiled_code:
__int64 __fastcall pthread_create(int *a1, const __m128i *a2, __int64 a3, __int64 a4)
{
int v6; // ebx
__int64 result; // rax
__m128i v8[4]; // [rsp+0h] [rbp-48h] BYREF

check_attr((__int64)v8, a2);
v6 = pthread_internal_create(v8, a3, a4);
if ( v6 < 0 )
{
if ( !a2->m128i_i64[1] )
free((void *)v8[0].m128i_i64[1]);
result = (unsigned int)-v6;
}
else
{
result = 0LL;
if ( a1 )
*a1 = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, const __m128i *a2, __int64 a3, __int64 a4)
{
int v6; // ebx
__int64 result; // rax
__m128i v8[4]; // [rsp+0h] [rbp-48h] BYREF

func3((__int64)v8, a2);
v6 = func6(v8, a3, a4);
if ( v6 < 0 )
{
if ( !a2->m128i_i64[1] )
free((void *)v8[0].m128i_i64[1]);
result = (unsigned int)-v6;
}
else
{
result = 0LL;
if ( a1 )
*a1 = v6;
}
return result;
}

original_code:
int pthread_create(pthread_t *__restrict thread,
       const pthread_attr_t *__restrict attr,
       void *(* start_routine)(void *), void *__restrict arg)
{
 pthread_attr_t nattr;
 pthread_t tid;
 check_attr(&nattr, attr);
 tid = pthread_internal_create(&nattr, start_routine, arg);
 if(tid < 0)
 {
  if(!attr->stackaddr)
   free(nattr.stackaddr);
  return -tid;
 }
 if(thread)
  *thread = tid;
 return 0;
}

canonical_original_code:
int pthread_create(int *thread, struct pthread_attr *attr, void *(*start_routine)(void *), void *arg)
{
 struct pthread_attr nattr;
 int tid;
 check_attr(&nattr, attr);
 tid = pthread_internal_create(&nattr, start_routine, arg);
 if(tid < 0)
 {
  if(!attr->stackaddr)
   free(nattr.stackaddr);
  return -tid;
 }
 if(thread)
  *thread = tid;
 return 0;
}

variable_types:
thread
int *

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; }


decompiled_code:
__int64 __fastcall pthread_join(__int64 a1)
{
int v1; // eax
_DWORD **v2; // rdx
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-4h] BYREF

v4 = 0;
v1 = syscall_thread_join_constprop_0(a1, &v4);
if ( v1 < 0 )
return (unsigned int)-v1;
result = 0LL;
if ( v2 )
**v2 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // eax
_DWORD **v2; // rdx
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-4h] BYREF

v4 = 0;
v1 = func4(a1, &v4);
if ( v1 < 0 )
return (unsigned int)-v1;
result = 0LL;
if ( v2 )
**v2 = v4;
return result;
}

original_code:
int pthread_join(pthread_t thread, void **value_ptr)
{
 int ret, value = 0;
 int **val;
 val = (int **)value_ptr;
 ret = syscall_thread_join(thread, &value);
 if(ret < 0)
 {
  return -ret;
 }
 if(value_ptr)
  **val = value;
 return 0;
}

canonical_original_code:
int pthread_join(int thread, void **value_ptr)
{
 int ret; int value = 0;
 int **val;
 val = (int **)value_ptr;
 ret = syscall_thread_join(thread, &value);
 if(ret < 0)
 {
  return -ret;
 }
 if(value_ptr)
  **val = value;
 return 0;
}

variable_types: thread int

variable_types: ret int

variable_types:
val
int **


decompiled_code:
_BOOL8 __fastcall pthread_equal(int a1, int a2)
{
return a1 != a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1, int a2)
{
return a1 != a2;
}

original_code:
int pthread_equal(pthread_t t1, pthread_t t2)
{
 if(t1 == t2)
  return 0;
 return 1;
}

canonical_original_code:
int pthread_equal(int t1, int t2)
{
 if(t1 == t2)
  return 0;
 return 1;
}


decompiled_code:
__int64 __fastcall pthread_atfork(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = (_QWORD *)get_pinternal();
v2[3] = a1;
v2[4] = a2;
v2[5] = v3;
return 0LL;
}

original_code:
int pthread_atfork(void (*prepare)(void), void (*parent)(void),
       void (*child)(void))
{
 struct pthread_internal *inter;
 inter = get_pinternal();
 inter->pt_fork.prepare = prepare;
 inter->pt_fork.parent = parent;
 inter->pt_fork.child = child;
 return 0;
}

canonical_original_code:
int pthread_atfork(void (*prepare)(), void (*parent)(), void (*child)())
{
 struct pthread_internal *inter;
 inter = get_pinternal();
 inter->pt_fork.prepare = prepare;
 inter->pt_fork.parent = parent;
 inter->pt_fork.child = child;
 return 0;
}

variable_types:
prepare
void (*)()

variable_types:
parent
void (*)()

variable_types:
child
void (*)()


decompiled_code:
void arch_thread_init()
{
*((_DWORD *)&stss + 1) = *(_DWORD *)(init_thread + 80LL);
*((_WORD *)&stss + 4) = 16;
LTR_constprop_0();
}

canonical_decompiled_code:
void func1()
{
*((_DWORD *)&stss + 1) = *(_DWORD *)(init_thread + 80LL);
*((_WORD *)&stss + 4) = 16;
func0();
}

original_code:
u32 arch_thread_init()
{
 vm_size_t total_threads;
 struct TSS *tss = &stss[0];
 total_threads = (ending_mem/(0x1000 * 4));
 tss->esp0 = init_thread->stack;
 tss->ss0 = 0x10;
 LTR(0x28);
 return total_threads;
}

canonical_original_code:
unsigned int arch_thread_init()
{
 unsigned int total_threads;
 struct TSS *tss = &stss[0];
 total_threads = (ending_mem/(0x1000 * 4));
 tss->esp0 = init_thread->stack;
 tss->ss0 = 0x10;
 LTR(0x28);
 return total_threads;
}

variable_types: struct TSS { unsigned short back_link; unsigned int esp0; unsigned short ss0; unsigned int esp1; unsigned short ss1; unsigned int esp2; unsigned short ss2; unsigned int cr3; unsigned int eip; unsigned int eflags; unsigned int eax; unsigned int ecx; unsigned int edx; unsigned int ebx; unsigned int esp; unsigned int ebp; unsigned int esi; unsigned int edi; unsigned short es; unsigned short cs; unsigned short ss; unsigned short ds; unsigned short fs; unsigned short gs; unsigned short ldt; unsigned short trace_trap; unsigned short io_bit_map_offset; unsigned int align[38]; } *

return_type: unsigned int


original_code:
void context_create(thread_t thread)
{
 struct context *ctx;
 struct vm_map *map = thread->proc->map;
 ctx = &thread->context;
 ctx->uregs.esp = thread->stack;
 ctx->uregs.cr3 = (u32)map->pmap->pdbr;
 ctx->irqflag = 0;
 ctx->handler = ((void *)0);
}

canonical_original_code:
void context_create(struct thread *thread)
{
 struct context *ctx;
 struct vm_map *map = thread->proc->map;
 ctx = &thread->context;
 ctx->uregs.esp = thread->stack;
 ctx->uregs.cr3 = (unsigned int)map->pmap->pdbr;
 ctx->irqflag = 0;
 ctx->handler = ((void *)0);
}

variable_types: struct thread { struct linked_list { void *next; } thread_list; struct thread *next; struct thread *waiting; struct linked_list runq; int tid; struct context { struct regs { unsigned int eip; unsigned int esp; unsigned int cr3; } uregs; int irqflag; void (*handler)(); } context; unsigned int stack; unsigned int states; struct process { struct linked_list threads; struct linked_list child; struct linked_list proclist; struct vm_map { struct vm_map_entry { struct linked_list entries; unsigned int start; unsigned int end; struct vm_object { struct linked_list page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *object; unsigned short type; unsigned short attr; struct spinlock lock; } *vmentry; struct pmap { struct linked_list plist; unsigned int *pdbr; struct spinlock lock; } *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; } *map; int pid; int uid; int gid; int session; struct process *parent; struct process *next; long start_time; long user_time; long system_time; struct linked_list timer; struct timer { struct linked_list tlist; struct linked_list pproc; unsigned long long timeout; long nextarm; struct sigevent { int sigev_notify; int sigev_signo; union sigval { int sigval_int; void *sigval_ptr; } handler; } sigv; struct thread *owner; int flag; int clkid; int timer_id; struct timer *next; } *alarm; int flag; int status; int exit_status; struct linked_list sigqueue; struct sigaction { int sa_mask; int sa_flags; union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; union sigval si_value; }, void *); } action; } action[32]; struct spinlock siglock; struct stack { void *ss_sp; unsigned int ss_size; int ss_flags; } ss; struct syncstruct { struct linked_list syncs; long id; } sync; struct fd { int fd_max; int fd_hint; unsigned int bitmap; struct inodev { unsigned int inode; unsigned int device; } cwd; char cwdstr[256]; unsigned int fileptr[-1]; struct spinlock lock; } fd; struct spinlock lock; } *proc; struct thread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } attr; int priority_dyn; int bound; int time_slice; int schedule; int exitstat; int sa_mask; int sigpending; struct message { union { unsigned int w3; unsigned int snd_bufsize; } m1; union { unsigned int w4; void *rcv_ptr; } m2; union { unsigned int w5; unsigned int rcv_bufsize; } m3; unsigned int dummy1; int tid; union { unsigned int w2; void *snd_ptr; } m4; unsigned int w1; unsigned short dummy; } msg; struct linked_list rcvq; struct linked_list sndq; int cpu; } *

variable_types: struct context { struct regs { unsigned int eip; unsigned int esp; unsigned int cr3; } uregs; int irqflag; void (*handler)(); } *

variable_types: struct vm_map { struct vm_map_entry { struct linked_list { void *next; } entries; unsigned int start; unsigned int end; struct vm_object { struct linked_list page; struct atomic_t { int value; } ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object { int fd; int blk_size; unsigned int page_size; unsigned int va; unsigned long offset; int map_type; int protection; unsigned int size; int pager_id; unsigned int noload_start; } vn; struct spinlock { int lock; } lock; } *object; unsigned short type; unsigned short attr; struct spinlock lock; } *vmentry; struct pmap { struct linked_list plist; unsigned int *pdbr; struct spinlock lock; } *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; } *

user_defined_types: struct thread { struct linked_list thread_list; struct thread *next; struct thread *waiting; struct linked_list runq; int tid; struct context context; unsigned int stack; unsigned int states; struct process *proc; struct thread_attr attr; int priority_dyn; int bound; int time_slice; int schedule; int exitstat; int sa_mask; int sigpending; struct message msg; struct linked_list rcvq; struct linked_list sndq; int cpu; }

user_defined_types: struct context { struct regs uregs; int irqflag; void (*handler)(); }

user_defined_types: struct vm_map { struct vm_map_entry *vmentry; struct pmap *pmap; unsigned int size; struct atomic_t ref_count; unsigned int start; unsigned int end; struct vm_map_entry *hint; unsigned int private; int attr; struct spinlock vmlock; }

user_defined_types: struct thread_attr { int flags; struct sched_param prio; void *stackaddr; unsigned int stack_size; int policy; }

user_defined_types: struct process { struct linked_list threads; struct linked_list child; struct linked_list proclist; struct vm_map *map; int pid; int uid; int gid; int session; struct process *parent; struct process *next; long start_time; long user_time; long system_time; struct linked_list timer; struct timer *alarm; int flag; int status; int exit_status; struct linked_list sigqueue; struct sigaction action[32]; struct spinlock siglock; struct stack ss; struct syncstruct sync; struct fd fd; struct spinlock lock; }

user_defined_types: struct vm_map_entry { struct linked_list entries; unsigned int start; unsigned int end; struct vm_object *object; unsigned short type; unsigned short attr; struct spinlock lock; }

user_defined_types: struct fd { int fd_max; int fd_hint; unsigned int bitmap; struct inodev cwd; char cwdstr[256]; unsigned int fileptr[-1]; struct spinlock lock; }

user_defined_types: struct timer { struct linked_list tlist; struct linked_list pproc; unsigned long long timeout; long nextarm; struct sigevent sigv; struct thread *owner; int flag; int clkid; int timer_id; struct timer *next; }

user_defined_types: struct sigaction { int sa_mask; int sa_flags; union handler action; }

user_defined_types: struct vm_object { struct linked_list page; struct atomic_t ref_count; struct atomic_t npages; unsigned int size; struct vm_object *shadow; int attribute; struct vn_object vn; struct spinlock lock; }

user_defined_types: struct sigevent { int sigev_notify; int sigev_signo; union sigval handler; }

user_defined_types: union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo, void *); }


original_code:
int pthread_attr_init(pthread_attr_t *attr)
{
 attr->flags = 0x0008 | 0x0020 | 0x0001;
 attr->policy = 4;
 attr->prio.sched_priority = 24;
 attr->stackaddr = ((void *) 0);
 attr->stack_size = 0;
 return 0;
}

canonical_original_code:
int pthread_attr_init(struct pthread_attr *attr)
{
 attr->flags = 0x0008 | 0x0020 | 0x0001;
 attr->policy = 4;
 attr->prio.sched_priority = 24;
 attr->stackaddr = ((void *) 0);
 attr->stack_size = 0;
 return 0;
}

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; } *


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

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

original_code:
int pthread_attr_destroy(pthread_attr_t *attr)
{
 return 0;
}

canonical_original_code:
int pthread_attr_destroy(struct pthread_attr *attr)
{
 return 0;
}


decompiled_code:
__int64 __fastcall pthread_attr_getinheritsched(_DWORD *a1, int *a2)
{
*a2 = *a1 & 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int *a2)
{
*a2 = *a1 & 3;
return 0LL;
}

original_code:
int pthread_attr_getinheritsched(const pthread_attr_t *__restrict attr,
       int *__restrict inheritsched)
{
 *inheritsched = attr->flags & 0x03;
 return 0;
}

canonical_original_code:
int pthread_attr_getinheritsched(struct pthread_attr *attr, int *inheritsched)
{
 *inheritsched = attr->flags & 0x03;
 return 0;
}

variable_types:
inheritsched
int *


decompiled_code:
__int64 __fastcall pthread_attr_getschedparam(__int64 a1, _DWORD *a2)
{
*a2 = *(_DWORD *)(a1 + 4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
*a2 = *(_DWORD *)(a1 + 4);
return 0LL;
}

original_code:
int pthread_attr_getschedparam(const pthread_attr_t *__restrict attr,
       struct sched_param *__restrict param)
{
 *param = attr->prio;
 return 0;
}

canonical_original_code:
int pthread_attr_getschedparam(struct pthread_attr *attr, struct sched_param *param)
{
 *param = attr->prio;
 return 0;
}

variable_types:
param
struct sched_param *


decompiled_code:
__int64 __fastcall pthread_attr_setschedparam(__int64 a1, _DWORD *a2)
{
*(_DWORD *)(a1 + 4) = *a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
*(_DWORD *)(a1 + 4) = *a2;
return 0LL;
}

original_code:
int pthread_attr_setschedparam(pthread_attr_t *__restrict attr,
       const struct sched_param *__restrict param)
{
 if(param->sched_priority < 4
  && param->sched_priority > 127)
  return 0x1d;
 attr->prio = *param;
 return 0;
}

canonical_original_code:
int pthread_attr_setschedparam(struct pthread_attr *attr, struct sched_param *param)
{
 if(param->sched_priority < 4
  && param->sched_priority > 127)
  return 0x1d;
 attr->prio = *param;
 return 0;
}


decompiled_code:
__int64 __fastcall pthread_attr_getschedpolicy(__int64 a1, _DWORD *a2)
{
*a2 = *(_DWORD *)(a1 + 20);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2)
{
*a2 = *(_DWORD *)(a1 + 20);
return 0LL;
}

original_code:
int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict attr,
       int *__restrict policy)
{
 *policy = attr->policy;
 return 0;
}

canonical_original_code:
int pthread_attr_getschedpolicy(struct pthread_attr *attr, int *policy)
{
 *policy = attr->policy;
 return 0;
}

variable_types:
policy
int *


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

if ( (unsigned int)(a2 - 1) <= 1 || (result = 29LL, a2 == 4) )
{
*(_DWORD *)(a1 + 20) = a2;
result = 0LL;
}
return result;
}

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

if ( (unsigned int)(a2 - 1) <= 1 || (result = 29LL, a2 == 4) )
{
*(_DWORD *)(a1 + 20) = a2;
result = 0LL;
}
return result;
}

original_code:
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
{
 if( (policy != 1) &&
  (policy != 2) &&
  (policy != 4))
  return 0x1d;
 attr->policy = policy;
 return 0;
}

canonical_original_code:
int pthread_attr_setschedpolicy(struct pthread_attr *attr, int policy)
{
 if( (policy != 1) &&
  (policy != 2) &&
  (policy != 4))
  return 0x1d;
 attr->policy = policy;
 return 0;
}

variable_types: policy int


decompiled_code:
__int64 __fastcall pthread_attr_getscope(_DWORD *a1, int *a2)
{
*a2 = *a1 & 0xC;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int *a2)
{
*a2 = *a1 & 0xC;
return 0LL;
}

original_code:
int pthread_attr_getscope(const pthread_attr_t *__restrict attr,
       int *__restrict contentionscope)
{
 *contentionscope = attr->flags & 0x0C;
 return 0;
}

canonical_original_code:
int pthread_attr_getscope(struct pthread_attr *attr, int *contentionscope)
{
 *contentionscope = attr->flags & 0x0C;
 return 0;
}

variable_types:
contentionscope
int *


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

result = 29LL;
if ( ((a2 - 4) & 0xFFFFFFFB) == 0 )
{
*a1 |= a2;
result = 0LL;
}
return result;
}

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

result = 29LL;
if ( ((a2 - 4) & 0xFFFFFFFB) == 0 )
{
*a1 |= a2;
result = 0LL;
}
return result;
}

original_code:
int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)
{
 if((contentionscope != 0x0008) &&
  (contentionscope != 0x0004))
  return 0x1d;
 attr->flags |= contentionscope;
 return 0;
}

canonical_original_code:
int pthread_attr_setscope(struct pthread_attr *attr, int contentionscope)
{
 if((contentionscope != 0x0008) &&
  (contentionscope != 0x0004))
  return 0x1d;
 attr->flags |= contentionscope;
 return 0;
}

variable_types: contentionscope int


decompiled_code:
__int64 __fastcall pthread_attr_getstackaddr(__int64 a1, _QWORD **a2)
{
**a2 = a1 + 8;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _QWORD **a2)
{
**a2 = a1 + 8;
return 0LL;
}

original_code:
int pthread_attr_getstackaddr(const pthread_attr_t *__restrict attr,
       void **__restrict stackaddr)
{
 unsigned long **stk = (unsigned long **)stackaddr;
 **stk = (unsigned long)&attr->stackaddr;
 return 0;
}

canonical_original_code:
int pthread_attr_getstackaddr(struct pthread_attr *attr, void **stackaddr)
{
 unsigned long **stk = (unsigned long **)stackaddr;
 **stk = (unsigned long)&attr->stackaddr;
 return 0;
}

variable_types:
stackaddr
void **

variable_types:
stk
unsigned long **


decompiled_code:
__int64 __fastcall pthread_attr_setstackaddr(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
return 0LL;
}

original_code:
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
{
 attr->stackaddr = stackaddr;
 return 0;
}

canonical_original_code:
int pthread_attr_setstackaddr(struct pthread_attr *attr, void *stackaddr)
{
 attr->stackaddr = stackaddr;
 return 0;
}

variable_types:
stackaddr
void *


decompiled_code:
__int64 __fastcall pthread_attr_getstack(__int64 a1, _QWORD **a2)
{
__int64 v2; // rcx
_DWORD *v3; // rdx

pthread_attr_getstackaddr(a1, a2);
*v3 = *(_DWORD *)(v2 + 16);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _QWORD **a2)
{
__int64 v2; // rcx
_DWORD *v3; // rdx

func9(a1, a2);
*v3 = *(_DWORD *)(v2 + 16);
return 0LL;
}

original_code:
int pthread_attr_getstack(const pthread_attr_t *__restrict attr,
       void **__restrict stackaddr, size_t *__restrict stacksize)
{
 pthread_attr_getstackaddr(attr, stackaddr);
 *stacksize = attr->stack_size;
 return 0;
}

canonical_original_code:
int pthread_attr_getstack(struct pthread_attr *attr, void **stackaddr, unsigned int *stacksize)
{
 pthread_attr_getstackaddr(attr, stackaddr);
 *stacksize = attr->stack_size;
 return 0;
}

variable_types:
stacksize
unsigned int *


decompiled_code:
__int64 __fastcall pthread_attr_setstack(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v4; // edx

result = 29LL;
if ( a3 > 0xFFF )
{
pthread_attr_setstackaddr(a1, a2);
*(_DWORD *)(a1 + 16) = v4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v4; // edx

result = 29LL;
if ( a3 > 0xFFF )
{
func10(a1, a2);
*(_DWORD *)(a1 + 16) = v4;
result = 0LL;
}
return result;
}

original_code:
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
       size_t stacksize)
{
 if(stacksize < 0x1000)
  return 0x1d;
 pthread_attr_setstackaddr(attr, stackaddr);
 attr->stack_size = stacksize;
 return 0;
}

canonical_original_code:
int pthread_attr_setstack(struct pthread_attr *attr, void *stackaddr, unsigned int stacksize)
{
 if(stacksize < 0x1000)
  return 0x1d;
 pthread_attr_setstackaddr(attr, stackaddr);
 attr->stack_size = stacksize;
 return 0;
}

variable_types:
stacksize
unsigned int


decompiled_code:
__int64 __fastcall pthread_attr_getdetachstate(_DWORD *a1, int *a2)
{
*a2 = *a1 & 0x30;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, int *a2)
{
*a2 = *a1 & 0x30;
return 0LL;
}

original_code:
int pthread_attr_getdetachstate(const pthread_attr_t *attr,
       int *detachstate)
{
 *detachstate = attr->flags & 0x30;
 return 0;
}

canonical_original_code:
int pthread_attr_getdetachstate(struct pthread_attr *attr, int *detachstate)
{
 *detachstate = attr->flags & 0x30;
 return 0;
}

variable_types:
detachstate
int *


decompiled_code:
__int64 __fastcall pthread_attr_setdetachstate(_DWORD *a1, int a2)
{
*a1 |= a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, int a2)
{
*a1 |= a2;
return 0LL;
}

original_code:
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
{
 attr->flags |= detachstate;
 return 0;
}

canonical_original_code:
int pthread_attr_setdetachstate(struct pthread_attr *attr, int detachstate)
{
 attr->flags |= detachstate;
 return 0;
}

variable_types: detachstate int


decompiled_code:
// attributes: thunk
__int64 __fastcall pthread_attr_setinheritsched(_DWORD *a1, int a2)
{
return pthread_attr_setdetachstate(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(_DWORD *a1, int a2)
{
return func14(a1, a2);
}

original_code:
int pthread_attr_setinheritsched(pthread_attr_t *attr,
       int inheritsched)
{
 attr->flags |= inheritsched;
 return 0;
}

canonical_original_code:
int pthread_attr_setinheritsched(struct pthread_attr *attr, int inheritsched)
{
 attr->flags |= inheritsched;
 return 0;
}

variable_types: inheritsched int


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

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

original_code:
int pthread_attr_getguardsize(const pthread_attr_t *__restrict attr,
       size_t *__restrict guardsize)
{
 return 0;
}

canonical_original_code:
int pthread_attr_getguardsize(struct pthread_attr *attr, unsigned int *guardsize)
{
 return 0;
}

variable_types:
guardsize
unsigned int *


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

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

original_code:
int pthread_attr_setguardsize(pthread_attr_t *attr,
       size_t guardsize)
{
 return 0;
}

canonical_original_code:
int pthread_attr_setguardsize(struct pthread_attr *attr, unsigned int guardsize)
{
 return 0;
}

variable_types:
guardsize
unsigned int


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

if ( a1 <= 2 )
{
result = 127LL;
if ( a1 > 0 )
return result;
goto LABEL_5;
}
result = 45LL;
if ( a1 != 4 )
{
LABEL_5:
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 <= 2 )
{
result = 127LL;
if ( a1 > 0 )
return result;
goto LABEL_5;
}
result = 45LL;
if ( a1 != 4 )
{
LABEL_5:
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sched_get_priority_max(int policy)
{
 int max;
 switch(policy)
 {
  case 4:
   max = 45;
   break;
  case 1:
  case 2:
   max = 127;
   break;
  default:
   errno = 0x1d;
   return -1;
 }
 return max;
}

variable_types: max int


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

result = (unsigned int)a1;
if ( a1 <= 2 )
{
if ( a1 > 0 )
return 88LL;
LABEL_5:
errno = 29;
return 0xFFFFFFFFLL;
}
if ( a1 != 4 )
goto LABEL_5;
return result;
}

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

result = (unsigned int)a1;
if ( a1 <= 2 )
{
if ( a1 > 0 )
return 88LL;
LABEL_5:
errno = 29;
return 0xFFFFFFFFLL;
}
if ( a1 != 4 )
goto LABEL_5;
return result;
}

original_code:
int sched_get_priority_min(int policy)
{
 int max;
 switch(policy)
 {
  case 4:
   max = 4;
   break;
  case 1:
  case 2:
   max = 88;
   break;
  default:
   errno = 0x1d;
   return -1;
 }
 return max;
}


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

result = syscall_sched_get_constprop_0();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = func2();
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sched_getparam(pid_t pid, struct sched_param *param)
{
 int ret;
 ret = syscall_sched_get(pid, param, 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int sched_getparam(int pid, struct sched_param *param)
{
 int ret;
 ret = syscall_sched_get(pid, param, 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

variable_types: pid int

variable_types: struct sched_param { int sched_priority; } *

variable_types: ret int


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

result = syscall_sched_get_constprop_0(a1, 0LL);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = func2(a1, 0LL);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sched_getscheduler(pid_t pid)
{
 int ret;
 ret = syscall_sched_get(pid, ((void *) 0), 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int sched_getscheduler(int pid)
{
 int ret;
 ret = syscall_sched_get(pid, ((void *) 0), 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}


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

result = syscall_sched_set_constprop_0(a1, 0LL, a2);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = func1(a1, 0LL, a2);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sched_setparam(pid_t pid, const struct sched_param *param)
{
 int ret;
 ret = syscall_sched_set(pid, 0, param, 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int sched_setparam(int pid, struct sched_param *param)
{
 int ret;
 ret = syscall_sched_set(pid, 0, param, 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}


decompiled_code:
__int64 sched_yield()
{
return syscall_sched_yield();
}

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

original_code:
int sched_yield(void)
{
 return syscall_sched_yield();
}

canonical_original_code:
int sched_yield()
{
 return syscall_sched_yield();
}


decompiled_code:
__int64 __fastcall sched_setscheduler(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = syscall_sched_set_constprop_0(a1, a2, a3);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = func1(a1, a2, a3);
if ( (int)result < 0 )
{
errno = -(int)result;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sched_setscheduler(pid_t pid, int policy,
       const struct sched_param *param)
{
 int ret;
 ret = syscall_sched_set(pid, policy, param, 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

canonical_original_code:
int sched_setscheduler(int pid, int policy, struct sched_param *param)
{
 int ret;
 ret = syscall_sched_set(pid, policy, param, 2);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return ret;
}

variable_types: policy int


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

result = 18LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

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

result = 18LL;
__asm { int 30h; (NOT A VECTOR!) FAR JMP instruction for CP/M-style calls }
return result;
}

original_code:
static inline int syscall_sched_yield()
{
 register int ret;
 asm volatile (
  "int $0x30\n\t"
  :"=a"(ret)
  :"0"(18)
  );
 return ret;
}


lseek

decompiled_code:
__int64 __fastcall lseek(unsigned int a1, __int64 a2, int a3)
{
__int64 v4; // rbp
int v5; // eax
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-58h] BYREF
__int64 v8; // [rsp+8h] [rbp-50h]

v4 = (unsigned int)pthread_self();
v5 = get_openfile(v4, a1, &v7);
if ( v5 < 0 )
{
errno = -v5;
result = -1LL;
}
else
{
switch ( a3 )
{
case 3:
v8 = a2;
goto LABEL_6;
case 1:
v8 += a2;
goto LABEL_6;
case 2:
v8 = -1LL;
LABEL_6:
syscall_fd_alloc_isra_0((unsigned int)v4, a1, &v7);
return v8;
}
errno = 29;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, int a3)
{
__int64 v4; // rbp
int v5; // eax
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-58h] BYREF
__int64 v8; // [rsp+8h] [rbp-50h]

v4 = (unsigned int)pthread_self();
v5 = get_openfile(v4, a1, &v7);
if ( v5 < 0 )
{
errno = -v5;
result = -1LL;
}
else
{
switch ( a3 )
{
case 3:
v8 = a2;
goto LABEL_6;
case 1:
v8 += a2;
goto LABEL_6;
case 2:
v8 = -1LL;
LABEL_6:
func0((unsigned int)v4, a1, &v7);
return v8;
}
errno = 29;
result = -1LL;
}
return result;
}

original_code:
off_t lseek(int fildes, off_t offset, int whence)
{
 struct file file;
 int ret;
 pthread_t tid = pthread_self();
 ret = get_openfile(tid, fildes, &file);
 if(ret < 0)
 {
  ((errno) = (-ret));
  return -1;
 }
 if(whence == 3)
  file.f_offset = offset;
 else if(whence == 1)
  file.f_offset += offset;
 else if(whence == 2)
  file.f_offset = -1;
 else
 {
  ((errno) = (0x1d));
  return -1;
 }
 ret = syscall_fd_alloc(tid, fildes, &file);
 return file.f_offset;
}

canonical_original_code:
unsigned long lseek(int fildes, unsigned long offset, int whence)
{
 struct file file;
 int ret;
 int tid = pthread_self();
 ret = get_openfile(tid, fildes, &file);
 if(ret < 0)
 {
  ((errno) = (-ret));
  return -1;
 }
 if(whence == 3)
  file.f_offset = offset;
 else if(whence == 1)
  file.f_offset += offset;
 else if(whence == 2)
  file.f_offset = -1;
 else
 {
  ((errno) = (0x1d));
  return -1;
 }
 ret = syscall_fd_alloc(tid, fildes, &file);
 return file.f_offset;
}

variable_types: fildes int

variable_types:
offset
unsigned long

variable_types: whence int

variable_types: struct file { int f_access; unsigned long f_offset; int f_ref; struct indev { int inode; unsigned long dev; } vnode; }

variable_types: tid int

return_type: unsigned long

user_defined_types: struct file { int f_access; unsigned long f_offset; int f_ref; struct indev vnode; }


outportb

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

result = a1;
__outbyte(a2, a1);
return result;
}

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

result = a1;
__outbyte(a2, a1);
return result;
}

original_code:
static inline void outportb(unsigned char value, unsigned short port)
{
 __asm__ volatile(
  "outb %%al, %%dx"
  :
  :"a" (value),"d" (port)
  );
}

variable_types:
value
unsigned char

variable_types:
port
unsigned short


inportb

decompiled_code:
unsigned __int8 __fastcall inportb(unsigned __int16 a1)
{
return __inbyte(a1);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func1(unsigned __int16 a1)
{
return __inbyte(a1);
}

original_code:
static inline unsigned char inportb(unsigned short port)
{
 register unsigned char ret;
 __asm__ volatile
   (
   "inb %%dx,%%al"
   :"=a" (ret)
   :"d" (port)
   );
 return ret;
}

variable_types:
ret
unsigned char

return_type: unsigned char


decompiled_code:
unsigned __int8 check_kbd()
{
unsigned __int8 result; // al
int v1; // ecx

do
result = inportb(0x64u);
while ( (result & 2) != 0 && v1 != 1 );
return result;
}

canonical_decompiled_code:
unsigned __int8 func2()
{
unsigned __int8 result; // al
int v1; // ecx

do
result = func1(0x64u);
while ( (result & 2) != 0 && v1 != 1 );
return result;
}

original_code:
static inline void check_kbd()
{
 int loop;
 for(loop = 0; loop < 100000; loop++)
  if(!(inportb(0x64) & 2))
   break;
}

variable_types: loop int


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

v0 = inportb(0x61u);
return outportb(v0 | 0x80u, 0x61u);
}

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

v0 = func1(0x61u);
return func0(v0 | 0x80u, 0x61u);
}

original_code:
static inline void keyb_disable()
{
 unsigned char data;
 data = inportb(0x61);
 data |= 0x80;
 outportb(data, 0x61);
}

variable_types:
data
unsigned char


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

v0 = inportb(0x61u);
return outportb(v0 & 0x7F, 0x61u);
}

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

v0 = func1(0x61u);
return func0(v0 & 0x7F, 0x61u);
}

original_code:
static inline void keyb_enable()
{
 unsigned char data;
 data = inportb(0x61);
 data &= ~0x80;
 outportb(data, 0x61);
}


decompiled_code:
__int64 set_led()
{
unsigned __int8 v0; // r8

check_kbd();
outportb(0xEDu, 0x64u);
return outportb(v0, 0x64u);
}

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

func2();
func0(0xEDu, 0x64u);
return func0(v0, 0x64u);
}

original_code:
static inline void set_led(unsigned char mask)
{
 check_kbd();
 outportb(0xED, 0x64);
 outportb(mask, 0x64);
}

variable_types:
mask
unsigned char


original_code:
static inline void termqueue_init(struct termqueue *q)
{
 q->last_scancode = 0;
 q->end = 0;
 q->keyflag = 0;
 q->led = 0;
}

variable_types: struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; } *


decompiled_code:
__int64 __fastcall scancode_check(unsigned __int8 a1)
{
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( a1 > 0xEDu )
result = (unsigned int)-(((1LL << (a1 + 18)) & 0x35001) != 0);
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( a1 > 0xEDu )
result = (unsigned int)-(((1LL << (a1 + 18)) & 0x35001) != 0);
return result;
}

original_code:
static inline int scancode_check(unsigned char scancode)
{
 switch(scancode)
 {
  case 0x00:
  case 0xFF:
  case 0xEE:
  case 0xFA:
  case 0xFC:
  case 0xFE:
   return -1;
  default:
   return 0;
 }
}

variable_types:
scancode
unsigned char


decompiled_code:
_BOOL8 __fastcall have_nlock_effect(char a1)
{
return (unsigned __int8)(a1 - 71) <= 0xCu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(char a1)
{
return (unsigned __int8)(a1 - 71) <= 0xCu;
}

original_code:
static inline int have_nlock_effect(unsigned char scancode)
{
 if((scancode >= 71) && (scancode <= 83))
  return 1;
 return 0;
}


decompiled_code:
unsigned __int64 __fastcall have_caps_effect(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x32u )
result = (0x7F07FC3FF0000uLL >> a1) & 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x32u )
result = (0x7F07FC3FF0000uLL >> a1) & 1;
return result;
}

original_code:
static inline int have_caps_effect(unsigned char scancode)
{
 if((scancode >= 16) && (scancode <= 25))
  return 1;
 else if((scancode >= 30) && (scancode <= 38))
  return 1;
 else if((scancode >= 44) && (scancode <= 50))
  return 1;
 return 0;
}


decompiled_code:
unsigned __int64 __fastcall have_shift_effect(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x35u )
result = (0x3FF3FFCFFF3FFCuLL >> a1) & 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 <= 0x35u )
result = (0x3FF3FFCFFF3FFCuLL >> a1) & 1;
return result;
}

original_code:
static inline int have_shift_effect(unsigned char scancode)
{
 if((scancode >= 2) && (scancode <= 13))
  return 1;
 else if((scancode >= 16) && (scancode <= 27))
  return 1;
 else if((scancode >= 30) && (scancode <= 41))
  return 1;
 else if((scancode >= 44) && (scancode <= 53))
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall check_extended(__int64 a1, unsigned __int8 *a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // rdx
__int64 result; // rax
__int64 v8; // r9
__int64 v9; // rax
__int64 v10; // rax
int v11; // edi
unsigned int v12; // edi
__int64 v13; // r9
__int64 v14; // rax
__int64 v15; // r8
char v16; // dl
__int64 v17; // r9
char v18; // dl
__int64 v19; // r9
char v20; // dl

v5 = *a2;
if ( (_BYTE)v5 == 0xE0 )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)v5 > 0x46u )
{
if ( (_BYTE)v5 == 0xAA || (_BYTE)v5 == 0xB6 )
{
*(_QWORD *)(a1 + 520) &= 0xFFFFFFFFFFFFFFF9LL;
return 0xFFFFFFFFLL;
}
LABEL_27:
if ( (v5 & 0x80u) == 0LL )
goto LABEL_18;
return 0xFFFFFFFFLL;
}
if ( (unsigned __int8)v5 <= 0x29u )
{
LABEL_18:
v15 = *(_QWORD *)(a1 + 520);
if ( (v15 & 6) != 0 && (unsigned int)have_shift_effect(v5) )
{
*a2 = v16 + 0x80;
v15 = *(_QWORD *)(v17 + 520);
}
if ( (v15 & 8) != 0 && (unsigned int)have_caps_effect(*a2) )
{
*a2 = v18 + 0x80;
v15 = *(_QWORD *)(v19 + 520);
}
result = 0LL;
if ( (v15 & 0x10) != 0 )
{
result = have_nlock_effect(*a2);
if ( (_DWORD)result )
{
result = 0LL;
*a2 = v20 + 0x80;
}
}
return result;
}
switch ( (char)v5 )
{
case '*':
case '6':
*(_QWORD *)(a1 + 520) |= 6uLL;
result = 0xFFFFFFFFLL;
break;
case ':':
v10 = *(_QWORD *)(a1 + 520);
v11 = *(_DWORD *)(a1 + 528);
if ( (v10 & 8) != 0 )
{
v12 = v11 | 4;
*(_QWORD *)(a1 + 520) = v10 & 0xFFFFFFFFFFFFFFF7LL;
}
else
{
v12 = v11 & 0xFFFFFFFB;
*(_QWORD *)(a1 + 520) = v10 | 8;
}
*(_DWORD *)(a1 + 528) = v12;
set_led((unsigned __int8)v12, a2, v5, a4, a5, a1);
result = 0xFFFFFFFFLL;
break;
case 'E':
set_led(*(unsigned __int8 *)(a1 + 528), a2, v5, a4, a5, a1);
v14 = *(_QWORD *)(v13 + 520);
if ( (v14 & 0x10) != 0 )
{
*(_DWORD *)(v13 + 528) |= 2u;
*(_QWORD *)(v13 + 520) = v14 & 0xFFFFFFFFFFFFFFEFLL;
}
else
{
*(_DWORD *)(v13 + 528) &= 0xFFFFFFFD;
*(_QWORD *)(v13 + 520) = v14 | 0x10;
}
result = 0xFFFFFFFFLL;
break;
case 'F':
set_led(*(unsigned __int8 *)(a1 + 528), a2, v5, a4, a5, a1);
v9 = *(_QWORD *)(v8 + 520);
if ( (v9 & 0x20) != 0 )
{
*(_DWORD *)(v8 + 528) |= 1u;
*(_QWORD *)(v8 + 520) = v9 & 0xFFFFFFFFFFFFFFDFLL;
}
else
{
*(_DWORD *)(v8 + 528) &= 0xFFFFFFFE;
*(_QWORD *)(v8 + 520) = v9 | 0x20;
}
result = 0xFFFFFFFFLL;
break;
default:
goto LABEL_27;
}
return result;
}

original_code:
static inline int check_extended(struct termqueue *q,
   unsigned char *ch)
{
 if(*ch == 0xE0)
  return -1;
 switch(*ch)
 {
  case 42:
  case 54:
   q->keyflag |= 0x06;
   return -1;
   break;
  case (42 | 0x80):
  case (54 | 0x80):
   q->keyflag &= ~0x06;
   return -1;
   break;
  case 58:
   if(q->keyflag & 0x08)
   {
    q->keyflag &= ~0x08;
    q->led |= 4;
   }
   else
   {
    q->keyflag |= 0x08;
    q->led &= ~4;
   }
   set_led(q->led);
   return -1;
   break;
  case 69:
   set_led(q->led);
   if(q->keyflag & 0x10)
   {
    q->keyflag &= ~0x10;
    q->led |= 2;
   }
   else
   {
    q->keyflag |= 0x10;
    q->led &= ~2;
   }
   return -1;
   break;
  case 70:
   set_led(q->led);
   if(q->keyflag & 0x20)
   {
    q->keyflag &= ~0x20;
    q->led |= 1;
   }
   else
   {
    q->keyflag |= 0x20;
    q->led &= ~1;
   }
   return -1;
   break;
 }
 if(*ch & 0x80)
  return -1;
 if((q->keyflag & 0x06) && have_shift_effect(*ch))
  *ch = (128 + *ch);
 if((q->keyflag & 0x08) && have_caps_effect(*ch))
  *ch = (128 + *ch);
 if((q->keyflag & 0x10) && have_nlock_effect(*ch))
  *ch = (128 + *ch);
 return 0;
}

variable_types:
ch
unsigned char *

user_defined_types: struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; }


decompiled_code:
__int64 kb_intr()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
unsigned __int8 v4; // al
unsigned __int8 v6[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = ttys + 3168LL * termindex;
keyb_disable();
v6[0] = inportb(0x60u);
if ( (unsigned int)scancode_check(v6[0]) != -1 )
{
if ( (unsigned int)check_extended(v0 + 56, v6, v1, v2, v3) != -1 )
{
v4 = put_ascii(v6[0]);
read_key(v4);
}
LOBYTE(v1) = v6[0];
}
*(_BYTE *)(v0 + 568) = v1;
keyb_enable();
return outportb(0x20u, 0x20u);
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
unsigned __int8 v4; // al
unsigned __int8 v6[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = ttys + 3168LL * termindex;
func3();
v6[0] = func1(0x60u);
if ( (unsigned int)func7(v6[0]) != -1 )
{
if ( (unsigned int)func11(v0 + 56, v6, v1, v2, v3) != -1 )
{
v4 = put_ascii(v6[0]);
read_key(v4);
}
LOBYTE(v1) = v6[0];
}
*(_BYTE *)(v0 + 568) = v1;
func4();
return func0(0x20u, 0x20u);
}

original_code:
void kb_intr()
{
 struct termqueue *q = &(ttys[termindex]).t_input;
 unsigned char scancode, ascii;
 int ret;
 keyb_disable();
 scancode = inportb(0x60);
 ret = scancode_check(scancode);
 if(ret == -1)
  goto done;
 ret = check_extended(q, &scancode);
 if(ret == -1)
  goto done;
 ascii = put_ascii(scancode);
 read_key(ascii);
done:
 q->last_scancode = scancode;
 keyb_enable();
 outportb(0x20, 0x20);
}

canonical_original_code:
void kb_intr()
{
 struct termqueue *q = &(ttys[termindex]).t_input;
 unsigned char scancode; unsigned char ascii;
 int ret;
 keyb_disable();
 scancode = inportb(0x60);
 ret = scancode_check(scancode);
 if(ret == -1)
  goto done;
 ret = check_extended(q, &scancode);
 if(ret == -1)
  goto done;
 ascii = put_ascii(scancode);
 read_key(ascii);
done:
 q->last_scancode = scancode;
 keyb_enable();
 outportb(0x20, 0x20);
}

variable_types:
ascii
unsigned char


decompiled_code:
void keyb_init()
{
__int64 v0; // rbp

v0 = ttys + 3168LL * termindex;
IRQ_request(1LL, kb_intr);
termqueue_init(v0 + 56);
}

canonical_decompiled_code:
void func13()
{
__int64 v0; // rbp

v0 = ttys + 3168LL * termindex;
IRQ_request(1LL, kb_intr);
func6(v0 + 56);
}

original_code:
int keyb_init()
{
 struct termqueue *q = &(ttys[termindex]).t_input;
 IRQ_request(0x01, kb_intr);
 termqueue_init(q);
 return 0;
}


decompiled_code:
__int64 __fastcall alloc_id(int *a1, int *a2)
{
int v2; // er8
int *v3; // rdi
int v4; // edx
int v5; // eax
signed __int32 *v6; // rcx
int v7; // edx
int v8; // er9

v2 = a1[*a2];
if ( v2 == -1 )
{
v2 = *a1;
if ( *a1 == -1 )
{
v3 = a1 + 1;
v4 = 0;
do
{
v2 = *v3++;
++v4;
}
while ( v2 == -1 );
if ( v4 > 128 )
return 0xFFFFFFFFLL;
}
}
v5 = ffc(v2);
_bittestandset(v6, v5);
*a2 = v7;
return (unsigned int)(v8 + v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, int *a2)
{
int v2; // er8
int *v3; // rdi
int v4; // edx
int v5; // eax
signed __int32 *v6; // rcx
int v7; // edx
int v8; // er9

v2 = a1[*a2];
if ( v2 == -1 )
{
v2 = *a1;
if ( *a1 == -1 )
{
v3 = a1 + 1;
v4 = 0;
do
{
v2 = *v3++;
++v4;
}
while ( v2 == -1 );
if ( v4 > 128 )
return 0xFFFFFFFFLL;
}
}
v5 = func0(v2);
_bittestandset(v6, v5);
*a2 = v7;
return (unsigned int)(v8 + v5);
}

original_code:
static inline int alloc_id(unsigned int *bitmap, int *hintptr)
{
 register int index;
 register int hint = *hintptr;
 if(bitmap[hint] == 0xFFFFFFFF)
 {
  hint = 0;
  while(bitmap[hint] == 0xFFFFFFFF)
   hint++;
  if(hint > (4096/32))
   return -1;
 }
 index = ffc(bitmap[hint]);
 { asm volatile ( "btsl %1, %0" :"=m"(*&bitmap[hint]) :"Ir"(index) ); };
 index += hint * 32;
 *hintptr = hint;
    return index;
}

variable_types:
bitmap
unsigned int *

variable_types:
hintptr
int *

variable_types: index int

variable_types: hint int


decompiled_code:
__int64 __fastcall dealloc_id(int a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

result = (unsigned int)(a1 / 32);
_bittestandreset((signed __int32 *)(a2 + 4LL * (int)result), a1 % 32);
*a3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

result = (unsigned int)(a1 / 32);
_bittestandreset((signed __int32 *)(a2 + 4LL * (int)result), a1 % 32);
*a3 = result;
return result;
}

original_code:
static inline void dealloc_id(int id, unsigned int *bitmap, int *hintptr)
{
 register int hint = *hintptr, index;
 hint = id / 32;
 index = id % 32;
 { asm volatile( "btrl %1, %0" :"=m"(*&bitmap[hint]) :"Ir"(index) ); };
 *hintptr = hint;
}

canonical_original_code:
static inline void dealloc_id(int id, unsigned int *bitmap, int *hintptr)
{
 register int hint = *hintptr; register int index;
 hint = id / 32;
 index = id % 32;
 { asm volatile( "btrl %1, %0" :"=m"(*&bitmap[hint]) :"Ir"(index) ); };
 *hintptr = hint;
}

variable_types: id int


decompiled_code:
__int64 id_init()
{
pidbitmap = (unsigned int)kmem_alloc(4096LL);
tidbitmap = (unsigned int)kmem_alloc(4096LL);
timeridbitmap = (unsigned int)kmem_alloc(4096LL);
memset_constprop_0((void *)timeridbitmap);
memset_constprop_0((void *)pidbitmap);
return memset_constprop_0((void *)tidbitmap);
}

canonical_decompiled_code:
__int64 func4()
{
pidbitmap = (unsigned int)kmem_alloc(4096LL);
tidbitmap = (unsigned int)kmem_alloc(4096LL);
timeridbitmap = (unsigned int)kmem_alloc(4096LL);
func3((void *)timeridbitmap);
func3((void *)pidbitmap);
return func3((void *)tidbitmap);
}

original_code:
void id_init()
{
 pidbitmap = (unsigned int *)kmem_alloc(4096);
 tidbitmap = (unsigned int *)kmem_alloc(4096);
 timeridbitmap = (unsigned int *)kmem_alloc(4096);
 memset(timeridbitmap, 0, 4096);
 memset(pidbitmap, 0, 4096);
 memset(tidbitmap, 0, 4096);
}


decompiled_code:
__int64 alloc_pid()
{
return (unsigned int)alloc_id((int *)pidbitmap, (int *)&pidhint) + 500;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)func1((int *)pidbitmap, (int *)&pidhint) + 500;
}

original_code:
int alloc_pid()
{
 return (500 + alloc_id(pidbitmap, &pidhint));
}


decompiled_code:
__int64 alloc_tid()
{
return (unsigned int)alloc_id((int *)tidbitmap, &tidhint) + 500;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)func1((int *)tidbitmap, &tidhint) + 500;
}

original_code:
int alloc_tid()
{
 return (500 + alloc_id(tidbitmap, &tidhint));
}


decompiled_code:
__int64 __fastcall dealloc_pid(int a1)
{
return dealloc_id(a1 - 500, pidbitmap, pidhint);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return func2(a1 - 500, pidbitmap, pidhint);
}

original_code:
void dealloc_pid(pid_t pid)
{
 dealloc_id(pid - 500, pidbitmap, &pidhint);
}

canonical_original_code:
void dealloc_pid(int pid)
{
 dealloc_id(pid - 500, pidbitmap, &pidhint);
}

variable_types: pid int


decompiled_code:
__int64 __fastcall dealloc_tid(int a1)
{
return dealloc_id(a1 - 500, tidbitmap, &tidhint);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return func2(a1 - 500, tidbitmap, &tidhint);
}

original_code:
void dealloc_tid(tid_t tid)
{
 dealloc_id(tid - 500, tidbitmap, &tidhint);
}

canonical_original_code:
void dealloc_tid(int tid)
{
 dealloc_id(tid - 500, tidbitmap, &tidhint);
}

variable_types: tid int


decompiled_code:
__int64 alloc_timerid()
{
return (unsigned int)alloc_id((int *)timeridbitmap, &timeridhint) + 1;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)func1((int *)timeridbitmap, &timeridhint) + 1;
}

original_code:
int alloc_timerid()
{
 return (1 + alloc_id(timeridbitmap, &timeridhint));
}


decompiled_code:
__int64 __fastcall dealloc_timerid(int a1)
{
return dealloc_id(a1 - 1, timeridbitmap, &timeridhint);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return func2(a1 - 1, timeridbitmap, &timeridhint);
}

original_code:
void dealloc_timerid(int timer_id)
{
 dealloc_id(timer_id - 1, timeridbitmap, &timeridhint);
}


decompiled_code:
__int64 __fastcall pthread_mutexattr_init(__int64 a1)
{
if ( !a1 )
return 29LL;
*(_DWORD *)(a1 + 8) = 2;
*(_QWORD *)a1 = 0x100000001LL;
return 0LL;
}

original_code:
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
{
 if(!attr)
  return 0x1d;
 attr->type = 1;
 attr->pshared = 1;
 attr->protocol = 2;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_init(struct mrx_mutexattr *attr)
{
 if(!attr)
  return 0x1d;
 attr->type = 1;
 attr->pshared = 1;
 attr->protocol = 2;
 return 0;
}

variable_types: struct mrx_mutexattr { int type; int pshared; int protocol; } *


decompiled_code:
__int64 pthread_mutexattr_setprioceiling()
{
return 55LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 55LL;
}

original_code:
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
       int prioceiling)
{
 return 0x37;
}

canonical_original_code:
int pthread_mutexattr_setprioceiling(struct mrx_mutexattr *attr, int prioceiling)
{
 return 0x37;
}

variable_types: prioceiling int

user_defined_types: struct mrx_mutexattr { int type; int pshared; int protocol; }


decompiled_code:
__int64 __fastcall pthread_mutexattr_getprotocol(__int64 a1, _DWORD *a2)
{
if ( !a1 )
return 29LL;
*a2 = *(_DWORD *)(a1 + 8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2)
{
if ( !a1 )
return 29LL;
*a2 = *(_DWORD *)(a1 + 8);
return 0LL;
}

original_code:
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *
       __restrict attr, int *__restrict protocol)
{
 if(!attr)
  return 0x1d;
 *protocol = attr->protocol;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_getprotocol(struct mrx_mutexattr *attr, int *protocol)
{
 if(!attr)
  return 0x1d;
 *protocol = attr->protocol;
 return 0;
}

variable_types:
protocol
int *


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

if ( !a1 )
return 29LL;
result = 60LL;
if ( (unsigned int)(a2 - 1) <= 2 )
{
*(_DWORD *)(a1 + 8) = a2;
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 29LL;
result = 60LL;
if ( (unsigned int)(a2 - 1) <= 2 )
{
*(_DWORD *)(a1 + 8) = a2;
result = 0LL;
}
return result;
}

original_code:
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
       int protocol)
{
 if(!attr)
  return 0x1d;
 if((protocol < 1) || (protocol > 3))
  return 0x3c;
 attr->protocol = protocol;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_setprotocol(struct mrx_mutexattr *attr, int protocol)
{
 if(!attr)
  return 0x1d;
 if((protocol < 1) || (protocol > 3))
  return 0x3c;
 attr->protocol = protocol;
 return 0;
}

variable_types: protocol int


decompiled_code:
__int64 __fastcall pthread_mutexattr_getpshared(__int64 a1, _DWORD *a2)
{
if ( !a1 )
return 29LL;
*a2 = *(_DWORD *)(a1 + 4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _DWORD *a2)
{
if ( !a1 )
return 29LL;
*a2 = *(_DWORD *)(a1 + 4);
return 0LL;
}

original_code:
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *
       __restrict attr, int *__restrict pshared)
{
 if(!attr)
  return 0x1d;
 *pshared = attr->pshared;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_getpshared(struct mrx_mutexattr *attr, int *pshared)
{
 if(!attr)
  return 0x1d;
 *pshared = attr->pshared;
 return 0;
}

variable_types:
pshared
int *


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

if ( !a1 )
return 29LL;
result = 60LL;
if ( (unsigned int)(a2 - 1) <= 1 )
{
*(_DWORD *)(a1 + 4) = a2;
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 29LL;
result = 60LL;
if ( (unsigned int)(a2 - 1) <= 1 )
{
*(_DWORD *)(a1 + 4) = a2;
result = 0LL;
}
return result;
}

original_code:
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
       int pshared)
{
 if(!attr)
  return 0x1d;
 if((pshared < 1) || (pshared > 2))
  return 0x3c;
 attr->pshared = pshared;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_setpshared(struct mrx_mutexattr *attr, int pshared)
{
 if(!attr)
  return 0x1d;
 if((pshared < 1) || (pshared > 2))
  return 0x3c;
 attr->pshared = pshared;
 return 0;
}

variable_types: pshared int


decompiled_code:
__int64 __fastcall pthread_mutexattr_gettype(_DWORD *a1, _DWORD *a2)
{
if ( !a1 )
return 29LL;
*a2 = *a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, _DWORD *a2)
{
if ( !a1 )
return 29LL;
*a2 = *a1;
return 0LL;
}

original_code:
int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict attr,
       int *__restrict type)
{
 if(!attr)
  return 0x1d;
 *type = attr->type;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_gettype(struct mrx_mutexattr *attr, int *type)
{
 if(!attr)
  return 0x1d;
 *type = attr->type;
 return 0;
}

variable_types:
type
int *


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

if ( !a1 )
return 29LL;
result = 60LL;
if ( (a2 & 0xF) == 15 )
{
*(_DWORD *)(a1 + 4) = a2;
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 29LL;
result = 60LL;
if ( (a2 & 0xF) == 15 )
{
*(_DWORD *)(a1 + 4) = a2;
result = 0LL;
}
return result;
}

original_code:
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
{
 if(!attr)
  return 0x1d;
 if(!(type & 8) ||
  !(type & 2) ||
  !(type & 1) ||
  !(type & 4))
  return 0x3c;
 attr->pshared = type;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_settype(struct mrx_mutexattr *attr, int type)
{
 if(!attr)
  return 0x1d;
 if(!(type & 8) ||
  !(type & 2) ||
  !(type & 1) ||
  !(type & 4))
  return 0x3c;
 attr->pshared = type;
 return 0;
}

variable_types: type int


decompiled_code:
__int64 __fastcall pthread_mutex_init(__int64 a1, __int64 a2)
{
int v2; // eax

if ( !a1 )
return 29LL;
if ( !a2 )
pthread_mutexattr_init(a1);
v2 = syscall_sync_create_constprop_0();
if ( v2 < 0 )
return (unsigned int)-v2;
*(_DWORD *)(a1 + 16) = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
int v2; // eax

if ( !a1 )
return 29LL;
if ( !a2 )
func3(a1);
v2 = func1();
if ( v2 < 0 )
return (unsigned int)-v2;
*(_DWORD *)(a1 + 16) = v2;
return 0LL;
}

original_code:
int pthread_mutex_init(pthread_mutex_t *__restrict mutex,
       const pthread_mutexattr_t *__restrict attr)
{
 int ret;
 if(!mutex)
  return 0x1d;
 if(!attr)
  pthread_mutexattr_init(&mutex->mattr);
 ret = syscall_sync_create(1);
 if(ret < 0)
  return -ret;
 mutex->sync_id = ret;
 return 0;
}

canonical_original_code:
int pthread_mutex_init(struct mrx_mutex *mutex, struct mrx_mutexattr *attr)
{
 int ret;
 if(!mutex)
  return 0x1d;
 if(!attr)
  pthread_mutexattr_init(&mutex->mattr);
 ret = syscall_sync_create(1);
 if(ret < 0)
  return -ret;
 mutex->sync_id = ret;
 return 0;
}

variable_types: struct mrx_mutex { struct mrx_mutexattr { int type; int pshared; int protocol; } mattr; int counter; int sync_id; } *

variable_types:
attr
struct mrx_mutexattr *

variable_types: ret int

user_defined_types: struct mrx_mutex { struct mrx_mutexattr mattr; int counter; int sync_id; }


decompiled_code:
__int64 __fastcall pthread_mutex_destroy(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
bool v3; // sf
__int64 result; // rax

if ( !a1 )
return 29LL;
v1 = syscall_sync_destroy(*(unsigned int *)(a1 + 16));
v2 = -v1;
v3 = v1 < 0;
result = 0LL;
if ( v3 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // eax
unsigned int v2; // edx
bool v3; // sf
__int64 result; // rax

if ( !a1 )
return 29LL;
v1 = func0(*(unsigned int *)(a1 + 16));
v2 = -v1;
v3 = v1 < 0;
result = 0LL;
if ( v3 )
result = v2;
return result;
}

original_code:
int pthread_mutex_destroy(pthread_mutex_t *mutex)
{
 int ret;
 if(!mutex)
  return 0x1d;
 ret = syscall_sync_destroy(mutex->sync_id);
 if(ret < 0)
  return -ret;
 return 0;
}

canonical_original_code:
int pthread_mutex_destroy(struct mrx_mutex *mutex)
{
 int ret;
 if(!mutex)
  return 0x1d;
 ret = syscall_sync_destroy(mutex->sync_id);
 if(ret < 0)
  return -ret;
 return 0;
}


decompiled_code:
__int64 __fastcall pthread_mutex_lock(__int64 a1)
{
return a1 == 0 ? 0x1D : 0;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return a1 == 0 ? 0x1D : 0;
}

original_code:
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
 if(!mutex)
  return 0x1d;
 mrx_mutex_lock(mutex);
 return 0;
}

canonical_original_code:
int pthread_mutex_lock(struct mrx_mutex *mutex)
{
 if(!mutex)
  return 0x1d;
 mrx_mutex_lock(mutex);
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall pthread_mutexattr_destroy(__int64 a1)
{
return pthread_mutex_lock(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func13(a1);
}

original_code:
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
 if(!attr)
  return 0x1d;
 return 0;
}

canonical_original_code:
int pthread_mutexattr_destroy(struct mrx_mutexattr *attr)
{
 if(!attr)
  return 0x1d;
 return 0;
}


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

if ( a1 )
result = mrx_mutex_trylock_constprop_0();
else
result = 29LL;
return result;
}

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

if ( a1 )
result = func2();
else
result = 29LL;
return result;
}

original_code:
int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
 if(!mutex)
  return 0x1d;
 return mrx_mutex_trylock(mutex);
}

canonical_original_code:
int pthread_mutex_trylock(struct mrx_mutex *mutex)
{
 if(!mutex)
  return 0x1d;
 return mrx_mutex_trylock(mutex);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall pthread_mutex_unlock(__int64 a1)
{
return pthread_mutex_lock(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func13(a1);
}

original_code:
int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
 if(!mutex)
  return 0x1d;
 mrx_mutex_unlock(mutex);
 return 0;
}

canonical_original_code:
int pthread_mutex_unlock(struct mrx_mutex *mutex)
{
 if(!mutex)
  return 0x1d;
 mrx_mutex_unlock(mutex);
 return 0;
}


decompiled_code:
__int64 pthread_mutex_timedlock()
{
return 55LL;
}

canonical_decompiled_code:
__int64 func17()
{
return 55LL;
}

original_code:
int pthread_mutex_timedlock(pthread_mutex_t *__restrict mutex,
       const struct timespec *__restrict abs_timeout)
{
 return 0x37;
}

canonical_original_code:
int pthread_mutex_timedlock(struct mrx_mutex *mutex, struct timespec *abs_timeout)
{
 return 0x37;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *


decompiled_code:
// attributes: thunk
__int64 pthread_mutexattr_getprioceiling()
{
return pthread_mutex_timedlock();
}

canonical_decompiled_code:
__int64 func18()
{
return func17();
}

original_code:
int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *
       __restrict attr, int *__restrict prioceiling)
{
 return 0x37;
}

canonical_original_code:
int pthread_mutexattr_getprioceiling(struct mrx_mutexattr *attr, int *prioceiling)
{
 return 0x37;
}

variable_types:
prioceiling
int *


decompiled_code:
void __fastcall spin_lock(volatile signed __int32 *a1)
{
_InterlockedDecrement(a1);
if ( *(int *)a1 <= 0 )
JUMPOUT(0x1ALL);
}

canonical_decompiled_code:
void __fastcall func0(volatile signed __int32 *a1)
{
_InterlockedDecrement(a1);
if ( *(int *)a1 <= 0 )
JUMPOUT(0x1ALL);
}

original_code:
static inline void spin_lock(spinlock_t *sp)
{
 asm volatile (
  "lock decl %0\n\t"
  "2: \n\t"
  "cmpl $0, %0\n\t"
  "jle 2f\n\t"
  :"=m"(sp->lock)
  :
  :"memory"
 );
}

canonical_original_code:
static inline void spin_lock(struct spinlock *sp)
{
 asm volatile (
  "lock decl %0\n\t"
  "2: \n\t"
  "cmpl $0, %0\n\t"
  "jle 2f\n\t"
  :"=m"(sp->lock)
  :
  :"memory"
 );
}

variable_types:
sp
struct spinlock { int lock; } *


decompiled_code:
__int64 __fastcall spin_trylock(volatile signed __int32 *a1)
{
__int64 result; // rax

_InterlockedDecrement(a1);
if ( *(int *)a1 <= 0 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(volatile signed __int32 *a1)
{
__int64 result; // rax

_InterlockedDecrement(a1);
if ( *(int *)a1 <= 0 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static inline int spin_trylock(spinlock_t *sp)
{
 int ret = 0;
 asm volatile (
  "lock decl %0\n\t"
  "cmpl $0, %0\n\t"
  "jle 2f\n\t"
  "jmp end\n\t"
  "2: \n\t"
  "movl $-1, %1\n\t"
  "end: \n\t"
  :"=m"(sp->lock),"=r"(ret)
  :
  :"memory"
 );
 return ret;
}

canonical_original_code:
static inline int spin_trylock(struct spinlock *sp)
{
 int ret = 0;
 asm volatile (
  "lock decl %0\n\t"
  "cmpl $0, %0\n\t"
  "jle 2f\n\t"
  "jmp end\n\t"
  "2: \n\t"
  "movl $-1, %1\n\t"
  "end: \n\t"
  :"=m"(sp->lock),"=r"(ret)
  :
  :"memory"
 );
 return ret;
}


decompiled_code:
__int64 __fastcall spin_unlock(volatile __int32 *a1)
{
__int32 v1; // eax

return (unsigned int)_InterlockedExchange(a1, v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(volatile __int32 *a1)
{
__int32 v1; // eax

return (unsigned int)_InterlockedExchange(a1, v1);
}

original_code:
static inline void spin_unlock(spinlock_t *sp)
{
 int val = -1;
 asm volatile (
  "xchgl %0, %1\n\t"
  :"=m"(sp->lock), "=g"(val)
  :
  :"memory"
 );
}

canonical_original_code:
static inline void spin_unlock(struct spinlock *sp)
{
 int val = -1;
 asm volatile (
  "xchgl %0, %1\n\t"
  :"=m"(sp->lock), "=g"(val)
  :
  :"memory"
 );
}

variable_types: val int


decompiled_code:
__int64 __fastcall pthread_spin_init(_DWORD *a1)
{
if ( !a1 )
return 29LL;
*a1 = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
if ( !a1 )
return 29LL;
*a1 = 1;
return 0LL;
}

original_code:
int pthread_spin_init(pthread_spinlock_t *lock, int pshared)
{
 if(!lock)
  return 0x1d;
 (lock->lock = 1);
 return 0;
}

canonical_original_code:
int pthread_spin_init(struct spinlock *lock, int pshared)
{
 if(!lock)
  return 0x1d;
 (lock->lock = 1);
 return 0;
}

variable_types:
lock
struct spinlock { int lock; } *


decompiled_code:
__int64 __fastcall pthread_spin_destroy(__int64 a1)
{
return a1 == 0 ? 0x1D : 0;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return a1 == 0 ? 0x1D : 0;
}

original_code:
int pthread_spin_destroy(pthread_spinlock_t *lock)
{
 if(!lock)
  return 0x1d;
 return 0;
}

canonical_original_code:
int pthread_spin_destroy(struct spinlock *lock)
{
 if(!lock)
  return 0x1d;
 return 0;
}


decompiled_code:
__int64 __fastcall pthread_spin_lock(volatile signed __int32 *a1)
{
if ( !a1 )
return 29LL;
spin_lock(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(volatile signed __int32 *a1)
{
if ( !a1 )
return 29LL;
func0(a1);
return 0LL;
}

original_code:
int pthread_spin_lock(pthread_spinlock_t *lock)
{
 if(!lock)
  return 0x1d;
 spin_lock(lock);
 return 0;
}

canonical_original_code:
int pthread_spin_lock(struct spinlock *lock)
{
 if(!lock)
  return 0x1d;
 spin_lock(lock);
 return 0;
}


decompiled_code:
__int64 __fastcall pthread_spin_trylock(volatile signed __int32 *a1)
{
__int64 result; // rax

if ( a1 )
result = ((int)spin_trylock(a1) >> 31) & 0xA;
else
result = 29LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(volatile signed __int32 *a1)
{
__int64 result; // rax

if ( a1 )
result = ((int)func1(a1) >> 31) & 0xA;
else
result = 29LL;
return result;
}

original_code:
int pthread_spin_trylock(pthread_spinlock_t *lock)
{
 if(!lock)
  return 0x1d;
 if(spin_trylock(lock) < 0)
  return 0x0a;
 return 0;
}

canonical_original_code:
int pthread_spin_trylock(struct spinlock *lock)
{
 if(!lock)
  return 0x1d;
 if(spin_trylock(lock) < 0)
  return 0x0a;
 return 0;
}


decompiled_code:
__int64 __fastcall pthread_spin_unlock(volatile __int32 *a1)
{
if ( !a1 )
return 29LL;
spin_unlock(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(volatile __int32 *a1)
{
if ( !a1 )
return 29LL;
func2(a1);
return 0LL;
}

original_code:
int pthread_spin_unlock(pthread_spinlock_t *lock)
{
 if(!lock)
  return 0x1d;
 spin_unlock(lock);
 return 0;
}

canonical_original_code:
int pthread_spin_unlock(struct spinlock *lock)
{
 if(!lock)
  return 0x1d;
 spin_unlock(lock);
 return 0;
}


sigemptyset

decompiled_code:
__int64 __fastcall sigemptyset(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
*a1 = 0;
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
*a1 = 0;
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sigemptyset(sigset_t *set)
{
 if(!set)
 {
  errno = 0x1d;
  return -1;
 }
 *set = 0;
 return 0;
}

canonical_original_code:
int sigemptyset(int *set)
{
 if(!set)
 {
  errno = 0x1d;
  return -1;
 }
 *set = 0;
 return 0;
}

variable_types:
set
int *


sigaddset

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

if ( a2 <= 0x20 && a1 )
{
_bittestandset(a1, a2);
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a2 <= 0x20 && a1 )
{
_bittestandset(a1, a2);
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sigaddset(sigset_t *set, int signo)
{
 if((signo < 0) || (signo > 32) || (!set))
 {
  errno = 0x1d;
  return -1;
 }
 { asm volatile ( "bts %1, %0" :"=m"(*set) :"Ir"(signo) ); };
 return 0;
}

canonical_original_code:
int sigaddset(int *set, int signo)
{
 if((signo < 0) || (signo > 32) || (!set))
 {
  errno = 0x1d;
  return -1;
 }
 { asm volatile ( "bts %1, %0" :"=m"(*set) :"Ir"(signo) ); };
 return 0;
}

variable_types: signo int


sigdelset

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

if ( a2 <= 0x20 && a1 )
{
_bittestandreset(a1, a2);
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a2 <= 0x20 && a1 )
{
_bittestandreset(a1, a2);
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sigdelset(sigset_t *set, int signo)
{
 if((signo < 0) || (signo > 32) || (!set))
 {
  errno = 0x1d;
  return -1;
 }
 { asm volatile( "btr %1, %0" :"=m"(*set) :"Ir"(signo) ); };
 return 0;
}

canonical_original_code:
int sigdelset(int *set, int signo)
{
 if((signo < 0) || (signo > 32) || (!set))
 {
  errno = 0x1d;
  return -1;
 }
 { asm volatile( "btr %1, %0" :"=m"(*set) :"Ir"(signo) ); };
 return 0;
}


sigfillset

decompiled_code:
__int64 __fastcall sigfillset(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
*a1 = -1;
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
*a1 = -1;
result = 0LL;
}
else
{
errno = 29;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sigfillset(sigset_t *set)
{
 if(!set)
 {
  errno = 0x1d;
  return -1;
 }
 *set = ((unsigned int)(~0));
 return 0;
}

canonical_original_code:
int sigfillset(int *set)
{
 if(!set)
 {
  errno = 0x1d;
  return -1;
 }
 *set = ((unsigned int)(~0));
 return 0;
}


sigismember

decompiled_code:
__int64 __fastcall sigismember(int *a1, unsigned int a2)
{
if ( a2 <= 0x20 && a1 )
return (unsigned int)check_set(*a1, a2) != 0;
errno = 29;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, unsigned int a2)
{
if ( a2 <= 0x20 && a1 )
return (unsigned int)func0(*a1, a2) != 0;
errno = 29;
return 0xFFFFFFFFLL;
}

original_code:
int sigismember(const sigset_t *set, int signo)
{
 if((signo < 0) || (signo > 32) || (!set))
 {
  errno = 0x1d;
  return -1;
 }
 if(check_set(*set, signo))
  return 1;
 else
  return 0;
}

canonical_original_code:
int sigismember(int *set, int signo)
{
 if((signo < 0) || (signo > 32) || (!set))
 {
  errno = 0x1d;
  return -1;
 }
 if(check_set(*set, signo))
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall check_set(int a1, unsigned int a2)
{
return (unsigned int)-_bittest(&a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned int a2)
{
return (unsigned int)-_bittest(&a1, a2);
}

original_code:
static inline int check_set(volatile unsigned int bitmap, int index)
{
 register int result;
 asm volatile(
  "btl %1, %2\t\n"
  "sbbl %0, %0\t\n"
  :"=r"(result)
  :"r"(index), "r"(bitmap)
  );
 return result;
}

canonical_original_code:
static inline int check_set(unsigned int bitmap, int index)
{
 register int result;
 asm volatile(
  "btl %1, %2\t\n"
  "sbbl %0, %0\t\n"
  :"=r"(result)
  :"r"(index), "r"(bitmap)
  );
 return result;
}

variable_types:
bitmap
unsigned int

variable_types: index int

variable_types: result int


original_code:
static inline void process_vkill(struct termios *trm, struct termqueue *q)
{
 while(q->end != 0)
 {
  if((q->queue[q->end] != trm->c_cc[2]) ||
   (q->queue[q->end] != trm->c_cc[1]) ||
   (q->queue[q->end] != 0xA))
   break;
  q->end--;
 }
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } *

variable_types: struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; } *


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
((void (__fastcall *)(char *))con_func[*((int *)a1 + 3)])((char *)a1 + 16);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
((void (__fastcall *)(char *))con_func[*((int *)a1 + 3)])((char *)a1 + 16);
return 0LL;
}

original_code:
void *worker(poolstruct_t pool)
{
 fptr_t ptr;
 ptr = con_func[pool->request];
 ptr(&pool->msg);
 return ((void *) 0);
}

canonical_original_code:
void *worker(struct poolstruct *pool)
{
 int (*ptr)(struct message *);
 ptr = con_func[pool->request];
 ptr(&pool->msg);
 return ((void *) 0);
}

variable_types: struct poolstruct { int flag; int owner_id; int reply; int request; struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; } msg; char data[256]; } *

variable_types: int (*)(struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; } *)

return_type: void *

user_defined_types: struct poolstruct { int flag; int owner_id; int reply; int request; struct message msg; char data[256]; }


original_code:
int msg_tcgetattr(message_t msg)
{
 struct termios *tm = msg->m4.snd_ptr;
 struct terminal *term = &(ttys[termindex]);
 *tm = term->t_termios;
 reply_message(msg->tid, msg);
 return 0;
}

canonical_original_code:
int msg_tcgetattr(struct message *msg)
{
 struct termios *tm = msg->m4.snd_ptr;
 struct terminal *term = &(ttys[termindex]);
 *tm = term->t_termios;
 reply_message(msg->tid, msg);
 return 0;
}

variable_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; } *

variable_types: struct terminal { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } t_termios; struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; } t_input; struct termqueue t_output; struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; } t_win; int pgid; } *

user_defined_types: struct terminal { struct termios t_termios; struct termqueue t_input; struct termqueue t_output; struct winattr t_win; int pgid; }


decompiled_code:
__int64 __fastcall msg_tcgetsid(__int64 a1)
{
*(_QWORD *)(a1 + 48) = *(int *)(ttys + 3168LL * termindex + 3164);
reply_message(*(unsigned int *)(a1 + 32), a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
*(_QWORD *)(a1 + 48) = *(int *)(ttys + 3168LL * termindex + 3164);
reply_message(*(unsigned int *)(a1 + 32), a1);
return 0LL;
}

original_code:
int msg_tcgetsid(message_t msg)
{
 struct terminal *term = &(ttys[termindex]);
 msg->w1 = term->pgid;
 reply_message(msg->tid, msg);
 return 0;
}

canonical_original_code:
int msg_tcgetsid(struct message *msg)
{
 struct terminal *term = &(ttys[termindex]);
 msg->w1 = term->pgid;
 reply_message(msg->tid, msg);
 return 0;
}

user_defined_types: struct message { union { unsigned long w3; unsigned long snd_bufsize; } m1; union { unsigned long w4; void *rcv_ptr; } m2; union { unsigned long w5; unsigned long rcv_bufsize; } m3; unsigned long dummy1; int tid; union { unsigned long w2; void *snd_ptr; } m4; unsigned long w1; unsigned short dummy; }

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; }

user_defined_types: struct winattr { int current_x; int max_x; int attr; char scrbuf[-1]; }


decompiled_code:
__int64 __fastcall msg_tcflush(__int64 a1)
{
if ( (*(_BYTE *)(a1 + 40) & 1) != 0 )
*(_DWORD *)(ttys + 3168LL * termindex + 572) = 0;
reply_message(*(unsigned int *)(a1 + 32), a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( (*(_BYTE *)(a1 + 40) & 1) != 0 )
*(_DWORD *)(ttys + 3168LL * termindex + 572) = 0;
reply_message(*(unsigned int *)(a1 + 32), a1);
return 0LL;
}

original_code:
int msg_tcflush(message_t msg)
{
 struct terminal *term = &(ttys[termindex]);
 struct termqueue *input;
 int type = msg->m4.w2;
 if(type & 1)
 {
  input = &term->t_input;
  input->end = 0;
 }
 reply_message(msg->tid, msg);
 return 0;
}

canonical_original_code:
int msg_tcflush(struct message *msg)
{
 struct terminal *term = &(ttys[termindex]);
 struct termqueue *input;
 int type = msg->m4.w2;
 if(type & 1)
 {
  input = &term->t_input;
  input->end = 0;
 }
 reply_message(msg->tid, msg);
 return 0;
}

variable_types: type int


decompiled_code:
__int64 __fastcall msg_con_write(__int64 a1)
{
scr_write(*(_QWORD *)(a1 + 40));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
scr_write(*(_QWORD *)(a1 + 40));
return 0LL;
}

original_code:
int msg_con_write(message_t msg)
{
 char *buf = (char *)msg->m4.snd_ptr;
 scr_write(buf);
 if(msg->flags & 0x20)
  return 0;
 return 0;
}

canonical_original_code:
int msg_con_write(struct message *msg)
{
 char *buf = (char *)msg->m4.snd_ptr;
 scr_write(buf);
 if(msg->flags & 0x20)
  return 0;
 return 0;
}

variable_types:
buf
char *


decompiled_code:
int handle_full()
{
char *v0; // rax
char *v1; // r12
struct sched_param param; // [rsp+Ch] [rbp-2Ch] BYREF
char v4[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = (char *)malloc(0x150uLL);
if ( v0 )
{
v1 = v0;
scr_write("OH serious error.");
pthread_attr_init((pthread_attr_t *)v4);
param.__sched_priority = 66;
pthread_attr_setschedparam((pthread_attr_t *)v4, &param);
LODWORD(v0) = pthread_create((pthread_t *)(v1 + 4), (const pthread_attr_t *)v4, worker, v1);
}
return (int)v0;
}

canonical_decompiled_code:
int func6()
{
char *v0; // rax
char *v1; // r12
struct sched_param param; // [rsp+Ch] [rbp-2Ch] BYREF
char v4[40]; // [rsp+10h] [rbp-28h] BYREF

v0 = (char *)malloc(0x150uLL);
if ( v0 )
{
v1 = v0;
scr_write("OH serious error.");
pthread_attr_init((pthread_attr_t *)v4);
param.__sched_priority = 66;
pthread_attr_setschedparam((pthread_attr_t *)v4, &param);
LODWORD(v0) = pthread_create((pthread_t *)(v1 + 4), (const pthread_attr_t *)v4, worker, v1);
}
return (int)v0;
}

original_code:
void handle_full(void *ptr)
{
 pthread_attr_t attr;
 struct sched_param parm;
 poolstruct_t thr;
 thr = (poolstruct_t)malloc(sizeof(struct poolstruct));
 if(thr == ((void *) 0))
  return ;
 scr_write("OH serious error.");
 pthread_attr_init(&attr);
 parm.sched_priority = 66;
 pthread_attr_setschedparam(&attr, &parm);
 pthread_create(&thr->owner_id, &attr, (pthtype_t)worker, thr);
}

canonical_original_code:
void handle_full(void *ptr)
{
 struct pthread_attr attr;
 struct sched_param parm;
 struct poolstruct *thr;
 thr = (struct poolstruct *)malloc(sizeof(struct poolstruct));
 if(thr == ((void *) 0))
  return ;
 scr_write("OH serious error.");
 pthread_attr_init(&attr);
 parm.sched_priority = 66;
 pthread_attr_setschedparam(&attr, &parm);
 pthread_create(&thr->owner_id, &attr, (void *(*)(void *))worker, thr);
}

variable_types:
ptr
void *

variable_types: struct pthread_attr { int flags; struct sched_param { int sched_priority; } prio; void *stackaddr; unsigned int stack_size; int policy; }

user_defined_types: struct pthread_attr { int flags; struct sched_param prio; void *stackaddr; unsigned int stack_size; int policy; }


decompiled_code:
void __fastcall __noreturn tty_worker(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int i; // ebp
char v3[4]; // [rsp+8h] [rbp-30h] BYREF
int sig; // [rsp+Ch] [rbp-2Ch] BYREF
char v5; // [rsp+10h] [rbp-28h] BYREF
__int64 v6; // [rsp+18h] [rbp-20h]

sigfillset((sigset_t *)v3);
sigdelset((sigset_t *)v3, 27);
pthread_sigmask(3, (const __sigset_t *)v3, 0LL);
v6 = 1LL;
sigaction(27, (const struct sigaction *)&v5, 0LL);
*a1 |= 1u;
syscall_change_iopl_constprop_0_isra_0();
for ( i = v1; ; _bittestandreset((signed __int32 *)&ttypool + 4, i) )
{
sigwait((const sigset_t *)v3, &sig);
((void (__fastcall *)(__int64))con_func[a1[3]])((__int64)(a1 + 4));
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(_DWORD *a1)
{
unsigned int v1; // edx
unsigned int i; // ebp
char v3[4]; // [rsp+8h] [rbp-30h] BYREF
int sig; // [rsp+Ch] [rbp-2Ch] BYREF
char v5; // [rsp+10h] [rbp-28h] BYREF
__int64 v6; // [rsp+18h] [rbp-20h]

sigfillset((sigset_t *)v3);
sigdelset((sigset_t *)v3, 27);
pthread_sigmask(3, (const __sigset_t *)v3, 0LL);
v6 = 1LL;
sigaction(27, (const struct sigaction *)&v5, 0LL);
*a1 |= 1u;
func7();
for ( i = v1; ; _bittestandreset((signed __int32 *)&ttypool + 4, i) )
{
sigwait((const sigset_t *)v3, &sig);
((void (__fastcall *)(__int64))con_func[a1[3]])((__int64)(a1 + 4));
}
}

original_code:
void *tty_worker(poolstruct_t pool)
{
 sigset_t set;
 struct sigaction action;
 int num, off;
 fptr_t ptr;
 sigfillset(&set);
 sigdelset(&set, 27);
 pthread_sigmask(3, &set, ((void *) 0));
 action.action.sa_handler = ((sighandler_t) 1);
 sigaction(27, &action, ((void *) 0));
 pool->flag |= 1;
 off = ((unsigned long)pool - (unsigned long)ttypool.pool)/sizeof(struct poolstruct);
  syscall_change_iopl(3);
 while(1)
 {
  sigwait(&set, &num);
  ptr = con_func[pool->request];
  ptr(&pool->msg);
  { asm volatile( "btr %1, %0" :"=m"(*&ttypool.pool_bitmap) :"Ir"(off) ); };
 }
}

canonical_original_code:
void *tty_worker(struct poolstruct *pool)
{
 int set;
 struct sigaction action;
 int num; int off;
 int (*ptr)(struct message *);
 sigfillset(&set);
 sigdelset(&set, 27);
 pthread_sigmask(3, &set, ((void *) 0));
 action.action.sa_handler = ((void (*)(int)) 1);
 sigaction(27, &action, ((void *) 0));
 pool->flag |= 1;
 off = ((unsigned long)pool - (unsigned long)ttypool.pool)/sizeof(struct poolstruct);
  syscall_change_iopl(3);
 while(1)
 {
  sigwait(&set, &num);
  ptr = con_func[pool->request];
  ptr(&pool->msg);
  { asm volatile( "btr %1, %0" :"=m"(*&ttypool.pool_bitmap) :"Ir"(off) ); };
 }
}

variable_types: set int

variable_types: struct sigaction { int sa_mask; int sa_flags; union handler { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; long si_band; union sigval { int sigval_int; void *sigval_ptr; } si_value; }, void *); } action; }

variable_types: num int

variable_types: off int

user_defined_types: struct siginfo { int si_signo; int si_code; int si_errno; int si_pid; void *si_addr; int si_status; long si_band; union sigval si_value; }


original_code:
int msg_con_open(message_t msg)
{
 struct terminal *tm = &(ttys[termindex]);
 struct userid id;
 syscall_get_user(msg->tid, &id);
 tm->pgid = id.gid;
 if(msg->flags & 0x20)
  return 0;
 reply_message(msg->tid, msg);
 return 0;
}

canonical_original_code:
int msg_con_open(struct message *msg)
{
 struct terminal *tm = &(ttys[termindex]);
 struct userid id;
 syscall_get_user(msg->tid, &id);
 tm->pgid = id.gid;
 if(msg->flags & 0x20)
  return 0;
 reply_message(msg->tid, msg);
 return 0;
}

variable_types:
id
struct userid { int uid; int gid; }


decompiled_code:
// attributes: thunk
__int64 __fastcall msg_con_close(__int64 a1, __int64 a2, int a3, int a4)
{
return msg_con_open(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, int a3, int a4)
{
return func11(a1, a2, a3, a4);
}

original_code:
int msg_con_close(message_t msg)
{
 struct terminal *tm = &(ttys[termindex]);
 struct userid id;
 syscall_get_user(msg->tid, &id);
 tm->pgid = id.gid;
 if(msg->flags & 0x20)
  return 0;
 reply_message(msg->tid, msg);
 return 0;
}

canonical_original_code:
int msg_con_close(struct message *msg)
{
 struct terminal *tm = &(ttys[termindex]);
 struct userid id;
 syscall_get_user(msg->tid, &id);
 tm->pgid = id.gid;
 if(msg->flags & 0x20)
  return 0;
 reply_message(msg->tid, msg);
 return 0;
}


decompiled_code:
__int64 __fastcall msg_tcsetattr(__int64 a1)
{
__int64 v1; // r8

memcpy_isra_0((_DWORD *)(ttys + 3168LL * termindex), *(_DWORD **)(a1 + 40), 0x38u);
reply_message(*(unsigned int *)(v1 + 32), v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 v1; // r8

func15((_DWORD *)(ttys + 3168LL * termindex), *(_DWORD **)(a1 + 40), 0x38u);
reply_message(*(unsigned int *)(v1 + 32), v1);
return 0LL;
}

original_code:
int msg_tcsetattr(message_t msg)
{
 struct termios *tm = msg->m4.snd_ptr;
 struct terminal *term = &(ttys[termindex]);
 memcpy(&term->t_termios, tm, sizeof(struct termios));
 reply_message(msg->tid, msg);
 return 0;
}

canonical_original_code:
int msg_tcsetattr(struct message *msg)
{
 struct termios *tm = msg->m4.snd_ptr;
 struct terminal *term = &(ttys[termindex]);
 memcpy(&term->t_termios, tm, sizeof(struct termios));
 reply_message(msg->tid, msg);
 return 0;
}


decompiled_code:
void __fastcall raw_read(unsigned int a1, _DWORD *a2, unsigned int a3, _DWORD *a4)
{
unsigned int v4; // eax
_DWORD *v8; // rbp
unsigned int v9; // ebx
__int64 v10; // r8
__int64 v11; // r8

v4 = a4[10];
v8 = a4 + 14;
if ( v4 )
{
v9 = a4[143];
}
else
{
v9 = a4[4];
if ( v9 )
goto LABEL_5;
memcpy_isra_0(a2, a4 + 14, a4[143]);
v4 = *(_DWORD *)(v11 + 40);
*(_DWORD *)(v11 + 572) = 0;
}
if ( v9 < v4 )
{
do
syscall_sleep_unint_isra_0(a1);
while ( *(_DWORD *)(v10 + 572) < *(_DWORD *)(v10 + 40) );
}
LABEL_5:
memcpy_isra_0(a2, v8, a3);
}

original_code:
static inline int raw_read(pthread_t tid, void *buf,
 size_t size, struct terminal *trm)
{
 int nread;
 if((trm->t_termios.c_cc[6] == 0) && (trm->t_termios.c_cc[0] == 0))
 {
  memcpy(buf, &trm->t_input.queue, trm->t_input.end);
  nread = trm->t_input.end;
  trm->t_input.end = 0;
 }
again:
 if(trm->t_input.end < trm->t_termios.c_cc[6])
 {
  syscall_sleep_unint(tid);
  goto again;
 }
 memcpy(buf, &trm->t_input.queue, size);
 return nread;
}

canonical_original_code:
static inline int raw_read(int tid, void *buf, unsigned int size, struct terminal *trm)
{
 int nread;
 if((trm->t_termios.c_cc[6] == 0) && (trm->t_termios.c_cc[0] == 0))
 {
  memcpy(buf, &trm->t_input.queue, trm->t_input.end);
  nread = trm->t_input.end;
  trm->t_input.end = 0;
 }
again:
 if(trm->t_input.end < trm->t_termios.c_cc[6])
 {
  syscall_sleep_unint(tid);
  goto again;
 }
 memcpy(buf, &trm->t_input.queue, size);
 return nread;
}

variable_types: tid int

variable_types:
buf
void *

variable_types:
size
unsigned int

variable_types: nread int


original_code:
int msg_con_read(message_t msg)
{
 struct terminal *tm = &(ttys[termindex]);
 void *buf = msg->m2.rcv_ptr;
 size_t size = msg->m3.rcv_bufsize;
 if(tm->pgid != getpgid(msg->tid))
  pthread_kill(msg->tid, 20);
 if(tm->t_termios.c_lflag & 0x010)
  msg->w1 = icanon_read(msg->tid, buf, size, tm);
 else
  msg->w1 = raw_read(msg->tid, buf, size, tm);
 reply_message(msg->tid, msg);
 return msg->w1;
}

canonical_original_code:
int msg_con_read(struct message *msg)
{
 struct terminal *tm = &(ttys[termindex]);
 void *buf = msg->m2.rcv_ptr;
 unsigned int size = msg->m3.rcv_bufsize;
 if(tm->pgid != getpgid(msg->tid))
  pthread_kill(msg->tid, 20);
 if(tm->t_termios.c_lflag & 0x010)
  msg->w1 = icanon_read(msg->tid, buf, size, tm);
 else
  msg->w1 = raw_read(msg->tid, buf, size, tm);
 reply_message(msg->tid, msg);
 return msg->w1;
}


original_code:
void read_key(unsigned char ch)
{
 struct termqueue *q = &(ttys[termindex]).t_input;
 struct termios *trm = &(ttys[termindex]).t_termios;
 if(trm->c_lflag & 0x040)
 {
  if(ch == trm->c_cc[4])
   killpg((ttys[termindex]).pgid, 9);
  else if(ch == trm->c_cc[7])
   killpg((ttys[termindex]).pgid, 13);
  else if(ch == trm->c_cc[8])
   ;
  else if(ch == trm->c_cc[9])
   ;
  else if(ch == trm->c_cc[10])
   killpg((ttys[termindex]).pgid, 19);
 }
 if(!(trm->c_lflag & 0x010))
  goto do_q;
 if(ch == trm->c_cc[5])
 {
  process_vkill(trm, q);
  goto out;
 }
 else if(ch == trm->c_cc[3])
 {
  process_verase(trm, q);
  goto out;
 }
do_q:
 if(ch == 0)
  goto out;
 if((ch == trm->c_cc[2]) || (ch == trm->c_cc[1]))
 {
  q->flag = 0x01;
  goto wakenout;
 }
 else
  q->queue[q->end++] = ch;
wakenout:
 if(q->thread)
  syscall_wake_unint(q->thread);
 q->thread = 0;
out:
 return;
}

variable_types:
ch
unsigned char

variable_types: struct termqueue { unsigned char queue[512]; unsigned char last_scancode; int end; unsigned long keyflag; int led; int flag; int thread; } *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned int c_cc[10]; } *


decompiled_code:
void __fastcall __noreturn con_panic(__int64 a1, int a2)
{
scr_write("Console Manager: ");
scr_write(a1);
scr_write("Exiting...\n");
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func21(__int64 a1, int a2)
{
scr_write("Console Manager: ");
scr_write(a1);
scr_write("Exiting...\n");
exit(a2);
}

original_code:
void con_panic(char *str, int error)
{
 scr_write("Console Manager: ");
 scr_write(str);
 scr_write("Exiting...\n");
 exit(error);
}

variable_types:
str
char *

variable_types: error int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax

termindex = 0;
syscall_change_iopl_constprop_0_isra_0(argc, argv, envp);
ttys = (__int64)malloc((unsigned int)(3168 * ntty));
if ( !ttys )
con_panic((__int64)"Not Enough Memory.\n", 49);
v3 = console_init();
result = 1;
if ( v3 != -1 )
{
keyb_init();
scr_write("CONMNGR: Initializing Console Manager: \n");
*(&ttypool + 1) = (__int64)handle_full;
*((_DWORD *)&ttypool + 4) = 0;
if ( (int)pool_init(&ttypool, 5LL, tty_worker) < 0 )
con_panic((__int64)"Pool Failed", 1);
msg_loop(&ttypool, 27LL);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax

termindex = 0;
func7(argc, argv, envp);
ttys = (__int64)malloc((unsigned int)(3168 * ntty));
if ( !ttys )
func21((__int64)"Not Enough Memory.\n", 49);
v3 = console_init();
result = 1;
if ( v3 != -1 )
{
keyb_init();
scr_write("CONMNGR: Initializing Console Manager: \n");
*(&ttypool + 1) = (__int64)handle_full;
*((_DWORD *)&ttypool + 4) = 0;
if ( (int)pool_init(&ttypool, 5LL, tty_worker) < 0 )
func21((__int64)"Pool Failed", 1);
msg_loop(&ttypool, 27LL);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int ret;
 termindex = 0;
 syscall_change_iopl(3);
 ttys = (struct terminal *) malloc(sizeof(struct terminal) * ntty);
 if(!ttys)
  con_panic("Not Enough Memory.\n", 0x31);
 ret = console_init();
 if(ret == -1)
  return 1;
 keyb_init();
 scr_write("CONMNGR: Initializing Console Manager: \n");
 ttypool.altworker = (pthtype_t)handle_full;
 ttypool.pool_bitmap = 0;
 ret = pool_init(&ttypool, 5, (pthtype_t)tty_worker);
 if(ret < 0)
  con_panic("Pool Failed", 1);
 msg_loop(&ttypool, 27);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret;
 termindex = 0;
 syscall_change_iopl(3);
 ttys = (struct terminal *) malloc(sizeof(struct terminal) * ntty);
 if(!ttys)
  con_panic("Not Enough Memory.\n", 0x31);
 ret = console_init();
 if(ret == -1)
  return 1;
 keyb_init();
 scr_write("CONMNGR: Initializing Console Manager: \n");
 ttypool.altworker = (void *(*)(void *))handle_full;
 ttypool.pool_bitmap = 0;
 ret = pool_init(&ttypool, 5, (void *(*)(void *))tty_worker);
 if(ret < 0)
  con_panic("Pool Failed", 1);
 msg_loop(&ttypool, 27);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int


sigqueue

decompiled_code:
__int64 __fastcall sigqueue(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-8h] BYREF

v5 = a3;
if ( (unsigned int)a2 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v3 = syscall_kill_constprop_0(a1, a2, &v5);
if ( v3 < 0 )
{
errno = -v3;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 result; // rax
__int64 v5; // [rsp+0h] [rbp-8h] BYREF

v5 = a3;
if ( (unsigned int)a2 > 0x20 )
{
errno = 29;
result = 0xFFFFFFFFLL;
}
else
{
v3 = func0(a1, a2, &v5);
if ( v3 < 0 )
{
errno = -v3;
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int sigqueue(pid_t pid, int signo, const union sigval value)
{
 int ret;
 if((signo < 0) || (signo > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_kill(pid, signo, 2|4, &value);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

canonical_original_code:
int sigqueue(int pid, int signo, union sigval value)
{
 int ret;
 if((signo < 0) || (signo > 32))
 {
  errno = 0x1d;
  return -1;
 }
 ret = syscall_kill(pid, signo, 2|4, &value);
 if(ret < 0)
 {
  errno = -ret;
  return -1;
 }
 return 0;
}

variable_types: pid int

variable_types: signo int

variable_types: union sigval { int sigval_int; void *sigval_ptr; }