// File: 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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movss %xmm0, -0x10(%rbp)
cmpl $0x1, -0xc(%rbp)
jne 0x13e3e4
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x13e3df
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm0
subss -0x10(%rbp), %xmm0
movss 0x3286b(%rip), %xmm1    # 0x170c3c
callq 0x139050
movq -0x8(%rbp), %rax
movss %xmm0, 0x4(%rax)
jmp 0x13e632
movq -0x8(%rbp), %rdi
movslq -0xc(%rbp), %rsi
movl $0x8, %edx
leaq 0x248(%rip), %rcx       # 0x13e640
callq 0xd6c0
movl $0x1, -0x14(%rbp)
movss -0x10(%rbp), %xmm0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, -0x2d(%rbp)
jbe 0x13e422
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
setl %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0x13e42e
jmp 0x13e561
jmp 0x13e430
movl -0x14(%rbp), %ecx
xorl %eax, %eax
cmpl -0xc(%rbp), %ecx
movb %al, -0x2e(%rbp)
jge 0x13e45d
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm1
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x4(%rax,%rcx,8), %xmm0
ucomiss %xmm1, %xmm0
setae %al
movb %al, -0x2e(%rbp)
movb -0x2e(%rbp), %al
testb $0x1, %al
jne 0x13e466
jmp 0x13e471
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x13e430
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x13e4ad
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movss 0x4(%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x13e4ad
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
subss 0x4(%rax,%rcx,8), %xmm0
movss %xmm0, -0x34(%rbp)
jmp 0x13e4c7
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm0
movss 0x3277e(%rip), %xmm1    # 0x170c3c
subss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x18(%rbp), %xmm0
jb 0x13e4df
jmp 0x13e561
movss -0x10(%rbp), %xmm0
cvtsi2ssl -0x14(%rbp), %xmm1
divss %xmm1, %xmm0
movss -0x18(%rbp), %xmm1
callq 0x13c690
movss %xmm0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x13e533
movss -0x1c(%rbp), %xmm1
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movss 0x4(%rax,%rcx,8), %xmm0
subss %xmm1, %xmm0
movss %xmm0, 0x4(%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x13e503
movss -0x1c(%rbp), %xmm0
cvtsi2ssl -0x14(%rbp), %xmm2
movss -0x10(%rbp), %xmm1
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x10(%rbp)
jmp 0x13e404
xorps %xmm0, %xmm0
movss %xmm0, -0x10(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x13e5cb
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movss 0x4(%rax,%rcx,8), %xmm0
callq 0x13e6a0
movss %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movss 0x4(%rax,%rcx,8), %xmm0
subss -0x28(%rbp), %xmm0
addss -0x10(%rbp), %xmm0
movss %xmm0, -0x10(%rbp)
movss -0x28(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movss %xmm0, 0x4(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x13e570
movss -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x13e632
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x13e630
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,8), %eax
movss 0x39fc6(%rip), %xmm0    # 0x1785c0
addss -0x10(%rbp), %xmm0
cvttss2si %xmm0, %ecx
cmpl %ecx, %eax
jge 0x13e623
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movss 0x32625(%rip), %xmm0    # 0x170c3c
addss 0x4(%rax,%rcx,8), %xmm0
movss %xmm0, 0x4(%rax,%rcx,8)
jmp 0x13e625
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13e5df
jmp 0x13e632
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)