// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/os.c
// Function: os_execute_impl
static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
    janet_sandbox_assert(JANET_SANDBOX_SUBPROCESS);
    janet_arity(argc, 1, 3);

    /* Get flags */
    int is_spawn = mode == JANET_EXECUTE_SPAWN;
    uint64_t flags = 0;
    if (argc > 1) {
        flags = janet_getflags(argv, 1, "epxd");
    }

    /* Get environment */
    int use_environ = !janet_flag_at(flags, 0);
    EnvBlock envp = os_execute_env(argc, argv);

    /* Get arguments */
    JanetView exargs = janet_getindexed(argv, 0);
    if (exargs.len < 1) {
        janet_panic("expected at least 1 command line argument");
    }

    /* Optional stdio redirections */
    JanetAbstract orig_in = NULL, orig_out = NULL, orig_err = NULL;
    JanetHandle new_in = JANET_HANDLE_NONE, new_out = JANET_HANDLE_NONE, new_err = JANET_HANDLE_NONE;
    JanetHandle pipe_in = JANET_HANDLE_NONE, pipe_out = JANET_HANDLE_NONE, pipe_err = JANET_HANDLE_NONE;
    int stderr_is_stdout = 0;
    int pipe_errflag = 0; /* Track errors setting up pipes */
    int pipe_owner_flags = (is_spawn && (flags & 0x8)) ? JANET_PROC_ALLOW_ZOMBIE : 0;

    /* Get optional redirections */
    if (argc > 2 && (mode != JANET_EXECUTE_EXEC)) {
        JanetDictView tab = janet_getdictionary(argv, 2);
        Janet maybe_stdin = janet_dictionary_get(tab.kvs, tab.cap, janet_ckeywordv("in"));
        Janet maybe_stdout = janet_dictionary_get(tab.kvs, tab.cap, janet_ckeywordv("out"));
        Janet maybe_stderr = janet_dictionary_get(tab.kvs, tab.cap, janet_ckeywordv("err"));
        if (is_spawn && janet_keyeq(maybe_stdin, "pipe")) {
            new_in = make_pipes(&pipe_in, 1, &pipe_errflag);
            pipe_owner_flags |= JANET_PROC_OWNS_STDIN;
        } else if (!janet_checktype(maybe_stdin, JANET_NIL)) {
            new_in = janet_getjstream(&maybe_stdin, 0, &orig_in);
        }
        if (is_spawn && janet_keyeq(maybe_stdout, "pipe")) {
            new_out = make_pipes(&pipe_out, 0, &pipe_errflag);
            pipe_owner_flags |= JANET_PROC_OWNS_STDOUT;
        } else if (!janet_checktype(maybe_stdout, JANET_NIL)) {
            new_out = janet_getjstream(&maybe_stdout, 0, &orig_out);
        }
        if (is_spawn && janet_keyeq(maybe_stderr, "pipe")) {
            new_err = make_pipes(&pipe_err, 0, &pipe_errflag);
            pipe_owner_flags |= JANET_PROC_OWNS_STDERR;
        } else if (is_spawn && janet_keyeq(maybe_stderr, "out")) {
            stderr_is_stdout = 1;
        } else if (!janet_checktype(maybe_stderr, JANET_NIL)) {
            new_err = janet_getjstream(&maybe_stderr, 0, &orig_err);
        }
    }

    /* Optional working directory. Available for both os/execute and os/spawn. */
    const char *chdir_path = NULL;
    if (argc > 2) {
        JanetDictView tab = janet_getdictionary(argv, 2);
        Janet workdir = janet_dictionary_get(tab.kvs, tab.cap, janet_ckeywordv("cd"));
        if (janet_checktype(workdir, JANET_STRING)) {
            chdir_path = (const char *) janet_unwrap_string(workdir);
#ifndef JANET_SPAWN_CHDIR
            janet_panicf(":cd argument not supported on this system - %s", chdir_path);
#endif
        } else if (!janet_checktype(workdir, JANET_NIL)) {
            janet_panicf("expected string for :cd argumnet, got %v", workdir);
        }
    }

    /* Clean up if any of the pipes have any issues */
    if (pipe_errflag) {
        if (pipe_in != JANET_HANDLE_NONE) close_handle(pipe_in);
        if (pipe_out != JANET_HANDLE_NONE) close_handle(pipe_out);
        if (pipe_err != JANET_HANDLE_NONE) close_handle(pipe_err);
        janet_panic("failed to create pipes");
    }

#ifdef JANET_WINDOWS

    HANDLE pHandle, tHandle;
    SECURITY_ATTRIBUTES saAttr;
    PROCESS_INFORMATION processInfo;
    STARTUPINFO startupInfo;
    LPCSTR lpCurrentDirectory = NULL;
    memset(&saAttr, 0, sizeof(saAttr));
    memset(&processInfo, 0, sizeof(processInfo));
    memset(&startupInfo, 0, sizeof(startupInfo));
    startupInfo.cb = sizeof(startupInfo);
    startupInfo.dwFlags |= STARTF_USESTDHANDLES;
    saAttr.nLength = sizeof(saAttr);

    JanetBuffer *buf = os_exec_escape(exargs);
    if (buf->count > 8191) {
        if (pipe_in != JANET_HANDLE_NONE) CloseHandle(pipe_in);
        if (pipe_out != JANET_HANDLE_NONE) CloseHandle(pipe_out);
        if (pipe_err != JANET_HANDLE_NONE) CloseHandle(pipe_err);
        janet_panic("command line string too long (max 8191 characters)");
    }
    const char *path = (const char *) janet_unwrap_string(exargs.items[0]);

    if (chdir_path != NULL) {
        lpCurrentDirectory = chdir_path;
    }

    /* Do IO redirection */

    if (pipe_in != JANET_HANDLE_NONE) {
        startupInfo.hStdInput = pipe_in;
    } else if (new_in != JANET_HANDLE_NONE) {
        startupInfo.hStdInput = new_in;
    } else {
        startupInfo.hStdInput = (HANDLE) _get_osfhandle(_fileno(stdin));
    }

    if (pipe_out != JANET_HANDLE_NONE) {
        startupInfo.hStdOutput = pipe_out;
    } else if (new_out != JANET_HANDLE_NONE) {
        startupInfo.hStdOutput = new_out;
    } else {
        startupInfo.hStdOutput = (HANDLE) _get_osfhandle(_fileno(stdout));
    }

    if (pipe_err != JANET_HANDLE_NONE) {
        startupInfo.hStdError = pipe_err;
    } else if (new_err != NULL) {
        startupInfo.hStdError = new_err;
    } else if (stderr_is_stdout) {
        startupInfo.hStdError = startupInfo.hStdOutput;
    } else {
        startupInfo.hStdError = (HANDLE) _get_osfhandle(_fileno(stderr));
    }

    int cp_failed = 0;
    if (!CreateProcess(janet_flag_at(flags, 1) ? NULL : path,
                       (char *) buf->data, /* Single CLI argument */
                       &saAttr, /* no proc inheritance */
                       &saAttr, /* no thread inheritance */
                       TRUE, /* handle inheritance */
                       0, /* flags */
                       use_environ ? NULL : envp, /* pass in environment */
                       lpCurrentDirectory,
                       &startupInfo,
                       &processInfo)) {
        cp_failed = 1;
    }

    if (pipe_in != JANET_HANDLE_NONE) CloseHandle(pipe_in);
    if (pipe_out != JANET_HANDLE_NONE) CloseHandle(pipe_out);
    if (pipe_err != JANET_HANDLE_NONE) CloseHandle(pipe_err);

    os_execute_cleanup(envp, NULL);

    if (cp_failed)  {
        janet_panic("failed to create process");
    }

    pHandle = processInfo.hProcess;
    tHandle = processInfo.hThread;

#else

    /* Result */
    int status = 0;

    const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
    for (int32_t i = 0; i < exargs.len; i++)
        child_argv[i] = janet_getcstring(exargs.items, i);
    child_argv[exargs.len] = NULL;
    /* Coerce to form that works for spawn. I'm fairly confident no implementation
     * of posix_spawn would modify the argv array passed in. */
    char *const *cargv = (char *const *)child_argv;

    if (use_environ) {
        janet_lock_environ();
    }

    /* exec mode */
    if (mode == JANET_EXECUTE_EXEC) {
        int status;
        if (!use_environ) {
            environ = envp;
        }
        do {
            if (janet_flag_at(flags, 1)) {
                status = execvp(cargv[0], cargv);
            } else {
                status = execv(cargv[0], cargv);
            }
        } while (status == -1 && errno == EINTR);
        janet_panicf("%p: %s", cargv[0], janet_strerror(errno ? errno : ENOENT));
    }

    /* Use posix_spawn to spawn new process */

    /* Posix spawn setup */
    posix_spawn_file_actions_t actions;
    posix_spawn_file_actions_init(&actions);
#ifdef JANET_SPAWN_CHDIR
    if (chdir_path != NULL) {
#ifdef JANET_SPAWN_CHDIR_NO_NP
        posix_spawn_file_actions_addchdir(&actions, chdir_path);
#else
        posix_spawn_file_actions_addchdir_np(&actions, chdir_path);
#endif
    }
#endif
    if (pipe_in != JANET_HANDLE_NONE) {
        posix_spawn_file_actions_adddup2(&actions, pipe_in, 0);
        posix_spawn_file_actions_addclose(&actions, pipe_in);
    } else if (new_in != JANET_HANDLE_NONE && new_in != 0) {
        posix_spawn_file_actions_adddup2(&actions, new_in, 0);
        if (new_in != new_out && new_in != new_err)
            posix_spawn_file_actions_addclose(&actions, new_in);
    }
    if (pipe_out != JANET_HANDLE_NONE) {
        posix_spawn_file_actions_adddup2(&actions, pipe_out, 1);
        posix_spawn_file_actions_addclose(&actions, pipe_out);
    } else if (new_out != JANET_HANDLE_NONE && new_out != 1) {
        posix_spawn_file_actions_adddup2(&actions, new_out, 1);
        if (new_out != new_err)
            posix_spawn_file_actions_addclose(&actions, new_out);
    }
    if (pipe_err != JANET_HANDLE_NONE) {
        posix_spawn_file_actions_adddup2(&actions, pipe_err, 2);
        posix_spawn_file_actions_addclose(&actions, pipe_err);
    } else if (new_err != JANET_HANDLE_NONE && new_err != 2) {
        posix_spawn_file_actions_adddup2(&actions, new_err, 2);
        posix_spawn_file_actions_addclose(&actions, new_err);
    } else if (stderr_is_stdout) {
        posix_spawn_file_actions_adddup2(&actions, 1, 2);
    }

    pid_t pid;
    if (janet_flag_at(flags, 1)) {
        status = posix_spawnp(&pid,
                              child_argv[0], &actions, NULL, cargv,
                              use_environ ? environ : envp);
    } else {
        status = posix_spawn(&pid,
                             child_argv[0], &actions, NULL, cargv,
                             use_environ ? environ : envp);
    }

    posix_spawn_file_actions_destroy(&actions);

    if (pipe_in != JANET_HANDLE_NONE) close(pipe_in);
    if (pipe_out != JANET_HANDLE_NONE) close(pipe_out);
    if (pipe_err != JANET_HANDLE_NONE) close(pipe_err);

    if (use_environ) {
        janet_unlock_environ();
    }

    os_execute_cleanup(envp, child_argv);
    if (status) {
        /* correct for macos bug where errno is not set */
        janet_panicf("%p: %s", argv[0], janet_strerror(errno ? errno : ENOENT));
    }

#endif
    JanetProc *proc = janet_abstract(&ProcAT, sizeof(JanetProc));
    proc->return_code = -1;
#ifdef JANET_WINDOWS
    proc->pHandle = pHandle;
    proc->tHandle = tHandle;
#else
    proc->pid = pid;
#endif
    proc->in = NULL;
    proc->out = NULL;
    proc->err = NULL;
    proc->flags = pipe_owner_flags;
    if (janet_flag_at(flags, 2)) {
        proc->flags |= JANET_PROC_ERROR_NONZERO;
    }
    if (is_spawn) {
        /* Only set up pointers to stdin, stdout, and stderr if os/spawn. */
        if (new_in != JANET_HANDLE_NONE) {
            proc->in = get_stdio_for_handle(new_in, orig_in, 1);
            if (NULL == proc->in) janet_panic("failed to construct proc");
        }
        if (new_out != JANET_HANDLE_NONE) {
            proc->out = get_stdio_for_handle(new_out, orig_out, 0);
            if (NULL == proc->out) janet_panic("failed to construct proc");
        }
        if (new_err != JANET_HANDLE_NONE) {
            proc->err = get_stdio_for_handle(new_err, orig_err, 0);
            if (NULL == proc->err) janet_panic("failed to construct proc");
        }
        return janet_wrap_abstract(proc);
    } else {
#ifdef JANET_EV
        os_proc_wait_impl(proc);
#else
        return os_proc_wait_impl(proc);
#endif
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %edx, %ebx
movq %rsi, %r12
movl %edi, %r14d
movl $0x2, %edi
callq 0x4f595
movl %r14d, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x192cc
movl %r14d, -0x88(%rbp)
cmpl $0x2, %r14d
jl 0x36023
leaq 0x314ee(%rip), %rdx     # 0x674ff
movq %r12, %rdi
movl $0x1, %esi
callq 0x1a0d0
movq %rax, %r15
jmp 0x36026
xorl %r15d, %r15d
movabsq $-0x800000000000, %r13  # imm = 0xFFFF800000000000
cmpl $0x3, -0x88(%rbp)
movl %ebx, -0x3c(%rbp)
movq %r12, -0x70(%rbp)
movq %r15, -0x90(%rbp)
jge 0x36054
movq $0x0, -0x80(%rbp)
jmp 0x361af
movq %r12, %rdi
movl $0x2, %esi
callq 0x19dc8
movq %rax, %rbx
movq %rdx, %r14
movslq %r14d, %rax
leaq 0x8(,%rax,8), %rdi
callq 0x2bfe0
movq %rax, -0x80(%rbp)
shrq $0x20, %r14
movq $0x0, -0x30(%rbp)
testl %r14d, %r14d
jle 0x3619e
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
xorl %r12d, %r12d
movq %r14, -0x48(%rbp)
movq %rbx, -0x38(%rbp)
movq %r12, %r15
shlq $0x4, %r15
movq (%rbx,%r15), %rdi
movq %rdi, %rax
andq %r13, %rax
cmpq %rcx, %rax
jne 0x3617e
addq %rbx, %r15
movq 0x8(%r15), %rax
andq %r13, %rax
cmpq %rcx, %rax
jne 0x3617e
callq 0x4f838
movq %rax, %r14
movq 0x8(%r15), %rdi
callq 0x4f838
movslq -0x8(%r14), %r15
movslq -0x8(%rax), %rbx
testq %r15, %r15
jle 0x36108
xorl %edx, %edx
movzbl (%r14,%rdx), %ecx
testl %ecx, %ecx
je 0x3616c
cmpl $0x3d, %ecx
je 0x3616c
incq %rdx
cmpq %rdx, %r15
jne 0x360f2
leaq (%r15,%rbx), %rdi
addq $0x2, %rdi
movq %rax, -0x68(%rbp)
callq 0x2bfe0
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x12680
leaq (%r15,%r13), %rdi
incq %rdi
movb $0x3d, -0x1(%rdi)
movq -0x68(%rbp), %rsi
movq %rbx, %rdx
callq 0x12680
leal (%r15,%rbx), %eax
cltq
movb $0x0, 0x1(%r13,%rax)
movq -0x30(%rbp), %rcx
movslq %ecx, %rax
incl %ecx
movq %rcx, -0x30(%rbp)
movq -0x80(%rbp), %rcx
movq %r13, (%rcx,%rax,8)
movabsq $-0x800000000000, %r13  # imm = 0xFFFF800000000000
movq -0x48(%rbp), %r14
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
movq -0x38(%rbp), %rbx
incq %r12
cmpq %r14, %r12
jne 0x360a5
movq -0x30(%rbp), %rcx
movslq %ecx, %rcx
movq -0x90(%rbp), %r15
movq -0x70(%rbp), %r12
jmp 0x361a0
xorl %ecx, %ecx
movq -0x80(%rbp), %rax
movq $0x0, (%rax,%rcx,8)
movl -0x3c(%rbp), %ebx
movq %r12, %rdi
xorl %esi, %esi
callq 0x19d81
movl %edx, -0x9c(%rbp)
testl %edx, %edx
jle 0x36954
movq %rax, %r14
cmpl $0x1, %ebx
sete %al
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
xorl %ecx, %ecx
movq %rcx, -0xb8(%rbp)
movq %rcx, -0xb0(%rbp)
movq %rcx, -0xa8(%rbp)
movl %r15d, %ecx
andl $0x8, %ecx
shrl $0x3, %ecx
andb %al, %cl
movzbl %cl, %eax
shll $0x7, %eax
movl %eax, -0x50(%rbp)
cmpl $0x3, -0x88(%rbp)
setl %al
cmpl $0x2, %ebx
sete %cl
orb %al, %cl
jne 0x3630b
movq %r12, %rdi
movq %rsi, %r15
movl $0x2, %esi
callq 0x19dc8
movq %rax, %rbx
movq %rdx, %r12
shrq $0x20, %r12
leaq 0x23174(%rip), %rdi     # 0x593b2
callq 0x47cd3
movq %rax, %rdi
movq %r15, %rsi
callq 0x4f9ad
movq %rbx, %rdi
movl %r12d, %esi
movq %rax, %rdx
callq 0x49189
movq %rax, -0x78(%rbp)
leaq 0x292fa(%rip), %rdi     # 0x5f561
callq 0x47cd3
movq %rax, %rdi
movq %r15, %rsi
callq 0x4f9ad
movq %rbx, %rdi
movl %r12d, %esi
movq %rax, %rdx
callq 0x49189
movq %rax, -0x98(%rbp)
leaq 0x2578b(%rip), %rdi     # 0x5ba1e
callq 0x47cd3
movq %rax, %rdi
movq %r15, %rsi
callq 0x4f9ad
movq %rbx, %rdi
movl -0x3c(%rbp), %ebx
movl %r12d, %esi
movq %rax, %rdx
callq 0x49189
movq %rax, %r12
movq %rax, -0x110(%rbp)
cmpl $0x1, %ebx
jne 0x36340
movq -0x78(%rbp), %rdi
leaq 0x256d8(%rip), %rsi     # 0x5b9a6
callq 0x193f7
testl %eax, %eax
je 0x36340
leaq -0x108(%rbp), %rdi
movl $0x2, %esi
callq 0x26007
testl %eax, %eax
je 0x3637d
movl $0x1, %r13d
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x60(%rbp)
jmp 0x3639f
movb $0x1, %r15b
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movb $0x1, %al
movl %eax, -0x4c(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x60(%rbp)
jmp 0x36545
movq -0x78(%rbp), %rax
andq %r13, %rax
xorl %r13d, %r13d
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
jne 0x36367
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x36377
leaq -0x78(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x38cbe
movq %rax, -0x60(%rbp)
jmp 0x363a3
movl -0x108(%rbp), %ecx
movl -0x104(%rbp), %eax
movq %rax, -0x60(%rbp)
movl %eax, -0x108(%rbp)
movl %ecx, -0x30(%rbp)
movl %ecx, -0x104(%rbp)
xorl %r13d, %r13d
orl $0x10, -0x50(%rbp)
cmpl $0x1, %ebx
jne 0x363fc
movq -0x98(%rbp), %rdi
leaq 0x255f0(%rip), %rsi     # 0x5b9a6
callq 0x193f7
testl %eax, %eax
je 0x363fc
leaq -0x108(%rbp), %rbx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x26007
xorl %edx, %edx
movl %eax, %ecx
negl %ecx
sbbl %edx, %edx
movl 0x4(%rbx), %ecx
orl %edx, %ecx
movl %ecx, -0x68(%rbp)
testl %eax, %eax
movl $0x1, %eax
cmovnel %eax, %r13d
orl (%rbx), %edx
movl %edx, -0x38(%rbp)
movl -0x3c(%rbp), %ebx
orl $0x20, -0x50(%rbp)
jmp 0x36445
movq -0x98(%rbp), %rax
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq %rcx, %rax
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
jne 0x3642f
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
jmp 0x36445
leaq -0x98(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x38cbe
movl %eax, -0x38(%rbp)
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
cmpl $0x1, %ebx
movl -0x30(%rbp), %ebx
jne 0x364ec
leaq 0x25544(%rip), %rsi     # 0x5b9a6
movq %r12, %rdi
callq 0x193f7
testl %eax, %eax
je 0x364bf
leaq -0x108(%rbp), %r12
movl $0x1, %ebx
movq %r12, %rdi
movl $0x1, %esi
callq 0x26007
xorl %edx, %edx
movl %eax, %ecx
negl %ecx
sbbl %edx, %edx
movl 0x4(%r12), %ecx
orl %edx, %ecx
movl %ecx, -0x48(%rbp)
testl %eax, %eax
cmovnel %ebx, %r13d
movl -0x30(%rbp), %ebx
orl (%r12), %edx
orl $0x40, -0x50(%rbp)
movb $0x1, %al
movl %eax, -0x4c(%rbp)
movq -0x70(%rbp), %r12
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
jmp 0x3653e
leaq 0x2909b(%rip), %rsi     # 0x5f561
movq %r12, %rdi
callq 0x193f7
testl %eax, %eax
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
je 0x364ec
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
jmp 0x36514
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq %rax, %r12
movb $0x1, %al
movl %eax, -0x4c(%rbp)
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movabsq $-0x7800000000000, %rax # imm = 0xFFF8800000000000
cmpq %rax, %r12
jne 0x3651b
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x3653a
leaq -0x110(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x38cbe
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movl %eax, %edx
movq -0x70(%rbp), %r12
testl %r13d, %r13d
sete %r15b
movl %edx, -0x54(%rbp)
movl %ebx, -0x30(%rbp)
cmpl $0x3, -0x88(%rbp)
jl 0x365cc
movq %r12, %rdi
movq %rsi, %rbx
movl $0x2, %esi
callq 0x19dc8
movq %rax, %r12
movq %rdx, %r13
shrq $0x20, %r13
leaq 0x30d92(%rip), %rdi     # 0x67307
callq 0x47cd3
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4f9ad
movq %r12, %rdi
movl %r13d, %esi
movabsq $-0x800000000000, %rbx  # imm = 0xFFFF800000000000
movq %rax, %rdx
callq 0x49189
andq %rax, %rbx
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rbx
je 0x365cc
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
cmpq %rcx, %rbx
jne 0x36a37
movq %rax, %rdi
callq 0x4f838
jmp 0x365ce
xorl %eax, %eax
movq %rax, -0x88(%rbp)
testb %r15b, %r15b
je 0x36960
movl -0x9c(%rbp), %r15d
movl %r15d, %ebx
leaq 0x8(,%rbx,8), %rdi
callq 0x2bfe0
movq %rax, %r13
cmpl $0x2, %r15d
movl $0x1, %r12d
cmovgel %r15d, %r12d
xorl %r15d, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x198dd
movq %rax, (%r13,%r15,8)
incq %r15
cmpq %r15, %r12
jne 0x36609
movq $0x0, (%r13,%rbx,8)
cmpl $0x2, -0x3c(%rbp)
je 0x36996
leaq -0x108(%rbp), %rdi
callq 0x120f0
movq -0x88(%rbp), %rsi
testq %rsi, %rsi
movq -0x90(%rbp), %r15
movq -0x80(%rbp), %r12
movl -0x30(%rbp), %ebx
je 0x36666
leaq -0x108(%rbp), %rdi
callq 0x12b80
cmpl $-0x1, %ebx
je 0x3668b
leaq -0x108(%rbp), %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x12b00
movl %ebx, %esi
leaq -0x108(%rbp), %rdi
callq 0x12ab0
jmp 0x366ba
movq -0x60(%rbp), %rax
decl %eax
cmpl $-0x3, %eax
ja 0x366ba
leaq -0x108(%rbp), %rdi
movq -0x60(%rbp), %rbx
movl %ebx, %esi
xorl %edx, %edx
callq 0x12b00
cmpl -0x38(%rbp), %ebx
je 0x366ba
movq -0x60(%rbp), %rax
movl %eax, %esi
cmpl -0x54(%rbp), %eax
jne 0x3667d
movl -0x68(%rbp), %r14d
cmpl $-0x1, %r14d
je 0x368b7
leaq -0x108(%rbp), %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x12b00
movl %r14d, %esi
leaq -0x108(%rbp), %rdi
callq 0x12ab0
movl -0x48(%rbp), %esi
cmpl $-0x1, %esi
je 0x368f1
leaq -0x108(%rbp), %r14
movq %r14, %rdi
movl $0x2, %edx
movq %r12, %rbx
movl %esi, %r12d
callq 0x12b00
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %r12
callq 0x12ab0
movq %r12, %r9
testb $0x1, %r15b
jne 0x36732
movq 0x4f891(%rip), %rax     # 0x85fc0
movq (%rax), %r9
movq (%r13), %rsi
testb $0x2, %r15b
movl -0x30(%rbp), %ebx
leaq -0x78(%rbp), %rdi
leaq -0x108(%rbp), %rdx
jne 0x36756
xorl %ecx, %ecx
movq %r13, %r8
callq 0x12990
jmp 0x36760
xorl %ecx, %ecx
movq %r13, %r8
callq 0x12810
movl %eax, %r14d
leaq -0x108(%rbp), %rdi
callq 0x122c0
cmpl $-0x1, %ebx
je 0x3677b
movl %ebx, %edi
callq 0x12460
movl -0x68(%rbp), %edi
cmpl $-0x1, %edi
je 0x36788
callq 0x12460
movl -0x48(%rbp), %edi
cmpl $-0x1, %edi
je 0x36795
callq 0x12460
movq %r13, %rdi
callq 0x2c187
testq %r12, %r12
je 0x367c1
movq (%r12), %rdi
testq %rdi, %rdi
je 0x367c1
leaq 0x8(%r12), %rbx
callq 0x2c187
movq (%rbx), %rdi
addq $0x8, %rbx
testq %rdi, %rdi
jne 0x367b0
movq %r12, %rdi
callq 0x2c187
testl %r14d, %r14d
jne 0x36a01
leaq 0x4cf97(%rip), %rdi     # 0x83770
movl $0x28, %esi
callq 0x144d2
movq %rax, %rbx
addl %r15d, %r15d
andl $0x8, %r15d
movl -0x50(%rbp), %ecx
orl %r15d, %ecx
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl -0x78(%rbp), %eax
movl %eax, 0x4(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movq $0x0, 0x20(%rbx)
movl %ecx, (%rbx)
cmpl $0x1, -0x3c(%rbp)
jne 0x36a2f
movq -0x60(%rbp), %rdi
cmpl $-0x1, %edi
movl -0x38(%rbp), %r15d
je 0x3684c
movq %rbx, %r14
addq $0x10, %r14
movq -0xb8(%rbp), %rsi
movl $0x1, %edx
callq 0x38d41
movq %rax, (%r14)
testq %rax, %rax
je 0x36948
cmpl $-0x1, %r15d
je 0x36870
movq -0xb0(%rbp), %rsi
movl %r15d, %edi
xorl %edx, %edx
callq 0x38d41
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x36948
movl -0x54(%rbp), %edi
cmpl $-0x1, %edi
je 0x36893
movq -0xa8(%rbp), %rsi
xorl %edx, %edx
callq 0x38d41
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x36948
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
movq %rbx, %rdi
callq 0x4f9f2
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, -0x38(%rbp)
je 0x366eb
cmpl $0x1, -0x38(%rbp)
je 0x366eb
leaq -0x108(%rbp), %rdi
movl -0x38(%rbp), %ebx
movl %ebx, %esi
movl $0x1, %edx
callq 0x12b00
movl %ebx, %esi
cmpl -0x54(%rbp), %ebx
jne 0x366df
jmp 0x366eb
movl -0x54(%rbp), %r14d
cmpl $-0x1, %r14d
je 0x36901
cmpl $0x2, %r14d
jne 0x36926
cmpb $0x0, -0x4c(%rbp)
jne 0x3671f
leaq -0x108(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x12b00
jmp 0x3671f
leaq -0x108(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x12b00
movq %rbx, %rdi
movl %r14d, %esi
jmp 0x3671a
leaq 0x30c26(%rip), %rdi     # 0x67575
callq 0x19263
leaq 0x30ba9(%rip), %rdi     # 0x67504
callq 0x19263
cmpl $-0x1, -0x30(%rbp)
je 0x3696e
movl -0x30(%rbp), %edi
callq 0x12460
cmpl $-0x1, -0x68(%rbp)
je 0x3697c
movl -0x68(%rbp), %edi
callq 0x12460
cmpl $-0x1, -0x48(%rbp)
je 0x3698a
movl -0x48(%rbp), %edi
callq 0x12460
leaq 0x30bc6(%rip), %rdi     # 0x67557
callq 0x19263
testb $0x1, -0x90(%rbp)
je 0x369ad
movq 0x4f61a(%rip), %rax     # 0x85fc0
movq -0x80(%rbp), %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rbx
movq (%r13), %rdi
movq %r13, %rsi
testb $0x2, %bl
jne 0x369c7
callq 0x12be0
jmp 0x369cc
callq 0x12a20
cmpl $-0x1, %eax
jne 0x369db
callq 0x12120
cmpl $0x4, (%rax)
je 0x369b4
movq (%r13), %rbx
callq 0x12120
movl (%rax), %eax
testl %eax, %eax
movl $0x2, %edi
cmovnel %eax, %edi
callq 0x4a8ae
leaq 0x30b72(%rip), %rdi     # 0x6756e
movq %rbx, %rsi
jmp 0x36a25
callq 0x12120
movl (%rax), %eax
testl %eax, %eax
movl $0x2, %edi
cmovnel %eax, %edi
callq 0x4a8ae
movq -0x70(%rbp), %rcx
movq (%rcx), %rsi
leaq 0x30b49(%rip), %rdi     # 0x6756e
movq %rax, %rdx
xorl %eax, %eax
callq 0x1917b
movq %rbx, %rdi
callq 0x35aab
leaq 0x30af0(%rip), %rdi     # 0x6752e
movq %rax, %rsi
xorl %eax, %eax
callq 0x1917b