// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rsi, -0x38(%rbp)
movl %ecx, -0x2c(%rbp)
testl %ecx, %ecx
je 0x2684f
movq %rdi, %rbx
testq %rdx, %rdx
js 0x266e4
movq %rdx, %r12
shrq $0x20, %r12
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
orq %rdx, %r13
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x25314
movq %rax, %r15
movl %r12d, %edi
callq 0x12f68
movq %rax, %r14
decl -0x2c(%rbp)
subl $0x1, %r12d
jb 0x266c4
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
movl -0x2c(%rbp), %ecx
callq 0x26643
movq %r14, %rdi
movq %rax, %rsi
callq 0x131d2
addq %r15, %rbx
jmp 0x2669c
movabsq $-0x4800000000000, %rsi # imm = 0xFFFB800000000000
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b3ab
decl %edx
cmpl $0xd, %edx
ja 0x26791
leaq 0x3080a(%rip), %rax     # 0x56f00
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movzbl (%rbx), %eax
movabsq $-0x7000000000000, %rdi # imm = 0xFFF9000000000000
orq %rax, %rdi
jmp 0x2679b
movq (%rbx), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29e70
movsd (%rbx), %xmm0
jmp 0x2683c
movq (%rbx), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29ea3
cvtsi2sdl (%rbx), %xmm0
jmp 0x2683c
movq (%rbx), %rdi
callq 0x411ea
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
jmp 0x26811
cvtss2sd (%rbx), %xmm0
jmp 0x2683c
movswl (%rbx), %eax
jmp 0x26838
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x26791
movabsq $-0x800000000000, %rsi  # imm = 0xFFFF800000000000
jmp 0x266d1
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b313
movsbl (%rbx), %eax
jmp 0x26838
movq -0x38(%rbp), %r14
movl 0x8(%r14), %edi
callq 0x44648
movq %rax, %r12
decl -0x2c(%rbp)
addq $0x20, %r14
xorl %r15d, %r15d
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
cmpq %rax, %r15
jae 0x267ff
movq -0x10(%r14), %rsi
movq -0x8(%r14), %rdx
movq (%r14), %rdi
addq %rbx, %rdi
movl -0x2c(%rbp), %ecx
callq 0x26643
movq %rax, (%r12,%r15,8)
incq %r15
addq $0x18, %r14
jmp 0x267d0
movq %r12, %rdi
callq 0x44674
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b366
movzbl (%rbx), %eax
jmp 0x26838
movl (%rbx), %eax
cvtsi2sd %rax, %xmm0
jmp 0x2683c
movzwl (%rbx), %eax
cvtsi2sd %eax, %xmm0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4b471
leaq 0x31aa4(%rip), %rdi     # 0x582fa
callq 0x177b1