// File: /workspace/github_c_makefile_star2_O1/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
leaq 0x12a9f(%rip), %rax     # 0x30b64
movl (%rbx), %edx
cmpq $0x3, %rdx
ja 0x1e287
movslq (%rax,%rdx,4), %rdx
addq %rax, %rdx
jmpq *%rdx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x28(%rbx)
movups %xmm0, 0x18(%rbx)
movq 0x8(%rbx), %rbx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
jmp 0x1e0c5
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
cmpq $0x2, 0x18(%rbx)
jl 0x1e11a
incq 0x10(%rcx)
movq 0x10(%rbx), %rbx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
jmp 0x1e0c5
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x18(%rbx)
movups %xmm0, 0x8(%rbx)
jmp 0x1e287
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 0x1e206
testq %rsi, %rsi
je 0x1e296
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 0x1e287
movq %rdx, %r15
xorl %r12d, %r12d
testq %r15, %r15
jle 0x1e1bf
decq %r15
incq 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 0x1e0a5
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 0x1e1b2
jmp 0x1e287
testq %rsi, %rsi
je 0x1e2b5
addq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %rsi
movq %rax, %r14
movq 0x20(%rsp), %rax
addq %r14, %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x10(%rbx)
jle 0x1e287
movq %rdx, %r15
xorl %r12d, %r12d
testq %r15, %r15
jle 0x1e245
decq %r15
incq 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 0x1e0a5
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 0x1e238
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x12a10(%rip), %rdi     # 0x30cad
leaq 0x12971(%rip), %rsi     # 0x30c15
leaq 0x12a21(%rip), %rcx     # 0x30ccc
movl $0x118, %edx            # imm = 0x118
callq 0xd280
leaq 0x129f1(%rip), %rdi     # 0x30cad
leaq 0x12952(%rip), %rsi     # 0x30c15
leaq 0x12a02(%rip), %rcx     # 0x30ccc
movl $0x12a, %edx            # imm = 0x12A
callq 0xd280