// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/compile.c
// Function: janetc_call
static JanetSlot janetc_call(JanetFopts opts, JanetSlot *slots, JanetSlot fun) {
    JanetSlot retslot;
    JanetCompiler *c = opts.compiler;
    int specialized = 0;
    if (fun.flags & JANET_SLOT_CONSTANT && !has_spliced(slots)) {
        if (janet_checktype(fun.constant, JANET_FUNCTION)) {
            JanetFunction *f = janet_unwrap_function(fun.constant);
            const JanetFunOptimizer *o = janetc_funopt(f->def->flags);
            if (o && (!o->can_optimize || o->can_optimize(opts, slots))) {
                specialized = 1;
                retslot = o->optimize(opts, slots);
            }
        }
        /* TODO janet function inlining (no c functions)*/
    }
    if (!specialized) {
        int32_t min_arity = janetc_pushslots(c, slots);
        /* Check for provably incorrect function calls */
        if (fun.flags & JANET_SLOT_CONSTANT) {

            /* Check for bad arity type if fun is a constant */
            switch (janet_type(fun.constant)) {
                case JANET_FUNCTION: {
                    JanetFunction *f = janet_unwrap_function(fun.constant);
                    int32_t min = f->def->min_arity;
                    int32_t max = f->def->max_arity;
                    if (min_arity < 0) {
                        /* Call has splices */
                        min_arity = -1 - min_arity;
                        if (min_arity > max && max >= 0) {
                            const uint8_t *es = janet_formatc(
                                                    "%v expects at most %d argument%s, got at least %d",
                                                    fun.constant, max, max == 1 ? "" : "s", min_arity);
                            janetc_error(c, es);
                        }
                    } else {
                        /* Call has no splices */
                        if (min_arity > max && max >= 0) {
                            const uint8_t *es = janet_formatc(
                                                    "%v expects at most %d argument%s, got %d",
                                                    fun.constant, max, max == 1 ? "" : "s", min_arity);
                            janetc_error(c, es);
                        }
                        if (min_arity < min) {
                            const uint8_t *es = janet_formatc(
                                                    "%v expects at least %d argument%s, got %d",
                                                    fun.constant, min, min == 1 ? "" : "s", min_arity);
                            janetc_error(c, es);
                        }
                    }
                }
                break;
                case JANET_CFUNCTION:
                case JANET_ABSTRACT:
                case JANET_NIL:
                    break;
                case JANET_KEYWORD:
                    if (min_arity == 0) {
                        const uint8_t *es = janet_formatc("%v expects at least 1 argument, got 0",
                                                          fun.constant);
                        janetc_error(c, es);
                    }
                    break;
                default:
                    if (min_arity > 1 || min_arity == 0) {
                        const uint8_t *es = janet_formatc("%v expects 1 argument, got %d",
                                                          fun.constant, min_arity);
                        janetc_error(c, es);
                    }
                    if (min_arity < -2) {
                        const uint8_t *es = janet_formatc("%v expects 1 argument, got at least %d",
                                                          fun.constant, -1 - min_arity);
                        janetc_error(c, es);
                    }
                    break;
            }
        }

        if ((opts.flags & JANET_FOPTS_TAIL) &&
                /* Prevent top level tail calls for better errors */
                !(c->scope->flags & JANET_SCOPE_TOP)) {
            janetc_emit_s(c, JOP_TAILCALL, fun, 0);
            retslot = janetc_cslot(janet_wrap_nil());
            retslot.flags = JANET_SLOT_RETURNED;
        } else {
            retslot = janetc_gettarget(opts);
            janetc_emit_ss(c, JOP_CALL, retslot, fun, 1);
        }
    }
    janetc_freeslots(c, slots);
    return retslot;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x38(%rbp), %rsi
leaq 0x10(%rbp), %r13
movq (%r13), %r15
testb $0x1, 0x12(%rsi)
je 0x1d97d
leaq 0x10(%r14), %rcx
movq $-0x1, %rax
testq %r14, %r14
je 0x1d8db
movslq -0x4(%r14), %rdx
jmp 0x1d8dd
xorl %edx, %edx
incq %rax
cmpq %rdx, %rax
jge 0x1d8f8
testb $0x1, 0x3(%rcx)
leaq 0x18(%rcx), %rcx
je 0x1d8d0
cmpq %rdx, %rax
jl 0x1d97d
movq (%rsi), %rdi
movq %rdi, %rax
shrq $0x2f, %rax
cmpl $0x1fffc, %eax          # imm = 0x1FFFC
jne 0x1d97d
callq 0x4f838
movq 0x10(%rax), %rax
movl 0x58(%rax), %edi
callq 0x1a298
testq %rax, %rax
je 0x1d97d
movq %rax, %r12
movq (%rax), %rax
testq %rax, %rax
je 0x1d951
movq 0x20(%r13), %rcx
movq %rcx, 0x20(%rsp)
movupd (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r14, %rdi
callq *%rax
testl %eax, %eax
je 0x1d97d
movq 0x20(%r13), %rax
movq %rax, 0x20(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%r12)
jmp 0x1dc37
movq %r15, %rdi
movq %r14, %rsi
callq 0x1d49c
leaq 0x38(%rbp), %rdi
testb $0x1, 0x12(%rdi)
je 0x1db3c
movl %eax, %r12d
movq (%rdi), %xmm0
movq %xmm0, %rsi
movq %rsi, %rcx
shrq $0x2f, %rcx
andl $0xf, %ecx
xorl %eax, %eax
ucomisd %xmm0, %xmm0
cmovpl %ecx, %eax
cmpl $0xc, %eax
jg 0x1da77
cmpl $0x1, %eax
je 0x1db3c
cmpl $0x6, %eax
je 0x1dadb
cmpl $0xc, %eax
jne 0x1da83
movq %rsi, %rdi
callq 0x4f838
movq 0x10(%rax), %rax
movl 0x68(%rax), %edx
testl %r12d, %r12d
js 0x1daf0
movl 0x64(%rax), %r8d
cmpl %r12d, %edx
jae 0x1da42
cmpl $0x1, %edx
leaq 0x4f6f9(%rip), %rax     # 0x6d0fd
leaq 0x4b628(%rip), %rcx     # 0x69033
cmoveq %rax, %rcx
leaq 0x38(%rbp), %rax
movq (%rax), %rsi
leaq 0x37d57(%rip), %rdi     # 0x55774
movl %r8d, -0x30(%rbp)
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3fd86
movl -0x30(%rbp), %r8d
cmpl $0x1, 0x48(%r15)
je 0x1da42
movl $0x1, 0x48(%r15)
movq %rax, 0x30(%r15)
cmpl %r8d, %r12d
leaq 0x38(%rbp), %rdi
jge 0x1db3c
cmpl $0x1, %r8d
leaq 0x4f6a3(%rip), %rax     # 0x6d0fd
leaq 0x4b5d2(%rip), %rcx     # 0x69033
cmoveq %rax, %rcx
movq (%rdi), %rsi
leaq 0x37d2e(%rip), %rdi     # 0x5579d
movl %r8d, %edx
jmp 0x1db1b
addl $-0xd, %eax
cmpl $0x2, %eax
jb 0x1db3c
cmpl $0x2, %r12d
setl %al
testl %r12d, %r12d
setne %cl
testb %cl, %al
jne 0x1dabc
leaq 0x37d52(%rip), %rdi     # 0x557ed
movl %r12d, %edx
xorl %eax, %eax
callq 0x3fd86
leaq 0x38(%rbp), %rdi
cmpl $0x1, 0x48(%r15)
je 0x1dabc
movl $0x1, 0x48(%r15)
movq %rax, 0x30(%r15)
cmpl $-0x3, %r12d
jg 0x1db3c
notl %r12d
movq (%rdi), %rsi
leaq 0x37d3c(%rip), %rdi     # 0x5580b
movl %r12d, %edx
xorl %eax, %eax
callq 0x3fd86
jmp 0x1db25
testl %r12d, %r12d
jne 0x1db3c
leaq 0x37ce0(%rip), %rdi     # 0x557c7
xorl %eax, %eax
callq 0x3fd86
jmp 0x1db25
notl %r12d
cmpl %r12d, %edx
leaq 0x38(%rbp), %rdi
jae 0x1db3c
cmpl $0x1, %edx
leaq 0x4f5f7(%rip), %rax     # 0x6d0fd
leaq 0x4b526(%rip), %rcx     # 0x69033
cmoveq %rax, %rcx
movq (%rdi), %rsi
leaq 0x37c27(%rip), %rdi     # 0x55742
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3fd86
leaq 0x38(%rbp), %rdi
cmpl $0x1, 0x48(%r15)
je 0x1db3c
movl $0x1, 0x48(%r15)
movq %rax, 0x30(%r15)
movl 0x20(%r13), %edx
btl $0x10, %edx
jae 0x1db94
movq (%r15), %rax
testb $0x4, 0x6c(%rax)
jne 0x1db94
movq 0x10(%rdi), %rax
movq %rax, 0x10(%rsp)
movups (%rdi), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movl $0x36, %esi
xorl %edx, %edx
callq 0x21e42
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rax, (%rbx)
movq $-0x1, 0x8(%rbx)
movl $0x100000, 0x10(%rbx)   # imm = 0x100000
jmp 0x1dc37
movq %r15, -0x30(%rbp)
movl 0x10(%r13), %eax
movl 0x14(%r13), %ecx
movl 0x1c(%r13), %r15d
shrl $0x11, %edx
testl %ecx, %ecx
sets %sil
andb %dl, %sil
cmpl $0x100, %eax            # imm = 0x100
setb %dl
testb %dl, %sil
je 0x1dbc7
movq 0x8(%r13), %r12
movl 0x18(%r13), %edx
jmp 0x1dbf0
movq (%r13), %r13
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rax, %r12
movq %r13, %rdi
callq 0x21a40
leaq 0x38(%rbp), %rdi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
movq %r12, (%rbx)
movl %eax, 0x8(%rbx)
movl %ecx, 0xc(%rbx)
movl %edx, 0x10(%rbx)
movl %r15d, 0x14(%rbx)
movq 0x10(%rdi), %rax
movq %rax, 0x28(%rsp)
movups (%rdi), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
movq -0x30(%rbp), %r15
movq %r15, %rdi
movl $0x35, %esi
movl $0x1, %edx
callq 0x22104
movq %r15, %rdi
movq %r14, %rsi
callq 0x1d6f5
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq