decompiled_code:
__int64 __fastcall tree_init(const char *a1, __int64 a2)
{
__int64 result; // rax
int *v3; // rax

debug("tree.c", 82LL, "tree_init", "path \"%s\" size %lu", a1, a2);
result = pmemalloc_init(a1, a2);
Pmp = result;
if ( !result )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "tree.c", 85LL, "tree_init", "pmemalloc_init on %s", a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2)
{
__int64 result; // rax
int *v3; // rax

debug("tree.c", 82LL, "tree_init", "path \"%s\" size %lu", a1, a2);
result = pmemalloc_init(a1, a2);
Pmp = result;
if ( !result )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "tree.c", 85LL, "tree_init", "pmemalloc_init on %s", a1);
}
return result;
}

original_code:
void
tree_init(const char *path, size_t size)
{
 debug("tree.c", 82, __func__, "path \"%s\" size %lu", path, size);
 if ((Pmp = pmemalloc_init(path, size)) == ((void *)0))
  fatal((*__errno_location ()), "tree.c", 85, __func__, "pmemalloc_init on %s", path);
}

canonical_original_code:
void tree_init(char *path, unsigned long size)
{
 debug("tree.c", 82, __func__, "path \"%s\" size %lu", path, size);
 if ((Pmp = pmemalloc_init(path, size)) == ((void *)0))
  fatal((*__errno_location ()), "tree.c", 85, __func__, "pmemalloc_init on %s", path);
}

variable_types:
path
char *

variable_types:
size
unsigned long


repo: pmem/linux-examples

decompiled_code:
__int64 __fastcall tree_insert(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)pmemalloc_static_area(Pmp);
return tree_insert_subtree(v1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)pmemalloc_static_area(Pmp);
return func0(v1, a1);
}

original_code:
void
tree_insert(const char *s)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_insert_subtree(&sp->root_, s);
}

canonical_original_code:
void tree_insert(char *s)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_insert_subtree(&sp->root_, s);
}

variable_types:
s
char *

variable_types: struct static_info { struct tnode { struct tnode *left_; struct tnode *right_; unsigned int count; char s[]; } *root_; } *

return_type: void

user_defined_types: struct static_info { struct tnode *root_; }


decompiled_code:
__int64 tree_walk()
{
__int64 *v0; // rax

v0 = (__int64 *)pmemalloc_static_area(Pmp);
return tree_walk_subtree(*v0);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 *v0; // rax

v0 = (__int64 *)pmemalloc_static_area(Pmp);
return func1(*v0);
}

original_code:
void
tree_walk(void)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_walk_subtree(sp->root_);
}

canonical_original_code:
void tree_walk()
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_walk_subtree(sp->root_);
}

user_defined_types: struct tnode { struct tnode *left_; struct tnode *right_; unsigned int count; char s[]; }


decompiled_code:
__int64 tree_free()
{
_QWORD *v0; // rax

v0 = (_QWORD *)pmemalloc_static_area(Pmp);
return tree_free_subtree(v0);
}

canonical_decompiled_code:
__int64 func6()
{
_QWORD *v0; // rax

v0 = (_QWORD *)pmemalloc_static_area(Pmp);
return func2(v0);
}

original_code:
void
tree_free(void)
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_free_subtree(&sp->root_);
}

canonical_original_code:
void tree_free()
{
 struct static_info *sp = pmemalloc_static_area(Pmp);
 tree_free_subtree(&sp->root_);
}


exename

decompiled_code:
char *exename()
{
unsigned int v0; // eax
int v1; // eax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

v0 = getpid();
snprintf(v3, 0x1000uLL, "/proc/%d/exe", v0);
v1 = readlink(v3, exename_0, 0x1000uLL);
if ( v1 < 0 )
strcpy(exename_0, "Unknown");
else
exename_0[v1] = 0;
return exename_0;
}

canonical_decompiled_code:
char *func0()
{
unsigned int v0; // eax
int v1; // eax
char v3[4104]; // [rsp+0h] [rbp-1008h] BYREF

v0 = getpid();
snprintf(v3, 0x1000uLL, "/proc/%d/exe", v0);
v1 = readlink(v3, exename_0, 0x1000uLL);
if ( v1 < 0 )
strcpy(exename_0, "Unknown");
else
exename_0[v1] = 0;
return exename_0;
}

original_code:
static const char *
exename(void)
{
 char proc[4096];
 static char exename[4096];
 int nbytes;
 snprintf(proc, 4096, "/proc/%d/exe", getpid());
 if ((nbytes = readlink(proc, exename, 4096)) < 0)
  strcpy(exename, "Unknown");
 else
  exename[nbytes] = '\0';
 return exename;
}

canonical_original_code:
static char *exename()
{
 char proc[4096];
 static char exename[4096];
 int nbytes;
 snprintf(proc, 4096, "/proc/%d/exe", getpid());
 if ((nbytes = readlink(proc, exename, 4096)) < 0)
  strcpy(exename, "Unknown");
 else
  exename[nbytes] = '\0';
 return exename;
}

variable_types:
proc
char [4096]

variable_types:
exename
char [4096]

variable_types: nbytes int

return_type: char *


debug

decompiled_code:
int debug(const char *a1, unsigned int a2, const char *a3, const char *a4, ...)
{
int result; // eax
int *v7; // rax
int v8; // er15
int *v9; // r13
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

result = Debug;
if ( Debug )
{
v7 = _errno_location();
v8 = *v7;
v9 = v7;
fprintf(stderr, "debug: %s:%d %s()", a1, a2, a3);
if ( a4 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a4);
vfprintf(stderr, a4, arg);
}
result = fputc(10, stderr);
*v9 = v8;
}
return result;
}

canonical_decompiled_code:
int func1(const char *a1, unsigned int a2, const char *a3, const char *a4, ...)
{
int result; // eax
int *v7; // rax
int v8; // er15
int *v9; // r13
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

result = Debug;
if ( Debug )
{
v7 = _errno_location();
v8 = *v7;
v9 = v7;
fprintf(stderr, "debug: %s:%d %s()", a1, a2, a3);
if ( a4 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a4);
vfprintf(stderr, a4, arg);
}
result = fputc(10, stderr);
*v9 = v8;
}
return result;
}

original_code:
void
debug(const char *file, int line, const char *func, const char *fmt, ...)
{
 va_list ap;
 int save_errno;
 if (!Debug)
  return;
 save_errno = (*__errno_location ());
 fprintf(stderr, "debug: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 (*__errno_location ()) = save_errno;
}

canonical_original_code:
void debug(char *file, int line, char *func, char *fmt, ...)
{
 __builtin_va_list ap;
 int save_errno;
 if (!Debug)
  return;
 save_errno = (*__errno_location ());
 fprintf(stderr, "debug: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 (*__errno_location ()) = save_errno;
}

variable_types:
file
char *

variable_types: line int

variable_types:
func
char *

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(int errnum, const char *a2, unsigned int a3, const char *a4, const char *a5, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

fprintf(stderr, "ERROR: %s:%d %s()", a2, a3, a4);
if ( a5 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a5);
vfprintf(stderr, a5, arg);
}
if ( errnum )
{
v6 = strerror(errnum);
fprintf(stderr, ": %s", v6);
}
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(int errnum, const char *a2, unsigned int a3, const char *a4, const char *a5, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

fprintf(stderr, "ERROR: %s:%d %s()", a2, a3, a4);
if ( a5 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a5);
vfprintf(stderr, a5, arg);
}
if ( errnum )
{
v6 = strerror(errnum);
fprintf(stderr, ": %s", v6);
}
fputc(10, stderr);
exit(1);
}

original_code:
void
fatal(int err, const char *file, int line, const char *func,
 const char *fmt, ...)
{
 va_list ap;
 fprintf(stderr, "ERROR: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 if (err)
  fprintf(stderr, ": %s", strerror(err));
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
void fatal(int err, char *file, int line, char *func, char *fmt, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "ERROR: %s:%d %s()", file, line, func);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 if (err)
  fprintf(stderr, ": %s", strerror(err));
 fprintf(stderr, "\n");
 exit(1);
}

variable_types: err int


usage

decompiled_code:
void __noreturn usage(const char *a1, const char *a2, ...)
{
char *v2; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)Myname;
if ( !Myname )
v2 = exename();
fprintf(stderr, "Usage: %s", v2);
if ( a1 )
fprintf(stderr, " %s", a1);
if ( a2 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a2);
vfprintf(stderr, a2, arg);
}
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, const char *a2, ...)
{
char *v2; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)Myname;
if ( !Myname )
v2 = func0();
fprintf(stderr, "Usage: %s", v2);
if ( a1 )
fprintf(stderr, " %s", a1);
if ( a2 )
{
fwrite(": ", 1uLL, 2uLL, stderr);
va_start(arg, a2);
vfprintf(stderr, a2, arg);
}
fputc(10, stderr);
exit(1);
}

original_code:
void
usage(const char *argfmt, const char *fmt, ...)
{
 va_list ap;
 fprintf(stderr, "Usage: %s", (Myname == ((void *)0)) ? exename() : Myname);
 if (argfmt)
  fprintf(stderr, " %s", argfmt);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 exit(1);
}

canonical_original_code:
void usage(char *argfmt, char *fmt, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "Usage: %s", (Myname == ((void *)0)) ? exename() : Myname);
 if (argfmt)
  fprintf(stderr, " %s", argfmt);
 if (fmt) {
  fprintf(stderr, ": ");
  __builtin_va_start(ap,fmt);
  vfprintf(stderr, fmt, ap);
  __builtin_va_end(ap);
 }
 fprintf(stderr, "\n");
 exit(1);
}

variable_types:
argfmt
char *


decompiled_code:
void *__fastcall pmem_map_msync(int fd, size_t a2)
{
void *result; // rax

result = mmap(0LL, a2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int fd, size_t a2)
{
void *result; // rax

result = mmap(0LL, a2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

original_code:
void *
pmem_map_msync(int fd, size_t len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}

canonical_original_code:
void *pmem_map_msync(int fd, unsigned long len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}

variable_types: fd int

variable_types:
len
unsigned long

variable_types:
base
void *

return_type: void *


decompiled_code:
void pmem_drain_pm_stores_msync()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
pmem_drain_pm_stores_msync(void)
{
}

canonical_original_code:
void pmem_drain_pm_stores_msync()
{
}


decompiled_code:
int __fastcall pmem_flush_cache_msync(__int64 a1, __int64 a2)
{
int result; // eax
int *v3; // rax

result = msync((void *)(a1 & 0xFFFFFFFFFFFFF000LL), ((a1 & 0xFFF) + a2 + 4095) & 0xFFFFFFFFFFFFF000LL, 4);
if ( result < 0 )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "pmem_msync.c", 106LL, "pmem_flush_cache_msync", "msync");
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
int result; // eax
int *v3; // rax

result = msync((void *)(a1 & 0xFFFFFFFFFFFFF000LL), ((a1 & 0xFFF) + a2 + 4095) & 0xFFFFFFFFFFFFF000LL, 4);
if ( result < 0 )
{
v3 = _errno_location();
result = fatal((unsigned int)*v3, "pmem_msync.c", 106LL, "pmem_flush_cache_msync", "msync");
}
return result;
}

original_code:
void
pmem_flush_cache_msync(void *addr, size_t len, int flags)
{
 uintptr_t uptr;
 len += (uintptr_t)addr & (4096 - 1);
 uptr = (uintptr_t)addr & ~(4096 - 1);
 len = (len + (4096 - 1)) & ~(4096 - 1);
 if (msync((void *)uptr, len, 4) < 0)
  fatal((*__errno_location ()), "pmem_msync.c", 106, __func__, "msync");
}

canonical_original_code:
void pmem_flush_cache_msync(void *addr, unsigned long len, int flags)
{
 unsigned long uptr;
 len += (unsigned long)addr & (4096 - 1);
 uptr = (unsigned long)addr & ~(4096 - 1);
 len = (len + (4096 - 1)) & ~(4096 - 1);
 if (msync((void *)uptr, len, 4) < 0)
  fatal((*__errno_location ()), "pmem_msync.c", 106, __func__, "msync");
}

variable_types:
addr
void *

variable_types: flags int

variable_types:
uptr
unsigned long


decompiled_code:
void __fastcall pmem_persist_msync(__int64 a1, __int64 a2)
{
pmem_flush_cache_msync(a1, a2);
_mm_sfence();
pmem_drain_pm_stores_msync();
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
func2(a1, a2);
_mm_sfence();
func1();
}

original_code:
void
pmem_persist_msync(void *addr, size_t len, int flags)
{
 pmem_flush_cache_msync(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_msync();
}

canonical_original_code:
void pmem_persist_msync(void *addr, unsigned long len, int flags)
{
 pmem_flush_cache_msync(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_msync();
}


trigger

decompiled_code:
void trigger()
{
Nothing = 0LL;
}

canonical_decompiled_code:
void func0()
{
Nothing = 0LL;
}

original_code:
static void
trigger(void)
{
 Nothing = 0;
}

canonical_original_code:
static void trigger()
{
 Nothing = 0;
}


handler

decompiled_code:
void __noreturn handler()
{
longjmp(Trigjmp, 1);
}

canonical_decompiled_code:
void __noreturn func1()
{
longjmp(Trigjmp, 1);
}

original_code:
static void
handler()
{
 longjmp(Trigjmp, 1);
}


pretrigger

decompiled_code:
void __noreturn pretrigger()
{
getpid();
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func2()
{
getpid();
while ( 1 )
;
}

original_code:
static void
pretrigger(void)
{
 int x = getpid();
 while (1) {
  x++;
  Nothing += x;
 }
}

canonical_original_code:
static void pretrigger()
{
 int x = getpid();
 while (1) {
  x++;
  Nothing += x;
 }
}

variable_types: x int


decompiled_code:
__pid_t icount_stop()
{
__pid_t result; // eax
int *v1; // rax
int *v2; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( read(Tracerpipe[0], &Total, 8uLL) < 0 )
{
v1 = _errno_location();
fatal((unsigned int)*v1, "../icount/icount.c", 246LL, "icount_stop", "read from pipe");
}
close(Tracerpipe[0]);
result = waitpid(Tracer_pid, stat_loc, 0);
if ( result < 0 )
{
v2 = _errno_location();
result = fatal(
(unsigned int)*v2,
"../icount/icount.c",
251LL,
"icount_stop",
"waitpid(pid=%d)",
(unsigned int)Tracer_pid);
}
Tracer_pid = 0;
return result;
}

canonical_decompiled_code:
__pid_t func4()
{
__pid_t result; // eax
int *v1; // rax
int *v2; // rax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( read(Tracerpipe[0], &Total, 8uLL) < 0 )
{
v1 = _errno_location();
fatal((unsigned int)*v1, "../icount/icount.c", 246LL, "icount_stop", "read from pipe");
}
close(Tracerpipe[0]);
result = waitpid(Tracer_pid, stat_loc, 0);
if ( result < 0 )
{
v2 = _errno_location();
result = fatal(
(unsigned int)*v2,
"../icount/icount.c",
251LL,
"icount_stop",
"waitpid(pid=%d)",
(unsigned int)Tracer_pid);
}
Tracer_pid = 0;
return result;
}

original_code:
void
icount_stop(void)
{
 int status;
 if (read(Tracerpipe[0], &Total, sizeof(Total)) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 246, __func__, "read from pipe");
 close(Tracerpipe[0]);
 if (waitpid(Tracer_pid, &status, 0) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 251, __func__, "waitpid(pid=%d)", Tracer_pid);
 Tracer_pid = 0;
}

canonical_original_code:
void icount_stop()
{
 int status;
 if (read(Tracerpipe[0], &Total, sizeof(Total)) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 246, __func__, "read from pipe");
 close(Tracerpipe[0]);
 if (waitpid(Tracer_pid, &status, 0) < 0)
  fatal((*__errno_location ()), "../icount/icount.c", 251, __func__, "waitpid(pid=%d)", Tracer_pid);
 Tracer_pid = 0;
}

variable_types: status int


decompiled_code:
__int64 icount_total()
{
return Total;
}

canonical_decompiled_code:
__int64 func6()
{
return Total;
}

original_code:
unsigned long
icount_total(void)
{
 return Total;
}

canonical_original_code:
unsigned long icount_total()
{
 return Total;
}

return_type: unsigned long


decompiled_code:
void *__fastcall pmem_map_cl(int fd, size_t a2)
{
void *result; // rax

result = mmap(0LL, a2, 3, 1, fd, 0LL);
if ( result == (void *)-1LL )
result = 0LL;
return result;
}

original_code:
void *
pmem_map_cl(int fd, size_t len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}

canonical_original_code:
void *pmem_map_cl(int fd, unsigned long len)
{
 void *base;
 if ((base = mmap(((void *)0), len, 0x1|0x2, 0x01,
     fd, 0)) == ((void *) -1))
  return ((void *)0);
 return base;
}


decompiled_code:
void pmem_drain_pm_stores_cl()
{
;
}

original_code:
void
pmem_drain_pm_stores_cl(void)
{
}

canonical_original_code:
void pmem_drain_pm_stores_cl()
{
}


decompiled_code:
char *__fastcall pmem_flush_cache_cl(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
char *result; // rax

v2 = a1 + a2;
result = (char *)(a1 & 0xFFFFFFFFFFFFFFC0LL);
if ( (a1 & 0xFFFFFFFFFFFFFFC0LL) < v2 )
{
do
{
_mm_clflush(result);
result += 64;
}
while ( (unsigned __int64)result < v2 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
char *result; // rax

v2 = a1 + a2;
result = (char *)(a1 & 0xFFFFFFFFFFFFFFC0LL);
if ( (a1 & 0xFFFFFFFFFFFFFFC0LL) < v2 )
{
do
{
_mm_clflush(result);
result += 64;
}
while ( (unsigned __int64)result < v2 );
}
return result;
}

original_code:
void
pmem_flush_cache_cl(void *addr, size_t len, int flags)
{
 uintptr_t uptr;
 for (uptr = (uintptr_t)addr & ~(64 - 1);
   uptr < (uintptr_t)addr + len; uptr += 64)
  __builtin_ia32_clflush((void *)uptr);
}

canonical_original_code:
void pmem_flush_cache_cl(void *addr, unsigned long len, int flags)
{
 unsigned long uptr;
 for (uptr = (unsigned long)addr & ~(64 - 1);
   uptr < (unsigned long)addr + len; uptr += 64)
  __builtin_ia32_clflush((void *)uptr);
}


decompiled_code:
void __fastcall pmem_persist_cl(__int64 a1, __int64 a2)
{
pmem_flush_cache_cl(a1, a2);
_mm_sfence();
pmem_drain_pm_stores_cl();
}

original_code:
void
pmem_persist_cl(void *addr, size_t len, int flags)
{
 pmem_flush_cache_cl(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_cl();
}

canonical_original_code:
void pmem_persist_cl(void *addr, unsigned long len, int flags)
{
 pmem_flush_cache_cl(addr, len, flags);
 __builtin_ia32_sfence();
 pmem_drain_pm_stores_cl();
}


decompiled_code:
void pmem_msync_mode()
{
Mode = 1;
}

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

original_code:
void
pmem_msync_mode(void)
{
 Mode = 1;
}

canonical_original_code:
void pmem_msync_mode()
{
 Mode = 1;
}


decompiled_code:
void pmem_fit_mode()
{
Mode = 2;
}

canonical_decompiled_code:
void func1()
{
Mode = 2;
}

original_code:
void
pmem_fit_mode(void)
{
 Mode = 2;
}

canonical_original_code:
void pmem_fit_mode()
{
 Mode = 2;
}


decompiled_code:
__int64 pmem_map()
{
return ((__int64 (*)(void))*(&Map + Mode))();
}

original_code:
void *
pmem_map(int fd, size_t len)
{
 return (*Map[Mode])(fd, len);
}

canonical_original_code:
void *pmem_map(int fd, unsigned long len)
{
 return (*Map[Mode])(fd, len);
}


decompiled_code:
__int64 pmem_persist()
{
return ((__int64 (*)(void))*(&Persist + Mode))();
}

canonical_decompiled_code:
__int64 func3()
{
return ((__int64 (*)(void))*(&Persist + Mode))();
}

original_code:
void
pmem_persist(void *addr, size_t len, int flags)
{
 (*Persist[Mode])(addr, len, flags);
}

canonical_original_code:
void pmem_persist(void *addr, unsigned long len, int flags)
{
 (*Persist[Mode])(addr, len, flags);
}


decompiled_code:
__int64 pmem_flush_cache()
{
return ((__int64 (*)(void))*(&Flush + Mode))();
}

original_code:
void
pmem_flush_cache(void *addr, size_t len, int flags)
{
 (*Flush[Mode])(addr, len, flags);
}

canonical_original_code:
void pmem_flush_cache(void *addr, unsigned long len, int flags)
{
 (*Flush[Mode])(addr, len, flags);
}


decompiled_code:
void pmem_fence()
{
_mm_sfence();
}

canonical_decompiled_code:
void func5()
{
_mm_sfence();
}

original_code:
void
pmem_fence(void)
{
 __builtin_ia32_sfence();
}

canonical_original_code:
void pmem_fence()
{
 __builtin_ia32_sfence();
}


decompiled_code:
__int64 pmem_drain_pm_stores()
{
return ((__int64 (*)(void))*(&Drain_pm_stores + Mode))();
}

canonical_decompiled_code:
__int64 func6()
{
return ((__int64 (*)(void))*(&Drain_pm_stores + Mode))();
}

original_code:
void
pmem_drain_pm_stores(void)
{
 (*Drain_pm_stores[Mode])();
}

canonical_original_code:
void pmem_drain_pm_stores()
{
 (*Drain_pm_stores[Mode])();
}


repo: pmer/yak

decompiled_code:
int create_uithread()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++nthreads;
return pthread_create(newthread, 0LL, uimain, 0LL);
}

canonical_decompiled_code:
int func6()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++nthreads;
return pthread_create(newthread, 0LL, uimain, 0LL);
}

original_code:
static void create_uithread()
{
 pthread_t thread;
 nthreads++;
 pthread_create(&thread, ((void *)0), uimain, ((void *)0));
}

canonical_original_code:
static void create_uithread()
{
 unsigned long thread;
 nthreads++;
 pthread_create(&thread, ((void *)0), uimain, ((void *)0));
}

variable_types:
thread
unsigned long


say

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

if ( chan )
result = ircproto_privmsg();
else
result = info();
return result;
}

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

if ( chan )
result = ircproto_privmsg();
else
result = info();
return result;
}

original_code:
static void say(char *line)
{
 if (*chan)
  ircproto_privmsg(chan, "%s", line);
 else
  info("please '/cd' into a channel first");
}

variable_types:
line
char *


uimain

decompiled_code:
__int64 __fastcall uimain(void *a1)
{
_BYTE *v1; // rbp

while ( 1 )
{
v1 = (_BYTE *)readline();
if ( !v1 )
break;
mutex_on();
if ( *v1 == 47 )
{
if ( !(unsigned __int8)eval_emit() )
info();
}
else
{
say(v1);
}
mutex_off();
free(v1);
}
putchar(10);
return safe_shutdown_and_die();
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1)
{
_BYTE *v1; // rbp

while ( 1 )
{
v1 = (_BYTE *)readline();
if ( !v1 )
break;
mutex_on();
if ( *v1 == 47 )
{
if ( !(unsigned __int8)eval_emit() )
info();
}
else
{
func8(v1);
}
mutex_off();
free(v1);
}
putchar(10);
return safe_shutdown_and_die();
}

original_code:
static void *uimain(void *unused)
{
 char *line;
 while (line = readline("> ")) {
  mutex_on();
  if (line[0] == '/') {
   if (!eval_emit(ectx, line + 1)) {
    info("invalid command: %s", line);
   }
  } else {
   say(line);
  }
  mutex_off();
  free(line);
 }
 printf("\n");
 safe_shutdown_and_die(0);
}

variable_types:
unused
void *


msg

decompiled_code:
__int64 msg()
{
return ircproto_privmsg();
}

canonical_decompiled_code:
__int64 func10()
{
return ircproto_privmsg();
}

original_code:
static void msg(char *line, char **caps, int ncaps)
{
 ircproto_privmsg(caps[0], "%s", caps[1]);
}

variable_types:
caps
char **

variable_types: ncaps int


nick

decompiled_code:
__int64 __fastcall nick(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
free(bot_nick);
bot_nick = strdup(*(const char **)a2);
return ircproto_nick();
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
free(bot_nick);
bot_nick = strdup(*(const char **)a2);
return ircproto_nick();
}

original_code:
static void nick(char *line, char **caps, int ncaps)
{
 if (ncaps > 1 && *caps[1])
  info("nick: must have one argument");
 free(bot_nick);
 bot_nick = strdup(caps[0]);
 ircproto_nick(caps[0]);
}


cd

decompiled_code:
char *__fastcall cd(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
info();
return strcpy(&chan, *(const char **)a2);
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, __int64 a2, int a3)
{
if ( a3 > 1 && **(_BYTE **)(a2 + 8) )
info();
info();
return strcpy(&chan, *(const char **)a2);
}

original_code:
static void cd(char *line, char **caps, int ncaps)
{
 if (ncaps > 1 && *caps[1])
  info("cd: must have one argument");
 info("now talking on %s", caps[0]);
 strcpy(chan, caps[0]);
}


quit

decompiled_code:
__int64 quit()
{
return safe_shutdown_and_die();
}

canonical_decompiled_code:
__int64 func7()
{
return safe_shutdown_and_die();
}

original_code:
static void quit(char *line, char **caps, int ncaps)
{
 safe_shutdown_and_die(0);
}


finish

decompiled_code:
__int64 finish()
{
return eval_destroy();
}

canonical_decompiled_code:
__int64 func14()
{
return eval_destroy();
}

original_code:
void finish()
{
 eval_destroy(ectx);
}

canonical_original_code:
void finish()
{
 eval_destroy(ectx);
}


decompiled_code:
__int64 __fastcall ircproto_parse_prefix(char *src, char *dest, int a3, char *a4, int a5, char *a6, int a7)
{
char *v9; // rbp
char *v10; // r12
__int64 result; // rax
int v12; // er8
int v13; // edx
int v14; // edx
const char *v15; // rsi
int v16; // ebx
int v17; // er12
__int64 v19; // [rsp+8h] [rbp-60h]
__int64 v20; // [rsp+8h] [rbp-60h]
int v21; // [rsp+10h] [rbp-58h]
int v22; // [rsp+1Ch] [rbp-4Ch]
int v24; // [rsp+28h] [rbp-40h]

v9 = strchr(src, 33);
v10 = strchr(src, 64);
result = strlen(src);
v24 = result;
if ( dest )
{
v12 = (_DWORD)v9 - (_DWORD)src;
if ( !v9 )
v12 = result;
v21 = a3 - 1;
v13 = v12;
v22 = v12;
if ( a3 - 1 <= v12 )
v13 = a3 - 1;
v19 = v13;
result = (__int64)strncpy(dest, src, v13);
dest[v19] = 0;
if ( v21 < v22 )
result = info("parse_prefix: %s: nick overflow", dest);
}
if ( a4 )
{
if ( v9 )
{
v14 = (_DWORD)v10 - ((_DWORD)v9 + 1);
if ( a5 - 1 <= v14 )
v14 = a5 - 1;
v20 = v14;
result = (__int64)strncpy(a4, v9 + 1, v14);
a4[v20] = 0;
if ( a5 - 1 < (int)v10 - ((int)v9 + 1) )
result = info("parse_prefix: %s: uname overflow", a4);
}
else
{
*a4 = 0;
}
}
if ( a6 )
{
if ( v10 )
{
v15 = v10 + 1;
v16 = v24 + (_DWORD)src - ((_DWORD)v10 + 1);
v17 = v16;
if ( a7 - 1 <= v16 )
v17 = a7 - 1;
result = (__int64)strncpy(a6, v15, v17);
a6[v17] = 0;
if ( a7 - 1 < v16 )
result = info("parse_prefix: %s: host overflow", a6);
}
else
{
*a6 = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, char *dest, int a3, char *a4, int a5, char *a6, int a7)
{
char *v9; // rbp
char *v10; // r12
__int64 result; // rax
int v12; // er8
int v13; // edx
int v14; // edx
const char *v15; // rsi
int v16; // ebx
int v17; // er12
__int64 v19; // [rsp+8h] [rbp-60h]
__int64 v20; // [rsp+8h] [rbp-60h]
int v21; // [rsp+10h] [rbp-58h]
int v22; // [rsp+1Ch] [rbp-4Ch]
int v24; // [rsp+28h] [rbp-40h]

v9 = strchr(src, 33);
v10 = strchr(src, 64);
result = strlen(src);
v24 = result;
if ( dest )
{
v12 = (_DWORD)v9 - (_DWORD)src;
if ( !v9 )
v12 = result;
v21 = a3 - 1;
v13 = v12;
v22 = v12;
if ( a3 - 1 <= v12 )
v13 = a3 - 1;
v19 = v13;
result = (__int64)strncpy(dest, src, v13);
dest[v19] = 0;
if ( v21 < v22 )
result = info("parse_prefix: %s: nick overflow", dest);
}
if ( a4 )
{
if ( v9 )
{
v14 = (_DWORD)v10 - ((_DWORD)v9 + 1);
if ( a5 - 1 <= v14 )
v14 = a5 - 1;
v20 = v14;
result = (__int64)strncpy(a4, v9 + 1, v14);
a4[v20] = 0;
if ( a5 - 1 < (int)v10 - ((int)v9 + 1) )
result = info("parse_prefix: %s: uname overflow", a4);
}
else
{
*a4 = 0;
}
}
if ( a6 )
{
if ( v10 )
{
v15 = v10 + 1;
v16 = v24 + (_DWORD)src - ((_DWORD)v10 + 1);
v17 = v16;
if ( a7 - 1 <= v16 )
v17 = a7 - 1;
result = (__int64)strncpy(a6, v15, v17);
a6[v17] = 0;
if ( a7 - 1 < v16 )
result = info("parse_prefix: %s: host overflow", a6);
}
else
{
*a6 = 0;
}
}
return result;
}

original_code:
void ircproto_parse_prefix(char *prefix,
                  char *nick, int nicksz,
                  char *user, int usersz,
                  char *host, int hostsz)
{
 char *bang, *at, *end, *uidx, *hidx;
 int nlen, ulen, hlen;
 int ncpy, ucpy, hcpy;
 bang = strchr(prefix, '!');
 at = strchr(prefix, '@');
 end = prefix + strlen(prefix);
 if (nick) {
  nlen = bang ? bang - prefix : end - prefix;
  ncpy = ((nlen) < (nicksz - 1) ? (nlen) : (nicksz - 1));
  strncpy(nick, prefix, ncpy);
  nick[ncpy] = '\0';
  if (ncpy != nlen)
   info("parse_prefix: %s: nick overflow", nick);
 }
 if (user) {
  if (bang) {
   uidx = bang + 1;
   ulen = at - uidx;
   ucpy = ((ulen) < (usersz - 1) ? (ulen) : (usersz - 1));
   strncpy(user, uidx, ucpy);
   user[ucpy] = '\0';
   if (ucpy != ulen)
    info("parse_prefix: %s: uname overflow", user);
  }
  else
   user[0] = '\0';
 }
 if (host) {
  if (at) {
   hidx = at + 1;
   hlen = end - hidx;
   hcpy = ((hlen) < (hostsz - 1) ? (hlen) : (hostsz - 1));
   strncpy(host, hidx, hcpy);
   host[hcpy] = '\0';
   if (hcpy != hlen)
    info("parse_prefix: %s: host overflow", host);
  }
  else
   host[0] = '\0';
 }
}

canonical_original_code:
void ircproto_parse_prefix(char *prefix, char *nick, int nicksz, char *user, int usersz, char *host, int hostsz)
{
 char *bang; char *at; char *end; char *uidx; char *hidx;
 int nlen; int ulen; int hlen;
 int ncpy; int ucpy; int hcpy;
 bang = strchr(prefix, '!');
 at = strchr(prefix, '@');
 end = prefix + strlen(prefix);
 if (nick) {
  nlen = bang ? bang - prefix : end - prefix;
  ncpy = ((nlen) < (nicksz - 1) ? (nlen) : (nicksz - 1));
  strncpy(nick, prefix, ncpy);
  nick[ncpy] = '\0';
  if (ncpy != nlen)
   info("parse_prefix: %s: nick overflow", nick);
 }
 if (user) {
  if (bang) {
   uidx = bang + 1;
   ulen = at - uidx;
   ucpy = ((ulen) < (usersz - 1) ? (ulen) : (usersz - 1));
   strncpy(user, uidx, ucpy);
   user[ucpy] = '\0';
   if (ucpy != ulen)
    info("parse_prefix: %s: uname overflow", user);
  }
  else
   user[0] = '\0';
 }
 if (host) {
  if (at) {
   hidx = at + 1;
   hlen = end - hidx;
   hcpy = ((hlen) < (hostsz - 1) ? (hlen) : (hostsz - 1));
   strncpy(host, hidx, hcpy);
   host[hcpy] = '\0';
   if (hcpy != hlen)
    info("parse_prefix: %s: host overflow", host);
  }
  else
   host[0] = '\0';
 }
}

variable_types:
prefix
char *

variable_types:
nick
char *

variable_types: nicksz int

variable_types:
user
char *

variable_types: usersz int

variable_types:
host
char *

variable_types: hostsz int

variable_types:
bang
char *

variable_types:
at
char *

variable_types:
end
char *

variable_types:
uidx
char *

variable_types:
hidx
char *

variable_types: nlen int

variable_types: ulen int

variable_types: hlen int

variable_types: ncpy int

variable_types: ucpy int

variable_types: hcpy int


decompiled_code:
__int64 __fastcall ircproto_pong(const char *a1)
{
return sock_sendline("PONG %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
return sock_sendline("PONG %s", a1);
}

original_code:
void ircproto_pong(char *id)
{
 sock_sendline("PONG %s", id);
}

variable_types:
id
char *


decompiled_code:
__int64 __fastcall ircproto_nick(const char *a1)
{
return sock_sendline("NICK %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
return sock_sendline("NICK %s", a1);
}

original_code:
void ircproto_nick(char *nick)
{
 sock_sendline("NICK %s", nick);
}

variable_types:
nick
char *


decompiled_code:
__int64 __fastcall ircproto_user(const char *a1, const char *a2)
{
return sock_sendline("USER %s 0 * :%s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
return sock_sendline("USER %s 0 * :%s", a1, a2);
}

original_code:
void ircproto_user(char *username, char *real_name)
{
 sock_sendline("USER %s 0 * :%s", username, real_name);
}

variable_types:
username
char *


decompiled_code:
__int64 __fastcall ircproto_identify(const char *a1, const char *a2)
{
return sock_sendline("PRIVMSG %s IDENTIFY %s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2)
{
return sock_sendline("PRIVMSG %s IDENTIFY %s", a1, a2);
}

original_code:
void ircproto_identify(char *nickserv_nick, char *password)
{
 sock_sendline("PRIVMSG %s IDENTIFY %s", nickserv_nick, password);
}

variable_types:
password
char *


decompiled_code:
__int64 __fastcall ircproto_oper(const char *a1, const char *a2)
{
return sock_sendline("OPER %s %s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
return sock_sendline("OPER %s %s", a1, a2);
}

original_code:
void ircproto_oper(char *oper_username, char *password)
{
 sock_sendline("OPER %s %s", oper_username, password);
}


decompiled_code:
__int64 __fastcall ircproto_join(const char *a1)
{
return sock_sendline("JOIN %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
return sock_sendline("JOIN %s", a1);
}

original_code:
void ircproto_join(char *chan_name)
{
 sock_sendline("JOIN %s", chan_name);
}


decompiled_code:
__int64 __fastcall ircproto_part(const char *a1)
{
return sock_sendline("PART %s", a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
return sock_sendline("PART %s", a1);
}

original_code:
void ircproto_part(char *chan_name)
{
 sock_sendline("PART %s", chan_name);
}


decompiled_code:
__int64 ircproto_privmsg(const char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return sock_sendline("PRIVMSG %s :%s", a1, s);
}

canonical_decompiled_code:
__int64 func10(const char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return sock_sendline("PRIVMSG %s :%s", a1, s);
}

original_code:
void ircproto_privmsg(char *recipient, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :%s", recipient, message);
}

canonical_original_code:
void ircproto_privmsg(char *recipient, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :%s", recipient, message);
}

variable_types:
recipient
char *

variable_types:
format
char *

variable_types:
message
char [512]


decompiled_code:
__int64 ircproto_privmsg_errno(const char *a1, const char *a2, ...)
{
int *v2; // rax
char *v3; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
v2 = _errno_location();
v3 = strerror(*v2);
return sock_sendline("PRIVMSG %s :err: %s: %s", a1, s, v3);
}

canonical_decompiled_code:
__int64 func11(const char *a1, const char *a2, ...)
{
int *v2; // rax
char *v3; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
v2 = _errno_location();
v3 = strerror(*v2);
return sock_sendline("PRIVMSG %s :err: %s: %s", a1, s, v3);
}

original_code:
void ircproto_privmsg_errno(char *recipient, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :err: %s: %s", recipient, message, strerror((*__errno_location ())));
}

canonical_original_code:
void ircproto_privmsg_errno(char *recipient, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("PRIVMSG %s :err: %s: %s", recipient, message, strerror((*__errno_location ())));
}


decompiled_code:
__int64 ircproto_notice(const char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return sock_sendline("NOTICE %s :%s", a1, s);
}

canonical_decompiled_code:
__int64 func12(const char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return sock_sendline("NOTICE %s :%s", a1, s);
}

original_code:
void ircproto_notice(char *recipient, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("NOTICE %s :%s", recipient, message);
}

canonical_original_code:
void ircproto_notice(char *recipient, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("NOTICE %s :%s", recipient, message);
}


decompiled_code:
__int64 ircproto_topic(const char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return sock_sendline("TOPIC %s :%s", a1, s);
}

canonical_decompiled_code:
__int64 func13(const char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return sock_sendline("TOPIC %s :%s", a1, s);
}

original_code:
void ircproto_topic(char *chan_name, char *format, ...)
{
 va_list args;
 char topic[512];
 __builtin_va_start(args,format);
 vsnprintf(topic, sizeof(topic), format, args);
 __builtin_va_end(args);
 sock_sendline("TOPIC %s :%s", chan_name, topic);
}

canonical_original_code:
void ircproto_topic(char *chan_name, char *format, ...)
{
 __builtin_va_list args;
 char topic[512];
 __builtin_va_start(args,format);
 vsnprintf(topic, sizeof(topic), format, args);
 __builtin_va_end(args);
 sock_sendline("TOPIC %s :%s", chan_name, topic);
}

variable_types:
topic
char [512]


decompiled_code:
__int64 ircproto_kick(const char *a1, const char *a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2E0h] BYREF
char s[512]; // [rsp+20h] [rbp-2C8h] BYREF

va_start(arg, a3);
vsnprintf(s, 0x200uLL, a3, arg);
return sock_sendline("KICK %s %s :%s", a1, a2, s);
}

canonical_decompiled_code:
__int64 func14(const char *a1, const char *a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2E0h] BYREF
char s[512]; // [rsp+20h] [rbp-2C8h] BYREF

va_start(arg, a3);
vsnprintf(s, 0x200uLL, a3, arg);
return sock_sendline("KICK %s %s :%s", a1, a2, s);
}

original_code:
void ircproto_kick(char *chan_name, char *nick, char *format, ...)
{
 va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("KICK %s %s :%s", chan_name, nick, message);
}

canonical_original_code:
void ircproto_kick(char *chan_name, char *nick, char *format, ...)
{
 __builtin_va_list args;
 char message[512];
 __builtin_va_start(args,format);
 vsnprintf(message, sizeof(message), format, args);
 __builtin_va_end(args);
 sock_sendline("KICK %s %s :%s", chan_name, nick, message);
}


decompiled_code:
__int64 __fastcall ircproto_mode(const char *a1, const char *a2)
{
return sock_sendline("MODE %s %s", a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, const char *a2)
{
return sock_sendline("MODE %s %s", a1, a2);
}

original_code:
void ircproto_mode(char *chan_name, char *modes)
{
 sock_sendline("MODE %s %s", chan_name, modes);
}

variable_types:
modes
char *


decompiled_code:
void handle_names_end()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void handle_names_end(char *prefix, int ncmd, char *params)
{
}

variable_types:
prefix
char *

variable_types: ncmd int

variable_types:
params
char *


decompiled_code:
const char *__fastcall chan_find(char *s2)
{
const char *v1; // r12

v1 = (const char *)chans;
if ( chans == &chans )
return 0LL;
while ( strcasecmp(v1 + 32, s2) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&chans )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func1(char *s2)
{
const char *v1; // r12

v1 = (const char *)chans;
if ( chans == &chans )
return 0LL;
while ( strcasecmp(v1 + 32, s2) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&chans )
return 0LL;
}
return v1;
}

original_code:
static struct chan *chan_find(char *chan_name)
{
 struct list_head *node;
 struct chan *chan;
 for (node = (&chans)->next; node != (&chans); node = node->next) {
  chan = ((struct chan *)((char *)(node)-(unsigned long)(&((struct chan *)0)->link)));
  if (!strcasecmp(chan->name, chan_name))
   return chan;
 }
 return ((void *)0);
}

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct chan { struct list_head { struct list_head *next; } link; struct list_head presences; char name[512]; } *

user_defined_types: struct chan { struct list_head link; struct list_head presences; char name[512]; }


decompiled_code:
char *__fastcall handle_names(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // rbp
char *v4; // r12
char *v5; // rax
char *v6; // rbx
const char *v7; // r12
char *result; // rax
char *v9; // rbp
int v10; // ebx
__int64 v11; // rax
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = strpbrk(a3, chantypes);
v4 = strchr(v3, 32);
v5 = strchr(v4, 58);
*v4 = 0;
v6 = v5;
v7 = chan_find(v3);
result = strtok_r(v6 + 1, " ", save_ptr);
if ( result )
{
v9 = result;
do
{
v10 = prefix2priv((unsigned int)*v9);
v11 = user_get(&v9[-(v10 == 0) + 1]);
*(_DWORD *)(presence_get(v7, v11) + 48) = v10;
result = strtok_r(0LL, " ", save_ptr);
v9 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // rbp
char *v4; // r12
char *v5; // rax
char *v6; // rbx
const char *v7; // r12
char *result; // rax
char *v9; // rbp
int v10; // ebx
__int64 v11; // rax
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = strpbrk(a3, chantypes);
v4 = strchr(v3, 32);
v5 = strchr(v4, 58);
*v4 = 0;
v6 = v5;
v7 = func1(v3);
result = strtok_r(v6 + 1, " ", save_ptr);
if ( result )
{
v9 = result;
do
{
v10 = prefix2priv((unsigned int)*v9);
v11 = user_get(&v9[-(v10 == 0) + 1]);
*(_DWORD *)(presence_get(v7, v11) + 48) = v10;
result = strtok_r(0LL, " ", save_ptr);
v9 = result;
}
while ( result );
}
return result;
}

original_code:
static void handle_names(char *prefix, int ncmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name, *space, *nicks, *nick, *save;
 enum priv priv;
 chan_name = strpbrk(params, chantypes);
 space = strchr(chan_name, ' ');
 nicks = strchr(space, ':') + 1;
 *space = '\0';
 chan = chan_find(chan_name);
 for (nick = strtok_r(nicks, " ", &save); nick;
   nick = strtok_r(((void *)0), " ", &save)) {
  priv = prefix2priv(nick[0]);
  if (priv != PRIV_NONE)
   nick++;
  user = user_get(nick);
  pres = presence_get(chan, user);
  pres->priv = priv;
 }
}

canonical_original_code:
static void handle_names(char *prefix, int ncmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name; char *space; char *nicks; char *nick; char *save;
 enum priv priv;
 chan_name = strpbrk(params, chantypes);
 space = strchr(chan_name, ' ');
 nicks = strchr(space, ':') + 1;
 *space = '\0';
 chan = chan_find(chan_name);
 for (nick = strtok_r(nicks, " ", &save); nick;
   nick = strtok_r(((void *)0), " ", &save)) {
  priv = prefix2priv(nick[0]);
  if (priv != PRIV_NONE)
   nick++;
  user = user_get(nick);
  pres = presence_get(chan, user);
  pres->priv = priv;
 }
}

variable_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *

variable_types: struct presence { struct list_head { struct list_head *next; } clink; struct chan { struct list_head link; struct list_head presences; char name[512]; } *chan; struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head presences; _Bool reg; } *user; enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 } priv; } *

variable_types:
space
char *

variable_types:
nicks
char *

variable_types:
save
char *

user_defined_types: struct presence { struct list_head clink; struct chan *chan; struct user *user; enum priv priv; }


decompiled_code:
__int64 __fastcall handle_kick(__int64 a1, __int64 a2, char *a3)
{
char *v3; // rbp
char *v4; // r12
const char *v5; // r14
__int64 v6; // rax
const char *v7; // r13
__int64 v8; // r14
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = strtok_r(a3, " ", save_ptr);
v4 = strtok_r(0LL, " ", save_ptr);
v5 = chan_find(v3);
v6 = user_find(v4);
if ( !v5 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v7 = (const char *)v6;
if ( !v6 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v8 = presence_find(v5, v6);
if ( !v8 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
info("user %s/%s kicked", v3, v7);
return presence_del(v8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, char *a3)
{
char *v3; // rbp
char *v4; // r12
const char *v5; // r14
__int64 v6; // rax
const char *v7; // r13
__int64 v8; // r14
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = strtok_r(a3, " ", save_ptr);
v4 = strtok_r(0LL, " ", save_ptr);
v5 = func1(v3);
v6 = user_find(v4);
if ( !v5 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v7 = (const char *)v6;
if ( !v6 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
v8 = presence_find(v5, v6);
if ( !v8 )
return info("user %s/%s kicked: wasn't aware of presence", v3, v4);
info("user %s/%s kicked", v3, v7);
return presence_del(v8);
}

original_code:
static void handle_kick(char *prefix, char *cmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name, *victim_prefix, *save;
 chan_name = strtok_r(params, " ", &save);
 victim_prefix = strtok_r(((void *)0), " ", &save);
 chan = chan_find(chan_name);
 user = user_find(victim_prefix);
 pres = chan && user ? presence_find(chan, user) : ((void *)0);
 if (pres) {
  info("user %s/%s kicked", chan_name, user->nick);
  presence_del(pres);
 }
 else {
  info("user %s/%s kicked: wasn't aware of presence",
   chan_name, victim_prefix);
 }
}

canonical_original_code:
static void handle_kick(char *prefix, char *cmd, char *params)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 char *chan_name; char *victim_prefix; char *save;
 chan_name = strtok_r(params, " ", &save);
 victim_prefix = strtok_r(((void *)0), " ", &save);
 chan = chan_find(chan_name);
 user = user_find(victim_prefix);
 pres = chan && user ? presence_find(chan, user) : ((void *)0);
 if (pres) {
  info("user %s/%s kicked", chan_name, user->nick);
  presence_del(pres);
 }
 else {
  info("user %s/%s kicked: wasn't aware of presence",
   chan_name, victim_prefix);
 }
}

variable_types:
cmd
char *

user_defined_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head presences; _Bool reg; }

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 }


decompiled_code:
__int64 __fastcall handle_part(const char *a1, __int64 a2, const char *a3)
{
char *v3; // rbp
const char *v4; // rax
const char *v5; // r12
const char *v6; // r13
__int64 v7; // rax

v3 = strpbrk(a3, chantypes);
v4 = chan_find(v3);
if ( !v4 )
return info("user %s/%s left: wasn't aware of presence", v3, a1);
v5 = v4;
v6 = (const char *)user_find(a1);
info("user %s/%s left", v3, v6);
v7 = presence_find(v5, v6);
return presence_del(v7);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2, const char *a3)
{
char *v3; // rbp
const char *v4; // rax
const char *v5; // r12
const char *v6; // r13
__int64 v7; // rax

v3 = strpbrk(a3, chantypes);
v4 = func1(v3);
if ( !v4 )
return info("user %s/%s left: wasn't aware of presence", v3, a1);
v5 = v4;
v6 = (const char *)user_find(a1);
info("user %s/%s left", v3, v6);
v7 = presence_find(v5, v6);
return presence_del(v7);
}

original_code:
static void handle_part(char *prefix, char *cmd, char *params)
{
 struct chan *chan;
 struct user *user;
 char *chan_name;
 chan_name = strpbrk(params, chantypes);
 chan = chan_find(chan_name);
 if (chan) {
  user = user_find(prefix);
  info("user %s/%s left", chan_name, user->nick);
  presence_del(presence_find(chan, user));
 }
 else {
  info("user %s/%s left: wasn't aware of presence",
   chan_name, prefix);
 }
}


decompiled_code:
__int64 __fastcall handle_quit(const char *a1)
{
const char *v1; // rax
const char *v2; // rbp

v1 = (const char *)user_find(a1);
if ( !v1 )
return info("user %s quit: wasn't aware of user", a1);
v2 = v1;
info("user %s quit", v1);
return user_del(v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
const char *v1; // rax
const char *v2; // rbp

v1 = (const char *)user_find(a1);
if ( !v1 )
return info("user %s quit: wasn't aware of user", a1);
v2 = v1;
info("user %s quit", v1);
return user_del(v2);
}

original_code:
static void handle_quit(char *prefix, char *cmd, char *params)
{
 struct user *user;
 user = user_find(prefix);
 if (user) {
  info("user %s quit", user->nick);
  user_del(user);
 }
 if (!user) {
  info("user %s quit: wasn't aware of user", prefix);
 }
}


decompiled_code:
__int64 __fastcall handle_join_other(char *a1, __int64 a2)
{
const char *v2; // r13
const char *v3; // r12
__int64 v4; // rax
bool v5; // zf
__int64 result; // rax
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = chan_find(a1);
v3 = (const char *)user_get(a2);
v4 = presence_get3(v2, v3, v7);
v5 = v7[0] == 0;
*(_DWORD *)(v4 + 48) = 0;
if ( !v5 || (result = info("user %s/%s joined", a1, v3), v7[0]) )
result = info("user %s/%s joined: thought already present", a1, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, __int64 a2)
{
const char *v2; // r13
const char *v3; // r12
__int64 v4; // rax
bool v5; // zf
__int64 result; // rax
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = func1(a1);
v3 = (const char *)user_get(a2);
v4 = presence_get3(v2, v3, v7);
v5 = v7[0] == 0;
*(_DWORD *)(v4 + 48) = 0;
if ( !v5 || (result = info("user %s/%s joined", a1, v3), v7[0]) )
result = info("user %s/%s joined: thought already present", a1, v3);
return result;
}

original_code:
static void handle_join_other(char *chan_name, char *prefix)
{
 struct chan *chan;
 struct user *user;
 struct presence *pres;
 _Bool existed;
 chan = chan_find(chan_name);
 user = user_get(prefix);
 pres = presence_get3(chan, user, &existed);
 pres->priv = PRIV_NONE;
 if (!existed)
  info("user %s/%s joined", chan_name, user->nick);
 if (existed)
  info("user %s/%s joined: thought already present",
   chan_name, user->nick);
}


decompiled_code:
void __fastcall handle_join(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // r12

v3 = strpbrk(a3, chantypes);
if ( (unsigned __int8)isme(a1) )
handle_join_me(v3);
else
handle_join_other(v3, a1);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2, const char *a3)
{
char *v3; // r12

v3 = strpbrk(a3, chantypes);
if ( (unsigned __int8)isme(a1) )
func10(v3);
else
func6(v3, a1);
}

original_code:
static void handle_join(char *prefix, char *cmd, char *params)
{
 char *chan_name;
 chan_name = strpbrk(params, chantypes);
 if (isme(prefix))
  handle_join_me(chan_name);
 else
  handle_join_other(chan_name, prefix);
}


decompiled_code:
char *__fastcall chan_set_prefix(char *src)
{
return strcpy(chantypes, src);
}

canonical_decompiled_code:
char *__fastcall func12(char *src)
{
return strcpy(chantypes, src);
}

original_code:
void chan_set_prefix(char *prefixes)
{
 strcpy(chantypes, prefixes);
}

variable_types:
prefixes
char *


decompiled_code:
bool __fastcall chan_is_prefix(char a1)
{
return strchr(chantypes, a1) != 0LL;
}

canonical_decompiled_code:
bool __fastcall func13(char a1)
{
return strchr(chantypes, a1) != 0LL;
}

original_code:
_Bool chan_is_prefix(char c)
{
 return strchr(chantypes, c) != ((void *)0);
}

variable_types: c char


decompiled_code:
__int64 chan_init()
{
callback_register_str(handle_join, "JOIN");
callback_register_str(handle_part, "PART");
callback_register_str(handle_quit, "QUIT");
callback_register_str(handle_kick, "KICK");
callback_register_numeric(handle_names, 353LL);
return callback_register_numeric(handle_names_end, 366LL);
}

canonical_decompiled_code:
__int64 func14()
{
callback_register_str(handle_join, "JOIN");
callback_register_str(handle_part, "PART");
callback_register_str(handle_quit, "QUIT");
callback_register_str(handle_kick, "KICK");
callback_register_numeric(handle_names, 353LL);
return callback_register_numeric(handle_names_end, 366LL);
}

original_code:
void chan_init()
{
 callback_register_str(handle_join, "JOIN");
 callback_register_str(handle_part, "PART");
 callback_register_str(handle_quit, "QUIT");
 callback_register_str(handle_kick, "KICK");
 callback_register_numeric(handle_names, 353);
 callback_register_numeric(handle_names_end, 366);
}


chomp

decompiled_code:
const char *__fastcall chomp(const char *a1)
{
const char *v1; // rax

v1 = &a1[(int)(strlen(a1) - 1)];
if ( *v1 == 10 )
*v1 = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
const char *v1; // rax

v1 = &a1[(int)(strlen(a1) - 1)];
if ( *v1 == 10 )
*v1 = 0;
return a1;
}

original_code:
char *chomp(char *str)
{
 int last = strlen(str) - 1;
 if (str[last] == '\n')
  str[last] = '\0';
 return str;
}

variable_types:
str
char *

variable_types: last int


pdlerror

decompiled_code:
__int64 pdlerror()
{
char *v0; // rax

v0 = dlerror();
if ( v0 )
err((int)"dlerror: %s", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rax

v0 = dlerror();
if ( v0 )
err((int)"dlerror: %s", v0);
return 0LL;
}

original_code:
static _Bool pdlerror()
{
 char *errmsg = dlerror();
 if (errmsg)
  err("dlerror: %s", errmsg);
 return errmsg != ((void *)0);
}

variable_types:
errmsg
char *


decompiled_code:
const char *__fastcall plg_find(char *s1)
{
const char *v1; // r12

v1 = (const char *)plgs;
if ( plgs == &plgs )
LABEL_6:
err((int)"plg_find: %s: not found", s1);
while ( strncmp(s1, v1 + 16, 0x100uLL) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&plgs )
goto LABEL_6;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func1(char *s1)
{
const char *v1; // r12

v1 = (const char *)plgs;
if ( plgs == &plgs )
LABEL_6:
err((int)"plg_find: %s: not found", s1);
while ( strncmp(s1, v1 + 16, 0x100uLL) )
{
v1 = *(const char **)v1;
if ( v1 == (const char *)&plgs )
goto LABEL_6;
}
return v1;
}

original_code:
static struct plg *plg_find(char *plg_name)
{
 struct list_head *node;
 struct plg *plg;
 for (node = (&plgs)->next; node != (&plgs); node = node->next) {
  plg = ((struct plg *)((char *)(node)-(unsigned long)(&((struct plg *)0)->link)));
  if (!strncmp(plg_name, plg->name, sizeof(plg->name)))
   return plg;
 }
 err("plg_find: %s: not found", plg_name);
 return ((void *)0);
}

variable_types: struct plg { struct list_head { struct list_head *next; } link; char name[256]; char file[256]; void *so; int (*init)(); void (*finish)(); } *

user_defined_types: struct plg { struct list_head link; char name[256]; char file[256]; void *so; int (*init)(); void (*finish)(); }


decompiled_code:
void plg_free_all()
{
void **v0; // rbp
void **v1; // rbx
void **v2; // rdi

v0 = (void **)plgs;
v1 = *(void ***)plgs;
if ( plgs != &plgs )
{
do
{
((void (*)(void))v0[68])();
dlclose(v0[66]);
pdlerror();
v2 = v0;
v0 = v1;
free(v2);
v1 = (void **)*v1;
}
while ( v0 != &plgs );
}
}

canonical_decompiled_code:
void func2()
{
void **v0; // rbp
void **v1; // rbx
void **v2; // rdi

v0 = (void **)plgs;
v1 = *(void ***)plgs;
if ( plgs != &plgs )
{
do
{
((void (*)(void))v0[68])();
dlclose(v0[66]);
func0();
v2 = v0;
v0 = v1;
free(v2);
v1 = (void **)*v1;
}
while ( v0 != &plgs );
}
}

original_code:
void plg_free_all()
{
 struct list_head *node, *next;
 struct plg *plg;
 for (node = (&plgs)->next, next = node->next; node != (&plgs); node = next, next = node->next) {
  plg = ((struct plg *)((char *)(node)-(unsigned long)(&((struct plg *)0)->link)));
  plg->finish();
  dlclose(plg->so);
  pdlerror();
  free(plg);
 }
}

canonical_original_code:
void plg_free_all()
{
 struct list_head *node; struct list_head *next;
 struct plg *plg;
 for (node = (&plgs)->next, next = node->next; node != (&plgs); node = next, next = node->next) {
  plg = ((struct plg *)((char *)(node)-(unsigned long)(&((struct plg *)0)->link)));
  plg->finish();
  dlclose(plg->so);
  pdlerror();
  free(plg);
 }
}


decompiled_code:
void __fastcall plg_load(char *src)
{
char *v1; // rbp

v1 = (char *)malloc(0x228uLL);
strncpy(v1 + 16, src, 0x100uLL);
snprintf(v1 + 272, 0x100uLL, "plg/%s/%s.so", src, src);
*((_QWORD *)v1 + 66) = dlopen(v1 + 272, 258);
if ( (unsigned __int8)pdlerror()
|| (*((_QWORD *)v1 + 67) = dlsym(*((void **)v1 + 66), "init"), (unsigned __int8)pdlerror())
|| (*((_QWORD *)v1 + 68) = dlsym(*((void **)v1 + 66), "finish"), (unsigned __int8)pdlerror()) )
{
free(v1);
}
else
{
if ( (*((unsigned int (**)(void))v1 + 67))() )
err((int)"plg->init(): failed: %s", src);
list_add_constprop_0(v1);
}
}

canonical_decompiled_code:
void __fastcall func5(char *src)
{
char *v1; // rbp

v1 = (char *)malloc(0x228uLL);
strncpy(v1 + 16, src, 0x100uLL);
snprintf(v1 + 272, 0x100uLL, "plg/%s/%s.so", src, src);
*((_QWORD *)v1 + 66) = dlopen(v1 + 272, 258);
if ( (unsigned __int8)func0()
|| (*((_QWORD *)v1 + 67) = dlsym(*((void **)v1 + 66), "init"), (unsigned __int8)func0())
|| (*((_QWORD *)v1 + 68) = dlsym(*((void **)v1 + 66), "finish"), (unsigned __int8)func0()) )
{
free(v1);
}
else
{
if ( (*((unsigned int (**)(void))v1 + 67))() )
err((int)"plg->init(): failed: %s", src);
func4(v1);
}
}

original_code:
void plg_load(char *plg_name)
{
 struct plg *plg = malloc(sizeof(struct plg));
 strncpy(plg->name, plg_name, sizeof(plg->name));
 snprintf(plg->file, sizeof(plg->file), "plg/%s/%s.so",
  plg_name, plg_name);
 plg->so = dlopen(plg->file, 0x00002 | 0x00100);
 if (pdlerror())
  goto err;
 plg->init = dlsym(plg->so, "init");
 if (pdlerror())
  goto err;
 plg->finish = dlsym(plg->so, "finish");
 if (pdlerror())
  goto err;
 if (plg->init()) {
  err("plg->init(): failed: %s", plg_name);
  goto err;
 }
 list_add(&plg->link, &plgs);
 return;
err:
 free(plg);
}


decompiled_code:
void *__fastcall plg_sym(char *a1, const char *a2)
{
const char *v2; // rax
void *v3; // r12

v2 = plg_find(a1);
v3 = (void *)v2;
if ( v2 )
{
v3 = dlsym(*((void **)v2 + 66), a2);
pdlerror();
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func7(char *a1, const char *a2)
{
const char *v2; // rax
void *v3; // r12

v2 = func1(a1);
v3 = (void *)v2;
if ( v2 )
{
v3 = dlsym(*((void **)v2 + 66), a2);
func0();
}
return v3;
}

original_code:
void *plg_sym(char *plg_name, char *symbol)
{
 struct plg *plg;
 void *addr;
 plg = plg_find(plg_name);
 if (plg) {
  addr = dlsym(plg->so, symbol);
  pdlerror();
  return addr;
 }
 else {
  return ((void *)0);
 }
}

variable_types:
symbol
char *

variable_types:
addr
void *


decompiled_code:
__int64 free_str_events()
{
return hashtab_destroy(str_events);
}

canonical_decompiled_code:
__int64 func0()
{
return hashtab_destroy(str_events);
}

original_code:
static void free_str_events()
{
 hashtab_destroy(str_events);
}


decompiled_code:
__int64 __fastcall callback_register_numeric(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (int)a2 > 549 )
_assert_fail("ncmd < MAX_NUMERIC", "callback.c", 0x2Eu, "callback_register_numeric");
if ( num_events[(int)a2] )
result = info("callback_register_numeric: %d: overwriting event", a2);
num_events[(int)a2] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (int)a2 > 549 )
_assert_fail("ncmd < MAX_NUMERIC", "callback.c", 0x2Eu, "callback_register_numeric");
if ( num_events[(int)a2] )
result = info("callback_register_numeric: %d: overwriting event", a2);
num_events[(int)a2] = a1;
return result;
}

original_code:
void callback_register_numeric(callback_numeric call, int ncmd)
{
 ((void) sizeof ((ncmd < 550) ? 1 : 0), __extension__ ({ if (ncmd < 550) ; else __assert_fail ("ncmd < MAX_NUMERIC", "callback.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 if (num_events[ncmd])
  info("callback_register_numeric: %d: overwriting event", ncmd);
 num_events[ncmd] = call;
}

canonical_original_code:
void callback_register_numeric(void (*call)(char *prefix, int ncmd, char *params), int ncmd)
{
 ((void) sizeof ((ncmd < 550) ? 1 : 0), __extension__ ({ if (ncmd < 550) ; else __assert_fail ("ncmd < MAX_NUMERIC", "callback.c", 46, __extension__ __PRETTY_FUNCTION__); }));
 if (num_events[ncmd])
  info("callback_register_numeric: %d: overwriting event", ncmd);
 num_events[ncmd] = call;
}

variable_types: void (*)(char *prefix, int ncmd, char *params)

variable_types: ncmd int


decompiled_code:
__int64 __fastcall callback_register_str(__int64 a1, const char *a2)
{
__int64 result; // rax

result = hashtab_insert(str_events, a2, a1);
if ( (_DWORD)result == -1 )
err((int)"callback_register_str: %s: event already exists", a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 result; // rax

result = hashtab_insert(str_events, a2, a1);
if ( (_DWORD)result == -1 )
err((int)"callback_register_str: %s: event already exists", a2);
return result;
}

original_code:
void callback_register_str(callback_str call, char *cmd)
{
 if (hashtab_insert(str_events, cmd, call) == -1)
  err("callback_register_str: %s: event already exists", cmd);
}

canonical_original_code:
void callback_register_str(void (*call)(char *prefix, char *cmd, char *params), char *cmd)
{
 if (hashtab_insert(str_events, cmd, call) == -1)
  err("callback_register_str: %s: event already exists", cmd);
}

variable_types: void (*)(char *prefix, char *cmd, char *params)


decompiled_code:
__int64 callback_init()
{
memset(num_events, 0, sizeof(num_events));
str_events = hashtab_create(&str_hash, &strcmp_hash, 31LL);
return add_shutdown_fn(free_str_events);
}

canonical_decompiled_code:
__int64 func3()
{
memset(num_events, 0, sizeof(num_events));
str_events = hashtab_create(&str_hash, &strcmp_hash, 31LL);
return add_shutdown_fn(free_str_events);
}

original_code:
void callback_init()
{
 memset(num_events, 0, sizeof(num_events));
 str_events = hashtab_create(str_hash, strcmp_hash, 31);
 add_shutdown_fn(free_str_events);
}


isme

decompiled_code:
bool __fastcall isme(char *s1)
{
char *v1; // rax
const char *v2; // r12
size_t v3; // rbx
int v4; // er8
bool result; // al

v1 = strchr(s1, 33);
v2 = bot_nick;
if ( !v1 )
return strcasecmp(s1, bot_nick) == 0;
v3 = (int)v1 - (int)s1;
v4 = strncasecmp(s1, bot_nick, v3);
result = 0;
if ( !v4 )
result = v3 == strlen(v2);
return result;
}

canonical_decompiled_code:
bool __fastcall func1(char *s1)
{
char *v1; // rax
const char *v2; // r12
size_t v3; // rbx
int v4; // er8
bool result; // al

v1 = strchr(s1, 33);
v2 = bot_nick;
if ( !v1 )
return strcasecmp(s1, bot_nick) == 0;
v3 = (int)v1 - (int)s1;
v4 = strncasecmp(s1, bot_nick, v3);
result = 0;
if ( !v4 )
result = v3 == strlen(v2);
return result;
}

original_code:
_Bool isme(char *prefix)
{
 char *bang;
 int len;
 bang = strchr(prefix, '!');
 if (bang) {
  len = bang - prefix;
  return !strncasecmp(prefix, bot_nick, len) &&
   strlen(bot_nick) == len;
 }
 else {
  return !strcasecmp(prefix, bot_nick);
 }
}

variable_types:
prefix
char *

variable_types:
bang
char *

variable_types: len int


decompiled_code:
void __fastcall user_del(void *ptr)
{
hashtab_remove(users, ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
hashtab_remove(users, ptr);
free(ptr);
}

original_code:
void user_del(struct user *user)
{
 hashtab_remove(users, user->nick);
 free(user);
}

variable_types: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *


decompiled_code:
__int64 __fastcall user_find(__int64 a1)
{
char v2[520]; // [rsp+8h] [rbp-208h] BYREF

ircproto_parse_prefix(a1, v2, "user_new: %s: user already exists", 0LL);
return hashtab_search(users, v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
char v2[520]; // [rsp+8h] [rbp-208h] BYREF

ircproto_parse_prefix(a1, v2, "user_new: %s: user already exists", 0LL);
return hashtab_search(users, v2);
}

original_code:
struct user *user_find(char *prefix)
{
 struct user *user;
 char nick[512];
 ircproto_parse_prefix(prefix, nick, sizeof(nick), ((void *)0), 0, ((void *)0), 0);
 user = hashtab_search(users, nick);
 return user;
}

variable_types:
nick
char [512]

return_type: struct user { char nick[512]; char host[512]; char uname[512]; char rname[512]; struct list_head { struct list_head *next; } presences; _Bool reg; } *


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

result = user_find(a1);
if ( !result )
result = (__int64)user_new(a1);
return result;
}

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

result = func3(a1);
if ( !result )
result = (__int64)func0(a1);
return result;
}

original_code:
struct user *user_get(char *prefix)
{
 struct user *user;
 user = user_find(prefix);
 return user ? user : user_new(prefix);
}


decompiled_code:
__int64 __fastcall user_get2(__int64 a1, bool *a2)
{
__int64 result; // rax

result = user_find(a1);
*a2 = result != 0;
if ( !result )
result = (__int64)user_new(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, bool *a2)
{
__int64 result; // rax

result = func3(a1);
*a2 = result != 0;
if ( !result )
result = (__int64)func0(a1);
return result;
}

original_code:
struct user *user_get2(char *prefix, _Bool *existed)
{
 struct user *user;
 user = user_find(prefix);
 *existed = user != ((void *)0);
 return user ? user : user_new(prefix);
}

variable_types:
existed
_Bool *


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

result = hashtab_create(&str_hash, &strcmp_hash, 101LL);
users = result;
return result;
}

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

result = hashtab_create(&str_hash, &strcmp_hash, 101LL);
users = result;
return result;
}

original_code:
void usr_init()
{
 users = hashtab_create(str_hash, strcmp_hash, 101);
}


decompiled_code:
__int64 __fastcall regex_compile(const char **a1)
{
__int64 result; // rax
const char *v2; // rcx
__int64 v3; // rdx
unsigned int v4; // [rsp+4h] [rbp-14h] BYREF
const char *v5; // [rsp+8h] [rbp-10h] BYREF

result = pcre_compile(*a1, 0LL, &v5, &v4, 0LL);
a1[2] = (const char *)result;
if ( result )
{
*((_DWORD *)a1 + 2) = 2;
}
else
{
v2 = v5;
v3 = v4;
*((_DWORD *)a1 + 2) = 1;
result = info("regex '%s':%d: %s", *a1, v3, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
__int64 result; // rax
const char *v2; // rcx
__int64 v3; // rdx
unsigned int v4; // [rsp+4h] [rbp-14h] BYREF
const char *v5; // [rsp+8h] [rbp-10h] BYREF

result = pcre_compile(*a1, 0LL, &v5, &v4, 0LL);
a1[2] = (const char *)result;
if ( result )
{
*((_DWORD *)a1 + 2) = 2;
}
else
{
v2 = v5;
v3 = v4;
*((_DWORD *)a1 + 2) = 1;
result = info("regex '%s':%d: %s", *a1, v3, v2);
}
return result;
}

original_code:
static void regex_compile(struct regex *re)
{
 const char* err;
 int erroff;
 re->re_detail = pcre_compile(re->pattern, 0, &err, &erroff, ((void *)0));
 if (re->re_detail) {
  re->state = RCS_COMPILED;
 }
 else {
  re->state = RCS_ERROR;
  info("regex '%s':%d: %s", re->pattern, erroff, err);
 }
}

canonical_original_code:
static void regex_compile(struct regex *re)
{
 char *err;
 int erroff;
 re->re_detail = pcre_compile(re->pattern, 0, &err, &erroff, ((void *)0));
 if (re->re_detail) {
  re->state = RCS_COMPILED;
 }
 else {
  re->state = RCS_ERROR;
  info("regex '%s':%d: %s", re->pattern, erroff, err);
 }
}

variable_types: struct regex { char *pattern; enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 } state; void *re_detail; } *

variable_types:
err
char *

variable_types: erroff int

user_defined_types: struct regex { char *pattern; enum regex_compiled_state state; void *re_detail; }


decompiled_code:
__int64 __fastcall regex_match_exec(__int64 a1, const char *a2, __int64 a3)
{
size_t v5; // rax
int v6; // eax
__int64 v7; // r13
__int64 v8; // rsi
int v9; // ebx
__int64 v10; // rax
unsigned int v12; // [rsp+Ch] [rbp-CCh]
_QWORD v13[25]; // [rsp+10h] [rbp-C8h] BYREF

v5 = strlen(a2);
v6 = pcre_exec(*(_QWORD *)(a1 + 16), 0LL, a2, v5, 0LL, 0LL, v13, 33LL);
v12 = v6;
if ( v6 < -1 )
{
info("pcre_exec failed: code=%d, re=%s, str=%s", (unsigned int)v6, *(const char **)a1, a2);
}
else if ( a3 && v6 > 1 )
{
v7 = 0LL;
do
{
v8 = SLODWORD(v13[v7 + 1]);
v9 = HIDWORD(v13[v7 + 1]) - v8;
*((_BYTE *)memcpy(*(void **)(a3 + 8 * v7), &a2[v8], v9) + v9) = 0;
v10 = v7++;
}
while ( v12 - 2 != v10 );
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, __int64 a3)
{
size_t v5; // rax
int v6; // eax
__int64 v7; // r13
__int64 v8; // rsi
int v9; // ebx
__int64 v10; // rax
unsigned int v12; // [rsp+Ch] [rbp-CCh]
_QWORD v13[25]; // [rsp+10h] [rbp-C8h] BYREF

v5 = strlen(a2);
v6 = pcre_exec(*(_QWORD *)(a1 + 16), 0LL, a2, v5, 0LL, 0LL, v13, 33LL);
v12 = v6;
if ( v6 < -1 )
{
info("pcre_exec failed: code=%d, re=%s, str=%s", (unsigned int)v6, *(const char **)a1, a2);
}
else if ( a3 && v6 > 1 )
{
v7 = 0LL;
do
{
v8 = SLODWORD(v13[v7 + 1]);
v9 = HIDWORD(v13[v7 + 1]) - v8;
*((_BYTE *)memcpy(*(void **)(a3 + 8 * v7), &a2[v8], v9) + v9) = 0;
v10 = v7++;
}
while ( v12 - 2 != v10 );
}
return v12;
}

original_code:
static int regex_match_exec(struct regex *re, char *str, char **caps)
{
 int vec[(3*(10 +1))];
 int matches, beg, end, len, i;
 char* cap;
 matches = pcre_exec(re->re_detail, ((void *)0), str, strlen(str),
  0, 0, vec, (3*(10 +1)));
 if (matches < (-1)) {
  info("pcre_exec failed: code=%d, re=%s, str=%s",
   matches, re->pattern, str);
 }
 if (caps) {
  for (i = 0; i < matches - 1; i++) {
   cap = caps[i];
   beg = vec[2*i + 2];
   end = vec[2*i + 3];
   len = end - beg;
   memcpy(cap, &str[beg], len);
   cap[len] = '\0';
  }
 }
 return matches;
}

canonical_original_code:
static int regex_match_exec(struct regex *re, char *str, char **caps)
{
 int vec[-1];
 int matches; int beg; int end; int len; int i;
 char *cap;
 matches = pcre_exec(re->re_detail, ((void *)0), str, strlen(str),
  0, 0, vec, (3*(10 +1)));
 if (matches < (-1)) {
  info("pcre_exec failed: code=%d, re=%s, str=%s",
   matches, re->pattern, str);
 }
 if (caps) {
  for (i = 0; i < matches - 1; i++) {
   cap = caps[i];
   beg = vec[2*i + 2];
   end = vec[2*i + 3];
   len = end - beg;
   memcpy(cap, &str[beg], len);
   cap[len] = '\0';
  }
 }
 return matches;
}

variable_types:
str
char *

variable_types:
caps
char **

variable_types:
vec
int [-1]

variable_types: matches int

variable_types: beg int

variable_types: end int

variable_types: i int

variable_types:
cap
char *

return_type: int

user_defined_types: enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 }


decompiled_code:
__int64 __fastcall regex_match(__int64 a1, const char *a2, __int64 a3)
{
int v4; // eax
__int64 result; // rax

while ( 1 )
{
v4 = *(_DWORD *)(a1 + 8);
if ( v4 )
break;
regex_compile((const char **)a1);
}
if ( v4 == 2 )
result = regex_match_exec(a1, a2, a3);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 a3)
{
int v4; // eax
__int64 result; // rax

while ( 1 )
{
v4 = *(_DWORD *)(a1 + 8);
if ( v4 )
break;
func0((const char **)a1);
}
if ( v4 == 2 )
result = func1(a1, a2, a3);
else
result = 0LL;
return result;
}

original_code:
int regex_match(struct regex *re, char *str, char **caps)
{
 switch (re->state) {
 case RCS_UNINIT:
  regex_compile(re);
  return regex_match(re, str, caps);
 case RCS_COMPILED:
  return regex_match_exec(re, str, caps);
 case RCS_ERROR:
  return 0;
 }
 return 0;
}


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

if ( *(_DWORD *)(a1 + 8) == 2 )
result = pcre_free(*(_QWORD *)(a1 + 16));
return result;
}

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

if ( *(_DWORD *)(a1 + 8) == 2 )
result = pcre_free(*(_QWORD *)(a1 + 16));
return result;
}

original_code:
void regex_free(struct regex *re)
{
 if (re->state == RCS_COMPILED)
  pcre_free(re->re_detail);
}


decompiled_code:
__int64 __fastcall mode2priv(char a1)
{
return (unsigned int)modetab[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (unsigned int)modetab[a1];
}

original_code:
enum priv mode2priv(char mode)
{
 return modetab[mode];
}

variable_types: mode char

return_type: enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 }


decompiled_code:
__int64 __fastcall prefix2priv(char a1)
{
return (unsigned int)prefixtab[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return (unsigned int)prefixtab[a1];
}

original_code:
enum priv prefix2priv(char prefix)
{
 return prefixtab[prefix];
}

variable_types: prefix char


decompiled_code:
__int64 __fastcall auth_isowner(char *s)
{
char *v1; // rax
int v2; // eax
__int64 v3; // rbx
const char *v4; // rbp
size_t v5; // r12

v1 = strchr(s, 33);
if ( v1 )
v2 = (_DWORD)v1 - (_DWORD)s;
else
v2 = strlen(s);
v3 = bot_owners;
v4 = (const char *)*bot_owners;
if ( !*bot_owners )
return 0LL;
v5 = v2;
while ( strncasecmp(s, v4, v5) || strlen(v4) != v5 )
{
v4 = *(const char **)(v3 + 8);
v3 += 8LL;
if ( !v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
char *v1; // rax
int v2; // eax
__int64 v3; // rbx
const char *v4; // rbp
size_t v5; // r12

v1 = strchr(s, 33);
if ( v1 )
v2 = (_DWORD)v1 - (_DWORD)s;
else
v2 = strlen(s);
v3 = bot_owners;
v4 = (const char *)*bot_owners;
if ( !*bot_owners )
return 0LL;
v5 = v2;
while ( strncasecmp(s, v4, v5) || strlen(v4) != v5 )
{
v4 = *(const char **)(v3 + 8);
v3 += 8LL;
if ( !v4 )
return 0LL;
}
return 1LL;
}

original_code:
_Bool auth_isowner(char *usr)
{
 int i;
 int len;
 char *bang, *owner, **owners;
 bang = strchr(usr, '!');
 len = bang ? bang - usr : strlen(usr);
 for (owners = bot_owners; *owners; owners++) {
  owner = *owners;
  if (!strncasecmp(usr, owner, len) && strlen(owner) == len)
   return 1;
 }
 return 0;
}

canonical_original_code:
_Bool auth_isowner(char *usr)
{
 int i;
 int len;
 char *bang; char *owner; char **owners;
 bang = strchr(usr, '!');
 len = bang ? bang - usr : strlen(usr);
 for (owners = bot_owners; *owners; owners++) {
  owner = *owners;
  if (!strncasecmp(usr, owner, len) && strlen(owner) == len)
   return 1;
 }
 return 0;
}

variable_types:
usr
char *

variable_types: len int

variable_types:
bang
char *

variable_types:
owner
char *

variable_types:
owners
char **


decompiled_code:
__int64 __fastcall auth_set_prefix(_BYTE *a1, char *a2)
{
__int64 result; // rax
_BYTE *v3; // r8
__int64 v4; // rdx

result = 0LL;
v3 = a1;
memset(modetab, 0, sizeof(modetab));
memset(prefixtab, 0, sizeof(prefixtab));
if ( *a1 )
{
LODWORD(result) = 20;
do
{
v4 = *a2;
result = (unsigned int)(result - 1);
if ( (_BYTE)v4 == 64 )
result = 10LL;
++v3;
++a2;
prefixtab[v4] = result;
modetab[(char)*(v3 - 1)] = result;
}
while ( *v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, char *a2)
{
__int64 result; // rax
_BYTE *v3; // r8
__int64 v4; // rdx

result = 0LL;
v3 = a1;
memset(modetab, 0, sizeof(modetab));
memset(prefixtab, 0, sizeof(prefixtab));
if ( *a1 )
{
LODWORD(result) = 20;
do
{
v4 = *a2;
result = (unsigned int)(result - 1);
if ( (_BYTE)v4 == 64 )
result = 10LL;
++v3;
++a2;
prefixtab[v4] = result;
modetab[(char)*(v3 - 1)] = result;
}
while ( *v3 );
}
return result;
}

original_code:
void auth_set_prefix(char *modes, char *prefixes)
{
 char *mode, *prefix;
 enum priv priv;
 memset(modetab, 0, sizeof(modetab));
 memset(prefixtab, 0, sizeof(modetab));
 priv = PRIV_HIGHEST;
 for (mode = modes, prefix = prefixes; *mode; mode++, prefix++) {
  if (*prefix == '@')
   priv = PRIV_OPERATOR;
  else
   priv--;
  modetab[*mode] = prefixtab[*prefix] = priv;
 }
}

canonical_original_code:
void auth_set_prefix(char *modes, char *prefixes)
{
 char *mode; char *prefix;
 enum priv priv;
 memset(modetab, 0, sizeof(modetab));
 memset(prefixtab, 0, sizeof(modetab));
 priv = PRIV_HIGHEST;
 for (mode = modes, prefix = prefixes; *mode; mode++, prefix++) {
  if (*prefix == '@')
   priv = PRIV_OPERATOR;
  else
   priv--;
  modetab[*mode] = prefixtab[*prefix] = priv;
 }
}

variable_types:
modes
char *

variable_types:
prefixes
char *

variable_types:
mode
char *

variable_types:
prefix
char *

variable_types: enum priv { PRIV_NONE=0, PRIV_OPERATOR=10, PRIV_HIGHEST=20 }


decompiled_code:
__int64 auth_init()
{
return auth_set_prefix(byte_943, "@+");
}

original_code:
void auth_init()
{
 auth_set_prefix("ov", "@+");
}


decompiled_code:
int close_connection()
{
int v0; // edi
int result; // eax

v0 = sock;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x79u, "close_connection");
if ( ssl )
{
if ( (unsigned int)SSL_shutdown(ssl) == -1 )
ERR_print_errors_fp(stderr);
SSL_free(ssl);
v0 = sock;
}
result = close(v0);
if ( result == -1 )
result = err_errno("close");
sock = -1;
return result;
}

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

v0 = sock;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x79u, "close_connection");
if ( ssl )
{
if ( (unsigned int)SSL_shutdown(ssl) == -1 )
ERR_print_errors_fp(stderr);
SSL_free(ssl);
v0 = sock;
}
result = close(v0);
if ( result == -1 )
result = err_errno("close");
sock = -1;
return result;
}

original_code:
void close_connection()
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 121, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl != ((void *)0)) {
  if (SSL_shutdown(ssl) == -1)
   ERR_print_errors_fp(stderr);
  SSL_free(ssl);
 }
 if (close(sock) == -1)
  err_errno("close");
 sock = -1;
}


decompiled_code:
ssize_t __fastcall sock_send(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x88u, "sock_send");
if ( ssl )
{
result = SSL_write(ssl, buf, n);
if ( (int)result <= 0 )
{
ERR_print_errors_fp(stderr);
result = safe_shutdown_and_die(1LL);
}
}
else
{
result = send(sock, buf, n, 0);
if ( result == -1 )
{
err_errno("send");
result = safe_shutdown_and_die(1LL);
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x88u, "sock_send");
if ( ssl )
{
result = SSL_write(ssl, buf, n);
if ( (int)result <= 0 )
{
ERR_print_errors_fp(stderr);
result = safe_shutdown_and_die(1LL);
}
}
else
{
result = send(sock, buf, n, 0);
if ( result == -1 )
{
err_errno("send");
result = safe_shutdown_and_die(1LL);
}
}
return result;
}

original_code:
void sock_send(const void *buffer, size_t length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 136, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0)) {
  if (send(sock, buffer, length, 0) == -1) {
   err_errno("send");
   safe_shutdown_and_die(1);
  }
 }
 else {
  if (SSL_write(ssl, buffer, length) <= 0) {
   ERR_print_errors_fp(stderr);
   safe_shutdown_and_die(1);
  }
 }
}

canonical_original_code:
void sock_send(void *buffer, unsigned long length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 136, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0)) {
  if (send(sock, buffer, length, 0) == -1) {
   err_errno("send");
   safe_shutdown_and_die(1);
  }
 }
 else {
  if (SSL_write(ssl, buffer, length) <= 0) {
   ERR_print_errors_fp(stderr);
   safe_shutdown_and_die(1);
  }
 }
}

variable_types:
buffer
void *

variable_types:
length
unsigned long


decompiled_code:
ssize_t __fastcall sock_recv(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x9Au, "sock_recv");
if ( ssl )
result = (int)SSL_read(ssl, buf, n);
else
result = recv(sock, buf, n, 0);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf, size_t n)
{
ssize_t result; // rax

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0x9Au, "sock_recv");
if ( ssl )
result = (int)SSL_read(ssl, buf, n);
else
result = recv(sock, buf, n, 0);
return result;
}

original_code:
ssize_t sock_recv(void *buffer, size_t length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 154, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0))
  return recv(sock, buffer, length, 0);
 else
  return SSL_read(ssl, buffer, length);
}

canonical_original_code:
long sock_recv(void *buffer, unsigned long length)
{
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 154, __extension__ __PRETTY_FUNCTION__); }));
 if (ssl == ((void *)0))
  return recv(sock, buffer, length, 0);
 else
  return SSL_read(ssl, buffer, length);
}

return_type: long


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

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xC2u, "sock_drainline");
do
{
while ( 1 )
{
result = sock_recv(buf, 1uLL);
if ( (_DWORD)result == -1 )
{
err_errno("recv");
result = safe_shutdown_and_die(1LL);
goto LABEL_3;
}
if ( !(_DWORD)result )
break;
LABEL_3:
if ( buf[0] == 10 )
return result;
}
info("server closed the socket, quitting");
result = safe_shutdown_and_die(0LL);
}
while ( buf[0] != 10 );
return result;
}

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

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xC2u, "sock_drainline");
do
{
while ( 1 )
{
result = func3(buf, 1uLL);
if ( (_DWORD)result == -1 )
{
err_errno("recv");
result = safe_shutdown_and_die(1LL);
goto LABEL_3;
}
if ( !(_DWORD)result )
break;
LABEL_3:
if ( buf[0] == 10 )
return result;
}
info("server closed the socket, quitting");
result = safe_shutdown_and_die(0LL);
}
while ( buf[0] != 10 );
return result;
}

original_code:
static void sock_drainline()
{
 int ret;
 char c = 0;
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 194, __extension__ __PRETTY_FUNCTION__); }));
 while (c != '\n') {
  ret = sock_recv(&c, 1);
  if (ret == -1) {
   err_errno("recv");
   safe_shutdown_and_die(1);
  }
  else if (ret == 0) {
   info("server closed the socket, quitting");
   safe_shutdown_and_die(0);
  }
 }
}

variable_types: ret int

variable_types: c char


decompiled_code:
ssize_t sock_sendline(char *format, ...)
{
size_t v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xA7u, "sock_sendline");
fwrite("> ", 1uLL, 2uLL, socklog);
va_start(arg, format);
vfprintf(socklog, format, arg);
putc(10, socklog);
fflush(socklog);
va_end(arg);
va_start(arg, format);
vsprintf(s, format, arg);
v1 = strlen(s);
sock_send(s, v1);
return sock_send("\n", 1uLL);
}

canonical_decompiled_code:
ssize_t func5(char *format, ...)
{
size_t v1; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xA7u, "sock_sendline");
fwrite("> ", 1uLL, 2uLL, socklog);
va_start(arg, format);
vfprintf(socklog, format, arg);
putc(10, socklog);
fflush(socklog);
va_end(arg);
va_start(arg, format);
vsprintf(s, format, arg);
v1 = strlen(s);
func2(s, v1);
return func2("\n", 1uLL);
}

original_code:
void sock_sendline(char *format, ...)
{
 va_list args;
 char buffer[512];
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 fprintf(socklog, "> ");
 __builtin_va_start(args,format);
 vfprintf(socklog, format, args);
 __builtin_va_end(args);
 putc('\n', socklog);
 fflush(socklog);
 __builtin_va_start(args,format);
 vsprintf(buffer, format, args);
 __builtin_va_end(args);
 sock_send(buffer, strlen(buffer));
 sock_send("\n", 1);
}

canonical_original_code:
void sock_sendline(char *format, ...)
{
 __builtin_va_list args;
 char buffer[512];
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 fprintf(socklog, "> ");
 __builtin_va_start(args,format);
 vfprintf(socklog, format, args);
 __builtin_va_end(args);
 putc('\n', socklog);
 fflush(socklog);
 __builtin_va_start(args,format);
 vsprintf(buffer, format, args);
 __builtin_va_end(args);
 sock_send(buffer, strlen(buffer));
 sock_send("\n", 1);
}

variable_types:
format
char *

variable_types:
buffer
char [512]


decompiled_code:
char *sock_readline()
{
char v0; // al
int v1; // ebx
__int64 v2; // rdx
int v3; // eax
FILE *v4; // rdi
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xD7u, "sock_readline");
v0 = 0;
v1 = 0;
while ( v0 != 10 )
{
v3 = sock_recv(buf, 1uLL);
if ( v3 == -1 )
{
err_errno("recv");
safe_shutdown_and_die(1LL);
}
else
{
if ( !v3 )
{
info("server closed the socket, quitting");
safe_shutdown_and_die(0LL);
goto LABEL_6;
}
if ( buf[0] != 13 )
{
v2 = v1++;
line_1[v2] = buf[0];
}
}
if ( v1 == 512 )
err((int)"server sent line >%d chars, forbidden by RFC, ignoring excess", (const char *)&loc_1FF + 1);
LABEL_6:
v0 = buf[0];
}
v4 = socklog;
line_1[v1 - 1] = 0;
fprintf(v4, "< %s\n", line_1);
fflush(socklog);
return line_1;
}

canonical_decompiled_code:
char *func6()
{
char v0; // al
int v1; // ebx
__int64 v2; // rdx
int v3; // eax
FILE *v4; // rdi
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = 0;
if ( sock == -1 )
_assert_fail("sock != -1", "socket.c", 0xD7u, "sock_readline");
v0 = 0;
v1 = 0;
while ( v0 != 10 )
{
v3 = func3(buf, 1uLL);
if ( v3 == -1 )
{
err_errno("recv");
safe_shutdown_and_die(1LL);
}
else
{
if ( !v3 )
{
info("server closed the socket, quitting");
safe_shutdown_and_die(0LL);
goto LABEL_6;
}
if ( buf[0] != 13 )
{
v2 = v1++;
line_1[v2] = buf[0];
}
}
if ( v1 == 512 )
err((int)"server sent line >%d chars, forbidden by RFC, ignoring excess", (const char *)&loc_1FF + 1);
LABEL_6:
v0 = buf[0];
}
v4 = socklog;
line_1[v1 - 1] = 0;
fprintf(v4, "< %s\n", line_1);
fflush(socklog);
return line_1;
}

original_code:
char *sock_readline()
{
 static char line[512];
 int ret, i = 0;
 char c = 0;
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 215, __extension__ __PRETTY_FUNCTION__); }));
 while (c != '\n') {
  ret = sock_recv(&c, 1);
  if (ret == -1) {
   err_errno("recv");
   safe_shutdown_and_die(1);
  }
  else if (ret == 0) {
   info("server closed the socket, quitting");
   safe_shutdown_and_die(0);
  }
  else if (c == '\r')
   ;
  else
   line[i++] = c;
  if (i == 512) {
   err("server sent line >%d chars, forbidden by RFC, "
    "ignoring excess", 512);
   sock_drainline();
  }
 }
 line[i-1] = '\0';
 fprintf(socklog, "< %s\n", line);
 fflush(socklog);
 return line;
}

canonical_original_code:
char *sock_readline()
{
 static char line[512];
 int ret; int i = 0;
 char c = 0;
 ((void) sizeof ((sock != -1) ? 1 : 0), __extension__ ({ if (sock != -1) ; else __assert_fail ("sock != -1", "socket.c", 215, __extension__ __PRETTY_FUNCTION__); }));
 while (c != '\n') {
  ret = sock_recv(&c, 1);
  if (ret == -1) {
   err_errno("recv");
   safe_shutdown_and_die(1);
  }
  else if (ret == 0) {
   info("server closed the socket, quitting");
   safe_shutdown_and_die(0);
  }
  else if (c == '\r')
   ;
  else
   line[i++] = c;
  if (i == 512) {
   err("server sent line >%d chars, forbidden by RFC, "
    "ignoring excess", 512);
   sock_drainline();
  }
 }
 line[i-1] = '\0';
 fprintf(socklog, "< %s\n", line);
 fflush(socklog);
 return line;
}

variable_types:
line
char [512]

variable_types: i int


decompiled_code:
struct _IO_FILE *sock_init()
{
struct _IO_FILE *result; // rax

result = stdout;
socklog = stdout;
return result;
}

canonical_decompiled_code:
struct _IO_FILE *func7()
{
struct _IO_FILE *result; // rax

result = stdout;
socklog = stdout;
return result;
}

original_code:
void sock_init()
{
 socklog = stdout;
}

canonical_original_code:
void sock_init()
{
 socklog = stdout;
}


decompiled_code:
void __fastcall ctcp_emit(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
_QWORD *v5; // rdx
void **v6; // rbx
int v7; // eax

if ( need_init_3 )
{
need_init_3 = 0;
v4 = (char *)&caps_buf_2;
v5 = &caps_1;
do
{
*v5 = v4;
v4 += 512;
++v5;
}
while ( v4 != (char *)&caps_buf_2 + 5120 );
}
v6 = (void **)events;
if ( events != &events )
{
do
{
v7 = regex_match() - 1;
if ( v7 >= 0 )
((void (__fastcall *)(__int64, __int64, __int64, void *, _QWORD))v6[2])(a1, a2, a3, &caps_1, (unsigned int)v7);
v6 = (void **)*v6;
}
while ( v6 != &events );
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
_QWORD *v5; // rdx
void **v6; // rbx
int v7; // eax

if ( need_init_3 )
{
need_init_3 = 0;
v4 = (char *)&caps_buf_2;
v5 = &caps_1;
do
{
*v5 = v4;
v4 += 512;
++v5;
}
while ( v4 != (char *)&caps_buf_2 + 5120 );
}
v6 = (void **)events;
if ( events != &events )
{
do
{
v7 = regex_match() - 1;
if ( v7 >= 0 )
((void (__fastcall *)(__int64, __int64, __int64, void *, _QWORD))v6[2])(a1, a2, a3, &caps_1, (unsigned int)v7);
v6 = (void **)*v6;
}
while ( v6 != &events );
}
}

original_code:
void ctcp_emit(char *usr, char *src, char *msg)
{
 ctcp_callback call;
 struct list_head *node;
 struct re_event *rev;
 int matches, ncap, i;
 static char *caps[10];
 static char caps_buf[512 * 10];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 for (node = (&events)->next; node != (&events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, msg, caps);
  ncap = matches - 1;
  if (ncap >= 0)
   rev->call(usr, src, msg, caps, ncap);
 }
}

canonical_original_code:
void ctcp_emit(char *usr, char *src, char *msg)
{
 void (*call)(char *usr, char *src, char *msg, char **caps, int ncap);
 struct list_head *node;
 struct re_event *rev;
 int matches; int ncap; int i;
 static char *caps[10];
 static char caps_buf[-1];
 static _Bool need_init = 1;
 if (need_init) {
  need_init = 0;
  for (i = 0; i < 10; i++)
   caps[i] = &caps_buf[512 * i];
 }
 for (node = (&events)->next; node != (&events); node = node->next) {
  rev = ((struct re_event *)((char *)(node)-(unsigned long)(&((struct re_event *)0)->link)));
  matches = regex_match(&rev->match, msg, caps);
  ncap = matches - 1;
  if (ncap >= 0)
   rev->call(usr, src, msg, caps, ncap);
 }
}

variable_types:
usr
char *

variable_types:
src
char *

variable_types:
msg
char *

variable_types: void (*)(char *usr, char *src, char *msg, char **caps, int ncap)

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct re_event { struct list_head { struct list_head *next; } link; void (*call)(char *usr, char *src, char *msg, char **caps, int ncap); struct regex { char *pattern; enum regex_compiled_state { RCS_UNINIT=0, RCS_ERROR=1, RCS_COMPILED=2 } state; void *re_detail; } match; } *

variable_types: matches int

variable_types: ncap int

variable_types:
caps
char *[10]

user_defined_types: struct re_event { struct list_head link; void (*call)(char *usr, char *src, char *msg, char **caps, int ncap); struct regex match; }


decompiled_code:
__int64 __fastcall handle_ctcp(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4, int a5)
{
if ( a5 <= 0 )
__assert_fail("ncaps >= 1", "ctcp.c", 0x3Fu, "handle_ctcp");
return ctcp_emit(a1, a2, *a4);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4, int a5)
{
if ( a5 <= 0 )
__assert_fail("ncaps >= 1", "ctcp.c", 0x3Fu, "handle_ctcp");
return func10(a1, a2, *a4);
}

original_code:
static void handle_ctcp(char *usr, char *src, char *msg,
  char **caps, int ncaps)
{
 char *message;
 ((void) sizeof ((ncaps >= 1) ? 1 : 0), __extension__ ({ if (ncaps >= 1) ; else __assert_fail ("ncaps >= 1", "ctcp.c", 63, __extension__ __PRETTY_FUNCTION__); }));
 message = caps[0];
 ctcp_emit(usr, src, message);
}

variable_types:
caps
char **

variable_types: ncaps int

variable_types:
message
char *


original_code:
int hashtab_insert(struct hashtab *h, void *key, void *datum)
{
 unsigned hvalue;
 struct hashtab_node *prev, *cur, *newnode;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (cur && (h->keycmp(h, key, cur->key) == 0))
  return -1;
 newnode = malloc(sizeof(*newnode));
 newnode->key = key;
 newnode->datum = datum;
 if (prev) {
  newnode->next = prev->next;
  prev->next = newnode;
 }
 else {
  newnode->next = h->htable[hvalue];
  h->htable[hvalue] = newnode;
 }
 h->nel++;
 return 0;
}

canonical_original_code:
int hashtab_insert(struct hashtab *h, void *key, void *datum)
{
 unsigned int hvalue;
 struct hashtab_node *prev; struct hashtab_node *cur; struct hashtab_node *newnode;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (cur && (h->keycmp(h, key, cur->key) == 0))
  return -1;
 newnode = malloc(sizeof(*newnode));
 newnode->key = key;
 newnode->datum = datum;
 if (prev) {
  newnode->next = prev->next;
  prev->next = newnode;
 }
 else {
  newnode->next = h->htable[hvalue];
  h->htable[hvalue] = newnode;
 }
 h->nel++;
 return 0;
}

variable_types: struct hashtab { struct hashtab_node { void *key; void *datum; struct hashtab_node *next; } **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab *h, void *key); int (*keycmp)(struct hashtab *h, void *key1, void *key2); } *

variable_types:
key
void *

variable_types:
datum
void *

variable_types:
hvalue
unsigned int

user_defined_types: struct hashtab { struct hashtab_node **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab *h, void *key); int (*keycmp)(struct hashtab *h, void *key1, void *key2); }


decompiled_code:
__int64 __fastcall hashtab_remove(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // r13
_QWORD *v4; // rbp
__int64 result; // rax

v2 = 0LL;
v3 = (*(unsigned int (**)(void))(a1 + 16))();
v4 = *(_QWORD **)(*(_QWORD *)a1 + 8 * v3);
if ( !v4 )
return 0xFFFFFFFFLL;
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v4) > 0 )
{
v2 = v4;
if ( !v4[2] )
return 0xFFFFFFFFLL;
v4 = (_QWORD *)v4[2];
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v4) )
return 0xFFFFFFFFLL;
if ( v2 )
v2[2] = v4[2];
else
*(_QWORD *)(*(_QWORD *)a1 + 8 * v3) = 0LL;
free(v4);
result = 0LL;
--*(_DWORD *)(a1 + 12);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD *v2; // r12
__int64 v3; // r13
_QWORD *v4; // rbp
__int64 result; // rax

v2 = 0LL;
v3 = (*(unsigned int (**)(void))(a1 + 16))();
v4 = *(_QWORD **)(*(_QWORD *)a1 + 8 * v3);
if ( !v4 )
return 0xFFFFFFFFLL;
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v4) > 0 )
{
v2 = v4;
if ( !v4[2] )
return 0xFFFFFFFFLL;
v4 = (_QWORD *)v4[2];
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v4) )
return 0xFFFFFFFFLL;
if ( v2 )
v2[2] = v4[2];
else
*(_QWORD *)(*(_QWORD *)a1 + 8 * v3) = 0LL;
free(v4);
result = 0LL;
--*(_DWORD *)(a1 + 12);
return result;
}

original_code:
int hashtab_remove(struct hashtab *h, void *key)
{
 unsigned hvalue;
 struct hashtab_node *prev, *cur;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (!cur || (h->keycmp(h, key, cur->key) != 0))
  return -1;
 if (prev)
  prev->next = cur->next;
 else
  h->htable[hvalue] = ((void *)0);
 free(cur);
 h->nel--;
 return 0;
}

canonical_original_code:
int hashtab_remove(struct hashtab *h, void *key)
{
 unsigned int hvalue;
 struct hashtab_node *prev; struct hashtab_node *cur;
 hvalue = h->hash_value(h, key);
 prev = ((void *)0);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0) {
  prev = cur;
  cur = cur->next;
 }
 if (!cur || (h->keycmp(h, key, cur->key) != 0))
  return -1;
 if (prev)
  prev->next = cur->next;
 else
  h->htable[hvalue] = ((void *)0);
 free(cur);
 h->nel--;
 return 0;
}

variable_types: struct hashtab_node { void *key; void *datum; struct hashtab_node *next; } *


decompiled_code:
__int64 __fastcall hashtab_search(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(_QWORD **)(*(_QWORD *)a1 + 8LL * (*(unsigned int (**)(void))(a1 + 16))());
if ( !v2 )
goto LABEL_8;
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) > 0 )
{
v2 = (_QWORD *)v2[2];
if ( !v2 )
goto LABEL_8;
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) )
LABEL_8:
result = 0LL;
else
result = v2[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = *(_QWORD **)(*(_QWORD *)a1 + 8LL * (*(unsigned int (**)(void))(a1 + 16))());
if ( !v2 )
goto LABEL_8;
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) > 0 )
{
v2 = (_QWORD *)v2[2];
if ( !v2 )
goto LABEL_8;
}
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24))(a1, a2, *v2) )
LABEL_8:
result = 0LL;
else
result = v2[1];
return result;
}

original_code:
void *hashtab_search(struct hashtab *h, void *key)
{
 unsigned hvalue;
 struct hashtab_node *cur;
 if (!h)
  return ((void *)0);
 hvalue = h->hash_value(h, key);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0)
  cur = cur->next;
 if (cur == ((void *)0) || (h->keycmp(h, key, cur->key) != 0))
  return ((void *)0);
 return cur->datum;
}

canonical_original_code:
void *hashtab_search(struct hashtab *h, void *key)
{
 unsigned int hvalue;
 struct hashtab_node *cur;
 if (!h)
  return ((void *)0);
 hvalue = h->hash_value(h, key);
 cur = h->htable[hvalue];
 while (cur && h->keycmp(h, key, cur->key) > 0)
  cur = cur->next;
 if (cur == ((void *)0) || (h->keycmp(h, key, cur->key) != 0))
  return ((void *)0);
 return cur->datum;
}

user_defined_types: struct hashtab_node { void *key; void *datum; struct hashtab_node *next; }