// File: /workspace/github_c_makefile_star2_O3/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, 0xc(%rsp)
movq %rdx, %r14
movl %esi, 0x8(%rsp)
movq %rdi, %rbx
testq %rdi, %rdi
jne 0x3d5a7
movq 0x49a6e(%rip), %r15     # 0x86ff0
movq (%r15), %rdi
leaq 0x33810(%rip), %rsi     # 0x70d9c
leaq 0x33827(%rip), %rdx     # 0x70dba
movl $0x51b7, %ecx           # imm = 0x51B7
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
testq %r14, %r14
jne 0x3d5d8
movq 0x49a3d(%rip), %r15     # 0x86ff0
movq (%r15), %rdi
leaq 0x337df(%rip), %rsi     # 0x70d9c
leaq 0x337f6(%rip), %rdx     # 0x70dba
movl $0x51b8, %ecx           # imm = 0x51B8
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
movq 0x4780(%rbx), %r15
testq %r15, %r15
jne 0x3d617
movq 0x49a05(%rip), %r15     # 0x86ff0
movq (%r15), %rdi
leaq 0x337a7(%rip), %rsi     # 0x70d9c
leaq 0x337be(%rip), %rdx     # 0x70dba
movl $0x51b9, %ecx           # imm = 0x51B9
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
movq 0x4780(%rbx), %r15
cmpq $0x0, 0xa8(%r15)
jne 0x3d660
movq 0x499c8(%rip), %r15     # 0x86ff0
movq (%r15), %rdi
leaq 0x3376a(%rip), %rsi     # 0x70d9c
leaq 0x33781(%rip), %rdx     # 0x70dba
xorl %r13d, %r13d
movl $0x51ba, %ecx           # imm = 0x51BA
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
movq 0x4780(%rbx), %r15
testq %r15, %r15
je 0x3d8f4
movq 0xa8(%r15), %rax
xorl %r13d, %r13d
testq %rax, %rax
je 0x3d8f4
testb $-0xc, (%rax)
je 0x3d6a6
movq 0x49971(%rip), %r12     # 0x86ff0
movq (%r12), %rdi
leaq 0x33712(%rip), %rsi     # 0x70d9c
leaq 0x33729(%rip), %rdx     # 0x70dba
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 0x3d70a
movq %rbx, %rdi
callq 0x56b07
movq %rax, %r12
testq %rax, %rax
je 0x3d6e5
movl 0x4794(%rbx), %eax
movl %eax, (%r12)
movq %r15, 0x1d8(%r12)
movq %r12, 0x120(%r15)
movl $0x0, 0x15c(%r15)
movl $0x4, 0x128(%r15)
cmpl %ebp, 0x158(%r15)
je 0x3d74b
cmpl $0x0, 0x15c(%r15)
jne 0x3d8f4
movl $0x1e0, %esi            # imm = 0x1E0
movq %r12, %rdi
callq 0x2542e
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 0x3a740
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 0x2fcd0(%rip), %xmm0    # 0x6d4f0
movaps 0x2fcd9(%rip), %xmm1    # 0x6d500
callq 0x13a50
movq %rbx, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x3a7b3
movq 0xa8(%r15), %rcx
testl %eax, %eax
je 0x3d87f
testq %rcx, %rcx
je 0x3d8c1
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 0x3d851
movq 0xa8(%r15), %rax
jmp 0x3d8c3
orb $0x1, 0x6(%rcx)
movq 0x1c8(%rcx), %rcx
testq %rcx, %rcx
jne 0x3d874
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 0x56ab8
movq $0x0, 0xa8(%r12)
jmp 0x3d8f4
xorl %eax, %eax
movl $0x1, 0x15c(%r15)
leaq 0x5c(%r12), %rcx
movq 0xa8(%r12), %rdx
movq %rcx, 0x18(%rdx)
addq $0x60, %r12
movq %r12, 0x20(%rdx)
movq %rax, 0x1c8(%rdx)
movl $0x1, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq