decompiled_code:
void __fastcall reader_close(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, int a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, void *ptr)
{
char *v11; // rbx
void *v12; // rdi
void *v13; // rdi

if ( a8 != -1 || HIDWORD(a7) != -1 )
{
if ( (_DWORD)a7 == 3 )
{
readadiosbp_close(a1, a2, 3LL, a4, a5);
}
else if ( (_DWORD)a7 != 4 )
{
fprintf(stderr, "reader_close: unknown file type is given: %d\n", (unsigned int)a7);
exit(200);
}
if ( (int)a9 > 0 )
{
v11 = (char *)ptr;
do
{
v13 = (void *)*((_QWORD *)v11 + 1);
if ( *(void **)v11 != v13 && v13 )
{
free(v13);
*((_QWORD *)v11 + 1) = 0LL;
}
if ( *(_QWORD *)v11 )
{
free(*(void **)v11);
*(_QWORD *)v11 = 0LL;
}
*((_QWORD *)v11 + 1) = 0LL;
v12 = (void *)*((_QWORD *)v11 + 7);
if ( v12 )
{
free(v12);
*((_QWORD *)v11 + 7) = 0LL;
}
v11 += 64;
}
while ( v11 != (char *)ptr + 64 * (unsigned __int64)(unsigned int)(a9 - 1) + 64 );
}
if ( ptr )
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, int a6, __int64 a7, __int64 a8, __int64 a9, __int64 a10, void *ptr)
{
char *v11; // rbx
void *v12; // rdi
void *v13; // rdi

if ( a8 != -1 || HIDWORD(a7) != -1 )
{
if ( (_DWORD)a7 == 3 )
{
readadiosbp_close(a1, a2, 3LL, a4, a5);
}
else if ( (_DWORD)a7 != 4 )
{
fprintf(stderr, "reader_close: unknown file type is given: %d\n", (unsigned int)a7);
exit(200);
}
if ( (int)a9 > 0 )
{
v11 = (char *)ptr;
do
{
v13 = (void *)*((_QWORD *)v11 + 1);
if ( *(void **)v11 != v13 && v13 )
{
free(v13);
*((_QWORD *)v11 + 1) = 0LL;
}
if ( *(_QWORD *)v11 )
{
free(*(void **)v11);
*(_QWORD *)v11 = 0LL;
}
*((_QWORD *)v11 + 1) = 0LL;
v12 = (void *)*((_QWORD *)v11 + 7);
if ( v12 )
{
free(v12);
*((_QWORD *)v11 + 7) = 0LL;
}
v11 += 64;
}
while ( v11 != (char *)ptr + 64 * (unsigned __int64)(unsigned int)(a9 - 1) + 64 );
}
if ( ptr )
free(ptr);
}
}

original_code:
void reader_close(DataFile df) {
    int i;
    if (df.fd == -1 && df.fh == -1)
        return;
    switch (df.type) {
 case(adiosbp_file):
     readadiosbp_close(df);
     break;
 case(ascii_file):
     break;
 default:
     fprintf(stderr, "reader_close: unknown file type is given: %d\n", (int) df.type);
     exit(200);
     break;
    }
    for (i=0; i < df.nvars; i++) {
        if (df.varinfo[i].dispname != df.varinfo[i].name)
            if (df.varinfo[i].dispname) { free(df.varinfo[i].dispname); df.varinfo[i].dispname=((void *)0); };
 if (df.varinfo[i].name) { free(df.varinfo[i].name); df.varinfo[i].name=((void *)0); };
        df.varinfo[i].dispname = ((void *)0);
 if (df.varinfo[i].groupname) { free(df.varinfo[i].groupname); df.varinfo[i].groupname=((void *)0); };
    }
    if (df.varinfo) { free(df.varinfo); df.varinfo=((void *)0); };
    df.fd = -1;
    df.fh = -1;
}

canonical_original_code:
void reader_close(struct DataFile df) {
    int i;
    if (df.fd == -1 && df.fh == -1)
        return;
    switch (df.type) {
 case(adiosbp_file):
     readadiosbp_close(df);
     break;
 case(ascii_file):
     break;
 default:
     fprintf(stderr, "reader_close: unknown file type is given: %d\n", (int) df.type);
     exit(200);
     break;
    }
    for (i=0; i < df.nvars; i++) {
        if (df.varinfo[i].dispname != df.varinfo[i].name)
            if (df.varinfo[i].dispname) { free(df.varinfo[i].dispname); df.varinfo[i].dispname=((void *)0); };
 if (df.varinfo[i].name) { free(df.varinfo[i].name); df.varinfo[i].name=((void *)0); };
        df.varinfo[i].dispname = ((void *)0);
 if (df.varinfo[i].groupname) { free(df.varinfo[i].groupname); df.varinfo[i].groupname=((void *)0); };
    }
    if (df.varinfo) { free(df.varinfo); df.varinfo=((void *)0); };
    df.fd = -1;
    df.fh = -1;
}

variable_types: struct DataFile { enum FileType { undef_file=0, netcdf_file=1, hdf5_file=2, adiosbp_file=3, ascii_file=4 } type; int fd; long fh; int nvars; int ngroups; int time_start; int time_stop; struct VarInfo { char *name; char *dispname; enum ArrayType { undefArray=0, int8Array=1, int16Array=2, int32Array=3, int64Array=4, floatArray=5, doubleArray=6 } type; int varid; int ndims; int dimsize[5]; int timedim; char *groupname; } *varinfo; }

variable_types: i int

user_defined_types: struct DataFile { enum FileType type; int fd; long fh; int nvars; int ngroups; int time_start; int time_stop; struct VarInfo *varinfo; }

user_defined_types: struct VarInfo { char *name; char *dispname; enum ArrayType type; int varid; int ndims; int dimsize[5]; int timedim; char *groupname; }


original_code:
void print_DFinfo( DataFile df) {
    int i, j;
    printf("==============================\n");
    printf("DataFile: fd=%d", df.fd);
    printf(" type=%s", fileTypeStrings[df.type]);
    printf(" nvars=%d\n", df.nvars);
    for (i=0; i < df.nvars; i++) {
 printf("  var=%s  type=%d  varid=%d  ndims=%d (",
  df.varinfo[i].name, df.varinfo[i].type,
  df.varinfo[i].varid, df.varinfo[i].ndims);
 for (j=0; j < df.varinfo[i].ndims; j++)
     printf("%d ", df.varinfo[i].dimsize[j]);
 printf(")\n");
    }
    printf("==============================\n");
}

canonical_original_code:
void print_DFinfo(struct DataFile df) {
    int i; int j;
    printf("==============================\n");
    printf("DataFile: fd=%d", df.fd);
    printf(" type=%s", fileTypeStrings[df.type]);
    printf(" nvars=%d\n", df.nvars);
    for (i=0; i < df.nvars; i++) {
 printf("  var=%s  type=%d  varid=%d  ndims=%d (",
  df.varinfo[i].name, df.varinfo[i].type,
  df.varinfo[i].varid, df.varinfo[i].ndims);
 for (j=0; j < df.varinfo[i].ndims; j++)
     printf("%d ", df.varinfo[i].dimsize[j]);
 printf(")\n");
    }
    printf("==============================\n");
}

variable_types: j int

return_type: void

user_defined_types: enum FileType { undef_file=0, netcdf_file=1, hdf5_file=2, adiosbp_file=3, ascii_file=4 }

user_defined_types: enum ArrayType { undefArray=0, int8Array=1, int16Array=2, int32Array=3, int64Array=4, floatArray=5, doubleArray=6 }


getbasename

decompiled_code:
char *__fastcall getbasename(const char *a1, char **a2)
{
char *v2; // rbx
char *v3; // rax
char *v4; // rax
char *v5; // rbp
char *v6; // rbp

v2 = strdup(a1);
v3 = &v2[strlen(v2) - 1];
if ( *v3 == 47 )
*v3 = 48;
v4 = rindex(v2, 47);
v5 = v4;
if ( !v4 || v2 == v4 )
{
*a2 = 0LL;
v6 = strdup(v2);
}
else
{
*v4 = 0;
*a2 = strdup(v2);
*v5 = 47;
v6 = strdup(v5 + 1);
}
free(v2);
return v6;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, char **a2)
{
char *v2; // rbx
char *v3; // rax
char *v4; // rax
char *v5; // rbp
char *v6; // rbp

v2 = strdup(a1);
v3 = &v2[strlen(v2) - 1];
if ( *v3 == 47 )
*v3 = 48;
v4 = rindex(v2, 47);
v5 = v4;
if ( !v4 || v2 == v4 )
{
*a2 = 0LL;
v6 = strdup(v2);
}
else
{
*v4 = 0;
*a2 = strdup(v2);
*v5 = 47;
v6 = strdup(v5 + 1);
}
free(v2);
return v6;
}

original_code:
char* getbasename( char *path, char **dirname )
{
    char *work, *base, *ptr;
    work = strdup(path);
    if (work[strlen(work)-1] == '/')
  work[strlen(work)-1] = '0';
    ptr = rindex(work, '/');
    if (ptr && ptr != work) {
       ptr[0] = 0;
       *dirname = strdup(work);
       ptr[0] = '/';
       base = strdup(ptr+1);
    }
    else {
 *dirname = ((void *)0);
 base =strdup(work);
    }
    free(work);
    return base;
}

canonical_original_code:
char *getbasename(char *path, char **dirname)
{
    char *work; char *base; char *ptr;
    work = strdup(path);
    if (work[strlen(work)-1] == '/')
  work[strlen(work)-1] = '0';
    ptr = rindex(work, '/');
    if (ptr && ptr != work) {
       ptr[0] = 0;
       *dirname = strdup(work);
       ptr[0] = '/';
       base = strdup(ptr+1);
    }
    else {
 *dirname = ((void *)0);
 base =strdup(work);
    }
    free(work);
    return base;
}

variable_types:
path
char *

variable_types:
dirname
char **

variable_types:
work
char *

variable_types:
base
char *

variable_types:
ptr
char *

return_type: char *


decompiled_code:
bool __fastcall file_exists(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

canonical_decompiled_code:
bool __fastcall func1(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

original_code:
bool file_exists (char * path)
{
    struct stat sb;
    int i = stat ( path, &sb );
    if ( i == 0 )
 return 1;
    return 0;
}

canonical_original_code:
char file_exists(char *path)
{
    struct stat sb;
    int i = stat ( path, &sb );
    if ( i == 0 )
 return 1;
    return 0;
}

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

return_type: char

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


decompiled_code:
__int64 __fastcall is_dir(const char *a1)
{
int v1; // edx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
int v1; // edx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

original_code:
bool is_dir(char *path) {
     struct stat sb;
     if ( !stat( path, &sb) ) {
         if ( sb.st_mode & 0040000 ) {
             return 1;
         }
     }
     return 0;
}

canonical_original_code:
char is_dir(char *path) {
     struct stat sb;
     if ( !stat( path, &sb) ) {
         if ( sb.st_mode & 0040000 ) {
             return 1;
         }
     }
     return 0;
}

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


decompiled_code:
__int64 __fastcall createdir_recursive(const char *a1)
{
char *v2; // r12
unsigned int v3; // ebp
int v5; // edi
char *v6; // rax
char *v7; // rax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = getbasename(a1, (char **)&ptr);
if ( ptr )
{
if ( (unsigned __int8)is_dir((const char *)ptr) )
{
free(ptr);
}
else
{
v3 = createdir_recursive(ptr);
free(ptr);
if ( v3 )
return v3;
}
}
v3 = 0;
if ( !file_exists(a1) )
{
v3 = mkdir(a1, 0x1EDu);
if ( v3 )
{
v5 = *_errno_location();
if ( v5 == 17 )
{
v7 = strerror(17);
fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", a1, v7);
fwrite("Some other process created this dir already during this function call\n", 1uLL, 0x46uLL, stderr);
v3 = 0;
}
else
{
v6 = strerror(v5);
fprintf(stderr, "createdir %s failed: %s\n", a1, v6);
}
}
}
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char *v2; // r12
unsigned int v3; // ebp
int v5; // edi
char *v6; // rax
char *v7; // rax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = func0(a1, (char **)&ptr);
if ( ptr )
{
if ( (unsigned __int8)func2((const char *)ptr) )
{
free(ptr);
}
else
{
v3 = func3(ptr);
free(ptr);
if ( v3 )
return v3;
}
}
v3 = 0;
if ( !func1(a1) )
{
v3 = mkdir(a1, 0x1EDu);
if ( v3 )
{
v5 = *_errno_location();
if ( v5 == 17 )
{
v7 = strerror(17);
fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", a1, v7);
fwrite("Some other process created this dir already during this function call\n", 1uLL, 0x46uLL, stderr);
v3 = 0;
}
else
{
v6 = strerror(v5);
fprintf(stderr, "createdir %s failed: %s\n", a1, v6);
}
}
}
free(v2);
return v3;
}

original_code:
int createdir_recursive( char* path)
{
    int res;
    char *dirs, *base;
    base = getbasename(path, &dirs);
    if ( dirs != ((void *)0)) {
        if ( !is_dir(dirs) ) {
            res = createdir_recursive(dirs);
 } else res = 0;
        free(dirs);
        if (res) return res;
    }
    if (file_exists(path))
        res = 0;
    else
        res = mkdir(path, (0400|0200|0100) | (0400 >> 3) | (0100 >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3));
    if (res) {
        if ((*__errno_location ()) == 17) {
            fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", path, strerror((*__errno_location ())));
            fprintf(stderr, "Some other process created this dir already during this function call\n");
            res = 0;
        } else {
            fprintf(stderr, "createdir %s failed: %s\n", path, strerror((*__errno_location ())));
        }
    }
    free(base);
    return (res);
}

canonical_original_code:
int createdir_recursive(char *path)
{
    int res;
    char *dirs; char *base;
    base = getbasename(path, &dirs);
    if ( dirs != ((void *)0)) {
        if ( !is_dir(dirs) ) {
            res = createdir_recursive(dirs);
 } else res = 0;
        free(dirs);
        if (res) return res;
    }
    if (file_exists(path))
        res = 0;
    else
        res = mkdir(path, (0400|0200|0100) | (0400 >> 3) | (0100 >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3));
    if (res) {
        if ((*__errno_location ()) == 17) {
            fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", path, strerror((*__errno_location ())));
            fprintf(stderr, "Some other process created this dir already during this function call\n");
            res = 0;
        } else {
            fprintf(stderr, "createdir %s failed: %s\n", path, strerror((*__errno_location ())));
        }
    }
    free(base);
    return (res);
}

variable_types: res int

variable_types:
dirs
char *

return_type: int


decompiled_code:
void *init_gtable()
{
void *result; // rax

result = memset(&gtable, 0, 0x5DC0uLL);
elemnum = 0;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

result = memset(&gtable, 0, 0x5DC0uLL);
elemnum = 0;
return result;
}

original_code:
static void init_gtable(void)
{
  memset(gtable, 0, 1000*sizeof(gelem));
  elemnum=0;
}

canonical_original_code:
static void init_gtable()
{
  memset(gtable, 0, 1000*sizeof(gelem));
  elemnum=0;
}


decompiled_code:
__int64 __fastcall gtable_get(char *s1)
{
int v1; // er13
const char **v2; // rbp
unsigned int v3; // ebx

v1 = elemnum;
if ( elemnum <= 0 )
{
v3 = 0;
}
else
{
v2 = (const char **)&gtable;
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return (unsigned int)-1;
}
}
if ( v1 == v3 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
int v1; // er13
const char **v2; // rbp
unsigned int v3; // ebx

v1 = elemnum;
if ( elemnum <= 0 )
{
v3 = 0;
}
else
{
v2 = (const char **)&gtable;
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return (unsigned int)-1;
}
}
if ( v1 == v3 )
v3 = -1;
return v3;
}

original_code:
static int gtable_get(char * name) {
    int i;
    for (i = 0; i < elemnum; i++) {
 if (!strcmp(name, gtable[i].name)) break;
    }
    if (i == elemnum) {
 i = -1;
    }
    return i;
}

canonical_original_code:
static int gtable_get(char *name) {
    int i;
    for (i = 0; i < elemnum; i++) {
 if (!strcmp(name, gtable[i].name)) break;
    }
    if (i == elemnum) {
 i = -1;
    }
    return i;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall minmax_open(char *src, unsigned int a2)
{
__int64 result; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( src )
strncpy(v7, src, 0x400uLL);
else
strcpy(v7, "minmax1D.dat");
if ( (_BYTE)a2 )
{
fminmax = fopen(v7, "r");
if ( fminmax )
{
LABEL_5:
init_gtable();
return 1LL;
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Error at opening for reading minmax file %s: %s\n", v7, v4);
result = 0LL;
}
else
{
fminmax = fopen(v7, "a+");
if ( fminmax )
goto LABEL_5;
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Error at opening for writing minmax file %s: %s\n", v7, v6);
result = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, unsigned int a2)
{
__int64 result; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( src )
strncpy(v7, src, 0x400uLL);
else
strcpy(v7, "minmax1D.dat");
if ( (_BYTE)a2 )
{
fminmax = fopen(v7, "r");
if ( fminmax )
{
LABEL_5:
func0();
return 1LL;
}
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Error at opening for reading minmax file %s: %s\n", v7, v4);
result = 0LL;
}
else
{
fminmax = fopen(v7, "a+");
if ( fminmax )
goto LABEL_5;
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Error at opening for writing minmax file %s: %s\n", v7, v6);
result = a2;
}
return result;
}

original_code:
bool minmax_open( char *path, bool readmode) {
    char fn[1024];
    if ( path != ((void *)0))
 strncpy(fn, path, 1024);
    else
 snprintf(fn, 1024, "minmax1D.dat");
    if ( readmode ) {
 if ((fminmax = fopen(fn,"r")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for reading minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    } else {
 if ((fminmax = fopen(fn,"a+")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for writing minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    }
    init_gtable();
    return 1;
}

canonical_original_code:
char minmax_open(char *path, char readmode) {
    char fn[1024];
    if ( path != ((void *)0))
 strncpy(fn, path, 1024);
    else
 snprintf(fn, 1024, "minmax1D.dat");
    if ( readmode ) {
 if ((fminmax = fopen(fn,"r")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for reading minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    } else {
 if ((fminmax = fopen(fn,"a+")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for writing minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    }
    init_gtable();
    return 1;
}

variable_types: readmode char

variable_types:
fn
char [1024]


decompiled_code:
int minmax_close()
{
int result; // eax

if ( fminmax )
result = fclose(fminmax);
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

if ( fminmax )
result = fclose(fminmax);
return result;
}

original_code:
void minmax_close() {
    if (fminmax)
 fclose(fminmax);
}


decompiled_code:
int __fastcall minmax_print(const char *a1, unsigned int a2, double a3, double a4)
{
int result; // eax

result = (int)fminmax;
if ( fminmax )
result = fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", a1, a2, a3, a4);
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, unsigned int a2, double a3, double a4)
{
int result; // eax

result = (int)fminmax;
if ( fminmax )
result = fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", a1, a2, a3, a4);
return result;
}

original_code:
void minmax_print(char* varname, int time, double min, double max) {
    if (fminmax)
 fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", varname, time, min, max);
}

canonical_original_code:
void minmax_print(char *varname, int time, double min, double max) {
    if (fminmax)
 fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", varname, time, min, max);
}

variable_types:
varname
char *

variable_types: time int

variable_types: min double

variable_types: max double


decompiled_code:
int __fastcall minmax_get(char *s1, double *a2, double *a3, double a4)
{
int v5; // eax
double v6; // xmm1_8
double v7; // rax
double v9; // [rsp+8h] [rbp-430h] BYREF
char s[1064]; // [rsp+10h] [rbp-428h] BYREF

sprintf(s, "%.12g", a4);
_isoc99_sscanf(s, "%lg", &v9);
if ( !elemnum )
read_minmax(v9);
v5 = gtable_get(s1);
if ( v5 < 0 )
{
LODWORD(v7) = fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", s1);
*a2 = a4;
*a3 = a4;
}
else
{
*(_QWORD *)a2 = qword_4E8[3 * v5];
*a3 = qword_4F0[3 * v5];
v6 = v9;
v7 = *a2;
if ( *a2 == v9 )
v7 = a4;
*a2 = v7;
if ( v6 == *a3 )
*a3 = a4;
}
return LODWORD(v7);
}

canonical_decompiled_code:
int __fastcall func7(char *s1, double *a2, double *a3, double a4)
{
int v5; // eax
double v6; // xmm1_8
double v7; // rax
double v9; // [rsp+8h] [rbp-430h] BYREF
char s[1064]; // [rsp+10h] [rbp-428h] BYREF

sprintf(s, "%.12g", a4);
_isoc99_sscanf(s, "%lg", &v9);
if ( !elemnum )
func3(v9);
v5 = func1(s1);
if ( v5 < 0 )
{
LODWORD(v7) = fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", s1);
*a2 = a4;
*a3 = a4;
}
else
{
*(_QWORD *)a2 = qword_4E8[3 * v5];
*a3 = qword_4F0[3 * v5];
v6 = v9;
v7 = *a2;
if ( *a2 == v9 )
v7 = a4;
*a2 = v7;
if ( v6 == *a3 )
*a3 = a4;
}
return LODWORD(v7);
}

original_code:
void minmax_get(char* varname, double undef_value, double *gmin, double *gmax) {
    int n;
    char line[1024];
    double undef;
    sprintf(line, "%.12g", undef_value);
    sscanf(line, "%lg", &undef);
    if (elemnum == 0) {
 read_minmax(undef);
    }
    n = gtable_get(varname);
    if (n > -1) {
 *gmin = gtable[n].gmin;
 *gmax = gtable[n].gmax;
 if (*gmin == undef) *gmin = undef_value;
 if (*gmax == undef) *gmax = undef_value;
    } else {
 fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", varname);
        *gmin = undef_value;
 *gmax = undef_value;
    }
}

canonical_original_code:
void minmax_get(char *varname, double undef_value, double *gmin, double *gmax) {
    int n;
    char line[1024];
    double undef;
    sprintf(line, "%.12g", undef_value);
    sscanf(line, "%lg", &undef);
    if (elemnum == 0) {
 read_minmax(undef);
    }
    n = gtable_get(varname);
    if (n > -1) {
 *gmin = gtable[n].gmin;
 *gmax = gtable[n].gmax;
 if (*gmin == undef) *gmin = undef_value;
 if (*gmax == undef) *gmax = undef_value;
    } else {
 fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", varname);
        *gmin = undef_value;
 *gmax = undef_value;
    }
}

variable_types:
gmin
double *

variable_types:
gmax
double *

variable_types: n int

variable_types:
line
char [1024]

variable_types: undef double


modifyheaders

repo: rtokarev/OPENRELEASE

original_code:
static int modifyheaders(Elf32_Ehdr *ehdr, Elf32_Phdr *phdrs,
    unsigned long newsize)
{
    Elf32_Phdr *phdr;
    int i;
    if (ehdr->e_shoff >= newsize) {
 ehdr->e_shoff = 0;
 ehdr->e_shnum = 0;
 ehdr->e_shentsize = 0;
 ehdr->e_shstrndx = 0;
    }
    for (i = 0, phdr = phdrs ; i < ehdr->e_phnum ; ++i, ++phdr) {
 if (phdr->p_offset >= newsize) {
     phdr->p_offset = newsize;
     phdr->p_filesz = 0;
 } else if (phdr->p_offset + phdr->p_filesz > newsize) {
     phdr->p_filesz = newsize - phdr->p_offset;
 }
    }
    return 1;
}

canonical_original_code:
static int modifyheaders(struct Elf32_Ehdr *ehdr, struct Elf32_Phdr *phdrs, unsigned long newsize)
{
    struct Elf32_Phdr *phdr;
    int i;
    if (ehdr->e_shoff >= newsize) {
 ehdr->e_shoff = 0;
 ehdr->e_shnum = 0;
 ehdr->e_shentsize = 0;
 ehdr->e_shstrndx = 0;
    }
    for (i = 0, phdr = phdrs ; i < ehdr->e_phnum ; ++i, ++phdr) {
 if (phdr->p_offset >= newsize) {
     phdr->p_offset = newsize;
     phdr->p_filesz = 0;
 } else if (phdr->p_offset + phdr->p_filesz > newsize) {
     phdr->p_filesz = newsize - phdr->p_offset;
 }
    }
    return 1;
}

variable_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *

variable_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *

variable_types:
newsize
unsigned long

variable_types: i int


err

decompiled_code:
void __fastcall __noreturn err(const char *a1)
{
fprintf(_bss_start, "%s: %s: %s\n", (const char *)progname, (const char *)filename, a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
fprintf(_bss_start, "%s: %s: %s\n", (const char *)progname, (const char *)filename, a1);
}

original_code:
static int err(char const *errmsg)
{
    fprintf(stderr, "%s: %s: %s\n", progname, filename, errmsg);
    return 0;
}

canonical_original_code:
static int err(char *errmsg)
{
    fprintf(stderr, "%s: %s: %s\n", progname, filename, errmsg);
    return 0;
}

variable_types:
errmsg
char *


readelfheader

decompiled_code:
__int64 __fastcall readelfheader(int fd, void *buf)
{
int *v2; // rbp
char *v3; // rdi
__int64 result; // rax

v2 = __errno_location();
*v2 = 0;
if ( read(fd, buf, 0x34uLL) != 52 )
{
v3 = "missing or incomplete ELF header.";
if ( *v2 )
v3 = strerror(*v2);
err(v3);
}
if ( *(_DWORD *)buf != 1179403647 )
err("missing ELF signature.");
if ( *((_BYTE *)buf + 5) != 1 )
err("ELF file has different endianness.");
if ( *((_BYTE *)buf + 4) != 1 )
err("ELF file has different word size.");
if ( *((_WORD *)buf + 20) != 52 )
err("unrecognized ELF header size.");
if ( *((_WORD *)buf + 21) != 32 )
err("unrecognized program segment header size.");
result = 1LL;
if ( (unsigned __int16)(*((_WORD *)buf + 8) - 2) > 1u )
err("not an executable or shared-object library.");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, void *buf)
{
int *v2; // rbp
char *v3; // rdi
__int64 result; // rax

v2 = __errno_location();
*v2 = 0;
if ( read(fd, buf, 0x34uLL) != 52 )
{
v3 = "missing or incomplete ELF header.";
if ( *v2 )
v3 = strerror(*v2);
func9(v3);
}
if ( *(_DWORD *)buf != 1179403647 )
func9("missing ELF signature.");
if ( *((_BYTE *)buf + 5) != 1 )
func9("ELF file has different endianness.");
if ( *((_BYTE *)buf + 4) != 1 )
func9("ELF file has different word size.");
if ( *((_WORD *)buf + 20) != 52 )
func9("unrecognized ELF header size.");
if ( *((_WORD *)buf + 21) != 32 )
func9("unrecognized program segment header size.");
result = 1LL;
if ( (unsigned __int16)(*((_WORD *)buf + 8) - 2) > 1u )
func9("not an executable or shared-object library.");
return result;
}

original_code:
static int readelfheader(int fd, Elf32_Ehdr *ehdr)
{
    (*__errno_location ()) = 0;
    if (read(fd, ehdr, sizeof *ehdr) != sizeof *ehdr)
 return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("missing or incomplete ELF header.")));
    if (!(ehdr->e_ident[0] == 0x7f &&
   ehdr->e_ident[1] == 'E' &&
   ehdr->e_ident[2] == 'L' &&
   ehdr->e_ident[3] == 'F'))
 return err("missing ELF signature.");
    if (ehdr->e_ident[5] != 1)
 return err("ELF file has different endianness.");
    if (ehdr->e_ident[4] != 1)
 return err("ELF file has different word size.");
    if (ehdr->e_ehsize != sizeof(Elf32_Ehdr))
 return err("unrecognized ELF header size.");
    if (ehdr->e_phentsize != sizeof(Elf32_Phdr))
 return err("unrecognized program segment header size.");
    if (ehdr->e_type != 2 && ehdr->e_type != 3)
 return err("not an executable or shared-object library.");
    return 1;
}

canonical_original_code:
static int readelfheader(int fd, struct Elf32_Ehdr *ehdr)
{
    (*__errno_location ()) = 0;
    if (read(fd, ehdr, sizeof *ehdr) != sizeof *ehdr)
 return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("missing or incomplete ELF header.")));
    if (!(ehdr->e_ident[0] == 0x7f &&
   ehdr->e_ident[1] == 'E' &&
   ehdr->e_ident[2] == 'L' &&
   ehdr->e_ident[3] == 'F'))
 return err("missing ELF signature.");
    if (ehdr->e_ident[5] != 1)
 return err("ELF file has different endianness.");
    if (ehdr->e_ident[4] != 1)
 return err("ELF file has different word size.");
    if (ehdr->e_ehsize != sizeof(Elf32_Ehdr))
 return err("unrecognized ELF header size.");
    if (ehdr->e_phentsize != sizeof(Elf32_Phdr))
 return err("unrecognized program segment header size.");
    if (ehdr->e_type != 2 && ehdr->e_type != 3)
 return err("not an executable or shared-object library.");
    return 1;
}

variable_types: fd int

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }


readphdrtable

decompiled_code:
__int64 __fastcall readphdrtable(int fd, __int64 a2, void **a3)
{
unsigned __int16 v4; // ax
size_t v5; // rbx
void *v6; // rax
int *v7; // r13
ssize_t v8; // rdx
__int64 result; // rax
char *v10; // rdi

if ( !*(_DWORD *)(a2 + 28) || (v4 = *(_WORD *)(a2 + 44)) == 0 )
err("ELF file has no program header table.");
v5 = 32LL * v4;
v6 = malloc(v5);
*a3 = v6;
if ( !v6 )
err("Out of memory!");
v7 = __errno_location();
*v7 = 0;
v8 = read(fd, *a3, v5);
result = 1LL;
if ( v8 != v5 )
{
v10 = "missing or incomplete program segment header table.";
if ( *v7 )
v10 = strerror(*v7);
err(v10);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, __int64 a2, void **a3)
{
unsigned __int16 v4; // ax
size_t v5; // rbx
void *v6; // rax
int *v7; // r13
ssize_t v8; // rdx
__int64 result; // rax
char *v10; // rdi

if ( !*(_DWORD *)(a2 + 28) || (v4 = *(_WORD *)(a2 + 44)) == 0 )
func9("ELF file has no program header table.");
v5 = 32LL * v4;
v6 = malloc(v5);
*a3 = v6;
if ( !v6 )
func9("Out of memory!");
v7 = __errno_location();
*v7 = 0;
v8 = read(fd, *a3, v5);
result = 1LL;
if ( v8 != v5 )
{
v10 = "missing or incomplete program segment header table.";
if ( *v7 )
v10 = strerror(*v7);
func9(v10);
}
return result;
}

original_code:
static int readphdrtable(int fd, Elf32_Ehdr const *ehdr, Elf32_Phdr **phdrs)
{
    size_t size;
    if (!ehdr->e_phoff || !ehdr->e_phnum)
 return err("ELF file has no program header table.");
    size = ehdr->e_phnum * sizeof **phdrs;
    if (!(*phdrs = malloc(size)))
 return err("Out of memory!");
    (*__errno_location ()) = 0;
    if (read(fd, *phdrs, size) != (ssize_t)size)
 return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("missing or incomplete program segment header table.")));
    return 1;
}

canonical_original_code:
static int readphdrtable(int fd, struct Elf32_Ehdr *ehdr, struct Elf32_Phdr **phdrs)
{
    unsigned long size;
    if (!ehdr->e_phoff || !ehdr->e_phnum)
 return err("ELF file has no program header table.");
    size = ehdr->e_phnum * sizeof **phdrs;
    if (!(*phdrs = malloc(size)))
 return err("Out of memory!");
    (*__errno_location ()) = 0;
    if (read(fd, *phdrs, size) != (long)size)
 return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("missing or incomplete program segment header table.")));
    return 1;
}

variable_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } **

variable_types:
size
unsigned long


truncatezeros

decompiled_code:
__int64 __fastcall truncatezeros(int fd, unsigned __int64 *a2)
{
unsigned __int64 v2; // rbp
int v3; // eax
char *v4; // rdi
int v5; // eax
char *v6; // rdi
size_t v7; // rbx
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = *a2;
do
{
v7 = 1024LL;
if ( v2 <= 0x3FF )
v7 = v2;
if ( lseek(fd, v2 - v7, 0) == -1 )
{
v3 = *__errno_location();
v4 = "cannot seek in file.";
if ( v3 )
v4 = strerror(v3);
err(v4);
}
if ( read(fd, v9, v7) != v7 )
{
v5 = *__errno_location();
v6 = "cannot read file contents";
if ( v5 )
v6 = strerror(v5);
err(v6);
}
for ( ; v7; --v2 )
{
if ( v9[--v7] )
break;
}
}
while ( v2 && !v7 );
if ( !v2 )
err("ELF file is completely blank!");
*a2 = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, unsigned __int64 *a2)
{
unsigned __int64 v2; // rbp
int v3; // eax
char *v4; // rdi
int v5; // eax
char *v6; // rdi
size_t v7; // rbx
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = *a2;
do
{
v7 = 1024LL;
if ( v2 <= 0x3FF )
v7 = v2;
if ( lseek(fd, v2 - v7, 0) == -1 )
{
v3 = *__errno_location();
v4 = "cannot seek in file.";
if ( v3 )
v4 = strerror(v3);
func9(v4);
}
if ( read(fd, v9, v7) != v7 )
{
v5 = *__errno_location();
v6 = "cannot read file contents";
if ( v5 )
v6 = strerror(v5);
func9(v6);
}
for ( ; v7; --v2 )
{
if ( v9[--v7] )
break;
}
}
while ( v2 && !v7 );
if ( !v2 )
func9("ELF file is completely blank!");
*a2 = v2;
return 1LL;
}

original_code:
static int truncatezeros(int fd, unsigned long *newsize)
{
    unsigned char contents[1024];
    unsigned long size, n;
    size = *newsize;
    do {
 n = sizeof contents;
 if (n > size)
     n = size;
 if (lseek(fd, size - n, 0) == (off_t)-1)
     return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("cannot seek in file.")));
 if (read(fd, contents, n) != (ssize_t)n)
     return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("cannot read file contents")));
 while (n && !contents[--n])
     --size;
    } while (size && !n);
    if (!size)
 return err("ELF file is completely blank!");
    *newsize = size;
    return 1;
}

canonical_original_code:
static int truncatezeros(int fd, unsigned long *newsize)
{
    unsigned char contents[1024];
    unsigned long size; unsigned long n;
    size = *newsize;
    do {
 n = sizeof contents;
 if (n > size)
     n = size;
 if (lseek(fd, size - n, 0) == (off_t)-1)
     return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("cannot seek in file.")));
 if (read(fd, contents, n) != (long)n)
     return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("cannot read file contents")));
 while (n && !contents[--n])
     --size;
    } while (size && !n);
    if (!size)
 return err("ELF file is completely blank!");
    *newsize = size;
    return 1;
}

variable_types:
newsize
unsigned long *

variable_types:
contents
unsigned char [1024]

variable_types:
n
unsigned long


commitchanges

decompiled_code:
__int64 __fastcall commitchanges(int fd, void *buf, void *a3, unsigned __int64 a4)
{
int v6; // eax
char *v7; // rdi
size_t v8; // r14
unsigned __int64 v9; // r14
__off_t v10; // rsi
int v11; // edx
__int64 result; // rax

if ( lseek(fd, 0LL, 0) )
{
v6 = *__errno_location();
v7 = "could not rewind file";
if ( v6 )
v7 = strerror(v6);
err(v7);
}
*__errno_location() = 0;
if ( write(fd, buf, 0x34uLL) != 52 )
err("could not modify file");
if ( lseek(fd, *((unsigned int *)buf + 7), 0) == -1 )
err("could not seek in file.");
v8 = 32LL * *((unsigned __int16 *)buf + 22);
if ( write(fd, a3, v8) != v8 )
err("could not write to file");
v9 = *((unsigned int *)buf + 7) + v8;
v10 = a4;
if ( v9 >= a4 )
v10 = v9;
v11 = ftruncate(fd, v10);
result = 1LL;
if ( v11 )
err("could not resize file");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd, void *buf, void *a3, unsigned __int64 a4)
{
int v6; // eax
char *v7; // rdi
size_t v8; // r14
unsigned __int64 v9; // r14
__off_t v10; // rsi
int v11; // edx
__int64 result; // rax

if ( lseek(fd, 0LL, 0) )
{
v6 = *__errno_location();
v7 = "could not rewind file";
if ( v6 )
v7 = strerror(v6);
func9(v7);
}
*__errno_location() = 0;
if ( write(fd, buf, 0x34uLL) != 52 )
func9("could not modify file");
if ( lseek(fd, *((unsigned int *)buf + 7), 0) == -1 )
func9("could not seek in file.");
v8 = 32LL * *((unsigned __int16 *)buf + 22);
if ( write(fd, a3, v8) != v8 )
func9("could not write to file");
v9 = *((unsigned int *)buf + 7) + v8;
v10 = a4;
if ( v9 >= a4 )
v10 = v9;
v11 = ftruncate(fd, v10);
result = 1LL;
if ( v11 )
func9("could not resize file");
return result;
}

original_code:
static int commitchanges(int fd, Elf32_Ehdr const *ehdr, Elf32_Phdr *phdrs,
    unsigned long newsize)
{
    size_t n;
    if (lseek(fd, 0, 0))
 return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("could not rewind file")));
    (*__errno_location ()) = 0;
    if (write(fd, ehdr, sizeof *ehdr) != sizeof *ehdr)
 return err("could not modify file");
    if (lseek(fd, ehdr->e_phoff, 0) == (off_t)-1) {
 err("could not seek in file.");
 goto warning;
    }
    n = ehdr->e_phnum * sizeof *phdrs;
    if (write(fd, phdrs, n) != (ssize_t)n) {
 err("could not write to file");
 goto warning;
    }
    if (newsize < ehdr->e_phoff + n)
 newsize = ehdr->e_phoff + n;
    if (ftruncate(fd, newsize)) {
 err("could not resize file");
 goto warning;
    }
    return 1;
  warning:
    return err("ELF file may have been corrupted!");
}

canonical_original_code:
static int commitchanges(int fd, struct Elf32_Ehdr *ehdr, struct Elf32_Phdr *phdrs, unsigned long newsize)
{
    unsigned long n;
    if (lseek(fd, 0, 0))
 return (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("could not rewind file")));
    (*__errno_location ()) = 0;
    if (write(fd, ehdr, sizeof *ehdr) != sizeof *ehdr)
 return err("could not modify file");
    if (lseek(fd, ehdr->e_phoff, 0) == (off_t)-1) {
 err("could not seek in file.");
 goto warning;
    }
    n = ehdr->e_phnum * sizeof *phdrs;
    if (write(fd, phdrs, n) != (long)n) {
 err("could not write to file");
 goto warning;
    }
    if (newsize < ehdr->e_phoff + n)
 newsize = ehdr->e_phoff + n;
    if (ftruncate(fd, newsize)) {
 err("could not resize file");
 goto warning;
    }
    return 1;
  warning:
    return err("ELF file may have been corrupted!");
}

user_defined_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
const char **v4; // rbp
int v5; // er12
int result; // eax
int v7; // eax
char *v8; // rdi
int v9; // eax
int v10; // ebx
unsigned __int64 v11; // [rsp+0h] [rbp-68h] BYREF
void *v12; // [rsp+8h] [rbp-60h] BYREF
char buf[88]; // [rsp+10h] [rbp-58h] BYREF

if ( argc <= 1 || (v3 = argv[1], *v3 == 45) )
{
puts(
"Usage: sstrip FILE...\n"
"sstrip discards all nonessential bytes from an executable.\n"
"\n"
"Version 2.0 Copyright (C) 2000,2001 Brian Raiter.\n"
"This program is free software, licensed under the GNU\n"
"General Public License. There is absolutely no warranty.");
result = 0;
}
else
{
progname = (__int64)*argv;
v4 = argv + 1;
v5 = 0;
do
{
filename = (__int64)v3;
v9 = open(v3, 2, envp);
v10 = v9;
if ( v9 < 0 )
{
v7 = *__errno_location();
v8 = "can't open";
if ( v7 )
v8 = strerror(v7);
err(v8);
}
if ( !(unsigned int)readelfheader(v9, buf)
|| !(unsigned int)readphdrtable(v10, (__int64)buf, &v12)
|| !(unsigned int)getmemorysize((__int64)buf, v12, &v11)
|| !(unsigned int)truncatezeros(v10, &v11)
|| !(unsigned int)modifyheaders((__int64)buf, (__int64)v12, v11)
|| !(unsigned int)commitchanges(v10, buf, v12, v11) )
{
++v5;
}
close(v10);
v3 = *++v4;
}
while ( *v4 );
result = v5 != 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
const char **v4; // rbp
int v5; // er12
int result; // eax
int v7; // eax
char *v8; // rdi
int v9; // eax
int v10; // ebx
unsigned __int64 v11; // [rsp+0h] [rbp-68h] BYREF
void *v12; // [rsp+8h] [rbp-60h] BYREF
char buf[88]; // [rsp+10h] [rbp-58h] BYREF

if ( argc <= 1 || (v3 = argv[1], *v3 == 45) )
{
puts(
"Usage: sstrip FILE...\n"
"sstrip discards all nonessential bytes from an executable.\n"
"\n"
"Version 2.0 Copyright (C) 2000,2001 Brian Raiter.\n"
"This program is free software, licensed under the GNU\n"
"General Public License. There is absolutely no warranty.");
result = 0;
}
else
{
progname = (__int64)*argv;
v4 = argv + 1;
v5 = 0;
do
{
filename = (__int64)v3;
v9 = open(v3, 2, envp);
v10 = v9;
if ( v9 < 0 )
{
v7 = *__errno_location();
v8 = "can't open";
if ( v7 )
v8 = strerror(v7);
func9(v8);
}
if ( !(unsigned int)func10(v9, buf)
|| !(unsigned int)func11(v10, (__int64)buf, &v12)
|| !(unsigned int)func7((__int64)buf, v12, &v11)
|| !(unsigned int)func12(v10, &v11)
|| !(unsigned int)func8((__int64)buf, (__int64)v12, v11)
|| !(unsigned int)func13(v10, buf, v12, v11) )
{
++v5;
}
close(v10);
v3 = *++v4;
}
while ( *v4 );
result = v5 != 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int fd;
    Elf32_Ehdr ehdr;
    Elf32_Phdr *phdrs;
    unsigned long newsize;
    char **arg;
    int failures = 0;
    if (argc < 2 || argv[1][0] == '-') {
 printf("Usage: sstrip FILE...\n"
        "sstrip discards all nonessential bytes from an executable.\n\n"
        "Version 2.0 Copyright (C) 2000,2001 Brian Raiter.\n"
        "This program is free software, licensed under the GNU\n"
        "General Public License. There is absolutely no warranty.\n");
 return 0;
    }
    progname = argv[0];
    for (arg = argv + 1 ; *arg != ((void *)0) ; ++arg) {
 filename = *arg;
 fd = open(*arg, 02);
 if (fd < 0) {
     (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("can't open")));
     ++failures;
     continue;
 }
 if (!(readelfheader(fd, &ehdr) &&
       readphdrtable(fd, &ehdr, &phdrs) &&
       getmemorysize(&ehdr, phdrs, &newsize) &&
       truncatezeros(fd, &newsize) &&
       modifyheaders(&ehdr, phdrs, newsize) &&
       commitchanges(fd, &ehdr, phdrs, newsize)))
     ++failures;
 close(fd);
    }
    return failures ? 1 : 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int fd;
    struct Elf32_Ehdr ehdr;
    struct Elf32_Phdr *phdrs;
    unsigned long newsize;
    char **arg;
    int failures = 0;
    if (argc < 2 || argv[1][0] == '-') {
 printf("Usage: sstrip FILE...\n"
        "sstrip discards all nonessential bytes from an executable.\n\n"
        "Version 2.0 Copyright (C) 2000,2001 Brian Raiter.\n"
        "This program is free software, licensed under the GNU\n"
        "General Public License. There is absolutely no warranty.\n");
 return 0;
    }
    progname = argv[0];
    for (arg = argv + 1 ; *arg != ((void *)0) ; ++arg) {
 filename = *arg;
 fd = open(*arg, 02);
 if (fd < 0) {
     (err((*__errno_location ()) ? strerror((*__errno_location ())) : ("can't open")));
     ++failures;
     continue;
 }
 if (!(readelfheader(fd, &ehdr) &&
       readphdrtable(fd, &ehdr, &phdrs) &&
       getmemorysize(&ehdr, phdrs, &newsize) &&
       truncatezeros(fd, &newsize) &&
       modifyheaders(&ehdr, phdrs, newsize) &&
       commitchanges(fd, &ehdr, phdrs, newsize)))
     ++failures;
 close(fd);
    }
    return failures ? 1 : 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

variable_types:
arg
char **

variable_types: failures int


initRobot

repo: rtosMasterTec/collisionAvoidanceProject

original_code:
int initRobot()
{
    botData.botData.location.x = 60;
    botData.botData.location.y = 50;
    botData.botData.speed = 0;
    strcpy(botData.botData.direction,"E");
    botData.botData.obstacle[0] = 0;
    botData.botData.obstacle[1] = 0;
    botData.botData.obstacle[2] = 0;
    botData.botData.obstacle[3] = 0;
}


receiveData

decompiled_code:
int receiveData()
{
return puts("receivingData() correctly run");
}

canonical_decompiled_code:
int func3()
{
return puts("receivingData() correctly run");
}

original_code:
void* receiveData(void *ptr)
{
    printf("receivingData() correctly run\n");
}

canonical_original_code:
void *receiveData(void *ptr)
{
    printf("receivingData() correctly run\n");
}

variable_types:
ptr
void *

return_type: void *


mcastSubscribe

decompiled_code:
int mcastSubscribe()
{
unsigned int v0; // ebp
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // er12

puts("mcastSubscribe() started");
v0 = botData[1];
printf("My position R%d = X=%d,Y=%d\n", 0LL, v0, botData[2]);
for ( i = 0LL; i != 10; ++i )
{
v2 = 90LL * (unsigned int)timeInst;
v3 = timeInstMatrix[9 * (int)i + 1 + v2];
printf("Check position of robot R%d = X=%d,Y=%d\n", (unsigned int)i, v3, timeInstMatrix[9 * (int)i + 2 + v2]);
if ( (int)(v0 - v3) <= 9 )
subscribeArr[i] = 1;
}
return puts("mcastSubscribe() correctly run");
}

canonical_decompiled_code:
int func4()
{
unsigned int v0; // ebp
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // er12

puts("mcastSubscribe() started");
v0 = botData[1];
printf("My position R%d = X=%d,Y=%d\n", 0LL, v0, botData[2]);
for ( i = 0LL; i != 10; ++i )
{
v2 = 90LL * (unsigned int)timeInst;
v3 = timeInstMatrix[9 * (int)i + 1 + v2];
printf("Check position of robot R%d = X=%d,Y=%d\n", (unsigned int)i, v3, timeInstMatrix[9 * (int)i + 2 + v2]);
if ( (int)(v0 - v3) <= 9 )
subscribeArr[i] = 1;
}
return puts("mcastSubscribe() correctly run");
}

original_code:
void* mcastSubscribe(void* ptr)
{
   printf("mcastSubscribe() started\n");
   int j;
   int my_coord_x;
   int my_coord_y;
   int coord_x;
   int coord_y;
   my_coord_x = botData.botData.location.x;
   my_coord_y = botData.botData.location.y;
   printf("My position R%d = X=%d,Y=%d\n",0 ,my_coord_x,my_coord_y);
   for(j=0; j< 10; j++)
   {
      coord_x = timeInstMatrix[timeInst][j][1];
      coord_y = timeInstMatrix[timeInst][j][2];
      printf("Check position of robot R%d = X=%d,Y=%d\n",j ,coord_x,coord_y);
      if(my_coord_x - coord_x < 10)
      {
         subscribeArr[j] = 1;
      }
   }
   printf("mcastSubscribe() correctly run\n");
}

canonical_original_code:
void *mcastSubscribe(void *ptr)
{
   printf("mcastSubscribe() started\n");
   int j;
   int my_coord_x;
   int my_coord_y;
   int coord_x;
   int coord_y;
   my_coord_x = botData.botData.location.x;
   my_coord_y = botData.botData.location.y;
   printf("My position R%d = X=%d,Y=%d\n",0 ,my_coord_x,my_coord_y);
   for(j=0; j< 10; j++)
   {
      coord_x = timeInstMatrix[timeInst][j][1];
      coord_y = timeInstMatrix[timeInst][j][2];
      printf("Check position of robot R%d = X=%d,Y=%d\n",j ,coord_x,coord_y);
      if(my_coord_x - coord_x < 10)
      {
         subscribeArr[j] = 1;
      }
   }
   printf("mcastSubscribe() correctly run\n");
}

variable_types: j int


mcastUnSubscribe

decompiled_code:
int mcastUnSubscribe()
{
unsigned int v0; // ebp
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // er12

puts("mcastUnSubscribe() started");
v0 = botData[1];
printf("My position R%d = X=%d,Y=%d\n", 0LL, v0, botData[2]);
for ( i = 1LL; i != 11; ++i )
{
v2 = 90LL * (unsigned int)timeInst;
v3 = timeInstMatrix[9 * (int)i + 1 + v2];
printf("Check position of robot R%d = X=%d,Y=%d\n", (unsigned int)i, v3, timeInstMatrix[9 * (int)i + 2 + v2]);
if ( (int)(v0 - v3) > 9 )
subscribeArr[i] = 0;
}
return puts("mcastUnSubscribe() correctly run");
}

canonical_decompiled_code:
int func5()
{
unsigned int v0; // ebp
__int64 i; // rbx
__int64 v2; // rax
unsigned int v3; // er12

puts("mcastUnSubscribe() started");
v0 = botData[1];
printf("My position R%d = X=%d,Y=%d\n", 0LL, v0, botData[2]);
for ( i = 1LL; i != 11; ++i )
{
v2 = 90LL * (unsigned int)timeInst;
v3 = timeInstMatrix[9 * (int)i + 1 + v2];
printf("Check position of robot R%d = X=%d,Y=%d\n", (unsigned int)i, v3, timeInstMatrix[9 * (int)i + 2 + v2]);
if ( (int)(v0 - v3) > 9 )
subscribeArr[i] = 0;
}
return puts("mcastUnSubscribe() correctly run");
}

original_code:
void* mcastUnSubscribe(void* ptr)
{
   printf("mcastUnSubscribe() started\n");
   int j;
   int my_coord_x;
   int my_coord_y;
   int coord_x;
   int coord_y;
   my_coord_x = botData.botData.location.x;
   my_coord_y = botData.botData.location.y;
   printf("My position R%d = X=%d,Y=%d\n",0 ,my_coord_x,my_coord_y);
   for(j=1; j<= 10; j++)
   {
      coord_x = timeInstMatrix[timeInst][j][1];
      coord_y = timeInstMatrix[timeInst][j][2];
      printf("Check position of robot R%d = X=%d,Y=%d\n",j ,coord_x,coord_y);
      if(my_coord_x - coord_x >= 10)
      {
         subscribeArr[j] = 0;
      }
   }
   printf("mcastUnSubscribe() correctly run\n");
}

canonical_original_code:
void *mcastUnSubscribe(void *ptr)
{
   printf("mcastUnSubscribe() started\n");
   int j;
   int my_coord_x;
   int my_coord_y;
   int coord_x;
   int coord_y;
   my_coord_x = botData.botData.location.x;
   my_coord_y = botData.botData.location.y;
   printf("My position R%d = X=%d,Y=%d\n",0 ,my_coord_x,my_coord_y);
   for(j=1; j<= 10; j++)
   {
      coord_x = timeInstMatrix[timeInst][j][1];
      coord_y = timeInstMatrix[timeInst][j][2];
      printf("Check position of robot R%d = X=%d,Y=%d\n",j ,coord_x,coord_y);
      if(my_coord_x - coord_x >= 10)
      {
         subscribeArr[j] = 0;
      }
   }
   printf("mcastUnSubscribe() correctly run\n");
}


decisionMaking

decompiled_code:
int decisionMaking()
{
puts("decisionMaking() started");
if ( *(&obstacle + 2) )
{
if ( obstacle )
{
if ( *(&obstacle + 1) )
{
nextMoveX = botData[1];
nextMoveY = botData[2];
}
else
{
move = 4;
nextMoveX = botData[1];
nextMoveY = botData[2] - 1;
}
}
else
{
move = 1;
nextMoveX = botData[1];
nextMoveY = botData[2] + 1;
}
}
else
{
move = 3;
nextMoveX = botData[1] + 1;
nextMoveY = botData[2];
}
updateRobot();
return puts("decisionMaking() correctly run");
}

canonical_decompiled_code:
int func6()
{
puts("decisionMaking() started");
if ( *(&obstacle + 2) )
{
if ( obstacle )
{
if ( *(&obstacle + 1) )
{
nextMoveX = botData[1];
nextMoveY = botData[2];
}
else
{
move = 4;
nextMoveX = botData[1];
nextMoveY = botData[2] - 1;
}
}
else
{
move = 1;
nextMoveX = botData[1];
nextMoveY = botData[2] + 1;
}
}
else
{
move = 3;
nextMoveX = botData[1] + 1;
nextMoveY = botData[2];
}
func0();
return puts("decisionMaking() correctly run");
}

original_code:
void* decisionMaking(void* ptr)
{
   printf("decisionMaking() started\n");
   if(!obstacle.e)
   {
      move = 3;
      nextMoveX = botData.botData.location.x+1;
      nextMoveY = botData.botData.location.y;
   }
   else if(!obstacle.n)
   {
      move = 1;
      nextMoveX = botData.botData.location.x;
      nextMoveY = botData.botData.location.y+1;
   }
   else if(!obstacle.s)
   {
      move = 4;
      nextMoveX = botData.botData.location.x;
      nextMoveY = botData.botData.location.y-1;
   }
   else
   {
      nextMoveX = botData.botData.location.x;
      nextMoveY = botData.botData.location.y;
   }
   updateRobot();
   printf("decisionMaking() correctly run\n");
}

canonical_original_code:
void *decisionMaking(void *ptr)
{
   printf("decisionMaking() started\n");
   if(!obstacle.e)
   {
      move = 3;
      nextMoveX = botData.botData.location.x+1;
      nextMoveY = botData.botData.location.y;
   }
   else if(!obstacle.n)
   {
      move = 1;
      nextMoveX = botData.botData.location.x;
      nextMoveY = botData.botData.location.y+1;
   }
   else if(!obstacle.s)
   {
      move = 4;
      nextMoveX = botData.botData.location.x;
      nextMoveY = botData.botData.location.y-1;
   }
   else
   {
      nextMoveX = botData.botData.location.x;
      nextMoveY = botData.botData.location.y;
   }
   updateRobot();
   printf("decisionMaking() correctly run\n");
}


dataProcessing

original_code:
void *dataProcessing(void* ptr)
{
   int j = 0;
   int currentTimeInst = 4;
   _Bool collision = 0;
   int xi, yi, xf, yf,i;
   int xactual, yactual;
   int dx, dy;
   xactual = botData.botData.location.x;
   yactual = botData.botData.location.y;
   obstacle.n = 0;
   obstacle.s = 0;
   obstacle.e = 0;
   for( i = 0; i < 4 ; i++)
   {
      xi = obstacleMap[i][0];
      yi = obstacleMap[i][1];
      xf = obstacleMap[i][2];
      yf = obstacleMap[i][3];
      if( xactual >= xi && xactual <= xf && yactual+1 >= yi && yactual+1 <= yf)
      {
         obstacle.n = 1;
      }
      if( xactual+1 >= xi && xactual+1 <= xf && yactual >= yi && yactual <= yf)
      {
         obstacle.e = 1;
      }
      if( xactual-1 >= xi && xactual-1 <= xf && yactual >= yi && yactual <= yf)
      {
         obstacle.s = 1;
      }
   }
   for(j = 0; j < 10; j++)
   {
      if(subscribeArr[j] == 1)
      {
            dataCollectionCtr++;
            if(timeInst == 61) { printf("DataCollection Bots processed = %d\n", dataCollectionCtr); };
         switch(timeInstMatrix[currentTimeInst][j][4])
         {
            case 1:
               {
                  dx = 0;
                  dy = 1;
                  break;
               }
            case 3:
               {
                  dx = 1;
                  dy = 0;
                  break;
               }
            case 4:
               {
                  dx = 0;
                  dy = -1;
               }
         }
         if((timeInstMatrix[currentTimeInst][j][1] + dx == xactual+1)
               && (timeInstMatrix[currentTimeInst][j][2]+dy == yactual ))
         {
            obstacle.e = 1;
         }
         else if((timeInstMatrix[currentTimeInst][j][1] + dx == xactual)
               && (timeInstMatrix[currentTimeInst][j][2]+dy == yactual+1 ))
         {
            obstacle.n = 1;
         }
         else if((timeInstMatrix[currentTimeInst][j][1] + dx == xactual)
               && (timeInstMatrix[currentTimeInst][j][2]+ dy == yactual-1 ))
         {
            obstacle.s = 1;
         }
      }
   }
    printf("dataProcessing() correctly run\n");
}

canonical_original_code:
void *dataProcessing(void *ptr)
{
   int j = 0;
   int currentTimeInst = 4;
   _Bool collision = 0;
   int xi; int yi; int xf; int yf; int i;
   int xactual; int yactual;
   int dx; int dy;
   xactual = botData.botData.location.x;
   yactual = botData.botData.location.y;
   obstacle.n = 0;
   obstacle.s = 0;
   obstacle.e = 0;
   for( i = 0; i < 4 ; i++)
   {
      xi = obstacleMap[i][0];
      yi = obstacleMap[i][1];
      xf = obstacleMap[i][2];
      yf = obstacleMap[i][3];
      if( xactual >= xi && xactual <= xf && yactual+1 >= yi && yactual+1 <= yf)
      {
         obstacle.n = 1;
      }
      if( xactual+1 >= xi && xactual+1 <= xf && yactual >= yi && yactual <= yf)
      {
         obstacle.e = 1;
      }
      if( xactual-1 >= xi && xactual-1 <= xf && yactual >= yi && yactual <= yf)
      {
         obstacle.s = 1;
      }
   }
   for(j = 0; j < 10; j++)
   {
      if(subscribeArr[j] == 1)
      {
            dataCollectionCtr++;
            if(timeInst == 61) { printf("DataCollection Bots processed = %d\n", dataCollectionCtr); };
         switch(timeInstMatrix[currentTimeInst][j][4])
         {
            case 1:
               {
                  dx = 0;
                  dy = 1;
                  break;
               }
            case 3:
               {
                  dx = 1;
                  dy = 0;
                  break;
               }
            case 4:
               {
                  dx = 0;
                  dy = -1;
               }
         }
         if((timeInstMatrix[currentTimeInst][j][1] + dx == xactual+1)
               && (timeInstMatrix[currentTimeInst][j][2]+dy == yactual ))
         {
            obstacle.e = 1;
         }
         else if((timeInstMatrix[currentTimeInst][j][1] + dx == xactual)
               && (timeInstMatrix[currentTimeInst][j][2]+dy == yactual+1 ))
         {
            obstacle.n = 1;
         }
         else if((timeInstMatrix[currentTimeInst][j][1] + dx == xactual)
               && (timeInstMatrix[currentTimeInst][j][2]+ dy == yactual-1 ))
         {
            obstacle.s = 1;
         }
      }
   }
    printf("dataProcessing() correctly run\n");
}

variable_types: currentTimeInst int

variable_types: xi int

variable_types: yi int

variable_types: xf int

variable_types: yf int

variable_types: xactual int

variable_types: yactual int

variable_types: dx int

variable_types: dy int


dataSelection

decompiled_code:
int dataSelection()
{
return puts("dataSelection() correctly run");
}

canonical_decompiled_code:
int func8()
{
return puts("dataSelection() correctly run");
}

original_code:
void* dataSelection(void* ptr)
{
    printf("dataSelection() correctly run\n");
}

canonical_original_code:
void *dataSelection(void *ptr)
{
    printf("dataSelection() correctly run\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initRobot(argc, argv, envp);
loadVector();
return scheduler();
}

original_code:
int main(int argc, char **argv)
{
   initRobot();
   loadVector();
    return scheduler();
}

variable_types:
argv
char **


scheduler

decompiled_code:
__int64 scheduler()
{
__int64 result; // rax
int i; // ebx

timeInst = 0;
dataCollectionCtr = 0;
if ( (unsigned int)pth_init() == 1 )
{
pt[0] = pth_self();
while ( 1 )
{
puts("yielding");
pt[1] = pth_spawn(0LL, &mcastSubscribe, 0LL);
pt[2] = pth_spawn(0LL, &mcastUnSubscribe, 0LL);
pt[3] = pth_spawn(0LL, &receiveData, 0LL);
pt[4] = pth_spawn(0LL, &dataSelection, 0LL);
pt[5] = pth_spawn(0LL, &dataProcessing, 0LL);
pt[6] = pth_spawn(0LL, &decisionMaking, 0LL);
pt[7] = pth_spawn(0LL, &sendData, 0LL);
for ( i = 1; i != 7; ++i )
pth_yield(pt[i]);
result = (unsigned int)timeInst;
if ( (unsigned int)timeInst > 0x3C )
break;
++timeInst;
}
}
else
{
fwrite("Could not initialize GNU Pth, exiting.\n", 1uLL, 0x27uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int i; // ebx

timeInst = 0;
dataCollectionCtr = 0;
if ( (unsigned int)pth_init() == 1 )
{
pt[0] = pth_self();
while ( 1 )
{
puts("yielding");
pt[1] = pth_spawn(0LL, &mcastSubscribe, 0LL);
pt[2] = pth_spawn(0LL, &mcastUnSubscribe, 0LL);
pt[3] = pth_spawn(0LL, &receiveData, 0LL);
pt[4] = pth_spawn(0LL, &dataSelection, 0LL);
pt[5] = pth_spawn(0LL, &dataProcessing, 0LL);
pt[6] = pth_spawn(0LL, &decisionMaking, 0LL);
pt[7] = pth_spawn(0LL, &sendData, 0LL);
for ( i = 1; i != 7; ++i )
pth_yield(pt[i]);
result = (unsigned int)timeInst;
if ( (unsigned int)timeInst > 0x3C )
break;
++timeInst;
}
}
else
{
fwrite("Could not initialize GNU Pth, exiting.\n", 1uLL, 0x27uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int scheduler(void)
{
   long numthreads;
   int pth_ret;
   int i;
   timeInst = 0;
   dataCollectionCtr = 0;
   pth_ret = pth_init();
   if (pth_ret != (!(0)))
   {
      fprintf(stderr, "Could not initialize GNU Pth, exiting.\n");
      return(1);
   }
   pt[0] = pth_self();
   while (1)
   {
      printf("yielding\n");
      pt[1] = pth_spawn((pth_attr_t)(0), mcastSubscribe, ((void *)0));
      pt[2] = pth_spawn((pth_attr_t)(0), mcastUnSubscribe, ((void *)0));
      pt[3] = pth_spawn((pth_attr_t)(0), receiveData, ((void *)0));
      pt[4] = pth_spawn((pth_attr_t)(0), dataSelection, ((void *)0));
      pt[5] = pth_spawn((pth_attr_t)(0), dataProcessing, ((void *)0));
      pt[6] = pth_spawn((pth_attr_t)(0), decisionMaking, ((void *)0));
      pt[7] = pth_spawn((pth_attr_t)(0), sendData, ((void *)0));
      for(i =1; i< 7; i++)
      {
         pth_yield(pt[i]);
      }
      if(timeInst >=61) {return;}
      timeInst++;
   }
   return(0);
 }

canonical_original_code:
int scheduler()
{
   long numthreads;
   int pth_ret;
   int i;
   timeInst = 0;
   dataCollectionCtr = 0;
   pth_ret = pth_init();
   if (pth_ret != (!(0)))
   {
      fprintf(stderr, "Could not initialize GNU Pth, exiting.\n");
      return(1);
   }
   pt[0] = pth_self();
   while (1)
   {
      printf("yielding\n");
      pt[1] = pth_spawn((pth_attr_t)(0), mcastSubscribe, ((void *)0));
      pt[2] = pth_spawn((pth_attr_t)(0), mcastUnSubscribe, ((void *)0));
      pt[3] = pth_spawn((pth_attr_t)(0), receiveData, ((void *)0));
      pt[4] = pth_spawn((pth_attr_t)(0), dataSelection, ((void *)0));
      pt[5] = pth_spawn((pth_attr_t)(0), dataProcessing, ((void *)0));
      pt[6] = pth_spawn((pth_attr_t)(0), decisionMaking, ((void *)0));
      pt[7] = pth_spawn((pth_attr_t)(0), sendData, ((void *)0));
      for(i =1; i< 7; i++)
      {
         pth_yield(pt[i]);
      }
      if(timeInst >=61) {return;}
      timeInst++;
   }
   return(0);
 }

variable_types: numthreads long

variable_types: i int


decompiled_code:
__int64 thread_1()
{
int v0; // ebx

v0 = 10;
do
{
printf("thread1\n ");
pth_yield(pt[0]);
--v0;
}
while ( v0 );
pth_exit(0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx

v0 = 10;
do
{
printf("thread1\n ");
pth_yield(pt[0]);
--v0;
}
while ( v0 );
pth_exit(0LL);
return 0LL;
}

original_code:
void *thread_1(void *ptr)
{
   int i;
   for (i = 0; i < 10; i++) {
      printf("thread1\n  ");
      pth_yield(pt[0]);
   }
   pth_exit(((void *)0));
   return(((void *)0));
}


decompiled_code:
__int64 thread_2()
{
int v0; // ebx

v0 = 10;
do
{
printf("thread2\n ");
pth_yield(pt[0]);
--v0;
}
while ( v0 );
pth_exit(0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx

v0 = 10;
do
{
printf("thread2\n ");
pth_yield(pt[0]);
--v0;
}
while ( v0 );
pth_exit(0LL);
return 0LL;
}

original_code:
void *thread_2(void *ptr)
{
   int i;
   for (i = 0; i < 10; i++) {
      printf("thread2\n  ");
      pth_yield(pt[0]);
   }
   pth_exit(((void *)0));
   return(((void *)0));
}


repo: rtosMasterTec/lotteryScheduling

decompiled_code:
int init_threads()
{
__int64 v0; // rsi
__int64 v1; // rsi
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // rsi

config[14] = 1;
config[15] = 1;
config[16] = 1;
config[17] = 1;
config[18] = 1;
LODWORD(Athread) = 50 * config[6];
v0 = (unsigned int)Athread;
*((_QWORD *)&Athread + 1) = 0LL;
printf("ATotalTerms %d\n", v0);
LODWORD(Bthread) = 50 * config[7];
v1 = (unsigned int)Bthread;
*((_QWORD *)&Bthread + 1) = 0LL;
printf("BTotalTerms %d\n", v1);
LODWORD(Cthread) = 50 * config[8];
v2 = (unsigned int)Cthread;
*((_QWORD *)&Cthread + 1) = 0LL;
printf("CTotalTerms %d\n", v2);
LODWORD(Dthread) = 50 * config[9];
v3 = (unsigned int)Dthread;
*((_QWORD *)&Dthread + 1) = 0LL;
printf("DTotalTerms %d\n", v3);
LODWORD(Ethread) = 50 * config[10];
v4 = (unsigned int)Ethread;
*((_QWORD *)&Ethread + 1) = 0LL;
return printf("ETotalTerms %d\n", v4);
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rsi
__int64 v1; // rsi
__int64 v2; // rsi
__int64 v3; // rsi
__int64 v4; // rsi

config[14] = 1;
config[15] = 1;
config[16] = 1;
config[17] = 1;
config[18] = 1;
LODWORD(Athread) = 50 * config[6];
v0 = (unsigned int)Athread;
*((_QWORD *)&Athread + 1) = 0LL;
printf("ATotalTerms %d\n", v0);
LODWORD(Bthread) = 50 * config[7];
v1 = (unsigned int)Bthread;
*((_QWORD *)&Bthread + 1) = 0LL;
printf("BTotalTerms %d\n", v1);
LODWORD(Cthread) = 50 * config[8];
v2 = (unsigned int)Cthread;
*((_QWORD *)&Cthread + 1) = 0LL;
printf("CTotalTerms %d\n", v2);
LODWORD(Dthread) = 50 * config[9];
v3 = (unsigned int)Dthread;
*((_QWORD *)&Dthread + 1) = 0LL;
printf("DTotalTerms %d\n", v3);
LODWORD(Ethread) = 50 * config[10];
v4 = (unsigned int)Ethread;
*((_QWORD *)&Ethread + 1) = 0LL;
return printf("ETotalTerms %d\n", v4);
}

original_code:
void init_threads(){
   config.threadbuffer[0] = 1;
   config.threadbuffer[1] = 1;
   config.threadbuffer[2] = 1;
   config.threadbuffer[3] = 1;
   config.threadbuffer[4] = 1;
   Athread.totalTerms = 50*config.workLoad[0];
   Athread.currPiValue = 0;
   printf("ATotalTerms %d\n", Athread.totalTerms);
   Bthread.totalTerms = 50*config.workLoad[1];
   Bthread.currPiValue = 0;
   printf("BTotalTerms %d\n", Bthread.totalTerms);
   Cthread.totalTerms = 50*config.workLoad[2];
   Cthread.currPiValue = 0;
   printf("CTotalTerms %d\n", Cthread.totalTerms);
   Dthread.totalTerms = 50*config.workLoad[3];
   Dthread.currPiValue = 0;
   printf("DTotalTerms %d\n", Dthread.totalTerms);
   Ethread.totalTerms = 50*config.workLoad[4];
   Ethread.currPiValue = 0;
   printf("ETotalTerms %d\n", Ethread.totalTerms);
}


algo

decompiled_code:
__int64 algo()
{
double v0; // xmm0_8
int v1; // eax
__m128i v3; // [rsp+0h] [rbp-18h] BYREF

v0 = *(double *)&LC6;
if ( !LOBYTE(config[0]) )
v0 = (double)(int)config[11];
v1 = *((_DWORD *)&sData + 250);
if ( v1 )
{
if ( v1 == 1 )
{
v3 = _mm_load_si128((const __m128i *)&Bthread);
goto LABEL_9;
}
if ( v1 == 2 )
{
v3 = _mm_load_si128((const __m128i *)&Cthread);
return calculatePI(&v3, v0);
}
}
else
{
v3 = _mm_load_si128((const __m128i *)&Athread);
}
if ( v1 == 3 )
{
v3 = _mm_load_si128((const __m128i *)&Dthread);
return calculatePI(&v3, v0);
}
LABEL_9:
if ( v1 == 4 )
v3 = _mm_load_si128((const __m128i *)&Ethread);
return calculatePI(&v3, v0);
}

canonical_decompiled_code:
__int64 func1()
{
double v0; // xmm0_8
int v1; // eax
__m128i v3; // [rsp+0h] [rbp-18h] BYREF

v0 = *(double *)&LC6;
if ( !LOBYTE(config[0]) )
v0 = (double)(int)config[11];
v1 = *((_DWORD *)&sData + 250);
if ( v1 )
{
if ( v1 == 1 )
{
v3 = _mm_load_si128((const __m128i *)&Bthread);
goto LABEL_9;
}
if ( v1 == 2 )
{
v3 = _mm_load_si128((const __m128i *)&Cthread);
return calculatePI(&v3, v0);
}
}
else
{
v3 = _mm_load_si128((const __m128i *)&Athread);
}
if ( v1 == 3 )
{
v3 = _mm_load_si128((const __m128i *)&Dthread);
return calculatePI(&v3, v0);
}
LABEL_9:
if ( v1 == 4 )
v3 = _mm_load_si128((const __m128i *)&Ethread);
return calculatePI(&v3, v0);
}

original_code:
void algo()
{
   double percentage;
   threadData_t currentThread;
   if(config.preemptive == 0) {
      percentage = config.quantum;
   } else
   {
      percentage = 100;
   }
   if(sData.threadID == 0) { currentThread = Athread; }
   if(sData.threadID == 1) { currentThread = Bthread; }
   if(sData.threadID == 2) { currentThread = Cthread; }
   if(sData.threadID == 3) { currentThread = Dthread; }
   if(sData.threadID == 4) { currentThread = Ethread; }
   calculatePI(&currentThread , percentage);
}

canonical_original_code:
void algo()
{
   double percentage;
   struct threadData_s currentThread;
   if(config.preemptive == 0) {
      percentage = config.quantum;
   } else
   {
      percentage = 100;
   }
   if(sData.threadID == 0) { currentThread = Athread; }
   if(sData.threadID == 1) { currentThread = Bthread; }
   if(sData.threadID == 2) { currentThread = Cthread; }
   if(sData.threadID == 3) { currentThread = Dthread; }
   if(sData.threadID == 4) { currentThread = Ethread; }
   calculatePI(&currentThread , percentage);
}

variable_types: percentage double

variable_types: struct threadData_s { int totalTerms; int currTerm; double currPiValue; }


restoreState

decompiled_code:
void __fastcall __noreturn restoreState(unsigned int a1)
{
siglongjmp((struct __jmp_buf_tag *)&sData + a1, 4 * (a1 == 5) + 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(unsigned int a1)
{
siglongjmp((struct __jmp_buf_tag *)&sData + a1, 4 * (a1 == 5) + 1);
}

original_code:
void restoreState(unsigned idx)
{
   int retval = 1;
   if(5 == idx)
   {
      retval = 5;
   }
   siglongjmp(sData.env[idx], retval);
   return;
}

canonical_original_code:
void restoreState(unsigned int idx)
{
   int retval = 1;
   if(5 == idx)
   {
      retval = 5;
   }
   siglongjmp(sData.env[idx], retval);
   return;
}

variable_types:
idx
unsigned int

variable_types: retval int


saveState

decompiled_code:
int __fastcall saveState(unsigned int a1)
{
return _sigsetjmp((struct __jmp_buf_tag *)&sData + a1, 1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
return _sigsetjmp((struct __jmp_buf_tag *)&sData + a1, 1);
}

original_code:
int saveState(unsigned idx)
{
   int ret;
   void * ptr;
   ret = __sigsetjmp (sData.env[idx], 1);
   if( 0 != ret && 5 != idx )
   {
   }
   return ret;
}

canonical_original_code:
int saveState(unsigned int idx)
{
   int ret;
   void *ptr;
   ret = __sigsetjmp (sData.env[idx], 1);
   if( 0 != ret && 5 != idx )
   {
   }
   return ret;
}

variable_types: ret int

variable_types:
ptr
void *


lottery

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

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

original_code:
int lottery()
{
   int winner=0;
   winner = sData.threadID+1;
   winner =0;
   if( winner >= 5 )
      winner = 0;
   return winner;
}

canonical_original_code:
int lottery()
{
   int winner = 0;
   winner = sData.threadID+1;
   winner =0;
   if( winner >= 5 )
      winner = 0;
   return winner;
}

variable_types: winner int


preemtiveTime

decompiled_code:
int preemtiveTime()
{
puts("setting the timer");
*((_QWORD *)&sData + 769) = 0LL;
*((_QWORD *)&sData + 770) = 100000LL;
*((_QWORD *)&sData + 767) = 0LL;
*((_QWORD *)&sData + 768) = 100000LL;
return setitimer(ITIMER_VIRTUAL, (const struct itimerval *)(unsigned int)((_DWORD)&sData + 6136), 0LL);
}

canonical_decompiled_code:
int func5()
{
puts("setting the timer");
*((_QWORD *)&sData + 769) = 0LL;
*((_QWORD *)&sData + 770) = 100000LL;
*((_QWORD *)&sData + 767) = 0LL;
*((_QWORD *)&sData + 768) = 100000LL;
return setitimer(ITIMER_VIRTUAL, (const struct itimerval *)(unsigned int)((_DWORD)&sData + 6136), 0LL);
}

original_code:
void preemtiveTime()
{
   printf("setting the timer\n");
   sData.timer.it_value.tv_sec = 0;
   sData.timer.it_value.tv_usec = 100000;
   sData.timer.it_interval.tv_sec = 0;
   sData.timer.it_interval.tv_usec = 100000;
   setitimer(ITIMER_VIRTUAL, &sData.timer, 0);
   return;
}


invalidateThread

decompiled_code:
bool __fastcall invalidateThread(int a1)
{
switch ( a1 )
{
case 1:
config[14] = 0;
break;
case 2:
config[15] = 0;
break;
case 3:
config[16] = 0;
return (config[18] | config[17] | config[16] | config[15] | config[14]) == 0;
case 4:
config[17] = 0;
return (config[18] | config[17] | config[16] | config[15] | config[14]) == 0;
}
if ( a1 == 5 )
config[18] = 0;
return (config[18] | config[17] | config[16] | config[15] | config[14]) == 0;
}

canonical_decompiled_code:
bool __fastcall func6(int a1)
{
switch ( a1 )
{
case 1:
config[14] = 0;
break;
case 2:
config[15] = 0;
break;
case 3:
config[16] = 0;
return (config[18] | config[17] | config[16] | config[15] | config[14]) == 0;
case 4:
config[17] = 0;
return (config[18] | config[17] | config[16] | config[15] | config[14]) == 0;
}
if ( a1 == 5 )
config[18] = 0;
return (config[18] | config[17] | config[16] | config[15] | config[14]) == 0;
}

original_code:
_Bool invalidateThread (unsigned ID)
{
    _Bool Done = 0;
    if (ID == 1) config.threadbuffer[0] = 0;
    if (ID == 2) config.threadbuffer[1] = 0;
    if (ID == 3) config.threadbuffer[2] = 0;
    if (ID == 4) config.threadbuffer[3] = 0;
    if (ID == 5) config.threadbuffer[4] = 0;
    Done = !(config.threadbuffer[0] | config.threadbuffer[1] | config.threadbuffer[2] | config.threadbuffer[3] | config.threadbuffer[4]);
    return Done;
}

canonical_original_code:
_Bool invalidateThread(unsigned int ID)
{
    _Bool Done = 0;
    if (ID == 1) config.threadbuffer[0] = 0;
    if (ID == 2) config.threadbuffer[1] = 0;
    if (ID == 3) config.threadbuffer[2] = 0;
    if (ID == 4) config.threadbuffer[3] = 0;
    if (ID == 5) config.threadbuffer[4] = 0;
    Done = !(config.threadbuffer[0] | config.threadbuffer[1] | config.threadbuffer[2] | config.threadbuffer[3] | config.threadbuffer[4]);
    return Done;
}

variable_types:
ID
unsigned int


schedulerInit

original_code:
void schedulerInit()
{
   unsigned thread;
   initDone = 1;
   for( thread = 0; thread < 5 ; thread ++ )
   {
      sData.taskInit[thread] = 0;
   }
   init_threads();
}

canonical_original_code:
void schedulerInit()
{
   unsigned int thread;
   initDone = 1;
   for( thread = 0; thread < 5 ; thread ++ )
   {
      sData.taskInit[thread] = 0;
   }
   init_threads();
}

variable_types:
thread
unsigned int


scheduler

decompiled_code:
void scheduler()
{
int v0; // eax
__int64 v1; // rsi

printf("Getting the alarm for thread: %d\n", *((unsigned int *)&sData + 250));
v0 = saveState(*((_DWORD *)&sData + 250));
if ( v0 == 1 )
{
printf("restoring state %d\n", *((unsigned int *)&sData + 250));
}
else if ( v0 != 5 )
{
dummy = 0;
if ( !initDone )
{
puts("entering init");
schedulerInit();
}
*((_DWORD *)&sData + 250) = lottery();
signal(26, scheduler);
preemtiveTime();
puts("sigalm passed");
v1 = *((unsigned int *)&sData + 250);
if ( !*((_BYTE *)&sData + v1 + 1004) )
{
printf("initializing thread: %d\n", v1);
*((_BYTE *)&sData + *((unsigned int *)&sData + 250) + 1004) = 1;
algo();
initscr();
print2screen(&Athread, &Bthread, &Cthread, &Dthread, &Ethread, *((unsigned int *)&sData + 250));
printf("\ntask %d is done\n", *((unsigned int *)&sData + 250));
invalidateThread(*((_DWORD *)&sData + 250));
restoreState(6u);
}
restoreState(v1);
}
}

canonical_decompiled_code:
void func8()
{
int v0; // eax
__int64 v1; // rsi

printf("Getting the alarm for thread: %d\n", *((unsigned int *)&sData + 250));
v0 = func3(*((_DWORD *)&sData + 250));
if ( v0 == 1 )
{
printf("restoring state %d\n", *((unsigned int *)&sData + 250));
}
else if ( v0 != 5 )
{
dummy = 0;
if ( !initDone )
{
puts("entering init");
func7();
}
*((_DWORD *)&sData + 250) = func4();
signal(26, scheduler);
func5();
puts("sigalm passed");
v1 = *((unsigned int *)&sData + 250);
if ( !*((_BYTE *)&sData + v1 + 1004) )
{
printf("initializing thread: %d\n", v1);
*((_BYTE *)&sData + *((unsigned int *)&sData + 250) + 1004) = 1;
func1();
initscr();
print2screen(&Athread, &Bthread, &Cthread, &Dthread, &Ethread, *((unsigned int *)&sData + 250));
printf("\ntask %d is done\n", *((unsigned int *)&sData + 250));
func6(*((_DWORD *)&sData + 250));
func2(6u);
}
func2(v1);
}
}

original_code:
void scheduler(int v)
{
   int ret;
   _Bool allDone = 0;
   printf("Getting the alarm for thread: %d\n", sData.threadID );
   ret = saveState(sData.threadID);
   if( 1 == ret )
   {
      printf("restoring state %d\n", sData.threadID);
      return;
   }
   if( 5 == ret )
   {
      return;
   }
   dummy = 0;
   if( !initDone )
   {
      printf("entering init\n");
      schedulerInit();
   }
   sData.threadID = lottery();
   signal(26, scheduler);
   preemtiveTime();
   printf("sigalm passed\n");
   if( !sData.taskInit[sData.threadID] )
   {
      printf("initializing thread: %d\n", sData.threadID);
      sData.taskInit[sData.threadID] = 1;
      algo();
initscr();
      print2screen(&Athread,&Bthread,&Cthread,&Dthread,&Ethread,sData.threadID);
      printf("\ntask %d is done\n", sData.threadID);
      allDone = invalidateThread(sData.threadID);
      allDone = 1;
      restoreState(6);
      if(allDone)
      {
         return;
      }
   }
   else
   {
      restoreState(sData.threadID);
   }
   return;
}

variable_types: v int


main

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

v3 = time(0LL);
srand(v3);
readfile(v3, argv);
init_threads();
sData[250] = 5;
initscr();
scheduler(0LL);
readfile(0LL, argv);
wrefresh(stdscr);
wgetch(stdscr);
endwin();
return 0;
}

original_code:
int main( int argc, char **argv)
{
   srand ( time(((void *)0)) );
   readfile();
   init_threads();
   sData.threadID = 5;
   initscr();
   scheduler(0);
   readfile();
   wrefresh(stdscr);
   wgetch(stdscr);
   endwin();
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
   srand ( time(((void *)0)) );
   readfile();
   init_threads();
   sData.threadID = 5;
   initscr();
   scheduler(0);
   readfile();
   wrefresh(stdscr);
   wgetch(stdscr);
   endwin();
   return 0;
}

variable_types: argc int


decompiled_code:
int __fastcall print_end_delimiter(int a1, int a2)
{
int result; // eax

if ( a2 - 1 == a1 )
result = printw(">");
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2)
{
int result; // eax

if ( a2 - 1 == a1 )
result = printw(">");
return result;
}

original_code:
void print_end_delimiter(int x, int y){
 if(x == y-1){
  printw(">");
 };
}

variable_types: x int

variable_types: y int


decompiled_code:
int __fastcall print2screen(double *a1, double *a2, double *a3, double *a4, double *a5, unsigned int a6)
{
unsigned int v9; // er15
float v10; // xmm3_4
int v11; // er15
int v12; // er14
int v13; // er13
int v14; // er12
int v15; // ebp
int i; // ebx
int v17; // esi
int j; // ebx
int v19; // esi
int k; // ebx
int v21; // esi
int l; // ebx
int v23; // esi
int m; // ebx
int v25; // esi
unsigned int v27; // [rsp+0h] [rbp-48h]
float v28; // [rsp+0h] [rbp-48h]
unsigned int v29; // [rsp+4h] [rbp-44h]
float v30; // [rsp+4h] [rbp-44h]
unsigned int v31; // [rsp+8h] [rbp-40h]
float v32; // [rsp+8h] [rbp-40h]
unsigned int v33; // [rsp+Ch] [rbp-3Ch]
float v34; // [rsp+Ch] [rbp-3Ch]

v9 = a6;
if ( a6 )
{
switch ( a6 )
{
case 1u:
v33 = 0;
v31 = 0;
v29 = 0;
v27 = 0;
break;
case 2u:
v33 = 0;
v31 = 0;
v29 = 1;
v9 = 0;
v27 = 0;
break;
case 3u:
v33 = 0;
v31 = 1;
v29 = 0;
v9 = 0;
v27 = 0;
break;
case 4u:
v33 = 1;
v31 = 0;
v29 = 0;
v9 = 0;
v27 = 0;
break;
default:
v33 = 0;
v31 = 0;
v29 = 0;
v9 = 0;
v27 = 1;
break;
}
}
else
{
v33 = 0;
v31 = 0;
v29 = 0;
v27 = 1;
}
wclear(stdscr);
printw(
"\rAthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a1 + 1),
*(unsigned int *)a1,
v27,
a1[1]);
printw(
"\rBthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a2 + 1),
*(unsigned int *)a2,
v9,
a2[1]);
printw(
"\rCthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a3 + 1),
*(unsigned int *)a3,
v29,
a3[1]);
printw(
"\rDthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a4 + 1),
*(unsigned int *)a4,
v31,
a4[1]);
printw(
"\rEthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a5 + 1),
*(unsigned int *)a5,
v33,
a5[1]);
v10 = (float)(100 * (*((_DWORD *)a1 + 1) / *(_DWORD *)a1));
v28 = (float)(100 * (*((_DWORD *)a2 + 1) / *(_DWORD *)a2));
v30 = (float)(100 * (*((_DWORD *)a3 + 1) / *(_DWORD *)a3));
v32 = (float)(100 * (*((_DWORD *)a4 + 1) / *(_DWORD *)a4));
v34 = (float)(100 * (*((_DWORD *)a5 + 1) / *(_DWORD *)a5));
v11 = (int)(float)((float)(v10 * 54.0) / 100.0);
v12 = (int)(float)((float)(v28 * 54.0) / 100.0);
v13 = (int)(float)((float)(v30 * 54.0) / 100.0);
v14 = (int)(float)((float)(v32 * 54.0) / 100.0);
v15 = (int)(float)((float)(54.0 * v34) / 100.0);
printw("\rProgress A: %d %% [", (unsigned int)(int)v10);
if ( v11 > 0 )
{
for ( i = 0; i != v11; ++i )
{
printw("=");
print_end_delimiter(i, v11);
}
}
v17 = -1;
if ( stdscr )
v17 = stdscr->_cury;
if ( wmove(stdscr, v17, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress B: %d %% [", (unsigned int)(int)v28);
if ( v12 > 0 )
{
for ( j = 0; j != v12; ++j )
{
printw("=");
print_end_delimiter(j, v12);
}
}
v19 = -1;
if ( stdscr )
v19 = stdscr->_cury;
if ( wmove(stdscr, v19, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress C: %d %% [", (unsigned int)(int)v30);
if ( v13 > 0 )
{
for ( k = 0; k != v13; ++k )
{
printw("=");
print_end_delimiter(k, v13);
}
}
v21 = -1;
if ( stdscr )
v21 = stdscr->_cury;
if ( wmove(stdscr, v21, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress D: %d %% [", (unsigned int)(int)v32);
if ( v14 > 0 )
{
for ( l = 0; l != v14; ++l )
{
printw("=");
print_end_delimiter(l, v14);
}
}
v23 = -1;
if ( stdscr )
v23 = stdscr->_cury;
if ( wmove(stdscr, v23, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress E: %d %% [", (unsigned int)(int)v34);
if ( v15 > 0 )
{
for ( m = 0; m != v15; ++m )
{
printw("=");
print_end_delimiter(m, v15);
}
}
v25 = -1;
if ( stdscr )
v25 = stdscr->_cury;
if ( wmove(stdscr, v25, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func1(double *a1, double *a2, double *a3, double *a4, double *a5, unsigned int a6)
{
unsigned int v9; // er15
float v10; // xmm3_4
int v11; // er15
int v12; // er14
int v13; // er13
int v14; // er12
int v15; // ebp
int i; // ebx
int v17; // esi
int j; // ebx
int v19; // esi
int k; // ebx
int v21; // esi
int l; // ebx
int v23; // esi
int m; // ebx
int v25; // esi
unsigned int v27; // [rsp+0h] [rbp-48h]
float v28; // [rsp+0h] [rbp-48h]
unsigned int v29; // [rsp+4h] [rbp-44h]
float v30; // [rsp+4h] [rbp-44h]
unsigned int v31; // [rsp+8h] [rbp-40h]
float v32; // [rsp+8h] [rbp-40h]
unsigned int v33; // [rsp+Ch] [rbp-3Ch]
float v34; // [rsp+Ch] [rbp-3Ch]

v9 = a6;
if ( a6 )
{
switch ( a6 )
{
case 1u:
v33 = 0;
v31 = 0;
v29 = 0;
v27 = 0;
break;
case 2u:
v33 = 0;
v31 = 0;
v29 = 1;
v9 = 0;
v27 = 0;
break;
case 3u:
v33 = 0;
v31 = 1;
v29 = 0;
v9 = 0;
v27 = 0;
break;
case 4u:
v33 = 1;
v31 = 0;
v29 = 0;
v9 = 0;
v27 = 0;
break;
default:
v33 = 0;
v31 = 0;
v29 = 0;
v9 = 0;
v27 = 1;
break;
}
}
else
{
v33 = 0;
v31 = 0;
v29 = 0;
v27 = 1;
}
wclear(stdscr);
printw(
"\rAthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a1 + 1),
*(unsigned int *)a1,
v27,
a1[1]);
printw(
"\rBthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a2 + 1),
*(unsigned int *)a2,
v9,
a2[1]);
printw(
"\rCthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a3 + 1),
*(unsigned int *)a3,
v29,
a3[1]);
printw(
"\rDthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a4 + 1),
*(unsigned int *)a4,
v31,
a4[1]);
printw(
"\rEthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a5 + 1),
*(unsigned int *)a5,
v33,
a5[1]);
v10 = (float)(100 * (*((_DWORD *)a1 + 1) / *(_DWORD *)a1));
v28 = (float)(100 * (*((_DWORD *)a2 + 1) / *(_DWORD *)a2));
v30 = (float)(100 * (*((_DWORD *)a3 + 1) / *(_DWORD *)a3));
v32 = (float)(100 * (*((_DWORD *)a4 + 1) / *(_DWORD *)a4));
v34 = (float)(100 * (*((_DWORD *)a5 + 1) / *(_DWORD *)a5));
v11 = (int)(float)((float)(v10 * 54.0) / 100.0);
v12 = (int)(float)((float)(v28 * 54.0) / 100.0);
v13 = (int)(float)((float)(v30 * 54.0) / 100.0);
v14 = (int)(float)((float)(v32 * 54.0) / 100.0);
v15 = (int)(float)((float)(54.0 * v34) / 100.0);
printw("\rProgress A: %d %% [", (unsigned int)(int)v10);
if ( v11 > 0 )
{
for ( i = 0; i != v11; ++i )
{
printw("=");
func0(i, v11);
}
}
v17 = -1;
if ( stdscr )
v17 = stdscr->_cury;
if ( wmove(stdscr, v17, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress B: %d %% [", (unsigned int)(int)v28);
if ( v12 > 0 )
{
for ( j = 0; j != v12; ++j )
{
printw("=");
func0(j, v12);
}
}
v19 = -1;
if ( stdscr )
v19 = stdscr->_cury;
if ( wmove(stdscr, v19, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress C: %d %% [", (unsigned int)(int)v30);
if ( v13 > 0 )
{
for ( k = 0; k != v13; ++k )
{
printw("=");
func0(k, v13);
}
}
v21 = -1;
if ( stdscr )
v21 = stdscr->_cury;
if ( wmove(stdscr, v21, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress D: %d %% [", (unsigned int)(int)v32);
if ( v14 > 0 )
{
for ( l = 0; l != v14; ++l )
{
printw("=");
func0(l, v14);
}
}
v23 = -1;
if ( stdscr )
v23 = stdscr->_cury;
if ( wmove(stdscr, v23, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress E: %d %% [", (unsigned int)(int)v34);
if ( v15 > 0 )
{
for ( m = 0; m != v15; ++m )
{
printw("=");
func0(m, v15);
}
}
v25 = -1;
if ( stdscr )
v25 = stdscr->_cury;
if ( wmove(stdscr, v25, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
return wrefresh(stdscr);
}

original_code:
void print2screen(
        threadData_t *ta,
        threadData_t *tb,
        threadData_t *tc,
        threadData_t *td,
        threadData_t *te,
 int active_thread_n
){
 int is_activeA = 0;
 int is_activeB = 0;
 int is_activeC = 0;
 int is_activeD = 0;
 int is_activeE = 0;
        int i;
 int row;
 int col;
 int MAXROW;
 int MAXCOL;
 int P_BAR_WIDTH;
        float progressA;
 float progressB;
 float progressC;
 float progressD;
 float progressE;
 if(active_thread_n == 0){
  is_activeA = 1;
 }else if(active_thread_n == 0){
                is_activeA = 1;
 }else if(active_thread_n == 1){
                is_activeB = 1;
 }else if(active_thread_n == 2){
                is_activeC = 1;
 }else if(active_thread_n == 3){
                is_activeD = 1;
 }else if(active_thread_n == 4){
                is_activeE = 1;
        }else{
  is_activeA = 1;
 }
 wclear(stdscr);
 (MAXROW = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), MAXCOL = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 printw("\rAthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 ta->currPiValue, ta->currTerm, ta->totalTerms, is_activeA);
 printw("\rBthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 tb->currPiValue, tb->currTerm, tb->totalTerms, is_activeB);
 printw("\rCthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 tc->currPiValue, tc->currTerm, tc->totalTerms, is_activeC);
 printw("\rDthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 td->currPiValue, td->currTerm, td->totalTerms, is_activeD);
 printw("\rEthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 te->currPiValue, te->currTerm, te->totalTerms, is_activeE);
 progressA = (ta->currTerm/ta->totalTerms)*100;
 progressB = (tb->currTerm/tb->totalTerms)*100;
 progressC = (tc->currTerm/tc->totalTerms)*100;
 progressD = (td->currTerm/td->totalTerms)*100;
 progressE = (te->currTerm/te->totalTerms)*100;
 P_BAR_WIDTH = 60;
 int total_ticks = P_BAR_WIDTH-6;
 int progress_ticksA = (progressA*total_ticks)/100;
 int progress_ticksB = (progressB*total_ticks)/100;
 int progress_ticksC = (progressC*total_ticks)/100;
 int progress_ticksD = (progressD*total_ticks)/100;
 int progress_ticksE = (progressE*total_ticks)/100;
        printw("\rProgress A: %d %% [", (int) progressA);
        for(i = 0 ; i < (int) progress_ticksA; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksA);
 };
 (row = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress B: %d %% [", (int) progressB);
        for(i = 0 ; i < (int) progress_ticksB; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksB);
 };
 (row = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress C: %d %% [", (int) progressC);
        for(i = 0 ; i < (int) progress_ticksC; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksC);
 };
 (row = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress D: %d %% [", (int) progressD);
        for(i = 0 ; i < (int) progress_ticksD; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksD);
 };
 (row = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress E: %d %% [", (int) progressE);
        for(i = 0 ; i < (int) progress_ticksE; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksE);
 };
 (row = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        wrefresh(stdscr);
}

canonical_original_code:
void print2screen(struct threadData_s *ta, struct threadData_s *tb, struct threadData_s *tc, struct threadData_s *td, struct threadData_s *te, int active_thread_n){
 int is_activeA = 0;
 int is_activeB = 0;
 int is_activeC = 0;
 int is_activeD = 0;
 int is_activeE = 0;
        int i;
 int row;
 int col;
 int MAXROW;
 int MAXCOL;
 int P_BAR_WIDTH;
        float progressA;
 float progressB;
 float progressC;
 float progressD;
 float progressE;
 if(active_thread_n == 0){
  is_activeA = 1;
 }else if(active_thread_n == 0){
                is_activeA = 1;
 }else if(active_thread_n == 1){
                is_activeB = 1;
 }else if(active_thread_n == 2){
                is_activeC = 1;
 }else if(active_thread_n == 3){
                is_activeD = 1;
 }else if(active_thread_n == 4){
                is_activeE = 1;
        }else{
  is_activeA = 1;
 }
 wclear(stdscr);
 (MAXROW = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), MAXCOL = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 printw("\rAthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 ta->currPiValue, ta->currTerm, ta->totalTerms, is_activeA);
 printw("\rBthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 tb->currPiValue, tb->currTerm, tb->totalTerms, is_activeB);
 printw("\rCthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 tc->currPiValue, tc->currTerm, tc->totalTerms, is_activeC);
 printw("\rDthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 td->currPiValue, td->currTerm, td->totalTerms, is_activeD);
 printw("\rEthread: Pi Value: %f  CurrentTerm: %d  TotalTerms: %d Active: %d\n",
 te->currPiValue, te->currTerm, te->totalTerms, is_activeE);
 progressA = (ta->currTerm/ta->totalTerms)*100;
 progressB = (tb->currTerm/tb->totalTerms)*100;
 progressC = (tc->currTerm/tc->totalTerms)*100;
 progressD = (td->currTerm/td->totalTerms)*100;
 progressE = (te->currTerm/te->totalTerms)*100;
 P_BAR_WIDTH = 60;
 int total_ticks = P_BAR_WIDTH-6;
 int progress_ticksA = (progressA*total_ticks)/100;
 int progress_ticksB = (progressB*total_ticks)/100;
 int progress_ticksC = (progressC*total_ticks)/100;
 int progress_ticksD = (progressD*total_ticks)/100;
 int progress_ticksE = (progressE*total_ticks)/100;
        printw("\rProgress A: %d %% [", (int) progressA);
        for(i = 0 ; i < (int) progress_ticksA; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksA);
 };
 (row = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress B: %d %% [", (int) progressB);
        for(i = 0 ; i < (int) progress_ticksB; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksB);
 };
 (row = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress C: %d %% [", (int) progressC);
        for(i = 0 ; i < (int) progress_ticksC; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksC);
 };
 (row = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress D: %d %% [", (int) progressD);
        for(i = 0 ; i < (int) progress_ticksD; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksD);
 };
 (row = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        printw("\rProgress E: %d %% [", (int) progressE);
        for(i = 0 ; i < (int) progress_ticksE; i++){
         printw("=");
  print_end_delimiter(i,(int) progress_ticksE);
 };
 (row = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), col = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 (wmove((stdscr),((row)),((total_ticks+20))) == (-1) ? (-1) : waddnstr((stdscr),(("]")),-1));
        printw("\n");
        wrefresh(stdscr);
}

variable_types: struct threadData_s { int totalTerms; int currTerm; double currPiValue; } *

variable_types:
tb
struct threadData_s *

variable_types:
tc
struct threadData_s *

variable_types:
td
struct threadData_s *

variable_types:
te
struct threadData_s *

variable_types: row int

variable_types: col int

variable_types: MAXROW int

variable_types: MAXCOL int

variable_types: progressA float

variable_types: progressB float

variable_types: progressC float

variable_types: progressD float

variable_types: progressE float


calculatePI

original_code:
void calculatePI(threadData_t *t ,double percentage)
{
   double tempResultA = 0;
   double tempResultB = 1;
   double n = 2;
   double m = 2;
   int numTermsExecute = 0;
   int totalIterations = 0;
   int currentIteration = 1;
   if(percentage == 100)
   {
      numTermsExecute = t->totalTerms;
   }
   else
   {
      numTermsExecute = t->totalTerms*(percentage/100);
 totalIterations = (t->totalTerms/numTermsExecute) + 1;
   }
   if(t->totalTerms == 1)
   {
      t->currPiValue = 2*1;
      return;
   }
   else
   {
     t->currPiValue = 2*1;
   }
   while (n <= t->totalTerms)
   {
      tempResultA = 2*(1/((2*n)-1));
      while(m <= n)
      {
          tempResultB = tempResultB*(((2*m)-3)/((2*m)-2));
          m++;
      }
      t->currPiValue = t->currPiValue + (tempResultA*tempResultB);
      t->currTerm = n;
      n++;
      m = 2;
      tempResultB = 1;
      if (totalIterations != 0 && (n == (numTermsExecute*currentIteration)))
      {
            currentIteration++;
  printf("---Giving Control to Scheduler---\n");
     syscall(26);
      }
   }
}

canonical_original_code:
void calculatePI(struct threadData_s *t, double percentage)
{
   double tempResultA = 0;
   double tempResultB = 1;
   double n = 2;
   double m = 2;
   int numTermsExecute = 0;
   int totalIterations = 0;
   int currentIteration = 1;
   if(percentage == 100)
   {
      numTermsExecute = t->totalTerms;
   }
   else
   {
      numTermsExecute = t->totalTerms*(percentage/100);
 totalIterations = (t->totalTerms/numTermsExecute) + 1;
   }
   if(t->totalTerms == 1)
   {
      t->currPiValue = 2*1;
      return;
   }
   else
   {
     t->currPiValue = 2*1;
   }
   while (n <= t->totalTerms)
   {
      tempResultA = 2*(1/((2*n)-1));
      while(m <= n)
      {
          tempResultB = tempResultB*(((2*m)-3)/((2*m)-2));
          m++;
      }
      t->currPiValue = t->currPiValue + (tempResultA*tempResultB);
      t->currTerm = n;
      n++;
      m = 2;
      tempResultB = 1;
      if (totalIterations != 0 && (n == (numTermsExecute*currentIteration)))
      {
            currentIteration++;
  printf("---Giving Control to Scheduler---\n");
     syscall(26);
      }
   }
}

variable_types: percentage double

variable_types: tempResultA double

variable_types: tempResultB double

variable_types: n double

variable_types: m double

variable_types: numTermsExecute int

variable_types: totalIterations int

variable_types: currentIteration int

user_defined_types: struct threadData_s { int totalTerms; int currTerm; double currPiValue; }


lcdWrite

repo: rtucker/raspi-fridge-overseer

original_code:
void lcdWrite(char *txbuf)
{
    int i;
    char newbuf[16 + 1];
    char space_out = (1==2);
    for (i = 0; i < 16; i++)
    {
        if (0 == (char)*(txbuf + i))
        {
            space_out = (1==1);
        }
        if ((1==1) == space_out)
        {
            newbuf[i] = ' ';
        }
        else
        {
            newbuf[i] = (char)*(txbuf + i);
        }
    }
    newbuf[16] = 0;
    uartTx(newbuf, 16);
}

canonical_original_code:
void lcdWrite(char *txbuf)
{
    int i;
    char newbuf[-1];
    char space_out = (1==2);
    for (i = 0; i < 16; i++)
    {
        if (0 == (char)*(txbuf + i))
        {
            space_out = (1==1);
        }
        if ((1==1) == space_out)
        {
            newbuf[i] = ' ';
        }
        else
        {
            newbuf[i] = (char)*(txbuf + i);
        }
    }
    newbuf[16] = 0;
    uartTx(newbuf, 16);
}

variable_types:
txbuf
char *

variable_types: i int

variable_types:
newbuf
char [-1]


lcdClear

decompiled_code:
__int64 lcdClear()
{
return uartTx(&unk_402004, 2uLL);
}

original_code:
void lcdClear()
{
    uartTx("\xFE\x01", 2);
}


lcdMoveLeft

decompiled_code:
__int64 lcdMoveLeft()
{
return uartTx(&unk_402007, 2uLL);
}

original_code:
void lcdMoveLeft()
{
    uartTx("\xFE\x10", 2);
}


lcdMoveRight

decompiled_code:
__int64 lcdMoveRight()
{
return uartTx(&unk_40200A, 2uLL);
}

canonical_decompiled_code:
__int64 func10()
{
return func22(&unk_40200A, 2uLL);
}

original_code:
void lcdMoveRight()
{
    uartTx("\xFE\x14", 2);
}


lcdScrollLeft

decompiled_code:
__int64 lcdScrollLeft()
{
return uartTx(&unk_40200D, 2uLL);
}

canonical_decompiled_code:
__int64 func11()
{
return func22(&unk_40200D, 2uLL);
}

original_code:
void lcdScrollLeft()
{
    uartTx("\xFE\x18", 2);
}


lcdScrollRight

decompiled_code:
__int64 lcdScrollRight()
{
return uartTx(&unk_402010, 2uLL);
}

original_code:
void lcdScrollRight()
{
    uartTx("\xFE\x1C", 2);
}


lcdVisualDisplayOn

decompiled_code:
__int64 lcdVisualDisplayOn()
{
return uartTx(&unk_402013, 2uLL);
}

original_code:
void lcdVisualDisplayOn()
{
    uartTx("\xFE\x0C", 2);
}


lcdVisualDisplayOff

decompiled_code:
__int64 lcdVisualDisplayOff()
{
return uartTx(&unk_402016, 2uLL);
}

original_code:
void lcdVisualDisplayOff()
{
    uartTx("\xFE\x08", 2);
}


lcdUnderlineCursorOn

decompiled_code:
__int64 lcdUnderlineCursorOn()
{
return uartTx(&unk_402019, 2uLL);
}

original_code:
void lcdUnderlineCursorOn()
{
    uartTx("\xFE\x0E", 2);
}


lcdUnderlineCursorOff

decompiled_code:
__int64 lcdUnderlineCursorOff()
{
return uartTx(&unk_402013, 2uLL);
}

original_code:
void lcdUnderlineCursorOff()
{
    uartTx("\xFE\x0C", 2);
}


lcdBoxCursorOn

decompiled_code:
__int64 lcdBoxCursorOn()
{
return uartTx(&unk_40201C, 2uLL);
}

canonical_decompiled_code:
__int64 func17()
{
return func22(&unk_40201C, 2uLL);
}

original_code:
void lcdBoxCursorOn()
{
    uartTx("\xFE\x0D", 2);
}


lcdBoxCursorOff

decompiled_code:
__int64 lcdBoxCursorOff()
{
return uartTx(&unk_402013, 2uLL);
}

original_code:
void lcdBoxCursorOff()
{
    uartTx("\xFE\x0C", 2);
}


lcdSetBrightness

decompiled_code:
__int64 lcdSetBrightness()
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[0] = 124;
buf[1] = 0x80;
buf[2] = 0;
return uartTx(buf, 2uLL);
}

canonical_decompiled_code:
__int64 func19()
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[0] = 124;
buf[1] = 0x80;
buf[2] = 0;
return func22(buf, 2uLL);
}

original_code:
void lcdSetBrightness(char level)
{
    char uartOut[3];
    char pwmValue;
    pwmValue = (level / 8) + 128;
    if (pwmValue > 157)
    {
        pwmValue = 157;
    }
    if (pwmValue < 128)
    {
        pwmValue = 128;
    }
    uartOut[0] = 0x7C;
    uartOut[1] = pwmValue;
    uartOut[2] = 0;
    uartTx(uartOut, 2);
}

variable_types: level char

variable_types:
uartOut
char [3]

variable_types: pwmValue char