decompiled_code:
void __noreturn log_fatal(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
output_log_msg("FATAL", stderr, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func1("FATAL", stderr, a1, va);
exit(1);
}

original_code:
void log_fatal(const char *format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    output_log_msg("FATAL", stderr, format, ap);
    __builtin_va_end(ap);
    exit(1);
}

canonical_original_code:
void log_fatal(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    output_log_msg("FATAL", stderr, format, ap);
    __builtin_va_end(ap);
    exit(1);
}


ustime

repo: Jahaja/cityslicker

decompiled_code:
__suseconds_t ustime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func5()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
long long ustime(void) {
    struct timeval tv;
    long long ust;
    gettimeofday(&tv, ((void *)0));
    ust = ((long long) tv.tv_sec) * 1000000;
    ust += tv.tv_usec;
    return ust;
}

canonical_original_code:
long long ustime() {
    struct timeval tv;
    long long ust;
    gettimeofday(&tv, ((void *)0));
    ust = ((long long) tv.tv_sec) * 1000000;
    ust += tv.tv_usec;
    return ust;
}

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

variable_types:
ust
long long

return_type: long long


mstime

decompiled_code:
__suseconds_t mstime()
{
return ustime() / 1000;
}

canonical_decompiled_code:
__suseconds_t func6()
{
return func5() / 1000;
}

original_code:
long long mstime(void) {
    return ustime() / 1000;
}

canonical_original_code:
long long mstime() {
    return ustime() / 1000;
}


decompiled_code:
__int64 __fastcall compare_cities(const void *a1, const void *a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
__int64 result; // rax

v2 = *(double *)(*(_QWORD *)a1 + 16LL);
v3 = *(double *)(*(_QWORD *)a2 + 16LL);
result = 1LL;
if ( v2 <= v3 )
result = (unsigned int)-(v3 > v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
__int64 result; // rax

v2 = *(double *)(*(_QWORD *)a1 + 16LL);
v3 = *(double *)(*(_QWORD *)a2 + 16LL);
result = 1LL;
if ( v2 <= v3 )
result = (unsigned int)-(v3 > v2);
return result;
}

original_code:
static int compare_cities(const void *p1, const void *p2) {
    const city *c1 = *(city * const *) p1;
    const city *c2 = *(city * const *) p2;
    if(c1->latitude > c2->latitude) {
        return 1;
    } else if (c1->latitude < c2->latitude) {
        return -1;
    } else {
        return 0;
    }
}

canonical_original_code:
static int compare_cities(void *p1, void *p2) {
    struct city *c1 = *(city * const *) p1;
    struct city *c2 = *(city * const *) p2;
    if(c1->latitude > c2->latitude) {
        return 1;
    } else if (c1->latitude < c2->latitude) {
        return -1;
    } else {
        return 0;
    }
}

variable_types: struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } *

return_type: int


decompiled_code:
__int64 __fastcall geonames_is_valid_feature_code(char *s1)
{
const char *v1; // rsi
char *v2; // rbx
__int64 v4[6]; // [rsp+8h] [rbp-50h] BYREF
char v5; // [rsp+38h] [rbp-20h] BYREF

v1 = (const char *)&unk_33C;
v4[0] = (__int64)"PCLI";
v2 = (char *)v4;
v4[1] = (__int64)"PPLA";
v4[2] = (__int64)"ADM1";
v4[3] = (__int64)"PPLL";
v4[4] = (__int64)"PPLC";
v4[5] = (__int64)"PPLF";
while ( strcmp(s1, v1) )
{
if ( v2 == &v5 )
return 0LL;
v1 = *(const char **)v2;
v2 += 8;
}
return 1LL;
}

original_code:
static int geonames_is_valid_feature_code(const char *feature_code) {
    const char *tbl[] = {
        "PPL",
        "PCLI",
        "PPLA",
        "ADM1",
        "PPLL",
        "PPLC",
        "PPLF"
    };
    unsigned int i, tlen;
    tlen = sizeof(tbl) / sizeof(tbl[0]);
    for(i = 0; i < tlen; i++) {
        if(!strcmp(feature_code, tbl[i]))
            return 1;
    }
    return 0;
}

canonical_original_code:
static int geonames_is_valid_feature_code(char *feature_code) {
    char *tbl[] = {
        "PPL",
        "PCLI",
        "PPLA",
        "ADM1",
        "PPLL",
        "PPLC",
        "PPLF"
    };
    unsigned int i; unsigned int tlen;
    tlen = sizeof(tbl) / sizeof(tbl[0]);
    for(i = 0; i < tlen; i++) {
        if(!strcmp(feature_code, tbl[i]))
            return 1;
    }
    return 0;
}

variable_types:
tbl
char *[]

variable_types:
i
unsigned int

variable_types:
tlen
unsigned int


decompiled_code:
__int64 __fastcall geonames_read_line(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r13
size_t v3; // rcx
int v4; // er14
unsigned int v5; // ebx
__int64 v6; // rax
__int64 v7; // rdx
char v8; // al
char v10[20520]; // [rsp+0h] [rbp-5028h] BYREF

v2 = city_create();
if ( !v2 )
log_fatal("Failed to create city object while loading genonames file. Out of memory?");
if ( a2 )
{
v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0LL;
do
{
while ( 1 )
{
v8 = *(_BYTE *)(a1 + v6);
if ( v8 == 9 )
break;
v7 = (unsigned int)v3;
v3 = (unsigned int)(v3 + 1);
v10[v7] = v8;
v6 = ++v5;
if ( v5 >= a2 )
return v2;
}
v10[v3] = 0;
geonames_load_column_isra_0(v2, v4++, v10, v3);
v3 = 0LL;
v6 = ++v5;
}
while ( v5 < a2 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r13
size_t v3; // rcx
int v4; // er14
unsigned int v5; // ebx
__int64 v6; // rax
__int64 v7; // rdx
char v8; // al
char v10[20520]; // [rsp+0h] [rbp-5028h] BYREF

v2 = city_create();
if ( !v2 )
log_fatal("Failed to create city object while loading genonames file. Out of memory?");
if ( a2 )
{
v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0LL;
do
{
while ( 1 )
{
v8 = *(_BYTE *)(a1 + v6);
if ( v8 == 9 )
break;
v7 = (unsigned int)v3;
v3 = (unsigned int)(v3 + 1);
v10[v7] = v8;
v6 = ++v5;
if ( v5 >= a2 )
return v2;
}
v10[v3] = 0;
func2(v2, v4++, v10, v3);
v3 = 0LL;
v6 = ++v5;
}
while ( v5 < a2 );
}
return v2;
}

original_code:
static city *geonames_read_line(const char *buffer, size_t len) {
    city *c = city_create();
    if(!c) {
        log_fatal("Failed to create city object while loading genonames file. Out of memory?");
    }
    char valbuf[1024*20];
    unsigned int i, j = 0, vlen = 0;
    for(i = 0; i < len; i++) {
        if(buffer[i] != '\t') {
            valbuf[vlen] = buffer[i];
            vlen++;
        } else {
            valbuf[vlen] = '\0';
            geonames_load_column(c, j, valbuf, vlen);
            j++;
            vlen = 0;
        }
    }
    return c;
}

canonical_original_code:
static struct city *geonames_read_line(char *buffer, unsigned long len) {
    struct city *c = city_create();
    if(!c) {
        log_fatal("Failed to create city object while loading genonames file. Out of memory?");
    }
    char valbuf[-1];
    unsigned int i; unsigned int j = 0; unsigned int vlen = 0;
    for(i = 0; i < len; i++) {
        if(buffer[i] != '\t') {
            valbuf[vlen] = buffer[i];
            vlen++;
        } else {
            valbuf[vlen] = '\0';
            geonames_load_column(c, j, valbuf, vlen);
            j++;
            vlen = 0;
        }
    }
    return c;
}

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types:
valbuf
char [-1]

variable_types:
j
unsigned int

variable_types:
vlen
unsigned int

return_type: struct city { int id; char *name; double latitude; double longitude; long long population; char feature_code[-1]; } *


decompiled_code:
__int64 __fastcall getopandminus2(_BYTE *a1)
{
__int64 v2; // r12
const unsigned __int16 **v3; // rax
const unsigned __int16 *v4; // rcx
const unsigned __int16 **v5; // rsi
int v6; // er9
__int64 result; // rax
_BYTE *v8; // rax
int v9; // er10
__int64 v10; // rdx
_BYTE *v11; // r8
__int64 v12; // rdi
__int64 v13; // rdx
__int64 v14; // rax

do
{
do
{
v2 = *((char *)&lines + linesCounter);
++linesCounter;
*a1 = v2;
}
while ( (_BYTE)v2 == 9 );
}
while ( (_BYTE)v2 == 32 );
a1[1] = 0;
v3 = _ctype_b_loc();
v4 = *v3;
v5 = v3;
if ( ((*v3)[v2] & 0x800) != 0 )
{
v8 = a1 + 1;
v9 = -(int)a1;
while ( 1 )
{
v10 = linesCounter;
v6 = v9 + (_DWORD)v8;
v11 = v8++;
++linesCounter;
v12 = *((char *)&lines + v10);
*(v8 - 1) = v12;
if ( (v4[v12] & 0x800) == 0 )
break;
v4 = *v5;
}
if ( (_BYTE)v12 != 46 )
goto LABEL_10;
v4 = *v5;
}
else
{
v6 = 0;
if ( (_DWORD)v2 != 46 )
return (unsigned int)v2;
}
v13 = (__int64)&a1[v6 + 1];
while ( 1 )
{
v11 = (_BYTE *)v13++;
v14 = *((char *)&lines + linesCounter);
++linesCounter;
*(_BYTE *)(v13 - 1) = v14;
if ( (v4[v14] & 0x800) == 0 )
break;
v4 = *v5;
}
LABEL_10:
*v11 = 0;
result = 48LL;
--linesCounter;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v2; // r12
const unsigned __int16 **v3; // rax
const unsigned __int16 *v4; // rcx
const unsigned __int16 **v5; // rsi
int v6; // er9
__int64 result; // rax
_BYTE *v8; // rax
int v9; // er10
__int64 v10; // rdx
_BYTE *v11; // r8
__int64 v12; // rdi
__int64 v13; // rdx
__int64 v14; // rax

do
{
do
{
v2 = *((char *)&lines + linesCounter);
++linesCounter;
*a1 = v2;
}
while ( (_BYTE)v2 == 9 );
}
while ( (_BYTE)v2 == 32 );
a1[1] = 0;
v3 = _ctype_b_loc();
v4 = *v3;
v5 = v3;
if ( ((*v3)[v2] & 0x800) != 0 )
{
v8 = a1 + 1;
v9 = -(int)a1;
while ( 1 )
{
v10 = linesCounter;
v6 = v9 + (_DWORD)v8;
v11 = v8++;
++linesCounter;
v12 = *((char *)&lines + v10);
*(v8 - 1) = v12;
if ( (v4[v12] & 0x800) == 0 )
break;
v4 = *v5;
}
if ( (_BYTE)v12 != 46 )
goto LABEL_10;
v4 = *v5;
}
else
{
v6 = 0;
if ( (_DWORD)v2 != 46 )
return (unsigned int)v2;
}
v13 = (__int64)&a1[v6 + 1];
while ( 1 )
{
v11 = (_BYTE *)v13++;
v14 = *((char *)&lines + linesCounter);
++linesCounter;
*(_BYTE *)(v13 - 1) = v14;
if ( (v4[v14] & 0x800) == 0 )
break;
v4 = *v5;
}
LABEL_10:
*v11 = 0;
result = 48LL;
--linesCounter;
return result;
}

original_code:
int getopandminus2(char s[]){
    int i, c;
    while ((s[0] = c = lines[linesCounter++]) == ' ' || c == '\t')
        ;
    s[1] = '\0';
    if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) && c != '.')
        return c;
    i = 0;
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
        while (((*__ctype_b_loc ())[(int) ((s[++i] = c = lines[linesCounter++]))] & (unsigned short int) _ISdigit))
            ;
    if (c == '.')
        while (((*__ctype_b_loc ())[(int) ((s[++i] = c = lines[linesCounter++]))] & (unsigned short int) _ISdigit))
              ;
    s[i] = '\0';
    linesCounter--;
    return '0';
}

canonical_original_code:
int getopandminus2(char s[]){
    int i; int c;
    while ((s[0] = c = lines[linesCounter++]) == ' ' || c == '\t')
        ;
    s[1] = '\0';
    if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) && c != '.')
        return c;
    i = 0;
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
        while (((*__ctype_b_loc ())[(int) ((s[++i] = c = lines[linesCounter++]))] & (unsigned short) _ISdigit))
            ;
    if (c == '.')
        while (((*__ctype_b_loc ())[(int) ((s[++i] = c = lines[linesCounter++]))] & (unsigned short) _ISdigit))
              ;
    s[i] = '\0';
    linesCounter--;
    return '0';
}

variable_types:
s
char []

variable_types: i int

variable_types: c int


clearVariables

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

result = 0LL;
memset(&variables, 0, 0xD0uLL);
return result;
}

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

result = 0LL;
memset(&variables, 0, 0xD0uLL);
return result;
}

original_code:
void clearVariables(char s[]){
  int i;
  for(i = 0; i < 26; i++)
    variables[i] = 0.0f;
}

return_type: void


printAllVariables

decompiled_code:
int printAllVariables()
{
__int64 i; // rbx
__int64 v1; // rsi
double v2; // xmm0_8

for ( i = 0LL; i != 26; ++i )
{
v1 = (unsigned int)(i + 65);
v2 = variables[i];
printf("\nVariable [%c]: %f", v1, v2);
}
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
__int64 i; // rbx
__int64 v1; // rsi
double v2; // xmm0_8

for ( i = 0LL; i != 26; ++i )
{
v1 = (unsigned int)(i + 65);
v2 = variables[i];
printf("\nVariable [%c]: %f", v1, v2);
}
return putchar(10);
}

original_code:
void printAllVariables(){
  int i;
  for(i = 0; i < 26; i++)
    printf("\nVariable [%c]: %f", i+'A', variables[i]);
  printf("\n");
}


initVariables

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

result = 0LL;
memset(variables, 0, sizeof(variables));
return result;
}

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

result = 0LL;
memset(variables, 0, sizeof(variables));
return result;
}

original_code:
void initVariables(){
  int i;
  for(i = 0; i < 26; i++){
    variables[i] = 0.0f;
  }
}


printstack

decompiled_code:
int printstack()
{
__int64 v0; // rbx
double v1; // xmm0_8
__int64 v2; // rsi
int result; // eax

if ( stackPointer <= 0 )
{
printf("\nerror: stack empty");
result = putchar(10);
}
else
{
v0 = stackPointer - 1;
do
{
v1 = value[v0];
v2 = (unsigned int)v0--;
printf("\nStack position [%3d] : %f", v2, v1);
}
while ( (_DWORD)v0 != -1 );
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
double v1; // xmm0_8
__int64 v2; // rsi
int result; // eax

if ( stackPointer <= 0 )
{
printf("\nerror: stack empty");
result = putchar(10);
}
else
{
v0 = stackPointer - 1;
do
{
v1 = value[v0];
v2 = (unsigned int)v0--;
printf("\nStack position [%3d] : %f", v2, v1);
}
while ( (_DWORD)v0 != -1 );
result = putchar(10);
}
return result;
}

original_code:
void printstack(){
  if(stackPointer > 0){
    int count = stackPointer;
    while(--count >= 0)
      printf("\nStack position [%3d] : %f", count, value[count]);
  }
  else
    printf("\nerror: stack empty");
  printf("\n");
}

variable_types: count int


printTop

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

if ( stackPointer <= 0 )
result = printf("\nerror: nothing in stack");
else
result = printf("\nTop of stack: %f", value[stackPointer - 1]);
return result;
}

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

if ( stackPointer <= 0 )
result = printf("\nerror: nothing in stack");
else
result = printf("\nTop of stack: %f", value[stackPointer - 1]);
return result;
}

original_code:
void printTop(){
  if(stackPointer > 0)
    printf("\nTop of stack: %f", value[stackPointer-1]);
  else
    printf("\nerror: nothing in stack");
}


clear

decompiled_code:
int clear()
{
if ( stackPointer <= 0 )
return printf("\nerror: stack already empty");
stackPointer = 0;
return printf("\nstack cleared");
}

canonical_decompiled_code:
int func6()
{
if ( stackPointer <= 0 )
return printf("\nerror: stack already empty");
stackPointer = 0;
return printf("\nstack cleared");
}

original_code:
void clear(){
  if(stackPointer > 0){
    stackPointer = 0;
    printf("\nstack cleared");
  }
  else
    printf("\nerror: stack already empty");
}


push

decompiled_code:
int __fastcall push(double a1)
{
int result; // eax

result = stackPointer;
if ( stackPointer > 99 )
return printf("\nerror: stack full, can't push %g\n", a1);
value[stackPointer] = a1;
stackPointer = result + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func7(double a1)
{
int result; // eax

result = stackPointer;
if ( stackPointer > 99 )
return printf("\nerror: stack full, can't push %g\n", a1);
value[stackPointer] = a1;
stackPointer = result + 1;
return result;
}

original_code:
void push(double f){
  if(stackPointer < 100)
    value[stackPointer++] = f;
  else
    printf("\nerror: stack full, can't push %g\n", f);
}

variable_types: f double


pop

decompiled_code:
double pop()
{
int v0; // eax
double result; // xmm0_8

v0 = stackPointer;
if ( stackPointer <= 0 )
{
puts("\nerror: stack empty");
result = 0.0;
}
else
{
--stackPointer;
result = value[v0 - 1];
}
return result;
}

canonical_decompiled_code:
double func8()
{
int v0; // eax
double result; // xmm0_8

v0 = stackPointer;
if ( stackPointer <= 0 )
{
puts("\nerror: stack empty");
result = 0.0;
}
else
{
--stackPointer;
result = value[v0 - 1];
}
return result;
}

original_code:
double pop(void){
  if(stackPointer > 0)
    return value[--stackPointer];
  else{
    printf("\nerror: stack empty\n");
    return 0.0f;
  }
}

canonical_original_code:
double pop(){
  if(stackPointer > 0)
    return value[--stackPointer];
  else{
    printf("\nerror: stack empty\n");
    return 0.0f;
  }
}

return_type: double


storeVariable

decompiled_code:
int __fastcall storeVariable(char *a1)
{
__int64 v1; // rbx
float v2; // xmm0_4
int result; // eax

v1 = *a1 - 65;
if ( variables[v1] == 0.0 )
{
v2 = pop();
result = printf("\nPopping stack & setting %c, with %f\n", (unsigned int)*a1, v2);
variables[v1] = v2;
}
else
{
puts("\nPushing variable onto stack");
result = push(variables[v1]);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *a1)
{
__int64 v1; // rbx
float v2; // xmm0_4
int result; // eax

v1 = *a1 - 65;
if ( variables[v1] == 0.0 )
{
v2 = func8();
result = printf("\nPopping stack & setting %c, with %f\n", (unsigned int)*a1, v2);
variables[v1] = v2;
}
else
{
puts("\nPushing variable onto stack");
result = func7(variables[v1]);
}
return result;
}

original_code:
void storeVariable(char s[]){
  int value = s[0] - 'A';
  if(variables[value] == 0.0f){
    float temp = pop();
    printf("\nPopping stack & setting %c, with %f\n", s[0], temp);
    variables[value] = temp;
  }
  else{
    printf("\nPushing variable onto stack\n");
    push(variables[value]);
  }
}

variable_types: value int

variable_types: temp float


functionUsed

decompiled_code:
int __fastcall functionUsed(const char *a1)
{
double v1; // xmm0_8
float v2; // xmm1_4
double v3; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // [rsp+8h] [rbp-10h]

if ( !strcmp(a1, "exp") )
{
v6 = pop();
v3 = exp(v6);
return push(v3);
}
if ( strcmp(a1, "pow") )
{
if ( !strcmp(a1, "sin") )
{
if ( stackPointer > 0 )
{
v7 = pop();
v3 = sin(v7);
return push(v3);
}
}
else
{
if ( strcmp(a1, "cos") )
return printf("\nerror: function unknown");
if ( stackPointer > 0 )
{
v5 = pop();
v3 = cos(v5);
return push(v3);
}
}
return printf("\nerror: no values on stack");
}
if ( stackPointer > 1 )
{
v8 = pop();
v1 = pop();
v2 = v8;
v3 = pow(v1, v2);
return push(v3);
}
return puts("\nerror: not enough values in stack");
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
double v1; // xmm0_8
float v2; // xmm1_4
double v3; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // [rsp+8h] [rbp-10h]

if ( !strcmp(a1, "exp") )
{
v6 = func8();
v3 = exp(v6);
return func7(v3);
}
if ( strcmp(a1, "pow") )
{
if ( !strcmp(a1, "sin") )
{
if ( stackPointer > 0 )
{
v7 = func8();
v3 = sin(v7);
return func7(v3);
}
}
else
{
if ( strcmp(a1, "cos") )
return printf("\nerror: function unknown");
if ( stackPointer > 0 )
{
v5 = func8();
v3 = cos(v5);
return func7(v3);
}
}
return printf("\nerror: no values on stack");
}
if ( stackPointer > 1 )
{
v8 = func8();
v1 = func8();
v2 = v8;
v3 = pow(v1, v2);
return func7(v3);
}
return puts("\nerror: not enough values in stack");
}

original_code:
void functionUsed(char s[]){
  if(0 == strcmp(s, "exp"))
    push(exp(pop()));
  else if(0 == strcmp(s, "pow")){
    if(stackPointer > 1){
      float op2 = pop();
      push(pow(pop(), op2));
    }
    else{
      printf("\nerror: not enough values in stack\n");
    }
  }
  else if(0 == strcmp(s, "sin")){
    if(stackPointer > 0)
      push(sin(pop()));
    else
      printf("\nerror: no values on stack");
  }
  else if(0 == strcmp(s, "cos")){
    if(stackPointer > 0)
      push(cos(pop()));
    else
      printf("\nerror: no values on stack");
  }
  else
    printf("\nerror: function unknown");
}


duplicate

decompiled_code:
int duplicate()
{
double v1; // [rsp+0h] [rbp-10h]

if ( stackPointer <= 0 )
return printf("\nerror: cannot duplicate as stack empty");
v1 = pop();
push(v1);
return push(v1);
}

canonical_decompiled_code:
int func11()
{
double v1; // [rsp+0h] [rbp-10h]

if ( stackPointer <= 0 )
return printf("\nerror: cannot duplicate as stack empty");
v1 = func8();
func7(v1);
return func7(v1);
}

original_code:
void duplicate(){
  if(stackPointer > 0){
    double f = pop();
    push(f);
    push(f);
  }
  else
    printf("\nerror: cannot duplicate as stack empty");
}


swap

decompiled_code:
int swap()
{
float v0; // xmm0_4
float v1; // xmm0_4
double v3; // [rsp+0h] [rbp-18h]
double v4; // [rsp+8h] [rbp-10h]

if ( stackPointer <= 1 )
return printf("\nerror: stack doesn't hold 2 values to swap");
v4 = pop();
v3 = pop();
v0 = v4;
push(v0);
v1 = v3;
return push(v1);
}

canonical_decompiled_code:
int func12()
{
float v0; // xmm0_4
float v1; // xmm0_4
double v3; // [rsp+0h] [rbp-18h]
double v4; // [rsp+8h] [rbp-10h]

if ( stackPointer <= 1 )
return printf("\nerror: stack doesn't hold 2 values to swap");
v4 = func8();
v3 = func8();
v0 = v4;
func7(v0);
v1 = v3;
return func7(v1);
}

original_code:
void swap(){
  if(stackPointer > 1){
    float f = pop();
    float g = pop();
    push(f);
    push(g);
  }
  else
    printf("\nerror: stack doesn't hold 2 values to swap");
}

variable_types: f float

variable_types: g float


getch

decompiled_code:
int getch()
{
int v0; // eax

v0 = bufferfreeposition;
if ( bufferfreeposition <= 0 )
return getchar();
--bufferfreeposition;
return buffer[v0 - 1];
}

canonical_decompiled_code:
int func13()
{
int v0; // eax

v0 = bufferfreeposition;
if ( bufferfreeposition <= 0 )
return getchar();
--bufferfreeposition;
return buffer[v0 - 1];
}

original_code:
int getch(void){
  return (bufferfreeposition > 0) ? buffer[--bufferfreeposition] : getchar();
}

canonical_original_code:
int getch(){
  return (bufferfreeposition > 0) ? buffer[--bufferfreeposition] : getchar();
}


original_code:
int getop2(char s[]){
  static int pushback = (-1);
  int c, i;
  i = 0;
  if(pushback != (-1) && pushback != ' ' && pushback != '\t'){
    c = pushback;
    pushback = (-1);
    return c;
  }
  if(pushback == (-1) || pushback == ' ' || pushback == '\t'){
    while((s[0] = c = getch()) == ' ' || c == '\t');
  }
  else{
    s[0] = c = pushback;
  }
  pushback = (-1);
  s[1] = '\0';
  if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
    return c;
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISdigit));
  if(c == '.')
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISdigit));
  s[++i] = '\0';
  pushback = c;
  return '0';
}

canonical_original_code:
int getop2(char s[]){
  static int pushback = (-1);
  int c; int i;
  i = 0;
  if(pushback != (-1) && pushback != ' ' && pushback != '\t'){
    c = pushback;
    pushback = (-1);
    return c;
  }
  if(pushback == (-1) || pushback == ' ' || pushback == '\t'){
    while((s[0] = c = getch()) == ' ' || c == '\t');
  }
  else{
    s[0] = c = pushback;
  }
  pushback = (-1);
  s[1] = '\0';
  if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
    return c;
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISdigit));
  if(c == '.')
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISdigit));
  s[++i] = '\0';
  pushback = c;
  return '0';
}

variable_types: pushback int


ungetch

decompiled_code:
int __fastcall ungetch(int a1)
{
int result; // eax

result = bufferfreeposition;
if ( bufferfreeposition > 99 )
return puts("\nungetch: too many characters");
if ( a1 != -1 )
{
buffer[bufferfreeposition] = a1;
bufferfreeposition = result + 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(int a1)
{
int result; // eax

result = bufferfreeposition;
if ( bufferfreeposition > 99 )
return puts("\nungetch: too many characters");
if ( a1 != -1 )
{
buffer[bufferfreeposition] = a1;
bufferfreeposition = result + 1;
}
return result;
}

original_code:
void ungetch(int c){
  if(bufferfreeposition >= 100)
    printf("\nungetch: too many characters\n");
  else{
    if(c != (-1))
      buffer[bufferfreeposition++] = c;
  }
}


ungets

decompiled_code:
int __fastcall ungets(const char *a1)
{
int result; // eax
char *v2; // rbx
__int64 v3; // rbp
int v4; // edi

result = strlen(a1);
if ( result > 0 )
{
v2 = (char *)&a1[result - 1];
v3 = (__int64)&a1[result - 2 - (result - 1)];
do
{
v4 = *v2--;
result = ungetch(v4);
}
while ( v2 != (char *)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(const char *a1)
{
int result; // eax
char *v2; // rbx
__int64 v3; // rbp
int v4; // edi

result = strlen(a1);
if ( result > 0 )
{
v2 = (char *)&a1[result - 1];
v3 = (__int64)&a1[result - 2 - (result - 1)];
do
{
v4 = *v2--;
result = func15(v4);
}
while ( v2 != (char *)v3 );
}
return result;
}

original_code:
void ungets(char s[]){
  int len = strlen(s);
  while(len > 0){
    ungetch(s[--len]);
  }
}

variable_types: len int


getopandminus

original_code:
int getopandminus(char s[]){
  int i, c, nextValue;
  i = 0;
  while((s[0] = c = getch()) == ' ' || c == '\t');
  s[1] = '\0';
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISupper)){
    return '2';
  }
  if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) && c != '.' && c != '-'){
    if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)){
      int nextValue = getch();
      if(((*__ctype_b_loc ())[(int) ((nextValue))] & (unsigned short int) _ISalpha)){
        s[0] = c;
        s[1] = nextValue;
        i = 1;
        while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISalpha));
        s[i] = '\0';
        if(c != (-1))
          ungetch(c);
        return '1';
      }
    }
    return c;
  }
  if(c == '-'){
    nextValue = getch();
    if(!((*__ctype_b_loc ())[(int) ((nextValue))] & (unsigned short int) _ISdigit) && nextValue != '.'){
      return c;
    }
    c = nextValue;
    i++;
    s[i] = c;
  }
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)){
      while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISdigit)){
        ;
      }
  }
  if(c == '.'){
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISdigit)){
      ;
    }
  }
  s[i] = '\0';
  if(c != (-1))
    ungetch(c);
  return '0';
}

canonical_original_code:
int getopandminus(char s[]){
  int i; int c; int nextValue;
  i = 0;
  while((s[0] = c = getch()) == ' ' || c == '\t');
  s[1] = '\0';
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISupper)){
    return '2';
  }
  if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) && c != '.' && c != '-'){
    if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)){
      int nextValue = getch();
      if(((*__ctype_b_loc ())[(int) ((nextValue))] & (unsigned short) _ISalpha)){
        s[0] = c;
        s[1] = nextValue;
        i = 1;
        while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISalpha));
        s[i] = '\0';
        if(c != (-1))
          ungetch(c);
        return '1';
      }
    }
    return c;
  }
  if(c == '-'){
    nextValue = getch();
    if(!((*__ctype_b_loc ())[(int) ((nextValue))] & (unsigned short) _ISdigit) && nextValue != '.'){
      return c;
    }
    c = nextValue;
    i++;
    s[i] = c;
  }
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)){
      while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISdigit)){
        ;
      }
  }
  if(c == '.'){
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISdigit)){
      ;
    }
  }
  s[i] = '\0';
  if(c != (-1))
    ungetch(c);
  return '0';
}

variable_types: nextValue int


getop

original_code:
int getop(char s[]){
  int i, c;
  while((s[0] = c = getch()) == ' ' || c == '\t');
  s[1] = '\0';
  if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit) && c != '.')
    return c;
  i = 0;
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISdigit));
  if(c == '.')
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short int) _ISdigit));
  s[i] = '\0';
  if(c != (-1))
    ungetch(c);
  return '0';
}

canonical_original_code:
int getop(char s[]){
  int i; int c;
  while((s[0] = c = getch()) == ' ' || c == '\t');
  s[1] = '\0';
  if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit) && c != '.')
    return c;
  i = 0;
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISdigit));
  if(c == '.')
    while(((*__ctype_b_loc ())[(int) ((s[++i] = c = getch()))] & (unsigned short) _ISdigit));
  s[i] = '\0';
  if(c != (-1))
    ungetch(c);
  return '0';
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp

while ( 1 )
{
v3 = getcharch8(*(_QWORD *)&argc, argv, envp);
if ( !v3 || v3 == (*_ctype_tolower_loc())[113] )
break;
*(_QWORD *)&argc = v3;
putchar(v3);
}
return 0;
}

original_code:
int main(int argc, char *argv[]){
  int c;
  while((c = getcharch8()) && (c != tolower('q'))){
    printf("%c", c);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


lowerString

decompiled_code:
__int64 __fastcall lowerString(unsigned __int8 *a1)
{
__int64 result; // rax

while ( 1 )
{
result = *a1;
if ( !(_BYTE)result )
break;
if ( (unsigned __int8)(result - 65) < 0x1Au )
LOBYTE(result) = result + 32;
*a1++ = result;
}
return result;
}

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

while ( 1 )
{
result = *a1;
if ( !(_BYTE)result )
break;
if ( (unsigned __int8)(result - 65) < 0x1Au )
LOBYTE(result) = result + 32;
*a1++ = result;
}
return result;
}

original_code:
void lowerString(char word[]){
 int i = 0;
 while(word[i] != '\0'){
  word[i] = (word[i] >= 'A' && word[i] <= 'Z') ? word[i] + 'a'-'A' : word[i];
  i++;
 }
}

variable_types:
word
char []


original_code:
void ex2_10(){
 char word[] = "JAMES IN UPPERCASE\n";
 printf("%s", word);
 lowerString(word);
 printf("%s", word);
}


bitCountOriginal

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

for ( result = 0LL; a1; a1 >>= 1 )
result = (unsigned int)result - (((a1 & 1) == 0) - 1);
return result;
}

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

for ( result = 0LL; a1; a1 >>= 1 )
result = (unsigned int)result - (((a1 & 1) == 0) - 1);
return result;
}

original_code:
int bitCountOriginal(unsigned x){
 int b;
 for(b = 0; x != 0; x >>= 1)
  if(x & 01)
   b++;
 return b;
}

canonical_original_code:
int bitCountOriginal(unsigned int x){
 int b;
 for(b = 0; x != 0; x >>= 1)
  if(x & 01)
   b++;
 return b;
}

variable_types:
x
unsigned int

variable_types: b int


decompiled_code:
int ex2_9()
{
unsigned int v0; // eax

v0 = bitCountOriginal(0xFFFFFFFu);
return printf("First value %d, Second value %d\n", v0, v0);
}

canonical_decompiled_code:
int func3()
{
unsigned int v0; // eax

v0 = func2(0xFFFFFFFu);
return printf("First value %d, Second value %d\n", v0, v0);
}

original_code:
void ex2_9(){
 unsigned int first = bitCountOriginal(0xFFFFFFF);
 unsigned int second = bitCountOriginal(0xFFFFFFF);
 printf("First value %d, Second value %d\n", first, second);
}

variable_types:
first
unsigned int

variable_types:
second
unsigned int


bitCountNew

decompiled_code:
__int64 __fastcall bitCountNew(int a1)
{
unsigned int i; // er8

for ( i = 0; a1; a1 &= a1 - 1 )
++i;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int i; // er8

for ( i = 0; a1; a1 &= a1 - 1 )
++i;
return i;
}

original_code:
int bitCountNew(unsigned x){
 int b;
 for(b = 0; x != 0; x &= (x-1))
  b++;
 return b;
}

canonical_original_code:
int bitCountNew(unsigned int x){
 int b;
 for(b = 0; x != 0; x &= (x-1))
  b++;
 return b;
}


rightRotate

decompiled_code:
__int64 __fastcall rightRotate(unsigned int a1, char a2)
{
return a1 >> a2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
return a1 >> a2;
}

original_code:
unsigned int rightRotate(unsigned int x, int number){
 return x >> number;
}

variable_types: number int

return_type: unsigned int


invertBits

original_code:
unsigned int invertBits(unsigned int x, int position, int number){
 unsigned int xValue = x;
 x = x & (~0 << position);
 x = x | ~(~0 << (position - number));
 xValue = (~xValue & ~(~0 << number));
 xValue = xValue << (position - number);
 return x | xValue;
}

variable_types: position int

variable_types:
xValue
unsigned int


setBits

original_code:
unsigned int setBits(unsigned int x, int position, int number, unsigned int value){
 x = x & (~0 << position);
 x = x | ~(~0 << (position - number));
 value = value & ~(~0 << number);
 value = value << (position - number);
 return x | value;
}

variable_types:
value
unsigned int


getBits

decompiled_code:
__int64 __fastcall getBits(unsigned int a1, char a2, char a3)
{
return (a1 >> (a2 - a3)) & ~(-1 << a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char a2, char a3)
{
return (a1 >> (a2 - a3)) & ~(-1 << a3);
}

original_code:
unsigned int getBits(unsigned int x, int position, int number){
 return ( x >> ( position - number )) & ~ ( ~ 0 << number);
}


printBinary

decompiled_code:
int __fastcall printBinary(unsigned int a1)
{
unsigned int v1; // edx
char *v2; // rcx
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
char *v6; // rbx
char *v7; // rbp
int v8; // edi
char v10; // [rsp+1h] [rbp-119h] BYREF
char v11[280]; // [rsp+2h] [rbp-118h] BYREF

v1 = a1;
memset(v11, 0, 0x100uLL);
if ( a1 )
{
v2 = v11;
do
{
*v2++ = (v1 & 1) + 48;
v1 >>= 1;
}
while ( v1 );
}
v3 = 0LL;
if ( v11[0] )
{
do
{
v4 = (int)v3;
v5 = v3++;
}
while ( v11[v3] );
v6 = &v11[v4];
v7 = &v10 + v4 - v5;
do
{
v8 = *v6--;
putchar(v8);
}
while ( v7 != v6 );
}
return putchar(10);
}

original_code:
void printBinary(unsigned int input){
 int MAXLENGTH = 256;
 char binaryString[MAXLENGTH];
 int i;
 for(i = 0; i < MAXLENGTH; i++)
  binaryString[i] = '\0';
 i = 0;
 while(input){
  binaryString[i] = '0' + (input & 1);
  input >>= 1;
  i++;
 }
 i = 0;
 while(binaryString[i] != '\0'){
  i++;
 }
 while(--i >= 0){
  printf("%c", binaryString[i]);
 }
 printf("\n");
}

canonical_original_code:
void printBinary(unsigned int input){
 int MAXLENGTH = 256;
 char binaryString[-1];
 int i;
 for(i = 0; i < MAXLENGTH; i++)
  binaryString[i] = '\0';
 i = 0;
 while(input){
  binaryString[i] = '0' + (input & 1);
  input >>= 1;
  i++;
 }
 i = 0;
 while(binaryString[i] != '\0'){
  i++;
 }
 while(--i >= 0){
  printf("%c", binaryString[i]);
 }
 printf("\n");
}

variable_types:
input
unsigned int

variable_types: MAXLENGTH int

variable_types:
binaryString
char [-1]

variable_types: i int


decompiled_code:
int ex2_8()
{
unsigned int v0; // eax

printBinary(8u);
v0 = rightRotate(8u, 2);
return printBinary(v0);
}

canonical_decompiled_code:
int func10()
{
unsigned int v0; // eax

func9(8u);
v0 = func5(8u, 2);
return func9(v0);
}

original_code:
void ex2_8(){
 unsigned int value = 8;
 printBinary(value);
 value = rightRotate(value, 2);
 printBinary(value);
}


decompiled_code:
int ex2_7()
{
unsigned int v0; // eax

printBinary(0xFu);
v0 = invertBits(15, 3, 2);
return printBinary(v0);
}

canonical_decompiled_code:
int func11()
{
unsigned int v0; // eax

func9(0xFu);
v0 = func6(15, 3, 2);
return func9(v0);
}

original_code:
void ex2_7(){
 unsigned int value = 0xF;
 printBinary(value);
 value = invertBits(value, 3, 2);
 printBinary(value);
}


decompiled_code:
int ex2_6()
{
unsigned int v0; // eax

printBinary(0xFu);
v0 = setBits(15, 4, 2, 2);
return printBinary(v0);
}

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

func9(0xFu);
v0 = func7(15, 4, 2, 2);
return func9(v0);
}

original_code:
void ex2_6(){
 unsigned int value = 0xF;
 unsigned int value2 = 2;
 printBinary(value);
 value = setBits(value, 4, 2, value2);
 printBinary(value);
}


decompiled_code:
__int64 __fastcall ex2_5(char *a1, char *a2)
{
char v2; // cl
__int64 v4; // rdi
char *v5; // rdx
char v6; // al

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( 1 )
{
v5 = a2 + 1;
v6 = *a2;
if ( *a2 )
break;
LABEL_8:
v2 = a1[++v4];
if ( !v2 )
return 0xFFFFFFFFLL;
}
while ( v2 != v6 )
{
v6 = *v5++;
if ( !v6 )
goto LABEL_8;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1, char *a2)
{
char v2; // cl
__int64 v4; // rdi
char *v5; // rdx
char v6; // al

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( 1 )
{
v5 = a2 + 1;
v6 = *a2;
if ( *a2 )
break;
LABEL_8:
v2 = a1[++v4];
if ( !v2 )
return 0xFFFFFFFFLL;
}
while ( v2 != v6 )
{
v6 = *v5++;
if ( !v6 )
goto LABEL_8;
}
return (unsigned int)v4;
}

original_code:
int ex2_5(char s1[], char s2[]){
 int position = -1;
 char temp, temp2;
 int i, j;
 for(i = 0; (temp = s1[i]) && temp != '\0'; i++){
  for(j = 0; (temp2 = s2[j]) && temp2 != '\0'; j++){
   if(temp == temp2)
    return position = i;
  }
 }
 return position;
}

canonical_original_code:
int ex2_5(char s1[], char s2[]){
 int position = -1;
 char temp; char temp2;
 int i; int j;
 for(i = 0; (temp = s1[i]) && temp != '\0'; i++){
  for(j = 0; (temp2 = s2[j]) && temp2 != '\0'; j++){
   if(temp == temp2)
    return position = i;
  }
 }
 return position;
}

variable_types: temp char

variable_types: j int


original_code:
void ex2_3(char myString[]){
 char hexDigits[] = "0123456789ABCDEF";
 float result = 0.0f;
 int counter = 0;
 while(myString[counter++] != '\0'){}
 counter--;
 int i;
 for(i = 0; counter-- > 0; i++){
  int j;
  if(myString[counter] == 'x' || myString[counter] == 'X')
   break;
  for(j = 0; j <= 16; j++){
   if(tolower(hexDigits[j]) == tolower(myString[counter])){
    float base = pow(16, i);
    if(base)
     result += base*j;
    else
     result += j;
   }
  }
 }
 printf("Result: %f\n", result);
}

variable_types:
myString
char []

variable_types:
hexDigits
char []

variable_types: result float

variable_types: counter int

variable_types: base float


original_code:
void ex2_2(){
 int lim = 10;
 char myString[lim];
 int i;
 char c;
 for(i = 0; i < lim; i++)
  myString[i] = '\0';
 for(i = 0; i < lim-1; ++i){
  if((c = getchar()) != '\n'){
   if(c != (-1))
    myString[i] = c;
  }
 }
 for(i = 0; i < lim; i++)
  printf("%c",myString[i]);
 printf("\n");
}

canonical_original_code:
void ex2_2(){
 int lim = 10;
 char myString[-1];
 int i;
 char c;
 for(i = 0; i < lim; i++)
  myString[i] = '\0';
 for(i = 0; i < lim-1; ++i){
  if((c = getchar()) != '\n'){
   if(c != (-1))
    myString[i] = c;
  }
 }
 for(i = 0; i < lim; i++)
  printf("%c",myString[i]);
 printf("\n");
}

variable_types: lim int

variable_types:
myString
char [-1]

variable_types: c char


decompiled_code:
int ex2_1()
{
printf("Unsigned char\tMax:%hhu\n", 255LL);
printf("Signed char\tMin:%hhd\tMax:%hhd\n", 4294967168LL, 127LL);
printf("Unsigned int\tMax:%u\n", 0xFFFFFFFFLL);
printf("Signed int\tMin:%u\tMax:%d\n", 0x80000000LL, 0x7FFFFFFFLL);
printf("Unsigned short\tMax:%hu\n", 0xFFFFLL);
printf("Signed short\tMin:%hd\tMax:%hd\n", 4294934528LL, 0x7FFFLL);
printf("Unsigned long\tMax:%lu\n", -1LL);
printf("Signed long\tMin:%ld\tMax:%ld\n", 0x8000000000000000LL, 0x7FFFFFFFFFFFFFFFLL);
printf("Unsigned long long\tMax:%llu\n", -1LL);
printf("Signed long long\tMin:%lld\tMax:%lld\n", 0x8000000000000000LL, 0x7FFFFFFFFFFFFFFFLL);
return printf("Float MIN:%E\tMAX:%E\n", *(double *)&LC19, *(double *)&LC18);
}

canonical_decompiled_code:
int func17()
{
printf("Unsigned char\tMax:%hhu\n", 255LL);
printf("Signed char\tMin:%hhd\tMax:%hhd\n", 4294967168LL, 127LL);
printf("Unsigned int\tMax:%u\n", 0xFFFFFFFFLL);
printf("Signed int\tMin:%u\tMax:%d\n", 0x80000000LL, 0x7FFFFFFFLL);
printf("Unsigned short\tMax:%hu\n", 0xFFFFLL);
printf("Signed short\tMin:%hd\tMax:%hd\n", 4294934528LL, 0x7FFFLL);
printf("Unsigned long\tMax:%lu\n", -1LL);
printf("Signed long\tMin:%ld\tMax:%ld\n", 0x8000000000000000LL, 0x7FFFFFFFFFFFFFFFLL);
printf("Unsigned long long\tMax:%llu\n", -1LL);
printf("Signed long long\tMin:%lld\tMax:%lld\n", 0x8000000000000000LL, 0x7FFFFFFFFFFFFFFFLL);
return printf("Float MIN:%E\tMAX:%E\n", *(double *)&LC19, *(double *)&LC18);
}

original_code:
void ex2_1(){
 printf("Unsigned char\tMax:%hhu\n",(0x7f * 2 + 1));
 printf("Signed char\tMin:%hhd\tMax:%hhd\n", (-0x7f - 1), 0x7f);
 printf("Unsigned int\tMax:%u\n", (0x7fffffff * 2U + 1U));
 printf("Signed int\tMin:%u\tMax:%d\n", (-0x7fffffff - 1), 0x7fffffff);
 printf("Unsigned short\tMax:%hu\n", (0x7fff * 2 + 1));
 printf("Signed short\tMin:%hd\tMax:%hd\n", (-0x7fff - 1), 0x7fff);
 printf("Unsigned long\tMax:%lu\n", (0x7fffffffffffffffL * 2UL + 1UL));
 printf("Signed long\tMin:%ld\tMax:%ld\n", (-0x7fffffffffffffffL - 1L), 0x7fffffffffffffffL);
 printf("Unsigned long long\tMax:%llu\n", (0x7fffffffffffffffLL * 2ULL + 1ULL));
 printf("Signed long long\tMin:%lld\tMax:%lld\n", (-0x7fffffffffffffffLL - 1LL), 0x7fffffffffffffffLL);
 printf("Float MIN:%E\tMAX:%E\n", 1.17549435082228750796873653722224568e-38F, 3.40282346638528859811704183484516925e+38F);
}


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

if ( read(0, buf, 1uLL) == 1 )
result = (unsigned __int8)buf[0];
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( read(0, buf, 1uLL) == 1 )
result = (unsigned __int8)buf[0];
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int getcharch8(void){
  char c;
  return (read(0, &c, 1) == 1) ? (unsigned char) c : (-1);
}

canonical_original_code:
int getcharch8(){
  char c;
  return (read(0, &c, 1) == 1) ? (unsigned char) c : (-1);
}


inputtooutput

decompiled_code:
ssize_t inputtooutput()
{
ssize_t result; // rax
_BYTE v1[120]; // [rsp+0h] [rbp-78h] BYREF

while ( 1 )
{
result = read(0, v1, 0x64uLL);
if ( (int)result <= 0 )
break;
write(1, v1, (int)result);
}
return result;
}

canonical_decompiled_code:
ssize_t func1()
{
ssize_t result; // rax
_BYTE v1[120]; // [rsp+0h] [rbp-78h] BYREF

while ( 1 )
{
result = read(0, v1, 0x64uLL);
if ( (int)result <= 0 )
break;
write(1, v1, (int)result);
}
return result;
}

original_code:
void inputtooutput(void){
  char buffer[100];
  int n;
  while((n = read(0, buffer, 100)) > 0){
    write(1, buffer, n);
  }
}

canonical_original_code:
void inputtooutput(){
  char buffer[100];
  int n;
  while((n = read(0, buffer, 100)) > 0){
    write(1, buffer, n);
  }
}

variable_types:
buffer
char [100]

variable_types: n int


main

repo: JamesBirchall/sdltutorials

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
SDL_Init();
SDL_Quit();
return 0;
}

original_code:
int main(int argc, char **argv){
  SDL_Init( 0x0000FFFF );
  SDL_Quit();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: JamesDillon/C-Misc

original_code:
void bubble_sort(int numbers[], int elements)
{
   int k, i;
   for ( i = elements; i > 0; i--)
   {
      for (k = 1; k <= elements; k++)
      {
         if (numbers[k - 1] > numbers[k])
         {
            numbers[k - 1] ^= numbers[k];
            numbers[k] ^= numbers[k - 1];
            numbers[k - 1] ^= numbers[k];
         }
      }
   }
}

canonical_original_code:
void bubble_sort(int numbers[], int elements)
{
   int k; int i;
   for ( i = elements; i > 0; i--)
   {
      for (k = 1; k <= elements; k++)
      {
         if (numbers[k - 1] > numbers[k])
         {
            numbers[k - 1] ^= numbers[k];
            numbers[k] ^= numbers[k - 1];
            numbers[k - 1] ^= numbers[k];
         }
      }
   }
}

variable_types:
numbers
int []

variable_types: elements int

variable_types: k int


original_code:
int main(int argc, char *argv[])
{
   int numbers[] = { 4, 5, 3, 1, 6, 8, 23, 53, 2, 5 };
   int number_of_elements = 10;
   int i;
   bubble_sort(numbers, number_of_elements);
   for (i = 0; i <= 10; i++)
   {
      printf("%d\t", numbers[i]);
   }
   return 0;
}

variable_types:
argv
char *[]

variable_types: i int


sort

decompiled_code:
__int64 __fastcall sort(unsigned int *a1, int a2)
{
unsigned int v2; // er8
unsigned int *v3; // rax

v2 = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
do
{
if ( (int)v2 < (int)*v3 )
v2 = *v3;
++v3;
}
while ( &a1[a2 - 2 + 2] != v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, int a2)
{
unsigned int v2; // er8
unsigned int *v3; // rax

v2 = *a1;
if ( a2 > 1 )
{
v3 = a1 + 1;
do
{
if ( (int)v2 < (int)*v3 )
v2 = *v3;
++v3;
}
while ( &a1[a2 - 2 + 2] != v3 );
}
return v2;
}

original_code:
int sort(int arr[], int size)
{
   int largestIndex = 0;
   int j;
   for (j = 1; j < size; j++)
   {
      if (arr[largestIndex] < arr[j])
      {
         largestIndex = j;
      }
   }
   return arr[largestIndex];
}

variable_types:
arr
int []

variable_types: size int

variable_types: largestIndex int

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]

v5[0] = 0x500000001LL;
v5[1] = 0x300000007LL;
v6 = 5;
v3 = sort(v5, 5LL, envp);
printf("The biggest is: %d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+10h] [rbp-18h]

v5[0] = 0x500000001LL;
v5[1] = 0x300000007LL;
v6 = 5;
v3 = func7(v5, 5LL, envp);
printf("The biggest is: %d\n", v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
   int arr[5] = { 1, 5, 7, 3, 5};
   printf("The biggest is: %d\n", sort(arr, 5));
   return 0;
}

variable_types:
arr
int [5]


getfreeframe

repo: Japumba/Operativos

decompiled_code:
__int64 getfreeframe()
{
__int64 result; // rax
int v1; // ecx
_DWORD *i; // rdx

result = framesbegin;
v1 = framesbegin + systemframetablesize;
if ( framesbegin + systemframetablesize <= framesbegin )
return 0xFFFFFFFFLL;
for ( i = (_DWORD *)(systemframetable + 24LL * framesbegin); *i; i += 6 )
{
result = (unsigned int)(result + 1);
if ( v1 == (_DWORD)result )
return 0xFFFFFFFFLL;
}
*i = 1;
if ( v1 <= (int)result )
return 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // ecx
_DWORD *i; // rdx

result = framesbegin;
v1 = framesbegin + systemframetablesize;
if ( framesbegin + systemframetablesize <= framesbegin )
return 0xFFFFFFFFLL;
for ( i = (_DWORD *)(systemframetable + 24LL * framesbegin); *i; i += 6 )
{
result = (unsigned int)(result + 1);
if ( v1 == (_DWORD)result )
return 0xFFFFFFFFLL;
}
*i = 1;
if ( v1 <= (int)result )
return 0xFFFFFFFFLL;
return result;
}

original_code:
int getfreeframe()
{
    int i;
    for(i=framesbegin;i<systemframetablesize+framesbegin;i++)
        if(!systemframetable[i].assigned)
        {
            systemframetable[i].assigned=1;
            break;
        }
    if(i<systemframetablesize+framesbegin)
        systemframetable[i].assigned=1;
    else
        i=-1;
    return(i);
}


pagefault

decompiled_code:
__int64 __fastcall pagefault(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

countframesassigned();
result = getfreeframe();
if ( (_DWORD)result != -1 )
{
v2 = 40LL * (a1 >> 12);
*(_DWORD *)((char *)&processpagetable + v2) = 1;
*(_DWORD *)((char *)&processpagetable + v2 + 8) = result;
result = 1LL;
}
return result;
}

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

countframesassigned();
result = func0();
if ( (_DWORD)result != -1 )
{
v2 = 40LL * (a1 >> 12);
*(_DWORD *)((char *)&processpagetable + v2) = 1;
*(_DWORD *)((char *)&processpagetable + v2 + 8) = result;
result = 1LL;
}
return result;
}

original_code:
int pagefault(char *vaddress)
{
    int i;
    int frame;
    int pag_a_expulsar;
    int pag_del_proceso;
    pag_del_proceso=(int) vaddress>>12;
    i=countframesassigned();
    frame=getfreeframe();
    if(frame==-1)
    {
        return(-1);
    }
    processpagetable[pag_del_proceso].presente=1;
    processpagetable[pag_del_proceso].framenumber=frame;
    return(1);
}

variable_types:
vaddress
char *

variable_types: frame int


createsem

decompiled_code:
int __fastcall createsem(key_t a1)
{
return semget(a1, 1, 950);
}

canonical_decompiled_code:
int __fastcall func7(key_t a1)
{
return semget(a1, 1, 950);
}

original_code:
int createsem(key_t key)
{
 int semid;
 return semid = semget(key, 1, 0666 | 01000);
}

canonical_original_code:
int createsem(int key)
{
 int semid;
 return semid = semget(key, 1, 0666 | 01000);
}

variable_types: key int

variable_types: semid int


seminit

decompiled_code:
int __fastcall seminit(int a1, unsigned int a2)
{
return semctl(a1, 0, 16, a2);
}

canonical_decompiled_code:
int __fastcall func8(int a1, unsigned int a2)
{
return semctl(a1, 0, 16, a2);
}

original_code:
void seminit(int semid, int val)
{
 union semnum arg;
 arg.val = val;
 semctl(semid, 0, 16, arg);
}

variable_types: val int

variable_types: union semnum { int val; struct semid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; } *buf; unsigned short *array; }

user_defined_types: union semnum { int val; struct semid_ds *buf; unsigned short *array; }

user_defined_types: struct semid_ds { struct ipc_perm sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; }


semwait

decompiled_code:
int __fastcall semwait(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = -65536;
sops.sem_flg = 4096;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = -65536;
sops.sem_flg = 4096;
return semop(a1, &sops, 1uLL);
}

original_code:
void semwait(int semid)
{
 struct sembuf buf;
 buf.sem_num = 0;
 buf.sem_op = -1;
 buf.sem_flg = 0x1000;
 semop(semid, &buf, 1);
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


semsignal

decompiled_code:
int __fastcall semsignal(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = 0x10000;
sops.sem_flg = 6144;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

*(_DWORD *)&sops.sem_num = 0x10000;
sops.sem_flg = 6144;
return semop(a1, &sops, 1uLL);
}

original_code:
void semsignal(int semid)
{
 struct sembuf buf;
 buf.sem_num = 0;
 buf.sem_op = 1;
 buf.sem_flg = 0x1000 | 04000;
 semop(semid, &buf, 1);
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
unsigned int v4; // eax
unsigned int v5; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

semid = createsem(1234LL, argv, envp);
v3 = (unsigned int)semid;
if ( semid == -1 )
{
perror("Couldn't create semaphore :(");
v3 = (unsigned int)semid;
}
seminit(v3, 1LL);
v4 = getpid();
srand(v4);
v5 = fork();
if ( !v5 )
LABEL_8:
proceso(v5);
if ( !fork() )
{
v5 = 1;
goto LABEL_8;
}
if ( !fork() )
{
v5 = 2;
goto LABEL_8;
}
wait((__WAIT_STATUS)&stat_loc);
wait((__WAIT_STATUS)&stat_loc);
wait((__WAIT_STATUS)&stat_loc);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
unsigned int v4; // eax
unsigned int v5; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

semid = func7(1234LL, argv, envp);
v3 = (unsigned int)semid;
if ( semid == -1 )
{
perror("Couldn't create semaphore :(");
v3 = (unsigned int)semid;
}
func8(v3, 1LL);
v4 = getpid();
srand(v4);
v5 = fork();
if ( !v5 )
LABEL_8:
func11(v5);
if ( !fork() )
{
v5 = 1;
goto LABEL_8;
}
if ( !fork() )
{
v5 = 2;
goto LABEL_8;
}
wait((__WAIT_STATUS)&stat_loc);
wait((__WAIT_STATUS)&stat_loc);
wait((__WAIT_STATUS)&stat_loc);
return 0;
}

original_code:
int main()
{
 int pid;
 int status;
 int args[3];
 int i;
 void *thread_result;
 key_t key = 1234;
 semid = createsem(key);
 if(semid == -1) perror("Couldn't create semaphore :(");
 seminit(semid, 1);
 srand(getpid());
 for(i=0;i<3;i++)
 {
  pid=fork();
  if(pid==0)
   proceso(i);
 }
 for(i=0;i<3;i++)
  pid = wait(&status);
}

canonical_original_code:
int main()
{
 int pid;
 int status;
 int args[3];
 int i;
 void *thread_result;
 int key = 1234;
 semid = createsem(key);
 if(semid == -1) perror("Couldn't create semaphore :(");
 seminit(semid, 1);
 srand(getpid());
 for(i=0;i<3;i++)
 {
  pid=fork();
  if(pid==0)
   proceso(i);
 }
 for(i=0;i<3;i++)
  pid = wait(&status);
}

variable_types: pid int

variable_types: status int

variable_types:
args
int [3]


proceso

decompiled_code:
void __fastcall __noreturn proceso(int a1)
{
int v1; // ebx
int v2; // eax
int v3; // eax

v1 = 10;
do
{
semwait(semid);
printf("Entra %s", (&pais)[a1]);
fflush(_bss_start);
v2 = rand();
sleep(v2 % 3);
printf("- %s Sale\n", (&pais)[a1]);
semsignal(semid);
v3 = rand();
sleep(v3 % 3);
--v1;
}
while ( v1 );
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(int a1)
{
int v1; // ebx
int v2; // eax
int v3; // eax

v1 = 10;
do
{
func9(semid);
printf("Entra %s", (&pais)[a1]);
fflush(_bss_start);
v2 = rand();
sleep(v2 % 3);
printf("- %s Sale\n", (&pais)[a1]);
func10(semid);
v3 = rand();
sleep(v3 % 3);
--v1;
}
while ( v1 );
exit(0);
}

original_code:
void proceso(int i)
{
 int k;
 int l;
 for(k=0;k<10;k++)
 {
  semwait(semid);
  printf("Entra %s",pais[i]);
  fflush(stdout);
  sleep(rand()%3);
  printf("- %s Sale\n",pais[i]);
  semsignal(semid);
  sleep(rand()%3);
 }
 exit(0);
}

variable_types: k int

variable_types: l int


execExit

decompiled_code:
void __noreturn execExit()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
exit(0);
}

original_code:
void execExit()
{
 exit(0);
}

canonical_original_code:
void execExit()
{
 exit(0);
}


execShutdown

decompiled_code:
int execShutdown()
{
return kill(initID, 9);
}

canonical_decompiled_code:
int func8()
{
return kill(initID, 9);
}

original_code:
void execShutdown()
{
 kill(initID, 9);
}


execGeneric

decompiled_code:
__pid_t __fastcall execGeneric(const char ***a1)
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

if ( !fork() )
{
execvp(**a1, (char *const *)*a1);
puts("ERROR EXECUTING PROGRAM");
}
return wait((__WAIT_STATUS)&stat_loc);
}

canonical_decompiled_code:
__pid_t __fastcall func9(const char ***a1)
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

if ( !fork() )
{
execvp(**a1, (char *const *)*a1);
puts("ERROR EXECUTING PROGRAM");
}
return wait((__WAIT_STATUS)&stat_loc);
}

original_code:
void execGeneric(COMMAND *cmd)
{
 int pid;
 int status;
 pid = fork();
 if(pid == 0)
 {
  execvp(cmd->argv[0],cmd->argv);
  printf("ERROR EXECUTING PROGRAM\n");
 }
 wait(&status);
}

canonical_original_code:
void execGeneric(struct COMMAND *cmd)
{
 int pid;
 int status;
 pid = fork();
 if(pid == 0)
 {
  execvp(cmd->argv[0],cmd->argv);
  printf("ERROR EXECUTING PROGRAM\n");
 }
 wait(&status);
}

variable_types: struct COMMAND { char **argv; int args; int type; } *


executeCommand

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

puts("!!!ATTEMPTING TO EXECUTE COMMAND");
if ( !a1 )
return puts("!!CANNOT EXECUTE COMMAND, NULL COMMAND");
v1 = *((_DWORD *)a1 + 3);
if ( v1 == 2 )
{
puts("!!!EXECUTING SHUTDOWN COMMAND");
result = execShutdown();
}
else if ( v1 == 3 )
{
printf("!!!EXECUTING GENERIC COMMAND WITH NAME: %s AND %i ARGUMENTS.\n", **a1, *((unsigned int *)a1 + 2));
result = execGeneric(a1);
}
else
{
if ( v1 == 1 )
{
puts("!!!EXECUTING EXIT COMMAND");
execExit();
}
result = puts("!!!COULDNT EXECUTE COMMAND. INVALID TYPE");
}
return result;
}

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

puts("!!!ATTEMPTING TO EXECUTE COMMAND");
if ( !a1 )
return puts("!!CANNOT EXECUTE COMMAND, NULL COMMAND");
v1 = *((_DWORD *)a1 + 3);
if ( v1 == 2 )
{
puts("!!!EXECUTING SHUTDOWN COMMAND");
result = func8();
}
else if ( v1 == 3 )
{
printf("!!!EXECUTING GENERIC COMMAND WITH NAME: %s AND %i ARGUMENTS.\n", **a1, *((unsigned int *)a1 + 2));
result = func9(a1);
}
else
{
if ( v1 == 1 )
{
puts("!!!EXECUTING EXIT COMMAND");
func7();
}
result = puts("!!!COULDNT EXECUTE COMMAND. INVALID TYPE");
}
return result;
}

original_code:
void executeCommand(COMMAND *cmd)
{
 printf("!!!ATTEMPTING TO EXECUTE COMMAND\n");
 if(cmd == ((void *)0))
 {
  printf("!!CANNOT EXECUTE COMMAND, NULL COMMAND\n");
  return;
 }
 int type = cmd->type;
 switch(type)
 {
  case 1:
   printf("!!!EXECUTING EXIT COMMAND\n");
   execExit();
   break;
  case 2:
   printf("!!!EXECUTING SHUTDOWN COMMAND\n");
   execShutdown();
   break;
  case 3:
   printf("!!!EXECUTING GENERIC COMMAND WITH NAME: %s AND %i ARGUMENTS.\n", cmd->argv[0], cmd->args);
   execGeneric(cmd);
   break;
  default:
   printf("!!!COULDNT EXECUTE COMMAND. INVALID TYPE\n");
   break;
 }
}

canonical_original_code:
void executeCommand(struct COMMAND *cmd)
{
 printf("!!!ATTEMPTING TO EXECUTE COMMAND\n");
 if(cmd == ((void *)0))
 {
  printf("!!CANNOT EXECUTE COMMAND, NULL COMMAND\n");
  return;
 }
 int type = cmd->type;
 switch(type)
 {
  case 1:
   printf("!!!EXECUTING EXIT COMMAND\n");
   execExit();
   break;
  case 2:
   printf("!!!EXECUTING SHUTDOWN COMMAND\n");
   execShutdown();
   break;
  case 3:
   printf("!!!EXECUTING GENERIC COMMAND WITH NAME: %s AND %i ARGUMENTS.\n", cmd->argv[0], cmd->args);
   execGeneric(cmd);
   break;
  default:
   printf("!!!COULDNT EXECUTE COMMAND. INVALID TYPE\n");
   break;
 }
}

variable_types: type int

user_defined_types: struct COMMAND { char **argv; int args; int type; }


destroyCommand

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

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

original_code:
void destroyCommand(COMMAND *cmd)
{
 free(cmd->argv);
 free(cmd);
}

canonical_original_code:
void destroyCommand(struct COMMAND *cmd)
{
 free(cmd->argv);
 free(cmd);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
void *v4; // rbp
char v6[256]; // [rsp-108h] [rbp-108h] BYREF
__int64 v7; // [rsp-8h] [rbp-8h]

if ( argc > 1 )
{
v7 = v3;
initID = atoi(argv[1]);
while ( 1 )
{
printf("sh> ");
gets();
printf("!!!COMMAND: %s\n", v6);
v4 = (void *)parseInput(v6);
executeCommand(v4);
destroyCommand(v4);
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
void *v4; // rbp
char v6[256]; // [rsp-108h] [rbp-108h] BYREF
__int64 v7; // [rsp-8h] [rbp-8h]

if ( argc > 1 )
{
v7 = v3;
initID = atoi(argv[1]);
while ( 1 )
{
printf("sh> ");
gets();
printf("!!!COMMAND: %s\n", v6);
v4 = (void *)parseInput(v6);
func10(v4);
func11(v4);
}
}
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 if(argc < 2)
  return 1;
 initID = atoi(argv[1]);
 char input[256];
 COMMAND *command = ((void *)0);
 int args = 0;
 while(1)
 {
  printf("sh> ");
  gets(input);
  printf("!!!COMMAND: %s\n", input);
  command = parseInput(input);
  executeCommand(command);
  destroyCommand(command);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc < 2)
  return 1;
 initID = atoi(argv[1]);
 char input[256];
 struct COMMAND *command = ((void *)0);
 int args = 0;
 while(1)
 {
  printf("sh> ");
  gets(input);
  printf("!!!COMMAND: %s\n", input);
  command = parseInput(input);
  executeCommand(command);
  destroyCommand(command);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
input
char [256]

variable_types: args int


takeItem

decompiled_code:
int takeItem()
{
int v0; // eax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

sem_getvalue(&notEmpty, sval);
v0 = pthread_self();
return printf("<<<ITEM TAKEN by %i, [%i] items in buffer\n", (unsigned int)(v0 % 100), (unsigned int)sval[0]);
}

canonical_decompiled_code:
int func7()
{
int v0; // eax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

sem_getvalue(&notEmpty, sval);
v0 = pthread_self();
return printf("<<<ITEM TAKEN by %i, [%i] items in buffer\n", (unsigned int)(v0 % 100), (unsigned int)sval[0]);
}

original_code:
void takeItem()
{
 int i;
 sem_getvalue(&notEmpty, &i);
 printf("<<<ITEM TAKEN by %i, [%i] items in buffer\n", (((int)pthread_self())%100), i);
}

variable_types: i int


consumerRoutine

decompiled_code:
void __fastcall __noreturn consumerRoutine(void *a1)
{
int v1; // eax

while ( 1 )
{
v1 = rand();
sleep(v1 % 3 + 1);
sem_wait(&notEmpty);
sem_wait(&consumerMutex);
takeItem();
sem_post(&consumerMutex);
sem_post(&notFull);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // eax

while ( 1 )
{
v1 = rand();
sleep(v1 % 3 + 1);
sem_wait(&notEmpty);
sem_wait(&consumerMutex);
func7();
sem_post(&consumerMutex);
sem_post(&notFull);
}
}

original_code:
void *consumerRoutine(void *arg)
{
 while(1)
 {
  sleep(rand() %3 + 1);
  sem_wait(&notEmpty);
  sem_wait(&consumerMutex);
  takeItem();
  sem_post(&consumerMutex);
  sem_post(&notFull);
 }
}

variable_types:
arg
void *

return_type: void *


placeItem

decompiled_code:
int placeItem()
{
int v0; // eax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

sem_getvalue(&notEmpty, sval);
v0 = pthread_self();
return printf(">>>ITEM PLACED by %i, [%i] items in buffer\n", (unsigned int)(v0 % 100), (unsigned int)(sval[0] + 1));
}

canonical_decompiled_code:
int func9()
{
int v0; // eax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

sem_getvalue(&notEmpty, sval);
v0 = pthread_self();
return printf(">>>ITEM PLACED by %i, [%i] items in buffer\n", (unsigned int)(v0 % 100), (unsigned int)(sval[0] + 1));
}

original_code:
void placeItem()
{
 int i;
 sem_getvalue(&notEmpty, &i);
 printf(">>>ITEM PLACED by %i, [%i] items in buffer\n", (((int)pthread_self())%100), i+1);
}


producerRoutine

decompiled_code:
void __fastcall __noreturn producerRoutine(void *a1)
{
int v1; // eax

while ( 1 )
{
v1 = rand();
sleep(v1 % 3 + 1);
sem_wait(&notFull);
sem_wait(&producerMutex);
placeItem();
sem_post(&producerMutex);
sem_post(&notEmpty);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
int v1; // eax

while ( 1 )
{
v1 = rand();
sleep(v1 % 3 + 1);
sem_wait(&notFull);
sem_wait(&producerMutex);
func9();
sem_post(&producerMutex);
sem_post(&notEmpty);
}
}

original_code:
void *producerRoutine(void *arg)
{
 while(1)
 {
  sleep(rand() %3 + 1);
  sem_wait(&notFull);
  sem_wait(&producerMutex);
  placeItem();
  sem_post(&producerMutex);
  sem_post(&notEmpty);
 }
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // eax
int j; // eax
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

sem_init(&notEmpty, 0, 0);
sem_init(&notFull, 0, 5u);
sem_init(&producerMutex, 0, 1u);
sem_init(&consumerMutex, 0, 1u);
sem_getvalue(&notFull, sval);
printf("SEM VALUE: %i\n", (unsigned int)sval[0]);
sval[0] = 0;
for ( i = 0; i <= 1; sval[0] = i )
{
pthread_create(&producer + i, 0LL, producerRoutine, sval);
i = sval[0] + 1;
}
sval[0] = 0;
for ( j = 0; j <= 0; sval[0] = j )
{
pthread_create(&consumer + j, 0LL, consumerRoutine, sval);
j = sval[0] + 1;
}
while ( 1 )
;
}

original_code:
int main(int argc, char *args[])
{
 int i;
 sem_init(&notEmpty, 0, 0);
 sem_init(&notFull, 0, 5);
 sem_init(&producerMutex, 0, 1);
 sem_init(&consumerMutex, 0, 1);
 sem_getvalue(&notFull,&i);
 printf("SEM VALUE: %i\n", i);
 for(i = 0; i < 2; i++)
  pthread_create(&producer[i], ((void *)0), producerRoutine, &i);
 for(i = 0; i < 1; i++)
  pthread_create(&consumer[i], ((void *)0), consumerRoutine, &i);
 while(1);
 return 0;
}

variable_types:
args
char *[]


blackandwhite

decompiled_code:
__int64 __fastcall blackandwhite(int a1)
{
return (unsigned int)(int)((double)BYTE1(a1) * 0.59 + (double)(unsigned __int8)a1 * 0.3 + (double)BYTE2(a1) * 0.11);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(int)((double)BYTE1(a1) * 0.59 + (double)(unsigned __int8)a1 * 0.3 + (double)BYTE2(a1) * 0.11);
}

original_code:
unsigned char blackandwhite(PIXEL p)
{
 return((unsigned char) (0.3*((float)p.red)+
 0.59*((float)p.green)+0.11*((float)p.blue)));
}

canonical_original_code:
unsigned char blackandwhite(struct PIXEL p)
{
 return((unsigned char) (0.3*((float)p.red)+
 0.59*((float)p.green)+0.11*((float)p.blue)));
}

variable_types: struct PIXEL { unsigned char red; unsigned char green; unsigned char blue; }

return_type: unsigned char


processBMP

original_code:
void *processBMP(void *arg)
{
 int i,j;
 int count=0;
 PIXEL *pfte,*pdst;
 PIXEL *v0,*v1,*v2,*v3,*v4,*v5,*v6,*v7;
 int imageRows,imageCols;
 int numThread = *(int *)arg;
 imageRows = (&imagenfte)->infoheader.rows;
 imageCols = (&imagenfte)->infoheader.cols;
 for(i=1+numThread;i<imageRows-1;i+=8)
  for(j=1;j<imageCols-1;j++)
  {
  pfte=(&imagenfte)->pixel+imageCols*i+j;
  v0=pfte-imageCols-1;
  v1=pfte-imageCols;
  v2=pfte-imageCols+1;
  v3=pfte-1;
  v4=pfte+1;
  v5=pfte+imageCols-1;
  v6=pfte+imageCols;
  v7=pfte+imageCols+1;
  pdst=(&imagendst)->pixel+imageCols*i+j;
  if(abs(blackandwhite(*pfte)-blackandwhite(*v0))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v1))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v2))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v3))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v4))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v5))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v6))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v7))>16)
  {
  pdst->red=0;
  pdst->green=0;
  pdst->blue=0;
  }
  else
  {
  pdst->red=255;
  pdst->green=255;
  pdst->blue=255;
  }
 }
}

canonical_original_code:
void *processBMP(void *arg)
{
 int i; int j;
 int count = 0;
 struct PIXEL *pfte; struct PIXEL *pdst;
 struct PIXEL *v0; struct PIXEL *v1; struct PIXEL *v2; struct PIXEL *v3; struct PIXEL *v4; struct PIXEL *v5; struct PIXEL *v6; struct PIXEL *v7;
 int imageRows; int imageCols;
 int numThread = *(int *)arg;
 imageRows = (&imagenfte)->infoheader.rows;
 imageCols = (&imagenfte)->infoheader.cols;
 for(i=1+numThread;i<imageRows-1;i+=8)
  for(j=1;j<imageCols-1;j++)
  {
  pfte=(&imagenfte)->pixel+imageCols*i+j;
  v0=pfte-imageCols-1;
  v1=pfte-imageCols;
  v2=pfte-imageCols+1;
  v3=pfte-1;
  v4=pfte+1;
  v5=pfte+imageCols-1;
  v6=pfte+imageCols;
  v7=pfte+imageCols+1;
  pdst=(&imagendst)->pixel+imageCols*i+j;
  if(abs(blackandwhite(*pfte)-blackandwhite(*v0))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v1))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v2))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v3))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v4))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v5))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v6))>16 ||
   abs(blackandwhite(*pfte)-blackandwhite(*v7))>16)
  {
  pdst->red=0;
  pdst->green=0;
  pdst->blue=0;
  }
  else
  {
  pdst->red=255;
  pdst->green=255;
  pdst->blue=255;
  }
 }
}

variable_types: j int

variable_types: count int

variable_types: struct PIXEL { unsigned char red; unsigned char green; unsigned char blue; } *

variable_types: imageRows int

variable_types: imageCols int

variable_types: numThread int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
__int64 v7; // rbx
__int64 v8; // r14
char *v9; // rbp
_DWORD *v10; // rcx
void *v11; // rsi
char *v12; // rbp
__pid_t v13; // edi
int v14; // eax
int stat_loc; // [rsp+Ch] [rbp-9Ch] BYREF
int v17[8]; // [rsp+10h] [rbp-98h] BYREF
char dest[120]; // [rsp+30h] [rbp-78h] BYREF

v3 = clock();
v4 = strtok(filename, ".");
v5 = stpcpy(dest, v4);
v6 = strlen(filename);
strcpy(v5, "_P.bmp");
*(_DWORD *)&filename[v6] = 1886216750;
*(_BYTE *)(v6 + 4210836) = 0;
printf("Archivo fuente %s\n", filename);
printf("Archivo destino %s\n", dest);
if ( (unsigned int)loadBMP(filename, &imagenfte) == -1 )
{
fwrite("Error al abrir imagen\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
v7 = 0LL;
printf(
"Procesando imagen de: Renglones = %d, Columnas = %d\n",
(unsigned int)dword_404118,
(unsigned int)dword_404114);
printf("Paralelizando usando %i threads\n", 8LL);
stat_loc = 0;
threadID = (__int64)malloc(0x20uLL);
v8 = threadID;
imagendst = (__int128)_mm_load_si128((const __m128i *)&imagenfte);
qword_4040F0 = qword_404130;
xmmword_4040D0 = (__int128)_mm_load_si128((const __m128i *)&unk_404110);
xmmword_4040E0 = (__int128)_mm_load_si128((const __m128i *)&xmmword_404120);
qword_4040F8 = (__int64)malloc(3 * dword_404114 * (__int64)dword_404118);
v9 = (char *)malloc(0x2625A00uLL) + 5000000;
while ( 1 )
{
v10 = (_DWORD *)(v8 + 4 * v7);
v11 = v9;
*v10 = v7;
v9 += 5000000;
v17[v7++] = clone(processBMP, v11, 1792, v10);
if ( v7 == 8 )
break;
v8 = threadID;
}
v12 = (char *)v17;
do
{
v13 = *(_DWORD *)v12;
v12 += 4;
waitpid(v13, &stat_loc, 0x40000000);
}
while ( v12 != dest );
if ( (unsigned int)saveBMP(v12, &imagendst) == -1 )
{
fwrite("Error al escribir imagen\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v14 = clock();
printf("Tiempo %3.6f segundos\n", (float)((float)((float)v14 - (float)v3) / 1000000.0));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
__int64 v7; // rbx
__int64 v8; // r14
char *v9; // rbp
_DWORD *v10; // rcx
void *v11; // rsi
char *v12; // rbp
__pid_t v13; // edi
int v14; // eax
int stat_loc; // [rsp+Ch] [rbp-9Ch] BYREF
int v17[8]; // [rsp+10h] [rbp-98h] BYREF
char dest[120]; // [rsp+30h] [rbp-78h] BYREF

v3 = clock();
v4 = strtok(filename, ".");
v5 = stpcpy(dest, v4);
v6 = strlen(filename);
strcpy(v5, "_P.bmp");
*(_DWORD *)&filename[v6] = 1886216750;
*(_BYTE *)(v6 + 4210836) = 0;
printf("Archivo fuente %s\n", filename);
printf("Archivo destino %s\n", dest);
if ( (unsigned int)func7(filename, &imagenfte) == -1 )
{
fwrite("Error al abrir imagen\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
v7 = 0LL;
printf(
"Procesando imagen de: Renglones = %d, Columnas = %d\n",
(unsigned int)dword_404118,
(unsigned int)dword_404114);
printf("Paralelizando usando %i threads\n", 8LL);
stat_loc = 0;
threadID = (__int64)malloc(0x20uLL);
v8 = threadID;
imagendst = (__int128)_mm_load_si128((const __m128i *)&imagenfte);
qword_4040F0 = qword_404130;
xmmword_4040D0 = (__int128)_mm_load_si128((const __m128i *)&unk_404110);
xmmword_4040E0 = (__int128)_mm_load_si128((const __m128i *)&xmmword_404120);
qword_4040F8 = (__int64)malloc(3 * dword_404114 * (__int64)dword_404118);
v9 = (char *)malloc(0x2625A00uLL) + 5000000;
while ( 1 )
{
v10 = (_DWORD *)(v8 + 4 * v7);
v11 = v9;
*v10 = v7;
v9 += 5000000;
v17[v7++] = clone(processBMP, v11, 1792, v10);
if ( v7 == 8 )
break;
v8 = threadID;
}
v12 = (char *)v17;
do
{
v13 = *(_DWORD *)v12;
v12 += 4;
waitpid(v13, &stat_loc, 0x40000000);
}
while ( v12 != dest );
if ( (unsigned int)func8(v12, &imagendst) == -1 )
{
fwrite("Error al escribir imagen\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v14 = clock();
printf("Tiempo %3.6f segundos\n", (float)((float)((float)v14 - (float)v3) / 1000000.0));
return 0;
}

original_code:
int main()
{
 int res, i, j;
 clock_t t_inicial,t_final;
 char namedest[80];
 t_inicial=clock();
 strcpy(namedest,strtok(filename,"."));
 strcat(filename,".bmp");
 strcat(namedest,"_P.bmp");
 printf("Archivo fuente %s\n",filename);
 printf("Archivo destino %s\n",namedest);
 res=loadBMP(filename,&imagenfte);
 if(res==-1)
 {
  fprintf(stderr,"Error al abrir imagen\n");
  exit(1);
 }
 printf("Procesando imagen de: Renglones = %d, Columnas = %d\n",imagenfte.infoheader.rows,imagenfte.infoheader.cols);
 printf("Paralelizando usando %i threads\n", 8);
 threadID = (int *) malloc(sizeof(int)*8);
 memcpy(&imagendst, &imagenfte, sizeof(IMAGE)-sizeof(PIXEL *));
 int imageRows = (&imagenfte)->infoheader.rows;
 int imageCols = (&imagenfte)->infoheader.cols;
 int status=0;
 (&imagendst)->pixel=(PIXEL *)malloc(sizeof(PIXEL)*imageRows*imageCols);
 int pids[8];
 char *stack;
 stack = malloc(5000000*8);
 for(i=1;i<8 +1;i++)
 {
  threadID[i-1] = i-1;
  pids[i-1] = clone(processBMP,stack + 5000000*i,0x00000200|0x00000400|0x00000100,(void*)&threadID[i-1]);
 }
 for(j=0;j<8;j++)
 {
  waitpid(pids[j], &status, 0x40000000);
 }
 res=saveBMP(namedest,&imagendst);
 if(res==-1)
 {
  fprintf(stderr,"Error al escribir imagen\n");
  exit(1);
 }
 t_final=clock();
 printf("Tiempo %3.6f segundos\n",((float) t_final- (float)t_inicial)/((__clock_t) 1000000));
}

canonical_original_code:
int main()
{
 int res; int i; int j;
 long t_inicial; long t_final;
 char namedest[80];
 t_inicial=clock();
 strcpy(namedest,strtok(filename,"."));
 strcat(filename,".bmp");
 strcat(namedest,"_P.bmp");
 printf("Archivo fuente %s\n",filename);
 printf("Archivo destino %s\n",namedest);
 res=loadBMP(filename,&imagenfte);
 if(res==-1)
 {
  fprintf(stderr,"Error al abrir imagen\n");
  exit(1);
 }
 printf("Procesando imagen de: Renglones = %d, Columnas = %d\n",imagenfte.infoheader.rows,imagenfte.infoheader.cols);
 printf("Paralelizando usando %i threads\n", 8);
 threadID = (int *) malloc(sizeof(int)*8);
 memcpy(&imagendst, &imagenfte, sizeof(IMAGE)-sizeof(struct PIXEL *));
 int imageRows = (&imagenfte)->infoheader.rows;
 int imageCols = (&imagenfte)->infoheader.cols;
 int status = 0;
 (&imagendst)->pixel=(struct PIXEL *)malloc(sizeof(PIXEL)*imageRows*imageCols);
 int pids[8];
 char *stack;
 stack = malloc(5000000*8);
 for(i=1;i<8 +1;i++)
 {
  threadID[i-1] = i-1;
  pids[i-1] = clone(processBMP,stack + 5000000*i,0x00000200|0x00000400|0x00000100,(void *)&threadID[i-1]);
 }
 for(j=0;j<8;j++)
 {
  waitpid(pids[j], &status, 0x40000000);
 }
 res=saveBMP(namedest,&imagendst);
 if(res==-1)
 {
  fprintf(stderr,"Error al escribir imagen\n");
  exit(1);
 }
 t_final=clock();
 printf("Tiempo %3.6f segundos\n",((float) t_final- (float)t_inicial)/((long) 1000000));
}

variable_types: res int

variable_types:
namedest
char [80]

variable_types: status int

variable_types:
pids
int [8]

variable_types:
stack
char *

user_defined_types: struct PIXEL { unsigned char red; unsigned char green; unsigned char blue; }


ctrlC

repo: JavaIsBad/SyncThread

decompiled_code:
void ctrlC()
{
fini = 1;
}

canonical_decompiled_code:
void func0()
{
fini = 1;
}

original_code:
void ctrlC(int signum){
    fini=0==0;
}

canonical_original_code:
void ctrlC(int signum){
    fini=0==0;
}

variable_types: signum int


erreur

decompiled_code:
void __fastcall __noreturn erreur(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
static inline void erreur(const char* err){
    perror(err);
    exit(1);
}

canonical_original_code:
static inline void erreur(char *err){
    perror(err);
    exit(1);
}

variable_types:
err
char *


randouze

decompiled_code:
__int64 __fastcall randouze(unsigned int *a1)
{
return (unsigned int)(int)(float)((float)((float)rand_r(a1) * 4.6566129e-10) * 255.0);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
return (unsigned int)(int)(float)((float)((float)rand_r(a1) * 4.6566129e-10) * 255.0);
}

original_code:
int randouze(unsigned int *seed){
    return (int) (((float)rand_r(seed)/2147483647)*255);
}

variable_types:
seed
unsigned int *


ajoutbuff

decompiled_code:
int __fastcall ajoutbuff(int a1)
{
int v1; // edx

sem_wait(&ecriture);
sem_wait(&AccesDenied);
v1 = finBuff;
buff[finBuff] = a1;
finBuff = (v1 + 1) % 0xAu;
sem_post(&AccesDenied);
return sem_post(&lecture);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int v1; // edx

sem_wait(&ecriture);
sem_wait(&AccesDenied);
v1 = finBuff;
buff[finBuff] = a1;
finBuff = (v1 + 1) % 0xAu;
sem_post(&AccesDenied);
return sem_post(&lecture);
}

original_code:
void ajoutbuff(int nbr){
    sem_wait(&ecriture);
    sem_wait(&AccesDenied);
    buff[finBuff]=nbr;
    finBuff=(finBuff+1)%10;
    sem_post(&AccesDenied);
    sem_post(&lecture);
}

variable_types: nbr int


retirerbuff

decompiled_code:
__int64 retirerbuff()
{
__int64 v0; // rbx

sem_wait(&lecture);
sem_wait(&AccesDenied2);
v0 = buff[debutBuff];
if ( (_DWORD)v0 == -1 )
sem_post(&lecture);
else
debutBuff = (debutBuff + 1) % 0xAu;
sem_post(&AccesDenied2);
sem_post(&ecriture);
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx

sem_wait(&lecture);
sem_wait(&AccesDenied2);
v0 = buff[debutBuff];
if ( (_DWORD)v0 == -1 )
sem_post(&lecture);
else
debutBuff = (debutBuff + 1) % 0xAu;
sem_post(&AccesDenied2);
sem_post(&ecriture);
return (unsigned int)v0;
}

original_code:
int retirerbuff(){
    int nbr;
    sem_wait(&lecture);
    sem_wait(&AccesDenied2);
    nbr=buff[debutBuff];
    if(nbr!=-1)
        debutBuff=(debutBuff+1)%10;
    else
        sem_post(&lecture);
    sem_post(&AccesDenied2);
    sem_post(&ecriture);
    return nbr;
}


setHandler

decompiled_code:
int __fastcall setHandler(void (*a1)(int), int a2)
{
int result; // eax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a1;
v3.sa_flags = 0;
result = sigfillset(&v3.sa_mask);
if ( !result )
result = sigaction(a2, &v3, 0LL);
return result;
}

canonical_decompiled_code:
int __fastcall func5(void (*a1)(int), int a2)
{
int result; // eax
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a1;
v3.sa_flags = 0;
result = sigfillset(&v3.sa_mask);
if ( !result )
result = sigaction(a2, &v3, 0LL);
return result;
}

original_code:
int setHandler(void (*handler)(int), int signum){
    struct sigaction s;
    int retfunct;
    s.__sigaction_handler.sa_handler=handler;
    s.sa_flags=0;
    retfunct=sigfillset(&s.sa_mask);
    if(retfunct==0)
        retfunct=sigaction(signum, &s, ((void *)0));
    return retfunct;
}

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: retfunct int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
void *v7; // rax
void *v8; // r15
pthread_t *v9; // r12
pthread_t *v10; // rbp
__int64 v11; // r13
unsigned int v12; // er12
pthread_t *v13; // rbx
__int64 v14; // rbp
unsigned int v15; // ebx
int v16; // er14
int v17; // er14
int v18; // er14
pthread_t *newthread; // [rsp+0h] [rbp-58h]
pthread_t *newthreada; // [rsp+0h] [rbp-58h]
int v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+Ch] [rbp-4Ch]
void *thread_return[8]; // [rsp+18h] [rbp-40h] BYREF

if ( setHandler((void (*)(int))ctrlC, 2) )
erreur("Impossible de creer le handler pour ^C");
if ( argc != 3 )
{
fprintf(
stderr,
"Utilisation : %s nbr_producteurs nbr_consommateurs\n0<=nbr_producteurs et 1<=nbr_consommateurs",
*argv);
exit(1);
}
v23 = atoi(argv[1]);
v22 = atoi(argv[2]);
if ( v22 <= 0 || v23 < 0 )
{
*_errno_location() = 22;
erreur("Le nombre de consommateurs doit etre d'au moins 1 et il doit y avoir au minimum 0 producteurs");
}
v3 = sem_init(&AccesDenied, 0, 1u);
v4 = sem_init(&AccesDenied2, 0, 1u) + v3;
v5 = sem_init(&lecture, 0, 0) + v4;
v6 = sem_init(&ecriture, 0, 0xAu) + v5;
if ( v6 )
erreur("sem_init");
newthread = (pthread_t *)malloc(8LL * v23);
v7 = malloc(8LL * v22);
v8 = v7;
if ( !newthread || !v7 )
{
perror("malloc");
if ( newthread )
free(newthread);
if ( v8 )
free(v8);
exit(1);
}
if ( v23 )
{
v9 = newthread;
do
{
if ( pthread_create(v9, 0LL, (void *(*)(void *))producteur, 0LL) )
LABEL_25:
erreur("pthread_create");
++v9;
}
while ( v9 != &newthread[v23] );
}
v10 = (pthread_t *)v8;
do
{
if ( pthread_create(v10, 0LL, (void *(*)(void *))consommateur, 0LL) )
goto LABEL_25;
++v6;
++v10;
}
while ( v22 > v6 );
if ( v23 )
{
v11 = 0LL;
v12 = 0;
v13 = newthread;
do
{
if ( pthread_join(*v13, thread_return) )
LABEL_26:
erreur("pthread_join");
++v13;
v12 += *(_DWORD *)thread_return[0];
v11 += *((_QWORD *)thread_return[0] + 1);
free(thread_return[0]);
}
while ( &newthread[v23] != v13 );
}
else
{
v11 = 0LL;
v12 = 0;
}
v14 = 0LL;
v15 = 0;
puts("\nFin prod");
free(newthread);
ajoutbuff(-1);
newthreada = 0LL;
do
{
if ( pthread_join(*((_QWORD *)v8 + v14), thread_return) )
goto LABEL_26;
++v14;
v15 += *(_DWORD *)thread_return[0];
newthreada = (pthread_t *)((char *)newthreada + *((_QWORD *)thread_return[0] + 1));
free(thread_return[0]);
}
while ( v22 > (int)v14 );
puts("Fin conso");
free(v8);
v16 = sem_destroy(&AccesDenied);
v17 = sem_destroy(&AccesDenied2) + v16;
v18 = sem_destroy(&lecture) + v17;
if ( sem_destroy(&ecriture) + v18 )
erreur("sem_destroy");
printf(format, (unsigned int)v23, v12, v11, (unsigned int)v22, v15, newthreada);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
void *v7; // rax
void *v8; // r15
pthread_t *v9; // r12
pthread_t *v10; // rbp
__int64 v11; // r13
unsigned int v12; // er12
pthread_t *v13; // rbx
__int64 v14; // rbp
unsigned int v15; // ebx
int v16; // er14
int v17; // er14
int v18; // er14
pthread_t *newthread; // [rsp+0h] [rbp-58h]
pthread_t *newthreada; // [rsp+0h] [rbp-58h]
int v22; // [rsp+8h] [rbp-50h]
int v23; // [rsp+Ch] [rbp-4Ch]
void *thread_return[8]; // [rsp+18h] [rbp-40h] BYREF

if ( func5((void (*)(int))ctrlC, 2) )
func1("Impossible de creer le handler pour ^C");
if ( argc != 3 )
{
fprintf(
stderr,
"Utilisation : %s nbr_producteurs nbr_consommateurs\n0<=nbr_producteurs et 1<=nbr_consommateurs",
*argv);
exit(1);
}
v23 = atoi(argv[1]);
v22 = atoi(argv[2]);
if ( v22 <= 0 || v23 < 0 )
{
*_errno_location() = 22;
func1("Le nombre de consommateurs doit etre d'au moins 1 et il doit y avoir au minimum 0 producteurs");
}
v3 = sem_init(&AccesDenied, 0, 1u);
v4 = sem_init(&AccesDenied2, 0, 1u) + v3;
v5 = sem_init(&lecture, 0, 0) + v4;
v6 = sem_init(&ecriture, 0, 0xAu) + v5;
if ( v6 )
func1("sem_init");
newthread = (pthread_t *)malloc(8LL * v23);
v7 = malloc(8LL * v22);
v8 = v7;
if ( !newthread || !v7 )
{
perror("malloc");
if ( newthread )
free(newthread);
if ( v8 )
free(v8);
exit(1);
}
if ( v23 )
{
v9 = newthread;
do
{
if ( pthread_create(v9, 0LL, (void *(*)(void *))producteur, 0LL) )
LABEL_25:
func1("pthread_create");
++v9;
}
while ( v9 != &newthread[v23] );
}
v10 = (pthread_t *)v8;
do
{
if ( pthread_create(v10, 0LL, (void *(*)(void *))consommateur, 0LL) )
goto LABEL_25;
++v6;
++v10;
}
while ( v22 > v6 );
if ( v23 )
{
v11 = 0LL;
v12 = 0;
v13 = newthread;
do
{
if ( pthread_join(*v13, thread_return) )
LABEL_26:
func1("pthread_join");
++v13;
v12 += *(_DWORD *)thread_return[0];
v11 += *((_QWORD *)thread_return[0] + 1);
free(thread_return[0]);
}
while ( &newthread[v23] != v13 );
}
else
{
v11 = 0LL;
v12 = 0;
}
v14 = 0LL;
v15 = 0;
puts("\nFin prod");
free(newthread);
func3(-1);
newthreada = 0LL;
do
{
if ( pthread_join(*((_QWORD *)v8 + v14), thread_return) )
goto LABEL_26;
++v14;
v15 += *(_DWORD *)thread_return[0];
newthreada = (pthread_t *)((char *)newthreada + *((_QWORD *)thread_return[0] + 1));
free(thread_return[0]);
}
while ( v22 > (int)v14 );
puts("Fin conso");
free(v8);
v16 = sem_destroy(&AccesDenied);
v17 = sem_destroy(&AccesDenied2) + v16;
v18 = sem_destroy(&lecture) + v17;
if ( sem_destroy(&ecriture) + v18 )
func1("sem_destroy");
printf(format, (unsigned int)v23, v12, v11, (unsigned int)v22, v15, newthreada);
return 0;
}

original_code:
int main (int argc, char ** argv){
    int nbprod=0, nbconso=0;
    unsigned int prodAproduit=0, consoAmanger=0;
    unsigned long int sommeProd=0, sommeMiam=0;
    int i, retval;
    struct nblu_somme *lu;
    pthread_t *prod, *conso;
    retval=setHandler(ctrlC, 2);
    if(retval!=0)
        erreur("Impossible de creer le handler pour ^C");
    if(argc != 3){
        fprintf(stderr,"Utilisation : %s nbr_producteurs nbr_consommateurs\n0<=nbr_producteurs et 1<=nbr_consommateurs",argv[0]);
        exit(1);
    }
    nbprod=atoi(argv[1]);
    nbconso=atoi(argv[2]);
    if(nbconso==0 || nbconso<0 || nbprod<0){
        (*__errno_location ())=22;
        erreur("Le nombre de consommateurs doit etre d'au moins 1 et il doit y avoir au minimum 0 producteurs");
    }
    retval=sem_init(&AccesDenied, 0, 1);
    retval+=sem_init(&AccesDenied2, 0, 1);
    retval+=sem_init(&lecture, 0, 0);
    retval+=sem_init(&ecriture, 0, 10);
    if(retval!=0)
        erreur("sem_init");
    prod=(pthread_t *) malloc(nbprod*sizeof(pthread_t));
    conso=(pthread_t *) malloc(nbconso*sizeof(pthread_t));
    if(prod==((void *)0) || conso==((void *)0)){
        perror("malloc");
        if(prod!=((void *)0))
            free(prod);
        if(conso!=((void *)0))
            free(conso);
        exit(1);
    }
    for(i=0; i<nbprod; i++){
        retval=pthread_create(&prod[i], ((void *)0), producteur, ((void *)0));
        if(retval!=0)
            erreur("pthread_create");
    }
    for(i=0; i<nbconso; i++){
        retval=pthread_create(&conso[i], ((void *)0), consommateur, ((void *)0));
        if(retval!=0)
            erreur("pthread_create");
    }
    for(i=0; i<nbprod; i++){
        retval=pthread_join(prod[i], (void**) &lu);
        if(retval!=0)
            erreur("pthread_join");
        prodAproduit+=lu->nblu;
        sommeProd+=lu->total;
        free(lu);
    }
    printf("\nFin prod\n");
    free(prod);
    ajoutbuff(-1);
    for(i=0; i<nbconso; i++){
        retval=pthread_join(conso[i], (void**) &lu);
        if(retval!=0)
            erreur("pthread_join");
        consoAmanger+=lu->nblu;
        sommeMiam+=lu->total;
        free(lu);
    }
    printf("Fin conso\n");
    free(conso);
    retval=sem_destroy(&AccesDenied);
    retval+=sem_destroy(&AccesDenied2);
    retval+=sem_destroy(&lecture);
    retval+=sem_destroy(&ecriture);
    if(retval!=0)
        erreur("sem_destroy");
    printf("Les %d producteurs ont produit %d            valeurs pour une somme de %ld.\n            Les %d consommateurs ont consommés %d            valeurs pour une somme de %ld.\n",
            nbprod, prodAproduit, sommeProd,
            nbconso, consoAmanger, sommeMiam);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    int nbprod = 0; int nbconso = 0;
    unsigned int prodAproduit = 0; unsigned int consoAmanger = 0;
    unsigned long sommeProd = 0; unsigned long sommeMiam = 0;
    int i; int retval;
    struct nblu_somme *lu;
    unsigned long *prod; unsigned long *conso;
    retval=setHandler(ctrlC, 2);
    if(retval!=0)
        erreur("Impossible de creer le handler pour ^C");
    if(argc != 3){
        fprintf(stderr,"Utilisation : %s nbr_producteurs nbr_consommateurs\n0<=nbr_producteurs et 1<=nbr_consommateurs",argv[0]);
        exit(1);
    }
    nbprod=atoi(argv[1]);
    nbconso=atoi(argv[2]);
    if(nbconso==0 || nbconso<0 || nbprod<0){
        (*__errno_location ())=22;
        erreur("Le nombre de consommateurs doit etre d'au moins 1 et il doit y avoir au minimum 0 producteurs");
    }
    retval=sem_init(&AccesDenied, 0, 1);
    retval+=sem_init(&AccesDenied2, 0, 1);
    retval+=sem_init(&lecture, 0, 0);
    retval+=sem_init(&ecriture, 0, 10);
    if(retval!=0)
        erreur("sem_init");
    prod=(unsigned long *) malloc(nbprod*sizeof(pthread_t));
    conso=(unsigned long *) malloc(nbconso*sizeof(pthread_t));
    if(prod==((void *)0) || conso==((void *)0)){
        perror("malloc");
        if(prod!=((void *)0))
            free(prod);
        if(conso!=((void *)0))
            free(conso);
        exit(1);
    }
    for(i=0; i<nbprod; i++){
        retval=pthread_create(&prod[i], ((void *)0), producteur, ((void *)0));
        if(retval!=0)
            erreur("pthread_create");
    }
    for(i=0; i<nbconso; i++){
        retval=pthread_create(&conso[i], ((void *)0), consommateur, ((void *)0));
        if(retval!=0)
            erreur("pthread_create");
    }
    for(i=0; i<nbprod; i++){
        retval=pthread_join(prod[i], (void **) &lu);
        if(retval!=0)
            erreur("pthread_join");
        prodAproduit+=lu->nblu;
        sommeProd+=lu->total;
        free(lu);
    }
    printf("\nFin prod\n");
    free(prod);
    ajoutbuff(-1);
    for(i=0; i<nbconso; i++){
        retval=pthread_join(conso[i], (void **) &lu);
        if(retval!=0)
            erreur("pthread_join");
        consoAmanger+=lu->nblu;
        sommeMiam+=lu->total;
        free(lu);
    }
    printf("Fin conso\n");
    free(conso);
    retval=sem_destroy(&AccesDenied);
    retval+=sem_destroy(&AccesDenied2);
    retval+=sem_destroy(&lecture);
    retval+=sem_destroy(&ecriture);
    if(retval!=0)
        erreur("sem_destroy");
    printf("Les %d producteurs ont produit %d            valeurs pour une somme de %ld.\n            Les %d consommateurs ont consommés %d            valeurs pour une somme de %ld.\n",
            nbprod, prodAproduit, sommeProd,
            nbconso, consoAmanger, sommeMiam);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: nbprod int

variable_types: nbconso int

variable_types:
prodAproduit
unsigned int

variable_types:
consoAmanger
unsigned int

variable_types:
sommeProd
unsigned long

variable_types:
sommeMiam
unsigned long

variable_types: i int

variable_types: retval int

variable_types: struct nblu_somme { unsigned int nblu; unsigned long total; } *

variable_types:
prod
unsigned long *

variable_types:
conso
unsigned long *


Ninit

repo: Jeanhwea/Compiler

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

nspacelen = 1;
result = 74LL;
strcpy(nspace, "J");
return result;
}

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

nspacelen = 1;
result = 74LL;
strcpy(nspace, "J");
return result;
}

original_code:
void Ninit(void)
{
 strcpy(nspace,"J");
 nspacelen = strlen(nspace);
}

canonical_original_code:
void Ninit()
{
 strcpy(nspace,"J");
 nspacelen = strlen(nspace);
}


Npush

decompiled_code:
__int64 __fastcall Npush(char *src)
{
size_t v1; // rax
__int64 result; // rax

v1 = strlen(nspace);
nspace[v1] = 95;
result = stpcpy(&nspace[v1 + 1], src) - nspace;
nspacelen = result;
return result;
}

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

v1 = strlen(nspace);
nspace[v1] = 95;
result = stpcpy(&nspace[v1 + 1], src) - nspace;
nspacelen = result;
return result;
}

original_code:
void Npush(char *name)
{
 strcat(nspace,"_");
 strcat(nspace, name);
 nspacelen = strlen(nspace);
}

variable_types:
name
char *


Npop

decompiled_code:
__int64 Npop()
{
__int64 v0; // rax

LODWORD(v0) = nspacelen - 1;
if ( nspacelen - 1 < 0 )
return 0LL;
v0 = (int)v0;
while ( nspace[v0] != 95 )
{
if ( (int)--v0 < 0 )
return 0LL;
}
nspace[(int)v0] = 0;
nspacelen = strlen(nspace);
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax

LODWORD(v0) = nspacelen - 1;
if ( nspacelen - 1 < 0 )
return 0LL;
v0 = (int)v0;
while ( nspace[v0] != 95 )
{
if ( (int)--v0 < 0 )
return 0LL;
}
nspace[(int)v0] = 0;
nspacelen = strlen(nspace);
return 1LL;
}

original_code:
BOOL Npop(void)
{
 int i;
 for (i = nspacelen - 1; i >= 0; i--) {
  if (nspace[i] == '_') {
   nspace[i] = '\0';
   nspacelen = strlen(nspace);
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int Npop()
{
 int i;
 for (i = nspacelen - 1; i >= 0; i--) {
  if (nspace[i] == '_') {
   nspace[i] = '\0';
   nspacelen = strlen(nspace);
   return 1;
  }
 }
 return 0;
}


Nappend

decompiled_code:
char *__fastcall Nappend(void *src)
{
size_t v1; // rbx
char *v2; // rax
char *v3; // r12
char *v4; // rax

if ( !src )
return 0LL;
v1 = strlen((const char *)src);
v2 = (char *)malloc((int)v1 + nspacelen + 2);
v3 = v2;
if ( v2 )
{
v4 = stpcpy(v2, nspace);
*v4 = 95;
memcpy(v4 + 1, src, v1 + 1);
}
else
{
fwrite("OUTOFMEM: in Nappend\n", 1uLL, 0x15uLL, errlist);
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(void *src)
{
size_t v1; // rbx
char *v2; // rax
char *v3; // r12
char *v4; // rax

if ( !src )
return 0LL;
v1 = strlen((const char *)src);
v2 = (char *)malloc((int)v1 + nspacelen + 2);
v3 = v2;
if ( v2 )
{
v4 = stpcpy(v2, nspace);
*v4 = 95;
memcpy(v4 + 1, src, v1 + 1);
}
else
{
fwrite("OUTOFMEM: in Nappend\n", 1uLL, 0x15uLL, errlist);
}
return v3;
}

original_code:
char *Nappend(char *name)
{
 int n;
 char *t;
 if (name == ((void *)0)) {
  return ((void *)0);
 }
 n = strlen(name);
 t = (char *) malloc((n+nspacelen+2)*sizeof(char));
 if (t == ((void *)0)) {
  fprintf(errlist, "OUTOFMEM: in Nappend\n");
  return ((void *)0);
 }
 strcpy(t, nspace);
 strcat(t, "_");
 strcat(t, name);
 return t;
}

variable_types: n int

variable_types:
t
char *

return_type: char *