// File: /workspace/github_c_makefile_star2_O0/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
subq $0xa0, %rsp
movq %rcx, -0x10(%rbp)
movq %r8, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x34644
leaq 0x54ceb(%rip), %rdi     # 0x8932a
callq 0x1ad60
cmpl $0x0, -0x4(%rbp)
jl 0x346f8
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x33060
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1cc50
movq %rax, -0x50(%rbp)
movl %edx, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
je 0x346a5
movl -0x4(%rbp), %esi
movl -0x48(%rbp), %edx
leaq 0x54c9f(%rip), %rdi     # 0x8933d
movb $0x0, %al
callq 0x1ac40
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x346f3
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x5c(%rbp), %edx
movl -0x28(%rbp), %r9d
subl $0x1, %r9d
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x34610
movq -0x40(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x346b4
jmp 0x349b0
movl -0x8(%rbp), %eax
movq %rax, -0x98(%rbp)
subq $0xe, %rax
ja 0x349b0
movq -0x98(%rbp), %rax
leaq 0x5378e(%rip), %rcx     # 0x87ea8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
testb $0x1, %al
jne 0x3472b
jmp 0x34761
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x34745
jmp 0x347a0
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x2f, %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x347a0
jmp 0x34786
movq -0x20(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movabsq $-0x800000000000, %rax  # imm = 0xFFFF800000000000
andq (%rcx,%rdx,8), %rax
movabsq $-0x7800000000000, %rcx # imm = 0xFFF8800000000000
cmpq %rcx, %rax
je 0x347a0
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x54bca(%rip), %rdi     # 0x89363
movb $0x0, %al
callq 0x1ac40
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1cc50
movq %rax, -0x70(%rbp)
movl %edx, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x68(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x347e4
movq -0x78(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x68(%rbp), %edx
leaq 0x54b9b(%rip), %rdi     # 0x89378
movb $0x0, %al
callq 0x1ac40
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x34863
movq -0x78(%rbp), %rax
addq $0x10, %rax
movslq -0x7c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
movq -0x78(%rbp), %rax
addq $0x10, %rax
movslq -0x7c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
addq 0x10(%rax), %rdi
movq -0x70(%rbp), %rsi
movl -0x7c(%rbp), %edx
movl -0x28(%rbp), %r9d
subl $0x1, %r9d
movq -0x90(%rbp), %rcx
movq -0x88(%rbp), %r8
callq 0x34610
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x347eb
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1b040
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1b040
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x35d50
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1b700
cmpl $0x0, %eax
setne %cl
movq -0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c7c0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c7c0
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c7c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c910
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c940
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c940
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c940
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x349b0
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x1c940
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)