concatenateSoundArray

decompiled_code:
__int64 __fastcall concatenateSoundArray(__int64 a1, _QWORD *a2, int a3)
{
int v4; // ebx
__int64 result; // rax
_QWORD *v6; // rbx
__int64 *v7; // rbx

convertToFileType(*(unsigned int *)(a1 + 8), *a2);
v4 = *(_DWORD *)(a1 + 8);
result = deepCopySound(a1, *a2);
*(_DWORD *)(a1 + 8) = v4;
if ( a3 > 0 )
{
v6 = a2;
do
result = convertToFileType(*(unsigned int *)(a1 + 8), *v6++);
while ( v6 != &a2[(unsigned int)(a3 - 1) + 1] );
}
if ( a3 > 1 )
{
v7 = a2 + 1;
do
result = concatenateSounds(a1, *v7++);
while ( v7 != &a2[(unsigned int)(a3 - 2) + 2] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2, int a3)
{
int v4; // ebx
__int64 result; // rax
_QWORD *v6; // rbx
__int64 *v7; // rbx

convertToFileType(*(unsigned int *)(a1 + 8), *a2);
v4 = *(_DWORD *)(a1 + 8);
result = deepCopySound(a1, *a2);
*(_DWORD *)(a1 + 8) = v4;
if ( a3 > 0 )
{
v6 = a2;
do
result = convertToFileType(*(unsigned int *)(a1 + 8), *v6++);
while ( v6 != &a2[(unsigned int)(a3 - 1) + 1] );
}
if ( a3 > 1 )
{
v7 = a2 + 1;
do
result = func3(a1, *v7++);
while ( v7 != &a2[(unsigned int)(a3 - 2) + 2] );
}
return result;
}

original_code:
void concatenateSoundArray(sound_t* dest, sound_t** sounds, int numSounds) {
  int i;
  fileType_t oldType;
  convertToFileType(dest->fileType, sounds[0]);
  oldType = dest->fileType;
  deepCopySound(dest, sounds[0]);
  dest->fileType = oldType;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  for(i = 1; i < numSounds; i++) {
    concatenateSounds(dest, sounds[i], dest->fileType);
  }
}

canonical_original_code:
void concatenateSoundArray(struct sound_t *dest, struct sound_t **sounds, int numSounds) {
  int i;
  enum fileType_t oldType;
  convertToFileType(dest->fileType, sounds[0]);
  oldType = dest->fileType;
  deepCopySound(dest, sounds[0]);
  dest->fileType = oldType;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  for(i = 1; i < numSounds; i++) {
    concatenateSounds(dest, sounds[i], dest->fileType);
  }
}

variable_types:
sounds
struct sound_t **

variable_types: numSounds int

variable_types:
oldType
enum fileType_t { CS229=0, WAVE=1 }


printHelp

repo: alexpogue/soundutils

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Sndcat Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,");
puts("and writes the result to a file (default:stdout , see -o option). Outputs in the");
puts("requested format (default:CS229, see -w option)\n");
puts("Defaults:");
puts("Default output file type is CS229 (see -w option)");
puts("Default output file is stdout unless another file is provided with -o.");
puts("If no source file(s) are provided by the arguments, input is read from stdin.");
puts("If only one source file is provided, the file is rewritten as-is in the desired");
puts("format. (useful for converting between formats)\n");
puts("Options:");
puts("-h\t\tdisplays this help page");
puts("-o [file]\toutput to a file rather than standard out");
return puts("-w\t\toutput in the WAVE format rather than CS229");
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
puts("Sndcat Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,");
puts("and writes the result to a file (default:stdout , see -o option). Outputs in the");
puts("requested format (default:CS229, see -w option)\n");
puts("Defaults:");
puts("Default output file type is CS229 (see -w option)");
puts("Default output file is stdout unless another file is provided with -o.");
puts("If no source file(s) are provided by the arguments, input is read from stdin.");
puts("If only one source file is provided, the file is rewritten as-is in the desired");
puts("format. (useful for converting between formats)\n");
puts("Options:");
puts("-h\t\tdisplays this help page");
puts("-o [file]\toutput to a file rather than standard out");
return puts("-w\t\toutput in the WAVE format rather than CS229");
}

original_code:
void printHelp(char* cmd) {
  printf("Sndcat Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,\n");
  printf("and writes the result to a file (default:stdout , see -o option). Outputs in the\n");
  printf("requested format (default:CS229, see -w option)\n\n");
  printf("Defaults:\n");
  printf("Default output file type is CS229 (see -w option)\n");
  printf("Default output file is stdout unless another file is provided with -o.\n");
  printf("If no source file(s) are provided by the arguments, input is read from stdin.\n");
  printf("If only one source file is provided, the file is rewritten as-is in the desired\n");
  printf("format. (useful for converting between formats)\n\n");
  printf("Options:\n");
  printf("-h\t\tdisplays this help page\n");
  printf("-o [file]\toutput to a file rather than standard out\n");
  printf("-w\t\toutput in the WAVE format rather than CS229\n");
}

canonical_original_code:
void printHelp(char *cmd) {
  printf("Sndcat Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the CS229/WAVE file(s) passed as arguments, concatenates them,\n");
  printf("and writes the result to a file (default:stdout , see -o option). Outputs in the\n");
  printf("requested format (default:CS229, see -w option)\n\n");
  printf("Defaults:\n");
  printf("Default output file type is CS229 (see -w option)\n");
  printf("Default output file is stdout unless another file is provided with -o.\n");
  printf("If no source file(s) are provided by the arguments, input is read from stdin.\n");
  printf("If only one source file is provided, the file is rewritten as-is in the desired\n");
  printf("format. (useful for converting between formats)\n\n");
  printf("Options:\n");
  printf("-h\t\tdisplays this help page\n");
  printf("-o [file]\toutput to a file rather than standard out\n");
  printf("-w\t\toutput in the WAVE format rather than CS229\n");
}

variable_types:
cmd
char *

return_type: void


handleCommandLineArgs

decompiled_code:
__int64 __fastcall handleCommandLineArgs(int a1, const char **a2, __int64 a3, __int64 a4, _DWORD *a5, _QWORD *a6)
{
unsigned int v9; // ebp
int v10; // eax
int v12; // edx
__int64 v13; // rdx
const char **v14; // rcx
const char *v15; // rsi
char v16; // cl

if ( a1 <= 1 )
return 0;
v9 = 0;
v10 = 1;
while ( 1 )
{
v13 = v10;
v14 = &a2[v13];
v15 = a2[v13];
if ( *v15 != 45 )
{
v12 = (*a5)++;
*(_QWORD *)(a3 + 8LL * v12) = *v14;
goto LABEL_8;
}
v16 = v15[1];
if ( v16 == 104 )
{
printHelp(*a2);
*a5 = -1;
return v9;
}
if ( v16 != 111 )
break;
*a6 = a2[v13 + 1];
++v10;
LABEL_8:
if ( a1 <= ++v10 )
return v9;
}
if ( v16 == 119 )
{
v9 = 1;
goto LABEL_8;
}
printInvalidOptionError((unsigned int)v16);
*a5 = -1;
return v9;
}

original_code:
fileType_t handleCommandLineArgs(int argc, char** argv, char** fileNames, int capacity, int* numFilesRead, char** outputFileName) {
  int i;
  fileType_t outputType = CS229;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

canonical_original_code:
enum fileType_t handleCommandLineArgs(int argc, char **argv, char **fileNames, int capacity, int *numFilesRead, char **outputFileName) {
  int i;
  enum fileType_t outputType = CS229;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fileNames
char **

variable_types: capacity int

variable_types:
numFilesRead
int *

variable_types:
outputFileName
char **

variable_types: i int

variable_types:
outputType
enum fileType_t { CS229=0, WAVE=1 }

return_type: enum fileType_t { CS229=0, WAVE=1 }


wavToSound

original_code:
void wavToSound(wavData_t* wd, sound_t* sound) {
  sound->sampleRate = wd->sampleRate;
  sound->bitDepth = wd->bitDepth;
  sound->numChannels = wd->numChannels;
  sound->dataSize = wd->dataChunkSize;
  sound->error = wd->error;
  sound->rawData = wd->data;
}

canonical_original_code:
void wavToSound(struct wavData_t *wd, struct sound_t *sound) {
  sound->sampleRate = wd->sampleRate;
  sound->bitDepth = wd->bitDepth;
  sound->numChannels = wd->numChannels;
  sound->dataSize = wd->dataChunkSize;
  sound->error = wd->error;
  sound->rawData = wd->data;
}

variable_types: struct wavData_t { void *data; enum chunkId_t { CHUNK_UNKNOWN=0, CHUNK_FMT=1, CHUNK_DATA=2 } currentChunkId; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned int numBytesInChunk; unsigned int sampleRate; unsigned int byteRate; unsigned int dataChunkSize; unsigned short audioFormat; unsigned short numChannels; unsigned short blockAlign; unsigned short bitDepth; } *

variable_types: struct sound_t { unsigned long sampleRate; enum fileType_t { CS229=0, WAVE=1 } fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned short numChannels; unsigned short bitDepth; } *

user_defined_types: struct wavData_t { void *data; enum chunkId_t currentChunkId; enum readError_t error; unsigned int numBytesInChunk; unsigned int sampleRate; unsigned int byteRate; unsigned int dataChunkSize; unsigned short audioFormat; unsigned short numChannels; unsigned short blockAlign; unsigned short bitDepth; }

user_defined_types: struct sound_t { unsigned long sampleRate; enum fileType_t fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t error; unsigned short numChannels; unsigned short bitDepth; }


PrintOutput

decompiled_code:
__int64 __fastcall PrintOutput(char *s)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
ctime_r(&timer, s);
s[strlen(s) - 1] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
ctime_r(&timer, s);
s[strlen(s) - 1] = 0;
return 0LL;
}

original_code:
int PrintOutput(char *string){
 time_t ltime;
  time(&ltime);
  ctime_r(&ltime,string);
  string[strlen(string)-1]='\0';
  return 0;
}

canonical_original_code:
int PrintOutput(char *string){
 long ltime;
  time(&ltime);
  ctime_r(&ltime,string);
  string[strlen(string)-1]='\0';
  return 0;
}

variable_types:
string
char *

variable_types: ltime long

return_type: int


CoreRemove

decompiled_code:
__int64 __fastcall CoreRemove(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r13
int v3; // eax
unsigned int v4; // ebx

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
goto LABEL_13;
v3 = GetElementMatrix(a1->__align, a2);
v4 = v3;
if ( v3 == -1 )
{
puts("Get Element Matrix Problem");
if ( !sem_post(v2) )
return v4;
LABEL_25:
perror("sem post");
return v4;
}
if ( v3 <= 0 )
{
v4 = 1;
if ( !sem_post(v2) )
return v4;
goto LABEL_12;
}
if ( (unsigned int)RemoveMatrix(a1->__align, a2) == -1 )
{
puts("RemoveMatrix Problem");
v4 = -1;
if ( !sem_post(v2) )
return v4;
goto LABEL_25;
}
if ( sem_post(v2) )
goto LABEL_12;
if ( sem_wait(a1 + 2) )
goto LABEL_13;
v4 = DeleteNeedle(*((unsigned int *)&a1->__align + 5), v4);
if ( v4 == -1 )
{
puts("DeleteNeedle Problem");
if ( !sem_post(a1 + 2) )
return v4;
goto LABEL_25;
}
if ( sem_post(a1 + 2) )
goto LABEL_12;
if ( sem_wait(a1 + 4) )
{
LABEL_13:
perror("sem wait");
return (unsigned int)-1;
}
v4 = QueueAdd(*(&a1->__align + 1), a2);
if ( v4 == -1 )
{
puts("QueueAdd Problem");
if ( !sem_post(a1 + 4) )
return v4;
goto LABEL_25;
}
v4 = sem_post(a1 + 4);
if ( v4 )
{
LABEL_12:
perror("sem post");
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r13
int v3; // eax
unsigned int v4; // ebx

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
goto LABEL_13;
v3 = GetElementMatrix(a1->__align, a2);
v4 = v3;
if ( v3 == -1 )
{
puts("Get Element Matrix Problem");
if ( !sem_post(v2) )
return v4;
LABEL_25:
perror("sem post");
return v4;
}
if ( v3 <= 0 )
{
v4 = 1;
if ( !sem_post(v2) )
return v4;
goto LABEL_12;
}
if ( (unsigned int)RemoveMatrix(a1->__align, a2) == -1 )
{
puts("RemoveMatrix Problem");
v4 = -1;
if ( !sem_post(v2) )
return v4;
goto LABEL_25;
}
if ( sem_post(v2) )
goto LABEL_12;
if ( sem_wait(a1 + 2) )
goto LABEL_13;
v4 = DeleteNeedle(*((unsigned int *)&a1->__align + 5), v4);
if ( v4 == -1 )
{
puts("DeleteNeedle Problem");
if ( !sem_post(a1 + 2) )
return v4;
goto LABEL_25;
}
if ( sem_post(a1 + 2) )
goto LABEL_12;
if ( sem_wait(a1 + 4) )
{
LABEL_13:
perror("sem wait");
return (unsigned int)-1;
}
v4 = QueueAdd(*(&a1->__align + 1), a2);
if ( v4 == -1 )
{
puts("QueueAdd Problem");
if ( !sem_post(a1 + 4) )
return v4;
goto LABEL_25;
}
v4 = sem_post(a1 + 4);
if ( v4 )
{
LABEL_12:
perror("sem post");
v4 = -1;
}
return v4;
}

original_code:
int CoreRemove(CorePtr Core,int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  printf("Get Element Matrix Problem\n");
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  return -1;
 }
 if(Offset>0)
  if(RemoveMatrix(Core->Matrix,Id)==-1){
   printf("RemoveMatrix Problem\n");
   if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
   return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  if(sem_wait(& ((Core)->Sem_File))){perror("sem wait"); return -1;}
  if(DeleteNeedle((Core)->Fd, Offset)==-1){
   printf("DeleteNeedle Problem\n");
   if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Queue)){perror("sem wait"); return -1;}
  if(QueueAdd(Core->Queue,Id)==-1){
   printf("QueueAdd Problem\n");
   if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return 0;
 }
 else{
  return 1;
 }
}

canonical_original_code:
int CoreRemove(struct Core *Core, int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  printf("Get Element Matrix Problem\n");
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  return -1;
 }
 if(Offset>0)
  if(RemoveMatrix(Core->Matrix,Id)==-1){
   printf("RemoveMatrix Problem\n");
   if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
   return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  if(sem_wait(& ((Core)->Sem_File))){perror("sem wait"); return -1;}
  if(DeleteNeedle((Core)->Fd, Offset)==-1){
   printf("DeleteNeedle Problem\n");
   if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& ((Core)->Sem_File))){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Queue)){perror("sem wait"); return -1;}
  if(QueueAdd(Core->Queue,Id)==-1){
   printf("QueueAdd Problem\n");
   if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
   return -1;
  }
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return 0;
 }
 else{
  return 1;
 }
}

variable_types: struct Core { struct Matrix { int *Table; int Size; } *Matrix; struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } *Queue; int Id; int Fd; int Total_Threads; union sem_t { char __size[32]; long __align; } Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; } *

variable_types: Id int

variable_types: Offset int

user_defined_types: struct Core { struct Matrix *Matrix; struct Queue *Queue; int Id; int Fd; int Total_Threads; union sem_t Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; }

user_defined_types: struct Queue { struct Node *Start; struct Node *End; }


CoreExists

decompiled_code:
__int64 __fastcall CoreExists(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r12
int v3; // ebx

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
{
perror("sem wait");
v3 = -1;
}
else
{
v3 = GetElementMatrix(a1->__align, a2);
if ( v3 == -1 )
{
if ( sem_post(v2) )
perror("sem post");
else
puts("Get Element Matrix Problem");
}
else if ( sem_post(v2) )
{
perror("sem post");
v3 = -1;
}
else if ( v3 < 0 )
{
v3 = 0;
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(sem_t *a1, unsigned int a2)
{
sem_t *v2; // r12
int v3; // ebx

v2 = a1 + 3;
if ( sem_wait(a1 + 3) )
{
perror("sem wait");
v3 = -1;
}
else
{
v3 = GetElementMatrix(a1->__align, a2);
if ( v3 == -1 )
{
if ( sem_post(v2) )
perror("sem post");
else
puts("Get Element Matrix Problem");
}
else if ( sem_post(v2) )
{
perror("sem post");
v3 = -1;
}
else if ( v3 < 0 )
{
v3 = 0;
}
}
return (unsigned int)v3;
}

original_code:
int CoreExists(CorePtr Core,int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  printf("Get Element Matrix Problem\n");
  return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  return Offset;
 }
 else{
  return 0;
 }
}

canonical_original_code:
int CoreExists(struct Core *Core, int Id){
 int Offset;
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if( (Offset=GetElementMatrix(Core->Matrix,Id))==-1){
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  printf("Get Element Matrix Problem\n");
  return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 if(Offset>0){
  return Offset;
 }
 else{
  return 0;
 }
}

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct Node { int Element; struct Node *Next; }


CoreInitiate

decompiled_code:
__int64 __fastcall CoreInitiate(sem_t **a1, unsigned int a2, __int64 a3)
{
sem_t *v5; // rdi
unsigned int v6; // ebp

if ( !a3 )
return (unsigned int)-1;
v5 = (sem_t *)malloc(0xC8uLL);
*a1 = v5;
if ( v5 )
{
if ( (unsigned int)InitiateMatrix(v5, a2) )
{
puts("Init Matrix Problem");
v6 = -1;
}
else if ( (unsigned int)QueueInitiate(&(*a1)->__align + 1) )
{
puts("Init Queue Problem");
v6 = -1;
}
else
{
*((_DWORD *)&(*a1)->__align + 4) = 0;
v6 = InitializeHayStack(a3, *a1);
if ( v6 == -1 )
{
puts("Init HayStack Problem");
}
else
{
*(__int64 *)((char *)&(*a1)->__align + 20) = v6;
*(_DWORD *)(*a1)[6].__size = 0;
if ( sem_init(*a1 + 1, 0, 1u)
|| sem_init(*a1 + 2, 0, 1u)
|| sem_init(*a1 + 3, 0, 1u)
|| sem_init(*a1 + 4, 0, 1u)
|| (v6 = sem_init(*a1 + 5, 0, 1u)) != 0 )
{
perror("Sem Init");
v6 = -1;
}
}
}
}
else
{
perror("Core malloc");
v6 = -1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(sem_t **a1, unsigned int a2, __int64 a3)
{
sem_t *v5; // rdi
unsigned int v6; // ebp

if ( !a3 )
return (unsigned int)-1;
v5 = (sem_t *)malloc(0xC8uLL);
*a1 = v5;
if ( v5 )
{
if ( (unsigned int)InitiateMatrix(v5, a2) )
{
puts("Init Matrix Problem");
v6 = -1;
}
else if ( (unsigned int)QueueInitiate(&(*a1)->__align + 1) )
{
puts("Init Queue Problem");
v6 = -1;
}
else
{
*((_DWORD *)&(*a1)->__align + 4) = 0;
v6 = InitializeHayStack(a3, *a1);
if ( v6 == -1 )
{
puts("Init HayStack Problem");
}
else
{
*(__int64 *)((char *)&(*a1)->__align + 20) = v6;
*(_DWORD *)(*a1)[6].__size = 0;
if ( sem_init(*a1 + 1, 0, 1u)
|| sem_init(*a1 + 2, 0, 1u)
|| sem_init(*a1 + 3, 0, 1u)
|| sem_init(*a1 + 4, 0, 1u)
|| (v6 = sem_init(*a1 + 5, 0, 1u)) != 0 )
{
perror("Sem Init");
v6 = -1;
}
}
}
}
else
{
perror("Core malloc");
v6 = -1;
}
return v6;
}

original_code:
int CoreInitiate(CorePtr *Core,int Size,char* WorkFile){
 int Fd;
 if(WorkFile==((void *)0))
  return -1;
 if(((*Core)=malloc(sizeof(struct Core)))==((void *)0)){perror("Core malloc");return -1;}
 if(InitiateMatrix(&((*Core)->Matrix),Size)!=0){printf("Init Matrix Problem\n");return -1;}
 if(QueueInitiate(&((*Core)->Queue))!=0){printf("Init Queue Problem\n");return -1;}
 (*Core)->Id=0;
 if( (Fd=InitializeHayStack( WorkFile,*Core))==-1){printf("Init HayStack Problem\n");return -1;}
 (*Core)->Fd=Fd;
 (*Core)->Total_Threads=0;
 (*Core)->TerminationFlag=0;
 if( sem_init (& ((*Core)->Sem_Total) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_File) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Matrix) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Queue) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Id) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 return 0;
}

canonical_original_code:
int CoreInitiate(struct Core **Core, int Size, char *WorkFile){
 int Fd;
 if(WorkFile==((void *)0))
  return -1;
 if(((*Core)=malloc(sizeof(struct Core)))==((void *)0)){perror("Core malloc");return -1;}
 if(InitiateMatrix(&((*Core)->Matrix),Size)!=0){printf("Init Matrix Problem\n");return -1;}
 if(QueueInitiate(&((*Core)->Queue))!=0){printf("Init Queue Problem\n");return -1;}
 (*Core)->Id=0;
 if( (Fd=InitializeHayStack( WorkFile,*Core))==-1){printf("Init HayStack Problem\n");return -1;}
 (*Core)->Fd=Fd;
 (*Core)->Total_Threads=0;
 (*Core)->TerminationFlag=0;
 if( sem_init (& ((*Core)->Sem_Total) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_File) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Matrix) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Queue) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 if( sem_init (& ((*Core)->Sem_Id) ,0 ,1)!=0){ perror("Sem Init"); return -1; }
 return 0;
}

variable_types: struct Core { struct Matrix { int *Table; int Size; } *Matrix; struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } *Queue; int Id; int Fd; int Total_Threads; union sem_t { char __size[32]; long __align; } Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; } **

variable_types: Size int

variable_types:
WorkFile
char *

variable_types: Fd int


CoreDelete

decompiled_code:
__int64 __fastcall CoreDelete(sem_t **a1)
{
unsigned int v1; // ebx

if ( *a1 )
{
v1 = DeleteMatrix();
if ( v1 == -1 )
{
puts("Delete Matrix Problem");
return v1;
}
v1 = QueueDelete(&(*a1)->__align + 1);
if ( v1 == -1 )
{
puts("Delete Queue Problem");
return v1;
}
v1 = close(*((_DWORD *)&(*a1)->__align + 5));
if ( v1 == -1 )
{
perror("close");
return v1;
}
v1 = sem_destroy(*a1 + 2);
if ( v1 == -1
|| (v1 = sem_destroy(*a1 + 3), v1 == -1)
|| (v1 = sem_destroy(*a1 + 4), v1 == -1)
|| (v1 = sem_destroy(*a1 + 5), v1 == -1) )
{
perror("Sem Dest");
return v1;
}
free(*a1);
}
*a1 = 0LL;
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func4(sem_t **a1)
{
unsigned int v1; // ebx

if ( *a1 )
{
v1 = DeleteMatrix();
if ( v1 == -1 )
{
puts("Delete Matrix Problem");
return v1;
}
v1 = QueueDelete(&(*a1)->__align + 1);
if ( v1 == -1 )
{
puts("Delete Queue Problem");
return v1;
}
v1 = close(*((_DWORD *)&(*a1)->__align + 5));
if ( v1 == -1 )
{
perror("close");
return v1;
}
v1 = sem_destroy(*a1 + 2);
if ( v1 == -1
|| (v1 = sem_destroy(*a1 + 3), v1 == -1)
|| (v1 = sem_destroy(*a1 + 4), v1 == -1)
|| (v1 = sem_destroy(*a1 + 5), v1 == -1) )
{
perror("Sem Dest");
return v1;
}
free(*a1);
}
*a1 = 0LL;
return 0;
}

original_code:
int CoreDelete(CorePtr *Core){
 if((*Core)!=((void *)0)){
  if(DeleteMatrix(& ((*Core)->Matrix))==-1){printf("Delete Matrix Problem\n");return -1;}
  if(QueueDelete(& ((*Core)->Queue))==-1){printf("Delete Queue Problem\n");return -1;}
  if(close((*Core)->Fd)==-1){perror("close");return -1;}
  if(sem_destroy (& ((*Core)->Sem_File) )==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Matrix))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Queue))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Id) )==-1){ perror("Sem Dest"); return -1; }
  free(*Core);
 }
 *Core=((void *)0);
 return 0;
}

canonical_original_code:
int CoreDelete(struct Core **Core){
 if((*Core)!=((void *)0)){
  if(DeleteMatrix(& ((*Core)->Matrix))==-1){printf("Delete Matrix Problem\n");return -1;}
  if(QueueDelete(& ((*Core)->Queue))==-1){printf("Delete Queue Problem\n");return -1;}
  if(close((*Core)->Fd)==-1){perror("close");return -1;}
  if(sem_destroy (& ((*Core)->Sem_File) )==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Matrix))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Queue))==-1){ perror("Sem Dest"); return -1; }
  if(sem_destroy (& ((*Core)->Sem_Id) )==-1){ perror("Sem Dest"); return -1; }
  free(*Core);
 }
 *Core=((void *)0);
 return 0;
}


CorePrint

decompiled_code:
__int64 __fastcall CorePrint(__int64 a1)
{
unsigned int v1; // ebx

puts("Printing Core:");
v1 = 0;
if ( !a1 )
return v1;
if ( sem_wait((sem_t *)(a1 + 128)) )
goto LABEL_10;
v1 = QueuePrint(*(_QWORD *)(a1 + 8));
if ( v1 == -1 )
{
LABEL_11:
puts("Get Element Matrix Problem");
return v1;
}
if ( sem_post((sem_t *)(a1 + 128)) )
goto LABEL_8;
if ( sem_wait((sem_t *)(a1 + 96)) )
{
LABEL_10:
perror("sem wait");
return (unsigned int)-1;
}
v1 = PrintMatrix(*(_QWORD *)a1);
if ( v1 == -1 )
goto LABEL_11;
v1 = sem_post((sem_t *)(a1 + 96));
if ( v1 )
{
LABEL_8:
perror("sem post");
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // ebx

puts("Printing Core:");
v1 = 0;
if ( !a1 )
return v1;
if ( sem_wait((sem_t *)(a1 + 128)) )
goto LABEL_10;
v1 = QueuePrint(*(_QWORD *)(a1 + 8));
if ( v1 == -1 )
{
LABEL_11:
puts("Get Element Matrix Problem");
return v1;
}
if ( sem_post((sem_t *)(a1 + 128)) )
goto LABEL_8;
if ( sem_wait((sem_t *)(a1 + 96)) )
{
LABEL_10:
perror("sem wait");
return (unsigned int)-1;
}
v1 = PrintMatrix(*(_QWORD *)a1);
if ( v1 == -1 )
goto LABEL_11;
v1 = sem_post((sem_t *)(a1 + 96));
if ( v1 )
{
LABEL_8:
perror("sem post");
v1 = -1;
}
return v1;
}

original_code:
int CorePrint(CorePtr Core){
 printf("Printing Core:\n");
 if(Core!=((void *)0)){
  if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
  if(QueuePrint(Core->Queue)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
  if(PrintMatrix(Core->Matrix)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 }
 return 0;
}

canonical_original_code:
int CorePrint(struct Core *Core){
 printf("Printing Core:\n");
 if(Core!=((void *)0)){
  if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
  if(QueuePrint(Core->Queue)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
  if(PrintMatrix(Core->Matrix)==-1){printf("Get Element Matrix Problem\n");return -1;}
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 }
 return 0;
}


CoreGetId

decompiled_code:
__int64 __fastcall CoreGetId(__int64 a1)
{
sem_t *v1; // r12
unsigned int v2; // ebp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a1 )
{
v1 = (sem_t *)(a1 + 128);
if ( sem_wait((sem_t *)(a1 + 128)) )
{
perror("sem wait");
v2 = -1;
}
else
{
v2 = QueueRemoveHead(*(_QWORD *)(a1 + 8), v4);
if ( v2 == -1 )
{
puts("QueueRemoveH Problem");
if ( sem_post(v1) )
perror("sem post");
}
else
{
if ( sem_post(v1) )
goto LABEL_15;
if ( v2 != 1 )
goto LABEL_6;
if ( sem_wait((sem_t *)(a1 + 160)) )
{
perror("sem wait");
return (unsigned int)-1;
}
v4[0] = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v4[0] + 1;
if ( sem_post((sem_t *)(a1 + 160)) )
{
LABEL_15:
perror("sem post");
v2 = -1;
}
else
{
LABEL_6:
v2 = v4[0];
}
}
}
}
else
{
puts("Core NUll");
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
sem_t *v1; // r12
unsigned int v2; // ebp
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a1 )
{
v1 = (sem_t *)(a1 + 128);
if ( sem_wait((sem_t *)(a1 + 128)) )
{
perror("sem wait");
v2 = -1;
}
else
{
v2 = QueueRemoveHead(*(_QWORD *)(a1 + 8), v4);
if ( v2 == -1 )
{
puts("QueueRemoveH Problem");
if ( sem_post(v1) )
perror("sem post");
}
else
{
if ( sem_post(v1) )
goto LABEL_15;
if ( v2 != 1 )
goto LABEL_6;
if ( sem_wait((sem_t *)(a1 + 160)) )
{
perror("sem wait");
return (unsigned int)-1;
}
v4[0] = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = v4[0] + 1;
if ( sem_post((sem_t *)(a1 + 160)) )
{
LABEL_15:
perror("sem post");
v2 = -1;
}
else
{
LABEL_6:
v2 = v4[0];
}
}
}
}
else
{
puts("Core NUll");
v2 = -1;
}
return v2;
}

original_code:
int CoreGetId(CorePtr Core){
 int Id,Err;
 if(Core==((void *)0)){printf("Core NUll\n");return -1;}
 if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
 if( (Err=QueueRemoveHead(Core->Queue,&Id))==-1){
  printf("QueueRemoveH Problem\n");
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
 if(Err==1){
  if(sem_wait(& ((Core)->Sem_Id))){perror("sem wait"); return -1;}
  Id=Core->Id;
  Core->Id++;
  if(sem_post(& (Core)->Sem_Id)){perror("sem post"); return -1;}
 }
  return Id;
}

canonical_original_code:
int CoreGetId(struct Core *Core){
 int Id; int Err;
 if(Core==((void *)0)){printf("Core NUll\n");return -1;}
 if(sem_wait(& ((Core)->Sem_Queue))){perror("sem wait"); return -1;}
 if( (Err=QueueRemoveHead(Core->Queue,&Id))==-1){
  printf("QueueRemoveH Problem\n");
  if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_Queue)){perror("sem post"); return -1;}
 if(Err==1){
  if(sem_wait(& ((Core)->Sem_Id))){perror("sem wait"); return -1;}
  Id=Core->Id;
  Core->Id++;
  if(sem_post(& (Core)->Sem_Id)){perror("sem post"); return -1;}
 }
  return Id;
}

variable_types: Err int


CoreAdd

decompiled_code:
__int64 __fastcall CoreAdd(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebx
sem_t *v5; // r12
unsigned int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = CoreGetId(a1);
if ( v4 == -1 )
{
puts("Id problem");
return v4;
}
if ( sem_wait((sem_t *)(a1 + 64)) )
{
perror("sem wait");
return (unsigned int)-1;
}
if ( (unsigned int)AddNeedleToFile(*(unsigned int *)(a1 + 20), a2, v4, a3, v7) == -1 )
{
puts("AddNeedle Problem");
v4 = -1;
if ( !sem_post((sem_t *)(a1 + 64)) )
return v4;
LABEL_13:
perror("sem post");
return v4;
}
if ( sem_post((sem_t *)(a1 + 64)) )
goto LABEL_8;
v5 = (sem_t *)(a1 + 96);
if ( sem_wait((sem_t *)(a1 + 96)) )
{
perror("sem wait");
return (unsigned int)-1;
}
if ( (unsigned int)AddMatrix(*(_QWORD *)a1, v4, v7[0]) == -1 )
{
puts("AddMatrix Problem");
v4 = -1;
if ( !sem_post(v5) )
return v4;
goto LABEL_13;
}
if ( sem_post(v5) )
{
LABEL_8:
perror("sem post");
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebx
sem_t *v5; // r12
unsigned int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = func6(a1);
if ( v4 == -1 )
{
puts("Id problem");
return v4;
}
if ( sem_wait((sem_t *)(a1 + 64)) )
{
perror("sem wait");
return (unsigned int)-1;
}
if ( (unsigned int)AddNeedleToFile(*(unsigned int *)(a1 + 20), a2, v4, a3, v7) == -1 )
{
puts("AddNeedle Problem");
v4 = -1;
if ( !sem_post((sem_t *)(a1 + 64)) )
return v4;
LABEL_13:
perror("sem post");
return v4;
}
if ( sem_post((sem_t *)(a1 + 64)) )
goto LABEL_8;
v5 = (sem_t *)(a1 + 96);
if ( sem_wait((sem_t *)(a1 + 96)) )
{
perror("sem wait");
return (unsigned int)-1;
}
if ( (unsigned int)AddMatrix(*(_QWORD *)a1, v4, v7[0]) == -1 )
{
puts("AddMatrix Problem");
v4 = -1;
if ( !sem_post(v5) )
return v4;
goto LABEL_13;
}
if ( sem_post(v5) )
{
LABEL_8:
perror("sem post");
v4 = -1;
}
return v4;
}

original_code:
int CoreAdd(CorePtr Core,int Buff_fd,int Size){
 int Id,Offset;
 if( (Id=CoreGetId(Core))==-1){printf("Id problem\n");return -1;}
 if(sem_wait(& (Core)->Sem_File)){perror("sem wait"); return -1;}
 if(AddNeedleToFile( (Core)->Fd,Buff_fd,Id,Size,&Offset)==-1){
  printf("AddNeedle Problem\n");
  if(sem_post(& (Core)->Sem_File)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_File)){perror("sem post"); return -1;}
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if(AddMatrix(Core->Matrix,Id,Offset)==-1){
  printf("AddMatrix Problem\n");
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 return Id;
}

canonical_original_code:
int CoreAdd(struct Core *Core, int Buff_fd, int Size){
 int Id; int Offset;
 if( (Id=CoreGetId(Core))==-1){printf("Id problem\n");return -1;}
 if(sem_wait(& (Core)->Sem_File)){perror("sem wait"); return -1;}
 if(AddNeedleToFile( (Core)->Fd,Buff_fd,Id,Size,&Offset)==-1){
  printf("AddNeedle Problem\n");
  if(sem_post(& (Core)->Sem_File)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_File)){perror("sem post"); return -1;}
 if(sem_wait(& (Core)->Sem_Matrix)){perror("sem wait"); return -1;}
 if(AddMatrix(Core->Matrix,Id,Offset)==-1){
  printf("AddMatrix Problem\n");
  if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
  return -1;
 }
 if(sem_post(& (Core)->Sem_Matrix)){perror("sem post"); return -1;}
 return Id;
}


InitiateMatrix

decompiled_code:
__int64 __fastcall InitiateMatrix(_QWORD *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // r12
void *v4; // rax
__int64 v5; // rax
__int64 result; // rax

v2 = malloc(0x10uLL);
*a1 = v2;
if ( v2 && (v3 = v2, v4 = malloc(4LL * a2), (*(_QWORD *)v3 = v4) != 0LL) )
{
v3[2] = a2;
if ( a2 <= 0 )
{
result = 0LL;
}
else
{
v5 = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)*a1 + v5) = 0;
v5 += 4LL;
}
while ( v5 != 4LL * (unsigned int)a2 );
result = 0LL;
}
}
else
{
perror("InitMatrix");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // r12
void *v4; // rax
__int64 v5; // rax
__int64 result; // rax

v2 = malloc(0x10uLL);
*a1 = v2;
if ( v2 && (v3 = v2, v4 = malloc(4LL * a2), (*(_QWORD *)v3 = v4) != 0LL) )
{
v3[2] = a2;
if ( a2 <= 0 )
{
result = 0LL;
}
else
{
v5 = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)*a1 + v5) = 0;
v5 += 4LL;
}
while ( v5 != 4LL * (unsigned int)a2 );
result = 0LL;
}
}
else
{
perror("InitMatrix");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int InitiateMatrix(MatrixPtr *Matrix,int Size){
 int i;
 if(((*Matrix)=malloc(sizeof(struct Matrix)))==((void *)0)){perror("InitMatrix");return -1;}
 if(((*Matrix)->Table=malloc(Size*sizeof(int)))==((void *)0)){perror("InitMatrix");return -1;}
 (*Matrix)->Size=Size;
 for(i=0;i<Size;i++)
  (*Matrix)->Table[i]=0;
 return 0;
}

canonical_original_code:
int InitiateMatrix(struct Matrix **Matrix, int Size){
 int i;
 if(((*Matrix)=malloc(sizeof(struct Matrix)))==((void *)0)){perror("InitMatrix");return -1;}
 if(((*Matrix)->Table=malloc(Size*sizeof(int)))==((void *)0)){perror("InitMatrix");return -1;}
 (*Matrix)->Size=Size;
 for(i=0;i<Size;i++)
  (*Matrix)->Table[i]=0;
 return 0;
}

variable_types: struct Matrix { int *Table; int Size; } **


DeleteMatrix

decompiled_code:
__int64 __fastcall DeleteMatrix(void ***a1)
{
if ( *a1 )
{
free(**a1);
free(*a1);
}
*a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void ***a1)
{
if ( *a1 )
{
free(**a1);
free(*a1);
}
*a1 = 0LL;
return 0LL;
}

original_code:
int DeleteMatrix(MatrixPtr *Matrix){
 if(*Matrix!=((void *)0)){
  free((*Matrix)->Table);
  free(*Matrix);
 }
 *Matrix=((void *)0);
 return 0;
}

canonical_original_code:
int DeleteMatrix(struct Matrix **Matrix){
 if(*Matrix!=((void *)0)){
  free((*Matrix)->Table);
  free(*Matrix);
 }
 *Matrix=((void *)0);
 return 0;
}


AddMatrix

decompiled_code:
__int64 __fastcall AddMatrix(__int64 a1, int a2, int a3)
{
int v5; // ebp
__int64 result; // rax
int v7; // esi
void *v8; // rax
__int64 i; // rax

if ( a1 )
{
v5 = *(_DWORD *)(a1 + 8);
if ( v5 > a2 )
{
LABEL_3:
*(_DWORD *)(*(_QWORD *)a1 + 4LL * a2) = a3;
return 0LL;
}
v7 = 2 * a2;
*(_DWORD *)(a1 + 8) = v7;
v8 = realloc(*(void **)a1, 4LL * v7);
*(_QWORD *)a1 = v8;
if ( v8 )
{
for ( i = 4LL * v5; *(_DWORD *)(a1 + 8) > v5; i += 4LL )
{
*(_DWORD *)(*(_QWORD *)a1 + i) = 0;
++v5;
}
goto LABEL_3;
}
perror("Realloc failed");
result = 0xFFFFFFFFLL;
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3)
{
int v5; // ebp
__int64 result; // rax
int v7; // esi
void *v8; // rax
__int64 i; // rax

if ( a1 )
{
v5 = *(_DWORD *)(a1 + 8);
if ( v5 > a2 )
{
LABEL_3:
*(_DWORD *)(*(_QWORD *)a1 + 4LL * a2) = a3;
return 0LL;
}
v7 = 2 * a2;
*(_DWORD *)(a1 + 8) = v7;
v8 = realloc(*(void **)a1, 4LL * v7);
*(_QWORD *)a1 = v8;
if ( v8 )
{
for ( i = 4LL * v5; *(_DWORD *)(a1 + 8) > v5; i += 4LL )
{
*(_DWORD *)(*(_QWORD *)a1 + i) = 0;
++v5;
}
goto LABEL_3;
}
perror("Realloc failed");
result = 0xFFFFFFFFLL;
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int AddMatrix(MatrixPtr Matrix,int Position,int Offset){
 int OldSize,i;
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 OldSize=Matrix->Size;
 if( Matrix->Size <= Position ){
  Matrix->Size=(Position)*2;
  if((Matrix->Table=realloc(Matrix->Table,(Matrix->Size)*sizeof(int)))==((void *)0)){perror("Realloc failed");return -1;}
  for(i=OldSize;i<Matrix->Size;i++)
   Matrix->Table[i]=0;
 }
 Matrix->Table[Position]=Offset;
 return 0;
}

canonical_original_code:
int AddMatrix(struct Matrix *Matrix, int Position, int Offset){
 int OldSize; int i;
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 OldSize=Matrix->Size;
 if( Matrix->Size <= Position ){
  Matrix->Size=(Position)*2;
  if((Matrix->Table=realloc(Matrix->Table,(Matrix->Size)*sizeof(int)))==((void *)0)){perror("Realloc failed");return -1;}
  for(i=OldSize;i<Matrix->Size;i++)
   Matrix->Table[i]=0;
 }
 Matrix->Table[Position]=Offset;
 return 0;
}

variable_types: struct Matrix { int *Table; int Size; } *

variable_types: Position int

variable_types: OldSize int


PrintMatrix

decompiled_code:
__int64 __fastcall PrintMatrix(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
puts("Printing Matrix:");
if ( *(int *)(a1 + 8) <= 0 )
{
result = 0LL;
}
else
{
v1 = 0LL;
do
{
printf("[%d]={%d}\n", (unsigned int)v1, *(unsigned int *)(*(_QWORD *)a1 + 4 * v1));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
result = 0LL;
}
}
else
{
puts("Matrix Table is null");
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
puts("Printing Matrix:");
if ( *(int *)(a1 + 8) <= 0 )
{
result = 0LL;
}
else
{
v1 = 0LL;
do
{
printf("[%d]={%d}\n", (unsigned int)v1, *(unsigned int *)(*(_QWORD *)a1 + 4 * v1));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
result = 0LL;
}
}
else
{
puts("Matrix Table is null");
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int PrintMatrix(MatrixPtr Matrix){
 int i;
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 if(Matrix->Table==((void *)0)){printf("Matrix Table is null\n");return -1;}
 printf("Printing Matrix:\n");
 for(i=0;i<Matrix->Size;i++)
  printf("[%d]={%d}\n",i,Matrix->Table[i]);
 return 0;
}

canonical_original_code:
int PrintMatrix(struct Matrix *Matrix){
 int i;
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 if(Matrix->Table==((void *)0)){printf("Matrix Table is null\n");return -1;}
 printf("Printing Matrix:\n");
 for(i=0;i<Matrix->Size;i++)
  printf("[%d]={%d}\n",i,Matrix->Table[i]);
 return 0;
}

variable_types: i int


GetElementMatrix

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

if ( a1 )
{
result = 0LL;
if ( *(_DWORD *)(a1 + 8) >= a2 )
result = *(unsigned int *)(*(_QWORD *)a1 + 4LL * a2);
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
result = 0LL;
if ( *(_DWORD *)(a1 + 8) >= a2 )
result = *(unsigned int *)(*(_QWORD *)a1 + 4LL * a2);
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int GetElementMatrix(MatrixPtr Matrix,int Position){
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 if(Position > Matrix->Size)
  return 0;
 return(Matrix->Table[Position]);
}

canonical_original_code:
int GetElementMatrix(struct Matrix *Matrix, int Position){
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 if(Position > Matrix->Size)
  return 0;
 return(Matrix->Table[Position]);
}


RemoveMatrix

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

if ( a1 )
{
*(_DWORD *)(*a1 + 4LL * a2) = 0;
result = 0LL;
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
*(_DWORD *)(*a1 + 4LL * a2) = 0;
result = 0LL;
}
else
{
puts("Matrix is null");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int RemoveMatrix(MatrixPtr Matrix,int Position){
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 Matrix->Table[Position]=0;
 return 0;
}

canonical_original_code:
int RemoveMatrix(struct Matrix *Matrix, int Position){
 if(Matrix==((void *)0)){printf("Matrix is null\n");return -1;}
 Matrix->Table[Position]=0;
 return 0;
}


CheckFile

decompiled_code:
__int64 __fastcall CheckFile(char *filename, _DWORD *a2)
{
unsigned int v2; // ebx
int v3; // eax
int v4; // ebp
char v6[268]; // [rsp+0h] [rbp-138h] BYREF
int buf[11]; // [rsp+10Ch] [rbp-2Ch] BYREF

v2 = access(filename, 0);
*_errno_location() = 0;
if ( v2 )
{
PrintOutput(v6);
printf("[%s] :{%s} DOES NOT EXIST,CREATING HAYSTACK FILE\n", v6, filename);
v2 = open(filename, 66, 420LL);
*a2 = v2;
if ( v2 == -1 )
perror("creating");
else
v2 = 0;
}
else
{
v3 = open(filename, 2, 420LL);
*a2 = v3;
if ( v3 == -1 )
{
perror("creating");
v2 = -1;
}
else if ( read(v3, buf, 4uLL) == 4 )
{
if ( buf[0] == 76 )
{
PrintOutput(v6);
printf("[%s] :{%s} IS IN VALID HAYSTACK FORM\n", v6, filename);
v2 = 1;
}
else if ( remove(filename) == -1 )
{
perror("remove");
v2 = -1;
}
else
{
PrintOutput(v6);
printf("[%s] :{%s} IS NOT A HAYSTACK FILE,REMOVING IT AND MAKING A NEW ONE WITH THE SAME NAME\n", v6, filename);
v4 = open(filename, 66, 420LL);
*a2 = v4;
if ( v4 == -1 )
{
perror("creating");
v2 = -1;
}
}
}
else
{
perror("read Magic");
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, _DWORD *a2)
{
unsigned int v2; // ebx
int v3; // eax
int v4; // ebp
char v6[268]; // [rsp+0h] [rbp-138h] BYREF
int buf[11]; // [rsp+10Ch] [rbp-2Ch] BYREF

v2 = access(filename, 0);
*_errno_location() = 0;
if ( v2 )
{
PrintOutput(v6);
printf("[%s] :{%s} DOES NOT EXIST,CREATING HAYSTACK FILE\n", v6, filename);
v2 = open(filename, 66, 420LL);
*a2 = v2;
if ( v2 == -1 )
perror("creating");
else
v2 = 0;
}
else
{
v3 = open(filename, 2, 420LL);
*a2 = v3;
if ( v3 == -1 )
{
perror("creating");
v2 = -1;
}
else if ( read(v3, buf, 4uLL) == 4 )
{
if ( buf[0] == 76 )
{
PrintOutput(v6);
printf("[%s] :{%s} IS IN VALID HAYSTACK FORM\n", v6, filename);
v2 = 1;
}
else if ( remove(filename) == -1 )
{
perror("remove");
v2 = -1;
}
else
{
PrintOutput(v6);
printf("[%s] :{%s} IS NOT A HAYSTACK FILE,REMOVING IT AND MAKING A NEW ONE WITH THE SAME NAME\n", v6, filename);
v4 = open(filename, 66, 420LL);
*a2 = v4;
if ( v4 == -1 )
{
perror("creating");
v2 = -1;
}
}
}
else
{
perror("read Magic");
v2 = -1;
}
}
return v2;
}

original_code:
int CheckFile(char* WorkFile,int* FileDes){
 int Num;
 int Result;
 char TimeBuffer[256];
 Result=access(WorkFile, 0);
 (*__errno_location ())=0;
 if (Result == 0){
  if (( *FileDes = open(WorkFile , 02 , 0644 ))== -1){perror("creating");return -1;}
  if(read(*FileDes,&Num,sizeof(int))!=sizeof(int)){perror("read Magic");return -1;}
  if( Num!=76){
   if(remove(WorkFile)==-1){perror("remove");return -1;}
   PrintOutput(TimeBuffer);
   printf("[%s] :{%s} IS NOT A HAYSTACK FILE,REMOVING IT AND MAKING A NEW ONE WITH THE SAME NAME\n",TimeBuffer,WorkFile);
   if (( *FileDes = open(WorkFile , 0100| 02 , 0644 ))== -1){perror("creating");return -1;}
   return 0;
  }
  PrintOutput(TimeBuffer);
  printf("[%s] :{%s} IS IN VALID HAYSTACK FORM\n",TimeBuffer,WorkFile);
  return 1;
 }
 PrintOutput(TimeBuffer);
 printf("[%s] :{%s} DOES NOT EXIST,CREATING HAYSTACK FILE\n",TimeBuffer,WorkFile);
 if (( *FileDes = open(WorkFile , 0100| 02 , 0644 ))== -1){perror("creating");return -1;}
 return 0;
}

canonical_original_code:
int CheckFile(char *WorkFile, int *FileDes){
 int Num;
 int Result;
 char TimeBuffer[256];
 Result=access(WorkFile, 0);
 (*__errno_location ())=0;
 if (Result == 0){
  if (( *FileDes = open(WorkFile , 02 , 0644 ))== -1){perror("creating");return -1;}
  if(read(*FileDes,&Num,sizeof(int))!=sizeof(int)){perror("read Magic");return -1;}
  if( Num!=76){
   if(remove(WorkFile)==-1){perror("remove");return -1;}
   PrintOutput(TimeBuffer);
   printf("[%s] :{%s} IS NOT A HAYSTACK FILE,REMOVING IT AND MAKING A NEW ONE WITH THE SAME NAME\n",TimeBuffer,WorkFile);
   if (( *FileDes = open(WorkFile , 0100| 02 , 0644 ))== -1){perror("creating");return -1;}
   return 0;
  }
  PrintOutput(TimeBuffer);
  printf("[%s] :{%s} IS IN VALID HAYSTACK FORM\n",TimeBuffer,WorkFile);
  return 1;
 }
 PrintOutput(TimeBuffer);
 printf("[%s] :{%s} DOES NOT EXIST,CREATING HAYSTACK FILE\n",TimeBuffer,WorkFile);
 if (( *FileDes = open(WorkFile , 0100| 02 , 0644 ))== -1){perror("creating");return -1;}
 return 0;
}

variable_types:
FileDes
int *

variable_types: Num int

variable_types: Result int

variable_types:
TimeBuffer
char [256]


AddNeedleToFile

decompiled_code:
__int64 __fastcall AddNeedleToFile(int fd, int a2, int a3, int a4, unsigned int *a5)
{
unsigned int v6; // ebx
int v7; // eax
int v9; // [rsp+8h] [rbp-140h] BYREF
int v10; // [rsp+Ch] [rbp-13Ch] BYREF
char v11[264]; // [rsp+10h] [rbp-138h] BYREF
int v12; // [rsp+118h] [rbp-30h] BYREF
int buf[11]; // [rsp+11Ch] [rbp-2Ch] BYREF

v10 = a3;
v9 = a4;
v12 = 1;
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
v6 = -1;
}
else if ( read(fd, buf, 4uLL) == 4 )
{
++buf[0];
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
v6 = -1;
}
else if ( write(fd, buf, 4uLL) == 4 )
{
v6 = lseek(fd, 0LL, 2);
*a5 = v6;
if ( v6 == -1 )
{
perror("lseek");
}
else if ( write(fd, &v10, 4uLL) == 4 )
{
if ( write(fd, &v12, 4uLL) == 4 )
{
if ( write(fd, &v9, 4uLL) == 4 )
{
while ( 1 )
{
v7 = read(a2, v11, 0x100uLL);
v6 = v7;
if ( v7 <= 0 )
break;
if ( write(fd, v11, v7) < v7 )
{
perror("write to file");
return (unsigned int)-1;
}
}
if ( v7 == -1 )
perror("read");
else
v6 = 0;
}
else
{
perror("write size");
v6 = -1;
}
}
else
{
perror("write state");
v6 = -1;
}
}
else
{
perror("write Id");
v6 = -1;
}
}
else
{
perror("write total");
v6 = -1;
}
}
else
{
perror("read total");
v6 = -1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, int a2, int a3, int a4, unsigned int *a5)
{
unsigned int v6; // ebx
int v7; // eax
int v9; // [rsp+8h] [rbp-140h] BYREF
int v10; // [rsp+Ch] [rbp-13Ch] BYREF
char v11[264]; // [rsp+10h] [rbp-138h] BYREF
int v12; // [rsp+118h] [rbp-30h] BYREF
int buf[11]; // [rsp+11Ch] [rbp-2Ch] BYREF

v10 = a3;
v9 = a4;
v12 = 1;
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
v6 = -1;
}
else if ( read(fd, buf, 4uLL) == 4 )
{
++buf[0];
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
v6 = -1;
}
else if ( write(fd, buf, 4uLL) == 4 )
{
v6 = lseek(fd, 0LL, 2);
*a5 = v6;
if ( v6 == -1 )
{
perror("lseek");
}
else if ( write(fd, &v10, 4uLL) == 4 )
{
if ( write(fd, &v12, 4uLL) == 4 )
{
if ( write(fd, &v9, 4uLL) == 4 )
{
while ( 1 )
{
v7 = read(a2, v11, 0x100uLL);
v6 = v7;
if ( v7 <= 0 )
break;
if ( write(fd, v11, v7) < v7 )
{
perror("write to file");
return (unsigned int)-1;
}
}
if ( v7 == -1 )
perror("read");
else
v6 = 0;
}
else
{
perror("write size");
v6 = -1;
}
}
else
{
perror("write state");
v6 = -1;
}
}
else
{
perror("write Id");
v6 = -1;
}
}
else
{
perror("write total");
v6 = -1;
}
}
else
{
perror("read total");
v6 = -1;
}
return v6;
}

original_code:
int AddNeedleToFile(int FileDes,int BufferDes,int Id,int Size,int* Offset){
 int Total,State=1,Nread;
 char Buffer[256];
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(read(FileDes,&Total,sizeof(int))!=sizeof(int)){perror("read total");return -1;}
 Total++;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(FileDes, &Total, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
 if( (*Offset=lseek(FileDes,0,2))==-1){perror("lseek");return -1;}
 if(write(FileDes, &Id, sizeof(int))!=sizeof(int)){perror("write Id");return -1;}
 if(write(FileDes, &State, sizeof(int))!=sizeof(int)){perror("write state");return -1;}
 if(write(FileDes, &Size, sizeof(int))!=sizeof(int)){perror("write size");return -1;}
 while ( (Nread =read (BufferDes, Buffer , 256 ) ) > 0 ){
  if ( write(FileDes,Buffer,Nread) < Nread){perror("write to file");return -1;}
 }
 if(Nread==-1){perror("read");return -1;}
 return 0;
}

canonical_original_code:
int AddNeedleToFile(int FileDes, int BufferDes, int Id, int Size, int *Offset){
 int Total; int State = 1; int Nread;
 char Buffer[256];
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(read(FileDes,&Total,sizeof(int))!=sizeof(int)){perror("read total");return -1;}
 Total++;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(FileDes, &Total, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
 if( (*Offset=lseek(FileDes,0,2))==-1){perror("lseek");return -1;}
 if(write(FileDes, &Id, sizeof(int))!=sizeof(int)){perror("write Id");return -1;}
 if(write(FileDes, &State, sizeof(int))!=sizeof(int)){perror("write state");return -1;}
 if(write(FileDes, &Size, sizeof(int))!=sizeof(int)){perror("write size");return -1;}
 while ( (Nread =read (BufferDes, Buffer , 256 ) ) > 0 ){
  if ( write(FileDes,Buffer,Nread) < Nread){perror("write to file");return -1;}
 }
 if(Nread==-1){perror("read");return -1;}
 return 0;
}

variable_types: FileDes int

variable_types: BufferDes int

variable_types:
Offset
int *

variable_types: Total int

variable_types: State int

variable_types: Nread int

variable_types:
Buffer
char [256]


DeleteNeedle

decompiled_code:
__int64 __fastcall DeleteNeedle(int fd, int a2)
{
int buf; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
return 0xFFFFFFFFLL;
}
if ( read(fd, &buf, 4uLL) != 4 )
{
perror("delete read total");
return 0xFFFFFFFFLL;
}
--buf;
if ( lseek(fd, 4LL, 0) == -1 )
goto LABEL_10;
if ( write(fd, &buf, 4uLL) == 4 )
{
if ( lseek(fd, a2 + 4LL, 0) != -1 )
{
if ( write(fd, v4, 4uLL) == 4 )
return 0LL;
goto LABEL_13;
}
LABEL_10:
perror("lseek");
return 0xFFFFFFFFLL;
}
LABEL_13:
perror("write total");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, int a2)
{
int buf; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
return 0xFFFFFFFFLL;
}
if ( read(fd, &buf, 4uLL) != 4 )
{
perror("delete read total");
return 0xFFFFFFFFLL;
}
--buf;
if ( lseek(fd, 4LL, 0) == -1 )
goto LABEL_10;
if ( write(fd, &buf, 4uLL) == 4 )
{
if ( lseek(fd, a2 + 4LL, 0) != -1 )
{
if ( write(fd, v4, 4uLL) == 4 )
return 0LL;
goto LABEL_13;
}
LABEL_10:
perror("lseek");
return 0xFFFFFFFFLL;
}
LABEL_13:
perror("write total");
return 0xFFFFFFFFLL;
}

original_code:
int DeleteNeedle(int FileDes,int Offset){
 int State=0,Total;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(read(FileDes,&Total,sizeof(int))!=sizeof(int)){perror("delete read total");return -1;}
 Total--;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(FileDes, &Total, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
 if(lseek(FileDes,Offset+sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(FileDes, &State, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
 return 0;
}

canonical_original_code:
int DeleteNeedle(int FileDes, int Offset){
 int State = 0; int Total;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(read(FileDes,&Total,sizeof(int))!=sizeof(int)){perror("delete read total");return -1;}
 Total--;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(FileDes, &Total, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
 if(lseek(FileDes,Offset+sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(FileDes, &State, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
 return 0;
}

variable_types: Offset int


RestoreQueue

decompiled_code:
__int64 __fastcall RestoreQueue(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

if ( *(int *)(a1 + 16) <= 0 )
return 0;
v1 = 0LL;
do
{
if ( !*(_DWORD *)(**(_QWORD **)a1 + 4 * v1) )
{
v2 = QueueAdd(*(_QWORD *)(a1 + 8), (unsigned int)v1);
if ( v2 == -1 )
{
puts("queue add problem");
return v2;
}
}
++v1;
}
while ( *(_DWORD *)(a1 + 16) > (int)v1 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

if ( *(int *)(a1 + 16) <= 0 )
return 0;
v1 = 0LL;
do
{
if ( !*(_DWORD *)(**(_QWORD **)a1 + 4 * v1) )
{
v2 = QueueAdd(*(_QWORD *)(a1 + 8), (unsigned int)v1);
if ( v2 == -1 )
{
puts("queue add problem");
return v2;
}
}
++v1;
}
while ( *(_DWORD *)(a1 + 16) > (int)v1 );
return 0;
}

original_code:
int RestoreQueue(CorePtr MyCore){
 int i;
 for (i=0;i<MyCore->Id;i++){
  if( MyCore->Matrix->Table[i]==0){
   if(QueueAdd(MyCore->Queue,i)==-1){printf("queue add problem\n");return -1;}
  }
 }
 return 0;
}

canonical_original_code:
int RestoreQueue(struct Core *MyCore){
 int i;
 for (i=0;i<MyCore->Id;i++){
  if( MyCore->Matrix->Table[i]==0){
   if(QueueAdd(MyCore->Queue,i)==-1){printf("queue add problem\n");return -1;}
  }
 }
 return 0;
}

variable_types: struct Core { struct Matrix { int *Table; int Size; } *Matrix; struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } *Queue; int Id; int Fd; int Total_Threads; union sem_t { char __size[32]; long __align; } Sem_Total; union sem_t Sem_File; union sem_t Sem_Matrix; union sem_t Sem_Queue; union sem_t Sem_Id; int TerminationFlag; } *


Compaction

decompiled_code:
__int64 __fastcall Compaction(int fd, int a2, __int64 a3)
{
int v3; // er13
unsigned int v4; // ebp
int v5; // er15
int v6; // er14
int v7; // ebp
signed int v8; // ebp
int v9; // eax
unsigned int v12; // [rsp+10h] [rbp-468h]
int v13; // [rsp+14h] [rbp-464h]
int v14; // [rsp+18h] [rbp-460h]
signed int v15; // [rsp+1Ch] [rbp-45Ch]
char v16[1036]; // [rsp+20h] [rbp-458h] BYREF
int v17; // [rsp+42Ch] [rbp-4Ch] BYREF
int v18; // [rsp+430h] [rbp-48h] BYREF
unsigned int v19; // [rsp+434h] [rbp-44h] BYREF
int v20; // [rsp+438h] [rbp-40h] BYREF
int buf[15]; // [rsp+43Ch] [rbp-3Ch] BYREF

buf[0] = 76;
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
v4 = -1;
}
else if ( write(a2, buf, 4uLL) == 4 )
{
if ( (unsigned int)read(fd, &v20, 4uLL) == 4 )
{
if ( write(a2, &v20, 4uLL) == 4 )
{
if ( v20 <= 0 )
goto LABEL_45;
v13 = -1;
v3 = 0;
v12 = 8;
do
{
if ( read(fd, &v19, 4uLL) != 4 )
{
perror("read id");
return (unsigned int)-1;
}
if ( read(fd, &v18, 4uLL) != 4 )
{
perror("read state");
return (unsigned int)-1;
}
if ( read(fd, &v17, 4uLL) != 4 )
{
perror("read size");
return (unsigned int)-1;
}
if ( v18 )
{
v4 = AddMatrix(*(_QWORD *)a3, v19, v12);
if ( v4 == -1 )
{
puts("addMatrix problem");
return v4;
}
v14 = v17;
v15 = v19;
if ( write(a2, &v19, 4uLL) != 4 || write(a2, &v18, 4uLL) != 4 || write(a2, &v17, 4uLL) != 4 )
{
perror("write magic number");
return (unsigned int)-1;
}
v5 = v17;
v6 = v17 / 256;
if ( v17 > 255 )
{
v7 = 0;
while ( read(fd, v16, 0x100uLL) > 255 )
{
if ( write(a2, v16, 0x100uLL) <= 255 )
goto LABEL_39;
if ( v6 <= ++v7 )
goto LABEL_23;
}
LABEL_37:
perror("read from file");
return (unsigned int)-1;
}
LABEL_23:
v8 = (unsigned __int8)(v5 + ((unsigned int)(v5 >> 31) >> 24)) - ((unsigned int)(v5 >> 31) >> 24);
if ( read(fd, v16, v8) < v8 )
goto LABEL_37;
if ( v8 > write(a2, v16, v8) )
{
LABEL_39:
perror("write to file");
return (unsigned int)-1;
}
v12 += v14 + 12;
v9 = v15;
if ( v13 >= v15 )
v9 = v13;
v13 = v9;
}
else
{
--v3;
if ( lseek(fd, v17, 1) == -1 )
{
perror("lseek");
return (unsigned int)-1;
}
}
++v3;
}
while ( v20 > v3 );
if ( v13 == -1 )
{
LABEL_45:
*(_DWORD *)(a3 + 16) = 0;
}
else
{
*(_DWORD *)(a3 + 16) = v13 + 1;
v4 = RestoreQueue(a3);
if ( v4 == -1 )
{
puts("restore queue problem");
return v4;
}
}
*(_DWORD *)(a3 + 20) = a2;
return 0;
}
perror("compatcion write total number");
v4 = -1;
}
else
{
perror("compatcion read total");
v4 = -1;
}
}
else
{
perror("write magic number");
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2, __int64 a3)
{
int v3; // er13
unsigned int v4; // ebp
int v5; // er15
int v6; // er14
int v7; // ebp
signed int v8; // ebp
int v9; // eax
unsigned int v12; // [rsp+10h] [rbp-468h]
int v13; // [rsp+14h] [rbp-464h]
int v14; // [rsp+18h] [rbp-460h]
signed int v15; // [rsp+1Ch] [rbp-45Ch]
char v16[1036]; // [rsp+20h] [rbp-458h] BYREF
int v17; // [rsp+42Ch] [rbp-4Ch] BYREF
int v18; // [rsp+430h] [rbp-48h] BYREF
unsigned int v19; // [rsp+434h] [rbp-44h] BYREF
int v20; // [rsp+438h] [rbp-40h] BYREF
int buf[15]; // [rsp+43Ch] [rbp-3Ch] BYREF

buf[0] = 76;
if ( lseek(fd, 4LL, 0) == -1 )
{
perror("lseek");
v4 = -1;
}
else if ( write(a2, buf, 4uLL) == 4 )
{
if ( (unsigned int)read(fd, &v20, 4uLL) == 4 )
{
if ( write(a2, &v20, 4uLL) == 4 )
{
if ( v20 <= 0 )
goto LABEL_45;
v13 = -1;
v3 = 0;
v12 = 8;
do
{
if ( read(fd, &v19, 4uLL) != 4 )
{
perror("read id");
return (unsigned int)-1;
}
if ( read(fd, &v18, 4uLL) != 4 )
{
perror("read state");
return (unsigned int)-1;
}
if ( read(fd, &v17, 4uLL) != 4 )
{
perror("read size");
return (unsigned int)-1;
}
if ( v18 )
{
v4 = AddMatrix(*(_QWORD *)a3, v19, v12);
if ( v4 == -1 )
{
puts("addMatrix problem");
return v4;
}
v14 = v17;
v15 = v19;
if ( write(a2, &v19, 4uLL) != 4 || write(a2, &v18, 4uLL) != 4 || write(a2, &v17, 4uLL) != 4 )
{
perror("write magic number");
return (unsigned int)-1;
}
v5 = v17;
v6 = v17 / 256;
if ( v17 > 255 )
{
v7 = 0;
while ( read(fd, v16, 0x100uLL) > 255 )
{
if ( write(a2, v16, 0x100uLL) <= 255 )
goto LABEL_39;
if ( v6 <= ++v7 )
goto LABEL_23;
}
LABEL_37:
perror("read from file");
return (unsigned int)-1;
}
LABEL_23:
v8 = (unsigned __int8)(v5 + ((unsigned int)(v5 >> 31) >> 24)) - ((unsigned int)(v5 >> 31) >> 24);
if ( read(fd, v16, v8) < v8 )
goto LABEL_37;
if ( v8 > write(a2, v16, v8) )
{
LABEL_39:
perror("write to file");
return (unsigned int)-1;
}
v12 += v14 + 12;
v9 = v15;
if ( v13 >= v15 )
v9 = v13;
v13 = v9;
}
else
{
--v3;
if ( lseek(fd, v17, 1) == -1 )
{
perror("lseek");
return (unsigned int)-1;
}
}
++v3;
}
while ( v20 > v3 );
if ( v13 == -1 )
{
LABEL_45:
*(_DWORD *)(a3 + 16) = 0;
}
else
{
*(_DWORD *)(a3 + 16) = v13 + 1;
v4 = func3(a3);
if ( v4 == -1 )
{
puts("restore queue problem");
return v4;
}
}
*(_DWORD *)(a3 + 20) = a2;
return 0;
}
perror("compatcion write total number");
v4 = -1;
}
else
{
perror("compatcion read total");
v4 = -1;
}
}
else
{
perror("write magic number");
v4 = -1;
}
return v4;
}

original_code:
int Compaction(int FileDes,int NewDes, CorePtr MyCore){
 int num=76,Res,Offset;
 int Total,i,Loop, Remaining,Id,State,Size,MaxId=-1;
 int Buffer[256],j;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(NewDes, &num, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
 if((Res=read(FileDes,&Total,sizeof(int)))!=sizeof(int)){perror("compatcion read total");return -1;}
 if(write(NewDes, &Total, sizeof(int))!=sizeof(int)){perror("compatcion write total number");return -1;}
 Offset=sizeof(int)*2;
 for( i=0; i<Total;i++){
  if(read(FileDes,&Id,sizeof(int))!=sizeof(int)){perror("read id");return -1;}
  if(read(FileDes,&State,sizeof(int))!=sizeof(int)){perror("read state");return -1;}
  if(read(FileDes,&Size,sizeof(int))!=sizeof(int)){perror("read size");return -1;}
  if( State==0){
   i--;
   if(lseek(FileDes,Size,1)==-1){perror("lseek");return -1;}
   continue;
  }
  if(AddMatrix(MyCore->Matrix,Id,Offset)==-1){printf("addMatrix problem\n");return -1;}
  Offset+=sizeof(int)*3+Size;
  if(Id>MaxId){ MaxId=Id;}
  if(write(NewDes, &Id, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  if(write(NewDes, &State, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  if(write(NewDes, &Size, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  Loop=Size/256;
  Remaining=Size%256;
  for(j=0;j<Loop;j++){
   if ( read(FileDes, Buffer , 256) < 256){perror("read from file");return -1;}
   if ( write(NewDes,Buffer,256) < 256){perror("write to file");return -1;}
  }
  if (read (FileDes, Buffer , Remaining) < Remaining){perror("read from file");return -1;}
  if ( write(NewDes,Buffer,Remaining) < Remaining){perror("write to file");return -1;}
 }
 if(MaxId==-1){
  MyCore->Id=0;
 }else{
  MyCore->Id=MaxId+1;
  if(RestoreQueue(MyCore)==-1){printf("restore queue problem\n");return -1;}
 }
 MyCore->Fd=NewDes;
 return 0;
}

canonical_original_code:
int Compaction(int FileDes, int NewDes, struct Core *MyCore){
 int num = 76; int Res; int Offset;
 int Total; int i; int Loop; int Remaining; int Id; int State; int Size; int MaxId = -1;
 int Buffer[256]; int j;
 if(lseek(FileDes,sizeof(int),0)==-1){perror("lseek");return -1;}
 if(write(NewDes, &num, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
 if((Res=read(FileDes,&Total,sizeof(int)))!=sizeof(int)){perror("compatcion read total");return -1;}
 if(write(NewDes, &Total, sizeof(int))!=sizeof(int)){perror("compatcion write total number");return -1;}
 Offset=sizeof(int)*2;
 for( i=0; i<Total;i++){
  if(read(FileDes,&Id,sizeof(int))!=sizeof(int)){perror("read id");return -1;}
  if(read(FileDes,&State,sizeof(int))!=sizeof(int)){perror("read state");return -1;}
  if(read(FileDes,&Size,sizeof(int))!=sizeof(int)){perror("read size");return -1;}
  if( State==0){
   i--;
   if(lseek(FileDes,Size,1)==-1){perror("lseek");return -1;}
   continue;
  }
  if(AddMatrix(MyCore->Matrix,Id,Offset)==-1){printf("addMatrix problem\n");return -1;}
  Offset+=sizeof(int)*3+Size;
  if(Id>MaxId){ MaxId=Id;}
  if(write(NewDes, &Id, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  if(write(NewDes, &State, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  if(write(NewDes, &Size, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  Loop=Size/256;
  Remaining=Size%256;
  for(j=0;j<Loop;j++){
   if ( read(FileDes, Buffer , 256) < 256){perror("read from file");return -1;}
   if ( write(NewDes,Buffer,256) < 256){perror("write to file");return -1;}
  }
  if (read (FileDes, Buffer , Remaining) < Remaining){perror("read from file");return -1;}
  if ( write(NewDes,Buffer,Remaining) < Remaining){perror("write to file");return -1;}
 }
 if(MaxId==-1){
  MyCore->Id=0;
 }else{
  MyCore->Id=MaxId+1;
  if(RestoreQueue(MyCore)==-1){printf("restore queue problem\n");return -1;}
 }
 MyCore->Fd=NewDes;
 return 0;
}

variable_types: NewDes int

variable_types: num int

variable_types: Res int

variable_types: Loop int

variable_types: Remaining int

variable_types: Id int

variable_types: Size int

variable_types: MaxId int

variable_types:
Buffer
int [256]

variable_types: j int


InitializeHayStack

decompiled_code:
__int64 __fastcall InitializeHayStack(char *filename, __int64 a2)
{
void *v2; // rsp
unsigned int v3; // eax
unsigned int v4; // ebx
int v6; // eax
char v7[264]; // [rsp+0h] [rbp-130h] BYREF
int buf; // [rsp+108h] [rbp-28h] BYREF
int fd[9]; // [rsp+10Ch] [rbp-24h] BYREF

if ( !filename )
return (unsigned int)-1;
buf = 76;
v2 = alloca(strlen(filename) + 5);
v3 = CheckFile(filename, fd);
v4 = v3;
if ( v3 == -1 )
{
puts("Result problem");
}
else if ( v3 == 1 )
{
sprintf(v7, "%s%s", "New_", filename);
PrintOutput(v7);
printf("[%s] :BOOTSTRAP COMPACTION IN TO NEW FILE :|%s|\n", v7, v7);
if ( !access(v7, 0) )
{
PrintOutput(v7);
printf("[%s] :NEW FILE NAME EXISTS,OVERWRITTING IT\n", v7);
remove(v7);
}
*_errno_location() = 0;
v6 = open(v7, 66, 420LL);
v4 = v6;
if ( v6 == -1 )
{
perror("creating");
}
else if ( (unsigned int)Compaction(fd[0], v6, a2) == -1 )
{
puts("Compaction problem");
v4 = -1;
}
}
else if ( v3 )
{
v4 = -1;
}
else if ( write(fd[0], &buf, 4uLL) == 4 )
{
buf = 0;
if ( write(fd[0], &buf, 4uLL) != 4 )
{
perror("write total");
v4 = -1;
}
}
else
{
perror("write magic number");
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *filename, __int64 a2)
{
void *v2; // rsp
unsigned int v3; // eax
unsigned int v4; // ebx
int v6; // eax
char v7[264]; // [rsp+0h] [rbp-130h] BYREF
int buf; // [rsp+108h] [rbp-28h] BYREF
int fd[9]; // [rsp+10Ch] [rbp-24h] BYREF

if ( !filename )
return (unsigned int)-1;
buf = 76;
v2 = alloca(strlen(filename) + 5);
v3 = func0(filename, fd);
v4 = v3;
if ( v3 == -1 )
{
puts("Result problem");
}
else if ( v3 == 1 )
{
sprintf(v7, "%s%s", "New_", filename);
PrintOutput(v7);
printf("[%s] :BOOTSTRAP COMPACTION IN TO NEW FILE :|%s|\n", v7, v7);
if ( !access(v7, 0) )
{
PrintOutput(v7);
printf("[%s] :NEW FILE NAME EXISTS,OVERWRITTING IT\n", v7);
remove(v7);
}
*_errno_location() = 0;
v6 = open(v7, 66, 420LL);
v4 = v6;
if ( v6 == -1 )
{
perror("creating");
}
else if ( (unsigned int)func4(fd[0], v6, a2) == -1 )
{
puts("Compaction problem");
v4 = -1;
}
}
else if ( v3 )
{
v4 = -1;
}
else if ( write(fd[0], &buf, 4uLL) == 4 )
{
buf = 0;
if ( write(fd[0], &buf, 4uLL) != 4 )
{
perror("write total");
v4 = -1;
}
}
else
{
perror("write magic number");
v4 = -1;
}
return v4;
}

original_code:
int InitializeHayStack(char *WorkFile,CorePtr Core){
 if(WorkFile==((void *)0)) return -1;
 int FileDes,NewDes;
 int Result;
 int num=76;
 char TimeBuffer[256];
 char Name[strlen(WorkFile)+strlen("New_")+1];
 if( (Result=CheckFile( WorkFile, &FileDes))==-1){printf("Result problem\n");return -1;}
 if(Result==1){
  sprintf(Name,"%s%s","New_",WorkFile);
  PrintOutput(TimeBuffer);
  printf("[%s] :BOOTSTRAP COMPACTION IN TO NEW FILE :|%s|\n",TimeBuffer,Name);
  if( access(Name, 0)==0){PrintOutput(TimeBuffer); printf("[%s] :NEW FILE NAME EXISTS,OVERWRITTING IT\n",TimeBuffer); remove(Name); }
  (*__errno_location ())=0;
  if (( NewDes = open(Name ,0100| 02, 0644 ))== -1){perror("creating");return -1;}
  if(Compaction(FileDes,NewDes, Core)==-1){printf("Compaction problem\n");return -1;}
  return NewDes;
 }
 else if(Result==0){
  if(write(FileDes, &num, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  num=0;
  if(write(FileDes, &num, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
  return FileDes;
 }
 return -1;
}

canonical_original_code:
int InitializeHayStack(char *WorkFile, struct Core *Core){
 if(WorkFile==((void *)0)) return -1;
 int FileDes; int NewDes;
 int Result;
 int num = 76;
 char TimeBuffer[256];
 char Name[-1];
 if( (Result=CheckFile( WorkFile, &FileDes))==-1){printf("Result problem\n");return -1;}
 if(Result==1){
  sprintf(Name,"%s%s","New_",WorkFile);
  PrintOutput(TimeBuffer);
  printf("[%s] :BOOTSTRAP COMPACTION IN TO NEW FILE :|%s|\n",TimeBuffer,Name);
  if( access(Name, 0)==0){PrintOutput(TimeBuffer); printf("[%s] :NEW FILE NAME EXISTS,OVERWRITTING IT\n",TimeBuffer); remove(Name); }
  (*__errno_location ())=0;
  if (( NewDes = open(Name ,0100| 02, 0644 ))== -1){perror("creating");return -1;}
  if(Compaction(FileDes,NewDes, Core)==-1){printf("Compaction problem\n");return -1;}
  return NewDes;
 }
 else if(Result==0){
  if(write(FileDes, &num, sizeof(int))!=sizeof(int)){perror("write magic number");return -1;}
  num=0;
  if(write(FileDes, &num, sizeof(int))!=sizeof(int)){perror("write total");return -1;}
  return FileDes;
 }
 return -1;
}

variable_types:
WorkFile
char *

variable_types: FileDes int

variable_types: Result int

variable_types:
TimeBuffer
char [256]

variable_types:
Name
char [-1]


QueueAdd

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

if ( a1 )
{
v2 = malloc(0x10uLL);
if ( v2 )
{
*(_DWORD *)v2 = a2;
v2[1] = 0LL;
if ( *a1 )
*(_QWORD *)(a1[1] + 8LL) = v2;
else
*a1 = v2;
a1[1] = v2;
result = 0LL;
}
else
{
perror("Malloc");
result = 0xFFFFFFFFLL;
}
}
else
{
puts("error ,null queue");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
v2 = malloc(0x10uLL);
if ( v2 )
{
*(_DWORD *)v2 = a2;
v2[1] = 0LL;
if ( *a1 )
*(_QWORD *)(a1[1] + 8LL) = v2;
else
*a1 = v2;
a1[1] = v2;
result = 0LL;
}
else
{
perror("Malloc");
result = 0xFFFFFFFFLL;
}
}
else
{
puts("error ,null queue");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int QueueAdd(QueuePtr Queue,int Element){
 NodePtr Temp;
  if(Queue==((void *)0)){printf("error ,null queue\n");return -1;}
  if((Temp=(NodePtr)malloc(sizeof(struct Node)))==((void *)0) ){perror("Malloc");return -1;}
  Temp->Element=Element;
  Temp->Next=((void *)0);
  if(Queue->Start==((void *)0)){
   Queue->Start=Temp;
   Queue->End=Temp;
  }
  else{
   Queue->End->Next=Temp;
   Queue->End=Temp;
  }
  return 0;
 }

canonical_original_code:
int QueueAdd(struct Queue *Queue, int Element){
 struct Node *Temp;
  if(Queue==((void *)0)){printf("error ,null queue\n");return -1;}
  if((Temp=(struct Node *)malloc(sizeof(struct Node)))==((void *)0) ){perror("Malloc");return -1;}
  Temp->Element=Element;
  Temp->Next=((void *)0);
  if(Queue->Start==((void *)0)){
   Queue->Start=Temp;
   Queue->End=Temp;
  }
  else{
   Queue->End->Next=Temp;
   Queue->End=Temp;
  }
  return 0;
 }

variable_types: struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } *

variable_types: Element int


QueueRemoveHead

decompiled_code:
__int64 __fastcall QueueRemoveHead(__int64 a1, _DWORD *a2)
{
_QWORD *v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
*a2 = **(_DWORD **)a1;
v3 = *(_QWORD **)a1;
*(_QWORD *)a1 = v3[1];
free(v3);
result = 0LL;
if ( !*(_QWORD *)a1 )
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
*a2 = -1;
result = 1LL;
}
}
else
{
puts("error ,null queue");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2)
{
_QWORD *v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
*a2 = **(_DWORD **)a1;
v3 = *(_QWORD **)a1;
*(_QWORD *)a1 = v3[1];
free(v3);
result = 0LL;
if ( !*(_QWORD *)a1 )
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
*a2 = -1;
result = 1LL;
}
}
else
{
puts("error ,null queue");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int QueueRemoveHead(QueuePtr Queue,int *Element){
 NodePtr Temp;
 if(Queue==((void *)0)){printf("error ,null queue\n");return -1;}
 if(Queue->Start==((void *)0) ){
  (*Element)=-1;
  return 1;
 }
 *Element=Queue->Start->Element;
 Temp=Queue->Start;
 Queue->Start=Queue->Start->Next;
 free(Temp);
 if(Queue->Start==((void *)0)){
  Queue->End=((void *)0);
 }
 return 0;
}

canonical_original_code:
int QueueRemoveHead(struct Queue *Queue, int *Element){
 struct Node *Temp;
 if(Queue==((void *)0)){printf("error ,null queue\n");return -1;}
 if(Queue->Start==((void *)0) ){
  (*Element)=-1;
  return 1;
 }
 *Element=Queue->Start->Element;
 Temp=Queue->Start;
 Queue->Start=Queue->Start->Next;
 free(Temp);
 if(Queue->Start==((void *)0)){
  Queue->End=((void *)0);
 }
 return 0;
}

variable_types:
Element
int *

variable_types: struct Node { int Element; struct Node *Next; } *


QueuePrint

decompiled_code:
__int64 __fastcall QueuePrint(unsigned int **a1)
{
unsigned int *i; // rbx
__int64 result; // rax

puts("printing Queue:");
if ( a1 )
{
for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("{%d}--->", *i);
puts("X");
result = 0LL;
}
else
{
puts("error ,null queue");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int **a1)
{
unsigned int *i; // rbx
__int64 result; // rax

puts("printing Queue:");
if ( a1 )
{
for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("{%d}--->", *i);
puts("X");
result = 0LL;
}
else
{
puts("error ,null queue");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int QueuePrint(QueuePtr Queue){
 NodePtr Start;
 printf("printing Queue:\n");
 if(Queue==((void *)0)){
  printf("error ,null queue\n");
  return -1;
 }
 Start=Queue->Start;
 while(Start!=((void *)0)){
  printf("{%d}--->",Start->Element);
  Start=Start->Next;
 }
 printf("X\n");
 return 0;
}

canonical_original_code:
int QueuePrint(struct Queue *Queue){
 struct Node *Start;
 printf("printing Queue:\n");
 if(Queue==((void *)0)){
  printf("error ,null queue\n");
  return -1;
 }
 Start=Queue->Start;
 while(Start!=((void *)0)){
  printf("{%d}--->",Start->Element);
  Start=Start->Next;
 }
 printf("X\n");
 return 0;
}


QueueDelete

decompiled_code:
__int64 __fastcall QueueDelete(_QWORD ***a1)
{
_QWORD *v2; // rax
_QWORD *i; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
for ( i = **a1; i; i = **a1 )
{
*v2 = i[1];
free(i);
v2 = *a1;
}
free(v2);
*a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD ***a1)
{
_QWORD *v2; // rax
_QWORD *i; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
for ( i = **a1; i; i = **a1 )
{
*v2 = i[1];
free(i);
v2 = *a1;
}
free(v2);
*a1 = 0LL;
return 0LL;
}

original_code:
int QueueDelete(QueuePtr *Queue){
 NodePtr Temp;
 if(Queue==((void *)0)){
  return -1;
 }
 while((*Queue)->Start){
  Temp=(*Queue)->Start;
  (*Queue)->Start=(*Queue)->Start->Next;
  free(Temp);
 }
 free(*Queue);
 (*Queue)=((void *)0);
 return 0;
}

canonical_original_code:
int QueueDelete(struct Queue **Queue){
 struct Node *Temp;
 if(Queue==((void *)0)){
  return -1;
 }
 while((*Queue)->Start){
  Temp=(*Queue)->Start;
  (*Queue)->Start=(*Queue)->Start->Next;
  free(Temp);
 }
 free(*Queue);
 (*Queue)=((void *)0);
 return 0;
}

variable_types: struct Queue { struct Node { int Element; struct Node *Next; } *Start; struct Node *End; } **


QueueInitiate

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

v1 = malloc(0x10uLL);
*a1 = v1;
if ( v1 )
{
*v1 = 0LL;
v1[1] = 0LL;
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

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

v1 = malloc(0x10uLL);
*a1 = v1;
if ( v1 )
{
*v1 = 0LL;
v1[1] = 0LL;
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int QueueInitiate(QueuePtr *Queue){
 if(((*Queue)=(QueuePtr)malloc(sizeof(struct Queue)))==((void *)0)){perror("malloc"); return -1;}
 (*Queue)->Start=((void *)0);
 (*Queue)->End=((void *)0);
 return 0;
}

canonical_original_code:
int QueueInitiate(struct Queue **Queue){
 if(((*Queue)=(struct Queue *)malloc(sizeof(struct Queue)))==((void *)0)){perror("malloc"); return -1;}
 (*Queue)->Start=((void *)0);
 (*Queue)->End=((void *)0);
 return 0;
}


QueueEmpty

decompiled_code:
__int64 __fastcall QueueEmpty(_QWORD *a1)
{
if ( a1 )
return *a1 == 0LL;
puts("queue is null");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
if ( a1 )
return *a1 == 0LL;
puts("queue is null");
return 0xFFFFFFFFLL;
}

original_code:
int QueueEmpty(QueuePtr Queue){
 if(Queue==((void *)0)){printf("queue is null\n");return -1;}
 if(Queue->Start==((void *)0))
  return 1;
 else
      return 0;
}

canonical_original_code:
int QueueEmpty(struct Queue *Queue){
 if(Queue==((void *)0)){printf("queue is null\n");return -1;}
 if(Queue->Start==((void *)0))
  return 1;
 else
      return 0;
}


rotl

decompiled_code:
__int64 __fastcall rotl(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

original_code:
static uint32_t rotl(uint32_t value, int shift)
{
  return (value << shift) | (value >> (32 - shift));
}

canonical_original_code:
static unsigned int rotl(unsigned int value, int shift)
{
  return (value << shift) | (value >> (32 - shift));
}

variable_types:
value
unsigned int

variable_types: shift int

return_type: unsigned int


original_code:
static uint32_t s20_littleendian(uint8_t *b)
{
  return b[0] +
         ((uint_fast16_t) b[1] << 8) +
         ((uint_fast32_t) b[2] << 16) +
         ((uint_fast32_t) b[3] << 24);
}

canonical_original_code:
static unsigned int s20_littleendian(unsigned char *b)
{
  return b[0] +
         ((unsigned long) b[1] << 8) +
         ((unsigned long) b[2] << 16) +
         ((unsigned long) b[3] << 24);
}

variable_types:
b
unsigned char *


decompiled_code:
__int64 __fastcall s20_rev_littleendian(unsigned int *a1, unsigned int a2)
{
*a1 = a2;
return HIBYTE(a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, unsigned int a2)
{
*a1 = a2;
return HIBYTE(a2);
}

original_code:
static void s20_rev_littleendian(uint8_t *b, uint32_t w)
{
  b[0] = w;
  b[1] = w >> 8;
  b[2] = w >> 16;
  b[3] = w >> 24;
}

canonical_original_code:
static void s20_rev_littleendian(unsigned char *b, unsigned int w)
{
  b[0] = w;
  b[1] = w >> 8;
  b[2] = w >> 16;
  b[3] = w >> 24;
}

variable_types:
w
unsigned int


decompiled_code:
__int64 __fastcall s20_hash(__int64 a1)
{
__int64 i; // rbx
int v2; // eax
int v3; // ebx
__int64 j; // rbx
unsigned int v5; // esi
__int64 result; // rax
int v7[36]; // [rsp+0h] [rbp-90h] BYREF

for ( i = 0LL; i != 16; ++i )
{
v2 = s20_littleendian((unsigned __int8 *)(a1 + i * 4));
v7[i] = v2;
v7[i + 16] = v2;
}
v3 = 10;
do
{
s20_doubleround(v7);
--v3;
}
while ( v3 );
for ( j = 0LL; j != 16; ++j )
{
v5 = v7[j] + v7[j + 16];
v7[j] = v5;
result = s20_rev_littleendian((unsigned int *)(a1 + j * 4), v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 i; // rbx
int v2; // eax
int v3; // ebx
__int64 j; // rbx
unsigned int v5; // esi
__int64 result; // rax
int v7[36]; // [rsp+0h] [rbp-90h] BYREF

for ( i = 0LL; i != 16; ++i )
{
v2 = func12((unsigned __int8 *)(a1 + i * 4));
v7[i] = v2;
v7[i + 16] = v2;
}
v3 = 10;
do
{
func11(v7);
--v3;
}
while ( v3 );
for ( j = 0LL; j != 16; ++j )
{
v5 = v7[j] + v7[j + 16];
v7[j] = v5;
result = func13((unsigned int *)(a1 + j * 4), v5);
}
return result;
}

original_code:
static void s20_hash(uint8_t seq[static 64])
{
  int i;
  uint32_t x[16];
  uint32_t z[16];
  for (i = 0; i < 16; ++i)
    x[i] = z[i] = s20_littleendian(seq + (4 * i));
  for (i = 0; i < 10; ++i)
    s20_doubleround(z);
  for (i = 0; i < 16; ++i) {
    z[i] += x[i];
    s20_rev_littleendian(seq + (4 * i), z[i]);
  }
}

canonical_original_code:
static void s20_hash(unsigned char seq[64])
{
  int i;
  unsigned int x[16];
  unsigned int z[16];
  for (i = 0; i < 16; ++i)
    x[i] = z[i] = s20_littleendian(seq + (4 * i));
  for (i = 0; i < 10; ++i)
    s20_doubleround(z);
  for (i = 0; i < 16; ++i) {
    z[i] += x[i];
    s20_rev_littleendian(seq + (4 * i), z[i]);
  }
}

variable_types:
seq
unsigned char [64]

variable_types: i int

variable_types:
x
unsigned int [16]

variable_types:
z
unsigned int [16]


canonical_original_code:
static void s20_expand16(unsigned char *k, unsigned char n[16], unsigned char keystream[64])
{
  int i; int j;
  unsigned char t[4][4] = {
    { 'e', 'x', 'p', 'a' },
    { 'n', 'd', ' ', '1' },
    { '6', '-', 'b', 'y' },
    { 't', 'e', ' ', 'k' }
  };
  for (i = 0; i < 64; i += 20)
    for (j = 0; j < 4; ++j)
      keystream[i + j] = t[i / 20][j];
  for (i = 0; i < 16; ++i) {
    keystream[4+i] = k[i];
    keystream[44+i] = k[i];
    keystream[24+i] = n[i];
  }
  s20_hash(keystream);
}

variable_types:
k
unsigned char *

variable_types:
n
unsigned char [16]

variable_types:
keystream
unsigned char [64]

variable_types: j int

variable_types:
t
unsigned char [4][4]


canonical_original_code:
static void s20_expand32(unsigned char *k, unsigned char n[16], unsigned char keystream[64])
{
  int i; int j;
  unsigned char o[4][4] = {
    { 'e', 'x', 'p', 'a' },
    { 'n', 'd', ' ', '3' },
    { '2', '-', 'b', 'y' },
    { 't', 'e', ' ', 'k' }
  };
  for (i = 0; i < 64; i += 20)
    for (j = 0; j < 4; ++j)
      keystream[i + j] = o[i / 20][j];
  for (i = 0; i < 16; ++i) {
    keystream[4+i] = k[i];
    keystream[44+i] = k[i+16];
    keystream[24+i] = n[i];
  }
  s20_hash(keystream);
}

variable_types:
o
unsigned char [4][4]


original_code:
enum s20_status_t s20_crypt(uint8_t *key,
                            enum s20_keylen_t keylen,
                            uint8_t nonce[static 8],
                            uint32_t si,
                            uint8_t *buf,
                            uint32_t buflen)
{
  uint8_t keystream[64];
  uint8_t n[16] = { 0 };
  uint32_t i;
  void (*expand)(uint8_t *, uint8_t *, uint8_t *) = ((void *)0);
  if (keylen == S20_KEYLEN_256)
    expand = s20_expand32;
  if (keylen == S20_KEYLEN_128)
    expand = s20_expand16;
  if (expand == ((void *)0) || key == ((void *)0) || nonce == ((void *)0) || buf == ((void *)0))
    return S20_FAILURE;
  for (i = 0; i < 8; ++i)
    n[i] = nonce[i];
  if (si % 64 != 0) {
    s20_rev_littleendian(n+8, si / 64);
    (*expand)(key, n, keystream);
  }
  for (i = 0; i < buflen; ++i) {
    if ((si + i) % 64 == 0) {
      s20_rev_littleendian(n+8, ((si + i) / 64));
      (*expand)(key, n, keystream);
    }
    buf[i] ^= keystream[(si + i) % 64];
  }
  return S20_SUCCESS;
}

canonical_original_code:
enum s20_status_t s20_crypt(unsigned char *key, enum s20_keylen_t keylen, unsigned char nonce[8], unsigned int si, unsigned char *buf, unsigned int buflen)
{
  unsigned char keystream[64];
  unsigned char n[16] = { 0 };
  unsigned int i;
  void (*expand)(unsigned char *, unsigned char *, unsigned char *) = ((void *)0);
  if (keylen == S20_KEYLEN_256)
    expand = s20_expand32;
  if (keylen == S20_KEYLEN_128)
    expand = s20_expand16;
  if (expand == ((void *)0) || key == ((void *)0) || nonce == ((void *)0) || buf == ((void *)0))
    return S20_FAILURE;
  for (i = 0; i < 8; ++i)
    n[i] = nonce[i];
  if (si % 64 != 0) {
    s20_rev_littleendian(n+8, si / 64);
    (*expand)(key, n, keystream);
  }
  for (i = 0; i < buflen; ++i) {
    if ((si + i) % 64 == 0) {
      s20_rev_littleendian(n+8, ((si + i) / 64));
      (*expand)(key, n, keystream);
    }
    buf[i] ^= keystream[(si + i) % 64];
  }
  return S20_SUCCESS;
}

variable_types:
key
unsigned char *

variable_types: enum s20_keylen_t { S20_KEYLEN_256=0, S20_KEYLEN_128=1 }

variable_types:
nonce
unsigned char [8]

variable_types:
si
unsigned int

variable_types:
buf
unsigned char *

variable_types:
buflen
unsigned int

variable_types:
i
unsigned int

variable_types: void (*)(unsigned char *, unsigned char *, unsigned char *)

return_type: enum s20_status_t { S20_SUCCESS=0, S20_FAILURE=1 }


main

canonical_name: main

repo: alhafoudh/fdlink

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // r12
int v5; // ebx

if ( argc != 3 )
{
fwrite("Usage: flink old-filename new-filename\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v3 = argv[1];
v4 = argv[2];
v5 = open(v3, 0, 438LL);
if ( v5 >= 0 )
{
printf("flink: %s->%s\n", v4, v3);
if ( (unsigned int)flink((unsigned int)v5, v4, 0LL) )
{
perror("flink");
exit(1);
}
exit(0);
}
fwrite("open: ", 1uLL, 6uLL, stderr);
perror(v3);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // r12
int v5; // ebx

if ( argc != 3 )
{
fwrite("Usage: flink old-filename new-filename\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v3 = argv[1];
v4 = argv[2];
v5 = open(v3, 0, 438LL);
if ( v5 >= 0 )
{
printf("flink: %s->%s\n", v4, v3);
if ( (unsigned int)func7((unsigned int)v5, v4, 0LL) )
{
perror("flink");
exit(1);
}
exit(0);
}
fwrite("open: ", 1uLL, 6uLL, stderr);
perror(v3);
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
  char *oldname, *newname;
  if (argc != 3)
  {
    fputs("Usage: flink old-filename new-filename\n", stderr);
    exit(1);
  }
  oldname = argv[1];
  newname = argv[2];
  int fd = open(oldname, 00, 0666);
  if (fd < 0)
  {
    fprintf(stderr, "open: ");
    perror(oldname);
    exit(1);
  }
  printf ("flink: %s->%s\n", newname, oldname);
  if (flink(fd, newname, 0))
  {
    perror("flink");
    exit(1);
  }
  exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *oldname; char *newname;
  if (argc != 3)
  {
    fputs("Usage: flink old-filename new-filename\n", stderr);
    exit(1);
  }
  oldname = argv[1];
  newname = argv[2];
  int fd = open(oldname, 00, 0666);
  if (fd < 0)
  {
    fprintf(stderr, "open: ");
    perror(oldname);
    exit(1);
  }
  printf ("flink: %s->%s\n", newname, oldname);
  if (flink(fd, newname, 0))
  {
    perror("flink");
    exit(1);
  }
  exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
oldname
char *

variable_types:
newname
char *

variable_types: fd int


flink

decompiled_code:
int __fastcall flink(int a1, __int64 a2)
{
int v3; // edi
int result; // eax
int v5; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+8h] [rbp-30h]
int v7; // [rsp+10h] [rbp-28h]

v3 = flinkfd_0;
if ( flinkfd_0 >= 0 || (v3 = open("/dev/flink", 0, 292LL), flinkfd_0 = v3, v3 >= 0) )
{
v5 = a1;
v6 = a2;
v7 = 0;
result = ioctl(v3, 0LL, &v5);
}
else
{
*__errno_location() = 19;
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int64 a2)
{
int v3; // edi
int result; // eax
int v5; // [rsp+0h] [rbp-38h] BYREF
__int64 v6; // [rsp+8h] [rbp-30h]
int v7; // [rsp+10h] [rbp-28h]

v3 = flinkfd_0;
if ( flinkfd_0 >= 0 || (v3 = open("/dev/flink", 0, 292LL), flinkfd_0 = v3, v3 >= 0) )
{
v5 = a1;
v6 = a2;
v7 = 0;
result = ioctl(v3, 0LL, &v5);
}
else
{
*__errno_location() = 19;
result = -1;
}
return result;
}

original_code:
int flink(unsigned int fd, const char *path, unsigned int flags)
{
  static int flinkfd = -1;
  if (flinkfd < 0)
    flinkfd = open("/dev/flink", 00, 0444);
  if (flinkfd < 0)
  {
    (*__errno_location ()) = 19;
    return -1;
  }
  struct flink data;
  data.fd = fd;
  data.path = path;
  data.flags = 0;
  return ioctl(flinkfd, 0, &data);
}

canonical_original_code:
int flink(unsigned int fd, char *path, unsigned int flags)
{
  static int flinkfd = -1;
  if (flinkfd < 0)
    flinkfd = open("/dev/flink", 00, 0444);
  if (flinkfd < 0)
  {
    (*__errno_location ()) = 19;
    return -1;
  }
  struct flink data;
  data.fd = fd;
  data.path = path;
  data.flags = 0;
  return ioctl(flinkfd, 0, &data);
}

variable_types:
fd
unsigned int

variable_types:
path
char *

variable_types:
flags
unsigned int

variable_types: flinkfd int

variable_types: struct flink { unsigned int fd; char *path; unsigned int flags; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // eax
int result; // eax
char v6[4096]; // [rsp+0h] [rbp-1818h] BYREF
char s[2056]; // [rsp+1000h] [rbp-818h] BYREF
unsigned int v8; // [rsp+1808h] [rbp-10h]
int fd[3]; // [rsp+180Ch] [rbp-Ch] BYREF

if ( argc <= 2 )
{
puts("Usage:\ntsar_clinet <address> <switch port>");
puts("Such as:./tsar_client localhost 56677");
result = 0;
}
else
{
strcpy(server_name, argv[1]);
server_port = atoi(argv[2]);
v3 = my_tcp_connect(server_name, (unsigned int)server_port, fd);
if ( v3 )
{
printf("Error: Could not connect to host %s on port %d\n", server_name, (unsigned int)server_port);
exit(2);
}
while ( 1 )
{
do
{
if ( !fgets(s, 2047, stdin) || feof(stdin) )
{
close(fd[0]);
printf("%d data packet(s) sent to host successfully.\n", v3);
exit(0);
}
strip(s);
}
while ( !s[0] );
strncpy(v6, s, 0xFFFuLL);
v6[4095] = 0;
++v3;
v8 = 4096;
v4 = sendall(fd[0]);
if ( v4 == -1 )
{
puts("Error: Could not send data to host");
close(fd[0]);
exit(3);
}
if ( v8 <= 0xFFF )
break;
printf("Notice: Sent to host:%s\n", v6);
}
printf("Warning: Sent only %d of %d bytes to host\n", v4, v8);
close(fd[0]);
result = 3;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // eax
int result; // eax
char v6[4096]; // [rsp+0h] [rbp-1818h] BYREF
char s[2056]; // [rsp+1000h] [rbp-818h] BYREF
unsigned int v8; // [rsp+1808h] [rbp-10h]
int fd[3]; // [rsp+180Ch] [rbp-Ch] BYREF

if ( argc <= 2 )
{
puts("Usage:\ntsar_clinet <address> <switch port>");
puts("Such as:./tsar_client localhost 56677");
result = 0;
}
else
{
strcpy(server_name, argv[1]);
server_port = atoi(argv[2]);
v3 = func11(server_name, (unsigned int)server_port, fd);
if ( v3 )
{
printf("Error: Could not connect to host %s on port %d\n", server_name, (unsigned int)server_port);
exit(2);
}
while ( 1 )
{
do
{
if ( !fgets(s, 2047, stdin) || feof(stdin) )
{
close(fd[0]);
printf("%d data packet(s) sent to host successfully.\n", v3);
exit(0);
}
func14(s);
}
while ( !s[0] );
strncpy(v6, s, 0xFFFuLL);
v6[4095] = 0;
++v3;
v8 = 4096;
v4 = func12(fd[0]);
if ( v4 == -1 )
{
puts("Error: Could not send data to host");
close(fd[0]);
exit(3);
}
if ( v8 <= 0xFFF )
break;
printf("Notice: Sent to host:%s\n", v6);
}
printf("Warning: Sent only %d of %d bytes to host\n", v4, v8);
close(fd[0]);
result = 3;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 struct sockaddr_in servaddr;
 char buf[4096];
 int sockfd, n;
 char *str="insert into `squid` (host_name, time) VALUES ('mmdev2.corp.alimama.com', '1273740861');insert into `squid` (host_name, time, qps, rt, r_hit, b_hit, d_hit,m_hit,fdused, fdque, objs, inmem, hot, size) VALUES ('mmdev3.corp.alimama.com', '1273740861', '1000.38', '7.00', '99.00', '90.00', '45','51','32.00', '0.00', '1060.00', '1060.00', '1054.00', '12.02');";
 sockfd = socket(2, SOCK_STREAM, 0);
 bzero(&servaddr, sizeof(servaddr));
 servaddr.sin_family = 2;
 inet_pton(2, "0.0.0.0", &servaddr.sin_addr);
 servaddr.sin_port = htons(56677);
 connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
 write(sockfd, str, strlen(str));
 printf("send %s length:%d:\n",str,strlen(str));
 close(sockfd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct sockaddr_in servaddr;
 char buf[4096];
 int sockfd; int n;
 char *str = "insert into `squid` (host_name, time) VALUES ('mmdev2.corp.alimama.com', '1273740861');insert into `squid` (host_name, time, qps, rt, r_hit, b_hit, d_hit,m_hit,fdused, fdque, objs, inmem, hot, size) VALUES ('mmdev3.corp.alimama.com', '1273740861', '1000.38', '7.00', '99.00', '90.00', '45','51','32.00', '0.00', '1060.00', '1060.00', '1054.00', '12.02');";
 sockfd = socket(2, SOCK_STREAM, 0);
 bzero(&servaddr, sizeof(servaddr));
 servaddr.sin_family = 2;
 inet_pton(2, "0.0.0.0", &servaddr.sin_addr);
 servaddr.sin_port = htons(56677);
 connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
 write(sockfd, str, strlen(str));
 printf("send %s length:%d:\n",str,strlen(str));
 close(sockfd);
 return 0;
}

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:
buf
char [4096]

variable_types: sockfd int

variable_types: n int

variable_types:
str
char *

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]; }


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

if ( (a1 & 0xFFFFFFF7) != 2 )
__assert_fail("proto == AF_INET || proto == AF_INET6", "nss_devenv.c", 0x2Bu, "PROTO_ADDRESS_SIZE");
result = 16LL;
if ( a1 != 10 )
result = 4LL;
return result;
}

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

if ( (a1 & 0xFFFFFFF7) != 2 )
__assert_fail("proto == AF_INET || proto == AF_INET6", "nss_devenv.c", 0x2Bu, "PROTO_ADDRESS_SIZE");
result = 16LL;
if ( a1 != 10 )
result = 4LL;
return result;
}

original_code:
static inline size_t PROTO_ADDRESS_SIZE(int proto) {
 ((void) sizeof ((proto == 2 || proto == 10) ? 1 : 0), __extension__ ({ if (proto == 2 || proto == 10) ; else __assert_fail ("proto == AF_INET || proto == AF_INET6", "nss_devenv.c", 43, __extension__ __PRETTY_FUNCTION__); }));
 return proto == 10 ? 16 : 4;
}

canonical_original_code:
static inline unsigned long PROTO_ADDRESS_SIZE(int proto) {
 ((void) sizeof ((proto == 2 || proto == 10) ? 1 : 0), __extension__ ({ if (proto == 2 || proto == 10) ; else __assert_fail ("proto == AF_INET || proto == AF_INET6", "nss_devenv.c", 43, __extension__ __PRETTY_FUNCTION__); }));
 return proto == 10 ? 16 : 4;
}

variable_types: proto int

return_type: unsigned long


usage

repo: allisonmachado/network-calc

decompiled_code:
void __fastcall __noreturn usage(const char *a1, const char *a2)
{
printf("\n%s\nUsage: %s <ip-addr/mask or net-addr/mask>\n\n", a2, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, const char *a2)
{
printf("\n%s\nUsage: %s <ip-addr/mask or net-addr/mask>\n\n", a2, a1);
exit(1);
}

original_code:
void usage(char * program_name, char * error_message)
{
    printf("\n%s\nUsage: %s <ip-addr/mask or net-addr/mask>\n\n", error_message, program_name);
    exit(1);
}

canonical_original_code:
void usage(char *program_name, char *error_message)
{
    printf("\n%s\nUsage: %s <ip-addr/mask or net-addr/mask>\n\n", error_message, program_name);
    exit(1);
}


decompiled_code:
__int64 __fastcall get_input_size(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int get_input_size(char *input)
{
    int size = 0;
    for(int i = 0; input[i] != 0; i++)
    {
        size++;
    }
    return size;
}

variable_types:
input
char *

variable_types: size int

variable_types: i int


decompiled_code:
__int64 __fastcall get_number_of_slashes(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1 == 47;
v1 = *v2++;
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1 == 47;
v1 = *v2++;
}
while ( v1 );
return v3;
}

original_code:
int get_number_of_slashes(char *input)
{
    int numberOfSlashes = 0;
    for(int i = 0; input[i] != 0; i++)
    {
        if (input[i] == '/') {
            numberOfSlashes++;
        }
    }
    return numberOfSlashes;
}

variable_types: numberOfSlashes int


decompiled_code:
__int64 __fastcall get_slash_position(char *a1)
{
char v1; // dl
__int64 v2; // rax
unsigned int v3; // ecx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( v1 == 47 )
break;
v1 = a1[++v2];
if ( !v1 )
return 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1)
{
char v1; // dl
__int64 v2; // rax
unsigned int v3; // ecx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( v1 == 47 )
break;
v1 = a1[++v2];
if ( !v1 )
return 0;
}
return v3;
}

original_code:
int get_slash_position(char *input)
{
    int slashPosition = 0;
    for(int i = 0; input[i] != 0; i++)
    {
        if (input[i] == '/') {
            return i;
        }
    }
    return 0;
}

variable_types: slashPosition int


decompiled_code:
_BOOL8 __fastcall is_valid_ip_address(char *cp)
{
char buf[20]; // [rsp+4h] [rbp-14h] BYREF

return inet_pton(2, cp, buf) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(char *cp)
{
char buf[20]; // [rsp+4h] [rbp-14h] BYREF

return inet_pton(2, cp, buf) != 0;
}

original_code:
int is_valid_ip_address(char *ipAddress)
{
    struct sockaddr_in sa;
    int result = inet_pton(2, ipAddress, &(sa.sin_addr));
    return result != 0;
}

variable_types:
ipAddress
char *

variable_types: result int


decompiled_code:
_BOOL8 __fastcall is_valid_mask(const char *a1)
{
char *endptr; // [rsp+8h] [rbp-10h] BYREF

return (int)strtol(a1, &endptr, 10) <= 30;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(const char *a1)
{
char *endptr; // [rsp+8h] [rbp-10h] BYREF

return (int)strtol(a1, &endptr, 10) <= 30;
}

original_code:
int is_valid_mask(char * mask_string)
{
    char *end;
    int i = strtol(mask_string, &end, 10);
    return i < 31;
}

canonical_original_code:
int is_valid_mask(char *mask_string)
{
    char *end;
    int i = strtol(mask_string, &end, 10);
    return i < 31;
}

variable_types:
end
char *


decompiled_code:
void __fastcall get_ip_string(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(_WORD *)(a2 + i) = *(unsigned __int8 *)(a1 + i);
}
}

original_code:
void get_ip_string(char * input, char * destination, int slashPosition) {
    for (int i = 0; i < slashPosition; i++) {
        destination[i] = input[i];
        destination[i + 1] = 0;
    }
}

canonical_original_code:
void get_ip_string(char *input, char *destination, int slashPosition) {
    for (int i = 0; i < slashPosition; i++) {
        destination[i] = input[i];
        destination[i + 1] = 0;
    }
}

variable_types:
destination
char *