// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::NavUpdatePageUpPageDown()
static float ImGui::NavUpdatePageUpPageDown()
{
    ImGuiContext& g = *GImGui;
    ImGuiIO& io = g.IO;

    if (g.NavMoveDir != ImGuiDir_None || g.NavWindow == NULL)
        return 0.0f;
    if ((g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL || g.NavLayer != ImGuiNavLayer_Main)
        return 0.0f;

    ImGuiWindow* window = g.NavWindow;
    const bool page_up_held = IsKeyDown(io.KeyMap[ImGuiKey_PageUp]) && !IsActiveIdUsingKey(ImGuiKey_PageUp);
    const bool page_down_held = IsKeyDown(io.KeyMap[ImGuiKey_PageDown]) && !IsActiveIdUsingKey(ImGuiKey_PageDown);
    const bool home_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_Home]) && !IsActiveIdUsingKey(ImGuiKey_Home);
    const bool end_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_End]) && !IsActiveIdUsingKey(ImGuiKey_End);
    if (page_up_held != page_down_held || home_pressed != end_pressed) // If either (not both) are pressed
    {
        if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll)
        {
            // Fallback manual-scroll when window has no navigable item
            if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true))
                SetScrollY(window, window->Scroll.y - window->InnerRect.GetHeight());
            else if (IsKeyPressed(io.KeyMap[ImGuiKey_PageDown], true))
                SetScrollY(window, window->Scroll.y + window->InnerRect.GetHeight());
            else if (home_pressed)
                SetScrollY(window, 0.0f);
            else if (end_pressed)
                SetScrollY(window, window->ScrollMax.y);
        }
        else
        {
            ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer];
            const float page_offset_y = ImMax(0.0f, window->InnerRect.GetHeight() - window->CalcFontSize() * 1.0f + nav_rect_rel.GetHeight());
            float nav_scoring_rect_offset_y = 0.0f;
            if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true))
            {
                nav_scoring_rect_offset_y = -page_offset_y;
                g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset up, we request the down direction (so we can always land on the last item)
                g.NavMoveClipDir = ImGuiDir_Up;
                g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
            }
            else if (IsKeyPressed(io.KeyMap[ImGuiKey_PageDown], true))
            {
                nav_scoring_rect_offset_y = +page_offset_y;
                g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset down, we request the up direction (so we can always land on the last item)
                g.NavMoveClipDir = ImGuiDir_Down;
                g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
            }
            else if (home_pressed)
            {
                // FIXME-NAV: handling of Home/End is assuming that the top/bottom most item will be visible with Scroll.y == 0/ScrollMax.y
                // Scrolling will be handled via the ImGuiNavMoveFlags_ScrollToEdge flag, we don't scroll immediately to avoid scrolling happening before nav result.
                // Preserve current horizontal position if we have any.
                nav_rect_rel.Min.y = nav_rect_rel.Max.y = -window->Scroll.y;
                if (nav_rect_rel.IsInverted())
                    nav_rect_rel.Min.x = nav_rect_rel.Max.x = 0.0f;
                g.NavMoveDir = ImGuiDir_Down;
                g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_ScrollToEdge;
            }
            else if (end_pressed)
            {
                nav_rect_rel.Min.y = nav_rect_rel.Max.y = window->ScrollMax.y + window->SizeFull.y - window->Scroll.y;
                if (nav_rect_rel.IsInverted())
                    nav_rect_rel.Min.x = nav_rect_rel.Max.x = 0.0f;
                g.NavMoveDir = ImGuiDir_Up;
                g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_ScrollToEdge;
            }
            return nav_scoring_rect_offset_y;
        }
    }
    return 0.0f;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x12bac1(%rip), %rax    # 0x212f40
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x1d10(%rax)
jne 0xe74aa
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1c90(%rax)
jne 0xe74b7
xorps %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0xe7935
movq -0x10(%rbp), %rax
movq 0x1c90(%rax), %rax
movl 0xc(%rax), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
jne 0xe74ea
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1dc0(%rax)
jne 0xe74ea
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1cdc(%rax)
je 0xe74f7
xorps %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0xe7935
movq -0x10(%rbp), %rax
movq 0x1c90(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x48(%rax), %edi
callq 0xd4960
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x39(%rbp)
jne 0xe7520
jmp 0xe752f
movl $0x5, %edi
callq 0xe94a0
xorb $-0x1, %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rax
movl 0x4c(%rax), %edi
callq 0xd4960
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3a(%rbp)
jne 0xe7551
jmp 0xe7560
movl $0x6, %edi
callq 0xe94a0
xorb $-0x1, %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x18(%rbp), %rax
movl 0x50(%rax), %edi
movl $0x1, %esi
callq 0xd4bc0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3b(%rbp)
jne 0xe7587
jmp 0xe7596
movl $0x7, %edi
callq 0xe94a0
xorb $-0x1, %al
movb %al, -0x3b(%rbp)
movb -0x3b(%rbp), %al
andb $0x1, %al
movb %al, -0x23(%rbp)
movq -0x18(%rbp), %rax
movl 0x54(%rax), %edi
movl $0x1, %esi
callq 0xd4bc0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3c(%rbp)
jne 0xe75bd
jmp 0xe75cc
movl $0x8, %edi
callq 0xe94a0
xorb $-0x1, %al
movb %al, -0x3c(%rbp)
movb -0x3c(%rbp), %al
andb $0x1, %al
movb %al, -0x24(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x22(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0xe7602
movb -0x23(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x24(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0xe792d
movq -0x20(%rbp), %rax
cmpl $0x0, 0x150(%rax)
jne 0xe7706
movq -0x20(%rbp), %rax
testb $0x1, 0x15d(%rax)
je 0xe7706
movq -0x18(%rbp), %rax
movl 0x48(%rax), %edi
movl $0x1, %esi
callq 0xd4bc0
testb $0x1, %al
jne 0xe763b
jmp 0xe767b
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movss 0x60(%rax), %xmm0
movss %xmm0, -0x40(%rbp)
movq -0x20(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0xeb860
movq -0x48(%rbp), %rdi
movaps %xmm0, %xmm1
movss -0x40(%rbp), %xmm0
subss %xmm1, %xmm0
callq 0xdd920
jmp 0xe7701
movq -0x18(%rbp), %rax
movl 0x4c(%rax), %edi
movl $0x1, %esi
callq 0xd4bc0
testb $0x1, %al
jne 0xe7692
jmp 0xe76cf
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movss 0x60(%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x20(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0xeb860
movq -0x58(%rbp), %rdi
movaps %xmm0, %xmm1
movss -0x4c(%rbp), %xmm0
addss %xmm1, %xmm0
callq 0xdd920
jmp 0xe76ff
testb $0x1, -0x23(%rbp)
je 0xe76e3
movq -0x20(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0xdd920
jmp 0xe76fd
testb $0x1, -0x24(%rbp)
je 0xe76fb
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movss 0x68(%rax), %xmm0
callq 0xdd920
jmp 0xe76fd
jmp 0xe76ff
jmp 0xe7701
jmp 0xe792b
movq -0x20(%rbp), %rax
addq $0x3b8, %rax            # imm = 0x3B8
movq -0x10(%rbp), %rcx
movl 0x1cdc(%rcx), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0xeb860
movss %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rdi
callq 0xebbf0
movss -0x60(%rbp), %xmm1
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movq -0x30(%rbp), %rdi
callq 0xeb860
movss -0x5c(%rbp), %xmm1
addss %xmm0, %xmm1
xorps %xmm0, %xmm0
callq 0xc88c0
movss %xmm0, -0x34(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x48(%rax), %edi
movl $0x1, %esi
callq 0xd4bc0
testb $0x1, %al
jne 0xe779c
jmp 0xe77e2
movss -0x34(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x3, 0x1d10(%rax)
movq -0x10(%rbp), %rax
movl $0x2, 0x1d18(%rax)
movq -0x10(%rbp), %rax
movl $0x30, 0x1d04(%rax)
jmp 0xe791f
movq -0x18(%rbp), %rax
movl 0x4c(%rax), %edi
movl $0x1, %esi
callq 0xd4bc0
testb $0x1, %al
jne 0xe77f9
jmp 0xe7832
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x2, 0x1d10(%rax)
movq -0x10(%rbp), %rax
movl $0x3, 0x1d18(%rax)
movq -0x10(%rbp), %rax
movl $0x30, 0x1d04(%rax)
jmp 0xe791d
testb $0x1, -0x23(%rbp)
je 0xe78a4
movq -0x20(%rbp), %rax
movss 0x60(%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq -0x30(%rbp), %rax
movss %xmm0, 0xc(%rax)
movq -0x30(%rbp), %rax
movss %xmm0, 0x4(%rax)
movq -0x30(%rbp), %rdi
callq 0xecc10
testb $0x1, %al
jne 0xe786f
jmp 0xe7886
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rax)
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movq -0x10(%rbp), %rax
movl $0x3, 0x1d10(%rax)
movq -0x10(%rbp), %rax
movl $0x50, 0x1d04(%rax)
jmp 0xe791b
testb $0x1, -0x24(%rbp)
je 0xe7919
movq -0x20(%rbp), %rax
movss 0x68(%rax), %xmm0
movq -0x20(%rbp), %rax
addss 0x24(%rax), %xmm0
movq -0x20(%rbp), %rax
subss 0x60(%rax), %xmm0
movq -0x30(%rbp), %rax
movss %xmm0, 0xc(%rax)
movq -0x30(%rbp), %rax
movss %xmm0, 0x4(%rax)
movq -0x30(%rbp), %rdi
callq 0xecc10
testb $0x1, %al
jne 0xe78e6
jmp 0xe78fd
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rax)
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movq -0x10(%rbp), %rax
movl $0x2, 0x1d10(%rax)
movq -0x10(%rbp), %rax
movl $0x50, 0x1d04(%rax)
jmp 0xe791b
jmp 0xe791d
jmp 0xe791f
movss -0x38(%rbp), %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0xe7935
jmp 0xe792d
xorps %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
movss -0x4(%rbp), %xmm0
addq $0x60, %rsp
popq %rbp
retq