// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_label.c
// Function: lv_label_get_letter_pos
void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, 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;

    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  the set the max length to very big */
    if(ext->long_mode == LV_LABEL_LONG_EXPAND) {
        max_w = LV_COORD_MAX;
    }

    uint16_t byte_id = lv_txt_encoded_get_byte_id(txt, char_id);

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

        y += letter_height + style->text.line_space;
        line_start = new_line_start;
    }

    /*If the last character is line break then go to the next line*/
    if(byte_id > 0) {
        if((txt[byte_id - 1] == '\n' || txt[byte_id - 1] == '\r') && txt[byte_id] == '\0') {
            y += letter_height + style->text.line_space;
            line_start = byte_id;
        }
    }

    const char *bidi_txt;
    uint16_t visual_byte_pos;
#if LV_USE_BIDI
    /*Handle Bidi*/
    if(new_line_start == byte_id) {
        visual_byte_pos = byte_id - line_start;
        bidi_txt =  &txt[line_start];
    }
    else {
        uint16_t line_char_id = lv_txt_encoded_get_char_id(&txt[line_start], byte_id - line_start);

        bool is_rtl;
        char *mutable_bidi_txt;
        uint16_t visual_char_pos = lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start, lv_obj_get_base_dir(label), line_char_id, &is_rtl);
        bidi_txt = mutable_bidi_txt;
        if (is_rtl) visual_char_pos++;
        visual_byte_pos = lv_txt_encoded_get_byte_id(bidi_txt, visual_char_pos);
    }
#else
    bidi_txt = &txt[line_start];
    visual_byte_pos = byte_id - line_start;
#endif


    /*Calculate the x coordinate*/
    lv_coord_t x = lv_txt_get_width(bidi_txt, visual_byte_pos, font, style->text.letter_space, flag);

    if(char_id != line_start) x += style->text.letter_space;

    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;
    }
    pos->x = x;
    pos->y = y;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movw %si, %ax
movq %rdi, -0x8(%rbp)
movw %ax, -0xa(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x2bcd6
movq -0x8(%rbp), %rsi
leaq 0x3c42d(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x2bcd4
movq -0x18(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x2bcf5
movq -0x18(%rbp), %rsi
leaq 0x3c40e(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x2bcf3
movq -0x8(%rbp), %rdi
callq 0x2abc0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0xa8f0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
movw %ax, -0x32(%rbp)
movq -0x8(%rbp), %rdi
callq 0xa080
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2c020
movb %al, -0x49(%rbp)
movw $0x0, -0x4c(%rbp)
movb $0x0, -0x4d(%rbp)
movq -0x28(%rbp), %rax
movw 0x18(%rax), %ax
shrw $0x6, %ax
andw $0x1, %ax
movzbl %al, %eax
cmpl $0x0, %eax
je 0x2bd7b
movzbl -0x4d(%rbp), %eax
orl $0x1, %eax
movb %al, -0x4d(%rbp)
movq -0x28(%rbp), %rax
movw 0x18(%rax), %ax
shrw $0x7, %ax
andw $0x1, %ax
movzbl %al, %eax
cmpl $0x0, %eax
je 0x2bd9d
movzbl -0x4d(%rbp), %eax
orl $0x2, %eax
movb %al, -0x4d(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2ab50
movb %al, -0x4e(%rbp)
movzbl -0x4e(%rbp), %eax
cmpl $0x1, %eax
jne 0x2bdbc
movzbl -0x4d(%rbp), %eax
orl $0x4, %eax
movb %al, -0x4d(%rbp)
movzbl -0x4e(%rbp), %eax
cmpl $0x2, %eax
jne 0x2bdcf
movzbl -0x4d(%rbp), %eax
orl $0x8, %eax
movb %al, -0x4d(%rbp)
movq -0x28(%rbp), %rax
movw 0x18(%rax), %ax
andw $0x7, %ax
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2bde9
movw $0x7c18, -0x32(%rbp)    # imm = 0x7C18
leaq 0x508e0(%rip), %rax     # 0x7c6d0
movq (%rax), %rax
movq -0x20(%rbp), %rdi
movzwl -0xa(%rbp), %esi
callq *%rax
movw %ax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2be7f
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %eax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rax
movw 0x30(%rax), %cx
movw -0x32(%rbp), %ax
movswl %cx, %edx
movswl %ax, %ecx
movzbl -0x4d(%rbp), %r8d
callq 0x46a40
movzwl %ax, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movzwl -0x50(%rbp), %eax
cmpl -0x30(%rbp), %eax
jb 0x2be5d
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x2be5f
jmp 0x2be7f
movzbl -0x49(%rbp), %ecx
movq -0x40(%rbp), %rax
movswl 0x32(%rax), %eax
addl %eax, %ecx
movswl -0x4c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x4c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x2be01
movzwl -0x50(%rbp), %eax
cmpl $0x0, %eax
jle 0x2bee8
movq -0x20(%rbp), %rax
movzwl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x2beb6
movq -0x20(%rbp), %rax
movzwl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x2bee6
movq -0x20(%rbp), %rax
movzwl -0x50(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x2bee6
movzbl -0x49(%rbp), %ecx
movq -0x40(%rbp), %rax
movswl 0x32(%rax), %eax
addl %eax, %ecx
movswl -0x4c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x4c(%rbp)
movzwl -0x50(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x2bee8
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movzwl -0x50(%rbp), %eax
subl -0x2c(%rbp), %eax
movw %ax, -0x5a(%rbp)
movq -0x58(%rbp), %rdi
movw -0x5a(%rbp), %cx
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rax
movw 0x30(%rax), %ax
movzwl %cx, %esi
movswl %ax, %ecx
movzbl -0x4d(%rbp), %r8d
callq 0x46bd0
movw %ax, -0x5c(%rbp)
movzwl -0xa(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x2bf44
movq -0x40(%rbp), %rax
movswl 0x30(%rax), %ecx
movswl -0x5c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5c(%rbp)
movzbl -0x4e(%rbp), %eax
cmpl $0x1, %eax
jne 0x2bfa8
movq -0x58(%rbp), %rdi
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rax
movw 0x30(%rax), %ax
movzwl %cx, %esi
movswl %ax, %ecx
movzbl -0x4d(%rbp), %r8d
callq 0x46bd0
movw %ax, -0x5e(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
cwtl
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movswl -0x5e(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
subl %eax, %ecx
movswl -0x5c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5c(%rbp)
jmp 0x2bffc
movzbl -0x4e(%rbp), %eax
cmpl $0x2, %eax
jne 0x2bffa
movq -0x58(%rbp), %rdi
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rax
movw 0x30(%rax), %ax
movzwl %cx, %esi
movswl %ax, %ecx
movzbl -0x4d(%rbp), %r8d
callq 0x46bd0
movw %ax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
movswl %ax, %ecx
movswl -0x60(%rbp), %eax
subl %eax, %ecx
movswl -0x5c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x5c(%rbp)
jmp 0x2bffc
movw -0x5c(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movw -0x4c(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)