// File: /workspace/github_c_makefile_star2_O1/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, 0x58(%rsp)
movq %rdi, 0x48(%rsp)
movq %r8, 0x20(%rsp)
cmpb $0x0, (%r8)
je 0x3a775
movl %ecx, %r13d
movq %rdx, %rbp
movq 0x120(%rsp), %r14
movq 0x28(%rdx), %r12
movzbl %r9b, %r10d
testb $0x2, %r9b
movl %r9d, 0x2c(%rsp)
movl %r10d, 0x18(%rsp)
jne 0x3a094
movq 0x48(%rsp), %rdx
movzwl 0x4(%rdx), %eax
subw (%rdx), %ax
incl %eax
jmp 0x3a0cc
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 0x2a643
movzwl (%rbx), %eax
movl 0x18(%rsp), %r10d
movq 0x48(%rsp), %rdx
movq 0x130(%rsp), %r15
movq %r12, 0x38(%rsp)
movzbl 0x10(%r12), %ecx
addw 0x32(%rbp), %cx
movq %rcx, 0x78(%rsp)
movzwl (%rdx), %ecx
movw %cx, 0x12(%rsp)
movswl 0x2(%rdx), %ecx
movw %cx, 0x14(%rsp)
testq %r14, %r14
je 0x3a11c
movzwl (%r14), %edx
movl %edx, 0x64(%rsp)
movzwl 0x2(%r14), %edx
movl %edx, %esi
addl %ecx, %esi
movw %si, 0x14(%rsp)
testw %dx, %dx
sete %dl
jmp 0x3a126
movb $0x1, %dl
movl $0x0, 0x64(%rsp)
testq %r15, %r15
setne %sil
andb %dl, %sil
testw %cx, %cx
sets %dil
andb %sil, %dil
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movswl 0x78(%rsp), %r12d
cmpb $0x1, %dil
jne 0x3a171
movl 0x8(%r15), %edx
subl %ecx, %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
movl $0x400, %esi            # imm = 0x400
subl %r12d, %esi
subl %r12d, %esi
cmpl %esi, %ecx
jle 0x3a16e
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
movl (%r15), %edx
testq %r15, %r15
setne %cl
testl %edx, %edx
setns %sil
andb %cl, %sil
cmpb $0x1, %sil
movl $0x0, %ebx
jne 0x3a197
movzwl 0x4(%r15), %ecx
addw %cx, 0x14(%rsp)
movl %edx, %ebx
movl %ebx, %edi
addq 0x20(%rsp), %rdi
movswl 0x30(%rbp), %edx
movswl %ax, %ecx
movq 0x38(%rsp), %rsi
movl %ecx, 0x68(%rsp)
movl %r10d, %r8d
callq 0x2a787
movzwl %ax, %r14d
addl %ebx, %r14d
movswl 0x14(%rsp), %eax
addl %r12d, %eax
movq 0x58(%rsp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x3a261
movl %r14d, %ebx
addq 0x20(%rsp), %rbx
movswl 0x30(%rbp), %edx
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl 0x68(%rsp), %ecx
movl 0x18(%rsp), %r8d
callq 0x2a787
movl %r14d, %esi
movzwl 0x14(%rsp), %ecx
addw 0x78(%rsp), %cx
movw %cx, 0x14(%rsp)
testq %r15, %r15
je 0x3a236
movswl %cx, %ecx
cmpl $0xfffffc00, %ecx       # imm = 0xFFFFFC00
jl 0x3a236
cmpl $0x0, (%r15)
jns 0x3a236
movl %esi, (%r15)
movq 0x48(%rsp), %rdx
movswl 0x2(%rdx), %edx
subl %edx, %ecx
movl %ecx, 0x4(%r15)
movl %edx, 0x8(%r15)
cmpb $0x0, (%rbx)
je 0x3a775
movzwl %ax, %r14d
addl %esi, %r14d
movswl 0x14(%rsp), %eax
addl %r12d, %eax
movq 0x58(%rsp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jl 0x3a1d6
jmp 0x3a263
movl %ebx, %esi
movl 0x2c(%rsp), %r15d
testb $0x4, %r15b
movl %r14d, 0x30(%rsp)
jne 0x3a2c1
movl %esi, %r12d
testb $0x8, %r15b
movl 0x18(%rsp), %r8d
je 0x3a308
movl %r12d, %edi
addq 0x20(%rsp), %rdi
movl 0x30(%rsp), %eax
subl %r12d, %eax
movswl 0x30(%rbp), %ecx
movzwl %ax, %esi
movq 0x38(%rsp), %rdx
callq 0x2ab49
movq 0x48(%rsp), %rdx
movzwl 0x4(%rdx), %ecx
addw (%rdx), %ax
subl %eax, %ecx
addw 0x12(%rsp), %cx
incl %ecx
movw %cx, 0x12(%rsp)
jmp 0x3a308
movl %esi, %edi
addq 0x20(%rsp), %rdi
movl %r14d, %eax
movl %esi, %r12d
subl %esi, %eax
movswl 0x30(%rbp), %ecx
movzwl %ax, %esi
movq 0x38(%rsp), %rdx
movl 0x18(%rsp), %r8d
callq 0x2ab49
movq 0x48(%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, 0x12(%rsp)
movq 0x128(%rsp), %rax
cmpb $-0x1, %r13b
je 0x3a32a
movzbl %r13b, %ecx
movzbl 0x34(%rbp), %edx
imull %ecx, %edx
shrl $0x8, %edx
movl %edx, 0x74(%rsp)
jmp 0x3a331
movb 0x34(%rbp), %cl
movl %ecx, 0x74(%rsp)
movq %rbp, 0x50(%rsp)
testq %rax, %rax
je 0x3a34f
movzwl (%rax), %ecx
movzwl 0x2(%rax), %ebp
cmpw %bp, %cx
movl %ebp, %ebx
cmoval %ecx, %ebx
cmovbl %ecx, %ebp
jmp 0x3a357
movw $0xffff, %bx            # imm = 0xFFFF
movw $0xffff, %bp            # imm = 0xFFFF
leaq 0x25c02(%rip), %rsi     # 0x5ff60
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
callq 0x798d
movq 0x50(%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, 0x17(%rsp)
movq 0x78(%rsp), %rax
decl %eax
movl %eax, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
movl %eax, 0x44(%rsp)
movl 0x30(%rsp), %esi
movl %r12d, 0x70(%rsp)
movl %r12d, %ecx
movq 0x20(%rsp), %rax
movq %rcx, 0x30(%rsp)
cmpb $0x0, (%rax,%rcx)
je 0x3a775
movl %esi, %r14d
cmpq $0x0, 0x120(%rsp)
je 0x3a3fe
movl 0x64(%rsp), %eax
addw %ax, 0x12(%rsp)
movl $0x0, 0x1c(%rsp)
movl %r14d, 0x6c(%rsp)
subl 0x70(%rsp), %r14d
movl %r14d, 0x94(%rsp)
jne 0x3a4aa
movl 0x6c(%rsp), %ebx
addq 0x20(%rsp), %rbx
movq 0x50(%rsp), %r12
movswl 0x30(%r12), %edx
movq %rbx, %rdi
movq 0x38(%rsp), %r14
movq %r14, %rsi
movl 0x68(%rsp), %ecx
movl 0x18(%rsp), %ebp
movl %ebp, %r8d
callq 0x2a787
movzwl %ax, %esi
movq 0x48(%rsp), %r13
movzwl (%r13), %eax
movw %ax, 0x12(%rsp)
testb $0x4, %r15b
jne 0x3a717
testb $0x8, %r15b
je 0x3a74f
movswl 0x30(%r12), %ecx
movq %rbx, %rdi
movq %r14, %rdx
movl %esi, %ebx
movl 0x18(%rsp), %r8d
callq 0x2ab49
movl %ebx, %esi
movzwl 0x4(%r13), %ecx
addw (%r13), %ax
subl %eax, %ecx
addw 0x12(%rsp), %cx
incl %ecx
movw %cx, 0x12(%rsp)
jmp 0x3a74f
movq 0x30(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %esi, %esi
xorl %ebp, %ebp
movl $0x0, %r14d
cmpb $0x0, 0x17(%rsp)
je 0x3a4e0
addl 0x70(%rsp), %esi
movq 0x20(%rsp), %rdi
leaq 0x1916e(%rip), %rax     # 0x53648
callq *(%rax)
movzwl %ax, %r14d
movq 0x30(%rsp), %r12
movq %r12, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0x1913c(%rip), %rbx     # 0x53630
callq *(%rbx)
movl %eax, %r13d
movl 0x1c(%rsp), %edi
addq %r12, %rdi
xorl %esi, %esi
callq *(%rbx)
testb $0x1, %r15b
je 0x3a60b
cmpl $0x23, %r13d
jne 0x3a542
xorl %ecx, %ecx
cmpb $0x2, %bpl
je 0x3a701
movzbl %bpl, %edx
cmpl $0x1, %edx
je 0x3a544
testl %edx, %edx
jne 0x3a542
movzwl 0x1c(%rsp), %eax
movq %rax, 0x98(%rsp)
movb $0x1, %bpl
jmp 0x3a6e7
movl %ebp, %ecx
cmpb $0x1, %cl
jne 0x3a609
cmpl $0x20, %r13d
jne 0x3a6fd
movl 0x1c(%rsp), %ecx
movzwl 0x98(%rsp), %eax
subl %eax, %ecx
cmpl $0x7, %ecx
jne 0x3a705
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 0x3a787
movl %eax, %r12d
shlb $0x4, %r12b
movl %ebx, %edi
callq 0x3a787
movl %eax, %ebx
orb %r12b, %bl
movl %r13d, %edi
callq 0x3a787
movl %eax, %r12d
shlb $0x4, %r12b
movl %r15d, %edi
callq 0x3a787
movl %eax, %r15d
orb %r12b, %r15b
movl %r14d, %edi
callq 0x3a787
movl %eax, %r12d
shlb $0x4, %r12b
movl %ebp, %edi
callq 0x3a787
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 0x3a70e
movl %ecx, %ebp
movl 0x44(%rsp), %ebx
cmpb $0x2, %bpl
je 0x3a61e
movq 0x50(%rsp), %rcx
movzwl 0x20(%rcx), %ebx
movq 0x38(%rsp), %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x27d87
movl %eax, %r12d
cmpl 0x90(%rsp), %r14d
setae %al
andb 0x17(%rsp), %al
movzbl 0x74(%rsp), %r15d
cmpb $0x1, %al
jne 0x3a6af
cmpl 0x8c(%rsp), %r14d
jae 0x3a6af
movzwl 0x12(%rsp), %eax
movw %ax, 0x80(%rsp)
movzwl 0x14(%rsp), %ecx
movw %cx, 0x82(%rsp)
addl %r12d, %eax
movq 0x50(%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 0x58(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movl %r15d, %ecx
callq 0x365ac
leaq 0x12(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl %r13d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x35601
testw %r12w, %r12w
jle 0x3a6e2
movq 0x50(%rsp), %rax
addw 0x30(%rax), %r12w
addw %r12w, 0x12(%rsp)
movl 0x2c(%rsp), %r15d
movl 0x1c(%rsp), %esi
cmpl 0x94(%rsp), %esi
jb 0x3a4bd
jmp 0x3a41e
movl %ecx, %ebp
jmp 0x3a6e7
xorl %ebp, %ebp
jmp 0x3a6e7
movq 0x50(%rsp), %rax
movzwl 0x20(%rax), %eax
movl %eax, 0x44(%rsp)
movb $0x2, %bpl
jmp 0x3a6e7
movswl 0x30(%r12), %ecx
movq %rbx, %rdi
movq %r14, %rdx
movl %esi, %ebx
movl %ebp, %r8d
callq 0x2ab49
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, 0x12(%rsp)
movl 0x6c(%rsp), %r12d
addl %r12d, %esi
movzwl 0x14(%rsp), %eax
addw 0x78(%rsp), %ax
movw %ax, 0x14(%rsp)
movq 0x58(%rsp), %rcx
cmpw 0x6(%rcx), %ax
jle 0x3a3cb
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq