// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/build/c/shell.c
// Function: main
int main(int argc, char **argv) {
    int i, status;
    JanetArray *args;
    JanetTable *env;

#ifdef _WIN32
    setup_console_output();
#endif

#if !defined(JANET_SIMPLE_GETLINE)
    atexit(clear_at_exit);
#endif

#if defined(JANET_PRF)
    uint8_t hash_key[JANET_HASH_KEY_SIZE + 1];
#ifdef JANET_REDUCED_OS
    char *envvar = NULL;
#else
    char *envvar = getenv("JANET_HASHSEED");
#endif
    if (NULL != envvar) {
        strncpy((char *) hash_key, envvar, sizeof(hash_key) - 1);
    } else if (janet_cryptorand(hash_key, JANET_HASH_KEY_SIZE) != 0) {
        fputs("unable to initialize janet PRF hash function.\n", stderr);
        return 1;
    }
    janet_init_hash_key(hash_key);
#endif

    /* Set up VM */
    janet_init();

    /* Replace original getline with new line getter */
    JanetTable *replacements = janet_table(0);
    janet_table_put(replacements, janet_csymbolv("getline"), janet_wrap_cfunction(janet_line_getter));
    janet_line_init();

    /* Get core env */
    env = janet_core_env(replacements);

    /* Create args tuple */
    args = janet_array(argc);
    for (i = 1; i < argc; i++)
        janet_array_push(args, janet_cstringv(argv[i]));

    /* Save current executable path to (dyn :executable) */
    janet_table_put(env, janet_ckeywordv("executable"), janet_cstringv(argv[0]));

    /* Run startup script */
    Janet mainfun;
    janet_resolve(env, janet_csymbol("cli-main"), &mainfun);
    Janet mainargs[1] = { janet_wrap_array(args) };
    JanetFiber *fiber = janet_fiber(janet_unwrap_function(mainfun), 64, 1, mainargs);
    janet_gcroot(janet_wrap_fiber(fiber));
    fiber->env = env;

    /* Run the fiber in an event loop */
    status = janet_loop_fiber(fiber);

    /* Deinitialize vm */
    janet_deinit();
    janet_line_deinit();

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movl %edi, %ebp
movabsq $-0x6000000000000, %r14 # imm = 0xFFFA000000000000
leaq 0x180(%rip), %rdi       # 0x5794e
callq 0x58800
callq 0x47dbe
xorl %edi, %edi
callq 0x1a98b
movq %rax, %rbx
leaq 0x52bc6(%rip), %rdi     # 0xaa3af
callq 0x1a519
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
movq %rax, %rdi
callq 0x1a512
movq %rax, %r12
leaq -0x10de(%rip), %rdi     # 0x5672c
movabsq $-0x1800000000000, %rsi # imm = 0xFFFE800000000000
callq 0x17805
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x176cb
movq %rbx, %rdi
callq 0x25406
movq %rax, %rbx
movl %ebp, %edi
callq 0x178f0
movq %rax, %r12
cmpl $0x2, %ebp
jl 0x57870
movl %ebp, %r13d
movl $0x1, %ebp
movq (%r15,%rbp,8), %rdi
callq 0x1ad1c
movq %rax, %rdi
movq %r14, %rsi
callq 0x1a512
movq %r12, %rdi
movq %rax, %rsi
callq 0x17acf
incq %rbp
cmpq %rbp, %r13
jne 0x57849
leaq 0x50597(%rip), %rdi     # 0xa7e0e
callq 0x1a519
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movq %rax, %rdi
callq 0x1a512
movq %rax, %r13
movq (%r15), %rdi
callq 0x1ad1c
movq %rax, %rdi
movq %r14, %rsi
callq 0x1a512
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x176cb
leaq 0x54bef(%rip), %rdi     # 0xac4a8
callq 0x1a519
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x2587d
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r12, %rdi
callq 0x17805
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq (%r14), %rdi
callq 0x1df4d
movq %rax, %rdi
movl $0x40, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2b630
movq %rax, %r14
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
movq %rax, %rdi
callq 0x17805
movq %rax, %rdi
callq 0x25804
movq %rbx, 0x28(%r14)
movq %r14, %rdi
callq 0x3f896
movl %eax, %ebx
callq 0x3852a
callq 0x57725
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq