repo: Braedon/rain

decompiled_code:
int screen_init()
{
mainwnd = initscr();
noecho();
cbreak();
nodelay(mainwnd, 1);
wrefresh(_bss_start);
return wrefresh(mainwnd);
}

canonical_decompiled_code:
int func7()
{
mainwnd = initscr();
noecho();
cbreak();
nodelay(mainwnd, 1);
wrefresh(_bss_start);
return wrefresh(mainwnd);
}

original_code:
void screen_init(void) {
  mainwnd = initscr();
  noecho();
  cbreak();
  nodelay(mainwnd, 1);
  wrefresh(stdscr);
  wrefresh(mainwnd);
}

canonical_original_code:
void screen_init() {
  mainwnd = initscr();
  noecho();
  cbreak();
  nodelay(mainwnd, 1);
  wrefresh(stdscr);
  wrefresh(mainwnd);
}

return_type: void


updateSize

decompiled_code:
__int64 __fastcall updateSize(int a1, int a2)
{
__int64 result; // rax
__int64 v4; // rbx
int v5; // ebp
int v6; // edx
__int64 v7; // rax
_QWORD *v8; // rax
void *v9; // rdi
__int64 v10; // rbx
int v11; // ebp
int v12; // edx
__int64 v13; // rbp
__int64 v14; // rax
void **v15; // r13
void **v16; // r13
int v17; // edx
__int64 i; // rax

result = (unsigned int)cols;
if ( cols == a2 )
{
if ( lines == a1 )
return result;
inputs = a2;
dword_4040F4 = 0;
}
else
{
inputs = a2;
dword_4040F4 = 0;
if ( cols > a2 )
{
v4 = 8LL * a2;
v5 = a2;
do
{
v9 = *(void **)((char *)ptr + v4);
if ( v9 )
free(v9);
++v5;
v4 += 8LL;
}
while ( cols > v5 );
}
}
ptr = realloc(ptr, 8LL * a2);
v6 = cols;
if ( a2 > cols )
{
v7 = 8LL * cols;
do
{
*(_QWORD *)((char *)ptr + v7) = 0LL;
v7 += 8LL;
}
while ( v7 != 8 * (v6 + (unsigned __int64)(unsigned int)(a2 + ~v6) + 1) );
}
if ( a2 > 0 )
{
v8 = ptr;
do
{
if ( *v8 )
++dword_4040F4;
++v8;
}
while ( v8 != (_QWORD *)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
if ( a1 < lines )
{
v10 = 8LL * a1;
v11 = a1;
do
{
free(*(void **)((char *)array + v10));
++v11;
v10 += 8LL;
}
while ( lines > v11 );
}
result = (__int64)realloc(array, 8LL * a1);
array = (void *)result;
v12 = lines;
if ( a1 > lines )
{
result = 8LL * lines;
do
{
*(_QWORD *)((char *)array + result) = 0LL;
result += 8LL;
}
while ( result != 8 * (v12 + (unsigned __int64)(unsigned int)(a1 + ~v12) + 1) );
}
if ( a1 > 0 )
{
v13 = 0LL;
do
{
v15 = (void **)((char *)array + 8 * v13);
*v15 = realloc(*v15, a2 + 1);
v16 = (void **)((char *)array + 8 * v13);
*v16 = realloc(*v16, a2 + 1LL);
v17 = cols;
if ( cols < a2 )
{
v14 = cols;
do
*(_BYTE *)(*((_QWORD *)array + v13) + v14++) = 32;
while ( v17 + (unsigned __int64)(unsigned int)(a2 + ~v17) + 1 != v14 );
}
if ( lines <= (int)v13 && a2 > 0 )
{
for ( i = 0LL; i != a2; *(_BYTE *)(*((_QWORD *)array + v13) + i++) = 32 )
;
}
result = *((_QWORD *)array + v13);
*(_BYTE *)(result + a2) = 0;
++v13;
}
while ( v13 != a1 );
}
lines = a1;
cols = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
__int64 result; // rax
__int64 v4; // rbx
int v5; // ebp
int v6; // edx
__int64 v7; // rax
_QWORD *v8; // rax
void *v9; // rdi
__int64 v10; // rbx
int v11; // ebp
int v12; // edx
__int64 v13; // rbp
__int64 v14; // rax
void **v15; // r13
void **v16; // r13
int v17; // edx
__int64 i; // rax

result = (unsigned int)cols;
if ( cols == a2 )
{
if ( lines == a1 )
return result;
inputs = a2;
dword_4040F4 = 0;
}
else
{
inputs = a2;
dword_4040F4 = 0;
if ( cols > a2 )
{
v4 = 8LL * a2;
v5 = a2;
do
{
v9 = *(void **)((char *)ptr + v4);
if ( v9 )
free(v9);
++v5;
v4 += 8LL;
}
while ( cols > v5 );
}
}
ptr = realloc(ptr, 8LL * a2);
v6 = cols;
if ( a2 > cols )
{
v7 = 8LL * cols;
do
{
*(_QWORD *)((char *)ptr + v7) = 0LL;
v7 += 8LL;
}
while ( v7 != 8 * (v6 + (unsigned __int64)(unsigned int)(a2 + ~v6) + 1) );
}
if ( a2 > 0 )
{
v8 = ptr;
do
{
if ( *v8 )
++dword_4040F4;
++v8;
}
while ( v8 != (_QWORD *)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
if ( a1 < lines )
{
v10 = 8LL * a1;
v11 = a1;
do
{
free(*(void **)((char *)array + v10));
++v11;
v10 += 8LL;
}
while ( lines > v11 );
}
result = (__int64)realloc(array, 8LL * a1);
array = (void *)result;
v12 = lines;
if ( a1 > lines )
{
result = 8LL * lines;
do
{
*(_QWORD *)((char *)array + result) = 0LL;
result += 8LL;
}
while ( result != 8 * (v12 + (unsigned __int64)(unsigned int)(a1 + ~v12) + 1) );
}
if ( a1 > 0 )
{
v13 = 0LL;
do
{
v15 = (void **)((char *)array + 8 * v13);
*v15 = realloc(*v15, a2 + 1);
v16 = (void **)((char *)array + 8 * v13);
*v16 = realloc(*v16, a2 + 1LL);
v17 = cols;
if ( cols < a2 )
{
v14 = cols;
do
*(_BYTE *)(*((_QWORD *)array + v13) + v14++) = 32;
while ( v17 + (unsigned __int64)(unsigned int)(a2 + ~v17) + 1 != v14 );
}
if ( lines <= (int)v13 && a2 > 0 )
{
for ( i = 0LL; i != a2; *(_BYTE *)(*((_QWORD *)array + v13) + i++) = 32 )
;
}
result = *((_QWORD *)array + v13);
*(_BYTE *)(result + a2) = 0;
++v13;
}
while ( v13 != a1 );
}
lines = a1;
cols = a2;
return result;
}

original_code:
void updateSize(int newLines, int newCols) {
  int i, j;
  if (cols != newCols || lines != newLines) {
    inputs.width = newCols;
    inputs.full = 0;
    for (j = newCols; j < cols; j++) {
      if (inputs.inputs[j] != ((void *)0)) {
        free(inputs.inputs[j]);
      }
    }
    inputs.inputs = (struct Input**) realloc(inputs.inputs, sizeof(struct Inputs*) * newCols);
    for (j = cols; j < newCols; j++) {
      inputs.inputs[j] = ((void *)0);
    }
    for (j = 0; j < newCols; j++) {
      if (inputs.inputs[j] != ((void *)0)) {
        inputs.full++;
      }
    }
    for (i = newLines; i < lines; i++) {
      free(array[i]);
    }
    array = (char**) realloc(array, sizeof(char*) * newLines);
    for (i = lines; i < newLines; i++) {
      array[i] = ((void *)0);
    }
    for (i = 0; i < newLines; i++) {
      array[i] = (char*) realloc(array[i], sizeof(char) * (newCols + 1));
      array[i] = (char*) realloc(array[i], sizeof(char) * newCols + 1);
      if (newCols > cols) {
        for (j = cols; j < newCols; j++) {
          array[i][j] = ' ';
        }
      }
      if (i >= lines ) {
        for (j = 0; j < newCols; j++) {
          array[i][j] = ' ';
        }
      }
      array[i][newCols] = '\0';
    }
    lines = newLines;
    cols = newCols;
  }
}

canonical_original_code:
void updateSize(int newLines, int newCols) {
  int i; int j;
  if (cols != newCols || lines != newLines) {
    inputs.width = newCols;
    inputs.full = 0;
    for (j = newCols; j < cols; j++) {
      if (inputs.inputs[j] != ((void *)0)) {
        free(inputs.inputs[j]);
      }
    }
    inputs.inputs = (struct Input **) realloc(inputs.inputs, sizeof(struct Inputs *) * newCols);
    for (j = cols; j < newCols; j++) {
      inputs.inputs[j] = ((void *)0);
    }
    for (j = 0; j < newCols; j++) {
      if (inputs.inputs[j] != ((void *)0)) {
        inputs.full++;
      }
    }
    for (i = newLines; i < lines; i++) {
      free(array[i]);
    }
    array = (char **) realloc(array, sizeof(char *) * newLines);
    for (i = lines; i < newLines; i++) {
      array[i] = ((void *)0);
    }
    for (i = 0; i < newLines; i++) {
      array[i] = (char *) realloc(array[i], sizeof(char) * (newCols + 1));
      array[i] = (char *) realloc(array[i], sizeof(char) * newCols + 1);
      if (newCols > cols) {
        for (j = cols; j < newCols; j++) {
          array[i][j] = ' ';
        }
      }
      if (i >= lines ) {
        for (j = 0; j < newCols; j++) {
          array[i][j] = ' ';
        }
      }
      array[i][newCols] = '\0';
    }
    lines = newLines;
    cols = newCols;
  }
}

variable_types: newLines int

variable_types: newCols int

variable_types: i int

variable_types: j int

user_defined_types: struct Inputs { int width; int full; struct Input **inputs; }

user_defined_types: struct Input { int currVal; char str[256]; }


shiftAndPrint

decompiled_code:
int shiftAndPrint()
{
__int64 v0; // r12
int v1; // ebp
__int64 v2; // rbx
__int64 v3; // rbx
int *v4; // rdi

v0 = *((_QWORD *)array + lines - 1);
v1 = lines - 1;
if ( lines - 1 > 0 )
{
v2 = 8LL * v1;
do
{
*(_QWORD *)((char *)array + v2) = *(_QWORD *)((char *)array + v2 - 8);
mvwprintw(mainwnd, v1, 0, "%s", *(const char **)((char *)array + v2));
v2 -= 8LL;
--v1;
}
while ( v1 );
}
*(_QWORD *)array = v0;
if ( cols > 0 )
{
v3 = 0LL;
do
{
v4 = (int *)*((_QWORD *)ptr + v3);
if ( v4 )
{
if ( *v4 < 0 )
{
free(v4);
*((_QWORD *)ptr + v3) = 0LL;
--dword_4040F4;
*(_BYTE *)(*(_QWORD *)array + v3) = 32;
}
else
{
*(_BYTE *)(*(_QWORD *)array + v3) = *((_BYTE *)v4 + (*v4)-- + 4);
}
}
else
{
*(_BYTE *)(*(_QWORD *)array + v3) = 32;
}
++v3;
}
while ( cols > (int)v3 );
}
return mvwprintw(mainwnd, 0, 0, "%s", *(const char **)array);
}

canonical_decompiled_code:
int func9()
{
__int64 v0; // r12
int v1; // ebp
__int64 v2; // rbx
__int64 v3; // rbx
int *v4; // rdi

v0 = *((_QWORD *)array + lines - 1);
v1 = lines - 1;
if ( lines - 1 > 0 )
{
v2 = 8LL * v1;
do
{
*(_QWORD *)((char *)array + v2) = *(_QWORD *)((char *)array + v2 - 8);
mvwprintw(mainwnd, v1, 0, "%s", *(const char **)((char *)array + v2));
v2 -= 8LL;
--v1;
}
while ( v1 );
}
*(_QWORD *)array = v0;
if ( cols > 0 )
{
v3 = 0LL;
do
{
v4 = (int *)*((_QWORD *)ptr + v3);
if ( v4 )
{
if ( *v4 < 0 )
{
free(v4);
*((_QWORD *)ptr + v3) = 0LL;
--dword_4040F4;
*(_BYTE *)(*(_QWORD *)array + v3) = 32;
}
else
{
*(_BYTE *)(*(_QWORD *)array + v3) = *((_BYTE *)v4 + (*v4)-- + 4);
}
}
else
{
*(_BYTE *)(*(_QWORD *)array + v3) = 32;
}
++v3;
}
while ( cols > (int)v3 );
}
return mvwprintw(mainwnd, 0, 0, "%s", *(const char **)array);
}

original_code:
void shiftAndPrint() {
  int i, j;
  struct Input* input;
  char* bottomRow;
  bottomRow = array[lines - 1];
  for (i = lines - 1; i > 0; i--) {
    array[i] = array[i - 1];
    mvwprintw(mainwnd,i, 0,"%s", array[i]);
  }
  array[0] = bottomRow;
  for (j = 0; j < cols; j++) {
    if (inputs.inputs[j] == ((void *)0)) {
      array[0][j] = ' ';
    } else {
      input = inputs.inputs[j];
      if (input->currVal < 0) {
        free(input);
        inputs.inputs[j] = ((void *)0);
        inputs.full--;
        array[0][j] = ' ';
      } else {
        array[0][j] = input->str[input->currVal];
        input->currVal--;
      }
    }
  }
  mvwprintw(mainwnd,0, 0,"%s", array[0]);
}

canonical_original_code:
void shiftAndPrint() {
  int i; int j;
  struct Input *input;
  char *bottomRow;
  bottomRow = array[lines - 1];
  for (i = lines - 1; i > 0; i--) {
    array[i] = array[i - 1];
    mvwprintw(mainwnd,i, 0,"%s", array[i]);
  }
  array[0] = bottomRow;
  for (j = 0; j < cols; j++) {
    if (inputs.inputs[j] == ((void *)0)) {
      array[0][j] = ' ';
    } else {
      input = inputs.inputs[j];
      if (input->currVal < 0) {
        free(input);
        inputs.inputs[j] = ((void *)0);
        inputs.full--;
        array[0][j] = ' ';
      } else {
        array[0][j] = input->str[input->currVal];
        input->currVal--;
      }
    }
  }
  mvwprintw(mainwnd,0, 0,"%s", array[0]);
}

variable_types: struct Input { int currVal; char str[256]; } *

variable_types:
bottomRow
char *


decompiled_code:
int update_display()
{
curs_set(0);
shiftAndPrint();
wrefresh(mainwnd);
return wrefresh(_bss_start);
}

canonical_decompiled_code:
int func10()
{
curs_set(0);
func9();
wrefresh(mainwnd);
return wrefresh(_bss_start);
}

original_code:
static void update_display(void) {
  int i, j;
  curs_set(0);
  shiftAndPrint();
  wrefresh(mainwnd);
  wrefresh(stdscr);
}

canonical_original_code:
static void update_display() {
  int i; int j;
  curs_set(0);
  shiftAndPrint();
  wrefresh(mainwnd);
  wrefresh(stdscr);
}


decompiled_code:
int screen_end()
{
return endwin();
}

canonical_decompiled_code:
int func11()
{
return endwin();
}

original_code:
void screen_end(void) {
  endwin();
}

canonical_original_code:
void screen_end() {
  endwin();
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int i; // er12
int v5; // ebp
char *v6; // r13
int v7; // edx
char **j; // rax
char v9[296]; // [rsp+0h] [rbp-128h] BYREF

screen_init();
while ( 1 )
{
updateSize(LINES__NCURSES6_TINFO_5_0_19991023, COLS__NCURSES6_TINFO_5_0_19991023);
if ( dword_4040F4 < inputs )
{
v5 = rand() % ((inputs - dword_4040F4) / (inputs / 4));
if ( v5 > 0 )
{
for ( i = 0; i != v5; ++i )
{
v3 = wgetnstr(_bss_start, v9, 255);
if ( !v3 )
{
v6 = (char *)malloc(0x104uLL);
strcpy(v6 + 4, v9);
*(_DWORD *)v6 = strlen(v6 + 4) - 1;
v7 = rand() % (inputs - dword_4040F4);
if ( inputs > 0 )
{
for ( j = (char **)ptr; j != (char **)((char *)ptr + 8 * (unsigned int)(inputs - 1) + 8); ++j )
{
if ( !*j )
{
if ( v7 == v3 )
{
*j = v6;
++dword_4040F4;
break;
}
++v3;
}
}
}
}
}
}
}
update_display();
nanosleep(&sleepPeriod, 0LL);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int i; // er12
int v5; // ebp
char *v6; // r13
int v7; // edx
char **j; // rax
char v9[296]; // [rsp+0h] [rbp-128h] BYREF

func7();
while ( 1 )
{
func8(LINES__NCURSES6_TINFO_5_0_19991023, COLS__NCURSES6_TINFO_5_0_19991023);
if ( dword_4040F4 < inputs )
{
v5 = rand() % ((inputs - dword_4040F4) / (inputs / 4));
if ( v5 > 0 )
{
for ( i = 0; i != v5; ++i )
{
v3 = wgetnstr(_bss_start, v9, 255);
if ( !v3 )
{
v6 = (char *)malloc(0x104uLL);
strcpy(v6 + 4, v9);
*(_DWORD *)v6 = strlen(v6 + 4) - 1;
v7 = rand() % (inputs - dword_4040F4);
if ( inputs > 0 )
{
for ( j = (char **)ptr; j != (char **)((char *)ptr + 8 * (unsigned int)(inputs - 1) + 8); ++j )
{
if ( !*j )
{
if ( v7 == v3 )
{
*j = v6;
++dword_4040F4;
break;
}
++v3;
}
}
}
}
}
}
}
func10();
nanosleep(&sleepPeriod, 0LL);
}
}

original_code:
int main(void) {
  struct Input* input;
  screen_init();
  int j, a, b, c, d, newx, newy;
  char line[256];
  int readResult;
  while (1) {
    updateSize(LINES, COLS);
    if (inputs.full < inputs.width) {
      d = rand() % (int)((inputs.width - inputs.full) / (inputs.width / 4));
      for (c = 0; c < d; c++) {
        readResult = wgetnstr(stdscr, line, (256 - 1));
        if(readResult == (0)) {
          input = (struct Input*) malloc(sizeof(struct Input));
          strcpy(input->str, line);
          input->currVal = strlen(input->str) - 1;
          b = rand() % (inputs.width - inputs.full);
          a = 0;
          for (j = 0; j < inputs.width; j++) {
            if (inputs.inputs[j] == ((void *)0)) {
              if ( a == b ) {
                inputs.inputs[j] = input;
                inputs.full++;
                break;
              }
              a++;
            }
          }
        }
      }
    }
    update_display();
    nanosleep(&sleepPeriod, ((void *)0));
  }
  screen_end();
  return 0;
}

canonical_original_code:
int main() {
  struct Input *input;
  screen_init();
  int j; int a; int b; int c; int d; int newx; int newy;
  char line[256];
  int readResult;
  while (1) {
    updateSize(LINES, COLS);
    if (inputs.full < inputs.width) {
      d = rand() % (int)((inputs.width - inputs.full) / (inputs.width / 4));
      for (c = 0; c < d; c++) {
        readResult = wgetnstr(stdscr, line, (256 - 1));
        if(readResult == (0)) {
          input = (struct Input *) malloc(sizeof(struct Input));
          strcpy(input->str, line);
          input->currVal = strlen(input->str) - 1;
          b = rand() % (inputs.width - inputs.full);
          a = 0;
          for (j = 0; j < inputs.width; j++) {
            if (inputs.inputs[j] == ((void *)0)) {
              if ( a == b ) {
                inputs.inputs[j] = input;
                inputs.full++;
                break;
              }
              a++;
            }
          }
        }
      }
    }
    update_display();
    nanosleep(&sleepPeriod, ((void *)0));
  }
  screen_end();
  return 0;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: newx int

variable_types: newy int

variable_types:
line
char [256]

variable_types: readResult int

return_type: int


decompiled_code:
__int64 __fastcall deny_service(_QWORD *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
char v6[512]; // [rsp+0h] [rbp-418h] BYREF
char buf[536]; // [rsp+200h] [rbp-218h] BYREF

v2 = open(a2, 0);
if ( v2 == -1 || (v3 = v2, v4 = read(v2, buf, 0x1FFuLL), close(v3), v4 < 0) )
strcpy(v6, "You are not authorized to use this service.\n");
else
strncpy(v6, buf, v4 + 1);
return _display_errmsg(*a1, 1LL, v6, a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
char v6[512]; // [rsp+0h] [rbp-418h] BYREF
char buf[536]; // [rsp+200h] [rbp-218h] BYREF

v2 = open(a2, 0);
if ( v2 == -1 || (v3 = v2, v4 = read(v2, buf, 0x1FFuLL), close(v3), v4 < 0) )
strcpy(v6, "You are not authorized to use this service.\n");
else
strncpy(v6, buf, v4 + 1);
return _display_errmsg(*a1, 1LL, v6, a1[1]);
}

original_code:
void deny_service(
 struct pam_conv *c,
 char *file)
{
 int fd;
 int n;
 int usedefault = 0;
 char buf[512];
 char messages[1][512];
 if ((fd = open(file,00)) == -1) {
  usedefault = 1;
 }
 else {
  n = read(fd,buf,512 -1);
  close(fd);
 }
 if (n >= 0 && !usedefault) {
  strncpy(messages[0],buf,n+1);
 }
 else {
  strncpy(messages[0],"You are not authorized to use this service.\n",strlen("You are not authorized to use this service.\n")+1);
 }
 __display_errmsg(c->conv,1,&messages[0],c->appdata_ptr);
}

canonical_original_code:
void deny_service(struct pam_conv *c, char *file)
{
 int fd;
 int n;
 int usedefault = 0;
 char buf[512];
 char messages[1][512];
 if ((fd = open(file,00)) == -1) {
  usedefault = 1;
 }
 else {
  n = read(fd,buf,512 -1);
  close(fd);
 }
 if (n >= 0 && !usedefault) {
  strncpy(messages[0],buf,n+1);
 }
 else {
  strncpy(messages[0],"You are not authorized to use this service.\n",strlen("You are not authorized to use this service.\n")+1);
 }
 __display_errmsg(c->conv,1,&messages[0],c->appdata_ptr);
}

variable_types: struct pam_conv { int (*conv)(int num_msg, struct pam_message { int msg_style; char *msg; } **msg, struct pam_response { char *resp; int resp_retcode; } **resp, void *appdata_ptr); void *appdata_ptr; } *

variable_types:
file
char *

variable_types: fd int

variable_types: n int

variable_types: usedefault int

variable_types:
buf
char [512]

variable_types:
messages
char [1][512]

user_defined_types: struct pam_conv { int (*conv)(int num_msg, struct pam_message **msg, struct pam_response **resp, void *appdata_ptr); void *appdata_ptr; }


msg

repo: CheezeCake/TPs-Prog-systeme

decompiled_code:
void __fastcall msg(int a1)
{
sleep(1u);
if ( a1 == 10 )
{
while ( kill(p2, 12) == -1 )
;
}
else
{
while ( kill(p1, 10) == -1 )
;
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
sleep(1u);
if ( a1 == 10 )
{
while ( kill(p2, 12) == -1 )
;
}
else
{
while ( kill(p1, 10) == -1 )
;
}
}

original_code:
void msg(int sig)
{
 sleep(1);
 if(sig == 10)
  while(kill(p2, 12) == -1);
 else
  while(kill(p1, 10) == -1);
}

variable_types: sig int


quit

decompiled_code:
void __noreturn quit()
{
kill(p1, 9);
wait(0LL);
kill(p2, 9);
wait(0LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
kill(p1, 9);
wait(0LL);
kill(p2, 9);
wait(0LL);
exit(0);
}

original_code:
void quit(int sig)
{
 kill(p1, 9);
 wait(((void *)0));
 kill(p2, 9);
 wait(((void *)0));
 exit(0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__pid_t v4; // eax
__pid_t v5; // eax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

signal(10, msg);
signal(12, msg);
signal(2, (__sighandler_t)quit);
signal(14, (__sighandler_t)quit);
if ( argc == 3 )
{
v3 = getpid();
sprintf(s, "%d", v3);
v4 = fork();
p1 = v4;
if ( v4 != -1 )
{
if ( v4 )
{
v5 = fork();
p2 = v5;
if ( v5 != -1 )
{
if ( v5 )
{
while ( 1 )
pause();
}
execl(argv[2], argv[2], s, 0LL);
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "Erreur exec %s: %s\n", argv[2], v9);
kill(p1, 9);
exit(1);
}
perror("fork");
kill(p1, 9);
exit(1);
}
execl(argv[1], argv[1], s, 0LL);
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(_bss_start, "Erreur exec %s: %s\n", argv[1], v7);
exit(1);
}
perror("fork");
exit(1);
}
fwrite("mauvais nombre d'arguments\nexercice4-3 prog1 prog2\n", 1uLL, 0x33uLL, _bss_start);
return 1;
}

original_code:
int main(int argc, char **argv)
{
 char pid[10];
 signal(10, msg);
 signal(12, msg);
 signal(2, quit);
 signal(14, quit);
 if(argc != 3)
 {
  fprintf(stderr, "mauvais nombre d'arguments\n"
    "exercice4-3 prog1 prog2\n");
  return 1;
 }
 sprintf(pid, "%d", getpid());
 switch((p1 = fork()))
 {
  case -1:
   perror("fork");
   exit(1);
   break;
  case 0:
   execl(argv[1], argv[1], pid, ((void *)0));
   fprintf(stderr, "Erreur exec %s: %s\n", argv[1], strerror((*__errno_location ())));
   exit(1);
   break;
 }
 switch((p2 = fork()))
 {
  case -1:
   perror("fork");
   kill(p1, 9);
   exit(1);
   break;
  case 0:
   execl(argv[2], argv[2], pid, ((void *)0));
   fprintf(stderr, "Erreur exec %s: %s\n", argv[2], strerror((*__errno_location ())));
   kill(p1, 9);
   exit(1);
 }
 while(1)
  pause();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
pid
char [10]


decompiled_code:
char *get_homedir()
{
char *v0; // rbx
__uid_t v2; // eax
struct passwd *v3; // rax

v0 = getenv("HOME");
if ( !v0 )
{
v2 = getuid();
v3 = getpwuid(v2);
v0 = (char *)v3;
if ( v3 )
v0 = v3->pw_dir;
else
fwrite("Who are you? Not found in passwd database!!\n", 1uLL, 0x2CuLL, stderr);
}
return v0;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rbx
__uid_t v2; // eax
struct passwd *v3; // rax

v0 = getenv("HOME");
if ( !v0 )
{
v2 = getuid();
v3 = getpwuid(v2);
v0 = (char *)v3;
if ( v3 )
v0 = v3->pw_dir;
else
fwrite("Who are you? Not found in passwd database!!\n", 1uLL, 0x2CuLL, stderr);
}
return v0;
}

original_code:
char *get_homedir(void)
{
 struct passwd *pw;
 char *home;
 home = getenv("HOME");
 if (home)
  return home;
 if (!(pw = getpwuid(getuid())))
 {
  fprintf(stderr, "Who are you? Not found in passwd database!!\n");
  return ((void *)0);
 }
 return pw->pw_dir;
}

canonical_original_code:
char *get_homedir()
{
 struct passwd *pw;
 char *home;
 home = getenv("HOME");
 if (home)
  return home;
 if (!(pw = getpwuid(getuid())))
 {
  fprintf(stderr, "Who are you? Not found in passwd database!!\n");
  return ((void *)0);
 }
 return pw->pw_dir;
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
home
char *

return_type: char *


decompiled_code:
int __fastcall check_and_create_dir(char *path)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat(path, &v2);
if ( result )
{
if ( *_errno_location() == 2 )
{
result = mkdir(path, 0x1FDu);
if ( result )
{
fprintf(stderr, "Error creating dir %s", path);
perror(" ");
result = -1;
}
}
else
{
fprintf(stderr, "Error opening %s", path);
perror(" ");
result = -1;
}
}
else if ( (v2.st_mode & 0xF000) != 0x4000 )
{
fprintf(stderr, "Error %s exists but isn't a dir\n", path);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *path)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat(path, &v2);
if ( result )
{
if ( *_errno_location() == 2 )
{
result = mkdir(path, 0x1FDu);
if ( result )
{
fprintf(stderr, "Error creating dir %s", path);
perror(" ");
result = -1;
}
}
else
{
fprintf(stderr, "Error opening %s", path);
perror(" ");
result = -1;
}
}
else if ( (v2.st_mode & 0xF000) != 0x4000 )
{
fprintf(stderr, "Error %s exists but isn't a dir\n", path);
result = -1;
}
return result;
}

original_code:
int check_and_create_dir(const char *name)
{
 struct stat stat_buffer;
 if (stat(name, &stat_buffer))
 {
  if ((*__errno_location ()) == 2)
  {
    if (mkdir(name, (0400|0200|0100)|((0400|0200|0100) >> 3)|((0400 >> 3) >> 3)|((0100 >> 3) >> 3)))
    {
     fprintf(stderr, "Error creating dir %s", name);
     perror(" ");
     return -1;
    }
  }
  else
  {
   fprintf(stderr, "Error opening %s", name);
   perror(" ");
   return -1;
  }
 }
 else
 {
   if (!((((stat_buffer.st_mode)) & 0170000) == (0040000)))
   {
    fprintf(stderr,"Error %s exists but isn't a dir\n", name);
    return -1;
   }
 }
 return 0;
}

canonical_original_code:
int check_and_create_dir(char *name)
{
 struct stat stat_buffer;
 if (stat(name, &stat_buffer))
 {
  if ((*__errno_location ()) == 2)
  {
    if (mkdir(name, (0400|0200|0100)|((0400|0200|0100) >> 3)|((0400 >> 3) >> 3)|((0100 >> 3) >> 3)))
    {
     fprintf(stderr, "Error creating dir %s", name);
     perror(" ");
     return -1;
    }
  }
  else
  {
   fprintf(stderr, "Error opening %s", name);
   perror(" ");
   return -1;
  }
 }
 else
 {
   if (!((((stat_buffer.st_mode)) & 0170000) == (0040000)))
   {
    fprintf(stderr,"Error %s exists but isn't a dir\n", name);
    return -1;
   }
 }
 return 0;
}

variable_types:
name
char *

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

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


FatalError

repo: GreatEmerald/Arcomage-GreatEmerald

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

va_start(arg, a1);
printf(a1);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(3);
}

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

va_start(arg, a1);
printf(a1);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(3);
}

original_code:
void FatalError(char *fmt,...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 printf(fmt);
 vfprintf(stderr,fmt,args);
 fprintf(stderr,"\n");
 __builtin_va_end(args);
 exit(3);
}

canonical_original_code:
void FatalError(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 printf(fmt);
 vfprintf(stderr,fmt,args);
 fprintf(stderr,"\n");
 __builtin_va_end(args);
 exit(3);
}

variable_types:
fmt
char *


OpenWebLink

decompiled_code:
int __fastcall OpenWebLink(const char *a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

snprintf(v2, 0x80uLL, "./browser %s", a1);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

snprintf(v2, 0x80uLL, "./browser %s", a1);
return system(v2);
}

original_code:
void OpenWebLink(char *web)
{
 char cmdline[128];
 snprintf(cmdline,128,"./browser %s",web);
 system(cmdline);
}

variable_types:
web
char *

variable_types:
cmdline
char [128]


repo: JAORMX/TweetRemoteControl

decompiled_code:
void tweetd_sigup_handler()
{
hupReceived = 1;
}

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

original_code:
static void tweetd_sigup_handler(int sig)
{
    hupReceived = 1;
}


decompiled_code:
char *get_string_from_stdin()
{
char *v0; // rax
char *v1; // rbx
char *v2; // rax

v0 = (char *)calloc(0x3E8uLL, 1uLL);
v1 = v0;
if ( v0 )
{
if ( fgets(v0, 999, stdin) )
{
v2 = strchr(v1, 10);
if ( v2 )
*v2 = 0;
}
else
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rax
char *v1; // rbx
char *v2; // rax

v0 = (char *)calloc(0x3E8uLL, 1uLL);
v1 = v0;
if ( v0 )
{
if ( fgets(v0, 999, stdin) )
{
v2 = strchr(v1, 10);
if ( v2 )
*v2 = 0;
}
else
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
static char *get_string_from_stdin(void)
{
    char *temp;
    char *string;
    string = calloc(1000, 1);
    if (!string)
        return ((void *)0);
    if (!fgets(string, 999, stdin)) {
        free(string);
        return ((void *)0);
    }
    temp = strchr(string, '\n');
    if (temp)
        *temp = '\0';
    return string;
}

canonical_original_code:
static char *get_string_from_stdin()
{
    char *temp;
    char *string;
    string = calloc(1000, 1);
    if (!string)
        return ((void *)0);
    if (!fgets(string, 999, stdin)) {
        free(string);
        return ((void *)0);
    }
    temp = strchr(string, '\n');
    if (temp)
        *temp = '\0';
    return string;
}

variable_types:
temp
char *

variable_types:
string
char *


decompiled_code:
int log_message(char *format, ...)
{
struct tm *v1; // rcx
time_t timer; // [rsp+8h] [rbp-F0h] BYREF
char s[24]; // [rsp+10h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-D0h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
if ( v1 && strftime(s, 0x14uLL, "%F %X", v1) )
fprintf(logfp, "%s: ", s);
else
fwrite("???Unknown time????: ", 1uLL, 0x15uLL, logfp);
va_start(arg, format);
vfprintf(logfp, format, arg);
return fputc(10, logfp);
}

canonical_decompiled_code:
int func4(char *format, ...)
{
struct tm *v1; // rcx
time_t timer; // [rsp+8h] [rbp-F0h] BYREF
char s[24]; // [rsp+10h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-D0h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
if ( v1 && strftime(s, 0x14uLL, "%F %X", v1) )
fprintf(logfp, "%s: ", s);
else
fwrite("???Unknown time????: ", 1uLL, 0x15uLL, logfp);
va_start(arg, format);
vfprintf(logfp, format, arg);
return fputc(10, logfp);
}

original_code:
static void log_message(const char *format, ...)
{
    va_list argList;
    const char *TIMESTAMP_FMT = "%F %X";
    char timestamp[sizeof("YYYY-MM-DD HH:MM:SS")];
    time_t t;
    struct tm *loc;
    t = time(((void *)0));
    loc = localtime(&t);
    if (loc == ((void *)0) ||
            strftime(timestamp, sizeof("YYYY-MM-DD HH:MM:SS"), TIMESTAMP_FMT, loc) == 0)
        fprintf(logfp, "???Unknown time????: ");
    else
        fprintf(logfp, "%s: ", timestamp);
    __builtin_va_start(argList,format);
    vfprintf(logfp, format, argList);
    fprintf(logfp, "\n");
    __builtin_va_end(argList);
}

canonical_original_code:
static void log_message(char *format, ...)
{
    __builtin_va_list argList;
    char *TIMESTAMP_FMT = "%F %X";
    char timestamp[-1];
    long t;
    struct tm *loc;
    t = time(((void *)0));
    loc = localtime(&t);
    if (loc == ((void *)0) ||
            strftime(timestamp, sizeof("YYYY-MM-DD HH:MM:SS"), TIMESTAMP_FMT, loc) == 0)
        fprintf(logfp, "???Unknown time????: ");
    else
        fprintf(logfp, "%s: ", timestamp);
    __builtin_va_start(argList,format);
    vfprintf(logfp, format, argList);
    fprintf(logfp, "\n");
    __builtin_va_end(argList);
}

variable_types:
format
char *

variable_types:
timestamp
char [-1]

variable_types: t long

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


decompiled_code:
int tweetd_log_close()
{
log_message("Closing log file");
return fclose(logfp);
}

canonical_decompiled_code:
int func5()
{
func4("Closing log file");
return fclose(logfp);
}

original_code:
static void tweetd_log_close(void)
{
    log_message("Closing log file");
    fclose(logfp);
}

canonical_original_code:
static void tweetd_log_close()
{
    log_message("Closing log file");
    fclose(logfp);
}


decompiled_code:
int __fastcall tweetd_log_open(char *filename)
{
__mode_t v1; // ebp
FILE *v2; // rbx

v1 = umask(0x3Fu);
v2 = fopen(filename, "a");
logfp = v2;
umask(v1);
if ( !v2 )
exit(1);
setbuf(v2, 0LL);
return log_message("Opened log file");
}

canonical_decompiled_code:
int __fastcall func6(char *filename)
{
__mode_t v1; // ebp
FILE *v2; // rbx

v1 = umask(0x3Fu);
v2 = fopen(filename, "a");
logfp = v2;
umask(v1);
if ( !v2 )
exit(1);
setbuf(v2, 0LL);
return func4("Opened log file");
}

original_code:
static void tweetd_log_open(const char *logFilename)
{
    mode_t m;
    m = umask(077);
    logfp = fopen(logFilename, "a");
    umask(m);
    if (logfp == ((void *)0))
        exit(1);
    setbuf(logfp, ((void *)0));
    log_message("Opened log file");
}

canonical_original_code:
static void tweetd_log_open(char *logFilename)
{
    unsigned int m;
    m = umask(077);
    logfp = fopen(logFilename, "a");
    umask(m);
    if (logfp == ((void *)0))
        exit(1);
    setbuf(logfp, ((void *)0));
    log_message("Opened log file");
}

variable_types:
logFilename
char *

variable_types:
m
unsigned int


decompiled_code:
__int64 tweetd_daemonize()
{
__uid_t v0; // ebx
__pid_t v1; // eax
unsigned int v2; // ebx
__pid_t v3; // eax

v0 = getuid();
if ( v0 != geteuid() || v0 )
{
puts("ERROR: You have to be logged in as root");
exit(0);
}
v1 = fork();
v2 = v1;
if ( v1 != -1 )
{
if ( v1 )
exit(0);
v2 = setsid();
if ( v2 != -1 )
{
v3 = fork();
v2 = v3;
if ( v3 != -1 )
{
if ( v3 )
exit(0);
umask(0);
if ( chdir("/") < 0 )
exit(1);
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 func8()
{
__uid_t v0; // ebx
__pid_t v1; // eax
unsigned int v2; // ebx
__pid_t v3; // eax

v0 = getuid();
if ( v0 != geteuid() || v0 )
{
puts("ERROR: You have to be logged in as root");
exit(0);
}
v1 = fork();
v2 = v1;
if ( v1 != -1 )
{
if ( v1 )
exit(0);
v2 = setsid();
if ( v2 != -1 )
{
v3 = fork();
v2 = v3;
if ( v3 != -1 )
{
if ( v3 )
exit(0);
umask(0);
if ( chdir("/") < 0 )
exit(1);
}
}
}
return v2;
}

original_code:
int tweetd_daemonize()
{
    int maxfd, fd;
    uid_t uid, euid;
    uid = getuid();
    euid = geteuid();
    if (uid != euid || uid != 0) {
        printf("ERROR: You have to be logged in as root\n");
        exit(0);
    }
    switch (fork()) {
        case -1: return -1;
        case 0: break;
        default: _exit(0);
    }
    if (setsid() == -1)
        return -1;
    switch (fork()) {
        case -1: return -1;
        case 0: break;
        default: _exit(0);
    }
    umask(0);
    if (chdir("/") < 0)
        exit(1);
    return 0;
}

canonical_original_code:
int tweetd_daemonize()
{
    int maxfd; int fd;
    unsigned int uid; unsigned int euid;
    uid = getuid();
    euid = geteuid();
    if (uid != euid || uid != 0) {
        printf("ERROR: You have to be logged in as root\n");
        exit(0);
    }
    switch (fork()) {
        case -1: return -1;
        case 0: break;
        default: _exit(0);
    }
    if (setsid() == -1)
        return -1;
    switch (fork()) {
        case -1: return -1;
        case 0: break;
        default: _exit(0);
    }
    umask(0);
    if (chdir("/") < 0)
        exit(1);
    return 0;
}

variable_types: maxfd int

variable_types: fd int

variable_types:
uid
unsigned int

variable_types:
euid
unsigned int


decompiled_code:
__int64 get_last_message()
{
__int64 v0; // r12
unsigned int v1; // ebx
__int64 v2; // r13
__int64 v3; // rax
__int64 *v4; // rbp

v0 = gsocial_get_direct_messages(last_id);
v1 = 0;
v2 = 0LL;
while ( (unsigned int)g_list_length(v0) > v1 )
{
v3 = g_list_nth_data(v0, v1);
v4 = (__int64 *)v3;
if ( !v1 )
{
last_id = *(_QWORD *)(v3 + 32);
if ( !(unsigned int)g_strcmp0(screen_name, *(_QWORD *)(v3 + 16)) )
v2 = *v4;
}
++v1;
}
return v2;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // r12
unsigned int v1; // ebx
__int64 v2; // r13
__int64 v3; // rax
__int64 *v4; // rbp

v0 = gsocial_get_direct_messages(last_id);
v1 = 0;
v2 = 0LL;
while ( (unsigned int)g_list_length(v0) > v1 )
{
v3 = g_list_nth_data(v0, v1);
v4 = (__int64 *)v3;
if ( !v1 )
{
last_id = *(_QWORD *)(v3 + 32);
if ( !(unsigned int)g_strcmp0(screen_name, *(_QWORD *)(v3 + 16)) )
v2 = *v4;
}
++v1;
}
return v2;
}

original_code:
gchar *get_last_message()
{
    gchar *last_msg = ((void *)0);
    gchar *inc_screen_name= ((void *)0);
    GList *messages = gsocial_get_direct_messages(last_id);
    GSLTweet *tweet;
    int i;
    for(i = 0; i<g_list_length(messages); i++){
        tweet = (GSLTweet *) g_list_nth_data(messages, i);
        if(i==0){
            last_id = tweet->id;
            inc_screen_name = tweet->screen_name;
            if(g_strcmp0(screen_name, inc_screen_name) == 0)
                last_msg = tweet->text;
        }
    }
    return last_msg;
}

canonical_original_code:
char *get_last_message()
{
    char *last_msg = ((void *)0);
    char *inc_screen_name = ((void *)0);
    struct _GList *messages = gsocial_get_direct_messages(last_id);
    struct GSLTweet *tweet;
    int i;
    for(i = 0; i<g_list_length(messages); i++){
        tweet = (struct GSLTweet *) g_list_nth_data(messages, i);
        if(i==0){
            last_id = tweet->id;
            inc_screen_name = tweet->screen_name;
            if(g_strcmp0(screen_name, inc_screen_name) == 0)
                last_msg = tweet->text;
        }
    }
    return last_msg;
}

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *

variable_types: struct GSLTweet { char *text; char *name; char *screen_name; char *created_at; char *id; } *

variable_types: i int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v4; // rax
char *v5; // rbx
char *v6; // rax
char *v7; // [rsp+8h] [rbp-150h] BYREF
char s[144]; // [rsp+10h] [rbp-148h] BYREF
struct sigaction v9; // [rsp+A0h] [rbp-B8h] BYREF

gsocial_init(argc, argv, envp);
gsocial_set_consumer_keys(consu_key, consu_secret);
read_keys((__int64)&key, (__int64)&secret);
gsocial_set_access_keys(key, secret);
sigemptyset(&v9.sa_mask);
v9.sa_flags = 0x10000000;
v9.sa_handler = (__sighandler_t)tweetd_sigup_handler;
if ( sigaction(1, &v9, 0LL) == -1 )
perror("sigaction");
if ( (unsigned int)tweetd_daemonize() != -1 )
{
tweetd_log_open("/var/log/tweetd.log");
tweetd_read_config_file("/tmp/tweetd.conf");
while ( 1 )
{
v3 = 30;
do
{
v3 = sleep(v3);
if ( hupReceived )
{
hupReceived = 0;
tweetd_log_close();
tweetd_log_open("/var/log/tweetd.log");
tweetd_read_config_file("/tmp/tweetd.conf");
}
}
while ( v3 );
v4 = (const char *)get_last_message();
v5 = (char *)v4;
if ( v4 && first_time == 1 )
{
log_message("Last message: %s\n", v4);
if ( (unsigned int)tweetd_handle_action(v5, &v7) )
{
log_message("Everything went WRONG");
}
else
{
log_message("handle_action: %s\n", v7);
log_message("Everything went OK");
sprintf(s, "@%s: %s", screen_name, "Done");
v6 = strdup(s);
if ( (unsigned int)gsocial_send_tweet(v6) )
log_message("Action responded");
else
log_message("Something is wrong with sending the message");
}
}
first_time = 1;
}
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v4; // rax
char *v5; // rbx
char *v6; // rax
char *v7; // [rsp+8h] [rbp-150h] BYREF
char s[144]; // [rsp+10h] [rbp-148h] BYREF
struct sigaction v9; // [rsp+A0h] [rbp-B8h] BYREF

gsocial_init(argc, argv, envp);
gsocial_set_consumer_keys(consu_key, consu_secret);
func2((__int64)&key, (__int64)&secret);
gsocial_set_access_keys(key, secret);
sigemptyset(&v9.sa_mask);
v9.sa_flags = 0x10000000;
v9.sa_handler = (__sighandler_t)tweetd_sigup_handler;
if ( sigaction(1, &v9, 0LL) == -1 )
perror("sigaction");
if ( (unsigned int)func8() != -1 )
{
func6("/var/log/tweetd.log");
func7("/tmp/tweetd.conf");
while ( 1 )
{
v3 = 30;
do
{
v3 = sleep(v3);
if ( hupReceived )
{
hupReceived = 0;
func5();
func6("/var/log/tweetd.log");
func7("/tmp/tweetd.conf");
}
}
while ( v3 );
v4 = (const char *)func9();
v5 = (char *)v4;
if ( v4 && first_time == 1 )
{
func4("Last message: %s\n", v4);
if ( (unsigned int)func3(v5, &v7) )
{
func4("Everything went WRONG");
}
else
{
func4("handle_action: %s\n", v7);
func4("Everything went OK");
sprintf(s, "@%s: %s", screen_name, "Done");
v6 = strdup(s);
if ( (unsigned int)gsocial_send_tweet(v6) )
func4("Action responded");
else
func4("Something is wrong with sending the message");
}
}
first_time = 1;
}
}
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
    const int SLEEP_TIME = 30;
    int count = 0;
    int unslept;
    struct sigaction sa;
    gsocial_init();
    gsocial_set_consumer_keys(consu_key, consu_secret);
    read_keys(&key, &secret);
    gsocial_set_access_keys(key, secret);
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    sa.__sigaction_handler.sa_handler = tweetd_sigup_handler;
    if (sigaction(1, &sa, ((void *)0)) == -1)
        perror("sigaction");
    if (tweetd_daemonize() == -1)
        _exit(1);
    tweetd_log_open(LOG_FILE);
    tweetd_read_config_file(CONFIG_FILE);
    unslept = SLEEP_TIME;
    while (1) {
        unslept = sleep(unslept);
        if (hupReceived) {
            hupReceived = 0;
            tweetd_log_close();
            tweetd_log_open(LOG_FILE);
            tweetd_read_config_file(CONFIG_FILE);
        }
        if (unslept == 0) {
            count++;
            char * last_msg = get_last_message();
            char * action;
            if (last_msg != ((void *)0) && first_time == 1) {
                log_message("Last message: %s\n", last_msg);
                if(tweetd_handle_action(last_msg, &action) == 0) {
                    log_message("handle_action: %s\n", action);
                    log_message("Everything went OK");
                    char tweet[140];
                    sprintf(tweet, "@%s:  %s", screen_name, "Done");
                    int sended = gsocial_send_tweet(strdup(tweet));
                    if(sended)
                        log_message("Action responded");
                    else
                        log_message("Something is wrong with sending the message");
                } else {
                    log_message("Everything went WRONG");
                }
            }
            first_time = 1;
            unslept = SLEEP_TIME;
        }
    }
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int SLEEP_TIME = 30;
    int count = 0;
    int unslept;
    struct sigaction sa;
    gsocial_init();
    gsocial_set_consumer_keys(consu_key, consu_secret);
    read_keys(&key, &secret);
    gsocial_set_access_keys(key, secret);
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    sa.__sigaction_handler.sa_handler = tweetd_sigup_handler;
    if (sigaction(1, &sa, ((void *)0)) == -1)
        perror("sigaction");
    if (tweetd_daemonize() == -1)
        _exit(1);
    tweetd_log_open(LOG_FILE);
    tweetd_read_config_file(CONFIG_FILE);
    unslept = SLEEP_TIME;
    while (1) {
        unslept = sleep(unslept);
        if (hupReceived) {
            hupReceived = 0;
            tweetd_log_close();
            tweetd_log_open(LOG_FILE);
            tweetd_read_config_file(CONFIG_FILE);
        }
        if (unslept == 0) {
            count++;
            char *last_msg = get_last_message();
            char *action;
            if (last_msg != ((void *)0) && first_time == 1) {
                log_message("Last message: %s\n", last_msg);
                if(tweetd_handle_action(last_msg, &action) == 0) {
                    log_message("handle_action: %s\n", action);
                    log_message("Everything went OK");
                    char tweet[140];
                    sprintf(tweet, "@%s:  %s", screen_name, "Done");
                    int sended = gsocial_send_tweet(strdup(tweet));
                    if(sended)
                        log_message("Action responded");
                    else
                        log_message("Something is wrong with sending the message");
                } else {
                    log_message("Everything went WRONG");
                }
            }
            first_time = 1;
            unslept = SLEEP_TIME;
        }
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: count int

variable_types: unslept 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:
action
char *

variable_types:
tweet
char [140]

variable_types: sended 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; }


printNumber

repo: MichaelRFairhurst/pretty-bash-util

decompiled_code:
size_t __fastcall printNumber(int a1)
{
fputs((const char *)(300LL * a1 + 4210880), _bss_start);
return fwrite("\x1B[5A\x1B[7C", 1uLL, 8uLL, _bss_start);
}

canonical_decompiled_code:
size_t __fastcall func7(int a1)
{
fputs((const char *)(300LL * a1 + 4210880), _bss_start);
return fwrite("\x1B[5A\x1B[7C", 1uLL, 8uLL, _bss_start);
}

original_code:
void printNumber(int n) {
 fputs(nums[n], stdout);
 fputs("\033[5A\033[7C", stdout);
}

variable_types: n int


recurseDeltaExpand

decompiled_code:
void __fastcall recurseDeltaExpand(unsigned int a1, unsigned int a2)
{
if ( a1 && a1 != 80 && a2 && a2 != 130 && !delta[130 * a1 + a2] )
{
delta[130 * a1 + a2] = rand() % 3 + 1;
recurseDeltaExpand(a1 - 1, a2 - 1);
recurseDeltaExpand(a1 - 1, a2);
recurseDeltaExpand(a1 - 1, a2 + 1);
recurseDeltaExpand(a1, a2 - 1);
recurseDeltaExpand(a1, a2 + 1);
recurseDeltaExpand(a1 + 1, a2 - 1);
recurseDeltaExpand(a1 + 1, a2);
recurseDeltaExpand(a1 + 1, a2 + 1);
}
}

original_code:
void recurseDeltaExpand(int i, int b) {
 if(i == 0 || i == 80 || b == 0 || b == 130) return;
 if(delta[i][b] != 0) return;
 delta[i][b] = (rand() % 3) + 1;
 recurseDeltaExpand(i-1, b-1);
 recurseDeltaExpand(i-1, b);
 recurseDeltaExpand(i-1, b+1);
 recurseDeltaExpand(i, b-1);
 recurseDeltaExpand(i, b+1);
 recurseDeltaExpand(i+1, b-1);
 recurseDeltaExpand(i+1, b);
 recurseDeltaExpand(i+1, b+1);
}

variable_types: b int


printLabel

decompiled_code:
int __fastcall printLabel(const char *a1)
{
return fprintf(_bss_start, "\x1B[37;44m[----%s----]\x1B[0m", a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
return fprintf(_bss_start, "\x1B[37;44m[----%s----]\x1B[0m", a1);
}

original_code:
void printLabel(char* text) {
 fprintf(stdout, "\033[37;44m[----%s----]\033[0m", text);
}

canonical_original_code:
void printLabel(char *text) {
 fprintf(stdout, "\033[37;44m[----%s----]\033[0m", text);
}

variable_types:
text
char *


printSpaces

decompiled_code:
void __fastcall printSpaces(int a1)
{
char *v1; // rbx

v1 = repeatChar(a1, 32);
fwrite("\x1B[34;40m", 1uLL, 8uLL, _bss_start);
fputs(v1, _bss_start);
fwrite("\x1B[0m", 1uLL, 4uLL, _bss_start);
free(v1);
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
char *v1; // rbx

v1 = repeatChar(a1, 32);
fwrite("\x1B[34;40m", 1uLL, 8uLL, _bss_start);
fputs(v1, _bss_start);
fwrite("\x1B[0m", 1uLL, 4uLL, _bss_start);
free(v1);
}

original_code:
void printSpaces(int size) {
 char* spaces = repeatChar(size, ' ');
 fputs("\033[34;40m", stdout);
 fputs(spaces, stdout);
 fputs("\033[0m", stdout);
 free(spaces);
}

canonical_original_code:
void printSpaces(int size) {
 char *spaces = repeatChar(size, ' ');
 fputs("\033[34;40m", stdout);
 fputs(spaces, stdout);
 fputs("\033[0m", stdout);
 free(spaces);
}

variable_types: size int

variable_types:
spaces
char *


printLabels

decompiled_code:
void __fastcall printLabels(int a1)
{
printSpaces(a1);
printLabel("HH");
printSpaces(2);
printLabel("MM");
printSpaces(2);
printLabel("SS");
printSpaces(a1);
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
func10(a1);
func9("HH");
func10(2);
func9("MM");
func10(2);
func9("SS");
func10(a1);
}

original_code:
void printLabels(int offset) {
 printSpaces(offset);
 printLabel("HH");
 printSpaces(2);
 printLabel("MM");
 printSpaces(2);
 printLabel("SS");
 printSpaces(offset);
}

variable_types: offset int


setTermSize

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

ioctl(0, 0x5413uLL, &ws);
rows = (unsigned __int16)ws;
result = (unsigned __int16)word_404CAA;
cols = (unsigned __int16)word_404CAA;
return result;
}

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

ioctl(0, 0x5413uLL, &ws);
rows = (unsigned __int16)ws;
result = (unsigned __int16)word_404CAA;
cols = (unsigned __int16)word_404CAA;
return result;
}

original_code:
void setTermSize() {
 ioctl(0, 0x5413, &ws);
 rows = ws.ws_row;
 cols = ws.ws_col;
}


printBackground

variable_types: heat int

variable_types: cool int


header

decompiled_code:
int header()
{
int v0; // ebx

v0 = (cols - 40) / 2;
puts("\x1B[2J\x1B[0;0H");
printLabels(v0);
printBackground();
return fprintf(_bss_start, "\x1B[8;%dH", (unsigned int)(v0 + 1));
}

canonical_decompiled_code:
int func14()
{
int v0; // ebx

v0 = (cols - 40) / 2;
puts("\x1B[2J\x1B[0;0H");
func11(v0);
func13();
return fprintf(_bss_start, "\x1B[8;%dH", (unsigned int)(v0 + 1));
}

original_code:
void header() {
 int offset = floor((cols - 40) / 2);
 int y;
 puts("\033[2J\033[0;0H");
 printLabels(offset);
 printBackground();
 fprintf(stdout, "\033[8;%dH", offset + 1);
}

variable_types: y int


footer

decompiled_code:
void footer()
{
const char *v0; // rbx
size_t v1; // rax

v0 = text;
v1 = strlen(text);
fprintf(_bss_start, "\x1B[5;%dH%s", (unsigned int)((int)(double)(int)((cols - v1) >> 1) + 1), v0);
fprintf(_bss_start, "\x1B[%d;0H", (unsigned int)rows);
printLabels((cols - 40) / 2);
}

canonical_decompiled_code:
void func15()
{
const char *v0; // rbx
size_t v1; // rax

v0 = text;
v1 = strlen(text);
fprintf(_bss_start, "\x1B[5;%dH%s", (unsigned int)((int)(double)(int)((cols - v1) >> 1) + 1), v0);
fprintf(_bss_start, "\x1B[%d;0H", (unsigned int)rows);
func11((cols - 40) / 2);
}

original_code:
void footer() {
 int offset = floor((cols - strlen(text)) / 2);
 fprintf(stdout, "\033[5;%dH%s", offset + 1, text);
 fprintf(stdout, "\033[%d;0H", rows);
 printLabels(floor((cols - 40) / 2));
}


printTime

decompiled_code:
size_t printTime()
{
struct tm *v0; // rbx
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
printNumber(v0->tm_hour / 10);
printNumber(v0->tm_hour % 10);
printNumber(v0->tm_min / 10);
printNumber(v0->tm_min % 10);
printNumber(v0->tm_sec / 10);
return printNumber(v0->tm_sec % 10);
}

canonical_decompiled_code:
size_t func16()
{
struct tm *v0; // rbx
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
func7(v0->tm_hour / 10);
func7(v0->tm_hour % 10);
func7(v0->tm_min / 10);
func7(v0->tm_min % 10);
func7(v0->tm_sec / 10);
return func7(v0->tm_sec % 10);
}

original_code:
void printTime() {
 time_t current;
 struct tm * localtm;
 current = time(((void *)0));
 localtm = localtime(&current);
 printNumber((int) floor(localtm->tm_hour / 10));
 printNumber(localtm->tm_hour % 10);
 printNumber((int) floor(localtm->tm_min / 10));
 printNumber(localtm->tm_min % 10);
 printNumber((int) floor(localtm->tm_sec / 10));
 printNumber(localtm->tm_sec % 10);
}

canonical_original_code:
void printTime() {
 long current;
 struct tm *localtm;
 current = time(((void *)0));
 localtm = localtime(&current);
 printNumber((int) floor(localtm->tm_hour / 10));
 printNumber(localtm->tm_hour % 10);
 printNumber((int) floor(localtm->tm_min / 10));
 printNumber(localtm->tm_min % 10);
 printNumber((int) floor(localtm->tm_sec / 10));
 printNumber(localtm->tm_sec % 10);
}

variable_types: current long

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


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi
__int64 i; // rbp
__int64 v5; // rbx

if ( argc > 1 )
text = (char *)argv[1];
v3 = time(0LL);
srand(v3);
for ( i = 260LL; i != 21060; i += 260LL )
{
v5 = i - 260;
do
{
*(__int16 *)((char *)&state + v5) = 0;
*(__int16 *)((char *)&laststate + v5) = 0;
*(__int16 *)((char *)delta + v5) = rand() % 3 + 1;
v5 += 2LL;
}
while ( v5 != i );
}
while ( 1 )
{
setTermSize(v3, argv);
header();
printTime();
footer();
fflush(_bss_start);
v3 = 80000LL;
usleep(0x13880u);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
time_t v3; // rdi
__int64 i; // rbp
__int64 v5; // rbx

if ( argc > 1 )
text = (char *)argv[1];
v3 = time(0LL);
srand(v3);
for ( i = 260LL; i != 21060; i += 260LL )
{
v5 = i - 260;
do
{
*(__int16 *)((char *)&state + v5) = 0;
*(__int16 *)((char *)&laststate + v5) = 0;
*(__int16 *)((char *)delta + v5) = rand() % 3 + 1;
v5 += 2LL;
}
while ( v5 != i );
}
while ( 1 )
{
func12(v3, argv);
func14();
func16();
func15();
fflush(_bss_start);
v3 = 80000LL;
usleep(0x13880u);
}
}

original_code:
int main(int argc, char** argv) {
 int i, b;
 if(argc > 1) text = argv[1];
 srand(time(((void *)0)));
 for(i = 0; i < 80; i++)
 for(b = 0; b < 130; b++) {
  state[i][b] = 0;
  laststate[i][b] = 0;
  delta[i][b] = (rand() % 3) + 1;
 }
 while(1) {
  setTermSize();
  header();
  printTime();
  footer();
  fflush(stdout);
  usleep(80000);
 }
}

canonical_original_code:
int main(int argc, char **argv) {
 int i; int b;
 if(argc > 1) text = argv[1];
 srand(time(((void *)0)));
 for(i = 0; i < 80; i++)
 for(b = 0; b < 130; b++) {
  state[i][b] = 0;
  laststate[i][b] = 0;
  delta[i][b] = (rand() % 3) + 1;
 }
 while(1) {
  setTermSize();
  header();
  printTime();
  footer();
  fflush(stdout);
  usleep(80000);
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


decompiled_code:
void SIGINT_handler()
{
__pid_t v0; // eax

fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 49LL, "SIGINT_handler");
fwrite("Shutdown command\n", 1uLL, 0x11uLL, stderr);
v0 = getpgrp();
kill(-v0, 15);
}

canonical_decompiled_code:
void func0()
{
__pid_t v0; // eax

fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 49LL, "SIGINT_handler");
fwrite("Shutdown command\n", 1uLL, 0x11uLL, stderr);
v0 = getpgrp();
kill(-v0, 15);
}

original_code:
void SIGINT_handler(int sig){
    fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 49, __FUNCTION__); fprintf(stderr, "Shutdown command\n");
    pid_t groupPid = getpgrp();
    kill((-1)*groupPid, 15);
}

canonical_original_code:
void SIGINT_handler(int sig){
    fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 49, __FUNCTION__); fprintf(stderr, "Shutdown command\n");
    int groupPid = getpgrp();
    kill((-1)*groupPid, 15);
}

variable_types: sig int

variable_types: groupPid int


shutdownDaemon

decompiled_code:
void __noreturn shutdownDaemon()
{
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
exit(1);
}

original_code:
void shutdownDaemon(){
    exit(1);
}

canonical_original_code:
void shutdownDaemon(){
    exit(1);
}


decompiled_code:
void SIGCHLD_handler()
{
while ( waitpid(-1, 0LL, 0) > 0 )
;
if ( *_errno_location() != 10 )
{
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 41LL, "SIGCHLD_handler");
fwrite("waitpid error\n", 1uLL, 0xEuLL, stderr);
shutdownDaemon();
}
}

canonical_decompiled_code:
void func3()
{
while ( waitpid(-1, 0LL, 0) > 0 )
;
if ( *_errno_location() != 10 )
{
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 41LL, "SIGCHLD_handler");
fwrite("waitpid error\n", 1uLL, 0xEuLL, stderr);
func2();
}
}

original_code:
void SIGCHLD_handler(int sig){
    pid_t pid;
    while((pid = waitpid(-1, ((void *)0), 0)) > 0);
    if((*__errno_location ()) != 10){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 41, __FUNCTION__); fprintf(stderr, "waitpid error\n");
        shutdownDaemon();
    }
}

canonical_original_code:
void SIGCHLD_handler(int sig){
    int pid;
    while((pid = waitpid(-1, ((void *)0), 0)) > 0);
    if((*__errno_location ()) != 10){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 41, __FUNCTION__); fprintf(stderr, "waitpid error\n");
        shutdownDaemon();
    }
}

variable_types: pid int


requestHandler

decompiled_code:
__int64 __fastcall requestHandler(__int64 a1, unsigned int a2)
{
const char *v2; // rax
__int64 result; // rax

v2 = (const char *)getHeader(a1, "URI:");
if ( strstr(v2, ".php") )
result = dynamicHandler(a1, a2);
else
result = staticHandler(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
const char *v2; // rax
__int64 result; // rax

v2 = (const char *)getHeader(a1, "URI:");
if ( strstr(v2, ".php") )
result = dynamicHandler(a1, a2);
else
result = staticHandler(a1, a2);
return result;
}

original_code:
void requestHandler(struct headers *request, int sockfd){
    char *uri = getHeader(request, "URI:");
    if(strstr(uri, ".php")){
        dynamicHandler(request, sockfd);
    }else{
        staticHandler(request, sockfd);
    }
}

variable_types: struct headers { char *keys[256]; char *values[256]; } *

variable_types: sockfd int

variable_types:
uri
char *


server

decompiled_code:
void __noreturn server()
{
int v0; // eax
int v1; // ebp
int v2; // ebx
__pid_t v3; // eax
__int64 v4; // rax
_BYTE v5[8204]; // [rsp+0h] [rbp-2048h] BYREF
socklen_t addr_len; // [rsp+200Ch] [rbp-3Ch] BYREF
struct sockaddr v7; // [rsp+2010h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+2020h] [rbp-28h] BYREF

v0 = socket(2, 1, 0);
if ( v0 >= 0 )
{
v1 = v0;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(80);
if ( bind(v1, &addr, 0x10u) >= 0 )
{
listen(v1, 5);
addr_len = 16;
while ( 1 )
{
v2 = accept(v1, &v7, &addr_len);
if ( v2 < 0 )
break;
v3 = fork();
if ( v3 < 0 )
{
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 97LL, "server");
fwrite("Error on fork\n", 1uLL, 0xEuLL, stderr);
shutdownDaemon();
}
if ( !v3 )
{
read(v2, v5, 0x2000uLL);
v4 = parseHTTPRequest(v5);
requestHandler(v4, v2);
exit(0);
}
close(v2);
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 92LL, "server");
fwrite("Error on accept", 1uLL, 0xFuLL, stderr);
shutdownDaemon();
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 81LL, "server");
fwrite("Error on binding", 1uLL, 0x10uLL, stderr);
shutdownDaemon();
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 69LL, "server");
fwrite("Error creating socket", 1uLL, 0x15uLL, stderr);
shutdownDaemon();
}

canonical_decompiled_code:
void __noreturn func5()
{
int v0; // eax
int v1; // ebp
int v2; // ebx
__pid_t v3; // eax
__int64 v4; // rax
_BYTE v5[8204]; // [rsp+0h] [rbp-2048h] BYREF
socklen_t addr_len; // [rsp+200Ch] [rbp-3Ch] BYREF
struct sockaddr v7; // [rsp+2010h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+2020h] [rbp-28h] BYREF

v0 = socket(2, 1, 0);
if ( v0 >= 0 )
{
v1 = v0;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func1(80);
if ( bind(v1, &addr, 0x10u) >= 0 )
{
listen(v1, 5);
addr_len = 16;
while ( 1 )
{
v2 = accept(v1, &v7, &addr_len);
if ( v2 < 0 )
break;
v3 = fork();
if ( v3 < 0 )
{
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 97LL, "server");
fwrite("Error on fork\n", 1uLL, 0xEuLL, stderr);
func2();
}
if ( !v3 )
{
read(v2, v5, 0x2000uLL);
v4 = parseHTTPRequest(v5);
func4(v4, v2);
exit(0);
}
close(v2);
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 92LL, "server");
fwrite("Error on accept", 1uLL, 0xFuLL, stderr);
func2();
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 81LL, "server");
fwrite("Error on binding", 1uLL, 0x10uLL, stderr);
func2();
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 69LL, "server");
fwrite("Error creating socket", 1uLL, 0x15uLL, stderr);
func2();
}

original_code:
int server(){
    int sockfd = socket(2, SOCK_STREAM, 0);
    if(sockfd<0){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 69, __FUNCTION__); fprintf(stderr, "Error creating socket");
        shutdownDaemon();
    }
    struct sockaddr_in serv_addr, cli_addr;
    memset((char*) &serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_port = htons(80);
    serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    if(bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 81, __FUNCTION__); fprintf(stderr, "Error on binding");
        shutdownDaemon();
    }
    listen(sockfd, 5);
    socklen_t cilen = sizeof(cli_addr);
    while(1){
        int newsockfd = accept(sockfd, (struct sockaddr*)&cli_addr, &cilen);
        if(newsockfd < 0){
            fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 92, __FUNCTION__); fprintf(stderr, "Error on accept");
            shutdownDaemon();
        }else{
            pid_t pid = fork();
            if(pid < 0){
                fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 97, __FUNCTION__); fprintf(stderr, "Error on fork\n");
                shutdownDaemon();
            }
            if(pid == 0){
                char request[8192];
                read(newsockfd, request, 8192);
                struct headers *requestStruct;
                requestStruct = parseHTTPRequest(request);
                requestHandler(requestStruct, newsockfd);
                exit(0);
            }
            close(newsockfd);
        }
    }
    return 0;
}

canonical_original_code:
int server(){
    int sockfd = socket(2, SOCK_STREAM, 0);
    if(sockfd<0){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 69, __FUNCTION__); fprintf(stderr, "Error creating socket");
        shutdownDaemon();
    }
    struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
    memset((char *) &serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_port = htons(80);
    serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    if(bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 81, __FUNCTION__); fprintf(stderr, "Error on binding");
        shutdownDaemon();
    }
    listen(sockfd, 5);
    unsigned int cilen = sizeof(cli_addr);
    while(1){
        int newsockfd = accept(sockfd, (struct sockaddr*)&cli_addr, &cilen);
        if(newsockfd < 0){
            fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 92, __FUNCTION__); fprintf(stderr, "Error on accept");
            shutdownDaemon();
        }else{
            int pid = fork();
            if(pid < 0){
                fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 97, __FUNCTION__); fprintf(stderr, "Error on fork\n");
                shutdownDaemon();
            }
            if(pid == 0){
                char request[8192];
                read(newsockfd, request, 8192);
                struct headers *requestStruct;
                requestStruct = parseHTTPRequest(request);
                requestHandler(requestStruct, newsockfd);
                exit(0);
            }
            close(newsockfd);
        }
    }
    return 0;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
cilen
unsigned int

variable_types: newsockfd int

variable_types:
request
char [8192]

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct headers { char *keys[256]; char *values[256]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( signal(17, (__sighandler_t)SIGCHLD_handler) != (__sighandler_t)-1LL
&& signal(2, (__sighandler_t)SIGINT_handler) != (__sighandler_t)-1LL )
{
server();
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 118LL, "main");
fwrite("Signal error\n", 1uLL, 0xDuLL, stderr);
shutdownDaemon(1LL);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( signal(17, (__sighandler_t)SIGCHLD_handler) != (__sighandler_t)-1LL
&& signal(2, (__sighandler_t)SIGINT_handler) != (__sighandler_t)-1LL )
{
func5();
}
fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 118LL, "main");
fwrite("Signal error\n", 1uLL, 0xDuLL, stderr);
func2(1LL);
}

original_code:
int main(int argc, char** argv){
    if(signal(17, SIGCHLD_handler) == ((__sighandler_t) -1) ||
       signal(2, SIGINT_handler ) == ((__sighandler_t) -1)){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 118, __FUNCTION__); fprintf(stderr, "Signal error\n");
        shutdownDaemon(1);
    }
    server();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    if(signal(17, SIGCHLD_handler) == ((__sighandler_t) -1) ||
       signal(2, SIGINT_handler ) == ((__sighandler_t) -1)){
        fprintf(stderr, "%s (%d) in %s(): ", "src/server.c", 118, __FUNCTION__); fprintf(stderr, "Signal error\n");
        shutdownDaemon(1);
    }
    server();
    return 0;
}


original_code:
void ft_elem_add(t_elem *first_elem, t_elem *elem_to_add)
{
 t_elem *tmp;
 tmp = first_elem->prev;
 if (!tmp)
 {
  first_elem->prev = elem_to_add;
  first_elem->next = elem_to_add;
  elem_to_add->prev = first_elem;
  elem_to_add->next = first_elem;
 }
 else
 {
  first_elem->prev = elem_to_add;
  elem_to_add->next = first_elem;
  elem_to_add->prev = tmp;
  tmp->next = elem_to_add;
 }
}

canonical_original_code:
void ft_elem_add(struct s_elem *first_elem, struct s_elem *elem_to_add)
{
 struct s_elem *tmp;
 tmp = first_elem->prev;
 if (!tmp)
 {
  first_elem->prev = elem_to_add;
  first_elem->next = elem_to_add;
  elem_to_add->prev = first_elem;
  elem_to_add->next = first_elem;
 }
 else
 {
  first_elem->prev = elem_to_add;
  elem_to_add->next = first_elem;
  elem_to_add->prev = tmp;
  tmp->next = elem_to_add;
 }
}

variable_types: struct s_elem { char *data; struct s_elem *next; struct s_elem *prev; int cursor; int selected; int posx; int posy; } *


original_code:
t_elem *ft_elem_del(t_list *list, t_elem *elem_to_del)
{
 t_elem *ptr_next;
 ptr_next = elem_to_del->next;
 if (elem_to_del == list->first_elem)
  list->first_elem = ptr_next;
 elem_to_del->prev->next = ptr_next;
 ptr_next->prev = elem_to_del->prev;
 list->nb_elem--;
 free(elem_to_del->data);
 free(elem_to_del);
 elem_to_del = ((void *)0);
 ptr_next->cursor = 1;
 return (ptr_next);
}

canonical_original_code:
struct s_elem *ft_elem_del(struct s_list *list, struct s_elem *elem_to_del)
{
 struct s_elem *ptr_next;
 ptr_next = elem_to_del->next;
 if (elem_to_del == list->first_elem)
  list->first_elem = ptr_next;
 elem_to_del->prev->next = ptr_next;
 ptr_next->prev = elem_to_del->prev;
 list->nb_elem--;
 free(elem_to_del->data);
 free(elem_to_del);
 elem_to_del = ((void *)0);
 ptr_next->cursor = 1;
 return (ptr_next);
}

variable_types: struct s_list { struct s_elem *first_elem; struct s_elem *curr_elem; int nb_elem; unsigned int longest; int fd; } *

return_type: struct s_elem { char *data; struct s_elem *next; struct s_elem *prev; int cursor; int selected; int posx; int posy; } *


repo: Sygnious/Kompilatorteknikk

decompiled_code:
double __fastcall x_squared(double a1)
{
return a1 * a1;
}

canonical_decompiled_code:
double __fastcall func7(double a1)
{
return a1 * a1;
}

original_code:
double x_squared(double x){
    return x*x;
}

variable_types: x double

return_type: double


decompiled_code:
double __fastcall x_cubed(double a1)
{
return a1 * a1 * a1;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return a1 * a1 * a1;
}

original_code:
double x_cubed(double x){
    return x*x*x;
}


decompiled_code:
__int64 __fastcall get_random_number(int a1)
{
return (unsigned int)(rand() % a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(rand() % a1);
}

original_code:
int get_random_number(int n){
    return rand() % n;
}

variable_types: n int


decompiled_code:
int __fastcall print_array(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d, ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d, ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

original_code:
void print_array(int* array, int size){
 for(int i=0; i<size; i++){
  printf("%d, ", array[i]);
 }
 printf("\n");
}

canonical_original_code:
void print_array(int *array, int size){
 for(int i = 0; i<size; i++){
  printf("%d, ", array[i]);
 }
 printf("\n");
}

variable_types:
array
int *

variable_types: size int


sort

decompiled_code:
unsigned __int64 __fastcall sort(__int64 a1, int a2, __int64 a3, __int64 a4, int a5)
{
unsigned __int64 result; // rax
void *v6; // rsp
_QWORD *v7; // r11
__int64 v8; // rax
int v9; // edx
int v10; // ecx
_QWORD v11[2]; // [rsp+0h] [rbp-10h] BYREF

result = (8LL * a2 + 15) & 0xFFFFFFFFFFFFFFF0LL;
v6 = alloca(8LL * a2);
if ( a2 > 0 )
{
v7 = v11;
do
{
v8 = 0LL;
v10 = 1215752191;
do
{
v9 = *(_DWORD *)(a1 + 4 * v8);
if ( v9 < v10 )
{
if ( v9 >= 0 )
v10 = *(_DWORD *)(a1 + 4 * v8);
if ( v9 >= 0 )
a5 = v8;
}
++v8;
}
while ( v8 != a2 );
*v7 = v10;
*(_DWORD *)(a1 + 4LL * a5) = -1;
++v7;
}
while ( v7 != &v11[a2] );
for ( result = 0LL; result != a2; ++result )
*(_DWORD *)(a1 + 4 * result) = v11[result];
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, int a2, __int64 a3, __int64 a4, int a5)
{
unsigned __int64 result; // rax
void *v6; // rsp
_QWORD *v7; // r11
__int64 v8; // rax
int v9; // edx
int v10; // ecx
_QWORD v11[2]; // [rsp+0h] [rbp-10h] BYREF

result = (8LL * a2 + 15) & 0xFFFFFFFFFFFFFFF0LL;
v6 = alloca(8LL * a2);
if ( a2 > 0 )
{
v7 = v11;
do
{
v8 = 0LL;
v10 = 1215752191;
do
{
v9 = *(_DWORD *)(a1 + 4 * v8);
if ( v9 < v10 )
{
if ( v9 >= 0 )
v10 = *(_DWORD *)(a1 + 4 * v8);
if ( v9 >= 0 )
a5 = v8;
}
++v8;
}
while ( v8 != a2 );
*v7 = v10;
*(_DWORD *)(a1 + 4LL * a5) = -1;
++v7;
}
while ( v7 != &v11[a2] );
for ( result = 0LL; result != a2; ++result )
*(_DWORD *)(a1 + 4 * result) = v11[result];
}
return result;
}

original_code:
void sort(int* array, int size){
 int* sortedArray[size];
 int index, low;
 for (int i = 0; i < size; i++){
  low = 1215752191;
  for (int j = 0; j < size; j++){
   if (array[j]>-1 && array[j]<low){
    index = j;
    low = array[j];
   }
  }
  sortedArray[i] = low;
  array[index]=-1;
 }
 for (int i = 0; i < size; i++){
  array[i] = sortedArray[i];
 }
}

canonical_original_code:
void sort(int *array, int size){
 int *sortedArray[-1];
 int index; int low;
 for (int i = 0; i < size; i++){
  low = 1215752191;
  for (int j = 0; j < size; j++){
   if (array[j]>-1 && array[j]<low){
    index = j;
    low = array[j];
   }
  }
  sortedArray[i] = low;
  array[index]=-1;
 }
 for (int i = 0; i < size; i++){
  array[i] = sortedArray[i];
 }
}

variable_types:
sortedArray
int *[-1]

variable_types: index int

variable_types: low int

variable_types: i int

variable_types: j int


search

decompiled_code:
__int64 __fastcall search(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 16);
result = 1LL;
if ( v2 != a2 )
{
if ( v2 > a2 )
{
result = 0LL;
if ( !*(_QWORD *)a1 )
return result;
return search();
}
if ( v2 >= a2 )
return 0LL;
result = 0LL;
if ( *(_QWORD *)(a1 + 8) )
return search();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 16);
result = 1LL;
if ( v2 != a2 )
{
if ( v2 > a2 )
{
result = 0LL;
if ( !*(_QWORD *)a1 )
return result;
return func13();
}
if ( v2 >= a2 )
return 0LL;
result = 0LL;
if ( *(_QWORD *)(a1 + 8) )
return func13();
}
return result;
}

original_code:
int search(Node* root, int n){
 if (n == root->value){
  return 1;
 } else if (n < root->value && root->left != ((void *)0)){
  return search(root->left, n);
 } else if (n > root->value && root->right != ((void *)0)){
  return search(root->right, n);
 }
 return 0;
}

canonical_original_code:
int search(struct Node *root, int n){
 if (n == root->value){
  return 1;
 } else if (n < root->value && root->left != ((void *)0)){
  return search(root->left, n);
 } else if (n > root->value && root->right != ((void *)0)){
  return search(root->right, n);
 }
 return 0;
}

variable_types: struct Node { struct Node *left; struct Node *right; int value; } *


decompiled_code:
_QWORD *create_blank_node()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func14()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
Node* create_blank_node(){
 Node* blankNode = (Node*) malloc (sizeof (Node));
 blankNode->left = ((void *)0);
 blankNode->right = ((void *)0);
 blankNode->value = 0;
 return blankNode;
}

canonical_original_code:
struct Node *create_blank_node(){
 struct Node *blankNode = (Node*) malloc (sizeof (Node));
 blankNode->left = ((void *)0);
 blankNode->right = ((void *)0);
 blankNode->value = 0;
 return blankNode;
}

return_type: struct Node { struct Node *left; struct Node *right; int value; } *


decompiled_code:
int __fastcall print_tree(__int64 a1, int a2)
{
int i; // ebx
int result; // eax
__int64 v4; // rdi

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
putchar(32);
}
result = printf("%d\n", *(unsigned int *)(a1 + 16));
if ( *(_QWORD *)a1 )
result = print_tree(*(_QWORD *)a1, (unsigned int)(a2 + 1));
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
result = print_tree(v4, (unsigned int)(a2 + 1));
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, int a2)
{
int i; // ebx
int result; // eax
__int64 v4; // rdi

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
putchar(32);
}
result = printf("%d\n", *(unsigned int *)(a1 + 16));
if ( *(_QWORD *)a1 )
result = func16(*(_QWORD *)a1, (unsigned int)(a2 + 1));
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
result = func16(v4, (unsigned int)(a2 + 1));
return result;
}

original_code:
void print_tree(Node* n, int offset){
 for (int i=0; i<offset; i++){
  printf(" ");
 }
 printf("%d\n", n->value);
 if (n->left != ((void *)0)){
  print_tree(n->left, offset+1);
 }
 if (n->right != ((void *)0)){
  print_tree(n->right, offset+1);
 }
}

canonical_original_code:
void print_tree(struct Node *n, int offset){
 for (int i = 0; i<offset; i++){
  printf(" ");
 }
 printf("%d\n", n->value);
 if (n->left != ((void *)0)){
  print_tree(n->left, offset+1);
 }
 if (n->right != ((void *)0)){
  print_tree(n->right, offset+1);
 }
}

variable_types: offset int

user_defined_types: struct Node { struct Node *left; struct Node *right; int value; }


integrate

decompiled_code:
double __fastcall integrate(double (__fastcall *a1)(double), double a2, double a3, double a4)
{
double v5; // [rsp+8h] [rbp-30h]
double v6; // [rsp+10h] [rbp-28h]

v5 = a2;
v6 = 0.0;
if ( a3 <= a2 )
{
v6 = 0.0;
}
else
{
do
{
v6 = a1(v5) + v6;
v5 = v5 + a4;
}
while ( a3 > v5 );
}
return a4 * v6;
}

canonical_decompiled_code:
double __fastcall func17(double (__fastcall *a1)(double), double a2, double a3, double a4)
{
double v5; // [rsp+8h] [rbp-30h]
double v6; // [rsp+10h] [rbp-28h]

v5 = a2;
v6 = 0.0;
if ( a3 <= a2 )
{
v6 = 0.0;
}
else
{
do
{
v6 = a1(v5) + v6;
v5 = v5 + a4;
}
while ( a3 > v5 );
}
return a4 * v6;
}

original_code:
double integrate(double (*function)(double), double start, double end, double stepsize){
 double result = 0.0;
 for (double i = start; i<end; i+=stepsize){
  result += (*function)(i);
 }
 result *= stepsize;
 return result;
}

variable_types:
function
double (*)(double)

variable_types: start double

variable_types: end double

variable_types: stepsize double

variable_types: result double

variable_types: i double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // er8
unsigned int *v7; // rbx
__int64 v8; // rbx
unsigned int v9; // ebp
unsigned int v10; // eax
double v11; // xmm0_8
double v12; // xmm0_8

v3 = create_random_array(10, 10);
print_array(v3, 10);
sort((__int64)v3, 10, v4, v5, v6);
print_array(v3, 10);
v7 = create_random_array(10, 10);
print_array(v7, 10);
v8 = create_tree(v7, 10);
print_tree(v8, 0);
v9 = search(v8, 3);
v10 = search(v8, 11);
printf("%d, %d\n", v9, v10);
v11 = integrate(x_squared, 0.0, 1.0, 0.001);
printf("%f\n", v11);
v12 = integrate(x_cubed, 0.0, 1.0, 0.001);
printf("%f\n", v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // er8
unsigned int *v7; // rbx
__int64 v8; // rbx
unsigned int v9; // ebp
unsigned int v10; // eax
double v11; // xmm0_8
double v12; // xmm0_8

v3 = create_random_array(10, 10);
func10(v3, 10);
func11((__int64)v3, 10, v4, v5, v6);
func10(v3, 10);
v7 = create_random_array(10, 10);
func10(v7, 10);
v8 = func15(v7, 10);
func16(v8, 0);
v9 = func13(v8, 3);
v10 = func13(v8, 11);
printf("%d, %d\n", v9, v10);
v11 = func17(x_squared, 0.0, 1.0, 0.001);
printf("%f\n", v11);
v12 = func17(x_cubed, 0.0, 1.0, 0.001);
printf("%f\n", v12);
return 0;
}

original_code:
int main(int argc, char** argv){
    int* array = create_random_array(10, 10);
    print_array(array, 10);
    sort(array, 10);
    print_array(array, 10);
    int* new_array = create_random_array(10,10);
    print_array(new_array, 10);
    Node* root = create_tree(new_array, 10);
    print_tree(root, 0);
    int found_3 = search(root, 3);
    int found_11 = search(root, 11);
    printf("%d, %d\n", found_3, found_11);
    printf("%f\n", integrate(&x_squared, 0, 1, 0.001));
    printf("%f\n", integrate(&x_cubed, 0, 1, 0.001));
}

canonical_original_code:
int main(int argc, char **argv){
    int *array = create_random_array(10, 10);
    print_array(array, 10);
    sort(array, 10);
    print_array(array, 10);
    int *new_array = create_random_array(10,10);
    print_array(new_array, 10);
    struct Node *root = create_tree(new_array, 10);
    print_tree(root, 0);
    int found_3 = search(root, 3);
    int found_11 = search(root, 11);
    printf("%d, %d\n", found_3, found_11);
    printf("%f\n", integrate(&x_squared, 0, 1, 0.001));
    printf("%f\n", integrate(&x_cubed, 0, 1, 0.001));
}

variable_types: argc int

variable_types:
argv
char **


repo: Tuqz/mandelbrot

decompiled_code:
double __fastcall complex_magnitude(double *a1)
{
double v1; // xmm0_8
double result; // xmm0_8

v1 = a1[1] * a1[1] + *a1 * *a1;
if ( v1 < 0.0 )
result = sqrt(v1);
else
result = sqrt(v1);
return result;
}

canonical_decompiled_code:
double __fastcall func7(double *a1)
{
double v1; // xmm0_8
double result; // xmm0_8

v1 = a1[1] * a1[1] + *a1 * *a1;
if ( v1 < 0.0 )
result = sqrt(v1);
else
result = sqrt(v1);
return result;
}

original_code:
double complex_magnitude(complex_t *z) {
 double mag_sq = (z->real*z->real)+(z->imag*z->imag);
 return sqrt(mag_sq);
}

canonical_original_code:
double complex_magnitude(struct complex *z) {
 double mag_sq = (z->real*z->real)+(z->imag*z->imag);
 return sqrt(mag_sq);
}

variable_types: struct complex { double real; double imag; } *


decompiled_code:
double __fastcall in_set(double *a1)
{
__int16 i; // bx
double v2; // xmm0_8
double v4; // [rsp+0h] [rbp-28h] BYREF
double v5; // [rsp+8h] [rbp-20h]

v4 = 0.0;
v5 = 0.0;
for ( i = 0; i != 200; ++i )
{
v2 = v4;
v4 = v2 * v2 - v5 * v5 + *a1;
v5 = (v2 + v2) * v5 + a1[1];
if ( complex_magnitude(&v4) >= 200.0 )
break;
}
return (double)i / 200.0;
}

original_code:
double in_set(complex_t *c) {
 complex_t z = {0, 0};
 short i;
 for(i = 0; i < 200; ++i) {
  complex_t z_sq = {(z.real*z.real)-(z.imag*z.imag), 2*z.real*z.imag};
  do{ z.real = z_sq.real + (*c).real; z.imag = z_sq.imag + (*c).imag; } while(0);
  if(complex_magnitude(&z) >= 200)
   break;
 }
 return ((double)i)/((double)200);
}

canonical_original_code:
double in_set(struct complex *c) {
 struct complex z = {0, 0};
 short i;
 for(i = 0; i < 200; ++i) {
  struct complex z_sq = {(z.real*z.real)-(z.imag*z.imag), 2*z.real*z.imag};
  do{ z.real = z_sq.real + (*c).real; z.imag = z_sq.imag + (*c).imag; } while(0);
  if(complex_magnitude(&z) >= 200)
   break;
 }
 return ((double)i)/((double)200);
}

variable_types: struct complex { double real; double imag; }

variable_types: i short


original_code:
void mandel_gen(uint32_t *pixels, double scale, double centre_x, double centre_y) {
#pragma omp parallel
 {
 for(int i = 0; i < 600; ++i) {
  for(int j = 0; j < 800; ++j) {
   complex_t scaled = {((j*scale)/(800/4.0))-(2.0*scale)+centre_x, ((i*scale)/(600/4.0))-(2.0*scale)+centre_y};
   double runs = in_set(&scaled);
   double sine_runs = sin(runs*3.141592635358);
   short value = (short)(sine_runs * 255.0);
   uint32_t pixel = 0 | value << 16 | value << 8 | value;
   pixels[(i * 800) + j] = pixel;
  }
 }
 }
}

canonical_original_code:
void mandel_gen(unsigned int *pixels, double scale, double centre_x, double centre_y) {
#pragma omp parallel
 {
 for(int i = 0; i < 600; ++i) {
  for(int j = 0; j < 800; ++j) {
   struct complex scaled = {((j*scale)/(800/4.0))-(2.0*scale)+centre_x, ((i*scale)/(600/4.0))-(2.0*scale)+centre_y};
   double runs = in_set(&scaled);
   double sine_runs = sin(runs*3.141592635358);
   short value = (short)(sine_runs * 255.0);
   unsigned int pixel = 0 | value << 16 | value << 8 | value;
   pixels[(i * 800) + j] = pixel;
  }
 }
 }
}

variable_types:
pixels
unsigned int *

variable_types: scale double

variable_types: runs double

variable_types: value short

variable_types:
pixel
unsigned int

user_defined_types: struct complex { double real; double imag; }


nose

decompiled_code:
__int64 nose()
{
glPushMatrix();
glRotatef(90.0, 0.0, 1.0);
glutSolidCone(10LL, 10LL, 1.0, 2.0);
return glPopMatrix();
}

canonical_decompiled_code:
__int64 func1()
{
glPushMatrix();
glRotatef(90.0, 0.0, 1.0);
glutSolidCone(10LL, 10LL, 1.0, 2.0);
return glPopMatrix();
}

original_code:
void nose()
{
 glPushMatrix();
 glRotatef(90, 0.0, 1.0, 0.0);
 double base = 1.0, height = 2.0;
 int slices = 10, stacks = 10;
 glutSolidCone((GLdouble) base, (GLdouble) height, (GLint) slices, (GLint) stacks);
 glPopMatrix();
}

canonical_original_code:
void nose()
{
 glPushMatrix();
 glRotatef(90, 0.0, 1.0, 0.0);
 double base = 1.0; double height = 2.0;
 int slices = 10; int stacks = 10;
 glutSolidCone((double) base, (double) height, (int) slices, (int) stacks);
 glPopMatrix();
}

variable_types: base double

variable_types: height double

variable_types: slices int

variable_types: stacks int


flames

original_code:
void flames()
{
 glColor3f(1.0, 0.0, 0.0);
 glRotatef(-90, 0.0, 1.0, 0.0);
 glTranslatef(0.0, 0.0, 9.5);
 double base = 0.8, height = 3.0;
 int slices = 10, stacks = 10;
 glutSolidCone((GLdouble) base, (GLdouble) height*flame, (GLint) slices, (GLint) stacks);
 glEnable(0x0BE2);
 glColor4f(1.0,1.0,0.0,0.8);
 glutSolidCone((GLdouble) base+0.2, (GLdouble) (height+0.8)*flame, (GLint) slices, (GLint) stacks);
 glDisable(0x0BE2);
}

canonical_original_code:
void flames()
{
 glColor3f(1.0, 0.0, 0.0);
 glRotatef(-90, 0.0, 1.0, 0.0);
 glTranslatef(0.0, 0.0, 9.5);
 double base = 0.8; double height = 3.0;
 int slices = 10; int stacks = 10;
 glutSolidCone((double) base, (double) height*flame, (int) slices, (int) stacks);
 glEnable(0x0BE2);
 glColor4f(1.0,1.0,0.0,0.8);
 glutSolidCone((double) base+0.2, (GLdouble) (height+0.8)*flame, (int) slices, (int) stacks);
 glDisable(0x0BE2);
}


wing

decompiled_code:
__int64 wing()
{
glBindTexture(3553LL, texture);
glBegin(4LL);
glTexCoord2f(0.0);
glVertex3f(0.0, 0.0);
glTexCoord2f(0.0);
glVertex3f(0.0, COERCE_DOUBLE((unsigned __int64)LC12));
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC1));
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC13), COERCE_DOUBLE((unsigned __int64)LC12));
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC1));
return glEnd(1.0, 0.0, 0.0);
}

canonical_decompiled_code:
__int64 func3()
{
glBindTexture(3553LL, texture);
glBegin(4LL);
glTexCoord2f(0.0);
glVertex3f(0.0, 0.0);
glTexCoord2f(0.0);
glVertex3f(0.0, COERCE_DOUBLE((unsigned __int64)LC12));
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC1));
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC13), COERCE_DOUBLE((unsigned __int64)LC12));
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC1));
return glEnd(1.0, 0.0, 0.0);
}

original_code:
void wing()
{
    glBindTexture(0x0DE1, texture[0]);
 glBegin(0x0004);
  glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
  glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 4.0, 0.0);
  glTexCoord2f(1.0, 1.0); glVertex3f(5.0, 4.0, 0.0);
  glTexCoord2f(1.0, 0.0);
 glEnd();
}


CrcHash

repo: akashgangil/GPU-Hashsums

decompiled_code:
__int64 __fastcall CrcHash(unsigned int *a1, unsigned int a2)
{
unsigned __int8 *v2; // rax
unsigned int v3; // edx
__int64 v4; // rcx

if ( a2 <= 3 )
{
v2 = (unsigned __int8 *)a1;
v3 = -1;
}
else
{
v2 = (unsigned __int8 *)&a1[a2 >> 2];
v3 = -1;
do
v3 = _mm_crc32_u32(v3, *a1++);
while ( v2 != (unsigned __int8 *)a1 );
}
if ( (a2 & 3) != 0 )
{
v4 = (__int64)&v2[a2 & 3];
do
v3 = _mm_crc32_u8(v3, *v2++);
while ( (unsigned __int8 *)v4 != v2 );
}
return ~v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int a2)
{
unsigned __int8 *v2; // rax
unsigned int v3; // edx
__int64 v4; // rcx

if ( a2 <= 3 )
{
v2 = (unsigned __int8 *)a1;
v3 = -1;
}
else
{
v2 = (unsigned __int8 *)&a1[a2 >> 2];
v3 = -1;
do
v3 = _mm_crc32_u32(v3, *a1++);
while ( v2 != (unsigned __int8 *)a1 );
}
if ( (a2 & 3) != 0 )
{
v4 = (__int64)&v2[a2 & 3];
do
v3 = _mm_crc32_u8(v3, *v2++);
while ( (unsigned __int8 *)v4 != v2 );
}
return ~v3;
}

original_code:
uint32_t CrcHash(const void* data, uint32_t bytes){
    uint32_t hash = 0xFFFFFFFF;
    uint32_t words = bytes / sizeof(uint32_t);
    bytes = bytes % sizeof(uint32_t);
    const uint32_t* p = (const uint32_t*)(data);
    while (words--) {
      hash = _mm_crc32_u32(hash, *p);
      ++p;
    }
    const uint8_t* s = (const uint8_t*)(p);
    while (bytes--) {
      hash = _mm_crc32_u8(hash, *s);
      ++s;
    }
    return hash ^ 0xFFFFFFFF;
}

canonical_original_code:
unsigned int CrcHash(void *data, unsigned int bytes){
    unsigned int hash = 0xFFFFFFFF;
    unsigned int words = bytes / sizeof(uint32_t);
    bytes = bytes % sizeof(unsigned int);
    unsigned int *p = (const uint32_t*)(data);
    while (words--) {
      hash = _mm_crc32_u32(hash, *p);
      ++p;
    }
    unsigned char *s = (const uint8_t*)(p);
    while (bytes--) {
      hash = _mm_crc32_u8(hash, *s);
      ++s;
    }
    return hash ^ 0xFFFFFFFF;
}

variable_types:
data
void *

variable_types:
bytes
unsigned int

variable_types:
hash
unsigned int

variable_types:
words
unsigned int

variable_types:
p
unsigned int *

variable_types:
s
unsigned char *

return_type: unsigned int


ParseEqMinus

repo: avtobiff/virtualagc

original_code:
int
ParseEqMinus (ParseInput_t *InRecord, ParseOutput_t *OutRecord)
{
  Address_t LabelValue = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  int i;
  OutRecord->ProgramCounter = InRecord->ProgramCounter;
  OutRecord->EBank = InRecord->EBank;
  OutRecord->SBank = InRecord->SBank;
  OutRecord->LabelValue.Invalid = 1;
  OutRecord->NumWords = 0;
  OutRecord->Equals = 1;
  if (*InRecord->Label == 0)
    {
      OutRecord->LabelValueValid = 0;
      return (0);
    }
  if (*InRecord->Operand == 0)
    {
      strcpy (OutRecord->ErrorMessage, "Missing operand.");
      OutRecord->Fatal = 1;
      return (0);
    }
  i = FetchSymbolPlusOffset (&InRecord->ProgramCounter,
      InRecord->Operand,
      InRecord->Mod1, &LabelValue);
  if (i)
    {
      sprintf(OutRecord->ErrorMessage, "Symbol \"%s\" undefined or offset bad", InRecord->Operand);
      OutRecord->Fatal = 1;
    }
  else
    {
      LabelValue.Invalid = 0;
      LabelValue.Constant = 1;
      LabelValue.Address = 0;
      LabelValue.Erasable = 0;
      LabelValue.Fixed = 0;
      LabelValue.Value = LabelValue.SReg - InRecord->ProgramCounter.SReg;
    }
  EditSymbolNew (InRecord->Label, &LabelValue, (8),
   CurrentFilename, CurrentLineInFile);
  OutRecord->LabelValue = LabelValue;
  return (0);
}

canonical_original_code:
int ParseEqMinus(struct ParseInput_t *InRecord, struct ParseOutput_t *OutRecord)
{
  struct Address_t LabelValue = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  int i;
  OutRecord->ProgramCounter = InRecord->ProgramCounter;
  OutRecord->EBank = InRecord->EBank;
  OutRecord->SBank = InRecord->SBank;
  OutRecord->LabelValue.Invalid = 1;
  OutRecord->NumWords = 0;
  OutRecord->Equals = 1;
  if (*InRecord->Label == 0)
    {
      OutRecord->LabelValueValid = 0;
      return (0);
    }
  if (*InRecord->Operand == 0)
    {
      strcpy (OutRecord->ErrorMessage, "Missing operand.");
      OutRecord->Fatal = 1;
      return (0);
    }
  i = FetchSymbolPlusOffset (&InRecord->ProgramCounter,
      InRecord->Operand,
      InRecord->Mod1, &LabelValue);
  if (i)
    {
      sprintf(OutRecord->ErrorMessage, "Symbol \"%s\" undefined or offset bad", InRecord->Operand);
      OutRecord->Fatal = 1;
    }
  else
    {
      LabelValue.Invalid = 0;
      LabelValue.Constant = 1;
      LabelValue.Address = 0;
      LabelValue.Erasable = 0;
      LabelValue.Fixed = 0;
      LabelValue.Value = LabelValue.SReg - InRecord->ProgramCounter.SReg;
    }
  EditSymbolNew (InRecord->Label, &LabelValue, (8),
   CurrentFilename, CurrentLineInFile);
  OutRecord->LabelValue = LabelValue;
  return (0);
}

variable_types: struct ParseInput_t { struct Address_t { unsigned int Invalid; unsigned int Constant; unsigned int Address; unsigned int SReg; unsigned int Erasable; unsigned int Fixed; unsigned int Unbanked; unsigned int Banked; unsigned int EB; unsigned int FB; unsigned int Super; unsigned int Overflow; int Value; int Syllable; } ProgramCounter; int Reserved; char *Label; int Index; unsigned int Extend; unsigned int IndexValid; struct EBank_t { int oneshotPending; struct Address_t current; struct Address_t last; } EBank; struct SBank_t { int oneshotPending; unsigned int current; unsigned int last; } SBank; char Column8; int InversionPending; int commentColumn; } *

variable_types: struct ParseOutput_t { struct Address_t ProgramCounter; int Reserved; int Words[2]; int NumWords; char ErrorMessage[-1]; struct Address_t LabelValue; int Index; unsigned int Warning; unsigned int Fatal; unsigned int LabelValueValid; unsigned int Extend; unsigned int IndexValid; struct EBank_t EBank; struct SBank_t SBank; int Equals; char Column8; } *

variable_types: i int

user_defined_types: struct ParseInput_t { struct Address_t ProgramCounter; int Reserved; char *Label; int Index; unsigned int Extend; unsigned int IndexValid; struct EBank_t EBank; struct SBank_t SBank; char Column8; int InversionPending; int commentColumn; }


decompiled_code:
void *ss7_get_version()
{
return &ss7_version;
}

canonical_decompiled_code:
void *func0()
{
return &ss7_version;
}

original_code:
const char *ss7_get_version(void)
{
 return ss7_version;
}

canonical_original_code:
char *ss7_get_version()
{
 return ss7_version;
}


die

repo: bobrippling/skype-chatlog-plaintext

decompiled_code:
void __noreturn die(char *s, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, s);
fprintf(_bss_start, "%s: ", (const char *)prog);
vfprintf(_bss_start, s, arg);
if ( s[strlen(s) - 1] == 58 )
{
fputc(32, _bss_start);
perror(0LL);
}
else
{
fputc(10, _bss_start);
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func7(char *s, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, s);
fprintf(_bss_start, "%s: ", (const char *)prog);
vfprintf(_bss_start, s, arg);
if ( s[strlen(s) - 1] == 58 )
{
fputc(32, _bss_start);
perror(0LL);
}
else
{
fputc(10, _bss_start);
}
exit(1);
}

original_code:
void die(const char *fmt, ...)
{
 va_list l;
 fprintf(stderr, "%s: ", prog);
 __builtin_va_start(l,fmt);
 vfprintf(stderr, fmt, l);
 __builtin_va_end(l);
 if(fmt[strlen(fmt)-1] == ':'){
  fputc(' ', stderr);
  perror(((void *)0));
 }else{
  fputc('\n', stderr);
 }
 exit(1);
}

canonical_original_code:
void die(char *fmt, ...)
{
 __builtin_va_list l;
 fprintf(stderr, "%s: ", prog);
 __builtin_va_start(l,fmt);
 vfprintf(stderr, fmt, l);
 __builtin_va_end(l);
 if(fmt[strlen(fmt)-1] == ':'){
  fputc(' ', stderr);
  perror(((void *)0));
 }else{
  fputc('\n', stderr);
 }
 exit(1);
}

variable_types:
fmt
char *


variable_types:
start
char *

variable_types: t long

return_type: long


decompiled_code:
char *__fastcall find_section(void *haystack, __int64 a2, __int64 a3, int a4)
{
const char *v5; // r14
size_t v6; // rbx
char *result; // rax
char *v8; // rbx

v5 = &sections[10 * a4];
v6 = strlen(v5);
result = (char *)memmem(haystack, a3 - ((unsigned __int64)haystack - a2), v5, v6);
v8 = &result[v6];
if ( result )
result = v8;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(void *haystack, __int64 a2, __int64 a3, int a4)
{
const char *v5; // r14
size_t v6; // rbx
char *result; // rax
char *v8; // rbx

v5 = &sections[10 * a4];
v6 = strlen(v5);
result = (char *)memmem(haystack, a3 - ((unsigned __int64)haystack - a2), v5, v6);
v8 = &result[v6];
if ( result )
result = v8;
return result;
}

original_code:
char *find_section(char *start, char *data, size_t len, int n)
{
 char *pos = memmem(start, len - (start - data), sections[n], strlen((const char *)sections[n]));
 if(!pos)
  return ((void *)0);
 return pos + strlen((const char *)sections[n]);
}

canonical_original_code:
char *find_section(char *start, char *data, unsigned long len, int n)
{
 char *pos = memmem(start, len - (start - data), sections[n], strlen((const char *)sections[n]));
 if(!pos)
  return ((void *)0);
 return pos + strlen((char *)sections[n]);
}

variable_types:
data
char *

variable_types:
len
unsigned long

variable_types: n int

variable_types:
pos
char *


decompiled_code:
char *__fastcall output_chat(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, const char *a6, char *s)
{
char *result; // rax

if ( strcmp(a2, a4) )
a3 = a2;
for ( result = strtok(s, "\n"); result; result = strtok(0LL, "\n") )
printf("%s: [%s] %s (%s) -> %s: %s\n", a1, a6, a4, a5, a3, result);
return result;
}

canonical_decompiled_code:
char *__fastcall func10(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, const char *a6, char *s)
{
char *result; // rax

if ( strcmp(a2, a4) )
a3 = a2;
for ( result = strtok(s, "\n"); result; result = strtok(0LL, "\n") )
printf("%s: [%s] %s (%s) -> %s: %s\n", a1, a6, a4, a5, a3, result);
return result;
}

original_code:
void output_chat(char *timestr, char *caller, char *recipients, char *sender, char *sendername, char *chatid, char *msg)
{
 char *tok;
 if (strcmp(caller, sender))
  recipients = caller;
 for(tok = strtok(msg, "\n"); tok; tok = strtok(((void *)0), "\n"))
  printf("%s: [%s] %s (%s) -> %s: %s\n", timestr, chatid, sender, sendername, recipients, tok);
}

variable_types:
timestr
char *

variable_types:
caller
char *

variable_types:
recipients
char *

variable_types:
sender
char *

variable_types:
sendername
char *

variable_types:
chatid
char *

variable_types:
msg
char *

variable_types:
tok
char *