// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdi, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
testl %r9d, %r9d
je 0x26550
movl %edx, %r15d
movq %rsi, %r12
testq %r8, %r8
js 0x26336
movq %r8, %rbx
shrq $0x20, %rbx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
orq %r8, %rsi
movq %rcx, -0x48(%rbp)
movq %rcx, %rdi
movq %rsi, -0x40(%rbp)
callq 0x25314
movq %rax, %r14
movq %r12, %rdi
movl %r15d, %esi
callq 0x18254
movq %rbx, %r13
cmpl %ebx, %edx
jne 0x2655c
movq %rax, %r15
decl -0x34(%rbp)
xorl %ebx, %ebx
cmpl %ebx, %r13d
je 0x26511
movq -0x30(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl -0x34(%rbp), %r9d
callq 0x26293
addq %r14, %r12
movq %r12, -0x30(%rbp)
incl %ebx
jmp 0x26305
cmpl $0xe, %r8d
ja 0x26511
movq %rcx, %rbx
movl %r8d, %eax
leaq 0x30b3b(%rip), %rcx     # 0x56e88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movslq %r15d, %rax
movq (%r12,%rax,8), %rsi
movq %rsi, %rax
shrq $0x2f, %rax
cmpl $0x1fff1, %eax          # imm = 0x1FFF1
je 0x26511
leaq 0x31fbd(%rip), %rdi     # 0x58333
xorl %eax, %eax
callq 0x176c9
movq %r12, %rdi
movl %r15d, %esi
callq 0x18254
movl %edx, %r12d
movl 0x8(%rbx), %esi
cmpl %esi, %edx
jne 0x2657e
movq %rax, %r13
decl -0x34(%rbp)
xorl %r14d, %r14d
testl %r12d, %r12d
cmovlel %r14d, %r12d
addq $0x20, %rbx
cmpq %r14, %r12
je 0x26511
movq -0x10(%rbx), %rcx
movq -0x8(%rbx), %r8
movq (%rbx), %rdi
addq -0x30(%rbp), %rdi
movq %r13, %rsi
movl %r14d, %edx
movl -0x34(%rbp), %r9d
callq 0x26293
incq %r14
addq $0x18, %rbx
jmp 0x263aa
movq %r12, %rdi
movl %r15d, %esi
callq 0x180f6
movq -0x30(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x17937
cvtsd2ss %xmm0, %xmm0
movq -0x30(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x180e5
jmp 0x264d0
movq %r12, %rdi
movl %r15d, %esi
callq 0x180f6
movq -0x30(%rbp), %rcx
movw %ax, (%rcx)
jmp 0x26511
movslq %r15d, %rbx
movsd (%r12,%rbx,8), %xmm0
ucomisd %xmm0, %xmm0
movq %xmm0, %rdx
jnp 0x2656d
movq %rdx, %rax
shrq $0x2f, %rax
andl $0xf, %eax
decl %eax
cmpl $0xe, %eax
ja 0x2656d
leaq 0x30a5d(%rip), %rcx     # 0x56ec4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rdx, %rdi
callq 0x4b1f1
jmp 0x264d0
movq %r12, %rdi
movl %r15d, %esi
callq 0x17dae
jmp 0x264d0
movq %r12, %rdi
movl %r15d, %esi
callq 0x180f6
movq -0x30(%rbp), %rcx
movb %al, (%rcx)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x17b10
testl %eax, %eax
movq -0x30(%rbp), %rax
setne (%rax)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x17937
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x180f6
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x17ff0
movq -0x30(%rbp), %rcx
movb %al, (%rcx)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x17ff0
movq -0x30(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x26511
movq %r12, %rdi
movl %r15d, %esi
callq 0x17ff0
movq -0x30(%rbp), %rcx
movw %ax, (%rcx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x264d0
movq %rdx, %rdi
callq 0x4b1f1
movq 0x18(%rax), %rax
jmp 0x264d0
movq %r12, %rdi
movl %r15d, %esi
callq 0x17ea2
jmp 0x264d0
movq %rdx, %rdi
callq 0x28c2a
movq (%r12,%rbx,8), %rdi
jmp 0x26473
leaq 0x31da3(%rip), %rdi     # 0x582fa
callq 0x177b1
leaq 0x31daa(%rip), %rdi     # 0x5830d
movl %r13d, %esi
xorl %eax, %eax
callq 0x176c9
leaq 0x31e0a(%rip), %rdi     # 0x5837e
movl %r15d, %esi
xorl %eax, %eax
callq 0x176c9
leaq 0x31dc3(%rip), %rdi     # 0x58348
movl %r12d, %edx
jmp 0x26566