decompiled_code:
__int64 __fastcall http_get_header_val(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v6; // er13
unsigned int v7; // er13
__int64 v8; // rdi
int v9; // er13
const char *v10; // rsi
char s[5]; // [rsp+Bh] [rbp-24Dh] BYREF
char v13[32]; // [rsp+10h] [rbp-248h] BYREF
char s1[256]; // [rsp+30h] [rbp-228h] BYREF
char v15[296]; // [rsp+130h] [rbp-128h] BYREF

_isoc99_sscanf(a2, "HTTP/1.1 %s %s\r\n", s, v13);
v6 = strlen(s);
v7 = v6 + strlen(v13) + 12;
if ( !a3 )
return new_str(s);
v8 = v7;
if ( a1 < v7 )
return 0LL;
while ( 1 )
{
_isoc99_sscanf(a2 + v8, "%s", s1);
v9 = v7 + strlen(s1) + 1;
_isoc99_sscanf(a2 + v9, "%[^\r]", v15);
v10 = (const char *)str_cat(a3, ":");
if ( !strcmp(s1, v10) )
break;
v7 = v9 + strlen(v15) + 2;
v8 = (int)v7;
if ( (int)v7 > a1 )
return 0LL;
}
return new_str(v15);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v6; // er13
unsigned int v7; // er13
__int64 v8; // rdi
int v9; // er13
const char *v10; // rsi
char s[5]; // [rsp+Bh] [rbp-24Dh] BYREF
char v13[32]; // [rsp+10h] [rbp-248h] BYREF
char s1[256]; // [rsp+30h] [rbp-228h] BYREF
char v15[296]; // [rsp+130h] [rbp-128h] BYREF

_isoc99_sscanf(a2, "HTTP/1.1 %s %s\r\n", s, v13);
v6 = strlen(s);
v7 = v6 + strlen(v13) + 12;
if ( !a3 )
return new_str(s);
v8 = v7;
if ( a1 < v7 )
return 0LL;
while ( 1 )
{
_isoc99_sscanf(a2 + v8, "%s", s1);
v9 = v7 + strlen(s1) + 1;
_isoc99_sscanf(a2 + v9, "%[^\r]", v15);
v10 = (const char *)str_cat(a3, ":");
if ( !strcmp(s1, v10) )
break;
v7 = v9 + strlen(v15) + 2;
v8 = (int)v7;
if ( (int)v7 > a1 )
return 0LL;
}
return new_str(v15);
}

original_code:
char *http_get_header_val(const struct http_buf_data raw, const char *key) {
    int current;
    char statusCode[5];
    char statusMsg[20];
    struct http_map *res, *tmp;
    sscanf(raw.buf, "HTTP/1.1 %s %s\r\n", statusCode, statusMsg);
    current = strlen(statusCode) + strlen(statusMsg) + 12;
    if(key == ((void *)0)) {
        return new_str(statusCode);
    }
    while(current <= raw.len) {
        char tmp_key[256];
        char tmp_val[256];
        sscanf(raw.buf + current, "%s", tmp_key);
        current += strlen(tmp_key) + 1;
        sscanf(raw.buf + current, "%[^\r]", tmp_val);
        if(strcmp(tmp_key, str_cat(key, ":")) == 0) {
            return new_str(tmp_val);
        }
        current += strlen(tmp_val) + 2;
    }
    return ((void *)0);
}

canonical_original_code:
char *http_get_header_val(struct http_buf_data raw, char *key) {
    int current;
    char statusCode[5];
    char statusMsg[20];
    struct http_map *res; struct http_map *tmp;
    sscanf(raw.buf, "HTTP/1.1 %s %s\r\n", statusCode, statusMsg);
    current = strlen(statusCode) + strlen(statusMsg) + 12;
    if(key == ((void *)0)) {
        return new_str(statusCode);
    }
    while(current <= raw.len) {
        char tmp_key[256];
        char tmp_val[256];
        sscanf(raw.buf + current, "%s", tmp_key);
        current += strlen(tmp_key) + 1;
        sscanf(raw.buf + current, "%[^\r]", tmp_val);
        if(strcmp(tmp_key, str_cat(key, ":")) == 0) {
            return new_str(tmp_val);
        }
        current += strlen(tmp_val) + 2;
    }
    return ((void *)0);
}

variable_types: struct http_buf_data { unsigned long len; char *buf; }

variable_types:
key
char *

variable_types: current int

variable_types:
statusCode
char [5]

variable_types:
statusMsg
char [20]

variable_types: struct http_map { char *key; char *val; } *


original_code:
char *build_url(const char *url, const struct http_map map[], size_t mapsize) {
    char *get_url;
    char *ret;
    int i;
    if(map != ((void *)0)) {
        get_url = new_str("?");
        for(i = 0; i < mapsize; ++i) {
            get_url = str_cat(get_url, map[i].key);
            get_url = str_cat(get_url, "=");
            get_url = str_cat(get_url, g_uri_escape_string(map[i].val, ((void *)0), ((json_bool)1)));
            if(i + 1 != mapsize) {
                get_url = str_cat(get_url, "&");
            }
        }
        ret = str_cat(url, get_url);
    } else {
        ret = new_str(url);
    }
    return ret;
}

canonical_original_code:
char *build_url(char *url, struct http_map map[], unsigned long mapsize) {
    char *get_url;
    char *ret;
    int i;
    if(map != ((void *)0)) {
        get_url = new_str("?");
        for(i = 0; i < mapsize; ++i) {
            get_url = str_cat(get_url, map[i].key);
            get_url = str_cat(get_url, "=");
            get_url = str_cat(get_url, g_uri_escape_string(map[i].val, ((void *)0), ((int)1)));
            if(i + 1 != mapsize) {
                get_url = str_cat(get_url, "&");
            }
        }
        ret = str_cat(url, get_url);
    } else {
        ret = new_str(url);
    }
    return ret;
}

variable_types:
url
char *

variable_types: struct http_map { char *key; char *val; } []

variable_types:
mapsize
unsigned long

variable_types:
ret
char *

variable_types: i int

return_type: char *


decompiled_code:
time_t __fastcall o_establish_getcode(__int64 a1)
{
const char *v1; // rax
__int64 v3[8]; // [rsp+0h] [rbp-C8h] BYREF
char v4[136]; // [rsp+40h] [rbp-88h] BYREF

v3[0] = new_str("response_type");
v3[1] = *(_QWORD *)a1;
v3[2] = new_str("redirect_uri");
v3[3] = *(_QWORD *)(a1 + 24);
v3[4] = new_str("client_id");
v3[5] = *(_QWORD *)(a1 + 8);
v3[6] = new_str("scope");
v3[7] = new_str(**(_QWORD **)(a1 + 32));
v1 = (const char *)build_url("https://accounts.google.com/o/oauth2/auth", v3, 4LL);
fprintf(stdout, "Get and input the code from %s .\n", v1);
_isoc99_scanf("%127s", v4);
*(_QWORD *)(a1 + 40) = new_str(v4);
return time((time_t *)(a1 + 88));
}

canonical_decompiled_code:
time_t __fastcall func2(__int64 a1)
{
const char *v1; // rax
__int64 v3[8]; // [rsp+0h] [rbp-C8h] BYREF
char v4[136]; // [rsp+40h] [rbp-88h] BYREF

v3[0] = new_str("response_type");
v3[1] = *(_QWORD *)a1;
v3[2] = new_str("redirect_uri");
v3[3] = *(_QWORD *)(a1 + 24);
v3[4] = new_str("client_id");
v3[5] = *(_QWORD *)(a1 + 8);
v3[6] = new_str("scope");
v3[7] = new_str(**(_QWORD **)(a1 + 32));
v1 = (const char *)build_url("https://accounts.google.com/o/oauth2/auth", v3, 4LL);
fprintf(stdout, "Get and input the code from %s .\n", v1);
_isoc99_scanf("%127s", v4);
*(_QWORD *)(a1 + 40) = new_str(v4);
return time((time_t *)(a1 + 88));
}

original_code:
void o_establish_getcode(struct o_val_t *o_val) {
    struct http_map getmap[4];
    char code[128];
    int i;
    getmap[0].key = new_str("response_type");
    getmap[0].val = o_val -> response_type;
    getmap[1].key = new_str("redirect_uri");
    getmap[1].val = o_val -> redirect_uri;
    getmap[2].key = new_str("client_id");
    getmap[2].val = o_val -> client_id;
    getmap[3].key = new_str("scope");
    getmap[3].val = new_str(o_val -> scope[0]);
    for(i = 1; i < (sizeof(o_val -> scope)/sizeof(o_val -> scope[0])); ++i) {
        getmap[3].val = str_cat(getmap[3].val, " ");
        getmap[3].val = str_cat(getmap[3].val, o_val -> scope[i]);
    }
    fprintf(stdout, "Get and input the code from %s .\n", build_url("https://accounts.google.com/o/oauth2/auth", getmap, (sizeof(getmap)/sizeof(getmap[0]))));
    scanf("%127s", code);
    o_val -> code = new_str(code);
    time(&(o_val -> established_time));
}

variable_types: struct o_val_t { char *response_type; char *client_id; char *client_secret; char *redirect_uri; char **scope; char *code; char *grant_type; char *access_token; char *refresh_token; int expires_in; char *token_type; long established_time; } *

variable_types: struct http_map { char *key; char *val; } [4]

variable_types:
code
char [128]

return_type: void


main

canonical_name: main

repo: arunov/adix

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc != 1 )
{
init_shell_env(envp);
process_exec_jobs(argc, argv, (char *const *)envp);
exit(0);
}
clrscr(argc, argv, envp);
init_shell();
run_shell();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc != 1 )
{
func2(envp);
func18(argc, argv, (char *const *)envp);
exit(0);
}
clrscr(argc, argv, envp);
func17();
func14();
}

original_code:
int main(int argc, char* argv[]) {
 struct superblock* sb;
 int fd;
 struct sector { char contents[512]; }* disk;
 struct inode* ino;
 struct stat diskstat;
 if (argc != 2) {
  fprintf(stderr, "Usage: %s disk.img\n", argv[0]);
  return 0;
 }
 if (stat(argv[1], &diskstat) == -1) {
  fprintf(stderr, "%s: Unable to stat %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  fprintf(stderr, "%s: Unable to open %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 disk = mmap(((void *)0), diskstat.st_size, 0x1|0x2, 0x01, fd, 0);
 if (disk == ((void *) -1)) {
  fprintf(stderr, "%s: Unable to map %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 sb = (struct superblock*)&disk[0];
 sb->magic = 0x20363035;
 ino = (struct inode*)&disk[1];
 ino->refcount = 0x45444F4344414544;
 munmap(disk, diskstat.st_size);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct superblock *sb;
 int fd;
 struct sector *disk;
 struct inode *ino;
 struct stat diskstat;
 if (argc != 2) {
  fprintf(stderr, "Usage: %s disk.img\n", argv[0]);
  return 0;
 }
 if (stat(argv[1], &diskstat) == -1) {
  fprintf(stderr, "%s: Unable to stat %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  fprintf(stderr, "%s: Unable to open %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 disk = mmap(((void *)0), diskstat.st_size, 0x1|0x2, 0x01, fd, 0);
 if (disk == ((void *) -1)) {
  fprintf(stderr, "%s: Unable to map %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 sb = (struct superblock *)&disk[0];
 sb->magic = 0x20363035;
 ino = (struct inode *)&disk[1];
 ino->refcount = 0x45444F4344414544;
 munmap(disk, diskstat.st_size);
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct superblock { unsigned int magic; } *

variable_types: fd int

variable_types:
disk
struct sector { char contents[512]; } *

variable_types: struct inode { unsigned long refcount; } *

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

return_type: int

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


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

if ( argc > 1 )
{
v3 = argv + 1;
while ( 1 )
{
v4 = open(*v3, (int)argv, envp);
v5 = v4;
if ( v4 < 0 )
break;
++v3;
cat(v4);
close(v5);
if ( v3 == &argv[(unsigned int)(argc - 2) + 2] )
exit(0);
}
printf("cat: cannot open %s\n", *v3);
exit(0);
}
cat(0);
exit(0);
}

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

if ( argc > 1 )
{
v3 = argv + 1;
while ( 1 )
{
v4 = open(*v3, (int)argv, envp);
v5 = v4;
if ( v4 < 0 )
break;
++v3;
func0(v4);
close(v5);
if ( v3 == &argv[(unsigned int)(argc - 2) + 2] )
exit(0);
}
printf("cat: cannot open %s\n", *v3);
exit(0);
}
func0(0);
exit(0);
}

user_defined_types: struct superblock { unsigned int magic; }

user_defined_types: struct inode { unsigned long refcount; }

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
_QWORD *v6; // rax
__off_t v7; // rsi
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
struct stat v14; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
if ( (unsigned int)stat((char *)argv[1], &v14) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s: Unable to stat %s (%s)\n", *argv, argv[1], v9);
}
else
{
v4 = open(argv[1], 2);
v5 = v4;
if ( v4 == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s: Unable to open %s (%s)\n", *argv, argv[1], v11);
}
else
{
v6 = mmap(0LL, v14.st_size, 3, 1, v4, 0LL);
if ( v6 == (_QWORD *)-1LL )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "%s: Unable to map %s (%s)\n", *argv, argv[1], v13);
}
else
{
*(_DWORD *)v6 = 540422197;
v7 = v14.st_size;
v6[64] = 0x45444F4344414544LL;
munmap(v6, v7);
close(v5);
}
}
}
}
else
{
fprintf(stderr, "Usage: %s disk.img\n", *argv);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
_QWORD *v6; // rax
__off_t v7; // rsi
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
struct stat v14; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
if ( (unsigned int)func9((char *)argv[1], &v14) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s: Unable to stat %s (%s)\n", *argv, argv[1], v9);
}
else
{
v4 = open(argv[1], 2);
v5 = v4;
if ( v4 == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(stderr, "%s: Unable to open %s (%s)\n", *argv, argv[1], v11);
}
else
{
v6 = mmap(0LL, v14.st_size, 3, 1, v4, 0LL);
if ( v6 == (_QWORD *)-1LL )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "%s: Unable to map %s (%s)\n", *argv, argv[1], v13);
}
else
{
*(_DWORD *)v6 = 540422197;
v7 = v14.st_size;
v6[64] = 0x45444F4344414544LL;
munmap(v6, v7);
close(v5);
}
}
}
}
else
{
fprintf(stderr, "Usage: %s disk.img\n", *argv);
}
return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[15008]; // [rsp+8h] [rbp-3AA0h] BYREF

v4[10000] = 97;
v4[0] = 98;
func(v4, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[15008]; // [rsp+8h] [rbp-3AA0h] BYREF

v4[10000] = 97;
v4[0] = 98;
func1(v4, argv, envp);
return 0;
}


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

if ( argc <= 1 )
{
v7 = (const char *)get_env("pwd", envp);
if ( v7 )
{
ls(v7);
result = 0;
}
else
{
printf("No environemnt variable %s\n", "pwd");
result = -1;
}
}
else
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
ls(v5);
}
while ( v3 != v4 );
result = 0;
}
return result;
}

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

if ( argc <= 1 )
{
v7 = (const char *)get_env("pwd", envp);
if ( v7 )
{
func0(v7);
result = 0;
}
else
{
printf("No environemnt variable %s\n", "pwd");
result = -1;
}
}
else
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
func0(v5);
}
while ( v3 != v4 );
result = 0;
}
return result;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v4; // er12
struct rlimit v6; // [rsp+0h] [rbp-38h] BYREF

if ( argc == 1 )
goto LABEL_13;
if ( argc == 2 )
{
if ( !(unsigned int)str_equal(argv[1], "-a", envp) )
goto LABEL_4;
LABEL_13:
v4 = 0;
printallulimits();
return v4;
}
if ( argc != 3 )
{
LABEL_7:
v4 = 1;
printf("usage:\n%s [-a|[%s|%s|%s [<new-limit>]]]\n", *argv, res_flag[0], res_flag[1], res_flag[2]);
return v4;
}
LABEL_4:
v3 = 0LL;
while ( !(unsigned int)str_equal(argv[1], res_flag[v3], envp) )
{
if ( ++v3 == 3 )
goto LABEL_7;
}
if ( argc == 3 )
{
v4 = 0;
v6.rlim_cur = atoi(argv[2]);
if ( setrlimit((__rlimit_resource_t)v3, &v6) == -1 )
printf("setrlimit failed\n");
}
else
{
v4 = 0;
printulimit((__rlimit_resource_t)v3);
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v4; // er12
struct rlimit v6; // [rsp+0h] [rbp-38h] BYREF

if ( argc == 1 )
goto LABEL_13;
if ( argc == 2 )
{
if ( !(unsigned int)str_equal(argv[1], "-a", envp) )
goto LABEL_4;
LABEL_13:
v4 = 0;
func1();
return v4;
}
if ( argc != 3 )
{
LABEL_7:
v4 = 1;
printf("usage:\n%s [-a|[%s|%s|%s [<new-limit>]]]\n", *argv, res_flag[0], res_flag[1], res_flag[2]);
return v4;
}
LABEL_4:
v3 = 0LL;
while ( !(unsigned int)str_equal(argv[1], res_flag[v3], envp) )
{
if ( ++v3 == 3 )
goto LABEL_7;
}
if ( argc == 3 )
{
v4 = 0;
v6.rlim_cur = atoi(argv[2]);
if ( setrlimit((__rlimit_resource_t)v3, &v6) == -1 )
printf("setrlimit failed\n");
}
else
{
v4 = 0;
func0((__rlimit_resource_t)v3);
}
return v4;
}


repo: arut/htserve

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r12
int v4; // eax
int v6; // ebx
__int16 v7; // ax
int v8; // edx
const void *v9; // rcx
socklen_t v10; // er8
int v11; // eax
int v12; // ebp
int v13; // [rsp+0h] [rbp-44h] BYREF
pthread_t newthread; // [rsp+4h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+Ch] [rbp-38h] BYREF
__int64 optval[5]; // [rsp+1Ch] [rbp-28h] BYREF

v3 = 8888;
addr = 0LL;
v13 = 1;
addr.sa_family = 2;
optval[0] = 0LL;
optval[1] = 0LL;
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "p:t:d:h", &lopts, 0LL);
if ( v4 == -1 )
break;
if ( v4 == 112 )
{
v3 = atoi(_bss_start);
}
else if ( v4 > 112 )
{
if ( v4 != 116 )
return 1;
optval[0] = atoi(_bss_start);
}
else
{
if ( v4 != 100 )
{
if ( v4 == 104 )
print_usage();
return 1;
}
if ( chdir(_bss_start) )
{
perror("chdir");
return 1;
}
}
}
signal(13, (__sighandler_t)1);
v6 = socket(2, 1, 0);
if ( v6 == -1 )
{
perror("socket");
}
else
{
v7 = _bswap_16(v3, 1LL, 2LL, &v13, 4LL);
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = v7;
if ( setsockopt(v6, 1, v8, v9, v10) )
perror("reuseaddr");
if ( bind(v6, &addr, 0x10u) )
{
perror("bind");
}
else
{
if ( !listen(v6, 100) )
{
while ( 1 )
{
while ( 1 )
{
v11 = accept(v6, 0LL, 0LL);
v12 = v11;
if ( v11 >= 0 )
break;
perror("accept");
}
if ( optval[0] && (setsockopt(v11, 1, 20, optval, 0x10u) || setsockopt(v12, 1, 21, optval, 0x10u)) )
{
perror("IO timeout");
close(v12);
}
else if ( pthread_create(&newthread, 0LL, http_handler, (void *)v12) )
{
fwrite("pthread_create failed\n", 1uLL, 0x16uLL, stderr);
close(v12);
}
else if ( pthread_detach(newthread) )
{
fwrite("pthread_detach failed\n", 1uLL, 0x16uLL, stderr);
}
}
}
perror("listen");
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r12
int v4; // eax
int v6; // ebx
__int16 v7; // ax
int v8; // edx
const void *v9; // rcx
socklen_t v10; // er8
int v11; // eax
int v12; // ebp
int v13; // [rsp+0h] [rbp-44h] BYREF
pthread_t newthread; // [rsp+4h] [rbp-40h] BYREF
struct sockaddr addr; // [rsp+Ch] [rbp-38h] BYREF
__int64 optval[5]; // [rsp+1Ch] [rbp-28h] BYREF

v3 = 8888;
addr = 0LL;
v13 = 1;
addr.sa_family = 2;
optval[0] = 0LL;
optval[1] = 0LL;
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "p:t:d:h", &lopts, 0LL);
if ( v4 == -1 )
break;
if ( v4 == 112 )
{
v3 = atoi(_bss_start);
}
else if ( v4 > 112 )
{
if ( v4 != 116 )
return 1;
optval[0] = atoi(_bss_start);
}
else
{
if ( v4 != 100 )
{
if ( v4 == 104 )
func10();
return 1;
}
if ( chdir(_bss_start) )
{
perror("chdir");
return 1;
}
}
}
signal(13, (__sighandler_t)1);
v6 = socket(2, 1, 0);
if ( v6 == -1 )
{
perror("socket");
}
else
{
v7 = func11(v3, 1LL, 2LL, &v13, 4LL);
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = v7;
if ( setsockopt(v6, 1, v8, v9, v10) )
perror("reuseaddr");
if ( bind(v6, &addr, 0x10u) )
{
perror("bind");
}
else
{
if ( !listen(v6, 100) )
{
while ( 1 )
{
while ( 1 )
{
v11 = accept(v6, 0LL, 0LL);
v12 = v11;
if ( v11 >= 0 )
break;
perror("accept");
}
if ( optval[0] && (setsockopt(v11, 1, 20, optval, 0x10u) || setsockopt(v12, 1, 21, optval, 0x10u)) )
{
perror("IO timeout");
close(v12);
}
else if ( pthread_create(&newthread, 0LL, http_handler, (void *)v12) )
{
fwrite("pthread_create failed\n", 1uLL, 0x16uLL, stderr);
close(v12);
}
else if ( pthread_detach(newthread) )
{
fwrite("pthread_detach failed\n", 1uLL, 0x16uLL, stderr);
}
}
}
perror("listen");
}
}
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 int s, ss, opt, one = 1, port = 8888;
 pthread_t pt;
 struct sockaddr_in sin = {
  .sin_family = 2
 };
 struct timeval timeout = {
  .tv_sec = 0,
  .tv_usec = 0
 };
 while((opt = getopt_long(argc, argv, shopts, lopts, ((void *)0))) != -1)
 {
  switch(opt) {
   case 'p':
    port = atoi(optarg);
    break;
   case 't':
    timeout.tv_sec = atoi(optarg);
    break;
   case 'd':
    if (chdir(optarg)) {
     perror("chdir");
     return 1;
    }
    break;
   case 'h':
    print_usage();
    break;
   default:
    return 1;
  }
 }
 signal(13, ((__sighandler_t) 1));
 s = socket(2, SOCK_STREAM, 0);
 if (s == -1) {
  perror("socket");
  return 1;
 }
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if (setsockopt(s, 1, 2, &one, sizeof(one)))
  perror("reuseaddr");
 if (bind(s, (struct sockaddr*)&sin, sizeof(sin))) {
  perror("bind");
  return 1;
 }
 if (listen(s, 100)) {
  perror("listen");
  return 1;
 }
 for(;;) {
  ss = accept(s, ((void *)0), ((void *)0));
  if (ss < 0) {
   perror("accept");
   continue;
  }
  if (timeout.tv_sec) {
   if (setsockopt(ss, 1, 20,
     &timeout, sizeof(timeout))
    || setsockopt(ss, 1, 21,
     &timeout, sizeof(timeout)))
   {
    perror("IO timeout");
    close(ss);
    continue;
   }
  }
  if (pthread_create(&pt, ((void *)0), http_handler, (void*)(long)ss)) {
   fprintf(stderr, "pthread_create failed\n");
   close(ss);
   continue;
  }
  if (pthread_detach(pt)) {
   fprintf(stderr, "pthread_detach failed\n");
   continue;
  }
 }
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int s; int ss; int opt; int one = 1; int port = 8888;
 unsigned long pt;
 struct sockaddr_in sin = {
  .sin_family = 2
 };
 struct timeval timeout = {
  .tv_sec = 0,
  .tv_usec = 0
 };
 while((opt = getopt_long(argc, argv, shopts, lopts, ((void *)0))) != -1)
 {
  switch(opt) {
   case 'p':
    port = atoi(optarg);
    break;
   case 't':
    timeout.tv_sec = atoi(optarg);
    break;
   case 'd':
    if (chdir(optarg)) {
     perror("chdir");
     return 1;
    }
    break;
   case 'h':
    print_usage();
    break;
   default:
    return 1;
  }
 }
 signal(13, ((void (*)(int)) 1));
 s = socket(2, SOCK_STREAM, 0);
 if (s == -1) {
  perror("socket");
  return 1;
 }
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if (setsockopt(s, 1, 2, &one, sizeof(one)))
  perror("reuseaddr");
 if (bind(s, (struct sockaddr *)&sin, sizeof(sin))) {
  perror("bind");
  return 1;
 }
 if (listen(s, 100)) {
  perror("listen");
  return 1;
 }
 for(;;) {
  ss = accept(s, ((void *)0), ((void *)0));
  if (ss < 0) {
   perror("accept");
   continue;
  }
  if (timeout.tv_sec) {
   if (setsockopt(ss, 1, 20,
     &timeout, sizeof(timeout))
    || setsockopt(ss, 1, 21,
     &timeout, sizeof(timeout)))
   {
    perror("IO timeout");
    close(ss);
    continue;
   }
  }
  if (pthread_create(&pt, ((void *)0), http_handler, (void *)(long)ss)) {
   fprintf(stderr, "pthread_create failed\n");
   close(ss);
   continue;
  }
  if (pthread_detach(pt)) {
   fprintf(stderr, "pthread_detach failed\n");
   continue;
  }
 }
 close(s);
 return 0;
}

variable_types: s int

variable_types: ss int

variable_types: opt int

variable_types: one int

variable_types: port int

variable_types:
pt
unsigned long

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 timeval { long tv_sec; long tv_usec; }

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

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


decompiled_code:
__int64 __fastcall output_buf(int fd, void *buf, size_t n)
{
int v5; // eax

while ( 1 )
{
v5 = send(fd, buf, n, 0x4000);
if ( v5 == n )
return 0LL;
if ( v5 == -1 )
break;
buf = (char *)buf + v5;
n -= v5;
}
perror("send error");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf, size_t n)
{
int v5; // eax

while ( 1 )
{
v5 = send(fd, buf, n, 0x4000);
if ( v5 == n )
return 0LL;
if ( v5 == -1 )
break;
buf = (char *)buf + v5;
n -= v5;
}
perror("send error");
return 1LL;
}

original_code:
static int output_buf(int fd, const char *buf, size_t size)
{
 int ret;
 for(;;) {
  ret = send(fd, buf, size, MSG_NOSIGNAL);
  if (ret == size)
   return 0;
  if (ret == -1) {
   perror("send error");
   return 1;
  }
  buf += ret;
  size -= ret;
 }
}

canonical_original_code:
static int output_buf(int fd, char *buf, unsigned long size)
{
 int ret;
 for(;;) {
  ret = send(fd, buf, size, MSG_NOSIGNAL);
  if (ret == size)
   return 0;
  if (ret == -1) {
   perror("send error");
   return 1;
  }
  buf += ret;
  size -= ret;
 }
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: ret int


decompiled_code:
void *__fastcall http_handler(void *a1)
{
int v1; // er15
size_t v2; // r13
const char *v3; // rbp
char *v4; // r14
char *v5; // rbx
ssize_t v6; // rax
_BYTE *v7; // rax
__int64 v8; // rdx
char *v9; // rax
char *v10; // rbx
const char *v11; // r12
char *v12; // rax
char v13; // al
unsigned int v14; // ebx
int v15; // eax
int v16; // ebp
int v18; // eax
off_t i; // rax
int fd; // [rsp+8h] [rbp-8E0h]
off_t offset; // [rsp+18h] [rbp-8D0h] BYREF
struct stat stat_buf; // [rsp+20h] [rbp-8C8h] BYREF
char buf[1024]; // [rsp+B0h] [rbp-838h] BYREF
char s[1080]; // [rsp+4B0h] [rbp-438h] BYREF

v1 = (int)a1;
v2 = 1024LL;
v3 = 0LL;
fd = (int)a1;
v4 = buf;
v5 = buf;
while ( 1 )
{
v6 = recv((int)a1, v5, v2, 0);
if ( !v6 )
{
fwrite("eof!\n", 1uLL, 5uLL, stderr);
goto LABEL_26;
}
if ( v6 < 0 )
break;
v5 += v6;
v2 -= v6;
while ( 1 )
{
v7 = memchr(v4, 10, v5 - v4);
if ( !v7 )
break;
*v7 = 0;
v8 = v7 - v4;
if ( v7 - v4 > 0 )
{
if ( *(v7 - 1) == 13 )
*(v7 - 1) = 0;
if ( v8 == 1 || v8 == 2 && !*(v7 - 1) )
{
if ( v3 )
{
v9 = strchr(v3, 32);
v10 = v9;
if ( !v9 )
goto LABEL_28;
*v9 = 0;
v11 = v9 + 1;
if ( strcmp(v3, "GET") )
{
fprintf(stderr, "unsupported method '%s'\n", v3);
goto LABEL_26;
}
v12 = strrchr(v11, 32);
if ( v12 )
{
*v12 = 0;
if ( !memcmp(v12 + 1, "HTTP/1.", 7uLL) && (v13 = v12[8], (unsigned __int8)(v13 - 48) <= 1u) )
{
if ( v10[1] == 47 )
v11 = v10 + 2;
v14 = (char)(v13 - 48);
v15 = open(v11, 0);
v16 = v15;
if ( v15 == -1 )
{
snprintf(
s,
0x400uLL,
"HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s",
1LL,
v14,
404LL,
"Not Found",
"\r\n");
output_buf(fd, s, 0x2DuLL);
}
else
{
if ( (unsigned int)fstat(v15, &stat_buf) )
{
perror("fstat");
}
else
{
snprintf(s, 0x400uLL, "HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s", 1LL, v14, 200LL, "OK", "");
if ( !(unsigned int)output_buf(fd, s, 0x24uLL) )
{
v18 = snprintf(s, 0x400uLL, "Content-Length: %ld\r\n\r\n", stat_buf.st_size);
if ( !(unsigned int)output_buf(fd, s, v18) )
{
offset = 0LL;
for ( i = 0LL; stat_buf.st_size != i; i = offset )
{
if ( sendfile(v1, v16, &offset, stat_buf.st_size - i) == -1 )
{
perror("sendfile");
break;
}
}
}
}
}
close(v16);
}
}
else
{
fwrite("malformed HTTP request finalizer\n", 1uLL, 0x21uLL, stderr);
}
}
else
{
LABEL_28:
fwrite("malformed HTTP request\n", 1uLL, 0x17uLL, stderr);
}
}
else
{
fwrite("empty HTTP request\n", 1uLL, 0x13uLL, stderr);
}
goto LABEL_26;
}
}
if ( v4 == buf )
v3 = v4;
v4 = v7 + 1;
}
}
perror("read");
LABEL_26:
close(fd);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // er15
size_t v2; // r13
const char *v3; // rbp
char *v4; // r14
char *v5; // rbx
ssize_t v6; // rax
_BYTE *v7; // rax
__int64 v8; // rdx
char *v9; // rax
char *v10; // rbx
const char *v11; // r12
char *v12; // rax
char v13; // al
unsigned int v14; // ebx
int v15; // eax
int v16; // ebp
int v18; // eax
off_t i; // rax
int fd; // [rsp+8h] [rbp-8E0h]
off_t offset; // [rsp+18h] [rbp-8D0h] BYREF
struct stat stat_buf; // [rsp+20h] [rbp-8C8h] BYREF
char buf[1024]; // [rsp+B0h] [rbp-838h] BYREF
char s[1080]; // [rsp+4B0h] [rbp-438h] BYREF

v1 = (int)a1;
v2 = 1024LL;
v3 = 0LL;
fd = (int)a1;
v4 = buf;
v5 = buf;
while ( 1 )
{
v6 = recv((int)a1, v5, v2, 0);
if ( !v6 )
{
fwrite("eof!\n", 1uLL, 5uLL, stderr);
goto LABEL_26;
}
if ( v6 < 0 )
break;
v5 += v6;
v2 -= v6;
while ( 1 )
{
v7 = memchr(v4, 10, v5 - v4);
if ( !v7 )
break;
*v7 = 0;
v8 = v7 - v4;
if ( v7 - v4 > 0 )
{
if ( *(v7 - 1) == 13 )
*(v7 - 1) = 0;
if ( v8 == 1 || v8 == 2 && !*(v7 - 1) )
{
if ( v3 )
{
v9 = strchr(v3, 32);
v10 = v9;
if ( !v9 )
goto LABEL_28;
*v9 = 0;
v11 = v9 + 1;
if ( strcmp(v3, "GET") )
{
fprintf(stderr, "unsupported method '%s'\n", v3);
goto LABEL_26;
}
v12 = strrchr(v11, 32);
if ( v12 )
{
*v12 = 0;
if ( !memcmp(v12 + 1, "HTTP/1.", 7uLL) && (v13 = v12[8], (unsigned __int8)(v13 - 48) <= 1u) )
{
if ( v10[1] == 47 )
v11 = v10 + 2;
v14 = (char)(v13 - 48);
v15 = open(v11, 0);
v16 = v15;
if ( v15 == -1 )
{
snprintf(
s,
0x400uLL,
"HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s",
1LL,
v14,
404LL,
"Not Found",
"\r\n");
func7(fd, s, 0x2DuLL);
}
else
{
if ( (unsigned int)func14(v15, &stat_buf) )
{
perror("fstat");
}
else
{
snprintf(s, 0x400uLL, "HTTP/%d.%d %d %s\r\nConnection: Close\r\n%s", 1LL, v14, 200LL, "OK", "");
if ( !(unsigned int)func7(fd, s, 0x24uLL) )
{
v18 = snprintf(s, 0x400uLL, "Content-Length: %ld\r\n\r\n", stat_buf.st_size);
if ( !(unsigned int)func7(fd, s, v18) )
{
offset = 0LL;
for ( i = 0LL; stat_buf.st_size != i; i = offset )
{
if ( sendfile(v1, v16, &offset, stat_buf.st_size - i) == -1 )
{
perror("sendfile");
break;
}
}
}
}
}
close(v16);
}
}
else
{
fwrite("malformed HTTP request finalizer\n", 1uLL, 0x21uLL, stderr);
}
}
else
{
LABEL_28:
fwrite("malformed HTTP request\n", 1uLL, 0x17uLL, stderr);
}
}
else
{
fwrite("empty HTTP request\n", 1uLL, 0x13uLL, stderr);
}
goto LABEL_26;
}
}
if ( v4 == buf )
v3 = v4;
v4 = v7 + 1;
}
}
perror("read");
LABEL_26:
close(fd);
return 0LL;
}

original_code:
static void* http_handler(void *arg)
{
 int ss = (long)arg;
 char rq[1024], *s = rq, *p = rq, *pp = p;
 size_t size;
 ssize_t ret;
 char *htrq = ((void *)0), *uri;
 int fd = -1;
 int htcode, htmajor, htminor;
 char *htmsg, *htsig;
 char buf[1024];
 off_t offs;
 struct stat st;
 size = sizeof(rq);
 for(;;) {
  ret = recv(ss, s, size, 0);
  if (!ret) {
   fprintf(stderr, "eof!\n");
   goto out;
  }
  if (ret < 0) {
   perror("read");
   goto out;
  }
  s += ret;
  size -= ret;
  for(;;) {
   pp = (char*)memchr(p, '\n', s - p);
   if (!pp)
    break;
   *pp = '\0';
   if (pp - p >= 1 && *(pp - 1) == '\r')
    *(pp - 1) = '\0';
   if (pp - p == 1
     || pp - p == 2 && !*(pp - 1))
    goto done_rq;
   if (p == rq)
    htrq = p;
   p = pp;
   ++p;
  }
 }
done_rq:
 if (!htrq) {
  fprintf(stderr, "empty HTTP request\n");
  goto out;
 }
 uri = strchr(htrq, ' ');
 if (uri == ((void *)0)) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *uri++ = 0;
 if (strcmp(htrq, "GET")) {
  fprintf(stderr, "unsupported method '%s'\n", htrq);
  goto out;
 }
 htsig = strrchr(uri, ' ');
 if (!htsig) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *htsig++ = 0;
 if (strncmp(htsig, "HTTP/1.", 7)
  || !htsig[7] || htsig[7] != '0' && htsig[7] != '1')
 {
  fprintf(stderr, "malformed HTTP request finalizer\n");
  goto out;
 }
 htmajor = 1;
 htminor = htsig[7] - '0';
 if (*uri == '/')
  ++uri;
 fd = open(uri, 00);
 if (fd != -1 && fstat(fd, &st)) {
  perror("fstat");
  goto out;
 }
 if (fd == -1) {
  htcode = 404;
  htmsg = "Not Found";
 } else {
  htcode = 200;
  htmsg = "OK";
 }
 size = snprintf(buf, sizeof(buf),
   "HTTP/%d.%d %d %s\r\n"
   "Connection: Close\r\n%s",
   htmajor, htminor, htcode, htmsg,
   fd == -1 ? "\r\n" : "");
 if (output_buf(ss, buf, size))
  goto out;
 if (fd != -1) {
  size = snprintf(buf, sizeof(buf),
    "Content-Length: %ld\r\n\r\n", st.st_size);
  if (output_buf(ss, buf, size))
   goto out;
  for(offs = 0; offs != st.st_size; ) {
   if (sendfile(ss, fd, &offs, st.st_size - offs) == -1) {
    perror("sendfile");
    goto out;
   }
  }
 }
out:
 if (fd != -1)
  close(fd);
 close(ss);
 return ((void *)0);
}

canonical_original_code:
static void *http_handler(void *arg)
{
 int ss = (long)arg;
 char rq[1024]; char *s = rq; char *p = rq; char *pp = p;
 unsigned long size;
 long ret;
 char *htrq = ((void *)0); char *uri;
 int fd = -1;
 int htcode; int htmajor; int htminor;
 char *htmsg; char *htsig;
 char buf[1024];
 long offs;
 struct stat st;
 size = sizeof(rq);
 for(;;) {
  ret = recv(ss, s, size, 0);
  if (!ret) {
   fprintf(stderr, "eof!\n");
   goto out;
  }
  if (ret < 0) {
   perror("read");
   goto out;
  }
  s += ret;
  size -= ret;
  for(;;) {
   pp = (char *)memchr(p, '\n', s - p);
   if (!pp)
    break;
   *pp = '\0';
   if (pp - p >= 1 && *(pp - 1) == '\r')
    *(pp - 1) = '\0';
   if (pp - p == 1
     || pp - p == 2 && !*(pp - 1))
    goto done_rq;
   if (p == rq)
    htrq = p;
   p = pp;
   ++p;
  }
 }
done_rq:
 if (!htrq) {
  fprintf(stderr, "empty HTTP request\n");
  goto out;
 }
 uri = strchr(htrq, ' ');
 if (uri == ((void *)0)) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *uri++ = 0;
 if (strcmp(htrq, "GET")) {
  fprintf(stderr, "unsupported method '%s'\n", htrq);
  goto out;
 }
 htsig = strrchr(uri, ' ');
 if (!htsig) {
  fprintf(stderr, "malformed HTTP request\n");
  goto out;
 }
 *htsig++ = 0;
 if (strncmp(htsig, "HTTP/1.", 7)
  || !htsig[7] || htsig[7] != '0' && htsig[7] != '1')
 {
  fprintf(stderr, "malformed HTTP request finalizer\n");
  goto out;
 }
 htmajor = 1;
 htminor = htsig[7] - '0';
 if (*uri == '/')
  ++uri;
 fd = open(uri, 00);
 if (fd != -1 && fstat(fd, &st)) {
  perror("fstat");
  goto out;
 }
 if (fd == -1) {
  htcode = 404;
  htmsg = "Not Found";
 } else {
  htcode = 200;
  htmsg = "OK";
 }
 size = snprintf(buf, sizeof(buf),
   "HTTP/%d.%d %d %s\r\n"
   "Connection: Close\r\n%s",
   htmajor, htminor, htcode, htmsg,
   fd == -1 ? "\r\n" : "");
 if (output_buf(ss, buf, size))
  goto out;
 if (fd != -1) {
  size = snprintf(buf, sizeof(buf),
    "Content-Length: %ld\r\n\r\n", st.st_size);
  if (output_buf(ss, buf, size))
   goto out;
  for(offs = 0; offs != st.st_size; ) {
   if (sendfile(ss, fd, &offs, st.st_size - offs) == -1) {
    perror("sendfile");
    goto out;
   }
  }
 }
out:
 if (fd != -1)
  close(fd);
 close(ss);
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
rq
char [1024]

variable_types:
s
char *

variable_types:
p
char *

variable_types:
pp
char *

variable_types: ret long

variable_types:
htrq
char *

variable_types:
uri
char *

variable_types: htcode int

variable_types: htmajor int

variable_types: htminor int

variable_types:
htmsg
char *

variable_types:
htsig
char *

variable_types:
buf
char [1024]

variable_types: offs long

return_type: void *


decompiled_code:
int print_version()
{
return puts("htserve - simple multithreaded HTTP server for static content");
}

canonical_decompiled_code:
int func9()
{
return puts("htserve - simple multithreaded HTTP server for static content");
}

original_code:
static void print_version()
{
    printf("htserve - simple multithreaded HTTP "
   "server for static content\n") ;
}


decompiled_code:
void __noreturn print_usage()
{
print_version();
printf(
"Usage: htserve [OPTION*]\n"
" -p, --port port to listen, default is %d\n"
" -t, --timeout network IO timeout (in sec), default is infinity\n"
" -d, --directory chdir to directory before runnung\n"
" -h, --help display this help and exit\n"
"\n",
8888LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func10()
{
func9();
printf(
"Usage: htserve [OPTION*]\n"
" -p, --port port to listen, default is %d\n"
" -t, --timeout network IO timeout (in sec), default is infinity\n"
" -d, --directory chdir to directory before runnung\n"
" -h, --help display this help and exit\n"
"\n",
8888LL);
exit(0);
}

original_code:
static void print_usage()
{
 print_version() ;
 printf("Usage: htserve [OPTION*]\n"
   "  -p, --port       port to listen, default is %d\n"
   "  -t, --timeout    network IO timeout (in sec), default is infinity\n"
   "  -d, --directory  chdir to directory before runnung\n"
   "  -h, --help       display this help and exit\n\n"
   , 8888);
 exit(0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_ht_ctor(argc, argv, envp);
test_ht_dtor();
test_convert_mac_to_ip();
test_ht_insert();
test_ht_search();
test_ht_delete();
puts("end of main()! ");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func14(argc, argv, envp);
func15();
func16();
func17();
func18();
func19();
puts("end of main()! ");
return 0;
}

original_code:
int main(){
 test_ht_ctor();
    test_ht_dtor();
 test_convert_mac_to_ip();
 test_ht_insert();
 test_ht_search();
 test_ht_delete();
 printf("end of main()! \n");
 return 0;
}


original_code:
void ht_dtor(ht_t* ht){
 int capacity=ht->capacity;
 int i;
    for(i=0;i<capacity;i++){
  bucket_t* pbucket=&(ht->bucket[i]);
  if(pbucket->next!=((void *)0)){
   pbucket=pbucket->next;
   while(pbucket->next!=((void *)0)){
    bucket_t* tmp=pbucket;
    pbucket=pbucket->next;
    free(tmp);
   }
  }
 }
 free(ht->bucket);
 free(ht);
}

canonical_original_code:
void ht_dtor(struct ht *ht){
 int capacity = ht->capacity;
 int i;
    for(i=0;i<capacity;i++){
  struct bucket *pbucket = &(ht->bucket[i]);
  if(pbucket->next!=((void *)0)){
   pbucket=pbucket->next;
   while(pbucket->next!=((void *)0)){
    struct bucket *tmp = pbucket;
    pbucket=pbucket->next;
    free(tmp);
   }
  }
 }
 free(ht->bucket);
 free(ht);
}

variable_types: struct ht { int count; int capacity; struct bucket { int data; int key; struct bucket *next; } *bucket; } *

variable_types: capacity int

variable_types: i int

user_defined_types: struct ht { int count; int capacity; struct bucket *bucket; }


decompiled_code:
__int64 __fastcall ht_hash(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return a1;
}

original_code:
int ht_hash(int in){
 return in;
}

canonical_original_code:
int ht_hash(int in){
 return in;
}

variable_types: in int


decompiled_code:
__int64 __fastcall get_last_32_bit(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return a1;
}

original_code:
int32_t get_last_32_bit(int64_t in){
    int32_t result=0x00000000;
    int32_t last_32_bit=0xFFFFFFFF;
    result = in & last_32_bit;
    return result;
}

canonical_original_code:
int get_last_32_bit(long in){
    int result = 0x00000000;
    int last_32_bit = 0xFFFFFFFF;
    result = in & last_32_bit;
    return result;
}

variable_types: in long

variable_types: result int


decompiled_code:
// attributes: thunk
__int64 __fastcall convert_mac_to_ip(__int64 a1)
{
return get_last_32_bit(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func9(a1);
}

original_code:
int32_t convert_mac_to_ip(int64_t mac){
 int32_t result=get_last_32_bit(mac);
 return result;
}

canonical_original_code:
int convert_mac_to_ip(long mac){
 int result = get_last_32_bit(mac);
 return result;
}

variable_types: mac long


original_code:
int ht_insert(ht_t* ht, int IP, int MAC){
 int index=ht_hash(IP);
    bucket_t* tmp=ht->bucket;
 if(tmp[index].key==-1&&tmp->next==((void *)0)){
     tmp[index].data=MAC;
     tmp[index].key=IP;
 }
 else{
  tmp=&(tmp[index]);
  while(tmp->key!=-1&&tmp->next!=((void *)0)){
   if(tmp->key!=-1&&tmp->next==((void *)0)){
    tmp->next=malloc(sizeof(bucket_t));
    tmp=tmp->next;
    tmp->data=MAC;
          tmp->key=IP;
    tmp->next=((void *)0);
    return 0;
   }
   tmp=tmp->next;
  }
 }
 return 0;
}

canonical_original_code:
int ht_insert(struct ht *ht, int IP, int MAC){
 int index = ht_hash(IP);
    struct bucket *tmp = ht->bucket;
 if(tmp[index].key==-1&&tmp->next==((void *)0)){
     tmp[index].data=MAC;
     tmp[index].key=IP;
 }
 else{
  tmp=&(tmp[index]);
  while(tmp->key!=-1&&tmp->next!=((void *)0)){
   if(tmp->key!=-1&&tmp->next==((void *)0)){
    tmp->next=malloc(sizeof(bucket_t));
    tmp=tmp->next;
    tmp->data=MAC;
          tmp->key=IP;
    tmp->next=((void *)0);
    return 0;
   }
   tmp=tmp->next;
  }
 }
 return 0;
}

variable_types: IP int

variable_types: MAC int

variable_types: index int

variable_types: struct bucket { int data; int key; struct bucket *next; } *


decompiled_code:
__int64 __fastcall ht_search(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 v3; // rcx
unsigned int *v4; // rdx
unsigned int *v5; // rax
__int64 result; // rax

v2 = ht_hash(a2);
v4 = (unsigned int *)(*(_QWORD *)(v3 + 8) + 16LL * v2);
v5 = (unsigned int *)*((_QWORD *)v4 + 1);
if ( v5 )
{
while ( v5[1] != a2 )
{
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
if ( !v5 )
return 2LL;
}
result = *v5;
}
else
{
result = 0xFFFFFFFFLL;
if ( a2 == v4[1] )
result = *v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 v3; // rcx
unsigned int *v4; // rdx
unsigned int *v5; // rax
__int64 result; // rax

v2 = func8(a2);
v4 = (unsigned int *)(*(_QWORD *)(v3 + 8) + 16LL * v2);
v5 = (unsigned int *)*((_QWORD *)v4 + 1);
if ( v5 )
{
while ( v5[1] != a2 )
{
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
if ( !v5 )
return 2LL;
}
result = *v5;
}
else
{
result = 0xFFFFFFFFLL;
if ( a2 == v4[1] )
result = *v4;
}
return result;
}

original_code:
int ht_search(ht_t* ht, int IP){
 int index=ht_hash(IP);
    bucket_t* tmp=ht->bucket;
 if(tmp[index].next==((void *)0)){
     bucket_t* tmp=ht->bucket;
     int data=tmp[index].data;
        int key=tmp[index].key;
  if(key==IP){
   return data;
  }
  else{
   return -1;
  }
 }
 else{
  bucket_t* p=&(tmp[index]);
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==IP){
    return p->data;
   }
   p=p->next;
  }
  return 2;
 }
}

canonical_original_code:
int ht_search(struct ht *ht, int IP){
 int index = ht_hash(IP);
    struct bucket *tmp = ht->bucket;
 if(tmp[index].next==((void *)0)){
     struct bucket *tmp = ht->bucket;
     int data = tmp[index].data;
        int key = tmp[index].key;
  if(key==IP){
   return data;
  }
  else{
   return -1;
  }
 }
 else{
  struct bucket *p = &(tmp[index]);
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==IP){
    return p->data;
   }
   p=p->next;
  }
  return 2;
 }
}

variable_types: data int

variable_types: key int

user_defined_types: struct bucket { int data; int key; struct bucket *next; }


decompiled_code:
__int64 __fastcall ht_delete(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rdx
unsigned int v5; // er12
__int64 v6; // rdi
__int64 v7; // rax
__int64 result; // rax

v2 = ht_hash(a2);
v4 = *(_QWORD *)(v3 + 8) + 16LL * v2;
v5 = *(_DWORD *)(v4 + 4);
if ( v5 == -1 )
{
puts("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) ");
LABEL_8:
result = v5;
}
else
{
v6 = *(_QWORD *)(v4 + 8);
if ( v6 )
{
while ( 1 )
{
v7 = *(_QWORD *)(v6 + 8);
if ( *(_DWORD *)(v6 + 4) == a2 )
break;
v4 = v6;
if ( !v7 )
{
v5 = 3;
goto LABEL_8;
}
v6 = *(_QWORD *)(v6 + 8);
}
if ( v7 )
*(_QWORD *)(v4 + 8) = v7;
else
*(_QWORD *)(v4 + 8) = 0LL;
free((void *)v6);
result = 0LL;
}
else if ( v5 == a2 )
{
*(_DWORD *)(v4 + 4) = -1;
result = 0LL;
}
else
{
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rdx
unsigned int v5; // er12
__int64 v6; // rdi
__int64 v7; // rax
__int64 result; // rax

v2 = func8(a2);
v4 = *(_QWORD *)(v3 + 8) + 16LL * v2;
v5 = *(_DWORD *)(v4 + 4);
if ( v5 == -1 )
{
puts("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) ");
LABEL_8:
result = v5;
}
else
{
v6 = *(_QWORD *)(v4 + 8);
if ( v6 )
{
while ( 1 )
{
v7 = *(_QWORD *)(v6 + 8);
if ( *(_DWORD *)(v6 + 4) == a2 )
break;
v4 = v6;
if ( !v7 )
{
v5 = 3;
goto LABEL_8;
}
v6 = *(_QWORD *)(v6 + 8);
}
if ( v7 )
*(_QWORD *)(v4 + 8) = v7;
else
*(_QWORD *)(v4 + 8) = 0LL;
free((void *)v6);
result = 0LL;
}
else if ( v5 == a2 )
{
*(_DWORD *)(v4 + 4) = -1;
result = 0LL;
}
else
{
result = 2LL;
}
}
return result;
}

original_code:
int ht_delete(ht_t* ht, int key){
    int index=ht_hash(key);
    bucket_t* tmp=ht->bucket;
 bucket_t* p=&(tmp[index]);
    bucket_t* q=&(tmp[index]);
 if(tmp[index].key==-1){
  printf("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) \n");
  return -1;
 }
 if(p->key!=-1&&p->next==((void *)0)){
  if(p->key==key){
   p->key=-1;
   return 0;
  }
  else{
   return 2;
  }
 }
 else{
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==key){
    if(p->next==((void *)0)){
     q->next=((void *)0);
     free(p);
     return 0;
    }
    else{
     q->next=p->next;
     free(p);
     return 0;
    }
   }
   q=p;
   p=p->next;
  }
  return 3;
 }
 return 4;
}

canonical_original_code:
int ht_delete(struct ht *ht, int key){
    int index = ht_hash(key);
    struct bucket *tmp = ht->bucket;
 struct bucket *p = &(tmp[index]);
    struct bucket *q = &(tmp[index]);
 if(tmp[index].key==-1){
  printf("ERROR: ht_delete(): trying to delete a data not in the list for index (computed by hash function) \n");
  return -1;
 }
 if(p->key!=-1&&p->next==((void *)0)){
  if(p->key==key){
   p->key=-1;
   return 0;
  }
  else{
   return 2;
  }
 }
 else{
  p=p->next;
  while(p!=((void *)0)){
   if(p->key==key){
    if(p->next==((void *)0)){
     q->next=((void *)0);
     free(p);
     return 0;
    }
    else{
     q->next=p->next;
     free(p);
     return 0;
    }
   }
   q=p;
   p=p->next;
  }
  return 3;
 }
 return 4;
}


decompiled_code:
int test_ht_ctor()
{
_DWORD *v0; // rbp
_DWORD *v1; // rax

v0 = ht_ctor(20);
v1 = (_DWORD *)*((_QWORD *)v0 + 1);
*v1 = 1;
v1[4] = 2;
printf("ht->bucket->data: %i\n", 1LL);
if ( *(_DWORD *)(*((_QWORD *)v0 + 1) + 16LL) != 2 )
__assert_fail("(ht->bucket[1]).data==2", "unittest.c", 0x11u, "test_ht_ctor");
printf("ht->bucket->data: %i\n", 2LL);
if ( v0[1] != 20 )
__assert_fail("ht->capacity==20", "unittest.c", 0x14u, "test_ht_ctor");
printf("ht->capacity: %i\n", 20LL);
ht_dtor(v0);
return puts("end of test_ht_ctor() -----");
}

canonical_decompiled_code:
int func14()
{
_DWORD *v0; // rbp
_DWORD *v1; // rax

v0 = ht_ctor(20);
v1 = (_DWORD *)*((_QWORD *)v0 + 1);
*v1 = 1;
v1[4] = 2;
printf("ht->bucket->data: %i\n", 1LL);
if ( *(_DWORD *)(*((_QWORD *)v0 + 1) + 16LL) != 2 )
__assert_fail("(ht->bucket[1]).data==2", "unittest.c", 0x11u, "test_ht_ctor");
printf("ht->bucket->data: %i\n", 2LL);
if ( v0[1] != 20 )
__assert_fail("ht->capacity==20", "unittest.c", 0x14u, "test_ht_ctor");
printf("ht->capacity: %i\n", 20LL);
func7(v0);
return puts("end of test_ht_ctor() -----");
}

original_code:
void test_ht_ctor(){
 ht_t* ht=ht_ctor(20);
 bucket_t* tmp=ht->bucket;
 tmp[0].data=1;
    tmp[1].data=2;
 ((void) sizeof (((ht->bucket)->data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket)->data==1) ; else __assert_fail ("(ht->bucket)->data==1", "unittest.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((ht->bucket[0]).data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket[0]).data==1) ; else __assert_fail ("(ht->bucket[0]).data==1", "unittest.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 printf("ht->bucket->data: %i\n", (ht->bucket)->data);
 ((void) sizeof (((ht->bucket[1]).data==2) ? 1 : 0), __extension__ ({ if ((ht->bucket[1]).data==2) ; else __assert_fail ("(ht->bucket[1]).data==2", "unittest.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->bucket->data: %i\n", (ht->bucket[1]).data);
 ((void) sizeof ((ht->capacity==20) ? 1 : 0), __extension__ ({ if (ht->capacity==20) ; else __assert_fail ("ht->capacity==20", "unittest.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->capacity: %i\n", ht->capacity);
    ht_dtor(ht);
 printf("end of test_ht_ctor() -----\n");
}

canonical_original_code:
void test_ht_ctor(){
 struct ht *ht = ht_ctor(20);
 struct bucket *tmp = ht->bucket;
 tmp[0].data=1;
    tmp[1].data=2;
 ((void) sizeof (((ht->bucket)->data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket)->data==1) ; else __assert_fail ("(ht->bucket)->data==1", "unittest.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof (((ht->bucket[0]).data==1) ? 1 : 0), __extension__ ({ if ((ht->bucket[0]).data==1) ; else __assert_fail ("(ht->bucket[0]).data==1", "unittest.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 printf("ht->bucket->data: %i\n", (ht->bucket)->data);
 ((void) sizeof (((ht->bucket[1]).data==2) ? 1 : 0), __extension__ ({ if ((ht->bucket[1]).data==2) ; else __assert_fail ("(ht->bucket[1]).data==2", "unittest.c", 17, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->bucket->data: %i\n", (ht->bucket[1]).data);
 ((void) sizeof ((ht->capacity==20) ? 1 : 0), __extension__ ({ if (ht->capacity==20) ; else __assert_fail ("ht->capacity==20", "unittest.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    printf("ht->capacity: %i\n", ht->capacity);
    ht_dtor(ht);
 printf("end of test_ht_ctor() -----\n");
}


decompiled_code:
int test_ht_dtor()
{
_DWORD **v0; // rax

v0 = (_DWORD **)ht_ctor(20);
*v0[1] = 1;
ht_dtor(v0);
return puts("end of test_ht_dtor() -----");
}

canonical_decompiled_code:
int func15()
{
_DWORD **v0; // rax

v0 = (_DWORD **)ht_ctor(20);
*v0[1] = 1;
func7(v0);
return puts("end of test_ht_dtor() -----");
}

original_code:
void test_ht_dtor(){
    ht_t* ht=ht_ctor(20);
 bucket_t* tmp=ht->bucket;
    tmp[0].data=1;
 ht_dtor(ht);
    printf("end of test_ht_dtor() -----\n");
}

canonical_original_code:
void test_ht_dtor(){
    struct ht *ht = ht_ctor(20);
 struct bucket *tmp = ht->bucket;
    tmp[0].data=1;
 ht_dtor(ht);
    printf("end of test_ht_dtor() -----\n");
}


decompiled_code:
int test_convert_mac_to_ip()
{
if ( (unsigned int)convert_mac_to_ip(1LL) != 1 )
__assert_fail("result==0x00000001", "unittest.c", 0x28u, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(2LL) != 2 )
__assert_fail("result==0x00000002", "unittest.c", 0x2Au, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(3LL) != 3 )
__assert_fail("result==0x00000003", "unittest.c", 0x2Cu, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(4LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x2Eu, "test_convert_mac_to_ip");
if ( (unsigned int)convert_mac_to_ip(0xFFFF00000004LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x31u, "test_convert_mac_to_ip");
return puts("end of test_convert_mac_to_ip() -----");
}

canonical_decompiled_code:
int func16()
{
if ( (unsigned int)func10(1LL) != 1 )
__assert_fail("result==0x00000001", "unittest.c", 0x28u, "test_convert_mac_to_ip");
if ( (unsigned int)func10(2LL) != 2 )
__assert_fail("result==0x00000002", "unittest.c", 0x2Au, "test_convert_mac_to_ip");
if ( (unsigned int)func10(3LL) != 3 )
__assert_fail("result==0x00000003", "unittest.c", 0x2Cu, "test_convert_mac_to_ip");
if ( (unsigned int)func10(4LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x2Eu, "test_convert_mac_to_ip");
if ( (unsigned int)func10(0xFFFF00000004LL) != 4 )
__assert_fail("result==0x00000004", "unittest.c", 0x31u, "test_convert_mac_to_ip");
return puts("end of test_convert_mac_to_ip() -----");
}

original_code:
void test_convert_mac_to_ip(){
 int32_t result;
 result = convert_mac_to_ip(0x0000000000000001);
 ((void) sizeof ((result==0x00000001) ? 1 : 0), __extension__ ({ if (result==0x00000001) ; else __assert_fail ("result==0x00000001", "unittest.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000002);
    ((void) sizeof ((result==0x00000002) ? 1 : 0), __extension__ ({ if (result==0x00000002) ; else __assert_fail ("result==0x00000002", "unittest.c", 42, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000003);
    ((void) sizeof ((result==0x00000003) ? 1 : 0), __extension__ ({ if (result==0x00000003) ; else __assert_fail ("result==0x00000003", "unittest.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000FFFF00000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of test_convert_mac_to_ip() -----\n");
}

canonical_original_code:
void test_convert_mac_to_ip(){
 int result;
 result = convert_mac_to_ip(0x0000000000000001);
 ((void) sizeof ((result==0x00000001) ? 1 : 0), __extension__ ({ if (result==0x00000001) ; else __assert_fail ("result==0x00000001", "unittest.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000002);
    ((void) sizeof ((result==0x00000002) ? 1 : 0), __extension__ ({ if (result==0x00000002) ; else __assert_fail ("result==0x00000002", "unittest.c", 42, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000003);
    ((void) sizeof ((result==0x00000003) ? 1 : 0), __extension__ ({ if (result==0x00000003) ; else __assert_fail ("result==0x00000003", "unittest.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000000000000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    result = convert_mac_to_ip(0x0000FFFF00000004);
    ((void) sizeof ((result==0x00000004) ? 1 : 0), __extension__ ({ if (result==0x00000004) ; else __assert_fail ("result==0x00000004", "unittest.c", 49, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of test_convert_mac_to_ip() -----\n");
}


decompiled_code:
int test_ht_insert()
{
_QWORD *v0; // rbp
_DWORD *v1; // rdx
int i; // eax

v0 = ht_ctor(20);
ht_insert((__int64)v0, 0);
ht_insert((__int64)v0, 1u);
ht_insert((__int64)v0, 2u);
ht_insert((__int64)v0, 3u);
ht_insert((__int64)v0, 4u);
ht_insert((__int64)v0, 5u);
ht_insert((__int64)v0, 6u);
ht_insert((__int64)v0, 7u);
ht_insert((__int64)v0, 8u);
ht_insert((__int64)v0, 9u);
ht_insert((__int64)v0, 0xAu);
ht_insert((__int64)v0, 0xBu);
ht_insert((__int64)v0, 0xCu);
ht_insert((__int64)v0, 0xDu);
ht_insert((__int64)v0, 0xEu);
ht_insert((__int64)v0, 0xFu);
ht_insert((__int64)v0, 0x10u);
ht_insert((__int64)v0, 0x11u);
ht_insert((__int64)v0, 0x12u);
ht_insert((__int64)v0, 0x13u);
v1 = (_DWORD *)v0[1];
for ( i = 0; i != 20; ++i )
{
if ( *v1 != i )
__assert_fail("(ht->bucket[i]).data==i", "unittest.c", 0x4Fu, "test_ht_insert");
v1 += 4;
}
ht_dtor(v0);
return puts("end of test_ht_insert() -----");
}

original_code:
void test_ht_insert(){
    ht_t* ht=ht_ctor(20);
 ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
 int i;
 for(i=0; i<20; i++){
  ((void) sizeof (((ht->bucket[i]).data==i) ? 1 : 0), __extension__ ({ if ((ht->bucket[i]).data==i) ; else __assert_fail ("(ht->bucket[i]).data==i", "unittest.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 }
    ht_dtor(ht);
    printf("end of test_ht_insert() -----\n");
}

canonical_original_code:
void test_ht_insert(){
    struct ht *ht = ht_ctor(20);
 ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
 int i;
 for(i=0; i<20; i++){
  ((void) sizeof (((ht->bucket[i]).data==i) ? 1 : 0), __extension__ ({ if ((ht->bucket[i]).data==i) ; else __assert_fail ("(ht->bucket[i]).data==i", "unittest.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 }
    ht_dtor(ht);
    printf("end of test_ht_insert() -----\n");
}


decompiled_code:
int test_ht_search()
{
unsigned int v0; // ebx
_DWORD *v1; // rbp

v0 = 0;
v1 = ht_ctor(20);
ht_insert((__int64)v1, 0);
ht_insert((__int64)v1, 1u);
ht_insert((__int64)v1, 2u);
ht_insert((__int64)v1, 3u);
ht_insert((__int64)v1, 4u);
ht_insert((__int64)v1, 5u);
ht_insert((__int64)v1, 6u);
ht_insert((__int64)v1, 7u);
ht_insert((__int64)v1, 8u);
ht_insert((__int64)v1, 9u);
ht_insert((__int64)v1, 0xAu);
ht_insert((__int64)v1, 0xBu);
ht_insert((__int64)v1, 0xCu);
ht_insert((__int64)v1, 0xDu);
ht_insert((__int64)v1, 0xEu);
ht_insert((__int64)v1, 0xFu);
ht_insert((__int64)v1, 0x10u);
ht_insert((__int64)v1, 0x11u);
ht_insert((__int64)v1, 0x12u);
ht_insert((__int64)v1, 0x13u);
do
{
if ( (unsigned int)ht_search((__int64)v1, v0) != v0 )
__assert_fail("a==i", "unittest.c", 0x76u, "test_ht_search");
++v0;
}
while ( v0 != 20 );
ht_dtor(v1);
return puts("end of test_ht_search() -----");
}

original_code:
void test_ht_search(){
    ht_t* ht=ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
  int a=ht_search(ht, i);
        ((void) sizeof ((a==i) ? 1 : 0), __extension__ ({ if (a==i) ; else __assert_fail ("a==i", "unittest.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_search() -----\n");
}

canonical_original_code:
void test_ht_search(){
    struct ht *ht = ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
  int a = ht_search(ht, i);
        ((void) sizeof ((a==i) ? 1 : 0), __extension__ ({ if (a==i) ; else __assert_fail ("a==i", "unittest.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_search() -----\n");
}

variable_types: a int


decompiled_code:
int test_ht_delete()
{
unsigned int v0; // ebx
_DWORD *v1; // rbp
unsigned int v2; // esi
unsigned int i; // ebx

v0 = 0;
v1 = ht_ctor(20);
ht_insert((__int64)v1, 0);
ht_insert((__int64)v1, 1u);
ht_insert((__int64)v1, 2u);
ht_insert((__int64)v1, 3u);
ht_insert((__int64)v1, 4u);
ht_insert((__int64)v1, 5u);
ht_insert((__int64)v1, 6u);
ht_insert((__int64)v1, 7u);
ht_insert((__int64)v1, 8u);
ht_insert((__int64)v1, 9u);
ht_insert((__int64)v1, 0xAu);
ht_insert((__int64)v1, 0xBu);
ht_insert((__int64)v1, 0xCu);
ht_insert((__int64)v1, 0xDu);
ht_insert((__int64)v1, 0xEu);
ht_insert((__int64)v1, 0xFu);
ht_insert((__int64)v1, 0x10u);
ht_insert((__int64)v1, 0x11u);
ht_insert((__int64)v1, 0x12u);
ht_insert((__int64)v1, 0x13u);
do
{
v2 = v0++;
ht_delete((__int64)v1, v2);
}
while ( v0 != 20 );
for ( i = 0; i != 20; ++i )
{
if ( (unsigned int)ht_search((__int64)v1, i) != -1 )
__assert_fail("a==-1", "unittest.c", 0xA3u, "test_ht_delete");
}
ht_dtor(v1);
return puts("end of test_ht_delete() -----");
}

original_code:
void test_ht_delete(){
    ht_t* ht=ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
        ht_delete(ht, i);
    }
    for(i=0; i<20; i++){
  int a=ht_search(ht, i);
  ((void) sizeof ((a==-1) ? 1 : 0), __extension__ ({ if (a==-1) ; else __assert_fail ("a==-1", "unittest.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_delete() -----\n");
}

canonical_original_code:
void test_ht_delete(){
    struct ht *ht = ht_ctor(20);
    ht_insert(ht, 0, 0);
    ht_insert(ht, 1, 1);
    ht_insert(ht, 2, 2);
    ht_insert(ht, 3, 3);
    ht_insert(ht, 4, 4);
    ht_insert(ht, 5, 5);
    ht_insert(ht, 6, 6);
    ht_insert(ht, 7, 7);
    ht_insert(ht, 8, 8);
    ht_insert(ht, 9, 9);
    ht_insert(ht, 10,10);
    ht_insert(ht, 11,11);
    ht_insert(ht, 12,12);
    ht_insert(ht, 13,13);
    ht_insert(ht, 14,14);
    ht_insert(ht, 15,15);
    ht_insert(ht, 16,16);
    ht_insert(ht, 17,17);
    ht_insert(ht, 18,18);
    ht_insert(ht, 19,19);
    int i;
    for(i=0; i<20; i++){
        ht_delete(ht, i);
    }
    for(i=0; i<20; i++){
  int a = ht_search(ht, i);
  ((void) sizeof ((a==-1) ? 1 : 0), __extension__ ({ if (a==-1) ; else __assert_fail ("a==-1", "unittest.c", 163, __extension__ __PRETTY_FUNCTION__); }));
    }
    ht_dtor(ht);
    printf("end of test_ht_delete() -----\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

v3 = (unsigned int)or(1LL, 2LL, envp);
printf("or(1, 2): %i \n", v3);
if ( (_DWORD)v3 != 3 )
__assert_fail("result==3", "main.c", 0x16u, "main");
if ( (unsigned __int8)get_last_four_bit(0LL) )
__assert_fail("eight_bit_result==0x00", "main.c", 0x1Au, "main");
if ( (unsigned __int8)get_last_four_bit(9LL) != 9 )
__assert_fail("eight_bit_result==0x09", "main.c", 0x1Du, "main");
if ( (unsigned __int8)get_last_four_bit(10LL) != 10 )
__assert_fail("eight_bit_result==10", "main.c", 0x1Fu, "main");
if ( (unsigned __int8)get_last_four_bit(11LL) != 11 )
__assert_fail("eight_bit_result==11", "main.c", 0x21u, "main");
if ( (unsigned __int8)get_last_four_bit(12LL) != 12 )
__assert_fail("eight_bit_result==12", "main.c", 0x23u, "main");
if ( (unsigned __int8)get_last_four_bit(15LL) != 15 )
__assert_fail("eight_bit_result==15", "main.c", 0x25u, "main");
if ( (unsigned __int8)get_last_four_bit(16LL) )
__assert_fail("eight_bit_result==0", "main.c", 0x27u, "main");
if ( (unsigned __int8)get_last_four_bit(32LL) )
__assert_fail("eight_bit_result==0", "main.c", 0x29u, "main");
puts("end of main() ");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

v3 = (unsigned int)func7(1LL, 2LL, envp);
printf("or(1, 2): %i \n", v3);
if ( (_DWORD)v3 != 3 )
__assert_fail("result==3", "main.c", 0x16u, "main");
if ( (unsigned __int8)func8(0LL) )
__assert_fail("eight_bit_result==0x00", "main.c", 0x1Au, "main");
if ( (unsigned __int8)func8(9LL) != 9 )
__assert_fail("eight_bit_result==0x09", "main.c", 0x1Du, "main");
if ( (unsigned __int8)func8(10LL) != 10 )
__assert_fail("eight_bit_result==10", "main.c", 0x1Fu, "main");
if ( (unsigned __int8)func8(11LL) != 11 )
__assert_fail("eight_bit_result==11", "main.c", 0x21u, "main");
if ( (unsigned __int8)func8(12LL) != 12 )
__assert_fail("eight_bit_result==12", "main.c", 0x23u, "main");
if ( (unsigned __int8)func8(15LL) != 15 )
__assert_fail("eight_bit_result==15", "main.c", 0x25u, "main");
if ( (unsigned __int8)func8(16LL) )
__assert_fail("eight_bit_result==0", "main.c", 0x27u, "main");
if ( (unsigned __int8)func8(32LL) )
__assert_fail("eight_bit_result==0", "main.c", 0x29u, "main");
puts("end of main() ");
return 0;
}

original_code:
int main(){
    int result=or(1, 2);
 printf("or(1, 2): %i \n", result);
 ((void) sizeof ((result==3) ? 1 : 0), __extension__ ({ if (result==3) ; else __assert_fail ("result==3", "main.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 int8_t eight_bit_result=0x00;
    eight_bit_result=get_last_four_bit(0x00);
    ((void) sizeof ((eight_bit_result==0x00) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x00) ; else __assert_fail ("eight_bit_result==0x00", "main.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(0x09);
 ((void) sizeof ((eight_bit_result==0x09) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x09) ; else __assert_fail ("eight_bit_result==0x09", "main.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(10);
    ((void) sizeof ((eight_bit_result==10) ? 1 : 0), __extension__ ({ if (eight_bit_result==10) ; else __assert_fail ("eight_bit_result==10", "main.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(11);
    ((void) sizeof ((eight_bit_result==11) ? 1 : 0), __extension__ ({ if (eight_bit_result==11) ; else __assert_fail ("eight_bit_result==11", "main.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(12);
    ((void) sizeof ((eight_bit_result==12) ? 1 : 0), __extension__ ({ if (eight_bit_result==12) ; else __assert_fail ("eight_bit_result==12", "main.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(15);
    ((void) sizeof ((eight_bit_result==15) ? 1 : 0), __extension__ ({ if (eight_bit_result==15) ; else __assert_fail ("eight_bit_result==15", "main.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(16);
 ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(32);
    ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of main() \n");
}

canonical_original_code:
int main(){
    int result = or(1, 2);
 printf("or(1, 2): %i \n", result);
 ((void) sizeof ((result==3) ? 1 : 0), __extension__ ({ if (result==3) ; else __assert_fail ("result==3", "main.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 char eight_bit_result = 0x00;
    eight_bit_result=get_last_four_bit(0x00);
    ((void) sizeof ((eight_bit_result==0x00) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x00) ; else __assert_fail ("eight_bit_result==0x00", "main.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(0x09);
 ((void) sizeof ((eight_bit_result==0x09) ? 1 : 0), __extension__ ({ if (eight_bit_result==0x09) ; else __assert_fail ("eight_bit_result==0x09", "main.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(10);
    ((void) sizeof ((eight_bit_result==10) ? 1 : 0), __extension__ ({ if (eight_bit_result==10) ; else __assert_fail ("eight_bit_result==10", "main.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(11);
    ((void) sizeof ((eight_bit_result==11) ? 1 : 0), __extension__ ({ if (eight_bit_result==11) ; else __assert_fail ("eight_bit_result==11", "main.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(12);
    ((void) sizeof ((eight_bit_result==12) ? 1 : 0), __extension__ ({ if (eight_bit_result==12) ; else __assert_fail ("eight_bit_result==12", "main.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(15);
    ((void) sizeof ((eight_bit_result==15) ? 1 : 0), __extension__ ({ if (eight_bit_result==15) ; else __assert_fail ("eight_bit_result==15", "main.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(16);
 ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    eight_bit_result=get_last_four_bit(32);
    ((void) sizeof ((eight_bit_result==0) ? 1 : 0), __extension__ ({ if (eight_bit_result==0) ; else __assert_fail ("eight_bit_result==0", "main.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    printf("end of main() \n");
}


or

decompiled_code:
__int64 __fastcall or(unsigned int a1, int a2)
{
return a2 | a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2)
{
return a2 | a1;
}

original_code:
int or(int in1, int in2){
 int result=in1 | in2;
 return result;
}

canonical_original_code:
int or(int in1, int in2){
 int result = in1 | in2;
 return result;
}


decompiled_code:
__int64 __fastcall get_last_four_bit(char a1)
{
return a1 & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return a1 & 0xF;
}

original_code:
int8_t get_last_four_bit(int8_t in){
    int8_t result=0x00;
 int8_t last_four_bit=0x0F;
 result = in & last_four_bit;
 return result;
}

canonical_original_code:
char get_last_four_bit(char in){
    char result = 0x00;
 char last_four_bit = 0x0F;
 result = in & last_four_bit;
 return result;
}

variable_types: in char

variable_types: result char

return_type: char


main

repo: ash/qerl

decompiled_code:
// attributes: thunk
int __cdecl main(int argc, const char **argv, const char **envp)
{
return yyparse(argc, argv, envp);
}

original_code:
int main() {
    return yyparse();
}

canonical_original_code:
int main() {
    return yyparse();
}


decompiled_code:
int __fastcall yy_stack_print(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbx
__int64 v3; // rdx

v2 = a1;
fwrite("Stack now", 1uLL, 9uLL, stderr);
if ( (unsigned __int64)a1 <= a2 )
{
do
{
v3 = (unsigned int)*v2++;
fprintf(stderr, " %d", v3);
}
while ( a2 >= (unsigned __int64)v2 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbx
__int64 v3; // rdx

v2 = a1;
fwrite("Stack now", 1uLL, 9uLL, stderr);
if ( (unsigned __int64)a1 <= a2 )
{
do
{
v3 = (unsigned int)*v2++;
fprintf(stderr, " %d", v3);
}
while ( a2 >= (unsigned __int64)v2 );
}
return fputc(10, stderr);
}

original_code:
static void
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
{
  fprintf (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      fprintf (stderr, " %d", yybot);
    }
  fprintf (stderr, "\n");
}

canonical_original_code:
static void yy_stack_print(short *yybottom, short *yytop)
{
  fprintf (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      fprintf (stderr, " %d", yybot);
    }
  fprintf (stderr, "\n");
}

variable_types:
yybottom
short *

variable_types:
yytop
short *

variable_types: yybot int


yyerror

decompiled_code:
int yyerror()
{
return printf("Error at line %d\n", yylineno);
}

canonical_decompiled_code:
int func4()
{
return printf("Error at line %d\n", yylineno);
}

original_code:
void yyerror(char *s, ...) {
    printf("Error at line %d\n", yylineno);
}

variable_types:
s
char *