// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rdx, %rbx
movl $0x0, (%rdi)
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
sete %dl
orb %al, %dl
jne 0x2ae0e
movq %rsi, %r10
movb 0x80(%rsp), %al
testb $0x2, %al
movl $0x7c18, %edx           # imm = 0x7C18
cmovel %r9d, %edx
movzbl 0x10(%rbx), %esi
cmpb $0x0, (%r10)
je 0x2adfb
movl %esi, 0xc(%rsp)
movzwl %si, %esi
movq %r8, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
addl %r8d, %esi
movl %esi, 0x1c(%rsp)
xorl %r13d, %r13d
movswl %cx, %ecx
movl %ecx, 0x18(%rsp)
movswl %dx, %ecx
movl %ecx, 0x14(%rsp)
movq %rbx, 0x40(%rsp)
movq %rdi, 0x20(%rsp)
movzbl %al, %eax
movl %eax, 0x10(%rsp)
movq %r10, %r15
movq %r10, 0x38(%rsp)
movq 0x40(%rsp), %r14
movl 0x18(%rsp), %ebx
movl 0x10(%rsp), %ebp
movq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
movl 0x14(%rsp), %ecx
movl %ebp, %r8d
callq 0x2ae1d
movzwl %ax, %esi
addl %esi, %r13d
movl 0x1c(%rsp), %eax
addw %ax, 0x2(%r12)
movq %r15, %rdi
movq %r14, %rdx
movl %ebx, %ecx
movl %ebp, %r8d
callq 0x2b2a4
movq 0x38(%rsp), %r10
movzwl (%r12), %ecx
cmpw %cx, %ax
cmovlel %ecx, %eax
movw %ax, (%r12)
leaq (%r10,%r13), %r15
cmpb $0x0, (%r10,%r13)
jne 0x2ad76
testl %r13d, %r13d
movq 0x30(%rsp), %r8
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdi
je 0x2adfb
decl %r13d
movzbl (%r10,%r13), %eax
cmpl $0xd, %eax
je 0x2adef
cmpl $0xa, %eax
jne 0x2adfb
movq 0x28(%rsp), %rax
addl %r8d, %eax
addw %ax, 0x2(%rdi)
movzwl 0x2(%rdi), %eax
movl %eax, %ecx
subl %r8d, %ecx
testw %ax, %ax
cmovnel %ecx, %esi
movw %si, 0x2(%rdi)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq