// File: /workspace/github_c_makefile_star2_O0/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
subq $0x210, %rsp            # imm = 0x210
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x2, %edi
callq 0x7ab10
movl -0xc(%rbp), %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x1ae30
cmpl $0x1, -0x1c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
cmpl $0x1, -0xc(%rbp)
jle 0x4a997
movq -0x18(%rbp), %rdi
movl $0x1, %esi
leaq 0x48c80(%rip), %rdx     # 0x9360e
callq 0x1d1f0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movl -0xc(%rbp), %edi
movq -0x18(%rbp), %rsi
callq 0x4ecc0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x1cc50
movq %rax, -0x48(%rbp)
movl %edx, -0x40(%rbp)
cmpl $0x1, -0x40(%rbp)
jge 0x4a9e4
leaq 0x48c34(%rip), %rdi     # 0x93613
callq 0x1ad60
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0xffffffff, -0x64(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x70(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x78(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x20(%rbp)
movb %al, -0x179(%rbp)
je 0x4aa57
movq -0x28(%rbp), %rax
andq $0x8, %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x179(%rbp)
movb -0x179(%rbp), %dl
xorl %eax, %eax
movl $0x80, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x84(%rbp)
cmpl $0x2, -0xc(%rbp)
jle 0x4adf2
cmpl $0x2, -0x1c(%rbp)
je 0x4adf2
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x1ccb0
movq %rax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x19c(%rbp)
leaq 0x3a901(%rip), %rdi     # 0x853c2
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq -0x1a8(%rbp), %rdi
movl -0x19c(%rbp), %esi
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdx
callq 0x6b130
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x198(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x18c(%rbp)
leaq 0x41acc(%rip), %rdi     # 0x8c5ec
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq -0x198(%rbp), %rdi
movl -0x18c(%rbp), %esi
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdx
callq 0x6b130
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x188(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x180(%rbp)
leaq 0x3ceaf(%rip), %rdi     # 0x87a2e
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq -0x188(%rbp), %rdi
movl -0x180(%rbp), %esi
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdx
callq 0x6b130
movq %rax, -0xc0(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x4ac01
movq -0xa0(%rbp), %rdi
leaq 0x3cde5(%rip), %rsi     # 0x879b6
callq 0x1b010
cmpl $0x0, %eax
je 0x4ac01
leaq -0x70(%rbp), %rdi
movl $0x1, %esi
leaq -0x80(%rbp), %rdx
callq 0x4ef30
movl %eax, -0x64(%rbp)
movl -0x84(%rbp), %eax
orl $0x10, %eax
movl %eax, -0x84(%rbp)
jmp 0x4ac6c
xorl %eax, %eax
testb $0x1, %al
jne 0x4ac09
jmp 0x4ac35
movsd -0xa0(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4ac1e
jmp 0x4ac6a
movq -0xa0(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x4ac6a
jmp 0x4ac55
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0xa0(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x4ac6a
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
leaq -0x50(%rbp), %rdx
callq 0x4efa0
movl %eax, -0x64(%rbp)
jmp 0x4ac6c
cmpl $0x0, -0x20(%rbp)
je 0x4acad
movq -0xb0(%rbp), %rdi
leaq 0x3cd36(%rip), %rsi     # 0x879b6
callq 0x1b010
cmpl $0x0, %eax
je 0x4acad
leaq -0x74(%rbp), %rdi
xorl %esi, %esi
leaq -0x80(%rbp), %rdx
callq 0x4ef30
movl %eax, -0x68(%rbp)
movl -0x84(%rbp), %eax
orl $0x20, %eax
movl %eax, -0x84(%rbp)
jmp 0x4ad18
xorl %eax, %eax
testb $0x1, %al
jne 0x4acb5
jmp 0x4ace1
movsd -0xb0(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4acca
jmp 0x4ad16
movq -0xb0(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x4ad16
jmp 0x4ad01
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0xb0(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x4ad16
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
leaq -0x58(%rbp), %rdx
callq 0x4efa0
movl %eax, -0x68(%rbp)
jmp 0x4ad18
cmpl $0x0, -0x20(%rbp)
je 0x4ad5c
movq -0xc0(%rbp), %rdi
leaq 0x3cc8a(%rip), %rsi     # 0x879b6
callq 0x1b010
cmpl $0x0, %eax
je 0x4ad5c
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
leaq -0x80(%rbp), %rdx
callq 0x4ef30
movl %eax, -0x6c(%rbp)
movl -0x84(%rbp), %eax
orl $0x40, %eax
movl %eax, -0x84(%rbp)
jmp 0x4adf0
cmpl $0x0, -0x20(%rbp)
je 0x4ad83
movq -0xc0(%rbp), %rdi
leaq 0x4187c(%rip), %rsi     # 0x8c5ec
callq 0x1b010
cmpl $0x0, %eax
je 0x4ad83
movl $0x1, -0x7c(%rbp)
jmp 0x4adee
xorl %eax, %eax
testb $0x1, %al
jne 0x4ad8b
jmp 0x4adb7
movsd -0xc0(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4ada0
jmp 0x4adec
movq -0xc0(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x4adec
jmp 0x4add7
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0xc0(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x4adec
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
leaq -0x60(%rbp), %rdx
callq 0x4efa0
movl %eax, -0x6c(%rbp)
jmp 0x4adee
jmp 0x4adf0
jmp 0x4adf2
movq $0x0, -0xd0(%rbp)
cmpl $0x2, -0xc(%rbp)
jle 0x4af58
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x1ccb0
movq %rax, -0xe0(%rbp)
movq %rdx, -0xd8(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0x1ac(%rbp)
leaq 0x485d2(%rip), %rdi     # 0x93416
callq 0x68d90
movq %rax, %rdi
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
callq 0x7b550
movq -0x1b8(%rbp), %rdi
movl -0x1ac(%rbp), %esi
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdx
callq 0x6b130
movq %rax, -0xe8(%rbp)
xorl %eax, %eax
testb $0x1, %al
jne 0x4ae8a
jmp 0x4aeb6
movsd -0xe8(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4ae9f
jmp 0x4aed6
movq -0xe8(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x4aed6
jmp 0x4aeeb
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0xe8(%rbp), %rax
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
cmpq %rcx, %rax
jne 0x4aeeb
movq -0xe8(%rbp), %rdi
callq 0x7b260
movq %rax, -0xd0(%rbp)
jmp 0x4af56
xorl %eax, %eax
testb $0x1, %al
jne 0x4aef3
jmp 0x4af1f
movsd -0xe8(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4af08
jmp 0x4af54
movq -0xe8(%rbp), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x4af54
jmp 0x4af3f
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq -0xe8(%rbp), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x4af54
movq -0xe8(%rbp), %rsi
leaq 0x486f0(%rip), %rdi     # 0x9363d
movb $0x0, %al
callq 0x1ac40
jmp 0x4af56
jmp 0x4af58
cmpl $0x0, -0x80(%rbp)
je 0x4af94
cmpl $-0x1, -0x70(%rbp)
je 0x4af6c
movl -0x70(%rbp), %edi
callq 0x4f090
cmpl $-0x1, -0x74(%rbp)
je 0x4af7a
movl -0x74(%rbp), %edi
callq 0x4f090
cmpl $-0x1, -0x78(%rbp)
je 0x4af88
movl -0x78(%rbp), %edi
callq 0x4f090
leaq 0x486d7(%rip), %rdi     # 0x93666
callq 0x1ad60
movl $0x0, -0xf4(%rbp)
movslq -0x40(%rbp), %rdi
addq $0x1, %rdi
shlq $0x3, %rdi
callq 0x3a870
movq %rax, -0x100(%rbp)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x4b000
movq -0x48(%rbp), %rdi
movl -0x104(%rbp), %esi
callq 0x1c280
movq %rax, %rdx
movq -0x100(%rbp), %rax
movslq -0x104(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x4afc0
movq -0x100(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4b02c
callq 0x4b9b0
cmpl $0x2, -0x1c(%rbp)
jne 0x4b11c
cmpl $0x0, -0x2c(%rbp)
jne 0x4b04a
movq -0x38(%rbp), %rcx
movq 0x64f89(%rip), %rax     # 0xaffd0
movq %rcx, (%rax)
jmp 0x4b04c
movq -0x28(%rbp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x4b078
movq -0x110(%rbp), %rax
movq (%rax), %rdi
movq -0x110(%rbp), %rsi
callq 0x12a20
movl %eax, -0x114(%rbp)
jmp 0x4b094
movq -0x110(%rbp), %rax
movq (%rax), %rdi
movq -0x110(%rbp), %rsi
callq 0x12be0
movl %eax, -0x114(%rbp)
jmp 0x4b096
xorl %eax, %eax
cmpl $-0x1, -0x114(%rbp)
movb %al, -0x1b9(%rbp)
jne 0x4b0b8
callq 0x12120
cmpl $0x4, (%rax)
sete %al
movb %al, -0x1b9(%rbp)
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0x4b04c
movq -0x110(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1c8(%rbp)
callq 0x12120
cmpl $0x0, (%rax)
je 0x4b0ec
callq 0x12120
movl (%rax), %eax
movl %eax, -0x1cc(%rbp)
jmp 0x4b0f9
movl $0x2, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x4b0f9
movl -0x1cc(%rbp), %edi
callq 0x6dd40
movq -0x1c8(%rbp), %rsi
movq %rax, %rdx
leaq 0x48568(%rip), %rdi     # 0x9367d
movb $0x0, %al
callq 0x1ac40
leaq -0x168(%rbp), %rdi
callq 0x120f0
cmpq $0x0, -0xd0(%rbp)
je 0x4b145
movq -0xd0(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x12b80
cmpl $-0x1, -0x70(%rbp)
je 0x4b16d
movl -0x70(%rbp), %esi
leaq -0x168(%rbp), %rdi
xorl %edx, %edx
callq 0x12b00
movl -0x70(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0x12ab0
jmp 0x4b1ad
cmpl $-0x1, -0x64(%rbp)
je 0x4b1ab
cmpl $0x0, -0x64(%rbp)
je 0x4b1ab
movl -0x64(%rbp), %esi
leaq -0x168(%rbp), %rdi
xorl %edx, %edx
callq 0x12b00
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
je 0x4b1a9
movl -0x64(%rbp), %eax
cmpl -0x6c(%rbp), %eax
je 0x4b1a9
movl -0x64(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0x12ab0
jmp 0x4b1ab
jmp 0x4b1ad
cmpl $-0x1, -0x74(%rbp)
je 0x4b1d8
movl -0x74(%rbp), %esi
leaq -0x168(%rbp), %rdi
movl $0x1, %edx
callq 0x12b00
movl -0x74(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0x12ab0
jmp 0x4b213
cmpl $-0x1, -0x68(%rbp)
je 0x4b211
cmpl $0x1, -0x68(%rbp)
je 0x4b211
movl -0x68(%rbp), %esi
leaq -0x168(%rbp), %rdi
movl $0x1, %edx
callq 0x12b00
movl -0x68(%rbp), %eax
cmpl -0x6c(%rbp), %eax
je 0x4b20f
movl -0x68(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0x12ab0
jmp 0x4b211
jmp 0x4b213
cmpl $-0x1, -0x78(%rbp)
je 0x4b23e
movl -0x78(%rbp), %esi
leaq -0x168(%rbp), %rdi
movl $0x2, %edx
callq 0x12b00
movl -0x78(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0x12ab0
jmp 0x4b28f
cmpl $-0x1, -0x6c(%rbp)
je 0x4b26f
cmpl $0x2, -0x6c(%rbp)
je 0x4b26f
movl -0x6c(%rbp), %esi
leaq -0x168(%rbp), %rdi
movl $0x2, %edx
callq 0x12b00
movl -0x6c(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0x12ab0
jmp 0x4b28d
cmpl $0x0, -0x7c(%rbp)
je 0x4b28b
leaq -0x168(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x12b00
jmp 0x4b28d
jmp 0x4b28f
movq -0x28(%rbp), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x4b314
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1e0(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4b2d5
movq 0x64d07(%rip), %rax     # 0xaffd0
movq (%rax), %rax
movq %rax, -0x1e8(%rbp)
jmp 0x4b2e0
movq -0x38(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1d8(%rbp), %r8
movq -0x1e0(%rbp), %rsi
movq -0x1e8(%rbp), %r9
leaq -0x16c(%rbp), %rdi
leaq -0x168(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x12800
movl %eax, -0xf4(%rbp)
jmp 0x4b389
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1f8(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x1f0(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4b34c
movq 0x64c90(%rip), %rax     # 0xaffd0
movq (%rax), %rax
movq %rax, -0x200(%rbp)
jmp 0x4b357
movq -0x38(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x1f0(%rbp), %r8
movq -0x1f8(%rbp), %rsi
movq -0x200(%rbp), %r9
leaq -0x16c(%rbp), %rdi
leaq -0x168(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x12990
movl %eax, -0xf4(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x122c0
cmpl $-0x1, -0x70(%rbp)
je 0x4b3a3
movl -0x70(%rbp), %edi
callq 0x12470
cmpl $-0x1, -0x74(%rbp)
je 0x4b3b1
movl -0x74(%rbp), %edi
callq 0x12470
cmpl $-0x1, -0x78(%rbp)
je 0x4b3bf
movl -0x78(%rbp), %edi
callq 0x12470
cmpl $0x0, -0x2c(%rbp)
je 0x4b3ca
callq 0x4b9c0
movq -0x38(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x4f0b0
cmpl $0x0, -0xf4(%rbp)
je 0x4b43a
movq -0x18(%rbp), %rax
movq %rax, -0x208(%rbp)
callq 0x12120
cmpl $0x0, (%rax)
je 0x4b407
callq 0x12120
movl (%rax), %eax
movl %eax, -0x20c(%rbp)
jmp 0x4b414
movl $0x2, %eax
movl %eax, -0x20c(%rbp)
jmp 0x4b414
movl -0x20c(%rbp), %edi
callq 0x6dd40
movq %rax, %rdx
movq -0x208(%rbp), %rax
movq (%rax), %rsi
leaq 0x4824a(%rip), %rdi     # 0x9367d
movb $0x0, %al
callq 0x1ac40
leaq 0x62b4f(%rip), %rdi     # 0xadf90
movl $0x28, %esi
callq 0x12de0
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl -0x16c(%rbp), %ecx
movq -0x178(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x178(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x178(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x178(%rbp), %rax
movq $0x0, 0x20(%rax)
movl -0x84(%rbp), %ecx
movq -0x178(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
andq $0x4, %rax
cmpq $0x0, %rax
je 0x4b4c8
movq -0x178(%rbp), %rax
movl (%rax), %ecx
orl $0x8, %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x20(%rbp)
je 0x4b5b9
cmpl $-0x1, -0x64(%rbp)
je 0x4b514
movl -0x64(%rbp), %edi
movq -0x50(%rbp), %rsi
movl $0x1, %edx
callq 0x4f110
movq %rax, %rcx
movq -0x178(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x178(%rbp), %rcx
xorl %eax, %eax
cmpq 0x10(%rcx), %rax
jne 0x4b512
leaq 0x48177(%rip), %rdi     # 0x93684
callq 0x1ad60
jmp 0x4b514
cmpl $-0x1, -0x68(%rbp)
je 0x4b553
movl -0x68(%rbp), %edi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x4f110
movq %rax, %rcx
movq -0x178(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x178(%rbp), %rcx
xorl %eax, %eax
cmpq 0x18(%rcx), %rax
jne 0x4b551
leaq 0x48138(%rip), %rdi     # 0x93684
callq 0x1ad60
jmp 0x4b553
cmpl $-0x1, -0x6c(%rbp)
je 0x4b592
movl -0x6c(%rbp), %edi
movq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x4f110
movq %rax, %rcx
movq -0x178(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x178(%rbp), %rcx
xorl %eax, %eax
cmpq 0x20(%rcx), %rax
jne 0x4b590
leaq 0x480f9(%rip), %rdi     # 0x93684
callq 0x1ad60
jmp 0x4b592
movq -0x178(%rbp), %rdi
movabsq $-0x1000000000000, %rsi # imm = 0xFFFF000000000000
callq 0x7b610
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x178(%rbp), %rdi
callq 0x4a130
nopw %cs:(%rax,%rax)