// File: /workspace/github_c_makefile_star2_O0/seojangho[P]clee/clee.c
// Function: clee
pid_t clee(const char *filename, char *const argv[], char *const envp[], clee_behavior initial_behavior, struct sock_filter *filter, unsigned short len) {
    if (tracing) {
        CLEE_ERROR;
    }
    pid_t pid;
    switch (pid = fork()) {
        case -1:
            /* error */
            CLEE_ERROR;
        case 0:
            if (filter != NULL) {
                if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) {
                    _exit(1);
                }
                struct sock_fprog prog = {
                    .len = len,
                    .filter = filter,
                };
                if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) == -1) {
                    _exit(1);
                }
            }
            if (ptrace(PTRACE_TRACEME, NULL, NULL, NULL) == -1)
            {
                /* ptrace error */
                _exit(1);
            }
            execve(filename, argv, envp);   // causes SIGTRAP
            /* execve error */
            _exit(1);
        default: ;
            /* parent */
            int status;
            if (waitpid(pid, &status, 0) == -1)
            {
                /* waitpid error */
                CLEE_ERROR;
            }
            clee_children_add(pid);
            if (WIFSTOPPED(status)) {
                long const options =
                    PTRACE_O_TRACESECCOMP |
                    PTRACE_O_TRACESYSGOOD |
                    PTRACE_O_TRACEFORK |
                    PTRACE_O_TRACEVFORK |
                    PTRACE_O_TRACECLONE;
                if (ptrace(PTRACE_SETOPTIONS, pid, 0, options) == -1) {
                    /* ptrace error */
                    CLEE_ERROR;
                }
                tracing = true;
                default_behavior = initial_behavior;
                ptrace(clee_behavior2request(initial_behavior), pid, NULL, 0);
                clee_main();
                return pid;
            }
            else
            {
                /* fail on child ptrace/execve error */
                CLEE_ERROR;
            }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movw %r9w, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movw %ax, -0x2a(%rbp)
testb $0x1, 0x8cfe(%rip)      # 0xc138
je 0x345b
leaq 0x4c65(%rip), %rdi      # 0x80a8
leaq 0x4c60(%rip), %rsi      # 0x80aa
movl $0x35, %edx
leaq 0x4c6c(%rip), %rcx      # 0x80c2
callq 0x30c0
callq 0x3210
movl %eax, -0x30(%rbp)
movl %eax, %ecx
movl %ecx, -0x54(%rbp)
subl $-0x1, %eax
je 0x347b
jmp 0x346f
movl -0x54(%rbp), %eax
testl %eax, %eax
je 0x349a
jmp 0x353e
leaq 0x4c26(%rip), %rdi      # 0x80a8
leaq 0x4c21(%rip), %rsi      # 0x80aa
movl $0x3b, %edx
leaq 0x4c2d(%rip), %rcx      # 0x80c2
callq 0x30c0
cmpq $0x0, -0x28(%rbp)
je 0x3500
movl $0x26, %edi
movl $0x1, %esi
xorl %r8d, %r8d
movl %r8d, %edx
movl %r8d, %ecx
movb $0x0, %al
callq 0x3160
cmpl $-0x1, %eax
jne 0x34ca
movl $0x1, %edi
callq 0x3050
movw -0x2a(%rbp), %ax
movw %ax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x16, %edi
movl $0x2, %esi
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x3160
cmpl $-0x1, %eax
jne 0x34fe
movl $0x1, %edi
callq 0x3050
jmp 0x3500
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
movb $0x0, %al
callq 0x3190
cmpq $-0x1, %rax
jne 0x3523
movl $0x1, %edi
callq 0x3050
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x3110
movl $0x1, %edi
callq 0x3050
movl -0x30(%rbp), %edi
leaq -0x44(%rbp), %rsi
xorl %edx, %edx
callq 0x31b0
cmpl $-0x1, %eax
jne 0x3570
leaq 0x4b50(%rip), %rdi      # 0x80a8
leaq 0x4b4b(%rip), %rsi      # 0x80aa
movl $0x57, %edx
leaq 0x4b57(%rip), %rcx      # 0x80c2
callq 0x30c0
movl -0x30(%rbp), %edi
callq 0x3620
movl -0x44(%rbp), %eax
andl $0xff, %eax
cmpl $0x7f, %eax
jne 0x3600
movq $0x8f, -0x50(%rbp)
movl -0x30(%rbp), %esi
movl $0x4200, %edi           # imm = 0x4200
xorl %edx, %edx
movl $0x8f, %ecx
movb $0x0, %al
callq 0x3190
cmpq $-0x1, %rax
jne 0x35c8
leaq 0x4af8(%rip), %rdi      # 0x80a8
leaq 0x4af3(%rip), %rsi      # 0x80aa
movl $0x63, %edx
leaq 0x4aff(%rip), %rcx      # 0x80c2
callq 0x30c0
movb $0x1, 0x8b69(%rip)      # 0xc138
movl -0x1c(%rbp), %eax
movl %eax, 0x8c40(%rip)      # 0xc218
movl -0x1c(%rbp), %edi
callq 0x3680
movl %eax, %edi
movl -0x30(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
movb $0x0, %al
callq 0x3190
callq 0x36e0
movl -0x30(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
leaq 0x4aa1(%rip), %rdi      # 0x80a8
leaq 0x4a9c(%rip), %rsi      # 0x80aa
movl $0x6e, %edx
leaq 0x4aa8(%rip), %rcx      # 0x80c2
callq 0x30c0
nop