decompiled_code:
__int64 __fastcall get_nbre_domaines(__int64 a1, int a2)
{
int v2; // eax
int v3; // er8
__int64 v4; // rdx
_BYTE *v5; // rax
_BYTE **v6; // rdx
__int64 result; // rax

v2 = nombreArguments();
if ( v2 == a2 )
{
puts("Hors du tableau");
v3 = 0;
}
else
{
v3 = 0;
if ( v2 > a2 )
{
v4 = 8LL * a2;
v5 = *(_BYTE **)(a1 + v4);
if ( v5 )
{
v6 = (_BYTE **)(a1 + v4 + 8);
while ( 1 )
{
if ( *v5 != 45 )
goto LABEL_5;
if ( v5[1] == 67 && !v5[2] )
goto LABEL_6;
if ( v5[1] == 76 && !v5[2] )
{
v5 = *v6++;
if ( !v5 )
break;
}
else
{
LABEL_5:
++v3;
LABEL_6:
v5 = *v6++;
if ( !v5 )
break;
}
}
}
}
}
if ( a2 )
result = v3 - (unsigned int)(a2 == 1);
else
result = (unsigned int)(v3 - 2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
int v3; // er8
__int64 v4; // rdx
_BYTE *v5; // rax
_BYTE **v6; // rdx
__int64 result; // rax

v2 = nombreArguments();
if ( v2 == a2 )
{
puts("Hors du tableau");
v3 = 0;
}
else
{
v3 = 0;
if ( v2 > a2 )
{
v4 = 8LL * a2;
v5 = *(_BYTE **)(a1 + v4);
if ( v5 )
{
v6 = (_BYTE **)(a1 + v4 + 8);
while ( 1 )
{
if ( *v5 != 45 )
goto LABEL_5;
if ( v5[1] == 67 && !v5[2] )
goto LABEL_6;
if ( v5[1] == 76 && !v5[2] )
{
v5 = *v6++;
if ( !v5 )
break;
}
else
{
LABEL_5:
++v3;
LABEL_6:
v5 = *v6++;
if ( !v5 )
break;
}
}
}
}
}
if ( a2 )
result = v3 - (unsigned int)(a2 == 1);
else
result = (unsigned int)(v3 - 2);
return result;
}

original_code:
int get_nbre_domaines(char *const argv[], int pos) {
    int nbdomaine = 0;
    int nbArg = nombreArguments(argv);
    if (pos == nbArg) {
        printf("Hors du tableau\n");
    }
    if (pos < nbArg) {
        while (*(argv + pos)) {
            nbdomaine++;
            if (!(strcmp(*(argv + pos), "-C")) || !(strcmp(*(argv + pos), "-L"))) {
                nbdomaine--;
            }
            argv++;
        }
    }
    if (pos == 0) {
        nbdomaine = nbdomaine - 2;
    }
    if (pos == 1) {
        nbdomaine--;
    }
    return nbdomaine;
}

canonical_original_code:
int get_nbre_domaines(char *argv[], int pos) {
    int nbdomaine = 0;
    int nbArg = nombreArguments(argv);
    if (pos == nbArg) {
        printf("Hors du tableau\n");
    }
    if (pos < nbArg) {
        while (*(argv + pos)) {
            nbdomaine++;
            if (!(strcmp(*(argv + pos), "-C")) || !(strcmp(*(argv + pos), "-L"))) {
                nbdomaine--;
            }
            argv++;
        }
    }
    if (pos == 0) {
        nbdomaine = nbdomaine - 2;
    }
    if (pos == 1) {
        nbdomaine--;
    }
    return nbdomaine;
}

variable_types:
argv
char *[]

variable_types: pos int

variable_types: nbdomaine int

variable_types: nbArg int


decompiled_code:
__int64 __fastcall get_debut(char *src, int *a2)
{
__int64 result; // rax
size_t v3; // rdx
void *v4; // rsp
char *v5; // rax
int v6; // er13
char *v7; // r14
char v8[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x36u, "get_debut");
if ( !a2 )
_assert_fail(
"debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"",
"mod_domaine.c",
0x37u,
"get_debut");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
v6 = strlen(src);
v7 = (char *)malloc(v6 + 1);
strncpy(v7, src, v6);
*a2 = atoi(v7);
free(v7);
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^[0-9]+-[0-9]+$)", src) )
{
strcpy(delim, "-");
v3 = (int)(strlen(src) + 1);
v4 = alloca(v3);
strncpy(v8, src, v3);
v5 = strtok(v8, delim);
*a2 = atoi(v5);
result = 1LL;
}
else
{
result = chercherDansChaine("(^-{1}[0-9]+$){1}", src);
if ( (_DWORD)result )
{
*a2 = 0;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int *a2)
{
__int64 result; // rax
size_t v3; // rdx
void *v4; // rsp
char *v5; // rax
int v6; // er13
char *v7; // r14
char v8[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x36u, "get_debut");
if ( !a2 )
_assert_fail(
"debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"",
"mod_domaine.c",
0x37u,
"get_debut");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
v6 = strlen(src);
v7 = (char *)malloc(v6 + 1);
strncpy(v7, src, v6);
*a2 = atoi(v7);
free(v7);
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^[0-9]+-[0-9]+$)", src) )
{
strcpy(delim, "-");
v3 = (int)(strlen(src) + 1);
v4 = alloca(v3);
strncpy(v8, src, v3);
v5 = strtok(v8, delim);
*a2 = atoi(v5);
result = 1LL;
}
else
{
result = chercherDansChaine("(^-{1}[0-9]+$){1}", src);
if ( (_DWORD)result )
{
*a2 = 0;
result = 1LL;
}
}
return result;
}

original_code:
int get_debut(char *domaine,int *debut){
  ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 54, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ; else __assert_fail ("debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"", "mod_domaine.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 if (chercherDansChaine("(^[0-9]+-$)",domaine))
 {
  int longueur=strlen(domaine)+1;
        char * debutStr=malloc(longueur*sizeof(char));
        strncpy(debutStr,domaine,longueur-1);
        *debut=(int)atoi(debutStr);
        free(debutStr);
        return 1;
 }
 else{
  if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
  {
    int longueur=strlen(domaine)+1;
             char delimiteur[2]="-";
             char domaineTab[longueur];
             strncpy(domaineTab,domaine,longueur);
             char * partie=strtok(domaineTab,delimiteur);
             *debut=(int)atoi(partie);
             return 1;
  }
  else{
   if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
   {
    *debut=0;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int get_debut(char *domaine, int *debut){
  ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 54, __extension__ __PRETTY_FUNCTION__); }));
     ((void) sizeof ((debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (debut!=((void *)0) && "ECHEC d'une precondition - debut doit etre alloue hors fonction") ; else __assert_fail ("debut!=NULL && \"ECHEC d'une precondition - debut doit etre alloue hors fonction\"", "mod_domaine.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 if (chercherDansChaine("(^[0-9]+-$)",domaine))
 {
  int longueur = strlen(domaine)+1;
        char *debutStr = malloc(longueur*sizeof(char));
        strncpy(debutStr,domaine,longueur-1);
        *debut=(int)atoi(debutStr);
        free(debutStr);
        return 1;
 }
 else{
  if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
  {
    int longueur = strlen(domaine)+1;
             char delimiteur[2] = "-";
             char domaineTab[-1];
             strncpy(domaineTab,domaine,longueur);
             char *partie = strtok(domaineTab,delimiteur);
             *debut=(int)atoi(partie);
             return 1;
  }
  else{
   if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
   {
    *debut=0;
    return 1;
   }
  }
 }
 return 0;
}

variable_types:
domaine
char *

variable_types:
debut
int *

variable_types: longueur int

variable_types:
debutStr
char *

variable_types:
delimiteur
char [2]

variable_types:
domaineTab
char [-1]

variable_types:
partie
char *

return_type: int


decompiled_code:
__int64 __fastcall get_fin(char *src, int *a2, int a3)
{
__int64 result; // rax
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
size_t v8; // r13
char *v9; // r14
char v10[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x5Fu, "get_fin");
if ( !a2 )
_assert_fail(
"fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"",
"mod_domaine.c",
0x60u,
"get_fin");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
*a2 = a3;
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^-{1}[0-9]+$){1}", src) )
{
v8 = (int)(strlen(src) + 1);
v9 = (char *)malloc(v8);
strncpy(v9, src + 1, v8);
*a2 = atoi(v9);
free(v9);
result = 1LL;
}
else
{
result = chercherDansChaine("(^[0-9]+-[0-9]+$)", src);
if ( (_DWORD)result )
{
strcpy(delim, "-");
v5 = (int)(strlen(src) + 1);
v6 = alloca(v5);
strncpy(v10, src, v5);
strtok(v10, delim);
v7 = strtok(0LL, delim);
*a2 = atoi(v7);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, int *a2, int a3)
{
__int64 result; // rax
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
size_t v8; // r13
char *v9; // r14
char v10[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

if ( !src )
_assert_fail("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 0x5Fu, "get_fin");
if ( !a2 )
_assert_fail(
"fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"",
"mod_domaine.c",
0x60u,
"get_fin");
if ( (unsigned int)chercherDansChaine("(^[0-9]+-$)", src) )
{
*a2 = a3;
result = 1LL;
}
else if ( (unsigned int)chercherDansChaine("(^-{1}[0-9]+$){1}", src) )
{
v8 = (int)(strlen(src) + 1);
v9 = (char *)malloc(v8);
strncpy(v9, src + 1, v8);
*a2 = atoi(v9);
free(v9);
result = 1LL;
}
else
{
result = chercherDansChaine("(^[0-9]+-[0-9]+$)", src);
if ( (_DWORD)result )
{
strcpy(delim, "-");
v5 = (int)(strlen(src) + 1);
v6 = alloca(v5);
strncpy(v10, src, v5);
strtok(v10, delim);
v7 = strtok(0LL, delim);
*a2 = atoi(v7);
result = 1LL;
}
}
return result;
}

original_code:
int get_fin(char *domaine,int *fin,int max){
 ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ; else __assert_fail ("fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"", "mod_domaine.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    if (chercherDansChaine("(^[0-9]+-$)",domaine))
    {
     *fin=(int)max;
     return 1;
    }
    else{
     if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
     {
              int longueur=strlen(domaine)+1;
                    char * finStr=malloc(longueur*sizeof(char));
                    strncpy(finStr,domaine+1,longueur);
                    *fin=(int)atoi(finStr);
                    free(finStr);
                    return 1;
     }
     else{
      if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
      {
       int longueur=strlen(domaine)+1;
                char delimiteur[2]="-";
                   char domaineTab[longueur];
                   strncpy(domaineTab,domaine,longueur);
                   char * partie=strtok(domaineTab,delimiteur);
                   partie=strtok(((void *)0),delimiteur);
                   *fin=(int)atoi(partie);
                   return 1;
      }
     }
    }
    return 0;
}

canonical_original_code:
int get_fin(char *domaine, int *fin, int max){
 ((void) sizeof ((domaine!=((void *)0) && "le domaine est obligatoire") ? 1 : 0), __extension__ ({ if (domaine!=((void *)0) && "le domaine est obligatoire") ; else __assert_fail ("domaine!=NULL && \"le domaine est obligatoire\"", "mod_domaine.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ? 1 : 0), __extension__ ({ if (fin!=((void *)0) && "ECHEC d'une precondition - fin doit etre alloue hors fonction") ; else __assert_fail ("fin!=NULL && \"ECHEC d'une precondition - fin doit etre alloue hors fonction\"", "mod_domaine.c", 96, __extension__ __PRETTY_FUNCTION__); }));
    if (chercherDansChaine("(^[0-9]+-$)",domaine))
    {
     *fin=(int)max;
     return 1;
    }
    else{
     if (chercherDansChaine("(^-{1}[0-9]+$){1}",domaine))
     {
              int longueur = strlen(domaine)+1;
                    char *finStr = malloc(longueur*sizeof(char));
                    strncpy(finStr,domaine+1,longueur);
                    *fin=(int)atoi(finStr);
                    free(finStr);
                    return 1;
     }
     else{
      if (chercherDansChaine("(^[0-9]+-[0-9]+$)",domaine))
      {
       int longueur = strlen(domaine)+1;
                char delimiteur[2] = "-";
                   char domaineTab[-1];
                   strncpy(domaineTab,domaine,longueur);
                   char *partie = strtok(domaineTab,delimiteur);
                   partie=strtok(((void *)0),delimiteur);
                   *fin=(int)atoi(partie);
                   return 1;
      }
     }
    }
    return 0;
}

variable_types:
fin
int *

variable_types: max int

variable_types:
finStr
char *


nombreArguments

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

for ( result = 0LL; *a1; result = (unsigned int)(result + 1) )
++a1;
return result;
}

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

for ( result = 0LL; *a1; result = (unsigned int)(result + 1) )
++a1;
return result;
}

original_code:
int nombreArguments(char *const argv[]){
 int nombre=0;
 while(*argv){
  nombre++;
  argv++;
 }
 return nombre;
}

canonical_original_code:
int nombreArguments(char *argv[]){
 int nombre = 0;
 while(*argv){
  nombre++;
  argv++;
 }
 return nombre;
}

variable_types: nombre int


chercherOption

original_code:
int chercherOption(char *const argv[],char option){
 int i=0;
 int occurences=0;
 int pos=0;
 option=toupper(option);
 if (option=='L')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-L"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='C')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-C"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='V')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-V"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='H')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-H"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else{
  signaler(3);
 }
 if (occurences>1)
 {
  signaler(3);
  return -1;
 }
 return pos;
}

canonical_original_code:
int chercherOption(char *argv[], char option){
 int i = 0;
 int occurences = 0;
 int pos = 0;
 option=toupper(option);
 if (option=='L')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-L"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='C')
 {
   while (*argv) {
            if (!(strcmp(*argv, "-C"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='V')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-V"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else if (option=='H')
 {
  while (*argv) {
            if (!(strcmp(*argv, "-H"))) {
                pos = i;
                occurences++;
            }
            argv++;
            i++;
        }
 }
 else{
  signaler(3);
 }
 if (occurences>1)
 {
  signaler(3);
  return -1;
 }
 return pos;
}

variable_types: option char

variable_types: i int

variable_types: occurences int


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

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
LODWORD(result) = 0;
do
result = (unsigned int)result - ((*a1++ == 0LL) - 1);
while ( a1 != (_QWORD *)v2 );
return result;
}

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

if ( a2 <= 0 )
return 0LL;
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
LODWORD(result) = 0;
do
result = (unsigned int)result - ((*a1++ == 0LL) - 1);
while ( a1 != (_QWORD *)v2 );
return result;
}

original_code:
int compteur_Lignes(char ** vecteur, int nbL) {
    int nb = 0;
    int i = 0;
    for (; i < nbL; i++) {
        if (vecteur[i] != 0) {
            nb++;
        }
    }
    return nb;
}

canonical_original_code:
int compteur_Lignes(char **vecteur, int nbL) {
    int nb = 0;
    int i = 0;
    for (; i < nbL; i++) {
        if (vecteur[i] != 0) {
            nb++;
        }
    }
    return nb;
}

variable_types:
vecteur
char **

variable_types: nbL int

variable_types: nb int


signaler

decompiled_code:
size_t __fastcall signaler(int a1)
{
size_t result; // rax

switch ( a1 )
{
case 0:
result = fwrite("Erreur d'ouverture du fichier.\n", 1uLL, 0x1FuLL, stderr);
break;
case 1:
result = fwrite("Le fichier ne comporte aucune donnee.\n", 1uLL, 0x26uLL, stderr);
break;
case 2:
result = fwrite("Erreur de syntaxe dans un domaine.\n", 1uLL, 0x23uLL, stderr);
break;
case 3:
result = fwrite("Erreur dans une option.\n", 1uLL, 0x18uLL, stderr);
break;
case 4:
result = fwrite("Tableau vide!\n", 1uLL, 0xEuLL, stderr);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(int a1)
{
size_t result; // rax

switch ( a1 )
{
case 0:
result = fwrite("Erreur d'ouverture du fichier.\n", 1uLL, 0x1FuLL, stderr);
break;
case 1:
result = fwrite("Le fichier ne comporte aucune donnee.\n", 1uLL, 0x26uLL, stderr);
break;
case 2:
result = fwrite("Erreur de syntaxe dans un domaine.\n", 1uLL, 0x23uLL, stderr);
break;
case 3:
result = fwrite("Erreur dans une option.\n", 1uLL, 0x18uLL, stderr);
break;
case 4:
result = fwrite("Tableau vide!\n", 1uLL, 0xEuLL, stderr);
break;
default:
return result;
}
return result;
}

original_code:
void signaler(int code){
 switch (code)
    {
        case 0 :
            fprintf(stderr,"Erreur d'ouverture du fichier.\n");
        break;
        case 2 :
            fprintf(stderr,"Erreur de syntaxe dans un domaine.\n");
            break;
        case 3 :
                fprintf(stderr,"Erreur dans une option.\n");
                break;
        case 1 :
            fprintf(stderr,"Le fichier ne comporte aucune donnee.\n");
            break;
        case 4 :
            fprintf(stderr,"Tableau vide!\n");
            break;
        default :
            break;
    }
}

variable_types: code int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rbp
__int64 v14; // r12
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rdi
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rdi
__int64 v22; // rbp
__int64 v23; // rax
__int64 v24; // rbp
__int64 v25; // r14
__int64 v26; // rax
__int64 v27; // rbp
__int64 v28; // rax
__int64 v29; // rbp
__int64 v30; // r13
__int64 v31; // rax
__int64 v32; // rbp
__int64 v33; // rax
__int64 v34; // rbp
__int64 v35; // rax
__int64 v36; // r15
__int64 v37; // rbp
__int64 v38; // rax
__int64 v39; // r15
__int64 v40; // rax
__int64 v41; // rax
__int64 v42; // rax
__int64 v43; // rax
__int64 v44; // rax
__int64 v45; // rax
__int64 v46; // rax
__int64 v47; // rax
__int64 v48; // rbp
__int64 v49; // rax
__int64 v50; // rbp
__int64 v51; // rax
__int64 v52; // rax
__int64 v53; // rdi
__int64 v54; // rbp
__int64 v55; // rax
const char **v57; // [rsp+0h] [rbp-68h] BYREF
int v58; // [rsp+Ch] [rbp-5Ch] BYREF
char v59[88]; // [rsp+10h] [rbp-58h] BYREF

v58 = argc;
v57 = argv;
gtk_init(&v58, &v57, envp);
v3 = gtk_window_new(0LL);
wMain[0] = v3;
v4 = gtk_window_get_type();
v5 = g_type_check_instance_cast(v3, v4);
gtk_window_set_position(v5, 0LL);
v6 = g_type_check_instance_cast(wMain[0], v4);
gtk_window_set_default_size(v6, 1024LL, 600LL);
v7 = g_type_check_instance_cast(wMain[0], v4);
gtk_window_set_title(v7, "ext3Viewer GUI");
v8 = gdk_pixbuf_new_from_file("/usr/local/share/ext3Viewer//img/icon.png", 0LL);
wMain[1] = v8;
gtk_window_set_default_icon(v8);
g_object_unref(wMain[1]);
v9 = g_type_check_instance_cast(wMain[0], 80LL);
g_signal_connect_data(v9, "destroy", &onQuit, 0LL, 0LL, 0LL);
v10 = gtk_vbox_new(0LL, 0LL);
wMain[3] = v10;
v11 = gtk_container_get_type();
v12 = g_type_check_instance_cast(wMain[0], v11);
gtk_container_add(v12, v10);
v13 = createMenu(wMain[0]);
wMain[5] = v13;
v14 = gtk_box_get_type();
v15 = g_type_check_instance_cast(wMain[3], v14);
gtk_box_pack_start(v15, v13, 0LL, 0LL, 0LL);
v16 = gtk_hseparator_new();
v17 = wMain[3];
v18 = v16;
wMain[8] = v16;
v19 = g_type_check_instance_cast(v17, v14);
gtk_box_pack_start(v19, v18, 0LL, 0LL, 0LL);
v20 = create_search(v59);
v21 = wMain[3];
v22 = v20;
wMain[11] = v20;
v23 = g_type_check_instance_cast(v21, v14);
gtk_box_pack_start(v23, v22, 0LL, 0LL, 0LL);
v24 = gtk_hpaned_new();
wMain[2] = v24;
v25 = gtk_paned_get_type();
v26 = g_type_check_instance_cast(v24, v25);
gtk_paned_set_position(v26, 470LL);
v27 = wMain[2];
v28 = g_type_check_instance_cast(wMain[3], v14);
gtk_box_pack_start(v28, v27, 1LL, 1LL, 0LL);
*(&centre + 2) = create_tree();
v29 = gtk_scrolled_window_new(0LL, 0LL);
*(&centre + 1) = v29;
v30 = gtk_scrolled_window_get_type();
v31 = g_type_check_instance_cast(v29, v30);
gtk_scrolled_window_set_policy(v31, 1LL, 1LL);
v32 = *(&centre + 2);
v33 = g_type_check_instance_cast(*(&centre + 1), v30);
gtk_scrolled_window_add_with_viewport(v33, v32);
v34 = *(&centre + 1);
v35 = g_type_check_instance_cast(wMain[2], v25);
gtk_paned_add1(v35, v34);
v36 = gtk_text_view_new();
centre = v36;
v37 = gtk_text_view_get_type();
v38 = g_type_check_instance_cast(v36, v37);
v39 = gtk_text_view_get_buffer(v38);
v40 = g_type_check_instance_cast(centre, v37);
gtk_text_view_set_wrap_mode(v40, 2LL);
v41 = g_type_check_instance_cast(centre, v37);
gtk_text_view_set_editable(v41, 0LL);
v42 = g_type_check_instance_cast(centre, v37);
gtk_text_view_set_cursor_visible(v42, 0LL);
v43 = g_type_check_instance_cast(centre, v37);
gtk_text_view_set_pixels_below_lines(v43, 5LL);
v44 = g_type_check_instance_cast(centre, v37);
gtk_text_view_set_left_margin(v44, 10LL);
v45 = g_type_check_instance_cast(centre, v37);
gtk_text_view_set_right_margin(v45, 10LL);
init_tags(v39);
v46 = gtk_scrolled_window_new(0LL, 0LL);
*(&centre + 1) = v46;
v47 = g_type_check_instance_cast(v46, v30);
gtk_scrolled_window_set_policy(v47, 2LL, 1LL);
v48 = centre;
v49 = g_type_check_instance_cast(*(&centre + 1), v30);
gtk_scrolled_window_add_with_viewport(v49, v48);
v50 = *(&centre + 1);
v51 = g_type_check_instance_cast(wMain[2], v25);
gtk_paned_add2(v51, v50);
v52 = gtk_statusbar_new();
v53 = wMain[3];
v54 = v52;
wMain[10] = v52;
v55 = g_type_check_instance_cast(v53, v14);
gtk_box_pack_start(v55, v54, 0LL, 0LL, 0LL);
gtk_widget_show_all(wMain[0]);
unk_7F0[1] = 0;
gtk_main();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
  struct ext3_super_block sb;
  struct ext3_inode i;
  struct ext3_group_desc gd;
  struct journal_superblock_s jsb;
  char *inodebitmap,*datablockbitmap;
  char c;
  char *block;
  int cc;
  int block_size;
  __u16 gd_num;
  __u32 inode_num;
  __u32 block_num;
  __u16 group_count;
  int fd;
  char pattern[255];
  long long int ret;
  ;
  ;
  if ( argc == 2 && !strcmp( argv[1], "-help" ) ) {
    printf("Usage: %s <FILESYSTEM> OPTION ARG1 [ ARG2 ... ]\n\n Dumps and interprets informations about ext3 filesystems.\n (in all this help, is the ext3 filesystem. ex: /dev/hda2)\n\n <FILESYSTEM> is the ext3 filesystem to examinate, could be a device or\n                 a image file. eg: /dev/hda2, /dev/sda3, ./image.ext3\n\n OPTION and ARGS are shown below :\n\t-stats [ <block num> <block size> ]\n\t                           info about the superblock and the group\n\t                           descriptors. if you specify a block number\n\t                           and a block size, it will read an alternate \n\t                           superblock. see -backups\n\n\t-stat  <inode num>         show the inode structure contents\n\t-bpoint  <block num>       display a block as a pointer of blocks\n\t-printgd  <group num>      dump the group_desc structure of a group\n\n\n\t-tree  <inode num>         show the form of an inode block allocation\n\t-imap  <group_desc num>    print the inode bitmap as an array\n\t-bmap  <group_desc num>    print the block bitmap as an array\n\t-ffi                       find the first free inode thanks to the\n\t                           bitmap\n\t-ffb                       find the first free block\n\n\n\t-cat  <inode num>  [ -x ]  dump the contents of a file.(read all the\n\t                           blocks). -x for hexa.\n\t-bcat  <block num> [ -x ]  dump the contents of a block.(read just one\n\t                           block) -x for hexa.\n\n\n\t-ls  <inode num>           print the directory entries of an inode.\n\t                           the root has inode number 2.\n\n\t-find  <inode_dir starting number> <regex pattern>\n\t                           find files recursively from a given directory\n\t                           that matches a regex pattern. for / type 2\n\n\t-iname  <inode num>        find all the files that have the given inode\n\n\t-backups                   calculate where the copies of the\n\t                           superblock are\n\n\n\t-jbd                       dump the journal contents.\n\n\n\t-help                      display this help. see also the man page\n\n See the man page for more details.\n\next3Viewer 1.0.2 GNU public license\nCopyright (C) 2013 Laurent Sebag\nCopyright (C) 2007 Laurent Sebag & Nathan Periana\ne2view (2003) Julien Poitrat, original idea\n", argv[0]);
    return 0;
  }
  else if ( argc < 3 ) {
    printf("Usage: %s <fd>  \n               [ -stats   | -stat | -printgd | -imap | -bmap | -ffi   |\n                 -ffb     | -cat  | -bcat    | -ls   | -find | -iname |\n                 -backups | -jbd  | -bpoint  | -tree ]\n'%s -help' for help.\nversion: ext3Viewer 1.0.2\n", argv[0], argv[0]);
    return 1;
  }
  else if ( !strcmp( argv[2], "-stats" ) ) {
    if ( argc != 5 && argc != 3 ) {
      printf("usage %s <filesystem> -stats [ <block number> <block size> ]\n",
          argv[0]);
      return 1;
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    if ( argc == 3 ) {
      ret = read_superblock( fd, &sb );
    }
    else {
      block_num = strtoul ( argv[3], ((void *)0), 10 );
      block_size = strtoul ( argv[4], ((void *)0), 10 );
      ret = read_superblock_backup( fd, &sb, block_num, block_size );
    }
    if ( ret == -1 )
      return 1;
    print_superblock( &sb );
    close_fs ( fd );
  }
  else if( !strcmp( argv[2], "-ls" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -ls <inode number>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 )
      exit(1);
    read_inode( fd, &sb, inode_num, &i);
    if ( !((((i.i_mode)) & 0170000) == (0040000)) ) {
      printf("WARNING: This inode does not seem to be a directory\n");
      printf("         seeing it as a directory could lead to impre-\n"
          "         dictable consequences\n");
      printf("continue anyway (y/n) ? ");
      c = getchar();
      if ( c == 'y' ) {
        print_dir( fd, &sb, inode_num );
      }
    }
    else {
      print_dir( fd, &sb, inode_num );
    }
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-stat" ) ) {
    if ( argc != 4 ) {
      printf("usage %s <filesystem> -stat <inode number>\n", argv[0]);
      exit(1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "Superblock read error\n");
      return 1;
    }
    if ( ret == -2 )
      return 0;
    read_inode ( fd, &sb, inode_num, &i );
    printf("+------------------------------------------------------------------------------+\n");
    printf("\t\t\tEXT3_INODE STRUCTURE OF INODE #%u\n", inode_num);
    printf("+------------------------------------------------------------------------------+\n");
    print_inode(fd,&sb, &i);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-tree" ) ) {
    if ( argc != 4 ) {
      printf("usage %s <filesystem> -tree <inode number>\n", argv[0]);
      exit(1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "Superblock read error\n");
      return 1;
    }
    if ( ret == -2 )
      return 0;
    read_inode ( fd, &sb, inode_num, &i );
    print_tree(fd,&sb, &i);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-bpoint" ) ) {
    if ( argc != 4 ) {
      printf("usage %s <filesystem> -bpoint <block num>\n", argv[0]);
      exit(1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    block_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "read_superblock\n");
      exit(1);
    }
    print_block_as_bpointer( fd, &sb, block_num );
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-bcat" ) ) {
    if ( argc != 4 && argc != 5 ) {
      printf("syntax: %s <filesystem> -bcat <block number> -x\n", argv[0]);
      exit (1);
    }
    block_num = strtoul ( argv[3], ((void *)0), 10 );
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10 );
    read_superblock( fd, &sb );
    if ( argc == 5 && !strcmp("-x", argv[4]) ) {
      printf("+------------------------------------------------------------------------------+\n");
      printf("\t\t\tSHOWING BLOCK #%u IN HEXADECIMAL\n", block_num );
      printf("+------------------------------------------------------------------------------+\n");
      print_block_hexa( fd, &sb, block_num );
      printf("+------------------------------------------------------------------------------+\n");
    }
    else if ( argc == 4 ) {
      block = malloc ( (1024 << (&sb)->s_log_block_size) );
      ret = read_block(fd, &sb, block_num, block );
      if ( ret == -1 )
        exit(1);
      for ( cc = 0 ; cc < (1024 << (&sb)->s_log_block_size) ; cc++ ) {
        putchar(block[cc]);
      }
      free(block);
      close_fs ( fd );
    }
    else {
      printf("syntax: %s <filesystem> -bcat <block number> -x\n", argv[0]);
    }
  }
  else if ( !strcmp( argv[2], "-cat" ) ) {
    if ( argc != 4 && argc != 5 ) {
      printf("syntax: %s <filesystem> -cat <inode number> [ -x ]\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10 );
    read_superblock( fd, &sb );
    read_inode( fd, &sb, inode_num, &i);
    if ( ((((i.i_mode)) & 0170000) == (0040000)) ) {
      printf("This inode is a directory, you should use -ls instead.\n");
      printf("use it anyway (y/n) ? ");
      c = getchar();
      if ( c != 'y') {
        close_fs(fd);
        return 0;
      }
    }
    else if ( ((((i.i_mode)) & 0170000) == (0120000)) ) {
      print_symlink( fd, &sb, inode_num);
      close_fs(fd);
      return 0;
    }
    if ( argc == 5 && !strcmp(argv[4],"-x") ) {
      printf("+------------------------------------------------------------------------------+\n");
      printf("\t\tDUMPING FILE WITH INODE #%u IN HEXADECIMAL\n", inode_num );
      printf("+------------------------------------------------------------------------------+\n");
      print_file ( fd, &sb, inode_num, 0 );
      printf("+------------------------------------------------------------------------------+\n");
    }
    else if ( argc == 4 )
      print_file ( fd, &sb, inode_num, 1 );
    else
      printf("syntax: %s <filesystem> -cat <inode number> [ -x ]\n", argv[0]);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-iname" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -iname <inode num>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10 );
    read_superblock( fd, &sb );
    search_inode ( fd, &sb, 2, inode_num );
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-find" ) ) {
    if ( argc != 5 ) {
      printf("syntax: %s <filesystem> -find <inode num of the parent dir>"
          " <regex pattern>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10);
    strcpy ( pattern, argv[4] );
    read_superblock( fd, &sb );
    read_inode( fd, &sb, inode_num, &i);
    if ( !((((i.i_mode)) & 0170000) == (0040000)) ) {
      printf("usage: -find <inode of the dir where the search begin> "
          "<pattern>\n");
      printf("The inode you specified is not a directory. Please specify\n");
      printf("an inode of a directory (eg. \"/\" has inode number 2)\n");
    }
    else {
      search_file ( fd, &sb, inode_num, pattern );
    }
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-imap" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -imap <group_descriptor_num>\n", argv[0]);
      exit (1);
    }
    gd_num =(__u16) atoi(argv[3]);
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    group_count = sb.s_blocks_count/((&sb)->s_blocks_per_group);
    if( gd_num >= group_count && gd_num != 0 )
    {
      printf("WARNING: Group descriptor %d entered seems to be "
          "inexistant.\n", gd_num);
      printf("(Existing group descriptors: from num. %d to num. %d,"
          " total %d)\n", 0, group_count == 0?0:group_count-1, group_count);
      printf("Proceed anyway? (y/n)");
      if(getchar()!='y')
      {
        exit(0);
      }
    }
    read_group_desc( fd, &sb, gd_num, &gd);
    inodebitmap = malloc( ((&sb)->s_inodes_per_group)/8 );
    read_inodebitmap( fd, &sb, &gd, inodebitmap);
    print_inodebitmap(&sb, inodebitmap, gd_num);
    free((void *)inodebitmap);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-bmap" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -bmap <group_descriptor_num>\n", argv[0]);
      exit (1);
    }
    gd_num =(__u16) atoi(argv[3]);
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    group_count = sb.s_blocks_count/((&sb)->s_blocks_per_group);
    if( gd_num >= group_count && gd_num != 0 )
    {
      printf("WARNING: Group descriptor %u entered seems to be inexistant.\n",
          gd_num);
      printf("(Existing group descriptors: from num. %u to num. %u,"
          " total %u)\n", 0, group_count == 0?0:group_count-1, group_count);
      printf("Proceed anyway? (y/n)");
      if(getchar()!='y')
      {
        exit(0);
      }
    }
    read_group_desc( fd, &sb, gd_num, &gd);
    datablockbitmap = malloc( ((&sb)->s_blocks_per_group)/8 );
    read_datablockbitmap( fd, &sb, &gd, gd_num, datablockbitmap);
    print_datablockbitmap(&sb, datablockbitmap, gd_num);
    free((void *)datablockbitmap);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-ffi" ) ) {
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    inodebitmap = malloc( (((&sb)->s_inodes_per_group)/8) );
    inode_num = search_first_free_inode(fd, &sb, inodebitmap);
    if(inode_num>0)
    {
      printf("First Free Inode found: %u\n", inode_num);
    }
    else
    {
      printf("No free inode found\n");
    }
    free(inodebitmap);
    close_fs(fd);
  }
  else if ( !strcmp( argv[2], "-ffb" ) ) {
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    datablockbitmap = malloc( (((&sb)->s_blocks_per_group)/8) );
    block_num = search_first_free_block(fd, &sb, datablockbitmap);
    if(block_num>0)
    {
      printf("First Free Block found: %u\n", block_num);
    }
    else
    {
      printf("No free block found\n");
    }
    free( datablockbitmap );
    close_fs(fd);
  }
  else if ( !strcmp( argv[2], "-jbd" ) ) {
    if ( argc != 3 ) {
      printf("syntax: %s <filesystem> -jbd\n", argv[0]);
      return 1;
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "superblock read error\n");
      exit(1);
    }
    else if ( ret == -2 ) {
      exit(0);
    }
    read_inode ( fd, &sb, sb.s_journal_inum, &i );
    read_journal_superblock( fd, (1024 << (&sb)->s_log_block_size), i.i_block[0], &jsb );
    printf("+------------------------------------------------------------------------------+\n");
    printf("\t\t\t\tJOURNAL SUPERBLOCK\n");
    printf("+------------------------------------------------------------------------------+\n""\n");
    print_journal_superblock(&jsb);
    printf("+------------------------------------------------------------------------------+\n");
    printf("\t\t\t\tJOURNAL CONTENTS\n");
    printf("+------------------------------------------------------------------------------+\n""\n");
    if ( jsb.s_start == 0 ) {
      printf("The journal is empty ! Dumping old transactions :\n");
    }
    dump_journal( fd, (1024 << (&sb)->s_log_block_size), &i );
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-printgd" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -printgd <group num>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    gd_num = (__u16) atoi(argv[3]);
    read_superblock( fd, &sb );
    group_count = sb.s_blocks_count/((&sb)->s_blocks_per_group);
    if ( gd_num > group_count ) {
      printf("WARNING: Group descriptor %d entered seems to be ", gd_num);
      printf("inexistant.\n");
      printf("(Existing group descriptors: from num. %d to num. %d,"
          " total %d)\n", 0, group_count, group_count+1);
      printf("Proceed anyway? (y/n) ");
      c = getchar();
      if ( c != 'y' )
        return 0;
    }
    read_group_desc( fd, &sb, gd_num, &gd);
    print_groupdesc ( &gd);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-backups" ) ) {
    if ( argc != 3 ) {
      printf("syntax: %s <filesystem> -backups\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    print_sb_copy ( &sb );
    close_fs ( fd );
  }
  else {
    printf("Usage: %s <fd>  \n               [ -stats   | -stat | -printgd | -imap | -bmap | -ffi   |\n                 -ffb     | -cat  | -bcat    | -ls   | -find | -iname |\n                 -backups | -jbd  | -bpoint  | -tree ]\n'%s -help' for help.\nversion: ext3Viewer 1.0.2\n", argv[0], argv[0]);
    return 1;
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct ext3_super_block sb;
  struct ext3_inode i;
  struct ext3_group_desc gd;
  struct journal_superblock_s jsb;
  char *inodebitmap; char *datablockbitmap;
  char c;
  char *block;
  int cc;
  int block_size;
  unsigned short gd_num;
  unsigned int inode_num;
  unsigned int block_num;
  unsigned short group_count;
  int fd;
  char pattern[255];
  long long ret;
  ;
  ;
  if ( argc == 2 && !strcmp( argv[1], "-help" ) ) {
    printf("Usage: %s <FILESYSTEM> OPTION ARG1 [ ARG2 ... ]\n\n Dumps and interprets informations about ext3 filesystems.\n (in all this help, is the ext3 filesystem. ex: /dev/hda2)\n\n <FILESYSTEM> is the ext3 filesystem to examinate, could be a device or\n                 a image file. eg: /dev/hda2, /dev/sda3, ./image.ext3\n\n OPTION and ARGS are shown below :\n\t-stats [ <block num> <block size> ]\n\t                           info about the superblock and the group\n\t                           descriptors. if you specify a block number\n\t                           and a block size, it will read an alternate \n\t                           superblock. see -backups\n\n\t-stat  <inode num>         show the inode structure contents\n\t-bpoint  <block num>       display a block as a pointer of blocks\n\t-printgd  <group num>      dump the group_desc structure of a group\n\n\n\t-tree  <inode num>         show the form of an inode block allocation\n\t-imap  <group_desc num>    print the inode bitmap as an array\n\t-bmap  <group_desc num>    print the block bitmap as an array\n\t-ffi                       find the first free inode thanks to the\n\t                           bitmap\n\t-ffb                       find the first free block\n\n\n\t-cat  <inode num>  [ -x ]  dump the contents of a file.(read all the\n\t                           blocks). -x for hexa.\n\t-bcat  <block num> [ -x ]  dump the contents of a block.(read just one\n\t                           block) -x for hexa.\n\n\n\t-ls  <inode num>           print the directory entries of an inode.\n\t                           the root has inode number 2.\n\n\t-find  <inode_dir starting number> <regex pattern>\n\t                           find files recursively from a given directory\n\t                           that matches a regex pattern. for / type 2\n\n\t-iname  <inode num>        find all the files that have the given inode\n\n\t-backups                   calculate where the copies of the\n\t                           superblock are\n\n\n\t-jbd                       dump the journal contents.\n\n\n\t-help                      display this help. see also the man page\n\n See the man page for more details.\n\next3Viewer 1.0.2 GNU public license\nCopyright (C) 2013 Laurent Sebag\nCopyright (C) 2007 Laurent Sebag & Nathan Periana\ne2view (2003) Julien Poitrat, original idea\n", argv[0]);
    return 0;
  }
  else if ( argc < 3 ) {
    printf("Usage: %s <fd>  \n               [ -stats   | -stat | -printgd | -imap | -bmap | -ffi   |\n                 -ffb     | -cat  | -bcat    | -ls   | -find | -iname |\n                 -backups | -jbd  | -bpoint  | -tree ]\n'%s -help' for help.\nversion: ext3Viewer 1.0.2\n", argv[0], argv[0]);
    return 1;
  }
  else if ( !strcmp( argv[2], "-stats" ) ) {
    if ( argc != 5 && argc != 3 ) {
      printf("usage %s <filesystem> -stats [ <block number> <block size> ]\n",
          argv[0]);
      return 1;
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    if ( argc == 3 ) {
      ret = read_superblock( fd, &sb );
    }
    else {
      block_num = strtoul ( argv[3], ((void *)0), 10 );
      block_size = strtoul ( argv[4], ((void *)0), 10 );
      ret = read_superblock_backup( fd, &sb, block_num, block_size );
    }
    if ( ret == -1 )
      return 1;
    print_superblock( &sb );
    close_fs ( fd );
  }
  else if( !strcmp( argv[2], "-ls" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -ls <inode number>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 )
      exit(1);
    read_inode( fd, &sb, inode_num, &i);
    if ( !((((i.i_mode)) & 0170000) == (0040000)) ) {
      printf("WARNING: This inode does not seem to be a directory\n");
      printf("         seeing it as a directory could lead to impre-\n"
          "         dictable consequences\n");
      printf("continue anyway (y/n) ? ");
      c = getchar();
      if ( c == 'y' ) {
        print_dir( fd, &sb, inode_num );
      }
    }
    else {
      print_dir( fd, &sb, inode_num );
    }
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-stat" ) ) {
    if ( argc != 4 ) {
      printf("usage %s <filesystem> -stat <inode number>\n", argv[0]);
      exit(1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "Superblock read error\n");
      return 1;
    }
    if ( ret == -2 )
      return 0;
    read_inode ( fd, &sb, inode_num, &i );
    printf("+------------------------------------------------------------------------------+\n");
    printf("\t\t\tEXT3_INODE STRUCTURE OF INODE #%u\n", inode_num);
    printf("+------------------------------------------------------------------------------+\n");
    print_inode(fd,&sb, &i);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-tree" ) ) {
    if ( argc != 4 ) {
      printf("usage %s <filesystem> -tree <inode number>\n", argv[0]);
      exit(1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "Superblock read error\n");
      return 1;
    }
    if ( ret == -2 )
      return 0;
    read_inode ( fd, &sb, inode_num, &i );
    print_tree(fd,&sb, &i);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-bpoint" ) ) {
    if ( argc != 4 ) {
      printf("usage %s <filesystem> -bpoint <block num>\n", argv[0]);
      exit(1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    block_num = strtoul( argv[3], ((void *)0), 10 );
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "read_superblock\n");
      exit(1);
    }
    print_block_as_bpointer( fd, &sb, block_num );
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-bcat" ) ) {
    if ( argc != 4 && argc != 5 ) {
      printf("syntax: %s <filesystem> -bcat <block number> -x\n", argv[0]);
      exit (1);
    }
    block_num = strtoul ( argv[3], ((void *)0), 10 );
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10 );
    read_superblock( fd, &sb );
    if ( argc == 5 && !strcmp("-x", argv[4]) ) {
      printf("+------------------------------------------------------------------------------+\n");
      printf("\t\t\tSHOWING BLOCK #%u IN HEXADECIMAL\n", block_num );
      printf("+------------------------------------------------------------------------------+\n");
      print_block_hexa( fd, &sb, block_num );
      printf("+------------------------------------------------------------------------------+\n");
    }
    else if ( argc == 4 ) {
      block = malloc ( (1024 << (&sb)->s_log_block_size) );
      ret = read_block(fd, &sb, block_num, block );
      if ( ret == -1 )
        exit(1);
      for ( cc = 0 ; cc < (1024 << (&sb)->s_log_block_size) ; cc++ ) {
        putchar(block[cc]);
      }
      free(block);
      close_fs ( fd );
    }
    else {
      printf("syntax: %s <filesystem> -bcat <block number> -x\n", argv[0]);
    }
  }
  else if ( !strcmp( argv[2], "-cat" ) ) {
    if ( argc != 4 && argc != 5 ) {
      printf("syntax: %s <filesystem> -cat <inode number> [ -x ]\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10 );
    read_superblock( fd, &sb );
    read_inode( fd, &sb, inode_num, &i);
    if ( ((((i.i_mode)) & 0170000) == (0040000)) ) {
      printf("This inode is a directory, you should use -ls instead.\n");
      printf("use it anyway (y/n) ? ");
      c = getchar();
      if ( c != 'y') {
        close_fs(fd);
        return 0;
      }
    }
    else if ( ((((i.i_mode)) & 0170000) == (0120000)) ) {
      print_symlink( fd, &sb, inode_num);
      close_fs(fd);
      return 0;
    }
    if ( argc == 5 && !strcmp(argv[4],"-x") ) {
      printf("+------------------------------------------------------------------------------+\n");
      printf("\t\tDUMPING FILE WITH INODE #%u IN HEXADECIMAL\n", inode_num );
      printf("+------------------------------------------------------------------------------+\n");
      print_file ( fd, &sb, inode_num, 0 );
      printf("+------------------------------------------------------------------------------+\n");
    }
    else if ( argc == 4 )
      print_file ( fd, &sb, inode_num, 1 );
    else
      printf("syntax: %s <filesystem> -cat <inode number> [ -x ]\n", argv[0]);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-iname" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -iname <inode num>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10 );
    read_superblock( fd, &sb );
    search_inode ( fd, &sb, 2, inode_num );
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-find" ) ) {
    if ( argc != 5 ) {
      printf("syntax: %s <filesystem> -find <inode num of the parent dir>"
          " <regex pattern>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    inode_num = strtoul ( argv[3], ((void *)0), 10);
    strcpy ( pattern, argv[4] );
    read_superblock( fd, &sb );
    read_inode( fd, &sb, inode_num, &i);
    if ( !((((i.i_mode)) & 0170000) == (0040000)) ) {
      printf("usage: -find <inode of the dir where the search begin> "
          "<pattern>\n");
      printf("The inode you specified is not a directory. Please specify\n");
      printf("an inode of a directory (eg. \"/\" has inode number 2)\n");
    }
    else {
      search_file ( fd, &sb, inode_num, pattern );
    }
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-imap" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -imap <group_descriptor_num>\n", argv[0]);
      exit (1);
    }
    gd_num =(unsigned short) atoi(argv[3]);
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    group_count = sb.s_blocks_count/((&sb)->s_blocks_per_group);
    if( gd_num >= group_count && gd_num != 0 )
    {
      printf("WARNING: Group descriptor %d entered seems to be "
          "inexistant.\n", gd_num);
      printf("(Existing group descriptors: from num. %d to num. %d,"
          " total %d)\n", 0, group_count == 0?0:group_count-1, group_count);
      printf("Proceed anyway? (y/n)");
      if(getchar()!='y')
      {
        exit(0);
      }
    }
    read_group_desc( fd, &sb, gd_num, &gd);
    inodebitmap = malloc( ((&sb)->s_inodes_per_group)/8 );
    read_inodebitmap( fd, &sb, &gd, inodebitmap);
    print_inodebitmap(&sb, inodebitmap, gd_num);
    free((void *)inodebitmap);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-bmap" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -bmap <group_descriptor_num>\n", argv[0]);
      exit (1);
    }
    gd_num =(unsigned short) atoi(argv[3]);
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    group_count = sb.s_blocks_count/((&sb)->s_blocks_per_group);
    if( gd_num >= group_count && gd_num != 0 )
    {
      printf("WARNING: Group descriptor %u entered seems to be inexistant.\n",
          gd_num);
      printf("(Existing group descriptors: from num. %u to num. %u,"
          " total %u)\n", 0, group_count == 0?0:group_count-1, group_count);
      printf("Proceed anyway? (y/n)");
      if(getchar()!='y')
      {
        exit(0);
      }
    }
    read_group_desc( fd, &sb, gd_num, &gd);
    datablockbitmap = malloc( ((&sb)->s_blocks_per_group)/8 );
    read_datablockbitmap( fd, &sb, &gd, gd_num, datablockbitmap);
    print_datablockbitmap(&sb, datablockbitmap, gd_num);
    free((void *)datablockbitmap);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-ffi" ) ) {
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    inodebitmap = malloc( (((&sb)->s_inodes_per_group)/8) );
    inode_num = search_first_free_inode(fd, &sb, inodebitmap);
    if(inode_num>0)
    {
      printf("First Free Inode found: %u\n", inode_num);
    }
    else
    {
      printf("No free inode found\n");
    }
    free(inodebitmap);
    close_fs(fd);
  }
  else if ( !strcmp( argv[2], "-ffb" ) ) {
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    datablockbitmap = malloc( (((&sb)->s_blocks_per_group)/8) );
    block_num = search_first_free_block(fd, &sb, datablockbitmap);
    if(block_num>0)
    {
      printf("First Free Block found: %u\n", block_num);
    }
    else
    {
      printf("No free block found\n");
    }
    free( datablockbitmap );
    close_fs(fd);
  }
  else if ( !strcmp( argv[2], "-jbd" ) ) {
    if ( argc != 3 ) {
      printf("syntax: %s <filesystem> -jbd\n", argv[0]);
      return 1;
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    ret = read_superblock( fd, &sb );
    if ( ret == -1 ) {
      fprintf( stderr, "superblock read error\n");
      exit(1);
    }
    else if ( ret == -2 ) {
      exit(0);
    }
    read_inode ( fd, &sb, sb.s_journal_inum, &i );
    read_journal_superblock( fd, (1024 << (&sb)->s_log_block_size), i.i_block[0], &jsb );
    printf("+------------------------------------------------------------------------------+\n");
    printf("\t\t\t\tJOURNAL SUPERBLOCK\n");
    printf("+------------------------------------------------------------------------------+\n""\n");
    print_journal_superblock(&jsb);
    printf("+------------------------------------------------------------------------------+\n");
    printf("\t\t\t\tJOURNAL CONTENTS\n");
    printf("+------------------------------------------------------------------------------+\n""\n");
    if ( jsb.s_start == 0 ) {
      printf("The journal is empty ! Dumping old transactions :\n");
    }
    dump_journal( fd, (1024 << (&sb)->s_log_block_size), &i );
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-printgd" ) ) {
    if ( argc != 4 ) {
      printf("syntax: %s <filesystem> -printgd <group num>\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    gd_num = (unsigned short) atoi(argv[3]);
    read_superblock( fd, &sb );
    group_count = sb.s_blocks_count/((&sb)->s_blocks_per_group);
    if ( gd_num > group_count ) {
      printf("WARNING: Group descriptor %d entered seems to be ", gd_num);
      printf("inexistant.\n");
      printf("(Existing group descriptors: from num. %d to num. %d,"
          " total %d)\n", 0, group_count, group_count+1);
      printf("Proceed anyway? (y/n) ");
      c = getchar();
      if ( c != 'y' )
        return 0;
    }
    read_group_desc( fd, &sb, gd_num, &gd);
    print_groupdesc ( &gd);
    close_fs ( fd );
  }
  else if ( !strcmp( argv[2], "-backups" ) ) {
    if ( argc != 3 ) {
      printf("syntax: %s <filesystem> -backups\n", argv[0]);
      exit (1);
    }
    fd = open_fs( argv[1] );
    if( fd == -1 )
      return 1;
    read_superblock( fd, &sb );
    print_sb_copy ( &sb );
    close_fs ( fd );
  }
  else {
    printf("Usage: %s <fd>  \n               [ -stats   | -stat | -printgd | -imap | -bmap | -ffi   |\n                 -ffb     | -cat  | -bcat    | -ls   | -find | -iname |\n                 -backups | -jbd  | -bpoint  | -tree ]\n'%s -help' for help.\nversion: ext3Viewer 1.0.2\n", argv[0], argv[0]);
    return 1;
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct ext3_super_block { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; unsigned int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_reserved_gdt_blocks; unsigned char s_journal_uuid[16]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char s_reserved_char_pad; unsigned short s_reserved_word_pad; unsigned int s_default_mount_opts; unsigned int s_first_meta_bg; unsigned int s_mkfs_time; unsigned int s_jnl_blocks[17]; unsigned int s_blocks_count_hi; unsigned int s_r_blocks_count_hi; unsigned int s_free_blocks_count_hi; unsigned short s_min_extra_isize; unsigned short s_want_extra_isize; unsigned int s_flags; unsigned short s_raid_stride; unsigned short s_mmp_interval; unsigned long long s_mmp_block; unsigned int s_raid_stripe_width; unsigned char s_log_groups_per_flex; unsigned char s_reserved_char_pad2; unsigned short s_reserved_pad; unsigned int s_reserved[162]; }

variable_types: struct ext3_inode { unsigned short i_mode; unsigned short i_uid; unsigned int i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; unsigned int i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned int i_blocks; unsigned int i_flags; union { struct { unsigned int l_i_reserved1; } linux1; struct { unsigned int h_i_translator; } hurd1; struct { unsigned int m_i_reserved1; } masix1; } osd1; unsigned int i_block[-1]; unsigned int i_generation; unsigned int i_file_acl; unsigned int i_dir_acl; unsigned int i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned int l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned int h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned int m_i_reserved2[2]; } masix2; } osd2; unsigned short i_extra_isize; unsigned short i_pad1; }

variable_types: struct ext3_group_desc { unsigned int bg_block_bitmap; unsigned int bg_inode_bitmap; unsigned int bg_inode_table; unsigned short bg_free_blocks_count; unsigned short bg_free_inodes_count; unsigned short bg_used_dirs_count; unsigned short bg_pad; unsigned int bg_reserved[3]; }

variable_types: struct journal_superblock_s { struct journal_header_s { unsigned int h_magic; unsigned int h_blocktype; unsigned int h_sequence; } s_header; unsigned int s_blocksize; unsigned int s_maxlen; unsigned int s_first; unsigned int s_sequence; unsigned int s_start; unsigned int s_errno; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; unsigned int s_nr_users; unsigned int s_dynsuper; unsigned int s_max_transaction; unsigned int s_max_trans_data; unsigned int s_padding[44]; unsigned char s_users[-1]; }

variable_types:
inodebitmap
char *

variable_types:
datablockbitmap
char *

variable_types: c char

variable_types:
block
char *

variable_types: cc int

variable_types: fd int

variable_types:
pattern
char [255]

variable_types:
ret
long long

user_defined_types: struct journal_superblock_s { struct journal_header_s s_header; unsigned int s_blocksize; unsigned int s_maxlen; unsigned int s_first; unsigned int s_sequence; unsigned int s_start; unsigned int s_errno; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; unsigned int s_nr_users; unsigned int s_dynsuper; unsigned int s_max_transaction; unsigned int s_max_trans_data; unsigned int s_padding[44]; unsigned char s_users[-1]; }


decompiled_code:
__int64 __fastcall read_xattrh(int fd, __int64 a2, unsigned int a3, void *a4)
{
unsigned int v5; // er13

if ( (unsigned int)lseek64(fd, a3, 0) == -1 )
{
v5 = -1;
perror("ext3Viewer - lseek error: ACL");
}
else
{
v5 = read(fd, a4, 0x20uLL);
if ( v5 == -1 )
perror("ext3Viewer - read error: ACL");
else
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, unsigned int a3, void *a4)
{
unsigned int v5; // er13

if ( (unsigned int)lseek64(fd, a3, 0) == -1 )
{
v5 = -1;
perror("ext3Viewer - lseek error: ACL");
}
else
{
v5 = read(fd, a4, 0x20uLL);
if ( v5 == -1 )
perror("ext3Viewer - read error: ACL");
else
v5 = 0;
}
return v5;
}

original_code:
int read_xattrh(int fd, const struct ext3_super_block *sb, __u32 header_pos,
    struct ext3_xattr_header * header )
{
  int ret;
  ret = lseek(fd, header_pos, 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: ACL");
    return -1;
  }
  ret = read( fd, header, sizeof(struct ext3_xattr_header) );
  if ( ret == -1 ) {
    perror("ext3Viewer - read error: ACL");
    return -1;
  }
  return 0;
}

canonical_original_code:
int read_xattrh(int fd, struct ext3_super_block *sb, unsigned int header_pos, struct ext3_xattr_header *header)
{
  int ret;
  ret = lseek(fd, header_pos, 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: ACL");
    return -1;
  }
  ret = read( fd, header, sizeof(struct ext3_xattr_header) );
  if ( ret == -1 ) {
    perror("ext3Viewer - read error: ACL");
    return -1;
  }
  return 0;
}

variable_types: struct ext3_super_block { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; unsigned int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_reserved_gdt_blocks; unsigned char s_journal_uuid[16]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char s_reserved_char_pad; unsigned short s_reserved_word_pad; unsigned int s_default_mount_opts; unsigned int s_first_meta_bg; unsigned int s_mkfs_time; unsigned int s_jnl_blocks[17]; unsigned int s_blocks_count_hi; unsigned int s_r_blocks_count_hi; unsigned int s_free_blocks_count_hi; unsigned short s_min_extra_isize; unsigned short s_want_extra_isize; unsigned int s_flags; unsigned short s_raid_stride; unsigned short s_mmp_interval; unsigned long long s_mmp_block; unsigned int s_raid_stripe_width; unsigned char s_log_groups_per_flex; unsigned char s_reserved_char_pad2; unsigned short s_reserved_pad; unsigned int s_reserved[162]; } *

variable_types: struct ext3_xattr_header { unsigned int h_magic; unsigned int h_refcount; unsigned int h_blocks; unsigned int h_hash; unsigned int h_reserved[4]; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall read_xattre(int fd, __int64 a2, int a3, unsigned __int16 a4, void *a5)
{
unsigned int v6; // er13

if ( (unsigned int)lseek64(fd, a3 * (1024 << *(_DWORD *)(a2 + 24)) + (unsigned int)a4, 0) == -1 )
{
v6 = -1;
perror("ext3Viewer - lseek error: xattr_entry");
}
else
{
v6 = read(fd, a5, 0x10uLL);
if ( v6 == -1 )
perror("ext3Viewer - read error: xattr_entry");
else
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2, int a3, unsigned __int16 a4, void *a5)
{
unsigned int v6; // er13

if ( (unsigned int)lseek64(fd, a3 * (1024 << *(_DWORD *)(a2 + 24)) + (unsigned int)a4, 0) == -1 )
{
v6 = -1;
perror("ext3Viewer - lseek error: xattr_entry");
}
else
{
v6 = read(fd, a5, 0x10uLL);
if ( v6 == -1 )
perror("ext3Viewer - read error: xattr_entry");
else
v6 = 0;
}
return v6;
}

original_code:
int read_xattre(int fd, const struct ext3_super_block *sb, __u32 entry_blocknum,
    __u16 offset, struct ext3_xattr_entry * entry )
{
  int ret;
  entry_blocknum = entry_blocknum*(1024 << (sb)->s_log_block_size);
  ret = lseek(fd, entry_blocknum+offset, 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: xattr_entry");
    return -1;
  }
  ret = read( fd, entry, sizeof(struct ext3_xattr_entry) );
  if ( ret == -1 ) {
    perror("ext3Viewer - read error: xattr_entry");
    return -1;
  }
  return 0;
}

canonical_original_code:
int read_xattre(int fd, struct ext3_super_block *sb, unsigned int entry_blocknum, unsigned short offset, struct ext3_xattr_entry *entry)
{
  int ret;
  entry_blocknum = entry_blocknum*(1024 << (sb)->s_log_block_size);
  ret = lseek(fd, entry_blocknum+offset, 0);
  if ( ret == -1 ) {
    perror("ext3Viewer - lseek error: xattr_entry");
    return -1;
  }
  ret = read( fd, entry, sizeof(struct ext3_xattr_entry) );
  if ( ret == -1 ) {
    perror("ext3Viewer - read error: xattr_entry");
    return -1;
  }
  return 0;
}

variable_types:
offset
unsigned short

variable_types: struct ext3_xattr_entry { unsigned char e_name_len; unsigned char e_name_index; unsigned short e_value_offs; unsigned int e_value_block; unsigned int e_value_size; unsigned int e_hash; char e_name[]; } *

user_defined_types: struct ext3_super_block { unsigned int s_inodes_count; unsigned int s_blocks_count; unsigned int s_r_blocks_count; unsigned int s_free_blocks_count; unsigned int s_free_inodes_count; unsigned int s_first_data_block; unsigned int s_log_block_size; unsigned int s_log_frag_size; unsigned int s_blocks_per_group; unsigned int s_frags_per_group; unsigned int s_inodes_per_group; unsigned int s_mtime; unsigned int s_wtime; unsigned short s_mnt_count; unsigned short s_max_mnt_count; unsigned short s_magic; unsigned short s_state; unsigned short s_errors; unsigned short s_minor_rev_level; unsigned int s_lastcheck; unsigned int s_checkinterval; unsigned int s_creator_os; unsigned int s_rev_level; unsigned short s_def_resuid; unsigned short s_def_resgid; unsigned int s_first_ino; unsigned short s_inode_size; unsigned short s_block_group_nr; unsigned int s_feature_compat; unsigned int s_feature_incompat; unsigned int s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; char s_last_mounted[64]; unsigned int s_algorithm_usage_bitmap; unsigned char s_prealloc_blocks; unsigned char s_prealloc_dir_blocks; unsigned short s_reserved_gdt_blocks; unsigned char s_journal_uuid[16]; unsigned int s_journal_inum; unsigned int s_journal_dev; unsigned int s_last_orphan; unsigned int s_hash_seed[4]; unsigned char s_def_hash_version; unsigned char s_reserved_char_pad; unsigned short s_reserved_word_pad; unsigned int s_default_mount_opts; unsigned int s_first_meta_bg; unsigned int s_mkfs_time; unsigned int s_jnl_blocks[17]; unsigned int s_blocks_count_hi; unsigned int s_r_blocks_count_hi; unsigned int s_free_blocks_count_hi; unsigned short s_min_extra_isize; unsigned short s_want_extra_isize; unsigned int s_flags; unsigned short s_raid_stride; unsigned short s_mmp_interval; unsigned long long s_mmp_block; unsigned int s_raid_stripe_width; unsigned char s_log_groups_per_flex; unsigned char s_reserved_char_pad2; unsigned short s_reserved_pad; unsigned int s_reserved[162]; }


decompiled_code:
int __fastcall print_acl(int fd, __int64 a2, int a3)
{
unsigned int v4; // er12
char v5[2]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int16 v6; // [rsp+2h] [rbp-46h]
unsigned int v7; // [rsp+4h] [rbp-44h]
unsigned int v8; // [rsp+8h] [rbp-40h]
unsigned int v9; // [rsp+Ch] [rbp-3Ch]
int v10[14]; // [rsp+10h] [rbp-38h] BYREF

if ( !a3 )
return puts("No ACL entry associated.");
v4 = (unsigned __int16)a3;
puts(
"This is the number of the file system block on which\n"
" the Extended Attributes associated with this inode are stored.");
read_xattrh(fd, a2, v4, v10);
read_xattre(fd, a2, v4, 0x20u, v5);
puts("Header of the extended attributes list");
printf("The magic number should be %#x, is %#x\n", 3925999616LL, (unsigned int)v10[0]);
printf("This set of attributes is referenced %u times\n", (unsigned int)v10[1]);
printf("%u blocks are used\n", (unsigned int)v10[2]);
printf("Hash value of all attributes:%#x\n", (unsigned int)v10[3]);
printf("Name length: %hhu\n", (unsigned __int8)v5[0]);
printf("Attribute name index: %hhu\n", (unsigned __int8)v5[1]);
printf("Disk block offset of value: %u\n", v6);
printf("Disk block attribute is stored on: %u\n", v7);
printf("Size of attribute value: %u\n", v8);
printf("Hash value of name and value: %#x\n", v9);
return printf("Attribute name: %#x\n", (unsigned int)SLOBYTE(v10[0]));
}

canonical_decompiled_code:
int __fastcall func2(int fd, __int64 a2, int a3)
{
unsigned int v4; // er12
char v5[2]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int16 v6; // [rsp+2h] [rbp-46h]
unsigned int v7; // [rsp+4h] [rbp-44h]
unsigned int v8; // [rsp+8h] [rbp-40h]
unsigned int v9; // [rsp+Ch] [rbp-3Ch]
int v10[14]; // [rsp+10h] [rbp-38h] BYREF

if ( !a3 )
return puts("No ACL entry associated.");
v4 = (unsigned __int16)a3;
puts(
"This is the number of the file system block on which\n"
" the Extended Attributes associated with this inode are stored.");
func0(fd, a2, v4, v10);
func1(fd, a2, v4, 0x20u, v5);
puts("Header of the extended attributes list");
printf("The magic number should be %#x, is %#x\n", 3925999616LL, (unsigned int)v10[0]);
printf("This set of attributes is referenced %u times\n", (unsigned int)v10[1]);
printf("%u blocks are used\n", (unsigned int)v10[2]);
printf("Hash value of all attributes:%#x\n", (unsigned int)v10[3]);
printf("Name length: %hhu\n", (unsigned __int8)v5[0]);
printf("Attribute name index: %hhu\n", (unsigned __int8)v5[1]);
printf("Disk block offset of value: %u\n", v6);
printf("Disk block attribute is stored on: %u\n", v7);
printf("Size of attribute value: %u\n", v8);
printf("Hash value of name and value: %#x\n", v9);
return printf("Attribute name: %#x\n", (unsigned int)SLOBYTE(v10[0]));
}

original_code:
void print_acl(int fd, const struct ext3_super_block *sb, __u32 i_type_acl)
{
  struct ext3_xattr_header xattr_header;
  struct ext3_xattr_entry xattr_entry;
  __u16 position = 0, offset = 0;
  if(i_type_acl == 0)
  {
    printf("No ACL entry associated.\n");
  }
  else
  {
    printf("This is the number of the file system block on which\n "
        "the Extended Attributes associated with this inode are stored.\n");
    position = i_type_acl;
    read_xattrh(fd, sb, position,&xattr_header);
    offset = sizeof(struct ext3_xattr_header);
    read_xattre(fd, sb, position, offset,&xattr_entry);
    printf("Header of the extended attributes list\n");
    printf("The magic number should be %#x, is %#x\n", 0xEA020000,
        xattr_header.h_magic);
    printf("This set of attributes is referenced %u times\n",
        xattr_header.h_refcount);
    printf("%u blocks are used\n", xattr_header.h_blocks);
    printf("Hash value of all attributes:%#x\n", xattr_header.h_hash);
    printf("Name length: %hhu\n", xattr_entry.e_name_len);
    printf("Attribute name index: %hhu\n", xattr_entry.e_name_index);
    printf("Disk block offset of value: %u\n",
        ((__u16)(__le16)(xattr_entry.e_value_offs)));
    printf("Disk block attribute is stored on: %u\n",
        ((__u32)(__le32)(xattr_entry.e_value_block)));
    printf("Size of attribute value: %u\n",
        ((__u32)(__le32)(xattr_entry.e_value_size)));
    printf("Hash value of name and value: %#x\n",
        ((__u32)(__le32)(xattr_entry.e_hash)));
    printf("Attribute name: %#x\n", xattr_entry.e_name[0]);
    offset = ((__u16)(__le16)(xattr_entry.e_value_offs));
  }
}

canonical_original_code:
void print_acl(int fd, struct ext3_super_block *sb, unsigned int i_type_acl)
{
  struct ext3_xattr_header xattr_header;
  struct ext3_xattr_entry xattr_entry;
  unsigned short position = 0; unsigned short offset = 0;
  if(i_type_acl == 0)
  {
    printf("No ACL entry associated.\n");
  }
  else
  {
    printf("This is the number of the file system block on which\n "
        "the Extended Attributes associated with this inode are stored.\n");
    position = i_type_acl;
    read_xattrh(fd, sb, position,&xattr_header);
    offset = sizeof(struct ext3_xattr_header);
    read_xattre(fd, sb, position, offset,&xattr_entry);
    printf("Header of the extended attributes list\n");
    printf("The magic number should be %#x, is %#x\n", 0xEA020000,
        xattr_header.h_magic);
    printf("This set of attributes is referenced %u times\n",
        xattr_header.h_refcount);
    printf("%u blocks are used\n", xattr_header.h_blocks);
    printf("Hash value of all attributes:%#x\n", xattr_header.h_hash);
    printf("Name length: %hhu\n", xattr_entry.e_name_len);
    printf("Attribute name index: %hhu\n", xattr_entry.e_name_index);
    printf("Disk block offset of value: %u\n",
        ((__u16)(__le16)(xattr_entry.e_value_offs)));
    printf("Disk block attribute is stored on: %u\n",
        ((__u32)(__le32)(xattr_entry.e_value_block)));
    printf("Size of attribute value: %u\n",
        ((__u32)(__le32)(xattr_entry.e_value_size)));
    printf("Hash value of name and value: %#x\n",
        ((__u32)(__le32)(xattr_entry.e_hash)));
    printf("Attribute name: %#x\n", xattr_entry.e_name[0]);
    offset = ((__u16)(__le16)(xattr_entry.e_value_offs));
  }
}

variable_types: struct ext3_xattr_header { unsigned int h_magic; unsigned int h_refcount; unsigned int h_blocks; unsigned int h_hash; unsigned int h_reserved[4]; }

variable_types: struct ext3_xattr_entry { unsigned char e_name_len; unsigned char e_name_index; unsigned short e_value_offs; unsigned int e_value_block; unsigned int e_value_size; unsigned int e_hash; char e_name[]; }

variable_types:
position
unsigned short


push

decompiled_code:
__int64 __fastcall push(char **a1, const char *a2, int a3)
{
char *v4; // rax
char *v5; // rdx
char *v6; // rax
__int64 result; // rax

v4 = (char *)malloc(0x110uLL);
if ( v4 )
{
v5 = strcpy(v4, a2);
*((_DWORD *)v5 + 64) = a3;
v6 = *a1;
*a1 = v5;
*((_QWORD *)v5 + 33) = v6;
result = 0LL;
}
else
{
perror("path_filo");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, const char *a2, int a3)
{
char *v4; // rax
char *v5; // rdx
char *v6; // rax
__int64 result; // rax

v4 = (char *)malloc(0x110uLL);
if ( v4 )
{
v5 = strcpy(v4, a2);
*((_DWORD *)v5 + 64) = a3;
v6 = *a1;
*a1 = v5;
*((_QWORD *)v5 + 33) = v6;
result = 0LL;
}
else
{
perror("path_filo");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int push ( struct path_filo **p, const char * name, __u32 inode ) {
  struct path_filo *element = malloc(sizeof(path_filo));
  if(!element) {
    perror("path_filo");
    return -1;
  }
  strcpy ( element->name, name );
  element->inode = inode;
  element->prev = *p;
  *p = element;
  return 0;
}

canonical_original_code:
int push(struct path_filo **p, char *name, unsigned int inode) {
  struct path_filo *element = malloc(sizeof(path_filo));
  if(!element) {
    perror("path_filo");
    return -1;
  }
  strcpy ( element->name, name );
  element->inode = inode;
  element->prev = *p;
  *p = element;
  return 0;
}

variable_types: struct path_filo { char name[255]; unsigned int inode; struct path_filo *prev; } **

variable_types:
name
char *

variable_types:
inode
unsigned int


decompiled_code:
__int64 __fastcall remove_top(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

v2 = *a1;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = (_QWORD *)v2[33];
free(v2);
result = 0LL;
*a1 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD **a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbp
__int64 result; // rax

v2 = *a1;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = (_QWORD *)v2[33];
free(v2);
result = 0LL;
*a1 = v3;
return result;
}

original_code:
int remove_top(struct path_filo **p)
{
  struct path_filo *tmp;
  if( *p == ((void *)0) )
    return -1;
  tmp = (*p)->prev;
  free(*p);
  *p = tmp;
  return 0;
}

variable_types: struct path_filo { char name[255]; unsigned int inode; struct path_filo *prev; } *


decompiled_code:
void __fastcall free_path(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v3; // rdi

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v1;
v1 = (_QWORD *)v1[33];
free(v3);
*a1 = v1;
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v3; // rdi

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v1;
v1 = (_QWORD *)v1[33];
free(v3);
*a1 = v1;
}
while ( v1 );
}
}

original_code:
void free_path(struct path_filo **p)
{
  struct path_filo *tmp;
  while( *p != ((void *)0) )
  {
    tmp = (*p)->prev;
    free(*p);
    *p = tmp;
  }
}

user_defined_types: struct path_filo { char name[255]; unsigned int inode; struct path_filo *prev; }


view

decompiled_code:
int __fastcall view(__int64 a1)
{
int result; // eax

if ( a1 )
{
view(*(_QWORD *)(a1 + 264));
result = printf("%s %d ", (const char *)a1, *(unsigned int *)(a1 + 256));
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax

if ( a1 )
{
func3(*(_QWORD *)(a1 + 264));
result = printf("%s %d ", (const char *)a1, *(unsigned int *)(a1 + 256));
}
return result;
}

original_code:
void view(const struct path_filo *p)
{
  if ( p != ((void *)0) ) {
    view ( p->prev) ;
    printf("%s %d ", p->name, p->inode);
  }
}

canonical_original_code:
void view(struct path_filo *p)
{
  if ( p != ((void *)0) ) {
    view ( p->prev) ;
    printf("%s %d ", p->name, p->inode);
  }
}


decompiled_code:
void __fastcall fill_path_name(char *src, char *s)
{
size_t v2; // rax

if ( src )
{
fill_path_name(*((char **)src + 33), s);
v2 = strlen(s);
s[v2] = 47;
strcpy(&s[v2 + 1], src);
}
}

canonical_decompiled_code:
void __fastcall func4(char *src, char *s)
{
size_t v2; // rax

if ( src )
{
func4(*((char **)src + 33), s);
v2 = strlen(s);
s[v2] = 47;
strcpy(&s[v2 + 1], src);
}
}

original_code:
void fill_path_name( struct path_filo *p, char *string )
{
  if ( p != ((void *)0) ) {
    fill_path_name ( p->prev, string );
    strcat ( string, "/");
    strcat ( string, p->name );
  }
}

canonical_original_code:
void fill_path_name(struct path_filo *p, char *string)
{
  if ( p != ((void *)0) ) {
    fill_path_name ( p->prev, string );
    strcat ( string, "/");
    strcat ( string, p->name );
  }
}

variable_types:
string
char *


decompiled_code:
__int64 __fastcall read_superblock(int fd, void *buf)
{
__int64 result; // rax
char v3; // bl

if ( lseek64(fd, 1024LL, 0) == -1 )
{
perror("ext3Viewer error - lseek superblock error");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, 0x400uLL) == -1 )
{
perror("ext3Viewer error - superblock read error");
result = 0xFFFFFFFFLL;
}
else if ( *((_WORD *)buf + 28) == 0xEF53 )
{
result = mask(*((unsigned int *)buf + 24), 4LL);
if ( (_DWORD)result )
{
printf(
"WARNING: This filesystem is mounted or corrupted.\n"
" unmount it or fsck before using ext3viewer.\n"
" Using ext3viewer on mounted partition may\n"
" be unsafe.\n"
"continue anyway (y/n)? ");
v3 = getchar();
while ( getchar() != 10 )
;
result = 3 * (unsigned int)(v3 == 121) - 2;
}
}
else
{
fwrite("!!ERROR!! : This filesystem is not a valid ext. Bad magic number\n", 1uLL, 0x41uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf)
{
__int64 result; // rax
char v3; // bl

if ( lseek64(fd, 1024LL, 0) == -1 )
{
perror("ext3Viewer error - lseek superblock error");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, 0x400uLL) == -1 )
{
perror("ext3Viewer error - superblock read error");
result = 0xFFFFFFFFLL;
}
else if ( *((_WORD *)buf + 28) == 0xEF53 )
{
result = mask(*((unsigned int *)buf + 24), 4LL);
if ( (_DWORD)result )
{
printf(
"WARNING: This filesystem is mounted or corrupted.\n"
" unmount it or fsck before using ext3viewer.\n"
" Using ext3viewer on mounted partition may\n"
" be unsafe.\n"
"continue anyway (y/n)? ");
v3 = getchar();
while ( getchar() != 10 )
;
result = 3 * (unsigned int)(v3 == 121) - 2;
}
}
else
{
fwrite("!!ERROR!! : This filesystem is not a valid ext. Bad magic number\n", 1uLL, 0x41uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int read_superblock ( int fd, struct ext3_super_block *sb ) {
  char c;
  if( (lseek( fd, 1024, 0 )) == -1 ) {
    perror("ext3Viewer error - lseek superblock error");
    return -1;
  }
  if( (read(fd, sb, sizeof(struct ext3_super_block) )) == -1 ) {
    perror("ext3Viewer error - superblock read error");
    return -1;
  }
  if ( sb->s_magic != 0xEF53 ) {
    fprintf( stderr, "!!ERROR!! : This filesystem is not a valid ext. "
        "Bad magic number\n");
    return -1;
  }
  if( mask(sb->s_feature_incompat, 0x0004) ) {
    printf("WARNING: This filesystem is mounted or corrupted.\n"
        "         unmount it or fsck before using ext3viewer.\n"
        "         Using ext3viewer on mounted partition may\n"
        "         be unsafe.\n"
        "continue anyway (y/n)? ");
    c = getchar();
    while ( getchar()!='\n');
    if ( c != 'y' )
      return -2;
    return 1;
  }
  return 0;
}

canonical_original_code:
int read_superblock(int fd, struct ext3_super_block *sb) {
  char c;
  if( (lseek( fd, 1024, 0 )) == -1 ) {
    perror("ext3Viewer error - lseek superblock error");
    return -1;
  }
  if( (read(fd, sb, sizeof(struct ext3_super_block) )) == -1 ) {
    perror("ext3Viewer error - superblock read error");
    return -1;
  }
  if ( sb->s_magic != 0xEF53 ) {
    fprintf( stderr, "!!ERROR!! : This filesystem is not a valid ext. "
        "Bad magic number\n");
    return -1;
  }
  if( mask(sb->s_feature_incompat, 0x0004) ) {
    printf("WARNING: This filesystem is mounted or corrupted.\n"
        "         unmount it or fsck before using ext3viewer.\n"
        "         Using ext3viewer on mounted partition may\n"
        "         be unsafe.\n"
        "continue anyway (y/n)? ");
    c = getchar();
    while ( getchar()!='\n');
    if ( c != 'y' )
      return -2;
    return 1;
  }
  return 0;
}

variable_types: c char


decompiled_code:
__int64 __fastcall read_superblock_backup(int fd, void *buf, int a3, int a4)
{
__int64 result; // rax
char v5; // bl

if ( lseek64(fd, (unsigned int)(a3 * a4), 0) == -1 )
{
perror("ext3Viewer error - superblock lseek error");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, 0x400uLL) == -1 )
{
perror("ext3Viewer error - superblock read error");
result = 0xFFFFFFFFLL;
}
else if ( *((_WORD *)buf + 28) == 0xEF53 )
{
result = mask(*((unsigned int *)buf + 24), 4LL);
if ( (_DWORD)result )
{
printf(
"WARNING: This filesystem is mounted or corrupted.\n"
" unmount it or fsck before using ext3viewer.\n"
" Using ext3viewer on mounted partition may\n"
" be unsafe.\n"
"continue anyway (y/n)? ");
v5 = getchar();
while ( getchar() != 10 )
;
result = 3 * (unsigned int)(v5 == 121) - 2;
}
}
else
{
fwrite("!!ERROR!! : This filesystem is not a valid ext. Bad magic number\n", 1uLL, 0x41uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, int a3, int a4)
{
__int64 result; // rax
char v5; // bl

if ( lseek64(fd, (unsigned int)(a3 * a4), 0) == -1 )
{
perror("ext3Viewer error - superblock lseek error");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, 0x400uLL) == -1 )
{
perror("ext3Viewer error - superblock read error");
result = 0xFFFFFFFFLL;
}
else if ( *((_WORD *)buf + 28) == 0xEF53 )
{
result = mask(*((unsigned int *)buf + 24), 4LL);
if ( (_DWORD)result )
{
printf(
"WARNING: This filesystem is mounted or corrupted.\n"
" unmount it or fsck before using ext3viewer.\n"
" Using ext3viewer on mounted partition may\n"
" be unsafe.\n"
"continue anyway (y/n)? ");
v5 = getchar();
while ( getchar() != 10 )
;
result = 3 * (unsigned int)(v5 == 121) - 2;
}
}
else
{
fwrite("!!ERROR!! : This filesystem is not a valid ext. Bad magic number\n", 1uLL, 0x41uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int read_superblock_backup ( int fd, struct ext3_super_block *sb,
    __u32 block_num, int block_size ) {
  char c;
  if( (lseek( fd, block_num*block_size, 0 )) == -1 ) {
    perror("ext3Viewer error - superblock lseek error");
    return -1;
  }
  if( (read(fd, sb, sizeof(struct ext3_super_block) )) == -1 ) {
    perror("ext3Viewer error - superblock read error");
    return -1;
  }
  if ( sb->s_magic != 0xEF53 ) {
    fprintf( stderr, "!!ERROR!! : This filesystem is not a valid ext. "
        "Bad magic number\n");
    return -1;
  }
  if( mask(sb->s_feature_incompat, 0x0004) ) {
    printf("WARNING: This filesystem is mounted or corrupted.\n"
        "         unmount it or fsck before using ext3viewer.\n"
        "         Using ext3viewer on mounted partition may\n"
        "         be unsafe.\n"
        "continue anyway (y/n)? ");
    c = getchar();
    while ( getchar()!='\n');
    if ( c != 'y' )
      return -2;
    return 1;
  }
  return 0;
}

canonical_original_code:
int read_superblock_backup(int fd, struct ext3_super_block *sb, unsigned int block_num, int block_size) {
  char c;
  if( (lseek( fd, block_num*block_size, 0 )) == -1 ) {
    perror("ext3Viewer error - superblock lseek error");
    return -1;
  }
  if( (read(fd, sb, sizeof(struct ext3_super_block) )) == -1 ) {
    perror("ext3Viewer error - superblock read error");
    return -1;
  }
  if ( sb->s_magic != 0xEF53 ) {
    fprintf( stderr, "!!ERROR!! : This filesystem is not a valid ext. "
        "Bad magic number\n");
    return -1;
  }
  if( mask(sb->s_feature_incompat, 0x0004) ) {
    printf("WARNING: This filesystem is mounted or corrupted.\n"
        "         unmount it or fsck before using ext3viewer.\n"
        "         Using ext3viewer on mounted partition may\n"
        "         be unsafe.\n"
        "continue anyway (y/n)? ");
    c = getchar();
    while ( getchar()!='\n');
    if ( c != 'y' )
      return -2;
    return 1;
  }
  return 0;
}

variable_types: fd int


decompiled_code:
__int64 __fastcall read_superblock_gui(int fd, void *buf)
{
__int64 result; // rax

if ( lseek64(fd, 1024LL, 0) == -1 )
{
perror("ext3Viewer error - superblock lseek error");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, 0x400uLL) == -1 )
{
perror("ext3Viewer error - superblock read error");
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
if ( *((_WORD *)buf + 28) == 0xEF53 )
result = (unsigned int)mask(*((unsigned int *)buf + 24), 4LL) != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf)
{
__int64 result; // rax

if ( lseek64(fd, 1024LL, 0) == -1 )
{
perror("ext3Viewer error - superblock lseek error");
result = 0xFFFFFFFFLL;
}
else if ( read(fd, buf, 0x400uLL) == -1 )
{
perror("ext3Viewer error - superblock read error");
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
if ( *((_WORD *)buf + 28) == 0xEF53 )
result = (unsigned int)mask(*((unsigned int *)buf + 24), 4LL) != 0;
}
return result;
}

original_code:
int read_superblock_gui ( int fd, struct ext3_super_block *sb ) {
  if( (lseek( fd, 1024, 0 )) == -1 ) {
    perror("ext3Viewer error - superblock lseek error");
    return -1;
  }
  if( (read(fd, sb, sizeof(struct ext3_super_block) )) == -1 ) {
    perror("ext3Viewer error - superblock read error");
    return -1;
  }
  if ( sb->s_magic != 0xEF53 ) {
    return -1;
  }
  if( mask(sb->s_feature_incompat, 0x0004) )
    return 1;
  else
    return 0;
}

canonical_original_code:
int read_superblock_gui(int fd, struct ext3_super_block *sb) {
  if( (lseek( fd, 1024, 0 )) == -1 ) {
    perror("ext3Viewer error - superblock lseek error");
    return -1;
  }
  if( (read(fd, sb, sizeof(struct ext3_super_block) )) == -1 ) {
    perror("ext3Viewer error - superblock read error");
    return -1;
  }
  if ( sb->s_magic != 0xEF53 ) {
    return -1;
  }
  if( mask(sb->s_feature_incompat, 0x0004) )
    return 1;
  else
    return 0;
}