// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movl 0x4(%rdi), %edx
testb $0x8, %dl
je 0x8c647
movl 0x6c(%rdi), %eax
movl $0x1, %esi
testl %eax, %eax
jle 0x8c43e
movq 0x10(%rdi), %r9
xorl %ecx, %ecx
movq %rax, %r10
xorl %r8d, %r8d
cmpq 0x18(%rdi), %r9
jae 0x8c5ea
movsbq 0x56(%r9), %r11
cmpq $-0x1, %r11
je 0x8c430
cmpb $0x0, 0x5a(%r9)
je 0x8c42b
cmpl $0x3f, %ecx
jge 0x8c628
incl %ecx
btsq %r11, %r8
jmp 0x8c430
movb $-0x1, 0x56(%r9)
addq $0x68, %r9
decq %r10
jne 0x8c3fe
incq %r8
jmp 0x8c446
xorl %ecx, %ecx
movl $0x1, %r8d
shlq %cl, %rsi
cmpq %r8, %rsi
sete %r8b
cmpl $0x2, %ecx
setge %r9b
btl $0x1a, %edx
setae %sil
andb %r9b, %sil
movl %esi, %r9d
xorb $0x1, %r9b
andb %r8b, %r9b
testl %ecx, %ecx
setle %r8b
orb %r9b, %r8b
jne 0x8c53b
xorl %r8d, %r8d
xorl %r9d, %r9d
testl %eax, %eax
jle 0x8c609
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl $0x56, %r11d
xorl %ebx, %ebx
btq %rbx, %r9
jb 0x8c4eb
movq 0x10(%rdi), %r14
movq 0x18(%rdi), %r15
leaq (%r14,%r11), %r12
addq $-0x56, %r12
cmpq %r15, %r12
jae 0x8c5ea
movb (%r14,%r11), %r12b
cmpb $-0x1, %r12b
je 0x8c4eb
cmpl $-0x1, %r10d
je 0x8c4e8
testl %r10d, %r10d
js 0x8c5ea
movslq %r10d, %r13
imulq $0x68, %r13, %r13
addq %r13, %r14
cmpq %r15, %r14
jae 0x8c5ea
cmpb 0x56(%r14), %r12b
jge 0x8c4eb
movl %ebx, %r10d
incq %rbx
addq $0x68, %r11
cmpq %rbx, %rax
jne 0x8c497
cmpl $-0x1, %r10d
je 0x8c609
testl %r10d, %r10d
js 0x8c5ea
movq 0x10(%rdi), %r11
movslq %r10d, %rbx
imulq $0x68, %rbx, %rbx
addq %r11, %rbx
cmpq 0x18(%rdi), %rbx
jae 0x8c5ea
movb %r8b, 0x56(%rbx)
testb %sil, %sil
jne 0x8c57e
btsq %r10, %r9
incl %r8d
cmpl %ecx, %r8d
jl 0x8c481
testl %ecx, %ecx
jne 0x8c5d5
testl %eax, %eax
setle %sil
shrl $0x1b, %edx
andl $0x1, %edx
xorl %ecx, %ecx
orb %sil, %dl
jne 0x8c5d5
movq 0x10(%rdi), %rdx
movq 0x18(%rdi), %rsi
cmpq %rsi, %rdx
jae 0x8c5ea
cmpb $0x1, 0x5a(%rdx)
jne 0x8c573
testb $0x1, 0x1(%rdx)
je 0x8c5b4
addq $0x68, %rdx
decq %rax
jne 0x8c55e
jmp 0x8c5d5
movl $0x1, %ecx
testl %eax, %eax
jle 0x8c5d5
movl %r10d, %edx
imulq $0x68, %rdx, %rdx
imulq $0x68, %rax, %rax
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x8c5a9
leaq (%r11,%rsi), %r8
cmpq 0x18(%rdi), %r8
jae 0x8c5ea
movb $-0x1, 0x56(%r11,%rsi)
addq $0x68, %rsi
cmpq %rsi, %rax
jne 0x8c594
jmp 0x8c5d5
movb $0x0, 0x56(%rdx)
movb 0x64(%rdx), %al
testb $0xc, %al
je 0x8c666
movb 0x65(%rdx), %cl
andb $0x3, %cl
andb $-0x4, %al
orb %cl, %al
movb %al, 0x64(%rdx)
movl $0x1, %ecx
movb %cl, 0x230(%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2e0c7(%rip), %rdi     # 0xba6b8
leaq 0x2d047(%rip), %rsi     # 0xb963f
leaq 0x2e0d2(%rip), %rcx     # 0xba6d1
movl $0x20e, %edx            # imm = 0x20E
callq 0xc140
leaq 0x437fb(%rip), %rdi     # 0xcfe0b
leaq 0x42873(%rip), %rsi     # 0xcee8a
leaq 0x43788(%rip), %rcx     # 0xcfda6
movl $0xa32, %edx            # imm = 0xA32
callq 0xc140
leaq 0x437a8(%rip), %rdi     # 0xcfdd7
leaq 0x42854(%rip), %rsi     # 0xcee8a
leaq 0x43769(%rip), %rcx     # 0xcfda6
movl $0xa21, %edx            # imm = 0xA21
callq 0xc140
leaq 0x43730(%rip), %rdi     # 0xcfd7e
leaq 0x42835(%rip), %rsi     # 0xcee8a
leaq 0x4374a(%rip), %rcx     # 0xcfda6
movl $0xa13, %edx            # imm = 0xA13
callq 0xc140
leaq 0x44194(%rip), %rdi     # 0xd0801
leaq 0x42816(%rip), %rsi     # 0xcee8a
leaq 0x441ab(%rip), %rcx     # 0xd0826
movl $0x9d1, %edx            # imm = 0x9D1
callq 0xc140