// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::TabBarScrollToTab(ImGuiTabBar*, ImGuiTabItem*, ImGuiTabBarSection*)
static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab, ImGuiTabBarSection* sections)
{
    if (tab->Flags & (ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing))
        return;

    ImGuiContext& g = *GImGui;
    float margin = g.FontSize * 1.0f; // When to scroll to make Tab N+1 visible always make a bit of N visible to suggest more scrolling area (since we don't have a scrollbar)
    int order = tab_bar->GetTabOrder(tab);

    // Scrolling happens only in the central section (leading/trailing sections are not scrolling)
    // FIXME: This is all confusing.
    float scrollable_width = tab_bar->BarRect.GetWidth() - sections[0].Width - sections[2].Width - sections[1].Spacing;

    // We make all tabs positions all relative Sections[0].Width to make code simpler
    float tab_x1 = tab->Offset - sections[0].Width + (order > sections[0].TabCount - 1 ? -margin : 0.0f);
    float tab_x2 = tab->Offset - sections[0].Width + tab->Width + (order + 1 < tab_bar->Tabs.Size - sections[2].TabCount ? margin : 1.0f);
    tab_bar->ScrollingTargetDistToVisibility = 0.0f;
    if (tab_bar->ScrollingTarget > tab_x1 || (tab_x2 - tab_x1 >= scrollable_width))
    {
        // Scroll to the left
        tab_bar->ScrollingTargetDistToVisibility = ImMax(tab_bar->ScrollingAnim - tab_x2, 0.0f);
        tab_bar->ScrollingTarget = tab_x1;
    }
    else if (tab_bar->ScrollingTarget < tab_x2 - scrollable_width)
    {
        // Scroll to the right
        tab_bar->ScrollingTargetDistToVisibility = ImMax((tab_x1 - scrollable_width) - tab_bar->ScrollingAnim, 0.0f);
        tab_bar->ScrollingTarget = tab_x2 - scrollable_width;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
je 0x15ae8a
jmp 0x15b05b
leaq 0xb80af(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movss 0x15d98(%rip), %xmm0    # 0x170c3c
mulss 0x1980(%rax), %xmm0
movss %xmm0, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x162910
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x2c, %rdi
callq 0xeb840
movq -0x18(%rbp), %rax
subss 0x4(%rax), %xmm0
movq -0x18(%rbp), %rax
subss 0x1c(%rax), %xmm0
movq -0x18(%rbp), %rax
subss 0x14(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movss 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
subss 0x4(%rax), %xmm0
movss %xmm0, -0x38(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x15af2e
movss -0x24(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x3c(%rbp)
jmp 0x15af38
xorps %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
jmp 0x15af38
movss -0x38(%rbp), %xmm0
movss -0x3c(%rbp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movss 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
subss 0x4(%rax), %xmm0
movq -0x10(%rbp), %rax
addss 0x14(%rax), %xmm0
movss %xmm0, -0x40(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
movl (%rcx), %ecx
movq -0x18(%rbp), %rdx
subl 0x18(%rdx), %ecx
cmpl %ecx, %eax
jge 0x15af8e
movss -0x24(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x15af9d
movss 0x15ca6(%rip), %xmm0    # 0x170c3c
movss %xmm0, -0x44(%rbp)
jmp 0x15af9d
movss -0x40(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x54(%rax)
movq -0x8(%rbp), %rax
movss 0x50(%rax), %xmm0
ucomiss -0x30(%rbp), %xmm0
ja 0x15afdb
movss -0x34(%rbp), %xmm0
subss -0x30(%rbp), %xmm0
ucomiss -0x2c(%rbp), %xmm0
jb 0x15b00a
movq -0x8(%rbp), %rax
movss 0x4c(%rax), %xmm0
subss -0x34(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0x139050
movq -0x8(%rbp), %rax
movss %xmm0, 0x54(%rax)
movss -0x30(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x50(%rax)
jmp 0x15b05b
movq -0x8(%rbp), %rax
movss 0x50(%rax), %xmm1
movss -0x34(%rbp), %xmm0
subss -0x2c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15b059
movss -0x30(%rbp), %xmm0
subss -0x2c(%rbp), %xmm0
movq -0x8(%rbp), %rax
subss 0x4c(%rax), %xmm0
xorps %xmm1, %xmm1
callq 0x139050
movq -0x8(%rbp), %rax
movss %xmm0, 0x54(%rax)
movss -0x34(%rbp), %xmm0
subss -0x2c(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x50(%rax)
jmp 0x15b05b
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)