// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/fiber.c
// Function: janet_fiber_funcframe
int janet_fiber_funcframe(JanetFiber *fiber, JanetFunction *func) {
    JanetStackFrame *newframe;

    int32_t i;
    int32_t oldtop = fiber->stacktop;
    int32_t oldframe = fiber->frame;
    int32_t nextframe = fiber->stackstart;
    int32_t nextstacktop = nextframe + func->def->slotcount + JANET_FRAME_SIZE;
    int32_t next_arity = fiber->stacktop - fiber->stackstart;

    /* Check strict arity before messing with state */
    if (next_arity < func->def->min_arity) return 1;
    if (next_arity > func->def->max_arity) return 1;

    if (fiber->capacity < nextstacktop) {
        janet_fiber_setcapacity(fiber, 2 * nextstacktop);
#ifdef JANET_DEBUG
    } else {
        janet_fiber_refresh_memory(fiber);
#endif
    }

    /* Nil unset stack arguments (Needed for gc correctness) */
    for (i = fiber->stacktop; i < nextstacktop; ++i) {
        fiber->data[i] = janet_wrap_nil();
    }

    /* Set up the next frame */
    fiber->frame = nextframe;
    fiber->stacktop = fiber->stackstart = nextstacktop;
    newframe = janet_fiber_frame(fiber);
    newframe->prevframe = oldframe;
    newframe->pc = func->def->bytecode;
    newframe->func = func;
    newframe->env = NULL;
    newframe->flags = 0;

    /* Check varargs */
    if (func->def->flags & JANET_FUNCDEF_FLAG_VARARG) {
        int32_t tuplehead = fiber->frame + func->def->arity;
        int st = func->def->flags & JANET_FUNCDEF_FLAG_STRUCTARG;
        if (tuplehead >= oldtop) {
            fiber->data[tuplehead] = st
                                     ? make_struct_n(NULL, 0)
                                     : janet_wrap_tuple(janet_tuple_n(NULL, 0));
        } else {
            fiber->data[tuplehead] = st
                                     ? make_struct_n(
                                         fiber->data + tuplehead,
                                         oldtop - tuplehead)
                                     : janet_wrap_tuple(janet_tuple_n(
                                             fiber->data + tuplehead,
                                             oldtop - tuplehead));
        }
    }

    /* Good return */
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl 0x1c(%rdi), %edx
movl 0x18(%rdi), %r14d
movq 0x10(%rsi), %rax
movl %edx, %ecx
subl %r14d, %ecx
pushq $0x1
popq %rbx
cmpl 0x64(%rax), %ecx
jl 0x271b8
cmpl 0x68(%rax), %ecx
jg 0x271b8
movq %rdi, %r12
movq %rsi, -0x50(%rbp)
movl 0x14(%rdi), %ecx
movl %ecx, -0x30(%rbp)
movl 0x5c(%rax), %eax
leal (%r14,%rax), %ebx
addl $0x4, %ebx
movl %edx, -0x2c(%rbp)
movl %edx, %eax
cmpl %ebx, 0x20(%rdi)
jge 0x270e4
leal (%rbx,%rbx), %esi
movq %r12, %rdi
callq 0x26ff6
movl 0x1c(%r12), %eax
movq %r14, -0x48(%rbp)
movslq %r14d, %rcx
movq %rcx, -0x38(%rbp)
movslq %eax, %r14
movq %rbx, -0x40(%rbp)
movslq %ebx, %r15
movabsq $-0x77fffffffffff, %rbx # imm = 0xFFF8800000000001
cmpq %r15, %r14
jge 0x2711f
movq 0x30(%r12), %r13
movq %rbx, %rdi
callq 0x4b313
movq %rax, (%r13,%r14,8)
incq %r14
jmp 0x27103
movq -0x48(%rbp), %rax
movl %eax, 0x14(%r12)
movq -0x40(%rbp), %rax
movl %eax, 0x18(%r12)
movl %eax, 0x1c(%r12)
movq 0x30(%r12), %rax
movl -0x30(%rbp), %ecx
movq -0x38(%rbp), %rsi
movl %ecx, -0x8(%rax,%rsi,8)
movq -0x50(%rbp), %rdx
movq 0x10(%rdx), %rcx
movq 0x28(%rcx), %rcx
movq %rcx, -0x18(%rax,%rsi,8)
movq %rdx, -0x20(%rax,%rsi,8)
andq $0x0, -0x10(%rax,%rsi,8)
andl $0x0, -0x4(%rax,%rsi,8)
movq 0x10(%rdx), %rdx
movl 0x58(%rdx), %ecx
xorl %ebx, %ebx
btl $0x10, %ecx
jae 0x271b8
movslq 0x60(%rdx), %rdx
addq %rsi, %rdx
leaq (%rax,%rdx,8), %r15
movl -0x2c(%rbp), %esi
subl %edx, %esi
jle 0x2718d
movq %r15, %rdi
jmp 0x27191
xorl %edi, %edi
xorl %esi, %esi
btl $0x18, %ecx
jb 0x271b0
callq 0x44692
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
callq 0x4b366
jmp 0x271b5
callq 0x27436
movq %rax, (%r15)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq