// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/ffi.c
// Function: janet_ffi_write_one
static void janet_ffi_write_one(void *to, const Janet *argv, int32_t n, 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);
        JanetView els = janet_getindexed(argv, n);
        if (els.len != type.array_count) {
            janet_panicf("bad array length, expected %d, got %d", type.array_count, els.len);
        }
        char *cursor = to;
        for (int32_t i = 0; i < els.len; i++) {
            janet_ffi_write_one(cursor, els.items, i, el_type, recur - 1);
            cursor += el_size;
        }
        return;
    }
    switch (type.prim) {
        case JANET_FFI_TYPE_VOID:
            if (!janet_checktype(argv[n], JANET_NIL)) {
                janet_panicf("expected nil, got %v", argv[n]);
            }
            break;
        case JANET_FFI_TYPE_STRUCT: {
            JanetView els = janet_getindexed(argv, n);
            JanetFFIStruct *st = type.st;
            if ((uint32_t) els.len != st->field_count) {
                janet_panicf("wrong number of fields in struct, expected %d, got %d",
                             (int32_t) st->field_count, els.len);
            }
            for (int32_t i = 0; i < els.len; i++) {
                JanetFFIType tp = st->fields[i].type;
                janet_ffi_write_one((char *) to + st->fields[i].offset, els.items, i, tp, recur - 1);
            }
        }
        break;
        case JANET_FFI_TYPE_DOUBLE:
            ((double *)(to))[0] = janet_getnumber(argv, n);
            break;
        case JANET_FFI_TYPE_FLOAT:
            ((float *)(to))[0] = (float) janet_getnumber(argv, n);
            break;
        case JANET_FFI_TYPE_PTR:
            ((void **)(to))[0] = janet_ffi_getpointer(argv, n);
            break;
        case JANET_FFI_TYPE_STRING:
            ((const char **)(to))[0] = janet_getcstring(argv, n);
            break;
        case JANET_FFI_TYPE_BOOL:
            ((bool *)(to))[0] = janet_getboolean(argv, n);
            break;
        case JANET_FFI_TYPE_INT8:
            ((int8_t *)(to))[0] = janet_getinteger(argv, n);
            break;
        case JANET_FFI_TYPE_INT16:
            ((int16_t *)(to))[0] = janet_getinteger(argv, n);
            break;
        case JANET_FFI_TYPE_INT32:
            ((int32_t *)(to))[0] = janet_getinteger(argv, n);
            break;
        case JANET_FFI_TYPE_INT64:
            ((int64_t *)(to))[0] = janet_getinteger64(argv, n);
            break;
        case JANET_FFI_TYPE_UINT8:
            ((uint8_t *)(to))[0] = (uint8_t) janet_getuinteger64(argv, n);
            break;
        case JANET_FFI_TYPE_UINT16:
            ((uint16_t *)(to))[0] = (uint16_t) janet_getuinteger64(argv, n);
            break;
        case JANET_FFI_TYPE_UINT32:
            ((uint32_t *)(to))[0] = (uint32_t) janet_getuinteger64(argv, n);
            break;
        case JANET_FFI_TYPE_UINT64:
            ((uint64_t *)(to))[0] = janet_getuinteger64(argv, n);
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testl %r9d, %r9d
je 0x28d3a
movq %rdi, %r12
testq %r8, %r8
js 0x28ab1
movq %r8, %r14
shrq $0x20, %r14
movl %r8d, %eax
cmpq $0xe, %rax
movq %r8, -0x30(%rbp)
jne 0x28af8
movl %r9d, %r13d
movq %rcx, %r15
movl (%rcx), %ebx
jmp 0x28b0d
cmpl $0xe, %r8d
ja 0x28b7f
movq %rcx, %rbx
movl %r8d, %eax
leaq 0x333c0(%rip), %rcx     # 0x5be88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movslq %edx, %rax
movq (%rsi,%rax,8), %rsi
movq %rsi, %rax
shrq $0x2f, %rax
cmpl $0x1fff1, %eax          # imm = 0x1FFF1
je 0x28b7f
leaq 0x34842(%rip), %rdi     # 0x5d333
xorl %eax, %eax
callq 0x1917b
movq %rcx, %r15
movl %r9d, %r13d
shlq $0x4, %rax
leaq 0x34397(%rip), %rcx     # 0x5cea0
movq (%rax,%rcx), %rbx
movq %rsi, %rdi
movl %edx, %esi
callq 0x19d81
cmpl %r14d, %edx
jne 0x28d46
testl %edx, %edx
movq -0x30(%rbp), %r14
jle 0x28b7f
movq %r15, %rcx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
orq %rsi, %r14
decl %r13d
xorl %r15d, %r15d
movl %edx, -0x34(%rbp)
movq %rbx, -0x40(%rbp)
movq %r12, -0x30(%rbp)
movq %r12, %rdi
movq %rax, %r12
movq %rax, %rsi
movl %r15d, %edx
movq %rcx, %rbx
movq %r14, %r8
movl %r13d, %r9d
callq 0x28a71
movq %rbx, %rcx
movq -0x40(%rbp), %rbx
movq %r12, %rax
movq -0x30(%rbp), %r12
movl -0x34(%rbp), %edx
addq %rbx, %r12
incl %r15d
cmpl %r15d, %edx
jne 0x28b45
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r9d, %r13d
movq %rsi, %rdi
movl %edx, %esi
callq 0x19d81
movl 0x8(%rbx), %esi
cmpl %esi, %edx
jne 0x28d57
testl %edx, %edx
jle 0x28b7f
movq %rax, %r15
decl %r13d
movl %edx, %ecx
movq %rcx, -0x30(%rbp)
addq $0x20, %rbx
xorl %r14d, %r14d
movq -0x10(%rbx), %rcx
movq -0x8(%rbx), %r8
movq (%rbx), %rdi
addq %r12, %rdi
movq %r15, %rsi
movl %r14d, %edx
movl %r13d, %r9d
callq 0x28a71
incq %r14
addq $0x18, %rbx
cmpq %r14, -0x30(%rbp)
jne 0x28bbd
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x19c23
movl %eax, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x1940c
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x19c12
jmp 0x28cc3
movq %rsi, %rdi
movl %edx, %esi
callq 0x19c23
movw %ax, (%r12)
jmp 0x28b7f
movslq %edx, %r14
movsd (%rsi,%r14,8), %xmm0
xorl %eax, %eax
ucomisd %xmm0, %xmm0
jp 0x28d60
decl %eax
cmpl $0xe, %eax
ja 0x28d70
leaq 0x33269(%rip), %rcx     # 0x5bec4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsi,%r14,8), %rdi
callq 0x4f838
jmp 0x28cc3
movq %rsi, %rdi
movl %edx, %esi
callq 0x198dd
jmp 0x28cc3
movq %rsi, %rdi
movl %edx, %esi
callq 0x19c23
movb %al, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x195ef
testl %eax, %eax
setne (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x1940c
movsd %xmm0, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x19c23
movq %rax, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b1d
movb %al, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b1d
movl %eax, (%r12)
jmp 0x28b7f
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b1d
movw %ax, (%r12)
jmp 0x28b7f
xorl %eax, %eax
jmp 0x28cc3
movq (%rsi,%r14,8), %rdi
callq 0x4f838
movq 0x18(%rax), %rax
jmp 0x28cc3
movq %rsi, %rdi
movl %edx, %esi
callq 0x199cf
jmp 0x28cc3
movq (%rsi,%r14,8), %rdi
movq %rsi, %r15
callq 0x2b5e5
movq (%r15,%r14,8), %rdi
jmp 0x28c68
leaq 0x345b9(%rip), %rdi     # 0x5d2fa
callq 0x19263
leaq 0x345c0(%rip), %rdi     # 0x5d30d
movl %r14d, %esi
xorl %eax, %eax
callq 0x1917b
leaq 0x345ea(%rip), %rdi     # 0x5d348
jmp 0x28d50
movq (%rsi,%r14,8), %rax
shrq $0x2f, %rax
andl $0xf, %eax
jmp 0x28c49
movq (%rsi,%r14,8), %rax
leaq 0x34603(%rip), %rdi     # 0x5d37e
movl %edx, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1917b