// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce_layout.c
// Function: ce_layout_split
CeLayout_t* ce_layout_split(CeLayout_t* layout, bool vertical, bool always_add_last){
     assert(layout->type == CE_LAYOUT_TYPE_TAB);
     CeLayout_t* parent_of_current = ce_layout_find_parent(layout, layout->tab.current);
     if(parent_of_current){
          CeBuffer_t* buffer = ce_layout_find_buffer(layout->tab.current);
          assert(buffer);
          switch(parent_of_current->type){
          default:
               break;
          case CE_LAYOUT_TYPE_LIST:
               if(parent_of_current->list.vertical == vertical){
                    CeRect_t parent_layout_rect = ce_layout_rect(parent_of_current);
                    CeLayout_t* new_layout = ce_layout_view_init(buffer);
                    if(!new_layout) return NULL;
                    new_layout->view.scroll = layout->tab.current->view.scroll;
                    new_layout->view.cursor = layout->tab.current->view.cursor;

                    int64_t split_layout_index = 0;
                    if(always_add_last){
                        split_layout_index = parent_of_current->list.layout_count;
                    }else{
                        for(int64_t i = 0; i < parent_of_current->list.layout_count; i++){
                             if(parent_of_current->list.layouts[i] == layout->tab.current){
                                  split_layout_index = i;
                                  break;
                             }
                        }
                    }

                    int64_t new_layout_count = parent_of_current->list.layout_count + 1;
                    parent_of_current->list.layouts = realloc(parent_of_current->list.layouts,
                                                              new_layout_count * sizeof(*parent_of_current->list.layouts));
                    if(parent_of_current->list.layouts){
                         parent_of_current->list.layout_count = new_layout_count;
                    }else{
                         return NULL;
                    }

                    // shift down the rest of the layouts first
                    for(int64_t i = parent_of_current->list.layout_count - 1; i > split_layout_index; i--){
                         parent_of_current->list.layouts[i] = parent_of_current->list.layouts[i - 1];
                    }
                    parent_of_current->list.layouts[split_layout_index] = new_layout;
                    ce_layout_distribute_rect(parent_of_current, parent_layout_rect);
                    layout->tab.current = new_layout;
                    return new_layout;
               }else{
                    CeLayout_t* new_list_layout = calloc(1, sizeof(*new_list_layout));
                    if(!new_list_layout) return NULL;
                    new_list_layout->type = CE_LAYOUT_TYPE_LIST;
                    new_list_layout->list.layouts = malloc(sizeof(*new_list_layout->list.layouts));
                    if(!new_list_layout->list.layouts) return NULL;
                    new_list_layout->list.layout_count = 1;
                    new_list_layout->list.vertical = vertical;
                    new_list_layout->list.layouts[0] = layout->tab.current;

                    // point parent at new list
                    for(int64_t i = 0; i < parent_of_current->list.layout_count; i++){
                         if(parent_of_current->list.layouts[i] == layout->tab.current){
                              parent_of_current->list.layouts[i] = new_list_layout;
                              break;
                         }
                    }

                    return ce_layout_split(layout, vertical, always_add_last);
               }
               break;
          case CE_LAYOUT_TYPE_TAB:
          {
               CeLayout_t* list_layout = calloc(1, sizeof(*list_layout));
               list_layout->type = CE_LAYOUT_TYPE_LIST;
               list_layout->list.layout_count = 1;
               list_layout->list.layouts = calloc(list_layout->list.layout_count, sizeof(*list_layout->list.layouts));
               list_layout->list.layouts[0] = layout->tab.current;
               list_layout->list.vertical = vertical;

               parent_of_current->tab.root = list_layout;

               return ce_layout_split(layout, vertical, always_add_last);
          } break;
          case CE_LAYOUT_TYPE_TAB_LIST:
               if(layout->tab_list.current) return ce_layout_split(layout->tab_list.current,
                                                                   vertical, always_add_last);
               break;
          }
     }

     return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movb %dl, %al
movb %sil, %cl
movq %rdi, -0x10(%rbp)
andb $0x1, %cl
movb %cl, -0x11(%rbp)
andb $0x1, %al
movb %al, -0x12(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x27d1a
jmp 0x27d39
leaq 0x1cf25(%rip), %rdi     # 0x44c46
leaq 0x1cee1(%rip), %rsi     # 0x44c09
movl $0xb1, %edx
leaq 0x1cf35(%rip), %rcx     # 0x44c69
callq 0xd270
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x281b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x28195
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x28330
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x27d73
jmp 0x27d92
leaq 0x1c76d(%rip), %rdi     # 0x444e7
leaq 0x1ce88(%rip), %rsi     # 0x44c09
movl $0xb5, %edx
leaq 0x1cedc(%rip), %rcx     # 0x44c69
callq 0xd270
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
subl $0x1, %eax
je 0x27dcc
jmp 0x27da5
movl -0x8c(%rbp), %eax
subl $0x2, %eax
je 0x280b8
jmp 0x27db6
movl -0x8c(%rbp), %eax
subl $0x3, %eax
je 0x28162
jmp 0x27dc7
jmp 0x28193
movq -0x20(%rbp), %rax
movb 0x18(%rax), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x11(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x27fb5
movq -0x20(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x28450
movq -0x28(%rbp), %rdi
callq 0x27b20
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x27e17
movq $0x0, -0x8(%rbp)
jmp 0x2819d
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x28(%rcx), %rdx
movq %rdx, 0x28(%rax)
movq 0x30(%rcx), %rcx
movq %rcx, 0x30(%rax)
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x38(%rcx), %rdx
movq %rdx, 0x38(%rax)
movq 0x40(%rcx), %rcx
movq %rcx, 0x40(%rax)
movq $0x0, -0x58(%rbp)
testb $0x1, -0x12(%rbp)
je 0x27e6b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x27eb7
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x27eb5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x27ea5
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x27eb5
jmp 0x27ea7
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x27e73
jmp 0x27eb7
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x68(%rbp), %rsi
shlq $0x3, %rsi
callq 0xd500
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x27f00
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x27f0d
movq $0x0, -0x8(%rbp)
jmp 0x2819d
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x58(%rbp), %rax
jle 0x27f59
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x27f1d
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rdi
leaq -0x48(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x285c0
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2819d
movl $0x1, %edi
movl $0x60, %esi
callq 0xd360
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x27fdc
movq $0x0, -0x8(%rbp)
jmp 0x2819d
movq -0x78(%rbp), %rax
movl $0x1, (%rax)
movl $0x8, %edi
callq 0xd4a0
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x78(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x28013
movq $0x0, -0x8(%rbp)
jmp 0x2819d
movq -0x78(%rbp), %rax
movq $0x1, 0x10(%rax)
movb -0x11(%rbp), %cl
movq -0x78(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x28095
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x28085
movq -0x78(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x80(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x28095
jmp 0x28087
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x28047
movq -0x10(%rbp), %rdi
movb -0x11(%rbp), %cl
movb -0x12(%rbp), %al
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %esi
movzbl %al, %edx
callq 0x27cf0
movq %rax, -0x8(%rbp)
jmp 0x2819d
movl $0x1, %edi
movl $0x60, %esi
callq 0xd360
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl $0x1, (%rax)
movq -0x88(%rbp), %rax
movq $0x1, 0x10(%rax)
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x8, %esi
callq 0xd360
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movb -0x11(%rbp), %cl
movq -0x88(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x18(%rax)
movq -0x88(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movb -0x11(%rbp), %cl
movb -0x12(%rbp), %al
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %esi
movzbl %al, %edx
callq 0x27cf0
movq %rax, -0x8(%rbp)
jmp 0x2819d
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x28191
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movb -0x11(%rbp), %cl
movb -0x12(%rbp), %al
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %esi
movzbl %al, %edx
callq 0x27cf0
movq %rax, -0x8(%rbp)
jmp 0x2819d
jmp 0x28193
jmp 0x28195
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)