empty

repo: bluke/relex

decompiled_code:
_BOOL8 __fastcall empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code:
int empty(Tree t)
{
 return t == ((void *)0);
}

canonical_original_code:
int empty(struct Tree *t)
{
 return t == ((void *)0);
}

variable_types: struct Tree { enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 } type; char *content; struct Tree *right; struct Tree *left; } *

user_defined_types: struct Tree { enum Type type; char *content; struct Tree *right; struct Tree *left; }


left

decompiled_code:
__int64 __fastcall left(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = empty(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 24);
return result;
}

original_code:
Tree left(Tree t)
{
 if(empty(t))
  return ((void *)0);
 else
  return t->left;
}

canonical_original_code:
struct Tree *left(struct Tree *t)
{
 if(empty(t))
  return ((void *)0);
 else
  return t->left;
}

variable_types:
t
struct Tree *

return_type: struct Tree { enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 } type; char *content; struct Tree *right; struct Tree *left; } *


right

decompiled_code:
__int64 __fastcall right(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = empty(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
Tree right(Tree t)
{
        if(empty(t))
                return ((void *)0);
        else
                return t->right;
}

canonical_original_code:
struct Tree *right(struct Tree *t)
{
        if(empty(t))
                return ((void *)0);
        else
                return t->right;
}

user_defined_types: enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 }


isfinal

decompiled_code:
_BOOL8 __fastcall isfinal(__int64 a1)
{
__int64 v1; // rax
_BOOL8 result; // rax
__int64 v3; // rax

v1 = left(a1);
result = empty(v1);
if ( result )
{
v3 = right(a1);
result = empty(v3);
if ( result )
result = !empty(a1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
_BOOL8 result; // rax
__int64 v3; // rax

v1 = func1(a1);
result = func0(v1);
if ( result )
{
v3 = func2(a1);
result = func0(v3);
if ( result )
result = !func0(a1);
}
return result;
}

original_code:
int isfinal(Tree t)
{
 if(empty(left(t))&&empty(right(t))&&!empty(t))
  return 1;
 else
  return 0;
}

canonical_original_code:
int isfinal(struct Tree *t)
{
 if(empty(left(t))&&empty(right(t))&&!empty(t))
  return 1;
 else
  return 0;
}

return_type: int


leaf

decompiled_code:
_BOOL8 __fastcall leaf(__int64 a1)
{
_BOOL4 v1; // edx
_BOOL8 result; // rax
__int64 v3; // rax
__int64 v4; // rax

v1 = empty(a1);
result = 0LL;
if ( !v1 )
{
v3 = left(a1);
result = empty(v3);
if ( result )
{
v4 = right(a1);
result = empty(v4);
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
_BOOL4 v1; // edx
_BOOL8 result; // rax
__int64 v3; // rax
__int64 v4; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
{
v3 = func1(a1);
result = func0(v3);
if ( result )
{
v4 = func2(a1);
result = func0(v4);
}
}
return result;
}

original_code:
int leaf(Tree t)
{
 if(empty(t))
  return 0;
 else if (empty(left(t))&&empty(right(t)))
  return 1;
 else
  return 0;
}

canonical_original_code:
int leaf(struct Tree *t)
{
 if(empty(t))
  return 0;
 else if (empty(left(t))&&empty(right(t)))
  return 1;
 else
  return 0;
}


type

decompiled_code:
__int64 __fastcall type(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return *a1;
}

original_code:
Type type(Tree t)
{
 return t->type;
}

canonical_original_code:
enum Type type(struct Tree *t)
{
 return t->type;
}

return_type: enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 }


content

decompiled_code:
__int64 __fastcall content(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
char* content(Tree t)
{
 return t->content;
}

canonical_original_code:
char *content(struct Tree *t)
{
 return t->content;
}

return_type: char *


show

decompiled_code:
int __fastcall show(__int64 a1)
{
unsigned int v2; // eax

if ( empty(a1) )
return puts("Arbre vide");
v2 = type((unsigned int *)a1);
return printf("Show du noeud de type : %d\ncontent : %s\n\n", v2, *(const char **)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
unsigned int v2; // eax

if ( func0(a1) )
return puts("Arbre vide");
v2 = func5((unsigned int *)a1);
return printf("Show du noeud de type : %d\ncontent : %s\n\n", v2, *(const char **)(a1 + 8));
}

original_code:
void show(Tree t)
{
 if(empty(t))
  printf("Arbre vide\n");
 else
  printf("Show du noeud de type : %d\ncontent : %s\n\n",type(t),t->content);
}

canonical_original_code:
void show(struct Tree *t)
{
 if(empty(t))
  printf("Arbre vide\n");
 else
  printf("Show du noeud de type : %d\ncontent : %s\n\n",type(t),t->content);
}

return_type: void


decompiled_code:
int __fastcall print_type(int *a1)
{
int v1; // eax

v1 = *a1;
if ( !*a1 )
return printf("Regle");
switch ( v1 )
{
case 1:
return printf("Union");
case 2:
return printf("Or");
case 3:
return printf("Plus");
case 4:
return printf("Etoile");
case 6:
return printf("Caractere");
case 7:
return printf("Ensemble");
case 8:
return printf("Intervalle");
case 5:
return putchar(63);
}
return printf("TYpe inconnu");
}

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

v1 = *a1;
if ( !*a1 )
return printf("Regle");
switch ( v1 )
{
case 1:
return printf("Union");
case 2:
return printf("Or");
case 3:
return printf("Plus");
case 4:
return printf("Etoile");
case 6:
return printf("Caractere");
case 7:
return printf("Ensemble");
case 8:
return printf("Intervalle");
case 5:
return putchar(63);
}
return printf("TYpe inconnu");
}

original_code:
void print_type(Tree t)
{
 Type ty=t->type;
 if(ty == REGLE)
  printf("Regle");
 else if(ty==UNION)
  printf("Union");
        else if(ty==OR)
         printf("Or");
        else if(ty==PLUS)
  printf("Plus");
        else if(ty==ETOILE)
  printf("Etoile");
        else if(ty==CARACTERE)
  printf("Caractere");
        else if(ty==ENSEMBLE)
  printf("Ensemble");
        else if(ty==INTERVALLE)
  printf("Intervalle");
 else if(ty==INTERROGATION)
  printf("?");
 else
  printf("TYpe inconnu");
}

canonical_original_code:
void print_type(struct Tree *t)
{
 enum Type ty = t->type;
 if(ty == REGLE)
  printf("Regle");
 else if(ty==UNION)
  printf("Union");
        else if(ty==OR)
         printf("Or");
        else if(ty==PLUS)
  printf("Plus");
        else if(ty==ETOILE)
  printf("Etoile");
        else if(ty==CARACTERE)
  printf("Caractere");
        else if(ty==ENSEMBLE)
  printf("Ensemble");
        else if(ty==INTERVALLE)
  printf("Intervalle");
 else if(ty==INTERROGATION)
  printf("?");
 else
  printf("TYpe inconnu");
}

variable_types: enum Type { REGLE=0, UNION=1, OR=2, PLUS=3, ETOILE=4, INTERROGATION=5, CARACTERE=6, ENSEMBLE=7, INTERVALLE=8 }


decompiled_code:
int __fastcall short_show(__int64 a1)
{
putchar(40);
print_type((int *)a1);
printf(") ");
return printf("%s", *(const char **)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
putchar(40);
func8((int *)a1);
printf(") ");
return printf("%s", *(const char **)(a1 + 8));
}

original_code:
void short_show(Tree t)
{
 printf("(");
 print_type(t);
 printf(") ");
 printf("%s",t->content);
}

canonical_original_code:
void short_show(struct Tree *t)
{
 printf("(");
 print_type(t);
 printf(") ");
 printf("%s",t->content);
}


decompiled_code:
int __fastcall print_space(int a1)
{
int result; // eax
int i; // ebx

result = putchar(10);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(32);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
int result; // eax
int i; // ebx

result = putchar(10);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(32);
}
return result;
}

original_code:
void print_space(int k)
{
 printf("\n");
 int i;
 for(i=0;i<k;i++)
  printf(" ");
}

variable_types: k int

variable_types: i int


decompiled_code:
int __fastcall tree_show(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rax

if ( isfinal(a1) )
return short_show(a1);
if ( empty(a1) )
return printf("(Vide)");
print_space(a2);
short_show(a1);
print_space(a2);
printf("|- ");
v2 = left(a1);
tree_show(v2, (unsigned int)(a2 + 2));
print_space(a2);
printf("|- ");
v3 = right(a1);
return tree_show(v3, (unsigned int)(a2 + 2));
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rax

if ( func3(a1) )
return func9(a1);
if ( func0(a1) )
return printf("(Vide)");
func10(a2);
func9(a1);
func10(a2);
printf("|- ");
v2 = func1(a1);
func11(v2, (unsigned int)(a2 + 2));
func10(a2);
printf("|- ");
v3 = func2(a1);
return func11(v3, (unsigned int)(a2 + 2));
}

original_code:
void tree_show(Tree t, int p)
{
 if(isfinal(t))
 {
  short_show(t);
 }
 else if(!empty(t))
 {
  print_space(p);
  short_show(t);
  print_space(p);
  printf("|- ");
  tree_show(left(t),p+2);
         print_space(p);
  printf("|- ");
  tree_show(right(t),p+2);
 }
 else if(empty(t))
  printf("(Vide)");
}

canonical_original_code:
void tree_show(struct Tree *t, int p)
{
 if(isfinal(t))
 {
  short_show(t);
 }
 else if(!empty(t))
 {
  print_space(p);
  short_show(t);
  print_space(p);
  printf("|- ");
  tree_show(left(t),p+2);
         print_space(p);
  printf("|- ");
  tree_show(right(t),p+2);
 }
 else if(empty(t))
  printf("(Vide)");
}

variable_types: p int


decompiled_code:
void __fastcall attach_left_son(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void attach_left_son(Tree father, Tree son)
{
 father->left=son;
}

canonical_original_code:
void attach_left_son(struct Tree *father, struct Tree *son)
{
 father->left=son;
}

variable_types:
son
struct Tree *


decompiled_code:
void __fastcall attach_right_son(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void attach_right_son(Tree father, Tree son)
{
        father->right=son;
}

canonical_original_code:
void attach_right_son(struct Tree *father, struct Tree *son)
{
        father->right=son;
}


decale

decompiled_code:
size_t __fastcall decale(int a1, const char *a2)
{
size_t i; // rbx
size_t result; // rax

for ( i = a1; ; ++i )
{
result = strlen(a2);
if ( result <= i )
break;
a2[i] = a2[i + 1];
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(int a1, const char *a2)
{
size_t i; // rbx
size_t result; // rax

for ( i = a1; ; ++i )
{
result = strlen(a2);
if ( result <= i )
break;
a2[i] = a2[i + 1];
}
return result;
}

original_code:
void decale(int j, char* t)
{
        int i;
        for(i=j;i<strlen(t);i++)
        {
                t[i]=t[i+1];
        }
}

canonical_original_code:
void decale(int j, char *t)
{
        int i;
        for(i=j;i<strlen(t);i++)
        {
                t[i]=t[i+1];
        }
}

variable_types: j int

variable_types:
t
char *


suppr

decompiled_code:
size_t __fastcall suppr(char a1, const char *a2)
{
size_t i; // rbx
size_t result; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(a2);
if ( result <= i )
break;
if ( a2[i] == a1 )
decale(i, a2);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(char a1, const char *a2)
{
size_t i; // rbx
size_t result; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(a2);
if ( result <= i )
break;
if ( a2[i] == a1 )
func0(i, a2);
}
return result;
}

original_code:
void suppr(char c, char* text)
{
 int i;
 for(i=0;i<strlen(text);i++)
 {
  if(text[i]==c)
  {
   decale(i,text);
  }
 }
}

canonical_original_code:
void suppr(char c, char *text)
{
 int i;
 for(i=0;i<strlen(text);i++)
 {
  if(text[i]==c)
  {
   decale(i,text);
  }
 }
}

variable_types: c char

variable_types:
text
char *


test

decompiled_code:
int __fastcall test(const char *a1)
{
suppr(91, a1);
return printf("apres : %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
func1(91, a1);
return printf("apres : %s\n", a1);
}

original_code:
void test(char* t)
{
 suppr('[',t);
 printf("apres : %s\n",t);
}

canonical_original_code:
void test(char *t)
{
 suppr('[',t);
 printf("apres : %s\n",t);
}


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

v2 = new(8LL, &unk_1FA);
new_left_son(v2, 6LL, a1);
new_right_son(v2, 6LL, a2);
puts("Nouvel intervalle cree");
tree_show(v2, 0LL);
return v2;
}

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

v2 = new(8LL, &unk_1FA);
new_left_son(v2, 6LL, a1);
new_right_son(v2, 6LL, a2);
puts("Nouvel intervalle cree");
tree_show(v2, 0LL);
return v2;
}

original_code:
Tree new_intervalle(char* begin, char* end)
{
 Tree t = new(INTERVALLE,"");
 new_left_son(t,CARACTERE,begin);
 new_right_son(t,CARACTERE,end);
 printf("Nouvel intervalle cree\n");
 tree_show(t,0);
 return t;
}

canonical_original_code:
struct Tree *new_intervalle(char *begin, char *end)
{
 struct Tree *t = new(INTERVALLE,"");
 new_left_son(t,CARACTERE,begin);
 new_right_son(t,CARACTERE,end);
 printf("Nouvel intervalle cree\n");
 tree_show(t,0);
 return t;
}

variable_types:
begin
char *

variable_types:
end
char *


decompiled_code:
int __fastcall new_family(__int64 a1, __int64 a2, __int64 a3)
{
attach_left_son(a2, a1);
attach_right_son(a2, a3);
return puts("Nouvelle famille cree");
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
attach_left_son(a2, a1);
attach_right_son(a2, a3);
return puts("Nouvelle famille cree");
}

original_code:
void new_family(Tree left, Tree father, Tree right)
{
 attach_left_son(father,left);
 attach_right_son(father, right);
 printf("Nouvelle famille cree\n");
}

canonical_original_code:
void new_family(struct Tree *left, struct Tree *father, struct Tree *right)
{
 attach_left_son(father,left);
 attach_right_son(father, right);
 printf("Nouvelle famille cree\n");
}

variable_types:
father
struct Tree *

variable_types:
right
struct Tree *


decompiled_code:
__int64 __fastcall new_union(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbx

v3 = new(a3, &unk_1FA);
attach_left_son(v3, a1);
attach_right_son(v3, a2);
printf("Nouvelle Union cree (");
print_type(v3);
puts(")");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rbx

v3 = new(a3, &unk_1FA);
attach_left_son(v3, a1);
attach_right_son(v3, a2);
printf("Nouvelle Union cree (");
print_type(v3);
puts(")");
return v3;
}

original_code:
Tree new_union(Tree left, Tree right, Type type)
{
 Tree t = new(type,"");
 attach_left_son(t,left);
 attach_right_son(t, right);
 printf("Nouvelle Union cree (");
 print_type(t);
 printf(")\n");
 return t;
}

canonical_original_code:
struct Tree *new_union(struct Tree *left, struct Tree *right, enum Type type)
{
 struct Tree *t = new(type,"");
 attach_left_son(t,left);
 attach_right_son(t, right);
 printf("Nouvelle Union cree (");
 print_type(t);
 printf(")\n");
 return t;
}

variable_types:
left
struct Tree *


decompiled_code:
__int64 __fastcall empile_tree(__int64 a1, unsigned int *a2, unsigned int a3, int a4)
{
__int64 v6; // rbx
__int64 v7; // rbp

printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n", *a2, (unsigned int)a4);
if ( (int)(*a2 - a4) > 1 )
{
puts("\nW00t");
v6 = new_union(*(_QWORD *)(a1 + 8LL * (int)*a2 - 16), *(_QWORD *)(a1 + 8LL * (int)*a2 - 8), a3);
LODWORD(v7) = *a2 - 3;
if ( a4 <= (int)v7 )
{
v7 = (int)v7;
do
v6 = new_union(*(_QWORD *)(a1 + 8 * v7--), v6, a3);
while ( a4 <= (int)v7 );
}
}
else if ( a3 == 7 || a3 == 2 )
{
puts("Ensemble ou Or");
v6 = new_union(*(_QWORD *)(a1 + 8LL * a4), 0LL, a3);
}
else
{
puts("Autre");
v6 = *(_QWORD *)(a1 + 8LL * a4);
}
*a2 = a4;
printf(aFinDeLEmpilage, (unsigned int)a4, (unsigned int)a4);
tree_show(v6, 0LL);
putchar(10);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2, unsigned int a3, int a4)
{
__int64 v6; // rbx
__int64 v7; // rbp

printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n", *a2, (unsigned int)a4);
if ( (int)(*a2 - a4) > 1 )
{
puts("\nW00t");
v6 = func2(*(_QWORD *)(a1 + 8LL * (int)*a2 - 16), *(_QWORD *)(a1 + 8LL * (int)*a2 - 8), a3);
LODWORD(v7) = *a2 - 3;
if ( a4 <= (int)v7 )
{
v7 = (int)v7;
do
v6 = func2(*(_QWORD *)(a1 + 8 * v7--), v6, a3);
while ( a4 <= (int)v7 );
}
}
else if ( a3 == 7 || a3 == 2 )
{
puts("Ensemble ou Or");
v6 = func2(*(_QWORD *)(a1 + 8LL * a4), 0LL, a3);
}
else
{
puts("Autre");
v6 = *(_QWORD *)(a1 + 8LL * a4);
}
*a2 = a4;
printf(aFinDeLEmpilage, (unsigned int)a4, (unsigned int)a4);
tree_show(v6, 0LL);
putchar(10);
return v6;
}

original_code:
Tree empile_tree(Tree ensemble_tree[], int* cpt_ensemble, Type type, int begin)
{
 int i;
 Tree tmp;
 printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n",*cpt_ensemble,begin);
 if(*cpt_ensemble-begin>=2)
 {
  printf("\nW00t\n");
  tmp=new_union(ensemble_tree[*cpt_ensemble-2],ensemble_tree[*cpt_ensemble-1],type);
  for(i=*cpt_ensemble-3;i>=begin;i--)
  {
   tmp=new_union(ensemble_tree[i],tmp,type);
  }
 }
 else
 {
  if(type==ENSEMBLE||type==OR)
  {
   printf("Ensemble ou Or\n");
   tmp=new_union(ensemble_tree[begin],((void *)0),type);
  }
  else
  {
   printf("Autre\n");
   tmp=ensemble_tree[begin];
  }
 }
 *(cpt_ensemble)=begin;
 printf("Fin de l'empilage en cours, on remet cpt_ensemble a jour et on affiche l'abre ainsi créé\ncpt_ensemble=%d et begin=%d\n",*cpt_ensemble,begin);
 tree_show(tmp,0);
 printf("\n");
 return tmp;
}

canonical_original_code:
struct Tree *empile_tree(struct Tree *ensemble_tree[], int *cpt_ensemble, enum Type type, int begin)
{
 int i;
 struct Tree *tmp;
 printf("Appel de la fonction empile avec cpt_ensemble=%d et begin =%d\n",*cpt_ensemble,begin);
 if(*cpt_ensemble-begin>=2)
 {
  printf("\nW00t\n");
  tmp=new_union(ensemble_tree[*cpt_ensemble-2],ensemble_tree[*cpt_ensemble-1],type);
  for(i=*cpt_ensemble-3;i>=begin;i--)
  {
   tmp=new_union(ensemble_tree[i],tmp,type);
  }
 }
 else
 {
  if(type==ENSEMBLE||type==OR)
  {
   printf("Ensemble ou Or\n");
   tmp=new_union(ensemble_tree[begin],((void *)0),type);
  }
  else
  {
   printf("Autre\n");
   tmp=ensemble_tree[begin];
  }
 }
 *(cpt_ensemble)=begin;
 printf("Fin de l'empilage en cours, on remet cpt_ensemble a jour et on affiche l'abre ainsi créé\ncpt_ensemble=%d et begin=%d\n",*cpt_ensemble,begin);
 tree_show(tmp,0);
 printf("\n");
 return tmp;
}

variable_types: begin int


repo: blunderer/cobaye

decompiled_code:
int cobaye_stdout_get_unsafe()
{
return fflush(stdout);
}

canonical_decompiled_code:
int func0()
{
return fflush(stdout);
}

original_code:
void cobaye_stdout_get_unsafe(void)
{
 fflush(stdout);
}

canonical_original_code:
void cobaye_stdout_get_unsafe()
{
 fflush(stdout);
}


decompiled_code:
int cobaye_stdout_put_unsafe()
{
return fflush(stdout);
}

canonical_decompiled_code:
int func1()
{
return fflush(stdout);
}

original_code:
void cobaye_stdout_put_unsafe(void)
{
 fflush(stdout);
}

canonical_original_code:
void cobaye_stdout_put_unsafe()
{
 fflush(stdout);
}


decompiled_code:
__int64 cobaye_printf(char *format, ...)
{
unsigned int v1; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&print_lock);
v1 = vfprintf(stdout, format, arg);
fflush(stdout);
pthread_mutex_unlock(&print_lock);
return v1;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
unsigned int v1; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&print_lock);
v1 = vfprintf(stdout, format, arg);
fflush(stdout);
pthread_mutex_unlock(&print_lock);
return v1;
}

original_code:
int cobaye_printf(char *fmt, ...)
{
 int ret = 0;
 va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&print_lock);
 ret = vfprintf(stdout, fmt, list);
 fflush(stdout);
 pthread_mutex_unlock(&print_lock);
 __builtin_va_end(list);
 return ret;
}

canonical_original_code:
int cobaye_printf(char *fmt, ...)
{
 int ret = 0;
 __builtin_va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&print_lock);
 ret = vfprintf(stdout, fmt, list);
 fflush(stdout);
 pthread_mutex_unlock(&print_lock);
 __builtin_va_end(list);
 return ret;
}

variable_types:
fmt
char *

variable_types: ret int


decompiled_code:
__int64 cobaye_scanf(char *format, ...)
{
unsigned int v1; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&scan_lock);
v1 = vscanf(format, arg);
pthread_mutex_unlock(&scan_lock);
return v1;
}

canonical_decompiled_code:
__int64 func3(char *format, ...)
{
unsigned int v1; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&scan_lock);
v1 = vscanf(format, arg);
pthread_mutex_unlock(&scan_lock);
return v1;
}

original_code:
int cobaye_scanf(char *fmt, ...)
{
 int ret = 0;
 va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&scan_lock);
 ret = vscanf(fmt, list);
 pthread_mutex_unlock(&scan_lock);
 __builtin_va_end(list);
 return ret;
}

canonical_original_code:
int cobaye_scanf(char *fmt, ...)
{
 int ret = 0;
 __builtin_va_list list;
 __builtin_va_start(list,fmt);
 pthread_mutex_lock(&scan_lock);
 ret = vscanf(fmt, list);
 pthread_mutex_unlock(&scan_lock);
 __builtin_va_end(list);
 return ret;
}


decompiled_code:
int __fastcall cobaye_run_command(char *command)
{
cobaye_printf(">> ");
return system(command);
}

canonical_decompiled_code:
int __fastcall func4(char *command)
{
func2(">> ");
return system(command);
}

original_code:
int cobaye_run_command(const char *command)
{
 cobaye_printf(">> ");
 return system(command);
}

canonical_original_code:
int cobaye_run_command(char *command)
{
 cobaye_printf(">> ");
 return system(command);
}

variable_types:
command
char *


decompiled_code:
__int64 __fastcall cobaye_build_list(__int64 a1)
{
const char **v1; // rbx
unsigned int v2; // er12
__int64 v3; // rbp

v1 = (const char **)&cobaye_start_cobaye_list;
v2 = 0;
do
{
if ( *v1 )
{
if ( a1 )
{
v3 = a1 + 96LL * (int)v2;
*(_DWORD *)v3 = 0;
strcpy((char *)(v3 + 4), *v1);
*(_QWORD *)(v3 + 72) = *v1;
*(_QWORD *)(v3 + 80) = 0LL;
*(_DWORD *)(v3 + 88) = 1;
}
++v2;
}
++v1;
}
while ( v1 != (const char **)&cobaye_end_cobaye_list );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char **v1; // rbx
unsigned int v2; // er12
__int64 v3; // rbp

v1 = (const char **)&cobaye_start_cobaye_list;
v2 = 0;
do
{
if ( *v1 )
{
if ( a1 )
{
v3 = a1 + 96LL * (int)v2;
*(_DWORD *)v3 = 0;
strcpy((char *)(v3 + 4), *v1);
*(_QWORD *)(v3 + 72) = *v1;
*(_QWORD *)(v3 + 80) = 0LL;
*(_DWORD *)(v3 + 88) = 1;
}
++v2;
}
++v1;
}
while ( v1 != (const char **)&cobaye_end_cobaye_list );
return v2;
}

original_code:
static int cobaye_build_list(struct cobaye_entry *list)
{
 int index = 0;
 struct cobaye_test **ptr = &cobaye_start_cobaye_list;
 do {
  if (*ptr) {
   if (list) {
    list[index].type = cobaye_func;
    strcpy(list[index].name, (*ptr)->name);
    list[index].test = (*ptr);
    list[index].seq = ((void *)0);
    list[index].value = 1;
   }
   index++;
  }
  ptr++;
 } while (ptr != &cobaye_end_cobaye_list);
 return index;
}

variable_types: struct cobaye_entry { enum cobaye_type { cobaye_inval=-1, cobaye_func=0, cobaye_int=1, cobaye_str=2 } type; char name[64]; struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } *test; struct cobaye_entry *seq; union { int value; char *string; }; } *

variable_types: index int

variable_types: struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } **

user_defined_types: struct cobaye_entry { enum cobaye_type type; char name[64]; struct cobaye_test *test; struct cobaye_entry *seq; union { int value; char *string; }; }


decompiled_code:
__int64 __fastcall cobaye_test_exist(char *s1)
{
__int64 v1; // rbx
__int64 v2; // r13
__int64 v3; // r12

if ( !cobaye_count )
return 0LL;
v1 = cobaye_list;
v2 = cobaye_list + 96LL * (unsigned int)(cobaye_count - 1) + 96;
while ( 1 )
{
v3 = v1;
if ( !strcmp(s1, (const char *)(v1 + 4)) )
break;
v1 += 96LL;
if ( v1 == v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
__int64 v1; // rbx
__int64 v2; // r13
__int64 v3; // r12

if ( !cobaye_count )
return 0LL;
v1 = cobaye_list;
v2 = cobaye_list + 96LL * (unsigned int)(cobaye_count - 1) + 96;
while ( 1 )
{
v3 = v1;
if ( !strcmp(s1, (const char *)(v1 + 4)) )
break;
v1 += 96LL;
if ( v1 == v2 )
return 0LL;
}
return v3;
}

original_code:
struct cobaye_entry *cobaye_test_exist(char *name)
{
 unsigned int i;
 for (i = 0; i < cobaye_count; i++) {
  if (strcmp(name, cobaye_list[i].name) == 0)
   return &cobaye_list[i];
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types:
i
unsigned int

return_type: struct cobaye_entry { enum cobaye_type { cobaye_inval=-1, cobaye_func=0, cobaye_int=1, cobaye_str=2 } type; char name[64]; struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } *test; struct cobaye_entry *seq; union { int value; char *string; }; } *


decompiled_code:
const char *__fastcall parse_cmdline(int a1, const char **a2)
{
int i; // er12
char v4; // al

for ( i = a1; i; --i )
{
v4 = (*a2)[1];
if ( **a2 != 45 )
break;
if ( (*a2)[2] )
{
++i;
--a2;
}
else if ( i == 1 )
{
if ( v4 != 45 )
{
LABEL_11:
printf("unknown argument '%s'\n", *a2);
usage();
}
++a2;
return *a2;
}
if ( v4 != 45 )
goto LABEL_11;
++a2;
}
return *a2;
}

canonical_decompiled_code:
const char *__fastcall func3(int a1, const char **a2)
{
int i; // er12
char v4; // al

for ( i = a1; i; --i )
{
v4 = (*a2)[1];
if ( **a2 != 45 )
break;
if ( (*a2)[2] )
{
++i;
--a2;
}
else if ( i == 1 )
{
if ( v4 != 45 )
{
LABEL_11:
printf("unknown argument '%s'\n", *a2);
func1();
}
++a2;
return *a2;
}
if ( v4 != 45 )
goto LABEL_11;
++a2;
}
return *a2;
}

original_code:
static char *parse_cmdline(int argc, char **argv)
{
 unsigned int index = 0;
 while (argc) {
  char opt = argv[0][1];
  char *value = argv[1];
  if (argv[0][0] != '-')
   break;
  if (argv[0][2]) {
   value = argv[0] + 2;
   argc++;
   argv--;
  } else if (argc == 1) {
   value = ((void *)0);
  }
  switch (opt) {
  case '-':
   break;
  case 'm':
   for (index = 0; index < cobaye_count; index++)
    cobaye_list[index].test->flags |= 0x0002;
   break;
  case 'd':
   cobaye_conf[item_date].value = 1;
   break;
  case 'i':
   if (value) {
    struct cobaye_entry *entry = cobaye_test_exist(value);
    if (entry) {
     printf("test: '%s':\n", entry->name);
     printf("descr: %s\n", entry->test->descr);
     printf("flags: ");
     if (!entry->test->flags)
      printf("none");
     if (entry->test->flags & 0x0001)
      printf("NO_FORK");
     if (entry->test->flags & 0x0002)
      printf("NO_USER");
     if (entry->test->flags & 0x0004)
      printf("BENCH");
     printf("\n");
    } else {
     entry = cobaye_build_seq(value);
     if (entry) {
      int i;
      printf("sequence: '%s': %d entries\n", entry->name, entry->value);
      for (i = 0; i < entry->value; i++)
       printf("  - test '%s' x %d\n", entry[i+1].name, entry[i+1].value);
     } else {
      printf("test '%s' doesn't exist\n", value);
     }
    }
   } else {
    printf("option -i expects a test or sequence name\n");
   }
   exit(0);
   break;
  case 'l':
   for (index = 0; index < cobaye_count; index++)
    printf(" - %s (%s)\n", cobaye_list[index].name, (cobaye_list[index].test-> flags & 0x0002) ? "auto" : "manual");
   exit(0);
   break;
  case 'h':
   usage();
   break;
  case 'f':
   if (value) {
    if(strstr(value, "all")) {
     cobaye_conf[item_report].value = 0xffffffff;
    } else {
     for (index = 0; index < cobaye_report_count; index++)
      if (strstr(value, cobaye_report[index]->ext))
       cobaye_conf[item_report].value |= (1 << index);
    }
    argc--;
    argv++;
   } else {
    printf("option -f expects a format specifier\n");
   }
   break;
  case 'o':
   if (value) {
    cobaye_conf[item_filename].string = strdup(value);
    argc--;
    argv++;
   } else {
    printf("option -o expects a report name\n");
   }
   break;
  default:
   printf("unknown argument '%s'\n", argv[0]);
   usage();
   break;
  }
  argc--;
  argv++;
 }
 return argv[0];
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
index
unsigned int

variable_types: opt char

variable_types:
value
char *

variable_types: i int

user_defined_types: enum cobaye_type { cobaye_inval=-1, cobaye_func=0, cobaye_int=1, cobaye_str=2 }

user_defined_types: struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rbx
__int64 v5; // rdi
int v6; // ebx
__int64 v8; // rax
__int64 v9; // rbp

cobaye_count = cobaye_build_list(0LL);
cobaye_list = (__int64)calloc((unsigned int)cobaye_count, 0x60uLL);
cobaye_count = cobaye_build_list(cobaye_list);
cobaye_report_count = cobaye_build_report_list(&cobaye_report);
v3 = (char *)parse_cmdline(argc - 1, argv + 1);
if ( !v3 )
usage();
v4 = v3;
v5 = cobaye_test_exist(v3);
if ( v5 )
return cobaye_run_tst(v5);
v8 = cobaye_build_seq(v4);
v9 = v8;
if ( v8 )
{
v6 = cobaye_run_tst(v8);
cobaye_destroy_seq(v9);
}
else
{
printf("test '%s' doesn't exist\n", v4);
v6 = -1;
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rbx
__int64 v5; // rdi
int v6; // ebx
__int64 v8; // rax
__int64 v9; // rbp

cobaye_count = func0(0LL);
cobaye_list = (__int64)calloc((unsigned int)cobaye_count, 0x60uLL);
cobaye_count = func0(cobaye_list);
cobaye_report_count = cobaye_build_report_list(&cobaye_report);
v3 = (char *)func3(argc - 1, argv + 1);
if ( !v3 )
func1();
v4 = v3;
v5 = func2(v3);
if ( v5 )
return cobaye_run_tst(v5);
v8 = cobaye_build_seq(v4);
v9 = v8;
if ( v8 )
{
v6 = cobaye_run_tst(v8);
cobaye_destroy_seq(v9);
}
else
{
printf("test '%s' doesn't exist\n", v4);
v6 = -1;
}
return v6;
}

original_code:
int main(int argc, char **argv)
{
 int ret;
 char *target;
 struct cobaye_entry *entry;
 cobaye_count = cobaye_build_list(((void *)0));
 cobaye_list = calloc(cobaye_count, sizeof(struct cobaye_entry));
 cobaye_count = cobaye_build_list(cobaye_list);
 cobaye_report_count = cobaye_build_report_list(&cobaye_report);
 target = parse_cmdline(argc - 1, argv + 1);
 if (!target)
  usage();
 entry = cobaye_test_exist(target);
 if (entry) {
  ret = cobaye_run_tst(entry);
 } else {
  struct cobaye_entry *seq = cobaye_build_seq(target);
  if (seq) {
   ret = cobaye_run_tst(seq);
   cobaye_destroy_seq(seq);
  } else {
   ret = -1;
   printf("test '%s' doesn't exist\n", target);
  }
 }
 return ret;
}

variable_types:
target
char *


decompiled_code:
__int64 __fastcall cobaye_fork(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
int v6; // ebx
int v7; // ebp
int v8; // er15
unsigned int v9; // ebx
int pid; // [rsp+Ch] [rbp-FCh]
int stat_loc; // [rsp+1Ch] [rbp-ECh] BYREF
int buf[34]; // [rsp+20h] [rbp-E8h] BYREF
int v14[2]; // [rsp+A8h] [rbp-60h] BYREF
int v15[2]; // [rsp+B0h] [rbp-58h] BYREF
int v16[2]; // [rsp+B8h] [rbp-50h] BYREF
int v17[2]; // [rsp+C0h] [rbp-48h] BYREF
int pipedes[2]; // [rsp+C8h] [rbp-40h] BYREF

pipe(pipedes);
pipe(v17);
pipe(v16);
pipe(v15);
pipe(v14);
pid = fork();
if ( !pid )
{
close(v14[1]);
close(v15[0]);
close(pipedes[0]);
close(v16[1]);
close(v17[0]);
dup2(v16[0], 0);
dup2(v17[1], 1);
dup2(pipedes[1], 2);
close(v16[0]);
close(v17[1]);
close(pipedes[1]);
v6 = (*(__int64 (**)(void))(a1 + 328))();
fflush(stdout);
fflush(stderr);
write(v15[1], &unk_628, 1uLL);
do
{
buf[0] = 0;
read(v14[0], buf, 1uLL);
}
while ( !buf[0] );
exit(v6);
}
if ( pid <= 0 )
return (unsigned int)-1;
close(pipedes[1]);
close(v15[1]);
close(v14[0]);
close(v17[1]);
close(v16[0]);
v2 = fcntl(0, 3, 0LL);
BYTE1(v2) |= 8u;
fcntl(0, 4, v2);
v3 = fcntl(v17[0], 3, 0LL);
BYTE1(v3) |= 8u;
fcntl(v17[0], 4, v3);
v4 = fcntl(pipedes[0], 3, 0LL);
BYTE1(v4) |= 8u;
fcntl(pipedes[0], 4, v4);
v5 = fcntl(v15[0], 3, 0LL);
BYTE1(v5) |= 8u;
stat_loc = v5;
fcntl(v15[0], 4, v5);
do
{
v8 = read(v15[0], buf, 1uLL);
while ( 1 )
{
memset(buf, 0, 0x80uLL);
if ( (int)read(v17[0], buf, 0x7FuLL) <= 0 )
break;
cobaye_report_all(8LL, a1, a2, buf, 1LL);
}
while ( 1 )
{
memset(buf, 0, 0x80uLL);
if ( (int)read(pipedes[0], buf, 0x7FuLL) <= 0 )
break;
cobaye_report_all(8LL, a1, a2, buf, 2LL);
}
while ( 1 )
{
memset(buf, 0, 0x80uLL);
v7 = read(0, buf, 0x7FuLL);
if ( v7 <= 0 )
break;
cobaye_report_all(8LL, a1, a2, buf, 0LL);
write(v16[1], buf, v7);
}
}
while ( v8 <= 0 );
write(v14[1], &unk_628, 1uLL);
v9 = waitpid(pid, &stat_loc, 0);
if ( pid == v9 )
{
v9 = BYTE1(stat_loc);
*(_DWORD *)(a1 + 320) = BYTE1(stat_loc);
}
close(pipedes[0]);
close(v17[0]);
close(v16[1]);
close(v15[0]);
close(v14[1]);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
int v6; // ebx
int v7; // ebp
int v8; // er15
unsigned int v9; // ebx
int pid; // [rsp+Ch] [rbp-FCh]
int stat_loc; // [rsp+1Ch] [rbp-ECh] BYREF
int buf[34]; // [rsp+20h] [rbp-E8h] BYREF
int v14[2]; // [rsp+A8h] [rbp-60h] BYREF
int v15[2]; // [rsp+B0h] [rbp-58h] BYREF
int v16[2]; // [rsp+B8h] [rbp-50h] BYREF
int v17[2]; // [rsp+C0h] [rbp-48h] BYREF
int pipedes[2]; // [rsp+C8h] [rbp-40h] BYREF

pipe(pipedes);
pipe(v17);
pipe(v16);
pipe(v15);
pipe(v14);
pid = fork();
if ( !pid )
{
close(v14[1]);
close(v15[0]);
close(pipedes[0]);
close(v16[1]);
close(v17[0]);
dup2(v16[0], 0);
dup2(v17[1], 1);
dup2(pipedes[1], 2);
close(v16[0]);
close(v17[1]);
close(pipedes[1]);
v6 = (*(__int64 (**)(void))(a1 + 328))();
fflush(stdout);
fflush(stderr);
write(v15[1], &unk_628, 1uLL);
do
{
buf[0] = 0;
read(v14[0], buf, 1uLL);
}
while ( !buf[0] );
exit(v6);
}
if ( pid <= 0 )
return (unsigned int)-1;
close(pipedes[1]);
close(v15[1]);
close(v14[0]);
close(v17[1]);
close(v16[0]);
v2 = fcntl(0, 3, 0LL);
BYTE1(v2) |= 8u;
fcntl(0, 4, v2);
v3 = fcntl(v17[0], 3, 0LL);
BYTE1(v3) |= 8u;
fcntl(v17[0], 4, v3);
v4 = fcntl(pipedes[0], 3, 0LL);
BYTE1(v4) |= 8u;
fcntl(pipedes[0], 4, v4);
v5 = fcntl(v15[0], 3, 0LL);
BYTE1(v5) |= 8u;
stat_loc = v5;
fcntl(v15[0], 4, v5);
do
{
v8 = read(v15[0], buf, 1uLL);
while ( 1 )
{
memset(buf, 0, 0x80uLL);
if ( (int)read(v17[0], buf, 0x7FuLL) <= 0 )
break;
cobaye_report_all(8LL, a1, a2, buf, 1LL);
}
while ( 1 )
{
memset(buf, 0, 0x80uLL);
if ( (int)read(pipedes[0], buf, 0x7FuLL) <= 0 )
break;
cobaye_report_all(8LL, a1, a2, buf, 2LL);
}
while ( 1 )
{
memset(buf, 0, 0x80uLL);
v7 = read(0, buf, 0x7FuLL);
if ( v7 <= 0 )
break;
cobaye_report_all(8LL, a1, a2, buf, 0LL);
write(v16[1], buf, v7);
}
}
while ( v8 <= 0 );
write(v14[1], &unk_628, 1uLL);
v9 = waitpid(pid, &stat_loc, 0);
if ( pid == v9 )
{
v9 = BYTE1(stat_loc);
*(_DWORD *)(a1 + 320) = BYTE1(stat_loc);
}
close(pipedes[0]);
close(v17[0]);
close(v16[1]);
close(v15[0]);
close(v14[1]);
return v9;
}

original_code:
static int cobaye_fork(struct cobaye_test *test, int iter)
{
 int ret = 0;
 int pid = 0;
 int err_from_tst[2];
 int data_from_tst[2];
 int data_to_tst[2];
 int ctrl_from_tst[2];
 int ctrl_to_tst[2];
 ret = pipe(err_from_tst);
 ret = pipe(data_from_tst);
 ret = pipe(data_to_tst);
 ret = pipe(ctrl_from_tst);
 ret = pipe(ctrl_to_tst);
 pid = fork();
 if (pid == 0) {
  int ret;
  close(ctrl_to_tst[1]);
  close(ctrl_from_tst[0]);
  close(err_from_tst[0]);
  close(data_to_tst[1]);
  close(data_from_tst[0]);
  dup2(data_to_tst[0], 0);
  dup2(data_from_tst[1], 1);
  dup2(err_from_tst[1], 2);
  close(data_to_tst[0]);
  close(data_from_tst[1]);
  close(err_from_tst[1]);
  ret = test->main();
  fflush(stdout);
  fflush(stderr);
  write(ctrl_from_tst[1], "Q", 1);
  do {
   int cmd = 0;
   read(ctrl_to_tst[0], &cmd, 1);
   if (cmd)
    break;
  } while (1);
  exit(ret);
 } else if (pid > 0) {
  int status;
  int tst_running = 1;
  close(err_from_tst[1]);
  close(ctrl_from_tst[1]);
  close(ctrl_to_tst[0]);
  close(data_from_tst[1]);
  close(data_to_tst[0]);
  status = fcntl(0, 3, 0) | 04000;
  fcntl(0, 4, status);
  status = fcntl(data_from_tst[0], 3, 0) | 04000;
  fcntl(data_from_tst[0], 4, status);
  status = fcntl(err_from_tst[0], 3, 0) | 04000;
  fcntl(err_from_tst[0], 4, status);
  status = fcntl(ctrl_from_tst[0], 3, 0) | 04000;
  fcntl(ctrl_from_tst[0], 4, status);
  while (tst_running) {
   int nbytes;
   char buffer[128];
   nbytes = read(ctrl_from_tst[0], buffer, 1);
   if (nbytes > 0)
    tst_running = 0;
   do {
    memset(buffer, 0, sizeof(buffer));
    nbytes = read(data_from_tst[0], buffer, sizeof(buffer) - 1);
    if (nbytes > 0)
     cobaye_report_all(8, test->name, iter, buffer, 1);
   } while (nbytes > 0);
   do {
    memset(buffer, 0, sizeof(buffer));
    nbytes = read(err_from_tst[0], buffer, sizeof(buffer) - 1);
    if (nbytes > 0)
     cobaye_report_all(8, test->name, iter, buffer, 2);
   } while (nbytes > 0);
   do {
    memset(buffer, 0, sizeof(buffer));
    nbytes = read(0, buffer, sizeof(buffer) - 1);
    if (nbytes > 0) {
     cobaye_report_all(8, test->name, iter, buffer, 0);
     write(data_to_tst[1], buffer, nbytes);
    }
   } while (nbytes > 0);
  }
  write(ctrl_to_tst[1], "Q", 1);
  ret = waitpid(pid, &status, 0);
  if (ret == pid) {
   ret = (((status) & 0xff00) >> 8);
   test->result = ret;
  }
  close(err_from_tst[0]);
  close(data_from_tst[0]);
  close(data_to_tst[1]);
  close(ctrl_from_tst[0]);
  close(ctrl_to_tst[1]);
 } else {
  ret = -1;
 }
 return ret;
}

variable_types: struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } *

variable_types: iter int

variable_types: pid int

variable_types: cmd int

variable_types: status int

variable_types: nbytes int

variable_types:
buffer
char [128]


decompiled_code:
_BOOL8 cobaye_forked()
{
return cobaye_pid != getpid();
}

canonical_decompiled_code:
_BOOL8 func3()
{
return cobaye_pid != getpid();
}

original_code:
int cobaye_forked(void)
{
 if (getpid() == cobaye_pid) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int cobaye_forked()
{
 if (getpid() == cobaye_pid) {
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall cobaye_run_tst(__int64 a1)
{
__int64 v2; // rsi
unsigned int v3; // ebp
unsigned int v4; // ebx
__int64 v6; // rsi
__int64 v7; // rdi

cobaye_pid = getpid();
cobaye_run_tst_pre(a1);
v2 = *(_QWORD *)(a1 + 72);
if ( v2 )
{
cobaye_report_all(1LL, v2, 0LL, 0LL, 0LL);
if ( cobaye_conf[46] > 0 )
{
v3 = 0;
v4 = 0;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 72);
if ( (*(_BYTE *)(v6 + 324) & 2) == 0 )
{
cobaye_report_all(4LL, v6, v3, 0LL, 0LL);
goto LABEL_5;
}
cobaye_report_all(3LL, v6, v3, 0LL, 0LL);
v7 = *(_QWORD *)(a1 + 72);
v4 = (*(_BYTE *)(v7 + 324) & 1) != 0 ? (*(unsigned int (**)(void))(v7 + 328))() : (unsigned int)cobaye_fork(v7, v3);
if ( (v4 & 0x80000000) != 0 )
break;
if ( v4 )
{
cobaye_report_all(7LL, *(_QWORD *)(a1 + 72), v3, 0LL, v4);
v4 = -1;
LABEL_10:
if ( cobaye_conf[22] == 1 )
goto LABEL_5;
goto LABEL_11;
}
cobaye_report_all(6LL, *(_QWORD *)(a1 + 72), v3, 0LL, 0LL);
LABEL_11:
if ( cobaye_conf[46] <= (int)++v3 )
goto LABEL_5;
}
cobaye_report_all(5LL, *(_QWORD *)(a1 + 72), v3, 0LL, v4);
goto LABEL_10;
}
v4 = 0;
LABEL_5:
cobaye_report_all(2LL, *(_QWORD *)(a1 + 72), 0LL, 0LL, 0LL);
}
else
{
cobaye_run_seq(a1);
v4 = 0;
}
cobaye_run_tst_post(a1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rsi
unsigned int v3; // ebp
unsigned int v4; // ebx
__int64 v6; // rsi
__int64 v7; // rdi

cobaye_pid = getpid();
func0(a1);
v2 = *(_QWORD *)(a1 + 72);
if ( v2 )
{
cobaye_report_all(1LL, v2, 0LL, 0LL, 0LL);
if ( cobaye_conf[46] > 0 )
{
v3 = 0;
v4 = 0;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 72);
if ( (*(_BYTE *)(v6 + 324) & 2) == 0 )
{
cobaye_report_all(4LL, v6, v3, 0LL, 0LL);
goto LABEL_5;
}
cobaye_report_all(3LL, v6, v3, 0LL, 0LL);
v7 = *(_QWORD *)(a1 + 72);
v4 = (*(_BYTE *)(v7 + 324) & 1) != 0 ? (*(unsigned int (**)(void))(v7 + 328))() : (unsigned int)func1(v7, v3);
if ( (v4 & 0x80000000) != 0 )
break;
if ( v4 )
{
cobaye_report_all(7LL, *(_QWORD *)(a1 + 72), v3, 0LL, v4);
v4 = -1;
LABEL_10:
if ( cobaye_conf[22] == 1 )
goto LABEL_5;
goto LABEL_11;
}
cobaye_report_all(6LL, *(_QWORD *)(a1 + 72), v3, 0LL, 0LL);
LABEL_11:
if ( cobaye_conf[46] <= (int)++v3 )
goto LABEL_5;
}
cobaye_report_all(5LL, *(_QWORD *)(a1 + 72), v3, 0LL, v4);
goto LABEL_10;
}
v4 = 0;
LABEL_5:
cobaye_report_all(2LL, *(_QWORD *)(a1 + 72), 0LL, 0LL, 0LL);
}
else
{
cobaye_run_seq(a1);
v4 = 0;
}
func2(a1);
return v4;
}

original_code:
int cobaye_run_tst(struct cobaye_entry *entry)
{
 int ret = 0;
 cobaye_pid = getpid();
 cobaye_run_tst_pre(entry);
 if (entry->test) {
  int iter;
  cobaye_report_all(1, entry->test->name, 0, ((void *)0), 0);
  for (iter = 0; iter < cobaye_conf[item_repeat].value; iter++) {
   if (((entry->test->flags & 0x0002) == 0)) {
    cobaye_report_all(4, entry->test->name, iter, ((void *)0), 0);
    break;
   }
   cobaye_report_all(3, entry->test->name, iter, ((void *)0), 0);
   if (entry->test->flags & 0x0001)
    ret = entry->test->main();
   else
    ret = cobaye_fork(entry->test, iter);
   if (ret < 0) {
    cobaye_report_all(5, entry->test->name, iter, ((void *)0), ret);
   } else if (ret == 0) {
    cobaye_report_all(6, entry->test->name, iter, ((void *)0), ret);
   } else {
    cobaye_report_all(7, entry->test->name, iter, ((void *)0), ret);
    ret = -1;
   }
   if ((ret != 0) && (cobaye_conf[item_stop_on_error].value == 1))
    break;
  }
  cobaye_report_all(2, entry->test->name, 0, ((void *)0), 0);
 } else {
  cobaye_run_seq(entry);
 }
 cobaye_run_tst_post(entry);
 return ret;
}

variable_types: struct cobaye_entry { enum cobaye_type { cobaye_inval=-1, cobaye_func=0, cobaye_int=1, cobaye_str=2 } type; char name[64]; struct cobaye_test { char name[64]; char descr[256]; int result; int flags; int (*main)(); } *test; struct cobaye_entry *seq; union { int value; char *string; }; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall cobaye_seq_add_entry(__int64 a1, const char *a2, unsigned int a3)
{
int v4; // eax
int v6; // er12
__int64 v7; // r13
__int64 v8; // r14
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = strtol(a2, &endptr, 0);
if ( *endptr == 58 )
{
v6 = v4;
++endptr;
v7 = cobaye_test_exist();
if ( v7 )
{
v8 = a1 + 96LL * (int)a3;
strcpy((char *)(v8 + 4), *(const char **)(v7 + 72));
*(_QWORD *)(v8 + 72) = *(_QWORD *)(v7 + 72);
*(_DWORD *)(v8 + 88) = v6;
*(_QWORD *)(v8 + 80) = a1;
++a3;
}
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, unsigned int a3)
{
int v4; // eax
int v6; // er12
__int64 v7; // r13
__int64 v8; // r14
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = strtol(a2, &endptr, 0);
if ( *endptr == 58 )
{
v6 = v4;
++endptr;
v7 = cobaye_test_exist();
if ( v7 )
{
v8 = a1 + 96LL * (int)a3;
strcpy((char *)(v8 + 4), *(const char **)(v7 + 72));
*(_QWORD *)(v8 + 72) = *(_QWORD *)(v7 + 72);
*(_DWORD *)(v8 + 88) = v6;
*(_QWORD *)(v8 + 80) = a1;
++a3;
}
}
return a3;
}

original_code:
static int cobaye_seq_add_entry(struct cobaye_entry *sequence, char *data, int index)
{
 char *cobaye_name;
 int cobaye_iter = 0;
 struct cobaye_test *newtest = ((void *)0);
 cobaye_iter = strtol(data, &cobaye_name, 0);
 if (cobaye_name[0] == ':') {
  struct cobaye_entry *entry;
  cobaye_name++;
  entry = cobaye_test_exist(cobaye_name);
  if (entry) {
   strcpy(sequence[index].name, entry->test->name);
   sequence[index].test = entry->test;
   sequence[index].value = cobaye_iter;
   sequence[index].seq = sequence;
   index++;
  }
 }
 return index;
}

variable_types:
data
char *

variable_types: index int


original_code:
int cobaye_run_seq(struct cobaye_entry *entry)
{
 int i;
 for (i = 1; i < entry->value + 1; i++) {
  cobaye_conf[item_repeat].value = entry[i].value;
  if (entry[i].test)
   cobaye_run_tst(&entry[i]);
 }
 return 0;
}


decompiled_code:
void __fastcall cobaye_destroy_seq(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

original_code:
void cobaye_destroy_seq(struct cobaye_entry *seq)
{
 free(seq);
}


decompiled_code:
__int64 __fastcall cobaye_report_all(int a1, const char *a2, unsigned int a3, const char *a4, unsigned int a5)
{
unsigned int v8; // ebx
int v9; // eax

if ( a1 == 6 )
{
gettimeofday(&stat_stop_test, 0LL);
++stat_nb_pass;
goto LABEL_6;
}
if ( a1 > 6 )
{
if ( a1 != 7 )
goto LABEL_6;
++stat_nb_fail;
goto LABEL_5;
}
if ( a1 == 3 )
{
gettimeofday(&stat_start_test, 0LL);
++stat_nb_test;
goto LABEL_6;
}
if ( (unsigned int)(a1 - 4) <= 1 )
LABEL_5:
gettimeofday(&stat_stop_test, 0LL);
LABEL_6:
cobaye_report_stdout(a1, a2, a3, a4, a5);
if ( cobaye_conf[70] && cobaye_report_count )
{
v8 = 0;
do
{
v9 = cobaye_conf[70];
if ( _bittest(&v9, v8) )
{
(*(void (__fastcall **)(_QWORD, const char *, _QWORD, const char *, _QWORD))(*(_QWORD *)(cobaye_report + 8LL * v8)
+ 576LL))(
(unsigned int)a1,
a2,
a3,
a4,
a5);
fflush(*(FILE **)(*(_QWORD *)(cobaye_report + 8LL * v8) + 584LL));
}
++v8;
}
while ( cobaye_report_count > v8 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char *a2, unsigned int a3, const char *a4, unsigned int a5)
{
unsigned int v8; // ebx
int v9; // eax

if ( a1 == 6 )
{
gettimeofday(&stat_stop_test, 0LL);
++stat_nb_pass;
goto LABEL_6;
}
if ( a1 > 6 )
{
if ( a1 != 7 )
goto LABEL_6;
++stat_nb_fail;
goto LABEL_5;
}
if ( a1 == 3 )
{
gettimeofday(&stat_start_test, 0LL);
++stat_nb_test;
goto LABEL_6;
}
if ( (unsigned int)(a1 - 4) <= 1 )
LABEL_5:
gettimeofday(&stat_stop_test, 0LL);
LABEL_6:
func0(a1, a2, a3, a4, a5);
if ( cobaye_conf[70] && cobaye_report_count )
{
v8 = 0;
do
{
v9 = cobaye_conf[70];
if ( _bittest(&v9, v8) )
{
(*(void (__fastcall **)(_QWORD, const char *, _QWORD, const char *, _QWORD))(*(_QWORD *)(cobaye_report + 8LL * v8)
+ 576LL))(
(unsigned int)a1,
a2,
a3,
a4,
a5);
fflush(*(FILE **)(*(_QWORD *)(cobaye_report + 8LL * v8) + 584LL));
}
++v8;
}
while ( cobaye_report_count > v8 );
}
return 0LL;
}

original_code:
int cobaye_report_all(int type, char *name, int iter, char *str, int id)
{
 unsigned int index = 0;
 switch(type) {
 case 3:
  gettimeofday(&stat_start_test, ((void *)0));
  stat_nb_test++;
  break;
 case 7:
  stat_nb_fail++;
 case 4:
 case 5:
  gettimeofday(&stat_stop_test, ((void *)0));
  break;
 case 6:
  gettimeofday(&stat_stop_test, ((void *)0));
  stat_nb_pass++;
  break;
 default:
  break;
 }
 cobaye_report_stdout(type, name, iter, str, id);
 if (!cobaye_conf[item_report].value)
  return 0;
 for (index = 0; index < cobaye_report_count; index++) {
  if (cobaye_conf[item_report].value & (1 << index)) {
   cobaye_report[index]->report(type, name, iter, str, id);
   fflush(cobaye_report[index]->stream);
  }
 }
 return 0;
}

variable_types: type int

variable_types:
name
char *

variable_types:
str
char *

variable_types: id int


decompiled_code:
__int64 cobaye_report_open()
{
char *v1; // r13
unsigned int v2; // ebx
struct tm *v3; // rax
char *v4; // rax
const char *v5; // rbx
char *v6; // rax
int v7; // eax
const char **v8; // rbp
__int64 v9; // rbp
time_t timer; // [rsp+8h] [rbp-250h] BYREF
char s[32]; // [rsp+10h] [rbp-248h] BYREF
char dest[8]; // [rsp+30h] [rbp-228h] BYREF
__int64 v13; // [rsp+38h] [rbp-220h]
char v14[496]; // [rsp+40h] [rbp-218h] BYREF

*(_QWORD *)dest = 0LL;
v13 = 0LL;
memset(v14, 0, sizeof(v14));
if ( cobaye_conf[70] && !reportpath )
{
strcpy(dest, *(const char **)&cobaye_conf[94]);
if ( cobaye_conf[118] == 1 )
{
timer = time(0LL);
v3 = localtime(&timer);
sprintf(
s,
"%04d%02d%02d_%02d%02d%02d_",
(unsigned int)(v3->tm_year + 1900),
(unsigned int)(v3->tm_mon + 1),
(unsigned int)v3->tm_mday,
(unsigned int)v3->tm_hour,
(unsigned int)v3->tm_min,
(unsigned int)v3->tm_sec);
v4 = strrchr(dest, 47);
if ( v4 )
strcpy(v4 + 1, s);
else
strcpy(dest, s);
v5 = *(const char **)&cobaye_conf[94];
v6 = strrchr(v5, 47);
if ( v6 )
v5 = v6 + 1;
strcat(dest, v5);
}
strcpy(&reportpath, dest);
v1 = &dest[strlen(&reportpath)];
mkdir(&reportpath, 0x1FFu);
if ( cobaye_report_count )
{
v2 = 0;
do
{
v7 = cobaye_conf[70];
if ( _bittest(&v7, v2) )
{
printf("Open new report type %s in %s\n", *(const char **)(cobaye_report + 8LL * v2), &reportpath);
v8 = (const char **)(cobaye_report + 8LL * v2);
strcpy((char *)*v8 + 64, &reportpath);
sprintf(v1, "/Report.%s", *v8);
v9 = *(_QWORD *)(cobaye_report + 8LL * v2);
*(_QWORD *)(v9 + 584) = fopen(dest, "w");
}
++v2;
}
while ( cobaye_report_count > v2 );
}
*v1 = 0;
gethostname(dest, 0x200uLL);
cobaye_report_all(0, dest, 0, 0LL, 0);
gettimeofday(&stat_start_tests, 0LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
char *v1; // r13
unsigned int v2; // ebx
struct tm *v3; // rax
char *v4; // rax
const char *v5; // rbx
char *v6; // rax
int v7; // eax
const char **v8; // rbp
__int64 v9; // rbp
time_t timer; // [rsp+8h] [rbp-250h] BYREF
char s[32]; // [rsp+10h] [rbp-248h] BYREF
char dest[8]; // [rsp+30h] [rbp-228h] BYREF
__int64 v13; // [rsp+38h] [rbp-220h]
char v14[496]; // [rsp+40h] [rbp-218h] BYREF

*(_QWORD *)dest = 0LL;
v13 = 0LL;
memset(v14, 0, sizeof(v14));
if ( cobaye_conf[70] && !reportpath )
{
strcpy(dest, *(const char **)&cobaye_conf[94]);
if ( cobaye_conf[118] == 1 )
{
timer = time(0LL);
v3 = localtime(&timer);
sprintf(
s,
"%04d%02d%02d_%02d%02d%02d_",
(unsigned int)(v3->tm_year + 1900),
(unsigned int)(v3->tm_mon + 1),
(unsigned int)v3->tm_mday,
(unsigned int)v3->tm_hour,
(unsigned int)v3->tm_min,
(unsigned int)v3->tm_sec);
v4 = strrchr(dest, 47);
if ( v4 )
strcpy(v4 + 1, s);
else
strcpy(dest, s);
v5 = *(const char **)&cobaye_conf[94];
v6 = strrchr(v5, 47);
if ( v6 )
v5 = v6 + 1;
strcat(dest, v5);
}
strcpy(&reportpath, dest);
v1 = &dest[strlen(&reportpath)];
mkdir(&reportpath, 0x1FFu);
if ( cobaye_report_count )
{
v2 = 0;
do
{
v7 = cobaye_conf[70];
if ( _bittest(&v7, v2) )
{
printf("Open new report type %s in %s\n", *(const char **)(cobaye_report + 8LL * v2), &reportpath);
v8 = (const char **)(cobaye_report + 8LL * v2);
strcpy((char *)*v8 + 64, &reportpath);
sprintf(v1, "/Report.%s", *v8);
v9 = *(_QWORD *)(cobaye_report + 8LL * v2);
*(_QWORD *)(v9 + 584) = fopen(dest, "w");
}
++v2;
}
while ( cobaye_report_count > v2 );
}
*v1 = 0;
gethostname(dest, 0x200uLL);
func2(0, dest, 0, 0LL, 0);
gettimeofday(&stat_start_tests, 0LL);
}
return 0LL;
}

original_code:
int cobaye_report_open(void)
{
 unsigned int index;
 time_t now;
 char buffer[512] = "";
 char *hostname = buffer;
 char *filepath = buffer;
 char *filename = buffer;
 if (!cobaye_conf[item_report].value)
  return 0;
 if(reportpath[0])
  return 0;
 strcpy(filepath, cobaye_conf[item_filename].string);
 if (cobaye_conf[item_date].value == 1) {
  char date[18];
  time_t now = time(((void *)0));
  struct tm *now_time = localtime(&now);
  sprintf(date, "%04d%02d%02d_%02d%02d%02d_",
    now_time->tm_year + 1900, now_time->tm_mon + 1,
    now_time->tm_mday, now_time->tm_hour, now_time->tm_min,
    now_time->tm_sec);
  char *filename = strrchr(filepath, '/');
  if (filename) {
   strcpy(filename + 1, date);
  } else {
   strcpy(filepath, date);
  }
  filename = strrchr(cobaye_conf[item_filename].string, '/');
  if (filename) {
   filename++;
  } else {
   filename = cobaye_conf[item_filename].string;
  }
  strcat(filepath, filename);
 }
 strcpy(reportpath, filepath);
 filename += strlen(reportpath);
 mkdir(reportpath, 0777);
 for (index = 0; index < cobaye_report_count; index++) {
  if (cobaye_conf[item_report].value & (1 << index)) {
   printf("Open new report type %s in %s\n", cobaye_report[index]->ext, reportpath);
   strcpy(cobaye_report[index]->path, reportpath);
   sprintf(filename, "/Report.%s", cobaye_report[index]->ext);
   cobaye_report[index]->stream = fopen(filepath, "w");
  }
 }
 strcpy(filename, "");
 gethostname(hostname, 512);
 cobaye_report_all(0, hostname, 0, ((void *)0), 0);
 gettimeofday(&stat_start_tests, ((void *)0));
 return 0;
}

canonical_original_code:
int cobaye_report_open()
{
 unsigned int index;
 long now;
 char buffer[512] = "";
 char *hostname = buffer;
 char *filepath = buffer;
 char *filename = buffer;
 if (!cobaye_conf[item_report].value)
  return 0;
 if(reportpath[0])
  return 0;
 strcpy(filepath, cobaye_conf[item_filename].string);
 if (cobaye_conf[item_date].value == 1) {
  char date[18];
  long now = time(((void *)0));
  struct tm *now_time = localtime(&now);
  sprintf(date, "%04d%02d%02d_%02d%02d%02d_",
    now_time->tm_year + 1900, now_time->tm_mon + 1,
    now_time->tm_mday, now_time->tm_hour, now_time->tm_min,
    now_time->tm_sec);
  char *filename = strrchr(filepath, '/');
  if (filename) {
   strcpy(filename + 1, date);
  } else {
   strcpy(filepath, date);
  }
  filename = strrchr(cobaye_conf[item_filename].string, '/');
  if (filename) {
   filename++;
  } else {
   filename = cobaye_conf[item_filename].string;
  }
  strcat(filepath, filename);
 }
 strcpy(reportpath, filepath);
 filename += strlen(reportpath);
 mkdir(reportpath, 0777);
 for (index = 0; index < cobaye_report_count; index++) {
  if (cobaye_conf[item_report].value & (1 << index)) {
   printf("Open new report type %s in %s\n", cobaye_report[index]->ext, reportpath);
   strcpy(cobaye_report[index]->path, reportpath);
   sprintf(filename, "/Report.%s", cobaye_report[index]->ext);
   cobaye_report[index]->stream = fopen(filepath, "w");
  }
 }
 strcpy(filename, "");
 gethostname(hostname, 512);
 cobaye_report_all(0, hostname, 0, ((void *)0), 0);
 gettimeofday(&stat_start_tests, ((void *)0));
 return 0;
}

variable_types:
index
unsigned int

variable_types: now long

variable_types:
buffer
char [512]

variable_types:
hostname
char *

variable_types:
filepath
char *

variable_types:
filename
char *

variable_types:
date
char [18]

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


decompiled_code:
__int64 cobaye_report_close()
{
unsigned int v1; // ebx
int v2; // eax
__int64 v3; // rbp
__int64 v4; // rax

if ( !cobaye_conf[70] )
return 0LL;
gettimeofday(&stat_stop_tests, 0LL);
cobaye_report_all(9, 0LL, 0, 0LL, 0);
if ( cobaye_report_count )
{
v1 = 0;
do
{
v2 = cobaye_conf[70];
if ( _bittest(&v2, v1) )
{
v3 = 8LL * v1;
fclose(*(FILE **)(*(_QWORD *)(cobaye_report + v3) + 584LL));
v4 = cobaye_report + v3;
*(_QWORD *)(*(_QWORD *)(cobaye_report + v3) + 584LL) = 0LL;
*(_BYTE *)(*(_QWORD *)v4 + 64LL) = 0;
}
++v1;
}
while ( cobaye_report_count > v1 );
}
reportpath = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v1; // ebx
int v2; // eax
__int64 v3; // rbp
__int64 v4; // rax

if ( !cobaye_conf[70] )
return 0LL;
gettimeofday(&stat_stop_tests, 0LL);
func2(9, 0LL, 0, 0LL, 0);
if ( cobaye_report_count )
{
v1 = 0;
do
{
v2 = cobaye_conf[70];
if ( _bittest(&v2, v1) )
{
v3 = 8LL * v1;
fclose(*(FILE **)(*(_QWORD *)(cobaye_report + v3) + 584LL));
v4 = cobaye_report + v3;
*(_QWORD *)(*(_QWORD *)(cobaye_report + v3) + 584LL) = 0LL;
*(_BYTE *)(*(_QWORD *)v4 + 64LL) = 0;
}
++v1;
}
while ( cobaye_report_count > v1 );
}
reportpath = 0;
return 0LL;
}

original_code:
int cobaye_report_close(void)
{
 unsigned int index;
 if (!cobaye_conf[item_report].value)
  return 0;
 gettimeofday(&stat_stop_tests, ((void *)0));
 cobaye_report_all(9, ((void *)0), 0, ((void *)0), 0);
 for (index = 0; index < cobaye_report_count; index++) {
  if (cobaye_conf[item_report].value & (1 << index)) {
   fclose(cobaye_report[index]->stream);
   cobaye_report[index]->stream = ((void *)0);
   strcpy(cobaye_report[index]->path, "");
  }
 }
 strcpy(reportpath, "");
 return 0;
}

canonical_original_code:
int cobaye_report_close()
{
 unsigned int index;
 if (!cobaye_conf[item_report].value)
  return 0;
 gettimeofday(&stat_stop_tests, ((void *)0));
 cobaye_report_all(9, ((void *)0), 0, ((void *)0), 0);
 for (index = 0; index < cobaye_report_count; index++) {
  if (cobaye_conf[item_report].value & (1 << index)) {
   fclose(cobaye_report[index]->stream);
   cobaye_report[index]->stream = ((void *)0);
   strcpy(cobaye_report[index]->path, "");
  }
 }
 strcpy(reportpath, "");
 return 0;
}


repo: blunderer/libotirc

decompiled_code:
__int64 __fastcall sbot_exec_message(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v7; // r14
unsigned __int8 *v8; // rax
__int64 v9; // rsi
unsigned __int64 v10; // rdx
const char *v11; // r15
char v13[1080]; // [rsp+0h] [rbp-438h] BYREF

v7 = (const char *)(a3 + 512);
v8 = (unsigned __int8 *)(a3 + (int)strlen((const char *)(a3 + 512)) + 512);
v9 = 0x100002601LL;
while ( 1 )
{
v10 = *v8;
if ( (unsigned __int8)v10 > 0x20u || !_bittest64(&v9, v10) )
break;
*v8-- = 0;
}
v11 = (const char *)(a3 + 256);
sprintf(v13, "%s/plugins-enabled/msg.sbot %s %s \"%s\"", basepath, (const char *)(a2 + 1), v11, v7);
exec_action(a1, v13, a2, (__int64)v11, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v7; // r14
unsigned __int8 *v8; // rax
__int64 v9; // rsi
unsigned __int64 v10; // rdx
const char *v11; // r15
char v13[1080]; // [rsp+0h] [rbp-438h] BYREF

v7 = (const char *)(a3 + 512);
v8 = (unsigned __int8 *)(a3 + (int)strlen((const char *)(a3 + 512)) + 512);
v9 = 0x100002601LL;
while ( 1 )
{
v10 = *v8;
if ( (unsigned __int8)v10 > 0x20u || !_bittest64(&v9, v10) )
break;
*v8-- = 0;
}
v11 = (const char *)(a3 + 256);
sprintf(v13, "%s/plugins-enabled/msg.sbot %s %s \"%s\"", basepath, (const char *)(a2 + 1), v11, v7);
func0(a1, v13, a2, (__int64)v11, a4);
return 0LL;
}

original_code:
int sbot_exec_message(irc_bot_t* bot, irc_chan_t *chan, irc_msg_t *msg, void * data)
{
 int i;
 char libcommand[1024];
 for(i = strlen(msg->mesg); (msg->mesg[i] == '\0') || (msg->mesg[i] == ' ') || (msg->mesg[i] == '\n' || (msg->mesg[i] == '\r')) || (msg->mesg[i] == '\t'); i--) msg->mesg[i] = '\0';
 sprintf(libcommand, "%s/plugins-enabled/msg.sbot %s %s \"%s\"", basepath, chan->name+1, msg->from, msg->mesg);
 exec_action(bot, libcommand, chan, msg->from, data);
 return 0;
}

canonical_original_code:
int sbot_exec_message(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data)
{
 int i;
 char libcommand[1024];
 for(i = strlen(msg->mesg); (msg->mesg[i] == '\0') || (msg->mesg[i] == ' ') || (msg->mesg[i] == '\n' || (msg->mesg[i] == '\r')) || (msg->mesg[i] == '\t'); i--) msg->mesg[i] = '\0';
 sprintf(libcommand, "%s/plugins-enabled/msg.sbot %s %s \"%s\"", basepath, chan->name+1, msg->from, msg->mesg);
 exec_action(bot, libcommand, chan, msg->from, data);
 return 0;
}

variable_types: struct _irc_bot_t { int soc; int port; char name[256]; char server[512]; struct _irc_chan_t { char name[256]; struct _irc_chan_t *next; } *chans; int (*on_msg)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t { char dest[256]; char from[256]; char mesg[2048]; } *msg, void *data); int (*on_cmd)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); int (*on_prv)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); int (*on_tom)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); void *on_msg_data; void *on_cmd_data; void *on_prv_data; void *on_tom_data; } *

variable_types:
chan
struct _irc_chan_t *

variable_types:
msg
struct _irc_msg_t *

variable_types:
data
void *

variable_types: i int

variable_types:
libcommand
char [1024]

user_defined_types: struct _irc_bot_t { int soc; int port; char name[256]; char server[512]; struct _irc_chan_t *chans; int (*on_msg)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); int (*on_cmd)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); int (*on_prv)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); int (*on_tom)(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data); void *on_msg_data; void *on_cmd_data; void *on_prv_data; void *on_tom_data; }


decompiled_code:
__int64 __fastcall sbot_exec_command(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v6; // r15
char v7; // al
char *v8; // rdx
int v9; // ecx
const char *v10; // r9
size_t v12; // [rsp+8h] [rbp-4C0h]
char s[1024]; // [rsp+10h] [rbp-4B8h] BYREF
char dest; // [rsp+410h] [rbp-B8h] BYREF
char v15[183]; // [rsp+411h] [rbp-B7h] BYREF

v6 = (const char *)(a3 + 512);
v12 = strlen((const char *)(a1 + 8));
if ( !strncmp(v6, (const char *)(a1 + 8), v12) )
strcpy(&dest, &v6[v12 + 2]);
else
strcpy(&dest, (const char *)(a3 + 512));
v7 = dest;
if ( (dest & 0xDF) != 0 )
{
v8 = v15;
v9 = 0;
do
{
if ( (unsigned __int8)(v7 - 9) <= 1u )
break;
if ( v7 == 13 )
break;
++v9;
v7 = *v8++;
}
while ( (v7 & 0xDF) != 0 );
}
else
{
v9 = 0;
}
*(&dest + v9) = 0;
v10 = &v15[v9];
if ( a4 == 2 && !strcmp(&dest, "quit") )
{
irc_send_command(a1, 3LL, v10);
running = 0;
}
else
{
if ( a2 )
sprintf(
s,
"%s/plugins-enabled/%s.sbot %s %s %s",
basepath,
&dest,
(const char *)(a2 + 1),
(const char *)(a3 + 256),
v10);
else
sprintf(s, "%s/plugins-enabled/%s.sbot PRIVATE %s %s", basepath, &dest, (const char *)(a3 + 256), v10);
exec_action(a1, s, a2, a3 + 256, a4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v6; // r15
char v7; // al
char *v8; // rdx
int v9; // ecx
const char *v10; // r9
size_t v12; // [rsp+8h] [rbp-4C0h]
char s[1024]; // [rsp+10h] [rbp-4B8h] BYREF
char dest; // [rsp+410h] [rbp-B8h] BYREF
char v15[183]; // [rsp+411h] [rbp-B7h] BYREF

v6 = (const char *)(a3 + 512);
v12 = strlen((const char *)(a1 + 8));
if ( !strncmp(v6, (const char *)(a1 + 8), v12) )
strcpy(&dest, &v6[v12 + 2]);
else
strcpy(&dest, (const char *)(a3 + 512));
v7 = dest;
if ( (dest & 0xDF) != 0 )
{
v8 = v15;
v9 = 0;
do
{
if ( (unsigned __int8)(v7 - 9) <= 1u )
break;
if ( v7 == 13 )
break;
++v9;
v7 = *v8++;
}
while ( (v7 & 0xDF) != 0 );
}
else
{
v9 = 0;
}
*(&dest + v9) = 0;
v10 = &v15[v9];
if ( a4 == 2 && !strcmp(&dest, "quit") )
{
irc_send_command(a1, 3LL, v10);
running = 0;
}
else
{
if ( a2 )
sprintf(
s,
"%s/plugins-enabled/%s.sbot %s %s %s",
basepath,
&dest,
(const char *)(a2 + 1),
(const char *)(a3 + 256),
v10);
else
sprintf(s, "%s/plugins-enabled/%s.sbot PRIVATE %s %s", basepath, &dest, (const char *)(a3 + 256), v10);
func0(a1, s, a2, a3 + 256, a4);
}
return 0LL;
}

original_code:
int sbot_exec_command(irc_bot_t* bot, irc_chan_t *chan, irc_msg_t *msg, void *data)
{
 int i = 0;
 char * arguments;
 char str[1024];
 char command[128];
 char libcommand[1024];
 if(strncmp(msg->mesg, bot->name, strlen(bot->name)) == 0) {
  strcpy(command, msg->mesg+strlen(bot->name)+2);
 } else {
  strcpy(command, msg->mesg);
 }
 for(i = 0; (command[i] != '\0') && (command[i] != ' ') && (command[i] != '\n' && (command[i] != '\r')) && (command[i] != '\t'); i++);
 command[i] = '\0';
 arguments = command+i+1;
 if(data == (void*)2) {
  if(strcmp(command, "quit") == 0) {
   irc_send_command(bot, quit_cmd, arguments);
   running = 0;
   return 0;
  }
 }
 if(chan) {
  sprintf(libcommand, "%s/plugins-enabled/%s.sbot %s %s %s", basepath, command, chan->name+1, msg->from, arguments);
 } else {
  sprintf(libcommand, "%s/plugins-enabled/%s.sbot PRIVATE %s %s", basepath, command, msg->from, arguments);
 }
 exec_action(bot, libcommand, chan, msg->from, data);
 return 0;
}

canonical_original_code:
int sbot_exec_command(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data)
{
 int i = 0;
 char *arguments;
 char str[1024];
 char command[128];
 char libcommand[1024];
 if(strncmp(msg->mesg, bot->name, strlen(bot->name)) == 0) {
  strcpy(command, msg->mesg+strlen(bot->name)+2);
 } else {
  strcpy(command, msg->mesg);
 }
 for(i = 0; (command[i] != '\0') && (command[i] != ' ') && (command[i] != '\n' && (command[i] != '\r')) && (command[i] != '\t'); i++);
 command[i] = '\0';
 arguments = command+i+1;
 if(data == (void *)2) {
  if(strcmp(command, "quit") == 0) {
   irc_send_command(bot, quit_cmd, arguments);
   running = 0;
   return 0;
  }
 }
 if(chan) {
  sprintf(libcommand, "%s/plugins-enabled/%s.sbot %s %s %s", basepath, command, chan->name+1, msg->from, arguments);
 } else {
  sprintf(libcommand, "%s/plugins-enabled/%s.sbot PRIVATE %s %s", basepath, command, msg->from, arguments);
 }
 exec_action(bot, libcommand, chan, msg->from, data);
 return 0;
}

variable_types:
arguments
char *

variable_types:
str
char [1024]

variable_types:
command
char [128]

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

user_defined_types: struct _irc_msg_t { char dest[256]; char from[256]; char mesg[2048]; }


decompiled_code:
__int64 __fastcall sbot_command(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
sbot_exec_command(a1, a2, a3, a4);
sbot_exec_message(a1, a2, a3, a4);
return 0LL;
}

original_code:
int sbot_command(irc_bot_t* bot, irc_chan_t *chan, irc_msg_t *msg, void *data)
{
 sbot_exec_command(bot, chan, msg, data);
 sbot_exec_message(bot, chan, msg, data);
 return 0;
}

canonical_original_code:
int sbot_command(struct _irc_bot_t *bot, struct _irc_chan_t *chan, struct _irc_msg_t *msg, void *data)
{
 sbot_exec_command(bot, chan, msg, data);
 sbot_exec_message(bot, chan, msg, data);
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char v4; // dl
const char *v5; // rax
const char *v6; // rbp
const char *v7; // r15
size_t v8; // rbp
size_t v9; // rax
__int64 v10; // rbp
unsigned int v11; // eax
const char **v12; // rbx
int v13; // ebx
size_t v14; // r14
size_t v15; // rax
__int64 i; // r13
char v18[128]; // [rsp+0h] [rbp-4B8h] BYREF
char s[1080]; // [rsp+80h] [rbp-438h] BYREF

v3 = *argv;
v4 = **argv;
if ( v4 )
{
v5 = v3 + 1;
do
{
if ( v4 == 47 )
v3 = v5;
v4 = *v5++;
}
while ( v4 );
}
memset(basepath, 0, sizeof(basepath));
v6 = *argv;
if ( **argv == 47 )
{
v14 = strlen(*argv);
v15 = strlen(v3);
strncat(basepath, v6, v14 - v15);
}
else
{
getcwd(basepath, 0x200uLL);
*(_WORD *)&basepath[strlen(basepath)] = 47;
v7 = *argv;
v8 = strlen(*argv);
v9 = strlen(v3);
strncat(basepath, v7, v8 - v9);
}
sprintf(s, "%s/plugins-enabled/cron.sbot", basepath);
v10 = irc_create_bot(v3);
if ( argc <= 2 )
{
puts("syntax: ./[bot name] [server] [port] [chan1] [chan2] ...");
exit(0);
}
v11 = atoi(argv[2]);
if ( (int)irc_connect_bot(v10, argv[1], v11) < 0 )
{
puts("cannot connect bot to server");
exit(1);
}
usleep(0xF4240u);
if ( argc > 3 )
{
v12 = argv + 3;
do
{
sprintf(v18, "#%s", *v12);
irc_join(v10, v18);
++v12;
}
while ( v12 != &argv[(unsigned int)(argc - 4) + 4] );
}
irc_call_on_chan_message(v10, sbot_exec_message, 1LL);
irc_call_on_chan_message_to_me(v10, sbot_command, 1LL);
irc_call_on_chan_message_private(v10, sbot_exec_command, 2LL);
if ( running )
{
v13 = 0;
do
{
if ( ++v13 % 10000 == 1 )
{
for ( i = *(_QWORD *)(v10 + 776); i; i = *(_QWORD *)(i + 256) )
exec_action(v10, s, i, 0LL, 1LL);
}
usleep(0x3E8u);
}
while ( running );
}
irc_disconnect_bot(v10);
irc_destroy_bot(v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
char v4; // dl
const char *v5; // rax
const char *v6; // rbp
const char *v7; // r15
size_t v8; // rbp
size_t v9; // rax
__int64 v10; // rbp
unsigned int v11; // eax
const char **v12; // rbx
int v13; // ebx
size_t v14; // r14
size_t v15; // rax
__int64 i; // r13
char v18[128]; // [rsp+0h] [rbp-4B8h] BYREF
char s[1080]; // [rsp+80h] [rbp-438h] BYREF

v3 = *argv;
v4 = **argv;
if ( v4 )
{
v5 = v3 + 1;
do
{
if ( v4 == 47 )
v3 = v5;
v4 = *v5++;
}
while ( v4 );
}
memset(basepath, 0, sizeof(basepath));
v6 = *argv;
if ( **argv == 47 )
{
v14 = strlen(*argv);
v15 = strlen(v3);
strncat(basepath, v6, v14 - v15);
}
else
{
getcwd(basepath, 0x200uLL);
*(_WORD *)&basepath[strlen(basepath)] = 47;
v7 = *argv;
v8 = strlen(*argv);
v9 = strlen(v3);
strncat(basepath, v7, v8 - v9);
}
sprintf(s, "%s/plugins-enabled/cron.sbot", basepath);
v10 = irc_create_bot(v3);
if ( argc <= 2 )
{
puts("syntax: ./[bot name] [server] [port] [chan1] [chan2] ...");
exit(0);
}
v11 = atoi(argv[2]);
if ( (int)irc_connect_bot(v10, argv[1], v11) < 0 )
{
puts("cannot connect bot to server");
exit(1);
}
usleep(0xF4240u);
if ( argc > 3 )
{
v12 = argv + 3;
do
{
sprintf(v18, "#%s", *v12);
irc_join(v10, v18);
++v12;
}
while ( v12 != &argv[(unsigned int)(argc - 4) + 4] );
}
irc_call_on_chan_message(v10, sbot_exec_message, 1LL);
irc_call_on_chan_message_to_me(v10, sbot_command, 1LL);
irc_call_on_chan_message_private(v10, sbot_exec_command, 2LL);
if ( running )
{
v13 = 0;
do
{
if ( ++v13 % 10000 == 1 )
{
for ( i = *(_QWORD *)(v10 + 776); i; i = *(_QWORD *)(i + 256) )
func0(v10, s, i, 0LL, 1LL);
}
usleep(0x3E8u);
}
while ( running );
}
irc_disconnect_bot(v10);
irc_destroy_bot(v10);
return 0;
}

original_code:
int main(int argc, const char ** argv)
{
 int i;
 int cnt = 0;
 char libcommand[1024];
 char * name = (char *)argv[0];
 for(i = 0; argv[0][i] != '\0'; i++) {
  if(argv[0][i] == '/') {
   name = (char*)argv[0] + i + 1;
  }
 }
 memset(basepath, 0, 512);
 if(argv[0][0] == '/') {
  strncat(basepath, argv[0], strlen(argv[0])-strlen(name));
 } else {
  getcwd(basepath, 512);
  strcat(basepath, "/");
  strncat(basepath, argv[0], strlen(argv[0])-strlen(name));
 }
 sprintf(libcommand, "%s/plugins-enabled/cron.sbot", basepath);
 irc_bot_t* sbot = irc_create_bot(name);
 if(argc > 2) {
  if(irc_connect_bot(sbot, (char*)argv[1], atoi((char*)argv[2])) < 0) {
   printf("cannot connect bot to server\n");
   exit(1);
  }
 } else {
  printf("syntax: ./[bot name] [server] [port] [chan1] [chan2] ...\n");
  exit(0);
 }
 usleep(1000000);
 for(i = 3; i < argc; i++) {
  char channame[128];
  sprintf(channame, "#%s", argv[i]);
  irc_join(sbot, channame);
 }
 irc_call_on_chan_message(sbot, sbot_exec_message, (void*)1);
 irc_call_on_chan_message_to_me(sbot, sbot_command, (void*)1);
 irc_call_on_chan_message_private(sbot, sbot_exec_command, (void*)2);
 while(running) {
  cnt++;
  if((cnt % 10000) == 1) {
   irc_chan_t * chan = sbot->chans;
   while(chan) {
    exec_action(sbot, libcommand, chan, ((void *)0), (void*)1);
    chan = chan->next;
   }
  }
  usleep(1000);
 }
 irc_disconnect_bot(sbot);
 irc_destroy_bot(sbot);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 int cnt = 0;
 char libcommand[1024];
 char *name = (char *)argv[0];
 for(i = 0; argv[0][i] != '\0'; i++) {
  if(argv[0][i] == '/') {
   name = (char *)argv[0] + i + 1;
  }
 }
 memset(basepath, 0, 512);
 if(argv[0][0] == '/') {
  strncat(basepath, argv[0], strlen(argv[0])-strlen(name));
 } else {
  getcwd(basepath, 512);
  strcat(basepath, "/");
  strncat(basepath, argv[0], strlen(argv[0])-strlen(name));
 }
 sprintf(libcommand, "%s/plugins-enabled/cron.sbot", basepath);
 struct _irc_bot_t *sbot = irc_create_bot(name);
 if(argc > 2) {
  if(irc_connect_bot(sbot, (char *)argv[1], atoi((char *)argv[2])) < 0) {
   printf("cannot connect bot to server\n");
   exit(1);
  }
 } else {
  printf("syntax: ./[bot name] [server] [port] [chan1] [chan2] ...\n");
  exit(0);
 }
 usleep(1000000);
 for(i = 3; i < argc; i++) {
  char channame[128];
  sprintf(channame, "#%s", argv[i]);
  irc_join(sbot, channame);
 }
 irc_call_on_chan_message(sbot, sbot_exec_message, (void *)1);
 irc_call_on_chan_message_to_me(sbot, sbot_command, (void *)1);
 irc_call_on_chan_message_private(sbot, sbot_exec_command, (void *)2);
 while(running) {
  cnt++;
  if((cnt % 10000) == 1) {
   struct _irc_chan_t *chan = sbot->chans;
   while(chan) {
    exec_action(sbot, libcommand, chan, ((void *)0), (void *)1);
    chan = chan->next;
   }
  }
  usleep(1000);
 }
 irc_disconnect_bot(sbot);
 irc_destroy_bot(sbot);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: cnt int

variable_types:
name
char *

variable_types:
channame
char [128]

variable_types: struct _irc_chan_t { char name[256]; struct _irc_chan_t *next; } *


usage

decompiled_code:
void __noreturn usage()
{
puts("proxy [-l <listening port>] -f <forward ip>:<forward port>");
exit(0);
}

canonical_decompiled_code:
void __noreturn func9()
{
puts("proxy [-l <listening port>] -f <forward ip>:<forward port>");
exit(0);
}

original_code:
void usage(void) {
 printf("proxy [-l <listening port>] -f <forward ip>:<forward port>\n");
 exit(0);
}

canonical_original_code:
void usage() {
 printf("proxy [-l <listening port>] -f <forward ip>:<forward port>\n");
 exit(0);
}


decompiled_code:
__int64 __fastcall parse_args(int a1, const char **a2)
{
__int64 result; // rax
const char *v3; // rbp
char *v4; // rdi

if ( a1 == 5 )
{
v3 = a2[1];
if ( !strcmp(v3, "-l") )
{
proxy_port = atoi(a2[2]);
}
else
{
result = 0LL;
if ( strcmp(a2[3], "-l") )
return result;
proxy_port = atoi(a2[4]);
}
if ( !strcmp(v3, "-f") )
{
strcpy(forward_addr, a2[2]);
v4 = strchr(forward_addr, 58);
result = 1LL;
if ( v4 )
{
LABEL_16:
*v4 = 0;
forward_port = atoi(v4 + 1);
return 1LL;
}
}
else
{
result = 0LL;
if ( !strcmp(a2[3], "-f") )
{
strcpy(forward_addr, a2[4]);
v4 = strchr(forward_addr, 58);
result = 1LL;
if ( v4 )
goto LABEL_16;
}
}
}
else
{
result = 0LL;
if ( a1 == 3 )
{
result = 1LL;
if ( !strcmp(a2[1], "-f") )
{
strcpy(forward_addr, a2[2]);
v4 = strchr(forward_addr, 58);
result = 1LL;
if ( v4 )
goto LABEL_16;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, const char **a2)
{
__int64 result; // rax
const char *v3; // rbp
char *v4; // rdi

if ( a1 == 5 )
{
v3 = a2[1];
if ( !strcmp(v3, "-l") )
{
proxy_port = atoi(a2[2]);
}
else
{
result = 0LL;
if ( strcmp(a2[3], "-l") )
return result;
proxy_port = atoi(a2[4]);
}
if ( !strcmp(v3, "-f") )
{
strcpy(forward_addr, a2[2]);
v4 = strchr(forward_addr, 58);
result = 1LL;
if ( v4 )
{
LABEL_16:
*v4 = 0;
forward_port = atoi(v4 + 1);
return 1LL;
}
}
else
{
result = 0LL;
if ( !strcmp(a2[3], "-f") )
{
strcpy(forward_addr, a2[4]);
v4 = strchr(forward_addr, 58);
result = 1LL;
if ( v4 )
goto LABEL_16;
}
}
}
else
{
result = 0LL;
if ( a1 == 3 )
{
result = 1LL;
if ( !strcmp(a2[1], "-f") )
{
strcpy(forward_addr, a2[2]);
v4 = strchr(forward_addr, 58);
result = 1LL;
if ( v4 )
goto LABEL_16;
}
}
}
return result;
}

original_code:
int parse_args(int argc, char ** argv)
{
 if(argc == 5) {
  if(strcmp(argv[1], "-l") == 0) {
   proxy_port = atoi(argv[2]);
  } else if(strcmp(argv[3], "-l") == 0) {
   proxy_port = atoi(argv[4]);
  } else {
   return 0;
  }
  if(strcmp(argv[1], "-f") == 0) {
   strcpy(forward_addr, argv[2]);
   if(strstr(forward_addr, ":")) {
    char *ptr = strstr(forward_addr, ":");
    ptr[0] = 0;
    forward_port = atoi(ptr+1);
   }
  } else if(strcmp(argv[3], "-f") == 0) {
   strcpy(forward_addr, argv[4]);
   if(strstr(forward_addr, ":")) {
    char *ptr = strstr(forward_addr, ":");
    ptr[0] = 0;
    forward_port = atoi(ptr+1);
   }
  } else {
   return 0;
  }
 }else if(argc == 3) {
  if(strcmp(argv[1], "-f") == 0) {
   strcpy(forward_addr, argv[2]);
   if(strstr(forward_addr, ":")) {
    char *ptr = strstr(forward_addr, ":");
    ptr[0] = 0;
    forward_port = atoi(ptr+1);
   }
  }
 } else {
  return 0;
 }
 return 1;
}

canonical_original_code:
int parse_args(int argc, char **argv)
{
 if(argc == 5) {
  if(strcmp(argv[1], "-l") == 0) {
   proxy_port = atoi(argv[2]);
  } else if(strcmp(argv[3], "-l") == 0) {
   proxy_port = atoi(argv[4]);
  } else {
   return 0;
  }
  if(strcmp(argv[1], "-f") == 0) {
   strcpy(forward_addr, argv[2]);
   if(strstr(forward_addr, ":")) {
    char *ptr = strstr(forward_addr, ":");
    ptr[0] = 0;
    forward_port = atoi(ptr+1);
   }
  } else if(strcmp(argv[3], "-f") == 0) {
   strcpy(forward_addr, argv[4]);
   if(strstr(forward_addr, ":")) {
    char *ptr = strstr(forward_addr, ":");
    ptr[0] = 0;
    forward_port = atoi(ptr+1);
   }
  } else {
   return 0;
  }
 }else if(argc == 3) {
  if(strcmp(argv[1], "-f") == 0) {
   strcpy(forward_addr, argv[2]);
   if(strstr(forward_addr, ":")) {
    char *ptr = strstr(forward_addr, ":");
    ptr[0] = 0;
    forward_port = atoi(ptr+1);
   }
  }
 } else {
  return 0;
 }
 return 1;
}

variable_types:
ptr
char *


repo: bmarcot/kemerald

decompiled_code:
void __noreturn job1()
{
unsigned int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // eax

while ( 1 )
{
v0 = rdesp();
v1 = rdebp();
printf("\t(job1)\tesp:%x ebp:%x\n", v0, v1);
v2 = sc_sysenter(1LL);
printf("\tsc_sleep() exit code = %d\n", v2);
}
}

canonical_decompiled_code:
void __noreturn func0()
{
unsigned int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // eax

while ( 1 )
{
v0 = rdesp();
v1 = rdebp();
printf("\t(job1)\tesp:%x ebp:%x\n", v0, v1);
v2 = sc_sysenter(1LL);
printf("\tsc_sleep() exit code = %d\n", v2);
}
}

original_code:
void job1(void)
{
  uint32_t esp, ebp;
  int32_t status = 0xbebe;
  while (1)
    {
      esp = rdesp();
      ebp = rdebp();
      printf("\t(job1)\tesp:%x ebp:%x\n", esp, ebp);
      status = sc_sysenter(1);
      printf("\tsc_sleep() exit code = %d\n", status);
    }
}

canonical_original_code:
void job1()
{
  unsigned int esp; unsigned int ebp;
  int status = 0xbebe;
  while (1)
    {
      esp = rdesp();
      ebp = rdebp();
      printf("\t(job1)\tesp:%x ebp:%x\n", esp, ebp);
      status = sc_sysenter(1);
      printf("\tsc_sleep() exit code = %d\n", status);
    }
}

variable_types:
esp
unsigned int

variable_types:
ebp
unsigned int

variable_types: status int


decompiled_code:
void __noreturn job2()
{
unsigned int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // eax

while ( 1 )
{
v0 = rdesp();
v1 = rdebp();
printf("\t(job2)\tesp:%x ebp:%x\n", v0, v1);
v2 = sc_sysenter(1LL);
printf("\tsc_sleep() exit code = %d\n", v2);
}
}

canonical_decompiled_code:
void __noreturn func1()
{
unsigned int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // eax

while ( 1 )
{
v0 = rdesp();
v1 = rdebp();
printf("\t(job2)\tesp:%x ebp:%x\n", v0, v1);
v2 = sc_sysenter(1LL);
printf("\tsc_sleep() exit code = %d\n", v2);
}
}

original_code:
void job2(void)
{
  uint32_t esp, ebp;
  int32_t status = 0xbebe;
  while (1)
    {
      esp = rdesp();
      ebp = rdebp();
      printf("\t(job2)\tesp:%x ebp:%x\n", esp, ebp);
      status = sc_sysenter(1);
      printf("\tsc_sleep() exit code = %d\n", status);
    }
}

canonical_original_code:
void job2()
{
  unsigned int esp; unsigned int ebp;
  int status = 0xbebe;
  while (1)
    {
      esp = rdesp();
      ebp = rdebp();
      printf("\t(job2)\tesp:%x ebp:%x\n", esp, ebp);
      status = sc_sysenter(1);
      printf("\tsc_sleep() exit code = %d\n", status);
    }
}


decompiled_code:
__int64 sched_init()
{
unsigned int v0; // eax
unsigned int v1; // ebp
unsigned int v2; // eax
unsigned int v3; // ebx

v0 = thread_create((unsigned int)job1, 1LL, "job1");
v1 = v0;
if ( v0 == -1 )
return (unsigned int)-1;
printf("Created thread job1 with id %d.\n", v0);
v2 = thread_create((unsigned int)job2, 1LL, "job2");
v3 = v2;
if ( v2 != -1 )
{
printf("Created thread job2 with id %d.\n", v2);
if ( (unsigned int)thread_start(v1) || (v3 = thread_start(v3)) != 0 )
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
unsigned int v1; // ebp
unsigned int v2; // eax
unsigned int v3; // ebx

v0 = thread_create((unsigned int)job1, 1LL, "job1");
v1 = v0;
if ( v0 == -1 )
return (unsigned int)-1;
printf("Created thread job1 with id %d.\n", v0);
v2 = thread_create((unsigned int)job2, 1LL, "job2");
v3 = v2;
if ( v2 != -1 )
{
printf("Created thread job2 with id %d.\n", v2);
if ( (unsigned int)thread_start(v1) || (v3 = thread_start(v3)) != 0 )
v3 = -1;
}
return v3;
}

original_code:
int32_t sched_init(void)
{
  int32_t id[2];
  uint32_t i;
  if ((id[0] = thread_create((uint32_t)(job1), USER, "job1")) == -1)
    {
      return -1;
    }
  printf("Created thread job1 with id %d.\n", id[0]);
  if ((id[1] = thread_create((uint32_t)(job2), USER, "job2")) == -1)
    {
      return -1;
    }
  printf("Created thread job2 with id %d.\n", id[1]);
  for (i = 0; i < 2; i++)
    {
      if (thread_start(id[i]) != 0)
 {
   return -1;
 }
    }
  return 0;
}

canonical_original_code:
int sched_init()
{
  int id[2];
  unsigned int i;
  if ((id[0] = thread_create((unsigned int)(job1), USER, "job1")) == -1)
    {
      return -1;
    }
  printf("Created thread job1 with id %d.\n", id[0]);
  if ((id[1] = thread_create((unsigned int)(job2), USER, "job2")) == -1)
    {
      return -1;
    }
  printf("Created thread job2 with id %d.\n", id[1]);
  for (i = 0; i < 2; i++)
    {
      if (thread_start(id[i]) != 0)
 {
   return -1;
 }
    }
  return 0;
}

variable_types:
id
int [2]

variable_types:
i
unsigned int


decompiled_code:
__int64 sched_elect()
{
_QWORD *v0; // rbx
__int64 i; // rdi
_QWORD *v2; // rax
_QWORD *v4; // rax

v0 = (_QWORD *)thread_get_ready();
for ( i = *v0; *(_DWORD *)(*v0 + 16LL) != 2; i = *v0 )
v0 = (_QWORD *)v0[2];
v2 = (_QWORD *)v0[2];
if ( v2 )
{
thread_switch(i, *v2);
}
else
{
v4 = (_QWORD *)thread_get_ready();
thread_switch(*v0, *v4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rbx
__int64 i; // rdi
_QWORD *v2; // rax
_QWORD *v4; // rax

v0 = (_QWORD *)thread_get_ready();
for ( i = *v0; *(_DWORD *)(*v0 + 16LL) != 2; i = *v0 )
v0 = (_QWORD *)v0[2];
v2 = (_QWORD *)v0[2];
if ( v2 )
{
thread_switch(i, *v2);
}
else
{
v4 = (_QWORD *)thread_get_ready();
thread_switch(*v0, *v4);
}
return 0LL;
}

original_code:
int32_t sched_elect(void)
{
  list_s *threads = thread_get_ready();
  while (((thread_ctx_s *)(threads->e))->state != RUNNING)
    {
      threads = threads->next;
    }
  if (threads->next)
    {
      thread_switch((thread_ctx_s *)(threads->e),
      (thread_ctx_s *)(threads->next->e));
    }
  else
    {
      thread_switch((thread_ctx_s *)(threads->e),
      (thread_ctx_s *)(thread_get_ready()->e));
    }
  return 0;
}

canonical_original_code:
int sched_elect()
{
  struct _list_s *threads = thread_get_ready();
  while (((struct _thread_ctx_s *)(threads->e))->state != RUNNING)
    {
      threads = threads->next;
    }
  if (threads->next)
    {
      thread_switch((struct _thread_ctx_s *)(threads->e),
      (struct _thread_ctx_s *)(threads->next->e));
    }
  else
    {
      thread_switch((struct _thread_ctx_s *)(threads->e),
      (struct _thread_ctx_s *)(thread_get_ready()->e));
    }
  return 0;
}

variable_types: struct _list_s { void *e; struct _list_s *prev; struct _list_s *next; } *

user_defined_types: struct _thread_ctx_s { unsigned int id; unsigned int priority; unsigned char name[8]; enum _thread_state_e state; enum _thread_class_e class; unsigned int entry; unsigned int eip; unsigned int esp0; unsigned int esp3; struct _s_thread_tss tss; }

user_defined_types: enum _thread_state_e { DORMANT=0, READY=1, RUNNING=2, WAITING=3 }

user_defined_types: enum _thread_class_e { SYSTEM=0, USER=1 }

user_defined_types: struct _s_thread_tss { unsigned int esp0; unsigned int iomap; }


decompiled_code:
__int64 sched_launch()
{
return thread_launch();
}

canonical_decompiled_code:
__int64 func4()
{
return thread_launch();
}

original_code:
void sched_launch(void)
{
  thread_launch();
}

canonical_original_code:
void sched_launch()
{
  thread_launch();
}


decompiled_code:
__int64 serial_init()
{
int *v0; // rax

v0 = &serial;
do
*v0++ = 0;
while ( v0 != (int *)&unk_280 );
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int *v0; // rax

v0 = &serial;
do
*v0++ = 0;
while ( v0 != (int *)&unk_280 );
return 0LL;
}

original_code:
int32_t serial_init(void)
{
  uint32_t i;
  for (i = 0; i < 128; i++)
    {
      _serial[i] = false;
    }
  return 0;
}

canonical_original_code:
int serial_init()
{
  unsigned int i;
  for (i = 0; i < 128; i++)
    {
      _serial[i] = false;
    }
  return 0;
}


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

result = 0LL;
while ( serial[result] )
{
if ( ++result == 128 )
return 0xFFFFFFFFLL;
}
serial[(unsigned int)result] = 1;
return result;
}

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

result = 0LL;
while ( serial[result] )
{
if ( ++result == 128 )
return 0xFFFFFFFFLL;
}
serial[(unsigned int)result] = 1;
return result;
}

original_code:
int32_t serial_generate(void)
{
  uint32_t i;
  for (i = 0; i < 128; i++)
    {
      if (_serial[i] == false)
 {
   _serial[i] = true;
   return i;
 }
    }
  return -1;
}

canonical_original_code:
int serial_generate()
{
  unsigned int i;
  for (i = 0; i < 128; i++)
    {
      if (_serial[i] == false)
 {
   _serial[i] = true;
   return i;
 }
    }
  return -1;
}


decompiled_code:
__int64 __fastcall serial_free(unsigned int a1)
{
if ( a1 > 0x7F )
return 0xFFFFFFFFLL;
serial[a1] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
if ( a1 > 0x7F )
return 0xFFFFFFFFLL;
serial[a1] = 0;
return 0LL;
}

original_code:
int32_t serial_free(uint32_t i)
{
  if (i >= 128)
    return -1;
  _serial[i] = false;
  return 0;
}

canonical_original_code:
int serial_free(unsigned int i)
{
  if (i >= 128)
    return -1;
  _serial[i] = false;
  return 0;
}


decompiled_code:
__int64 isr_stage2_init()
{
int *v0; // rax

v0 = &_isr_stage2;
do
*v0++ = (unsigned int)isr_stage2_unhandled;
while ( v0 != (int *)(unsigned int)((_DWORD)&_isr_stage2 + 1024) );
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int *v0; // rax

v0 = &_isr_stage2;
do
*v0++ = (unsigned int)isr_stage2_unhandled;
while ( v0 != (int *)(unsigned int)((_DWORD)&_isr_stage2 + 1024) );
return 0LL;
}

original_code:
int32_t isr_stage2_init(void)
{
  uint32_t i;
  for (i = 0; i < 256; i++)
    {
      __isr_stage2[i] = (uint32_t) _isr_stage2_unhandled;
    }
  return 0;
}

canonical_original_code:
int isr_stage2_init()
{
  unsigned int i;
  for (i = 0; i < 256; i++)
    {
      __isr_stage2[i] = (unsigned int) _isr_stage2_unhandled;
    }
  return 0;
}


decompiled_code:
void __fastcall isr_stage2_bind(int a1, unsigned __int8 a2)
{
_isr_stage2[a2] = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1, unsigned __int8 a2)
{
_isr_stage2[a2] = a1;
}

original_code:
void isr_stage2_bind(uint32_t f,
     uint8_t index)
{
  __isr_stage2[index] = f;
}

canonical_original_code:
void isr_stage2_bind(unsigned int f, unsigned char index)
{
  __isr_stage2[index] = f;
}

variable_types:
f
unsigned int

variable_types:
index
unsigned char


decompiled_code:
int isr_stage2_pending()
{
apic_local_ack();
return printf("Int acked.\n");
}

canonical_decompiled_code:
int func3()
{
apic_local_ack();
return printf("Int acked.\n");
}

original_code:
void isr_stage2_pending(void)
{
  uint8_t pending_n;
  apic_local_ack();
  printf("Int acked.\n");
}

canonical_original_code:
void isr_stage2_pending()
{
  unsigned char pending_n;
  apic_local_ack();
  printf("Int acked.\n");
}


strlen

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
__int64 result; // rax

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
result = (unsigned int)(result + 1);
while ( a1[(unsigned int)result] );
return result;
}

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

if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
result = (unsigned int)(result + 1);
while ( a1[(unsigned int)result] );
return result;
}

original_code:
int32_t strlen(const char *str)
{
uint32_t i = 0;
  while (str[i])
    i++;
  return i;
}

canonical_original_code:
int strlen(char *str)
{
unsigned int i = 0;
  while (str[i])
    i++;
  return i;
}

variable_types:
str
char *


strcat

decompiled_code:
__int64 __fastcall strcat(_BYTE *a1, char *a2)
{
int v3; // edx
char v4; // si
int v5; // eax
int v6; // er9
int v7; // edx
int v8; // ecx

if ( *a1 )
{
v3 = 0;
do
++v3;
while ( a1[v3] );
}
else
{
v3 = 0;
}
v4 = *a2;
if ( v4 )
{
v5 = v3;
v6 = 1 - v3;
do
{
v7 = v6 + v5;
v8 = v5++;
a1[v8] = v4;
v4 = a2[v7];
}
while ( v4 );
}
return 0LL;
}

original_code:
int32_t strcat(char *dest,
         const char *src)
{
uint32_t i = 0;
uint32_t j = 0;
  while (dest[i])
    i++;
  while (src[j])
    dest[i++] = src[j++];
  return 0;
}

canonical_original_code:
int strcat(char *dest, char *src)
{
unsigned int i = 0;
unsigned int j = 0;
  while (dest[i])
    i++;
  while (src[j])
    dest[i++] = src[j++];
  return 0;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
j
unsigned int


strcpy

decompiled_code:
__int64 __fastcall strcpy(__int64 a1, char *a2)
{
char v2; // al
int v3; // ecx
__int64 v4; // rdx

if ( !a1 || !a2 )
return 4294967294LL;
v2 = *a2;
if ( !*a2 )
return 0LL;
v3 = 0;
v4 = 0LL;
do
{
*(_BYTE *)(a1 + v4) = v2;
v4 = (unsigned int)++v3;
v2 = a2[v3];
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2)
{
char v2; // al
int v3; // ecx
__int64 v4; // rdx

if ( !a1 || !a2 )
return 4294967294LL;
v2 = *a2;
if ( !*a2 )
return 0LL;
v3 = 0;
v4 = 0LL;
do
{
*(_BYTE *)(a1 + v4) = v2;
v4 = (unsigned int)++v3;
v2 = a2[v3];
}
while ( v2 );
return 0LL;
}

original_code:
int32_t strcpy(char *dest,
         const char *src)
{
uint32_t i = 0;
  if ((dest == 0) || (src == 0))
    return -2;
  while (src[i])
    {
      dest[i] = src[i];
      i++;
    }
  return 0;
}

canonical_original_code:
int strcpy(char *dest, char *src)
{
unsigned int i = 0;
  if ((dest == 0) || (src == 0))
    return -2;
  while (src[i])
    {
      dest[i] = src[i];
      i++;
    }
  return 0;
}


itoa

decompiled_code:
__int64 __fastcall itoa(char *a1, unsigned int a2, unsigned __int8 a3)
{
unsigned int v4; // edi
unsigned int v5; // esi
int v6; // ecx
char *v7; // rax
char v8; // cl
char *v9; // rdx

v4 = a2;
if ( a2 < a3 )
{
*a1 = byte_13F[a2];
v5 = 0;
}
else
{
v5 = 0;
do
{
v6 = v5++;
a1[v6] = byte_13F[v4 % a3];
v4 /= a3;
}
while ( v4 >= a3 );
a1[v5] = byte_13F[v4];
if ( v5 )
{
v7 = a1;
do
{
v8 = *v7;
v9 = &a1[v5 + (unsigned int)a1 - (unsigned int)v7];
*v7 = *v9;
*v9 = v8;
++v7;
}
while ( &a1[(v5 >> 1) + 1] != v7 );
}
}
return v5 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, unsigned int a2, unsigned __int8 a3)
{
unsigned int v4; // edi
unsigned int v5; // esi
int v6; // ecx
char *v7; // rax
char v8; // cl
char *v9; // rdx

v4 = a2;
if ( a2 < a3 )
{
*a1 = byte_13F[a2];
v5 = 0;
}
else
{
v5 = 0;
do
{
v6 = v5++;
a1[v6] = byte_13F[v4 % a3];
v4 /= a3;
}
while ( v4 >= a3 );
a1[v5] = byte_13F[v4];
if ( v5 )
{
v7 = a1;
do
{
v8 = *v7;
v9 = &a1[v5 + (unsigned int)a1 - (unsigned int)v7];
*v7 = *v9;
*v9 = v8;
++v7;
}
while ( &a1[(v5 >> 1) + 1] != v7 );
}
}
return v5 + 1;
}

original_code:
int32_t itoa(char *buffer,
       uint32_t n,
       uint8_t base_length)
{
  char c;
  char *base = "0123456789abcdef";
  uint32_t i = 0;
  uint32_t position = 0;
  while (n / base_length)
    {
      buffer[position++] = base[n % base_length];
      n /= base_length;
    }
  buffer[position] = base[n];
  while ((i <= (position / 2)) && (position > 0))
    {
      c = buffer[i];
      buffer[i] = buffer[position - i];
      buffer[position - i] = c;
      i++;
    }
  return ++position;
}

canonical_original_code:
int itoa(char *buffer, unsigned int n, unsigned char base_length)
{
  char c;
  char *base = "0123456789abcdef";
  unsigned int i = 0;
  unsigned int position = 0;
  while (n / base_length)
    {
      buffer[position++] = base[n % base_length];
      n /= base_length;
    }
  buffer[position] = base[n];
  while ((i <= (position / 2)) && (position > 0))
    {
      c = buffer[i];
      buffer[i] = buffer[position - i];
      buffer[position - i] = c;
      i++;
    }
  return ++position;
}

variable_types:
buffer
char *

variable_types:
n
unsigned int

variable_types: c char

variable_types:
base
char *

variable_types:
position
unsigned int


decompiled_code:
__int64 __fastcall sc_thread_stop(unsigned int a1)
{
printf("Stop thread: %d\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
printf("Stop thread: %d\n", a1);
return 0LL;
}

original_code:
int32_t sc_thread_stop(uint32_t thread_id)
{
  printf("Stop thread: %d\n", thread_id);
  return 0;
}

canonical_original_code:
int sc_thread_stop(unsigned int thread_id)
{
  printf("Stop thread: %d\n", thread_id);
  return 0;
}


decompiled_code:
__int64 sc_sleep()
{
sti();
hlt();
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
sti();
hlt();
return 0LL;
}

original_code:
int32_t sc_sleep(uint32_t delay)
{
  sti();
  hlt();
  return 0;
}

canonical_original_code:
int sc_sleep(unsigned int delay)
{
  sti();
  hlt();
  return 0;
}

variable_types:
delay
unsigned int


decompiled_code:
__int64 sc_init()
{
wrmsr(372LL, 8LL);
wrmsr(374LL, (unsigned int)&sc_hook);
printf("System-call hook set at @: %x\n", &sc_hook);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
wrmsr(372LL, 8LL);
wrmsr(374LL, (unsigned int)&sc_hook);
printf("System-call hook set at @: %x\n", &sc_hook);
return 0LL;
}

original_code:
int32_t sc_init(void)
{
  wrmsr(0x174, (1 << 3));
  wrmsr(0x176, (uint64_t) sc_hook & 0xffffffff);
  printf("System-call hook set at @: %x\n", (uint32_t)(sc_hook));
  return 0;
}

canonical_original_code:
int sc_init()
{
  wrmsr(0x174, (1 << 3));
  wrmsr(0x176, (unsigned long long) sc_hook & 0xffffffff);
  printf("System-call hook set at @: %x\n", (unsigned int)(sc_hook));
  return 0;
}


decompiled_code:
__int64 __fastcall sc_enter(int a1)
{
return ((__int64 (__fastcall *)(unsigned int))service_call[a1])(1u);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return ((__int64 (__fastcall *)(unsigned int))service_call[a1])(1u);
}

original_code:
int32_t sc_enter(uint32_t service_id,
                         uint32_t esp3,
                         uint32_t eip3)
{
  return _service_call[service_id](1);
}

canonical_original_code:
int sc_enter(unsigned int service_id, unsigned int esp3, unsigned int eip3)
{
  return _service_call[service_id](1);
}


decompiled_code:
__int64 apic_local_init()
{
int v0; // eax

v0 = rdmsr(27LL);
apic_local_base = v0 & 0xFFFFF000;
wrmsr(27LL, v0 | 0x800u);
printf("Before reserve: %x\n", (unsigned int)apic_local_base);
if ( (unsigned int)mmu_virt_page_reserve((unsigned int)apic_local_base, 538LL) )
{
printf("Can't reserve a page for the Local-APIC memory-mapped registers.\n");
__halt();
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax

v0 = rdmsr(27LL);
apic_local_base = v0 & 0xFFFFF000;
wrmsr(27LL, v0 | 0x800u);
printf("Before reserve: %x\n", (unsigned int)apic_local_base);
if ( (unsigned int)mmu_virt_page_reserve((unsigned int)apic_local_base, 538LL) )
{
printf("Can't reserve a page for the Local-APIC memory-mapped registers.\n");
__halt();
}
return 0LL;
}

original_code:
int32_t apic_local_init(void)
{
  uint32_t msr;
  msr = (uint32_t) rdmsr(0x1b);
  _apic_local_base = msr & ~0xfff;
  msr |= (1 << 11);
  wrmsr(0x1b, ((uint64_t) msr) & 0xffffffff);
  printf("Before reserve: %x\n", _apic_local_base);
  if (mmu_virt_page_reserve((vaddr_t) _apic_local_base,
       (1 << 1)
       | (1 << 3)
       | (1 << 4)
       | (1 << 9)))
    {
      printf("Can't reserve a page for the Local-APIC memory-mapped registers.\n");
      while (1) __asm__ __volatile__ ("hlt");;;
      return -1;
    }
  return 0;
}

canonical_original_code:
int apic_local_init()
{
  unsigned int msr;
  msr = (unsigned int) rdmsr(0x1b);
  _apic_local_base = msr & ~0xfff;
  msr |= (1 << 11);
  wrmsr(0x1b, ((unsigned long long) msr) & 0xffffffff);
  printf("Before reserve: %x\n", _apic_local_base);
  if (mmu_virt_page_reserve((void *) _apic_local_base,
       (1 << 1)
       | (1 << 3)
       | (1 << 4)
       | (1 << 9)))
    {
      printf("Can't reserve a page for the Local-APIC memory-mapped registers.\n");
      while (1) __asm__ __volatile__ ("hlt");;;
      return -1;
    }
  return 0;
}

variable_types:
msr
unsigned int


decompiled_code:
__int64 apic_local_ack()
{
return apic_local_wrreg(176);
}

canonical_decompiled_code:
__int64 func4()
{
return func1(176);
}

original_code:
void apic_local_ack(void)
{
  _apic_local_wrreg(0xb0, 0);
}

canonical_original_code:
void apic_local_ack()
{
  _apic_local_wrreg(0xb0, 0);
}


decompiled_code:
__int64 apic_local_timer_config()
{
apic_local_wrreg(992);
apic_local_wrreg(896);
apic_local_wrreg(912);
apic_local_rdreg(800);
apic_local_wrreg(800);
return 0LL;
}

original_code:
int32_t apic_local_timer_config(uint32_t initial_count)
{
  uint32_t lvt_timer;
  _apic_local_wrreg(0x3e0, 3);
  _apic_local_wrreg(0x380, initial_count);
  _apic_local_wrreg(0x390, initial_count);
  lvt_timer = _apic_local_rdreg(0x320);
  lvt_timer |= (1 << 17);
  lvt_timer = (lvt_timer & ~0xff) | 32;
  lvt_timer &= ~(1 << 16);
  _apic_local_wrreg(0x320, lvt_timer);
  return 0;
}

canonical_original_code:
int apic_local_timer_config(unsigned int initial_count)
{
  unsigned int lvt_timer;
  _apic_local_wrreg(0x3e0, 3);
  _apic_local_wrreg(0x380, initial_count);
  _apic_local_wrreg(0x390, initial_count);
  lvt_timer = _apic_local_rdreg(0x320);
  lvt_timer |= (1 << 17);
  lvt_timer = (lvt_timer & ~0xff) | 32;
  lvt_timer &= ~(1 << 16);
  _apic_local_wrreg(0x320, lvt_timer);
  return 0;
}


decompiled_code:
__int64 __fastcall apic_local_set_task_priority(unsigned __int8 a1)
{
if ( a1 > 0xFu )
return 0xFFFFFFFFLL;
apic_local_wrreg(128);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
if ( a1 > 0xFu )
return 0xFFFFFFFFLL;
func1(128);
return 0LL;
}

original_code:
int32_t apic_local_set_task_priority(uint8_t task_priority)
{
  if (task_priority > 15)
    {
      return -1;
    }
  _apic_local_wrreg(0x80,
      (uint32_t) task_priority << 4);
  return 0;
}

canonical_original_code:
int apic_local_set_task_priority(unsigned char task_priority)
{
  if (task_priority > 15)
    {
      return -1;
    }
  _apic_local_wrreg(0x80,
      (unsigned int) task_priority << 4);
  return 0;
}


decompiled_code:
char apic_local_get_task_priority()
{
return (unsigned __int8)apic_local_rdreg(128) >> 4;
}

canonical_decompiled_code:
char func7()
{
return (unsigned __int8)func0(128) >> 4;
}

original_code:
uint8_t apic_local_get_task_priority(void)
{
  return (uint8_t)((_apic_local_rdreg(0x80) >> 4) & 0xf);
}

canonical_original_code:
unsigned char apic_local_get_task_priority()
{
  return (unsigned char)((_apic_local_rdreg(0x80) >> 4) & 0xf);
}

return_type: unsigned char


decompiled_code:
char apic_local_get_proc_priority()
{
return (unsigned __int8)apic_local_rdreg(160) >> 4;
}

canonical_decompiled_code:
char func8()
{
return (unsigned __int8)func0(160) >> 4;
}

original_code:
uint8_t apic_local_get_proc_priority(void)
{
  return (uint8_t)((_apic_local_rdreg(0xa0) >> 4) & 0xf);
}

canonical_original_code:
unsigned char apic_local_get_proc_priority()
{
  return (unsigned char)((_apic_local_rdreg(0xa0) >> 4) & 0xf);
}