// File: /workspace/github_c_makefile_star2_O1/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:
movl 0x1c(%rdi), %edx
subl 0x18(%rdi), %edx
movq 0x10(%rsi), %rcx
movl $0x1, %eax
cmpl 0x64(%rcx), %edx
jl 0x2a1c4
cmpl 0x68(%rcx), %edx
jg 0x2a1c4
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
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 0x29fe2
leal (%r15,%r15), %esi
movq %r14, %rdi
callq 0x298e0
movq 0x30(%r14), %rcx
movslq 0x14(%r14), %rax
movq %rcx, -0x48(%rbp)
leaq (%rcx,%rax,8), %r12
movslq 0x18(%r14), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x20(%r12)
je 0x2a00c
movq -0x10(%r12), %rdi
callq 0x29e54
movq 0x30(%r14), %rax
movslq 0x14(%r14), %rcx
movq $0x0, -0x10(%rax,%rcx,8)
movq 0x10(%rbx), %rcx
movl 0x58(%rcx), %edi
btl $0x10, %edi
movq %rbx, -0x60(%rbp)
movq %r15, -0x58(%rbp)
movq %r12, -0x50(%rbp)
jb 0x2a043
movl 0x1c(%r14), %ebx
subl 0x18(%r14), %ebx
jmp 0x2a131
movl 0x18(%r14), %edx
movl 0x1c(%r14), %esi
addl 0x60(%rcx), %edx
subl %edx, %esi
jle 0x2a082
movslq %edx, %rcx
leaq (%rax,%rcx,8), %r12
btl $0x18, %edi
movq %rdx, %rbx
movq %r12, %rdi
jb 0x2a0fb
callq 0x48a9f
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
callq 0x4f9ad
jmp 0x2a100
movl %edi, -0x2c(%rbp)
cmpl 0x20(%r14), %edx
movq %rdx, %r15
jl 0x2a09e
leal 0x2(,%r15,2), %esi
movq %r14, %rdi
callq 0x298e0
movslq 0x1c(%r14), %rbx
movq %r15, -0x38(%rbp)
cmpl %r15d, %ebx
jge 0x2a0d4
movq -0x38(%rbp), %rax
movl %eax, %r12d
subl %ebx, %r12d
movq 0x30(%r14), %r15
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4f95a
movq %rax, (%r15,%rbx,8)
incq %rbx
decl %r12d
jne 0x2a0b5
movq 0x30(%r14), %r15
movq -0x38(%rbp), %rbx
movslq %ebx, %r12
btl $0x18, -0x2c(%rbp)
jb 0x2a106
xorl %edi, %edi
xorl %esi, %esi
callq 0x48a9f
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
jmp 0x2a11f
callq 0x29d25
movq %rax, (%r12)
jmp 0x2a12b
xorl %edi, %edi
callq 0x46f8c
movq %rax, %rdi
callq 0x472c9
movabsq $-0x3000000000000, %rsi # imm = 0xFFFD000000000000
movq %rax, %rdi
callq 0x4f9ad
movq %rax, (%r15,%r12,8)
subl 0x18(%r14), %ebx
incl %ebx
movslq %ebx, %r12
testl %ebx, %ebx
je 0x2a155
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
leaq (%rax,%rcx,8), %rsi
leaq (,%r12,8), %rdx
movq -0x50(%rbp), %rdi
callq 0x12930
movslq 0x14(%r14), %rax
addl %eax, %ebx
cmpl %r13d, %ebx
jge 0x2a185
movabsq $-0x77fffffffffff, %r15 # imm = 0xFFF8800000000001
addq %rax, %r12
movq 0x30(%r14), %rbx
movq %r15, %rdi
callq 0x4f95a
movq %rax, (%rbx,%r12,8)
incq %r12
cmpq %r13, %r12
jl 0x2a16d
movq -0x58(%rbp), %rax
movl %eax, 0x18(%r14)
movl %eax, 0x1c(%r14)
movq 0x30(%r14), %rax
movslq 0x14(%r14), %rcx
movq -0x60(%rbp), %rdx
movq %rdx, -0x20(%rax,%rcx,8)
movq 0x10(%rdx), %rdx
movq 0x28(%rdx), %rdx
movq %rdx, -0x18(%rax,%rcx,8)
orb $0x1, -0x4(%rax,%rcx,8)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq