// File: /workspace/github_c_makefile_star2_O1/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_popup_begin
NK_API nk_bool
nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type,
    const char *title, nk_flags flags, struct nk_rect rect)
{
    struct nk_window *popup;
    struct nk_window *win;
    struct nk_panel *panel;

    int title_len;
    nk_hash title_hash;
    nk_size allocated;

    NK_ASSERT(ctx);
    NK_ASSERT(title);
    NK_ASSERT(ctx->current);
    NK_ASSERT(ctx->current->layout);
    if (!ctx || !ctx->current || !ctx->current->layout)
        return 0;

    win = ctx->current;
    panel = win->layout;
    NK_ASSERT(!((int)panel->type & (int)NK_PANEL_SET_POPUP) && "popups are not allowed to have popups");
    (void)panel;
    title_len = (int)nk_strlen(title);
    title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_POPUP);

    popup = win->popup.win;
    if (!popup) {
        popup = (struct nk_window*)nk_create_window(ctx);
        popup->parent = win;
        win->popup.win = popup;
        win->popup.active = 0;
        win->popup.type = NK_PANEL_POPUP;
    }

    /* make sure we have correct popup */
    if (win->popup.name != title_hash) {
        if (!win->popup.active) {
            nk_zero(popup, sizeof(*popup));
            win->popup.name = title_hash;
            win->popup.active = 1;
            win->popup.type = NK_PANEL_POPUP;
        } else return 0;
    }

    /* popup position is local to window */
    ctx->current = popup;
    rect.x += win->layout->clip.x;
    rect.y += win->layout->clip.y;

    /* setup popup data */
    popup->parent = win;
    popup->bounds = rect;
    popup->seq = ctx->seq;
    popup->layout = (struct nk_panel*)nk_create_panel(ctx);
    popup->flags = flags;
    popup->flags |= NK_WINDOW_BORDER;
    if (type == NK_POPUP_DYNAMIC)
        popup->flags |= NK_WINDOW_DYNAMIC;

    popup->buffer = win->buffer;
    nk_start_popup(ctx, win);
    allocated = ctx->memory.allocated;
    nk_push_scissor(&popup->buffer, nk_null_rect);

    if (nk_panel_begin(ctx, title, NK_PANEL_POPUP)) {
        /* popup is running therefore invalidate parent panels */
        struct nk_panel *root;
        root = win->layout;
        while (root) {
            root->flags |= NK_WINDOW_ROM;
            root->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM;
            root = root->parent;
        }
        win->popup.active = 1;
        popup->layout->offset_x = &popup->scrollbar.x;
        popup->layout->offset_y = &popup->scrollbar.y;
        popup->layout->parent = win->layout;
        return 1;
    } else {
        /* popup was closed/is invalid so cleanup */
        struct nk_panel *root;
        root = win->layout;
        while (root) {
            root->flags |= NK_WINDOW_REMOVE_ROM;
            root = root->parent;
        }
        win->popup.buf.active = 0;
        win->popup.active = 0;
        ctx->memory.allocated = allocated;
        ctx->current = win;
        nk_free_panel(ctx, popup->layout);
        popup->layout = 0;
        return 0;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movaps %xmm1, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %rbx
testq %rdi, %rdi
jne 0x3ddbc
movq 0x4a259(%rip), %r15     # 0x87ff0
movq (%r15), %rdi
leaq 0x33feb(%rip), %rsi     # 0x71d8c
leaq 0x34002(%rip), %rdx     # 0x71daa
movl $0x51b7, %ecx           # imm = 0x51B7
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
testq %r14, %r14
jne 0x3dded
movq 0x4a228(%rip), %r15     # 0x87ff0
movq (%r15), %rdi
leaq 0x33fba(%rip), %rsi     # 0x71d8c
leaq 0x33fd1(%rip), %rdx     # 0x71daa
movl $0x51b8, %ecx           # imm = 0x51B8
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
cmpq $0x0, 0x4780(%rbx)
jne 0x3de23
movq 0x4a1f2(%rip), %r15     # 0x87ff0
movq (%r15), %rdi
leaq 0x33f84(%rip), %rsi     # 0x71d8c
leaq 0x33f9b(%rip), %rdx     # 0x71daa
movl $0x51b9, %ecx           # imm = 0x51B9
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
movq 0x4780(%rbx), %rax
cmpq $0x0, 0xa8(%rax)
jne 0x3de60
movq 0x4a1b5(%rip), %r15     # 0x87ff0
movq (%r15), %rdi
leaq 0x33f47(%rip), %rsi     # 0x71d8c
leaq 0x33f5e(%rip), %rdx     # 0x71daa
movl $0x51ba, %ecx           # imm = 0x51BA
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
xorl %r13d, %r13d
testq %rbx, %rbx
je 0x3e117
movq 0x4780(%rbx), %r15
testq %r15, %r15
je 0x3e117
movq 0xa8(%r15), %rax
testq %rax, %rax
je 0x3e117
movl %r12d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
testb $-0xc, (%rax)
je 0x3dec8
movq 0x4a14f(%rip), %r12     # 0x87ff0
movq (%r12), %rdi
leaq 0x33ee0(%rip), %rsi     # 0x71d8c
leaq 0x33ef7(%rip), %rdx     # 0x71daa
movl $0x51c0, %ecx           # imm = 0x51C0
xorl %eax, %eax
callq 0x12d80
movq (%r12), %rdi
callq 0x13780
movq %r14, %rdi
callq 0x12f10
movq %r14, %rdi
movl %eax, %esi
movl $0x4, %edx
callq 0x12560
movl %eax, %ebp
movq 0x120(%r15), %r12
testq %r12, %r12
jne 0x3df31
movq %rbx, %rdi
callq 0x576fb
testq %rax, %rax
je 0x3df09
movq %rax, %r12
movl 0x4794(%rbx), %eax
movl %eax, (%r12)
jmp 0x3df0c
xorl %r12d, %r12d
movq %r15, 0x1d8(%r12)
movq %r12, 0x120(%r15)
movl $0x0, 0x15c(%r15)
movl $0x4, 0x128(%r15)
cmpl %ebp, 0x158(%r15)
je 0x3df72
cmpl $0x0, 0x15c(%r15)
jne 0x3e117
movl $0x1e0, %esi            # imm = 0x1E0
movq %r12, %rdi
callq 0x25316
movl %ebp, 0x158(%r15)
movl $0x1, 0x15c(%r15)
movl $0x4, 0x128(%r15)
movq %r12, 0x4780(%rbx)
movq 0xa8(%r15), %rax
movsd 0x44(%rax), %xmm0
addps 0x10(%rsp), %xmm0
movq %r15, 0x1d8(%r12)
unpcklpd 0x20(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movups %xmm0, 0x4c(%r12)
movl 0x4794(%rbx), %eax
movl %eax, (%r12)
movq %rbx, %rdi
callq 0x3aec3
movq %rax, 0xa8(%r12)
xorl %eax, %eax
cmpl $0x1, 0x8(%rsp)
sete %al
shll $0xb, %eax
orl 0xc(%rsp), %eax
orl $0x1, %eax
movl %eax, 0x48(%r12)
leaq 0x68(%r12), %rdi
movups 0x68(%r15), %xmm0
movups 0x78(%r15), %xmm1
movups 0x88(%r15), %xmm2
movups 0x98(%r15), %xmm3
movups %xmm0, 0x68(%r12)
movups %xmm1, 0x78(%r12)
movups %xmm2, 0x88(%r12)
movups %xmm3, 0x98(%r12)
movdqu 0x98(%r15), %xmm0
movdqu %xmm0, 0x130(%r15)
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqu %xmm0, 0x140(%r15)
movl $0x1, 0x150(%r15)
movq 0x2560(%rbx), %rbp
movaps 0x304a9(%rip), %xmm0    # 0x6e4f0
movaps 0x304b2(%rip), %xmm1    # 0x6e500
callq 0x13a50
movq %rbx, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x3af4c
movq 0xa8(%r15), %rcx
testl %eax, %eax
je 0x3e0d7
testq %rcx, %rcx
je 0x3e092
movl $0xfffeefff, %eax       # imm = 0xFFFEEFFF
movl 0x4(%rcx), %edx
andl %eax, %edx
orl $0x1000, %edx           # imm = 0x1000
movl %edx, 0x4(%rcx)
movq 0x1c8(%rcx), %rcx
testq %rcx, %rcx
jne 0x3e078
movl $0x1, 0x15c(%r15)
leaq 0x5c(%r12), %rax
movq 0xa8(%r12), %rcx
movq %rax, 0x18(%rcx)
addq $0x60, %r12
movq %r12, 0x20(%rcx)
movq 0xa8(%r15), %rax
movq %rax, 0x1c8(%rcx)
movl $0x1, %r13d
jmp 0x3e117
orb $0x1, 0x6(%rcx)
movq 0x1c8(%rcx), %rcx
testq %rcx, %rcx
jne 0x3e0cc
xorl %r13d, %r13d
movl %r13d, 0x150(%r15)
movl %r13d, 0x15c(%r15)
movq %rbp, 0x2560(%rbx)
movq %r15, 0x4780(%rbx)
movq 0xa8(%r12), %rsi
movq %rbx, %rdi
callq 0x576ac
movq $0x0, 0xa8(%r12)
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq