// File: 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
subq $0x100, %rsp            # imm = 0x100
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movb 0x10(%rbp), %al
movlpd %xmm0, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
leaq 0xba6e2(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
movss 0x19706(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movlpd %xmm0, -0x48(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x158892
movq 0x18(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, 0x20(%rbp)
je 0x1588a0
movq 0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rdi
callq 0xeb840
movaps %xmm0, %xmm1
movss 0x18388(%rip), %xmm0    # 0x170c3c
ucomiss %xmm1, %xmm0
jb 0x1588be
jmp 0x158c51
leaq 0x1da8d(%rip), %rax     # 0x176352
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
addss -0x8(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm1
addss -0x4(%rbp), %xmm1
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm2
subss -0x8(%rbp), %xmm2
movq -0x18(%rbp), %rax
movss 0xc(%rax), %xmm3
leaq -0x60(%rbp), %rdi
callq 0xec090
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x158a1d
movq -0x50(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
movss 0x1965d(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movlpd %xmm0, -0x68(%rbp)
movss -0x68(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movss -0x8(%rbp), %xmm1
addss %xmm1, %xmm0
movss -0x48(%rbp), %xmm1
addss %xmm1, %xmm0
movss 0x1966a(%rip), %xmm1    # 0x171fcc
addss %xmm1, %xmm0
movss -0x58(%rbp), %xmm1
callq 0x13c690
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm1
movss -0x4(%rbp), %xmm2
addss %xmm2, %xmm1
movq -0x40(%rbp), %rax
movss 0x1980(%rax), %xmm2
movss 0x19e26(%rip), %xmm3    # 0x1727bc
mulss %xmm3, %xmm2
cvttps2dq %xmm2, %xmm2
cvtdq2ps %xmm2, %xmm2
addss %xmm2, %xmm1
leaq -0x70(%rbp), %rdi
callq 0xbf4c0
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
leaq -0x8(%rbp), %rsi
callq 0x1390e0
movlpd %xmm0, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x80(%rbp), %rdi
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rcx
leaq -0x70(%rbp), %rsi
leaq -0x78(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r9d
leaq -0x80(%rbp), %rax
movq %r9, %r8
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0xc8550
movq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, 0x20(%rbp)
je 0x158a57
movss -0x90(%rbp), %xmm0
addss -0x48(%rbp), %xmm0
ucomiss -0x58(%rbp), %xmm0
seta %cl
movq 0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movb $0x0, -0x91(%rbp)
movb $0x0, -0x92(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x158ace
testb $0x1, -0x31(%rbp)
jne 0x158a87
movq -0x18(%rbp), %rdi
callq 0xeb840
movq -0x40(%rbp), %rax
ucomiss 0x15ec(%rax), %xmm0
jb 0x158acc
movq -0x40(%rbp), %rax
movl 0x1b1c(%rax), %eax
cmpl -0x2c(%rbp), %eax
je 0x158ac3
movq -0x40(%rbp), %rax
movl 0x1b1c(%rax), %eax
cmpl -0x30(%rbp), %eax
je 0x158ac3
movq -0x40(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x2c(%rbp), %eax
je 0x158ac3
movq -0x40(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x30(%rbp), %eax
jne 0x158aca
movb $0x1, -0x92(%rbp)
jmp 0x158acc
jmp 0x158ace
testb $0x1, -0x92(%rbp)
je 0x158bc1
leaq -0xbc(%rbp), %rdi
callq 0x1625d0
movq -0x40(%rbp), %rax
movss 0x1980(%rax), %xmm0
movss %xmm0, -0xc0(%rbp)
movl $0xa, %edi
leaq -0x8(%rbp), %rsi
callq 0xc7b50
movl -0x30(%rbp), %eax
movl %eax, -0xe4(%rbp)
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm1
movss -0x8(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
addss %xmm0, %xmm0
addss %xmm1, %xmm0
subss -0xc0(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm1
leaq -0xc8(%rbp), %rdi
callq 0xbf4c0
movl -0xe4(%rbp), %edi
leaq -0xc8(%rbp), %rsi
callq 0x13ae80
testb $0x1, %al
jne 0x158b6a
jmp 0x158b71
movb $0x1, -0x91(%rbp)
movl $0x1, %edi
callq 0xc7c10
leaq -0xbc(%rbp), %rdi
callq 0x162610
movl -0x1c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x158bab
movl $0x2, %edi
xorl %esi, %esi
callq 0xd4d60
testb $0x1, %al
jne 0x158ba4
jmp 0x158bab
movb $0x1, -0x91(%rbp)
movss -0xc0(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
testb $0x1, -0x92(%rbp)
je 0x158bd9
movss -0x58(%rbp), %xmm0
movss %xmm0, -0xe8(%rbp)
jmp 0x158bf6
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm0
movss 0x18052(%rip), %xmm1    # 0x170c3c
subss %xmm1, %xmm0
movss %xmm0, -0xe8(%rbp)
movss -0xe8(%rbp), %xmm0
movss %xmm0, -0xcc(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x90(%rbp), %rdx
addq $0x8, %rdx
movss -0x58(%rbp), %xmm0
movss -0xcc(%rbp), %xmm1
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x48(%rbp), %r9
callq 0xc89c0
cmpq $0x0, 0x18(%rbp)
je 0x158c51
movb -0x91(%rbp), %cl
movq 0x18(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw (%rax,%rax)