getCommandLine

decompiled_code:
int __fastcall getCommandLine(_BYTE **a1, int a2)
{
_BYTE *v3; // r12
__int64 i; // rbp
int result; // eax
char v6; // bl

v3 = *a1;
**a1 = 0;
isReading = 1;
for ( i = 0LL; ; v3[i] = 0 )
{
result = getc(stdin);
v6 = result;
if ( (_BYTE)result == 10 || (_BYTE)result == 0xFF )
break;
if ( a2 == i )
{
a2 *= 2;
v3 = realloc(v3, a2 + 1);
}
v3[i++] = v6;
}
isReading = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func4(_BYTE **a1, int a2)
{
_BYTE *v3; // r12
__int64 i; // rbp
int result; // eax
char v6; // bl

v3 = *a1;
**a1 = 0;
isReading = 1;
for ( i = 0LL; ; v3[i] = 0 )
{
result = getc(stdin);
v6 = result;
if ( (_BYTE)result == 10 || (_BYTE)result == 0xFF )
break;
if ( a2 == i )
{
a2 *= 2;
v3 = realloc(v3, a2 + 1);
}
v3[i++] = v6;
}
isReading = 0;
return result;
}

original_code:
void getCommandLine(char** buf, int size)
 {
  char ch;
  size_t used=0;
  char* cmd = *buf;
  cmd[0] = '\0';
  isReading = 1;
  while (((ch = getc(stdin)) != (-1)) &&
         (ch != '\n'))
  {
   if (used == size)
   {
    size *= 2;
    cmd = realloc(cmd, sizeof(char)*(size+1));
   }
   cmd[used] = ch;
   used++;
   cmd[used] = '\0';
  }
  isReading = 0;
 }

canonical_original_code:
void getCommandLine(char **buf, int size)
 {
  char ch;
  unsigned long used = 0;
  char *cmd = *buf;
  cmd[0] = '\0';
  isReading = 1;
  while (((ch = getc(stdin)) != (-1)) &&
         (ch != '\n'))
  {
   if (used == size)
   {
    size *= 2;
    cmd = realloc(cmd, sizeof(char)*(size+1));
   }
   cmd[used] = ch;
   used++;
   cmd[used] = '\0';
  }
  isReading = 0;
 }

variable_types:
buf
char **

variable_types: ch char

variable_types:
used
unsigned long

variable_types:
cmd
char *


original_code:
void parser_single(char *c, int sz, commandT** cd, int bg)
{
  int i, task_argc = 0, quot1 = 0, quot2 = 0;
  char *in = ((void *)0), * out = ((void *)0), *tmp;
  int cmd_length;
  c[sz] = '\0';
  for(i = 0; i < sz; i++)
    if(c[i] != ' ') break;
  c = &(c[i]);
  sz = sz - i;
  cmd_length = sz;
  for(i = 0; i < sz; i++){
    if(c[i] == '\''){
      if(quot2) continue;
      else if(quot1){
 quot1 = 0;continue;
      }
      else quot1 = 1;
    }
    if(c[i] == '"'){
      if(quot1) continue;
      else if(quot2){
        quot2 = 0;continue;
      }
      else quot2 = 1;
    }
    if(c[i] == '<' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i + 1] == ' ') i++;
      in = &(c[i+1]);
    }
    if(c[i] == '>' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
      out = &(c[i+1]);
    }
    if(c[i] == ' ' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) task_argc++;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
    }
  }
  if(c[cmd_length - 1] != ' ') task_argc++;
  (*cd) = CreateCmdT(task_argc);
  (*cd) -> bg = bg;
  (*cd)->cmdline = strdup(c);
  tmp = c;
  for(i = 0; i < task_argc; i++){
    (*cd) -> argv[i] = strdup(single_param(tmp));
    while ((*tmp) != '\0') tmp++;
    tmp ++;
  }
  if(in){
    (*cd) -> is_redirect_in = 1;
    (*cd) -> redirect_in = strdup(single_param(in));
  }
  if(out){
    (*cd) -> is_redirect_out = 1;
    (*cd) -> redirect_out = strdup(single_param(out));
  }
}

canonical_original_code:
void parser_single(char *c, int sz, struct command_t **cd, int bg)
{
  int i; int task_argc = 0; int quot1 = 0; int quot2 = 0;
  char *in = ((void *)0); char *out = ((void *)0); char *tmp;
  int cmd_length;
  c[sz] = '\0';
  for(i = 0; i < sz; i++)
    if(c[i] != ' ') break;
  c = &(c[i]);
  sz = sz - i;
  cmd_length = sz;
  for(i = 0; i < sz; i++){
    if(c[i] == '\''){
      if(quot2) continue;
      else if(quot1){
 quot1 = 0;continue;
      }
      else quot1 = 1;
    }
    if(c[i] == '"'){
      if(quot1) continue;
      else if(quot2){
        quot2 = 0;continue;
      }
      else quot2 = 1;
    }
    if(c[i] == '<' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i + 1] == ' ') i++;
      in = &(c[i+1]);
    }
    if(c[i] == '>' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) cmd_length = i;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
      out = &(c[i+1]);
    }
    if(c[i] == ' ' && quot1 != 1 && quot2 != 1){
      if(cmd_length == sz) task_argc++;
      while(i < (sz - 1) && c[i+1] == ' ') i++;
    }
  }
  if(c[cmd_length - 1] != ' ') task_argc++;
  (*cd) = CreateCmdT(task_argc);
  (*cd) -> bg = bg;
  (*cd)->cmdline = strdup(c);
  tmp = c;
  for(i = 0; i < task_argc; i++){
    (*cd) -> argv[i] = strdup(single_param(tmp));
    while ((*tmp) != '\0') tmp++;
    tmp ++;
  }
  if(in){
    (*cd) -> is_redirect_in = 1;
    (*cd) -> redirect_in = strdup(single_param(in));
  }
  if(out){
    (*cd) -> is_redirect_out = 1;
    (*cd) -> redirect_out = strdup(single_param(out));
  }
}

variable_types:
c
char *

variable_types: sz int

variable_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; } **

variable_types: bg int

variable_types: i int

variable_types:
in
char *

variable_types:
out
char *

variable_types:
tmp
char *

return_type: void


Interpret

original_code:
void Interpret(char* cmdLine)
{
  int task = 1;
  int bg = 0, i,k,j = 0, quotation1 = 0, quotation2 = 0;
  commandT **command;
  if(cmdLine[0] == '\0') return;
  for(i = 0; i < strlen(cmdLine); i++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      task ++;
    }
  }
  command = (commandT **) malloc(sizeof(commandT *) * task);
  i = strlen(cmdLine) - 1;
  while(i >= 0 && cmdLine[i] == ' ') i--;
  if(cmdLine[i] == '&'){
    if(i == 0) return;
    bg = 1;
    cmdLine[i] = '\0';
  }
  quotation1 = quotation2 = 0;
  task = 0;
  k = strlen(cmdLine);
  for(i = 0; i < k; i++, j++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
      task++;
      j = -1;
    }
  }
  parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
  RunCmd(command, task+1);
  free(command);
}

canonical_original_code:
void Interpret(char *cmdLine)
{
  int task = 1;
  int bg = 0; int i; int k; int j = 0; int quotation1 = 0; int quotation2 = 0;
  struct command_t **command;
  if(cmdLine[0] == '\0') return;
  for(i = 0; i < strlen(cmdLine); i++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      task ++;
    }
  }
  command = (struct command_t **) malloc(sizeof(struct command_t *) * task);
  i = strlen(cmdLine) - 1;
  while(i >= 0 && cmdLine[i] == ' ') i--;
  if(cmdLine[i] == '&'){
    if(i == 0) return;
    bg = 1;
    cmdLine[i] = '\0';
  }
  quotation1 = quotation2 = 0;
  task = 0;
  k = strlen(cmdLine);
  for(i = 0; i < k; i++, j++){
    if(cmdLine[i] == '\''){
      if(quotation2) continue;
      else if(quotation1){
 quotation1 = 0;continue;
      }
      else quotation1 = 1;
    }
    if(cmdLine[i] == '"'){
      if(quotation1) continue;
      else if(quotation2){
        quotation2 = 0;continue;
      }
      else quotation2 = 1;
    }
    if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){
      parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
      task++;
      j = -1;
    }
  }
  parser_single(&(cmdLine[i-j]), j, &(command[task]),bg);
  RunCmd(command, task+1);
  free(command);
}

variable_types:
cmdLine
char *

variable_types: task int

variable_types: k int

variable_types: j int

user_defined_types: struct command_t { char *name; char *cmdline; char *redirect_in; int is_redirect_in; int bg; int argc; char *argv[]; }


repo: HeisSpiter/hepunion

decompiled_code:
int check_root_tree()
{
int result; // eax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

++run_tests;
if ( (unsigned int)stat("root/", &v1) == -1 )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: ", "hepunion_tests_tests.c", 22LL, "stat(\"root/\", &buf) != -1");
}
++run_tests;
if ( (v1.st_mode & 0xF000) != 0x4000 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
25LL,
"S_ISDIR(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 3 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
26LL,
"buf.st_nlink == 3",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: gid = %d\n", "hepunion_tests_tests.c", 27LL, "buf.st_gid == 0", v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: uid = %d\n", "hepunion_tests_tests.c", 28LL, "buf.st_uid == 0", v1.st_uid);
}
++run_tests;
if ( v1.st_blocks != 8 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
29LL,
"buf.st_blocks == 8",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size != 4096 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: size = %lu\n",
"hepunion_tests_tests.c",
30LL,
"buf.st_size == 4096",
v1.st_size);
}
++run_tests;
if ( (unsigned int)stat("root/ro_file", &v1) == -1 )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: ", "hepunion_tests_tests.c", 33LL, "stat(\"root/ro_file\", &buf) != -1");
}
++run_tests;
if ( (v1.st_mode & 0xF000) != 0x8000 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
36LL,
"S_ISREG(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 1 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
37LL,
"buf.st_nlink == 1",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: gid = %d\n", "hepunion_tests_tests.c", 38LL, "buf.st_gid == 0", v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: uid = %d\n", "hepunion_tests_tests.c", 39LL, "buf.st_uid == 0", v1.st_uid);
}
++run_tests;
if ( v1.st_blocks )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
40LL,
"buf.st_blocks == 0",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: size = %lu\n", "hepunion_tests_tests.c", 41LL, "buf.st_size == 0", v1.st_size);
}
++run_tests;
if ( (unsigned int)stat("root/ro_dir", &v1) == -1 )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: ", "hepunion_tests_tests.c", 44LL, "stat(\"root/ro_dir\", &buf) != -1");
}
++run_tests;
if ( (v1.st_mode & 0xF000) != 0x4000 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
47LL,
"S_ISDIR(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 2 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
48LL,
"buf.st_nlink == 2",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: gid = %d\n", "hepunion_tests_tests.c", 49LL, "buf.st_gid == 0", v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: uid = %d\n", "hepunion_tests_tests.c", 50LL, "buf.st_uid == 0", v1.st_uid);
}
++run_tests;
if ( v1.st_blocks != 8 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
51LL,
"buf.st_blocks == 8",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size != 4096 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: size = %lu\n",
"hepunion_tests_tests.c",
52LL,
"buf.st_size == 4096",
v1.st_size);
}
++run_tests;
if ( (unsigned int)stat("root/ro_dir/ro_file", &v1) == -1 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: ",
"hepunion_tests_tests.c",
55LL,
"stat(\"root/ro_dir/ro_file\", &buf) != -1");
}
++run_tests;
result = v1.st_mode & 0xF000;
if ( result != 0x8000 )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
58LL,
"S_ISREG(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 1 )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
59LL,
"buf.st_nlink == 1",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: gid = %d\n",
"hepunion_tests_tests.c",
60LL,
"buf.st_gid == 0",
v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: uid = %d\n",
"hepunion_tests_tests.c",
61LL,
"buf.st_uid == 0",
v1.st_uid);
}
++run_tests;
if ( v1.st_blocks )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
62LL,
"buf.st_blocks == 0",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: size = %lu\n",
"hepunion_tests_tests.c",
63LL,
"buf.st_size == 0",
v1.st_size);
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

++run_tests;
if ( (unsigned int)func12("root/", &v1) == -1 )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: ", "hepunion_tests_tests.c", 22LL, "stat(\"root/\", &buf) != -1");
}
++run_tests;
if ( (v1.st_mode & 0xF000) != 0x4000 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
25LL,
"S_ISDIR(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 3 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
26LL,
"buf.st_nlink == 3",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: gid = %d\n", "hepunion_tests_tests.c", 27LL, "buf.st_gid == 0", v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: uid = %d\n", "hepunion_tests_tests.c", 28LL, "buf.st_uid == 0", v1.st_uid);
}
++run_tests;
if ( v1.st_blocks != 8 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
29LL,
"buf.st_blocks == 8",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size != 4096 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: size = %lu\n",
"hepunion_tests_tests.c",
30LL,
"buf.st_size == 4096",
v1.st_size);
}
++run_tests;
if ( (unsigned int)func12("root/ro_file", &v1) == -1 )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: ", "hepunion_tests_tests.c", 33LL, "stat(\"root/ro_file\", &buf) != -1");
}
++run_tests;
if ( (v1.st_mode & 0xF000) != 0x8000 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
36LL,
"S_ISREG(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 1 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
37LL,
"buf.st_nlink == 1",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: gid = %d\n", "hepunion_tests_tests.c", 38LL, "buf.st_gid == 0", v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: uid = %d\n", "hepunion_tests_tests.c", 39LL, "buf.st_uid == 0", v1.st_uid);
}
++run_tests;
if ( v1.st_blocks )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
40LL,
"buf.st_blocks == 0",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: size = %lu\n", "hepunion_tests_tests.c", 41LL, "buf.st_size == 0", v1.st_size);
}
++run_tests;
if ( (unsigned int)func12("root/ro_dir", &v1) == -1 )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: ", "hepunion_tests_tests.c", 44LL, "stat(\"root/ro_dir\", &buf) != -1");
}
++run_tests;
if ( (v1.st_mode & 0xF000) != 0x4000 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
47LL,
"S_ISDIR(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 2 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
48LL,
"buf.st_nlink == 2",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: gid = %d\n", "hepunion_tests_tests.c", 49LL, "buf.st_gid == 0", v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
fprintf(stderr, "%s:%d \"%s\" failed: uid = %d\n", "hepunion_tests_tests.c", 50LL, "buf.st_uid == 0", v1.st_uid);
}
++run_tests;
if ( v1.st_blocks != 8 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
51LL,
"buf.st_blocks == 8",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size != 4096 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: size = %lu\n",
"hepunion_tests_tests.c",
52LL,
"buf.st_size == 4096",
v1.st_size);
}
++run_tests;
if ( (unsigned int)func12("root/ro_dir/ro_file", &v1) == -1 )
{
++failed_tests;
fprintf(
stderr,
"%s:%d \"%s\" failed: ",
"hepunion_tests_tests.c",
55LL,
"stat(\"root/ro_dir/ro_file\", &buf) != -1");
}
++run_tests;
result = v1.st_mode & 0xF000;
if ( result != 0x8000 )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: st_mode = %#X\n",
"hepunion_tests_tests.c",
58LL,
"S_ISREG(buf.st_mode)",
v1.st_mode);
}
++run_tests;
if ( v1.st_nlink != 1 )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: st_nlinks = %lu\n",
"hepunion_tests_tests.c",
59LL,
"buf.st_nlink == 1",
v1.st_nlink);
}
++run_tests;
if ( v1.st_gid )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: gid = %d\n",
"hepunion_tests_tests.c",
60LL,
"buf.st_gid == 0",
v1.st_gid);
}
++run_tests;
if ( v1.st_uid )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: uid = %d\n",
"hepunion_tests_tests.c",
61LL,
"buf.st_uid == 0",
v1.st_uid);
}
++run_tests;
if ( v1.st_blocks )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: blocks = %lu\n",
"hepunion_tests_tests.c",
62LL,
"buf.st_blocks == 0",
v1.st_blocks);
}
++run_tests;
if ( v1.st_size )
{
++failed_tests;
result = fprintf(
stderr,
"%s:%d \"%s\" failed: size = %lu\n",
"hepunion_tests_tests.c",
63LL,
"buf.st_size == 0",
v1.st_size);
}
return result;
}

original_code:
static void check_root_tree() {
 struct stat buf;
 ++run_tests; if (!(stat("root/", &buf) != -1)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "", "hepunion_tests_tests.c", 22, "stat(\"root/\", &buf) != -1"); };
 ++run_tests; if (!(((((buf.st_mode)) & 0170000) == (0040000)))) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_mode = %#X\n", "hepunion_tests_tests.c", 25, "S_ISDIR(buf.st_mode)", buf.st_mode); };
 ++run_tests; if (!(buf.st_nlink == 3)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_nlinks = %lu\n", "hepunion_tests_tests.c", 26, "buf.st_nlink == 3", buf.st_nlink); };
 ++run_tests; if (!(buf.st_gid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "gid = %d\n", "hepunion_tests_tests.c", 27, "buf.st_gid == 0", buf.st_gid); };
 ++run_tests; if (!(buf.st_uid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "uid = %d\n", "hepunion_tests_tests.c", 28, "buf.st_uid == 0", buf.st_uid); };
 ++run_tests; if (!(buf.st_blocks == 8)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "blocks = %lu\n", "hepunion_tests_tests.c", 29, "buf.st_blocks == 8", buf.st_blocks); };
 ++run_tests; if (!(buf.st_size == 4096)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "size = %lu\n", "hepunion_tests_tests.c", 30, "buf.st_size == 4096", buf.st_size); };
 ++run_tests; if (!(stat("root/ro_file", &buf) != -1)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "", "hepunion_tests_tests.c", 33, "stat(\"root/ro_file\", &buf) != -1"); };
 ++run_tests; if (!(((((buf.st_mode)) & 0170000) == (0100000)))) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_mode = %#X\n", "hepunion_tests_tests.c", 36, "S_ISREG(buf.st_mode)", buf.st_mode); };
 ++run_tests; if (!(buf.st_nlink == 1)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_nlinks = %lu\n", "hepunion_tests_tests.c", 37, "buf.st_nlink == 1", buf.st_nlink); };
 ++run_tests; if (!(buf.st_gid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "gid = %d\n", "hepunion_tests_tests.c", 38, "buf.st_gid == 0", buf.st_gid); };
 ++run_tests; if (!(buf.st_uid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "uid = %d\n", "hepunion_tests_tests.c", 39, "buf.st_uid == 0", buf.st_uid); };
 ++run_tests; if (!(buf.st_blocks == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "blocks = %lu\n", "hepunion_tests_tests.c", 40, "buf.st_blocks == 0", buf.st_blocks); };
 ++run_tests; if (!(buf.st_size == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "size = %lu\n", "hepunion_tests_tests.c", 41, "buf.st_size == 0", buf.st_size); };
 ++run_tests; if (!(stat("root/ro_dir", &buf) != -1)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "", "hepunion_tests_tests.c", 44, "stat(\"root/ro_dir\", &buf) != -1"); };
 ++run_tests; if (!(((((buf.st_mode)) & 0170000) == (0040000)))) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_mode = %#X\n", "hepunion_tests_tests.c", 47, "S_ISDIR(buf.st_mode)", buf.st_mode); };
 ++run_tests; if (!(buf.st_nlink == 2)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_nlinks = %lu\n", "hepunion_tests_tests.c", 48, "buf.st_nlink == 2", buf.st_nlink); };
 ++run_tests; if (!(buf.st_gid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "gid = %d\n", "hepunion_tests_tests.c", 49, "buf.st_gid == 0", buf.st_gid); };
 ++run_tests; if (!(buf.st_uid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "uid = %d\n", "hepunion_tests_tests.c", 50, "buf.st_uid == 0", buf.st_uid); };
 ++run_tests; if (!(buf.st_blocks == 8)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "blocks = %lu\n", "hepunion_tests_tests.c", 51, "buf.st_blocks == 8", buf.st_blocks); };
 ++run_tests; if (!(buf.st_size == 4096)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "size = %lu\n", "hepunion_tests_tests.c", 52, "buf.st_size == 4096", buf.st_size); };
 ++run_tests; if (!(stat("root/ro_dir/ro_file", &buf) != -1)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "", "hepunion_tests_tests.c", 55, "stat(\"root/ro_dir/ro_file\", &buf) != -1"); };
 ++run_tests; if (!(((((buf.st_mode)) & 0170000) == (0100000)))) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_mode = %#X\n", "hepunion_tests_tests.c", 58, "S_ISREG(buf.st_mode)", buf.st_mode); };
 ++run_tests; if (!(buf.st_nlink == 1)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "st_nlinks = %lu\n", "hepunion_tests_tests.c", 59, "buf.st_nlink == 1", buf.st_nlink); };
 ++run_tests; if (!(buf.st_gid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "gid = %d\n", "hepunion_tests_tests.c", 60, "buf.st_gid == 0", buf.st_gid); };
 ++run_tests; if (!(buf.st_uid == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "uid = %d\n", "hepunion_tests_tests.c", 61, "buf.st_uid == 0", buf.st_uid); };
 ++run_tests; if (!(buf.st_blocks == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "blocks = %lu\n", "hepunion_tests_tests.c", 62, "buf.st_blocks == 0", buf.st_blocks); };
 ++run_tests; if (!(buf.st_size == 0)) { ++failed_tests; fprintf(stderr, "%s:%d \"%s\" failed: " "size = %lu\n", "hepunion_tests_tests.c", 63, "buf.st_size == 0", buf.st_size); };
}

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]; }


decompiled_code:
int do_tests()
{
check_root_tree();
return fprintf(
_bss_start,
"%s:%d %u tests executed, %u failed\n",
"hepunion_tests_tests.c",
75LL,
(unsigned int)run_tests,
(unsigned int)failed_tests);
}

canonical_decompiled_code:
int func8()
{
func7();
return fprintf(
_bss_start,
"%s:%d %u tests executed, %u failed\n",
"hepunion_tests_tests.c",
75LL,
(unsigned int)run_tests,
(unsigned int)failed_tests);
}

original_code:
void do_tests(const char * working_dir) {
 (void)working_dir;
 check_root_tree();
 fprintf(stdout, "%s:%d " "%u tests executed, %u failed\n", "hepunion_tests_tests.c", 75, run_tests, failed_tests);
}

canonical_original_code:
void do_tests(char *working_dir) {
 (void)working_dir;
 check_root_tree();
 fprintf(stdout, "%s:%d " "%u tests executed, %u failed\n", "hepunion_tests_tests.c", 75, run_tests, failed_tests);
}


decompiled_code:
__int64 __fastcall check_tree_dir(char *src)
{
struct stat v2; // [rsp+0h] [rbp-1098h] BYREF
char dest[4104]; // [rsp+90h] [rbp-1008h] BYREF

strncpy(dest, src, 0x1000uLL);
return stat(dest, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src)
{
struct stat v2; // [rsp+0h] [rbp-1098h] BYREF
char dest[4104]; // [rsp+90h] [rbp-1008h] BYREF

strncpy(dest, src, 0x1000uLL);
return func12(dest, &v2);
}

original_code:
static inline int check_tree_dir(const char * path) {
 char current_dir[4096];
 struct stat buf;
 strncpy(current_dir, path, sizeof(current_dir) / sizeof(current_dir[0]));
 return stat(current_dir, &buf);
}

canonical_original_code:
static inline int check_tree_dir(char *path) {
 char current_dir[4096];
 struct stat buf;
 strncpy(current_dir, path, sizeof(current_dir) / sizeof(current_dir[0]));
 return stat(current_dir, &buf);
}

variable_types:
path
char *

return_type: int

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int *v4; // rbx
int *v5; // rbx
int *v6; // rbx
int *v7; // rbx
char v8[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( geteuid() )
{
fprintf(
stderr,
"%s:%d \"%s\" failed: %s",
"hepunion_tests_main.c",
24LL,
"geteuid() == 0",
"Please, run the program as root!\n");
return -13;
}
if ( argc <= 1 )
{
getcwd(v8, 0x1000uLL);
}
else
{
strncpy(v8, argv[1], 0x1000uLL);
if ( chdir(v8) == -1 )
{
v4 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: working_dir=\"%s\" errno=%d\n",
"hepunion_tests_main.c",
30LL,
"chdir(working_dir) != -1",
v8,
(unsigned int)*v4);
return -*v4;
}
}
fprintf(_bss_start, "%s:%d Will execute tests on: %s\n", "hepunion_tests_main.c", 36LL, v8);
if ( (unsigned int)check_tree_dir("export/") == -1 )
{
v5 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on export directory, errno = %d\n",
"hepunion_tests_main.c",
39LL,
"check_tree_dir(\"export/\") != -1",
(unsigned int)*v5);
result = -*v5;
}
else if ( (unsigned int)check_tree_dir("root/") == -1 )
{
v6 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on root directory, errno = %d\n",
"hepunion_tests_main.c",
40LL,
"check_tree_dir(\"root/\") != -1",
(unsigned int)*v6);
result = -*v6;
}
else if ( (unsigned int)check_tree_dir("snapshot/") == -1 )
{
v7 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on snapshot directory, errno = %d\n",
"hepunion_tests_main.c",
41LL,
"check_tree_dir(\"snapshot/\") != -1",
(unsigned int)*v7);
result = -*v7;
}
else
{
do_tests();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int *v4; // rbx
int *v5; // rbx
int *v6; // rbx
int *v7; // rbx
char v8[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( geteuid() )
{
fprintf(
stderr,
"%s:%d \"%s\" failed: %s",
"hepunion_tests_main.c",
24LL,
"geteuid() == 0",
"Please, run the program as root!\n");
return -13;
}
if ( argc <= 1 )
{
getcwd(v8, 0x1000uLL);
}
else
{
strncpy(v8, argv[1], 0x1000uLL);
if ( chdir(v8) == -1 )
{
v4 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: working_dir=\"%s\" errno=%d\n",
"hepunion_tests_main.c",
30LL,
"chdir(working_dir) != -1",
v8,
(unsigned int)*v4);
return -*v4;
}
}
fprintf(_bss_start, "%s:%d Will execute tests on: %s\n", "hepunion_tests_main.c", 36LL, v8);
if ( (unsigned int)func9("export/") == -1 )
{
v5 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on export directory, errno = %d\n",
"hepunion_tests_main.c",
39LL,
"check_tree_dir(\"export/\") != -1",
(unsigned int)*v5);
result = -*v5;
}
else if ( (unsigned int)func9("root/") == -1 )
{
v6 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on root directory, errno = %d\n",
"hepunion_tests_main.c",
40LL,
"check_tree_dir(\"root/\") != -1",
(unsigned int)*v6);
result = -*v6;
}
else if ( (unsigned int)func9("snapshot/") == -1 )
{
v7 = __errno_location();
fprintf(
stderr,
"%s:%d \"%s\" failed: Failed stat() on snapshot directory, errno = %d\n",
"hepunion_tests_main.c",
41LL,
"check_tree_dir(\"snapshot/\") != -1",
(unsigned int)*v7);
result = -*v7;
}
else
{
func8();
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 char working_dir[4096];
 if (!(geteuid() == 0)) { fprintf(stderr, "%s:%d \"%s\" failed: " "%s", "hepunion_tests_main.c", 24, "geteuid() == 0", "Please, run the program as root!\n"); return -13; };
 if (argc > 1) {
  strncpy(working_dir, argv[1], sizeof(working_dir) / sizeof(working_dir[0]));
  if (!(chdir(working_dir) != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "working_dir=\"%s\" errno=%d\n", "hepunion_tests_main.c", 30, "chdir(working_dir) != -1", working_dir, (*__errno_location ())); return -(*__errno_location ()); };
 } else {
  getcwd(working_dir, sizeof(working_dir));
 }
 fprintf(stdout, "%s:%d " "Will execute tests on: %s\n", "hepunion_tests_main.c", 36, working_dir);
 if (!(check_tree_dir("export/") != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "Failed stat() on export directory, errno = %d\n", "hepunion_tests_main.c", 39, "check_tree_dir(\"export/\") != -1", (*__errno_location ())); return -(*__errno_location ()); };
 if (!(check_tree_dir("root/") != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "Failed stat() on root directory, errno = %d\n", "hepunion_tests_main.c", 40, "check_tree_dir(\"root/\") != -1", (*__errno_location ())); return -(*__errno_location ()); };
 if (!(check_tree_dir("snapshot/") != -1)) { fprintf(stderr, "%s:%d \"%s\" failed: " "Failed stat() on snapshot directory, errno = %d\n", "hepunion_tests_main.c", 41, "check_tree_dir(\"snapshot/\") != -1", (*__errno_location ())); return -(*__errno_location ()); };
 do_tests(working_dir);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


blah

repo: Helmsfeld/C-Tutorium

decompiled_code:
char *blah()
{
char v1; // [rsp+0h] [rbp-10h] BYREF

*(double *)&g_re = *(double *)&g_re + 1.0;
*(double *)&g_im = *(double *)&g_im + 3.0;
return &v1;
}

canonical_decompiled_code:
char *func7()
{
char v1; // [rsp+0h] [rbp-10h] BYREF

*(double *)&g_re = *(double *)&g_re + 1.0;
*(double *)&g_im = *(double *)&g_im + 3.0;
return &v1;
}

original_code:
m_complex_p blah() {
    m_complex_p r = (double[]) {g_re,g_im};
    g_re += 1.0;
    g_im += 3.0;
    return r;
}

canonical_original_code:
double *blah() {
    double *r = (double[]) {g_re,g_im};
    g_re += 1.0;
    g_im += 3.0;
    return r;
}

variable_types:
r
double *

return_type: double *


main

original_code:
int main(int argc, const char * argv[])
{
    printf("g_re=%f, g_im=%f\n", g_re, g_im);
    m_complex_p a = blah();
    printf("g_re=%f, g_im=%f\n", g_re, g_im);
    m_complex_p b = blah();
    printf("g_re=%f, g_im=%f\n", g_re, g_im);
    printf("Erwarte: a = %f+%fi, b= %f+%fi\n", 2.0, 5.0, 3.0, 8.0);
    printf("Habe:    a = %f+%fi, b= %f+%fi\n", a[0], a[1], b[0], b[1]);
    a = (double[]) {2.0,3.0};
    b = (double[]) {4.0,5.0};
    a = kaputt_add(a,b);
    puts("Nach kaputt_add(a, b):");
    printf("Habe:    a = %f+%fi\n", a[0], a[1]);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    printf("g_re=%f, g_im=%f\n", g_re, g_im);
    double *a = blah();
    printf("g_re=%f, g_im=%f\n", g_re, g_im);
    double *b = blah();
    printf("g_re=%f, g_im=%f\n", g_re, g_im);
    printf("Erwarte: a = %f+%fi, b= %f+%fi\n", 2.0, 5.0, 3.0, 8.0);
    printf("Habe:    a = %f+%fi, b= %f+%fi\n", a[0], a[1], b[0], b[1]);
    a = (double []) {2.0,3.0};
    b = (double []) {4.0,5.0};
    a = kaputt_add(a,b);
    puts("Nach kaputt_add(a, b):");
    printf("Habe:    a = %f+%fi\n", a[0], a[1]);
    return 0;
}

variable_types:
argv
char *[]

variable_types:
a
double *

variable_types:
b
double *


decompiled_code:
void __fastcall m_add_with_extra_argument(double *a1, double *a2, double *a3)
{
*a3 = *a1 + *a2;
a3[1] = a1[1] + a2[1];
}

canonical_decompiled_code:
void __fastcall func7(double *a1, double *a2, double *a3)
{
*a3 = *a1 + *a2;
a3[1] = a1[1] + a2[1];
}

original_code:
void m_add_with_extra_argument(m_complex_p a, m_complex_p b, m_complex_p r)
{
    r[0] = a[0] + b[0];
    r[1] = a[1] + b[1];
}

canonical_original_code:
void m_add_with_extra_argument(double *a, double *b, double *r)
{
    r[0] = a[0] + b[0];
    r[1] = a[1] + b[1];
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double *v3; // rbx
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
__int64 v7; // [rsp+18h] [rbp-20h]
double v8; // [rsp+20h] [rbp-18h] BYREF
double v9; // [rsp+28h] [rbp-10h]

v5[0] = 0x4000000000000000LL;
v5[1] = 0x4008000000000000LL;
v6 = 0x4018000000000000LL;
v7 = 0x3FF0000000000000LL;
v8 = 0.0;
v9 = 0.0;
m_add_with_extra_argument((double *)v5, (double *)&v6, &v8);
printf("a+b = r1 = %f+%fi\n", v8, v9);
v3 = m_add_with_malloc((double *)v5, (double *)&v6);
printf("a+b = r2 = %f+%fi\n", *v3, v3[1]);
free(v3);
printf("b = %f+%fi, c = %f+%fi\n", *(double *)&v6, *(double *)&v7, *(double *)&v6, *(double *)&v7);
v6 = 0xC059000000000000LL;
puts("Anderung von c bewirkt nun auch aenderung von b!");
printf("b = %f+%fi, c = %f+%fi\n", *(double *)&v6, *(double *)&v7, *(double *)&v6, *(double *)&v7);
return 0;
}

original_code:
int main(void)
{
    m_complex_p a = (double[]){2.0, 3.0};
    m_complex_p b = (double[]){6.0, 1.0};
    m_complex_p c = b;
    m_complex_p r1 = (double[]){0.0, 0.0};
    m_complex_p r2;
    m_add_with_extra_argument(a, b, r1);
    printf("a+b = r1 = %f+%fi\n", r1[0], r1[1]);
    r2 = m_add_with_malloc(a, b);
    printf("a+b = r2 = %f+%fi\n", r2[0], r2[1]);
    free(r2);
    printf("b = %f+%fi, c = %f+%fi\n", b[0], b[1], c[0], c[1]);
    c[0] = -100.0;
    puts("Anderung von c bewirkt nun auch aenderung von b!");
    printf("b = %f+%fi, c = %f+%fi\n", b[0], b[1], c[0], c[1]);
    return 0;
}

canonical_original_code:
int main()
{
    double *a = (double[]){2.0, 3.0};
    double *b = (double[]){6.0, 1.0};
    double *c = b;
    double *r1 = (double[]){0.0, 0.0};
    double *r2;
    m_add_with_extra_argument(a, b, r1);
    printf("a+b = r1 = %f+%fi\n", r1[0], r1[1]);
    r2 = m_add_with_malloc(a, b);
    printf("a+b = r2 = %f+%fi\n", r2[0], r2[1]);
    free(r2);
    printf("b = %f+%fi, c = %f+%fi\n", b[0], b[1], c[0], c[1]);
    c[0] = -100.0;
    puts("Anderung von c bewirkt nun auch aenderung von b!");
    printf("b = %f+%fi, c = %f+%fi\n", b[0], b[1], c[0], c[1]);
    return 0;
}

variable_types:
c
double *


error

repo: Helmsfeld/turing

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

original_code:
void error(char *err_msg) {
 fprintf(stderr, "%s", err_msg);
 exit(1);
}


getSymbolIndex

decompiled_code:
__int64 __fastcall getSymbolIndex(char a1)
{
char v1; // dl
__int64 v2; // rax
unsigned int v3; // ecx

v1 = symbols[0];
if ( symbols[0] == a1 || !symbols[0] )
{
v3 = 0;
}
else
{
v2 = 1LL;
do
{
v3 = v2;
v1 = symbols[v2++];
}
while ( v1 != a1 && v1 );
}
if ( !v1 )
{
fprintf(stderr, "getSymbolIndex: Request for undefined symbol: %c\n", (unsigned int)a1);
exit(1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
char v1; // dl
__int64 v2; // rax
unsigned int v3; // ecx

v1 = symbols[0];
if ( symbols[0] == a1 || !symbols[0] )
{
v3 = 0;
}
else
{
v2 = 1LL;
do
{
v3 = v2;
v1 = symbols[v2++];
}
while ( v1 != a1 && v1 );
}
if ( !v1 )
{
fprintf(stderr, "getSymbolIndex: Request for undefined symbol: %c\n", (unsigned int)a1);
exit(1);
}
return v3;
}

original_code:
int getSymbolIndex(char symbol) {
 int i=0;
 while (symbols[i] != '\0' && symbols[i] != symbol) i++;
 if (symbols[i] == '\0') {
  fprintf(stderr, "getSymbolIndex: Request for"
   " undefined symbol: %c\n", symbol);
  exit(1);
 }
 return i;
}

canonical_original_code:
int getSymbolIndex(char symbol) {
 int i = 0;
 while (symbols[i] != '\0' && symbols[i] != symbol) i++;
 if (symbols[i] == '\0') {
  fprintf(stderr, "getSymbolIndex: Request for"
   " undefined symbol: %c\n", symbol);
  exit(1);
 }
 return i;
}

variable_types: symbol char

variable_types: i int


printTape

decompiled_code:
int printTape()
{
int i; // ebx
int v1; // ebx

if ( strlen(&tape) >= current_head_pos + 1 )
{
printf("%s#", &tape);
}
else
{
printf("%s", &tape);
for ( i = strlen(&tape); current_head_pos >= i; ++i )
putchar(35);
}
printf("... (%i)\n", (unsigned int)current_state);
if ( current_head_pos > 0 )
{
v1 = 0;
do
{
putchar(32);
++v1;
}
while ( current_head_pos > v1 );
}
return puts("^");
}

canonical_decompiled_code:
int func9()
{
int i; // ebx
int v1; // ebx

if ( strlen(&tape) >= current_head_pos + 1 )
{
printf("%s#", &tape);
}
else
{
printf("%s", &tape);
for ( i = strlen(&tape); current_head_pos >= i; ++i )
putchar(35);
}
printf("... (%i)\n", (unsigned int)current_state);
if ( current_head_pos > 0 )
{
v1 = 0;
do
{
putchar(32);
++v1;
}
while ( current_head_pos > v1 );
}
return puts("^");
}

original_code:
void printTape() {
 if (strlen(tape) < current_head_pos+1){
  printf("%s", tape);
  for (int i=strlen(tape); i<= current_head_pos; i++)
   printf("#");
 } else {
  printf("%s#", tape);
 }
 printf("... (%i)\n", current_state);
 for (int i=0; i<current_head_pos; i++)
  printf(" ");
 printf("^\n");
}

canonical_original_code:
void printTape() {
 if (strlen(tape) < current_head_pos+1){
  printf("%s", tape);
  for (int i = strlen(tape); i<= current_head_pos; i++)
   printf("#");
 } else {
  printf("%s#", tape);
 }
 printf("... (%i)\n", current_state);
 for (int i = 0; i<current_head_pos; i++)
  printf(" ");
 printf("^\n");
}


printTransitionTable

decompiled_code:
int printTransitionTable()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rbx
int result; // eax

if ( number_of_symbols > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
printf("%c ", (unsigned int)symbols[v1]);
if ( number_of_states > 0 )
{
v2 = 0LL;
do
{
printf("%i %c ", (unsigned int)transition_table[2 * v2 + v0], (unsigned int)byte_404164[8 * v2 + v0 * 4]);
++v2;
}
while ( number_of_states > (int)v2 );
}
result = putchar(10);
++v1;
v0 += 200LL;
}
while ( number_of_symbols > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int func10()
{
__int64 v0; // rbp
__int64 v1; // r12
__int64 v2; // rbx
int result; // eax

if ( number_of_symbols > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
printf("%c ", (unsigned int)symbols[v1]);
if ( number_of_states > 0 )
{
v2 = 0LL;
do
{
printf("%i %c ", (unsigned int)transition_table[2 * v2 + v0], (unsigned int)byte_404164[8 * v2 + v0 * 4]);
++v2;
}
while ( number_of_states > (int)v2 );
}
result = putchar(10);
++v1;
v0 += 200LL;
}
while ( number_of_symbols > (int)v1 );
}
return result;
}

original_code:
void printTransitionTable() {
 for (int i=0; i<number_of_symbols; i++) {
  printf("%c ", symbols[i]);
  for (int j=0; j<number_of_states; j++) {
   printf("%i %c ", transition_table[i][j].newstate, transition_table[i][j].mvwr);
  }
  printf("\n");
 }
}

canonical_original_code:
void printTransitionTable() {
 for (int i = 0; i<number_of_symbols; i++) {
  printf("%c ", symbols[i]);
  for (int j = 0; j<number_of_states; j++) {
   printf("%i %c ", transition_table[i][j].newstate, transition_table[i][j].mvwr);
  }
  printf("\n");
 }
}


initTM

decompiled_code:
int initTM()
{
size_t v0; // rax
int v1; // er12
int v2; // eax
__int64 v3; // rbp
unsigned int v4; // ebx
char v6; // [rsp+Ah] [rbp-1Eh]
char v7; // [rsp+Bh] [rbp-1Dh]
unsigned int v8; // [rsp+Ch] [rbp-1Ch]

__isoc99_scanf();
if ( number_of_states > 100 )
{
fprintf(stderr, "Maximal %i states are allowed, got %i", 100LL, (unsigned int)number_of_states);
exit(1);
}
__isoc99_scanf();
printf("Read symbols: %s\n", symbols);
v0 = strlen(symbols);
number_of_symbols = v0;
printf("Number of symbols: %i\n", v0);
if ( number_of_symbols > 0 )
{
v1 = 0;
do
{
__isoc99_scanf();
printf("Reading line for %c\n", (unsigned int)v6);
if ( v6 == 33 )
{
while ( fgetc(stdin) != 10 )
;
--v1;
}
else
{
v2 = getSymbolIndex(v6);
if ( number_of_states > 0 )
{
v3 = 200LL * v2;
v4 = 0;
do
{
__isoc99_scanf();
printf("Reading for(%i,%c) -> state: %i\n", v4, (unsigned int)v6, v8);
__isoc99_scanf();
printf("Reading for(%i,%c) -> movement/write: %c\n", v4, (unsigned int)v6, (unsigned int)v7);
transition_table[v3] = v8;
byte_404164[v3 * 4] = v7;
++v4;
v3 += 2LL;
}
while ( number_of_states > (int)v4 );
}
__isoc99_scanf();
}
++v1;
}
while ( number_of_symbols > v1 );
}
puts("Reading initial tape");
__isoc99_scanf();
printf("Tape: %s\n", &tape);
__isoc99_scanf();
__isoc99_scanf();
printf("Initial head position: %i\n", (unsigned int)current_head_pos);
printTape();
return printTransitionTable();
}

canonical_decompiled_code:
int func11()
{
size_t v0; // rax
int v1; // er12
int v2; // eax
__int64 v3; // rbp
unsigned int v4; // ebx
char v6; // [rsp+Ah] [rbp-1Eh]
char v7; // [rsp+Bh] [rbp-1Dh]
unsigned int v8; // [rsp+Ch] [rbp-1Ch]

__isoc99_scanf();
if ( number_of_states > 100 )
{
fprintf(stderr, "Maximal %i states are allowed, got %i", 100LL, (unsigned int)number_of_states);
exit(1);
}
__isoc99_scanf();
printf("Read symbols: %s\n", symbols);
v0 = strlen(symbols);
number_of_symbols = v0;
printf("Number of symbols: %i\n", v0);
if ( number_of_symbols > 0 )
{
v1 = 0;
do
{
__isoc99_scanf();
printf("Reading line for %c\n", (unsigned int)v6);
if ( v6 == 33 )
{
while ( fgetc(stdin) != 10 )
;
--v1;
}
else
{
v2 = func8(v6);
if ( number_of_states > 0 )
{
v3 = 200LL * v2;
v4 = 0;
do
{
__isoc99_scanf();
printf("Reading for(%i,%c) -> state: %i\n", v4, (unsigned int)v6, v8);
__isoc99_scanf();
printf("Reading for(%i,%c) -> movement/write: %c\n", v4, (unsigned int)v6, (unsigned int)v7);
transition_table[v3] = v8;
byte_404164[v3 * 4] = v7;
++v4;
v3 += 2LL;
}
while ( number_of_states > (int)v4 );
}
__isoc99_scanf();
}
++v1;
}
while ( number_of_symbols > v1 );
}
puts("Reading initial tape");
__isoc99_scanf();
printf("Tape: %s\n", &tape);
__isoc99_scanf();
__isoc99_scanf();
printf("Initial head position: %i\n", (unsigned int)current_head_pos);
func9();
return func10();
}

original_code:
void initTM(){
 scanf("%i", &number_of_states);
 if (number_of_states > 100) {
  fprintf(stderr, "Maximal %i "
   "states are allowed, got %i", 100,
   number_of_states);
  exit(1);
 }
 scanf("%s\n", symbols);
 printf("Read symbols: %s\n", symbols);
 number_of_symbols = strlen(symbols);
 printf("Number of symbols: %i\n", number_of_symbols);
 for (int i=0; i<number_of_symbols; i++) {
  char t_sym;
  scanf("%c", &t_sym);
  printf("Reading line for %c\n", t_sym);
  if (t_sym == '!') {
   while (fgetc(stdin) != '\n') ;
   i--;
   continue;
  }
  int t_row = getSymbolIndex(t_sym);
  for (int j=0; j<number_of_states; j++) {
   int t_nstate;
   scanf(" %d", &t_nstate);
   printf("Reading for(%i,%c) -> state: %i\n", j, t_sym, t_nstate);
   char t_mvwr;
   scanf(" %c", &t_mvwr);
   printf("Reading for(%i,%c) -> movement/write: %c\n", j, t_sym, t_mvwr);
   transition newTrans = (transition) {.newstate = t_nstate,
    .mvwr = t_mvwr};
   transition_table[t_row][j] = newTrans;
  }
  char blah;
  scanf("%c", &blah);
 }
 printf("Reading initial tape\n");
 scanf("%s", tape);
 printf("Tape: %s\n", tape);
 scanf("\n");
 scanf("%i", &current_head_pos);
 printf("Initial head position: %i\n", current_head_pos);
 printTape();
 printTransitionTable();
}

canonical_original_code:
void initTM(){
 scanf("%i", &number_of_states);
 if (number_of_states > 100) {
  fprintf(stderr, "Maximal %i "
   "states are allowed, got %i", 100,
   number_of_states);
  exit(1);
 }
 scanf("%s\n", symbols);
 printf("Read symbols: %s\n", symbols);
 number_of_symbols = strlen(symbols);
 printf("Number of symbols: %i\n", number_of_symbols);
 for (int i = 0; i<number_of_symbols; i++) {
  char t_sym;
  scanf("%c", &t_sym);
  printf("Reading line for %c\n", t_sym);
  if (t_sym == '!') {
   while (fgetc(stdin) != '\n') ;
   i--;
   continue;
  }
  int t_row = getSymbolIndex(t_sym);
  for (int j = 0; j<number_of_states; j++) {
   int t_nstate;
   scanf(" %d", &t_nstate);
   printf("Reading for(%i,%c) -> state: %i\n", j, t_sym, t_nstate);
   char t_mvwr;
   scanf(" %c", &t_mvwr);
   printf("Reading for(%i,%c) -> movement/write: %c\n", j, t_sym, t_mvwr);
   struct transition newTrans = (transition) {.newstate = t_nstate,
    .mvwr = t_mvwr};
   transition_table[t_row][j] = newTrans;
  }
  char blah;
  scanf("%c", &blah);
 }
 printf("Reading initial tape\n");
 scanf("%s", tape);
 printf("Tape: %s\n", tape);
 scanf("\n");
 scanf("%i", &current_head_pos);
 printf("Initial head position: %i\n", current_head_pos);
 printTape();
 printTransitionTable();
}

variable_types: struct transition { int newstate; char mvwr; }

variable_types: blah char


executeTM

decompiled_code:
int executeTM()
{
unsigned int v0; // ebx
__int64 v1; // rax
int v2; // esi
char v3; // al
int v4; // eax
int v5; // edx

if ( current_state >= number_of_states )
{
v0 = 0;
}
else
{
v0 = 0;
do
{
v1 = 5LL * (int)getSymbolIndex(tape[current_head_pos]);
v2 = transition_table[40 * v1 + 2 * current_state];
v3 = byte_404164[160 * v1 + 8 * current_state];
if ( v3 == 76 )
{
if ( current_head_pos > 0 )
--current_head_pos;
}
else if ( v3 == 82 )
{
v4 = current_head_pos;
if ( current_head_pos <= 99 )
{
v5 = current_head_pos + 1;
current_head_pos = v5;
if ( !tape[v5] )
{
tape[v5] = 35;
tape[v4 + 2] = 0;
}
}
}
else
{
tape[current_head_pos] = v3;
}
current_state = v2;
printf("Step %i\n", ++v0);
printTape();
__isoc99_scanf();
}
while ( current_state < number_of_states );
}
return printf("Execution stopped after %i steps.\n", v0);
}

canonical_decompiled_code:
int func12()
{
unsigned int v0; // ebx
__int64 v1; // rax
int v2; // esi
char v3; // al
int v4; // eax
int v5; // edx

if ( current_state >= number_of_states )
{
v0 = 0;
}
else
{
v0 = 0;
do
{
v1 = 5LL * (int)func8(tape[current_head_pos]);
v2 = transition_table[40 * v1 + 2 * current_state];
v3 = byte_404164[160 * v1 + 8 * current_state];
if ( v3 == 76 )
{
if ( current_head_pos > 0 )
--current_head_pos;
}
else if ( v3 == 82 )
{
v4 = current_head_pos;
if ( current_head_pos <= 99 )
{
v5 = current_head_pos + 1;
current_head_pos = v5;
if ( !tape[v5] )
{
tape[v5] = 35;
tape[v4 + 2] = 0;
}
}
}
else
{
tape[current_head_pos] = v3;
}
current_state = v2;
printf("Step %i\n", ++v0);
func9();
__isoc99_scanf();
}
while ( current_state < number_of_states );
}
return printf("Execution stopped after %i steps.\n", v0);
}

original_code:
void executeTM() {
 int steps = 0;
 while (current_state < number_of_states) {
  transition curr_trans = transition_table[getSymbolIndex(tape[current_head_pos])][current_state];
  if (curr_trans.mvwr == 'L' ) {
   if ( current_head_pos > 0)
    current_head_pos--;
  } else if (curr_trans.mvwr == 'R') {
   if (current_head_pos < 100) {
    current_head_pos++;
    if (tape[current_head_pos] == '\0') {
      tape[current_head_pos] = '#';
      tape[current_head_pos+1] = '\0';
    }
   }
  } else {
   tape[current_head_pos] = curr_trans.mvwr;
  }
  current_state = curr_trans.newstate;
  printf("Step %i\n", ++steps);
  printTape();
  char tmp;
  scanf("%c", &tmp);
 }
 printf("Execution stopped after %i steps.\n", steps);
}

canonical_original_code:
void executeTM() {
 int steps = 0;
 while (current_state < number_of_states) {
  struct transition curr_trans = transition_table[getSymbolIndex(tape[current_head_pos])][current_state];
  if (curr_trans.mvwr == 'L' ) {
   if ( current_head_pos > 0)
    current_head_pos--;
  } else if (curr_trans.mvwr == 'R') {
   if (current_head_pos < 100) {
    current_head_pos++;
    if (tape[current_head_pos] == '\0') {
      tape[current_head_pos] = '#';
      tape[current_head_pos+1] = '\0';
    }
   }
  } else {
   tape[current_head_pos] = curr_trans.mvwr;
  }
  current_state = curr_trans.newstate;
  printf("Step %i\n", ++steps);
  printTape();
  char tmp;
  scanf("%c", &tmp);
 }
 printf("Execution stopped after %i steps.\n", steps);
}

variable_types: steps int

variable_types: tmp char

user_defined_types: struct transition { int newstate; char mvwr; }


main

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func11();
func12();
return 0;
}

original_code:
int main(void) {
 initTM();
 executeTM();
}

canonical_original_code:
int main() {
 initTM();
 executeTM();
}


repo: HeroicKatora/USim

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rdi
struct tm *v5; // rax
char *v6; // rax
unsigned int i; // ebp
__int64 v8; // rbx
struct tm *v9; // rax
char *v10; // rax
int result; // eax
int *v12; // rbx
char *v13; // r8
int *v14; // rbx
char *v15; // r8
time_t v16; // [rsp+0h] [rbp-28h] BYREF
__int64 v17[4]; // [rsp+8h] [rbp-20h] BYREF

puts("##### DEBUG VERSION #####");
v3 = state_create_empty(8000LL, argv, 30000.0, 10000.0);
v17[0] = v3;
if ( v3 )
{
v4 = state_init_random(v3);
v17[0] = v4;
if ( v4 )
{
state_write(v4);
v16 = time(0LL);
v5 = localtime(&v16);
v6 = asctime(v5);
printf("Gestartet um: %s\n", v6);
for ( i = 0; i != 500; printf("State %i um: %s\n", i, v10) )
{
v8 = get_next_state(v17[0], 1.0);
state_write(v8);
state_free(v17);
v17[0] = v8;
v16 = time(0LL);
v9 = localtime(&v16);
v10 = asctime(v9);
++i;
}
result = 0;
}
else
{
v14 = _errno_location();
v15 = "None";
if ( *v14 )
v15 = strerror(*v14);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "main.c", 17LL, v15);
*v14 = 0;
result = 1;
}
}
else
{
v12 = _errno_location();
v13 = "None";
if ( *v12 )
v13 = strerror(*v12);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "main.c", 15LL, v13);
*v12 = 0;
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
  printf("##### DEBUG VERSION #####\n");
  int c = (8000);
  Sim_state *state = state_create_empty(c, (double)30000.0, 10000);
  if(!((state))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "main.c", 15, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  state = state_init_random(state);
  if(!((state))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "main.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  state_write(state);
  time_t t;
  t = time (((void *)0));
  printf("Gestartet um: %s\n", asctime(localtime(&t)));
  int rec = 0;
  for(rec = 0;rec < 500;rec++){
   Sim_state *state_new = get_next_state(state, (double)1.0);
   state_write(state_new);
   state_free(&state);
   state = state_new;
   t = time(((void *)0));
   printf("State %i um: %s\n",rec+1, asctime(localtime(&t)));
  }
  return 0;
error:
  return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
  printf("##### DEBUG VERSION #####\n");
  int c = (8000);
  struct Sim_state *state = state_create_empty(c, (double)30000.0, 10000);
  if(!((state))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "main.c", 15, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  state = state_init_random(state);
  if(!((state))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "main.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  state_write(state);
  long t;
  t = time (((void *)0));
  printf("Gestartet um: %s\n", asctime(localtime(&t)));
  int rec = 0;
  for(rec = 0;rec < 500;rec++){
   struct Sim_state *state_new = get_next_state(state, (double)1.0);
   state_write(state_new);
   state_free(&state);
   state = state_new;
   t = time(((void *)0));
   printf("State %i um: %s\n",rec+1, asctime(localtime(&t)));
  }
  return 0;
error:
  return 1;
}

variable_types: c int

variable_types: struct Sim_state { double box_size; double mass_multiplier; int count; int step_count; struct Particle { double mass; struct Vector { double x; double y; double z; } *position; struct Vector *speed; struct Vector *speed_old; } **particles; } *

variable_types: t long

variable_types: rec int

user_defined_types: struct Sim_state { double box_size; double mass_multiplier; int count; int step_count; struct Particle **particles; }

user_defined_types: struct Particle { double mass; struct Vector *position; struct Vector *speed; struct Vector *speed_old; }


original_code:
Particle *particle_join(Particle *a, Particle *b, Particle *write){
 Vector pos_dif;
 vector_sub(b->position, a->position, &pos_dif);
 vector_shorten_in_cube(&pos_dif, &pos_dif);
 vector_mul_true(&pos_dif,1-(a->mass/(a->mass+b->mass)));
 vector_add_true(a->position, &pos_dif);
 vector_to_unitcube(a->position);
 Vector movA,movB;
 vector_mul(a->speed,a->mass,&movA);
 vector_mul(b->speed,b->mass,&movB);
 vector_add_true(&movA, &movB);
 *(a->speed) = movA;
 vector_div_true(a->speed, a->mass+ b->mass);
 vector_mul(a->speed_old,a->mass,&movA);
 vector_mul(b->speed_old,b->mass,&movB);
 vector_add_true(&movA, &movB);
 *(a->speed_old) = movA;
 vector_div_true(a->speed_old, a->mass+ b->mass);
 a->mass = a->mass+b->mass;
 b->position->x = 0;
 b->position->y = 0;
 b->position->z = 0;
 b->mass = 0;
 return a;
}

canonical_original_code:
struct Particle *particle_join(struct Particle *a, struct Particle *b, struct Particle *write){
 struct Vector pos_dif;
 vector_sub(b->position, a->position, &pos_dif);
 vector_shorten_in_cube(&pos_dif, &pos_dif);
 vector_mul_true(&pos_dif,1-(a->mass/(a->mass+b->mass)));
 vector_add_true(a->position, &pos_dif);
 vector_to_unitcube(a->position);
 struct Vector movA; struct Vector movB;
 vector_mul(a->speed,a->mass,&movA);
 vector_mul(b->speed,b->mass,&movB);
 vector_add_true(&movA, &movB);
 *(a->speed) = movA;
 vector_div_true(a->speed, a->mass+ b->mass);
 vector_mul(a->speed_old,a->mass,&movA);
 vector_mul(b->speed_old,b->mass,&movB);
 vector_add_true(&movA, &movB);
 *(a->speed_old) = movA;
 vector_div_true(a->speed_old, a->mass+ b->mass);
 a->mass = a->mass+b->mass;
 b->position->x = 0;
 b->position->y = 0;
 b->position->z = 0;
 b->mass = 0;
 return a;
}

variable_types:
a
struct Particle *

variable_types:
b
struct Particle *

variable_types:
write
struct Particle *

return_type: struct Particle { double mass; struct Vector { double x; double y; double z; } *position; struct Vector *speed; struct Vector *speed_old; } *


decompiled_code:
void __fastcall particle_free(void **a1)
{
_QWORD *v2; // rdi

v2 = *a1;
if ( v2 )
{
if ( v2[1] )
vector_free(v2 + 1);
if ( *((_QWORD *)*a1 + 2) )
vector_free((char *)*a1 + 16);
if ( *((_QWORD *)*a1 + 3) )
vector_free((char *)*a1 + 24);
free(*a1);
}
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
_QWORD *v2; // rdi

v2 = *a1;
if ( v2 )
{
if ( v2[1] )
vector_free(v2 + 1);
if ( *((_QWORD *)*a1 + 2) )
vector_free((char *)*a1 + 16);
if ( *((_QWORD *)*a1 + 3) )
vector_free((char *)*a1 + 24);
free(*a1);
}
*a1 = 0LL;
}

original_code:
void particle_free(Particle **p)
{
  if(*p){
    if((*p)->position) vector_free(&(*p)->position);
    if((*p)->speed) vector_free(&(*p)->speed);
    if((*p)->speed_old) vector_free(&(*p)->speed_old);
    free(*p);
  }
  *p = ((void *)0);
}

canonical_original_code:
void particle_free(struct Particle **p)
{
  if(*p){
    if((*p)->position) vector_free(&(*p)->position);
    if((*p)->speed) vector_free(&(*p)->speed);
    if((*p)->speed_old) vector_free(&(*p)->speed_old);
    free(*p);
  }
  *p = ((void *)0);
}

variable_types: struct Particle { double mass; struct Vector { double x; double y; double z; } *position; struct Vector *speed; struct Vector *speed_old; } **


decompiled_code:
double *__fastcall particle_create(double a1, double a2, double a3, double a4)
{
double *v4; // rax
int *v6; // rbx
char *v7; // r8
int *v8; // rbx
char *v9; // r8
int *v10; // rbx
char *v11; // r8
int *v12; // rbx
char *v13; // r8
double *v14; // [rsp+8h] [rbp-30h] BYREF

v4 = (double *)malloc(0x20uLL);
v14 = v4;
if ( v4 )
{
*((_QWORD *)v4 + 1) = vector_create(a1, a2, a3);
if ( *((_QWORD *)v14 + 1) )
{
*((_QWORD *)v14 + 2) = vector_create(0.0, 0.0, 0.0);
if ( *((_QWORD *)v14 + 2) )
{
*((_QWORD *)v14 + 3) = vector_create(0.0, 0.0, 0.0);
if ( *((_QWORD *)v14 + 3) )
{
*v14 = a4;
return v14;
}
v12 = _errno_location();
v13 = "None";
if ( *v12 )
v13 = strerror(*v12);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 17LL, v13);
*v12 = 0;
}
else
{
v10 = _errno_location();
v11 = "None";
if ( *v10 )
v11 = strerror(*v10);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 14LL, v11);
*v10 = 0;
}
}
else
{
v8 = _errno_location();
v9 = "None";
if ( *v8 )
v9 = strerror(*v8);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 11LL, v9);
*v8 = 0;
}
}
else
{
v6 = _errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 8LL, v7);
*v6 = 0;
}
particle_free((void **)&v14);
return 0LL;
}

canonical_decompiled_code:
double *__fastcall func2(double a1, double a2, double a3, double a4)
{
double *v4; // rax
int *v6; // rbx
char *v7; // r8
int *v8; // rbx
char *v9; // r8
int *v10; // rbx
char *v11; // r8
int *v12; // rbx
char *v13; // r8
double *v14; // [rsp+8h] [rbp-30h] BYREF

v4 = (double *)malloc(0x20uLL);
v14 = v4;
if ( v4 )
{
*((_QWORD *)v4 + 1) = vector_create(a1, a2, a3);
if ( *((_QWORD *)v14 + 1) )
{
*((_QWORD *)v14 + 2) = vector_create(0.0, 0.0, 0.0);
if ( *((_QWORD *)v14 + 2) )
{
*((_QWORD *)v14 + 3) = vector_create(0.0, 0.0, 0.0);
if ( *((_QWORD *)v14 + 3) )
{
*v14 = a4;
return v14;
}
v12 = _errno_location();
v13 = "None";
if ( *v12 )
v13 = strerror(*v12);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 17LL, v13);
*v12 = 0;
}
else
{
v10 = _errno_location();
v11 = "None";
if ( *v10 )
v11 = strerror(*v10);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 14LL, v11);
*v10 = 0;
}
}
else
{
v8 = _errno_location();
v9 = "None";
if ( *v8 )
v9 = strerror(*v8);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 11LL, v9);
*v8 = 0;
}
}
else
{
v6 = _errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "particle.c", 8LL, v7);
*v6 = 0;
}
func1((void **)&v14);
return 0LL;
}

original_code:
Particle *particle_create(double x, double y, double z, double mass)
{
  Particle *p = (Particle *) malloc(sizeof(Particle));
  if(!((p))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 8, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->position = vector_create(x, y, z);
  if(!((p->position))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 11, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->speed = vector_create(0, 0, 0);
  if(!((p->speed))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->speed_old = vector_create(0, 0, 0);
  if(!((p->speed_old))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->mass = mass;
  return p;
error:
  particle_free(&p);
  return ((void *)0);
}

canonical_original_code:
struct Particle *particle_create(double x, double y, double z, double mass)
{
  struct Particle *p = (Particle *) malloc(sizeof(Particle));
  if(!((p))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 8, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->position = vector_create(x, y, z);
  if(!((p->position))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 11, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->speed = vector_create(0, 0, 0);
  if(!((p->speed))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->speed_old = vector_create(0, 0, 0);
  if(!((p->speed_old))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "particle.c", 17, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  p->mass = mass;
  return p;
error:
  particle_free(&p);
  return ((void *)0);
}

variable_types: x double

variable_types: y double

variable_types: z double

variable_types: mass double

variable_types: struct Particle { double mass; struct Vector { double x; double y; double z; } *position; struct Vector *speed; struct Vector *speed_old; } *


decompiled_code:
void __fastcall vector_free(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
free(v2);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
free(v2);
*a1 = 0LL;
}

original_code:
void vector_free(Vector **v)
{
  if(*v) free(*v);
  *v = ((void *)0);
}

canonical_original_code:
void vector_free(struct Vector **v)
{
  if(*v) free(*v);
  *v = ((void *)0);
}

variable_types: struct Vector { double x; double y; double z; } **


original_code:
Sim_state *state_init_random(Sim_state* state)
{
 srand(time(((void *)0)));
 int i;
 for(i = 0;i<state->count;i++){
  double x,y,z,m;
  x = (double)(rand())/2147483647;
  y = (double)(rand())/2147483647;
  z = (double)(rand())/2147483647;
  m = 0.99+((double)(rand())/2147483647/50);
  particle_free(&(state->particles[i]));
  state->particles[i] = particle_create(x,y,z,m);
 }
 return state;
}

canonical_original_code:
struct Sim_state *state_init_random(struct Sim_state *state)
{
 srand(time(((void *)0)));
 int i;
 for(i = 0;i<state->count;i++){
  double x; double y; double z; double m;
  x = (double)(rand())/2147483647;
  y = (double)(rand())/2147483647;
  z = (double)(rand())/2147483647;
  m = 0.99+((double)(rand())/2147483647/50);
  particle_free(&(state->particles[i]));
  state->particles[i] = particle_create(x,y,z,m);
 }
 return state;
}

variable_types:
state
struct Sim_state *

variable_types: i int

variable_types: m double

return_type: struct Sim_state { double box_size; double mass_multiplier; int count; int step_count; struct Particle { double mass; struct Vector { double x; double y; double z; } *position; struct Vector *speed; struct Vector *speed_old; } **particles; } *


original_code:
void state_particles_free(Sim_state *sim)
{
 if(sim&&sim->particles){
  int i;
  for(i = sim->count-1;i>=0;i--){
   particle_free(&(sim->particles[i]));
  }
  free(sim->particles);
 }
 sim->particles = ((void *)0);
}

canonical_original_code:
void state_particles_free(struct Sim_state *sim)
{
 if(sim&&sim->particles){
  int i;
  for(i = sim->count-1;i>=0;i--){
   particle_free(&(sim->particles[i]));
  }
  free(sim->particles);
 }
 sim->particles = ((void *)0);
}

user_defined_types: struct Vector { double x; double y; double z; }


decompiled_code:
__int64 __fastcall state_set_particles(__int64 a1, __int64 a2, int a3)
{
state_particles_free(a1);
*(_DWORD *)(a1 + 16) = a3;
*(_QWORD *)(a1 + 24) = a2;
return a1;
}

original_code:
Sim_state *state_set_particles(Sim_state* state, Particle **particles, int count)
{
 state_particles_free(state);
 state->count = count;
 state->particles = particles;
 return state;
}

canonical_original_code:
struct Sim_state *state_set_particles(struct Sim_state *state, struct Particle **particles, int count)
{
 state_particles_free(state);
 state->count = count;
 state->particles = particles;
 return state;
}

variable_types:
particles
struct Particle **

variable_types: count int


decompiled_code:
void __fastcall state_free(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
state_particles_free((__int64)v2);
free(*a1);
}
}

canonical_decompiled_code:
void __fastcall func3(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
func1((__int64)v2);
free(*a1);
}
}

original_code:
void state_free(Sim_state **sim)
{
 if(*sim){
  state_particles_free(*sim);
  free(*sim);
 }
 sim = ((void *)0);
}

canonical_original_code:
void state_free(struct Sim_state **sim)
{
 if(*sim){
  state_particles_free(*sim);
  free(*sim);
 }
 sim = ((void *)0);
}

variable_types: struct Sim_state { double box_size; double mass_multiplier; int count; int step_count; struct Particle { double mass; struct Vector { double x; double y; double z; } *position; struct Vector *speed; struct Vector *speed_old; } **particles; } **


decompiled_code:
double *__fastcall vector_cross(double *a1, double *a2, double *a3)
{
double *result; // rax

result = a3;
if ( !a3 )
result = (double *)vector_create(0.0, 0.0);
*result = a1[1] * a2[2] - a1[2] * a2[1];
result[1] = a1[2] * *a2 - *a1 * a2[2];
result[2] = *a1 * a2[1] - a1[1] * *a2;
return result;
}

canonical_decompiled_code:
double *__fastcall func4(double *a1, double *a2, double *a3)
{
double *result; // rax

result = a3;
if ( !a3 )
result = (double *)vector_create(0.0, 0.0);
*result = a1[1] * a2[2] - a1[2] * a2[1];
result[1] = a1[2] * *a2 - *a1 * a2[2];
result[2] = *a1 * a2[1] - a1[1] * *a2;
return result;
}

original_code:
Vector *vector_cross(Vector *a, Vector *b, Vector *write)
{
 if(!write) write = vector_create(0,0,0);
 write->x = (a->y * b->z) - (a->z * b->y);
 write->y = (a->z * b->x) - (a->x * b->z);
 write->z = (a->x * b->y) - (a->y * b->x);
 return write;
}

canonical_original_code:
struct Vector *vector_cross(struct Vector *a, struct Vector *b, struct Vector *write)
{
 if(!write) write = vector_create(0,0,0);
 write->x = (a->y * b->z) - (a->z * b->y);
 write->y = (a->z * b->x) - (a->x * b->z);
 write->z = (a->x * b->y) - (a->y * b->x);
 return write;
}

variable_types:
a
struct Vector *

variable_types:
b
struct Vector *

variable_types:
write
struct Vector *

return_type: struct Vector { double x; double y; double z; } *


decompiled_code:
__int64 __fastcall vector_to_unitcube(double *a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
double v3; // xmm0_8
__int64 result; // rax
double v5; // xmm0_8

v1 = *a1 - (double)(int)*a1;
if ( v1 < 0.0 )
v1 = v1 + 1.0;
*a1 = v1;
v2 = a1[1] - (double)(int)a1[1];
if ( v2 < 0.0 )
v2 = v2 + 1.0;
a1[1] = v2;
v3 = a1[2];
result = (unsigned int)(int)v3;
v5 = v3 - (double)(int)result;
if ( v5 < 0.0 )
v5 = v5 + 1.0;
a1[2] = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(double *a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
double v3; // xmm0_8
__int64 result; // rax
double v5; // xmm0_8

v1 = *a1 - (double)(int)*a1;
if ( v1 < 0.0 )
v1 = v1 + 1.0;
*a1 = v1;
v2 = a1[1] - (double)(int)a1[1];
if ( v2 < 0.0 )
v2 = v2 + 1.0;
a1[1] = v2;
v3 = a1[2];
result = (unsigned int)(int)v3;
v5 = v3 - (double)(int)result;
if ( v5 < 0.0 )
v5 = v5 + 1.0;
a1[2] = v5;
return result;
}

variable_types: struct Vector { double x; double y; double z; } *


decompiled_code:
__int64 __fastcall vector_shorten_in_cube(const __m128i *a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8
double v4; // xmm0_8

result = a2;
if ( !a2 )
result = vector_create(0.0, 0.0);
*(__m128i *)result = _mm_loadu_si128(a1);
*(_QWORD *)(result + 16) = a1[1].m128i_i64[0];
if ( *(double *)result > 0.5 )
*(double *)result = *(double *)result - 1.0;
v3 = *(double *)(result + 8);
if ( v3 > 0.5 )
*(double *)(result + 8) = v3 - 1.0;
v4 = *(double *)(result + 16);
if ( v4 > 0.5 )
*(double *)(result + 16) = v4 - 1.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const __m128i *a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8
double v4; // xmm0_8

result = a2;
if ( !a2 )
result = vector_create(0.0, 0.0);
*(__m128i *)result = _mm_loadu_si128(a1);
*(_QWORD *)(result + 16) = a1[1].m128i_i64[0];
if ( *(double *)result > 0.5 )
*(double *)result = *(double *)result - 1.0;
v3 = *(double *)(result + 8);
if ( v3 > 0.5 )
*(double *)(result + 8) = v3 - 1.0;
v4 = *(double *)(result + 16);
if ( v4 > 0.5 )
*(double *)(result + 16) = v4 - 1.0;
return result;
}

original_code:
Vector *vector_shorten_in_cube(Vector *a, Vector *write){
 if(!write)write = vector_create(0,0,0);
 *write = *a;
 if(write->x > 0.5)write->x -= 1;
 if(write->y > 0.5)write->y -= 1;
 if(write->z > 0.5)write->z -= 1;
 return write;
}

canonical_original_code:
struct Vector *vector_shorten_in_cube(struct Vector *a, struct Vector *write){
 if(!write)write = vector_create(0,0,0);
 *write = *a;
 if(write->x > 0.5)write->x -= 1;
 if(write->y > 0.5)write->y -= 1;
 if(write->z > 0.5)write->z -= 1;
 return write;
}


getnibble

repo: HerrSchrader/McBetty

decompiled_code:
__int64 __fastcall getnibble(_QWORD *a1)
{
char *v1; // rax
int v2; // edx
__int64 result; // rax
unsigned int v4; // edx

v1 = (char *)(*a1)++;
v2 = *v1;
result = (unsigned int)(v2 - 48);
v4 = v2 - 55;
if ( (int)result > 9 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
char *v1; // rax
int v2; // edx
__int64 result; // rax
unsigned int v4; // edx

v1 = (char *)(*a1)++;
v2 = *v1;
result = (unsigned int)(v2 - 48);
v4 = v2 - 55;
if ( (int)result > 9 )
result = v4;
return result;
}

original_code:
int getnibble(char **p)
{
  int ret = *((*p)++) - '0';
  if (ret > 9) {
    ret -= 'A' - '9' - 1;
  }
  return ret;
}

variable_types:
p
char **

variable_types: ret int


getbyte

decompiled_code:
__int64 __fastcall getbyte(_QWORD *a1)
{
int v1; // ebx

v1 = getnibble(a1);
return (16 * v1) | (unsigned int)getnibble(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
int v1; // ebx

v1 = func7(a1);
return (16 * v1) | (unsigned int)func7(a1);
}

original_code:
int getbyte(char **p)
{
  return (getnibble(p) << 4) | getnibble(p);
}


usage

decompiled_code:
size_t usage()
{
return fwrite(
"makebin: convert a Intel IHX file to binary.\nUsage: makebin [-p] [-s romsize] [-h]\n",
1uLL,
0x53uLL,
stderr);
}

canonical_decompiled_code:
size_t func9()
{
return fwrite(
"makebin: convert a Intel IHX file to binary.\nUsage: makebin [-p] [-s romsize] [-h]\n",
1uLL,
0x53uLL,
stderr);
}

original_code:
void usage(void)
{
  fprintf(stderr,
          "makebin: convert a Intel IHX file to binary.\n"
          "Usage: makebin [-p] [-s romsize] [-h]\n");
}

canonical_original_code:
void usage()
{
  fprintf(stderr,
          "makebin: convert a Intel IHX file to binary.\n"
          "Usage: makebin [-p] [-s romsize] [-h]\n");
}


fixStdout

decompiled_code:
void fixStdout()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void fixStdout(void)
{
}

canonical_original_code:
void fixStdout()
{
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rsi
int v4; // ebx
int v5; // edx
int v6; // ebp
int v7; // er13
char v8; // al
_BYTE *v10; // rax
_BYTE *v11; // r14
int v12; // er15
int v13; // ebp
int v14; // er12
int v15; // er12
char *v16; // [rsp+18h] [rbp-140h] BYREF
char s; // [rsp+20h] [rbp-138h] BYREF
char v18; // [rsp+21h] [rbp-137h] BYREF

v3 = argv + 1;
v4 = argc - 1;
if ( argc != 1 )
{
v5 = argc - 2;
v6 = 0;
v7 = 0x8000;
while ( 1 )
{
if ( **v3 != 45 )
goto LABEL_7;
v8 = (*v3)[1];
switch ( v8 )
{
case 'p':
v4 = v5;
v6 = 1;
break;
case 's':
if ( v5 <= 0 )
goto LABEL_7;
v4 -= 2;
v7 = atoi(v3[1]);
++v3;
break;
case 'h':
usage();
return 0;
default:
LABEL_7:
usage();
return -1;
}
++v3;
v5 = v4 - 1;
if ( !v4 )
{
v4 = v6;
goto LABEL_18;
}
}
}
v7 = 0x8000;
LABEL_18:
v10 = malloc(v7);
v11 = v10;
if ( v10 )
{
memset(v10, 255, v7);
v12 = 0;
while ( fgets(&s, 256, stdin) )
{
if ( s != 58 )
{
fwrite("error: invalid IHX line.\n", 1uLL, 0x19uLL, stderr);
return -2;
}
v16 = &v18;
v13 = getbyte(&v16);
v15 = getbyte(&v16);
v14 = getbyte(&v16) | (v15 << 8);
getbyte(&v16);
for ( ; v13; --v13 )
{
if ( v7 > v14 )
v11[v14++] = getbyte(&v16);
}
if ( v12 < v14 )
v12 = v14;
}
if ( v4 )
{
fwrite(v11, 1uLL, v12, stdout);
v4 = 0;
}
else
{
fwrite(v11, 1uLL, v7, stdout);
}
}
else
{
fwrite("error: couldn't allocate room for the image.\n", 1uLL, 0x2DuLL, stderr);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rsi
int v4; // ebx
int v5; // edx
int v6; // ebp
int v7; // er13
char v8; // al
_BYTE *v10; // rax
_BYTE *v11; // r14
int v12; // er15
int v13; // ebp
int v14; // er12
int v15; // er12
char *v16; // [rsp+18h] [rbp-140h] BYREF
char s; // [rsp+20h] [rbp-138h] BYREF
char v18; // [rsp+21h] [rbp-137h] BYREF

v3 = argv + 1;
v4 = argc - 1;
if ( argc != 1 )
{
v5 = argc - 2;
v6 = 0;
v7 = 0x8000;
while ( 1 )
{
if ( **v3 != 45 )
goto LABEL_7;
v8 = (*v3)[1];
switch ( v8 )
{
case 'p':
v4 = v5;
v6 = 1;
break;
case 's':
if ( v5 <= 0 )
goto LABEL_7;
v4 -= 2;
v7 = atoi(v3[1]);
++v3;
break;
case 'h':
func9();
return 0;
default:
LABEL_7:
func9();
return -1;
}
++v3;
v5 = v4 - 1;
if ( !v4 )
{
v4 = v6;
goto LABEL_18;
}
}
}
v7 = 0x8000;
LABEL_18:
v10 = malloc(v7);
v11 = v10;
if ( v10 )
{
memset(v10, 255, v7);
v12 = 0;
while ( fgets(&s, 256, stdin) )
{
if ( s != 58 )
{
fwrite("error: invalid IHX line.\n", 1uLL, 0x19uLL, stderr);
return -2;
}
v16 = &v18;
v13 = func8(&v16);
v15 = func8(&v16);
v14 = func8(&v16) | (v15 << 8);
func8(&v16);
for ( ; v13; --v13 )
{
if ( v7 > v14 )
v11[v14++] = func8(&v16);
}
if ( v12 < v14 )
v12 = v14;
}
if ( v4 )
{
fwrite(v11, 1uLL, v12, stdout);
v4 = 0;
}
else
{
fwrite(v11, 1uLL, v7, stdout);
}
}
else
{
fwrite("error: couldn't allocate room for the image.\n", 1uLL, 0x2DuLL, stderr);
v4 = -1;
}
return v4;
}

original_code:
int main(int argc, char **argv)
{
    int size = 32768, pack = 0, real_size = 0;
    BYTE *rom;
    char line[256];
    char *p;
    argc--;
    argv++;
    fixStdout();
    while (argc--) {
        if (**argv != '-') {
            usage();
            return -1;
        }
        switch (argv[0][1]) {
 case 's':
            if (argc < 1) {
                usage();
                return -1;
            }
            argc--;
            argv++;
     size = atoi(*argv);
     break;
 case 'h':
            usage();
     return 0;
 case 'p':
     pack = 1;
     break;
 default:
            usage();
            return -1;
 }
        argv++;
    }
    rom = malloc(size);
    if (rom == ((void *)0)) {
 fprintf(stderr, "error: couldn't allocate room for the image.\n");
 return -1;
    }
    memset(rom, 0xFF, size);
    while (fgets(line, 256, stdin) != ((void *)0)) {
 int nbytes;
 int addr;
 if (*line != ':') {
     fprintf(stderr, "error: invalid IHX line.\n");
     return -2;
 }
 p = line+1;
 nbytes = getbyte(&p);
 addr = getbyte(&p)<<8 | getbyte(&p);
 getbyte(&p);
 while (nbytes--) {
     if (addr < size)
  rom[addr++] = getbyte(&p);
 }
 if (addr > real_size)
     real_size = addr;
    }
    if (pack)
        fwrite(rom, 1, real_size, stdout);
    else
        fwrite(rom, 1, size, stdout);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int size = 32768; int pack = 0; int real_size = 0;
    unsigned char *rom;
    char line[256];
    char *p;
    argc--;
    argv++;
    fixStdout();
    while (argc--) {
        if (**argv != '-') {
            usage();
            return -1;
        }
        switch (argv[0][1]) {
 case 's':
            if (argc < 1) {
                usage();
                return -1;
            }
            argc--;
            argv++;
     size = atoi(*argv);
     break;
 case 'h':
            usage();
     return 0;
 case 'p':
     pack = 1;
     break;
 default:
            usage();
            return -1;
 }
        argv++;
    }
    rom = malloc(size);
    if (rom == ((void *)0)) {
 fprintf(stderr, "error: couldn't allocate room for the image.\n");
 return -1;
    }
    memset(rom, 0xFF, size);
    while (fgets(line, 256, stdin) != ((void *)0)) {
 int nbytes;
 int addr;
 if (*line != ':') {
     fprintf(stderr, "error: invalid IHX line.\n");
     return -2;
 }
 p = line+1;
 nbytes = getbyte(&p);
 addr = getbyte(&p)<<8 | getbyte(&p);
 getbyte(&p);
 while (nbytes--) {
     if (addr < size)
  rom[addr++] = getbyte(&p);
 }
 if (addr > real_size)
     real_size = addr;
    }
    if (pack)
        fwrite(rom, 1, real_size, stdout);
    else
        fwrite(rom, 1, size, stdout);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: size int

variable_types: pack int

variable_types:
rom
unsigned char *

variable_types:
line
char [256]

variable_types:
p
char *

variable_types: nbytes int

variable_types: addr int


repo: HexHive/memTrace

decompiled_code:
void __fastcall __noreturn thread_function(void *a1)
{
unsigned int i; // ebx

g = (_DWORD)a1 * (_DWORD)a1;
g = *__errno_location() + (_DWORD)a1 * (_DWORD)a1;
for ( i = 0; i != 5000; ++i )
printf("i is %d\n", i);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int i; // ebx

g = (_DWORD)a1 * (_DWORD)a1;
g = *__errno_location() + (_DWORD)a1 * (_DWORD)a1;
for ( i = 0; i != 5000; ++i )
printf("i is %d\n", i);
pthread_exit(0LL);
}

original_code:
void* thread_function(void* arg)
{
  g = (int)arg*(int)arg;
  g += (*__errno_location ());
  int i;
  for (i=0; i<5000; i++){
    printf("i is %d\n", i);
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *thread_function(void *arg)
{
  g = (int)arg*(int)arg;
  g += (*__errno_location ());
  int i;
  for (i=0; i<5000; i++){
    printf("i is %d\n", i);
  }
  pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: i int

return_type: void *


ekrpr

decompiled_code:
ssize_t __fastcall ekrpr(int fd, unsigned int a2)
{
char *v2; // rcx
unsigned int v3; // edx
char v4; // al
char *v5; // rax
char *v6; // rdx
char *v7; // rcx
char buf[9]; // [rsp+Fh] [rbp-19h] BYREF
char v10[16]; // [rsp+18h] [rbp-10h] BYREF

qmemcpy(v10, "00000000", 8);
if ( a2 )
{
v2 = v10;
while ( 1 )
{
v3 = a2 & 0xF;
v4 = v3 + 87;
if ( v3 <= 9 )
v4 = v3 + 48;
*v2++ = v4;
if ( a2 <= 0xF )
break;
a2 >>= 4;
}
}
v5 = &v10[7];
v6 = buf;
do
{
*v6 = *v5;
v7 = v5--;
++v6;
}
while ( v7 != v10 );
buf[8] = 10;
return write(fd, buf, 9uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, unsigned int a2)
{
char *v2; // rcx
unsigned int v3; // edx
char v4; // al
char *v5; // rax
char *v6; // rdx
char *v7; // rcx
char buf[9]; // [rsp+Fh] [rbp-19h] BYREF
char v10[16]; // [rsp+18h] [rbp-10h] BYREF

qmemcpy(v10, "00000000", 8);
if ( a2 )
{
v2 = v10;
while ( 1 )
{
v3 = a2 & 0xF;
v4 = v3 + 87;
if ( v3 <= 9 )
v4 = v3 + 48;
*v2++ = v4;
if ( a2 <= 0xF )
break;
a2 >>= 4;
}
}
v5 = &v10[7];
v6 = buf;
do
{
*v6 = *v5;
v7 = v5--;
++v6;
}
while ( v7 != v10 );
buf[8] = 10;
return write(fd, buf, 9uLL);
}

original_code:
void ekrpr(int fd, unsigned n)
{
  char bb[8];
  char bbrev[9];
  int i;
  for (i=0; i<8; i++){
    bb[i]='0';
  }
  int bbs = 0;
  while (n){
    unsigned tmp = (n%16);
    if (tmp < 10){
      bb[bbs] = (unsigned char)((unsigned int)'0' + tmp);
    } else {
      bb[bbs] = (unsigned char)((unsigned int)'a' + tmp - 10);
    }
    n /= 16;
    bbs++;
  }
  for (i=0; i<8; i++){
    bbrev[i]=bb[7-i];
  }
  bbrev[8] = '\n';
  int rs = write(fd, bbrev, 9);
}

canonical_original_code:
void ekrpr(int fd, unsigned int n)
{
  char bb[8];
  char bbrev[9];
  int i;
  for (i=0; i<8; i++){
    bb[i]='0';
  }
  int bbs = 0;
  while (n){
    unsigned int tmp = (n%16);
    if (tmp < 10){
      bb[bbs] = (unsigned char)((unsigned int)'0' + tmp);
    } else {
      bb[bbs] = (unsigned char)((unsigned int)'a' + tmp - 10);
    }
    n /= 16;
    bbs++;
  }
  for (i=0; i<8; i++){
    bbrev[i]=bb[7-i];
  }
  bbrev[8] = '\n';
  int rs = write(fd, bbrev, 9);
}

variable_types: fd int

variable_types:
n
unsigned int

variable_types:
bb
char [8]

variable_types:
bbrev
char [9]

variable_types: bbs int

variable_types:
tmp
unsigned int

variable_types: rs int


bar

decompiled_code:
int bar()
{
unsigned int i; // ebx
int result; // eax

for ( i = 0; i != 5000; ++i )
result = printf("q is %d\n", i);
return result;
}

canonical_decompiled_code:
int func9()
{
unsigned int i; // ebx
int result; // eax

for ( i = 0; i != 5000; ++i )
result = printf("q is %d\n", i);
return result;
}

original_code:
void bar()
{
  int i;
  for (i=0; i<5000; i++){
    printf("q is %d\n", i);
  }
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

xx = 15;
byte_404071 = 13;
byte_404072 = 14;
byte_404073 = 15;
printf("About to create a thread of %x\n", thread_function);
pthread_create(newthread, 0LL, (void *(*)(void *))thread_function, 0LL);
bar();
pthread_join(newthread[0], 0LL);
puts("bye");
pthread_exit(0LL);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

xx = 15;
byte_404071 = 13;
byte_404072 = 14;
byte_404073 = 15;
printf("About to create a thread of %x\n", thread_function);
pthread_create(newthread, 0LL, (void *(*)(void *))thread_function, 0LL);
func9();
pthread_join(newthread[0], 0LL);
puts("bye");
pthread_exit(0LL);
}

original_code:
int main(int argc, char** argv)
{
  long ar;
  xx[0] = 15;
  xx[1] = 13;
  xx[2] = 14;
  xx[3] = xx[0];
  printf("About to create a thread of %x\n", &thread_function);
  pthread_t thrd;
  pthread_create(&thrd, ((void *)0), thread_function, (void*)ar);
  bar();
  pthread_join(thrd, ((void *)0));
  printf("bye\n");
  pthread_exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  long ar;
  xx[0] = 15;
  xx[1] = 13;
  xx[2] = 14;
  xx[3] = xx[0];
  printf("About to create a thread of %x\n", &thread_function);
  unsigned long thrd;
  pthread_create(&thrd, ((void *)0), thread_function, (void *)ar);
  bar();
  pthread_join(thrd, ((void *)0));
  printf("bye\n");
  pthread_exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ar long

variable_types:
thrd
unsigned long


decompiled_code:
__int64 __fastcall select_by_FIFO(__int64 a1)
{
unsigned int v1; // ecx

*(_QWORD *)(page_table + 24LL * FIFO_pos) = a1;
v1 = FIFO_pos;
FIFO_pos = (FIFO_pos + 1) % size_of_memory;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // ecx

*(_QWORD *)(page_table + 24LL * FIFO_pos) = a1;
v1 = FIFO_pos;
FIFO_pos = (FIFO_pos + 1) % size_of_memory;
return v1;
}

original_code:
int select_by_FIFO(long page) {
  page_table[FIFO_pos].page_num = page;
  int temp_FIFO = FIFO_pos;
  FIFO_pos = (FIFO_pos + 1) % size_of_memory;
  return temp_FIFO;
}

variable_types: page long


decompiled_code:
__int64 __fastcall select_by_LRU(__int64 a1)
{
int *v1; // rdx
unsigned int v2; // er8
int v3; // esi
unsigned int v4; // eax
__int64 v5; // rax

if ( size_of_memory <= 0 )
{
v2 = 0;
}
else
{
v1 = (int *)(page_table + 16);
v2 = 0;
v3 = 0;
v4 = 0;
do
{
if ( *v1 > v3 )
{
v2 = v4;
v3 = *v1;
}
++v4;
v1 += 6;
}
while ( v4 != size_of_memory );
}
v5 = 24LL * (int)v2;
*(_QWORD *)(page_table + v5) = a1;
*(_DWORD *)(page_table + v5 + 16) = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int *v1; // rdx
unsigned int v2; // er8
int v3; // esi
unsigned int v4; // eax
__int64 v5; // rax

if ( size_of_memory <= 0 )
{
v2 = 0;
}
else
{
v1 = (int *)(page_table + 16);
v2 = 0;
v3 = 0;
v4 = 0;
do
{
if ( *v1 > v3 )
{
v2 = v4;
v3 = *v1;
}
++v4;
v1 += 6;
}
while ( v4 != size_of_memory );
}
v5 = 24LL * (int)v2;
*(_QWORD *)(page_table + v5) = a1;
*(_DWORD *)(page_table + v5 + 16) = 0;
return v2;
}

original_code:
int select_by_LRU(long page) {
  int i = 0;
  int highest_ticks_since_use = 0;
  int highest_index = 0;
  for ( i=0; i < size_of_memory; i++ ) {
    if (page_table[i].ticks_since_use > highest_ticks_since_use) {
      highest_ticks_since_use = page_table[i].ticks_since_use;
      highest_index = i;
    }
  }
  page_table[highest_index].page_num = page;
  page_table[highest_index].ticks_since_use = 0;
  return highest_index;
}


decompiled_code:
__int64 __fastcall resolve_address(__int64 a1)
{
char v2; // cl
__int64 v3; // r8
__int64 v4; // rdi
int v5; // eax
__int64 v6; // rbx
int v7; // edi
__int64 v8; // rax
int v9; // edx
__int64 v10; // r9
__int64 v11; // rsi
_DWORD *v12; // rax
__int64 v13; // rdx
__int64 result; // rax
__int64 v15; // rsi
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // rcx
_DWORD *v19; // rdx
__int64 v20; // rax
_DWORD *v21; // rax
__int64 v22; // rdx
__int64 v23; // rax
_DWORD *v24; // rdx
int v25; // eax

v2 = size_of_frame;
v3 = a1 >> size_of_frame;
if ( size_of_frame <= 0 )
{
v4 = 0LL;
}
else
{
v4 = 0LL;
v5 = 0;
do
{
v4 = 2 * v4 + 1;
++v5;
}
while ( size_of_frame != v5 );
}
v6 = v4 & a1;
v7 = size_of_memory;
if ( size_of_memory <= 0 )
{
++page_faults;
goto LABEL_34;
}
v8 = page_table;
v9 = 0;
while ( 1 )
{
v10 = v8;
if ( !*(_DWORD *)(v8 + 12) && *(_QWORD *)v8 == v3 )
break;
++v9;
v8 += 24LL;
if ( v9 == size_of_memory )
goto LABEL_31;
}
v11 = v9;
LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
if ( !LRU_tick_current )
{
v12 = (_DWORD *)(page_table + 16);
v13 = page_table + 24LL * (unsigned int)(size_of_memory - 1) + 40;
do
{
++*v12;
v12 += 6;
}
while ( v12 != (_DWORD *)v13 );
}
*(_DWORD *)(v10 + 16) = 0;
if ( v11 != -1 )
return v6 | (v11 << v2);
LABEL_31:
++page_faults;
v24 = (_DWORD *)(page_table + 12);
v25 = 0;
while ( !*v24 )
{
++v25;
v24 += 6;
if ( v25 == v7 )
goto LABEL_34;
}
v15 = v25;
if ( v25 == -1 )
{
LABEL_34:
++swap_outs;
++swap_ins;
LRU_tick_current = (LRU_tick_current + 1) % v7;
if ( LRU_tick_current )
{
if ( page_replacement_scheme == 1 )
{
LABEL_37:
v23 = (int)select_by_FIFO(v3);
return v6 | (v23 << size_of_frame);
}
if ( page_replacement_scheme != 2 )
return -1LL;
}
else
{
if ( page_replacement_scheme != 2 )
{
result = -1LL;
if ( page_replacement_scheme != 1 )
return result;
goto LABEL_37;
}
if ( v7 > 0 )
{
v21 = (_DWORD *)(page_table + 16);
v22 = page_table + 24LL * (unsigned int)(v7 - 1) + 40;
do
{
++*v21;
v21 += 6;
}
while ( v21 != (_DWORD *)v22 );
}
}
v23 = (int)select_by_LRU(v3);
return v6 | (v23 << size_of_frame);
}
v16 = 24LL * v25;
*(_QWORD *)(page_table + v16) = v3;
v17 = page_table;
v18 = page_table + v16;
*(_DWORD *)(v18 + 12) = 0;
LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
if ( !LRU_tick_current && page_replacement_scheme == 2 && size_of_memory > 0 )
{
v19 = (_DWORD *)(v17 + 16);
v20 = v17 + 24LL * (unsigned int)(size_of_memory - 1) + 40;
do
{
++*v19;
v19 += 6;
}
while ( v19 != (_DWORD *)v20 );
}
*(_DWORD *)(v18 + 16) = 0;
++swap_ins;
return v6 | (v15 << size_of_frame);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
char v2; // cl
__int64 v3; // r8
__int64 v4; // rdi
int v5; // eax
__int64 v6; // rbx
int v7; // edi
__int64 v8; // rax
int v9; // edx
__int64 v10; // r9
__int64 v11; // rsi
_DWORD *v12; // rax
__int64 v13; // rdx
__int64 result; // rax
__int64 v15; // rsi
__int64 v16; // rcx
__int64 v17; // r8
__int64 v18; // rcx
_DWORD *v19; // rdx
__int64 v20; // rax
_DWORD *v21; // rax
__int64 v22; // rdx
__int64 v23; // rax
_DWORD *v24; // rdx
int v25; // eax

v2 = size_of_frame;
v3 = a1 >> size_of_frame;
if ( size_of_frame <= 0 )
{
v4 = 0LL;
}
else
{
v4 = 0LL;
v5 = 0;
do
{
v4 = 2 * v4 + 1;
++v5;
}
while ( size_of_frame != v5 );
}
v6 = v4 & a1;
v7 = size_of_memory;
if ( size_of_memory <= 0 )
{
++page_faults;
goto LABEL_34;
}
v8 = page_table;
v9 = 0;
while ( 1 )
{
v10 = v8;
if ( !*(_DWORD *)(v8 + 12) && *(_QWORD *)v8 == v3 )
break;
++v9;
v8 += 24LL;
if ( v9 == size_of_memory )
goto LABEL_31;
}
v11 = v9;
LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
if ( !LRU_tick_current )
{
v12 = (_DWORD *)(page_table + 16);
v13 = page_table + 24LL * (unsigned int)(size_of_memory - 1) + 40;
do
{
++*v12;
v12 += 6;
}
while ( v12 != (_DWORD *)v13 );
}
*(_DWORD *)(v10 + 16) = 0;
if ( v11 != -1 )
return v6 | (v11 << v2);
LABEL_31:
++page_faults;
v24 = (_DWORD *)(page_table + 12);
v25 = 0;
while ( !*v24 )
{
++v25;
v24 += 6;
if ( v25 == v7 )
goto LABEL_34;
}
v15 = v25;
if ( v25 == -1 )
{
LABEL_34:
++swap_outs;
++swap_ins;
LRU_tick_current = (LRU_tick_current + 1) % v7;
if ( LRU_tick_current )
{
if ( page_replacement_scheme == 1 )
{
LABEL_37:
v23 = (int)func7(v3);
return v6 | (v23 << size_of_frame);
}
if ( page_replacement_scheme != 2 )
return -1LL;
}
else
{
if ( page_replacement_scheme != 2 )
{
result = -1LL;
if ( page_replacement_scheme != 1 )
return result;
goto LABEL_37;
}
if ( v7 > 0 )
{
v21 = (_DWORD *)(page_table + 16);
v22 = page_table + 24LL * (unsigned int)(v7 - 1) + 40;
do
{
++*v21;
v21 += 6;
}
while ( v21 != (_DWORD *)v22 );
}
}
v23 = (int)func8(v3);
return v6 | (v23 << size_of_frame);
}
v16 = 24LL * v25;
*(_QWORD *)(page_table + v16) = v3;
v17 = page_table;
v18 = page_table + v16;
*(_DWORD *)(v18 + 12) = 0;
LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
if ( !LRU_tick_current && page_replacement_scheme == 2 && size_of_memory > 0 )
{
v19 = (_DWORD *)(v17 + 16);
v20 = v17 + 24LL * (unsigned int)(size_of_memory - 1) + 40;
do
{
++*v19;
v19 += 6;
}
while ( v19 != (_DWORD *)v20 );
}
*(_DWORD *)(v18 + 16) = 0;
++swap_ins;
return v6 | (v15 << size_of_frame);
}

original_code:
long resolve_address(long logical, int memwrite)
{
 int i;
 long page, frame;
 long offset;
 long mask = 0;
 long effective;
 page = (logical >> size_of_frame);
 for (i=0; i<size_of_frame; i++) {
   mask = mask << 1;
   mask |= 1;
 }
 offset = logical & mask;
 frame = -1;
 for ( i = 0; i < size_of_memory; i++ ) {
   if (!page_table[i].free && page_table[i].page_num == page) {
     frame = i;
     LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
     if (LRU_tick_current == 0) {
       int j;
       for (j=0; j<size_of_memory; j++) { page_table[j].ticks_since_use++; }
     }
     page_table[i].ticks_since_use = 0;
     break;
   }
 }
 if (frame != -1) {
   effective = (frame << size_of_frame) | offset;
   return effective;
 }
 page_faults++;
 for ( i = 0; i < size_of_memory; i++) {
   if (page_table[i].free) {
     frame = i;
     break;
   }
 }
 if (frame != -1) {
   page_table[frame].page_num = page;
   page_table[i].free = 0;
   LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
   if (LRU_tick_current == 0 && page_replacement_scheme == 2) {
     int j;
     for (j=0; j<size_of_memory; j++) { page_table[j].ticks_since_use++; }
   }
   page_table[i].ticks_since_use = 0;
   swap_ins++;
   effective = (frame << size_of_frame) | offset;
   return effective;
 } else {
   swap_outs++;
   swap_ins++;
   LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
   if (LRU_tick_current == 0 && page_replacement_scheme == 2) {
     int j;
     for (j=0; j<size_of_memory; j++) { page_table[j].ticks_since_use++; }
   }
   switch (page_replacement_scheme) {
     case 1:
        frame = select_by_FIFO(page);
        break;
      case 2:
        frame = select_by_LRU(page);
        break;
      default:
        return -1;
   }
  effective = (frame << size_of_frame) | offset;
  return effective;
 }
}

canonical_original_code:
long resolve_address(long logical, int memwrite)
{
 int i;
 long page; long frame;
 long offset;
 long mask = 0;
 long effective;
 page = (logical >> size_of_frame);
 for (i=0; i<size_of_frame; i++) {
   mask = mask << 1;
   mask |= 1;
 }
 offset = logical & mask;
 frame = -1;
 for ( i = 0; i < size_of_memory; i++ ) {
   if (!page_table[i].free && page_table[i].page_num == page) {
     frame = i;
     LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
     if (LRU_tick_current == 0) {
       int j;
       for (j=0; j<size_of_memory; j++) { page_table[j].ticks_since_use++; }
     }
     page_table[i].ticks_since_use = 0;
     break;
   }
 }
 if (frame != -1) {
   effective = (frame << size_of_frame) | offset;
   return effective;
 }
 page_faults++;
 for ( i = 0; i < size_of_memory; i++) {
   if (page_table[i].free) {
     frame = i;
     break;
   }
 }
 if (frame != -1) {
   page_table[frame].page_num = page;
   page_table[i].free = 0;
   LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
   if (LRU_tick_current == 0 && page_replacement_scheme == 2) {
     int j;
     for (j=0; j<size_of_memory; j++) { page_table[j].ticks_since_use++; }
   }
   page_table[i].ticks_since_use = 0;
   swap_ins++;
   effective = (frame << size_of_frame) | offset;
   return effective;
 } else {
   swap_outs++;
   swap_ins++;
   LRU_tick_current = (LRU_tick_current + 1) % size_of_memory;
   if (LRU_tick_current == 0 && page_replacement_scheme == 2) {
     int j;
     for (j=0; j<size_of_memory; j++) { page_table[j].ticks_since_use++; }
   }
   switch (page_replacement_scheme) {
     case 1:
        frame = select_by_FIFO(page);
        break;
      case 2:
        frame = select_by_LRU(page);
        break;
      default:
        return -1;
   }
  effective = (frame << size_of_frame) | offset;
  return effective;
 }
}

variable_types: logical long

variable_types: memwrite int

variable_types: frame long

variable_types: offset long

variable_types: mask long

variable_types: effective long

variable_types: j int

return_type: long


decompiled_code:
int __fastcall display_progress(unsigned int a1)
{
int v1; // er12
int result; // eax
int v3; // ebx
int v4; // er13

v1 = 30 * a1;
result = (int)(30 * a1) >> 31;
v3 = (int)(30 * a1) / 100;
if ( last_to_date_0 < v3 )
{
last_to_date_0 = v1 / 100;
printf("Progress [");
if ( v1 <= 99 )
{
v3 = 0;
}
else
{
v4 = 0;
do
{
putchar(46);
++v4;
}
while ( v3 > v4 );
if ( v3 <= 0 )
v3 = 1;
if ( v1 > 2999 )
goto LABEL_9;
}
do
{
putchar(32);
++v3;
}
while ( v3 <= 29 );
LABEL_9:
printf("] %3d%%", a1);
putchar(13);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
int v1; // er12
int result; // eax
int v3; // ebx
int v4; // er13

v1 = 30 * a1;
result = (int)(30 * a1) >> 31;
v3 = (int)(30 * a1) / 100;
if ( last_to_date_0 < v3 )
{
last_to_date_0 = v1 / 100;
printf("Progress [");
if ( v1 <= 99 )
{
v3 = 0;
}
else
{
v4 = 0;
do
{
putchar(46);
++v4;
}
while ( v3 > v4 );
if ( v3 <= 0 )
v3 = 1;
if ( v1 > 2999 )
goto LABEL_9;
}
do
{
putchar(32);
++v3;
}
while ( v3 <= 29 );
LABEL_9:
printf("] %3d%%", a1);
putchar(13);
result = fflush(stdout);
}
return result;
}

original_code:
void display_progress(int percent)
{
 int to_date = 30 * percent / 100;
 static int last_to_date = 0;
 int i;
 if (last_to_date < to_date) {
   last_to_date = to_date;
 } else {
   return;
 }
 printf("Progress [");
 for (i=0; i<to_date; i++) {
   printf(".");
 }
 for (; i<30; i++) {
   printf(" ");
 }
 printf("] %3d%%", percent);
 printf("\r");
 fflush(stdout);
}

variable_types: percent int

variable_types: i int


initialize

decompiled_code:
__int64 initialize()
{
int v0; // ebx
char *v1; // rax
char *v2; // rdx
_DWORD *v3; // rax
__int64 v4; // rdx

v0 = size_of_memory;
v1 = (char *)malloc(24LL * size_of_memory);
page_table = (__int64)v1;
if ( !v1 )
{
fwrite("Simulator error: cannot allocate memory for page table.\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
v2 = v1;
if ( v0 > 0 )
{
v3 = v1 + 12;
v4 = (__int64)&v2[24 * (v0 - 1) + 36];
do
{
*v3 = 1;
v3 += 6;
}
while ( v3 != (_DWORD *)v4 );
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
char *v1; // rax
char *v2; // rdx
_DWORD *v3; // rax
__int64 v4; // rdx

v0 = size_of_memory;
v1 = (char *)malloc(24LL * size_of_memory);
page_table = (__int64)v1;
if ( !v1 )
{
fwrite("Simulator error: cannot allocate memory for page table.\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
v2 = v1;
if ( v0 > 0 )
{
v3 = v1 + 12;
v4 = (__int64)&v2[24 * (v0 - 1) + 36];
do
{
*v3 = 1;
v3 += 6;
}
while ( v3 != (_DWORD *)v4 );
}
return 0xFFFFFFFFLL;
}

original_code:
int initialize()
{
 int i;
 page_table = (struct page_table_entry *)malloc(sizeof(struct page_table_entry) *
   size_of_memory);
 if (page_table == ((void *)0)) {
   fprintf(stderr, "Simulator error: cannot allocate memory for page table.\n");
   exit(1);
 }
 for (i=0; i<size_of_memory; i++) {
   page_table[i].free = 1;
 }
       return -1;
}

user_defined_types: struct page_table_entry { long page_num; int dirty; int free; int ticks_since_use; }


finalize

decompiled_code:
__int64 finalize()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func12()
{
return 0xFFFFFFFFLL;
}

original_code:
int finalize()
{
       return -1;
}

canonical_original_code:
int finalize()
{
       return -1;
}


decompiled_code:
void __fastcall __noreturn error_resolve_address(__int64 a1, unsigned int a2)
{
fputc(10, stderr);
fprintf(stderr, "Simulator error: cannot resolve address 0x%lx at line %d\n", a1, a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(__int64 a1, unsigned int a2)
{
fputc(10, stderr);
fprintf(stderr, "Simulator error: cannot resolve address 0x%lx at line %d\n", a1, a2);
exit(1);
}

original_code:
void error_resolve_address(long a, int l)
{
 fprintf(stderr, "\n");
 fprintf(stderr, "Simulator error: cannot resolve address 0x%lx at line %d\n",
   a, l);
 exit(1);
}

variable_types: a long

variable_types: l int