// File: /workspace/github_c_makefile_star2_O1/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), %r15d
movq 0x10(%rsi), %rax
movl %edx, %ecx
subl %r15d, %ecx
movl $0x1, %ebx
cmpl 0x64(%rax), %ecx
jl 0x29aab
cmpl 0x68(%rax), %ecx
jg 0x29aab
movq %rdi, %r12
movq %rsi, -0x50(%rbp)
movl %edx, -0x2c(%rbp)
movl 0x14(%rdi), %ecx
movl %ecx, -0x30(%rbp)
movl 0x5c(%rax), %r14d
leal (%r15,%r14), %ebx
addl $0x4, %ebx
cmpl %ebx, 0x20(%rdi)
jge 0x299a5
leal (%rbx,%rbx), %esi
movq %r12, %rdi
callq 0x298e0
movq %r15, -0x38(%rbp)
movslq %r15d, %rax
movq %rax, -0x48(%rbp)
movslq 0x1c(%r12), %r15
movq %rbx, -0x40(%rbp)
cmpl %ebx, %r15d
jge 0x299ed
addl -0x38(%rbp), %r14d
subl %r15d, %r14d
addl $0x4, %r14d
movabsq $-0x77fffffffffff, %rbx # imm = 0xFFF8800000000001
movq 0x30(%r12), %r13
movq %rbx, %rdi
callq 0x4f95a
movq %rax, (%r13,%r15,8)
incq %r15
decl %r14d
jne 0x299d3
movq -0x38(%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 -0x48(%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)
movq $0x0, -0x10(%rax,%rsi,8)
movl $0x0, -0x4(%rax,%rsi,8)
movq 0x10(%rdx), %rdx
movl 0x58(%rdx), %ecx
xorl %ebx, %ebx
btl $0x10, %ecx
jae 0x29aab
movslq 0x60(%rdx), %rdx
addq %rsi, %rdx
leaq (%rax,%rdx,8), %r15
movl -0x2c(%rbp), %esi
subl %edx, %esi
jle 0x29a6c
movq %r15, %rdi
btl $0x18, %ecx
jae 0x29a76
callq 0x29d25
jmp 0x29aa8
btl $0x18, %ecx
jb 0x29a87
xorl %edi, %edi
xorl %esi, %esi
callq 0x48a9f
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
jmp 0x29aa0
xorl %edi, %edi
callq 0x46f8c
movq %rax, %rdi
callq 0x472c9
movabsq $-0x3000000000000, %rsi # imm = 0xFFFD000000000000
movq %rax, %rdi
callq 0x4f9ad
movq %rax, (%r15)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq