// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGuiListClipper::Step()
bool ImGuiListClipper::Step()
{
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = g.CurrentWindow;

    ImGuiTable* table = g.CurrentTable;
    if (table && table->IsInsideRow)
        ImGui::TableEndRow(table);

    // No items
    if (ItemsCount == 0 || GetSkipItemForListClipping())
    {
        End();
        return false;
    }

    // Step 0: Let you process the first element (regardless of it being visible or not, so we can measure the element height)
    if (StepNo == 0)
    {
        // While we are in frozen row state, keep displaying items one by one, unclipped
        // FIXME: Could be stored as a table-agnostic state.
        if (table != NULL && !table->IsUnfrozenRows)
        {
            DisplayStart = ItemsFrozen;
            DisplayEnd = ItemsFrozen + 1;
            ItemsFrozen++;
            return true;
        }

        StartPosY = window->DC.CursorPos.y;
        if (ItemsHeight <= 0.0f)
        {
            // Submit the first item so we can measure its height (generally it is 0..1)
            DisplayStart = ItemsFrozen;
            DisplayEnd = ItemsFrozen + 1;
            StepNo = 1;
            return true;
        }

        // Already has item height (given by user in Begin): skip to calculating step
        DisplayStart = DisplayEnd;
        StepNo = 2;
    }

    // Step 1: the clipper infer height from first element
    if (StepNo == 1)
    {
        IM_ASSERT(ItemsHeight <= 0.0f);
        if (table)
        {
            const float pos_y1 = table->RowPosY1;   // Using this instead of StartPosY to handle clipper straddling the frozen row
            const float pos_y2 = table->RowPosY2;   // Using this instead of CursorPos.y to take account of tallest cell.
            ItemsHeight = pos_y2 - pos_y1;
            window->DC.CursorPos.y = pos_y2;
        }
        else
        {
            ItemsHeight = window->DC.CursorPos.y - StartPosY;
        }
        IM_ASSERT(ItemsHeight > 0.0f && "Unable to calculate item height! First item hasn't moved the cursor vertically!");
        StepNo = 2;
    }

    // Reached end of list
    if (DisplayEnd >= ItemsCount)
    {
        End();
        return false;
    }

    // Step 2: calculate the actual range of elements to display, and position the cursor before the first element
    if (StepNo == 2)
    {
        IM_ASSERT(ItemsHeight > 0.0f);

        int already_submitted = DisplayEnd;
        ImGui::CalcListClipping(ItemsCount - already_submitted, ItemsHeight, &DisplayStart, &DisplayEnd);
        DisplayStart += already_submitted;
        DisplayEnd += already_submitted;

        // Seek cursor
        if (DisplayStart > already_submitted)
            SetCursorPosYAndSetupForPrevLine(StartPosY + (DisplayStart - ItemsFrozen) * ItemsHeight, ItemsHeight);

        StepNo = 3;
        return true;
    }

    // Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd),
    // Advance the cursor to the end of the list and then returns 'false' to end the loop.
    if (StepNo == 3)
    {
        // Seek cursor
        if (ItemsCount < INT_MAX)
            SetCursorPosYAndSetupForPrevLine(StartPosY + (ItemsCount - ItemsFrozen) * ItemsHeight, ItemsHeight); // advance cursor
        ItemsCount = -1;
        return false;
    }

    IM_ASSERT(0);
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x14bc05(%rip), %rax    # 0x212f40
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x1ae0(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x20a8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xc737a
movq -0x28(%rbp), %rax
testb $0x1, 0x249(%rax)
je 0xc737a
movq -0x28(%rbp), %rdi
callq 0x12e9d0
movq -0x40(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xc738f
callq 0xc6f60
testb $0x1, %al
jne 0xc738f
jmp 0xc73a1
movq -0x40(%rbp), %rdi
callq 0xc7140
movb $0x0, -0x1(%rbp)
jmp 0xc7670
movq -0x40(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xc7437
cmpq $0x0, -0x28(%rbp)
je 0xc73e7
movq -0x28(%rbp), %rax
testb $0x1, 0x253(%rax)
jne 0xc73e7
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, (%rax)
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xc7670
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movss 0xdc(%rcx), %xmm0
movss %xmm0, 0x18(%rax)
xorps %xmm0, %xmm0
ucomiss 0x14(%rax), %xmm0
jb 0xc7427
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, (%rax)
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl $0x1, 0xc(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xc7670
movq -0x40(%rbp), %rax
movl 0x4(%rax), %ecx
movl %ecx, (%rax)
movl $0x2, 0xc(%rax)
movq -0x40(%rbp), %rax
cmpl $0x1, 0xc(%rax)
jne 0xc752b
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
ucomiss 0x14(%rax), %xmm0
jb 0xc7454
jmp 0xc7473
leaq 0xabcbe(%rip), %rdi     # 0x173119
leaq 0xabaa7(%rip), %rsi     # 0x172f09
movl $0x90b, %edx            # imm = 0x90B
leaq 0xabcbf(%rip), %rcx     # 0x17312d
callq 0xd180
cmpq $0x0, -0x28(%rbp)
je 0xc74bf
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movss 0x7c(%rcx), %xmm0
movss %xmm0, -0x2c(%rbp)
movq -0x28(%rbp), %rcx
movss 0x80(%rcx), %xmm0
movss %xmm0, -0x30(%rbp)
movss -0x30(%rbp), %xmm0
subss -0x2c(%rbp), %xmm0
movss %xmm0, 0x14(%rax)
movss -0x30(%rbp), %xmm0
movq -0x20(%rbp), %rax
movss %xmm0, 0xdc(%rax)
jmp 0xc74d9
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movss 0xdc(%rcx), %xmm0
subss 0x18(%rax), %xmm0
movss %xmm0, 0x14(%rax)
movq -0x40(%rbp), %rax
movss 0x14(%rax), %xmm0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, -0x41(%rbp)
jbe 0xc74f6
movb $0x1, %al
movb %al, -0x41(%rbp)
jmp 0xc74f6
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0xc74ff
jmp 0xc7501
jmp 0xc7520
leaq 0xabc93(%rip), %rdi     # 0x17319b
leaq 0xab9fa(%rip), %rsi     # 0x172f09
movl $0x917, %edx            # imm = 0x917
leaq 0xabc12(%rip), %rcx     # 0x17312d
callq 0xd180
movq -0x40(%rbp), %rax
movl $0x2, 0xc(%rax)
movq -0x40(%rbp), %rcx
movl 0x4(%rcx), %eax
cmpl 0x8(%rcx), %eax
jl 0xc7549
movq -0x40(%rbp), %rdi
callq 0xc7140
movb $0x0, -0x1(%rbp)
jmp 0xc7670
movq -0x40(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0xc75ff
movq -0x40(%rbp), %rax
movss 0x14(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xc756a
jmp 0xc7589
leaq 0xabc92(%rip), %rdi     # 0x173203
leaq 0xab991(%rip), %rsi     # 0x172f09
movl $0x925, %edx            # imm = 0x925
leaq 0xabba9(%rip), %rcx     # 0x17312d
callq 0xd180
movq -0x40(%rbp), %rsi
movl 0x4(%rsi), %eax
movl %eax, -0x34(%rbp)
movl 0x8(%rsi), %edi
subl -0x34(%rbp), %edi
movss 0x14(%rsi), %xmm0
movq %rsi, %rdx
addq $0x4, %rdx
callq 0xc6d70
movq -0x40(%rbp), %rax
movl -0x34(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x34(%rbp), %ecx
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movl (%rax), %eax
cmpl -0x34(%rbp), %eax
jle 0xc75ee
movq -0x40(%rbp), %rax
movss 0x18(%rax), %xmm1
movl (%rax), %ecx
subl 0x10(%rax), %ecx
cvtsi2ss %ecx, %xmm0
movss 0x14(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss 0x14(%rax), %xmm1
callq 0xc71c0
movq -0x40(%rbp), %rax
movl $0x3, 0xc(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xc7670
movq -0x40(%rbp), %rax
cmpl $0x3, 0xc(%rax)
jne 0xc7651
movq -0x40(%rbp), %rax
cmpl $0x7fffffff, 0x8(%rax)  # imm = 0x7FFFFFFF
jge 0xc7640
movq -0x40(%rbp), %rax
movss 0x18(%rax), %xmm1
movl 0x8(%rax), %ecx
subl 0x10(%rax), %ecx
cvtsi2ss %ecx, %xmm0
movss 0x14(%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss 0x14(%rax), %xmm1
callq 0xc71c0
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movb $0x0, -0x1(%rbp)
jmp 0xc7670
leaq 0xadab2(%rip), %rdi     # 0x17510a
leaq 0xab8aa(%rip), %rsi     # 0x172f09
movl $0x93f, %edx            # imm = 0x93F
leaq 0xabac2(%rip), %rcx     # 0x17312d
callq 0xd180
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)