// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
cmpb $0x1, 0x7d63(%rip)      # 0xb110
je 0x345d
movl %r9d, %ebx
movq %r8, %r13
movl %ecx, %r12d
movq %rsi, %r14
movq %rdi, %r15
callq 0x31d0
testl %eax, %eax
je 0x3479
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x34af
leaq 0x8(%rsp), %rsi
movl %ebp, %edi
xorl %edx, %edx
callq 0x3180
cmpl $-0x1, %eax
je 0x34c8
movl %ebp, %edi
callq 0x355a
cmpb $0x7f, 0x8(%rsp)
jne 0x34e1
movl $0x8f, %ecx
movl $0x4200, %edi           # imm = 0x4200
movl %ebp, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3170
cmpq $-0x1, %rax
je 0x34fa
movb $0x1, 0x7ce7(%rip)      # 0xb110
movl %r12d, 0x7dc0(%rip)     # 0xb1f0
movl %r12d, %edi
callq 0x359b
movl %eax, %edi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3170
callq 0x35b5
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2bbc(%rip), %rdi      # 0x6020
leaq 0x2bb7(%rip), %rsi      # 0x6022
leaq 0x2bc8(%rip), %rcx      # 0x603a
pushq $0x35
jmp 0x3511
testq %r13, %r13
jne 0x3517
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3170
cmpq $-0x1, %rax
je 0x3552
movq %r15, %rdi
movq %r14, %rsi
movq (%rsp), %rdx
callq 0x30f0
jmp 0x3552
leaq 0x2b6a(%rip), %rdi      # 0x6020
leaq 0x2b65(%rip), %rsi      # 0x6022
leaq 0x2b76(%rip), %rcx      # 0x603a
pushq $0x3b
jmp 0x3511
leaq 0x2b51(%rip), %rdi      # 0x6020
leaq 0x2b4c(%rip), %rsi      # 0x6022
leaq 0x2b5d(%rip), %rcx      # 0x603a
pushq $0x57
jmp 0x3511
leaq 0x2b38(%rip), %rdi      # 0x6020
leaq 0x2b33(%rip), %rsi      # 0x6022
leaq 0x2b44(%rip), %rcx      # 0x603a
pushq $0x6e
jmp 0x3511
leaq 0x2b1f(%rip), %rdi      # 0x6020
leaq 0x2b1a(%rip), %rsi      # 0x6022
leaq 0x2b2b(%rip), %rcx      # 0x603a
pushq $0x63
popq %rdx
callq 0x30c0
pushq $0x26
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3140
cmpl $-0x1, %eax
je 0x3552
leaq 0x8(%rsp), %rdx
movw %bx, (%rdx)
movq %r13, 0x8(%rdx)
pushq $0x16
popq %rdi
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x3140
cmpl $-0x1, %eax
jne 0x3482
pushq $0x1
popq %rdi
callq 0x3050