// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/boot/boot.c
// Function: main
int main(int argc, const char **argv) {

    /* Init janet */
    janet_init();

    /* Run tests */
    array_test();
    buffer_test();
    number_test();
    system_test();
    table_test();

    /* C tests passed */

    /* Set up VM */
    int status;
    JanetTable *env;

    env = janet_core_env(NULL);

    /* Create args tuple */
    JanetArray *args = janet_array(argc);
    for (int i = 0; i < argc; i++)
        janet_array_push(args, janet_cstringv(argv[i]));
    janet_def(env, "boot/args", janet_wrap_array(args), "Command line arguments.");

    /* Add in options from janetconf.h so boot.janet can configure the image as needed. */
    JanetTable *opts = janet_table(0);
#ifdef JANET_NO_DOCSTRINGS
    janet_table_put(opts, janet_ckeywordv("no-docstrings"), janet_wrap_true());
#endif
#ifdef JANET_NO_SOURCEMAPS
    janet_table_put(opts, janet_ckeywordv("no-sourcemaps"), janet_wrap_true());
#endif
    janet_def(env, "boot/config", janet_wrap_table(opts), "Boot options");

    /* Run bootstrap script to generate core image */
    const char *boot_filename;
#ifdef JANET_NO_SOURCEMAPS
    boot_filename = NULL;
#else
    boot_filename = "boot.janet";
#endif

    int chdir_status = chdir(argv[1]);
    if (chdir_status) {
        fprintf(stderr, "Could not change to directory %s\n", argv[1]);
        exit(1);
    }

    FILE *boot_file = fopen("src/boot/boot.janet", "rb");
    if (NULL == boot_file) {
        fprintf(stderr, "Could not open src/boot/boot.janet\n");
        exit(1);
    }

    /* Slurp file into buffer */
    fseek(boot_file, 0, SEEK_END);
    size_t boot_size = ftell(boot_file);
    fseek(boot_file, 0, SEEK_SET);
    unsigned char *boot_buffer = janet_malloc(boot_size);
    if (NULL == boot_buffer) {
        fprintf(stderr, "Failed to allocate boot buffer\n");
        exit(1);
    }
    if (!fread(boot_buffer, 1, boot_size, boot_file)) {
        fprintf(stderr, "Failed to read into boot buffer\n");
        exit(1);
    }
    fclose(boot_file);

    status = janet_dobytes(env, boot_buffer, (int32_t) boot_size, boot_filename, NULL);
    janet_free(boot_buffer);

    /* Deinitialize vm */
    janet_deinit();

    return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edi, %r15d
callq 0x4ae26
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x4b588
xorl %eax, %eax
callq 0x4bac4
xorl %eax, %eax
callq 0x4bc50
xorl %eax, %eax
callq 0x4bdac
xorl %eax, %eax
callq 0x4c2ec
xorl %edi, %edi
callq 0x1dd58
movq %rax, -0x30(%rbp)
movl %r15d, %edi
callq 0x12f68
movq %rax, %r12
testl %r15d, %r15d
movl $0x0, %ebx
cmovgl %r15d, %ebx
movabsq $-0x6000000000000, %r15 # imm = 0xFFFA000000000000
cmpq %r13, %rbx
je 0x4b934
movq (%r14,%r13,8), %rdi
callq 0x411ea
movq %rax, %rdi
movq %r15, %rsi
callq 0x4b366
movq %r12, %rdi
movq %rax, %rsi
callq 0x131d2
incq %r13
jmp 0x4b90b
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r12, %rdi
callq 0x4b3ab
leaq 0x1c6c9(%rip), %rsi     # 0x68016
leaq 0x1c6cc(%rip), %rcx     # 0x68020
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rdx
callq 0x44f49
xorl %edi, %edi
callq 0x43b8a
movabsq $-0x3800000000000, %rsi # imm = 0xFFFC800000000000
movq %rax, %rdi
callq 0x4b3ab
leaq 0x1c6b5(%rip), %rsi     # 0x68038
leaq 0x1c6ba(%rip), %rcx     # 0x68044
movq %rbx, %rdi
movq %rax, %rdx
callq 0x44f49
movq 0x8(%r14), %rdi
callq 0x12320
testl %eax, %eax
jne 0x4ba57
leaq 0x1c6c6(%rip), %rdi     # 0x68073
leaq 0x1c6d3(%rip), %rsi     # 0x68087
callq 0x12970
testq %rax, %rax
je 0x4ba75
movq %rax, %r14
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x12820
movq %r14, %rdi
callq 0x12600
movq %rax, %r15
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x12820
movq %r15, %rdi
callq 0x12760
testq %rax, %rax
je 0x4ba8a
movq %rax, %r12
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x121d0
testq %rax, %rax
je 0x4ba9f
movq %r14, %rdi
callq 0x122b0
leaq 0x1c656(%rip), %rcx     # 0x6807c
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x3d5ac
movl %eax, %ebx
movq %r12, %rdi
callq 0x120b0
callq 0x4af60
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x34592(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
movq 0x8(%r14), %rdx
leaq 0x1c5e5(%rip), %rsi     # 0x68051
xorl %eax, %eax
callq 0x125e0
jmp 0x4babb
movq 0x34574(%rip), %rax     # 0x7fff0
movq (%rax), %rcx
leaq 0x1c604(%rip), %rdi     # 0x6808a
pushq $0x23
jmp 0x4bab2
movq 0x3455f(%rip), %rax     # 0x7fff0
movq (%rax), %rcx
leaq 0x1c613(%rip), %rdi     # 0x680ae
pushq $0x1f
jmp 0x4bab2
movq 0x3454a(%rip), %rax     # 0x7fff0
movq (%rax), %rcx
leaq 0x1c61e(%rip), %rdi     # 0x680ce
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x12a80
pushq $0x1
popq %rdi
callq 0x12a60
nop