// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/vm.c
// Function: janet_call
Janet janet_call(JanetFunction *fun, int32_t argc, const Janet *argv) {
    /* Check entry conditions */
    if (!janet_vm.fiber)
        janet_panic("janet_call failed because there is no current fiber");
    if (janet_vm.stackn >= JANET_RECURSION_GUARD)
        janet_panic("C stack recursed too deeply");

    /* Dirty stack */
    int32_t dirty_stack = janet_vm.fiber->stacktop - janet_vm.fiber->stackstart;
    if (dirty_stack) {
        janet_fiber_cframe(janet_vm.fiber, void_cfunction);
    }

    /* Tracing */
    if (fun->gc.flags & JANET_FUNCFLAG_TRACE) {
        janet_vm.stackn++;
        vm_do_trace(fun, argc, argv);
        janet_vm.stackn--;
    }

    /* Push frame */
    janet_fiber_pushn(janet_vm.fiber, argv, argc);
    if (janet_fiber_funcframe(janet_vm.fiber, fun)) {
        int32_t min = fun->def->min_arity;
        int32_t max = fun->def->max_arity;
        Janet funv = janet_wrap_function(fun);
        if (min == max && min != argc)
            janet_panicf("arity mismatch in %v, expected %d, got %d", funv, min, argc);
        if (min >= 0 && argc < min)
            janet_panicf("arity mismatch in %v, expected at least %d, got %d", funv, min, argc);
        janet_panicf("arity mismatch in %v, expected at most %d, got %d", funv, max, argc);
    }
    janet_fiber_frame(janet_vm.fiber)->flags |= JANET_STACKFRAME_ENTRANCE;

    /* Set up */
    int32_t oldn = janet_vm.stackn++;
    int handle = janet_gclock();

    /* Run vm */
    janet_vm.fiber->flags |= JANET_FIBER_RESUME_NO_USEVAL | JANET_FIBER_RESUME_NO_SKIP;
    int old_coerce_error = janet_vm.coerce_error;
    janet_vm.coerce_error = 1;
    JanetSignal signal = run_vm(janet_vm.fiber, janet_wrap_nil());
    janet_vm.coerce_error = old_coerce_error;

    /* Teardown */
    janet_vm.stackn = oldn;
    janet_gcunlock(handle);
    if (dirty_stack) {
        janet_fiber_popframe(janet_vm.fiber);
        janet_vm.fiber->stacktop += dirty_stack;
    }

    if (signal != JANET_SIGNAL_OK) {
        /* Should match logic in janet_signalv */
#ifdef JANET_EV
        if (janet_vm.root_fiber != NULL && signal == JANET_SIGNAL_EVENT) {
            janet_vm.root_fiber->sched_id++;
        }
#endif
        if (signal != JANET_SIGNAL_ERROR) {
            *janet_vm.return_reg = janet_wrap_string(janet_formatc("%v coerced from %s to error", *janet_vm.return_reg, janet_signal_names[signal]));
        }
        janet_panicv(*janet_vm.return_reg);
    }

    return *janet_vm.return_reg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
movl %esi, %r14d
movq %rdi, %r15
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
je 0x4b84d
movq %rax, %rbx
cmpl $0x400, 0x18(%rax)      # imm = 0x400
jge 0x4b859
movl 0x18(%rdi), %ecx
movl 0x1c(%rdi), %eax
movl %eax, -0x30(%rbp)
movl %ecx, -0x34(%rbp)
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
je 0x4b770
leaq 0x1cb(%rip), %rsi       # 0x4b936
callq 0x29d12
testb $0x1, 0x2(%r15)
je 0x4b78b
incl 0x18(%rbx)
movq %r15, %rdi
movl %r14d, %esi
movq %r12, %rdx
callq 0x4b946
decl 0x18(%rbx)
movq 0x20(%rbx), %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x297d7
movq 0x20(%rbx), %rdi
movq %r15, %rsi
callq 0x29466
testl %eax, %eax
jne 0x4b865
movq 0x20(%rbx), %rax
movq 0x30(%rax), %rcx
movslq 0x14(%rax), %rax
orl $0x2, -0x4(%rcx,%rax,8)
movl 0x18(%rbx), %r12d
leal 0x1(%r12), %eax
movl %eax, 0x18(%rbx)
callq 0x2bafa
movq 0x20(%rbx), %r14
orl $0x6000000, 0x10(%r14)  # imm = 0x6000000
movl %eax, %r15d
movl 0x40(%rbx), %r13d
movl $0x1, 0x40(%rbx)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %r14, %rdi
movq %rax, %rsi
callq 0x4ba17
movl %eax, %r14d
movl %r13d, 0x40(%rbx)
movl %r12d, 0x18(%rbx)
movl %r15d, %edi
callq 0x2bb21
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x4b832
movq 0x20(%rbx), %rdi
callq 0x29d8c
movq 0x20(%rbx), %rax
movl -0x2c(%rbp), %ecx
addl %ecx, 0x1c(%rax)
testl %r14d, %r14d
jne 0x4b8aa
movq 0x38(%rbx), %rax
movq (%rax), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2024e(%rip), %rdi     # 0x6baa2
callq 0x191a3
leaq 0x20276(%rip), %rdi     # 0x6bad6
callq 0x191a3
movq 0x10(%r15), %rax
movl 0x64(%rax), %ebx
movl 0x68(%rax), %r12d
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
movq %r15, %rdi
callq 0x4ed7e
cmpl %r12d, %ebx
setne %cl
cmpl %r14d, %ebx
sete %dl
orb %cl, %dl
je 0x4b8c7
testl %ebx, %ebx
sets %cl
cmpl %r14d, %ebx
setle %dl
orb %cl, %dl
jne 0x4b91f
leaq 0x20274(%rip), %rdi     # 0x6bb1c
jmp 0x4b8ce
movq 0x28(%rbx), %rax
testq %rax, %rax
setne %cl
cmpl $0xd, %r14d
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x4b8d5
incl 0x48(%rax)
jmp 0x4b8db
leaq 0x20224(%rip), %rdi     # 0x6baf2
movq %rax, %rsi
movl %ebx, %edx
jmp 0x4b92c
cmpl $0x1, %r14d
je 0x4b913
movq 0x38(%rbx), %r15
movl %r14d, %eax
leaq 0x38ba7(%rip), %rcx     # 0x84490
movq (%rcx,%rax,8), %rdx
movq (%r15), %rsi
leaq 0x87a9(%rip), %rdi      # 0x540a0
xorl %eax, %eax
callq 0x3f652
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
movq %rax, %rdi
callq 0x4ed39
movq %rax, (%r15)
movq 0x38(%rbx), %rax
movq (%rax), %rdi
callq 0x190aa
leaq 0x20229(%rip), %rdi     # 0x6bb4f
movq %rax, %rsi
movl %r12d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x190bb