getgamedat

decompiled_code:
ssize_t __fastcall getgamedat(char a1)
{
int v1; // ebx
ssize_t result; // rax
char v3; // si
char v4; // cl
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v1 = 0;
while ( 1 )
{
filelength((unsigned int)gamedab);
if ( (unsigned int)lock(gamedab) != -1 )
break;
if ( ++v1 == 101 )
goto LABEL_8;
v5.tv_sec = 0LL;
v5.tv_usec = 30000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
if ( v1 <= 99 )
goto LABEL_6;
LABEL_8:
puts("\agetgamedat: error locking game.dab\r");
LABEL_6:
lseek(gamedab, 0LL, 0);
read(gamedab, &misc, 1uLL);
read(gamedab, &curplayer, 1uLL);
read(gamedab, &total_nodes, 1uLL);
read(gamedab, node, 2 * (unsigned __int8)total_nodes);
result = read(gamedab, &status, (unsigned __int8)total_nodes);
total_players = 0;
if ( total_nodes )
{
result = 0LL;
v3 = 0;
v4 = 0;
do
{
if ( node[result] )
{
++v4;
v3 = 1;
}
++result;
}
while ( (unsigned __int8)total_nodes > (int)result );
if ( v3 )
total_players = v4;
}
if ( !a1 )
{
filelength((unsigned int)gamedab);
result = unlock(gamedab);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func7(char a1)
{
int v1; // ebx
ssize_t result; // rax
char v3; // si
char v4; // cl
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v1 = 0;
while ( 1 )
{
func11((unsigned int)gamedab);
if ( (unsigned int)func12(gamedab) != -1 )
break;
if ( ++v1 == 101 )
goto LABEL_8;
v5.tv_sec = 0LL;
v5.tv_usec = 30000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
if ( v1 <= 99 )
goto LABEL_6;
LABEL_8:
puts("\agetgamedat: error locking game.dab\r");
LABEL_6:
lseek(gamedab, 0LL, 0);
read(gamedab, &misc, 1uLL);
read(gamedab, &curplayer, 1uLL);
read(gamedab, &total_nodes, 1uLL);
read(gamedab, node, 2 * (unsigned __int8)total_nodes);
result = read(gamedab, &status, (unsigned __int8)total_nodes);
total_players = 0;
if ( total_nodes )
{
result = 0LL;
v3 = 0;
v4 = 0;
do
{
if ( node[result] )
{
++v4;
v3 = 1;
}
++result;
}
while ( (unsigned __int8)total_nodes > (int)result );
if ( v3 )
total_players = v4;
}
if ( !a1 )
{
func11((unsigned int)gamedab);
result = func13(gamedab);
}
return result;
}

original_code:
void getgamedat(char lockit)
{
    int i=0;
while(lock(gamedab,0L,filelength(gamedab))==-1 && i++<100)
 ({ int sleep_msecs=30; 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); });
if(i>=100) {
 printf("\7getgamedat: error locking game.dab\r\n"); }
lseek(gamedab,0L,0);
read(gamedab,&misc,1);
read(gamedab,&curplayer,1);
read(gamedab,&total_nodes,1);
read(gamedab,node,total_nodes*2);
read(gamedab,status,total_nodes);
total_players=0;
for(i=0;i<total_nodes;i++)
    if(node[i])
        total_players++;
if(!lockit)
 unlock(gamedab,0L,filelength(gamedab));
}

canonical_original_code:
void getgamedat(char lockit)
{
    int i = 0;
while(lock(gamedab,0L,filelength(gamedab))==-1 && i++<100)
 ({ int sleep_msecs = 30; 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); });
if(i>=100) {
 printf("\7getgamedat: error locking game.dab\r\n"); }
lseek(gamedab,0L,0);
read(gamedab,&misc,1);
read(gamedab,&curplayer,1);
read(gamedab,&total_nodes,1);
read(gamedab,node,total_nodes*2);
read(gamedab,status,total_nodes);
total_players=0;
for(i=0;i<total_nodes;i++)
    if(node[i])
        total_players++;
if(!lockit)
 unlock(gamedab,0L,filelength(gamedab));
}

variable_types: lockit char

variable_types: i int


putgamedat

repo: ftnapps/pkg-sbbs

decompiled_code:
__int64 putgamedat()
{
lseek(gamedab, 0LL, 0);
write(gamedab, &misc, 1uLL);
write(gamedab, &curplayer, 1uLL);
write(gamedab, &total_nodes, 1uLL);
write(gamedab, node, 2 * (unsigned __int8)total_nodes);
write(gamedab, &status, (unsigned __int8)total_nodes);
filelength((unsigned int)gamedab);
return unlock(gamedab);
}

canonical_decompiled_code:
__int64 func8()
{
lseek(gamedab, 0LL, 0);
write(gamedab, &misc, 1uLL);
write(gamedab, &curplayer, 1uLL);
write(gamedab, &total_nodes, 1uLL);
write(gamedab, node, 2 * (unsigned __int8)total_nodes);
write(gamedab, &status, (unsigned __int8)total_nodes);
func11((unsigned int)gamedab);
return func13(gamedab);
}

original_code:
void putgamedat()
{
lseek(gamedab,0L,0);
write(gamedab,&misc,1);
write(gamedab,&curplayer,1);
write(gamedab,&total_nodes,1);
write(gamedab,node,total_nodes*2);
write(gamedab,status,total_nodes);
unlock(gamedab,0L,filelength(gamedab));
}

return_type: void


nextplayer

decompiled_code:
__int64 nextplayer()
{
__int64 v0; // rax
int v1; // ecx
__int64 v2; // rax
int v3; // edx
char v4; // al
__int64 result; // rax

getgamedat(1);
if ( (!curplayer || total_players == 1) && node[(unsigned __int8)node_num - 1] )
{
curplayer = node_num;
result = putgamedat();
}
else
{
if ( (unsigned __int8)curplayer >= (int)(unsigned __int8)total_nodes )
goto LABEL_8;
v0 = (unsigned __int8)curplayer;
while ( !node[v0] )
{
if ( (unsigned __int8)total_nodes <= (int)++v0 )
goto LABEL_8;
}
if ( (unsigned __int8)total_nodes <= (int)v0 )
{
LABEL_8:
v1 = (unsigned __int8)curplayer - 1;
if ( v1 <= 0 )
{
v3 = 0;
}
else
{
v2 = 0LL;
do
{
v3 = v2;
if ( node[v2] )
break;
v3 = ++v2;
}
while ( v1 > (int)v2 );
}
v4 = 0;
if ( v1 != v3 )
v4 = v3 + 1;
curplayer = v4;
}
else
{
curplayer = v0 + 1;
}
result = putgamedat();
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax
int v1; // ecx
__int64 v2; // rax
int v3; // edx
char v4; // al
__int64 result; // rax

func7(1);
if ( (!curplayer || total_players == 1) && node[(unsigned __int8)node_num - 1] )
{
curplayer = node_num;
result = func8();
}
else
{
if ( (unsigned __int8)curplayer >= (int)(unsigned __int8)total_nodes )
goto LABEL_8;
v0 = (unsigned __int8)curplayer;
while ( !node[v0] )
{
if ( (unsigned __int8)total_nodes <= (int)++v0 )
goto LABEL_8;
}
if ( (unsigned __int8)total_nodes <= (int)v0 )
{
LABEL_8:
v1 = (unsigned __int8)curplayer - 1;
if ( v1 <= 0 )
{
v3 = 0;
}
else
{
v2 = 0LL;
do
{
v3 = v2;
if ( node[v2] )
break;
v3 = ++v2;
}
while ( v1 > (int)v2 );
}
v4 = 0;
if ( v1 != v3 )
v4 = v3 + 1;
curplayer = v4;
}
else
{
curplayer = v0 + 1;
}
result = func8();
}
return result;
}

original_code:
void nextplayer()
{
    int i;
getgamedat(1);
if((!curplayer
    || total_players==1)
    && node[node_num-1]) {
 curplayer=node_num;
    putgamedat();
    return; }
for(i=curplayer;i<total_nodes;i++)
    if(node[i])
        break;
if(i>=total_nodes) {
 for(i=0;i<curplayer-1;i++)
        if(node[i])
            break;
 if(i==curplayer-1)
  curplayer=0;
    else
  curplayer=i+1; }
else
 curplayer=i+1;
putgamedat();
}


filetime

decompiled_code:
__time_t __fastcall filetime(int a1)
{
__time_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)fstat(a1, &v2) )
result = -1LL;
else
result = v2.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func10(int a1)
{
__time_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func17(a1, &v2) )
result = -1LL;
else
result = v2.st_mtim.tv_sec;
return result;
}

original_code:
time_t filetime(int fd)
{
 struct stat st;
 if(fstat(fd, &st)!=0)
  return(-1);
 return(st.st_mtim.tv_sec);
}

canonical_original_code:
long filetime(int fd)
{
 struct stat st;
 if(fstat(fd, &st)!=0)
  return(-1);
 return(st.st_mtim.tv_sec);
}

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


filelength

decompiled_code:
__off_t __fastcall filelength(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)fstat(a1, &v2) )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func11(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func17(a1, &v2) )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
long filelength(int fd)
{
 struct stat st;
 if(fstat(fd, &st)!=0)
  return(-1L);
 return(st.st_size);
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


lock

original_code:
int lock(int fd, long pos, long len)
{
   struct flock alock;
  int flags;
  if((flags=fcntl(fd,3))==-1)
   return -1;
  if(flags==00)
   alock.l_type = 0;
  else
   alock.l_type = 1;
  alock.l_whence = 0;
  alock.l_start = pos;
  alock.l_len = (int)len;
  if(fcntl(fd, 6, &alock)==-1 && (*__errno_location ()) != 22)
   return(-1);
  if(flock(fd,2|4)!=0 && (*__errno_location ()) != 95)
   return(-1);
  return(0);
}

variable_types: pos long

variable_types: len long

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }

variable_types: flags int

return_type: int


unlock

original_code:
int unlock(int fd, long pos, long len)
{
 struct flock alock;
 alock.l_type = 2;
 alock.l_whence = 0;
 alock.l_start = pos;
 alock.l_len = (int)len;
 if(fcntl(fd, 6, &alock)==-1 && (*__errno_location ()) != 22)
  return(-1);
 if(flock(fd,8|4)!=0 && (*__errno_location ()) != 95)
  return(-1);
 return(0);
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rdi
size_t v5; // rax
int v6; // ecx
int v7; // er8
int v8; // er9
char v9; // dl
__int64 v10; // rax
int result; // eax
char v12; // [rsp+1h] [rbp-119h]
char v13[280]; // [rsp+2h] [rbp-118h] BYREF

v3 = getenv("SBBSNODE");
if ( v3 )
{
strcpy(v13, v3);
v4 = getenv("SBBSNNUM");
if ( v4 )
{
node_num = atoi(v4);
v5 = strlen(v13);
v9 = *(&v12 + v5);
if ( v9 != 47 && v9 != 92 )
*(_WORD *)&v13[v5] = 47;
gamedab = sopen((unsigned int)"GAME.DAB", 2, 2, v6, v7, v8, v13[0]);
if ( gamedab == -1 )
{
fwrite("Error opening GAME.DAB\r\n", 1uLL, 0x18uLL, stderr);
result = 1;
}
else
{
getgamedat(1);
v10 = (unsigned __int8)node_num - 1;
node[v10] = 0;
status[v10] = 0;
putgamedat();
if ( curplayer == node_num )
nextplayer();
close(gamedab);
result = 0;
}
}
else
{
fwrite("!Need SBBSNNUM env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
}
else
{
fwrite("!Need SBBSNODE env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rdi
size_t v5; // rax
int v6; // ecx
int v7; // er8
int v8; // er9
char v9; // dl
__int64 v10; // rax
int result; // eax
char v12; // [rsp+1h] [rbp-119h]
char v13[280]; // [rsp+2h] [rbp-118h] BYREF

v3 = getenv("SBBSNODE");
if ( v3 )
{
strcpy(v13, v3);
v4 = getenv("SBBSNNUM");
if ( v4 )
{
node_num = atoi(v4);
v5 = strlen(v13);
v9 = *(&v12 + v5);
if ( v9 != 47 && v9 != 92 )
*(_WORD *)&v13[v5] = 47;
gamedab = func14((unsigned int)"GAME.DAB", 2, 2, v6, v7, v8, v13[0]);
if ( gamedab == -1 )
{
fwrite("Error opening GAME.DAB\r\n", 1uLL, 0x18uLL, stderr);
result = 1;
}
else
{
func7(1);
v10 = (unsigned __int8)node_num - 1;
node[v10] = 0;
status[v10] = 0;
func8();
if ( curplayer == node_num )
func9();
close(gamedab);
result = 0;
}
}
else
{
fwrite("!Need SBBSNNUM env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
}
else
{
fwrite("!Need SBBSNODE env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 char* p;
 char node_dir[260 +1];
 if((p=getenv("SBBSNODE"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNODE env var\n");
  return(-1);
 }
 strcpy(node_dir,p);
 if((p=getenv("SBBSNNUM"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNNUM env var\n");
  return(-1);
 }
 node_num=atoi(p);
 if(node_dir[strlen(node_dir)-1]!='\\'
  && node_dir[strlen(node_dir)-1]!='/')
  strcat(node_dir,"/");
 if((gamedab=sopen("GAME.DAB",02|0,2))==-1) {
  fprintf(stderr,"Error opening GAME.DAB\r\n");
  return(1);
 }
 getgamedat(1);
 node[node_num-1]=0;
 status[node_num-1]=0;
 putgamedat();
 if(curplayer==node_num)
  nextplayer();
 close(gamedab);
 return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *p;
 char node_dir[-1];
 if((p=getenv("SBBSNODE"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNODE env var\n");
  return(-1);
 }
 strcpy(node_dir,p);
 if((p=getenv("SBBSNNUM"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNNUM env var\n");
  return(-1);
 }
 node_num=atoi(p);
 if(node_dir[strlen(node_dir)-1]!='\\'
  && node_dir[strlen(node_dir)-1]!='/')
  strcat(node_dir,"/");
 if((gamedab=sopen("GAME.DAB",02|0,2))==-1) {
  fprintf(stderr,"Error opening GAME.DAB\r\n");
  return(1);
 }
 getgamedat(1);
 node[node_num-1]=0;
 status[node_num-1]=0;
 putgamedat();
 if(curplayer==node_num)
  nextplayer();
 close(gamedab);
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
p
char *


makewave

original_code:
void makewave(double freq, unsigned char *wave, int samples, enum WAVE_SHAPE shape)
{
 int i;
 int midpoint;
 double inc;
 double pos;
 int endhigh;
 midpoint=samples/2;
 inc=8.0*atan(1.0);
 inc *= ((double)freq / (double)22050);
 for(i=0;i<samples;i++) {
  pos=(inc*(double)i);
  pos -= (int)(pos/6.28318530717958647692)*6.28318530717958647692;
  switch(shape) {
   case WAVE_SHAPE_SINE:
    wave[i]=(sin (pos))*127+128;
    break;
   case WAVE_SHAPE_SINE_HARM:
    wave[i]=(sin (pos))*64+128;
    wave[i]=(sin ((inc*2)*(double)i))*24;
    wave[i]=(sin ((inc*3)*(double)i))*16;
    break;
   case WAVE_SHAPE_SAWTOOTH:
    wave[i]=(6.28318530717958647692 -pos)*40.5;
    break;
   case WAVE_SHAPE_SQUARE:
    wave[i]=(pos<3.14159265358979323846)?255:0;
    break;
   case WAVE_SHAPE_SINE_SAW:
    wave[i]=(((sin (pos))*127+128)+((6.28318530717958647692 -pos)*40.5))/2;
    break;
   case WAVE_SHAPE_SINE_SAW_CHORD:
    wave[i]=(((sin (pos))*64+128)+((6.28318530717958647692 -pos)*6.2))/2;
    wave[i]+=(sin ((inc/2)*(double)i))*24;
    wave[i]+=(sin ((inc/3)*(double)i))*16;
    break;
   case WAVE_SHAPE_SINE_SAW_HARM:
    wave[i]=(((sin (pos))*64+128)+((6.28318530717958647692 -pos)*6.2))/2;
    wave[i]+=(sin ((inc*2)*(double)i))*24;
    wave[i]+=(sin ((inc*3)*(double)i))*16;
    break;
  }
 }
 if(wave[samples-1]>128)
  endhigh=1;
 else
  endhigh=0;
 i=samples-1;
 if(wave[i]!=128) {
  for(;i>midpoint;i--) {
   if(endhigh && wave[i]<128)
    break;
   if(!endhigh && wave[i]>128)
    break;
   wave[i]=128;
  }
 }
}

variable_types: freq double

variable_types:
wave
unsigned char *

variable_types: samples int

variable_types: enum WAVE_SHAPE { WAVE_SHAPE_SINE=0, WAVE_SHAPE_SAWTOOTH=1, WAVE_SHAPE_SQUARE=2, WAVE_SHAPE_SINE_SAW=3, WAVE_SHAPE_SINE_HARM=4, WAVE_SHAPE_SINE_SAW_CHORD=5, WAVE_SHAPE_SINE_SAW_HARM=6 }

variable_types: midpoint int

variable_types: inc double

variable_types: pos double

variable_types: endhigh int


decompiled_code:
__int64 xptone_open()
{
unsigned int v0; // ebx
int v1; // ebp
int v3; // eax
int v4; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+4h] [rbp-24h] BYREF
int v6; // [rsp+8h] [rbp-20h] BYREF
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7[0] = 8;
v6 = 1;
v5 = 22050;
v4 = 2147418116;
v0 = handle_type;
if ( handle_type )
return 1;
v1 = sound_device_open_failed;
if ( !sound_device_open_failed )
{
v3 = open("/dev/dsp", 1, 0LL);
dsp = v3;
if ( v3 >= 0 )
{
ioctl(v3, 0xC004500AuLL, &v4);
if ( ioctl(dsp, 0xC0045005uLL, v7) == -1
|| v7[0] != 8
|| ioctl(dsp, 0xC0045006uLL, &v6) == -1
|| v6 != 1
|| ioctl(dsp, 0xC0045002uLL, &v5) == -1
|| v5 != 22050 )
{
sound_device_open_failed = 1;
close(dsp);
}
if ( sound_device_open_failed )
{
v0 = v1;
}
else
{
handle_type = 3;
v0 = 1;
}
}
else
{
sound_device_open_failed = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
int v1; // ebp
int v3; // eax
int v4; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+4h] [rbp-24h] BYREF
int v6; // [rsp+8h] [rbp-20h] BYREF
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7[0] = 8;
v6 = 1;
v5 = 22050;
v4 = 2147418116;
v0 = handle_type;
if ( handle_type )
return 1;
v1 = sound_device_open_failed;
if ( !sound_device_open_failed )
{
v3 = open("/dev/dsp", 1, 0LL);
dsp = v3;
if ( v3 >= 0 )
{
ioctl(v3, 0xC004500AuLL, &v4);
if ( ioctl(dsp, 0xC0045005uLL, v7) == -1
|| v7[0] != 8
|| ioctl(dsp, 0xC0045006uLL, &v6) == -1
|| v6 != 1
|| ioctl(dsp, 0xC0045002uLL, &v5) == -1
|| v5 != 22050 )
{
sound_device_open_failed = 1;
close(dsp);
}
if ( sound_device_open_failed )
{
v0 = v1;
}
else
{
handle_type = 3;
v0 = 1;
}
}
else
{
sound_device_open_failed = 1;
}
}
return v0;
}

variable_types: format int

variable_types: channels int

variable_types: rate int

variable_types: fragsize int


decompiled_code:
__int64 xptone_close()
{
if ( handle_type == 3 )
close(dsp);
handle_type = 0;
sound_device_open_failed = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( handle_type == 3 )
close(dsp);
handle_type = 0;
sound_device_open_failed = 0;
return 1LL;
}

original_code:
int xptone_close(void)
{
 if(handle_type==SOUND_DEVICE_OSS)
  close(dsp);
 handle_type=SOUND_DEVICE_CLOSED;
 sound_device_open_failed=0;
 alsa_device_open_failed=0;
 sdl_device_open_failed=0;
 return(1);
}

canonical_original_code:
int xptone_close()
{
 if(handle_type==SOUND_DEVICE_OSS)
  close(dsp);
 handle_type=SOUND_DEVICE_CLOSED;
 sound_device_open_failed=0;
 alsa_device_open_failed=0;
 sdl_device_open_failed=0;
 return(1);
}


xptone

decompiled_code:
__int64 __fastcall xptone(__int64 a1, int a2, double a3)
{
double v3; // rbp
unsigned int v4; // er12
int v5; // er14
double v6; // xmm0_8
int v8; // ebx
int v9; // eax
_BYTE v10[165416]; // [rsp+0h] [rbp-28628h] BYREF

v3 = a3;
v4 = 0;
if ( !handle_type )
{
v4 = xptone_open();
if ( !v4 )
return v4;
v4 = 1;
}
if ( a3 < 17.0 )
v3 = *(double *)&LC13;
v5 = 22050 * a1 / 0x3E8uLL;
v6 = 22050.0 / v3 + 22050.0 / v3;
if ( v6 >= (double)v5 )
v5 = (int)v6;
makewave(v10, v5, a2, v3);
if ( handle_type == 3 )
{
if ( v5 > 0 )
{
v8 = 0;
do
{
v9 = write(dsp, &v10[v8], v5 - v8);
if ( v9 >= 0 )
v8 += v9;
}
while ( v5 > v8 );
}
if ( v4 )
xptone_close();
else
v4 = 1;
}
else if ( v4 )
{
xptone_close();
v4 = 0;
}
return v4;
}

original_code:
int xptone(double freq, ulong duration, enum WAVE_SHAPE shape)
{
 int must_close=0;
 unsigned char wave[22050*15/2+1];
 int samples;
 int wr;
 int i;
 if(handle_type==SOUND_DEVICE_CLOSED) {
  must_close=1;
  if(!xptone_open())
   return(0);
 }
 if(freq<17)
  freq=17;
 samples=22050*duration/1000;
 if(samples<=22050/freq*2)
  samples=22050/freq*2;
 makewave(freq,wave,samples,shape);
 if(handle_type==SOUND_DEVICE_OSS) {
  wr=0;
  while(wr<samples) {
   i=write(dsp, wave+wr, samples-wr);
   if(i>=0)
    wr+=i;
  }
  if(must_close)
   xptone_close();
  return(1);
 }
 if(must_close)
  xptone_close();
 return(0);
}

canonical_original_code:
int xptone(double freq, unsigned long duration, enum WAVE_SHAPE shape)
{
 int must_close = 0;
 unsigned char wave[-1];
 int samples;
 int wr;
 int i;
 if(handle_type==SOUND_DEVICE_CLOSED) {
  must_close=1;
  if(!xptone_open())
   return(0);
 }
 if(freq<17)
  freq=17;
 samples=22050*duration/1000;
 if(samples<=22050/freq*2)
  samples=22050/freq*2;
 makewave(freq,wave,samples,shape);
 if(handle_type==SOUND_DEVICE_OSS) {
  wr=0;
  while(wr<samples) {
   i=write(dsp, wave+wr, samples-wr);
   if(i>=0)
    wr+=i;
  }
  if(must_close)
   xptone_close();
  return(1);
 }
 if(must_close)
  xptone_close();
 return(0);
}

variable_types:
duration
unsigned long

variable_types:
wave
unsigned char [-1]

variable_types: wr int

variable_types: i int

user_defined_types: enum WAVE_SHAPE { WAVE_SHAPE_SINE=0, WAVE_SHAPE_SAWTOOTH=1, WAVE_SHAPE_SQUARE=2, WAVE_SHAPE_SINE_SAW=3, WAVE_SHAPE_SINE_HARM=4, WAVE_SHAPE_SINE_SAW_CHORD=5, WAVE_SHAPE_SINE_SAW_HARM=6 }


decompiled_code:
int __fastcall unix_beep(int a1, int a2)
{
int v3; // edi
int result; // eax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v3 = console_fd_0;
if ( console_fd_0 != -1 || (result = open("/dev/console", 256), v3 = result, console_fd_0 = result, result != -1) )
{
if ( a1 )
ioctl(v3, 0x4B2FuLL, (unsigned int)(1193180 / a1));
v5.tv_sec = a2 / 1000;
v5.tv_usec = 1000 * (a2 % 1000);
select(0, 0LL, 0LL, 0LL, &v5);
result = ioctl(console_fd_0, 0x4B2FuLL, 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, int a2)
{
int v3; // edi
int result; // eax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v3 = console_fd_0;
if ( console_fd_0 != -1 || (result = open("/dev/console", 256), v3 = result, console_fd_0 = result, result != -1) )
{
if ( a1 )
ioctl(v3, 0x4B2FuLL, (unsigned int)(1193180 / a1));
v5.tv_sec = a2 / 1000;
v5.tv_usec = 1000 * (a2 % 1000);
select(0, 0LL, 0LL, 0LL, &v5);
result = ioctl(console_fd_0, 0x4B2FuLL, 0LL);
}
return result;
}

original_code:
void unix_beep(int freq, int dur)
{
 static int console_fd=-1;
 if(console_fd == -1)
    console_fd = open("/dev/console", 0400);
 if(console_fd != -1) {
  if(freq != 0)
   ioctl(console_fd, 0x4B2F, (int) (1193180 / freq));
  ({ int sleep_msecs=dur; 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); });
  ioctl(console_fd, 0x4B2F, 0);
 }
}

canonical_original_code:
void unix_beep(int freq, int dur)
{
 static int console_fd = -1;
 if(console_fd == -1)
    console_fd = open("/dev/console", 0400);
 if(console_fd != -1) {
  if(freq != 0)
   ioctl(console_fd, 0x4B2F, (int) (1193180 / freq));
  ({ int sleep_msecs = dur; 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); });
  ioctl(console_fd, 0x4B2F, 0);
 }
}

variable_types: freq int

variable_types: dur int

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


xpbeep

decompiled_code:
int __fastcall xpbeep(__int64 a1, double a2)
{
int result; // eax

result = xptone(a1, 6, a2);
if ( !result )
result = unix_beep((int)(a2 + 0.5), a1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, double a2)
{
int result; // eax

result = func3(a1, 6, a2);
if ( !result )
result = func4((int)(a2 + 0.5), a1);
return result;
}

original_code:
void xpbeep(double freq, ulong duration)
{
 if(xptone(freq,duration,WAVE_SHAPE_SINE_SAW_HARM))
  return;
 unix_beep((int)(freq+.5),duration);
}

canonical_original_code:
void xpbeep(double freq, unsigned long duration)
{
 if(xptone(freq,duration,WAVE_SHAPE_SINE_SAW_HARM))
  return;
 unix_beep((int)(freq+.5),duration);
}

variable_types: freq double


sethelp

decompiled_code:
void __fastcall sethelp(int a1, char *a2)
{
helpline = a1;
helpfile = a2;
}

canonical_decompiled_code:
void __fastcall func2(int a1, char *a2)
{
helpline = a1;
helpfile = a2;
}

original_code:
void sethelp(int line, char* file)
{
    helpline=line;
    helpfile=file;
}

canonical_original_code:
void sethelp(int line, char *file)
{
    helpline=line;
    helpfile=file;
}

variable_types: line int

variable_types:
file
char *


upop

decompiled_code:
int __fastcall upop(const char *a1)
{
int result; // eax

if ( a1 )
result = printf("\r%-79s", a1);
else
result = putchar(10);
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
int result; // eax

if ( a1 )
result = printf("\r%-79s", a1);
else
result = putchar(10);
return result;
}

original_code:
void upop(char *str)
{
    if(str==((void *)0))
        printf("\n");
    else
        printf("\r%-79s",str);
}

variable_types:
str
char *


uinput

decompiled_code:
size_t __fastcall uinput(__int64 a1, __int64 a2, __int64 a3, const char *a4, char *a5, unsigned int a6, char a7)
{
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

while ( 1 )
{
printf("%s (maxlen=%u): ", a4, a6);
getstr((__int64)v11, a6);
truncsp(v11);
if ( strcmp(v11, "?") )
break;
help();
}
if ( strcmp(a5, v11) )
*(_DWORD *)(api + 16) = 1;
if ( (a7 & 1) != 0 )
strupr(v11);
strcpy(a5, v11);
return strlen(a5);
}

canonical_decompiled_code:
size_t __fastcall func8(__int64 a1, __int64 a2, __int64 a3, const char *a4, char *a5, unsigned int a6, char a7)
{
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

while ( 1 )
{
printf("%s (maxlen=%u): ", a4, a6);
func5((__int64)v11, a6);
func3(v11);
if ( strcmp(v11, "?") )
break;
func6();
}
if ( strcmp(a5, v11) )
*(_DWORD *)(api + 16) = 1;
if ( (a7 & 1) != 0 )
func7(v11);
strcpy(a5, v11);
return strlen(a5);
}

original_code:
int uinput(int mode, int left, int top, char *prompt, char *outstr,
 int max, int kmode)
{
    char str[256];
    while(1) {
        printf("%s (maxlen=%u): ",prompt,max);
        getstr(str,max);
        truncsp(str);
        if(strcmp(str,"?"))
            break;
        help();
    }
 if(strcmp(outstr,str))
  api->changes=1;
    if(kmode&(1L<<0))
     strupr(str);
    strcpy(outstr,str);
    return(strlen(outstr));
}

variable_types: mode int

variable_types: left int

variable_types: top int

variable_types:
prompt
char *

variable_types:
outstr
char *

variable_types: max int

variable_types: kmode int

variable_types:
str
char [256]


which

decompiled_code:
__int64 __fastcall which(const char *a1, int a2)
{
int v2; // eax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

do
{
do
{
printf("%s which (1-%d): ", a1, (unsigned int)a2);
v4[0] = 0;
getstr((__int64)v4, 40);
v2 = atoi(v4);
}
while ( v2 <= 0 );
}
while ( a2 < v2 );
return (unsigned int)(v2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, int a2)
{
int v2; // eax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

do
{
do
{
printf("%s which (1-%d): ", a1, (unsigned int)a2);
v4[0] = 0;
func5((__int64)v4, 40);
v2 = atoi(v4);
}
while ( v2 <= 0 );
}
while ( a2 < v2 );
return (unsigned int)(v2 - 1);
}

original_code:
static int which(char* prompt, int max)
{
    char str[41];
    int i;
    while(1) {
        printf("%s which (1-%d): ",prompt,max);
        str[0]=0;
  getstr(str,sizeof(str)-1);
        i=atoi(str);
        if(i>0 && i<=max)
            return(i-1);
    }
}

canonical_original_code:
static int which(char *prompt, int max)
{
    char str[41];
    int i;
    while(1) {
        printf("%s which (1-%d): ",prompt,max);
        str[0]=0;
  getstr(str,sizeof(str)-1);
        i=atoi(str);
        if(i>0 && i<=max)
            return(i-1);
    }
}

variable_types:
str
char [41]


ulist

decompiled_code:
__int64 __fastcall ulist(__int16 a1, __int64 a2, __int64 a3, __int64 a4, int *a5, __int64 a6, const char *a7, const char **a8)
{
const char **v8; // rdx
int i; // er13
int v10; // er14
const char **v11; // r12
int v12; // ebp
int v13; // ebx
int v14; // eax
unsigned int v17; // [rsp+8h] [rbp-C0h]
char nptr[184]; // [rsp+10h] [rbp-B8h] BYREF

v8 = a8;
for ( i = 0; i != 10000; ++i )
{
if ( !*v8 )
break;
if ( !**v8 )
break;
++v8;
}
if ( *a5 >= i )
*a5 = i - 1;
if ( *a5 < 0 )
*a5 = 0;
v10 = 4;
if ( i <= 999 )
{
v10 = 3;
if ( i <= 99 )
v10 = (i > 9) + 1;
}
do
{
if ( i == 2 )
{
if ( !strcasecmp(*a8, "Yes") && !strcasecmp(a8[1], "No") )
{
printf("%s? ", a7);
goto LABEL_32;
}
printf("\n[%s]\n", a7);
LABEL_16:
v11 = a8;
v12 = 0;
do
{
v13 = v12++;
printf("%*d: %s\n", v10, (unsigned int)v12, *v11);
if ( !((unsigned int)(v13 + 3) % *(_DWORD *)(api + 28)) )
{
printf("More? ");
nptr[0] = 0;
getstr((__int64)nptr, 127);
if ( (*_ctype_toupper_loc())[nptr[0]] == 78 )
break;
}
++v11;
}
while ( v12 < i );
goto LABEL_23;
}
printf("\n[%s]\n", a7);
if ( i > 0 )
goto LABEL_16;
LABEL_23:
nptr[0] = 0;
if ( (a1 & 0x1000) != 0 )
strcat(nptr, ", Copy");
if ( (a1 & 0x2000) != 0 )
*(_QWORD *)&nptr[strlen(nptr)] = 0x6574736150202CLL;
if ( (a1 & 0x20) != 0 )
strcat(nptr, ", Add");
if ( (a1 & 0x80u) != 0 )
strcat(nptr, ", Delete");
printf("\nWhich (Help%s or Quit): ", nptr);
LABEL_32:
nptr[0] = 0;
getstr((__int64)nptr, 127);
truncsp(nptr);
v14 = atoi(nptr);
if ( v14 > 0 && v14 <= i )
{
v17 = v14 - 1;
*a5 = v14 - 1;
return v17;
}
atoi(&nptr[1]);
}
while ( (*_ctype_toupper_loc())[nptr[0]] );
puts("Quit");
return (unsigned int)-1;
}

original_code:
int ulist(int mode, int left, int top, int width, int *cur, int *bar
 , char *title, char **option)
{
    char str[128];
 int i,opts;
    int optnumlen;
    int yesno=0;
    int lines;
    for(opts=0;opts<10000;opts++)
     if(option[opts]==((void *)0) || option[opts][0]==0)
      break;
    if((*cur)>=opts)
        (*cur)=opts-1;
    if((*cur)<0)
        (*cur)=0;
    if(opts>999)
        optnumlen=4;
    else if(opts>99)
        optnumlen=3;
    else if(opts>9)
        optnumlen=2;
    else
        optnumlen=1;
    while(1) {
        if(opts==2 && !strcasecmp(option[0],"Yes") && !strcasecmp(option[1],"No")) {
            yesno=1;
            printf("%s? ",title);
        } else {
            printf("\n[%s]\n",title);
            lines=2;
            for(i=0;i<opts;i++) {
                printf("%*d: %s\n",optnumlen,i+1,option[i]);
                lines++;
                if(!(lines%api->scrn_len)) {
                    printf("More? ");
                    str[0]=0;
                    getstr(str,sizeof(str)-1);
                    if(toupper(*str)=='N')
                        break;
                }
            }
            str[0]=0;
            if(mode&(1<<12))
                strcat(str,", Copy");
            if(mode&(1<<13))
                strcat(str,", Paste");
            if(mode&(1<<5))
                strcat(str,", Add");
            if(mode&(1<<7))
                strcat(str,", Delete");
            printf("\nWhich (Help%s or Quit): ",str);
        }
        str[0]=0;
        getstr(str,sizeof(str)-1);
        truncsp(str);
        i=atoi(str);
        if(i>0 && i<=opts) {
            *cur=--i;
            return(*cur);
        }
        i=atoi(str+1);
        switch(toupper(*str)) {
            case 0:
            case 0x1b:
            case 'Q':
                printf("Quit\n");
                return(-1);
            case 'Y':
                if(!yesno)
                    break;
                printf("Yes\n");
                return(0);
            case 'N':
                if(!yesno)
                    break;
                printf("No\n");
                return(1);
            case 'H':
            case '?':
                printf("Help\n");
                help();
                break;
            case 'A':
    if(!(mode&(1<<5)))
     break;
    if(!opts)
        return(0x10000000);
                if(i>0 && i<=opts+1)
           return((i-1)|0x10000000);
                return(which("Add before",opts+1)|0x10000000);
            case 'D':
    if(!(mode&(1<<7)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x20000000);
                if(opts==1)
                    return(0x20000000);
                return(which("Delete",opts)|0x20000000);
            case 'C':
    if(!(mode&(1<<12)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x30000000);
                if(opts==1)
                    return(0x30000000);
                return(which("Copy",opts)|0x30000000);
            case 'P':
    if(!(mode&(1<<13)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x40000000);
                if(opts==1)
                    return(0x40000000);
                return(which("Paste",opts)|0x40000000);
        }
    }
}

canonical_original_code:
int ulist(int mode, int left, int top, int width, int *cur, int *bar, char *title, char **option)
{
    char str[128];
 int i; int opts;
    int optnumlen;
    int yesno = 0;
    int lines;
    for(opts=0;opts<10000;opts++)
     if(option[opts]==((void *)0) || option[opts][0]==0)
      break;
    if((*cur)>=opts)
        (*cur)=opts-1;
    if((*cur)<0)
        (*cur)=0;
    if(opts>999)
        optnumlen=4;
    else if(opts>99)
        optnumlen=3;
    else if(opts>9)
        optnumlen=2;
    else
        optnumlen=1;
    while(1) {
        if(opts==2 && !strcasecmp(option[0],"Yes") && !strcasecmp(option[1],"No")) {
            yesno=1;
            printf("%s? ",title);
        } else {
            printf("\n[%s]\n",title);
            lines=2;
            for(i=0;i<opts;i++) {
                printf("%*d: %s\n",optnumlen,i+1,option[i]);
                lines++;
                if(!(lines%api->scrn_len)) {
                    printf("More? ");
                    str[0]=0;
                    getstr(str,sizeof(str)-1);
                    if(toupper(*str)=='N')
                        break;
                }
            }
            str[0]=0;
            if(mode&(1<<12))
                strcat(str,", Copy");
            if(mode&(1<<13))
                strcat(str,", Paste");
            if(mode&(1<<5))
                strcat(str,", Add");
            if(mode&(1<<7))
                strcat(str,", Delete");
            printf("\nWhich (Help%s or Quit): ",str);
        }
        str[0]=0;
        getstr(str,sizeof(str)-1);
        truncsp(str);
        i=atoi(str);
        if(i>0 && i<=opts) {
            *cur=--i;
            return(*cur);
        }
        i=atoi(str+1);
        switch(toupper(*str)) {
            case 0:
            case 0x1b:
            case 'Q':
                printf("Quit\n");
                return(-1);
            case 'Y':
                if(!yesno)
                    break;
                printf("Yes\n");
                return(0);
            case 'N':
                if(!yesno)
                    break;
                printf("No\n");
                return(1);
            case 'H':
            case '?':
                printf("Help\n");
                help();
                break;
            case 'A':
    if(!(mode&(1<<5)))
     break;
    if(!opts)
        return(0x10000000);
                if(i>0 && i<=opts+1)
           return((i-1)|0x10000000);
                return(which("Add before",opts+1)|0x10000000);
            case 'D':
    if(!(mode&(1<<7)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x20000000);
                if(opts==1)
                    return(0x20000000);
                return(which("Delete",opts)|0x20000000);
            case 'C':
    if(!(mode&(1<<12)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x30000000);
                if(opts==1)
                    return(0x30000000);
                return(which("Copy",opts)|0x30000000);
            case 'P':
    if(!(mode&(1<<13)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x40000000);
                if(opts==1)
                    return(0x40000000);
                return(which("Paste",opts)|0x40000000);
        }
    }
}

variable_types: width int

variable_types:
cur
int *

variable_types:
bar
int *

variable_types:
title
char *

variable_types:
option
char **

variable_types:
str
char [128]

variable_types: i int

variable_types: opts int

variable_types: optnumlen int

variable_types: yesno int

variable_types: lines int


uifcinix

original_code:
int uifcinix(uifcapi_t* uifcapi)
{
    if(uifcapi==((void *)0) || uifcapi->size!=sizeof(uifcapi_t))
        return(-1);
    api=uifcapi;
    api->bail=uifcbail;
    api->scrn=uscrn;
    api->msg=umsg;
    api->pop=upop;
    api->list=ulist;
    api->input=uinput;
    api->sethelp=sethelp;
    api->showhelp=help;
 api->showbuf=((void *)0);
 api->timedisplay=((void *)0);
    setvbuf(stdin,((void *)0),2,0);
    setvbuf(stdout,((void *)0),2,0);
    api->scrn_len=24;
 api->initialized=1;
    return(0);
}

canonical_original_code:
int uifcinix(struct uifcapi_t *uifcapi)
{
    if(uifcapi==((void *)0) || uifcapi->size!=sizeof(uifcapi_t))
        return(-1);
    api=uifcapi;
    api->bail=uifcbail;
    api->scrn=uscrn;
    api->msg=umsg;
    api->pop=upop;
    api->list=ulist;
    api->input=uinput;
    api->sethelp=sethelp;
    api->showhelp=help;
 api->showbuf=((void *)0);
 api->timedisplay=((void *)0);
    setvbuf(stdin,((void *)0),2,0);
    setvbuf(stdout,((void *)0),2,0);
    api->scrn_len=24;
 api->initialized=1;
    return(0);
}

variable_types: struct uifcapi_t { unsigned long size; long mode; int changes; unsigned int savnum; unsigned int savdepth; unsigned int scrn_len; unsigned int scrn_width; unsigned int esc_delay; char *helpbuf; char helpdatfile[-1]; char helpixbfile[-1]; int buttony; int exitstart; int exitend; int helpstart; int helpend; int list_height; unsigned char hclr; int initialized; void (*bail)(); int (*scrn)(char *str); void (*msg)(char *str); void (*pop)(char *str); int (*list)(int mode, int left, int top, int width, int *dflt, int *bar, char *title, char **option); int (*input)(int mode, int left, int top, char *prompt, char *str, int len, int kmode); void (*sethelp)(int line, char *file); void (*showhelp)(); void (*showbuf)(int mode, int left, int top, int width, int height, char *title, char *hbuf, int *curp, int *barp); void (*timedisplay)(int force); void (*bottomline)(int line); int (*getstrxy)(int left, int top, int width, char *outstr, int max, long mode, int *lastkey); int (*printf)(int x, int y, unsigned int attr, char *fmat, ...); } *


mimegetboundary

decompiled_code:
_BYTE *mimegetboundary()
{
_BYTE *v0; // r12
unsigned int v1; // eax
_BYTE *v2; // rbx
unsigned int v3; // ecx
char v4; // dl
char v5; // al
int v6; // eax

v0 = malloc(0x25uLL);
v1 = time(0LL);
srand(v1);
if ( v0 )
{
v2 = v0;
do
{
v6 = rand() % 62;
if ( v6 > 9 )
{
v3 = v6 - 10;
v4 = v6 + 55;
v5 = v6 + 61;
if ( v3 <= 0x19 )
v5 = v4;
}
else
{
v5 = v6 + 48;
}
*v2++ = v5;
}
while ( v2 != v0 + 36 );
v0[36] = 0;
}
return v0;
}

original_code:
char* mimegetboundary()
{
    int i, num;
    char* boundaryString = (char*)malloc(36 + 1);
    srand(time(((void *)0)));
    if (boundaryString == ((void *)0))
        return ((void *)0);
    for (i=0;i<36;i++) {
        num=(rand()%62);
        if(num<10)
            num+=48;
        else if(num>=10 && num<36)
            num+=55;
        else
            num+=61;
        boundaryString[i]=(char)num;
    }
    boundaryString[i]='\0';
    return boundaryString;
}

canonical_original_code:
char *mimegetboundary()
{
    int i; int num;
    char *boundaryString = (char*)malloc(36 + 1);
    srand(time(((void *)0)));
    if (boundaryString == ((void *)0))
        return ((void *)0);
    for (i=0;i<36;i++) {
        num=(rand()%62);
        if(num<10)
            num+=48;
        else if(num>=10 && num<36)
            num+=55;
        else
            num+=61;
        boundaryString[i]=(char)num;
    }
    boundaryString[i]='\0';
    return boundaryString;
}

variable_types: num int

variable_types:
boundaryString
char *

return_type: char *


mimeheaders

decompiled_code:
__int64 __fastcall mimeheaders(__int64 a1, const char *a2)
{
sockprintf(a1, "MIME-Version: 1.0");
sockprintf((unsigned int)a1, "Content-Type: multipart/mixed;");
return sockprintf((unsigned int)a1, " boundary=\"%s\"", a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
sockprintf(a1, "MIME-Version: 1.0");
sockprintf((unsigned int)a1, "Content-Type: multipart/mixed;");
return sockprintf((unsigned int)a1, " boundary=\"%s\"", a2);
}

original_code:
void mimeheaders(int socket, char* boundary)
{
    sockprintf(socket,"MIME-Version: 1.0");
    sockprintf(socket,"Content-Type: multipart/mixed;");
    sockprintf(socket," boundary=\"%s\"",boundary);
}

canonical_original_code:
void mimeheaders(int socket, char *boundary)
{
    sockprintf(socket,"MIME-Version: 1.0");
    sockprintf(socket,"Content-Type: multipart/mixed;");
    sockprintf(socket," boundary=\"%s\"",boundary);
}

variable_types: socket int

variable_types:
boundary
char *


mimeblurb

decompiled_code:
__int64 __fastcall mimeblurb(__int64 a1)
{
sockprintf(a1, "This is a multi-part message in MIME format.");
return sockprintf((unsigned int)a1, (const char *)&unk_31A);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
sockprintf(a1, "This is a multi-part message in MIME format.");
return sockprintf((unsigned int)a1, (const char *)&unk_31A);
}

original_code:
void mimeblurb(int socket, char* boundary)
{
    sockprintf(socket,"This is a multi-part message in MIME format.");
    sockprintf(socket,"");
}

canonical_original_code:
void mimeblurb(int socket, char *boundary)
{
    sockprintf(socket,"This is a multi-part message in MIME format.");
    sockprintf(socket,"");
}


mimetextpartheader

decompiled_code:
__int64 __fastcall mimetextpartheader(__int64 a1, const char *a2)
{
sockprintf(a1, "--%s", a2);
sockprintf((unsigned int)a1, "Content-Type: text/plain;");
sockprintf((unsigned int)a1, " charset=\"iso-8859-1\"");
return sockprintf((unsigned int)a1, "Content-Transfer-Encoding: 7bit");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
sockprintf(a1, "--%s", a2);
sockprintf((unsigned int)a1, "Content-Type: text/plain;");
sockprintf((unsigned int)a1, " charset=\"iso-8859-1\"");
return sockprintf((unsigned int)a1, "Content-Transfer-Encoding: 7bit");
}

original_code:
void mimetextpartheader(int socket, char* boundary)
{
    sockprintf(socket,"--%s",boundary);
    sockprintf(socket,"Content-Type: text/plain;");
    sockprintf(socket," charset=\"iso-8859-1\"");
    sockprintf(socket,"Content-Transfer-Encoding: 7bit");
}

canonical_original_code:
void mimetextpartheader(int socket, char *boundary)
{
    sockprintf(socket,"--%s",boundary);
    sockprintf(socket,"Content-Type: text/plain;");
    sockprintf(socket," charset=\"iso-8859-1\"");
    sockprintf(socket,"Content-Transfer-Encoding: 7bit");
}


mimeattach

decompiled_code:
__int64 __fastcall mimeattach(unsigned int a1, const char *a2, const char *a3)
{
const char *v4; // r12
__int64 result; // rax

v4 = (const char *)getfname(a3);
sockprintf(a1, "--%s", a2);
sockprintf(a1, "Content-Type: application/octet-stream;");
sockprintf(a1, " name=\"%s\"", v4);
sockprintf(a1, "Content-Transfer-Encoding: base64");
sockprintf(a1, "Content-Disposition: attachment;");
sockprintf(a1, " filename=\"%s\"", v4);
sockprintf(a1, (const char *)&unk_31A);
result = base64out(a1, a3);
if ( (_DWORD)result )
{
sockprintf(a1, (const char *)&unk_31A);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, const char *a2, const char *a3)
{
const char *v4; // r12
__int64 result; // rax

v4 = (const char *)getfname(a3);
sockprintf(a1, "--%s", a2);
sockprintf(a1, "Content-Type: application/octet-stream;");
sockprintf(a1, " name=\"%s\"", v4);
sockprintf(a1, "Content-Transfer-Encoding: base64");
sockprintf(a1, "Content-Disposition: attachment;");
sockprintf(a1, " filename=\"%s\"", v4);
sockprintf(a1, (const char *)&unk_31A);
result = func4(a1, a3);
if ( (_DWORD)result )
{
sockprintf(a1, (const char *)&unk_31A);
result = 1LL;
}
return result;
}

original_code:
int mimeattach(int socket, char* boundary, char* pathfile)
{
    char* fname = getfname(pathfile);
    sockprintf(socket,"--%s",boundary);
    sockprintf(socket,"Content-Type: application/octet-stream;");
    sockprintf(socket," name=\"%s\"",fname);
    sockprintf(socket,"Content-Transfer-Encoding: base64");
    sockprintf(socket,"Content-Disposition: attachment;");
    sockprintf(socket," filename=\"%s\"",fname);
    sockprintf(socket,"");
    if(!base64out(socket,pathfile))
  return(0);
    sockprintf(socket,"");
 return(1);
}

canonical_original_code:
int mimeattach(int socket, char *boundary, char *pathfile)
{
    char *fname = getfname(pathfile);
    sockprintf(socket,"--%s",boundary);
    sockprintf(socket,"Content-Type: application/octet-stream;");
    sockprintf(socket," name=\"%s\"",fname);
    sockprintf(socket,"Content-Transfer-Encoding: base64");
    sockprintf(socket,"Content-Disposition: attachment;");
    sockprintf(socket," filename=\"%s\"",fname);
    sockprintf(socket,"");
    if(!base64out(socket,pathfile))
  return(0);
    sockprintf(socket,"");
 return(1);
}

variable_types:
pathfile
char *

variable_types:
fname
char *


endmime

decompiled_code:
__int64 __fastcall endmime(__int64 a1, const char *a2)
{
sockprintf(a1, "--%s--", a2);
return sockprintf((unsigned int)a1, (const char *)&unk_31A);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
sockprintf(a1, "--%s--", a2);
return sockprintf((unsigned int)a1, (const char *)&unk_31A);
}

original_code:
void endmime(int socket, char* boundary)
{
    sockprintf(socket,"--%s--",boundary);
    sockprintf(socket,"");
}

canonical_original_code:
void endmime(int socket, char *boundary)
{
    sockprintf(socket,"--%s--",boundary);
    sockprintf(socket,"");
}


msgdate

decompiled_code:
char *__fastcall msgdate(time_t a1, __int16 a2, char *a3)
{
int v4; // er12
char v5; // bp
__int64 v6; // rax
time_t v8; // [rsp+0h] [rbp-68h] BYREF
__int16 v9; // [rsp+8h] [rbp-60h]
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

v8 = a1;
v9 = a2;
v4 = smb_tzutc((unsigned int)a2);
v5 = 43;
if ( (v4 & 0x8000u) != 0 )
{
v4 = -v4;
v5 = 45;
}
if ( !localtime_r(&v8, &tp) )
{
*(_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;
}
v6 = (unsigned int)((__int16)v4 / 60);
LODWORD(v6) = (__int16)v4 / 60;
sprintf(
a3,
"%s, %d %s %d %02d:%02d:%02d %c%02u%02u",
*((const char **)&wday + tp.tm_wday),
(unsigned int)tp.tm_mday,
*((const char **)&mon + tp.tm_mon),
(unsigned int)(tp.tm_year + 1900),
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
(unsigned int)v5,
v6,
(unsigned int)((__int16)v4 % 60));
return a3;
}

canonical_decompiled_code:
char *__fastcall func0(time_t a1, __int16 a2, char *a3)
{
int v4; // er12
char v5; // bp
__int64 v6; // rax
time_t v8; // [rsp+0h] [rbp-68h] BYREF
__int16 v9; // [rsp+8h] [rbp-60h]
struct tm tp; // [rsp+10h] [rbp-58h] BYREF

v8 = a1;
v9 = a2;
v4 = smb_tzutc((unsigned int)a2);
v5 = 43;
if ( (v4 & 0x8000u) != 0 )
{
v4 = -v4;
v5 = 45;
}
if ( !localtime_r(&v8, &tp) )
{
*(_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;
}
v6 = (unsigned int)((__int16)v4 / 60);
LODWORD(v6) = (__int16)v4 / 60;
sprintf(
a3,
"%s, %d %s %d %02d:%02d:%02d %c%02u%02u",
*((const char **)&wday + tp.tm_wday),
(unsigned int)tp.tm_mday,
*((const char **)&mon + tp.tm_mon),
(unsigned int)(tp.tm_year + 1900),
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
(unsigned int)v5,
v6,
(unsigned int)((__int16)v4 % 60));
return a3;
}

original_code:
char* msgdate(when_t when, char* buf)
{
 struct tm tm;
 char plus='+';
 short tz;
 tz=smb_tzutc(when.zone);
 if(tz<0) {
  plus='-';
  tz=-tz;
 }
 if(localtime_r((const time_t*)&when.time,&tm)==((void *)0))
  memset(&tm,0,sizeof(tm));
 sprintf(buf,"%s, %d %s %d %02d:%02d:%02d %c%02u%02u"
  ,wday[tm.tm_wday]
  ,tm.tm_mday
  ,mon[tm.tm_mon]
  ,1900+tm.tm_year
  ,tm.tm_hour
  ,tm.tm_min
  ,tm.tm_sec
  ,plus, tz/60, tz%60
  );
 return(buf);
}

canonical_original_code:
char *msgdate(struct when_t when, char *buf)
{
 struct tm tm;
 char plus = '+';
 short tz;
 tz=smb_tzutc(when.zone);
 if(tz<0) {
  plus='-';
  tz=-tz;
 }
 if(localtime_r((long *)&when.time,&tm)==((void *)0))
  memset(&tm,0,sizeof(tm));
 sprintf(buf,"%s, %d %s %d %02d:%02d:%02d %c%02u%02u"
  ,wday[tm.tm_wday]
  ,tm.tm_mday
  ,mon[tm.tm_mon]
  ,1900+tm.tm_year
  ,tm.tm_hour
  ,tm.tm_min
  ,tm.tm_sec
  ,plus, tz/60, tz%60
  );
 return(buf);
}

variable_types: struct when_t { unsigned long time; short zone; }

variable_types:
buf
char *

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

variable_types: plus char

variable_types: tz short


decompiled_code:
time_t __fastcall rfc822date(char *nptr)
{
char *v1; // rbp
char v2; // bl
const unsigned __int16 *v3; // r12
char v4; // al
const char *v5; // rbx
int v6; // eax
char v7; // bp
const unsigned __int16 *v8; // rax
char v9; // bp
const unsigned __int16 *v10; // rdx
char v11; // bp
const unsigned __int16 *v12; // rdx
char v13; // bp
const unsigned __int16 *v14; // rax
char j; // bp
const char *v16; // rbx
int v17; // eax
const char *v18; // rdi
__int16 v19; // ax
struct tm tp; // [rsp+10h] [rbp-B8h] BYREF
__int64 v22; // [rsp+56h] [rbp-72h]
__int16 i; // [rsp+5Eh] [rbp-6Ah]
char s[32]; // [rsp+60h] [rbp-68h] BYREF
char nptra[72]; // [rsp+80h] [rbp-48h] BYREF

v1 = nptr;
*(_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;
v22 = 0LL;
for ( i = 0; *v1 && *v1 <= 32; ++v1 )
;
v2 = *v1;
if ( *v1 )
{
v3 = *_ctype_b_loc();
while ( (v3[v2] & 0x800) == 0 )
{
v2 = *++v1;
if ( !*v1 )
goto LABEL_9;
}
tp.tm_mday = atoi(v1);
v4 = *v1;
if ( *v1 )
{
while ( (v3[v4] & 0x800) != 0 )
{
v4 = *++v1;
if ( !*v1 )
goto LABEL_13;
}
for ( ; *v1 && *v1 <= 32; ++v1 )
;
}
}
else
{
LABEL_9:
tp.tm_mday = atoi(v1);
}
LABEL_13:
sprintf(s, "%3.3s", v1);
if ( !strcasecmp(s, "jan") )
{
tp.tm_mon = 0;
}
else if ( !strcasecmp(s, "feb") )
{
tp.tm_mon = 1;
}
else if ( !strcasecmp(s, "mar") )
{
tp.tm_mon = 2;
}
else if ( !strcasecmp(s, "apr") )
{
tp.tm_mon = 3;
}
else if ( !strcasecmp(s, "may") )
{
tp.tm_mon = 4;
}
else if ( !strcasecmp(s, "jun") )
{
tp.tm_mon = 5;
}
else if ( !strcasecmp(s, "jul") )
{
tp.tm_mon = 6;
}
else if ( !strcasecmp(s, "aug") )
{
tp.tm_mon = 7;
}
else if ( !strcasecmp(s, "sep") )
{
tp.tm_mon = 8;
}
else if ( !strcasecmp(s, "oct") )
{
tp.tm_mon = 9;
}
else
{
tp.tm_mon = 11 - (strcasecmp(s, "nov") == 0);
}
v5 = v1 + 4;
v6 = atoi(v1 + 4);
if ( v6 > 69 )
{
if ( v6 >= 1901 )
v6 -= 1900;
tp.tm_year = v6;
}
else
{
tp.tm_year = v6 + 100;
}
v7 = v1[4];
if ( v7 )
{
v8 = *_ctype_b_loc();
while ( (v8[v7] & 0x800) != 0 )
{
v7 = *++v5;
if ( !*v5 )
goto LABEL_21;
}
for ( ; *v5 && *v5 <= 32; ++v5 )
;
}
LABEL_21:
tp.tm_hour = atoi(v5);
v9 = *v5;
if ( *v5 )
{
v10 = *_ctype_b_loc();
while ( (v10[v9] & 0x800) != 0 )
{
v9 = *++v5;
if ( !*v5 )
goto LABEL_59;
}
v5 += -(v9 == 0) + 1;
}
LABEL_59:
tp.tm_min = atoi(v5);
v11 = *v5;
if ( !*v5 )
{
tp.tm_sec = atoi(v5);
LABEL_69:
j = *v5;
goto LABEL_74;
}
v12 = *_ctype_b_loc();
while ( (v12[v11] & 0x800) != 0 )
{
v11 = *++v5;
if ( !*v5 )
goto LABEL_65;
}
v5 += -(v11 == 0) + 1;
LABEL_65:
tp.tm_sec = atoi(v5);
v13 = *v5;
if ( !*v5 )
goto LABEL_69;
v14 = *_ctype_b_loc();
while ( (v14[v13] & 0x800) != 0 )
{
v13 = *++v5;
if ( !*v5 )
goto LABEL_69;
}
for ( j = *v5; *v5 && j <= 32; j = *v5 )
++v5;
LABEL_74:
if ( j )
{
if ( ((*_ctype_b_loc())[j] & 0x800) == 0 && ((j - 43) & 0xFD) != 0 )
{
if ( !strncasecmp(v5, "PDT", 3uLL) )
{
i = -15904;
}
else if ( !strncasecmp(v5, "MDT", 3uLL) )
{
i = -15964;
}
else if ( !strncasecmp(v5, "CDT", 3uLL) )
{
i = -16024;
}
else if ( !strncasecmp(v5, "EDT", 3uLL) )
{
i = -16084;
}
else if ( !strncasecmp(v5, "PST", 3uLL) )
{
i = 16864;
}
else if ( !strncasecmp(v5, "MST", 3uLL) )
{
i = 16804;
}
else if ( !strncasecmp(v5, "CST", 3uLL) )
{
i = 16744;
}
else if ( !strncasecmp(v5, "EST", 3uLL) )
{
i = 16684;
}
}
else
{
v16 = &v5[j == 43];
sprintf(nptra, "%.*s", (*v16 == 45) + 2, v16);
v17 = 15 * atoi(nptra);
v18 = &v16[(*v16 == 45) + 2];
v19 = 4 * v17;
if ( v19 < 0 )
i = v19 - atoi(v18);
else
i = v19 + atoi(v18);
}
}
tp.tm_isdst = -1;
return mktime(&tp);
}

canonical_decompiled_code:
time_t __fastcall func1(char *nptr)
{
char *v1; // rbp
char v2; // bl
const unsigned __int16 *v3; // r12
char v4; // al
const char *v5; // rbx
int v6; // eax
char v7; // bp
const unsigned __int16 *v8; // rax
char v9; // bp
const unsigned __int16 *v10; // rdx
char v11; // bp
const unsigned __int16 *v12; // rdx
char v13; // bp
const unsigned __int16 *v14; // rax
char j; // bp
const char *v16; // rbx
int v17; // eax
const char *v18; // rdi
__int16 v19; // ax
struct tm tp; // [rsp+10h] [rbp-B8h] BYREF
__int64 v22; // [rsp+56h] [rbp-72h]
__int16 i; // [rsp+5Eh] [rbp-6Ah]
char s[32]; // [rsp+60h] [rbp-68h] BYREF
char nptra[72]; // [rsp+80h] [rbp-48h] BYREF

v1 = nptr;
*(_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;
v22 = 0LL;
for ( i = 0; *v1 && *v1 <= 32; ++v1 )
;
v2 = *v1;
if ( *v1 )
{
v3 = *_ctype_b_loc();
while ( (v3[v2] & 0x800) == 0 )
{
v2 = *++v1;
if ( !*v1 )
goto LABEL_9;
}
tp.tm_mday = atoi(v1);
v4 = *v1;
if ( *v1 )
{
while ( (v3[v4] & 0x800) != 0 )
{
v4 = *++v1;
if ( !*v1 )
goto LABEL_13;
}
for ( ; *v1 && *v1 <= 32; ++v1 )
;
}
}
else
{
LABEL_9:
tp.tm_mday = atoi(v1);
}
LABEL_13:
sprintf(s, "%3.3s", v1);
if ( !strcasecmp(s, "jan") )
{
tp.tm_mon = 0;
}
else if ( !strcasecmp(s, "feb") )
{
tp.tm_mon = 1;
}
else if ( !strcasecmp(s, "mar") )
{
tp.tm_mon = 2;
}
else if ( !strcasecmp(s, "apr") )
{
tp.tm_mon = 3;
}
else if ( !strcasecmp(s, "may") )
{
tp.tm_mon = 4;
}
else if ( !strcasecmp(s, "jun") )
{
tp.tm_mon = 5;
}
else if ( !strcasecmp(s, "jul") )
{
tp.tm_mon = 6;
}
else if ( !strcasecmp(s, "aug") )
{
tp.tm_mon = 7;
}
else if ( !strcasecmp(s, "sep") )
{
tp.tm_mon = 8;
}
else if ( !strcasecmp(s, "oct") )
{
tp.tm_mon = 9;
}
else
{
tp.tm_mon = 11 - (strcasecmp(s, "nov") == 0);
}
v5 = v1 + 4;
v6 = atoi(v1 + 4);
if ( v6 > 69 )
{
if ( v6 >= 1901 )
v6 -= 1900;
tp.tm_year = v6;
}
else
{
tp.tm_year = v6 + 100;
}
v7 = v1[4];
if ( v7 )
{
v8 = *_ctype_b_loc();
while ( (v8[v7] & 0x800) != 0 )
{
v7 = *++v5;
if ( !*v5 )
goto LABEL_21;
}
for ( ; *v5 && *v5 <= 32; ++v5 )
;
}
LABEL_21:
tp.tm_hour = atoi(v5);
v9 = *v5;
if ( *v5 )
{
v10 = *_ctype_b_loc();
while ( (v10[v9] & 0x800) != 0 )
{
v9 = *++v5;
if ( !*v5 )
goto LABEL_59;
}
v5 += -(v9 == 0) + 1;
}
LABEL_59:
tp.tm_min = atoi(v5);
v11 = *v5;
if ( !*v5 )
{
tp.tm_sec = atoi(v5);
LABEL_69:
j = *v5;
goto LABEL_74;
}
v12 = *_ctype_b_loc();
while ( (v12[v11] & 0x800) != 0 )
{
v11 = *++v5;
if ( !*v5 )
goto LABEL_65;
}
v5 += -(v11 == 0) + 1;
LABEL_65:
tp.tm_sec = atoi(v5);
v13 = *v5;
if ( !*v5 )
goto LABEL_69;
v14 = *_ctype_b_loc();
while ( (v14[v13] & 0x800) != 0 )
{
v13 = *++v5;
if ( !*v5 )
goto LABEL_69;
}
for ( j = *v5; *v5 && j <= 32; j = *v5 )
++v5;
LABEL_74:
if ( j )
{
if ( ((*_ctype_b_loc())[j] & 0x800) == 0 && ((j - 43) & 0xFD) != 0 )
{
if ( !strncasecmp(v5, "PDT", 3uLL) )
{
i = -15904;
}
else if ( !strncasecmp(v5, "MDT", 3uLL) )
{
i = -15964;
}
else if ( !strncasecmp(v5, "CDT", 3uLL) )
{
i = -16024;
}
else if ( !strncasecmp(v5, "EDT", 3uLL) )
{
i = -16084;
}
else if ( !strncasecmp(v5, "PST", 3uLL) )
{
i = 16864;
}
else if ( !strncasecmp(v5, "MST", 3uLL) )
{
i = 16804;
}
else if ( !strncasecmp(v5, "CST", 3uLL) )
{
i = 16744;
}
else if ( !strncasecmp(v5, "EST", 3uLL) )
{
i = 16684;
}
}
else
{
v16 = &v5[j == 43];
sprintf(nptra, "%.*s", (*v16 == 45) + 2, v16);
v17 = 15 * atoi(nptra);
v18 = &v16[(*v16 == 45) + 2];
v19 = 4 * v17;
if ( v19 < 0 )
i = v19 - atoi(v18);
else
i = v19 + atoi(v18);
}
}
tp.tm_isdst = -1;
return mktime(&tp);
}

original_code:
when_t rfc822date(char* date)
{
 char* p=date;
 char str[32];
 char month[32];
 when_t when;
 struct tm tm;
 memset(&tm,0,sizeof(tm));
 memset(&when,0,sizeof(when));
 while(*p && *p<=' ') p++;
 while(*p && !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) p++;
 tm.tm_mday=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) p++;
 while(*p && *p<=' ') p++;
 sprintf(month,"%3.3s",p);
 if(!strcasecmp(month,"jan"))
  tm.tm_mon=0;
 else if(!strcasecmp(month,"feb"))
  tm.tm_mon=1;
 else if(!strcasecmp(month,"mar"))
  tm.tm_mon=2;
 else if(!strcasecmp(month,"apr"))
  tm.tm_mon=3;
 else if(!strcasecmp(month,"may"))
  tm.tm_mon=4;
 else if(!strcasecmp(month,"jun"))
  tm.tm_mon=5;
 else if(!strcasecmp(month,"jul"))
  tm.tm_mon=6;
 else if(!strcasecmp(month,"aug"))
  tm.tm_mon=7;
 else if(!strcasecmp(month,"sep"))
  tm.tm_mon=8;
 else if(!strcasecmp(month,"oct"))
  tm.tm_mon=9;
 else if(!strcasecmp(month,"nov"))
  tm.tm_mon=10;
 else
  tm.tm_mon=11;
 p+=4;
 tm.tm_year=atoi(p);
 if(tm.tm_year<70)
  tm.tm_year+=100;
 else if(tm.tm_year>1900)
  tm.tm_year-=1900;
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) p++;
 while(*p && *p<=' ') p++;
 tm.tm_hour=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) p++;
 if(*p) p++;
 tm.tm_min=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) p++;
 if(*p) p++;
 tm.tm_sec=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) p++;
 while(*p && *p<=' ') p++;
 if(*p) {
  if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) || *p=='-' || *p=='+') {
   if(*p=='+') p++;
   sprintf(str,"%.*s",*p=='-'? 3:2,p);
   when.zone=atoi(str)*60;
   p+=(*p=='-') ? 3:2;
   if(when.zone<0)
    when.zone-=atoi(p);
   else
    when.zone+=atoi(p);
  }
  else if(!strncasecmp(p,"PDT",3))
   when.zone=(short)0xC1E0;
  else if(!strncasecmp(p,"MDT",3))
   when.zone=(short)0xC1A4;
  else if(!strncasecmp(p,"CDT",3))
   when.zone=(short)0xC168;
  else if(!strncasecmp(p,"EDT",3))
   when.zone=(short)0xC12C;
  else if(!strncasecmp(p,"PST",3))
   when.zone=(short)0x41E0;
  else if(!strncasecmp(p,"MST",3))
   when.zone=(short)0x41A4;
  else if(!strncasecmp(p,"CST",3))
   when.zone=(short)0x4168;
  else if(!strncasecmp(p,"EST",3))
   when.zone=(short)0x412C;
 }
 tm.tm_isdst=-1;
 when.time=mktime(&tm);
 return(when);
}

canonical_original_code:
struct when_t rfc822date(char *date)
{
 char *p = date;
 char str[32];
 char month[32];
 struct when_t when;
 struct tm tm;
 memset(&tm,0,sizeof(tm));
 memset(&when,0,sizeof(when));
 while(*p && *p<=' ') p++;
 while(*p && !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) p++;
 tm.tm_mday=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) p++;
 while(*p && *p<=' ') p++;
 sprintf(month,"%3.3s",p);
 if(!strcasecmp(month,"jan"))
  tm.tm_mon=0;
 else if(!strcasecmp(month,"feb"))
  tm.tm_mon=1;
 else if(!strcasecmp(month,"mar"))
  tm.tm_mon=2;
 else if(!strcasecmp(month,"apr"))
  tm.tm_mon=3;
 else if(!strcasecmp(month,"may"))
  tm.tm_mon=4;
 else if(!strcasecmp(month,"jun"))
  tm.tm_mon=5;
 else if(!strcasecmp(month,"jul"))
  tm.tm_mon=6;
 else if(!strcasecmp(month,"aug"))
  tm.tm_mon=7;
 else if(!strcasecmp(month,"sep"))
  tm.tm_mon=8;
 else if(!strcasecmp(month,"oct"))
  tm.tm_mon=9;
 else if(!strcasecmp(month,"nov"))
  tm.tm_mon=10;
 else
  tm.tm_mon=11;
 p+=4;
 tm.tm_year=atoi(p);
 if(tm.tm_year<70)
  tm.tm_year+=100;
 else if(tm.tm_year>1900)
  tm.tm_year-=1900;
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) p++;
 while(*p && *p<=' ') p++;
 tm.tm_hour=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) p++;
 if(*p) p++;
 tm.tm_min=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) p++;
 if(*p) p++;
 tm.tm_sec=atoi(p);
 while(*p && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) p++;
 while(*p && *p<=' ') p++;
 if(*p) {
  if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) || *p=='-' || *p=='+') {
   if(*p=='+') p++;
   sprintf(str,"%.*s",*p=='-'? 3:2,p);
   when.zone=atoi(str)*60;
   p+=(*p=='-') ? 3:2;
   if(when.zone<0)
    when.zone-=atoi(p);
   else
    when.zone+=atoi(p);
  }
  else if(!strncasecmp(p,"PDT",3))
   when.zone=(short)0xC1E0;
  else if(!strncasecmp(p,"MDT",3))
   when.zone=(short)0xC1A4;
  else if(!strncasecmp(p,"CDT",3))
   when.zone=(short)0xC168;
  else if(!strncasecmp(p,"EDT",3))
   when.zone=(short)0xC12C;
  else if(!strncasecmp(p,"PST",3))
   when.zone=(short)0x41E0;
  else if(!strncasecmp(p,"MST",3))
   when.zone=(short)0x41A4;
  else if(!strncasecmp(p,"CST",3))
   when.zone=(short)0x4168;
  else if(!strncasecmp(p,"EST",3))
   when.zone=(short)0x412C;
 }
 tm.tm_isdst=-1;
 when.time=mktime(&tm);
 return(when);
}

variable_types:
date
char *

variable_types:
p
char *

variable_types:
str
char [32]

variable_types:
month
char [32]

return_type: struct when_t { unsigned long time; short zone; }

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


decompiled_code:
void __fastcall edit_table(int a1)
{
const char *v1; // rdx
const char *v2; // rdx
int v3; // eax
char v4[1024]; // [rsp+0h] [rbp-458h] BYREF
_BYTE *v5[11]; // [rsp+400h] [rbp-58h] BYREF

while ( 1 )
{
v1 = enabled;
if ( (tables[2 * a1] & 1) == 0 )
v1 = disabled[0];
sprintf(v4, "Computer Player: %s", v1);
v5[0] = strdup(v4);
v2 = enabled;
if ( (tables[2 * a1] & 2) == 0 )
v2 = disabled[0];
sprintf(v4, "Password Protection: %s", v2);
v5[1] = strdup(v4);
sprintf(v4, "Ante: %d", (unsigned int)SWORD1(tables[2 * a1]));
v5[2] = strdup(v4);
sprintf(v4, "Bet Limit: %d", (unsigned int)SWORD2(tables[2 * a1]));
v5[3] = strdup(v4);
sprintf(v4, "Table Limit: %d", tables[2 * a1 + 1]);
v5[4] = strdup(v4);
v5[5] = strdup(&s);
sprintf(v4, "Table %d Options", (unsigned int)(a1 + 1));
v3 = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, void *, void *, char *, _BYTE **))uifc[1039])(
3078LL,
0LL,
0LL,
0LL,
&opt_1,
&bar_0,
v4,
v5);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 0:
LOWORD(tables[2 * a1]) ^= 1u;
break;
case 1:
LOWORD(tables[2 * a1]) ^= 2u;
break;
case 2:
sprintf(v4, "%d", (unsigned int)SWORD1(tables[2 * a1]));
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Ante",
v4,
4LL,
132LL) != -1 )
WORD1(tables[2 * a1]) = atoi(v4);
if ( (tables[2 * a1] & 0x80000000LL) != 0 )
WORD1(tables[2 * a1]) = 0;
break;
case 3:
sprintf(v4, "%d", (unsigned int)SWORD2(tables[2 * a1]));
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Bet Limit",
v4,
4LL,
132LL) != -1 )
WORD2(tables[2 * a1]) = atoi(v4);
if ( SWORD2(tables[2 * a1]) <= 0 )
WORD2(tables[2 * a1]) = 1;
break;
case 4:
sprintf(v4, "%d", tables[2 * a1 + 1]);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Table Limit",
v4,
10LL,
132LL) != -1 )
tables[2 * a1 + 1] = atoi(v4);
if ( !tables[2 * a1 + 1] )
tables[2 * a1 + 1] = 1LL;
break;
default:
break;
}
free_opts(v5);
}
free_opts(v5);
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
const char *v1; // rdx
const char *v2; // rdx
int v3; // eax
char v4[1024]; // [rsp+0h] [rbp-458h] BYREF
_BYTE *v5[11]; // [rsp+400h] [rbp-58h] BYREF

while ( 1 )
{
v1 = enabled;
if ( (tables[2 * a1] & 1) == 0 )
v1 = disabled[0];
sprintf(v4, "Computer Player: %s", v1);
v5[0] = strdup(v4);
v2 = enabled;
if ( (tables[2 * a1] & 2) == 0 )
v2 = disabled[0];
sprintf(v4, "Password Protection: %s", v2);
v5[1] = strdup(v4);
sprintf(v4, "Ante: %d", (unsigned int)SWORD1(tables[2 * a1]));
v5[2] = strdup(v4);
sprintf(v4, "Bet Limit: %d", (unsigned int)SWORD2(tables[2 * a1]));
v5[3] = strdup(v4);
sprintf(v4, "Table Limit: %d", tables[2 * a1 + 1]);
v5[4] = strdup(v4);
v5[5] = strdup(&s);
sprintf(v4, "Table %d Options", (unsigned int)(a1 + 1));
v3 = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, void *, void *, char *, _BYTE **))uifc[1039])(
3078LL,
0LL,
0LL,
0LL,
&opt_1,
&bar_0,
v4,
v5);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 0:
LOWORD(tables[2 * a1]) ^= 1u;
break;
case 1:
LOWORD(tables[2 * a1]) ^= 2u;
break;
case 2:
sprintf(v4, "%d", (unsigned int)SWORD1(tables[2 * a1]));
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Ante",
v4,
4LL,
132LL) != -1 )
WORD1(tables[2 * a1]) = atoi(v4);
if ( (tables[2 * a1] & 0x80000000LL) != 0 )
WORD1(tables[2 * a1]) = 0;
break;
case 3:
sprintf(v4, "%d", (unsigned int)SWORD2(tables[2 * a1]));
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Bet Limit",
v4,
4LL,
132LL) != -1 )
WORD2(tables[2 * a1]) = atoi(v4);
if ( SWORD2(tables[2 * a1]) <= 0 )
WORD2(tables[2 * a1]) = 1;
break;
case 4:
sprintf(v4, "%d", tables[2 * a1 + 1]);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Table Limit",
v4,
10LL,
132LL) != -1 )
tables[2 * a1 + 1] = atoi(v4);
if ( !tables[2 * a1 + 1] )
tables[2 * a1 + 1] = 1LL;
break;
default:
break;
}
func2(v5);
}
func2(v5);
}

original_code:
void edit_table(int table)
{
 char *opts[6];
 char str[1024];
 int i;
 static int opt=0;
 static int bar=0;
 while(1) {
  sprintf(str,"Computer Player:     %s",tables[table].options&(1<<0)?enabled:disabled);
  opts[0]=strdup(str);
  sprintf(str,"Password Protection: %s",tables[table].options&(1<<1)?enabled:disabled);
  opts[1]=strdup(str);
  sprintf(str,"Ante:                %d",tables[table].ante);
  opts[2]=strdup(str);
  sprintf(str,"Bet Limit:           %d",tables[table].bet_limit);
  opts[3]=strdup(str);
  sprintf(str,"Table Limit:         %d",tables[table].max_total);
  opts[4]=strdup(str);
  opts[5]=strdup("");
  sprintf(str,"Table %d Options",table+1);
  i=uifc.list((1<<1)|(1<<11)|(1<<10)|(1<<2),0,0,0,&opt,&bar,str,opts);
  if(i==-1) {
   free_opts(opts);
   break;
  }
  switch(i) {
   case 0:
    tables[table].options ^= (1<<0);
    break;
   case 1:
    tables[table].options ^= (1<<1);
    break;
   case 2:
    sprintf(str,"%d",tables[table].ante);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Ante",str,4,(1L<<7)|(1L<<2))!=-1)
     tables[table].ante=atoi(str);
    if(tables[table].ante<0)
     tables[table].ante=0;
    break;
   case 3:
    sprintf(str,"%d",tables[table].bet_limit);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Bet Limit",str,4,(1L<<7)|(1L<<2))!=-1)
     tables[table].bet_limit=atoi(str);
    if(tables[table].bet_limit<1)
     tables[table].bet_limit=1;
    break;
   case 4:
    sprintf(str,"%d",tables[table].max_total);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Table Limit",str,10,(1L<<7)|(1L<<2))!=-1)
     tables[table].max_total=atoi(str);
    if(tables[table].max_total<1)
     tables[table].max_total=1;
    break;
  }
  free_opts(opts);
 }
}

canonical_original_code:
void edit_table(int table)
{
 char *opts[6];
 char str[1024];
 int i;
 static int opt = 0;
 static int bar = 0;
 while(1) {
  sprintf(str,"Computer Player:     %s",tables[table].options&(1<<0)?enabled:disabled);
  opts[0]=strdup(str);
  sprintf(str,"Password Protection: %s",tables[table].options&(1<<1)?enabled:disabled);
  opts[1]=strdup(str);
  sprintf(str,"Ante:                %d",tables[table].ante);
  opts[2]=strdup(str);
  sprintf(str,"Bet Limit:           %d",tables[table].bet_limit);
  opts[3]=strdup(str);
  sprintf(str,"Table Limit:         %d",tables[table].max_total);
  opts[4]=strdup(str);
  opts[5]=strdup("");
  sprintf(str,"Table %d Options",table+1);
  i=uifc.list((1<<1)|(1<<11)|(1<<10)|(1<<2),0,0,0,&opt,&bar,str,opts);
  if(i==-1) {
   free_opts(opts);
   break;
  }
  switch(i) {
   case 0:
    tables[table].options ^= (1<<0);
    break;
   case 1:
    tables[table].options ^= (1<<1);
    break;
   case 2:
    sprintf(str,"%d",tables[table].ante);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Ante",str,4,(1L<<7)|(1L<<2))!=-1)
     tables[table].ante=atoi(str);
    if(tables[table].ante<0)
     tables[table].ante=0;
    break;
   case 3:
    sprintf(str,"%d",tables[table].bet_limit);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Bet Limit",str,4,(1L<<7)|(1L<<2))!=-1)
     tables[table].bet_limit=atoi(str);
    if(tables[table].bet_limit<1)
     tables[table].bet_limit=1;
    break;
   case 4:
    sprintf(str,"%d",tables[table].max_total);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Table Limit",str,10,(1L<<7)|(1L<<2))!=-1)
     tables[table].max_total=atoi(str);
    if(tables[table].max_total<1)
     tables[table].max_total=1;
    break;
  }
  free_opts(opts);
 }
}

variable_types: table int

variable_types:
opts
char *[6]

variable_types:
str
char [1024]

variable_types: i int

variable_types: opt int

variable_types: bar int


decompiled_code:
void __fastcall free_opts(_BYTE **a1)
{
_BYTE *v2; // rdi
_BYTE **v3; // rbx

v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
while ( *v2 )
{
free(v2);
v2 = *v3++;
if ( !v2 )
return;
}
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func2(_BYTE **a1)
{
_BYTE *v2; // rdi
_BYTE **v3; // rbx

v2 = *a1;
if ( v2 )
{
v3 = a1 + 1;
while ( *v2 )
{
free(v2);
v2 = *v3++;
if ( !v2 )
return;
}
free(v2);
}
}

original_code:
void free_opts(char **opts)
{
 int i;
 for(i=0; opts[i]!=((void *)0) && opts[i][0]; i++) {
  free(opts[i]);
 }
 if(opts[i]!=((void *)0))
  free(opts[i]);
}

variable_types:
opts
char **


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er13
_BYTE **v5; // rbp
int v6; // eax
int v8; // ebx
int v9; // ebx
int v10; // [rsp+Ch] [rbp-48Ch] BYREF
__int64 v11[4]; // [rsp+10h] [rbp-488h] BYREF
int v12; // [rsp+34h] [rbp-464h] BYREF
int v13; // [rsp+38h] [rbp-460h] BYREF
int v14; // [rsp+3Ch] [rbp-45Ch] BYREF
char s[1024]; // [rsp+40h] [rbp-458h] BYREF
_BYTE *v16[11]; // [rsp+440h] [rbp-58h] BYREF

v14 = 0;
v13 = 0;
v12 = 0;
v11[0] = (__int64)"Yes";
v11[1] = (__int64)"No";
v11[2] = (__int64)&::s;
read_ini();
memset(uifc, 0, sizeof(uifc));
uifc[0] = 8384LL;
HIDWORD(uifc[4]) = 25;
v3 = uifcini32(uifc);
v4 = v3;
v10 = v3;
if ( v3 )
{
fprintf(stderr, "uifc library init returned error %d\n", v3);
v4 = -1;
}
else
{
if ( ((unsigned int (__fastcall *)(const char *))uifc[1036])("Domain Poker Config") )
{
printf(" USCRN (len=%d) failed!\n", (unsigned int)(HIDWORD(uifc[3]) + 1));
((void (*)(void))uifc[1035])();
}
v5 = (_BYTE **)malloc(0xD0uLL);
if ( v5 )
{
while ( 1 )
{
sprintf(s, "Computer Player's Name: %s", comp_name);
v16[0] = strdup(s);
sprintf(s, "Number of Tables: %d", (unsigned int)num_tables);
v16[1] = strdup(s);
sprintf(s, "Time allow playing computer: %d", time_allowed);
v16[2] = strdup(s);
sprintf(s, "Percentage house takes from pot: %d%%", (unsigned int)skim);
v16[3] = strdup(s);
v16[4] = strdup("Table configuration...");
v16[5] = strdup(&::s);
switch ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, int *, _QWORD, const char *, _BYTE **))uifc[1039])(
25LL,
0LL,
0LL,
0LL,
&v14,
0LL,
"Main Options",
v16) )
{
case 0xFFFFFFFF:
v10 = 0;
v6 = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, int *, _QWORD, const char *, __int64 *))uifc[1039])(
24LL,
0LL,
0LL,
0LL,
&v10,
0LL,
"Save Changes?",
v11);
if ( v6 )
{
if ( v6 != 1 )
goto LABEL_13;
}
else
{
write_ini();
v4 = 0;
}
return v4;
case 0u:
((void (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Computer's Name",
comp_name,
40LL,
128LL);
goto LABEL_13;
case 1u:
sprintf(s, "%d", (unsigned int)num_tables);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Number of Tables",
s,
2LL,
132LL) != -1 )
num_tables = atoi(s);
if ( num_tables <= 25 )
{
if ( num_tables <= 0 )
num_tables = 1;
}
else
{
num_tables = 25;
}
goto LABEL_13;
case 2u:
sprintf(s, "%d", time_allowed);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Time allowed computer",
s,
5LL,
132LL) != -1 )
time_allowed = atoi(s);
if ( (unsigned __int64)time_allowed > 0x15180 )
time_allowed = 86400LL;
goto LABEL_13;
case 3u:
sprintf(s, "%d", (unsigned int)skim);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Percentage to house",
s,
2LL,
132LL) != -1 )
skim = atoi(s);
if ( skim < 0 )
{
skim = 0;
}
else if ( skim > 50 )
{
skim = 50;
}
goto LABEL_13;
case 4u:
while ( 1 )
{
v10 = 0;
if ( num_tables <= 0 )
{
v8 = v4;
}
else
{
v8 = v4;
do
{
sprintf(s, "Table %d", (unsigned int)(v8 + 1));
v9 = v10;
v5[v9] = strdup(s);
v8 = v9 + 1;
v10 = v8;
}
while ( v8 < num_tables );
}
v5[v8] = strdup(&::s);
v10 = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, int *, int *, const char *, _BYTE **))uifc[1039])(
485LL,
0LL,
0LL,
0LL,
&v13,
&v12,
"Table Options",
v5);
if ( v10 == -1 )
break;
if ( num_tables == v13 )
v10 = v13 | 0x10000000;
if ( (v10 & 0x10000000) != 0 )
{
if ( num_tables <= 24 )
{
++num_tables;
memcpy(&tables[2 * v13 + 2], &tables[2 * v13], 16LL * (24 - v13));
}
}
else if ( (v10 & 0x20000000) != 0 )
{
if ( num_tables > 1 )
{
--num_tables;
memcpy(&tables[2 * v13], &tables[2 * v13 + 2], 16LL * (24 - v13));
LOWORD(tables[48]) = 1;
WORD1(tables[48]) = 250;
WORD2(tables[48]) = 250;
tables[49] = 1000LL;
}
}
else
{
edit_table(v13);
}
free_opts(v5);
}
free_opts(v5);
goto LABEL_13;
default:
LABEL_13:
free_opts(v16);
break;
}
}
}
fwrite("MALLOC() error!\r\n", 1uLL, 0x11uLL, stderr);
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er13
_BYTE **v5; // rbp
int v6; // eax
int v8; // ebx
int v9; // ebx
int v10; // [rsp+Ch] [rbp-48Ch] BYREF
__int64 v11[4]; // [rsp+10h] [rbp-488h] BYREF
int v12; // [rsp+34h] [rbp-464h] BYREF
int v13; // [rsp+38h] [rbp-460h] BYREF
int v14; // [rsp+3Ch] [rbp-45Ch] BYREF
char s[1024]; // [rsp+40h] [rbp-458h] BYREF
_BYTE *v16[11]; // [rsp+440h] [rbp-58h] BYREF

v14 = 0;
v13 = 0;
v12 = 0;
v11[0] = (__int64)"Yes";
v11[1] = (__int64)"No";
v11[2] = (__int64)&::s;
func0();
memset(uifc, 0, sizeof(uifc));
uifc[0] = 8384LL;
HIDWORD(uifc[4]) = 25;
v3 = uifcini32(uifc);
v4 = v3;
v10 = v3;
if ( v3 )
{
fprintf(stderr, "uifc library init returned error %d\n", v3);
v4 = -1;
}
else
{
if ( ((unsigned int (__fastcall *)(const char *))uifc[1036])("Domain Poker Config") )
{
printf(" USCRN (len=%d) failed!\n", (unsigned int)(HIDWORD(uifc[3]) + 1));
((void (*)(void))uifc[1035])();
}
v5 = (_BYTE **)malloc(0xD0uLL);
if ( v5 )
{
while ( 1 )
{
sprintf(s, "Computer Player's Name: %s", comp_name);
v16[0] = strdup(s);
sprintf(s, "Number of Tables: %d", (unsigned int)num_tables);
v16[1] = strdup(s);
sprintf(s, "Time allow playing computer: %d", time_allowed);
v16[2] = strdup(s);
sprintf(s, "Percentage house takes from pot: %d%%", (unsigned int)skim);
v16[3] = strdup(s);
v16[4] = strdup("Table configuration...");
v16[5] = strdup(&::s);
switch ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, int *, _QWORD, const char *, _BYTE **))uifc[1039])(
25LL,
0LL,
0LL,
0LL,
&v14,
0LL,
"Main Options",
v16) )
{
case 0xFFFFFFFF:
v10 = 0;
v6 = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, int *, _QWORD, const char *, __int64 *))uifc[1039])(
24LL,
0LL,
0LL,
0LL,
&v10,
0LL,
"Save Changes?",
v11);
if ( v6 )
{
if ( v6 != 1 )
goto LABEL_13;
}
else
{
func1();
v4 = 0;
}
return v4;
case 0u:
((void (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Computer's Name",
comp_name,
40LL,
128LL);
goto LABEL_13;
case 1u:
sprintf(s, "%d", (unsigned int)num_tables);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Number of Tables",
s,
2LL,
132LL) != -1 )
num_tables = atoi(s);
if ( num_tables <= 25 )
{
if ( num_tables <= 0 )
num_tables = 1;
}
else
{
num_tables = 25;
}
goto LABEL_13;
case 2u:
sprintf(s, "%d", time_allowed);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Time allowed computer",
s,
5LL,
132LL) != -1 )
time_allowed = atoi(s);
if ( (unsigned __int64)time_allowed > 0x15180 )
time_allowed = 86400LL;
goto LABEL_13;
case 3u:
sprintf(s, "%d", (unsigned int)skim);
if ( ((unsigned int (__fastcall *)(__int64, _QWORD, _QWORD, const char *, char *, __int64, __int64))uifc[1040])(
26LL,
0LL,
0LL,
"Percentage to house",
s,
2LL,
132LL) != -1 )
skim = atoi(s);
if ( skim < 0 )
{
skim = 0;
}
else if ( skim > 50 )
{
skim = 50;
}
goto LABEL_13;
case 4u:
while ( 1 )
{
v10 = 0;
if ( num_tables <= 0 )
{
v8 = v4;
}
else
{
v8 = v4;
do
{
sprintf(s, "Table %d", (unsigned int)(v8 + 1));
v9 = v10;
v5[v9] = strdup(s);
v8 = v9 + 1;
v10 = v8;
}
while ( v8 < num_tables );
}
v5[v8] = strdup(&::s);
v10 = ((__int64 (__fastcall *)(__int64, _QWORD, _QWORD, _QWORD, int *, int *, const char *, _BYTE **))uifc[1039])(
485LL,
0LL,
0LL,
0LL,
&v13,
&v12,
"Table Options",
v5);
if ( v10 == -1 )
break;
if ( num_tables == v13 )
v10 = v13 | 0x10000000;
if ( (v10 & 0x10000000) != 0 )
{
if ( num_tables <= 24 )
{
++num_tables;
memcpy(&tables[2 * v13 + 2], &tables[2 * v13], 16LL * (24 - v13));
}
}
else if ( (v10 & 0x20000000) != 0 )
{
if ( num_tables > 1 )
{
--num_tables;
memcpy(&tables[2 * v13], &tables[2 * v13 + 2], 16LL * (24 - v13));
LOWORD(tables[48]) = 1;
WORD1(tables[48]) = 250;
WORD2(tables[48]) = 250;
tables[49] = 1000LL;
}
}
else
{
func3(v13);
}
func2(v5);
}
func2(v5);
goto LABEL_13;
default:
LABEL_13:
func2(v16);
break;
}
}
}
fwrite("MALLOC() error!\r\n", 1uLL, 0x11uLL, stderr);
v4 = 1;
}
return v4;
}

original_code:
int main(int argc, char **argv)
{
 char *opts[6];
 char **topts;
 char str[1024];
 int opt=0;
 int topt=0;
 int tbar=0;
 char *YesNo[3]={"Yes","No",""};
 int i;
 read_ini();
    memset(&uifc,0,sizeof(uifc));
 uifc.size=sizeof(uifc);
 uifc.esc_delay=25;
 if((i=uifcini32(&uifc))!=0) {
  fprintf(stderr,"uifc library init returned error %d\n",i);
  return(-1);
 }
 if(uifc.scrn("Domain Poker Config")) {
  printf(" USCRN (len=%d) failed!\n",uifc.scrn_len+1);
  uifc.bail();
 }
 topts=(char **)malloc(sizeof(char *)*(25 +1));
 if(topts==((void *)0)) {
  fprintf(stderr,"MALLOC() error!\r\n");
  return(1);
 }
 while(1) {
  sprintf(str,"Computer Player's Name:          %s",comp_name);
  opts[0]=strdup(str);
  sprintf(str,"Number of Tables:                %d",num_tables);
  opts[1]=strdup(str);
  sprintf(str,"Time allow playing computer:     %d",time_allowed);
  opts[2]=strdup(str);
  sprintf(str,"Percentage house takes from pot: %d%%",skim);
  opts[3]=strdup(str);
  opts[4]=strdup("Table configuration...");
  opts[5]=strdup("");
  switch(uifc.list((1<<0)|(1<<3)|(1<<4),0,0,0,&opt,((void *)0),"Main Options",opts)) {
   case -1:
    i=0;
    switch(uifc.list((1<<3)|(1<<4),0,0,0,&i,((void *)0),"Save Changes?",YesNo)) {
     case 0:
      write_ini();
     case 1:
      return(0);
    }
    break;
   case 0:
    uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Computer's Name",comp_name,sizeof(comp_name)-1,(1L<<7));
    break;
   case 1:
    sprintf(str,"%d",num_tables);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Number of Tables",str,2,(1L<<7)|(1L<<2))!=-1)
     num_tables=atoi(str);
    if(num_tables>25)
     num_tables=25;
    if(num_tables<1)
     num_tables=1;
    break;
   case 2:
    sprintf(str,"%d",time_allowed);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Time allowed computer",str,5,(1L<<7)|(1L<<2))!=-1)
     time_allowed=atoi(str);
    if(time_allowed>86400 || time_allowed<0)
     time_allowed=86400;
    break;
   case 3:
    sprintf(str,"%d",skim);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Percentage to house",str,2,(1L<<7)|(1L<<2))!=-1)
     skim=atoi(str);
    if(skim<0)
     skim=0;
    if(skim>50)
     skim=50;
    break;
   case 4:
    while(1) {
     for(i=0;i<num_tables;i++) {
      sprintf(str,"Table %d",i+1);
      topts[i]=strdup(str);
     }
     topts[i]=strdup("");
     i=uifc.list((1<<0)|(1<<7)|(1<<5)|(1<<2)|(1<<8)|(1<<6),0,0,0,&topt,&tbar,"Table Options",topts);
     if(i==-1) {
      free_opts(topts);
      break;
     }
     if(topt==num_tables)
      i=topt|0x10000000;
     if(i&0x10000000) {
      if(num_tables<25) {
       num_tables++;
       memcpy(&tables[topt+1],&tables[topt],sizeof(tables[topt])*(25 -topt-1));
      }
     }
     else if(i&0x20000000) {
      if(num_tables>1) {
       num_tables--;
       memcpy(&tables[topt],&tables[topt+1],sizeof(tables[topt])*(25 -topt-1));
       tables[25 -1].options=(1<<0);
       tables[25 -1].ante=250;
       tables[25 -1].bet_limit=250;
       tables[25 -1].max_total=1000;
      }
     }
     else {
      edit_table(topt);
     }
     free_opts(topts);
    }
    break;
  }
  free_opts(opts);
 }
 return(1);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *opts[6];
 char **topts;
 char str[1024];
 int opt = 0;
 int topt = 0;
 int tbar = 0;
 char *YesNo[3] = {"Yes","No",""};
 int i;
 read_ini();
    memset(&uifc,0,sizeof(uifc));
 uifc.size=sizeof(uifc);
 uifc.esc_delay=25;
 if((i=uifcini32(&uifc))!=0) {
  fprintf(stderr,"uifc library init returned error %d\n",i);
  return(-1);
 }
 if(uifc.scrn("Domain Poker Config")) {
  printf(" USCRN (len=%d) failed!\n",uifc.scrn_len+1);
  uifc.bail();
 }
 topts=(char **)malloc(sizeof(char *)*(25 +1));
 if(topts==((void *)0)) {
  fprintf(stderr,"MALLOC() error!\r\n");
  return(1);
 }
 while(1) {
  sprintf(str,"Computer Player's Name:          %s",comp_name);
  opts[0]=strdup(str);
  sprintf(str,"Number of Tables:                %d",num_tables);
  opts[1]=strdup(str);
  sprintf(str,"Time allow playing computer:     %d",time_allowed);
  opts[2]=strdup(str);
  sprintf(str,"Percentage house takes from pot: %d%%",skim);
  opts[3]=strdup(str);
  opts[4]=strdup("Table configuration...");
  opts[5]=strdup("");
  switch(uifc.list((1<<0)|(1<<3)|(1<<4),0,0,0,&opt,((void *)0),"Main Options",opts)) {
   case -1:
    i=0;
    switch(uifc.list((1<<3)|(1<<4),0,0,0,&i,((void *)0),"Save Changes?",YesNo)) {
     case 0:
      write_ini();
     case 1:
      return(0);
    }
    break;
   case 0:
    uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Computer's Name",comp_name,sizeof(comp_name)-1,(1L<<7));
    break;
   case 1:
    sprintf(str,"%d",num_tables);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Number of Tables",str,2,(1L<<7)|(1L<<2))!=-1)
     num_tables=atoi(str);
    if(num_tables>25)
     num_tables=25;
    if(num_tables<1)
     num_tables=1;
    break;
   case 2:
    sprintf(str,"%d",time_allowed);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Time allowed computer",str,5,(1L<<7)|(1L<<2))!=-1)
     time_allowed=atoi(str);
    if(time_allowed>86400 || time_allowed<0)
     time_allowed=86400;
    break;
   case 3:
    sprintf(str,"%d",skim);
    if(uifc.input((1<<3)|(1<<4)|(1<<1),0,0,"Percentage to house",str,2,(1L<<7)|(1L<<2))!=-1)
     skim=atoi(str);
    if(skim<0)
     skim=0;
    if(skim>50)
     skim=50;
    break;
   case 4:
    while(1) {
     for(i=0;i<num_tables;i++) {
      sprintf(str,"Table %d",i+1);
      topts[i]=strdup(str);
     }
     topts[i]=strdup("");
     i=uifc.list((1<<0)|(1<<7)|(1<<5)|(1<<2)|(1<<8)|(1<<6),0,0,0,&topt,&tbar,"Table Options",topts);
     if(i==-1) {
      free_opts(topts);
      break;
     }
     if(topt==num_tables)
      i=topt|0x10000000;
     if(i&0x10000000) {
      if(num_tables<25) {
       num_tables++;
       memcpy(&tables[topt+1],&tables[topt],sizeof(tables[topt])*(25 -topt-1));
      }
     }
     else if(i&0x20000000) {
      if(num_tables>1) {
       num_tables--;
       memcpy(&tables[topt],&tables[topt+1],sizeof(tables[topt])*(25 -topt-1));
       tables[25 -1].options=(1<<0);
       tables[25 -1].ante=250;
       tables[25 -1].bet_limit=250;
       tables[25 -1].max_total=1000;
      }
     }
     else {
      edit_table(topt);
     }
     free_opts(topts);
    }
    break;
  }
  free_opts(opts);
 }
 return(1);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
topts
char **

variable_types: topt int

variable_types: tbar int

variable_types:
YesNo
char *[3]


viewscroll

decompiled_code:
void viewscroll()
{
unsigned int v0; // ebx
unsigned int v1; // ebp
char *v2; // r13
int v3; // ebp
signed int v4; // ebx
int v5; // eax
char v6[7]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v7; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v8; // [rsp+Dh] [rbp-2Bh]

ciolib_gettextinfo(v6);
v0 = v8;
v1 = v7;
v2 = (char *)malloc(2 * v8 * (v7 + 1000));
memcpy(v2, *((const void **)&cterm + 265), (int)(2000 * v0));
ciolib_gettext(1LL, 1LL, v0, v1, &v2[2 * *((_DWORD *)&cterm + 1) * *((_DWORD *)&cterm + 532)]);
v3 = *((_DWORD *)&cterm + 532);
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
LABEL_19:
if ( v3 <= 0 )
v3 = 1;
if ( *((_DWORD *)&cterm + 532) <= v3 )
v3 = *((_DWORD *)&cterm + 532);
ciolib_puttext(1LL, 1LL, v8, v7, &v2[2 * v3 * v8]);
v5 = ciolib_getch();
if ( v5 <= 108 )
break;
if ( v5 == 255 )
goto LABEL_2;
}
if ( v5 <= 71 )
break;
switch ( v5 )
{
case 'H':
case 'h':
v3 -= v7;
break;
case 'J':
case 'j':
--v3;
break;
case 'K':
case 'k':
++v3;
break;
case 'L':
case 'l':
v3 += v7;
break;
default:
goto LABEL_19;
}
}
if ( v5 )
break;
LABEL_2:
v4 = ((unsigned int)ciolib_getch() << 8) | v5;
if ( v4 == 20480 )
{
++v3;
}
else if ( v4 > 20480 )
{
if ( v4 == 20736 )
v3 += v7;
}
else if ( v4 == 18432 )
{
--v3;
}
else if ( v4 == 18688 )
{
v3 -= v7;
}
}
}
while ( v5 != 27 );
free(v2);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // ebx
unsigned int v1; // ebp
char *v2; // r13
int v3; // ebp
signed int v4; // ebx
int v5; // eax
char v6[7]; // [rsp+5h] [rbp-33h] BYREF
unsigned __int8 v7; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v8; // [rsp+Dh] [rbp-2Bh]

ciolib_gettextinfo(v6);
v0 = v8;
v1 = v7;
v2 = (char *)malloc(2 * v8 * (v7 + 1000));
memcpy(v2, *((const void **)&cterm + 265), (int)(2000 * v0));
ciolib_gettext(1LL, 1LL, v0, v1, &v2[2 * *((_DWORD *)&cterm + 1) * *((_DWORD *)&cterm + 532)]);
v3 = *((_DWORD *)&cterm + 532);
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
LABEL_19:
if ( v3 <= 0 )
v3 = 1;
if ( *((_DWORD *)&cterm + 532) <= v3 )
v3 = *((_DWORD *)&cterm + 532);
ciolib_puttext(1LL, 1LL, v8, v7, &v2[2 * v3 * v8]);
v5 = ciolib_getch();
if ( v5 <= 108 )
break;
if ( v5 == 255 )
goto LABEL_2;
}
if ( v5 <= 71 )
break;
switch ( v5 )
{
case 'H':
case 'h':
v3 -= v7;
break;
case 'J':
case 'j':
--v3;
break;
case 'K':
case 'k':
++v3;
break;
case 'L':
case 'l':
v3 += v7;
break;
default:
goto LABEL_19;
}
}
if ( v5 )
break;
LABEL_2:
v4 = ((unsigned int)ciolib_getch() << 8) | v5;
if ( v4 == 20480 )
{
++v3;
}
else if ( v4 > 20480 )
{
if ( v4 == 20736 )
v3 += v7;
}
else if ( v4 == 18432 )
{
--v3;
}
else if ( v4 == 18688 )
{
v3 -= v7;
}
}
}
while ( v5 != 27 );
free(v2);
}

original_code:
void viewscroll(void)
{
 int top;
 int key;
 int i;
 char *scrollback;
 struct text_info txtinfo;
    ciolib_gettextinfo(&txtinfo);
 scrollback=(char *)malloc((txtinfo.screenwidth*2*1000)+(txtinfo.screenheight*txtinfo.screenwidth*2));
 memcpy(scrollback,cterm.scrollback,txtinfo.screenwidth*2*1000);
 ciolib_gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrollback+(cterm.backpos)*cterm.width*2);
 top=cterm.backpos;
 for(i=0;!i;) {
  if(top<1)
   top=1;
  if(top>cterm.backpos)
   top=cterm.backpos;
  ciolib_puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrollback+(txtinfo.screenwidth*2*top));
  key=ciolib_getch();
  switch(key) {
   case 0xff:
   case 0:
    switch(key|ciolib_getch()<<8) {
     case (72 << 8):
      top--;
      break;
     case (80 << 8):
      top++;
      break;
     case (0x49 << 8):
      top-=txtinfo.screenheight;
      break;
     case (0x51 << 8):
      top+=txtinfo.screenheight;
      break;
    }
    break;
   case 'j':
   case 'J':
    top--;
    break;
   case 'k':
   case 'K':
    top++;
    break;
   case 'h':
   case 'H':
    top-=txtinfo.screenheight;
    break;
   case 'l':
   case 'L':
    top+=txtinfo.screenheight;
    break;
   case '\033':
    i=1;
    break;
  }
 }
 free(scrollback);
 return;
}

canonical_original_code:
void viewscroll()
{
 int top;
 int key;
 int i;
 char *scrollback;
 struct text_info txtinfo;
    ciolib_gettextinfo(&txtinfo);
 scrollback=(char *)malloc((txtinfo.screenwidth*2*1000)+(txtinfo.screenheight*txtinfo.screenwidth*2));
 memcpy(scrollback,cterm.scrollback,txtinfo.screenwidth*2*1000);
 ciolib_gettext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrollback+(cterm.backpos)*cterm.width*2);
 top=cterm.backpos;
 for(i=0;!i;) {
  if(top<1)
   top=1;
  if(top>cterm.backpos)
   top=cterm.backpos;
  ciolib_puttext(1,1,txtinfo.screenwidth,txtinfo.screenheight,scrollback+(txtinfo.screenwidth*2*top));
  key=ciolib_getch();
  switch(key) {
   case 0xff:
   case 0:
    switch(key|ciolib_getch()<<8) {
     case (72 << 8):
      top--;
      break;
     case (80 << 8):
      top++;
      break;
     case (0x49 << 8):
      top-=txtinfo.screenheight;
      break;
     case (0x51 << 8):
      top+=txtinfo.screenheight;
      break;
    }
    break;
   case 'j':
   case 'J':
    top--;
    break;
   case 'k':
   case 'K':
    top++;
    break;
   case 'h':
   case 'H':
    top-=txtinfo.screenheight;
    break;
   case 'l':
   case 'L':
    top+=txtinfo.screenheight;
    break;
   case '\033':
    i=1;
    break;
  }
 }
 free(scrollback);
 return;
}

variable_types: top int

variable_types: key int

variable_types:
scrollback
char *

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


lfexpand

decompiled_code:
void *__fastcall lfexpand(void *dest, int *a2)
{
void *v2; // r8
char *v4; // rdx
char *v5; // rdi
int v6; // ecx
char v7; // si
int v8; // eax
char v10[2056]; // [rsp+0h] [rbp-808h] BYREF

v2 = dest;
if ( *a2 <= 0 )
{
v6 = 0;
}
else
{
v4 = (char *)dest;
v5 = (char *)dest + (unsigned int)(*a2 - 1) + 1;
v6 = 0;
do
{
v7 = *v4;
v8 = v6;
if ( *v4 == 10 )
{
v8 = v6 + 1;
v10[v6] = 13;
}
v6 = v8 + 1;
v10[v8] = v7;
++v4;
}
while ( v4 != v5 );
}
*a2 = v6;
return memcpy(v2, v10, v6);
}

original_code:
void lfexpand(char *buf, int *len)
{
 char newbuf[1024*2];
 int newlen=0;
 int i;
 for(i=0; i<*len; i++) {
  if(buf[i]=='\n') {
   newbuf[newlen++]='\r';
  }
  newbuf[newlen++]=buf[i];
 }
 *len=newlen;
 memcpy(buf, newbuf, newlen);
 return;
}

canonical_original_code:
void lfexpand(char *buf, int *len)
{
 char newbuf[-1];
 int newlen = 0;
 int i;
 for(i=0; i<*len; i++) {
  if(buf[i]=='\n') {
   newbuf[newlen++]='\r';
  }
  newbuf[newlen++]=buf[i];
 }
 *len=newlen;
 memcpy(buf, newbuf, newlen);
 return;
}

variable_types:
buf
char *

variable_types:
len
int *

variable_types:
newbuf
char [-1]

variable_types: newlen int