// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_commands.c
// Function: delete_layout
static bool delete_layout(CeApp_t* app){
     CeView_t* view = NULL;
     CeRect_t view_rect = {};
     int64_t current_index = 0;
     CeLayout_t* tab_layout = app->tab_list_layout->tab_list.current;

     for(int64_t i = 0; i < app->tab_list_layout->tab_list.tab_count; i++){
          if(app->tab_list_layout->tab_list.current == app->tab_list_layout->tab_list.tabs[i]){
               current_index = i;
               break;
          }
     }

     CeLayout_t* parent_of_current = ce_layout_find_parent(tab_layout->tab.root, tab_layout->tab.current);

     // check if this is the only view, and ignore the delete request
     if(app->tab_list_layout->tab_list.tab_count == 1 &&
        tab_layout->tab.root->type == CE_LAYOUT_TYPE_LIST &&
        tab_layout->tab.root->list.layout_count == 1 &&
        parent_of_current == tab_layout->tab.root){
          return false;
     }

     if(app->input_complete_func) return false;

     if(!get_view_info_from_tab(tab_layout, &view, &view_rect)){
          return false;
     }

     CePoint_t cursor = {0, 0};
     if(view) cursor = view_cursor_on_screen(view, app->config_options.tab_width, app->config_options.line_number);

     if(app->tab_list_layout->tab_list.tab_count > 1 && ce_layout_tab_get_layout_count(tab_layout) == 1){
          ce_layout_delete(app->tab_list_layout, tab_layout);
          if(current_index >= app->tab_list_layout->tab_list.tab_count){
               current_index = app->tab_list_layout->tab_list.tab_count - 1;
          }
          app->tab_list_layout->tab_list.current = app->tab_list_layout->tab_list.tabs[current_index];
          tab_layout = app->tab_list_layout->tab_list.current;
     }else{
          ce_layout_delete(tab_layout, tab_layout->tab.current);
     }

     CeLayout_t* layout = ce_layout_find_at(tab_layout, cursor);
     if(layout) tab_layout->tab.current = layout;

     return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %r14
movq 0x2818(%rdi), %rcx
movq 0x10(%rcx), %rbx
movq 0x18(%rcx), %rax
testq %rax, %rax
jle 0x1713c
movq 0x8(%rcx), %rcx
xorl %r13d, %r13d
cmpq (%rcx,%r13,8), %rbx
je 0x1713f
incq %r13
cmpq %r13, %rax
jne 0x1712e
xorl %r13d, %r13d
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x1dde1
movq 0x2818(%r14), %rcx
cmpq $0x1, 0x18(%rcx)
jne 0x1716f
movq 0x8(%rbx), %rcx
cmpl $0x1, (%rcx)
jne 0x1716f
cmpq $0x1, 0x10(%rcx)
jne 0x1716f
cmpq %rcx, %rax
je 0x171c3
cmpq $0x0, 0x27f8(%r14)
jne 0x171c3
movq 0x10(%rbx), %rdi
movl (%rdi), %eax
cmpl $0x2, %eax
je 0x17195
cmpl $0x1, %eax
je 0x17195
testl %eax, %eax
jne 0x1719b
addq $0x8, %rdi
movb $0x1, %al
jmp 0x1719f
movb $0x1, %al
xorl %edi, %edi
jmp 0x1719f
xorl %edi, %edi
xorl %eax, %eax
testb %al, %al
je 0x171c3
testq %rdi, %rdi
je 0x171cf
movq 0x1a58(%r14), %rsi
movl 0x1a50(%r14), %edx
callq 0x117a6
movq %rax, %r15
movq %rdx, %r12
jmp 0x171d5
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x2818(%r14), %rax
cmpq $0x2, 0x18(%rax)
jl 0x1722f
movq %rbx, %rdi
callq 0x1f30d
cmpq $0x1, %rax
jne 0x1722f
movq 0x2818(%r14), %rdi
movq %rbx, %rsi
callq 0x1eeec
movq 0x2818(%r14), %rax
movq 0x8(%rax), %rcx
movq 0x18(%rax), %rdx
leaq -0x1(%rdx), %rsi
cmpq %rdx, %r13
cmovlq %r13, %rsi
movq (%rcx,%rsi,8), %rcx
movq %rcx, 0x10(%rax)
movq 0x2818(%r14), %rax
movq 0x10(%rax), %rbx
jmp 0x1723b
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x1eeec
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1ed8e
movq %rax, %rcx
movb $0x1, %al
testq %rcx, %rcx
je 0x171c5
movq %rcx, 0x10(%rbx)
jmp 0x171c5