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 func8(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 *

return_type: int


readelfheader

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

v2 = __errno_location();
*v2 = 0;
v3 = v2;
if ( read(fd, buf, 0x34uLL) != 52 )
{
if ( !*v3 )
err("missing or incomplete ELF header.");
v5 = strerror(*v3);
err(v5);
}
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.");
if ( (unsigned __int16)(*((_WORD *)buf + 8) - 2) > 1u )
err("not an executable or shared-object library.");
return 1LL;
}

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

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

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, _QWORD *a3)
{
unsigned __int16 v3; // ax
size_t v4; // rbp
void *v6; // rax
void *v7; // r12
int *v8; // rax
int *v9; // rbx
char *v11; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func10(int fd, __int64 a2, _QWORD *a3)
{
unsigned __int16 v3; // ax
size_t v4; // rbp
void *v6; // rax
void *v7; // r12
int *v8; // rax
int *v9; // rbx
char *v11; // rdi

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

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
size_t v3; // rbx
bool v4; // al
char *v6; // rdi
int v7; // er8
int *v8; // rax
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = *a2;
do
{
if ( v2 <= 0x3FF )
{
v3 = v2;
if ( lseek(fd, 0LL, 0) == -1 )
{
LABEL_13:
v6 = "cannot seek in file.";
v7 = *__errno_location();
if ( !v7 )
goto LABEL_14;
goto LABEL_18;
}
}
else
{
v3 = 1024LL;
if ( lseek(fd, v2 - 1024, 0) == -1 )
goto LABEL_13;
}
if ( read(fd, v9, v3) != v3 )
{
v8 = __errno_location();
v6 = "cannot read file contents";
v7 = *v8;
if ( !*v8 )
LABEL_14:
err(v6);
LABEL_18:
v6 = strerror(v7);
goto LABEL_14;
}
while ( 1 )
{
if ( !v3 )
{
v4 = 1;
if ( !v2 )
goto LABEL_16;
goto LABEL_10;
}
if ( v9[--v3] )
break;
--v2;
}
v4 = v3 == 0;
if ( !v2 )
{
LABEL_16:
v6 = "ELF file is completely blank!";
goto LABEL_14;
}
LABEL_10:
;
}
while ( v4 );
*a2 = v2;
return 1LL;
}

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

v2 = *a2;
do
{
if ( v2 <= 0x3FF )
{
v3 = v2;
if ( lseek(fd, 0LL, 0) == -1 )
{
LABEL_13:
v6 = "cannot seek in file.";
v7 = *__errno_location();
if ( !v7 )
goto LABEL_14;
goto LABEL_18;
}
}
else
{
v3 = 1024LL;
if ( lseek(fd, v2 - 1024, 0) == -1 )
goto LABEL_13;
}
if ( read(fd, v9, v3) != v3 )
{
v8 = __errno_location();
v6 = "cannot read file contents";
v7 = *v8;
if ( !*v8 )
LABEL_14:
func8(v6);
LABEL_18:
v6 = strerror(v7);
goto LABEL_14;
}
while ( 1 )
{
if ( !v3 )
{
v4 = 1;
if ( !v2 )
goto LABEL_16;
goto LABEL_10;
}
if ( v9[--v3] )
break;
--v2;
}
v4 = v3 == 0;
if ( !v2 )
{
LABEL_16:
v6 = "ELF file is completely blank!";
goto LABEL_14;
}
LABEL_10:
;
}
while ( v4 );
*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)
{
__off_t v7; // r12
int *v8; // rax
const char *v9; // rdi
ssize_t v10; // rax
size_t v11; // r12
ssize_t v12; // rax
char *v13; // rdi
unsigned __int64 v14; // rax
__off_t v15; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func12(int fd, void *buf, void *a3, unsigned __int64 a4)
{
__off_t v7; // r12
int *v8; // rax
const char *v9; // rdi
ssize_t v10; // rax
size_t v11; // r12
ssize_t v12; // rax
char *v13; // rdi
unsigned __int64 v14; // rax
__off_t v15; // rsi

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

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; // rbx
int v5; // er12
int v6; // eax
int v7; // ebp
char *v8; // rdi
int v9; // er8
_BOOL8 v10; // rax
void *v12; // [rsp+0h] [rbp-68h]
__int64 v13; // [rsp+8h] [rbp-60h] BYREF
char buf[28]; // [rsp+10h] [rbp-58h] BYREF
unsigned int v15; // [rsp+2Ch] [rbp-3Ch]
unsigned __int16 v16; // [rsp+3Ch] [rbp-2Ch]

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.");
LODWORD(v10) = 0;
}
else
{
v4 = argv + 1;
v5 = 0;
progname = (__int64)*argv;
do
{
filename = (__int64)v3;
v6 = open(v3, 2, envp);
v7 = v6;
if ( v6 < 0 )
{
v8 = "can't open";
v9 = *__errno_location();
if ( v9 )
v8 = strerror(v9);
err(v8);
}
if ( !(unsigned int)readelfheader(v6, buf)
|| !(unsigned int)readphdrtable(v7)
|| !(unsigned int)getmemorysize_isra_0(v15, v16, v12, &v13)
|| !(unsigned int)truncatezeros(v7)
|| !(unsigned int)modifyheaders(buf, v12, v13)
|| !(unsigned int)commitchanges(v7, buf, v12) )
{
++v5;
}
++v4;
close(v7);
v3 = *v4;
}
while ( *v4 );
v10 = v5 != 0;
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
const char **v4; // rbx
int v5; // er12
int v6; // eax
int v7; // ebp
char *v8; // rdi
int v9; // er8
_BOOL8 v10; // rax
void *v12; // [rsp+0h] [rbp-68h]
__int64 v13; // [rsp+8h] [rbp-60h] BYREF
char buf[28]; // [rsp+10h] [rbp-58h] BYREF
unsigned int v15; // [rsp+2Ch] [rbp-3Ch]
unsigned __int16 v16; // [rsp+3Ch] [rbp-2Ch]

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.");
LODWORD(v10) = 0;
}
else
{
v4 = argv + 1;
v5 = 0;
progname = (__int64)*argv;
do
{
filename = (__int64)v3;
v6 = open(v3, 2, envp);
v7 = v6;
if ( v6 < 0 )
{
v8 = "can't open";
v9 = *__errno_location();
if ( v9 )
v8 = strerror(v9);
func8(v8);
}
if ( !(unsigned int)func9(v6, buf)
|| !(unsigned int)func10(v7)
|| !(unsigned int)func13(v15, v16, v12, &v13)
|| !(unsigned int)func11(v7)
|| !(unsigned int)func7(buf, v12, v13)
|| !(unsigned int)func12(v7, buf, v12) )
{
++v5;
}
++v4;
close(v7);
v3 = *v4;
}
while ( *v4 );
v10 = v5 != 0;
}
return v10;
}

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

decompiled_code:
__int64 initRobot()
{
__int64 result; // rax

*((_DWORD *)&botData + 8) = 0;
*((_WORD *)&botData + 18) = 69;
result = 0x320000003CLL;
*(_QWORD *)((char *)&botData + 4) = 0x320000003CLL;
*(_QWORD *)((char *)&botData + 12) = 0LL;
*(_QWORD *)((char *)&botData + 20) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

*((_DWORD *)&botData + 8) = 0;
*((_WORD *)&botData + 18) = 69;
result = 0x320000003CLL;
*(_QWORD *)((char *)&botData + 4) = 0x320000003CLL;
*(_QWORD *)((char *)&botData + 12) = 0LL;
*(_QWORD *)((char *)&botData + 20) = 0LL;
return result;
}

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()
{
__int64 v0; // rbx
unsigned int v1; // ebp
char *v2; // rax
unsigned int v3; // er12

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

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

v0 = 0LL;
puts("mcastSubscribe() started");
v1 = botData[1];
printf("My position R%d = X=%d,Y=%d\n", 0LL, v1, botData[2]);
do
{
v2 = (char *)&timeInstMatrix + 360 * (unsigned int)timeInst + 36 * (int)v0;
v3 = *((_DWORD *)v2 + 1);
printf("Check position of robot R%d = X=%d,Y=%d\n", (unsigned int)v0, v3, *((unsigned int *)v2 + 2));
if ( (int)(v1 - v3) <= 9 )
subscribeArr[v0] = 1;
++v0;
}
while ( v0 != 10 );
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()
{
__int64 v0; // rbx
unsigned int v1; // ebp
char *v2; // rax
unsigned int v3; // er12

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

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

v0 = 1LL;
puts("mcastUnSubscribe() started");
v1 = botData[1];
printf("My position R%d = X=%d,Y=%d\n", 0LL, v1, botData[2]);
do
{
v2 = (char *)&timeInstMatrix + 360 * (unsigned int)timeInst + 36 * (int)v0;
v3 = *((_DWORD *)v2 + 1);
printf("Check position of robot R%d = X=%d,Y=%d\n", (unsigned int)v0, v3, *((unsigned int *)v2 + 2));
if ( (int)(v1 - v3) > 9 )
subscribeArr[v0] = 0;
++v0;
}
while ( v0 != 11 );
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()
{
unsigned int v1; // eax

puts("decisionMaking() started");
if ( *((_BYTE *)&obstacle + 2) )
{
v1 = botData[2];
if ( (_BYTE)obstacle )
{
if ( HIBYTE(obstacle) )
{
nextMoveX = botData[1];
}
else
{
--v1;
nextMoveX = botData[1];
move = 4;
}
nextMoveY = v1;
}
else
{
nextMoveX = botData[1];
move = 1;
nextMoveY = v1 + 1;
}
}
else
{
move = 3;
nextMoveX = botData[1] + 1;
nextMoveY = botData[2];
}
updateRobot_isra_0();
return puts("decisionMaking() correctly run");
}

canonical_decompiled_code:
int func6()
{
unsigned int v1; // eax

puts("decisionMaking() started");
if ( *((_BYTE *)&obstacle + 2) )
{
v1 = botData[2];
if ( (_BYTE)obstacle )
{
if ( HIBYTE(obstacle) )
{
nextMoveX = botData[1];
}
else
{
--v1;
nextMoveX = botData[1];
move = 4;
}
nextMoveY = v1;
}
else
{
nextMoveX = botData[1];
move = 1;
nextMoveY = v1 + 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

decompiled_code:
int __fastcall dataProcessing()
{
int v0; // er12
int v1; // er13
bool v2; // r10
bool v3; // r9
signed int v4; // ebp
signed int v5; // ebx
int v6; // er14
signed int *v7; // rax
signed int v8; // edx
signed int v9; // er8
signed int v10; // esi
signed int v11; // edi
bool v12; // zf
bool v13; // sf
bool v14; // of
char v15; // di
unsigned __int8 v16; // cl
int v17; // er8
unsigned __int64 v18; // r15
unsigned __int64 v19; // rcx
signed int v20; // edx
signed int v21; // ebp
int *v22; // rbx
__int64 v23; // rsi
int v24; // eax
int v25; // eax
int v26; // eax
char v28; // [rsp+4h] [rbp-44h]
signed int v29; // [rsp+4h] [rbp-44h]
int v30; // [rsp+8h] [rbp-40h]
int v31; // [rsp+8h] [rbp-40h]

v2 = 0;
v3 = 0;
v4 = botData[2];
v5 = botData[1];
*((_BYTE *)&obstacle + 2) = 0;
v28 = 0;
obstacle = 0;
v6 = v5 + 1;
v7 = (signed int *)&obstacleMap;
v30 = v4 + 1;
do
{
v8 = *v7;
v9 = v7[1];
v10 = v7[2];
v11 = v7[3];
if ( v5 >= *v7 && v5 <= v10 && v4 < v11 && v30 >= v9 )
v2 = v4 < v11 && v30 >= v9;
if ( v8 <= v6 && v4 <= v11 && v5 < v10 && v4 >= v9 )
v3 = v4 <= v11 && v5 < v10 && v4 >= v9;
if ( v5 > v8 && v5 - 1 <= v10 )
{
v14 = __OFSUB__(v4, v11);
v12 = v4 == v11;
v13 = v4 - v11 < 0;
v15 = v28;
v16 = v13 ^ v14 | v12;
if ( (v16 & (v4 >= v9)) != 0 )
v15 = v16 & (v4 >= v9);
v28 = v15;
}
v7 += 4;
}
while ( (signed int *)(unsigned int)((_DWORD)&obstacleMap + 64) != v7 );
if ( v3 )
*((_BYTE *)&obstacle + 2) = 1;
if ( v2 )
LOBYTE(obstacle) = 1;
if ( v28 )
HIBYTE(obstacle) = 1;
v17 = v4 + 1;
v18 = (unsigned int)((_DWORD)&timeInstMatrix + 1444);
v19 = (unsigned int)((_DWORD)&timeInstMatrix + 1804);
v20 = v4;
v21 = v5;
v22 = subscribeArr;
do
{
while ( 1 )
{
if ( *v22 == 1 )
{
v23 = (unsigned int)++dataCollectionCtr;
if ( timeInst == 61 )
{
v31 = v17;
v29 = v20;
printf("DataCollection Bots processed = %d\n", v23);
v17 = v31;
v20 = v29;
v19 = (unsigned int)((_DWORD)&timeInstMatrix + 1804);
}
v24 = *(_DWORD *)(v18 + 12);
if ( v24 == 3 )
{
v0 = 1;
v1 = 0;
}
else if ( v24 == 4 )
{
v1 = -1;
v0 = 0;
}
else
{
if ( v24 == 1 )
v1 = 1;
if ( v24 == 1 )
v0 = 0;
}
v25 = v0 + *(_DWORD *)v18;
if ( v25 == v6 && v1 + *(_DWORD *)(v18 + 4) == v20 )
{
*((_BYTE *)&obstacle + 2) = 1;
goto LABEL_22;
}
if ( v25 == v21 )
{
v26 = v1 + *(_DWORD *)(v18 + 4);
if ( v26 == v17 )
{
LOBYTE(obstacle) = 1;
goto LABEL_22;
}
if ( v26 == v20 - 1 )
break;
}
}
LABEL_22:
v18 += 36LL;
++v22;
if ( v19 == v18 )
return puts("dataProcessing() correctly run");
}
v18 += 36LL;
HIBYTE(obstacle) = 1;
++v22;
}
while ( v19 != v18 );
return puts("dataProcessing() correctly run");
}

canonical_decompiled_code:
int __fastcall func7()
{
int v0; // er12
int v1; // er13
bool v2; // r10
bool v3; // r9
signed int v4; // ebp
signed int v5; // ebx
int v6; // er14
signed int *v7; // rax
signed int v8; // edx
signed int v9; // er8
signed int v10; // esi
signed int v11; // edi
bool v12; // zf
bool v13; // sf
bool v14; // of
char v15; // di
unsigned __int8 v16; // cl
int v17; // er8
unsigned __int64 v18; // r15
unsigned __int64 v19; // rcx
signed int v20; // edx
signed int v21; // ebp
int *v22; // rbx
__int64 v23; // rsi
int v24; // eax
int v25; // eax
int v26; // eax
char v28; // [rsp+4h] [rbp-44h]
signed int v29; // [rsp+4h] [rbp-44h]
int v30; // [rsp+8h] [rbp-40h]
int v31; // [rsp+8h] [rbp-40h]

v2 = 0;
v3 = 0;
v4 = botData[2];
v5 = botData[1];
*((_BYTE *)&obstacle + 2) = 0;
v28 = 0;
obstacle = 0;
v6 = v5 + 1;
v7 = (signed int *)&obstacleMap;
v30 = v4 + 1;
do
{
v8 = *v7;
v9 = v7[1];
v10 = v7[2];
v11 = v7[3];
if ( v5 >= *v7 && v5 <= v10 && v4 < v11 && v30 >= v9 )
v2 = v4 < v11 && v30 >= v9;
if ( v8 <= v6 && v4 <= v11 && v5 < v10 && v4 >= v9 )
v3 = v4 <= v11 && v5 < v10 && v4 >= v9;
if ( v5 > v8 && v5 - 1 <= v10 )
{
v14 = __OFSUB__(v4, v11);
v12 = v4 == v11;
v13 = v4 - v11 < 0;
v15 = v28;
v16 = v13 ^ v14 | v12;
if ( (v16 & (v4 >= v9)) != 0 )
v15 = v16 & (v4 >= v9);
v28 = v15;
}
v7 += 4;
}
while ( (signed int *)(unsigned int)((_DWORD)&obstacleMap + 64) != v7 );
if ( v3 )
*((_BYTE *)&obstacle + 2) = 1;
if ( v2 )
LOBYTE(obstacle) = 1;
if ( v28 )
HIBYTE(obstacle) = 1;
v17 = v4 + 1;
v18 = (unsigned int)((_DWORD)&timeInstMatrix + 1444);
v19 = (unsigned int)((_DWORD)&timeInstMatrix + 1804);
v20 = v4;
v21 = v5;
v22 = subscribeArr;
do
{
while ( 1 )
{
if ( *v22 == 1 )
{
v23 = (unsigned int)++dataCollectionCtr;
if ( timeInst == 61 )
{
v31 = v17;
v29 = v20;
printf("DataCollection Bots processed = %d\n", v23);
v17 = v31;
v20 = v29;
v19 = (unsigned int)((_DWORD)&timeInstMatrix + 1804);
}
v24 = *(_DWORD *)(v18 + 12);
if ( v24 == 3 )
{
v0 = 1;
v1 = 0;
}
else if ( v24 == 4 )
{
v1 = -1;
v0 = 0;
}
else
{
if ( v24 == 1 )
v1 = 1;
if ( v24 == 1 )
v0 = 0;
}
v25 = v0 + *(_DWORD *)v18;
if ( v25 == v6 && v1 + *(_DWORD *)(v18 + 4) == v20 )
{
*((_BYTE *)&obstacle + 2) = 1;
goto LABEL_22;
}
if ( v25 == v21 )
{
v26 = v1 + *(_DWORD *)(v18 + 4);
if ( v26 == v17 )
{
LOBYTE(obstacle) = 1;
goto LABEL_22;
}
if ( v26 == v20 - 1 )
break;
}
}
LABEL_22:
v18 += 36LL;
++v22;
if ( v19 == v18 )
return puts("dataProcessing() correctly run");
}
v18 += 36LL;
HIBYTE(obstacle) = 1;
++v22;
}
while ( v19 != v18 );
return puts("dataProcessing() correctly run");
}

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 v1; // ebx
__int64 v2; // rax

timeInst = 0;
dataCollectionCtr = 0;
if ( (unsigned int)pth_init() == 1 )
{
pt[0] = pth_self();
while ( 1 )
{
v1 = 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);
do
{
v2 = v1++;
pth_yield(pt[v2]);
}
while ( v1 != 7 );
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 v1; // ebx
__int64 v2; // rax

timeInst = 0;
dataCollectionCtr = 0;
if ( (unsigned int)pth_init() == 1 )
{
pt[0] = pth_self();
while ( 1 )
{
v1 = 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);
do
{
v2 = v1++;
pth_yield(pt[v2]);
}
while ( v1 != 7 );
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

v0 = (unsigned int)(50 * *((_DWORD *)&config + 6));
*((_QWORD *)&config + 7) = 0x100000001LL;
*((_QWORD *)&config + 8) = 0x100000001LL;
LODWORD(Athread) = v0;
*((_DWORD *)&config + 18) = 1;
*((_QWORD *)&Athread + 1) = 0LL;
printf("ATotalTerms %d\n", v0);
v1 = (unsigned int)(50 * *((_DWORD *)&config + 7));
*((_QWORD *)&Bthread + 1) = 0LL;
LODWORD(Bthread) = v1;
printf("BTotalTerms %d\n", v1);
v2 = (unsigned int)(50 * *((_DWORD *)&config + 8));
*((_QWORD *)&Cthread + 1) = 0LL;
LODWORD(Cthread) = v2;
printf("CTotalTerms %d\n", v2);
v3 = (unsigned int)(50 * *((_DWORD *)&config + 9));
*((_QWORD *)&Dthread + 1) = 0LL;
LODWORD(Dthread) = v3;
printf("DTotalTerms %d\n", v3);
v4 = (unsigned int)(50 * *((_DWORD *)&config + 10));
*((_QWORD *)&Ethread + 1) = 0LL;
LODWORD(Ethread) = v4;
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

v0 = (unsigned int)(50 * *((_DWORD *)&config + 6));
*((_QWORD *)&config + 7) = 0x100000001LL;
*((_QWORD *)&config + 8) = 0x100000001LL;
LODWORD(Athread) = v0;
*((_DWORD *)&config + 18) = 1;
*((_QWORD *)&Athread + 1) = 0LL;
printf("ATotalTerms %d\n", v0);
v1 = (unsigned int)(50 * *((_DWORD *)&config + 7));
*((_QWORD *)&Bthread + 1) = 0LL;
LODWORD(Bthread) = v1;
printf("BTotalTerms %d\n", v1);
v2 = (unsigned int)(50 * *((_DWORD *)&config + 8));
*((_QWORD *)&Cthread + 1) = 0LL;
LODWORD(Cthread) = v2;
printf("CTotalTerms %d\n", v2);
v3 = (unsigned int)(50 * *((_DWORD *)&config + 9));
*((_QWORD *)&Dthread + 1) = 0LL;
LODWORD(Dthread) = v3;
printf("DTotalTerms %d\n", v3);
v4 = (unsigned int)(50 * *((_DWORD *)&config + 10));
*((_QWORD *)&Ethread + 1) = 0LL;
LODWORD(Ethread) = v4;
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);
}

return_type: void


algo

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

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

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

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

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)
{
int v1; // ecx
int v2; // edx
int v3; // eax
int v4; // esi
bool result; // al
int v6; // eax
int v7; // ecx

switch ( a1 )
{
case 1:
config[14] = 0;
v3 = config[15];
v1 = config[16];
v2 = config[17];
goto LABEL_4;
case 2:
v1 = config[16];
v2 = config[17];
v3 = 0;
config[15] = 0;
LABEL_4:
v4 = config[18];
return (v4 | v2 | config[14] | v1 | v3) == 0;
case 3:
v3 = config[15];
v2 = config[17];
v1 = 0;
config[16] = 0;
v4 = config[18];
return (v4 | v2 | config[14] | v1 | v3) == 0;
case 4:
v6 = config[15];
v7 = config[16];
config[17] = 0;
result = (config[18] | config[14] | v7 | v6) == 0;
break;
default:
v3 = config[15];
v1 = config[16];
v2 = config[17];
if ( a1 != 5 )
goto LABEL_4;
config[18] = 0;
result = (v2 | config[14] | v1 | v3) == 0;
break;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func6(int a1)
{
int v1; // ecx
int v2; // edx
int v3; // eax
int v4; // esi
bool result; // al
int v6; // eax
int v7; // ecx

switch ( a1 )
{
case 1:
config[14] = 0;
v3 = config[15];
v1 = config[16];
v2 = config[17];
goto LABEL_4;
case 2:
v1 = config[16];
v2 = config[17];
v3 = 0;
config[15] = 0;
LABEL_4:
v4 = config[18];
return (v4 | v2 | config[14] | v1 | v3) == 0;
case 3:
v3 = config[15];
v2 = config[17];
v1 = 0;
config[16] = 0;
v4 = config[18];
return (v4 | v2 | config[14] | v1 | v3) == 0;
case 4:
v6 = config[15];
v7 = config[16];
config[17] = 0;
result = (config[18] | config[14] | v7 | v6) == 0;
break;
default:
v3 = config[15];
v1 = config[16];
v2 = config[17];
if ( a1 != 5 )
goto LABEL_4;
config[18] = 0;
result = (v2 | config[14] | v1 | v3) == 0;
break;
}
return result;
}

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

decompiled_code:
int schedulerInit()
{
initDone = 1;
*((_DWORD *)&sData + 251) = 0;
*((_BYTE *)&sData + 1008) = 0;
return init_threads();
}

canonical_decompiled_code:
int func7()
{
initDone = 1;
*((_DWORD *)&sData + 251) = 0;
*((_BYTE *)&sData + 1008) = 0;
return func0();
}

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

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(26LL, scheduler);
signal(26, scheduler);
preemtiveTime();
puts("sigalm passed");
v1 = *((unsigned int *)&sData + 250);
if ( !*((_BYTE *)&sData + v1 + 1004) )
{
printf("initializing thread: %d\n", *((unsigned int *)&sData + 250));
*((_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; // rax

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(26LL, scheduler);
signal(26, scheduler);
func5();
puts("sigalm passed");
v1 = *((unsigned int *)&sData + 250);
if ( !*((_BYTE *)&sData + v1 + 1004) )
{
printf("initializing thread: %d\n", *((unsigned int *)&sData + 250));
*((_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 v6; // er15
int v10; // er8
int v11; // er9
int v12; // er10
int v13; // ecx
float v14; // xmm3_4
int v15; // er15
int v16; // er14
int v17; // er13
int v18; // er12
int v19; // ebp
int i; // ebx
int v21; // edi
int v22; // esi
int j; // ebx
int v24; // edi
int v25; // esi
int k; // ebx
int v27; // edi
int v28; // esi
int l; // ebx
int v30; // edi
int v31; // esi
int m; // ebx
int v33; // edi
int v34; // esi
unsigned int v36; // [rsp+0h] [rbp-48h]
float v37; // [rsp+0h] [rbp-48h]
unsigned int v38; // [rsp+4h] [rbp-44h]
float v39; // [rsp+4h] [rbp-44h]
unsigned int v40; // [rsp+8h] [rbp-40h]
float v41; // [rsp+8h] [rbp-40h]
unsigned int v42; // [rsp+Ch] [rbp-3Ch]
float v43; // [rsp+Ch] [rbp-3Ch]

v6 = a6;
if ( a6 )
{
switch ( a6 )
{
case 1u:
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 0;
break;
case 2u:
v10 = 0;
v11 = 0;
v12 = 1;
v6 = 0;
v13 = 0;
break;
case 3u:
v10 = 0;
v11 = 1;
v12 = 0;
v6 = 0;
v13 = 0;
break;
case 4u:
v10 = 1;
v11 = 0;
v12 = 0;
v6 = 0;
v13 = 0;
break;
default:
v10 = 0;
v11 = 0;
v12 = 0;
v6 = 0;
v13 = 1;
break;
}
}
else
{
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 1;
}
v42 = v10;
v40 = v11;
v38 = v12;
v36 = v13;
wclear(stdscr);
printw(
"\rAthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a1 + 1),
*(unsigned int *)a1,
v36,
a1[1]);
printw(
"\rBthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a2 + 1),
*(unsigned int *)a2,
v6,
a2[1]);
printw(
"\rCthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a3 + 1),
*(unsigned int *)a3,
v38,
a3[1]);
printw(
"\rDthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a4 + 1),
*(unsigned int *)a4,
v40,
a4[1]);
printw(
"\rEthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a5 + 1),
*(unsigned int *)a5,
v42,
a5[1]);
v14 = (float)(100 * (*((_DWORD *)a1 + 1) / *(_DWORD *)a1));
v37 = (float)(100 * (*((_DWORD *)a2 + 1) / *(_DWORD *)a2));
v15 = (int)(float)((float)(v14 * 54.0) / 100.0);
v39 = (float)(100 * (*((_DWORD *)a3 + 1) / *(_DWORD *)a3));
v16 = (int)(float)((float)(v37 * 54.0) / 100.0);
v41 = (float)(100 * (*((_DWORD *)a4 + 1) / *(_DWORD *)a4));
v17 = (int)(float)((float)(v39 * 54.0) / 100.0);
v43 = (float)(100 * (*((_DWORD *)a5 + 1) / *(_DWORD *)a5));
v18 = (int)(float)((float)(v41 * 54.0) / 100.0);
v19 = (int)(float)((float)(54.0 * v43) / 100.0);
printw("\rProgress A: %d %% [", (unsigned int)(int)v14);
if ( v15 > 0 )
{
for ( i = 0; i != v15; ++i )
{
printw("=");
v21 = i;
print_end_delimiter(v21, v15);
}
}
v22 = -1;
if ( stdscr )
v22 = stdscr->_cury;
if ( wmove(stdscr, v22, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress B: %d %% [", (unsigned int)(int)v37);
if ( v16 > 0 )
{
for ( j = 0; j != v16; ++j )
{
printw("=");
v24 = j;
print_end_delimiter(v24, v16);
}
}
v25 = -1;
if ( stdscr )
v25 = stdscr->_cury;
if ( wmove(stdscr, v25, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress C: %d %% [", (unsigned int)(int)v39);
if ( v17 > 0 )
{
for ( k = 0; k != v17; ++k )
{
printw("=");
v27 = k;
print_end_delimiter(v27, v17);
}
}
v28 = -1;
if ( stdscr )
v28 = stdscr->_cury;
if ( wmove(stdscr, v28, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress D: %d %% [", (unsigned int)(int)v41);
if ( v18 > 0 )
{
for ( l = 0; l != v18; ++l )
{
printw("=");
v30 = l;
print_end_delimiter(v30, v18);
}
}
v31 = -1;
if ( stdscr )
v31 = stdscr->_cury;
if ( wmove(stdscr, v31, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress E: %d %% [", (unsigned int)(int)v43);
if ( v19 > 0 )
{
for ( m = 0; m != v19; ++m )
{
printw("=");
v33 = m;
print_end_delimiter(v33, v19);
}
}
v34 = -1;
if ( stdscr )
v34 = stdscr->_cury;
if ( wmove(stdscr, v34, 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 v6; // er15
int v10; // er8
int v11; // er9
int v12; // er10
int v13; // ecx
float v14; // xmm3_4
int v15; // er15
int v16; // er14
int v17; // er13
int v18; // er12
int v19; // ebp
int i; // ebx
int v21; // edi
int v22; // esi
int j; // ebx
int v24; // edi
int v25; // esi
int k; // ebx
int v27; // edi
int v28; // esi
int l; // ebx
int v30; // edi
int v31; // esi
int m; // ebx
int v33; // edi
int v34; // esi
unsigned int v36; // [rsp+0h] [rbp-48h]
float v37; // [rsp+0h] [rbp-48h]
unsigned int v38; // [rsp+4h] [rbp-44h]
float v39; // [rsp+4h] [rbp-44h]
unsigned int v40; // [rsp+8h] [rbp-40h]
float v41; // [rsp+8h] [rbp-40h]
unsigned int v42; // [rsp+Ch] [rbp-3Ch]
float v43; // [rsp+Ch] [rbp-3Ch]

v6 = a6;
if ( a6 )
{
switch ( a6 )
{
case 1u:
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 0;
break;
case 2u:
v10 = 0;
v11 = 0;
v12 = 1;
v6 = 0;
v13 = 0;
break;
case 3u:
v10 = 0;
v11 = 1;
v12 = 0;
v6 = 0;
v13 = 0;
break;
case 4u:
v10 = 1;
v11 = 0;
v12 = 0;
v6 = 0;
v13 = 0;
break;
default:
v10 = 0;
v11 = 0;
v12 = 0;
v6 = 0;
v13 = 1;
break;
}
}
else
{
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 1;
}
v42 = v10;
v40 = v11;
v38 = v12;
v36 = v13;
wclear(stdscr);
printw(
"\rAthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a1 + 1),
*(unsigned int *)a1,
v36,
a1[1]);
printw(
"\rBthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a2 + 1),
*(unsigned int *)a2,
v6,
a2[1]);
printw(
"\rCthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a3 + 1),
*(unsigned int *)a3,
v38,
a3[1]);
printw(
"\rDthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a4 + 1),
*(unsigned int *)a4,
v40,
a4[1]);
printw(
"\rEthread: Pi Value: %f CurrentTerm: %d TotalTerms: %d Active: %d\n",
*((unsigned int *)a5 + 1),
*(unsigned int *)a5,
v42,
a5[1]);
v14 = (float)(100 * (*((_DWORD *)a1 + 1) / *(_DWORD *)a1));
v37 = (float)(100 * (*((_DWORD *)a2 + 1) / *(_DWORD *)a2));
v15 = (int)(float)((float)(v14 * 54.0) / 100.0);
v39 = (float)(100 * (*((_DWORD *)a3 + 1) / *(_DWORD *)a3));
v16 = (int)(float)((float)(v37 * 54.0) / 100.0);
v41 = (float)(100 * (*((_DWORD *)a4 + 1) / *(_DWORD *)a4));
v17 = (int)(float)((float)(v39 * 54.0) / 100.0);
v43 = (float)(100 * (*((_DWORD *)a5 + 1) / *(_DWORD *)a5));
v18 = (int)(float)((float)(v41 * 54.0) / 100.0);
v19 = (int)(float)((float)(54.0 * v43) / 100.0);
printw("\rProgress A: %d %% [", (unsigned int)(int)v14);
if ( v15 > 0 )
{
for ( i = 0; i != v15; ++i )
{
printw("=");
v21 = i;
func0(v21, v15);
}
}
v22 = -1;
if ( stdscr )
v22 = stdscr->_cury;
if ( wmove(stdscr, v22, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress B: %d %% [", (unsigned int)(int)v37);
if ( v16 > 0 )
{
for ( j = 0; j != v16; ++j )
{
printw("=");
v24 = j;
func0(v24, v16);
}
}
v25 = -1;
if ( stdscr )
v25 = stdscr->_cury;
if ( wmove(stdscr, v25, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress C: %d %% [", (unsigned int)(int)v39);
if ( v17 > 0 )
{
for ( k = 0; k != v17; ++k )
{
printw("=");
v27 = k;
func0(v27, v17);
}
}
v28 = -1;
if ( stdscr )
v28 = stdscr->_cury;
if ( wmove(stdscr, v28, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress D: %d %% [", (unsigned int)(int)v41);
if ( v18 > 0 )
{
for ( l = 0; l != v18; ++l )
{
printw("=");
v30 = l;
func0(v30, v18);
}
}
v31 = -1;
if ( stdscr )
v31 = stdscr->_cury;
if ( wmove(stdscr, v31, 74) != -1 )
waddnstr(stdscr, "]", -1);
printw("\n");
printw("\rProgress E: %d %% [", (unsigned int)(int)v43);
if ( v19 > 0 )
{
for ( m = 0; m != v19; ++m )
{
printw("=");
v33 = m;
func0(v33, v19);
}
}
v34 = -1;
if ( stdscr )
v34 = stdscr->_cury;
if ( wmove(stdscr, v34, 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 lcdVisualDisplayOn();
}

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

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

canonical_decompiled_code:
__int64 func18()
{
return func13();
}

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


lcdSetBrightness

decompiled_code:
__int64 lcdSetBrightness()
{
__int16 buf; // [rsp+Dh] [rbp-Bh] BYREF
char v2; // [rsp+Fh] [rbp-9h]

buf = -32644;
v2 = 0;
return uartTx(&buf, 2uLL);
}

canonical_decompiled_code:
__int64 func19()
{
__int16 buf; // [rsp+Dh] [rbp-Bh] BYREF
char v2; // [rsp+Fh] [rbp-9h]

buf = -32644;
v2 = 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


uartInit

decompiled_code:
__int64 __fastcall uartInit(_QWORD a1, const char *a2)
{
__int64 result; // rax
int v3; // eax
int v4; // ebp
struct termios v5; // [rsp+0h] [rbp-48h] BYREF

if ( uart0_filestream == -1 )
{
v3 = open("/dev/ttyAMA0", 2306);
uart0_filestream = v3;
v4 = v3;
if ( v3 == -1 )
{
fprintf(stderr, "uartInit: unable to open %s\n", "/dev/ttyAMA0");
result = 0LL;
}
else
{
tcgetattr(v3, &v5);
*(_QWORD *)&v5.c_iflag = 4LL;
*(_QWORD *)&v5.c_cflag = 2237LL;
tcflush(v4, 0);
tcsetattr(v4, 0, &v5);
result = 1LL;
}
}
else
{
fwrite("uartInit: uart already open\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(_QWORD a1, const char *a2)
{
__int64 result; // rax
int v3; // eax
int v4; // ebp
struct termios v5; // [rsp+0h] [rbp-48h] BYREF

if ( uart0_filestream == -1 )
{
v3 = open("/dev/ttyAMA0", 2306);
uart0_filestream = v3;
v4 = v3;
if ( v3 == -1 )
{
fprintf(stderr, "uartInit: unable to open %s\n", "/dev/ttyAMA0");
result = 0LL;
}
else
{
tcgetattr(v3, &v5);
*(_QWORD *)&v5.c_iflag = 4LL;
*(_QWORD *)&v5.c_cflag = 2237LL;
tcflush(v4, 0);
tcsetattr(v4, 0, &v5);
result = 1LL;
}
}
else
{
fwrite("uartInit: uart already open\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
char uartInit()
{
    if (uart0_filestream != -1)
    {
        fprintf(stderr, "uartInit: uart already open\n");
        return (1==2);
    }
    uart0_filestream = open("/dev/ttyAMA0", 02 | 0400 | 04000);
    if (uart0_filestream == -1)
    {
        fprintf(stderr, "uartInit: unable to open %s\n", "/dev/ttyAMA0");
        return (1==2);
    }
    struct termios options;
    tcgetattr(uart0_filestream, &options);
    options.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
    options.c_iflag = 0000004;
    options.c_oflag = 0;
    options.c_lflag = 0;
    tcflush(uart0_filestream, 0);
    tcsetattr(uart0_filestream, 0, &options);
    return (1==1);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: char


uartClose

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

if ( uart0_filestream != -1 )
result = close(uart0_filestream);
uart0_filestream = -1;
return result;
}

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

if ( uart0_filestream != -1 )
result = close(uart0_filestream);
uart0_filestream = -1;
return result;
}

original_code:
void uartClose()
{
    if (uart0_filestream != -1)
    {
        close(uart0_filestream);
    }
    uart0_filestream = -1;
    return;
}


uartTx

decompiled_code:
__int64 __fastcall uartTx(void *buf, size_t n)
{
__int64 result; // rax

if ( uart0_filestream == -1 )
{
fwrite("uartTx: uart not initialized (call uartInit first)\n", 1uLL, 0x33uLL, stderr);
result = 0LL;
}
else
{
if ( (int)write(uart0_filestream, buf, n) < 0 )
fwrite("uartTx: uart tx error\n", 1uLL, 0x16uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(void *buf, size_t n)
{
__int64 result; // rax

if ( uart0_filestream == -1 )
{
fwrite("uartTx: uart not initialized (call uartInit first)\n", 1uLL, 0x33uLL, stderr);
result = 0LL;
}
else
{
if ( (int)write(uart0_filestream, buf, n) < 0 )
fwrite("uartTx: uart tx error\n", 1uLL, 0x16uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
char uartTx(char *txbuf, size_t len)
{
    if (uart0_filestream == -1)
    {
        fprintf(stderr, "uartTx: uart not initialized (call uartInit first)\n");
        return (1==2);
    }
    int tx_len = write(uart0_filestream, txbuf, len);
    if (tx_len < 0)
    {
        fprintf(stderr, "uartTx: uart tx error\n");
    }
    return (1==1);
}

canonical_original_code:
char uartTx(char *txbuf, unsigned long len)
{
    if (uart0_filestream == -1)
    {
        fprintf(stderr, "uartTx: uart not initialized (call uartInit first)\n");
        return (1==2);
    }
    int tx_len = write(uart0_filestream, txbuf, len);
    if (tx_len < 0)
    {
        fprintf(stderr, "uartTx: uart tx error\n");
    }
    return (1==1);
}

variable_types:
len
unsigned long


uartRx

decompiled_code:
__int64 __fastcall uartRx(void *buf, size_t nbytes)
{
__int64 result; // rax

if ( uart0_filestream == -1 )
{
fwrite("uartRx: uart not initialized (call uartInit first)\n", 1uLL, 0x33uLL, stderr);
result = 0LL;
}
else
{
LODWORD(result) = read(uart0_filestream, buf, nbytes);
if ( (int)result < 0 )
{
fwrite("uartRx: uart rx error\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
else
{
result = (int)result;
*((_BYTE *)buf + (int)result) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(void *buf, size_t nbytes)
{
__int64 result; // rax

if ( uart0_filestream == -1 )
{
fwrite("uartRx: uart not initialized (call uartInit first)\n", 1uLL, 0x33uLL, stderr);
result = 0LL;
}
else
{
LODWORD(result) = read(uart0_filestream, buf, nbytes);
if ( (int)result < 0 )
{
fwrite("uartRx: uart rx error\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
else
{
result = (int)result;
*((_BYTE *)buf + (int)result) = 0;
}
}
return result;
}

original_code:
size_t uartRx(char *rxbuf, size_t maxlen)
{
    if (uart0_filestream == -1)
    {
        fprintf(stderr, "uartRx: uart not initialized (call uartInit first)\n");
        return 0;
    }
    int rx_len = read(uart0_filestream, rxbuf, maxlen);
    if (rx_len < 0)
    {
        fprintf(stderr, "uartRx: uart rx error\n");
        return 0;
    }
    else
    {
        rxbuf[rx_len] = '\0';
        return rx_len;
    }
}

canonical_original_code:
unsigned long uartRx(char *rxbuf, unsigned long maxlen)
{
    if (uart0_filestream == -1)
    {
        fprintf(stderr, "uartRx: uart not initialized (call uartInit first)\n");
        return 0;
    }
    int rx_len = read(uart0_filestream, rxbuf, maxlen);
    if (rx_len < 0)
    {
        fprintf(stderr, "uartRx: uart rx error\n");
        return 0;
    }
    else
    {
        rxbuf[rx_len] = '\0';
        return rx_len;
    }
}

variable_types:
rxbuf
char *

variable_types:
maxlen
unsigned long

return_type: unsigned long


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

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

original_code:
int float_cmp(void const *a, void const *b)
{
    int const *ia = (int const *)a;
    int const *ib = (int const *)b;
    return *ia - *ib;
}

canonical_original_code:
int float_cmp(void *a, void *b)
{
    int *ia = (int const *)a;
    int *ib = (int const *)b;
    return *ia - *ib;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
ia
int *

variable_types:
ib
int *


convertTemperature

decompiled_code:
float __fastcall convertTemperature(char a1, char a2)
{
int v2; // eax

v2 = a1 >> 31;
LOWORD(v2) = 0;
return (float)(a2 + v2 + (a1 << 8)) * 0.0625;
}

canonical_decompiled_code:
float __fastcall func1(char a1, char a2)
{
int v2; // eax

v2 = a1 >> 31;
LOWORD(v2) = 0;
return (float)(a2 + v2 + (a1 << 8)) * 0.0625;
}

original_code:
float convertTemperature(char msb, char lsb)
{
    signed int rawval = 0;
    if ((msb & (1 << 7)) > 0)
    {
        rawval -= 0x10000;
    }
    rawval += msb << 8;
    rawval += lsb;
    return (float)rawval * 0.0625;
}

canonical_original_code:
float convertTemperature(char msb, char lsb)
{
    int rawval = 0;
    if ((msb & (1 << 7)) > 0)
    {
        rawval -= 0x10000;
    }
    rawval += msb << 8;
    rawval += lsb;
    return (float)rawval * 0.0625;
}

variable_types: msb char

variable_types: lsb char

variable_types: rawval int

return_type: float


repo: rudymatela/evenmoreutils

decompiled_code:
__int64 __fastcall custom_callback(const char *a1)
{
printf("Custom callback with %s as parameter\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
printf("Custom callback with %s as parameter\n", a1);
return 0LL;
}

original_code:
int custom_callback(const char *arg, void *pvar)
{
 printf("Custom callback with %s as parameter\n", arg);
 return 0;
}

canonical_original_code:
int custom_callback(char *arg, void *pvar)
{
 printf("Custom callback with %s as parameter\n", arg);
 return 0;
}

variable_types:
arg
char *

variable_types:
pvar
void *


sgetoptnormal

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

for ( result = a1; *(_BYTE *)result || *(_QWORD *)(result + 8); result += 40LL )
;
return result;
}

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

for ( result = a1; *(_BYTE *)result || *(_QWORD *)(result + 8); result += 40LL )
;
return result;
}

original_code:
const static struct soption *sgetoptnormal(const struct soption optable[])
{
 while (optable->sname || optable->lname)
  optable++;
 return optable;
}

canonical_original_code:
static struct soption *sgetoptnormal(struct soption optable[])
{
 while (optable->sname || optable->lname)
  optable++;
 return optable;
}

variable_types:
optable
struct soption []

return_type: struct soption { char sname; char *lname; int has_arg; int (*func)(char *, void *); void *arg; } *


sgetoptfromc

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

for ( result = a2; *(_BYTE *)result || *(_QWORD *)(result + 8); result += 40LL )
{
if ( *(_BYTE *)result == a1 )
return result;
}
if ( a1 )
result = *(_QWORD *)(result + 8);
return result;
}

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

for ( result = a2; *(_BYTE *)result || *(_QWORD *)(result + 8); result += 40LL )
{
if ( *(_BYTE *)result == a1 )
return result;
}
if ( a1 )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
const static struct soption *sgetoptfromc(char c, const struct soption optable[])
{
 while (optable->sname || optable->lname) {
  if (optable->sname == c)
   return optable;
  optable++;
 }
 return c ? ((void *)0): optable;
}

canonical_original_code:
static struct soption *sgetoptfromc(char c, struct soption optable[])
{
 while (optable->sname || optable->lname) {
  if (optable->sname == c)
   return optable;
  optable++;
 }
 return c ? ((void *)0): optable;
}

variable_types: c char

user_defined_types: struct soption { char sname; char *lname; int has_arg; int (*func)(char *, void *); void *arg; }


sgetoptfroms

decompiled_code:
__int64 __fastcall sgetoptfroms(__int64 a1, __int64 a2)
{
__int64 v4; // rdi

while ( 1 )
{
v4 = *(_QWORD *)(a2 + 8);
if ( !*(_BYTE *)a2 )
break;
if ( v4 && !(unsigned int)strchrcmp_constprop_0(v4, a1) )
return a2;
LABEL_4:
a2 += 40LL;
}
if ( v4 )
{
if ( !(unsigned int)strchrcmp_constprop_0(v4, a1) )
return a2;
goto LABEL_4;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v4; // rdi

while ( 1 )
{
v4 = *(_QWORD *)(a2 + 8);
if ( !*(_BYTE *)a2 )
break;
if ( v4 && !(unsigned int)func10(v4, a1) )
return a2;
LABEL_4:
a2 += 40LL;
}
if ( v4 )
{
if ( !(unsigned int)func10(v4, a1) )
return a2;
goto LABEL_4;
}
return 0LL;
}

original_code:
const static struct soption *sgetoptfroms(const char *s, const struct soption optable[])
{
 while (optable->sname || optable->lname) {
  if (optable->lname && strchrcmp(optable->lname,s,'=') == 0)
   return optable;
  optable++;
 }
 return s ? ((void *)0): optable;
}

canonical_original_code:
static struct soption *sgetoptfroms(char *s, struct soption optable[])
{
 while (optable->sname || optable->lname) {
  if (optable->lname && strchrcmp(optable->lname,s,'=') == 0)
   return optable;
  optable++;
 }
 return s ? ((void *)0): optable;
}

variable_types:
s
char *


decompiled_code:
_BOOL8 __fastcall capture_int(const char *a1, _DWORD *a2)
{
char *endptr; // [rsp+8h] [rbp-20h] BYREF

*a2 = strtol(a1, &endptr, 10);
return endptr == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(const char *a1, _DWORD *a2)
{
char *endptr; // [rsp+8h] [rbp-20h] BYREF

*a2 = strtol(a1, &endptr, 10);
return endptr == a1;
}

original_code:
int capture_int(const char *carg, void *pvar)
{
 int *pi = pvar;
 char *end;
 *pi = strtol(carg, &end, 10);
 return end!=carg ? 0: 1;
}

canonical_original_code:
int capture_int(char *carg, void *pvar)
{
 int *pi = pvar;
 char *end;
 *pi = strtol(carg, &end, 10);
 return end!=carg ? 0: 1;
}

variable_types:
carg
char *

variable_types:
pi
int *

variable_types:
end
char *


decompiled_code:
_BOOL8 __fastcall capture_int_pedantic(const char *a1, _DWORD *a2)
{
int v2; // eax
char *v3; // rdx
_BOOL8 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = strtol(a1, &endptr, 10);
v3 = endptr;
*a2 = v2;
result = 1LL;
if ( v3 != a1 )
result = *v3 != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(const char *a1, _DWORD *a2)
{
int v2; // eax
char *v3; // rdx
_BOOL8 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v2 = strtol(a1, &endptr, 10);
v3 = endptr;
*a2 = v2;
result = 1LL;
if ( v3 != a1 )
result = *v3 != 0;
return result;
}

original_code:
int capture_int_pedantic(const char *carg, void *pvar)
{
 int *pi = pvar;
 char *end;
 *pi = strtol(carg, &end, 10);
 return end!=carg && !*end ? 0: 1;
}

canonical_original_code:
int capture_int_pedantic(char *carg, void *pvar)
{
 int *pi = pvar;
 char *end;
 *pi = strtol(carg, &end, 10);
 return end!=carg && !*end ? 0: 1;
}


decompiled_code:
_BOOL8 __fastcall capture_char(_BYTE *a1, _BYTE *a2)
{
bool v2; // zf

v2 = *a1 == 0;
*a2 = *a1;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(_BYTE *a1, _BYTE *a2)
{
bool v2; // zf

v2 = *a1 == 0;
*a2 = *a1;
return v2;
}

original_code:
int capture_char(const char *carg, void *pvar)
{
 char *pc = pvar;
 *pc = *carg;
 return *pc ? 0 : 1;
}

canonical_original_code:
int capture_char(char *carg, void *pvar)
{
 char *pc = pvar;
 *pc = *carg;
 return *pc ? 0 : 1;
}

variable_types:
pc
char *