// File: /workspace/github_c_makefile_star2_O3/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 0x2887c
movq %rdi, %rbx
testq %r8, %r8
js 0x285f0
movq %r8, %r15
shrq $0x20, %r15
movl %r8d, %eax
cmpq $0xe, %rax
movq %r8, -0x30(%rbp)
jne 0x28637
movl %r9d, %r13d
movq %rcx, %r14
movl (%rcx), %r12d
jmp 0x2864c
cmpl $0xe, %r8d
ja 0x286c5
movq %rcx, %r12
movl %r8d, %eax
leaq 0x32881(%rip), %rcx     # 0x5ae88
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 0x286c5
leaq 0x33d03(%rip), %rdi     # 0x5c333
xorl %eax, %eax
callq 0x190bb
movq %rcx, %r14
movl %r9d, %r13d
shlq $0x4, %rax
leaq 0x33858(%rip), %rcx     # 0x5bea0
movq (%rax,%rcx), %r12
movq %rsi, %rdi
movl %edx, %esi
callq 0x19cbb
movq %r15, %rsi
cmpl %esi, %edx
jne 0x28888
testl %esi, %esi
movq %r14, %rcx
movq -0x30(%rbp), %r14
jle 0x286c5
movq %rax, %r8
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
orq %rax, %r14
decl %r13d
xorl %r15d, %r15d
movq %rsi, -0x40(%rbp)
movq %r8, -0x38(%rbp)
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
movq %r8, %rsi
movl %r15d, %edx
movq %r12, %rbx
movq %rcx, %r12
movq %r14, %r8
movl %r13d, %r9d
callq 0x285af
movq %r12, %rcx
movq %rbx, %r12
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %rbx
movq -0x40(%rbp), %rsi
addq %r12, %rbx
incl %r15d
cmpl %r15d, %esi
jne 0x2868a
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 0x19cbb
movl 0x8(%r12), %esi
cmpl %esi, %edx
jne 0x288a9
testl %edx, %edx
jle 0x286c5
movq %rax, %r15
decl %r13d
movl %edx, %ecx
movq %rcx, -0x30(%rbp)
addq $0x20, %r12
xorl %r14d, %r14d
movq -0x10(%r12), %rcx
movq -0x8(%r12), %r8
movq (%r12), %rdi
addq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
movl %r13d, %r9d
callq 0x285af
incq %r14
addq $0x18, %r12
cmpq %r14, -0x30(%rbp)
jne 0x28705
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b5d
movl %eax, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19346
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b4c
jmp 0x2880e
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b5d
movw %ax, (%rbx)
jmp 0x286c5
movslq %edx, %r14
movsd (%rsi,%r14,8), %xmm0
ucomisd %xmm0, %xmm0
movq %xmm0, %rax
jnp 0x28896
movq %rax, %rcx
shrq $0x2f, %rcx
andl $0xf, %ecx
decl %ecx
cmpl $0xe, %ecx
ja 0x28896
leaq 0x32717(%rip), %rdi     # 0x5aec4
movslq (%rdi,%rcx,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
movq %rax, %rdi
callq 0x4ebc4
jmp 0x2880e
movq %rsi, %rdi
movl %edx, %esi
callq 0x19817
jmp 0x2880e
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b5d
movb %al, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19529
testl %eax, %eax
setne (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19346
movsd %xmm0, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19b5d
movq %rax, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19a57
movb %al, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19a57
movl %eax, (%rbx)
jmp 0x286c5
movq %rsi, %rdi
movl %edx, %esi
callq 0x19a57
movw %ax, (%rbx)
jmp 0x286c5
xorl %eax, %eax
jmp 0x2880e
movq %rax, %rdi
callq 0x4ebc4
movq 0x18(%rax), %rax
jmp 0x2880e
movq %rsi, %rdi
movl %edx, %esi
callq 0x19909
jmp 0x2880e
movq %rax, %rdi
movq %rsi, %r15
callq 0x2b13a
movq (%r15,%r14,8), %rdi
jmp 0x287b9
leaq 0x33a77(%rip), %rdi     # 0x5c2fa
callq 0x191a3
leaq 0x33a7e(%rip), %rdi     # 0x5c30d
xorl %eax, %eax
callq 0x190bb
leaq 0x33ae1(%rip), %rdi     # 0x5c37e
movl %edx, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x190bb
leaq 0x33a98(%rip), %rdi     # 0x5c348
jmp 0x2888f