// File: /workspace/github_c_makefile_star2_O2/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, 0x78(%rsp)
movq %r8, 0x30(%rsp)
cmpb $0x0, (%r8)
je 0x370fd
movq %rdx, %r14
movq %rdi, %r15
movl %ecx, 0x48(%rsp)
movq 0x120(%rsp), %rbp
movq 0x28(%rdx), %r13
movzbl %r9b, %r10d
testb $0x2, %r9b
movl %r9d, 0x44(%rsp)
movl %r10d, 0x1c(%rsp)
jne 0x369fa
movzwl 0x4(%r15), %eax
movzwl (%r15), %ecx
subl %ecx, %eax
incl %eax
jmp 0x36a32
movswl 0x30(%r14), %ecx
movswl 0x32(%r14), %r8d
movl %r10d, (%rsp)
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movq %r13, %rdx
movl $0x7c18, %r9d           # imm = 0x7C18
callq 0x28723
movzwl (%rbx), %eax
movl 0x1c(%rsp), %r10d
movzwl (%r15), %ecx
movq 0x130(%rsp), %r12
movq %r13, 0x38(%rsp)
movzbl 0x10(%r13), %edx
addw 0x32(%r14), %dx
movq %rdx, 0x50(%rsp)
movw %cx, 0x14(%rsp)
movzwl 0x2(%r15), %edx
movw %dx, 0x16(%rsp)
testq %rbp, %rbp
je 0x36a7f
movzwl (%rbp), %ecx
movl %ecx, 0x58(%rsp)
movzwl 0x2(%rbp), %esi
leal (%rdx,%rsi), %ecx
movw %cx, 0x16(%rsp)
testw %si, %si
sete %sil
jmp 0x36a8c
movb $0x1, %sil
movl $0x0, 0x58(%rsp)
movl %edx, %ecx
movq %r15, 0x68(%rsp)
testq %r12, %r12
setne %dil
andb %sil, %dil
testw %dx, %dx
sets %sil
testb %sil, %dil
movq %r14, 0x20(%rsp)
je 0x36ada
movswl %dx, %edx
movl 0x8(%r12), %esi
subl %edx, %esi
movl %esi, %edx
negl %edx
cmovsl %esi, %edx
movswl 0x50(%rsp), %ebp
movl $0x400, %edi            # imm = 0x400
subl %ebp, %edi
subl %ebp, %edi
cmpl %edi, %edx
jle 0x36c6b
orl $-0x1, (%r12)
jmp 0x36adf
movswl 0x50(%rsp), %ebp
xorl %r14d, %r14d
movq 0x128(%rsp), %r15
movl %r14d, %edi
addq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rcx
movswl 0x30(%rcx), %edx
movswl %ax, %ecx
movq 0x38(%rsp), %rsi
movl %ecx, 0x5c(%rsp)
movl %r10d, %r8d
callq 0x28866
movzwl %ax, %eax
addl %r14d, %eax
movzwl 0x16(%rsp), %ecx
movl %r14d, %edx
movl %eax, %r14d
movswl %cx, %eax
addl %ebp, %eax
movq 0x78(%rsp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x36bab
movl %r14d, %ebx
addq 0x30(%rsp), %rbx
movq 0x20(%rsp), %rax
movswl 0x30(%rax), %edx
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl 0x5c(%rsp), %ecx
movl 0x1c(%rsp), %r8d
callq 0x28866
movzwl 0x16(%rsp), %ecx
addw 0x50(%rsp), %cx
movw %cx, 0x16(%rsp)
testq %r12, %r12
je 0x36b97
cmpw $0xfc00, %cx            # imm = 0xFC00
jl 0x36b97
cmpl $0x0, (%r12)
jns 0x36b97
movl %r14d, (%r12)
movswl %cx, %edx
movq 0x68(%rsp), %rsi
movswl 0x2(%rsi), %esi
subl %esi, %edx
movl %edx, 0x4(%r12)
movl %esi, 0x8(%r12)
movzwl %ax, %eax
addl %r14d, %eax
cmpb $0x0, (%rbx)
jne 0x36b1a
jmp 0x370fd
pushq $0x2
popq %rbx
movl %edx, %edi
movl 0x44(%rsp), %r12d
testb $0x4, %r12b
movl %edx, 0x28(%rsp)
jne 0x36c08
testb $0x8, %r12b
movq 0x68(%rsp), %rbx
movq 0x38(%rsp), %rdx
je 0x36c4b
addq 0x30(%rsp), %rdi
movl %r14d, %eax
subl 0x28(%rsp), %eax
movq 0x20(%rsp), %rcx
movswl 0x30(%rcx), %ecx
movzwl %ax, %esi
movl 0x1c(%rsp), %r8d
callq 0x28bb3
movzwl 0x4(%rbx), %ecx
addw (%rbx), %ax
subl %eax, %ecx
addw 0x14(%rsp), %cx
incl %ecx
movw %cx, 0x14(%rsp)
jmp 0x36c4b
addq 0x30(%rsp), %rdi
movl %r14d, %eax
subl %edx, %eax
movq 0x20(%rsp), %rcx
movswl 0x30(%rcx), %ecx
movzwl %ax, %esi
movq 0x38(%rsp), %rdx
movl 0x1c(%rsp), %r8d
callq 0x28bb3
movq 0x68(%rsp), %rdx
movzwl 0x4(%rdx), %ecx
subw (%rdx), %cx
incl %ecx
movswl %cx, %ecx
cwtl
subl %eax, %ecx
movl %ecx, %eax
cltd
idivl %ebx
addw %ax, 0x14(%rsp)
movl 0x48(%rsp), %eax
cmpb $-0x1, %al
je 0x36c88
movzbl %al, %eax
movq 0x20(%rsp), %rcx
movzbl 0x34(%rcx), %ecx
imull %eax, %ecx
shrl $0x8, %ecx
movl %ecx, 0x64(%rsp)
jmp 0x36c94
movl (%r12), %r14d
testl %r14d, %r14d
js 0x36adf
addw 0x4(%r12), %cx
movw %cx, 0x16(%rsp)
jmp 0x36ae2
movq 0x20(%rsp), %rax
movb 0x34(%rax), %al
movl %eax, 0x64(%rsp)
testq %r15, %r15
je 0x36caf
movzwl (%r15), %eax
movzwl 0x2(%r15), %ebp
cmpw %bp, %ax
movl %ebp, %ebx
cmoval %eax, %ebx
cmovbl %eax, %ebp
jmp 0x36cb7
movw $0xffff, %bx            # imm = 0xFFFF
movw $0xffff, %bp            # imm = 0xFFFF
leaq 0x272a2(%rip), %rsi     # 0x5df60
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
callq 0x74d4
movq 0x20(%rsp), %rax
movq %rax, %r15
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, 0x48(%rsp)
movq 0x50(%rsp), %rax
decl %eax
movl %eax, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
movl %eax, 0x4c(%rsp)
movq 0x120(%rsp), %rbp
movl 0x28(%rsp), %r13d
movl %r13d, 0x60(%rsp)
movl %r13d, %ecx
movq 0x30(%rsp), %rax
movq %rcx, 0x70(%rsp)
cmpb $0x0, (%rax,%rcx)
je 0x370fd
testq %rbp, %rbp
je 0x36d61
movl 0x58(%rsp), %eax
addw %ax, 0x14(%rsp)
movq 0x70(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x70(%rsp)
andl $0x0, 0x2c(%rsp)
movl %r14d, 0x28(%rsp)
subl 0x60(%rsp), %r14d
movl %r14d, 0x94(%rsp)
xorl %esi, %esi
movl $0x0, 0x18(%rsp)
cmpl 0x94(%rsp), %esi
jae 0x3700f
movq %r15, %rbp
movl %r12d, %r15d
xorl %r14d, %r14d
cmpb $0x0, 0x48(%rsp)
je 0x36dc4
addl 0x60(%rsp), %esi
movq 0x30(%rsp), %rdi
leaq 0x1a88a(%rip), %rax     # 0x51648
callq *(%rax)
movzwl %ax, %r14d
movq 0x70(%rsp), %r12
movq %r12, %rdi
leaq 0x2c(%rsp), %rsi
leaq 0x1a858(%rip), %rbx     # 0x51630
callq *(%rbx)
movl %eax, %r13d
movl 0x2c(%rsp), %edi
addq %r12, %rdi
xorl %esi, %esi
callq *(%rbx)
movl %r15d, %r12d
testb $0x1, %r12b
movl 0x18(%rsp), %ecx
jne 0x36e04
movl 0x4c(%rsp), %ebx
cmpb $0x2, %cl
je 0x36e2f
movzwl 0x20(%rbp), %ebx
jmp 0x36e2f
cmpl $0x23, %r13d
jne 0x36f0c
cmpb $0x2, %cl
je 0x36fd3
movzbl %cl, %ecx
cmpl $0x1, %ecx
jne 0x36fdd
movzwl 0x20(%rbp), %ebx
movl $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x2603b
movl %eax, %r12d
cmpl 0x90(%rsp), %r14d
setae %al
andb 0x48(%rsp), %al
movzbl 0x64(%rsp), %r15d
cmpb $0x1, %al
jne 0x36ec0
cmpl 0x8c(%rsp), %r14d
jae 0x36ec0
movzwl 0x14(%rsp), %eax
movw %ax, 0x80(%rsp)
movzwl 0x16(%rsp), %ecx
movw %cx, 0x82(%rsp)
addl %r12d, %eax
movq 0x20(%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 0x78(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movl %r15d, %ecx
callq 0x336d4
leaq 0x14(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x38(%rsp), %rdx
movl %r13d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x3297c
testw %r12w, %r12w
jle 0x36efd
movq 0x20(%rsp), %r15
addw 0x30(%r15), %r12w
addw %r12w, 0x14(%rsp)
movl 0x44(%rsp), %r12d
jmp 0x37006
movl 0x44(%rsp), %r12d
movq 0x20(%rsp), %r15
jmp 0x37006
cmpb $0x1, %cl
jne 0x36df5
cmpl $0x20, %r13d
jne 0x36fea
movl 0x2c(%rsp), %ecx
movzwl 0x98(%rsp), %eax
subl %eax, %ecx
cmpl $0x7, %ecx
jne 0x36ff5
movq 0x70(%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 0x3710f
movl %eax, %r12d
shlb $0x4, %r12b
movl %ebx, %edi
callq 0x3710f
movl %eax, %ebx
orb %r12b, %bl
movl %r13d, %edi
callq 0x3710f
movl %eax, %r12d
shlb $0x4, %r12b
movl %r15d, %edi
callq 0x3710f
movl %eax, %r15d
orb %r12b, %r15b
movl %r14d, %edi
callq 0x3710f
movl %eax, %r12d
shlb $0x4, %r12b
movl %ebp, %edi
callq 0x3710f
orb %r12b, %al
movl 0x44(%rsp), %r12d
shrb $0x3, %al
movzbl %al, %eax
shrb $0x2, %r15b
movzbl %r15b, %ecx
movq 0x20(%rsp), %r15
shll $0x5, %ecx
orl %eax, %ecx
shrb $0x3, %bl
movzbl %bl, %eax
shll $0xb, %eax
orl %ecx, %eax
jmp 0x36ffc
movl $0x0, 0x18(%rsp)
jmp 0x36ff0
movzwl 0x2c(%rsp), %eax
movq %rax, 0x98(%rsp)
movb $0x1, %al
movl %eax, 0x18(%rsp)
movq %rbp, %r15
jmp 0x37006
movq %rbp, %r15
movzwl 0x20(%rbp), %eax
movl %eax, 0x4c(%rsp)
movb $0x2, %al
movl %eax, 0x18(%rsp)
movl 0x2c(%rsp), %esi
jmp 0x36d91
movl 0x28(%rsp), %ebx
addq 0x30(%rsp), %rbx
movswl 0x30(%r15), %edx
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl 0x5c(%rsp), %ecx
movl 0x1c(%rsp), %ebp
movl %ebp, %r8d
callq 0x28866
movq %r15, %rcx
movzwl %ax, %r14d
movq 0x68(%rsp), %r13
movzwl (%r13), %eax
movw %ax, 0x14(%rsp)
testb $0x4, %r12b
jne 0x37096
movq %rcx, %r15
testb $0x8, %r12b
movq 0x120(%rsp), %rbp
je 0x370d7
movswl 0x30(%r15), %ecx
movq %rbx, %rdi
movl %r14d, %esi
movq 0x38(%rsp), %rdx
movl 0x1c(%rsp), %r8d
callq 0x28bb3
movzwl 0x4(%r13), %ecx
addw (%r13), %ax
subl %eax, %ecx
addw 0x14(%rsp), %cx
incl %ecx
movw %cx, 0x14(%rsp)
jmp 0x370d7
movq %rcx, %r15
movswl 0x30(%rcx), %ecx
movq %rbx, %rdi
movl %r14d, %esi
movq 0x38(%rsp), %rdx
movl %ebp, %r8d
callq 0x28bb3
movzwl 0x4(%r13), %ecx
subw (%r13), %cx
incl %ecx
movswl %cx, %ecx
cwtl
subl %eax, %ecx
movl %ecx, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
addw %ax, 0x14(%rsp)
movq 0x120(%rsp), %rbp
movl 0x28(%rsp), %r13d
addl %r13d, %r14d
movzwl 0x16(%rsp), %eax
addw 0x50(%rsp), %ax
movw %ax, 0x16(%rsp)
movq 0x78(%rsp), %rcx
cmpw 0x6(%rcx), %ax
jle 0x36d37
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq