maxBordure

decompiled_code:
__int64 __fastcall maxBordure(__int64 a1, __int64 a2, int a3)
{
size_t v4; // r14
_QWORD *v5; // rax
_QWORD *v6; // r13
unsigned int v7; // ebx
void *v9; // rax
__int64 i; // rax
int v11; // [rsp+0h] [rbp-48h] BYREF
__int64 v12; // [rsp+8h] [rbp-40h]
_QWORD *v13; // [rsp+10h] [rbp-38h]

v11 = 0;
v12 = 0LL;
v4 = 8LL * a3;
v5 = malloc(v4);
v13 = v5;
if ( !v5 )
_assert_fail("G.mat != NULL", "strategie_coloriage.c", 0x11Du, "maxBordure");
v6 = v5;
if ( a3 > 0 )
{
v9 = malloc(v4);
*v6 = v9;
if ( v9 )
{
for ( i = 0LL; ; i += 8LL )
*(_QWORD *)(*v13 + i) = 0LL;
}
_assert_fail("G.mat[i]", "strategie_coloriage.c", 0x121u, "maxBordure");
}
cree_graphe_zone(a2, (unsigned int)a3, &v11);
if ( v11 <= 0 )
return 0;
v7 = 0;
do
{
update_bordure_graphe(&v11, a2, *(unsigned int *)(a1 + 4));
++v7;
}
while ( v11 > 0 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
size_t v4; // r14
_QWORD *v5; // rax
_QWORD *v6; // r13
unsigned int v7; // ebx
void *v9; // rax
__int64 i; // rax
int v11; // [rsp+0h] [rbp-48h] BYREF
__int64 v12; // [rsp+8h] [rbp-40h]
_QWORD *v13; // [rsp+10h] [rbp-38h]

v11 = 0;
v12 = 0LL;
v4 = 8LL * a3;
v5 = malloc(v4);
v13 = v5;
if ( !v5 )
_assert_fail("G.mat != NULL", "strategie_coloriage.c", 0x11Du, "maxBordure");
v6 = v5;
if ( a3 > 0 )
{
v9 = malloc(v4);
*v6 = v9;
if ( v9 )
{
for ( i = 0LL; ; i += 8LL )
*(_QWORD *)(*v13 + i) = 0LL;
}
_assert_fail("G.mat[i]", "strategie_coloriage.c", 0x121u, "maxBordure");
}
cree_graphe_zone(a2, (unsigned int)a3, &v11);
if ( v11 <= 0 )
return 0;
v7 = 0;
do
{
update_bordure_graphe(&v11, a2, *(unsigned int *)(a1 + 4));
++v7;
}
while ( v11 > 0 );
return v7;
}

original_code:
int maxBordure(Grille *Grille, int **M, int nbCases)
{
 int i , j, cpt = 0;
 Graphe_zone G;
 G.nbsom = 0;
 G.som = ((void *)0);
 G.mat = (Sommet ***) malloc(sizeof(Sommet**)*nbCases);
 ((void) sizeof ((G.mat != ((void *)0)) ? 1 : 0), __extension__ ({ if (G.mat != ((void *)0)) ; else __assert_fail ("G.mat != NULL", "strategie_coloriage.c", 285, __extension__ __PRETTY_FUNCTION__); }));
 for(i = 0; i < nbCases; i++) {
   G.mat[i] = (Sommet **) malloc(sizeof(Sommet*)*nbCases);
   ((void) sizeof ((G.mat[i]) ? 1 : 0), __extension__ ({ if (G.mat[i]) ; else __assert_fail ("G.mat[i]", "strategie_coloriage.c", 289, __extension__ __PRETTY_FUNCTION__); }));
   for(j = 0; i < nbCases; j++)
     G.mat[i][j] = ((void *)0);
 }
 cree_graphe_zone(M, nbCases, &G);
 while (G.nbsom > 0) {
  update_bordure_graphe(&G, M, Grille->nbcl);
  cpt++;
 }
 return cpt;
}

canonical_original_code:
int maxBordure(struct grille *Grille, int **M, int nbCases)
{
 int i; int j; int cpt = 0;
 struct graphe_zone G;
 G.nbsom = 0;
 G.som = ((void *)0);
 G.mat = (struct sommet ***) malloc(sizeof(struct sommet **)*nbCases);
 ((void) sizeof ((G.mat != ((void *)0)) ? 1 : 0), __extension__ ({ if (G.mat != ((void *)0)) ; else __assert_fail ("G.mat != NULL", "strategie_coloriage.c", 285, __extension__ __PRETTY_FUNCTION__); }));
 for(i = 0; i < nbCases; i++) {
   G.mat[i] = (struct sommet **) malloc(sizeof(struct sommet *)*nbCases);
   ((void) sizeof ((G.mat[i]) ? 1 : 0), __extension__ ({ if (G.mat[i]) ; else __assert_fail ("G.mat[i]", "strategie_coloriage.c", 289, __extension__ __PRETTY_FUNCTION__); }));
   for(j = 0; i < nbCases; j++)
     G.mat[i][j] = ((void *)0);
 }
 cree_graphe_zone(M, nbCases, &G);
 while (G.nbsom > 0) {
  update_bordure_graphe(&G, M, Grille->nbcl);
  cpt++;
 }
 return cpt;
}

variable_types: struct grille { int nbcase; int nbcl; int taille_pixel; int cas_aff; int taille_case; int modulo; unsigned int *T_coul; } *

variable_types:
M
int **

variable_types: struct graphe_zone { int nbsom; struct cellule_som { struct sommet { int num; int cl; struct Liste_C { int i; int j; struct Liste_C *next; } *cases; int nbcase_som; struct cellule_som *sommet_adj; int marque; struct sommet *pere; } *sommet; struct cellule_som *suiv; } *som; struct sommet ***mat; }

user_defined_types: struct graphe_zone { int nbsom; struct cellule_som *som; struct sommet ***mat; }

user_defined_types: struct sommet { int num; int cl; struct Liste_C *cases; int nbcase_som; struct cellule_som *sommet_adj; int marque; struct sommet *pere; }

user_defined_types: struct cellule_som { struct sommet *sommet; struct cellule_som *suiv; }


StrategieLarge

repo: tshikaboom/flood-it

decompiled_code:
__int64 __fastcall StrategieLarge(__int64 a1, __int64 a2, int a3)
{
size_t v4; // r13
__int64 v5; // rbx
__int64 v6; // rbp
void **v7; // r12
__int64 v8; // rcx
__int64 v9; // rax
int v11[100]; // [rsp+10h] [rbp-1E8h] BYREF
int v12; // [rsp+1A0h] [rbp-58h] BYREF
__int64 v13; // [rsp+1A8h] [rbp-50h]
char *v14; // [rsp+1B0h] [rbp-48h]

memset(v11, 0, sizeof(v11));
v13 = 0LL;
v12 = 0;
v4 = 8LL * a3;
v14 = (char *)malloc(v4);
if ( a3 > 0 )
{
v5 = 8LL * (unsigned int)a3;
v6 = 0LL;
do
{
v7 = (void **)&v14[v6];
*v7 = malloc(v4);
v6 += 8LL;
}
while ( v5 != v6 );
v8 = 0LL;
do
{
v9 = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)&v14[v8] + v9) = 0LL;
v9 += 8LL;
}
while ( v9 != v5 );
v8 += 8LL;
}
while ( v8 != v5 );
}
if ( !v14 )
_assert_fail("G.mat != NULL", "strategie_coloriage.c", 0xFAu, "StrategieLarge");
cree_graphe_zone(a2, (unsigned int)a3, &v12);
if ( plusCourtChemin(&v12, (unsigned int)a3) )
{
while ( 1 )
;
}
update_bordure_graphe(&v12, a2, (unsigned int)v11[0]);
return (unsigned int)maxBordure(a1, a2, a3) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, int a3)
{
size_t v4; // r13
__int64 v5; // rbx
__int64 v6; // rbp
void **v7; // r12
__int64 v8; // rcx
__int64 v9; // rax
int v11[100]; // [rsp+10h] [rbp-1E8h] BYREF
int v12; // [rsp+1A0h] [rbp-58h] BYREF
__int64 v13; // [rsp+1A8h] [rbp-50h]
char *v14; // [rsp+1B0h] [rbp-48h]

memset(v11, 0, sizeof(v11));
v13 = 0LL;
v12 = 0;
v4 = 8LL * a3;
v14 = (char *)malloc(v4);
if ( a3 > 0 )
{
v5 = 8LL * (unsigned int)a3;
v6 = 0LL;
do
{
v7 = (void **)&v14[v6];
*v7 = malloc(v4);
v6 += 8LL;
}
while ( v5 != v6 );
v8 = 0LL;
do
{
v9 = 0LL;
do
{
*(_QWORD *)(*(_QWORD *)&v14[v8] + v9) = 0LL;
v9 += 8LL;
}
while ( v9 != v5 );
v8 += 8LL;
}
while ( v8 != v5 );
}
if ( !v14 )
_assert_fail("G.mat != NULL", "strategie_coloriage.c", 0xFAu, "StrategieLarge");
cree_graphe_zone(a2, (unsigned int)a3, &v12);
if ( plusCourtChemin(&v12, (unsigned int)a3) )
{
while ( 1 )
;
}
update_bordure_graphe(&v12, a2, (unsigned int)v11[0]);
return (unsigned int)func5(a1, a2, a3) + 1;
}

original_code:
int StrategieLarge(Grille* Grille, int **M, int nbCases)
{
 Graphe_zone G;
 Cellule_som *path = ((void *)0);
 int i, j, couleurs[100] = {0};
 int cpt = 0;
 G.som = ((void *)0);
 G.nbsom = 0;
 G.mat = ((void *)0);
 G.mat = (Sommet ***) malloc(nbCases*sizeof(Sommet **));
 for(i=0; i<nbCases; i++)
   G.mat[i] = (Sommet **) malloc(nbCases*sizeof(Sommet *));
 for (i=0; i<nbCases; i++)
   for (j=0; j<nbCases; j++)
     G.mat[i][j] = ((void *)0);
 ((void) sizeof ((G.mat != ((void *)0)) ? 1 : 0), __extension__ ({ if (G.mat != ((void *)0)) ; else __assert_fail ("G.mat != NULL", "strategie_coloriage.c", 250, __extension__ __PRETTY_FUNCTION__); }));
 cree_graphe_zone(M, nbCases, &G);
 path = plusCourtChemin(&G, nbCases);
 for(i = 0; path != ((void *)0); i++)
   couleurs[i] = (path->sommet)->cl;
 for(; i >= 0; (i--, cpt++))
   update_bordure_graphe(&G, M, couleurs[i]);
 cpt += maxBordure(Grille, M, nbCases);
 return cpt;
}

canonical_original_code:
int StrategieLarge(struct grille *Grille, int **M, int nbCases)
{
 struct graphe_zone G;
 struct cellule_som *path = ((void *)0);
 int i; int j; int couleurs[100] = {0};
 int cpt = 0;
 G.som = ((void *)0);
 G.nbsom = 0;
 G.mat = ((void *)0);
 G.mat = (struct sommet ***) malloc(nbCases*sizeof(struct sommet **));
 for(i=0; i<nbCases; i++)
   G.mat[i] = (struct sommet **) malloc(nbCases*sizeof(struct sommet *));
 for (i=0; i<nbCases; i++)
   for (j=0; j<nbCases; j++)
     G.mat[i][j] = ((void *)0);
 ((void) sizeof ((G.mat != ((void *)0)) ? 1 : 0), __extension__ ({ if (G.mat != ((void *)0)) ; else __assert_fail ("G.mat != NULL", "strategie_coloriage.c", 250, __extension__ __PRETTY_FUNCTION__); }));
 cree_graphe_zone(M, nbCases, &G);
 path = plusCourtChemin(&G, nbCases);
 for(i = 0; path != ((void *)0); i++)
   couleurs[i] = (path->sommet)->cl;
 for(; i >= 0; (i--, cpt++))
   update_bordure_graphe(&G, M, couleurs[i]);
 cpt += maxBordure(Grille, M, nbCases);
 return cpt;
}

variable_types: nbCases int

variable_types: struct cellule_som { struct sommet { int num; int cl; struct Liste_C { int i; int j; struct Liste_C *next; } *cases; int nbcase_som; struct cellule_som *sommet_adj; int marque; struct sommet *pere; } *sommet; struct cellule_som *suiv; } *

variable_types: i int

variable_types: j int

variable_types:
couleurs
int [100]

variable_types: cpt int

return_type: int

user_defined_types: struct grille { int nbcase; int nbcl; int taille_pixel; int cas_aff; int taille_case; int modulo; unsigned int *T_coul; }


original_code:
void Grille_init(int nbcase, int nbcl, int taille_pixel,Grille **G){
  int i;
  unsigned int genecl = 10101;
  (*G)=(Grille*) malloc(sizeof(Grille));
  (*G)->nbcase=nbcase;
  (*G)->nbcl=nbcl;
  (*G)->taille_pixel=taille_pixel;
  (*G)->T_coul=(Uint32*) malloc(sizeof(Uint32)*nbcl);
  for (i=0;i<32;i++){
    genecl=genecl*(i+i+1);
    genecl=(genecl^(0xffffff))>>2;
  }
  for (i=0;i<nbcl;i++){
    genecl=genecl*(i+i+1);
    genecl=(genecl^(0xffffff))>>2;
    (*G)->T_coul[i]=genecl;
  }
  if ((taille_pixel*1.0)/nbcase>1){
    (*G)->cas_aff=0;
    (*G)->taille_case=taille_pixel/nbcase;
  }
  else{
    (*G)->cas_aff=1;
    (*G)->modulo=nbcase/taille_pixel;
  }
}

canonical_original_code:
void Grille_init(int nbcase, int nbcl, int taille_pixel, struct grille **G){
  int i;
  unsigned int genecl = 10101;
  (*G)=(struct grille *) malloc(sizeof(Grille));
  (*G)->nbcase=nbcase;
  (*G)->nbcl=nbcl;
  (*G)->taille_pixel=taille_pixel;
  (*G)->T_coul=(unsigned int *) malloc(sizeof(Uint32)*nbcl);
  for (i=0;i<32;i++){
    genecl=genecl*(i+i+1);
    genecl=(genecl^(0xffffff))>>2;
  }
  for (i=0;i<nbcl;i++){
    genecl=genecl*(i+i+1);
    genecl=(genecl^(0xffffff))>>2;
    (*G)->T_coul[i]=genecl;
  }
  if ((taille_pixel*1.0)/nbcase>1){
    (*G)->cas_aff=0;
    (*G)->taille_case=taille_pixel/nbcase;
  }
  else{
    (*G)->cas_aff=1;
    (*G)->modulo=nbcase/taille_pixel;
  }
}

variable_types: nbcase int

variable_types: nbcl int

variable_types: struct grille { int nbcase; int nbcl; int taille_pixel; int cas_aff; int taille_case; int modulo; unsigned int *T_coul; } **

variable_types:
genecl
unsigned int

return_type: void


decompiled_code:
void __fastcall Grille_free(void **a1)
{
free(*((void **)*a1 + 3));
free(*a1);
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
free(*((void **)*a1 + 3));
free(*a1);
}

original_code:
void Grille_free(Grille **G){
  free((*G)->T_coul);
  free(*G);
}

canonical_original_code:
void Grille_free(struct grille **G){
  free((*G)->T_coul);
  free(*G);
}


decompiled_code:
int __fastcall Grille_ouvre_fenetre(__int64 a1)
{
int result; // eax
__int64 v2; // rax

if ( (unsigned int)SDL_Init(32LL) )
{
v2 = SDL_GetError();
result = fprintf(stderr, format, v2);
}
else
{
atexit((void (*)(void))&SDL_Quit);
SDL_SetVideoMode(*(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 8), 0LL, 1073742081LL);
SDL_EnableKeyRepeat(7LL, 41LL);
result = SDL_WM_SetCaption("Jeu d'inondation", 0LL);
}
return result;
}

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

if ( (unsigned int)SDL_Init(32LL) )
{
v2 = SDL_GetError();
result = fprintf(stderr, format, v2);
}
else
{
atexit((void (*)(void))&SDL_Quit);
SDL_SetVideoMode(*(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 8), 0LL, 1073742081LL);
SDL_EnableKeyRepeat(7LL, 41LL);
result = SDL_WM_SetCaption("Jeu d'inondation", 0LL);
}
return result;
}

original_code:
void Grille_ouvre_fenetre(Grille *G){
  Uint32 flags=0x00000001 | 0x00000100 | 0x40000000;
  if(SDL_Init(0x00000020) != 0) {
    fprintf(stderr,
     "Erreur: ne peut pas initialiser le système graphique (\"%s\").\n",
     SDL_GetError());
    return;
  }
  atexit(SDL_Quit);
  SDL_SetVideoMode(G->taille_pixel, G->taille_pixel, 0, flags);
  SDL_EnableKeyRepeat(30 / 4,
        500 / 12);
  SDL_WM_SetCaption("Jeu d'inondation", 0);
}

canonical_original_code:
void Grille_ouvre_fenetre(struct grille *G){
  unsigned int flags = 0x00000001 | 0x00000100 | 0x40000000;
  if(SDL_Init(0x00000020) != 0) {
    fprintf(stderr,
     "Erreur: ne peut pas initialiser le système graphique (\"%s\").\n",
     SDL_GetError());
    return;
  }
  atexit(SDL_Quit);
  SDL_SetVideoMode(G->taille_pixel, G->taille_pixel, 0, flags);
  SDL_EnableKeyRepeat(30 / 4,
        500 / 12);
  SDL_WM_SetCaption("Jeu d'inondation", 0);
}

variable_types:
flags
unsigned int


decompiled_code:
void Grille_ferme_fenetre()
{
SDL_Quit();
}

canonical_decompiled_code:
void func3()
{
SDL_Quit();
}


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

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

original_code:
int pile_vide(Pile p)
{
  return p.e == ((void *)0);
}

canonical_original_code:
int pile_vide(struct Pile p)
{
  return p.e == ((void *)0);
}

variable_types: struct Pile { struct Element_pile { int i; int j; struct Element_pile *next; } *e; }


depile

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

result = *a1;
if ( !*a1 )
{
fwrite("Pile vide!\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
*a1 = *(_QWORD *)(result + 8);
return result;
}

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

result = *a1;
if ( !*a1 )
{
fwrite("Pile vide!\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
*a1 = *(_QWORD *)(result + 8);
return result;
}

original_code:
Element* depile(Pile *p)
{
  if (p->e == ((void *)0)) {
      fprintf(stderr, "Pile vide!\n");
      exit(1);
    }
  Element *tmp = p->e;
  p->e = tmp->next;
  return tmp;
}

canonical_original_code:
struct Element_pile *depile(struct Pile *p)
{
  if (p->e == ((void *)0)) {
      fprintf(stderr, "Pile vide!\n");
      exit(1);
    }
  struct Element_pile *tmp = p->e;
  p->e = tmp->next;
  return tmp;
}

variable_types: struct Pile { struct Element_pile *e; } *

variable_types: struct Element_pile { int i; int j; struct Element_pile *next; } *


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

result = *a1;
if ( !*a1 )
return 0LL;
while ( *(_DWORD *)result != a2 || *(_DWORD *)(result + 4) != a3 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

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

result = *a1;
if ( !*a1 )
return 0LL;
while ( *(_DWORD *)result != a2 || *(_DWORD *)(result + 4) != a3 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int pile_existe(Pile *l, int i, int j)
{
  Element *elem = l->e;
  while (elem != ((void *)0)) {
    if (elem->i == i && elem->j == j)
      return 1;
    elem = elem->next;
  }
  return 0;
}

canonical_original_code:
int pile_existe(struct Pile *l, int i, int j)
{
  struct Element_pile *elem = l->e;
  while (elem != ((void *)0)) {
    if (elem->i == i && elem->j == j)
      return 1;
    elem = elem->next;
  }
  return 0;
}

variable_types: struct Pile { struct Element_pile { int i; int j; struct Element_pile *next; } *e; } *


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

result = malloc(0x10uLL);
if ( !result )
exit(1);
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
if ( !result )
exit(1);
result[1] = 0LL;
return result;
}

original_code:
Liste_case *liste_init()
{
  Liste_case *e = ((void *)0);
  e = (Liste_case*) malloc(sizeof(Liste_case));
  if (e == ((void *)0))
    exit(1);
  e->next=((void *)0);
  return e;
}

canonical_original_code:
struct Liste_C *liste_init()
{
  struct Liste_C *e = ((void *)0);
  e = (struct Liste_C *) malloc(sizeof(Liste_case));
  if (e == ((void *)0))
    exit(1);
  e->next=((void *)0);
  return e;
}

variable_types: struct Liste_C { int i; int j; struct Liste_C *next; } *


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

original_code:
int liste_vide(Liste_case *l)
{
  return (l == ((void *)0)) ;
}

canonical_original_code:
int liste_vide(struct Liste_C *l)
{
  return (l == ((void *)0)) ;
}

user_defined_types: struct Liste_C { int i; int j; struct Liste_C *next; }


decompiled_code:
__int64 __fastcall liste_existe(__int64 a1, int a2, int a3)
{
for ( ; a1; a1 = *(_QWORD *)(a1 + 8) )
{
if ( *(_DWORD *)a1 == a2 && *(_DWORD *)(a1 + 4) == a3 )
break;
}
return 1LL;
}

original_code:
int liste_existe(Liste_case *l, int i, int j)
{
  Liste_case *tmp = l;
  while (tmp) {
    if (tmp->i == i && tmp->j == j)
      return 1;
    tmp = tmp->next;
  }
  return 1;
}

canonical_original_code:
int liste_existe(struct Liste_C *l, int i, int j)
{
  struct Liste_C *tmp = l;
  while (tmp) {
    if (tmp->i == i && tmp->j == j)
      return 1;
    tmp = tmp->next;
  }
  return 1;
}


decompiled_code:
int __fastcall liste_affiche(unsigned int *a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d %d\n", *i, i[1]);
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("%d %d\n", *i, i[1]);
return result;
}

original_code:
void liste_affiche(Liste_case *L)
{
  Liste_case *l = L;
  while(l != ((void *)0)) {
    printf("%d %d\n", l->i, l->j);
    l = l->next;
  }
}

canonical_original_code:
void liste_affiche(struct Liste_C *L)
{
  struct Liste_C *l = L;
  while(l != ((void *)0)) {
    printf("%d %d\n", l->i, l->j);
    l = l->next;
  }
}


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

for ( i = a1; i; i = *(_QWORD *)(i + 8) )
*a2 = (__int64)liste_ajoute(*a2, *(_DWORD *)i, *(_DWORD *)(i + 4));
}

original_code:
void liste_copy(Liste_case *old, Liste_case **new)
{
  while(old != ((void *)0)) {
    *new = liste_ajoute( *new, old->i, old->j);
    old = old->next;
  }
}

canonical_original_code:
void liste_copy(struct Liste_C *old, struct Liste_C **new)
{
  while(old != ((void *)0)) {
    *new = liste_ajoute( *new, old->i, old->j);
    old = old->next;
  }
}

variable_types:
new
struct Liste_C **


original_code:
void trouve_zone(int **M, int i, int j, Sommet *s, Graphe_zone *G, int nbCases)
{
  Pile p;
  Element *e;
  s->cl = M[i][j];
  detruit_liste_sommet(s->sommet_adj);
  s->nbcase_som = 0;
  init_pile(&p);
  empile(&p, i, j);
  while (!pile_vide(p)) {
    e = depile(&p);
    i = e->i, j = e->j;
    if ((e->j+1 < nbCases) &&
 (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i, e->j+1))) {
      liste_ajoute(s->cases, e->i, e->j+1);
      s->nbcase_som++;
      empile(&p, e->i, e->j+1);
    }
    if ((e->j-1 >= 0) &&
 (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i, e->j-1))) {
      liste_ajoute(s->cases, e->i, e->j-1);
      s->nbcase_som++;
      empile(&p, e->i, e->j-1);
    }
    if ((e->i+1 < nbCases) &&
 (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i+1, e->j))) {
      liste_ajoute(s->cases, e->i+1, e->j);
      s->nbcase_som++;
      empile(&p, e->i+1, e->j);
    }
    if ((e->i-1 >= 0) && (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i-1, e->j))) {
      liste_ajoute((s->cases), e->i-1, e->j);
      s->nbcase_som++;
      empile(&p, e->i-1, e->j);
    }
    G->mat[i][j] = s;
    G->som++;
    free(e);
  }
}

canonical_original_code:
void trouve_zone(int **M, int i, int j, struct sommet *s, struct graphe_zone *G, int nbCases)
{
  struct Pile p;
  struct Element_pile *e;
  s->cl = M[i][j];
  detruit_liste_sommet(s->sommet_adj);
  s->nbcase_som = 0;
  init_pile(&p);
  empile(&p, i, j);
  while (!pile_vide(p)) {
    e = depile(&p);
    i = e->i, j = e->j;
    if ((e->j+1 < nbCases) &&
 (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i, e->j+1))) {
      liste_ajoute(s->cases, e->i, e->j+1);
      s->nbcase_som++;
      empile(&p, e->i, e->j+1);
    }
    if ((e->j-1 >= 0) &&
 (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i, e->j-1))) {
      liste_ajoute(s->cases, e->i, e->j-1);
      s->nbcase_som++;
      empile(&p, e->i, e->j-1);
    }
    if ((e->i+1 < nbCases) &&
 (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i+1, e->j))) {
      liste_ajoute(s->cases, e->i+1, e->j);
      s->nbcase_som++;
      empile(&p, e->i+1, e->j);
    }
    if ((e->i-1 >= 0) && (M[e->i][e->j] == s->cl) &&
 (!pile_existe(&p, e->i, e->j+1)) &&
 (!liste_existe(s->cases, e->i-1, e->j))) {
      liste_ajoute((s->cases), e->i-1, e->j);
      s->nbcase_som++;
      empile(&p, e->i-1, e->j);
    }
    G->mat[i][j] = s;
    G->som++;
    free(e);
  }
}

variable_types:
M
int **

variable_types: struct sommet { int num; int cl; struct Liste_C { int i; int j; struct Liste_C *next; } *cases; int nbcase_som; struct cellule_som { struct sommet *sommet; struct cellule_som *suiv; } *sommet_adj; int marque; struct sommet *pere; } *

variable_types: struct graphe_zone { int nbsom; struct cellule_som *som; struct sommet ***mat; } *

variable_types: nbCases int

user_defined_types: struct Element_pile { int i; int j; struct Element_pile *next; }


original_code:
void cree_graphe_zone(int** M, int nbCases, Graphe_zone *G)
{
  int i, j;
  Sommet *s = ((void *)0), *s2 = ((void *)0);
  for (i=0; i<nbCases; i++)
    for (j=0; j<nbCases; j++)
      if (G->mat[i][j] == ((void *)0)) {
 s = (Sommet *) malloc(sizeof(Sommet));
 s->nbcase_som = 0;
 s->cases = liste_init();
 s->cases->i = i;
 s->cases->j = j;
 s->sommet_adj = ((void *)0);
 G->mat[i][j] = s;
 (G->nbsom)++;
 G->som = ajoute_liste_sommet(s, G->som);
 trouve_zone(M, i, j, s, G, nbCases);
      }
  for (i=0; i < nbCases; i++)
    for(j=0; j < (nbCases - 1); j++) {
      s = G->mat[i][j];
      s2 = G->mat[i][j+1];
      if (s == s2 || adjacent(s, s2) != 0)
 continue;
      ajoute_voisin(s, s2);
    }
}

canonical_original_code:
void cree_graphe_zone(int **M, int nbCases, struct graphe_zone *G)
{
  int i; int j;
  struct sommet *s = ((void *)0); struct sommet *s2 = ((void *)0);
  for (i=0; i<nbCases; i++)
    for (j=0; j<nbCases; j++)
      if (G->mat[i][j] == ((void *)0)) {
 s = (struct sommet *) malloc(sizeof(Sommet));
 s->nbcase_som = 0;
 s->cases = liste_init();
 s->cases->i = i;
 s->cases->j = j;
 s->sommet_adj = ((void *)0);
 G->mat[i][j] = s;
 (G->nbsom)++;
 G->som = ajoute_liste_sommet(s, G->som);
 trouve_zone(M, i, j, s, G, nbCases);
      }
  for (i=0; i < nbCases; i++)
    for(j=0; j < (nbCases - 1); j++) {
      s = G->mat[i][j];
      s2 = G->mat[i][j+1];
      if (s == s2 || adjacent(s, s2) != 0)
 continue;
      ajoute_voisin(s, s2);
    }
}

variable_types: struct graphe_zone { int nbsom; struct cellule_som { struct sommet { int num; int cl; struct Liste_C { int i; int j; struct Liste_C *next; } *cases; int nbcase_som; struct cellule_som *sommet_adj; int marque; struct sommet *pere; } *sommet; struct cellule_som *suiv; } *som; struct sommet ***mat; } *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall affichage_graphe(__int64 a1, int a2)
{
__int64 j; // rbp
unsigned int **v3; // rbx
__int64 result; // rax
__int64 i; // [rsp+0h] [rbp-40h]

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; result = ++i )
{
for ( j = 0LL; j != a2; ++j )
{
v3 = *(unsigned int ***)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * i) + 8 * j) + 24LL);
printf("Dans le sommet [%d][%d], on a les noeuds ", (unsigned int)i, (unsigned int)j);
for ( ; v3; v3 = (unsigned int **)v3[1] )
printf("%d ", **v3);
putchar(10);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 j; // rbp
unsigned int **v3; // rbx
__int64 result; // rax
__int64 i; // [rsp+0h] [rbp-40h]

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; result = ++i )
{
for ( j = 0LL; j != a2; ++j )
{
v3 = *(unsigned int ***)(*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * i) + 8 * j) + 24LL);
printf("Dans le sommet [%d][%d], on a les noeuds ", (unsigned int)i, (unsigned int)j);
for ( ; v3; v3 = (unsigned int **)v3[1] )
printf("%d ", **v3);
putchar(10);
}
}
}
return result;
}

original_code:
void affichage_graphe(Graphe_zone *G, int nbCases)
{
  int i=0, j=0;
  Cellule_som *parcours;
  for (i=0; i<nbCases; i++)
    for (j=0; j<nbCases; j++) {
      parcours = G->mat[i][j]->sommet_adj;
      printf("Dans le sommet [%d][%d], on a les noeuds ", i, j);
      while (parcours) {
 printf("%d ", parcours->sommet->num);
 parcours = parcours->suiv;
      }
      printf("\n");
    }
}

canonical_original_code:
void affichage_graphe(struct graphe_zone *G, int nbCases)
{
  int i = 0; int j = 0;
  struct cellule_som *parcours;
  for (i=0; i<nbCases; i++)
    for (j=0; j<nbCases; j++) {
      parcours = G->mat[i][j]->sommet_adj;
      printf("Dans le sommet [%d][%d], on a les noeuds ", i, j);
      while (parcours) {
 printf("%d ", parcours->sommet->num);
 parcours = parcours->suiv;
      }
      printf("\n");
    }
}

variable_types: struct cellule_som { struct sommet { int num; int cl; struct Liste_C { int i; int j; struct Liste_C *next; } *cases; int nbcase_som; struct cellule_som *sommet_adj; int marque; struct sommet *pere; } *sommet; struct cellule_som *suiv; } *


decompiled_code:
__int64 __fastcall sommet_dans_bordure(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(*(_QWORD *)(a2 + 16) + 8LL * *(int *)(*(_QWORD *)a1 + 4LL));
if ( !result )
return 0LL;
while ( **(_DWORD **)result != **(_DWORD **)a1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

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

result = *(_QWORD *)(*(_QWORD *)(a2 + 16) + 8LL * *(int *)(*(_QWORD *)a1 + 4LL));
if ( !result )
return 0LL;
while ( **(_DWORD **)result != **(_DWORD **)a1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int sommet_dans_bordure(Cellule_som *sommet, Bordure *bordure)
{
  Cellule_som *parcours = bordure->tab[sommet->sommet->cl];
  while (parcours) {
    if (parcours->sommet->num == sommet->sommet->num) return 1;
    parcours = parcours->suiv;
  }
  return 0;
}

canonical_original_code:
int sommet_dans_bordure(struct cellule_som *sommet, struct s_bordure *bordure)
{
  struct cellule_som *parcours = bordure->tab[sommet->sommet->cl];
  while (parcours) {
    if (parcours->sommet->num == sommet->sommet->num) return 1;
    parcours = parcours->suiv;
  }
  return 0;
}

variable_types: struct s_bordure { int nbcl; int *taille_liste; struct cellule_som **tab; } *


changeCouleurZsg

decompiled_code:
int *__fastcall changeCouleurZsg(__int64 a1, __int64 a2, int a3)
{
__int64 v6; // rdx
int *result; // rax

v6 = ***(_QWORD ***)(a1 + 16);
result = *(int **)(v6 + 8);
for ( *(_DWORD *)(v6 + 4) = a3; result; result = (int *)*((_QWORD *)result + 1) )
*(_DWORD *)(*(_QWORD *)(a2 + 8LL * *result) + 4LL * result[1]) = a3;
return result;
}

canonical_decompiled_code:
int *__fastcall func6(__int64 a1, __int64 a2, int a3)
{
__int64 v6; // rdx
int *result; // rax

v6 = ***(_QWORD ***)(a1 + 16);
result = *(int **)(v6 + 8);
for ( *(_DWORD *)(v6 + 4) = a3; result; result = (int *)*((_QWORD *)result + 1) )
*(_DWORD *)(*(_QWORD *)(a2 + 8LL * *result) + 4LL * result[1]) = a3;
return result;
}

original_code:
void changeCouleurZsg(Graphe_zone *G, int ** M, int cl)
{
  Liste_case *elem = (G->mat[0][0])->cases;
  int i, j;
  (G->mat[0][0])->cl = cl;
  while(elem != ((void *)0)) {
      i = elem->i;
      j = elem->j;
      M[i][j] = cl;
      elem = elem->next;
    }
}

canonical_original_code:
void changeCouleurZsg(struct graphe_zone *G, int **M, int cl)
{
  struct Liste_C *elem = (G->mat[0][0])->cases;
  int i; int j;
  (G->mat[0][0])->cl = cl;
  while(elem != ((void *)0)) {
      i = elem->i;
      j = elem->j;
      M[i][j] = cl;
      elem = elem->next;
    }
}

variable_types: cl int


original_code:
void Gene_instance_genere_matrice(int nbcase, int nbcl, int nivdif, int graine, int **M){
  int i,j,k,m,c,di,si,prof,larg;
  int diam= (nivdif/100.0)*nbcase;
  if (diam==0) diam=1;
  srand(graine);
  for (j=0;j<nbcase;j++)
    for (i=0;i<nbcase;i++)
      M[i][j]=-1;
  for (j=0;j<nbcase;j++)
    for (i=0;i<nbcase;i++){
      if (M[i][j]==-1){
 c=rand()%(nbcl);
 prof=1+rand()%(diam);
 larg=1+rand()%(diam);
 k=0;
 while ((k<prof)&&(j+k<nbcase)){
   M[i][j]=c;
   di=(rand()%larg)/4.0;
   si=1-2*rand()%2;
   m=0;
   while (m<larg){
     if ((i+si*di+m>=0)&&(i+si*di+m<nbcase)&&(M[i+si*di+m][j+k]==-1))
       M[i+si*di+m][j+k]=c;
     m++;
   }
   k++;
 }
      }
    }
}

canonical_original_code:
void Gene_instance_genere_matrice(int nbcase, int nbcl, int nivdif, int graine, int **M){
  int i; int j; int k; int m; int c; int di; int si; int prof; int larg;
  int diam = (nivdif/100.0)*nbcase;
  if (diam==0) diam=1;
  srand(graine);
  for (j=0;j<nbcase;j++)
    for (i=0;i<nbcase;i++)
      M[i][j]=-1;
  for (j=0;j<nbcase;j++)
    for (i=0;i<nbcase;i++){
      if (M[i][j]==-1){
 c=rand()%(nbcl);
 prof=1+rand()%(diam);
 larg=1+rand()%(diam);
 k=0;
 while ((k<prof)&&(j+k<nbcase)){
   M[i][j]=c;
   di=(rand()%larg)/4.0;
   si=1-2*rand()%2;
   m=0;
   while (m<larg){
     if ((i+si*di+m>=0)&&(i+si*di+m<nbcase)&&(M[i+si*di+m][j+k]==-1))
       M[i+si*di+m][j+k]=c;
     m++;
   }
   k++;
 }
      }
    }
}

variable_types: nbcase int

variable_types: nbcl int

variable_types: nivdif int

variable_types: graine int

variable_types: k int

variable_types: m int

variable_types: c int

variable_types: di int

variable_types: si int

variable_types: prof int

variable_types: larg int

variable_types: diam int


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

printf("test_doesDirExist ? %s: ", a1);
if ( (unsigned int)doesDirExist(a1) )
result = puts("yes");
else
result = puts("no");
return result;
}

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

printf("test_doesDirExist ? %s: ", a1);
if ( (unsigned int)doesDirExist(a1) )
result = puts("yes");
else
result = puts("no");
return result;
}

original_code:
void test_doesDirExist(char* dir){
 printf("test_doesDirExist ? %s: ", dir);
 if(doesDirExist(dir)){
  printf("yes\n");
 }else{
  printf("no\n");
 }
}

canonical_original_code:
void test_doesDirExist(char *dir){
 printf("test_doesDirExist ? %s: ", dir);
 if(doesDirExist(dir)){
  printf("yes\n");
 }else{
  printf("no\n");
 }
}

variable_types:
dir
char *


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

printf("test_doesFileExist ? %s: ", a1);
if ( (unsigned int)doesFileExist(a1) )
result = puts("yes");
else
result = puts("no");
return result;
}

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

printf("test_doesFileExist ? %s: ", a1);
if ( (unsigned int)doesFileExist(a1) )
result = puts("yes");
else
result = puts("no");
return result;
}

original_code:
void test_doesFileExist(char* dir){
 printf("test_doesFileExist ? %s: ", dir);
 if(doesFileExist(dir)){
  printf("yes\n");
 }else{
  printf("no\n");
 }
}

canonical_original_code:
void test_doesFileExist(char *dir){
 printf("test_doesFileExist ? %s: ", dir);
 if(doesFileExist(dir)){
  printf("yes\n");
 }else{
  printf("no\n");
 }
}


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

v1 = (const char *)tildaToHome();
return printf("test_tildaToHome: %s -> %s\n", a1, v1);
}

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

v1 = (const char *)tildaToHome();
return printf("test_tildaToHome: %s -> %s\n", a1, v1);
}

original_code:
void test_tildaToHome(char* dir){
 char* newPath = tildaToHome(dir);
 printf("test_tildaToHome: %s -> %s\n", dir, newPath);
}

canonical_original_code:
void test_tildaToHome(char *dir){
 char *newPath = tildaToHome(dir);
 printf("test_tildaToHome: %s -> %s\n", dir, newPath);
}

variable_types:
newPath
char *


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

v1 = (const char *)homeToTilda();
return printf("test_homeToTilda: %s -> %s\n", a1, v1);
}

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

v1 = (const char *)homeToTilda();
return printf("test_homeToTilda: %s -> %s\n", a1, v1);
}

original_code:
void test_homeToTilda(char* dir){
 char* newPath = homeToTilda(dir);
 printf("test_homeToTilda: %s -> %s\n", dir, newPath);
}

canonical_original_code:
void test_homeToTilda(char *dir){
 char *newPath = homeToTilda(dir);
 printf("test_homeToTilda: %s -> %s\n", dir, newPath);
}


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

printf("test_getFilePath: %s\n", a1);
v1 = (const char *)getFilePath(a1);
if ( v1 )
result = puts(v1);
else
result = puts("File does not exist");
return result;
}

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

printf("test_getFilePath: %s\n", a1);
v1 = (const char *)getFilePath(a1);
if ( v1 )
result = puts(v1);
else
result = puts("File does not exist");
return result;
}

original_code:
void test_getFilePath(char* fileName){
 printf("test_getFilePath: %s\n", fileName);
 char* filePath = getFilePath(fileName);
 if(filePath){
  printf("%s\n", filePath);
 }else{
  printf("File does not exist\n");
 }
}

canonical_original_code:
void test_getFilePath(char *fileName){
 printf("test_getFilePath: %s\n", fileName);
 char *filePath = getFilePath(fileName);
 if(filePath){
  printf("%s\n", filePath);
 }else{
  printf("File does not exist\n");
 }
}

variable_types:
fileName
char *

variable_types:
filePath
char *


decompiled_code:
int test_getPaths()
{
const char **v0; // rax
const char *v1; // rdi
const char **v2; // rbx

puts("test_getPaths:");
v0 = (const char **)getPaths();
v1 = *v0;
if ( *v0 )
{
v2 = v0 + 1;
do
{
LODWORD(v0) = puts(v1);
v1 = *v2++;
}
while ( v1 );
}
return (int)v0;
}

canonical_decompiled_code:
int func5()
{
const char **v0; // rax
const char *v1; // rdi
const char **v2; // rbx

puts("test_getPaths:");
v0 = (const char **)getPaths();
v1 = *v0;
if ( *v0 )
{
v2 = v0 + 1;
do
{
LODWORD(v0) = puts(v1);
v1 = *v2++;
}
while ( v1 );
}
return (int)v0;
}

original_code:
void test_getPaths(void){
 printf("test_getPaths:\n");
 char** paths = getPaths();
 int i = 0;
 while(((void *)0) != paths[i]){
  printf("%s\n", paths[i]);
  i++;
 }
}

canonical_original_code:
void test_getPaths(){
 printf("test_getPaths:\n");
 char **paths = getPaths();
 int i = 0;
 while(((void *)0) != paths[i]){
  printf("%s\n", paths[i]);
  i++;
 }
}

variable_types:
paths
char **

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_doesDirExist("/usr/bin/");
doesDirExist(".");
test_doesDirExist("../");
test_doesFileExist("testrun");
test_doesFileExist("/bin/ls");
test_doesFileExist("../../shell.c");
test_doesFileExist("/usr/bin");
test_doesFileExist("lksjdf");
test_doesFileExist("mkdir");
test_tildaToHome("~/Documents");
test_tildaToHome("/Documents");
test_homeToTilda("/home/trevor/Downloads");
test_homeToTilda("/usr/bin/soemthing/blah");
test_getFilePath("ls");
test_getFilePath("mkdir");
test_getFilePath("firefox");
test_getFilePath("somelksdjf");
test_getFilePath("/bin/ls");
test_getFilePath("../../shell.c");
test_getFilePath("fileGetTest.c");
test_getFilePath("~/.vimrc");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0("/usr/bin/");
doesDirExist(".");
func0("../");
func1("testrun");
func1("/bin/ls");
func1("../../shell.c");
func1("/usr/bin");
func1("lksjdf");
func1("mkdir");
func2("~/Documents");
func2("/Documents");
func3("/home/trevor/Downloads");
func3("/usr/bin/soemthing/blah");
func4("ls");
func4("mkdir");
func4("firefox");
func4("somelksdjf");
func4("/bin/ls");
func4("../../shell.c");
func4("fileGetTest.c");
func4("~/.vimrc");
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 test_doesDirExist("/usr/bin/");
 doesDirExist(".");
 test_doesDirExist("../");
 test_doesFileExist("testrun");
 test_doesFileExist("/bin/ls");
 test_doesFileExist("../../shell.c");
 test_doesFileExist("/usr/bin");
 test_doesFileExist("lksjdf");
 test_doesFileExist("mkdir");
 test_tildaToHome("~/Documents");
 test_tildaToHome("/Documents");
 test_homeToTilda("/home/trevor/Downloads");
 test_homeToTilda("/usr/bin/soemthing/blah");
 test_getFilePath("ls");
 test_getFilePath("mkdir");
 test_getFilePath("firefox");
 test_getFilePath("somelksdjf");
 test_getFilePath("/bin/ls");
 test_getFilePath("../../shell.c");
 test_getFilePath("fileGetTest.c");
 test_getFilePath("~/.vimrc");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 test_doesDirExist("/usr/bin/");
 doesDirExist(".");
 test_doesDirExist("../");
 test_doesFileExist("testrun");
 test_doesFileExist("/bin/ls");
 test_doesFileExist("../../shell.c");
 test_doesFileExist("/usr/bin");
 test_doesFileExist("lksjdf");
 test_doesFileExist("mkdir");
 test_tildaToHome("~/Documents");
 test_tildaToHome("/Documents");
 test_homeToTilda("/home/trevor/Downloads");
 test_homeToTilda("/usr/bin/soemthing/blah");
 test_getFilePath("ls");
 test_getFilePath("mkdir");
 test_getFilePath("firefox");
 test_getFilePath("somelksdjf");
 test_getFilePath("/bin/ls");
 test_getFilePath("../../shell.c");
 test_getFilePath("fileGetTest.c");
 test_getFilePath("~/.vimrc");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


welcome

original_code:
void welcome()
{
   printf("\n%s********************************\n", RED);
   printf("* %sThe EECE 315 B5 SHELL        %s*\n", BLUE, RED);
   printf("********************************\n");
   printf("* %sDeveloped by:                %s*\n", BLUE, RED);
   printf("* %sAndrej Satara, Jessica Seto  %s*\n", GREEN, RED);
   printf("* %sTrevor Siemens, Rohit Singla %s*\n", GREEN, RED);
   printf("********************************\n%s", ENDCLR);
   return;
}


makePrompt

decompiled_code:
char *__fastcall makePrompt(unsigned int a1)
{
char *v1; // rbp
char *v2; // rax
const char *v3; // rbx
char *v4; // r12
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char *result; // rax
char s[3]; // [rsp+Dh] [rbp-143Bh] BYREF
char dest[8]; // [rsp+10h] [rbp-1438h] BYREF
__int64 v12; // [rsp+18h] [rbp-1430h]
char v13[1008]; // [rsp+20h] [rbp-1428h] BYREF
char name[8]; // [rsp+410h] [rbp-1038h] BYREF
__int64 v15; // [rsp+418h] [rbp-1030h]
__int64 v16; // [rsp+420h] [rbp-1028h]
__int64 v17; // [rsp+428h] [rbp-1020h]
char buf[8]; // [rsp+430h] [rbp-1018h] BYREF
__int64 v19; // [rsp+438h] [rbp-1010h]
char v20[4080]; // [rsp+440h] [rbp-1008h] BYREF

*(_QWORD *)buf = 0LL;
v19 = 0LL;
memset(v20, 0, sizeof(v20));
*(_QWORD *)name = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
*(_QWORD *)dest = 0LL;
v12 = 0LL;
memset(v13, 0, sizeof(v13));
sprintf(s, "%d", a1);
v1 = getenv("LOGNAME");
v2 = getcwd(buf, 0x1000uLL);
v3 = (const char *)homeToTilda(v2);
v4 = name;
if ( gethostname(name, 0x20uLL) )
v4 = "B5";
if ( !v3 )
puts("getcwd() ERROR!");
if ( v1 )
{
v5 = strlen(dest);
*(_QWORD *)&dest[v5] = *(_QWORD *)"\x1B[00;34m";
*((_BYTE *)&v12 + v5) = BLUE[8];
strcat(dest, v1);
v6 = strlen(dest);
*(_QWORD *)&dest[v6] = *(_QWORD *)"\x1B[00;31m";
*((_BYTE *)&v12 + v6) = RED[8];
*(_WORD *)&dest[strlen(dest)] = 64;
v7 = strlen(dest);
*(_QWORD *)&dest[v7] = *(_QWORD *)"\x1B[00;32m";
*((_BYTE *)&v12 + v7) = GREEN[8];
strcat(dest, v4);
v8 = strlen(dest);
*(_QWORD *)&dest[v8] = YELLOW;
*((_BYTE *)&v12 + v8) = 0;
if ( v3 )
{
*(_WORD *)&dest[strlen(dest)] = 58;
strcat(dest, v3);
}
*(_WORD *)&dest[strlen(dest)] = 91;
strcat(dest, s);
result = dest;
}
else
{
puts("ERROR: no LOGIN");
puts("ERROR: cannot form prompt. set to default");
result = "???$";
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1)
{
char *v1; // rbp
char *v2; // rax
const char *v3; // rbx
char *v4; // r12
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
char *result; // rax
char s[3]; // [rsp+Dh] [rbp-143Bh] BYREF
char dest[8]; // [rsp+10h] [rbp-1438h] BYREF
__int64 v12; // [rsp+18h] [rbp-1430h]
char v13[1008]; // [rsp+20h] [rbp-1428h] BYREF
char name[8]; // [rsp+410h] [rbp-1038h] BYREF
__int64 v15; // [rsp+418h] [rbp-1030h]
__int64 v16; // [rsp+420h] [rbp-1028h]
__int64 v17; // [rsp+428h] [rbp-1020h]
char buf[8]; // [rsp+430h] [rbp-1018h] BYREF
__int64 v19; // [rsp+438h] [rbp-1010h]
char v20[4080]; // [rsp+440h] [rbp-1008h] BYREF

*(_QWORD *)buf = 0LL;
v19 = 0LL;
memset(v20, 0, sizeof(v20));
*(_QWORD *)name = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
*(_QWORD *)dest = 0LL;
v12 = 0LL;
memset(v13, 0, sizeof(v13));
sprintf(s, "%d", a1);
v1 = getenv("LOGNAME");
v2 = getcwd(buf, 0x1000uLL);
v3 = (const char *)homeToTilda(v2);
v4 = name;
if ( gethostname(name, 0x20uLL) )
v4 = "B5";
if ( !v3 )
puts("getcwd() ERROR!");
if ( v1 )
{
v5 = strlen(dest);
*(_QWORD *)&dest[v5] = *(_QWORD *)"\x1B[00;34m";
*((_BYTE *)&v12 + v5) = BLUE[8];
strcat(dest, v1);
v6 = strlen(dest);
*(_QWORD *)&dest[v6] = *(_QWORD *)"\x1B[00;31m";
*((_BYTE *)&v12 + v6) = RED[8];
*(_WORD *)&dest[strlen(dest)] = 64;
v7 = strlen(dest);
*(_QWORD *)&dest[v7] = *(_QWORD *)"\x1B[00;32m";
*((_BYTE *)&v12 + v7) = GREEN[8];
strcat(dest, v4);
v8 = strlen(dest);
*(_QWORD *)&dest[v8] = YELLOW;
*((_BYTE *)&v12 + v8) = 0;
if ( v3 )
{
*(_WORD *)&dest[strlen(dest)] = 58;
strcat(dest, v3);
}
*(_WORD *)&dest[strlen(dest)] = 91;
strcat(dest, s);
result = dest;
}
else
{
puts("ERROR: no LOGIN");
puts("ERROR: cannot form prompt. set to default");
result = "???$";
}
return result;
}

original_code:
char* makePrompt(int cmdCount)
{
   char fileBuffer[4096] = { 0 };
   char smallBuffer[32] = { 0 };
   char largeBuffer[1024] = { 0 };
   char* pPrompt;
   char* pHost;
   char* pCWD;
   char* pLogin;
   char intStr[3];
   sprintf(intStr,"%d",cmdCount);
   pLogin = getenv("LOGNAME");
   pCWD = getcwd(fileBuffer,sizeof(fileBuffer));
   pCWD = homeToTilda(pCWD);
   pHost = gethostname(smallBuffer,sizeof(smallBuffer)) == 0 ? smallBuffer : "B5";
   if(pHost == ((void *)0)){
       printf("ERROR: no HOSTNAME\n");
   }
   if(pCWD == ((void *)0)){
       printf("getcwd() ERROR!\n");
   }
   if(pLogin == ((void *)0)){
       printf("ERROR: no LOGIN\n");
   }
   if( (pLogin != ((void *)0)) && (pHost != ((void *)0)) ) {
       strcat(largeBuffer, BLUE);
       strcat(largeBuffer,pLogin);
       strcat(largeBuffer, RED);
       strcat(largeBuffer,"@");
       strcat(largeBuffer, GREEN);
       strcat(largeBuffer,pHost);
       strcat(largeBuffer, YELLOW);
       if(pCWD != ((void *)0)) {
           strcat(largeBuffer,":");
           strcat(largeBuffer,pCWD);
       }
    strcat(largeBuffer,"[");
    strcat(largeBuffer,intStr);
    strcat(largeBuffer,"]");
           strcat(largeBuffer,"\n>>");
    strcat(largeBuffer, ENDCLR);
           pPrompt = largeBuffer;
       } else {
           printf("ERROR: cannot form prompt. set to default\n");
           pPrompt = "???$";
       }
   if( pPrompt == ((void *)0)) {
       printf("ERROR: prompt is null \n");
   }
   return pPrompt;
}

canonical_original_code:
char *makePrompt(int cmdCount)
{
   char fileBuffer[4096] = { 0 };
   char smallBuffer[32] = { 0 };
   char largeBuffer[1024] = { 0 };
   char *pPrompt;
   char *pHost;
   char *pCWD;
   char *pLogin;
   char intStr[3];
   sprintf(intStr,"%d",cmdCount);
   pLogin = getenv("LOGNAME");
   pCWD = getcwd(fileBuffer,sizeof(fileBuffer));
   pCWD = homeToTilda(pCWD);
   pHost = gethostname(smallBuffer,sizeof(smallBuffer)) == 0 ? smallBuffer : "B5";
   if(pHost == ((void *)0)){
       printf("ERROR: no HOSTNAME\n");
   }
   if(pCWD == ((void *)0)){
       printf("getcwd() ERROR!\n");
   }
   if(pLogin == ((void *)0)){
       printf("ERROR: no LOGIN\n");
   }
   if( (pLogin != ((void *)0)) && (pHost != ((void *)0)) ) {
       strcat(largeBuffer, BLUE);
       strcat(largeBuffer,pLogin);
       strcat(largeBuffer, RED);
       strcat(largeBuffer,"@");
       strcat(largeBuffer, GREEN);
       strcat(largeBuffer,pHost);
       strcat(largeBuffer, YELLOW);
       if(pCWD != ((void *)0)) {
           strcat(largeBuffer,":");
           strcat(largeBuffer,pCWD);
       }
    strcat(largeBuffer,"[");
    strcat(largeBuffer,intStr);
    strcat(largeBuffer,"]");
           strcat(largeBuffer,"\n>>");
    strcat(largeBuffer, ENDCLR);
           pPrompt = largeBuffer;
       } else {
           printf("ERROR: cannot form prompt. set to default\n");
           pPrompt = "???$";
       }
   if( pPrompt == ((void *)0)) {
       printf("ERROR: prompt is null \n");
   }
   return pPrompt;
}

variable_types: cmdCount int

variable_types:
fileBuffer
char [4096]

variable_types:
smallBuffer
char [32]

variable_types:
largeBuffer
char [1024]

variable_types:
pPrompt
char *

variable_types:
pHost
char *

variable_types:
pCWD
char *

variable_types:
pLogin
char *

variable_types:
intStr
char [3]

return_type: char *


getPathEnv

decompiled_code:
char *getPathEnv()
{
char *result; // rax

result = getenv("PATH");
if ( !result )
result = "/bin";
return result;
}

canonical_decompiled_code:
char *func2()
{
char *result; // rax

result = getenv("PATH");
if ( !result )
result = "/bin";
return result;
}

original_code:
char* getPathEnv(){
   char* pPath;
   pPath = getenv("PATH");
   char* defaultPath = "/bin";
   if(pPath == ((void *)0)){
       pPath = defaultPath;
   }
   return pPath;
}

canonical_original_code:
char *getPathEnv(){
   char *pPath;
   pPath = getenv("PATH");
   char *defaultPath = "/bin";
   if(pPath == ((void *)0)){
       pPath = defaultPath;
   }
   return pPath;
}

variable_types:
pPath
char *

variable_types:
defaultPath
char *


quoteDelimit

original_code:
char* quoteDelimit(char* command){
   if( command == ((void *)0) ){
       return ((void *)0);
   }
   bool inQuotes = 0;
   int length = strlen(command);
   int i;
   for(i = 0; i < length; i++){
       if(!inQuotes && command[i] == ' '){
     command[i] = '\"';
       } else if( !inQuotes && command[i] == '\"' ){
    inQuotes = 1;
       } else if( inQuotes && command[i] == '\"' ){
    inQuotes = 0;
       }
   }
   return command;
}

canonical_original_code:
char *quoteDelimit(char *command){
   if( command == ((void *)0) ){
       return ((void *)0);
   }
   int inQuotes = 0;
   int length = strlen(command);
   int i;
   for(i = 0; i < length; i++){
       if(!inQuotes && command[i] == ' '){
     command[i] = '\"';
       } else if( !inQuotes && command[i] == '\"' ){
    inQuotes = 1;
       } else if( inQuotes && command[i] == '\"' ){
    inQuotes = 0;
       }
   }
   return command;
}

variable_types:
command
char *

variable_types: inQuotes int

variable_types: length int


help

decompiled_code:
int help()
{
puts("EECE 315 B5 Shell, version 1.0");
puts("These shell commands are defined internally:");
puts("cd [dir]");
puts("help");
puts("senv [env var name] [env var value]");
puts("usenv [env var name]");
puts("genv [env var name]");
puts("quit OR exit OR q");
return puts("Insert '&' after a program command to run in background");
}

canonical_decompiled_code:
int func4()
{
puts("EECE 315 B5 Shell, version 1.0");
puts("These shell commands are defined internally:");
puts("cd [dir]");
puts("help");
puts("senv [env var name] [env var value]");
puts("usenv [env var name]");
puts("genv [env var name]");
puts("quit OR exit OR q");
return puts("Insert '&' after a program command to run in background");
}

original_code:
void help()
{
   printf("EECE 315 B5 Shell, version 1.0\n");
   printf("These shell commands are defined internally:\n");
   printf("cd [dir]\n");
   printf("help\n");
   printf("senv [env var name] [env var value]\n");
   printf("usenv [env var name]\n");
   printf("genv [env var name]\n");
   printf("quit OR exit OR q\n");
   printf("Insert '&' after a program command to run in background\n");
   return;
}


setEnvVar

decompiled_code:
int __fastcall setEnvVar(const char *a1, const char *a2)
{
int result; // eax

if ( !a1 || !a2 )
return puts("Error: senv requires arguments [environment name] [value]");
result = setenv(a1, a2, 1);
if ( result == -1 )
result = printf("Error: Could not set %s\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2)
{
int result; // eax

if ( !a1 || !a2 )
return puts("Error: senv requires arguments [environment name] [value]");
result = setenv(a1, a2, 1);
if ( result == -1 )
result = printf("Error: Could not set %s\n", a1);
return result;
}

original_code:
void setEnvVar(char* envName, char* envValue){
   if( envName == ((void *)0) || envValue == ((void *)0) ){
       printf("Error: senv requires arguments [environment name] [value]\n");
   } else {
       if( setenv(envName, envValue, 1) == ENV_ERR ){
        printf("Error: Could not set %s\n", envName);
       }
   }
   return;
}

canonical_original_code:
void setEnvVar(char *envName, char *envValue){
   if( envName == ((void *)0) || envValue == ((void *)0) ){
       printf("Error: senv requires arguments [environment name] [value]\n");
   } else {
       if( setenv(envName, envValue, 1) == ENV_ERR ){
        printf("Error: Could not set %s\n", envName);
       }
   }
   return;
}

variable_types:
envName
char *

variable_types:
envValue
char *


unsetEnvVar

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

if ( !a1 )
return puts("Error: usenv requires arguments [environment name]");
result = unsetenv(a1);
if ( result == -1 )
result = printf("Error: Could not unset %s\n", a1);
return result;
}

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

if ( !a1 )
return puts("Error: usenv requires arguments [environment name]");
result = unsetenv(a1);
if ( result == -1 )
result = printf("Error: Could not unset %s\n", a1);
return result;
}

original_code:
void unsetEnvVar(char* envName){
   if( envName == ((void *)0) ){
       printf("Error: usenv requires arguments [environment name]\n");
   } else {
       if( unsetenv(envName) == ENV_ERR ){
     printf("Error: Could not unset %s\n", envName);
       }
   }
   return;
}

canonical_original_code:
void unsetEnvVar(char *envName){
   if( envName == ((void *)0) ){
       printf("Error: usenv requires arguments [environment name]\n");
   } else {
       if( unsetenv(envName) == ENV_ERR ){
     printf("Error: Could not unset %s\n", envName);
       }
   }
   return;
}


getEnvVar

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

if ( !a1 )
return puts("Error: genv requires arguments [environment name]");
v1 = getenv(a1);
return printf("%s = %s\n", a1, v1);
}

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

if ( !a1 )
return puts("Error: genv requires arguments [environment name]");
v1 = getenv(a1);
return printf("%s = %s\n", a1, v1);
}

original_code:
void getEnvVar(char* envName){
   if( envName == ((void *)0) ){
       printf("Error: genv requires arguments [environment name]\n");
   } else{
       printf("%s = %s\n", envName, getenv(envName));
   }
   return;
}

canonical_original_code:
void getEnvVar(char *envName){
   if( envName == ((void *)0) ){
       printf("Error: genv requires arguments [environment name]\n");
   } else{
       printf("%s = %s\n", envName, getenv(envName));
   }
   return;
}


changeDirectory

decompiled_code:
int changeDirectory()
{
const char *v0; // rax
int result; // eax

v0 = (const char *)tildaToHome();
result = chdir(v0);
if ( result == -1 )
result = puts("I'm sorry Dave, I cannot change to that directory.");
return result;
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rax
int result; // eax

v0 = (const char *)tildaToHome();
result = chdir(v0);
if ( result == -1 )
result = puts("I'm sorry Dave, I cannot change to that directory.");
return result;
}

original_code:
void changeDirectory(char* pPath)
{
   int ret;
   char* absPath = tildaToHome(pPath);
   ret = chdir(absPath);
   if(ret == NEG_ONE) {
       printf("I'm sorry Dave, I cannot change to that directory.\n");
   }
   return;
}

canonical_original_code:
void changeDirectory(char *pPath)
{
   int ret;
   char *absPath = tildaToHome(pPath);
   ret = chdir(absPath);
   if(ret == NEG_ONE) {
       printf("I'm sorry Dave, I cannot change to that directory.\n");
   }
   return;
}

variable_types: ret int

variable_types:
absPath
char *


processCommand

decompiled_code:
__int64 __fastcall processCommand(const char **a1, char *const *a2)
{
char *v4; // rdx
unsigned int v5; // ebp
int v7; // eax
const char *v8; // rdi
const char *v9; // rsi
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
const char *v17; // rdi
const char *v18; // r12
int v19; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = getenv("HOME");
if ( !strcmp(*a1, "cd") )
{
v5 = *((_DWORD *)a1 + 2);
changeDirectory();
if ( v5 != 1 )
v5 = 1;
}
else if ( !strcmp(*a1, "help") )
{
help();
v5 = 1;
}
else if ( !strcmp(*a1, "senv") )
{
v7 = *((_DWORD *)a1 + 2);
v8 = 0LL;
if ( v7 > 1 )
v8 = a1[3];
v9 = 0LL;
if ( v7 > 2 )
v9 = a1[4];
setEnvVar(v8, v9);
v5 = 1;
}
else
{
v10 = strcmp(*a1, "usenv") != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
{
v14 = "genv";
v15 = 5LL;
v16 = *a1;
do
{
if ( !v15 )
break;
v11 = *v16 < (unsigned int)*v14;
v12 = *v16++ == *v14++;
--v15;
}
while ( v12 );
if ( (!v11 && !v12) == v11 )
{
v17 = 0LL;
if ( *((int *)a1 + 2) > 1 )
v17 = a1[3];
getEnvVar(v17);
v5 = 1;
}
else
{
v18 = (const char *)getFilePath(*a1, v16, v4);
if ( v18 )
{
v19 = fork();
if ( v19 < 0 )
{
fwrite("Fork failure!\n", 1uLL, 0xEuLL, stderr);
v5 = 1;
}
else if ( v19 )
{
if ( *((_DWORD *)a1 + 3) )
printf("Process ID: %d\n", (unsigned int)v19);
else
waitpid(v19, stat_loc, 0);
v5 = 1;
}
else
{
if ( *((_DWORD *)a1 + 3) )
{
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
execve(v18, (char *const *)a1 + 2, a2);
v5 = 1;
}
}
else
{
v5 = strcmp(*a1, "quit") != 0;
if ( v5 )
{
v5 = strcmp(*a1, "exit") != 0;
if ( v5 )
{
v12 = strcmp(*a1, "q") == 0;
v5 = !v12;
if ( !v12 )
{
printf("%s: Command not found\n", *a1);
v5 = 0;
}
}
}
}
}
}
else
{
v13 = 0LL;
if ( *((int *)a1 + 2) > 1 )
v13 = a1[3];
unsetEnvVar(v13);
v5 = 1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char **a1, char *const *a2)
{
char *v4; // rdx
unsigned int v5; // ebp
int v7; // eax
const char *v8; // rdi
const char *v9; // rsi
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
const char *v17; // rdi
const char *v18; // r12
int v19; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = getenv("HOME");
if ( !strcmp(*a1, "cd") )
{
v5 = *((_DWORD *)a1 + 2);
func8();
if ( v5 != 1 )
v5 = 1;
}
else if ( !strcmp(*a1, "help") )
{
func4();
v5 = 1;
}
else if ( !strcmp(*a1, "senv") )
{
v7 = *((_DWORD *)a1 + 2);
v8 = 0LL;
if ( v7 > 1 )
v8 = a1[3];
v9 = 0LL;
if ( v7 > 2 )
v9 = a1[4];
func5(v8, v9);
v5 = 1;
}
else
{
v10 = strcmp(*a1, "usenv") != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
{
v14 = "genv";
v15 = 5LL;
v16 = *a1;
do
{
if ( !v15 )
break;
v11 = *v16 < (unsigned int)*v14;
v12 = *v16++ == *v14++;
--v15;
}
while ( v12 );
if ( (!v11 && !v12) == v11 )
{
v17 = 0LL;
if ( *((int *)a1 + 2) > 1 )
v17 = a1[3];
func7(v17);
v5 = 1;
}
else
{
v18 = (const char *)getFilePath(*a1, v16, v4);
if ( v18 )
{
v19 = fork();
if ( v19 < 0 )
{
fwrite("Fork failure!\n", 1uLL, 0xEuLL, stderr);
v5 = 1;
}
else if ( v19 )
{
if ( *((_DWORD *)a1 + 3) )
printf("Process ID: %d\n", (unsigned int)v19);
else
waitpid(v19, stat_loc, 0);
v5 = 1;
}
else
{
if ( *((_DWORD *)a1 + 3) )
{
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
execve(v18, (char *const *)a1 + 2, a2);
v5 = 1;
}
}
else
{
v5 = strcmp(*a1, "quit") != 0;
if ( v5 )
{
v5 = strcmp(*a1, "exit") != 0;
if ( v5 )
{
v12 = strcmp(*a1, "q") == 0;
v5 = !v12;
if ( !v12 )
{
printf("%s: Command not found\n", *a1);
v5 = 0;
}
}
}
}
}
}
else
{
v13 = 0LL;
if ( *((int *)a1 + 2) > 1 )
v13 = a1[3];
func6(v13);
v5 = 1;
}
}
return v5;
}

original_code:
bool processCommand(command_t* command, char* pEnv[]){
   char* defaultDir = getenv("HOME");
   if( strcmp(command->name, "cd") == CMP_OK) {
       if( command->argc == 1 ) {
    changeDirectory(defaultDir);
       } else {
    changeDirectory(command->argv[1]);
       }
   } else if( strcmp(command->name,"help") == CMP_OK) {
       help();
   } else if( strcmp(command->name, "senv") == CMP_OK) {
       char* envName = ((void *)0);
       char* envVal = ((void *)0);
       if( command->argc > 1) {
           envName = command->argv[1];
       }
       if( command->argc > 2) {
           envVal = command->argv[2];
       }
       setEnvVar(envName,envVal);
   } else if( strcmp(command->name, "usenv") == CMP_OK) {
       char* envName = ((void *)0);
       if( command->argc > 1) {
        envName = command->argv[1];
       }
       unsetEnvVar(envName);
   } else if( strcmp(command->name, "genv") == CMP_OK) {
       char* envName = ((void *)0);
       if( command-> argc > 1) {
        envName = command->argv[1];
       }
       getEnvVar(envName);
   } else {
       char* filePath = getFilePath(command->name);
       if(filePath != ((void *)0)) {
    pid_t pid_command = fork();
           if(pid_command < CHILD) {
        fprintf(stderr, "Fork failure!\n");
      } else if ( pid_command == CHILD) {
        if(command->isBg) {
     freopen("/dev/null","w",stdout);
            freopen("/dev/null","w",stderr);
        }
        execve(filePath, command->argv, pEnv);
    } else {
        if(!command->isBg) {
     int stat;
     waitpid(pid_command, &stat, 0);
        } else {
      printf("Process ID: %d\n", pid_command);
     }
           }
       } else if(strcmp(command->name, "quit") == CMP_OK ||
   strcmp(command->name, "exit") == CMP_OK ||
   strcmp(command->name, "q") == CMP_OK ) {
    return 0;
       } else {
       printf("%s: Command not found\n", command->name);
    return 0;
       }
   }
   return 1;
}

canonical_original_code:
int processCommand(struct command_t *command, char *pEnv[]){
   char *defaultDir = getenv("HOME");
   if( strcmp(command->name, "cd") == CMP_OK) {
       if( command->argc == 1 ) {
    changeDirectory(defaultDir);
       } else {
    changeDirectory(command->argv[1]);
       }
   } else if( strcmp(command->name,"help") == CMP_OK) {
       help();
   } else if( strcmp(command->name, "senv") == CMP_OK) {
       char *envName = ((void *)0);
       char *envVal = ((void *)0);
       if( command->argc > 1) {
           envName = command->argv[1];
       }
       if( command->argc > 2) {
           envVal = command->argv[2];
       }
       setEnvVar(envName,envVal);
   } else if( strcmp(command->name, "usenv") == CMP_OK) {
       char *envName = ((void *)0);
       if( command->argc > 1) {
        envName = command->argv[1];
       }
       unsetEnvVar(envName);
   } else if( strcmp(command->name, "genv") == CMP_OK) {
       char *envName = ((void *)0);
       if( command-> argc > 1) {
        envName = command->argv[1];
       }
       getEnvVar(envName);
   } else {
       char *filePath = getFilePath(command->name);
       if(filePath != ((void *)0)) {
    int pid_command = fork();
           if(pid_command < CHILD) {
        fprintf(stderr, "Fork failure!\n");
      } else if ( pid_command == CHILD) {
        if(command->isBg) {
     freopen("/dev/null","w",stdout);
            freopen("/dev/null","w",stderr);
        }
        execve(filePath, command->argv, pEnv);
    } else {
        if(!command->isBg) {
     int stat;
     waitpid(pid_command, &stat, 0);
        } else {
      printf("Process ID: %d\n", pid_command);
     }
           }
       } else if(strcmp(command->name, "quit") == CMP_OK ||
   strcmp(command->name, "exit") == CMP_OK ||
   strcmp(command->name, "q") == CMP_OK ) {
    return 0;
       } else {
       printf("%s: Command not found\n", command->name);
    return 0;
       }
   }
   return 1;
}

variable_types: struct command_t { char *name; int argc; int isBg; char *argv[100]; } *

variable_types:
pEnv
char *[]

variable_types:
defaultDir
char *

variable_types:
envVal
char *

variable_types:
filePath
char *

variable_types: stat int


doesFileExist

decompiled_code:
_BOOL8 __fastcall doesFileExist(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax

v1 = open(a1, 0);
result = 0LL;
if ( v1 != -1 )
result = !doesDirExist(a1);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
int v1; // edx
_BOOL8 result; // rax

v1 = open(a1, 0);
result = 0LL;
if ( v1 != -1 )
result = !func0(a1);
return result;
}

original_code:
bool doesFileExist(char* path){
   int status = open(path, 00);
   if( NEG_ONE == status || doesDirExist(path)){
       return 0;
   } else{
       return 1;
   }
}

canonical_original_code:
int doesFileExist(char *path){
   int status = open(path, 00);
   if( NEG_ONE == status || doesDirExist(path)){
       return 0;
   } else{
       return 1;
   }
}

variable_types:
path
char *

variable_types: status int


tildaToHome

decompiled_code:
char *__fastcall tildaToHome(char *s)
{
char *v1; // rbx
char *v2; // rbp
int v3; // eax
char *v5; // r12
size_t v6; // rbx
size_t v7; // rax

v1 = s;
v2 = getenv("HOME");
v3 = strlen(s);
if ( v3 && *s == 126 )
{
v5 = (char *)malloc(v3);
strcpy(v5, s + 1);
v6 = strlen(s);
v7 = strlen(v2);
v1 = (char *)malloc(v6 + v7);
strcpy(v1, v2);
strcat(v1, v5);
free(v5);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
char *v1; // rbx
char *v2; // rbp
int v3; // eax
char *v5; // r12
size_t v6; // rbx
size_t v7; // rax

v1 = s;
v2 = getenv("HOME");
v3 = strlen(s);
if ( v3 && *s == 126 )
{
v5 = (char *)malloc(v3);
strcpy(v5, s + 1);
v6 = strlen(s);
v7 = strlen(v2);
v1 = (char *)malloc(v6 + v7);
strcpy(v1, v2);
strcat(v1, v5);
free(v5);
}
return v1;
}

original_code:
char* tildaToHome(char* path){
   char* homeDir = getenv("HOME");
   char* fullPath;
   char* tempPath;
   int pathLength = strlen(path);
   if(pathLength && '~' == path[0]){
       tempPath = (char*) malloc(pathLength);
       strcpy(tempPath, &path[1]);
       fullPath = (char*) malloc((strlen(path)+strlen(homeDir)));
       strcpy(fullPath, homeDir);
       strcat(fullPath, tempPath);
       free(tempPath);
       return fullPath;
   } else{
       return path;
   }
}

canonical_original_code:
char *tildaToHome(char *path){
   char *homeDir = getenv("HOME");
   char *fullPath;
   char *tempPath;
   int pathLength = strlen(path);
   if(pathLength && '~' == path[0]){
       tempPath = (char *) malloc(pathLength);
       strcpy(tempPath, &path[1]);
       fullPath = (char *) malloc((strlen(path)+strlen(homeDir)));
       strcpy(fullPath, homeDir);
       strcat(fullPath, tempPath);
       free(tempPath);
       return fullPath;
   } else{
       return path;
   }
}

variable_types:
homeDir
char *

variable_types:
fullPath
char *

variable_types:
tempPath
char *

variable_types: pathLength int


homeToTilda

decompiled_code:
char *__fastcall homeToTilda(char *s2)
{
char *v1; // rbx
char *v2; // r14
int v3; // er13
size_t v4; // rax
int v5; // ebp
char *v7; // rbp

v1 = s2;
v2 = getenv("HOME");
v3 = strlen(v2);
v4 = strlen(s2);
if ( v4 >= v3 )
{
v5 = v4;
if ( !strncmp(v2, s2, v3) )
{
v7 = (char *)malloc(v5 - v3 + 1);
strcpy(v7, &s2[v3 - 1]);
*v7 = 126;
v1 = v7;
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func3(char *s2)
{
char *v1; // rbx
char *v2; // r14
int v3; // er13
size_t v4; // rax
int v5; // ebp
char *v7; // rbp

v1 = s2;
v2 = getenv("HOME");
v3 = strlen(v2);
v4 = strlen(s2);
if ( v4 >= v3 )
{
v5 = v4;
if ( !strncmp(v2, s2, v3) )
{
v7 = (char *)malloc(v5 - v3 + 1);
strcpy(v7, &s2[v3 - 1]);
*v7 = 126;
v1 = v7;
}
}
return v1;
}

original_code:
char* homeToTilda(char* path){
   char* homeDir = getenv("HOME");
   int homeLength = strlen(homeDir);
   int pathLength = strlen(path);
   char* tildaPath;
   if(strlen(path) >= homeLength && !strncmp(homeDir, path, homeLength)){
       tildaPath = (char*) malloc(pathLength - homeLength +1);
       strcpy(tildaPath, &path[homeLength -1]);
       tildaPath[0] = '~';
       return tildaPath;
   } else{
       return path;
   }
}

canonical_original_code:
char *homeToTilda(char *path){
   char *homeDir = getenv("HOME");
   int homeLength = strlen(homeDir);
   int pathLength = strlen(path);
   char *tildaPath;
   if(strlen(path) >= homeLength && !strncmp(homeDir, path, homeLength)){
       tildaPath = (char *) malloc(pathLength - homeLength +1);
       strcpy(tildaPath, &path[homeLength -1]);
       tildaPath[0] = '~';
       return tildaPath;
   } else{
       return path;
   }
}

variable_types: homeLength int

variable_types:
tildaPath
char *


getPaths

original_code:
char** getPaths(){
   char* temp = getenv("PATH");
   char* pathEnv = (char*)malloc(strlen(temp));
   strcpy(pathEnv, temp);
   int numOfPaths = 1;
   int i;
   for(i = (strlen(pathEnv)-1); i > 0; i--){
       if(':' == pathEnv[i]){
    numOfPaths++;
       }
   }
   char** paths = (char**)calloc(numOfPaths+1, sizeof(char*));
   paths[numOfPaths] = ((void *)0);
   numOfPaths--;
   for(i = (strlen(pathEnv)-1); i > 0; i--){
       if(':' == pathEnv[i]){
     paths[numOfPaths] = &pathEnv[i+1];
    numOfPaths--;
    pathEnv[i] = '\0';
 }
   }
   paths[0] = &pathEnv[0];
   return paths;
}

canonical_original_code:
char **getPaths(){
   char *temp = getenv("PATH");
   char *pathEnv = (char*)malloc(strlen(temp));
   strcpy(pathEnv, temp);
   int numOfPaths = 1;
   int i;
   for(i = (strlen(pathEnv)-1); i > 0; i--){
       if(':' == pathEnv[i]){
    numOfPaths++;
       }
   }
   char **paths = (char**)calloc(numOfPaths+1, sizeof(char*));
   paths[numOfPaths] = ((void *)0);
   numOfPaths--;
   for(i = (strlen(pathEnv)-1); i > 0; i--){
       if(':' == pathEnv[i]){
     paths[numOfPaths] = &pathEnv[i+1];
    numOfPaths--;
    pathEnv[i] = '\0';
 }
   }
   paths[0] = &pathEnv[0];
   return paths;
}

variable_types:
temp
char *

variable_types:
pathEnv
char *

variable_types: numOfPaths int

variable_types: i int

variable_types:
paths
char **

return_type: char **


getFilePath

decompiled_code:
char *__fastcall getFilePath(char *src)
{
const char **v1; // rbp
char *v2; // rbx
const char *v3; // rsi
const char **v4; // rbp
char *v5; // rax

v1 = (const char **)getPaths();
v2 = (char *)malloc(0x1000uLL);
v3 = *v1;
if ( *v1 )
{
v4 = v1 + 1;
while ( 1 )
{
strcpy(v2, v3);
*(_WORD *)&v2[strlen(v2)] = 47;
strcat(v2, src);
if ( doesFileExist(v2) )
break;
v3 = *v4++;
if ( !v3 )
goto LABEL_5;
}
}
else
{
LABEL_5:
strcpy(v2, src);
v5 = tildaToHome(v2);
v2 = realpath(v5, 0LL);
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
const char **v1; // rbp
char *v2; // rbx
const char *v3; // rsi
const char **v4; // rbp
char *v5; // rax

v1 = (const char **)func4();
v2 = (char *)malloc(0x1000uLL);
v3 = *v1;
if ( *v1 )
{
v4 = v1 + 1;
while ( 1 )
{
strcpy(v2, v3);
*(_WORD *)&v2[strlen(v2)] = 47;
strcat(v2, src);
if ( func1(v2) )
break;
v3 = *v4++;
if ( !v3 )
goto LABEL_5;
}
}
else
{
LABEL_5:
strcpy(v2, src);
v5 = func2(v2);
v2 = realpath(v5, 0LL);
}
return v2;
}

original_code:
char* getFilePath(char* fileName){
   char** paths = getPaths();
   char* filePath = ((void *)0);
   int i = 0;
   filePath = malloc(4096*sizeof(char));
   while( paths[i] != ((void *)0)){
       strcpy(filePath, paths[i]);
       strcat(filePath, "/");
       strcat(filePath, fileName);
       if(doesFileExist(filePath)){
    return filePath;
 }
  i++;
   }
   strcpy(filePath, fileName);
   filePath = tildaToHome(filePath);
   filePath = realpath(filePath, ((void *)0));
   if( filePath != ((void *)0) ){
       return filePath;
   }
 return ((void *)0);
}

canonical_original_code:
char *getFilePath(char *fileName){
   char **paths = getPaths();
   char *filePath = ((void *)0);
   int i = 0;
   filePath = malloc(4096*sizeof(char));
   while( paths[i] != ((void *)0)){
       strcpy(filePath, paths[i]);
       strcat(filePath, "/");
       strcat(filePath, fileName);
       if(doesFileExist(filePath)){
    return filePath;
 }
  i++;
   }
   strcpy(filePath, fileName);
   filePath = tildaToHome(filePath);
   filePath = realpath(filePath, ((void *)0));
   if( filePath != ((void *)0) ){
       return filePath;
   }
 return ((void *)0);
}

variable_types:
fileName
char *


repo: tsliwowicz/evented-http-server

decompiled_code:
void ctrl_c_handler()
{
http_server_stop(0LL);
}

canonical_decompiled_code:
void func0()
{
http_server_stop(0LL);
}

original_code:
static void ctrl_c_handler(int sig)
{
    http_server_stop(0);
}

variable_types: sig int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
http_server_init(argc, argv, envp);
http_server_start(8080LL, &handlers, 2LL, "/var/www");
signal(2, (__sighandler_t)ctrl_c_handler);
while ( (unsigned int)http_server_is_active() )
usleep(0x2710u);
fwrite("bye bye\n", 1uLL, 8uLL, stderr);
http_server_cleanup();
return 0;
}

original_code:
int main(int c, char **v)
{
    http_server_init();
 http_server_start(8080, handlers, sizeof(handlers)/sizeof(handlers[0]), "/var/www");
 signal (2,ctrl_c_handler);
 while (http_server_is_active())
 {
     usleep(10000);
 }
 fprintf(stderr, "bye bye\n");
 http_server_cleanup();
 return(0);
}

variable_types: c int

variable_types:
v
char **


repo: tspink/syssy

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
int v5; // ebp

puts("SYSSY - The System Simulator");
puts("Copyright (C) University of Edinburgh 2013\n");
v3 = system_create(default_mcu, &default_dcu);
if ( v3 )
{
v4 = v3;
v5 = system_run_simulation(v3);
if ( v5 )
puts("error: error whilst running simulation");
system_destroy(v4);
}
else
{
puts("error: unable to create system descriptor");
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
int v5; // ebp

puts("SYSSY - The System Simulator");
puts("Copyright (C) University of Edinburgh 2013\n");
v3 = system_create(default_mcu, &default_dcu);
if ( v3 )
{
v4 = v3;
v5 = func1(v3);
if ( v5 )
puts("error: error whilst running simulation");
func0(v4);
}
else
{
puts("error: unable to create system descriptor");
v5 = -1;
}
return v5;
}

original_code:
int main(int argc, char** argv)
{
    system_t *sys;
    int rc;
    printf("SYSSY - The System Simulator\n");
    printf("Copyright (C) University of Edinburgh 2013\n\n");
    sys = system_create(&default_mcu, &default_dcu);
    if (!sys) {
        printf("error: unable to create system descriptor\n");
        return -1;
    }
    rc = system_run_simulation(sys);
    if (rc) {
        printf("error: error whilst running simulation\n");
    }
    system_destroy(sys);
    return rc;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct _system *sys;
    int rc;
    printf("SYSSY - The System Simulator\n");
    printf("Copyright (C) University of Edinburgh 2013\n\n");
    sys = system_create(&default_mcu, &default_dcu);
    if (!sys) {
        printf("error: unable to create system descriptor\n");
        return -1;
    }
    rc = system_run_simulation(sys);
    if (rc) {
        printf("error: error whilst running simulation\n");
    }
    system_destroy(sys);
    return rc;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct _system { struct memctl_t { int (*init)(struct _system *system); int (*write)(struct _system *system, unsigned long addr, unsigned long long data, unsigned int size); int (*read)(struct _system *system, unsigned long addr, unsigned long long *data, unsigned int size); int (*install_handler)(struct _system *system, unsigned long base, unsigned long size, int (*callback)(int operation, unsigned long addr, unsigned long long *data)); } *memctl; void *memctl_priv; struct devctl_t { int (*init)(struct _system *system); } *devctl; void *devctl_priv; } *

variable_types: rc int

user_defined_types: struct _system { struct memctl_t *memctl; void *memctl_priv; struct devctl_t *devctl; void *devctl_priv; }


decompiled_code:
__int64 system_destroy()
{
return syssy_free();
}

canonical_decompiled_code:
__int64 func0()
{
return func3();
}

original_code:
void system_destroy(system_t *sys)
{
    syssy_free(sys);
}

canonical_original_code:
void system_destroy(struct _system *sys)
{
    syssy_free(sys);
}

user_defined_types: struct memctl_t { int (*init)(struct _system *system); int (*write)(struct _system *system, unsigned long addr, unsigned long long data, unsigned int size); int (*read)(struct _system *system, unsigned long addr, unsigned long long *data, unsigned int size); int (*install_handler)(struct _system *system, unsigned long base, unsigned long size, int (*callback)(int operation, unsigned long addr, unsigned long long *data)); }

user_defined_types: struct devctl_t { int (*init)(struct _system *system); }


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

v1 = (**a1)(a1);
if ( !v1 )
{
v1 = (*a1[2])(a1);
if ( !v1 )
fwrite("info: todo: implement system_run_simulation\n", 1uLL, 0x2CuLL, stderr);
}
return v1;
}

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

v1 = (**a1)(a1);
if ( !v1 )
{
v1 = (*a1[2])(a1);
if ( !v1 )
fwrite("info: todo: implement system_run_simulation\n", 1uLL, 0x2CuLL, stderr);
}
return v1;
}

original_code:
int system_run_simulation(system_t *sys)
{
    int rc;
    rc = sys->memctl->init(sys);
    if (rc)
        return rc;
    rc = sys->devctl->init(sys);
    if (rc)
        return rc;
    fprintf(stderr, "info: " "todo: implement system_run_simulation\n");
    return rc;
}

canonical_original_code:
int system_run_simulation(struct _system *sys)
{
    int rc;
    rc = sys->memctl->init(sys);
    if (rc)
        return rc;
    rc = sys->devctl->init(sys);
    if (rc)
        return rc;
    fprintf(stderr, "info: " "todo: implement system_run_simulation\n");
    return rc;
}


decompiled_code:
void *__fastcall syssy_alloc(size_t size, char a2)
{
void *result; // rax

if ( (a2 & 1) != 0 )
result = calloc(1uLL, (unsigned int)size);
else
result = malloc((unsigned int)size);
return result;
}

canonical_decompiled_code:
void *__fastcall func2(size_t size, char a2)
{
void *result; // rax

if ( (a2 & 1) != 0 )
result = calloc(1uLL, (unsigned int)size);
else
result = malloc((unsigned int)size);
return result;
}

original_code:
void *syssy_alloc(unsigned int size, syssy_alloc_flags_t flags)
{
    if (flags & ZEROMEM)
        return calloc(1, size);
    else
        return malloc(size);
}

canonical_original_code:
void *syssy_alloc(unsigned int size, enum syssy_alloc_flags_t flags)
{
    if (flags & ZEROMEM)
        return calloc(1, size);
    else
        return malloc(size);
}

variable_types:
size
unsigned int

variable_types: enum syssy_alloc_flags_t { NONE=0, ZEROMEM=1 }

return_type: void *


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

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

original_code:
void syssy_free(void *ptr)
{
    free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
__int64 mcu_install_handler()
{
fwrite("error: mcu_install_handler: not implemented", 1uLL, 0x2BuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
fwrite("error: mcu_install_handler: not implemented", 1uLL, 0x2BuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int mcu_install_handler(system_t *sys, sys_addr base, sys_addr length, memio_callback_t callback)
{
    struct mcu *mcu = get_mcu(sys);
    fprintf(stderr, "error: " "mcu_install_handler: not implemented");
    return -1;
}

canonical_original_code:
static int mcu_install_handler(struct _system *sys, unsigned long base, unsigned long length, int (*callback)(int operation, unsigned long addr, unsigned long long *data))
{
    struct mcu *mcu = get_mcu(sys);
    fprintf(stderr, "error: " "mcu_install_handler: not implemented");
    return -1;
}

variable_types:
base
unsigned long

variable_types:
length
unsigned long

variable_types: int (*)(int operation, unsigned long addr, unsigned long long *data)

variable_types: struct mcu { void *vmem; unsigned long size; } *


decompiled_code:
__int64 mcu_read()
{
fwrite("error: mcu_read: not implemented", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func5()
{
fwrite("error: mcu_read: not implemented", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int mcu_read(system_t *sys, sys_addr addr, sys_data *data, unsigned int size)
{
    struct mcu *mcu = get_mcu(sys);
    fprintf(stderr, "error: " "mcu_read: not implemented");
    return -1;
}

canonical_original_code:
static int mcu_read(struct _system *sys, unsigned long addr, unsigned long long *data, unsigned int size)
{
    struct mcu *mcu = get_mcu(sys);
    fprintf(stderr, "error: " "mcu_read: not implemented");
    return -1;
}

variable_types:
addr
unsigned long

variable_types:
data
unsigned long long *

user_defined_types: struct mcu { void *vmem; unsigned long size; }


decompiled_code:
__int64 mcu_write()
{
fwrite("error: mcu_write: not implemented", 1uLL, 0x21uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func6()
{
fwrite("error: mcu_write: not implemented", 1uLL, 0x21uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int mcu_write(system_t *sys, sys_addr addr, sys_data data, unsigned int size)
{
    struct mcu *mcu = get_mcu(sys);
    fprintf(stderr, "error: " "mcu_write: not implemented");
    return -1;
}

canonical_original_code:
static int mcu_write(struct _system *sys, unsigned long addr, unsigned long long data, unsigned int size)
{
    struct mcu *mcu = get_mcu(sys);
    fprintf(stderr, "error: " "mcu_write: not implemented");
    return -1;
}

variable_types:
data
unsigned long long


decompiled_code:
__int64 __fastcall mcu_init(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
void *v3; // rax
__int64 result; // rax

v1 = syssy_alloc(0x10uLL, 0);
if ( v1 )
{
v2 = v1;
v1[1] = 0xFFFFFFFFLL;
v3 = mmap(0LL, 0xFFFFFFFFuLL, 3, 2, -1, 0LL);
*v2 = v3;
if ( v3 )
{
*(_QWORD *)(a1 + 8) = v2;
result = 0LL;
}
else
{
fwrite("error: unable to map memory for virtual memory pool\n", 1uLL, 0x34uLL, stderr);
syssy_free(v2);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("error: unable to allocate memory for mcu private structure\n", 1uLL, 0x3BuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbx
void *v3; // rax
__int64 result; // rax

v1 = func2(0x10uLL, 0);
if ( v1 )
{
v2 = v1;
v1[1] = 0xFFFFFFFFLL;
v3 = mmap(0LL, 0xFFFFFFFFuLL, 3, 2, -1, 0LL);
*v2 = v3;
if ( v3 )
{
*(_QWORD *)(a1 + 8) = v2;
result = 0LL;
}
else
{
fwrite("error: unable to map memory for virtual memory pool\n", 1uLL, 0x34uLL, stderr);
func3(v2);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("error: unable to allocate memory for mcu private structure\n", 1uLL, 0x3BuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int mcu_init(system_t *sys)
{
    struct mcu *mcu;
    mcu = syssy_alloc(sizeof(struct mcu), NONE);
    if (!mcu) {
        fprintf(stderr, "error: " "unable to allocate memory for mcu private structure\n");
        return -1;
    }
    mcu->size = 0xFFFFFFFF;
    mcu->vmem = mmap(((void *)0), mcu->size, 0x1 | 0x2, 0x02, -1, 0);
    if (!mcu->vmem) {
        fprintf(stderr, "error: " "unable to map memory for virtual memory pool\n");
        syssy_free(mcu);
        return -1;
    }
    sys->memctl_priv = mcu;
    return 0;
}

canonical_original_code:
static int mcu_init(struct _system *sys)
{
    struct mcu *mcu;
    mcu = syssy_alloc(sizeof(struct mcu), NONE);
    if (!mcu) {
        fprintf(stderr, "error: " "unable to allocate memory for mcu private structure\n");
        return -1;
    }
    mcu->size = 0xFFFFFFFF;
    mcu->vmem = mmap(((void *)0), mcu->size, 0x1 | 0x2, 0x02, -1, 0);
    if (!mcu->vmem) {
        fprintf(stderr, "error: " "unable to map memory for virtual memory pool\n");
        syssy_free(mcu);
        return -1;
    }
    sys->memctl_priv = mcu;
    return 0;
}


decompiled_code:
__int64 __fastcall dcu_init(__int64 a1)
{
void *v1; // rax
__int64 result; // rax

v1 = syssy_alloc(4uLL, 0);
if ( v1 )
{
*(_QWORD *)(a1 + 24) = v1;
result = 0LL;
}
else
{
fwrite("error: unable to allocate memory for dcu private structure\n", 1uLL, 0x3BuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
void *v1; // rax
__int64 result; // rax

v1 = func2(4uLL, 0);
if ( v1 )
{
*(_QWORD *)(a1 + 24) = v1;
result = 0LL;
}
else
{
fwrite("error: unable to allocate memory for dcu private structure\n", 1uLL, 0x3BuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int dcu_init(system_t *sys)
{
    struct dcu *dcu;
    dcu = syssy_alloc(sizeof(*dcu), NONE);
    if (!dcu) {
        fprintf(stderr, "error: " "unable to allocate memory for dcu private structure\n");
        return -1;
    }
    sys->devctl_priv = dcu;
    return 0;
}

canonical_original_code:
static int dcu_init(struct _system *sys)
{
    struct dcu *dcu;
    dcu = syssy_alloc(sizeof(*dcu), NONE);
    if (!dcu) {
        fprintf(stderr, "error: " "unable to allocate memory for dcu private structure\n");
        return -1;
    }
    sys->devctl_priv = dcu;
    return 0;
}

variable_types:
dcu
struct dcu { int tag; } *


koyomi

repo: tsupo/tamo

decompiled_code:
int __fastcall koyomi(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, unsigned int a9, unsigned int a10, unsigned int a11)
{
__int64 v11; // r15
unsigned int v12; // ebp
unsigned int v13; // er14
unsigned int v14; // er12
int result; // eax
unsigned int v19; // [rsp+34h] [rbp-44h] BYREF
unsigned int v20; // [rsp+38h] [rbp-40h] BYREF
unsigned int v21[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v11 = absoluteFromGregorian(a3, a2, a1);
gregorianFromAbsolute(v11, v21, &v20, &v19);
v12 = v19;
v13 = v20;
v14 = v21[0];
printHeader(v19, v20, v21[0], a7, a8);
if ( (int)v12 <= 0 && a7 )
{
printf(format);
result = puts(aPAHrefTamoCgi);
}
else
{
printMainStatement(v12, v13, v14, a4, a5, a6, a9, a7);
printTableHeader(a7);
tamo_koyomi(v12, v13, v14, a4, a5, a6, v11, a7, a9, a11);
tamo_information(v12, v13, v14, v11, a7, a10);
printTableSeparator(a7);
tamo_solar((int)v12, (int)v13, (int)v14, a7);
tamo_igrf((int)v12, (int)v13, (int)v14, a7);
tamo_moon((int)v12, (int)v13, (int)v14, (int)a4, (int)a5, (int)a6, a7);
tamo_campaign(v12, v13, v14, v11, a7);
tamo_link(v12, v13, v14, a7);
printTableFooter(v12, v13, v14, a4, a5, a6, a7);
result = printFooter(a7, a8);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, unsigned int a8, unsigned int a9, unsigned int a10, unsigned int a11)
{
__int64 v11; // r15
unsigned int v12; // ebp
unsigned int v13; // er14
unsigned int v14; // er12
int result; // eax
unsigned int v19; // [rsp+34h] [rbp-44h] BYREF
unsigned int v20; // [rsp+38h] [rbp-40h] BYREF
unsigned int v21[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v11 = absoluteFromGregorian(a3, a2, a1);
gregorianFromAbsolute(v11, v21, &v20, &v19);
v12 = v19;
v13 = v20;
v14 = v21[0];
printHeader(v19, v20, v21[0], a7, a8);
if ( (int)v12 <= 0 && a7 )
{
printf(format);
result = puts(aPAHrefTamoCgi);
}
else
{
printMainStatement(v12, v13, v14, a4, a5, a6, a9, a7);
printTableHeader(a7);
tamo_koyomi(v12, v13, v14, a4, a5, a6, v11, a7, a9, a11);
tamo_information(v12, v13, v14, v11, a7, a10);
printTableSeparator(a7);
tamo_solar((int)v12, (int)v13, (int)v14, a7);
tamo_igrf((int)v12, (int)v13, (int)v14, a7);
tamo_moon((int)v12, (int)v13, (int)v14, (int)a4, (int)a5, (int)a6, a7);
tamo_campaign(v12, v13, v14, v11, a7);
tamo_link(v12, v13, v14, a7);
printTableFooter(v12, v13, v14, a4, a5, a6, a7);
result = printFooter(a7, a8);
}
return result;
}

original_code:
static void
koyomi( int yy, int mm, int dd, int HH, int MM, int SS,
        int htmlMode, int withHeader,
        int printTime, int printTrain, int printTsupo )
{
    int a1, a2, a3;
    long g;
    g = absoluteFromGregorian( dd, mm, yy );
    gregorianFromAbsolute( g, &a1, &a2, &a3 );
    yy = a3; mm = a2; dd = a1;
    printHeader( yy, mm, dd, htmlMode, withHeader );
    if ( (yy <= 0) && htmlMode ) {
        printf("
紀元前には対応していません。あしからず、ご了承ください。");
        printf("
戻る\n\n\n");
        return;
    }
    printMainStatement( yy, mm, dd, HH, MM, SS, printTime, htmlMode );
    printTableHeader( htmlMode );
    tamo_koyomi( yy, mm, dd, HH, MM, SS, g, htmlMode, printTime, printTsupo );
    tamo_information( yy, mm, dd, g, htmlMode, printTrain );
    printTableSeparator( htmlMode );
    tamo_solar( yy, mm, dd, htmlMode );
    tamo_igrf( yy, mm, dd, htmlMode );
    tamo_moon( yy, mm, dd, HH, MM, SS, htmlMode );
    tamo_campaign( yy, mm, dd, g, htmlMode );
    tamo_link( yy, mm, dd, htmlMode );
    printTableFooter( yy, mm, dd, HH, MM, SS, htmlMode );
    printFooter( htmlMode, withHeader );
}

canonical_original_code:
static void koyomi(int yy, int mm, int dd, int HH, int MM, int SS, int htmlMode, int withHeader, int printTime, int printTrain, int printTsupo)
{
    int a1; int a2; int a3;
    long g;
    g = absoluteFromGregorian( dd, mm, yy );
    gregorianFromAbsolute( g, &a1, &a2, &a3 );
    yy = a3; mm = a2; dd = a1;
    printHeader( yy, mm, dd, htmlMode, withHeader );
    if ( (yy <= 0) && htmlMode ) {
        printf("
紀元前には対応していません。あしからず、ご了承ください。");
        printf("
戻る\n\n\n");
        return;
    }
    printMainStatement( yy, mm, dd, HH, MM, SS, printTime, htmlMode );
    printTableHeader( htmlMode );
    tamo_koyomi( yy, mm, dd, HH, MM, SS, g, htmlMode, printTime, printTsupo );
    tamo_information( yy, mm, dd, g, htmlMode, printTrain );
    printTableSeparator( htmlMode );
    tamo_solar( yy, mm, dd, htmlMode );
    tamo_igrf( yy, mm, dd, htmlMode );
    tamo_moon( yy, mm, dd, HH, MM, SS, htmlMode );
    tamo_campaign( yy, mm, dd, g, htmlMode );
    tamo_link( yy, mm, dd, htmlMode );
    printTableFooter( yy, mm, dd, HH, MM, SS, htmlMode );
    printFooter( htmlMode, withHeader );
}

variable_types: yy int

variable_types: mm int

variable_types: dd int

variable_types: HH int

variable_types: MM int

variable_types: SS int

variable_types: htmlMode int

variable_types: withHeader int

variable_types: printTime int

variable_types: printTrain int

variable_types: printTsupo int

variable_types: g long


version

decompiled_code:
int version()
{
puts("Tsuporone's Activity MemO $Revision: 1.91 $ by H.Tsujimura");
puts("Bug reports are welcome. Send E-mail to:");
puts(" tsupo@na.rim.or.jp");
return putchar(10);
}

canonical_decompiled_code:
int func1()
{
puts("Tsuporone's Activity MemO $Revision: 1.91 $ by H.Tsujimura");
puts("Bug reports are welcome. Send E-mail to:");
puts(" tsupo@na.rim.or.jp");
return putchar(10);
}

original_code:
static void
version( void )
{
    printf( "Tsuporone's Activity MemO $Revision: 1.91 $ by H.Tsujimura\n" );
    printf( "Bug reports are welcome. Send E-mail to:\n" );
    printf( "  tsupo@na.rim.or.jp\n" );
    printf( "\n" );
}

canonical_original_code:
static void version()
{
    printf( "Tsuporone's Activity MemO $Revision: 1.91 $ by H.Tsujimura\n" );
    printf( "Bug reports are welcome. Send E-mail to:\n" );
    printf( "  tsupo@na.rim.or.jp\n" );
    printf( "\n" );
}


usage

decompiled_code:
int usage()
{
puts("Usage:");
puts(" tamo [-advAJTM] [{YYYY|yy}[mm[dd [HH[MM[SS]]]]]]]");
puts(" -A: print out all information, if possibble.");
puts(" -M: print out by HTML formatted text.");
puts(" YYYY: year (0001-9999)");
puts(" yy: year (00-99)");
puts(" mm: month (01-12)");
puts(" dd: day (01-31)");
puts(" HH: hour (00-23)");
puts(" MM: minute (00-59)");
puts(" SS: second (00-59)");
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
puts("Usage:");
puts(" tamo [-advAJTM] [{YYYY|yy}[mm[dd [HH[MM[SS]]]]]]]");
puts(" -A: print out all information, if possibble.");
puts(" -M: print out by HTML formatted text.");
puts(" YYYY: year (0001-9999)");
puts(" yy: year (00-99)");
puts(" mm: month (01-12)");
puts(" dd: day (01-31)");
puts(" HH: hour (00-23)");
puts(" MM: minute (00-59)");
puts(" SS: second (00-59)");
return putchar(10);
}

original_code:
static void
usage( void )
{
  printf("Usage:\n");
  printf("  tamo [-advAJTM] [{YYYY|yy}[mm[dd [HH[MM[SS]]]]]]]\n");
  printf("    -A: print out all information, if possibble.\n" );
  printf("    -M: print out by HTML formatted text.\n" );
  printf("    YYYY: year   (0001-9999)\n");
  printf("      yy: year   (00-99)\n");
  printf("      mm: month  (01-12)\n");
  printf("      dd: day    (01-31)\n");
  printf("      HH: hour   (00-23)\n");
  printf("      MM: minute (00-59)\n");
  printf("      SS: second (00-59)\n");
  printf("\n");
}

canonical_original_code:
static void usage()
{
  printf("Usage:\n");
  printf("  tamo [-advAJTM] [{YYYY|yy}[mm[dd [HH[MM[SS]]]]]]]\n");
  printf("    -A: print out all information, if possibble.\n" );
  printf("    -M: print out by HTML formatted text.\n" );
  printf("    YYYY: year   (0001-9999)\n");
  printf("      yy: year   (00-99)\n");
  printf("      mm: month  (01-12)\n");
  printf("      dd: day    (01-31)\n");
  printf("      HH: hour   (00-23)\n");
  printf("      MM: minute (00-59)\n");
  printf("      SS: second (00-59)\n");
  printf("\n");
}