// File: /workspace/github_c_makefile_star2_O3/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 0x118ce(%rip), %rdx     # 0x2fc00
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdi
movl (%rbx), %r8d
cmpq $0x3, %r8
ja 0x1e4fe
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 0x1e38f
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
cmpq $0x2, 0x18(%rbx)
jl 0x1e388
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 0x1e33c
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x18(%rbx)
movups %xmm0, 0x8(%rbx)
jmp 0x1e4fe
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
movl $0x1, %eax
subq %rsi, %rax
cmpb $0x1, 0x18(%rbx)
jne 0x1e47c
testq %rsi, %rsi
je 0x1e50d
addq 0x18(%rcx), %rax
subq 0x10(%rcx), %rax
cqto
idivq %rsi
movq %rax, %r14
movq 0x30(%rsp), %rax
addq %r14, %rax
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x10(%rbx)
jle 0x1e4fe
movq %rdx, %r15
xorl %r12d, %r12d
testq %r15, %r15
jle 0x1e435
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 0x1e30e
movq 0x38(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%rsp)
addq %r14, %rax
incq %rax
movq %rax, 0x38(%rsp)
incq %r12
cmpq 0x10(%rbx), %r12
jl 0x1e425
jmp 0x1e4fe
testq %rsi, %rsi
je 0x1e52c
addq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %rsi
movq %rax, %r14
movq 0x20(%rsp), %rax
addq %r14, %rax
movq %rax, 0x28(%rsp)
testq %rsi, %rsi
jle 0x1e4fe
movq %rdx, %r15
xorl %r12d, %r12d
testq %r15, %r15
jle 0x1e4bc
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 0x1e30e
movq 0x28(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rsp)
addq %r14, %rax
incq %rax
movq %rax, 0x28(%rsp)
incq %r12
cmpq 0x10(%rbx), %r12
jl 0x1e4ac
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x1184d(%rip), %rdi     # 0x2fd61
leaq 0x117ae(%rip), %rsi     # 0x2fcc9
leaq 0x1185e(%rip), %rcx     # 0x2fd80
movl $0x118, %edx            # imm = 0x118
callq 0xd280
leaq 0x1182e(%rip), %rdi     # 0x2fd61
leaq 0x1178f(%rip), %rsi     # 0x2fcc9
leaq 0x1183f(%rip), %rcx     # 0x2fd80
movl $0x12a, %edx            # imm = 0x12A
callq 0xd280