// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq 0x10(%rsi), %rcx
movl 0x18(%rdi), %r15d
movl 0x1c(%rdi), %edx
subl %r15d, %edx
pushq $0x1
popq %rax
cmpl 0x64(%rcx), %edx
jl 0x278af
cmpl 0x68(%rcx), %edx
jg 0x278af
movq %rsi, %r12
movq %rdi, %r14
movslq 0x14(%rdi), %rax
movslq 0x5c(%rcx), %r13
addq %rax, %r13
leal 0x4(%r13), %ebx
cmpl %ebx, 0x20(%rdi)
jge 0x27703
leal (%rbx,%rbx), %esi
movq %r14, %rdi
callq 0x26ff6
movl 0x14(%r14), %eax
movl 0x18(%r14), %r15d
movq 0x30(%r14), %rdx
movslq %eax, %rcx
leaq (%rdx,%rcx,8), %rdi
cmpq $0x0, -0x20(%rdi)
movq %rdx, -0x48(%rbp)
movq %rdx, %rax
movq %rbx, -0x50(%rbp)
je 0x27737
movq %rdi, %rbx
movq -0x10(%rdi), %rdi
callq 0x27560
movq %rbx, %rdi
movq 0x30(%r14), %rax
movslq 0x14(%r14), %rcx
andq $0x0, -0x10(%rax,%rcx,8)
movq 0x10(%r12), %rcx
movl 0x58(%rcx), %edx
btl $0x10, %edx
jb 0x27758
movl 0x1c(%r14), %ebx
subl 0x18(%r14), %ebx
jmp 0x2783e
movl %edx, -0x38(%rbp)
movslq 0x18(%r14), %rdx
movslq 0x60(%rcx), %rbx
addq %rdx, %rbx
movl 0x1c(%r14), %ecx
movl %ecx, %esi
subl %ebx, %esi
movq %rdi, -0x40(%rbp)
jle 0x277a6
movslq %ebx, %rcx
leaq (%rax,%rcx,8), %rax
btl $0x18, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movq %rax, %rdi
jb 0x2780f
callq 0x44692
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
callq 0x4b366
jmp 0x27814
movl %r15d, -0x34(%rbp)
movq %r12, -0x30(%rbp)
cmpl 0x20(%r14), %ebx
jl 0x277c7
leal 0x2(,%rbx,2), %esi
movq %r14, %rdi
callq 0x26ff6
movl 0x1c(%r14), %ecx
movslq %ecx, %r15
movq 0x30(%r14), %r12
cmpq %rbx, %r15
jge 0x277eb
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
movq %rax, (%r12,%r15,8)
incq %r15
jmp 0x277ca
btl $0x18, -0x38(%rbp)
jb 0x2781d
xorl %edi, %edi
xorl %esi, %esi
callq 0x44692
movabsq $-0x4000000000000, %rsi # imm = 0xFFFC000000000000
movq %rax, %rdi
callq 0x4b366
jmp 0x27826
callq 0x27436
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
jmp 0x27832
xorl %edi, %edi
xorl %esi, %esi
callq 0x27436
movq %rax, (%r12,%rbx,8)
movq -0x30(%rbp), %r12
movl -0x34(%rbp), %r15d
movl 0x18(%r14), %eax
subl %eax, %ebx
incl %ebx
movq -0x40(%rbp), %rdi
testl %ebx, %ebx
je 0x27859
movslq %r15d, %rax
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,8), %rsi
movslq %ebx, %rdx
shlq $0x3, %rdx
callq 0x12920
addl 0x14(%r14), %ebx
movslq %ebx, %rbx
cmpq %r13, %rbx
jge 0x27881
movq 0x30(%r14), %r15
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x4b313
movq %rax, (%r15,%rbx,8)
incq %rbx
jmp 0x27860
movq -0x50(%rbp), %rax
movl %eax, 0x18(%r14)
movl %eax, 0x1c(%r14)
movq 0x30(%r14), %rax
movslq 0x14(%r14), %rcx
movq %r12, -0x20(%rax,%rcx,8)
movq 0x10(%r12), %rdx
movq 0x28(%rdx), %rdx
movq %rdx, -0x18(%rax,%rcx,8)
orb $0x1, -0x4(%rax,%rcx,8)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq