// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGui::TreeNodeBehaviorIsOpen(unsigned int, int)
bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags)
{
    if (flags & ImGuiTreeNodeFlags_Leaf)
        return true;

    // We only write to the tree storage if the user clicks (or explicitly use the SetNextItemOpen function)
    ImGuiContext& g = *GImGui;
    ImGuiWindow* window = g.CurrentWindow;
    ImGuiStorage* storage = window->DC.StateStorage;

    bool is_open;
    if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasOpen)
    {
        if (g.NextItemData.OpenCond & ImGuiCond_Always)
        {
            is_open = g.NextItemData.OpenVal;
            storage->SetInt(id, is_open);
        }
        else
        {
            // We treat ImGuiCond_Once and ImGuiCond_FirstUseEver the same because tree node state are not saved persistently.
            const int stored_value = storage->GetInt(id, -1);
            if (stored_value == -1)
            {
                is_open = g.NextItemData.OpenVal;
                storage->SetInt(id, is_open);
            }
            else
            {
                is_open = stored_value != 0;
            }
        }
    }
    else
    {
        is_open = storage->GetInt(id, (flags & ImGuiTreeNodeFlags_DefaultOpen) ? 1 : 0) != 0;
    }

    // When logging is enabled, we automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
    // NB- If we are above max depth we still allow manually opened nodes to be logged.
    if (g.LogEnabled && !(flags & ImGuiTreeNodeFlags_NoAutoOpenOnLog) && (window->DC.TreeDepth - g.LogDepthRef) < g.LogDepthToExpand)
        is_open = true;

    return is_open;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x152164
movb $0x1, -0x1(%rbp)
jmp 0x15229a
leaq 0xc0dd5(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x1ae0(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x1a8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x1bf8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x15222c
movq -0x18(%rbp), %rax
movl 0x1c04(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1521dd
movq -0x18(%rbp), %rax
movb 0x1c08(%rax), %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x28(%rbp), %rdi
movl -0x8(%rbp), %esi
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0xc6380
jmp 0x15222a
movq -0x28(%rbp), %rdi
movl -0x8(%rbp), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xc5f40
movl %eax, -0x30(%rbp)
cmpl $-0x1, -0x30(%rbp)
jne 0x15221c
movq -0x18(%rbp), %rax
movb 0x1c08(%rax), %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x28(%rbp), %rdi
movl -0x8(%rbp), %esi
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0xc6380
jmp 0x152228
cmpl $0x0, -0x30(%rbp)
setne %al
andb $0x1, %al
movb %al, -0x29(%rbp)
jmp 0x15222a
jmp 0x152256
movq -0x28(%rbp), %rdi
movl -0x8(%rbp), %esi
movl -0xc(%rbp), %ecx
andl $0x20, %ecx
xorl %edx, %edx
movl $0x1, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
callq 0xc5f40
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x18(%rbp), %rax
testb $0x1, 0x3138(%rax)
je 0x152292
movl -0xc(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x152292
movq -0x20(%rbp), %rax
movl 0x18c(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x3160(%rcx), %eax
movq -0x18(%rbp), %rcx
cmpl 0x3164(%rcx), %eax
jge 0x152292
movb $0x1, -0x29(%rbp)
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)