// File: /workspace/github_c_makefile_star2_O2/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 0x47d42
movq %rax, %rbx
cmpl $0x400, 0x18(%rax)      # imm = 0x400
jge 0x47d4e
movl 0x18(%rdi), %ecx
movl 0x1c(%rdi), %eax
movl %eax, -0x30(%rbp)
movl %ecx, -0x34(%rbp)
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
je 0x47c65
leaq 0x1cb(%rip), %rsi       # 0x47e2b
callq 0x278be
testb $0x1, 0x2(%r15)
je 0x47c80
incl 0x18(%rbx)
movq %r15, %rdi
movl %r14d, %esi
movq %r12, %rdx
callq 0x47e3b
decl 0x18(%rbx)
movq 0x20(%rbx), %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x273c8
movq 0x20(%rbx), %rdi
movq %r15, %rsi
callq 0x2707d
testl %eax, %eax
jne 0x47d5a
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 0x29627
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 0x4b313
movq %r14, %rdi
movq %rax, %rsi
callq 0x47f05
movl %eax, %r14d
movl %r13d, 0x40(%rbx)
movl %r12d, 0x18(%rbx)
movl %r15d, %edi
callq 0x2964e
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x47d27
movq 0x20(%rbx), %rdi
callq 0x27935
movq 0x20(%rbx), %rax
movl -0x2c(%rbp), %ecx
addl %ecx, 0x1c(%rax)
testl %r14d, %r14d
jne 0x47d9f
movq 0x38(%rbx), %rax
movq (%rax), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fd79(%rip), %rdi     # 0x67ac2
callq 0x177b1
leaq 0x1fda1(%rip), %rdi     # 0x67af6
callq 0x177b1
movq 0x10(%r15), %rax
movl 0x64(%rax), %ebx
movl 0x68(%rax), %r12d
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
movq %r15, %rdi
callq 0x4b3ab
cmpl %r12d, %ebx
setne %cl
cmpl %r14d, %ebx
sete %dl
orb %cl, %dl
je 0x47dbc
testl %ebx, %ebx
sets %cl
cmpl %r14d, %ebx
setle %dl
orb %cl, %dl
jne 0x47e14
leaq 0x1fd9f(%rip), %rdi     # 0x67b3c
jmp 0x47dc3
movq 0x28(%rbx), %rax
testq %rax, %rax
setne %cl
cmpl $0xd, %r14d
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x47dca
incl 0x48(%rax)
jmp 0x47dd0
leaq 0x1fd4f(%rip), %rdi     # 0x67b12
movq %rax, %rsi
movl %ebx, %edx
jmp 0x47e21
cmpl $0x1, %r14d
je 0x47e08
movq 0x38(%rbx), %r15
movl %r14d, %eax
leaq 0x376b2(%rip), %rcx     # 0x7f490
movq (%rcx,%rax,8), %rdx
movq (%r15), %rsi
leaq 0x82b4(%rip), %rdi      # 0x500a0
xorl %eax, %eax
callq 0x3c0ed
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
movq %rax, %rdi
callq 0x4b366
movq %rax, (%r15)
movq 0x38(%rbx), %rax
movq (%rax), %rdi
callq 0x176ba
leaq 0x1fd54(%rip), %rdi     # 0x67b6f
movq %rax, %rsi
movl %r12d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x176c9