repo: paulguy/piccrap

original_code:
int analog_decode(Connection *connection, Surface *surface, DecodeParams *params) {
 double invautolevel = 1.0 - params->autolevel;
 int i;
 int currentline, linestart;
 int xpos, avgsample, samples;
 double xposd;
 int runningstride;
 int activestart;
 int fuzz;
 double sampleperiod;
 SyncMode syncing;
 double synclevel, blanklevel;
 double whitelevel, blacklevel;
 currentline = 0;
 syncing = SYNC_SYNC;
 synclevel = (100.0);
 blanklevel = (75.0);
 fuzz = params->fuzzyness;
 activestart = 0;
 linestart = 0;
 for(i = 0; i < connection->length; i++) {
    if(currentline < (9)) {
   switch (syncing) {
    case SYNC_SYNC:
     if(connection->stream[i] < (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       fuzz = params->fuzzyness;
       syncing = SYNC_BLANK;
      } else {
       fuzz--;
      }
     } else {
      synclevel = synclevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       fuzz = params->fuzzyness;
      }
     }
     break;
    case SYNC_BLANK:
     if(connection->stream[i] > (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       if(currentline == 0) {
        runningstride = i - linestart;
       } else {
        runningstride += i - linestart;
       }
fprintf(stderr, "%d %d %d %d %f %f\n", currentline, i - linestart, runningstride, runningstride / (currentline + 1), synclevel, blanklevel);
       linestart = i;
       currentline++;
       fuzz = params->fuzzyness;
       syncing = SYNC_SYNC;
      } else {
       fuzz--;
      }
     } else {
      blanklevel = blanklevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       fuzz = params->fuzzyness;
      }
     }
     break;
    default:
     return(-1);
   }
  } else {
   switch (syncing) {
    case SYNC_SYNC:
     if(connection->stream[i] < synclevel) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       fuzz = params->fuzzyness;
       syncing = SYNC_BLANK;
      } else {
       fuzz--;
      }
     } else {
      synclevel = synclevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       activestart += params->fuzzyness - fuzz;
       fuzz = params->fuzzyness;
      }
     }
     break;
    case SYNC_BLANK:
     if(connection->stream[i] < blanklevel) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       activestart = i - linestart;
       sampleperiod = (double)(surface->width) / ((double)(runningstride / currentline) -
           (double)activestart -
           (((12) / ((44) + (48))) * (double)activestart));
fprintf(stderr, "%d %f ", activestart, sampleperiod);
       activestart = 0;
       xpos = 0;
       xposd = 0.0;
       samples = 0;
       avgsample = 0;
       whitelevel = blanklevel * ((12.5) / (75.0));
       blacklevel = blanklevel * ((70.0) / (75.0));
fprintf(stderr, "%f %f %f\n", blanklevel, blacklevel, whitelevel);
       fuzz = params->fuzzyness;
       syncing = SYNC_ACTIVE;
      } else {
       fuzz--;
      }
     } else {
      blanklevel = blanklevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       activestart += params->fuzzyness - fuzz;
       fuzz = params->fuzzyness;
      }
     }
     break;
    case SYNC_ACTIVE:
     if(connection->stream[i] > (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       runningstride += i - linestart;
       linestart = i;
       xpos = 0;
       currentline++;
       fuzz = params->fuzzyness;
       syncing = SYNC_SYNC;
fprintf(stderr, "%d %d %d %f %f\n", currentline, i - linestart, runningstride, synclevel, blanklevel);
fprintf(stderr, "Line %d ended at %d due to hsync reached.\n", currentline, i);
      } else {
       fuzz--;
      }
     } else {
      fuzz = params->fuzzyness;
     }
     if(connection->stream[i] < whitelevel) {
      avgsample += whitelevel;
     } else if(connection->stream[i] > blacklevel) {
      avgsample += blacklevel;
     } else {
      avgsample += connection->stream[i];
     }
     samples++;
     xposd += sampleperiod;
     if((int)xposd > xpos) {
      surface->luma[(currentline - (9)) * surface->width + xpos] = (int)(255.0 - ((avgsample / (double)samples) - whitelevel) * (255.0 / (blacklevel - whitelevel)));
      avgsample = 0;
      samples = 0;
      xpos++;
      if(xpos >= surface->width) {
fprintf(stderr, "Ran out of framebuffer on line %d.\n", currentline);
       syncing = SYNC_END;
      }
     }
     break;
    case SYNC_END:
     if(connection->stream[i] > (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       runningstride += i - linestart;
       currentline++;
fprintf(stderr, "%d %d %d %d %f %d %f\n", currentline, i - linestart, runningstride, runningstride / currentline, xposd, xpos, synclevel);
       linestart = i;
       xpos = 0;
       fuzz = params->fuzzyness;
       syncing = SYNC_SYNC;
      } else {
       fuzz--;
      }
     } else {
      fuzz = params->fuzzyness;
     }
     break;
   }
  }
 }
fprintf(stderr, "Read ended at %d, %d.\n", xpos, currentline);
 return(0);
}

canonical_original_code:
int analog_decode(struct Connection *connection, struct Surface *surface, struct DecodeParams *params) {
 double invautolevel = 1.0 - params->autolevel;
 int i;
 int currentline; int linestart;
 int xpos; int avgsample; int samples;
 double xposd;
 int runningstride;
 int activestart;
 int fuzz;
 double sampleperiod;
 enum SyncMode syncing;
 double synclevel; double blanklevel;
 double whitelevel; double blacklevel;
 currentline = 0;
 syncing = SYNC_SYNC;
 synclevel = (100.0);
 blanklevel = (75.0);
 fuzz = params->fuzzyness;
 activestart = 0;
 linestart = 0;
 for(i = 0; i < connection->length; i++) {
    if(currentline < (9)) {
   switch (syncing) {
    case SYNC_SYNC:
     if(connection->stream[i] < (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       fuzz = params->fuzzyness;
       syncing = SYNC_BLANK;
      } else {
       fuzz--;
      }
     } else {
      synclevel = synclevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       fuzz = params->fuzzyness;
      }
     }
     break;
    case SYNC_BLANK:
     if(connection->stream[i] > (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       if(currentline == 0) {
        runningstride = i - linestart;
       } else {
        runningstride += i - linestart;
       }
fprintf(stderr, "%d %d %d %d %f %f\n", currentline, i - linestart, runningstride, runningstride / (currentline + 1), synclevel, blanklevel);
       linestart = i;
       currentline++;
       fuzz = params->fuzzyness;
       syncing = SYNC_SYNC;
      } else {
       fuzz--;
      }
     } else {
      blanklevel = blanklevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       fuzz = params->fuzzyness;
      }
     }
     break;
    default:
     return(-1);
   }
  } else {
   switch (syncing) {
    case SYNC_SYNC:
     if(connection->stream[i] < synclevel) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       fuzz = params->fuzzyness;
       syncing = SYNC_BLANK;
      } else {
       fuzz--;
      }
     } else {
      synclevel = synclevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       activestart += params->fuzzyness - fuzz;
       fuzz = params->fuzzyness;
      }
     }
     break;
    case SYNC_BLANK:
     if(connection->stream[i] < blanklevel) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       activestart = i - linestart;
       sampleperiod = (double)(surface->width) / ((double)(runningstride / currentline) -
           (double)activestart -
           (((12) / ((44) + (48))) * (double)activestart));
fprintf(stderr, "%d %f ", activestart, sampleperiod);
       activestart = 0;
       xpos = 0;
       xposd = 0.0;
       samples = 0;
       avgsample = 0;
       whitelevel = blanklevel * ((12.5) / (75.0));
       blacklevel = blanklevel * ((70.0) / (75.0));
fprintf(stderr, "%f %f %f\n", blanklevel, blacklevel, whitelevel);
       fuzz = params->fuzzyness;
       syncing = SYNC_ACTIVE;
      } else {
       fuzz--;
      }
     } else {
      blanklevel = blanklevel*params->autolevel + connection->stream[i]*invautolevel;
      if(fuzz < params->fuzzyness) {
       activestart += params->fuzzyness - fuzz;
       fuzz = params->fuzzyness;
      }
     }
     break;
    case SYNC_ACTIVE:
     if(connection->stream[i] > (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       runningstride += i - linestart;
       linestart = i;
       xpos = 0;
       currentline++;
       fuzz = params->fuzzyness;
       syncing = SYNC_SYNC;
fprintf(stderr, "%d %d %d %f %f\n", currentline, i - linestart, runningstride, synclevel, blanklevel);
fprintf(stderr, "Line %d ended at %d due to hsync reached.\n", currentline, i);
      } else {
       fuzz--;
      }
     } else {
      fuzz = params->fuzzyness;
     }
     if(connection->stream[i] < whitelevel) {
      avgsample += whitelevel;
     } else if(connection->stream[i] > blacklevel) {
      avgsample += blacklevel;
     } else {
      avgsample += connection->stream[i];
     }
     samples++;
     xposd += sampleperiod;
     if((int)xposd > xpos) {
      surface->luma[(currentline - (9)) * surface->width + xpos] = (int)(255.0 - ((avgsample / (double)samples) - whitelevel) * (255.0 / (blacklevel - whitelevel)));
      avgsample = 0;
      samples = 0;
      xpos++;
      if(xpos >= surface->width) {
fprintf(stderr, "Ran out of framebuffer on line %d.\n", currentline);
       syncing = SYNC_END;
      }
     }
     break;
    case SYNC_END:
     if(connection->stream[i] > (synclevel * params->syncthresh)) {
      if(fuzz == 0) {
       i -= params->fuzzyness;
       runningstride += i - linestart;
       currentline++;
fprintf(stderr, "%d %d %d %d %f %d %f\n", currentline, i - linestart, runningstride, runningstride / currentline, xposd, xpos, synclevel);
       linestart = i;
       xpos = 0;
       fuzz = params->fuzzyness;
       syncing = SYNC_SYNC;
      } else {
       fuzz--;
      }
     } else {
      fuzz = params->fuzzyness;
     }
     break;
   }
  }
 }
fprintf(stderr, "Read ended at %d, %d.\n", xpos, currentline);
 return(0);
}

variable_types: struct Connection { double *stream; int length; } *

variable_types: struct Surface { int width; char *luma; } *

variable_types: struct DecodeParams { double syncthresh; double blankthresh; double autolevel; double autostride; int fuzzyness; } *

variable_types: invautolevel double

variable_types: i int

variable_types: currentline int

variable_types: linestart int

variable_types: xpos int

variable_types: avgsample int

variable_types: samples int

variable_types: xposd double

variable_types: runningstride int

variable_types: activestart int

variable_types: fuzz int

variable_types: sampleperiod double

variable_types: enum SyncMode { SYNC_SYNC=0, SYNC_BLANK=1, SYNC_ACTIVE=2, SYNC_END=3 }

variable_types: synclevel double

variable_types: blanklevel double

variable_types: whitelevel double

variable_types: blacklevel double


ragequit

decompiled_code:
void __fastcall __noreturn ragequit(const char *a1)
{
syslog(27, "%s", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
syslog(27, "%s", a1);
exit(-1);
}

original_code:
void ragequit(const char *msg){
  syslog((3<<3)|3,"%s", msg);
  exit(-1);
}

canonical_original_code:
void ragequit(char *msg){
  syslog((3<<3)|3,"%s", msg);
  exit(-1);
}

variable_types:
msg
char *

return_type: void


isnumber

decompiled_code:
__int16 __fastcall isnumber(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rdx
__int16 result; // ax

v1 = *a1;
if ( !*a1 )
return 1;
v2 = a1;
if ( v1 == 58 )
return 1;
v3 = *__ctype_b_loc();
while ( 1 )
{
result = v3[v1] & 0x800;
if ( !result )
break;
v1 = *++v2;
if ( !*v2 || v1 == 58 )
return 1;
}
return result;
}

canonical_decompiled_code:
__int16 __fastcall func9(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rdx
__int16 result; // ax

v1 = *a1;
if ( !*a1 )
return 1;
v2 = a1;
if ( v1 == 58 )
return 1;
v3 = *__ctype_b_loc();
while ( 1 )
{
result = v3[v1] & 0x800;
if ( !result )
break;
v1 = *++v2;
if ( !*v2 || v1 == 58 )
return 1;
}
return result;
}

original_code:
unsigned short int isnumber(char *buf){
  while(*buf != '\0' && *buf != ':'){
    if(!((*__ctype_b_loc ())[(int) ((*buf))] & (unsigned short int) _ISdigit))
      return 0;
    buf++;
  }
  return 1;
}

canonical_original_code:
unsigned short isnumber(char *buf){
  while(*buf != '\0' && *buf != ':'){
    if(!((*__ctype_b_loc ())[(int) ((*buf))] & (unsigned short) _ISdigit))
      return 0;
    buf++;
  }
  return 1;
}

variable_types:
buf
char *

return_type: unsigned short


mstrcmp

decompiled_code:
__int64 __fastcall mstrcmp(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl

v2 = 0LL;
do
v3 = *(_BYTE *)(a1 + v2++);
while ( v3 == *(_BYTE *)(a2 + v2 - 1) );
return 1LL;
}

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
__pid_t v4; // eax
int v5; // eax
int v6; // ebp
int v7; // ebx
__pid_t v8; // eax
int *v9; // rax
char *v10; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = getcryptid(argc, argv, envp);
if ( v3 - 1 > 5 )
ragequit("The crypt id found in /etc/shadow is invalid.");
v4 = fork();
if ( v4 < 0 )
ragequit("fork failed!\n");
if ( v4 > 0 )
{
printf("pid of child process %d \n", (unsigned int)v4);
exit(0);
}
umask(6u);
if ( setsid() < 0 )
ragequit("Couldn't get session id.\n");
close(0);
close(1);
v5 = socket(2, 1, 0);
v6 = v5;
if ( v5 < 0 )
ragequit("can't create socket");
fcntl(v5, 2, 1LL);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
*(_WORD *)addr.sa_data = _bswap_16(7331);
if ( bind(v6, &addr, 0x10u) < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "WARNING: cannot bind to socket %s (%s), exiting\n", "127.0.0.1", v10);
exit(-1);
}
if ( listen(v6, 1) )
ragequit("pald failed to listen on open sock\n");
addr_len = 16;
while ( 1 )
{
v7 = accept(v6, &addr, &addr_len);
if ( v7 < 0 )
break;
v8 = fork();
if ( v8 < 0 )
ragequit("fork");
if ( !v8 )
check_creds(v7, v3);
close(v7);
}
close(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
__pid_t v4; // eax
int v5; // eax
int v6; // ebp
int v7; // ebx
__pid_t v8; // eax
int *v9; // rax
char *v10; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = func10(argc, argv, envp);
if ( v3 - 1 > 5 )
func8("The crypt id found in /etc/shadow is invalid.");
v4 = fork();
if ( v4 < 0 )
func8("fork failed!\n");
if ( v4 > 0 )
{
printf("pid of child process %d \n", (unsigned int)v4);
exit(0);
}
umask(6u);
if ( setsid() < 0 )
func8("Couldn't get session id.\n");
close(0);
close(1);
v5 = socket(2, 1, 0);
v6 = v5;
if ( v5 < 0 )
func8("can't create socket");
fcntl(v5, 2, 1LL);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
*(_WORD *)addr.sa_data = func7(7331);
if ( bind(v6, &addr, 0x10u) < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "WARNING: cannot bind to socket %s (%s), exiting\n", "127.0.0.1", v10);
exit(-1);
}
if ( listen(v6, 1) )
func8("pald failed to listen on open sock\n");
addr_len = 16;
while ( 1 )
{
v7 = accept(v6, &addr, &addr_len);
if ( v7 < 0 )
break;
v8 = fork();
if ( v8 < 0 )
func8("fork");
if ( !v8 )
func12(v7, v3);
close(v7);
}
close(v6);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
  int crypt_id=getcryptid();
  if(crypt_id>6 || crypt_id<1)
    ragequit("The crypt id found in /etc/shadow is invalid.");
  pid_t pid = 0;
  pid_t sid = 0;
  pid = fork();
  if (pid < 0)
    ragequit("fork failed!\n");
  if (pid > 0)
    {
      printf("pid of child process %d \n", pid);
      exit(0);
    }
  umask(((0400 >> 3) >> 3)|((0200 >> 3) >> 3));
  sid = setsid();
  if(sid < 0)
    {
      ragequit("Couldn't get session id.\n");
    }
  close(0);
  close(1);
  int infd=socket(2, SOCK_STREAM, 0);
  if (infd < 0)
    ragequit("can't create socket");
  fcntl(infd, 2, 1);
  struct sockaddr_in addr;
  addr.sin_family = 2;
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  addr.sin_port = htons(7331);
  if (bind(infd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
    fprintf(stderr,"WARNING: cannot bind to socket %s (%s), exiting\n",
     "127.0.0.1", strerror((*__errno_location ())));
    exit(-1);
  }
  if(listen(infd,1)!=0)
    ragequit("pald failed to listen on open sock\n");
  int connection_fd;
  socklen_t address_length=(socklen_t)sizeof(struct sockaddr);
  while((connection_fd = accept(infd, (struct sockaddr *) &addr, &address_length )) > -1){
    pid_t child = fork();
    if(child<0)
      ragequit("fork");
    else if(child == 0)
      return check_creds(connection_fd, crypt_id);
    else
      close(connection_fd);
  }
  close(infd);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int crypt_id = getcryptid();
  if(crypt_id>6 || crypt_id<1)
    ragequit("The crypt id found in /etc/shadow is invalid.");
  int pid = 0;
  int sid = 0;
  pid = fork();
  if (pid < 0)
    ragequit("fork failed!\n");
  if (pid > 0)
    {
      printf("pid of child process %d \n", pid);
      exit(0);
    }
  umask(((0400 >> 3) >> 3)|((0200 >> 3) >> 3));
  sid = setsid();
  if(sid < 0)
    {
      ragequit("Couldn't get session id.\n");
    }
  close(0);
  close(1);
  int infd = socket(2, SOCK_STREAM, 0);
  if (infd < 0)
    ragequit("can't create socket");
  fcntl(infd, 2, 1);
  struct sockaddr_in addr;
  addr.sin_family = 2;
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  addr.sin_port = htons(7331);
  if (bind(infd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
    fprintf(stderr,"WARNING: cannot bind to socket %s (%s), exiting\n",
     "127.0.0.1", strerror((*__errno_location ())));
    exit(-1);
  }
  if(listen(infd,1)!=0)
    ragequit("pald failed to listen on open sock\n");
  int connection_fd;
  unsigned int address_length = (socklen_t)sizeof(struct sockaddr);
  while((connection_fd = accept(infd, (struct sockaddr *) &addr, &address_length )) > -1){
    int child = fork();
    if(child<0)
      ragequit("fork");
    else if(child == 0)
      return check_creds(connection_fd, crypt_id);
    else
      close(connection_fd);
  }
  close(infd);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: pid int

variable_types: sid int

variable_types: infd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: child int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


dispose

repo: pawel-smolenski/MyFS

decompiled_code:
__int64 __fastcall dispose(unsigned int a1)
{
fseek(partitionFile, 0LL, 0);
fwrite(superblock, 0x1CuLL, 1uLL, partitionFile);
fwrite(iNodeTable, 0x20uLL, iNodeTableSize, partitionFile);
free(filename);
fclose(partitionFile);
free(superblock);
free(iNodeTable);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
fseek(partitionFile, 0LL, 0);
fwrite(superblock, 0x1CuLL, 1uLL, partitionFile);
fwrite(iNodeTable, 0x20uLL, iNodeTableSize, partitionFile);
free(filename);
fclose(partitionFile);
free(superblock);
free(iNodeTable);
return a1;
}

original_code:
int dispose(int returnCode)
{
 fseek(partitionFile, 0, 0);
 fwrite(superblock, sizeof(struct SUPERBLOCK), 1, partitionFile);
 fwrite(iNodeTable, sizeof(struct INODE), iNodeTableSize, partitionFile);
 free(filename);
 fclose(partitionFile);
 free(superblock);
 free(iNodeTable);
 return returnCode;
}

variable_types: returnCode int

user_defined_types: struct SUPERBLOCK { int partitionSize; int blockSize; int dataBlockOffset; int firstFile; int lastFile; int firstFree; int lastFree; }

user_defined_types: struct INODE { char fileName[16]; int fileSize; int blockAddres; int nextBlock; int nextFile; }


decompiled_code:
__int64 print_help()
{
puts("My File System");
puts(" create SIZE BLOCKSIZE - Tworzy nowa partycje o rozmiarze SIZE bajtow");
puts(" delete - Usuwa partycje");
puts(" map - Wyswietla mape partycji");
puts(aLsWyswietlaZaw);
puts(aCptoSourceFile);
puts(" cpfrom FILENAME DEST - Kopiuje plik z partycji na lokalny dysk");
puts(" rm FILENAME - Usuwa plik z partycji");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
puts("My File System");
puts(" create SIZE BLOCKSIZE - Tworzy nowa partycje o rozmiarze SIZE bajtow");
puts(" delete - Usuwa partycje");
puts(" map - Wyswietla mape partycji");
puts(aLsWyswietlaZaw);
puts(aCptoSourceFile);
puts(" cpfrom FILENAME DEST - Kopiuje plik z partycji na lokalny dysk");
puts(" rm FILENAME - Usuwa plik z partycji");
return 0LL;
}

original_code:
int print_help(void)
{
 printf("My File System\n");
 printf("  create SIZE BLOCKSIZE - Tworzy nowa partycje o rozmiarze SIZE bajtow\n");
 printf("  delete - Usuwa partycje\n");
 printf("  map - Wyswietla mape partycji\n");
 printf("  ls - Wyswietla zawartość katalogu glownego\n");
 printf("  cpto SOURCE FILENAME - Kopiuje plik z lokalnego dysku na partycję\n");
 printf("  cpfrom FILENAME DEST - Kopiuje plik z partycji na lokalny dysk\n");
 printf("  rm FILENAME - Usuwa plik z partycji\n");
 return 0;
}

canonical_original_code:
int print_help()
{
 printf("My File System\n");
 printf("  create SIZE BLOCKSIZE - Tworzy nowa partycje o rozmiarze SIZE bajtow\n");
 printf("  delete - Usuwa partycje\n");
 printf("  map - Wyswietla mape partycji\n");
 printf("  ls - Wyswietla zawartość katalogu glownego\n");
 printf("  cpto SOURCE FILENAME - Kopiuje plik z lokalnego dysku na partycję\n");
 printf("  cpfrom FILENAME DEST - Kopiuje plik z partycji na lokalny dysk\n");
 printf("  rm FILENAME - Usuwa plik z partycji\n");
 return 0;
}


getFilename

decompiled_code:
char *getFilename()
{
char *v0; // rbx

v0 = (char *)calloc(0x10uLL, 1uLL);
strcpy(v0, "./");
strcat(v0, "partition.mfs");
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx

v0 = (char *)calloc(0x10uLL, 1uLL);
strcpy(v0, "./");
strcat(v0, "partition.mfs");
return v0;
}

original_code:
char *getFilename(void)
{
 char *filename = calloc(strlen("partition.mfs") + 3, sizeof(char));
 strcpy(filename, "./");
 strcat(filename, "partition.mfs");
 return filename;
}

canonical_original_code:
char *getFilename()
{
 char *filename = calloc(strlen("partition.mfs") + 3, sizeof(char));
 strcpy(filename, "./");
 strcat(filename, "partition.mfs");
 return filename;
}

variable_types:
filename
char *

return_type: char *


calculateINodeTableSize

decompiled_code:
unsigned __int64 __fastcall calculateINodeTableSize(int a1, int a2)
{
return a1 / (unsigned __int64)(a2 + 32LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(int a1, int a2)
{
return a1 / (unsigned __int64)(a2 + 32LL);
}

original_code:
int calculateINodeTableSize(int size, int blockSize)
{
 return size / (blockSize + sizeof(struct INODE));
}

variable_types: size int

variable_types: blockSize int


init

decompiled_code:
void init()
{
FILE *v0; // rax
FILE *v1; // rbx
size_t v2; // rbx

filename = getFilename();
v0 = fopen(filename, "r+");
partitionFile = v0;
if ( v0 )
{
v1 = v0;
superblock = calloc(1uLL, 0x1CuLL);
fread(superblock, 0x1CuLL, 1uLL, v1);
iNodeTableSize = calculateINodeTableSize(*(_DWORD *)superblock, *((_DWORD *)superblock + 1));
v2 = iNodeTableSize;
iNodeTable = calloc(iNodeTableSize, 0x20uLL);
fread(iNodeTable, 0x20uLL, v2, partitionFile);
}
else
{
puts("Partycja nie istnieje");
free(filename);
}
}

canonical_decompiled_code:
void func4()
{
FILE *v0; // rax
FILE *v1; // rbx
size_t v2; // rbx

filename = func2();
v0 = fopen(filename, "r+");
partitionFile = v0;
if ( v0 )
{
v1 = v0;
superblock = calloc(1uLL, 0x1CuLL);
fread(superblock, 0x1CuLL, 1uLL, v1);
iNodeTableSize = func3(*(_DWORD *)superblock, *((_DWORD *)superblock + 1));
v2 = iNodeTableSize;
iNodeTable = calloc(iNodeTableSize, 0x20uLL);
fread(iNodeTable, 0x20uLL, v2, partitionFile);
}
else
{
puts("Partycja nie istnieje");
free(filename);
}
}

original_code:
void init(void)
{
 filename = getFilename();
 partitionFile = fopen(filename, "r+");
 if (partitionFile == ((void *)0))
 {
  printf("Partycja nie istnieje\n");
  free(filename);
  return;
 }
 superblock = calloc(1, sizeof(struct SUPERBLOCK));
 fread(superblock, sizeof(struct SUPERBLOCK), 1, partitionFile);
 iNodeTableSize = calculateINodeTableSize(superblock->partitionSize, superblock->blockSize);
 iNodeTable = (struct INODE *)calloc(iNodeTableSize, sizeof(struct INODE));
 fread(iNodeTable, sizeof(struct INODE), iNodeTableSize, partitionFile);
}

canonical_original_code:
void init()
{
 filename = getFilename();
 partitionFile = fopen(filename, "r+");
 if (partitionFile == ((void *)0))
 {
  printf("Partycja nie istnieje\n");
  free(filename);
  return;
 }
 superblock = calloc(1, sizeof(struct SUPERBLOCK));
 fread(superblock, sizeof(struct SUPERBLOCK), 1, partitionFile);
 iNodeTableSize = calculateINodeTableSize(superblock->partitionSize, superblock->blockSize);
 iNodeTable = (struct INODE *)calloc(iNodeTableSize, sizeof(struct INODE));
 fread(iNodeTable, sizeof(struct INODE), iNodeTableSize, partitionFile);
}


filenameExists

decompiled_code:
int __fastcall filenameExists(char *s2)
{
int v1; // eax
char *v2; // r12
char *v3; // rbx
int result; // eax

v1 = *((_DWORD *)superblock + 3);
if ( v1 < 0 )
return -1;
v2 = (char *)iNodeTable;
while ( 1 )
{
v3 = &v2[32 * v1];
result = strcmp(v3, s2);
if ( !result )
break;
v1 = *((_DWORD *)v3 + 7);
if ( v1 < 0 )
return -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(char *s2)
{
int v1; // eax
char *v2; // r12
char *v3; // rbx
int result; // eax

v1 = *((_DWORD *)superblock + 3);
if ( v1 < 0 )
return -1;
v2 = (char *)iNodeTable;
while ( 1 )
{
v3 = &v2[32 * v1];
result = strcmp(v3, s2);
if ( !result )
break;
v1 = *((_DWORD *)v3 + 7);
if ( v1 < 0 )
return -1;
}
return result;
}

original_code:
int filenameExists(char* filename)
{
 int fileAddress;
 for(fileAddress = superblock->firstFile; fileAddress >= 0; fileAddress = iNodeTable[fileAddress].nextFile)
 {
  if(strcmp(iNodeTable[fileAddress].fileName, filename) == 0)
  {
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int filenameExists(char *filename)
{
 int fileAddress;
 for(fileAddress = superblock->firstFile; fileAddress >= 0; fileAddress = iNodeTable[fileAddress].nextFile)
 {
  if(strcmp(iNodeTable[fileAddress].fileName, filename) == 0)
  {
   return 0;
  }
 }
 return -1;
}

variable_types: fileAddress int


hasEnoughFreeSpace

decompiled_code:
__int64 __fastcall hasEnoughFreeSpace(int a1)
{
__int64 result; // rax
int v2; // edx

result = *((unsigned int *)superblock + 5);
if ( a1 <= 0 )
return 0LL;
if ( (_DWORD)result != -1 )
{
v2 = 0;
while ( 1 )
{
v2 += *((_DWORD *)superblock + 1);
result = *((unsigned int *)iNodeTable + 8 * (int)result + 6);
if ( a1 <= v2 )
break;
if ( (_DWORD)result == -1 )
return result;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
int v2; // edx

result = *((unsigned int *)superblock + 5);
if ( a1 <= 0 )
return 0LL;
if ( (_DWORD)result != -1 )
{
v2 = 0;
while ( 1 )
{
v2 += *((_DWORD *)superblock + 1);
result = *((unsigned int *)iNodeTable + 8 * (int)result + 6);
if ( a1 <= v2 )
break;
if ( (_DWORD)result == -1 )
return result;
}
result = 0LL;
}
return result;
}

original_code:
int hasEnoughFreeSpace(int size)
{
 int freeBlockAddr;
 int freeSpace = 0;
 for(freeBlockAddr=superblock->firstFree; freeSpace < size; freeBlockAddr = iNodeTable[freeBlockAddr].nextBlock)
 {
  if(freeBlockAddr == -1)
  {
   return -1;
  }
  freeSpace += superblock->blockSize;
 }
 return 0;
}

variable_types: freeBlockAddr int

variable_types: freeSpace int


format

decompiled_code:
__int64 __fastcall format(int a1, int a2)
{
_DWORD *v2; // rbx
int v3; // er12
__int64 v4; // rcx
int i; // edx
_DWORD *v6; // rax
char ptr[25]; // [rsp+Fh] [rbp-19h] BYREF

ptr[0] = 0;
v2 = calloc(1uLL, 0x1CuLL);
superblock = v2;
*v2 = a1;
v2[1] = a2;
v2[3] = -1;
v2[4] = -1;
v2[5] = 0;
v3 = calculateINodeTableSize(a1, a2);
iNodeTableSize = v3;
v2[6] = v3 - 1;
v2[2] = 32 * v3 + 28;
iNodeTable = calloc(v3, 0x20uLL);
if ( v3 > 0 )
{
v4 = 0LL;
for ( i = 0; ; v6[6] = i )
{
*((_BYTE *)iNodeTable + v4) = 0;
v6 = (char *)iNodeTable + v4;
v6[4] = 0;
v6[5] = i;
v6[7] = -1;
++i;
v4 += 32LL;
if ( i >= iNodeTableSize )
break;
}
v6[6] = -1;
}
fseek(partitionFile, 0LL, 0);
fwrite(superblock, 0x1CuLL, 1uLL, partitionFile);
fwrite(iNodeTable, 0x20uLL, iNodeTableSize, partitionFile);
fseek(partitionFile, a1, 0);
fwrite(ptr, 1uLL, 1uLL, partitionFile);
free(iNodeTable);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
_DWORD *v2; // rbx
int v3; // er12
__int64 v4; // rcx
int i; // edx
_DWORD *v6; // rax
char ptr[25]; // [rsp+Fh] [rbp-19h] BYREF

ptr[0] = 0;
v2 = calloc(1uLL, 0x1CuLL);
superblock = v2;
*v2 = a1;
v2[1] = a2;
v2[3] = -1;
v2[4] = -1;
v2[5] = 0;
v3 = func3(a1, a2);
iNodeTableSize = v3;
v2[6] = v3 - 1;
v2[2] = 32 * v3 + 28;
iNodeTable = calloc(v3, 0x20uLL);
if ( v3 > 0 )
{
v4 = 0LL;
for ( i = 0; ; v6[6] = i )
{
*((_BYTE *)iNodeTable + v4) = 0;
v6 = (char *)iNodeTable + v4;
v6[4] = 0;
v6[5] = i;
v6[7] = -1;
++i;
v4 += 32LL;
if ( i >= iNodeTableSize )
break;
}
v6[6] = -1;
}
fseek(partitionFile, 0LL, 0);
fwrite(superblock, 0x1CuLL, 1uLL, partitionFile);
fwrite(iNodeTable, 0x20uLL, iNodeTableSize, partitionFile);
fseek(partitionFile, a1, 0);
fwrite(ptr, 1uLL, 1uLL, partitionFile);
free(iNodeTable);
return 0LL;
}

original_code:
int format(int size, int blockSize)
{
 int i;
 char buffer[1];
 buffer[0] = '\0';
 superblock = calloc(1, sizeof(struct SUPERBLOCK));
 superblock->partitionSize = size;
 superblock->blockSize = blockSize;
 superblock->firstFile = -1;
 superblock->lastFile = -1;
 superblock->firstFree = 0;
 iNodeTableSize = calculateINodeTableSize(size, blockSize);
 superblock->lastFree = iNodeTableSize-1;
 superblock->dataBlockOffset = sizeof(struct SUPERBLOCK) + sizeof(struct INODE)*iNodeTableSize;
 iNodeTable = (struct INODE*) calloc(iNodeTableSize, sizeof(struct INODE));
 for (i = 0; i < iNodeTableSize; i++)
 {
  iNodeTable[i].fileName[0] = '\0';
  iNodeTable[i].fileSize = 0;
  iNodeTable[i].blockAddres = i;
  iNodeTable[i].nextFile = -1;
  if(i+1 < iNodeTableSize)
  {
   iNodeTable[i].nextBlock = i+1;
  }
  else
  {
   iNodeTable[i].nextBlock = -1;
  }
 }
 fseek(partitionFile, 0, 0);
 fwrite(superblock, sizeof(struct SUPERBLOCK), 1, partitionFile);
 fwrite(iNodeTable, sizeof(struct INODE), iNodeTableSize, partitionFile);
 fseek(partitionFile, size, 0);
 fwrite(buffer, sizeof(char), 1, partitionFile);
 free(iNodeTable);
 return 0;
}

canonical_original_code:
int format(int size, int blockSize)
{
 int i;
 char buffer[1];
 buffer[0] = '\0';
 superblock = calloc(1, sizeof(struct SUPERBLOCK));
 superblock->partitionSize = size;
 superblock->blockSize = blockSize;
 superblock->firstFile = -1;
 superblock->lastFile = -1;
 superblock->firstFree = 0;
 iNodeTableSize = calculateINodeTableSize(size, blockSize);
 superblock->lastFree = iNodeTableSize-1;
 superblock->dataBlockOffset = sizeof(struct SUPERBLOCK) + sizeof(struct INODE)*iNodeTableSize;
 iNodeTable = (struct INODE *) calloc(iNodeTableSize, sizeof(struct INODE));
 for (i = 0; i < iNodeTableSize; i++)
 {
  iNodeTable[i].fileName[0] = '\0';
  iNodeTable[i].fileSize = 0;
  iNodeTable[i].blockAddres = i;
  iNodeTable[i].nextFile = -1;
  if(i+1 < iNodeTableSize)
  {
   iNodeTable[i].nextBlock = i+1;
  }
  else
  {
   iNodeTable[i].nextBlock = -1;
  }
 }
 fseek(partitionFile, 0, 0);
 fwrite(superblock, sizeof(struct SUPERBLOCK), 1, partitionFile);
 fwrite(iNodeTable, sizeof(struct INODE), iNodeTableSize, partitionFile);
 fseek(partitionFile, size, 0);
 fwrite(buffer, sizeof(char), 1, partitionFile);
 free(iNodeTable);
 return 0;
}

variable_types: i int

variable_types:
buffer
char [1]


create

decompiled_code:
__int64 __fastcall create(int a1, int a2)
{
char *v3; // rdi
__int64 result; // rax

v3 = getFilename();
filename = v3;
if ( a1 < (unsigned __int64)(10 * a2 + 60LL) )
{
puts("Rozmiar partycji jest nieprawidlowy");
result = 1LL;
}
else
{
partitionFile = fopen(v3, "wb");
format(a1, a2);
fclose(partitionFile);
free(filename);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
char *v3; // rdi
__int64 result; // rax

v3 = func2();
filename = v3;
if ( a1 < (unsigned __int64)(10 * a2 + 60LL) )
{
puts("Rozmiar partycji jest nieprawidlowy");
result = 1LL;
}
else
{
partitionFile = fopen(v3, "wb");
func7(a1, a2);
fclose(partitionFile);
free(filename);
result = 0LL;
}
return result;
}

original_code:
int create(int size, int blockSize)
{
 filename = getFilename();
 if (size < (sizeof(struct SUPERBLOCK) + sizeof(struct INODE) + 10 * blockSize))
 {
  printf("Rozmiar partycji jest nieprawidlowy\n");
  return 1;
 }
 partitionFile = fopen(filename, "wb");
 format(size, blockSize);
 fclose(partitionFile);
 free(filename);
 return 0;
}


delete

decompiled_code:
__int64 delete()
{
FILE *v0; // rax
const char *v1; // rbp
size_t v2; // rax
char *v3; // rbx
__int64 result; // rax
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

filename = getFilename();
v0 = fopen(filename, "r");
partitionFile = v0;
if ( v0 )
{
fclose(v0);
printf("Czy na pewno usunac partycje? y/n: ");
_isoc99_scanf("%c", v5);
if ( v5[0] == 110 )
{
puts("Usuniecie partycji anulowane");
}
else
{
v1 = filename;
v2 = strlen(filename);
v3 = (char *)calloc(v2 + 4, 1uLL);
*(_DWORD *)v3 = 2125170;
strcat(v3, v1);
system(v3);
puts("Partycja zostala usunieta");
free(v3);
free(filename);
}
result = 0LL;
}
else
{
puts("Partycja nie istnieje");
free(filename);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
FILE *v0; // rax
const char *v1; // rbp
size_t v2; // rax
char *v3; // rbx
__int64 result; // rax
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

filename = func2();
v0 = fopen(filename, "r");
partitionFile = v0;
if ( v0 )
{
fclose(v0);
printf("Czy na pewno usunac partycje? y/n: ");
_isoc99_scanf("%c", v5);
if ( v5[0] == 110 )
{
puts("Usuniecie partycji anulowane");
}
else
{
v1 = filename;
v2 = strlen(filename);
v3 = (char *)calloc(v2 + 4, 1uLL);
*(_DWORD *)v3 = 2125170;
strcat(v3, v1);
system(v3);
puts("Partycja zostala usunieta");
free(v3);
free(filename);
}
result = 0LL;
}
else
{
puts("Partycja nie istnieje");
free(filename);
result = 1LL;
}
return result;
}

original_code:
int delete(void)
{
 char *command;
 char decision;
 filename = getFilename();
 partitionFile = fopen(filename, "r");
 if (partitionFile == ((void *)0))
 {
  printf("Partycja nie istnieje\n");
  free(filename);
  return 1;
 }
 fclose(partitionFile);
 printf("Czy na pewno usunac partycje? y/n: ");
 scanf("%c", &decision);
 if (decision == 'n')
 {
  printf("Usuniecie partycji anulowane\n");
  return 0;
 }
 command = calloc(strlen(filename) + 4, sizeof(char));
 strcpy(command, "rm ");
 strcat(command, filename);
 system(command);
 printf("Partycja zostala usunieta\n");
 free(command);
 free(filename);
 return 0;
}

canonical_original_code:
int delete()
{
 char *command;
 char decision;
 filename = getFilename();
 partitionFile = fopen(filename, "r");
 if (partitionFile == ((void *)0))
 {
  printf("Partycja nie istnieje\n");
  free(filename);
  return 1;
 }
 fclose(partitionFile);
 printf("Czy na pewno usunac partycje? y/n: ");
 scanf("%c", &decision);
 if (decision == 'n')
 {
  printf("Usuniecie partycji anulowane\n");
  return 0;
 }
 command = calloc(strlen(filename) + 4, sizeof(char));
 strcpy(command, "rm ");
 strcat(command, filename);
 system(command);
 printf("Partycja zostala usunieta\n");
 free(command);
 free(filename);
 return 0;
}

variable_types:
command
char *

variable_types: decision char


map

decompiled_code:
__int64 map()
{
__int64 v0; // rbx
__int64 v1; // rbp
const char *v2; // rsi

printf(
"Size: %d Block: %d DataOffset: %d FirstFile: %d LastFile: %d FirstFree: %d LastFree: %d\n",
*(unsigned int *)superblock,
*((unsigned int *)superblock + 1),
*((unsigned int *)superblock + 2),
*((unsigned int *)superblock + 3),
*((unsigned int *)superblock + 4),
*((unsigned int *)superblock + 5),
*((unsigned int *)superblock + 6));
puts("ID\tFilename\tFileSize\tNextFile\tNextBlock");
if ( iNodeTableSize > 0 )
{
v0 = 0LL;
do
{
printf("%3d", (unsigned int)v0);
v1 = 32 * v0;
v2 = (char *)iNodeTable + 32 * v0;
if ( *v2 )
{
printf("\t%15s", v2);
printf("\t%5d", *(unsigned int *)((char *)iNodeTable + v1 + 16));
}
else
{
printf("\tEMPTY BLOCK ");
printf("\t - ");
}
printf("\t%d", *(unsigned int *)((char *)iNodeTable + v1 + 28));
printf("\t%d", *(unsigned int *)((char *)iNodeTable + v1 + 24));
putchar(10);
++v0;
}
while ( iNodeTableSize > (int)v0 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rbx
__int64 v1; // rbp
const char *v2; // rsi

printf(
"Size: %d Block: %d DataOffset: %d FirstFile: %d LastFile: %d FirstFree: %d LastFree: %d\n",
*(unsigned int *)superblock,
*((unsigned int *)superblock + 1),
*((unsigned int *)superblock + 2),
*((unsigned int *)superblock + 3),
*((unsigned int *)superblock + 4),
*((unsigned int *)superblock + 5),
*((unsigned int *)superblock + 6));
puts("ID\tFilename\tFileSize\tNextFile\tNextBlock");
if ( iNodeTableSize > 0 )
{
v0 = 0LL;
do
{
printf("%3d", (unsigned int)v0);
v1 = 32 * v0;
v2 = (char *)iNodeTable + 32 * v0;
if ( *v2 )
{
printf("\t%15s", v2);
printf("\t%5d", *(unsigned int *)((char *)iNodeTable + v1 + 16));
}
else
{
printf("\tEMPTY BLOCK ");
printf("\t - ");
}
printf("\t%d", *(unsigned int *)((char *)iNodeTable + v1 + 28));
printf("\t%d", *(unsigned int *)((char *)iNodeTable + v1 + 24));
putchar(10);
++v0;
}
while ( iNodeTableSize > (int)v0 );
}
return 0LL;
}

original_code:
int map(void)
{
 int i;
 printf("Size: %d  Block: %d  DataOffset: %d FirstFile: %d  LastFile: %d FirstFree: %d LastFree: %d\n", superblock->partitionSize, superblock->blockSize, superblock->dataBlockOffset, superblock->firstFile, superblock->lastFile, superblock->firstFree, superblock->lastFree);
 printf("ID\tFilename\tFileSize\tNextFile\tNextBlock\n" );
 for(i = 0; i < iNodeTableSize; i++)
 {
  printf("%3d", i);
  if(strlen(iNodeTable[i].fileName) > 0)
  {
   printf("\t%15s", iNodeTable[i].fileName);
   printf("\t%5d", iNodeTable[i].fileSize);
  }
  else
  {
   printf("\tEMPTY BLOCK    ");
   printf("\t  -  ");
  }
  printf("\t%d", iNodeTable[i].nextFile);
  printf("\t%d", iNodeTable[i].nextBlock);
  printf("\n");
 }
 return 0;
}

canonical_original_code:
int map()
{
 int i;
 printf("Size: %d  Block: %d  DataOffset: %d FirstFile: %d  LastFile: %d FirstFree: %d LastFree: %d\n", superblock->partitionSize, superblock->blockSize, superblock->dataBlockOffset, superblock->firstFile, superblock->lastFile, superblock->firstFree, superblock->lastFree);
 printf("ID\tFilename\tFileSize\tNextFile\tNextBlock\n" );
 for(i = 0; i < iNodeTableSize; i++)
 {
  printf("%3d", i);
  if(strlen(iNodeTable[i].fileName) > 0)
  {
   printf("\t%15s", iNodeTable[i].fileName);
   printf("\t%5d", iNodeTable[i].fileSize);
  }
  else
  {
   printf("\tEMPTY BLOCK    ");
   printf("\t  -  ");
  }
  printf("\t%d", iNodeTable[i].nextFile);
  printf("\t%d", iNodeTable[i].nextBlock);
  printf("\n");
 }
 return 0;
}


ls

decompiled_code:
__int64 ls()
{
int v0; // eax
__int64 v1; // rbx

v0 = *((_DWORD *)superblock + 3);
if ( v0 == -1 )
{
puts("Brak plikow na dysku");
}
else
{
do
{
v1 = 32LL * v0;
printf("%15s %-5d\n", (const char *)iNodeTable + v1, *(unsigned int *)((char *)iNodeTable + v1 + 16));
v0 = *(_DWORD *)((char *)iNodeTable + v1 + 28);
}
while ( v0 != -1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
__int64 v1; // rbx

v0 = *((_DWORD *)superblock + 3);
if ( v0 == -1 )
{
puts("Brak plikow na dysku");
}
else
{
do
{
v1 = 32LL * v0;
printf("%15s %-5d\n", (const char *)iNodeTable + v1, *(unsigned int *)((char *)iNodeTable + v1 + 16));
v0 = *(_DWORD *)((char *)iNodeTable + v1 + 28);
}
while ( v0 != -1 );
}
return 0LL;
}

original_code:
int ls(void)
{
 int fileAddr;
 if(superblock->firstFile == -1)
 {
  printf("Brak plikow na dysku\n");
 }
 else
 {
  for(fileAddr = superblock->firstFile; fileAddr != -1; fileAddr = iNodeTable[fileAddr].nextFile)
  {
   printf("%15s   %-5d\n", iNodeTable[fileAddr].fileName, iNodeTable[fileAddr].fileSize);
  }
 }
 return 0;
}

canonical_original_code:
int ls()
{
 int fileAddr;
 if(superblock->firstFile == -1)
 {
  printf("Brak plikow na dysku\n");
 }
 else
 {
  for(fileAddr = superblock->firstFile; fileAddr != -1; fileAddr = iNodeTable[fileAddr].nextFile)
  {
   printf("%15s   %-5d\n", iNodeTable[fileAddr].fileName, iNodeTable[fileAddr].fileSize);
  }
 }
 return 0;
}

variable_types: fileAddr int


rm

decompiled_code:
int __fastcall rm(char *s2)
{
_DWORD *v1; // r15
int v2; // er14
int v3; // ebp
int v4; // er12
char *v5; // rbx
int result; // eax
char *v7; // rsi
_DWORD *v8; // rdx
_DWORD *v9; // [rsp+8h] [rbp-40h]

v1 = superblock;
v2 = *((_DWORD *)superblock + 3);
if ( v2 == -1 )
{
LABEL_6:
puts("Plik o podanej nazwie nie zostal znaleziony");
result = 1;
}
else
{
v9 = iNodeTable;
v3 = *((_DWORD *)superblock + 3);
v4 = -1;
while ( 1 )
{
v5 = (char *)&v9[8 * v3];
result = strcmp(v5, s2);
if ( !result )
break;
v4 = v3;
if ( *((_DWORD *)v5 + 7) == -1 )
goto LABEL_6;
v3 = *((_DWORD *)v5 + 7);
}
if ( v2 == v3 )
v1[3] = *((_DWORD *)v5 + 7);
if ( v1[4] == v3 )
v1[4] = v4;
if ( v4 != -1 )
v9[8 * v4 + 7] = *((_DWORD *)v5 + 7);
do
{
*v5 = 0;
*((_DWORD *)v5 + 4) = 0;
*((_DWORD *)v5 + 7) = -1;
v7 = (char *)iNodeTable;
v8 = superblock;
*((_DWORD *)iNodeTable + 8 * *((int *)superblock + 6) + 6) = v3;
v8[6] = v3;
if ( v8[5] == -1 )
v8[5] = v3;
v3 = *((_DWORD *)v5 + 6);
*((_DWORD *)v5 + 6) = -1;
v5 = &v7[32 * v3];
}
while ( v3 != -1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(char *s2)
{
_DWORD *v1; // r15
int v2; // er14
int v3; // ebp
int v4; // er12
char *v5; // rbx
int result; // eax
char *v7; // rsi
_DWORD *v8; // rdx
_DWORD *v9; // [rsp+8h] [rbp-40h]

v1 = superblock;
v2 = *((_DWORD *)superblock + 3);
if ( v2 == -1 )
{
LABEL_6:
puts("Plik o podanej nazwie nie zostal znaleziony");
result = 1;
}
else
{
v9 = iNodeTable;
v3 = *((_DWORD *)superblock + 3);
v4 = -1;
while ( 1 )
{
v5 = (char *)&v9[8 * v3];
result = strcmp(v5, s2);
if ( !result )
break;
v4 = v3;
if ( *((_DWORD *)v5 + 7) == -1 )
goto LABEL_6;
v3 = *((_DWORD *)v5 + 7);
}
if ( v2 == v3 )
v1[3] = *((_DWORD *)v5 + 7);
if ( v1[4] == v3 )
v1[4] = v4;
if ( v4 != -1 )
v9[8 * v4 + 7] = *((_DWORD *)v5 + 7);
do
{
*v5 = 0;
*((_DWORD *)v5 + 4) = 0;
*((_DWORD *)v5 + 7) = -1;
v7 = (char *)iNodeTable;
v8 = superblock;
*((_DWORD *)iNodeTable + 8 * *((int *)superblock + 6) + 6) = v3;
v8[6] = v3;
if ( v8[5] == -1 )
v8[5] = v3;
v3 = *((_DWORD *)v5 + 6);
*((_DWORD *)v5 + 6) = -1;
v5 = &v7[32 * v3];
}
while ( v3 != -1 );
}
return result;
}

original_code:
int rm(char *filename)
{
 int blockAddr, prevBlockAddr = -1;
 struct INODE* currentFile;
 for(blockAddr = superblock->firstFile; blockAddr != -1; blockAddr = currentFile->nextFile)
 {
  currentFile = &iNodeTable[blockAddr];
  if(strcmp(currentFile->fileName, filename) == 0)
  {
   break;
  }
  prevBlockAddr = blockAddr;
 }
 if(blockAddr == -1)
 {
  printf("Plik o podanej nazwie nie zostal znaleziony\n");
  return 1;
 }
 if(blockAddr == superblock->firstFile)
 {
  superblock->firstFile = currentFile->nextFile;
 }
 if(blockAddr == superblock->lastFile)
 {
  superblock->lastFile = prevBlockAddr;
 }
 if(prevBlockAddr != -1)
 {
  iNodeTable[prevBlockAddr].nextFile = currentFile->nextFile;
 }
 while(blockAddr != -1)
 {
  currentFile->fileName[0] = '\0';
  currentFile->fileSize = 0;
  currentFile->nextFile = -1;
  iNodeTable[superblock->lastFree].nextBlock = blockAddr;
  superblock->lastFree = blockAddr;
  if(superblock->firstFree == -1)
  {
   superblock->firstFree = blockAddr;
  }
  blockAddr = currentFile->nextBlock;
  currentFile->nextBlock = -1;
  currentFile = &iNodeTable[blockAddr];
 }
 return 0;
}

canonical_original_code:
int rm(char *filename)
{
 int blockAddr; int prevBlockAddr = -1;
 struct INODE *currentFile;
 for(blockAddr = superblock->firstFile; blockAddr != -1; blockAddr = currentFile->nextFile)
 {
  currentFile = &iNodeTable[blockAddr];
  if(strcmp(currentFile->fileName, filename) == 0)
  {
   break;
  }
  prevBlockAddr = blockAddr;
 }
 if(blockAddr == -1)
 {
  printf("Plik o podanej nazwie nie zostal znaleziony\n");
  return 1;
 }
 if(blockAddr == superblock->firstFile)
 {
  superblock->firstFile = currentFile->nextFile;
 }
 if(blockAddr == superblock->lastFile)
 {
  superblock->lastFile = prevBlockAddr;
 }
 if(prevBlockAddr != -1)
 {
  iNodeTable[prevBlockAddr].nextFile = currentFile->nextFile;
 }
 while(blockAddr != -1)
 {
  currentFile->fileName[0] = '\0';
  currentFile->fileSize = 0;
  currentFile->nextFile = -1;
  iNodeTable[superblock->lastFree].nextBlock = blockAddr;
  superblock->lastFree = blockAddr;
  if(superblock->firstFree == -1)
  {
   superblock->firstFree = blockAddr;
  }
  blockAddr = currentFile->nextBlock;
  currentFile->nextBlock = -1;
  currentFile = &iNodeTable[blockAddr];
 }
 return 0;
}

variable_types: blockAddr int

variable_types: prevBlockAddr int

variable_types: struct INODE { char fileName[16]; int fileSize; int blockAddres; int nextBlock; int nextFile; } *


repo: pbasista/stc

decompiled_code:
__int64 __fastcall st_slli_bp_simulate_suffix_link_bottom_up(int *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // ecx
int v6; // er12
__int64 result; // rax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = a2;
if ( a2 )
{
v5 = a2 - 1;
if ( a2 > 0 )
v5 = *(_DWORD *)(*(_QWORD *)(a4 + 24) + 24LL * a2 + 12);
v6 = *a1;
v8[0] = v5;
*a1 = 0;
result = st_slli_bp_go_up(a1, v8, a3, a4);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -1 )
{
fwrite("Error: Suffix link simulation failed permanently!\n", 1uLL, 0x32uLL, stderr);
result = 2LL;
}
}
else
{
*(_DWORD *)(*(_QWORD *)(a4 + 24) + 24LL * v6 + 12) = *a1;
}
}
else
{
fwrite("Error: Invalid number of child (0)!\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // ecx
int v6; // er12
__int64 result; // rax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = a2;
if ( a2 )
{
v5 = a2 - 1;
if ( a2 > 0 )
v5 = *(_DWORD *)(*(_QWORD *)(a4 + 24) + 24LL * a2 + 12);
v6 = *a1;
v8[0] = v5;
*a1 = 0;
result = st_slli_bp_go_up(a1, v8, a3, a4);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -1 )
{
fwrite("Error: Suffix link simulation failed permanently!\n", 1uLL, 0x32uLL, stderr);
result = 2LL;
}
}
else
{
*(_DWORD *)(*(_QWORD *)(a4 + 24) + 24LL * v6 + 12) = *a1;
}
}
else
{
fwrite("Error: Invalid number of child (0)!\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int st_slli_bp_simulate_suffix_link_bottom_up (signed_integral_type *parent,
  signed_integral_type child,
  unsigned_integral_type target_depth,
  suffix_tree_slli_bp *stree) {
 signed_integral_type starting_from = (*parent);
 int tmp = 0;
 if (child == 0) {
  fprintf(stderr, "Error: Invalid number of child (0)!\n");
  return (1);
 } else if (child > 0) {
  child = stree->tbranch[child].suffix_link;
 } else {
  child = child - 1;
 }
 (*parent) = 0;
 if ((tmp = st_slli_bp_go_up(parent, &child, target_depth,
     stree)) == 0) {
  stree->tbranch[starting_from].suffix_link = (*parent);
  return (0);
 } else if (tmp == (-1)) {
  return (-1);
 } else {
  fprintf(stderr, "Error: Suffix link simulation "
    "failed permanently!\n");
  return (2);
 }
}

canonical_original_code:
int st_slli_bp_simulate_suffix_link_bottom_up(int *parent, int child, unsigned int target_depth, struct suffix_tree_slli_bp_struct *stree) {
 int starting_from = (*parent);
 int tmp = 0;
 if (child == 0) {
  fprintf(stderr, "Error: Invalid number of child (0)!\n");
  return (1);
 } else if (child > 0) {
  child = stree->tbranch[child].suffix_link;
 } else {
  child = child - 1;
 }
 (*parent) = 0;
 if ((tmp = st_slli_bp_go_up(parent, &child, target_depth,
     stree)) == 0) {
  stree->tbranch[starting_from].suffix_link = (*parent);
  return (0);
 } else if (tmp == (-1)) {
  return (-1);
 } else {
  fprintf(stderr, "Error: Suffix link simulation "
    "failed permanently!\n");
  return (2);
 }
}

variable_types:
parent
int *

variable_types: struct suffix_tree_slli_bp_struct { unsigned long lr_size; unsigned long br_size; struct leaf_record_slli_bp_struct { int parent; int next_brother; } *tleaf; struct branch_record_slli_bp_struct { int parent; int first_child; int branch_brother; int suffix_link; unsigned int depth; unsigned int head_position; } *tbranch; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; } *

variable_types: tmp int

user_defined_types: struct suffix_tree_slli_bp_struct { unsigned long lr_size; unsigned long br_size; struct leaf_record_slli_bp_struct *tleaf; struct branch_record_slli_bp_struct *tbranch; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; }


decompiled_code:
__int64 __fastcall st_slli_bp_mccreight_insert_suffix(int *a1, int *a2, _DWORD *a3, __int64 a4, __int64 a5, unsigned __int64 a6, _QWORD *a7)
{
unsigned __int64 v9; // rax
unsigned int v10; // eax
unsigned int v11; // ebp
int v13; // er13
__int64 v14; // rdx
int v15; // eax
__int64 v16; // rdx
__int64 v19; // [rsp+28h] [rbp-50h] BYREF
unsigned int v20; // [rsp+34h] [rbp-44h] BYREF
unsigned int v21; // [rsp+38h] [rbp-40h] BYREF
int v22[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v22[0] = 0;
v21 = 0;
v20 = 0;
v19 = a4 + *(unsigned int *)(a7[3] + 24LL * *a1 + 16);
v9 = a7[5];
if ( a7[4] == v9 && v9 < a6 && (int)st_slli_bp_reallocate(0LL, a6, a7) > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
v11 = 1;
}
else
{
while ( 1 )
{
v10 = st_slli_bp_branch_once((unsigned int)*a1, v22, &v21, v19, a5, a7);
v11 = v10;
if ( v10 )
{
if ( v10 == 1 )
{
fprintf(stderr, "Error: Insertion of the suffix number %zu failed!\n", a4);
v11 = 4;
}
else
{
if ( v10 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
*(_DWORD *)(a7[3] + 24LL * *a1 + 4) = -(int)a4;
*(_DWORD *)(a7[2] + 8 * a4) = *a1;
*(_DWORD *)(a7[2] + 8 * a4 + 4) = 0;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a1, (unsigned int)v22[0], v21, (unsigned int)-(int)a4, a7);
}
v11 = 0;
if ( *a1 > 1 )
*a1 = *(_DWORD *)(a7[3] + 24LL * *a1 + 12);
}
return v11;
}
if ( (unsigned int)st_slli_bp_edge_slowscan((unsigned int)*a1, (unsigned int)v22[0], v19, &v20, a5, a6 + 1, a7) )
break;
st_slli_bp_edge_descend(a1, v22, &v21, &v19, a6 + 1, a7);
if ( *a1 < 0 )
{
fwrite(
"Error: The newly inserted suffix already has the corresponding leaf node\npresent in the suffix tree!\n",
1uLL,
0x65uLL,
stderr);
return 2;
}
}
v13 = v22[0];
st_slli_bp_split_edge(a1, v22, &v21, &v19, v20, (unsigned int)a4, a7);
st_slli_bp_create_leaf((unsigned int)*a1, (unsigned int)v22[0], v21, (unsigned int)-(int)a4, a7);
v14 = (unsigned int)*a2;
if ( (_DWORD)v14 )
{
if ( a4 + (unsigned int)*a3 != v19 )
{
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v14);
return 3;
}
*(_DWORD *)(a7[3] + 24LL * (int)v14 + 12) = *a1;
}
v15 = *a1;
*a2 = *a1;
v16 = (unsigned int)(*(_DWORD *)(a7[3] + 24LL * v15 + 16) - 1);
*a3 = v16;
if ( !(unsigned int)st_slli_bp_simulate_suffix_link_bottom_up(a1, v13, v16, (__int64)a7) )
{
*a2 = 0;
*a3 = 0;
v11 = 0;
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, int *a2, _DWORD *a3, __int64 a4, __int64 a5, unsigned __int64 a6, _QWORD *a7)
{
unsigned __int64 v9; // rax
unsigned int v10; // eax
unsigned int v11; // ebp
int v13; // er13
__int64 v14; // rdx
int v15; // eax
__int64 v16; // rdx
__int64 v19; // [rsp+28h] [rbp-50h] BYREF
unsigned int v20; // [rsp+34h] [rbp-44h] BYREF
unsigned int v21; // [rsp+38h] [rbp-40h] BYREF
int v22[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v22[0] = 0;
v21 = 0;
v20 = 0;
v19 = a4 + *(unsigned int *)(a7[3] + 24LL * *a1 + 16);
v9 = a7[5];
if ( a7[4] == v9 && v9 < a6 && (int)st_slli_bp_reallocate(0LL, a6, a7) > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
v11 = 1;
}
else
{
while ( 1 )
{
v10 = st_slli_bp_branch_once((unsigned int)*a1, v22, &v21, v19, a5, a7);
v11 = v10;
if ( v10 )
{
if ( v10 == 1 )
{
fprintf(stderr, "Error: Insertion of the suffix number %zu failed!\n", a4);
v11 = 4;
}
else
{
if ( v10 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
*(_DWORD *)(a7[3] + 24LL * *a1 + 4) = -(int)a4;
*(_DWORD *)(a7[2] + 8 * a4) = *a1;
*(_DWORD *)(a7[2] + 8 * a4 + 4) = 0;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a1, (unsigned int)v22[0], v21, (unsigned int)-(int)a4, a7);
}
v11 = 0;
if ( *a1 > 1 )
*a1 = *(_DWORD *)(a7[3] + 24LL * *a1 + 12);
}
return v11;
}
if ( (unsigned int)st_slli_bp_edge_slowscan((unsigned int)*a1, (unsigned int)v22[0], v19, &v20, a5, a6 + 1, a7) )
break;
st_slli_bp_edge_descend(a1, v22, &v21, &v19, a6 + 1, a7);
if ( *a1 < 0 )
{
fwrite(
"Error: The newly inserted suffix already has the corresponding leaf node\npresent in the suffix tree!\n",
1uLL,
0x65uLL,
stderr);
return 2;
}
}
v13 = v22[0];
st_slli_bp_split_edge(a1, v22, &v21, &v19, v20, (unsigned int)a4, a7);
st_slli_bp_create_leaf((unsigned int)*a1, (unsigned int)v22[0], v21, (unsigned int)-(int)a4, a7);
v14 = (unsigned int)*a2;
if ( (_DWORD)v14 )
{
if ( a4 + (unsigned int)*a3 != v19 )
{
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v14);
return 3;
}
*(_DWORD *)(a7[3] + 24LL * (int)v14 + 12) = *a1;
}
v15 = *a1;
*a2 = *a1;
v16 = (unsigned int)(*(_DWORD *)(a7[3] + 24LL * v15 + 16) - 1);
*a3 = v16;
if ( !(unsigned int)func0(a1, v13, v16, (__int64)a7) )
{
*a2 = 0;
*a3 = 0;
v11 = 0;
}
}
return v11;
}

original_code:
int st_slli_bp_mccreight_insert_suffix (signed_integral_type *parent,
  signed_integral_type *sl_source,
  unsigned_integral_type *sl_targets_depth,
  size_t starting_position,
  const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type latest_child = 0;
 signed_integral_type child = 0;
 signed_integral_type prev_child = 0;
 signed_integral_type last_match_position = 0;
 size_t position = starting_position +
  stree->tbranch[(*parent)].depth;
 size_t tbranch_size = (size_t)(stree->tbranch_size);
 int tmp = 0;
 if ((tbranch_size == stree->branching_nodes) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate((size_t)(0), length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if (st_slli_bp_edge_slowscan((*parent), child, position,
   &last_match_position, text, length + 1, stree) == 0) {
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, length + 1, stree);
   if ((*parent) < 0) {
    fprintf(stderr, "Error: The newly inserted "
      "suffix already has the "
      "corresponding leaf node\n"
      "present in the "
      "suffix tree!\n");
    return (2);
   }
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (3);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Insertion of the suffix number "
    "%zu failed!\n", starting_position);
  return (4);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 return (0);
}

canonical_original_code:
int st_slli_bp_mccreight_insert_suffix(int *parent, int *sl_source, unsigned int *sl_targets_depth, unsigned long starting_position, char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int latest_child = 0;
 int child = 0;
 int prev_child = 0;
 int last_match_position = 0;
 unsigned long position = starting_position +
  stree->tbranch[(*parent)].depth;
 unsigned long tbranch_size = (size_t)(stree->tbranch_size);
 int tmp = 0;
 if ((tbranch_size == stree->branching_nodes) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate((unsigned long)(0), length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if (st_slli_bp_edge_slowscan((*parent), child, position,
   &last_match_position, text, length + 1, stree) == 0) {
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, length + 1, stree);
   if ((*parent) < 0) {
    fprintf(stderr, "Error: The newly inserted "
      "suffix already has the "
      "corresponding leaf node\n"
      "present in the "
      "suffix tree!\n");
    return (2);
   }
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (3);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Insertion of the suffix number "
    "%zu failed!\n", starting_position);
  return (4);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 return (0);
}

variable_types:
text
char *

variable_types:
length
unsigned long

variable_types: child int

variable_types:
position
unsigned long

user_defined_types: struct leaf_record_slli_bp_struct { int parent; int next_brother; }

user_defined_types: struct branch_record_slli_bp_struct { int parent; int first_child; int branch_brother; int suffix_link; unsigned int depth; unsigned int head_position; }


decompiled_code:
__int64 __fastcall st_slli_bp_ukkonen_prolong_suffix(__int64 a1, __int64 a2, __int64 *a3, int *a4, int *a5, _DWORD *a6, __int64 a7, __int64 a8)
{
unsigned int v9; // eax
unsigned int v10; // ebp
int v11; // eax
int v12; // ebp
int v14; // er13
__int64 v15; // rdx
int v16; // eax
__int64 v17; // rdx
__int64 v21; // [rsp+28h] [rbp-50h] BYREF
unsigned int v22; // [rsp+34h] [rbp-44h] BYREF
unsigned int v23; // [rsp+38h] [rbp-40h] BYREF
int v24[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v24[0] = 0;
v23 = 0;
v22 = 0;
v21 = *a3;
if ( a1 == a2 )
return (unsigned int)-1;
while ( 1 )
{
v9 = st_slli_bp_branch_once((unsigned int)*a4, v24, &v23, v21, a7, a8);
v10 = v9;
if ( v9 )
{
if ( v9 == 1 )
{
fprintf(stderr, "Error: Prolonging of the suffix number %zu to the length of %zu failed!\n", a1, a2 - a1);
v10 = 2;
}
else
{
if ( v9 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
*(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 4) = -(int)a1;
*(_DWORD *)(*(_QWORD *)(a8 + 16) + 8 * a1) = *a4;
*(_DWORD *)(*(_QWORD *)(a8 + 16) + 8 * a1 + 4) = 0;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a4, (unsigned int)v24[0], v23, (unsigned int)-(int)a1, a8);
}
if ( *a4 > 1 )
*a4 = *(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 12);
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
v10 = 0;
}
return v10;
}
v11 = st_slli_bp_edge_slowscan((unsigned int)*a4, (unsigned int)v24[0], v21, &v22, a7, a2 - 1, a8);
if ( v11 )
break;
v12 = *a4;
st_slli_bp_edge_descend(a4, v24, &v23, &v21, a2 - 1, a8);
if ( *a4 < 0 )
{
*a4 = v12;
if ( v12 != 1 )
*a4 = *(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * v12 + 12);
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
return (unsigned int)-2;
}
if ( a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) == a2 )
{
*a3 = a2;
return (unsigned int)-3;
}
}
if ( v11 == 2 )
{
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16);
return (unsigned int)-4;
}
v14 = v24[0];
st_slli_bp_split_edge(a4, v24, &v23, &v21, v22, (unsigned int)a1, a8);
st_slli_bp_create_leaf((unsigned int)*a4, (unsigned int)v24[0], v23, (unsigned int)-(int)a1, a8);
v15 = (unsigned int)*a5;
if ( (_DWORD)v15 )
{
if ( a1 + (unsigned int)*a6 != v21 )
{
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v15);
return 1;
}
*(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * (int)v15 + 12) = *a4;
}
v16 = *a4;
*a5 = *a4;
v17 = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * v16 + 16) - 1);
*a6 = v17;
if ( !(unsigned int)st_slli_bp_simulate_suffix_link_bottom_up(a4, v14, v17, a8) )
{
*a5 = 0;
*a6 = 0;
}
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 *a3, int *a4, int *a5, _DWORD *a6, __int64 a7, __int64 a8)
{
unsigned int v9; // eax
unsigned int v10; // ebp
int v11; // eax
int v12; // ebp
int v14; // er13
__int64 v15; // rdx
int v16; // eax
__int64 v17; // rdx
__int64 v21; // [rsp+28h] [rbp-50h] BYREF
unsigned int v22; // [rsp+34h] [rbp-44h] BYREF
unsigned int v23; // [rsp+38h] [rbp-40h] BYREF
int v24[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v24[0] = 0;
v23 = 0;
v22 = 0;
v21 = *a3;
if ( a1 == a2 )
return (unsigned int)-1;
while ( 1 )
{
v9 = st_slli_bp_branch_once((unsigned int)*a4, v24, &v23, v21, a7, a8);
v10 = v9;
if ( v9 )
{
if ( v9 == 1 )
{
fprintf(stderr, "Error: Prolonging of the suffix number %zu to the length of %zu failed!\n", a1, a2 - a1);
v10 = 2;
}
else
{
if ( v9 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
*(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 4) = -(int)a1;
*(_DWORD *)(*(_QWORD *)(a8 + 16) + 8 * a1) = *a4;
*(_DWORD *)(*(_QWORD *)(a8 + 16) + 8 * a1 + 4) = 0;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a4, (unsigned int)v24[0], v23, (unsigned int)-(int)a1, a8);
}
if ( *a4 > 1 )
*a4 = *(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 12);
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
v10 = 0;
}
return v10;
}
v11 = st_slli_bp_edge_slowscan((unsigned int)*a4, (unsigned int)v24[0], v21, &v22, a7, a2 - 1, a8);
if ( v11 )
break;
v12 = *a4;
st_slli_bp_edge_descend(a4, v24, &v23, &v21, a2 - 1, a8);
if ( *a4 < 0 )
{
*a4 = v12;
if ( v12 != 1 )
*a4 = *(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * v12 + 12);
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
return (unsigned int)-2;
}
if ( a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) == a2 )
{
*a3 = a2;
return (unsigned int)-3;
}
}
if ( v11 == 2 )
{
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16);
return (unsigned int)-4;
}
v14 = v24[0];
st_slli_bp_split_edge(a4, v24, &v23, &v21, v22, (unsigned int)a1, a8);
st_slli_bp_create_leaf((unsigned int)*a4, (unsigned int)v24[0], v23, (unsigned int)-(int)a1, a8);
v15 = (unsigned int)*a5;
if ( (_DWORD)v15 )
{
if ( a1 + (unsigned int)*a6 != v21 )
{
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v15);
return 1;
}
*(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * (int)v15 + 12) = *a4;
}
v16 = *a4;
*a5 = *a4;
v17 = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a8 + 24) + 24LL * v16 + 16) - 1);
*a6 = v17;
if ( !(unsigned int)func0(a4, v14, v17, a8) )
{
*a5 = 0;
*a6 = 0;
}
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
return v10;
}

original_code:
int st_slli_bp_ukkonen_prolong_suffix (size_t starting_position,
  size_t ending_position,
  size_t *active_index,
  signed_integral_type *parent,
  signed_integral_type *sl_source,
  unsigned_integral_type *sl_targets_depth,
  const character_type *text,
  suffix_tree_slli_bp *stree) {
 signed_integral_type latest_child = 0;
 signed_integral_type grandpa = 0;
 signed_integral_type child = 0;
 signed_integral_type prev_child = 0;
 signed_integral_type last_match_position = 0;
 size_t position = (*active_index);
 int tmp = 0;
 int slowscan_return = 0;
 if (starting_position == ending_position) {
  return (-1);
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if ((slowscan_return = st_slli_bp_edge_slowscan((*parent),
    child, position, &last_match_position, text,
    ending_position - 1, stree)) == 0) {
   grandpa = (*parent);
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, ending_position - 1, stree);
   if ((*parent) < 0) {
    (*parent) = grandpa;
    if ((*parent) != 1) {
     (*parent) = stree->tbranch[(*parent)].
      suffix_link;
    }
    (*active_index) = starting_position + 1 +
    (size_t)(stree->tbranch[(*parent)].depth);
    return (-2);
   } else if (starting_position +
     stree->tbranch[(*parent)].depth ==
     ending_position) {
    (*active_index) = starting_position +
     stree->tbranch[(*parent)].depth;
    return (-3);
   }
  } else if (slowscan_return == 2) {
   (*active_index) = starting_position +
    stree->tbranch[(*parent)].depth;
   return (-4);
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (1);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   (*active_index) = starting_position + 1 +
    stree->tbranch[(*parent)].depth;
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Prolonging of the suffix number "
    "%zu to the length of %zu failed!\n",
    starting_position,
    ending_position - starting_position);
  return (2);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 (*active_index) = starting_position + 1 +
  stree->tbranch[(*parent)].depth;
 return (0);
}

canonical_original_code:
int st_slli_bp_ukkonen_prolong_suffix(unsigned long starting_position, unsigned long ending_position, unsigned long *active_index, int *parent, int *sl_source, unsigned int *sl_targets_depth, char *text, struct suffix_tree_slli_bp_struct *stree) {
 int latest_child = 0;
 int grandpa = 0;
 int child = 0;
 int prev_child = 0;
 int last_match_position = 0;
 unsigned long position = (*active_index);
 int tmp = 0;
 int slowscan_return = 0;
 if (starting_position == ending_position) {
  return (-1);
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if ((slowscan_return = st_slli_bp_edge_slowscan((*parent),
    child, position, &last_match_position, text,
    ending_position - 1, stree)) == 0) {
   grandpa = (*parent);
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, ending_position - 1, stree);
   if ((*parent) < 0) {
    (*parent) = grandpa;
    if ((*parent) != 1) {
     (*parent) = stree->tbranch[(*parent)].
      suffix_link;
    }
    (*active_index) = starting_position + 1 +
    (unsigned long)(stree->tbranch[(*parent)].depth);
    return (-2);
   } else if (starting_position +
     stree->tbranch[(*parent)].depth ==
     ending_position) {
    (*active_index) = starting_position +
     stree->tbranch[(*parent)].depth;
    return (-3);
   }
  } else if (slowscan_return == 2) {
   (*active_index) = starting_position +
    stree->tbranch[(*parent)].depth;
   return (-4);
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (1);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   (*active_index) = starting_position + 1 +
    stree->tbranch[(*parent)].depth;
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Prolonging of the suffix number "
    "%zu to the length of %zu failed!\n",
    starting_position,
    ending_position - starting_position);
  return (2);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 (*active_index) = starting_position + 1 +
  stree->tbranch[(*parent)].depth;
 return (0);
}

variable_types: grandpa int


decompiled_code:
__int64 __fastcall st_slli_bp_ukkonen_prolong_suffixes(__int64 *a1, __int64 a2, __int64 *a3, int *a4, __int64 a5, unsigned __int64 a6, __int64 a7)
{
unsigned __int64 v11; // rdi
unsigned __int64 v12; // rax
unsigned int v13; // edx
int v14; // eax
__int64 v15; // rdi
int v17; // [rsp+8h] [rbp-40h] BYREF
int v18[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v18[0] = 0;
v17 = 0;
v11 = *(_QWORD *)(a7 + 32) + a2 - 1 - *a1;
v12 = a6;
if ( v11 <= a6 )
v12 = v11;
if ( v12 <= *(_QWORD *)(a7 + 40) || (int)st_slli_bp_reallocate(v11, a6, a7) <= 0 )
{
while ( 1 )
{
v14 = st_slli_bp_ukkonen_prolong_suffix(*a1, a2, a3, a4, v18, &v17, a5, a7);
if ( v14 != -1 )
break;
++*a1;
}
for ( ; !v14; v14 = st_slli_bp_ukkonen_prolong_suffix(v15, a2, a3, a4, v18, &v17, a5, a7) )
{
v15 = *a1 + 1;
*a1 = v15;
}
v13 = 0;
if ( v14 > 0 )
{
fprintf(stderr, "Error: Could not prolong suffixes to the ending position %zu!\n", a2);
v13 = 2;
}
}
else
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
v13 = 1;
}
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 a2, __int64 *a3, int *a4, __int64 a5, unsigned __int64 a6, __int64 a7)
{
unsigned __int64 v11; // rdi
unsigned __int64 v12; // rax
unsigned int v13; // edx
int v14; // eax
__int64 v15; // rdi
int v17; // [rsp+8h] [rbp-40h] BYREF
int v18[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v18[0] = 0;
v17 = 0;
v11 = *(_QWORD *)(a7 + 32) + a2 - 1 - *a1;
v12 = a6;
if ( v11 <= a6 )
v12 = v11;
if ( v12 <= *(_QWORD *)(a7 + 40) || (int)st_slli_bp_reallocate(v11, a6, a7) <= 0 )
{
while ( 1 )
{
v14 = func2(*a1, a2, a3, a4, v18, &v17, a5, a7);
if ( v14 != -1 )
break;
++*a1;
}
for ( ; !v14; v14 = func2(v15, a2, a3, a4, v18, &v17, a5, a7) )
{
v15 = *a1 + 1;
*a1 = v15;
}
v13 = 0;
if ( v14 > 0 )
{
fprintf(stderr, "Error: Could not prolong suffixes to the ending position %zu!\n", a2);
v13 = 2;
}
}
else
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
v13 = 1;
}
return v13;
}

original_code:
int st_slli_bp_ukkonen_prolong_suffixes (size_t *starting_position,
  size_t ending_position,
  size_t *active_index,
  signed_integral_type *active_node,
  const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type sl_source = 0;
 unsigned_integral_type sl_targets_depth = 0;
 size_t maximum_possible_size = stree->branching_nodes +
  ending_position - (*starting_position) - 1;
 int tmp = 0;
 size_t tbranch_size = (size_t)(stree->tbranch_size);
 if ((tbranch_size < maximum_possible_size) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate(maximum_possible_size,
     length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
     ending_position, active_index,
     active_node, &sl_source,
     &sl_targets_depth, text,
     stree)) == (-1)) {
  ++(*starting_position);
 }
 while (tmp == 0) {
  ++(*starting_position);
  tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
   ending_position, active_index, active_node, &sl_source,
   &sl_targets_depth, text, stree);
 }
 if (tmp > 0) {
  fprintf(stderr, "Error: Could not prolong suffixes "
    "to the ending position %zu!\n",
    ending_position);
  return (2);
 }
 return (0);
}

canonical_original_code:
int st_slli_bp_ukkonen_prolong_suffixes(unsigned long *starting_position, unsigned long ending_position, unsigned long *active_index, int *active_node, char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int sl_source = 0;
 unsigned int sl_targets_depth = 0;
 unsigned long maximum_possible_size = stree->branching_nodes +
  ending_position - (*starting_position) - 1;
 int tmp = 0;
 unsigned long tbranch_size = (size_t)(stree->tbranch_size);
 if ((tbranch_size < maximum_possible_size) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate(maximum_possible_size,
     length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
     ending_position, active_index,
     active_node, &sl_source,
     &sl_targets_depth, text,
     stree)) == (-1)) {
  ++(*starting_position);
 }
 while (tmp == 0) {
  ++(*starting_position);
  tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
   ending_position, active_index, active_node, &sl_source,
   &sl_targets_depth, text, stree);
 }
 if (tmp > 0) {
  fprintf(stderr, "Error: Could not prolong suffixes "
    "to the ending position %zu!\n",
    ending_position);
  return (2);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall st_slli_bp_create_mccreight(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v8[0] = 1;
v7 = 0;
v6 = 0;
puts("Creating suffix tree using McCright's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 1LL;
if ( a2 >= 0xFFFFFFFFFFFFFFFELL )
{
LABEL_5:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
else
{
while ( (int)st_slli_bp_mccreight_insert_suffix(v8, &v7, &v6, v4, a1, a2, a3) <= 0 )
{
if ( ++v4 == a2 + 2 )
goto LABEL_5;
}
fprintf(stderr, "Could not insert suffix number %zu. Exiting.\n", v4);
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v8[0] = 1;
v7 = 0;
v6 = 0;
puts("Creating suffix tree using McCright's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 1LL;
if ( a2 >= 0xFFFFFFFFFFFFFFFELL )
{
LABEL_5:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
else
{
while ( (int)func1(v8, &v7, &v6, v4, a1, a2, a3) <= 0 )
{
if ( ++v4 == a2 + 2 )
goto LABEL_5;
}
fprintf(stderr, "Could not insert suffix number %zu. Exiting.\n", v4);
result = 2LL;
}
}
return result;
}

original_code:
int st_slli_bp_create_mccreight (const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type starting_node = 1;
 signed_integral_type sl_source = 0;
 unsigned_integral_type sl_targets_depth = 0;
 size_t i = 1;
 printf("Creating suffix tree using McCright's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 1; i < length + 2; ++i) {
  if (st_slli_bp_mccreight_insert_suffix(&starting_node,
     &sl_source, &sl_targets_depth, i,
     text, length, stree) > 0) {
   fprintf(stderr, "Could not insert suffix number "
     "%zu. Exiting.\n", i);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (size_t)(0), stree->branching_nodes,
   (size_t)(0), (size_t)(0), stree->tbranch_size,
   (size_t)(0), stree->lr_size, (size_t)(0),
   stree->br_size, (size_t)(0),
   (size_t)(0), (size_t)(0));
 return (0);
}

canonical_original_code:
int st_slli_bp_create_mccreight(char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int starting_node = 1;
 int sl_source = 0;
 unsigned int sl_targets_depth = 0;
 unsigned long i = 1;
 printf("Creating suffix tree using McCright's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 1; i < length + 2; ++i) {
  if (st_slli_bp_mccreight_insert_suffix(&starting_node,
     &sl_source, &sl_targets_depth, i,
     text, length, stree) > 0) {
   fprintf(stderr, "Could not insert suffix number "
     "%zu. Exiting.\n", i);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (unsigned long)(0), stree->branching_nodes,
   (unsigned long)(0), (unsigned long)(0), stree->tbranch_size,
   (unsigned long)(0), stree->lr_size, (unsigned long)(0),
   stree->br_size, (unsigned long)(0),
   (unsigned long)(0), (unsigned long)(0));
 return (0);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall st_slli_bp_create_ukkonen(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
int v8[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v8[0] = 1;
v7 = 1LL;
v6 = 1LL;
puts("Creating suffix tree using Ukkonen's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 2LL;
if ( a2 >= 0xFFFFFFFFFFFFFFFELL )
{
LABEL_5:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
else
{
while ( (int)st_slli_bp_ukkonen_prolong_suffixes(&v6, v4, &v7, v8, a1, a2, (__int64)a3) <= 0 )
{
if ( ++v4 > a2 + 2 )
goto LABEL_5;
}
fprintf(stderr, "Could not create the intermediate tree number %zu. Exiting.\n", v4 - 1);
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
int v8[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v8[0] = 1;
v7 = 1LL;
v6 = 1LL;
puts("Creating suffix tree using Ukkonen's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 2LL;
if ( a2 >= 0xFFFFFFFFFFFFFFFELL )
{
LABEL_5:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
else
{
while ( (int)func3(&v6, v4, &v7, v8, a1, a2, (__int64)a3) <= 0 )
{
if ( ++v4 > a2 + 2 )
goto LABEL_5;
}
fprintf(stderr, "Could not create the intermediate tree number %zu. Exiting.\n", v4 - 1);
result = 2LL;
}
}
return result;
}

original_code:
int st_slli_bp_create_ukkonen (const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type active_node = 1;
 size_t active_index = 1;
 size_t starting_position = 1;
 size_t i = 1;
 printf("Creating suffix tree using Ukkonen's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 2; i <= length + 2; ++i) {
  if (st_slli_bp_ukkonen_prolong_suffixes(&starting_position, i,
     &active_index, &active_node, text,
     length, stree) > 0) {
   fprintf(stderr, "Could not create the intermediate "
     "tree number %zu. Exiting.\n", i - 1);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (size_t)(0), stree->branching_nodes,
   (size_t)(0), (size_t)(0), stree->tbranch_size,
   (size_t)(0), stree->lr_size, (size_t)(0),
   stree->br_size, (size_t)(0),
   (size_t)(0), (size_t)(0));
 return (0);
}

canonical_original_code:
int st_slli_bp_create_ukkonen(char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int active_node = 1;
 unsigned long active_index = 1;
 unsigned long starting_position = 1;
 unsigned long i = 1;
 printf("Creating suffix tree using Ukkonen's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 2; i <= length + 2; ++i) {
  if (st_slli_bp_ukkonen_prolong_suffixes(&starting_position, i,
     &active_index, &active_node, text,
     length, stree) > 0) {
   fprintf(stderr, "Could not create the intermediate "
     "tree number %zu. Exiting.\n", i - 1);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (unsigned long)(0), stree->branching_nodes,
   (unsigned long)(0), (unsigned long)(0), stree->tbranch_size,
   (unsigned long)(0), stree->lr_size, (unsigned long)(0),
   stree->br_size, (unsigned long)(0),
   (unsigned long)(0), (unsigned long)(0));
 return (0);
}


decompiled_code:
__int64 __fastcall st_shti_bp_simulate_suffix_link_bottom_up(int *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // ecx
int v6; // er12
__int64 result; // rax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = a2;
if ( a2 )
{
v5 = a2 - 1;
if ( a2 > 0 )
v5 = *(_DWORD *)(*(_QWORD *)(a4 + 72) + 16LL * a2 + 12);
v6 = *a1;
v8[0] = v5;
*a1 = 0;
result = st_shti_bp_go_up(a1, v8, a3, a4);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -1 )
{
fwrite("Error: Suffix link simulation failed permanently!\n", 1uLL, 0x32uLL, stderr);
result = 2LL;
}
}
else
{
*(_DWORD *)(*(_QWORD *)(a4 + 72) + 16LL * v6 + 12) = *a1;
}
}
else
{
fwrite("Error: Invalid number of child (0)!\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // ecx
int v6; // er12
__int64 result; // rax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = a2;
if ( a2 )
{
v5 = a2 - 1;
if ( a2 > 0 )
v5 = *(_DWORD *)(*(_QWORD *)(a4 + 72) + 16LL * a2 + 12);
v6 = *a1;
v8[0] = v5;
*a1 = 0;
result = st_shti_bp_go_up(a1, v8, a3, a4);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -1 )
{
fwrite("Error: Suffix link simulation failed permanently!\n", 1uLL, 0x32uLL, stderr);
result = 2LL;
}
}
else
{
*(_DWORD *)(*(_QWORD *)(a4 + 72) + 16LL * v6 + 12) = *a1;
}
}
else
{
fwrite("Error: Invalid number of child (0)!\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int st_shti_bp_simulate_suffix_link_bottom_up (signed_integral_type *parent,
  signed_integral_type child,
  unsigned_integral_type target_depth,
  suffix_tree_shti_bp *stree) {
 signed_integral_type starting_from = (*parent);
 int tmp = 0;
 if (child == 0) {
  fprintf(stderr, "Error: Invalid number of child (0)!\n");
  return (1);
 } else if (child > 0) {
  child = stree->tbranch[child].suffix_link;
 } else {
  child = child - 1;
 }
 (*parent) = 0;
 if ((tmp = st_shti_bp_go_up(parent, &child, target_depth,
     stree)) == 0) {
  stree->tbranch[starting_from].suffix_link = (*parent);
  return (0);
 } else if (tmp == (-1)) {
  return (-1);
 } else {
  fprintf(stderr, "Error: Suffix link simulation "
    "failed permanently!\n");
  return (2);
 }
}

canonical_original_code:
int st_shti_bp_simulate_suffix_link_bottom_up(int *parent, int child, unsigned int target_depth, struct suffix_tree_shti_bp_struct *stree) {
 int starting_from = (*parent);
 int tmp = 0;
 if (child == 0) {
  fprintf(stderr, "Error: Invalid number of child (0)!\n");
  return (1);
 } else if (child > 0) {
  child = stree->tbranch[child].suffix_link;
 } else {
  child = child - 1;
 }
 (*parent) = 0;
 if ((tmp = st_shti_bp_go_up(parent, &child, target_depth,
     stree)) == 0) {
  stree->tbranch[starting_from].suffix_link = (*parent);
  return (0);
 } else if (tmp == (-1)) {
  return (-1);
 } else {
  fprintf(stderr, "Error: Suffix link simulation "
    "failed permanently!\n");
  return (2);
 }
}

variable_types: struct suffix_tree_shti_bp_struct { unsigned long hs_size; unsigned long lr_size; unsigned long er_size; unsigned long br_size; int crt_type; unsigned long chf_number; struct hash_settings_struct { int crt_type; unsigned int phf_max; unsigned int shf_max; unsigned long chf_number; unsigned int npu_size; unsigned int *chf_as; unsigned int *chf_bs; unsigned long *cp_offsets; unsigned long *cp_sizes; unsigned long allocated_size; } *hs; struct leaf_record_shti_bp_struct { int parent; } *tleaf; struct edge_record_struct { int source_node; int target_node; } *tedge; struct branch_record_shti_bp_struct { int parent; unsigned int depth; unsigned int head_position; int suffix_link; } *tbranch; unsigned long edges; unsigned long tedge_size; unsigned long tesize_increase; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; } *

user_defined_types: struct suffix_tree_shti_bp_struct { unsigned long hs_size; unsigned long lr_size; unsigned long er_size; unsigned long br_size; int crt_type; unsigned long chf_number; struct hash_settings_struct *hs; struct leaf_record_shti_bp_struct *tleaf; struct edge_record_struct *tedge; struct branch_record_shti_bp_struct *tbranch; unsigned long edges; unsigned long tedge_size; unsigned long tesize_increase; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; }