// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/ffi.c
// Function: janet_ffi_read_one
static Janet janet_ffi_read_one(const uint8_t *from, JanetFFIType type, int recur) {
    if (recur == 0) janet_panic("recursion too deep");
    if (type.array_count >= 0) {
        JanetFFIType el_type = type;
        el_type.array_count = -1;
        size_t el_size = type_size(el_type);
        JanetArray *array = janet_array(type.array_count);
        for (int32_t i = 0; i < type.array_count; i++) {
            janet_array_push(array, janet_ffi_read_one(from, el_type, recur - 1));
            from += el_size;
        }
        return janet_wrap_array(array);
    }
    switch (type.prim) {
        default:
        case JANET_FFI_TYPE_VOID:
            return janet_wrap_nil();
        case JANET_FFI_TYPE_STRUCT: {
            JanetFFIStruct *st = type.st;
            Janet *tup = janet_tuple_begin(st->field_count);
            for (uint32_t i = 0; i < st->field_count; i++) {
                JanetFFIType tp = st->fields[i].type;
                tup[i] = janet_ffi_read_one(from + st->fields[i].offset, tp, recur - 1);
            }
            return janet_wrap_tuple(janet_tuple_end(tup));
        }
        case JANET_FFI_TYPE_DOUBLE:
            return janet_wrap_number(((double *)(from))[0]);
        case JANET_FFI_TYPE_FLOAT:
            return janet_wrap_number(((float *)(from))[0]);
        case JANET_FFI_TYPE_PTR: {
            void *ptr = ((void **)(from))[0];
            return (NULL == ptr) ? janet_wrap_nil() : janet_wrap_pointer(ptr);
        }
        case JANET_FFI_TYPE_STRING:
            return janet_cstringv(((char **)(from))[0]);
        case JANET_FFI_TYPE_BOOL:
            return janet_wrap_boolean(((bool *)(from))[0]);
        case JANET_FFI_TYPE_INT8:
            return janet_wrap_number(((int8_t *)(from))[0]);
        case JANET_FFI_TYPE_INT16:
            return janet_wrap_number(((int16_t *)(from))[0]);
        case JANET_FFI_TYPE_INT32:
            return janet_wrap_number(((int32_t *)(from))[0]);
        case JANET_FFI_TYPE_UINT8:
            return janet_wrap_number(((uint8_t *)(from))[0]);
        case JANET_FFI_TYPE_UINT16:
            return janet_wrap_number(((uint16_t *)(from))[0]);
        case JANET_FFI_TYPE_UINT32:
            return janet_wrap_number(((uint32_t *)(from))[0]);
#ifdef JANET_INT_TYPES
        case JANET_FFI_TYPE_INT64:
            return janet_wrap_s64(((int64_t *)(from))[0]);
        case JANET_FFI_TYPE_UINT64:
            return janet_wrap_u64(((uint64_t *)(from))[0]);
#else
        case JANET_FFI_TYPE_INT64:
            return janet_wrap_number(((int64_t *)(from))[0]);
        case JANET_FFI_TYPE_UINT64:
            return janet_wrap_number(((uint64_t *)(from))[0]);
#endif
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testl %ecx, %ecx
je 0x290ac
movl %ecx, %r13d
movq %rdi, %rbx
testq %rdx, %rdx
js 0x28eae
movl %r13d, %r12d
movq %rdx, %r13
shrq $0x20, %r13
movl %edx, %eax
cmpq $0xe, %rax
movq %rdx, -0x48(%rbp)
jne 0x28ede
movq %rsi, %r15
movl (%rsi), %eax
jmp 0x28ef0
decl %edx
cmpl $0xd, %edx
ja 0x28fe7
leaq 0x33040(%rip), %rax     # 0x5bf00
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movzbl (%rbx), %eax
movabsq $-0x7000000000000, %rdi # imm = 0xFFF9000000000000
orq %rax, %rdi
jmp 0x28ff1
movq %rsi, %r15
shlq $0x4, %rax
leaq 0x33fb4(%rip), %rcx     # 0x5cea0
movq (%rax,%rcx), %rax
movq %rax, -0x40(%rbp)
movl %r13d, %edi
callq 0x146a0
movq %rax, -0x30(%rbp)
testl %r13d, %r13d
movl %r12d, -0x34(%rbp)
movq %r15, %r12
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r14
jle 0x28f49
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
orq %rax, %r15
decl -0x34(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl -0x34(%rbp), %ecx
callq 0x28e6d
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x148b3
addq %r14, %rbx
decl %r13d
jne 0x28f24
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq -0x30(%rbp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f9f2
movq (%rbx), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c747
movsd (%rbx), %xmm0
jmp 0x29099
movq (%rbx), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c77c
cvtsi2sdl (%rbx), %xmm0
jmp 0x29099
movq (%rbx), %rdi
callq 0x4516c
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
jmp 0x2906e
cvtss2sd (%rbx), %xmm0
jmp 0x29099
movswl (%rbx), %eax
jmp 0x29095
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x28fe7
movabsq $-0x800000000000, %rsi  # imm = 0xFFFF800000000000
jmp 0x28f57
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f95a
movsbl (%rbx), %eax
jmp 0x29095
movl 0x8(%rsi), %edi
movq %rsi, -0x30(%rbp)
callq 0x48a50
movq -0x30(%rbp), %rcx
movq %rax, %r12
cmpl $0x0, 0x8(%rcx)
je 0x2905c
decl %r13d
leaq 0x20(%rcx), %r14
xorl %r15d, %r15d
movq -0x10(%r14), %rsi
movq -0x8(%r14), %rdx
movq (%r14), %rdi
addq %rbx, %rdi
movl %r13d, %ecx
callq 0x28e6d
movq %rax, (%r12,%r15,8)
incq %r15
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
addq $0x18, %r14
cmpq %rax, %r15
jb 0x2902f
movq %r12, %rdi
callq 0x48a81
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f9ad
movzbl (%rbx), %eax
jmp 0x29095
movl (%rbx), %eax
cvtsi2sd %rax, %xmm0
jmp 0x29099
movzwl (%rbx), %eax
cvtsi2sd %eax, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4fab8
leaq 0x34247(%rip), %rdi     # 0x5d2fa
callq 0x19263