// File: /workspace/github_c_makefile_star2_O3/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 0x295d3
cmpl 0x68(%rax), %ecx
jg 0x295d3
movq %rdi, %r12
movq %rsi, -0x50(%rbp)
movl 0x14(%rdi), %ecx
movl %ecx, -0x30(%rbp)
movl 0x5c(%rax), %r14d
leal (%r15,%r14), %ebx
addl $0x4, %ebx
movl %edx, -0x2c(%rbp)
movl %edx, %eax
cmpl %ebx, 0x20(%rdi)
jge 0x294d0
leal (%rbx,%rbx), %esi
movq %r12, %rdi
callq 0x29404
movl 0x1c(%r12), %eax
movq %r15, -0x38(%rbp)
movslq %r15d, %rcx
movq %rcx, -0x40(%rbp)
movq %rbx, -0x48(%rbp)
cmpl %ebx, %eax
jge 0x29515
movslq %eax, %r15
addl -0x38(%rbp), %r14d
subl %eax, %r14d
addl $0x4, %r14d
movabsq $-0x77fffffffffff, %rbx # imm = 0xFFF8800000000001
movq 0x30(%r12), %r13
movq %rbx, %rdi
callq 0x4ece6
movq %rax, (%r13,%r15,8)
incq %r15
decl %r14d
jne 0x294fb
movq -0x38(%rbp), %rax
movl %eax, 0x14(%r12)
movq -0x48(%rbp), %rax
movl %eax, 0x18(%r12)
movl %eax, 0x1c(%r12)
movq 0x30(%r12), %rax
movl -0x30(%rbp), %ecx
movq -0x40(%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 0x295d3
movslq 0x60(%rdx), %rdx
addq %rsi, %rdx
leaq (%rax,%rdx,8), %r15
movl -0x2c(%rbp), %esi
subl %edx, %esi
jle 0x29594
movq %r15, %rdi
btl $0x18, %ecx
jae 0x2959e
callq 0x29855
jmp 0x295d0
btl $0x18, %ecx
jb 0x295af
xorl %edi, %edi
xorl %esi, %esi
callq 0x47fef
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
jmp 0x295c8
xorl %edi, %edi
callq 0x46574
movq %rax, %rdi
callq 0x468c4
movabsq $-0x3000000000000, %rsi # imm = 0xFFFD000000000000
movq %rax, %rdi
callq 0x4ed39
movq %rax, (%r15)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq