// File: /workspace/github_c_makefile_star2_O3/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 0x16d35
movq 0x8(%rcx), %rcx
xorl %r13d, %r13d
cmpq (%rcx,%r13,8), %rbx
je 0x16d38
incq %r13
cmpq %r13, %rax
jne 0x16d27
xorl %r13d, %r13d
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x1e10f
movq 0x2818(%r14), %rcx
movq 0x18(%rcx), %rcx
cmpq $0x1, %rcx
jne 0x16d6b
movq 0x8(%rbx), %rdx
cmpl $0x1, (%rdx)
jne 0x16d6b
cmpq $0x1, 0x10(%rdx)
jne 0x16d6b
cmpq %rdx, %rax
je 0x16d75
cmpq $0x0, 0x27f8(%r14)
je 0x16d85
xorl %r15d, %r15d
movl %r15d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x10(%rbx), %rdi
movl (%rdi), %eax
xorl %r15d, %r15d
leal -0x1(%rax), %edx
cmpl $0x2, %edx
jae 0x16d9b
xorl %r12d, %r12d
jmp 0x16dc7
testl %eax, %eax
jne 0x16d78
addq $0x8, %rdi
movq 0x1a58(%r14), %rsi
movl 0x1a50(%r14), %edx
callq 0x1159f
movq %rax, %r15
movq %rdx, %r12
movq 0x2818(%r14), %rax
movq 0x18(%rax), %rcx
cmpq $0x2, %rcx
jl 0x16e19
movq %rbx, %rdi
callq 0x1f29c
cmpq $0x1, %rax
jne 0x16e19
movq 0x2818(%r14), %rdi
movq %rbx, %rsi
callq 0x1eeff
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 0x16e25
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x1eeff
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1ede6
movb $0x1, %r15b
testq %rax, %rax
je 0x16d78
movq %rax, 0x10(%rbx)
jmp 0x16d78