// File: Ciaxur[P]yagb-emu/include/imgui/backends/imgui_impl_sdl.cpp
// Function: ImGui_ImplSDL2_UpdateMousePosAndButtons()
static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
{
    ImGuiIO& io = ImGui::GetIO();

    // Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
    if (io.WantSetMousePos)
        SDL_WarpMouseInWindow(g_Window, (int)io.MousePos.x, (int)io.MousePos.y);
    else
        io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);

    int mx, my;
    Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
    io.MouseDown[0] = g_MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;  // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
    io.MouseDown[1] = g_MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
    io.MouseDown[2] = g_MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
    g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;

#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
    SDL_Window* focused_window = SDL_GetKeyboardFocus();
    if (g_Window == focused_window)
    {
        if (g_MouseCanUseGlobalState)
        {
            // SDL_GetMouseState() gives mouse position seemingly based on the last window entered/focused(?)
            // The creation of a new windows at runtime and SDL_CaptureMouse both seems to severely mess up with that, so we retrieve that position globally.
            // Won't use this workaround when on Wayland, as there is no global mouse position.
            int wx, wy;
            SDL_GetWindowPosition(focused_window, &wx, &wy);
            SDL_GetGlobalMouseState(&mx, &my);
            mx -= wx;
            my -= wy;
        }
        io.MousePos = ImVec2((float)mx, (float)my);
    }

    // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger the OS window resize cursor.
    // The function is only supported from SDL 2.0.4 (released Jan 2016)
    bool any_mouse_button_down = ImGui::IsAnyMouseDown();
    SDL_CaptureMouse(any_mouse_button_down ? SDL_TRUE : SDL_FALSE);
#else
    if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_INPUT_FOCUS)
        io.MousePos = ImVec2((float)mx, (float)my);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
callq 0xcb1a0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x393(%rax)
je 0x168724
movq 0xb14f3(%rip), %rdi     # 0x219bf8
movq -0x8(%rbp), %rax
cvttss2si 0x120(%rax), %esi
movq -0x8(%rbp), %rax
cvttss2si 0x124(%rax), %edx
callq 0xd130
jmp 0x168747
leaq -0x10(%rbp), %rdi
movss 0xa028(%rip), %xmm1     # 0x172758
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, 0x120(%rax)
leaq -0x14(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0xd900
movl %eax, -0x1c(%rbp)
movb $0x1, %al
testb $0x1, 0xb1490(%rip)     # 0x219bf0
movb %al, -0x3a(%rbp)
jne 0x168774
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x128(%rax)
movb $0x1, %al
testb $0x1, 0xb1464(%rip)     # 0x219bf1
movb %al, -0x3b(%rbp)
jne 0x1687a1
movl -0x1c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x3b(%rbp)
movb -0x3b(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x129(%rax)
movb $0x1, %al
testb $0x1, 0xb1438(%rip)     # 0x219bf2
movb %al, -0x3c(%rbp)
jne 0x1687ce
movl -0x1c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x3c(%rbp)
movb -0x3c(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x12a(%rax)
movb $0x0, 0xb140d(%rip)     # 0x219bf2
movb $0x0, 0xb1405(%rip)     # 0x219bf1
movb $0x0, 0xb13fd(%rip)     # 0x219bf0
callq 0xd090
movq %rax, -0x28(%rbp)
movq 0xb13f5(%rip), %rax     # 0x219bf8
cmpq -0x28(%rbp), %rax
jne 0x168868
testb $0x1, 0xaa592(%rip)     # 0x212da2
je 0x168846
movq -0x28(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0xd330
leaq -0x14(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0xd650
movl -0x2c(%rbp), %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x30(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
cvtsi2ssl -0x14(%rbp), %xmm0
cvtsi2ssl -0x18(%rbp), %xmm1
leaq -0x38(%rbp), %rdi
callq 0xbf4c0
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x120(%rax)
callq 0xd5110
andb $0x1, %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %cl
xorl %edi, %edi
movl $0x1, %eax
testb $0x1, %cl
cmovnel %eax, %edi
callq 0xd770
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)