// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x38(%rbp), %rax
leaq 0x10(%rbp), %r13
movq (%r13), %r14
movl 0x10(%rax), %r12d
btl $0x10, %r12d
movq %r14, -0x30(%rbp)
jb 0x1d648
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1d251
jmp 0x1d8ba
leaq 0x10(%rbx), %rcx
movq $-0x1, %rax
testq %rbx, %rbx
je 0x1d65e
movslq -0x4(%rbx), %rdx
jmp 0x1d660
xorl %edx, %edx
incq %rax
cmpq %rdx, %rax
jge 0x1d677
testb $0x1, 0x3(%rcx)
leaq 0x18(%rcx), %rcx
je 0x1d653
jmp 0x1d71d
leaq 0x38(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rax
shrq $0x2f, %rax
cmpl $0x1fffc, %eax          # imm = 0x1FFFC
jne 0x1d71d
callq 0x4ebc4
movq 0x10(%rax), %rax
movl 0x58(%rax), %edi
callq 0x1a1a4
testq %rax, %rax
je 0x1d71d
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
je 0x1d6de
movq %rcx, -0x38(%rbp)
movq 0x20(%r13), %rcx
movq %rcx, 0x20(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq *%rax
movq -0x38(%rbp), %rcx
testl %eax, %eax
je 0x1d71d
movq 0x20(%r13), %rax
movq %rax, 0x20(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq *0x8(%rcx)
movq 0x10(%r13), %rax
movq %rax, 0x10(%r15)
movups (%r13), %xmm0
movups %xmm0, (%r15)
jmp 0x1d9c2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1d251
btl $0x10, %r12d
jae 0x1d8ba
movl %eax, %edx
leaq 0x38(%rbp), %rax
movq (%rax), %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 0x1d824
cmpl $0x1, %eax
je 0x1d8ba
cmpl $0x6, %eax
je 0x1d848
cmpl $0xc, %eax
jne 0x1d830
movq %rsi, %r14
movq %rsi, %rdi
movl %edx, %r12d
callq 0x4ebc4
movl %r12d, %r8d
movq 0x10(%rax), %rax
movl 0x68(%rax), %edx
testl %r12d, %r12d
js 0x1d873
movl 0x64(%rax), %r9d
leaq 0x4e938(%rip), %rdi     # 0x6c0dd
leaq 0x4a867(%rip), %r10     # 0x68013
cmpl %r8d, %edx
jae 0x1d801
cmpl $0x1, %edx
cmoveq %rdi, %r10
leaq 0x36fb5(%rip), %rdi     # 0x54774
movq %r14, %rsi
movq %r10, %rcx
movl %r12d, %r8d
xorl %eax, %eax
movl %r9d, -0x38(%rbp)
callq 0x3f652
leaq 0x4e903(%rip), %rdi     # 0x6c0dd
leaq 0x4a832(%rip), %r10     # 0x68013
movl -0x38(%rbp), %r9d
movl %r12d, %r8d
movq -0x30(%rbp), %rcx
cmpl $0x1, 0x48(%rcx)
je 0x1d801
movq -0x30(%rbp), %rcx
movl $0x1, 0x48(%rcx)
movq %rax, 0x30(%rcx)
cmpl %r9d, %r8d
jge 0x1d8ba
cmpl $0x1, %r9d
cmoveq %rdi, %r10
leaq 0x36f84(%rip), %rdi     # 0x5479d
movq %r14, %rsi
movl %r9d, %edx
movq %r10, %rcx
jmp 0x1d89a
addl $-0xd, %eax
cmpl $0x2, %eax
jb 0x1d8ba
cmpl $0x2, %edx
setl %al
testl %edx, %edx
setne %cl
testb %cl, %al
jne 0x1d85c
leaq 0x36fa7(%rip), %rdi     # 0x547ed
jmp 0x1d86a
testl %edx, %edx
jne 0x1d8ba
leaq 0x36f74(%rip), %rdi     # 0x547c7
xorl %eax, %eax
callq 0x3f652
jmp 0x1d8a1
cmpl $-0x3, %edx
jg 0x1d8ba
notl %edx
leaq 0x36fa1(%rip), %rdi     # 0x5480b
xorl %eax, %eax
callq 0x3f652
jmp 0x1d8a1
notl %r8d
cmpl %r8d, %edx
jae 0x1d8ba
cmpl $0x1, %edx
leaq 0x4e858(%rip), %rax     # 0x6c0dd
leaq 0x4a787(%rip), %rcx     # 0x68013
cmoveq %rax, %rcx
leaq 0x36eab(%rip), %rdi     # 0x54742
movq %r14, %rsi
xorl %eax, %eax
callq 0x3f652
movq -0x30(%rbp), %rcx
cmpl $0x1, 0x48(%rcx)
je 0x1d8ba
movq -0x30(%rbp), %rcx
movl $0x1, 0x48(%rcx)
movq %rax, 0x30(%rcx)
movl 0x20(%r13), %edx
btl $0x10, %edx
jae 0x1d91f
movq -0x30(%rbp), %rax
movq (%rax), %rax
testb $0x4, 0x6c(%rax)
jne 0x1d91f
leaq 0x38(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
movq -0x30(%rbp), %r14
movq %r14, %rdi
movl $0x36, %esi
xorl %edx, %edx
callq 0x21ae6
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %rax, (%r15)
movq $-0x1, 0x8(%r15)
movl $0x100000, 0x10(%r15)   # imm = 0x100000
jmp 0x1d9c2
movl 0x10(%r13), %eax
movl 0x14(%r13), %ecx
movl 0x1c(%r13), %r14d
shrl $0x11, %edx
testl %ecx, %ecx
sets %sil
andb %dl, %sil
cmpl $0x100, %eax            # imm = 0x100
setb %dl
testb %dl, %sil
je 0x1d94e
movq 0x8(%r13), %r12
movl 0x18(%r13), %edx
jmp 0x1d973
movq (%r13), %r13
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %rax, %r12
movq %r13, %rdi
callq 0x216e0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
movq %r12, (%r15)
movl %eax, 0x8(%r15)
movl %ecx, 0xc(%r15)
movl %edx, 0x10(%r15)
movl %r14d, 0x14(%r15)
leaq 0x38(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x28(%rsp)
movups (%rcx), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq -0x30(%rbp), %r14
movq %r14, %rdi
movl $0x35, %esi
movl $0x1, %edx
callq 0x21da8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1d496
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq