// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movl 0x4(%rdi), %r11d
testb $0x8, %r11b
je 0x8e398
movslq 0x6c(%rdi), %rbx
movl $0x1, %esi
testq %rbx, %rbx
jle 0x8e158
movq 0x10(%rdi), %r9
xorl %ecx, %ecx
movq %rbx, %r10
xorl %r8d, %r8d
cmpq 0x18(%rdi), %r9
jae 0x8e33b
cmpb $-0x1, 0x56(%r9)
je 0x8e130
cmpb $0x0, 0x5a(%r9)
jne 0x8e130
movb $-0x1, 0x56(%r9)
movsbq 0x56(%r9), %rax
cmpq $-0x1, %rax
je 0x8e14a
cmpl $0x3f, %ecx
jge 0x8e379
incl %ecx
btsq %rax, %r8
addq $0x68, %r9
decq %r10
jne 0x8e113
incq %r8
jmp 0x8e160
xorl %ecx, %ecx
movl $0x1, %r8d
shlq %cl, %rsi
cmpq %r8, %rsi
sete %al
cmpl $0x2, %ecx
setge %dl
movl %r11d, -0x30(%rbp)
btl $0x1a, %r11d
setae %sil
andb %dl, %sil
movl %esi, %edx
xorb $0x1, %dl
andb %al, %dl
testl %ecx, %ecx
setle %al
orb %dl, %al
jne 0x8e2ac
testl %ebx, %ebx
setg %al
movl %ebx, %r9d
andb %sil, %al
movb %al, -0x29(%rbp)
imulq $0x68, %r9, %r10
xorl %r11d, %r11d
xorl %r14d, %r14d
movq %rbx, -0x38(%rbp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %ebx, %ebx
jle 0x8e220
movl $0x56, %r12d
xorl %r13d, %r13d
btq %r13, %r14
jb 0x8e214
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rbx
leaq (%rax,%r12), %rdx
addq $-0x56, %rdx
cmpq %rbx, %rdx
jae 0x8e33b
movb (%rax,%r12), %dl
cmpb $-0x1, %dl
je 0x8e214
cmpl $-0x1, %r15d
je 0x8e211
testl %r15d, %r15d
js 0x8e33b
movslq %r15d, %r8
imulq $0x68, %r8, %r8
addq %r8, %rax
cmpq %rbx, %rax
jae 0x8e33b
cmpb 0x56(%rax), %dl
jge 0x8e214
movl %r13d, %r15d
incq %r13
addq $0x68, %r12
cmpq %r13, %r9
jne 0x8e1c2
cmpl $-0x1, %r15d
je 0x8e35a
testl %r15d, %r15d
js 0x8e33b
movq 0x10(%rdi), %r12
movslq %r15d, %rax
imulq $0x68, %rax, %rax
addq %r12, %rax
cmpq 0x18(%rdi), %rax
jae 0x8e33b
movb %r11b, 0x56(%rax)
testb %sil, %sil
movl $0x1, %eax
cmovnel %eax, %ecx
cmpb $0x0, -0x29(%rbp)
je 0x8e290
movl %r15d, %eax
imulq $0x68, %rax, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x8e282
leaq (%r12,%rcx), %rdx
cmpq 0x18(%rdi), %rdx
jae 0x8e33b
movb $-0x1, 0x56(%r12,%rcx)
addq $0x68, %rcx
cmpq %rcx, %r10
jne 0x8e269
movl $0x1, %ecx
btsq %r15, %r14
incl %r11d
cmpl %ecx, %r11d
setge %al
orb %sil, %al
cmpb $0x1, %al
movq -0x38(%rbp), %rbx
jne 0x8e1af
testl %ecx, %ecx
jne 0x8e326
xorl %ecx, %ecx
btl $0x1b, -0x30(%rbp)
jb 0x8e326
cmpl $0x0, 0x6c(%rdi)
jle 0x8e326
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x10(%rdi), %rsi
leaq (%rsi,%rax), %r9
cmpq 0x18(%rdi), %r9
jae 0x8e33b
movb $0x1, %r8b
cmpb $0x1, 0x5a(%rsi,%rax)
jne 0x8e311
testb $0x1, 0x1(%r9)
jne 0x8e311
movb $0x0, 0x56(%rsi,%rax)
movb 0x64(%rsi,%rax), %cl
testb $0xc, %cl
je 0x8e3b7
movb 0x65(%rsi,%rax), %r8b
andb $0x3, %r8b
andb $-0x4, %cl
orb %r8b, %cl
movb %cl, 0x64(%rsi,%rax)
movl $0x1, %ecx
xorl %r8d, %r8d
testb %r8b, %r8b
je 0x8e326
incq %rdx
movslq 0x6c(%rdi), %rsi
addq $0x68, %rax
cmpq %rsi, %rdx
jl 0x8e2c5
movb %cl, 0x230(%rdi)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2e376(%rip), %rdi     # 0xbc6b8
leaq 0x2d2f6(%rip), %rsi     # 0xbb63f
leaq 0x2e381(%rip), %rcx     # 0xbc6d1
movl $0x20e, %edx            # imm = 0x20E
callq 0xc140
leaq 0x43ada(%rip), %rdi     # 0xd1e3b
leaq 0x42b52(%rip), %rsi     # 0xd0eba
leaq 0x43a67(%rip), %rcx     # 0xd1dd6
movl $0xa32, %edx            # imm = 0xA32
callq 0xc140
leaq 0x43a87(%rip), %rdi     # 0xd1e07
leaq 0x42b33(%rip), %rsi     # 0xd0eba
leaq 0x43a48(%rip), %rcx     # 0xd1dd6
movl $0xa21, %edx            # imm = 0xA21
callq 0xc140
leaq 0x43a0f(%rip), %rdi     # 0xd1dae
leaq 0x42b14(%rip), %rsi     # 0xd0eba
leaq 0x43a29(%rip), %rcx     # 0xd1dd6
movl $0xa13, %edx            # imm = 0xA13
callq 0xc140
leaq 0x44473(%rip), %rdi     # 0xd2831
leaq 0x42af5(%rip), %rsi     # 0xd0eba
leaq 0x4448a(%rip), %rcx     # 0xd2856
movl $0x9d1, %edx            # imm = 0x9D1
callq 0xc140