// File: /workspace/github_c_makefile_star2_O1/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 0x4c419
movq %rax, %rbx
cmpl $0x400, 0x18(%rax)      # imm = 0x400
jge 0x4c425
movl 0x18(%rdi), %ecx
movl 0x1c(%rdi), %eax
movl %eax, -0x30(%rbp)
movl %ecx, -0x34(%rbp)
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
je 0x4c33c
leaq 0x1c9(%rip), %rsi       # 0x4c500
callq 0x2a1c5
testb $0x1, 0x2(%r15)
je 0x4c357
incl 0x18(%rbx)
movq %r15, %rdi
movl %r14d, %esi
movq %r12, %rdx
callq 0x4c510
decl 0x18(%rbx)
movq 0x20(%rbx), %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x29ca9
movq 0x20(%rbx), %rdi
movq %r15, %rsi
callq 0x29942
testl %eax, %eax
jne 0x4c431
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 0x2bf94
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 0x4f95a
movq %r14, %rdi
movq %rax, %rsi
callq 0x4c5e1
movl %eax, %r14d
movl %r13d, 0x40(%rbx)
movl %r12d, 0x18(%rbx)
movl %r15d, %edi
callq 0x2bfbb
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x4c3fe
movq 0x20(%rbx), %rdi
callq 0x2a23f
movq 0x20(%rbx), %rax
movl -0x2c(%rbp), %ecx
addl %ecx, 0x1c(%rax)
testl %r14d, %r14d
jne 0x4c476
movq 0x38(%rbx), %rax
movq (%rax), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x206a2(%rip), %rdi     # 0x6cac2
callq 0x19263
leaq 0x206ca(%rip), %rdi     # 0x6caf6
callq 0x19263
movq 0x10(%r15), %rax
movl 0x64(%rax), %ebx
movl 0x68(%rax), %r12d
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
movq %r15, %rdi
callq 0x4f9f2
cmpl %r12d, %ebx
setne %cl
cmpl %r14d, %ebx
sete %dl
orb %cl, %dl
je 0x4c4db
testl %ebx, %ebx
sets %cl
cmpl %r14d, %ebx
setle %dl
orb %cl, %dl
jne 0x4c4e9
leaq 0x206c8(%rip), %rdi     # 0x6cb3c
jmp 0x4c4e2
movq 0x28(%rbx), %rax
testq %rax, %rax
setne %cl
cmpl $0xd, %r14d
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x4c491
incl 0x48(%rax)
cmpl $0x1, %r14d
je 0x4c4cf
movq 0x38(%rbx), %r15
movl %r14d, %eax
leaq 0x38feb(%rip), %rcx     # 0x85490
movq (%rcx,%rax,8), %rdx
movq (%r15), %rsi
leaq 0x8bed(%rip), %rdi      # 0x550a0
xorl %eax, %eax
callq 0x3fd86
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
movq %rax, %rdi
callq 0x4f9ad
movq %rax, (%r15)
movq 0x38(%rbx), %rax
movq (%rax), %rdi
callq 0x1916a
leaq 0x20630(%rip), %rdi     # 0x6cb12
movq %rax, %rsi
movl %ebx, %edx
jmp 0x4c4f6
leaq 0x2067f(%rip), %rdi     # 0x6cb6f
movq %rax, %rsi
movl %r12d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x1917b