// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, -0x48(%rbp)
movq %rsi, -0x88(%rbp)
movq %rdi, %r14
cmpl $0x8, 0x28(%rdi)
jne 0x280e4
movq 0x20(%r14), %rcx
movq %rcx, %rdx
sarq $0x20, %rdx
testq %rcx, %rcx
movl $0x1, %eax
cmovnsq %rdx, %rax
movl %ecx, %ecx
cmpq $0xe, %rcx
jne 0x280f4
movq 0x18(%r14), %rcx
movl (%rcx), %ecx
imulq %rcx, %rax
jmp 0x28104
leaq -0xe0(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x28120
shlq $0x4, %rcx
leaq 0x33da1(%rip), %rdx     # 0x5bea0
imulq (%rcx,%rdx), %rax
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, %rsp
movq %rcx, -0xe8(%rbp)
movq %rcx, -0x80(%rbp)
movl 0x10(%r14), %eax
movq %rsp, %rcx
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xf0(%rbp)
movq %rcx, %rsp
cmpl $0x0, 0x4(%r14)
je 0x2826c
leaq 0x50(%r14), %r15
xorl %r13d, %r13d
movl -0x8(%r15), %eax
cmpq $0x8, %rax
ja 0x28472
leaq 0x2(%r13), %rdx
movq -0x18(%r15), %rcx
movq -0x10(%r15), %r8
movl -0x4(%r15), %ebx
movl (%r15), %r12d
leaq 0x32cda(%rip), %rsi     # 0x5ae54
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
leaq -0x80(,%rbx,8), %rdi
addq %rbp, %rdi
jmp 0x28249
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x40, %r9d
callq 0x285af
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0xd0(%rbp,%rbx,8)
jmp 0x2820d
leaq -0xd0(,%rbx,8), %rdi
addq %rbp, %rdi
jmp 0x28249
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x40, %r9d
callq 0x285af
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0xd0(%rbp,%rbx,8)
jmp 0x28234
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x40, %r9d
callq 0x285af
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0x80(%rbp,%rbx,8)
movq %rcx, -0x80(%rbp,%r12,8)
jmp 0x28258
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x40, %r9d
callq 0x285af
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0x80(%rbp,%rbx,8)
movq %rcx, -0xd0(%rbp,%r12,8)
jmp 0x28258
movq -0xf0(%rbp), %rax
leaq (%rax,%rbx,8), %rdi
movq -0x48(%rbp), %rsi
movl $0x40, %r9d
callq 0x285af
incq %r13
movl 0x4(%r14), %eax
addq $0x20, %r15
cmpq %rax, %r13
jb 0x28152
movl 0xc(%r14), %eax
cmpq $0x3, %rax
ja 0x2844a
leaq 0x32bf7(%rip), %rcx     # 0x5ae78
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x58(%rbp), %r9
movsd -0xd0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm3
movsd -0xb0(%rbp), %xmm4
movsd -0xa8(%rbp), %xmm5
movsd -0xa0(%rbp), %xmm6
movsd -0x98(%rbp), %xmm7
callq *-0x88(%rbp)
movq %rax, -0xe0(%rbp)
movq %rdx, -0xd8(%rbp)
jmp 0x2844a
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x58(%rbp), %r9
movsd -0xd0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm3
movsd -0xb0(%rbp), %xmm4
movsd -0xa8(%rbp), %xmm5
movsd -0xa0(%rbp), %xmm6
movsd -0x98(%rbp), %xmm7
callq *-0x88(%rbp)
movq %rax, -0xe0(%rbp)
movsd %xmm0, -0xd8(%rbp)
jmp 0x2844a
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x58(%rbp), %r9
movsd -0xd0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm3
movsd -0xb0(%rbp), %xmm4
movsd -0xa8(%rbp), %xmm5
movsd -0xa0(%rbp), %xmm6
movsd -0x98(%rbp), %xmm7
callq *-0x88(%rbp)
movsd %xmm0, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
jmp 0x2844a
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x58(%rbp), %r9
movsd -0xd0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movsd -0xb8(%rbp), %xmm3
movsd -0xb0(%rbp), %xmm4
movsd -0xa8(%rbp), %xmm5
movsd -0xa0(%rbp), %xmm6
movsd -0x98(%rbp), %xmm7
callq *-0x88(%rbp)
movsd %xmm0, -0xe0(%rbp)
movsd %xmm1, -0xd8(%rbp)
movq 0x18(%r14), %rsi
movq 0x20(%r14), %rdx
movq -0xe8(%rbp), %rdi
movl $0x40, %ecx
callq 0x28998
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x33e31(%rip), %rdi     # 0x5c2aa
callq 0x191a3