// File: /workspace/github_c_makefile_star2_O2/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, %r13
cmpl $0x8, 0x28(%rdi)
jne 0x25e3c
movq 0x18(%r13), %rdi
movq 0x20(%r13), %rsi
callq 0x25314
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, %rsp
movq %rcx, -0xe8(%rbp)
movq %rcx, -0x80(%rbp)
jmp 0x25e4a
leaq -0xe0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl 0x10(%r13), %eax
movq %rsp, %rcx
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xf0(%rbp)
movq %rcx, %rsp
leaq 0x50(%r13), %r14
xorl %r15d, %r15d
movl 0x4(%r13), %eax
cmpq %rax, %r15
jae 0x25f83
movl -0x8(%r14), %eax
cmpq $0x8, %rax
ja 0x26187
leaq 0x2(%r15), %rdx
movq -0x18(%r14), %rcx
movq -0x10(%r14), %r8
movl -0x4(%r14), %ebx
movl (%r14), %r12d
leaq 0x30fbe(%rip), %rsi     # 0x56e64
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
leaq -0x80(,%rbx,8), %rdi
addq %rbp, %rdi
jmp 0x25f6a
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
pushq $0x40
popq %r9
callq 0x26293
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0xd0(%rbp,%rbx,8)
jmp 0x25f30
leaq -0xd0(,%rbx,8), %rdi
addq %rbp, %rdi
jmp 0x25f6a
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
pushq $0x40
popq %r9
callq 0x26293
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0xd0(%rbp,%rbx,8)
jmp 0x25f55
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
pushq $0x40
popq %r9
callq 0x26293
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0x80(%rbp,%rbx,8)
movq %rcx, -0x80(%rbp,%r12,8)
jmp 0x25f77
leaq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
pushq $0x40
popq %r9
callq 0x26293
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rax, -0x80(%rbp,%rbx,8)
movq %rcx, -0xd0(%rbp,%r12,8)
jmp 0x25f77
movq -0xf0(%rbp), %rax
leaq (%rax,%rbx,8), %rdi
movq -0x48(%rbp), %rsi
pushq $0x40
popq %r9
callq 0x26293
incq %r15
addq $0x20, %r14
jmp 0x25e71
movl 0xc(%r13), %eax
cmpq $0x3, %rax
ja 0x26161
leaq 0x30ebc(%rip), %rcx     # 0x56e54
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 0x26161
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 0x26161
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 0x26161
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(%r13), %rsi
movq 0x20(%r13), %rdx
pushq $0x40
popq %rcx
movq -0xe8(%rbp), %rdi
callq 0x26643
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3211c(%rip), %rdi     # 0x582aa
callq 0x177b1