// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andq $0x0, (%rsp)
movq %rdi, %r14
movq 0x2818(%rdi), %rax
movq 0x10(%rax), %rbx
movq 0x18(%rax), %rcx
xorl %r13d, %r13d
testq %rcx, %rcx
cmovleq %r13, %rcx
cmpq %r13, %rcx
je 0x1635d
movq 0x8(%rax), %rdx
cmpq (%rdx,%r13,8), %rbx
je 0x16360
incq %r13
jmp 0x16349
xorl %r13d, %r13d
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x1c2a3
movq 0x2818(%r14), %rcx
movq 0x18(%rcx), %rbp
cmpq $0x1, %rbp
jne 0x16393
movq 0x8(%rbx), %rcx
cmpl $0x1, (%rcx)
jne 0x16393
cmpq $0x1, 0x10(%rcx)
jne 0x16393
cmpq %rcx, %rax
je 0x163e0
cmpq $0x0, 0x27f8(%r14)
jne 0x163e0
movq %rsp, %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x15e3a
testb %al, %al
je 0x163e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x163f1
movq 0x1a58(%r14), %rsi
movl 0x1a50(%r14), %edx
callq 0x10ec2
movq %rax, %r15
movq %rdx, %r12
movq 0x2818(%r14), %rax
movq 0x18(%rax), %rbp
jmp 0x163f7
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq $0x2, %rbp
jl 0x16449
movq %rbx, %rdi
callq 0x1d50a
cmpq $0x1, %rax
jne 0x16449
movq 0x2818(%r14), %rdi
movq %rbx, %rsi
callq 0x1d151
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 0x16455
movq 0x10(%rbx), %rsi
movq %rbx, %rdi
callq 0x1d151
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1d04c
movq %rax, %rcx
movb $0x1, %al
testq %rcx, %rcx
je 0x163e2
movq %rcx, 0x10(%rbx)
jmp 0x163e2