// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::TabItemLabelAndCloseButton(ImDrawList*, ImRect const&, int, ImVec2, char const*, unsigned int, unsigned int, bool, bool*, bool*)
void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id, bool is_contents_visible, bool* out_just_closed, bool* out_text_clipped)
{
    ImGuiContext& g = *GImGui;
    ImVec2 label_size = CalcTextSize(label, NULL, true);

    if (out_just_closed)
        *out_just_closed = false;
    if (out_text_clipped)
        *out_text_clipped = false;

    if (bb.GetWidth() <= 1.0f)
        return;

    // In Style V2 we'll have full override of all colors per state (e.g. focused, selected)
    // But right now if you want to alter text color of tabs this is what you need to do.
#if 0
    const float backup_alpha = g.Style.Alpha;
    if (!is_contents_visible)
        g.Style.Alpha *= 0.7f;
#endif

    // Render text label (with clipping + alpha gradient) + unsaved marker
    const char* TAB_UNSAVED_MARKER = "*";
    ImRect text_pixel_clip_bb(bb.Min.x + frame_padding.x, bb.Min.y + frame_padding.y, bb.Max.x - frame_padding.x, bb.Max.y);
    if (flags & ImGuiTabItemFlags_UnsavedDocument)
    {
        text_pixel_clip_bb.Max.x -= CalcTextSize(TAB_UNSAVED_MARKER, NULL, false).x;
        ImVec2 unsaved_marker_pos(ImMin(bb.Min.x + frame_padding.x + label_size.x + 2, text_pixel_clip_bb.Max.x), bb.Min.y + frame_padding.y + IM_FLOOR(-g.FontSize * 0.25f));
        RenderTextClippedEx(draw_list, unsaved_marker_pos, bb.Max - frame_padding, TAB_UNSAVED_MARKER, NULL, NULL);
    }
    ImRect text_ellipsis_clip_bb = text_pixel_clip_bb;

    // Return clipped state ignoring the close button
    if (out_text_clipped)
    {
        *out_text_clipped = (text_ellipsis_clip_bb.Min.x + label_size.x) > text_pixel_clip_bb.Max.x;
        //draw_list->AddCircle(text_ellipsis_clip_bb.Min, 3.0f, *out_text_clipped ? IM_COL32(255, 0, 0, 255) : IM_COL32(0, 255, 0, 255));
    }

    // Close Button
    // We are relying on a subtle and confusing distinction between 'hovered' and 'g.HoveredId' which happens because we are using ImGuiButtonFlags_AllowOverlapMode + SetItemAllowOverlap()
    //  'hovered' will be true when hovering the Tab but NOT when hovering the close button
    //  'g.HoveredId==id' will be true when hovering the Tab including when hovering the close button
    //  'g.ActiveId==close_button_id' will be true when we are holding on the close button, in which case both hovered booleans are false
    bool close_button_pressed = false;
    bool close_button_visible = false;
    if (close_button_id != 0)
        if (is_contents_visible || bb.GetWidth() >= g.Style.TabMinWidthForCloseButton)
            if (g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == tab_id || g.ActiveId == close_button_id)
                close_button_visible = true;
    if (close_button_visible)
    {
        ImGuiLastItemDataBackup last_item_backup;
        const float close_button_sz = g.FontSize;
        PushStyleVar(ImGuiStyleVar_FramePadding, frame_padding);
        if (CloseButton(close_button_id, ImVec2(bb.Max.x - frame_padding.x * 2.0f - close_button_sz, bb.Min.y)))
            close_button_pressed = true;
        PopStyleVar();
        last_item_backup.Restore();

        // Close with middle mouse button
        if (!(flags & ImGuiTabItemFlags_NoCloseWithMiddleMouseButton) && IsMouseClicked(2))
            close_button_pressed = true;

        text_pixel_clip_bb.Max.x -= close_button_sz;
    }

    // FIXME: if FramePadding is noticeably large, ellipsis_max_x will be wrong here (e.g. #3497), maybe for consistency that parameter of RenderTextEllipsis() shouldn't exist..
    float ellipsis_max_x = close_button_visible ? text_pixel_clip_bb.Max.x : bb.Max.x - 1.0f;
    RenderTextEllipsis(draw_list, text_ellipsis_clip_bb.Min, text_ellipsis_clip_bb.Max, text_pixel_clip_bb.Max.x, ellipsis_max_x, label, NULL, &label_size);

#if 0
    if (!is_contents_visible)
        g.Style.Alpha = backup_alpha;
#endif

    if (out_just_closed)
        *out_just_closed = close_button_pressed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %r13d
movl %r8d, -0x30(%rbp)
movl %edx, -0x3c(%rbp)
movq %rsi, %r15
movq %rdi, -0x70(%rbp)
movq 0x20(%rbp), %r14
movq 0x18(%rbp), %rbx
movlps %xmm0, -0x38(%rbp)
leaq 0x55e0c(%rip), %rax     # 0xfdcd0
movq (%rax), %r12
movss 0xf101(%rip), %xmm0     # 0xb6fd0
movq %rcx, -0x78(%rbp)
movq %rcx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4548d
movlps %xmm0, -0x50(%rbp)
testq %rbx, %rbx
je 0xa7eee
movb $0x0, (%rbx)
testq %r14, %r14
je 0xa7ef7
movb $0x0, (%r14)
movss (%r15), %xmm3
movss 0x8(%r15), %xmm2
movaps %xmm2, %xmm0
subss %xmm3, %xmm0
movss 0xf0d3(%rip), %xmm1     # 0xb6fe4
ucomiss %xmm0, %xmm1
jae 0xa81fa
movss -0x38(%rbp), %xmm0
addss %xmm0, %xmm3
movss 0x4(%r15), %xmm4
movss 0xc(%r15), %xmm1
addss -0x34(%rbp), %xmm4
subss %xmm0, %xmm2
testb $0x1, -0x3c(%rbp)
je 0xa802f
leaq 0x13399(%rip), %rdi     # 0xbb2e2
xorl %ebx, %ebx
movss 0xf07d(%rip), %xmm0     # 0xb6fd0
xorl %esi, %esi
xorl %edx, %edx
movss %xmm2, -0x2c(%rbp)
movss %xmm3, -0x48(%rbp)
movss %xmm1, -0x58(%rbp)
movss %xmm4, -0x54(%rbp)
callq 0x4548d
movss -0x2c(%rbp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, -0x2c(%rbp)
movss -0x38(%rbp), %xmm0
movss (%r15), %xmm1
addss %xmm0, %xmm1
addss -0x50(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
addss 0xf8ca(%rip), %xmm1     # 0xb7868
minss -0x2c(%rbp), %xmm1
movss 0x4(%r15), %xmm3
movss 0x1980(%r12), %xmm4
mulss 0xf90d(%rip), %xmm4     # 0xb78c8
addss %xmm2, %xmm3
cvttps2dq %xmm4, %xmm4
cvtdq2ps %xmm4, %xmm4
addss %xmm3, %xmm4
leaq -0xa0(%rbp), %rsi
movss %xmm1, (%rsi)
movss %xmm4, 0x4(%rsi)
movss 0x8(%r15), %xmm1
movss 0xc(%r15), %xmm3
subss %xmm0, %xmm1
subss %xmm2, %xmm3
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
leaq -0x68(%rbp), %rdx
movlps %xmm1, (%rdx)
leaq -0x80(%rbp), %rax
movq %rbx, (%rax)
movq -0x70(%rbp), %rdi
leaq 0x132d8(%rip), %rcx     # 0xbb2e2
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbx
pushq %rax
callq 0x4526d
movss -0x54(%rbp), %xmm4
movss -0x58(%rbp), %xmm1
movss -0x48(%rbp), %xmm3
movss -0x2c(%rbp), %xmm2
addq $0x10, %rsp
movss %xmm3, -0x68(%rbp)
movss %xmm4, -0x64(%rbp)
movss %xmm2, -0x60(%rbp)
movss %xmm1, -0x5c(%rbp)
testq %r14, %r14
je 0xa8054
addss -0x50(%rbp), %xmm3
ucomiss %xmm2, %xmm3
seta (%r14)
testl %r13d, %r13d
je 0xa80aa
cmpb $0x0, 0x10(%rbp)
jne 0xa8075
movss 0x8(%r15), %xmm0
subss (%r15), %xmm0
ucomiss 0x15ec(%r12), %xmm0
jb 0xa80aa
movl 0x1b1c(%r12), %eax
movl -0x30(%rbp), %edx
cmpl %edx, %eax
sete %cl
cmpl %r13d, %eax
sete %al
orb %cl, %al
jne 0xa80a6
movl 0x1b30(%r12), %eax
cmpl %edx, %eax
setne %cl
cmpl %r13d, %eax
setne %al
testb %al, %cl
jne 0xa80aa
movb $0x1, %bl
jmp 0xa80ac
xorl %ebx, %ebx
testb %bl, %bl
je 0xa81b7
movss %xmm2, -0x2c(%rbp)
leaq 0x55c10(%rip), %rax     # 0xfdcd0
movq (%rax), %rax
movq 0x1ae0(%rax), %rax
movq 0x124(%rax), %rcx
movq %rcx, -0x48(%rbp)
movups 0x12c(%rax), %xmm0
movaps %xmm0, -0xa0(%rbp)
movups 0x13c(%rax), %xmm0
movaps %xmm0, -0x90(%rbp)
movss 0x1980(%r12), %xmm0
movss %xmm0, -0x30(%rbp)
leaq -0x38(%rbp), %r14
movl $0xa, %edi
movq %r14, %rsi
callq 0x44ba2
movss 0x4(%r15), %xmm0
movss 0x8(%r15), %xmm1
movss (%r14), %xmm2
addss %xmm2, %xmm2
subss %xmm2, %xmm1
subss -0x30(%rbp), %xmm1
leaq -0x80(%rbp), %rsi
movss %xmm1, (%rsi)
movss %xmm0, 0x4(%rsi)
movl %r13d, %edi
callq 0x934c0
movl %eax, %r14d
movl $0x1, %r12d
movl $0x1, %edi
callq 0x44d5f
leaq 0x55b72(%rip), %rax     # 0xfdcd0
movq (%rax), %rax
movq 0x1ae0(%rax), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x124(%rax)
movaps -0xa0(%rbp), %xmm0
movups %xmm0, 0x12c(%rax)
movaps -0x90(%rbp), %xmm0
movups %xmm0, 0x13c(%rax)
testb $0x4, -0x3c(%rbp)
jne 0xa81ab
movl $0x2, %edi
xorl %esi, %esi
callq 0x52641
movzbl %r14b, %r14d
testb %al, %al
cmovnel %r12d, %r14d
movss -0x2c(%rbp), %xmm2
subss -0x30(%rbp), %xmm2
jmp 0xa81ba
xorl %r14d, %r14d
leaq -0x60(%rbp), %rdx
movaps %xmm2, %xmm1
testb %bl, %bl
jne 0xa81d3
movss 0x8(%r15), %xmm1
addss 0xedfd(%rip), %xmm1     # 0xb6fd0
leaq -0x68(%rbp), %rsi
leaq -0x50(%rbp), %r9
movq -0x70(%rbp), %rdi
movaps %xmm2, %xmm0
movq -0x78(%rbp), %rcx
xorl %r8d, %r8d
callq 0x455d4
movq 0x18(%rbp), %rax
testq %rax, %rax
je 0xa81fa
movb %r14b, (%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq