// File: /workspace/github_c_makefile_star2_O1/OnionIoT[P]lv_example/lvgl/src/lv_misc/lv_txt.c
// Function: lv_txt_get_size
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, lv_coord_t letter_space,
                     lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag)
{
    size_res->x = 0;
    size_res->y = 0;

    if(text == NULL) return;
    if(font == NULL) return;

    if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;

    uint32_t line_start     = 0;
    uint32_t new_line_start = 0;
    lv_coord_t act_line_length;
    uint8_t letter_height = lv_font_get_line_height(font);

    /*Calc. the height and longest line*/
    while(text[line_start] != '\0') {
        new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag);
        size_res->y += letter_height;
        size_res->y += line_space;

        /*Calculate the the longest line*/
        act_line_length = lv_txt_get_width(&text[line_start], new_line_start - line_start, font, letter_space, flag);

        size_res->x = LV_MATH_MAX(act_line_length, size_res->x);
        line_start  = new_line_start;
    }

    /*Ma ke the text one line taller if the last character is '\n' or '\r'*/
    if((line_start != 0) && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) {
        size_res->y += letter_height + line_space;
    }

    /*Correction with the last line space or set the height manually if the text is empty*/
    if(size_res->y == 0)
        size_res->y = letter_height;
    else
        size_res->y -= line_space;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movl $0x0, (%rdi)
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
sete %dl
orb %al, %dl
jne 0x2a778
movb 0x70(%rsp), %al
testb $0x2, %al
movl $0x7c18, %edx           # imm = 0x7C18
cmovel %r9d, %edx
movzbl 0x10(%rbx), %r9d
cmpb $0x0, (%rsi)
movl %r8d, 0xc(%rsp)
movl %r9d, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
je 0x2a730
movzwl %r9w, %r9d
addl %r8d, %r9d
movl %r9d, 0x1c(%rsp)
xorl %r13d, %r13d
movswl %cx, %ecx
movl %ecx, 0x18(%rsp)
movswl %dx, %ecx
movl %ecx, 0x14(%rsp)
movzbl %al, %eax
movl %eax, 0x10(%rsp)
movq %rbx, 0x30(%rsp)
movq %rsi, %r14
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %r12
movl 0x18(%rsp), %ebp
movl 0x10(%rsp), %ebx
movq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
movl 0x14(%rsp), %ecx
movl %ebx, %r8d
callq 0x2a787
movzwl %ax, %esi
addl %esi, %r13d
movl 0x1c(%rsp), %eax
addw %ax, 0x2(%r15)
movq %r14, %rdi
movq %r12, %rdx
movl %ebp, %ecx
movl %ebx, %r8d
callq 0x2ab49
movq 0x28(%rsp), %rsi
movzwl (%r15), %ecx
cmpw %cx, %ax
cmovlel %ecx, %eax
movw %ax, (%r15)
leaq (%rsi,%r13), %r14
cmpb $0x0, (%rsi,%r13)
jne 0x2a6dd
jmp 0x2a733
xorl %r13d, %r13d
testl %r13d, %r13d
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %edi
movq 0x20(%rsp), %r12
je 0x2a762
decl %r13d
movzbl (%rsi,%r13), %eax
cmpl $0xd, %eax
je 0x2a757
cmpl $0xa, %eax
jne 0x2a762
movzwl %di, %eax
addl %edx, %eax
addw %ax, 0x2(%r12)
movzwl 0x2(%r12), %eax
movl %eax, %ecx
subl %edx, %ecx
testw %ax, %ax
cmovnel %ecx, %edi
movw %di, 0x2(%r12)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq