// File: /workspace/github_c_makefile_star2_O2/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 0x177(%rip), %rdi       # 0x4bbd3
callq 0x4c720
callq 0x3e81a
xorl %edi, %edi
callq 0x1867b
movq %rax, %rbx
leaq 0x5295c(%rip), %rdi     # 0x9e3d3
callq 0x18251
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
movq %rax, %rdi
callq 0x1824a
movq %rax, %r12
leaq -0x1430(%rip), %rdi     # 0x4a668
movabsq $-0x1800000000000, %rsi # imm = 0xFFFE800000000000
callq 0x16065
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x15f5f
movq %rbx, %rdi
callq 0x2128f
movq %rax, %rbx
movl %ebp, %edi
callq 0x16142
movq %rax, %r12
movslq %ebp, %r13
pushq $0x1
popq %rbp
cmpq %r13, %rbp
jge 0x4baf9
movq (%r15,%rbp,8), %rdi
callq 0x1892a
movq %rax, %rdi
movq %r14, %rsi
callq 0x1824a
movq %r12, %rdi
movq %rax, %rsi
callq 0x1637d
incq %rbp
jmp 0x4bad0
leaq 0x50332(%rip), %rdi     # 0x9be32
callq 0x18251
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movq %rax, %rdi
callq 0x1824a
movq %rax, %r13
movq (%r15), %rdi
callq 0x1892a
movq %rax, %rdi
movq %r14, %rsi
callq 0x1824a
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x15f5f
leaq 0x549a2(%rip), %rdi     # 0xa04e4
callq 0x18251
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x21623
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r12, %rdi
callq 0x16065
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq (%r14), %rdi
callq 0x1b154
pushq $0x40
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rdi
movq %r15, %rcx
callq 0x26949
movq %rax, %r14
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
movq %rax, %rdi
callq 0x16065
movq %rax, %rdi
callq 0x21583
movq %rbx, 0x28(%r14)
movq %r14, %rdi
callq 0x373bb
movl %eax, %ebx
callq 0x3124d
callq 0x4b9aa
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq