// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_label.c
// Function: lv_draw_label
void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale,
                   const char * txt, lv_txt_flag_t flag, lv_point_t * offset, lv_draw_label_txt_sel_t * sel,
                   lv_draw_label_hint_t * hint, lv_bidi_dir_t bidi_dir)
{
    const lv_font_t * font = style->text.font;
    lv_coord_t w;

    /*No need to waste processor time if string is empty*/
    if (txt[0] == '\0')  return;

    if((flag & LV_TXT_FLAG_EXPAND) == 0) {
        /*Normally use the label's width as width*/
        w = lv_area_get_width(coords);
    } else {
        /*If EXAPND is enabled then not limit the text's width to the object's width*/
        lv_point_t p;
        lv_txt_get_size(&p, txt, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX,
                flag);
        w = p.x;
    }

    lv_coord_t line_height = lv_font_get_line_height(font) + style->text.line_space;

    /*Init variables for the first line*/
    lv_coord_t line_width = 0;
    lv_point_t pos;
    pos.x = coords->x1;
    pos.y = coords->y1;

    lv_coord_t x_ofs = 0;
    lv_coord_t y_ofs = 0;
    if(offset != NULL) {
        x_ofs = offset->x;
        y_ofs = offset->y;
        pos.y += y_ofs;
    }

    uint32_t line_start     = 0;
    int32_t last_line_start = -1;

    /*Check the hint to use the cached info*/
    if(hint && y_ofs == 0 && coords->y1 < 0) {
        /*If the label changed too much recalculate the hint.*/
        if(LV_MATH_ABS(hint->coord_y - coords->y1) > LV_LABEL_HINT_UPDATE_TH - 2 * line_height) {
            hint->line_start = -1;
        }
        last_line_start = hint->line_start;
    }

    /*Use the hint if it's valid*/
    if(hint && last_line_start >= 0) {
        line_start = last_line_start;
        pos.y += hint->y;
    }


    uint32_t line_end = line_start + lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag);

    /*Go the first visible line*/
    while(pos.y + line_height < mask->y1) {
        /*Go to next line*/
        line_start = line_end;
        line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag);
        pos.y += line_height;

        /*Save at the threshold coordinate*/
        if(hint && pos.y >= -LV_LABEL_HINT_UPDATE_TH && hint->line_start < 0) {
            hint->line_start = line_start;
            hint->y          = pos.y - coords->y1;
            hint->coord_y    = coords->y1;
        }

        if(txt[line_start] == '\0') return;
    }

    /*Align to middle*/
    if(flag & LV_TXT_FLAG_CENTER) {
        line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, font, style->text.letter_space, flag);

        pos.x += (lv_area_get_width(coords) - line_width) / 2;

    }
    /*Align to the right*/
    else if(flag & LV_TXT_FLAG_RIGHT) {
        line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, font, style->text.letter_space, flag);
        pos.x += lv_area_get_width(coords) - line_width;
    }

    lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->text.opa : (uint16_t)((uint16_t)style->text.opa * opa_scale) >> 8;

    uint16_t sel_start = 0xFFFF;
    uint16_t sel_end = 0xFFFF;
    if(sel) {
        sel_start = sel->start;
        sel_end = sel->end;
        if(sel_start > sel_end) {
            uint16_t tmp = sel_start;
            sel_start = sel_end;
            sel_end = tmp;
        }
    }

    cmd_state_t cmd_state = CMD_STATE_WAIT;
    uint32_t i;
    uint16_t par_start = 0;
    lv_color_t recolor;
    lv_coord_t letter_w;
    lv_style_t sel_style;
    lv_style_copy(&sel_style, &lv_style_plain_color);
    sel_style.body.main_color = sel_style.body.grad_color = style->text.sel_color;

    /*Write out all lines*/
    while(txt[line_start] != '\0') {
        if(offset != NULL) {
            pos.x += x_ofs;
        }
        /*Write all letter of a line*/
        cmd_state = CMD_STATE_WAIT;
        i         = 0;
        uint32_t letter;
        uint32_t letter_next;
#if LV_USE_BIDI
        char *bidi_txt = lv_draw_get_buf(line_end - line_start + 1);
        lv_bidi_process_paragraph(txt + line_start, bidi_txt, line_end - line_start, bidi_dir, NULL, 0);
#else
        const char *bidi_txt = txt + line_start;
#endif

        while(i < line_end - line_start) {
            uint16_t logical_char_pos = 0;
            if(sel_start != 0xFFFF && sel_end != 0xFFFF) {
#if LV_USE_BIDI
                logical_char_pos = lv_txt_encoded_get_char_id(txt, line_start);
                uint16_t t = lv_txt_encoded_get_char_id(bidi_txt, i);
                logical_char_pos += lv_bidi_get_logical_pos(bidi_txt, NULL, line_end - line_start, bidi_dir, t, NULL);
#else
                logical_char_pos = lv_txt_encoded_get_char_id(txt, line_start + i);
#endif
            }

            letter      = lv_txt_encoded_next(bidi_txt, &i);
            letter_next = lv_txt_encoded_next(&bidi_txt[i], NULL);


            /*Handle the re-color command*/
            if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
                if(letter == (uint32_t)LV_TXT_COLOR_CMD[0]) {
                    if(cmd_state == CMD_STATE_WAIT) { /*Start char*/
                        par_start = i;
                        cmd_state = CMD_STATE_PAR;
                        continue;
                    } else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */
                        cmd_state = CMD_STATE_WAIT;
                    } else if(cmd_state == CMD_STATE_IN) { /*Command end */
                        cmd_state = CMD_STATE_WAIT;
                        continue;
                    }
                }

                /*Skip the color parameter and wait the space after it*/
                if(cmd_state == CMD_STATE_PAR) {
                    if(letter == ' ') {
                        /*Get the parameter*/
                        if(i - par_start == LABEL_RECOLOR_PAR_LENGTH + 1) {
                            char buf[LABEL_RECOLOR_PAR_LENGTH + 1];
                            memcpy(buf, &bidi_txt[par_start], LABEL_RECOLOR_PAR_LENGTH);
                            buf[LABEL_RECOLOR_PAR_LENGTH] = '\0';
                            int r, g, b;
                            r       = (hex_char_to_num(buf[0]) << 4) + hex_char_to_num(buf[1]);
                            g       = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]);
                            b       = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]);
                            recolor = lv_color_make(r, g, b);
                        } else {
                            recolor.full = style->text.color.full;
                        }
                        cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/
                    }
                    continue;
                }
            }

            lv_color_t color = style->text.color;

            if(cmd_state == CMD_STATE_IN) color = recolor;

            letter_w = lv_font_get_glyph_width(font, letter, letter_next);

            if(sel_start != 0xFFFF && sel_end != 0xFFFF) {
                if(logical_char_pos >= sel_start && logical_char_pos < sel_end) {
                    lv_area_t sel_coords;
                    sel_coords.x1 = pos.x;
                    sel_coords.y1 = pos.y;
                    sel_coords.x2 = pos.x + letter_w + style->text.letter_space - 1;
                    sel_coords.y2 = pos.y + line_height - 1;
                    lv_draw_rect(&sel_coords, mask, &sel_style, opa);
                }
            }

            lv_draw_letter(&pos, mask, font, letter, color, opa);

            if(letter_w > 0) {
                pos.x += letter_w + style->text.letter_space;
            }
        }
        /*Go to next line*/
        line_start = line_end;
        line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag);

        pos.x = coords->x1;
        /*Align to middle*/
        if(flag & LV_TXT_FLAG_CENTER) {
            line_width =
                    lv_txt_get_width(&txt[line_start], line_end - line_start, font, style->text.letter_space, flag);

            pos.x += (lv_area_get_width(coords) - line_width) / 2;

        }
        /*Align to the right*/
        else if(flag & LV_TXT_FLAG_RIGHT) {
            line_width =
                    lv_txt_get_width(&txt[line_start], line_end - line_start, font, style->text.letter_space, flag);
            pos.x += lv_area_get_width(coords) - line_width;
        }

        /*Go the next line position*/
        pos.y += line_height;

        if(pos.y > mask->y2) return;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, 0x60(%rsp)
movq %rdi, 0x50(%rsp)
movq %r8, 0x20(%rsp)
cmpb $0x0, (%r8)
je 0x3acdb
movq %rdx, %rbp
movq 0x120(%rsp), %r14
movq 0x28(%rdx), %r12
movzbl %r9b, %r10d
testb $0x2, %r9b
movl %r9d, 0x2c(%rsp)
movl %r10d, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
jne 0x3a60f
movq 0x50(%rsp), %rdx
movzwl (%rdx), %ecx
movzwl 0x4(%rdx), %eax
subl %ecx, %eax
incl %eax
jmp 0x3a64a
movswl 0x30(%rbp), %ecx
movswl 0x32(%rbp), %r8d
movl %r10d, (%rsp)
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
movl $0x7c18, %r9d           # imm = 0x7C18
callq 0x2acd4
movzwl (%rbx), %eax
movl 0x14(%rsp), %r10d
movq 0x50(%rsp), %rdx
movzwl (%rdx), %ecx
movq 0x130(%rsp), %r15
movq %r12, 0x40(%rsp)
movzbl 0x10(%r12), %esi
addw 0x32(%rbp), %si
movq %rsi, 0x58(%rsp)
movw %cx, 0x10(%rsp)
movzwl 0x2(%rdx), %edx
movw %dx, 0x12(%rsp)
testq %r14, %r14
je 0x3a697
movzwl (%r14), %ecx
movl %ecx, 0x6c(%rsp)
movzwl 0x2(%r14), %esi
leal (%rdx,%rsi), %ecx
movw %cx, 0x12(%rsp)
testw %si, %si
sete %sil
jmp 0x3a6a4
movb $0x1, %sil
movl $0x0, 0x6c(%rsp)
movl %edx, %ecx
testq %r15, %r15
setne %dil
andb %sil, %dil
testw %dx, %dx
sets %sil
testb %sil, %dil
je 0x3a6ec
movswl %dx, %edx
movl 0x8(%r15), %esi
subl %edx, %esi
movl %esi, %edx
negl %edx
cmovsl %esi, %edx
movswl 0x58(%rsp), %r12d
movl $0x400, %edi            # imm = 0x400
subl %r12d, %edi
subl %r12d, %edi
cmpl %edi, %edx
jle 0x3aced
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
jmp 0x3a6f2
movswl 0x58(%rsp), %r12d
xorl %r13d, %r13d
movl %r13d, %edi
addq 0x20(%rsp), %rdi
movswl 0x30(%rbp), %edx
movswl %ax, %ecx
movq 0x40(%rsp), %rsi
movl %ecx, 0x70(%rsp)
movl %r10d, %r8d
callq 0x2ae1d
movzwl %ax, %r14d
addl %r13d, %r14d
movswl 0x12(%rsp), %eax
addl %r12d, %eax
movq 0x60(%rsp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x3a7bb
movl %r14d, %r13d
movl %r14d, %ebx
addq 0x20(%rsp), %rbx
movswl 0x30(%rbp), %edx
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
movl 0x70(%rsp), %ecx
movl 0x14(%rsp), %r8d
callq 0x2ae1d
movzwl 0x12(%rsp), %ecx
addw 0x58(%rsp), %cx
movw %cx, 0x12(%rsp)
movswl %cx, %ecx
testq %r15, %r15
je 0x3a797
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jl 0x3a797
cmpl $0x0, (%r15)
jns 0x3a797
movl %r13d, (%r15)
movq 0x50(%rsp), %rdx
movswl 0x2(%rdx), %edx
movl %ecx, %esi
subl %edx, %esi
movl %esi, 0x4(%r15)
movl %edx, 0x8(%r15)
cmpb $0x0, (%rbx)
je 0x3acdb
movzwl %ax, %r14d
addl %r13d, %r14d
addl %r12d, %ecx
movq 0x60(%rsp), %rax
movswl 0x2(%rax), %eax
cmpl %eax, %ecx
jl 0x3a735
movl 0x2c(%rsp), %r15d
testb $0x4, %r15b
movl %r14d, 0x30(%rsp)
jne 0x3a81d
movl %r13d, %r12d
testb $0x8, %r15b
movl 0x14(%rsp), %r8d
movl 0x18(%rsp), %ebx
je 0x3a86a
movl %r12d, %edi
addq 0x20(%rsp), %rdi
movl 0x30(%rsp), %eax
subl %r12d, %eax
movswl 0x30(%rbp), %ecx
movzwl %ax, %esi
movq 0x40(%rsp), %rdx
callq 0x2b2a4
movq 0x50(%rsp), %rdx
movzwl 0x4(%rdx), %ecx
addw (%rdx), %ax
subl %eax, %ecx
addw 0x10(%rsp), %cx
incl %ecx
movw %cx, 0x10(%rsp)
jmp 0x3a86a
movl %r13d, %edi
addq 0x20(%rsp), %rdi
movl %r14d, %eax
movl %r13d, %r12d
subl %r13d, %eax
movswl 0x30(%rbp), %ecx
movzwl %ax, %esi
movq 0x40(%rsp), %rdx
movl 0x14(%rsp), %r8d
callq 0x2b2a4
movq 0x50(%rsp), %rdx
movzwl 0x4(%rdx), %ecx
subw (%rdx), %cx
incl %ecx
movswl %cx, %ecx
cwtl
subl %eax, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
shrl %eax
addw %ax, 0x10(%rsp)
movl 0x18(%rsp), %ebx
movq 0x128(%rsp), %rax
cmpb $-0x1, %bl
je 0x3a88a
movzbl %bl, %ecx
movzbl 0x34(%rbp), %edx
imull %ecx, %edx
shrl $0x8, %edx
movl %edx, 0x7c(%rsp)
jmp 0x3a891
movb 0x34(%rbp), %cl
movl %ecx, 0x7c(%rsp)
movq %rbp, 0x38(%rsp)
testq %rax, %rax
je 0x3a8af
movzwl (%rax), %ecx
movzwl 0x2(%rax), %ebp
cmpw %bp, %cx
movl %ebp, %ebx
cmoval %ecx, %ebx
cmovbl %ecx, %ebp
jmp 0x3a8b7
movw $0xffff, %bx            # imm = 0xFFFF
movw $0xffff, %bp            # imm = 0xFFFF
leaq 0x256a2(%rip), %rsi     # 0x5ff60
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
callq 0x799d
movq 0x38(%rsp), %rax
movzwl 0x22(%rax), %eax
movw %ax, 0x4(%r13)
movw %ax, 0x2(%r13)
movzwl %bp, %eax
movl %eax, 0x90(%rsp)
cmpw $-0x1, %ax
setne %al
movzwl %bx, %ecx
movl %ecx, 0x8c(%rsp)
cmpw $-0x1, %cx
setne %cl
andb %al, %cl
movb %cl, 0x18(%rsp)
movq 0x58(%rsp), %rax
decl %eax
movl %eax, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
movl %eax, 0x4c(%rsp)
movl 0x30(%rsp), %esi
movl %r12d, 0x78(%rsp)
movl %r12d, %ecx
movq 0x20(%rsp), %rax
movq %rcx, 0x30(%rsp)
cmpb $0x0, (%rax,%rcx)
je 0x3acdb
movl %esi, %r14d
cmpq $0x0, 0x120(%rsp)
je 0x3a95e
movl 0x6c(%rsp), %eax
addw %ax, 0x10(%rsp)
movl $0x0, 0x1c(%rsp)
movl %r14d, 0x74(%rsp)
subl 0x78(%rsp), %r14d
movl %r14d, 0x94(%rsp)
jne 0x3aa0a
movl 0x74(%rsp), %ebx
addq 0x20(%rsp), %rbx
movq 0x38(%rsp), %r12
movswl 0x30(%r12), %edx
movq %rbx, %rdi
movq 0x40(%rsp), %r14
movq %r14, %rsi
movl 0x70(%rsp), %ecx
movl 0x14(%rsp), %ebp
movl %ebp, %r8d
callq 0x2ae1d
movzwl %ax, %esi
movq 0x50(%rsp), %r13
movzwl (%r13), %eax
movw %ax, 0x10(%rsp)
testb $0x4, %r15b
jne 0x3ac7d
testb $0x8, %r15b
je 0x3acb5
movswl 0x30(%r12), %ecx
movq %rbx, %rdi
movl %esi, %ebx
movq %r14, %rdx
movl 0x14(%rsp), %r8d
callq 0x2b2a4
movl %ebx, %esi
movzwl 0x4(%r13), %ecx
addw (%r13), %ax
subl %eax, %ecx
addw 0x10(%rsp), %cx
incl %ecx
movw %cx, 0x10(%rsp)
jmp 0x3acb5
movq 0x30(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %esi, %esi
xorl %ebp, %ebp
movl $0x0, %r14d
cmpb $0x0, 0x18(%rsp)
je 0x3aa40
addl 0x78(%rsp), %esi
movq 0x20(%rsp), %rdi
leaq 0x18c0e(%rip), %rax     # 0x53648
callq *(%rax)
movzwl %ax, %r14d
movq 0x30(%rsp), %r12
movq %r12, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0x18bdc(%rip), %rbx     # 0x53630
callq *(%rbx)
movl %eax, %r13d
movl 0x1c(%rsp), %edi
addq %r12, %rdi
xorl %esi, %esi
callq *(%rbx)
testb $0x1, %r15b
jne 0x3aa7f
movl 0x4c(%rsp), %ebx
cmpb $0x2, %bpl
je 0x3aaab
movq 0x38(%rsp), %rcx
movzwl 0x20(%rcx), %ebx
jmp 0x3aaab
cmpl $0x23, %r13d
jne 0x3ab8a
cmpb $0x2, %bpl
je 0x3ac4c
movzbl %bpl, %ecx
cmpl $0x1, %ecx
jne 0x3ac53
movq 0x38(%rsp), %rcx
movzwl 0x20(%rcx), %ebx
xorl %ebp, %ebp
movq 0x40(%rsp), %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x28487
movl %eax, %r12d
cmpl 0x90(%rsp), %r14d
setae %al
andb 0x18(%rsp), %al
movzbl 0x7c(%rsp), %r15d
cmpb $0x1, %al
jne 0x3ab3c
cmpl 0x8c(%rsp), %r14d
jae 0x3ab3c
movzwl 0x10(%rsp), %eax
movw %ax, 0x80(%rsp)
movzwl 0x12(%rsp), %ecx
movw %cx, 0x82(%rsp)
addl %r12d, %eax
movq 0x38(%rsp), %rdx
addw 0x30(%rdx), %ax
decl %eax
movw %ax, 0x84(%rsp)
addl 0x88(%rsp), %ecx
movw %cx, 0x86(%rsp)
leaq 0x80(%rsp), %rdi
movq 0x60(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movl %r15d, %ecx
callq 0x36968
leaq 0x10(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x40(%rsp), %rdx
movl %r13d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x35a71
testw %r12w, %r12w
jle 0x3ab6f
movq 0x38(%rsp), %rax
addw 0x30(%rax), %r12w
addw %r12w, 0x10(%rsp)
movl 0x2c(%rsp), %r15d
movl 0x1c(%rsp), %esi
cmpl 0x94(%rsp), %esi
jb 0x3aa1d
jmp 0x3a97e
cmpb $0x1, %bpl
jne 0x3aa6a
movb $0x1, %bpl
cmpl $0x20, %r13d
jne 0x3ab74
movl 0x1c(%rsp), %ecx
movzwl 0x98(%rsp), %eax
subl %eax, %ecx
cmpl $0x7, %ecx
jne 0x3ac68
movq 0x30(%rsp), %rcx
movsbl (%rcx,%rax), %edi
movsbl 0x1(%rcx,%rax), %ebx
movsbl 0x2(%rcx,%rax), %r13d
movsbl 0x3(%rcx,%rax), %r15d
movsbl 0x4(%rcx,%rax), %r14d
movsbl 0x5(%rcx,%rax), %ebp
callq 0x3ad08
movl %eax, %r12d
shlb $0x4, %r12b
movl %ebx, %edi
callq 0x3ad08
movl %eax, %ebx
orb %r12b, %bl
movl %r13d, %edi
callq 0x3ad08
movl %eax, %r12d
shlb $0x4, %r12b
movl %r15d, %edi
callq 0x3ad08
movl %eax, %r15d
orb %r12b, %r15b
movl %r14d, %edi
callq 0x3ad08
movl %eax, %r12d
shlb $0x4, %r12b
movl %ebp, %edi
callq 0x3ad08
orb %r12b, %al
shrb $0x3, %al
movzbl %al, %eax
shrb $0x2, %r15b
movzbl %r15b, %ecx
movl 0x2c(%rsp), %r15d
shll $0x5, %ecx
orl %eax, %ecx
shrb $0x3, %bl
movzbl %bl, %eax
shll $0xb, %eax
orl %ecx, %eax
jmp 0x3ac71
xorl %ebp, %ebp
jmp 0x3ab74
movzwl 0x1c(%rsp), %eax
movq %rax, 0x98(%rsp)
movb $0x1, %bpl
jmp 0x3ab74
movq 0x38(%rsp), %rax
movzwl 0x20(%rax), %eax
movl %eax, 0x4c(%rsp)
movb $0x2, %bpl
jmp 0x3ab74
movswl 0x30(%r12), %ecx
movq %rbx, %rdi
movl %esi, %ebx
movq %r14, %rdx
movl %ebp, %r8d
callq 0x2b2a4
movl %ebx, %esi
movzwl 0x4(%r13), %ecx
subw (%r13), %cx
incl %ecx
movswl %cx, %ecx
cwtl
subl %eax, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
shrl %eax
addw %ax, 0x10(%rsp)
movl 0x74(%rsp), %r12d
addl %r12d, %esi
movzwl 0x12(%rsp), %eax
addw 0x58(%rsp), %ax
movw %ax, 0x12(%rsp)
movq 0x60(%rsp), %rcx
cmpw 0x6(%rcx), %ax
jle 0x3a92b
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r15), %r13d
testl %r13d, %r13d
js 0x3a6f2
addw 0x4(%r15), %cx
movw %cx, 0x12(%rsp)
jmp 0x3a6f5