// File: Ciaxur[P]yagb-emu/include/imgui/imgui_tables.cpp
// Function: ImGui::TableDrawBorders(ImGuiTable*)
void ImGui::TableDrawBorders(ImGuiTable* table)
{
    ImGuiWindow* inner_window = table->InnerWindow;
    if (!table->OuterWindow->ClipRect.Overlaps(table->OuterRect))
        return;

    ImDrawList* inner_drawlist = inner_window->DrawList;
    table->DrawSplitter.SetCurrentChannel(inner_drawlist, TABLE_DRAW_CHANNEL_BG0);
    inner_drawlist->PushClipRect(table->Bg0ClipRectForDrawCmd.Min, table->Bg0ClipRectForDrawCmd.Max, false);

    // Draw inner border and resizing feedback
    const float border_size = TABLE_BORDER_SIZE;
    const float draw_y1 = table->InnerRect.Min.y;
    const float draw_y2_body = table->InnerRect.Max.y;
    const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->LastFirstRowHeight) : draw_y1;
    if (table->Flags & ImGuiTableFlags_BordersInnerV)
    {
        for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
        {
            if (!(table->EnabledMaskByDisplayOrder & ((ImU64)1 << order_n)))
                continue;

            const int column_n = table->DisplayOrderToIndex[order_n];
            ImGuiTableColumn* column = &table->Columns[column_n];
            const bool is_hovered = (table->HoveredColumnBorder == column_n);
            const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent);
            const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0;
            const bool is_frozen_separator = (table->FreezeColumnsCount != -1 && table->FreezeColumnsCount == order_n + 1);
            if (column->MaxX > table->InnerClipRect.Max.x && !is_resized)
                continue;

            // Decide whether right-most column is visible
            if (column->NextEnabledColumn == -1 && !is_resizable)
                if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || (table->Flags & ImGuiTableFlags_NoHostExtendX))
                    continue;
            if (column->MaxX <= column->ClipRect.Min.x) // FIXME-TABLE FIXME-STYLE: Assume BorderSize==1, this is problematic if we want to increase the border size..
                continue;

            // Draw in outer window so right-most column won't be clipped
            // Always draw full height border when being resized/hovered, or on the delimitation of frozen column scrolling.
            ImU32 col;
            float draw_y2;
            if (is_hovered || is_resized || is_frozen_separator)
            {
                draw_y2 = draw_y2_body;
                col = is_resized ? GetColorU32(ImGuiCol_SeparatorActive) : is_hovered ? GetColorU32(ImGuiCol_SeparatorHovered) : table->BorderColorStrong;
            }
            else
            {
                draw_y2 = (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)) ? draw_y2_head : draw_y2_body;
                col = (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)) ? table->BorderColorStrong : table->BorderColorLight;
            }

            if (draw_y2 > draw_y1)
                inner_drawlist->AddLine(ImVec2(column->MaxX, draw_y1), ImVec2(column->MaxX, draw_y2), col, border_size);
        }
    }

    // Draw outer border
    // FIXME: could use AddRect or explicit VLine/HLine helper?
    if (table->Flags & ImGuiTableFlags_BordersOuter)
    {
        // Display outer border offset by 1 which is a simple way to display it without adding an extra draw call
        // (Without the offset, in outer_window it would be rendered behind cells, because child windows are above their
        // parent. In inner_window, it won't reach out over scrollbars. Another weird solution would be to display part
        // of it in inner window, and the part that's over scrollbars in the outer window..)
        // Either solution currently won't allow us to use a larger border size: the border would clipped.
        const ImRect outer_border = table->OuterRect;
        const ImU32 outer_col = table->BorderColorStrong;
        if ((table->Flags & ImGuiTableFlags_BordersOuter) == ImGuiTableFlags_BordersOuter)
        {
            inner_drawlist->AddRect(outer_border.Min, outer_border.Max, outer_col, 0.0f, ~0, border_size);
        }
        else if (table->Flags & ImGuiTableFlags_BordersOuterV)
        {
            inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Min.x, outer_border.Max.y), outer_col, border_size);
            inner_drawlist->AddLine(ImVec2(outer_border.Max.x, outer_border.Min.y), outer_border.Max, outer_col, border_size);
        }
        else if (table->Flags & ImGuiTableFlags_BordersOuterH)
        {
            inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Max.x, outer_border.Min.y), outer_col, border_size);
            inner_drawlist->AddLine(ImVec2(outer_border.Min.x, outer_border.Max.y), outer_border.Max, outer_col, border_size);
        }
    }
    if ((table->Flags & ImGuiTableFlags_BordersInnerH) && table->RowPosY2 < table->OuterRect.Max.y)
    {
        // Draw bottom-most row border
        const float border_y = table->RowPosY2;
        if (border_y >= table->BgClipRect.Min.y && border_y < table->BgClipRect.Max.y)
            inner_drawlist->AddLine(ImVec2(table->BorderX1, border_y), ImVec2(table->BorderX2, border_y), table->BorderColorLight, border_size);
    }

    inner_drawlist->PopClipRect();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x1d0(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x1c8(%rax), %rdi
addq $0x258, %rdi            # imm = 0x258
movq -0x8(%rbp), %rsi
addq $0xec, %rsi
callq 0xe9420
testb $0x1, %al
jne 0x12f499
jmp 0x12fba6
movq -0x10(%rbp), %rax
movq 0x2b8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x115220
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x13c(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x144(%rax), %rax
movq %rax, -0x28(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
xorl %esi, %esi
callq 0x10f4f0
movss 0x41743(%rip), %xmm0    # 0x170c3c
movss %xmm0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movss 0x100(%rax), %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movss 0x108(%rax), %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x24c(%rax)
je 0x12f5a6
movq -0x8(%rbp), %rax
movss 0x108(%rax), %xmm0
movss %xmm0, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movsbl 0x241(%rax), %eax
cmpl $0x1, %eax
jl 0x12f567
movq -0x8(%rbp), %rax
movss 0x100(%rax), %xmm0
movss %xmm0, -0xb4(%rbp)
jmp 0x12f57b
movq -0x8(%rbp), %rax
movss 0x110(%rax), %xmm0
movss %xmm0, -0xb4(%rbp)
movss -0xb0(%rbp), %xmm0
movss -0xb4(%rbp), %xmm1
movq -0x8(%rbp), %rax
addss 0xd0(%rax), %xmm1
callq 0x12a6b0
movss %xmm0, -0xb8(%rbp)
jmp 0x12f5b3
movss -0x30(%rbp), %xmm0
movss %xmm0, -0xb8(%rbp)
movss -0xb8(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x12f8cc
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x12f8ca
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x3c(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x12f610
jmp 0x12f8bc
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movl -0x3c(%rbp), %esi
callq 0x1370a0
movsbl (%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movl -0x40(%rbp), %esi
callq 0xeea20
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movsbl 0x235(%rax), %eax
cmpl -0x40(%rbp), %eax
sete %al
andb $0x1, %al
movb %al, -0x49(%rbp)
movq -0x8(%rbp), %rax
movsbl 0x237(%rax), %ecx
xorl %eax, %eax
cmpl -0x40(%rbp), %ecx
movb %al, -0xb9(%rbp)
jne 0x12f683
movq -0x8(%rbp), %rax
movswl 0x7a(%rax), %eax
movq -0x8(%rbp), %rcx
movswl 0x78(%rcx), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %al
andb $0x1, %al
movb %al, -0x4a(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %eax
andl $0x40000010, %eax       # imm = 0x40000010
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0x4b(%rbp)
movq -0x8(%rbp), %rax
movsbl 0x243(%rax), %ecx
xorl %eax, %eax
cmpl $-0x1, %ecx
movb %al, -0xba(%rbp)
je 0x12f6d8
movq -0x8(%rbp), %rax
movsbl 0x243(%rax), %eax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0xba(%rbp)
movb -0xba(%rbp), %al
andb $0x1, %al
movb %al, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x8(%rbp), %rax
ucomiss 0x124(%rax), %xmm0
jbe 0x12f704
testb $0x1, -0x4a(%rbp)
jne 0x12f704
jmp 0x12f8bc
movq -0x48(%rbp), %rax
movsbl 0x55(%rax), %eax
cmpl $-0x1, %eax
jne 0x12f742
testb $0x1, -0x4b(%rbp)
jne 0x12f742
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0xe000, %eax           # imm = 0xE000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x12f73b
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x12f740
jmp 0x12f8bc
jmp 0x12f742
movq -0x48(%rbp), %rax
movss 0xc(%rax), %xmm1
movq -0x48(%rbp), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x12f75e
jmp 0x12f8bc
testb $0x1, -0x49(%rbp)
jne 0x12f770
testb $0x1, -0x4a(%rbp)
jne 0x12f770
testb $0x1, -0x4c(%rbp)
je 0x12f7e1
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
testb $0x1, -0x4a(%rbp)
je 0x12f79a
movl $0x1d, %edi
movss 0x414af(%rip), %xmm0    # 0x170c3c
callq 0xc76e0
movl %eax, -0xc0(%rbp)
jmp 0x12f7d6
testb $0x1, -0x49(%rbp)
je 0x12f7ba
movl $0x1c, %edi
movss 0x4148f(%rip), %xmm0    # 0x170c3c
callq 0xc76e0
movl %eax, -0xc4(%rbp)
jmp 0x12f7ca
movq -0x8(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x12f857
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1800, %eax           # imm = 0x1800
cmpl $0x0, %eax
je 0x12f801
movss -0x38(%rbp), %xmm0
movss %xmm0, -0xc8(%rbp)
jmp 0x12f80e
movss -0x34(%rbp), %xmm0
movss %xmm0, -0xc8(%rbp)
movss -0xc8(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1800, %eax           # imm = 0x1800
cmpl $0x0, %eax
je 0x12f83e
movq -0x8(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0xcc(%rbp)
jmp 0x12f84e
movq -0x8(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x50(%rbp)
movss -0x54(%rbp), %xmm0
ucomiss -0x30(%rbp), %xmm0
jbe 0x12f8ba
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x48(%rbp), %rax
movss 0xc(%rax), %xmm0
movss -0x30(%rbp), %xmm1
leaq -0x5c(%rbp), %rdi
callq 0xbf4c0
movq -0x48(%rbp), %rax
movss 0xc(%rax), %xmm0
movss -0x54(%rbp), %xmm1
leaq -0x64(%rbp), %rdi
callq 0xbf4c0
movq -0xd8(%rbp), %rdi
movl -0x50(%rbp), %ecx
leaq -0x5c(%rbp), %rsi
leaq -0x64(%rbp), %rdx
movss 0x41387(%rip), %xmm0    # 0x170c3c
callq 0x112e20
jmp 0x12f8bc
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x12f5dc
jmp 0x12f8cc
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x500, %eax            # imm = 0x500
cmpl $0x0, %eax
je 0x12faa8
movq -0x8(%rbp), %rax
movq 0xec(%rax), %rcx
movq %rcx, -0x74(%rbp)
movq 0xf4(%rax), %rax
movq %rax, -0x6c(%rbp)
movq -0x8(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x500, %eax            # imm = 0x500
cmpl $0x500, %eax            # imm = 0x500
jne 0x12f949
movq -0x18(%rbp), %rdi
leaq -0x74(%rbp), %rsi
leaq -0x74(%rbp), %rdx
addq $0x8, %rdx
movl -0x78(%rbp), %ecx
xorps %xmm0, %xmm0
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movss 0x412fd(%rip), %xmm1    # 0x170c3c
callq 0x112ef0
jmp 0x12faa6
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x12f9f5
movq -0x18(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x74(%rbp), %rax
movq %rax, -0xe8(%rbp)
movss -0x74(%rbp), %xmm0
movss -0x68(%rbp), %xmm1
leaq -0x80(%rbp), %rdi
callq 0xbf4c0
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movl -0x78(%rbp), %ecx
leaq -0x80(%rbp), %rdx
movss 0x41298(%rip), %xmm0    # 0x170c3c
callq 0x112e20
movq -0x18(%rbp), %rax
movq %rax, -0xe0(%rbp)
movss -0x6c(%rbp), %xmm0
movss -0x70(%rbp), %xmm1
leaq -0x88(%rbp), %rdi
callq 0xbf4c0
movq -0xe0(%rbp), %rdi
leaq -0x74(%rbp), %rdx
addq $0x8, %rdx
movl -0x78(%rbp), %ecx
leaq -0x88(%rbp), %rsi
movss 0x41251(%rip), %xmm0    # 0x170c3c
callq 0x112e20
jmp 0x12faa4
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x12faa2
movq -0x18(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x74(%rbp), %rax
movq %rax, -0x100(%rbp)
movss -0x6c(%rbp), %xmm0
movss -0x70(%rbp), %xmm1
leaq -0x90(%rbp), %rdi
callq 0xbf4c0
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movl -0x78(%rbp), %ecx
leaq -0x90(%rbp), %rdx
movss 0x411e6(%rip), %xmm0    # 0x170c3c
callq 0x112e20
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
movss -0x74(%rbp), %xmm0
movss -0x68(%rbp), %xmm1
leaq -0x98(%rbp), %rdi
callq 0xbf4c0
movq -0xf8(%rbp), %rdi
leaq -0x74(%rbp), %rdx
addq $0x8, %rdx
movl -0x78(%rbp), %ecx
leaq -0x98(%rbp), %rsi
movss 0x4119f(%rip), %xmm0    # 0x170c3c
callq 0x112e20
jmp 0x12faa4
jmp 0x12faa6
jmp 0x12faa8
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x12fb9d
movq -0x8(%rbp), %rax
movss 0x80(%rax), %xmm1
movq -0x8(%rbp), %rax
movss 0xf8(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x12fb9d
movq -0x8(%rbp), %rax
movss 0x80(%rax), %xmm0
movss %xmm0, -0x9c(%rbp)
movss -0x9c(%rbp), %xmm0
movq -0x8(%rbp), %rax
ucomiss 0x130(%rax), %xmm0
jb 0x12fb9b
movss -0x9c(%rbp), %xmm1
movq -0x8(%rbp), %rax
movss 0x138(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x12fb9b
movq -0x18(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x8(%rbp), %rax
movss 0xa8(%rax), %xmm0
movss -0x9c(%rbp), %xmm1
leaq -0xa4(%rbp), %rdi
callq 0xbf4c0
movq -0x8(%rbp), %rax
movss 0xac(%rax), %xmm0
movss -0x9c(%rbp), %xmm1
leaq -0xac(%rbp), %rdi
callq 0xbf4c0
movq -0x110(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0xa4(%rax), %ecx
leaq -0xa4(%rbp), %rsi
leaq -0xac(%rbp), %rdx
movss 0x410a6(%rip), %xmm0    # 0x170c3c
callq 0x112e20
jmp 0x12fb9d
movq -0x18(%rbp), %rdi
callq 0x10f6c0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nop