// File: /workspace/github_c_makefile_star2_O1/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       # 0x59494
callq 0x5a380
callq 0x496bc
xorl %edi, %edi
callq 0x1bba5
movq %rax, %rbx
leaq 0x52f94(%rip), %rdi     # 0xac2c3
callq 0x1b640
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
movq %rax, %rdi
callq 0x1b639
movq %rax, %r12
leaq -0xfc0(%rip), %rdi      # 0x58390
movabsq $-0x1800000000000, %rsi # imm = 0xFFFE800000000000
callq 0x1886d
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x18739
movq %rbx, %rdi
callq 0x266d3
movq %rax, %rbx
movl %ebp, %edi
callq 0x18958
movq %rax, %r12
cmpl $0x2, %ebp
jl 0x593b6
movl %ebp, %r13d
movl $0x1, %ebp
movq (%r15,%rbp,8), %rdi
callq 0x1bf4a
movq %rax, %rdi
movq %r14, %rsi
callq 0x1b639
movq %r12, %rdi
movq %rax, %rsi
callq 0x18b37
incq %rbp
cmpq %rbp, %r13
jne 0x5938f
leaq 0x50965(%rip), %rdi     # 0xa9d22
callq 0x1b640
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movq %rax, %rdi
callq 0x1b639
movq %rax, %r13
movq (%r15), %rdi
callq 0x1bf4a
movq %rax, %rdi
movq %r14, %rsi
callq 0x1b639
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x18739
leaq 0x54fb9(%rip), %rdi     # 0xae3b8
callq 0x1b640
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x26b46
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r12, %rdi
callq 0x1886d
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movq (%r14), %rdi
callq 0x1f147
movq %rax, %rdi
movl $0x40, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2cb14
movq %rax, %r14
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
movq %rax, %rdi
callq 0x1886d
movq %rax, %rdi
callq 0x26aca
movq %rbx, 0x28(%r14)
movq %r14, %rdi
callq 0x40db6
movl %eax, %ebx
callq 0x397a8
callq 0x5926b
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq