// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_layout.c
// Function: ce_layout_distribute_rect
void ce_layout_distribute_rect(CeLayout_t* layout, CeRect_t rect){
     switch(layout->type){
     default:
          break;
     case CE_LAYOUT_TYPE_VIEW:
          layout->view.rect = rect;
          break;
     case CE_LAYOUT_TYPE_LIST:
     {
          layout->list.rect = rect;
          CeRect_t sliced_rect = rect;
          int64_t separator_lines = layout->list.layout_count - 1;

          if(layout->list.vertical){
               assert(layout->list.layout_count != 0);
               int64_t rect_height = rect.bottom - rect.top;
               int64_t slice_height = (rect_height - separator_lines) / layout->list.layout_count;
               int64_t leftover_lines = (rect_height - separator_lines) % layout->list.layout_count;
               sliced_rect.bottom = sliced_rect.top + slice_height;

               for(int64_t i = 0; i < layout->list.layout_count; i++){
                    if(leftover_lines > 0){
                         leftover_lines--;
                         sliced_rect.bottom++;
                    }

                    ce_layout_distribute_rect(layout->list.layouts[i], sliced_rect);

                    sliced_rect.top = sliced_rect.bottom + 1;
                    sliced_rect.bottom = sliced_rect.top + slice_height;
               }
          }else{
               assert(layout->list.layout_count != 0);
               int64_t rect_width = rect.right - rect.left;
               int64_t slice_width = (rect_width - separator_lines) / layout->list.layout_count;
               int64_t leftover_lines = (rect_width - separator_lines) % layout->list.layout_count;
               sliced_rect.right = sliced_rect.left + slice_width;

               for(int64_t i = 0; i < layout->list.layout_count; i++){
                    if(leftover_lines > 0){
                         leftover_lines--;
                         sliced_rect.right++;
                    }

                    ce_layout_distribute_rect(layout->list.layouts[i], sliced_rect);

                    sliced_rect.left = sliced_rect.right + 1;
                    sliced_rect.right = sliced_rect.left + slice_width;
               }
          }
     } break;
     case CE_LAYOUT_TYPE_TAB:
          layout->tab.rect = rect;
          ce_layout_distribute_rect(layout->tab.root, rect);
          break;
     case CE_LAYOUT_TYPE_TAB_LIST:
          layout->tab_list.rect = rect;
          if(layout->tab_list.tab_count > 1) rect.top++; // leave space for a tab bar, this probably doesn't want to be built in?
          ce_layout_distribute_rect(layout->tab_list.current, rect);
          break;
     }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
leaq 0xb0(%rsp), %rcx
movq 0x10(%rcx), %rax
leaq 0x106ba(%rip), %rdx     # 0x2cb98
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdi
movl (%rbx), %r8d
cmpq $0x3, %r8
ja 0x1c55b
movslq (%rdx,%r8,4), %r8
addq %rdx, %r8
jmpq *%r8
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x28(%rbx)
movups %xmm0, 0x18(%rbx)
addq $0x8, %rbx
movq %rsi, %r8
jmp 0x1c537
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
cmpq $0x2, 0x18(%rbx)
jl 0x1c530
incq %rax
movq %rax, 0x10(%rcx)
addq $0x10, %rbx
movq %rdi, %r8
movq (%rbx), %rbx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%r8)
movups %xmm0, (%r8)
jmp 0x1c4e8
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x18(%rbx)
movups %xmm0, 0x8(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x10(%rbx), %rsi
pushq $0x1
popq %rax
subq %rsi, %rax
cmpb $0x1, 0x18(%rbx)
jne 0x1c61e
testq %rsi, %rsi
je 0x1c6a4
addq 0x18(%rcx), %rax
subq 0x10(%rcx), %rax
cqto
idivq %rsi
movq %rax, %r14
movq %rdx, %r15
movq 0x30(%rsp), %rax
addq %r14, %rax
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
cmpq 0x10(%rbx), %r12
jge 0x1c55b
testq %r15, %r15
jle 0x1c5e0
decq %r15
incq %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rbx), %rax
movq (%rax,%r12,8), %rdi
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1c4ba
movq 0x38(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%rsp)
addq %r14, %rax
incq %rax
movq %rax, 0x38(%rsp)
incq %r12
jmp 0x1c5ca
testq %rsi, %rsi
je 0x1c6c3
addq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %rsi
movq %rax, %r14
movq %rdx, %r15
movq 0x20(%rsp), %rax
addq %r14, %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
cmpq %rsi, %r12
jge 0x1c55b
testq %r15, %r15
jle 0x1c662
decq %r15
incq %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rbx), %rax
movq (%rax,%r12,8), %rdi
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x1c4ba
movq 0x28(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
addq %r14, %rax
incq %rax
movq %rax, 0x28(%rsp)
incq %r12
movq 0x10(%rbx), %rsi
jmp 0x1c649
leaq 0x1064e(%rip), %rdi     # 0x2ccf9
leaq 0x105af(%rip), %rsi     # 0x2cc61
leaq 0x1065f(%rip), %rcx     # 0x2cd18
movl $0x118, %edx            # imm = 0x118
callq 0xd280
leaq 0x1062f(%rip), %rdi     # 0x2ccf9
leaq 0x10590(%rip), %rsi     # 0x2cc61
leaq 0x10640(%rip), %rcx     # 0x2cd18
movl $0x12a, %edx            # imm = 0x12A
callq 0xd280