handleKey

decompiled_code:
__int64 __fastcall handleKey(int a1)
{
unsigned int v1; // er12
size_t v3; // rbp
int v4; // er13
size_t v5; // rax

v1 = showHelpWindow;
if ( showHelpWindow )
{
if ( a1 == 27 )
{
delwin(helpwin);
helpwin = 0LL;
showHelpWindow = 0;
fullRedraw = 1;
}
return 0;
}
if ( a1 == 27 )
{
LABEL_29:
v1 = 1;
if ( ++escapeCount_0 > 1 )
{
Error_Set(0LL);
escapeCount_0 = 0;
}
return v1;
}
escapeCount_0 = 0;
if ( a1 > 263 )
{
if ( a1 == 360 )
{
v1 = 1;
items_Select(0xFFFFFFFFLL);
copyItemToUserInput();
return v1;
}
if ( a1 > 360 )
goto LABEL_14;
if ( a1 != 330 )
{
if ( a1 == 343 )
{
LABEL_24:
executeSelection();
return 1;
}
goto LABEL_14;
}
goto LABEL_19;
}
if ( a1 <= 257 )
{
if ( a1 <= 27 )
{
if ( a1 > 7 )
{
switch ( a1 )
{
case 8:
showHelpWindow = 1;
v1 = 1;
break;
case 9:
items_SelectNextSection();
v1 = 1;
break;
case 10:
case 13:
goto LABEL_24;
case 21:
clearInput();
v1 = 1;
break;
case 27:
goto LABEL_29;
default:
goto LABEL_14;
}
return v1;
}
goto LABEL_14;
}
if ( a1 != 127 )
{
LABEL_14:
v3 = strlen(userInput);
v4 = v3;
LABEL_15:
if ( (unsigned int)isValidInput(a1) && v3 <= 0x1F )
{
userInput[v4 - 1] = a1;
userInput[v4] = 95;
userInput[v4 + 1] = 0;
return v1;
}
return 0;
}
LABEL_19:
v5 = strlen(userInput);
v3 = v5;
v4 = v5;
if ( v5 <= 1 )
goto LABEL_15;
userInput[(int)v5 - 2] = 95;
userInput[(int)v5 - 1] = 0;
goto LABEL_14;
}
switch ( a1 )
{
case 259:
v1 = 1;
items_SelectDelta(0LL, 0xFFFFFFFFLL);
copyItemToUserInput();
break;
case 260:
v1 = 1;
items_SelectDelta(0xFFFFFFFFLL, 0LL);
copyItemToUserInput();
break;
case 261:
v1 = 1;
items_SelectDelta(1LL, 0LL);
copyItemToUserInput();
break;
case 262:
v1 = 1;
items_Select(0LL);
copyItemToUserInput();
break;
case 263:
goto LABEL_19;
default:
v1 = 1;
items_SelectDelta(0LL, 1LL);
copyItemToUserInput();
break;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
unsigned int v1; // er12
size_t v3; // rbp
int v4; // er13
size_t v5; // rax

v1 = showHelpWindow;
if ( showHelpWindow )
{
if ( a1 == 27 )
{
delwin(helpwin);
helpwin = 0LL;
showHelpWindow = 0;
fullRedraw = 1;
}
return 0;
}
if ( a1 == 27 )
{
LABEL_29:
v1 = 1;
if ( ++escapeCount_0 > 1 )
{
Error_Set(0LL);
escapeCount_0 = 0;
}
return v1;
}
escapeCount_0 = 0;
if ( a1 > 263 )
{
if ( a1 == 360 )
{
v1 = 1;
items_Select(0xFFFFFFFFLL);
func7();
return v1;
}
if ( a1 > 360 )
goto LABEL_14;
if ( a1 != 330 )
{
if ( a1 == 343 )
{
LABEL_24:
func12();
return 1;
}
goto LABEL_14;
}
goto LABEL_19;
}
if ( a1 <= 257 )
{
if ( a1 <= 27 )
{
if ( a1 > 7 )
{
switch ( a1 )
{
case 8:
showHelpWindow = 1;
v1 = 1;
break;
case 9:
items_SelectNextSection();
v1 = 1;
break;
case 10:
case 13:
goto LABEL_24;
case 21:
func6();
v1 = 1;
break;
case 27:
goto LABEL_29;
default:
goto LABEL_14;
}
return v1;
}
goto LABEL_14;
}
if ( a1 != 127 )
{
LABEL_14:
v3 = strlen(userInput);
v4 = v3;
LABEL_15:
if ( (unsigned int)func16(a1) && v3 <= 0x1F )
{
userInput[v4 - 1] = a1;
userInput[v4] = 95;
userInput[v4 + 1] = 0;
return v1;
}
return 0;
}
LABEL_19:
v5 = strlen(userInput);
v3 = v5;
v4 = v5;
if ( v5 <= 1 )
goto LABEL_15;
userInput[(int)v5 - 2] = 95;
userInput[(int)v5 - 1] = 0;
goto LABEL_14;
}
switch ( a1 )
{
case 259:
v1 = 1;
items_SelectDelta(0LL, 0xFFFFFFFFLL);
func7();
break;
case 260:
v1 = 1;
items_SelectDelta(0xFFFFFFFFLL, 0LL);
func7();
break;
case 261:
v1 = 1;
items_SelectDelta(1LL, 0LL);
func7();
break;
case 262:
v1 = 1;
items_Select(0LL);
func7();
break;
case 263:
goto LABEL_19;
default:
v1 = 1;
items_SelectDelta(0LL, 1LL);
func7();
break;
}
return v1;
}

original_code:
int handleKey( int ch )
{
 static int escapeCount = 0;
 int ret = 1;
 int len = 0;
 if( showHelpWindow ) {
  if( ch != 27 ) {
   return 0;
  }
  delwin( helpwin );
  helpwin = ((void *)0);
  showHelpWindow = 0;
  fullRedraw = 1;
  return 0;
 }
 if( ch != 27 ) {
  escapeCount = 0;
 }
 switch( ch ) {
 case( 27 ):
  escapeCount++;
  if( escapeCount > 1 ) {
   Error_Set( 0 );
   escapeCount = 0;
  }
  break;
 case( 0402 ):
  items_SelectDelta( 0, 1 );
  copyItemToUserInput();
  break;
 case( 0403 ):
  items_SelectDelta( 0, -1 );
  copyItemToUserInput();
  break;
 case( 0404 ):
  items_SelectDelta( -1, 0 );
  copyItemToUserInput();
  break;
 case( 0405 ):
  items_SelectDelta( 1, 0 );
  copyItemToUserInput();
  break;
 case( 0406 ):
  items_Select( 0 );
  copyItemToUserInput();
  break;
 case( 0550 ):
  items_Select( -1 );
  copyItemToUserInput();
  break;
 case( (('h')&037) ):
  showHelpWindow = 1;
  break;
 case( (('u')&037) ):
  clearInput();
  break;
 case( '\t' ):
  items_SelectNextSection();
  break;
 case( 0527 ):
 case( '\n' ): case( '\r' ):
  executeSelection();
  break;
 case( 127 ):
 case( 0407 ):
 case( 0512 ):
  len = strlen( userInput );
  if( len >= 2 ) {
   userInput[ len-2 ] = '_';
   userInput[ len-1 ] = '\0';
  }
 default:
  len = strlen( userInput );
  if( isValidInput( ch ) && len < 32 ) {
   userInput[ len-1 ] = ch;
   userInput[ len ] = '_';
   userInput[ len+1 ] = '\0';
  }
  ret = 0;
  break;
 }
 return ret;
}

canonical_original_code:
int handleKey(int ch)
{
 static int escapeCount = 0;
 int ret = 1;
 int len = 0;
 if( showHelpWindow ) {
  if( ch != 27 ) {
   return 0;
  }
  delwin( helpwin );
  helpwin = ((void *)0);
  showHelpWindow = 0;
  fullRedraw = 1;
  return 0;
 }
 if( ch != 27 ) {
  escapeCount = 0;
 }
 switch( ch ) {
 case( 27 ):
  escapeCount++;
  if( escapeCount > 1 ) {
   Error_Set( 0 );
   escapeCount = 0;
  }
  break;
 case( 0402 ):
  items_SelectDelta( 0, 1 );
  copyItemToUserInput();
  break;
 case( 0403 ):
  items_SelectDelta( 0, -1 );
  copyItemToUserInput();
  break;
 case( 0404 ):
  items_SelectDelta( -1, 0 );
  copyItemToUserInput();
  break;
 case( 0405 ):
  items_SelectDelta( 1, 0 );
  copyItemToUserInput();
  break;
 case( 0406 ):
  items_Select( 0 );
  copyItemToUserInput();
  break;
 case( 0550 ):
  items_Select( -1 );
  copyItemToUserInput();
  break;
 case( (('h')&037) ):
  showHelpWindow = 1;
  break;
 case( (('u')&037) ):
  clearInput();
  break;
 case( '\t' ):
  items_SelectNextSection();
  break;
 case( 0527 ):
 case( '\n' ): case( '\r' ):
  executeSelection();
  break;
 case( 127 ):
 case( 0407 ):
 case( 0512 ):
  len = strlen( userInput );
  if( len >= 2 ) {
   userInput[ len-2 ] = '_';
   userInput[ len-1 ] = '\0';
  }
 default:
  len = strlen( userInput );
  if( isValidInput( ch ) && len < 32 ) {
   userInput[ len-1 ] = ch;
   userInput[ len ] = '_';
   userInput[ len+1 ] = '\0';
  }
  ret = 0;
  break;
 }
 return ret;
}

variable_types: escapeCount int

variable_types: ret int

variable_types: len int


handleMouse

repo: BleuLlama/model-t-shell

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

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

original_code:
int handleMouse( int ch )
{
 int ret = 0;
 int my = 0;
 int mx = 0;
 my=my; mx=mx;
 if( ch != 0631 ) return ret;
 (my = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 return ret;
}

canonical_original_code:
int handleMouse(int ch)
{
 int ret = 0;
 int my = 0;
 int mx = 0;
 my=my; mx=mx;
 if( ch != 0631 ) return ret;
 (my = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 return ret;
}

variable_types: ch int

variable_types: my int

variable_types: mx int

return_type: int


handleResize

decompiled_code:
__int64 __fastcall handleResize(int a1)
{
__int64 result; // rax

if ( a1 != 410 )
return 0LL;
delwin(win);
result = 1LL;
win = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1)
{
__int64 result; // rax

if ( a1 != 410 )
return 0LL;
delwin(win);
result = 1LL;
win = 0LL;
return result;
}

original_code:
int handleResize( int ch )
{
 if( ch != 0632 ) return 0;
 delwin( win );
 win = ((void *)0);
 return 1;
}

canonical_original_code:
int handleResize(int ch)
{
 if( ch != 0632 ) return 0;
 delwin( win );
 win = ((void *)0);
 return 1;
}


doCursesInterface

decompiled_code:
int doCursesInterface()
{
__int64 v0; // rsi
__int64 v1; // rdi
int v2; // ebp
int v3; // er13
int v4; // er12

clearInput();
exitNow = 0;
if ( stdscr )
{
v0 = (unsigned int)(stdscr->_maxy + 1);
v1 = (unsigned int)(stdscr->_maxx + 1);
}
else
{
v0 = 0xFFFFFFFFLL;
v1 = 0xFFFFFFFFLL;
}
items_Init(v1, v0);
items_Populate();
while ( !exitNow )
{
if ( stdscr )
{
v3 = stdscr->_maxy + 1;
v4 = stdscr->_maxx + 1;
}
else
{
v3 = -1;
v4 = -1;
}
v2 = wgetch(stdscr);
if ( (unsigned int)handleResize(v2) || v2 == -1 )
{
if ( showHelpWindow )
showHelp(v4, v3);
else
showDisplay(v4, v3);
doupdate();
v2 = -1;
}
handleKey(v2);
}
return deinitScreen();
}

canonical_decompiled_code:
int func20()
{
__int64 v0; // rsi
__int64 v1; // rdi
int v2; // ebp
int v3; // er13
int v4; // er12

func6();
exitNow = 0;
if ( stdscr )
{
v0 = (unsigned int)(stdscr->_maxy + 1);
v1 = (unsigned int)(stdscr->_maxx + 1);
}
else
{
v0 = 0xFFFFFFFFLL;
v1 = 0xFFFFFFFFLL;
}
items_Init(v1, v0);
items_Populate();
while ( !exitNow )
{
if ( stdscr )
{
v3 = stdscr->_maxy + 1;
v4 = stdscr->_maxx + 1;
}
else
{
v3 = -1;
v4 = -1;
}
v2 = wgetch(stdscr);
if ( (unsigned int)func19(v2) || v2 == -1 )
{
if ( showHelpWindow )
func14(v4, v3);
else
func15(v4, v3);
doupdate();
v2 = -1;
}
func17(v2);
}
return func1();
}

original_code:
void doCursesInterface( void )
{
 int ch = 0;
 int mx = 0, my = 0;
 clearInput();
 exitNow = 0;
 (my = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 items_Init( mx, my );
 items_Populate();
 while( !exitNow )
 {
  (my = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  ch = wgetch(stdscr);
  if( handleResize( ch )) ch = -1;
  if( ch == -1 )
  {
   if( showHelpWindow ) {
    showHelp( mx, my );
   } else {
    showDisplay( mx, my );
   }
   doupdate();
  }
  handleMouse( ch );
  handleKey( ch );
 }
 deinitScreen();
}

canonical_original_code:
void doCursesInterface()
{
 int ch = 0;
 int mx = 0; int my = 0;
 clearInput();
 exitNow = 0;
 (my = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 items_Init( mx, my );
 items_Populate();
 while( !exitNow )
 {
  (my = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mx = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  ch = wgetch(stdscr);
  if( handleResize( ch )) ch = -1;
  if( ch == -1 )
  {
   if( showHelpWindow ) {
    showHelp( mx, my );
   } else {
    showDisplay( mx, my );
   }
   doupdate();
  }
  handleMouse( ch );
  handleKey( ch );
 }
 deinitScreen();
}

return_type: void


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
fprintf(stderr, "Model \"T\" Shell v%s %s Scott Lawrence, yorgle@gmail.com\n", "0.05", "2013-Jan-09");
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
return fprintf(stderr, " %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func21(const char *a1)
{
fprintf(stderr, "Model \"T\" Shell v%s %s Scott Lawrence, yorgle@gmail.com\n", "0.05", "2013-Jan-09");
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
return fprintf(stderr, " %s\n", a1);
}

original_code:
void usage( char * pn )
{
 fprintf( stderr, "Model \"T\" Shell v%s  %s Scott Lawrence, yorgle@gmail.com\n",
  "0.05", "2013-Jan-09" );
 fprintf( stderr, "Usage:\n" );
 fprintf( stderr, "       %s\n", pn );
}

canonical_original_code:
void usage(char *pn)
{
 fprintf( stderr, "Model \"T\" Shell v%s  %s Scott Lawrence, yorgle@gmail.com\n",
  "0.05", "2013-Jan-09" );
 fprintf( stderr, "Usage:\n" );
 fprintf( stderr, "       %s\n", pn );
}

variable_types:
pn
char *


handleOptions

decompiled_code:
__int64 __fastcall handleOptions(int a1, const char **a2)
{
if ( a1 == 1 )
return 0LL;
usage(*a2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1, const char **a2)
{
if ( a1 == 1 )
return 0LL;
func21(*a2);
return 0xFFFFFFFFLL;
}

original_code:
int handleOptions( int argc, char ** argv )
{
 if( argc != 1 ) {
  usage( argv[0] );
  return -1;
 }
 return 0;
}

canonical_original_code:
int handleOptions(int argc, char **argv)
{
 if( argc != 1 ) {
  usage( argv[0] );
  return -1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


main

canonical_name: main

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

Error_Set(0LL);
if ( (unsigned int)handleOptions(argc, argv) )
return -1;
v3 = 0;
conf_Init();
v4 = conf_Get("StartDir");
utils_changeDirectory(v4, 1LL);
v5 = (const char *)conf_Get("StartDir");
printf("Change to %s\n", v5);
initScreen();
doCursesInterface();
return v3;
}

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

Error_Set(0LL);
if ( (unsigned int)func22(argc, argv) )
return -1;
v3 = 0;
conf_Init();
v4 = conf_Get("StartDir");
utils_changeDirectory(v4, 1LL);
v5 = (const char *)conf_Get("StartDir");
printf("Change to %s\n", v5);
func0();
func20();
return v3;
}

original_code:
int main( int argc, char ** argv )
{
 Error_Set( 0 );
 if( handleOptions( argc, argv )) {
  return -1;
 }
 conf_Init();
 utils_changeDirectory( conf_Get( "StartDir" ), 1);
 printf( "Change to %s\n", conf_Get( "StartDir" ));
 initScreen();
 doCursesInterface();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 Error_Set( 0 );
 if( handleOptions( argc, argv )) {
  return -1;
 }
 conf_Init();
 utils_changeDirectory( conf_Get( "StartDir" ), 1);
 printf( "Change to %s\n", conf_Get( "StartDir" ));
 initScreen();
 doCursesInterface();
 return 0;
}


decompiled_code:
char *__fastcall conf_InGroup(char *s1, char *s2)
{
size_t v2; // r12
int v3; // er8
char *result; // rax

if ( !s1 )
return 0LL;
if ( !s2 )
return 0LL;
v2 = (int)strlen(s1);
v3 = strncmp(s1, s2, v2);
result = 0LL;
if ( !v3 && s2[v2] == 46 )
result = &s2[v2 + 1];
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *s1, char *s2)
{
size_t v2; // r12
int v3; // er8
char *result; // rax

if ( !s1 )
return 0LL;
if ( !s2 )
return 0LL;
v2 = (int)strlen(s1);
v3 = strncmp(s1, s2, v2);
result = 0LL;
if ( !v3 && s2[v2] == 46 )
result = &s2[v2 + 1];
return result;
}

original_code:
char * conf_InGroup( char * group, char * key )
{
 int glen;
 if( !group || !key ) return ((void *)0);
 glen = strlen( group );
 if( !strncmp( group, key, glen )) {
  if( *(key+glen) == '.' ) {
   return key+glen+1;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *conf_InGroup(char *group, char *key)
{
 int glen;
 if( !group || !key ) return ((void *)0);
 glen = strlen( group );
 if( !strncmp( group, key, glen )) {
  if( *(key+glen) == '.' ) {
   return key+glen+1;
  }
 }
 return ((void *)0);
}

variable_types:
group
char *

variable_types:
key
char *

variable_types: glen int

return_type: char *


decompiled_code:
const char *__fastcall conf_TrimString(char *s)
{
const unsigned __int16 *v1; // rbx
const char *v2; // r12
int v3; // eax
__int64 i; // rdx

if ( !s )
return 0LL;
v1 = *_ctype_b_loc();
do
v2 = s++;
while ( (v1[*v2] & 0x2000) != 0 );
v3 = strlen(v2) - 1;
i = v3;
if ( (v1[v2[v3]] & 0x2000) != 0 )
{
if ( v3 < 0 )
return v2;
for ( i = v3 - 1LL; ; --i )
{
--v3;
if ( (v1[v2[i]] & 0x2000) == 0 )
break;
if ( v3 == -1 )
return v2;
}
}
if ( v3 >= 0 )
v2[i + 1] = 0;
return v2;
}

original_code:
char * conf_TrimString( char * in )
{
 char * ret = in;
 int idx;
 if( !in ) return ret;
 for( idx=0 ; ((*__ctype_b_loc ())[(int) ((in[idx]))] & (unsigned short int) _ISspace) ; idx++ );
 ret = &in[idx];
 for( idx=strlen(ret)-1 ; ((*__ctype_b_loc ())[(int) ((ret[idx]))] & (unsigned short int) _ISspace)&& idx >=0 ; idx-- );
 if( idx >= 0 ) ret[idx+1] = '\0';
 return ret;
}

canonical_original_code:
char *conf_TrimString(char *in)
{
 char *ret = in;
 int idx;
 if( !in ) return ret;
 for( idx=0 ; ((*__ctype_b_loc ())[(int) ((in[idx]))] & (unsigned short) _ISspace) ; idx++ );
 ret = &in[idx];
 for( idx=strlen(ret)-1 ; ((*__ctype_b_loc ())[(int) ((ret[idx]))] & (unsigned short) _ISspace)&& idx >=0 ; idx-- );
 if( idx >= 0 ) ret[idx+1] = '\0';
 return ret;
}

variable_types:
in
char *

variable_types:
ret
char *

variable_types: idx int


decompiled_code:
char *__fastcall conf_Find(char *s1)
{
char *v1; // rbx

if ( !cis )
return 0LL;
v1 = &cis;
while ( !(unsigned int)string_sameCI(s1, v1) && strcmp(s1, v1) )
{
v1 += 768;
if ( !*v1 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func2(char *s1)
{
char *v1; // rbx

if ( !cis )
return 0LL;
v1 = &cis;
while ( !(unsigned int)string_sameCI(s1, v1) && strcmp(s1, v1) )
{
v1 += 768;
if ( !*v1 )
return 0LL;
}
return v1;
}

original_code:
confItem * conf_Find( char * key )
{
 int ci = 0;
 while( cis[ci].key[0] != '\0' )
 {
  if( string_sameCI( key, cis[ci].key )) return( &cis[ci] );
  if( !strcmp( key, cis[ci].key )) return( &cis[ci] );
  ci++;
 }
 return ((void *)0);
}

canonical_original_code:
struct confItem *conf_Find(char *key)
{
 int ci = 0;
 while( cis[ci].key[0] != '\0' )
 {
  if( string_sameCI( key, cis[ci].key )) return( &cis[ci] );
  if( !strcmp( key, cis[ci].key )) return( &cis[ci] );
  ci++;
 }
 return ((void *)0);
}

variable_types: ci int

return_type: struct confItem { char key[-1]; char value[-1]; char d0[-1]; } *


decompiled_code:
__int64 __fastcall conf_GetKV(unsigned int a1, _QWORD *a2, _QWORD *a3)
{
__int64 v3; // rax

if ( a1 > 0x64 )
return 0xFFFFFFFFLL;
v3 = 768LL * (int)a1;
if ( !cis[v3] )
return 4294967294LL;
*a2 = &cis[v3];
*a3 = (char *)&unk_8E0 + v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, _QWORD *a2, _QWORD *a3)
{
__int64 v3; // rax

if ( a1 > 0x64 )
return 0xFFFFFFFFLL;
v3 = 768LL * (int)a1;
if ( !cis[v3] )
return 4294967294LL;
*a2 = &cis[v3];
*a3 = (char *)&unk_8E0 + v3;
return 0LL;
}

original_code:
int conf_GetKV( int idx, char ** key, char ** value )
{
 if( idx > (100) || idx < 0 ) {
  return -1;
 }
 if( cis[idx].key[0] == '\0' ) return -2;
 *key = cis[idx].key;
 *value = cis[idx].value;
 return 0;
}

canonical_original_code:
int conf_GetKV(int idx, char **key, char **value)
{
 if( idx > (100) || idx < 0 ) {
  return -1;
 }
 if( cis[idx].key[0] == '\0' ) return -2;
 *key = cis[idx].key;
 *value = cis[idx].value;
 return 0;
}

variable_types:
key
char **

variable_types:
value
char **


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

result = conf_Find(a1);
if ( result )
result += 256;
return result;
}

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

result = func2(a1);
if ( result )
result += 256;
return result;
}

original_code:
char * conf_Get( char * key )
{
 confItem * c = conf_Find( key );
 if( !c ) return ((void *)0);
 return c->value;
}

canonical_original_code:
char *conf_Get(char *key)
{
 struct confItem *c = conf_Find( key );
 if( !c ) return ((void *)0);
 return c->value;
}

variable_types: struct confItem { char key[-1]; char value[-1]; char d0[-1]; } *


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

v1 = conf_Get(a1);
if ( v1 )
result = atoi(v1);
else
result = 0;
return result;
}

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

v1 = func5(a1);
if ( v1 )
result = atoi(v1);
else
result = 0;
return result;
}

original_code:
int conf_GetInt( char * key )
{
 char * v = conf_Get( key );
 if( !v ) return 0;
 return( atoi( v ));
}

canonical_original_code:
int conf_GetInt(char *key)
{
 char *v = conf_Get( key );
 if( !v ) return 0;
 return( atoi( v ));
}

variable_types:
v
char *


decompiled_code:
int __fastcall conf_Set(char *src, char *a2)
{
char *v3; // rdi
char *v5; // rax
int v6; // edx
char *v7; // rdi

v3 = conf_Find(src);
if ( !v3 )
{
if ( cis[0] )
{
v5 = (char *)&unk_AE0;
v6 = 0;
do
{
v5 += 768;
++v6;
}
while ( *(v5 - 768) );
v7 = &cis[768 * v6];
}
else
{
v7 = cis;
}
v3 = strncpy(v7, src, 0x100uLL);
}
strncpy(v3 + 256, a2, 0x100uLL);
return conf_Save();
}

canonical_decompiled_code:
int __fastcall func7(char *src, char *a2)
{
char *v3; // rdi
char *v5; // rax
int v6; // edx
char *v7; // rdi

v3 = func2(src);
if ( !v3 )
{
if ( cis[0] )
{
v5 = (char *)&unk_AE0;
v6 = 0;
do
{
v5 += 768;
++v6;
}
while ( *(v5 - 768) );
v7 = &cis[768 * v6];
}
else
{
v7 = cis;
}
v3 = strncpy(v7, src, 0x100uLL);
}
strncpy(v3 + 256, a2, 0x100uLL);
return func3();
}

original_code:
void conf_Set( char * key, char * val )
{
 confItem * c = conf_Find( key );
 if( !c ) {
  int ci = 0;
  while( cis[ci].key[0] != '\0' ) { ci++; };
  c = &cis[ci];
  strncpy( c->key, key, (256) );
 }
 strncpy( c->value, val, (256));
 conf_Save();
}

canonical_original_code:
void conf_Set(char *key, char *val)
{
 struct confItem *c = conf_Find( key );
 if( !c ) {
  int ci = 0;
  while( cis[ci].key[0] != '\0' ) { ci++; };
  c = &cis[ci];
  strncpy( c->key, key, (256) );
 }
 strncpy( c->value, val, (256));
 conf_Save();
}

variable_types:
val
char *

user_defined_types: struct confItem { char key[-1]; char value[-1]; char d0[-1]; }


decompiled_code:
int __fastcall conf_SetInt(char *a1, unsigned int a2)
{
char *v2; // rax

v2 = conf_Find(a1);
if ( v2 )
{
snprintf(v2 + 256, (int)a2, "%d", a2);
LODWORD(v2) = conf_Save();
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func10(char *a1, unsigned int a2)
{
char *v2; // rax

v2 = func2(a1);
if ( v2 )
{
snprintf(v2 + 256, (int)a2, "%d", a2);
LODWORD(v2) = func3();
}
return (int)v2;
}

original_code:
void conf_SetInt( char * key, int val )
{
 confItem * c = conf_Find( key );
 if( !c ) return;
 snprintf( c->value, val, "%d", val );
 conf_Save();
}

canonical_original_code:
void conf_SetInt(char *key, int val)
{
 struct confItem *c = conf_Find( key );
 if( !c ) return;
 snprintf( c->value, val, "%d", val );
 conf_Save();
}

variable_types: val int


decompiled_code:
char *__fastcall conf_Item(int a1)
{
_BYTE *v1; // rdx
int v2; // eax

if ( a1 >= 0 && cis[0] )
{
v1 = &unk_AE0;
v2 = 0;
if ( !a1 )
return cis;
while ( 1 )
{
++v2;
if ( !*v1 )
break;
v1 += 768;
if ( a1 == v2 )
return &cis[768 * a1];
}
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func11(int a1)
{
_BYTE *v1; // rdx
int v2; // eax

if ( a1 >= 0 && cis[0] )
{
v1 = &unk_AE0;
v2 = 0;
if ( !a1 )
return cis;
while ( 1 )
{
++v2;
if ( !*v1 )
break;
v1 += 768;
if ( a1 == v2 )
return &cis[768 * a1];
}
}
return 0LL;
}

original_code:
confItem * conf_Item( int idx )
{
 int ci = 0;
 if( idx < 0 ) return ((void *)0);
 while( cis[ci].key[0] != '\0' )
 {
  if( ci == idx ) return &cis[ci];
  ci++;
 }
 return ((void *)0);
}

canonical_original_code:
struct confItem *conf_Item(int idx)
{
 int ci = 0;
 if( idx < 0 ) return ((void *)0);
 while( cis[ci].key[0] != '\0' )
 {
  if( ci == idx ) return &cis[ci];
  ci++;
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall conf_NextInGroup(__int64 a1, int a2)
{
int v2; // er12
__int64 v3; // rbx
char *v4; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = a2 + 1;
if ( a2 < 0 )
v2 = 0;
v3 = 768LL * v2;
if ( !cis[v3] )
return 0xFFFFFFFFLL;
v4 = &cis[v3];
while ( !(unsigned int)string_startsWith(v4, a1) )
{
v4 += 768;
++v2;
if ( !*v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
int v2; // er12
__int64 v3; // rbx
char *v4; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = a2 + 1;
if ( a2 < 0 )
v2 = 0;
v3 = 768LL * v2;
if ( !cis[v3] )
return 0xFFFFFFFFLL;
v4 = &cis[v3];
while ( !(unsigned int)string_startsWith(v4, a1) )
{
v4 += 768;
++v2;
if ( !*v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int conf_NextInGroup( char * group, int after )
{
 int ret = after;
 if( !group ) return -1;
 if( after < 0 )
 {
  ret = 0;
 } else {
  ret++;
 }
 while( cis[ret].key[0] != '\0' )
 {
  if( string_startsWith( cis[ret].key, group )) {
   return ret;
  }
  ret++;
 }
 return -1;
}

canonical_original_code:
int conf_NextInGroup(char *group, int after)
{
 int ret = after;
 if( !group ) return -1;
 if( after < 0 )
 {
  ret = 0;
 } else {
  ret++;
 }
 while( cis[ret].key[0] != '\0' )
 {
  if( string_startsWith( cis[ret].key, group )) {
   return ret;
  }
  ret++;
 }
 return -1;
}

variable_types: after int

variable_types: ret int


decompiled_code:
void __fastcall string_Overlay(__int64 a1, char *a2)
{
char v2; // dl
__int64 i; // rax

if ( a1 )
{
if ( a2 )
{
v2 = *a2;
for ( i = 0LL; v2; v2 = a2[i] )
{
if ( !*(_BYTE *)(a1 + i) )
break;
*(_BYTE *)(a1 + i++) = v2;
}
}
}
}

original_code:
void string_Overlay( char * dest, char * src )
{
 int i=0;
 if( !dest || !src ) return;
 while( src[i] != '\0' && dest[i] != '\0' )
 {
  dest[i] = src[i];
  i++;
 }
}

canonical_original_code:
void string_Overlay(char *dest, char *src)
{
 int i = 0;
 if( !dest || !src ) return;
 while( src[i] != '\0' && dest[i] != '\0' )
 {
  dest[i] = src[i];
  i++;
 }
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: i int


decompiled_code:
void __fastcall string_Left(__int64 a1, char *a2)
{
if ( a2 )
{
if ( a1 )
string_Overlay(a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char *a2)
{
if ( a2 )
{
if ( a1 )
func1(a1, a2);
}
}

original_code:
void string_Left( char * dest, char * src )
{
 if( !src || !dest ) return;
 string_Overlay( dest, src );
}

canonical_original_code:
void string_Left(char *dest, char *src)
{
 if( !src || !dest ) return;
 string_Overlay( dest, src );
}


decompiled_code:
void __fastcall string_Right(char *s, char *a2)
{
int v2; // er12
int v3; // eax

if ( a2 )
{
if ( s )
{
v2 = strlen(a2);
v3 = strlen(s);
string_Overlay((__int64)&s[v3 - v2], a2);
}
}
}

canonical_decompiled_code:
void __fastcall func3(char *s, char *a2)
{
int v2; // er12
int v3; // eax

if ( a2 )
{
if ( s )
{
v2 = strlen(a2);
v3 = strlen(s);
func1((__int64)&s[v3 - v2], a2);
}
}
}

original_code:
void string_Right( char * dest, char * src )
{
 int sl, dl;
 if( !src || !dest ) return;
 sl = strlen( src );
 dl = strlen( dest );
 string_Overlay( dest + (dl-sl), src );
}

canonical_original_code:
void string_Right(char *dest, char *src)
{
 int sl; int dl;
 if( !src || !dest ) return;
 sl = strlen( src );
 dl = strlen( dest );
 string_Overlay( dest + (dl-sl), src );
}

variable_types: sl int

variable_types: dl int


decompiled_code:
void __fastcall string_Center(char *s, char *a2)
{
int v2; // er12
int v3; // eax

if ( a2 )
{
if ( s )
{
v2 = strlen(a2);
v3 = strlen(s);
string_Overlay((__int64)&s[(v3 - v2) / 2], a2);
}
}
}

canonical_decompiled_code:
void __fastcall func4(char *s, char *a2)
{
int v2; // er12
int v3; // eax

if ( a2 )
{
if ( s )
{
v2 = strlen(a2);
v3 = strlen(s);
func1((__int64)&s[(v3 - v2) / 2], a2);
}
}
}

original_code:
void string_Center( char * dest, char * src )
{
 int sl, dl;
 if( !src || !dest ) return;
 sl = strlen( src );
 dl = strlen( dest );
 string_Overlay( dest + ((dl - sl)/2), src );
}

canonical_original_code:
void string_Center(char *dest, char *src)
{
 int sl; int dl;
 if( !src || !dest ) return;
 sl = strlen( src );
 dl = strlen( dest );
 string_Overlay( dest + ((dl - sl)/2), src );
}


decompiled_code:
_BOOL8 __fastcall string_sameCI(__int128 a1)
{
_BOOL8 result; // rax
__int64 v2; // r12
char *v3; // rbp
__int64 v4; // rbx
const __int32_t *v5; // rdx
const __int32_t *v6; // rcx
__int64 v7; // rsi

result = 1LL;
if ( a1 != 0 )
{
v2 = a1;
if ( (_QWORD)a1 && (v3 = (char *)*((_QWORD *)&a1 + 1)) != 0LL )
{
v4 = *(char *)a1;
v5 = *_ctype_toupper_loc();
v6 = v5;
v7 = (char)**((_BYTE **)&a1 + 1);
if ( (_BYTE)v4 )
{
while ( 1 )
{
v7 = *v3;
v6 = &v5[v4];
if ( !(_BYTE)v7 )
break;
if ( v5[v7] != *v6 )
goto LABEL_11;
v4 = *(char *)++v2;
if ( !(_BYTE)v4 )
{
v7 = v3[1];
v6 = v5;
break;
}
++v3;
}
}
result = v5[v7] == *v6;
}
else
{
LABEL_11:
result = 0LL;
}
}
return result;
}

original_code:
int string_sameCI( char * a, char * b )
{
 if( !a && !b ) return 1;
 if( !a || !b ) return 0;
 while( *a && *b ) {
  if( toupper(*a) != toupper(*b) ) return 0;
  a++; b++;
 }
 if( toupper(*a) == toupper(*b) ) return 1;
 return 0;
}

canonical_original_code:
int string_sameCI(char *a, char *b)
{
 if( !a && !b ) return 1;
 if( !a || !b ) return 0;
 while( *a && *b ) {
  if( toupper(*a) != toupper(*b) ) return 0;
  a++; b++;
 }
 if( toupper(*a) == toupper(*b) ) return 1;
 return 0;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
_BOOL8 __fastcall string_startsWith(char *s1, char *s2)
{
size_t v2; // rax

if ( !s1 )
return 0LL;
if ( !s2 )
return 0LL;
v2 = strlen(s2);
return strncmp(s1, s2, v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(char *s1, char *s2)
{
size_t v2; // rax

if ( !s1 )
return 0LL;
if ( !s2 )
return 0LL;
v2 = strlen(s2);
return strncmp(s1, s2, v2) == 0;
}

original_code:
int string_startsWith( char * haystack, char * needle )
{
 if( !haystack || !needle ) return 0;
 if( !strncmp( haystack, needle, strlen( needle )) ) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int string_startsWith(char *haystack, char *needle)
{
 if( !haystack || !needle ) return 0;
 if( !strncmp( haystack, needle, strlen( needle )) ) {
  return 1;
 }
 return 0;
}

variable_types:
haystack
char *

variable_types:
needle
char *


decompiled_code:
char *utils_whoami()
{
char *result; // rax
__uid_t v1; // eax
struct passwd *v2; // rax

result = (char *)whoiam;
if ( !whoiam )
{
v1 = geteuid();
v2 = getpwuid(v1);
if ( v2 )
result = strdup(v2->pw_name);
else
result = strdup("you");
whoiam = (__int64)result;
}
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax
__uid_t v1; // eax
struct passwd *v2; // rax

result = (char *)whoiam;
if ( !whoiam )
{
v1 = geteuid();
v2 = getpwuid(v1);
if ( v2 )
result = strdup(v2->pw_name);
else
result = strdup("you");
whoiam = (__int64)result;
}
return result;
}

original_code:
char * utils_whoami( void )
{
 register struct passwd *pw;
 register uid_t uid;
 if( whoiam != ((void *)0) ) return whoiam;
 uid = geteuid ();
 pw = getpwuid (uid);
 if (pw) {
  whoiam = strdup( pw->pw_name );
 } else {
  whoiam = strdup( "you" );
 }
 return whoiam;
}

canonical_original_code:
char *utils_whoami()
{
 register struct passwd *pw;
 register unsigned int uid;
 if( whoiam != ((void *)0) ) return whoiam;
 uid = geteuid ();
 pw = getpwuid (uid);
 if (pw) {
  whoiam = strdup( pw->pw_name );
 } else {
  whoiam = strdup( "you" );
 }
 return whoiam;
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
uid
unsigned int


decompiled_code:
char *__fastcall utils_getcwd(char *a1, int a2)
{
return getcwd(a1, a2);
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, int a2)
{
return getcwd(a1, a2);
}

original_code:
void utils_getcwd( char * buf, int bufsize )
{
 getcwd( buf, bufsize );
}

canonical_original_code:
void utils_getcwd(char *buf, int bufsize)
{
 getcwd( buf, bufsize );
}

variable_types:
buf
char *

variable_types: bufsize int


decompiled_code:
char *__fastcall utils_changeDirectory(char *s, int a2)
{
char *v2; // r12
bool v3; // zf
int v4; // ebx
char *result; // rax
size_t v6; // rdx
char v7[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( s )
{
v2 = cwd;
v3 = strcmp(s, ".. (Parent)") == 0;
v4 = !v3;
if ( v3 )
{
v6 = strlen(cwd);
for ( result = 0LL; (char *)v6 != result; ++result )
{
if ( result[(_QWORD)v2] == 47 )
v4 = (int)result;
}
if ( v4 )
v2[v4] = 0;
else
v2[1] = 0;
}
else if ( cwd )
{
if ( a2 )
snprintf(v7, 0x100uLL, "%s", s);
else
snprintf(v7, 0x100uLL, "%s/%s", cwd, s);
free(cwd);
result = strdup(v7);
cwd = result;
}
else
{
result = strdup(s);
cwd = result;
}
}
else
{
utils_getcwd(v7, 4096);
result = strdup(v7);
cwd = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, int a2)
{
char *v2; // r12
bool v3; // zf
int v4; // ebx
char *result; // rax
size_t v6; // rdx
char v7[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( s )
{
v2 = cwd;
v3 = strcmp(s, ".. (Parent)") == 0;
v4 = !v3;
if ( v3 )
{
v6 = strlen(cwd);
for ( result = 0LL; (char *)v6 != result; ++result )
{
if ( result[(_QWORD)v2] == 47 )
v4 = (int)result;
}
if ( v4 )
v2[v4] = 0;
else
v2[1] = 0;
}
else if ( cwd )
{
if ( a2 )
snprintf(v7, 0x100uLL, "%s", s);
else
snprintf(v7, 0x100uLL, "%s/%s", cwd, s);
free(cwd);
result = strdup(v7);
cwd = result;
}
else
{
result = strdup(s);
cwd = result;
}
}
else
{
func1(v7, 4096);
result = strdup(v7);
cwd = result;
}
return result;
}

original_code:
void utils_changeDirectory( char * diff, int isAbsolute )
{
 char buf[ 256 ];
 int idx = 0;
 int lastslash = 0;
 if( diff == ((void *)0) ) {
  char pth[4096];
  utils_getcwd( pth, sizeof( pth ));
  cwd = strdup( pth );
  return;
 }
 if( !strcmp( diff, ".. (Parent)" )) {
  for( idx=0 ; idx< strlen( cwd ) ; idx++ ) {
   if( cwd[idx] == '/' ) lastslash = idx;
  }
  if( lastslash > 0 ) cwd[lastslash] = '\0';
  if( lastslash == 0 ) cwd[lastslash+1] = '\0';
  return;
 }
 if( cwd != ((void *)0) ) {
  if( isAbsolute ) {
   snprintf( buf, 256, "%s", diff );
  } else {
   snprintf( buf, 256, "%s/%s", cwd, diff );
  }
  free( cwd );
  cwd = strdup( buf );
 } else {
  cwd = strdup( diff );
 }
}

canonical_original_code:
void utils_changeDirectory(char *diff, int isAbsolute)
{
 char buf[256];
 int idx = 0;
 int lastslash = 0;
 if( diff == ((void *)0) ) {
  char pth[4096];
  utils_getcwd( pth, sizeof( pth ));
  cwd = strdup( pth );
  return;
 }
 if( !strcmp( diff, ".. (Parent)" )) {
  for( idx=0 ; idx< strlen( cwd ) ; idx++ ) {
   if( cwd[idx] == '/' ) lastslash = idx;
  }
  if( lastslash > 0 ) cwd[lastslash] = '\0';
  if( lastslash == 0 ) cwd[lastslash+1] = '\0';
  return;
 }
 if( cwd != ((void *)0) ) {
  if( isAbsolute ) {
   snprintf( buf, 256, "%s", diff );
  } else {
   snprintf( buf, 256, "%s/%s", cwd, diff );
  }
  free( cwd );
  cwd = strdup( buf );
 } else {
  cwd = strdup( diff );
 }
}

variable_types:
diff
char *

variable_types: isAbsolute int

variable_types:
buf
char [256]

variable_types: idx int

variable_types: lastslash int

variable_types:
pth
char [4096]


decompiled_code:
const char *Error_Get()
{
const char *v0; // r8
__int64 v1; // rax

v0 = "e103: Unknown error.";
v1 = (unsigned int)(errCode + 2);
if ( (unsigned int)v1 <= 3 )
v0 = CSWTCH_2[v1];
return v0;
}

canonical_decompiled_code:
const char *func0()
{
const char *v0; // r8
__int64 v1; // rax

v0 = "e103: Unknown error.";
v1 = (unsigned int)(errCode + 2);
if ( (unsigned int)v1 <= 3 )
v0 = CSWTCH_2[v1];
return v0;
}

original_code:
char * Error_Get( void )
{
 switch( errCode )
 {
  case( 0 ): return "";
  case( 1 ): return "e1: End of file reached";
  case( -2 ): return "e2: No config file found!";
 }
 return "e103: Unknown error.";
}

canonical_original_code:
char *Error_Get()
{
 switch( errCode )
 {
  case( 0 ): return "";
  case( 1 ): return "e1: End of file reached";
  case( -2 ): return "e2: No config file found!";
 }
 return "e103: Unknown error.";
}


decompiled_code:
void __fastcall Error_Set(int a1)
{
errCode = a1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
errCode = a1;
}

original_code:
void Error_Set( int e )
{
 errCode = e;
}

canonical_original_code:
void Error_Set(int e)
{
 errCode = e;
}

variable_types: e int


repo: Blizzardking/FileSystem

decompiled_code:
__int64 __fastcall read_block(unsigned int a1, void *a2, size_t a3)
{
__int64 result; // rax
int *v5; // rax
int *v6; // rax

if ( a3 > 0x800 )
return -1LL;
if ( (int)lseek(curr_fd, (int)(a1 << 11), 0) < 0 )
{
fprintf(stderr, "Error in seek block %d\n", a1);
v6 = _errno_location();
exit(*v6);
}
LODWORD(result) = read(curr_fd, a2, a3);
if ( (int)result < 0 )
{
fprintf(stderr, "Error in read block %d\n", a1);
v5 = _errno_location();
exit(*v5);
}
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, void *a2, size_t a3)
{
__int64 result; // rax
int *v5; // rax
int *v6; // rax

if ( a3 > 0x800 )
return -1LL;
if ( (int)lseek(curr_fd, (int)(a1 << 11), 0) < 0 )
{
fprintf(stderr, "Error in seek block %d\n", a1);
v6 = _errno_location();
exit(*v6);
}
LODWORD(result) = read(curr_fd, a2, a3);
if ( (int)result < 0 )
{
fprintf(stderr, "Error in read block %d\n", a1);
v5 = _errno_location();
exit(*v5);
}
return (int)result;
}

original_code:
ssize_t read_block(uint block_index, void* buf, size_t count) {
        int bytes = 0;
        if(count > sizeof(struct super_block))
                return -1;
        int offset = block_index * sizeof(struct super_block);
        int offs = 0;
        if((offs = lseek(curr_fd, offset, 0)) < 0) {
            fprintf(stderr, "Error in seek block %d\n", block_index);
            exit((*__errno_location ()));
        }
        if((bytes = read(curr_fd, (void *)(buf), count)) < 0) {
            fprintf(stderr, "Error in read block %d\n", block_index);
            exit((*__errno_location ()));
        }
        return bytes;
}

canonical_original_code:
long read_block(unsigned int block_index, void *buf, unsigned long count) {
        int bytes = 0;
        if(count > sizeof(struct super_block))
                return -1;
        int offset = block_index * sizeof(struct super_block);
        int offs = 0;
        if((offs = lseek(curr_fd, offset, 0)) < 0) {
            fprintf(stderr, "Error in seek block %d\n", block_index);
            exit((*__errno_location ()));
        }
        if((bytes = read(curr_fd, (void *)(buf), count)) < 0) {
            fprintf(stderr, "Error in read block %d\n", block_index);
            exit((*__errno_location ()));
        }
        return bytes;
}

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: bytes int

variable_types: offset int

variable_types: offs int

return_type: long

user_defined_types: struct super_block { unsigned int isize; unsigned int fsize; unsigned int nfree; unsigned int ninode; unsigned int free[251]; unsigned int inode[251]; char flock; char ilock; char fmod; char padding; long time[2]; }


decompiled_code:
__int64 __fastcall write_block(unsigned int a1, const void *a2, size_t a3)
{
__int64 result; // rax
int *v5; // rax
int *v6; // rax

if ( a3 > 0x800 )
return -1LL;
qmemcpy(&curr_block, a2, 0x800uLL);
if ( (int)lseek(curr_fd, (int)(a1 << 11), 0) < 0 )
{
fprintf(stderr, "Error in seek block %d\n", a1);
v6 = _errno_location();
exit(*v6);
}
LODWORD(result) = write(curr_fd, &curr_block, a3);
if ( (int)result < 0 )
{
fprintf(stderr, "Error in read block %d\n", a1);
v5 = _errno_location();
exit(*v5);
}
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, const void *a2, size_t a3)
{
__int64 result; // rax
int *v5; // rax
int *v6; // rax

if ( a3 > 0x800 )
return -1LL;
qmemcpy(&curr_block, a2, 0x800uLL);
if ( (int)lseek(curr_fd, (int)(a1 << 11), 0) < 0 )
{
fprintf(stderr, "Error in seek block %d\n", a1);
v6 = _errno_location();
exit(*v6);
}
LODWORD(result) = write(curr_fd, &curr_block, a3);
if ( (int)result < 0 )
{
fprintf(stderr, "Error in read block %d\n", a1);
v5 = _errno_location();
exit(*v5);
}
return (int)result;
}

original_code:
ssize_t write_block(uint block_index, void *buf, size_t count) {
        if(count > sizeof(struct super_block))
                return -1;
        int offset = block_index * sizeof(struct super_block);
        memcpy(curr_block.data, buf, sizeof(struct super_block));
        curr_block_num = block_index;
        int offs = 0;
        if((offs = lseek(curr_fd, offset, 0)) < 0) {
                fprintf(stderr, "Error in seek block %d\n", block_index);
                exit((*__errno_location ()));
        }
        int bytes = 0;
        if((bytes = write(curr_fd, curr_block.data, count)) < 0) {
                fprintf(stderr, "Error in read block %d\n", block_index);
                exit((*__errno_location ()));
        }
        return bytes;
}

canonical_original_code:
long write_block(unsigned int block_index, void *buf, unsigned long count) {
        if(count > sizeof(struct super_block))
                return -1;
        int offset = block_index * sizeof(struct super_block);
        memcpy(curr_block.data, buf, sizeof(struct super_block));
        curr_block_num = block_index;
        int offs = 0;
        if((offs = lseek(curr_fd, offset, 0)) < 0) {
                fprintf(stderr, "Error in seek block %d\n", block_index);
                exit((*__errno_location ()));
        }
        int bytes = 0;
        if((bytes = write(curr_fd, curr_block.data, count)) < 0) {
                fprintf(stderr, "Error in read block %d\n", block_index);
                exit((*__errno_location ()));
        }
        return bytes;
}


decompiled_code:
__int64 __fastcall free_block(unsigned int a1)
{
__int64 v1; // rax
int v2; // edx
__int64 v4; // rax
int v5[2]; // [rsp+0h] [rbp-808h] BYREF
__int64 v6[125]; // [rsp+8h] [rbp-800h] BYREF

v1 = (unsigned int)curr_superblock[2];
if ( (_DWORD)v1 == 251 )
{
v4 = *(_QWORD *)&curr_superblock[4];
v5[0] = 251;
v5[1] = v4;
qmemcpy(v6, (const void *)(unsigned int)((_DWORD)curr_superblock + 20), sizeof(v6));
write_block(a1, v5, 0x800uLL);
v2 = 1;
v1 = 0LL;
}
else
{
v2 = v1 + 1;
}
curr_superblock[v1 + 4] = a1;
curr_superblock[2] = v2;
return write_superblock();
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // rax
int v2; // edx
__int64 v4; // rax
int v5[2]; // [rsp+0h] [rbp-808h] BYREF
__int64 v6[125]; // [rsp+8h] [rbp-800h] BYREF

v1 = (unsigned int)curr_superblock[2];
if ( (_DWORD)v1 == 251 )
{
v4 = *(_QWORD *)&curr_superblock[4];
v5[0] = 251;
v5[1] = v4;
qmemcpy(v6, (const void *)(unsigned int)((_DWORD)curr_superblock + 20), sizeof(v6));
func1(a1, v5, 0x800uLL);
v2 = 1;
v1 = 0LL;
}
else
{
v2 = v1 + 1;
}
curr_superblock[v1 + 4] = a1;
curr_superblock[2] = v2;
return write_superblock();
}

original_code:
void free_block(uint free_block) {
    if(curr_superblock.nfree == 251) {
        struct head_free_block w;
        w.nfr = curr_superblock.nfree;
        memcpy(w.fr, curr_superblock.free, curr_superblock.nfree * sizeof(uint));
        write_block(free_block, (void*)&w, sizeof(struct super_block));
        curr_superblock.nfree = 0;
    }
    curr_superblock.free[curr_superblock.nfree++] = free_block;
    write_superblock();
}

canonical_original_code:
void free_block(unsigned int free_block) {
    if(curr_superblock.nfree == 251) {
        struct head_free_block w;
        w.nfr = curr_superblock.nfree;
        memcpy(w.fr, curr_superblock.free, curr_superblock.nfree * sizeof(uint));
        write_block(free_block, (void *)&w, sizeof(struct super_block));
        curr_superblock.nfree = 0;
    }
    curr_superblock.free[curr_superblock.nfree++] = free_block;
    write_superblock();
}

variable_types: struct head_free_block { unsigned int nfr; unsigned int fr[251]; unsigned int padding[-1]; }


decompiled_code:
__int64 allocate_block()
{
__int64 v0; // rdx
unsigned int v1; // er12
__int64 v3; // rdx
int v4; // [rsp+0h] [rbp-808h] BYREF
char src[2052]; // [rsp+4h] [rbp-804h] BYREF

v0 = (unsigned int)(curr_superblock[2] - 1);
v1 = curr_superblock[v0 + 4];
curr_superblock[2] = v0;
if ( !v1 )
{
fwrite("Error: the data blocks are full, allocation failure\n", 1uLL, 0x34uLL, stderr);
exit(-1);
}
if ( !(_DWORD)v0 )
{
read_block(v1, &v4, 0x800uLL);
v3 = (unsigned int)(v4 + 1);
curr_superblock[2] = v4;
memcpy((void *)(unsigned int)((_DWORD)curr_superblock + 16), src, 4 * v3);
}
write_superblock();
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
unsigned int v1; // er12
__int64 v3; // rdx
int v4; // [rsp+0h] [rbp-808h] BYREF
char src[2052]; // [rsp+4h] [rbp-804h] BYREF

v0 = (unsigned int)(curr_superblock[2] - 1);
v1 = curr_superblock[v0 + 4];
curr_superblock[2] = v0;
if ( !v1 )
{
fwrite("Error: the data blocks are full, allocation failure\n", 1uLL, 0x34uLL, stderr);
exit(-1);
}
if ( !(_DWORD)v0 )
{
func0(v1, &v4, 0x800uLL);
v3 = (unsigned int)(v4 + 1);
curr_superblock[2] = v4;
memcpy((void *)(unsigned int)((_DWORD)curr_superblock + 16), src, 4 * v3);
}
write_superblock();
return v1;
}

original_code:
uint allocate_block() {
    curr_superblock.nfree--;
    uint block_id = curr_superblock.free[curr_superblock.nfree];
    if(block_id == 0) {
        fprintf(stderr, "Error: the data blocks are full, allocation failure\n");
        exit(-1);
    }
    if(curr_superblock.nfree == 0) {
        struct head_free_block w;
        read_block(block_id, (void*)&w, sizeof(struct super_block));
        curr_superblock.nfree = w.nfr;
        memcpy(curr_superblock.free, w.fr, (curr_superblock.nfree + 1) * sizeof(uint));
    }
 write_superblock();
    return block_id;
}

canonical_original_code:
unsigned int allocate_block() {
    curr_superblock.nfree--;
    unsigned int block_id = curr_superblock.free[curr_superblock.nfree];
    if(block_id == 0) {
        fprintf(stderr, "Error: the data blocks are full, allocation failure\n");
        exit(-1);
    }
    if(curr_superblock.nfree == 0) {
        struct head_free_block w;
        read_block(block_id, (void *)&w, sizeof(struct super_block));
        curr_superblock.nfree = w.nfr;
        memcpy(curr_superblock.free, w.fr, (curr_superblock.nfree + 1) * sizeof(uint));
    }
 write_superblock();
    return block_id;
}

return_type: unsigned int

user_defined_types: struct head_free_block { unsigned int nfr; unsigned int fr[251]; unsigned int padding[-1]; }


decompiled_code:
__int64 initiate_free_list()
{
unsigned int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx
unsigned int v3; // edi

free_block(0);
v0 = curr_superblock[0] + 1;
result = (unsigned int)curr_superblock[1];
v2 = result - 1;
if ( (int)result - 1 > (unsigned int)(curr_superblock[0] + 1) )
{
do
{
v3 = v2--;
result = free_block(v3);
}
while ( v0 < v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx
unsigned int v3; // edi

func2(0);
v0 = curr_superblock[0] + 1;
result = (unsigned int)curr_superblock[1];
v2 = result - 1;
if ( (int)result - 1 > (unsigned int)(curr_superblock[0] + 1) )
{
do
{
v3 = v2--;
result = func2(v3);
}
while ( v0 < v2 );
}
return result;
}

original_code:
void initiate_free_list() {
    free_block(0);
    uint max_inode_block = 1 + curr_superblock.isize;
    int i;
    for(i = curr_superblock.fsize - 1; i > max_inode_block; i--) {
        free_block(i);
    }
}

canonical_original_code:
void initiate_free_list() {
    free_block(0);
    unsigned int max_inode_block = 1 + curr_superblock.isize;
    int i;
    for(i = curr_superblock.fsize - 1; i > max_inode_block; i--) {
        free_block(i);
    }
}

variable_types: i int


decompiled_code:
__int64 initiate_inode_list()
{
__int64 result; // rax
int v1; // ebp
unsigned int v2; // er13
unsigned int v3; // ebx
unsigned int v4; // edi
unsigned int v5; // ebp
unsigned int v6; // ebp
unsigned int v7; // ebx
_BYTE v8[128]; // [rsp+0h] [rbp-8A8h] BYREF
char v9[2088]; // [rsp+80h] [rbp-828h] BYREF

result = 0LL;
v1 = curr_superblock[0];
v2 = curr_superblock[0] + 1;
memset(v9, 0, 0x800uLL);
if ( (unsigned int)(curr_superblock[0] + 1) > 1 )
{
v3 = 2;
do
{
v4 = v3++;
result = write_block(v4, v9, 0x800uLL);
}
while ( v3 <= v2 );
v1 = curr_superblock[0];
}
v5 = 16 * v1;
if ( v5 <= 1 )
{
LABEL_12:
result = (unsigned int)curr_superblock[3];
if ( !(_DWORD)result )
{
fwrite("Error: the inode blocks are full, allocation falure!", 1uLL, 0x34uLL, stderr);
exit(-1);
}
}
else
{
v6 = v5 + 1;
v7 = 2;
while ( curr_superblock[3] != 251 )
{
read_inode(v7, v8);
result = check_allocation(v8);
if ( (_DWORD)result != 1 )
result = free_inode(v7);
if ( v6 == ++v7 )
goto LABEL_12;
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
int v1; // ebp
unsigned int v2; // er13
unsigned int v3; // ebx
unsigned int v4; // edi
unsigned int v5; // ebp
unsigned int v6; // ebp
unsigned int v7; // ebx
_BYTE v8[128]; // [rsp+0h] [rbp-8A8h] BYREF
char v9[2088]; // [rsp+80h] [rbp-828h] BYREF

result = 0LL;
v1 = curr_superblock[0];
v2 = curr_superblock[0] + 1;
memset(v9, 0, 0x800uLL);
if ( (unsigned int)(curr_superblock[0] + 1) > 1 )
{
v3 = 2;
do
{
v4 = v3++;
result = func1(v4, v9, 0x800uLL);
}
while ( v3 <= v2 );
v1 = curr_superblock[0];
}
v5 = 16 * v1;
if ( v5 <= 1 )
{
LABEL_12:
result = (unsigned int)curr_superblock[3];
if ( !(_DWORD)result )
{
fwrite("Error: the inode blocks are full, allocation falure!", 1uLL, 0x34uLL, stderr);
exit(-1);
}
}
else
{
v6 = v5 + 1;
v7 = 2;
while ( curr_superblock[3] != 251 )
{
read_inode(v7, v8);
result = check_allocation(v8);
if ( (_DWORD)result != 1 )
result = free_inode(v7);
if ( v6 == ++v7 )
goto LABEL_12;
}
}
return result;
}

original_code:
void initiate_inode_list() {
    int arr[512];
    memset(arr,0 ,sizeof(arr));
    int i;
    uint max_inode_block = 1 + curr_superblock.isize;
    for(i = 2; i <= max_inode_block; i++)
        write_block(i, arr, sizeof(arr));
    uint inode_number = curr_superblock.isize * (sizeof(struct super_block)/sizeof(struct inode));
    for(i = 2; i <= inode_number; i++) {
        if(curr_superblock.ninode == 251)
            break;
        struct inode ino;
        read_inode(i, &ino);
        if(check_allocation(&ino) != 1) {
            free_inode(i);
        }
    }
    if(curr_superblock.ninode == 0){
        fprintf(stderr,"Error: the inode blocks are full, allocation falure!");
        exit(-1);
    }
}

canonical_original_code:
void initiate_inode_list() {
    int arr[512];
    memset(arr,0 ,sizeof(arr));
    int i;
    unsigned int max_inode_block = 1 + curr_superblock.isize;
    for(i = 2; i <= max_inode_block; i++)
        write_block(i, arr, sizeof(arr));
    unsigned int inode_number = curr_superblock.isize * (sizeof(struct super_block)/sizeof(struct inode));
    for(i = 2; i <= inode_number; i++) {
        if(curr_superblock.ninode == 251)
            break;
        struct inode ino;
        read_inode(i, &ino);
        if(check_allocation(&ino) != 1) {
            free_inode(i);
        }
    }
    if(curr_superblock.ninode == 0){
        fprintf(stderr,"Error: the inode blocks are full, allocation falure!");
        exit(-1);
    }
}

variable_types:
arr
int [512]

variable_types: struct inode { unsigned short flags; char nlinks; char uid; char gid; char padding[3]; unsigned int size; unsigned int pos; unsigned int addr[20]; long actime[2]; long modtime[2]; }


decompiled_code:
__int64 __fastcall initiate_super_block(int a1, int a2, int a3)
{
curr_fd = a1;
curr_superblock[0] = a3;
curr_superblock[1] = a2;
*(_QWORD *)&curr_superblock[2] = 0LL;
initiate_free_list();
initiate_inode_list();
return write_superblock();
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2, int a3)
{
curr_fd = a1;
curr_superblock[0] = a3;
curr_superblock[1] = a2;
*(_QWORD *)&curr_superblock[2] = 0LL;
func4();
func5();
return write_superblock();
}

original_code:
void initiate_super_block(int fd, int total_block_number, int inode_block_number) {
    curr_fd = fd;
    curr_superblock.isize = inode_block_number;
    curr_superblock.fsize = total_block_number;
    curr_superblock.nfree = 0;
    curr_superblock.ninode = 0;
    initiate_free_list();
    initiate_inode_list();
    write_superblock();
}

variable_types: fd int


decompiled_code:
int print_superblock()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rsi
int result; // eax
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rsi

printf("isize: %d\n", (unsigned int)curr_superblock[0]);
printf("fsize: %d\n", (unsigned int)curr_superblock[1]);
printf("nfree: %d\n", (unsigned int)curr_superblock[2]);
LODWORD(v0) = curr_superblock[2] - 1;
if ( (int)v0 >= 0 )
{
v0 = (int)v0;
do
{
v1 = (unsigned int)curr_superblock[v0 + 4];
v2 = (unsigned int)v0--;
printf("free block %d: %d ", v2, v1);
}
while ( (int)v0 >= 0 );
}
putchar(10);
printf("ninode: %d\n", (unsigned int)curr_superblock[3]);
result = curr_superblock[3];
if ( result )
{
v4 = 0LL;
do
{
v5 = (unsigned int)curr_superblock[v4 + 255];
v6 = (unsigned int)v4++;
result = printf("free inode %d: %d ", v6, v5);
}
while ( curr_superblock[3] > (unsigned int)v4 );
}
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rsi
int result; // eax
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rsi

printf("isize: %d\n", (unsigned int)curr_superblock[0]);
printf("fsize: %d\n", (unsigned int)curr_superblock[1]);
printf("nfree: %d\n", (unsigned int)curr_superblock[2]);
LODWORD(v0) = curr_superblock[2] - 1;
if ( (int)v0 >= 0 )
{
v0 = (int)v0;
do
{
v1 = (unsigned int)curr_superblock[v0 + 4];
v2 = (unsigned int)v0--;
printf("free block %d: %d ", v2, v1);
}
while ( (int)v0 >= 0 );
}
putchar(10);
printf("ninode: %d\n", (unsigned int)curr_superblock[3]);
result = curr_superblock[3];
if ( result )
{
v4 = 0LL;
do
{
v5 = (unsigned int)curr_superblock[v4 + 255];
v6 = (unsigned int)v4++;
result = printf("free inode %d: %d ", v6, v5);
}
while ( curr_superblock[3] > (unsigned int)v4 );
}
return result;
}

original_code:
void print_superblock() {
    printf("isize: %d\n",curr_superblock.isize);
    printf("fsize: %d\n",curr_superblock.fsize);
    printf("nfree: %d\n",curr_superblock.nfree);
    int i;
    for(i = curr_superblock.nfree -1; i>=0; i--){
        printf("free block %d: %d  ",i, curr_superblock.free[i]);
    }
    printf("\n");
    printf("ninode: %d\n",curr_superblock.ninode);
    for(i = 0; i<curr_superblock.ninode; i++){
        printf("free inode %d: %d  ",i, curr_superblock.inode[i]);
    }
}


original_code:
void read_inode(uint inode, struct inode *inode_buf) {
    int block_index = (inode - 1) / (sizeof(struct super_block)/sizeof(struct inode)) + 2;
    int inode_offset = (inode - 1) % (sizeof(struct super_block)/sizeof(struct inode));
    int byte_offset = inode_offset * sizeof(struct inode);
    struct block curr_block;
    read_block(block_index, &curr_block, sizeof(struct super_block));
    memcpy((void *)inode_buf, (void *)&curr_block + byte_offset, sizeof(struct inode));
}

canonical_original_code:
void read_inode(unsigned int inode, struct inode *inode_buf) {
    int block_index = (inode - 1) / (sizeof(struct super_block)/sizeof(struct inode)) + 2;
    int inode_offset = (inode - 1) % (sizeof(struct super_block)/sizeof(struct inode));
    int byte_offset = inode_offset * sizeof(struct inode);
    struct block curr_block;
    read_block(block_index, &curr_block, sizeof(struct super_block));
    memcpy((void *)inode_buf, (void *)&curr_block + byte_offset, sizeof(struct inode));
}

variable_types:
inode
unsigned int

variable_types: struct inode { unsigned short flags; char nlinks; char uid; char gid; char padding[3]; unsigned int size; unsigned int pos; unsigned int addr[20]; long actime[2]; long modtime[2]; } *

variable_types: struct block { unsigned int data[512]; }


original_code:
void write_inode(uint inode, struct inode *inode_buf) {
    int block_index = (inode - 1) / (sizeof(struct super_block)/sizeof(struct inode)) + 2;
    int inode_offset = (inode -1) % (sizeof(struct super_block)/sizeof(struct inode));
    int byte_offset = inode_offset * sizeof(struct inode);
    struct block curr_block;
    read_block(block_index, &curr_block, sizeof(struct super_block));
    memcpy((void *)&curr_block + byte_offset, (void *)inode_buf, sizeof(struct inode));
    write_block(block_index, &curr_block, sizeof(struct super_block));
}

canonical_original_code:
void write_inode(unsigned int inode, struct inode *inode_buf) {
    int block_index = (inode - 1) / (sizeof(struct super_block)/sizeof(struct inode)) + 2;
    int inode_offset = (inode -1) % (sizeof(struct super_block)/sizeof(struct inode));
    int byte_offset = inode_offset * sizeof(struct inode);
    struct block curr_block;
    read_block(block_index, &curr_block, sizeof(struct super_block));
    memcpy((void *)&curr_block + byte_offset, (void *)inode_buf, sizeof(struct inode));
    write_block(block_index, &curr_block, sizeof(struct super_block));
}

user_defined_types: struct block { unsigned int data[512]; }

user_defined_types: struct inode { unsigned short flags; char nlinks; char uid; char gid; char padding[3]; unsigned int size; unsigned int pos; unsigned int addr[20]; long actime[2]; long modtime[2]; }


decompiled_code:
__int64 __fastcall free_inode(int a1)
{
int v1; // eax

v1 = curr_superblock[3];
if ( v1 == 251 )
return 0xFFFFFFFFLL;
curr_superblock[3] = v1 + 1;
curr_superblock[v1 + 255] = a1;
write_superblock();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax

v1 = curr_superblock[3];
if ( v1 == 251 )
return 0xFFFFFFFFLL;
curr_superblock[3] = v1 + 1;
curr_superblock[v1 + 255] = a1;
write_superblock();
return 0LL;
}

original_code:
int free_inode(uint free_inode) {
    if(curr_superblock.ninode == 251)
        return -1;
    curr_superblock.inode[curr_superblock.ninode] = free_inode;
    curr_superblock.ninode++;
    write_superblock();
    return 0;
}

canonical_original_code:
int free_inode(unsigned int free_inode) {
    if(curr_superblock.ninode == 251)
        return -1;
    curr_superblock.inode[curr_superblock.ninode] = free_inode;
    curr_superblock.ninode++;
    write_superblock();
    return 0;
}


decompiled_code:
__int64 get_free_inode()
{
int v0; // eax
unsigned int v1; // er12
__int64 v2; // rax

v0 = curr_superblock[3];
v1 = -1;
if ( v0 )
{
v2 = (unsigned int)(v0 - 1);
curr_superblock[3] = v2;
v1 = curr_superblock[v2 + 255];
write_superblock();
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
unsigned int v1; // er12
__int64 v2; // rax

v0 = curr_superblock[3];
v1 = -1;
if ( v0 )
{
v2 = (unsigned int)(v0 - 1);
curr_superblock[3] = v2;
v1 = curr_superblock[v2 + 255];
write_superblock();
}
return v1;
}

original_code:
uint get_free_inode() {
    if(curr_superblock.ninode == 0)
        return -1;
    curr_superblock.ninode--;
    uint inode_id = curr_superblock.inode[curr_superblock.ninode];
    write_superblock();
    return inode_id;
}

canonical_original_code:
unsigned int get_free_inode() {
    if(curr_superblock.ninode == 0)
        return -1;
    curr_superblock.ninode--;
    unsigned int inode_id = curr_superblock.inode[curr_superblock.ninode];
    write_superblock();
    return inode_id;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+Ch] [rbp-ACh] BYREF
const char *v5[6]; // [rsp+10h] [rbp-A8h] BYREF
char s[120]; // [rsp+40h] [rbp-78h] BYREF

while ( 1 )
{
fwrite(&unk_68, 1uLL, 3uLL, stdout);
fgets(s, 100, stdin);
s[(int)(strlen(s) - 1)] = 0;
if ( s[0] == 113 && !s[1] )
break;
tokenize(s, (__int64)v5, (int *)&v4);
if ( v5[0] )
{
if ( !strcmp(v5[0], "cpin") )
{
cpin(v4, v5);
}
else if ( !strcmp(v5[0], "initfs") )
{
initfs(v4, v5);
}
else if ( !strcmp(v5[0], "cpout") )
{
cpout(v4, v5);
}
else if ( !strcmp(v5[0], "mkdir") )
{
mkdir1(v4, v5);
}
else if ( *v5[0] == 108 && v5[0][1] == 115 && !v5[0][2] )
{
ls(v4, v5);
}
else
{
puts("Error: unsupported operations!\nThis File System only support cpin, cpout, makdir and ls");
}
}
}
close(curr_fd);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+Ch] [rbp-ACh] BYREF
const char *v5[6]; // [rsp+10h] [rbp-A8h] BYREF
char s[120]; // [rsp+40h] [rbp-78h] BYREF

while ( 1 )
{
fwrite(&unk_68, 1uLL, 3uLL, stdout);
fgets(s, 100, stdin);
s[(int)(strlen(s) - 1)] = 0;
if ( s[0] == 113 && !s[1] )
break;
func0(s, (__int64)v5, (int *)&v4);
if ( v5[0] )
{
if ( !strcmp(v5[0], "cpin") )
{
cpin(v4, v5);
}
else if ( !strcmp(v5[0], "initfs") )
{
initfs(v4, v5);
}
else if ( !strcmp(v5[0], "cpout") )
{
cpout(v4, v5);
}
else if ( !strcmp(v5[0], "mkdir") )
{
mkdir1(v4, v5);
}
else if ( *v5[0] == 108 && v5[0][1] == 115 && !v5[0][2] )
{
ls(v4, v5);
}
else
{
puts("Error: unsupported operations!\nThis File System only support cpin, cpout, makdir and ls");
}
}
}
close(curr_fd);
return 0;
}

original_code:
int main() {
    while(1) {
        char string[100];
        fputs(">>>", stdout);
        fgets(string, 100, stdin);
        int length = strlen(string) - 1;
        string[length] = '\0';
        if(strcmp(string, "q") == 0){
           break;
        }
        char* argv[5];
        int argc;
        tokenize(string, argv, &argc);
        if(argv[0] != '\0') {
            if(strcmp(argv[0], "cpin") == 0)
                cpin(argc, argv);
            else if(strcmp(argv[0], "initfs") == 0)
                initfs(argc,argv);
            else if(strcmp(argv[0], "cpout") == 0)
                cpout(argc,argv);
            else if(strcmp(argv[0], "mkdir") == 0)
                mkdir1(argc,argv);
            else if(strcmp(argv[0], "ls") == 0)
                ls(argc,argv);
            else {
                printf("Error: unsupported operations!\nThis File System only support cpin, cpout, makdir and ls\n");
            }
        }
     }
     close(curr_fd);
     return 0;
}

canonical_original_code:
int main() {
    while(1) {
        char string[100];
        fputs(">>>", stdout);
        fgets(string, 100, stdin);
        int length = strlen(string) - 1;
        string[length] = '\0';
        if(strcmp(string, "q") == 0){
           break;
        }
        char *argv[5];
        int argc;
        tokenize(string, argv, &argc);
        if(argv[0] != '\0') {
            if(strcmp(argv[0], "cpin") == 0)
                cpin(argc, argv);
            else if(strcmp(argv[0], "initfs") == 0)
                initfs(argc,argv);
            else if(strcmp(argv[0], "cpout") == 0)
                cpout(argc,argv);
            else if(strcmp(argv[0], "mkdir") == 0)
                mkdir1(argc,argv);
            else if(strcmp(argv[0], "ls") == 0)
                ls(argc,argv);
            else {
                printf("Error: unsupported operations!\nThis File System only support cpin, cpout, makdir and ls\n");
            }
        }
     }
     close(curr_fd);
     return 0;
}

variable_types:
string
char [100]

variable_types: length int

variable_types:
argv
char *[5]

variable_types: argc int


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

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

original_code:
int add_file_entry_to_directory(struct V6_file *file, struct inode *dir_inode) {
 return 0;
}

variable_types: struct V6_file { unsigned int inumber; unsigned char filename[-1]; } *


original_code:
int add_entry_to_inode(struct V6_file *entry, struct inode *dir_inode) {
 int full_blocks = dir_inode->size / sizeof(struct super_block);
 if(full_blocks > 20)
  return -1;
 uint block_index = dir_inode->addr[full_blocks];
 if(block_index == 0) {
  block_index = allocate_block();
  dir_inode->addr[full_blocks] = block_index;
 }
 struct block last_block;
 read_block(block_index, &last_block, sizeof(struct super_block));
 int extra_entry = (dir_inode->size % sizeof(struct super_block)) / (sizeof(struct V6_file));
 if(extra_entry == (sizeof(struct super_block) / (sizeof(struct V6_file))))
  return -1;
 dir_inode->size += (sizeof(struct V6_file));
 memcpy((void *)&last_block + extra_entry * (sizeof(struct V6_file)), entry, (sizeof(struct V6_file)));
 write_block(block_index, &last_block, sizeof(struct super_block));
 return 0;
}

canonical_original_code:
int add_entry_to_inode(struct V6_file *entry, struct inode *dir_inode) {
 int full_blocks = dir_inode->size / sizeof(struct super_block);
 if(full_blocks > 20)
  return -1;
 unsigned int block_index = dir_inode->addr[full_blocks];
 if(block_index == 0) {
  block_index = allocate_block();
  dir_inode->addr[full_blocks] = block_index;
 }
 struct block last_block;
 read_block(block_index, &last_block, sizeof(struct super_block));
 int extra_entry = (dir_inode->size % sizeof(struct super_block)) / (sizeof(struct V6_file));
 if(extra_entry == (sizeof(struct super_block) / (sizeof(struct V6_file))))
  return -1;
 dir_inode->size += (sizeof(struct V6_file));
 memcpy((void *)&last_block + extra_entry * (sizeof(struct V6_file)), entry, (sizeof(struct V6_file)));
 write_block(block_index, &last_block, sizeof(struct super_block));
 return 0;
}

user_defined_types: struct V6_file { unsigned int inumber; unsigned char filename[-1]; }


original_code:
int make_root_directory(struct V6_file *_root) {
 struct inode root_inode;
 read_inode(1, &root_inode);
 allocate_inode(&root_inode);
 _root->inumber = 1;
 strncpy((char *)_root->filename, (const char *)"/", 1);
 struct V6_file dot;
 struct V6_file dotdot;
 dot.inumber = 1;
 dotdot.inumber = 1;
 strncpy((char *)dot.filename, ".", (32 - sizeof(uint)));
 strncpy((char *)dotdot.filename, "..", (32 - sizeof(uint)));
 add_entry_to_inode(&dot, &root_inode);
 add_entry_to_inode(&dotdot, &root_inode);
 write_inode(1, &root_inode);
 memcpy(&root, _root, sizeof(struct V6_file));
 return 0;
}

canonical_original_code:
int make_root_directory(struct V6_file *_root) {
 struct inode root_inode;
 read_inode(1, &root_inode);
 allocate_inode(&root_inode);
 _root->inumber = 1;
 strncpy((char *)_root->filename, (char *)"/", 1);
 struct V6_file dot;
 struct V6_file dotdot;
 dot.inumber = 1;
 dotdot.inumber = 1;
 strncpy((char *)dot.filename, ".", (32 - sizeof(uint)));
 strncpy((char *)dotdot.filename, "..", (32 - sizeof(uint)));
 add_entry_to_inode(&dot, &root_inode);
 add_entry_to_inode(&dotdot, &root_inode);
 write_inode(1, &root_inode);
 memcpy(&root, _root, sizeof(struct V6_file));
 return 0;
}

variable_types: struct V6_file { unsigned int inumber; unsigned char filename[-1]; }


original_code:
int add_directory_to_directory(struct V6_file *dir_entry, struct V6_file *parent_dir_entry) {
 struct V6_file itself;
 memset(&itself, 0, (sizeof(struct V6_file)));
 itself.inumber = dir_entry->inumber;
 strncpy((char *)itself.filename, ".", 2);
 struct V6_file parent;
 memset(&parent, 0, (sizeof(struct V6_file)));
 memcpy(&parent, parent_dir_entry, (sizeof(struct V6_file)));
 strncpy((char *)parent.filename, "..", 3);
 struct inode itself_dir_inode;
 struct inode parent_dir_inode;
 read_inode(dir_entry->inumber, &itself_dir_inode);
 read_inode(parent_dir_entry->inumber, &parent_dir_inode);
 add_entry_to_inode(&itself, &itself_dir_inode);
 add_entry_to_inode(&parent, &itself_dir_inode);
 write_inode(dir_entry->inumber, &itself_dir_inode);
 int ret = add_directory_to_inode(dir_entry, &parent_dir_inode);
 write_inode(parent_dir_entry->inumber, &parent_dir_inode);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall make_directory_in_directory(char *src)
{
unsigned int v1; // er12
unsigned int v3; // [rsp+0h] [rbp-B8h] BYREF
char dest[28]; // [rsp+4h] [rbp-B4h] BYREF
char v5[152]; // [rsp+20h] [rbp-98h] BYREF

v1 = get_free_inode();
read_inode(v1, v5);
allocate_inode(v5);
write_inode(v1, v5);
strncpy(dest, src, 0x1CuLL);
v3 = v1;
add_directory_to_directory(&v3, (const __m128i *)&root);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src)
{
unsigned int v1; // er12
unsigned int v3; // [rsp+0h] [rbp-B8h] BYREF
char dest[28]; // [rsp+4h] [rbp-B4h] BYREF
char v5[152]; // [rsp+20h] [rbp-98h] BYREF

v1 = get_free_inode();
read_inode(v1, v5);
allocate_inode(v5);
write_inode(v1, v5);
strncpy(dest, src, 0x1CuLL);
v3 = v1;
func3(&v3, (const __m128i *)&root);
return v1;
}

original_code:
uint make_directory_in_directory(char *filename, struct V6_file *spec_dir) {
 struct inode dir_inode;
 struct V6_file new_entry;
 uint inode = get_free_inode();
 read_inode(inode, &dir_inode);
 allocate_inode(&dir_inode);
 write_inode(inode, &dir_inode);
 strncpy((char *)new_entry.filename, (const char *)filename, (32 - sizeof(uint)));
 new_entry.inumber = inode;
 add_directory_to_directory(&new_entry, &root);
 return inode;
}

canonical_original_code:
unsigned int make_directory_in_directory(char *filename, struct V6_file *spec_dir) {
 struct inode dir_inode;
 struct V6_file new_entry;
 unsigned int inode = get_free_inode();
 read_inode(inode, &dir_inode);
 allocate_inode(&dir_inode);
 write_inode(inode, &dir_inode);
 strncpy((char *)new_entry.filename, (char *)filename, (32 - sizeof(uint)));
 new_entry.inumber = inode;
 add_directory_to_directory(&new_entry, &root);
 return inode;
}

variable_types:
filename
char *


original_code:
int read_file_by_inode(struct inode *file_inode, void *buf) {
    struct inode_data data;
 read_inode_data(file_inode, &data);
 int i;
 int num_full_block = file_inode->size / sizeof(struct super_block);
 struct block tmp_block;
 for(i = 0; i < num_full_block; i++) {
  read_block(data.addr[i], &tmp_block, sizeof(struct super_block));
  memcpy(buf + sizeof(struct super_block) * i, &tmp_block, sizeof(struct super_block));
 }
 int extra_byte_in_block = file_inode->size - num_full_block * sizeof(struct super_block);
 read_block(data.addr[num_full_block], &tmp_block, sizeof(struct super_block));
 memcpy(buf + sizeof(struct super_block) * num_full_block, tmp_block.data, (int)extra_byte_in_block);
 return file_inode->size;
}

variable_types:
buf
void *

variable_types: struct inode_data { unsigned int addr[20]; }


original_code:
int ensure_enough_blocks(struct inode * file_inode, size_t total_size) {
 int num_full_blocks = total_size / sizeof(struct super_block);
 if((total_size - num_full_blocks * sizeof(struct super_block)) > 0)
  num_full_blocks++;
 int already_allocated_blocks = file_inode->size / sizeof(struct super_block);
 if((file_inode->size - already_allocated_blocks * sizeof(struct super_block)) > 0)
  already_allocated_blocks++;
 int i;
 for(i = already_allocated_blocks; i < num_full_blocks; i++) {
  file_inode->addr[i] = allocate_block();
 }
 return 0;
}

canonical_original_code:
int ensure_enough_blocks(struct inode *file_inode, unsigned long total_size) {
 int num_full_blocks = total_size / sizeof(struct super_block);
 if((total_size - num_full_blocks * sizeof(struct super_block)) > 0)
  num_full_blocks++;
 int already_allocated_blocks = file_inode->size / sizeof(struct super_block);
 if((file_inode->size - already_allocated_blocks * sizeof(struct super_block)) > 0)
  already_allocated_blocks++;
 int i;
 for(i = already_allocated_blocks; i < num_full_blocks; i++) {
  file_inode->addr[i] = allocate_block();
 }
 return 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall write_file_by_inode(__int64 a1, char *a2, unsigned __int64 a3)
{
char *v4; // rbp
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rbx
int v8; // er14
__int64 v9; // rax
char *v10; // rdx
char *v11; // rbx
unsigned int *v12; // rbp
__int64 v13; // r12
__int64 v14; // rdi
int v17; // [rsp+8h] [rbp-890h]
char v18[80]; // [rsp+10h] [rbp-888h] BYREF
char dest[2104]; // [rsp+60h] [rbp-838h] BYREF

v4 = a2;
v17 = a3;
read_inode_data(a1, v18);
v6 = a3 + *(unsigned int *)(a1 + 8);
v7 = a3 >> 11;
ensure_enough_blocks(a1, v6);
memset(dest, 0, 0x800uLL);
v8 = v7;
if ( (int)v7 > 0 )
{
v9 = (unsigned int)(v7 - 1);
v10 = v4;
v11 = v4;
v12 = (unsigned int *)(a1 + 16);
v13 = (__int64)&v10[2048 * v9 + 2048];
do
{
qmemcpy(dest, v11, 0x800uLL);
v14 = *v12;
v11 += 2048;
++v12;
write_block(v14, dest, 2048LL);
}
while ( v11 != (char *)v13 );
}
memcpy(dest, &a2[2048 * (__int64)v8], v17 - (v8 << 11));
write_block(*(unsigned int *)(a1 + 4LL * v8 + 16), dest, 2048LL);
return 0LL;
}

original_code:
int write_file_by_inode(struct inode *file_inode, void *buf, size_t count) {
 struct inode_data data;
 read_inode_data(file_inode, &data);
 ensure_enough_blocks(file_inode, file_inode->size + count);
 int num_full_blocks = count / sizeof(struct super_block);
 struct block tmp_block;
 memset(&tmp_block, 0, sizeof(struct super_block));
 int i;
 for(i = 0; i < num_full_blocks; i++) {
  memcpy(&tmp_block, buf + sizeof(struct super_block) * i, sizeof(struct super_block));
  write_block(file_inode->addr[i], &tmp_block, sizeof(struct super_block));
 }
 int extra_byte_in_block = count - num_full_blocks * sizeof(struct super_block);
 memcpy(tmp_block.data, buf + sizeof(struct super_block) * num_full_blocks, (int)extra_byte_in_block);
 write_block(file_inode->addr[num_full_blocks], &tmp_block, sizeof(struct super_block));
 return 0;
}

canonical_original_code:
int write_file_by_inode(struct inode *file_inode, void *buf, unsigned long count) {
 struct inode_data data;
 read_inode_data(file_inode, &data);
 ensure_enough_blocks(file_inode, file_inode->size + count);
 int num_full_blocks = count / sizeof(struct super_block);
 struct block tmp_block;
 memset(&tmp_block, 0, sizeof(struct super_block));
 int i;
 for(i = 0; i < num_full_blocks; i++) {
  memcpy(&tmp_block, buf + sizeof(struct super_block) * i, sizeof(struct super_block));
  write_block(file_inode->addr[i], &tmp_block, sizeof(struct super_block));
 }
 int extra_byte_in_block = count - num_full_blocks * sizeof(struct super_block);
 memcpy(tmp_block.data, buf + sizeof(struct super_block) * num_full_blocks, (int)extra_byte_in_block);
 write_block(file_inode->addr[num_full_blocks], &tmp_block, sizeof(struct super_block));
 return 0;
}

variable_types:
count
unsigned long

user_defined_types: struct inode_data { unsigned int addr[20]; }


decompiled_code:
__int64 __fastcall get_file_size(__int64 a1)
{
__int64 result; // rax
_DWORD v2[34]; // [rsp+0h] [rbp-88h] BYREF

if ( (int)filename_to_inode(a1, &root, v2) < 0 )
result = 0xFFFFFFFFLL;
else
result = v2[2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
_DWORD v2[34]; // [rsp+0h] [rbp-88h] BYREF

if ( (int)filename_to_inode(a1, &root, v2) < 0 )
result = 0xFFFFFFFFLL;
else
result = v2[2];
return result;
}

original_code:
int get_file_size(char *filename) {
 struct inode file_inode;
 int inode = filename_to_inode(filename, &root, &file_inode);
 if(inode < 0)
  return -1;
 else
  return file_inode.size;
}

variable_types: struct inode { unsigned short flags; char nlinks; char uid; char gid; char padding[3]; unsigned int size; unsigned int pos; unsigned int addr[20]; long actime[2]; long modtime[2]; }

variable_types: inode int


decompiled_code:
__int64 __fastcall read_file(__int64 a1, __int64 a2)
{
int v2; // er8
__int64 result; // rax
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = filename_to_inode(a1, &root, v4);
result = -1LL;
if ( v2 >= 0 )
result = (int)read_file_by_inode((__int64)v4, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // er8
__int64 result; // rax
_BYTE v4[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = filename_to_inode(a1, &root, v4);
result = -1LL;
if ( v2 >= 0 )
result = (int)func5((__int64)v4, a2);
return result;
}

original_code:
size_t read_file(char *filename, void *buf, size_t count) {
 struct inode file_inode;
 int inode = filename_to_inode(filename, &root, &file_inode);
 if(inode < 0)
  return -1;
 return read_file_by_inode(&file_inode, buf);
}

canonical_original_code:
unsigned long read_file(char *filename, void *buf, unsigned long count) {
 struct inode file_inode;
 int inode = filename_to_inode(filename, &root, &file_inode);
 if(inode < 0)
  return -1;
 return read_file_by_inode(&file_inode, buf);
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall write_file(char *src, char *a2, unsigned __int64 a3)
{
unsigned __int32 v4; // ebx
__m128i v6[2]; // [rsp+0h] [rbp-148h] BYREF
int v7[32]; // [rsp+20h] [rbp-128h] BYREF
char v8[168]; // [rsp+A0h] [rbp-A8h] BYREF

memset(v7, 0, sizeof(v7));
v4 = get_free_inode();
read_inode(v4, v7);
allocate_inode(v7);
v7[2] = a3;
write_inode(v4, v7);
read_inode((unsigned int)root, v8);
v6[0].m128i_i32[0] = v4;
strncpy(&v6[0].m128i_i8[4], src, 0x1CuLL);
add_entry_to_inode(v6, (__int64)v8);
write_inode((unsigned int)root, v8);
return (int)write_file_by_inode((__int64)v7, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *src, char *a2, unsigned __int64 a3)
{
unsigned __int32 v4; // ebx
__m128i v6[2]; // [rsp+0h] [rbp-148h] BYREF
int v7[32]; // [rsp+20h] [rbp-128h] BYREF
char v8[168]; // [rsp+A0h] [rbp-A8h] BYREF

memset(v7, 0, sizeof(v7));
v4 = get_free_inode();
read_inode(v4, v7);
allocate_inode(v7);
v7[2] = a3;
write_inode(v4, v7);
read_inode((unsigned int)root, v8);
v6[0].m128i_i32[0] = v4;
strncpy(&v6[0].m128i_i8[4], src, 0x1CuLL);
func1(v6, (__int64)v8);
write_inode((unsigned int)root, v8);
return (int)func7((__int64)v7, a2, a3);
}

original_code:
size_t write_file(char *filename, void *buf, size_t count) {
 struct V6_file V6_file;
 struct inode file_inode;
 memset(&file_inode, 0, sizeof(struct inode));
 int inode = get_free_inode();
 read_inode(inode, &file_inode);
 allocate_inode(&file_inode);
 file_inode.size = count;
 write_inode(inode, &file_inode);
 struct inode dir_inode;
 read_inode(root.inumber, &dir_inode);
 V6_file.inumber = inode;
 strncpy((char *)V6_file.filename, (const char *)filename, (32 - sizeof(uint)));
 add_entry_to_inode(&V6_file, &dir_inode);
 write_inode(root.inumber, &dir_inode);
 return write_file_by_inode(&file_inode, buf, count);
}

canonical_original_code:
unsigned long write_file(char *filename, void *buf, unsigned long count) {
 struct V6_file V6_file;
 struct inode file_inode;
 memset(&file_inode, 0, sizeof(struct inode));
 int inode = get_free_inode();
 read_inode(inode, &file_inode);
 allocate_inode(&file_inode);
 file_inode.size = count;
 write_inode(inode, &file_inode);
 struct inode dir_inode;
 read_inode(root.inumber, &dir_inode);
 V6_file.inumber = inode;
 strncpy((char *)V6_file.filename, (char *)filename, (32 - sizeof(uint)));
 add_entry_to_inode(&V6_file, &dir_inode);
 write_inode(root.inumber, &dir_inode);
 return write_file_by_inode(&file_inode, buf, count);
}


decompiled_code:
_BOOL8 __fastcall is_this_file(__int64 a1, const char *a2)
{
return strcmp((const char *)(a1 + 4), a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, const char *a2)
{
return strcmp((const char *)(a1 + 4), a2) == 0;
}

original_code:
int is_this_file(struct V6_file *entry, const char* filename) {
 if(strcmp((const char *)entry->filename, filename) == 0)
  return 1;
 else
  return 0;
}

canonical_original_code:
int is_this_file(struct V6_file *entry, char *filename) {
 if(strcmp((char *)entry->filename, filename) == 0)
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall read_directory(__int64 a1, _QWORD *a2, _DWORD *a3)
{
__int64 v4; // rdi
void *v5; // rax

v4 = *(_DWORD *)(a1 + 8) >> 5;
*a3 = v4;
v5 = malloc(32 * v4);
*a2 = v5;
return read_file_by_inode(a1, (__int64)v5);
}

original_code:
int read_directory(struct inode *dir_inode, struct V6_file **entries, int *entry_num) {
 *entry_num = dir_inode->size / (sizeof(struct V6_file));
 *entries = malloc((*entry_num) * (sizeof(struct V6_file)));
 return read_file_by_inode(dir_inode, (void *)*entries);
}

variable_types: struct V6_file { unsigned int inumber; unsigned char filename[-1]; } **


decompiled_code:
__int64 __fastcall find_file_in_directory(const char *a1, unsigned int *a2)
{
unsigned int *v2; // rbx
__int64 v3; // r12
int v5; // [rsp+4h] [rbp-A4h] BYREF
unsigned int *v6; // [rsp+8h] [rbp-A0h] BYREF
char v7[152]; // [rsp+10h] [rbp-98h] BYREF

read_inode(*a2, v7);
v5 = 0;
read_directory((__int64)v7, &v6, &v5);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
v2 = v6;
v3 = (__int64)&v6[8 * (v5 - 1) + 8];
while ( !is_this_file((__int64)v2, a1) )
{
v2 += 8;
if ( v2 == (unsigned int *)v3 )
return 0xFFFFFFFFLL;
}
return *v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, unsigned int *a2)
{
unsigned int *v2; // rbx
__int64 v3; // r12
int v5; // [rsp+4h] [rbp-A4h] BYREF
unsigned int *v6; // [rsp+8h] [rbp-A0h] BYREF
char v7[152]; // [rsp+10h] [rbp-98h] BYREF

read_inode(*a2, v7);
v5 = 0;
func12((__int64)v7, &v6, &v5);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
v2 = v6;
v3 = (__int64)&v6[8 * (v5 - 1) + 8];
while ( !func11((__int64)v2, a1) )
{
v2 += 8;
if ( v2 == (unsigned int *)v3 )
return 0xFFFFFFFFLL;
}
return *v2;
}

original_code:
int find_file_in_directory(const char *filename, struct V6_file *spec_dir) {
 struct inode curr_inode;
 read_inode(spec_dir->inumber, &curr_inode);
 if((curr_inode.flags | 0100000) == 0) {
  do { fprintf(stderr, "Internal error: an existing file contains unallocated inode\n"); exit(-1); }while(0);
 }
 if((curr_inode.flags | 040000) == 0) {
  do { fprintf(stderr, "Internal error: the current file is NOT directory\n"); exit(-1); }while(0);
 }
 struct V6_file *entries;
 int entry_num = 0;
 read_directory(&curr_inode, &entries, &entry_num);
 int i = 0;
 for(i = 0; i < entry_num; i++) {
  if(is_this_file(&entries[i], filename)) {
   int ret = entries[i].inumber;
   return ret;
  }
 }
 return -1;
}

canonical_original_code:
int find_file_in_directory(char *filename, struct V6_file *spec_dir) {
 struct inode curr_inode;
 read_inode(spec_dir->inumber, &curr_inode);
 if((curr_inode.flags | 0100000) == 0) {
  do { fprintf(stderr, "Internal error: an existing file contains unallocated inode\n"); exit(-1); }while(0);
 }
 if((curr_inode.flags | 040000) == 0) {
  do { fprintf(stderr, "Internal error: the current file is NOT directory\n"); exit(-1); }while(0);
 }
 struct V6_file *entries;
 int entry_num = 0;
 read_directory(&curr_inode, &entries, &entry_num);
 int i = 0;
 for(i = 0; i < entry_num; i++) {
  if(is_this_file(&entries[i], filename)) {
   int ret = entries[i].inumber;
   return ret;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall find_directory_in_directory(const char *a1, unsigned int *a2)
{
__int64 v2; // r12

v2 = (unsigned int)find_file_in_directory(a1, a2);
if ( !(unsigned int)is_directory(v2) )
LODWORD(v2) = -1;
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1, unsigned int *a2)
{
__int64 v2; // r12

v2 = (unsigned int)func13(a1, a2);
if ( !(unsigned int)is_directory(v2) )
LODWORD(v2) = -1;
return (unsigned int)v2;
}

original_code:
int find_directory_in_directory(const char *filename, struct V6_file *spec_dir) {
 uint inode = find_file_in_directory(filename, spec_dir);
 if(inode < 0)
  return -1;
 if(is_directory(inode) == 0)
  return -1;
 return inode;
}

canonical_original_code:
int find_directory_in_directory(char *filename, struct V6_file *spec_dir) {
 unsigned int inode = find_file_in_directory(filename, spec_dir);
 if(inode < 0)
  return -1;
 if(is_directory(inode) == 0)
  return -1;
 return inode;
}

variable_types:
inode
unsigned int


decompiled_code:
__int64 __fastcall find_file_in_current_directory(const char *a1)
{
return find_file_in_directory(a1, (unsigned int *)&root);
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1)
{
return func13(a1, (unsigned int *)&root);
}

original_code:
uint find_file_in_current_directory(const char *filename) {
 return find_file_in_directory(filename, &root);
}

canonical_original_code:
unsigned int find_file_in_current_directory(char *filename) {
 return find_file_in_directory(filename, &root);
}


decompiled_code:
__int64 __fastcall list_directory(_QWORD *a1)
{
int v1; // er12
_QWORD *v2; // rax
void *v3; // r13
_QWORD *v4; // rbp
const char *v5; // rbx
const char *v6; // r12
char *v7; // rax
const char *v8; // rsi
unsigned int v10; // [rsp+4h] [rbp-B4h] BYREF
void *ptr; // [rsp+8h] [rbp-B0h] BYREF
char v12[168]; // [rsp+10h] [rbp-A8h] BYREF

v10 = 0;
read_inode((unsigned int)root, v12);
read_directory((__int64)v12, &ptr, &v10);
v1 = v10;
v2 = malloc(28LL * (int)v10);
*a1 = v2;
if ( v1 <= 0 )
{
v3 = ptr;
}
else
{
v3 = ptr;
v4 = v2;
v5 = (char *)ptr + 4;
v6 = (char *)ptr + 32 * (unsigned int)(v1 - 1) + 36;
do
{
++v4;
v7 = (char *)malloc(0x1CuLL);
v8 = v5;
v5 += 32;
*(v4 - 1) = v7;
strncpy(v7, v8, 0x1CuLL);
}
while ( v5 != v6 );
}
free(v3);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1)
{
int v1; // er12
_QWORD *v2; // rax
void *v3; // r13
_QWORD *v4; // rbp
const char *v5; // rbx
const char *v6; // r12
char *v7; // rax
const char *v8; // rsi
unsigned int v10; // [rsp+4h] [rbp-B4h] BYREF
void *ptr; // [rsp+8h] [rbp-B0h] BYREF
char v12[168]; // [rsp+10h] [rbp-A8h] BYREF

v10 = 0;
read_inode((unsigned int)root, v12);
func12((__int64)v12, &ptr, &v10);
v1 = v10;
v2 = malloc(28LL * (int)v10);
*a1 = v2;
if ( v1 <= 0 )
{
v3 = ptr;
}
else
{
v3 = ptr;
v4 = v2;
v5 = (char *)ptr + 4;
v6 = (char *)ptr + 32 * (unsigned int)(v1 - 1) + 36;
do
{
++v4;
v7 = (char *)malloc(0x1CuLL);
v8 = v5;
v5 += 32;
*(v4 - 1) = v7;
strncpy(v7, v8, 0x1CuLL);
}
while ( v5 != v6 );
}
free(v3);
return v10;
}

original_code:
int list_directory(char ***all_filename, struct V6_file *spec_dir) {
 struct V6_file *entries;
 int entry_num = 0;
 uint inode = root.inumber;
 struct inode dir_inode;
 read_inode(inode, &dir_inode);
 read_directory(&dir_inode, &entries, &entry_num);
 *all_filename = malloc((32 - sizeof(uint)) * entry_num);
 int i = 0;
 for(i = 0; i < entry_num; i++) {
  (*all_filename)[i] = malloc((32 - sizeof(uint)));
  strncpy((*all_filename)[i], (const char *)entries[i].filename, (32 - sizeof(uint)));
 }
 free(entries);
 return entry_num;
}

canonical_original_code:
int list_directory(char ***all_filename, struct V6_file *spec_dir) {
 struct V6_file *entries;
 int entry_num = 0;
 unsigned int inode = root.inumber;
 struct inode dir_inode;
 read_inode(inode, &dir_inode);
 read_directory(&dir_inode, &entries, &entry_num);
 *all_filename = malloc((32 - sizeof(uint)) * entry_num);
 int i = 0;
 for(i = 0; i < entry_num; i++) {
  (*all_filename)[i] = malloc((32 - sizeof(uint)));
  strncpy((*all_filename)[i], (char *)entries[i].filename, (32 - sizeof(uint)));
 }
 free(entries);
 return entry_num;
}


initfs

decompiled_code:
__int64 __fastcall initfs(int a1, const char **a2)
{
int v2; // ebp
unsigned int v3; // er12
unsigned int v4; // er13
__int64 result; // rax

if ( a1 <= 3 )
{
puts(
"Usage: initfs file_name(representing disk) n1(total number of blocks) n2(total number of blocks containing inodes)");
result = 0xFFFFFFFFLL;
}
else
{
curr_fd = open(a2[1], 66, 384LL);
v2 = curr_fd;
if ( curr_fd == -1 )
{
perror("Disk cannot be allocated");
exit(-1);
}
v3 = atoi(a2[2]);
v4 = atoi(a2[3]);
lseek(v2, (int)(v3 << 11), 0);
write(curr_fd, " ", 1uLL);
initiate_super_block((unsigned int)curr_fd, v3, v4);
make_root_directory(&root2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char **a2)
{
int v2; // ebp
unsigned int v3; // er12
unsigned int v4; // er13
__int64 result; // rax

if ( a1 <= 3 )
{
puts(
"Usage: initfs file_name(representing disk) n1(total number of blocks) n2(total number of blocks containing inodes)");
result = 0xFFFFFFFFLL;
}
else
{
curr_fd = open(a2[1], 66, 384LL);
v2 = curr_fd;
if ( curr_fd == -1 )
{
perror("Disk cannot be allocated");
exit(-1);
}
v3 = atoi(a2[2]);
v4 = atoi(a2[3]);
lseek(v2, (int)(v3 << 11), 0);
write(curr_fd, " ", 1uLL);
initiate_super_block((unsigned int)curr_fd, v3, v4);
make_root_directory(&root2);
result = 0LL;
}
return result;
}

original_code:
int initfs(int argc, char** argv) {
    if(argc < 4) {
         printf("Usage: initfs file_name(representing disk) n1(total number of blocks) n2(total number of blocks containing inodes)\n");
         return -1;
    }
    curr_fd = open(argv[1], 0100 | 02, 0600);
    if (curr_fd == -1) {
        perror("Disk cannot be allocated");
        exit(-1);
    }
    int n1 = atoi(argv[2]);
    int n2 = atoi(argv[3]);
    lseek(curr_fd, n1 * 2048, 0);
    write(curr_fd," ",1);
    initiate_super_block(curr_fd, n1, n2);
    make_root_directory(&root2);
    return 0;
}

canonical_original_code:
int initfs(int argc, char **argv) {
    if(argc < 4) {
         printf("Usage: initfs file_name(representing disk) n1(total number of blocks) n2(total number of blocks containing inodes)\n");
         return -1;
    }
    curr_fd = open(argv[1], 0100 | 02, 0600);
    if (curr_fd == -1) {
        perror("Disk cannot be allocated");
        exit(-1);
    }
    int n1 = atoi(argv[2]);
    int n2 = atoi(argv[3]);
    lseek(curr_fd, n1 * 2048, 0);
    write(curr_fd," ",1);
    initiate_super_block(curr_fd, n1, n2);
    make_root_directory(&root2);
    return 0;
}

variable_types:
argv
char **


cpin

decompiled_code:
__int64 __fastcall cpin(int a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // r14
int v4; // er13
size_t v5; // r15
void *v6; // rax
void *v7; // rbp
int v8; // eax
struct stat v10; // [rsp+0h] [rbp-C8h] BYREF

if ( a1 == 3 )
{
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
v2 = find_file_in_directory(*(_QWORD *)(a2 + 16), &root2);
if ( v2 == -1 )
{
v3 = *(_QWORD *)(a2 + 16);
v4 = open(*(const char **)(a2 + 8), 0);
fstat(v4, &v10);
v5 = SLODWORD(v10.st_size);
v6 = malloc(SLODWORD(v10.st_size));
v7 = v6;
if ( v6 )
{
v2 = 0;
v8 = read(v4, v6, v5);
write_file(v3, v7, v8);
free(v7);
}
else
{
puts("ERROR: Out of memory");
}
}
else
{
v2 = -1;
printf(
"Filename %s exists! You are not allowed to override an existing file. Please change to another filename\n",
*(const char **)(a2 + 16));
}
}
else
{
v2 = 1;
puts("Usage: cpin external_file_name v6_file");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // r14
int v4; // er13
size_t v5; // r15
void *v6; // rax
void *v7; // rbp
int v8; // eax
struct stat v10; // [rsp+0h] [rbp-C8h] BYREF

if ( a1 == 3 )
{
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
v2 = find_file_in_directory(*(_QWORD *)(a2 + 16), &root2);
if ( v2 == -1 )
{
v3 = *(_QWORD *)(a2 + 16);
v4 = open(*(const char **)(a2 + 8), 0);
fstat(v4, &v10);
v5 = SLODWORD(v10.st_size);
v6 = malloc(SLODWORD(v10.st_size));
v7 = v6;
if ( v6 )
{
v2 = 0;
v8 = read(v4, v6, v5);
write_file(v3, v7, v8);
free(v7);
}
else
{
puts("ERROR: Out of memory");
}
}
else
{
v2 = -1;
printf(
"Filename %s exists! You are not allowed to override an existing file. Please change to another filename\n",
*(const char **)(a2 + 16));
}
}
else
{
v2 = 1;
puts("Usage: cpin external_file_name v6_file");
}
return v2;
}

original_code:
int cpin(int argc, char** argv) {
    int src_fd;
    char * src_path, *dst_path;
    if(argc != 3) {
         printf("Usage: cpin external_file_name v6_file\n");
         return 1;
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    uint curr_inode_number = find_file_in_directory(argv[2], &root2);
    if (curr_inode_number != -1) {
         printf("Filename %s exists! You are not allowed to override an existing file. Please change to another filename\n", argv[2]);
         return -1;
    }
    src_path = argv[1];
    dst_path = argv[2];
    struct stat statbuf;
    src_fd = open(src_path, 00);
    if (fstat(src_fd, &statbuf) == -1) {
    }
    int filelength = statbuf.st_size;
    char *buf;
    buf = malloc(filelength);
    if (buf == 0)
    {
        printf("ERROR: Out of memory\n");
        return -1;
    }
    int size = read(src_fd, buf, filelength);
    write_file(dst_path, buf, size);
    free(buf);
    return 0;
}

canonical_original_code:
int cpin(int argc, char **argv) {
    int src_fd;
    char *src_path; char *dst_path;
    if(argc != 3) {
         printf("Usage: cpin external_file_name v6_file\n");
         return 1;
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    unsigned int curr_inode_number = find_file_in_directory(argv[2], &root2);
    if (curr_inode_number != -1) {
         printf("Filename %s exists! You are not allowed to override an existing file. Please change to another filename\n", argv[2]);
         return -1;
    }
    src_path = argv[1];
    dst_path = argv[2];
    struct stat statbuf;
    src_fd = open(src_path, 00);
    if (fstat(src_fd, &statbuf) == -1) {
    }
    int filelength = statbuf.st_size;
    char *buf;
    buf = malloc(filelength);
    if (buf == 0)
    {
        printf("ERROR: Out of memory\n");
        return -1;
    }
    int size = read(src_fd, buf, filelength);
    write_file(dst_path, buf, size);
    free(buf);
    return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: filelength int

variable_types:
buf
char *

variable_types: size int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


cpout

decompiled_code:
__int64 __fastcall cpout(int a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // r15
int v4; // er14
size_t v5; // r13
void *v6; // rax
void *v7; // rbp

if ( a1 == 3 )
{
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
v2 = find_file_in_directory(*(_QWORD *)(a2 + 16), &root2);
if ( v2 == -1 )
{
v3 = *(_QWORD *)(a2 + 8);
v4 = open(*(const char **)(a2 + 16), 65, 384LL);
v5 = (int)get_file_size(v3);
v6 = malloc(v5);
v7 = v6;
if ( v6 )
{
v2 = 0;
read_file(v3, v6, v5);
write(v4, v7, v5);
free(v7);
}
else
{
puts("ERROR: Out of memory");
}
}
else
{
v2 = -1;
printf("filename %s doesn't exists! Please check your typing\n", *(const char **)(a2 + 16));
}
}
else
{
v2 = 1;
puts("Usage: cpin v6_file external_file_name");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v3; // r15
int v4; // er14
size_t v5; // r13
void *v6; // rax
void *v7; // rbp

if ( a1 == 3 )
{
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
v2 = find_file_in_directory(*(_QWORD *)(a2 + 16), &root2);
if ( v2 == -1 )
{
v3 = *(_QWORD *)(a2 + 8);
v4 = open(*(const char **)(a2 + 16), 65, 384LL);
v5 = (int)get_file_size(v3);
v6 = malloc(v5);
v7 = v6;
if ( v6 )
{
v2 = 0;
read_file(v3, v6, v5);
write(v4, v7, v5);
free(v7);
}
else
{
puts("ERROR: Out of memory");
}
}
else
{
v2 = -1;
printf("filename %s doesn't exists! Please check your typing\n", *(const char **)(a2 + 16));
}
}
else
{
v2 = 1;
puts("Usage: cpin v6_file external_file_name");
}
return v2;
}

original_code:
int cpout(int argc, char** argv) {
    int dst_fd;
    char* src_path, *dst_path;
    if(argc != 3) {
         printf("Usage: cpin v6_file external_file_name\n");
         return 1;
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    uint curr_inode_number = find_file_in_directory(argv[2], &root2);
    if (curr_inode_number != -1) {
        printf("filename %s doesn't exists! Please check your typing\n", argv[2]);
        return -1;
    }
    src_path = argv[1];
    dst_path = argv[2];
    dst_fd = open(dst_path, 0100 | 01, 0600);
    char *buf;
    int filelength = get_file_size(src_path);
    buf = malloc(filelength);
    if (buf == 0)
    {
        printf("ERROR: Out of memory\n");
        return -1;
    }
    read_file(src_path, buf, filelength);
    write(dst_fd, buf, filelength);
    free(buf);
    return 0;
    close(dst_fd);
    return 0;
}

canonical_original_code:
int cpout(int argc, char **argv) {
    int dst_fd;
    char *src_path; char *dst_path;
    if(argc != 3) {
         printf("Usage: cpin v6_file external_file_name\n");
         return 1;
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    unsigned int curr_inode_number = find_file_in_directory(argv[2], &root2);
    if (curr_inode_number != -1) {
        printf("filename %s doesn't exists! Please check your typing\n", argv[2]);
        return -1;
    }
    src_path = argv[1];
    dst_path = argv[2];
    dst_fd = open(dst_path, 0100 | 01, 0600);
    char *buf;
    int filelength = get_file_size(src_path);
    buf = malloc(filelength);
    if (buf == 0)
    {
        printf("ERROR: Out of memory\n");
        return -1;
    }
    read_file(src_path, buf, filelength);
    write(dst_fd, buf, filelength);
    free(buf);
    return 0;
    close(dst_fd);
    return 0;
}

variable_types: argc int


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

if ( a1 != 2 )
{
puts("Usage: mkdir V6-directory");
exit(-1);
}
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
if ( (unsigned int)find_directory_in_directory(*(_QWORD *)(a2 + 8), &root2) == -1 )
{
make_directory_in_directory(*(_QWORD *)(a2 + 8), &root2);
result = 0LL;
}
else
{
printf("Diretory %s exists! Can't override an existing file\n", *(const char **)(a2 + 8));
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 != 2 )
{
puts("Usage: mkdir V6-directory");
exit(-1);
}
if ( curr_fd == -1 )
{
perror("disk doesn't exist!\n");
exit(-1);
}
if ( (unsigned int)find_directory_in_directory(*(_QWORD *)(a2 + 8), &root2) == -1 )
{
make_directory_in_directory(*(_QWORD *)(a2 + 8), &root2);
result = 0LL;
}
else
{
printf("Diretory %s exists! Can't override an existing file\n", *(const char **)(a2 + 8));
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mkdir1 (int argc, char** argv) {
    char* dir_name;
    if(argc != 2) {
         printf("Usage: mkdir V6-directory\n");
         exit(-1);
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    int curr_inode_number = find_directory_in_directory(argv[1], &root2);
    if (curr_inode_number != -1) {
        printf("Diretory %s exists! Can't override an existing file\n", argv[1]);
        return -1;
    }
    dir_name = argv[1];
    make_directory_in_directory(dir_name, &root2);
    return 0;
}

canonical_original_code:
int mkdir1(int argc, char **argv) {
    char *dir_name;
    if(argc != 2) {
         printf("Usage: mkdir V6-directory\n");
         exit(-1);
    }
    if (curr_fd == -1) {
         perror("disk doesn't exist!\n");
         exit(-1);
    }
    int curr_inode_number = find_directory_in_directory(argv[1], &root2);
    if (curr_inode_number != -1) {
        printf("Diretory %s exists! Can't override an existing file\n", argv[1]);
        return -1;
    }
    dir_name = argv[1];
    make_directory_in_directory(dir_name, &root2);
    return 0;
}