decompiled_code:
__int64 __fastcall ringbuf_push_hook(unsigned int (__fastcall *a1)(char *, __int64, unsigned __int64), __int64 a2, unsigned __int64 a3)
{
signed __int64 v4; // rsi
unsigned __int32 v6; // er13
signed __int32 v7; // ebp
unsigned int v8; // er8
__pid_t v10; // eax

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

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int (__fastcall *a1)(char *, __int64, unsigned __int64), __int64 a2, unsigned __int64 a3)
{
signed __int64 v4; // rsi
unsigned __int32 v6; // er13
signed __int32 v7; // ebp
unsigned int v8; // er8
__pid_t v10; // eax

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

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 *


repo: alex-guoba/SHM-Ring-Buffer

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

v3 = *((_QWORD *)shm + 32);
if ( v3 < a3 )
return 0xFFFFFFFFLL;
result = 1LL;
v5 = (unsigned __int64)(unsigned int)(*((_DWORD *)shm + 69) + 1) % *((_QWORD *)shm + 33);
if ( *((_DWORD *)shm + 68) != (_DWORD)v5 )
{
result = a1((char *)shm + v3 * *((unsigned int *)shm + 69) + 340, a2, v3);
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 v3; // r9
__int64 result; // rax
unsigned __int64 v5; // rbx

v3 = *((_QWORD *)shm + 32);
if ( v3 < a3 )
return 0xFFFFFFFFLL;
result = 1LL;
v5 = (unsigned __int64)(unsigned int)(*((_DWORD *)shm + 69) + 1) % *((_QWORD *)shm + 33);
if ( *((_DWORD *)shm + 68) != (_DWORD)v5 )
{
result = a1((char *)shm + v3 * *((unsigned int *)shm + 69) + 340, a2, v3);
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;
}

variable_types:
len
unsigned long

variable_types:
next
unsigned int

return_type: int


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

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

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

v1 = pid_0;
if ( !pid_0 )
{
v6 = getpid();
v1 = v6;
pid_0 = v6;
}
func9((__int64)&mutex_r, v1);
v2 = (volatile signed __int32 *)shm;
v3 = *((_DWORD *)shm + 68);
if ( *((_DWORD *)shm + 69) == v3 )
{
func7((volatile signed __int64 **)&mutex_r, pid_0);
result = 2LL;
}
else
{
v4 = (unsigned __int64)(v3 + 1) % *((_QWORD *)shm + 33);
memcpy(dest, (char *)shm + *((_QWORD *)shm + 32) * v3 + 340, *((_QWORD *)shm + 32));
_InterlockedCompareExchange(v2 + 68, v4, v3);
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;
}

variable_types:
value
char *

variable_types: pid int


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));
result = 0LL;
v1[68] = (unsigned __int64)(unsigned int)(v1[68] + 1) % *((_QWORD *)v1 + 33);
}
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));
result = 0LL;
v1[68] = (unsigned __int64)(unsigned int)(v1[68] + 1) % *((_QWORD *)v1 + 33);
}
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);
}

return_type: void


cpuid

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

_RAX = a1;
__asm { cpuid }
a2[1] = _RBX;
*a2 = result;
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[1] = _RBX;
*a2 = result;
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

return_type: void *

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)
{
unsigned int v2; // er9
__int64 v3; // rdx
int result; // eax
_DWORD *v5; // rdx

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

canonical_decompiled_code:
int __fastcall func12(__int64 a1, __int64 a2)
{
unsigned int v2; // er9
__int64 v3; // rdx
int result; // eax
_DWORD *v5; // rdx

v2 = *(_DWORD *)(a1 + 12);
v3 = *(_QWORD *)(a1 + 24) + (int)(v2 * *(_DWORD *)(a1 + 4));
if ( (signed int)v2 >= *(_DWORD *)a1 )
return printf("Chunk of memory does not exist. %d, %d\n", v2, *(unsigned int *)(a1 + 8));
result = *(_DWORD *)(a1 + 12);
while ( a2 != v3 )
{
++result;
v3 += *(int *)(a1 + 4);
if ( result == *(_DWORD *)a1 )
return printf("Chunk of memory does not exist. %d, %d\n", v2, *(unsigned int *)(a1 + 8));
}
v5 = (_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * result);
*v5 = 0;
if ( result < *(_DWORD *)(a1 + 8) )
{
*(_DWORD *)(a1 + 8) = result;
if ( result != *(_DWORD *)(a1 + 12) )
return result;
}
else if ( result != *(_DWORD *)(a1 + 12) )
{
return result;
}
if ( *(_DWORD *)a1 > result )
{
do
{
if ( *v5 )
break;
++result;
++v5;
}
while ( *(_DWORD *)a1 != result );
}
*(_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)
{
__int64 v3; // rdi
int v4; // ebx
const char *v5; // rax
char *v6; // rbp
int result; // eax
struct sigaction v8; // [rsp+0h] [rbp-B8h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
int v4; // ebx
const char *v5; // rax
char *v6; // rbp
int result; // eax
struct sigaction v8; // [rsp+0h] [rbp-B8h] BYREF

func10(&mm, 1000LL, 64LL);
v8.sa_handler = (__sighandler_t)packet_handler;
v8.sa_flags = 0;
if ( sigemptyset(&v8.sa_mask) == -1 || sigaction(14, &v8, 0LL) == -1 )
{
perror("Failed to set SIGALARM handler!\n");
result = -1;
}
else
{
v3 = 10000LL;
v4 = 3;
ualarm(0x2710u, 0x186A0u);
do
{
while ( pkt_cnt < pkt_total )
pause();
v5 = (const char *)func8(v3);
v6 = (char *)v5;
if ( v5 )
{
fprintf(stderr, "GOT IT: message=%s\n", v5);
v3 = (__int64)v6;
free(v6);
}
else
{
v3 = (__int64)"Failed to assemble message";
perror("Failed to assemble message");
}
--v4;
}
while ( v4 );
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)
{
__int64 v2; // rbp
__int64 v3; // rax
_QWORD *v4; // rdi
__int64 v5; // rbp
_QWORD *v6; // rax
__int64 v7; // rdx

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

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 v2; // rbp
__int64 v3; // rax
_QWORD *v4; // rdi
__int64 v5; // rbp
_QWORD *v6; // rax
__int64 v7; // rdx

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

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; // eax
int v4; // er12
unsigned int v6; // ebp
int v7; // er14
unsigned int v8; // eax
int v9; // eax
int v10; // er15
_QWORD *v11; // rax
int v12; // eax
__int128 *v13; // rbx
__int128 *v14; // r13
int v15; // eax
__int64 v16; // rdi
__int64 v17; // rdi
__int64 v18; // rbp
__int64 v19; // rbx
__int64 v20; // [rsp+0h] [rbp-80h] BYREF
struct epoll_event event; // [rsp+Ch] [rbp-74h] BYREF
char v22[16]; // [rsp+18h] [rbp-68h] BYREF
__int128 v23; // [rsp+28h] [rbp-58h] BYREF
__int64 v24; // [rsp+38h] [rbp-48h]

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v24 = 0LL;
v20 = 0LL;
v23 = 0LL;
while ( 2 )
{
v3 = getopt(argc, (char *const *)argv, "clusev");
if ( v3 != -1 )
{
switch ( v3 )
{
case '?':
v4 = 1;
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.");
return v4;
case 'c':
v4 = check("monks");
if ( v4 )
{
if ( v4 == 1 )
puts("Monks kernel module is loaded.");
LABEL_10:
v4 = 0;
}
else
{
puts("Monks kernel module is not loaded.");
}
break;
case 'e':
v4 = stop();
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully stopped.");
break;
case 'l':
v4 = load("./monks.ko");
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully loaded.");
break;
case 's':
v4 = start();
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully started.");
break;
case 'u':
v4 = unload("monks");
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully unloaded.");
break;
case 'v':
printf("Monks %g\n", *(double *)&LC8);
continue;
default:
continue;
}
return v4;
}
break;
}
v6 = net_init(&v20, v22);
if ( v6 == -1 )
{
v4 = -1;
puts("Error starting NetLink.");
return v4;
}
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 )
{
v4 = -1;
puts("Error creating epoll");
return v4;
}
event.data.fd = v6;
event.events = 1;
v4 = epoll_ctl(v9, 1, v6, &event);
if ( v4 == -1 )
{
puts("Error adding socket fd to epoll");
return v4;
}
event.data.fd = v7;
event.events = 1;
v4 = epoll_ctl(v10, 1, v7, &event);
if ( v4 == -1 )
{
puts("Error adding stdin fd to epoll");
return v4;
}
v11 = (_QWORD *)new(24LL);
head = (__int64)v11;
if ( !v11 )
{
v4 = -1;
puts("Error allocating memory for data list");
return v4;
}
*v11 = 0LL;
v11[2] = 0LL;
v11[1] = 0LL;
curr = (__int64)v11;
tail = (__int64)v11;
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();
do
LABEL_28:
v12 = epoll_wait(v10, (struct epoll_event *)&v23, 2, -1);
while ( v12 <= 0 );
v13 = &v23;
v14 = (__int128 *)((char *)&v23 + 12 * (unsigned int)(v12 - 1) + 12);
while ( 1 )
{
if ( (*(_BYTE *)v13 & 1) != 0 )
{
v15 = *((_DWORD *)v13 + 1);
if ( v15 == v6 )
{
while ( 1 )
{
v17 = read_from_socket(v6, v20);
if ( !v17 )
break;
add_data(v17);
}
v16 = curr;
if ( curr != tail )
goto LABEL_30;
goto LABEL_36;
}
if ( v15 == v7 )
break;
}
LABEL_30:
v13 = (__int128 *)((char *)v13 + 12);
if ( v13 == v14 )
goto LABEL_28;
}
if ( (int)read_from_kb() >= 0 )
{
v16 = curr;
LABEL_36:
draw_data(v16);
goto LABEL_30;
}
v4 = 0;
close(v6);
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);
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
unsigned int v6; // ebp
int v7; // er14
unsigned int v8; // eax
int v9; // eax
int v10; // er15
_QWORD *v11; // rax
int v12; // eax
__int128 *v13; // rbx
__int128 *v14; // r13
int v15; // eax
__int64 v16; // rdi
__int64 v17; // rdi
__int64 v18; // rbp
__int64 v19; // rbx
__int64 v20; // [rsp+0h] [rbp-80h] BYREF
struct epoll_event event; // [rsp+Ch] [rbp-74h] BYREF
char v22[16]; // [rsp+18h] [rbp-68h] BYREF
__int128 v23; // [rsp+28h] [rbp-58h] BYREF
__int64 v24; // [rsp+38h] [rbp-48h]

*(_QWORD *)&event.events = 0LL;
HIDWORD(event.data.u64) = 0;
v24 = 0LL;
v20 = 0LL;
v23 = 0LL;
while ( 2 )
{
v3 = getopt(argc, (char *const *)argv, "clusev");
if ( v3 != -1 )
{
switch ( v3 )
{
case '?':
v4 = 1;
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.");
return v4;
case 'c':
v4 = check("monks");
if ( v4 )
{
if ( v4 == 1 )
puts("Monks kernel module is loaded.");
LABEL_10:
v4 = 0;
}
else
{
puts("Monks kernel module is not loaded.");
}
break;
case 'e':
v4 = stop();
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully stopped.");
break;
case 'l':
v4 = load("./monks.ko");
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully loaded.");
break;
case 's':
v4 = start();
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully started.");
break;
case 'u':
v4 = unload("monks");
if ( v4 )
goto LABEL_10;
puts("Monks kernel module successfully unloaded.");
break;
case 'v':
printf("Monks %g\n", *(double *)&LC8);
continue;
default:
continue;
}
return v4;
}
break;
}
v6 = net_init(&v20, v22);
if ( v6 == -1 )
{
v4 = -1;
puts("Error starting NetLink.");
return v4;
}
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 )
{
v4 = -1;
puts("Error creating epoll");
return v4;
}
event.data.fd = v6;
event.events = 1;
v4 = epoll_ctl(v9, 1, v6, &event);
if ( v4 == -1 )
{
puts("Error adding socket fd to epoll");
return v4;
}
event.data.fd = v7;
event.events = 1;
v4 = epoll_ctl(v10, 1, v7, &event);
if ( v4 == -1 )
{
puts("Error adding stdin fd to epoll");
return v4;
}
v11 = (_QWORD *)new(24LL);
head = (__int64)v11;
if ( !v11 )
{
v4 = -1;
puts("Error allocating memory for data list");
return v4;
}
*v11 = 0LL;
v11[2] = 0LL;
v11[1] = 0LL;
curr = (__int64)v11;
tail = (__int64)v11;
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();
do
LABEL_28:
v12 = epoll_wait(v10, (struct epoll_event *)&v23, 2, -1);
while ( v12 <= 0 );
v13 = &v23;
v14 = (__int128 *)((char *)&v23 + 12 * (unsigned int)(v12 - 1) + 12);
while ( 1 )
{
if ( (*(_BYTE *)v13 & 1) != 0 )
{
v15 = *((_DWORD *)v13 + 1);
if ( v15 == v6 )
{
while ( 1 )
{
v17 = read_from_socket(v6, v20);
if ( !v17 )
break;
func2(v17);
}
v16 = curr;
if ( curr != tail )
goto LABEL_30;
goto LABEL_36;
}
if ( v15 == v7 )
break;
}
LABEL_30:
v13 = (__int128 *)((char *)v13 + 12);
if ( v13 == v14 )
goto LABEL_28;
}
if ( (int)read_from_kb() >= 0 )
{
v16 = curr;
LABEL_36:
draw_data(v16);
goto LABEL_30;
}
v4 = 0;
close(v6);
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);
return v4;
}

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:
// attributes: thunk
void *new(size_t size)
{
return malloc(size);
}

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

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:
// attributes: thunk
void *renew(void *ptr, size_t size)
{
return realloc(ptr, size);
}

canonical_decompiled_code:
void *func1(void *ptr, size_t size)
{
return realloc(ptr, size);
}

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:
// attributes: thunk
char *duplicate(const char *s)
{
return strdup(s);
}

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

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


del

decompiled_code:
// attributes: thunk
void del(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

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 )
goto LABEL_3;
LABEL_5:
destroy_win(0LL);
goto LABEL_3;
}
if ( !win_data )
goto LABEL_5;
LABEL_3:
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 )
goto LABEL_3;
LABEL_5:
func1(0LL);
goto LABEL_3;
}
if ( !win_data )
goto LABEL_5;
LABEL_3:
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_starty = 3;
win_data_box_startx = 2;
win_data_starty = 4;
win_data_box_height = LINES - 4;
win_data_height = LINES - 6;
win_data_startx = 3;
result = (unsigned int)(COLS - 6);
win_data_box_width = COLS - 4;
win_data_width = COLS - 6;
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_starty = 3;
win_data_box_startx = 2;
win_data_starty = 4;
win_data_box_height = LINES - 4;
win_data_height = LINES - 6;
win_data_startx = 3;
result = (unsigned int)(COLS - 6);
win_data_box_width = COLS - 4;
win_data_width = COLS - 6;
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:
__int64 __fastcall filter_i(const char **a1)
{
__pid_t v1; // ebp
__pid_t v2; // eax
int v3; // edx
_BOOL4 v4; // er8

v1 = getpid();
v2 = getppid();
v3 = *((_DWORD *)a1 + 2);
if ( v3 == v1 || v3 == v2 )
return 1LL;
if ( **a1 == 88 && !(*a1)[1] )
return 1LL;
v4 = 1;
if ( strcmp(*a1, "Xorg") )
v4 = strcmp(*a1, "konsole") == 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1)
{
__pid_t v1; // ebp
__pid_t v2; // eax
int v3; // edx
_BOOL4 v4; // er8

v1 = getpid();
v2 = getppid();
v3 = *((_DWORD *)a1 + 2);
if ( v3 == v1 || v3 == v2 )
return 1LL;
if ( **a1 == 88 && !(*a1)[1] )
return 1LL;
v4 = 1;
if ( strcmp(*a1, "Xorg") )
v4 = strcmp(*a1, "konsole") == 0;
return v4;
}

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 v4; // er12
int v5; // er14
int v6; // er12
const char *v7; // rax
const char *v8; // r15
int v9; // er12
const char *v10; // rax
const char *v11; // r15
int v12; // er12
const char *v13; // rax
const char *v14; // r15
int v15; // er12
const char *v16; // rax
const char *v17; // r15
_BYTE *v18; // rax
attr_t v19; // rsi
int v20; // er12
const char *v21; // rax
const char *v22; // r15
int v23; // er12
const char *v24; // rax
const char *v25; // rbp
int v26; // edx
const char *v27; // rdi

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 ( a1 )
{
v4 = ~win_data_height;
if ( win_data_height >= 0 )
{
while ( 1 )
{
if ( head == v2 )
return wrefresh(win_data);
if ( (unsigned int)filter_i(*(const char ***)v2) )
goto LABEL_6;
v5 = v3 - 1;
wmove(win_data, v3, 0);
wclrtoeol(win_data);
if ( win_data )
{
v6 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v6 > 0 )
{
v7 = (const char *)format("%-15.20s", (_BYTE *)init_ncurses + 2);
v8 = v7;
if ( v7 )
{
waddnstr(win_data, v7, v6);
del(v8);
}
if ( win_data )
{
v9 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v9 > 0 )
{
v10 = (const char *)format("%10u", 1LL);
v11 = v10;
if ( v10 )
{
waddnstr(win_data, v10, v9);
del(v11);
}
if ( win_data )
{
v12 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v12 > 0 )
{
v13 = (const char *)format(" %-15.10s", (_BYTE *)init_ncurses + 2);
v14 = v13;
if ( v13 )
{
waddnstr(win_data, v13, v12);
del(v14);
}
if ( win_data )
{
v15 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v15 > 0 )
{
v16 = (const char *)format("%-50.45s", (_BYTE *)init_ncurses + 2);
v17 = v16;
if ( v16 )
{
waddnstr(win_data, v16, v15);
del(v17);
}
if ( has_colors() )
{
v18 = *(_BYTE **)(*(_QWORD *)v2 + 32LL);
if ( *v18 != 79 || v18[1] != 107 || (v19 = 256LL, v1 = 1, v18[2]) )
{
v19 = 512LL;
v1 = 2;
}
wattr_on(win_data, v19, 0LL);
}
if ( win_data )
{
v20 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v20 > 0 )
{
v21 = (const char *)format("%-10.10s", (_BYTE *)init_ncurses + 2);
v22 = v21;
if ( v21 )
{
waddnstr(win_data, v21, v20);
del(v22);
}
if ( has_colors() )
wattr_off(win_data, (unsigned int)(v1 << 8), 0LL);
if ( win_data )
{
v23 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v23 > 0 )
{
v24 = (const char *)format(" %-200.200s", (_BYTE *)init_ncurses + 2);
v25 = v24;
if ( v24 )
break;
}
}
}
}
}
}
}
}
}
}
}
}
v2 = *(_QWORD *)(v2 + 8);
v3 = v5;
v4 = ~v5;
if ( v5 < 0 )
return wrefresh(win_data);
LABEL_7:
if ( !v2 )
return wrefresh(win_data);
}
v26 = v23;
v4 = ~v5;
waddnstr(win_data, v24, v26);
v27 = v25;
v3 = v5;
del(v27);
LABEL_6:
v2 = *(_QWORD *)(v2 + 8);
if ( v4 >= 0 )
return wrefresh(win_data);
goto LABEL_7;
}
}
return wrefresh(win_data);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int v1; // er13
__int64 v2; // rbx
int v3; // ebp
int v4; // er12
int v5; // er14
int v6; // er12
const char *v7; // rax
const char *v8; // r15
int v9; // er12
const char *v10; // rax
const char *v11; // r15
int v12; // er12
const char *v13; // rax
const char *v14; // r15
int v15; // er12
const char *v16; // rax
const char *v17; // r15
_BYTE *v18; // rax
attr_t v19; // rsi
int v20; // er12
const char *v21; // rax
const char *v22; // r15
int v23; // er12
const char *v24; // rax
const char *v25; // rbp
int v26; // edx
const char *v27; // rdi

v2 = a1;
if ( scheduled_resize )
{
endwin();
wrefresh(stdscr);
wclear(stdscr);
func4();
func2();
scheduled_resize = 0;
}
v3 = win_data_height;
if ( a1 )
{
v4 = ~win_data_height;
if ( win_data_height >= 0 )
{
while ( 1 )
{
if ( head == v2 )
return wrefresh(win_data);
if ( (unsigned int)func5(*(const char ***)v2) )
goto LABEL_6;
v5 = v3 - 1;
wmove(win_data, v3, 0);
wclrtoeol(win_data);
if ( win_data )
{
v6 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v6 > 0 )
{
v7 = (const char *)format("%-15.20s", (_BYTE *)init_ncurses + 2);
v8 = v7;
if ( v7 )
{
waddnstr(win_data, v7, v6);
del(v8);
}
if ( win_data )
{
v9 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v9 > 0 )
{
v10 = (const char *)format("%10u", 1LL);
v11 = v10;
if ( v10 )
{
waddnstr(win_data, v10, v9);
del(v11);
}
if ( win_data )
{
v12 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v12 > 0 )
{
v13 = (const char *)format(" %-15.10s", (_BYTE *)init_ncurses + 2);
v14 = v13;
if ( v13 )
{
waddnstr(win_data, v13, v12);
del(v14);
}
if ( win_data )
{
v15 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v15 > 0 )
{
v16 = (const char *)format("%-50.45s", (_BYTE *)init_ncurses + 2);
v17 = v16;
if ( v16 )
{
waddnstr(win_data, v16, v15);
del(v17);
}
if ( has_colors() )
{
v18 = *(_BYTE **)(*(_QWORD *)v2 + 32LL);
if ( *v18 != 79 || v18[1] != 107 || (v19 = 256LL, v1 = 1, v18[2]) )
{
v19 = 512LL;
v1 = 2;
}
wattr_on(win_data, v19, 0LL);
}
if ( win_data )
{
v20 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v20 > 0 )
{
v21 = (const char *)format("%-10.10s", (_BYTE *)init_ncurses + 2);
v22 = v21;
if ( v21 )
{
waddnstr(win_data, v21, v20);
del(v22);
}
if ( has_colors() )
wattr_off(win_data, (unsigned int)(v1 << 8), 0LL);
if ( win_data )
{
v23 = win_data->_maxx + 1 - win_data->_curx;
if ( win_data->_cury == v3 && v23 > 0 )
{
v24 = (const char *)format(" %-200.200s", (_BYTE *)init_ncurses + 2);
v25 = v24;
if ( v24 )
break;
}
}
}
}
}
}
}
}
}
}
}
}
v2 = *(_QWORD *)(v2 + 8);
v3 = v5;
v4 = ~v5;
if ( v5 < 0 )
return wrefresh(win_data);
LABEL_7:
if ( !v2 )
return wrefresh(win_data);
}
v26 = v23;
v4 = ~v5;
waddnstr(win_data, v24, v26);
v27 = v25;
v3 = v5;
del(v27);
LABEL_6:
v2 = *(_QWORD *)(v2 + 8);
if ( v4 >= 0 )
return wrefresh(win_data);
goto LABEL_7;
}
}
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 *


decompiled_code:
__int64 read_from_kb()
{
int v0; // eax
int v1; // edx
__int64 result; // rax
const char ***v3; // rax
const char ***v4; // rax

v0 = wgetch(stdscr);
v1 = v0;
if ( v0 == 259 )
{
v4 = *(const char ****)(curr + 8LL);
if ( !v4 )
return (unsigned int)-(v1 == 113);
curr = *(_QWORD *)(curr + 8LL);
while ( (unsigned int)filter_i(*v4) )
{
curr = *(_QWORD *)(curr + 8LL);
v4 = (const char ***)curr;
if ( curr == head )
goto LABEL_8;
}
result = 0LL;
}
else
{
if ( v0 != 258 )
return (unsigned int)-(v1 == 113);
v3 = *(const char ****)(curr + 16LL);
if ( v3 )
{
curr = *(_QWORD *)(curr + 16LL);
do
{
if ( !(unsigned int)filter_i(*v3) )
break;
curr = *(_QWORD *)(curr + 16LL);
v3 = (const char ***)curr;
}
while ( curr != tail );
}
LABEL_8:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
int v1; // edx
__int64 result; // rax
const char ***v3; // rax
const char ***v4; // rax

v0 = wgetch(stdscr);
v1 = v0;
if ( v0 == 259 )
{
v4 = *(const char ****)(curr + 8LL);
if ( !v4 )
return (unsigned int)-(v1 == 113);
curr = *(_QWORD *)(curr + 8LL);
while ( (unsigned int)func5(*v4) )
{
curr = *(_QWORD *)(curr + 8LL);
v4 = (const char ***)curr;
if ( curr == head )
goto LABEL_8;
}
result = 0LL;
}
else
{
if ( v0 != 258 )
return (unsigned int)-(v1 == 113);
v3 = *(const char ****)(curr + 16LL);
if ( v3 )
{
curr = *(_QWORD *)(curr + 16LL);
do
{
if ( !(unsigned int)func5(*v3) )
break;
curr = *(_QWORD *)(curr + 16LL);
v3 = (const char ***)curr;
}
while ( curr != tail );
}
LABEL_8:
result = 0LL;
}
return result;
}

original_code:
int read_from_kb(void){
 int ch = wgetch(stdscr);
 if(ch == 0403 && curr->prev){
  curr = curr->prev;
  while(filter_i(curr->i)){
   curr = curr->prev;
   if(curr == head){
    break;
   }
  }
 }else if(ch == 0402 && curr->next){
  curr = curr->next;
  while(filter_i(curr->i)){
   curr = curr->next;
   if(curr == tail){
    break;
   }
  }
 }else if(ch == 'q'){
  return -1;
 }
 return 0;
}

canonical_original_code:
int read_from_kb(){
 int ch = wgetch(stdscr);
 if(ch == 0403 && curr->prev){
  curr = curr->prev;
  while(filter_i(curr->i)){
   curr = curr->prev;
   if(curr == head){
    break;
   }
  }
 }else if(ch == 0402 && curr->next){
  curr = curr->next;
  while(filter_i(curr->i)){
   curr = curr->next;
   if(curr == tail){
    break;
   }
  }
 }else if(ch == 'q'){
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall net_init(_QWORD *a1, _QWORD *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // er12
_QWORD *v5; // rax
_DWORD *v6; // rax
struct sockaddr addr; // [rsp+4h] [rbp-24h] BYREF

v2 = get_netlink_id();
v3 = socket(16, 2, v2);
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
*(_DWORD *)&addr.sa_data[6] = 0;
*(_DWORD *)&addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v4, &addr, 0xCu) )
return (unsigned int)-1;
v5 = (_QWORD *)new(1040LL);
*a1 = v5;
*v5 = 0LL;
v5[129] = 0LL;
memset(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 1040) >> 3));
v6 = (_DWORD *)*a1;
*v6 = 1040;
*a2 = v6;
a2[1] = *(unsigned int *)*a1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // er12
_QWORD *v5; // rax
_DWORD *v6; // rax
struct sockaddr addr; // [rsp+4h] [rbp-24h] BYREF

v2 = get_netlink_id();
v3 = socket(16, 2, v2);
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
*(_DWORD *)&addr.sa_data[6] = 0;
*(_DWORD *)&addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v4, &addr, 0xCu) )
return (unsigned int)-1;
v5 = (_QWORD *)new(1040LL);
*a1 = v5;
*v5 = 0LL;
v5[129] = 0LL;
memset(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 1040) >> 3));
v6 = (_DWORD *)*a1;
*v6 = 1040;
*a2 = v6;
a2[1] = *(unsigned int *)*a1;
return v4;
}

original_code:
int net_init(struct nlmsghdr **nlh, struct iovec *iov){
 int sock_fd, ret;
 struct sockaddr_nl src_addr;
 sock_fd = socket(16, SOCK_DGRAM, get_netlink_id());
 if(sock_fd < 0){
  return -1;
 }
 memset(&src_addr, 0, sizeof(src_addr));
 src_addr.nl_family = 16;
 src_addr.nl_pid = getpid();
 ret = bind(sock_fd, (struct sockaddr *)&src_addr, sizeof(src_addr));
 if(ret != 0){
  return -1;
 }
 *nlh = (struct nlmsghdr *)new(( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 memset(*nlh, 0, ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 (*nlh)->nlmsg_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 iov->iov_base = (void *)*nlh;
 iov->iov_len = (*nlh)->nlmsg_len;
 return sock_fd;
}

canonical_original_code:
int net_init(struct nlmsghdr **nlh, struct iovec *iov){
 int sock_fd; int ret;
 struct sockaddr_nl src_addr;
 sock_fd = socket(16, SOCK_DGRAM, get_netlink_id());
 if(sock_fd < 0){
  return -1;
 }
 memset(&src_addr, 0, sizeof(src_addr));
 src_addr.nl_family = 16;
 src_addr.nl_pid = getpid();
 ret = bind(sock_fd, (struct sockaddr *)&src_addr, sizeof(src_addr));
 if(ret != 0){
  return -1;
 }
 *nlh = (struct nlmsghdr *)new(( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 memset(*nlh, 0, ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 (*nlh)->nlmsg_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 iov->iov_base = (void *)*nlh;
 iov->iov_len = (*nlh)->nlmsg_len;
 return sock_fd;
}

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: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

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


decompiled_code:
__int64 __fastcall read_from_socket(int a1, _DWORD *a2)
{
size_t *v2; // rbp
size_t v3; // rdi
void *v4; // rax
__int64 v5; // r12
__int64 v7[2]; // [rsp+0h] [rbp-68h] BYREF
struct msghdr message; // [rsp+10h] [rbp-58h] BYREF

v7[0] = (__int64)a2;
v7[1] = 1040LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
message.msg_iov = (iovec *)v7;
message.msg_iovlen = 1LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
message.msg_flags = 0;
if ( recvmsg(a1, &message, 64) <= 0 )
return 0LL;
v2 = (size_t *)new(16LL);
if ( !v2 )
return 0LL;
v3 = (unsigned int)(*a2 - 16);
*v2 = v3;
v4 = (void *)new(v3);
v2[1] = (size_t)v4;
if ( !v4 )
return 0LL;
memcpy(v4, a2 + 4, *v2);
v5 = deserialize_syscall_info(v2);
del(v2[1]);
del(v2);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _DWORD *a2)
{
size_t *v2; // rbp
size_t v3; // rdi
void *v4; // rax
__int64 v5; // r12
__int64 v7[2]; // [rsp+0h] [rbp-68h] BYREF
struct msghdr message; // [rsp+10h] [rbp-58h] BYREF

v7[0] = (__int64)a2;
v7[1] = 1040LL;
message.msg_name = 0LL;
message.msg_namelen = 0;
message.msg_iov = (iovec *)v7;
message.msg_iovlen = 1LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
message.msg_flags = 0;
if ( recvmsg(a1, &message, 64) <= 0 )
return 0LL;
v2 = (size_t *)new(16LL);
if ( !v2 )
return 0LL;
v3 = (unsigned int)(*a2 - 16);
*v2 = v3;
v4 = (void *)new(v3);
v2[1] = (size_t)v4;
if ( !v4 )
return 0LL;
memcpy(v4, a2 + 4, *v2);
v5 = deserialize_syscall_info(v2);
del(v2[1]);
del(v2);
return v5;
}

original_code:
syscall_intercept_info *read_from_socket(int sock_fd, struct nlmsghdr *nlh){
 membuffer *x;
 syscall_intercept_info *i;
 struct iovec iov;
 struct msghdr msg;
 iov.iov_base = nlh;
 iov.iov_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 msg.msg_name = ((void *)0);
 msg.msg_namelen = 0;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = ((void *)0);
 msg.msg_controllen = 0;
 msg.msg_flags = 0;
 if (recvmsg(sock_fd, &msg, MSG_DONTWAIT) <= 0)
  return ((void *)0);
 x = new(sizeof(membuffer));
 if(!x){
  return ((void *)0);
 }
 x->len = nlh->nlmsg_len - ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ));
 x->data = new(x->len);
 if(!x->data){
  return ((void *)0);
 }
 memcpy(x->data, ((void*)(((char*)nlh) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))), x->len);
 i = deserialize_syscall_info(x);
 del(x->data);
 del(x);
 if(!i){
  return ((void *)0);
 }
 return i;
}

canonical_original_code:
struct syscall_intercept_info *read_from_socket(int sock_fd, struct nlmsghdr *nlh){
 struct membuffer *x;
 struct syscall_intercept_info *i;
 struct iovec iov;
 struct msghdr msg;
 iov.iov_base = nlh;
 iov.iov_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 msg.msg_name = ((void *)0);
 msg.msg_namelen = 0;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = ((void *)0);
 msg.msg_controllen = 0;
 msg.msg_flags = 0;
 if (recvmsg(sock_fd, &msg, MSG_DONTWAIT) <= 0)
  return ((void *)0);
 x = new(sizeof(membuffer));
 if(!x){
  return ((void *)0);
 }
 x->len = nlh->nlmsg_len - ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ));
 x->data = new(x->len);
 if(!x->data){
  return ((void *)0);
 }
 memcpy(x->data, ((void *)(((char *)nlh) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))), x->len);
 i = deserialize_syscall_info(x);
 del(x->data);
 del(x);
 if(!i){
  return ((void *)0);
 }
 return i;
}

variable_types: struct membuffer { unsigned long len; unsigned char *data; } *

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

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

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


original_code:
void *get_chunk(membuffer *buffer){
 size_t size;
 void *chunk;
 membuffer *tmp;
 memcpy(&size, buffer->data, sizeof(size_t));
 chunk = new(size);
 memcpy(chunk, buffer->data + sizeof(size_t), size);
 tmp = new(sizeof(membuffer));
 tmp->len = buffer->len - sizeof(size_t) - size;
 tmp->data = new(tmp->len);
 memcpy(tmp->data, buffer->data + sizeof(size_t) + size, tmp->len);
 del(buffer->data);
 buffer->data = tmp->data;
 buffer->len = tmp->len;
 del(tmp);
 return chunk;
}

canonical_original_code:
void *get_chunk(struct membuffer *buffer){
 unsigned long size;
 void *chunk;
 struct membuffer *tmp;
 memcpy(&size, buffer->data, sizeof(unsigned long));
 chunk = new(size);
 memcpy(chunk, buffer->data + sizeof(unsigned long), size);
 tmp = new(sizeof(membuffer));
 tmp->len = buffer->len - sizeof(unsigned long) - size;
 tmp->data = new(tmp->len);
 memcpy(tmp->data, buffer->data + sizeof(unsigned long) + size, tmp->len);
 del(buffer->data);
 buffer->data = tmp->data;
 buffer->len = tmp->len;
 del(tmp);
 return chunk;
}

variable_types:
size
unsigned long

variable_types:
chunk
void *

user_defined_types: struct membuffer { unsigned long len; unsigned char *data; }


decompiled_code:
__int64 __fastcall deserialize_syscall_info(__int64 a1)
{
__int64 v1; // r12
_DWORD *v2; // rax

v1 = new(48LL);
if ( v1 )
{
*(_QWORD *)v1 = get_chunk(a1);
v2 = get_chunk(a1);
*(_DWORD *)(v1 + 8) = *v2;
del(v2);
*(_QWORD *)(v1 + 16) = get_chunk(a1);
*(_QWORD *)(v1 + 24) = get_chunk(a1);
*(_QWORD *)(v1 + 32) = get_chunk(a1);
*(_QWORD *)(v1 + 40) = get_chunk(a1);
}
return v1;
}

original_code:
syscall_intercept_info *deserialize_syscall_info(membuffer *buffer){
 void *tmp;
 syscall_intercept_info *i = new(sizeof(struct syscall_intercept_info));
 if(!i){
  return ((void *)0);
 }
 i->pname = (char *)get_chunk(buffer);
 tmp = get_chunk(buffer);
 i->pid = *(pid_t *)tmp;
 del(tmp);
 i->operation = (char *)get_chunk(buffer);
 i->path = (char *)get_chunk(buffer);
 i->result = (char *)get_chunk(buffer);
 i->details = (char *)get_chunk(buffer);
 return i;
}

canonical_original_code:
struct syscall_intercept_info *deserialize_syscall_info(struct membuffer *buffer){
 void *tmp;
 struct syscall_intercept_info *i = new(sizeof(struct syscall_intercept_info));
 if(!i){
  return ((void *)0);
 }
 i->pname = (char *)get_chunk(buffer);
 tmp = get_chunk(buffer);
 i->pid = *(int *)tmp;
 del(tmp);
 i->operation = (char *)get_chunk(buffer);
 i->path = (char *)get_chunk(buffer);
 i->result = (char *)get_chunk(buffer);
 i->details = (char *)get_chunk(buffer);
 return i;
}

variable_types:
tmp
void *

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


rstrip

decompiled_code:
void __fastcall rstrip(const char *a1)
{
int v1; // ebx
const unsigned __int16 **v2; // rsi
__int64 i; // rax

if ( a1 )
{
v1 = strlen(a1);
v2 = _ctype_b_loc();
for ( i = v1 - 1; ((*v2)[a1[i]] & 0x2000) != 0 && (int)i >= 0; --i )
a1[i] = 0;
}
}

canonical_decompiled_code:
void __fastcall func1(const char *a1)
{
int v1; // ebx
const unsigned __int16 **v2; // rsi
__int64 i; // rax

if ( a1 )
{
v1 = strlen(a1);
v2 = _ctype_b_loc();
for ( i = v1 - 1; ((*v2)[a1[i]] & 0x2000) != 0 && (int)i >= 0; --i )
a1[i] = 0;
}
}

original_code:
void rstrip(char *string){
 int l;
 if(!string){
  return;
 }
 l = strlen(string) - 1;
 while(((*__ctype_b_loc ())[(int) ((string[l]))] & (unsigned short int) _ISspace) && l >= 0){
  string[l--] = 0;
 }
}

canonical_original_code:
void rstrip(char *string){
 int l;
 if(!string){
  return;
 }
 l = strlen(string) - 1;
 while(((*__ctype_b_loc ())[(int) ((string[l]))] & (unsigned short) _ISspace) && l >= 0){
  string[l--] = 0;
 }
}

variable_types:
string
char *

variable_types: l int


original_code:
char *get_str_info(syscall_intercept_info *i){
 int err;
 int max_len = 2048;
 char *tmp = new(max_len);
 if(!tmp){
  return ((void *)0);
 }
 err = snprintf(tmp,
  max_len,
  "%-15.20s"
  "%10u"
  " %-15.10s"
  "%-50.45s"
  "%-10.10s"
  " %-200.200s\n",
  i->pname,
  i->pid,
  i->operation,
  i->path,
  i->result,
  i->details
 );
 if(err < 0){
  del(tmp);
  return ((void *)0);
 }
 rstrip(tmp);
 return tmp;
}

canonical_original_code:
char *get_str_info(struct syscall_intercept_info *i){
 int err;
 int max_len = 2048;
 char *tmp = new(max_len);
 if(!tmp){
  return ((void *)0);
 }
 err = snprintf(tmp,
  max_len,
  "%-15.20s"
  "%10u"
  " %-15.10s"
  "%-50.45s"
  "%-10.10s"
  " %-200.200s\n",
  i->pname,
  i->pid,
  i->operation,
  i->path,
  i->result,
  i->details
 );
 if(err < 0){
  del(tmp);
  return ((void *)0);
 }
 rstrip(tmp);
 return tmp;
}

variable_types: err int


lstrip

decompiled_code:
void __fastcall lstrip(void *dest)
{
int v1; // er12
const unsigned __int16 **v2; // r13
unsigned __int16 v3; // ax

if ( dest )
{
v1 = strlen((const char *)dest);
v2 = _ctype_b_loc();
v3 = (*v2)[*(char *)dest];
while ( (v3 & 0x2000) != 0 )
{
while ( v1 > 0 )
{
memmove(dest, (char *)dest + 1, (unsigned int)(v1 - 1) + 1LL);
v3 = (*v2)[*(char *)dest];
if ( (v3 & 0x2000) == 0 )
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(void *dest)
{
int v1; // er12
const unsigned __int16 **v2; // r13
unsigned __int16 v3; // ax

if ( dest )
{
v1 = strlen((const char *)dest);
v2 = _ctype_b_loc();
v3 = (*v2)[*(char *)dest];
while ( (v3 & 0x2000) != 0 )
{
while ( v1 > 0 )
{
memmove(dest, (char *)dest + 1, (unsigned int)(v1 - 1) + 1LL);
v3 = (*v2)[*(char *)dest];
if ( (v3 & 0x2000) == 0 )
return;
}
}
}
}

original_code:
void lstrip(char *string){
 int i, l;
 if(!string){
  return;
 }
 l = strlen(string);
 while(((*__ctype_b_loc ())[(int) ((string[(i = 0)]))] & (unsigned short int) _ISspace)){
  while(i++ < l){
   string[i-1] = string[i];
  }
 }
}

canonical_original_code:
void lstrip(char *string){
 int i; int l;
 if(!string){
  return;
 }
 l = strlen(string);
 while(((*__ctype_b_loc ())[(int) ((string[(i = 0)]))] & (unsigned short) _ISspace)){
  while(i++ < l){
   string[i-1] = string[i];
  }
 }
}


main

repo: alexandream/atest

original_code:
int main(int argc, char** argv) {
    SuiteSummary* summary_pool;
    int num_summaries = 0;
    int max_summaries = argc -1;
    int error = 0;
    int i;
    if (argc < 2) {
        fprintf(stderr, "Wrong number of arguments.\n");
        exit(1);
    }
    summary_pool = malloc(sizeof(SuiteSummary)*max_summaries);
    if (summary_pool == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(2);
    }
    for (i = 0; i < max_summaries; i++) {
        SuiteSummary *summary = summary_pool + i;
        const char* file_name = argv[i+1];
        error = process_output_file(file_name, summary);
        if (error) {
            fprintf(stderr, "Got error %d while processing file %s.\n",
                    error, file_name);
            exit(3);
        }
        num_summaries++;
    }
    printf ("%s\n", ("========================================" "========================================"));
    printf("| %-46s| %s | %s | %s | %s |\n",
           "Suite Name", "Tests", "Errors", "Fails", "  %");
    printf("|%s|%s|%s|%s|%s|\n",
           "-----------------------------------------------",
           "-------","--------","-------","-----");
    for (i = 0; i < num_summaries; i++) {
        SuiteSummary *summary = summary_pool +i;
        int percent;
  if (summary->tests > 0) {
   percent = 100 - 100 * (summary->errors + summary->failures)
                                / summary->tests;
  }
  else {
   percent = 0;
  }
        printf("| %-46s|   %3d |    %3d |   %3d | %3d |\n",
               summary->name, summary->tests, summary->errors,
               summary->failures, percent);
    }
    printf(" %s \n",
           "---------------------------------------"
           "---------------------------------------");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct SuiteSummary *summary_pool;
    int num_summaries = 0;
    int max_summaries = argc -1;
    int error = 0;
    int i;
    if (argc < 2) {
        fprintf(stderr, "Wrong number of arguments.\n");
        exit(1);
    }
    summary_pool = malloc(sizeof(SuiteSummary)*max_summaries);
    if (summary_pool == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(2);
    }
    for (i = 0; i < max_summaries; i++) {
        struct SuiteSummary *summary = summary_pool + i;
        char *file_name = argv[i+1];
        error = process_output_file(file_name, summary);
        if (error) {
            fprintf(stderr, "Got error %d while processing file %s.\n",
                    error, file_name);
            exit(3);
        }
        num_summaries++;
    }
    printf ("%s\n", ("========================================" "========================================"));
    printf("| %-46s| %s | %s | %s | %s |\n",
           "Suite Name", "Tests", "Errors", "Fails", "  %");
    printf("|%s|%s|%s|%s|%s|\n",
           "-----------------------------------------------",
           "-------","--------","-------","-----");
    for (i = 0; i < num_summaries; i++) {
        struct SuiteSummary *summary = summary_pool +i;
        int percent;
  if (summary->tests > 0) {
   percent = 100 - 100 * (summary->errors + summary->failures)
                                / summary->tests;
  }
  else {
   percent = 0;
  }
        printf("| %-46s|   %3d |    %3d |   %3d | %3d |\n",
               summary->name, summary->tests, summary->errors,
               summary->failures, percent);
    }
    printf(" %s \n",
           "---------------------------------------"
           "---------------------------------------");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct SuiteSummary { char *name; int tests; int errors; int failures; } *

variable_types: error int

variable_types: percent int


decompiled_code:
const char *__fastcall read_line(const char **a1)
{
const char *v1; // r12
char *v2; // rax

v1 = *a1;
v2 = strchr(*a1, 10);
if ( v2 )
{
*v2 = 0;
*a1 = v2 + 1;
}
else
{
*a1 = &v1[strlen(v1)];
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func8(const char **a1)
{
const char *v1; // r12
char *v2; // rax

v1 = *a1;
v2 = strchr(*a1, 10);
if ( v2 )
{
*v2 = 0;
*a1 = v2 + 1;
}
else
{
*a1 = &v1[strlen(v1)];
}
return v1;
}

original_code:
char* read_line(char** buffer) {
    char *result = *buffer;
    char* eol = strchr(*buffer, '\n');
    if (eol) {
        *eol = '\0';
        *buffer = eol+1;
    }
    else {
        size_t len = strlen(*buffer);
        *buffer = *buffer + len;
    }
    return result;
}

canonical_original_code:
char *read_line(char **buffer) {
    char *result = *buffer;
    char *eol = strchr(*buffer, '\n');
    if (eol) {
        *eol = '\0';
        *buffer = eol+1;
    }
    else {
        unsigned long len = strlen(*buffer);
        *buffer = *buffer + len;
    }
    return result;
}

variable_types:
buffer
char **

variable_types:
result
char *

variable_types:
eol
char *

variable_types:
len
unsigned long


decompiled_code:
int __fastcall process_footer(char *a1, _DWORD *a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
int result; // eax

strtok(a1, "\t");
v2 = strtok(0LL, "\t");
a2[2] = atoi(v2);
v3 = strtok(0LL, "\t");
a2[3] = atoi(v3);
v4 = strtok(0LL, "\t");
result = atoi(v4);
a2[4] = result;
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *a1, _DWORD *a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
int result; // eax

strtok(a1, "\t");
v2 = strtok(0LL, "\t");
a2[2] = atoi(v2);
v3 = strtok(0LL, "\t");
a2[3] = atoi(v3);
v4 = strtok(0LL, "\t");
result = atoi(v4);
a2[4] = result;
return result;
}

original_code:
void process_footer(char* line, SuiteSummary* summary) {
    strtok(line, "\t");
    summary->tests = atoi(strtok(((void *)0), "\t"));
    summary->errors = atoi(strtok(((void *)0), "\t"));
    summary->failures = atoi(strtok(((void *)0), "\t"));
}

canonical_original_code:
void process_footer(char *line, struct SuiteSummary *summary) {
    strtok(line, "\t");
    summary->tests = atoi(strtok(((void *)0), "\t"));
    summary->errors = atoi(strtok(((void *)0), "\t"));
    summary->failures = atoi(strtok(((void *)0), "\t"));
}

variable_types:
line
char *

user_defined_types: struct SuiteSummary { char *name; int tests; int errors; int failures; }


original_code:
char*
decode_crlf(const char* input) {
 char* result;
 size_t length = strlen(input);
 size_t i;
 size_t j;
 result = malloc(sizeof(char) * (length + 1));
 if (result == ((void *)0)) {
  return ((void *)0);
 }
 for (i = 0, j = 0; i < length; i++, j++) {
  if (input[i] == '\\') {
   char c = input[i+1];
   if (c != '\\' && c != 'n' && c != 'r') {
    free(result);
    (*__errno_location ()) = 33;
    return ((void *)0);
   }
   result[j] = (c == '\\') ? '\\'
             : (c == 'r') ? '\r'
             : '\n';
   i++;
  }
  else {
   result[j] = input[i];
  }
 }
 result[j] = '\0';
 return result;
}

canonical_original_code:
char *decode_crlf(char *input) {
 char *result;
 unsigned long length = strlen(input);
 unsigned long i;
 unsigned long j;
 result = malloc(sizeof(char) * (length + 1));
 if (result == ((void *)0)) {
  return ((void *)0);
 }
 for (i = 0, j = 0; i < length; i++, j++) {
  if (input[i] == '\\') {
   char c = input[i+1];
   if (c != '\\' && c != 'n' && c != 'r') {
    free(result);
    (*__errno_location ()) = 33;
    return ((void *)0);
   }
   result[j] = (c == '\\') ? '\\'
             : (c == 'r') ? '\r'
             : '\n';
   i++;
  }
  else {
   result[j] = input[i];
  }
 }
 result[j] = '\0';
 return result;
}

variable_types:
input
char *

variable_types:
length
unsigned long

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types: c char


decompiled_code:
__int64 __fastcall process_output_file(const char *a1, __int64 *a2)
{
const char *v2; // rax
char i; // al
__int64 v4; // rbp
char *v5; // rax
char *v6; // rax
const char *v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = (const char *)read_file_to_memory(a1);
if ( !v8[0] )
return 0xFFFFFFFFLL;
v2 = read_line(v8);
process_header((__int64)v2, a2);
for ( i = *v8[0]; *v8[0]; i = *v8[0] )
{
if ( i == 35 )
break;
v4 = *a2;
v5 = (char *)read_line(v8);
process_result(v5, v4);
}
v6 = (char *)read_line(v8);
process_footer(v6, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, __int64 *a2)
{
const char *v2; // rax
char i; // al
__int64 v4; // rbp
char *v5; // rax
char *v6; // rax
const char *v8[4]; // [rsp+8h] [rbp-20h] BYREF

v8[0] = (const char *)read_file_to_memory(a1);
if ( !v8[0] )
return 0xFFFFFFFFLL;
v2 = func8(v8);
func9((__int64)v2, a2);
for ( i = *v8[0]; *v8[0]; i = *v8[0] )
{
if ( i == 35 )
break;
v4 = *a2;
v5 = (char *)func8(v8);
func12(v5, v4);
}
v6 = (char *)func8(v8);
func10(v6, a2);
return 0LL;
}

original_code:
int process_output_file(const char* file_name, SuiteSummary *summary) {
    char* buffer = read_file_to_memory(file_name);
    char* p = buffer;
    if (buffer == ((void *)0)) {
        return -1;
    }
    process_header(read_line(&p), summary);
    while(*p && *p != '#') {
        process_result(read_line(&p), summary->name);
    }
    process_footer(read_line(&p), summary);
    return 0;
}

canonical_original_code:
int process_output_file(char *file_name, struct SuiteSummary *summary) {
    char *buffer = read_file_to_memory(file_name);
    char *p = buffer;
    if (buffer == ((void *)0)) {
        return -1;
    }
    process_header(read_line(&p), summary);
    while(*p && *p != '#') {
        process_result(read_line(&p), summary->name);
    }
    process_footer(read_line(&p), summary);
    return 0;
}

variable_types:
buffer
char *

variable_types:
p
char *


original_code:
void process_result(char* line, const char* suite) {
    char extra_info[81];
    char dash_line[81];
    const char* type = strtok(line, "\t");
    const char* name = strtok(((void *)0), "\t");
    const char* file = strtok(((void *)0), "\t");
    char* line_num = strtok(((void *)0), "\t");
    char* check = strtok(((void *)0), "\t");
    char* n_checks = strtok(((void *)0), "\t");
    char* msg = decode_crlf(strtok(((void *)0), "\t"));
    int extra_info_len = strlen(file) + strlen(line_num) + strlen(check) +
                         strlen(n_checks) + 7;
    if (msg == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(19);
    }
    printf("%s\n", ("========================================" "========================================"));
    printf("%-5s: %s.%s\n",
           *type == 'E' ? "ERROR" : "FAIL",
           suite, name);
    strcpy(dash_line, ("----------------------------------------" "----------------------------------------"));
    sprintf(extra_info, " %s, %s, %s/%s ",
            file, line_num, check, n_checks);
    memcpy(dash_line+(80 - extra_info_len ), extra_info, extra_info_len);
    printf("%s\n\n", dash_line);
    printf("%s\n\n", msg);
    free(msg);
}

canonical_original_code:
void process_result(char *line, char *suite) {
    char extra_info[81];
    char dash_line[81];
    char *type = strtok(line, "\t");
    char *name = strtok(((void *)0), "\t");
    char *file = strtok(((void *)0), "\t");
    char *line_num = strtok(((void *)0), "\t");
    char *check = strtok(((void *)0), "\t");
    char *n_checks = strtok(((void *)0), "\t");
    char *msg = decode_crlf(strtok(((void *)0), "\t"));
    int extra_info_len = strlen(file) + strlen(line_num) + strlen(check) +
                         strlen(n_checks) + 7;
    if (msg == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(19);
    }
    printf("%s\n", ("========================================" "========================================"));
    printf("%-5s: %s.%s\n",
           *type == 'E' ? "ERROR" : "FAIL",
           suite, name);
    strcpy(dash_line, ("----------------------------------------" "----------------------------------------"));
    sprintf(extra_info, " %s, %s, %s/%s ",
            file, line_num, check, n_checks);
    memcpy(dash_line+(80 - extra_info_len ), extra_info, extra_info_len);
    printf("%s\n\n", dash_line);
    printf("%s\n\n", msg);
    free(msg);
}

variable_types:
suite
char *

variable_types:
type
char *

variable_types:
name
char *

variable_types:
file
char *

variable_types:
check
char *

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall at_eq_long(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi
__int64 result; // rax

if ( a3 == a4 )
{
at_make_success(a1, a2, a3, a4, a3);
result = a1;
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %ld but found to have value %ld.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi
__int64 result; // rax

if ( a3 == a4 )
{
at_make_success(a1, a2, a3, a4, a3);
result = a1;
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %ld but found to have value %ld.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

original_code:
AtCheckResult at_eq_long(const char* expr, long value, long expected) {
 do { if (! ((value == expected)) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "%ld" " but found to have value " "%ld" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_long(char *expr, long value, long expected) {
 do { if (! ((value == expected)) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "%ld" " but found to have value " "%ld" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
expr
char *

variable_types: value long

variable_types: expected long

return_type: struct AtCheckResult { int status; int check_number; char *message; char *file_name; int line_number; void (*clean_up)(char *); }


decompiled_code:
__int64 __fastcall at_eq_ulong(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi
__int64 result; // rax

if ( a3 == a4 )
{
at_make_success(a1, a2, a3, a4, a3);
result = a1;
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %lu but found to have value %lu.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi
__int64 result; // rax

if ( a3 == a4 )
{
at_make_success(a1, a2, a3, a4, a3);
result = a1;
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %lu but found to have value %lu.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
result = a1;
}
return result;
}

original_code:
AtCheckResult at_eq_ulong(const char* expr, unsigned long value,
                          unsigned long expected) {
 do { if (! ((value == expected)) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "%lu" " but found to have value " "%lu" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_ulong(char *expr, unsigned long value, unsigned long expected) {
 do { if (! ((value == expected)) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "%lu" " but found to have value " "%lu" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
value
unsigned long

variable_types:
expected
unsigned long

user_defined_types: struct AtCheckResult { int status; int check_number; char *message; char *file_name; int line_number; void (*clean_up)(char *); }