// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/fiber.c
// Function: janet_fiber_funcframe_tail
int janet_fiber_funcframe_tail(JanetFiber *fiber, JanetFunction *func) {
    int32_t i;
    int32_t nextframetop = fiber->frame + func->def->slotcount;
    int32_t nextstacktop = nextframetop + JANET_FRAME_SIZE;
    int32_t next_arity = fiber->stacktop - fiber->stackstart;
    int32_t stacksize;

    /* 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
    }

    Janet *stack = fiber->data + fiber->frame;
    Janet *args = fiber->data + fiber->stackstart;

    /* Detach old function */
    if (NULL != janet_fiber_frame(fiber)->func)
        janet_env_detach(janet_fiber_frame(fiber)->env);
    janet_fiber_frame(fiber)->env = NULL;

    /* Check varargs */
    if (func->def->flags & JANET_FUNCDEF_FLAG_VARARG) {
        int32_t tuplehead = fiber->stackstart + func->def->arity;
        int st = func->def->flags & JANET_FUNCDEF_FLAG_STRUCTARG;
        if (tuplehead >= fiber->stacktop) {
            if (tuplehead >= fiber->capacity) janet_fiber_setcapacity(fiber, 2 * (tuplehead + 1));
            for (i = fiber->stacktop; i < tuplehead; ++i) fiber->data[i] = janet_wrap_nil();
            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,
                                         fiber->stacktop - tuplehead)
                                     : janet_wrap_tuple(janet_tuple_n(
                                             fiber->data + tuplehead,
                                             fiber->stacktop - tuplehead));
        }
        stacksize = tuplehead - fiber->stackstart + 1;
    } else {
        stacksize = fiber->stacktop - fiber->stackstart;
    }

    if (stacksize) memmove(stack, args, stacksize * sizeof(Janet));

    /* Nil unset locals (Needed for functional correctness) */
    for (i = fiber->frame + stacksize; i < nextframetop; ++i)
        fiber->data[i] = janet_wrap_nil();

    /* Set stack stuff */
    fiber->stacktop = fiber->stackstart = nextstacktop;

    /* Set frame stuff */
    janet_fiber_frame(fiber)->func = func;
    janet_fiber_frame(fiber)->pc = func->def->bytecode;
    janet_fiber_frame(fiber)->flags |= JANET_STACKFRAME_TAILCALL;

    /* Good return */
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x10(%rsi), %rcx
movl 0x18(%rdi), %r12d
movl 0x1c(%rdi), %edx
subl %r12d, %edx
movl $0x1, %eax
cmpl 0x64(%rcx), %edx
jl 0x29d03
cmpl 0x68(%rcx), %edx
jg 0x29d03
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x14(%rdi), %rax
movslq 0x5c(%rcx), %r13
addq %rax, %r13
leal 0x4(%r13), %r15d
cmpl %r15d, 0x20(%rdi)
jge 0x29b16
leal (%r15,%r15), %esi
movq %r14, %rdi
callq 0x29404
movl 0x14(%r14), %eax
movl 0x18(%r14), %r12d
movq %r15, -0x48(%rbp)
movq 0x30(%r14), %rdx
movslq %eax, %rcx
leaq (%rdx,%rcx,8), %rdi
cmpq $0x0, -0x20(%rdi)
movq %rdx, -0x58(%rbp)
movq %rdx, %rax
je 0x29b4a
movq %rdi, %r15
movq -0x10(%rdi), %rdi
callq 0x2997c
movq %r15, %rdi
movq 0x30(%r14), %rax
movslq 0x14(%r14), %rcx
movq $0x0, -0x10(%rax,%rcx,8)
movq 0x10(%rbx), %rdx
movl 0x58(%rdx), %r8d
btl $0x10, %r8d
movl %r12d, -0x38(%rbp)
jb 0x29b73
movl 0x1c(%r14), %r15d
subl 0x18(%r14), %r15d
jmp 0x29c78
movl 0x18(%r14), %r15d
movl 0x1c(%r14), %ecx
addl 0x60(%rdx), %r15d
movl %ecx, %esi
subl %r15d, %esi
movq %rdi, -0x50(%rbp)
jle 0x29bbb
movslq %r15d, %rcx
leaq (%rax,%rcx,8), %r12
movq %r12, %rdi
btl $0x18, %r8d
jb 0x29c39
callq 0x47fef
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
callq 0x4ed39
jmp 0x29c3e
movl %r8d, -0x34(%rbp)
movq %rbx, -0x30(%rbp)
cmpl 0x20(%r14), %r15d
jl 0x29bdd
leal 0x2(,%r15,2), %esi
movq %r14, %rdi
callq 0x29404
movl 0x1c(%r14), %ecx
movq %r15, -0x40(%rbp)
cmpl %r15d, %ecx
jge 0x29c12
movslq %ecx, %r15
movq -0x40(%rbp), %rax
movl %eax, %r12d
subl %ecx, %r12d
movq 0x30(%r14), %rbx
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4ece6
movq %rax, (%rbx,%r15,8)
incq %r15
decl %r12d
jne 0x29bf3
movq 0x30(%r14), %rbx
movq -0x40(%rbp), %r15
movslq %r15d, %r12
btl $0x18, -0x34(%rbp)
jb 0x29c44
xorl %edi, %edi
xorl %esi, %esi
callq 0x47fef
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
jmp 0x29c5d
callq 0x29855
movq %rax, (%r12)
jmp 0x29c6d
xorl %edi, %edi
callq 0x46574
movq %rax, %rdi
callq 0x468c4
movabsq $-0x3000000000000, %rsi # imm = 0xFFFD000000000000
movq %rax, %rdi
callq 0x4ed39
movq %rax, (%rbx,%r12,8)
movq -0x30(%rbp), %rbx
subl 0x18(%r14), %r15d
incl %r15d
movq -0x50(%rbp), %rdi
movslq %r15d, %r12
testl %r15d, %r15d
je 0x29c99
movslq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
leaq (%rcx,%rax,8), %rsi
leaq (,%r12,8), %rdx
callq 0x12920
movl 0x14(%r14), %eax
addl %eax, %r15d
cmpl %r13d, %r15d
jge 0x29cd8
movq %rbx, -0x30(%rbp)
cltq
movabsq $-0x77fffffffffff, %r15 # imm = 0xFFF8800000000001
addq %rax, %r12
movq 0x30(%r14), %rbx
movq %r15, %rdi
callq 0x4ece6
movq %rax, (%rbx,%r12,8)
incq %r12
cmpq %r13, %r12
jl 0x29cb8
movl 0x14(%r14), %eax
movq -0x30(%rbp), %rbx
movq -0x48(%rbp), %rcx
movl %ecx, 0x18(%r14)
movl %ecx, 0x1c(%r14)
movq 0x30(%r14), %rcx
cltq
movq %rbx, -0x20(%rcx,%rax,8)
movq 0x10(%rbx), %rdx
movq 0x28(%rdx), %rdx
movq %rdx, -0x18(%rcx,%rax,8)
orb $0x1, -0x4(%rcx,%rax,8)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq