// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_table.c
// Function: lv_table_design
static bool lv_table_design(lv_obj_t * table, const lv_area_t * mask, lv_design_mode_t mode)
{
    /*Return false if the object is not covers the mask_p area*/
    if(mode == LV_DESIGN_COVER_CHK) {
        return false;
    }
    /*Draw the object*/
    else if(mode == LV_DESIGN_DRAW_MAIN) {
        ancestor_scrl_design(table, mask, mode);

        lv_table_ext_t * ext        = lv_obj_get_ext_attr(table);
        const lv_style_t * bg_style = lv_obj_get_style(table);
        lv_coord_t h_row;
        lv_point_t txt_size;
        lv_area_t cell_area;
        lv_area_t txt_area;
        lv_txt_flag_t txt_flags;
        lv_opa_t opa_scale = lv_obj_get_opa_scale(table);

        uint16_t col;
        uint16_t row;
        uint16_t cell = 0;

        cell_area.y2 = table->coords.y1 + bg_style->body.padding.top;
        for(row = 0; row < ext->row_cnt; row++) {
            h_row = get_row_height(table, row);

            cell_area.y1 = cell_area.y2 + 1;
            cell_area.y2 = cell_area.y1 + h_row - 1;

            cell_area.x2 = table->coords.x1 + bg_style->body.padding.left;

            for(col = 0; col < ext->col_cnt; col++) {

                lv_table_cell_format_t format;
                if(ext->cell_data[cell]) {
                    format.format_byte = ext->cell_data[cell][0];
                } else {
                    format.s.right_merge = 0;
                    format.s.align       = LV_LABEL_ALIGN_LEFT;
                    format.s.type        = 0;
                    format.s.crop        = 1;
                }


                lv_style_t cell_style;
                lv_style_copy(&cell_style, ext->cell_style[format.s.type]);
                cell_area.x1 = cell_area.x2 + 1;
                cell_area.x2 = cell_area.x1 + ext->col_w[col] - 1;

                uint16_t col_merge = 0;
                for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) {

                    if(ext->cell_data[cell + col_merge] != NULL) {
                        format.format_byte = ext->cell_data[cell + col_merge][0];
                        if(format.s.right_merge)
                            cell_area.x2 += ext->col_w[col + col_merge + 1];
                        else
                            break;
                    } else {
                        break;
                    }
                }

                lv_draw_rect(&cell_area, mask, &cell_style, opa_scale);

                if(ext->cell_data[cell]) {

                    txt_area.x1 = cell_area.x1 + cell_style.body.padding.left;
                    txt_area.x2 = cell_area.x2 - cell_style.body.padding.right;
                    txt_area.y1 = cell_area.y1 + cell_style.body.padding.top;
                    txt_area.y2 = cell_area.y2 - cell_style.body.padding.bottom;
                    /*Align the content to the middle if not cropped*/
                    if(format.s.crop == 0) {
                        txt_flags = LV_TXT_FLAG_NONE;
                    } else {
                        txt_flags = LV_TXT_FLAG_EXPAND;
                    }

                    lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style.text.font,
                                    cell_style.text.letter_space, cell_style.text.line_space,
                                    lv_area_get_width(&txt_area), txt_flags);

                    /*Align the content to the middle if not cropped*/
                    if(format.s.crop == 0) {
                        txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2;
                        txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2;
                    }

                    switch(format.s.align) {
                        default:
                        case LV_LABEL_ALIGN_LEFT: txt_flags |= LV_TXT_FLAG_NONE; break;
                        case LV_LABEL_ALIGN_RIGHT: txt_flags |= LV_TXT_FLAG_RIGHT; break;
                        case LV_LABEL_ALIGN_CENTER: txt_flags |= LV_TXT_FLAG_CENTER; break;
                    }

                    lv_area_t label_mask;
                    bool label_mask_ok;
                    label_mask_ok = lv_area_intersect(&label_mask, mask, &cell_area);
                    if(label_mask_ok) {
                        lv_draw_label(&txt_area, &label_mask, &cell_style, opa_scale, ext->cell_data[cell] + 1,
                                      txt_flags, NULL, NULL, NULL, lv_obj_get_base_dir(table));
                    }
                    /*Draw lines after '\n's*/
                    lv_point_t p1;
                    lv_point_t p2;
                    p1.x = cell_area.x1;
                    p2.x = cell_area.x2;
                    uint16_t i;
                    for(i = 1; ext->cell_data[cell][i] != '\0'; i++) {
                        if(ext->cell_data[cell][i] == '\n') {
                            ext->cell_data[cell][i] = '\0';
                            lv_txt_get_size(&txt_size, ext->cell_data[cell] + 1, cell_style.text.font,
                                            cell_style.text.letter_space, cell_style.text.line_space,
                                            lv_area_get_width(&txt_area), txt_flags);

                            p1.y = txt_area.y1 + txt_size.y + cell_style.text.line_space / 2;
                            p2.y = txt_area.y1 + txt_size.y + cell_style.text.line_space / 2;
                            lv_draw_line(&p1, &p2, mask, &cell_style, opa_scale);

                            ext->cell_data[cell][i] = '\n';
                        }
                    }
                }

                cell += col_merge + 1;
                col += col_merge;
            }
        }
    }
    /*Post draw when the children are drawn*/
    else if(mode == LV_DESIGN_DRAW_POST) {
    }

    return true;
}

// Assembly:
testl %edx, %edx
jne 0xf331
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
movl %edx, 0x68(%rsp)
xorl %ebp, %ebp
movq %rsi, 0x50(%rsp)
xorl %edx, %edx
callq *0x4f3ea(%rip)          # 0x5e328
movq %rbx, %rdi
callq 0x6747
movq %rax, %r12
movq %rbx, %rdi
callq 0x6316
movq %rax, %r14
movq %rbx, %rdi
callq 0x6649
movb %al, 0x2f(%rsp)
movq %r14, 0x78(%rsp)
movzwl 0x16(%r14), %eax
addw 0x22(%rbx), %ax
leaq 0x30(%rsp), %rcx
movw %ax, 0x6(%rcx)
xorl %r13d, %r13d
movq %rbx, 0x70(%rsp)
cmpw 0x2(%r12), %bp
jae 0xf31c
movl %ebp, 0x6c(%rsp)
movzwl %bp, %esi
movq %rbx, %rdi
callq 0xfce3
movzwl 0x36(%rsp), %ecx
leal 0x1(%rcx), %edx
movw %dx, 0x32(%rsp)
addl %eax, %ecx
movw %cx, 0x36(%rsp)
movq 0x78(%rsp), %rcx
movzwl 0x1a(%rcx), %ecx
addw 0x20(%rbx), %cx
cwtd
movw %cx, 0x34(%rsp)
movw $0x2, %cx
idivw %cx
movw %ax, 0x42(%rsp)
xorl %r15d, %r15d
cmpw (%r12), %r15w
jae 0xf30c
movq 0x8(%r12), %rax
movq %r13, 0x80(%rsp)
movzwl %r13w, %r13d
movq (%rax,%r13,8), %rax
testq %rax, %rax
je 0xeffb
movb (%rax), %bpl
jmp 0xeffe
movb $0x20, %bpl
movzwl %r15w, %ebx
movl %ebp, %eax
shrb $0x3, %al
andb $0x3, %al
movzbl %al, %eax
movq 0x10(%r12,%rax,8), %rsi
leaq 0x90(%rsp), %rdi
callq 0x74d4
movl 0x34(%rsp), %ecx
movl %ecx, %eax
incl %eax
movw %ax, 0x30(%rsp)
movl %ebx, %eax
movzwl 0x30(%r12,%rax,2), %eax
addw %cx, %ax
movw %ax, 0x34(%rsp)
movzwl (%r12), %ecx
decl %ecx
xorl %r14d, %r14d
movzwl %r14w, %r14d
leal (%r14,%rbx), %r15d
cmpl %ecx, %r15d
jge 0xf080
movq 0x8(%r12), %rdx
leal (%r14,%r13), %esi
movq (%rdx,%rsi,8), %rdx
testq %rdx, %rdx
je 0xf080
movb (%rdx), %bpl
testb $0x4, %bpl
je 0xf080
movl %r15d, %edx
addw 0x32(%r12,%rdx,2), %ax
movw %ax, 0x34(%rsp)
incl %r14d
jmp 0xf045
movzbl 0x2f(%rsp), %ecx
leaq 0x30(%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movl %ecx, 0x5c(%rsp)
callq 0x336d4
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rsi
testq %rsi, %rsi
je 0xf2f6
movq 0x30(%rsp), %xmm0
movq 0xa6(%rsp), %xmm1
pshuflw $0x72, %xmm1, %xmm1     # xmm1 = xmm1[2,0,3,1,4,5,6,7]
movdqa %xmm0, %xmm2
paddw %xmm1, %xmm2
psubw %xmm1, %xmm0
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movdqa %xmm2, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movq %xmm1, 0x48(%rsp)
movl %ebp, %ebx
andb $0x20, %bl
movl %ebx, %edi
shrb $0x4, %dil
incq %rsi
movq 0xb8(%rsp), %rdx
movswl 0xc0(%rsp), %ecx
movswl 0xc2(%rsp), %r8d
psubw %xmm2, %xmm0
movd %xmm0, %eax
incl %eax
movb %dil, 0x3c(%rsp)
movzbl %dil, %edi
movl %edi, (%rsp)
movswl %ax, %r9d
leaq 0x44(%rsp), %rdi
callq 0x28723
testb %bl, %bl
jne 0xf167
movzwl 0x32(%rsp), %esi
movzwl 0x46(%rsp), %ecx
movl %ecx, %eax
cwtd
addw 0x42(%rsp), %si
movw $0xfffe, %di            # imm = 0xFFFE
idivw %di
addl %esi, %eax
movw %ax, 0x4a(%rsp)
movl %ecx, %eax
cwtd
movw $0x2, %cx
idivw %cx
addl %esi, %eax
movw %ax, 0x4e(%rsp)
andb $0x3, %bpl
movzbl %bpl, %eax
leaq 0x2c3da(%rip), %rcx     # 0x3b550
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x50(%rsp), %rsi
movb 0x3c(%rsp), %bl
jmp 0xf19f
movb 0x3c(%rsp), %bl
orb $0x4, %bl
jmp 0xf19a
movb 0x3c(%rsp), %bl
orb $0x8, %bl
movq 0x50(%rsp), %rsi
leaq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x26880
movzbl %bl, %ecx
movl %ecx, 0x3c(%rsp)
testb %al, %al
je 0xf20e
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rbx
incq %rbx
movq 0x70(%rsp), %rdi
callq 0x47b9
movzbl %al, %eax
movl %eax, 0x18(%rsp)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x88(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movl 0x5c(%rsp), %ecx
movq %rbx, %r8
movl 0x3c(%rsp), %r9d
callq 0x3699c
movzwl 0x30(%rsp), %eax
movzwl 0x34(%rsp), %ecx
movw %ax, 0x64(%rsp)
movw %cx, 0x60(%rsp)
movw $0x1, %bx
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rax
movzwl %bx, %ebx
movzbl (%rax,%rbx), %ecx
cmpl $0xa, %ecx
je 0xf248
testl %ecx, %ecx
jne 0xf2ef
jmp 0xf2f6
movb $0x0, (%rax,%rbx)
movq 0x8(%r12), %rax
leal (,%r13,8), %ebp
movq (%rax,%rbp), %rsi
incq %rsi
movq 0xb8(%rsp), %rdx
movswl 0xc0(%rsp), %ecx
movswl 0xc2(%rsp), %r8d
movzwl 0x4c(%rsp), %eax
subw 0x48(%rsp), %ax
incl %eax
movl 0x3c(%rsp), %edi
movl %edi, (%rsp)
movswl %ax, %r9d
leaq 0x44(%rsp), %rdi
callq 0x28723
movzwl 0x46(%rsp), %ecx
addw 0x4a(%rsp), %cx
movzwl 0xc2(%rsp), %eax
cwtd
movw $0x2, %si
idivw %si
addl %ecx, %eax
movw %ax, 0x66(%rsp)
movw %ax, 0x62(%rsp)
leaq 0x64(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x90(%rsp), %rcx
movl 0x5c(%rsp), %r8d
callq 0x37138
movq 0x8(%r12), %rax
movq (%rax,%rbp), %rax
movb $0xa, (%rax,%rbx)
incl %ebx
jmp 0xf226
movq 0x80(%rsp), %r13
addl %r14d, %r13d
incl %r13d
incl %r15d
jmp 0xefd1
movl 0x6c(%rsp), %ebp
incl %ebp
movq 0x70(%rsp), %rbx
jmp 0xef7f
movl 0x68(%rsp), %edx
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
cmpb $0x2, %dl
setne %al
retq