CoreAdd

decompiled_code:
__int64 __fastcall CoreAdd(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // er12
unsigned int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // er12
unsigned int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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

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; // rbx
void *v4; // 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 )
memset(v4, 0, 4LL * 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; // rbx
void *v4; // 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 )
memset(v4, 0, 4LL * 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; } **

variable_types: Size int

variable_types: i int

return_type: int


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 v3; // er13
_DWORD *v6; // rdi
__int64 result; // rax
_DWORD *v8; // rax
__int64 v9; // rax

if ( a1 )
{
v3 = *(_DWORD *)(a1 + 8);
v6 = *(_DWORD **)a1;
if ( v3 > a2 )
{
LABEL_3:
v6[a2] = a3;
return 0LL;
}
*(_DWORD *)(a1 + 8) = 2 * a2;
v8 = realloc(v6, 8LL * a2);
*(_QWORD *)a1 = v8;
v6 = v8;
if ( v8 )
{
v9 = v3;
if ( v3 < *(_DWORD *)(a1 + 8) )
{
do
v6[v9++] = 0;
while ( *(_DWORD *)(a1 + 8) > (int)v9 );
}
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 v3; // er13
_DWORD *v6; // rdi
__int64 result; // rax
_DWORD *v8; // rax
__int64 v9; // rax

if ( a1 )
{
v3 = *(_DWORD *)(a1 + 8);
v6 = *(_DWORD **)a1;
if ( v3 > a2 )
{
LABEL_3:
v6[a2] = a3;
return 0LL;
}
*(_DWORD *)(a1 + 8) = 2 * a2;
v8 = realloc(v6, 8LL * a2);
*(_QWORD *)a1 = v8;
v6 = v8;
if ( v8 )
{
v9 = v3;
if ( v3 < *(_DWORD *)(a1 + 8) )
{
do
v6[v9++] = 0;
while ( *(_DWORD *)(a1 + 8) > (int)v9 );
}
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: Offset int

variable_types: OldSize int


PrintMatrix

decompiled_code:
__int64 __fastcall PrintMatrix(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
__int64 v3; // rdx
__int64 result; // rax

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
puts("Printing Matrix:");
if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
v2 = (unsigned int)v1;
v3 = *(unsigned int *)(*(_QWORD *)a1 + 4 * v1++);
printf("[%d]={%d}\n", v2, v3);
}
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 v2; // rsi
__int64 v3; // rdx
__int64 result; // rax

if ( a1 )
{
if ( *(_QWORD *)a1 )
{
puts("Printing Matrix:");
if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
v2 = (unsigned int)v1;
v3 = *(unsigned int *)(*(_QWORD *)a1 + 4 * v1++);
printf("[%d]={%d}\n", v2, v3);
}
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;
}


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, int *a2)
{
int v2; // er12
int v3; // eax
int v4; // eax
__int64 result; // rax
int buf; // [rsp+1Ch] [rbp-11Ch] BYREF
char v7[280]; // [rsp+20h] [rbp-118h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, int *a2)
{
int v2; // er12
int v3; // eax
int v4; // eax
__int64 result; // rax
int buf; // [rsp+1Ch] [rbp-11Ch] BYREF
char v7[280]; // [rsp+20h] [rbp-118h] BYREF

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

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:
WorkFile
char *

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, _DWORD *a5)
{
int v6; // eax
int v7; // eax
unsigned int v9; // er13
int v10; // [rsp+8h] [rbp-140h] BYREF
int v11[3]; // [rsp+Ch] [rbp-13Ch] BYREF
int buf; // [rsp+18h] [rbp-130h] BYREF
int v13; // [rsp+1Ch] [rbp-12Ch] BYREF
char v14[296]; // [rsp+20h] [rbp-128h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(int fd, int a2, int a3, int a4, _DWORD *a5)
{
int v6; // eax
int v7; // eax
unsigned int v9; // er13
int v10; // [rsp+8h] [rbp-140h] BYREF
int v11[3]; // [rsp+Ch] [rbp-13Ch] BYREF
int buf; // [rsp+18h] [rbp-130h] BYREF
int v13; // [rsp+1Ch] [rbp-12Ch] BYREF
char v14[296]; // [rsp+20h] [rbp-128h] BYREF

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

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: Id 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 v3; // [rsp+8h] [rbp-20h] BYREF
int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

v3 = 0;
if ( lseek(fd, 4LL, 0) != -1 )
{
if ( read(fd, buf, 4uLL) != 4 )
{
perror("delete read total");
return 0xFFFFFFFFLL;
}
--buf[0];
if ( lseek(fd, 4LL, 0) != -1 )
{
if ( write(fd, buf, 4uLL) != 4 )
{
LABEL_8:
perror("write total");
return 0xFFFFFFFFLL;
}
if ( lseek(fd, a2 + 4LL, 0) != -1 )
{
if ( write(fd, &v3, 4uLL) == 4 )
return 0LL;
goto LABEL_8;
}
}
}
perror("lseek");
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;
}


RestoreQueue

decompiled_code:
__int64 __fastcall RestoreQueue(__int64 a1)
{
__int64 v1; // rbx

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

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

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

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

variable_types: i 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; }


Compaction

decompiled_code:
__int64 __fastcall Compaction(int fd, int a2, __int64 a3)
{
int v3; // er15
unsigned int v4; // er13
int v5; // er14
int v6; // ebp
int v7; // er13
signed int v9; // ebp
int v10; // 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]
int buf; // [rsp+2Ch] [rbp-44Ch] BYREF
int v17; // [rsp+30h] [rbp-448h] BYREF
unsigned int v18; // [rsp+34h] [rbp-444h] BYREF
int v19; // [rsp+38h] [rbp-440h] BYREF
int v20; // [rsp+3Ch] [rbp-43Ch] BYREF
char v21[1080]; // [rsp+40h] [rbp-438h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2, __int64 a3)
{
int v3; // er15
unsigned int v4; // er13
int v5; // er14
int v6; // ebp
int v7; // er13
signed int v9; // ebp
int v10; // 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]
int buf; // [rsp+2Ch] [rbp-44Ch] BYREF
int v17; // [rsp+30h] [rbp-448h] BYREF
unsigned int v18; // [rsp+34h] [rbp-444h] BYREF
int v19; // [rsp+38h] [rbp-440h] BYREF
int v20; // [rsp+3Ch] [rbp-43Ch] BYREF
char v21[1080]; // [rsp+40h] [rbp-438h] BYREF

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

variable_types: Loop int

variable_types: Remaining int

variable_types: Size int

variable_types: MaxId int

variable_types:
Buffer
int [256]

variable_types: j int

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

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


InitializeHayStack

decompiled_code:
__int64 __fastcall InitializeHayStack(char *filename, __int64 a2)
{
void *v2; // rsp
unsigned int v3; // eax
unsigned int v4; // er12
int v6; // eax
char v7[8]; // [rsp+0h] [rbp-130h] BYREF
int fd; // [rsp+8h] [rbp-128h] BYREF
int buf; // [rsp+Ch] [rbp-124h] BYREF
char v10[288]; // [rsp+10h] [rbp-120h] 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");
return v4;
}
if ( v3 != 1 )
{
if ( !v3 )
{
if ( write(fd, &buf, 4uLL) == 4 )
{
buf = 0;
if ( write(fd, &buf, 4uLL) == 4 )
return (unsigned int)fd;
v4 = -1;
perror("write total");
return v4;
}
perror("write magic number");
}
return (unsigned int)-1;
}
sprintf(v7, "%s%s", "New_", filename);
PrintOutput(v10);
printf("[%s] :BOOTSTRAP COMPACTION IN TO NEW FILE :|%s|\n", v10, v7);
if ( !access(v7, 0) )
{
PrintOutput(v10);
printf("[%s] :NEW FILE NAME EXISTS,OVERWRITTING IT\n", v10);
remove(v7);
}
*_errno_location() = 0;
v6 = open(v7, 66, 420LL);
v4 = v6;
if ( v6 == -1 )
{
perror("creating");
}
else if ( (unsigned int)Compaction(fd, v6, a2) == -1 )
{
v4 = -1;
puts("Compaction problem");
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *filename, __int64 a2)
{
void *v2; // rsp
unsigned int v3; // eax
unsigned int v4; // er12
int v6; // eax
char v7[8]; // [rsp+0h] [rbp-130h] BYREF
int fd; // [rsp+8h] [rbp-128h] BYREF
int buf; // [rsp+Ch] [rbp-124h] BYREF
char v10[288]; // [rsp+10h] [rbp-120h] 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");
return v4;
}
if ( v3 != 1 )
{
if ( !v3 )
{
if ( write(fd, &buf, 4uLL) == 4 )
{
buf = 0;
if ( write(fd, &buf, 4uLL) == 4 )
return (unsigned int)fd;
v4 = -1;
perror("write total");
return v4;
}
perror("write magic number");
}
return (unsigned int)-1;
}
sprintf(v7, "%s%s", "New_", filename);
PrintOutput(v10);
printf("[%s] :BOOTSTRAP COMPACTION IN TO NEW FILE :|%s|\n", v10, v7);
if ( !access(v7, 0) )
{
PrintOutput(v10);
printf("[%s] :NEW FILE NAME EXISTS,OVERWRITTING IT\n", v10);
remove(v7);
}
*_errno_location() = 0;
v6 = open(v7, 66, 420LL);
v4 = v6;
if ( v6 == -1 )
{
perror("creating");
}
else if ( (unsigned int)func4(fd, v6, a2) == -1 )
{
v4 = -1;
puts("Compaction problem");
}
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
bool v3; // zf
__int64 result; // rax

if ( a1 )
{
v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *a1 == 0LL;
*(_DWORD *)v2 = a2;
v2[1] = 0LL;
if ( v3 )
*a1 = v2;
else
*(_QWORD *)(a1[1] + 8LL) = 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
bool v3; // zf
__int64 result; // rax

if ( a1 )
{
v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *a1 == 0LL;
*(_DWORD *)v2 = a2;
v2[1] = 0LL;
if ( v3 )
*a1 = v2;
else
*(_QWORD *)(a1[1] + 8LL) = 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 )
{
v3 = *(_QWORD **)a1;
if ( v3 )
{
*a2 = *(_DWORD *)v3;
*(_QWORD *)a1 = v3[1];
free(v3);
result = 0LL;
if ( !*(_QWORD *)a1 )
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
result = 1LL;
*a2 = -1;
}
}
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 )
{
v3 = *(_QWORD **)a1;
if ( v3 )
{
*a2 = *(_DWORD *)v3;
*(_QWORD *)a1 = v3[1];
free(v3);
result = 0LL;
if ( !*(_QWORD *)a1 )
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
result = 1LL;
*a2 = -1;
}
}
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 *v1; // r8
_QWORD *i; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD ***a1)
{
_QWORD *v1; // r8
_QWORD *i; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
for ( i = **a1; i; i = **a1 )
{
*v1 = i[1];
free(i);
v1 = *a1;
}
free(v1);
*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:
void __fastcall s20_rev_littleendian(_DWORD *a1, int a2)
{
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func13(_DWORD *a1, int a2)
{
*a1 = 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

return_type: void


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; // r12
const char *v4; // r13
int v5; // ebp

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; // r12
const char *v4; // r13
int v5; // ebp

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 || (flinkfd_0 = open("/dev/flink", 0, 292LL), v3 = flinkfd_0, flinkfd_0 >= 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 || (flinkfd_0 = open("/dev/flink", 0, 292LL), v3 = flinkfd_0, flinkfd_0 >= 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; // ebp
unsigned int v4; // eax
int result; // eax
int fd; // [rsp+8h] [rbp-1810h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-180Ch]
char s[2048]; // [rsp+10h] [rbp-1808h] BYREF
char dest[4104]; // [rsp+810h] [rbp-1008h] 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);
printf("%d data packet(s) sent to host successfully.\n", v3);
exit(0);
}
strip(s);
}
while ( !s[0] );
++v3;
strncpy(dest, s, 0xFFFuLL);
dest[4095] = 0;
v7 = 4096;
v4 = sendall(fd);
if ( v4 == -1 )
{
puts("Error: Could not send data to host");
close(fd);
exit(3);
}
if ( v7 <= 0xFFF )
break;
printf("Notice: Sent to host:%s\n", dest);
}
printf("Warning: Sent only %d of %d bytes to host\n", v4, v7);
close(fd);
result = 3;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
int result; // eax
int fd; // [rsp+8h] [rbp-1810h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-180Ch]
char s[2048]; // [rsp+10h] [rbp-1808h] BYREF
char dest[4104]; // [rsp+810h] [rbp-1008h] 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);
printf("%d data packet(s) sent to host successfully.\n", v3);
exit(0);
}
func14(s);
}
while ( !s[0] );
++v3;
strncpy(dest, s, 0xFFFuLL);
dest[4095] = 0;
v7 = 4096;
v4 = func12(fd);
if ( v4 == -1 )
{
puts("Error: Could not send data to host");
close(fd);
exit(3);
}
if ( v7 <= 0xFFF )
break;
printf("Notice: Sent to host:%s\n", dest);
}
printf("Warning: Sent only %d of %d bytes to host\n", v4, v7);
close(fd);
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


repo: allisonmachado/network-calc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int v4; // eax
__int64 v5; // r9
__int64 v6; // rdi
unsigned int v7; // eax
int v8; // ecx
unsigned int v9; // er12
double v10; // xmm0_8
unsigned int v12; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v13; // [rsp+10h] [rbp-38h] BYREF
unsigned int v14; // [rsp+14h] [rbp-34h] BYREF
unsigned int v15; // [rsp+18h] [rbp-30h] BYREF
char v16[4]; // [rsp+1Dh] [rbp-2Bh] BYREF
char cp[39]; // [rsp+21h] [rbp-27h] BYREF

v12 = 0;
v13 = 0;
v14 = 0;
v15 = 0;
if ( argc <= 1
|| (v3 = argv[1], v4 = get_input_size(v3, argv, envp), v4 > 18)
|| (unsigned int)get_number_of_slashes(v3, argv, envp, (unsigned int)v4) != 1
|| (v6 = v5, v7 = get_slash_position(v5), (v9 = v7) == 0)
|| v8 - 1 == v7
|| (get_ip_string(v6, cp, v7), !(unsigned int)is_valid_ip_address(cp))
|| (get_mask_string(argv[1], v16, v9), !(unsigned int)is_valid_mask(v16)) )
{
usage(*argv, "You must provide a valid ip/mask", envp);
}
putchar(10);
printf("Entry: %s\n", argv[1]);
putchar(10);
handle_input(argv[1]);
v12 = mask_number & ip_number;
v13 = (mask_number & ip_number) + ~mask_number;
v15 = v13 - 1;
v14 = (mask_number & ip_number) + 1;
printf("Network address: ");
putchar(9);
binary_print(v12);
putchar(9);
print_ip_address(&v12);
putchar(10);
printf("Netmask: ");
putchar(9);
binary_print((unsigned int)mask_number);
putchar(9);
print_ip_address(&mask_number);
printf("(%d bits)", (unsigned int)number_of_mask_bits);
putchar(10);
printf("Broadcast addr: ");
putchar(9);
binary_print(v13);
putchar(9);
print_ip_address(&v13);
putchar(10);
printf("Min Host value: ");
putchar(9);
binary_print(v14);
putchar(9);
print_ip_address(&v14);
putchar(10);
printf("Max Host value: ");
putchar(9);
binary_print(v15);
putchar(9);
print_ip_address(&v15);
putchar(10);
putchar(10);
v10 = pow(2.0, (double)(32 - number_of_mask_bits));
printf("The possible number of hosts on this network is %d.\n", (unsigned int)((int)v10 - 2));
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int v4; // eax
__int64 v5; // r9
__int64 v6; // rdi
unsigned int v7; // eax
int v8; // ecx
unsigned int v9; // er12
double v10; // xmm0_8
unsigned int v12; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v13; // [rsp+10h] [rbp-38h] BYREF
unsigned int v14; // [rsp+14h] [rbp-34h] BYREF
unsigned int v15; // [rsp+18h] [rbp-30h] BYREF
char v16[4]; // [rsp+1Dh] [rbp-2Bh] BYREF
char cp[39]; // [rsp+21h] [rbp-27h] BYREF

v12 = 0;
v13 = 0;
v14 = 0;
v15 = 0;
if ( argc <= 1
|| (v3 = argv[1], v4 = func8(v3, argv, envp), v4 > 18)
|| (unsigned int)func9(v3, argv, envp, (unsigned int)v4) != 1
|| (v6 = v5, v7 = func10(v5), (v9 = v7) == 0)
|| v8 - 1 == v7
|| (func13(v6, cp, v7), !(unsigned int)func11(cp))
|| (func14(argv[1], v16, v9), !(unsigned int)func12(v16)) )
{
func7(*argv, "You must provide a valid ip/mask", envp);
}
putchar(10);
printf("Entry: %s\n", argv[1]);
putchar(10);
func17(argv[1]);
v12 = mask_number & ip_number;
v13 = (mask_number & ip_number) + ~mask_number;
v15 = v13 - 1;
v14 = (mask_number & ip_number) + 1;
printf("Network address: ");
putchar(9);
func16(v12);
putchar(9);
func15(&v12);
putchar(10);
printf("Netmask: ");
putchar(9);
func16((unsigned int)mask_number);
putchar(9);
func15(&mask_number);
printf("(%d bits)", (unsigned int)number_of_mask_bits);
putchar(10);
printf("Broadcast addr: ");
putchar(9);
func16(v13);
putchar(9);
func15(&v13);
putchar(10);
printf("Min Host value: ");
putchar(9);
func16(v14);
putchar(9);
func15(&v14);
putchar(10);
printf("Max Host value: ");
putchar(9);
func16(v15);
putchar(9);
func15(&v15);
putchar(10);
putchar(10);
v10 = pow(2.0, (double)(32 - number_of_mask_bits));
printf("The possible number of hosts on this network is %d.\n", (unsigned int)((int)v10 - 2));
putchar(10);
return 0;
}

original_code:
int main(int argc, char ** argv)
{
    unsigned int network_address = 0;
    unsigned int broadcast = 0;
    unsigned int host_min = 0;
    unsigned int host_max = 0;
    double number_of_hosts_bits = 0;
    char ip_string[15];
    char mask_string[4];
    if(argc < 2)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int inputSize = get_input_size(argv[1]);
    if (inputSize > 18)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int numberOfSlashes = get_number_of_slashes(argv[1]);
    if (numberOfSlashes != 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int slashPosition = get_slash_position(argv[1]);
    if (slashPosition == 0 || slashPosition == inputSize - 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_ip_string(argv[1], ip_string, slashPosition);
    if (!is_valid_ip_address(ip_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_mask_string(argv[1], mask_string, slashPosition);
    if (!is_valid_mask(mask_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    printf("\n");
    printf("Entry: %s\n", argv[1]);
    printf("\n");
    handle_input(argv[1]);
    network_address = ip_number & mask_number;
    broadcast = ~(mask_number);
    broadcast = broadcast + network_address;
    host_min = network_address + 1;
    host_max = broadcast - 1;
    printf("Network address: ");
    printf("\t");
    binary_print(network_address);
    printf("\t");
    print_ip_address(&network_address);
    printf("\n");
    printf("Netmask:          ");
    printf("\t");
    binary_print(mask_number);
    printf("\t");
    print_ip_address(&mask_number);
    printf("(%d bits)", number_of_mask_bits);
    printf("\n");
    printf("Broadcast addr:   ");
    printf("\t");
    binary_print(broadcast);
    printf("\t");
    print_ip_address(&broadcast);
    printf("\n");
    printf("Min Host value:   ");
    printf("\t");
    binary_print(host_min);
    printf("\t");
    print_ip_address(&host_min);
    printf("\n");
    printf("Max Host value:   ");
    printf("\t");
    binary_print(host_max);
    printf("\t");
    print_ip_address(&host_max);
    printf("\n");
    printf("\n");
    number_of_hosts_bits = 32 - number_of_mask_bits;
    printf("The possible number of hosts on this network is %d.\n", (int)pow(2, number_of_hosts_bits) - 2);
    printf("\n");
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned int network_address = 0;
    unsigned int broadcast = 0;
    unsigned int host_min = 0;
    unsigned int host_max = 0;
    double number_of_hosts_bits = 0;
    char ip_string[15];
    char mask_string[4];
    if(argc < 2)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int inputSize = get_input_size(argv[1]);
    if (inputSize > 18)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int numberOfSlashes = get_number_of_slashes(argv[1]);
    if (numberOfSlashes != 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    int slashPosition = get_slash_position(argv[1]);
    if (slashPosition == 0 || slashPosition == inputSize - 1)
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_ip_string(argv[1], ip_string, slashPosition);
    if (!is_valid_ip_address(ip_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    get_mask_string(argv[1], mask_string, slashPosition);
    if (!is_valid_mask(mask_string))
    {
        usage(argv[0], "You must provide a valid ip/mask");
    }
    printf("\n");
    printf("Entry: %s\n", argv[1]);
    printf("\n");
    handle_input(argv[1]);
    network_address = ip_number & mask_number;
    broadcast = ~(mask_number);
    broadcast = broadcast + network_address;
    host_min = network_address + 1;
    host_max = broadcast - 1;
    printf("Network address: ");
    printf("\t");
    binary_print(network_address);
    printf("\t");
    print_ip_address(&network_address);
    printf("\n");
    printf("Netmask:          ");
    printf("\t");
    binary_print(mask_number);
    printf("\t");
    print_ip_address(&mask_number);
    printf("(%d bits)", number_of_mask_bits);
    printf("\n");
    printf("Broadcast addr:   ");
    printf("\t");
    binary_print(broadcast);
    printf("\t");
    print_ip_address(&broadcast);
    printf("\n");
    printf("Min Host value:   ");
    printf("\t");
    binary_print(host_min);
    printf("\t");
    print_ip_address(&host_min);
    printf("\n");
    printf("Max Host value:   ");
    printf("\t");
    binary_print(host_max);
    printf("\t");
    print_ip_address(&host_max);
    printf("\n");
    printf("\n");
    number_of_hosts_bits = 32 - number_of_mask_bits;
    printf("The possible number of hosts on this network is %d.\n", (int)pow(2, number_of_hosts_bits) - 2);
    printf("\n");
}

variable_types:
argv
char **

variable_types:
broadcast
unsigned int

variable_types: inputSize int

variable_types: numberOfSlashes int

variable_types: slashPosition int


usage

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; // er8

if ( !*a1 )
return 0LL;
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; // er8

if ( !*a1 )
return 0LL;
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
_BYTE *v2; // rdi
unsigned int v3; // er8

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

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

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
++v2;
v3 += v1 == 47;
v1 = *(v2 - 1);
}
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;
}


decompiled_code:
__int64 __fastcall get_slash_position(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
result = 0LL;
while ( v1 != 47 )
{
v1 = a1[++result];
if ( !v1 )
return 0LL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
result = 0LL;
while ( v1 != 47 )
{
v1 = a1[++result];
if ( !v1 )
return 0LL;
}
return (unsigned int)result;
}

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


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 *


decompiled_code:
__int64 __fastcall get_mask_string(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 result; // rax
char v5; // dl
__int64 v6; // rdi

v3 = a3;
result = a3 + 1;
v5 = *(_BYTE *)(a1 + result);
if ( v5 )
{
result = 0LL;
v6 = v3 + a1;
do
{
*(_BYTE *)(a2 + result) = v5;
*(_BYTE *)(a2 + result++ + 1) = 0;
v5 = *(_BYTE *)(v6 + result + 1);
}
while ( v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 result; // rax
char v5; // dl
__int64 v6; // rdi

v3 = a3;
result = a3 + 1;
v5 = *(_BYTE *)(a1 + result);
if ( v5 )
{
result = 0LL;
v6 = v3 + a1;
do
{
*(_BYTE *)(a2 + result) = v5;
*(_BYTE *)(a2 + result++ + 1) = 0;
v5 = *(_BYTE *)(v6 + result + 1);
}
while ( v5 );
}
return result;
}

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

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

variable_types: j int


decompiled_code:
int __fastcall print_ip_address(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx

v1 = a1 + 2;
printf("%d", a1[3]);
while ( 1 )
{
putchar(46);
printf("%d", *v1);
if ( v1 == a1 )
break;
--v1;
}
return putchar(32);
}

canonical_decompiled_code:
int __fastcall func15(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx

v1 = a1 + 2;
printf("%d", a1[3]);
while ( 1 )
{
putchar(46);
printf("%d", *v1);
if ( v1 == a1 )
break;
--v1;
}
return putchar(32);
}

original_code:
void print_ip_address(int * number_addr)
{
    unsigned char * raw_ptr;
    int i, aux_int;
    raw_ptr = (unsigned char *) number_addr;
    for (i = 3; i > -1; i--)
    {
        aux_int = raw_ptr[i];
        printf("%d", aux_int);
        if(i != 0)
            printf(".");
    }
    printf(" ");
}

canonical_original_code:
void print_ip_address(int *number_addr)
{
    unsigned char *raw_ptr;
    int i; int aux_int;
    raw_ptr = (unsigned char *) number_addr;
    for (i = 3; i > -1; i--)
    {
        aux_int = raw_ptr[i];
        printf("%d", aux_int);
        if(i != 0)
            printf(".");
    }
    printf(" ");
}


decompiled_code:
int __fastcall binary_print(int a1)
{
unsigned int v1; // er13
int i; // er12
int v3; // ebp
unsigned int v4; // ebx
int result; // eax

v1 = -16777216;
for ( i = 24; i != -8; i -= 8 )
{
v3 = 8;
v4 = (v1 & a1) >> i;
putchar(32);
do
{
while ( (v4 & 0x80u) != 0 )
{
v4 *= 2;
result = putchar(49);
if ( !--v3 )
goto LABEL_6;
}
v4 *= 2;
result = putchar(48);
--v3;
}
while ( v3 );
LABEL_6:
v1 >>= 8;
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
unsigned int v1; // er13
int i; // er12
int v3; // ebp
unsigned int v4; // ebx
int result; // eax

v1 = -16777216;
for ( i = 24; i != -8; i -= 8 )
{
v3 = 8;
v4 = (v1 & a1) >> i;
putchar(32);
do
{
while ( (v4 & 0x80u) != 0 )
{
v4 *= 2;
result = putchar(49);
if ( !--v3 )
goto LABEL_6;
}
v4 *= 2;
result = putchar(48);
--v3;
}
while ( v3 );
LABEL_6:
v1 >>= 8;
}
return result;
}

original_code:
void binary_print(unsigned int number)
{
    unsigned int mask = 0xff000000;
    unsigned int shift = 24;
    unsigned int byte, byte_iterator, bit_iterator;
    for(byte_iterator = 0; byte_iterator < 4; byte_iterator++)
    {
        byte = (number & mask) >> shift;
        printf(" ");
        for(bit_iterator = 0; bit_iterator < 8; bit_iterator++)
        {
            if(byte & 128)
                printf("1");
            else
                printf("0");
            byte <<= 1;
        }
        mask >>= 8;
        shift -= 8;
    }
}

canonical_original_code:
void binary_print(unsigned int number)
{
    unsigned int mask = 0xff000000;
    unsigned int shift = 24;
    unsigned int byte; unsigned int byte_iterator; unsigned int bit_iterator;
    for(byte_iterator = 0; byte_iterator < 4; byte_iterator++)
    {
        byte = (number & mask) >> shift;
        printf(" ");
        for(bit_iterator = 0; bit_iterator < 8; bit_iterator++)
        {
            if(byte & 128)
                printf("1");
            else
                printf("0");
            byte <<= 1;
        }
        mask >>= 8;
        shift -= 8;
    }
}

variable_types:
number
unsigned int

variable_types:
mask
unsigned int

variable_types:
shift
unsigned int

variable_types:
byte
unsigned int


decompiled_code:
__int64 __fastcall handle_input(const char *a1)
{
__int64 result; // rax
int v2; // er13
__int64 v3; // rbp
const char *v4; // rbx
int v5; // eax
char v6; // cl
int v7; // er13
__int64 v8; // rbp
int v9; // ecx
int v10; // edx

ip_number = atoi(a1) << 24;
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result )
{
v2 = 16;
LODWORD(v3) = 0;
do
{
v3 = (unsigned int)(v3 + 1);
v4 = &a1[v3];
if ( (_BYTE)result == 46 )
{
v5 = atoi(&a1[v3]);
v6 = v2;
v2 -= 8;
ip_number += v5 << v6;
}
LOBYTE(result) = *v4;
}
while ( *v4 );
result = *(unsigned __int8 *)a1;
v7 = number_of_mask_bits;
if ( (_BYTE)result )
{
LODWORD(v8) = 0;
do
{
v8 = (unsigned int)(v8 + 1);
if ( (_BYTE)result == 47 )
{
v7 += atoi(&a1[v8]);
number_of_mask_bits = v7;
}
result = (unsigned __int8)a1[v8];
}
while ( (_BYTE)result );
}
}
else
{
v7 = number_of_mask_bits;
}
if ( (unsigned int)(31 - v7) <= 0x1E )
{
LODWORD(result) = mask_number;
v9 = 31;
do
{
v10 = 1 << v9--;
result = (unsigned int)(v10 + result);
}
while ( v9 != 31 - v7 );
mask_number = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1)
{
__int64 result; // rax
int v2; // er13
__int64 v3; // rbp
const char *v4; // rbx
int v5; // eax
char v6; // cl
int v7; // er13
__int64 v8; // rbp
int v9; // ecx
int v10; // edx

ip_number = atoi(a1) << 24;
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result )
{
v2 = 16;
LODWORD(v3) = 0;
do
{
v3 = (unsigned int)(v3 + 1);
v4 = &a1[v3];
if ( (_BYTE)result == 46 )
{
v5 = atoi(&a1[v3]);
v6 = v2;
v2 -= 8;
ip_number += v5 << v6;
}
LOBYTE(result) = *v4;
}
while ( *v4 );
result = *(unsigned __int8 *)a1;
v7 = number_of_mask_bits;
if ( (_BYTE)result )
{
LODWORD(v8) = 0;
do
{
v8 = (unsigned int)(v8 + 1);
if ( (_BYTE)result == 47 )
{
v7 += atoi(&a1[v8]);
number_of_mask_bits = v7;
}
result = (unsigned __int8)a1[v8];
}
while ( (_BYTE)result );
}
}
else
{
v7 = number_of_mask_bits;
}
if ( (unsigned int)(31 - v7) <= 0x1E )
{
LODWORD(result) = mask_number;
v9 = 31;
do
{
v10 = 1 << v9--;
result = (unsigned int)(v10 + result);
}
while ( v9 != 31 - v7 );
mask_number = result;
}
return result;
}

original_code:
void handle_input(char * string)
{
    unsigned int i, shift, temp = 0;
    shift = 24;
    ip_number = (atoi(&string[0]) << shift);
    shift -= 8;
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 46)
        {
            ip_number += (atoi(&string[i + 1]) << shift);
            shift -= 8;
        }
    }
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 47)
        {
            number_of_mask_bits += atoi(&string[i + 1]);
        }
    }
    for(i = 31; i > (31 - number_of_mask_bits); i--)
    {
        temp = (1 << i);
        mask_number += temp;
    }
}

canonical_original_code:
void handle_input(char *string)
{
    unsigned int i; unsigned int shift; unsigned int temp = 0;
    shift = 24;
    ip_number = (atoi(&string[0]) << shift);
    shift -= 8;
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 46)
        {
            ip_number += (atoi(&string[i + 1]) << shift);
            shift -= 8;
        }
    }
    for(i = 0; string[i] != 0; i++)
    {
        if(string[i] == 47)
        {
            number_of_mask_bits += atoi(&string[i + 1]);
        }
    }
    for(i = 31; i > (31 - number_of_mask_bits); i--)
    {
        temp = (1 << i);
        mask_number += temp;
    }
}

variable_types:
string
char *

variable_types:
i
unsigned int

variable_types:
temp
unsigned int