// File: Ciaxur[P]yagb-emu/include/imgui/imgui_tables.cpp
// Function: ImGui::TableDrawContextMenu(ImGuiTable*)
void ImGui::TableDrawContextMenu(ImGuiTable* table)
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = g.CurrentWindow;
    if (window->SkipItems)
        return;

    bool want_separator = false;
    const int column_n = (table->ContextPopupColumn >= 0 && table->ContextPopupColumn < table->ColumnsCount) ? table->ContextPopupColumn : -1;
    ImGuiTableColumn* column = (column_n != -1) ? &table->Columns[column_n] : NULL;

    // Sizing
    if (table->Flags & ImGuiTableFlags_Resizable)
    {
        if (column != NULL)
        {
            const bool can_resize = !(column->Flags & ImGuiTableColumnFlags_NoResize) && column->IsEnabled;
            if (MenuItem("Size column to fit###SizeOne", NULL, false, can_resize))
                TableSetColumnWidthAutoSingle(table, column_n);
        }

        const char* size_all_desc;
        if (table->ColumnsEnabledFixedCount == table->ColumnsEnabledCount && (table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame)
            size_all_desc = "Size all columns to fit###SizeAll";        // All fixed
        else
            size_all_desc = "Size all columns to default###SizeAll";    // All stretch or mixed
        if (MenuItem(size_all_desc, NULL))
            TableSetColumnWidthAutoAll(table);
        want_separator = true;
    }

    // Ordering
    if (table->Flags & ImGuiTableFlags_Reorderable)
    {
        if (MenuItem("Reset order", NULL, false, !table->IsDefaultDisplayOrder))
            table->IsResetDisplayOrderRequest = true;
        want_separator = true;
    }

    // Reset all (should work but seems unnecessary/noisy to expose?)
    //if (MenuItem("Reset all"))
    //    table->IsResetAllRequest = true;

    // Sorting
    // (modify TableOpenContextMenu() to add _Sortable flag if enabling this)
#if 0
    if ((table->Flags & ImGuiTableFlags_Sortable) && column != NULL && (column->Flags & ImGuiTableColumnFlags_NoSort) == 0)
    {
        if (want_separator)
            Separator();
        want_separator = true;

        bool append_to_sort_specs = g.IO.KeyShift;
        if (MenuItem("Sort in Ascending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Ascending, (column->Flags & ImGuiTableColumnFlags_NoSortAscending) == 0))
            TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Ascending, append_to_sort_specs);
        if (MenuItem("Sort in Descending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Descending, (column->Flags & ImGuiTableColumnFlags_NoSortDescending) == 0))
            TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Descending, append_to_sort_specs);
    }
#endif

    // Hiding / Visibility
    if (table->Flags & ImGuiTableFlags_Hideable)
    {
        if (want_separator)
            Separator();
        want_separator = true;

        PushItemFlag(ImGuiItemFlags_SelectableDontClosePopup, true);
        for (int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++)
        {
            ImGuiTableColumn* other_column = &table->Columns[other_column_n];
            const char* name = TableGetColumnName(table, other_column_n);
            if (name == NULL || name[0] == 0)
                name = "<Unknown>";

            // Make sure we can't hide the last active column
            bool menu_item_active = (other_column->Flags & ImGuiTableColumnFlags_NoHide) ? false : true;
            if (other_column->IsEnabled && table->ColumnsEnabledCount <= 1)
                menu_item_active = false;
            if (MenuItem(name, NULL, other_column->IsEnabled, menu_item_active))
                other_column->IsEnabledNextFrame = !other_column->IsEnabled;
        }
        PopItemFlag();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
leaq 0xe58ad(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x1ae0(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
testb $0x1, 0x93(%rax)
je 0x12d6bb
jmp 0x12d960
movb $0x0, -0x19(%rbp)
movq -0x8(%rbp), %rax
movsbl 0x23f(%rax), %eax
cmpl $0x0, %eax
jl 0x12d6f3
movq -0x8(%rbp), %rax
movsbl 0x23f(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x12d6f3
movq -0x8(%rbp), %rax
movsbl 0x23f(%rax), %eax
movl %eax, -0x58(%rbp)
jmp 0x12d6fd
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x58(%rbp)
jmp 0x12d6fd
movl -0x58(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
je 0x12d71f
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movl -0x20(%rbp), %esi
callq 0xeea20
movq %rax, -0x60(%rbp)
jmp 0x12d727
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x12d727
movq -0x60(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x12d808
cmpq $0x0, -0x28(%rbp)
je 0x12d79c
movq -0x28(%rbp), %rax
movl (%rax), %ecx
andl $0x10, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x61(%rbp)
jne 0x12d766
movq -0x28(%rbp), %rax
movb 0x5a(%rax), %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
leaq 0x5fbf2(%rip), %rdi     # 0x18d36a
xorl %ecx, %ecx
movl %ecx, %esi
xorl %edx, %edx
andb $0x1, %al
movzbl %al, %ecx
callq 0x155360
testb $0x1, %al
jne 0x12d78e
jmp 0x12d79a
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x12dbf0
jmp 0x12d79c
movq -0x8(%rbp), %rax
movsbl 0x232(%rax), %eax
movq -0x8(%rbp), %rcx
movsbl 0x231(%rcx), %ecx
cmpl %ecx, %eax
jne 0x12d7d6
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0xe000, %eax           # imm = 0xE000
cmpl $0x4000, %eax           # imm = 0x4000
je 0x12d7d6
leaq 0x5fbb7(%rip), %rax     # 0x18d387
movq %rax, -0x38(%rbp)
jmp 0x12d7e1
leaq 0x5fbcc(%rip), %rax     # 0x18d3a9
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x155360
testb $0x1, %al
jne 0x12d7fb
jmp 0x12d804
movq -0x8(%rbp), %rdi
callq 0x132020
movb $0x1, -0x19(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12d852
movq -0x8(%rbp), %rax
movb 0x250(%rax), %al
xorb $-0x1, %al
xorl %ecx, %ecx
xorl %ecx, %ecx
movzbl %al, %ecx
andl $0x1, %ecx
leaq 0x5fb9b(%rip), %rdi     # 0x18d3cf
xorl %edx, %edx
movl %edx, %esi
callq 0x155360
testb $0x1, %al
jne 0x12d843
jmp 0x12d84e
movq -0x8(%rbp), %rax
movb $0x1, 0x252(%rax)
movb $0x1, -0x19(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x12d960
testb $0x1, -0x19(%rbp)
je 0x12d870
callq 0x13dec0
movb $0x1, -0x19(%rbp)
movl $0x20, %edi
movl $0x1, %esi
callq 0xda0f0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x12d95b
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movl -0x3c(%rbp), %esi
callq 0xeea20
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x1310c0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x12d8d1
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x12d8dc
leaq 0x5fb03(%rip), %rax     # 0x18d3db
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movb (%rax), %cl
andb $0x40, %cl
xorl %eax, %eax
subb $0x1, %cl
sbbl %eax, %eax
andb $0x1, %al
movb %al, -0x51(%rbp)
movq -0x48(%rbp), %rax
testb $0x1, 0x5a(%rax)
je 0x12d90f
movq -0x8(%rbp), %rax
movsbl 0x231(%rax), %eax
cmpl $0x1, %eax
jg 0x12d90f
movb $0x0, -0x51(%rbp)
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rax
movb 0x5a(%rax), %cl
movb -0x51(%rbp), %al
xorl %edx, %edx
movl %edx, %esi
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x155360
testb $0x1, %al
jne 0x12d937
jmp 0x12d94b
movq -0x48(%rbp), %rax
movb 0x5a(%rax), %cl
xorb $-0x1, %cl
movq -0x48(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x5b(%rax)
jmp 0x12d94d
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x12d88a
callq 0xda1b0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)