// File: /workspace/github_c_makefile_star2_O3/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 0x4e80b
xorl %eax, %eax
callq 0x4ef34
xorl %eax, %eax
callq 0x4f438
xorl %eax, %eax
callq 0x4f5d8
xorl %eax, %eax
callq 0x4f740
xorl %eax, %eax
callq 0x4fcac
xorl %edi, %edi
callq 0x1fb46
movq %rax, -0x30(%rbp)
movl %r15d, %edi
callq 0x14690
movq %rax, %r12
testl %r15d, %r15d
jle 0x4f2fd
movl %r15d, %r13d
xorl %ebx, %ebx
movabsq $-0x6000000000000, %r15 # imm = 0xFFFA000000000000
movq (%r14,%rbx,8), %rdi
callq 0x4482c
movq %rax, %rdi
movq %r15, %rsi
callq 0x4ed39
movq %r12, %rdi
movq %rax, %rsi
callq 0x148a3
incq %rbx
cmpq %rbx, %r13
jne 0x4f2d6
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r12, %rdi
callq 0x4ed7e
leaq 0x1cce0(%rip), %rsi     # 0x6bff6
leaq 0x1cce3(%rip), %rcx     # 0x6c000
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rdx
callq 0x489e4
xorl %edi, %edi
callq 0x47425
movabsq $-0x3800000000000, %rsi # imm = 0xFFFC800000000000
movq %rax, %rdi
callq 0x4ed7e
leaq 0x1cccc(%rip), %rsi     # 0x6c018
leaq 0x1ccd1(%rip), %rcx     # 0x6c024
movq %rbx, %rdi
movq %rax, %rdx
callq 0x489e4
movq 0x8(%r14), %rdi
callq 0x12320
testl %eax, %eax
jne 0x4f41c
leaq 0x1ccdd(%rip), %rdi     # 0x6c053
leaq 0x1ccea(%rip), %rsi     # 0x6c067
callq 0x12970
testq %rax, %rax
je 0x4f428
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
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 0x4f42d
movq %rax, %r12
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x121d0
testq %rax, %rax
je 0x4f432
movq %r14, %rdi
callq 0x122b0
leaq 0x1cc71(%rip), %rcx     # 0x6c05c
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x40bb4
movl %eax, %ebx
movq %r12, %rdi
callq 0x120b0
callq 0x4e954
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 0x142f0
callq 0x1436a
callq 0x14342
callq 0x1431a
nop