// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::DragScalar(char const*, int, void*, float, void const*, void const*, char const*, int)
bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const ImGuiID id = window->GetID(label);
    const float w = CalcItemWidth();
    const ImVec2 label_size = CalcTextSize(label, NULL, true);
    const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f));
    const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));

    ItemSize(total_bb, style.FramePadding.y);
    if (!ItemAdd(total_bb, id, &frame_bb))
        return false;

    // Default format string when passing NULL
    if (format == NULL)
        format = DataTypeGetInfo(data_type)->PrintFmt;
    else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.)
        format = PatchFormatStringFloatToInt(format);

    // Tabbing or CTRL-clicking on Drag turns it into an InputText
    const bool hovered = ItemHoverable(frame_bb, id);
    const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0;
    bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
    if (!temp_input_is_active)
    {
        const bool focus_requested = temp_input_allowed && FocusableItemRegister(window, id);
        const bool clicked = (hovered && g.IO.MouseClicked[0]);
        const bool double_clicked = (hovered && g.IO.MouseDoubleClicked[0]);
        if (focus_requested || clicked || double_clicked || g.NavActivateId == id || g.NavInputId == id)
        {
            SetActiveID(id, window);
            SetFocusID(id, window);
            FocusWindow(window);
            g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
            if (temp_input_allowed && (focus_requested || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavInputId == id))
            {
                temp_input_is_active = true;
                FocusableItemUnregister(window);
            }
        }
        // Experimental: simple click (without moving) turns Drag into an InputText
        // FIXME: Currently polling ImGuiConfigFlags_IsTouchScreen, may either poll an hypothetical ImGuiBackendFlags_HasKeyboard and/or an explicit drag settings.
        if (g.IO.ConfigDragClickToInputText && temp_input_allowed && !temp_input_is_active)
            if (g.ActiveId == id && hovered && g.IO.MouseReleased[0] && !IsMouseDragPastThreshold(0, g.IO.MouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR))
            {
                g.NavInputId = id;
                temp_input_is_active = true;
                FocusableItemUnregister(window);
            }
    }

    if (temp_input_is_active)
    {
        // Only clamp CTRL+Click input when ImGuiSliderFlags_AlwaysClamp is set
        const bool is_clamp_input = (flags & ImGuiSliderFlags_AlwaysClamp) != 0 && (p_min == NULL || p_max == NULL || DataTypeCompare(data_type, p_min, p_max) < 0);
        return TempInputScalar(frame_bb, id, label, data_type, p_data, format, is_clamp_input ? p_min : NULL, is_clamp_input ? p_max : NULL);
    }

    // Draw frame
    const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
    RenderNavHighlight(frame_bb, id);
    RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding);

    // Drag behavior
    const bool value_changed = DragBehavior(id, data_type, p_data, v_speed, p_min, p_max, format, flags);
    if (value_changed)
        MarkItemEdited(id);

    // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
    char value_buf[64];
    const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format);
    RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f));

    if (label_size.x > 0.0f)
        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);

    IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
    return value_changed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
callq 0xeb270
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
testb $0x1, 0x93(%rax)
je 0x142309
movb $0x0, -0x1(%rbp)
jmp 0x142a6c
leaq 0xd0c30(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x1560, %rax           # imm = 0x1560
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x150(%rbp)
callq 0xc9910
movl %eax, -0x5c(%rbp)
callq 0xdcdc0
movq -0x150(%rbp), %rsi
movss %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movss 0x2fc1e(%rip), %xmm0    # 0x171f80
callq 0xc87e0
movlpd %xmm0, -0x68(%rbp)
movq -0x48(%rbp), %rax
addq $0xd8, %rax
movq %rax, -0x140(%rbp)
movss -0x60(%rbp), %xmm0
movss -0x64(%rbp), %xmm2
movq -0x58(%rbp), %rax
movss 0x3c(%rax), %xmm1
addss %xmm1, %xmm1
addss %xmm2, %xmm1
leaq -0x88(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0xbf4c0
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdi
callq 0x139090
movq -0x140(%rbp), %rsi
movlpd %xmm0, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0xe8660
leaq -0x78(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x78(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x130(%rbp)
movss -0x68(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x142416
movq -0x58(%rbp), %rax
movss 0x50(%rax), %xmm0
addss -0x68(%rbp), %xmm0
movss %xmm0, -0x154(%rbp)
jmp 0x142423
xorps %xmm0, %xmm0
movss %xmm0, -0x154(%rbp)
jmp 0x142423
movss -0x154(%rbp), %xmm0
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x160(%rbp)
xorps %xmm1, %xmm1
callq 0xbf4c0
movq -0x130(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x139090
movq -0x138(%rbp), %rsi
movlpd %xmm0, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0xe8660
movq -0x58(%rbp), %rax
movss 0x3c(%rax), %xmm0
leaq -0x98(%rbp), %rdi
callq 0xdc300
movl -0x5c(%rbp), %esi
leaq -0x98(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0xd6250
testb $0x1, %al
jne 0x1424ab
movb $0x0, -0x1(%rbp)
jmp 0x142a6c
cmpq $0x0, -0x40(%rbp)
jne 0x1424c4
movl -0x14(%rbp), %edi
callq 0x13fc60
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x1424ee
cmpl $0x4, -0x14(%rbp)
jne 0x1424ec
movq -0x40(%rbp), %rdi
leaq 0x374f2(%rip), %rsi     # 0x1799c7
callq 0xd7e0
cmpl $0x0, %eax
je 0x1424ec
movq -0x40(%rbp), %rdi
callq 0x142a80
movq %rax, -0x40(%rbp)
jmp 0x1424ee
movl -0x5c(%rbp), %esi
leaq -0x78(%rbp), %rdi
callq 0xca460
andb $0x1, %al
movb %al, -0xa9(%rbp)
movl 0x10(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movb %al, -0xaa(%rbp)
xorl %eax, %eax
testb $0x1, -0xaa(%rbp)
movb %al, -0x161(%rbp)
je 0x142537
movl -0x5c(%rbp), %edi
callq 0x15e5f0
movb %al, -0x161(%rbp)
movb -0x161(%rbp), %al
andb $0x1, %al
movb %al, -0xab(%rbp)
testb $0x1, -0xab(%rbp)
jne 0x142720
xorl %eax, %eax
testb $0x1, -0xaa(%rbp)
movb %al, -0x162(%rbp)
je 0x142575
movq -0x48(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0xca7d0
movb %al, -0x162(%rbp)
movb -0x162(%rbp), %al
andb $0x1, %al
movb %al, -0xac(%rbp)
xorl %eax, %eax
testb $0x1, -0xa9(%rbp)
movb %al, -0x163(%rbp)
je 0x1425a4
movq -0x50(%rbp), %rax
movb 0x420(%rax), %al
movb %al, -0x163(%rbp)
movb -0x163(%rbp), %al
andb $0x1, %al
movb %al, -0xad(%rbp)
xorl %eax, %eax
testb $0x1, -0xa9(%rbp)
movb %al, -0x164(%rbp)
je 0x1425d3
movq -0x50(%rbp), %rax
movb 0x425(%rax), %al
movb %al, -0x164(%rbp)
movb -0x164(%rbp), %al
andb $0x1, %al
movb %al, -0xae(%rbp)
testb $0x1, -0xac(%rbp)
jne 0x14261e
testb $0x1, -0xad(%rbp)
jne 0x14261e
testb $0x1, -0xae(%rbp)
jne 0x14261e
movq -0x50(%rbp), %rax
movl 0x1ca0(%rax), %eax
cmpl -0x5c(%rbp), %eax
je 0x14261e
movq -0x50(%rbp), %rax
movl 0x1cac(%rax), %eax
cmpl -0x5c(%rbp), %eax
jne 0x14269f
movl -0x5c(%rbp), %edi
movq -0x48(%rbp), %rsi
callq 0xc9ec0
movl -0x5c(%rbp), %edi
movq -0x48(%rbp), %rsi
callq 0xdf460
movq -0x48(%rbp), %rdi
callq 0xcb380
movq -0x50(%rbp), %rax
movl $0x3, 0x1b44(%rax)
testb $0x1, -0xaa(%rbp)
je 0x14269d
testb $0x1, -0xac(%rbp)
jne 0x14268d
testb $0x1, -0xad(%rbp)
je 0x142675
movq -0x50(%rbp), %rax
testb $0x1, 0x140(%rax)
jne 0x14268d
testb $0x1, -0xae(%rbp)
jne 0x14268d
movq -0x50(%rbp), %rax
movl 0x1cac(%rax), %eax
cmpl -0x5c(%rbp), %eax
jne 0x14269d
movb $0x1, -0xab(%rbp)
movq -0x48(%rbp), %rdi
callq 0xca950
jmp 0x14269f
movq -0x50(%rbp), %rax
testb $0x1, 0xcb(%rax)
je 0x14271e
testb $0x1, -0xaa(%rbp)
je 0x14271e
testb $0x1, -0xab(%rbp)
jne 0x14271e
movq -0x50(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x5c(%rbp), %eax
jne 0x14271c
testb $0x1, -0xa9(%rbp)
je 0x14271c
movq -0x50(%rbp), %rax
testb $0x1, 0x42a(%rax)
je 0x14271c
movq -0x50(%rbp), %rax
movss 0x2f8e9(%rip), %xmm0    # 0x171fd8
mulss 0x38(%rax), %xmm0
xorl %edi, %edi
callq 0xd4f40
testb $0x1, %al
jne 0x14271c
movl -0x5c(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x1cac(%rax)
movb $0x1, -0xab(%rbp)
movq -0x48(%rbp), %rdi
callq 0xca950
jmp 0x14271e
jmp 0x142720
testb $0x1, -0xab(%rbp)
je 0x142862
movl 0x10(%rbp), %ecx
andl $0x10, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x165(%rbp)
je 0x142786
movb $0x1, %al
cmpq $0x0, -0x30(%rbp)
movb %al, -0x166(%rbp)
je 0x14277a
movb $0x1, %al
cmpq $0x0, -0x38(%rbp)
movb %al, -0x166(%rbp)
je 0x14277a
movl -0x14(%rbp), %edi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x140f90
cmpl $0x0, %eax
setl %al
movb %al, -0x166(%rbp)
movb -0x166(%rbp), %al
movb %al, -0x165(%rbp)
movb -0x165(%rbp), %al
andb $0x1, %al
movb %al, -0xaf(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x18c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x188(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x17c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x170(%rbp)
testb $0x1, -0xaf(%rbp)
je 0x1427dd
movq -0x30(%rbp), %rax
movq %rax, -0x198(%rbp)
jmp 0x1427e8
xorl %eax, %eax
movq %rax, -0x198(%rbp)
jmp 0x1427e8
movq -0x198(%rbp), %rax
movq %rax, -0x1a0(%rbp)
testb $0x1, -0xaf(%rbp)
je 0x14280c
movq -0x38(%rbp), %rax
movq %rax, -0x1a8(%rbp)
jmp 0x142817
xorl %eax, %eax
movq %rax, -0x1a8(%rbp)
jmp 0x142817
movq -0x1a0(%rbp), %r10
movq -0x170(%rbp), %r9
movq -0x178(%rbp), %r8
movl -0x17c(%rbp), %ecx
movq -0x188(%rbp), %rdx
movl -0x18c(%rbp), %esi
movq -0x1a8(%rbp), %rax
leaq -0x78(%rbp), %rdi
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x142ba0
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x142a6c
movq -0x50(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x5c(%rbp), %eax
jne 0x14287e
movl $0x9, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x1428a0
movq -0x50(%rbp), %rax
movl 0x1b1c(%rax), %edx
movl -0x5c(%rbp), %esi
movl $0x7, %eax
movl $0x8, %ecx
cmpl %esi, %edx
cmovel %ecx, %eax
movl %eax, -0x1ac(%rbp)
movl -0x1ac(%rbp), %edi
movss 0x2e38e(%rip), %xmm0    # 0x170c3c
callq 0xc76e0
movl %eax, -0xb4(%rbp)
movl -0x5c(%rbp), %esi
leaq -0x78(%rbp), %rdi
movl $0x1, %edx
callq 0xc91e0
movq -0x78(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl -0xb4(%rbp), %edi
movq -0x58(%rbp), %rax
movss 0x40(%rax), %xmm2
movsd -0xc0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
movl $0x1, %esi
callq 0xc8f20
movl -0x5c(%rbp), %edi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movss -0x24(%rbp), %xmm0
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movl 0x10(%rbp), %eax
movl %eax, (%rsp)
callq 0x141a40
andb $0x1, %al
movb %al, -0xc9(%rbp)
testb $0x1, -0xc9(%rbp)
je 0x142948
movl -0x5c(%rbp), %edi
callq 0xca110
leaq -0x110(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x110(%rbp), %rdi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x40, %esi
callq 0x13fcd0
movl %eax, %ecx
movq -0x1d8(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x118(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x78(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1c8(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x120(%rbp), %rdi
movss 0x2f60b(%rip), %xmm1    # 0x171fd8
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0x1d0(%rbp), %rdi
movq -0x1c8(%rbp), %rsi
movq -0x1c0(%rbp), %rdx
movq -0x1b8(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x120(%rbp), %r9
movq $0x0, (%rsp)
callq 0xc8900
movss -0x68(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x142a5d
movss -0x74(%rbp), %xmm1
movss -0x70(%rbp), %xmm0
movq -0x58(%rbp), %rax
movss 0x3c(%rax), %xmm2
movss 0x50(%rax), %xmm3
addss %xmm3, %xmm0
addss %xmm2, %xmm1
leaq -0x128(%rbp), %rdi
callq 0xbf4c0
movq -0x10(%rbp), %rdi
movsd -0x128(%rbp), %xmm0
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0xc8120
jmp 0x142a5f
jmp 0x142a61
movb -0xc9(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
nopw (%rax,%rax)