decompiled_code:
void __fastcall free_process(void *ptr)
{
list_iterate_constprop_0_isra_0(**((_QWORD **)ptr + 1));
list_free_isra_0(**((void ***)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
func3(**((_QWORD **)ptr + 1));
func5(**((void ***)ptr + 1));
free(ptr);
}

original_code:
void
free_process(struct proc_process* p) {
 list_iterate(*p->chunks,free_chunk);
 list_free(*p->chunks);
 free(p);
}

canonical_original_code:
void free_process(struct proc_process *p) {
 list_iterate(*p->chunks,free_chunk);
 list_free(*p->chunks);
 free(p);
}

variable_types: struct proc_process { char *name; struct list { struct item { void *p; struct item *next; } *head; int len; } *chunks; } *


repo: lomegor/procs

decompiled_code:
unsigned __int64 __fastcall get_long(const char **a1, char a2, int a3)
{
const char *v4; // rbp
char *v5; // rax

v4 = *a1;
v5 = strchr(*a1, a2);
if ( !v5 )
return 0LL;
*v5 = 0;
*a1 = v5;
return strtoul(v4, 0LL, a3);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(const char **a1, char a2, int a3)
{
const char *v4; // rbp
char *v5; // rax

v4 = *a1;
v5 = strchr(*a1, a2);
if ( !v5 )
return 0LL;
*v5 = 0;
*a1 = v5;
return strtoul(v4, 0LL, a3);
}

original_code:
unsigned long
get_long(char** start, char search, unsigned int base) {
 char *ptr1,*ptr2;
 ptr1 = *start;
 if ((ptr2 = strchr(ptr1, search)) == ((void *)0))
  return 0;
 *ptr2 = '\0';
 *start = ptr2;
 return strtoul(ptr1, ((void *)0), base);
}

canonical_original_code:
unsigned long get_long(char **start, char search, unsigned int base) {
 char *ptr1; char *ptr2;
 ptr1 = *start;
 if ((ptr2 = strchr(ptr1, search)) == ((void *)0))
  return 0;
 *ptr2 = '\0';
 *start = ptr2;
 return strtoul(ptr1, ((void *)0), base);
}

variable_types:
start
char **

variable_types: search char

variable_types:
base
unsigned int

return_type: unsigned long


decompiled_code:
size_t __fastcall read_from_file_pointer(FILE *stream, void *ptr, size_t size)
{
size_t result; // rax

result = fread(ptr, size, 1uLL, stream);
if ( !result )
result = -1LL;
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(FILE *stream, void *ptr, size_t size)
{
size_t result; // rax

result = fread(ptr, size, 1uLL, stream);
if ( !result )
result = -1LL;
return result;
}

original_code:
long
read_from_file_pointer(void* fp, void* mem, size_t s) {
 long i = fread(mem,s,1,(FILE*)fp);
 if (i==0) return -1;
 return i;
}

canonical_original_code:
long read_from_file_pointer(void *fp, void *mem, unsigned long s) {
 long i = fread(mem,s,1,(FILE*)fp);
 if (i==0) return -1;
 return i;
}

variable_types:
fp
void *

variable_types:
mem
void *

variable_types:
s
unsigned long

variable_types: i long

return_type: long


decompiled_code:
ssize_t __fastcall write_to_socket(int *a1, const void *a2, size_t a3)
{
return write(*a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func11(int *a1, const void *a2, size_t a3)
{
return write(*a1, a2, a3);
}

original_code:
void
write_to_socket(void* fp, void* mem, size_t s) {
 write(*(int*)fp,mem,s);
}

canonical_original_code:
void write_to_socket(void *fp, void *mem, unsigned long s) {
 write(*(int *)fp,mem,s);
}

return_type: void


decompiled_code:
ssize_t __fastcall read_from_socket(int *a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r13
unsigned __int64 v5; // rsi
ssize_t result; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
v5 = 0LL;
while ( 1 )
{
result = read(*a1, (void *)(a2 + v5), a3 - v5);
if ( result < 0 )
break;
v3 += result;
v5 = v3;
if ( v3 >= a3 )
return v3;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func12(int *a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r13
unsigned __int64 v5; // rsi
ssize_t result; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
v5 = 0LL;
while ( 1 )
{
result = read(*a1, (void *)(a2 + v5), a3 - v5);
if ( result < 0 )
break;
v3 += result;
v5 = v3;
if ( v3 >= a3 )
return v3;
}
return result;
}

original_code:
long
read_from_socket(void* socket,void* mem, size_t size) {
 long bytesread=0;
 while (bytesread<size) {
  long a = read(*(int*)socket,(void*)(mem+bytesread),size-bytesread);
  if (a<0)
   return a;
  bytesread+=a;
 }
 return bytesread;
}

canonical_original_code:
long read_from_socket(void *socket, void *mem, unsigned long size) {
 long bytesread = 0;
 while (bytesread<size) {
  long a = read(*(int*)socket,(void*)(mem+bytesread),size-bytesread);
  if (a<0)
   return a;
  bytesread+=a;
 }
 return bytesread;
}

variable_types:
socket
void *

variable_types:
size
unsigned long

variable_types: bytesread long

variable_types: a long


original_code:
static inline void
list_init(struct list *l) {
 l->head = l->tail = ((void *)0);
 l->len=0;
}

variable_types: struct list { struct item { void *p; struct item *next; } *head; int len; } *

user_defined_types: struct list { struct item *head; int len; }


original_code:
int
get_one_vma(pid_t pid, char* line, struct proc_vma *vma, int vma_no, long *bin_offset) {
 char *ptr1,*ptr2 = ((void *)0);
 int to_read = 0;
 memset(vma, 0, sizeof(struct proc_vma));
 ptr1 = line;
 vma->start = get_long(&ptr1,'-',16);
 ptr1++;
 vma->length = get_long(&ptr1,' ',16) - vma->start;
 ptr1++;
 vma->prot = 0;
 vma->flags = 0x10;
 ptr1[0] == 'r' && (vma->prot |= 0x1);
 ptr1[1] == 'w' && (vma->prot |= 0x2);
 ptr1[2] == 'x' && (vma->prot |= 0x4);
 if (ptr1[3] == 's')
  vma->flags |= 0x01;
 else if (ptr1[3] == 'p')
  vma->flags |= 0x02;
 ptr1 = ptr1+5;
 vma->pg_off = get_long(&ptr1,' ',16);
 if ((signed long)vma->pg_off < 0)
  vma->flags |= 0x00100;
 ptr1++;
 unsigned long dmajor = get_long(&ptr1,':',16);
 ptr1++;
 unsigned long dminor = get_long(&ptr1,' ',16);
 vma->dev = ((dmajor)<<8 | (dminor));
 ptr1++;
 vma->inode = get_long(&ptr1,' ',10);
 ptr1++;
 while (*ptr1 == ' ') ptr1++;
 if (*ptr1 != '\n') {
  ptr2 = strchr(ptr1, '\n');
  *ptr2 = '\0';
  vma->filename = strdup(ptr1);
  to_read = 1;
  if (strstr(ptr1, ".so") != ((void *)0)) {
   vma->is_lib=1;
   char* ptr3 = ptr1;
   while ((ptr2 = strchr(ptr3,'/')) != ((void *)0))
    ptr3 = ptr2+1;
   ptr2 = strchr(ptr1,'-');
   *ptr2 = '.';
   *(ptr2+1)='s';
   *(ptr2+2)='o';
   *(ptr2+3)='\0';
   vma->filename = strdup(ptr3);
  } else if (strstr(ptr1,"[heap]") != ((void *)0)) {
   (*bin_offset) = vma->start;
   vma->flags |= 0x20;
   vma->is_heap=1;
  }
 } else {
  vma->flags |= 0x20;
  to_read = 1;
 }
 if (to_read) {
  vma->data = malloc(vma->length);
  long i, n = vma->length/sizeof(long);
  for (i = 0; i < n; i++) {
   vma->data[i] = ptrace(PTRACE_PEEKTEXT, pid, vma->start+(i*sizeof(long)), 0);
   if ((*__errno_location ())) {
   }
  }
  vma->have_data=1;
 } else {
  if (vma->data!=((void *)0)) {
   free(vma->data);
   vma->data=((void *)0);
  }
  vma->have_data=0;
 }
 last_vma_end = vma->start + vma->length;
 return 1;
}

canonical_original_code:
int get_one_vma(int pid, char *line, struct proc_vma *vma, int vma_no, long *bin_offset) {
 char *ptr1; char *ptr2 = ((void *)0);
 int to_read = 0;
 memset(vma, 0, sizeof(struct proc_vma));
 ptr1 = line;
 vma->start = get_long(&ptr1,'-',16);
 ptr1++;
 vma->length = get_long(&ptr1,' ',16) - vma->start;
 ptr1++;
 vma->prot = 0;
 vma->flags = 0x10;
 ptr1[0] == 'r' && (vma->prot |= 0x1);
 ptr1[1] == 'w' && (vma->prot |= 0x2);
 ptr1[2] == 'x' && (vma->prot |= 0x4);
 if (ptr1[3] == 's')
  vma->flags |= 0x01;
 else if (ptr1[3] == 'p')
  vma->flags |= 0x02;
 ptr1 = ptr1+5;
 vma->pg_off = get_long(&ptr1,' ',16);
 if ((long)vma->pg_off < 0)
  vma->flags |= 0x00100;
 ptr1++;
 unsigned long dmajor = get_long(&ptr1,':',16);
 ptr1++;
 unsigned long dminor = get_long(&ptr1,' ',16);
 vma->dev = ((dmajor)<<8 | (dminor));
 ptr1++;
 vma->inode = get_long(&ptr1,' ',10);
 ptr1++;
 while (*ptr1 == ' ') ptr1++;
 if (*ptr1 != '\n') {
  ptr2 = strchr(ptr1, '\n');
  *ptr2 = '\0';
  vma->filename = strdup(ptr1);
  to_read = 1;
  if (strstr(ptr1, ".so") != ((void *)0)) {
   vma->is_lib=1;
   char *ptr3 = ptr1;
   while ((ptr2 = strchr(ptr3,'/')) != ((void *)0))
    ptr3 = ptr2+1;
   ptr2 = strchr(ptr1,'-');
   *ptr2 = '.';
   *(ptr2+1)='s';
   *(ptr2+2)='o';
   *(ptr2+3)='\0';
   vma->filename = strdup(ptr3);
  } else if (strstr(ptr1,"[heap]") != ((void *)0)) {
   (*bin_offset) = vma->start;
   vma->flags |= 0x20;
   vma->is_heap=1;
  }
 } else {
  vma->flags |= 0x20;
  to_read = 1;
 }
 if (to_read) {
  vma->data = malloc(vma->length);
  long i; long n = vma->length/sizeof(long);
  for (i = 0; i < n; i++) {
   vma->data[i] = ptrace(PTRACE_PEEKTEXT, pid, vma->start+(i*sizeof(long)), 0);
   if ((*__errno_location ())) {
   }
  }
  vma->have_data=1;
 } else {
  if (vma->data!=((void *)0)) {
   free(vma->data);
   vma->data=((void *)0);
  }
  vma->have_data=0;
 }
 last_vma_end = vma->start + vma->length;
 return 1;
}

variable_types: pid int

variable_types:
line
char *

variable_types: struct proc_vma { unsigned long start; int prot; long pg_off; char *filename; long *data; } *

variable_types:
dmajor
unsigned long

variable_types:
dminor
unsigned long

variable_types: n long

return_type: int


decompiled_code:
__int64 __fastcall save_process(__pid_t pid, __int64 a2, int a3)
{
void *v4; // rbx
__int64 result; // rax
__int64 v6[6]; // [rsp+8h] [rbp-30h] BYREF

v4 = malloc(0x18uLL);
list_init((__int64)v4);
if ( ptrace(PTRACE_ATTACH, (unsigned int)pid) == -1 && *_errno_location() )
{
perror("error attach");
result = a2;
}
else
{
waitpid(pid, 0LL, 0);
fetch_chunks_vma(pid, (__int64)v4, v6);
fetch_chunks_fd(pid, (__int64)v4);
fetch_chunks_regs(pid, (__int64)v4);
if ( a3 )
{
if ( ptrace(PTRACE_CONT, (unsigned int)pid, 0LL, 0LL) == -1 && *_errno_location() )
perror("error cont");
}
else if ( ptrace(PTRACE_KILL, (unsigned int)pid, 0LL, 0LL) == -1 )
{
if ( *_errno_location() )
perror("error kill");
}
result = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__pid_t pid, __int64 a2, int a3)
{
void *v4; // rbx
__int64 result; // rax
__int64 v6[6]; // [rsp+8h] [rbp-30h] BYREF

v4 = malloc(0x18uLL);
func0((__int64)v4);
if ( ptrace(PTRACE_ATTACH, (unsigned int)pid) == -1 && *_errno_location() )
{
perror("error attach");
result = a2;
}
else
{
waitpid(pid, 0LL, 0);
func3(pid, (__int64)v4, v6);
func4(pid, (__int64)v4);
fetch_chunks_regs(pid, (__int64)v4);
if ( a3 )
{
if ( ptrace(PTRACE_CONT, (unsigned int)pid, 0LL, 0LL) == -1 && *_errno_location() )
perror("error cont");
}
else if ( ptrace(PTRACE_KILL, (unsigned int)pid, 0LL, 0LL) == -1 )
{
if ( *_errno_location() )
perror("error kill");
}
result = a2;
}
return result;
}

original_code:
struct proc_process
save_process(pid_t pid,char* name, int nokill)
{
 struct proc_process saved_process;
 saved_process.name=name;
 struct list *chunks=malloc(sizeof(struct list));
 list_init(chunks);
 long offset;
 if (ptrace(PTRACE_ATTACH, pid, ((void *)0), ((void *)0))== -1 && (*__errno_location ())) {
  perror("error attach");
  return saved_process;
 }
 waitpid(pid,0,0);
 fetch_chunks_vma(pid, chunks, &offset);
  fetch_chunks_fd(pid, chunks);
  fetch_chunks_regs(pid,chunks);
 if (nokill) {
  if (ptrace(PTRACE_CONT, pid, ((void *)0), ((void *)0))== -1 && (*__errno_location ())) {
    perror("error cont");
    return saved_process;
  }
 } else if (ptrace(PTRACE_KILL, pid, ((void *)0), ((void *)0))== -1 && (*__errno_location ())) {
  perror("error kill");
  return saved_process;
 }
 saved_process.chunks = chunks;
 return saved_process;
}

canonical_original_code:
struct proc_process save_process(int pid, char *name, int nokill)
{
 struct proc_process saved_process;
 saved_process.name=name;
 struct list *chunks = malloc(sizeof(struct list));
 list_init(chunks);
 long offset;
 if (ptrace(PTRACE_ATTACH, pid, ((void *)0), ((void *)0))== -1 && (*__errno_location ())) {
  perror("error attach");
  return saved_process;
 }
 waitpid(pid,0,0);
 fetch_chunks_vma(pid, chunks, &offset);
  fetch_chunks_fd(pid, chunks);
  fetch_chunks_regs(pid,chunks);
 if (nokill) {
  if (ptrace(PTRACE_CONT, pid, ((void *)0), ((void *)0))== -1 && (*__errno_location ())) {
    perror("error cont");
    return saved_process;
  }
 } else if (ptrace(PTRACE_KILL, pid, ((void *)0), ((void *)0))== -1 && (*__errno_location ())) {
  perror("error kill");
  return saved_process;
 }
 saved_process.chunks = chunks;
 return saved_process;
}

variable_types:
name
char *

variable_types: nokill int

variable_types: struct proc_process { char *name; struct list { struct item { void *p; struct item *next; } *head; int len; } *chunks; }

variable_types: offset long

user_defined_types: struct proc_process { char *name; struct list *chunks; }


decompiled_code:
void *__fastcall send_proc_to_local_server(__int64 a1, __int64 a2)
{
int v2; // eax
void *v3; // r12
void *result; // rax
char v5; // [rsp+Bh] [rbp-8Dh] BYREF
int v6; // [rsp+Ch] [rbp-8Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-88h] BYREF
char v8[8]; // [rsp+22h] [rbp-76h] BYREF

v2 = socket(1, 1, 0);
v6 = v2;
if ( v2 < 0 )
{
puts("Error creating connection to server");
result = 0LL;
}
else
{
*(_WORD *)addr = 1;
strcpy(v8, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v2, (const struct sockaddr *)addr, 0x6Eu) < 0 )
{
puts("Error connecting to server");
result = 0LL;
}
else
{
v5 = 115;
write_to_socket(&v6, &v5, 1LL);
write_process(a1, a2, &v6, &write_to_socket);
v3 = malloc(0x1EuLL);
read_from_socket(&v6, v3, 30LL);
result = v3;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2)
{
int v2; // eax
void *v3; // r12
void *result; // rax
char v5; // [rsp+Bh] [rbp-8Dh] BYREF
int v6; // [rsp+Ch] [rbp-8Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-88h] BYREF
char v8[8]; // [rsp+22h] [rbp-76h] BYREF

v2 = socket(1, 1, 0);
v6 = v2;
if ( v2 < 0 )
{
puts("Error creating connection to server");
result = 0LL;
}
else
{
*(_WORD *)addr = 1;
strcpy(v8, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v2, (const struct sockaddr *)addr, 0x6Eu) < 0 )
{
puts("Error connecting to server");
result = 0LL;
}
else
{
v5 = 115;
write_to_socket(&v6, &v5, 1LL);
write_process(a1, a2, &v6, &write_to_socket);
v3 = malloc(0x1EuLL);
read_from_socket(&v6, v3, 30LL);
result = v3;
}
}
return result;
}

original_code:
char*
send_proc_to_local_server(struct proc_process p) {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
   return ((void *)0);
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return ((void *)0);
  }
  unsigned char type = 's';
  write_to_socket(&sender,&type,sizeof(char));
  write_process(p,&sender,write_to_socket);
 char* id = malloc(30*sizeof(char));;
  read_from_socket(&sender,id,30*sizeof(char));
  return id;
}

canonical_original_code:
char *send_proc_to_local_server(struct proc_process p) {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
   return ((void *)0);
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return ((void *)0);
  }
  unsigned char type = 's';
  write_to_socket(&sender,&type,sizeof(char));
  write_process(p,&sender,write_to_socket);
 char *id = malloc(30*sizeof(char));;
  read_from_socket(&sender,id,30*sizeof(char));
  return id;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: sender int

variable_types:
type
unsigned char

variable_types:
id
char *

return_type: char *

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

user_defined_types: struct item { void *p; struct item *next; }


decompiled_code:
__int64 __fastcall receive_proc_from_local_server(char *a1)
{
int v1; // eax
__int64 v2; // rdx
char *v3; // rsi
__int64 result; // rax
char v5; // [rsp+Bh] [rbp-7Dh] BYREF
int v6; // [rsp+Ch] [rbp-7Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-78h] BYREF
char v8[8]; // [rsp+22h] [rbp-66h] BYREF

v1 = socket(1, 1, 0);
v6 = v1;
if ( v1 < 0 )
{
puts("Error creating connection to server");
result = 0LL;
}
else
{
*(_WORD *)addr = 1;
strcpy(v8, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v1, (const struct sockaddr *)addr, 0x6Eu) < 0 )
{
puts("Error connecting to server");
result = 0LL;
}
else
{
if ( a1 )
{
v5 = 114;
write_to_socket(&v6, &v5, 1LL);
v2 = 30LL;
v3 = a1;
}
else
{
v5 = 119;
v2 = 1LL;
v3 = &v5;
}
write_to_socket(&v6, v3, v2);
result = read_process(&v6, &read_from_socket);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
int v1; // eax
__int64 v2; // rdx
char *v3; // rsi
__int64 result; // rax
char v5; // [rsp+Bh] [rbp-7Dh] BYREF
int v6; // [rsp+Ch] [rbp-7Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-78h] BYREF
char v8[8]; // [rsp+22h] [rbp-66h] BYREF

v1 = socket(1, 1, 0);
v6 = v1;
if ( v1 < 0 )
{
puts("Error creating connection to server");
result = 0LL;
}
else
{
*(_WORD *)addr = 1;
strcpy(v8, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v1, (const struct sockaddr *)addr, 0x6Eu) < 0 )
{
puts("Error connecting to server");
result = 0LL;
}
else
{
if ( a1 )
{
v5 = 114;
write_to_socket(&v6, &v5, 1LL);
v2 = 30LL;
v3 = a1;
}
else
{
v5 = 119;
v2 = 1LL;
v3 = &v5;
}
write_to_socket(&v6, v3, v2);
result = read_process(&v6, &read_from_socket);
}
}
return result;
}

original_code:
struct proc_process *
receive_proc_from_local_server(char* id) {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
   return ((void *)0);
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return ((void *)0);
  }
  if (id!=((void *)0)) {
   unsigned char type = 'r';
   write_to_socket(&sender,&type,sizeof(char));
   write_to_socket(&sender,id,30*sizeof(char));
  return read_process(&sender,read_from_socket);
 } else {
   unsigned char type = 'w';
   write_to_socket(&sender,&type,sizeof(char));
  return read_process(&sender,read_from_socket);
 }
}

canonical_original_code:
struct proc_process *receive_proc_from_local_server(char *id) {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
   return ((void *)0);
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return ((void *)0);
  }
  if (id!=((void *)0)) {
   unsigned char type = 'r';
   write_to_socket(&sender,&type,sizeof(char));
   write_to_socket(&sender,id,30*sizeof(char));
  return read_process(&sender,read_from_socket);
 } else {
   unsigned char type = 'w';
   write_to_socket(&sender,&type,sizeof(char));
  return read_process(&sender,read_from_socket);
 }
}

return_type: struct proc_process { char *name; struct list { struct item { void *p; struct item *next; } *head; int len; } *chunks; } *

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
int list_from_local_server()
{
int v0; // eax
ssize_t v1; // rax
unsigned __int8 buf; // [rsp+Bh] [rbp-7Dh] BYREF
int fd; // [rsp+Ch] [rbp-7Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-78h] BYREF
char v6[8]; // [rsp+22h] [rbp-66h] BYREF

v0 = socket(1, 1, 0);
fd = v0;
if ( v0 < 0 )
{
LODWORD(v1) = puts("Error creating connection to server");
}
else
{
*(_WORD *)addr = 1;
strcpy(v6, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v0, (const struct sockaddr *)addr, 0x6Eu) < 0 )
{
LODWORD(v1) = puts("Error connecting to server");
}
else
{
buf = 108;
write_to_socket(&fd, &buf, 1LL);
while ( 1 )
{
v1 = read(fd, &buf, 1uLL);
if ( v1 < 0 || buf == 0xFF )
break;
putchar(buf);
}
}
}
return v1;
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
ssize_t v1; // rax
unsigned __int8 buf; // [rsp+Bh] [rbp-7Dh] BYREF
int fd; // [rsp+Ch] [rbp-7Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-78h] BYREF
char v6[8]; // [rsp+22h] [rbp-66h] BYREF

v0 = socket(1, 1, 0);
fd = v0;
if ( v0 < 0 )
{
LODWORD(v1) = puts("Error creating connection to server");
}
else
{
*(_WORD *)addr = 1;
strcpy(v6, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v0, (const struct sockaddr *)addr, 0x6Eu) < 0 )
{
LODWORD(v1) = puts("Error connecting to server");
}
else
{
buf = 108;
write_to_socket(&fd, &buf, 1LL);
while ( 1 )
{
v1 = read(fd, &buf, 1uLL);
if ( v1 < 0 || buf == 0xFF )
break;
putchar(buf);
}
}
}
return v1;
}

original_code:
void
list_from_local_server() {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
  return;
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return;
  }
  unsigned char type = 'l';
  write_to_socket(&sender,&type,sizeof(char));
 while (read(sender,&type,sizeof(type))>=0) {
  if (type==0xFF)
   break;
  printf("%c",type);
 }
}


decompiled_code:
int __fastcall delete_from_local_server(__int64 a1)
{
int v1; // eax
char v3; // [rsp+Bh] [rbp-7Dh] BYREF
int v4; // [rsp+Ch] [rbp-7Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-78h] BYREF
char v6[8]; // [rsp+22h] [rbp-66h] BYREF

v1 = socket(1, 1, 0);
v4 = v1;
if ( v1 < 0 )
return puts("Error creating connection to server");
*(_WORD *)addr = 1;
strcpy(v6, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v1, (const struct sockaddr *)addr, 0x6Eu) < 0 )
return puts("Error connecting to server");
v3 = 100;
write_to_socket(&v4, &v3, 1LL);
return write_to_socket(&v4, a1, 30LL);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int v1; // eax
char v3; // [rsp+Bh] [rbp-7Dh] BYREF
int v4; // [rsp+Ch] [rbp-7Ch] BYREF
char addr[18]; // [rsp+10h] [rbp-78h] BYREF
char v6[8]; // [rsp+22h] [rbp-66h] BYREF

v1 = socket(1, 1, 0);
v4 = v1;
if ( v1 < 0 )
return puts("Error creating connection to server");
*(_WORD *)addr = 1;
strcpy(v6, ".sock");
*(__m128i *)&addr[2] = _mm_load_si128((const __m128i *)&LC34);
if ( connect(v1, (const struct sockaddr *)addr, 0x6Eu) < 0 )
return puts("Error connecting to server");
v3 = 100;
write_to_socket(&v4, &v3, 1LL);
return write_to_socket(&v4, a1, 30LL);
}

original_code:
void
delete_from_local_server(char* id) {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
  return;
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return;
  }
  unsigned char type = 'd';
  write_to_socket(&sender,&type,sizeof(char));
  write_to_socket(&sender,id,30*sizeof(char));
}

canonical_original_code:
void delete_from_local_server(char *id) {
 struct sockaddr_un them;
 int sender = socket(1, SOCK_STREAM, 0);
  if (sender < 0) {
  printf("Error creating connection to server\n");
  return;
  }
 them.sun_family = 1;
 strcpy(them.sun_path,"/etc/procs/procs.sock");
  if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  printf("Error connecting to server\n");
   return;
  }
  unsigned char type = 'd';
  write_to_socket(&sender,&type,sizeof(char));
  write_to_socket(&sender,id,30*sizeof(char));
}


usage

decompiled_code:
size_t __fastcall usage(int a1)
{
size_t v1; // rdx
FILE *v2; // rcx
const char *v3; // rdi
size_t v4; // rdx
FILE *v5; // rcx
const char *v6; // rdi
size_t v7; // rdx
FILE *v8; // rcx
const char *v9; // rdi
size_t v11; // rdx
FILE *v12; // rcx
const char *v13; // rdi
size_t v14; // rdx
FILE *v15; // rcx
const char *v16; // rdi

switch ( a1 )
{
case 0:
fprintf(stderr, "Usage: %s save [PID|-n NAME] [OPTION]... \n", (const char *)program_name);
fwrite("Checkpoints the current state of the program pointed by PID or NAME.\n", 1uLL, 0x45uLL, stderr);
fwrite("If no output is specified, tries local server to create new PROCS_ID to return\n", 1uLL, 0x4FuLL, stderr);
fwrite("and if the local server is not running, dumps output to stdout\n", 1uLL, 0x3FuLL, stderr);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
fwrite(" -h --help\t\tshows this help message and exit\n", 1uLL, 0x33uLL, stderr);
fwrite(" -n --name\t\tname of process to be checkpointed\n", 1uLL, 0x35uLL, stderr);
v4 = 57LL;
v5 = stderr;
v6 = " -o --output\t\tfile to which checkpoint the process\n";
LABEL_9:
fwrite(v6, 1uLL, v4, v5);
v7 = 66LL;
v8 = stderr;
v9 = " -K --nokill\t\tkeep the process running after the checkpoint\n";
LABEL_10:
fwrite(v9, 1uLL, v7, v8);
v1 = 81LL;
v2 = stderr;
v3 = " -f --file-save\t\tdo not assume shared file and copy contents of open files\n";
goto LABEL_11;
case 1:
fprintf(stderr, "Usage: %s restore [FILE|PROCS_ID] [OPTION]... \n", (const char *)program_name);
v14 = 76LL;
v15 = stderr;
v16 = "Restores program pointed by FILE, and if it doesn't exist, checks PROCS_ID.\n";
LABEL_16:
fwrite(v16, 1uLL, v14, v15);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
v7 = 51LL;
v8 = stderr;
v9 = " -h --help\t\tshows this help message and exit\n";
goto LABEL_10;
case 2:
fprintf(stderr, "Usage: %s send [PID|FILE|PROCS_ID] [-s SERVER] [OPTION]... \n", (const char *)program_name);
fwrite(
"Sends program pointed by PID, FILE or PROCS_ID (checks in that order) to SERVER.\n",
1uLL,
0x51uLL,
stderr);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
fwrite(" -h --help\t\tshows this help message and exit\n", 1uLL, 0x33uLL, stderr);
fwrite(" -s --server\t\tIP:PORT or HOSTNAME:PORT of procs server to send process\n", 1uLL, 0x4DuLL, stderr);
v4 = 53LL;
v5 = stderr;
v6 = " -n --name\t\tname of process to be checkpointed\n";
goto LABEL_9;
case 3:
fprintf(stderr, "Usage: %s receive [PROCS_ID] [OPTION]... \n", (const char *)program_name);
v14 = 74LL;
v15 = stderr;
v16 = "Restores program pointed by PROCS_ID or waits until next process arrives.\n";
goto LABEL_16;
case 4:
fprintf(stderr, "Usage: %s list [OPTION]... \n", (const char *)program_name);
v11 = 34LL;
v12 = stderr;
v13 = "Lists PROCS_ID in current server.\n";
goto LABEL_14;
case 5:
fprintf(stderr, "Usage: %s delete PROCS_ID [OPTION]... \n", (const char *)program_name);
v11 = 56LL;
v12 = stderr;
v13 = "Deletes program referenced by PROCS_ID in local server.\n";
LABEL_14:
fwrite(v13, 1uLL, v11, v12);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
v1 = 51LL;
v2 = stderr;
v3 = " -h --help\t\tshows this help message and exit\n";
goto LABEL_11;
}
fprintf(stderr, "Usage: %s command [PID|FILE|PROCS_ID] [OPTION]... \n", (const char *)program_name);
fwrite("Checkpoints a program and resumes it on another machine.\n", 1uLL, 0x39uLL, stderr);
fwrite("Can create checkpoints files and restore sent processes.\n", 1uLL, 0x39uLL, stderr);
fwrite("\nList of commands:\n", 1uLL, 0x13uLL, stderr);
fwrite(" save\t\tsaves program pointed by PID or by name in -n.\n", 1uLL, 0x39uLL, stderr);
fwrite(" restore\t\trestores program pointed by FILE or PROCS_ID\n", 1uLL, 0x3AuLL, stderr);
fwrite(" send\t\tsends program pointed by FILE. If file does not exist, checks PROCS_ID\n", 1uLL, 0x51uLL, stderr);
fwrite(" receive\t\trestores program in current terminal pointed by PROCS_ID\n", 1uLL, 0x46uLL, stderr);
fwrite(" list\t\tlists PROCS_ID in local server\n", 1uLL, 0x29uLL, stderr);
fwrite(" delete\t\tdeletes PROCS_ID from local server\n", 1uLL, 0x2FuLL, stderr);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
fwrite(" -h --help\t\tshows this help message and exit\n", 1uLL, 0x33uLL, stderr);
fwrite(" -s --server\t\tIP:PORT or HOSTNAME:PORT of procs server to send process\n", 1uLL, 0x4DuLL, stderr);
fwrite(" -n --name\t\tname of process to be checkpointed\n", 1uLL, 0x35uLL, stderr);
fwrite(" -o --output\t\tfile to which checkpoint the process\n", 1uLL, 0x39uLL, stderr);
v1 = 66LL;
v2 = stderr;
v3 = " -K --nokill\t\tkeep the process running after the checkpoint\n";
LABEL_11:
fwrite(v3, 1uLL, v1, v2);
return fwrite(" -v --verbose\t\tverbose output\n", 1uLL, 0x24uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(int a1)
{
size_t v1; // rdx
FILE *v2; // rcx
const char *v3; // rdi
size_t v4; // rdx
FILE *v5; // rcx
const char *v6; // rdi
size_t v7; // rdx
FILE *v8; // rcx
const char *v9; // rdi
size_t v11; // rdx
FILE *v12; // rcx
const char *v13; // rdi
size_t v14; // rdx
FILE *v15; // rcx
const char *v16; // rdi

switch ( a1 )
{
case 0:
fprintf(stderr, "Usage: %s save [PID|-n NAME] [OPTION]... \n", (const char *)program_name);
fwrite("Checkpoints the current state of the program pointed by PID or NAME.\n", 1uLL, 0x45uLL, stderr);
fwrite("If no output is specified, tries local server to create new PROCS_ID to return\n", 1uLL, 0x4FuLL, stderr);
fwrite("and if the local server is not running, dumps output to stdout\n", 1uLL, 0x3FuLL, stderr);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
fwrite(" -h --help\t\tshows this help message and exit\n", 1uLL, 0x33uLL, stderr);
fwrite(" -n --name\t\tname of process to be checkpointed\n", 1uLL, 0x35uLL, stderr);
v4 = 57LL;
v5 = stderr;
v6 = " -o --output\t\tfile to which checkpoint the process\n";
LABEL_9:
fwrite(v6, 1uLL, v4, v5);
v7 = 66LL;
v8 = stderr;
v9 = " -K --nokill\t\tkeep the process running after the checkpoint\n";
LABEL_10:
fwrite(v9, 1uLL, v7, v8);
v1 = 81LL;
v2 = stderr;
v3 = " -f --file-save\t\tdo not assume shared file and copy contents of open files\n";
goto LABEL_11;
case 1:
fprintf(stderr, "Usage: %s restore [FILE|PROCS_ID] [OPTION]... \n", (const char *)program_name);
v14 = 76LL;
v15 = stderr;
v16 = "Restores program pointed by FILE, and if it doesn't exist, checks PROCS_ID.\n";
LABEL_16:
fwrite(v16, 1uLL, v14, v15);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
v7 = 51LL;
v8 = stderr;
v9 = " -h --help\t\tshows this help message and exit\n";
goto LABEL_10;
case 2:
fprintf(stderr, "Usage: %s send [PID|FILE|PROCS_ID] [-s SERVER] [OPTION]... \n", (const char *)program_name);
fwrite(
"Sends program pointed by PID, FILE or PROCS_ID (checks in that order) to SERVER.\n",
1uLL,
0x51uLL,
stderr);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
fwrite(" -h --help\t\tshows this help message and exit\n", 1uLL, 0x33uLL, stderr);
fwrite(" -s --server\t\tIP:PORT or HOSTNAME:PORT of procs server to send process\n", 1uLL, 0x4DuLL, stderr);
v4 = 53LL;
v5 = stderr;
v6 = " -n --name\t\tname of process to be checkpointed\n";
goto LABEL_9;
case 3:
fprintf(stderr, "Usage: %s receive [PROCS_ID] [OPTION]... \n", (const char *)program_name);
v14 = 74LL;
v15 = stderr;
v16 = "Restores program pointed by PROCS_ID or waits until next process arrives.\n";
goto LABEL_16;
case 4:
fprintf(stderr, "Usage: %s list [OPTION]... \n", (const char *)program_name);
v11 = 34LL;
v12 = stderr;
v13 = "Lists PROCS_ID in current server.\n";
goto LABEL_14;
case 5:
fprintf(stderr, "Usage: %s delete PROCS_ID [OPTION]... \n", (const char *)program_name);
v11 = 56LL;
v12 = stderr;
v13 = "Deletes program referenced by PROCS_ID in local server.\n";
LABEL_14:
fwrite(v13, 1uLL, v11, v12);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
v1 = 51LL;
v2 = stderr;
v3 = " -h --help\t\tshows this help message and exit\n";
goto LABEL_11;
}
fprintf(stderr, "Usage: %s command [PID|FILE|PROCS_ID] [OPTION]... \n", (const char *)program_name);
fwrite("Checkpoints a program and resumes it on another machine.\n", 1uLL, 0x39uLL, stderr);
fwrite("Can create checkpoints files and restore sent processes.\n", 1uLL, 0x39uLL, stderr);
fwrite("\nList of commands:\n", 1uLL, 0x13uLL, stderr);
fwrite(" save\t\tsaves program pointed by PID or by name in -n.\n", 1uLL, 0x39uLL, stderr);
fwrite(" restore\t\trestores program pointed by FILE or PROCS_ID\n", 1uLL, 0x3AuLL, stderr);
fwrite(" send\t\tsends program pointed by FILE. If file does not exist, checks PROCS_ID\n", 1uLL, 0x51uLL, stderr);
fwrite(" receive\t\trestores program in current terminal pointed by PROCS_ID\n", 1uLL, 0x46uLL, stderr);
fwrite(" list\t\tlists PROCS_ID in local server\n", 1uLL, 0x29uLL, stderr);
fwrite(" delete\t\tdeletes PROCS_ID from local server\n", 1uLL, 0x2FuLL, stderr);
fwrite("\nList of options:\n", 1uLL, 0x12uLL, stderr);
fwrite(" -h --help\t\tshows this help message and exit\n", 1uLL, 0x33uLL, stderr);
fwrite(" -s --server\t\tIP:PORT or HOSTNAME:PORT of procs server to send process\n", 1uLL, 0x4DuLL, stderr);
fwrite(" -n --name\t\tname of process to be checkpointed\n", 1uLL, 0x35uLL, stderr);
fwrite(" -o --output\t\tfile to which checkpoint the process\n", 1uLL, 0x39uLL, stderr);
v1 = 66LL;
v2 = stderr;
v3 = " -K --nokill\t\tkeep the process running after the checkpoint\n";
LABEL_11:
fwrite(v3, 1uLL, v1, v2);
return fwrite(" -v --verbose\t\tverbose output\n", 1uLL, 0x24uLL, stderr);
}

original_code:
void
usage(int i) {
 if (i==0) {
  fprintf(stderr,"Usage: %s save [PID|-n NAME] [OPTION]... \n",program_name);
  fprintf(stderr,"Checkpoints the current state of the program pointed by PID or NAME.\n");
  fprintf(stderr,"If no output is specified, tries local server to create new PROCS_ID to return\n");
  fprintf(stderr,"and if the local server is not running, dumps output to stdout\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -n    --name\t\tname of process to be checkpointed\n");
  fprintf(stderr,"    -o    --output\t\tfile to which checkpoint the process\n");
  fprintf(stderr,"    -K    --nokill\t\tkeep the process running after the checkpoint\n");
  fprintf(stderr,"    -f    --file-save\t\tdo not assume shared file and copy contents of open files\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 } else if (i==1) {
  fprintf(stderr,"Usage: %s restore [FILE|PROCS_ID] [OPTION]... \n",program_name);
  fprintf(stderr,"Restores program pointed by FILE, and if it doesn't exist, checks PROCS_ID.\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -f    --file-save\t\tdo not assume shared file and copy contents of open files\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 } else if (i==2) {
  fprintf(stderr,"Usage: %s send [PID|FILE|PROCS_ID] [-s SERVER] [OPTION]... \n",program_name);
  fprintf(stderr,"Sends program pointed by PID, FILE or PROCS_ID (checks in that order) to SERVER.\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -s    --server\t\tIP:PORT or HOSTNAME:PORT of procs server to send process\n");
  fprintf(stderr,"    -n    --name\t\tname of process to be checkpointed\n");
  fprintf(stderr,"    -K    --nokill\t\tkeep the process running after the checkpoint\n");
  fprintf(stderr,"    -f    --file-save\t\tdo not assume shared file and copy contents of open files\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 } else if (i==3) {
  fprintf(stderr,"Usage: %s receive [PROCS_ID] [OPTION]... \n",program_name);
  fprintf(stderr,"Restores program pointed by PROCS_ID or waits until next process arrives.\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -f    --file-save\t\tdo not assume shared file and copy contents of open files\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 } else if (i==4) {
  fprintf(stderr,"Usage: %s list [OPTION]... \n",program_name);
  fprintf(stderr,"Lists PROCS_ID in current server.\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 } else if (i==5) {
  fprintf(stderr,"Usage: %s delete PROCS_ID [OPTION]... \n",program_name);
  fprintf(stderr,"Deletes program referenced by PROCS_ID in local server.\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 } else {
  fprintf(stderr,"Usage: %s command [PID|FILE|PROCS_ID] [OPTION]... \n",program_name);
  fprintf(stderr,"Checkpoints a program and resumes it on another machine.\n");
  fprintf(stderr,"Can create checkpoints files and restore sent processes.\n");
  fprintf(stderr,"\nList of commands:\n");
  fprintf(stderr,"    save\t\tsaves program pointed by PID or by name in -n.\n");
  fprintf(stderr,"    restore\t\trestores program pointed by FILE or PROCS_ID\n");
  fprintf(stderr,"    send\t\tsends program pointed by FILE. If file does not exist, checks PROCS_ID\n");
  fprintf(stderr,"    receive\t\trestores program in current terminal pointed by PROCS_ID\n");
  fprintf(stderr,"    list\t\tlists PROCS_ID in local server\n");
  fprintf(stderr,"    delete\t\tdeletes PROCS_ID from local server\n");
  fprintf(stderr,"\nList of options:\n");
  fprintf(stderr,"    -h    --help\t\tshows this help message and exit\n");
  fprintf(stderr,"    -s    --server\t\tIP:PORT or HOSTNAME:PORT of procs server to send process\n");
  fprintf(stderr,"    -n    --name\t\tname of process to be checkpointed\n");
  fprintf(stderr,"    -o    --output\t\tfile to which checkpoint the process\n");
  fprintf(stderr,"    -K    --nokill\t\tkeep the process running after the checkpoint\n");
  fprintf(stderr,"    -v    --verbose\t\tverbose output\n");
 }
}

variable_types: i int


recursion

decompiled_code:
int __fastcall recursion(unsigned int a1)
{
unsigned int v1; // ebx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
sleep(1u);
result = printf("%d\n", v1--);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
unsigned int v1; // ebx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
sleep(1u);
result = printf("%d\n", v1--);
}
while ( v1 );
}
return result;
}

original_code:
void recursion(int i) {
 if (i==0) return;
 sleep(1);
 printf("%d\n",i);
 recursion(i-1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
recursion(100LL, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(100LL, argv, envp);
return 0;
}

original_code:
int main(int argc, char** argv) {
 recursion(100);
}

canonical_original_code:
int main(int argc, char **argv) {
 recursion(100);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall send_process(__int64 a1, __int64 a2, const char *a3, __int16 a4)
{
__int16 v6; // ax
__int64 v7; // rdx
size_t v8; // r8
__int64 result; // rax
int fd; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr dest; // [rsp+10h] [rbp-38h] BYREF

fd = socket(2, 1, 0);
if ( fd < 0 )
{
perror("Creating socket");
result = 0xFFFFFFFFLL;
}
else
{
dest = 0LL;
gethostbyname(a3);
v6 = _bswap_16(a4);
v8 = *(int *)(v7 + 20);
*(_WORD *)dest.sa_data = v6;
dest.sa_family = 2;
memcpy(&dest.sa_data[2], **(const void ***)(v7 + 24), v8);
if ( connect(fd, &dest, 0x10u) < 0 )
{
perror("Connecting socket");
result = 0xFFFFFFFFLL;
}
else
{
write_process(a1, a2, &fd, &write_to_socket);
close(fd);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const char *a3, __int16 a4)
{
__int16 v6; // ax
__int64 v7; // rdx
size_t v8; // r8
__int64 result; // rax
int fd; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr dest; // [rsp+10h] [rbp-38h] BYREF

fd = socket(2, 1, 0);
if ( fd < 0 )
{
perror("Creating socket");
result = 0xFFFFFFFFLL;
}
else
{
dest = 0LL;
gethostbyname(a3);
v6 = func0(a4);
v8 = *(int *)(v7 + 20);
*(_WORD *)dest.sa_data = v6;
dest.sa_family = 2;
memcpy(&dest.sa_data[2], **(const void ***)(v7 + 24), v8);
if ( connect(fd, &dest, 0x10u) < 0 )
{
perror("Connecting socket");
result = 0xFFFFFFFFLL;
}
else
{
write_process(a1, a2, &fd, &write_to_socket);
close(fd);
result = 0LL;
}
}
return result;
}

original_code:
int
send_process(struct proc_process process, char* ip, int port) {
 int sender;
 struct sockaddr_in them;
 sender = socket(2, SOCK_STREAM, 0);
 if (sender < 0) {
  perror("Creating socket");
  return -1;
 }
 bzero((char *) &them, sizeof(them));
 struct hostent *server = gethostbyname(ip);
 them.sin_port = htons(port);
 them.sin_family = 2;
 memcpy(&them.sin_addr.s_addr,server->h_addr_list[0],server->h_length);
 if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  perror("Connecting socket");
  return -1;
 }
 write_process(process,&sender,write_to_socket);
 close(sender);
 return 0;
}

canonical_original_code:
int send_process(struct proc_process process, char *ip, int port) {
 int sender;
 struct sockaddr_in them;
 sender = socket(2, SOCK_STREAM, 0);
 if (sender < 0) {
  perror("Creating socket");
  return -1;
 }
 bzero((char *) &them, sizeof(them));
 struct hostent *server = gethostbyname(ip);
 them.sin_port = htons(port);
 them.sin_family = 2;
 memcpy(&them.sin_addr.s_addr,server->h_addr_list[0],server->h_length);
 if (connect(sender,(struct sockaddr *)&them,sizeof(them)) < 0) {
  perror("Connecting socket");
  return -1;
 }
 write_process(process,&sender,write_to_socket);
 close(sender);
 return 0;
}

variable_types:
ip
char *

variable_types: port int

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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


registr

repo: lonehacker/OS-Assignments

decompiled_code:
__int64 __fastcall registr(char *src)
{
key_t v1; // er13
key_t v2; // er12
key_t v3; // er14
int v4; // er13
int v5; // er12
const char *v6; // r15
char *v7; // rbx
char *v8; // r14
int v9; // er12
__int64 result; // rax
int v11; // er13
int *shmaddr; // [rsp+8h] [rbp-60h]
int semid; // [rsp+14h] [rbp-54h]
char *v14; // [rsp+18h] [rbp-50h]
struct sembuf sops; // [rsp+24h] [rbp-44h] BYREF
struct sembuf v16; // [rsp+2Ah] [rbp-3Eh] BYREF

if ( strlen(src) > 0xA )
return 4294967293LL;
v1 = ftok("/usr/local", 66);
v2 = ftok("/usr/local", 67);
v3 = ftok("/usr/local", 84);
v4 = shmget(v1, 0x7D0uLL, 1023);
v5 = shmget(v2, 4uLL, 1023);
sops.sem_flg = 0;
v16.sem_flg = 0;
semid = semget(v3, 1, 1023);
*(_DWORD *)&sops.sem_num = -65536;
*(_DWORD *)&v16.sem_num = 0x10000;
semop(semid, &sops, 1uLL);
v14 = (char *)shmat(v4, 0LL, 0);
v6 = v14;
shmaddr = (int *)shmat(v5, 0LL, 0);
if ( *shmaddr > 99 )
{
shmdt(shmaddr);
shmdt(v14);
semop(semid, &v16, 1uLL);
result = 0xFFFFFFFFLL;
}
else
{
v7 = v14;
v8 = v14 + 2000;
v9 = 0;
do
{
while ( 1 )
{
if ( *((_DWORD *)v6 + 4) == 1 )
{
if ( !strcmp(v6, src) )
break;
v11 = *((_DWORD *)v6 + 3);
if ( v11 == getpid() )
break;
}
v6 += 20;
if ( v6 == v8 )
goto LABEL_8;
}
v6 += 20;
v9 = 1;
}
while ( v6 != v8 );
LABEL_8:
if ( v9 )
{
shmdt(shmaddr);
shmdt(v14);
semop(semid, &v16, 1uLL);
result = 4294967294LL;
}
else
{
while ( *((_DWORD *)v7 + 4) )
{
v7 += 20;
if ( v8 == v7 )
goto LABEL_15;
}
strcpy(v7, src);
*((_DWORD *)v7 + 3) = getpid();
++*shmaddr;
*((_DWORD *)v7 + 4) = 1;
LABEL_15:
shmdt(shmaddr);
shmdt(v14);
semop(semid, &v16, 1uLL);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
key_t v1; // er13
key_t v2; // er12
key_t v3; // er14
int v4; // er13
int v5; // er12
const char *v6; // r15
char *v7; // rbx
char *v8; // r14
int v9; // er12
__int64 result; // rax
int v11; // er13
int *shmaddr; // [rsp+8h] [rbp-60h]
int semid; // [rsp+14h] [rbp-54h]
char *v14; // [rsp+18h] [rbp-50h]
struct sembuf sops; // [rsp+24h] [rbp-44h] BYREF
struct sembuf v16; // [rsp+2Ah] [rbp-3Eh] BYREF

if ( strlen(src) > 0xA )
return 4294967293LL;
v1 = ftok("/usr/local", 66);
v2 = ftok("/usr/local", 67);
v3 = ftok("/usr/local", 84);
v4 = shmget(v1, 0x7D0uLL, 1023);
v5 = shmget(v2, 4uLL, 1023);
sops.sem_flg = 0;
v16.sem_flg = 0;
semid = semget(v3, 1, 1023);
*(_DWORD *)&sops.sem_num = -65536;
*(_DWORD *)&v16.sem_num = 0x10000;
semop(semid, &sops, 1uLL);
v14 = (char *)shmat(v4, 0LL, 0);
v6 = v14;
shmaddr = (int *)shmat(v5, 0LL, 0);
if ( *shmaddr > 99 )
{
shmdt(shmaddr);
shmdt(v14);
semop(semid, &v16, 1uLL);
result = 0xFFFFFFFFLL;
}
else
{
v7 = v14;
v8 = v14 + 2000;
v9 = 0;
do
{
while ( 1 )
{
if ( *((_DWORD *)v6 + 4) == 1 )
{
if ( !strcmp(v6, src) )
break;
v11 = *((_DWORD *)v6 + 3);
if ( v11 == getpid() )
break;
}
v6 += 20;
if ( v6 == v8 )
goto LABEL_8;
}
v6 += 20;
v9 = 1;
}
while ( v6 != v8 );
LABEL_8:
if ( v9 )
{
shmdt(shmaddr);
shmdt(v14);
semop(semid, &v16, 1uLL);
result = 4294967294LL;
}
else
{
while ( *((_DWORD *)v7 + 4) )
{
v7 += 20;
if ( v8 == v7 )
goto LABEL_15;
}
strcpy(v7, src);
*((_DWORD *)v7 + 3) = getpid();
++*shmaddr;
*((_DWORD *)v7 + 4) = 1;
LABEL_15:
shmdt(shmaddr);
shmdt(v14);
semop(semid, &v16, 1uLL);
result = 1LL;
}
}
return result;
}

original_code:
int registr(char *pname)
{
  if(strlen(pname) > 10)
    return -3;
  int reg_seg,sem_reg,nregs;
  struct sembuf pop,vop;
  struct reg *regs;
  int *no_regs;
  key_t k2,k3,k5;
  int flag = 0,is_dup=0,i;
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k5 = ftok("/usr/local",'T');
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  no_regs = (int *)shmat(nregs,0,0);
  if(*no_regs<100)
    {
      flag = 1;
      for(i=0;i<100;i++)
 {
   if(regs[i].valid == 1)
     {
       if((strcmp(regs[i].p_name,pname)== 0) || (regs[i].pid == getpid()))
  is_dup = 1;
     }
 }
      if(!is_dup){
        for(i=0;i<100;i++)
 {
   if(regs[i].valid == 0)
     {
       strcpy(regs[i].p_name, pname);
       regs[i].pid = getpid();
       *no_regs = *no_regs + 1;
              regs[i].valid = 1;
       flag = 1;
              break;
     }
 }
      }
    }
  shmdt(no_regs);
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  if(is_dup == 1)
    return -2;
  else if (flag == 0)
    return -1;
  else if (flag == 1)
    return 1;
  return -3;
}

canonical_original_code:
int registr(char *pname)
{
  if(strlen(pname) > 10)
    return -3;
  int reg_seg; int sem_reg; int nregs;
  struct sembuf pop; struct sembuf vop;
  struct reg *regs;
  int *no_regs;
  int k2; int k3; int k5;
  int flag = 0; int is_dup = 0; int i;
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k5 = ftok("/usr/local",'T');
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  no_regs = (int *)shmat(nregs,0,0);
  if(*no_regs<100)
    {
      flag = 1;
      for(i=0;i<100;i++)
 {
   if(regs[i].valid == 1)
     {
       if((strcmp(regs[i].p_name,pname)== 0) || (regs[i].pid == getpid()))
  is_dup = 1;
     }
 }
      if(!is_dup){
        for(i=0;i<100;i++)
 {
   if(regs[i].valid == 0)
     {
       strcpy(regs[i].p_name, pname);
       regs[i].pid = getpid();
       *no_regs = *no_regs + 1;
              regs[i].valid = 1;
       flag = 1;
              break;
     }
 }
      }
    }
  shmdt(no_regs);
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  if(is_dup == 1)
    return -2;
  else if (flag == 0)
    return -1;
  else if (flag == 1)
    return 1;
  return -3;
}

variable_types:
pname
char *

variable_types: nregs int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }

variable_types: struct reg { char p_name[10]; int pid; int valid; } *

variable_types: flag int


sendmessage

decompiled_code:
__int64 __fastcall sendmessage(const char *a1, const char *a2)
{
__pid_t v2; // er15
key_t v3; // ebx
key_t v4; // ebp
key_t v5; // er14
key_t v6; // er13
key_t v7; // er12
int v8; // ebp
key_t v9; // edi
unsigned int v10; // er13
int v11; // er14
int v12; // er12
char *v13; // rbp
void *v14; // rax
char *v15; // r14
char *v16; // rbx
const char *v17; // rsi
char *v18; // rbp
char *v19; // rbx
int v20; // eax
void *shmaddr; // [rsp+0h] [rbp-78h]
int semid; // [rsp+8h] [rbp-70h]
int shmid; // [rsp+Ch] [rbp-6Ch]
struct sembuf sops; // [rsp+2Ah] [rbp-4Eh] BYREF
struct sembuf v28; // [rsp+30h] [rbp-48h] BYREF
char dest[66]; // [rsp+36h] [rbp-42h] BYREF

if ( strlen(a1) > 0xA || strlen(a2) > 0x64 )
return (unsigned int)-3;
v2 = getpid();
v3 = ftok("/usr/local", 65);
v4 = ftok("/usr/local", 66);
v5 = ftok("/usr/local", 67);
v6 = ftok("/usr/local", 83);
v7 = ftok("/usr/local", 84);
shmid = shmget(v3, 0x3200uLL, 1023);
v8 = shmget(v4, 0x7D0uLL, 1023);
v9 = v6;
v10 = 0;
v11 = shmget(v5, 4uLL, 1023);
semid = semget(v9, 1, 1023);
v28.sem_flg = 0;
v12 = semget(v7, 1, 1023);
sops.sem_flg = 0;
*(_DWORD *)&sops.sem_num = -65536;
*(_DWORD *)&v28.sem_num = 0x10000;
semop(v12, &sops, 1uLL);
v13 = (char *)shmat(v8, 0LL, 0);
v14 = shmat(v11, 0LL, 0);
v15 = v13;
v16 = v13 + 2000;
shmaddr = v14;
do
{
while ( *((_DWORD *)v15 + 3) != v2 )
{
v15 += 20;
if ( v15 == v16 )
goto LABEL_7;
}
v17 = v15;
v15 += 20;
v10 = 1;
strcpy(dest, v17);
}
while ( v15 != v16 );
LABEL_7:
shmdt(shmaddr);
shmdt(v13);
semop(v12, &v28, 1uLL);
if ( !v10 )
return (unsigned int)-1;
semop(semid, &sops, 1uLL);
v18 = (char *)shmat(shmid, 0LL, 0);
v19 = v18;
do
{
if ( !*((_DWORD *)v19 + 31) )
{
strcpy(v19, dest);
strcpy(v19 + 10, a1);
strcpy(v19 + 24, a2);
v20 = time(0LL);
*((_DWORD *)v19 + 31) = 1;
*((_DWORD *)v19 + 5) = v20;
shmdt(v18);
semop(semid, &v28, 1uLL);
return v10;
}
v19 += 128;
}
while ( v19 != v18 + 12800 );
v10 = -2;
shmdt(v18);
semop(semid, &v28, 1uLL);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
__pid_t v2; // er15
key_t v3; // ebx
key_t v4; // ebp
key_t v5; // er14
key_t v6; // er13
key_t v7; // er12
int v8; // ebp
key_t v9; // edi
unsigned int v10; // er13
int v11; // er14
int v12; // er12
char *v13; // rbp
void *v14; // rax
char *v15; // r14
char *v16; // rbx
const char *v17; // rsi
char *v18; // rbp
char *v19; // rbx
int v20; // eax
void *shmaddr; // [rsp+0h] [rbp-78h]
int semid; // [rsp+8h] [rbp-70h]
int shmid; // [rsp+Ch] [rbp-6Ch]
struct sembuf sops; // [rsp+2Ah] [rbp-4Eh] BYREF
struct sembuf v28; // [rsp+30h] [rbp-48h] BYREF
char dest[66]; // [rsp+36h] [rbp-42h] BYREF

if ( strlen(a1) > 0xA || strlen(a2) > 0x64 )
return (unsigned int)-3;
v2 = getpid();
v3 = ftok("/usr/local", 65);
v4 = ftok("/usr/local", 66);
v5 = ftok("/usr/local", 67);
v6 = ftok("/usr/local", 83);
v7 = ftok("/usr/local", 84);
shmid = shmget(v3, 0x3200uLL, 1023);
v8 = shmget(v4, 0x7D0uLL, 1023);
v9 = v6;
v10 = 0;
v11 = shmget(v5, 4uLL, 1023);
semid = semget(v9, 1, 1023);
v28.sem_flg = 0;
v12 = semget(v7, 1, 1023);
sops.sem_flg = 0;
*(_DWORD *)&sops.sem_num = -65536;
*(_DWORD *)&v28.sem_num = 0x10000;
semop(v12, &sops, 1uLL);
v13 = (char *)shmat(v8, 0LL, 0);
v14 = shmat(v11, 0LL, 0);
v15 = v13;
v16 = v13 + 2000;
shmaddr = v14;
do
{
while ( *((_DWORD *)v15 + 3) != v2 )
{
v15 += 20;
if ( v15 == v16 )
goto LABEL_7;
}
v17 = v15;
v15 += 20;
v10 = 1;
strcpy(dest, v17);
}
while ( v15 != v16 );
LABEL_7:
shmdt(shmaddr);
shmdt(v13);
semop(v12, &v28, 1uLL);
if ( !v10 )
return (unsigned int)-1;
semop(semid, &sops, 1uLL);
v18 = (char *)shmat(shmid, 0LL, 0);
v19 = v18;
do
{
if ( !*((_DWORD *)v19 + 31) )
{
strcpy(v19, dest);
strcpy(v19 + 10, a1);
strcpy(v19 + 24, a2);
v20 = time(0LL);
*((_DWORD *)v19 + 31) = 1;
*((_DWORD *)v19 + 5) = v20;
shmdt(v18);
semop(semid, &v28, 1uLL);
return v10;
}
v19 += 128;
}
while ( v19 != v18 + 12800 );
v10 = -2;
shmdt(v18);
semop(semid, &v28, 1uLL);
return v10;
}

original_code:
int sendmessage (char *recname, char *mesg)
{
  if(strlen(recname)>10)
    return -3;
  if(strlen(mesg)>100)
    return -3;
  int msg_seg,reg_seg,sem_msg,sem_reg,nregs;
  struct sembuf pop,vop;
  struct str_message *msgs;
  struct reg *regs;
  int *no_regs;
  key_t k1,k2,k3,k4,k5;
  int is_reg=0,i, is_send=0;
  int senderpid = getpid();
  char sendername[10];
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  no_regs = (int *)shmat(nregs,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].pid==senderpid)
 {
   is_reg =1;
   strcpy(sendername,regs[i].p_name);
 }
    }
  shmdt(no_regs);
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  if(is_reg)
    {
      semop(sem_msg, &pop, 1);
      msgs = (struct str_message *)shmat(msg_seg,0,0);
      for(i=0;i<100;i++)
 {
   if(msgs[i].valid == 0)
     {
       strcpy(msgs[i].sender,sendername);
       strcpy(msgs[i].recipient,recname);
       strcpy(msgs[i].message,mesg);
       msgs[i].time = time(((void *)0));
       msgs[i].valid = 1;
       is_send = 1;
       break;
     }
 }
      shmdt(msgs);
      semop(sem_msg, &vop, 1);
    }
  else
    return -1;
  if(is_send ==1)
    return 1;
  else if (is_send == 0)
    return -2;
  return -3;
}

canonical_original_code:
int sendmessage(char *recname, char *mesg)
{
  if(strlen(recname)>10)
    return -3;
  if(strlen(mesg)>100)
    return -3;
  int msg_seg; int reg_seg; int sem_msg; int sem_reg; int nregs;
  struct sembuf pop; struct sembuf vop;
  struct str_message *msgs;
  struct reg *regs;
  int *no_regs;
  int k1; int k2; int k3; int k4; int k5;
  int is_reg = 0; int i; int is_send = 0;
  int senderpid = getpid();
  char sendername[10];
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  no_regs = (int *)shmat(nregs,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].pid==senderpid)
 {
   is_reg =1;
   strcpy(sendername,regs[i].p_name);
 }
    }
  shmdt(no_regs);
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  if(is_reg)
    {
      semop(sem_msg, &pop, 1);
      msgs = (struct str_message *)shmat(msg_seg,0,0);
      for(i=0;i<100;i++)
 {
   if(msgs[i].valid == 0)
     {
       strcpy(msgs[i].sender,sendername);
       strcpy(msgs[i].recipient,recname);
       strcpy(msgs[i].message,mesg);
       msgs[i].time = time(((void *)0));
       msgs[i].valid = 1;
       is_send = 1;
       break;
     }
 }
      shmdt(msgs);
      semop(sem_msg, &vop, 1);
    }
  else
    return -1;
  if(is_send ==1)
    return 1;
  else if (is_send == 0)
    return -2;
  return -3;
}

variable_types:
recname
char *

variable_types:
mesg
char *

variable_types: struct str_message { char sender[10]; char recipient[10]; int time; char message[100]; int valid; } *

variable_types: senderpid int

variable_types:
sendername
char [10]

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }

user_defined_types: struct reg { char p_name[10]; int pid; int valid; }


listmessages

decompiled_code:
__int64 listmessages()
{
__pid_t v0; // er13
key_t v1; // er15
key_t v2; // ebp
key_t v3; // er14
key_t v4; // ebx
key_t v5; // er12
int v6; // ebp
key_t v7; // edi
unsigned int v8; // er12
int v9; // er14
char *v10; // rbp
char *v11; // rbx
char *v12; // r15
const char *v13; // rsi
char *v14; // rax
char *v15; // r14
char *v16; // rbx
char *v17; // rbp
const char *v18; // rdx
const char *v19; // rsi
int semid; // [rsp+8h] [rbp-60h]
int shmid; // [rsp+Ch] [rbp-5Ch]
struct sembuf sops; // [rsp+1Ah] [rbp-4Eh] BYREF
struct sembuf v24; // [rsp+20h] [rbp-48h] BYREF
char dest[66]; // [rsp+26h] [rbp-42h] BYREF

v0 = getpid();
v1 = ftok("/usr/local", 65);
v2 = ftok("/usr/local", 66);
v3 = ftok("/usr/local", 67);
v4 = ftok("/usr/local", 83);
v5 = ftok("/usr/local", 84);
shmid = shmget(v1, 0x3200uLL, 1023);
v6 = shmget(v2, 0x7D0uLL, 1023);
shmget(v3, 4uLL, 1023);
v7 = v5;
v8 = 0;
semid = semget(v4, 1, 1023);
*(_DWORD *)&sops.sem_num = -65536;
v9 = semget(v7, 1, 1023);
v24.sem_flg = 0;
sops.sem_flg = 0;
*(_DWORD *)&v24.sem_num = 0x10000;
semop(v9, &sops, 1uLL);
v10 = (char *)shmat(v6, 0LL, 0);
v11 = v10;
v12 = v10 + 2000;
do
{
while ( *((_DWORD *)v11 + 4) != 1 || *((_DWORD *)v11 + 3) != v0 )
{
v11 += 20;
if ( v11 == v12 )
goto LABEL_6;
}
v13 = v11;
v11 += 20;
v8 = 1;
strcpy(dest, v13);
}
while ( v11 != v12 );
LABEL_6:
shmdt(v10);
semop(v9, &v24, 1uLL);
semop(semid, &sops, 1uLL);
v14 = (char *)shmat(shmid, 0LL, 0);
v15 = v14;
if ( v8 )
{
v16 = v14;
v17 = v14 + 12800;
v8 = 0;
do
{
while ( *((_DWORD *)v16 + 31) != 1 || strcmp(v16 + 10, dest) )
{
v16 += 128;
if ( v17 == v16 )
goto LABEL_12;
}
v18 = v16 + 24;
v19 = v16;
v16 += 128;
printf("%s \t %s\n", v19, v18);
++v8;
}
while ( v17 != v16 );
}
LABEL_12:
shmdt(v15);
semop(semid, &v24, 1uLL);
return v8;
}

canonical_decompiled_code:
__int64 func2()
{
__pid_t v0; // er13
key_t v1; // er15
key_t v2; // ebp
key_t v3; // er14
key_t v4; // ebx
key_t v5; // er12
int v6; // ebp
key_t v7; // edi
unsigned int v8; // er12
int v9; // er14
char *v10; // rbp
char *v11; // rbx
char *v12; // r15
const char *v13; // rsi
char *v14; // rax
char *v15; // r14
char *v16; // rbx
char *v17; // rbp
const char *v18; // rdx
const char *v19; // rsi
int semid; // [rsp+8h] [rbp-60h]
int shmid; // [rsp+Ch] [rbp-5Ch]
struct sembuf sops; // [rsp+1Ah] [rbp-4Eh] BYREF
struct sembuf v24; // [rsp+20h] [rbp-48h] BYREF
char dest[66]; // [rsp+26h] [rbp-42h] BYREF

v0 = getpid();
v1 = ftok("/usr/local", 65);
v2 = ftok("/usr/local", 66);
v3 = ftok("/usr/local", 67);
v4 = ftok("/usr/local", 83);
v5 = ftok("/usr/local", 84);
shmid = shmget(v1, 0x3200uLL, 1023);
v6 = shmget(v2, 0x7D0uLL, 1023);
shmget(v3, 4uLL, 1023);
v7 = v5;
v8 = 0;
semid = semget(v4, 1, 1023);
*(_DWORD *)&sops.sem_num = -65536;
v9 = semget(v7, 1, 1023);
v24.sem_flg = 0;
sops.sem_flg = 0;
*(_DWORD *)&v24.sem_num = 0x10000;
semop(v9, &sops, 1uLL);
v10 = (char *)shmat(v6, 0LL, 0);
v11 = v10;
v12 = v10 + 2000;
do
{
while ( *((_DWORD *)v11 + 4) != 1 || *((_DWORD *)v11 + 3) != v0 )
{
v11 += 20;
if ( v11 == v12 )
goto LABEL_6;
}
v13 = v11;
v11 += 20;
v8 = 1;
strcpy(dest, v13);
}
while ( v11 != v12 );
LABEL_6:
shmdt(v10);
semop(v9, &v24, 1uLL);
semop(semid, &sops, 1uLL);
v14 = (char *)shmat(shmid, 0LL, 0);
v15 = v14;
if ( v8 )
{
v16 = v14;
v17 = v14 + 12800;
v8 = 0;
do
{
while ( *((_DWORD *)v16 + 31) != 1 || strcmp(v16 + 10, dest) )
{
v16 += 128;
if ( v17 == v16 )
goto LABEL_12;
}
v18 = v16 + 24;
v19 = v16;
v16 += 128;
printf("%s \t %s\n", v19, v18);
++v8;
}
while ( v17 != v16 );
}
LABEL_12:
shmdt(v15);
semop(semid, &v24, 1uLL);
return v8;
}

original_code:
int listmessages()
{
  int msg_seg,reg_seg,sem_msg,sem_reg,nregs;
  struct sembuf pop,vop;
  struct str_message *msgs;
  struct reg *regs;
  key_t k1,k2,k3,k4,k5;
  int i,found=0,msgcount=0;
  int currpid = getpid();
  char rec[10];
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].valid ==1)
 {
   if(regs[i].pid == currpid)
     {
       strcpy(rec,regs[i].p_name);
       found =1;
     }
 }
    }
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  semop(sem_msg, &pop, 1);
  msgs = (struct str_message *)shmat(msg_seg,0,0);
  if(found)
    {
      for(i=0;i<100;i++)
 {
   if(msgs[i].valid == 1)
     {
       if(strcmp(msgs[i].recipient, rec) == 0)
  {
    printf("%s \t %s\n",msgs[i].sender,msgs[i].message);
    msgcount++;
  }
     }
 }
    }
  shmdt(msgs);
  semop(sem_msg, &vop, 1);
  if(found)
    return msgcount;
  else
    return 0;
  return -1;
}

canonical_original_code:
int listmessages()
{
  int msg_seg; int reg_seg; int sem_msg; int sem_reg; int nregs;
  struct sembuf pop; struct sembuf vop;
  struct str_message *msgs;
  struct reg *regs;
  int k1; int k2; int k3; int k4; int k5;
  int i; int found = 0; int msgcount = 0;
  int currpid = getpid();
  char rec[10];
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].valid ==1)
 {
   if(regs[i].pid == currpid)
     {
       strcpy(rec,regs[i].p_name);
       found =1;
     }
 }
    }
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  semop(sem_msg, &pop, 1);
  msgs = (struct str_message *)shmat(msg_seg,0,0);
  if(found)
    {
      for(i=0;i<100;i++)
 {
   if(msgs[i].valid == 1)
     {
       if(strcmp(msgs[i].recipient, rec) == 0)
  {
    printf("%s \t %s\n",msgs[i].sender,msgs[i].message);
    msgcount++;
  }
     }
 }
    }
  shmdt(msgs);
  semop(sem_msg, &vop, 1);
  if(found)
    return msgcount;
  else
    return 0;
  return -1;
}

variable_types: i int

variable_types: found int

variable_types: msgcount int

variable_types: currpid int

variable_types:
rec
char [10]

user_defined_types: struct str_message { char sender[10]; char recipient[10]; int time; char message[100]; int valid; }


readmessage

original_code:
int readmessage(struct str_message *buffer )
{
  int msg_seg,sem_msg,reg_seg,nregs,sem_reg;
  struct sembuf pop,vop;
  struct str_message *msgs;
  struct reg *regs;
  key_t k1,k2,k3,k4,k5;
  int i,found=0,msgcount=0;
  int currpid = getpid();
  int mint=0,minid=0;
  char rec[10];
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].valid ==1)
 {
   if(regs[i].pid == currpid)
     {
       strcpy(rec,regs[i].p_name);
       found =1;
     }
 }
    }
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  semop(sem_msg, &pop, 1);
  msgs = (struct str_message *)shmat(msg_seg,0,0);
  if(found)
    {
      for(i=0;i<100;i++)
 {
   if(msgs[i].valid == 1)
     {
       if(strcmp(msgs[i].recipient, rec) == 0)
  {
    if(mint<msgs[i].time)
      {
        mint = msgs[i].time;
                      minid = i;
      }
  }
     }
 }
    }
  strcpy(buffer->sender, msgs[minid].sender);
  strcpy(buffer->recipient, msgs[minid].recipient);
  strcpy(buffer->message, msgs[minid].message);
  buffer->time = msgs[minid].time;
  msgs[minid].valid = 0;
  msgcount = 1;
  shmdt(msgs);
  semop(sem_msg, &vop, 1);
  if(found)
    {
      if(msgcount)
 return 1;
      else
 return 0;
    }
  else
    return 0;
  return -1;
}

canonical_original_code:
int readmessage(struct str_message *buffer)
{
  int msg_seg; int sem_msg; int reg_seg; int nregs; int sem_reg;
  struct sembuf pop; struct sembuf vop;
  struct str_message *msgs;
  struct reg *regs;
  int k1; int k2; int k3; int k4; int k5;
  int i; int found = 0; int msgcount = 0;
  int currpid = getpid();
  int mint = 0; int minid = 0;
  char rec[10];
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].valid ==1)
 {
   if(regs[i].pid == currpid)
     {
       strcpy(rec,regs[i].p_name);
       found =1;
     }
 }
    }
  shmdt(regs);
  semop(sem_reg, &vop, 1);
  semop(sem_msg, &pop, 1);
  msgs = (struct str_message *)shmat(msg_seg,0,0);
  if(found)
    {
      for(i=0;i<100;i++)
 {
   if(msgs[i].valid == 1)
     {
       if(strcmp(msgs[i].recipient, rec) == 0)
  {
    if(mint<msgs[i].time)
      {
        mint = msgs[i].time;
                      minid = i;
      }
  }
     }
 }
    }
  strcpy(buffer->sender, msgs[minid].sender);
  strcpy(buffer->recipient, msgs[minid].recipient);
  strcpy(buffer->message, msgs[minid].message);
  buffer->time = msgs[minid].time;
  msgs[minid].valid = 0;
  msgcount = 1;
  shmdt(msgs);
  semop(sem_msg, &vop, 1);
  if(found)
    {
      if(msgcount)
 return 1;
      else
 return 0;
    }
  else
    return 0;
  return -1;
}

variable_types: mint int

variable_types: minid int


deregister

decompiled_code:
int deregister()
{
__pid_t v0; // ebx
key_t v1; // ebp
key_t v2; // er13
key_t v3; // er12
int v4; // ebp
int v5; // er13
int v6; // er12
_DWORD *v7; // rbp
_DWORD *v8; // rdi
_DWORD *v9; // rax
struct sembuf sops; // [rsp+4h] [rbp-34h] BYREF
struct sembuf v12; // [rsp+Ah] [rbp-2Eh] BYREF

v0 = getpid();
v1 = ftok("/usr/local", 66);
v2 = ftok("/usr/local", 67);
v3 = ftok("/usr/local", 84);
v4 = shmget(v1, 0x7D0uLL, 1023);
v5 = shmget(v2, 4uLL, 1023);
*(_DWORD *)&sops.sem_num = -65536;
v6 = semget(v3, 1, 1023);
v12.sem_flg = 0;
sops.sem_flg = 0;
*(_DWORD *)&v12.sem_num = 0x10000;
semop(v6, &sops, 1uLL);
v7 = shmat(v4, 0LL, 0);
v8 = shmat(v5, 0LL, 0);
v9 = v7 + 3;
do
{
if ( *v9 == v0 )
{
v9[1] = 0;
--*v8;
}
v9 += 5;
}
while ( v9 != v7 + 503 );
shmdt(v8);
shmdt(v7);
return semop(v6, &v12, 1uLL);
}

canonical_decompiled_code:
int func4()
{
__pid_t v0; // ebx
key_t v1; // ebp
key_t v2; // er13
key_t v3; // er12
int v4; // ebp
int v5; // er13
int v6; // er12
_DWORD *v7; // rbp
_DWORD *v8; // rdi
_DWORD *v9; // rax
struct sembuf sops; // [rsp+4h] [rbp-34h] BYREF
struct sembuf v12; // [rsp+Ah] [rbp-2Eh] BYREF

v0 = getpid();
v1 = ftok("/usr/local", 66);
v2 = ftok("/usr/local", 67);
v3 = ftok("/usr/local", 84);
v4 = shmget(v1, 0x7D0uLL, 1023);
v5 = shmget(v2, 4uLL, 1023);
*(_DWORD *)&sops.sem_num = -65536;
v6 = semget(v3, 1, 1023);
v12.sem_flg = 0;
sops.sem_flg = 0;
*(_DWORD *)&v12.sem_num = 0x10000;
semop(v6, &sops, 1uLL);
v7 = shmat(v4, 0LL, 0);
v8 = shmat(v5, 0LL, 0);
v9 = v7 + 3;
do
{
if ( *v9 == v0 )
{
v9[1] = 0;
--*v8;
}
v9 += 5;
}
while ( v9 != v7 + 503 );
shmdt(v8);
shmdt(v7);
return semop(v6, &v12, 1uLL);
}

original_code:
int deregister()
{
  int reg_seg,sem_reg,nregs;
  struct sembuf pop,vop;
  struct reg *regs;
  int *no_regs;
  key_t k2,k3,k5;
  int i;
  int curid = getpid();
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k5 = ftok("/usr/local",'T');
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  no_regs = (int *)shmat(nregs,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].pid == curid)
 {
   regs[i].valid = 0;
   *no_regs = *no_regs -1;
 }
    }
  shmdt(no_regs);
  shmdt(regs);
  semop(sem_reg, &vop, 1);
}

canonical_original_code:
int deregister()
{
  int reg_seg; int sem_reg; int nregs;
  struct sembuf pop; struct sembuf vop;
  struct reg *regs;
  int *no_regs;
  int k2; int k3; int k5;
  int i;
  int curid = getpid();
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k5 = ftok("/usr/local",'T');
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  semop(sem_reg, &pop, 1);
  regs = (struct reg *)shmat(reg_seg,0,0);
  no_regs = (int *)shmat(nregs,0,0);
  for(i=0;i<100;i++)
    {
      if(regs[i].pid == curid)
 {
   regs[i].valid = 0;
   *no_regs = *no_regs -1;
 }
    }
  shmdt(no_regs);
  shmdt(regs);
  semop(sem_reg, &vop, 1);
}

variable_types: curid int


cleanup

decompiled_code:
void __noreturn cleanup()
{
semctl(sem_msg, 0, 0, 0LL);
semctl(sem_reg, 0, 0, 0LL);
shmctl(msg_seg, 0, 0LL);
shmctl(reg_seg, 0, 0LL);
shmctl(nregs, 0, 0LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
semctl(sem_msg, 0, 0, 0LL);
semctl(sem_reg, 0, 0, 0LL);
shmctl(msg_seg, 0, 0LL);
shmctl(reg_seg, 0, 0LL);
shmctl(nregs, 0, 0LL);
exit(0);
}

original_code:
void cleanup()
{
  semctl(sem_msg, 0, 0, 0);
  semctl(sem_reg, 0, 0, 0);
  shmctl(msg_seg,0,0);
  shmctl(reg_seg,0,0);
  shmctl(nregs,0,0);
  exit(0);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
key_t v3; // er14
key_t v4; // er13
key_t v5; // er15
key_t v6; // er12
key_t v7; // ebp
_DWORD *v8; // rbp
char *v9; // rbp
_DWORD *v10; // r12
_DWORD *v11; // rdx
char *v12; // rax
int v13; // ebx
_DWORD *v14; // rdi
_DWORD *v15; // rax
_DWORD *v16; // rdx
void *v17; // r12
unsigned int *v18; // rbp
struct sembuf sops; // [rsp+4h] [rbp-44h] BYREF
struct sembuf v20; // [rsp+Ah] [rbp-3Eh] BYREF

v3 = ftok("/usr/local", 65);
v4 = ftok("/usr/local", 66);
v5 = ftok("/usr/local", 67);
v6 = ftok("/usr/local", 83);
v7 = ftok("/usr/local", 84);
msg_seg = shmget(v3, 0x3200uLL, 1023);
reg_seg = shmget(v4, 0x7D0uLL, 1023);
nregs = shmget(v5, 4uLL, 1023);
sem_msg = semget(v6, 1, 1023);
sem_reg = semget(v7, 1, 1023);
semctl(sem_msg, 0, 16, 1LL);
semctl(sem_reg, 0, 16, 1LL);
v20.sem_flg = 0;
*(_DWORD *)&sops.sem_num = -65536;
sops.sem_flg = 0;
*(_DWORD *)&v20.sem_num = 0x10000;
v8 = shmat(nregs, 0LL, 0);
signal(2, cleanup);
*v8 = 0;
printf("%d", 0LL);
shmdt(v8);
v9 = (char *)shmat(reg_seg, 0LL, 0);
v10 = shmat(msg_seg, 0LL, 0);
v11 = v10 + 31;
v12 = v9 + 16;
do
{
*v11 = 0;
v12 += 20;
v11 += 32;
*((_DWORD *)v12 - 5) = 0;
}
while ( v12 != v9 + 2016 );
shmdt(v9);
shmdt(v10);
while ( 1 )
{
semop(sem_msg, &sops, 1uLL);
v13 = time(0LL);
v14 = shmat(msg_seg, 0LL, 0);
v15 = v14 + 31;
v16 = v14 + 3231;
do
{
while ( *v15 != 1 || v13 - *(v15 - 26) <= 14 )
{
v15 += 32;
if ( v15 == v16 )
goto LABEL_9;
}
*v15 = 0;
v15 += 32;
}
while ( v15 != v16 );
LABEL_9:
shmdt(v14);
semop(sem_msg, &v20, 1uLL);
semop(sem_reg, &sops, 1uLL);
v17 = shmat(reg_seg, 0LL, 0);
v18 = (unsigned int *)shmat(nregs, 0LL, 0);
printf("No of registrations = %d\n", *v18);
shmdt(v18);
shmdt(v17);
semop(sem_reg, &v20, 1uLL);
sleep(2u);
}
}

original_code:
int main()
{
  struct str_message *msgs;
  struct reg *regs;
  struct sembuf pop,vop;
  int t;
  int *no_regs,i;
  key_t k1,k2,k3,k4,k5;
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  semctl(sem_msg, 0, 16, 1);
  semctl(sem_reg, 0, 16, 1);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  no_regs = (int *) shmat(nregs,0,0);
  signal(2,cleanup);
  *no_regs = 0;
  printf("%d",*no_regs);
  shmdt(no_regs);
  regs = (struct reg *)shmat(reg_seg,0,0);
  msgs = (struct str_message *)shmat(msg_seg,0,0);
  for(i=0;i<100;i++)
  {
   msgs[i].valid = 0;
   regs[i].valid =0 ;
  }
      shmdt(regs);
      shmdt(msgs);
  while(1)
    {
      semop(sem_msg, &pop, 1);
      t = time(((void *)0));
      msgs = (struct str_message *)shmat(msg_seg,0,0);
      for(i=0;i<100;i++)
      {
        if(msgs[i].valid ==1)
        {
         if(t - msgs[i].time >=15)
         msgs[i].valid = 0;
        }
      }
      shmdt(msgs);
      semop(sem_msg, &vop, 1);
      semop(sem_reg, &pop, 1);
      regs = (struct reg *)shmat(reg_seg,0,0);
      no_regs = (int *) shmat(nregs,0,0);
      printf("No of registrations = %d\n",*no_regs);
      shmdt(no_regs);
      shmdt(regs);
      semop(sem_reg, &vop, 1);
      sleep(2);
    }
}

canonical_original_code:
int main()
{
  struct str_message *msgs;
  struct reg *regs;
  struct sembuf pop; struct sembuf vop;
  int t;
  int *no_regs; int i;
  int k1; int k2; int k3; int k4; int k5;
  k1 = ftok("/usr/local",'A');
  k2 = ftok("/usr/local",'B');
  k3 = ftok("/usr/local",'C');
  k4 = ftok("/usr/local",'S');
  k5 = ftok("/usr/local",'T');
  msg_seg = shmget(k1,100*sizeof(struct str_message),0777|01000);
  reg_seg = shmget(k2,100*sizeof(struct reg),0777|01000);
  nregs = shmget(k3,sizeof(int),0777|01000);
  sem_msg = semget(k4,1,0777|01000);
  sem_reg = semget(k5,1,0777|01000);
  semctl(sem_msg, 0, 16, 1);
  semctl(sem_reg, 0, 16, 1);
  pop.sem_num = vop.sem_num = 0;
  pop.sem_flg = vop.sem_flg = 0;
  pop.sem_op = -1 ; vop.sem_op = 1 ;
  no_regs = (int *) shmat(nregs,0,0);
  signal(2,cleanup);
  *no_regs = 0;
  printf("%d",*no_regs);
  shmdt(no_regs);
  regs = (struct reg *)shmat(reg_seg,0,0);
  msgs = (struct str_message *)shmat(msg_seg,0,0);
  for(i=0;i<100;i++)
  {
   msgs[i].valid = 0;
   regs[i].valid =0 ;
  }
      shmdt(regs);
      shmdt(msgs);
  while(1)
    {
      semop(sem_msg, &pop, 1);
      t = time(((void *)0));
      msgs = (struct str_message *)shmat(msg_seg,0,0);
      for(i=0;i<100;i++)
      {
        if(msgs[i].valid ==1)
        {
         if(t - msgs[i].time >=15)
         msgs[i].valid = 0;
        }
      }
      shmdt(msgs);
      semop(sem_msg, &vop, 1);
      semop(sem_reg, &pop, 1);
      regs = (struct reg *)shmat(reg_seg,0,0);
      no_regs = (int *) shmat(nregs,0,0);
      printf("No of registrations = %d\n",*no_regs);
      shmdt(no_regs);
      shmdt(regs);
      semop(sem_reg, &vop, 1);
      sleep(2);
    }
}

variable_types: t int


repo: longluo/xPrintf

original_code:
char *i2a(int val, int base, char ** ps)
{
 int m = val % base;
 int q = val / base;
 if (q) {
  i2a(q, base, ps);
 }
 *(*ps)++ = (m < 10) ? (m + '0') : (m - 10 + 'A');
 return *ps;
}

canonical_original_code:
char *i2a(int val, int base, char **ps)
{
 int m = val % base;
 int q = val / base;
 if (q) {
  i2a(q, base, ps);
 }
 *(*ps)++ = (m < 10) ? (m + '0') : (m - 10 + 'A');
 return *ps;
}

variable_types: val int

variable_types: base int

variable_types:
ps
char **

variable_types: m int

variable_types: q int


vsLprintf

original_code:
int vsLprintf(char *buf, const char *fmt, va_list args)
{
 char *p;
 int m;
 char inner_buf[1024];
 char cs;
 int align_nr;
 va_list p_next_arg = args;
 for (p=buf; *fmt; fmt++) {
  if (*fmt != '%') {
   *p++ = *fmt;
   continue;
  }
  else {
   align_nr = 0;
  }
  fmt++;
  if (*fmt == '%') {
   *p++ = *fmt;
   continue;
  }
  else if (*fmt == '0') {
   cs = '0';
   fmt++;
  }
  else {
   cs = ' ';
  }
  while (((unsigned char)(*fmt) >= '0') && ((unsigned char)(*fmt) <= '9')) {
   align_nr *= 10;
   align_nr += *fmt - '0';
   fmt++;
  }
  char * q = inner_buf;
  memset(q, 0, sizeof(inner_buf));
  switch (*fmt) {
  case 'c':
   *q++ = *((char*)p_next_arg);
   p_next_arg += 4;
   break;
  case 'x':
   m = *((int*)p_next_arg);
   i2a(m, 16, &q);
   p_next_arg += 4;
   break;
  case 'd':
   m = *((int*)p_next_arg);
   if (m < 0) {
    m = m * (-1);
    *q++ = '-';
   }
   i2a(m, 10, &q);
   p_next_arg += 4;
   break;
  case 's':
   strcpy(q, (*((char**)p_next_arg)));
   q += strlen(*((char**)p_next_arg));
   p_next_arg += 4;
   break;
  default:
   break;
  }
  int k;
  for (k = 0; k < ((align_nr > strlen(inner_buf)) ? (align_nr - strlen(inner_buf)) : 0); k++) {
   *p++ = cs;
  }
  q = inner_buf;
  while (*q) {
   *p++ = *q++;
  }
 }
 *p = 0;
 return (p - buf);
}

canonical_original_code:
int vsLprintf(char *buf, char *fmt, char *args)
{
 char *p;
 int m;
 char inner_buf[1024];
 char cs;
 int align_nr;
 char *p_next_arg = args;
 for (p=buf; *fmt; fmt++) {
  if (*fmt != '%') {
   *p++ = *fmt;
   continue;
  }
  else {
   align_nr = 0;
  }
  fmt++;
  if (*fmt == '%') {
   *p++ = *fmt;
   continue;
  }
  else if (*fmt == '0') {
   cs = '0';
   fmt++;
  }
  else {
   cs = ' ';
  }
  while (((unsigned char)(*fmt) >= '0') && ((unsigned char)(*fmt) <= '9')) {
   align_nr *= 10;
   align_nr += *fmt - '0';
   fmt++;
  }
  char *q = inner_buf;
  memset(q, 0, sizeof(inner_buf));
  switch (*fmt) {
  case 'c':
   *q++ = *((char *)p_next_arg);
   p_next_arg += 4;
   break;
  case 'x':
   m = *((int *)p_next_arg);
   i2a(m, 16, &q);
   p_next_arg += 4;
   break;
  case 'd':
   m = *((int *)p_next_arg);
   if (m < 0) {
    m = m * (-1);
    *q++ = '-';
   }
   i2a(m, 10, &q);
   p_next_arg += 4;
   break;
  case 's':
   strcpy(q, (*((char **)p_next_arg)));
   q += strlen(*((char **)p_next_arg));
   p_next_arg += 4;
   break;
  default:
   break;
  }
  int k;
  for (k = 0; k < ((align_nr > strlen(inner_buf)) ? (align_nr - strlen(inner_buf)) : 0); k++) {
   *p++ = cs;
  }
  q = inner_buf;
  while (*q) {
   *p++ = *q++;
  }
 }
 *p = 0;
 return (p - buf);
}

variable_types:
buf
char *

variable_types:
fmt
char *

variable_types:
args
char *

variable_types:
p
char *

variable_types: cs char

variable_types:
q
char *

variable_types: k int


sLprintf

decompiled_code:
__int64 __fastcall sLprintf(char *a1, char *a2)
{
const char *v3; // [rsp+Ch] [rbp-Ch] BYREF

LODWORD(v3) = HIDWORD(a2);
return vsLprintf(a1, a2, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char *a2)
{
const char *v3; // [rsp+Ch] [rbp-Ch] BYREF

LODWORD(v3) = HIDWORD(a2);
return func1(a1, a2, &v3);
}

original_code:
int sLprintf(char *buf, const char *fmt, ...)
{
 va_list arg = (va_list)((char*)(&fmt) + 4);
 return vsLprintf(buf, fmt, arg);
}

canonical_original_code:
int sLprintf(char *buf, char *fmt, ...)
{
 char *arg = (va_list)((char*)(&fmt) + 4);
 return vsLprintf(buf, fmt, arg);
}

variable_types:
arg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Lprintf("%s\n\n", " A Tiny Demo show the LLprintf ");
Lprintf("\t\t%s, version %f \n\n", "LLprintf", *(double *)&LC2);
Lprintf("\tCreated by %s, %s.\n\n", "Long.Luo", "Jan. 24th, 2013");
return 0;
}

original_code:
int main(void)
{
 char *welcome = "     A Tiny Demo show the LLprintf   ";
 char *program_name = "LLprintf";
 char *program_author = "Long.Luo";
 char *date = "Jan. 24th, 2013";
 float program_version = 2.1;
 Lprintf("%s\n\n", welcome);
 Lprintf("\t\t%s, version %f \n\n", program_name, program_version);
 Lprintf("\tCreated by %s, %s.\n\n", program_author, date);
 return 0;
}

canonical_original_code:
int main()
{
 char *welcome = "     A Tiny Demo show the LLprintf   ";
 char *program_name = "LLprintf";
 char *program_author = "Long.Luo";
 char *date = "Jan. 24th, 2013";
 float program_version = 2.1;
 Lprintf("%s\n\n", welcome);
 Lprintf("\t\t%s, version %f \n\n", program_name, program_version);
 Lprintf("\tCreated by %s, %s.\n\n", program_author, date);
 return 0;
}

variable_types:
welcome
char *

variable_types:
date
char *


decompiled_code:
__int64 __fastcall zc_hashtable_str_hash(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 5381; *a1; v1 = (char)*a1 )
{
++a1;
i += 32 * i + v1;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 5381; *a1; v1 = (char)*a1 )
{
++a1;
i += 32 * i + v1;
}
return i;
}

original_code:
unsigned int zc_hashtable_str_hash(const void *str)
{
 unsigned int h = 5381;
 const char *p = (const char *)str;
 while (*p != '\0')
  h = ((h << 5) + h) + (*p++);
 return h;
}

canonical_original_code:
unsigned int zc_hashtable_str_hash(void *str)
{
 unsigned int h = 5381;
 char *p = (const char *)str;
 while (*p != '\0')
  h = ((h << 5) + h) + (*p++);
 return h;
}

variable_types:
str
void *

variable_types:
h
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall zc_hashtable_str_equal(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int zc_hashtable_str_equal(const void *key1, const void *key2)
{
 return (( strcmp((const char *)key1,(const char *)key2) == 0 ));
}

canonical_original_code:
int zc_hashtable_str_equal(void *key1, void *key2)
{
 return (( strcmp((char *)key1,(char *)key2) == 0 ));
}


decompiled_code:
void __fastcall zc_hashtable_del(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // r13
_QWORD *v5; // rbx
void (__fastcall *v6)(_QWORD); // rax
_QWORD *v7; // rbp
void (__fastcall *v8)(_QWORD); // rax

v2 = *((_QWORD *)ptr + 2) == 0LL;
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)v3[v4];
if ( v5 )
{
do
{
v6 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 5);
v7 = v5;
v5 = (_QWORD *)v5[4];
if ( v6 )
v6(v7[1]);
v8 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 6);
if ( v8 )
v8(v7[2]);
free(v7);
}
while ( v5 );
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
}
++v4;
}
while ( *((_QWORD *)ptr + 2) > v4 );
}
if ( v3 )
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
bool v2; // zf
_QWORD *v3; // rdi
unsigned __int64 v4; // r13
_QWORD *v5; // rbx
void (__fastcall *v6)(_QWORD); // rax
_QWORD *v7; // rbp
void (__fastcall *v8)(_QWORD); // rax

v2 = *((_QWORD *)ptr + 2) == 0LL;
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v2 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)v3[v4];
if ( v5 )
{
do
{
v6 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 5);
v7 = v5;
v5 = (_QWORD *)v5[4];
if ( v6 )
v6(v7[1]);
v8 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 6);
if ( v8 )
v8(v7[2]);
free(v7);
}
while ( v5 );
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
}
++v4;
}
while ( *((_QWORD *)ptr + 2) > v4 );
}
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void zc_hashtable_del(zc_hashtable_t * a_table)
{
 size_t i;
 zc_hashtable_entry_t *p;
 zc_hashtable_entry_t *q;
 for (i = 0; i < a_table->tab_size; i++) {
  for (p = (a_table->tab)[i]; p; p = q) {
   q = p->next;
   if (a_table->key_del) {
    a_table->key_del(p->key);
   }
   if (a_table->value_del) {
    a_table->value_del(p->value);
   }
   free(p);
  }
 }
 if (a_table->tab)
  free(a_table->tab);
 free(a_table);
 return;
}

canonical_original_code:
void zc_hashtable_del(struct zc_hashtable_s *a_table)
{
 unsigned long i;
 struct zc_hashtable_entry_s *p;
 struct zc_hashtable_entry_s *q;
 for (i = 0; i < a_table->tab_size; i++) {
  for (p = (a_table->tab)[i]; p; p = q) {
   q = p->next;
   if (a_table->key_del) {
    a_table->key_del(p->key);
   }
   if (a_table->value_del) {
    a_table->value_del(p->value);
   }
   free(p);
  }
 }
 if (a_table->tab)
  free(a_table->tab);
 free(a_table);
 return;
}

variable_types: struct zc_hashtable_s { unsigned long nelem; struct zc_hashtable_entry_s { unsigned int hash_key; void *key; void *value; struct zc_hashtable_entry_s *prev; struct zc_hashtable_entry_s *next; } **tab; unsigned long tab_size; unsigned int (*hash)(void *key); int (*equal)(void *key1, void *key2); void (*key_del)(void *kv); void (*value_del)(void *kv); } *

variable_types:
i
unsigned long

user_defined_types: struct zc_hashtable_s { unsigned long nelem; struct zc_hashtable_entry_s **tab; unsigned long tab_size; unsigned int (*hash)(void *key); int (*equal)(void *key1, void *key2); void (*key_del)(void *kv); void (*value_del)(void *kv); }


original_code:
void zc_hashtable_clean(zc_hashtable_t * a_table)
{
 size_t i;
 zc_hashtable_entry_t *p;
 zc_hashtable_entry_t *q;
 for (i = 0; i < a_table->tab_size; i++) {
  for (p = (a_table->tab)[i]; p; p = q) {
   q = p->next;
   if (a_table->key_del) {
    a_table->key_del(p->key);
   }
   if (a_table->value_del) {
    a_table->value_del(p->value);
   }
   free(p);
  }
  (a_table->tab)[i] = ((void *)0);
 }
 a_table->nelem = 0;
 return;
}

canonical_original_code:
void zc_hashtable_clean(struct zc_hashtable_s *a_table)
{
 unsigned long i;
 struct zc_hashtable_entry_s *p;
 struct zc_hashtable_entry_s *q;
 for (i = 0; i < a_table->tab_size; i++) {
  for (p = (a_table->tab)[i]; p; p = q) {
   q = p->next;
   if (a_table->key_del) {
    a_table->key_del(p->key);
   }
   if (a_table->value_del) {
    a_table->value_del(p->value);
   }
   free(p);
  }
  (a_table->tab)[i] = ((void *)0);
 }
 a_table->nelem = 0;
 return;
}

variable_types: struct zc_hashtable_entry_s { unsigned int hash_key; void *key; void *value; struct zc_hashtable_entry_s *prev; struct zc_hashtable_entry_s *next; } *


original_code:
zc_hashtable_entry_t *zc_hashtable_get_entry(zc_hashtable_t * a_table, const void *a_key)
{
 unsigned int i;
 zc_hashtable_entry_t *p;
 i = a_table->hash(a_key) % a_table->tab_size;
 for (p = (a_table->tab)[i]; p; p = p->next) {
  if (a_table->equal(a_key, p->key))
   return p;
 }
 return ((void *)0);
}

canonical_original_code:
struct zc_hashtable_entry_s *zc_hashtable_get_entry(struct zc_hashtable_s *a_table, void *a_key)
{
 unsigned int i;
 struct zc_hashtable_entry_s *p;
 i = a_table->hash(a_key) % a_table->tab_size;
 for (p = (a_table->tab)[i]; p; p = p->next) {
  if (a_table->equal(a_key, p->key))
   return p;
 }
 return ((void *)0);
}

variable_types: struct zc_hashtable_s { unsigned long nelem; struct zc_hashtable_entry_s **tab; unsigned long tab_size; unsigned int (*hash)(void *key); int (*equal)(void *key1, void *key2); void (*key_del)(void *kv); void (*value_del)(void *kv); } *

variable_types:
i
unsigned int

return_type: struct zc_hashtable_entry_s { unsigned int hash_key; void *key; void *value; struct zc_hashtable_entry_s *prev; struct zc_hashtable_entry_s *next; } *


decompiled_code:
__int64 __fastcall zc_hashtable_begin(__int64 a1)
{
__int64 v1; // rdx
__int64 i; // rax
__int64 v3; // r8

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 )
return 0LL;
for ( i = 0LL; i != v1; ++i )
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * i);
if ( v3 )
break;
}
return v3;
}

original_code:
zc_hashtable_entry_t *zc_hashtable_begin(zc_hashtable_t * a_table)
{
 size_t i;
 zc_hashtable_entry_t *p;
 for (i = 0; i < a_table->tab_size; i++) {
  for (p = (a_table->tab)[i]; p; p = p->next) {
   if (p)
    return p;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct zc_hashtable_entry_s *zc_hashtable_begin(struct zc_hashtable_s *a_table)
{
 unsigned long i;
 struct zc_hashtable_entry_s *p;
 for (i = 0; i < a_table->tab_size; i++) {
  for (p = (a_table->tab)[i]; p; p = p->next) {
   if (p)
    return p;
  }
 }
 return ((void *)0);
}

user_defined_types: struct zc_hashtable_entry_s { unsigned int hash_key; void *key; void *value; struct zc_hashtable_entry_s *prev; struct zc_hashtable_entry_s *next; }


decompiled_code:
__int64 __fastcall zc_hashtable_next(__int64 a1, unsigned int *a2)
{
__int64 v2; // r8
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rdx
__int64 v6; // rax

v2 = *((_QWORD *)a2 + 4);
if ( v2 )
return v2;
v4 = *(_QWORD *)(a1 + 16);
v5 = *a2 % v4 + 1;
if ( v4 <= v5 )
return v2;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(v6 + 8 * v5);
if ( v2 )
break;
if ( v4 == ++v5 )
return v2;
}
return *(_QWORD *)(v6 + 8 * v5);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int *a2)
{
__int64 v2; // r8
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rdx
__int64 v6; // rax

v2 = *((_QWORD *)a2 + 4);
if ( v2 )
return v2;
v4 = *(_QWORD *)(a1 + 16);
v5 = *a2 % v4 + 1;
if ( v4 <= v5 )
return v2;
while ( 1 )
{
v6 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(v6 + 8 * v5);
if ( v2 )
break;
if ( v4 == ++v5 )
return v2;
}
return *(_QWORD *)(v6 + 8 * v5);
}

original_code:
zc_hashtable_entry_t *zc_hashtable_next(zc_hashtable_t * a_table, zc_hashtable_entry_t * a_entry)
{
 size_t i;
 size_t j;
 if (a_entry->next)
  return a_entry->next;
 i = a_entry->hash_key % a_table->tab_size;
 for (j = i + 1; j < a_table->tab_size; j++) {
  if ((a_table->tab)[j]) {
   return (a_table->tab)[j];
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct zc_hashtable_entry_s *zc_hashtable_next(struct zc_hashtable_s *a_table, struct zc_hashtable_entry_s *a_entry)
{
 unsigned long i;
 unsigned long j;
 if (a_entry->next)
  return a_entry->next;
 i = a_entry->hash_key % a_table->tab_size;
 for (j = i + 1; j < a_table->tab_size; j++) {
  if ((a_table->tab)[j]) {
   return (a_table->tab)[j];
  }
 }
 return ((void *)0);
}

variable_types:
j
unsigned long


decompiled_code:
__int64 __fastcall zlog_level_list_profile(unsigned int *a1, unsigned int a2)
{
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rdi

if ( !a1 )
return zc_profile_inner(2LL, "level_list.c", 36LL, "levels is null or 0");
v3 = 0LL;
zc_profile_inner(a2, "level_list.c", 37LL, "--level_list[%p]--", a1);
result = a1[2];
if ( (int)result > 0 )
{
do
{
result = *(_QWORD *)a1;
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v3);
if ( v5 )
result = zlog_level_profile(v5, a2);
++v3;
}
while ( (int)a1[2] > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, unsigned int a2)
{
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rdi

if ( !a1 )
return zc_profile_inner(2LL, "level_list.c", 36LL, "levels is null or 0");
v3 = 0LL;
zc_profile_inner(a2, "level_list.c", 37LL, "--level_list[%p]--", a1);
result = a1[2];
if ( (int)result > 0 )
{
do
{
result = *(_QWORD *)a1;
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v3);
if ( v5 )
result = zlog_level_profile(v5, a2);
++v3;
}
while ( (int)a1[2] > (int)v3 );
}
return result;
}

original_code:
void zlog_level_list_profile(zc_arraylist_t *levels, int flag)
{
 int i;
 zlog_level_t *a_level;
 if(!(levels)) { zc_profile_inner(ZC_ERROR, "level_list.c", 36, "levels"" is null or 0"); return ; };
 zc_profile_inner(flag, "level_list.c", 37, "--level_list[%p]--", levels);
 for(i = 0, a_level = levels->array[0]; (i < levels->len) && (a_level = levels->array[i], 1) ; i++) {
  if (a_level) zlog_level_profile(a_level, flag);
 }
 return;
}

canonical_original_code:
void zlog_level_list_profile(struct zc_arraylist_t *levels, int flag)
{
 int i;
 struct zlog_level_s *a_level;
 if(!(levels)) { zc_profile_inner(ZC_ERROR, "level_list.c", 36, "levels"" is null or 0"); return ; };
 zc_profile_inner(flag, "level_list.c", 37, "--level_list[%p]--", levels);
 for(i = 0, a_level = levels->array[0]; (i < levels->len) && (a_level = levels->array[i], 1) ; i++) {
  if (a_level) zlog_level_profile(a_level, flag);
 }
 return;
}

variable_types: struct zc_arraylist_t { void **array; int len; int size; void (*del)(void *data); } *

variable_types: flag int

variable_types: i int

variable_types: struct zlog_level_s { int int_level; char str_uppercase[-1]; char str_lowercase[-1]; unsigned long str_len; int syslog_level; } *


decompiled_code:
__int64 __fastcall zlog_level_list_del(const void *a1)
{
if ( !a1 )
return zc_profile_inner(2LL, "level_list.c", 48LL, "levels is null or 0");
zc_arraylist_del();
return zc_profile_inner(0LL, "level_list.c", 50LL, "zc_level_list_del[%p]", a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1)
{
if ( !a1 )
return zc_profile_inner(2LL, "level_list.c", 48LL, "levels is null or 0");
zc_arraylist_del();
return zc_profile_inner(0LL, "level_list.c", 50LL, "zc_level_list_del[%p]", a1);
}

original_code:
void zlog_level_list_del(zc_arraylist_t *levels)
{
 if(!(levels)) { zc_profile_inner(ZC_ERROR, "level_list.c", 48, "levels"" is null or 0"); return ; };
 zc_arraylist_del(levels);
 zc_profile_inner(ZC_DEBUG, "level_list.c", 50, "zc_level_list_del[%p]", levels);
 return;
}

canonical_original_code:
void zlog_level_list_del(struct zc_arraylist_t *levels)
{
 if(!(levels)) { zc_profile_inner(ZC_ERROR, "level_list.c", 48, "levels"" is null or 0"); return ; };
 zc_arraylist_del(levels);
 zc_profile_inner(ZC_DEBUG, "level_list.c", 50, "zc_level_list_del[%p]", levels);
 return;
}

user_defined_types: struct zc_arraylist_t { void **array; int len; int size; void (*del)(void *data); }


decompiled_code:
__int64 __fastcall zlog_level_list_set(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbp
__int64 result; // rax

v2 = (unsigned int *)zlog_level_new(a2);
if ( v2 )
{
v3 = v2;
result = zc_arraylist_set(a1, *v2, v2);
if ( (_DWORD)result )
{
zc_profile_inner(2LL, "level_list.c", 101LL, "zc_arraylist_set fail");
zc_profile_inner(2LL, "level_list.c", 107LL, "line[%s]", a2);
zlog_level_del(v3);
result = 0xFFFFFFFFLL;
}
}
else
{
zc_profile_inner(2LL, "level_list.c", 96LL, "zlog_level_new fail");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbp
__int64 result; // rax

v2 = (unsigned int *)zlog_level_new(a2);
if ( v2 )
{
v3 = v2;
result = zc_arraylist_set(a1, *v2, v2);
if ( (_DWORD)result )
{
zc_profile_inner(2LL, "level_list.c", 101LL, "zc_arraylist_set fail");
zc_profile_inner(2LL, "level_list.c", 107LL, "line[%s]", a2);
zlog_level_del(v3);
result = 0xFFFFFFFFLL;
}
}
else
{
zc_profile_inner(2LL, "level_list.c", 96LL, "zlog_level_new fail");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int zlog_level_list_set(zc_arraylist_t *levels, char *line)
{
 zlog_level_t *a_level;
 a_level = zlog_level_new(line);
 if (!a_level) {
  zc_profile_inner(ZC_ERROR, "level_list.c", 96, "zlog_level_new fail");
  return -1;
 }
 if (zc_arraylist_set(levels, a_level->int_level, a_level)) {
  zc_profile_inner(ZC_ERROR, "level_list.c", 101, "zc_arraylist_set fail");
  goto err;
 }
 return 0;
err:
 zc_profile_inner(ZC_ERROR, "level_list.c", 107, "line[%s]", line);
 zlog_level_del(a_level);
 return -1;
}

canonical_original_code:
int zlog_level_list_set(struct zc_arraylist_t *levels, char *line)
{
 struct zlog_level_s *a_level;
 a_level = zlog_level_new(line);
 if (!a_level) {
  zc_profile_inner(ZC_ERROR, "level_list.c", 96, "zlog_level_new fail");
  return -1;
 }
 if (zc_arraylist_set(levels, a_level->int_level, a_level)) {
  zc_profile_inner(ZC_ERROR, "level_list.c", 101, "zc_arraylist_set fail");
  goto err;
 }
 return 0;
err:
 zc_profile_inner(ZC_ERROR, "level_list.c", 107, "line[%s]", line);
 zlog_level_del(a_level);
 return -1;
}

variable_types:
line
char *

user_defined_types: struct zlog_level_s { int int_level; char str_uppercase[-1]; char str_lowercase[-1]; unsigned long str_len; int syslog_level; }


decompiled_code:
_BOOL8 __fastcall zlog_level_list_set_default(__int64 a1)
{
_BOOL8 result; // rax

if ( (unsigned int)zlog_level_list_set(a1, "* = 0, LOG_INFO")
|| (unsigned int)zlog_level_list_set(a1, "DEBUG = 20, LOG_DEBUG")
|| (unsigned int)zlog_level_list_set(a1, "INFO = 40, LOG_INFO")
|| (unsigned int)zlog_level_list_set(a1, "NOTICE = 60, LOG_NOTICE")
|| (unsigned int)zlog_level_list_set(a1, "WARN = 80, LOG_WARNING")
|| (unsigned int)zlog_level_list_set(a1, "ERROR = 100, LOG_ERR")
|| (unsigned int)zlog_level_list_set(a1, "FATAL = 120, LOG_ALERT")
|| (unsigned int)zlog_level_list_set(a1, "UNKNOWN = 254, LOG_ERR") )
{
result = 1LL;
}
else
{
result = (unsigned int)zlog_level_list_set(a1, "! = 255, LOG_INFO") != 0;
}
return result;
}

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

if ( (unsigned int)func2(a1, "* = 0, LOG_INFO")
|| (unsigned int)func2(a1, "DEBUG = 20, LOG_DEBUG")
|| (unsigned int)func2(a1, "INFO = 40, LOG_INFO")
|| (unsigned int)func2(a1, "NOTICE = 60, LOG_NOTICE")
|| (unsigned int)func2(a1, "WARN = 80, LOG_WARNING")
|| (unsigned int)func2(a1, "ERROR = 100, LOG_ERR")
|| (unsigned int)func2(a1, "FATAL = 120, LOG_ALERT")
|| (unsigned int)func2(a1, "UNKNOWN = 254, LOG_ERR") )
{
result = 1LL;
}
else
{
result = (unsigned int)func2(a1, "! = 255, LOG_INFO") != 0;
}
return result;
}

original_code:
static int zlog_level_list_set_default(zc_arraylist_t *levels)
{
 return zlog_level_list_set(levels, "* = 0, LOG_INFO")
 || zlog_level_list_set(levels, "DEBUG = 20, LOG_DEBUG")
 || zlog_level_list_set(levels, "INFO = 40, LOG_INFO")
 || zlog_level_list_set(levels, "NOTICE = 60, LOG_NOTICE")
 || zlog_level_list_set(levels, "WARN = 80, LOG_WARNING")
 || zlog_level_list_set(levels, "ERROR = 100, LOG_ERR")
 || zlog_level_list_set(levels, "FATAL = 120, LOG_ALERT")
 || zlog_level_list_set(levels, "UNKNOWN = 254, LOG_ERR")
 || zlog_level_list_set(levels, "! = 255, LOG_INFO");
}

canonical_original_code:
static int zlog_level_list_set_default(struct zc_arraylist_t *levels)
{
 return zlog_level_list_set(levels, "* = 0, LOG_INFO")
 || zlog_level_list_set(levels, "DEBUG = 20, LOG_DEBUG")
 || zlog_level_list_set(levels, "INFO = 40, LOG_INFO")
 || zlog_level_list_set(levels, "NOTICE = 60, LOG_NOTICE")
 || zlog_level_list_set(levels, "WARN = 80, LOG_WARNING")
 || zlog_level_list_set(levels, "ERROR = 100, LOG_ERR")
 || zlog_level_list_set(levels, "FATAL = 120, LOG_ALERT")
 || zlog_level_list_set(levels, "UNKNOWN = 254, LOG_ERR")
 || zlog_level_list_set(levels, "! = 255, LOG_INFO");
}