// File: /workspace/github_c_makefile_star2_O1/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 0x4f47f
xorl %eax, %eax
callq 0x4fba8
xorl %eax, %eax
callq 0x500ac
xorl %eax, %eax
callq 0x5024c
xorl %eax, %eax
callq 0x503b4
xorl %eax, %eax
callq 0x50920
xorl %edi, %edi
callq 0x1feb8
movq %rax, -0x30(%rbp)
movl %r15d, %edi
callq 0x146a0
movq %rax, %r12
testl %r15d, %r15d
jle 0x4ff71
movl %r15d, %r13d
xorl %ebx, %ebx
movabsq $-0x6000000000000, %r15 # imm = 0xFFFA000000000000
movq (%r14,%rbx,8), %rdi
callq 0x4516c
movq %rax, %rdi
movq %r15, %rsi
callq 0x4f9ad
movq %r12, %rdi
movq %rax, %rsi
callq 0x148b3
incq %rbx
cmpq %rbx, %r13
jne 0x4ff4a
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r12, %rdi
callq 0x4f9f2
leaq 0x1d08c(%rip), %rsi     # 0x6d016
leaq 0x1d08f(%rip), %rcx     # 0x6d020
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rdx
callq 0x494f4
xorl %edi, %edi
callq 0x47e96
movabsq $-0x3800000000000, %rsi # imm = 0xFFFC800000000000
movq %rax, %rdi
callq 0x4f9f2
leaq 0x1d078(%rip), %rsi     # 0x6d038
leaq 0x1d07d(%rip), %rcx     # 0x6d044
movq %rbx, %rdi
movq %rax, %rdx
callq 0x494f4
movq 0x8(%r14), %rdi
callq 0x12320
testl %eax, %eax
jne 0x50090
leaq 0x1d089(%rip), %rdi     # 0x6d073
leaq 0x1d096(%rip), %rsi     # 0x6d087
callq 0x12980
testq %rax, %rax
je 0x5009c
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x12830
movq %r14, %rdi
callq 0x12610
movq %rax, %r15
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x12830
movq %r15, %rdi
callq 0x12770
testq %rax, %rax
je 0x500a1
movq %rax, %r12
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x121d0
testq %rax, %rax
je 0x500a6
movq %r14, %rdi
callq 0x122b0
leaq 0x1d01d(%rip), %rcx     # 0x6d07c
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x41328
movl %eax, %ebx
movq %r12, %rdi
callq 0x120b0
callq 0x4f5c8
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x8, %r14
movq %r14, %rdi
callq 0x14300
callq 0x1437a
callq 0x14352
callq 0x1432a
nop