// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui_tables.cpp
// Function: ImGui::TableSortSpecsSanitize(ImGuiTable*)
void ImGui::TableSortSpecsSanitize(ImGuiTable* table)
{
    IM_ASSERT(table->Flags & ImGuiTableFlags_Sortable);

    // Clear SortOrder from hidden column and verify that there's no gap or duplicate.
    int sort_order_count = 0;
    ImU64 sort_order_mask = 0x00;
    for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
    {
        ImGuiTableColumn* column = &table->Columns[column_n];
        if (column->SortOrder != -1 && !column->IsEnabled)
            column->SortOrder = -1;
        if (column->SortOrder == -1)
            continue;
        sort_order_count++;
        sort_order_mask |= ((ImU64)1 << column->SortOrder);
        IM_ASSERT(sort_order_count < (int)sizeof(sort_order_mask) * 8);
    }

    const bool need_fix_linearize = ((ImU64)1 << sort_order_count) != (sort_order_mask + 1);
    const bool need_fix_single_sort_order = (sort_order_count > 1) && !(table->Flags & ImGuiTableFlags_SortMulti);
    if (need_fix_linearize || need_fix_single_sort_order)
    {
        ImU64 fixed_mask = 0x00;
        for (int sort_n = 0; sort_n < sort_order_count; sort_n++)
        {
            // Fix: Rewrite sort order fields if needed so they have no gap or duplicate.
            // (e.g. SortOrder 0 disappeared, SortOrder 1..2 exists --> rewrite then as SortOrder 0..1)
            int column_with_smallest_sort_order = -1;
            for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
                if ((fixed_mask & ((ImU64)1 << (ImU64)column_n)) == 0 && table->Columns[column_n].SortOrder != -1)
                    if (column_with_smallest_sort_order == -1 || table->Columns[column_n].SortOrder < table->Columns[column_with_smallest_sort_order].SortOrder)
                        column_with_smallest_sort_order = column_n;
            IM_ASSERT(column_with_smallest_sort_order != -1);
            fixed_mask |= ((ImU64)1 << column_with_smallest_sort_order);
            table->Columns[column_with_smallest_sort_order].SortOrder = (ImGuiTableColumnIdx)sort_n;

            // Fix: Make sure only one column has a SortOrder if ImGuiTableFlags_MultiSortable is not set.
            if (need_fix_single_sort_order)
            {
                sort_order_count = 1;
                for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
                    if (column_n != column_with_smallest_sort_order)
                        table->Columns[column_n].SortOrder = -1;
                break;
            }
        }
    }

    // Fallback default sort order (if no column had the ImGuiTableColumnFlags_DefaultSort flag)
    if (sort_order_count == 0 && !(table->Flags & ImGuiTableFlags_SortTristate))
        for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
        {
            ImGuiTableColumn* column = &table->Columns[column_n];
            if (column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_NoSort))
            {
                sort_order_count = 1;
                column->SortOrder = 0;
                column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0);
                break;
            }
        }

    table->SortSpecsCount = (ImGuiTableColumnIdx)sort_order_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testb $0x8, 0x4(%rdi)
je 0x75a0b
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, -0x30(%rbp)
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpl 0x6c(%rbx), %r12d
jge 0x7584a
movq -0x30(%rbp), %rdi
movl %r12d, %esi
callq 0x4c4c6
movsbq 0x56(%rax), %rcx
cmpq $-0x1, %rcx
je 0x75845
cmpb $0x0, 0x5a(%rax)
je 0x75841
cmpl $0x3f, %r15d
jge 0x759cd
incl %r15d
btsq %rcx, %r14
jmp 0x75845
movb $-0x1, 0x56(%rax)
incl %r12d
jmp 0x7580b
pushq $0x1
popq %rax
movl %r15d, %ecx
shlq %cl, %rax
incq %r14
cmpl $0x1, %r15d
jle 0x75865
testb $0x4, 0x7(%rbx)
sete %cl
jmp 0x75867
xorl %ecx, %ecx
cmpq %r14, %rax
setne %al
orb %cl, %al
testb $0x1, %al
je 0x75933
xorl %r14d, %r14d
xorl %eax, %eax
movl %r15d, -0x38(%rbp)
movl %ecx, -0x34(%rbp)
cmpl %r15d, %eax
jge 0x75933
movl %eax, -0x3c(%rbp)
xorl %r13d, %r13d
pushq $-0x1
popq %rax
movl %eax, %r12d
movq %r14, -0x48(%rbp)
movslq 0x6c(%rbx), %rax
cmpq %rax, %r13
jge 0x758ff
btq %r13, %r14
jb 0x758fa
movq -0x30(%rbp), %rdi
movl %r13d, %esi
callq 0x4c4c6
cmpb $-0x1, 0x56(%rax)
je 0x758fa
cmpl $-0x1, %r12d
je 0x758f7
movq %r12, %r14
movq %rbx, %r12
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4c4c6
movb 0x56(%rax), %r15b
movq %rbx, %rdi
movq %r12, %rbx
movq %r14, %r12
movq -0x48(%rbp), %r14
movl %r12d, %esi
callq 0x4c4c6
cmpb 0x56(%rax), %r15b
jge 0x758fa
movl %r13d, %r12d
incq %r13
jmp 0x7589c
cmpl $-0x1, %r12d
je 0x759ec
movq -0x30(%rbp), %rdi
movl %r12d, %esi
callq 0x4c4c6
movl -0x3c(%rbp), %ecx
movb %cl, 0x56(%rax)
movl %ecx, %eax
movl -0x34(%rbp), %ecx
testb %cl, %cl
movl -0x38(%rbp), %r15d
jne 0x75970
btsq %r12, %r14
incl %eax
jmp 0x75883
testl %r15d, %r15d
jne 0x759b7
xorl %r15d, %r15d
testb $0x8, 0x7(%rbx)
jne 0x759b7
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpl 0x6c(%rbx), %r12d
jge 0x759b7
movq -0x30(%rbp), %rdi
movl %r12d, %esi
callq 0x4c4c6
cmpb $0x1, 0x5a(%rax)
jne 0x75968
movq %rax, %r13
testb $0x1, 0x1(%rax)
je 0x75997
incl %r12d
xorl %r15d, %r15d
jmp 0x75947
xorl %r13d, %r13d
pushq $0x1
popq %r15
cmpl 0x6c(%rbx), %r13d
jge 0x759b7
cmpl %r13d, %r12d
je 0x75992
movq -0x30(%rbp), %rdi
movl %r13d, %esi
callq 0x4c4c6
movb $-0x1, 0x56(%rax)
incl %r13d
jmp 0x75977
movb $0x0, 0x56(%r13)
movq %r13, %rdi
xorl %esi, %esi
callq 0x755c4
movb 0x64(%r13), %cl
andb $-0x4, %cl
orb %al, %cl
movb %cl, 0x64(%r13)
pushq $0x1
popq %r15
movb %r15b, 0x230(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4167f(%rip), %rdi     # 0xb7053
leaq 0x4072b(%rip), %rsi     # 0xb6106
leaq 0x41640(%rip), %rcx     # 0xb7022
movl $0xa21, %edx            # imm = 0xA21
callq 0xc140
leaq 0x41694(%rip), %rdi     # 0xb7087
leaq 0x4070c(%rip), %rsi     # 0xb6106
leaq 0x41621(%rip), %rcx     # 0xb7022
movl $0xa32, %edx            # imm = 0xA32
callq 0xc140
leaq 0x415e8(%rip), %rdi     # 0xb6ffa
leaq 0x406ed(%rip), %rsi     # 0xb6106
leaq 0x41602(%rip), %rcx     # 0xb7022
movl $0xa13, %edx            # imm = 0xA13
callq 0xc140