// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_app.c
// Function: ce_app_open_popup_view
bool ce_app_open_popup_view(CeApp_t* app, CeBuffer_t* buffer){
     CeLayout_t* tab_layout = app->tab_list_layout->tab_list.current;
     if(tab_layout->type != CE_LAYOUT_TYPE_TAB){
         return false;
     }

     // If the split already exists, just re-use it.
     CeLayout_t* popup_layout = ce_layout_find_popup(app->tab_list_layout);
     if(popup_layout){
         if(popup_layout->type == CE_LAYOUT_TYPE_VIEW){
             popup_layout->view.buffer = buffer;
             popup_layout->view.scroll = (CePoint_t){0, 0};
             app->last_popup_buffer = buffer;
             return true;
         }
         ce_log("error layout at active view position not view type\n");
         return false;
     }

     // Find the highest level parent layout that isn't a tab, which should be a list.
     CeLayout_t* parent_layout = ce_layout_find_parent(tab_layout->tab.root, tab_layout->tab.current);
     CeLayout_t* save_current = tab_layout->tab.current;
     CeLayout_t* new_parent_layout = NULL;
     while(parent_layout){
         new_parent_layout = ce_layout_find_parent(tab_layout->tab.root, parent_layout);
         if(!new_parent_layout || new_parent_layout->type == CE_LAYOUT_TYPE_TAB){
             break;
         }
         parent_layout = new_parent_layout;
     }
     if(parent_layout != NULL){
         tab_layout->tab.current = parent_layout;
     }else{
         parent_layout = tab_layout->tab.current;
     }

     // split the layout
     bool vertical = true;
     bool always_add_last = true;
     CeLayout_t* new_layout = ce_layout_split(tab_layout, vertical, always_add_last);
     if(new_layout == NULL){
         return false;
     }
     new_layout->view.buffer = buffer;
     new_layout->view.scroll = (CePoint_t){0, 0};
     new_layout->popup = true;

     // shrink the window after the even split.
     CePoint_t parent_point = {parent_layout->list.rect.left, parent_layout->list.rect.bottom};
     CeLayout_t* layout_to_resize = ce_layout_find_at(app->tab_list_layout, parent_point);
     int64_t current_popup_height = (new_layout->view.rect.bottom - new_layout->view.rect.top);
     if(layout_to_resize && app->config_options.popup_view_height < current_popup_height &&
        app->config_options.popup_view_height < app->terminal_rect.bottom){
         int64_t popup_resize_delta = current_popup_height - app->config_options.popup_view_height;
         ce_layout_resize_rect(app->tab_list_layout, layout_to_resize, app->terminal_rect, CE_DOWN, true, popup_resize_delta);
         if(parent_layout->type != CE_LAYOUT_TYPE_VIEW){
             ce_layout_distribute_rect(parent_layout, parent_layout->list.rect);
         }
     }
     app->last_popup_buffer = buffer;
     tab_layout->tab.current = save_current;
     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movq 0x2818(%rdi), %rdi
movq 0x10(%rdi), %r15
cmpl $0x2, (%r15)
jne 0x1338a
movq %rsi, %rbx
callq 0x1d0e4
testq %rax, %rax
je 0x13283
cmpl $0x0, (%rax)
je 0x132b8
leaq 0x18bfe(%rip), %rdi     # 0x2be73
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd8e5
jmp 0x1338c
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
callq 0x1c2a3
movq 0x10(%r15), %rbp
testq %rax, %rax
je 0x132cf
movq %rax, %r12
movq 0x8(%r15), %rdi
movq %rax, %rsi
callq 0x1c2a3
testq %rax, %rax
je 0x132b2
cmpl $0x2, (%rax)
jne 0x13294
movq %r12, 0x10(%r15)
jmp 0x132d3
movq %rbx, 0x48(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rax)
movq %rbx, 0x2dd0(%r14)
jmp 0x13386
movq 0x10(%r15), %r12
pushq $0x1
popq %rdx
movq %r15, %rdi
movl %edx, %esi
callq 0x1c04f
testq %rax, %rax
je 0x1338a
movq %rax, %r13
movq %rbx, 0x48(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rax)
movb $0x1, 0x58(%rax)
movq 0x20(%r12), %rsi
movq 0x38(%r12), %rdx
movq 0x2818(%r14), %rdi
callq 0x1d04c
testq %rax, %rax
je 0x1337b
movq 0x20(%r13), %r8
subq 0x18(%r13), %r8
movslq 0x26f8(%r14), %rcx
subq %rcx, %r8
jle 0x1337b
cmpq %rcx, 0x18(%r14)
jle 0x1337b
movq 0x2818(%r14), %rdi
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x3
popq %rdx
pushq $0x1
popq %rcx
movq %rax, %rsi
callq 0x1c6e2
cmpl $0x0, (%r12)
je 0x1337b
leaq 0x20(%r12), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x1c4ba
movq %rbx, 0x2dd0(%r14)
movq %rbp, 0x10(%r15)
movb $0x1, %bl
jmp 0x1338c
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq