// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, 0x28(%rsp)
callq 0x1dde1
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x1f061
movq %rax, %rbx
movl (%rax), %eax
cmpl $0x1, %eax
je 0x1ef62
cmpl $0x2, %eax
je 0x1f0ef
cmpl $0x3, %eax
jne 0x1f061
movq 0x18(%rbx), %rax
movq $-0x1, %r14
testq %rax, %rax
jle 0x1f023
movq 0x8(%rbx), %rdx
xorl %ecx, %ecx
cmpq %r15, (%rdx,%rcx,8)
je 0x1f020
incq %rcx
cmpq %rcx, %rax
jne 0x1ef4b
jmp 0x1f023
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x1dfb8
movq 0x10(%rbx), %rax
movq $-0x1, %r12
testq %rax, %rax
jle 0x1ef98
movq 0x8(%rbx), %rdx
xorl %ecx, %ecx
cmpq %r15, (%rdx,%rcx,8)
je 0x1ef95
incq %rcx
cmpq %rcx, %rax
jne 0x1ef85
jmp 0x1ef98
movq %rcx, %r12
cmpq $-0x1, %r12
je 0x1f0a3
leaq 0x28(%rsp), %rdi
callq 0x1da6f
movq 0x10(%rbx), %r15
leaq -0x1(%r15), %rax
cmpq %rax, %r12
jge 0x1efd1
incq %r12
movq 0x8(%rbx), %rcx
movq (%rcx,%r12,8), %rdx
movq %rdx, -0x8(%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0x1efbc
movq %rax, 0x10(%rbx)
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x1e0a5
cmpq %r14, %rbx
jne 0x1f000
cmpq $0x0, 0x10(%rbx)
je 0x1f0ff
cmpq $0x2, %r15
je 0x1f068
cmpq $0x1, %r15
jne 0x1f0e9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1eeec
jmp 0x1f0ab
movq %rcx, %r14
cmpq $-0x1, %r14
je 0x1f061
leaq 0x28(%rsp), %rdi
callq 0x1da6f
movq 0x18(%rbx), %rcx
leaq -0x1(%rcx), %rax
cmpq %rax, %r14
jge 0x1f058
incq %r14
movq 0x8(%rbx), %rdx
movq (%rdx,%r14,8), %rsi
movq %rsi, -0x8(%rdx,%r14,8)
incq %r14
cmpq %r14, %rcx
jne 0x1f043
movq %rax, 0x18(%rbx)
jmp 0x1f0ef
xorl %eax, %eax
jmp 0x1f0f1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1dde1
testq %rax, %rax
je 0x1f0a9
movl (%rax), %ecx
cmpl $0x2, %ecx
je 0x1f0af
cmpl $0x1, %ecx
jne 0x1f0a3
movq 0x10(%rax), %rcx
testq %rcx, %rcx
jle 0x1f0df
movq 0x8(%rax), %rax
xorl %edx, %edx
cmpq %rbx, (%rax,%rdx,8)
je 0x1f0c3
incq %rdx
cmpq %rdx, %rcx
jne 0x1f093
jmp 0x1f0df
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x1f0eb
movb $0x1, %al
xorl %ecx, %ecx
jmp 0x1f0eb
movq %rbx, %rcx
addq $0x8, %rcx
movq 0x8(%rbx), %rdx
movq (%rdx), %rdx
movq %rdx, 0x8(%rax)
jmp 0x1f0d5
movq %rbx, %rcx
addq $0x8, %rcx
movq 0x8(%rbx), %rsi
movq (%rsi), %rsi
movq %rsi, (%rax,%rdx,8)
movq (%rcx), %rax
movq $0x0, (%rax)
leaq 0x30(%rsp), %rdi
callq 0x1da6f
movb $0x1, %cl
testb %cl, %cl
je 0x1f0f1
movb $0x1, %al
andb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x11bfd(%rip), %rdi     # 0x30d03
leaq 0x11b08(%rip), %rsi     # 0x30c15
leaq 0x11c23(%rip), %rcx     # 0x30d37
movl $0x356, %edx            # imm = 0x356
callq 0xd280