decompiled_code:
__int64 __fastcall xp_sem_wait(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
int v4; // edx
int v5; // eax
pthread_mutex_t *v6; // rsi
pthread_cond_t *v7; // rdi
pthread_mutex_t *v8; // rdi
__int64 result; // rax

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *a1;
v4 = *(_DWORD *)(*a1 + 96);
if ( !v4 )
{
v5 = *(_DWORD *)(v3 + 100);
do
{
v6 = (pthread_mutex_t *)(v3 + 8);
v7 = (pthread_cond_t *)(v3 + 48);
v7[1].__futex = v5 + 1;
pthread_cond_wait(v7, v6);
v3 = *a1;
v4 = *(_DWORD *)(*a1 + 96);
v5 = *(_DWORD *)(*a1 + 100) - 1;
*(_DWORD *)(*a1 + 100) = v5;
}
while ( !v4 );
}
v8 = (pthread_mutex_t *)(v3 + 8);
v8[2].__owner = v4 - 1;
pthread_mutex_unlock(v8);
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
int v4; // edx
int v5; // eax
pthread_mutex_t *v6; // rsi
pthread_cond_t *v7; // rdi
pthread_mutex_t *v8; // rdi
__int64 result; // rax

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *a1;
v4 = *(_DWORD *)(*a1 + 96);
if ( !v4 )
{
v5 = *(_DWORD *)(v3 + 100);
do
{
v6 = (pthread_mutex_t *)(v3 + 8);
v7 = (pthread_cond_t *)(v3 + 48);
v7[1].__futex = v5 + 1;
pthread_cond_wait(v7, v6);
v3 = *a1;
v4 = *(_DWORD *)(*a1 + 96);
v5 = *(_DWORD *)(*a1 + 100) - 1;
*(_DWORD *)(*a1 + 100) = v5;
}
while ( !v4 );
}
v8 = (pthread_mutex_t *)(v3 + 8);
v8[2].__owner = v4 - 1;
pthread_mutex_unlock(v8);
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_wait(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
  (*sem)->nwaiters--;
 }
 (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_wait(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  pthread_cond_wait(&(*sem)->gtzero, &(*sem)->lock);
  (*sem)->nwaiters--;
 }
 (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}


repo: ftnapps/pkg-sbbs

decompiled_code:
__int64 __fastcall xp_sem_trywait(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx
int v4; // eax
unsigned int v5; // er12

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *a1;
v4 = *(_DWORD *)(v3 + 96);
if ( v4 )
{
v5 = 0;
*(_DWORD *)(v3 + 96) = v4 - 1;
}
else
{
v5 = -1;
*_errno_location() = 11;
}
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
}
else
{
v5 = -1;
*_errno_location() = 22;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx
int v4; // eax
unsigned int v5; // er12

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *a1;
v4 = *(_DWORD *)(v3 + 96);
if ( v4 )
{
v5 = 0;
*(_DWORD *)(v3 + 96) = v4 - 1;
}
else
{
v5 = -1;
*_errno_location() = 11;
}
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
}
else
{
v5 = -1;
*_errno_location() = 22;
}
return v5;
}

original_code:
int
xp_sem_trywait(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->count > 0) {
  (*sem)->count--;
  retval = 0;
 } else {
  (*__errno_location ()) = 11;
  retval = -1;
 }
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_trywait(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->count > 0) {
  (*sem)->count--;
  retval = 0;
 } else {
  (*__errno_location ()) = 11;
  retval = -1;
 }
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

variable_types: struct xp_sem { unsigned int magic; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } **

variable_types: retval int

return_type: int

user_defined_types: struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t gtzero; unsigned int count; unsigned int nwaiters; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall xp_sem_post(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
int v4; // eax
__int64 result; // rax

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *a1;
v4 = *(_DWORD *)(*a1 + 100);
++*(_DWORD *)(*a1 + 96);
if ( v4 )
{
pthread_cond_broadcast((pthread_cond_t *)(v3 + 48));
v3 = *a1;
}
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
int v4; // eax
__int64 result; // rax

if ( a1 && (v2 = *a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = *a1;
v4 = *(_DWORD *)(*a1 + 100);
++*(_DWORD *)(*a1 + 96);
if ( v4 )
{
pthread_cond_broadcast((pthread_cond_t *)(v3 + 48));
v3 = *a1;
}
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_post(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count++;
 if ((*sem)->nwaiters > 0) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_post(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count++;
 if ((*sem)->nwaiters > 0) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall xp_sem_getvalue(__int64 *a1, _DWORD *a2)
{
__int64 v3; // rdi
pthread_mutex_t *v4; // rdi
__int64 result; // rax

if ( a1 && (v3 = *a1, *(_DWORD *)v3 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v3 + 8));
v4 = (pthread_mutex_t *)(*a1 + 8);
*a2 = *(_DWORD *)(*a1 + 96);
pthread_mutex_unlock(v4);
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, _DWORD *a2)
{
__int64 v3; // rdi
pthread_mutex_t *v4; // rdi
__int64 result; // rax

if ( a1 && (v3 = *a1, *(_DWORD *)v3 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v3 + 8));
v4 = (pthread_mutex_t *)(*a1 + 8);
*a2 = *(_DWORD *)(*a1 + 96);
pthread_mutex_unlock(v4);
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_getvalue(xp_sem_t *sem, int *sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 *sval = (int)(*sem)->count;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_getvalue(struct xp_sem **sem, int *sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 *sval = (int)(*sem)->count;
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

variable_types:
sval
int *


decompiled_code:
__int64 __fastcall xp_sem_setvalue(__int64 *a1, int a2)
{
__int64 v3; // rdi
__int64 v4; // rdi
int v5; // eax
__int64 result; // rax

if ( a1 && (v3 = *a1, *(_DWORD *)v3 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v3 + 8));
v4 = *a1;
v5 = *(_DWORD *)(*a1 + 100);
*(_DWORD *)(*a1 + 96) = a2;
if ( v5 )
{
if ( a2 )
{
pthread_cond_broadcast((pthread_cond_t *)(v4 + 48));
v4 = *a1;
}
}
pthread_mutex_unlock((pthread_mutex_t *)(v4 + 8));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, int a2)
{
__int64 v3; // rdi
__int64 v4; // rdi
int v5; // eax
__int64 result; // rax

if ( a1 && (v3 = *a1, *(_DWORD *)v3 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v3 + 8));
v4 = *a1;
v5 = *(_DWORD *)(*a1 + 100);
*(_DWORD *)(*a1 + 96) = a2;
if ( v5 )
{
if ( a2 )
{
pthread_cond_broadcast((pthread_cond_t *)(v4 + 48));
v4 = *a1;
}
}
pthread_mutex_unlock((pthread_mutex_t *)(v4 + 8));
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_setvalue(xp_sem_t *sem, int sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count=(u_int32_t)sval;
 if (((*sem)->nwaiters > 0) && sval) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_setvalue(struct xp_sem **sem, int sval)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 (*sem)->count=(unsigned int)sval;
 if (((*sem)->nwaiters > 0) && sval) {
  pthread_cond_broadcast(&(*sem)->gtzero);
 }
 pthread_mutex_unlock(&(*sem)->lock);
 retval = 0;
  RETURN:
 return retval;
}

variable_types: sval int


decompiled_code:
__int64 __fastcall xp_sem_timedwait(pthread_cond_t **a1, const struct timespec *a2)
{
pthread_cond_t *v3; // rdi
pthread_cond_t *v5; // rbx
int v6; // eax
int v7; // eax
pthread_mutex_t *v8; // rsi
unsigned int v9; // er12

if ( a1 && (v3 = *a1, v3->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v3->__align + 1));
v5 = *a1;
do
{
v7 = v5[2].__lock;
v8 = (pthread_mutex_t *)(&v5->__align + 1);
if ( v7 )
{
v9 = 0;
v5[2].__lock = v7 - 1;
goto LABEL_7;
}
++v5[2].__futex;
v6 = pthread_cond_timedwait(v5 + 1, v8, a2);
v5 = *a1;
--(*a1)[2].__futex;
}
while ( !v6 );
v9 = -1;
v8 = (pthread_mutex_t *)(&v5->__align + 1);
*_errno_location() = v6;
LABEL_7:
pthread_mutex_unlock(v8);
}
else
{
v9 = -1;
*_errno_location() = 22;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func10(pthread_cond_t **a1, const struct timespec *a2)
{
pthread_cond_t *v3; // rdi
pthread_cond_t *v5; // rbx
int v6; // eax
int v7; // eax
pthread_mutex_t *v8; // rsi
unsigned int v9; // er12

if ( a1 && (v3 = *a1, v3->__lock == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(&v3->__align + 1));
v5 = *a1;
do
{
v7 = v5[2].__lock;
v8 = (pthread_mutex_t *)(&v5->__align + 1);
if ( v7 )
{
v9 = 0;
v5[2].__lock = v7 - 1;
goto LABEL_7;
}
++v5[2].__futex;
v6 = pthread_cond_timedwait(v5 + 1, v8, a2);
v5 = *a1;
--(*a1)[2].__futex;
}
while ( !v6 );
v9 = -1;
v8 = (pthread_mutex_t *)(&v5->__align + 1);
*_errno_location() = v6;
LABEL_7:
pthread_mutex_unlock(v8);
}
else
{
v9 = -1;
*_errno_location() = 22;
}
return v9;
}

original_code:
int
xp_sem_timedwait(xp_sem_t *sem, const struct timespec *abs_timeout)
{
 int retval=0;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  retval=pthread_cond_timedwait(&(*sem)->gtzero, &(*sem)->lock, abs_timeout);
  (*sem)->nwaiters--;
  if(retval) {
   (*__errno_location ())=retval;
   retval=-1;
   break;
  }
 }
 if(retval==0)
  (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_timedwait(struct xp_sem **sem, struct timespec *abs_timeout)
{
 int retval = 0;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 while ((*sem)->count == 0) {
  (*sem)->nwaiters++;
  retval=pthread_cond_timedwait(&(*sem)->gtzero, &(*sem)->lock, abs_timeout);
  (*sem)->nwaiters--;
  if(retval) {
   (*__errno_location ())=retval;
   retval=-1;
   break;
  }
 }
 if(retval==0)
  (*sem)->count--;
 pthread_mutex_unlock(&(*sem)->lock);
  RETURN:
 return retval;
}

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


msgQueueReadList

decompiled_code:
__int64 __fastcall msgQueueReadList(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( (*(_BYTE *)(a1 + 336) & 2) != 0 && *(_QWORD *)(a1 + 320) == pthread_self() )
return a1 + 128;
return a1 + 224;
}

original_code:
static link_list_t* msgQueueReadList(msg_queue_t* q)
{
 if(q==((void *)0))
  return(((void *)0));
 if((q->flags&(1<<1))
  && q->owner_thread_id == pthread_self())
  return(&q->in);
 return(&q->out);
}

canonical_original_code:
static struct link_list *msgQueueReadList(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(((void *)0));
 if((q->flags&(1<<1))
  && q->owner_thread_id == pthread_self())
  return(&q->in);
 return(&q->out);
}

variable_types: struct msg_queue_t { char name[128]; struct link_list in; struct link_list out; unsigned long owner_thread_id; long refs; unsigned long flags; void *private_data; } *

return_type: struct link_list { struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; } *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *

user_defined_types: struct link_list { struct list_node *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t mutex; struct xp_sem *sem; }


msgQueueWriteList

decompiled_code:
__int64 __fastcall msgQueueWriteList(__int64 a1)
{
pthread_t v1; // r8
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( (*(_BYTE *)(a1 + 336) & 2) == 0 || (v1 = pthread_self(), result = a1 + 128, *(_QWORD *)(a1 + 320) == v1) )
result = a1 + 224;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
pthread_t v1; // r8
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( (*(_BYTE *)(a1 + 336) & 2) == 0 || (v1 = pthread_self(), result = a1 + 128, *(_QWORD *)(a1 + 320) == v1) )
result = a1 + 224;
return result;
}

original_code:
static link_list_t* msgQueueWriteList(msg_queue_t* q)
{
 if(q==((void *)0))
  return(((void *)0));
 if(!(q->flags&(1<<1))
  || q->owner_thread_id == pthread_self())
  return(&q->out);
 return(&q->in);
}

canonical_original_code:
static struct link_list *msgQueueWriteList(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(((void *)0));
 if(!(q->flags&(1<<1))
  || q->owner_thread_id == pthread_self())
  return(&q->out);
 return(&q->in);
}

user_defined_types: struct msg_queue_t { char name[128]; struct link_list in; struct link_list out; unsigned long owner_thread_id; long refs; unsigned long flags; void *private_data; }

user_defined_types: struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; }


decompiled_code:
__int64 __fastcall list_wait(__int64 a1, __int64 a2)
{
if ( a2 < 0 )
return listSemWait();
if ( a2 )
return listSemTryWaitBlock();
return listSemTryWait();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
if ( a2 < 0 )
return listSemWait();
if ( a2 )
return listSemTryWaitBlock();
return listSemTryWait();
}

original_code:
static int list_wait(link_list_t* list, long timeout)
{
 if(timeout<0)
  return listSemWait(list);
 if(timeout==0)
  return listSemTryWait(list);
 return listSemTryWaitBlock(list,timeout);
}

canonical_original_code:
static int list_wait(struct link_list *list, long timeout)
{
 if(timeout<0)
  return listSemWait(list);
 if(timeout==0)
  return listSemTryWait(list);
 return listSemTryWaitBlock(list,timeout);
}

variable_types: struct link_list { struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; } *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *

variable_types: timeout long


msgQueueFree

decompiled_code:
__int64 __fastcall msgQueueFree(void *ptr)
{
__int64 result; // rax

result = 0LL;
if ( ptr )
{
listFree((char *)ptr + 128);
listFree((char *)ptr + 224);
result = 1LL;
if ( (*((_BYTE *)ptr + 336) & 1) != 0 )
{
free(ptr);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
__int64 result; // rax

result = 0LL;
if ( ptr )
{
listFree((char *)ptr + 128);
listFree((char *)ptr + 224);
result = 1LL;
if ( (*((_BYTE *)ptr + 336) & 1) != 0 )
{
free(ptr);
result = 1LL;
}
}
return result;
}

original_code:
int msgQueueFree(msg_queue_t* q)
{
 if(q==((void *)0))
  return(0);
 listFree(&q->in);
 listFree(&q->out);
 if(q->flags&(1<<0))
  free(q);
 return(1);
}

canonical_original_code:
int msgQueueFree(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(0);
 listFree(&q->in);
 listFree(&q->out);
 if(q->flags&(1<<0))
  free(q);
 return(1);
}

variable_types: struct msg_queue_t { char name[128]; struct link_list { struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list *list; unsigned long flags; } *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } in; struct link_list out; unsigned long owner_thread_id; long refs; unsigned long flags; void *private_data; } *


msgQueueAttach

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

if ( !a1 )
return -1LL;
result = *(_QWORD *)(a1 + 328) + 1LL;
*(_QWORD *)(a1 + 328) = result;
return result;
}

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

if ( !a1 )
return -1LL;
result = *(_QWORD *)(a1 + 328) + 1LL;
*(_QWORD *)(a1 + 328) = result;
return result;
}

original_code:
long msgQueueAttach(msg_queue_t* q)
{
 if(q==((void *)0))
  return(-1);
 q->refs++;
 return(q->refs);
}

canonical_original_code:
long msgQueueAttach(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(-1);
 q->refs++;
 return(q->refs);
}

return_type: long


msgQueueDetach

decompiled_code:
__int64 __fastcall msgQueueDetach(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

if ( !a1 )
return -1LL;
v1 = a1[41];
if ( v1 <= 0 )
return -1LL;
v2 = v1 - 1;
a1[41] = v2;
if ( !(_DWORD)v2 )
msgQueueFree(a1);
return (int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

if ( !a1 )
return -1LL;
v1 = a1[41];
if ( v1 <= 0 )
return -1LL;
v2 = v1 - 1;
a1[41] = v2;
if ( !(_DWORD)v2 )
func3(a1);
return (int)v2;
}

original_code:
long msgQueueDetach(msg_queue_t* q)
{
 int refs;
 if(q==((void *)0) || q->refs<1)
  return(-1);
 if((refs=--q->refs)==0)
  msgQueueFree(q);
 return(refs);
}

canonical_original_code:
long msgQueueDetach(struct msg_queue_t *q)
{
 int refs;
 if(q==((void *)0) || q->refs<1)
  return(-1);
 if((refs=--q->refs)==0)
  msgQueueFree(q);
 return(refs);
}

variable_types: refs int


msgQueueSetPrivateData

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 344);
*(_QWORD *)(a1 + 344) = a2;
return result;
}

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

if ( !a1 )
return 0LL;
result = *(_QWORD *)(a1 + 344);
*(_QWORD *)(a1 + 344) = a2;
return result;
}

original_code:
void* msgQueueSetPrivateData(msg_queue_t* q, void* p)
{
 void* old;
 if(q==((void *)0))
  return(((void *)0));
 old=q->private_data;
 q->private_data=p;
 return(old);
}

canonical_original_code:
void *msgQueueSetPrivateData(struct msg_queue_t *q, void *p)
{
 void *old;
 if(q==((void *)0))
  return(((void *)0));
 old=q->private_data;
 q->private_data=p;
 return(old);
}

variable_types:
p
void *

variable_types:
old
void *

return_type: void *


msgQueueGetPrivateData

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

if ( a1 )
result = *(_QWORD *)(a1 + 344);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 344);
else
result = 0LL;
return result;
}

original_code:
void* msgQueueGetPrivateData(msg_queue_t* q)
{
 if(q==((void *)0))
  return(((void *)0));
 return(q->private_data);
}

canonical_original_code:
void *msgQueueGetPrivateData(struct msg_queue_t *q)
{
 if(q==((void *)0))
  return(((void *)0));
 return(q->private_data);
}


msgQueueReadLevel

decompiled_code:
__int64 __fastcall msgQueueReadLevel(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueReadList(a1);
return listCountNodes(v1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax

v1 = func0(a1);
return listCountNodes(v1);
}

original_code:
long msgQueueReadLevel(msg_queue_t* q)
{
 return listCountNodes(msgQueueReadList(q));
}

canonical_original_code:
long msgQueueReadLevel(struct msg_queue_t *q)
{
 return listCountNodes(msgQueueReadList(q));
}


msgQueueWait

decompiled_code:
__int64 __fastcall msgQueueWait(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // er12

v2 = msgQueueReadList(a1);
v3 = list_wait(v2, a2);
if ( v3 == 1 )
listSemPost(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // er12

v2 = func0(a1);
v3 = func2(v2, a2);
if ( v3 == 1 )
listSemPost(v2);
return v3;
}

original_code:
int msgQueueWait(msg_queue_t* q, long timeout)
{
 int result;
 link_list_t* list = msgQueueReadList(q);
 if((result=list_wait(list,timeout))==1)
  listSemPost(list)
  ;
 return(result);
}

canonical_original_code:
int msgQueueWait(struct msg_queue_t *q, long timeout)
{
 int result;
 struct link_list *list = msgQueueReadList(q);
 if((result=list_wait(list,timeout))==1)
  listSemPost(list)
  ;
 return(result);
}

variable_types: result int


msgQueueRead

decompiled_code:
__int64 __fastcall msgQueueRead(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = msgQueueReadList(a1);
list_wait(v2, a2);
return listRemoveNode(v2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = func0(a1);
func2(v2, a2);
return listRemoveNode(v2, 0LL, 0LL);
}

original_code:
void* msgQueueRead(msg_queue_t* q, long timeout)
{
 link_list_t* list = msgQueueReadList(q);
 list_wait(list,timeout);
 return listRemoveNode(list, ((list_node_t*)((void *)0)), 0);
}

canonical_original_code:
void *msgQueueRead(struct msg_queue_t *q, long timeout)
{
 struct link_list *list = msgQueueReadList(q);
 list_wait(list,timeout);
 return listRemoveNode(list, ((struct list_node *)((void *)0)), 0);
}


msgQueuePeek

decompiled_code:
__int64 __fastcall msgQueuePeek(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = msgQueueReadList(a1);
if ( (unsigned int)list_wait(v2, a2) )
listSemPost(v2);
v3 = listFirstNode(v2);
return listNodeData(v3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = func0(a1);
if ( (unsigned int)func2(v2, a2) )
listSemPost(v2);
v3 = listFirstNode(v2);
return listNodeData(v3);
}

original_code:
void* msgQueuePeek(msg_queue_t* q, long timeout)
{
 link_list_t* list = msgQueueReadList(q);
 if(list_wait(list,timeout))
  listSemPost(list)
  ;
 return listNodeData(listFirstNode(list));
}

canonical_original_code:
void *msgQueuePeek(struct msg_queue_t *q, long timeout)
{
 struct link_list *list = msgQueueReadList(q);
 if(list_wait(list,timeout))
  listSemPost(list)
  ;
 return listNodeData(listFirstNode(list));
}


msgQueueFind

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

v4 = msgQueueReadList(a1);
v5 = listFindNode(v4, a2, a3);
if ( v5 )
result = listRemoveNode(v4, v5, 0LL);
else
result = 0LL;
return result;
}

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

v4 = func0(a1);
v5 = listFindNode(v4, a2, a3);
if ( v5 )
result = listRemoveNode(v4, v5, 0LL);
else
result = 0LL;
return result;
}

original_code:
void* msgQueueFind(msg_queue_t* q, const void* data, size_t length)
{
 link_list_t* list = msgQueueReadList(q);
 list_node_t* node;
 if((node=listFindNode(list,data,length))==((void *)0))
  return(((void *)0));
 return listRemoveNode(list,node, 0);
}

canonical_original_code:
void *msgQueueFind(struct msg_queue_t *q, void *data, unsigned long length)
{
 struct link_list *list = msgQueueReadList(q);
 struct list_node *node;
 if((node=listFindNode(list,data,length))==((void *)0))
  return(((void *)0));
 return listRemoveNode(list,node, 0);
}

variable_types:
data
void *

variable_types:
length
unsigned long

variable_types: struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list { struct list_node *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *list; unsigned long flags; } *


msgQueueFirstNode

decompiled_code:
__int64 __fastcall msgQueueFirstNode(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueReadList(a1);
return listFirstNode(v1);
}

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

v1 = func0(a1);
return listFirstNode(v1);
}

original_code:
list_node_t* msgQueueFirstNode(msg_queue_t* q)
{
 return listFirstNode(msgQueueReadList(q));
}

canonical_original_code:
struct list_node *msgQueueFirstNode(struct msg_queue_t *q)
{
 return listFirstNode(msgQueueReadList(q));
}

return_type: struct list_node { void *data; struct list_node *next; struct list_node *prev; struct link_list { struct list_node *first; struct list_node *last; unsigned long flags; long count; void *private_data; long refs; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; } *list; unsigned long flags; } *


msgQueueLastNode

decompiled_code:
__int64 __fastcall msgQueueLastNode(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueReadList(a1);
return listLastNode(v1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v1; // rax

v1 = func0(a1);
return listLastNode(v1);
}

original_code:
list_node_t* msgQueueLastNode(msg_queue_t* q)
{
 return listLastNode(msgQueueReadList(q));
}

canonical_original_code:
struct list_node *msgQueueLastNode(struct msg_queue_t *q)
{
 return listLastNode(msgQueueReadList(q));
}


msgQueueWriteLevel

decompiled_code:
__int64 __fastcall msgQueueWriteLevel(__int64 a1)
{
__int64 v1; // rax

v1 = msgQueueWriteList(a1);
return listCountNodes(v1);
}

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

v1 = func1(a1);
return listCountNodes(v1);
}

original_code:
long msgQueueWriteLevel(msg_queue_t* q)
{
 return listCountNodes(msgQueueWriteList(q));
}

canonical_original_code:
long msgQueueWriteLevel(struct msg_queue_t *q)
{
 return listCountNodes(msgQueueWriteList(q));
}


msgQueueWrite

decompiled_code:
_BOOL8 __fastcall msgQueueWrite(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = msgQueueWriteList(a1);
return listAddNodeData(v4, a2, a3, -1LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = func1(a1);
return listAddNodeData(v4, a2, a3, -1LL) != 0;
}

original_code:
int msgQueueWrite(msg_queue_t* q, const void* data, size_t length)
{
 return listAddNodeData(msgQueueWriteList(q), data, length, ((list_node_t*)-1))!=((void *)0);
}

canonical_original_code:
int msgQueueWrite(struct msg_queue_t *q, void *data, unsigned long length)
{
 return listAddNodeData(msgQueueWriteList(q), data, length, ((struct list_node *)-1))!=((void *)0);
}


getstr

original_code:
static int getstr(char* str, int maxlen)
{
 char ch;
    int len=0;
 int istty;
 istty=isatty(fileno(stdin));
    while(1) {
  fread(&ch,1,1,stdin);
  if(!istty) {
   printf("%c",ch);
   fflush(stdout);
  }
        if(ch=='\r' || ch=='\n')
         break;
        if(ch=='\b' || ch==0x7f) {
         if(len) len--;
            continue;
     }
        if(len<maxlen)
   str[len++]=ch;
 }
    str[len]=0;
 return(len);
}

canonical_original_code:
static int getstr(char *str, int maxlen)
{
 char ch;
    int len = 0;
 int istty;
 istty=isatty(fileno(stdin));
    while(1) {
  fread(&ch,1,1,stdin);
  if(!istty) {
   printf("%c",ch);
   fflush(stdout);
  }
        if(ch=='\r' || ch=='\n')
         break;
        if(ch=='\b' || ch==0x7f) {
         if(len) len--;
            continue;
     }
        if(len<maxlen)
   str[len++]=ch;
 }
    str[len]=0;
 return(len);
}

variable_types:
str
char *

variable_types: maxlen int

variable_types: ch char

variable_types: len int

variable_types: istty int


getnum

decompiled_code:
__int64 __fastcall sbbs_t::getnum(sbbs_t *this, unsigned __int64 a2)
{
__int64 v3; // [rsp+10h] [rbp-10h]
char v4; // [rsp+1Eh] [rbp-2h]
char v5; // [rsp+1Fh] [rbp-1h]

v4 = 0;
v3 = 0LL;
while ( *((_QWORD *)this + 6413) )
{
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 >= 0 )
{
if ( v5 == 81 )
{
sbbs_t::outchar(this, 81);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) != 0 )
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 != 8 && v5 != 127 )
{
LABEL_12:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
sbbs_t::backspace(this);
}
else
{
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
goto LABEL_12;
if ( v5 == 13 )
{
LABEL_14:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v3;
}
if ( (v5 == 8 || v5 == 127) && v4 )
{
sbbs_t::backspace(this);
v3 /= 10LL;
--v4;
}
else if ( (unsigned int)(unsigned __int8)v5 - 48 <= 9
&& a2 >= 10 * v3 + (unsigned __int64)(v5 & 0xF)
&& (v5 != 48 || v4) )
{
++v4;
v3 = (v5 & 0xF) + 10 * v3;
sbbs_t::outchar(this, v5);
if ( a2 < 10 * v3 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
goto LABEL_14;
}
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall sbbs_t::func1(sbbs_t *this, unsigned __int64 a2)
{
__int64 v3; // [rsp+10h] [rbp-10h]
char v4; // [rsp+1Eh] [rbp-2h]
char v5; // [rsp+1Fh] [rbp-1h]

v4 = 0;
v3 = 0LL;
while ( *((_QWORD *)this + 6413) )
{
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 >= 0 )
{
if ( v5 == 81 )
{
sbbs_t::outchar(this, 81);
if ( (*((_QWORD *)this + 3362) & 0x40000LL) != 0 )
v5 = sbbs_t::getkey(this, 1LL);
if ( v5 != 8 && v5 != 127 )
{
LABEL_12:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return -1LL;
}
sbbs_t::backspace(this);
}
else
{
if ( (*((_QWORD *)this + 6414) & 0x800LL) != 0 )
goto LABEL_12;
if ( v5 == 13 )
{
LABEL_14:
sbbs_t::outchar(this, 13);
sbbs_t::outchar(this, 10);
*((_QWORD *)this + 6065) = 0LL;
return v3;
}
if ( (v5 == 8 || v5 == 127) && v4 )
{
sbbs_t::backspace(this);
v3 /= 10LL;
--v4;
}
else if ( (unsigned int)(unsigned __int8)v5 - 48 <= 9
&& a2 >= 10 * v3 + (unsigned __int64)(v5 & 0xF)
&& (v5 != 48 || v4) )
{
++v4;
v3 = (v5 & 0xF) + 10 * v3;
sbbs_t::outchar(this, v5);
if ( a2 < 10 * v3 && (*((_QWORD *)this + 3362) & 0x40000LL) == 0 )
goto LABEL_14;
}
}
}
}
return 0LL;
}

original_code:
int getnum(int max)
{
 unsigned char ch,n=0;
 int i=0;
 while(1) {
  ch=getkey((1<<0));
  if(ch>0x7f)
   continue;
  if(ch=='Q') {
   outchar('Q');
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch==3) {
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch=='\r') {
   { outchar('\r'); outchar('\n'); };
   return(i);
  }
  else if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) {
   i*=10;
   n++;
   i+=ch&0xf;
   outchar(ch);
   if(i*10>max) {
    { outchar('\r'); outchar('\n'); };
    return(i);
   }
  }
 }
 return(-1);
}

canonical_original_code:
int getnum(int max)
{
 unsigned char ch; unsigned char n = 0;
 int i = 0;
 while(1) {
  ch=getkey((1<<0));
  if(ch>0x7f)
   continue;
  if(ch=='Q') {
   outchar('Q');
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch==3) {
   { outchar('\r'); outchar('\n'); };
   break;
  }
  else if(ch=='\r') {
   { outchar('\r'); outchar('\n'); };
   return(i);
  }
  else if(ch=='\b' && n) {
   bputs("\b \b");
   i/=10;
   n--;
  }
  else if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) {
   i*=10;
   n++;
   i+=ch&0xf;
   outchar(ch);
   if(i*10>max) {
    { outchar('\r'); outchar('\n'); };
    return(i);
   }
  }
 }
 return(-1);
}

variable_types: max int

variable_types:
ch
unsigned char

variable_types:
n
unsigned char

variable_types: i int


decompiled_code:
__int64 __fastcall semfile_check(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er8

if ( !*a1 )
*a1 = time(0LL);
v2 = fdate(a2);
v3 = 0;
if ( v2 != -1 && *a1 < v2 )
{
*a1 = v2;
v3 = 1;
}
return v3;
}

original_code:
int semfile_check(time_t* t, const char* fname)
{
 time_t ft;
 if(*t==0)
  *t=time(((void *)0));
 if((ft=fdate(fname))==-1 || ft<=*t)
  return(0);
 *t=ft;
 return(1);
}

canonical_original_code:
int semfile_check(long *t, char *fname)
{
 long ft;
 if(*t==0)
  *t=time(((void *)0));
 if((ft=fdate(fname))==-1 || ft<=*t)
  return(0);
 *t=ft;
 return(1);
}

variable_types:
t
long *

variable_types:
fname
char *

variable_types: ft long


decompiled_code:
__int64 __fastcall semfile_list_check(__int64 *a1, __int64 *a2)
{
__int64 *v2; // rbx
__int64 v3; // rsi
__int64 v4; // r12

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
v4 = 0LL;
do
{
if ( (unsigned int)semfile_check(a1, v3) )
v4 = *v2;
v3 = v2[1];
++v2;
}
while ( v3 );
return v4;
}

original_code:
char* semfile_list_check(time_t* t, str_list_t filelist)
{
 char* signaled=((void *)0);
 size_t i;
 for(i=0;filelist[i]!=((void *)0);i++)
  if(semfile_check(t, filelist[i]))
   signaled = filelist[i];
 return(signaled);
}

canonical_original_code:
char *semfile_list_check(long *t, char **filelist)
{
 char *signaled = ((void *)0);
 unsigned long i;
 for(i=0;filelist[i]!=((void *)0);i++)
  if(semfile_check(t, filelist[i]))
   signaled = filelist[i];
 return(signaled);
}

variable_types:
filelist
char **

variable_types:
signaled
char *

variable_types:
i
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall semfile_list_init(const char *a1, const char *a2, const char *a3)
{
__int64 result; // rax
char *v5; // rax
__int64 v6; // [rsp+8h] [rbp-10B0h] BYREF
char name[128]; // [rsp+10h] [rbp-10A8h] BYREF
char v8[4096]; // [rsp+90h] [rbp-1028h] BYREF
char v9; // [rsp+1090h] [rbp-28h]

result = strListInit();
v6 = result;
if ( result )
{
safe_snprintf(v8, 4097LL, "%s%s", a1, a2);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
if ( !gethostname(name, 0x80uLL) )
{
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
v5 = strchr(name, 46);
if ( v5 )
{
*v5 = 0;
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
}
}
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2, const char *a3)
{
__int64 result; // rax
char *v5; // rax
__int64 v6; // [rsp+8h] [rbp-10B0h] BYREF
char name[128]; // [rsp+10h] [rbp-10A8h] BYREF
char v8[4096]; // [rsp+90h] [rbp-1028h] BYREF
char v9; // [rsp+1090h] [rbp-28h]

result = strListInit();
v6 = result;
if ( result )
{
safe_snprintf(v8, 4097LL, "%s%s", a1, a2);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
if ( !gethostname(name, 0x80uLL) )
{
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
v5 = strchr(name, 46);
if ( v5 )
{
*v5 = 0;
safe_snprintf(v8, 4097LL, "%s%s.%s", a1, a2, name);
v9 = 0;
strListAppend(&v6, v8, -1LL);
safe_snprintf(v8, 4097LL, "%s%s.%s.%s", a1, a2, name, a3);
v9 = 0;
strListAppend(&v6, v8, -1LL);
}
}
result = v6;
}
return result;
}

original_code:
str_list_t semfile_list_init(const char* parent,
          const char* action, const char* service)
{
 char path[4096 +1];
 char hostname[128];
 char* p;
 str_list_t list;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 safe_snprintf(path,sizeof(path),"%s%s",parent,action), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,service), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 if(gethostname(hostname,sizeof(hostname))==0) {
  safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  if((p=strchr(hostname,'.'))!=((void *)0)) {
   *p=0;
   safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
   safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
  }
 }
 return(list);
}

canonical_original_code:
char **semfile_list_init(char *parent, char *action, char *service)
{
 char path[-1];
 char hostname[128];
 char *p;
 char **list;
 if((list=strListInit())==((void *)0))
  return(((void *)0));
 safe_snprintf(path,sizeof(path),"%s%s",parent,action), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,service), path[sizeof(path)-1]=0;
 strListAppend(&list, path, (~0));
 if(gethostname(hostname,sizeof(hostname))==0) {
  safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
  strListAppend(&list, path, (~0));
  if((p=strchr(hostname,'.'))!=((void *)0)) {
   *p=0;
   safe_snprintf(path,sizeof(path),"%s%s.%s",parent,action,hostname), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
   safe_snprintf(path,sizeof(path),"%s%s.%s.%s",parent,action,hostname,service), path[sizeof(path)-1]=0;
   strListAppend(&list, path, (~0));
  }
 }
 return(list);
}

variable_types:
parent
char *

variable_types:
action
char *

variable_types:
service
char *

variable_types:
path
char [-1]

variable_types:
hostname
char [128]

variable_types:
p
char *

variable_types:
list
char **

return_type: char **


decompiled_code:
__int64 __fastcall semfile_list_add(__int64 a1, __int64 a2)
{
return strListAppend(a1, a2, -1LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return strListAppend(a1, a2, -1LL);
}

original_code:
void semfile_list_add(str_list_t* filelist, const char* path)
{
 strListAppend(filelist, path, (~0));
}

canonical_original_code:
void semfile_list_add(char ***filelist, char *path)
{
 strListAppend(filelist, path, (~0));
}

variable_types:
filelist
char ***

variable_types:
path
char *

return_type: void


decompiled_code:
// attributes: thunk
__int64 semfile_list_free()
{
return strListFree();
}

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

original_code:
void semfile_list_free(str_list_t* filelist)
{
 strListFree(filelist);
}

canonical_original_code:
void semfile_list_free(char ***filelist)
{
 strListFree(filelist);
}


decompiled_code:
__int64 __fastcall semfile_signal(char *file, void *buf)
{
const char *v2; // rbp
int v3; // er12
size_t v5; // rax
char v6[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = (const char *)buf;
if ( !buf )
{
if ( gethostname(v6, 0x80uLL) )
{
v3 = open(file, 65);
if ( v3 < 0 )
return 0LL;
goto LABEL_5;
}
v2 = v6;
}
v3 = open(file, 65);
if ( v3 < 0 )
return 0LL;
v5 = strlen(v2);
write(v3, v2, v5);
LABEL_5:
close(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *file, void *buf)
{
const char *v2; // rbp
int v3; // er12
size_t v5; // rax
char v6[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = (const char *)buf;
if ( !buf )
{
if ( gethostname(v6, 0x80uLL) )
{
v3 = open(file, 65);
if ( v3 < 0 )
return 0LL;
goto LABEL_5;
}
v2 = v6;
}
v3 = open(file, 65);
if ( v3 < 0 )
return 0LL;
v5 = strlen(v2);
write(v3, v2, v5);
LABEL_5:
close(v3);
return 1LL;
}

original_code:
int semfile_signal(const char* fname, const char* text)
{
 int file;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if((file=open(fname,0100|01))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

canonical_original_code:
int semfile_signal(char *fname, char *text)
{
 int file;
 char hostname[128];
 if(text==((void *)0) && gethostname(hostname,sizeof(hostname))==0)
  text=hostname;
 if((file=open(fname,0100|01))<0)
  return(0);
 if(text!=((void *)0))
  write(file,text,strlen(text));
 close(file);
 return(1);
}

variable_types:
text
char *

variable_types: file int


decompiled_code:
__int64 __fastcall ucrc16(char a1, _WORD *a2)
{
int v2; // edx
__int16 v4; // cx
__int64 result; // rax
unsigned int v6; // esi

v2 = (unsigned __int16)*a2;
v4 = 8;
do
{
result = (unsigned int)(2 * v2);
if ( a1 < 0 )
result = (2 * v2) | 1u;
a1 *= 2;
HIWORD(v6) = WORD1(result);
if ( (v2 & 0x8000u) != 0 )
{
LOWORD(v6) = result ^ 0x1021;
result = v6;
}
v2 = result;
--v4;
}
while ( v4 );
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, _WORD *a2)
{
int v2; // edx
__int16 v4; // cx
__int64 result; // rax
unsigned int v6; // esi

v2 = (unsigned __int16)*a2;
v4 = 8;
do
{
result = (unsigned int)(2 * v2);
if ( a1 < 0 )
result = (2 * v2) | 1u;
a1 *= 2;
HIWORD(v6) = WORD1(result);
if ( (v2 & 0x8000u) != 0 )
{
LOWORD(v6) = result ^ 0x1021;
result = v6;
}
v2 = result;
--v4;
}
while ( v4 );
*a2 = result;
return result;
}

original_code:
void ucrc16(unsigned char ch, ushort *rcrc) {
 ushort i, cy;
    unsigned char nch=ch;
for (i=0; i<8; i++) {
    cy=*rcrc & 0x8000;
    *rcrc<<=1;
    if (nch & 0x80) *rcrc |= 1;
    nch<<=1;
    if (cy) *rcrc ^= 0x1021; }
}

canonical_original_code:
void ucrc16(unsigned char ch, unsigned short *rcrc) {
 unsigned short i; unsigned short cy;
    unsigned char nch = ch;
for (i=0; i<8; i++) {
    cy=*rcrc & 0x8000;
    *rcrc<<=1;
    if (nch & 0x80) *rcrc |= 1;
    nch<<=1;
    if (cy) *rcrc ^= 0x1021; }
}

variable_types:
ch
unsigned char

variable_types:
rcrc
unsigned short *

variable_types:
i
unsigned short

variable_types:
cy
unsigned short

variable_types:
nch
unsigned char


unixtodstr

decompiled_code:
char *__fastcall unixtodstr(time_t a1, char *a2)
{
char *result; // rax
struct tm *v3; // rax
int v4; // ecx
int v5; // er8
__int64 v6; // rcx
__int64 v7; // rdx
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
if ( a1 && (v3 = gmtime(&timer)) != 0LL )
{
v4 = v3->tm_mon;
v5 = v3->tm_year;
if ( v4 > 11 )
{
++v5;
v3->tm_mon = 0;
v6 = 1LL;
v3->tm_year = v5;
}
else
{
v6 = (unsigned int)(v4 + 1);
}
v7 = (unsigned int)v3->tm_mday;
if ( (int)v7 > 31 )
{
v3->tm_mday = 1;
v7 = 1LL;
}
sprintf(a2, "%02u/%02u/%02u", v7, v6, (unsigned int)(v5 % 100));
result = a2;
}
else
{
strcpy(a2, "00/00/00");
result = a2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(time_t a1, char *a2)
{
char *result; // rax
struct tm *v3; // rax
int v4; // ecx
int v5; // er8
__int64 v6; // rcx
__int64 v7; // rdx
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
if ( a1 && (v3 = gmtime(&timer)) != 0LL )
{
v4 = v3->tm_mon;
v5 = v3->tm_year;
if ( v4 > 11 )
{
++v5;
v3->tm_mon = 0;
v6 = 1LL;
v3->tm_year = v5;
}
else
{
v6 = (unsigned int)(v4 + 1);
}
v7 = (unsigned int)v3->tm_mday;
if ( (int)v7 > 31 )
{
v3->tm_mday = 1;
v7 = 1LL;
}
sprintf(a2, "%02u/%02u/%02u", v7, v6, (unsigned int)(v5 % 100));
result = a2;
}
else
{
strcpy(a2, "00/00/00");
result = a2;
}
return result;
}

original_code:
char* unixtodstr(time_t unix_time, char *str)
{
 struct tm* tm;
 if(!unix_time)
  strcpy(str,"00/00/00");
 else {
  tm=gmtime(&unix_time);
  if(tm==((void *)0)) {
   strcpy(str,"00/00/00");
   return(str);
  }
  if(tm->tm_mon>11) {
   tm->tm_mon=0;
   tm->tm_year++; }
  if(tm->tm_mday>31)
   tm->tm_mday=1;
  sprintf(str,"%02u/%02u/%02u",tm->tm_mday,tm->tm_mon+1
   ,((tm->tm_year)%100));
 }
 return(str);
}

canonical_original_code:
char *unixtodstr(long unix_time, char *str)
{
 struct tm *tm;
 if(!unix_time)
  strcpy(str,"00/00/00");
 else {
  tm=gmtime(&unix_time);
  if(tm==((void *)0)) {
   strcpy(str,"00/00/00");
   return(str);
  }
  if(tm->tm_mon>11) {
   tm->tm_mon=0;
   tm->tm_year++; }
  if(tm->tm_mday>31)
   tm->tm_mday=1;
  sprintf(str,"%02u/%02u/%02u",tm->tm_mday,tm->tm_mon+1
   ,((tm->tm_year)%100));
 }
 return(str);
}

variable_types:
str
char *

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


original_code:
int x_puttext(int sx, int sy, int ex, int ey, void *fill)
{
 int x,y;
 unsigned char *out;
 ushort sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=*(out++);
   sch |= (*(out++))<<8;
   vmem[y*DpyCols+x]=sch;
  }
 }
 return(1);
}

canonical_original_code:
int x_puttext(int sx, int sy, int ex, int ey, void *fill)
{
 int x; int y;
 unsigned char *out;
 unsigned short sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=*(out++);
   sch |= (*(out++))<<8;
   vmem[y*DpyCols+x]=sch;
  }
 }
 return(1);
}

variable_types: sx int

variable_types: sy int

variable_types: ex int

variable_types: ey int

variable_types:
fill
void *

variable_types: x int

variable_types: y int

variable_types:
out
unsigned char *

variable_types:
sch
unsigned short

variable_types: struct text_info { unsigned char winleft; unsigned char wintop; unsigned char winright; unsigned char winbottom; unsigned char attribute; unsigned char normattr; unsigned char currmode; unsigned char screenheight; unsigned char screenwidth; unsigned char curx; unsigned char cury; }


original_code:
int x_gettext(int sx, int sy, int ex, int ey, void *fill)
{
 int x,y;
 unsigned char *out;
 ushort sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=vmem[y*DpyCols+x];
   *(out++)=sch & 0xff;
   *(out++)=sch >> 8;
  }
 }
 return(1);
}

canonical_original_code:
int x_gettext(int sx, int sy, int ex, int ey, void *fill)
{
 int x; int y;
 unsigned char *out;
 unsigned short sch;
 struct text_info ti;
 ciolib_gettextinfo(&ti);
 if( sx < 1
   || sy < 1
   || ex < 1
   || ey < 1
   || sx > ti.screenwidth
   || sy > ti.screenheight
   || sx > ex
   || sy > ey
   || ex > ti.screenwidth
   || ey > ti.screenheight
   || fill==((void *)0))
  return(0);
 out=fill;
 for(y=sy-1;y<ey;y++) {
  for(x=sx-1;x<ex;x++) {
   sch=vmem[y*DpyCols+x];
   *(out++)=sch & 0xff;
   *(out++)=sch >> 8;
  }
 }
 return(1);
}

user_defined_types: struct text_info { unsigned char winleft; unsigned char wintop; unsigned char winright; unsigned char winbottom; unsigned char attribute; unsigned char normattr; unsigned char currmode; unsigned char screenheight; unsigned char screenwidth; unsigned char curx; unsigned char cury; }


decompiled_code:
void __fastcall x_textattr(__int16 a1)
{
x_curr_attr = a1 << 8;
}

canonical_decompiled_code:
void __fastcall func2(__int16 a1)
{
x_curr_attr = a1 << 8;
}

original_code:
void x_textattr(int attr)
{
 x_curr_attr=attr<<8;
}

variable_types: attr int


decompiled_code:
// attributes: thunk
__int64 x_kbhit()
{
return tty_kbhit();
}

canonical_decompiled_code:
__int64 func3()
{
return tty_kbhit();
}

original_code:
int x_kbhit(void)
{
 return(tty_kbhit());
}

canonical_original_code:
int x_kbhit()
{
 return(tty_kbhit());
}


decompiled_code:
int __fastcall x_delay(int a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
return usleep(1000 * a1);
}

original_code:
void x_delay(long msec)
{
 usleep(msec*1000);
}

variable_types: msec long


decompiled_code:
__int64 x_wherey()
{
return (unsigned int)CursRow + 1;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)CursRow + 1;
}

original_code:
int x_wherey(void)
{
 return(CursRow+1);
}

canonical_original_code:
int x_wherey()
{
 return(CursRow+1);
}


decompiled_code:
__int64 x_wherex()
{
return (unsigned int)CursCol + 1;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)CursCol + 1;
}

original_code:
int x_wherex(void)
{
 return(CursCol+1);
}

canonical_original_code:
int x_wherex()
{
 return(CursCol+1);
}


decompiled_code:
__int64 __fastcall x_putch(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rdx
__int16 v5; // bx
__int16 v6; // bx
int v7; // eax
__int64 v8; // rdx
int v9; // eax
__int64 v10; // rdi
unsigned __int8 v11; // cl
int *v12; // rbx
int i; // ebp
int v14; // eax
unsigned int v15; // eax
unsigned __int8 v16; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v17; // [rsp+6h] [rbp-32h]
unsigned __int8 v18; // [rsp+7h] [rbp-31h]
unsigned __int8 v19; // [rsp+8h] [rbp-30h]
unsigned __int8 v20; // [rsp+Eh] [rbp-2Ah]
unsigned __int8 v21; // [rsp+Fh] [rbp-29h]

v2 = a1;
v3 = (unsigned __int16)x_curr_attr;
switch ( (int)a1 )
{
case 7:
tty_beep(a1, a2, (unsigned __int16)x_curr_attr);
return (unsigned int)a1;
case 8:
v11 = CursCol;
if ( CursCol )
v11 = --CursCol;
*(_WORD *)(vmem + 2LL * (v11 + DpyCols * CursRow)) = x_curr_attr | 0x20;
return (unsigned int)a1;
case 9:
v12 = (int *)(unsigned int)((_DWORD)&x_tabs + 4);
for ( i = a1; (int)ciolib_wherex(a1, a2, v3) >= i; i = *v12++ )
{
if ( (int *)(unsigned int)((_DWORD)&x_tabs + 40) == v12 )
{
ciolib_putch(13LL);
ciolib_putch(10LL);
return v2;
}
}
while ( (int)ciolib_wherex(a1, a2, v3) < i )
{
a1 = 32LL;
ciolib_putch(32LL);
}
return v2;
case 10:
ciolib_gettextinfo(&v16);
if ( (unsigned int)ciolib_wherey() != v19 - v17 + 1 )
{
++CursRow;
return (unsigned int)a1;
}
ciolib_wscroll();
return v2;
case 13:
ciolib_gettextinfo(&v16);
CursCol = v16 - 1;
return v2;
default:
v5 = x_curr_attr;
ciolib_gettextinfo(&v16);
v6 = a1 | v5;
v7 = ciolib_wherey();
v8 = v17;
if ( v7 == v19 - v17 + 1 )
{
v14 = ciolib_wherex(&v16, a2, v17);
v8 = v16;
if ( v14 == v18 - v16 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v6;
ciolib_wscroll();
v15 = ciolib_wherey();
ciolib_gotoxy(v16, v15);
return v2;
}
}
v9 = ciolib_wherex(&v16, a2, v8);
v10 = v16;
if ( v9 == v18 - v16 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v6;
ciolib_gotoxy(v10, (unsigned int)v21 + 1);
return v2;
}
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v6;
ciolib_gotoxy((unsigned int)v20 + 1, v21);
return v2;
}
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // rdx
__int16 v5; // bx
__int16 v6; // bx
int v7; // eax
__int64 v8; // rdx
int v9; // eax
__int64 v10; // rdi
unsigned __int8 v11; // cl
int *v12; // rbx
int i; // ebp
int v14; // eax
unsigned int v15; // eax
unsigned __int8 v16; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v17; // [rsp+6h] [rbp-32h]
unsigned __int8 v18; // [rsp+7h] [rbp-31h]
unsigned __int8 v19; // [rsp+8h] [rbp-30h]
unsigned __int8 v20; // [rsp+Eh] [rbp-2Ah]
unsigned __int8 v21; // [rsp+Fh] [rbp-29h]

v2 = a1;
v3 = (unsigned __int16)x_curr_attr;
switch ( (int)a1 )
{
case 7:
tty_beep(a1, a2, (unsigned __int16)x_curr_attr);
return (unsigned int)a1;
case 8:
v11 = CursCol;
if ( CursCol )
v11 = --CursCol;
*(_WORD *)(vmem + 2LL * (v11 + DpyCols * CursRow)) = x_curr_attr | 0x20;
return (unsigned int)a1;
case 9:
v12 = (int *)(unsigned int)((_DWORD)&x_tabs + 4);
for ( i = a1; (int)ciolib_wherex(a1, a2, v3) >= i; i = *v12++ )
{
if ( (int *)(unsigned int)((_DWORD)&x_tabs + 40) == v12 )
{
ciolib_putch(13LL);
ciolib_putch(10LL);
return v2;
}
}
while ( (int)ciolib_wherex(a1, a2, v3) < i )
{
a1 = 32LL;
ciolib_putch(32LL);
}
return v2;
case 10:
ciolib_gettextinfo(&v16);
if ( (unsigned int)ciolib_wherey() != v19 - v17 + 1 )
{
++CursRow;
return (unsigned int)a1;
}
ciolib_wscroll();
return v2;
case 13:
ciolib_gettextinfo(&v16);
CursCol = v16 - 1;
return v2;
default:
v5 = x_curr_attr;
ciolib_gettextinfo(&v16);
v6 = a1 | v5;
v7 = ciolib_wherey();
v8 = v17;
if ( v7 == v19 - v17 + 1 )
{
v14 = ciolib_wherex(&v16, a2, v17);
v8 = v16;
if ( v14 == v18 - v16 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v6;
ciolib_wscroll();
v15 = ciolib_wherey();
ciolib_gotoxy(v16, v15);
return v2;
}
}
v9 = ciolib_wherex(&v16, a2, v8);
v10 = v16;
if ( v9 == v18 - v16 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v6;
ciolib_gotoxy(v10, (unsigned int)v21 + 1);
return v2;
}
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v6;
ciolib_gotoxy((unsigned int)v20 + 1, v21);
return v2;
}
}

original_code:
int x_putch(int ch)
{
 struct text_info ti;
 ushort sch;
 int i;
 sch=x_curr_attr|ch;
 switch(ch) {
  case '\r':
   ciolib_gettextinfo(&ti);
   CursCol=ti.winleft-1;
   break;
  case '\n':
   ciolib_gettextinfo(&ti);
   if(ciolib_wherey()==ti.winbottom-ti.wintop+1)
    ciolib_wscroll();
   else
    CursRow++;
   break;
  case '\b':
   if(CursCol>0)
    CursCol--;
   vmem[CursCol+CursRow*DpyCols]=x_curr_attr|' ';
   break;
  case 7:
   tty_beep();
   break;
  case '\t':
   for(i=0;i<10;i++) {
    if(x_tabs[i]>ciolib_wherex()) {
     while(ciolib_wherex()<x_tabs[i]) {
      ciolib_putch(' ');
     }
     break;
    }
   }
   if(i==10) {
    ciolib_putch('\r');
    ciolib_putch('\n');
   }
   break;
  default:
   ciolib_gettextinfo(&ti);
   if(ciolib_wherey()==ti.winbottom-ti.wintop+1
     && ciolib_wherex()==ti.winright-ti.winleft+1) {
    vmem[CursCol+CursRow*DpyCols]=sch;
    ciolib_wscroll();
    ciolib_gotoxy(ti.winleft,ciolib_wherey());
   }
   else {
    if(ciolib_wherex()==ti.winright-ti.winleft+1) {
     vmem[CursCol+CursRow*DpyCols]=sch;
     ciolib_gotoxy(ti.winleft,ti.cury+1);
    }
    else {
     vmem[CursCol+CursRow*DpyCols]=sch;
     ciolib_gotoxy(ti.curx+1,ti.cury);
    }
   }
   break;
 }
 return(ch);
}

canonical_original_code:
int x_putch(int ch)
{
 struct text_info ti;
 unsigned short sch;
 int i;
 sch=x_curr_attr|ch;
 switch(ch) {
  case '\r':
   ciolib_gettextinfo(&ti);
   CursCol=ti.winleft-1;
   break;
  case '\n':
   ciolib_gettextinfo(&ti);
   if(ciolib_wherey()==ti.winbottom-ti.wintop+1)
    ciolib_wscroll();
   else
    CursRow++;
   break;
  case '\b':
   if(CursCol>0)
    CursCol--;
   vmem[CursCol+CursRow*DpyCols]=x_curr_attr|' ';
   break;
  case 7:
   tty_beep();
   break;
  case '\t':
   for(i=0;i<10;i++) {
    if(x_tabs[i]>ciolib_wherex()) {
     while(ciolib_wherex()<x_tabs[i]) {
      ciolib_putch(' ');
     }
     break;
    }
   }
   if(i==10) {
    ciolib_putch('\r');
    ciolib_putch('\n');
   }
   break;
  default:
   ciolib_gettextinfo(&ti);
   if(ciolib_wherey()==ti.winbottom-ti.wintop+1
     && ciolib_wherex()==ti.winright-ti.winleft+1) {
    vmem[CursCol+CursRow*DpyCols]=sch;
    ciolib_wscroll();
    ciolib_gotoxy(ti.winleft,ciolib_wherey());
   }
   else {
    if(ciolib_wherex()==ti.winright-ti.winleft+1) {
     vmem[CursCol+CursRow*DpyCols]=sch;
     ciolib_gotoxy(ti.winleft,ti.cury+1);
    }
    else {
     vmem[CursCol+CursRow*DpyCols]=sch;
     ciolib_gotoxy(ti.curx+1,ti.cury);
    }
   }
   break;
 }
 return(ch);
}

variable_types: ch int

variable_types: i int


decompiled_code:
void __fastcall x_gotoxy(char a1, char a2)
{
CursRow = a2 - 1;
CursCol = a1 - 1;
}

canonical_decompiled_code:
void __fastcall func8(char a1, char a2)
{
CursRow = a2 - 1;
CursCol = a1 - 1;
}

original_code:
void x_gotoxy(int x, int y)
{
 CursRow=y-1;
 CursCol=x-1;
}


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

if ( a1 )
{
if ( a1 == 1 )
{
CursStart = 0;
result = (unsigned int)FH - 1;
CursEnd = FH - 1;
}
else
{
CursStart = InitCS;
result = InitCE;
CursEnd = InitCE;
}
}
else
{
CursStart = -1;
CursEnd = 0;
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
CursStart = 0;
result = (unsigned int)FH - 1;
CursEnd = FH - 1;
}
else
{
CursStart = InitCS;
result = InitCE;
CursEnd = InitCE;
}
}
else
{
CursStart = -1;
CursEnd = 0;
}
return result;
}

original_code:
void x_setcursortype(int type)
{
 switch(type) {
  case _NOCURSOR:
   CursStart=0xff;
   CursEnd=0;
   break;
  case _SOLIDCURSOR:
   CursStart=0;
   CursEnd=FH-1;
   break;
  default:
      CursStart = InitCS;
      CursEnd = InitCE;
   break;
 }
}

variable_types: type int


decompiled_code:
__int64 x_getch()
{
return tty_read(8LL);
}

canonical_decompiled_code:
__int64 func11()
{
return tty_read(8LL);
}

original_code:
int x_getch(void)
{
 return(tty_read(0x00000008));
}

canonical_original_code:
int x_getch()
{
 return(tty_read(0x00000008));
}


decompiled_code:
__int64 x_getche()
{
unsigned int v0; // eax
unsigned int v1; // er12

if ( x_nextchar )
return x_getch();
v0 = x_getch();
v1 = v0;
if ( !v0 )
return 0LL;
ciolib_putch(v0);
return v1;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax
unsigned int v1; // er12

if ( x_nextchar )
return func11();
v0 = func11();
v1 = v0;
if ( !v0 )
return 0LL;
ciolib_putch(v0);
return v1;
}

original_code:
int x_getche(void)
{
 int ch;
 if(x_nextchar)
  return(x_getch());
 ch=x_getch();
 if(ch)
  ciolib_putch(ch);
 return(ch);
}

canonical_original_code:
int x_getche()
{
 int ch;
 if(x_nextchar)
  return(x_getch());
 ch=x_getch();
 if(ch)
  ciolib_putch(ch);
 return(ch);
}


decompiled_code:
__int64 __fastcall x_beep(__int64 a1, __int64 a2, __int64 a3)
{
tty_beep(a1, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, __int64 a3)
{
tty_beep(a1, a2, a3);
return 0LL;
}

original_code:
int x_beep(void)
{
 tty_beep();
 return(0);
}

canonical_original_code:
int x_beep()
{
 tty_beep();
 return(0);
}


decompiled_code:
__int64 __fastcall x_textmode(int a1)
{
console_new_mode = a1;
return xp_sem_wait(&console_mode_changed);
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
console_new_mode = a1;
return xp_sem_wait(&console_mode_changed);
}

original_code:
void x_textmode(int mode)
{
 console_new_mode=mode;
 xp_sem_wait(&console_mode_changed);
}

variable_types: mode int


decompiled_code:
__int64 x_setname()
{
return x_win_name();
}

canonical_decompiled_code:
__int64 func15()
{
return x_win_name();
}

original_code:
void x_setname(const char *name)
{
 x_win_name(name);
}

canonical_original_code:
void x_setname(char *name)
{
 x_win_name(name);
}

variable_types:
name
char *


decompiled_code:
// attributes: thunk
__int64 x_settitle()
{
return x_win_title();
}

canonical_decompiled_code:
__int64 func16()
{
return x_win_title();
}

original_code:
void x_settitle(const char *title)
{
 x_win_title(title);
}

canonical_original_code:
void x_settitle(char *title)
{
 x_win_title(title);
}

variable_types:
title
char *


decompiled_code:
int __fastcall x_copytext(char *src, __int64 a2)
{
pthread_mutex_lock(&copybuf_mutex);
if ( copybuf )
free(copybuf);
copybuf = malloc(a2 + 1);
if ( copybuf )
{
strcpy((char *)copybuf, src);
xp_sem_post(&copybuf_set);
}
return pthread_mutex_unlock(&copybuf_mutex);
}

canonical_decompiled_code:
int __fastcall func17(char *src, __int64 a2)
{
pthread_mutex_lock(&copybuf_mutex);
if ( copybuf )
free(copybuf);
copybuf = malloc(a2 + 1);
if ( copybuf )
{
strcpy((char *)copybuf, src);
xp_sem_post(&copybuf_set);
}
return pthread_mutex_unlock(&copybuf_mutex);
}

original_code:
void x_copytext(const char *text, size_t buflen)
{
 pthread_mutex_lock(&copybuf_mutex);
 if(copybuf!=((void *)0)) {
  free(copybuf);
  copybuf=((void *)0);
 }
 copybuf=(char *)malloc(buflen+1);
 if(copybuf!=((void *)0)) {
  strcpy(copybuf, text);
  xp_sem_post(&copybuf_set);
 }
 pthread_mutex_unlock(&copybuf_mutex);
 return;
}

canonical_original_code:
void x_copytext(char *text, unsigned long buflen)
{
 pthread_mutex_lock(&copybuf_mutex);
 if(copybuf!=((void *)0)) {
  free(copybuf);
  copybuf=((void *)0);
 }
 copybuf=(char *)malloc(buflen+1);
 if(copybuf!=((void *)0)) {
  strcpy(copybuf, text);
  xp_sem_post(&copybuf_set);
 }
 pthread_mutex_unlock(&copybuf_mutex);
 return;
}

variable_types:
text
char *

variable_types:
buflen
unsigned long


decompiled_code:
void *x_getcliptext()
{
void *v0; // r12
char *v1; // rbp
size_t v2; // r13
void *v3; // rax

v0 = 0LL;
xp_sem_post(&pastebuf_request);
xp_sem_wait(&pastebuf_set);
v1 = pastebuf;
if ( pastebuf )
{
v2 = strlen(pastebuf) + 1;
v3 = malloc(v2);
v0 = v3;
if ( v3 )
memcpy(v3, v1, v2);
}
xp_sem_post(&pastebuf_request);
return v0;
}

canonical_decompiled_code:
void *func18()
{
void *v0; // r12
char *v1; // rbp
size_t v2; // r13
void *v3; // rax

v0 = 0LL;
xp_sem_post(&pastebuf_request);
xp_sem_wait(&pastebuf_set);
v1 = pastebuf;
if ( pastebuf )
{
v2 = strlen(pastebuf) + 1;
v3 = malloc(v2);
v0 = v3;
if ( v3 )
memcpy(v3, v1, v2);
}
xp_sem_post(&pastebuf_request);
return v0;
}

original_code:
char *x_getcliptext(void)
{
 char *ret=((void *)0);
 xp_sem_post(&pastebuf_request);
 xp_sem_wait(&pastebuf_set);
 if(pastebuf!=((void *)0)) {
  ret=(char *)malloc(strlen(pastebuf)+1);
  if(ret!=((void *)0))
   strcpy(ret,pastebuf);
 }
 xp_sem_post(&pastebuf_request);
 return(ret);
}

canonical_original_code:
char *x_getcliptext()
{
 char *ret = ((void *)0);
 xp_sem_post(&pastebuf_request);
 xp_sem_wait(&pastebuf_set);
 if(pastebuf!=((void *)0)) {
  ret=(char *)malloc(strlen(pastebuf)+1);
  if(ret!=((void *)0))
   strcpy(ret,pastebuf);
 }
 xp_sem_post(&pastebuf_request);
 return(ret);
}

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall x_setfont(int a1, int a2)
{
int v2; // er8
__int64 result; // rax

v2 = ciolib_getfont();
result = 0LL;
if ( v2 != a1 )
{
font_force = a2;
new_font = a1;
xp_sem_wait(&font_set);
result = setfont_return;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1, int a2)
{
int v2; // er8
__int64 result; // rax

v2 = ciolib_getfont();
result = 0LL;
if ( v2 != a1 )
{
font_force = a2;
new_font = a1;
xp_sem_wait(&font_set);
result = setfont_return;
}
return result;
}

original_code:
int x_setfont(int font, int force)
{
 if(font==ciolib_getfont())
  return(0);
 font_force=force;
 new_font=font;
 xp_sem_wait(&font_set);
 return(setfont_return);
}

variable_types: font int

variable_types: force int


decompiled_code:
__int64 x_getfont()
{
return new_font;
}

canonical_decompiled_code:
__int64 func20()
{
return new_font;
}

original_code:
int x_getfont(void)
{
 return(new_font);
}

canonical_original_code:
int x_getfont()
{
 return(new_font);
}


decompiled_code:
// attributes: thunk
__int64 x_loadfont()
{
return x_load_font();
}

canonical_decompiled_code:
__int64 func21()
{
return x_load_font();
}

original_code:
int x_loadfont(char *filename)
{
 return(x_load_font(filename));
}

variable_types:
filename
char *


RingBufInit

decompiled_code:
__int64 __fastcall RingBufInit(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
char *v4; // rax

v3 = a1 + 16;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 80) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 104) >> 3));
v4 = (char *)malloc(a2 + 1);
*(_QWORD *)a1 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 24) = &v4[a2];
*(_QWORD *)(a1 + 32) = a2;
xp_sem_init(a1 + 40, 0LL, 0LL);
xp_sem_init(a1 + 48, 0LL, 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 64), 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
char *v4; // rax

v3 = a1 + 16;
*(_QWORD *)(v3 - 8) = 0LL;
*(_QWORD *)(v3 + 80) = 0LL;
memset(
(void *)(v3 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v3 & 0xFFFFFFF8) + 104) >> 3));
v4 = (char *)malloc(a2 + 1);
*(_QWORD *)a1 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = v4;
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 24) = &v4[a2];
*(_QWORD *)(a1 + 32) = a2;
xp_sem_init(a1 + 40, 0LL, 0LL);
xp_sem_init(a1 + 48, 0LL, 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 64), 0LL);
return 0LL;
}

original_code:
int RingBufInit( RingBuf* rb, ulong size
 )
{
 memset(rb,0,sizeof(RingBuf));
 if((rb->pStart=(unsigned char *)malloc(size+1))==((void *)0))
  return(-1);
 rb->pHead=rb->pTail=rb->pStart;
 rb->pEnd=rb->pStart+size;
    rb->size=size;
 xp_sem_init(&rb->sem, 0, 0);
 xp_sem_init(&rb->highwater_sem, 0, 0);
 pthread_mutex_init(&rb->mutex,((void *)0));
 return(0);
}

canonical_original_code:
int RingBufInit(struct RingBuf *rb, unsigned long size)
{
 memset(rb,0,sizeof(RingBuf));
 if((rb->pStart=(unsigned char *)malloc(size+1))==((void *)0))
  return(-1);
 rb->pHead=rb->pTail=rb->pStart;
 rb->pEnd=rb->pStart+size;
    rb->size=size;
 xp_sem_init(&rb->sem, 0, 0);
 xp_sem_init(&rb->highwater_sem, 0, 0);
 pthread_mutex_init(&rb->mutex,((void *)0));
 return(0);
}

variable_types: struct RingBuf { unsigned char *pStart; unsigned char *pHead; unsigned char *pTail; unsigned char *pEnd; unsigned long size; struct xp_sem { unsigned int magic; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } *sem; struct xp_sem *highwater_sem; unsigned long highwater_mark; union pthread_mutex_t mutex; } *

variable_types:
size
unsigned long

user_defined_types: struct RingBuf { unsigned char *pStart; unsigned char *pHead; unsigned char *pTail; unsigned char *pEnd; unsigned long size; struct xp_sem *sem; struct xp_sem *highwater_sem; unsigned long highwater_mark; union pthread_mutex_t mutex; }


RingBufDispose

decompiled_code:
__int64 __fastcall RingBufDispose(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax
struct timeval v4[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = *(void **)a1;
if ( v2 )
free(v2);
xp_sem_post(a1 + 40);
while ( (unsigned int)xp_sem_destroy(a1 + 40) == -1 && *_errno_location() == 16 )
{
v4[0].tv_sec = 0LL;
v4[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v4);
xp_sem_post(a1 + 40);
}
while ( (unsigned int)xp_sem_destroy(a1 + 48) == -1 && *_errno_location() == 16 )
{
v4[0].tv_sec = 0LL;
v4[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v4);
xp_sem_post(a1 + 48);
}
while ( pthread_mutex_destroy((pthread_mutex_t *)(a1 + 64)) == 16 )
{
v4[0].tv_sec = 0LL;
v4[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v4);
}
*(_QWORD *)a1 = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 96) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 104) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax
struct timeval v4[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = *(void **)a1;
if ( v2 )
free(v2);
xp_sem_post(a1 + 40);
while ( (unsigned int)xp_sem_destroy(a1 + 40) == -1 && *_errno_location() == 16 )
{
v4[0].tv_sec = 0LL;
v4[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v4);
xp_sem_post(a1 + 40);
}
while ( (unsigned int)xp_sem_destroy(a1 + 48) == -1 && *_errno_location() == 16 )
{
v4[0].tv_sec = 0LL;
v4[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v4);
xp_sem_post(a1 + 48);
}
while ( pthread_mutex_destroy((pthread_mutex_t *)(a1 + 64)) == 16 )
{
v4[0].tv_sec = 0LL;
v4[0].tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, v4);
}
*(_QWORD *)a1 = 0LL;
result = 0LL;
*(_QWORD *)(a1 + 96) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 104) >> 3));
return result;
}

original_code:
void RingBufDispose( RingBuf* rb)
{
    if(rb->pStart!=((void *)0))
  free(rb->pStart);
 xp_sem_post(&rb->sem);
 while(xp_sem_destroy(&rb->sem)==-1 && (*__errno_location ())==16) {
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  xp_sem_post(&rb->sem);
 }
 while(xp_sem_destroy(&rb->highwater_sem)==-1 && (*__errno_location ())==16) {
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  xp_sem_post(&rb->highwater_sem);
 }
 while(pthread_mutex_destroy(&rb->mutex)==16)
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 memset(rb,0,sizeof(RingBuf));
}

canonical_original_code:
void RingBufDispose(struct RingBuf *rb)
{
    if(rb->pStart!=((void *)0))
  free(rb->pStart);
 xp_sem_post(&rb->sem);
 while(xp_sem_destroy(&rb->sem)==-1 && (*__errno_location ())==16) {
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  xp_sem_post(&rb->sem);
 }
 while(xp_sem_destroy(&rb->highwater_sem)==-1 && (*__errno_location ())==16) {
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  xp_sem_post(&rb->highwater_sem);
 }
 while(pthread_mutex_destroy(&rb->mutex)==16)
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 memset(rb,0,sizeof(RingBuf));
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


RingBufFull

decompiled_code:
__int64 __fastcall RingBufFull(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
__int64 v3; // r12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 64));
v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 16);
if ( v1 < v2 )
v3 = v1 - v2 + *(_QWORD *)(a1 + 32) + 1;
else
v3 = v1 - v2;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 64));
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
__int64 v3; // r12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 64));
v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 16);
if ( v1 < v2 )
v3 = v1 - v2 + *(_QWORD *)(a1 + 32) + 1;
else
v3 = v1 - v2;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 64));
return v3;
}

original_code:
ulong RingBufFull( RingBuf* rb )
{
 ulong retval;
 pthread_mutex_lock(&rb->mutex);
 retval = (rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1))));
 pthread_mutex_unlock(&rb->mutex);
 return(retval);
}

canonical_original_code:
unsigned long RingBufFull(struct RingBuf *rb)
{
 unsigned long retval;
 pthread_mutex_lock(&rb->mutex);
 retval = (rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1))));
 pthread_mutex_unlock(&rb->mutex);
 return(retval);
}

variable_types:
retval
unsigned long

return_type: unsigned long


RingBufFree

decompiled_code:
__int64 __fastcall RingBufFree(__int64 a1)
{
__int64 v1; // rbx

v1 = *(_QWORD *)(a1 + 32);
return v1 - RingBufFull(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx

v1 = *(_QWORD *)(a1 + 32);
return v1 - func2(a1);
}

original_code:
ulong RingBufFree( RingBuf* rb )
{
 ulong retval;
 retval = (rb->size - RingBufFull( rb ));
 return(retval);
}

canonical_original_code:
unsigned long RingBufFree(struct RingBuf *rb)
{
 unsigned long retval;
 retval = (rb->size - RingBufFull( rb ));
 return(retval);
}


RingBufWrite

original_code:
ulong RingBufWrite( RingBuf* rb, unsigned char* src, ulong cnt )
{
 ulong max, first, remain;
 if(rb->pStart==((void *)0))
  return(0);
 pthread_mutex_lock(&rb->mutex);
 max = (((ulong) rb->pEnd) - ((ulong) rb->pHead)) + 1;
 if( max >= cnt ) {
  first = cnt;
  remain = 0;
 } else {
  first = max;
  remain = cnt - first;
 }
 memcpy( rb->pHead, src, first );
 rb->pHead += first;
    src += first;
 if(remain) {
  rb->pHead = rb->pStart;
  memcpy(rb->pHead, src, remain);
  rb->pHead += remain;
 }
    if(rb->pHead > rb->pEnd)
     rb->pHead = rb->pStart;
 xp_sem_post(&rb->sem);
 if(rb->highwater_mark!=0 && (rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1))))>=rb->highwater_mark)
  xp_sem_post(&rb->highwater_sem);
 pthread_mutex_unlock(&rb->mutex);
 return(cnt);
}

canonical_original_code:
unsigned long RingBufWrite(struct RingBuf *rb, unsigned char *src, unsigned long cnt)
{
 unsigned long max; unsigned long first; unsigned long remain;
 if(rb->pStart==((void *)0))
  return(0);
 pthread_mutex_lock(&rb->mutex);
 max = (((unsigned long) rb->pEnd) - ((unsigned long) rb->pHead)) + 1;
 if( max >= cnt ) {
  first = cnt;
  remain = 0;
 } else {
  first = max;
  remain = cnt - first;
 }
 memcpy( rb->pHead, src, first );
 rb->pHead += first;
    src += first;
 if(remain) {
  rb->pHead = rb->pStart;
  memcpy(rb->pHead, src, remain);
  rb->pHead += remain;
 }
    if(rb->pHead > rb->pEnd)
     rb->pHead = rb->pStart;
 xp_sem_post(&rb->sem);
 if(rb->highwater_mark!=0 && (rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1))))>=rb->highwater_mark)
  xp_sem_post(&rb->highwater_sem);
 pthread_mutex_unlock(&rb->mutex);
 return(cnt);
}

variable_types:
src
unsigned char *

variable_types:
cnt
unsigned long

variable_types:
max
unsigned long

variable_types:
first
unsigned long

variable_types:
remain
unsigned long


RingBufRead

original_code:
ulong RingBufRead( RingBuf* rb, unsigned char* dst, ulong cnt )
{
 ulong max, first, remain, len;
 pthread_mutex_lock(&rb->mutex);
 len = (rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1))));
 if( len < cnt )
        cnt = len;
 max = (((ulong) rb->pEnd) - ((ulong) rb->pTail)) + 1;
 if( max >= cnt ) {
  first = cnt;
  remain = 0;
 } else {
  first = max;
  remain = cnt - first;
 }
    if(first && dst!=((void *)0)) {
  memcpy( dst, rb->pTail, first );
  dst += first;
    }
 rb->pTail += first;
 if( remain ){
  rb->pTail = rb->pStart;
        if(dst!=((void *)0))
   memcpy( dst, rb->pTail, remain );
  rb->pTail += remain;
 }
    if(rb->pTail > rb->pEnd)
  rb->pTail = rb->pStart;
 if((rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1)))) == 0)
  xp_sem_setvalue((&rb->sem), 0);
 if((rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1)))) < rb->highwater_mark)
  xp_sem_setvalue((&rb->highwater_sem), 0);
 pthread_mutex_unlock(&rb->mutex);
 return(cnt);
}

canonical_original_code:
unsigned long RingBufRead(struct RingBuf *rb, unsigned char *dst, unsigned long cnt)
{
 unsigned long max; unsigned long first; unsigned long remain; unsigned long len;
 pthread_mutex_lock(&rb->mutex);
 len = (rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1))));
 if( len < cnt )
        cnt = len;
 max = (((unsigned long) rb->pEnd) - ((unsigned long) rb->pTail)) + 1;
 if( max >= cnt ) {
  first = cnt;
  remain = 0;
 } else {
  first = max;
  remain = cnt - first;
 }
    if(first && dst!=((void *)0)) {
  memcpy( dst, rb->pTail, first );
  dst += first;
    }
 rb->pTail += first;
 if( remain ){
  rb->pTail = rb->pStart;
        if(dst!=((void *)0))
   memcpy( dst, rb->pTail, remain );
  rb->pTail += remain;
 }
    if(rb->pTail > rb->pEnd)
  rb->pTail = rb->pStart;
 if((rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1)))) == 0)
  xp_sem_setvalue((&rb->sem), 0);
 if((rb->pHead >= rb->pTail ? (rb->pHead - rb->pTail) : (rb->size - (rb->pTail - (rb->pHead + 1)))) < rb->highwater_mark)
  xp_sem_setvalue((&rb->highwater_sem), 0);
 pthread_mutex_unlock(&rb->mutex);
 return(cnt);
}

variable_types:
dst
unsigned char *

variable_types:
len
unsigned long


RingBufPeek

decompiled_code:
unsigned __int64 __fastcall RingBufPeek(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r12
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // rbx
size_t v9; // rdx
__int64 v10; // [rsp+8h] [rbp-40h]

v4 = RingBufFull(a1);
if ( v4 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 64));
v6 = *(_QWORD *)(a1 + 24);
v7 = *(_QWORD *)(a1 + 16);
if ( v4 > a3 )
v4 = a3;
v8 = v6 + 1;
v9 = v6 + 1 - v7;
if ( v4 > v9 )
{
v10 = v6 + 1 - v7;
memcpy(a2, *(const void **)(a1 + 16), v9);
memcpy(&a2[v10], *(const void **)a1, v7 - v8 + v4);
}
else
{
memcpy(a2, *(const void **)(a1 + 16), v4);
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 64));
}
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r12
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // rbx
size_t v9; // rdx
__int64 v10; // [rsp+8h] [rbp-40h]

v4 = func2(a1);
if ( v4 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 64));
v6 = *(_QWORD *)(a1 + 24);
v7 = *(_QWORD *)(a1 + 16);
if ( v4 > a3 )
v4 = a3;
v8 = v6 + 1;
v9 = v6 + 1 - v7;
if ( v4 > v9 )
{
v10 = v6 + 1 - v7;
memcpy(a2, *(const void **)(a1 + 16), v9);
memcpy(&a2[v10], *(const void **)a1, v7 - v8 + v4);
}
else
{
memcpy(a2, *(const void **)(a1 + 16), v4);
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 64));
}
return v4;
}

original_code:
ulong RingBufPeek( RingBuf* rb, unsigned char* dst, ulong cnt)
{
 ulong max, first, remain, len;
 len = RingBufFull( rb );
 if( len == 0 )
  return(0);
 pthread_mutex_lock(&rb->mutex);
 if( len < cnt )
        cnt = len;
 max = (((ulong) rb->pEnd) - ((ulong) rb->pTail)) + 1;
 if( max >= cnt ) {
  first = cnt;
  remain = 0;
 } else {
  first = max;
  remain = cnt - first;
 }
 memcpy( dst, rb->pTail, first );
 dst += first;
 if(remain) {
  memcpy( dst, rb->pStart, remain );
 }
 pthread_mutex_unlock(&rb->mutex);
 return(cnt);
}

canonical_original_code:
unsigned long RingBufPeek(struct RingBuf *rb, unsigned char *dst, unsigned long cnt)
{
 unsigned long max; unsigned long first; unsigned long remain; unsigned long len;
 len = RingBufFull( rb );
 if( len == 0 )
  return(0);
 pthread_mutex_lock(&rb->mutex);
 if( len < cnt )
        cnt = len;
 max = (((unsigned long) rb->pEnd) - ((unsigned long) rb->pTail)) + 1;
 if( max >= cnt ) {
  first = cnt;
  remain = 0;
 } else {
  first = max;
  remain = cnt - first;
 }
 memcpy( dst, rb->pTail, first );
 dst += first;
 if(remain) {
  memcpy( dst, rb->pStart, remain );
 }
 pthread_mutex_unlock(&rb->mutex);
 return(cnt);
}


RingBufReInit

decompiled_code:
int __fastcall RingBufReInit(__int64 *a1)
{
__int64 v1; // rax

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v1 = *a1;
a1[2] = *a1;
a1[1] = v1;
xp_sem_setvalue(a1 + 5, 0LL);
xp_sem_setvalue(a1 + 6, 0LL);
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
v1 = *a1;
a1[2] = *a1;
a1[1] = v1;
xp_sem_setvalue(a1 + 5, 0LL);
xp_sem_setvalue(a1 + 6, 0LL);
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

original_code:
void RingBufReInit(RingBuf* rb)
{
 pthread_mutex_lock(&rb->mutex);
 rb->pHead = rb->pTail = rb->pStart;
 xp_sem_setvalue((&rb->sem), 0);
 xp_sem_setvalue((&rb->highwater_sem), 0);
 pthread_mutex_unlock(&rb->mutex);
}

canonical_original_code:
void RingBufReInit(struct RingBuf *rb)
{
 pthread_mutex_lock(&rb->mutex);
 rb->pHead = rb->pTail = rb->pStart;
 xp_sem_setvalue((&rb->sem), 0);
 xp_sem_setvalue((&rb->highwater_sem), 0);
 pthread_mutex_unlock(&rb->mutex);
}


decompiled_code:
int __fastcall get_game_status(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int result; // eax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

password = 0;
memset(&node, 0, 0xF8uLL);
*((_WORD *)&node + 124) = 0;
sprintf(v4, "gamestat.%d", a1);
v1 = nopen(v4, 0LL);
if ( v1 == -1 )
{
sprintf(v4, "Couldn't open gamestat.%d for READ", a1);
result = bputs(v4);
}
else
{
v2 = v1;
read(v1, &password, 8uLL);
read(v2, &total_players, 2uLL);
read(v2, &dealer, 2uLL);
read(v2, &cur_node, 2uLL);
read(v2, &firstbid, 2uLL);
read(v2, &stage, 2uLL);
read(v2, &current_bet, 8uLL);
read(v2, &total_pot, 8uLL);
read(v2, &node, sys_nodes);
result = close(v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int result; // eax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

password = 0;
memset(&node, 0, 0xF8uLL);
*((_WORD *)&node + 124) = 0;
sprintf(v4, "gamestat.%d", a1);
v1 = nopen(v4, 0LL);
if ( v1 == -1 )
{
sprintf(v4, "Couldn't open gamestat.%d for READ", a1);
result = bputs(v4);
}
else
{
v2 = v1;
read(v1, &password, 8uLL);
read(v2, &total_players, 2uLL);
read(v2, &dealer, 2uLL);
read(v2, &cur_node, 2uLL);
read(v2, &firstbid, 2uLL);
read(v2, &stage, 2uLL);
read(v2, &current_bet, 8uLL);
read(v2, &total_pot, 8uLL);
read(v2, &node, sys_nodes);
result = close(v2);
}
return result;
}

original_code:
void get_game_status(int tablenum)
{
    char str[256];
    int file;
    memset(node,'\0',250);
    password[0]=0;
    sprintf(str,"gamestat.%d",tablenum);
    if ((file=nopen(str,00))==-1) {
        sprintf(str,"Couldn't open gamestat.%d for READ",tablenum);
        bputs(str);
        return;
    }
    read(file,password,8);
    read(file,&total_players,sizeof(total_players));
    read(file,&dealer,sizeof(dealer));
    read(file,&cur_node,sizeof(cur_node));
    read(file,&firstbid,sizeof(firstbid));
    read(file,&stage,sizeof(stage));
    read(file,&current_bet,sizeof(current_bet));
    read(file,&total_pot,sizeof(total_pot));
    read(file,node,sys_nodes);
    close(file);
}

variable_types: tablenum int

variable_types:
str
char [256]

variable_types: file int


decompiled_code:
int __fastcall put_game_status(unsigned int a1)
{
int v1; // eax
int v2; // ebp
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v4, "gamestat.%d", (unsigned int)cur_table);
v1 = nopen(v4, 65LL);
if ( v1 == -1 )
return bputs("Couldn't open GAMESTAT for WRITE");
v2 = v1;
write(v1, &password, 8uLL);
write(v2, &total_players, 2uLL);
write(v2, &dealer, 2uLL);
write(v2, &cur_node, 2uLL);
write(v2, &firstbid, 2uLL);
write(v2, &stage, 2uLL);
write(v2, &current_bet, 8uLL);
write(v2, &total_pot, 8uLL);
if ( sys_nodes > a1 )
{
lseek(v2, (int)a1, 1);
write(v2, &node[a1], 1uLL);
}
else
{
write(v2, node, 0xFAuLL);
}
return close(v2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
int v1; // eax
int v2; // ebp
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v4, "gamestat.%d", (unsigned int)cur_table);
v1 = nopen(v4, 65LL);
if ( v1 == -1 )
return bputs("Couldn't open GAMESTAT for WRITE");
v2 = v1;
write(v1, &password, 8uLL);
write(v2, &total_players, 2uLL);
write(v2, &dealer, 2uLL);
write(v2, &cur_node, 2uLL);
write(v2, &firstbid, 2uLL);
write(v2, &stage, 2uLL);
write(v2, &current_bet, 8uLL);
write(v2, &total_pot, 8uLL);
if ( sys_nodes > a1 )
{
lseek(v2, (int)a1, 1);
write(v2, &node[a1], 1uLL);
}
else
{
write(v2, node, 0xFAuLL);
}
return close(v2);
}

original_code:
void put_game_status(int specnode)
{
    char str[256];
    int file;
    sprintf(str,"gamestat.%d",cur_table);
    if ((file=nopen(str,01|0100))==-1) {
        bputs("Couldn't open GAMESTAT for WRITE");
        return;
    }
    write(file,password,8);
    write(file,&total_players,sizeof(total_players));
    write(file,&dealer,sizeof(dealer));
    write(file,&cur_node,sizeof(cur_node));
    write(file,&firstbid,sizeof(firstbid));
    write(file,&stage,sizeof(stage));
    write(file,&current_bet,sizeof(current_bet));
    write(file,&total_pot,sizeof(total_pot));
    if (specnode>=0 && specnode<sys_nodes) {
        lseek(file,specnode,1);
        write(file,&node[specnode],1);
    } else write(file,node,250);
    close(file);
}

variable_types: specnode int


decompiled_code:
int __fastcall get_player(unsigned int a1)
{
int v1; // eax
int v2; // ebp
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v4, "player.%d", a1);
v1 = nopen(v4, 0LL);
if ( v1 == -1 )
return bprintf("get_player: Error opening '%s'\r\n", v4);
v2 = v1;
read(v1, &cur_table, 2uLL);
read(v2, &temp_num, 2uLL);
read(v2, &player_bet, 8uLL);
read(v2, &temppts, 8uLL);
read(v2, &rank, 4uLL);
read(v2, &dupcard1, 2uLL);
read(v2, &dupcard2, 2uLL);
read(v2, &hicard, 2uLL);
read(v2, (char *)&hand + 20 * (int)a1, 0xAuLL);
return close(v2);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1)
{
int v1; // eax
int v2; // ebp
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v4, "player.%d", a1);
v1 = nopen(v4, 0LL);
if ( v1 == -1 )
return bprintf("get_player: Error opening '%s'\r\n", v4);
v2 = v1;
read(v1, &cur_table, 2uLL);
read(v2, &temp_num, 2uLL);
read(v2, &player_bet, 8uLL);
read(v2, &temppts, 8uLL);
read(v2, &rank, 4uLL);
read(v2, &dupcard1, 2uLL);
read(v2, &dupcard2, 2uLL);
read(v2, &hicard, 2uLL);
read(v2, (char *)&hand + 20 * (int)a1, 0xAuLL);
return close(v2);
}

original_code:
void get_player(int player)
{
    int file;
    char str[256];
    sprintf(str,"player.%d",player);
    if((file=nopen(str,00))==-1) {
    bprintf("get_player: Error opening '%s'\r\n",str);
        return; }
    read(file,&cur_table,sizeof(cur_table));
    read(file,&temp_num,sizeof(temp_num));
    read(file,&player_bet,sizeof(player_bet));
    read(file,&temppts,sizeof(temppts));
    read(file,&rank,sizeof(rank));
    read(file,&dupcard1,sizeof(dupcard1));
    read(file,&dupcard2,sizeof(dupcard2));
    read(file,&hicard,sizeof(hicard));
    read(file,hand[player],5*sizeof(card_t));
    close(file);
}

variable_types: player int


decompiled_code:
__int64 __fastcall send_all_message(const char *a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( sys_nodes )
{
v2 = 1LL;
do
{
if ( node[v2 - 1] && node_num != (_DWORD)v2 && (_DWORD)v2 != a2 )
send_player_message(v2, a1);
result = sys_nodes;
++v2;
}
while ( sys_nodes >= (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( sys_nodes )
{
v2 = 1LL;
do
{
if ( node[v2 - 1] && node_num != (_DWORD)v2 && (_DWORD)v2 != a2 )
func3(v2, a1);
result = sys_nodes;
++v2;
}
while ( sys_nodes >= (int)v2 );
}
return result;
}

original_code:
void send_all_message(char *msg,int exception)
{
    int num;
    for (num=1;num<=sys_nodes;num++) {
        if (node[num-1] && (num!=node_num) && (num!=exception)) {
            send_player_message(num,msg);
        }
    }
}

canonical_original_code:
void send_all_message(char *msg, int exception)
{
    int num;
    for (num=1;num<=sys_nodes;num++) {
        if (node[num-1] && (num!=node_num) && (num!=exception)) {
            send_player_message(num,msg);
        }
    }
}

variable_types:
msg
char *

variable_types: exception int

variable_types: num int