decompiled_code:
__int64 __fastcall rbuf_init(__int64 a1, int a2, int a3)
{
void *v4; // rax
__int64 result; // rax

v4 = malloc(a3 * a2);
*(_QWORD *)a1 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 8) = a3;
result = 0LL;
*(_DWORD *)(a1 + 12) = a2;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 24) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
void *v4; // rax
__int64 result; // rax

v4 = malloc(a3 * a2);
*(_QWORD *)a1 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 8) = a3;
result = 0LL;
*(_DWORD *)(a1 + 12) = a2;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 24) = 0;
return result;
}

original_code:
int rbuf_init(struct ring_buffer *rbuf, int num_entries, int entry_size)
{
 rbuf->base = malloc(num_entries * entry_size);
 if(!rbuf->base)
  return -1;
 rbuf->entry_size = entry_size;
 rbuf->num_entries = num_entries;
 rbuf->wr_ptr = 0;
 rbuf->rd_ptr = 0;
 rbuf->count = 0;
 return 0;
}

variable_types: struct ring_buffer { void *base; int entry_size; int wr_ptr; } *


repo: neub/wr-switch-sw

decompiled_code:
__int64 __fastcall rbuf_push(__int64 a1, const void *a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 24);
result = (unsigned int)(*(_DWORD *)(a1 + 12) - 1);
if ( v2 < (int)result )
{
*(_DWORD *)(a1 + 24) = v2 + 1;
memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 16)), a2, *(int *)(a1 + 8));
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
if ( (_DWORD)result == *(_DWORD *)(a1 + 12) )
*(_DWORD *)(a1 + 16) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const void *a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 24);
result = (unsigned int)(*(_DWORD *)(a1 + 12) - 1);
if ( v2 < (int)result )
{
*(_DWORD *)(a1 + 24) = v2 + 1;
memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 16)), a2, *(int *)(a1 + 8));
result = (unsigned int)(*(_DWORD *)(a1 + 16) + 1);
*(_DWORD *)(a1 + 16) = result;
if ( (_DWORD)result == *(_DWORD *)(a1 + 12) )
*(_DWORD *)(a1 + 16) = 0;
}
return result;
}

original_code:
void rbuf_push(struct ring_buffer *rbuf, void *what)
{
 if(rbuf->count >= rbuf->num_entries-1)
  return;
 rbuf->count++;
 memcpy(rbuf->base + rbuf->wr_ptr*rbuf->entry_size, what,
        rbuf->entry_size);
 rbuf->wr_ptr++;
 if(rbuf->wr_ptr == rbuf->num_entries)
  rbuf->wr_ptr = 0;
}

variable_types:
what
void *

return_type: void

user_defined_types: struct ring_buffer { void *base; int entry_size; int wr_ptr; }


decompiled_code:
__int64 __fastcall rbuf_pop(__int64 a1, void *a2)
{
__int64 result; // rax
size_t v3; // rdx
int v4; // edx

result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result )
{
v3 = *(int *)(a1 + 8);
*(_DWORD *)(a1 + 24) = result - 1;
memcpy(a2, (const void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 20) * (int)v3), v3);
v4 = *(_DWORD *)(a1 + 20) + 1;
result = 1LL;
*(_DWORD *)(a1 + 20) = v4;
if ( v4 == *(_DWORD *)(a1 + 12) )
*(_DWORD *)(a1 + 20) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, void *a2)
{
__int64 result; // rax
size_t v3; // rdx
int v4; // edx

result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result )
{
v3 = *(int *)(a1 + 8);
*(_DWORD *)(a1 + 24) = result - 1;
memcpy(a2, (const void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 20) * (int)v3), v3);
v4 = *(_DWORD *)(a1 + 20) + 1;
result = 1LL;
*(_DWORD *)(a1 + 20) = v4;
if ( v4 == *(_DWORD *)(a1 + 12) )
*(_DWORD *)(a1 + 20) = 0;
}
return result;
}

original_code:
int rbuf_pop(struct ring_buffer *rbuf, void *dst)
{
 if(!rbuf->count)
  return 0;
 rbuf->count--;
 memcpy(dst, rbuf->base + rbuf->rd_ptr*rbuf->entry_size,
        rbuf->entry_size);
 rbuf->rd_ptr++;
 if(rbuf->rd_ptr == rbuf->num_entries)
  rbuf->rd_ptr = 0;
 return 1;
}

variable_types:
dst
void *

return_type: int


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

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

original_code:
void rbuf_release(struct ring_buffer *rbuf)
{
 free(rbuf->base);
}


decompiled_code:
__int64 __fastcall poll_spll_fifo(int a1)
{
_DWORD *v1; // rdx
__int64 result; // rax
int v3; // [rsp+8h] [rbp-20h] BYREF
__int16 v4; // [rsp+Ch] [rbp-1Ch]

v1 = (_DWORD *)fpga_base_virt;
result = *(unsigned int *)(fpga_base_virt + 65880LL);
if ( (result & 0x20000) == 0 )
{
while ( (result & 0x10000) == 0 || a1 )
{
v3 = v1[16468];
v4 = v1[16469];
if ( a1 )
{
result = (unsigned int)v1[16470];
if ( (result & 0x20000) != 0 )
return result;
}
else
{
LABEL_8:
rbuf_push((__int64)&spll_trace, &v3);
v1 = (_DWORD *)fpga_base_virt;
result = *(unsigned int *)(fpga_base_virt + 65880LL);
if ( (result & 0x20000) != 0 )
return result;
}
}
fwrite("FIFO OVERFLOW!\n", 1uLL, 0xFuLL, stderr);
v3 = *(_DWORD *)(fpga_base_virt + 65872LL);
v4 = *(_DWORD *)(fpga_base_virt + 65876LL);
goto LABEL_8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
_DWORD *v1; // rdx
__int64 result; // rax
int v3; // [rsp+8h] [rbp-20h] BYREF
__int16 v4; // [rsp+Ch] [rbp-1Ch]

v1 = (_DWORD *)fpga_base_virt;
result = *(unsigned int *)(fpga_base_virt + 65880LL);
if ( (result & 0x20000) == 0 )
{
while ( (result & 0x10000) == 0 || a1 )
{
v3 = v1[16468];
v4 = v1[16469];
if ( a1 )
{
result = (unsigned int)v1[16470];
if ( (result & 0x20000) != 0 )
return result;
}
else
{
LABEL_8:
func4((__int64)&spll_trace, &v3);
v1 = (_DWORD *)fpga_base_virt;
result = *(unsigned int *)(fpga_base_virt + 65880LL);
if ( (result & 0x20000) != 0 )
return result;
}
}
fwrite("FIFO OVERFLOW!\n", 1uLL, 0xFuLL, stderr);
v3 = *(_DWORD *)(fpga_base_virt + 65872LL);
v4 = *(_DWORD *)(fpga_base_virt + 65876LL);
goto LABEL_8;
}
return result;
}

original_code:
void poll_spll_fifo(int purge)
{
 while(1) {
  uint32_t csr = (*(volatile uint32_t *)(_fpga_base_virt + (((uint32_t)(&_spll_regs->DFR_HOST_CSR)))));
  struct fifo_entry ent;
  if(csr & (((1<<(1))-1) << (17))) break;
  else if((csr & (((1<<(1))-1) << (16))) && !purge)
  {
   fprintf(stderr, "FIFO OVERFLOW!\n");
  }
  ent.value = (*(volatile uint32_t *)(_fpga_base_virt + (((uint32_t)(&_spll_regs->DFR_HOST_R0)))));
  ent.seq_id = (*(volatile uint32_t *)(_fpga_base_virt + (((uint32_t)(&_spll_regs->DFR_HOST_R1))))) & 0xffff;
  if(!purge)
   rbuf_push(&spll_trace, (void *)&ent);
 }
}

canonical_original_code:
void poll_spll_fifo(int purge)
{
 while(1) {
  unsigned int csr = (*(volatile uint32_t *)(_fpga_base_virt + (((uint32_t)(&_spll_regs->DFR_HOST_CSR)))));
  struct fifo_entry ent;
  if(csr & (((1<<(1))-1) << (17))) break;
  else if((csr & (((1<<(1))-1) << (16))) && !purge)
  {
   fprintf(stderr, "FIFO OVERFLOW!\n");
  }
  ent.value = (*(unsigned int *)(_fpga_base_virt + (((unsigned int)(&_spll_regs->DFR_HOST_R0)))));
  ent.seq_id = (*(unsigned int *)(_fpga_base_virt + (((unsigned int)(&_spll_regs->DFR_HOST_R1))))) & 0xffff;
  if(!purge)
   rbuf_push(&spll_trace, (void *)&ent);
 }
}

variable_types: purge int

variable_types:
csr
unsigned int

variable_types: struct fifo_entry { unsigned int value; unsigned short seq_id; }


decompiled_code:
void __fastcall proxy_stuff(int fd)
{
char *v1; // rbx
char *v2; // rsi
_BYTE v3[1024]; // [rsp+0h] [rbp-418h] BYREF
char v4; // [rsp+400h] [rbp-18h] BYREF

poll_spll_fifo(1);
if ( (int)rbuf_init((__int64)&spll_trace, 0x100000, 8) < 0 )
{
perror("rbuf_init()");
}
else
{
fprintf(stderr, "Connection accepted [record size %d].\n", 8LL);
proxy_done = 0;
signal(13, sighandler);
LABEL_3:
poll_spll_fifo(0);
do
{
if ( *((int *)&spll_trace + 6) <= 128 )
{
usleep(0x2710u);
goto LABEL_3;
}
v1 = v3;
do
{
v2 = v1;
v1 += 8;
rbuf_pop((__int64)&spll_trace, v2);
}
while ( &v4 != v1 );
if ( proxy_done )
goto LABEL_10;
}
while ( send(fd, v3, 0x400uLL, 0) > 0 );
fwrite("Connection closed.\n", 1uLL, 0x13uLL, stderr);
LABEL_10:
rbuf_release((void **)&spll_trace);
}
}

canonical_decompiled_code:
void __fastcall func8(int fd)
{
char *v1; // rbx
char *v2; // rsi
_BYTE v3[1024]; // [rsp+0h] [rbp-418h] BYREF
char v4; // [rsp+400h] [rbp-18h] BYREF

func7(1);
if ( (int)func3((__int64)&spll_trace, 0x100000, 8) < 0 )
{
perror("rbuf_init()");
}
else
{
fprintf(stderr, "Connection accepted [record size %d].\n", 8LL);
proxy_done = 0;
signal(13, sighandler);
LABEL_3:
func7(0);
do
{
if ( *((int *)&spll_trace + 6) <= 128 )
{
usleep(0x2710u);
goto LABEL_3;
}
v1 = v3;
do
{
v2 = v1;
v1 += 8;
func5((__int64)&spll_trace, v2);
}
while ( &v4 != v1 );
if ( proxy_done )
goto LABEL_10;
}
while ( send(fd, v3, 0x400uLL, 0) > 0 );
fwrite("Connection closed.\n", 1uLL, 0x13uLL, stderr);
LABEL_10:
func6((void **)&spll_trace);
}
}

original_code:
void proxy_stuff(int fd)
{
 poll_spll_fifo(1);
 if(rbuf_init(&spll_trace, 1048576,
       sizeof(struct fifo_entry)) < 0)
 {
  perror("rbuf_init()");
  return ;
 }
 fprintf(stderr,"Connection accepted [record size %d].\n",
  sizeof(struct fifo_entry));
 proxy_done = 0;
 signal(13, sighandler);
 for(;;)
 {
  poll_spll_fifo(0);
  while(spll_trace.count > 128)
  {
   struct fifo_entry tx_buf[128];
   int i;
   for(i=0;i<128;i++)
    rbuf_pop(&spll_trace, &tx_buf[i]);
   if(proxy_done)
   {
    rbuf_release(&spll_trace);
    return;
   }
   if(send(fd, tx_buf, sizeof(tx_buf), 0) <= 0)
   {
    fprintf(stderr,"Connection closed.\n");
    rbuf_release(&spll_trace);
    return;
   }
  }
  usleep(10000);
 }
}

variable_types: fd int

variable_types: struct fifo_entry { unsigned int value; unsigned short seq_id; } [128]

variable_types: i int


sighandler

decompiled_code:
void __fastcall sighandler(int a1)
{
if ( a1 == 13 )
{
fwrite("Connection broken. Killing proxy\n", 1uLL, 0x21uLL, stderr);
proxy_done = 1;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 13 )
{
fwrite("Connection broken. Killing proxy\n", 1uLL, 0x21uLL, stderr);
proxy_done = 1;
}
}

original_code:
void sighandler(int sig)
{
 if(sig == 13)
 {
  fprintf(stderr,"Connection broken. Killing proxy\n");
  proxy_done = 1;
 }
}

variable_types: sig int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebx
socklen_t v5; // edx
int v6; // edi
int optval; // [rsp+8h] [rbp-30h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

shw_fpga_mmap_init(argc, argv, envp);
v3 = socket(2, 1, 6);
if ( v3 < 0 )
{
perror("socket()");
}
else
{
v4 = v3;
optval = 1;
if ( setsockopt(v3, 1, 2, &optval, 4u) < 0 )
{
perror("setsockopt()");
}
else
{
v10.sa_family = 2;
*(_DWORD *)&v10.sa_data[2] = _bswap_32_constprop_0(v4, &v10, 16LL);
*(_WORD *)v10.sa_data = _bswap_16_constprop_0();
if ( bind(v4, &v10, v5) < 0 )
{
perror("bind()");
}
else
{
if ( listen(v4, 1) >= 0 )
{
while ( 1 )
{
do
{
addr_len = 16;
v6 = accept(v4, &addr, &addr_len);
}
while ( v6 <= 0 );
proxy_stuff(v6);
}
}
perror("listen()");
}
}
}
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebx
socklen_t v5; // edx
int v6; // edi
int optval; // [rsp+8h] [rbp-30h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v10; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

shw_fpga_mmap_init(argc, argv, envp);
v3 = socket(2, 1, 6);
if ( v3 < 0 )
{
perror("socket()");
}
else
{
v4 = v3;
optval = 1;
if ( setsockopt(v3, 1, 2, &optval, 4u) < 0 )
{
perror("setsockopt()");
}
else
{
v10.sa_family = 2;
*(_DWORD *)&v10.sa_data[2] = func1(v4, &v10, 16LL);
*(_WORD *)v10.sa_data = func2();
if ( bind(v4, &v10, v5) < 0 )
{
perror("bind()");
}
else
{
if ( listen(v4, 1) >= 0 )
{
while ( 1 )
{
do
{
addr_len = 16;
v6 = accept(v4, &addr, &addr_len);
}
while ( v6 <= 0 );
func8(v6);
}
}
perror("listen()");
}
}
}
return -1;
}

original_code:
int main(int argc, char *argv[])
{
  int sock_fd;
  struct sockaddr_in sin;
  shw_fpga_mmap_init();
  if((sock_fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
   perror("socket()");
   return -1;
  }
  int yes = 1;
  if (setsockopt(sock_fd,1,2,
          &yes,sizeof(yes)) < 0) {
   perror("setsockopt()");
   return -1;
  }
    sin.sin_family = 2;
    sin.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    sin.sin_port = htons(12345);
    if (bind(sock_fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
    {
     perror("bind()");
     return -1;
    }
    if (listen(sock_fd, 1) < 0)
    {
     perror("listen()");
   return -1;
  }
  for(;;)
  {
   struct sockaddr_in client_addr;
   socklen_t client_len = sizeof(client_addr);
   int client_fd;
   if((client_fd = accept(sock_fd,
            (struct sockaddr *)&client_addr,
            &client_len)) > 0)
    proxy_stuff(client_fd);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int sock_fd;
  struct sockaddr_in sin;
  shw_fpga_mmap_init();
  if((sock_fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
  {
   perror("socket()");
   return -1;
  }
  int yes = 1;
  if (setsockopt(sock_fd,1,2,
          &yes,sizeof(yes)) < 0) {
   perror("setsockopt()");
   return -1;
  }
    sin.sin_family = 2;
    sin.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    sin.sin_port = htons(12345);
    if (bind(sock_fd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
    {
     perror("bind()");
     return -1;
    }
    if (listen(sock_fd, 1) < 0)
    {
     perror("listen()");
   return -1;
  }
  for(;;)
  {
   struct sockaddr_in client_addr;
   unsigned int client_len = sizeof(client_addr);
   int client_fd;
   if((client_fd = accept(sock_fd,
            (struct sockaddr *)&client_addr,
            &client_len)) > 0)
    proxy_stuff(client_fd);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: yes int

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

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


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

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
{
if ( v1 == 1 )
result = i2c_fpga_reg_init_bus();
else
result = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 40) = result;
}
else
{
result = i2c_bitbang_init_bus();
*(_DWORD *)(a1 + 40) = result;
}
return result;
}

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

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
{
if ( v1 == 1 )
result = i2c_fpga_reg_init_bus();
else
result = 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 40) = result;
}
else
{
result = i2c_bitbang_init_bus();
*(_DWORD *)(a1 + 40) = result;
}
return result;
}

original_code:
int i2c_init_bus(struct i2c_bus *bus)
{
 int ret;
 if (bus->type == 0)
  ret = i2c_bitbang_init_bus(bus);
 else if (bus->type == 1)
  ret = i2c_fpga_reg_init_bus(bus);
 else
  ret = -1;
 bus->err = ret;
 return ret;
}

variable_types: struct i2c_bus { char *name; int type; void *type_specific; int (*transfer)(struct i2c_bus *bus, unsigned int address, unsigned int to_write, unsigned int to_read, unsigned char *data); int (*scan)(struct i2c_bus *bus, unsigned int address); int err; } *

variable_types: ret int


original_code:
int32_t i2c_transfer(struct i2c_bus* bus, uint32_t address, uint32_t to_write, uint32_t to_read, uint8_t* data)
{
 return bus->transfer(bus, address, to_write, to_read, data);
}

canonical_original_code:
int i2c_transfer(struct i2c_bus *bus, unsigned int address, unsigned int to_write, unsigned int to_read, unsigned char *data)
{
 return bus->transfer(bus, address, to_write, to_read, data);
}

variable_types:
address
unsigned int

variable_types:
data
unsigned char *

user_defined_types: struct i2c_bus { char *name; int type; void *type_specific; int (*transfer)(struct i2c_bus *bus, unsigned int address, unsigned int to_write, unsigned int to_read, unsigned char *data); int (*scan)(struct i2c_bus *bus, unsigned int address); int err; }


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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 16) )
((void (*)(void))shw_free)();
result = shw_free(a1);
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)(a1 + 16) )
((void (*)(void))shw_free)();
result = shw_free(a1);
}
return result;
}

original_code:
void i2c_free(struct i2c_bus* bus)
{
    if (!bus)
 return;
    if (bus->type_specific)
 shw_free(bus->type_specific);
    shw_free(bus);
}

canonical_original_code:
void i2c_free(struct i2c_bus *bus)
{
    if (!bus)
 return;
    if (bus->type_specific)
 shw_free(bus->type_specific);
    shw_free(bus);
}


original_code:
int32_t i2c_write(struct i2c_bus* bus, uint32_t address, uint32_t to_write, uint8_t* data)
{
    return bus->transfer(bus, address, to_write, 0, data);
}

canonical_original_code:
int i2c_write(struct i2c_bus *bus, unsigned int address, unsigned int to_write, unsigned char *data)
{
    return bus->transfer(bus, address, to_write, 0, data);
}


decompiled_code:
__int64 __fastcall i2c_read(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
return (*(__int64 (__fastcall **)(__int64, __int64, _QWORD, _QWORD, __int64))(a1 + 24))(a1, a2, 0LL, a3, a4);
}

original_code:
int32_t i2c_read (struct i2c_bus* bus, uint32_t address, uint32_t to_read, uint8_t* data)
{
    return bus->transfer(bus, address, 0, to_read, data);
}

canonical_original_code:
int i2c_read(struct i2c_bus *bus, unsigned int address, unsigned int to_read, unsigned char *data)
{
    return bus->transfer(bus, address, 0, to_read, data);
}


decompiled_code:
__int64 __fastcall i2c_scan(__int64 a1, _OWORD *a2)
{
__int64 v2; // r12
int i; // ebx

if ( a1 )
{
v2 = 0LL;
*a2 = 0LL;
for ( i = 0; i != 128; ++i )
{
if ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 32))(a1, (unsigned int)i) )
{
v2 = (unsigned int)(v2 + 1);
*((_BYTE *)a2 + (i >> 3)) |= 1 << (i & 7);
}
}
trace_printf("i2c.c", 84LL, 16LL, "%s (0x%X): ndev=%d", *(const char **)a1, a1, v2);
}
else
{
LODWORD(v2) = -17;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _OWORD *a2)
{
__int64 v2; // r12
int i; // ebx

if ( a1 )
{
v2 = 0LL;
*a2 = 0LL;
for ( i = 0; i != 128; ++i )
{
if ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 32))(a1, (unsigned int)i) )
{
v2 = (unsigned int)(v2 + 1);
*((_BYTE *)a2 + (i >> 3)) |= 1 << (i & 7);
}
}
trace_printf("i2c.c", 84LL, 16LL, "%s (0x%X): ndev=%d", *(const char **)a1, a1, v2);
}
else
{
LODWORD(v2) = -17;
}
return (unsigned int)v2;
}

original_code:
int32_t i2c_scan(struct i2c_bus* bus, uint8_t* data)
{
    if (!bus)
        return -0x11;
    int address;
    const int first_valid_address = 0;
    const int last_valid_address = 0x7f;
    memset((void*)data, 0, 16);
    int found = 0;
    for (address = first_valid_address; address <= last_valid_address; address++)
    {
 int res = bus->scan(bus, address);
 if (res)
 {
     int offset = address >> 3;
     int bit = (1 << (address%8));
     data[offset] |= bit;
     found++;
 }
    }
    trace_printf("i2c.c", 84, 0x10,"%s (0x%X): ndev=%d",bus->name,bus,found);;
    return found;
}

canonical_original_code:
int i2c_scan(struct i2c_bus *bus, unsigned char *data)
{
    if (!bus)
        return -0x11;
    int address;
    int first_valid_address = 0;
    int last_valid_address = 0x7f;
    memset((void *)data, 0, 16);
    int found = 0;
    for (address = first_valid_address; address <= last_valid_address; address++)
    {
 int res = bus->scan(bus, address);
 if (res)
 {
     int offset = address >> 3;
     int bit = (1 << (address%8));
     data[offset] |= bit;
     found++;
 }
    }
    trace_printf("i2c.c", 84, 0x10,"%s (0x%X): ndev=%d",bus->name,bus,found);;
    return found;
}

variable_types: address int

variable_types: found int

variable_types: res int

variable_types: offset int

variable_types: bit int


decompiled_code:
void __noreturn shw_exit_fatal()
{
trace_printf("init.c", 42LL, 3LL, "exiting due to fatal error.");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func1()
{
trace_printf("init.c", 42LL, 3LL, "exiting due to fatal error.");
exit(-1);
}

original_code:
int shw_exit_fatal()
{
 trace_printf("init.c", 42, 3, "exiting due to fatal error.");;
 exit(-1);
}


decompiled_code:
void trace_log_stderr()
{
trace_to_stderr = 1;
}

canonical_decompiled_code:
void func0()
{
trace_to_stderr = 1;
}


decompiled_code:
int trace_printf(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
int v5; // eax
int result; // eax
int v7; // [rsp+Eh] [rbp-10Ah] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-100h] BYREF
char s[48]; // [rsp+30h] [rbp-E8h] BYREF

if ( a3 == 3 )
{
v7 = 2695464;
}
else if ( a3 == 16 )
{
v7 = 2705704;
}
else
{
v5 = 2704680;
if ( a3 != 2 )
v5 = 2703144;
v7 = v5;
}
snprintf(s, 0x28uLL, "%s [%s:%d]", (const char *)&v7, a1, a2);
va_start(arg, a4);
if ( trace_file )
{
fprintf(trace_file, "%-24s ", s);
vfprintf(trace_file, a4, arg);
fflush(trace_file);
fputc(10, trace_file);
}
result = trace_to_stderr;
if ( trace_to_stderr )
{
fprintf(stderr, "%-24s ", s);
vfprintf(stderr, a4, arg);
result = fputc(10, stderr);
}
return result;
}

canonical_decompiled_code:
int func1(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
int v5; // eax
int result; // eax
int v7; // [rsp+Eh] [rbp-10Ah] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-100h] BYREF
char s[48]; // [rsp+30h] [rbp-E8h] BYREF

if ( a3 == 3 )
{
v7 = 2695464;
}
else if ( a3 == 16 )
{
v7 = 2705704;
}
else
{
v5 = 2704680;
if ( a3 != 2 )
v5 = 2703144;
v7 = v5;
}
snprintf(s, 0x28uLL, "%s [%s:%d]", (const char *)&v7, a1, a2);
va_start(arg, a4);
if ( trace_file )
{
fprintf(trace_file, "%-24s ", s);
vfprintf(trace_file, a4, arg);
fflush(trace_file);
fputc(10, trace_file);
}
result = trace_to_stderr;
if ( trace_to_stderr )
{
fprintf(stderr, "%-24s ", s);
vfprintf(stderr, a4, arg);
result = fputc(10, stderr);
}
return result;
}

original_code:
void trace_printf(const char *fname, int lineno, int level, const char *fmt, ...)
{
    char linestr[40];
    char typestr[10];
    va_list vargs;
    switch (level)
    {
            case 0x10: strcpy(typestr, "(I)"); break;
            case 2: strcpy(typestr, "(E)"); break;
            case 3: strcpy(typestr, "(!)"); break;
            default: strcpy(typestr, "(?)"); break;
    }
    snprintf(linestr, 40, "%s [%s:%d]", typestr, fname, lineno);
    __builtin_va_start(vargs,fmt);
    if(trace_file)
    {
        fprintf(trace_file, "%-24s ", linestr);
        vfprintf(trace_file, fmt, vargs);
        fflush(trace_file);
  fprintf(trace_file,"\n");
 }
    if(trace_to_stderr)
    {
        fprintf(stderr, "%-24s ", linestr);
        vfprintf(stderr, fmt, vargs);
  fprintf(stderr,"\n");
    }
    __builtin_va_end(vargs);
}

canonical_original_code:
void trace_printf(char *fname, int lineno, int level, char *fmt, ...)
{
    char linestr[40];
    char typestr[10];
    __builtin_va_list vargs;
    switch (level)
    {
            case 0x10: strcpy(typestr, "(I)"); break;
            case 2: strcpy(typestr, "(E)"); break;
            case 3: strcpy(typestr, "(!)"); break;
            default: strcpy(typestr, "(?)"); break;
    }
    snprintf(linestr, 40, "%s [%s:%d]", typestr, fname, lineno);
    __builtin_va_start(vargs,fmt);
    if(trace_file)
    {
        fprintf(trace_file, "%-24s ", linestr);
        vfprintf(trace_file, fmt, vargs);
        fflush(trace_file);
  fprintf(trace_file,"\n");
 }
    if(trace_to_stderr)
    {
        fprintf(stderr, "%-24s ", linestr);
        vfprintf(stderr, fmt, vargs);
  fprintf(stderr,"\n");
    }
    __builtin_va_end(vargs);
}

variable_types:
fname
char *

variable_types: lineno int

variable_types: level int

variable_types:
fmt
char *

variable_types:
linestr
char [40]

variable_types:
typestr
char [10]


decompiled_code:
__suseconds_t tm_get_tics()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

tz = 0LL;
gettimeofday(&tv, &tz);
return tv.tv_usec + 1000000 * tv.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func0()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

tz = 0LL;
gettimeofday(&tv, &tz);
return tv.tv_usec + 1000000 * tv.tv_sec;
}

original_code:
static inline uint64_t tm_get_tics()
{
 struct timezone tz = {0, 0};
 struct timeval tv;
 gettimeofday(&tv, &tz);
 return (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t) tv.tv_usec;
}

canonical_original_code:
static inline unsigned long tm_get_tics()
{
 struct timezone tz = {0, 0};
 struct timeval tv;
 gettimeofday(&tv, &tz);
 return (unsigned long) tv.tv_sec * 1000000ULL + (unsigned long) tv.tv_usec;
}

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

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

return_type: unsigned long


decompiled_code:
__int64 __fastcall tmo_expired(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // er12

LOBYTE(result) = (unsigned __int64)(tm_get_tics() - *(_QWORD *)(a1 + 8)) > *(_QWORD *)(a1 + 16);
v2 = (unsigned __int8)result;
if ( !*(_DWORD *)a1 || !(_BYTE)result )
return (unsigned __int8)result;
*(_QWORD *)(a1 + 8) = tm_get_tics();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // er12

LOBYTE(result) = (unsigned __int64)(func0() - *(_QWORD *)(a1 + 8)) > *(_QWORD *)(a1 + 16);
v2 = (unsigned __int8)result;
if ( !*(_DWORD *)a1 || !(_BYTE)result )
return (unsigned __int8)result;
*(_QWORD *)(a1 + 8) = func0();
return v2;
}

original_code:
static inline int tmo_expired(timeout_t *tmo)
{
 int expired = (tm_get_tics() - tmo->start_tics > tmo->timeout);
 if(tmo->repeat && expired)
  tmo->start_tics = tm_get_tics();
 return expired;
}

canonical_original_code:
static inline int tmo_expired(struct timeout_t *tmo)
{
 int expired = (tm_get_tics() - tmo->start_tics > tmo->timeout);
 if(tmo->repeat && expired)
  tmo->start_tics = tm_get_tics();
 return expired;
}

variable_types: struct timeout_t { int repeat; unsigned long start_tics; unsigned long timeout; } *

variable_types: expired int


decompiled_code:
__int64 hal_init_timing()
{
unsigned int v0; // er12
unsigned int v2; // [rsp+Ch] [rbp-23Ch] BYREF
char v3[32]; // [rsp+10h] [rbp-238h] BYREF
char s1[128]; // [rsp+30h] [rbp-218h] BYREF
char v5[408]; // [rsp+B0h] [rbp-198h] BYREF

v2 = 0;
if ( (int)rts_connect() < 0 )
{
v0 = -1;
trace_printf("hal_timing.c", 31LL, 2LL, "Failed to establish communication with the RT subsystem.");
}
else
{
if ( (int)hal_config_get_string("timing.mode", s1, 128LL) < 0 )
{
trace_printf(
"hal_timing.c",
37LL,
16LL,
"Not timing mode specified in the config file. Defaulting to Boundary Clock.");
timing_mode = 2;
strcpy(s1, "BoundaryClock");
}
else if ( !strcasecmp(s1, "GrandMaster") || !strcasecmp(s1, "GM") )
{
timing_mode = 0;
}
else if ( !strcasecmp(s1, "FreeMaster") || !strcasecmp(s1, "FM") )
{
timing_mode = 1;
}
else
{
if ( strcasecmp(s1, "BoundaryClock") && strcasecmp(s1, "BC") )
{
v0 = -1;
trace_printf("hal_timing.c", 48LL, 2LL, "Unrecognized timing mode '%s'", s1);
return v0;
}
timing_mode = 2;
}
trace_printf("hal_timing.c", 53LL, 16LL, "Timing mode: %s", s1);
if ( timing_mode )
{
if ( (unsigned int)(timing_mode - 1) <= 1 )
{
rts_set_mode(2LL);
tmo_init_constprop_0_isra_0((__int64)v3, 0x2710u);
}
}
else
{
rts_set_mode(1LL);
tmo_init_constprop_0_isra_0((__int64)v3, 0xEA60u);
}
while ( 1 )
{
v0 = tmo_expired((__int64)v3);
if ( v0 )
{
trace_printf(
"hal_timing.c",
76LL,
2LL,
"Can't lock the PLL. If running in the GrandMaster mode, are you sure the 1-PPS and 10 MHz reference clock sign"
"als are properly connected?");
return (unsigned int)-1;
}
if ( (int)rts_get_state(v5) < 0 )
return (unsigned int)-1;
if ( (v5[360] & 1) != 0 )
break;
usleep(0x186A0u);
}
if ( (int)hal_config_get_int("timing.use_nmea", &v2) >= 0 && !timing_mode )
{
v0 = v2;
if ( v2 )
{
v0 = 0;
trace_printf("hal_timing.c", 95LL, 16LL, "re-syncing to UTC from serial port");
nmea_resync_ppsgen("/dev/ttyS2");
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12
unsigned int v2; // [rsp+Ch] [rbp-23Ch] BYREF
char v3[32]; // [rsp+10h] [rbp-238h] BYREF
char s1[128]; // [rsp+30h] [rbp-218h] BYREF
char v5[408]; // [rsp+B0h] [rbp-198h] BYREF

v2 = 0;
if ( (int)rts_connect() < 0 )
{
v0 = -1;
trace_printf("hal_timing.c", 31LL, 2LL, "Failed to establish communication with the RT subsystem.");
}
else
{
if ( (int)hal_config_get_string("timing.mode", s1, 128LL) < 0 )
{
trace_printf(
"hal_timing.c",
37LL,
16LL,
"Not timing mode specified in the config file. Defaulting to Boundary Clock.");
timing_mode = 2;
strcpy(s1, "BoundaryClock");
}
else if ( !strcasecmp(s1, "GrandMaster") || !strcasecmp(s1, "GM") )
{
timing_mode = 0;
}
else if ( !strcasecmp(s1, "FreeMaster") || !strcasecmp(s1, "FM") )
{
timing_mode = 1;
}
else
{
if ( strcasecmp(s1, "BoundaryClock") && strcasecmp(s1, "BC") )
{
v0 = -1;
trace_printf("hal_timing.c", 48LL, 2LL, "Unrecognized timing mode '%s'", s1);
return v0;
}
timing_mode = 2;
}
trace_printf("hal_timing.c", 53LL, 16LL, "Timing mode: %s", s1);
if ( timing_mode )
{
if ( (unsigned int)(timing_mode - 1) <= 1 )
{
rts_set_mode(2LL);
func2((__int64)v3, 0x2710u);
}
}
else
{
rts_set_mode(1LL);
func2((__int64)v3, 0xEA60u);
}
while ( 1 )
{
v0 = func1((__int64)v3);
if ( v0 )
{
trace_printf(
"hal_timing.c",
76LL,
2LL,
"Can't lock the PLL. If running in the GrandMaster mode, are you sure the 1-PPS and 10 MHz reference clock sign"
"als are properly connected?");
return (unsigned int)-1;
}
if ( (int)rts_get_state(v5) < 0 )
return (unsigned int)-1;
if ( (v5[360] & 1) != 0 )
break;
usleep(0x186A0u);
}
if ( (int)hal_config_get_int("timing.use_nmea", &v2) >= 0 && !timing_mode )
{
v0 = v2;
if ( v2 )
{
v0 = 0;
trace_printf("hal_timing.c", 95LL, 16LL, "re-syncing to UTC from serial port");
nmea_resync_ppsgen("/dev/ttyS2");
}
}
}
return v0;
}

original_code:
int hal_init_timing()
{
 char str[128];
 timeout_t lock_tmo;
 int use_utc = 0;
 if(rts_connect() < 0)
 {
  trace_printf("hal_timing.c", 31, 2, "Failed to establish communication with the RT subsystem.");;
  return -1;
 }
  if( hal_config_get_string("timing.mode", str, sizeof(str)) < 0)
  {
   trace_printf("hal_timing.c", 37, 0x10,"Not timing mode specified in the config file. Defaulting to Boundary Clock.");;
   timing_mode = 2;
   strcpy (str, "BoundaryClock");
  } else {
   if(!strcasecmp(str, "GrandMaster") || !strcasecmp(str, "GM"))
    timing_mode = 0;
   else if (!strcasecmp(str, "FreeMaster") || !strcasecmp(str, "FM"))
    timing_mode = 1;
   else if (!strcasecmp(str, "BoundaryClock") || !strcasecmp(str,"BC"))
    timing_mode = 2;
   else {
    trace_printf("hal_timing.c", 48, 2, "Unrecognized timing mode '%s'", str);;
    return -1;
   }
  }
 trace_printf("hal_timing.c", 53, 0x10, "Timing mode: %s", str);;
 switch(timing_mode)
 {
  case 0:
   rts_set_mode(1);
   tmo_init(&lock_tmo, 60000, 0);
   break;
  case 1:
  case 2:
   rts_set_mode(2);
   tmo_init(&lock_tmo, 10000, 0);
   break;
 }
 while(1)
 {
  struct rts_pll_state pstate;
  if(tmo_expired(&lock_tmo))
  {
   trace_printf("hal_timing.c", 76, 2, "Can't lock the PLL. If running in the GrandMaster mode, are you sure the 1-PPS and 10 MHz reference clock signals are properly connected?");;
   return -1;
  }
  if(rts_get_state(&pstate) < 0)
   return -1;
  if(pstate.flags & (1<<0))
   break;
  usleep(100000);
 }
 if(hal_config_get_int("timing.use_nmea", &use_utc) < 0)
  use_utc = 0;
 if(timing_mode == 0 && use_utc)
 {
  trace_printf("hal_timing.c", 95, 0x10, "re-syncing to UTC from serial port");;
  nmea_resync_ppsgen("/dev/ttyS2");
 }
 return 0;
}

canonical_original_code:
int hal_init_timing()
{
 char str[128];
 struct timeout_t lock_tmo;
 int use_utc = 0;
 if(rts_connect() < 0)
 {
  trace_printf("hal_timing.c", 31, 2, "Failed to establish communication with the RT subsystem.");;
  return -1;
 }
  if( hal_config_get_string("timing.mode", str, sizeof(str)) < 0)
  {
   trace_printf("hal_timing.c", 37, 0x10,"Not timing mode specified in the config file. Defaulting to Boundary Clock.");;
   timing_mode = 2;
   strcpy (str, "BoundaryClock");
  } else {
   if(!strcasecmp(str, "GrandMaster") || !strcasecmp(str, "GM"))
    timing_mode = 0;
   else if (!strcasecmp(str, "FreeMaster") || !strcasecmp(str, "FM"))
    timing_mode = 1;
   else if (!strcasecmp(str, "BoundaryClock") || !strcasecmp(str,"BC"))
    timing_mode = 2;
   else {
    trace_printf("hal_timing.c", 48, 2, "Unrecognized timing mode '%s'", str);;
    return -1;
   }
  }
 trace_printf("hal_timing.c", 53, 0x10, "Timing mode: %s", str);;
 switch(timing_mode)
 {
  case 0:
   rts_set_mode(1);
   tmo_init(&lock_tmo, 60000, 0);
   break;
  case 1:
  case 2:
   rts_set_mode(2);
   tmo_init(&lock_tmo, 10000, 0);
   break;
 }
 while(1)
 {
  struct rts_pll_state pstate;
  if(tmo_expired(&lock_tmo))
  {
   trace_printf("hal_timing.c", 76, 2, "Can't lock the PLL. If running in the GrandMaster mode, are you sure the 1-PPS and 10 MHz reference clock signals are properly connected?");;
   return -1;
  }
  if(rts_get_state(&pstate) < 0)
   return -1;
  if(pstate.flags & (1<<0))
   break;
  usleep(100000);
 }
 if(hal_config_get_int("timing.use_nmea", &use_utc) < 0)
  use_utc = 0;
 if(timing_mode == 0 && use_utc)
 {
  trace_printf("hal_timing.c", 95, 0x10, "re-syncing to UTC from serial port");;
  nmea_resync_ppsgen("/dev/ttyS2");
 }
 return 0;
}

variable_types:
str
char [128]

variable_types: struct timeout_t { int repeat; unsigned long start_tics; unsigned long timeout; }

variable_types: struct rts_pll_state { struct channel { unsigned int priority; int phase_setpoint; int phase_current; int phase_loopback; unsigned int flags; } channels[18]; unsigned int flags; int holdover_duration; unsigned int current_ref; unsigned int mode; unsigned int delock_count; }

user_defined_types: struct rts_pll_state { struct channel channels[18]; unsigned int flags; int holdover_duration; unsigned int current_ref; unsigned int mode; unsigned int delock_count; }


decompiled_code:
__int64 hal_get_timing_mode()
{
return (unsigned int)timing_mode;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)timing_mode;
}

original_code:
int hal_get_timing_mode()
{
 return timing_mode;
}


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

gettimeofday(&v3, 0LL);
v1 = a1 + v3.tv_usec + 1000000 * v3.tv_sec;
do
{
gettimeofday(&v3, 0LL);
result = v3.tv_usec + 1000000 * v3.tv_sec;
}
while ( result <= v1 );
return result;
}

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

gettimeofday(&v3, 0LL);
v1 = a1 + v3.tv_usec + 1000000 * v3.tv_sec;
do
{
gettimeofday(&v3, 0LL);
result = v3.tv_usec + 1000000 * v3.tv_sec;
}
while ( result <= v1 );
return result;
}

original_code:
void shw_udelay(uint32_t microseconds)
{
    uint64_t t_start, t_cur;
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    t_start = (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t)tv.tv_usec;
    do {
    gettimeofday(&tv, ((void *)0));
    t_cur = (uint64_t) tv.tv_sec * 1000000ULL + (uint64_t)tv.tv_usec;
    } while(t_cur <= t_start + (uint64_t) microseconds);
}

canonical_original_code:
void shw_udelay(unsigned int microseconds)
{
    unsigned long t_start; unsigned long t_cur;
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    t_start = (unsigned long) tv.tv_sec * 1000000ULL + (unsigned long)tv.tv_usec;
    do {
    gettimeofday(&tv, ((void *)0));
    t_cur = (unsigned long) tv.tv_sec * 1000000ULL + (unsigned long)tv.tv_usec;
    } while(t_cur <= t_start + (unsigned long) microseconds);
}

variable_types:
microseconds
unsigned int

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


decompiled_code:
void *__fastcall shw_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
trace_printf("util.c", 30LL, 3LL, "malloc(%d) failed!", a1);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
trace_printf("util.c", 30LL, 3LL, "malloc(%d) failed!", a1);
exit(-1);
}
return result;
}

original_code:
void *shw_malloc(size_t nbytes)
{
        void *p = malloc(nbytes);
        if(!p)
        {
                trace_printf("util.c", 30, 3, "malloc(%d) failed!", nbytes);;
                exit(-1);
        }
        return p;
}

canonical_original_code:
void *shw_malloc(unsigned long nbytes)
{
        void *p = malloc(nbytes);
        if(!p)
        {
                trace_printf("util.c", 30, 3, "malloc(%d) failed!", nbytes);;
                exit(-1);
        }
        return p;
}

variable_types:
nbytes
unsigned long

variable_types:
p
void *

return_type: void *


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

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

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

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

variable_types:
ptr
void *


decompiled_code:
__suseconds_t shw_get_tics()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

tz = 0LL;
gettimeofday(&tv, &tz);
return tv.tv_usec + 1000000 * tv.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func3()
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

tz = 0LL;
gettimeofday(&tv, &tz);
return tv.tv_usec + 1000000 * tv.tv_sec;
}

original_code:
uint64_t shw_get_tics()
{
  struct timeval tv;
  struct timezone tz={0,0};
  gettimeofday(&tv, &tz);
  return (uint64_t)tv.tv_usec + (uint64_t)tv.tv_sec * 1000000ULL;
}

canonical_original_code:
unsigned long shw_get_tics()
{
  struct timeval tv;
  struct timezone tz = {0,0};
  gettimeofday(&tv, &tz);
  return (unsigned long)tv.tv_usec + (unsigned long)tv.tv_sec * 1000000ULL;
}

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


original_code:
const char *shw_2binary(uint8_t x)
{
    static char b[9];
    int z;
    char *p=b;
    for (z=0x80; z > 0; z >>= 1)
    {
       *p++=(((x & z) == z) ? '1' : '0');
    }
    *p='\0';
    return b;
}

canonical_original_code:
char *shw_2binary(unsigned char x)
{
    static char b[9];
    int z;
    char *p = b;
    for (z=0x80; z > 0; z >>= 1)
    {
       *p++=(((x & z) == z) ? '1' : '0');
    }
    *p='\0';
    return b;
}

variable_types:
x
unsigned char

variable_types:
b
char [9]

variable_types: z int

variable_types:
p
char *

return_type: char *


daemonize

decompiled_code:
__pid_t daemonize()
{
__pid_t result; // eax
__pid_t v1; // eax

result = getppid();
if ( result != 1 )
{
v1 = fork();
if ( v1 < 0 )
goto LABEL_9;
if ( v1 )
exit(0);
umask(0);
if ( setsid() < 0 || chdir("/") < 0 )
LABEL_9:
exit(1);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
result = (unsigned int)freopen("/dev/null", "w", stderr);
}
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax
__pid_t v1; // eax

result = getppid();
if ( result != 1 )
{
v1 = fork();
if ( v1 < 0 )
goto LABEL_9;
if ( v1 )
exit(0);
umask(0);
if ( setsid() < 0 || chdir("/") < 0 )
LABEL_9:
exit(1);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
result = (unsigned int)freopen("/dev/null", "w", stderr);
}
return result;
}

original_code:
void daemonize(void)
{
    pid_t pid, sid;
    if ( getppid() == 1 ) return;
    pid = fork();
    if (pid < 0) {
        exit(1);
    }
    if (pid > 0) {
        exit(0);
    }
    umask(0);
    sid = setsid();
    if (sid < 0) {
        exit(1);
    }
    if ((chdir("/")) < 0) {
        exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/dev/null", "w", stderr);
}

canonical_original_code:
void daemonize()
{
    int pid; int sid;
    if ( getppid() == 1 ) return;
    pid = fork();
    if (pid < 0) {
        exit(1);
    }
    if (pid > 0) {
        exit(0);
    }
    umask(0);
    sid = setsid();
    if (sid < 0) {
        exit(1);
    }
    if ((chdir("/")) < 0) {
        exit(1);
    }
    freopen( "/dev/null", "r", stdin);
    freopen( "/dev/null", "w", stdout);
    freopen( "/dev/null", "w", stderr);
}

variable_types: pid int

variable_types: sid int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s [-dh] [-p <polly>] [-r <time>] [-t <time>]\n"
"\t-d daemonize\n"
"\t-h help\n"
"\t-p polynomial for hash calculation. Possible values are CCITT, IBM, DECT\n"
"\t-r aging resolution (in sec). 20 sec by default\n"
"\t-t aging time (10 to 10000 sec). 300 sec by default.\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(
stderr,
"Usage: %s [-dh] [-p <polly>] [-r <time>] [-t <time>]\n"
"\t-d daemonize\n"
"\t-h help\n"
"\t-p polynomial for hash calculation. Possible values are CCITT, IBM, DECT\n"
"\t-r aging resolution (in sec). 20 sec by default\n"
"\t-t aging time (10 to 10000 sec). 300 sec by default.\n",
a1);
exit(1);
}

original_code:
void usage(char *name)
{
    fprintf(stderr,
        "Usage: %s [-dh] [-p <polly>] [-r <time>] [-t <time>]\n"
        "\t-d   daemonize\n"
        "\t-h   help\n"
        "\t-p   polynomial for hash calculation. Possible values are CCITT, IBM, DECT\n"
        "\t-r   aging resolution (in sec). 20 sec by default\n"
        "\t-t   aging time (10 to 10000 sec). 300 sec by default.\n",
        name);
    exit(1);
}

variable_types:
name
char *


decompiled_code:
void term_restore(void)
{
tcsetattr(0, 0, &oldkey);
}

canonical_decompiled_code:
void func0(void)
{
tcsetattr(0, 0, &oldkey);
}

original_code:
void term_restore(void)
{
 tcsetattr(0,0,&oldkey);
}

canonical_original_code:
void term_restore()
{
 tcsetattr(0,0,&oldkey);
}


decompiled_code:
int term_init()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
speed_t v2; // eax

fcntl(0, 4, 2048LL);
tcgetattr(0, &oldkey);
v0 = _mm_load_si128((const __m128i *)&oldkey.c_line);
v1 = _mm_load_si128((const __m128i *)&oldkey.c_cc[15]);
*(_QWORD *)&newkey.c_cc[31] = *(_QWORD *)&oldkey.c_cc[31];
v2 = oldkey.c_ospeed;
*(__m128i *)&newkey.c_line = v0;
newkey.c_ospeed = v2;
*(_QWORD *)&newkey.c_iflag = 0x500000004LL;
*(_QWORD *)&newkey.c_cflag = 2147485885LL;
*(__m128i *)&newkey.c_cc[15] = v1;
*(_WORD *)&newkey.c_cc[5] = 256;
tcflush(0, 0);
tcsetattr(0, 0, &newkey);
return atexit(term_restore);
}

canonical_decompiled_code:
int func1()
{
__m128i v0; // xmm0
__m128i v1; // xmm1
speed_t v2; // eax

fcntl(0, 4, 2048LL);
tcgetattr(0, &oldkey);
v0 = _mm_load_si128((const __m128i *)&oldkey.c_line);
v1 = _mm_load_si128((const __m128i *)&oldkey.c_cc[15]);
*(_QWORD *)&newkey.c_cc[31] = *(_QWORD *)&oldkey.c_cc[31];
v2 = oldkey.c_ospeed;
*(__m128i *)&newkey.c_line = v0;
newkey.c_ospeed = v2;
*(_QWORD *)&newkey.c_iflag = 0x500000004LL;
*(_QWORD *)&newkey.c_cflag = 2147485885LL;
*(__m128i *)&newkey.c_cc[15] = v1;
*(_WORD *)&newkey.c_cc[5] = 256;
tcflush(0, 0);
tcsetattr(0, 0, &newkey);
return atexit(term_restore);
}

original_code:
void term_init(void)
{
 fcntl(0, 4, 04000);
 tcgetattr(0,&oldkey);
 memcpy(&newkey, &oldkey, sizeof(struct termios));
 newkey.c_cflag = 0000015 | 020000000000 | 0000060 | 0004000 | 0000200;
 newkey.c_iflag = 0000004;
 newkey.c_oflag = 0000001 |0000004;
 newkey.c_lflag = 0;
 newkey.c_cc[6]=1;
 newkey.c_cc[5]=0;
 tcflush(0, 0);
 tcsetattr(0,0,&newkey);
 atexit(term_restore);
}

canonical_original_code:
void term_init()
{
 fcntl(0, 4, 04000);
 tcgetattr(0,&oldkey);
 memcpy(&newkey, &oldkey, sizeof(struct termios));
 newkey.c_cflag = 0000015 | 020000000000 | 0000060 | 0004000 | 0000200;
 newkey.c_iflag = 0000004;
 newkey.c_oflag = 0000001 |0000004;
 newkey.c_lflag = 0;
 newkey.c_cc[6]=1;
 newkey.c_cc[5]=0;
 tcflush(0, 0);
 tcsetattr(0,0,&newkey);
 atexit(term_restore);
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
_BOOL8 term_poll()
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = 0;
fds.events = 3;
return poll(&fds, 1uLL, 0) > 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = 0;
fds.events = 3;
return poll(&fds, 1uLL, 0) > 0;
}

original_code:
int term_poll(void)
{
 struct pollfd pfd;
 pfd.fd = 0;
 pfd.events = 0x001 | 0x002;
 if(poll(&pfd,1,0)>0)return 1;
 return 0;
}

canonical_original_code:
int term_poll()
{
 struct pollfd pfd;
 pfd.fd = 0;
 pfd.events = 0x001 | 0x002;
 if(poll(&pfd,1,0)>0)return 1;
 return 0;
}

variable_types: struct pollfd { int fd; short events; short revents; }


decompiled_code:
__int64 term_get()
{
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( read(0, buf, 1uLL) == 1 )
result = (unsigned __int8)buf[0];
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( read(0, buf, 1uLL) == 1 )
result = (unsigned __int8)buf[0];
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int term_get(void)
{
 unsigned char c;
 int q;
 if(read(0, &c, 1 ) == 1)
 {
  q=c;
 } else q=-1;
 return q;
}

canonical_original_code:
int term_get()
{
 unsigned char c;
 int q;
 if(read(0, &c, 1 ) == 1)
 {
  q=c;
 } else q=-1;
 return q;
}

variable_types:
c
unsigned char

variable_types: q int


decompiled_code:
int term_cprintf(unsigned __int8 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
printf("\x1B[0%d;3%dm", (unsigned int)(a1 >> 7) + 1, a1 & 0x7F);
vprintf(a2, arg);
return fflush(stdout);
}

canonical_decompiled_code:
int func4(unsigned __int8 a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
printf("\x1B[0%d;3%dm", (unsigned int)(a1 >> 7) + 1, a1 & 0x7F);
vprintf(a2, arg);
return fflush(stdout);
}

original_code:
void term_cprintf(int color, const char *fmt, ...)
{
 va_list ap;
 printf("\033[0%d;3%dm",color & 0x80 ? 2:1, color&0x7f);
 __builtin_va_start(ap,fmt);
 vprintf(fmt, ap);
 __builtin_va_end(ap);
 fflush(stdout);
}

canonical_original_code:
void term_cprintf(int color, char *fmt, ...)
{
 __builtin_va_list ap;
 printf("\033[0%d;3%dm",color & 0x80 ? 2:1, color&0x7f);
 __builtin_va_start(ap,fmt);
 vprintf(fmt, ap);
 __builtin_va_end(ap);
 fflush(stdout);
}

variable_types: color int

variable_types:
fmt
char *


decompiled_code:
int term_pcprintf(unsigned int a1, unsigned int a2, unsigned __int8 a3, const char *a4, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a4);
printf("\x1B[%d;%df", a1, a2);
printf("\x1B[0%d;3%dm", (unsigned int)(a3 >> 7) + 1, a3 & 0x7F);
vprintf(a4, arg);
return fflush(stdout);
}

canonical_decompiled_code:
int func5(unsigned int a1, unsigned int a2, unsigned __int8 a3, const char *a4, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a4);
printf("\x1B[%d;%df", a1, a2);
printf("\x1B[0%d;3%dm", (unsigned int)(a3 >> 7) + 1, a3 & 0x7F);
vprintf(a4, arg);
return fflush(stdout);
}

original_code:
void term_pcprintf(int row, int col, int color, const char *fmt, ...)
{
 va_list ap;
 printf("\033[%d;%df", row, col);
 printf("\033[0%d;3%dm",color & 0x80 ? 2:1, color&0x7f);
 __builtin_va_start(ap,fmt);
 vprintf(fmt, ap);
 __builtin_va_end(ap);
 fflush(stdout);
}

canonical_original_code:
void term_pcprintf(int row, int col, int color, char *fmt, ...)
{
 __builtin_va_list ap;
 printf("\033[%d;%df", row, col);
 printf("\033[0%d;3%dm",color & 0x80 ? 2:1, color&0x7f);
 __builtin_va_start(ap,fmt);
 vprintf(fmt, ap);
 __builtin_va_end(ap);
 fflush(stdout);
}

variable_types: row int

variable_types: col int


decompiled_code:
int term_clear()
{
return printf("\x1B[2J\x1B[1;1H");
}

canonical_decompiled_code:
int func6()
{
return printf("\x1B[2J\x1B[1;1H");
}

original_code:
void term_clear(void)
{
 printf("\033[2J\033[1;1H");
}


decompiled_code:
int print_gw_info()
{
char v1[3]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 v2; // [rsp+3h] [rbp-25h]
unsigned __int8 v3; // [rsp+4h] [rbp-24h]
unsigned __int8 v4; // [rsp+5h] [rbp-23h]
unsigned __int8 v5; // [rsp+6h] [rbp-22h]
unsigned __int8 v6; // [rsp+7h] [rbp-21h]
unsigned int v7; // [rsp+8h] [rbp-20h]
unsigned int v8; // [rsp+Ch] [rbp-1Ch]
unsigned int v9; // [rsp+10h] [rbp-18h]

shw_fpga_mmap_init();
puts("Reading GW info");
if ( (int)shw_hwiu_gwver(v1) < 0 )
return puts("Could not get GW version info");
if ( v2 != 1 )
printf("WARNING: dealing with unsupported info struct, sw:%u, gw:%u\n", 1LL, v2);
printf("WRSW Gateware: version %u.%u\n", (unsigned __int8)v1[1], (unsigned __int8)v1[0]);
printf("WRSW Gateware: build %02u/%02u/%02u.%02u\n", v6, v5, v4, v3);
printf("WRSW Gateware: wr_switch_hdl commit: %x\n", v7);
printf("WRSW Gateware: general-cores commit: %x\n", v8);
return printf("WRSW Gateware: wr-cores commit: %x\n", v9);
}

canonical_decompiled_code:
int func1()
{
char v1[3]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int8 v2; // [rsp+3h] [rbp-25h]
unsigned __int8 v3; // [rsp+4h] [rbp-24h]
unsigned __int8 v4; // [rsp+5h] [rbp-23h]
unsigned __int8 v5; // [rsp+6h] [rbp-22h]
unsigned __int8 v6; // [rsp+7h] [rbp-21h]
unsigned int v7; // [rsp+8h] [rbp-20h]
unsigned int v8; // [rsp+Ch] [rbp-1Ch]
unsigned int v9; // [rsp+10h] [rbp-18h]

shw_fpga_mmap_init();
puts("Reading GW info");
if ( (int)shw_hwiu_gwver(v1) < 0 )
return puts("Could not get GW version info");
if ( v2 != 1 )
printf("WARNING: dealing with unsupported info struct, sw:%u, gw:%u\n", 1LL, v2);
printf("WRSW Gateware: version %u.%u\n", (unsigned __int8)v1[1], (unsigned __int8)v1[0]);
printf("WRSW Gateware: build %02u/%02u/%02u.%02u\n", v6, v5, v4, v3);
printf("WRSW Gateware: wr_switch_hdl commit: %x\n", v7);
printf("WRSW Gateware: general-cores commit: %x\n", v8);
return printf("WRSW Gateware: wr-cores commit: %x\n", v9);
}

original_code:
void print_gw_info()
{
 struct gw_info info;
 shw_fpga_mmap_init();
 printf("Reading GW info\n");
 if( shw_hwiu_gwver(&info) < 0 ) {
  printf("Could not get GW version info\n");
  return;
 }
 if( info.struct_ver != 1 )
  printf("WARNING: dealing with unsupported info struct, sw:%u, gw:%u\n",
  1, info.struct_ver);
 printf("WRSW Gateware: version %u.%u\n", info.ver_major, info.ver_minor);
 printf("WRSW Gateware: build %02u/%02u/%02u.%02u\n", info.build_day,
  info.build_month, info.build_year, info.build_no);
 printf("WRSW Gateware: wr_switch_hdl commit: %x\n", info.switch_hdl_hash);
 printf("WRSW Gateware: general-cores commit: %x\n", info.general_cores_hash);
 printf("WRSW Gateware: wr-cores commit: %x\n", info.wr_cores_hash);
}

variable_types: struct gw_info { unsigned char ver_minor; unsigned char nwords; unsigned char struct_ver; unsigned char build_no; unsigned int switch_hdl_hash; unsigned int general_cores_hash; unsigned int wr_cores_hash; }


repo: neuro-sys/neuro-bot

decompiled_code:
char *__fastcall parse_prefix_nickname(char *dest, char *s)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // r13
char *v5; // rax
size_t v6; // rbx
size_t v7; // rax

v2 = strchr(s, 64);
if ( v2 )
{
v3 = v2;
v4 = strlen(v2);
strncpy(dest + 200, v3 + 1, v4);
dest[v4 + 200] = 0;
v5 = strchr(s, 33);
if ( v5 )
{
v6 = v3 - v5 - 1;
strncpy(dest + 100, v5 + 1, v6);
dest[v6 + 100] = 0;
}
}
v7 = strcspn(s, "!@ ");
return strncpy(dest, s, v7);
}

canonical_decompiled_code:
char *__fastcall func0(char *dest, char *s)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // r13
char *v5; // rax
size_t v6; // rbx
size_t v7; // rax

v2 = strchr(s, 64);
if ( v2 )
{
v3 = v2;
v4 = strlen(v2);
strncpy(dest + 200, v3 + 1, v4);
dest[v4 + 200] = 0;
v5 = strchr(s, 33);
if ( v5 )
{
v6 = v3 - v5 - 1;
strncpy(dest + 100, v5 + 1, v6);
dest[v6 + 100] = 0;
}
}
v7 = strcspn(s, "!@ ");
return strncpy(dest, s, v7);
}

original_code:
static void parse_prefix_nickname(struct nickname_t * nickname, const char * src)
{
    char * c;
    size_t len;
    if (src == ((void *)0))
        return;
    if ((c = strchr(src, '@'))) {
        char * k;
        len = strlen(c);
        strncpy(nickname->host, c+1, len);
        nickname->host[len] = '\0';
        if ((k = strchr(src, '!'))) {
            len = (c - k - 1);
            strncpy(nickname->user, k+1, len);
            nickname->user[len] = '\0';
        }
    }
    len = strcspn(src, "!@ ");
    strncpy(nickname->nickname, src, len);
}

canonical_original_code:
static void parse_prefix_nickname(struct nickname_t *nickname, char *src)
{
    char *c;
    unsigned long len;
    if (src == ((void *)0))
        return;
    if ((c = strchr(src, '@'))) {
        char *k;
        len = strlen(c);
        strncpy(nickname->host, c+1, len);
        nickname->host[len] = '\0';
        if ((k = strchr(src, '!'))) {
            len = (c - k - 1);
            strncpy(nickname->user, k+1, len);
            nickname->user[len] = '\0';
        }
    }
    len = strcspn(src, "!@ ");
    strncpy(nickname->nickname, src, len);
}

variable_types: struct nickname_t { char nickname[100]; char user[100]; char host[100]; } *

variable_types:
src
char *

variable_types:
c
char *

variable_types:
len
unsigned long

variable_types:
k
char *


decompiled_code:
char *__fastcall parse_prefix(char *dest, char *s)
{
char *result; // rax

if ( strchr(s, 64) || !strchr(s, 46) )
result = parse_prefix_nickname(dest + 100, s);
else
result = strcpy(dest, s);
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, char *s)
{
char *result; // rax

if ( strchr(s, 64) || !strchr(s, 46) )
result = func0(dest + 100, s);
else
result = strcpy(dest, s);
return result;
}

original_code:
static void parse_prefix(struct prefix_t * prefix, const char * src)
{
    if (src == ((void *)0))
        return;
    if (!strchr(src, '@') && strchr(src, '.'))
        strcpy(prefix->servername, src);
    else
        parse_prefix_nickname(&prefix->nickname, src);
}

canonical_original_code:
static void parse_prefix(struct prefix_t *prefix, char *src)
{
    if (src == ((void *)0))
        return;
    if (!strchr(src, '@') && strchr(src, '.'))
        strcpy(prefix->servername, src);
    else
        parse_prefix_nickname(&prefix->nickname, src);
}

variable_types: struct prefix_t { char servername[100]; struct nickname_t { char nickname[100]; char user[100]; char host[100]; } nickname; } *

user_defined_types: struct prefix_t { char servername[100]; struct nickname_t nickname; }


decompiled_code:
__int64 __fastcall parse_params(char *dest, char *a2, char *src)
{
char *v4; // rax
char *v5; // rbx
__int64 result; // rax
char *v7; // rbp
int v8; // ebx
char *v9; // rdi
char *v10; // rsi
char v11[536]; // [rsp+0h] [rbp-218h] BYREF

strncpy(v11, src, 0x1FEuLL);
v4 = strstr(v11, " :");
if ( v4 )
{
v5 = v4;
*strchr(v4, 13) = 0;
strcpy(a2, v5 + 2);
*v5 = 0;
}
result = (__int64)strtok(v11, " \r\n");
if ( result )
{
v7 = dest + 50;
v8 = 1;
strcpy(dest, (const char *)result);
while ( 1 )
{
v10 = strtok(0LL, " \r\n");
if ( !v10 )
break;
if ( v8 == 15 )
{
result = 750LL;
goto LABEL_9;
}
v9 = v7;
++v8;
v7 += 50;
strcpy(v9, v10);
}
result = 50LL * v8;
LABEL_9:
dest[result] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest, char *a2, char *src)
{
char *v4; // rax
char *v5; // rbx
__int64 result; // rax
char *v7; // rbp
int v8; // ebx
char *v9; // rdi
char *v10; // rsi
char v11[536]; // [rsp+0h] [rbp-218h] BYREF

strncpy(v11, src, 0x1FEuLL);
v4 = strstr(v11, " :");
if ( v4 )
{
v5 = v4;
*strchr(v4, 13) = 0;
strcpy(a2, v5 + 2);
*v5 = 0;
}
result = (__int64)strtok(v11, " \r\n");
if ( result )
{
v7 = dest + 50;
v8 = 1;
strcpy(dest, (const char *)result);
while ( 1 )
{
v10 = strtok(0LL, " \r\n");
if ( !v10 )
break;
if ( v8 == 15 )
{
result = 750LL;
goto LABEL_9;
}
v9 = v7;
++v8;
v7 += 50;
strcpy(v9, v10);
}
result = 50LL * v8;
LABEL_9:
dest[result] = 0;
}
return result;
}

original_code:
static void parse_params(char params[][50], char * trailing, const char * src)
{
    int i = 0;
    char buf[510];
    char * t;
    strncpy(buf, src, sizeof buf);
    if ((t = strstr(buf, " :"))) {
        char * end = strchr(t, '\r');
        *end = '\0';
        strcpy(trailing, t+2);
        *t = '\0';
    }
    t = strtok(buf, " \r\n");
    if (t) {
        strcpy(params[i++], t);
        while ( (t = strtok(((void *)0), " \r\n")) && i <= 14) {
            strcpy(params[i++], t);
        }
        params[i][0] = '\0';
    }
}

canonical_original_code:
static void parse_params(char params[][50], char *trailing, char *src)
{
    int i = 0;
    char buf[510];
    char *t;
    strncpy(buf, src, sizeof buf);
    if ((t = strstr(buf, " :"))) {
        char *end = strchr(t, '\r');
        *end = '\0';
        strcpy(trailing, t+2);
        *t = '\0';
    }
    t = strtok(buf, " \r\n");
    if (t) {
        strcpy(params[i++], t);
        while ( (t = strtok(((void *)0), " \r\n")) && i <= 14) {
            strcpy(params[i++], t);
        }
        params[i][0] = '\0';
    }
}

variable_types:
params
char [][50]

variable_types:
trailing
char *

variable_types: i int

variable_types:
buf
char [510]

variable_types:
t
char *

variable_types:
end
char *


decompiled_code:
void __fastcall irc_parser(char *dest, char *s)
{
unsigned __int64 v3; // rdi
char *v4; // rbx
size_t v5; // r12
size_t v6; // r12
char v7; // [rsp+0h] [rbp-218h] BYREF
char sa[535]; // [rsp+1h] [rbp-217h] BYREF

if ( s && dest )
{
*(_QWORD *)dest = 0LL;
v3 = (unsigned __int64)(dest + 8);
*(_QWORD *)(v3 + 1604) = 0LL;
v4 = s;
memset((void *)(v3 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)dest - (v3 & 0xFFFFFFF8) + 1620) >> 3));
if ( *s == 58 )
{
v6 = strcspn(s, " ");
strncpy(&v7, s, v6);
*(&v7 + v6) = 0;
parse_prefix(dest, sa);
v4 = &s[v6 + 1];
}
v5 = strcspn(v4, " \r\n");
strncpy(dest + 400, v4, v5);
dest[v5 + 400] = 0;
if ( v4[v5] )
parse_params(dest + 410, dest + 1110, &v4[v5]);
}
}

canonical_decompiled_code:
void __fastcall func3(char *dest, char *s)
{
unsigned __int64 v3; // rdi
char *v4; // rbx
size_t v5; // r12
size_t v6; // r12
char v7; // [rsp+0h] [rbp-218h] BYREF
char sa[535]; // [rsp+1h] [rbp-217h] BYREF

if ( s && dest )
{
*(_QWORD *)dest = 0LL;
v3 = (unsigned __int64)(dest + 8);
*(_QWORD *)(v3 + 1604) = 0LL;
v4 = s;
memset((void *)(v3 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)dest - (v3 & 0xFFFFFFF8) + 1620) >> 3));
if ( *s == 58 )
{
v6 = strcspn(s, " ");
strncpy(&v7, s, v6);
*(&v7 + v6) = 0;
func1(dest, sa);
v4 = &s[v6 + 1];
}
v5 = strcspn(v4, " \r\n");
strncpy(dest + 400, v4, v5);
dest[v5 + 400] = 0;
if ( v4[v5] )
func2(dest + 410, dest + 1110, &v4[v5]);
}
}

original_code:
void irc_parser(struct message_t * message, const char * line)
{
    size_t pos;
    if (line == ((void *)0) || message == ((void *)0))
        return;
    memset(message, 0, sizeof (struct message_t));
    if (line[0] == ':') {
        char buffer[510];
        pos = strcspn(line, " ");
        strncpy(buffer, line, pos);
        buffer[pos] = '\0';
        parse_prefix(&message->prefix, buffer+1);
        line += pos + 1;
    }
    pos = strcspn(line, " \r\n");
    strncpy(message->command, line, pos);
    message->command[pos] = '\0';
    line += pos;
    if (strlen(line))
        parse_params(message->params, message->trailing, line);
}

canonical_original_code:
void irc_parser(struct message_t *message, char *line)
{
    unsigned long pos;
    if (line == ((void *)0) || message == ((void *)0))
        return;
    memset(message, 0, sizeof (struct message_t));
    if (line[0] == ':') {
        char buffer[510];
        pos = strcspn(line, " ");
        strncpy(buffer, line, pos);
        buffer[pos] = '\0';
        parse_prefix(&message->prefix, buffer+1);
        line += pos + 1;
    }
    pos = strcspn(line, " \r\n");
    strncpy(message->command, line, pos);
    message->command[pos] = '\0';
    line += pos;
    if (strlen(line))
        parse_params(message->params, message->trailing, line);
}

variable_types: struct message_t { struct prefix_t { char servername[100]; struct nickname_t { char nickname[100]; char user[100]; char host[100]; } nickname; } prefix; char command[10]; char params[14][50]; char trailing[510]; } *

variable_types:
line
char *

variable_types:
pos
unsigned long

variable_types:
buffer
char [510]

user_defined_types: struct message_t { struct prefix_t prefix; char command[10]; char params[14][50]; char trailing[510]; }


decompiled_code:
int __fastcall print_message_t(__int64 a1)
{
__int64 v2; // rbx
char v3[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( *(_BYTE *)a1 )
{
snprintf(v3, 0x1000uLL, "\x1B[1;31mServ\x1B[0m: (\x1B[1;36m%s\x1B[0m ) ", (const char *)a1);
LABEL_3:
if ( !*(_BYTE *)(a1 + 400) )
goto LABEL_4;
goto LABEL_12;
}
if ( !*(_BYTE *)(a1 + 100) )
goto LABEL_3;
fprintf(stdout, "\x1B[1;32mNick\x1B[0m: (\x1B[1;32m%s\x1B[0m", (const char *)(a1 + 100));
if ( *(_BYTE *)(a1 + 200) )
fprintf(stdout, "\x1B[1;33m!%s\x1B[0m", (const char *)(a1 + 200));
if ( *(_BYTE *)(a1 + 300) )
fprintf(stdout, "\x1B[1;33m@%s \x1B[0m", (const char *)(a1 + 300));
fwrite(") ", 1uLL, 2uLL, stdout);
if ( !*(_BYTE *)(a1 + 400) )
{
LABEL_4:
if ( !*(_BYTE *)(a1 + 410) )
goto LABEL_5;
goto LABEL_13;
}
LABEL_12:
fprintf(stdout, "(\x1B[1;36m%s\x1B[0m) ", (const char *)(a1 + 400));
if ( !*(_BYTE *)(a1 + 410) )
{
LABEL_5:
if ( !*(_BYTE *)(a1 + 1110) )
goto LABEL_6;
LABEL_16:
fprintf(stdout, " => %s", (const char *)(a1 + 1110));
goto LABEL_6;
}
LABEL_13:
v2 = a1 + 410;
fputc(123, stdout);
if ( *(_BYTE *)(a1 + 410) )
{
do
{
fprintf(stdout, "\x1B[1;35m\"%s\"\x1B[0m", (const char *)v2);
if ( !*(_BYTE *)(v2 + 50) )
break;
v2 += 50LL;
fwrite(", ", 1uLL, 2uLL, stdout);
}
while ( *(_BYTE *)v2 );
}
fputc(125, stdout);
if ( *(_BYTE *)(a1 + 1110) )
goto LABEL_16;
LABEL_6:
fputc(10, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v2; // rbx
char v3[4120]; // [rsp+0h] [rbp-1018h] BYREF

if ( *(_BYTE *)a1 )
{
snprintf(v3, 0x1000uLL, "\x1B[1;31mServ\x1B[0m: (\x1B[1;36m%s\x1B[0m ) ", (const char *)a1);
LABEL_3:
if ( !*(_BYTE *)(a1 + 400) )
goto LABEL_4;
goto LABEL_12;
}
if ( !*(_BYTE *)(a1 + 100) )
goto LABEL_3;
fprintf(stdout, "\x1B[1;32mNick\x1B[0m: (\x1B[1;32m%s\x1B[0m", (const char *)(a1 + 100));
if ( *(_BYTE *)(a1 + 200) )
fprintf(stdout, "\x1B[1;33m!%s\x1B[0m", (const char *)(a1 + 200));
if ( *(_BYTE *)(a1 + 300) )
fprintf(stdout, "\x1B[1;33m@%s \x1B[0m", (const char *)(a1 + 300));
fwrite(") ", 1uLL, 2uLL, stdout);
if ( !*(_BYTE *)(a1 + 400) )
{
LABEL_4:
if ( !*(_BYTE *)(a1 + 410) )
goto LABEL_5;
goto LABEL_13;
}
LABEL_12:
fprintf(stdout, "(\x1B[1;36m%s\x1B[0m) ", (const char *)(a1 + 400));
if ( !*(_BYTE *)(a1 + 410) )
{
LABEL_5:
if ( !*(_BYTE *)(a1 + 1110) )
goto LABEL_6;
LABEL_16:
fprintf(stdout, " => %s", (const char *)(a1 + 1110));
goto LABEL_6;
}
LABEL_13:
v2 = a1 + 410;
fputc(123, stdout);
if ( *(_BYTE *)(a1 + 410) )
{
do
{
fprintf(stdout, "\x1B[1;35m\"%s\"\x1B[0m", (const char *)v2);
if ( !*(_BYTE *)(v2 + 50) )
break;
v2 += 50LL;
fwrite(", ", 1uLL, 2uLL, stdout);
}
while ( *(_BYTE *)v2 );
}
fputc(125, stdout);
if ( *(_BYTE *)(a1 + 1110) )
goto LABEL_16;
LABEL_6:
fputc(10, stdout);
return fflush(stdout);
}

original_code:
void print_message_t(struct message_t * message)
{
    char buf[4096];
    if (message->prefix.servername[0])
        snprintf(buf, sizeof buf, "\033[1;31m" "Serv" "\033[0m" ": (" "\033[1;36m" "%s" "\033[0m" " ) ", message->prefix.servername);
    else if (message->prefix.nickname.nickname[0]) {
        fprintf(stdout, "\033[1;32m" "Nick" "\033[0m" ": (" "\033[1;32m" "%s" "\033[0m", message->prefix.nickname.nickname);
        if (message->prefix.nickname.user[0])
            fprintf(stdout, "\033[1;33m" "!%s" "\033[0m", message->prefix.nickname.user);
        if (message->prefix.nickname.host[0])
            fprintf(stdout, "\033[1;33m" "@%s " "\033[0m", message->prefix.nickname.host);
        fprintf(stdout, ") ");
    }
    if (message->command[0])
        fprintf(stdout, "(" "\033[1;36m" "%s" "\033[0m" ") ", message->command);
    if (message->params[0][0]) {
        int i = 0;
        fprintf(stdout, "{");
        while (message->params[i][0]) {
            fprintf(stdout, "\033[1;35m" "\"%s\"" "\033[0m", message->params[i++]);
            if (message->params[i][0])
                fprintf(stdout, ", ");
        }
        fprintf(stdout, "}");
    }
    if (message->trailing[0])
        fprintf(stdout, " => %s", message->trailing);
    fprintf(stdout, "\n");
    fflush(stdout);
}

canonical_original_code:
void print_message_t(struct message_t *message)
{
    char buf[4096];
    if (message->prefix.servername[0])
        snprintf(buf, sizeof buf, "\033[1;31m" "Serv" "\033[0m" ": (" "\033[1;36m" "%s" "\033[0m" " ) ", message->prefix.servername);
    else if (message->prefix.nickname.nickname[0]) {
        fprintf(stdout, "\033[1;32m" "Nick" "\033[0m" ": (" "\033[1;32m" "%s" "\033[0m", message->prefix.nickname.nickname);
        if (message->prefix.nickname.user[0])
            fprintf(stdout, "\033[1;33m" "!%s" "\033[0m", message->prefix.nickname.user);
        if (message->prefix.nickname.host[0])
            fprintf(stdout, "\033[1;33m" "@%s " "\033[0m", message->prefix.nickname.host);
        fprintf(stdout, ") ");
    }
    if (message->command[0])
        fprintf(stdout, "(" "\033[1;36m" "%s" "\033[0m" ") ", message->command);
    if (message->params[0][0]) {
        int i = 0;
        fprintf(stdout, "{");
        while (message->params[i][0]) {
            fprintf(stdout, "\033[1;35m" "\"%s\"" "\033[0m", message->params[i++]);
            if (message->params[i][0])
                fprintf(stdout, ", ");
        }
        fprintf(stdout, "}");
    }
    if (message->trailing[0])
        fprintf(stdout, " => %s", message->trailing);
    fprintf(stdout, "\n");
    fflush(stdout);
}

variable_types:
buf
char [4096]

user_defined_types: struct nickname_t { char nickname[100]; char user[100]; char host[100]; }


decompiled_code:
void __noreturn termination_handler()
{
fwrite("Terminating application.\n", 1uLL, 0x19uLL, stdout);
plugin_free();
irc_free(&irc);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Terminating application.\n", 1uLL, 0x19uLL, stdout);
plugin_free();
irc_free(&irc);
exit(0);
}

original_code:
void
termination_handler (int signum)
{
    fprintf(stdout, "Terminating application.\n");
    plugin_free();
    irc_free(&irc);
    exit(0);
}

canonical_original_code:
void termination_handler(int signum)
{
    fprintf(stdout, "Terminating application.\n");
    plugin_free();
    irc_free(&irc);
    exit(0);
}

variable_types: signum int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
signal(2, (__sighandler_t)termination_handler);
setlocale(0, &locale);
memset(&irc, 0, 0x6F8uLL);
config_load(&irc);
plugin_init(&irc);
while ( (int)irc_run(&irc) > 0 )
;
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    signal(2, termination_handler);
    setlocale(0, "");
    memset(&irc, 0, sizeof(struct irc_t));
    config_load(&irc);
    plugin_init(&irc);
    while ( irc_run(&irc) > 0 ) { }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

user_defined_types: struct irc_t { struct message_t message; char from[100]; struct channel_list_t channel_list_head; void *sockfd; char *hostname; char *port; char *nickname; char *password; char *admin; struct ajoin_channel_list_t ajoin_channels_head; }

user_defined_types: struct channel_list_t { struct channel_t *lh_first; }

user_defined_types: struct ajoin_channel_list_t { struct ajoin_channel_t *lh_first; }

user_defined_types: struct channel_t { char *name; struct { struct user_t *lh_first; } user_list_head; struct { struct channel_t *le_next; struct channel_t **le_prev; } list; }

user_defined_types: struct ajoin_channel_t { char *channel_name; struct { struct ajoin_channel_t *le_next; struct ajoin_channel_t **le_prev; } list; }

user_defined_types: struct user_t { char *name; struct { struct user_t *le_next; struct user_t **le_prev; } list; }


decompiled_code:
int __fastcall thread_create(pthread_t **a1, void *(*a2)(void *), void *a3)
{
pthread_t *v4; // rax

v4 = (pthread_t *)malloc(8uLL);
*a1 = v4;
return pthread_create(v4, 0LL, a2, a3);
}

canonical_decompiled_code:
int __fastcall func0(pthread_t **a1, void *(*a2)(void *), void *a3)
{
pthread_t *v4; // rax

v4 = (pthread_t *)malloc(8uLL);
*a1 = v4;
return pthread_create(v4, 0LL, a2, a3);
}

original_code:
int thread_create(thread_t * thread, void *(*start_routine)(void *), void *arg)
{
    *thread = malloc(sizeof (pthread_t));
    return pthread_create(*thread, ((void *)0), start_routine, arg);
}

canonical_original_code:
int thread_create(void **thread, void *(*start_routine)(void *), void *arg)
{
    *thread = malloc(sizeof (pthread_t));
    return pthread_create(*thread, ((void *)0), start_routine, arg);
}

variable_types:
thread
void **

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall thread_kill(pthread_t **a1)
{
pthread_kill(**a1, 9);
free(*a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_t **a1)
{
pthread_kill(**a1, 9);
free(*a1);
return 0LL;
}

original_code:
int thread_kill(thread_t * thread)
{
    pthread_kill(*((pthread_t *) *thread), 9);
    free(*thread);
    return 0;
}

canonical_original_code:
int thread_kill(void **thread)
{
    pthread_kill(*((unsigned long *) *thread), 9);
    free(*thread);
    return 0;
}


decompiled_code:
void __fastcall plugin_sigsegv_handler(int a1)
{
if ( a1 == 11 )
longjmp(jmp_buf_recover_plugin, 1);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 11 )
longjmp(jmp_buf_recover_plugin, 1);
}

original_code:
void plugin_sigsegv_handler(int s)
{
    if (s == 11) {
        longjmp(jmp_buf_recover_plugin, 1);
    }
}

variable_types: s int


decompiled_code:
__int64 __fastcall command_help(__int64 a1)
{
__int64 v1; // rbx
size_t v2; // rax
int v3; // eax
size_t v4; // rax
char dest[552]; // [rsp+0h] [rbp-228h] BYREF

sprintf(dest, "PRIVMSG %s :Loaded plugins: ", (const char *)(a1 + 1620));
v1 = plugin_slist_head;
if ( plugin_slist_head )
{
while ( 1 )
{
v2 = strlen(dest);
strcpy(&dest[v2], *(const char **)v1);
v3 = *(_DWORD *)(v1 + 16);
if ( (v3 & 1) != 0 )
{
strcat(dest, " (daemon)");
v3 = *(_DWORD *)(v1 + 16);
if ( (v3 & 8) == 0 )
{
LABEL_4:
if ( (v3 & 4) == 0 )
goto LABEL_5;
goto LABEL_10;
}
}
else if ( (v3 & 8) == 0 )
{
goto LABEL_4;
}
*(_QWORD *)&dest[strlen(dest)] = 0x29706572672820LL;
if ( (*(_DWORD *)(v1 + 16) & 4) == 0 )
{
LABEL_5:
v1 = *(_QWORD *)(v1 + 48);
if ( !v1 )
break;
goto LABEL_6;
}
LABEL_10:
strcat(dest, " (command)");
v1 = *(_QWORD *)(v1 + 48);
if ( !v1 )
break;
LABEL_6:
if ( plugin_slist_head != v1 )
strcat(dest, ", ");
}
}
*(_DWORD *)&dest[strlen(dest)] = 658734;
v4 = strlen(dest);
return socket_write(*(_QWORD *)(a1 + 1728), dest, v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
size_t v2; // rax
int v3; // eax
size_t v4; // rax
char dest[552]; // [rsp+0h] [rbp-228h] BYREF

sprintf(dest, "PRIVMSG %s :Loaded plugins: ", (const char *)(a1 + 1620));
v1 = plugin_slist_head;
if ( plugin_slist_head )
{
while ( 1 )
{
v2 = strlen(dest);
strcpy(&dest[v2], *(const char **)v1);
v3 = *(_DWORD *)(v1 + 16);
if ( (v3 & 1) != 0 )
{
strcat(dest, " (daemon)");
v3 = *(_DWORD *)(v1 + 16);
if ( (v3 & 8) == 0 )
{
LABEL_4:
if ( (v3 & 4) == 0 )
goto LABEL_5;
goto LABEL_10;
}
}
else if ( (v3 & 8) == 0 )
{
goto LABEL_4;
}
*(_QWORD *)&dest[strlen(dest)] = 0x29706572672820LL;
if ( (*(_DWORD *)(v1 + 16) & 4) == 0 )
{
LABEL_5:
v1 = *(_QWORD *)(v1 + 48);
if ( !v1 )
break;
goto LABEL_6;
}
LABEL_10:
strcat(dest, " (command)");
v1 = *(_QWORD *)(v1 + 48);
if ( !v1 )
break;
LABEL_6:
if ( plugin_slist_head != v1 )
strcat(dest, ", ");
}
}
*(_DWORD *)&dest[strlen(dest)] = 658734;
v4 = strlen(dest);
return socket_write(*(_QWORD *)(a1 + 1728), dest, v4);
}

original_code:
static void command_help(struct irc_t * irc)
{
    struct plugin_t * iterator;
    char message[500];
    sprintf(message, "PRIVMSG %s :Loaded plugins: ", irc->from);
    for ((iterator) = ((&plugin_slist_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
        struct plugin_t * plugin = iterator;
        if (((&plugin_slist_head)->lh_first) != iterator) {
            sprintf(message + strlen(message), ", ");
        }
        sprintf(message + strlen(message), "%s", plugin->name);
        if (plugin->type & PLUGIN_TYPE_DAEMON) {
            sprintf(message + strlen(message), " (daemon)" );
        }
        if (plugin->type & PLUGIN_TYPE_GREP) {
            sprintf(message + strlen(message), " (grep)" );
        }
        if (plugin->type & PLUGIN_TYPE_COMMAND) {
            sprintf(message + strlen(message), " (command)" );
        }
    }
    sprintf(message + strlen(message), ".\r\n");
    socket_write(irc->sockfd, message, strlen(message));
}

canonical_original_code:
static void command_help(struct irc_t *irc)
{
    struct plugin_t *iterator;
    char message[500];
    sprintf(message, "PRIVMSG %s :Loaded plugins: ", irc->from);
    for ((iterator) = ((&plugin_slist_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
        struct plugin_t *plugin = iterator;
        if (((&plugin_slist_head)->lh_first) != iterator) {
            sprintf(message + strlen(message), ", ");
        }
        sprintf(message + strlen(message), "%s", plugin->name);
        if (plugin->type & PLUGIN_TYPE_DAEMON) {
            sprintf(message + strlen(message), " (daemon)" );
        }
        if (plugin->type & PLUGIN_TYPE_GREP) {
            sprintf(message + strlen(message), " (grep)" );
        }
        if (plugin->type & PLUGIN_TYPE_COMMAND) {
            sprintf(message + strlen(message), " (command)" );
        }
    }
    sprintf(message + strlen(message), ".\r\n");
    socket_write(irc->sockfd, message, strlen(message));
}

variable_types: struct plugin_t { char *name; char **keywords; enum plugin_type { PLUGIN_TYPE_DAEMON=1, PLUGIN_TYPE_COMMAND=expr, PLUGIN_TYPE_GREP=expr } type; void (*send_message)(struct irc_t { struct message_t { struct prefix_t { char servername[100]; struct nickname_t { char nickname[100]; char user[100]; char host[100]; } nickname; } prefix; char command[10]; char params[14][50]; char trailing[510]; } message; char from[100]; struct channel_list_t { struct channel_t { char *name; struct { struct user_t { char *name; struct { struct user_t *le_next; struct user_t **le_prev; } list; } *lh_first; } user_list_head; struct { struct channel_t *le_next; struct channel_t **le_prev; } list; } *lh_first; } channel_list_head; void *sockfd; char *hostname; char *port; char *nickname; char *password; char *admin; struct ajoin_channel_list_t { struct ajoin_channel_t { char *channel_name; struct { struct ajoin_channel_t *le_next; struct ajoin_channel_t **le_prev; } list; } *lh_first; } ajoin_channels_head; } *, char *message); struct irc_t *irc; void (*run)(int type); struct { struct plugin_t *le_next; struct plugin_t **le_prev; } list; } *

variable_types:
message
char [500]

user_defined_types: struct plugin_t { char *name; char **keywords; enum plugin_type type; void (*send_message)(struct irc_t *, char *message); struct irc_t *irc; void (*run)(int type); struct { struct plugin_t *le_next; struct plugin_t **le_prev; } list; }


decompiled_code:
__int64 __fastcall process_command_part_channel(__int64 a1)
{
__int64 v1; // rbx
const char *v2; // rbp
__int64 v3; // rdi
__int64 v4; // rax

v1 = *(_QWORD *)(a1 + 1720);
if ( !v1 )
return channel_free(0LL);
v2 = (const char *)(a1 + 410);
v3 = 0LL;
do
{
channel_free(v3);
v3 = 0LL;
if ( !strcmp(*(const char **)v1, v2) )
{
v4 = *(_QWORD *)(v1 + 16);
if ( v4 )
*(_QWORD *)(v4 + 24) = *(_QWORD *)(v1 + 24);
v3 = v1;
**(_QWORD **)(v1 + 24) = v4;
}
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
return channel_free(v3);
}

original_code:
static void process_command_part_channel(struct irc_t * irc)
{
    struct channel_t * iterator, * temp;
    char * channel_name;
    channel_name = irc->message.params[0];
    temp = ((void *)0);
    for ((iterator) = ((&irc->channel_list_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
        channel_free(temp);
        temp = ((void *)0);
        if (strcmp(iterator->name, channel_name) == 0) {
            do { if ((iterator)->list.le_next != ((void *)0)) (iterator)->list.le_next->list.le_prev = (iterator)->list.le_prev; *(iterator)->list.le_prev = (iterator)->list.le_next; } while ( 0);
            temp = iterator;
        }
    }
    channel_free(temp);
}

canonical_original_code:
static void process_command_part_channel(struct irc_t *irc)
{
    struct channel_t *iterator; struct channel_t *temp;
    char *channel_name;
    channel_name = irc->message.params[0];
    temp = ((void *)0);
    for ((iterator) = ((&irc->channel_list_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
        channel_free(temp);
        temp = ((void *)0);
        if (strcmp(iterator->name, channel_name) == 0) {
            do { if ((iterator)->list.le_next != ((void *)0)) (iterator)->list.le_next->list.le_prev = (iterator)->list.le_prev; *(iterator)->list.le_prev = (iterator)->list.le_next; } while ( 0);
            temp = iterator;
        }
    }
    channel_free(temp);
}

variable_types: struct irc_t { struct message_t { struct prefix_t { char servername[100]; struct nickname_t { char nickname[100]; char user[100]; char host[100]; } nickname; } prefix; char command[10]; char params[14][50]; char trailing[510]; } message; char from[100]; struct channel_list_t { struct channel_t { char *name; struct { struct user_t { char *name; struct { struct user_t *le_next; struct user_t **le_prev; } list; } *lh_first; } user_list_head; struct { struct channel_t *le_next; struct channel_t **le_prev; } list; } *lh_first; } channel_list_head; void *sockfd; char *hostname; char *port; char *nickname; char *password; char *admin; struct ajoin_channel_list_t { struct ajoin_channel_t { char *channel_name; struct { struct ajoin_channel_t *le_next; struct ajoin_channel_t **le_prev; } list; } *lh_first; } ajoin_channels_head; } *


decompiled_code:
void __fastcall irc_plugin_handle_grep(__int64 a1)
{
__int64 i; // r12
__int64 *v2; // rbp
__int64 v3; // rbx

for ( i = plugin_slist_head; i; i = *(_QWORD *)(i + 48) )
{
while ( 1 )
{
if ( (*(_BYTE *)(i + 16) & 8) != 0 )
{
fprintf(stderr, "Grepping plugin for: %s\n", *(const char **)i);
v2 = *(__int64 **)(i + 8);
v3 = *v2;
if ( *v2 )
break;
}
LABEL_3:
i = *(_QWORD *)(i + 48);
if ( !i )
return;
}
while ( !strstr((const char *)(a1 + 1110), (const char *)v3) && (*(_BYTE *)v3 != 42 || *(_BYTE *)(v3 + 1)) )
{
v3 = v2[1];
++v2;
if ( !v3 )
goto LABEL_3;
}
(*(void (__fastcall **)(__int64))(i + 40))(8LL);
}
}

original_code:
static void irc_plugin_handle_grep(struct irc_t * irc)
{
    struct plugin_t * iterator;
    for ((iterator) = ((&plugin_slist_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
        struct plugin_t * plugin = iterator;
        char ** keywords_v;
        if (!(plugin->type & PLUGIN_TYPE_GREP))
            continue;
        fprintf(stderr, "Grepping plugin for: %s\n", plugin->name);
        for (keywords_v = plugin->keywords; *keywords_v != ((void *)0); keywords_v++) {
            char * keyword = *keywords_v;
            if (strstr(irc->message.trailing, keyword) || strcmp("*", keyword) == 0) {
                plugin->run(PLUGIN_TYPE_GREP);
                break;
            }
        }
    }
}

canonical_original_code:
static void irc_plugin_handle_grep(struct irc_t *irc)
{
    struct plugin_t *iterator;
    for ((iterator) = ((&plugin_slist_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
        struct plugin_t *plugin = iterator;
        char **keywords_v;
        if (!(plugin->type & PLUGIN_TYPE_GREP))
            continue;
        fprintf(stderr, "Grepping plugin for: %s\n", plugin->name);
        for (keywords_v = plugin->keywords; *keywords_v != ((void *)0); keywords_v++) {
            char *keyword = *keywords_v;
            if (strstr(irc->message.trailing, keyword) || strcmp("*", keyword) == 0) {
                plugin->run(PLUGIN_TYPE_GREP);
                break;
            }
        }
    }
}

variable_types:
keyword
char *

user_defined_types: enum plugin_type { PLUGIN_TYPE_DAEMON=1, PLUGIN_TYPE_COMMAND=expr, PLUGIN_TYPE_GREP=expr }


decompiled_code:
int __fastcall irc_plugin_handle_command(__int64 a1)
{
size_t v1; // rax
int result; // eax
__int64 i; // rbx
int v4; // [rsp+0h] [rbp-58h] BYREF
char v5; // [rsp+4h] [rbp-54h]

v1 = strcspn((const char *)(a1 + 1111), " \r\n");
result = snprintf((char *)&v4, v1 + 1, "%s", (const char *)(a1 + 1111));
if ( v4 == 1886152040 && !v5 )
return command_help(a1);
for ( i = plugin_slist_head; i; i = *(_QWORD *)(i + 48) )
{
result = strcmp(*(const char **)i, (const char *)&v4);
if ( !result )
result = (*(__int64 (__fastcall **)(__int64))(i + 40))(4LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
size_t v1; // rax
int result; // eax
__int64 i; // rbx
int v4; // [rsp+0h] [rbp-58h] BYREF
char v5; // [rsp+4h] [rbp-54h]

v1 = strcspn((const char *)(a1 + 1111), " \r\n");
result = snprintf((char *)&v4, v1 + 1, "%s", (const char *)(a1 + 1111));
if ( v4 == 1886152040 && !v5 )
return func1(a1);
for ( i = plugin_slist_head; i; i = *(_QWORD *)(i + 48) )
{
result = strcmp(*(const char **)i, (const char *)&v4);
if ( !result )
result = (*(__int64 (__fastcall **)(__int64))(i + 40))(4LL);
}
return result;
}

original_code:
static void irc_plugin_handle_command(struct irc_t * irc)
{
    char command_name[50];
    struct plugin_t * iterator;
    size_t n = strcspn(irc->message.trailing+1, " \r\n");
    snprintf(command_name, n+1, "%s", irc->message.trailing+1);
    if (strcmp(command_name, "help") == 0) {
        command_help(irc);
    } else {
        for ((iterator) = ((&plugin_slist_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
            if (strcmp(iterator->name, command_name) == 0) {
                iterator->run(PLUGIN_TYPE_COMMAND);
            }
        }
    }
}

canonical_original_code:
static void irc_plugin_handle_command(struct irc_t *irc)
{
    char command_name[50];
    struct plugin_t *iterator;
    unsigned long n = strcspn(irc->message.trailing+1, " \r\n");
    snprintf(command_name, n+1, "%s", irc->message.trailing+1);
    if (strcmp(command_name, "help") == 0) {
        command_help(irc);
    } else {
        for ((iterator) = ((&plugin_slist_head)->lh_first); (iterator); (iterator) = ((iterator)->list.le_next)) {
            if (strcmp(iterator->name, command_name) == 0) {
                iterator->run(PLUGIN_TYPE_COMMAND);
            }
        }
    }
}

variable_types:
n
unsigned long


decompiled_code:
int __fastcall process_bot_command_admin(__int64 a1)
{
char *v1; // rax
char *v2; // rcx
const char *v3; // rsi
size_t v4; // rax
int v6; // [rsp+0h] [rbp-808h] BYREF
__int16 v7; // [rsp+4h] [rbp-804h]
char v8[512]; // [rsp+200h] [rbp-608h] BYREF
char s[512]; // [rsp+400h] [rbp-408h] BYREF
char v10[520]; // [rsp+600h] [rbp-208h] BYREF

snprintf(s, 0x1FEuLL, "%s", (const char *)(a1 + 1110));
v1 = strtok(s, " \r\n");
if ( v1 )
{
snprintf((char *)&v6, 0x1FEuLL, "%s", v1);
v1 = strtok(0LL, "\r\n");
v2 = v1;
if ( v1 )
LODWORD(v1) = snprintf(v8, 0x1FEuLL, "%s", v1);
if ( v6 == 1768909358 )
{
v3 = "JOIN %s\r\n";
if ( v7 == 110 )
{
LABEL_11:
sprintf(v10, v3, v8, v2);
LABEL_12:
v4 = strlen(v10);
LODWORD(v1) = socket_write(*(_QWORD *)(a1 + 1728), v10, v4);
return (int)v1;
}
}
else if ( v6 == 1918988334 )
{
v3 = "PART %s\r\n";
if ( v7 == 116 )
goto LABEL_11;
}
if ( v6 == 2002874926 && !(_BYTE)v7 )
{
sprintf(v10, "%s\r\n", v8);
goto LABEL_12;
}
}
return (int)v1;
}

original_code:
static void process_bot_command_admin (struct irc_t * irc)
{
    char * token;
    char command[510], argument[510];
    char tokenize_buffer[510];
    char response[512];
    snprintf(tokenize_buffer, 510, "%s", irc->message.trailing);
    if ((token = strtok(tokenize_buffer, " \r\n")) == ((void *)0))
        return;
    snprintf(command, 510, "%s", token);
    if ((token = strtok(((void *)0), "\r\n"))) {
        snprintf(argument, 510, "%s", token);
    }
    if (strcmp(".join", command) == 0) {
        sprintf(response, "JOIN %s\r\n", argument);
        socket_write(irc->sockfd, response, strlen(response));
    } else if (strcmp(".part", command) == 0) {
        sprintf(response, "PART %s\r\n", argument);
        socket_write(irc->sockfd, response, strlen(response));
    } else if (strcmp(".raw", command) == 0) {
        sprintf(response, "%s\r\n", argument);
        socket_write(irc->sockfd, response, strlen(response));
    } else if (strcmp(".reload", command) == 0) {
    }
}

canonical_original_code:
static void process_bot_command_admin(struct irc_t *irc)
{
    char *token;
    char command[510]; char argument[510];
    char tokenize_buffer[510];
    char response[512];
    snprintf(tokenize_buffer, 510, "%s", irc->message.trailing);
    if ((token = strtok(tokenize_buffer, " \r\n")) == ((void *)0))
        return;
    snprintf(command, 510, "%s", token);
    if ((token = strtok(((void *)0), "\r\n"))) {
        snprintf(argument, 510, "%s", token);
    }
    if (strcmp(".join", command) == 0) {
        sprintf(response, "JOIN %s\r\n", argument);
        socket_write(irc->sockfd, response, strlen(response));
    } else if (strcmp(".part", command) == 0) {
        sprintf(response, "PART %s\r\n", argument);
        socket_write(irc->sockfd, response, strlen(response));
    } else if (strcmp(".raw", command) == 0) {
        sprintf(response, "%s\r\n", argument);
        socket_write(irc->sockfd, response, strlen(response));
    } else if (strcmp(".reload", command) == 0) {
    }
}

variable_types:
token
char *

variable_types:
command
char [510]

variable_types:
argument
char [510]

variable_types:
response
char [512]


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

irc_plugin_handle_command(a1);
result = strcmp(*(const char **)(a1 + 1768), (const char *)(a1 + 100));
if ( !result )
result = process_bot_command_admin(a1);
return result;
}

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

func4(a1);
result = strcmp(*(const char **)(a1 + 1768), (const char *)(a1 + 100));
if ( !result )
result = func5(a1);
return result;
}

original_code:
static void process_bot_command_user (struct irc_t * irc)
{
    irc_plugin_handle_command(irc);
    if (strcmp(irc->admin, irc->message.prefix.nickname.nickname) == 0)
        process_bot_command_admin (irc);
}

canonical_original_code:
static void process_bot_command_user(struct irc_t *irc)
{
    irc_plugin_handle_command(irc);
    if (strcmp(irc->admin, irc->message.prefix.nickname.nickname) == 0)
        process_bot_command_admin (irc);
}


decompiled_code:
void __fastcall process_command_privmsg(__int64 a1)
{
strcpy((char *)(a1 + 1620), (const char *)(a1 + 410));
if ( !strcmp((const char *)(a1 + 410), *(const char **)(a1 + 1752)) )
strcpy((char *)(a1 + 1620), (const char *)(a1 + 100));
signal(11, plugin_sigsegv_handler);
if ( setjmp(jmp_buf_recover_plugin) )
{
fwrite("Recovered from fatal error.\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( *(_BYTE *)(a1 + 1110) == 46 )
process_bot_command_user(a1);
irc_plugin_handle_grep(a1);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
strcpy((char *)(a1 + 1620), (const char *)(a1 + 410));
if ( !strcmp((const char *)(a1 + 410), *(const char **)(a1 + 1752)) )
strcpy((char *)(a1 + 1620), (const char *)(a1 + 100));
signal(11, plugin_sigsegv_handler);
if ( setjmp(jmp_buf_recover_plugin) )
{
fwrite("Recovered from fatal error.\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( *(_BYTE *)(a1 + 1110) == 46 )
func6(a1);
func3(a1);
}
}

original_code:
static void process_command_privmsg (struct irc_t * irc)
{
    strcpy(irc->from, irc->message.params[0]);
    if (!strcmp(irc->message.params[0], irc->nickname))
        strcpy(irc->from, irc->message.prefix.nickname.nickname);
    signal(11, plugin_sigsegv_handler);
    if (!_setjmp (jmp_buf_recover_plugin)) {
        if ( irc->message.trailing[0] == '.' )
            process_bot_command_user (irc);
        irc_plugin_handle_grep(irc);
    } else {
        fprintf(stderr, "Recovered from fatal error.\n");;
    }
}

canonical_original_code:
static void process_command_privmsg(struct irc_t *irc)
{
    strcpy(irc->from, irc->message.params[0]);
    if (!strcmp(irc->message.params[0], irc->nickname))
        strcpy(irc->from, irc->message.prefix.nickname.nickname);
    signal(11, plugin_sigsegv_handler);
    if (!_setjmp (jmp_buf_recover_plugin)) {
        if ( irc->message.trailing[0] == '.' )
            process_bot_command_user (irc);
        irc_plugin_handle_grep(irc);
    } else {
        fprintf(stderr, "Recovered from fatal error.\n");;
    }
}


decompiled_code:
char *__fastcall process_command_353(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
char *result; // rax
char *v4; // rbx
char *i; // rsi

v1 = a1 + 410;
do
{
v2 = v1;
if ( !v1 )
break;
v1 += 50LL;
}
while ( *(_BYTE *)(v1 - 50) != 35 );
result = (char *)channel_find(a1 + 1720, v2);
v4 = result;
if ( result )
{
result = strtok((char *)(a1 + 1110), " ");
for ( i = result; result; i = result )
{
channel_add_user(v4, i);
result = strtok(0LL, " ");
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
char *result; // rax
char *v4; // rbx
char *i; // rsi

v1 = a1 + 410;
do
{
v2 = v1;
if ( !v1 )
break;
v1 += 50LL;
}
while ( *(_BYTE *)(v1 - 50) != 35 );
result = (char *)channel_find(a1 + 1720, v2);
v4 = result;
if ( result )
{
result = strtok((char *)(a1 + 1110), " ");
for ( i = result; result; i = result )
{
channel_add_user(v4, i);
result = strtok(0LL, " ");
}
}
return result;
}

original_code:
static void process_command_353(struct irc_t * irc)
{
    struct channel_t * channel;
    char * channel_name;
    int param_counter = 0;
    while ((channel_name = irc->message.params[param_counter++]) != ((void *)0)) {
        if (channel_name[0] == '#') {
            break;
        }
    }
    channel = channel_find(&irc->channel_list_head, channel_name);
    if (channel == ((void *)0)) {
        return;
    }
    char * token;
    token = strtok(irc->message.trailing, " ");
    if (token == ((void *)0)) {
        return;
    }
    channel_add_user(channel, token);
    while ((token = strtok(((void *)0), " ")) != ((void *)0)) {
        channel_add_user(channel, token);
    }
}

canonical_original_code:
static void process_command_353(struct irc_t *irc)
{
    struct channel_t *channel;
    char *channel_name;
    int param_counter = 0;
    while ((channel_name = irc->message.params[param_counter++]) != ((void *)0)) {
        if (channel_name[0] == '#') {
            break;
        }
    }
    channel = channel_find(&irc->channel_list_head, channel_name);
    if (channel == ((void *)0)) {
        return;
    }
    char *token;
    token = strtok(irc->message.trailing, " ");
    if (token == ((void *)0)) {
        return;
    }
    channel_add_user(channel, token);
    while ((token = strtok(((void *)0), " ")) != ((void *)0)) {
        channel_add_user(channel, token);
    }
}

variable_types: struct channel_t { char *name; struct { struct user_t { char *name; struct { struct user_t *le_next; struct user_t **le_prev; } list; } *lh_first; } user_list_head; struct { struct channel_t *le_next; struct channel_t **le_prev; } list; } *


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

result = channel_find(a1 + 1720, a1 + 410);
if ( result )
result = channel_add_user(result, a1 + 100);
return result;
}

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

result = channel_find(a1 + 1720, a1 + 410);
if ( result )
result = channel_add_user(result, a1 + 100);
return result;
}

original_code:
static void process_command_join_new_user(struct irc_t * irc)
{
    struct channel_t * channel;
    char * channel_name, * nickname;
    channel_name = irc->message.params[0];
    if (channel_name == ((void *)0)) {
        return;
    }
    nickname = irc->message.prefix.nickname.nickname;
    if (nickname == ((void *)0)) {
        return;
    }
    channel = channel_find(&irc->channel_list_head, channel_name);
    if (channel == ((void *)0)) {
        return;
    }
    channel_add_user(channel, nickname);
}

canonical_original_code:
static void process_command_join_new_user(struct irc_t *irc)
{
    struct channel_t *channel;
    char *channel_name; char *nickname;
    channel_name = irc->message.params[0];
    if (channel_name == ((void *)0)) {
        return;
    }
    nickname = irc->message.prefix.nickname.nickname;
    if (nickname == ((void *)0)) {
        return;
    }
    channel = channel_find(&irc->channel_list_head, channel_name);
    if (channel == ((void *)0)) {
        return;
    }
    channel_add_user(channel, nickname);
}

variable_types:
nickname
char *


decompiled_code:
__int64 __fastcall process_command_join_new_channel(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = channel_new(a1 + 410);
v2 = *(_QWORD *)(a1 + 1720);
*(_QWORD *)(result + 16) = v2;
if ( v2 )
*(_QWORD *)(v2 + 24) = result + 16;
*(_QWORD *)(a1 + 1720) = result;
*(_QWORD *)(result + 24) = a1 + 1720;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = channel_new(a1 + 410);
v2 = *(_QWORD *)(a1 + 1720);
*(_QWORD *)(result + 16) = v2;
if ( v2 )
*(_QWORD *)(v2 + 24) = result + 16;
*(_QWORD *)(a1 + 1720) = result;
*(_QWORD *)(result + 24) = a1 + 1720;
return result;
}

original_code:
static void process_command_join_new_channel(struct irc_t * irc)
{
    char * channel_name;
    struct channel_t * channel;
    channel_name = irc->message.params[0];
    channel = channel_new(channel_name);
    do { if (((channel)->list.le_next = (&irc->channel_list_head)->lh_first) != ((void *)0)) (&irc->channel_list_head)->lh_first->list.le_prev = &(channel)->list.le_next; (&irc->channel_list_head)->lh_first = (channel); (channel)->list.le_prev = &(&irc->channel_list_head)->lh_first; } while ( 0);
}

canonical_original_code:
static void process_command_join_new_channel(struct irc_t *irc)
{
    char *channel_name;
    struct channel_t *channel;
    channel_name = irc->message.params[0];
    channel = channel_new(channel_name);
    do { if (((channel)->list.le_next = (&irc->channel_list_head)->lh_first) != ((void *)0)) (&irc->channel_list_head)->lh_first->list.le_prev = &(channel)->list.le_next; (&irc->channel_list_head)->lh_first = (channel); (channel)->list.le_prev = &(&irc->channel_list_head)->lh_first; } while ( 0);
}


decompiled_code:
__int64 __fastcall process_command_part_user(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12

result = channel_find(a1 + 1720, a1 + 410);
if ( result )
{
v2 = result;
fprintf(stdout, "process_command_part_user, nickname: %s\n", (const char *)(a1 + 100));
result = channel_remove_user(v2, a1 + 100);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12

result = channel_find(a1 + 1720, a1 + 410);
if ( result )
{
v2 = result;
fprintf(stdout, "process_command_part_user, nickname: %s\n", (const char *)(a1 + 100));
result = channel_remove_user(v2, a1 + 100);
}
return result;
}

original_code:
static void process_command_part_user(struct irc_t * irc)
{
    struct channel_t * channel;
    char * channel_name, * nickname;
    channel_name = irc->message.params[0];
    if (channel_name == ((void *)0)) {
        return;
    }
    nickname = irc->message.prefix.nickname.nickname;
    if (nickname == ((void *)0)) {
        return;
    }
    channel = channel_find(&irc->channel_list_head, channel_name);
    if (channel == ((void *)0)) {
        return;
    }
    fprintf(stdout, "process_command_part_user, nickname: %s\n", nickname);
    channel_remove_user(channel, nickname);
}

canonical_original_code:
static void process_command_part_user(struct irc_t *irc)
{
    struct channel_t *channel;
    char *channel_name; char *nickname;
    channel_name = irc->message.params[0];
    if (channel_name == ((void *)0)) {
        return;
    }
    nickname = irc->message.prefix.nickname.nickname;
    if (nickname == ((void *)0)) {
        return;
    }
    channel = channel_find(&irc->channel_list_head, channel_name);
    if (channel == ((void *)0)) {
        return;
    }
    fprintf(stdout, "process_command_part_user, nickname: %s\n", nickname);
    channel_remove_user(channel, nickname);
}


decompiled_code:
__int64 __fastcall irc_set_nick(__int64 a1, const char *a2)
{
size_t v2; // rax
char v4[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v4, 0x1FEuLL, "NICK %s\r\n", a2);
v2 = strlen(v4);
return socket_write(*(_QWORD *)(a1 + 1728), v4, v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2)
{
size_t v2; // rax
char v4[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v4, 0x1FEuLL, "NICK %s\r\n", a2);
v2 = strlen(v4);
return socket_write(*(_QWORD *)(a1 + 1728), v4, v2);
}

original_code:
void irc_set_nick(struct irc_t * irc, char * nickname)
{
    char buffer[510];
    snprintf(buffer, 510, "NICK %s\r\n", nickname);
    socket_write(irc->sockfd, buffer, strlen(buffer));
}

canonical_original_code:
void irc_set_nick(struct irc_t *irc, char *nickname)
{
    char buffer[510];
    snprintf(buffer, 510, "NICK %s\r\n", nickname);
    socket_write(irc->sockfd, buffer, strlen(buffer));
}

variable_types:
buffer
char [510]


decompiled_code:
__int64 __fastcall irc_set_user(__int64 a1, const char *a2, const char *a3)
{
size_t v3; // rax
char v5[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v5, 0x1FEuLL, "USER %s 8 * :%s\r\n\r\n", a2, a3);
v3 = strlen(v5);
return socket_write(*(_QWORD *)(a1 + 1728), v5, v3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2, const char *a3)
{
size_t v3; // rax
char v5[520]; // [rsp+0h] [rbp-208h] BYREF

snprintf(v5, 0x1FEuLL, "USER %s 8 * :%s\r\n\r\n", a2, a3);
v3 = strlen(v5);
return socket_write(*(_QWORD *)(a1 + 1728), v5, v3);
}

original_code:
void irc_set_user(struct irc_t * irc, char * user, char * host)
{
    char buffer[510];
    snprintf(buffer, 510, "USER %s 8 * :%s\r\n\r\n", user, host);
    socket_write(irc->sockfd, buffer, strlen(buffer));
}

canonical_original_code:
void irc_set_user(struct irc_t *irc, char *user, char *host)
{
    char buffer[510];
    snprintf(buffer, 510, "USER %s 8 * :%s\r\n\r\n", user, host);
    socket_write(irc->sockfd, buffer, strlen(buffer));
}

variable_types:
user
char *

variable_types:
host
char *