original_code:
static void frame_data(l2_frame_t *f, const u_char* packet)
{
 f->frame_ptr = (void*)packet;
 f->eth_header = (struct ether_header*) packet;
 f->eth_type = ntohs(f->eth_header->ether_type);
 if (f->eth_type == 0x0800) {
  f->ip_header = (struct ip*) (packet + sizeof(struct ether_header));
  f->ip_proto = f->ip_header->ip_p;
  f->ip_len = ntohs(f->ip_header->ip_len);
  f->payload = packet + sizeof(struct ether_header) + sizeof(struct ip);
  f->ip_src_addr = f->ip_header->ip_src.s_addr;
  f->ip_dst_addr = f->ip_header->ip_dst.s_addr;
 } else if (f->eth_type == 0x0806) {
  f->arp = (struct ether_arp*) (packet + sizeof(struct ether_header));
  memcpy((void*)&f->ip_src_addr, (const void*)f->arp->arp_spa, sizeof(f->ip_src_addr));
  memcpy((void*)&f->ip_dst_addr, (const void*)f->arp->arp_tpa, sizeof(f->ip_dst_addr));
 } else {
  do { pthread_mutex_lock(&con_mutex); fprintf(stderr, "Error: (BUG).\n"); pthread_mutex_unlock(&con_mutex); } while (0);
 }
 ether_ntoa_r((struct ether_addr*)f->eth_header->ether_shost, f->eth_addr_src);
 ether_ntoa_r((struct ether_addr*)f->eth_header->ether_dhost, f->eth_addr_dst);
}

canonical_original_code:
static void frame_data(struct l2_frame_t *f, unsigned char *packet)
{
 f->frame_ptr = (void *)packet;
 f->eth_header = (struct ether_header *) packet;
 f->eth_type = ntohs(f->eth_header->ether_type);
 if (f->eth_type == 0x0800) {
  f->ip_header = (struct ip *) (packet + sizeof(struct ether_header));
  f->ip_proto = f->ip_header->ip_p;
  f->ip_len = ntohs(f->ip_header->ip_len);
  f->payload = packet + sizeof(struct ether_header) + sizeof(struct ip);
  f->ip_src_addr = f->ip_header->ip_src.s_addr;
  f->ip_dst_addr = f->ip_header->ip_dst.s_addr;
 } else if (f->eth_type == 0x0806) {
  f->arp = (struct ether_arp *) (packet + sizeof(struct ether_header));
  memcpy((void *)&f->ip_src_addr, (void *)f->arp->arp_spa, sizeof(f->ip_src_addr));
  memcpy((void *)&f->ip_dst_addr, (void *)f->arp->arp_tpa, sizeof(f->ip_dst_addr));
 } else {
  do { pthread_mutex_lock(&con_mutex); fprintf(stderr, "Error: (BUG).\n"); pthread_mutex_unlock(&con_mutex); } while (0);
 }
 ether_ntoa_r((struct ether_addr *)f->eth_header->ether_shost, f->eth_addr_src);
 ether_ntoa_r((struct ether_addr *)f->eth_header->ether_dhost, f->eth_addr_dst);
}

variable_types: struct l2_frame_t { void *frame_ptr; unsigned long size; struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *eth_header; unsigned int eth_type; char eth_addr_src[32]; char eth_addr_dst[32]; struct ether_arp { struct arphdr { unsigned short ar_hrd; unsigned short ar_pro; unsigned char ar_hln; unsigned char ar_pln; unsigned short ar_op; } ea_hdr; unsigned char arp_sha[6]; unsigned char arp_spa[4]; unsigned char arp_tha[6]; unsigned char arp_tpa[4]; } *arp; struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *ip_header; unsigned int ip_proto; unsigned short ip_len; unsigned long ip_dst_addr; unsigned long ip_src_addr; unsigned char *payload; } *

variable_types:
packet
unsigned char *

user_defined_types: struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }

user_defined_types: struct l2_frame_t { void *frame_ptr; unsigned long size; struct ether_header *eth_header; unsigned int eth_type; char eth_addr_src[32]; char eth_addr_dst[32]; struct ether_arp *arp; struct ip *ip_header; unsigned int ip_proto; unsigned short ip_len; unsigned long ip_dst_addr; unsigned long ip_src_addr; unsigned char *payload; }

user_defined_types: struct ether_arp { struct arphdr ea_hdr; unsigned char arp_sha[6]; unsigned char arp_spa[4]; unsigned char arp_tha[6]; unsigned char arp_tpa[4]; }

user_defined_types: struct ether_addr { unsigned char ether_addr_octet[6]; }


decompiled_code:
__int64 l2_init()
{
unsigned int v0; // edx

raw_sock = libnet_init(1LL, 0LL, errbuf);
v0 = 1;
if ( !raw_sock )
{
fprintf(stderr, "Error: Failed to create raw socket, %s.\n", errbuf);
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // edx

raw_sock = libnet_init(1LL, 0LL, errbuf);
v0 = 1;
if ( !raw_sock )
{
fprintf(stderr, "Error: Failed to create raw socket, %s.\n", errbuf);
v0 = 0;
}
return v0;
}

original_code:
extern int l2_init()
{
 if ((raw_sock = libnet_init(0x01, ((void *)0), errbuf)) == ((void *)0)) {
  fprintf(stderr, "Error: Failed to create raw socket, %s.\n",
    errbuf);
  return(0);
 }
 return(1);
}

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( !(unsigned int)l2_init(argc, argv, envp) )
exit(1);
if ( !(unsigned int)l2_parse_conf(stdin) )
{
fwrite("Error: Please review your config file.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
if ( !(unsigned int)l2_set_filters() )
{
fwrite("Error: Please review your config file.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
if ( !(unsigned int)l2_route() )
exit(1);
l2_deinit();
exit(0);
}

original_code:
int main()
{
 if (! l2_init())
  exit(1);
 if (! l2_parse_conf(stdin)) {
  fprintf(stderr, "Error: Please review your config file.\n");
  exit(1);
 }
 if (! l2_set_filters()) {
  fprintf(stderr, "Error: Please review your config file.\n");
  exit(1);
 }
 if (! l2_route())
  exit(1);
 l2_deinit();
 exit(0);
}


variable_types: argc int

variable_types:
argv
char **

variable_types: fd int

variable_types: j int

variable_types: struct cc16_naf_data { unsigned int naf; unsigned int data; }


decompiled_code:
__int64 __fastcall export_gpio(unsigned int a1)
{
int v1; // ebp
unsigned int v2; // ebx
int v3; // eax
char v5[16]; // [rsp+0h] [rbp-D8h] BYREF
char s[32]; // [rsp+10h] [rbp-C8h] BYREF
struct stat v7; // [rsp+30h] [rbp-A8h] BYREF

sprintf(s, "/sys/class/gpio/gpio%d", a1);
v1 = sprintf(v5, "%d", a1);
v2 = stat(s, &v7);
if ( v2 )
{
if ( *_errno_location() == 2 )
{
v3 = open("/sys/class/gpio/export", 1);
v2 = v3;
if ( v3 == -1 )
{
perror("/sys/class/gpio/export");
}
else if ( write(v3, v5, v1) == v1 )
{
close(v2);
v2 = -(stat(s, &v7) != 0);
}
else
{
close(v2);
perror("/sys/class/gpio/export");
v2 = -1;
}
}
else
{
perror(s);
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // ebp
unsigned int v2; // ebx
int v3; // eax
char v5[16]; // [rsp+0h] [rbp-D8h] BYREF
char s[32]; // [rsp+10h] [rbp-C8h] BYREF
struct stat v7; // [rsp+30h] [rbp-A8h] BYREF

sprintf(s, "/sys/class/gpio/gpio%d", a1);
v1 = sprintf(v5, "%d", a1);
v2 = stat(s, &v7);
if ( v2 )
{
if ( *_errno_location() == 2 )
{
v3 = open("/sys/class/gpio/export", 1);
v2 = v3;
if ( v3 == -1 )
{
perror("/sys/class/gpio/export");
}
else if ( write(v3, v5, v1) == v1 )
{
close(v2);
v2 = -(stat(s, &v7) != 0);
}
else
{
close(v2);
perror("/sys/class/gpio/export");
v2 = -1;
}
}
else
{
perror(s);
v2 = -1;
}
}
return v2;
}

original_code:
static int export_gpio(int ngpio){
 struct stat ss;
 char gpio_dir[32],nstr[16];
 int nlen,fd;
 sprintf(gpio_dir,GPIO_DIR_FMT,ngpio);
 nlen = sprintf(nstr,"%d",ngpio);
 if(stat(gpio_dir,&ss) == 0)
  return 0;
 if((*__errno_location ()) != 2){
  perror(gpio_dir);
  return -1;
 }
 fd = open(GPIO_EXPORT,01);
 if(fd == -1){
  perror(GPIO_EXPORT);
  return -1;
 }
 if(write(fd,nstr,nlen) != nlen){
  close(fd);
  perror(GPIO_EXPORT);
  return -1;
 }
 close(fd);
 if(stat(gpio_dir,&ss) == 0)
  return 0;
 return -1;
}

canonical_original_code:
static int export_gpio(int ngpio){
 struct stat ss;
 char gpio_dir[32]; char nstr[16];
 int nlen; int fd;
 sprintf(gpio_dir,GPIO_DIR_FMT,ngpio);
 nlen = sprintf(nstr,"%d",ngpio);
 if(stat(gpio_dir,&ss) == 0)
  return 0;
 if((*__errno_location ()) != 2){
  perror(gpio_dir);
  return -1;
 }
 fd = open(GPIO_EXPORT,01);
 if(fd == -1){
  perror(GPIO_EXPORT);
  return -1;
 }
 if(write(fd,nstr,nlen) != nlen){
  close(fd);
  perror(GPIO_EXPORT);
  return -1;
 }
 close(fd);
 if(stat(gpio_dir,&ss) == 0)
  return 0;
 return -1;
}

variable_types: ngpio int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
nstr
char [16]

variable_types: nlen int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void __fastcall sysfs_gpio_close(void *ptr)
{
int v2; // edi
int v3; // edi
int v4; // edi

v2 = *((_DWORD *)ptr + 1);
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 2);
if ( v3 != -1 )
close(v3);
v4 = *((_DWORD *)ptr + 3);
if ( v4 != -1 )
close(v4);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
int v2; // edi
int v3; // edi
int v4; // edi

v2 = *((_DWORD *)ptr + 1);
if ( v2 != -1 )
close(v2);
v3 = *((_DWORD *)ptr + 2);
if ( v3 != -1 )
close(v3);
v4 = *((_DWORD *)ptr + 3);
if ( v4 != -1 )
close(v4);
free(ptr);
}

original_code:
void
sysfs_gpio_close(struct sysfs_gpio *p){
 if(p->dir_fd != -1)
  close(p->dir_fd);
 if(p->value_fd != -1)
  close(p->value_fd);
 if(p->direction_fd != -1)
  close(p->direction_fd);
 free(p);
}

variable_types: struct sysfs_gpio { int ngpio; int dir_fd; int value_fd; int direction_fd; } *

return_type: void


decompiled_code:
__int64 __fastcall sysfs_gpio_value(unsigned int *a1, int a2)
{
unsigned int v2; // ebx
unsigned int v4; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

buf[0] = 48 - ((a2 == 0) - 1);
v2 = a1[2];
if ( v2 == -1
&& (v4 = openat(a1[1], "value", 2),
a1[2] = v4,
fprintf(stderr, "Opened gpio%d value as fd %d.\n", *a1, v4),
v2 = a1[2],
v2 == -1) )
{
perror("value");
fprintf(stderr, "(for gpio %d)\n", *a1);
}
else if ( write(v2, buf, 1uLL) == 1 )
{
v2 = 0;
}
else
{
perror("write()");
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, int a2)
{
unsigned int v2; // ebx
unsigned int v4; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

buf[0] = 48 - ((a2 == 0) - 1);
v2 = a1[2];
if ( v2 == -1
&& (v4 = openat(a1[1], "value", 2),
a1[2] = v4,
fprintf(stderr, "Opened gpio%d value as fd %d.\n", *a1, v4),
v2 = a1[2],
v2 == -1) )
{
perror("value");
fprintf(stderr, "(for gpio %d)\n", *a1);
}
else if ( write(v2, buf, 1uLL) == 1 )
{
v2 = 0;
}
else
{
perror("write()");
v2 = -1;
}
return v2;
}

original_code:
extern int
sysfs_gpio_value(struct sysfs_gpio *p, int value){
 char strval = '0' + !!value;
 if(p->value_fd == -1){
  p->value_fd = openat(p->dir_fd,"value",02);
  fprintf(stderr,"Opened gpio%d value as fd %d.\n",
   p->ngpio,p->value_fd);
 }
 if(p->value_fd == -1){
  perror("value");
  fprintf(stderr,"(for gpio %d)\n",p->ngpio);
  return -1;
 }
 if(write(p->value_fd,&strval,1) != 1){
  perror("write()");
  return -1;
 }
 return 0;
}

variable_types: value int

variable_types: strval char

user_defined_types: struct sysfs_gpio { int ngpio; int dir_fd; int value_fd; int direction_fd; }


decompiled_code:
__int64 __fastcall sysfs_gpio_get_value(unsigned int *a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = a1[2];
if ( v2 == -1
&& (v3 = openat(a1[1], "value", 2),
a1[2] = v3,
fprintf(stderr, "Opened gpio%d value as fd %d.\n", *a1, v3),
v2 = a1[2],
v2 == -1) )
{
perror("value");
fprintf(stderr, "(for gpio %d)\n", *a1);
}
else if ( read(v2, buf, 1uLL) == 1 )
{
if ( buf[0] == 48 )
{
*a2 = 0;
v2 = 0;
}
else
{
v2 = 0;
if ( buf[0] == 49 )
*a2 = 1;
}
}
else
{
perror("read()");
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = a1[2];
if ( v2 == -1
&& (v3 = openat(a1[1], "value", 2),
a1[2] = v3,
fprintf(stderr, "Opened gpio%d value as fd %d.\n", *a1, v3),
v2 = a1[2],
v2 == -1) )
{
perror("value");
fprintf(stderr, "(for gpio %d)\n", *a1);
}
else if ( read(v2, buf, 1uLL) == 1 )
{
if ( buf[0] == 48 )
{
*a2 = 0;
v2 = 0;
}
else
{
v2 = 0;
if ( buf[0] == 49 )
*a2 = 1;
}
}
else
{
perror("read()");
v2 = -1;
}
return v2;
}

original_code:
extern int
sysfs_gpio_get_value(struct sysfs_gpio *p, int *value){
 char strval;
 if(p->value_fd == -1){
  p->value_fd = openat(p->dir_fd,"value",02);
  fprintf(stderr,"Opened gpio%d value as fd %d.\n",
   p->ngpio,p->value_fd);
 }
 if(p->value_fd == -1){
  perror("value");
  fprintf(stderr,"(for gpio %d)\n",p->ngpio);
  return -1;
 }
 if(read(p->value_fd,&strval,1) != 1){
  perror("read()");
  return -1;
 }
 if(strval == '0')
  *value = 0;
 if(strval == '1')
  *value = 1;
 return 0;
}

variable_types:
value
int *


decompiled_code:
__int64 __fastcall sysfs_gpio_direction(unsigned int *a1, int a2)
{
unsigned int v2; // ebx
size_t v3; // rbp
unsigned int v5; // eax

v2 = a1[3];
if ( v2 == -1
&& (v5 = openat(a1[1], "direction", 2),
a1[3] = v5,
fprintf(stderr, "Opened gpio%d direction as fd %d.\n", *a1, v5),
v2 = a1[3],
v2 == -1) )
{
perror("direction");
fprintf(stderr, "(for gpio %d)\n", *a1);
}
else
{
v3 = len_1[a2 != 0];
if ( write(v2, words_0[a2 != 0], v3) == v3 )
{
v2 = 0;
}
else
{
perror("direction");
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2)
{
unsigned int v2; // ebx
size_t v3; // rbp
unsigned int v5; // eax

v2 = a1[3];
if ( v2 == -1
&& (v5 = openat(a1[1], "direction", 2),
a1[3] = v5,
fprintf(stderr, "Opened gpio%d direction as fd %d.\n", *a1, v5),
v2 = a1[3],
v2 == -1) )
{
perror("direction");
fprintf(stderr, "(for gpio %d)\n", *a1);
}
else
{
v3 = len_1[a2 != 0];
if ( write(v2, words_0[a2 != 0], v3) == v3 )
{
v2 = 0;
}
else
{
perror("direction");
v2 = -1;
}
}
return v2;
}

original_code:
extern int
sysfs_gpio_direction(struct sysfs_gpio *p, int inout){
 static const char *words[2]={ "in", "out" };
 static const int len[2]={ 2, 3 };
 inout = !!inout;
 if(p->direction_fd == -1){
  p->direction_fd = openat(p->dir_fd,"direction",02);
  fprintf(stderr,"Opened gpio%d direction as fd %d.\n",
   p->ngpio,p->direction_fd);
 }
 if(p->direction_fd == -1){
  perror("direction");
  fprintf(stderr,"(for gpio %d)\n",p->ngpio);
  return -1;
 }
 if(write(p->direction_fd,words[inout],len[inout]) != len[inout]){
  perror("direction");
  return -1;
 }
 return 0;
}

canonical_original_code:
extern int sysfs_gpio_direction(struct sysfs_gpio *p, int inout){
 static char *words[2] = { "in", "out" };
 static int len[2] = { 2, 3 };
 inout = !!inout;
 if(p->direction_fd == -1){
  p->direction_fd = openat(p->dir_fd,"direction",02);
  fprintf(stderr,"Opened gpio%d direction as fd %d.\n",
   p->ngpio,p->direction_fd);
 }
 if(p->direction_fd == -1){
  perror("direction");
  fprintf(stderr,"(for gpio %d)\n",p->ngpio);
  return -1;
 }
 if(write(p->direction_fd,words[inout],len[inout]) != len[inout]){
  perror("direction");
  return -1;
 }
 return 0;
}

variable_types: inout int

variable_types:
words
char *[2]

variable_types:
len
int [2]


decompiled_code:
__int64 __fastcall signed_short_from_buf(unsigned __int8 *a1)
{
return *a1 + (a1[1] << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
return *a1 + (a1[1] << 8);
}

original_code:
static short
signed_short_from_buf(unsigned char *buf)
{
 unsigned short us = buf[0]+(buf[1]<<8);
 return *((short*)&us);
}

canonical_original_code:
static short signed_short_from_buf(unsigned char *buf)
{
 unsigned short us = buf[0]+(buf[1]<<8);
 return *((short *)&us);
}

variable_types:
buf
unsigned char *

variable_types:
us
unsigned short

return_type: short


repo: vogon/hear-and-now

decompiled_code:
float *__fastcall hn_fngen_create(__int64 a1, float a2, __m128i a3)
{
float *result; // rax
float v4; // xmm0_4

result = (float *)calloc(1uLL, 0x10uLL);
*(_QWORD *)result = a1;
v4 = a2 * 6.283185307179586 / 44100.0;
result[3] = v4;
*((_DWORD *)result + 2) = _mm_cvtsi128_si32(a3);
return result;
}

canonical_decompiled_code:
float *__fastcall func0(__int64 a1, float a2, __m128i a3)
{
float *result; // rax
float v4; // xmm0_4

result = (float *)calloc(1uLL, 0x10uLL);
*(_QWORD *)result = a1;
v4 = a2 * 6.283185307179586 / 44100.0;
result[3] = v4;
*((_DWORD *)result + 2) = _mm_cvtsi128_si32(a3);
return result;
}

original_code:
HnFunctionGenerator *hn_fngen_create(HnFunction function, float frequency, float theta0)
{
    HnFunctionGenerator *pGenerator =
        (HnFunctionGenerator *)calloc(1, sizeof(HnFunctionGenerator));
    pGenerator->function = function;
    pGenerator->thetaStep = 2.0f * 3.14159265358979323846 * frequency / 44100;
    pGenerator->nextTheta = theta0;
    return pGenerator;
}

canonical_original_code:
struct HnFunctionGenerator *hn_fngen_create(float (*function)(float theta), float frequency, float theta0)
{
    struct HnFunctionGenerator *pGenerator = (HnFunctionGenerator *)calloc(1, sizeof(HnFunctionGenerator));
    pGenerator->function = function;
    pGenerator->thetaStep = 2.0f * 3.14159265358979323846 * frequency / 44100;
    pGenerator->nextTheta = theta0;
    return pGenerator;
}

variable_types:
function
float (*)(float theta)

variable_types: frequency float

variable_types: struct HnFunctionGenerator { float (*function)(float theta); float nextTheta; } *


decompiled_code:
float __fastcall hn_square(float a1)
{
float result; // xmm0_4

if ( a1 - 3.141592653589793 <= 0.0 )
result = *(float *)&LC3;
else
result = *(float *)&LC2;
return result;
}

canonical_decompiled_code:
float __fastcall func2(float a1)
{
float result; // xmm0_4

if ( a1 - 3.141592653589793 <= 0.0 )
result = *(float *)&LC3;
else
result = *(float *)&LC2;
return result;
}

variable_types: theta float

return_type: float


variable_types: f float


decompiled_code:
float __fastcall hn_sine(float a1)
{
return sin(a1);
}

canonical_decompiled_code:
float __fastcall func5(float a1)
{
return sin(a1);
}

original_code:
float hn_sine(float theta)
{
    return sin(theta);
}


decompiled_code:
void __fastcall hn_mixer_release(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void hn_mixer_release(HnMixer *pMixer)
{
    free(pMixer->pImpl);
    free(pMixer);
}

canonical_original_code:
void hn_mixer_release(struct HnMixer *pMixer)
{
    free(pMixer->pImpl);
    free(pMixer);
}

variable_types:
pMixer
struct HnMixer { void *pImpl; } *


decompiled_code:
pthread_mutex_t *hn_mutex_create()
{
pthread_mutex_t *v0; // rbx

v0 = (pthread_mutex_t *)malloc(0x28uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

canonical_decompiled_code:
pthread_mutex_t *func0()
{
pthread_mutex_t *v0; // rbx

v0 = (pthread_mutex_t *)malloc(0x28uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

original_code:
HnMutex *hn_mutex_create()
{
    HnMutex *result = (HnMutex *)malloc(sizeof(HnMutex));
    pthread_mutex_init(&(result->mutex), ((void *)0));
    return result;
}

canonical_original_code:
struct HnMutex *hn_mutex_create()
{
    struct HnMutex *result = (HnMutex *)malloc(sizeof(HnMutex));
    pthread_mutex_init(&(result->mutex), ((void *)0));
    return result;
}

variable_types: struct HnMutex { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

user_defined_types: struct HnMutex { union pthread_mutex_t mutex; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall hn_mutex_lock(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1);
}

canonical_decompiled_code:
int __fastcall func1(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1);
}

original_code:
void hn_mutex_lock(HnMutex *pMutex)
{
    pthread_mutex_lock(&(pMutex->mutex));
}

canonical_original_code:
void hn_mutex_lock(struct HnMutex *pMutex)
{
    pthread_mutex_lock(&(pMutex->mutex));
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall hn_mutex_unlock(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1);
}

canonical_decompiled_code:
int __fastcall func2(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1);
}

original_code:
void hn_mutex_unlock(HnMutex *pMutex)
{
    pthread_mutex_unlock(&(pMutex->mutex));
}

canonical_original_code:
void hn_mutex_unlock(struct HnMutex *pMutex)
{
    pthread_mutex_unlock(&(pMutex->mutex));
}


decompiled_code:
void __fastcall hn_mutex_destroy(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}

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

original_code:
void hn_mutex_destroy(HnMutex *pMutex)
{
    pthread_mutex_destroy(&(pMutex->mutex));
    free(pMutex);
}

canonical_original_code:
void hn_mutex_destroy(struct HnMutex *pMutex)
{
    pthread_mutex_destroy(&(pMutex->mutex));
    free(pMutex);
}


decompiled_code:
pthread_cond_t *hn_cv_create()
{
pthread_cond_t *v0; // rbx

v0 = (pthread_cond_t *)malloc(0x30uLL);
pthread_cond_init(v0, 0LL);
return v0;
}

canonical_decompiled_code:
pthread_cond_t *func4()
{
pthread_cond_t *v0; // rbx

v0 = (pthread_cond_t *)malloc(0x30uLL);
pthread_cond_init(v0, 0LL);
return v0;
}

original_code:
HnConditionVariable *hn_cv_create()
{
    HnConditionVariable *result =
        (HnConditionVariable *)malloc(sizeof(HnConditionVariable));
    pthread_cond_init(&(result->cv), ((void *)0));
    return result;
}

canonical_original_code:
struct HnConditionVariable *hn_cv_create()
{
    struct HnConditionVariable *result = (HnConditionVariable *)malloc(sizeof(HnConditionVariable));
    pthread_cond_init(&(result->cv), ((void *)0));
    return result;
}

variable_types: struct HnConditionVariable { union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cv; } *

user_defined_types: struct HnConditionVariable { union pthread_cond_t cv; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


decompiled_code:
int __fastcall hn_cv_sleep(pthread_cond_t *a1, pthread_mutex_t *a2)
{
return pthread_cond_wait(a1, a2);
}

canonical_decompiled_code:
int __fastcall func5(pthread_cond_t *a1, pthread_mutex_t *a2)
{
return pthread_cond_wait(a1, a2);
}

original_code:
void hn_cv_sleep(HnConditionVariable *pCv,
                 HnMutex *pLock)
{
    pthread_cond_wait(&(pCv->cv), &(pLock->mutex));
}

canonical_original_code:
void hn_cv_sleep(struct HnConditionVariable *pCv, struct HnMutex *pLock)
{
    pthread_cond_wait(&(pCv->cv), &(pLock->mutex));
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


decompiled_code:
int __fastcall hn_cv_wake(pthread_cond_t *a1)
{
return pthread_cond_signal(a1);
}

canonical_decompiled_code:
int __fastcall func6(pthread_cond_t *a1)
{
return pthread_cond_signal(a1);
}

original_code:
void hn_cv_wake(HnConditionVariable *pCv)
{
    pthread_cond_signal(&(pCv->cv));
}

canonical_original_code:
void hn_cv_wake(struct HnConditionVariable *pCv)
{
    pthread_cond_signal(&(pCv->cv));
}


decompiled_code:
void *hn_cmd_queue_create()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
HnCmdQueue *hn_cmd_queue_create()
{
    HnCmdQueue *pQueue = (HnCmdQueue *)calloc(1, sizeof(HnCmdQueue));
    return pQueue;
}

canonical_original_code:
struct HnCmdQueue *hn_cmd_queue_create()
{
    struct HnCmdQueue *pQueue = (HnCmdQueue *)calloc(1, sizeof(HnCmdQueue));
    return pQueue;
}

variable_types: struct HnCmdQueue { struct HnCmdQueueTag { struct HnCmd { unsigned int sample; enum HnCmdCode { CmdNoteOn=1, CmdNoteOff=2 } code; } *pCmd; struct HnCmdQueueTag *pNext; } *pFirst; } *

user_defined_types: struct HnCmdQueue { struct HnCmdQueueTag *pFirst; }

user_defined_types: struct HnCmdQueueTag { struct HnCmd *pCmd; struct HnCmdQueueTag *pNext; }

user_defined_types: struct HnCmd { unsigned int sample; enum HnCmdCode code; }


original_code:
HnCmd *hn_cmd_queue_pop(HnCmdQueue *pQueue)
{
    HnCmdQueueTag *pTag = pQueue->pFirst;
    if (((void *)0) == pTag)
    {
        return ((void *)0);
    }
    else
    {
        if (((void *)0) == pTag->pNext)
        {
            pQueue->pLast = ((void *)0);
        }
        pQueue->pFirst = pTag->pNext;
        HnCmd *pCmd = pTag->pCmd;
        free(pTag);
        return pCmd;
    }
}

canonical_original_code:
struct HnCmd *hn_cmd_queue_pop(struct HnCmdQueue *pQueue)
{
    struct HnCmdQueueTag *pTag = pQueue->pFirst;
    if (((void *)0) == pTag)
    {
        return ((void *)0);
    }
    else
    {
        if (((void *)0) == pTag->pNext)
        {
            pQueue->pLast = ((void *)0);
        }
        pQueue->pFirst = pTag->pNext;
        struct HnCmd *pCmd = pTag->pCmd;
        free(pTag);
        return pCmd;
    }
}

variable_types: struct HnCmdQueue { struct HnCmdQueueTag { struct HnCmd *pCmd; struct HnCmdQueueTag *pNext; } *pFirst; } *

variable_types: struct HnCmdQueueTag { struct HnCmd { unsigned int sample; enum HnCmdCode { CmdNoteOn=1, CmdNoteOff=2 } code; } *pCmd; struct HnCmdQueueTag *pNext; } *


decompiled_code:
float __fastcall up_12tet(unsigned __int8 a1, float a2)
{
return powf(2.0, (float)a1 / 12.0) * a2;
}

canonical_decompiled_code:
float __fastcall func0(unsigned __int8 a1, float a2)
{
return powf(2.0, (float)a1 / 12.0) * a2;
}

original_code:
extern inline float up_12tet(float root, uint8_t semitones)
{
    return root * powf(2.0f, (float)semitones / 12.);
}

canonical_original_code:
extern inline float up_12tet(float root, unsigned char semitones)
{
    return root * powf(2.0f, (float)semitones / 12.);
}

variable_types: root float

variable_types:
semitones
unsigned char


repo: vokbuz/libjq

decompiled_code:
void jq_queue_quit_proc()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void jq_queue_quit_proc( void* context ) {
}

canonical_original_code:
static void jq_queue_quit_proc(void *context) {
}

variable_types:
context
void *


original_code:
void jq_object_init( jq_object* obj, jq_object_vtable* vtable ) {
  obj->magic = 0xFADEDFAC;
  obj->refs = 1;
  obj->vtable = vtable;
}

canonical_original_code:
void jq_object_init(struct jq_object *obj, struct jq_object_vtable *vtable) {
  obj->magic = 0xFADEDFAC;
  obj->refs = 1;
  obj->vtable = vtable;
}

variable_types: struct jq_object { int magic; struct jq_object_vtable { void (*destroy)(void *); } *vtable; unsigned long refs; } *

variable_types:
vtable
struct jq_object_vtable *

user_defined_types: struct jq_object { int magic; struct jq_object_vtable *vtable; unsigned long refs; }


decompiled_code:
volatile signed __int64 *__fastcall jq_retain(_DWORD *a1)
{
volatile signed __int64 *result; // rax

result = (volatile signed __int64 *)jq_object_get(a1);
if ( result )
_InterlockedAdd64(result + 2, 1uLL);
return result;
}

canonical_decompiled_code:
volatile signed __int64 *__fastcall func1(_DWORD *a1)
{
volatile signed __int64 *result; // rax

result = (volatile signed __int64 *)jq_object_get(a1);
if ( result )
_InterlockedAdd64(result + 2, 1uLL);
return result;
}

original_code:
void jq_retain( void* ptr ) {
  jq_object* obj = jq_object_get( ptr );
  if( !obj ) return;
  __sync_fetch_and_add( (&obj->refs), (1) );
}

canonical_original_code:
void jq_retain(void *ptr) {
  struct jq_object *obj = jq_object_get( ptr );
  if( !obj ) return;
  __sync_fetch_and_add( (&obj->refs), (1) );
}

variable_types:
ptr
void *

user_defined_types: struct jq_object_vtable { void (*destroy)(void *); }


decompiled_code:
_BOOL8 __fastcall jq_once(volatile signed __int32 *a1)
{
return _InterlockedCompareExchange(a1, 1, 0) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(volatile signed __int32 *a1)
{
return _InterlockedCompareExchange(a1, 1, 0) == 0;
}

original_code:
int jq_once( jq_once_t* once ) {
  return __sync_val_compare_and_swap( (once), (0), (1) ) == 0;
}

canonical_original_code:
int jq_once(int *once) {
  return __sync_val_compare_and_swap( (once), (0), (1) ) == 0;
}

variable_types:
once
int *


decompiled_code:
__int64 __fastcall pthread_spin_init(_DWORD *a1)
{
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
*a1 = 0;
return 0LL;
}

original_code:
int pthread_spin_init( pthread_spinlock_t* lock, int pshared ) {
  if( !lock ) return 22;
  *lock = 0;
  return 0;
}

canonical_original_code:
int pthread_spin_init(int *lock, int pshared) {
  if( !lock ) return 22;
  *lock = 0;
  return 0;
}

variable_types:
lock
int *

variable_types: pshared int


decompiled_code:
__int64 pthread_spin_destroy()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0LL;
}

original_code:
int pthread_spin_destroy( pthread_spinlock_t* lock ) {
  return 0;
}

canonical_original_code:
int pthread_spin_destroy(int *lock) {
  return 0;
}


decompiled_code:
__int64 __fastcall pthread_spin_lock(volatile signed __int32 *a1)
{
while ( _InterlockedCompareExchange(a1, 1, 0) )
sched_yield();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(volatile signed __int32 *a1)
{
while ( _InterlockedCompareExchange(a1, 1, 0) )
sched_yield();
return 0LL;
}

original_code:
int pthread_spin_lock( pthread_spinlock_t* lock ) {
  while( 1 ) {
    if( __sync_val_compare_and_swap( (lock), (0), (1) ) == 0 )
      break;
    sched_yield();
  }
  return 0;
}

canonical_original_code:
int pthread_spin_lock(int *lock) {
  while( 1 ) {
    if( __sync_val_compare_and_swap( (lock), (0), (1) ) == 0 )
      break;
    sched_yield();
  }
  return 0;
}


decompiled_code:
__int64 __fastcall pthread_spin_trylock(volatile signed __int32 *a1)
{
return 16 * (unsigned int)(_InterlockedCompareExchange(a1, 1, 0) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(volatile signed __int32 *a1)
{
return 16 * (unsigned int)(_InterlockedCompareExchange(a1, 1, 0) != 0);
}

original_code:
int pthread_spin_trylock( pthread_spinlock_t* lock ) {
  return (__sync_val_compare_and_swap( (lock), (0), (1) ) == 0) ? 0 : 16;
}

canonical_original_code:
int pthread_spin_trylock(int *lock) {
  return (__sync_val_compare_and_swap( (lock), (0), (1) ) == 0) ? 0 : 16;
}


decompiled_code:
__int64 __fastcall pthread_spin_unlock(volatile signed __int32 *a1)
{
_InterlockedCompareExchange(a1, 0, 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(volatile signed __int32 *a1)
{
_InterlockedCompareExchange(a1, 0, 1);
return 0LL;
}

original_code:
int pthread_spin_unlock( pthread_spinlock_t* lock ) {
  __sync_val_compare_and_swap( (lock), (1), (0) );
  return 0;
}

canonical_original_code:
int pthread_spin_unlock(int *lock) {
  __sync_val_compare_and_swap( (lock), (1), (0) );
  return 0;
}


decompiled_code:
int __fastcall jq_group_vtable_destroy(__int64 a1)
{
pthread_cond_destroy((pthread_cond_t *)(a1 + 64));
return pthread_mutex_destroy((pthread_mutex_t *)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
pthread_cond_destroy((pthread_cond_t *)(a1 + 64));
return pthread_mutex_destroy((pthread_mutex_t *)(a1 + 24));
}

original_code:
static void jq_group_vtable_destroy( void* object ) {
  jq_group* group = (jq_group*)object;
  pthread_cond_destroy( &group->cond );
  pthread_mutex_destroy( &group->mutex );
}

canonical_original_code:
static void jq_group_vtable_destroy(void *object) {
  struct jq_group *group = (jq_group*)object;
  pthread_cond_destroy( &group->cond );
  pthread_mutex_destroy( &group->mutex );
}

variable_types:
object
void *

variable_types: struct jq_group { struct jq_object { int magic; struct jq_object_vtable { void (*destroy)(void *); } *vtable; unsigned long refs; } object; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; unsigned long members; } *

user_defined_types: struct jq_group { struct jq_object object; union pthread_mutex_t mutex; union pthread_cond_t cond; unsigned long members; }


decompiled_code:
_QWORD *jq_group_create()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = (_QWORD *)jq_fsa_alloc(&group_allocator);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[14] = 0LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 120) >> 3));
jq_object_init(v0, group_vtable);
if ( pthread_mutex_init((pthread_mutex_t *)(v1 + 3), 0LL) || pthread_cond_init((pthread_cond_t *)(v1 + 8), 0LL) )
{
jq_fsa_free(&group_allocator, v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = (_QWORD *)jq_fsa_alloc(&group_allocator);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[14] = 0LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 120) >> 3));
jq_object_init(v0, group_vtable);
if ( pthread_mutex_init((pthread_mutex_t *)(v1 + 3), 0LL) || pthread_cond_init((pthread_cond_t *)(v1 + 8), 0LL) )
{
jq_fsa_free(&group_allocator, v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
jq_group_t jq_group_create() {
  jq_group_t group = (jq_group_t)jq_fsa_alloc( &group_allocator );
  if( group ) {
    memset( group, 0, sizeof(*group) );
    jq_object_init( &group->object, &group_vtable );
    if( pthread_mutex_init( &group->mutex, ((void *)0) ) != 0 )
      goto fail;
    if( pthread_cond_init( &group->cond, ((void *)0) ) != 0 )
      goto fail;
  }
  return group;
fail:
  jq_fsa_free( &group_allocator, group );
  return ((void *)0);
}

canonical_original_code:
struct jq_group *jq_group_create() {
  struct jq_group *group = (jq_group_t)jq_fsa_alloc( &group_allocator );
  if( group ) {
    memset( group, 0, sizeof(*group) );
    jq_object_init( &group->object, &group_vtable );
    if( pthread_mutex_init( &group->mutex, ((void *)0) ) != 0 )
      goto fail;
    if( pthread_cond_init( &group->cond, ((void *)0) ) != 0 )
      goto fail;
  }
  return group;
fail:
  jq_fsa_free( &group_allocator, group );
  return ((void *)0);
}

return_type: struct jq_group { struct jq_object { int magic; struct jq_object_vtable { void (*destroy)(void *); } *vtable; unsigned long refs; } object; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; unsigned long members; } *


decompiled_code:
int __fastcall jq_group_enter(__int64 a1)
{
int result; // eax

if ( a1 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
++*(_QWORD *)(a1 + 112);
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int result; // eax

if ( a1 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
++*(_QWORD *)(a1 + 112);
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

original_code:
void jq_group_enter( jq_group_t group ) {
  if( !group ) return;
  pthread_mutex_lock( &group->mutex );
  group->members++;
  pthread_mutex_unlock( &group->mutex );
}

canonical_original_code:
void jq_group_enter(struct jq_group *group) {
  if( !group ) return;
  pthread_mutex_lock( &group->mutex );
  group->members++;
  pthread_mutex_unlock( &group->mutex );
}


decompiled_code:
int __fastcall jq_group_leave(__int64 a1)
{
__int64 v1; // rax
int result; // eax

if ( a1 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_QWORD *)(a1 + 112);
*(_QWORD *)(a1 + 112) = v1 - 1;
if ( v1 == 1 )
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

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

if ( a1 )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_QWORD *)(a1 + 112);
*(_QWORD *)(a1 + 112) = v1 - 1;
if ( v1 == 1 )
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
return result;
}

original_code:
void jq_group_leave( jq_group_t group ) {
  if( !group ) return;
  pthread_mutex_lock( &group->mutex );
  if( group->members-- == 1 ) {
    pthread_cond_signal( &group->cond );
  }
  pthread_mutex_unlock( &group->mutex );
}

canonical_original_code:
void jq_group_leave(struct jq_group *group) {
  if( !group ) return;
  pthread_mutex_lock( &group->mutex );
  if( group->members-- == 1 ) {
    pthread_cond_signal( &group->cond );
  }
  pthread_mutex_unlock( &group->mutex );
}


decompiled_code:
int __fastcall jq_group_wait(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int result; // eax

if ( a1 )
{
v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
while ( *(_QWORD *)(a1 + 112) )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
result = pthread_mutex_unlock(v1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int result; // eax

if ( a1 )
{
v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
while ( *(_QWORD *)(a1 + 112) )
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
result = pthread_mutex_unlock(v1);
}
return result;
}

original_code:
void jq_group_wait( jq_group_t group ) {
  if( !group ) return;
  pthread_mutex_lock( &group->mutex );
  while( group->members != 0 ) {
    pthread_cond_wait( &group->cond, &group->mutex );
  }
  pthread_mutex_unlock( &group->mutex );
}

canonical_original_code:
void jq_group_wait(struct jq_group *group) {
  if( !group ) return;
  pthread_mutex_lock( &group->mutex );
  while( group->members != 0 ) {
    pthread_cond_wait( &group->cond, &group->mutex );
  }
  pthread_mutex_unlock( &group->mutex );
}


decompiled_code:
int __fastcall jq_fsa_init(__int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
if ( a2 < 8 )
a2 = 8LL;
*(_QWORD *)a1 = a2;
if ( a3 < 8 )
a3 = 8LL;
*(_QWORD *)(a1 + 8) = a3;
return pthread_spin_init((pthread_spinlock_t *)(a1 + 32), 0);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
if ( a2 < 8 )
a2 = 8LL;
*(_QWORD *)a1 = a2;
if ( a3 < 8 )
a3 = 8LL;
*(_QWORD *)(a1 + 8) = a3;
return pthread_spin_init((pthread_spinlock_t *)(a1 + 32), 0);
}

original_code:
void jq_fsa_init( jq_fsa* fsa, size_t size, size_t blocks_per_chunk ) {
  memset( fsa, 0, sizeof(jq_fsa) );
  fsa->size = size < sizeof(void*) ? sizeof(void*) : size;
  fsa->blocks_per_chunk = blocks_per_chunk < 8 ? 8 : blocks_per_chunk;
  pthread_spin_init( &fsa->lock, 0 );
}

canonical_original_code:
void jq_fsa_init(struct jq_fsa *fsa, unsigned long size, unsigned long blocks_per_chunk) {
  memset( fsa, 0, sizeof(jq_fsa) );
  fsa->size = size < sizeof(void *) ? sizeof(void *) : size;
  fsa->blocks_per_chunk = blocks_per_chunk < 8 ? 8 : blocks_per_chunk;
  pthread_spin_init( &fsa->lock, 0 );
}

variable_types: struct jq_fsa { unsigned long size; unsigned long blocks_per_chunk; void *first_chunk; void *first_free; int lock; } *

variable_types:
size
unsigned long


decompiled_code:
int __fastcall jq_fsa_destroy(__int64 a1)
{
jq_fsa_dealloc_chunks(a1);
return pthread_spin_destroy((pthread_spinlock_t *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
func0(a1);
return pthread_spin_destroy((pthread_spinlock_t *)(a1 + 32));
}

original_code:
void jq_fsa_destroy( jq_fsa* fsa ) {
  jq_fsa_dealloc_chunks( fsa );
  pthread_spin_destroy( &fsa->lock );
}

canonical_original_code:
void jq_fsa_destroy(struct jq_fsa *fsa) {
  jq_fsa_dealloc_chunks( fsa );
  pthread_spin_destroy( &fsa->lock );
}

user_defined_types: struct jq_fsa { unsigned long size; unsigned long blocks_per_chunk; void *first_chunk; void *first_free; int lock; }


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

if ( a2 )
{
pthread_spin_lock((pthread_spinlock_t *)(a1 + 32));
*a2 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = a2;
result = pthread_spin_unlock((pthread_spinlock_t *)(a1 + 32));
}
return result;
}

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

if ( a2 )
{
pthread_spin_lock((pthread_spinlock_t *)(a1 + 32));
*a2 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 24) = a2;
result = pthread_spin_unlock((pthread_spinlock_t *)(a1 + 32));
}
return result;
}

original_code:
void jq_fsa_free( jq_fsa* fsa, void* ptr ) {
  if( !ptr ) return;
  pthread_spin_lock( &fsa->lock );
  (*(void**)(ptr)) = fsa->first_free;
  fsa->first_free = ptr;
  pthread_spin_unlock( &fsa->lock );
}

canonical_original_code:
void jq_fsa_free(struct jq_fsa *fsa, void *ptr) {
  if( !ptr ) return;
  pthread_spin_lock( &fsa->lock );
  (*(void **)(ptr)) = fsa->first_free;
  fsa->first_free = ptr;
  pthread_spin_unlock( &fsa->lock );
}


decompiled_code:
int __fastcall jq_fsa_free_all(__int64 a1)
{
pthread_spin_lock((pthread_spinlock_t *)(a1 + 32));
jq_fsa_dealloc_chunks(a1);
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
return pthread_spin_unlock((pthread_spinlock_t *)(a1 + 32));
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
pthread_spin_lock((pthread_spinlock_t *)(a1 + 32));
func0(a1);
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
return pthread_spin_unlock((pthread_spinlock_t *)(a1 + 32));
}

original_code:
void jq_fsa_free_all( jq_fsa* fsa ) {
  pthread_spin_lock( &fsa->lock );
  jq_fsa_dealloc_chunks( fsa );
  fsa->first_free = ((void *)0);
  fsa->first_chunk = ((void *)0);
  pthread_spin_unlock( &fsa->lock );
}

canonical_original_code:
void jq_fsa_free_all(struct jq_fsa *fsa) {
  pthread_spin_lock( &fsa->lock );
  jq_fsa_dealloc_chunks( fsa );
  fsa->first_free = ((void *)0);
  fsa->first_chunk = ((void *)0);
  pthread_spin_unlock( &fsa->lock );
}


HashBytes

repo: voku/snappy

decompiled_code:
__int64 __fastcall HashBytes(int a1, char a2)
{
return (unsigned int)(506832829 * a1) >> a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char a2)
{
return (unsigned int)(506832829 * a1) >> a2;
}

original_code:
static inline uint32_t HashBytes(uint32_t bytes, int shift)
{
 uint32_t kMul = 0x1e35a7bd;
 return (bytes * kMul) >> shift;
}

canonical_original_code:
static inline unsigned int HashBytes(unsigned int bytes, int shift)
{
 unsigned int kMul = 0x1e35a7bd;
 return (bytes * kMul) >> shift;
}

variable_types:
bytes
unsigned int

variable_types: shift int

variable_types:
kMul
unsigned int

return_type: unsigned int


Hash

decompiled_code:
__int64 __fastcall Hash(int *a1, char a2)
{
return HashBytes(*a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, char a2)
{
return func1(*a1, a2);
}

original_code:
static inline uint32_t Hash(const char *p, int shift)
{
 return HashBytes((*(const uint32_t*)(p)), shift);
}

canonical_original_code:
static inline unsigned int Hash(char *p, int shift)
{
 return HashBytes((*(unsigned int *)(p)), shift);
}

variable_types:
p
char *


original_code:
static inline char*
EmitCopyLessThan64(char *op, int offset, int len)
{
 ;
 ;
 ;
 if ((len < 12) && (offset < 2048)) {
  int len_minus_4 = len - 4;
  ;
  *op++ = COPY_1_BYTE_OFFSET +
   ((len_minus_4) << 2) +
   ((offset >> 8) << 5);
  *op++ = offset & 0xff;
 } else {
  *op++ = COPY_2_BYTE_OFFSET + ((len-1) << 2);
  (*(uint16_t*)(op) = (offset));
  op += 2;
 }
 return op;
}

canonical_original_code:
static inline char *EmitCopyLessThan64(char *op, int offset, int len)
{
 ;
 ;
 ;
 if ((len < 12) && (offset < 2048)) {
  int len_minus_4 = len - 4;
  ;
  *op++ = COPY_1_BYTE_OFFSET +
   ((len_minus_4) << 2) +
   ((offset >> 8) << 5);
  *op++ = offset & 0xff;
 } else {
  *op++ = COPY_2_BYTE_OFFSET + ((len-1) << 2);
  (*(unsigned short *)(op) = (offset));
  op += 2;
 }
 return op;
}

variable_types:
op
char *

variable_types: offset int

variable_types: len int

return_type: char *


EmitCopy

decompiled_code:
__int64 __fastcall EmitCopy(__int64 a1, int a2, int a3)
{
int v3; // er12
int i; // ebx

v3 = a3;
if ( a3 > 67 )
{
for ( i = a3; i > 67; i -= 64 )
a1 = EmitCopyLessThan64(a1, a2, 64);
v3 = v3 - ((v3 - 68) & 0xFFFFFFC0) - 64;
}
if ( v3 > 64 )
{
a1 = EmitCopyLessThan64(a1, a2, 60);
v3 -= 60;
}
return EmitCopyLessThan64(a1, a2, v3);
}

original_code:
static inline char*
EmitCopy(char *op, int offset, int len)
{
 while (len >= 68) {
  op = EmitCopyLessThan64(op, offset, 64);
  len -= 64;
 }
 if (len > 64) {
  op = EmitCopyLessThan64(op, offset, 60);
  len -= 60;
 }
 op = EmitCopyLessThan64(op, offset, len);
 return op;
}

canonical_original_code:
static inline char *EmitCopy(char *op, int offset, int len)
{
 while (len >= 68) {
  op = EmitCopyLessThan64(op, offset, 64);
  len -= 64;
 }
 if (len > 64) {
  op = EmitCopyLessThan64(op, offset, 60);
  len -= 60;
 }
 op = EmitCopyLessThan64(op, offset, len);
 return op;
}


GetEightBytesAt

decompiled_code:
__int64 __fastcall GetEightBytesAt(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
static inline EightBytesReference GetEightBytesAt(const char* ptr) {
 return (*(const uint64_t*)(ptr));
}

canonical_original_code:
static inline unsigned long GetEightBytesAt(char *ptr) {
 return (*(unsigned long *)(ptr));
}

variable_types:
ptr
char *

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall GetUint32AtOffset(unsigned __int64 a1, char a2)
{
return a1 >> (8 * a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(unsigned __int64 a1, char a2)
{
return a1 >> (8 * a2);
}

original_code:
static inline uint32_t GetUint32AtOffset(uint64_t v, int offset) {
 ;
 ;
 return v >> (8 * offset);
}

canonical_original_code:
static inline unsigned int GetUint32AtOffset(unsigned long v, int offset) {
 ;
 ;
 return v >> (8 * offset);
}

variable_types:
v
unsigned long


decompiled_code:
__int64 __fastcall FindLSBSetNonZero64(__int64 _RDI)
{
__int64 result; // rax

__asm { tzcnt rax, rdi }
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 _RDI)
{
__int64 result; // rax

__asm { tzcnt rax, rdi }
return result;
}

original_code:
static inline int FindLSBSetNonZero64(uint64_t n)
{
 return __builtin_ctzll(n);
}

canonical_original_code:
static inline int FindLSBSetNonZero64(unsigned long n)
{
 return __builtin_ctzll(n);
}

variable_types:
n
unsigned long


FindMatchLength

decompiled_code:
__int64 __fastcall FindMatchLength(_QWORD *a1, _QWORD *a2, unsigned __int64 a3)
{
_QWORD *v3; // r9
unsigned int v4; // ebx
unsigned __int64 v6; // rdx
__int64 v7; // rcx
char *v8; // rsi

if ( a3 - 8 < (unsigned __int64)a2 )
{
v4 = 0;
LABEL_9:
if ( (unsigned __int64)a2 < a3 )
{
v6 = (int)v4 + a3 - (_QWORD)a2;
v7 = (int)v4;
v8 = (char *)a2 - (int)v4;
do
{
v4 = v7;
if ( *((_BYTE *)a1 + v7) != v8[v7] )
break;
v4 = ++v7;
}
while ( v7 != v6 );
}
}
else
{
v3 = a1;
v4 = 0;
while ( *v3 == *a2 )
{
++a2;
v4 += 8;
++v3;
if ( a3 - 8 < (unsigned __int64)a2 )
goto LABEL_9;
}
v4 += (int)FindLSBSetNonZero64(*a2 ^ *v3) >> 3;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, _QWORD *a2, unsigned __int64 a3)
{
_QWORD *v3; // r9
unsigned int v4; // ebx
unsigned __int64 v6; // rdx
__int64 v7; // rcx
char *v8; // rsi

if ( a3 - 8 < (unsigned __int64)a2 )
{
v4 = 0;
LABEL_9:
if ( (unsigned __int64)a2 < a3 )
{
v6 = (int)v4 + a3 - (_QWORD)a2;
v7 = (int)v4;
v8 = (char *)a2 - (int)v4;
do
{
v4 = v7;
if ( *((_BYTE *)a1 + v7) != v8[v7] )
break;
v4 = ++v7;
}
while ( v7 != v6 );
}
}
else
{
v3 = a1;
v4 = 0;
while ( *v3 == *a2 )
{
++a2;
v4 += 8;
++v3;
if ( a3 - 8 < (unsigned __int64)a2 )
goto LABEL_9;
}
v4 += (int)func7(*a2 ^ *v3) >> 3;
}
return v4;
}

original_code:
static inline int
FindMatchLength(const char *s1, const char *s2, const char *s2_limit)
{
 uint64_t x;
 int matched, matching_bits;
 ;
 matched = 0;
 while (__builtin_expect(!!(s2 <= s2_limit - 8), 1)) {
  if (__builtin_expect(!!((*(const uint64_t*)(s1 + matched)) == (*(const uint64_t*)(s2))), 0)) {
   s2 += 8;
   matched += 8;
  } else {
   x = (*(const uint64_t*)(s1 + matched)) ^
    (*(const uint64_t*)(s2));
   matching_bits = FindLSBSetNonZero64(x);
   matched += matching_bits >> 3;
   return matched;
  }
 }
 while (__builtin_expect(!!(s2 < s2_limit), 1)) {
  if (__builtin_expect(!!(s1[matched] == *s2), 1)) {
   ++s2;
   ++matched;
  } else {
   return matched;
  }
 }
 return matched;
}

canonical_original_code:
static inline int FindMatchLength(char *s1, char *s2, char *s2_limit)
{
 unsigned long x;
 int matched; int matching_bits;
 ;
 matched = 0;
 while (__builtin_expect(!!(s2 <= s2_limit - 8), 1)) {
  if (__builtin_expect(!!((*(unsigned long *)(s1 + matched)) == (*(unsigned long *)(s2))), 0)) {
   s2 += 8;
   matched += 8;
  } else {
   x = (*(unsigned long *)(s1 + matched)) ^
    (*(unsigned long *)(s2));
   matching_bits = FindLSBSetNonZero64(x);
   matched += matching_bits >> 3;
   return matched;
  }
 }
 while (__builtin_expect(!!(s2 < s2_limit), 1)) {
  if (__builtin_expect(!!(s1[matched] == *s2), 1)) {
   ++s2;
   ++matched;
  } else {
   return matched;
  }
 }
 return matched;
}

variable_types:
x
unsigned long

variable_types: matched int


original_code:
char*
csnappy_compress_fragment(
 const char *input,
 const uint32_t input_size,
 char *op,
 void *working_memory,
 const int workmem_bytes_power_of_two)
{
 const char *ip, *ip_end, *base_ip, *next_emit, *ip_limit, *next_ip,
   *candidate, *base;
 uint16_t *table = (uint16_t *)working_memory;
 EightBytesReference input_bytes;
 uint32_t hash, next_hash, prev_hash, cur_hash, skip, candidate_bytes;
 int shift, matched;
 ;
 ;
 shift = 33 - workmem_bytes_power_of_two;
 ip = input;
 ;
 ip_end = input + input_size;
 base_ip = ip;
 next_emit = ip;
 if (__builtin_expect(!!(input_size < 15), 0))
  goto emit_remainder;
 memset(working_memory, 0, 1 << workmem_bytes_power_of_two);
 ip_limit = input + input_size - 15;
 next_hash = Hash(++ip, shift);
main_loop:
 ;
 skip = 32;
 next_ip = ip;
 do {
  ip = next_ip;
  hash = next_hash;
  ;
  next_ip = ip + (skip++ >> 5);
  if (__builtin_expect(!!(next_ip > ip_limit), 0))
   goto emit_remainder;
  next_hash = Hash(next_ip, shift);
  candidate = base_ip + table[hash];
  ;
  ;
  table[hash] = ip - base_ip;
 } while (__builtin_expect(!!((*(const uint32_t*)(ip)) != (*(const uint32_t*)(candidate))), 1));
 ;
 op = EmitLiteral(op, next_emit, ip - next_emit, 1);
 candidate_bytes = 0;
 do {
  base = ip;
  matched = 4 + FindMatchLength(candidate + 4, ip + 4, ip_end);
  ip += matched;
  ;
  op = EmitCopy(op, base - candidate, matched);
  next_emit = ip;
  if (__builtin_expect(!!(ip >= ip_limit), 0))
   goto emit_remainder;
  input_bytes = GetEightBytesAt(ip - 1);
  prev_hash = HashBytes(GetUint32AtOffset(input_bytes, 0), shift);
  table[prev_hash] = ip - base_ip - 1;
  cur_hash = HashBytes(GetUint32AtOffset(input_bytes, 1), shift);
  candidate = base_ip + table[cur_hash];
  candidate_bytes = (*(const uint32_t*)(candidate));
  table[cur_hash] = ip - base_ip;
 } while (GetUint32AtOffset(input_bytes, 1) == candidate_bytes);
 next_hash = HashBytes(GetUint32AtOffset(input_bytes, 2), shift);
 ++ip;
 goto main_loop;
emit_remainder:
 if (next_emit < ip_end)
  op = EmitLiteral(op, next_emit, ip_end - next_emit, 0);
 return op;
}

canonical_original_code:
char *csnappy_compress_fragment(char *input, unsigned int input_size, char *op, void *working_memory, int workmem_bytes_power_of_two)
{
 char *ip; char *ip_end; char *base_ip; char *next_emit; char *ip_limit; char *next_ip; char *candidate; char *base;
 unsigned short *table = (uint16_t *)working_memory;
 unsigned long input_bytes;
 unsigned int hash; unsigned int next_hash; unsigned int prev_hash; unsigned int cur_hash; unsigned int skip; unsigned int candidate_bytes;
 int shift; int matched;
 ;
 ;
 shift = 33 - workmem_bytes_power_of_two;
 ip = input;
 ;
 ip_end = input + input_size;
 base_ip = ip;
 next_emit = ip;
 if (__builtin_expect(!!(input_size < 15), 0))
  goto emit_remainder;
 memset(working_memory, 0, 1 << workmem_bytes_power_of_two);
 ip_limit = input + input_size - 15;
 next_hash = Hash(++ip, shift);
main_loop:
 ;
 skip = 32;
 next_ip = ip;
 do {
  ip = next_ip;
  hash = next_hash;
  ;
  next_ip = ip + (skip++ >> 5);
  if (__builtin_expect(!!(next_ip > ip_limit), 0))
   goto emit_remainder;
  next_hash = Hash(next_ip, shift);
  candidate = base_ip + table[hash];
  ;
  ;
  table[hash] = ip - base_ip;
 } while (__builtin_expect(!!((*(unsigned int *)(ip)) != (*(unsigned int *)(candidate))), 1));
 ;
 op = EmitLiteral(op, next_emit, ip - next_emit, 1);
 candidate_bytes = 0;
 do {
  base = ip;
  matched = 4 + FindMatchLength(candidate + 4, ip + 4, ip_end);
  ip += matched;
  ;
  op = EmitCopy(op, base - candidate, matched);
  next_emit = ip;
  if (__builtin_expect(!!(ip >= ip_limit), 0))
   goto emit_remainder;
  input_bytes = GetEightBytesAt(ip - 1);
  prev_hash = HashBytes(GetUint32AtOffset(input_bytes, 0), shift);
  table[prev_hash] = ip - base_ip - 1;
  cur_hash = HashBytes(GetUint32AtOffset(input_bytes, 1), shift);
  candidate = base_ip + table[cur_hash];
  candidate_bytes = (*(unsigned int *)(candidate));
  table[cur_hash] = ip - base_ip;
 } while (GetUint32AtOffset(input_bytes, 1) == candidate_bytes);
 next_hash = HashBytes(GetUint32AtOffset(input_bytes, 2), shift);
 ++ip;
 goto main_loop;
emit_remainder:
 if (next_emit < ip_end)
  op = EmitLiteral(op, next_emit, ip_end - next_emit, 0);
 return op;
}

variable_types:
input
char *

variable_types:
ip
char *

variable_types:
candidate
char *

variable_types:
base
char *

variable_types:
table
unsigned short *

variable_types:
hash
unsigned int

variable_types:
skip
unsigned int


decompiled_code:
__int64 __fastcall csnappy_max_compressed_length(unsigned int a1)
{
return a1 + a1 / 6 + 32;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
return a1 + a1 / 6 + 32;
}

original_code:
uint32_t __attribute__((const))
csnappy_max_compressed_length(uint32_t source_len)
{
 return 32 + source_len + source_len/6;
}

canonical_original_code:
unsigned int csnappy_max_compressed_length(unsigned int source_len)
{
 return 32 + source_len + source_len/6;
}


usage

repo: volodim/uchat

decompiled_code:
void __noreturn usage()
{
fwrite("uchat: must writting some help, heh :)\n", 1uLL, 0x27uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("uchat: must writting some help, heh :)\n", 1uLL, 0x27uLL, stderr);
exit(1);
}

original_code:
void
usage(void) {
   fprintf(stderr, "uchat: must writting some help, heh :)\n");
   exit(1);
}

canonical_original_code:
void usage() {
   fprintf(stderr, "uchat: must writting some help, heh :)\n");
   exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
fd_set v5; // [rsp+0h] [rbp-20B8h] BYREF
char v6[4096]; // [rsp+80h] [rbp-2038h] BYREF
int v7; // [rsp+1080h] [rbp-1038h]
__int64 buf[517]; // [rsp+1090h] [rbp-1028h] BYREF

buf[0] = 0LL;
buf[1] = 0LL;
memset(&buf[2], 0, 0xFF0uLL);
memset(v6, 0, sizeof(v6));
v7 = 0;
if ( argc > 1 )
{
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "c:n:");
if ( v3 == 1 )
break;
if ( v3 == 63 )
usage();
}
}
running = 1;
puts("uchat starting");
init_gui();
gui_get_input(v6);
while ( running )
{
timeout_0.tv_sec = 0LL;
timeout_0.tv_usec = 10000LL;
memset(&v5, 0, sizeof(v5));
v5.fds_bits[0] |= 1uLL;
if ( Socket >= 0 )
v5.fds_bits[Socket / 64] |= 1LL << (Socket % 64);
if ( select(1024, &v5, 0LL, 0LL, &timeout_0) )
{
if ( (v5.fds_bits[0] & 1) != 0 )
{
gui_get_input(v6);
}
else if ( Socket >= 0 && (v5.fds_bits[Socket / 64] & (1LL << (Socket % 64))) != 0 )
{
memset(buf, 0, 0x1000uLL);
if ( (int)recv(Socket, buf, 0x1000uLL, 0) > 0 )
{
wprintw(mainwin, (const char *)buf);
wrefresh(mainwin);
}
}
}
gui_update_statuswin(0LL);
wmove(inputwin, 0, v7);
wrefresh(inputwin);
}
wclear(stdscr);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
fd_set v5; // [rsp+0h] [rbp-20B8h] BYREF
char v6[4096]; // [rsp+80h] [rbp-2038h] BYREF
int v7; // [rsp+1080h] [rbp-1038h]
__int64 buf[517]; // [rsp+1090h] [rbp-1028h] BYREF

buf[0] = 0LL;
buf[1] = 0LL;
memset(&buf[2], 0, 0xFF0uLL);
memset(v6, 0, sizeof(v6));
v7 = 0;
if ( argc > 1 )
{
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "c:n:");
if ( v3 == 1 )
break;
if ( v3 == 63 )
func0();
}
}
running = 1;
puts("uchat starting");
init_gui();
gui_get_input(v6);
while ( running )
{
timeout_0.tv_sec = 0LL;
timeout_0.tv_usec = 10000LL;
memset(&v5, 0, sizeof(v5));
v5.fds_bits[0] |= 1uLL;
if ( Socket >= 0 )
v5.fds_bits[Socket / 64] |= 1LL << (Socket % 64);
if ( select(1024, &v5, 0LL, 0LL, &timeout_0) )
{
if ( (v5.fds_bits[0] & 1) != 0 )
{
gui_get_input(v6);
}
else if ( Socket >= 0 && (v5.fds_bits[Socket / 64] & (1LL << (Socket % 64))) != 0 )
{
memset(buf, 0, 0x1000uLL);
if ( (int)recv(Socket, buf, 0x1000uLL, 0) > 0 )
{
wprintw(mainwin, (const char *)buf);
wrefresh(mainwin);
}
}
}
gui_update_statuswin(0LL);
wmove(inputwin, 0, v7);
wrefresh(inputwin);
}
wclear(stdscr);
endwin();
return 0;
}

original_code:
int
main(int argc, char *argv[]) {
     int n;
     char buffer[4096] = { 0 };
     InputBufStruct ib;
     fd_set fd;
     static struct timeval timeout;
     int online = 0;
     memset(ib.buffer, 0, 4096);
     ib.pos = 0;
     if(argc > 1) {
     int ch;
      while ((ch = getopt(argc, argv, "c:n:")) != 1) {
       switch (ch) {
         case 'c':
               break;
  case 'n':
               break;
         case '?':
               usage();
       }
      }
     }
   running = 1;
   printf("uchat starting\n");
   init_gui();
   gui_get_input(&ib);
   while(running)
   {
        timeout.tv_sec = 0;
        timeout.tv_usec = 10000;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
        if(Socket >= 0)
             ((void) (((&fd)->__fds_bits)[((Socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((Socket) % (8 * (int) sizeof (__fd_mask)))))));
        if(select(1024, &fd, ((void *)0), ((void *)0), &timeout))
        {
             if(((((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
                  gui_get_input(&ib);
             else
             {
                  if(Socket >= 0 && (((((&fd)->__fds_bits)[((Socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((Socket) % (8 * (int) sizeof (__fd_mask)))))) != 0)))
                  {
                       memset(buffer, 0, 4096);
                       n = recv(Socket, buffer, 4096, 0);
                       if(n > 0)
                       {
                            wprintw(mainwin, buffer);
                            wrefresh(mainwin);
                       }
                  }
             }
        }
        gui_update_statuswin(online);
        wmove(inputwin, 0, ib.pos);
        wrefresh(inputwin);
   }
   wclear(stdscr);
   endwin();
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
     int n;
     char buffer[4096] = { 0 };
     struct InputBufStruct ib;
     struct fd_set fd;
     static struct timeval timeout;
     int online = 0;
     memset(ib.buffer, 0, 4096);
     ib.pos = 0;
     if(argc > 1) {
     int ch;
      while ((ch = getopt(argc, argv, "c:n:")) != 1) {
       switch (ch) {
         case 'c':
               break;
  case 'n':
               break;
         case '?':
               usage();
       }
      }
     }
   running = 1;
   printf("uchat starting\n");
   init_gui();
   gui_get_input(&ib);
   while(running)
   {
        timeout.tv_sec = 0;
        timeout.tv_usec = 10000;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
        if(Socket >= 0)
             ((void) (((&fd)->__fds_bits)[((Socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((Socket) % (8 * (int) sizeof (__fd_mask)))))));
        if(select(1024, &fd, ((void *)0), ((void *)0), &timeout))
        {
             if(((((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
                  gui_get_input(&ib);
             else
             {
                  if(Socket >= 0 && (((((&fd)->__fds_bits)[((Socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((Socket) % (8 * (int) sizeof (__fd_mask)))))) != 0)))
                  {
                       memset(buffer, 0, 4096);
                       n = recv(Socket, buffer, 4096, 0);
                       if(n > 0)
                       {
                            wprintw(mainwin, buffer);
                            wrefresh(mainwin);
                       }
                  }
             }
        }
        gui_update_statuswin(online);
        wmove(inputwin, 0, ib.pos);
        wrefresh(inputwin);
   }
   wclear(stdscr);
   endwin();
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n int

variable_types:
buffer
char [4096]

variable_types: struct InputBufStruct { char buffer[4096]; int pos; }

variable_types:
fd
struct fd_set { long __fds_bits[-1]; }

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

variable_types: online int

variable_types: ch int


decompiled_code:
int init_gui()
{
int v0; // eax

initscr();
noecho();
keypad(stdscr, 1);
printw("uChat IRC Client.\n");
start_color();
v0 = use_default_colors();
init_pair(0, -(v0 == 0), -(v0 == 0));
init_pair(1, 0, 2);
mainwin = newwin(LINES - 2, COLS, 1, 0);
scrollok(mainwin, 1);
wrefresh(mainwin);
inputwin = newwin(1, COLS, LINES - 1, 0);
wmove(inputwin, 0, 0);
wrefresh(inputwin);
statuswin = newwin(1, COLS, LINES - 2, 0);
wbkgd(statuswin, 0x100uLL);
wrefresh(statuswin);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
int v0; // eax

initscr();
noecho();
keypad(stdscr, 1);
printw("uChat IRC Client.\n");
start_color();
v0 = use_default_colors();
init_pair(0, -(v0 == 0), -(v0 == 0));
init_pair(1, 0, 2);
mainwin = newwin(LINES - 2, COLS, 1, 0);
scrollok(mainwin, 1);
wrefresh(mainwin);
inputwin = newwin(1, COLS, LINES - 1, 0);
wmove(inputwin, 0, 0);
wrefresh(inputwin);
statuswin = newwin(1, COLS, LINES - 2, 0);
wbkgd(statuswin, 0x100uLL);
wrefresh(statuswin);
return wrefresh(stdscr);
}

original_code:
void
init_gui(void)
{
     int bg = -1;
     initscr();
     noecho();
     keypad(stdscr, 1);
     printw("uChat IRC Client.\n");
     start_color();
     bg = (use_default_colors() == (0)) ? -1 : 0;
     init_pair(0, bg, bg);
     init_pair(1, 0, 2);
     mainwin = newwin(LINES - 2, COLS, 1, 0);
     scrollok(mainwin, 1);
     wrefresh(mainwin);
     inputwin = newwin(1, COLS, LINES - 1, 0);
     wmove(inputwin, 0, 0);
     wrefresh(inputwin);
     statuswin = newwin(1, COLS, LINES - 2, 0);
     wbkgd(statuswin, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
     wrefresh(statuswin);
     wrefresh(stdscr);
     return;
}

canonical_original_code:
void init_gui()
{
     int bg = -1;
     initscr();
     noecho();
     keypad(stdscr, 1);
     printw("uChat IRC Client.\n");
     start_color();
     bg = (use_default_colors() == (0)) ? -1 : 0;
     init_pair(0, bg, bg);
     init_pair(1, 0, 2);
     mainwin = newwin(LINES - 2, COLS, 1, 0);
     scrollok(mainwin, 1);
     wrefresh(mainwin);
     inputwin = newwin(1, COLS, LINES - 1, 0);
     wmove(inputwin, 0, 0);
     wrefresh(inputwin);
     statuswin = newwin(1, COLS, LINES - 2, 0);
     wbkgd(statuswin, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
     wrefresh(statuswin);
     wrefresh(stdscr);
     return;
}

variable_types: bg int


decompiled_code:
int __fastcall gui_update_statuswin(int a1)
{
werase(statuswin);
update_date();
mvwprintw(statuswin, 0, 0, "[%s]", global_date);
if ( a1 )
mvwprintw(statuswin, 0, 15, "[%s]", (const char *)serverhost);
else
mvwprintw(statuswin, 0, 15, "[offline]");
wbkgd(statuswin, 0x100uLL);
return wrefresh(statuswin);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
werase(statuswin);
update_date();
mvwprintw(statuswin, 0, 0, "[%s]", global_date);
if ( a1 )
mvwprintw(statuswin, 0, 15, "[%s]", (const char *)serverhost);
else
mvwprintw(statuswin, 0, 15, "[offline]");
wbkgd(statuswin, 0x100uLL);
return wrefresh(statuswin);
}

original_code:
void
gui_update_statuswin(int online)
{
     werase(statuswin);
     update_date();
     mvwprintw(statuswin, 0, 0, "[%s]", global_date);
     if(online == 0)
       mvwprintw(statuswin, 0, 15, "[offline]");
     else
       mvwprintw(statuswin, 0, 15, "[%s]", serverhost);
     wbkgd(statuswin, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
     wrefresh(statuswin);
     return;
}


decompiled_code:
int __fastcall gui_get_input(char *s)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // eax
int v8; // edx
int v9; // edx
__int64 i; // rbx
int v12; // eax

halfdelay(1);
v1 = wgetch(stdscr);
if ( v1 == 262 )
{
wmove(inputwin, 0, 0);
*((_DWORD *)s + 1024) = 0;
return wrefresh(inputwin);
}
v2 = v1;
if ( v1 > 262 )
{
if ( v1 != 330 )
{
if ( v1 == 360 )
{
v7 = strlen(s);
wmove(inputwin, 0, v7);
*((_DWORD *)s + 1024) = strlen(s);
return wrefresh(inputwin);
}
if ( v1 == 263 )
{
LABEL_12:
v5 = *((_DWORD *)s + 1024);
if ( v5 > 0 )
{
v6 = v5 - 1;
*((_DWORD *)s + 1024) = v6;
wmove(inputwin, 0, v6);
s[*((int *)s + 1024)] = 0;
wdelch(inputwin);
}
return wrefresh(inputwin);
}
goto LABEL_30;
}
wdelch(inputwin);
LODWORD(i) = *((_DWORD *)s + 1024);
if ( s[(int)i] && (int)i >= 0 )
{
for ( i = (int)i; (int)strlen(s) > (int)i; ++i )
s[i] = s[i + 1];
}
}
else
{
if ( v1 != 260 )
{
if ( v1 > 260 )
{
v3 = *((_DWORD *)s + 1024);
if ( s[v3] )
{
v4 = v3 + 1;
*((_DWORD *)s + 1024) = v4;
wmove(inputwin, 0, v4);
}
return wrefresh(inputwin);
}
if ( v1 == 10 )
{
if ( *((_DWORD *)s + 1024) || *s )
{
input_manage(s);
werase(inputwin);
*(_QWORD *)s = 0LL;
*((_QWORD *)s + 127) = 0LL;
memset(
(void *)((unsigned __int64)(s + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)s - (((_DWORD)s + 8) & 0xFFFFFFF8) + 1024) >> 3));
*((_DWORD *)s + 1024) = 0;
wmove(inputwin, 0, 0);
}
return wrefresh(inputwin);
}
if ( v1 == 127 )
goto LABEL_12;
if ( v1 <= 0 )
return wrefresh(inputwin);
LABEL_30:
if ( strlen(s) <= 0xFFF )
{
v12 = *((_DWORD *)s + 1024);
s[v12] = v2;
*((_DWORD *)s + 1024) = v12 + 1;
winsch(inputwin, v2);
wmove(inputwin, 0, *((_DWORD *)s + 1024));
}
return wrefresh(inputwin);
}
v8 = *((_DWORD *)s + 1024);
if ( v8 > 0 )
{
v9 = v8 - 1;
*((_DWORD *)s + 1024) = v9;
wmove(inputwin, 0, v9);
}
}
return wrefresh(inputwin);
}

canonical_decompiled_code:
int __fastcall func2(char *s)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // eax
int v8; // edx
int v9; // edx
__int64 i; // rbx
int v12; // eax

halfdelay(1);
v1 = wgetch(stdscr);
if ( v1 == 262 )
{
wmove(inputwin, 0, 0);
*((_DWORD *)s + 1024) = 0;
return wrefresh(inputwin);
}
v2 = v1;
if ( v1 > 262 )
{
if ( v1 != 330 )
{
if ( v1 == 360 )
{
v7 = strlen(s);
wmove(inputwin, 0, v7);
*((_DWORD *)s + 1024) = strlen(s);
return wrefresh(inputwin);
}
if ( v1 == 263 )
{
LABEL_12:
v5 = *((_DWORD *)s + 1024);
if ( v5 > 0 )
{
v6 = v5 - 1;
*((_DWORD *)s + 1024) = v6;
wmove(inputwin, 0, v6);
s[*((int *)s + 1024)] = 0;
wdelch(inputwin);
}
return wrefresh(inputwin);
}
goto LABEL_30;
}
wdelch(inputwin);
LODWORD(i) = *((_DWORD *)s + 1024);
if ( s[(int)i] && (int)i >= 0 )
{
for ( i = (int)i; (int)strlen(s) > (int)i; ++i )
s[i] = s[i + 1];
}
}
else
{
if ( v1 != 260 )
{
if ( v1 > 260 )
{
v3 = *((_DWORD *)s + 1024);
if ( s[v3] )
{
v4 = v3 + 1;
*((_DWORD *)s + 1024) = v4;
wmove(inputwin, 0, v4);
}
return wrefresh(inputwin);
}
if ( v1 == 10 )
{
if ( *((_DWORD *)s + 1024) || *s )
{
input_manage(s);
werase(inputwin);
*(_QWORD *)s = 0LL;
*((_QWORD *)s + 127) = 0LL;
memset(
(void *)((unsigned __int64)(s + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)s - (((_DWORD)s + 8) & 0xFFFFFFF8) + 1024) >> 3));
*((_DWORD *)s + 1024) = 0;
wmove(inputwin, 0, 0);
}
return wrefresh(inputwin);
}
if ( v1 == 127 )
goto LABEL_12;
if ( v1 <= 0 )
return wrefresh(inputwin);
LABEL_30:
if ( strlen(s) <= 0xFFF )
{
v12 = *((_DWORD *)s + 1024);
s[v12] = v2;
*((_DWORD *)s + 1024) = v12 + 1;
winsch(inputwin, v2);
wmove(inputwin, 0, *((_DWORD *)s + 1024));
}
return wrefresh(inputwin);
}
v8 = *((_DWORD *)s + 1024);
if ( v8 > 0 )
{
v9 = v8 - 1;
*((_DWORD *)s + 1024) = v9;
wmove(inputwin, 0, v9);
}
}
return wrefresh(inputwin);
}

original_code:
void
gui_get_input(InputBufStruct *ib)
{
     int i, c;
     halfdelay(1);
     switch((c = wgetch(stdscr)))
     {
     case 10:
          if(ib->pos || strlen(ib->buffer))
          {
               input_manage(ib->buffer);
               werase(inputwin);
               memset(ib->buffer, 0, 1024);
               ib->pos = 0;
               wmove(inputwin, 0, ib->pos);
          }
          break;
     case 0404:
          if(ib->pos >= 1)
          {
               --(ib->pos);
               wmove(inputwin, 0, ib->pos);
          }
          break;
     case 0405:
          if(ib->buffer[ib->pos] != 0)
          {
               ++(ib->pos);
               wmove(inputwin, 0, ib->pos);
          }
          break;
     case 127:
     case 0407:
          if(ib->pos >= 1)
          {
               --(ib->pos);
               wmove(inputwin, 0, ib->pos);
               ib->buffer[ib->pos] = '\0';
               wdelch(inputwin);
          }
          break;
     case 0512:
          wdelch(inputwin);
          if(ib->buffer[ib->pos] != 0
             && ib->pos >= 0)
               for(i = ib->pos; i < (int)strlen(ib->buffer); ++i)
                    ib->buffer[i] = ib->buffer[i + 1];
          break;
     case 0406:
          wmove(inputwin, 0, 0);
          ib->pos = 0;
          break;
     case 0550:
          wmove(inputwin, 0, strlen(ib->buffer));
          ib->pos = strlen(ib->buffer);
          break;
     default:
          if(c > 0 && strlen(ib->buffer) < 4096)
          {
               ib->buffer[ib->pos] = c;
               ++(ib->pos);
               winsch(inputwin, c);
               wmove(inputwin, 0, ib->pos);
          }
          break;
     }
     wrefresh(inputwin);
     return;
}

canonical_original_code:
void gui_get_input(struct InputBufStruct *ib)
{
     int i; int c;
     halfdelay(1);
     switch((c = wgetch(stdscr)))
     {
     case 10:
          if(ib->pos || strlen(ib->buffer))
          {
               input_manage(ib->buffer);
               werase(inputwin);
               memset(ib->buffer, 0, 1024);
               ib->pos = 0;
               wmove(inputwin, 0, ib->pos);
          }
          break;
     case 0404:
          if(ib->pos >= 1)
          {
               --(ib->pos);
               wmove(inputwin, 0, ib->pos);
          }
          break;
     case 0405:
          if(ib->buffer[ib->pos] != 0)
          {
               ++(ib->pos);
               wmove(inputwin, 0, ib->pos);
          }
          break;
     case 127:
     case 0407:
          if(ib->pos >= 1)
          {
               --(ib->pos);
               wmove(inputwin, 0, ib->pos);
               ib->buffer[ib->pos] = '\0';
               wdelch(inputwin);
          }
          break;
     case 0512:
          wdelch(inputwin);
          if(ib->buffer[ib->pos] != 0
             && ib->pos >= 0)
               for(i = ib->pos; i < (int)strlen(ib->buffer); ++i)
                    ib->buffer[i] = ib->buffer[i + 1];
          break;
     case 0406:
          wmove(inputwin, 0, 0);
          ib->pos = 0;
          break;
     case 0550:
          wmove(inputwin, 0, strlen(ib->buffer));
          ib->pos = strlen(ib->buffer);
          break;
     default:
          if(c > 0 && strlen(ib->buffer) < 4096)
          {
               ib->buffer[ib->pos] = c;
               ++(ib->pos);
               winsch(inputwin, c);
               wmove(inputwin, 0, ib->pos);
          }
          break;
     }
     wrefresh(inputwin);
     return;
}

variable_types: struct InputBufStruct { char buffer[4096]; int pos; } *

variable_types: i int

variable_types: c int


decompiled_code:
void input_help()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void
input_help(const char *arg) {
     return;
}

canonical_original_code:
void input_help(char *arg) {
     return;
}

variable_types:
arg
char *


decompiled_code:
void input_disconnect()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
input_disconnect(const char *arg) {
  return;
}

canonical_original_code:
void input_disconnect(char *arg) {
  return;
}


decompiled_code:
__int64 __fastcall input_setnick(const char *a1)
{
return send_msg((unsigned int)Socket, "NICK %s :\r\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
return send_msg((unsigned int)Socket, "NICK %s :\r\n", a1);
}

original_code:
void
input_setnick(const char *arg) {
     send_msg(Socket, "NICK %s :\r\n", arg);
     return;
}

canonical_original_code:
void input_setnick(char *arg) {
     send_msg(Socket, "NICK %s :\r\n", arg);
     return;
}


decompiled_code:
__int64 __fastcall input_join(const char *a1)
{
return send_msg((unsigned int)Socket, "JOIN %s :\r\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
return send_msg((unsigned int)Socket, "JOIN %s :\r\n", a1);
}

original_code:
void
input_join(const char *arg) {
     send_msg(Socket, "JOIN %s :\r\n", arg);
     return;
}

canonical_original_code:
void input_join(char *arg) {
     send_msg(Socket, "JOIN %s :\r\n", arg);
     return;
}


decompiled_code:
__int64 input_connect()
{
init_connection("irc.freenode.net", 6667LL, 0LL);
return gui_update_statuswin(0LL);
}

canonical_decompiled_code:
__int64 func4()
{
init_connection("irc.freenode.net", 6667LL, 0LL);
return gui_update_statuswin(0LL);
}

original_code:
void
input_connect(const char *arg) {
  int online;
  init_connection("irc.freenode.net", 6667, online);
  gui_update_statuswin(online);
  return;
}

canonical_original_code:
void input_connect(char *arg) {
  int online;
  init_connection("irc.freenode.net", 6667, online);
  gui_update_statuswin(online);
  return;
}


decompiled_code:
void __fastcall __noreturn input_quit(const char *a1)
{
send_msg((unsigned int)Socket, "QUIT %s :\r\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
send_msg((unsigned int)Socket, "QUIT %s :\r\n", a1);
exit(0);
}

original_code:
void
input_quit(const char *arg) {
     send_msg(Socket, "QUIT %s :\r\n", arg);
     exit(0);
}

canonical_original_code:
void input_quit(char *arg) {
     send_msg(Socket, "QUIT %s :\r\n", arg);
     exit(0);
}


decompiled_code:
int __fastcall input_manage(const char *a1)
{
const char *v1; // r12
char **v2; // rbp
const char *v3; // r14
size_t v4; // rbx
int result; // eax

if ( *a1 != 47 )
return send_msg((unsigned int)Socket, "PRIVMSG #uchat :%s\r\n", a1);
v1 = a1 + 1;
v2 = &input_struct;
do
{
v3 = *v2;
v4 = strlen(*v2);
result = strncmp(v1, v3, v4);
if ( !result )
result = ((__int64 (__fastcall *)(const char *))v2[1])(&v1[v4]);
v2 += 2;
}
while ( v2 != (char **)(unsigned int)((_DWORD)&input_struct + 96) );
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
const char *v1; // r12
char **v2; // rbp
const char *v3; // r14
size_t v4; // rbx
int result; // eax

if ( *a1 != 47 )
return send_msg((unsigned int)Socket, "PRIVMSG #uchat :%s\r\n", a1);
v1 = a1 + 1;
v2 = &input_struct;
do
{
v3 = *v2;
v4 = strlen(*v2);
result = strncmp(v1, v3, v4);
if ( !result )
result = ((__int64 (__fastcall *)(const char *))v2[1])(&v1[v4]);
v2 += 2;
}
while ( v2 != (char **)(unsigned int)((_DWORD)&input_struct + 96) );
return result;
}

original_code:
void
input_manage(const char *input)
{
     int i;
     if(input[0] == '/')
     {
          ++input;
          for(i = 0; i < (sizeof(input_struct) / sizeof((input_struct)[0])); ++i)
               if(!strncmp(input, input_struct[i].cmd, strlen(input_struct[i].cmd)))
                    input_struct[i].func(input + strlen(input_struct[i].cmd));
     }
     else
          send_msg(Socket, "PRIVMSG ""#uchat"" :%s\r\n", input);
     return;
}

canonical_original_code:
void input_manage(char *input)
{
     int i;
     if(input[0] == '/')
     {
          ++input;
          for(i = 0; i < (sizeof(input_struct) / sizeof((input_struct)[0])); ++i)
               if(!strncmp(input, input_struct[i].cmd, strlen(input_struct[i].cmd)))
                    input_struct[i].func(input + strlen(input_struct[i].cmd));
     }
     else
          send_msg(Socket, "PRIVMSG ""#uchat"" :%s\r\n", input);
     return;
}

variable_types:
input
char *


decompiled_code:
__int64 __fastcall input_part(const char *a1)
{
return send_msg((unsigned int)Socket, "PART %s :\r\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
return send_msg((unsigned int)Socket, "PART %s :\r\n", a1);
}

original_code:
void
input_part(const char *arg) {
     send_msg(Socket, "PART %s :\r\n", arg);
     return;
}

canonical_original_code:
void input_part(char *arg) {
     send_msg(Socket, "PART %s :\r\n", arg);
     return;
}


decompiled_code:
void send_msg(int fd, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[4096]; // [rsp+20h] [rbp-10B8h] BYREF

if ( fd )
{
va_start(arg, a2);
vsprintf(s, a2, arg);
v2 = strlen(s);
send(fd, s, v2, 0);
}
}

canonical_decompiled_code:
void func0(int fd, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-10D0h] BYREF
char s[4096]; // [rsp+20h] [rbp-10B8h] BYREF

if ( fd )
{
va_start(arg, a2);
vsprintf(s, a2, arg);
v2 = strlen(s);
send(fd, s, v2, 0);
}
}

original_code:
void
send_msg(int sock, char* format, ...)
{
     char buf[4096];
     va_list ap;
     if(!sock)
          return;
     __builtin_va_start(ap,format);
     vsprintf(buf, format, ap);
     __builtin_va_end(ap);
     send(sock, buf, strlen(buf), 0);
     return;
}

canonical_original_code:
void send_msg(int sock, char *format, ...)
{
     char buf[4096];
     __builtin_va_list ap;
     if(!sock)
          return;
     __builtin_va_start(ap,format);
     vsprintf(buf, format, ap);
     __builtin_va_end(ap);
     send(sock, buf, strlen(buf), 0);
     return;
}

variable_types: sock int

variable_types:
format
char *

variable_types:
buf
char [4096]


decompiled_code:
size_t update_date()
{
tm = localtime(&lt);
lt = time(0LL);
return strftime(global_date, 0x1000uLL, "%r", tm);
}

canonical_decompiled_code:
size_t func1()
{
tm = localtime(&lt);
lt = time(0LL);
return strftime(global_date, 0x1000uLL, "%r", tm);
}

original_code:
void
update_date(void)
{
     tm = localtime(&lt);
     lt = time(((void *)0));
     strftime(global_date, sizeof(global_date), "%r", tm);
     return;
}

canonical_original_code:
void update_date()
{
     tm = localtime(&lt);
     lt = time(((void *)0));
     strftime(global_date, sizeof(global_date), "%r", tm);
     return;
}


decompiled_code:
__int64 __fastcall init_connection(const char *a1, __int16 a2)
{
struct hostent *v3; // rax
struct hostent *v5; // rbx
int v6; // edi
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v3 = gethostbyname(a1);
if ( v3->h_addrtype != 2 )
return fwrite("Fatal: Sorry but we dont support this server (Probably IPV6 IP)\n", 1uLL, 0x40uLL, stderr);
v5 = v3;
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = _bswap_16(a2);
memcpy(&v7[0].sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
v6 = socket(2, 1, 0);
Socket = v6;
if ( v6 < 0 )
return fwrite("Fatal: Unable to create the socket\n", 1uLL, 0x23uLL, stderr);
if ( connect(v6, v7, 0x10u) )
return fwrite("Fatal: Unable to connect socket\n", 1uLL, 0x20uLL, stderr);
send_msg((unsigned int)Socket, "NICK uchatTEST :\r\n");
send_msg((unsigned int)Socket, "USER %s %s %s :%s\r\n", "pwetuchat.", "pwetuchat.", a1, "uchatTEST");
return send_msg((unsigned int)Socket, "JOIN #uchat :\r\n");
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int16 a2)
{
struct hostent *v3; // rax
struct hostent *v5; // rbx
int v6; // edi
struct sockaddr v7[2]; // [rsp+0h] [rbp-28h] BYREF

v3 = gethostbyname(a1);
if ( v3->h_addrtype != 2 )
return fwrite("Fatal: Sorry but we dont support this server (Probably IPV6 IP)\n", 1uLL, 0x40uLL, stderr);
v5 = v3;
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = func0(a2);
memcpy(&v7[0].sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
v6 = socket(2, 1, 0);
Socket = v6;
if ( v6 < 0 )
return fwrite("Fatal: Unable to create the socket\n", 1uLL, 0x23uLL, stderr);
if ( connect(v6, v7, 0x10u) )
return fwrite("Fatal: Unable to connect socket\n", 1uLL, 0x20uLL, stderr);
send_msg((unsigned int)Socket, "NICK uchatTEST :\r\n");
send_msg((unsigned int)Socket, "USER %s %s %s :%s\r\n", "pwetuchat.", "pwetuchat.", a1, "uchatTEST");
return send_msg((unsigned int)Socket, "JOIN #uchat :\r\n");
}

original_code:
void
init_connection(char *serverhost, int port, int online, ...)
{
     struct hostent *server;
     struct sockaddr_in addr;
     server = gethostbyname(serverhost);
     if(server->h_addrtype != 2)
     {
          fprintf(stderr, "Fatal: Sorry but we dont support this server (Probably IPV6 IP)\n");
          return;
     }
     addr.sin_family = 2;
     addr.sin_port = htons(port);
     memcpy(&addr.sin_addr.s_addr, server->h_addr_list[0], server->h_length);
     if((Socket = socket(2, SOCK_STREAM, 0)) < 0)
     {
          fprintf(stderr, "Fatal: Unable to create the socket\n");
          return;
     }
     if(connect(Socket, (struct sockaddr*) &addr, sizeof(addr)) != 0)
     {
          fprintf(stderr,"Fatal: Unable to connect socket\n");
          return;
     }
     online = 1;
     send_msg(Socket, "NICK ""uchatTEST"" :\r\n");
     send_msg(Socket, "USER %s %s %s :%s\r\n", "pwetuchat.", "pwetuchat.", serverhost, "uchatTEST");
     send_msg(Socket, "JOIN ""#uchat"" :\r\n");
     return;
}

canonical_original_code:
void init_connection(char *serverhost, int port, int online, ...)
{
     struct hostent *server;
     struct sockaddr_in addr;
     server = gethostbyname(serverhost);
     if(server->h_addrtype != 2)
     {
          fprintf(stderr, "Fatal: Sorry but we dont support this server (Probably IPV6 IP)\n");
          return;
     }
     addr.sin_family = 2;
     addr.sin_port = htons(port);
     memcpy(&addr.sin_addr.s_addr, server->h_addr_list[0], server->h_length);
     if((Socket = socket(2, SOCK_STREAM, 0)) < 0)
     {
          fprintf(stderr, "Fatal: Unable to create the socket\n");
          return;
     }
     if(connect(Socket, (struct sockaddr *) &addr, sizeof(addr)) != 0)
     {
          fprintf(stderr,"Fatal: Unable to connect socket\n");
          return;
     }
     online = 1;
     send_msg(Socket, "NICK ""uchatTEST"" :\r\n");
     send_msg(Socket, "USER %s %s %s :%s\r\n", "pwetuchat.", "pwetuchat.", serverhost, "uchatTEST");
     send_msg(Socket, "JOIN ""#uchat"" :\r\n");
     return;
}

variable_types:
serverhost
char *

variable_types: port int

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

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

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

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


updatecache

original_code:
void updatecache(Cache **cache, int setindex, int associativity, int ix){
    int i;
    for(i=0; i<associativity ;i++){
        if(cache[setindex][i].freq!=0){
             cache[setindex][i].freq++;
        }
    }
    cache[setindex][ix].freq=1;
}

canonical_original_code:
void updatecache(struct Cache **cache, int setindex, int associativity, int ix){
    int i;
    for(i=0; i<associativity ;i++){
        if(cache[setindex][i].freq!=0){
             cache[setindex][i].freq++;
        }
    }
    cache[setindex][ix].freq=1;
}

variable_types: struct Cache { unsigned long tag; int valid; int freq; } **

variable_types: setindex int

variable_types: associativity int

variable_types: ix int


lru

original_code:
void lru(Cache **cache, int setindex ,int associativity, size_t tag){
    int maximum = cache[setindex][0].freq;
    int i, j=0;
    for( i =0;i<associativity;i++){
        if(maximum < cache[setindex][i].freq){
            maximum= cache[setindex][i].freq;
            j=i;
        }
    }
    cache[setindex][j].tag=tag;
    updatecache(cache, setindex,associativity,j );
}

canonical_original_code:
void lru(struct Cache **cache, int setindex, int associativity, unsigned long tag){
    int maximum = cache[setindex][0].freq;
    int i; int j = 0;
    for( i =0;i<associativity;i++){
        if(maximum < cache[setindex][i].freq){
            maximum= cache[setindex][i].freq;
            j=i;
        }
    }
    cache[setindex][j].tag=tag;
    updatecache(cache, setindex,associativity,j );
}

variable_types:
tag
unsigned long

variable_types: maximum int

variable_types: j int

user_defined_types: struct Cache { unsigned long tag; int valid; int freq; }


Search

decompiled_code:
__int64 __fastcall Search(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
__int64 *v6; // r13
__int64 v7; // rdx
__int64 i; // rax
unsigned int v9; // ebx

if ( a4 > 0 )
{
v6 = (__int64 *)(a1 + 8LL * a2);
v7 = *v6;
for ( i = 0LL; i != a4; ++i )
{
v9 = *(_DWORD *)(v7 + 8);
if ( !v9 )
{
*(_QWORD *)v7 = a3;
*(_DWORD *)(*v6 + 16 * i + 8) = 1;
if ( a5 == 1 )
{
++L1_Coldmisses;
++L1_misses;
updatecache(a1, a2, a4, i);
}
else if ( a5 == 2 )
{
++L2_Coldmisses;
++L2_misses;
updatecache(a1, a2, a4, i);
}
else
{
++L3_Coldmisses;
++L3_misses;
updatecache(a1, a2, a4, i);
v9 = 1;
}
return v9;
}
if ( v9 == 1 )
{
if ( *(_QWORD *)v7 == a3 )
{
switch ( a5 )
{
case 1:
++L1_hits;
updatecache(a1, a2, a4, i);
return 1;
case 2:
++L2_hits;
updatecache(a1, a2, a4, i);
return v9;
case 3:
++L3_hits;
updatecache(a1, a2, a4, i);
return v9;
}
}
else if ( a4 == 1 )
{
*(_QWORD *)v7 = a3;
if ( a5 == 1 )
{
++L1_misses;
v9 = 0;
}
else if ( a5 == 2 )
{
++L2_misses;
v9 = 0;
}
else
{
v9 = 0;
if ( a5 == 3 )
++L3_misses;
}
return v9;
}
}
v7 += 16LL;
}
}
if ( a5 == 1 )
{
++L1_misses;
if ( replacealg == 1 )
fifo(a2, L1assoc, a3, 1);
else
lru(a1, a2, L1assoc, a3);
v9 = 0;
}
else if ( a5 == 2 )
{
++L2_misses;
if ( replacealg == 1 )
fifo(a2, L2assoc, a3, 2);
else
lru(a1, a2, L2assoc, a3);
v9 = 0;
}
else
{
v9 = 0;
if ( a5 == 3 )
{
++L3_misses;
if ( replacealg == 1 )
{
fifo(a2, L3assoc, a3, 3);
}
else
{
lru(a1, a2, L3assoc, a3);
v9 = 0;
}
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
__int64 *v6; // r13
__int64 v7; // rdx
__int64 i; // rax
unsigned int v9; // ebx

if ( a4 > 0 )
{
v6 = (__int64 *)(a1 + 8LL * a2);
v7 = *v6;
for ( i = 0LL; i != a4; ++i )
{
v9 = *(_DWORD *)(v7 + 8);
if ( !v9 )
{
*(_QWORD *)v7 = a3;
*(_DWORD *)(*v6 + 16 * i + 8) = 1;
if ( a5 == 1 )
{
++L1_Coldmisses;
++L1_misses;
func0(a1, a2, a4, i);
}
else if ( a5 == 2 )
{
++L2_Coldmisses;
++L2_misses;
func0(a1, a2, a4, i);
}
else
{
++L3_Coldmisses;
++L3_misses;
func0(a1, a2, a4, i);
v9 = 1;
}
return v9;
}
if ( v9 == 1 )
{
if ( *(_QWORD *)v7 == a3 )
{
switch ( a5 )
{
case 1:
++L1_hits;
func0(a1, a2, a4, i);
return 1;
case 2:
++L2_hits;
func0(a1, a2, a4, i);
return v9;
case 3:
++L3_hits;
func0(a1, a2, a4, i);
return v9;
}
}
else if ( a4 == 1 )
{
*(_QWORD *)v7 = a3;
if ( a5 == 1 )
{
++L1_misses;
v9 = 0;
}
else if ( a5 == 2 )
{
++L2_misses;
v9 = 0;
}
else
{
v9 = 0;
if ( a5 == 3 )
++L3_misses;
}
return v9;
}
}
v7 += 16LL;
}
}
if ( a5 == 1 )
{
++L1_misses;
if ( replacealg == 1 )
fifo(a2, L1assoc, a3, 1);
else
func1(a1, a2, L1assoc, a3);
v9 = 0;
}
else if ( a5 == 2 )
{
++L2_misses;
if ( replacealg == 1 )
fifo(a2, L2assoc, a3, 2);
else
func1(a1, a2, L2assoc, a3);
v9 = 0;
}
else
{
v9 = 0;
if ( a5 == 3 )
{
++L3_misses;
if ( replacealg == 1 )
{
fifo(a2, L3assoc, a3, 3);
}
else
{
func1(a1, a2, L3assoc, a3);
v9 = 0;
}
}
}
return v9;
}

original_code:
int Search(Cache** cache, int inoffset, size_t tag, int associativity ,int chc){
  int i;
  for(i=0; i< associativity ;i++){
    if(cache[inoffset][i].valid==0){
        cache[inoffset][i].tag=tag;
        cache[inoffset][i].valid=1;
        if(chc==1){
            L1_Coldmisses++;
            L1_misses++;
            updatecache(cache, inoffset, associativity,i);
        }else if(chc==2){
            L2_Coldmisses++;
            L2_misses++;
            updatecache(cache, inoffset, associativity,i);
        }else{
            L3_Coldmisses++;
            L3_misses++;
            updatecache(cache, inoffset, associativity,i);
   return 1;
        }
        return 0;
    }else if(cache[inoffset][i].valid==1){
        if(cache[inoffset][i].tag==tag){
            if(chc==1){
                L1_hits++;
                    updatecache(cache, inoffset, associativity,i);
                    return 1;
            }else if(chc==2){
                L2_hits++;
                    updatecache(cache, inoffset, associativity,i);
                    return 1;
            }else if(chc==3){
                L3_hits++;
                    updatecache(cache, inoffset, associativity,i);
                    return 1;
            }
        }else if(associativity==1){
          cache[inoffset][i].tag= tag;
            if(chc==1){
                 L1_misses++;
            }else if(chc==2){
                 L2_misses++;
            }else if(chc==3){
                 L3_misses++;
            }
                 return 0;
        }else{
            continue;
        }
    }
  }
  if(chc==1){
     L1_misses++;
        if(replacealg==1){
                fifo(inoffset,L1assoc,tag,chc);
        }else{
              lru(cache,inoffset,L1assoc,tag);
        }
     }else if(chc==2){
        L2_misses++;
        if(replacealg==1){
                fifo(inoffset,L2assoc,tag,chc);
        }else{
              lru(cache,inoffset,L2assoc,tag);
        }
     }else if(chc==3){
        L3_misses++;
        if(replacealg==1){
               fifo(inoffset,L3assoc,tag,chc);
        }else{
              lru(cache,inoffset,L3assoc,tag);
        }
     }
    return 0;
   }

canonical_original_code:
int Search(struct Cache **cache, int inoffset, unsigned long tag, int associativity, int chc){
  int i;
  for(i=0; i< associativity ;i++){
    if(cache[inoffset][i].valid==0){
        cache[inoffset][i].tag=tag;
        cache[inoffset][i].valid=1;
        if(chc==1){
            L1_Coldmisses++;
            L1_misses++;
            updatecache(cache, inoffset, associativity,i);
        }else if(chc==2){
            L2_Coldmisses++;
            L2_misses++;
            updatecache(cache, inoffset, associativity,i);
        }else{
            L3_Coldmisses++;
            L3_misses++;
            updatecache(cache, inoffset, associativity,i);
   return 1;
        }
        return 0;
    }else if(cache[inoffset][i].valid==1){
        if(cache[inoffset][i].tag==tag){
            if(chc==1){
                L1_hits++;
                    updatecache(cache, inoffset, associativity,i);
                    return 1;
            }else if(chc==2){
                L2_hits++;
                    updatecache(cache, inoffset, associativity,i);
                    return 1;
            }else if(chc==3){
                L3_hits++;
                    updatecache(cache, inoffset, associativity,i);
                    return 1;
            }
        }else if(associativity==1){
          cache[inoffset][i].tag= tag;
            if(chc==1){
                 L1_misses++;
            }else if(chc==2){
                 L2_misses++;
            }else if(chc==3){
                 L3_misses++;
            }
                 return 0;
        }else{
            continue;
        }
    }
  }
  if(chc==1){
     L1_misses++;
        if(replacealg==1){
                fifo(inoffset,L1assoc,tag,chc);
        }else{
              lru(cache,inoffset,L1assoc,tag);
        }
     }else if(chc==2){
        L2_misses++;
        if(replacealg==1){
                fifo(inoffset,L2assoc,tag,chc);
        }else{
              lru(cache,inoffset,L2assoc,tag);
        }
     }else if(chc==3){
        L3_misses++;
        if(replacealg==1){
               fifo(inoffset,L3assoc,tag,chc);
        }else{
              lru(cache,inoffset,L3assoc,tag);
        }
     }
    return 0;
   }

variable_types: inoffset int

variable_types: chc int

variable_types: i int


indexoffset

original_code:
int indexoffset(int inoffset, size_t hex, int blockoffset){
    size_t large= pow(2,inoffset)-1;
    int index_offset = (hex >> blockoffset)&large;
    return index_offset;
}

canonical_original_code:
int indexoffset(int inoffset, unsigned long hex, int blockoffset){
    unsigned long large = pow(2,inoffset)-1;
    int index_offset = (hex >> blockoffset)&large;
    return index_offset;
}

variable_types:
hex
unsigned long

variable_types: blockoffset int

variable_types:
large
unsigned long


power

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

result = a1;
if ( a1 )
result = (a1 & (a1 - 1)) == 0;
return result;
}

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

result = a1;
if ( a1 )
result = (a1 & (a1 - 1)) == 0;
return result;
}

original_code:
int power(int x){
 return x && (!(x&(x-1)));
}

variable_types: x int


repo: vpj/ahira

decompiled_code:
int __fastcall log_epoll_event(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
printf("Event fd: %d events: ", HIDWORD(a7));
if ( (a7 & 8) != 0 )
printf("EPOLLERR ");
if ( (int)a7 < 0 )
printf("EPOLLET ");
if ( (a7 & 0x10) != 0 )
printf("EPOLLHUP ");
if ( (a7 & 1) != 0 )
printf("EPOLLIN ");
if ( (a7 & 0x40000000) != 0 )
printf("EPOLLONESHOT ");
if ( (a7 & 4) != 0 )
printf("EPOLLOUT ");
if ( (a7 & 2) != 0 )
printf("EPOLLPRI ");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
printf("Event fd: %d events: ", HIDWORD(a7));
if ( (a7 & 8) != 0 )
printf("EPOLLERR ");
if ( (int)a7 < 0 )
printf("EPOLLET ");
if ( (a7 & 0x10) != 0 )
printf("EPOLLHUP ");
if ( (a7 & 1) != 0 )
printf("EPOLLIN ");
if ( (a7 & 0x40000000) != 0 )
printf("EPOLLONESHOT ");
if ( (a7 & 4) != 0 )
printf("EPOLLOUT ");
if ( (a7 & 2) != 0 )
printf("EPOLLPRI ");
return putchar(10);
}

original_code:
void log_epoll_event(struct epoll_event e) {
 printf("Event fd: %d events: ", e.data.fd);
 if(e.events & EPOLLERR)
  printf("EPOLLERR ");
 if(e.events & EPOLLET)
  printf("EPOLLET ");
 if(e.events & EPOLLHUP)
  printf("EPOLLHUP ");
 if(e.events & EPOLLIN)
  printf("EPOLLIN ");
 if(e.events & EPOLLONESHOT)
  printf("EPOLLONESHOT ");
 if(e.events & EPOLLOUT)
  printf("EPOLLOUT ");
 if(e.events & EPOLLPRI)
  printf("EPOLLPRI ");
 printf("\n");
}

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

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


decompiled_code:
void __fastcall log_error(char *s, char a2)
{
if ( (a2 & 2) != 0 )
{
perror("FATAL ERROR: ");
perror(s);
exit(1);
}
if ( (a2 & 1) != 0 )
perror("ERROR: ");
perror(s);
}

canonical_decompiled_code:
void __fastcall func1(char *s, char a2)
{
if ( (a2 & 2) != 0 )
{
perror("FATAL ERROR: ");
perror(s);
exit(1);
}
if ( (a2 & 1) != 0 )
perror("ERROR: ");
perror(s);
}

original_code:
void log_error(char *m, int level) {
 if(level & 2)
  perror("FATAL ERROR: ");
 else if(level & 1)
  perror("ERROR: ");
 perror(m);
 if(level & 2)
  exit(1);
}

variable_types:
m
char *

variable_types: level int