main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v5; // eax
int v6; // ebp
void *v7; // rbp
struct stat v8; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
v3 = 2;
v5 = open(argv[1], 2, envp);
v6 = v5;
if ( v5 < 0 )
{
perror("open file failed:");
v3 = 1;
}
else if ( (unsigned int)fstat(v5, &v8) == -1 || !v8.st_size )
{
puts("fstat failed:");
}
else
{
v7 = mmap(0LL, v8.st_size, 1, 1, v6, 0LL);
if ( v7 == (void *)-1LL )
{
v3 = 3;
}
else
{
v3 = set_pcm();
if ( v3 )
{
puts("set_pcm fialed:");
v3 = 1;
}
else
{
decode(v7, v8.st_size);
if ( munmap(v7, v8.st_size) == -1 )
{
v3 = 4;
}
else
{
snd_pcm_drain();
snd_pcm_close();
}
}
}
}
}
else
{
printf("Usage: minimad + mp3 file name");
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v5; // eax
int v6; // ebp
void *v7; // rbp
struct stat v8; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
v3 = 2;
v5 = open(argv[1], 2, envp);
v6 = v5;
if ( v5 < 0 )
{
perror("open file failed:");
v3 = 1;
}
else if ( (unsigned int)func15(v5, &v8) == -1 || !v8.st_size )
{
puts("fstat failed:");
}
else
{
v7 = mmap(0LL, v8.st_size, 1, 1, v6, 0LL);
if ( v7 == (void *)-1LL )
{
v3 = 3;
}
else
{
v3 = func12();
if ( v3 )
{
puts("set_pcm fialed:");
v3 = 1;
}
else
{
func8(v7, v8.st_size);
if ( munmap(v7, v8.st_size) == -1 )
{
v3 = 4;
}
else
{
snd_pcm_drain();
snd_pcm_close();
}
}
}
}
}
else
{
printf("Usage: minimad + mp3 file name");
v3 = 1;
}
return v3;
}

original_code:
int main(int argc, char *argv[])
{
    struct stat stat;
    void *fdm;
    if (argc != 2)
    {
        printf("Usage: minimad + mp3 file name");
        return 1;
    }
    int fd;
    fd=open(argv[1],02);
    if(fd<0)
    {
        perror("open file failed:");
        return 1;
    }
    if (fstat(fd, &stat) == -1 ||stat.st_size == 0)
    {
        printf("fstat failed:\n");
        return 2;
    }
    fdm = mmap(0, stat.st_size, 0x1, 0x01, fd, 0);
    if (fdm == ((void *) -1))
        return 3;
    if(set_pcm()!=0)
    {
        printf("set_pcm fialed:\n");
        return 1;
    }
    decode(fdm, stat.st_size);
    if (munmap(fdm, stat.st_size) == -1)
        return 4;
    snd_pcm_drain(handle);
    snd_pcm_close(handle);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types:
fdm
void *

variable_types: fd int

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


canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbx
size_t v5; // rax

if ( argc != 2 )
{
printf("Usage:%s <wav file>\n", *argv);
exit(1);
}
v3 = fopen(argv[1], "rb");
v4 = v3;
if ( !v3 )
{
perror("open file failed:\n");
exit(1);
}
v5 = fread(&wav_header, 1uLL, 0x2CuLL, v3);
printf("nread=%d\n", v5);
printf(&byte_4020B2, (unsigned int)dword_404104);
printf(&byte_4020C9, (unsigned int)word_404116);
printf(&byte_4020D9, (unsigned int)dword_404118);
printf(&byte_4020EC, (unsigned int)word_404122);
printf("wSampleLength=%d\n", (unsigned int)dword_404128);
set_pcm_play(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbx
size_t v5; // rax

if ( argc != 2 )
{
printf("Usage:%s <wav file>\n", *argv);
exit(1);
}
v3 = fopen(argv[1], "rb");
v4 = v3;
if ( !v3 )
{
perror("open file failed:\n");
exit(1);
}
v5 = fread(&wav_header, 1uLL, 0x2CuLL, v3);
printf("nread=%d\n", v5);
printf(&byte_4020B2, (unsigned int)dword_404104);
printf(&byte_4020C9, (unsigned int)word_404116);
printf(&byte_4020D9, (unsigned int)dword_404118);
printf(&byte_4020EC, (unsigned int)word_404122);
printf("wSampleLength=%d\n", (unsigned int)dword_404128);
func7(v4);
return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct stat stat;
    void *fdm;
    if (argc != 2)
    {
        printf("Usage: minimad + mp3 file name");
        return 1;
    }
    int fd;
    fd=open(argv[1],02);
    if(fd<0)
    {
        perror("open file failed:");
        return 1;
    }
    if (fstat(fd, &stat) == -1 ||stat.st_size == 0)
    {
        printf("fstat failed:\n");
        return 2;
    }
    fdm = mmap(0, stat.st_size, 0x1, 0x01, fd, 0);
    if (fdm == ((void *) -1))
        return 3;
    if(set_pcm()!=0)
    {
        printf("set_pcm fialed:\n");
        return 1;
    }
    decode(fdm, stat.st_size);
    if (munmap(fdm, stat.st_size) == -1)
        return 4;
    snd_pcm_drain(handle);
    snd_pcm_close(handle);
    return 0;
}

return_type: int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


xopen

repo: toofishes/onkyocontrol

decompiled_code:
__int64 __fastcall xopen(char *file, int oflag)
{
int v2; // ebx

do
v2 = open(file, oflag);
while ( v2 < 0 && *_errno_location() == 4 );
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file, int oflag)
{
int v2; // ebx

do
v2 = open(file, oflag);
while ( v2 < 0 && *_errno_location() == 4 );
return (unsigned int)v2;
}

original_code:
int xopen(const char *path, int oflag)
{
 int fd;
 while(1) {
  fd = open(path, oflag);
  if ((fd < 0) && (*__errno_location ()) == 4)
   continue;
  return fd;
 }
}

canonical_original_code:
int xopen(char *path, int oflag)
{
 int fd;
 while(1) {
  fd = open(path, oflag);
  if ((fd < 0) && (*__errno_location ()) == 4)
   continue;
  return fd;
 }
}

variable_types:
path
char *

variable_types: oflag int


xclose

decompiled_code:
__int64 __fastcall xclose(int fd)
{
int v1; // ebx

do
v1 = close(fd);
while ( v1 < 0 && *_errno_location() == 4 );
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
int v1; // ebx

do
v1 = close(fd);
while ( v1 < 0 && *_errno_location() == 4 );
return (unsigned int)v1;
}

original_code:
int xclose(int fd)
{
 int nr;
 while(1) {
  nr = close(fd);
  if((nr < 0) && (*__errno_location ()) == 4)
   continue;
  return nr;
 }
}

variable_types: nr int


xread

decompiled_code:
ssize_t __fastcall xread(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

original_code:
ssize_t xread(int fd, void *buf, size_t len)
{
 ssize_t nr;
 while(1) {
  nr = read(fd, buf, len);
  if ((nr < 0) && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4))
   continue;
  return nr;
 }
}

canonical_original_code:
long xread(int fd, void *buf, unsigned long len)
{
 long nr;
 while(1) {
  nr = read(fd, buf, len);
  if ((nr < 0) && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4))
   continue;
  return nr;
 }
}

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types: nr long

return_type: long


xwrite

decompiled_code:
ssize_t __fastcall xwrite(int fd, void *buf, size_t n)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = write(fd, buf, n);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd, void *buf, size_t n)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = write(fd, buf, n);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

original_code:
ssize_t xwrite(int fd, const void *buf, size_t len)
{
 ssize_t nr;
 while(1) {
  nr = write(fd, buf, len);
  if ((nr < 0) && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4))
   continue;
  return nr;
 }
}

canonical_original_code:
long xwrite(int fd, void *buf, unsigned long len)
{
 long nr;
 while(1) {
  nr = write(fd, buf, len);
  if ((nr < 0) && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4))
   continue;
  return nr;
 }
}


decompiled_code:
__int64 __fastcall hash_sdbm(char *a1)
{
char *v1; // rcx
char v2; // al
__int64 v3; // rdx

if ( !a1 )
return 0LL;
v1 = a1 + 1;
v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = 0LL;
do
{
v3 = (unsigned int)v2 + 65599 * v3;
v2 = *v1++;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char *v1; // rcx
char v2; // al
__int64 v3; // rdx

if ( !a1 )
return 0LL;
v1 = a1 + 1;
v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = 0LL;
do
{
v3 = (unsigned int)v2 + 65599 * v3;
v2 = *v1++;
}
while ( v2 );
return v3;
}

original_code:
unsigned long hash_sdbm(const char *str)
{
 unsigned long hash = 0;
 int c;
 if(!str)
  return hash;
 while((c = *str++))
  hash = (unsigned int)c + hash * 65599;
 return hash;
}

canonical_original_code:
unsigned long hash_sdbm(char *str)
{
 unsigned long hash = 0;
 int c;
 if(!str)
  return hash;
 while((c = *str++))
  hash = (unsigned int)c + hash * 65599;
 return hash;
}

variable_types:
str
char *

variable_types:
hash
unsigned long

variable_types: c int

return_type: unsigned long


decompiled_code:
__int64 __fastcall timeval_diff(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = *a1 - *a2;
*a3 = v3;
result = a1[1] - a2[1];
if ( result < 0 )
{
result += 1000000LL;
a3[1] = result;
*a3 = v3 - 1;
}
else
{
a3[1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = *a1 - *a2;
*a3 = v3;
result = a1[1] - a2[1];
if ( result < 0 )
{
result += 1000000LL;
a3[1] = result;
*a3 = v3 - 1;
}
else
{
a3[1] = result;
}
return result;
}

original_code:
void timeval_diff(struct timeval * restrict a,
  struct timeval * restrict b, struct timeval * restrict result)
{
 result->tv_sec = a->tv_sec - b->tv_sec;
 result->tv_usec = a->tv_usec - b->tv_usec;
 if(result->tv_usec < 0) {
  result->tv_usec += 1000000;
  result->tv_sec -= 1;
 }
}

canonical_original_code:
void timeval_diff(struct timeval *a, struct timeval *b, struct timeval *result)
{
 result->tv_sec = a->tv_sec - b->tv_sec;
 result->tv_usec = a->tv_usec - b->tv_usec;
 if(result->tv_usec < 0) {
  result->tv_usec += 1000000;
  result->tv_sec -= 1;
 }
}

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

variable_types:
b
struct timeval *

variable_types:
result
struct timeval *

return_type: void


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

v2 = *a1;
if ( !*a1 && !a1[1] )
return *a2;
if ( v2 < *a2 )
return *a1;
if ( v2 > *a2 )
return *a2;
if ( a1[1] >= a2[1] )
return *a2;
return *a1;
}

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

v2 = *a1;
if ( !*a1 && !a1[1] )
return *a2;
if ( v2 < *a2 )
return *a1;
if ( v2 > *a2 )
return *a2;
if ( a1[1] >= a2[1] )
return *a2;
return *a1;
}

original_code:
struct timeval timeval_min(struct timeval *restrict a,
  struct timeval * restrict b)
{
 if(a->tv_sec == 0 && a->tv_usec == 0) {
  return *b;
 } if(a->tv_sec < b->tv_sec) {
  return *a;
 } else if(a->tv_sec > b->tv_sec) {
  return *b;
 }
 return a->tv_usec < b->tv_usec ? *a : *b;
}

canonical_original_code:
struct timeval timeval_min(struct timeval *a, struct timeval *b)
{
 if(a->tv_sec == 0 && a->tv_usec == 0) {
  return *b;
 } if(a->tv_sec < b->tv_sec) {
  return *a;
 } else if(a->tv_sec > b->tv_sec) {
  return *b;
 }
 return a->tv_usec < b->tv_usec ? *a : *b;
}

variable_types:
a
struct timeval *

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


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

result = 1LL;
if ( *a1 <= 0 )
{
result = 0LL;
if ( !*a1 )
result = a1[1] > 0;
}
return result;
}

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

result = 1LL;
if ( *a1 <= 0 )
{
result = 0LL;
if ( !*a1 )
result = a1[1] > 0;
}
return result;
}

original_code:
int timeval_positive(struct timeval *tv)
{
 if(tv->tv_sec > 0)
  return 1;
 if(tv->tv_sec == 0 && tv->tv_usec > 0)
  return 1;
 return 0;
}

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


usage

repo: topcatsoftware/topic

decompiled_code:
void __noreturn usage()
{
fwrite("usage: bin2c [-cz] <input_file> <output_file>\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
fwrite("usage: bin2c [-cz] <input_file> <output_file>\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}

original_code:
void usage(void)
{
 fprintf(stderr, "usage: bin2c [-cz] <input_file> <output_file>\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "usage: bin2c [-cz] <input_file> <output_file>\n");
 exit(1);
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
__int64 v4; // r8
const char **v5; // r10
bool v6; // cf
bool v7; // zf
const char ***v8; // rax
const char *v9; // rdi
bool v10; // cf
bool v11; // zf
const char *v12; // rdi

v5 = argv;
v6 = (unsigned int)argc < 3;
v7 = argc == 3;
if ( argc > 3 )
{
v8 = (const char ***)(argv + 1);
v4 = (unsigned int)(argc - 1);
do
{
v5 = (const char **)v8;
v12 = "-c";
v3 = 3LL;
argv = *v8;
do
{
if ( !v3 )
break;
v6 = *(_BYTE *)argv < *v12;
v7 = *(_BYTE *)argv == *v12;
argv = (const char **)((char *)argv + 1);
++v12;
--v3;
}
while ( v7 );
LOBYTE(envp) = (!v6 && !v7) - v6;
v10 = 0;
v11 = (_BYTE)envp == 0;
if ( (_BYTE)envp )
{
v9 = "-z";
v3 = 3LL;
argv = *v8;
do
{
if ( !v3 )
break;
v10 = *(_BYTE *)argv < *v9;
v11 = *(_BYTE *)argv == *v9;
argv = (const char **)((char *)argv + 1);
++v9;
--v3;
}
while ( v11 );
LOBYTE(envp) = (!v10 && !v11) - v10;
if ( (_BYTE)envp )
usage(v9, argv, envp, v3, v4);
zeroterminated = 1;
*(_QWORD *)&argc = (unsigned int)v4;
}
else
{
useconst = 1;
*(_QWORD *)&argc = (unsigned int)v4;
}
++v8;
v4 = (unsigned int)(v4 - 1);
v6 = (unsigned int)argc < 3;
v7 = argc == 3;
}
while ( argc > 3 );
}
if ( argc != 3 )
usage(*(_QWORD *)&argc, argv, envp, v3, v4);
process((char *)v5[1], (char *)v5[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
__int64 v4; // r8
const char **v5; // r10
bool v6; // cf
bool v7; // zf
const char ***v8; // rax
const char *v9; // rdi
bool v10; // cf
bool v11; // zf
const char *v12; // rdi

v5 = argv;
v6 = (unsigned int)argc < 3;
v7 = argc == 3;
if ( argc > 3 )
{
v8 = (const char ***)(argv + 1);
v4 = (unsigned int)(argc - 1);
do
{
v5 = (const char **)v8;
v12 = "-c";
v3 = 3LL;
argv = *v8;
do
{
if ( !v3 )
break;
v6 = *(_BYTE *)argv < *v12;
v7 = *(_BYTE *)argv == *v12;
argv = (const char **)((char *)argv + 1);
++v12;
--v3;
}
while ( v7 );
LOBYTE(envp) = (!v6 && !v7) - v6;
v10 = 0;
v11 = (_BYTE)envp == 0;
if ( (_BYTE)envp )
{
v9 = "-z";
v3 = 3LL;
argv = *v8;
do
{
if ( !v3 )
break;
v10 = *(_BYTE *)argv < *v9;
v11 = *(_BYTE *)argv == *v9;
argv = (const char **)((char *)argv + 1);
++v9;
--v3;
}
while ( v11 );
LOBYTE(envp) = (!v10 && !v11) - v10;
if ( (_BYTE)envp )
func9(v9, argv, envp, v3, v4);
zeroterminated = 1;
*(_QWORD *)&argc = (unsigned int)v4;
}
else
{
useconst = 1;
*(_QWORD *)&argc = (unsigned int)v4;
}
++v8;
v4 = (unsigned int)(v4 - 1);
v6 = (unsigned int)argc < 3;
v7 = argc == 3;
}
while ( argc > 3 );
}
if ( argc != 3 )
func9(*(_QWORD *)&argc, argv, envp, v3, v4);
func8((char *)v5[1], (char *)v5[2]);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 while (argc > 3)
 {
  if (!strcmp(argv[1], "-c"))
  {
   useconst = 1;
   --argc;
   ++argv;
  } else if (!strcmp(argv[1], "-z"))
  {
   zeroterminated = 1;
   --argc;
   ++argv;
  } else {
   usage();
  }
 }
 if (argc != 3)
 {
  usage();
 }
 process(argv[1], argv[2]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // er12
char *v7; // rbx

v3 = fileno(stdin);
v4 = isatty(v3 == 1);
v5 = v4;
if ( argc == 2 )
{
v7 = (char *)argv[1];
if ( !strcasecmp(v7, "-m") )
{
if ( v5 )
return getblurb(2, 0);
}
else if ( !strcasecmp(v7, "-l") )
{
if ( v5 )
return getblurb(1, 0);
}
else if ( !strcasecmp(v7, "-i") )
{
if ( !v5 )
return getindex();
}
else if ( !v5 )
{
return getblock(v7);
}
}
else if ( v4 )
{
return getblurb(0, 0);
}
return getblurb(0, 1u);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // er12
char *v7; // rbx

v3 = fileno(stdin);
v4 = isatty(v3 == 1);
v5 = v4;
if ( argc == 2 )
{
v7 = (char *)argv[1];
if ( !strcasecmp(v7, "-m") )
{
if ( v5 )
return func10(2, 0);
}
else if ( !strcasecmp(v7, "-l") )
{
if ( v5 )
return func10(1, 0);
}
else if ( !strcasecmp(v7, "-i") )
{
if ( !v5 )
return func8();
}
else if ( !v5 )
{
return func9(v7);
}
}
else if ( v4 )
{
return func10(0, 0);
}
return func10(0, 1u);
}

canonical_original_code:
int main(int argc, char **argv)
{
 while (argc > 3)
 {
  if (!strcmp(argv[1], "-c"))
  {
   useconst = 1;
   --argc;
   ++argv;
  } else if (!strcmp(argv[1], "-z"))
  {
   zeroterminated = 1;
   --argc;
   ++argv;
  } else {
   usage();
  }
 }
 if (argc != 3)
 {
  usage();
 }
 process(argv[1], argv[2]);
 return 0;
}


repo: topromulan/daisyd

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r13
__int64 v5; // r12
int v6; // eax
char *v7; // rsi
__int64 v8; // rdx
__int16 v10; // [rsp+0h] [rbp-248h] BYREF
unsigned __int16 v11; // [rsp+2h] [rbp-246h]
unsigned int v12; // [rsp+4h] [rbp-244h]
char dest[524]; // [rsp+10h] [rbp-238h] BYREF
unsigned int buf[11]; // [rsp+21Ch] [rbp-2Ch] BYREF

openlog("daisyd", 33, 24);
syslog(5, "daisyd");
LODWORD(v4) = 0;
LODWORD(v5) = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "s:a:p:l:");
if ( v6 == -1 )
break;
if ( v6 == 112 )
{
v5 = (unsigned int)atoi(optarg);
syslog(5, "Proxy port: %d", v5);
}
else if ( v6 > 112 )
{
if ( v6 != 115 )
goto LABEL_14;
strncpy(dest, optarg, 0x200uLL);
syslog(5, "SSL information %s", dest);
}
else if ( v6 == 97 )
{
v7 = optarg;
if ( inet_pton(2, optarg, buf) <= 0 )
err((int)"inet_pton", v7);
syslog(5, "Proxy address: %s", optarg);
}
else
{
if ( v6 != 108 )
{
LABEL_14:
syslog(3, "what is %d?", (unsigned int)v6);
err((int)"options", "what is %d?", v8);
}
v4 = (unsigned int)atoi(optarg);
syslog(5, "Listen port: %d", v4);
}
}
v11 = _bswap_16(v5);
v12 = buf[0];
v10 = 2;
syslog(5, "proxy port %d = %d", (unsigned int)v5, v11);
syslog(5, "proxy address %d ", buf[0]);
sigchld_handling();
if ( !fork() )
daisy_server(dest, (unsigned int)v4, &v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r13
__int64 v5; // r12
int v6; // eax
char *v7; // rsi
__int64 v8; // rdx
__int16 v10; // [rsp+0h] [rbp-248h] BYREF
unsigned __int16 v11; // [rsp+2h] [rbp-246h]
unsigned int v12; // [rsp+4h] [rbp-244h]
char dest[524]; // [rsp+10h] [rbp-238h] BYREF
unsigned int buf[11]; // [rsp+21Ch] [rbp-2Ch] BYREF

openlog("daisyd", 33, 24);
syslog(5, "daisyd");
LODWORD(v4) = 0;
LODWORD(v5) = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "s:a:p:l:");
if ( v6 == -1 )
break;
if ( v6 == 112 )
{
v5 = (unsigned int)atoi(optarg);
syslog(5, "Proxy port: %d", v5);
}
else if ( v6 > 112 )
{
if ( v6 != 115 )
goto LABEL_14;
strncpy(dest, optarg, 0x200uLL);
syslog(5, "SSL information %s", dest);
}
else if ( v6 == 97 )
{
v7 = optarg;
if ( inet_pton(2, optarg, buf) <= 0 )
err((int)"inet_pton", v7);
syslog(5, "Proxy address: %s", optarg);
}
else
{
if ( v6 != 108 )
{
LABEL_14:
syslog(3, "what is %d?", (unsigned int)v6);
err((int)"options", "what is %d?", v8);
}
v4 = (unsigned int)atoi(optarg);
syslog(5, "Listen port: %d", v4);
}
}
v11 = func0(v5);
v12 = buf[0];
v10 = 2;
syslog(5, "proxy port %d = %d", (unsigned int)v5, v11);
syslog(5, "proxy address %d ", buf[0]);
sigchld_handling();
if ( !fork() )
daisy_server(dest, (unsigned int)v4, &v10);
return 0;
}

original_code:
int main(int argc, char **argv) {
 int opt;
 in_addr_t proxy_address;
 int proxy_port = 0;
 int listen_port = 0;
 char cert_file[512];
 struct sockaddr_in p_addr;
        openlog("daisyd", 0x20 | 0x01, (3<<3));
        syslog(5, "daisyd");
 while ( -1 != ( opt = getopt(argc, argv, "s:a:p:l:") ) ) {
  switch ( opt ) {
   case 's':
    strncpy(cert_file, optarg, sizeof(cert_file));
    syslog(5, "SSL information %s",
     cert_file);
    break;
   case 'a':
    opt = inet_pton(2, optarg,
     &proxy_address);
    if ( opt <= 0 )
     err("inet_pton");
    syslog(5, "Proxy address: %s",
     optarg);
    break;
   case 'p':
    proxy_port = atoi(optarg);
    syslog(5, "Proxy port: %d",
     proxy_port);
    break;
   case 'l':
    listen_port = atoi(optarg);
    syslog(5, "Listen port: %d",
     listen_port);
    break;
   default:
    syslog(3, "what is %d?", opt);
    err("options");
  }
 }
 p_addr.sin_port = htons(proxy_port);
 p_addr.sin_addr.s_addr = proxy_address;
 p_addr.sin_family = 2;
        syslog(5, "proxy port %d = %d", proxy_port, p_addr.sin_port);
        syslog(5, "proxy address %d ", proxy_address);
 sigchld_handling();
 if ( ! fork() )
  daisy_server(cert_file, listen_port, &p_addr);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int opt;
 unsigned int proxy_address;
 int proxy_port = 0;
 int listen_port = 0;
 char cert_file[512];
 struct sockaddr_in p_addr;
        openlog("daisyd", 0x20 | 0x01, (3<<3));
        syslog(5, "daisyd");
 while ( -1 != ( opt = getopt(argc, argv, "s:a:p:l:") ) ) {
  switch ( opt ) {
   case 's':
    strncpy(cert_file, optarg, sizeof(cert_file));
    syslog(5, "SSL information %s",
     cert_file);
    break;
   case 'a':
    opt = inet_pton(2, optarg,
     &proxy_address);
    if ( opt <= 0 )
     err("inet_pton");
    syslog(5, "Proxy address: %s",
     optarg);
    break;
   case 'p':
    proxy_port = atoi(optarg);
    syslog(5, "Proxy port: %d",
     proxy_port);
    break;
   case 'l':
    listen_port = atoi(optarg);
    syslog(5, "Listen port: %d",
     listen_port);
    break;
   default:
    syslog(3, "what is %d?", opt);
    err("options");
  }
 }
 p_addr.sin_port = htons(proxy_port);
 p_addr.sin_addr.s_addr = proxy_address;
 p_addr.sin_family = 2;
        syslog(5, "proxy port %d = %d", proxy_port, p_addr.sin_port);
        syslog(5, "proxy address %d ", proxy_address);
 sigchld_handling();
 if ( ! fork() )
  daisy_server(cert_file, listen_port, &p_addr);
 return 0;
}

variable_types: opt int

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

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


decompiled_code:
int sigchld_handling()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = 0LL;
v1.sa_flags = 2;
result = sigaction(17, &v1, 0LL);
if ( result )
err((int)"sigaction error", (const char *)&v1);
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = 0LL;
v1.sa_flags = 2;
result = sigaction(17, &v1, 0LL);
if ( result )
err((int)"sigaction error", (const char *)&v1);
return result;
}

original_code:
void sigchld_handling(void) {
        struct sigaction my_handling;
        my_handling.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
        my_handling.sa_flags = 2;
        if ( sigaction(17, &my_handling, 0) )
                err("sigaction error");
}

canonical_original_code:
void sigchld_handling() {
        struct sigaction my_handling;
        my_handling.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
        my_handling.sa_flags = 2;
        if ( sigaction(17, &my_handling, 0) )
                err("sigaction error");
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 daisy_ssl_init()
{
OPENSSL_init_ssl(0LL, 0LL);
CRYPTO_malloc_init();
OPENSSL_init_crypto(2LL, 0LL);
OPENSSL_init_ssl(2097154LL, 0LL);
OPENSSL_init_crypto(4LL, 0LL);
OPENSSL_init_crypto(8LL, 0LL);
return OPENSSL_init_crypto(12LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
OPENSSL_init_ssl(0LL, 0LL);
CRYPTO_malloc_init();
OPENSSL_init_crypto(2LL, 0LL);
OPENSSL_init_ssl(2097154LL, 0LL);
OPENSSL_init_crypto(4LL, 0LL);
OPENSSL_init_crypto(8LL, 0LL);
return OPENSSL_init_crypto(12LL, 0LL);
}

original_code:
void daisy_ssl_init(void) {
 OPENSSL_init_ssl(0, ((void *)0));
 CRYPTO_malloc_init();
 OPENSSL_init_crypto(0x00000002L, ((void *)0));
 OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
 OPENSSL_init_crypto(0x00000004L, ((void *)0));
 OPENSSL_init_crypto(0x00000008L, ((void *)0));
 OPENSSL_init_crypto(0x00000004L | 0x00000008L, ((void *)0));
}

canonical_original_code:
void daisy_ssl_init() {
 OPENSSL_init_ssl(0, ((void *)0));
 CRYPTO_malloc_init();
 OPENSSL_init_crypto(0x00000002L, ((void *)0));
 OPENSSL_init_ssl(0x00200000L | 0x00000002L, ((void *)0));
 OPENSSL_init_crypto(0x00000004L, ((void *)0));
 OPENSSL_init_crypto(0x00000008L, ((void *)0));
 OPENSSL_init_crypto(0x00000004L | 0x00000008L, ((void *)0));
}


decompiled_code:
__int64 __fastcall daisy_listener_setup(int a1)
{
int v1; // ebx
unsigned int v2; // ebp
__int16 v3; // ax
int v4; // edi
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v1 = a1;
v2 = socket(2, 1, 0);
v3 = (_WORD)a1 << 8;
v4 = a1 + 255;
if ( v1 < 0 )
v1 = v4;
*(_WORD *)v6.sa_data = v3 + (v1 >> 8);
*(_DWORD *)&v6.sa_data[2] = 0;
if ( bind(v2, &v6, 0x10u) )
_assert_fail(
"!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))",
"daisy.c",
0x70u,
"daisy_listener_setup");
if ( listen(v2, 1024) )
_assert_fail("!listen(s, 1024)", "daisy.c", 0x72u, "daisy_listener_setup");
syslog(5, "Listening.");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ebx
unsigned int v2; // ebp
__int16 v3; // ax
int v4; // edi
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

v1 = a1;
v2 = socket(2, 1, 0);
v3 = (_WORD)a1 << 8;
v4 = a1 + 255;
if ( v1 < 0 )
v1 = v4;
*(_WORD *)v6.sa_data = v3 + (v1 >> 8);
*(_DWORD *)&v6.sa_data[2] = 0;
if ( bind(v2, &v6, 0x10u) )
_assert_fail(
"!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))",
"daisy.c",
0x70u,
"daisy_listener_setup");
if ( listen(v2, 1024) )
_assert_fail("!listen(s, 1024)", "daisy.c", 0x72u, "daisy_listener_setup");
syslog(5, "Listening.");
return v2;
}

original_code:
int daisy_listener_setup(int listen_port) {
 int s;
 struct sockaddr_in saddr;
 s = socket(2, SOCK_STREAM, 0);
 saddr.sin_port = listen_port % 256 * 256 + listen_port / 256;
 saddr.sin_addr.s_addr = (in_addr_t)0;
 ((void) sizeof ((!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))) ? 1 : 0), __extension__ ({ if (!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))) ; else __assert_fail ("!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))", "daisy.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!listen(s, 1024)) ? 1 : 0), __extension__ ({ if (!listen(s, 1024)) ; else __assert_fail ("!listen(s, 1024)", "daisy.c", 114, __extension__ __PRETTY_FUNCTION__); }));
 syslog(5, "Listening.");
 return s;
}

canonical_original_code:
int daisy_listener_setup(int listen_port) {
 int s;
 struct sockaddr_in saddr;
 s = socket(2, SOCK_STREAM, 0);
 saddr.sin_port = listen_port % 256 * 256 + listen_port / 256;
 saddr.sin_addr.s_addr = (unsigned int)0;
 ((void) sizeof ((!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))) ? 1 : 0), __extension__ ({ if (!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))) ; else __assert_fail ("!bind(s, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))", "daisy.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!listen(s, 1024)) ? 1 : 0), __extension__ ({ if (!listen(s, 1024)) ; else __assert_fail ("!listen(s, 1024)", "daisy.c", 114, __extension__ __PRETTY_FUNCTION__); }));
 syslog(5, "Listening.");
 return s;
}

variable_types: s int

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


err

decompiled_code:
void __fastcall __noreturn err(const char *a1)
{
int *v1; // rax
char *v2; // rax
const char *v3; // rax
__int64 v4; // rdi

v1 = _errno_location();
v2 = strerror(*v1);
sprintf(buff, "Uh oh - %20s. %30s", a1, v2);
syslog(3, buff);
if ( ERR_peek_error() )
{
while ( 1 )
{
v4 = ERR_get_error();
if ( !v4 )
break;
v3 = (const char *)ERR_error_string(v4, 0LL);
sprintf(buff, "SSL Error: %s.", v3);
syslog(3, buff);
}
}
else
{
syslog(7, "No SSL Errors.");
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
int *v1; // rax
char *v2; // rax
const char *v3; // rax
__int64 v4; // rdi

v1 = _errno_location();
v2 = strerror(*v1);
sprintf(buff, "Uh oh - %20s. %30s", a1, v2);
syslog(3, buff);
if ( ERR_peek_error() )
{
while ( 1 )
{
v4 = ERR_get_error();
if ( !v4 )
break;
v3 = (const char *)ERR_error_string(v4, 0LL);
sprintf(buff, "SSL Error: %s.", v3);
syslog(3, buff);
}
}
else
{
syslog(7, "No SSL Errors.");
}
exit(1);
}

original_code:
void err(char *explanation)
{
 unsigned long sad_truth;
 sprintf(buff, "Uh oh - %20s. %30s", explanation, strerror((*__errno_location ())));
 syslog(3, buff);
 if ( ERR_peek_error() ) {
  while ( ( sad_truth = ERR_get_error() ) ) {
   sprintf(buff, "SSL Error: %s.", ERR_error_string(sad_truth, ((void *)0)) );
   syslog(3, buff);
  }
 } else
  syslog(7, "No SSL Errors.");
        exit(1);
}

variable_types:
explanation
char *


decompiled_code:
void assert_active_test_suite()
{
if ( active_test_suite != 1 )
{
fwrite("No active test suite! Call begin_test_suite() first!\n", 1uLL, 0x35uLL, stderr);
_assert_fail("0", "unit_test.c", 0x18u, "assert_active_test_suite");
}
}

canonical_decompiled_code:
void func0()
{
if ( active_test_suite != 1 )
{
fwrite("No active test suite! Call begin_test_suite() first!\n", 1uLL, 0x35uLL, stderr);
_assert_fail("0", "unit_test.c", 0x18u, "assert_active_test_suite");
}
}

original_code:
static void assert_active_test_suite() {
 if(active_test_suite != 1) {
  fprintf(stderr, "No active test suite! Call begin_test_suite() first!\n");
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "unit_test.c", 24, __extension__ __PRETTY_FUNCTION__); }));
 }
}


decompiled_code:
void assert_active_test()
{
if ( test_status == -1 )
{
fwrite("Assert called, but no test was active\n", 1uLL, 0x26uLL, stderr);
_assert_fail("0", "unit_test.c", 0x1Fu, "assert_active_test");
}
}

canonical_decompiled_code:
void func1()
{
if ( test_status == -1 )
{
fwrite("Assert called, but no test was active\n", 1uLL, 0x26uLL, stderr);
_assert_fail("0", "unit_test.c", 0x1Fu, "assert_active_test");
}
}

original_code:
static void assert_active_test() {
 if(test_status == -1) {
  fprintf(stderr, "Assert called, but no test was active\n");
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "unit_test.c", 31, __extension__ __PRETTY_FUNCTION__); }));
 }
}


decompiled_code:
void __fastcall core_assert(int a1, const char *a2)
{
assert_active_test();
if ( !(test_status | a1) )
{
color("\x1B[0;31m");
printf("Test %s: FAIL. Expected %s\n", current_test, a2);
test_status = 1;
reset_color();
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const char *a2)
{
func1();
if ( !(test_status | a1) )
{
color("\x1B[0;31m");
printf("Test %s: FAIL. Expected %s\n", current_test, a2);
test_status = 1;
reset_color();
}
}

original_code:
static void core_assert(int expr, const char * error_msg) {
 assert_active_test();
 if(test_status == 0) {
  if(expr == 0) {
   color("\033[0;31m");
   printf("Test %s: FAIL. Expected %s\n", current_test, error_msg);
   test_status=1;
   reset_color();
  }
 }
}

canonical_original_code:
static void core_assert(int expr, char *error_msg) {
 assert_active_test();
 if(test_status == 0) {
  if(expr == 0) {
   color("\033[0;31m");
   printf("Test %s: FAIL. Expected %s\n", current_test, error_msg);
   test_status=1;
   reset_color();
  }
 }
}

variable_types: expr int


decompiled_code:
int begin_test_suite()
{
int result; // eax

if ( active_test_suite == 1 )
{
fwrite("Test suite already active!\n", 1uLL, 0x1BuLL, stderr);
_assert_fail("0", "unit_test.c", 0x26u, "begin_test_suite");
}
result = puts("============= BEGIN TEST SUITE ===============\n");
success_tests = 0;
total_tests = 0;
active_test_suite = 1;
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

if ( active_test_suite == 1 )
{
fwrite("Test suite already active!\n", 1uLL, 0x1BuLL, stderr);
_assert_fail("0", "unit_test.c", 0x26u, "begin_test_suite");
}
result = puts("============= BEGIN TEST SUITE ===============\n");
success_tests = 0;
total_tests = 0;
active_test_suite = 1;
return result;
}

original_code:
void begin_test_suite() {
 if(active_test_suite == 1) {
  fprintf(stderr, "Test suite already active!\n");
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "unit_test.c", 38, __extension__ __PRETTY_FUNCTION__); }));
 } else {
  printf("============= BEGIN TEST SUITE ===============\n\n");
 }
 success_tests = 0;
 total_tests = 0;
 active_test_suite = 1;
}


decompiled_code:
_BOOL8 end_test_suite()
{
const char *v0; // rsi

assert_active_test_suite();
active_test_suite = 0;
puts("============= END TEST SUITE ===============");
if ( success_tests == total_tests )
{
color("\x1B[0;32m");
v0 = "succeeded";
}
else
{
color("\x1B[0;31m");
v0 = "failed";
}
printf("Test suite %s. Succesive tests: %d/%d\n", v0, (unsigned int)success_tests, (unsigned int)total_tests);
reset_color();
return success_tests != total_tests;
}

canonical_decompiled_code:
_BOOL8 func4()
{
const char *v0; // rsi

func0();
active_test_suite = 0;
puts("============= END TEST SUITE ===============");
if ( success_tests == total_tests )
{
color("\x1B[0;32m");
v0 = "succeeded";
}
else
{
color("\x1B[0;31m");
v0 = "failed";
}
printf("Test suite %s. Succesive tests: %d/%d\n", v0, (unsigned int)success_tests, (unsigned int)total_tests);
reset_color();
return success_tests != total_tests;
}

original_code:
int end_test_suite() {
 assert_active_test_suite();
 active_test_suite = 0;
 const char * status;
 printf("============= END TEST SUITE ===============\n");
 if(success_tests == total_tests) {
  status = "succeeded";
  color("\033[0;32m");
 } else {
  status = "failed";
  color("\033[0;31m");
 }
 printf("Test suite %s. Succesive tests: %d/%d\n", status, success_tests, total_tests);
 reset_color();
 return !(success_tests == total_tests);
}

canonical_original_code:
int end_test_suite() {
 assert_active_test_suite();
 active_test_suite = 0;
 char *status;
 printf("============= END TEST SUITE ===============\n");
 if(success_tests == total_tests) {
  status = "succeeded";
  color("\033[0;32m");
 } else {
  status = "failed";
  color("\033[0;31m");
 }
 printf("Test suite %s. Succesive tests: %d/%d\n", status, success_tests, total_tests);
 reset_color();
 return !(success_tests == total_tests);
}

variable_types:
status
char *


decompiled_code:
int __fastcall begin_context(char *src)
{
assert_active_test_suite();
context_tests = 0;
context_success = 0;
test_status = -1;
strcpy(current_context, src);
return printf("==== %s ====\n", src);
}

canonical_decompiled_code:
int __fastcall func5(char *src)
{
func0();
context_tests = 0;
context_success = 0;
test_status = -1;
strcpy(current_context, src);
return printf("==== %s ====\n", src);
}

original_code:
void begin_context(const char * context) {
 assert_active_test_suite();
 context_tests = 0;
 context_success = 0;
 test_status = -1;
 strcpy(current_context, context);
 printf("==== %s ====\n", context);
}

canonical_original_code:
void begin_context(char *context) {
 assert_active_test_suite();
 context_tests = 0;
 context_success = 0;
 test_status = -1;
 strcpy(current_context, context);
 printf("==== %s ====\n", context);
}

variable_types:
context
char *


decompiled_code:
__int64 end_test()
{
unsigned int v0; // ebx

v0 = test_status;
if ( test_status == -1 )
return 0;
++context_tests;
++total_tests;
if ( test_status )
{
test_status = -1;
v0 = 1;
}
else
{
++context_success;
++success_tests;
test_status = -1;
color("\x1B[0;32m");
printf("Test %s: OK\n", current_test);
reset_color();
}
return v0;
}

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

v0 = test_status;
if ( test_status == -1 )
return 0;
++context_tests;
++total_tests;
if ( test_status )
{
test_status = -1;
v0 = 1;
}
else
{
++context_success;
++success_tests;
test_status = -1;
color("\x1B[0;32m");
printf("Test %s: OK\n", current_test);
reset_color();
}
return v0;
}

original_code:
int end_test() {
 if(test_status == -1) {
  return 0;
 } else {
  ++context_tests;
  ++total_tests;
  if(test_status == 0) {
   ++context_success;
   ++success_tests;
   test_status = -1;
   color("\033[0;32m");
   printf("Test %s: OK\n", current_test);
   reset_color();
   return 0;
  } else {
   test_status = -1;
   return 1;
  }
 }
}


decompiled_code:
_BOOL8 end_context()
{
end_test();
puts("==============================");
printf(
"Result for %s: %d/%d successfull tests\n\n",
current_context,
(unsigned int)context_success,
(unsigned int)context_tests);
return context_success != context_tests;
}

canonical_decompiled_code:
_BOOL8 func7()
{
func6();
puts("==============================");
printf(
"Result for %s: %d/%d successfull tests\n\n",
current_context,
(unsigned int)context_success,
(unsigned int)context_tests);
return context_success != context_tests;
}

original_code:
int end_context() {
 const char * status;
 end_test();
 printf("==============================\n");
 printf("Result for %s: %d/%d successfull tests\n\n", current_context, context_success, context_tests);
 return !(context_success == context_tests);
}

canonical_original_code:
int end_context() {
 char *status;
 end_test();
 printf("==============================\n");
 printf("Result for %s: %d/%d successfull tests\n\n", current_context, context_success, context_tests);
 return !(context_success == context_tests);
}


decompiled_code:
char *__fastcall begin_test(char *src)
{
assert_active_test_suite();
end_test();
test_status = 0;
return strcpy(current_test, src);
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
func0();
func6();
test_status = 0;
return strcpy(current_test, src);
}

original_code:
void begin_test(const char * test_name) {
 assert_active_test_suite();
 end_test();
 test_status = 0;
 strcpy(current_test, test_name);
}

canonical_original_code:
void begin_test(char *test_name) {
 assert_active_test_suite();
 end_test();
 test_status = 0;
 strcpy(current_test, test_name);
}


decompiled_code:
void __fastcall assert_custom(int a1, const char *a2)
{
core_assert(a1, a2);
}

canonical_decompiled_code:
void __fastcall func9(int a1, const char *a2)
{
func2(a1, a2);
}

original_code:
void assert_custom(int expr, const char * msg) {
 core_assert(expr, msg);
}

canonical_original_code:
void assert_custom(int expr, char *msg) {
 core_assert(expr, msg);
}

variable_types:
msg
char *


decompiled_code:
void __fastcall assert_true(int a1)
{
core_assert(a1, "expression to be true");
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
func2(a1, "expression to be true");
}

original_code:
void assert_true(int expr) {
 core_assert(expr, "expression to be true");
}


decompiled_code:
void __fastcall assert_false(int a1)
{
core_assert(a1 == 0, "expression to be false");
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
func2(a1 == 0, "expression to be false");
}

original_code:
void assert_false(int expr) {
 core_assert((expr==0), "expression to be false");
}


decompiled_code:
void __fastcall assert_gt(unsigned int a1, unsigned int a2)
{
char v2[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v2, "%d to be greater than %d", a1, a2);
core_assert((int)a1 > (int)a2, v2);
}

canonical_decompiled_code:
void __fastcall func12(unsigned int a1, unsigned int a2)
{
char v2[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v2, "%d to be greater than %d", a1, a2);
func2((int)a1 > (int)a2, v2);
}

original_code:
void assert_gt(int v1,int v2) {
 char msg[128];
 sprintf(msg, "%d to be greater than %d", v1, v2);
 core_assert((v1>v2), msg);
}

canonical_original_code:
void assert_gt(int v1, int v2) {
 char msg[128];
 sprintf(msg, "%d to be greater than %d", v1, v2);
 core_assert((v1>v2), msg);
}

variable_types:
msg
char [128]


decompiled_code:
void __fastcall assert_lt(unsigned int a1, unsigned int a2)
{
char v2[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v2, "%d to be less than %d", a1, a2);
core_assert((int)a1 < (int)a2, v2);
}

canonical_decompiled_code:
void __fastcall func13(unsigned int a1, unsigned int a2)
{
char v2[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v2, "%d to be less than %d", a1, a2);
func2((int)a1 < (int)a2, v2);
}

original_code:
void assert_lt(int v1, int v2) {
 char msg[128];
 sprintf(msg, "%d to be less than %d", v1, v2);
 core_assert((v1<v2), msg);
}


decompiled_code:
void __fastcall assert_strings_equal(char *s1, char *s2)
{
size_t v2; // rbx
int v3; // eax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = strlen(s1);
if ( strlen(s2) + v2 > 0xEF )
strcpy(v4, "strings to be equal");
else
sprintf(v4, "\"%s\" to be equal to \"%s\"", s1, s2);
v3 = strcmp(s1, s2);
core_assert(v3 == 0, v4);
}

canonical_decompiled_code:
void __fastcall func14(char *s1, char *s2)
{
size_t v2; // rbx
int v3; // eax
char v4[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = strlen(s1);
if ( strlen(s2) + v2 > 0xEF )
strcpy(v4, "strings to be equal");
else
sprintf(v4, "\"%s\" to be equal to \"%s\"", s1, s2);
v3 = strcmp(s1, s2);
func2(v3 == 0, v4);
}

original_code:
void assert_strings_equal(const char * str1, const char * str2) {
 char msg[256];
 if(strlen(str1)+strlen(str2) < 240) {
  sprintf(msg, "\"%s\" to be equal to \"%s\"", str1, str2);
 } else {
  sprintf(msg, "strings to be equal");
 }
 core_assert((strcmp(str1, str2)==0), msg);
}

canonical_original_code:
void assert_strings_equal(char *str1, char *str2) {
 char msg[256];
 if(strlen(str1)+strlen(str2) < 240) {
  sprintf(msg, "\"%s\" to be equal to \"%s\"", str1, str2);
 } else {
  sprintf(msg, "strings to be equal");
 }
 core_assert((strcmp(str1, str2)==0), msg);
}

variable_types:
msg
char [256]


decompiled_code:
void __fastcall assert_strings_equal_n(char *s1, char *s2, int a3)
{
int v4; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( 2 * a3 > 239 )
strcpy(v5, "strings to be equal");
else
sprintf(v5, "\"%.*s\" to be equal to \"%.*s\"", a3, s1, a3, s2);
v4 = strncmp(s1, s2, a3);
core_assert(v4 == 0, v5);
}

canonical_decompiled_code:
void __fastcall func15(char *s1, char *s2, int a3)
{
int v4; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( 2 * a3 > 239 )
strcpy(v5, "strings to be equal");
else
sprintf(v5, "\"%.*s\" to be equal to \"%.*s\"", a3, s1, a3, s2);
v4 = strncmp(s1, s2, a3);
func2(v4 == 0, v5);
}

original_code:
void assert_strings_equal_n(const char * str1, const char * str2, int n) {
 char msg[256];
 if(2*n < 240) {
  sprintf(msg, "\"%.*s\" to be equal to \"%.*s\"", n,str1,n, str2);
 } else {
  sprintf(msg, "strings to be equal");
 }
 core_assert((strncmp(str1, str2, n)==0), msg);
}

canonical_original_code:
void assert_strings_equal_n(char *str1, char *str2, int n) {
 char msg[256];
 if(2*n < 240) {
  sprintf(msg, "\"%.*s\" to be equal to \"%.*s\"", n,str1,n, str2);
 } else {
  sprintf(msg, "strings to be equal");
 }
 core_assert((strncmp(str1, str2, n)==0), msg);
}

variable_types: n int


decompiled_code:
void __fastcall assert_ints_equal(unsigned int a1, unsigned int a2)
{
char v2[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v2, "%d to be equal to %d", a1, a2);
core_assert(a1 == a2, v2);
}

canonical_decompiled_code:
void __fastcall func16(unsigned int a1, unsigned int a2)
{
char v2[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v2, "%d to be equal to %d", a1, a2);
func2(a1 == a2, v2);
}

original_code:
void assert_ints_equal(int i1, int i2) {
 char msg[128];
 sprintf(msg, "%d to be equal to %d", i1, i2);
 core_assert((i1==i2), msg);
}


color

decompiled_code:
int __fastcall color(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("%s", a1);
}

original_code:
void color(const char * color) {
 printf("%s", color);
}

canonical_original_code:
void color(char *color) {
 printf("%s", color);
}

variable_types:
color
char *


decompiled_code:
int reset_color()
{
return printf("%s", "\x1B[0m");
}

canonical_decompiled_code:
int func1()
{
return printf("%s", "\x1B[0m");
}

original_code:
void reset_color() {
 printf("%s", "\033[0m");
}


repo: torrentkino/torrentkino

decompiled_code:
_QWORD *nbhd_init()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)myalloc(16LL);
*v0 = bckt_init();
v0[1] = hash_init(4096LL);
return v0;
}

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

v0 = (_QWORD *)myalloc(16LL);
*v0 = bckt_init();
v0[1] = hash_init(4096LL);
return v0;
}

original_code:
NBHD *nbhd_init(void)
{
 NBHD *nbhd = (NBHD *) myalloc(sizeof(NBHD));
 nbhd->bucket = bckt_init();
 nbhd->hash = hash_init(4096);
 return nbhd;
}

canonical_original_code:
struct obj_nbhd *nbhd_init()
{
 struct obj_nbhd *nbhd = (NBHD *) myalloc(sizeof(NBHD));
 nbhd->bucket = bckt_init();
 nbhd->hash = hash_init(4096);
 return nbhd;
}

variable_types: struct obj_nbhd { struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *bucket; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

user_defined_types: struct obj_nbhd { struct obj_list *bucket; struct HASH *hash; }

user_defined_types: struct obj_list { struct obj_item *item; long size; }

user_defined_types: struct HASH { struct BUCKET *buckets; long size; }

user_defined_types: struct BUCKET { struct PAIR *pairs; long size; }


decompiled_code:
__int64 nbhd_free()
{
bckt_free(**((_QWORD **)main + 7));
hash_free(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL));
return myfree(*((_QWORD *)main + 7));
}

canonical_decompiled_code:
__int64 func1()
{
bckt_free(**((_QWORD **)main + 7));
hash_free(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL));
return myfree(*((_QWORD *)main + 7));
}

original_code:
void nbhd_free(void)
{
 bckt_free(_main->nbhd->bucket);
 hash_free(_main->nbhd->hash);
 myfree(_main->nbhd);
}

canonical_original_code:
void nbhd_free()
{
 bckt_free(_main->nbhd->bucket);
 hash_free(_main->nbhd->hash);
 myfree(_main->nbhd);
}


decompiled_code:
__int64 __fastcall nbhd_put(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rbx

result = node_me();
if ( !(_DWORD)result )
{
result = ip_is_localhost(a2);
if ( !(_DWORD)result )
{
v3 = hash_get(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
if ( v3 )
{
result = node_update(v3, a2);
}
else
{
v4 = node_init(a1, a2);
if ( (unsigned int)bckt_put(**((_QWORD **)main + 7), v4) )
result = hash_put(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), v4, 20LL, v4);
else
result = node_free(v4);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rbx

result = node_me();
if ( !(_DWORD)result )
{
result = ip_is_localhost(a2);
if ( !(_DWORD)result )
{
v3 = hash_get(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
if ( v3 )
{
result = node_update(v3, a2);
}
else
{
v4 = node_init(a1, a2);
if ( (unsigned int)bckt_put(**((_QWORD **)main + 7), v4) )
result = hash_put(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), v4, 20LL, v4);
else
result = node_free(v4);
}
}
}
return result;
}

original_code:
void nbhd_put(UCHAR * id, IP * sa)
{
 UDP_NODE *n = ((void *)0);
 if (node_me(id)) {
  return;
 }
 if (ip_is_localhost(sa)) {
  return;
 }
 if ((n = hash_get(_main->nbhd->hash, id, 20)) != ((void *)0)) {
  node_update(n, sa);
  return;
 }
 n = node_init(id, sa);
 if (!bckt_put(_main->nbhd->bucket, n)) {
  node_free(n);
  return;
 }
 hash_put(_main->nbhd->hash, n->id, 20, n);
}

canonical_original_code:
void nbhd_put(unsigned char *id, struct sockaddr_in *sa)
{
 struct UDP_NODE *n = ((void *)0);
 if (node_me(id)) {
  return;
 }
 if (ip_is_localhost(sa)) {
  return;
 }
 if ((n = hash_get(_main->nbhd->hash, id, 20)) != ((void *)0)) {
  node_update(n, sa);
  return;
 }
 n = node_init(id, sa);
 if (!bckt_put(_main->nbhd->bucket, n)) {
  node_free(n);
  return;
 }
 hash_put(_main->nbhd->hash, n->id, 20, n);
}

variable_types:
id
unsigned char *

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

variable_types: struct UDP_NODE { unsigned char id[20]; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } c_addr; long time_ping; long time_find; int pinged; } *

user_defined_types: struct UDP_NODE { unsigned char id[20]; struct sockaddr_in c_addr; long time_ping; long time_find; int pinged; }


decompiled_code:
__int64 __fastcall nbhd_del(__int64 a1)
{
bckt_del(**((_QWORD **)main + 7), a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
return node_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
bckt_del(**((_QWORD **)main + 7), a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
return node_free(a1);
}

original_code:
void nbhd_del(UDP_NODE * n)
{
 bckt_del(_main->nbhd->bucket, n);
 hash_del(_main->nbhd->hash, n->id, 20);
 node_free(n);
}

canonical_original_code:
void nbhd_del(struct UDP_NODE *n)
{
 bckt_del(_main->nbhd->bucket, n);
 hash_del(_main->nbhd->hash, n->id, 20);
 node_free(n);
}


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

result = hash_get(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
if ( result )
result = node_pinged(result);
return result;
}

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

result = hash_get(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
if ( result )
result = node_pinged(result);
return result;
}

original_code:
void nbhd_pinged(UCHAR * id)
{
 UDP_NODE *n = hash_get(_main->nbhd->hash, id, 20);
 if (n != ((void *)0)) {
  node_pinged(n);
 }
}

canonical_original_code:
void nbhd_pinged(unsigned char *id)
{
 struct UDP_NODE *n = hash_get(_main->nbhd->hash, id, 20);
 if (n != ((void *)0)) {
  node_pinged(n);
 }
}


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

result = hash_get(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
if ( result )
result = node_ponged(result, a2);
return result;
}

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

result = hash_get(*(_QWORD *)(*((_QWORD *)main + 7) + 8LL), a1, 20LL);
if ( result )
result = node_ponged(result, a2);
return result;
}

original_code:
void nbhd_ponged(UCHAR * id, IP * from)
{
 UDP_NODE *n = hash_get(_main->nbhd->hash, id, 20);
 if (n != ((void *)0)) {
  node_ponged(n, from);
 }
}

canonical_original_code:
void nbhd_ponged(unsigned char *id, struct sockaddr_in *from)
{
 struct UDP_NODE *n = hash_get(_main->nbhd->hash, id, 20);
 if (n != ((void *)0)) {
  node_ponged(n, from);
 }
}


decompiled_code:
__int64 nbhd_expire()
{
__int64 result; // rax
__int64 i; // r12
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax

result = list_start(**((_QWORD **)main + 7));
for ( i = result; result; i = result )
{
v4 = list_value(i);
v3 = list_start(*(_QWORD *)(v4 + 24));
while ( v3 )
{
v2 = list_value(v3);
v3 = list_next(v3);
if ( (unsigned int)node_bad(v2) )
nbhd_del(v2);
}
result = list_next(i);
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 i; // r12
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax

result = list_start(**((_QWORD **)main + 7));
for ( i = result; result; i = result )
{
v4 = list_value(i);
v3 = list_start(*(_QWORD *)(v4 + 24));
while ( v3 )
{
v2 = list_value(v3);
v3 = list_next(v3);
if ( (unsigned int)node_bad(v2) )
func3(v2);
}
result = list_next(i);
}
return result;
}

original_code:
void nbhd_expire(time_t now)
{
 ITEM *item_b = ((void *)0);
 BUCK *b = ((void *)0);
 ITEM *item_n = ((void *)0);
 ITEM *item_n_next = ((void *)0);
 UDP_NODE *n = ((void *)0);
 item_b = list_start(_main->nbhd->bucket);
 while (item_b != ((void *)0)) {
  b = list_value(item_b);
  item_n = list_start(b->nodes);
  while (item_n != ((void *)0)) {
   n = list_value(item_n);
   item_n_next = list_next(item_n);
   if (node_bad(n)) {
    nbhd_del(n);
   }
   item_n = item_n_next;
  }
  item_b = list_next(item_b);
 }
}

canonical_original_code:
void nbhd_expire(long now)
{
 struct obj_item *item_b = ((void *)0);
 struct obj_neighboorhood_bucket *b = ((void *)0);
 struct obj_item *item_n = ((void *)0);
 struct obj_item *item_n_next = ((void *)0);
 struct UDP_NODE *n = ((void *)0);
 item_b = list_start(_main->nbhd->bucket);
 while (item_b != ((void *)0)) {
  b = list_value(item_b);
  item_n = list_start(b->nodes);
  while (item_n != ((void *)0)) {
   n = list_value(item_n);
   item_n_next = list_next(item_n);
   if (node_bad(n)) {
    nbhd_del(n);
   }
   item_n = item_n_next;
  }
  item_b = list_next(item_b);
 }
}

variable_types: now long

variable_types: struct obj_neighboorhood_bucket { unsigned char id[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *nodes; } *

user_defined_types: struct obj_neighboorhood_bucket { unsigned char id[20]; struct obj_list *nodes; }


decompiled_code:
__int64 __fastcall nbhd_split(__int64 a1, unsigned int a2)
{
return bckt_split_loop(**((_QWORD **)main + 7), a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return bckt_split_loop(**((_QWORD **)main + 7), a1, a2);
}

original_code:
void nbhd_split(UCHAR * target, int verbose)
{
 bckt_split_loop(_main->nbhd->bucket, target, verbose);
}

canonical_original_code:
void nbhd_split(unsigned char *target, int verbose)
{
 bckt_split_loop(_main->nbhd->bucket, target, verbose);
}

variable_types:
target
unsigned char *

variable_types: verbose int


decompiled_code:
__int64 nbhd_is_empty()
{
return bckt_is_empty(**((_QWORD **)main + 7));
}

canonical_decompiled_code:
__int64 func8()
{
return bckt_is_empty(**((_QWORD **)main + 7));
}

original_code:
int nbhd_is_empty(void)
{
 return bckt_is_empty(_main->nbhd->bucket);
}

canonical_original_code:
int nbhd_is_empty()
{
 return bckt_is_empty(_main->nbhd->bucket);
}


decompiled_code:
unsigned __int64 __fastcall p_get16bits(unsigned __int8 **a1)
{
unsigned __int64 result; // rax

result = ((unsigned __int64)**a1 << 8) + (*a1)[1];
*a1 += 2;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int8 **a1)
{
unsigned __int64 result; // rax

result = ((unsigned __int64)**a1 << 8) + (*a1)[1];
*a1 += 2;
return result;
}

original_code:
int p_get16bits(const UCHAR ** buffer)
{
 size_t value = (*buffer)[0];
 value = value << 8;
 value += (*buffer)[1];
 *buffer += 2;
 return value;
}

canonical_original_code:
int p_get16bits(unsigned char **buffer)
{
 unsigned long value = (*buffer)[0];
 value = value << 8;
 value += (*buffer)[1];
 *buffer += 2;
 return value;
}

variable_types:
buffer
unsigned char **

variable_types:
value
unsigned long


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

result = a2;
**(_BYTE **)a1 = BYTE1(a2);
*(_BYTE *)(*(_QWORD *)a1 + 1LL) = a2;
*(_QWORD *)a1 += 2LL;
return result;
}

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

result = a2;
**(_BYTE **)a1 = BYTE1(a2);
*(_BYTE *)(*(_QWORD *)a1 + 1LL) = a2;
*(_QWORD *)a1 += 2LL;
return result;
}

original_code:
void p_put16bits(UCHAR ** buffer, USHORT value)
{
 (*buffer)[0] = (value & 0xFF00) >> 8;
 (*buffer)[1] = value & 0xFF;
 *buffer += 2;
}

canonical_original_code:
void p_put16bits(unsigned char **buffer, unsigned short value)
{
 (*buffer)[0] = (value & 0xFF00) >> 8;
 (*buffer)[1] = value & 0xFF;
 *buffer += 2;
}

variable_types:
value
unsigned short


original_code:
int p_decode_domain(char *domain, const UCHAR ** buffer, size_t size)
{
 const UCHAR *p = *buffer;
 const UCHAR *beg = p;
 size_t i = 0;
 size_t len = 0;
 while (*p != '\0') {
  if (i != 0) {
   domain[i] = '.';
   i += 1;
  }
  len = *p;
  p += 1;
  if (i + len >= 256 || i + len >= size) {
   return -1;
  }
  memcpy(domain + i, p, len);
  p += len;
  i += len;
 }
 domain[i] = '\0';
 *buffer = p + 1;
 return (*buffer) - beg;
}

canonical_original_code:
int p_decode_domain(char *domain, unsigned char **buffer, unsigned long size)
{
 unsigned char *p = *buffer;
 unsigned char *beg = p;
 unsigned long i = 0;
 unsigned long len = 0;
 while (*p != '\0') {
  if (i != 0) {
   domain[i] = '.';
   i += 1;
  }
  len = *p;
  p += 1;
  if (i + len >= 256 || i + len >= size) {
   return -1;
  }
  memcpy(domain + i, p, len);
  p += len;
  i += len;
 }
 domain[i] = '\0';
 *buffer = p + 1;
 return (*buffer) - beg;
}

variable_types:
domain
char *

variable_types:
size
unsigned long

variable_types:
p
unsigned char *

variable_types:
beg
unsigned char *

variable_types:
i
unsigned long

variable_types:
len
unsigned long


original_code:
int p_decode_header(DNS_MSG * msg, const UCHAR ** buffer)
{
 size_t fields;
 msg->id = p_get16bits(buffer);
 fields = p_get16bits(buffer);
 msg->qr = (fields & QR_MASK) >> 15;
 msg->opcode = (fields & OPCODE_MASK) >> 11;
 msg->aa = (fields & AA_MASK) >> 10;
 msg->tc = (fields & TC_MASK) >> 9;
 msg->rd = (fields & RD_MASK) >> 8;
 msg->ra = (fields & RA_MASK) >> 7;
 msg->rcode = (fields & RCODE_MASK) >> 0;
 msg->qdCount = p_get16bits(buffer);
 msg->anCount = p_get16bits(buffer);
 msg->nsCount = p_get16bits(buffer);
 msg->arCount = p_get16bits(buffer);
 return 12;
}

canonical_original_code:
int p_decode_header(struct DNS_MSG *msg, unsigned char **buffer)
{
 unsigned long fields;
 msg->id = p_get16bits(buffer);
 fields = p_get16bits(buffer);
 msg->qr = (fields & QR_MASK) >> 15;
 msg->opcode = (fields & OPCODE_MASK) >> 11;
 msg->aa = (fields & AA_MASK) >> 10;
 msg->tc = (fields & TC_MASK) >> 9;
 msg->rd = (fields & RD_MASK) >> 8;
 msg->ra = (fields & RA_MASK) >> 7;
 msg->rcode = (fields & RCODE_MASK) >> 0;
 msg->qdCount = p_get16bits(buffer);
 msg->anCount = p_get16bits(buffer);
 msg->nsCount = p_get16bits(buffer);
 msg->arCount = p_get16bits(buffer);
 return 12;
}

variable_types: struct DNS_MSG { unsigned short id; unsigned short qr; unsigned short opcode; unsigned short aa; unsigned short tc; unsigned short rd; unsigned short ra; unsigned short rcode; unsigned short qdCount; unsigned short anCount; unsigned short nsCount; unsigned short arCount; struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; } question; struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; } rd_data; } answer[16]; char qName_buffer[256]; } *

variable_types:
fields
unsigned long

user_defined_types: struct DNS_MSG { unsigned short id; unsigned short qr; unsigned short opcode; unsigned short aa; unsigned short tc; unsigned short rd; unsigned short ra; unsigned short rcode; unsigned short qdCount; unsigned short anCount; unsigned short nsCount; unsigned short arCount; struct DNS_Q question; struct DNS_RR answer[16]; char qName_buffer[256]; }

user_defined_types: struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD rd_data; }


decompiled_code:
__int64 __fastcall p_encode_header(unsigned __int16 *a1, __int64 a2)
{
p_put16bits(a2, *a1);
p_put16bits(a2, a1[7] & 0xF | (unsigned __int16)(a1[1] << 15));
p_put16bits(a2, a1[8]);
p_put16bits(a2, a1[9]);
p_put16bits(a2, a1[10]);
return p_put16bits(a2, a1[11]);
}

original_code:
void p_encode_header(DNS_MSG * msg, UCHAR ** buffer)
{
 size_t fields = 0;
 p_put16bits(buffer, msg->id);
 fields |= (msg->qr << 15) & QR_MASK;
 fields |= (msg->rcode << 0) & RCODE_MASK;
 p_put16bits(buffer, fields);
 p_put16bits(buffer, msg->qdCount);
 p_put16bits(buffer, msg->anCount);
 p_put16bits(buffer, msg->nsCount);
 p_put16bits(buffer, msg->arCount);
}

canonical_original_code:
void p_encode_header(struct DNS_MSG *msg, unsigned char **buffer)
{
 unsigned long fields = 0;
 p_put16bits(buffer, msg->id);
 fields |= (msg->qr << 15) & QR_MASK;
 fields |= (msg->rcode << 0) & RCODE_MASK;
 p_put16bits(buffer, fields);
 p_put16bits(buffer, msg->qdCount);
 p_put16bits(buffer, msg->anCount);
 p_put16bits(buffer, msg->nsCount);
 p_put16bits(buffer, msg->arCount);
}

user_defined_types: struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; }

user_defined_types: union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; }


original_code:
int p_decode_query(DNS_MSG * msg, const UCHAR * buffer, int size)
{
 ssize_t n;
 if ((n = p_decode_header(msg, &buffer)) < 0) {
  return 0;
 }
 size -= n;
 if (msg->anCount != 0) {
  return -1;
 }
 if (msg->nsCount != 0) {
  return -2;
 }
 if (msg->qdCount != 1) {
  return -3;
 }
 n = p_decode_domain(msg->qName_buffer, &buffer, size);
 if (n < 0) {
  return -4;
 }
 size -= n;
 if (size < 4) {
  return -5;
 }
 int qType = p_get16bits(&buffer);
 int qClass = p_get16bits(&buffer);
 msg->question.qName = msg->qName_buffer;
 msg->question.qType = qType;
 msg->question.qClass = qClass;
 return 1;
}

canonical_original_code:
int p_decode_query(struct DNS_MSG *msg, unsigned char *buffer, int size)
{
 long n;
 if ((n = p_decode_header(msg, &buffer)) < 0) {
  return 0;
 }
 size -= n;
 if (msg->anCount != 0) {
  return -1;
 }
 if (msg->nsCount != 0) {
  return -2;
 }
 if (msg->qdCount != 1) {
  return -3;
 }
 n = p_decode_domain(msg->qName_buffer, &buffer, size);
 if (n < 0) {
  return -4;
 }
 size -= n;
 if (size < 4) {
  return -5;
 }
 int qType = p_get16bits(&buffer);
 int qClass = p_get16bits(&buffer);
 msg->question.qName = msg->qName_buffer;
 msg->question.qType = qType;
 msg->question.qClass = qClass;
 return 1;
}

variable_types:
buffer
unsigned char *

variable_types: size int

variable_types: n long

variable_types: qType int

variable_types: qClass int


decompiled_code:
char *__fastcall p_get_domain_from_srv_record(char *haystack)
{
char *v1; // rax
char *result; // rax
char *v3; // rdx

v1 = strstr(haystack, "._tcp.");
if ( v1 )
return v1 + 6;
v3 = strstr(haystack, "._udp.");
result = v3 + 6;
if ( !v3 )
result = haystack;
return result;
}

canonical_decompiled_code:
char *__fastcall func10(char *haystack)
{
char *v1; // rax
char *result; // rax
char *v3; // rdx

v1 = strstr(haystack, "._tcp.");
if ( v1 )
return v1 + 6;
v3 = strstr(haystack, "._udp.");
result = v3 + 6;
if ( !v3 )
result = haystack;
return result;
}

original_code:
char *p_get_domain_from_srv_record(char *name)
{
 char *domain = ((void *)0);
 if ((domain = strstr(name, "._tcp.")) != ((void *)0)) {
  domain += 6;
  return domain;
 } else if ((domain = strstr(name, "._udp.")) != ((void *)0)) {
  domain += 6;
  return domain;
 }
 return name;
}

variable_types:
name
char *

return_type: char *


decompiled_code:
unsigned __int64 __fastcall p_put_srv(__int64 a1, _QWORD *a2, __int64 a3, const char *a4)
{
unsigned __int64 result; // rax
unsigned __int8 *v6; // [rsp+8h] [rbp-20h] BYREF

v6 = (unsigned __int8 *)(a3 + 4);
*(_QWORD *)a1 = *a2;
*(_WORD *)(a1 + 8) = 33;
*(_WORD *)(a1 + 10) = 1;
*(_WORD *)(a1 + 12) = 300;
*(_DWORD *)(a1 + 14) = (unsigned __int16)(strlen(a4) + 8);
*(_WORD *)(a1 + 18) = 0;
result = p_get16bits(&v6);
*(_WORD *)(a1 + 20) = result;
*(_QWORD *)(a1 + 24) = a4;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, _QWORD *a2, __int64 a3, const char *a4)
{
unsigned __int64 result; // rax
unsigned __int8 *v6; // [rsp+8h] [rbp-20h] BYREF

v6 = (unsigned __int8 *)(a3 + 4);
*(_QWORD *)a1 = *a2;
*(_WORD *)(a1 + 8) = 33;
*(_WORD *)(a1 + 10) = 1;
*(_WORD *)(a1 + 12) = 300;
*(_DWORD *)(a1 + 14) = (unsigned __int16)(strlen(a4) + 8);
*(_WORD *)(a1 + 18) = 0;
result = func1(&v6);
*(_WORD *)(a1 + 20) = result;
*(_QWORD *)(a1 + 24) = a4;
return result;
}

original_code:
void p_put_srv(DNS_RR * rr, DNS_Q * qu, UCHAR * p, char *name)
{
 const UCHAR *p_port = p + 4;
 rr->name = qu->qName;
 rr->type = SRV_Resource_RecordType;
 rr->class = 1;
 rr->ttl = 300;
 rr->rd_length = 6 + strlen(name) + 2;
 rr->rd_data.srv_record.priority = 0;
 rr->rd_data.srv_record.weight = 0;
 rr->rd_data.srv_record.port = p_get16bits(&p_port);
 rr->rd_data.srv_record.target = name;
}

canonical_original_code:
void p_put_srv(struct DNS_RR *rr, struct DNS_Q *qu, unsigned char *p, char *name)
{
 unsigned char *p_port = p + 4;
 rr->name = qu->qName;
 rr->type = SRV_Resource_RecordType;
 rr->class = 1;
 rr->ttl = 300;
 rr->rd_length = 6 + strlen(name) + 2;
 rr->rd_data.srv_record.priority = 0;
 rr->rd_data.srv_record.weight = 0;
 rr->rd_data.srv_record.port = p_get16bits(&p_port);
 rr->rd_data.srv_record.target = name;
}

variable_types: struct DNS_RR { char *name; unsigned short type; unsigned short class; unsigned short ttl; unsigned short rd_length; union DNS_RD { struct { char *txt_data; } txt_record; struct { char *name; } name_server_record; struct { char *name; } cname_record; struct { char *name; } ptr_record; struct { unsigned int preference; char *exchange; } mx_record; struct { unsigned char addr[4]; } x_record; struct { unsigned short priority; unsigned short weight; unsigned short port; char *target; } srv_record; } rd_data; } *

variable_types: struct DNS_Q { char *qName; unsigned int qType; unsigned int qClass; } *


original_code:
void p_put_addr(DNS_RR * rr, DNS_Q * qu, UCHAR * p, char *name)
{
 rr->name = name;
 rr->class = qu->qClass;
 rr->ttl = 300;
 rr->rd_length = 4;
 rr->type = A_Resource_RecordType;
 memcpy(rr->rd_data.x_record.addr, p, 4);
}

canonical_original_code:
void p_put_addr(struct DNS_RR *rr, struct DNS_Q *qu, unsigned char *p, char *name)
{
 rr->name = name;
 rr->class = qu->qClass;
 rr->ttl = 300;
 rr->rd_length = 4;
 rr->type = A_Resource_RecordType;
 memcpy(rr->rd_data.x_record.addr, p, 4);
}


original_code:
void p_reply_msg(DNS_MSG * msg, UCHAR * nodes_compact_list,
   int nodes_compact_size)
{
 DNS_Q *qu = &msg->question;
 UCHAR *p = nodes_compact_list;
 char *domain = ((void *)0);
 int i = 0, j = 0;
 p_prepare_msg(msg, nodes_compact_size / 6);
 switch (msg->question.qType) {
 case SRV_Resource_RecordType:
  msg->arCount = msg->anCount;
  domain = p_get_domain_from_srv_record(qu->qName);
  p = nodes_compact_list;
  for (i = 0; i < msg->anCount; i++) {
   p_put_srv(&msg->answer[i], qu, p, domain);
   p += 6;
  }
  p = nodes_compact_list;
  for (j = i; j < msg->anCount + msg->arCount; j++) {
   p_put_addr(&msg->answer[j], qu, p, domain);
   p += 6;
  }
  break;
 default:
  for (i = 0; i < msg->anCount; i++) {
   p_put_addr(&msg->answer[i], qu, p, qu->qName);
   p += 6;
  }
 }
}

canonical_original_code:
void p_reply_msg(struct DNS_MSG *msg, unsigned char *nodes_compact_list, int nodes_compact_size)
{
 struct DNS_Q *qu = &msg->question;
 unsigned char *p = nodes_compact_list;
 char *domain = ((void *)0);
 int i = 0; int j = 0;
 p_prepare_msg(msg, nodes_compact_size / 6);
 switch (msg->question.qType) {
 case SRV_Resource_RecordType:
  msg->arCount = msg->anCount;
  domain = p_get_domain_from_srv_record(qu->qName);
  p = nodes_compact_list;
  for (i = 0; i < msg->anCount; i++) {
   p_put_srv(&msg->answer[i], qu, p, domain);
   p += 6;
  }
  p = nodes_compact_list;
  for (j = i; j < msg->anCount + msg->arCount; j++) {
   p_put_addr(&msg->answer[j], qu, p, domain);
   p += 6;
  }
  break;
 default:
  for (i = 0; i < msg->anCount; i++) {
   p_put_addr(&msg->answer[i], qu, p, qu->qName);
   p += 6;
  }
 }
}

variable_types: i int

variable_types: j int


original_code:
void p_reset_msg(DNS_MSG * msg)
{
 DNS_RR *rr = msg->answer;
 DNS_Q *qu = &msg->question;
 p_prepare_msg(msg, 0);
 rr = msg->answer;
 rr->name = qu->qName;
 rr->class = qu->qClass;
 rr->ttl = 300;
 rr->type = 0;
 rr->rd_length = 0;
}

canonical_original_code:
void p_reset_msg(struct DNS_MSG *msg)
{
 struct DNS_RR *rr = msg->answer;
 struct DNS_Q *qu = &msg->question;
 p_prepare_msg(msg, 0);
 rr = msg->answer;
 rr->name = qu->qName;
 rr->class = qu->qClass;
 rr->ttl = 300;
 rr->type = 0;
 rr->rd_length = 0;
}


original_code:
ITEM *node_put(void)
{
 TCP_NODE *n = (TCP_NODE *) myalloc(sizeof(TCP_NODE));
 ITEM *thisnode = ((void *)0);
 n->c_addrlen = sizeof(IP);
 memset((char *)&n->c_addr, '\0', n->c_addrlen);
 memset(n->recv_buf, '\0', 1024);
 n->recv_size = 0;
 n->pipeline = 1;
 n->keepalive = 0;
 n->response = list_init();
 mutex_block(_main->work->tcp_node);
 thisnode = list_put(_main->node, n);
 mutex_unblock(_main->work->tcp_node);
 if (thisnode == ((void *)0)) {
  list_free(n->response);
  myfree(n);
 }
 return thisnode;
}

canonical_original_code:
struct obj_item *node_put()
{
 struct TCP_NODE *n = (TCP_NODE *) myalloc(sizeof(TCP_NODE));
 struct obj_item *thisnode = ((void *)0);
 n->c_addrlen = sizeof(IP);
 memset((char *)&n->c_addr, '\0', n->c_addrlen);
 memset(n->recv_buf, '\0', 1024);
 n->recv_size = 0;
 n->pipeline = 1;
 n->keepalive = 0;
 n->response = list_init();
 mutex_block(_main->work->tcp_node);
 thisnode = list_put(_main->node, n);
 mutex_unblock(_main->work->tcp_node);
 if (thisnode == ((void *)0)) {
  list_free(n->response);
  myfree(n);
 }
 return thisnode;
}

variable_types: struct TCP_NODE { int connfd; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } c_addr; unsigned int c_addrlen; char recv_buf[1024]; long recv_size; int keepalive; int pipeline; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *response; } *

user_defined_types: struct TCP_NODE { int connfd; struct sockaddr_in6 c_addr; unsigned int c_addrlen; char recv_buf[1024]; long recv_size; int keepalive; int pipeline; struct obj_list *response; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
int __fastcall node_disconnect(int fd)
{
int result; // eax
int *v2; // rax
char *v3; // rax

if ( epoll_ctl(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL), 2, fd, 0LL) == -1 && status == 1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
info(log, 0LL, v3);
fail("node_shutdown: epoll_ctl() failed");
}
result = close(fd);
if ( result )
result = info(log, 0LL, "close() failed");
return result;
}

canonical_decompiled_code:
int __fastcall func2(int fd)
{
int result; // eax
int *v2; // rax
char *v3; // rax

if ( epoll_ctl(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL), 2, fd, 0LL) == -1 && status == 1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
info(log, 0LL, v3);
fail("node_shutdown: epoll_ctl() failed");
}
result = close(fd);
if ( result )
result = info(log, 0LL, "close() failed");
return result;
}

original_code:
void node_disconnect(int connfd)
{
 if (epoll_ctl(_main->tcp->epollfd, 2, connfd, ((void *)0)) == -1) {
  if (status == 1) {
   info(_log, ((void *)0), strerror((*__errno_location ())));
   fail("node_shutdown: epoll_ctl() failed");
  }
 }
 if (close(connfd) != 0) {
  info(_log, ((void *)0), "close() failed");
 }
}

variable_types: connfd int


decompiled_code:
__int64 __fastcall node_shutdown(__int64 a1)
{
__int64 v1; // rbx

v1 = list_value();
mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 88LL));
node_disconnect(*(_DWORD *)v1);
resp_free(*(_QWORD *)(v1 + 1080));
myfree(v1);
list_del(*((_QWORD *)main + 4), a1);
return mutex_unblock(*(_QWORD *)(*((_QWORD *)main + 3) + 88LL));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx

v1 = list_value();
mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 88LL));
func2(*(_DWORD *)v1);
resp_free(*(_QWORD *)(v1 + 1080));
myfree(v1);
list_del(*((_QWORD *)main + 4), a1);
return mutex_unblock(*(_QWORD *)(*((_QWORD *)main + 3) + 88LL));
}

original_code:
void node_shutdown(ITEM * thisnode)
{
 TCP_NODE *n = list_value(thisnode);
 mutex_block(_main->work->tcp_node);
 node_disconnect(n->connfd);
 resp_free(n->response);
 myfree(n);
 list_del(_main->node, thisnode);
 mutex_unblock(_main->work->tcp_node);
}

canonical_original_code:
void node_shutdown(struct obj_item *thisnode)
{
 struct TCP_NODE *n = list_value(thisnode);
 mutex_block(_main->work->tcp_node);
 node_disconnect(n->connfd);
 resp_free(n->response);
 myfree(n);
 list_del(_main->node, thisnode);
 mutex_unblock(_main->work->tcp_node);
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
void __fastcall node_status(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 1076) = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 1076) = a2;
}

original_code:
void node_status(TCP_NODE * n, int status)
{
 n->pipeline = status;
}

canonical_original_code:
void node_status(struct TCP_NODE *n, int status)
{
 n->pipeline = status;
}

variable_types: status int

user_defined_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; }


decompiled_code:
__int64 __fastcall node_clearRecvBuf(_QWORD *a1)
{
__int64 result; // rax

*(_QWORD *)((char *)a1 + 36) = 0LL;
*(_QWORD *)((char *)a1 + 1052) = 0LL;
result = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 44) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 44) & 0xFFFFFFF8) + 1060) >> 3));
a1[133] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 result; // rax

*(_QWORD *)((char *)a1 + 36) = 0LL;
*(_QWORD *)((char *)a1 + 1052) = 0LL;
result = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 44) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 44) & 0xFFFFFFF8) + 1060) >> 3));
a1[133] = 0LL;
return result;
}

original_code:
void node_clearRecvBuf(TCP_NODE * n)
{
 memset(n->recv_buf, '\0', 1024);
 n->recv_size = 0;
}

canonical_original_code:
void node_clearRecvBuf(struct TCP_NODE *n)
{
 memset(n->recv_buf, '\0', 1024);
 n->recv_size = 0;
}


decompiled_code:
size_t __fastcall node_appendBuffer(__int64 a1, const void *a2, signed __int64 a3)
{
size_t v3; // rbx
size_t result; // rax

v3 = a3;
result = *(_QWORD *)(a1 + 1064);
if ( (__int64)(1023 - result) <= a3 )
v3 = 1023 - result;
if ( v3 )
{
memcpy((void *)(a1 + result + 36), a2, v3);
result = *(_QWORD *)(a1 + 1064) + v3;
*(_QWORD *)(a1 + 1064) = result;
*(_BYTE *)(a1 + result + 36) = 0;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, const void *a2, signed __int64 a3)
{
size_t v3; // rbx
size_t result; // rax

v3 = a3;
result = *(_QWORD *)(a1 + 1064);
if ( (__int64)(1023 - result) <= a3 )
v3 = 1023 - result;
if ( v3 )
{
memcpy((void *)(a1 + result + 36), a2, v3);
result = *(_QWORD *)(a1 + 1064) + v3;
*(_QWORD *)(a1 + 1064) = result;
*(_BYTE *)(a1 + result + 36) = 0;
}
return result;
}

original_code:
ssize_t node_appendBuffer(TCP_NODE * n, char *buffer, ssize_t bytes)
{
 char *p = n->recv_buf + n->recv_size;
 ssize_t buf_free = 1023 - n->recv_size;
 ssize_t buf_copy = (bytes > buf_free) ? buf_free : bytes;
 if (buf_copy == 0) {
  return n->recv_size;
 }
 memcpy(p, buffer, buf_copy);
 n->recv_size += buf_copy;
 n->recv_buf[n->recv_size] = '\0';
 return n->recv_size;
}

canonical_original_code:
long node_appendBuffer(struct TCP_NODE *n, char *buffer, long bytes)
{
 char *p = n->recv_buf + n->recv_size;
 long buf_free = 1023 - n->recv_size;
 long buf_copy = (bytes > buf_free) ? buf_free : bytes;
 if (buf_copy == 0) {
  return n->recv_size;
 }
 memcpy(p, buffer, buf_copy);
 n->recv_size += buf_copy;
 n->recv_buf[n->recv_size] = '\0';
 return n->recv_size;
}

variable_types:
buffer
char *

variable_types: bytes long

variable_types:
p
char *


decompiled_code:
__int64 node_init()
{
return list_init();
}

canonical_decompiled_code:
__int64 func0()
{
return list_init();
}

original_code:
LIST *node_init(void)
{
 return list_init();
}

canonical_original_code:
struct obj_list *node_init()
{
 return list_init();
}

return_type: struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *


decompiled_code:
__int64 node_free()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rbx

while ( 1 )
{
v1 = list_start(*((_QWORD *)main + 4));
v2 = v1;
if ( !v1 )
break;
v0 = list_value(v1);
node_status(v0, 5);
node_shutdown(v2);
}
return list_free(*((_QWORD *)main + 4));
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rbx

while ( 1 )
{
v1 = list_start(*((_QWORD *)main + 4));
v2 = v1;
if ( !v1 )
break;
v0 = list_value(v1);
func4(v0, 5);
func3(v2);
}
return list_free(*((_QWORD *)main + 4));
}

original_code:
void node_free(void)
{
 ITEM *i = ((void *)0);
 TCP_NODE *n = ((void *)0);
 while ((i = list_start(_main->node)) != ((void *)0)) {
  n = list_value(i);
  node_status(n, 5);
  node_shutdown(i);
 }
 list_free(_main->node);
}

canonical_original_code:
void node_free()
{
 struct obj_item *i = ((void *)0);
 struct TCP_NODE *n = ((void *)0);
 while ((i = list_start(_main->node)) != ((void *)0)) {
  n = list_value(i);
  node_status(n, 5);
  node_shutdown(i);
 }
 list_free(_main->node);
}


decompiled_code:
_QWORD *cache_init()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)myalloc(16LL);
*v0 = list_init();
v0[1] = hash_init(51LL);
return v0;
}

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

v0 = (_QWORD *)myalloc(16LL);
*v0 = list_init();
v0[1] = hash_init(51LL);
return v0;
}

original_code:
CACHE *cache_init(void)
{
 CACHE *cache = (CACHE *) myalloc(sizeof(CACHE));
 cache->list = list_init();
 cache->hash = hash_init(50 + 1);
 return cache;
}

canonical_original_code:
struct obj_cache *cache_init()
{
 struct obj_cache *cache = (CACHE *) myalloc(sizeof(CACHE));
 cache->list = list_init();
 cache->hash = hash_init(50 + 1);
 return cache;
}

variable_types: struct obj_cache { struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

user_defined_types: struct obj_cache { struct obj_list *list; struct HASH *hash; }


decompiled_code:
__int64 __fastcall cache_find(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), a1, 20LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), a1, 20LL);
}

original_code:
TARGET_C *cache_find(UCHAR * target_id)
{
 return hash_get(_main->cache->hash, target_id, 20);
}

canonical_original_code:
struct TARGET_C *cache_find(unsigned char *target_id)
{
 return hash_get(_main->cache->hash, target_id, 20);
}

return_type: struct TARGET_C { unsigned char target[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; long lifetime; long refresh; } *

user_defined_types: struct TARGET_C { unsigned char target[20]; struct obj_list *list; struct HASH *hash; long lifetime; long refresh; }


original_code:
int cache_compact_list(UCHAR * nodes_compact_list, UCHAR * target_id)
{
 UCHAR *p = nodes_compact_list;
 NODE_C *node_c = ((void *)0);
 TARGET_C *target = ((void *)0);
 ITEM *item = ((void *)0);
 int j = 0;
 int size = 0;
 if ((target = cache_find(target_id)) == ((void *)0)) {
  return 0;
 }
 item = list_start(target->list);
 while (item != ((void *)0) && j < 8) {
  node_c = list_value(item);
  memcpy(p, node_c->pair, 6);
  p += 6;
  size += 6;
  item = list_next(item);
  j++;
 }
 time_add_30_min(&target->lifetime);
 return size;
}

canonical_original_code:
int cache_compact_list(unsigned char *nodes_compact_list, unsigned char *target_id)
{
 unsigned char *p = nodes_compact_list;
 struct NODE_C *node_c = ((void *)0);
 struct TARGET_C *target = ((void *)0);
 struct obj_item *item = ((void *)0);
 int j = 0;
 int size = 0;
 if ((target = cache_find(target_id)) == ((void *)0)) {
  return 0;
 }
 item = list_start(target->list);
 while (item != ((void *)0) && j < 8) {
  node_c = list_value(item);
  memcpy(p, node_c->pair, 6);
  p += 6;
  size += 6;
  item = list_next(item);
  j++;
 }
 time_add_30_min(&target->lifetime);
 return size;
}

variable_types:
p
unsigned char *

variable_types: struct NODE_C { unsigned char pair[6]; long eol; } *

variable_types: struct TARGET_C { unsigned char target[20]; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; long lifetime; long refresh; } *

variable_types: size int


decompiled_code:
__int64 __fastcall tgt_c_free(__int64 a1)
{
list_clear(*(_QWORD *)(a1 + 24));
list_free(*(_QWORD *)(a1 + 24));
hash_free(*(_QWORD *)(a1 + 32));
return myfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
list_clear(*(_QWORD *)(a1 + 24));
list_free(*(_QWORD *)(a1 + 24));
hash_free(*(_QWORD *)(a1 + 32));
return myfree(a1);
}

original_code:
void tgt_c_free(TARGET_C * target)
{
 list_clear(target->list);
 list_free(target->list);
 hash_free(target->hash);
 myfree(target);
}

canonical_original_code:
void tgt_c_free(struct TARGET_C *target)
{
 list_clear(target->list);
 list_free(target->list);
 hash_free(target->hash);
 myfree(target);
}

user_defined_types: struct PAIR { unsigned char *key; long size; void *value; }


decompiled_code:
__int64 __fastcall cache_del(__int64 a1)
{
__int64 v1; // rbx

v1 = list_value(a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v1, 20LL);
list_del(**((_QWORD **)main + 5), a1);
return tgt_c_free(v1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx

v1 = list_value(a1);
hash_del(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL), v1, 20LL);
list_del(**((_QWORD **)main + 5), a1);
return func3(v1);
}

original_code:
void cache_del(ITEM * i)
{
 TARGET_C *target = list_value(i);
 hash_del(_main->cache->hash, target->target, 20);
 list_del(_main->cache->list, i);
 tgt_c_free(target);
}

canonical_original_code:
void cache_del(struct obj_item *i)
{
 struct TARGET_C *target = list_value(i);
 hash_del(_main->cache->hash, target->target, 20);
 list_del(_main->cache->list, i);
 tgt_c_free(target);
}


decompiled_code:
__int64 *cache_clean()
{
__int64 *result; // rax
__int64 i; // rdi

result = (__int64 *)**((_QWORD **)main + 5);
for ( i = *result; *result; i = *result )
{
cache_del(i);
result = (__int64 *)**((_QWORD **)main + 5);
}
return result;
}

canonical_decompiled_code:
__int64 *func5()
{
__int64 *result; // rax
__int64 i; // rdi

result = (__int64 *)**((_QWORD **)main + 5);
for ( i = *result; *result; i = *result )
{
func4(i);
result = (__int64 *)**((_QWORD **)main + 5);
}
return result;
}

original_code:
void cache_clean(void)
{
 while (_main->cache->list->item != ((void *)0)) {
  cache_del(_main->cache->list->item);
 }
}

canonical_original_code:
void cache_clean()
{
 while (_main->cache->list->item != ((void *)0)) {
  cache_del(_main->cache->list->item);
 }
}


decompiled_code:
__int64 cache_free()
{
cache_clean();
list_clear(**((_QWORD **)main + 5));
list_free(**((_QWORD **)main + 5));
hash_free(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL));
return myfree(*((_QWORD *)main + 5));
}

canonical_decompiled_code:
__int64 func6()
{
func5();
list_clear(**((_QWORD **)main + 5));
list_free(**((_QWORD **)main + 5));
hash_free(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL));
return myfree(*((_QWORD *)main + 5));
}

original_code:
void cache_free(void)
{
 cache_clean();
 list_clear(_main->cache->list);
 list_free(_main->cache->list);
 hash_free(_main->cache->hash);
 myfree(_main->cache);
}

canonical_original_code:
void cache_free()
{
 cache_clean();
 list_clear(_main->cache->list);
 list_free(_main->cache->list);
 hash_free(_main->cache->hash);
 myfree(_main->cache);
}


decompiled_code:
__int64 __fastcall tgt_c_print(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
__int64 v3; // rax
_BYTE v4[24]; // [rsp+0h] [rbp-18h] BYREF

result = list_start(*(_QWORD *)(a1 + 24));
for ( i = result; result; i = result )
{
v3 = list_value(i);
ip_tuple_to_sin(v4, v3);
info(log, v4, " IP:");
result = list_next(i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
__int64 v3; // rax
_BYTE v4[24]; // [rsp+0h] [rbp-18h] BYREF

result = list_start(*(_QWORD *)(a1 + 24));
for ( i = result; result; i = result )
{
v3 = list_value(i);
ip_tuple_to_sin(v4, v3);
info(log, v4, " IP:");
result = list_next(i);
}
return result;
}

original_code:
void tgt_c_print(TARGET_C * target)
{
 ITEM *i = ((void *)0);
 NODE_C *node = ((void *)0);
 IP sin;
 i = list_start(target->list);
 while (i != ((void *)0)) {
  node = list_value(i);
  ip_tuple_to_sin(&sin, node->pair);
  info(_log, &sin, "  IP:");
  i = list_next(i);
 }
}

canonical_original_code:
void tgt_c_print(struct TARGET_C *target)
{
 struct obj_item *i = ((void *)0);
 struct NODE_C *node = ((void *)0);
 struct sockaddr_in sin;
 i = list_start(target->list);
 while (i != ((void *)0)) {
  node = list_value(i);
  ip_tuple_to_sin(&sin, node->pair);
  info(_log, &sin, "  IP:");
  i = list_next(i);
 }
}

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

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

user_defined_types: struct NODE_C { unsigned char pair[6]; long eol; }


decompiled_code:
__int64 cache_print()
{
__int64 result; // rax
__int64 i; // rbx
__int64 v2; // rbp
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = log_verbosely(log);
if ( !(_DWORD)result )
{
info(log, 0LL, "Cache renewal triggered:");
result = list_start(**((_QWORD **)main + 5));
for ( i = result; result; i = result )
{
v2 = list_value(i);
hex_hash_encode(v3, v2);
info(log, 0LL, " Target: %s", v3);
tgt_c_print(v2);
result = list_next(i);
}
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
__int64 i; // rbx
__int64 v2; // rbp
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = log_verbosely(log);
if ( !(_DWORD)result )
{
info(log, 0LL, "Cache renewal triggered:");
result = list_start(**((_QWORD **)main + 5));
for ( i = result; result; i = result )
{
v2 = list_value(i);
hex_hash_encode(v3, v2);
info(log, 0LL, " Target: %s", v3);
func8(v2);
result = list_next(i);
}
}
return result;
}

original_code:
void cache_print(void)
{
 ITEM *i = ((void *)0);
 TARGET_C *t = ((void *)0);
 char hex[2*20 +1];
 if (log_verbosely(_log)) {
  return;
 }
 info(_log, ((void *)0), "Cache renewal triggered:");
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  hex_hash_encode(hex, t->target);
  info(_log, ((void *)0), " Target: %s", hex);
  tgt_c_print(t);
  i = list_next(i);
 }
}

canonical_original_code:
void cache_print()
{
 struct obj_item *i = ((void *)0);
 struct TARGET_C *t = ((void *)0);
 char hex[-1];
 if (log_verbosely(_log)) {
  return;
 }
 info(_log, ((void *)0), "Cache renewal triggered:");
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  hex_hash_encode(hex, t->target);
  info(_log, ((void *)0), " Target: %s", hex);
  tgt_c_print(t);
  i = list_next(i);
 }
}

variable_types:
hex
char [-1]

user_defined_types: struct obj_list { struct obj_item *item; long size; }

user_defined_types: struct HASH { struct BUCKET *buckets; long size; }


decompiled_code:
__int64 __fastcall cache_renew(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // er14
__int64 v4; // rax
__int64 v5; // rbp

result = list_start(**((_QWORD **)main + 5));
if ( result )
{
v2 = result;
v3 = 0;
do
{
v4 = list_value(v2);
v5 = v4;
if ( *(_QWORD *)(v4 + 48) < a1 )
{
p2p_cron_lookup(v4, 4LL);
time_add_5_min_approx(v5 + 48);
v3 = 1;
}
result = list_next(v2);
v2 = result;
}
while ( result );
if ( v3 )
result = cache_print();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // er14
__int64 v4; // rax
__int64 v5; // rbp

result = list_start(**((_QWORD **)main + 5));
if ( result )
{
v2 = result;
v3 = 0;
do
{
v4 = list_value(v2);
v5 = v4;
if ( *(_QWORD *)(v4 + 48) < a1 )
{
p2p_cron_lookup(v4, 4LL);
time_add_5_min_approx(v5 + 48);
v3 = 1;
}
result = list_next(v2);
v2 = result;
}
while ( result );
if ( v3 )
result = func9();
}
return result;
}

original_code:
void cache_renew(time_t now)
{
 ITEM *i = ((void *)0);
 TARGET_C *t = ((void *)0);
 int changes = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  if (now > t->refresh) {
   p2p_cron_lookup(t->target, 4);
   time_add_5_min_approx(&t->refresh);
   changes = 1;
  }
  i = list_next(i);
 }
 if (changes) {
  cache_print();
 }
}

canonical_original_code:
void cache_renew(long now)
{
 struct obj_item *i = ((void *)0);
 struct TARGET_C *t = ((void *)0);
 int changes = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  t = list_value(i);
  if (now > t->refresh) {
   p2p_cron_lookup(t->target, 4);
   time_add_5_min_approx(&t->refresh);
   changes = 1;
  }
  i = list_next(i);
 }
 if (changes) {
  cache_print();
 }
}

variable_types: now long

variable_types: changes int

user_defined_types: struct BUCKET { struct PAIR *pairs; long size; }


decompiled_code:
__int64 __fastcall tgt_c_find(__int64 a1, __int64 a2)
{
return hash_get(*(_QWORD *)(a1 + 32), a2, 6LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
return hash_get(*(_QWORD *)(a1 + 32), a2, 6LL);
}

original_code:
ITEM *tgt_c_find(TARGET_C * target, UCHAR * pair)
{
 return hash_get(target->hash, pair, 6);
}

canonical_original_code:
struct obj_item *tgt_c_find(struct TARGET_C *target, unsigned char *pair)
{
 return hash_get(target->hash, pair, 6);
}

variable_types: struct TARGET_C { unsigned char target[20]; struct obj_list { struct obj_item *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; long lifetime; long refresh; } *

variable_types:
pair
unsigned char *

return_type: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


decompiled_code:
__int64 __fastcall node_c_free(__int64 a1)
{
return myfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return myfree(a1);
}

original_code:
void node_c_free(NODE_C * node_c)
{
 myfree(node_c);
}

canonical_original_code:
void node_c_free(struct NODE_C *node_c)
{
 myfree(node_c);
}


decompiled_code:
__int64 __fastcall tgt_c_del(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = list_value(a2);
hash_del(*(_QWORD *)(a1 + 32), v2, 6LL);
list_del(*(_QWORD *)(a1 + 24), a2);
return node_c_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = list_value(a2);
hash_del(*(_QWORD *)(a1 + 32), v2, 6LL);
list_del(*(_QWORD *)(a1 + 24), a2);
return func12(v2);
}

original_code:
void tgt_c_del(TARGET_C * target, ITEM * i)
{
 NODE_C *node_c = list_value(i);
 hash_del(target->hash, node_c->pair, 6);
 list_del(target->list, i);
 node_c_free(node_c);
}

canonical_original_code:
void tgt_c_del(struct TARGET_C *target, struct obj_item *i)
{
 struct NODE_C *node_c = list_value(i);
 hash_del(target->hash, node_c->pair, 6);
 list_del(target->list, i);
 node_c_free(node_c);
}

variable_types:
i
struct obj_item *


decompiled_code:
__int64 __fastcall tgt_c_expire(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp

result = list_start(*(_QWORD *)(a1 + 24));
v3 = result;
while ( v3 )
{
v4 = v3;
v3 = list_next(v3);
result = list_value(v4);
if ( *(_QWORD *)(result + 8) < a2 )
result = tgt_c_del(a1, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp

result = list_start(*(_QWORD *)(a1 + 24));
v3 = result;
while ( v3 )
{
v4 = v3;
v3 = list_next(v3);
result = list_value(v4);
if ( *(_QWORD *)(result + 8) < a2 )
result = func13(a1, v4);
}
return result;
}

original_code:
void tgt_c_expire(TARGET_C * target, time_t now)
{
 ITEM *i = ((void *)0);
 ITEM *n = ((void *)0);
 NODE_C *node = ((void *)0);
 i = list_start(target->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  node = list_value(i);
  if (now > node->eol) {
   tgt_c_del(target, i);
  }
  i = n;
 }
}

canonical_original_code:
void tgt_c_expire(struct TARGET_C *target, long now)
{
 struct obj_item *i = ((void *)0);
 struct obj_item *n = ((void *)0);
 struct NODE_C *node = ((void *)0);
 i = list_start(target->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  node = list_value(i);
  if (now > node->eol) {
   tgt_c_del(target, i);
  }
  i = n;
 }
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


decompiled_code:
__int64 __fastcall cache_expire(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rbp

result = list_start(**((_QWORD **)main + 5));
v2 = result;
while ( v2 )
{
v3 = v2;
v2 = list_next(v2);
v4 = list_value(v3);
result = tgt_c_expire(v4, a1);
if ( *(_QWORD *)(v4 + 40) < a1 )
result = cache_del(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rbp

result = list_start(**((_QWORD **)main + 5));
v2 = result;
while ( v2 )
{
v3 = v2;
v2 = list_next(v2);
v4 = list_value(v3);
result = func14(v4, a1);
if ( *(_QWORD *)(v4 + 40) < a1 )
result = func4(v3);
}
return result;
}

original_code:
void cache_expire(time_t now)
{
 ITEM *i = ((void *)0), *n = ((void *)0);
 TARGET_C *target = ((void *)0);
 int index = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  target = list_value(i);
  tgt_c_expire(target, now);
  if (now > target->lifetime) {
   cache_del(i);
  }
  i = n;
  index++;
 }
}

canonical_original_code:
void cache_expire(long now)
{
 struct obj_item *i = ((void *)0); struct obj_item *n = ((void *)0);
 struct TARGET_C *target = ((void *)0);
 int index = 0;
 i = list_start(_main->cache->list);
 while (i != ((void *)0)) {
  n = list_next(i);
  target = list_value(i);
  tgt_c_expire(target, now);
  if (now > target->lifetime) {
   cache_del(i);
  }
  i = n;
  index++;
 }
}

variable_types: index int


original_code:
void node_c_update(NODE_C * node_c, UCHAR * pair)
{
 memcpy(node_c->pair, pair, 6);
 time_add_30_min(&node_c->eol);
}

canonical_original_code:
void node_c_update(struct NODE_C *node_c, unsigned char *pair)
{
 memcpy(node_c->pair, pair, 6);
 time_add_30_min(&node_c->eol);
}