// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/ffi.c
// Function: janet_ffi_sysv64
static Janet janet_ffi_sysv64(JanetFFISignature *signature, void *function_pointer, const Janet *argv) {
    union {
        sysv64_int_return int_return;
        sysv64_sse_return sse_return;
        sysv64_sseint_return sseint_return;
        sysv64_intsse_return intsse_return;
    } retu;
    uint64_t pair[2];
    uint64_t regs[6];
    double fp_regs[8];
    JanetFFIWordSpec ret_spec = signature->ret.spec;
    void *ret_mem = &retu.int_return;
    if (ret_spec == JANET_SYSV64_MEMORY) {
        ret_mem = alloca(type_size(signature->ret.type));
        regs[0] = (uint64_t) ret_mem;
    }
    uint64_t *stack = alloca(sizeof(uint64_t) * signature->stack_count);
    for (uint32_t i = 0; i < signature->arg_count; i++) {
        uint64_t *to;
        int32_t n = i + 2;
        JanetFFIMapping arg = signature->args[i];
        switch (arg.spec) {
            default:
                janet_panic("nyi");
            case JANET_SYSV64_INTEGER:
                to = regs + arg.offset;
                break;
            case JANET_SYSV64_SSE:
                to = (uint64_t *)(fp_regs + arg.offset);
                break;
            case JANET_SYSV64_MEMORY:
                to = stack + arg.offset;
                break;
            case JANET_SYSV64_PAIR_INTINT:
                janet_ffi_write_one(pair, argv, n, arg.type, JANET_FFI_MAX_RECUR);
                regs[arg.offset] = pair[0];
                regs[arg.offset2] = pair[1];
                continue;
            case JANET_SYSV64_PAIR_INTSSE:
                janet_ffi_write_one(pair, argv, n, arg.type, JANET_FFI_MAX_RECUR);
                regs[arg.offset] = pair[0];
                ((uint64_t *) fp_regs)[arg.offset2] = pair[1];
                continue;
            case JANET_SYSV64_PAIR_SSEINT:
                janet_ffi_write_one(pair, argv, n, arg.type, JANET_FFI_MAX_RECUR);
                ((uint64_t *) fp_regs)[arg.offset] = pair[0];
                regs[arg.offset2] = pair[1];
                continue;
            case JANET_SYSV64_PAIR_SSESSE:
                janet_ffi_write_one(pair, argv, n, arg.type, JANET_FFI_MAX_RECUR);
                ((uint64_t *) fp_regs)[arg.offset] = pair[0];
                ((uint64_t *) fp_regs)[arg.offset2] = pair[1];
                continue;
        }
        janet_ffi_write_one(to, argv, n, arg.type, JANET_FFI_MAX_RECUR);
    }

    switch (signature->variant) {
        case 0:
            retu.int_return = ((janet_sysv64_variant_1 *)(function_pointer))(
                                  regs[0], regs[1], regs[2], regs[3], regs[4], regs[5],
                                  fp_regs[0], fp_regs[1], fp_regs[2], fp_regs[3],
                                  fp_regs[4], fp_regs[5], fp_regs[6], fp_regs[7]);
            break;
        case 1:
            retu.sse_return = ((janet_sysv64_variant_2 *)(function_pointer))(
                                  regs[0], regs[1], regs[2], regs[3], regs[4], regs[5],
                                  fp_regs[0], fp_regs[1], fp_regs[2], fp_regs[3],
                                  fp_regs[4], fp_regs[5], fp_regs[6], fp_regs[7]);
            break;
        case 2:
            retu.intsse_return = ((janet_sysv64_variant_3 *)(function_pointer))(
                                     regs[0], regs[1], regs[2], regs[3], regs[4], regs[5],
                                     fp_regs[0], fp_regs[1], fp_regs[2], fp_regs[3],
                                     fp_regs[4], fp_regs[5], fp_regs[6], fp_regs[7]);
            break;
        case 3:
            retu.sseint_return = ((janet_sysv64_variant_4 *)(function_pointer))(
                                     regs[0], regs[1], regs[2], regs[3], regs[4], regs[5],
                                     fp_regs[0], fp_regs[1], fp_regs[2], fp_regs[3],
                                     fp_regs[4], fp_regs[5], fp_regs[6], fp_regs[7]);
            break;
    }

    return janet_ffi_read_one(ret_mem, signature->ret.type, JANET_FFI_MAX_RECUR);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0xb4(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpl $0x8, -0xb4(%rbp)
jne 0x33fef
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x20(%rax), %rsi
callq 0x33060
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x34263
movl -0xcc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xdc(%rbp)
movq -0x10(%rbp), %rax
movl -0xcc(%rbp), %ecx
shlq $0x5, %rcx
movups 0x38(%rax,%rcx), %xmm0
movups 0x48(%rax,%rcx), %xmm1
movaps %xmm1, -0xf0(%rbp)
movaps %xmm0, -0x100(%rbp)
movl -0xf0(%rbp), %eax
movq %rax, -0x148(%rbp)
subq $0x8, %rax
ja 0x3408e
movq -0x148(%rbp), %rax
leaq 0x53dff(%rip), %rcx     # 0x87e84
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x55245(%rip), %rdi     # 0x892da
callq 0x1ad60
leaq -0x70(%rbp), %rax
movl -0xec(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
jmp 0x34225
leaq -0xb0(%rbp), %rax
movl -0xec(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
jmp 0x34225
movq -0xc8(%rbp), %rax
movl -0xec(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
jmp 0x34225
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xdc(%rbp), %edx
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %r8
movl $0x40, %r9d
callq 0x34610
movq -0x40(%rbp), %rcx
movl -0xec(%rbp), %eax
movq %rcx, -0x70(%rbp,%rax,8)
movq -0x38(%rbp), %rcx
movl -0xe8(%rbp), %eax
movq %rcx, -0x70(%rbp,%rax,8)
jmp 0x3424f
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xdc(%rbp), %edx
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %r8
movl $0x40, %r9d
callq 0x34610
movq -0x40(%rbp), %rcx
movl -0xec(%rbp), %eax
movq %rcx, -0x70(%rbp,%rax,8)
movq -0x38(%rbp), %rcx
movl -0xe8(%rbp), %eax
movq %rcx, -0xb0(%rbp,%rax,8)
jmp 0x3424f
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xdc(%rbp), %edx
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %r8
movl $0x40, %r9d
callq 0x34610
movq -0x40(%rbp), %rcx
movl -0xec(%rbp), %eax
movq %rcx, -0xb0(%rbp,%rax,8)
movq -0x38(%rbp), %rcx
movl -0xe8(%rbp), %eax
movq %rcx, -0x70(%rbp,%rax,8)
jmp 0x3424f
leaq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xdc(%rbp), %edx
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %r8
movl $0x40, %r9d
callq 0x34610
movq -0x40(%rbp), %rcx
movl -0xec(%rbp), %eax
movq %rcx, -0xb0(%rbp,%rax,8)
movq -0x38(%rbp), %rcx
movl -0xe8(%rbp), %eax
movq %rcx, -0xb0(%rbp,%rax,8)
jmp 0x3424f
movq -0xd8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0xdc(%rbp), %edx
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %r8
movl $0x40, %r9d
callq 0x34610
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x3401c
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x150(%rbp)
subq $0x3, %rax
ja 0x34492
movq -0x150(%rbp), %rax
leaq 0x53beb(%rip), %rcx     # 0x87e74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x48(%rbp), %r9
movsd -0xb0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm3
movsd -0x90(%rbp), %xmm4
movsd -0x88(%rbp), %xmm5
movsd -0x80(%rbp), %xmm6
movsd -0x78(%rbp), %xmm7
callq *%rax
movq %rax, -0x110(%rbp)
movq %rdx, -0x108(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x34492
movq -0x18(%rbp), %rax
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x48(%rbp), %r9
movsd -0xb0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm3
movsd -0x90(%rbp), %xmm4
movsd -0x88(%rbp), %xmm5
movsd -0x80(%rbp), %xmm6
movsd -0x78(%rbp), %xmm7
callq *%rax
movsd %xmm0, -0x120(%rbp)
movsd %xmm1, -0x118(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x34492
movq -0x18(%rbp), %rax
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x48(%rbp), %r9
movsd -0xb0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm3
movsd -0x90(%rbp), %xmm4
movsd -0x88(%rbp), %xmm5
movsd -0x80(%rbp), %xmm6
movsd -0x78(%rbp), %xmm7
callq *%rax
movq %rax, -0x130(%rbp)
movsd %xmm0, -0x128(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x34492
movq -0x18(%rbp), %rax
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x48(%rbp), %r9
movsd -0xb0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm3
movsd -0x90(%rbp), %xmm4
movsd -0x88(%rbp), %xmm5
movsd -0x80(%rbp), %xmm6
movsd -0x78(%rbp), %xmm7
callq *%rax
movsd %xmm0, -0x140(%rbp)
movq %rax, -0x138(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0xc0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq 0x20(%rax), %rdx
movl $0x40, %ecx
callq 0x34b10
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)