// File: /workspace/github_c_makefile_star2_O0/justy989[P]ce/ce_layout.c
// Function: ce_layout_delete
bool ce_layout_delete(CeLayout_t* root, CeLayout_t* node){
     CeLayout_t* parent = ce_layout_find_parent(root, node);
     if(!parent) return false;

     switch(parent->type){
     default:
          return false;
     case CE_LAYOUT_TYPE_LIST:
     {
          CeRect_t parent_rect = ce_layout_rect(parent);

          // find index of matching node
          int64_t index = -1;
          for(int64_t i = 0; i < parent->list.layout_count; i++){
               if(parent->list.layouts[i] == node){
                    index = i;
                    break;
               }
          }

          if(index == -1) return false;

          ce_layout_free(&node);

          // remove element, keeping element order
          int64_t new_count = parent->list.layout_count - 1;
          for(int64_t i = index; i < new_count; i++){
               parent->list.layouts[i] = parent->list.layouts[i + 1];
          }
          parent->list.layout_count = new_count;
          ce_layout_distribute_rect(parent, parent_rect);
          assert(!(parent->list.layout_count == 0 && parent == root));

          if(new_count == 0){
              return ce_layout_delete(root, parent);
          }else if(new_count == 1){
               // reduce back to a single layout
               CeLayout_t* grandparent = ce_layout_find_parent(root, parent);
               if(!grandparent) return true;

               switch(grandparent->type){
               default:
                    return false;
               case CE_LAYOUT_TYPE_LIST:
                    // replace the parent at that element
                    for(int64_t i = 0; i < grandparent->list.layout_count; i++){
                         if(grandparent->list.layouts[i] == parent){
                              grandparent->list.layouts[i] = parent->list.layouts[0];
                              parent->list.layouts[0] = NULL;
                              break;
                         }
                    }
                    break;
               case CE_LAYOUT_TYPE_TAB:
                    grandparent->tab.root = parent->list.layouts[0];
                    parent->list.layouts[0] = NULL;
                    break;
               case CE_LAYOUT_TYPE_TAB_LIST:
                    return false;
               }

               ce_layout_free(&parent);
          }
     } break;
     case CE_LAYOUT_TYPE_TAB:
          break;
     case CE_LAYOUT_TYPE_TAB_LIST:
     {
          // find index of matching node
          int64_t index = -1;
          for(int64_t i = 0; i < parent->tab_list.tab_count; i++){
               if(parent->tab_list.tabs[i] == node){
                    index = i;
                    break;
               }
          }

          if(index == -1) return false;

          ce_layout_free(&node);

          // remove element, keeping element order
          int64_t new_count = parent->tab_list.tab_count - 1;
          for(int64_t i = index; i < new_count; i++){
               parent->tab_list.tabs[i] = parent->tab_list.tabs[i + 1];
          }
          parent->tab_list.tab_count = new_count;
     } break;
     }

     return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x281b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x29fa4
movb $0x0, -0x1(%rbp)
jmp 0x2a32f
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
subl $0x1, %eax
je 0x29fe2
jmp 0x29fb7
movl -0x94(%rbp), %eax
subl $0x2, %eax
je 0x2a247
jmp 0x29fc8
movl -0x94(%rbp), %eax
subl $0x3, %eax
je 0x2a24c
jmp 0x29fd9
movb $0x0, -0x1(%rbp)
jmp 0x2a32f
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x28450
movq $-0x1, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x2a03d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x18(%rbp), %rax
jne 0x2a02d
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x2a03d
jmp 0x2a02f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x29fff
cmpq $-0x1, -0x48(%rbp)
jne 0x2a04d
movb $0x0, -0x1(%rbp)
jmp 0x2a32f
leaq -0x18(%rbp), %rdi
callq 0x27ba0
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x2a0a7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x2a06e
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rdi
leaq -0x40(%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 -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x2a0f7
movq -0x20(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x2a0f9
jmp 0x2a118
leaq 0x1abf7(%rip), %rdi     # 0x44cf7
leaq 0x1ab02(%rip), %rsi     # 0x44c09
movl $0x356, %edx            # imm = 0x356
leaq 0x1ac18(%rip), %rcx     # 0x44d2b
callq 0xd270
cmpq $0x0, -0x58(%rbp)
jne 0x2a136
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x29f70
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x2a32f
cmpq $0x1, -0x58(%rbp)
jne 0x2a240
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x281b0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x2a162
movb $0x1, -0x1(%rbp)
jmp 0x2a32f
movq -0x68(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x98(%rbp)
subl $0x1, %eax
je 0x2a1a0
jmp 0x2a175
movl -0x98(%rbp), %eax
subl $0x2, %eax
je 0x2a20a
jmp 0x2a186
movl -0x98(%rbp), %eax
subl $0x3, %eax
je 0x2a22e
jmp 0x2a197
movb $0x0, -0x1(%rbp)
jmp 0x2a32f
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x2a208
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x20(%rbp), %rax
jne 0x2a1f8
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, (%rax)
jmp 0x2a208
jmp 0x2a1fa
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x2a1a8
jmp 0x2a237
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, (%rax)
jmp 0x2a237
movb $0x0, -0x1(%rbp)
jmp 0x2a32f
leaq -0x20(%rbp), %rdi
callq 0x27ba0
jmp 0x2a242
jmp 0x2a32b
jmp 0x2a32b
movq $-0x1, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x2a29a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x18(%rbp), %rax
jne 0x2a28a
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x2a29a
jmp 0x2a28c
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x2a25c
cmpq $-0x1, -0x78(%rbp)
jne 0x2a2aa
movb $0x0, -0x1(%rbp)
jmp 0x2a32f
leaq -0x18(%rbp), %rdi
callq 0x27ba0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
subq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jge 0x2a31c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x90(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x90(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x2a2d1
movq -0x88(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)