// File: /workspace/github_c_makefile_star2_O3/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 0x28bd7
movl %ecx, %r13d
movq %rdi, %rbx
testq %rdx, %rdx
js 0x289d9
movl %r13d, %r12d
movq %rdx, %r13
shrq $0x20, %r13
movl %edx, %eax
cmpq $0xe, %rax
movq %rdx, -0x48(%rbp)
jne 0x28a09
movq %rsi, %r15
movl (%rsi), %eax
jmp 0x28a1b
decl %edx
cmpl $0xd, %edx
ja 0x28b12
leaq 0x32515(%rip), %rax     # 0x5af00
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movzbl (%rbx), %eax
movabsq $-0x7000000000000, %rdi # imm = 0xFFF9000000000000
orq %rax, %rdi
jmp 0x28b1c
movq %rsi, %r15
shlq $0x4, %rax
leaq 0x33489(%rip), %rcx     # 0x5bea0
movq (%rax,%rcx), %rax
movq %rax, -0x40(%rbp)
movl %r13d, %edi
callq 0x14690
movq %rax, -0x30(%rbp)
testl %r13d, %r13d
movl %r12d, -0x34(%rbp)
movq %r15, %r12
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r14
jle 0x28a74
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 0x28998
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x148a3
addq %r14, %rbx
decl %r13d
jne 0x28a4f
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 0x4ed7e
movq (%rbx), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c267
movsd (%rbx), %xmm0
jmp 0x28bc4
movq (%rbx), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c29c
cvtsi2sdl (%rbx), %xmm0
jmp 0x28bc4
movq (%rbx), %rdi
callq 0x4482c
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
jmp 0x28b99
cvtss2sd (%rbx), %xmm0
jmp 0x28bc4
movswl (%rbx), %eax
jmp 0x28bc0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x28b12
movabsq $-0x800000000000, %rsi  # imm = 0xFFFF800000000000
jmp 0x28a82
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ece6
movsbl (%rbx), %eax
jmp 0x28bc0
movl 0x8(%rsi), %edi
movq %rsi, -0x30(%rbp)
callq 0x47fa0
movq -0x30(%rbp), %rcx
movq %rax, %r12
cmpl $0x0, 0x8(%rcx)
je 0x28b87
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 0x28998
movq %rax, (%r12,%r15,8)
incq %r15
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
addq $0x18, %r14
cmpq %rax, %r15
jb 0x28b5a
movq %r12, %rdi
callq 0x47fd1
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ed39
movzbl (%rbx), %eax
jmp 0x28bc0
movl (%rbx), %eax
cvtsi2sd %rax, %xmm0
jmp 0x28bc4
movzwl (%rbx), %eax
cvtsi2sd %eax, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4ee44
leaq 0x3371c(%rip), %rdi     # 0x5c2fa
callq 0x191a3