// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_label.c
// Function: lv_label_get_letter_on
uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
{
    LV_ASSERT_OBJ(label, LV_OBJX_NAME);
    LV_ASSERT_NULL(pos);

    const char * txt         = lv_label_get_text(label);
    lv_label_ext_t * ext     = lv_obj_get_ext_attr(label);
    uint32_t line_start      = 0;
    uint32_t new_line_start  = 0;
    lv_coord_t max_w         = lv_obj_get_width(label);
    const lv_style_t * style = lv_obj_get_style(label);
    const lv_font_t * font   = style->text.font;
    uint8_t letter_height    = lv_font_get_line_height(font);
    lv_coord_t y             = 0;
    lv_txt_flag_t flag       = LV_TXT_FLAG_NONE;
    uint16_t logical_pos;
    char *bidi_txt;

    if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
    if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;

    lv_label_align_t align = lv_label_get_align(label);
    if(align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
    if(align == LV_LABEL_ALIGN_RIGHT) flag |= LV_TXT_FLAG_RIGHT;

    /*If the width will be expanded set the max length to very big */
    if(ext->long_mode == LV_LABEL_LONG_EXPAND) {
        max_w = LV_COORD_MAX;
    }

    /*Search the line of the index letter */;
    while(txt[line_start] != '\0') {
        new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag);

        if(pos->y <= y + letter_height) {
            /*The line is found (stored in 'line_start')*/
            /* Include the NULL terminator in the last line */
            uint32_t tmp = new_line_start;
            uint32_t letter;
            letter = lv_txt_encoded_prev(txt, &tmp);
            if(letter != '\n' && txt[new_line_start] == '\0' ) new_line_start++;
            break;
        }
        y += letter_height + style->text.line_space;

        line_start = new_line_start;
    }

#if LV_USE_BIDI
    bidi_txt = lv_draw_get_buf(new_line_start - line_start + 1);
    uint16_t txt_len = new_line_start - line_start;
    if(bidi_txt[new_line_start] == '\0') txt_len--;
    lv_bidi_process_paragraph(txt + line_start, bidi_txt, txt_len, lv_obj_get_base_dir(label), NULL, 0);
#else
    bidi_txt = (char*)txt + line_start;
#endif

    /*Calculate the x coordinate*/
    lv_coord_t x = 0;
    if(align == LV_LABEL_ALIGN_CENTER) {
        lv_coord_t line_w;
        line_w = lv_txt_get_width(bidi_txt, new_line_start - line_start, font, style->text.letter_space, flag);
        x += lv_obj_get_width(label) / 2 - line_w / 2;
    }
    else if(align == LV_LABEL_ALIGN_RIGHT) {
        lv_coord_t line_w;
        line_w = lv_txt_get_width(bidi_txt, new_line_start - line_start, font, style->text.letter_space, flag);
        x += lv_obj_get_width(label) - line_w;
    }

    lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;

    uint32_t i = 0;
    uint32_t i_act = i;
    uint32_t letter;
    uint32_t letter_next;

    if(new_line_start > 0) {
        while(i + line_start < new_line_start) {
            /* Get the current letter.*/
            letter = lv_txt_encoded_next(bidi_txt, &i);

            /*Get the next letter too for kerning*/
            letter_next = lv_txt_encoded_next(&bidi_txt[i], NULL);

            /*Handle the recolor command*/
            if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
                if(lv_txt_is_cmd(&cmd_state, bidi_txt[i]) != false) {
                    continue; /*Skip the letter is it is part of a command*/
                }
            }

            x += lv_font_get_glyph_width(font, letter, letter_next);

            /*Finish if the x position or the last char of the line is reached*/
            if(pos->x < x || i + line_start == new_line_start) {
                i = i_act;
                break;
            }
            x += style->text.letter_space;
            i_act = i;
        }
    }

#if LV_USE_BIDI
    /*Handle Bidi*/
    bool is_rtl;
    logical_pos = lv_bidi_get_logical_pos(&txt[line_start], NULL, txt_len, lv_obj_get_base_dir(label), lv_txt_encoded_get_char_id(bidi_txt, i), &is_rtl);
    if (is_rtl) logical_pos++;
#else
    logical_pos = lv_txt_encoded_get_char_id(bidi_txt, i);
#endif

    return  logical_pos + lv_txt_encoded_get_char_id(txt, line_start);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
movq %rdi, %r15
callq 0x80e4
testb %al, %al
je 0x1b8e1
movq %rbx, %rdi
callq 0x80e4
testb %al, %al
je 0x1b8f2
movq %rbx, 0x50(%rsp)
movq %r15, %rdi
callq 0x1aa00
movq %rax, %r13
movq %r15, %rdi
callq 0x6af7
movq %rax, %rbx
movq %r15, %rdi
callq 0x566d
movl %eax, %ebp
movq %r15, %rdi
callq 0x66b6
movq %rax, 0x18(%rsp)
movq 0x28(%rax), %rax
movq %rax, 0x28(%rsp)
movzbl 0x10(%rax), %eax
movl %eax, 0x14(%rsp)
movb 0x18(%rbx), %al
movl %eax, %ecx
shrb $0x6, %cl
movl %ecx, %edx
andb $0x1, %dl
orb $0x2, %cl
testb %al, %al
movzbl %dl, %eax
movzbl %cl, %r14d
cmovnsl %eax, %r14d
movq %r15, 0x48(%rsp)
movq %r15, %rdi
callq 0x1a9c6
leal 0x4(%r14), %ecx
cmpb $0x1, %al
movzbl %cl, %ecx
movl %ecx, 0x40(%rsp)
cmovel %ecx, %r14d
movl %r14d, %ecx
orb $0x8, %cl
movb %al, 0xe(%rsp)
cmpb $0x2, %al
movzbl %cl, %eax
movl %eax, 0x3c(%rsp)
cmovel %eax, %r14d
testb $0x7, 0x18(%rbx)
movl $0x7c18, %eax           # imm = 0x7C18
cmovnel %ebp, %eax
cmpb $0x0, (%r13)
movq %r13, 0x30(%rsp)
movq %r14, 0x58(%rsp)
je 0x1b903
xorl %r15d, %r15d
cwtl
movl %eax, 0x20(%rsp)
movzbl %r14b, %eax
movl %eax, 0x44(%rsp)
xorl %ebx, %ebx
movq 0x18(%rsp), %r14
movswl 0x30(%r14), %edx
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movl 0x20(%rsp), %ecx
movl 0x44(%rsp), %r8d
callq 0x2ae1d
movzwl %ax, %ebp
addl %r15d, %ebp
movq 0x50(%rsp), %rax
movswl 0x2(%rax), %eax
movswl %bx, %ebx
addl 0x14(%rsp), %ebx
cmpl %eax, %ebx
jge 0x1b90a
movzwl 0x32(%r14), %eax
addl %eax, %ebx
movl %ebp, %eax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %r13
cmpb $0x0, (%rcx,%rax)
movl %ebp, %r15d
movl %ebp, %r12d
jne 0x1b88c
jmp 0x1b936
leaq 0x238fc(%rip), %rdi     # 0x3f1e4
movq %r15, %rsi
callq 0x8294
jmp 0x1b8f0
leaq 0x238eb(%rip), %rdi     # 0x3f1e4
movq %rbx, %rsi
callq 0x8294
jmp 0x1b901
xorl %ebp, %ebp
xorl %r12d, %r12d
jmp 0x1b936
leaq 0x64(%rsp), %rsi
movl %ebp, (%rsi)
leaq 0x37d20(%rip), %rax     # 0x53638
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq *(%rax)
cmpl $0xa, %eax
je 0x1b930
movl %ebp, %eax
cmpb $0x1, (%rbx,%rax)
adcl $0x0, %ebp
movl %ebp, %r12d
movl %r15d, %ebp
movb 0xe(%rsp), %al
cmpb $0x1, %al
jne 0x1b98d
movl %r12d, %eax
subl %ebp, %eax
movq 0x18(%rsp), %rcx
movswl 0x30(%rcx), %ecx
movzwl %ax, %esi
movq %r13, %rdi
movq 0x28(%rsp), %rdx
movl 0x40(%rsp), %r8d
callq 0x2b2a4
movl %eax, %r14d
movzwl %ax, %ebx
movq 0x48(%rsp), %rdi
callq 0x566d
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
shrl $0xf, %ebx
addl %r14d, %ebx
movswl %bx, %ecx
sarl %ecx
subl %ecx, %eax
jmp 0x1b9c8
cmpb $0x2, %al
jne 0x1b9c6
movl %r12d, %eax
subl %ebp, %eax
movq 0x18(%rsp), %rcx
movswl 0x30(%rcx), %ecx
movzwl %ax, %esi
movq %r13, %rdi
movq 0x28(%rsp), %rdx
movl 0x3c(%rsp), %r8d
callq 0x2b2a4
movl %eax, %r14d
movq 0x48(%rsp), %rdi
callq 0x566d
subl %r14d, %eax
jmp 0x1b9c8
xorl %eax, %eax
movb $0x0, 0xf(%rsp)
movl $0x0, 0x10(%rsp)
testl %r12d, %r12d
je 0x1ba7b
movl %eax, 0x14(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x37c3e(%rip), %rbx     # 0x53630
movl 0x10(%rsp), %esi
leal (%rsi,%rbp), %eax
cmpl %r12d, %eax
jae 0x1ba7d
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq *(%rbx)
movl %eax, %r15d
movl 0x10(%rsp), %edi
addq %r13, %rdi
xorl %esi, %esi
callq *(%rbx)
movl %eax, %r14d
testb $0x1, 0x58(%rsp)
je 0x1ba38
movl 0x10(%rsp), %eax
movsbl (%r13,%rax), %esi
leaq 0xf(%rsp), %rdi
callq 0x2b3cf
testb %al, %al
jne 0x1b9f2
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x28487
movl 0x14(%rsp), %edx
addl %eax, %edx
movq 0x50(%rsp), %rax
cmpw %dx, (%rax)
jl 0x1baa7
movl 0x10(%rsp), %eax
leal (%rax,%rbp), %ecx
cmpl %r12d, %ecx
je 0x1baa7
movq 0x18(%rsp), %rcx
addw 0x30(%rcx), %dx
movl %edx, 0x14(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x1b9f2
xorl %esi, %esi
leaq 0x37bc4(%rip), %r14     # 0x53648
movq %r13, %rdi
callq *(%r14)
movl %eax, %ebx
movq 0x30(%rsp), %rdi
movl %ebp, %esi
callq *(%r14)
addl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rsi
movl %esi, 0x10(%rsp)
jmp 0x1ba7d