// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::ShrinkWidths(ImGuiShrinkWidthItem*, int, float)
void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess)
{
    if (count == 1)
    {
        if (items[0].Width >= 0.0f)
            items[0].Width = ImMax(items[0].Width - width_excess, 1.0f);
        return;
    }
    ImQsort(items, (size_t)count, sizeof(ImGuiShrinkWidthItem), ShrinkWidthItemComparer);
    int count_same_width = 1;
    while (width_excess > 0.0f && count_same_width < count)
    {
        while (count_same_width < count && items[0].Width <= items[count_same_width].Width)
            count_same_width++;
        float max_width_to_remove_per_item = (count_same_width < count && items[count_same_width].Width >= 0.0f) ? (items[0].Width - items[count_same_width].Width) : (items[0].Width - 1.0f);
        if (max_width_to_remove_per_item <= 0.0f)
            break;
        float width_to_remove_per_item = ImMin(width_excess / count_same_width, max_width_to_remove_per_item);
        for (int item_n = 0; item_n < count_same_width; item_n++)
            items[item_n].Width -= width_to_remove_per_item;
        width_excess -= width_to_remove_per_item * count_same_width;
    }

    // Round width and redistribute remainder left-to-right (could make it an option of the function?)
    // Ensure that e.g. the right-most tab of a shrunk tab-bar always reaches exactly at the same distance from the right-most edge of the tab bar separator.
    width_excess = 0.0f;
    for (int n = 0; n < count; n++)
    {
        float width_rounded = ImFloor(items[n].Width);
        width_excess += items[n].Width - width_rounded;
        items[n].Width = width_rounded;
    }
    if (width_excess > 0.0f)
        for (int n = 0; n < count; n++)
            if (items[n].Index < (int)(width_excess + 0.01f))
                items[n].Width += 1.0f;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x1, %esi
jne 0x7ce5f
movss 0x4(%rbx), %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm2
jb 0x7cf80
subss %xmm0, %xmm2
maxss 0x1f1a3(%rip), %xmm2    # 0x9bff8
movss %xmm2, 0x4(%rbx)
jmp 0x7cf80
movl %esi, %r14d
movslq %esi, %r15
leaq 0x11f(%rip), %rcx       # 0x7cf8b
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
movss %xmm0, -0x1c(%rbp)
callq 0xc650
movss -0x1c(%rbp), %xmm5
pushq $0x1
popq %rax
xorps %xmm0, %xmm0
movss 0x1f15e(%rip), %xmm1    # 0x9bff0
cmpl %r14d, %eax
jge 0x7cf12
ucomiss %xmm0, %xmm5
jbe 0x7cf12
cltq
cmpq %r15, %rax
jge 0x7ceb8
movss 0x4(%rbx), %xmm2
movss 0x4(%rbx,%rax,8), %xmm3
ucomiss %xmm2, %xmm3
jb 0x7cebf
incq %rax
jmp 0x7ce9e
movss 0x4(%rbx), %xmm2
jmp 0x7cec4
ucomiss %xmm0, %xmm3
jae 0x7ceca
addss %xmm1, %xmm2
jmp 0x7cece
subss %xmm3, %xmm2
ucomiss %xmm2, %xmm0
jae 0x7cf12
cvtsi2ss %eax, %xmm4
movaps %xmm5, %xmm3
divss %xmm4, %xmm3
minss %xmm2, %xmm3
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x7cf08
movss 0x4(%rbx,%rdx,8), %xmm2
subss %xmm3, %xmm2
movss %xmm2, 0x4(%rbx,%rdx,8)
incq %rdx
jmp 0x7ceee
mulss %xmm4, %xmm3
subss %xmm3, %xmm5
jmp 0x7ce92
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
xorps %xmm0, %xmm0
cmpq %rax, %r14
je 0x7cf43
movss 0x4(%rbx,%rax,8), %xmm1
cvttps2dq %xmm1, %xmm2
cvtdq2ps %xmm2, %xmm2
subss %xmm2, %xmm1
addss %xmm1, %xmm0
movss %xmm2, 0x4(%rbx,%rax,8)
incq %rax
jmp 0x7cf1e
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x7cf80
addss 0x252d1(%rip), %xmm0    # 0xa2224
cvttss2si %xmm0, %eax
xorl %ecx, %ecx
movss 0x1f097(%rip), %xmm0    # 0x9bff8
cmpq %rcx, %r14
je 0x7cf80
cmpl %eax, (%rbx,%rcx,8)
jge 0x7cf7b
movss 0x4(%rbx,%rcx,8), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x4(%rbx,%rcx,8)
incq %rcx
jmp 0x7cf61
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq