decompiled_code:
char *__fastcall Str_Dup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)Mem_Malloc(v1 + 1, "Str_Dup()");
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)func0(v1 + 1, "Str_Dup()");
return strcpy(v2, src);
}

original_code:
char *Str_Dup( const char *s) {
  char *p;
  p = (char *)Mem_Malloc(strlen(s)+1, "Str_Dup()");
  strcpy(p, s);
  return p;
}

canonical_original_code:
char *Str_Dup(char *s) {
  char *p;
  p = (char *)Mem_Malloc(strlen(s)+1, "Str_Dup()");
  strcpy(p, s);
  return p;
}

variable_types:
s
char *

variable_types:
p
char *


decompiled_code:
void *__fastcall Mem_ReAlloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 || !a2 )
_assert_fail("p != NULL && sizeNew > 0", "mymemory.c", 0xC3u, "Mem_ReAlloc");
result = realloc(a1, a2);
if ( !result )
{
LogError(stderr, 12LL, "realloc failed in Mem_ReAlloc()");
result = a1;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

if ( !a1 || !a2 )
_assert_fail("p != NULL && sizeNew > 0", "mymemory.c", 0xC3u, "Mem_ReAlloc");
result = realloc(a1, a2);
if ( !result )
{
LogError(stderr, 12LL, "realloc failed in Mem_ReAlloc()");
result = a1;
}
return result;
}

original_code:
void *Mem_ReAlloc( void *block, size_t sizeNew) {
  byte *p = (byte *)block,
       *pNew;
  ((void) sizeof ((p != ((void *)0) && sizeNew > 0) ? 1 : 0), __extension__ ({ if (p != ((void *)0) && sizeNew > 0) ; else __assert_fail ("p != NULL && sizeNew > 0", "mymemory.c", 195, __extension__ __PRETTY_FUNCTION__); }));
   pNew = (byte *)realloc(p, sizeNew);
   if (pNew != ((void *)0)) {
       p = pNew;
   } else
       LogError(stderr, 0x0c,"realloc failed in Mem_ReAlloc()");
   return p;
}

canonical_original_code:
void *Mem_ReAlloc(void *block, unsigned long sizeNew) {
  unsigned char *p = (byte *)block; unsigned char *pNew;
  ((void) sizeof ((p != ((void *)0) && sizeNew > 0) ? 1 : 0), __extension__ ({ if (p != ((void *)0) && sizeNew > 0) ; else __assert_fail ("p != NULL && sizeNew > 0", "mymemory.c", 195, __extension__ __PRETTY_FUNCTION__); }));
   pNew = (unsigned char *)realloc(p, sizeNew);
   if (pNew != ((void *)0)) {
       p = pNew;
   } else
       LogError(stderr, 0x0c,"realloc failed in Mem_ReAlloc()");
   return p;
}

variable_types:
block
void *

variable_types:
sizeNew
unsigned long

variable_types:
p
unsigned char *

variable_types:
pNew
unsigned char *

return_type: void *


decompiled_code:
// attributes: thunk
void Mem_Free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

original_code:
void Mem_Free( void *block) {
  free(block);
}

canonical_original_code:
void Mem_Free(void *block) {
  free(block);
}

return_type: void


decompiled_code:
void *__fastcall Mem_Set(void *a1, unsigned __int8 a2, size_t a3)
{
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func4(void *a1, unsigned __int8 a2, size_t a3)
{
return memset(a1, a2, a3);
}

original_code:
void Mem_Set( void *block, byte c, size_t n) {
  memset(block, (int) c, n);
}

canonical_original_code:
void Mem_Set(void *block, unsigned char c, unsigned long n) {
  memset(block, (int) c, n);
}

variable_types:
c
unsigned char

variable_types:
n
unsigned long


decompiled_code:
void *__fastcall Mem_Calloc(__int64 a1, __int64 a2, const char *a3)
{
void *v3; // r12

v3 = Mem_Malloc(a1 * a2, a3);
Mem_Set(v3, 0, a1 * a2);
return v3;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, __int64 a2, const char *a3)
{
void *v3; // r12

v3 = func0(a1 * a2, a3);
func4(v3, 0, a1 * a2);
return v3;
}

original_code:
void *Mem_Calloc( size_t nobjs, size_t size, const char *funcname) {
  void *p;
  p = Mem_Malloc( size * nobjs, funcname);
    Mem_Set(p, 0, size * nobjs);
  return p;
}

canonical_original_code:
void *Mem_Calloc(unsigned long nobjs, unsigned long size, char *funcname) {
  void *p;
  p = Mem_Malloc( size * nobjs, funcname);
    Mem_Set(p, 0, size * nobjs);
  return p;
}

variable_types:
nobjs
unsigned long

variable_types:
size
unsigned long

variable_types:
funcname
char *

variable_types:
p
void *


decompiled_code:
// attributes: thunk
void *Mem_Copy(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

canonical_decompiled_code:
void *func6(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

original_code:
void Mem_Copy( void *dest, const void *src, size_t n) {
  memcpy(dest, src, n);
}

canonical_original_code:
void Mem_Copy(void *dest, void *src, unsigned long n) {
  memcpy(dest, src, n);
}

variable_types:
dest
void *

variable_types:
src
void *


init

decompiled_code:
int __fastcall init(char *src)
{
char *v1; // rax
char *v2; // rbp
char *v3; // r12
__int128 v5; // [rsp+0h] [rbp-218h] BYREF
char v6[496]; // [rsp+10h] [rbp-208h] BYREF

LODWORD(v1) = 0;
v2 = src;
v3 = InFiles;
v5 = 0LL;
memset(v6, 0, sizeof(v6));
if ( InFiles )
{
if ( src )
{
LODWORD(v1) = strcmp(src, InFiles);
if ( (_DWORD)v1 )
{
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, src);
if ( (_BYTE)v5 )
{
Mem_Free(v3);
LABEL_8:
v1 = (char *)Str_Dup(&v5);
InFiles = v1;
return (int)v1;
}
}
}
}
else
{
if ( !src )
v2 = "files.in";
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, v2);
if ( (_BYTE)v5 )
goto LABEL_8;
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func0(char *src)
{
char *v1; // rax
char *v2; // rbp
char *v3; // r12
__int128 v5; // [rsp+0h] [rbp-218h] BYREF
char v6[496]; // [rsp+10h] [rbp-208h] BYREF

LODWORD(v1) = 0;
v2 = src;
v3 = InFiles;
v5 = 0LL;
memset(v6, 0, sizeof(v6));
if ( InFiles )
{
if ( src )
{
LODWORD(v1) = strcmp(src, InFiles);
if ( (_DWORD)v1 )
{
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, src);
if ( (_BYTE)v5 )
{
Mem_Free(v3);
LABEL_8:
v1 = (char *)Str_Dup(&v5);
InFiles = v1;
return (int)v1;
}
}
}
}
else
{
if ( !src )
v2 = "files.in";
LODWORD(v1) = (unsigned int)strcpy((char *)&v5, v2);
if ( (_BYTE)v5 )
goto LABEL_8;
}
return (int)v1;
}

original_code:
static void init(const char *s) {
  char fname[512] = {'\0'};
  if (((void *)0) == InFiles[eFirst])
    strcpy(fname,(s ? s :"files.in"));
  else if (s && strcmp(s, InFiles[eFirst]))
    strcpy(fname, s);
  if (*fname) {
    if (!(((void *)0) == (InFiles[eFirst]))) Mem_Free(InFiles[eFirst]);
    InFiles[eFirst] = Str_Dup(fname);
  }
}

canonical_original_code:
static void init(char *s) {
  char fname[512] = {'\0'};
  if (((void *)0) == InFiles[eFirst])
    strcpy(fname,(s ? s :"files.in"));
  else if (s && strcmp(s, InFiles[eFirst]))
    strcpy(fname, s);
  if (*fname) {
    if (!(((void *)0) == (InFiles[eFirst]))) Mem_Free(InFiles[eFirst]);
    InFiles[eFirst] = Str_Dup(fname);
  }
}

variable_types:
fname
char [512]


decompiled_code:
char *__fastcall SW_F_name(int a1)
{
return (&InFiles)[a1];
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
return (&InFiles)[a1];
}

original_code:
char *SW_F_name( SW_FileIndex i) {
    return InFiles[i];
}

canonical_original_code:
char *SW_F_name(enum SW_FileIndex i) {
    return InFiles[i];
}

variable_types: enum SW_FileIndex { eNoFile=-1, eFirst=0, eModel=1, eLog=2, eSite=3, eLayers=4, eWeather=5, eMarkovProb=6, eMarkovCov=7, eSky=8, eVegProd=9, eVegEstab=10, eSoilwat=11, eOutput=12, eEndFile=13 }

return_type: char *


decompiled_code:
const char *__fastcall SW_F_construct(char *a1)
{
char *v1; // rbx
const char *result; // rax
char i; // dl

v1 = a1;
init(a1);
result = (const char *)DirName(a1);
if ( result )
{
result = &a1[stpcpy(&ProjDir, result) - &ProjDir];
for ( i = *result; *result; i = *result )
{
++result;
*v1++ = i;
}
*v1 = 0;
}
else
{
ProjDir = 0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(char *a1)
{
char *v1; // rbx
const char *result; // rax
char i; // dl

v1 = a1;
func0(a1);
result = (const char *)DirName(a1);
if ( result )
{
result = &a1[stpcpy(&ProjDir, result) - &ProjDir];
for ( i = *result; *result; i = *result )
{
++result;
*v1++ = i;
}
*v1 = 0;
}
else
{
ProjDir = 0;
}
return result;
}

original_code:
void SW_F_construct(const char *firstfile) {
  char *c, *p;
  init(firstfile);
  if ((c=DirName(firstfile)) ) {
    strcpy(_ProjDir, c);
    c = (char *) firstfile;
    p = c + strlen(_ProjDir);
    while(*p) *(c++) = *(p++);
    *c = '\0';
  } else
    _ProjDir[0] = '\0';
}

canonical_original_code:
void SW_F_construct(char *firstfile) {
  char *c; char *p;
  init(firstfile);
  if ((c=DirName(firstfile)) ) {
    strcpy(_ProjDir, c);
    c = (char *) firstfile;
    p = c + strlen(_ProjDir);
    while(*p) *(c++) = *(p++);
    *c = '\0';
  } else
    _ProjDir[0] = '\0';
}

variable_types:
firstfile
char *

variable_types:
c
char *


decompiled_code:
char *__fastcall SW_WeatherPrefix(char *a1)
{
return strcpy(a1, weather_prefix);
}

canonical_decompiled_code:
char *__fastcall func4(char *a1)
{
return strcpy(a1, weather_prefix);
}

original_code:
void SW_WeatherPrefix(char prefix[]){
 strcpy(prefix, weather_prefix);
}

variable_types:
prefix
char []


decompiled_code:
char *__fastcall SW_OutputPrefix(char *a1)
{
char *result; // rax

if ( *(_WORD *)output_prefix != 47 )
return strcpy(a1, output_prefix);
*a1 = 0;
return result;
}

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

if ( *(_WORD *)output_prefix != 47 )
return strcpy(a1, output_prefix);
*a1 = 0;
return result;
}

original_code:
void SW_OutputPrefix(char prefix[]){
 if(strcmp(output_prefix, "/") == 0)
  prefix[0] = '\0';
 else
  strcpy(prefix, output_prefix);
}


decompiled_code:
void check_log(void)
{
if ( (struct _IO_FILE *)logfp != stdout && (struct _IO_FILE *)logfp != stderr )
{
if ( logged && !QuietMode )
{
fwrite("\nCheck logfile for error or status messages.\n", 1uLL, 0x2DuLL, stderr);
CloseFile(&logfp);
}
else
{
CloseFile(&logfp);
}
}
}

canonical_decompiled_code:
void func0(void)
{
if ( (struct _IO_FILE *)logfp != stdout && (struct _IO_FILE *)logfp != stderr )
{
if ( logged && !QuietMode )
{
fwrite("\nCheck logfile for error or status messages.\n", 1uLL, 0x2DuLL, stderr);
CloseFile(&logfp);
}
else
{
CloseFile(&logfp);
}
}
}

original_code:
static void check_log(void) {
if (logfp != stdout && logfp != stderr) {
if (logged && !QuietMode)
fprintf(stderr, "\nCheck logfile for error or status messages.\n");
CloseFile(&logfp);
}
}

canonical_original_code:
static void check_log() {
if (logfp != stdout && logfp != stderr) {
if (logged && !QuietMode)
fprintf(stderr, "\nCheck logfile for error or status messages.\n");
CloseFile(&logfp);
}
}


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"Soil water model version 2.2a (SGS-LTER Oct-2003).\n"
"Usage: soilwat [-d startdir] [-f files.in] [-e] [-q]\n"
" -d : operate (chdir) in startdir (default=.)\n"
" -f : supply list of input files (default=files.in)\n"
" a preceeding path applies to all input files\n"
" -e : echo initial values from site and estab to logfile\n"
" -q : quiet mode, don't print message to check logfile.\n",
1uLL,
0x173uLL,
stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
fwrite(
"Soil water model version 2.2a (SGS-LTER Oct-2003).\n"
"Usage: soilwat [-d startdir] [-f files.in] [-e] [-q]\n"
" -d : operate (chdir) in startdir (default=.)\n"
" -f : supply list of input files (default=files.in)\n"
" a preceeding path applies to all input files\n"
" -e : echo initial values from site and estab to logfile\n"
" -q : quiet mode, don't print message to check logfile.\n",
1uLL,
0x173uLL,
stderr);
exit(0);
}

original_code:
static void usage(void) {
char *s1="Soil water model version 2.2a (SGS-LTER Oct-2003).\n"
"Usage: soilwat [-d startdir] [-f files.in] [-e] [-q]\n"
"  -d : operate (chdir) in startdir (default=.)\n"
"  -f : supply list of input files (default=files.in)\n"
"       a preceeding path applies to all input files\n"
"  -e : echo initial values from site and estab to logfile\n"
"  -q : quiet mode, don't print message to check logfile.\n";
fprintf(stderr,"%s", s1);
exit(0);
}

canonical_original_code:
static void usage() {
char *s1 = "Soil water model version 2.2a (SGS-LTER Oct-2003).\n"
"Usage: soilwat [-d startdir] [-f files.in] [-e] [-q]\n"
"  -d : operate (chdir) in startdir (default=.)\n"
"  -f : supply list of input files (default=files.in)\n"
"       a preceeding path applies to all input files\n"
"  -e : echo initial values from site and estab to logfile\n"
"  -q : quiet mode, don't print message to check logfile.\n";
fprintf(stderr,"%s", s1);
exit(0);
}


decompiled_code:
__int64 __fastcall init_args(int a1, __int64 a2)
{
int v2; // er12
int v3; // ebp
__int64 result; // rax
__int64 v5; // r13
const char *v6; // r15
const char *v7; // r14
const char *v8; // rsi
__int64 v10[6]; // [rsp+20h] [rbp-468h]
char dest[1080]; // [rsp+50h] [rbp-438h] BYREF

v2 = 4;
v3 = 1;
firstfile[8] = 0;
v10[0] = 0x100000001LL;
result = 0x6E692E73656C6966LL;
v10[3] = (__int64)"-f";
v10[4] = (__int64)"-e";
v10[5] = (__int64)"-q";
v10[1] = 0LL;
*(_QWORD *)firstfile = 0x6E692E73656C6966LL;
EchoInits = 0;
QuietMode = 0;
do
{
if ( a1 <= v3 )
break;
v5 = 0LL;
v6 = "-d";
v7 = *(const char **)(a2 + 8LL * v3);
while ( strncmp(v6, v7, 2uLL) )
{
if ( ++v5 == 4 )
{
fprintf(stderr, "Invalid option %s\n", v7);
usage();
}
v6 = (const char *)v10[v5 + 2];
}
dest[0] = 0;
result = *((unsigned int *)v10 + (int)v5);
if ( (_DWORD)result )
{
if ( v7[2] )
{
result = (__int64)strcpy(dest, v7 + 2);
}
else
{
v8 = *(const char **)(a2 + 8LL * v3 + 8);
if ( *v8 == 45 )
{
if ( (int)result > 0 )
{
fprintf(stderr, "Incomplete option %s\n", v6);
usage();
}
}
else
{
++v3;
result = (__int64)strcpy(dest, v8);
}
}
}
switch ( (_DWORD)v5 )
{
case 2:
EchoInits = 1;
break;
case 3:
QuietMode = 1;
break;
case 1:
result = (__int64)strcpy(firstfile, dest);
break;
default:
result = ChDir(dest);
if ( !(_DWORD)result )
result = LogError(stderr, 12LL, "Invalid project directory (%s)", dest);
break;
}
++v3;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
int v2; // er12
int v3; // ebp
__int64 result; // rax
__int64 v5; // r13
const char *v6; // r15
const char *v7; // r14
const char *v8; // rsi
__int64 v10[6]; // [rsp+20h] [rbp-468h]
char dest[1080]; // [rsp+50h] [rbp-438h] BYREF

v2 = 4;
v3 = 1;
firstfile[8] = 0;
v10[0] = 0x100000001LL;
result = 0x6E692E73656C6966LL;
v10[3] = (__int64)"-f";
v10[4] = (__int64)"-e";
v10[5] = (__int64)"-q";
v10[1] = 0LL;
*(_QWORD *)firstfile = 0x6E692E73656C6966LL;
EchoInits = 0;
QuietMode = 0;
do
{
if ( a1 <= v3 )
break;
v5 = 0LL;
v6 = "-d";
v7 = *(const char **)(a2 + 8LL * v3);
while ( strncmp(v6, v7, 2uLL) )
{
if ( ++v5 == 4 )
{
fprintf(stderr, "Invalid option %s\n", v7);
func1();
}
v6 = (const char *)v10[v5 + 2];
}
dest[0] = 0;
result = *((unsigned int *)v10 + (int)v5);
if ( (_DWORD)result )
{
if ( v7[2] )
{
result = (__int64)strcpy(dest, v7 + 2);
}
else
{
v8 = *(const char **)(a2 + 8LL * v3 + 8);
if ( *v8 == 45 )
{
if ( (int)result > 0 )
{
fprintf(stderr, "Incomplete option %s\n", v6);
func1();
}
}
else
{
++v3;
result = (__int64)strcpy(dest, v8);
}
}
}
switch ( (_DWORD)v5 )
{
case 2:
EchoInits = 1;
break;
case 3:
QuietMode = 1;
break;
case 1:
result = (__int64)strcpy(firstfile, dest);
break;
default:
result = ChDir(dest);
if ( !(_DWORD)result )
result = LogError(stderr, 12LL, "Invalid project directory (%s)", dest);
break;
}
++v3;
--v2;
}
while ( v2 );
return result;
}

original_code:
static void init_args(int argc, char **argv) {
char str[1024],
*opts[] = {"-d","-f","-e", "-q"};
int valopts[] = { 1, 1, 0, 0 };
int i,
a,
op,
nopts=sizeof(opts)/sizeof(char *);
strcpy(_firstfile, "files.in");
QuietMode = EchoInits = FALSE;
a=1;
for( i=1; i<=nopts; i++) {
if (a >= argc) break;
for(op=0; op<nopts; op++) {
if (strncmp(opts[op], argv[a], 2) == 0)
break;
}
if (op==nopts) {
fprintf(stderr, "Invalid option %s\n", argv[a]);
usage();
exit(-1);
}
*str = '\0';
if ( valopts[op] ) {
if ('\0' != argv[a][2]) {
strcpy(str, (argv[a]+2));
} else if ('-' != *argv[a+1]) {
strcpy(str, argv[++a]);
} else if ( 0 < valopts[op]) {
fprintf(stderr, "Incomplete option %s\n", opts[op]);
usage();
exit(-1);
}
}
switch (op) {
case 0:
if (!ChDir(str)) {
LogError(stderr, 0x0c, "Invalid project directory (%s)",str);
}
break;
case 1:
strcpy(_firstfile, str); break;
case 2:
EchoInits = TRUE; break;
case 3:
QuietMode = TRUE; break;
default:
LogError(logfp, 0x0c, "Programmer: bad option in main:init_args:switch");
}
a++;
}
}

canonical_original_code:
static void init_args(int argc, char **argv) {
char str[1024]; char *opts[] = {"-d","-f","-e", "-q"};
int valopts[] = { 1, 1, 0, 0 };
int i; int a; int op; int nopts = sizeof(opts)/sizeof(char *);
strcpy(_firstfile, "files.in");
QuietMode = EchoInits = FALSE;
a=1;
for( i=1; i<=nopts; i++) {
if (a >= argc) break;
for(op=0; op<nopts; op++) {
if (strncmp(opts[op], argv[a], 2) == 0)
break;
}
if (op==nopts) {
fprintf(stderr, "Invalid option %s\n", argv[a]);
usage();
exit(-1);
}
*str = '\0';
if ( valopts[op] ) {
if ('\0' != argv[a][2]) {
strcpy(str, (argv[a]+2));
} else if ('-' != *argv[a+1]) {
strcpy(str, argv[++a]);
} else if ( 0 < valopts[op]) {
fprintf(stderr, "Incomplete option %s\n", opts[op]);
usage();
exit(-1);
}
}
switch (op) {
case 0:
if (!ChDir(str)) {
LogError(stderr, 0x0c, "Invalid project directory (%s)",str);
}
break;
case 1:
strcpy(_firstfile, str); break;
case 2:
EchoInits = TRUE; break;
case 3:
QuietMode = TRUE; break;
default:
LogError(logfp, 0x0c, "Programmer: bad option in main:init_args:switch");
}
a++;
}
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
str
char [1024]

variable_types:
opts
char *[]

variable_types:
valopts
int []

variable_types: i int

variable_types: a int

variable_types: op int

variable_types: nopts int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
logged = 0;
atexit(check_log);
logfp = (__int64)stdout;
init_args(argc, (__int64)argv);
SW_CTL_init_model(firstfile);
SW_CTL_main();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
logged = 0;
atexit(check_log);
logfp = (__int64)stdout;
func2(argc, (__int64)argv);
SW_CTL_init_model(firstfile);
SW_CTL_main();
return 0;
}

original_code:
int main ( int argc, char **argv) {
logged = FALSE;
atexit(check_log);
logfp = stdout;
init_args(argc, argv);
SW_CTL_init_model(_firstfile);
SW_CTL_main();
return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
logged = FALSE;
atexit(check_log);
logfp = stdout;
init_args(argc, argv);
SW_CTL_init_model(_firstfile);
SW_CTL_main();
return 0;
}

return_type: int


decompiled_code:
__int64 SW_CTL_init_model()
{
SW_F_construct();
SW_MDL_construct();
SW_WTH_construct();
SW_SIT_construct();
SW_VES_construct();
SW_VPD_construct();
SW_OUT_construct();
SW_SWC_construct();
return read_inputs();
}

canonical_decompiled_code:
__int64 func5()
{
SW_F_construct();
SW_MDL_construct();
SW_WTH_construct();
SW_SIT_construct();
SW_VES_construct();
SW_VPD_construct();
SW_OUT_construct();
SW_SWC_construct();
return func0();
}

original_code:
void SW_CTL_init_model(const char *firstfile) {
  SW_F_construct(firstfile);
  SW_MDL_construct();
  SW_WTH_construct();
  SW_SIT_construct();
  SW_VES_construct();
  SW_VPD_construct();
  SW_OUT_construct();
  SW_SWC_construct();
  _read_inputs();
}

canonical_original_code:
void SW_CTL_init_model(char *firstfile) {
  SW_F_construct(firstfile);
  SW_MDL_construct();
  SW_WTH_construct();
  SW_SIT_construct();
  SW_VES_construct();
  SW_VPD_construct();
  SW_OUT_construct();
  SW_SWC_construct();
  _read_inputs();
}


decompiled_code:
__int64 SW_CTL_run_current_year()
{
unsigned int v0; // eax
bool v1; // cc
unsigned int v2; // eax

begin_year();
v0 = SW_Model[5];
v1 = v0 <= SW_Model[6];
for ( SW_Model[7] = v0; v1; SW_Model[7] = v2 )
{
begin_day();
SW_SWC_water_flow();
if ( SW_VegEstab )
SW_VES_checkestab();
end_day();
v2 = SW_Model[7] + 1;
v1 = v2 <= SW_Model[6];
}
return SW_OUT_flush();
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
bool v1; // cc
unsigned int v2; // eax

func1();
v0 = SW_Model[5];
v1 = v0 <= SW_Model[6];
for ( SW_Model[7] = v0; v1; SW_Model[7] = v2 )
{
func2();
SW_SWC_water_flow();
if ( SW_VegEstab )
SW_VES_checkestab();
func4();
v2 = SW_Model[7] + 1;
v1 = v2 <= SW_Model[6];
}
return SW_OUT_flush();
}

original_code:
void SW_CTL_run_current_year(void) {
  TimeInt *doy = &SW_Model.doy;
    _begin_year();
    for ( *doy = SW_Model.firstdoy;
          *doy <= SW_Model.lastdoy;
         (*doy)++)
    {
       _begin_day();
       SW_SWC_water_flow();
       if (SW_VegEstab.use) SW_VES_checkestab();
       _end_day();
    }
    SW_OUT_flush();
}

canonical_original_code:
void SW_CTL_run_current_year() {
  unsigned int *doy = &SW_Model.doy;
    _begin_year();
    for ( *doy = SW_Model.firstdoy;
          *doy <= SW_Model.lastdoy;
         (*doy)++)
    {
       _begin_day();
       SW_SWC_water_flow();
       if (SW_VegEstab.use) SW_VES_checkestab();
       _end_day();
    }
    SW_OUT_flush();
}

variable_types:
doy
unsigned int *


decompiled_code:
__int64 SW_CTL_main()
{
bool v0; // cc
unsigned int v1; // eax

v0 = SW_Model[0] <= SW_Model[1];
for ( SW_Model[10] = SW_Model[0]; v0; SW_Model[10] = v1 )
{
SW_CTL_run_current_year();
v1 = SW_Model[10] + 1;
v0 = v1 <= SW_Model[1];
}
return SW_OUT_close_files();
}

canonical_decompiled_code:
__int64 func7()
{
bool v0; // cc
unsigned int v1; // eax

v0 = SW_Model[0] <= SW_Model[1];
for ( SW_Model[10] = SW_Model[0]; v0; SW_Model[10] = v1 )
{
func6();
v1 = SW_Model[10] + 1;
v0 = v1 <= SW_Model[1];
}
return SW_OUT_close_files();
}

original_code:
void SW_CTL_main(void) {
  TimeInt *cur_yr = &SW_Model.year;
  for ( *cur_yr = SW_Model.startyr;
        *cur_yr <= SW_Model.endyr;
        (*cur_yr)++)
  {
     SW_CTL_run_current_year();
  }
  SW_OUT_close_files();
}

canonical_original_code:
void SW_CTL_main() {
  unsigned int *cur_yr = &SW_Model.year;
  for ( *cur_yr = SW_Model.startyr;
        *cur_yr <= SW_Model.endyr;
        (*cur_yr)++)
  {
     SW_CTL_run_current_year();
  }
  SW_OUT_close_files();
}


decompiled_code:
__int64 SW_MDL_construct()
{
Time_init();
*(&SW_Model + 11) = 0;
*((_QWORD *)&SW_Model + 6) = 0LL;
return RandSeed(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
Time_init();
*(&SW_Model + 11) = 0;
*((_QWORD *)&SW_Model + 6) = 0LL;
return RandSeed(0LL);
}

original_code:
void SW_MDL_construct(void) {
  SW_MODEL *m = &SW_Model;
  Time_init();
  m->newweek = m->newmonth = m->newyear = FALSE;
    RandSeed(0);
}

canonical_original_code:
void SW_MDL_construct() {
  struct SW_MODEL *m = &SW_Model;
  Time_init();
  m->newweek = m->newmonth = m->newyear = FALSE;
    RandSeed(0);
}

variable_types: struct SW_MODEL { unsigned int startyr; enum Bool { FALSE=expr, TRUE=expr } newweek; enum Bool { FALSE=expr, TRUE=expr } isnorth; } *

user_defined_types: struct SW_MODEL { unsigned int startyr; enum Bool newweek; enum Bool isnorth; }


decompiled_code:
__int64 SW_MDL_new_year()
{
unsigned int v0; // ebx
int v1; // eax
bool v2; // zf
__int64 result; // rax

v0 = SW_Model[10];
prevmonth = 0xFFFF;
prevweek = 0xFFFF;
Time_new_year(v0);
v1 = 1;
if ( SW_Model[0] == v0 )
v1 = SW_Model[2];
v2 = SW_Model[1] == v0;
SW_Model[5] = v1;
result = (unsigned int)SW_Model[3];
if ( !v2 )
result = Time_lastDOY();
SW_Model[6] = result;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
int v1; // eax
bool v2; // zf
__int64 result; // rax

v0 = SW_Model[10];
prevmonth = 0xFFFF;
prevweek = 0xFFFF;
Time_new_year(v0);
v1 = 1;
if ( SW_Model[0] == v0 )
v1 = SW_Model[2];
v2 = SW_Model[1] == v0;
SW_Model[5] = v1;
result = (unsigned int)SW_Model[3];
if ( !v2 )
result = Time_lastDOY();
SW_Model[6] = result;
return result;
}

original_code:
void SW_MDL_new_year() {
  SW_MODEL *m = &SW_Model;
  TimeInt year = SW_Model.year;
  _prevweek = _prevmonth = _prevyear = _notime;
  Time_new_year( year);
  m->firstdoy = (year == m->startyr)
              ? m->startstart
              : 1;
  m->lastdoy = (year == m->endyr)
             ? m->endend
             : Time_lastDOY();
}

canonical_original_code:
void SW_MDL_new_year() {
  struct SW_MODEL *m = &SW_Model;
  unsigned int year = SW_Model.year;
  _prevweek = _prevmonth = _prevyear = _notime;
  Time_new_year( year);
  m->firstdoy = (year == m->startyr)
              ? m->startstart
              : 1;
  m->lastdoy = (year == m->endyr)
             ? m->endend
             : Time_lastDOY();
}

variable_types:
year
unsigned int


decompiled_code:
__int64 SW_MDL_new_day()
{
int v0; // eax
__int64 v1; // rdi
__int64 result; // rax
bool v3; // cc
int v4; // ecx
int v5; // edx

v0 = doy2month((unsigned int)SW_Model[7]);
v1 = (unsigned int)SW_Model[7];
SW_Model[9] = v0;
result = doy2week(v1);
v3 = SW_Model[7] <= (unsigned int)SW_Model[6];
SW_Model[8] = result;
if ( v3 )
{
v4 = prevmonth;
if ( SW_Model[9] == prevmonth )
{
SW_Model[12] = 0;
v5 = prevweek;
if ( (_DWORD)result != prevweek )
goto LABEL_4;
}
else
{
prevmonth = SW_Model[9];
v5 = prevweek;
SW_Model[12] = v4 != 0xFFFF;
if ( (_DWORD)result != v5 )
{
LABEL_4:
prevweek = result;
SW_Model[11] = v5 != 0xFFFF;
return result;
}
}
SW_Model[11] = 0;
}
else
{
result = 0x100000001LL;
SW_Model[11] = 1;
*(_QWORD *)&SW_Model[12] = 0x100000001LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
__int64 v1; // rdi
__int64 result; // rax
bool v3; // cc
int v4; // ecx
int v5; // edx

v0 = doy2month((unsigned int)SW_Model[7]);
v1 = (unsigned int)SW_Model[7];
SW_Model[9] = v0;
result = doy2week(v1);
v3 = SW_Model[7] <= (unsigned int)SW_Model[6];
SW_Model[8] = result;
if ( v3 )
{
v4 = prevmonth;
if ( SW_Model[9] == prevmonth )
{
SW_Model[12] = 0;
v5 = prevweek;
if ( (_DWORD)result != prevweek )
goto LABEL_4;
}
else
{
prevmonth = SW_Model[9];
v5 = prevweek;
SW_Model[12] = v4 != 0xFFFF;
if ( (_DWORD)result != v5 )
{
LABEL_4:
prevweek = result;
SW_Model[11] = v5 != 0xFFFF;
return result;
}
}
SW_Model[11] = 0;
}
else
{
result = 0x100000001LL;
SW_Model[11] = 1;
*(_QWORD *)&SW_Model[12] = 0x100000001LL;
}
return result;
}

original_code:
void SW_MDL_new_day(void) {
  SW_Model.month = doy2month(SW_Model.doy);
  SW_Model.week = doy2week(SW_Model.doy);
  if (SW_Model.doy > SW_Model.lastdoy) {
    SW_Model.newyear = SW_Model.newmonth = SW_Model.newweek = TRUE;
    return;
  }
  if (SW_Model.month != _prevmonth) {
    SW_Model.newmonth = (_prevmonth != _notime) ? TRUE : FALSE;
    _prevmonth = SW_Model.month;
  } else
    SW_Model.newmonth = FALSE;
  if (SW_Model.week != _prevweek) {
    SW_Model.newweek = (_prevweek != _notime) ? TRUE : FALSE;
    _prevweek = SW_Model.week;
  } else
    SW_Model.newweek = FALSE;
}

canonical_original_code:
void SW_MDL_new_day() {
  SW_Model.month = doy2month(SW_Model.doy);
  SW_Model.week = doy2week(SW_Model.doy);
  if (SW_Model.doy > SW_Model.lastdoy) {
    SW_Model.newyear = SW_Model.newmonth = SW_Model.newweek = TRUE;
    return;
  }
  if (SW_Model.month != _prevmonth) {
    SW_Model.newmonth = (_prevmonth != _notime) ? TRUE : FALSE;
    _prevmonth = SW_Model.month;
  } else
    SW_Model.newmonth = FALSE;
  if (SW_Model.week != _prevweek) {
    SW_Model.newweek = (_prevweek != _notime) ? TRUE : FALSE;
    _prevweek = SW_Model.week;
  } else
    SW_Model.newweek = FALSE;
}


original_code:
char ticker_sequence(ticker *t) {
        char c;
        int position = t->head + t->cursor;
        if (t->cursor >= t->width) {
                return '\0';
        }
        c = BLUNK_CHAR;
        if (t->width <= position && t->width + t->message_length > position) {
                c = *(t->message + (position - t->width));
        }
        t->cursor++;
        return c;
}

canonical_original_code:
char ticker_sequence(struct ticker *t) {
        char c;
        int position = t->head + t->cursor;
        if (t->cursor >= t->width) {
                return '\0';
        }
        c = BLUNK_CHAR;
        if (t->width <= position && t->width + t->message_length > position) {
                c = *(t->message + (position - t->width));
        }
        t->cursor++;
        return c;
}

variable_types: struct ticker { char *message; int width; int head; int message_length; int cursor; } *

variable_types: c char

variable_types: position int

return_type: char


original_code:
int ticker_forward(ticker *t) {
        if (t->head + 1 > t->message_length + t->width) {
                return 0;
        }
        t->head++;
        t->cursor = 0;
        return 1;
}

canonical_original_code:
int ticker_forward(struct ticker *t) {
        if (t->head + 1 > t->message_length + t->width) {
                return 0;
        }
        t->head++;
        t->cursor = 0;
        return 1;
}

user_defined_types: struct ticker { char *message; int width; int head; int message_length; int cursor; }


decompiled_code:
void __fastcall ticker_rewind(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 20) = 0;
}

original_code:
void ticker_rewind(ticker *t) {
        t->head = 0;
        t->cursor = 0;
}

canonical_original_code:
void ticker_rewind(struct ticker *t) {
        t->head = 0;
        t->cursor = 0;
}


decompiled_code:
void __fastcall ticker_destroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void ticker_destroy(ticker *t) {
        free(t->message);
        free(t);
}

canonical_original_code:
void ticker_destroy(struct ticker *t) {
        free(t->message);
        free(t);
}


repo: dmjio/FiveCardDraw

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi

v3 = time(0LL);
srand(v3);
return start_game(v3, argv);
}

original_code:
int main(int argc, char const *argv[]){
  srand(time(((void *)0)));
  return start_game();
}

canonical_original_code:
int main(int argc, char *argv[]){
  srand(time(((void *)0)));
  return start_game();
}

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall show_hands(__int64 a1, int a2, unsigned int a3)
{
__int64 v4; // rbp
__int64 v5; // rbx
__int64 result; // rax
const char *v7; // rsi

if ( a2 > 0 )
{
v4 = a1 + 40LL * (unsigned int)(a2 - 1) + 40;
v5 = a1;
do
{
while ( 1 )
{
result = *(unsigned int *)(v5 + 24);
if ( (_DWORD)result )
break;
v5 += 40LL;
if ( v5 == v4 )
return result;
}
v7 = *(const char **)(v5 + 16);
v5 += 40LL;
printf("%s", v7);
result = best_hand(*(_QWORD *)(v5 - 40), a3, *(unsigned int *)(v5 - 8));
}
while ( v5 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, unsigned int a3)
{
__int64 v4; // rbp
__int64 v5; // rbx
__int64 result; // rax
const char *v7; // rsi

if ( a2 > 0 )
{
v4 = a1 + 40LL * (unsigned int)(a2 - 1) + 40;
v5 = a1;
do
{
while ( 1 )
{
result = *(unsigned int *)(v5 + 24);
if ( (_DWORD)result )
break;
v5 += 40LL;
if ( v5 == v4 )
return result;
}
v7 = *(const char **)(v5 + 16);
v5 += 40LL;
printf("%s", v7);
result = best_hand(*(_QWORD *)(v5 - 40), a3, *(unsigned int *)(v5 - 8));
}
while ( v5 != v4 );
}
return result;
}

original_code:
void show_hands(Player * players, int player_count, int lastRound){
 int i;
 for (i = 0; i < player_count; ++i) {
  if (players[i].isActive){
   printf("%s", players[i].name);
   best_hand(players[i].hand, lastRound, players[i].isComputer);
  }
 }
}

canonical_original_code:
void show_hands(struct Player *players, int player_count, int lastRound){
 int i;
 for (i = 0; i < player_count; ++i) {
  if (players[i].isActive){
   printf("%s", players[i].name);
   best_hand(players[i].hand, lastRound, players[i].isComputer);
  }
 }
}

variable_types: struct Player { struct Hand { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); } *hand; int isBetter; int hasFolded; char *name; int isActive; int bet; int isComputer; int amount; } *

variable_types: lastRound int

user_defined_types: struct Player { struct Hand *hand; int isBetter; int hasFolded; char *name; int isActive; int bet; int isComputer; int amount; }

user_defined_types: struct Hand { struct Card card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); }


original_code:
void prompt_player(Player * p, Deck * d){
 Card temp;
 int * recommendation = malloc(sizeof(int) * 5);
 char * result = malloc(sizeof(char)*10);
 int i, j, k;
 Exchange * e = malloc(sizeof(Exchange));
 i = j = 0;
 if (!p->hasFolded && p->isActive){
  if (p->isComputer){
   recommendation = compute_expected_value(p->hand, p->isComputer);
   if (recommendation[0] != -1){
    for (i = 0; i < 5; ++i)
     if (recommendation[i]){
      e->card[j++] = p->hand->card[i];
      p->hand->card[i].suite = -1;
      p->hand->card[i].value = -1;
     }
   printf("%s Exchanged: ", p->name);
   for (i = 0; i < j; ++i){
    printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
   }
   printf("\n\t\t     For: ");
   exchange_card(d, e, j);
   for (i = 0; i < j; ++i){
    printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
   }
   insert_exchange_into_hand(e, p->hand, j);
   printf("\n\t\tNew hand: ");
  } else {
   printf("%s Stayed: ", p->name);
  }
   best_hand(p->hand, 0, 0);
   printf("\n");
   free(result);
   free(e);
   free(recommendation);
   return;
  }
  recommendation = compute_expected_value(p->hand, p->isComputer);
  j = 0;
  scanf("%s", result);
  if (!strncmp(result, "y", strlen("y"))){
   for (i = 0; i < 5; ++i){
    if (recommendation[0] == -1)
     goto do_nothing;
    if (recommendation[i]){
     e->card[j++] = p->hand->card[i];
     p->hand->card[i].suite = -1;
     p->hand->card[i].value = -1;
    }
   }
  } else {
   printf("%s, Which cards would you like to exchange? (ex: '1,2,3' or '1,5 etc..')\n",
    p->name);
   scanf("%s", result);
   while (result[i] != '\0'){
    if (result[i] == ','){
     i++;
     continue;
    }
    k = atoi(&result[i]);
    k = k-1;
    temp = p->hand->card[k];
    p->hand->card[k].suite = -1;
    p->hand->card[k].value = -1;
    e->card[j] = temp;
    j++;
    i++;
   }
  }
  printf("%s Exchanged: ", p->name);
  for (i = 0; i < j; ++i){
   printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
  }
  printf("\n\t\t     For: ");
  exchange_card(d, e, j);
   for (i = 0; i < j; ++i){
    printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
   }
  insert_exchange_into_hand(e, p->hand, j);
  printf("\n\t\tNew hand: ");
 do_nothing:
  if (recommendation[0] == -1)
   printf("%s Stayed: ", p->name);
  best_hand(p->hand, 0, p->isComputer);
  printf("\n");
  free(result);
  free(e);
  free(recommendation);
  return;
 }
}

canonical_original_code:
void prompt_player(struct Player *p, struct Deck *d){
 struct Card temp;
 int *recommendation = malloc(sizeof(int) * 5);
 char *result = malloc(sizeof(char)*10);
 int i; int j; int k;
 struct Exchange *e = malloc(sizeof(Exchange));
 i = j = 0;
 if (!p->hasFolded && p->isActive){
  if (p->isComputer){
   recommendation = compute_expected_value(p->hand, p->isComputer);
   if (recommendation[0] != -1){
    for (i = 0; i < 5; ++i)
     if (recommendation[i]){
      e->card[j++] = p->hand->card[i];
      p->hand->card[i].suite = -1;
      p->hand->card[i].value = -1;
     }
   printf("%s Exchanged: ", p->name);
   for (i = 0; i < j; ++i){
    printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
   }
   printf("\n\t\t     For: ");
   exchange_card(d, e, j);
   for (i = 0; i < j; ++i){
    printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
   }
   insert_exchange_into_hand(e, p->hand, j);
   printf("\n\t\tNew hand: ");
  } else {
   printf("%s Stayed: ", p->name);
  }
   best_hand(p->hand, 0, 0);
   printf("\n");
   free(result);
   free(e);
   free(recommendation);
   return;
  }
  recommendation = compute_expected_value(p->hand, p->isComputer);
  j = 0;
  scanf("%s", result);
  if (!strncmp(result, "y", strlen("y"))){
   for (i = 0; i < 5; ++i){
    if (recommendation[0] == -1)
     goto do_nothing;
    if (recommendation[i]){
     e->card[j++] = p->hand->card[i];
     p->hand->card[i].suite = -1;
     p->hand->card[i].value = -1;
    }
   }
  } else {
   printf("%s, Which cards would you like to exchange? (ex: '1,2,3' or '1,5 etc..')\n",
    p->name);
   scanf("%s", result);
   while (result[i] != '\0'){
    if (result[i] == ','){
     i++;
     continue;
    }
    k = atoi(&result[i]);
    k = k-1;
    temp = p->hand->card[k];
    p->hand->card[k].suite = -1;
    p->hand->card[k].value = -1;
    e->card[j] = temp;
    j++;
    i++;
   }
  }
  printf("%s Exchanged: ", p->name);
  for (i = 0; i < j; ++i){
   printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
  }
  printf("\n\t\t     For: ");
  exchange_card(d, e, j);
   for (i = 0; i < j; ++i){
    printf("%s%ls ", to_val(e->card[i].value), to_suite(e->card[i].suite));
   }
  insert_exchange_into_hand(e, p->hand, j);
  printf("\n\t\tNew hand: ");
 do_nothing:
  if (recommendation[0] == -1)
   printf("%s Stayed: ", p->name);
  best_hand(p->hand, 0, p->isComputer);
  printf("\n");
  free(result);
  free(e);
  free(recommendation);
  return;
 }
}

variable_types: struct Deck { struct Card card[52]; void (*add_card)(struct Card *); struct Card (*deal_card)(); int size; int head; int tail; } *

variable_types:
recommendation
int *

variable_types:
result
char *

variable_types: j int

variable_types: k int

variable_types: struct Exchange { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[5]; int count; } *

user_defined_types: struct Exchange { struct Card card[5]; int count; }


original_code:
void exchange_turn(Player * players, int player_size, Deck * deck){
 int i, count;
 count = 0;
 for (i = 0; i < 4; ++i)
  if (players[i].isActive && players[i].hasFolded)
   count++;
 if (player_size - count != 1)
  for (i = 0; i < player_size; ++i)
   prompt_player(&players[i], deck);
}

canonical_original_code:
void exchange_turn(struct Player *players, int player_size, struct Deck *deck){
 int i; int count;
 count = 0;
 for (i = 0; i < 4; ++i)
  if (players[i].isActive && players[i].hasFolded)
   count++;
 if (player_size - count != 1)
  for (i = 0; i < player_size; ++i)
   prompt_player(&players[i], deck);
}

variable_types: i int

variable_types: count int

user_defined_types: struct Deck { struct Card card[52]; void (*add_card)(struct Card *); struct Card (*deal_card)(); int size; int head; int tail; }

user_defined_types: struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); }


decompiled_code:
char *__fastcall to_player(unsigned int a1)
{
char *v1; // r12

v1 = (char *)malloc(4uLL);
sprintf(v1, "AI - Player %d ", a1);
return v1;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
char *v1; // r12

v1 = (char *)malloc(4uLL);
sprintf(v1, "AI - Player %d ", a1);
return v1;
}

original_code:
char * to_player(int i){
 char * result = malloc(sizeof(30));
 sprintf(result, "AI - Player %d ", i);
 return result;
}

canonical_original_code:
char *to_player(int i){
 char *result = malloc(sizeof(30));
 sprintf(result, "AI - Player %d ", i);
 return result;
}


decompiled_code:
__int64 __fastcall print_hand(_QWORD *a1)
{
printf("%s : ", (const char *)a1[2]);
sort_cards(*a1, 5LL);
return print(*a1, 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
printf("%s : ", (const char *)a1[2]);
sort_cards(*a1, 5LL);
return print(*a1, 5LL);
}

original_code:
void print_hand(Player * p){
 printf("%s : ", p->name);
 sort_cards(p->hand->card, 5);
 print(p->hand->card, 5);
}

canonical_original_code:
void print_hand(struct Player *p){
 printf("%s : ", p->name);
 sort_cards(p->hand->card, 5);
 print(p->hand->card, 5);
}


original_code:
void init_players(Player * players, int size){
 int i;
 for (i = 0; i < size; ++i){
  players[i].hand = malloc(sizeof(Hand));
  players[i].bet = 0;
  players[i].name = to_player(i+1);
  players[i].isComputer = 1;
  players[i].isActive = 1;
  players[i].amount = 400 / size;
  players[i].isBetter = 0;
 }
 if (!1){
  players[0].isComputer = 0;
  players[0].name = "HU - Player 1 ";
  players[0].isBetter = 0;
 }
}

canonical_original_code:
void init_players(struct Player *players, int size){
 int i;
 for (i = 0; i < size; ++i){
  players[i].hand = malloc(sizeof(Hand));
  players[i].bet = 0;
  players[i].name = to_player(i+1);
  players[i].isComputer = 1;
  players[i].isActive = 1;
  players[i].amount = 400 / size;
  players[i].isBetter = 0;
 }
 if (!1){
  players[0].isComputer = 0;
  players[0].name = "HU - Player 1 ";
  players[0].isBetter = 0;
 }
}

variable_types: size int


swap

original_code:
void swap(Card * d1, Card * d2){
 Card * temp = malloc(sizeof(Card));
    memcpy(temp, d1, sizeof(Card));
    memcpy(d1,d2, sizeof(Card));
    memcpy(d2,temp, sizeof(Card));
    free(temp);
}

canonical_original_code:
void swap(struct Card *d1, struct Card *d2){
 struct Card *temp = malloc(sizeof(Card));
    memcpy(temp, d1, sizeof(Card));
    memcpy(d1,d2, sizeof(Card));
    memcpy(d2,temp, sizeof(Card));
    free(temp);
}

variable_types: struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } *


decompiled_code:
int clear_screen()
{
return printf("\x1B[1;1H\x1B[2J");
}

canonical_decompiled_code:
int func1()
{
return printf("\x1B[1;1H\x1B[2J");
}

original_code: void clear_screen(){ printf("\e[1;1H\e[2J"); }


decompiled_code:
__int64 test_queue()
{
int v0; // er14
char *v1; // rbp
char *v2; // r12
char *v3; // rbx
char *v4; // r15
__int64 v5; // rdx
int v6; // er15
__int64 v7; // rbx
char *v9; // [rsp+8h] [rbp-60h]
__m128i v10; // [rsp+10h] [rbp-58h] BYREF
__int64 v11; // [rsp+20h] [rbp-48h]

v0 = 100;
v1 = (char *)malloc(0x500uLL);
v9 = (char *)malloc(0x500uLL);
v2 = (char *)malloc(0xA8uLL);
build_deck(v1);
shuffle_deck(v1);
build_deck(v9);
shuffle_deck(v9);
do
{
v3 = v2;
v4 = v2;
puts("Initialized Deck and Hand");
print(v1, 52LL);
print(v2, 5LL);
do
{
v4 += 24;
deal_card(&v10, v1);
v5 = v11;
*(__m128i *)(v4 - 24) = _mm_loadu_si128(&v10);
*((_QWORD *)v4 - 1) = v5;
}
while ( v4 != v2 + 120 );
v6 = 0;
puts("\nAdded cards to hand");
print(v1, 52LL);
print(v2, 5LL);
do
{
++v6;
v3 += 24;
add_card(v1);
*((_DWORD *)v3 - 5) = -1;
*((_DWORD *)v3 - 6) = -1;
}
while ( v6 != 5 );
puts("\nPut cards back into deck");
print(v1, 52LL);
print(v2, 5LL);
puts("\n");
--v0;
}
while ( v0 );
v7 = 0LL;
sort_cards(v1, 52LL);
sort_cards(v9, 52LL);
do
{
if ( *(_DWORD *)&v1[v7] != *(_DWORD *)&v9[v7] )
puts("Bad Shuffle");
v7 += 24LL;
}
while ( v7 != 1248 );
puts("Good Shuffle");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er14
char *v1; // rbp
char *v2; // r12
char *v3; // rbx
char *v4; // r15
__int64 v5; // rdx
int v6; // er15
__int64 v7; // rbx
char *v9; // [rsp+8h] [rbp-60h]
__m128i v10; // [rsp+10h] [rbp-58h] BYREF
__int64 v11; // [rsp+20h] [rbp-48h]

v0 = 100;
v1 = (char *)malloc(0x500uLL);
v9 = (char *)malloc(0x500uLL);
v2 = (char *)malloc(0xA8uLL);
build_deck(v1);
shuffle_deck(v1);
build_deck(v9);
shuffle_deck(v9);
do
{
v3 = v2;
v4 = v2;
puts("Initialized Deck and Hand");
print(v1, 52LL);
print(v2, 5LL);
do
{
v4 += 24;
deal_card(&v10, v1);
v5 = v11;
*(__m128i *)(v4 - 24) = _mm_loadu_si128(&v10);
*((_QWORD *)v4 - 1) = v5;
}
while ( v4 != v2 + 120 );
v6 = 0;
puts("\nAdded cards to hand");
print(v1, 52LL);
print(v2, 5LL);
do
{
++v6;
v3 += 24;
add_card(v1);
*((_DWORD *)v3 - 5) = -1;
*((_DWORD *)v3 - 6) = -1;
}
while ( v6 != 5 );
puts("\nPut cards back into deck");
print(v1, 52LL);
print(v2, 5LL);
puts("\n");
--v0;
}
while ( v0 );
v7 = 0LL;
sort_cards(v1, 52LL);
sort_cards(v9, 52LL);
do
{
if ( *(_DWORD *)&v1[v7] != *(_DWORD *)&v9[v7] )
puts("Bad Shuffle");
v7 += 24LL;
}
while ( v7 != 1248 );
puts("Good Shuffle");
return 0LL;
}

original_code:
int test_queue(){
 int i,j;
 Card card;
 Deck * deck = malloc(sizeof(Deck));
 Deck * deck2 = malloc(sizeof(Deck));
 Hand * hand = malloc(sizeof(Hand));
 build_deck(deck);
 shuffle_deck(deck);
 build_deck(deck2);
 shuffle_deck(deck2);
 i = 0;
 for (;;){
 printf("Initialized Deck and Hand\n");
 print(deck->card, 52);
 print(hand->card, 5);
 for (j = 0; j < 5; ++j){
  card = deal_card(deck);
  hand->card[j] = card;
 }
 printf("\nAdded cards to hand\n");
 print(deck->card, 52);
 print(hand->card, 5);
 for (j = 0; j < 5; ++j){
  add_card(deck, hand->card[j]);
  hand->card[j].suite = -1;
  hand->card[j].value = -1;
 }
 printf("\nPut cards back into deck\n");
 print(deck->card, 52);
 print(hand->card, 5);
 printf("\n\n");
 i++;
  if (i == 100)
   break;
 }
 sort_cards(deck->card, 52);
 sort_cards(deck2->card, 52);
 for (i = 0; i < 52; ++i)
  if (deck->card[i].value != deck2->card[i].value) printf("Bad Shuffle\n");
 printf("Good Shuffle\n");
 return 0;
}

canonical_original_code:
int test_queue(){
 int i; int j;
 struct Card card;
 struct Deck *deck = malloc(sizeof(Deck));
 struct Deck *deck2 = malloc(sizeof(Deck));
 struct Hand *hand = malloc(sizeof(Hand));
 build_deck(deck);
 shuffle_deck(deck);
 build_deck(deck2);
 shuffle_deck(deck2);
 i = 0;
 for (;;){
 printf("Initialized Deck and Hand\n");
 print(deck->card, 52);
 print(hand->card, 5);
 for (j = 0; j < 5; ++j){
  card = deal_card(deck);
  hand->card[j] = card;
 }
 printf("\nAdded cards to hand\n");
 print(deck->card, 52);
 print(hand->card, 5);
 for (j = 0; j < 5; ++j){
  add_card(deck, hand->card[j]);
  hand->card[j].suite = -1;
  hand->card[j].value = -1;
 }
 printf("\nPut cards back into deck\n");
 print(deck->card, 52);
 print(hand->card, 5);
 printf("\n\n");
 i++;
  if (i == 100)
   break;
 }
 sort_cards(deck->card, 52);
 sort_cards(deck2->card, 52);
 for (i = 0; i < 52; ++i)
  if (deck->card[i].value != deck2->card[i].value) printf("Bad Shuffle\n");
 printf("Good Shuffle\n");
 return 0;
}

variable_types: struct Deck { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[52]; void (*add_card)(struct Card *); struct Card (*deal_card)(); int size; int head; int tail; } *

variable_types: struct Hand { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); } *


original_code:
int exp_value(){
 Hand * hand = malloc(sizeof(Hand) * 5);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = Ace;
 hand->card[2].suite=Spades; hand->card[2].value = Seven;
 hand->card[3].suite=Clubs; hand->card[3].value = Three;
 hand->card[4].suite=Diamonds; hand->card[4].value = Three;
 compute_expected_value(hand, 1);
 return 0;
}

canonical_original_code:
int exp_value(){
 struct Hand *hand = malloc(sizeof(Hand) * 5);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = Ace;
 hand->card[2].suite=Spades; hand->card[2].value = Seven;
 hand->card[3].suite=Clubs; hand->card[3].value = Three;
 hand->card[4].suite=Diamonds; hand->card[4].value = Three;
 compute_expected_value(hand, 1);
 return 0;
}


decompiled_code:
int check_good_shuffle()
{
char *v0; // rbp
char *v1; // rbx
__int64 i; // rax

v0 = (char *)malloc(0x500uLL);
v1 = (char *)malloc(0x500uLL);
build_deck(v0);
build_deck(v1);
shuffle_deck(v1);
sort_cards(v0, 52LL);
sort_cards(v1, 52LL);
print(v0, 52LL);
print(v1, 52LL);
for ( i = 0LL; i != 1248; i += 24LL )
{
if ( *(_DWORD *)&v0[i] != *(_DWORD *)&v1[i] )
return puts("Bad Shuffle");
}
return puts("Good Shuffle");
}

canonical_decompiled_code:
int func2()
{
char *v0; // rbp
char *v1; // rbx
__int64 i; // rax

v0 = (char *)malloc(0x500uLL);
v1 = (char *)malloc(0x500uLL);
build_deck(v0);
build_deck(v1);
shuffle_deck(v1);
sort_cards(v0, 52LL);
sort_cards(v1, 52LL);
print(v0, 52LL);
print(v1, 52LL);
for ( i = 0LL; i != 1248; i += 24LL )
{
if ( *(_DWORD *)&v0[i] != *(_DWORD *)&v1[i] )
return puts("Bad Shuffle");
}
return puts("Good Shuffle");
}

original_code:
void check_good_shuffle(){
 int i;
 Deck * deck1 = malloc(sizeof(Deck));
 Deck * deck2 = malloc(sizeof(Deck));
 build_deck(deck1);
 build_deck(deck2);
 shuffle_deck(deck2);
 sort_cards(deck1->card, 52);
 sort_cards(deck2->card, 52);
 print(deck1->card, 52);
 print(deck2->card, 52);
 for (i = 0; i < 52; ++i)
  if (deck1->card[i].value != deck2->card[i].value)
  {
   printf("Bad Shuffle\n");
   return;
  }
 printf("Good Shuffle\n");
 return;
}

canonical_original_code:
void check_good_shuffle(){
 int i;
 struct Deck *deck1 = malloc(sizeof(Deck));
 struct Deck *deck2 = malloc(sizeof(Deck));
 build_deck(deck1);
 build_deck(deck2);
 shuffle_deck(deck2);
 sort_cards(deck1->card, 52);
 sort_cards(deck2->card, 52);
 print(deck1->card, 52);
 print(deck2->card, 52);
 for (i = 0; i < 52; ++i)
  if (deck1->card[i].value != deck2->card[i].value)
  {
   printf("Bad Shuffle\n");
   return;
  }
 printf("Good Shuffle\n");
 return;
}


original_code:
int test_hands(){
 int i;
 Hand * hand = malloc(sizeof(Hand) * 5);
 for (i = 0; i < 5; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Ten + i;
 }
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Two + i;
 }
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -1; ++i) {
  hand->card[i].suite=Hearts+i;
  hand->card[i].value = Ace;
 }
 hand->card[4].suite = Diamonds;
 hand->card[4].value = Three;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 3; ++i) {
  hand->card[i].suite=Hearts+i;
  hand->card[i].value = King;
 }
 for (i = 0; i < 2; ++i) {
  hand->card[i+3].suite=Hearts+i;
  hand->card[i+3].value = Ace;
 }
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -1; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Five+i;
 }
 hand->card[4].suite=Hearts;
 hand->card[4].value = Ace;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -1; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Five+i;
 }
 hand->card[4].suite=Clubs;
 hand->card[4].value = Four;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -2; ++i) {
  hand->card[i].suite=Hearts+i;
  hand->card[i].value = Ace;
 }
 hand->card[3].suite=Hearts; hand->card[3].value = Three;
 hand->card[4].suite=Diamonds; hand->card[4].value = Five;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = Ace;
 hand->card[2].suite=Spades; hand->card[2].value = Seven;
 hand->card[3].suite=Clubs; hand->card[3].value = Three;
 hand->card[4].suite=Diamonds; hand->card[4].value = Three;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = Ace;
 hand->card[2].suite=Clubs; hand->card[2].value = Three;
 hand->card[3].suite=Diamonds; hand->card[3].value = Four;
 hand->card[4].suite=Spades; hand->card[4].value = Seven;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = King;
 hand->card[2].suite=Clubs; hand->card[2].value = Ten;
 hand->card[3].suite=Diamonds; hand->card[3].value = Nine;
 hand->card[4].suite=Spades; hand->card[4].value = Seven;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 check_good_shuffle();
 return 0;
}

canonical_original_code:
int test_hands(){
 int i;
 struct Hand *hand = malloc(sizeof(Hand) * 5);
 for (i = 0; i < 5; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Ten + i;
 }
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Two + i;
 }
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -1; ++i) {
  hand->card[i].suite=Hearts+i;
  hand->card[i].value = Ace;
 }
 hand->card[4].suite = Diamonds;
 hand->card[4].value = Three;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 3; ++i) {
  hand->card[i].suite=Hearts+i;
  hand->card[i].value = King;
 }
 for (i = 0; i < 2; ++i) {
  hand->card[i+3].suite=Hearts+i;
  hand->card[i+3].value = Ace;
 }
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -1; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Five+i;
 }
 hand->card[4].suite=Hearts;
 hand->card[4].value = Ace;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -1; ++i) {
  hand->card[i].suite=Hearts;
  hand->card[i].value = Five+i;
 }
 hand->card[4].suite=Clubs;
 hand->card[4].value = Four;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 for (i = 0; i < 5 -2; ++i) {
  hand->card[i].suite=Hearts+i;
  hand->card[i].value = Ace;
 }
 hand->card[3].suite=Hearts; hand->card[3].value = Three;
 hand->card[4].suite=Diamonds; hand->card[4].value = Five;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = Ace;
 hand->card[2].suite=Spades; hand->card[2].value = Seven;
 hand->card[3].suite=Clubs; hand->card[3].value = Three;
 hand->card[4].suite=Diamonds; hand->card[4].value = Three;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = Ace;
 hand->card[2].suite=Clubs; hand->card[2].value = Three;
 hand->card[3].suite=Diamonds; hand->card[3].value = Four;
 hand->card[4].suite=Spades; hand->card[4].value = Seven;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 hand->card[0].suite=Spades; hand->card[0].value = Ace;
 hand->card[1].suite=Diamonds; hand->card[1].value = King;
 hand->card[2].suite=Clubs; hand->card[2].value = Ten;
 hand->card[3].suite=Diamonds; hand->card[3].value = Nine;
 hand->card[4].suite=Spades; hand->card[4].value = Seven;
 best_hand(hand, 1, 1);
 printf("grade: %d\n", hand->value);
 check_good_shuffle();
 return 0;
}


decompiled_code:
__int64 __fastcall init_game(_QWORD *a1)
{
void *v1; // rax
void *v2; // rbp

puts("Welcome to 5-card draw Poker with Monte Carlo simulations!");
v1 = malloc(0x500uLL);
a1[1] = v1;
v2 = v1;
a1[2] = malloc(0xA0uLL);
a1[3] = 0x500000000LL;
*a1 = 0x400000190LL;
init_deck(v2);
return init_players(a1[2], 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
void *v1; // rax
void *v2; // rbp

puts("Welcome to 5-card draw Poker with Monte Carlo simulations!");
v1 = malloc(0x500uLL);
a1[1] = v1;
v2 = v1;
a1[2] = malloc(0xA0uLL);
a1[3] = 0x500000000LL;
*a1 = 0x400000190LL;
init_deck(v2);
return init_players(a1[2], 4LL);
}

original_code:
void init_game(Game * game){
 printf("Welcome to 5-card draw Poker with Monte Carlo simulations!\n");
 game->deck = malloc(sizeof(Deck));
 game->players = malloc(sizeof(Player) * 4);
 game->value = 400;
 game->pot = 0;
 game->ante = 5;
 game->player_count = 4;
 init_deck(game->deck);
 init_players(game->players, 4);
}

canonical_original_code:
void init_game(struct Game *game){
 printf("Welcome to 5-card draw Poker with Monte Carlo simulations!\n");
 game->deck = malloc(sizeof(Deck));
 game->players = malloc(sizeof(Player) * 4);
 game->value = 400;
 game->pot = 0;
 game->ante = 5;
 game->player_count = 4;
 init_deck(game->deck);
 init_players(game->players, 4);
}

variable_types: struct Game { int value; int player_count; struct Deck { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[52]; void (*add_card)(struct Card *); struct Card (*deal_card)(); int size; int head; int tail; } *deck; struct Player { struct Hand { struct Card card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); } *hand; int isBetter; int hasFolded; char *name; int isActive; int bet; int isComputer; int amount; } *players; int pot; int ante; } *

user_defined_types: struct Game { int value; int player_count; struct Deck *deck; struct Player *players; int pot; int ante; }


decompiled_code:
__int64 __fastcall reset_game(void *a1)
{
_QWORD *v1; // rax

free(a1);
v1 = malloc(0x20uLL);
return init_game(v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1)
{
_QWORD *v1; // rax

free(a1);
v1 = malloc(0x20uLL);
return func0(v1);
}

original_code:
void reset_game(Game * g){
 free(g);
 Game * game = malloc(sizeof(Game));
 init_game(game);
}

canonical_original_code:
void reset_game(struct Game *g){
 free(g);
 struct Game *game = malloc(sizeof(Game));
 init_game(game);
}


original_code:
void ante_up(Game * game){
 int i, count;
 count = 0;
 for (i = 0; i < game->player_count; ++i){
  if (game->players[i].isActive){
   if ((game->players[i].amount - game->ante) < 0){
    printf("%s loses, not enough money to play\n", game->players[i].name);
    game->players[i].isActive = 0;
    game->players[i].hasFolded = 1;
    game->pot += game->players[i].amount;
    game->players[i].amount = 0;
    count++;
    continue;
   }
   game->pot += game->ante;
   game->players[i].amount -= game->ante;
   printf("%s ante's %d, now has: %d chips\n", game->players[i].name, game->ante, game->players[i].amount);
  }
 }
 printf("Pot at: %d\n", game->pot);
}

canonical_original_code:
void ante_up(struct Game *game){
 int i; int count;
 count = 0;
 for (i = 0; i < game->player_count; ++i){
  if (game->players[i].isActive){
   if ((game->players[i].amount - game->ante) < 0){
    printf("%s loses, not enough money to play\n", game->players[i].name);
    game->players[i].isActive = 0;
    game->players[i].hasFolded = 1;
    game->pot += game->players[i].amount;
    game->players[i].amount = 0;
    count++;
    continue;
   }
   game->pot += game->ante;
   game->players[i].amount -= game->ante;
   printf("%s ante's %d, now has: %d chips\n", game->players[i].name, game->ante, game->players[i].amount);
  }
 }
 printf("Pot at: %d\n", game->pot);
}


original_code:
void betting_round(Game * game, Player * players, int player_size){
 int i;
 i = 0;
 char * result = malloc(sizeof(char) * 10);
 int bet;
 int count;
 count = 0;
 for (i = 0; i < 4; ++i)
  if (players[i].isActive && players[i].hasFolded)
   count++;
 if (player_size - count != 1 && game->pot != 400){
  for (i = 0; i < player_size; ++i)
   players[i].isBetter = 0;
  find_better:
   i = rand() % 4;
   if (!players[i].isActive || players[i].hasFolded)
    goto find_better;
   players[i].isBetter = 1;
   for (i = 0; i < player_size; ++i) {
    if (players[i].isComputer && players[i].isBetter){
      bet = rand() % players[i].amount;
      printf("%s bet %d\n", players[i].name, bet);
      players[i].amount -= bet;
      game->pot += bet;
    }
    if (!players[i].isComputer && players[i].isBetter){
     printf("What would you like to bet? (ex: 1, 10, 50), you have: %d\n", players[i].amount);
    bet:
     scanf("%s", result);
     bet = atoi(result);
     if (bet > players[i].amount || bet < 0){
      printf("Too high or too low, please try again\n");
      goto bet;
     }
     printf("%s bet %d\n", players[i].name, bet);
     players[i].amount -= bet;
     game->pot += bet;
    }
   }
   for (i = 0; i < player_size; ++i) {
    if (!players[i].hasFolded && players[i].isActive){
     if (players[i].isComputer && !players[i].isBetter){
      if (players[i].amount - bet < 0) {
       players[i].hasFolded = 1;
       printf("%s has folded\n", players[i].name);
      }
      else {
       players[i].amount -= bet;
       printf("%s called the bet\n", players[i].name);
       game->pot += bet;
      }
     }
     if (!players[i].isComputer && !players[i].isBetter){
      if (players[i].amount - bet < 0) {
       players[i].hasFolded = 1;
       printf("%s has folded\n", players[i].name);
      }
      else {
      printf("What would you like to do? Call or Fold? (ex: 'c' or 'f') \n");
      scanf("%s", result);
      if (!strncmp(result, "c", strlen("c"))){
       players[i].amount -= bet;
       printf("%s called the bet\n", players[i].name);
       game->pot += bet;
      }
      else {
       players[i].hasFolded = 1;
       printf("%s has folded\n", players[i].name);
      }
     }
    }
   }
  }
  printf("Current pot at: %d\n", game->pot);
 }
 free(result);
}

canonical_original_code:
void betting_round(struct Game *game, struct Player *players, int player_size){
 int i;
 i = 0;
 char *result = malloc(sizeof(char) * 10);
 int bet;
 int count;
 count = 0;
 for (i = 0; i < 4; ++i)
  if (players[i].isActive && players[i].hasFolded)
   count++;
 if (player_size - count != 1 && game->pot != 400){
  for (i = 0; i < player_size; ++i)
   players[i].isBetter = 0;
  find_better:
   i = rand() % 4;
   if (!players[i].isActive || players[i].hasFolded)
    goto find_better;
   players[i].isBetter = 1;
   for (i = 0; i < player_size; ++i) {
    if (players[i].isComputer && players[i].isBetter){
      bet = rand() % players[i].amount;
      printf("%s bet %d\n", players[i].name, bet);
      players[i].amount -= bet;
      game->pot += bet;
    }
    if (!players[i].isComputer && players[i].isBetter){
     printf("What would you like to bet? (ex: 1, 10, 50), you have: %d\n", players[i].amount);
    bet:
     scanf("%s", result);
     bet = atoi(result);
     if (bet > players[i].amount || bet < 0){
      printf("Too high or too low, please try again\n");
      goto bet;
     }
     printf("%s bet %d\n", players[i].name, bet);
     players[i].amount -= bet;
     game->pot += bet;
    }
   }
   for (i = 0; i < player_size; ++i) {
    if (!players[i].hasFolded && players[i].isActive){
     if (players[i].isComputer && !players[i].isBetter){
      if (players[i].amount - bet < 0) {
       players[i].hasFolded = 1;
       printf("%s has folded\n", players[i].name);
      }
      else {
       players[i].amount -= bet;
       printf("%s called the bet\n", players[i].name);
       game->pot += bet;
      }
     }
     if (!players[i].isComputer && !players[i].isBetter){
      if (players[i].amount - bet < 0) {
       players[i].hasFolded = 1;
       printf("%s has folded\n", players[i].name);
      }
      else {
      printf("What would you like to do? Call or Fold? (ex: 'c' or 'f') \n");
      scanf("%s", result);
      if (!strncmp(result, "c", strlen("c"))){
       players[i].amount -= bet;
       printf("%s called the bet\n", players[i].name);
       game->pot += bet;
      }
      else {
       players[i].hasFolded = 1;
       printf("%s has folded\n", players[i].name);
      }
     }
    }
   }
  }
  printf("Current pot at: %d\n", game->pot);
 }
 free(result);
}

variable_types:
players
struct Player *

variable_types: bet int


original_code:
void determine_winner(Game * game, Player * players, int p_size){
 int max, i, counter, rem;
 max = counter = rem = 0;
 char * result = malloc(sizeof(char));
 char * split = malloc(sizeof(int)*4);
 show_hands(players, game->player_count, 1);
 for (i = 0; i < 4; ++i) split[i] = -1;
 for (i = 0; i < p_size; ++i){
  if (players[i].isActive && !players[i].hasFolded){
   if (max < players[i].hand->value){
     max = players[i].hand->value;
    }
   }
  }
 for (i = 0; i < p_size; ++i)
  if (players[i].isActive && !players[i].hasFolded)
   if (max == players[i].hand->value)
    split[i] = max;
 for (i = 0; i < p_size; ++i)
  if (split[i] > -1)
   counter++;
 if (counter > 1){
   printf("Tie game, split the pot\n");
   for (i = 0; i < p_size; ++i)
    if (split[i] != -1)
     printf("%s wins round.\n", players[i].name);
   if (game->pot % counter != 0){
    rem = game->pot % counter;
    game->pot -= rem;
    for (i = 0; i < p_size; ++i){
     if (split[i] != -1)
      players[i].amount += game->pot / counter;
    }
    game->pot = rem;
   } else {
    for (i = 0; i < p_size; ++i)
     if (split[i] != -1)
      players[i].amount += game->pot / counter;
    }
    game->pot = 0;
   }
 else {
  for (i = 0; i < p_size; ++i){
   if (players[i].isActive && !players[i].hasFolded){
    if (players[i].hand->value == max){
     printf("%s wins round.\n", players[i].name);
     players[i].amount += game->pot;
    }
   }
  }
  game->pot = 0;
 }
 for (i = 0; i < p_size; ++i){
  if (players[i].isActive){
   printf("%s - Score: %d, Chips: %d",
   players[i].name,
   players[i].hand->value,
   players[i].amount);
  }
  if (players[i].isActive && players[i].hasFolded)
   printf(" (Folded)");
  printf("\n");
 }
 for (i = 0; i < p_size; ++i){
  if (players[i].isActive){
   players[i].hasFolded = 0;
  }
 }
 printf("Type any key and enter to start next round: ");
 scanf("%s", result);
 if (!strncmp(result, "", strlen("")))
  clear_screen();
 printf("\n");
 free(result);
 free(split);
}

canonical_original_code:
void determine_winner(struct Game *game, struct Player *players, int p_size){
 int max; int i; int counter; int rem;
 max = counter = rem = 0;
 char *result = malloc(sizeof(char));
 char *split = malloc(sizeof(int)*4);
 show_hands(players, game->player_count, 1);
 for (i = 0; i < 4; ++i) split[i] = -1;
 for (i = 0; i < p_size; ++i){
  if (players[i].isActive && !players[i].hasFolded){
   if (max < players[i].hand->value){
     max = players[i].hand->value;
    }
   }
  }
 for (i = 0; i < p_size; ++i)
  if (players[i].isActive && !players[i].hasFolded)
   if (max == players[i].hand->value)
    split[i] = max;
 for (i = 0; i < p_size; ++i)
  if (split[i] > -1)
   counter++;
 if (counter > 1){
   printf("Tie game, split the pot\n");
   for (i = 0; i < p_size; ++i)
    if (split[i] != -1)
     printf("%s wins round.\n", players[i].name);
   if (game->pot % counter != 0){
    rem = game->pot % counter;
    game->pot -= rem;
    for (i = 0; i < p_size; ++i){
     if (split[i] != -1)
      players[i].amount += game->pot / counter;
    }
    game->pot = rem;
   } else {
    for (i = 0; i < p_size; ++i)
     if (split[i] != -1)
      players[i].amount += game->pot / counter;
    }
    game->pot = 0;
   }
 else {
  for (i = 0; i < p_size; ++i){
   if (players[i].isActive && !players[i].hasFolded){
    if (players[i].hand->value == max){
     printf("%s wins round.\n", players[i].name);
     players[i].amount += game->pot;
    }
   }
  }
  game->pot = 0;
 }
 for (i = 0; i < p_size; ++i){
  if (players[i].isActive){
   printf("%s - Score: %d, Chips: %d",
   players[i].name,
   players[i].hand->value,
   players[i].amount);
  }
  if (players[i].isActive && players[i].hasFolded)
   printf(" (Folded)");
  printf("\n");
 }
 for (i = 0; i < p_size; ++i){
  if (players[i].isActive){
   players[i].hasFolded = 0;
  }
 }
 printf("Type any key and enter to start next round: ");
 scanf("%s", result);
 if (!strncmp(result, "", strlen("")))
  clear_screen();
 printf("\n");
 free(result);
 free(split);
}

variable_types: max int

variable_types: counter int

variable_types: rem int

variable_types:
split
char *


decompiled_code:
__int64 __fastcall game_winner(_QWORD *a1, int a2)
{
_BYTE *v2; // rax
_BYTE *v3; // r12
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax

v2 = malloc(1uLL);
if ( a2 <= 0 )
{
LABEL_7:
init_deck(a1[1]);
result = 0LL;
}
else
{
v3 = v2;
v4 = a1[2];
v5 = v4 + 40LL * (unsigned int)(a2 - 1) + 40;
while ( *(_DWORD *)(v4 + 36) != 400 )
{
v4 += 40LL;
if ( v4 == v5 )
goto LABEL_7;
}
printf("%s is the winner. \n", *(const char **)(v4 + 16));
puts("Would you like to play again? 'y' or 'n'");
_isoc99_scanf("%s", v3);
result = 1LL;
if ( *v3 == 121 )
{
clear_screen();
reset_game(a1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, int a2)
{
_BYTE *v2; // rax
_BYTE *v3; // r12
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax

v2 = malloc(1uLL);
if ( a2 <= 0 )
{
LABEL_7:
init_deck(a1[1]);
result = 0LL;
}
else
{
v3 = v2;
v4 = a1[2];
v5 = v4 + 40LL * (unsigned int)(a2 - 1) + 40;
while ( *(_DWORD *)(v4 + 36) != 400 )
{
v4 += 40LL;
if ( v4 == v5 )
goto LABEL_7;
}
printf("%s is the winner. \n", *(const char **)(v4 + 16));
puts("Would you like to play again? 'y' or 'n'");
_isoc99_scanf("%s", v3);
result = 1LL;
if ( *v3 == 121 )
{
clear_screen();
func1(a1);
result = 0LL;
}
}
return result;
}

original_code:
int game_winner(Game * game, int psize){
 int i;
 char * result = malloc(sizeof(char));
 for (i = 0; i < psize; ++i){
   if (game->players[i].amount == 400){
    printf("%s is the winner. \n", game->players[i].name);
    printf("Would you like to play again? 'y' or 'n'\n");
    scanf("%s", result);
    if (!strncmp(result, "y", strlen("y"))){
     clear_screen();
     reset_game(game);
     return 0;
    }
    return 1;
   }
  }
  init_deck(game->deck);
  return 0;
}

canonical_original_code:
int game_winner(struct Game *game, int psize){
 int i;
 char *result = malloc(sizeof(char));
 for (i = 0; i < psize; ++i){
   if (game->players[i].amount == 400){
    printf("%s is the winner. \n", game->players[i].name);
    printf("Would you like to play again? 'y' or 'n'\n");
    scanf("%s", result);
    if (!strncmp(result, "y", strlen("y"))){
     clear_screen();
     reset_game(game);
     return 0;
    }
    return 1;
   }
  }
  init_deck(game->deck);
  return 0;
}

variable_types: psize int

variable_types:
result
char *


decompiled_code:
__int64 __fastcall card_comparator(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
int card_comparator(const void * a, const void * b){
    const Card * c1 = (const Card *)a;
    const Card * c2 = (const Card *)b;
    return (c1->value - c2->value);
}

canonical_original_code:
int card_comparator(void *a, void *b){
    struct Card *c1 = (const Card *)a;
    struct Card *c2 = (const Card *)b;
    return (c1->value - c2->value);
}

variable_types:
a
void *

variable_types:
b
void *


variable_types: value int

variable_types:
values
char *[13]


decompiled_code:
char *__fastcall to_suite(unsigned int a1)
{
char *result; // rax

setlocale(6, &locale);
result = (char *)&unk_1E4;
if ( a1 <= 3 )
result = CSWTCH_4[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
char *result; // rax

setlocale(6, &locale);
result = (char *)&unk_1E4;
if ( a1 <= 3 )
result = CSWTCH_4[a1];
return result;
}

original_code:
wchar_t * to_suite(int suite){
 wchar_t *clubs = L"\u2667";
    wchar_t *diamonds = L"\u2666";
    wchar_t *hearts = L"\u2665";
    wchar_t *spades = L"\u2664";
    setlocale(6, "");
 switch(suite){
  case 0: return hearts; break;
  case 1: return clubs; break;
  case 2: return spades; break;
  case 3: return diamonds; break;
  default: break;
 }
 return L"";
}

canonical_original_code:
int *to_suite(int suite){
 int *clubs = L"\u2667";
    int *diamonds = L"\u2666";
    int *hearts = L"\u2665";
    int *spades = L"\u2664";
    setlocale(6, "");
 switch(suite){
  case 0: return hearts; break;
  case 1: return clubs; break;
  case 2: return spades; break;
  case 3: return diamonds; break;
  default: break;
 }
 return L"";
}

variable_types: suite int

variable_types:
clubs
int *

variable_types:
diamonds
int *

variable_types:
hearts
int *

variable_types:
spades
int *

return_type: int *


decompiled_code:
char *__fastcall to_card(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
char *v7; // r12
const char *v8; // rax
const wchar_t *v9; // rcx

v7 = (char *)malloc(4uLL);
to_suite(HIDWORD(a7));
v8 = to_val(a7);
sprintf(v7, " %s%ls ", v8, v9);
return v7;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
char *v7; // r12
const char *v8; // rax
const wchar_t *v9; // rcx

v7 = (char *)malloc(4uLL);
func2(HIDWORD(a7));
v8 = func1(a7);
sprintf(v7, " %s%ls ", v8, v9);
return v7;
}

original_code:
char * to_card(Card card){
 char * result = malloc(sizeof(52));
 sprintf(result, " %s%ls ", to_val(card.value),to_suite(card.suite));
 return result;
}

canonical_original_code:
char *to_card(struct Card card){
 char *result = malloc(sizeof(52));
 sprintf(result, " %s%ls ", to_val(card.value),to_suite(card.suite));
 return result;
}

variable_types: struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); }


print

original_code:
void print(Card * deck, int size){
 int i;
 printf("[");
 for (i = 0; i < size; ++i){
  if (deck[i].value == -1){
   printf(" - ");
   continue;
  }
  printf("%s", to_card(deck[i]));
 }
 printf(" ] ");
}

canonical_original_code:
void print(struct Card *deck, int size){
 int i;
 printf("[");
 for (i = 0; i < size; ++i){
  if (deck[i].value == -1){
   printf(" - ");
   continue;
  }
  printf("%s", to_card(deck[i]));
 }
 printf(" ] ");
}

variable_types: struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } *

variable_types: size int

variable_types: i int


decompiled_code:
void __fastcall sort_cards(void *a1, int a2)
{
qsort(a1, a2, 0x18uLL, (__compar_fn_t)card_comparator);
}

canonical_decompiled_code:
void __fastcall func5(void *a1, int a2)
{
qsort(a1, a2, 0x18uLL, (__compar_fn_t)card_comparator);
}

original_code:
void sort_cards(Card * cards, int size){
 qsort(cards, size, sizeof(*cards), card_comparator);
}

canonical_original_code:
void sort_cards(struct Card *cards, int size){
 qsort(cards, size, sizeof(*cards), card_comparator);
}


decompiled_code:
__int64 start_game()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
init_game(v0);
while ( !(unsigned int)game_winner(v0, *((unsigned int *)v0 + 1)) )
{
deal_players(v0[2], v0[1]);
ante_up(v0);
show_hands(v0[2], *((unsigned int *)v0 + 1), 1LL);
betting_round(v0, v0[2], *((unsigned int *)v0 + 1));
exchange_turn(v0[2], *((unsigned int *)v0 + 1), v0[1]);
betting_round(v0, v0[2], *((unsigned int *)v0 + 1));
determine_winner(v0, v0[2], *((unsigned int *)v0 + 1));
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
init_game(v0);
while ( !(unsigned int)game_winner(v0, *((unsigned int *)v0 + 1)) )
{
deal_players(v0[2], v0[1]);
ante_up(v0);
show_hands(v0[2], *((unsigned int *)v0 + 1), 1LL);
betting_round(v0, v0[2], *((unsigned int *)v0 + 1));
exchange_turn(v0[2], *((unsigned int *)v0 + 1), v0[1]);
betting_round(v0, v0[2], *((unsigned int *)v0 + 1));
determine_winner(v0, v0[2], *((unsigned int *)v0 + 1));
}
return 0LL;
}

original_code:
int start_game() {
    if (0) return test_queue();
 Game * game = malloc(sizeof(Game));
 init_game(game);
 while (!game_winner(game, game->player_count)) {
  deal_players(game->players, game->deck);
  ante_up(game);
  show_hands(game->players, game->player_count, 1);
  betting_round(game, game->players, game->player_count);
  exchange_turn(game->players, game->player_count, game->deck);
  betting_round(game, game->players, game->player_count);
  determine_winner(game, game->players, game->player_count);
 }
 return 0;
}

canonical_original_code:
int start_game() {
    if (0) return test_queue();
 struct Game *game = malloc(sizeof(Game));
 init_game(game);
 while (!game_winner(game, game->player_count)) {
  deal_players(game->players, game->deck);
  ante_up(game);
  show_hands(game->players, game->player_count, 1);
  betting_round(game, game->players, game->player_count);
  exchange_turn(game->players, game->player_count, game->deck);
  betting_round(game, game->players, game->player_count);
  determine_winner(game, game->players, game->player_count);
 }
 return 0;
}

variable_types: struct Game { int value; int player_count; struct Deck { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[52]; void (*add_card)(struct Card *); struct Card (*deal_card)(); int size; int head; int tail; } *deck; struct Player { struct Hand { struct Card card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); } *hand; int isBetter; int hasFolded; char *name; int isActive; int bet; int isComputer; int amount; } *players; int pot; int ante; } *


original_code:
void best_hand(Hand * hand, int isFinalRound, int isCPU){
 int i, oneS, twoS, threeS, fourS, fiveS, oneV, twoV, threeV, fourV, fiveV;
 sort_cards(hand->card, 5);
 if (isFinalRound || !isCPU) print(hand->card, 5);
 oneS = hand->card[0].suite; oneV = hand->card[0].value;
 twoS = hand->card[1].suite; twoV = hand->card[1].value;
 threeS = hand->card[2].suite; threeV = hand->card[2].value;
 fourS = hand->card[3].suite; fourV = hand->card[3].value;
 fiveS = hand->card[4].suite; fiveV = hand->card[4].value;
 if ((oneS == twoS && twoS == threeS && threeS == fourS && fourS == fiveS) &&
  (oneV == Ten && twoV == Jack && threeV == Queen && fourV == King && fiveV == Ace)){
   hand->_class = 9;
   hand->rank = fiveV;
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   hand_value(hand);
   if (isFinalRound || !isCPU) printf("Royal Flush\n");
   return;
 }
 if (oneS == twoS && twoS == threeS && threeS == fourS && fourS == fiveS &&
  fiveV == fourV + 1 && fourV == threeV + 1 && threeV == twoV + 1 && twoV == oneV + 1){
  hand->highCard.value = fiveV;
  hand->highCard.suite = fiveS;
  if (isFinalRound || !isCPU) printf("Straight Flush\n");
  hand->_class = 9;
  hand->rank = fiveV;
  hand_value(hand);
  return;
 }
 if ((oneV == twoV && twoV == threeV && threeV == fourV) ||
  (twoV == threeV && threeV == fourV && fourV == fiveV)){
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU) printf("Four of a kind\n");
   hand->_class = 8;
   hand->rank = threeV;
   hand_value(hand);
   return;
 }
 if ((oneV == twoV && twoV == threeV && fourV == fiveV) ||
     (oneV == twoV && threeV == fourV && fourV == fiveV)) {
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU) printf("Full House\n");
   hand->_class = 7;
   hand->rank = fiveV;
   hand_value(hand);
   return;
 }
 if (oneS == twoS && twoS == threeS && threeS == fourS && fourS == fiveS){
  hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU)printf("Flush\n");
   hand->_class = 6;
   hand->rank = fiveV;
   hand_value(hand);
  return;
 }
 if (fiveV == fourV+1 && fourV+1 == threeV+2 && threeV+2 == twoV+3 && twoV+3 == oneV+4){
  hand->highCard.value = fiveV;
  hand->highCard.suite = fiveS;
  if (isFinalRound || !isCPU) printf("Straight\n");
  hand->_class = 5;
  hand->rank = fiveV;
  hand_value(hand);
  return;
 }
 for (i = 0; i < 5 - 2; ++i){
  if ((hand->card[i].value == hand->card[i+1].value) && (hand->card[i+1].value == hand->card[i+2].value)){
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   hand->_class = 4;
   hand->rank = threeV;
   hand_value(hand);
   if (isFinalRound || !isCPU) printf("3 of a kind\n");
   return;
  }
 }
 if ((oneV == twoV && threeV == fourV) ||
  (twoV == threeV && fourV == fiveV) ||
  (oneV == twoV && fourV == fiveV)) {
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU) printf("Two Pair\n");
   hand->_class = 3;
   hand->rank = fourV;
   hand_value(hand);
   return;
 }
 for (i = 0; i < 5 -1; ++i) {
  int j, value;
  if (hand->card[i].value == hand->card[i+1].value){
   value = hand->card[i].value;
   if (isFinalRound || !isCPU) {
    printf("Pair (");
    for (j = 0; j < 2; ++j){
     printf("%s", to_card(hand->card[i]));
     i++;
    }
    printf(")\n");
   }
   hand->_class = 2;
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   hand->rank = value;
   hand_value(hand);
   return;
  }
 }
 if (isFinalRound || !isCPU)
  printf("High - Card %s%ls\n", to_val(fiveV), to_suite(fiveS));
 hand->_class = 1;
 hand->highCard.value = fiveV;
 hand->highCard.suite = fiveS;
 hand->rank = fiveV;
 hand_value(hand);
 return;
}

canonical_original_code:
void best_hand(struct Hand *hand, int isFinalRound, int isCPU){
 int i; int oneS; int twoS; int threeS; int fourS; int fiveS; int oneV; int twoV; int threeV; int fourV; int fiveV;
 sort_cards(hand->card, 5);
 if (isFinalRound || !isCPU) print(hand->card, 5);
 oneS = hand->card[0].suite; oneV = hand->card[0].value;
 twoS = hand->card[1].suite; twoV = hand->card[1].value;
 threeS = hand->card[2].suite; threeV = hand->card[2].value;
 fourS = hand->card[3].suite; fourV = hand->card[3].value;
 fiveS = hand->card[4].suite; fiveV = hand->card[4].value;
 if ((oneS == twoS && twoS == threeS && threeS == fourS && fourS == fiveS) &&
  (oneV == Ten && twoV == Jack && threeV == Queen && fourV == King && fiveV == Ace)){
   hand->_class = 9;
   hand->rank = fiveV;
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   hand_value(hand);
   if (isFinalRound || !isCPU) printf("Royal Flush\n");
   return;
 }
 if (oneS == twoS && twoS == threeS && threeS == fourS && fourS == fiveS &&
  fiveV == fourV + 1 && fourV == threeV + 1 && threeV == twoV + 1 && twoV == oneV + 1){
  hand->highCard.value = fiveV;
  hand->highCard.suite = fiveS;
  if (isFinalRound || !isCPU) printf("Straight Flush\n");
  hand->_class = 9;
  hand->rank = fiveV;
  hand_value(hand);
  return;
 }
 if ((oneV == twoV && twoV == threeV && threeV == fourV) ||
  (twoV == threeV && threeV == fourV && fourV == fiveV)){
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU) printf("Four of a kind\n");
   hand->_class = 8;
   hand->rank = threeV;
   hand_value(hand);
   return;
 }
 if ((oneV == twoV && twoV == threeV && fourV == fiveV) ||
     (oneV == twoV && threeV == fourV && fourV == fiveV)) {
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU) printf("Full House\n");
   hand->_class = 7;
   hand->rank = fiveV;
   hand_value(hand);
   return;
 }
 if (oneS == twoS && twoS == threeS && threeS == fourS && fourS == fiveS){
  hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU)printf("Flush\n");
   hand->_class = 6;
   hand->rank = fiveV;
   hand_value(hand);
  return;
 }
 if (fiveV == fourV+1 && fourV+1 == threeV+2 && threeV+2 == twoV+3 && twoV+3 == oneV+4){
  hand->highCard.value = fiveV;
  hand->highCard.suite = fiveS;
  if (isFinalRound || !isCPU) printf("Straight\n");
  hand->_class = 5;
  hand->rank = fiveV;
  hand_value(hand);
  return;
 }
 for (i = 0; i < 5 - 2; ++i){
  if ((hand->card[i].value == hand->card[i+1].value) && (hand->card[i+1].value == hand->card[i+2].value)){
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   hand->_class = 4;
   hand->rank = threeV;
   hand_value(hand);
   if (isFinalRound || !isCPU) printf("3 of a kind\n");
   return;
  }
 }
 if ((oneV == twoV && threeV == fourV) ||
  (twoV == threeV && fourV == fiveV) ||
  (oneV == twoV && fourV == fiveV)) {
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   if (isFinalRound || !isCPU) printf("Two Pair\n");
   hand->_class = 3;
   hand->rank = fourV;
   hand_value(hand);
   return;
 }
 for (i = 0; i < 5 -1; ++i) {
  int j; int value;
  if (hand->card[i].value == hand->card[i+1].value){
   value = hand->card[i].value;
   if (isFinalRound || !isCPU) {
    printf("Pair (");
    for (j = 0; j < 2; ++j){
     printf("%s", to_card(hand->card[i]));
     i++;
    }
    printf(")\n");
   }
   hand->_class = 2;
   hand->highCard.value = fiveV;
   hand->highCard.suite = fiveS;
   hand->rank = value;
   hand_value(hand);
   return;
  }
 }
 if (isFinalRound || !isCPU)
  printf("High - Card %s%ls\n", to_val(fiveV), to_suite(fiveS));
 hand->_class = 1;
 hand->highCard.value = fiveV;
 hand->highCard.suite = fiveS;
 hand->rank = fiveV;
 hand_value(hand);
 return;
}

variable_types: struct Hand { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); } *

variable_types: isFinalRound int

variable_types: isCPU int

variable_types: oneS int

variable_types: twoS int

variable_types: threeS int

variable_types: fourS int

variable_types: fiveS int

variable_types: oneV int

variable_types: twoV int

variable_types: threeV int

variable_types: fourV int

variable_types: fiveV int

variable_types: j int


decompiled_code:
__int64 __fastcall shuffle_deck(__int64 a1)
{
__int64 v1; // rbp
int v2; // eax
__int64 result; // rax

v1 = a1 + 1224;
do
{
v2 = rand();
swap(v1, a1 + 24LL * (v2 % 51));
result = v1;
v1 -= 24LL;
}
while ( result != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbp
int v2; // eax
__int64 result; // rax

v1 = a1 + 1224;
do
{
v2 = rand();
swap(v1, a1 + 24LL * (v2 % 51));
result = v1;
v1 -= 24LL;
}
while ( result != a1 );
return result;
}

original_code:
void shuffle_deck(Deck * deck) {
 int i, index;
 for (i = 51; i >= 0; i--){
     index = rand() % 51;
     swap(&deck->card[i], &deck->card[index]);
 }
}

canonical_original_code:
void shuffle_deck(struct Deck *deck) {
 int i; int index;
 for (i = 51; i >= 0; i--){
     index = rand() % 51;
     swap(&deck->card[i], &deck->card[index]);
 }
}

variable_types: struct Deck { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[52]; void (*add_card)(struct Card *); struct Card (*deal_card)(); int size; int head; int tail; } *

variable_types: index int


decompiled_code:
__int64 __fastcall init_deck(_DWORD *a1)
{
__int64 v1; // r9

build_deck(a1);
return shuffle_deck(v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
__int64 v1; // r9

func1(a1);
return func0(v1);
}

original_code:
void init_deck(Deck * deck){
 build_deck(deck);
 shuffle_deck(deck);
}

canonical_original_code:
void init_deck(struct Deck *deck){
 build_deck(deck);
 shuffle_deck(deck);
}


original_code:
void add_card(Deck * deck, Card card){
 if (deck->size == 52)
  return;
 deck->card[deck->tail].suite = card.suite;
 deck->card[deck->tail].value = card.value;
 deck->tail = (deck->tail + 1) % 52;
 deck->size++;
 return;
}

canonical_original_code:
void add_card(struct Deck *deck, struct Card card){
 if (deck->size == 52)
  return;
 deck->card[deck->tail].suite = card.suite;
 deck->card[deck->tail].value = card.value;
 deck->tail = (deck->tail + 1) % 52;
 deck->size++;
 return;
}

variable_types:
card
struct Card


original_code:
void insert_exchange_into_hand(Exchange*e, Hand*h, int size){
 int i;
 Card temp;
 i = 0;
 sort_cards(h->card, 5);
 for (i=0;i<size;i++){
   temp = e->card[i];
   e->card[i] = h->card[i];
   h->card[i] = temp;
  }
 }

canonical_original_code:
void insert_exchange_into_hand(struct Exchange *e, struct Hand *h, int size){
 int i;
 struct Card temp;
 i = 0;
 sort_cards(h->card, 5);
 for (i=0;i<size;i++){
   temp = e->card[i];
   e->card[i] = h->card[i];
   h->card[i] = temp;
  }
 }

variable_types: struct Exchange { struct Card { int value; int suite; char *(*to_suite)(int); char *(*to_val)(int); } card[5]; int count; } *

variable_types: struct Hand { struct Card card[5]; struct Card highCard; int rank; int _class; int value; void (*calc_hand_value)(int _class, int rank); } *

variable_types: size int

variable_types: i int


repo: dmorneau/TCP-Simulation

decompiled_code:
void send_pkt()
{
_DWORD *v0; // rbp
int v1; // eax
void *v2; // rbx

v0 = lbuf;
while ( v0 && v0[4] <= elapsed_time )
{
if ( (v0[2] & 1) == 0 )
{
while ( (int)write(sock_s, v0 + 5, (unsigned int)v0[3]) < 0 )
{
v1 = *_errno_location();
if ( v1 != 105 )
{
if ( (v1 & 0xFFFFFFFB) != 107 )
{
perror("send_pkt: write");
exit(1);
}
return;
}
usleep(0x3E8u);
if ( (v0[2] & 1) != 0 )
break;
}
}
v2 = *(void **)v0;
LODWORD(qword_660) = qword_660 - v0[3];
lbuf = v2;
free(v0);
if ( !v2 )
qword_658 = 0LL;
v0 = v2;
if ( (qword_660 & 0x100000000LL) != 0 )
HIDWORD(qword_660) &= 0xFFFFFFFE;
}
}

canonical_decompiled_code:
void func0()
{
_DWORD *v0; // rbp
int v1; // eax
void *v2; // rbx

v0 = lbuf;
while ( v0 && v0[4] <= elapsed_time )
{
if ( (v0[2] & 1) == 0 )
{
while ( (int)write(sock_s, v0 + 5, (unsigned int)v0[3]) < 0 )
{
v1 = *_errno_location();
if ( v1 != 105 )
{
if ( (v1 & 0xFFFFFFFB) != 107 )
{
perror("send_pkt: write");
exit(1);
}
return;
}
usleep(0x3E8u);
if ( (v0[2] & 1) != 0 )
break;
}
}
v2 = *(void **)v0;
LODWORD(qword_660) = qword_660 - v0[3];
lbuf = v2;
free(v0);
if ( !v2 )
qword_658 = 0LL;
v0 = v2;
if ( (qword_660 & 0x100000000LL) != 0 )
HIDWORD(qword_660) &= 0xFFFFFFFE;
}
}

original_code:
static void
send_pkt()
{
 struct pktbuf *pb;
 while ((pb = lbuf.lbuf_head) != ((void *)0) &&
    pb->pb_txtime <= elapsed_time) {
retry:
  if (!(pb->pb_stat & 0x0001)) {
   if (write(sock_s, (char *)&pb->pb_lowerpkt,
       pb->pb_size) < 0) {
    if ((*__errno_location ()) == 105) {
     usleep(1000);
     goto retry;
    }
    if ((*__errno_location ()) == 107 || (*__errno_location ()) == 111)
     return;
    perror("send_pkt: write");
    exit(1);
   }
  }
  lbuf.lbuf_size -= pb->pb_size;
  lbuf.lbuf_head = pb->pb_next;
  free(pb);
  if (lbuf.lbuf_head == ((void *)0))
   lbuf.lbuf_tail = ((void *)0);
  if (lbuf.lbuf_stat & 0x0001)
   lbuf.lbuf_stat &= ~0x0001;
 }
}

variable_types: struct pktbuf { struct pktbuf *pb_next; int pb_stat; int pb_size; int pb_txtime; struct lowerpkt { int lp_type; char lp_buf[1500]; } pb_lowerpkt; } *

user_defined_types: struct pktbuf { struct pktbuf *pb_next; int pb_stat; int pb_size; int pb_txtime; struct lowerpkt pb_lowerpkt; }


decompiled_code:
void alarm_handler()
{
watchdog_0 -= 10;
if ( watchdog_0 < 0 )
{
fwrite("Watchdog timer expired!\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
send_pkt();
elapsed_time += 10;
timer_handler();
}

canonical_decompiled_code:
void func1()
{
watchdog_0 -= 10;
if ( watchdog_0 < 0 )
{
fwrite("Watchdog timer expired!\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
func0();
elapsed_time += 10;
timer_handler();
}

original_code:
static void
alarm_handler()
{
 static int watchdog = (5*60*1000);
 watchdog -= 10;
 if (watchdog < 0) {
  fprintf(stderr, "Watchdog timer expired!\n");
  exit(1);
 }
 send_pkt();
 elapsed_time += 10;
 timer_handler();
}

variable_types: watchdog int


decompiled_code:
int __fastcall print_help(const char *a1)
{
printf("%s file bandwidth delay error_rate\n", a1);
puts("\tbandwidth: 1, 10, 100 (Mbps)");
puts("\tdelay: 10, 20, 50 (msec)");
return puts("\terror rate: 0, -4 (1*10^-4), -3 (1*10^-3), -2 (1*10^-2), -1 (1*10^-1)");
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
printf("%s file bandwidth delay error_rate\n", a1);
puts("\tbandwidth: 1, 10, 100 (Mbps)");
puts("\tdelay: 10, 20, 50 (msec)");
return puts("\terror rate: 0, -4 (1*10^-4), -3 (1*10^-3), -2 (1*10^-2), -1 (1*10^-1)");
}

original_code:
static void
print_help(char *command)
{
 printf("%s file bandwidth delay error_rate\n", command);
 printf("\tbandwidth: 1, 10, 100 (Mbps)\n");
 printf("\tdelay: 10, 20, 50 (msec)\n");
 printf("\terror rate: 0, -4 (1*10^-4), -3 (1*10^-3), -2 (1*10^-2), -1 (1*10^-1)\n");
}

variable_types:
command
char *


decompiled_code:
__int64 __fastcall udt_send(_DWORD *a1, int a2)
{
_QWORD *v2; // rax
_DWORD *v3; // rbx
char *v4; // rax
__int64 v5; // rbp
int v6; // eax
_QWORD *v7; // rdx
int v8; // eax
bool v9; // cc

if ( a2 > 1500 )
return 4294967294LL;
v2 = malloc(0x5F8uLL);
v3 = v2;
if ( !v2 )
{
perror("udt_send: malloc");
return 4294967293LL;
}
*v2 = 0LL;
v4 = (char *)(v2 + 3);
if ( (unsigned __int64)a2 < 8 )
{
if ( (a2 & 4) != 0 )
{
v3[6] = *a1;
*(_DWORD *)&v4[a2 - 4] = *(_DWORD *)((char *)a1 + a2 - 4);
}
else if ( a2 )
{
*((_BYTE *)v3 + 24) = *(_BYTE *)a1;
if ( (a2 & 2) != 0 )
*(_WORD *)&v4[a2 - 2] = *(_WORD *)((char *)a1 + a2 - 2);
}
}
else
{
*(_QWORD *)&v4[a2 - 8] = *(_QWORD *)((char *)a1 + a2 - 8);
qmemcpy(v4, a1, 8 * ((unsigned __int64)(a2 - 1LL) >> 3));
}
v3[5] = 0;
v3[3] = a2 + 4;
v5 = erate;
v3[2] = 0;
if ( (_DWORD)v5 )
{
if ( !(random() % v5) )
v3[2] |= 1u;
}
v3[4] = elapsed_time + delay;
if ( sigprocmask(0, &sigs, 0LL) >= 0 )
{
v6 = v3[3];
if ( !lbuf )
{
qword_658 = (__int64)v3;
lbuf = v3;
LODWORD(qword_660) = v6;
goto LABEL_19;
}
v7 = (_QWORD *)qword_658;
v8 = qword_660 + v6;
qword_658 = (__int64)v3;
v9 = v8 < bdp;
LODWORD(qword_660) = v8;
*v7 = v3;
if ( v9 )
{
LABEL_19:
if ( sigprocmask(1, &sigs, 0LL) >= 0 )
return 0LL;
goto LABEL_12;
}
while ( sigprocmask(1, &sigs, 0LL) >= 0 )
{
HIDWORD(qword_660) |= 1u;
pause();
if ( (int)qword_660 < bdp )
goto LABEL_19;
}
}
LABEL_12:
perror("sigprocmask");
return 4294967293LL;
}

original_code:
int
udt_send(void *buf, int size)
{
 int cnt;
 struct pktbuf *pbuf;
 struct lowerpkt *lpp;
 long rnd;
 if (size > 1500)
  return -2;
 if ((pbuf = (struct pktbuf *)malloc(sizeof(struct pktbuf))) == ((void *)0)) {
  perror("udt_send: malloc");
  return -3;
 }
 lpp = &pbuf->pb_lowerpkt;
 pbuf->pb_next = ((void *)0);
 bcopy(buf, lpp->lp_buf, size);
 lpp->lp_type = 0;
 pbuf->pb_size = size + 4;
 pbuf->pb_stat = 0;
 if (erate) {
  rnd = random();
  if ((rnd % erate) == 0) {
   pbuf->pb_stat |= 0x0001;
  }
 }
 pbuf->pb_txtime = elapsed_time + delay;
 if (sigprocmask(0, &sigs, ((void *)0)) < 0) {
  perror("sigprocmask");
  return -3;
 }
 if (lbuf.lbuf_head == ((void *)0)) {
  lbuf.lbuf_head = lbuf.lbuf_tail = pbuf;
  lbuf.lbuf_size = pbuf->pb_size;
 } else {
  lbuf.lbuf_tail->pb_next = pbuf;
  lbuf.lbuf_tail = pbuf;
  lbuf.lbuf_size += pbuf->pb_size;
retry:
  if (lbuf.lbuf_size >= bdp) {
   if (sigprocmask(1, &sigs, ((void *)0)) < 0) {
    perror("sigprocmask");
    return -3;
   }
   lbuf.lbuf_stat |= 0x0001;
   pause();
   goto retry;
  }
 }
 if (sigprocmask(1, &sigs, ((void *)0)) < 0) {
  perror("sigprocmask");
  return -3;
 }
 return 0;
}

variable_types:
buf
void *

variable_types: cnt int

variable_types: struct lowerpkt { int lp_type; char lp_buf[1500]; } *

variable_types: rnd long


decompiled_code:
__int64 __fastcall udt_recv(void *dest, int a2, int a3)
{
int v4; // ebx
int v5; // edi
int v6; // eax
unsigned int v7; // er15
int v8; // eax
fd_set v10; // [rsp+0h] [rbp-698h] BYREF
int buf; // [rsp+80h] [rbp-618h] BYREF
char src[1556]; // [rsp+84h] [rbp-614h] BYREF

if ( a3 != -1 )
{
v4 = a3;
memset(&v10, 0, sizeof(v10));
v5 = sock_r;
v10.fds_bits[sock_r / 64] |= 1LL << (sock_r % 64);
do
{
while ( 1 )
{
v6 = select(v5 + 1, &v10, 0LL, 0LL, 0LL);
v7 = v6;
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
{
v7 = -3;
perror("udt_recv: select");
return v7;
}
v4 -= 10;
if ( v4 <= 0 )
return 0;
v5 = sock_r;
}
if ( !v6 )
return v7;
v5 = sock_r;
}
while ( (v10.fds_bits[sock_r / 64] & (1LL << (sock_r % 64))) == 0 );
v8 = read(sock_r, &buf, (unsigned int)(a2 + 4));
if ( v8 >= 0 )
goto LABEL_14;
LABEL_7:
if ( *_errno_location() != 104 )
{
v7 = -3;
perror("udt_recv: read");
return v7;
}
return (unsigned int)-1;
}
v8 = read(sock_r, &buf, (unsigned int)(a2 + 4));
if ( v8 < 0 )
goto LABEL_7;
LABEL_14:
if ( buf != 1 )
{
v7 = v8 - 4;
memcpy(dest, src, v8 - 4);
return v7;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *dest, int a2, int a3)
{
int v4; // ebx
int v5; // edi
int v6; // eax
unsigned int v7; // er15
int v8; // eax
fd_set v10; // [rsp+0h] [rbp-698h] BYREF
int buf; // [rsp+80h] [rbp-618h] BYREF
char src[1556]; // [rsp+84h] [rbp-614h] BYREF

if ( a3 != -1 )
{
v4 = a3;
memset(&v10, 0, sizeof(v10));
v5 = sock_r;
v10.fds_bits[sock_r / 64] |= 1LL << (sock_r % 64);
do
{
while ( 1 )
{
v6 = select(v5 + 1, &v10, 0LL, 0LL, 0LL);
v7 = v6;
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
{
v7 = -3;
perror("udt_recv: select");
return v7;
}
v4 -= 10;
if ( v4 <= 0 )
return 0;
v5 = sock_r;
}
if ( !v6 )
return v7;
v5 = sock_r;
}
while ( (v10.fds_bits[sock_r / 64] & (1LL << (sock_r % 64))) == 0 );
v8 = read(sock_r, &buf, (unsigned int)(a2 + 4));
if ( v8 >= 0 )
goto LABEL_14;
LABEL_7:
if ( *_errno_location() != 104 )
{
v7 = -3;
perror("udt_recv: read");
return v7;
}
return (unsigned int)-1;
}
v8 = read(sock_r, &buf, (unsigned int)(a2 + 4));
if ( v8 < 0 )
goto LABEL_7;
LABEL_14:
if ( buf != 1 )
{
v7 = v8 - 4;
memcpy(dest, src, v8 - 4);
return v7;
}
return (unsigned int)-1;
}

original_code:
int
udt_recv(void *buf, int size, int timeout)
{
 int cnt;
 int nfd;
 long t;
 fd_set rdfds;
 struct lowerpkt lpkt;
 if (timeout == -1) {
  if ((cnt = read(sock_r, &lpkt, size+4)) < 0) {
   if ((*__errno_location ()) == 104)
    return -1;
   perror("udt_recv: read");
   return -3;
  }
  goto recvd;
 }
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rdfds)->__fds_bits)[((sock_r) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock_r) % (8 * (int) sizeof (__fd_mask)))))));
again:
 if ((nfd = select(sock_r + 1, &rdfds, ((void *)0), ((void *)0), ((void *)0))) < 0) {
  if ((*__errno_location ()) == 4) {
   timeout -= 10;
   if (timeout <= 0)
    return 0;
   goto again;
  } else {
   perror("udt_recv: select");
   return -3;
  }
 } else if (nfd > 0) {
  if (!((((&rdfds)->__fds_bits)[((sock_r) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock_r) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   goto again;
  if ((cnt = read(sock_r, &lpkt, size+4)) < 0) {
   if ((*__errno_location ()) == 104)
    return -1;
   perror("udt_recv: read");
   return -3;
  }
  goto recvd;
 } else {
  return 0;
 }
recvd:
 if (lpkt.lp_type == 1)
  return -1;
 cnt -= 4;
 bcopy(lpkt.lp_buf, buf, cnt);
 return cnt;
}

canonical_original_code:
int udt_recv(void *buf, int size, int timeout)
{
 int cnt;
 int nfd;
 long t;
 struct fd_set rdfds;
 struct lowerpkt lpkt;
 if (timeout == -1) {
  if ((cnt = read(sock_r, &lpkt, size+4)) < 0) {
   if ((*__errno_location ()) == 104)
    return -1;
   perror("udt_recv: read");
   return -3;
  }
  goto recvd;
 }
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdfds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rdfds)->__fds_bits)[((sock_r) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock_r) % (8 * (int) sizeof (__fd_mask)))))));
again:
 if ((nfd = select(sock_r + 1, &rdfds, ((void *)0), ((void *)0), ((void *)0))) < 0) {
  if ((*__errno_location ()) == 4) {
   timeout -= 10;
   if (timeout <= 0)
    return 0;
   goto again;
  } else {
   perror("udt_recv: select");
   return -3;
  }
 } else if (nfd > 0) {
  if (!((((&rdfds)->__fds_bits)[((sock_r) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock_r) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   goto again;
  if ((cnt = read(sock_r, &lpkt, size+4)) < 0) {
   if ((*__errno_location ()) == 104)
    return -1;
   perror("udt_recv: read");
   return -3;
  }
  goto recvd;
 } else {
  return 0;
 }
recvd:
 if (lpkt.lp_type == 1)
  return -1;
 cnt -= 4;
 bcopy(lpkt.lp_buf, buf, cnt);
 return cnt;
}

variable_types: timeout int

variable_types: nfd int

variable_types: t long

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

variable_types: struct lowerpkt { int lp_type; char lp_buf[1500]; }