original_code:
skO *parse_number (char **next)
{
 char *c = *next;
 char buffer[256];
 short i = 0;
 if (*c == '-' && c[1] >= '0' && c[1] <= '9') {
  buffer[i] = *c;
  i++;
  c++;
 }
 if (*c == '.')
  return ((void *)0);
 while (1) {
  if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISdigit))
   break;
  buffer[i] = *c;
  i++;
  c++;
 }
 if (*c == '.') {
  buffer[i] = *c;
  i++;
  c++;
  while (1) {
   if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISdigit))
    break;
   buffer[i] = *c;
   i++;
   c++;
  }
 }
 buffer[i] = 0;
 if ((((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace) || *c == '[' || *c == ']' || *c == '(' || *c == ')' || *c == 0) && i) {
  char **dummy = ((void *)0);
  *next = c;
  return skO_number_new(strtod(buffer, dummy));
 } else {
  return ((void *)0);
 }
}

canonical_original_code:
struct skO *parse_number(char **next)
{
 char *c = *next;
 char buffer[256];
 short i = 0;
 if (*c == '-' && c[1] >= '0' && c[1] <= '9') {
  buffer[i] = *c;
  i++;
  c++;
 }
 if (*c == '.')
  return ((void *)0);
 while (1) {
  if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISdigit))
   break;
  buffer[i] = *c;
  i++;
  c++;
 }
 if (*c == '.') {
  buffer[i] = *c;
  i++;
  c++;
  while (1) {
   if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISdigit))
    break;
   buffer[i] = *c;
   i++;
   c++;
  }
 }
 buffer[i] = 0;
 if ((((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace) || *c == '[' || *c == ']' || *c == '(' || *c == ')' || *c == 0) && i) {
  char **dummy = ((void *)0);
  *next = c;
  return skO_number_new(strtod(buffer, dummy));
 } else {
  return ((void *)0);
 }
}

variable_types:
buffer
char [256]

variable_types: i short

variable_types:
dummy
char **


repo: hashmal/shirka

decompiled_code:
__int64 __fastcall parse_character(char **a1)
{
char *v2; // rax
char v3; // di

v2 = *a1;
v3 = **a1;
if ( v3 == 92 )
{
v3 = v2[1];
if ( v3 != 34 )
{
fprintf(stderr, "PANIC! Unknown escape sequence \\%c.\n", (unsigned int)v3);
exit(1);
}
++v2;
}
*a1 = v2 + 1;
return skO_character_new((unsigned int)v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1)
{
char *v2; // rax
char v3; // di

v2 = *a1;
v3 = **a1;
if ( v3 == 92 )
{
v3 = v2[1];
if ( v3 != 34 )
{
fprintf(stderr, "PANIC! Unknown escape sequence \\%c.\n", (unsigned int)v3);
exit(1);
}
++v2;
}
*a1 = v2 + 1;
return skO_character_new((unsigned int)v3);
}

original_code:
skO *parse_character (char **next, jmp_buf jmp)
{
 char *c = *next;
 char result = 0;
 if (*c == '\\') {
  c++;
  switch (*c) {
  case '\\':
   result = '\\';
   break;
  case '"':
   result = '"';
   break;
  case 'a':
   result = '\a';
   break;
  case 'b':
   result = '\b';
   break;
  case 'f':
   result = '\f';
   break;
  case 'n':
   result = '\n';
   break;
  case 'r':
   result = '\r';
   break;
  case 's':
   result = ' ';
   break;
  case 't':
   result = '\t';
   break;
  case 'v':
   result = '\v';
   break;
  default:
   do { fprintf (stderr, "PANIC! Unknown escape sequence \\%c.\n", *c); exit(1); } while (0);
   longjmp(jmp, 1);
  }
 } else {
  result = *c;
 }
 c++;
 *next = c;
 return skO_character_new(result);
}

canonical_original_code:
struct skO *parse_character(char **next, struct __jmp_buf_tag jmp[1])
{
 char *c = *next;
 char result = 0;
 if (*c == '\\') {
  c++;
  switch (*c) {
  case '\\':
   result = '\\';
   break;
  case '"':
   result = '"';
   break;
  case 'a':
   result = '\a';
   break;
  case 'b':
   result = '\b';
   break;
  case 'f':
   result = '\f';
   break;
  case 'n':
   result = '\n';
   break;
  case 'r':
   result = '\r';
   break;
  case 's':
   result = ' ';
   break;
  case 't':
   result = '\t';
   break;
  case 'v':
   result = '\v';
   break;
  default:
   do { fprintf (stderr, "PANIC! Unknown escape sequence \\%c.\n", *c); exit(1); } while (0);
   longjmp(jmp, 1);
  }
 } else {
  result = *c;
 }
 c++;
 *next = c;
 return skO_character_new(result);
}

variable_types:
next
char **

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]

variable_types:
c
char *

variable_types: result char

return_type: struct skO { struct skO *next; enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 } tag; union { double number; int boolean; char character; struct symbol { char name[256]; struct symbol *next; } *sym; struct skO *list; } data; } *

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }

user_defined_types: struct skO { struct skO *next; enum skO_t tag; union { double number; int boolean; char character; struct symbol *sym; struct skO *list; } data; }


decompiled_code:
__int64 __fastcall parse_character_literal(char **a1)
{
__int64 result; // rax

result = 0LL;
if ( **a1 == 39 )
{
++*a1;
result = parse_character(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1)
{
__int64 result; // rax

result = 0LL;
if ( **a1 == 39 )
{
++*a1;
result = func2(a1);
}
return result;
}

original_code:
skO *parse_character_literal (char **next, jmp_buf jmp)
{
 if (**next != '\'')
  return ((void *)0);
 ++*next;
 return parse_character(next, jmp);
}

canonical_original_code:
struct skO *parse_character_literal(char **next, struct __jmp_buf_tag jmp[1])
{
 if (**next != '\'')
  return ((void *)0);
 ++*next;
 return parse_character(next, jmp);
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 }

user_defined_types: struct symbol { char name[256]; struct symbol *next; }


original_code:
skO *parse_op_def (char **next)
{
 char *src = *next;
 skO *sym;
 if (src[0] == '=' && src[1] == '>') {
  src++;
  src++;
  consume_leading(&src);
  sym = parse_identifier(&src);
  if (sym) {
   *next = src;
   sym->tag = SKO_QSYMBOL;
   return(sym);
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct skO *parse_op_def(char **next)
{
 char *src = *next;
 struct skO *sym;
 if (src[0] == '=' && src[1] == '>') {
  src++;
  src++;
  consume_leading(&src);
  sym = parse_identifier(&src);
  if (sym) {
   *next = src;
   sym->tag = SKO_QSYMBOL;
   return(sym);
  }
 }
 return ((void *)0);
}

variable_types:
src
char *

variable_types: struct skO { struct skO *next; enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 } tag; union { double number; int boolean; char character; struct symbol { char name[256]; struct symbol *next; } *sym; struct skO *list; } data; } *


original_code:
skO *parse_obj_reserve (char **next)
{
 char *src = *next;
 skO *sym;
 if (src[0] == '-' && src[1] == '>') {
  src++;
  src++;
  consume_leading(&src);
  sym = parse_identifier(&src);
  if (sym) {
   *next = src;
   sym->tag = SKO_QSYMBOL;
   return(sym);
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct skO *parse_obj_reserve(char **next)
{
 char *src = *next;
 struct skO *sym;
 if (src[0] == '-' && src[1] == '>') {
  src++;
  src++;
  consume_leading(&src);
  sym = parse_identifier(&src);
  if (sym) {
   *next = src;
   sym->tag = SKO_QSYMBOL;
   return(sym);
  }
 }
 return ((void *)0);
}


original_code:
skO *parse_obj_restore (char **next)
{
 char *src = *next;
 skO *sym;
 if (src[0] == '<' && src[1] == '-') {
  src++;
  src++;
  consume_leading(&src);
  sym = parse_identifier(&src);
  if (sym) {
   *next = src;
   sym->tag = SKO_QSYMBOL;
   return(sym);
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct skO *parse_obj_restore(char **next)
{
 char *src = *next;
 struct skO *sym;
 if (src[0] == '<' && src[1] == '-') {
  src++;
  src++;
  consume_leading(&src);
  sym = parse_identifier(&src);
  if (sym) {
   *next = src;
   sym->tag = SKO_QSYMBOL;
   return(sym);
  }
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall parse_string_literal(char **a1)
{
__int64 v1; // rbp
char *i; // rax
__int64 v3; // rax

v1 = 0LL;
if ( **a1 == 34 )
{
++*a1;
v1 = skO_list_new();
for ( i = *a1; **a1 != 34; i = *a1 )
{
v3 = parse_character(a1);
sk_list_append(v1, v3);
}
*a1 = i + 1;
}
return v1;
}

original_code:
skO *parse_string_literal (char **next, jmp_buf jmp)
{
 skO *list;
 if (**next != '"')
  return ((void *)0);
 ++*next;
 list = skO_list_new();
 while (**next != '"')
  sk_list_append(list, parse_character(next, jmp));
 ++*next;
 return list;
}

canonical_original_code:
struct skO *parse_string_literal(char **next, struct __jmp_buf_tag jmp[1])
{
 struct skO *list;
 if (**next != '"')
  return ((void *)0);
 ++*next;
 list = skO_list_new();
 while (**next != '"')
  sk_list_append(list, parse_character(next, jmp));
 ++*next;
 return list;
}


decompiled_code:
__int64 __fastcall skO_parse(char **a1, struct __jmp_buf_tag *a2, _BYTE *a3)
{
__int64 v4; // rsi
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r9
__int64 v9; // rsi
_QWORD *v10; // rbx
__int64 v11; // rsi
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // r8
__int64 v15; // r9
__int64 v16; // rsi
__int64 v17; // rdx
__int64 v18; // rcx
__int64 v19; // r8
__int64 v20; // r9
__int64 v21; // [rsp+0h] [rbp-F8h]
jmp_buf env; // [rsp+20h] [rbp-D8h] BYREF
char *v25[2]; // [rsp+E8h] [rbp-10h] BYREF

v21 = skO_list_new();
v25[0] = *a1;
consume_leading(v25);
if ( setjmp(env) )
{
skO_free(v21);
puts("parse jmp");
}
if ( a3 )
{
if ( *v25[0] == *a3 )
{
++v25[0];
consume_leading(v25);
goto LABEL_15;
}
v21 = 0LL;
}
else
{
if ( !*v25[0] )
exit(1);
while ( 1 )
{
LABEL_15:
consume_leading(v25);
if ( !*v25[0] )
{
*a1 = v25[0];
return v21;
}
if ( a3 && *v25[0] == a3[1] )
break;
v10 = (_QWORD *)skO_parse(v25, env, "()");
if ( v10 )
consume_leading(v25);
v11 = parse_op_def(v25);
if ( v11 )
{
sk_list_append(v21, v11);
v9 = skO_symbol_new("$=>", v11, v12, v13, v14, v15, v21);
}
else
{
v4 = parse_obj_reserve(v25);
if ( v4 )
{
sk_list_append(v21, v4);
v9 = skO_symbol_new("$->", v4, v5, v6, v7, v8, v21);
}
else
{
v16 = parse_obj_restore(v25);
if ( v16 )
{
sk_list_append(v21, v16);
v9 = skO_symbol_new("$<-", v16, v17, v18, v19, v20, v21);
}
else
{
v9 = parse_string_literal(v25);
if ( !v9 )
{
v9 = parse_number(v25);
if ( !v9 )
{
v9 = parse_qidentifier(v25);
if ( !v9 )
{
v9 = parse_identifier(v25);
if ( !v9 )
{
v9 = parse_character_literal(v25);
if ( !v9 )
{
v9 = skO_parse(v25, env, "[]");
if ( !v9 )
{
fprintf(stderr, "PANIC! Parsing error: %s\n", v25[0]);
longjmp(a2, 1);
}
}
}
}
}
}
}
}
}
sk_list_append(v21, v9);
if ( v10 )
{
sk_list_append(v21, v10[2]);
free(v10);
}
}
*a1 = v25[0] + 1;
}
return v21;
}

original_code:
skO *skO_parse (char **next, jmp_buf jmp, char *delim)
{
 skO *obj;
 skO *list = skO_list_new();
 skO *prefixed = ((void *)0);
 char *src = *next;
 jmp_buf pe;
 int ended = 0;
 consume_leading(&src);
 if (_setjmp (pe)) {
  if (prefixed)
   free(prefixed);
  skO_free(list);
  printf("parse jmp\n");
 }
 if (delim) {
  if (*src != delim[0])
   return ((void *)0);
  src++;
  consume_leading(&src);
 } else if (*src == 0) {
  ended = 1;
  exit(1);
 }
 while (!ended) {
  consume_leading(&src);
  if (*src == 0) {
   ended = 1;
   *next = src;
   break;
  }
  if (delim) {
   if (*src == delim[1]) {
    src++;
    *next = src;
    return list;
   }
  }
  prefixed = skO_parse(&src, pe, "()");
  if (prefixed)
   consume_leading(&src);
  obj = parse_op_def(&src);
  if (obj) {
   sk_list_append(list, obj);
   obj = skO_symbol_new("$=>");
   goto matched;
  }
  obj = parse_obj_reserve(&src);
  if (obj) {
   sk_list_append(list, obj);
   obj = skO_symbol_new("$->");
   goto matched;
  }
  obj = parse_obj_restore(&src);
  if (obj) {
   sk_list_append(list, obj);
   obj = skO_symbol_new("$<-");
   goto matched;
  }
  if ((obj = parse_string_literal(&src, pe))
   || (obj = parse_number(&src))
   || (obj = parse_qidentifier(&src))
   || (obj = parse_identifier(&src))
   || (obj = parse_character_literal(&src, pe))
   || (obj = skO_parse(&src, pe, "[]")))
   goto matched;
  fprintf(stderr, "PANIC! Parsing error: %s\n", src);
  longjmp(jmp, 1);
 matched:
  sk_list_append(list, obj);
  if (prefixed) {
   sk_list_append(list, prefixed->data.list);
   free(prefixed);
   prefixed = ((void *)0);
  }
 }
 *next = src;
 return list;
}

canonical_original_code:
struct skO *skO_parse(char **next, struct __jmp_buf_tag jmp[1], char *delim)
{
 struct skO *obj;
 struct skO *list = skO_list_new();
 struct skO *prefixed = ((void *)0);
 char *src = *next;
 struct __jmp_buf_tag pe[1];
 int ended = 0;
 consume_leading(&src);
 if (_setjmp (pe)) {
  if (prefixed)
   free(prefixed);
  skO_free(list);
  printf("parse jmp\n");
 }
 if (delim) {
  if (*src != delim[0])
   return ((void *)0);
  src++;
  consume_leading(&src);
 } else if (*src == 0) {
  ended = 1;
  exit(1);
 }
 while (!ended) {
  consume_leading(&src);
  if (*src == 0) {
   ended = 1;
   *next = src;
   break;
  }
  if (delim) {
   if (*src == delim[1]) {
    src++;
    *next = src;
    return list;
   }
  }
  prefixed = skO_parse(&src, pe, "()");
  if (prefixed)
   consume_leading(&src);
  obj = parse_op_def(&src);
  if (obj) {
   sk_list_append(list, obj);
   obj = skO_symbol_new("$=>");
   goto matched;
  }
  obj = parse_obj_reserve(&src);
  if (obj) {
   sk_list_append(list, obj);
   obj = skO_symbol_new("$->");
   goto matched;
  }
  obj = parse_obj_restore(&src);
  if (obj) {
   sk_list_append(list, obj);
   obj = skO_symbol_new("$<-");
   goto matched;
  }
  if ((obj = parse_string_literal(&src, pe))
   || (obj = parse_number(&src))
   || (obj = parse_qidentifier(&src))
   || (obj = parse_identifier(&src))
   || (obj = parse_character_literal(&src, pe))
   || (obj = skO_parse(&src, pe, "[]")))
   goto matched;
  fprintf(stderr, "PANIC! Parsing error: %s\n", src);
  longjmp(jmp, 1);
 matched:
  sk_list_append(list, obj);
  if (prefixed) {
   sk_list_append(list, prefixed->data.list);
   free(prefixed);
   prefixed = ((void *)0);
  }
 }
 *next = src;
 return list;
}

variable_types:
delim
char *

variable_types: ended int


printError

repo: hatsuseno/bigextract

decompiled_code:
void __fastcall __noreturn printError(const char *a1)
{
printf("BigExtract: %s\nBigExtract: calling it a day...", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
printf("BigExtract: %s\nBigExtract: calling it a day...", a1);
exit(1);
}

original_code:
void printError(char *emsg) {
  printf("BigExtract: %s\nBigExtract: calling it a day...", emsg);
  exit(1);
}

variable_types:
emsg
char *

return_type: void


printHelp

decompiled_code:
void __fastcall __noreturn printHelp(const char *a1)
{
printf("BigExtract v%s help\n", version);
puts("Released in public domain, as is");
puts("Rudolf Leermakers <rudolf@hatsuseno.org>\n");
printf(" Usage : %s <options> [filename]\n\n", a1);
puts(" -f do a normal search, if possible by index");
puts(" -x extract files");
puts(" -n name extract files to name@adress");
puts(" -d name output matrix of found files to file");
puts(" -h display this message\n");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
printf("BigExtract v%s help\n", version);
puts("Released in public domain, as is");
puts("Rudolf Leermakers <rudolf@hatsuseno.org>\n");
printf(" Usage : %s <options> [filename]\n\n", a1);
puts(" -f do a normal search, if possible by index");
puts(" -x extract files");
puts(" -n name extract files to name@adress");
puts(" -d name output matrix of found files to file");
puts(" -h display this message\n");
exit(1);
}

original_code:
void printHelp(char *filename) {
  printf("BigExtract v%s help\n", version);
  printf("Released in public domain, as is\n");
  printf("Rudolf Leermakers <rudolf@hatsuseno.org>\n\n");
  printf(" Usage : %s <options> [filename]\n\n", filename);
 printf(" -f        do a normal search, if possible by index\n");
  printf(" -x        extract files\n");
 printf(" -n name   extract files to name@adress\n");
 printf(" -d name   output matrix of found files to file\n");
 printf(" -h        display this message\n\n");
 exit(1);
}

variable_types:
filename
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rax
unsigned int *v4; // rbp
const char *v5; // rax
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = (unsigned int *)malloc(0x1000uLL);
v7[0] = 0;
if ( argc <= 2 )
printHelp(*argv);
v4 = v3;
v5 = argv[1];
if ( *v5 != 45 )
printHelp(*argv);
switch ( v5[1] )
{
case 'd':
findFiles((char *)argv[3], (__int64)v4, v7);
outputMatrix(argv[2], v4, v7);
break;
case 'e':
case 'f':
findFiles((char *)argv[2], (__int64)v4, v7);
break;
case 'h':
printHelp(*argv);
case 'n':
findFiles((char *)argv[3], (__int64)v4, v7);
extractFiles((char *)argv[3], argv[2], (__int64)v4, (FILE *)v7);
break;
case 'x':
findFiles((char *)argv[2], (__int64)v4, v7);
extractFiles((char *)argv[2], argv[2], (__int64)v4, (FILE *)v7);
break;
default:
printHelp(*argv);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rax
unsigned int *v4; // rbp
const char *v5; // rax
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = (unsigned int *)malloc(0x1000uLL);
v7[0] = 0;
if ( argc <= 2 )
func9(*argv);
v4 = v3;
v5 = argv[1];
if ( *v5 != 45 )
func9(*argv);
switch ( v5[1] )
{
case 'd':
func10((char *)argv[3], (__int64)v4, v7);
func8(argv[2], v4, v7);
break;
case 'e':
case 'f':
func10((char *)argv[2], (__int64)v4, v7);
break;
case 'h':
func9(*argv);
case 'n':
func10((char *)argv[3], (__int64)v4, v7);
extractFiles((char *)argv[3], argv[2], (__int64)v4, (FILE *)v7);
break;
case 'x':
func10((char *)argv[2], (__int64)v4, v7);
extractFiles((char *)argv[2], argv[2], (__int64)v4, (FILE *)v7);
break;
default:
func9(*argv);
}
return 0;
}

original_code:
int main(int argc, char **argv) {
  int *matrix = malloc(1024*sizeof(int)), fc=0;
  if(argc < 3) { printHelp(argv[0]); }
  if(argv[1][0] == '-') {
    switch(argv[1][1]) {
      case 'f': findFiles(argv[2], matrix, &fc); break;
      case 'x': findFiles(argv[2], matrix, &fc); extractFiles(argv[2], argv[2], matrix, &fc); break;
      case 'n': findFiles(argv[3], matrix, &fc); extractFiles(argv[3], argv[2], matrix, &fc); break;
      case 'd': findFiles(argv[3], matrix, &fc); outputMatrix(argv[2], matrix, &fc); break;
      case 'e': findFiles(argv[2], matrix, &fc); break;
      case 'h': printHelp(argv[0]); break;
      default : printHelp(argv[0]);
    }
  }else {
    printHelp(argv[0]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int *matrix = malloc(1024*sizeof(int)); int fc = 0;
  if(argc < 3) { printHelp(argv[0]); }
  if(argv[1][0] == '-') {
    switch(argv[1][1]) {
      case 'f': findFiles(argv[2], matrix, &fc); break;
      case 'x': findFiles(argv[2], matrix, &fc); extractFiles(argv[2], argv[2], matrix, &fc); break;
      case 'n': findFiles(argv[3], matrix, &fc); extractFiles(argv[3], argv[2], matrix, &fc); break;
      case 'd': findFiles(argv[3], matrix, &fc); outputMatrix(argv[2], matrix, &fc); break;
      case 'e': findFiles(argv[2], matrix, &fc); break;
      case 'h': printHelp(argv[0]); break;
      default : printHelp(argv[0]);
    }
  }else {
    printHelp(argv[0]);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
matrix
int *

variable_types: fc int

return_type: int


checkLU

repo: haulisson/denseLinearAlgebraHybrid

decompiled_code:
__int64 checkLU()
{
__int64 v0; // rdx
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
double *v4; // r12
unsigned int v5; // er13
unsigned int i; // ebx
double v7; // r15
double v8; // xmm0_8
double v9; // r15
double v10; // rbp
__int64 v12; // [rsp+0h] [rbp-98h] BYREF
__int64 v13; // [rsp+8h] [rbp-90h]
__int64 v14; // [rsp+10h] [rbp-88h] BYREF
__int64 v15; // [rsp+18h] [rbp-80h]
__int64 v16; // [rsp+20h] [rbp-78h] BYREF
__int64 v17; // [rsp+28h] [rbp-70h]
__int64 v18; // [rsp+30h] [rbp-68h] BYREF
__int64 v19; // [rsp+38h] [rbp-60h]
__int64 v20[3]; // [rsp+40h] [rbp-58h] BYREF
char v21; // [rsp+58h] [rbp-40h] BYREF

v20[0] = LC0;
v20[1] = LC1;
v20[2] = LC2;
v18 = allocAndInitRandomizedMatrix(100LL, 100LL);
v19 = v0;
v16 = allocAndInitZeroMatrix(100LL, 100LL);
v17 = v1;
v14 = allocAndInitZeroMatrix(100LL, 100LL);
v15 = v2;
v12 = allocAndInitZeroMatrix(100LL, 100LL);
v13 = v3;
v4 = (double *)v20;
v5 = 1;
do
{
v10 = *v4;
printf("Tests for cond = %e :\n\n", *v4);
for ( i = 0; i != 5; ++i )
{
getCondNumberMatrix(&v18, i, v10);
v7 = read_timer();
LUFactorize(v18, v19, &v16, &v14);
v8 = read_timer();
printf("Elapsed time = %f seconds.\n", v8 - v7);
matrixMatrixMultiply(v16, v17, v14, v15, &v12);
v9 = maxDiffMatrix(v12, v13, v18, v19);
printf("maxDiff = %e\n", v9);
if ( v9 >= 1.0e-10 )
{
printf("LU factorization test failed on matrix of type %d.\n\n", i);
v5 = 0;
}
else
{
printf("LU factorization test passed on matrix of type %d.\n\n", i);
}
}
++v4;
}
while ( v4 != (double *)&v21 );
if ( (_BYTE)v5 )
puts("LU factorization test passed.\n");
else
puts("LU factorization test failed.\n");
freeMatrix(v18, v19);
freeMatrix(v16, v17);
freeMatrix(v14, v15);
freeMatrix(v12, v13);
return v5;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdx
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
double *v4; // r12
unsigned int v5; // er13
unsigned int i; // ebx
double v7; // r15
double v8; // xmm0_8
double v9; // r15
double v10; // rbp
__int64 v12; // [rsp+0h] [rbp-98h] BYREF
__int64 v13; // [rsp+8h] [rbp-90h]
__int64 v14; // [rsp+10h] [rbp-88h] BYREF
__int64 v15; // [rsp+18h] [rbp-80h]
__int64 v16; // [rsp+20h] [rbp-78h] BYREF
__int64 v17; // [rsp+28h] [rbp-70h]
__int64 v18; // [rsp+30h] [rbp-68h] BYREF
__int64 v19; // [rsp+38h] [rbp-60h]
__int64 v20[3]; // [rsp+40h] [rbp-58h] BYREF
char v21; // [rsp+58h] [rbp-40h] BYREF

v20[0] = LC0;
v20[1] = LC1;
v20[2] = LC2;
v18 = allocAndInitRandomizedMatrix(100LL, 100LL);
v19 = v0;
v16 = allocAndInitZeroMatrix(100LL, 100LL);
v17 = v1;
v14 = allocAndInitZeroMatrix(100LL, 100LL);
v15 = v2;
v12 = allocAndInitZeroMatrix(100LL, 100LL);
v13 = v3;
v4 = (double *)v20;
v5 = 1;
do
{
v10 = *v4;
printf("Tests for cond = %e :\n\n", *v4);
for ( i = 0; i != 5; ++i )
{
getCondNumberMatrix(&v18, i, v10);
v7 = read_timer();
LUFactorize(v18, v19, &v16, &v14);
v8 = read_timer();
printf("Elapsed time = %f seconds.\n", v8 - v7);
matrixMatrixMultiply(v16, v17, v14, v15, &v12);
v9 = maxDiffMatrix(v12, v13, v18, v19);
printf("maxDiff = %e\n", v9);
if ( v9 >= 1.0e-10 )
{
printf("LU factorization test failed on matrix of type %d.\n\n", i);
v5 = 0;
}
else
{
printf("LU factorization test passed on matrix of type %d.\n\n", i);
}
}
++v4;
}
while ( v4 != (double *)&v21 );
if ( (_BYTE)v5 )
puts("LU factorization test passed.\n");
else
puts("LU factorization test failed.\n");
freeMatrix(v18, v19);
freeMatrix(v16, v17);
freeMatrix(v14, v15);
freeMatrix(v12, v13);
return v5;
}

original_code:
char checkLU(){
 int j;
 int n = 100 ;
 double tolMax = 1e-10 ;
 char pass = 1;
 double cond[3] = {10.0, 1.0 / sqrt(1e-14), 1.0 / 1e-14} ;
 int numConds = 3;
 int type = 4;
 double startTime, endTime;
 matrix A = allocAndInitRandomizedMatrix(n,n) ;
 matrix L = allocAndInitZeroMatrix(n, n) ;
 matrix U = allocAndInitZeroMatrix(n, n) ;
 matrix product = allocAndInitZeroMatrix(n,n) ;
 for(j=0; j<numConds; j++){
  printf("Tests for cond = %e :\n\n", cond[j]) ;
  for(type = 0; type < 5; type++){
   getCondNumberMatrix(&A, cond[j], type) ;
   startTime = read_timer();
   LUFactorize(A, &L, &U) ;
   endTime = read_timer();
   printf("Elapsed time = %f seconds.\n", endTime - startTime);
   matrixMatrixMultiply(L, U, &product) ;
   char output = 0;
   if(output){
    printf("Input matrix:\n");
    printMatrix(A);
    printf("U = \n") ;
    printMatrix(U);
    printf("L = \n") ;
    printMatrix(L);
    printMatrix(product) ;
   }
   double maxDiff = maxDiffMatrix(product, A) ;
   printf("maxDiff = %e\n", maxDiff) ;
   if(maxDiff < tolMax){
    printf("LU factorization test passed on matrix of type %d.\n\n", type) ;
   }
   else{
    printf("LU factorization test failed on matrix of type %d.\n\n", type) ;
    pass = 0;
   }
  }
 }
 if(pass)
  printf("LU factorization test passed.\n\n") ;
 else
  printf("LU factorization test failed.\n\n") ;
 freeMatrix(A) ;
 freeMatrix(L) ;
 freeMatrix(U) ;
 freeMatrix(product) ;
 return pass;
}

canonical_original_code:
char checkLU(){
 int j;
 int n = 100;
 double tolMax = 1e-10;
 char pass = 1;
 double cond[3] = {10.0, 1.0 / sqrt(1e-14), 1.0 / 1e-14};
 int numConds = 3;
 int type = 4;
 double startTime; double endTime;
 struct matrix A = allocAndInitRandomizedMatrix(n,n);
 struct matrix L = allocAndInitZeroMatrix(n, n);
 struct matrix U = allocAndInitZeroMatrix(n, n);
 struct matrix product = allocAndInitZeroMatrix(n,n);
 for(j=0; j<numConds; j++){
  printf("Tests for cond = %e :\n\n", cond[j]) ;
  for(type = 0; type < 5; type++){
   getCondNumberMatrix(&A, cond[j], type) ;
   startTime = read_timer();
   LUFactorize(A, &L, &U) ;
   endTime = read_timer();
   printf("Elapsed time = %f seconds.\n", endTime - startTime);
   matrixMatrixMultiply(L, U, &product) ;
   char output = 0;
   if(output){
    printf("Input matrix:\n");
    printMatrix(A);
    printf("U = \n") ;
    printMatrix(U);
    printf("L = \n") ;
    printMatrix(L);
    printMatrix(product) ;
   }
   double maxDiff = maxDiffMatrix(product, A);
   printf("maxDiff = %e\n", maxDiff) ;
   if(maxDiff < tolMax){
    printf("LU factorization test passed on matrix of type %d.\n\n", type) ;
   }
   else{
    printf("LU factorization test failed on matrix of type %d.\n\n", type) ;
    pass = 0;
   }
  }
 }
 if(pass)
  printf("LU factorization test passed.\n\n") ;
 else
  printf("LU factorization test failed.\n\n") ;
 freeMatrix(A) ;
 freeMatrix(L) ;
 freeMatrix(U) ;
 freeMatrix(product) ;
 return pass;
}

variable_types: j int

variable_types: n int

variable_types: tolMax double

variable_types: pass char

variable_types:
cond
double [3]

variable_types: numConds int

variable_types: type int

variable_types: startTime double

variable_types: endTime double

variable_types: struct matrix { double **values; int m; int n; }

variable_types: output char

variable_types: maxDiff double

return_type: char


checkQR

decompiled_code:
__int64 checkQR()
{
void *v0; // r12
__int64 v1; // rdx
unsigned int v2; // er13
unsigned int i; // ebx
double v4; // r14
void *v5; // rbp
double v6; // xmm0_8
double v7; // r14
__int64 v9; // [rsp+0h] [rbp-38h] BYREF
__int64 v10; // [rsp+8h] [rbp-30h]

v0 = malloc(0x320uLL);
v9 = allocAndInitZeroMatrix(100LL, 100LL);
v10 = v1;
v2 = 1;
for ( i = 0; i != 9; ++i )
{
getEigenvalueTestMatrix(100LL, i, &v9, v0);
qsort(v0, 0x64uLL, 8uLL, (__compar_fn_t)&compareDoubles);
v4 = read_timer();
v5 = (void *)symmetricQR(v9, v10);
v6 = read_timer();
printf("Elapsed time = %f seconds.\n", v6 - v4);
v7 = maxDiffVector(v5, v0, 100LL);
printf("maxDiff = %e\n", v7);
if ( v7 >= 1.0e-12 )
{
printf("QR factorization for eigenvalues test failed on matrix of type %d.\n\n", i);
v2 = 0;
}
else
{
printf("QR factorization for eigenvalues test passed on matrix of type %d.\n\n", i);
}
}
if ( (_BYTE)v2 )
puts("QR factorization for eigenvalues test passed.\n");
else
puts("QR factorization for eigenvalues test failed.\n");
free(v5);
free(v0);
freeMatrix(v9, v10);
return v2;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // r12
__int64 v1; // rdx
unsigned int v2; // er13
unsigned int i; // ebx
double v4; // r14
void *v5; // rbp
double v6; // xmm0_8
double v7; // r14
__int64 v9; // [rsp+0h] [rbp-38h] BYREF
__int64 v10; // [rsp+8h] [rbp-30h]

v0 = malloc(0x320uLL);
v9 = allocAndInitZeroMatrix(100LL, 100LL);
v10 = v1;
v2 = 1;
for ( i = 0; i != 9; ++i )
{
getEigenvalueTestMatrix(100LL, i, &v9, v0);
qsort(v0, 0x64uLL, 8uLL, (__compar_fn_t)&compareDoubles);
v4 = read_timer();
v5 = (void *)symmetricQR(v9, v10);
v6 = read_timer();
printf("Elapsed time = %f seconds.\n", v6 - v4);
v7 = maxDiffVector(v5, v0, 100LL);
printf("maxDiff = %e\n", v7);
if ( v7 >= 1.0e-12 )
{
printf("QR factorization for eigenvalues test failed on matrix of type %d.\n\n", i);
v2 = 0;
}
else
{
printf("QR factorization for eigenvalues test passed on matrix of type %d.\n\n", i);
}
}
if ( (_BYTE)v2 )
puts("QR factorization for eigenvalues test passed.\n");
else
puts("QR factorization for eigenvalues test failed.\n");
free(v5);
free(v0);
freeMatrix(v9, v10);
return v2;
}

original_code:
char checkQR(){
 int n = 100;
 int type ;
 double tolMax = 1e-12 ;
 char pass = 1;
 int numTypes = 9 ;
 double maxDiff ;
 char output = 0;
 double startTime, endTime;
 double *eigsOriginal = (double *) malloc(n * sizeof(double)) ;
 matrix A = allocAndInitZeroMatrix(n,n);
 double *eigs ;
 for(type=0; type < numTypes; type++){
  getEigenvalueTestMatrix(n, type, &A, eigsOriginal) ;
  qsort(eigsOriginal, n, sizeof(double), compareDoubles) ;
  if(output){
   printf("Input matrix:\n") ;
   printMatrix(A) ;
  }
  startTime = read_timer();
  eigs = symmetricQR(A) ;
  endTime = read_timer();
  printf("Elapsed time = %f seconds.\n", endTime - startTime);
  if(output){
   printf("Known eigenvalues = \n") ;
   printVector(eigsOriginal, n) ;
   printf("Computed eigenvalues = \n") ;
   printVector(eigs, n) ;
  }
  maxDiff = maxDiffVector(eigs, eigsOriginal, n) ;
  printf("maxDiff = %e\n", maxDiff);
  if (maxDiff < tolMax) {
   printf("QR factorization for eigenvalues test passed on matrix of type %d.\n\n", type);
  } else {
   printf("QR factorization for eigenvalues test failed on matrix of type %d.\n\n", type);
   pass = 0;
  }
 }
 if(pass)
  printf("QR factorization for eigenvalues test passed.\n\n") ;
 else
  printf("QR factorization for eigenvalues test failed.\n\n") ;
 free(eigs) ;
 free(eigsOriginal) ;
 freeMatrix(A) ;
 return pass;
}

canonical_original_code:
char checkQR(){
 int n = 100;
 int type;
 double tolMax = 1e-12;
 char pass = 1;
 int numTypes = 9;
 double maxDiff;
 char output = 0;
 double startTime; double endTime;
 double *eigsOriginal = (double *) malloc(n * sizeof(double));
 struct matrix A = allocAndInitZeroMatrix(n,n);
 double *eigs;
 for(type=0; type < numTypes; type++){
  getEigenvalueTestMatrix(n, type, &A, eigsOriginal) ;
  qsort(eigsOriginal, n, sizeof(double), compareDoubles) ;
  if(output){
   printf("Input matrix:\n") ;
   printMatrix(A) ;
  }
  startTime = read_timer();
  eigs = symmetricQR(A) ;
  endTime = read_timer();
  printf("Elapsed time = %f seconds.\n", endTime - startTime);
  if(output){
   printf("Known eigenvalues = \n") ;
   printVector(eigsOriginal, n) ;
   printf("Computed eigenvalues = \n") ;
   printVector(eigs, n) ;
  }
  maxDiff = maxDiffVector(eigs, eigsOriginal, n) ;
  printf("maxDiff = %e\n", maxDiff);
  if (maxDiff < tolMax) {
   printf("QR factorization for eigenvalues test passed on matrix of type %d.\n\n", type);
  } else {
   printf("QR factorization for eigenvalues test failed on matrix of type %d.\n\n", type);
   pass = 0;
  }
 }
 if(pass)
  printf("QR factorization for eigenvalues test passed.\n\n") ;
 else
  printf("QR factorization for eigenvalues test failed.\n\n") ;
 free(eigs) ;
 free(eigsOriginal) ;
 freeMatrix(A) ;
 return pass;
}

variable_types: numTypes int

variable_types:
eigsOriginal
double *

variable_types:
eigs
double *

user_defined_types: struct matrix { double **values; int m; int n; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rbp
double v4; // r12
char v5; // bl
double v6; // xmm0_8

puts("Dense Linear Algebra Tests.");
v3 = malloc(2uLL);
v4 = read_timer(2LL, argv);
v5 = checkLU();
*v3 = v5;
v3[1] = checkQR();
v6 = read_timer(2LL, argv);
printf("Total time for all tests = %f seconds.\n\n", v6 - v4);
if ( v5 )
{
printf("Test %d passed.\n", 0LL);
v5 = 1;
}
else
{
fprintf(stderr, "Test %d failed.\n", 0LL);
}
if ( !v3[1] )
{
fprintf(stderr, "Test %d failed.\n", 1LL);
v5 = 0;
goto LABEL_9;
}
printf("Test %d passed.\n", 1LL);
if ( !v5 )
{
LABEL_9:
fwrite("\nTests failed!\n", 1uLL, 0xFuLL, stderr);
goto LABEL_6;
}
puts("\nAll tests passed.\n");
LABEL_6:
free(v3);
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rbp
double v4; // r12
char v5; // bl
double v6; // xmm0_8

puts("Dense Linear Algebra Tests.");
v3 = malloc(2uLL);
v4 = read_timer(2LL, argv);
v5 = func0();
*v3 = v5;
v3[1] = func1();
v6 = read_timer(2LL, argv);
printf("Total time for all tests = %f seconds.\n\n", v6 - v4);
if ( v5 )
{
printf("Test %d passed.\n", 0LL);
v5 = 1;
}
else
{
fprintf(stderr, "Test %d failed.\n", 0LL);
}
if ( !v3[1] )
{
fprintf(stderr, "Test %d failed.\n", 1LL);
v5 = 0;
goto LABEL_9;
}
printf("Test %d passed.\n", 1LL);
if ( !v5 )
{
LABEL_9:
fwrite("\nTests failed!\n", 1uLL, 0xFuLL, stderr);
goto LABEL_6;
}
puts("\nAll tests passed.\n");
LABEL_6:
free(v3);
return v5;
}

original_code:
int main(){
 printf("Dense Linear Algebra Tests.\n") ;
 int i;
 int numTests = 2;
 char *pass = (char *) malloc(numTests * sizeof(char));
 char allPass = 1;
 double startTime, endTime;
 startTime = read_timer();
 pass[0] = checkLU() ;
 pass[1] = checkQR() ;
 endTime = read_timer();
 printf("Total time for all tests = %f seconds.\n\n", endTime - startTime);
 for(i=0; i<numTests; i++){
  if(pass[i]){
   printf("Test %d passed.\n", i) ;
   allPass &= 1;
  }
  else{
   fprintf(stderr, "Test %d failed.\n", i) ;
   allPass = 0;
  }
 }
 if( allPass )
  printf("\nAll tests passed.\n\n") ;
 else
  fprintf(stderr, "\nTests failed!\n") ;
 free(pass) ;
 return allPass;
}

canonical_original_code:
int main(){
 printf("Dense Linear Algebra Tests.\n") ;
 int i;
 int numTests = 2;
 char *pass = (char *) malloc(numTests * sizeof(char));
 char allPass = 1;
 double startTime; double endTime;
 startTime = read_timer();
 pass[0] = checkLU() ;
 pass[1] = checkQR() ;
 endTime = read_timer();
 printf("Total time for all tests = %f seconds.\n\n", endTime - startTime);
 for(i=0; i<numTests; i++){
  if(pass[i]){
   printf("Test %d passed.\n", i) ;
   allPass &= 1;
  }
  else{
   fprintf(stderr, "Test %d failed.\n", i) ;
   allPass = 0;
  }
 }
 if( allPass )
  printf("\nAll tests passed.\n\n") ;
 else
  fprintf(stderr, "\nTests failed!\n") ;
 free(pass) ;
 return allPass;
}

variable_types: i int

variable_types: numTests int

variable_types:
pass
char *

variable_types: allPass char


repo: hauspie/minunit

original_code:
static __inline__ int mu_run_test_suite(mu_test_func setup, mu_test_func tear_down, struct mu_test_desc *tests_array, int *out_success, int *out_total)
    {
 int i;
 int success = 0;
 for (i = 0 ; tests_array[i].test != ((void *)0) ; ++i)
 {
     struct mu_test_desc *desc = &tests_array[i];
     desc->success = desc->performed = 0;
     setup(desc);
     desc->test(desc);
     tear_down(desc);
     if (((desc)->performed != 0 && ((desc)->success == (desc)->performed)))
  success++;
 }
 if (out_total)
     *out_total = i;
 if (out_success)
     *out_success = success;
 if (i == success) return 0;
 return -1;
    }

canonical_original_code:
static __inline__ int mu_run_test_suite(void (*setup)(struct mu_test_desc *desc), void (*tear_down)(struct mu_test_desc *desc), struct mu_test_desc *tests_array, int *out_success, int *out_total)
    {
 int i;
 int success = 0;
 for (i = 0 ; tests_array[i].test != ((void *)0) ; ++i)
 {
     struct mu_test_desc *desc = &tests_array[i];
     desc->success = desc->performed = 0;
     setup(desc);
     desc->test(desc);
     tear_down(desc);
     if (((desc)->performed != 0 && ((desc)->success == (desc)->performed)))
  success++;
 }
 if (out_total)
     *out_total = i;
 if (out_success)
     *out_success = success;
 if (i == success) return 0;
 return -1;
    }

variable_types: void (*)(struct mu_test_desc { void (*test)(struct mu_test_desc *desc); char *test_name; int success; int performed; } *desc)

variable_types: success int


decompiled_code:
void sampleTest_setup()
{
value = 0;
}

canonical_decompiled_code:
void func8()
{
value = 0;
}

original_code:
void sampleTest_setup(struct mu_test_desc *desc)
{
    value = 0;
}

variable_types: struct mu_test_desc { void (*test)(struct mu_test_desc *desc); char *test_name; int success; int performed; } *


decompiled_code:
void __fastcall sampleTest_tear_down(__int64 a1)
{
if ( value )
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
}

original_code:
void sampleTest_tear_down(struct mu_test_desc *desc)
{
    do { if ( (((value) != (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
}

user_defined_types: struct mu_test_desc { void (*test)(struct mu_test_desc *desc); char *test_name; int success; int performed; }


decompiled_code:
void __fastcall sampleTest_test1(__int64 a1)
{
if ( !value )
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
value = 1;
}

original_code:
void sampleTest_test1(struct mu_test_desc *desc)
{
    do { if ( (((value) == (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
    value = 1;
}


decompiled_code:
void __fastcall sampleTest_test2(__int64 a1)
{
if ( !value )
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
value = 2;
}

original_code:
void sampleTest_test2(struct mu_test_desc *desc)
{
    do { if ( (((value) == (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
    value = 2;
}


decompiled_code:
void half_success_setup()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code: void half_success_setup(struct mu_test_desc *desc) {}


decompiled_code:
void half_success_tear_down()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code: void half_success_tear_down(struct mu_test_desc *desc) {}


decompiled_code:
void __fastcall half_success_success1(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
}

original_code: void half_success_success1(struct mu_test_desc *desc) { do { if ( (((0) == (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);}


decompiled_code:
void __fastcall half_success_success2(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
}

original_code: void half_success_success2(struct mu_test_desc *desc) { do { if ( (((1) != (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0); }


decompiled_code:
void __fastcall half_success_fail1(__int64 a1)
{
++*(_DWORD *)(a1 + 20);
}

original_code: void half_success_fail1(struct mu_test_desc *desc) { do { if ( (((0) == (1))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0); }


decompiled_code:
void __fastcall half_success_fail2(__int64 a1)
{
++*(_DWORD *)(a1 + 20);
}

original_code: void half_success_fail2(struct mu_test_desc *desc) { do { if ( (((0) != (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0); }


decompiled_code:
void test_half_setup()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code: void test_half_setup(struct mu_test_desc *desc) {}


decompiled_code:
void test_half_tear_down()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code: void test_half_tear_down(struct mu_test_desc *desc) {}


decompiled_code:
__int64 __fastcall test_half_run(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3; // [rsp+8h] [rbp-10h] BYREF
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)mu_run_test_suite(
(void (__fastcall *)(_QWORD *))half_success_setup,
(void (__fastcall *)(_QWORD *))half_success_tear_down,
&half_success_tests_array,
v4,
&v3) == -1 )
++*(_DWORD *)(a1 + 16);
v1 = *(_DWORD *)(a1 + 20);
if ( v4[0] == 2 )
++*(_DWORD *)(a1 + 16);
if ( v3 == 4 )
++*(_DWORD *)(a1 + 16);
result = (unsigned int)(v1 + 3);
*(_DWORD *)(a1 + 20) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3; // [rsp+8h] [rbp-10h] BYREF
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func7(
(void (__fastcall *)(_QWORD *))half_success_setup,
(void (__fastcall *)(_QWORD *))half_success_tear_down,
&half_success_tests_array,
v4,
&v3) == -1 )
++*(_DWORD *)(a1 + 16);
v1 = *(_DWORD *)(a1 + 20);
if ( v4[0] == 2 )
++*(_DWORD *)(a1 + 16);
if ( v3 == 4 )
++*(_DWORD *)(a1 + 16);
result = (unsigned int)(v1 + 3);
*(_DWORD *)(a1 + 20) = result;
return result;
}

original_code:
void test_half_run(struct mu_test_desc *desc) {
    int success, total;
    do { if ( (((mu_run_test_suite(half_success_setup, half_success_tear_down, half_success_tests_array, (&success), (&total))) == (-1))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
    do { if ( (((success) == (2))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
    do { if ( (((total) == (4))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
}

canonical_original_code:
void test_half_run(struct mu_test_desc *desc) {
    int success; int total;
    do { if ( (((mu_run_test_suite(half_success_setup, half_success_tear_down, half_success_tests_array, (&success), (&total))) == (-1))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
    do { if ( (((success) == (2))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
    do { if ( (((total) == (4))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
}

variable_types: total int


decompiled_code:
void test_assertions_setup()
{
;
}

canonical_decompiled_code:
void func21()
{
;
}

original_code: void test_assertions_setup(struct mu_test_desc *desc) {}


decompiled_code:
void test_assertions_tear_down()
{
;
}

canonical_decompiled_code:
void func22()
{
;
}

original_code: void test_assertions_tear_down(struct mu_test_desc *desc) {}


decompiled_code:
void __fastcall test_assertions_assert(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
}

original_code:
void test_assertions_assert(struct mu_test_desc *desc) {
    do { if ( ((0 == 0)) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
}


decompiled_code:
void __fastcall test_assertions_equal(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
}

original_code:
void test_assertions_equal(struct mu_test_desc *desc) {
    do { if ( (((0) == (0))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
}


decompiled_code:
void __fastcall test_assertions_notequal(__int64 a1)
{
++*(_DWORD *)(a1 + 16);
++*(_DWORD *)(a1 + 20);
}

original_code:
void test_assertions_notequal(struct mu_test_desc *desc) {
    do { if ( (((0) != (1))) ) desc->success++; else { do {} while(0) ; } desc->performed++; } while (0);
}


decompiled_code:
int __fastcall mu_report_test_suite_report(const char *a1, _QWORD *a2, unsigned int a3, unsigned int a4)
{
int result; // eax
_QWORD *v7; // rbx

printf("%s", "Suite ");
printf("%s", a1);
printf("%s", ": ");
printf("%d", a3);
putchar(47);
printf("%d", a4);
result = putchar(10);
if ( a3 != a4 )
{
result = puts("\tFailing tests:");
if ( *a2 )
{
v7 = a2 + 3;
do
{
result = *((_DWORD *)v7 - 1);
if ( !result || result != *((_DWORD *)v7 - 2) )
{
printf("%s", "\t\t");
printf("%s", (const char *)*(v7 - 2));
printf("%s", ": ");
if ( *((_DWORD *)v7 - 1) )
{
printf("%d", *((unsigned int *)v7 - 2));
putchar(47);
printf("%d", *((unsigned int *)v7 - 1));
printf("%s", " passed");
result = putchar(10);
}
else
{
result = puts("no test performed");
}
}
v7 += 3;
}
while ( *(v7 - 3) );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func26(const char *a1, _QWORD *a2, unsigned int a3, unsigned int a4)
{
int result; // eax
_QWORD *v7; // rbx

printf("%s", "Suite ");
printf("%s", a1);
printf("%s", ": ");
printf("%d", a3);
putchar(47);
printf("%d", a4);
result = putchar(10);
if ( a3 != a4 )
{
result = puts("\tFailing tests:");
if ( *a2 )
{
v7 = a2 + 3;
do
{
result = *((_DWORD *)v7 - 1);
if ( !result || result != *((_DWORD *)v7 - 2) )
{
printf("%s", "\t\t");
printf("%s", (const char *)*(v7 - 2));
printf("%s", ": ");
if ( *((_DWORD *)v7 - 1) )
{
printf("%d", *((unsigned int *)v7 - 2));
putchar(47);
printf("%d", *((unsigned int *)v7 - 1));
printf("%s", " passed");
result = putchar(10);
}
else
{
result = puts("no test performed");
}
}
v7 += 3;
}
while ( *(v7 - 3) );
}
}
return result;
}

original_code:
static __inline__ void mu_report_test_suite_report(const char *suite_name, struct mu_test_desc *tests_array, int success, int total)
    {
 printf("%s", ("Suite "));
 printf("%s", (suite_name));
 printf("%s", (": "));
 printf("%d", (success));
 printf("%c", ('/'));
 printf("%d", (total));
 printf("%c", ('\n'));
 if (success != total)
 {
     int i;
     printf("%s", ("\tFailing tests:\n"));
     for (i = 0 ; tests_array[i].test != ((void *)0) ; ++i)
     {
  struct mu_test_desc *desc = &tests_array[i];
  if (!((desc)->performed != 0 && ((desc)->success == (desc)->performed)))
  {
      printf("%s", ("\t\t"));
      printf("%s", (desc->test_name));
      printf("%s", (": "));
      if (desc->performed != 0)
      {
   printf("%d", (desc->success));
   printf("%c", ('/'));
   printf("%d", (desc->performed));
   printf("%s", (" passed"));
   printf("%s", ("\n")) ;
      }
      else
      {
   printf("%s", ("no test performed\n"));
      }
  }
     }
 }
    }

canonical_original_code:
static __inline__ void mu_report_test_suite_report(char *suite_name, struct mu_test_desc *tests_array, int success, int total)
    {
 printf("%s", ("Suite "));
 printf("%s", (suite_name));
 printf("%s", (": "));
 printf("%d", (success));
 printf("%c", ('/'));
 printf("%d", (total));
 printf("%c", ('\n'));
 if (success != total)
 {
     int i;
     printf("%s", ("\tFailing tests:\n"));
     for (i = 0 ; tests_array[i].test != ((void *)0) ; ++i)
     {
  struct mu_test_desc *desc = &tests_array[i];
  if (!((desc)->performed != 0 && ((desc)->success == (desc)->performed)))
  {
      printf("%s", ("\t\t"));
      printf("%s", (desc->test_name));
      printf("%s", (": "));
      if (desc->performed != 0)
      {
   printf("%d", (desc->success));
   printf("%c", ('/'));
   printf("%d", (desc->performed));
   printf("%s", (" passed"));
   printf("%s", ("\n")) ;
      }
      else
      {
   printf("%s", ("no test performed\n"));
      }
  }
     }
 }
    }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 0;
v5[0] = 0;
mu_run_test_suite(
(void (__fastcall *)(_QWORD *))sampleTest_setup,
(void (__fastcall *)(_QWORD *))sampleTest_tear_down,
&sampleTest_tests_array,
&v4,
v5);
mu_report_test_suite_report("sampleTest", &sampleTest_tests_array, v4, v5[0]);
v4 = 0;
v5[0] = 0;
mu_run_test_suite(
(void (__fastcall *)(_QWORD *))test_half_setup,
(void (__fastcall *)(_QWORD *))test_half_tear_down,
&test_half_tests_array,
&v4,
v5);
mu_report_test_suite_report("test_half", &test_half_tests_array, v4, v5[0]);
v4 = 0;
v5[0] = 0;
mu_run_test_suite(
(void (__fastcall *)(_QWORD *))test_assertions_setup,
(void (__fastcall *)(_QWORD *))test_assertions_tear_down,
&test_assertions_tests_array,
&v4,
v5);
mu_report_test_suite_report("test_assertions", &test_assertions_tests_array, v4, v5[0]);
puts("The next suite will fail on purpose");
v4 = 0;
v5[0] = 0;
mu_run_test_suite(
(void (__fastcall *)(_QWORD *))half_success_setup,
(void (__fastcall *)(_QWORD *))half_success_tear_down,
&half_success_tests_array,
&v4,
v5);
mu_report_test_suite_report("half_success", &half_success_tests_array, v4, v5[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = 0;
v5[0] = 0;
func7(
(void (__fastcall *)(_QWORD *))sampleTest_setup,
(void (__fastcall *)(_QWORD *))sampleTest_tear_down,
&sampleTest_tests_array,
&v4,
v5);
func26("sampleTest", &sampleTest_tests_array, v4, v5[0]);
v4 = 0;
v5[0] = 0;
func7(
(void (__fastcall *)(_QWORD *))test_half_setup,
(void (__fastcall *)(_QWORD *))test_half_tear_down,
&test_half_tests_array,
&v4,
v5);
func26("test_half", &test_half_tests_array, v4, v5[0]);
v4 = 0;
v5[0] = 0;
func7(
(void (__fastcall *)(_QWORD *))test_assertions_setup,
(void (__fastcall *)(_QWORD *))test_assertions_tear_down,
&test_assertions_tests_array,
&v4,
v5);
func26("test_assertions", &test_assertions_tests_array, v4, v5[0]);
puts("The next suite will fail on purpose");
v4 = 0;
v5[0] = 0;
func7(
(void (__fastcall *)(_QWORD *))half_success_setup,
(void (__fastcall *)(_QWORD *))half_success_tear_down,
&half_success_tests_array,
&v4,
v5);
func26("half_success", &half_success_tests_array, v4, v5[0]);
return 0;
}

original_code:
int main(void)
{
    do { int success = 0; int total = 0; mu_run_test_suite(sampleTest_setup, sampleTest_tear_down, sampleTest_tests_array, (&success), (&total)); mu_report_test_suite_report("sampleTest", sampleTest_tests_array, success, total); } while(0);
    do { int success = 0; int total = 0; mu_run_test_suite(test_half_setup, test_half_tear_down, test_half_tests_array, (&success), (&total)); mu_report_test_suite_report("test_half", test_half_tests_array, success, total); } while(0);
    do { int success = 0; int total = 0; mu_run_test_suite(test_assertions_setup, test_assertions_tear_down, test_assertions_tests_array, (&success), (&total)); mu_report_test_suite_report("test_assertions", test_assertions_tests_array, success, total); } while(0);
    printf("%s", ("The next suite will fail on purpose\n"));
    do { int success = 0; int total = 0; mu_run_test_suite(half_success_setup, half_success_tear_down, half_success_tests_array, (&success), (&total)); mu_report_test_suite_report("half_success", half_success_tests_array, success, total); } while(0);
    return 0;
}

canonical_original_code:
int main()
{
    do { int success = 0; int total = 0; mu_run_test_suite(sampleTest_setup, sampleTest_tear_down, sampleTest_tests_array, (&success), (&total)); mu_report_test_suite_report("sampleTest", sampleTest_tests_array, success, total); } while(0);
    do { int success = 0; int total = 0; mu_run_test_suite(test_half_setup, test_half_tear_down, test_half_tests_array, (&success), (&total)); mu_report_test_suite_report("test_half", test_half_tests_array, success, total); } while(0);
    do { int success = 0; int total = 0; mu_run_test_suite(test_assertions_setup, test_assertions_tear_down, test_assertions_tests_array, (&success), (&total)); mu_report_test_suite_report("test_assertions", test_assertions_tests_array, success, total); } while(0);
    printf("%s", ("The next suite will fail on purpose\n"));
    do { int success = 0; int total = 0; mu_run_test_suite(half_success_setup, half_success_tear_down, half_success_tests_array, (&success), (&total)); mu_report_test_suite_report("half_success", half_success_tests_array, success, total); } while(0);
    return 0;
}


repo: hazybluedot/fdtrace

decompiled_code:
__int64 __fastcall pid2pib_helper(int a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
return 0LL;
while ( 1 )
{
if ( f_debug > 1 )
fprintf(stderr, "checking if %jd == %jd\n", *(int *)(v2 + 16), a1);
if ( *(_DWORD *)(v2 + 16) == a1 )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
return 0LL;
while ( 1 )
{
if ( f_debug > 1 )
fprintf(stderr, "checking if %jd == %jd\n", *(int *)(v2 + 16), a1);
if ( *(_DWORD *)(v2 + 16) == a1 )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return v2;
}

original_code:
static struct pib*
pid2pib_helper(pid_t pid, struct pib *start) {
    struct pib *cur = start;
    while(cur != ((void *)0)) {
        if (f_debug > 1)
            fprintf(stderr, "checking if %jd == %jd\n", (intmax_t)cur->pid, (intmax_t)pid);
        if (cur->pid == pid)
            return cur;
        cur = cur->next;
    }
    return ((void *)0);
}

canonical_original_code:
static struct pib *pid2pib_helper(int pid, struct pib *start) {
    struct pib *cur = start;
    while(cur != ((void *)0)) {
        if (f_debug > 1)
            fprintf(stderr, "checking if %jd == %jd\n", (long)cur->pid, (long)pid);
        if (cur->pid == pid)
            return cur;
        cur = cur->next;
    }
    return ((void *)0);
}

variable_types: pid int

variable_types:
start
struct pib *

variable_types: struct pib { int flags; struct pib *next; int pid; long syscall; long long params[3]; long rval; struct pib *children; } *


decompiled_code:
__int64 __fastcall pid2pib(int a1)
{
if ( f_debug )
{
fprintf(stderr, "searching for %jd in pid list\n", a1);
fprintf(stderr, "head (%p) ->pid is %jd\n", (const void *)head, *(int *)(head + 16));
}
return pid2pib_helper(a1, head);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
if ( f_debug )
{
fprintf(stderr, "searching for %jd in pid list\n", a1);
fprintf(stderr, "head (%p) ->pid is %jd\n", (const void *)head, *(int *)(head + 16));
}
return func7(a1, head);
}

original_code:
static struct pib*
pid2pib(pid_t pid) {
    if (f_debug) {
        fprintf(stderr, "searching for %jd in pid list\n", (intmax_t)pid);
        fprintf(stderr, "head (%p) ->pid is %jd\n", head, (intmax_t)head->pid);
    }
    return pid2pib_helper(pid, head);
}

canonical_original_code:
static struct pib *pid2pib(int pid) {
    if (f_debug) {
        fprintf(stderr, "searching for %jd in pid list\n", (long)pid);
        fprintf(stderr, "head (%p) ->pid is %jd\n", head, (long)head->pid);
    }
    return pid2pib_helper(pid, head);
}

return_type: struct pib { int flags; struct pib *next; int pid; long syscall; long long params[3]; long rval; struct pib *children; } *


usage

decompiled_code:
size_t usage()
{
return fwrite("Usage: fdtrace COMMAND\n", 1uLL, 0x17uLL, stderr);
}

canonical_decompiled_code:
size_t func9()
{
return fwrite("Usage: fdtrace COMMAND\n", 1uLL, 0x17uLL, stderr);
}

original_code:
void usage() {
    fputs("Usage: fdtrace COMMAND\n", stderr);
}


decompiled_code:
__int64 __fastcall get_params(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 32) = ptrace(PTRACE_PEEKUSER, v1, 40LL, 0LL);
*(_QWORD *)(a1 + 40) = ptrace(PTRACE_PEEKUSER, v1, 88LL, 0LL);
result = ptrace(PTRACE_PEEKUSER, v1, 96LL, 0LL);
*(_QWORD *)(a1 + 48) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 32) = ptrace(PTRACE_PEEKUSER, v1, 40LL, 0LL);
*(_QWORD *)(a1 + 40) = ptrace(PTRACE_PEEKUSER, v1, 88LL, 0LL);
result = ptrace(PTRACE_PEEKUSER, v1, 96LL, 0LL);
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
void get_params(struct pib *pip) {
    pid_t pid = pip->pid;
    pip->params[0] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 5, ((void *)0));
    pip->params[1] = ptrace(PTRACE_PEEKUSER,
                            pid, 8 * 11, ((void *)0));
    pip->params[2] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 12, ((void *)0));
}

canonical_original_code:
void get_params(struct pib *pip) {
    int pid = pip->pid;
    pip->params[0] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 5, ((void *)0));
    pip->params[1] = ptrace(PTRACE_PEEKUSER,
                            pid, 8 * 11, ((void *)0));
    pip->params[2] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 12, ((void *)0));
}

user_defined_types: struct pib { int flags; struct pib *next; int pid; long syscall; long long params[3]; long rval; struct pib *children; }


decompiled_code:
int __fastcall print_syscall(_QWORD *a1)
{
__int64 v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = a1[3];
if ( v1 == 2 )
{
strcpy(v3, "open");
goto LABEL_6;
}
if ( v1 <= 2 && v1 == 1 )
{
strcpy(v3, "write");
LABEL_6:
LODWORD(v1) = fprintf(stderr, "%s(%lld, %lld, %lld)\n", v3, a1[4], a1[5], a1[6]);
}
return v1;
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1)
{
__int64 v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = a1[3];
if ( v1 == 2 )
{
strcpy(v3, "open");
goto LABEL_6;
}
if ( v1 <= 2 && v1 == 1 )
{
strcpy(v3, "write");
LABEL_6:
LODWORD(v1) = fprintf(stderr, "%s(%lld, %lld, %lld)\n", v3, a1[4], a1[5], a1[6]);
}
return v1;
}

original_code:
void print_syscall(struct pib *pip) {
    char name[255];
    int argc;
    switch(pip->syscall) {
    case(2):
        strcpy(name, "open"); argc=3;
        break;
    case(3):
        strcpy(name, "close"); argc=1;
        break;
    case(32):
        strcpy(name, "dup"); argc=1;
        break;
    case(33):
        strcpy(name, "dup2"); argc=2;
        break;
    case(72):
        strcpy(name, "fnctl"); argc=-1;
        break;
    case(1):
        strcpy(name, "write"); argc=3;
        break;
    }
    switch(argc) {
    case(3):
        fprintf(stderr, "%s(%lld, %lld, %lld)\n", name, pip->params[0], pip->params[1], pip->params[2]);
        break;
    }
}

variable_types:
name
char [255]

variable_types: argc int


decompiled_code:
void exit_syscall()
{
;
}

original_code:
void exit_syscall(struct pib *pip) {
}

canonical_original_code:
void exit_syscall(struct pib *pip) {
}


decompiled_code:
int __fastcall enter_syscall(__int64 a1)
{
__int64 v1; // rax

v1 = *(_QWORD *)(a1 + 24);
if ( v1 > 3 )
{
if ( v1 > 33 )
{
if ( v1 != 72 )
return v1;
}
else if ( v1 <= 31 )
{
return v1;
}
goto LABEL_11;
}
if ( v1 > 1 )
{
LABEL_11:
*(_DWORD *)a1 |= 0x200u;
return v1;
}
if ( v1 == 1 )
{
if ( (*(_DWORD *)a1 & 0x200) != 0 )
{
list_fd(*(unsigned int *)(a1 + 16));
*(_DWORD *)a1 &= 0xFFFFFDFF;
}
get_params(a1);
LODWORD(v1) = print_syscall((_QWORD *)a1);
}
return v1;
}

original_code:
void enter_syscall(struct pib *pip) {
    switch(pip->syscall) {
    case(2):
    case(3):
    case(32):
    case(33):
    case(72):
        pip->flags |= 01000;
        break;
    case(0):
        break;
    case(1):
        if (pip->flags & 01000) {
            list_fd(pip->pid);
            pip->flags &= ~01000;
        }
        get_params(pip);
        print_syscall(pip);
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
__pid_t v4; // eax
unsigned int v5; // er12
int *v6; // rax
int v8; // ebp
__int64 v9; // rbx
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
usage();
exit(1);
}
for ( i = 3; i != 9; ++i )
close(i);
v4 = fork();
v5 = v4;
if ( v4 < 0 )
{
perror("fork");
}
else if ( v4 )
{
if ( f_debug )
fprintf(stderr, "setting pid %jd as head\n", v4);
v6 = (int *)alloc_pib(v5);
head = (__int64)v6;
if ( f_debug )
fprintf(stderr, "head (%p) ->pid is %jd\n", v6, v6[4]);
while ( 1 )
{
while ( 1 )
{
v8 = wait((__WAIT_STATUS)&stat_loc);
v9 = pid2pib(v8);
if ( v9 )
break;
fprintf(stderr, "Untracked pid: %jd\n", v8);
}
if ( ((__int64)stat_loc.__uptr & 0x7F) == 0 )
break;
*(_QWORD *)(v9 + 24) = ptrace(PTRACE_PEEKUSER, v5, 120LL, 0LL);
if ( (*(_DWORD *)v9 & 8) != 0 )
{
*(_DWORD *)v9 &= 0xFFFFFFF7;
}
else
{
enter_syscall(v9);
*(_DWORD *)v9 |= 8u;
}
ptrace(PTRACE_SYSCALL, v5, 0LL, 0LL);
}
}
else
{
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
if ( execvp(argv[1], (char *const *)argv + 1) == -1 )
{
perror("execv");
exit(1);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
__pid_t v4; // eax
unsigned int v5; // er12
int *v6; // rax
int v8; // ebp
__int64 v9; // rbx
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
func9();
exit(1);
}
for ( i = 3; i != 9; ++i )
close(i);
v4 = fork();
v5 = v4;
if ( v4 < 0 )
{
perror("fork");
}
else if ( v4 )
{
if ( f_debug )
fprintf(stderr, "setting pid %jd as head\n", v4);
v6 = (int *)alloc_pib(v5);
head = (__int64)v6;
if ( f_debug )
fprintf(stderr, "head (%p) ->pid is %jd\n", v6, v6[4]);
while ( 1 )
{
while ( 1 )
{
v8 = wait((__WAIT_STATUS)&stat_loc);
v9 = func8(v8);
if ( v9 )
break;
fprintf(stderr, "Untracked pid: %jd\n", v8);
}
if ( ((__int64)stat_loc.__uptr & 0x7F) == 0 )
break;
*(_QWORD *)(v9 + 24) = ptrace(PTRACE_PEEKUSER, v5, 120LL, 0LL);
if ( (*(_DWORD *)v9 & 8) != 0 )
{
*(_DWORD *)v9 &= 0xFFFFFFF7;
}
else
{
func13(v9);
*(_DWORD *)v9 |= 8u;
}
ptrace(PTRACE_SYSCALL, v5, 0LL, 0LL);
}
}
else
{
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
if ( execvp(argv[1], (char *const *)argv + 1) == -1 )
{
perror("execv");
exit(1);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    pid_t pid;
    int status;
    if (argc < 2) {
        usage();
        exit(1);
    }
    for(unsigned int i=3; i<9; i++)
        close(i);
    if ((pid = fork()) < 0) {
        perror("fork");
    } else if (pid == 0) {
        ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
        if (-1 == execvp(argv[1], &argv[1]) ) {
            perror("execv");
            exit(1);
        }
    } else {
        if (f_debug)
            fprintf(stderr, "setting pid %jd as head\n", (intmax_t)pid);
        head = alloc_pib(pid);
        if (f_debug)
            fprintf(stderr, "head (%p) ->pid is %jd\n", head, (intmax_t)head->pid);
        while(1) {
            pid_t ppid = wait(&status);
            struct pib *pip = pid2pib(ppid);
            if (!pip) {
                fprintf(stderr, "Untracked pid: %jd\n", (intmax_t)ppid);
            } else {
                if((((status) & 0x7f) == 0))
                    break;
                pip->syscall = ptrace(PTRACE_PEEKUSER,
                                      pid, 8 * 15, ((void *)0));
                if (pip->flags & 00010) {
                    exit_syscall(pip);
                    pip->flags &= ~00010;
                } else {
                    enter_syscall(pip);
                    pip->flags |= 00010;
                }
                ptrace(PTRACE_SYSCALL,
                       pid, ((void *)0), ((void *)0));
            }
        }
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int pid;
    int status;
    if (argc < 2) {
        usage();
        exit(1);
    }
    for(unsigned int i = 3; i<9; i++)
        close(i);
    if ((pid = fork()) < 0) {
        perror("fork");
    } else if (pid == 0) {
        ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
        if (-1 == execvp(argv[1], &argv[1]) ) {
            perror("execv");
            exit(1);
        }
    } else {
        if (f_debug)
            fprintf(stderr, "setting pid %jd as head\n", (long)pid);
        head = alloc_pib(pid);
        if (f_debug)
            fprintf(stderr, "head (%p) ->pid is %jd\n", head, (long)head->pid);
        while(1) {
            int ppid = wait(&status);
            struct pib *pip = pid2pib(ppid);
            if (!pip) {
                fprintf(stderr, "Untracked pid: %jd\n", (long)ppid);
            } else {
                if((((status) & 0x7f) == 0))
                    break;
                pip->syscall = ptrace(PTRACE_PEEKUSER,
                                      pid, 8 * 15, ((void *)0));
                if (pip->flags & 00010) {
                    exit_syscall(pip);
                    pip->flags &= ~00010;
                } else {
                    enter_syscall(pip);
                    pip->flags |= 00010;
                }
                ptrace(PTRACE_SYSCALL,
                       pid, ((void *)0), ((void *)0));
            }
        }
    }
}

variable_types:
argv
char *[]

variable_types: status int

variable_types:
i
unsigned int

variable_types: ppid int


decompiled_code:
void __fastcall set_link_type(int a1)
{
const char *v1; // rax

if ( a1 == 12 )
{
LODWORD(link_hdr_len) = 0;
}
else
{
if ( a1 > 12 )
{
if ( a1 != 108 )
{
LABEL_7:
LODWORD(link_hdr_len) = 0;
v1 = (const char *)pcap_datalink_val_to_name();
fprintf(stderr, "Warning: Link type %s not recognized.\n", v1);
return;
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
LODWORD(link_hdr_len) = 14;
return;
}
goto LABEL_7;
}
LODWORD(link_hdr_len) = 4;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
const char *v1; // rax

if ( a1 == 12 )
{
LODWORD(link_hdr_len) = 0;
}
else
{
if ( a1 > 12 )
{
if ( a1 != 108 )
{
LABEL_7:
LODWORD(link_hdr_len) = 0;
v1 = (const char *)pcap_datalink_val_to_name();
fprintf(stderr, "Warning: Link type %s not recognized.\n", v1);
return;
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
LODWORD(link_hdr_len) = 14;
return;
}
goto LABEL_7;
}
LODWORD(link_hdr_len) = 4;
}
}

original_code:
void set_link_type(const int dlt)
{
    switch (dlt) {
    case 1:
        link_hdr_len = 14;
        break;
    case 0:
    case 108:
        link_hdr_len = 4;
        break;
    case 12:
        link_hdr_len = 0;
        break;
    default:
        link_hdr_len = 0;
        fprintf(stderr, "Warning: Link type %s not recognized.\n", pcap_datalink_val_to_name(dlt));
    }
}

canonical_original_code:
void set_link_type(int dlt)
{
    switch (dlt) {
    case 1:
        link_hdr_len = 14;
        break;
    case 0:
    case 108:
        link_hdr_len = 4;
        break;
    case 12:
        link_hdr_len = 0;
        break;
    default:
        link_hdr_len = 0;
        fprintf(stderr, "Warning: Link type %s not recognized.\n", pcap_datalink_val_to_name(dlt));
    }
}

variable_types: dlt int


decompiled_code:
__int64 get_link_hdr_len()
{
return (unsigned int)link_hdr_len;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)link_hdr_len;
}

original_code:
u_int get_link_hdr_len()
{
    return link_hdr_len;
}

canonical_original_code:
unsigned int get_link_hdr_len()
{
    return link_hdr_len;
}

return_type: unsigned int


isBigEndian

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

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

original_code:
int isBigEndian()
{
   long int i = 1;
   const char *p = (const char *) &i;
   if (p[0] == 1)
      return 0;
   else
      return 1;
}

canonical_original_code:
int isBigEndian()
{
   long i = 1;
   char *p = (const char *) &i;
   if (p[0] == 1)
      return 0;
   else
      return 1;
}

variable_types: i long

variable_types:
p
char *


decompiled_code:
__int64 __fastcall unpack_packet(void *src, void *dest)
{
char *v2; // rbx
__int16 v3; // ax
__int64 result; // rax

memcpy(dest, src, (unsigned int)link_hdr_len);
v2 = (char *)src + (unsigned int)link_hdr_len;
*((_BYTE *)dest + 14) = (unsigned __int8)*v2 >> 4;
*((_BYTE *)dest + 15) = *v2 & 0xF;
*((_BYTE *)dest + 16) = v2[1];
*((_WORD *)dest + 9) = *((_WORD *)v2 + 1);
*((_WORD *)dest + 10) = *((_WORD *)v2 + 2);
if ( (unsigned int)isBigEndian() )
{
*((_BYTE *)dest + 22) = (unsigned __int8)v2[6] >> 5;
v3 = *((_WORD *)v2 + 3) & 0x1FFF;
}
else
{
*((_BYTE *)dest + 22) = v2[6] & 7;
v3 = *((_WORD *)v2 + 3);
HIBYTE(v3) &= 0xF8u;
}
*((_WORD *)dest + 12) = v3;
*(_QWORD *)((char *)dest + 26) = *((_QWORD *)v2 + 1);
result = *((unsigned int *)v2 + 4);
*(_DWORD *)((char *)dest + 34) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, void *dest)
{
char *v2; // rbx
__int16 v3; // ax
__int64 result; // rax

memcpy(dest, src, (unsigned int)link_hdr_len);
v2 = (char *)src + (unsigned int)link_hdr_len;
*((_BYTE *)dest + 14) = (unsigned __int8)*v2 >> 4;
*((_BYTE *)dest + 15) = *v2 & 0xF;
*((_BYTE *)dest + 16) = v2[1];
*((_WORD *)dest + 9) = *((_WORD *)v2 + 1);
*((_WORD *)dest + 10) = *((_WORD *)v2 + 2);
if ( (unsigned int)func2() )
{
*((_BYTE *)dest + 22) = (unsigned __int8)v2[6] >> 5;
v3 = *((_WORD *)v2 + 3) & 0x1FFF;
}
else
{
*((_BYTE *)dest + 22) = v2[6] & 7;
v3 = *((_WORD *)v2 + 3);
HIBYTE(v3) &= 0xF8u;
}
*((_WORD *)dest + 12) = v3;
*(_QWORD *)((char *)dest + 26) = *((_QWORD *)v2 + 1);
result = *((unsigned int *)v2 + 4);
*(_DWORD *)((char *)dest + 34) = result;
return result;
}

original_code:
void unpack_packet(const u_char* origPacket, struct packet_struct* parsedPacket,
                   size_t capturedSize)
{
    u_char icmpIpHdrOct=0;
    u_char icmpIpHdrProto=0;
    u_char icmpTcpHdrOct=0;
    memcpy((void*)(&(parsedPacket->dstMacAddr[0])), (const void*)origPacket, (size_t)link_hdr_len);
    const u_char* origIpPacket = origPacket+link_hdr_len;
    parsedPacket->ipVer = origIpPacket[0]>>4;
    parsedPacket->ipHdrLen = origIpPacket[0]&0x0f;
    parsedPacket->tos = origIpPacket[1];
    parsedPacket->packetLen = *((u_int16_t*)(origIpPacket+2));
    parsedPacket->id = *((u_int16_t*)(origIpPacket+4));
    if (isBigEndian()) {
        parsedPacket->flags = origIpPacket[6]>>5;
        parsedPacket->fragOffset = (*((u_int16_t*)(origIpPacket+6)))&0x1fff;
    } else {
        parsedPacket->flags = origIpPacket[6]&0x07;
        parsedPacket->fragOffset = (*((u_int16_t*)(origIpPacket+6)))&0xf8ff;
    }
    memcpy(&(parsedPacket->ttl), origIpPacket+8, 12);
}

canonical_original_code:
void unpack_packet(unsigned char *origPacket, struct packet_struct *parsedPacket, unsigned long capturedSize)
{
    unsigned char icmpIpHdrOct = 0;
    unsigned char icmpIpHdrProto = 0;
    unsigned char icmpTcpHdrOct = 0;
    memcpy((void *)(&(parsedPacket->dstMacAddr[0])), (void *)origPacket, (unsigned long)link_hdr_len);
    unsigned char *origIpPacket = origPacket+link_hdr_len;
    parsedPacket->ipVer = origIpPacket[0]>>4;
    parsedPacket->ipHdrLen = origIpPacket[0]&0x0f;
    parsedPacket->tos = origIpPacket[1];
    parsedPacket->packetLen = *((unsigned int *)(origIpPacket+2));
    parsedPacket->id = *((unsigned int *)(origIpPacket+4));
    if (isBigEndian()) {
        parsedPacket->flags = origIpPacket[6]>>5;
        parsedPacket->fragOffset = (*((unsigned int *)(origIpPacket+6)))&0x1fff;
    } else {
        parsedPacket->flags = origIpPacket[6]&0x07;
        parsedPacket->fragOffset = (*((unsigned int *)(origIpPacket+6)))&0xf8ff;
    }
    memcpy(&(parsedPacket->ttl), origIpPacket+8, 12);
}

variable_types:
origPacket
unsigned char *

variable_types: struct packet_struct { unsigned char dstMacAddr[6]; unsigned char srcMacAddr[6]; unsigned char etherProto[2]; unsigned char ipVer; unsigned char ipHdrLen; unsigned char tos; unsigned int packetLen; unsigned int id; unsigned char flags; unsigned int fragOffset; unsigned char ttl; unsigned char protocol; unsigned int hdrXsum; unsigned char srcIpQ1; unsigned char srcIpQ2; unsigned char srcIpQ3; unsigned char srcIpQ4; unsigned char dstIpQ1; unsigned char dstIpQ2; unsigned char dstIpQ3; unsigned char dstIpQ4; } *

variable_types:
capturedSize
unsigned long

variable_types:
icmpIpHdrOct
unsigned char

variable_types:
icmpIpHdrProto
unsigned char

variable_types:
icmpTcpHdrOct
unsigned char

variable_types:
origIpPacket
unsigned char *


initlist

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

result = malloc(0x18uLL);
head = (__int64)result;
*result = 0LL;
result[2] = result;
result[1] = result;
return result;
}

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

result = malloc(0x18uLL);
head = (__int64)result;
*result = 0LL;
result[2] = result;
result[1] = result;
return result;
}

original_code:
Dlinklist initlist()
{
 head = ((void *)0);
head = malloc(sizeof(Dlnode));
 head->data = ((void *)0);
 head->next = head;
 head->prior = head;
 return head;
}

canonical_original_code:
struct dlnode *initlist()
{
 head = ((void *)0);
head = malloc(sizeof(Dlnode));
 head->data = ((void *)0);
 head->next = head;
 head->prior = head;
 return head;
}

return_type: struct dlnode { void *data; struct dlnode *prior; } *


dinsertbefore

decompiled_code:
__int64 __fastcall dinsertbefore(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

if ( !a1 )
return 3LL;
v2 = dmakenode(a2);
if ( !v2 )
return 2LL;
v2[2] = a1;
v3 = *(_QWORD *)(a1 + 8);
v2[1] = v3;
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

original_code:
ret dinsertbefore(Dlinklist p, void *e)
{
 if(p!=((void *)0))
 {
  Dlinklist s;
  s = dmakenode(e);
  if(((void *)0) == s)
  return(ERROR);
  s->next = p;
  s->prior = p->prior;
  p->prior->next = s;
  p->prior = s;
  return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertbefore(struct dlnode *p, void *e)
{
 if(p!=((void *)0))
 {
  struct dlnode *s;
  s = dmakenode(e);
  if(((void *)0) == s)
  return(ERROR);
  s->next = p;
  s->prior = p->prior;
  p->prior->next = s;
  p->prior = s;
  return OK;
 }
 else return NO;
}

variable_types: struct dlnode { void *data; struct dlnode *prior; } *

variable_types:
e
void *

return_type: enum Ret { OK=1, ERROR=2, NO=3 }


dinsertbeforen

original_code:
ret dinsertbeforen(Dlinklist p, void *e, int index)
{
 if(p!=((void *)0))
 {
   Dlinklist s;
   int i;
   s = dmakenode(e);
   if(((void *)0) == s)
   return(ERROR);
   Dlinklist head = p;
   Dlinklist fhead = head;
   for(i=0;i<index;i++)
   {
    fhead = fhead->next;
   }
   s->next = fhead;
   s->prior = fhead->prior;
   fhead->prior->next = s;
   fhead->prior = s;
   return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertbeforen(struct dlnode *p, void *e, int index)
{
 if(p!=((void *)0))
 {
   struct dlnode *s;
   int i;
   s = dmakenode(e);
   if(((void *)0) == s)
   return(ERROR);
   struct dlnode *head = p;
   struct dlnode *fhead = head;
   for(i=0;i<index;i++)
   {
    fhead = fhead->next;
   }
   s->next = fhead;
   s->prior = fhead->prior;
   fhead->prior->next = s;
   fhead->prior = s;
   return OK;
 }
 else return NO;
}

variable_types: index int

variable_types: i int

user_defined_types: struct dlnode { void *data; struct dlnode *prior; }


dinsertafter

decompiled_code:
__int64 __fastcall dinsertafter(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

if ( !a1 )
return 3LL;
v2 = dmakenode(a2);
if ( !v2 )
return 2LL;
v2[2] = *(_QWORD *)(a1 + 16);
v2[1] = a1;
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) = v2;
*(_QWORD *)(a1 + 16) = v2;
return 1LL;
}

original_code:
ret dinsertafter(Dlinklist p, void *e)
{
   if(p!=((void *)0))
 {
  Dlinklist s;
  s = dmakenode(e);
  if(s == ((void *)0))
  return(ERROR);
  s->next = p->next;
  s->prior = p;
  p->next->prior = s;
  p->next = s;
  return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertafter(struct dlnode *p, void *e)
{
   if(p!=((void *)0))
 {
  struct dlnode *s;
  s = dmakenode(e);
  if(s == ((void *)0))
  return(ERROR);
  s->next = p->next;
  s->prior = p;
  p->next->prior = s;
  p->next = s;
  return OK;
 }
 else return NO;
}


ddeletenode

decompiled_code:
__int64 __fastcall ddeletenode(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 *v3; // rbx
__int64 *v4; // rax
__int64 v5; // rdx

result = 3LL;
if ( a1 )
{
v3 = (__int64 *)dgethead(a1)[2];
if ( *v3 )
{
do
{
v4 = dlocateitem(v3, a2);
if ( v4 )
{
v5 = v4[2];
*(_QWORD *)(v4[1] + 16) = v5;
*(_QWORD *)(v5 + 8) = v4[1];
}
v3 = (__int64 *)v3[2];
}
while ( *v3 );
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
ret ddeletenode(Dlinklist p, void *e)
{
 if(p!=((void *)0))
 {
  Dlinklist head = dgethead(p);
  Dlinklist temp;
  Dlinklist tempp;
  for(temp=head->next;temp->data != ((void *)0);temp = temp->next)
  {
   tempp = dlocateitem(temp,e);
   if(tempp != ((void *)0))
   {
    tempp->prior->next = tempp->next;
    tempp->next->prior = tempp->prior;
   }
  }
 return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret ddeletenode(struct dlnode *p, void *e)
{
 if(p!=((void *)0))
 {
  struct dlnode *head = dgethead(p);
  struct dlnode *temp;
  struct dlnode *tempp;
  for(temp=head->next;temp->data != ((void *)0);temp = temp->next)
  {
   tempp = dlocateitem(temp,e);
   if(tempp != ((void *)0))
   {
    tempp->prior->next = tempp->next;
    tempp->next->prior = tempp->prior;
   }
  }
 return OK;
 }
 else return NO;
}


setitem

decompiled_code:
__int64 __fastcall setitem(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 *v5; // rax

result = 3LL;
if ( a1 )
{
v5 = dlocateitem(a1, a2);
if ( v5 )
*v5 = a3;
else
printf("can not find the node ");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 *v5; // rax

result = 3LL;
if ( a1 )
{
v5 = dlocateitem(a1, a2);
if ( v5 )
*v5 = a3;
else
printf("can not find the node ");
result = 1LL;
}
return result;
}

original_code:
ret setitem(Dlinklist p,void *e, void *edest)
{
 if(p)
 {
  Dlinklist retp = dlocateitem(p,e);
  if(retp == ((void *)0))
  {
   printf("can not find the node ");
  }
  else{
   retp->data = edest;
  }
 return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret setitem(struct dlnode *p, void *e, void *edest)
{
 if(p)
 {
  struct dlnode *retp = dlocateitem(p,e);
  if(retp == ((void *)0))
  {
   printf("can not find the node ");
  }
  else{
   retp->data = edest;
  }
 return OK;
 }
 else return NO;
}

variable_types:
edest
void *


dlistlength

decompiled_code:
__int64 __fastcall dlistlength(__int64 a1)
{
unsigned int v1; // edx
_QWORD *v2; // rax

v1 = 0;
if ( a1 )
{
v2 = *(_QWORD **)(a1 + 16);
if ( *v2 )
{
v1 = 1;
do
{
v2 = (_QWORD *)v2[2];
++v1;
}
while ( *v2 );
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
int dlistlength(Dlinklist p)
{
 if(p!=((void *)0))
 {
  int i=1;
  Dlinklist ptmp = p->next;
  while(ptmp->data !=((void *)0))
  {
   ptmp = ptmp->next;
   i++;
  }
  return(i);
 }
 else return(0);
}

canonical_original_code:
int dlistlength(struct dlnode *p)
{
 if(p!=((void *)0))
 {
  int i = 1;
  struct dlnode *ptmp = p->next;
  while(ptmp->data !=((void *)0))
  {
   ptmp = ptmp->next;
   i++;
  }
  return(i);
 }
 else return(0);
}


dinsertaftern

decompiled_code:
__int64 __fastcall dinsertaftern(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
int v5; // edx
__int64 result; // rax
_QWORD *v7; // rdx
int v8; // eax

if ( !a1 )
return 3LL;
v3 = a1;
v5 = dlistlength(a1);
result = 3LL;
if ( v5 >= a3 )
{
v7 = dmakenode(a2);
if ( v7 )
{
if ( a3 > 0 )
{
v8 = 0;
do
{
v3 = *(_QWORD *)(v3 + 16);
++v8;
}
while ( a3 != v8 );
}
v7[2] = *(_QWORD *)(v3 + 16);
v7[1] = v3;
*(_QWORD *)(*(_QWORD *)(v3 + 16) + 8LL) = v7;
*(_QWORD *)(v3 + 16) = v7;
result = 1LL;
}
else
{
result = 2LL;
}
}
return result;
}

original_code:
ret dinsertaftern(Dlinklist p, void *e,int index)
{ if(p!=((void *)0))
 {
  int j=dlistlength(p);
  if(j+1 > index)
  {
   Dlinklist s;
   Dlinklist tmpp=p;
   int i;
   s = dmakenode(e);
   if(s == ((void *)0))
   return(ERROR);
   for(i=0;i<index;i++)
   {
    tmpp=tmpp->next;
   }
   s->next = tmpp->next;
   s->prior = tmpp;
   tmpp->next->prior = s;
   tmpp->next = s;
   return OK;
  }
  else return NO;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertaftern(struct dlnode *p, void *e, int index)
{ if(p!=((void *)0))
 {
  int j = dlistlength(p);
  if(j+1 > index)
  {
   struct dlnode *s;
   struct dlnode *tmpp = p;
   int i;
   s = dmakenode(e);
   if(s == ((void *)0))
   return(ERROR);
   for(i=0;i<index;i++)
   {
    tmpp=tmpp->next;
   }
   s->next = tmpp->next;
   s->prior = tmpp;
   tmpp->next->prior = s;
   tmpp->next = s;
   return OK;
  }
  else return NO;
 }
 else return NO;
}

variable_types: j int


ddeletenoden

decompiled_code:
__int64 __fastcall ddeletenoden(void *ptr, int a2)
{
_QWORD *v2; // rbx
int v3; // edx
__int64 result; // rax
int i; // eax
__int64 v6; // rax

if ( !ptr )
return 3LL;
v2 = ptr;
v3 = dlistlength((__int64)ptr);
result = 3LL;
if ( v3 >= a2 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v2 = (_QWORD *)v2[2];
}
v6 = v2[1];
*(_QWORD *)(v2[2] + 8LL) = v6;
*(_QWORD *)(v6 + 16) = v2[2];
free(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr, int a2)
{
_QWORD *v2; // rbx
int v3; // edx
__int64 result; // rax
int i; // eax
__int64 v6; // rax

if ( !ptr )
return 3LL;
v2 = ptr;
v3 = func6((__int64)ptr);
result = 3LL;
if ( v3 >= a2 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
v2 = (_QWORD *)v2[2];
}
v6 = v2[1];
*(_QWORD *)(v2[2] + 8LL) = v6;
*(_QWORD *)(v6 + 16) = v2[2];
free(v2);
result = 1LL;
}
return result;
}

original_code:
ret ddeletenoden(Dlinklist p,int index)
{
 if(p !=((void *)0)){
  int j=dlistlength(p);
  if(j<index)
  return NO;
  else
  {
   Dlinklist tmpp = p;
   int i;
   for(i=0;i<index;i++)
   {
    tmpp = tmpp->next;
   }
   tmpp->next->prior = tmpp->prior;
   tmpp->prior->next = tmpp->next;
   free(tmpp);
   return OK;
  }
  return NO;
 }
 else return NO;
}

canonical_original_code:
enum Ret ddeletenoden(struct dlnode *p, int index)
{
 if(p !=((void *)0)){
  int j = dlistlength(p);
  if(j<index)
  return NO;
  else
  {
   struct dlnode *tmpp = p;
   int i;
   for(i=0;i<index;i++)
   {
    tmpp = tmpp->next;
   }
   tmpp->next->prior = tmpp->prior;
   tmpp->prior->next = tmpp->next;
   free(tmpp);
   return OK;
  }
  return NO;
 }
 else return NO;
}


dscan

decompiled_code:
__int64 __fastcall dscan(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
if ( !a1 )
return 0LL;
if ( (int)dlistlength((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
}
else
{
while ( (_QWORD *)a1[2] != a1 )
a2(*a1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
if ( !a1 )
return 0LL;
if ( (int)func6((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
}
else
{
while ( (_QWORD *)a1[2] != a1 )
a2(*a1);
}
return 0LL;
}

original_code:
Dlinklist dscan(Dlinklist p, VisitFunc visit)
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i=0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->next !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}

canonical_original_code:
struct dlnode *dscan(struct dlnode *p, void *visit(void *data))
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i = 0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->next !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}

variable_types:
p
struct dlnode *

variable_types:
visit
void *(void *data)

variable_types:
retp
void *


drescan

decompiled_code:
__int64 __fastcall drescan(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
if ( !a1 )
return 0LL;
if ( (int)dlistlength((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
}
else
{
while ( (_QWORD *)a1[1] != a1 )
a2(*a1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
if ( !a1 )
return 0LL;
if ( (int)func6((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
}
else
{
while ( (_QWORD *)a1[1] != a1 )
a2(*a1);
}
return 0LL;
}

original_code:
Dlinklist drescan(Dlinklist p, VisitFunc visit)
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i=0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->prior !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}

canonical_original_code:
struct dlnode *drescan(struct dlnode *p, void *visit(void *data))
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i = 0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->prior !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}


disempty

decompiled_code:
__int64 __fastcall disempty(__int64 a1)
{
if ( a1 )
return 2 * (unsigned int)(*(_QWORD *)(a1 + 16) == a1) + 1;
printf("a NULL list occored");
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( a1 )
return 2 * (unsigned int)(*(_QWORD *)(a1 + 16) == a1) + 1;
printf("a NULL list occored");
return 3LL;
}

original_code:
ret disempty(Dlinklist p)
{
 if(p==((void *)0))
 {
  printf("a NULL list occored");
  return NO;
 }
 else
 {
  if(p->next == p)
  return NO;
  else
  return OK;
 }
}

canonical_original_code:
enum Ret disempty(struct dlnode *p)
{
 if(p==((void *)0))
 {
  printf("a NULL list occored");
  return NO;
 }
 else
 {
  if(p->next == p)
  return NO;
  else
  return OK;
 }
}


sortlist

decompiled_code:
__int64 __fastcall sortlist(__int64 a1, int (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // r14
int v3; // edx
__int64 result; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbp
__int64 v7; // rax
int v8; // er13

if ( a1 )
{
v2 = malloc(0x18uLL);
v3 = dlistlength(a1);
result = 3LL;
if ( v3 > 2 )
{
do
{
v5 = *(_QWORD **)(a1 + 16);
v6 = (_QWORD *)v5[2];
if ( !*v6 )
break;
v8 = 0;
do
{
if ( a2(*v5) > 0 )
{
v7 = *v5;
*v2 = *v5;
*v5 = *v6;
*v6 = v7;
v8 = 1;
}
v5 = (_QWORD *)v5[2];
v6 = (_QWORD *)v6[2];
}
while ( *v6 );
}
while ( v8 );
free(v2);
result = 1LL;
}
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // r14
int v3; // edx
__int64 result; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbp
__int64 v7; // rax
int v8; // er13

if ( a1 )
{
v2 = malloc(0x18uLL);
v3 = func6(a1);
result = 3LL;
if ( v3 > 2 )
{
do
{
v5 = *(_QWORD **)(a1 + 16);
v6 = (_QWORD *)v5[2];
if ( !*v6 )
break;
v8 = 0;
do
{
if ( a2(*v5) > 0 )
{
v7 = *v5;
*v2 = *v5;
*v5 = *v6;
*v6 = v7;
v8 = 1;
}
v5 = (_QWORD *)v5[2];
v6 = (_QWORD *)v6[2];
}
while ( *v6 );
}
while ( v8 );
free(v2);
result = 1LL;
}
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

original_code:
ret sortlist(Dlinklist p,int cmpall(const void *a,const void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  Dlinklist p1=((void *)0);
  Dlinklist p2=((void *)0);
  Dlinklist p3=malloc(sizeof(Dlnode));
  int len = dlistlength(p);
  int j,i;
  if(len<3)
  {
   return NO;
  }
  else
  {
   int docmp=1;
   while(docmp)
   {
    p1 = p->next;
    p2 = p1->next;
    docmp =0;
    while(p2->data !=((void *)0))
    {
     if(cmpall(p1->data, p2->data) >0)
     {
      p3->data = p1->data;
      p1->data = p2->data;
      p2->data = p3->data;
      docmp = 1;
     }
     p1 = p1->next;
     p2=p2->next;
    }
   }
  }
  free(p3);
 return OK;
}
return NO;
}

canonical_original_code:
enum Ret sortlist(struct dlnode *p, int cmpall(void *a, void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  struct dlnode *p1 = ((void *)0);
  struct dlnode *p2 = ((void *)0);
  struct dlnode *p3 = malloc(sizeof(Dlnode));
  int len = dlistlength(p);
  int j; int i;
  if(len<3)
  {
   return NO;
  }
  else
  {
   int docmp = 1;
   while(docmp)
   {
    p1 = p->next;
    p2 = p1->next;
    docmp =0;
    while(p2->data !=((void *)0))
    {
     if(cmpall(p1->data, p2->data) >0)
     {
      p3->data = p1->data;
      p1->data = p2->data;
      p2->data = p3->data;
      docmp = 1;
     }
     p1 = p1->next;
     p2=p2->next;
    }
   }
  }
  free(p3);
 return OK;
}
return NO;
}

variable_types:
cmpall
int (void *a, void *b)

variable_types: len int

variable_types: docmp int


quicksort

original_code:
void quicksort(Dlinklist leftlist, Dlinklist rightlist , int left,int right, int cmpall(const void *a,const void *b))
{
 if(left < right)
 {
  Dlinklist baselist = leftlist;
  Dlinklist curleftlist = leftlist;
  Dlinklist currightlist = rightlist;
  leftlist = leftlist->prior;
  rightlist = rightlist->next;
  Dlinklist p;
  Dlinklist q;
  int curleft = left;
  int curright = right;
  while(curright > curleft)
  {
   while(curright > left && (cmpall(baselist->data,currightlist->data) < 0))
   {
    currightlist = currightlist->prior;
    curright--;
   }
   while(curleft < right && (cmpall(baselist->data,curleftlist->data) > 0))
   {
    curleftlist = curleftlist->next;
    curleft++;
   }
   if(curleft < curright)
   {
    p = curleftlist->prior;
    q = currightlist->next;
    curleftlist->next->prior = p;
    p->next = curleftlist->next;
    currightlist->prior->next=q;
    q->prior = currightlist->prior;
    currightlist->next = p->next;
    currightlist->prior = p;
    p->next->prior = currightlist;
    p->next =currightlist;
    curleftlist->next = q;
    curleftlist->prior = q->prior;
    q->prior->next = curleftlist;
    q->prior = curleftlist;
   curright--;
   curleft++;
   curleftlist = p->next->next;
   currightlist = q->prior->prior;
   }
  }
  if(left < curright)
  {
   quicksort(leftlist->next,currightlist->prior,left,curright-1,cmpall);
  }
  if(right > curleft)
  {
   quicksort(currightlist->next,rightlist->prior,curright+1,right,cmpall);
  }
 }
 exit(1);
}

canonical_original_code:
void quicksort(struct dlnode *leftlist, struct dlnode *rightlist, int left, int right, int cmpall(void *a, void *b))
{
 if(left < right)
 {
  struct dlnode *baselist = leftlist;
  struct dlnode *curleftlist = leftlist;
  struct dlnode *currightlist = rightlist;
  leftlist = leftlist->prior;
  rightlist = rightlist->next;
  struct dlnode *p;
  struct dlnode *q;
  int curleft = left;
  int curright = right;
  while(curright > curleft)
  {
   while(curright > left && (cmpall(baselist->data,currightlist->data) < 0))
   {
    currightlist = currightlist->prior;
    curright--;
   }
   while(curleft < right && (cmpall(baselist->data,curleftlist->data) > 0))
   {
    curleftlist = curleftlist->next;
    curleft++;
   }
   if(curleft < curright)
   {
    p = curleftlist->prior;
    q = currightlist->next;
    curleftlist->next->prior = p;
    p->next = curleftlist->next;
    currightlist->prior->next=q;
    q->prior = currightlist->prior;
    currightlist->next = p->next;
    currightlist->prior = p;
    p->next->prior = currightlist;
    p->next =currightlist;
    curleftlist->next = q;
    curleftlist->prior = q->prior;
    q->prior->next = curleftlist;
    q->prior = curleftlist;
   curright--;
   curleft++;
   curleftlist = p->next->next;
   currightlist = q->prior->prior;
   }
  }
  if(left < curright)
  {
   quicksort(leftlist->next,currightlist->prior,left,curright-1,cmpall);
  }
  if(right > curleft)
  {
   quicksort(currightlist->next,rightlist->prior,curright+1,right,cmpall);
  }
 }
 exit(1);
}

variable_types:
rightlist
struct dlnode *

variable_types: left int

variable_types: right int

variable_types: curleft int

variable_types: curright int


quicksortlist

decompiled_code:
__int64 __fastcall quicksortlist(__int64 a1, int (__fastcall *a2)(_QWORD, _QWORD))
{
int v2; // eax
__int64 result; // rax

if ( a1 )
{
v2 = dlistlength(a1);
if ( v2 > 1 )
quicksort(*(_QWORD **)(a1 + 16), *(_QWORD **)(a1 + 8), 1, v2 - 1, a2);
result = 1LL;
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int (__fastcall *a2)(_QWORD, _QWORD))
{
int v2; // eax
__int64 result; // rax

if ( a1 )
{
v2 = func6(a1);
if ( v2 > 1 )
func13(*(_QWORD **)(a1 + 16), *(_QWORD **)(a1 + 8), 1, v2 - 1, a2);
result = 1LL;
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

original_code:
ret quicksortlist(Dlinklist p,int cmpall(const void *a,const void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  int len = dlistlength(p);
  if(len < 2)
  {
   return OK;
  }
  else
  {
   int left = 1;
   int right = len - 1;
   quicksort(p->next, p->prior, left, right, cmpall);
  }
 }
}

canonical_original_code:
enum Ret quicksortlist(struct dlnode *p, int cmpall(void *a, void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  int len = dlistlength(p);
  if(len < 2)
  {
   return OK;
  }
  else
  {
   int left = 1;
   int right = len - 1;
   quicksort(p->next, p->prior, left, right, cmpall);
  }
 }
}

variable_types: struct dlnode { void *data; struct dlnode *prior; } *


myscan

decompiled_code:
int __fastcall myscan(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 16); *i; i = (_QWORD *)i[2] )
a2();
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 16); *i; i = (_QWORD *)i[2] )
a2();
return putchar(10);
}

original_code:
void myscan(Dlinklist list, VisitFunc visit)
{
 Dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->next;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->next;
    }
 printf("\n");
}

canonical_original_code:
void myscan(struct dlnode *list, void *visit(void *data))
{
 struct dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->next;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->next;
    }
 printf("\n");
}


myrescan

decompiled_code:
int __fastcall myrescan(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 8); *i; i = (_QWORD *)i[1] )
a2();
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 8); *i; i = (_QWORD *)i[1] )
a2();
return putchar(10);
}

original_code:
void myrescan(Dlinklist list, VisitFunc visit)
{
 Dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->prior;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->prior;
    }
 printf("\n");
}

canonical_original_code:
void myrescan(struct dlnode *list, void *visit(void *data))
{
 struct dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->prior;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->prior;
    }
 printf("\n");
}