// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/os.c
// Function: os_stat_or_lstat
static Janet os_stat_or_lstat(int do_lstat, int32_t argc, Janet *argv) {
    janet_sandbox_assert(JANET_SANDBOX_FS_READ);
    janet_arity(argc, 1, 2);
    const char *path = janet_getcstring(argv, 0);
    JanetTable *tab = NULL;
    const uint8_t *key = NULL;
    if (argc == 2) {
        if (janet_checktype(argv[1], JANET_KEYWORD)) {
            key = janet_getkeyword(argv, 1);
        } else {
            tab = janet_gettable(argv, 1);
        }
    } else {
        tab = janet_table(0);
    }

    /* Build result */
    jstat_t st;
#ifdef JANET_WINDOWS
    (void) do_lstat;
    int res = _stat(path, &st);
#else
    int res;
    if (do_lstat) {
        res = lstat(path, &st);
    } else {
        res = stat(path, &st);
    }
#endif
    if (-1 == res) {
        return janet_wrap_nil();
    }

    if (NULL == key) {
        /* Put results in table */
        for (const struct OsStatGetter *sg = os_stat_getters; sg->name != NULL; sg++) {
            janet_table_put(tab, janet_ckeywordv(sg->name), sg->fn(&st));
        }
        return janet_wrap_table(tab);
    } else {
        /* Get one result */
        for (const struct OsStatGetter *sg = os_stat_getters; sg->name != NULL; sg++) {
            if (janet_cstrcmp(key, sg->name)) continue;
            return sg->fn(&st);
        }
        janet_panicf("unexpected keyword %v", janet_wrap_keyword(key));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %rbx
movl %esi, %r14d
movl %edi, %r15d
movl $0x40, %edi
callq 0x4e921
movl %r14d, %edi
movl $0x1, %esi
movl $0x2, %edx
callq 0x1920c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x19817
movq %rax, %r12
cmpl $0x2, %r14d
jne 0x37a48
movq 0x8(%rbx), %rax
shrq $0x2f, %rax
movq %rbx, %rdi
movl $0x1, %esi
cmpl $0x1fff6, %eax          # imm = 0x1FFF6
jne 0x37a57
callq 0x1943f
movq %rax, %r14
xorl %ebx, %ebx
jmp 0x37a62
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x47425
movq %rax, %rbx
jmp 0x37a62
callq 0x193ca
movq %rax, %rbx
xorl %r14d, %r14d
leaq -0xb8(%rbp), %rsi
movq %r12, %rdi
testl %r15d, %r15d
je 0x37a78
callq 0x12280
jmp 0x37a7d
callq 0x12350
cmpl $-0x1, %eax
je 0x37adf
testq %r14, %r14
je 0x37aff
leaq 0x2eb67(%rip), %rsi     # 0x665f5
leaq 0x4b71b(%rip), %rbx     # 0x831b0
movq %r14, %rdi
callq 0x4872e
testl %eax, %eax
je 0x37ad0
movq (%rbx), %rsi
addq $0x10, %rbx
testq %rsi, %rsi
jne 0x37a95
movabsq $-0x5000000000000, %rsi # imm = 0xFFFB000000000000
movq %r14, %rdi
callq 0x4ed39
leaq 0x2aa6e(%rip), %rdi     # 0x62534
movq %rax, %rsi
xorl %eax, %eax
callq 0x190bb
leaq -0xb8(%rbp), %rdi
callq *-0x8(%rbx)
jmp 0x37b65
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ece6
leaq 0x2eaef(%rip), %rdi     # 0x665f5
leaq 0x4b6a3(%rip), %r13     # 0x831b0
movabsq $-0x5000000000000, %r14 # imm = 0xFFFB000000000000
leaq -0xb8(%rbp), %r15
callq 0x47261
movq %rax, %rdi
movq %r14, %rsi
callq 0x4ed39
movq %rax, %r12
movq %r15, %rdi
callq *-0x8(%r13)
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x476f0
movq (%r13), %rdi
addq $0x10, %r13
testq %rdi, %rdi
jne 0x37b1e
movabsq $-0x3800000000000, %rsi # imm = 0xFFFC800000000000
movq %rbx, %rdi
callq 0x4ed7e
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq