// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::RenderWindowTitleBarContents(ImGuiWindow*, ImRect const&, char const*, bool*)
void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open)
{
    ImGuiContext& g = *GImGui;
    ImGuiStyle& style = g.Style;
    ImGuiWindowFlags flags = window->Flags;

    const bool has_close_button = (p_open != NULL);
    const bool has_collapse_button = !(flags & ImGuiWindowFlags_NoCollapse) && (style.WindowMenuButtonPosition != ImGuiDir_None);

    // Close & Collapse button are on the Menu NavLayer and don't default focus (unless there's nothing else on that layer)
    const ImGuiItemFlags item_flags_backup = window->DC.ItemFlags;
    window->DC.ItemFlags |= ImGuiItemFlags_NoNavDefaultFocus;
    window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;

    // Layout buttons
    // FIXME: Would be nice to generalize the subtleties expressed here into reusable code.
    float pad_l = style.FramePadding.x;
    float pad_r = style.FramePadding.x;
    float button_sz = g.FontSize;
    ImVec2 close_button_pos;
    ImVec2 collapse_button_pos;
    if (has_close_button)
    {
        pad_r += button_sz;
        close_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - style.FramePadding.x, title_bar_rect.Min.y);
    }
    if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Right)
    {
        pad_r += button_sz;
        collapse_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - style.FramePadding.x, title_bar_rect.Min.y);
    }
    if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Left)
    {
        collapse_button_pos = ImVec2(title_bar_rect.Min.x + pad_l - style.FramePadding.x, title_bar_rect.Min.y);
        pad_l += button_sz;
    }

    // Collapse button (submitting first so it gets priority when choosing a navigation init fallback)
    if (has_collapse_button)
        if (CollapseButton(window->GetID("#COLLAPSE"), collapse_button_pos))
            window->WantCollapseToggle = true; // Defer actual collapsing to next frame as we are too far in the Begin() function

    // Close button
    if (has_close_button)
        if (CloseButton(window->GetID("#CLOSE"), close_button_pos))
            *p_open = false;

    window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
    window->DC.ItemFlags = item_flags_backup;

    // Title bar text (with: horizontal alignment, avoiding collapse/close button, optional "unsaved document" marker)
    // FIXME: Refactor text alignment facilities along with RenderText helpers, this is WAY too much messy code..
    const char* UNSAVED_DOCUMENT_MARKER = "*";
    const float marker_size_x = (flags & ImGuiWindowFlags_UnsavedDocument) ? CalcTextSize(UNSAVED_DOCUMENT_MARKER, NULL, false).x : 0.0f;
    const ImVec2 text_size = CalcTextSize(name, NULL, true) + ImVec2(marker_size_x, 0.0f);

    // As a nice touch we try to ensure that centered title text doesn't get affected by visibility of Close/Collapse button,
    // while uncentered title text will still reach edges correct.
    if (pad_l > style.FramePadding.x)
        pad_l += g.Style.ItemInnerSpacing.x;
    if (pad_r > style.FramePadding.x)
        pad_r += g.Style.ItemInnerSpacing.x;
    if (style.WindowTitleAlign.x > 0.0f && style.WindowTitleAlign.x < 1.0f)
    {
        float centerness = ImSaturate(1.0f - ImFabs(style.WindowTitleAlign.x - 0.5f) * 2.0f); // 0.0f on either edges, 1.0f on center
        float pad_extend = ImMin(ImMax(pad_l, pad_r), title_bar_rect.GetWidth() - pad_l - pad_r - text_size.x);
        pad_l = ImMax(pad_l, pad_extend * centerness);
        pad_r = ImMax(pad_r, pad_extend * centerness);
    }

    ImRect layout_r(title_bar_rect.Min.x + pad_l, title_bar_rect.Min.y, title_bar_rect.Max.x - pad_r, title_bar_rect.Max.y);
    ImRect clip_r(layout_r.Min.x, layout_r.Min.y, layout_r.Max.x + g.Style.ItemInnerSpacing.x, layout_r.Max.y);
    //if (g.IO.KeyCtrl) window->DrawList->AddRect(layout_r.Min, layout_r.Max, IM_COL32(255, 128, 0, 255)); // [DEBUG]
    RenderTextClipped(layout_r.Min, layout_r.Max, name, NULL, &text_size, style.WindowTitleAlign, &clip_r);
    if (flags & ImGuiWindowFlags_UnsavedDocument)
    {
        ImVec2 marker_pos = ImVec2(ImMax(layout_r.Min.x, layout_r.Min.x + (layout_r.GetWidth() - text_size.x) * style.WindowTitleAlign.x) + text_size.x, layout_r.Min.y) + ImVec2(2 - marker_size_x, 0.0f);
        ImVec2 off = ImVec2(0.0f, IM_FLOOR(-g.FontSize * 0.25f));
        RenderTextClipped(marker_pos + off, layout_r.Max + off, UNSAVED_DOCUMENT_MARKER, NULL, NULL, ImVec2(0, style.WindowTitleAlign.y), &clip_r);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq 0x139cee(%rip), %rax    # 0x212f40
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
addq $0x1560, %rax           # imm = 0x1560
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x34(%rbp)
cmpq $0x0, -0x20(%rbp)
setne %al
andb $0x1, %al
movb %al, -0x35(%rbp)
movl -0x34(%rbp), %ecx
andl $0x20, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xfd(%rbp)
jne 0xd929f
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x24(%rax)
setne %al
movb %al, -0xfd(%rbp)
movb -0xfd(%rbp), %al
andb $0x1, %al
movb %al, -0x36(%rbp)
movq -0x8(%rbp), %rax
movl 0x1cc(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl 0x1cc(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x1cc(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0x14c(%rax)
movq -0x30(%rbp), %rax
movss 0x38(%rax), %xmm0
movss %xmm0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movss 0x38(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x28(%rbp), %rax
movss 0x1980(%rax), %xmm0
movss %xmm0, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xe7de0
leaq -0x58(%rbp), %rdi
callq 0xe7de0
testb $0x1, -0x35(%rbp)
je 0xd935d
movss -0x48(%rbp), %xmm0
addss -0x44(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movss 0x8(%rax), %xmm0
subss -0x44(%rbp), %xmm0
movq -0x30(%rbp), %rax
subss 0x38(%rax), %xmm0
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm1
leaq -0x60(%rbp), %rdi
callq 0xbf4c0
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
testb $0x1, -0x36(%rbp)
je 0xd93ad
movq -0x30(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jne 0xd93ad
movss -0x48(%rbp), %xmm0
addss -0x44(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movss 0x8(%rax), %xmm0
subss -0x44(%rbp), %xmm0
movq -0x30(%rbp), %rax
subss 0x38(%rax), %xmm0
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm1
leaq -0x68(%rbp), %rdi
callq 0xbf4c0
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
testb $0x1, -0x36(%rbp)
je 0xd93fc
movq -0x30(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jne 0xd93fc
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
addss -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
subss 0x38(%rax), %xmm0
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm1
leaq -0x70(%rbp), %rdi
callq 0xbf4c0
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movss -0x48(%rbp), %xmm0
addss -0x40(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
testb $0x1, -0x36(%rbp)
je 0xd9434
movq -0x8(%rbp), %rdi
leaq 0x9d75f(%rip), %rsi     # 0x176b6c
xorl %eax, %eax
movl %eax, %edx
callq 0xc9910
movl %eax, %edi
leaq -0x58(%rbp), %rsi
callq 0x13b2a0
testb $0x1, %al
jne 0xd9427
jmp 0xd9432
movq -0x8(%rbp), %rax
movb $0x1, 0x92(%rax)
jmp 0xd9434
testb $0x1, -0x35(%rbp)
je 0xd9468
movq -0x8(%rbp), %rdi
leaq 0x9d731(%rip), %rsi     # 0x176b76
xorl %eax, %eax
movl %eax, %edx
callq 0xc9910
movl %eax, %edi
leaq -0x50(%rbp), %rsi
callq 0x13ae80
testb $0x1, %al
jne 0xd945f
jmp 0xd9466
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
jmp 0xd9468
movq -0x8(%rbp), %rax
movl $0x0, 0x14c(%rax)
movl -0x3c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1cc(%rax)
leaq 0x9cec8(%rip), %rax     # 0x176352
movq %rax, -0x78(%rbp)
movl -0x34(%rbp), %eax
andl $0x100000, %eax         # imm = 0x100000
cmpl $0x0, %eax
je 0xd94ca
movq -0x78(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
movss 0x98ad5(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movlpd %xmm0, -0x84(%rbp)
movss -0x84(%rbp), %xmm0
movss %xmm0, -0x104(%rbp)
jmp 0xd94d7
xorps %xmm0, %xmm0
movss %xmm0, -0x104(%rbp)
jmp 0xd94d7
movss -0x104(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
movss 0x98a87(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movlpd %xmm0, -0x94(%rbp)
movss -0x7c(%rbp), %xmm0
leaq -0x9c(%rbp), %rdi
movq %rdi, -0x110(%rbp)
xorps %xmm1, %xmm1
callq 0xbf4c0
movq -0x110(%rbp), %rsi
leaq -0x94(%rbp), %rdi
callq 0xc41b0
movlpd %xmm0, -0x8c(%rbp)
movss -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
ucomiss 0x38(%rax), %xmm0
jbe 0xd9561
movq -0x28(%rbp), %rax
movss 0x15b0(%rax), %xmm0
addss -0x40(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x44(%rbp), %xmm0
movq -0x30(%rbp), %rax
ucomiss 0x38(%rax), %xmm0
jbe 0xd9586
movq -0x28(%rbp), %rax
movss 0x15b0(%rax), %xmm0
addss -0x44(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x30(%rbp), %rax
movss 0x1c(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd9683
movq -0x30(%rbp), %rax
movss 0x97695(%rip), %xmm0    # 0x170c3c
ucomiss 0x1c(%rax), %xmm0
jbe 0xd9683
movq -0x30(%rbp), %rax
movss 0x1c(%rax), %xmm0
movss 0x98a16(%rip), %xmm1    # 0x171fd8
subss %xmm1, %xmm0
movaps 0x99233(%rip), %xmm1    # 0x172800
pand %xmm1, %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
addss %xmm0, %xmm0
movss 0x97652(%rip), %xmm1    # 0x170c3c
addss %xmm1, %xmm0
callq 0xc5aa0
movss %xmm0, -0xa0(%rbp)
movss -0x40(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
callq 0xc88c0
movss %xmm0, -0x114(%rbp)
movq -0x10(%rbp), %rdi
callq 0xeb840
movaps %xmm0, %xmm1
movss -0x114(%rbp), %xmm0
subss -0x40(%rbp), %xmm1
subss -0x44(%rbp), %xmm1
subss -0x8c(%rbp), %xmm1
callq 0xc4620
movss %xmm0, -0xa4(%rbp)
movss -0x40(%rbp), %xmm0
movss -0xa4(%rbp), %xmm1
mulss -0xa0(%rbp), %xmm1
callq 0xc88c0
movss %xmm0, -0x40(%rbp)
movss -0x44(%rbp), %xmm0
movss -0xa4(%rbp), %xmm1
mulss -0xa0(%rbp), %xmm1
callq 0xc88c0
movss %xmm0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
addss -0x40(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm1
movq -0x10(%rbp), %rax
movss 0x8(%rax), %xmm2
subss -0x44(%rbp), %xmm2
movq -0x10(%rbp), %rax
movss 0xc(%rax), %xmm3
leaq -0xb4(%rbp), %rdi
callq 0xec090
movss -0xb4(%rbp), %xmm0
movss -0xb0(%rbp), %xmm1
movss -0xac(%rbp), %xmm2
movq -0x28(%rbp), %rax
addss 0x15b0(%rax), %xmm2
movss -0xa8(%rbp), %xmm3
leaq -0xc4(%rbp), %rdi
callq 0xec090
leaq -0xb4(%rbp), %rdi
leaq -0xb4(%rbp), %rsi
addq $0x8, %rsi
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %r9
addq $0x1c, %r9
xorl %eax, %eax
movl %eax, %ecx
leaq -0x8c(%rbp), %r8
leaq -0xc4(%rbp), %rax
movq %rax, (%rsp)
callq 0xc8900
movl -0x34(%rbp), %eax
andl $0x100000, %eax         # imm = 0x100000
cmpl $0x0, %eax
je 0xd98c2
movss -0xb4(%rbp), %xmm0
movss %xmm0, -0x144(%rbp)
leaq -0xb4(%rbp), %rdi
callq 0xeb840
movaps %xmm0, %xmm1
movss -0x144(%rbp), %xmm0
movss -0x8c(%rbp), %xmm2
subss %xmm2, %xmm1
movq -0x30(%rbp), %rax
movss 0x1c(%rax), %xmm2
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
callq 0xc88c0
movss -0x8c(%rbp), %xmm1
addss %xmm1, %xmm0
movss -0xb0(%rbp), %xmm1
leaq -0xd4(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0xbf4c0
movss -0x7c(%rbp), %xmm1
movss 0x98811(%rip), %xmm0    # 0x171fcc
subss %xmm1, %xmm0
leaq -0xdc(%rbp), %rdi
movq %rdi, -0x138(%rbp)
xorps %xmm1, %xmm1
movss %xmm1, -0x12c(%rbp)
callq 0xbf4c0
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
callq 0xc41b0
movaps %xmm0, %xmm1
movss -0x12c(%rbp), %xmm0
movlpd %xmm1, -0xcc(%rbp)
movq -0x28(%rbp), %rax
movss 0x1980(%rax), %xmm1
movss 0x98fa5(%rip), %xmm2    # 0x1727bc
mulss %xmm2, %xmm1
cvttps2dq %xmm1, %xmm1
cvtdq2ps %xmm1, %xmm1
leaq -0xe4(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0xbf4c0
movq -0x128(%rbp), %rsi
leaq -0xcc(%rbp), %rdi
callq 0xc41b0
movq -0x128(%rbp), %rsi
movlpd %xmm0, -0xec(%rbp)
leaq -0xac(%rbp), %rdi
callq 0xc41b0
movlpd %xmm0, -0xf4(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x30(%rbp), %rax
movss 0x20(%rax), %xmm1
leaq -0xfc(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xbf4c0
movq -0x120(%rbp), %rdx
leaq -0xec(%rbp), %rdi
leaq -0xf4(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r8d
leaq -0xfc(%rbp), %r9
leaq -0xc4(%rbp), %rax
movq %r8, %rcx
movq %rax, (%rsp)
callq 0xc8900
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopl (%rax,%rax)