decompiled_code:
__int64 __fastcall Send_Packet_a1_a1(__int64 a1)
{
return SendPacket(a1, &Packet_a1_a1, 4LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return SendPacket(a1, &Packet_a1_a1, 4LL, 255LL);
}

original_code:
inline BYTE Send_Packet_a1_a1(int Device)
{
  return SendPacket(Device, Packet_a1_a1, sizeof(Packet_a1_a1), 255);
}

canonical_original_code:
inline unsigned char Send_Packet_a1_a1(int Device)
{
  return SendPacket(Device, Packet_a1_a1, sizeof(Packet_a1_a1), 255);
}


decompiled_code:
__int64 __fastcall Send_Packet_a1_d0(__int64 a1)
{
return SendPacket(a1, &Packet_a1_d0, 4LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return SendPacket(a1, &Packet_a1_d0, 4LL, 0LL);
}

original_code:
inline BYTE Send_Packet_a1_d0(int Device)
{
  return SendPacket(Device, Packet_a1_d0, sizeof(Packet_a1_d0), 0);
}

canonical_original_code:
inline unsigned char Send_Packet_a1_d0(int Device)
{
  return SendPacket(Device, Packet_a1_d0, sizeof(Packet_a1_d0), 0);
}

variable_types: Device int

return_type: unsigned char


decompiled_code:
__int64 __fastcall Send_Packet_a4_e0(__int64 a1)
{
return SendPacket(a1, &Packet_a4_e0, 4LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return SendPacket(a1, &Packet_a4_e0, 4LL, 255LL);
}

original_code:
inline BYTE Send_Packet_a4_e0(int Device)
{
  return SendPacket(Device, Packet_a4_e0, sizeof(Packet_a4_e0), 255);
}

canonical_original_code:
inline unsigned char Send_Packet_a4_e0(int Device)
{
  return SendPacket(Device, Packet_a4_e0, sizeof(Packet_a4_e0), 255);
}


decompiled_code:
__int64 __fastcall Send_Packet_a0_d0(__int64 a1)
{
return SendPacket(a1, &Packet_a0_d0, 38LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return SendPacket(a1, &Packet_a0_d0, 38LL, 0LL);
}

original_code:
inline BYTE Send_Packet_a0_d0(int Device)
{
  return SendPacket(Device, Packet_a0_d0, sizeof(Packet_a0_d0), 0);
}

canonical_original_code:
inline unsigned char Send_Packet_a0_d0(int Device)
{
  return SendPacket(Device, Packet_a0_d0, sizeof(Packet_a0_d0), 0);
}


decompiled_code:
__int64 __fastcall Send_Packet_a5_e0(__int64 a1)
{
return SendPacket(a1, &Packet_a5_e0, 12LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return SendPacket(a1, &Packet_a5_e0, 12LL, 255LL);
}

original_code:
inline BYTE Send_Packet_a5_e0(int Device)
{
  return SendPacket(Device, Packet_a5_e0, sizeof(Packet_a5_e0), 255);
}

canonical_original_code:
inline unsigned char Send_Packet_a5_e0(int Device)
{
  return SendPacket(Device, Packet_a5_e0, sizeof(Packet_a5_e0), 255);
}


StartTimer

decompiled_code:
int __fastcall StartTimer(__int64 a1, __int64 a2)
{
int result; // eax

result = gettimeofday((struct timeval *)a1, 0LL);
*(_QWORD *)(a1 + 16) = a2;
*(_BYTE *)(a1 + 24) = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
int result; // eax

result = gettimeofday((struct timeval *)a1, 0LL);
*(_QWORD *)(a1 + 16) = a2;
*(_BYTE *)(a1 + 24) = 0;
return result;
}

original_code:
void StartTimer(TTimeId *ID, long uSec)
{
  gettimeofday(&ID->StartTime, ((void *)0));
  ID->Delay = uSec;
  ID->Done = 0;
}

canonical_original_code:
void StartTimer(struct TTimeId *ID, long uSec)
{
  gettimeofday(&ID->StartTime, ((void *)0));
  ID->Delay = uSec;
  ID->Done = 0;
}

variable_types: struct TTimeId { struct timeval { long tv_sec; long tv_usec; } StartTime; long Delay; unsigned char Done; } *

variable_types: uSec long

return_type: void

user_defined_types: struct TTimeId { struct timeval StartTime; long Delay; unsigned char Done; }


Timeout

decompiled_code:
__int64 __fastcall Timeout(__int64 a1)
{
unsigned int v1; // ebp
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

v1 = *(unsigned __int8 *)(a1 + 24);
if ( (_BYTE)v1 )
return 1;
gettimeofday(&v3, 0LL);
if ( *(_QWORD *)(a1 + 16) <= v3.tv_usec + 1000000 * (v3.tv_sec - *(_QWORD *)a1) - *(_QWORD *)(a1 + 8) )
{
*(_BYTE *)(a1 + 24) = 1;
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

v1 = *(unsigned __int8 *)(a1 + 24);
if ( (_BYTE)v1 )
return 1;
gettimeofday(&v3, 0LL);
if ( *(_QWORD *)(a1 + 16) <= v3.tv_usec + 1000000 * (v3.tv_sec - *(_QWORD *)a1) - *(_QWORD *)(a1 + 8) )
{
*(_BYTE *)(a1 + 24) = 1;
v1 = 1;
}
return v1;
}

original_code:
BOOL Timeout(TTimeId *ID)
{
  struct timeval t;
  long diff;
  if(ID->Done)
    return 1;
  gettimeofday(&t, ((void *)0));
  diff = t.tv_sec - ID->StartTime.tv_sec;
  diff = diff * 1000000L + t.tv_usec - ID->StartTime.tv_usec;
  if(diff >= ID->Delay)
  {
   ID->Done = 1;
   return 1;
  }
  return 0;
}

canonical_original_code:
unsigned char Timeout(struct TTimeId *ID)
{
  struct timeval t;
  long diff;
  if(ID->Done)
    return 1;
  gettimeofday(&t, ((void *)0));
  diff = t.tv_sec - ID->StartTime.tv_sec;
  diff = diff * 1000000L + t.tv_usec - ID->StartTime.tv_usec;
  if(diff >= ID->Delay)
  {
   ID->Done = 1;
   return 1;
  }
  return 0;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: diff long


decompiled_code:
bool __fastcall HasLBP800(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
char v3; // r12
bool result; // al

v1 = Parport_Open();
if ( v1 == -1 )
{
fprintf(stderr, "parcapt:HasLBP No printer found at %s\n", a1);
result = 0;
}
else
{
v2 = v1;
v3 = InitPrinter(v1);
Parport_Close(v2);
fprintf(stderr, "parcapt:HasLBP Printer found at %s\n", a1);
result = v3 == 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
char v3; // r12
bool result; // al

v1 = Parport_Open();
if ( v1 == -1 )
{
fprintf(stderr, "parcapt:HasLBP No printer found at %s\n", a1);
result = 0;
}
else
{
v2 = v1;
v3 = InitPrinter(v1);
Parport_Close(v2);
fprintf(stderr, "parcapt:HasLBP Printer found at %s\n", a1);
result = v3 == 0;
}
return result;
}

original_code:
BOOL HasLBP800(char *DeviceName)
{
  BYTE Status=0;
  int Device=0;
  Device = Parport_Open(DeviceName);
  if (Device == -1){
     fprintf(stderr,"parcapt:HasLBP No printer found at %s\n",DeviceName);
    return 0;
 }
  Status = InitPrinter(Device) ;
  Parport_Close(Device);
  fprintf(stderr,"parcapt:HasLBP Printer found at %s\n",DeviceName);
  return (Status == 0x00);
}

canonical_original_code:
unsigned char HasLBP800(char *DeviceName)
{
  unsigned char Status = 0;
  int Device = 0;
  Device = Parport_Open(DeviceName);
  if (Device == -1){
     fprintf(stderr,"parcapt:HasLBP No printer found at %s\n",DeviceName);
    return 0;
 }
  Status = InitPrinter(Device) ;
  Parport_Close(Device);
  fprintf(stderr,"parcapt:HasLBP Printer found at %s\n",DeviceName);
  return (Status == 0x00);
}

variable_types:
DeviceName
char *

variable_types:
Status
unsigned char


getLastDifference

original_code:
int getLastDifference(TLineBuf LineBuf, BYTE CurLine)
{
  int iPos;
  BYTE *CurrPtr = LineBuf[CurLine] + 592;
  BYTE *PrevPtr = LineBuf[CurLine ? 0 : 1] + 592;
  iPos = 592;
  while( (*(--CurrPtr) == *(--PrevPtr)) && iPos)
    iPos--;
  return iPos;
}

canonical_original_code:
int getLastDifference(unsigned char LineBuf[2][592], unsigned char CurLine)
{
  int iPos;
  unsigned char *CurrPtr = LineBuf[CurLine] + 592;
  unsigned char *PrevPtr = LineBuf[CurLine ? 0 : 1] + 592;
  iPos = 592;
  while( (*(--CurrPtr) == *(--PrevPtr)) && iPos)
    iPos--;
  return iPos;
}

variable_types:
LineBuf
unsigned char [2][592]

variable_types:
CurLine
unsigned char

variable_types: iPos int

variable_types:
CurrPtr
unsigned char *

variable_types:
PrevPtr
unsigned char *

return_type: int


sign

repo: alesgaroth/mauve-db

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

result = (unsigned int)a1;
if ( a1 )
result = (a1 >> 31) | 1u;
return result;
}

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

result = (unsigned int)a1;
if ( a1 )
result = (a1 >> 31) | 1u;
return result;
}

variable_types: v int


decompiled_code:
__int64 __fastcall RowMatcher2(__int64 a1, const char *a2)
{
int v2; // eax

v2 = strcasecmp(*(const char **)(a1 + 8), a2);
return sign(v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
int v2; // eax

v2 = strcasecmp(*(const char **)(a1 + 8), a2);
return func0(v2);
}

original_code:
int RowMatcher2(Row r_, Closure c){
 struct row *r = (struct row*)r_;
 char *key = (char *)c;
 return sign(strcasecmp(r->name, key));
}

canonical_original_code:
int RowMatcher2(void *r_, void *c){
 struct row *r = (struct row*)r_;
 char *key = (char *)c;
 return sign(strcasecmp(r->name, key));
}

variable_types:
c
void *

variable_types: struct row { long size; char *name; char *value; } *

variable_types:
key
char *


reporter

decompiled_code:
void __fastcall __noreturn reporter(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "%s:%d: %s\n", a1, a2, a3);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "%s:%d: %s\n", a1, a2, a3);
exit(1);
}

original_code:
void reporter(const char *file, int line, const char *error){
 fprintf(stderr, "%s:%d: %s\n", file, line, error);
 exit(1);
}

canonical_original_code:
void reporter(char *file, int line, char *error){
 fprintf(stderr, "%s:%d: %s\n", file, line, error);
 exit(1);
}

variable_types:
file
char *

variable_types: line int

variable_types:
error
char *


doinsert

decompiled_code:
__int64 __fastcall doinsert(__int64 a1, __int64 a2, __int64 a3, const char *a4, unsigned int a5)
{
__int64 result; // rax
__int64 (__fastcall *v8)(__int64, __int64); // [rsp+0h] [rbp-28h] BYREF
_QWORD *v9; // [rsp+8h] [rbp-20h]

v8 = RowMatcher;
v9 = newRow(a2, a3);
result = tree_insert(a1, v9, &v8);
if ( !result )
reporter(a4, a5, "expected tree_insert; returned NULL;");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, const char *a4, unsigned int a5)
{
__int64 result; // rax
__int64 (__fastcall *v8)(__int64, __int64); // [rsp+0h] [rbp-28h] BYREF
_QWORD *v9; // [rsp+8h] [rbp-20h]

v8 = RowMatcher;
v9 = newRow(a2, a3);
result = tree_insert(a1, v9, &v8);
if ( !result )
func3(a4, a5, "expected tree_insert; returned NULL;");
return result;
}

original_code:
TreeNode doinsert(TreeNode tn, char *key, char *value, char *file, int line){
 Row r = newRow(key, value);
 struct lookUp lu = { RowMatcher, r};
 tn = tree_insert(tn, r, &lu);
 if (!tn) reporter(file, line, "expected tree_insert;  returned NULL;");
 return tn;
}

canonical_original_code:
void *doinsert(void *tn, char *key, char *value, char *file, int line){
 void *r = newRow(key, value);
 struct lookUp lu = { RowMatcher, r};
 tn = tree_insert(tn, r, &lu);
 if (!tn) reporter(file, line, "expected tree_insert;  returned NULL;");
 return tn;
}

variable_types:
tn
void *

variable_types:
value
char *

variable_types:
r
void *

variable_types: struct lookUp { int (*m)(void *datum, void *c); void *c; }

return_type: void *


dolookup

decompiled_code:
int __fastcall dolookup(__int64 a1, __int64 a2, const char *a3, const char *a4, unsigned int a5)
{
__int64 v8; // rax
int result; // eax
__int64 v10[5]; // [rsp+0h] [rbp-28h] BYREF

v10[0] = (__int64)RowMatcher2;
v10[1] = a2;
v8 = tree_findSingle(a1, v10);
if ( !v8 )
reporter(a4, a5, "looked up by key failed");
result = strcasecmp(*(const char **)(v8 + 16), a3);
if ( result )
reporter(a4, a5, "looked up by key failed");
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, const char *a3, const char *a4, unsigned int a5)
{
__int64 v8; // rax
int result; // eax
__int64 v10[5]; // [rsp+0h] [rbp-28h] BYREF

v10[0] = (__int64)RowMatcher2;
v10[1] = a2;
v8 = tree_findSingle(a1, v10);
if ( !v8 )
func3(a4, a5, "looked up by key failed");
result = strcasecmp(*(const char **)(v8 + 16), a3);
if ( result )
func3(a4, a5, "looked up by key failed");
return result;
}

original_code:
void dolookup(TreeNode tn, char *key, char *value, char *file, int line){
 struct lookUp lu = (struct lookUp){ RowMatcher2, key};
 Row v = tree_findSingle(tn, &lu);
 if (!v) reporter(file, line, "looked up by key failed");
 if (strcasecmp(((struct row*)v)->value, value)) reporter(file, line, "looked up by key failed");
}

canonical_original_code:
void dolookup(void *tn, char *key, char *value, char *file, int line){
 struct lookUp lu = (struct lookUp){ RowMatcher2, key};
 void *v = tree_findSingle(tn, &lu);
 if (!v) reporter(file, line, "looked up by key failed");
 if (strcasecmp(((struct row *)v)->value, value)) reporter(file, line, "looked up by key failed");
}

variable_types:
v
void *

user_defined_types: struct lookUp { int (*m)(void *datum, void *c); void *c; }

user_defined_types: struct row { long size; char *name; char *value; }


dolookupf

decompiled_code:
__int64 __fastcall dolookupf(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[0] = (__int64)RowMatcher2;
v7[1] = a2;
result = tree_findSingle(a1, v7);
if ( result )
reporter(a3, a4, "found key in the tree we should not have");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[0] = (__int64)RowMatcher2;
v7[1] = a2;
result = tree_findSingle(a1, v7);
if ( result )
func3(a3, a4, "found key in the tree we should not have");
return result;
}

original_code:
void dolookupf(TreeNode tn, char *key, char *file, int line){
 struct lookUp lu = (struct lookUp){ RowMatcher2, key};
 Row v = tree_findSingle(tn, &lu);
 if (v) reporter(file, line, "found key in the tree we should not have");
}

canonical_original_code:
void dolookupf(void *tn, char *key, char *file, int line){
 struct lookUp lu = (struct lookUp){ RowMatcher2, key};
 void *v = tree_findSingle(tn, &lu);
 if (v) reporter(file, line, "found key in the tree we should not have");
}


dodelete

decompiled_code:
__int64 __fastcall dodelete(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[0] = (__int64)RowMatcher2;
v7[1] = a2;
result = tree_deleteSingle(a1, v7);
if ( !result )
reporter(a3, a4, "expected tree_delete; returned NULL;");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, const char *a3, unsigned int a4)
{
__int64 result; // rax
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[0] = (__int64)RowMatcher2;
v7[1] = a2;
result = tree_deleteSingle(a1, v7);
if ( !result )
func3(a3, a4, "expected tree_delete; returned NULL;");
return result;
}

original_code:
TreeNode dodelete(TreeNode tn, char *key, char *file, int line){
 struct lookUp lu = (struct lookUp){ RowMatcher2, key};
 tn = tree_deleteSingle(tn, &lu);
 if (!tn) reporter(file, line, "expected tree_delete;  returned NULL;");
 return tn;
}

canonical_original_code:
void *dodelete(void *tn, char *key, char *file, int line){
 struct lookUp lu = (struct lookUp){ RowMatcher2, key};
 tn = tree_deleteSingle(tn, &lu);
 if (!tn) reporter(file, line, "expected tree_delete;  returned NULL;");
 return tn;
}


printRow

decompiled_code:
int __fastcall printRow(__int64 a1)
{
return printf("%s: %s", *(const char **)(a1 + 8), *(const char **)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
return printf("%s: %s", *(const char **)(a1 + 8), *(const char **)(a1 + 16));
}

original_code:
void printRow(Row r_){
 struct row *r = (struct row*)r_;
 printf("%s: %s", r->name, r->value);
}

canonical_original_code:
void printRow(void *r_){
 struct row *r = (struct row*)r_;
 printf("%s: %s", r->name, r->value);
}


decompiled_code:
__int64 __fastcall heap_alloc(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 result; // rax
char *v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx

v1 = (a1 + 7) & 0xFFFFFFFFFFFFFFF8LL;
if ( !v1 )
_assert_fail("numbytes && \"heap_alloc called for nothing\"", "memman.c", 0xFu, "heap_alloc");
if ( !mem )
{
mem = (__int64)mymem;
mymem[2] = 0x4000000LL;
mymem[0] = (__int64)sbrk(0x4000000LL);
*(_QWORD *)(mem + 8) = *(_QWORD *)mem;
}
if ( *(_QWORD *)(mem + 8) + v1 > *(_QWORD *)mem + *(_QWORD *)(mem + 16) )
{
v3 = (char *)sbrk(0x4000000LL);
v4 = mem;
v5 = *(_QWORD *)mem;
if ( *(_QWORD *)(mem + 8) >= *(_QWORD *)(mem + 16) + *(_QWORD *)mem )
{
*(_QWORD *)(mem + 8) = v3;
*(_QWORD *)(v4 + 16) = &v3[-v5];
}
*(_QWORD *)(v4 + 16) += 0x4000000LL;
}
result = *(_QWORD *)(mem + 8);
*(_QWORD *)(mem + 8) = result + v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rbx
__int64 result; // rax
char *v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx

v1 = (a1 + 7) & 0xFFFFFFFFFFFFFFF8LL;
if ( !v1 )
_assert_fail("numbytes && \"heap_alloc called for nothing\"", "memman.c", 0xFu, "heap_alloc");
if ( !mem )
{
mem = (__int64)mymem;
mymem[2] = 0x4000000LL;
mymem[0] = (__int64)sbrk(0x4000000LL);
*(_QWORD *)(mem + 8) = *(_QWORD *)mem;
}
if ( *(_QWORD *)(mem + 8) + v1 > *(_QWORD *)mem + *(_QWORD *)(mem + 16) )
{
v3 = (char *)sbrk(0x4000000LL);
v4 = mem;
v5 = *(_QWORD *)mem;
if ( *(_QWORD *)(mem + 8) >= *(_QWORD *)(mem + 16) + *(_QWORD *)mem )
{
*(_QWORD *)(mem + 8) = v3;
*(_QWORD *)(v4 + 16) = &v3[-v5];
}
*(_QWORD *)(v4 + 16) += 0x4000000LL;
}
result = *(_QWORD *)(mem + 8);
*(_QWORD *)(mem + 8) = result + v1;
return result;
}

original_code:
void *heap_alloc(size_t numbytes){
 numbytes = (numbytes+7)&(-8);
 ((numbytes && "heap_alloc called for nothing") ? (void) (0) : __assert_fail ("numbytes && \"heap_alloc called for nothing\"", "memman.c", 15, __extension__ __PRETTY_FUNCTION__));
 if (!mem){
  mem = &mymem;
  mem->sizeofmemory = 64 * 1024 *1024;
  mem->startofmem = sbrk(mem->sizeofmemory);
  mem->nexttoalloc = mem->startofmem;
 }
 if (mem->nexttoalloc + numbytes > mem->startofmem + mem->sizeofmemory){
  void *newmem = sbrk(64 * 1024 *1024);
  if (mem->nexttoalloc >= mem->sizeofmemory + mem->startofmem){
   mem->nexttoalloc = newmem;
   mem->sizeofmemory = mem->nexttoalloc - mem->startofmem;
  }
  mem->sizeofmemory += 64 * 1024 *1024;
 }
 void *rmem = mem->nexttoalloc;
 mem->nexttoalloc += numbytes;
 return rmem;
}

canonical_original_code:
void *heap_alloc(unsigned long numbytes){
 numbytes = (numbytes+7)&(-8);
 ((numbytes && "heap_alloc called for nothing") ? (void) (0) : __assert_fail ("numbytes && \"heap_alloc called for nothing\"", "memman.c", 15, __extension__ __PRETTY_FUNCTION__));
 if (!mem){
  mem = &mymem;
  mem->sizeofmemory = 64 * 1024 *1024;
  mem->startofmem = sbrk(mem->sizeofmemory);
  mem->nexttoalloc = mem->startofmem;
 }
 if (mem->nexttoalloc + numbytes > mem->startofmem + mem->sizeofmemory){
  void *newmem = sbrk(64 * 1024 *1024);
  if (mem->nexttoalloc >= mem->sizeofmemory + mem->startofmem){
   mem->nexttoalloc = newmem;
   mem->sizeofmemory = mem->nexttoalloc - mem->startofmem;
  }
  mem->sizeofmemory += 64 * 1024 *1024;
 }
 void *rmem = mem->nexttoalloc;
 mem->nexttoalloc += numbytes;
 return rmem;
}

variable_types:
numbytes
unsigned long

variable_types:
newmem
void *

variable_types:
rmem
void *


rdtsc

repo: alex-guoba/SHM-Ring-Buffer

decompiled_code:
unsigned __int64 rdtsc()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func0()
{
return __rdtsc();
}

original_code:
static inline uint64_t
rdtsc()
{
    unsigned int lo, hi;
    __asm__ __volatile__ (
            "rdtsc"
            : "=a" (lo), "=d" (hi)
            );
    return (uint64_t)hi << 32 | lo;
}

canonical_original_code:
static inline unsigned long rdtsc()
{
    unsigned int lo; unsigned int hi;
    __asm__ __volatile__ (
            "rdtsc"
            : "=a" (lo), "=d" (hi)
            );
    return (unsigned long)hi << 32 | lo;
}

variable_types:
lo
unsigned int

variable_types:
hi
unsigned int

return_type: unsigned long


CalcCpuFreq

decompiled_code:
unsigned __int64 CalcCpuFreq()
{
unsigned __int64 v0; // rbx

v0 = rdtsc();
Sleep(0x64u);
return 10 * (rdtsc() - v0);
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned __int64 v0; // rbx

v0 = func0();
func2(0x64u);
return 10 * (func0() - v0);
}

original_code:
static uint64_t
CalcCpuFreq()
{
    uint64_t t1;
    uint64_t t2;
    t1 = rdtsc();
    Sleep(100);
    t2 = rdtsc();
    return (t2-t1)*10;
}

canonical_original_code:
static unsigned long CalcCpuFreq()
{
    unsigned long t1;
    unsigned long t2;
    t1 = rdtsc();
    Sleep(100);
    t2 = rdtsc();
    return (t2-t1)*10;
}


decompiled_code:
void __fastcall shmtx_init(__int64 a1, __int64 a2, int a3)
{
*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 8) = a3;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, int a3)
{
*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 8) = a3;
}

original_code:
void shmtx_init(shmctx_t *mtx, shmtx_sh_t *addr, unsigned int spin) {
    mtx->lock = &addr->lock;
    mtx->spin = spin;
}

canonical_original_code:
void shmtx_init(struct shmctx_t *mtx, struct shmtx_sh_t *addr, unsigned int spin) {
    mtx->lock = &addr->lock;
    mtx->spin = spin;
}

variable_types: struct shmctx_t { unsigned long *lock; unsigned int spin; } *

variable_types: struct shmtx_sh_t { unsigned long lock; } *

variable_types:
spin
unsigned int


decompiled_code:
__int64 __fastcall shmctx_trylock(volatile signed __int64 **a1, signed __int64 a2)
{
__int64 result; // rax

LODWORD(result) = 0;
if ( !**a1 )
LODWORD(result) = _InterlockedCompareExchange64(*a1, a2, 0LL) == 0;
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func6(volatile signed __int64 **a1, signed __int64 a2)
{
__int64 result; // rax

LODWORD(result) = 0;
if ( !**a1 )
LODWORD(result) = _InterlockedCompareExchange64(*a1, a2, 0LL) == 0;
return (int)result;
}

original_code:
uint_t shmctx_trylock(shmctx_t *mtx, uint_t id) {
    return (*mtx->lock == 0 && __sync_bool_compare_and_swap(mtx->lock, 0, id));
}

canonical_original_code:
unsigned long shmctx_trylock(struct shmctx_t *mtx, unsigned long id) {
    return (*mtx->lock == 0 && __sync_bool_compare_and_swap(mtx->lock, 0, id));
}

variable_types:
id
unsigned long

user_defined_types: struct shmctx_t { unsigned long *lock; unsigned int spin; }


decompiled_code:
_BOOL8 __fastcall shmtx_unlock(volatile signed __int64 **a1, signed __int64 a2)
{
return a2 == _InterlockedCompareExchange64(*a1, 0LL, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(volatile signed __int64 **a1, signed __int64 a2)
{
return a2 == _InterlockedCompareExchange64(*a1, 0LL, a2);
}

original_code:
uint_t shmtx_unlock(shmctx_t *mtx, uint_t id) {
    return __sync_bool_compare_and_swap(mtx->lock, id, 0);
}

canonical_original_code:
unsigned long shmtx_unlock(struct shmctx_t *mtx, unsigned long id) {
    return __sync_bool_compare_and_swap(mtx->lock, id, 0);
}


decompiled_code:
__int64 __fastcall shmtx_force_unlock(volatile __int64 **a1)
{
return _InterlockedExchange64(*a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(volatile __int64 **a1)
{
return _InterlockedExchange64(*a1, 0LL);
}

original_code:
uint_t shmtx_force_unlock(shmctx_t *mtx) {
    return __sync_lock_test_and_set(mtx->lock, 0);
}

canonical_original_code:
unsigned long shmtx_force_unlock(struct shmctx_t *mtx) {
    return __sync_lock_test_and_set(mtx->lock, 0);
}


decompiled_code:
signed __int64 __fastcall shmtx_lock(__int64 a1, signed __int64 a2)
{
__int64 v2; // rbp
int v3; // edx
int v4; // eax
signed __int64 result; // rax

if ( !ticks_per_second_4 )
ticks_per_second_4 = GetCpuFreq();
v2 = 0LL;
while ( 1 )
{
if ( !**(_QWORD **)a1 )
{
result = _InterlockedCompareExchange64(*(volatile signed __int64 **)a1, a2, 0LL);
if ( !result )
return result;
}
v3 = 1;
if ( *(_DWORD *)(a1 + 8) > 1u )
{
do
{
v4 = 0;
if ( v3 > 0 )
{
do
{
_mm_pause();
++v4;
}
while ( v4 != v3 );
v2 += (unsigned int)(v3 - 1) + 1LL;
}
if ( !**(_QWORD **)a1 )
{
result = _InterlockedCompareExchange64(*(volatile signed __int64 **)a1, a2, 0LL);
if ( !result )
return result;
}
v3 *= 2;
}
while ( *(_DWORD *)(a1 + 8) > (unsigned int)v3 );
}
if ( ticks_per_second_4 / 0x32uLL < ++v2 )
{
shmtx_force_unlock((volatile __int64 **)a1);
v2 = 0LL;
}
sched_yield();
}
}

canonical_decompiled_code:
signed __int64 __fastcall func9(__int64 a1, signed __int64 a2)
{
__int64 v2; // rbp
int v3; // edx
int v4; // eax
signed __int64 result; // rax

if ( !ticks_per_second_4 )
ticks_per_second_4 = func4();
v2 = 0LL;
while ( 1 )
{
if ( !**(_QWORD **)a1 )
{
result = _InterlockedCompareExchange64(*(volatile signed __int64 **)a1, a2, 0LL);
if ( !result )
return result;
}
v3 = 1;
if ( *(_DWORD *)(a1 + 8) > 1u )
{
do
{
v4 = 0;
if ( v3 > 0 )
{
do
{
_mm_pause();
++v4;
}
while ( v4 != v3 );
v2 += (unsigned int)(v3 - 1) + 1LL;
}
if ( !**(_QWORD **)a1 )
{
result = _InterlockedCompareExchange64(*(volatile signed __int64 **)a1, a2, 0LL);
if ( !result )
return result;
}
v3 *= 2;
}
while ( *(_DWORD *)(a1 + 8) > (unsigned int)v3 );
}
if ( ticks_per_second_4 / 0x32uLL < ++v2 )
{
func8((volatile __int64 **)a1);
v2 = 0LL;
}
sched_yield();
}
}

original_code:
void shmtx_lock(shmctx_t *mtx, uint_t id) {
    int i, n;
    static unsigned long long ticks_per_second = 0;
    unsigned long long ticks_nop = 0;
    if (__builtin_expect((ticks_per_second == 0),0)) {
        ticks_per_second = GetCpuFreq();
    }
    for ( ;; ) {
        if (*mtx->lock == 0 && __sync_bool_compare_and_swap(mtx->lock, 0, id)) {
            return;
        }
        for (n = 1; n < mtx->spin; n <<= 1) {
            for (i = 0; i < n; i++) {
                __asm__ ("pause");
                ticks_nop++;
            }
            if (*mtx->lock == 0 && __sync_bool_compare_and_swap(mtx->lock, 0, id)) {
                return;
            }
        }
        if (++ticks_nop > ticks_per_second/50) {
            shmtx_force_unlock(mtx);
            ticks_nop = 0;
        }
        sched_yield();
    }
}

canonical_original_code:
void shmtx_lock(struct shmctx_t *mtx, unsigned long id) {
    int i; int n;
    static unsigned long long ticks_per_second = 0;
    unsigned long long ticks_nop = 0;
    if (__builtin_expect((ticks_per_second == 0),0)) {
        ticks_per_second = GetCpuFreq();
    }
    for ( ;; ) {
        if (*mtx->lock == 0 && __sync_bool_compare_and_swap(mtx->lock, 0, id)) {
            return;
        }
        for (n = 1; n < mtx->spin; n <<= 1) {
            for (i = 0; i < n; i++) {
                __asm__ ("pause");
                ticks_nop++;
            }
            if (*mtx->lock == 0 && __sync_bool_compare_and_swap(mtx->lock, 0, id)) {
                return;
            }
        }
        if (++ticks_nop > ticks_per_second/50) {
            shmtx_force_unlock(mtx);
            ticks_nop = 0;
        }
        sched_yield();
    }
}

variable_types: i int

variable_types: n int


decompiled_code:
__int64 __fastcall ringbuf_init(__int64 a1, __int64 a2, key_t a3)
{
int v3; // eax
_QWORD *v4; // rax
_QWORD *v5; // rbx

v3 = shmget(a3, a2 * a1 + 344, 896);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = shmat(v3, 0LL, 0);
v5 = v4;
if ( v4 == (_QWORD *)-1LL )
return 4294967294LL;
shm = v4;
v4[32] = a1;
v4[33] = a2;
shmtx_init((__int64)&mutex_w, (__int64)v4, 2048);
shmtx_init((__int64)&mutex_r, (__int64)(v5 + 8), 2048);
return 0LL;
}

original_code:
int ringbuf_init(size_t size, size_t n, int key) {
    size_t initsize = 0;
    void *addr = ((void *)0);
    char *ch;
    int id;
    initsize = sizeof(shm_data_t) + size * n;
    id = shmget(key, initsize, 0400|0200|01000);
    if (id == 0)
        return -1;
    addr = shmat(id, ((void *)0), 0);
    if (addr == (void*)-1)
        return -2;
    shm = (shm_data_t*)addr;
    shm->size = size;
    shm->max = n;
    ch = shm->channel;
    shmtx_init(&mutex_w, (shmtx_sh_t*)ch, 0x800);
    shmtx_init(&mutex_r, (shmtx_sh_t*)(ch + 64), 0x800);
    return 0;
}

canonical_original_code:
int ringbuf_init(unsigned long size, unsigned long n, int key) {
    unsigned long initsize = 0;
    void *addr = ((void *)0);
    char *ch;
    int id;
    initsize = sizeof(shm_data_t) + size * n;
    id = shmget(key, initsize, 0400|0200|01000);
    if (id == 0)
        return -1;
    addr = shmat(id, ((void *)0), 0);
    if (addr == (void *)-1)
        return -2;
    shm = (struct shm_data_t *)addr;
    shm->size = size;
    shm->max = n;
    ch = shm->channel;
    shmtx_init(&mutex_w, (struct shmtx_sh_t *)ch, 0x800);
    shmtx_init(&mutex_r, (struct shmtx_sh_t *)(ch + 64), 0x800);
    return 0;
}

variable_types:
size
unsigned long

variable_types:
n
unsigned long

variable_types: key int

variable_types:
initsize
unsigned long

variable_types:
addr
void *

variable_types:
ch
char *

variable_types: id int

user_defined_types: struct shm_data_t { char channel[256]; unsigned long size; unsigned long max; unsigned int index_r; unsigned int index_w; char pending[60]; char datas[]; }

user_defined_types: struct shmtx_sh_t { unsigned long lock; }


decompiled_code:
__int64 __fastcall ringbuf_push(void *src, size_t n)
{
volatile signed __int32 *v2; // rbx
unsigned __int32 v3; // er12
signed __int32 v4; // er14
__int64 result; // rax

if ( *((_QWORD *)shm + 32) < n )
return 0xFFFFFFFFLL;
if ( !pid_2 )
pid_2 = getpid();
shmtx_lock((__int64)&mutex_w, pid_2);
v2 = (volatile signed __int32 *)shm;
v3 = *((_DWORD *)shm + 69);
v4 = (unsigned __int64)(v3 + 1) % *((_QWORD *)shm + 33);
if ( *((_DWORD *)shm + 68) == v4 )
{
shmtx_unlock((volatile signed __int64 **)&mutex_w, pid_2);
result = 1LL;
}
else
{
memcpy((char *)shm + *((_QWORD *)shm + 32) * v3 + 340, src, n);
_InterlockedCompareExchange(v2 + 69, v4, v3);
shmtx_unlock((volatile signed __int64 **)&mutex_w, pid_2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *src, size_t n)
{
volatile signed __int32 *v2; // rbx
unsigned __int32 v3; // er12
signed __int32 v4; // er14
__int64 result; // rax

if ( *((_QWORD *)shm + 32) < n )
return 0xFFFFFFFFLL;
if ( !pid_2 )
pid_2 = getpid();
func9((__int64)&mutex_w, pid_2);
v2 = (volatile signed __int32 *)shm;
v3 = *((_DWORD *)shm + 69);
v4 = (unsigned __int64)(v3 + 1) % *((_QWORD *)shm + 33);
if ( *((_DWORD *)shm + 68) == v4 )
{
func7((volatile signed __int64 **)&mutex_w, pid_2);
result = 1LL;
}
else
{
memcpy((char *)shm + *((_QWORD *)shm + 32) * v3 + 340, src, n);
_InterlockedCompareExchange(v2 + 69, v4, v3);
func7((volatile signed __int64 **)&mutex_w, pid_2);
result = 0LL;
}
return result;
}

original_code:
int ringbuf_push(const char *value, size_t len) {
    static pid_t pid = 0;
 if (__builtin_expect((len > shm->size),0))
  return -1;
    if (__builtin_expect((pid == 0),0))
        pid = getpid();
    shmtx_lock(&mutex_w, pid);
    uint32_t index_w = shm->index_w;
    uint32_t next = ((index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        shmtx_unlock(&mutex_w, pid);
        return Cache_Full;
    }
    memcpy(shm->datas + index_w * shm->size, value, len);
    __sync_bool_compare_and_swap(&shm->index_w, index_w, next);
    if (!shmtx_unlock(&mutex_w, pid)) {
    }
    return 0;
}

canonical_original_code:
int ringbuf_push(char *value, unsigned long len) {
    static int pid = 0;
 if (__builtin_expect((len > shm->size),0))
  return -1;
    if (__builtin_expect((pid == 0),0))
        pid = getpid();
    shmtx_lock(&mutex_w, pid);
    unsigned int index_w = shm->index_w;
    unsigned int next = ((index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        shmtx_unlock(&mutex_w, pid);
        return Cache_Full;
    }
    memcpy(shm->datas + index_w * shm->size, value, len);
    __sync_bool_compare_and_swap(&shm->index_w, index_w, next);
    if (!shmtx_unlock(&mutex_w, pid)) {
    }
    return 0;
}

variable_types:
value
char *

variable_types:
len
unsigned long

variable_types: pid int

variable_types:
next
unsigned int


decompiled_code:
__int64 __fastcall ringbuf_push_unlock(void *src, unsigned __int64 a2)
{
_DWORD *v2; // rbx
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rbp
__int64 result; // rax

v2 = shm;
v3 = *((_QWORD *)shm + 32);
if ( v3 < a2 )
return 0xFFFFFFFFLL;
v4 = (unsigned __int64)(unsigned int)(*((_DWORD *)shm + 69) + 1) % *((_QWORD *)shm + 33);
result = 1LL;
if ( *((_DWORD *)shm + 68) != (_DWORD)v4 )
{
memcpy((char *)shm + v3 * *((unsigned int *)shm + 69) + 340, src, *((_QWORD *)shm + 32));
v2[69] = v4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *src, unsigned __int64 a2)
{
_DWORD *v2; // rbx
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rbp
__int64 result; // rax

v2 = shm;
v3 = *((_QWORD *)shm + 32);
if ( v3 < a2 )
return 0xFFFFFFFFLL;
v4 = (unsigned __int64)(unsigned int)(*((_DWORD *)shm + 69) + 1) % *((_QWORD *)shm + 33);
result = 1LL;
if ( *((_DWORD *)shm + 68) != (_DWORD)v4 )
{
memcpy((char *)shm + v3 * *((unsigned int *)shm + 69) + 340, src, *((_QWORD *)shm + 32));
v2[69] = v4;
result = 0LL;
}
return result;
}

original_code:
int ringbuf_push_unlock(const char *value, size_t len) {
 if (__builtin_expect((len > shm->size),0))
  return -1;
    uint32_t next = ((shm->index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        return Cache_Full;
    }
    memcpy(shm->datas + shm->index_w * shm->size, value, shm->size);
    shm->index_w = next;
    return 0;
}

canonical_original_code:
int ringbuf_push_unlock(char *value, unsigned long len) {
 if (__builtin_expect((len > shm->size),0))
  return -1;
    unsigned int next = ((shm->index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        return Cache_Full;
    }
    memcpy(shm->datas + shm->index_w * shm->size, value, shm->size);
    shm->index_w = next;
    return 0;
}


decompiled_code:
__int64 __fastcall ringbuf_push_hook(__int64 (__fastcall *a1)(char *, __int64, unsigned __int64), __int64 a2, unsigned __int64 a3)
{
unsigned __int32 v4; // ebp
signed __int32 v5; // er12
unsigned int v6; // ebx

if ( *((_QWORD *)shm + 32) < a3 )
return (unsigned int)-1;
if ( !pid_1 )
pid_1 = getpid();
shmtx_lock((__int64)&mutex_w, pid_1);
v4 = *((_DWORD *)shm + 69);
v5 = (unsigned __int64)(v4 + 1) % *((_QWORD *)shm + 33);
if ( *((_DWORD *)shm + 68) == v5 )
{
shmtx_unlock((volatile signed __int64 **)&mutex_w, pid_1);
v6 = 1;
}
else
{
v6 = a1((char *)shm + *((_QWORD *)shm + 32) * v4 + 340, a2, a3);
if ( v6 )
{
shmtx_unlock((volatile signed __int64 **)&mutex_w, pid_1);
v6 = 3;
}
else
{
_InterlockedCompareExchange((volatile signed __int32 *)shm + 69, v5, v4);
shmtx_unlock((volatile signed __int64 **)&mutex_w, pid_1);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 (__fastcall *a1)(char *, __int64, unsigned __int64), __int64 a2, unsigned __int64 a3)
{
unsigned __int32 v4; // ebp
signed __int32 v5; // er12
unsigned int v6; // ebx

if ( *((_QWORD *)shm + 32) < a3 )
return (unsigned int)-1;
if ( !pid_1 )
pid_1 = getpid();
func9((__int64)&mutex_w, pid_1);
v4 = *((_DWORD *)shm + 69);
v5 = (unsigned __int64)(v4 + 1) % *((_QWORD *)shm + 33);
if ( *((_DWORD *)shm + 68) == v5 )
{
func7((volatile signed __int64 **)&mutex_w, pid_1);
v6 = 1;
}
else
{
v6 = a1((char *)shm + *((_QWORD *)shm + 32) * v4 + 340, a2, a3);
if ( v6 )
{
func7((volatile signed __int64 **)&mutex_w, pid_1);
v6 = 3;
}
else
{
_InterlockedCompareExchange((volatile signed __int32 *)shm + 69, v5, v4);
func7((volatile signed __int64 **)&mutex_w, pid_1);
}
}
return v6;
}

original_code:
int ringbuf_push_hook(CopyFunc func, const void *value, size_t len) {
    static pid_t pid = 0;
 if (__builtin_expect((len > shm->size),0))
  return -1;
    if (__builtin_expect((pid == 0),0))
        pid = getpid();
    shmtx_lock(&mutex_w, pid);
    uint32_t index_w = shm->index_w;
    uint32_t next = ((index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        shmtx_unlock(&mutex_w, pid);
        return Cache_Full;
    }
    if(func(shm->datas + index_w * shm->size, value, len)) {
        shmtx_unlock(&mutex_w, pid);
        return Hook_Error;
    }
    __sync_bool_compare_and_swap(&shm->index_w, index_w, next);
    if (!shmtx_unlock(&mutex_w, pid)) {
    }
    return 0;
}

canonical_original_code:
int ringbuf_push_hook(int (*func)(void *dest, void *src, unsigned long n), void *value, unsigned long len) {
    static int pid = 0;
 if (__builtin_expect((len > shm->size),0))
  return -1;
    if (__builtin_expect((pid == 0),0))
        pid = getpid();
    shmtx_lock(&mutex_w, pid);
    unsigned int index_w = shm->index_w;
    unsigned int next = ((index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        shmtx_unlock(&mutex_w, pid);
        return Cache_Full;
    }
    if(func(shm->datas + index_w * shm->size, value, len)) {
        shmtx_unlock(&mutex_w, pid);
        return Hook_Error;
    }
    __sync_bool_compare_and_swap(&shm->index_w, index_w, next);
    if (!shmtx_unlock(&mutex_w, pid)) {
    }
    return 0;
}

variable_types: int (*)(void *dest, void *src, unsigned long n)

variable_types:
value
void *


decompiled_code:
__int64 __fastcall ringbuf_push_hook_unlock(__int64 (__fastcall *a1)(char *, __int64, unsigned __int64), __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rdi
unsigned __int64 v5; // rbx
__int64 result; // rax

v4 = *((_QWORD *)shm + 32);
if ( v4 < a3 )
return 0xFFFFFFFFLL;
v5 = (unsigned __int64)(unsigned int)(*((_DWORD *)shm + 69) + 1) % *((_QWORD *)shm + 33);
result = 1LL;
if ( *((_DWORD *)shm + 68) != (_DWORD)v5 )
{
result = a1((char *)shm + v4 * *((unsigned int *)shm + 69) + 340, a2, v4);
if ( (_DWORD)result )
result = 3LL;
else
*((_DWORD *)shm + 69) = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 (__fastcall *a1)(char *, __int64, unsigned __int64), __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rdi
unsigned __int64 v5; // rbx
__int64 result; // rax

v4 = *((_QWORD *)shm + 32);
if ( v4 < a3 )
return 0xFFFFFFFFLL;
v5 = (unsigned __int64)(unsigned int)(*((_DWORD *)shm + 69) + 1) % *((_QWORD *)shm + 33);
result = 1LL;
if ( *((_DWORD *)shm + 68) != (_DWORD)v5 )
{
result = a1((char *)shm + v4 * *((unsigned int *)shm + 69) + 340, a2, v4);
if ( (_DWORD)result )
result = 3LL;
else
*((_DWORD *)shm + 69) = v5;
}
return result;
}

original_code:
int ringbuf_push_hook_unlock(CopyFunc func, const void *value, size_t len) {
 if (__builtin_expect((len > shm->size),0))
  return -1;
    uint32_t next = ((shm->index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        return Cache_Full;
    }
    if(func(shm->datas + shm->index_w * shm->size, value, shm->size)) {
        return Hook_Error;
    }
    shm->index_w = next;
    return 0;
}

canonical_original_code:
int ringbuf_push_hook_unlock(int (*func)(void *dest, void *src, unsigned long n), void *value, unsigned long len) {
 if (__builtin_expect((len > shm->size),0))
  return -1;
    unsigned int next = ((shm->index_w) + 1) % (shm->max);
    if (next == shm->index_r) {
        return Cache_Full;
    }
    if(func(shm->datas + shm->index_w * shm->size, value, shm->size)) {
        return Hook_Error;
    }
    shm->index_w = next;
    return 0;
}


decompiled_code:
__int64 __fastcall ringbuf_pop(void *dest)
{
volatile signed __int32 *v1; // rbx
unsigned __int32 v2; // ebp
signed __int32 v3; // er13
__int64 result; // rax

if ( !pid_0 )
pid_0 = getpid();
shmtx_lock((__int64)&mutex_r, pid_0);
v1 = (volatile signed __int32 *)shm;
v2 = *((_DWORD *)shm + 68);
if ( *((_DWORD *)shm + 69) == v2 )
{
shmtx_unlock((volatile signed __int64 **)&mutex_r, pid_0);
result = 2LL;
}
else
{
v3 = (unsigned __int64)(v2 + 1) % *((_QWORD *)shm + 33);
memcpy(dest, (char *)shm + *((_QWORD *)shm + 32) * v2 + 340, *((_QWORD *)shm + 32));
_InterlockedCompareExchange(v1 + 68, v3, v2);
shmtx_unlock((volatile signed __int64 **)&mutex_r, pid_0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(void *dest)
{
volatile signed __int32 *v1; // rbx
unsigned __int32 v2; // ebp
signed __int32 v3; // er13
__int64 result; // rax

if ( !pid_0 )
pid_0 = getpid();
func9((__int64)&mutex_r, pid_0);
v1 = (volatile signed __int32 *)shm;
v2 = *((_DWORD *)shm + 68);
if ( *((_DWORD *)shm + 69) == v2 )
{
func7((volatile signed __int64 **)&mutex_r, pid_0);
result = 2LL;
}
else
{
v3 = (unsigned __int64)(v2 + 1) % *((_QWORD *)shm + 33);
memcpy(dest, (char *)shm + *((_QWORD *)shm + 32) * v2 + 340, *((_QWORD *)shm + 32));
_InterlockedCompareExchange(v1 + 68, v3, v2);
func7((volatile signed __int64 **)&mutex_r, pid_0);
result = 0LL;
}
return result;
}

original_code:
int ringbuf_pop(char *value) {
    static pid_t pid = 0;
    if (__builtin_expect((pid == 0),0))
        pid = getpid();
    shmtx_lock(&mutex_r, pid);
    uint32_t index_r = shm->index_r;
    if (shm->index_w == index_r) {
        shmtx_unlock(&mutex_r, pid);
        return No_Data;
    }
    uint32_t next = ((index_r) + 1) % (shm->max);
    memcpy(value, shm->datas + index_r * shm->size, shm->size);
    __sync_bool_compare_and_swap(&shm->index_r, index_r, next);
    if (!shmtx_unlock(&mutex_r, pid)) {
    }
    return 0;
}

canonical_original_code:
int ringbuf_pop(char *value) {
    static int pid = 0;
    if (__builtin_expect((pid == 0),0))
        pid = getpid();
    shmtx_lock(&mutex_r, pid);
    unsigned int index_r = shm->index_r;
    if (shm->index_w == index_r) {
        shmtx_unlock(&mutex_r, pid);
        return No_Data;
    }
    unsigned int next = ((index_r) + 1) % (shm->max);
    memcpy(value, shm->datas + index_r * shm->size, shm->size);
    __sync_bool_compare_and_swap(&shm->index_r, index_r, next);
    if (!shmtx_unlock(&mutex_r, pid)) {
    }
    return 0;
}


decompiled_code:
__int64 __fastcall ringbuf_pop_unlock(void *a1)
{
_DWORD *v1; // rbx
__int64 result; // rax

v1 = shm;
result = 2LL;
if ( *((_DWORD *)shm + 69) != *((_DWORD *)shm + 68) )
{
memcpy(a1, (char *)shm + *((_QWORD *)shm + 32) * *((unsigned int *)shm + 68) + 340, *((_QWORD *)shm + 32));
v1[68] = (unsigned __int64)(unsigned int)(v1[68] + 1) % *((_QWORD *)v1 + 33);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(void *a1)
{
_DWORD *v1; // rbx
__int64 result; // rax

v1 = shm;
result = 2LL;
if ( *((_DWORD *)shm + 69) != *((_DWORD *)shm + 68) )
{
memcpy(a1, (char *)shm + *((_QWORD *)shm + 32) * *((unsigned int *)shm + 68) + 340, *((_QWORD *)shm + 32));
v1[68] = (unsigned __int64)(unsigned int)(v1[68] + 1) % *((_QWORD *)v1 + 33);
result = 0LL;
}
return result;
}

original_code:
int ringbuf_pop_unlock(char *value) {
    if (shm->index_w == shm->index_r) {
        return No_Data;
    }
    memcpy(value, shm->datas + shm->index_r * shm->size, shm->size);
    shm->index_r = ((shm->index_r) + 1) % (shm->max);
    return 0;
}


decompiled_code:
int ringbuf_destory()
{
int result; // eax

result = shmdt(shm);
shm = 0LL;
return result;
}

canonical_decompiled_code:
int func17()
{
int result; // eax

result = shmdt(shm);
shm = 0LL;
return result;
}

original_code:
void ringbuf_destory() {
    shmdt(shm);
    shm = ((void *)0);
}


cpuid

decompiled_code:
__int64 __fastcall cpuid(unsigned int a1, _DWORD *a2)
{
__int64 result; // rax

_RAX = a1;
__asm { cpuid }
*a2 = result;
a2[1] = _RBX;
a2[2] = _RDX;
a2[3] = _RCX;
return result;
}

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

_RAX = a1;
__asm { cpuid }
*a2 = result;
a2[1] = _RBX;
a2[2] = _RDX;
a2[3] = _RCX;
return result;
}

original_code:
static inline void
cpuid(uint32_t i, uint32_t *buf)
{
    uint32_t eax, ebx, ecx, edx;
    __asm__ (
        "cpuid"
    : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (i) );
    buf[0] = eax;
    buf[1] = ebx;
    buf[2] = edx;
    buf[3] = ecx;
}

canonical_original_code:
static inline void cpuid(unsigned int i, unsigned int *buf)
{
    unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
    __asm__ (
        "cpuid"
    : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (i) );
    buf[0] = eax;
    buf[1] = ebx;
    buf[2] = edx;
    buf[3] = ecx;
}

variable_types:
i
unsigned int

variable_types:
buf
unsigned int *

variable_types:
eax
unsigned int

variable_types:
ebx
unsigned int

variable_types:
ecx
unsigned int

variable_types:
edx
unsigned int


cpuinfo

original_code:
int
cpuinfo(void)
{
    u_char *vendor;
    uint32_t vbuf[5], cpu[4], model;
    int cacheline_size;
    vbuf[0] = 0;
    vbuf[1] = 0;
    vbuf[2] = 0;
    vbuf[3] = 0;
    vbuf[4] = 0;
    cpuid(0, vbuf);
    vendor = (u_char *) &vbuf[1];
    if (vbuf[0] == 0) {
        return 0;
    }
    cpuid(1, cpu);
    if (strcmp((char*)vendor, "GenuineIntel") == 0) {
        switch ((cpu[0] & 0xf00) >> 8) {
        case 5:
            cacheline_size = 32;
            break;
        case 6:
            cacheline_size = 32;
            model = ((cpu[0] & 0xf0000) >> 8) | (cpu[0] & 0xf0);
            if (model >= 0xd0) {
                cacheline_size = 64;
            }
            break;
        case 15:
            cacheline_size = 128;
            break;
        }
    } else if (strcmp((char*)vendor, "AuthenticAMD") == 0) {
        cacheline_size = 64;
    }
    return cacheline_size;
}

canonical_original_code:
int cpuinfo()
{
    unsigned char *vendor;
    unsigned int vbuf[5]; unsigned int cpu[4]; unsigned int model;
    int cacheline_size;
    vbuf[0] = 0;
    vbuf[1] = 0;
    vbuf[2] = 0;
    vbuf[3] = 0;
    vbuf[4] = 0;
    cpuid(0, vbuf);
    vendor = (unsigned char *) &vbuf[1];
    if (vbuf[0] == 0) {
        return 0;
    }
    cpuid(1, cpu);
    if (strcmp((char *)vendor, "GenuineIntel") == 0) {
        switch ((cpu[0] & 0xf00) >> 8) {
        case 5:
            cacheline_size = 32;
            break;
        case 6:
            cacheline_size = 32;
            model = ((cpu[0] & 0xf0000) >> 8) | (cpu[0] & 0xf0);
            if (model >= 0xd0) {
                cacheline_size = 64;
            }
            break;
        case 15:
            cacheline_size = 128;
            break;
        }
    } else if (strcmp((char *)vendor, "AuthenticAMD") == 0) {
        cacheline_size = 64;
    }
    return cacheline_size;
}

variable_types:
vendor
unsigned char *

variable_types:
vbuf
unsigned int [5]

variable_types:
cpu
unsigned int [4]

variable_types:
model
unsigned int


original_code:
static void packet_handler(int sig) {
 packet_t pkt;
 pkt = get_packet();
    char* pkt_pointer;
    pkt_pointer = mm_get(&mm);
 memcpy(pkt_pointer, pkt.data, 56);
 pkt_cnt+=1;
 message.num_packets+=1;
 message.data[pkt.which]=pkt_pointer;
}

canonical_original_code:
static void packet_handler(int sig) {
 struct packet_t pkt;
 pkt = get_packet();
    char *pkt_pointer;
    pkt_pointer = mm_get(&mm);
 memcpy(pkt_pointer, pkt.data, 56);
 pkt_cnt+=1;
 message.num_packets+=1;
 message.data[pkt.which]=pkt_pointer;
}

variable_types: sig int

variable_types: struct packet_t { int how_many; int which; char data[56]; }


original_code:
static char *assemble_message() {
 char * msg;
 int i;
 msg = (char*) malloc (64 * 1000);
 for(i=0; i<=pkt_total-1; i++){
  memcpy (msg+(i*56), message.data[i], 56);
  mm_put(&mm, message.data[i]);
 }
 message.num_packets=0;
 pkt_total = 3;
 pkt_cnt = 0;
 message.num_packets = 0;
 if (msg){
  return msg;
 } else {
  (*__errno_location ())=74;
  return ((void *)0);
 };
}

canonical_original_code:
static char *assemble_message() {
 char *msg;
 int i;
 msg = (char *) malloc (64 * 1000);
 for(i=0; i<=pkt_total-1; i++){
  memcpy (msg+(i*56), message.data[i], 56);
  mm_put(&mm, message.data[i]);
 }
 message.num_packets=0;
 pkt_total = 3;
 pkt_cnt = 0;
 message.num_packets = 0;
 if (msg){
  return msg;
 } else {
  (*__errno_location ())=74;
  return ((void *)0);
 };
}

variable_types:
msg
char *

variable_types: i int

return_type: char *


decompiled_code:
double __fastcall comp_time(__int64 a1, int a2, __int64 a3, int a4)
{
double result; // xmm0_8

if ( a1 >= a3 )
result = (double)(a4 - a2);
else
result = (double)(a4 - a2 + 1000000) + (double)((int)a3 - (int)a1 - 1) * 1000000.0 + 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func9(__int64 a1, int a2, __int64 a3, int a4)
{
double result; // xmm0_8

if ( a1 >= a3 )
result = (double)(a4 - a2);
else
result = (double)(a4 - a2 + 1000000) + (double)((int)a3 - (int)a1 - 1) * 1000000.0 + 0.0;
return result;
}

original_code:
double comp_time(struct timeval time_s, struct timeval time_e) {
  double elap = 0.0;
  if (time_e.tv_sec > time_s.tv_sec) {
    elap += (time_e.tv_sec - time_s.tv_sec - 1) * 1000000.0;
    elap += time_e.tv_usec + (1000000 - time_s.tv_usec);
  }
  else {
    elap = time_e.tv_usec - time_s.tv_usec;
  }
  return elap;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: elap double

return_type: double


original_code:
int mm_init(mm_t *mm, int hm, int sz) {
  mm -> num_chunks = hm;
  mm -> chunk_size = sz;
  mm -> lowest_open = 0;
  mm -> lowest_closed = hm;
  mm -> valid = (int*) malloc (hm * sizeof(int));
  mm -> dyn_mem = (void*) malloc(hm * sz);
  if (mm->dyn_mem == ((void *)0)){
    return -1;
  }
  int i;
  for (i = 0; i < hm; i++){
    (mm -> valid)[i] = 0;
  }
  return 0;
}

canonical_original_code:
int mm_init(struct mm_t *mm, int hm, int sz) {
  mm -> num_chunks = hm;
  mm -> chunk_size = sz;
  mm -> lowest_open = 0;
  mm -> lowest_closed = hm;
  mm -> valid = (int *) malloc (hm * sizeof(int));
  mm -> dyn_mem = (void *) malloc(hm * sz);
  if (mm->dyn_mem == ((void *)0)){
    return -1;
  }
  int i;
  for (i = 0; i < hm; i++){
    (mm -> valid)[i] = 0;
  }
  return 0;
}

variable_types: struct mm_t { int num_chunks; int chunk_size; int lowest_open; int lowest_closed; int *valid; void *dyn_mem; } *

variable_types: hm int

variable_types: sz int


original_code:
void *mm_get(mm_t *mm) {
  int open, temp;
  open = mm -> lowest_open;
  if (open >= mm->num_chunks)
  {
    printf("No available memory.\n");
    return ((void *)0);
  }
  else{
    mm -> valid [open] = 1;
    if (open < mm -> lowest_closed ){
      mm -> lowest_closed = open;
    }
    temp = open;
    while (temp < mm -> num_chunks && mm -> valid[temp] != 0){
      temp++;
    }
    mm -> lowest_open = temp;
    return (void*) (mm -> dyn_mem) + open * mm->chunk_size;
  }
}

canonical_original_code:
void *mm_get(struct mm_t *mm) {
  int open; int temp;
  open = mm -> lowest_open;
  if (open >= mm->num_chunks)
  {
    printf("No available memory.\n");
    return ((void *)0);
  }
  else{
    mm -> valid [open] = 1;
    if (open < mm -> lowest_closed ){
      mm -> lowest_closed = open;
    }
    temp = open;
    while (temp < mm -> num_chunks && mm -> valid[temp] != 0){
      temp++;
    }
    mm -> lowest_open = temp;
    return (void *) (mm -> dyn_mem) + open * mm->chunk_size;
  }
}

variable_types: open int

variable_types: temp int

user_defined_types: struct mm_t { int num_chunks; int chunk_size; int lowest_open; int lowest_closed; int *valid; void *dyn_mem; }


decompiled_code:
int __fastcall mm_put(__int64 a1, __int64 a2)
{
int v3; // er9
int v4; // ecx
__int64 v5; // rdx
int v6; // edi
int result; // eax
_DWORD *v8; // rdx

v3 = *(_DWORD *)(a1 + 12);
v4 = *(_DWORD *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 24) + v3 * v4;
v6 = *(_DWORD *)a1;
if ( v5 == a2 || v3 >= v6 )
{
result = v3;
}
else
{
result = v3;
do
{
++result;
v5 += v4;
}
while ( a2 != v5 && result < v6 );
}
if ( v6 <= result )
return printf("Chunk of memory does not exist. %d, %d\n", (unsigned int)v3, *(unsigned int *)(a1 + 8));
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * result) = 0;
if ( *(_DWORD *)(a1 + 8) > result )
*(_DWORD *)(a1 + 8) = result;
if ( *(_DWORD *)(a1 + 12) == result )
{
if ( *(_DWORD *)a1 > result )
{
v8 = (_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * result);
while ( !*v8 )
{
++result;
++v8;
if ( result == *(_DWORD *)a1 )
{
result = *(_DWORD *)a1;
break;
}
}
}
*(_DWORD *)(a1 + 12) = result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1, __int64 a2)
{
int v3; // er9
int v4; // ecx
__int64 v5; // rdx
int v6; // edi
int result; // eax
_DWORD *v8; // rdx

v3 = *(_DWORD *)(a1 + 12);
v4 = *(_DWORD *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 24) + v3 * v4;
v6 = *(_DWORD *)a1;
if ( v5 == a2 || v3 >= v6 )
{
result = v3;
}
else
{
result = v3;
do
{
++result;
v5 += v4;
}
while ( a2 != v5 && result < v6 );
}
if ( v6 <= result )
return printf("Chunk of memory does not exist. %d, %d\n", (unsigned int)v3, *(unsigned int *)(a1 + 8));
*(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * result) = 0;
if ( *(_DWORD *)(a1 + 8) > result )
*(_DWORD *)(a1 + 8) = result;
if ( *(_DWORD *)(a1 + 12) == result )
{
if ( *(_DWORD *)a1 > result )
{
v8 = (_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * result);
while ( !*v8 )
{
++result;
++v8;
if ( result == *(_DWORD *)a1 )
{
result = *(_DWORD *)a1;
break;
}
}
}
*(_DWORD *)(a1 + 12) = result;
}
return result;
}

original_code:
void mm_put(mm_t *mm, void *chunk) {
  int chunk_num = mm -> lowest_closed;
  void* temp = (mm -> dyn_mem) + (chunk_num * mm -> chunk_size);
  int i = 0;
  while (chunk_num < mm -> num_chunks && temp != chunk){
    chunk_num++;
    temp += mm -> chunk_size;
  }
  if (chunk_num >= mm -> num_chunks){
    printf("Chunk of memory does not exist. %d, %d\n", mm -> lowest_closed, mm -> lowest_open);
    return;
  }
  else{
    mm->valid [chunk_num] = 0;
  }
  if (chunk_num < mm -> lowest_open){
    mm -> lowest_open = chunk_num;
  }
  if (chunk_num == mm -> lowest_closed){
   while (chunk_num < mm -> num_chunks && mm -> valid[chunk_num] == 0){
      chunk_num++;
    }
    mm -> lowest_closed = chunk_num;
  }
}

canonical_original_code:
void mm_put(struct mm_t *mm, void *chunk) {
  int chunk_num = mm -> lowest_closed;
  void *temp = (mm -> dyn_mem) + (chunk_num * mm -> chunk_size);
  int i = 0;
  while (chunk_num < mm -> num_chunks && temp != chunk){
    chunk_num++;
    temp += mm -> chunk_size;
  }
  if (chunk_num >= mm -> num_chunks){
    printf("Chunk of memory does not exist. %d, %d\n", mm -> lowest_closed, mm -> lowest_open);
    return;
  }
  else{
    mm->valid [chunk_num] = 0;
  }
  if (chunk_num < mm -> lowest_open){
    mm -> lowest_open = chunk_num;
  }
  if (chunk_num == mm -> lowest_closed){
   while (chunk_num < mm -> num_chunks && mm -> valid[chunk_num] == 0){
      chunk_num++;
    }
    mm -> lowest_closed = chunk_num;
  }
}

variable_types:
chunk
void *

variable_types:
temp
void *


original_code:
void mm_release(mm_t *mm) {
  free(mm -> valid);
  mm -> valid = ((void *)0);
  free(mm -> dyn_mem);
  mm -> dyn_mem = ((void *)0);
  mm = ((void *)0);
}

canonical_original_code:
void mm_release(struct mm_t *mm) {
  free(mm -> valid);
  mm -> valid = ((void *)0);
  free(mm -> dyn_mem);
  mm -> dyn_mem = ((void *)0);
  mm = ((void *)0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int result; // eax
__m128i *v5; // rax
__m128i *v6; // rbx
struct sigaction v7; // [rsp+0h] [rbp-B8h] BYREF

mm_init(&mm, 1000LL, 64LL);
v7.sa_handler = (__sighandler_t)packet_handler;
v7.sa_flags = 0;
if ( sigemptyset(&v7.sa_mask) == -1 || sigaction(14, &v7, 0LL) == -1 )
{
perror("Failed to set SIGALARM handler!\n");
result = -1;
}
else
{
ualarm(0x2710u, 0x186A0u);
v3 = 3;
do
{
while ( pkt_cnt < pkt_total )
pause();
v5 = assemble_message();
v6 = v5;
if ( v5 )
{
fprintf(stderr, "GOT IT: message=%s\n", v5->m128i_i8);
free(v6);
}
else
{
perror("Failed to assemble message");
}
--v3;
}
while ( v3 );
mm_release(&mm);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int result; // eax
__m128i *v5; // rax
__m128i *v6; // rbx
struct sigaction v7; // [rsp+0h] [rbp-B8h] BYREF

func10(&mm, 1000LL, 64LL);
v7.sa_handler = (__sighandler_t)packet_handler;
v7.sa_flags = 0;
if ( sigemptyset(&v7.sa_mask) == -1 || sigaction(14, &v7, 0LL) == -1 )
{
perror("Failed to set SIGALARM handler!\n");
result = -1;
}
else
{
ualarm(0x2710u, 0x186A0u);
v3 = 3;
do
{
while ( pkt_cnt < pkt_total )
pause();
v5 = func8();
v6 = v5;
if ( v5 )
{
fprintf(stderr, "GOT IT: message=%s\n", v5->m128i_i8);
free(v6);
}
else
{
perror("Failed to assemble message");
}
--v3;
}
while ( v3 );
func13(&mm);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 int i;
 char *msg;
    mm_init(&mm, 1000, 64);
    struct sigaction act;
    act.__sigaction_handler.sa_handler = packet_handler;
    act.sa_flags = 0;
    if((sigemptyset(&act.sa_mask) == -1) || (sigaction(14,&act,((void *)0))) == -1)
    {
        perror("Failed to set SIGALARM handler!\n");
        return -1;
    }
 ualarm(10000, 100000);
 for (i = 1; i <= NUM_MESSAGES; i++) {
  while (pkt_cnt < pkt_total) {
    pause();
  }
  msg = assemble_message();
  if (msg == ((void *)0)) {
    perror("Failed to assemble message");
  }
  else {
    fprintf(stderr, "GOT IT: message=%s\n", msg);
    free(msg);
  }
 }
    mm_release(&mm);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


repo: alexandernst/monks

decompiled_code:
void __noreturn do_segfault()
{
endwin();
abort();
}

canonical_decompiled_code:
void __noreturn func0()
{
endwin();
abort();
}

original_code:
void do_segfault(){
 endwin();
 abort();
}


decompiled_code:
__int64 __fastcall free_data(_QWORD *a1)
{
del(*a1);
del(a1[2]);
del(a1[3]);
del(a1[4]);
del(a1[5]);
return del(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
del(*a1);
del(a1[2]);
del(a1[3]);
del(a1[4]);
del(a1[5]);
return del(a1);
}

original_code:
void free_data(syscall_intercept_info *i){
 del(i->pname);
 del(i->operation);
 del(i->path);
 del(i->result);
 del(i->details);
 del(i);
}

canonical_original_code:
void free_data(struct syscall_intercept_info *i){
 del(i->pname);
 del(i->operation);
 del(i->path);
 del(i->result);
 del(i->details);
 del(i);
}

variable_types: struct syscall_intercept_info { char *pname; int pid; char *operation; char *path; char *result; char *details; } *


decompiled_code:
void __fastcall add_data(__int64 a1)
{
_QWORD **v1; // rbp
_QWORD *v2; // rax
__int64 v3; // rdx

if ( a1 )
{
v1 = (_QWORD **)head;
if ( *(_QWORD *)head )
{
if ( (unsigned __int64)total_nodes_0 > 0x752F )
{
head = *(_QWORD *)(head + 16);
free_data(*v1);
del(v1);
--total_nodes_0;
}
v2 = calloc(0x18uLL, 1uLL);
v3 = tail;
v2[1] = tail;
*v2 = a1;
*(_QWORD *)(v3 + 16) = v2;
tail = (__int64)v2;
v2[2] = 0LL;
}
else
{
*(_QWORD *)head = a1;
}
++total_nodes_0;
if ( *(_QWORD *)(tail + 8) == curr )
curr = tail;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
_QWORD **v1; // rbp
_QWORD *v2; // rax
__int64 v3; // rdx

if ( a1 )
{
v1 = (_QWORD **)head;
if ( *(_QWORD *)head )
{
if ( (unsigned __int64)total_nodes_0 > 0x752F )
{
head = *(_QWORD *)(head + 16);
func1(*v1);
del(v1);
--total_nodes_0;
}
v2 = calloc(0x18uLL, 1uLL);
v3 = tail;
v2[1] = tail;
*v2 = a1;
*(_QWORD *)(v3 + 16) = v2;
tail = (__int64)v2;
v2[2] = 0LL;
}
else
{
*(_QWORD *)head = a1;
}
++total_nodes_0;
if ( *(_QWORD *)(tail + 8) == curr )
curr = tail;
}
}

original_code:
void add_data(syscall_intercept_info *i){
 static unsigned long int total_nodes = 0;
 syscall_intercept_info_node *in, *tmp;
 if(!i){
  return;
 }
 if(head->i == ((void *)0)){
  in = head;
  in->i = i;
 }else{
  if(total_nodes >= 30000){
   tmp = head;
   head = head->next;
   free_data(tmp->i);
   del(tmp);
   total_nodes--;
  }
  in = calloc(sizeof(syscall_intercept_info_node), 1);
  in->prev = tail;
  in->i = i;
  tail->next = in;
  tail = in;
  tail->next = ((void *)0);
 }
 total_nodes++;
 if(curr == tail->prev){
  curr = tail;
 }
}

canonical_original_code:
void add_data(struct syscall_intercept_info *i){
 static unsigned long total_nodes = 0;
 struct syscall_intercept_info_node *in; struct syscall_intercept_info_node *tmp;
 if(!i){
  return;
 }
 if(head->i == ((void *)0)){
  in = head;
  in->i = i;
 }else{
  if(total_nodes >= 30000){
   tmp = head;
   head = head->next;
   free_data(tmp->i);
   del(tmp);
   total_nodes--;
  }
  in = calloc(sizeof(syscall_intercept_info_node), 1);
  in->prev = tail;
  in->i = i;
  tail->next = in;
  tail = in;
  tail->next = ((void *)0);
 }
 total_nodes++;
 if(curr == tail->prev){
  curr = tail;
 }
}

variable_types: struct syscall_intercept_info_node { struct syscall_intercept_info { char *pname; int pid; char *operation; char *path; char *result; char *details; } *i; struct syscall_intercept_info_node *prev; } *

user_defined_types: struct syscall_intercept_info_node { struct syscall_intercept_info *i; struct syscall_intercept_info_node *prev; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
unsigned int v5; // ebp
int v7; // er13
unsigned int v8; // eax
int v9; // eax
int v10; // er14
_QWORD *v11; // rax
int v12; // er15
__int64 v13; // rdi
__int128 *v14; // rbx
int v15; // eax
int v16; // eax
__int128 *v17; // r12
__int64 v18; // rbx
__int64 v19; // rbp
__int64 v20; // [rsp+8h] [rbp-80h] BYREF
char v21[16]; // [rsp+10h] [rbp-78h] BYREF
__int128 events; // [rsp+20h] [rbp-68h] BYREF
__int64 v23; // [rsp+30h] [rbp-58h]
struct epoll_event event; // [rsp+44h] [rbp-44h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
events = 0uLL;
v23 = 0LL;
v20 = 0LL;
while ( 2 )
{
v3 = getopt(argc, (char *const *)argv, "clusev");
if ( v3 == -1 )
{
v5 = net_init(&v20, v21);
if ( v5 == -1 )
{
puts("Error starting NetLink.");
}
else
{
v7 = fcntl(0, 0, 0LL);
v8 = getpid();
set_client_pid(v8);
signal(11, (__sighandler_t)do_segfault);
v9 = epoll_create1(0);
v10 = v9;
if ( v9 == -1 )
{
puts("Error creating epoll");
v5 = -1;
}
else
{
event.data.fd = v5;
event.events = 1;
if ( epoll_ctl(v9, 1, v5, &event) == -1 )
{
puts("Error adding socket fd to epoll");
v5 = -1;
}
else
{
event.data.fd = v7;
event.events = 1;
if ( epoll_ctl(v10, 1, v7, &event) == -1 )
{
puts("Error adding stdin fd to epoll");
v5 = -1;
}
else
{
v11 = (_QWORD *)new(24LL);
head = (__int64)v11;
if ( v11 )
{
v11[2] = 0LL;
v11[1] = 0LL;
*v11 = 0LL;
curr = head;
tail = head;
init_ncurses();
if ( has_colors() )
{
start_color();
init_pair(1, 2, 0);
init_pair(2, 1, 0);
init_pair(3, 1, 0);
}
signal(28, (__sighandler_t)&schedule_resize);
calc_w_size_pos();
wrefresh(stdscr);
create_win_data_data_box();
v12 = 1;
LABEL_48:
while ( v12 )
{
v16 = epoll_wait(v10, (struct epoll_event *)&events, 2, -1);
if ( v16 > 0 )
{
v14 = &events;
v17 = (__int128 *)((char *)&events + 12 * (unsigned int)(v16 - 1) + 12);
while ( 1 )
{
if ( (*(_BYTE *)v14 & 1) != 0 )
{
v15 = *((_DWORD *)v14 + 1);
if ( v15 == v5 )
{
while ( 1 )
{
v13 = read_from_socket(v5, v20);
if ( !v13 )
break;
add_data(v13);
}
if ( curr == tail )
((void (*)(void))draw_data)();
}
else if ( v15 == v7 )
{
if ( (int)read_from_kb() < 0 )
{
v12 = 0;
goto LABEL_48;
}
draw_data(curr);
}
}
v14 = (__int128 *)((char *)v14 + 12);
if ( v14 == v17 )
goto LABEL_48;
}
}
}
close(v5);
v18 = head;
if ( *(_QWORD *)head && head != tail )
{
while ( !*(_QWORD *)(v18 + 16) )
{
free_data(*(_QWORD **)v18);
v19 = *(_QWORD *)(v18 + 16);
del(v18);
v18 = v19;
}
}
del(v20);
endwin();
set_client_pid(0xFFFFFFFFLL);
v5 = 0;
}
else
{
puts("Error allocating memory for data list");
v5 = v3;
}
}
}
}
}
}
else
{
switch ( v3 )
{
case '?':
puts(
"Possible options are:\n"
"\t'c' - Check if monks kernel module is loaded.\n"
"\t'l' - Load monks kernel module.\n"
"\t'u' - Unload monks kernel module.\n"
"\t's' - Start monks kernel module hijack.\n"
"\t'e' - End monks kernel module hijack.\n"
"\t'v' - Show monks version.");
v5 = 1;
break;
case 'c':
v4 = check("monks");
v5 = v4;
if ( v4 )
{
if ( v4 == 1 )
puts("Monks kernel module is loaded.");
v5 = 0;
}
else
{
puts("Monks kernel module is not loaded.");
}
break;
case 'e':
v5 = stop();
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully stopped.");
break;
case 'l':
v5 = load("./monks.ko");
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully loaded.");
break;
case 's':
v5 = start();
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully started.");
break;
case 'u':
v5 = unload("monks");
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully unloaded.");
break;
case 'v':
printf("Monks %g\n", *(double *)&LC8);
continue;
default:
continue;
}
}
return v5;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
unsigned int v5; // ebp
int v7; // er13
unsigned int v8; // eax
int v9; // eax
int v10; // er14
_QWORD *v11; // rax
int v12; // er15
__int64 v13; // rdi
__int128 *v14; // rbx
int v15; // eax
int v16; // eax
__int128 *v17; // r12
__int64 v18; // rbx
__int64 v19; // rbp
__int64 v20; // [rsp+8h] [rbp-80h] BYREF
char v21[16]; // [rsp+10h] [rbp-78h] BYREF
__int128 events; // [rsp+20h] [rbp-68h] BYREF
__int64 v23; // [rsp+30h] [rbp-58h]
struct epoll_event event; // [rsp+44h] [rbp-44h] BYREF

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
events = 0uLL;
v23 = 0LL;
v20 = 0LL;
while ( 2 )
{
v3 = getopt(argc, (char *const *)argv, "clusev");
if ( v3 == -1 )
{
v5 = net_init(&v20, v21);
if ( v5 == -1 )
{
puts("Error starting NetLink.");
}
else
{
v7 = fcntl(0, 0, 0LL);
v8 = getpid();
set_client_pid(v8);
signal(11, (__sighandler_t)do_segfault);
v9 = epoll_create1(0);
v10 = v9;
if ( v9 == -1 )
{
puts("Error creating epoll");
v5 = -1;
}
else
{
event.data.fd = v5;
event.events = 1;
if ( epoll_ctl(v9, 1, v5, &event) == -1 )
{
puts("Error adding socket fd to epoll");
v5 = -1;
}
else
{
event.data.fd = v7;
event.events = 1;
if ( epoll_ctl(v10, 1, v7, &event) == -1 )
{
puts("Error adding stdin fd to epoll");
v5 = -1;
}
else
{
v11 = (_QWORD *)new(24LL);
head = (__int64)v11;
if ( v11 )
{
v11[2] = 0LL;
v11[1] = 0LL;
*v11 = 0LL;
curr = head;
tail = head;
init_ncurses();
if ( has_colors() )
{
start_color();
init_pair(1, 2, 0);
init_pair(2, 1, 0);
init_pair(3, 1, 0);
}
signal(28, (__sighandler_t)&schedule_resize);
calc_w_size_pos();
wrefresh(stdscr);
create_win_data_data_box();
v12 = 1;
LABEL_48:
while ( v12 )
{
v16 = epoll_wait(v10, (struct epoll_event *)&events, 2, -1);
if ( v16 > 0 )
{
v14 = &events;
v17 = (__int128 *)((char *)&events + 12 * (unsigned int)(v16 - 1) + 12);
while ( 1 )
{
if ( (*(_BYTE *)v14 & 1) != 0 )
{
v15 = *((_DWORD *)v14 + 1);
if ( v15 == v5 )
{
while ( 1 )
{
v13 = read_from_socket(v5, v20);
if ( !v13 )
break;
func2(v13);
}
if ( curr == tail )
((void (*)(void))draw_data)();
}
else if ( v15 == v7 )
{
if ( (int)read_from_kb() < 0 )
{
v12 = 0;
goto LABEL_48;
}
draw_data(curr);
}
}
v14 = (__int128 *)((char *)v14 + 12);
if ( v14 == v17 )
goto LABEL_48;
}
}
}
close(v5);
v18 = head;
if ( *(_QWORD *)head && head != tail )
{
while ( !*(_QWORD *)(v18 + 16) )
{
func1(*(_QWORD **)v18);
v19 = *(_QWORD *)(v18 + 16);
del(v18);
v18 = v19;
}
}
del(v20);
endwin();
set_client_pid(0xFFFFFFFFLL);
v5 = 0;
}
else
{
puts("Error allocating memory for data list");
v5 = v3;
}
}
}
}
}
}
else
{
switch ( v3 )
{
case '?':
puts(
"Possible options are:\n"
"\t'c' - Check if monks kernel module is loaded.\n"
"\t'l' - Load monks kernel module.\n"
"\t'u' - Unload monks kernel module.\n"
"\t's' - Start monks kernel module hijack.\n"
"\t'e' - End monks kernel module hijack.\n"
"\t'v' - Show monks version.");
v5 = 1;
break;
case 'c':
v4 = check("monks");
v5 = v4;
if ( v4 )
{
if ( v4 == 1 )
puts("Monks kernel module is loaded.");
v5 = 0;
}
else
{
puts("Monks kernel module is not loaded.");
}
break;
case 'e':
v5 = stop();
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully stopped.");
break;
case 'l':
v5 = load("./monks.ko");
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully loaded.");
break;
case 's':
v5 = start();
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully started.");
break;
case 'u':
v5 = unload("monks");
if ( v5 )
v5 = 0;
else
puts("Monks kernel module successfully unloaded.");
break;
case 'v':
printf("Monks %g\n", *(double *)&LC8);
continue;
default:
continue;
}
}
return v5;
}
}

original_code:
int main(int argc, char **argv){
 int ch, running;
 syscall_intercept_info *info;
 syscall_intercept_info_node *in, *tmp;
 int sock_fd, stdin_fd, efd;
 struct epoll_event event = {
  .events = 0
 },
 events[2] = {
  { .events = 0 },
  { .events = 0 }
 };
 struct iovec iov;
 struct nlmsghdr *nlh = ((void *)0);
 while((ch = getopt(argc, argv, "clusev")) != -1){
  switch(ch){
   int ret;
   case 'c':
    ret = check("monks");
    if(ret == 0){
     printf("Monks kernel module is not loaded.\n");
    }else if(ret == 1){
     printf("Monks kernel module is loaded.\n");
    }
    return 0;
   case 'l':
    if(load("./monks.ko") == 0){
     printf("Monks kernel module successfully loaded.\n");
    }
    return 0;
   case 'u':
    if(unload("monks") == 0){
     printf("Monks kernel module successfully unloaded.\n");
    }
    return 0;
   case 's':
    if(start() == 0){
     printf("Monks kernel module successfully started.\n");
    }
    return 0;
   case 'e':
    if(stop() == 0){
     printf("Monks kernel module successfully stopped.\n");
    }
    return 0;
   case 'v':
    printf("Monks %g\n", 0.1);
    break;
   case '?':
    printf(
     "Possible options are:\n\t"
      "'c' - Check if monks kernel module is loaded.\n\t"
      "'l' - Load monks kernel module.\n\t"
      "'u' - Unload monks kernel module.\n\t"
      "'s' - Start monks kernel module hijack.\n\t"
      "'e' - End monks kernel module hijack.\n\t"
      "'v' - Show monks version.\n"
    );
    return 1;
   default:
    break;
  }
 }
 sock_fd = net_init(&nlh, &iov);
 if(sock_fd == -1){
  printf("Error starting NetLink.\n");
  return -1;
 }
 stdin_fd = fcntl(0, 0, 0);
 set_client_pid(getpid());
 signal(11, do_segfault);
 efd = epoll_create1(0);
 if(efd == -1){
  printf("Error creating epoll\n");
  return -1;
 }
 event.data.fd = sock_fd;
 event.events = EPOLLIN;
 if(epoll_ctl(efd, 1, sock_fd, &event) == -1){
  printf("Error adding socket fd to epoll\n");
  return -1;
 }
 event.data.fd = stdin_fd;
 event.events = EPOLLIN;
 if(epoll_ctl(efd, 1, stdin_fd, &event) == -1){
  printf("Error adding stdin fd to epoll\n");
  return -1;
 }
 head = new(sizeof(syscall_intercept_info_node));
 if(!head){
  printf("Error allocating memory for data list\n");
  return -1;
 }
 head->prev = head->next = ((void *)0);
 head->i = ((void *)0);
 tail = curr = head;
 init_ncurses();
 if(has_colors()){
  start_color();
  init_pair(GREEN, 2, 0);
  init_pair(RED, 1, 0);
  init_pair(YELLOW, 1, 0);
 }
 signal(28, schedule_resize);
 calc_w_size_pos();
 wrefresh(stdscr);
 create_win_data_data_box();
 running = 1;
 while(running){
  int n, i;
  n = epoll_wait(efd, events, 2, -1);
  for(i = 0; i < n; i++){
   if(events[i].events & EPOLLIN){
    if(events[i].data.fd == sock_fd){
     while ((info = read_from_socket(sock_fd, nlh)) != ((void *)0)) {
      add_data(info);
     }
     if(curr == tail){
      draw_data(curr);
     }
    }else if(events[i].data.fd == stdin_fd){
     if(read_from_kb() < 0){
      running = 0;
      break;
     }else{
      draw_data(curr);
     }
    }
   }else if(events[i].events & (EPOLLHUP | EPOLLERR)){
    continue;
   }
  }
 }
 close(sock_fd);
 if(head->i && head != tail){
  in = head;
  while(!in->next){
   free_data(in->i);
   tmp = in;
   in = in->next;
   del(tmp);
  }
 }
 del(nlh);
 endwin();
 set_client_pid(-1);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 int ch; int running;
 struct syscall_intercept_info *info;
 struct syscall_intercept_info_node *in; struct syscall_intercept_info_node *tmp;
 int sock_fd; int stdin_fd; int efd;
 struct epoll_event event = {
  .events = 0
 }; struct epoll_event events[2] = {
  { .events = 0 },
  { .events = 0 }
 };
 struct iovec iov;
 struct nlmsghdr *nlh = ((void *)0);
 while((ch = getopt(argc, argv, "clusev")) != -1){
  switch(ch){
   int ret;
   case 'c':
    ret = check("monks");
    if(ret == 0){
     printf("Monks kernel module is not loaded.\n");
    }else if(ret == 1){
     printf("Monks kernel module is loaded.\n");
    }
    return 0;
   case 'l':
    if(load("./monks.ko") == 0){
     printf("Monks kernel module successfully loaded.\n");
    }
    return 0;
   case 'u':
    if(unload("monks") == 0){
     printf("Monks kernel module successfully unloaded.\n");
    }
    return 0;
   case 's':
    if(start() == 0){
     printf("Monks kernel module successfully started.\n");
    }
    return 0;
   case 'e':
    if(stop() == 0){
     printf("Monks kernel module successfully stopped.\n");
    }
    return 0;
   case 'v':
    printf("Monks %g\n", 0.1);
    break;
   case '?':
    printf(
     "Possible options are:\n\t"
      "'c' - Check if monks kernel module is loaded.\n\t"
      "'l' - Load monks kernel module.\n\t"
      "'u' - Unload monks kernel module.\n\t"
      "'s' - Start monks kernel module hijack.\n\t"
      "'e' - End monks kernel module hijack.\n\t"
      "'v' - Show monks version.\n"
    );
    return 1;
   default:
    break;
  }
 }
 sock_fd = net_init(&nlh, &iov);
 if(sock_fd == -1){
  printf("Error starting NetLink.\n");
  return -1;
 }
 stdin_fd = fcntl(0, 0, 0);
 set_client_pid(getpid());
 signal(11, do_segfault);
 efd = epoll_create1(0);
 if(efd == -1){
  printf("Error creating epoll\n");
  return -1;
 }
 event.data.fd = sock_fd;
 event.events = EPOLLIN;
 if(epoll_ctl(efd, 1, sock_fd, &event) == -1){
  printf("Error adding socket fd to epoll\n");
  return -1;
 }
 event.data.fd = stdin_fd;
 event.events = EPOLLIN;
 if(epoll_ctl(efd, 1, stdin_fd, &event) == -1){
  printf("Error adding stdin fd to epoll\n");
  return -1;
 }
 head = new(sizeof(syscall_intercept_info_node));
 if(!head){
  printf("Error allocating memory for data list\n");
  return -1;
 }
 head->prev = head->next = ((void *)0);
 head->i = ((void *)0);
 tail = curr = head;
 init_ncurses();
 if(has_colors()){
  start_color();
  init_pair(GREEN, 2, 0);
  init_pair(RED, 1, 0);
  init_pair(YELLOW, 1, 0);
 }
 signal(28, schedule_resize);
 calc_w_size_pos();
 wrefresh(stdscr);
 create_win_data_data_box();
 running = 1;
 while(running){
  int n; int i;
  n = epoll_wait(efd, events, 2, -1);
  for(i = 0; i < n; i++){
   if(events[i].events & EPOLLIN){
    if(events[i].data.fd == sock_fd){
     while ((info = read_from_socket(sock_fd, nlh)) != ((void *)0)) {
      add_data(info);
     }
     if(curr == tail){
      draw_data(curr);
     }
    }else if(events[i].data.fd == stdin_fd){
     if(read_from_kb() < 0){
      running = 0;
      break;
     }else{
      draw_data(curr);
     }
    }
   }else if(events[i].events & (EPOLLHUP | EPOLLERR)){
    continue;
   }
  }
 }
 close(sock_fd);
 if(head->i && head != tail){
  in = head;
  while(!in->next){
   free_data(in->i);
   tmp = in;
   in = in->next;
   del(tmp);
  }
 }
 del(nlh);
 endwin();
 set_client_pid(-1);
 return 0;
}

variable_types: ch int

variable_types: running int

variable_types: efd int

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } [2]

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: ret int

variable_types: n int

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: struct syscall_intercept_info { char *pname; int pid; char *operation; char *path; char *result; char *details; }


new

decompiled_code:
void *__fastcall new(size_t a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
return malloc(a1);
}

original_code:
void *new(size_t sz){
 return malloc(sz);
}

canonical_original_code:
void *new(unsigned long sz){
 return malloc(sz);
}

variable_types:
sz
unsigned long


renew

decompiled_code:
void *__fastcall renew(void *a1, size_t a2)
{
return realloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func1(void *a1, size_t a2)
{
return realloc(a1, a2);
}

original_code:
void *renew(void *ptr, size_t sz){
 return realloc(ptr, sz);
}

canonical_original_code:
void *renew(void *ptr, unsigned long sz){
 return realloc(ptr, sz);
}

variable_types:
ptr
void *


duplicate

decompiled_code:
char *__fastcall duplicate(const char *a1)
{
return strdup(a1);
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
return strdup(a1);
}

original_code:
void *duplicate(void *ptr){
 return strdup(ptr);
}


del

decompiled_code:
void __fastcall del(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void del(void *ptr){
 free(ptr);
}

canonical_original_code:
void del(void *ptr){
 free(ptr);
}


decompiled_code:
int init_ncurses()
{
initscr();
noecho();
cbreak();
keypad(stdscr, 1);
curs_set(0);
return nodelay(stdscr, 1);
}

canonical_decompiled_code:
int func0()
{
initscr();
noecho();
cbreak();
keypad(stdscr, 1);
curs_set(0);
return nodelay(stdscr, 1);
}

original_code:
void init_ncurses(void){
 initscr();
 noecho();
 cbreak();
 keypad(stdscr, 1);
 curs_set(0);
 nodelay(stdscr, 1);
}

canonical_original_code:
void init_ncurses(){
 initscr();
 noecho();
 cbreak();
 keypad(stdscr, 1);
 curs_set(0);
 nodelay(stdscr, 1);
}


decompiled_code:
int create_win_data_data_box()
{
if ( !win_data_box )
destroy_win(0LL);
if ( !win_data )
destroy_win(0LL);
wrefresh(stdscr);
header_box = create_newwin(header_box_height, header_box_width, header_box_starty, header_box_startx);
mvwprintw(
header_box,
1,
1,
"%-15.20s%10s %-15.10s%-50.45s%-10.10s %-7.7s",
"Process name",
"PID",
"Operation",
"Path",
"Result",
"Details");
wrefresh(header_box);
win_data_box = (__int64)create_newwin(
win_data_box_height,
win_data_box_width,
win_data_box_starty,
win_data_box_startx);
win_data = create_newwin(win_data_height, win_data_width, win_data_starty, win_data_startx);
wclear(win_data);
return wrefresh(win_data);
}

canonical_decompiled_code:
int func2()
{
if ( !win_data_box )
func1(0LL);
if ( !win_data )
func1(0LL);
wrefresh(stdscr);
header_box = create_newwin(header_box_height, header_box_width, header_box_starty, header_box_startx);
mvwprintw(
header_box,
1,
1,
"%-15.20s%10s %-15.10s%-50.45s%-10.10s %-7.7s",
"Process name",
"PID",
"Operation",
"Path",
"Result",
"Details");
wrefresh(header_box);
win_data_box = (__int64)create_newwin(
win_data_box_height,
win_data_box_width,
win_data_box_starty,
win_data_box_startx);
win_data = create_newwin(win_data_height, win_data_width, win_data_starty, win_data_startx);
wclear(win_data);
return wrefresh(win_data);
}

original_code:
void create_win_data_data_box(){
 if(!win_data_box){
  destroy_win(win_data_box);
 }
 if(!win_data){
  destroy_win(win_data);
 }
 wrefresh(stdscr);
 header_box = create_newwin(header_box_height, header_box_width, header_box_starty, header_box_startx);
 mvwprintw(header_box, 1, 1,
  "%-15.20s"
  "%10s"
  " %-15.10s"
  "%-50.45s"
  "%-10.10s"
  " %-7.7s",
  "Process name", "PID", "Operation", "Path", "Result", "Details");
 wrefresh(header_box);
 win_data_box = create_newwin(win_data_box_height, win_data_box_width, win_data_box_starty, win_data_box_startx);
 win_data = create_newwin(win_data_height, win_data_width, win_data_starty, win_data_startx);
 wclear(win_data);
 wrefresh(win_data);
}


decompiled_code:
void schedule_resize()
{
scheduled_resize = 1;
}

canonical_decompiled_code:
void func3()
{
scheduled_resize = 1;
}

original_code:
void schedule_resize(){
 scheduled_resize = 1;
}


decompiled_code:
__int64 calc_w_size_pos()
{
__int64 result; // rax

win_data_box_height = LINES - 4;
win_data_box_width = COLS - 4;
win_data_box_starty = 3;
win_data_box_startx = 2;
win_data_height = LINES - 6;
result = (unsigned int)(COLS - 6);
win_data_width = COLS - 6;
win_data_starty = 4;
win_data_startx = 3;
header_box_height = 3;
header_box_width = COLS - 4;
header_box_starty = 0;
header_box_startx = 2;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

win_data_box_height = LINES - 4;
win_data_box_width = COLS - 4;
win_data_box_starty = 3;
win_data_box_startx = 2;
win_data_height = LINES - 6;
result = (unsigned int)(COLS - 6);
win_data_width = COLS - 6;
win_data_starty = 4;
win_data_startx = 3;
header_box_height = 3;
header_box_width = COLS - 4;
header_box_starty = 0;
header_box_startx = 2;
return result;
}

original_code:
void calc_w_size_pos(){
 win_data_box_height = LINES - 4;
 win_data_box_width = COLS - 4;
 win_data_box_starty = (LINES - win_data_box_height) / 2 + 1;
 win_data_box_startx = (COLS - win_data_box_width) / 2;
 win_data_height = win_data_box_height - 2;
 win_data_width = win_data_box_width - 2;
 win_data_starty = win_data_box_starty + 1;
 win_data_startx = win_data_box_startx + 1;
 header_box_height = 3;
 header_box_width = win_data_box_width;
 header_box_starty = win_data_box_starty - 3;
 header_box_startx = win_data_box_startx;
}


decompiled_code:
_BOOL8 __fastcall filter_i(__int64 a1)
{
__pid_t v1; // ebp
__pid_t v2; // edx
int v3; // eax
_BOOL8 result; // rax

v1 = getpid();
v2 = getppid();
v3 = *(_DWORD *)(a1 + 8);
if ( v3 == v2 || v3 == v1 )
return 1LL;
result = 1LL;
if ( strcmp(*(const char **)a1, "X") )
{
if ( strcmp(*(const char **)a1, "Xorg") )
result = strcmp(*(const char **)a1, "konsole") == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
__pid_t v1; // ebp
__pid_t v2; // edx
int v3; // eax
_BOOL8 result; // rax

v1 = getpid();
v2 = getppid();
v3 = *(_DWORD *)(a1 + 8);
if ( v3 == v2 || v3 == v1 )
return 1LL;
result = 1LL;
if ( strcmp(*(const char **)a1, "X") )
{
if ( strcmp(*(const char **)a1, "Xorg") )
result = strcmp(*(const char **)a1, "konsole") == 0;
}
return result;
}

original_code:
int filter_i(syscall_intercept_info *i){
 pid_t mypid, parentpid;
 mypid = getpid();
 parentpid = getppid();
 if(
  i->pid != mypid &&
  i->pid != parentpid &&
  strcmp(i->pname, "X") != 0 &&
  strcmp(i->pname, "Xorg") != 0 &&
  strcmp(i->pname, "konsole") != 0
 ){
  return 0;
 }else{
  return 1;
 }
}

canonical_original_code:
int filter_i(struct syscall_intercept_info *i){
 int mypid; int parentpid;
 mypid = getpid();
 parentpid = getppid();
 if(
  i->pid != mypid &&
  i->pid != parentpid &&
  strcmp(i->pname, "X") != 0 &&
  strcmp(i->pname, "Xorg") != 0 &&
  strcmp(i->pname, "konsole") != 0
 ){
  return 0;
 }else{
  return 1;
 }
}

variable_types: mypid int

variable_types: parentpid int


decompiled_code:
int __fastcall draw_data(__int64 *a1)
{
int v1; // er13
__int64 *v2; // rbx
int v3; // ebp
int v5; // er12
const char *v6; // rax
const char *v7; // r14
int v8; // er12
const char *v9; // rax
const char *v10; // r14
int v11; // er12
const char *v12; // rax
const char *v13; // r14
int v14; // er12
const char *v15; // rax
const char *v16; // r14
int v17; // er12
const char *v18; // rax
const char *v19; // r14
int v20; // er12
const char *v21; // rax
const char *v22; // r14

v2 = a1;
if ( scheduled_resize )
{
endwin();
wrefresh(stdscr);
wclear(stdscr);
calc_w_size_pos();
create_win_data_data_box();
scheduled_resize = 0;
}
v3 = win_data_height;
if ( win_data_height >= 0 && a1 )
{
do
{
if ( (__int64 *)head == v2 )
break;
if ( filter_i(*v2) )
{
++v3;
}
else
{
wmove(win_data, v3, 0);
wclrtoeol(win_data);
if ( win_data )
{
v5 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v5 > 0 )
{
v6 = (const char *)format("%-15.20s", (_BYTE *)init_ncurses + 2);
v7 = v6;
if ( v6 )
{
waddnstr(win_data, v6, v5);
del(v7);
}
if ( win_data )
{
v8 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v8 > 0 )
{
v9 = (const char *)format("%10u", 1LL);
v10 = v9;
if ( v9 )
{
waddnstr(win_data, v9, v8);
del(v10);
}
if ( win_data )
{
v11 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v11 > 0 )
{
v12 = (const char *)format(" %-15.10s", (_BYTE *)init_ncurses + 2);
v13 = v12;
if ( v12 )
{
waddnstr(win_data, v12, v11);
del(v13);
}
if ( win_data )
{
v14 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v14 > 0 )
{
v15 = (const char *)format("%-50.45s", (_BYTE *)init_ncurses + 2);
v16 = v15;
if ( v15 )
{
waddnstr(win_data, v15, v14);
del(v16);
}
if ( has_colors() )
{
v1 = 1 - ((strcmp(*(const char **)(*v2 + 32), "Ok") == 0) - 1);
wattr_on(win_data, (unsigned int)(v1 << 8), 0LL);
}
if ( win_data )
{
v17 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v17 > 0 )
{
v18 = (const char *)format("%-10.10s", (_BYTE *)init_ncurses + 2);
v19 = v18;
if ( v18 )
{
waddnstr(win_data, v18, v17);
del(v19);
}
if ( v1 && has_colors() )
wattr_off(win_data, (unsigned int)(v1 << 8), 0LL);
if ( win_data )
{
v20 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v20 > 0 )
{
v21 = (const char *)format(" %-200.200s", (_BYTE *)init_ncurses + 2);
v22 = v21;
if ( v21 )
{
waddnstr(win_data, v21, v20);
del(v22);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
v2 = (__int64 *)v2[1];
if ( --v3 < 0 )
break;
}
while ( v2 );
}
return wrefresh(win_data);
}

canonical_decompiled_code:
int __fastcall func6(__int64 *a1)
{
int v1; // er13
__int64 *v2; // rbx
int v3; // ebp
int v5; // er12
const char *v6; // rax
const char *v7; // r14
int v8; // er12
const char *v9; // rax
const char *v10; // r14
int v11; // er12
const char *v12; // rax
const char *v13; // r14
int v14; // er12
const char *v15; // rax
const char *v16; // r14
int v17; // er12
const char *v18; // rax
const char *v19; // r14
int v20; // er12
const char *v21; // rax
const char *v22; // r14

v2 = a1;
if ( scheduled_resize )
{
endwin();
wrefresh(stdscr);
wclear(stdscr);
func4();
func2();
scheduled_resize = 0;
}
v3 = win_data_height;
if ( win_data_height >= 0 && a1 )
{
do
{
if ( (__int64 *)head == v2 )
break;
if ( func5(*v2) )
{
++v3;
}
else
{
wmove(win_data, v3, 0);
wclrtoeol(win_data);
if ( win_data )
{
v5 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v5 > 0 )
{
v6 = (const char *)format("%-15.20s", (_BYTE *)init_ncurses + 2);
v7 = v6;
if ( v6 )
{
waddnstr(win_data, v6, v5);
del(v7);
}
if ( win_data )
{
v8 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v8 > 0 )
{
v9 = (const char *)format("%10u", 1LL);
v10 = v9;
if ( v9 )
{
waddnstr(win_data, v9, v8);
del(v10);
}
if ( win_data )
{
v11 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v11 > 0 )
{
v12 = (const char *)format(" %-15.10s", (_BYTE *)init_ncurses + 2);
v13 = v12;
if ( v12 )
{
waddnstr(win_data, v12, v11);
del(v13);
}
if ( win_data )
{
v14 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v14 > 0 )
{
v15 = (const char *)format("%-50.45s", (_BYTE *)init_ncurses + 2);
v16 = v15;
if ( v15 )
{
waddnstr(win_data, v15, v14);
del(v16);
}
if ( has_colors() )
{
v1 = 1 - ((strcmp(*(const char **)(*v2 + 32), "Ok") == 0) - 1);
wattr_on(win_data, (unsigned int)(v1 << 8), 0LL);
}
if ( win_data )
{
v17 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v17 > 0 )
{
v18 = (const char *)format("%-10.10s", (_BYTE *)init_ncurses + 2);
v19 = v18;
if ( v18 )
{
waddnstr(win_data, v18, v17);
del(v19);
}
if ( v1 && has_colors() )
wattr_off(win_data, (unsigned int)(v1 << 8), 0LL);
if ( win_data )
{
v20 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v20 > 0 )
{
v21 = (const char *)format(" %-200.200s", (_BYTE *)init_ncurses + 2);
v22 = v21;
if ( v21 )
{
waddnstr(win_data, v21, v20);
del(v22);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
v2 = (__int64 *)v2[1];
if ( --v3 < 0 )
break;
}
while ( v2 );
}
return wrefresh(win_data);
}

original_code:
void draw_data(syscall_intercept_info_node *in) {
 int i, result_color;
 if(scheduled_resize){
  endwin();
  wrefresh(stdscr);
  wclear(stdscr);
  calc_w_size_pos();
  create_win_data_data_box();
  scheduled_resize = 0;
 }
 for(i = win_data_height; i >= 0 && in != ((void *)0) && in != head; i--, in = in->prev){
  if(!filter_i(in->i)){
   wmove(win_data, i, 0);
   wclrtoeol(win_data);
   { int available; int cur_x, cur_y; int max_x, max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (const void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (const void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (const void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%-15.20s", STRING, in->i->pname); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   { int available; int cur_x, cur_y; int max_x, max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (const void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (const void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (const void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%10u", NUMBER, in->i->pid); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   { int available; int cur_x, cur_y; int max_x, max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (const void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (const void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (const void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format(" %-15.10s", STRING, in->i->operation); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   { int available; int cur_x, cur_y; int max_x, max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (const void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (const void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (const void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%-50.45s", STRING, in->i->path); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   if(has_colors()){ if(strcmp(in->i->result, "Ok") == 0){ result_color = GREEN; }else{ result_color = RED; } if(result_color){ wattr_on(win_data, (attr_t)((((chtype)(((result_color))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0)); } };
   { int available; int cur_x, cur_y; int max_x, max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (const void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (const void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (const void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%-10.10s", STRING, in->i->result); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   if(result_color && has_colors()){ wattr_off(win_data, (attr_t)((((chtype)(((result_color))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0)); };
   { int available; int cur_x, cur_y; int max_x, max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (const void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (const void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (const void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (const void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format(" %-200.200s", STRING, in->i->details); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
  }else{
   i++;
  }
 }
 wrefresh(win_data);
}

canonical_original_code:
void draw_data(struct syscall_intercept_info_node *in) {
 int i; int result_color;
 if(scheduled_resize){
  endwin();
  wrefresh(stdscr);
  wclear(stdscr);
  calc_w_size_pos();
  create_win_data_data_box();
  scheduled_resize = 0;
 }
 for(i = win_data_height; i >= 0 && in != ((void *)0) && in != head; i--, in = in->prev){
  if(!filter_i(in->i)){
   wmove(win_data, i, 0);
   wclrtoeol(win_data);
   { int available; int cur_x; int cur_y; int max_x; int max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%-15.20s", STRING, in->i->pname); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   { int available; int cur_x; int cur_y; int max_x; int max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%10u", NUMBER, in->i->pid); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   { int available; int cur_x; int cur_y; int max_x; int max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format(" %-15.10s", STRING, in->i->operation); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   { int available; int cur_x; int cur_y; int max_x; int max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%-50.45s", STRING, in->i->path); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   if(has_colors()){ if(strcmp(in->i->result, "Ok") == 0){ result_color = GREEN; }else{ result_color = RED; } if(result_color){ wattr_on(win_data, (attr_t)((((chtype)(((result_color))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0)); } };
   { int available; int cur_x; int cur_y; int max_x; int max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format("%-10.10s", STRING, in->i->result); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
   if(result_color && has_colors()){ wattr_off(win_data, (attr_t)((((chtype)(((result_color))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0)); };
   { int available; int cur_x; int cur_y; int max_x; int max_y; char *tmp; cur_y = max_y; (cur_y = ((0 != (void *)((win_data))) ? (win_data)->_cury : (-1)), cur_x = ((0 != (void *)((win_data))) ? (win_data)->_curx : (-1))); (max_y = ((0 != (void *)((win_data))) ? ((win_data)->_maxy + 1) : (-1)), max_x = ((0 != (void *)((win_data))) ? ((win_data)->_maxx + 1) : (-1))); available = max_x - cur_x; if(available > 0 && cur_y == i){ tmp = format(" %-200.200s", STRING, in->i->details); if(tmp){ waddnstr(win_data, tmp, available); del(tmp); } }else{ continue; } };
  }else{
   i++;
  }
 }
 wrefresh(win_data);
}

variable_types: i int

variable_types: available int

variable_types:
tmp
char *