decompiled_code:
__int64 __fastcall linepiper_enqueue(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r13

if ( a3 < 0 )
return 0xFFFFFFFFLL;
v3 = a1 + 24;
if ( (int)tcpbuf_space(a1 + 24) <= a3 )
return 0xFFFFFFFFLL;
tcpbuf_enqueue(v3, (unsigned int)a3, a2);
tcpbuf_enqueue(v3, 1LL, a1 + 44);
return (unsigned int)(a3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r13

if ( a3 < 0 )
return 0xFFFFFFFFLL;
v3 = a1 + 24;
if ( (int)tcpbuf_space(a1 + 24) <= a3 )
return 0xFFFFFFFFLL;
tcpbuf_enqueue(v3, (unsigned int)a3, a2);
tcpbuf_enqueue(v3, 1LL, a1 + 44);
return (unsigned int)(a3 + 1);
}

original_code:
int
linepiper_enqueue(linepiper *lp, const char *data, int len)
{
    if(len<0)
        return -1;
    if(tcpbuf_space(&lp->buf_out)<len+1)
        return -1;
    tcpbuf_enqueue(&lp->buf_out, len, data);
    tcpbuf_enqueue(&lp->buf_out, 1, &lp->delim);
    return len+1;
}

canonical_original_code:
int linepiper_enqueue(struct linepiper *lp, char *data, int len)
{
    if(len<0)
        return -1;
    if(tcpbuf_space(&lp->buf_out)<len+1)
        return -1;
    tcpbuf_enqueue(&lp->buf_out, len, data);
    tcpbuf_enqueue(&lp->buf_out, 1, &lp->delim);
    return len+1;
}

variable_types:
data
char *

variable_types: len int


repo: sheheitthey/pipeserver

decompiled_code:
__int64 __fastcall linepiper_dequeue(__int64 a1)
{
__int64 v1; // r8
__int64 v2; // rax

if ( *(int *)(a1 + 40) < 0 )
return 0LL;
v1 = tcpbuf_data(a1 + 8);
v2 = *(int *)(a1 + 40);
if ( *(_BYTE *)(v1 + v2) != *(_BYTE *)(a1 + 44) )
return 0LL;
tcpbuf_dequeue(a1 + 8, (unsigned int)(v2 + 1));
*(_DWORD *)(a1 + 40) = -1;
advance_in_pos_isra_0(a1);
return 1LL;
}

original_code:
int
linepiper_dequeue(linepiper *lp)
{
    const char *t;
    if(lp->in_pos<0)
        return 0;
    t=tcpbuf_data(&lp->buf_in);
    if(t[lp->in_pos]!=lp->delim)
        return 0;
    tcpbuf_dequeue(&lp->buf_in, (lp->in_pos)+1);
    lp->in_pos=-1;
    advance_in_pos(lp);
    return 1;
}

canonical_original_code:
int linepiper_dequeue(struct linepiper *lp)
{
    char *t;
    if(lp->in_pos<0)
        return 0;
    t=tcpbuf_data(&lp->buf_in);
    if(t[lp->in_pos]!=lp->delim)
        return 0;
    tcpbuf_dequeue(&lp->buf_in, (lp->in_pos)+1);
    lp->in_pos=-1;
    advance_in_pos(lp);
    return 1;
}

variable_types: struct linepiper { int fd_in; int fd_out; struct tcpbuf { int len; int pos; unsigned char *data; } buf_in; struct tcpbuf buf_out; int in_pos; char delim; } *

variable_types:
t
char *

return_type: int

user_defined_types: struct linepiper { int fd_in; int fd_out; struct tcpbuf buf_in; struct tcpbuf buf_out; int in_pos; char delim; }


decompiled_code:
__int64 __fastcall linepiper_line(__int64 a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rax
__int64 v5; // rcx
__int64 result; // rax

if ( *(int *)(a1 + 40) < 0 )
return 0LL;
v4 = tcpbuf_data(a1 + 8);
v5 = *(int *)(a1 + 40);
if ( *(_BYTE *)(v4 + v5) != *(_BYTE *)(a1 + 44) )
return 0LL;
if ( a2 )
*a2 = v4;
result = 1LL;
if ( a3 )
*a3 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rax
__int64 v5; // rcx
__int64 result; // rax

if ( *(int *)(a1 + 40) < 0 )
return 0LL;
v4 = tcpbuf_data(a1 + 8);
v5 = *(int *)(a1 + 40);
if ( *(_BYTE *)(v4 + v5) != *(_BYTE *)(a1 + 44) )
return 0LL;
if ( a2 )
*a2 = v4;
result = 1LL;
if ( a3 )
*a3 = v5;
return result;
}

original_code:
int
linepiper_line(linepiper *lp, const char **data, int *len)
{
    const char *t;
    if(lp->in_pos<0)
        return 0;
    t=tcpbuf_data(&lp->buf_in);
    if(t[lp->in_pos]!=lp->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lp->in_pos;
    return 1;
}

canonical_original_code:
int linepiper_line(struct linepiper *lp, char **data, int *len)
{
    char *t;
    if(lp->in_pos<0)
        return 0;
    t=tcpbuf_data(&lp->buf_in);
    if(t[lp->in_pos]!=lp->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lp->in_pos;
    return 1;
}

variable_types:
data
char **

variable_types:
len
int *

user_defined_types: struct tcpbuf { int len; int pos; unsigned char *data; }


decompiled_code:
int __fastcall print_pollpool_state(__int64 a1)
{
__int64 v2; // rbp
__int64 v3; // rdi
unsigned int v4; // eax
int v5; // ebp
int v6; // eax

printf("pollconns: ");
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
v4 = pollconn_sock(*(_QWORD *)(a1 + 8) + (v3 << 7));
printf("%d ", v4);
}
while ( *(_DWORD *)a1 > (int)v2 );
}
putchar(10);
printf("freelist: ");
if ( *(int *)(a1 + 36) > 0 )
{
v5 = 0;
do
{
v6 = v5 + *(_DWORD *)(a1 + 32);
++v5;
printf("%d ", *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL * (v6 % *(_DWORD *)a1)));
}
while ( *(_DWORD *)(a1 + 36) > v5 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v2; // rbp
__int64 v3; // rdi
unsigned int v4; // eax
int v5; // ebp
int v6; // eax

printf("pollconns: ");
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
v4 = pollconn_sock(*(_QWORD *)(a1 + 8) + (v3 << 7));
printf("%d ", v4);
}
while ( *(_DWORD *)a1 > (int)v2 );
}
putchar(10);
printf("freelist: ");
if ( *(int *)(a1 + 36) > 0 )
{
v5 = 0;
do
{
v6 = v5 + *(_DWORD *)(a1 + 32);
++v5;
printf("%d ", *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL * (v6 % *(_DWORD *)a1)));
}
while ( *(_DWORD *)(a1 + 36) > v5 );
}
return putchar(10);
}

original_code:
void
print_pollpool_state(const pollpool *p)
{
    int i;
    printf("pollconns: ");
    for(i=0; i<p->len; i++)
        printf("%d ", pollconn_sock(p->pollconns+i));
    printf("\n");
    printf("freelist: ");
    for(i=0; i<p->freelist_len; i++)
    {
        printf("%d ", p->freelist[(p->freelist_head+i)%p->len]);
    }
    printf("\n");
}

canonical_original_code:
void print_pollpool_state(struct pollpool *p)
{
    int i;
    printf("pollconns: ");
    for(i=0; i<p->len; i++)
        printf("%d ", pollconn_sock(p->pollconns+i));
    printf("\n");
    printf("freelist: ");
    for(i=0; i<p->freelist_len; i++)
    {
        printf("%d ", p->freelist[(p->freelist_head+i)%p->len]);
    }
    printf("\n");
}

variable_types: struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } *

variable_types: i int

return_type: void

user_defined_types: struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; }

user_defined_types: struct pollconn { struct pollsock s; struct sockaddr_in saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; }

user_defined_types: struct pollsock { struct pollfd *pfd; struct tcpbuf sendbuf; struct tcpbuf recvbuf; }

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:
__int64 handle_cmd_quit()
{
return 0LL;
}

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

original_code:
int handle_cmd_quit(char *cmd)
{
    return 0;
}

variable_types:
cmd
char *


original_code:
int handle_cmd(char *cmd)
{
    int i, len;
    len=strlen(cmd);
    const char *args;
    for(i=0; i<len; i++)
    {
        if(cmd[i]==' ')
        {
            cmd[i]='\0';
            break;
        }
    }
    args=cmd+i+1;
    if(strcmp(cmd, "add")==0)
        return handle_cmd_add(cmd+i+1);
    else if(strcmp(cmd, "del")==0)
        return handle_cmd_del(cmd+i+1);
    else if(strcmp(cmd, "print")==0)
        return handle_cmd_print(cmd+i+1);
    else if(strcmp(cmd, "quit")==0 || strcmp(cmd, "exit")==0)
        return handle_cmd_quit(cmd+i+1);
    else
    {
        printf("Unrecognized command.\n");
        return 1;
    }
}

canonical_original_code:
int handle_cmd(char *cmd)
{
    int i; int len;
    len=strlen(cmd);
    char *args;
    for(i=0; i<len; i++)
    {
        if(cmd[i]==' ')
        {
            cmd[i]='\0';
            break;
        }
    }
    args=cmd+i+1;
    if(strcmp(cmd, "add")==0)
        return handle_cmd_add(cmd+i+1);
    else if(strcmp(cmd, "del")==0)
        return handle_cmd_del(cmd+i+1);
    else if(strcmp(cmd, "print")==0)
        return handle_cmd_print(cmd+i+1);
    else if(strcmp(cmd, "quit")==0 || strcmp(cmd, "exit")==0)
        return handle_cmd_quit(cmd+i+1);
    else
    {
        printf("Unrecognized command.\n");
        return 1;
    }
}

variable_types:
args
char *


decompiled_code:
__int64 daemon_init()
{
__pid_t v0; // eax
unsigned int v1; // er12

v0 = fork();
if ( v0 < 0 )
return (unsigned int)-1;
if ( v0 )
exit(0);
v1 = 0;
setsid();
chdir("/");
umask(0);
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
__pid_t v0; // eax
unsigned int v1; // er12

v0 = fork();
if ( v0 < 0 )
return (unsigned int)-1;
if ( v0 )
exit(0);
v1 = 0;
setsid();
chdir("/");
umask(0);
return v1;
}

original_code:
int
daemon_init(void)
{
    pid_t pid;
    if((pid=fork())<0)
        return -1;
    if(pid!=0)
        exit(0);
    setsid();
    chdir("/");
    umask(0);
    return 0;
}

canonical_original_code:
int daemon_init()
{
    int pid;
    if((pid=fork())<0)
        return -1;
    if(pid!=0)
        exit(0);
    setsid();
    chdir("/");
    umask(0);
    return 0;
}

variable_types: pid int


decompiled_code:
__int64 __fastcall pipe_std_exec(_DWORD *a1, int *a2, const char *a3, char *const *a4)
{
unsigned int v7; // er12
__pid_t v8; // eax
int v9; // edi
int v11; // eax
int v12; // eax
int v13; // eax
int v14; // eax
int fd; // [rsp+0h] [rbp-38h] BYREF
int v16; // [rsp+4h] [rbp-34h]
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

v7 = pipe(&fd);
if ( v7 != -1 )
{
v7 = pipe(pipedes);
if ( v7 == -1 )
{
close(fd);
close(v16);
}
else
{
v8 = fork();
v7 = v8;
if ( v8 == -1 )
{
close(fd);
close(v16);
close(pipedes[0]);
close(pipedes[1]);
}
else if ( v8
|| (close(pipedes[0]),
close(v16),
v11 = fileno(stdout),
dup2(pipedes[1], v11),
v12 = fileno(stdin),
dup2(fd, v12),
execv(a3, a4) != -1) )
{
v9 = pipedes[1];
*a1 = pipedes[0];
*a2 = v16;
close(v9);
close(fd);
}
else
{
v7 = -1;
close(pipedes[1]);
close(fd);
v13 = fileno(stdout);
close(v13);
v14 = fileno(stdin);
close(v14);
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int *a2, const char *a3, char *const *a4)
{
unsigned int v7; // er12
__pid_t v8; // eax
int v9; // edi
int v11; // eax
int v12; // eax
int v13; // eax
int v14; // eax
int fd; // [rsp+0h] [rbp-38h] BYREF
int v16; // [rsp+4h] [rbp-34h]
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

v7 = pipe(&fd);
if ( v7 != -1 )
{
v7 = pipe(pipedes);
if ( v7 == -1 )
{
close(fd);
close(v16);
}
else
{
v8 = fork();
v7 = v8;
if ( v8 == -1 )
{
close(fd);
close(v16);
close(pipedes[0]);
close(pipedes[1]);
}
else if ( v8
|| (close(pipedes[0]),
close(v16),
v11 = fileno(stdout),
dup2(pipedes[1], v11),
v12 = fileno(stdin),
dup2(fd, v12),
execv(a3, a4) != -1) )
{
v9 = pipedes[1];
*a1 = pipedes[0];
*a2 = v16;
close(v9);
close(fd);
}
else
{
v7 = -1;
close(pipedes[1]);
close(fd);
v13 = fileno(stdout);
close(v13);
v14 = fileno(stdin);
close(v14);
}
}
}
return v7;
}

original_code:
pid_t pipe_std_exec(int *fd_stdout, int *fd_stdin,
                    const char *path, char *const argv[])
{
    pid_t ret;
    int in[2];
    int out[2];
    if(pipe(in)==-1)
        return -1;
    if(pipe(out)==-1)
    {
        close(in[0]);
        close(in[1]);
        return -1;
    }
    if((ret=fork())==-1)
    {
        close(in[0]);
        close(in[1]);
        close(out[0]);
        close(out[1]);
        return -1;
    }
    if(ret==0)
    {
        close(out[0]);
        close(in[1]);
        dup2(out[1], fileno(stdout));
        dup2(in[0], fileno(stdin));
        if(execv(path, argv)==-1)
        {
            close(out[1]);
            close(in[0]);
            close(fileno(stdout));
            close(fileno(stdin));
            return -1;
        }
    }
    *fd_stdout=out[0];
    *fd_stdin=in[1];
    close(out[1]);
    close(in[0]);
    return ret;
}

canonical_original_code:
int pipe_std_exec(int *fd_stdout, int *fd_stdin, char *path, char *argv[])
{
    int ret;
    int in[2];
    int out[2];
    if(pipe(in)==-1)
        return -1;
    if(pipe(out)==-1)
    {
        close(in[0]);
        close(in[1]);
        return -1;
    }
    if((ret=fork())==-1)
    {
        close(in[0]);
        close(in[1]);
        close(out[0]);
        close(out[1]);
        return -1;
    }
    if(ret==0)
    {
        close(out[0]);
        close(in[1]);
        dup2(out[1], fileno(stdout));
        dup2(in[0], fileno(stdin));
        if(execv(path, argv)==-1)
        {
            close(out[1]);
            close(in[0]);
            close(fileno(stdout));
            close(fileno(stdin));
            return -1;
        }
    }
    *fd_stdout=out[0];
    *fd_stdin=in[1];
    close(out[1]);
    close(in[0]);
    return ret;
}

variable_types:
path
char *

variable_types:
argv
char *[]

variable_types: ret int

variable_types:
in
int [2]

variable_types:
out
int [2]


decompiled_code:
int print_usage_str()
{
return fprintf(
stderr,
"Usage: pipeserve <-p port (default %d)>\n"
" <-n max clients (default %d)>\n"
" <-s send buffer size (default %d)>\n"
" <-r receive buffer size (default %d)>\n"
" <-i pipe read buffer size (default %d)>\n"
" <-o pipe write buffer size (defaut %d)>\n"
" <-f (run in the foreground)\n"
" [path] args...\n",
7584LL,
1000LL,
4096LL,
4096LL,
0x100000LL,
0x100000LL);
}

canonical_decompiled_code:
int func2()
{
return fprintf(
stderr,
"Usage: pipeserve <-p port (default %d)>\n"
" <-n max clients (default %d)>\n"
" <-s send buffer size (default %d)>\n"
" <-r receive buffer size (default %d)>\n"
" <-i pipe read buffer size (default %d)>\n"
" <-o pipe write buffer size (defaut %d)>\n"
" <-f (run in the foreground)\n"
" [path] args...\n",
7584LL,
1000LL,
4096LL,
4096LL,
0x100000LL,
0x100000LL);
}


decompiled_code:
__int64 __fastcall read_args(int argc, char **argv)
{
char v2; // al
__int64 result; // rax
void *v4; // rax
int v5; // er12
char *v6; // rcx
char *v7; // rax

while ( 2 )
{
v2 = getopt(argc, argv, "p:n:s:r:i:o:f");
if ( v2 == -1 )
{
if ( argc - optind <= 0 )
{
print_usage_str();
result = 0LL;
}
else
{
execv_path = argv[optind];
v4 = malloc(8LL * (argc - optind + 1));
v5 = optind;
execv_argv = v4;
v6 = (char *)v4;
if ( argc > optind )
{
v7 = (char *)memcpy(v4, &argv[optind], 8LL * (unsigned int)(argc + ~optind) + 8);
optind = argc;
v6 = &v7[8 * (argc - v5)];
}
*(_QWORD *)v6 = 0LL;
result = 1LL;
}
}
else
{
switch ( v2 )
{
case 'f':
foreground = 1;
continue;
case 'i':
inbuf_len = atoi(optarg);
if ( inbuf_len > 0 )
continue;
fwrite("Error: invalid pipe read buffer size.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
break;
case 'n':
max_clients = atoi(optarg);
if ( max_clients > 0 )
continue;
fwrite("Error: invalid number of max clients.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
break;
case 'o':
outbuf_len = atoi(optarg);
if ( outbuf_len > 0 )
continue;
fwrite("Error: invalid pipe out buffer size.\n", 1uLL, 0x25uLL, stderr);
result = 0LL;
break;
case 'p':
listen_port = atoi(optarg);
if ( listen_port > 0 )
continue;
fwrite("Error: invalid port.\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
break;
case 'r':
recvbuf_len = atoi(optarg);
if ( recvbuf_len > 0 )
continue;
fwrite("Error: invalid receive buffer size.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
break;
case 's':
sendbuf_len = atoi(optarg);
if ( sendbuf_len > 0 )
continue;
fwrite("Error: invalid send buffer size.\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
break;
default:
continue;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv)
{
char v2; // al
__int64 result; // rax
void *v4; // rax
int v5; // er12
char *v6; // rcx
char *v7; // rax

while ( 2 )
{
v2 = getopt(argc, argv, "p:n:s:r:i:o:f");
if ( v2 == -1 )
{
if ( argc - optind <= 0 )
{
func2();
result = 0LL;
}
else
{
execv_path = argv[optind];
v4 = malloc(8LL * (argc - optind + 1));
v5 = optind;
execv_argv = v4;
v6 = (char *)v4;
if ( argc > optind )
{
v7 = (char *)memcpy(v4, &argv[optind], 8LL * (unsigned int)(argc + ~optind) + 8);
optind = argc;
v6 = &v7[8 * (argc - v5)];
}
*(_QWORD *)v6 = 0LL;
result = 1LL;
}
}
else
{
switch ( v2 )
{
case 'f':
foreground = 1;
continue;
case 'i':
inbuf_len = atoi(optarg);
if ( inbuf_len > 0 )
continue;
fwrite("Error: invalid pipe read buffer size.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
break;
case 'n':
max_clients = atoi(optarg);
if ( max_clients > 0 )
continue;
fwrite("Error: invalid number of max clients.\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
break;
case 'o':
outbuf_len = atoi(optarg);
if ( outbuf_len > 0 )
continue;
fwrite("Error: invalid pipe out buffer size.\n", 1uLL, 0x25uLL, stderr);
result = 0LL;
break;
case 'p':
listen_port = atoi(optarg);
if ( listen_port > 0 )
continue;
fwrite("Error: invalid port.\n", 1uLL, 0x15uLL, stderr);
result = 0LL;
break;
case 'r':
recvbuf_len = atoi(optarg);
if ( recvbuf_len > 0 )
continue;
fwrite("Error: invalid receive buffer size.\n", 1uLL, 0x24uLL, stderr);
result = 0LL;
break;
case 's':
sendbuf_len = atoi(optarg);
if ( sendbuf_len > 0 )
continue;
fwrite("Error: invalid send buffer size.\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
break;
default:
continue;
}
}
break;
}
return result;
}

original_code:
int
read_args(int argc, char *argv[])
{
    int i;
    char opt;
    while((opt=getopt(argc, argv, "p:n:s:r:i:o:f"))!=-1)
    {
        switch(opt)
        {
        case 'p':
            listen_port=atoi(optarg);
            if(listen_port<=0)
            {
                fprintf(stderr, "Error: invalid port.\n");
                return 0;
            }
            break;
        case 'n':
            max_clients=atoi(optarg);
            if(max_clients<=0)
            {
                fprintf(stderr, "Error: invalid number of max clients.\n");
                return 0;
            }
            break;
        case 's':
            sendbuf_len=atoi(optarg);
            if(sendbuf_len<=0)
            {
                fprintf(stderr, "Error: invalid send buffer size.\n");
                return 0;
            }
            break;
        case 'r':
            recvbuf_len=atoi(optarg);
            if(recvbuf_len<=0)
            {
                fprintf(stderr, "Error: invalid receive buffer size.\n");
                return 0;
            }
            break;
        case 'i':
            inbuf_len=atoi(optarg);
            if(inbuf_len<=0)
            {
                fprintf(stderr, "Error: invalid pipe read buffer size.\n");
                return 0;
            }
            break;
        case 'o':
            outbuf_len=atoi(optarg);
            if(outbuf_len<=0)
            {
                fprintf(stderr, "Error: invalid pipe out buffer size.\n");
                return 0;
            }
            break;
        case 'f':
            foreground=1;
            break;
        }
    }
    if(argc-optind<=0)
    {
        print_usage_str();
        return 0;
    }
    execv_path=argv[optind];
    execv_argv=(char **)malloc(sizeof(char *)*(argc-optind+1));
    i=0;
    while(optind<argc)
    {
        execv_argv[i]=argv[optind];
        optind++;
        i++;
    }
    execv_argv[i]=(char *)((void *)0);
    return 1;
}

variable_types: argc int

variable_types: opt char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct pollfd *v4; // rax
const char *v5; // r12
struct pollfd *v6; // rbp
int v7; // er9
int v8; // eax
__int64 v9; // r8
int v10; // ebx
int v11; // [rsp+8h] [rbp-170h] BYREF
int v12; // [rsp+Ch] [rbp-16Ch] BYREF
char v13[360]; // [rsp+10h] [rbp-168h] BYREF

setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stdin, 0LL, 2, 0LL);
if ( (unsigned int)read_args(argc, (char **)argv) )
{
v4 = (struct pollfd *)malloc(8LL * (max_clients + 2));
v5 = execv_path;
v6 = v4;
if ( !strcmp(execv_path, "-") )
{
v11 = fileno(stdin);
v12 = fileno(stdout);
}
else if ( (int)pipe_std_exec(&v11, &v12, v5, (char *const *)execv_argv) < 0 )
{
perror("pipeserve execv");
return 0;
}
free(execv_argv);
v7 = v11;
v8 = max_clients;
v6->events = 1;
v9 = (unsigned int)recvbuf_len;
v6->fd = v7;
pipeserver_construct(v13, &v6[1], (unsigned int)(v8 + 1), (unsigned int)sendbuf_len, v9);
if ( (unsigned int)pipeserver_listen(v13, (unsigned __int16)listen_port) == -1 )
{
perror("pipeserver bind() and listen()");
pipeserver_destruct(v13);
}
else if ( foreground || (int)daemon_init() >= 0 )
{
v10 = -1;
while ( poll(v6, max_clients + 1, 250) != -1 )
{
pipeserver_operate(v13);
if ( (v6->revents & 1) != 0 )
v10 = pipeserver_read(v13);
while ( (int)pipeserver_process_in(v13) > 0 )
pipeserver_write(v13);
while ( (int)pipeserver_process_out(v13) > 0 )
;
if ( !v10 )
goto LABEL_15;
}
perror("pipeserver poll()");
LABEL_15:
pipeserver_destruct(v13);
free(v6);
}
else
{
perror("pipeserve backgrounding");
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct pollfd *v4; // rax
const char *v5; // r12
struct pollfd *v6; // rbp
int v7; // er9
int v8; // eax
__int64 v9; // r8
int v10; // ebx
int v11; // [rsp+8h] [rbp-170h] BYREF
int v12; // [rsp+Ch] [rbp-16Ch] BYREF
char v13[360]; // [rsp+10h] [rbp-168h] BYREF

setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stdin, 0LL, 2, 0LL);
if ( (unsigned int)func3(argc, (char **)argv) )
{
v4 = (struct pollfd *)malloc(8LL * (max_clients + 2));
v5 = execv_path;
v6 = v4;
if ( !strcmp(execv_path, "-") )
{
v11 = fileno(stdin);
v12 = fileno(stdout);
}
else if ( (int)func1(&v11, &v12, v5, (char *const *)execv_argv) < 0 )
{
perror("pipeserve execv");
return 0;
}
free(execv_argv);
v7 = v11;
v8 = max_clients;
v6->events = 1;
v9 = (unsigned int)recvbuf_len;
v6->fd = v7;
pipeserver_construct(v13, &v6[1], (unsigned int)(v8 + 1), (unsigned int)sendbuf_len, v9);
if ( (unsigned int)pipeserver_listen(v13, (unsigned __int16)listen_port) == -1 )
{
perror("pipeserver bind() and listen()");
pipeserver_destruct(v13);
}
else if ( foreground || (int)func0() >= 0 )
{
v10 = -1;
while ( poll(v6, max_clients + 1, 250) != -1 )
{
pipeserver_operate(v13);
if ( (v6->revents & 1) != 0 )
v10 = pipeserver_read(v13);
while ( (int)pipeserver_process_in(v13) > 0 )
pipeserver_write(v13);
while ( (int)pipeserver_process_out(v13) > 0 )
;
if ( !v10 )
goto LABEL_15;
}
perror("pipeserver poll()");
LABEL_15:
pipeserver_destruct(v13);
free(v6);
}
else
{
perror("pipeserve backgrounding");
}
}
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
    pipeserver server;
    struct pollfd *ufds;
    int fd_stdout, fd_stdin, ret=-1;
    setvbuf(stdout, ((void *)0), 2, 0);
    setvbuf(stdin, ((void *)0), 2, 0);
    if(!read_args(argc, argv))
        return 0;
    ufds=(struct pollfd*)malloc(sizeof(struct pollfd)*(max_clients+2));
    if(strcmp(execv_path, "-")==0)
    {
        fd_stdout=fileno(stdin);
        fd_stdin=fileno(stdout);
    }
    else if(pipe_std_exec(&fd_stdout, &fd_stdin, execv_path, execv_argv)<0)
    {
        perror("pipeserve execv");
        return 0;
    }
    free(execv_argv);
    ufds[0].fd=fd_stdout;
    ufds[0].events=0x001;
    pipeserver_construct(&server, ufds+1, max_clients+1,
                         sendbuf_len, recvbuf_len,
                         fd_stdout, fd_stdin,
                         inbuf_len, outbuf_len);
    if(pipeserver_listen(&server, listen_port)==-1)
    {
        perror("pipeserver bind() and listen()");
        pipeserver_destruct(&server);
        return 0;
    }
    if(!foreground && daemon_init()<0)
    {
        perror("pipeserve backgrounding");
        return 0;
    }
    while(1)
    {
        if(poll(ufds, max_clients+1, 250)==-1)
        {
            perror("pipeserver poll()");
            break;
        }
        pipeserver_operate(&server);
        if(ufds[0].revents&0x001)
            ret=pipeserver_read(&server);
        while(pipeserver_process_in(&server)>0)
            pipeserver_write(&server);
        while(pipeserver_process_out(&server)>0);
        if(ret==0)
            break;
    }
    pipeserver_destruct(&server);
    free(ufds);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct pipeserver server;
    struct pollfd *ufds;
    int fd_stdout; int fd_stdin; int ret = -1;
    setvbuf(stdout, ((void *)0), 2, 0);
    setvbuf(stdin, ((void *)0), 2, 0);
    if(!read_args(argc, argv))
        return 0;
    ufds=(struct pollfd *)malloc(sizeof(struct pollfd)*(max_clients+2));
    if(strcmp(execv_path, "-")==0)
    {
        fd_stdout=fileno(stdin);
        fd_stdin=fileno(stdout);
    }
    else if(pipe_std_exec(&fd_stdout, &fd_stdin, execv_path, execv_argv)<0)
    {
        perror("pipeserve execv");
        return 0;
    }
    free(execv_argv);
    ufds[0].fd=fd_stdout;
    ufds[0].events=0x001;
    pipeserver_construct(&server, ufds+1, max_clients+1,
                         sendbuf_len, recvbuf_len,
                         fd_stdout, fd_stdin,
                         inbuf_len, outbuf_len);
    if(pipeserver_listen(&server, listen_port)==-1)
    {
        perror("pipeserver bind() and listen()");
        pipeserver_destruct(&server);
        return 0;
    }
    if(!foreground && daemon_init()<0)
    {
        perror("pipeserve backgrounding");
        return 0;
    }
    while(1)
    {
        if(poll(ufds, max_clients+1, 250)==-1)
        {
            perror("pipeserver poll()");
            break;
        }
        pipeserver_operate(&server);
        if(ufds[0].revents&0x001)
            ret=pipeserver_read(&server);
        while(pipeserver_process_in(&server)>0)
            pipeserver_write(&server);
        while(pipeserver_process_out(&server)>0);
        if(ret==0)
            break;
    }
    pipeserver_destruct(&server);
    free(ufds);
    return 0;
}

variable_types: struct pipeserver { struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; } ls; struct linepiper { int fd_in; int fd_out; struct tcpbuf buf_in; struct tcpbuf buf_out; int in_pos; char delim; } lp; int accepted; int in_conn; int out_conn; enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 } in_event; enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 } out_event; char *in_data; int in_datalen; char *out_data; int out_datalen; char *msg; int msg_len; }

user_defined_types: struct pipeserver { struct lineserver ls; struct linepiper lp; int accepted; int in_conn; int out_conn; enum pipeserver_event in_event; enum pipeserver_event out_event; char *in_data; int in_datalen; char *out_data; int out_datalen; char *msg; int msg_len; }

user_defined_types: struct lineserver { struct pollset ps; struct pollconn ls; struct lineserver_client *clients; int num_clients; int max_clients; int next_conn_pos; char delim; }

user_defined_types: struct pollset { struct pollpool pp; struct pollconn **handles; int handles_len; }


repo: sheimi/tiny-find

decompiled_code:
void init_option()
{
*(&options + 1) = 0LL;
*(&options + 4) = 0LL;
*((_QWORD *)&options + 2) = -1LL;
*((_DWORD *)&options + 17) = 1;
options = 0LL;
*(&options + 2) = 0LL;
*(&options + 3) = 0LL;
}

canonical_decompiled_code:
void func0()
{
*(&options + 1) = 0LL;
*(&options + 4) = 0LL;
*((_QWORD *)&options + 2) = -1LL;
*((_DWORD *)&options + 17) = 1;
options = 0LL;
*(&options + 2) = 0LL;
*(&options + 3) = 0LL;
}

original_code:
static void init_option() {
  memset(&options, 0, sizeof(FindOption));
  options.max_depth = -1;
  options.min_depth = -1;
  options.no_actions = 1;
}


decompiled_code:
void __fastcall execute_exec(int a1, const char **a2, const char *a3, int a4)
{
size_t v4; // r15
const char **v7; // rax
const char **v8; // rbp
const char **v9; // rdx
const char **v10; // rbx
__int64 v11; // r14
__int64 v12; // rcx
const char *v13; // rax
const char *v14; // rdx
int v15; // eax

v4 = a1;
v7 = (const char **)malloc(v4 * 8);
v8 = v7;
if ( a1 <= 1 )
{
v7[v4 - 1] = 0LL;
if ( a4 )
{
fputc(34, stdout);
goto LABEL_11;
}
}
else
{
v9 = v7;
v10 = v7;
v11 = (unsigned int)(a1 - 2);
v12 = (__int64)&a2[v11 + 1];
do
{
while ( 1 )
{
v13 = *a2;
if ( **a2 != 123 || v13[1] != 125 || v13[2] )
break;
++a2;
*v9++ = a3;
if ( a2 == (const char **)v12 )
goto LABEL_8;
}
++a2;
*v9++ = v13;
}
while ( a2 != (const char **)v12 );
LABEL_8:
v8[v4 - 1] = 0LL;
if ( a4 )
{
fputc(34, stdout);
do
{
v14 = *v10++;
fprintf(stdout, "%s ", v14);
}
while ( v10 != &v8[v11 + 1] );
LABEL_11:
fwrite("\"?", 1uLL, 2uLL, stdout);
if ( (getchar() & 0xDF) != 89 )
return;
goto LABEL_12;
}
}
LABEL_12:
v15 = fork();
if ( v15 < 0 )
{
fwrite("ERROR\n", 1uLL, 6uLL, stderr);
}
else if ( v15 )
{
waitpid(v15, 0LL, 0);
}
else
{
execvp(*v8, (char *const *)v8);
}
free(v8);
}

canonical_decompiled_code:
void __fastcall func1(int a1, const char **a2, const char *a3, int a4)
{
size_t v4; // r15
const char **v7; // rax
const char **v8; // rbp
const char **v9; // rdx
const char **v10; // rbx
__int64 v11; // r14
__int64 v12; // rcx
const char *v13; // rax
const char *v14; // rdx
int v15; // eax

v4 = a1;
v7 = (const char **)malloc(v4 * 8);
v8 = v7;
if ( a1 <= 1 )
{
v7[v4 - 1] = 0LL;
if ( a4 )
{
fputc(34, stdout);
goto LABEL_11;
}
}
else
{
v9 = v7;
v10 = v7;
v11 = (unsigned int)(a1 - 2);
v12 = (__int64)&a2[v11 + 1];
do
{
while ( 1 )
{
v13 = *a2;
if ( **a2 != 123 || v13[1] != 125 || v13[2] )
break;
++a2;
*v9++ = a3;
if ( a2 == (const char **)v12 )
goto LABEL_8;
}
++a2;
*v9++ = v13;
}
while ( a2 != (const char **)v12 );
LABEL_8:
v8[v4 - 1] = 0LL;
if ( a4 )
{
fputc(34, stdout);
do
{
v14 = *v10++;
fprintf(stdout, "%s ", v14);
}
while ( v10 != &v8[v11 + 1] );
LABEL_11:
fwrite("\"?", 1uLL, 2uLL, stdout);
if ( (getchar() & 0xDF) != 89 )
return;
goto LABEL_12;
}
}
LABEL_12:
v15 = fork();
if ( v15 < 0 )
{
fwrite("ERROR\n", 1uLL, 6uLL, stderr);
}
else if ( v15 )
{
waitpid(v15, 0LL, 0);
}
else
{
execvp(*v8, (char *const *)v8);
}
free(v8);
}

original_code:
static void execute_exec(int argc, char ** argv, char * path, bool ask) {
  char ** argv_r = (char **)(malloc(sizeof(char *) * (argc)));
  int i = 0;
  for (i = 0; i < argc - 1; i++) {
    if ((strcmp(argv[i], "{}") == 0)) {
      argv_r[i] = path;
    } else {
      argv_r[i] = argv[i];
    }
  }
  argv_r[argc - 1] = '\0';
  if (ask) {
    fputs("\"", stdout);
    for (i = 0; i < argc - 1; i++) {
      fprintf(stdout, "%s ", argv_r[i]);
    }
    fputs("\"?", stdout);
    char o = getchar();
    if (o != 'y' && o != 'Y')
      return;
  }
  pid_t pid;
  if ((pid = fork()) < 0) {
    fprintf(stderr, "ERROR\n");
  } else if (pid == 0) {
    execvp(argv_r[0], argv_r);
  } else {
    waitpid(pid, ((void *)0), 0);
  }
  free(argv_r);
}

canonical_original_code:
static void execute_exec(int argc, char **argv, char *path, int ask) {
  char **argv_r = (char **)(malloc(sizeof(char *) * (argc)));
  int i = 0;
  for (i = 0; i < argc - 1; i++) {
    if ((strcmp(argv[i], "{}") == 0)) {
      argv_r[i] = path;
    } else {
      argv_r[i] = argv[i];
    }
  }
  argv_r[argc - 1] = '\0';
  if (ask) {
    fputs("\"", stdout);
    for (i = 0; i < argc - 1; i++) {
      fprintf(stdout, "%s ", argv_r[i]);
    }
    fputs("\"?", stdout);
    char o = getchar();
    if (o != 'y' && o != 'Y')
      return;
  }
  int pid;
  if ((pid = fork()) < 0) {
    fprintf(stderr, "ERROR\n");
  } else if (pid == 0) {
    execvp(argv_r[0], argv_r);
  } else {
    waitpid(pid, ((void *)0), 0);
  }
  free(argv_r);
}

variable_types:
argv
char **

variable_types: ask int

variable_types: o char


check

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

result = execute_filter_tree();
if ( !result )
return result;
if ( *((_DWORD *)&options + 6) )
{
execute_exec(*((_DWORD *)&options + 10), *((const char ***)&options + 4), *(const char **)(a1 + 48), 0);
if ( !*((_DWORD *)&options + 11) )
{
LABEL_4:
if ( !*((_DWORD *)&options + 16) )
goto LABEL_5;
LABEL_8:
fputs(*(const char **)(a1 + 48), stdout);
result = *((_DWORD *)&options + 17) | *((_DWORD *)&options + 15);
if ( result )
return fprintf(stdout, "%s\n", *(const char **)(a1 + 48));
return result;
}
}
else if ( !*((_DWORD *)&options + 11) )
{
goto LABEL_4;
}
execute_exec(*((_DWORD *)&options + 14), *((const char ***)&options + 6), *(const char **)(a1 + 48), 1);
if ( *((_DWORD *)&options + 16) )
goto LABEL_8;
LABEL_5:
result = *((_DWORD *)&options + 17) | *((_DWORD *)&options + 15);
if ( result )
return fprintf(stdout, "%s\n", *(const char **)(a1 + 48));
return result;
}

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

result = execute_filter_tree();
if ( !result )
return result;
if ( *((_DWORD *)&options + 6) )
{
func1(*((_DWORD *)&options + 10), *((const char ***)&options + 4), *(const char **)(a1 + 48), 0);
if ( !*((_DWORD *)&options + 11) )
{
LABEL_4:
if ( !*((_DWORD *)&options + 16) )
goto LABEL_5;
LABEL_8:
fputs(*(const char **)(a1 + 48), stdout);
result = *((_DWORD *)&options + 17) | *((_DWORD *)&options + 15);
if ( result )
return fprintf(stdout, "%s\n", *(const char **)(a1 + 48));
return result;
}
}
else if ( !*((_DWORD *)&options + 11) )
{
goto LABEL_4;
}
func1(*((_DWORD *)&options + 14), *((const char ***)&options + 6), *(const char **)(a1 + 48), 1);
if ( *((_DWORD *)&options + 16) )
goto LABEL_8;
LABEL_5:
result = *((_DWORD *)&options + 17) | *((_DWORD *)&options + 15);
if ( result )
return fprintf(stdout, "%s\n", *(const char **)(a1 + 48));
return result;
}

original_code:
static void check(FTSENT * ent) {
  if (execute_filter_tree(ent)) {
    if (options.is_exec) {
      execute_exec(options.argc, options.argv, ent->fts_path, 0);
    }
    if (options.is_ok) {
      execute_exec(options.ok_argc, options.ok_argv, ent->fts_path, 1);
    }
    if (options.is_print0) {
      fprintf(stdout, "%s", ent->fts_path);
    }
    if (options.is_print || options.no_actions){
      fprintf(stdout, "%s\n", ent->fts_path);
    }
  }
}

canonical_original_code:
static void check(struct _ftsent *ent) {
  if (execute_filter_tree(ent)) {
    if (options.is_exec) {
      execute_exec(options.argc, options.argv, ent->fts_path, 0);
    }
    if (options.is_ok) {
      execute_exec(options.ok_argc, options.ok_argv, ent->fts_path, 1);
    }
    if (options.is_print0) {
      fprintf(stdout, "%s", ent->fts_path);
    }
    if (options.is_print || options.no_actions){
      fprintf(stdout, "%s\n", ent->fts_path);
    }
  }
}

variable_types: struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; 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]; } *fts_statp; char fts_name[1]; } *

user_defined_types: struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; struct stat *fts_statp; char fts_name[1]; }

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 __fastcall consider_check(FTS *a1, FTSENT *a2)
{
int v2; // eax
u_short v3; // bx
int result; // eax

v2 = *((_DWORD *)&options + 5);
v3 = a2->fts_info;
if ( v2 >= 0 && v2 <= a2->fts_level )
{
fts_set(a1, a2, 4);
result = a2->fts_level;
if ( result > *((_DWORD *)&options + 5) )
return result;
goto LABEL_7;
}
result = *((_DWORD *)&options + 4);
if ( result < 0 || result <= a2->fts_level )
{
LABEL_7:
if ( v3 != 6 )
result = check((__int64)a2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(FTS *a1, FTSENT *a2)
{
int v2; // eax
u_short v3; // bx
int result; // eax

v2 = *((_DWORD *)&options + 5);
v3 = a2->fts_info;
if ( v2 >= 0 && v2 <= a2->fts_level )
{
fts_set(a1, a2, 4);
result = a2->fts_level;
if ( result > *((_DWORD *)&options + 5) )
return result;
goto LABEL_7;
}
result = *((_DWORD *)&options + 4);
if ( result < 0 || result <= a2->fts_level )
{
LABEL_7:
if ( v3 != 6 )
result = func2((__int64)a2);
}
return result;
}

original_code:
static void consider_check(FTS * fts, FTSENT * ent) {
  bool ignore = 0;
  if (ent->fts_info == 6) {
    ignore = 1;
  }
  if (options.max_depth >=0 && ent->fts_level >= options.max_depth) {
    fts_set(fts, ent, 4);
    if (ent->fts_level > options.max_depth)
      ignore = 1;
  } else if (options.min_depth >=0 && ent->fts_level < options.min_depth) {
    ignore = 1;
  }
  if (!ignore) {
    check(ent);
  }
}

canonical_original_code:
static void consider_check(struct FTS *fts, struct _ftsent *ent) {
  int ignore = 0;
  if (ent->fts_info == 6) {
    ignore = 1;
  }
  if (options.max_depth >=0 && ent->fts_level >= options.max_depth) {
    fts_set(fts, ent, 4);
    if (ent->fts_level > options.max_depth)
      ignore = 1;
  } else if (options.min_depth >=0 && ent->fts_level < options.min_depth) {
    ignore = 1;
  }
  if (!ignore) {
    check(ent);
  }
}

variable_types: struct FTS { struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; 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]; } *fts_statp; char fts_name[1]; } *fts_cur; struct _ftsent *fts_child; struct _ftsent **fts_array; unsigned long fts_dev; char *fts_path; int fts_rfd; int fts_pathlen; int fts_nitems; int (*fts_compar)(void *, void *); int fts_options; } *

variable_types:
ent
struct _ftsent *

variable_types: ignore int

user_defined_types: struct FTS { struct _ftsent *fts_cur; struct _ftsent *fts_child; struct _ftsent **fts_array; unsigned long fts_dev; char *fts_path; int fts_rfd; int fts_pathlen; int fts_nitems; int (*fts_compar)(void *, void *); int fts_options; }


decompiled_code:
void __fastcall __noreturn print_error(const char *a1)
{
if ( a1 )
fputs(a1, stderr);
else
fwrite("encounter a error, exit\n", 1uLL, 0x18uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1)
{
if ( a1 )
fputs(a1, stderr);
else
fwrite("encounter a error, exit\n", 1uLL, 0x18uLL, stderr);
exit(1);
}

original_code:
void print_error(const char * message) {
  if (message != ((void *)0)) {
    fputs(message, stderr);
  } else {
    fputs("encounter a error, exit\n", stderr);
  }
  exit(1);
}

canonical_original_code:
void print_error(char *message) {
  if (message != ((void *)0)) {
    fputs(message, stderr);
  } else {
    fputs("encounter a error, exit\n", stderr);
  }
  exit(1);
}

variable_types:
message
char *


decompiled_code:
void __fastcall __noreturn require_arg(const char *a1)
{
if ( a1 )
{
fprintf(stderr, "find: %s: requires additional arguments\n", a1);
exit(1);
}
print_error("find: requires additional arguments\n");
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
if ( a1 )
{
fprintf(stderr, "find: %s: requires additional arguments\n", a1);
exit(1);
}
func4("find: requires additional arguments\n");
}

original_code:
void require_arg(const char * exp) {
  if (exp != ((void *)0)) {
    fprintf(stderr, "find: %s: requires additional arguments\n", exp);
    exit(1);
  } else {
    print_error("find: requires additional arguments\n");
  }
}

canonical_original_code:
void require_arg(char *exp) {
  if (exp != ((void *)0)) {
    fprintf(stderr, "find: %s: requires additional arguments\n", exp);
    exit(1);
  } else {
    print_error("find: requires additional arguments\n");
  }
}

variable_types:
exp
char *


main

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

if ( argc <= 1 )
print_error(USAGE);
init_option();
init_parser(argc, argv);
init_filter_tree((unsigned int)argc);
free_parser();
if ( (int)options > 0 )
{
v3 = 0;
do
{
++v3;
find(**((char ***)&options + 1));
}
while ( (int)options > v3 );
}
free_filter_tree();
return 0;
}

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

if ( argc <= 1 )
func4(USAGE);
func0();
init_parser(argc, argv);
init_filter_tree((unsigned int)argc);
free_parser();
if ( (int)options > 0 )
{
v3 = 0;
do
{
++v3;
find(**((char ***)&options + 1));
}
while ( (int)options > v3 );
}
free_filter_tree();
return 0;
}

original_code:
int main(int argc, char * argv[]) {
  if (argc < 2) {
    print_error(USAGE);
  }
  init_option();
  init_parser(argc, argv);
  init_filter_tree(argc);
  free_parser();
  int i;
  for (i = 0; i < options.pathes_num; i++) {
    find(options.find_pathes[0]);
  }
  free_filter_tree();
  free_option();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if (argc < 2) {
    print_error(USAGE);
  }
  init_option();
  init_parser(argc, argv);
  init_filter_tree(argc);
  free_parser();
  int i;
  for (i = 0; i < options.pathes_num; i++) {
    find(options.find_pathes[0]);
  }
  free_filter_tree();
  free_option();
  return 0;
}

variable_types: i int


decompiled_code:
__int64 get_exp()
{
int v0; // eax

v0 = i_0;
if ( post_exp_index - 1 == i_0 )
return 0LL;
++i_0;
return *((_QWORD *)post_exp + v0 + 1);
}

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

v0 = i_0;
if ( post_exp_index - 1 == i_0 )
return 0LL;
++i_0;
return *((_QWORD *)post_exp + v0 + 1);
}

original_code:
char * get_exp() {
  static int i = -1;
  if (i == post_exp_index - 1) {
    return ((void *)0);
  }
  i++;
  return post_exp[i];
}

canonical_original_code:
char *get_exp() {
  static int i = -1;
  if (i == post_exp_index - 1) {
    return ((void *)0);
  }
  i++;
  return post_exp[i];
}

return_type: char *


decompiled_code:
__int64 __fastcall is_exp(char *s1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = ALL_EXP_LEN;
if ( ALL_EXP_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, (&ALL_EXP)[v2]) )
{
if ( ++v2 == v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = ALL_EXP_LEN;
if ( ALL_EXP_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, (&ALL_EXP)[v2]) )
{
if ( ++v2 == v1 )
return 0LL;
}
return 1LL;
}

original_code:
bool is_exp(char * arg) {
  int i;
  for (i = 0; i < ALL_EXP_LEN; i++) {
    if ((strcmp(arg, ALL_EXP[i]) == 0))
      return 1;
  }
  return 0;
}

canonical_original_code:
int is_exp(char *arg) {
  int i;
  for (i = 0; i < ALL_EXP_LEN; i++) {
    if ((strcmp(arg, ALL_EXP[i]) == 0))
      return 1;
  }
  return 0;
}

variable_types:
arg
char *


decompiled_code:
__int64 __fastcall is_options(char *s1)
{
int v1; // er12
__int64 v2; // rbx

v1 = OPTIONS_LEN;
if ( OPTIONS_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, OPTIONS[v2]) )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
int v1; // er12
__int64 v2; // rbx

v1 = OPTIONS_LEN;
if ( OPTIONS_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, OPTIONS[v2]) )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

original_code:
bool is_options(char * arg) {
  int i;
  for (i = 0; i < OPTIONS_LEN; i++) {
    if ((strcmp(arg, OPTIONS[i]) == 0))
      return 1;
  }
  return 0;
}

canonical_original_code:
int is_options(char *arg) {
  int i;
  for (i = 0; i < OPTIONS_LEN; i++) {
    if ((strcmp(arg, OPTIONS[i]) == 0))
      return 1;
  }
  return 0;
}


decompiled_code:
_BOOL8 __fastcall is_logic_op(const char *a1)
{
_BOOL4 v1; // er8
int v3; // edx
int v4; // edx

v1 = 1;
if ( strcmp(a1, "-and") )
{
if ( strcmp(a1, "-or") )
{
if ( strcmp(a1, "-not") )
{
v3 = *(unsigned __int8 *)a1;
if ( v3 != 40 || a1[1] )
{
v4 = v3 - 41;
if ( !v4 )
v4 = *((unsigned __int8 *)a1 + 1);
v1 = v4 == 0;
}
}
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
_BOOL4 v1; // er8
int v3; // edx
int v4; // edx

v1 = 1;
if ( strcmp(a1, "-and") )
{
if ( strcmp(a1, "-or") )
{
if ( strcmp(a1, "-not") )
{
v3 = *(unsigned __int8 *)a1;
if ( v3 != 40 || a1[1] )
{
v4 = v3 - 41;
if ( !v4 )
v4 = *((unsigned __int8 *)a1 + 1);
v1 = v4 == 0;
}
}
}
}
return v1;
}

original_code:
bool is_logic_op(char * exp) {
  return (strcmp(exp, "-and") == 0) || (strcmp(exp, "-or") == 0) || (strcmp(exp, "-not") == 0)
         || (strcmp(exp, "(") == 0) || (strcmp(exp, ")") == 0);
}

canonical_original_code:
int is_logic_op(char *exp) {
  return (strcmp(exp, "-and") == 0) || (strcmp(exp, "-or") == 0) || (strcmp(exp, "-not") == 0)
         || (strcmp(exp, "(") == 0) || (strcmp(exp, ")") == 0);
}


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

v1 = post_exp_index;
*((_QWORD *)post_exp + post_exp_index) = a1;
result = (unsigned int)(v1 + 1);
post_exp_index = result;
return result;
}

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

v1 = post_exp_index;
*((_QWORD *)post_exp + post_exp_index) = a1;
result = (unsigned int)(v1 + 1);
post_exp_index = result;
return result;
}

original_code:
void push_back_exp(char * exp) {
  post_exp[post_exp_index] = exp;
  post_exp_index++;
}

canonical_original_code:
void push_back_exp(char *exp) {
  post_exp[post_exp_index] = exp;
  post_exp_index++;
}


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

v1 = stack_index;
*((_QWORD *)help_stack + stack_index) = a1;
result = (unsigned int)(v1 + 1);
stack_index = result;
return result;
}

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

v1 = stack_index;
*((_QWORD *)help_stack + stack_index) = a1;
result = (unsigned int)(v1 + 1);
stack_index = result;
return result;
}

original_code:
void push_stack(char * exp) {
  help_stack[stack_index] = exp;
  stack_index++;
}

canonical_original_code:
void push_stack(char *exp) {
  help_stack[stack_index] = exp;
  stack_index++;
}


decompiled_code:
__int64 pop_stack()
{
return *((_QWORD *)help_stack + --stack_index);
}

canonical_decompiled_code:
__int64 func6()
{
return *((_QWORD *)help_stack + --stack_index);
}

original_code:
char * pop_stack() {
  stack_index--;
  return help_stack[stack_index];
}

canonical_original_code:
char *pop_stack() {
  stack_index--;
  return help_stack[stack_index];
}


decompiled_code:
void *top_stack()
{
void *v0; // r8

v0 = &unk_A76;
if ( stack_index )
v0 = (void *)*((_QWORD *)help_stack + stack_index - 1);
return v0;
}

canonical_decompiled_code:
void *func7()
{
void *v0; // r8

v0 = &unk_A76;
if ( stack_index )
v0 = (void *)*((_QWORD *)help_stack + stack_index - 1);
return v0;
}

original_code:
char * top_stack() {
  if (stack_index == 0) {
    return "";
  }
  return help_stack[stack_index - 1];
}

canonical_original_code:
char *top_stack() {
  if (stack_index == 0) {
    return "";
  }
  return help_stack[stack_index - 1];
}


decompiled_code:
_BOOL8 stack_empty()
{
return stack_index == 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return stack_index == 0;
}

original_code:
bool stack_empty() {
  return stack_index == 0;
}

canonical_original_code:
int stack_empty() {
  return stack_index == 0;
}


decompiled_code:
_BOOL8 __fastcall set_post_exp(const char *a1, const char *a2)
{
const char *v2; // r14
int v3; // ebx
unsigned __int8 **v4; // rax
int v5; // ebp
unsigned __int8 *v6; // rdx
unsigned __int8 **v7; // rcx
int v8; // ecx
__int64 v9; // rax
const char *v10; // r12
char *v11; // r9
int v12; // er13
bool v13; // cf
bool v14; // zf
int v15; // er12
__int64 v16; // rcx
int v17; // er15
const char *v18; // rdi
char v19; // al
bool v20; // cf
bool v21; // zf
const char *v22; // rdi
__int64 v23; // rcx
char v24; // al
bool v25; // cf
bool v26; // zf
_BOOL8 result; // rax
__int64 v28; // rdx
__int64 v29; // rcx
const char *v30; // rdi
__int64 v31; // rcx
char v32; // al
bool v33; // cf
bool v34; // zf
__int64 v35; // rcx
char v36; // al
bool v37; // cf
bool v38; // zf
__int64 v39; // rcx
char v40; // al
bool v41; // cf
bool v42; // zf
__int64 v43; // rcx
char v44; // al
bool v45; // cf
bool v46; // zf
const char *v47; // rcx
_BYTE *v48; // rax
__int64 v49; // rax
_BYTE *v50; // rcx
int v51; // eax
__int64 v52; // rcx
unsigned int v53; // eax
bool v54; // cf
bool v55; // zf
__int64 v56; // rdi
__int64 v57; // rdx
_BYTE *v58; // rax
bool v59; // cf
bool v60; // zf
__int64 v61; // rdx
__int64 v62; // rcx
char v63; // al
bool v64; // cf
bool v65; // zf
const char *v66; // rdi
__int64 v67; // rcx
bool v68; // cf
bool v69; // zf
__int64 v70; // rcx
const char *v71; // rdi
char v72; // al
bool v73; // cf
bool v74; // zf
const char *v75; // rdi
__int64 v76; // rcx
char v77; // al
bool v78; // cf
bool v79; // zf
__int64 v80; // rcx
const char *v81; // rdi
const char *v82; // rcx
_BYTE *v83; // rax
__int64 v84; // rax
_BYTE *v85; // rcx
int v86; // eax
__int64 v87; // r9
_BYTE *v88; // rax
__int64 v89; // rdx
__int64 v90; // rcx
bool v91; // cf
bool v92; // zf
const char *v93; // rax
__int64 v94; // rcx
const char *v95; // rdi
bool v96; // cf
bool v97; // zf
__int64 v98; // rdx
__int64 v99; // rcx
int v100; // [rsp+4h] [rbp-44h]
__int64 v101; // [rsp+8h] [rbp-40h]

v2 = a2;
v3 = (int)a1;
if ( (int)a1 <= 1 )
{
v5 = 1;
v10 = a2 + 8;
goto LABEL_32;
}
v4 = (unsigned __int8 **)(a2 + 8);
v5 = 1;
while ( 1 )
{
while ( 1 )
{
v6 = *v4;
v7 = v4;
if ( **v4 != 45 )
goto LABEL_33;
v8 = v6[1];
++v5;
if ( v8 != 76 || v6[2] )
break;
*((_DWORD *)&options + 18) = 0;
LABEL_5:
++v4;
if ( (_DWORD)a1 == v5 )
goto LABEL_31;
}
a2 = (const char *)*v6;
if ( (_DWORD)a2 != 45 )
goto LABEL_5;
if ( v8 != 80 || v6[2] )
break;
*((_DWORD *)&options + 18) = 1;
++v4;
if ( (_DWORD)a1 == v5 )
{
LABEL_31:
v10 = &v2[8 * (int)a1];
goto LABEL_32;
}
}
if ( v8 == 72 && !v6[2] )
{
*((_DWORD *)&options + 18) = 2;
goto LABEL_5;
}
if ( v8 != 102 || v6[2] )
goto LABEL_5;
v9 = v5;
v10 = &v2[8 * v5];
if ( (int)a1 > v5 )
{
v11 = *(char **)&v2[8 * v5];
*((_QWORD *)&options + 1) = v10;
v12 = v5;
if ( *v11 != 45 )
goto LABEL_35;
goto LABEL_15;
}
LABEL_32:
a1 = (const char *)USAGE;
print_error(USAGE);
v7 = (unsigned __int8 **)v10;
LABEL_33:
*((_QWORD *)&options + 1) = v7;
v9 = v5;
if ( v3 > v5 )
{
while ( 1 )
{
v11 = *(char **)&v2[8 * v9];
v12 = v9;
if ( *v11 == 45 )
break;
LABEL_35:
++v9;
++options;
if ( v3 <= (int)v9 )
goto LABEL_39;
}
LABEL_15:
if ( v3 > (int)v9 )
{
v100 = 0;
v13 = 0;
v14 = 1;
v15 = 0;
while ( 1 )
{
v16 = 7LL;
a2 = v11;
v17 = v12 + 1;
v18 = "-depth";
do
{
if ( !v16 )
break;
v13 = *a2 < (unsigned int)*v18;
v14 = *a2++ == *v18++;
--v16;
}
while ( v14 );
v19 = (!v13 && !v14) - v13;
v20 = 0;
v21 = v19 == 0;
if ( !v19 )
{
a1 = *(const char **)&v2[8 * v17];
*((_DWORD *)&options + 5) = atoi(a1);
*((_DWORD *)&options + 4) = atoi(a1);
goto LABEL_18;
}
v22 = "-maxdepth";
v23 = 10LL;
a2 = v11;
do
{
if ( !v23 )
break;
v20 = *a2 < (unsigned int)*v22;
v21 = *a2++ == *v22++;
--v23;
}
while ( v21 );
v24 = (!v20 && !v21) - v20;
v25 = 0;
v26 = v24 == 0;
if ( !v24 )
{
a1 = *(const char **)&v2[8 * v17];
*((_DWORD *)&options + 5) = atoi(a1);
goto LABEL_18;
}
v30 = "-mindepth";
v31 = 10LL;
a2 = v11;
do
{
if ( !v31 )
break;
v25 = *a2 < (unsigned int)*v30;
v26 = *a2++ == *v30++;
--v31;
}
while ( v26 );
v32 = (!v25 && !v26) - v25;
v33 = 0;
v34 = v32 == 0;
if ( !v32 )
{
a1 = *(const char **)&v2[8 * v17];
*((_DWORD *)&options + 4) = atoi(a1);
goto LABEL_18;
}
a1 = "-exec";
v35 = 6LL;
a2 = v11;
do
{
if ( !v35 )
break;
v33 = *a2 < (unsigned int)*a1;
v34 = *a2++ == *a1++;
--v35;
}
while ( v34 );
v36 = (!v33 && !v34) - v33;
v37 = 0;
v38 = v36 == 0;
if ( v36 )
{
a1 = "-ok";
v39 = 4LL;
a2 = v11;
do
{
if ( !v39 )
break;
v37 = *a2 < (unsigned int)*a1;
v38 = *a2++ == *a1++;
--v39;
}
while ( v38 );
v40 = (!v37 && !v38) - v37;
v41 = 0;
v42 = v40 == 0;
if ( v40 )
{
a1 = "-print";
v43 = 7LL;
a2 = v11;
do
{
if ( !v43 )
break;
v41 = *a2 < (unsigned int)*a1;
v42 = *a2++ == *a1++;
--v43;
}
while ( v42 );
v44 = (!v41 && !v42) - v41;
v45 = 0;
v46 = v44 == 0;
if ( !v44 )
{
*((_DWORD *)&options + 17) = 0;
v17 = v12;
*((_DWORD *)&options + 15) = 1;
goto LABEL_18;
}
a1 = "-print0";
v52 = 8LL;
a2 = v11;
do
{
if ( !v52 )
break;
v45 = *a2 < (unsigned int)*a1;
v46 = *a2++ == *a1++;
--v52;
}
while ( v46 );
if ( (!v45 && !v46) == v45 )
{
*((_QWORD *)&options + 8) = 1LL;
v17 = v12;
goto LABEL_18;
}
v53 = (unsigned __int8)*v11;
if ( v53 == 40 && !v11[1] )
{
a1 = v11;
v17 = v12;
push_stack((__int64)v11);
goto LABEL_18;
}
v54 = v53 < 0x29;
v55 = v53 == 41;
if ( v53 == 41 && (v54 = 0, v55 = v11[1] == 0, !v11[1]) )
{
while ( !stack_empty() )
{
v58 = top_stack();
if ( *v58 == 40 && !v58[1] )
break;
v56 = ((__int64 (*)(void))pop_stack)();
push_back_exp(v56);
}
a1 = "-not";
v17 = v12;
pop_stack("-not", a2, v57, 5LL);
a2 = (const char *)top_stack();
do
{
if ( !v62 )
break;
v59 = *a2 < (unsigned int)*a1;
v60 = *a2++ == *a1++;
--v62;
}
while ( v60 );
v63 = (!v59 && !v60) - v59;
v64 = 0;
v65 = v63 == 0;
if ( !v63 )
{
v66 = "-and";
v67 = 5LL;
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
do
{
if ( !v67 )
break;
v64 = *a2 < (unsigned int)*v66;
v65 = *a2++ == *v66++;
--v67;
}
while ( v65 );
LOBYTE(v67) = (!v64 && !v65) - v64;
v68 = 0;
v69 = (_BYTE)v67 == 0;
if ( (_BYTE)v67 )
{
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
v66 = "-or";
v67 = 4LL;
do
{
if ( !v67 )
break;
v68 = *a2 < (unsigned int)*v66;
v69 = *a2++ == *v66++;
--v67;
}
while ( v69 );
if ( (!v68 && !v69) != v68 )
{
v66 = "-and";
push_back_exp((__int64)"-and");
}
}
v17 = v12;
a1 = (const char *)pop_stack(v66, a2, v61, v67);
push_back_exp((__int64)a1);
}
}
else
{
v70 = 5LL;
a2 = v11;
v71 = "-and";
do
{
if ( !v70 )
break;
v54 = *a2 < (unsigned int)*v71;
v55 = *a2++ == *v71++;
--v70;
}
while ( v55 );
v72 = (!v54 && !v55) - v54;
v73 = 0;
v74 = v72 == 0;
if ( v72 )
{
v75 = "-or";
v76 = 4LL;
a2 = v11;
do
{
if ( !v76 )
break;
v73 = *a2 < (unsigned int)*v75;
v74 = *a2++ == *v75++;
--v76;
}
while ( v74 );
v77 = (!v73 && !v74) - v73;
v78 = 0;
v79 = v77 == 0;
if ( !v77 )
{
while ( !stack_empty() )
{
v88 = top_stack();
if ( *v88 == 40 && !v88[1] )
break;
v75 = (const char *)pop_stack(v75, a2, v89, v90);
push_back_exp((__int64)v75);
}
LABEL_125:
a1 = (const char *)v87;
v15 = 0;
v17 = v12;
push_stack(v87);
goto LABEL_18;
}
v80 = 5LL;
a2 = v11;
v81 = "-not";
do
{
if ( !v80 )
break;
v78 = *a2 < (unsigned int)*v81;
v79 = *a2++ == *v81++;
--v80;
}
while ( v79 );
a1 = v11;
if ( (!v78 && !v79) == v78 )
{
push_stack((__int64)v11);
v17 = v12;
}
else
{
v101 = (__int64)v11;
a1 = v11;
if ( (unsigned int)is_exp(v11) )
{
push_back_exp(v101);
if ( v15 )
{
v100 = v15;
v17 = v12;
}
else
{
v17 = v12;
v15 = 1;
}
}
else
{
push_back_exp(v101);
a1 = "-not";
a2 = (const char *)top_stack();
do
{
if ( !v99 )
break;
v96 = *a2 < (unsigned int)*a1;
v97 = *a2++ == *a1++;
--v99;
}
while ( v97 );
if ( (!v96 && !v97) == v96 )
{
a1 = (const char *)pop_stack(a1, a2, v98, v99);
push_back_exp((__int64)a1);
}
v17 = v12;
if ( v100 )
{
a1 = "-and";
push_back_exp((__int64)"-and");
v100 = 0;
}
}
}
}
else
{
if ( stack_empty() )
goto LABEL_125;
v93 = (const char *)top_stack();
v94 = 5LL;
v95 = "-and";
a2 = v93;
do
{
if ( !v94 )
break;
v91 = *a2 < (unsigned int)*v95;
v92 = *a2++ == *v95++;
--v94;
}
while ( v92 );
v15 = (char)((!v91 && !v92) - v91);
if ( (!v91 && !v92) != v91 )
goto LABEL_125;
a1 = (const char *)v87;
v17 = v12;
push_back_exp(v87);
}
}
}
else
{
*((_DWORD *)&options + 11) = 1;
*((_DWORD *)&options + 17) = 0;
v82 = &v2[8 * v17];
v83 = (_BYTE *)*((_QWORD *)v82 + 1);
*((_QWORD *)&options + 6) = v82;
if ( *v83 == 59 )
{
v86 = 2;
}
else
{
v84 = v12 + 2;
do
{
v85 = *(_BYTE **)&v2[8 * v84 + 8];
v17 = v84++;
}
while ( *v85 != 59 );
v86 = v17 - v12 + 1;
}
*((_DWORD *)&options + 14) = v86;
++v17;
}
}
else
{
*((_DWORD *)&options + 6) = 1;
*((_DWORD *)&options + 17) = 0;
v47 = &v2[8 * v17];
v48 = (_BYTE *)*((_QWORD *)v47 + 1);
*((_QWORD *)&options + 4) = v47;
if ( *v48 == 59 )
{
v51 = 2;
}
else
{
v49 = v12 + 2;
do
{
v50 = *(_BYTE **)&v2[8 * v49 + 8];
v17 = v49++;
}
while ( *v50 != 59 );
v51 = v17 - v12 + 1;
}
*((_DWORD *)&options + 10) = v51;
++v17;
}
LABEL_18:
v12 = v17 + 1;
v13 = v3 < (unsigned int)(v17 + 1);
v14 = v3 == v17 + 1;
if ( v3 <= v17 + 1 )
break;
v11 = *(char **)&v2[8 * v12];
}
}
}
LABEL_39:
while ( 1 )
{
result = stack_empty();
if ( result )
break;
a1 = (const char *)pop_stack(a1, a2, v28, v29);
push_back_exp((__int64)a1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(const char *a1, const char *a2)
{
const char *v2; // r14
int v3; // ebx
unsigned __int8 **v4; // rax
int v5; // ebp
unsigned __int8 *v6; // rdx
unsigned __int8 **v7; // rcx
int v8; // ecx
__int64 v9; // rax
const char *v10; // r12
char *v11; // r9
int v12; // er13
bool v13; // cf
bool v14; // zf
int v15; // er12
__int64 v16; // rcx
int v17; // er15
const char *v18; // rdi
char v19; // al
bool v20; // cf
bool v21; // zf
const char *v22; // rdi
__int64 v23; // rcx
char v24; // al
bool v25; // cf
bool v26; // zf
_BOOL8 result; // rax
__int64 v28; // rdx
__int64 v29; // rcx
const char *v30; // rdi
__int64 v31; // rcx
char v32; // al
bool v33; // cf
bool v34; // zf
__int64 v35; // rcx
char v36; // al
bool v37; // cf
bool v38; // zf
__int64 v39; // rcx
char v40; // al
bool v41; // cf
bool v42; // zf
__int64 v43; // rcx
char v44; // al
bool v45; // cf
bool v46; // zf
const char *v47; // rcx
_BYTE *v48; // rax
__int64 v49; // rax
_BYTE *v50; // rcx
int v51; // eax
__int64 v52; // rcx
unsigned int v53; // eax
bool v54; // cf
bool v55; // zf
__int64 v56; // rdi
__int64 v57; // rdx
_BYTE *v58; // rax
bool v59; // cf
bool v60; // zf
__int64 v61; // rdx
__int64 v62; // rcx
char v63; // al
bool v64; // cf
bool v65; // zf
const char *v66; // rdi
__int64 v67; // rcx
bool v68; // cf
bool v69; // zf
__int64 v70; // rcx
const char *v71; // rdi
char v72; // al
bool v73; // cf
bool v74; // zf
const char *v75; // rdi
__int64 v76; // rcx
char v77; // al
bool v78; // cf
bool v79; // zf
__int64 v80; // rcx
const char *v81; // rdi
const char *v82; // rcx
_BYTE *v83; // rax
__int64 v84; // rax
_BYTE *v85; // rcx
int v86; // eax
__int64 v87; // r9
_BYTE *v88; // rax
__int64 v89; // rdx
__int64 v90; // rcx
bool v91; // cf
bool v92; // zf
const char *v93; // rax
__int64 v94; // rcx
const char *v95; // rdi
bool v96; // cf
bool v97; // zf
__int64 v98; // rdx
__int64 v99; // rcx
int v100; // [rsp+4h] [rbp-44h]
__int64 v101; // [rsp+8h] [rbp-40h]

v2 = a2;
v3 = (int)a1;
if ( (int)a1 <= 1 )
{
v5 = 1;
v10 = a2 + 8;
goto LABEL_32;
}
v4 = (unsigned __int8 **)(a2 + 8);
v5 = 1;
while ( 1 )
{
while ( 1 )
{
v6 = *v4;
v7 = v4;
if ( **v4 != 45 )
goto LABEL_33;
v8 = v6[1];
++v5;
if ( v8 != 76 || v6[2] )
break;
*((_DWORD *)&options + 18) = 0;
LABEL_5:
++v4;
if ( (_DWORD)a1 == v5 )
goto LABEL_31;
}
a2 = (const char *)*v6;
if ( (_DWORD)a2 != 45 )
goto LABEL_5;
if ( v8 != 80 || v6[2] )
break;
*((_DWORD *)&options + 18) = 1;
++v4;
if ( (_DWORD)a1 == v5 )
{
LABEL_31:
v10 = &v2[8 * (int)a1];
goto LABEL_32;
}
}
if ( v8 == 72 && !v6[2] )
{
*((_DWORD *)&options + 18) = 2;
goto LABEL_5;
}
if ( v8 != 102 || v6[2] )
goto LABEL_5;
v9 = v5;
v10 = &v2[8 * v5];
if ( (int)a1 > v5 )
{
v11 = *(char **)&v2[8 * v5];
*((_QWORD *)&options + 1) = v10;
v12 = v5;
if ( *v11 != 45 )
goto LABEL_35;
goto LABEL_15;
}
LABEL_32:
a1 = (const char *)USAGE;
print_error(USAGE);
v7 = (unsigned __int8 **)v10;
LABEL_33:
*((_QWORD *)&options + 1) = v7;
v9 = v5;
if ( v3 > v5 )
{
while ( 1 )
{
v11 = *(char **)&v2[8 * v9];
v12 = v9;
if ( *v11 == 45 )
break;
LABEL_35:
++v9;
++options;
if ( v3 <= (int)v9 )
goto LABEL_39;
}
LABEL_15:
if ( v3 > (int)v9 )
{
v100 = 0;
v13 = 0;
v14 = 1;
v15 = 0;
while ( 1 )
{
v16 = 7LL;
a2 = v11;
v17 = v12 + 1;
v18 = "-depth";
do
{
if ( !v16 )
break;
v13 = *a2 < (unsigned int)*v18;
v14 = *a2++ == *v18++;
--v16;
}
while ( v14 );
v19 = (!v13 && !v14) - v13;
v20 = 0;
v21 = v19 == 0;
if ( !v19 )
{
a1 = *(const char **)&v2[8 * v17];
*((_DWORD *)&options + 5) = atoi(a1);
*((_DWORD *)&options + 4) = atoi(a1);
goto LABEL_18;
}
v22 = "-maxdepth";
v23 = 10LL;
a2 = v11;
do
{
if ( !v23 )
break;
v20 = *a2 < (unsigned int)*v22;
v21 = *a2++ == *v22++;
--v23;
}
while ( v21 );
v24 = (!v20 && !v21) - v20;
v25 = 0;
v26 = v24 == 0;
if ( !v24 )
{
a1 = *(const char **)&v2[8 * v17];
*((_DWORD *)&options + 5) = atoi(a1);
goto LABEL_18;
}
v30 = "-mindepth";
v31 = 10LL;
a2 = v11;
do
{
if ( !v31 )
break;
v25 = *a2 < (unsigned int)*v30;
v26 = *a2++ == *v30++;
--v31;
}
while ( v26 );
v32 = (!v25 && !v26) - v25;
v33 = 0;
v34 = v32 == 0;
if ( !v32 )
{
a1 = *(const char **)&v2[8 * v17];
*((_DWORD *)&options + 4) = atoi(a1);
goto LABEL_18;
}
a1 = "-exec";
v35 = 6LL;
a2 = v11;
do
{
if ( !v35 )
break;
v33 = *a2 < (unsigned int)*a1;
v34 = *a2++ == *a1++;
--v35;
}
while ( v34 );
v36 = (!v33 && !v34) - v33;
v37 = 0;
v38 = v36 == 0;
if ( v36 )
{
a1 = "-ok";
v39 = 4LL;
a2 = v11;
do
{
if ( !v39 )
break;
v37 = *a2 < (unsigned int)*a1;
v38 = *a2++ == *a1++;
--v39;
}
while ( v38 );
v40 = (!v37 && !v38) - v37;
v41 = 0;
v42 = v40 == 0;
if ( v40 )
{
a1 = "-print";
v43 = 7LL;
a2 = v11;
do
{
if ( !v43 )
break;
v41 = *a2 < (unsigned int)*a1;
v42 = *a2++ == *a1++;
--v43;
}
while ( v42 );
v44 = (!v41 && !v42) - v41;
v45 = 0;
v46 = v44 == 0;
if ( !v44 )
{
*((_DWORD *)&options + 17) = 0;
v17 = v12;
*((_DWORD *)&options + 15) = 1;
goto LABEL_18;
}
a1 = "-print0";
v52 = 8LL;
a2 = v11;
do
{
if ( !v52 )
break;
v45 = *a2 < (unsigned int)*a1;
v46 = *a2++ == *a1++;
--v52;
}
while ( v46 );
if ( (!v45 && !v46) == v45 )
{
*((_QWORD *)&options + 8) = 1LL;
v17 = v12;
goto LABEL_18;
}
v53 = (unsigned __int8)*v11;
if ( v53 == 40 && !v11[1] )
{
a1 = v11;
v17 = v12;
func5((__int64)v11);
goto LABEL_18;
}
v54 = v53 < 0x29;
v55 = v53 == 41;
if ( v53 == 41 && (v54 = 0, v55 = v11[1] == 0, !v11[1]) )
{
while ( !func8() )
{
v58 = func7();
if ( *v58 == 40 && !v58[1] )
break;
v56 = ((__int64 (*)(void))pop_stack)();
func4(v56);
}
a1 = "-not";
v17 = v12;
func6("-not", a2, v57, 5LL);
a2 = (const char *)func7();
do
{
if ( !v62 )
break;
v59 = *a2 < (unsigned int)*a1;
v60 = *a2++ == *a1++;
--v62;
}
while ( v60 );
v63 = (!v59 && !v60) - v59;
v64 = 0;
v65 = v63 == 0;
if ( !v63 )
{
v66 = "-and";
v67 = 5LL;
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
do
{
if ( !v67 )
break;
v64 = *a2 < (unsigned int)*v66;
v65 = *a2++ == *v66++;
--v67;
}
while ( v65 );
LOBYTE(v67) = (!v64 && !v65) - v64;
v68 = 0;
v69 = (_BYTE)v67 == 0;
if ( (_BYTE)v67 )
{
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
v66 = "-or";
v67 = 4LL;
do
{
if ( !v67 )
break;
v68 = *a2 < (unsigned int)*v66;
v69 = *a2++ == *v66++;
--v67;
}
while ( v69 );
if ( (!v68 && !v69) != v68 )
{
v66 = "-and";
func4((__int64)"-and");
}
}
v17 = v12;
a1 = (const char *)func6(v66, a2, v61, v67);
func4((__int64)a1);
}
}
else
{
v70 = 5LL;
a2 = v11;
v71 = "-and";
do
{
if ( !v70 )
break;
v54 = *a2 < (unsigned int)*v71;
v55 = *a2++ == *v71++;
--v70;
}
while ( v55 );
v72 = (!v54 && !v55) - v54;
v73 = 0;
v74 = v72 == 0;
if ( v72 )
{
v75 = "-or";
v76 = 4LL;
a2 = v11;
do
{
if ( !v76 )
break;
v73 = *a2 < (unsigned int)*v75;
v74 = *a2++ == *v75++;
--v76;
}
while ( v74 );
v77 = (!v73 && !v74) - v73;
v78 = 0;
v79 = v77 == 0;
if ( !v77 )
{
while ( !func8() )
{
v88 = func7();
if ( *v88 == 40 && !v88[1] )
break;
v75 = (const char *)func6(v75, a2, v89, v90);
func4((__int64)v75);
}
LABEL_125:
a1 = (const char *)v87;
v15 = 0;
v17 = v12;
func5(v87);
goto LABEL_18;
}
v80 = 5LL;
a2 = v11;
v81 = "-not";
do
{
if ( !v80 )
break;
v78 = *a2 < (unsigned int)*v81;
v79 = *a2++ == *v81++;
--v80;
}
while ( v79 );
a1 = v11;
if ( (!v78 && !v79) == v78 )
{
func5((__int64)v11);
v17 = v12;
}
else
{
v101 = (__int64)v11;
a1 = v11;
if ( (unsigned int)func1(v11) )
{
func4(v101);
if ( v15 )
{
v100 = v15;
v17 = v12;
}
else
{
v17 = v12;
v15 = 1;
}
}
else
{
func4(v101);
a1 = "-not";
a2 = (const char *)func7();
do
{
if ( !v99 )
break;
v96 = *a2 < (unsigned int)*a1;
v97 = *a2++ == *a1++;
--v99;
}
while ( v97 );
if ( (!v96 && !v97) == v96 )
{
a1 = (const char *)func6(a1, a2, v98, v99);
func4((__int64)a1);
}
v17 = v12;
if ( v100 )
{
a1 = "-and";
func4((__int64)"-and");
v100 = 0;
}
}
}
}
else
{
if ( func8() )
goto LABEL_125;
v93 = (const char *)func7();
v94 = 5LL;
v95 = "-and";
a2 = v93;
do
{
if ( !v94 )
break;
v91 = *a2 < (unsigned int)*v95;
v92 = *a2++ == *v95++;
--v94;
}
while ( v92 );
v15 = (char)((!v91 && !v92) - v91);
if ( (!v91 && !v92) != v91 )
goto LABEL_125;
a1 = (const char *)v87;
v17 = v12;
func4(v87);
}
}
}
else
{
*((_DWORD *)&options + 11) = 1;
*((_DWORD *)&options + 17) = 0;
v82 = &v2[8 * v17];
v83 = (_BYTE *)*((_QWORD *)v82 + 1);
*((_QWORD *)&options + 6) = v82;
if ( *v83 == 59 )
{
v86 = 2;
}
else
{
v84 = v12 + 2;
do
{
v85 = *(_BYTE **)&v2[8 * v84 + 8];
v17 = v84++;
}
while ( *v85 != 59 );
v86 = v17 - v12 + 1;
}
*((_DWORD *)&options + 14) = v86;
++v17;
}
}
else
{
*((_DWORD *)&options + 6) = 1;
*((_DWORD *)&options + 17) = 0;
v47 = &v2[8 * v17];
v48 = (_BYTE *)*((_QWORD *)v47 + 1);
*((_QWORD *)&options + 4) = v47;
if ( *v48 == 59 )
{
v51 = 2;
}
else
{
v49 = v12 + 2;
do
{
v50 = *(_BYTE **)&v2[8 * v49 + 8];
v17 = v49++;
}
while ( *v50 != 59 );
v51 = v17 - v12 + 1;
}
*((_DWORD *)&options + 10) = v51;
++v17;
}
LABEL_18:
v12 = v17 + 1;
v13 = v3 < (unsigned int)(v17 + 1);
v14 = v3 == v17 + 1;
if ( v3 <= v17 + 1 )
break;
v11 = *(char **)&v2[8 * v12];
}
}
}
LABEL_39:
while ( 1 )
{
result = func8();
if ( result )
break;
a1 = (const char *)func6(a1, a2, v28, v29);
func4((__int64)a1);
}
return result;
}

original_code:
void set_post_exp(int argc, char * argv[]) {
  int i = 1;
  bool flag_c1 = 0;
  bool flag_c2 = 0;
  while (i < argc && argv[i][0] == '-') {
    char * exp = argv[i];
    i++;
    if ((strcmp(exp, "-L") == 0)) {
      options.symbol_handle = S_L;
    } else if ((strcmp(exp, "-P") == 0)) {
      options.symbol_handle = S_P;
    } else if ((strcmp(exp, "-H") == 0)) {
      options.symbol_handle = S_H;
    } else if ((strcmp(exp, "-f") == 0)) {
      break;
    }
  }
  if (i >= argc) {
    print_error(USAGE);
  }
  options.find_pathes = &argv[i];
  while (i < argc && argv[i][0] != '-') {
    options.pathes_num++;
    i++;
  }
  for (; i < argc; i++) {
    char * exp = argv[i];
    if ((strcmp(exp, "-depth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-maxdepth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-mindepth") == 0)) {
      i++;
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-exec") == 0)) {
      int count = i;
      i++;
      options.is_exec = 1;
      options.no_actions = 0;
      options.argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-ok") == 0)) {
      int count = i;
      i++;
      options.is_ok= 1;
      options.no_actions = 0;
      options.ok_argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.ok_argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-print") == 0)) {
      options.no_actions = 0;
      options.is_print = 1;
    } else if ((strcmp(exp, "-print0") == 0)) {
      options.no_actions = 0;
      options.is_print0 = 1;
    } else if ((strcmp(exp, "(") == 0)) {
      push_stack(exp);
    } else if ((strcmp(exp, ")") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      pop_stack();
      if ((strcmp(top_stack(), "-not") == 0)) {
        char * tmp = post_exp[post_exp_index - 1];
        if ((strcmp(tmp, "-and") != 0) && (strcmp(tmp, "-or") != 0)) {
          push_back_exp("-and");
        }
        push_back_exp(pop_stack());
      }
    } else if ((strcmp(exp, "-and") == 0)) {
      if (!stack_empty() && (strcmp(top_stack(), "-and") == 0)) {
        push_back_exp(exp);
      } else {
        push_stack(exp);
      }
      flag_c1 = 0;
    } else if ((strcmp(exp, "-or") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      push_stack(exp);
      flag_c1 = 0;
    } else if ((strcmp(exp, "-not") == 0)) {
      push_stack(exp);
    } else if (is_exp(exp)) {
      push_back_exp(exp);
      if (flag_c1) {
        flag_c2 = 1;
      }
      flag_c1 = 1;
    } else {
      push_back_exp(exp);
      if ((strcmp(top_stack(), "-not") == 0)) {
        push_back_exp(pop_stack());
      }
      if (flag_c2) {
        push_back_exp("-and");
        flag_c2 = 0;
      }
    }
  }
  while (!stack_empty()) {
    push_back_exp(pop_stack());
  }
}

canonical_original_code:
void set_post_exp(int argc, char *argv[]) {
  int i = 1;
  int flag_c1 = 0;
  int flag_c2 = 0;
  while (i < argc && argv[i][0] == '-') {
    char *exp = argv[i];
    i++;
    if ((strcmp(exp, "-L") == 0)) {
      options.symbol_handle = S_L;
    } else if ((strcmp(exp, "-P") == 0)) {
      options.symbol_handle = S_P;
    } else if ((strcmp(exp, "-H") == 0)) {
      options.symbol_handle = S_H;
    } else if ((strcmp(exp, "-f") == 0)) {
      break;
    }
  }
  if (i >= argc) {
    print_error(USAGE);
  }
  options.find_pathes = &argv[i];
  while (i < argc && argv[i][0] != '-') {
    options.pathes_num++;
    i++;
  }
  for (; i < argc; i++) {
    char *exp = argv[i];
    if ((strcmp(exp, "-depth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-maxdepth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-mindepth") == 0)) {
      i++;
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-exec") == 0)) {
      int count = i;
      i++;
      options.is_exec = 1;
      options.no_actions = 0;
      options.argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-ok") == 0)) {
      int count = i;
      i++;
      options.is_ok= 1;
      options.no_actions = 0;
      options.ok_argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.ok_argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-print") == 0)) {
      options.no_actions = 0;
      options.is_print = 1;
    } else if ((strcmp(exp, "-print0") == 0)) {
      options.no_actions = 0;
      options.is_print0 = 1;
    } else if ((strcmp(exp, "(") == 0)) {
      push_stack(exp);
    } else if ((strcmp(exp, ")") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      pop_stack();
      if ((strcmp(top_stack(), "-not") == 0)) {
        char *tmp = post_exp[post_exp_index - 1];
        if ((strcmp(tmp, "-and") != 0) && (strcmp(tmp, "-or") != 0)) {
          push_back_exp("-and");
        }
        push_back_exp(pop_stack());
      }
    } else if ((strcmp(exp, "-and") == 0)) {
      if (!stack_empty() && (strcmp(top_stack(), "-and") == 0)) {
        push_back_exp(exp);
      } else {
        push_stack(exp);
      }
      flag_c1 = 0;
    } else if ((strcmp(exp, "-or") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      push_stack(exp);
      flag_c1 = 0;
    } else if ((strcmp(exp, "-not") == 0)) {
      push_stack(exp);
    } else if (is_exp(exp)) {
      push_back_exp(exp);
      if (flag_c1) {
        flag_c2 = 1;
      }
      flag_c1 = 1;
    } else {
      push_back_exp(exp);
      if ((strcmp(top_stack(), "-not") == 0)) {
        push_back_exp(pop_stack());
      }
      if (flag_c2) {
        push_back_exp("-and");
        flag_c2 = 0;
      }
    }
  }
  while (!stack_empty()) {
    push_back_exp(pop_stack());
  }
}

variable_types:
argv
char *[]

variable_types: count int

variable_types:
tmp
char *


decompiled_code:
_BOOL8 __fastcall init_parser(unsigned int a1, const char *a2)
{
post_exp = malloc(8LL * (int)a1);
help_stack = malloc(8LL * (int)a1);
post_exp_index = 0;
stack_index = 0;
return set_post_exp((const char *)a1, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(unsigned int a1, const char *a2)
{
post_exp = malloc(8LL * (int)a1);
help_stack = malloc(8LL * (int)a1);
post_exp_index = 0;
stack_index = 0;
return func9((const char *)a1, a2);
}

original_code:
void init_parser(int argc, char * argv[]) {
  post_exp = (char **)(malloc(sizeof(char **) * argc));
  help_stack = (char **)(malloc(sizeof(char **) * argc));
  post_exp_index = 0;
  stack_index = 0;
  set_post_exp(argc, argv);
}

canonical_original_code:
void init_parser(int argc, char *argv[]) {
  post_exp = (char **)(malloc(sizeof(char **) * argc));
  help_stack = (char **)(malloc(sizeof(char **) * argc));
  post_exp_index = 0;
  stack_index = 0;
  set_post_exp(argc, argv);
}

variable_types: argc int


decompiled_code:
void free_parser()
{
free(post_exp);
free(help_stack);
}

canonical_decompiled_code:
void func11()
{
free(post_exp);
free(help_stack);
}


repo: sheimi/tiny-server

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init_dispatcher(argc, argv, envp);
create_childpool((unsigned int)argc, argv);
free_childpool();
free_dispatcher();
return 0;
}

original_code:
int main(int argc, char * argv[]) {
  init_dispatcher();
  create_childpool(argc, argv);
  free_childpool();
  free_dispatcher();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  init_dispatcher();
  create_childpool(argc, argv);
  free_childpool();
  free_dispatcher();
  return 0;
}


decompiled_code:
void handle_request()
{
const char *v0; // rax
char *v1; // rbp
size_t v2; // rax
struct stat v3; // [rsp+0h] [rbp-168h] BYREF
char s[216]; // [rsp+90h] [rbp-D8h] BYREF

v0 = parse_request_isra_0();
if ( v0 )
{
v1 = (char *)v0;
sprintf(s, "htdocs%s", v0 + 16);
v2 = strlen(s);
if ( *((_BYTE *)&v3.__unused[2] + v2 + 7) == 47 )
strcpy(&s[v2], "index.html");
if ( stat(s, &v3) == -1 )
{
not_found_constprop_0();
}
else
{
if ( (v3.st_mode & 0xF000) == 0x4000 )
strcat(s, "/index.html");
serve_file_isra_0(s);
}
free(v1);
}
}

canonical_decompiled_code:
void func6()
{
const char *v0; // rax
char *v1; // rbp
size_t v2; // rax
struct stat v3; // [rsp+0h] [rbp-168h] BYREF
char s[216]; // [rsp+90h] [rbp-D8h] BYREF

v0 = func5();
if ( v0 )
{
v1 = (char *)v0;
sprintf(s, "htdocs%s", v0 + 16);
v2 = strlen(s);
if ( *((_BYTE *)&v3.__unused[2] + v2 + 7) == 47 )
strcpy(&s[v2], "index.html");
if ( stat(s, &v3) == -1 )
{
func1();
}
else
{
if ( (v3.st_mode & 0xF000) == 0x4000 )
strcat(s, "/index.html");
func4(s);
}
free(v1);
}
}

original_code:
void handle_request(int fd) {
  char path[200];
  struct stat st;
  Request * request = parse_request(fd);
  if (!request)
    return;
  sprintf(path, "htdocs%s", request->url);
  if (path[strlen(path) - 1] == '/')
    strcat(path, "index.html");
  if (stat(path, &st) == -1) {
    not_found(fd);
  } else {
    if ((st.st_mode & 0170000) == 0040000)
      strcat(path, "/index.html");
    serve_file(fd, path);
  }
  free(request);
}

canonical_original_code:
void handle_request(int fd) {
  char path[200];
  struct stat st;
  struct Request *request = parse_request(fd);
  if (!request)
    return;
  sprintf(path, "htdocs%s", request->url);
  if (path[strlen(path) - 1] == '/')
    strcat(path, "index.html");
  if (stat(path, &st) == -1) {
    not_found(fd);
  } else {
    if ((st.st_mode & 0170000) == 0040000)
      strcat(path, "/index.html");
    serve_file(fd, path);
  }
  free(request);
}

variable_types: fd int

variable_types:
path
char [200]

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: struct Request { char method[16]; char url[128]; char *query_string; char protocol[8]; char host[32]; char connection[16]; char accept[16]; char agent[128]; char encoding[32]; char lang[32]; } *


decompiled_code:
void init_dispatcher()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void init_dispatcher() {
}

canonical_original_code:
void init_dispatcher() {
}


dispatch

decompiled_code:
void dispatch()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void dispatch(request_info * dif) {
}

canonical_original_code:
void dispatch(struct _request_info *dif) {
}

variable_types: struct _request_info { char *url; char *method; } *


decompiled_code:
void free_dispatcher()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void free_dispatcher() {
}

canonical_original_code:
void free_dispatcher() {
}


decompiled_code:
_QWORD *init_request_info()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
request_info * init_request_info() {
  request_info * ri = (request_info *) (malloc(sizeof(request_info *)));
  ri->url = 0;
  ri->method = 0;
  return ri;
}

canonical_original_code:
struct _request_info *init_request_info() {
  struct _request_info *ri = (request_info *) (malloc(sizeof(request_info *)));
  ri->url = 0;
  ri->method = 0;
  return ri;
}

return_type: struct _request_info { char *url; char *method; } *


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

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

original_code:
void free_request_info(request_info * ri) {
  free(ri);
}

canonical_original_code:
void free_request_info(struct _request_info *ri) {
  free(ri);
}

user_defined_types: struct _request_info { char *url; char *method; }


decompiled_code:
void __fastcall socketpair_wrapper(int a1, int a2, int a3, int *a4)
{
if ( socketpair(a1, a2, a3, a4) < 0 )
perror("socketpair error");
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2, int a3, int *a4)
{
if ( socketpair(a1, a2, a3, a4) < 0 )
perror("socketpair error");
}

original_code:
void socketpair_wrapper(int family, int type, int protocol, int * fd) {
  int n;
  if ( (n = socketpair(family, type, protocol, fd)) < 0)
    perror("socketpair error");
}

canonical_original_code:
void socketpair_wrapper(int family, int type, int protocol, int *fd) {
  int n;
  if ( (n = socketpair(family, type, protocol, fd)) < 0)
    perror("socketpair error");
}

variable_types: family int

variable_types: type int

variable_types: protocol int

variable_types:
fd
int *

variable_types: n int


decompiled_code:
__pid_t fork_wrapper()
{
__pid_t result; // eax
__pid_t v1; // [rsp+Ch] [rbp-Ch]

result = fork();
if ( result < 0 )
{
v1 = result;
perror("fork error");
result = v1;
}
return result;
}

canonical_decompiled_code:
__pid_t func1()
{
__pid_t result; // eax
__pid_t v1; // [rsp+Ch] [rbp-Ch]

result = fork();
if ( result < 0 )
{
v1 = result;
perror("fork error");
result = v1;
}
return result;
}

original_code:
pid_t fork_wrapper() {
  pid_t pid;
  if ((pid = fork()) < 0)
    perror("fork error");
  return pid;
}

canonical_original_code:
int fork_wrapper() {
  int pid;
  if ((pid = fork()) < 0)
    perror("fork error");
  return pid;
}

variable_types: pid int


decompiled_code:
void __fastcall dup2_wrapper(int a1, int a2)
{
if ( dup2(a1, a2) == -1 )
perror("dup error");
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
if ( dup2(a1, a2) == -1 )
perror("dup error");
}

original_code:
void dup2_wrapper(int fd1, int fd2) {
  if (dup2(fd1, fd2) == -1)
    perror("dup error");
}


decompiled_code:
__sighandler_t __fastcall signal_wrapper(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v4; // [rsp+A0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
if ( sigaction(sig, &v3, &v4) < 0 )
perror("signal error");
return v4.sa_handler;
}

canonical_decompiled_code:
__sighandler_t __fastcall func3(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v4; // [rsp+A0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
if ( sigaction(sig, &v3, &v4) < 0 )
perror("signal error");
return v4.sa_handler;
}

original_code:
sigfunc signal_wrapper(int signo, sigfunc func) {
  struct sigaction act, oact;
  act.__sigaction_handler.sa_handler = func;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  if (sigaction(signo, &act, &oact) < 0)
    perror("signal error");
  return oact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*signal_wrapper(int signo, void (*func)(int signo)))(int signo) {
  struct sigaction act; struct sigaction oact;
  act.__sigaction_handler.sa_handler = func;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  if (sigaction(signo, &act, &oact) < 0)
    perror("signal error");
  return oact.__sigaction_handler.sa_handler;
}

variable_types: signo int

variable_types:
func
void (*)(int signo)

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)(); }

return_type: void (*)(int signo)

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 __fastcall tcp_listen(const char *a1, const char *a2, socklen_t *a3)
{
struct addrinfo *v4; // rbp
struct addrinfo *v5; // rax
int v6; // eax
unsigned int v7; // er12
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_flags = 1;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
perror("error");
v4 = pai;
v5 = pai;
while ( 1 )
{
v6 = socket(v5->ai_family, v5->ai_socktype, v5->ai_protocol);
v7 = v6;
if ( v6 >= 0 )
break;
LABEL_7:
v5 = pai->ai_next;
pai = v5;
if ( !v5 )
goto LABEL_8;
}
setsockopt(v6, 1, 2, &optval, 4u);
if ( bind(v7, pai->ai_addr, pai->ai_addrlen) )
{
close(v7);
goto LABEL_7;
}
if ( !pai )
LABEL_8:
perror("error");
listen(v7, 1024);
if ( a3 )
*a3 = pai->ai_addrlen;
freeaddrinfo(v4);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char *a2, socklen_t *a3)
{
struct addrinfo *v4; // rbp
struct addrinfo *v5; // rax
int v6; // eax
unsigned int v7; // er12
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_flags = 1;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
perror("error");
v4 = pai;
v5 = pai;
while ( 1 )
{
v6 = socket(v5->ai_family, v5->ai_socktype, v5->ai_protocol);
v7 = v6;
if ( v6 >= 0 )
break;
LABEL_7:
v5 = pai->ai_next;
pai = v5;
if ( !v5 )
goto LABEL_8;
}
setsockopt(v6, 1, 2, &optval, 4u);
if ( bind(v7, pai->ai_addr, pai->ai_addrlen) )
{
close(v7);
goto LABEL_7;
}
if ( !pai )
LABEL_8:
perror("error");
listen(v7, 1024);
if ( a3 )
*a3 = pai->ai_addrlen;
freeaddrinfo(v4);
return v7;
}

original_code:
int tcp_listen(const char * host, const char * serv, socklen_t * addrlenp) {
  int listenfd, n;
  const int on = 1;
  struct addrinfo hints, *res, *ressave;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0001;
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    perror("error");
  ressave = res;
  do {
    listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (listenfd < 0)
      continue;
    setsockopt(listenfd, 1, 2, &on, sizeof(on));
    if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
      break;
    close(listenfd);
  } while ( (res = res->ai_next) != ((void *)0));
  if (res == ((void *)0))
    perror("error");
  listen(listenfd, 1024);
  if (addrlenp)
    *addrlenp = res->ai_addrlen;
  freeaddrinfo(ressave);
  return(listenfd);
}

canonical_original_code:
int tcp_listen(char *host, char *serv, unsigned int *addrlenp) {
  int listenfd; int n;
  int on = 1;
  struct addrinfo hints; struct addrinfo *res; struct addrinfo *ressave;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0001;
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    perror("error");
  ressave = res;
  do {
    listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (listenfd < 0)
      continue;
    setsockopt(listenfd, 1, 2, &on, sizeof(on));
    if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
      break;
    close(listenfd);
  } while ( (res = res->ai_next) != ((void *)0));
  if (res == ((void *)0))
    perror("error");
  listen(listenfd, 1024);
  if (addrlenp)
    *addrlenp = res->ai_addrlen;
  freeaddrinfo(ressave);
  return(listenfd);
}

variable_types:
host
char *

variable_types:
serv
char *

variable_types:
addrlenp
unsigned int *

variable_types: listenfd int

variable_types: on int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
void __noreturn sig_int()
{
__int64 v0; // rbx
__pid_t v1; // edi

if ( idle_num > 0 )
{
v0 = 0LL;
do
{
v1 = *((_DWORD *)pids + v0++);
kill(v1, 15);
}
while ( idle_num > (int)v0 );
}
while ( wait(0LL) > 0 )
;
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // rbx
__pid_t v1; // edi

if ( idle_num > 0 )
{
v0 = 0LL;
do
{
v1 = *((_DWORD *)pids + v0++);
kill(v1, 15);
}
while ( idle_num > (int)v0 );
}
while ( wait(0LL) > 0 )
;
exit(0);
}

original_code:
static void sig_int(int signo) {
  int i;
  for (i = 0; i < idle_num; i++) {
    kill(pids[i], 15);
  }
  while (wait(((void *)0)) > 0);
  exit(0);
}

variable_types: i int


decompiled_code:
void __fastcall __noreturn create_childpool(__int64 a1, __int64 a2)
{
int v3; // eax
__int64 v4; // rsi
__int64 v5; // rdi
int v6; // ebx
int v7; // er12
char *v8; // rax
__int64 i; // rbp
signed int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = atoi(*(const char **)(a2 + 24));
v4 = *(_QWORD *)(a2 + 16);
v5 = *(_QWORD *)(a2 + 8);
v6 = v3;
pid_len = v3;
idle_num = v3;
v7 = tcp_listen(v5, v4, v10);
v8 = (char *)malloc(4LL * v6);
pids = v8;
if ( v6 > 0 )
{
for ( i = 0LL; ; i += 4LL )
{
*(_DWORD *)&v8[i] = child_make_isra_0(v7, v10[0]);
if ( 4LL * (unsigned int)(v6 - 1) == i )
break;
v8 = (char *)pids;
}
}
signal_wrapper(2LL, sig_int);
while ( 1 )
pause();
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1, __int64 a2)
{
int v3; // eax
__int64 v4; // rsi
__int64 v5; // rdi
int v6; // ebx
int v7; // er12
char *v8; // rax
__int64 i; // rbp
signed int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = atoi(*(const char **)(a2 + 24));
v4 = *(_QWORD *)(a2 + 16);
v5 = *(_QWORD *)(a2 + 8);
v6 = v3;
pid_len = v3;
idle_num = v3;
v7 = tcp_listen(v5, v4, v10);
v8 = (char *)malloc(4LL * v6);
pids = v8;
if ( v6 > 0 )
{
for ( i = 0LL; ; i += 4LL )
{
*(_DWORD *)&v8[i] = func2(v7, v10[0]);
if ( 4LL * (unsigned int)(v6 - 1) == i )
break;
v8 = (char *)pids;
}
}
signal_wrapper(2LL, sig_int);
while ( 1 )
pause();
}

original_code:
void create_childpool(int argc, char * argv[]){
  int i;
  int num = atoi(argv[3]);
  pid_len = num;
  idle_num = num;
  socklen_t addrlen;
  int listenfd;
  listenfd = tcp_listen(argv[1], argv[2], &addrlen);
  pids = (pid_t *)(malloc(sizeof(pid_t) * num));
  for (i = 0; i < num; i++) {
    pids[i] = child_make(i, listenfd, addrlen);
  }
  signal_wrapper(2, sig_int);
  while(1) {
    pause();
  }
}

canonical_original_code:
void create_childpool(int argc, char *argv[]){
  int i;
  int num = atoi(argv[3]);
  pid_len = num;
  idle_num = num;
  unsigned int addrlen;
  int listenfd;
  listenfd = tcp_listen(argv[1], argv[2], &addrlen);
  pids = (int *)(malloc(sizeof(pid_t) * num));
  for (i = 0; i < num; i++) {
    pids[i] = child_make(i, listenfd, addrlen);
  }
  signal_wrapper(2, sig_int);
  while(1) {
    pause();
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: num int

variable_types:
addrlen
unsigned int


decompiled_code:
void free_childpool()
{
free(pids);
}

canonical_decompiled_code:
void func4()
{
free(pids);
}

original_code:
void free_childpool() {
  free(pids);
}

canonical_original_code:
void free_childpool() {
  free(pids);
}


repo: shellygr/SwProj

decompiled_code:
double *__fastcall init_tuple(int a1, int a2, double a3)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
if ( result )
{
*(_DWORD *)result = a1;
result[1] = a3;
*((_DWORD *)result + 4) = a2;
*((_DWORD *)result + 5) = 0;
}
return result;
}

canonical_decompiled_code:
double *__fastcall func0(int a1, int a2, double a3)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
if ( result )
{
*(_DWORD *)result = a1;
result[1] = a3;
*((_DWORD *)result + 4) = a2;
*((_DWORD *)result + 5) = 0;
}
return result;
}

original_code:
void* init_tuple(int size, double score, int place) {
 tuple *ret = (tuple *) malloc(sizeof(tuple));
 if (ret == ((void *)0))
  return ((void *)0);
 ret->size = size;
 ret->score = score;
 ret->place = place;
 ret->diameter = 0;
 return ret;
}

canonical_original_code:
void *init_tuple(int size, double score, int place) {
 struct tuple *ret = (tuple *) malloc(sizeof(tuple));
 if (ret == ((void *)0))
  return ((void *)0);
 ret->size = size;
 ret->score = score;
 ret->place = place;
 ret->diameter = 0;
 return ret;
}

variable_types: size int

variable_types: score double

variable_types: place int

variable_types: struct tuple { int size; double score; int place; int diameter; } *

return_type: void *


decompiled_code:
__int64 __fastcall compare_to(__int64 a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8
double v4; // xmm1_8

result = 1LL;
if ( *(_DWORD *)a1 <= *(_DWORD *)a2 )
{
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
goto LABEL_6;
v3 = *(double *)(a1 + 8);
v4 = *(double *)(a2 + 8);
if ( v3 > v4 )
return result;
if ( v4 > v3 )
LABEL_6:
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a2 + 16));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8
double v4; // xmm1_8

result = 1LL;
if ( *(_DWORD *)a1 <= *(_DWORD *)a2 )
{
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
goto LABEL_6;
v3 = *(double *)(a1 + 8);
v4 = *(double *)(a2 + 8);
if ( v3 > v4 )
return result;
if ( v4 > v3 )
LABEL_6:
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a2 + 16));
}
return result;
}

original_code:
int compare_to(const void *a, const void *b) {
 tuple *x = (tuple *) a;
 tuple *y = (tuple *) b;
 if ((x->size) > (y->size)) {
  return 1;
 }
 if ((x->size) < (y->size)) {
  return -1;
 }
 if ((x->score) > (y->score)) {
  return 1;
 }
 if ((x->score) < (y->score)) {
  return -1;
 }
 return (x->place) - (y->place);
}

canonical_original_code:
int compare_to(void *a, void *b) {
 struct tuple *x = (tuple *) a;
 struct tuple *y = (tuple *) b;
 if ((x->size) > (y->size)) {
  return 1;
 }
 if ((x->size) < (y->size)) {
  return -1;
 }
 if ((x->score) > (y->score)) {
  return 1;
 }
 if ((x->score) < (y->score)) {
  return -1;
 }
 return (x->place) - (y->place);
}

variable_types:
a
void *

variable_types:
b
void *

user_defined_types: struct tuple { int size; double score; int place; int diameter; }


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

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

original_code:
void destroy_elem(elem* elm) {
 free(elm);
}

canonical_original_code:
void destroy_elem(struct elem *elm) {
 free(elm);
}

variable_types: struct elem { void *content; struct elem *next; } *


decompiled_code:
_QWORD *init_queue()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
queue * init_queue() {
 queue *q = (queue*) malloc(sizeof(queue));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = ((void *)0);
 q->tail = ((void *)0);
 return q;
}

canonical_original_code:
struct queue *init_queue() {
 struct queue *q = (queue*) malloc(sizeof(queue));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = ((void *)0);
 q->tail = ((void *)0);
 return q;
}

variable_types: struct queue { struct elem { void *content; struct elem *next; } *head; struct elem *tail; } *

user_defined_types: struct queue { struct elem *head; struct elem *tail; }