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

    bool source_drag_active = false;
    ImGuiID source_id = 0;
    ImGuiID source_parent_id = 0;
    ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
    if (!(flags & ImGuiDragDropFlags_SourceExtern))
    {
        source_id = window->DC.LastItemId;
        if (source_id != 0 && g.ActiveId != source_id) // Early out for most common case
            return false;
        if (g.IO.MouseDown[mouse_button] == false)
            return false;

        if (source_id == 0)
        {
            // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
            // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag, C) Swallow your programmer pride.
            if (!(flags & ImGuiDragDropFlags_SourceAllowNullID))
            {
                IM_ASSERT(0);
                return false;
            }

            // Early out
            if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) == 0 && (g.ActiveId == 0 || g.ActiveIdWindow != window))
                return false;

            // Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image()
            // We build a throwaway ID based on current ID stack + relative AABB of items in window.
            // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
            // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
            source_id = window->DC.LastItemId = window->GetIDFromRectangle(window->DC.LastItemRect);
            bool is_hovered = ItemHoverable(window->DC.LastItemRect, source_id);
            if (is_hovered && g.IO.MouseClicked[mouse_button])
            {
                SetActiveID(source_id, window);
                FocusWindow(window);
            }
            if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker.
                g.ActiveIdAllowOverlap = is_hovered;
        }
        else
        {
            g.ActiveIdAllowOverlap = false;
        }
        if (g.ActiveId != source_id)
            return false;
        source_parent_id = window->IDStack.back();
        source_drag_active = IsMouseDragging(mouse_button);

        // Disable navigation and key inputs while dragging
        g.ActiveIdUsingNavDirMask = ~(ImU32)0;
        g.ActiveIdUsingNavInputMask = ~(ImU32)0;
        g.ActiveIdUsingKeyInputMask = ~(ImU64)0;
    }
    else
    {
        window = NULL;
        source_id = ImHashStr("#SourceExtern");
        source_drag_active = true;
    }

    if (source_drag_active)
    {
        if (!g.DragDropActive)
        {
            IM_ASSERT(source_id != 0);
            ClearDragDrop();
            ImGuiPayload& payload = g.DragDropPayload;
            payload.SourceId = source_id;
            payload.SourceParentId = source_parent_id;
            g.DragDropActive = true;
            g.DragDropSourceFlags = flags;
            g.DragDropMouseButton = mouse_button;
            if (payload.SourceId == g.ActiveId)
                g.ActiveIdNoClearOnFocusLoss = true;
        }
        g.DragDropSourceFrameCount = g.FrameCount;
        g.DragDropWithinSource = true;

        if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
        {
            // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
            // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
            BeginTooltip();
            if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
            {
                ImGuiWindow* tooltip_window = g.CurrentWindow;
                tooltip_window->SkipItems = true;
                tooltip_window->HiddenFramesCanSkipItems = 1;
            }
        }

        if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern))
            window->DC.LastItemStatusFlags &= ~ImGuiItemStatusFlags_HoveredRect;

        return true;
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq 0x13335e(%rip), %rax    # 0x212f40
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x1ae0(%rax), %rax
movq %rax, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x8(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xdfde0
movq -0x18(%rbp), %rax
movl 0x124(%rax), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xdfc48
movq -0x10(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0xdfc48
movb $0x0, -0x1(%rbp)
jmp 0xdff59
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb 0x130(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xdfc6a
movb $0x0, -0x1(%rbp)
jmp 0xdff59
cmpl $0x0, -0x20(%rbp)
jne 0xdfd66
movl -0x8(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xdfc9e
leaq 0x95484(%rip), %rdi     # 0x17510a
leaq 0x9327c(%rip), %rsi     # 0x172f09
movl $0x2548, %edx           # imm = 0x2548
leaq 0x957b1(%rip), %rcx     # 0x17544a
callq 0xd180
movq -0x18(%rbp), %rax
movl 0x128(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xdfcd7
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1b30(%rax)
je 0xdfcce
movq -0x10(%rbp), %rax
movq 0x1b60(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0xdfcd7
movb $0x0, -0x1(%rbp)
jmp 0xdff59
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0xd8, %rsi
addq $0x54, %rsi
callq 0xc9c90
movq -0x18(%rbp), %rcx
movl %eax, 0x124(%rcx)
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd8, %rdi
addq $0x54, %rdi
movl -0x20(%rbp), %esi
callq 0xca460
andb $0x1, %al
movb %al, -0x29(%rbp)
testb $0x1, -0x29(%rbp)
je 0xdfd45
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
testb $0x1, 0x420(%rax,%rcx)
je 0xdfd45
movl -0x20(%rbp), %edi
movq -0x18(%rbp), %rsi
callq 0xc9ec0
movq -0x18(%rbp), %rdi
callq 0xcb380
movq -0x10(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0xdfd64
movb -0x29(%rbp), %cl
movq -0x10(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x1b3d(%rax)
jmp 0xdfd71
movq -0x10(%rbp), %rax
movb $0x0, 0x1b3d(%rax)
movq -0x10(%rbp), %rax
movl 0x1b30(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0xdfd89
movb $0x0, -0x1(%rbp)
jmp 0xdff59
movq -0x18(%rbp), %rdi
addq $0xc8, %rdi
callq 0xe9130
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %edi
movss 0x921d7(%rip), %xmm0    # 0x171f80
callq 0xd4fe0
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x1b44(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x1b48(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq $-0x1, 0x1b50(%rax)
jmp 0xdfe01
movq $0x0, -0x18(%rbp)
leaq 0x9568f(%rip), %rdi     # 0x17547e
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0xc4f20
movl %eax, -0x20(%rbp)
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
je 0xdff55
movq -0x10(%rbp), %rax
testb $0x1, 0x2004(%rax)
jne 0xdfeaf
cmpl $0x0, -0x20(%rbp)
je 0xdfe24
jmp 0xdfe43
leaq 0x95661(%rip), %rdi     # 0x17548c
leaq 0x930d7(%rip), %rsi     # 0x172f09
movl $0x2577, %edx           # imm = 0x2577
leaq 0x9560c(%rip), %rcx     # 0x17544a
callq 0xd180
callq 0xd40c0
movq -0x10(%rbp), %rax
addq $0x2018, %rax           # imm = 0x2018
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x2004(%rax)
movl -0x8(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2008(%rax)
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2010(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1b30(%rcx), %eax
jne 0xdfead
movq -0x10(%rbp), %rax
movb $0x1, 0x1b3e(%rax)
jmp 0xdfeaf
movq -0x10(%rbp), %rax
movl 0x1a68(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x200c(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x2005(%rax)
movl -0x8(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xdff26
callq 0xddb50
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2078(%rax)
je 0xdff24
movq -0x10(%rbp), %rax
movl 0x206c(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0xdff24
movq -0x10(%rbp), %rax
movq 0x1ae0(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb $0x1, 0x93(%rax)
movq -0x40(%rbp), %rax
movb $0x1, 0xac(%rax)
jmp 0xdff26
movl -0x8(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xdff4f
movl -0x8(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xdff4f
movq -0x18(%rbp), %rax
movl 0x128(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x128(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xdff59
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)