// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x2c072
movq -0x8(%rbp), %rsi
leaq 0x3c091(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x2c070
movq -0x10(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x2c091
movq -0x10(%rbp), %rsi
leaq 0x3c072(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x2c08f
movq -0x8(%rbp), %rdi
callq 0x2abc0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xa8f0
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
movw %ax, -0x2a(%rbp)
movq -0x8(%rbp), %rdi
callq 0xa080
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2c020
movb %al, -0x41(%rbp)
movw $0x0, -0x44(%rbp)
movb $0x0, -0x45(%rbp)
movq -0x20(%rbp), %rax
movw 0x18(%rax), %ax
shrw $0x6, %ax
andw $0x1, %ax
movzbl %al, %eax
cmpl $0x0, %eax
je 0x2c117
movzbl -0x45(%rbp), %eax
orl $0x1, %eax
movb %al, -0x45(%rbp)
movq -0x20(%rbp), %rax
movw 0x18(%rax), %ax
shrw $0x7, %ax
andw $0x1, %ax
movzbl %al, %eax
cmpl $0x0, %eax
je 0x2c139
movzbl -0x45(%rbp), %eax
orl $0x2, %eax
movb %al, -0x45(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2ab50
movb %al, -0x51(%rbp)
movzbl -0x51(%rbp), %eax
cmpl $0x1, %eax
jne 0x2c158
movzbl -0x45(%rbp), %eax
orl $0x4, %eax
movb %al, -0x45(%rbp)
movzbl -0x51(%rbp), %eax
cmpl $0x2, %eax
jne 0x2c16b
movzbl -0x45(%rbp), %eax
orl $0x8, %eax
movb %al, -0x45(%rbp)
movq -0x20(%rbp), %rax
movw 0x18(%rax), %ax
andw $0x7, %ax
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2c185
movw $0x7c18, -0x2a(%rbp)    # imm = 0x7C18
jmp 0x2c187
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2c245
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %eax
addq %rax, %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
movw 0x30(%rax), %cx
movw -0x2a(%rbp), %ax
movswl %cx, %edx
movswl %ax, %ecx
movzbl -0x45(%rbp), %r8d
callq 0x46a40
movzwl %ax, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movswl 0x2(%rax), %eax
movswl -0x44(%rbp), %ecx
movzbl -0x41(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jg 0x2c222
movl -0x28(%rbp), %eax
movl %eax, -0x58(%rbp)
leaq 0x504d7(%rip), %rax     # 0x7c6c8
movq (%rax), %rax
movq -0x18(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq *%rax
movl %eax, -0x5c(%rbp)
cmpl $0xa, -0x5c(%rbp)
je 0x2c220
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x2c220
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2c245
movzbl -0x41(%rbp), %ecx
movq -0x38(%rbp), %rax
movswl 0x32(%rax), %eax
addl %eax, %ecx
movswl -0x44(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x44(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x2c187
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movw $0x0, -0x5e(%rbp)
movzbl -0x51(%rbp), %eax
cmpl $0x1, %eax
jne 0x2c2bd
movq -0x50(%rbp), %rdi
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
movw %ax, %cx
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
movw 0x30(%rax), %ax
movzwl %cx, %esi
movswl %ax, %ecx
movzbl -0x45(%rbp), %r8d
callq 0x46bd0
movw %ax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
cwtl
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movswl -0x60(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
subl %eax, %ecx
movswl -0x5e(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5e(%rbp)
jmp 0x2c311
movzbl -0x51(%rbp), %eax
cmpl $0x2, %eax
jne 0x2c30f
movq -0x50(%rbp), %rdi
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
movw %ax, %cx
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
movw 0x30(%rax), %ax
movzwl %cx, %esi
movswl %ax, %ecx
movzbl -0x45(%rbp), %r8d
callq 0x46bd0
movw %ax, -0x62(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
movswl %ax, %ecx
movswl -0x62(%rbp), %eax
subl %eax, %ecx
movswl -0x5e(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5e(%rbp)
jmp 0x2c311
movb $0x0, -0x63(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x28(%rbp)
jbe 0x2c3fc
jmp 0x2c32e
movl -0x68(%rbp), %eax
addl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x2c3fa
leaq 0x5037c(%rip), %rax     # 0x7c6c0
movq (%rax), %rax
movq -0x50(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq *%rax
movl %eax, -0x70(%rbp)
leaq 0x50365(%rip), %rax     # 0x7c6c0
movq (%rax), %rax
movq -0x50(%rbp), %rdi
movl -0x68(%rbp), %ecx
addq %rcx, %rdi
xorl %ecx, %ecx
movl %ecx, %esi
callq *%rax
movl %eax, -0x74(%rbp)
movzbl -0x45(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2c39f
movq -0x50(%rbp), %rax
movl -0x68(%rbp), %ecx
movsbl (%rax,%rcx), %esi
leaq -0x63(%rbp), %rdi
callq 0x46ff0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x2c39d
jmp 0x2c32e
jmp 0x2c39f
movq -0x40(%rbp), %rdi
movl -0x70(%rbp), %esi
movl -0x74(%rbp), %edx
callq 0x415e0
movzwl %ax, %ecx
movswl -0x5e(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5e(%rbp)
movq -0x10(%rbp), %rax
movswl (%rax), %eax
movswl -0x5e(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2c3d5
movl -0x68(%rbp), %eax
addl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x2c3dd
movl -0x6c(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x2c3fa
movq -0x38(%rbp), %rax
movswl 0x30(%rax), %ecx
movswl -0x5e(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5e(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x2c32e
jmp 0x2c3fc
leaq 0x502d5(%rip), %rax     # 0x7c6d8
movq (%rax), %rax
movq -0x50(%rbp), %rdi
movl -0x68(%rbp), %esi
callq *%rax
movw %ax, -0x48(%rbp)
movzwl -0x48(%rbp), %eax
movl %eax, -0x78(%rbp)
leaq 0x502b7(%rip), %rax     # 0x7c6d8
movq (%rax), %rax
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
callq *%rax
movl %eax, %ecx
movl -0x78(%rbp), %eax
addl %ecx, %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)