decompiled_code:
__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());
}


repo: ftnapps/pkg-sbbs

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

return_type: void


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

return_type: int


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; // ebp
__int64 v3; // rdx
__int64 v5; // rbx
int v6; // er13
int v7; // er12
__int16 v8; // bx
unsigned int v9; // eax
unsigned __int8 v10; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v11; // [rsp+6h] [rbp-32h]
unsigned __int8 v12; // [rsp+7h] [rbp-31h]
unsigned __int8 v13; // [rsp+8h] [rbp-30h]
unsigned __int8 v14; // [rsp+Eh] [rbp-2Ah]
unsigned __int8 v15; // [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);
break;
case 8:
if ( CursCol )
--CursCol;
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = x_curr_attr | 0x20;
break;
case 9:
v5 = 0LL;
while ( 1 )
{
v6 = v5;
v7 = x_tabs[v5];
if ( v7 > (int)ciolib_wherex(a1, a2, v3) )
break;
v6 = ++v5;
if ( v5 == 10 )
goto LABEL_14;
}
while ( v7 > (int)ciolib_wherex(a1, a2, v3) )
{
a1 = 32LL;
ciolib_putch(32LL);
}
LABEL_14:
if ( v6 == 10 )
{
ciolib_putch(13LL);
ciolib_putch(10LL);
}
break;
case 10:
ciolib_gettextinfo(&v10);
if ( (unsigned int)ciolib_wherey() == v13 - v11 + 1 )
ciolib_wscroll();
else
++CursRow;
break;
case 13:
ciolib_gettextinfo(&v10);
CursCol = v10 - 1;
break;
default:
v8 = a1 | x_curr_attr;
ciolib_gettextinfo(&v10);
if ( (unsigned int)ciolib_wherey() == v13 - v11 + 1
&& (unsigned int)((__int64 (*)(void))ciolib_wherex)() == v12 - v10 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v8;
ciolib_wscroll();
v9 = ciolib_wherey();
ciolib_gotoxy(v10, v9);
}
else if ( (unsigned int)((__int64 (*)(void))ciolib_wherex)() == v12 - v10 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v8;
ciolib_gotoxy(v10, (unsigned int)v15 + 1);
}
else
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v8;
ciolib_gotoxy((unsigned int)v14 + 1, v15);
}
break;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rdx
__int64 v5; // rbx
int v6; // er13
int v7; // er12
__int16 v8; // bx
unsigned int v9; // eax
unsigned __int8 v10; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v11; // [rsp+6h] [rbp-32h]
unsigned __int8 v12; // [rsp+7h] [rbp-31h]
unsigned __int8 v13; // [rsp+8h] [rbp-30h]
unsigned __int8 v14; // [rsp+Eh] [rbp-2Ah]
unsigned __int8 v15; // [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);
break;
case 8:
if ( CursCol )
--CursCol;
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = x_curr_attr | 0x20;
break;
case 9:
v5 = 0LL;
while ( 1 )
{
v6 = v5;
v7 = x_tabs[v5];
if ( v7 > (int)ciolib_wherex(a1, a2, v3) )
break;
v6 = ++v5;
if ( v5 == 10 )
goto LABEL_14;
}
while ( v7 > (int)ciolib_wherex(a1, a2, v3) )
{
a1 = 32LL;
ciolib_putch(32LL);
}
LABEL_14:
if ( v6 == 10 )
{
ciolib_putch(13LL);
ciolib_putch(10LL);
}
break;
case 10:
ciolib_gettextinfo(&v10);
if ( (unsigned int)ciolib_wherey() == v13 - v11 + 1 )
ciolib_wscroll();
else
++CursRow;
break;
case 13:
ciolib_gettextinfo(&v10);
CursCol = v10 - 1;
break;
default:
v8 = a1 | x_curr_attr;
ciolib_gettextinfo(&v10);
if ( (unsigned int)ciolib_wherey() == v13 - v11 + 1
&& (unsigned int)((__int64 (*)(void))ciolib_wherex)() == v12 - v10 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v8;
ciolib_wscroll();
v9 = ciolib_wherey();
ciolib_gotoxy(v10, v9);
}
else if ( (unsigned int)((__int64 (*)(void))ciolib_wherex)() == v12 - v10 + 1 )
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v8;
ciolib_gotoxy(v10, (unsigned int)v15 + 1);
}
else
{
*(_WORD *)(vmem + 2LL * (CursCol + DpyCols * CursRow)) = v8;
ciolib_gotoxy((unsigned int)v14 + 1, v15);
}
break;
}
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: 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; }

variable_types:
sch
unsigned short

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

variable_types: x int

variable_types: y int


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; // ebx

if ( x_nextchar )
return (unsigned int)x_getch();
v0 = x_getch();
v1 = v0;
if ( v0 )
ciolib_putch(v0);
return v1;
}

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

if ( x_nextchar )
return (unsigned int)func11();
v0 = func11();
v1 = v0;
if ( v0 )
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:
__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)
{
void *v3; // rdi

pthread_mutex_lock(&copybuf_mutex);
if ( copybuf )
free(copybuf);
v3 = malloc(a2 + 1);
copybuf = v3;
if ( v3 )
{
strcpy((char *)v3, src);
xp_sem_post(&copybuf_set);
}
return pthread_mutex_unlock(&copybuf_mutex);
}

canonical_decompiled_code:
int __fastcall func17(char *src, __int64 a2)
{
void *v3; // rdi

pthread_mutex_lock(&copybuf_mutex);
if ( copybuf )
free(copybuf);
v3 = malloc(a2 + 1);
copybuf = v3;
if ( v3 )
{
strcpy((char *)v3, 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:
char *x_getcliptext()
{
const char *v0; // rbp
char *v1; // rbx
size_t v2; // rax
char *v3; // rax

xp_sem_post(&pastebuf_request);
xp_sem_wait(&pastebuf_set);
v0 = pastebuf;
v1 = pastebuf;
if ( pastebuf )
{
v2 = strlen(pastebuf);
v3 = (char *)malloc(v2 + 1);
v1 = v3;
if ( v3 )
strcpy(v3, v0);
}
xp_sem_post(&pastebuf_request);
return v1;
}

canonical_decompiled_code:
char *func18()
{
const char *v0; // rbp
char *v1; // rbx
size_t v2; // rax
char *v3; // rax

xp_sem_post(&pastebuf_request);
xp_sem_wait(&pastebuf_set);
v0 = pastebuf;
v1 = pastebuf;
if ( pastebuf )
{
v2 = strlen(pastebuf);
v3 = (char *)malloc(v2 + 1);
v1 = v3;
if ( v3 )
strcpy(v3, v0);
}
xp_sem_post(&pastebuf_request);
return v1;
}

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 *

return_type: char *


decompiled_code:
__int64 __fastcall x_setfont(int a1, int a2)
{
int v2; // edx
__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; // edx
__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:
__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)
{
char *v2; // rax

*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 96) = 0LL;
memset(
(void *)((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 16) & 0xFFFFFFF8) + 104) >> 3));
v2 = (char *)malloc(a2 + 1);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = v2;
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 24) = &v2[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)
{
char *v2; // rax

*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 96) = 0LL;
memset(
(void *)((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 16) & 0xFFFFFFF8) + 104) >> 3));
v2 = (char *)malloc(a2 + 1);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = v2;
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 24) = &v2[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; }

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


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;
*(_QWORD *)(a1 + 96) = 0LL;
result = 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;
*(_QWORD *)(a1 + 96) = 0LL;
result = 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; }

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


RingBufFull

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

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; // rbx

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; // rbx
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r13
unsigned __int64 v9; // r14

v4 = RingBufFull(a1);
if ( v4 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 64));
if ( v4 > a3 )
v4 = a3;
v6 = *(_QWORD *)(a1 + 16);
v7 = *(_QWORD *)(a1 + 24);
v8 = v7 + 1;
v9 = v7 + 1 - v6;
if ( v4 <= v9 )
{
memcpy(a2, *(const void **)(a1 + 16), v4);
}
else
{
memcpy(a2, *(const void **)(a1 + 16), v7 + 1 - v6);
memcpy(&a2[v9], *(const void **)a1, v6 - v8 + 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; // rbx
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r13
unsigned __int64 v9; // r14

v4 = func2(a1);
if ( v4 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 64));
if ( v4 > a3 )
v4 = a3;
v6 = *(_QWORD *)(a1 + 16);
v7 = *(_QWORD *)(a1 + 24);
v8 = v7 + 1;
v9 = v7 + 1 - v6;
if ( v4 <= v9 )
{
memcpy(a2, *(const void **)(a1 + 16), v4);
}
else
{
memcpy(a2, *(const void **)(a1 + 16), v7 + 1 - v6);
memcpy(&a2[v9], *(const void **)a1, v6 - v8 + 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; // ebx
int result; // eax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

memset(&node, 0, 0xF8uLL);
*((_WORD *)&node + 124) = 0;
password = 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; // ebx
int result; // eax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

memset(&node, 0, 0xF8uLL);
*((_WORD *)&node + 124) = 0;
password = 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; // ebx
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 ( a1 < sys_nodes )
{
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; // ebx
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 ( a1 < sys_nodes )
{
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; // ebx
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; // ebx
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 && a2 != (_DWORD)v2 )
send_player_message(v2, a1);
++v2;
result = sys_nodes;
}
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 && a2 != (_DWORD)v2 )
func3(v2, a1);
++v2;
result = sys_nodes;
}
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


decompiled_code:
int quit_out()
{
__int64 v0; // rcx
__int64 v1; // rax
int v2; // eax
int v3; // ebx
unsigned int v4; // ebx
__int64 v5; // rax
unsigned __int64 v7; // [rsp+0h] [rbp-118h] BYREF
__int64 buf; // [rsp+8h] [rbp-110h] BYREF
char s[8]; // [rsp+10h] [rbp-108h] BYREF
char v10[24]; // [rsp+18h] [rbp-100h] BYREF

v0 = newpts - user_cdt - xfer_pts2;
xfer_pts2 = newpts - user_cdt;
buf = v0 / 1024;
if ( v0 / 1024 )
{
v7 = time_played / 0x3CuLL;
sprintf(s, "%-25.25s", (const char *)&user_name);
v2 = nopen("dpoker.plr", 1089LL);
v3 = v2;
if ( v2 != -1 )
{
write(v2, s, 0x19uLL);
write(v3, &v7, 8uLL);
write(v3, &buf, 8uLL);
close(v3);
}
}
buf = 0LL;
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
get_game_status(cur_table);
LODWORD(v1) = node_num - 1;
if ( (unsigned __int8)(node[(int)v1] - 1) <= 4u )
{
node[(int)v1] = 0;
--total_players;
put_game_status(0xFFFFFFFF);
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
sprintf(s, asc_21F0, node_num, &user_name);
send_all_message(s, 0);
if ( total_players )
{
LODWORD(v1) = node_num;
if ( node_num == dealer && sys_nodes )
{
v1 = 1LL;
while ( 1 )
{
v4 = v1;
if ( node[v1 - 1] == 1 )
break;
if ( sys_nodes < (int)++v1 )
return v1;
}
dealer = v1;
if ( cur_node == node_num )
cur_node = v1;
if ( total_players == 1 )
{
current_bet = 0LL;
stage = 0;
}
put_game_status(0xFFFFFFFF);
get_player(v4);
v5 = username((unsigned __int16)temp_num);
sprintf(s, asc_2220, v5);
bprintf(s);
send_all_message(s, v4);
*(_QWORD *)s = 0x6F5968016D010A0DLL;
strcpy(v10, "u are now the dealer.");
LODWORD(v1) = send_player_message(v4, s);
}
}
else
{
sprintf(s, "gamestat.%d", (unsigned int)cur_table);
LODWORD(v1) = unlink(s);
}
}
return v1;
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rcx
__int64 v1; // rax
int v2; // eax
int v3; // ebx
unsigned int v4; // ebx
__int64 v5; // rax
unsigned __int64 v7; // [rsp+0h] [rbp-118h] BYREF
__int64 buf; // [rsp+8h] [rbp-110h] BYREF
char s[8]; // [rsp+10h] [rbp-108h] BYREF
char v10[24]; // [rsp+18h] [rbp-100h] BYREF

v0 = newpts - user_cdt - xfer_pts2;
xfer_pts2 = newpts - user_cdt;
buf = v0 / 1024;
if ( v0 / 1024 )
{
v7 = time_played / 0x3CuLL;
sprintf(s, "%-25.25s", (const char *)&user_name);
v2 = nopen("dpoker.plr", 1089LL);
v3 = v2;
if ( v2 != -1 )
{
write(v2, s, 0x19uLL);
write(v3, &v7, 8uLL);
write(v3, &buf, 8uLL);
close(v3);
}
}
buf = 0LL;
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
func0(cur_table);
LODWORD(v1) = node_num - 1;
if ( (unsigned __int8)(node[(int)v1] - 1) <= 4u )
{
node[(int)v1] = 0;
--total_players;
func1(0xFFFFFFFF);
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
sprintf(s, asc_21F0, node_num, &user_name);
func4(s, 0);
if ( total_players )
{
LODWORD(v1) = node_num;
if ( node_num == dealer && sys_nodes )
{
v1 = 1LL;
while ( 1 )
{
v4 = v1;
if ( node[v1 - 1] == 1 )
break;
if ( sys_nodes < (int)++v1 )
return v1;
}
dealer = v1;
if ( cur_node == node_num )
cur_node = v1;
if ( total_players == 1 )
{
current_bet = 0LL;
stage = 0;
}
func1(0xFFFFFFFF);
func2(v4);
v5 = username((unsigned __int16)temp_num);
sprintf(s, asc_2220, v5);
bprintf(s);
func4(s, v4);
*(_QWORD *)s = 0x6F5968016D010A0DLL;
strcpy(v10, "u are now the dealer.");
LODWORD(v1) = func3(v4, s);
}
}
else
{
sprintf(s, "gamestat.%d", (unsigned int)cur_table);
LODWORD(v1) = unlink(s);
}
}
return v1;
}

original_code:
void quit_out()
{
    char str[256];
    int num,file;
    long xfer_pts;
    unsigned long x;
    xfer_pts=(newpts-user_cdt)-xfer_pts2;
    xfer_pts2+=xfer_pts;
    xfer_pts=xfer_pts/1024L;
    if (xfer_pts!=0) {
        x=time_played/60;
        sprintf(str,"%-25.25s",user_name);
        if ((file=nopen("dpoker.plr",01|0100|02000))!=-1) {
            write(file,str,25);
            write(file,&x,sizeof(x));
            write(file,&xfer_pts,sizeof(xfer_pts));
            close(file);
        }
    }
    xfer_pts=0;
    sprintf(str,"message.%d",node_num);
    unlink(str);
    sprintf(str,"player.%d",node_num);
    unlink(str);
    get_game_status(cur_table);
    if (node[node_num-1]>0 && node[node_num-1]<6) {
        node[node_num-1]=0; --total_players;
        put_game_status(-1);
        sprintf(str,"message.%d",node_num);
        unlink(str);
        sprintf(str,"player.%d",node_num);
        unlink(str);
        sprintf(str,"\r\n\1n\1gNode %2d: \1h%s \1n\1ghas left the game.\1n"
                ,node_num,user_name);
        send_all_message(str,0);
        if (!total_players) {
            sprintf(str,"gamestat.%d",cur_table);
            unlink(str);
            return;
        } else {
            if (dealer==node_num) {
                for (num=1;num<=sys_nodes;num++) {
                    if (node[num-1]==1) {
                        dealer=num; if (cur_node==node_num) cur_node=num;
                        if (total_players==1) { current_bet=0; stage=0; }
                        put_game_status(-1); get_player(num);
                        sprintf(str,"\r\n\1y\1h%s \1m\1his the new dealer."
                                ,username(temp_num));
                        bprintf(str);
                        send_all_message(str,num);
                        sprintf(str,"\r\n\1m\1hYou are now the dealer.");
                        send_player_message(num,str);
                        return;
                    }
                }
            }
        }
    }
}

canonical_original_code:
void quit_out()
{
    char str[256];
    int num; int file;
    long xfer_pts;
    unsigned long x;
    xfer_pts=(newpts-user_cdt)-xfer_pts2;
    xfer_pts2+=xfer_pts;
    xfer_pts=xfer_pts/1024L;
    if (xfer_pts!=0) {
        x=time_played/60;
        sprintf(str,"%-25.25s",user_name);
        if ((file=nopen("dpoker.plr",01|0100|02000))!=-1) {
            write(file,str,25);
            write(file,&x,sizeof(x));
            write(file,&xfer_pts,sizeof(xfer_pts));
            close(file);
        }
    }
    xfer_pts=0;
    sprintf(str,"message.%d",node_num);
    unlink(str);
    sprintf(str,"player.%d",node_num);
    unlink(str);
    get_game_status(cur_table);
    if (node[node_num-1]>0 && node[node_num-1]<6) {
        node[node_num-1]=0; --total_players;
        put_game_status(-1);
        sprintf(str,"message.%d",node_num);
        unlink(str);
        sprintf(str,"player.%d",node_num);
        unlink(str);
        sprintf(str,"\r\n\1n\1gNode %2d: \1h%s \1n\1ghas left the game.\1n"
                ,node_num,user_name);
        send_all_message(str,0);
        if (!total_players) {
            sprintf(str,"gamestat.%d",cur_table);
            unlink(str);
            return;
        } else {
            if (dealer==node_num) {
                for (num=1;num<=sys_nodes;num++) {
                    if (node[num-1]==1) {
                        dealer=num; if (cur_node==node_num) cur_node=num;
                        if (total_players==1) { current_bet=0; stage=0; }
                        put_game_status(-1); get_player(num);
                        sprintf(str,"\r\n\1y\1h%s \1m\1his the new dealer."
                                ,username(temp_num));
                        bprintf(str);
                        send_all_message(str,num);
                        sprintf(str,"\r\n\1m\1hYou are now the dealer.");
                        send_player_message(num,str);
                        return;
                    }
                }
            }
        }
    }
}

variable_types:
x
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rsi
const char **v5; // rbx
const char **v6; // r12
const char *v7; // rbp
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v4 = getenv("SBBSNODE");
strcpy(&node_dir, v4);
backslash(&node_dir);
if ( argc > 1 )
{
if ( !strcasecmp(argv[1], "/?") )
{
printf("\r\nDomain Poker Clean-Up Copyright 2005 Domain Entertainment");
puts("\r\n\r\nUsage: DPCLEAN [/options]\r");
printf("\r\nOptions: DAILY = Perform daily clean-up");
return 0;
}
v5 = argv + 1;
v6 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v7 = *v5;
if ( !strchr(*v5, 47) )
{
strcpy(&node_dir, v7);
backslash(&node_dir);
}
++v5;
}
while ( v5 != v6 );
}
initdata();
sprintf(v9, "player.%d", node_num);
if ( (unsigned int)fexist(v9) )
{
get_player(node_num);
newpts = temppts;
quit_out();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rsi
const char **v5; // rbx
const char **v6; // r12
const char *v7; // rbp
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v4 = getenv("SBBSNODE");
strcpy(&node_dir, v4);
backslash(&node_dir);
if ( argc > 1 )
{
if ( !strcasecmp(argv[1], "/?") )
{
printf("\r\nDomain Poker Clean-Up Copyright 2005 Domain Entertainment");
puts("\r\n\r\nUsage: DPCLEAN [/options]\r");
printf("\r\nOptions: DAILY = Perform daily clean-up");
return 0;
}
v5 = argv + 1;
v6 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v7 = *v5;
if ( !strchr(*v5, 47) )
{
strcpy(&node_dir, v7);
backslash(&node_dir);
}
++v5;
}
while ( v5 != v6 );
}
initdata();
sprintf(v9, "player.%d", node_num);
if ( (unsigned int)fexist(v9) )
{
func2(node_num);
newpts = temppts;
func5();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    char str[128];
    int x;
    sprintf(node_dir,"%s",getenv("SBBSNODE"));
    backslash(node_dir);
    if(argc>1 && !strcasecmp(argv[1],"/?")) {
        printf("\r\nDomain Poker Clean-Up  Copyright 2005 Domain "
                "Entertainment");
        printf("\r\n\r\nUsage: DPCLEAN [/options]\r\n");
        printf("\r\nOptions: DAILY = Perform daily clean-up");
        return(0);
    }
    for (x=1; x<argc; x++) {
        if (!strchr(argv[x],'/')) {
            strcpy(node_dir,argv[x]);
            backslash(node_dir); } }
    initdata();
    sprintf(str,"player.%d",node_num);
    if (!fexist(str)) return(0);
    else {
        get_player(node_num);
        newpts=temppts;
        quit_out();
    }
    return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
str
char [128]

variable_types: x int


decompiled_code:
const char *__fastcall telnet_cmd_desc(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 < 0xF1u )
{
sprintf(unknown_1, "%d", a1);
result = unknown_1;
}
else
{
switch ( a1 )
{
case 0xF1:
result = "NOP";
break;
case 0xF2:
result = "SYNC";
break;
case 0xF3:
result = "BRK";
break;
case 0xF4:
result = "IP";
break;
case 0xF5:
result = "AO";
break;
case 0xF6:
result = "AYT";
break;
case 0xF7:
result = "EC";
break;
case 0xF8:
result = "EL";
break;
case 0xF9:
result = "GA";
break;
case 0xFA:
result = "SB";
break;
case 0xFB:
result = "WILL";
break;
case 0xFC:
result = "WON'T";
break;
case 0xFD:
result = (const char *)&unk_2E4;
break;
case 0xFE:
result = "DON'T";
break;
case 0xFF:
result = (const char *)&unk_2E0;
break;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 < 0xF1u )
{
sprintf(unknown_1, "%d", a1);
result = unknown_1;
}
else
{
switch ( a1 )
{
case 0xF1:
result = "NOP";
break;
case 0xF2:
result = "SYNC";
break;
case 0xF3:
result = "BRK";
break;
case 0xF4:
result = "IP";
break;
case 0xF5:
result = "AO";
break;
case 0xF6:
result = "AYT";
break;
case 0xF7:
result = "EC";
break;
case 0xF8:
result = "EL";
break;
case 0xF9:
result = "GA";
break;
case 0xFA:
result = "SB";
break;
case 0xFB:
result = "WILL";
break;
case 0xFC:
result = "WON'T";
break;
case 0xFD:
result = (const char *)&unk_2E4;
break;
case 0xFE:
result = "DON'T";
break;
case 0xFF:
result = (const char *)&unk_2E0;
break;
}
}
return result;
}

original_code:
const char* telnet_cmd_desc(unsigned char cmd)
{
 static char unknown[32];
 switch(cmd) {
     case 255: return("IAC");
     case 254: return("DON'T");
     case 253: return("DO");
     case 252: return("WON'T");
     case 251: return("WILL");
     case 250: return("SB");
     case 249: return("GA");
     case 248: return("EL");
     case 247: return("EC");
     case 246: return("AYT");
     case 245: return("AO");
     case 244: return("IP");
     case 243: return("BRK");
     case 242: return("SYNC");
     case 241: return("NOP");
        default:
   sprintf(unknown,"%d",cmd);
            return(unknown);
 }
}

canonical_original_code:
char *telnet_cmd_desc(unsigned char cmd)
{
 static char unknown[32];
 switch(cmd) {
     case 255: return("IAC");
     case 254: return("DON'T");
     case 253: return("DO");
     case 252: return("WON'T");
     case 251: return("WILL");
     case 250: return("SB");
     case 249: return("GA");
     case 248: return("EL");
     case 247: return("EC");
     case 246: return("AYT");
     case 245: return("AO");
     case 244: return("IP");
     case 243: return("BRK");
     case 242: return("SYNC");
     case 241: return("NOP");
        default:
   sprintf(unknown,"%d",cmd);
            return(unknown);
 }
}

variable_types:
cmd
unsigned char

variable_types:
unknown
char [32]


decompiled_code:
const char *__fastcall telnet_opt_desc(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 <= 0x28u )
return (&telnet_option_descriptions)[a1];
result = "Extended Options List";
if ( a1 != 0xFF )
{
sprintf(unknown_0, "%d", a1);
result = unknown_0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 <= 0x28u )
return (&telnet_option_descriptions)[a1];
result = "Extended Options List";
if ( a1 != 0xFF )
{
sprintf(unknown_0, "%d", a1);
result = unknown_0;
}
return result;
}

original_code:
const char* telnet_opt_desc(unsigned char opt)
{
 static char unknown[32];
 if(opt<sizeof(telnet_option_descriptions)/sizeof(char*))
  return(telnet_option_descriptions[opt]);
 if(opt==TELNET_EXOPL)
  return("Extended Options List");
 sprintf(unknown,"%d",opt);
    return(unknown);
}

canonical_original_code:
char *telnet_opt_desc(unsigned char opt)
{
 static char unknown[32];
 if(opt<sizeof(telnet_option_descriptions)/sizeof(char *))
  return(telnet_option_descriptions[opt]);
 if(opt==TELNET_EXOPL)
  return("Extended Options List");
 sprintf(unknown,"%d",opt);
    return(unknown);
}

variable_types:
opt
unsigned char


decompiled_code:
__int64 __fastcall telnet_opt_ack(unsigned __int8 a1)
{
int v1; // eax
__int64 result; // rax

if ( a1 == 0xFD )
return 4294967291LL;
if ( a1 > 0xFDu )
{
LOBYTE(v1) = a1 != 0xFE;
result = (unsigned int)(4 * v1 - 4);
}
else
{
result = 4294967293LL;
if ( a1 != 0xFB )
{
LOBYTE(result) = a1 != 0xFC;
result = (unsigned int)(2 * result - 2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
int v1; // eax
__int64 result; // rax

if ( a1 == 0xFD )
return 4294967291LL;
if ( a1 > 0xFDu )
{
LOBYTE(v1) = a1 != 0xFE;
result = (unsigned int)(4 * v1 - 4);
}
else
{
result = 4294967293LL;
if ( a1 != 0xFB )
{
LOBYTE(result) = a1 != 0xFC;
result = (unsigned int)(2 * result - 2);
}
}
return result;
}

original_code:
unsigned char telnet_opt_ack(unsigned char cmd)
{
 switch(cmd) {
  case 253: return 251;
  case 254: return 252;
  case 251: return 253;
  case 252: return 254;
 }
 return 0;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall telnet_opt_nak(unsigned __int8 a1)
{
int v1; // eax
__int64 result; // rax

if ( a1 == 0xFD )
return 4294967292LL;
if ( a1 > 0xFDu )
{
LOBYTE(v1) = a1 != 0xFE;
result = (unsigned int)(5 * v1 - 5);
}
else
{
result = 4294967294LL;
if ( a1 != 0xFB )
{
LOBYTE(result) = a1 != 0xFC;
result = (unsigned int)(3 * result - 3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
int v1; // eax
__int64 result; // rax

if ( a1 == 0xFD )
return 4294967292LL;
if ( a1 > 0xFDu )
{
LOBYTE(v1) = a1 != 0xFE;
result = (unsigned int)(5 * v1 - 5);
}
else
{
result = 4294967294LL;
if ( a1 != 0xFB )
{
LOBYTE(result) = a1 != 0xFC;
result = (unsigned int)(3 * result - 3);
}
}
return result;
}

original_code:
unsigned char telnet_opt_nak(unsigned char cmd)
{
 switch(cmd) {
  case 253: return 252;
  case 254: return 251;
  case 251: return 254;
  case 252: return 253;
 }
 return 0;
}


getSocketOptionByName

decompiled_code:
__int64 __fastcall getSocketOptionByName(char *nptr, _DWORD *a2)
{
const char *v3; // rsi
char **v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( a2 )
*a2 = 1;
v3 = socket_options;
if ( socket_options )
{
v4 = &off_718;
v5 = 0;
while ( strcasecmp(nptr, v3) )
{
++v5;
v4 += 3;
v3 = *(v4 - 3);
if ( !v3 )
goto LABEL_7;
}
if ( a2 )
*a2 = dword_70C[6 * v5];
result = (unsigned int)dword_710[6 * v5];
}
else
{
LABEL_7:
if ( (unsigned int)(*nptr - 48) > 9 )
result = 0xFFFFFFFFLL;
else
result = strtol(nptr, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr, _DWORD *a2)
{
const char *v3; // rsi
char **v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( a2 )
*a2 = 1;
v3 = socket_options;
if ( socket_options )
{
v4 = &off_718;
v5 = 0;
while ( strcasecmp(nptr, v3) )
{
++v5;
v4 += 3;
v3 = *(v4 - 3);
if ( !v3 )
goto LABEL_7;
}
if ( a2 )
*a2 = dword_70C[6 * v5];
result = (unsigned int)dword_710[6 * v5];
}
else
{
LABEL_7:
if ( (unsigned int)(*nptr - 48) > 9 )
result = 0xFFFFFFFFLL;
else
result = strtol(nptr, 0LL, 0);
}
return result;
}

original_code:
int getSocketOptionByName(const char* name, int* level)
{
 int i;
 if(level!=((void *)0))
  *level=1;
 for(i=0;socket_options[i].name;i++) {
  if(strcasecmp(name,socket_options[i].name)==0) {
   if(level!=((void *)0))
    *level = socket_options[i].level;
   return(socket_options[i].value);
  }
 }
 if(!isdigit(*name))
  return(-1);
 return(strtol(name,((void *)0),0));
}

canonical_original_code:
int getSocketOptionByName(char *name, int *level)
{
 int i;
 if(level!=((void *)0))
  *level=1;
 for(i=0;socket_options[i].name;i++) {
  if(strcasecmp(name,socket_options[i].name)==0) {
   if(level!=((void *)0))
    *level = socket_options[i].level;
   return(socket_options[i].value);
  }
 }
 if(!isdigit(*name))
  return(-1);
 return(strtol(name,((void *)0),0));
}

variable_types:
name
char *

variable_types:
level
int *

variable_types: i int


getSocketOptionList

decompiled_code:
char **getSocketOptionList()
{
return &socket_options;
}

canonical_decompiled_code:
char **func2()
{
return &socket_options;
}

original_code:
socket_option_t* getSocketOptionList(void)
{
 return(socket_options);
}

canonical_original_code:
struct socket_option_t *getSocketOptionList()
{
 return(socket_options);
}

return_type: struct socket_option_t { char *name; int type; int level; int value; } *


sendfilesocket

decompiled_code:
__int64 __fastcall sendfilesocket(int a1, unsigned int a2, __off_t *a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v7; // rbp
int v8; // eax
int v9; // ebx
int v10; // er15
int v11; // ebp
int v12; // eax
__int64 v14; // rbx
unsigned int v15; // [rsp+4h] [rbp-4054h]
signed int v16; // [rsp+Ch] [rbp-404Ch]
struct timeval timeout; // [rsp+10h] [rbp-4048h] BYREF
char buf[16440]; // [rsp+20h] [rbp-4038h] BYREF

v6 = filelength(a2);
if ( a3 && lseek(a2, *a3, 0) < 0 )
return (unsigned int)-1;
if ( a4 > 0 && v6 >= a4 )
goto LABEL_5;
v14 = v6 - lseek(a2, 0LL, 1);
a4 = v14;
if ( v14 < 0 )
{
*_errno_location() = 22;
return (unsigned int)-1;
}
if ( v14 > 0 )
{
LABEL_5:
v16 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(a2, buf, 0x4000uLL);
v9 = v8;
v10 = v8;
if ( v8 == -1 )
return (unsigned int)-1;
if ( !v8 )
{
v15 = v16;
goto LABEL_24;
}
if ( v8 <= 0 )
return (unsigned int)-1;
v11 = 0;
do
{
v12 = write(a1, &buf[v11], v10 - v11);
v15 = v12;
if ( v12 <= 0 )
{
if ( v12 != -1 || *_errno_location() != 11 )
return v15;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &timeout);
v15 = 0;
}
v11 += v15;
}
while ( v10 > v11 );
if ( v9 != v11 )
break;
v16 += v11;
v7 = v16;
if ( v16 >= a4 )
{
v15 = v16;
goto LABEL_24;
}
}
v15 = -1;
}
else
{
v15 = 0;
v7 = 0LL;
LABEL_24:
if ( a3 )
*a3 += v7;
}
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2, __off_t *a3, __int64 a4)
{
__int64 v6; // rbx
__int64 v7; // rbp
int v8; // eax
int v9; // ebx
int v10; // er15
int v11; // ebp
int v12; // eax
__int64 v14; // rbx
unsigned int v15; // [rsp+4h] [rbp-4054h]
signed int v16; // [rsp+Ch] [rbp-404Ch]
struct timeval timeout; // [rsp+10h] [rbp-4048h] BYREF
char buf[16440]; // [rsp+20h] [rbp-4038h] BYREF

v6 = filelength(a2);
if ( a3 && lseek(a2, *a3, 0) < 0 )
return (unsigned int)-1;
if ( a4 > 0 && v6 >= a4 )
goto LABEL_5;
v14 = v6 - lseek(a2, 0LL, 1);
a4 = v14;
if ( v14 < 0 )
{
*_errno_location() = 22;
return (unsigned int)-1;
}
if ( v14 > 0 )
{
LABEL_5:
v16 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(a2, buf, 0x4000uLL);
v9 = v8;
v10 = v8;
if ( v8 == -1 )
return (unsigned int)-1;
if ( !v8 )
{
v15 = v16;
goto LABEL_24;
}
if ( v8 <= 0 )
return (unsigned int)-1;
v11 = 0;
do
{
v12 = write(a1, &buf[v11], v10 - v11);
v15 = v12;
if ( v12 <= 0 )
{
if ( v12 != -1 || *_errno_location() != 11 )
return v15;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &timeout);
v15 = 0;
}
v11 += v15;
}
while ( v10 > v11 );
if ( v9 != v11 )
break;
v16 += v11;
v7 = v16;
if ( v16 >= a4 )
{
v15 = v16;
goto LABEL_24;
}
}
v15 = -1;
}
else
{
v15 = 0;
v7 = 0LL;
LABEL_24:
if ( a3 )
*a3 += v7;
}
return v15;
}

original_code:
int sendfilesocket(int sock, int file, long *offset, long count)
{
 char buf[1024*16];
 long len;
 int rd;
 int wr=0;
 int total=0;
 int i;
 len=filelength(file);
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 if(count<1 || count>len) {
  count=len;
  count-=lseek(file,0,1);
 }
 if(count<0) {
  (*__errno_location ())=22;
  return(-1);
 }
 while(total<count) {
  rd=read(file,buf,sizeof(buf));
  if(rd==-1)
   return(-1);
  if(rd==0)
   break;
  for(i=wr=0;i<rd;i+=wr) {
   wr=write(sock,buf+i,rd-i);
   if(wr>0)
    continue;
   if(wr==-1 && (*__errno_location ())==11) {
    wr=0;
    ({ 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); });
    continue;
   }
   return(wr);
  }
  if(i!=rd)
   return(-1);
  total+=rd;
 }
 if(offset!=((void *)0))
  (*offset)+=total;
 return(total);
}

canonical_original_code:
int sendfilesocket(int sock, int file, long *offset, long count)
{
 char buf[-1];
 long len;
 int rd;
 int wr = 0;
 int total = 0;
 int i;
 len=filelength(file);
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 if(count<1 || count>len) {
  count=len;
  count-=lseek(file,0,1);
 }
 if(count<0) {
  (*__errno_location ())=22;
  return(-1);
 }
 while(total<count) {
  rd=read(file,buf,sizeof(buf));
  if(rd==-1)
   return(-1);
  if(rd==0)
   break;
  for(i=wr=0;i<rd;i+=wr) {
   wr=write(sock,buf+i,rd-i);
   if(wr>0)
    continue;
   if(wr==-1 && (*__errno_location ())==11) {
    wr=0;
    ({ 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); });
    continue;
   }
   return(wr);
  }
  if(i!=rd)
   return(-1);
  total+=rd;
 }
 if(offset!=((void *)0))
  (*offset)+=total;
 return(total);
}

variable_types: sock int

variable_types: file int

variable_types:
offset
long *

variable_types: count long

variable_types:
buf
char [-1]

variable_types: len long

variable_types: rd int

variable_types: wr int

variable_types: total int

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


recvfilesocket

decompiled_code:
__int64 __fastcall recvfilesocket(int fd, int a2, __off_t *a3, signed __int64 a4)
{
void *v6; // rsp
int v7; // eax
int v8; // edx
size_t v10; // rdx
_BYTE v11[15]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 <= 0 )
{
*_errno_location() = 34;
v8 = -1;
}
else
{
v6 = alloca(a4 + 8);
if ( a3 )
{
if ( lseek(a2, *a3, 0) < 0 )
{
v8 = -1;
}
else
{
v7 = read(fd, v11, a4);
if ( a4 == v7 )
{
v8 = write(a2, v11, v7);
*a3 += v8;
}
else
{
v8 = -1;
}
}
}
else
{
v10 = (int)read(fd, v11, a4);
if ( v10 == a4 )
v8 = write(a2, v11, v10);
else
v8 = -1;
}
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2, __off_t *a3, signed __int64 a4)
{
void *v6; // rsp
int v7; // eax
int v8; // edx
size_t v10; // rdx
_BYTE v11[15]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 <= 0 )
{
*_errno_location() = 34;
v8 = -1;
}
else
{
v6 = alloca(a4 + 8);
if ( a3 )
{
if ( lseek(a2, *a3, 0) < 0 )
{
v8 = -1;
}
else
{
v7 = read(fd, v11, a4);
if ( a4 == v7 )
{
v8 = write(a2, v11, v7);
*a3 += v8;
}
else
{
v8 = -1;
}
}
}
else
{
v10 = (int)read(fd, v11, a4);
if ( v10 == a4 )
v8 = write(a2, v11, v10);
else
v8 = -1;
}
}
return (unsigned int)v8;
}

original_code:
int recvfilesocket(int sock, int file, long *offset, long count)
{
 char* buf;
 int rd;
 int wr;
 if(count<1) {
  (*__errno_location ())=34;
  return(-1);
 }
 if((buf=(char*)__builtin_alloca (count))==((void *)0)) {
  (*__errno_location ())=12;
  return(-1);
 }
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 rd=read(sock,buf,count);
 if(rd!=count)
  return(-1);
 wr=write(file,buf,rd);
 if(offset!=((void *)0))
  (*offset)+=wr;
 return(wr);
}

canonical_original_code:
int recvfilesocket(int sock, int file, long *offset, long count)
{
 char *buf;
 int rd;
 int wr;
 if(count<1) {
  (*__errno_location ())=34;
  return(-1);
 }
 if((buf=(char *)__builtin_alloca (count))==((void *)0)) {
  (*__errno_location ())=12;
  return(-1);
 }
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 rd=read(sock,buf,count);
 if(rd!=count)
  return(-1);
 wr=write(file,buf,rd);
 if(offset!=((void *)0))
  (*offset)+=wr;
 return(wr);
}

variable_types:
buf
char *


decompiled_code:
int __fastcall socket_check(int fd, _DWORD *a2, _DWORD *a3, unsigned __int64 a4)
{
int result; // eax
int v7; // er12
__int64 v8; // r14
fd_set *v9; // r15
fd_set *v10; // rdi
_BOOL8 v11; // rbp
int v12; // edx
int *v13; // rdx
struct timeval v14; // [rsp+0h] [rbp-158h] BYREF
fd_set writefds; // [rsp+10h] [rbp-148h] BYREF
fd_set readfds; // [rsp+90h] [rbp-C8h] BYREF
char buf[57]; // [rsp+11Fh] [rbp-39h] BYREF

if ( a2 )
*a2 = 0;
if ( a3 )
*a3 = 0;
result = 0;
if ( fd == -1 )
return result;
memset(&readfds, 0, sizeof(readfds));
v7 = fd / 64;
v8 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v8;
if ( a3 )
{
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v7] |= v8;
v9 = &writefds;
v10 = &readfds;
if ( !a2 )
v10 = 0LL;
}
else
{
v9 = 0LL;
v10 = &readfds;
}
v14.tv_sec = a4 / 0x3E8;
v14.tv_usec = 1000 * (a4 % 0x3E8);
result = select(fd + 1, v10, v9, 0LL, &v14);
if ( result == -1 )
return 0;
if ( !result )
return 1;
if ( a3 )
{
if ( (v9->fds_bits[v7] & v8) != 0 )
{
*a3 = 1;
if ( result == 1 )
return result;
}
if ( !a2 )
return 0;
v12 = recv(fd, buf, 1uLL, 2);
LOBYTE(v11) = 1;
if ( v12 == 1 )
{
LABEL_24:
*a2 = 1;
return 1;
}
goto LABEL_21;
}
v11 = a2 != 0LL;
v12 = recv(fd, buf, 1uLL, 2);
if ( v12 != 1 )
{
LABEL_21:
result = 0;
if ( v12 != -1 )
return result;
v13 = _errno_location();
result = 0;
if ( *v13 != 90 )
return result;
}
result = 1;
if ( v11 )
goto LABEL_24;
return result;
}

canonical_decompiled_code:
int __fastcall func5(int fd, _DWORD *a2, _DWORD *a3, unsigned __int64 a4)
{
int result; // eax
int v7; // er12
__int64 v8; // r14
fd_set *v9; // r15
fd_set *v10; // rdi
_BOOL8 v11; // rbp
int v12; // edx
int *v13; // rdx
struct timeval v14; // [rsp+0h] [rbp-158h] BYREF
fd_set writefds; // [rsp+10h] [rbp-148h] BYREF
fd_set readfds; // [rsp+90h] [rbp-C8h] BYREF
char buf[57]; // [rsp+11Fh] [rbp-39h] BYREF

if ( a2 )
*a2 = 0;
if ( a3 )
*a3 = 0;
result = 0;
if ( fd == -1 )
return result;
memset(&readfds, 0, sizeof(readfds));
v7 = fd / 64;
v8 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v8;
if ( a3 )
{
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v7] |= v8;
v9 = &writefds;
v10 = &readfds;
if ( !a2 )
v10 = 0LL;
}
else
{
v9 = 0LL;
v10 = &readfds;
}
v14.tv_sec = a4 / 0x3E8;
v14.tv_usec = 1000 * (a4 % 0x3E8);
result = select(fd + 1, v10, v9, 0LL, &v14);
if ( result == -1 )
return 0;
if ( !result )
return 1;
if ( a3 )
{
if ( (v9->fds_bits[v7] & v8) != 0 )
{
*a3 = 1;
if ( result == 1 )
return result;
}
if ( !a2 )
return 0;
v12 = recv(fd, buf, 1uLL, 2);
LOBYTE(v11) = 1;
if ( v12 == 1 )
{
LABEL_24:
*a2 = 1;
return 1;
}
goto LABEL_21;
}
v11 = a2 != 0LL;
v12 = recv(fd, buf, 1uLL, 2);
if ( v12 != 1 )
{
LABEL_21:
result = 0;
if ( v12 != -1 )
return result;
v13 = _errno_location();
result = 0;
if ( *v13 != 90 )
return result;
}
result = 1;
if ( v11 )
goto LABEL_24;
return result;
}

original_code:
int socket_check(int sock, int* rd_p, int* wr_p, ulong timeout)
{
 char ch;
 int i,rd;
 fd_set rd_set;
 fd_set* rd_set_p=&rd_set;
 fd_set wr_set;
 fd_set* wr_set_p=((void *)0);
 struct timeval tv;
 if(rd_p!=((void *)0))
  *rd_p=0;
 if(wr_p!=((void *)0))
  *wr_p=0;
 if(sock==(int)(~0))
  return(0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 if(wr_p!=((void *)0)) {
  wr_set_p=&wr_set;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wr_set_p)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  if(rd_p==((void *)0))
   rd_set_p=((void *)0);
 }
 tv.tv_sec=timeout/1000;
 tv.tv_usec=(timeout%1000)*1000;
 i=select(sock+1,rd_set_p,wr_set_p,((void *)0),&tv);
 if(i==-1)
  return(0);
 if(i==0)
  return(1);
 if(wr_p!=((void *)0) && ((((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  *wr_p=1;
  if(i==1)
   return(1);
 }
 if(rd_p !=((void *)0) || wr_p==((void *)0)) {
  rd=recv(sock,&ch,1,MSG_PEEK);
  if(rd==1
   || (rd==-1 && (*__errno_location ())==90)) {
   if(rd_p!=((void *)0))
    *rd_p=1;
   return(1);
  }
 }
 return(0);
}

canonical_original_code:
int socket_check(int sock, int *rd_p, int *wr_p, unsigned long timeout)
{
 char ch;
 int i; int rd;
 struct fd_set rd_set;
 struct fd_set *rd_set_p = &rd_set;
 struct fd_set wr_set;
 struct fd_set *wr_set_p = ((void *)0);
 struct timeval tv;
 if(rd_p!=((void *)0))
  *rd_p=0;
 if(wr_p!=((void *)0))
  *wr_p=0;
 if(sock==(int)(~0))
  return(0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 if(wr_p!=((void *)0)) {
  wr_set_p=&wr_set;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wr_set_p)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  if(rd_p==((void *)0))
   rd_set_p=((void *)0);
 }
 tv.tv_sec=timeout/1000;
 tv.tv_usec=(timeout%1000)*1000;
 i=select(sock+1,rd_set_p,wr_set_p,((void *)0),&tv);
 if(i==-1)
  return(0);
 if(i==0)
  return(1);
 if(wr_p!=((void *)0) && ((((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  *wr_p=1;
  if(i==1)
   return(1);
 }
 if(rd_p !=((void *)0) || wr_p==((void *)0)) {
  rd=recv(sock,&ch,1,MSG_PEEK);
  if(rd==1
   || (rd==-1 && (*__errno_location ())==90)) {
   if(rd_p!=((void *)0))
    *rd_p=1;
   return(1);
  }
 }
 return(0);
}

variable_types:
timeout
unsigned long

variable_types: ch char

variable_types: struct fd_set { long __fds_bits[-1]; } *

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


decompiled_code:
__int64 __fastcall retry_bind(int fd, struct sockaddr *addr, socklen_t a3, unsigned int a4, unsigned int a5, const char *a6, __int64 a7)
{
unsigned int i; // ebx
unsigned __int16 v9; // ax
unsigned int v10; // ebp
__int64 v11; // rcx
struct timeval timeout; // [rsp+20h] [rbp-C8h] BYREF
char v17[184]; // [rsp+30h] [rbp-B8h] BYREF

if ( addr->sa_family == 2 )
{
v9 = _bswap_16(*(_WORD *)addr->sa_data);
safe_snprintf(v17, 128LL, " to port %u", v9);
v17[127] = 0;
}
else
{
v17[0] = 0;
}
for ( i = 0; a4 >= i; ++i )
{
v10 = bind(fd, addr, a3);
if ( !v10 )
break;
if ( a7 )
{
v11 = (unsigned int)*_errno_location();
if ( a4 <= i )
{
((void (*)(__int64, const char *, ...))a7)(
3LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v11,
a6,
v17);
continue;
}
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v11,
a6,
v17);
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d Will retry in %u seconds (%u of %u)",
(unsigned int)fd,
a5,
i + 1,
a4);
LABEL_6:
timeout.tv_sec = (int)(1000 * a5) / 1000;
timeout.tv_usec = 1000 * ((int)(1000 * a5) % 1000);
select(0, 0LL, 0LL, 0LL, &timeout);
continue;
}
if ( a4 > i )
goto LABEL_6;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, struct sockaddr *addr, socklen_t a3, unsigned int a4, unsigned int a5, const char *a6, __int64 a7)
{
unsigned int i; // ebx
unsigned __int16 v9; // ax
unsigned int v10; // ebp
__int64 v11; // rcx
struct timeval timeout; // [rsp+20h] [rbp-C8h] BYREF
char v17[184]; // [rsp+30h] [rbp-B8h] BYREF

if ( addr->sa_family == 2 )
{
v9 = func0(*(_WORD *)addr->sa_data);
safe_snprintf(v17, 128LL, " to port %u", v9);
v17[127] = 0;
}
else
{
v17[0] = 0;
}
for ( i = 0; a4 >= i; ++i )
{
v10 = bind(fd, addr, a3);
if ( !v10 )
break;
if ( a7 )
{
v11 = (unsigned int)*_errno_location();
if ( a4 <= i )
{
((void (*)(__int64, const char *, ...))a7)(
3LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v11,
a6,
v17);
continue;
}
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v11,
a6,
v17);
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d Will retry in %u seconds (%u of %u)",
(unsigned int)fd,
a5,
i + 1,
a4);
LABEL_6:
timeout.tv_sec = (int)(1000 * a5) / 1000;
timeout.tv_usec = 1000 * ((int)(1000 * a5) % 1000);
select(0, 0LL, 0LL, 0LL, &timeout);
continue;
}
if ( a4 > i )
goto LABEL_6;
}
return v10;
}

original_code:
int retry_bind(int s, const struct sockaddr *addr, socklen_t addrlen
      ,uint retries, uint wait_secs
      ,const char* prot
      ,int (*lprintf)(int level, char *fmt, ...))
{
 char port_str[128];
 int result=-1;
 uint i;
 if(addr->sa_family==2)
  safe_snprintf(port_str,sizeof(port_str)," to port %u",ntohs(((struct sockaddr_in *)(addr))->sin_port)), port_str[sizeof(port_str)-1]=0;
 else
  port_str[0]=0;
 for(i=0;i<=retries;i++) {
  if((result=bind(s,addr,addrlen))==0)
   break;
  if(lprintf!=((void *)0))
   lprintf(i<retries ? 4:3
    ,"%04d !ERROR %d binding %s socket%s", s, (*__errno_location ()), prot, port_str);
  if(i<retries) {
   if(lprintf!=((void *)0))
    lprintf(4,"%04d Will retry in %u seconds (%u of %u)"
     ,s, wait_secs, i+1, retries);
   ({ int sleep_msecs=wait_secs*1000; 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); });
  }
 }
 return(result);
}

canonical_original_code:
int retry_bind(int s, struct sockaddr *addr, unsigned int addrlen, unsigned int retries, unsigned int wait_secs, char *prot, int (*lprintf)(int level, char *fmt, ...))
{
 char port_str[128];
 int result = -1;
 unsigned int i;
 if(addr->sa_family==2)
  safe_snprintf(port_str,sizeof(port_str)," to port %u",ntohs(((struct sockaddr_in *)(addr))->sin_port)), port_str[sizeof(port_str)-1]=0;
 else
  port_str[0]=0;
 for(i=0;i<=retries;i++) {
  if((result=bind(s,addr,addrlen))==0)
   break;
  if(lprintf!=((void *)0))
   lprintf(i<retries ? 4:3
    ,"%04d !ERROR %d binding %s socket%s", s, (*__errno_location ()), prot, port_str);
  if(i<retries) {
   if(lprintf!=((void *)0))
    lprintf(4,"%04d Will retry in %u seconds (%u of %u)"
     ,s, wait_secs, i+1, retries);
   ({ int sleep_msecs = wait_secs*1000; 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); });
  }
 }
 return(result);
}

variable_types: s int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
addrlen
unsigned int

variable_types:
retries
unsigned int

variable_types:
prot
char *

variable_types:
lprintf
int (*)(int level, char *fmt, ...)

variable_types: result int

variable_types:
i
unsigned int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
time_t __fastcall sane_mktime(struct tm *a1)
{
int v1; // eax
int v2; // eax

v1 = a1->tm_year;
if ( v1 > 1899 )
a1->tm_year = v1 - 1900;
v2 = a1->tm_mon;
if ( v2 )
a1->tm_mon = v2 - 1;
a1->tm_isdst = -1;
return mktime(a1);
}

canonical_decompiled_code:
time_t __fastcall func0(struct tm *a1)
{
int v1; // eax
int v2; // eax

v1 = a1->tm_year;
if ( v1 > 1899 )
a1->tm_year = v1 - 1900;
v2 = a1->tm_mon;
if ( v2 )
a1->tm_mon = v2 - 1;
a1->tm_isdst = -1;
return mktime(a1);
}

original_code:
time_t sane_mktime(struct tm* tm)
{
 if(tm->tm_year>=1900)
  tm->tm_year-=1900;
 if(tm->tm_mon)
  tm->tm_mon--;
 tm->tm_isdst=-1;
 return mktime(tm);
}

canonical_original_code:
long sane_mktime(struct tm *tm)
{
 if(tm->tm_year>=1900)
  tm->tm_year-=1900;
 if(tm->tm_mon)
  tm->tm_mon--;
 tm->tm_isdst=-1;
 return mktime(tm);
}

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

return_type: long


decompiled_code:
__int64 __fastcall xpDateTime_create(__int64 a1, int a2, int a3, int a4, int a5, int a6, float a7, int a8)
{
__int64 result; // rax

result = a1;
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
*(_DWORD *)(a1 + 8) = a4;
*(_DWORD *)(a1 + 12) = a5;
*(_DWORD *)(a1 + 16) = a6;
*(float *)(a1 + 20) = a7;
*(_DWORD *)(a1 + 24) = a8;
return result;
}

original_code:
xpDateTime_t xpDateTime_create(unsigned year, unsigned month, unsigned day
         ,unsigned hour, unsigned minute, float second
         ,xpTimeZone_t zone)
{
 xpDateTime_t xpDateTime;
 xpDateTime.date.year = year;
 xpDateTime.date.month = month;
 xpDateTime.date.day = day;
 xpDateTime.time.hour = hour;
 xpDateTime.time.minute = minute;
 xpDateTime.time.second = second;
 xpDateTime.zone = zone;
 return xpDateTime;
}

canonical_original_code:
struct xpDateTime_t xpDateTime_create(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, float second, int zone)
{
 struct xpDateTime_t xpDateTime;
 xpDateTime.date.year = year;
 xpDateTime.date.month = month;
 xpDateTime.date.day = day;
 xpDateTime.time.hour = hour;
 xpDateTime.time.minute = minute;
 xpDateTime.time.second = second;
 xpDateTime.zone = zone;
 return xpDateTime;
}

variable_types:
year
unsigned int

variable_types:
month
unsigned int

variable_types:
day
unsigned int

variable_types:
hour
unsigned int

variable_types:
minute
unsigned int

variable_types: second float

variable_types: zone int

variable_types: struct xpDateTime_t { struct xpDate_t { unsigned int year; unsigned int month; unsigned int day; } date; struct xpTime_t { unsigned int hour; unsigned int minute; float second; } time; int zone; }

user_defined_types: struct xpDateTime_t { struct xpDate_t date; struct xpTime_t time; int zone; }


decompiled_code:
__int64 xpTimeZone_local()
{
return timezone / -60;
}

canonical_decompiled_code:
__int64 func2()
{
return timezone / -60;
}

original_code:
xpTimeZone_t xpTimeZone_local(void)
{
 return -timezone/60;
}

canonical_original_code:
int xpTimeZone_local()
{
 return -timezone/60;
}


decompiled_code:
__int64 __fastcall xpDateTime_now(__int64 a1)
{
int v1; // eax
float v2; // xmm0_4
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
struct tm tp; // [rsp+20h] [rbp-48h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
localtime_r(&timer, &tp);
v1 = xpTimeZone_local();
v2 = (double)SLODWORD(tv.tv_usec) * 0.00001 + (float)tp.tm_sec;
xpDateTime_create(a1, tp.tm_year + 1900, tp.tm_mon + 1, tp.tm_mday, tp.tm_hour, tp.tm_min, v2, v1);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
float v2; // xmm0_4
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
struct tm tp; // [rsp+20h] [rbp-48h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
localtime_r(&timer, &tp);
v1 = func2();
v2 = (double)SLODWORD(tv.tv_usec) * 0.00001 + (float)tp.tm_sec;
func1(a1, tp.tm_year + 1900, tp.tm_mon + 1, tp.tm_mday, tp.tm_hour, tp.tm_min, v2, v1);
return a1;
}

original_code:
xpDateTime_t xpDateTime_now(void)
{
 struct tm tm;
 struct timeval tv;
 time_t t;
 gettimeofday(&tv, ((void *)0));
 t=tv.tv_sec;
 localtime_r(&t,&tm);
 return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday
  ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec+(tv.tv_usec*0.00001)
  ,xpTimeZone_local());
}

canonical_original_code:
struct xpDateTime_t xpDateTime_now()
{
 struct tm tm;
 struct timeval tv;
 long t;
 gettimeofday(&tv, ((void *)0));
 t=tv.tv_sec;
 localtime_r(&t,&tm);
 return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday
  ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec+(tv.tv_usec*0.00001)
  ,xpTimeZone_local());
}

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

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

variable_types: t long

return_type: struct xpDateTime_t { struct xpDate_t { unsigned int year; unsigned int month; unsigned int day; } date; struct xpTime_t { unsigned int hour; unsigned int minute; float second; } time; int zone; }


decompiled_code:
time_t __fastcall xpDateTime_to_time(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
time_t result; // rax
struct tm v10; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v10.tm_mon = 0LL;
*(_QWORD *)&v10.tm_wday = 0LL;
*(_QWORD *)&v10.tm_isdst = 0LL;
v10.tm_gmtoff = 0LL;
v10.tm_zone = 0LL;
result = 0LL;
if ( (_DWORD)a7 )
{
v10.tm_mon = HIDWORD(a7);
v10.tm_year = a7;
v10.tm_hour = HIDWORD(a8);
v10.tm_mday = a8;
v10.tm_min = a9;
v10.tm_sec = (int)*((float *)&a9 + 1);
result = sane_mktime(&v10);
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
time_t result; // rax
struct tm v10; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v10.tm_mon = 0LL;
*(_QWORD *)&v10.tm_wday = 0LL;
*(_QWORD *)&v10.tm_isdst = 0LL;
v10.tm_gmtoff = 0LL;
v10.tm_zone = 0LL;
result = 0LL;
if ( (_DWORD)a7 )
{
v10.tm_mon = HIDWORD(a7);
v10.tm_year = a7;
v10.tm_hour = HIDWORD(a8);
v10.tm_mday = a8;
v10.tm_min = a9;
v10.tm_sec = (int)*((float *)&a9 + 1);
result = func0(&v10);
}
return result;
}

original_code:
time_t xpDateTime_to_time(xpDateTime_t xpDateTime)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(xpDateTime.date.year==0)
  return(0);
 tm.tm_year = xpDateTime.date.year;
 tm.tm_mon = xpDateTime.date.month;
 tm.tm_mday = xpDateTime.date.day;
 tm.tm_hour = xpDateTime.time.hour;
 tm.tm_min = xpDateTime.time.minute;
 tm.tm_sec = (int)xpDateTime.time.second;
 return sane_mktime(&tm);
}

canonical_original_code:
long xpDateTime_to_time(struct xpDateTime_t xpDateTime)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(xpDateTime.date.year==0)
  return(0);
 tm.tm_year = xpDateTime.date.year;
 tm.tm_mon = xpDateTime.date.month;
 tm.tm_mday = xpDateTime.date.day;
 tm.tm_hour = xpDateTime.time.hour;
 tm.tm_min = xpDateTime.time.minute;
 tm.tm_sec = (int)xpDateTime.time.second;
 return sane_mktime(&tm);
}

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

user_defined_types: struct xpDate_t { unsigned int year; unsigned int month; unsigned int day; }

user_defined_types: struct xpTime_t { unsigned int hour; unsigned int minute; float second; }


decompiled_code:
__int64 __fastcall xpDateTime_to_isoDateTime(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 result; // rax

if ( a1 )
{
*a1 = 0LL;
result = 0LL;
if ( !(_DWORD)a7 )
return result;
*a1 = (unsigned int)((int)*((float *)&a9 + 1) + 100 * a9 + 10000 * HIDWORD(a8));
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
}
result = 0LL;
if ( (_DWORD)a7 )
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 result; // rax

if ( a1 )
{
*a1 = 0LL;
result = 0LL;
if ( !(_DWORD)a7 )
return result;
*a1 = (unsigned int)((int)*((float *)&a9 + 1) + 100 * a9 + 10000 * HIDWORD(a8));
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
}
result = 0LL;
if ( (_DWORD)a7 )
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
return result;
}

original_code:
isoDate_t xpDateTime_to_isoDateTime(xpDateTime_t xpDateTime, isoTime_t* isoTime)
{
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(xpDateTime.date.year==0)
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((xpDateTime.time.hour)*10000)+((xpDateTime.time.minute)*100)+((unsigned)xpDateTime.time.second));
 return (((xpDateTime.date.year)*10000)+((xpDateTime.date.month)*100)+(xpDateTime.date.day));
}

canonical_original_code:
unsigned long xpDateTime_to_isoDateTime(struct xpDateTime_t xpDateTime, unsigned long *isoTime)
{
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(xpDateTime.date.year==0)
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((xpDateTime.time.hour)*10000)+((xpDateTime.time.minute)*100)+((unsigned int)xpDateTime.time.second));
 return (((xpDateTime.date.year)*10000)+((xpDateTime.date.month)*100)+(xpDateTime.date.day));
}

variable_types:
isoTime
unsigned long *


original_code:
xpDateTime_t isoDateTime_to_xpDateTime(isoDate_t date, isoTime_t ti)
{
 return xpDateTime_create(((date)/10000),(((date)/100)%100),((date)%100)
  ,((ti)/10000),(((ti)/100)%100),(float)((ti)%100),xpTimeZone_local());
}

canonical_original_code:
struct xpDateTime_t isoDateTime_to_xpDateTime(unsigned long date, unsigned long ti)
{
 return xpDateTime_create(((date)/10000),(((date)/100)%100),((date)%100)
  ,((ti)/10000),(((ti)/100)%100),(float)((ti)%100),xpTimeZone_local());
}

variable_types:
date
unsigned long

variable_types:
ti
unsigned long


decompiled_code:
__int64 __fastcall time_to_isoDateTime(time_t a1, _QWORD *a2)
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
if ( a2 )
*a2 = 0LL;
result = 0LL;
if ( timer )
{
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
if ( gmtime_r(&timer, &tp) )
{
if ( a2 )
*a2 = (unsigned int)(tp.tm_sec + 100 * tp.tm_min + 10000 * tp.tm_hour);
result = tp.tm_mday + 100 * (tp.tm_mon + 1) + 10000 * (tp.tm_year + 1900);
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(time_t a1, _QWORD *a2)
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
if ( a2 )
*a2 = 0LL;
result = 0LL;
if ( timer )
{
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
if ( gmtime_r(&timer, &tp) )
{
if ( a2 )
*a2 = (unsigned int)(tp.tm_sec + 100 * tp.tm_min + 10000 * tp.tm_hour);
result = tp.tm_mday + 100 * (tp.tm_mon + 1) + 10000 * (tp.tm_year + 1900);
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
isoDate_t time_to_isoDateTime(time_t ti, isoTime_t* isoTime)
{
 struct tm tm;
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(ti==0)
  return(0);
 memset(&(tm),0,sizeof(tm));
 if(gmtime_r(&ti,&tm)==((void *)0))
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((tm.tm_hour)*10000)+((tm.tm_min)*100)+((unsigned)tm.tm_sec));
 return (((1900+tm.tm_year)*10000)+((1+tm.tm_mon)*100)+(tm.tm_mday));
}

canonical_original_code:
unsigned long time_to_isoDateTime(long ti, unsigned long *isoTime)
{
 struct tm tm;
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(ti==0)
  return(0);
 memset(&(tm),0,sizeof(tm));
 if(gmtime_r(&ti,&tm)==((void *)0))
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((tm.tm_hour)*10000)+((tm.tm_min)*100)+((unsigned int)tm.tm_sec));
 return (((1900+tm.tm_year)*10000)+((1+tm.tm_mon)*100)+(tm.tm_mday));
}

variable_types: ti long


decompiled_code:
__int64 __fastcall time_to_isoTime(time_t a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

time_to_isoDateTime(a1, &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(time_t a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

func7(a1, &v2);
return v2;
}

original_code:
isoTime_t time_to_isoTime(time_t ti)
{
 isoTime_t isoTime;
 time_to_isoDateTime(ti,&isoTime);
 return isoTime;
}

canonical_original_code:
unsigned long time_to_isoTime(long ti)
{
 unsigned long isoTime;
 time_to_isoDateTime(ti,&isoTime);
 return isoTime;
}

variable_types:
isoTime
unsigned long


decompiled_code:
time_t __fastcall isoDateTime_to_time(unsigned __int64 a1, unsigned __int64 a2)
{
time_t result; // rax
struct tm v3; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v3.tm_mon = 0LL;
*(_QWORD *)&v3.tm_wday = 0LL;
*(_QWORD *)&v3.tm_isdst = 0LL;
v3.tm_gmtoff = 0LL;
v3.tm_zone = 0LL;
result = 0LL;
if ( a1 )
{
v3.tm_year = a1 / 0x2710;
v3.tm_mon = a1 / 0x64
- 20
* (((unsigned __int64)((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a1 / 0x190)) >> 64) >> 2)
+ (((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a1 / 0x190)) >> 64) & 0xFFFFFFFC));
v3.tm_mday = a1 % 0x64;
v3.tm_hour = a2 / 0x2710;
v3.tm_min = a2 / 0x64
- 20
* (((unsigned __int64)((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 / 0x190)) >> 64) >> 2)
+ (((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 / 0x190)) >> 64) & 0xFFFFFFFC));
v3.tm_sec = a2 % 0x64;
result = sane_mktime(&v3);
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func9(unsigned __int64 a1, unsigned __int64 a2)
{
time_t result; // rax
struct tm v3; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v3.tm_mon = 0LL;
*(_QWORD *)&v3.tm_wday = 0LL;
*(_QWORD *)&v3.tm_isdst = 0LL;
v3.tm_gmtoff = 0LL;
v3.tm_zone = 0LL;
result = 0LL;
if ( a1 )
{
v3.tm_year = a1 / 0x2710;
v3.tm_mon = a1 / 0x64
- 20
* (((unsigned __int64)((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a1 / 0x190)) >> 64) >> 2)
+ (((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a1 / 0x190)) >> 64) & 0xFFFFFFFC));
v3.tm_mday = a1 % 0x64;
v3.tm_hour = a2 / 0x2710;
v3.tm_min = a2 / 0x64
- 20
* (((unsigned __int64)((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 / 0x190)) >> 64) >> 2)
+ (((0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 / 0x190)) >> 64) & 0xFFFFFFFC));
v3.tm_sec = a2 % 0x64;
result = func0(&v3);
}
return result;
}

original_code:
time_t isoDateTime_to_time(isoDate_t date, isoTime_t ti)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(date==0)
  return(0);
 tm.tm_year = ((date)/10000);
 tm.tm_mon = (((date)/100)%100);
 tm.tm_mday = ((date)%100);
 tm.tm_hour = ((ti)/10000);
 tm.tm_min = (((ti)/100)%100);
 tm.tm_sec = ((ti)%100);
 return sane_mktime(&tm);
}

canonical_original_code:
long isoDateTime_to_time(unsigned long date, unsigned long ti)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(date==0)
  return(0);
 tm.tm_year = ((date)/10000);
 tm.tm_mon = (((date)/100)%100);
 tm.tm_mday = ((date)%100);
 tm.tm_hour = ((ti)/10000);
 tm.tm_min = (((ti)/100)%100);
 tm.tm_sec = ((ti)%100);
 return sane_mktime(&tm);
}


decompiled_code:
__int64 __fastcall isoTimeZone_parse(char *a1, _DWORD *a2)
{
char v2; // al
int v3; // edx
__int64 result; // rax
int v5; // edx
int v6; // [rsp+8h] [rbp-20h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch] BYREF

v7 = 0;
v6 = 0;
v2 = *a1;
if ( *a1 != 45 )
{
if ( v2 > 45 )
{
if ( v2 != 90 )
return 0LL;
*a2 = 0;
return 1LL;
}
if ( !v2 )
{
*a2 = xpTimeZone_local();
return 1LL;
}
if ( v2 != 43 )
return 0LL;
}
v3 = _isoc99_sscanf(a1 + 1, "%2u%*s%2u", &v7, &v6);
result = 0LL;
if ( v3 > 0 )
{
v5 = v6 + 60 * v7;
*a2 = v5;
result = 1LL;
if ( *a1 == 45 )
*a2 = -v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, _DWORD *a2)
{
char v2; // al
int v3; // edx
__int64 result; // rax
int v5; // edx
int v6; // [rsp+8h] [rbp-20h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch] BYREF

v7 = 0;
v6 = 0;
v2 = *a1;
if ( *a1 != 45 )
{
if ( v2 > 45 )
{
if ( v2 != 90 )
return 0LL;
*a2 = 0;
return 1LL;
}
if ( !v2 )
{
*a2 = func2();
return 1LL;
}
if ( v2 != 43 )
return 0LL;
}
v3 = _isoc99_sscanf(a1 + 1, "%2u%*s%2u", &v7, &v6);
result = 0LL;
if ( v3 > 0 )
{
v5 = v6 + 60 * v7;
*a2 = v5;
result = 1LL;
if ( *a1 == 45 )
*a2 = -v5;
}
return result;
}

original_code:
int isoTimeZone_parse(const char* str, xpTimeZone_t* zone)
{
 unsigned hour=0,minute=0;
 switch(*str) {
  case 0:
   *zone = xpTimeZone_local();
   return 1;
  case 'Z':
   *zone = 0;
   return 1;
  case '+':
  case '-':
   if(sscanf(str+1,"%2u%*s%2u",&hour,&minute)>=1) {
    *zone = (hour*60) + minute;
    if(*str=='-')
     *zone = -(*zone);
    return 1;
   }
   break;
 }
 return 0;
}

canonical_original_code:
int isoTimeZone_parse(char *str, int *zone)
{
 unsigned int hour = 0; unsigned int minute = 0;
 switch(*str) {
  case 0:
   *zone = xpTimeZone_local();
   return 1;
  case 'Z':
   *zone = 0;
   return 1;
  case '+':
  case '-':
   if(sscanf(str+1,"%2u%*s%2u",&hour,&minute)>=1) {
    *zone = (hour*60) + minute;
    if(*str=='-')
     *zone = -(*zone);
    return 1;
   }
   break;
 }
 return 0;
}

variable_types:
str
char *

variable_types:
zone
int *


decompiled_code:
__int64 __fastcall xp_getdate(__int64 a1)
{
__int64 result; // rax
struct tm v2; // [rsp+0h] [rbp-48h] BYREF
time_t timer; // [rsp+38h] [rbp-10h] BYREF

timer = time(0LL);
localtime_r(&timer, &v2);
*(_WORD *)a1 = LOWORD(v2.tm_year) + 1900;
*(_BYTE *)(a1 + 2) = v2.tm_mday;
result = (unsigned int)LOBYTE(v2.tm_mon) + 1;
*(_BYTE *)(a1 + 3) = LOBYTE(v2.tm_mon) + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
struct tm v2; // [rsp+0h] [rbp-48h] BYREF
time_t timer; // [rsp+38h] [rbp-10h] BYREF

timer = time(0LL);
localtime_r(&timer, &v2);
*(_WORD *)a1 = LOWORD(v2.tm_year) + 1900;
*(_BYTE *)(a1 + 2) = v2.tm_mday;
result = (unsigned int)LOBYTE(v2.tm_mon) + 1;
*(_BYTE *)(a1 + 3) = LOBYTE(v2.tm_mon) + 1;
return result;
}

original_code:
void xp_getdate(struct date* nyd)
{
 time_t tim;
 struct tm dte;
 tim=time(((void *)0));
 localtime_r(&tim,&dte);
 nyd->da_year=dte.tm_year+1900;
 nyd->da_day=dte.tm_mday;
 nyd->da_mon=dte.tm_mon+1;
}

canonical_original_code:
void xp_getdate(struct date *nyd)
{
 long tim;
 struct tm dte;
 tim=time(((void *)0));
 localtime_r(&tim,&dte);
 nyd->da_year=dte.tm_year+1900;
 nyd->da_day=dte.tm_mday;
 nyd->da_mon=dte.tm_mon+1;
}

variable_types: struct date { short da_year; char da_day; char da_mon; } *

variable_types: tim long


getflagoff

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

result = 744LL;
if ( a1 != 3 )
{
result = 752LL;
if ( a1 != 4 )
{
result = 499LL;
if ( a1 == 2 )
result = 509LL;
}
}
return result;
}

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

result = 744LL;
if ( a1 != 3 )
{
result = 752LL;
if ( a1 != 4 )
{
result = 499LL;
if ( a1 == 2 )
result = 509LL;
}
}
return result;
}

variable_types: set int


kbhit

decompiled_code:
int kbhit()
{
int result; // eax
struct timeval v1; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v1.tv_sec = 0LL;
v1.tv_usec = 0LL;
if ( istty || (result = isatty(0), (istty = result) != 0) )
{
if ( !beensetup )
termios_setup();
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
result = select(1, &readfds, 0LL, 0LL, &v1) > 0;
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
struct timeval v1; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v1.tv_sec = 0LL;
v1.tv_usec = 0LL;
if ( istty || (result = isatty(0), (istty = result) != 0) )
{
if ( !beensetup )
func3();
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
result = select(1, &readfds, 0LL, 0LL, &v1) > 0;
}
return result;
}

original_code:
int kbhit(void)
{
 fd_set inp;
 struct timeval timeout = {0, 0};
 if(!istty) {
  istty = isatty(0);
  if(!istty)
   return 0;
 }
    if(!beensetup)
     _termios_setup();
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&inp)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&inp)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if(select(0 +1, &inp, ((void *)0), ((void *)0), &timeout)<1)
  return 0;
 return 1;
}

canonical_original_code:
int kbhit()
{
 struct fd_set inp;
 struct timeval timeout = {0, 0};
 if(!istty) {
  istty = isatty(0);
  if(!istty)
   return 0;
 }
    if(!beensetup)
     _termios_setup();
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&inp)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&inp)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if(select(0 +1, &inp, ((void *)0), ((void *)0), &timeout)<1)
  return 0;
 return 1;
}

variable_types:
inp
struct fd_set { long __fds_bits[-1]; }


getch

decompiled_code:
__int64 getch()
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( !beensetup )
termios_setup();
read(0, buf, 1uLL);
return (unsigned int)buf[0];
}

canonical_decompiled_code:
__int64 func5()
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( !beensetup )
func3();
read(0, buf, 1uLL);
return (unsigned int)buf[0];
}

original_code:
int getch(void)
{
 char c;
    if(!beensetup)
     _termios_setup();
    read(0, &c, 1);
    return c;
}

canonical_original_code:
int getch()
{
 char c;
    if(!beensetup)
     _termios_setup();
    read(0, &c, 1);
    return c;
}

variable_types: c char