// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r12
movl %esi, %ebx
movq %rdi, %r15
callq 0x80e4
testb %al, %al
je 0x1b5d4
movq %r12, %rdi
callq 0x80e4
testb %al, %al
je 0x1b5e5
movq %r15, %rdi
callq 0x1aa00
movq %rax, 0x30(%rsp)
movq %r15, %rdi
callq 0x6af7
movq %rax, %rbp
movq %r15, %rdi
callq 0x566d
movl %eax, 0x10(%rsp)
movq %r15, %rdi
callq 0x66b6
movq %rax, 0x18(%rsp)
movq 0x28(%rax), %r13
movzbl 0x10(%r13), %eax
movl %eax, 0x24(%rsp)
movb 0x18(%rbp), %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, 0x50(%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, 0xf(%rsp)
cmpb $0x2, %al
movzbl %cl, %eax
movl %eax, 0x3c(%rsp)
cmovel %eax, %r14d
movzwl 0x18(%rbp), %eax
testb $0x7, %al
movl $0x7c18, %r15d          # imm = 0x7C18
cmovnel 0x10(%rsp), %r15d
leaq 0x380e0(%rip), %rax     # 0x53640
movzwl %bx, %esi
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movl %esi, 0x48(%rsp)
callq *(%rax)
movq %rbx, %r9
cmpb $0x0, (%rbx)
movl %eax, 0x44(%rsp)
movzwl %ax, %r10d
movzbl %r14b, %r8d
movq %r13, 0x10(%rsp)
movq %r12, 0x28(%rsp)
je 0x1b5f6
movq 0x18(%rsp), %rax
movswl 0x30(%rax), %edx
movswl %r15w, %ecx
movq %r9, %rdi
movq %r13, %rsi
movl %ecx, 0x4c(%rsp)
movl %r8d, %ebp
movq %r10, %rbx
callq 0x2ae1d
movq %rbx, %r10
movzwl %ax, %r15d
xorl %r12d, %r12d
cmpl %r15d, %r10d
jae 0x1b605
xorl %eax, %eax
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %rsi
movl %ebp, %r8d
jmp 0x1b66b
leaq 0x23c09(%rip), %rdi     # 0x3f1e4
movq %r15, %rsi
callq 0x8294
jmp 0x1b5e3
leaq 0x23bf8(%rip), %rdi     # 0x3f1e4
movq %r12, %rsi
callq 0x8294
jmp 0x1b5f4
xorl %r12d, %r12d
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x18(%rsp), %rsi
jmp 0x1b66b
xorl %r12d, %r12d
movzwl 0x24(%rsp), %r13d
xorl %eax, %eax
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %rsi
movl %ebp, %r8d
movl %r15d, %r14d
movl %r15d, %edi
cmpb $0x0, (%r9,%rdi)
je 0x1b668
addq %r9, %rdi
addl %r13d, %r12d
addw 0x32(%rsi), %r12w
movswl 0x30(%rsi), %edx
movq 0x10(%rsp), %rsi
movl 0x4c(%rsp), %ecx
callq 0x2ae1d
movq %rbx, %r10
movl %ebp, %r8d
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %r9
movzwl %ax, %r15d
addl %r14d, %r15d
movl %r14d, %eax
cmpl %r15d, %r10d
jae 0x1b61d
jmp 0x1b66b
movl %r14d, %r15d
testl %r10d, %r10d
je 0x1b691
movzbl -0x1(%r9,%r10), %ecx
cmpl $0xd, %ecx
movq 0x10(%rsp), %rdx
je 0x1b685
cmpl $0xa, %ecx
jne 0x1b68c
cmpb $0x0, (%r9,%r10)
je 0x1b6a0
movl %eax, %r10d
jmp 0x1b6ad
movl %eax, %r10d
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %rdx
jmp 0x1b6b2
movzwl 0x24(%rsp), %eax
addl %eax, %r12d
addw 0x32(%rsi), %r12w
movq 0x28(%rsp), %rbp
movl %r10d, %eax
addq %rax, %r9
movl 0x44(%rsp), %eax
subl %r10d, %eax
movswl 0x30(%rsi), %ecx
movq %rsi, %r13
movzwl %ax, %esi
movq %r9, %r14
movq %r9, %rdi
movq %r10, %rbx
callq 0x2b2a4
movq %rbx, %rcx
movl %eax, %ebx
cmpl 0x48(%rsp), %ecx
je 0x1b6e7
addw 0x30(%r13), %bx
movb 0xf(%rsp), %al
cmpb $0x1, %al
movq %r14, %rdi
jne 0x1b741
subl %ecx, %r15d
movswl 0x30(%r13), %ecx
movzwl %r15w, %esi
movq 0x10(%rsp), %rdx
movl 0x40(%rsp), %r8d
callq 0x2b2a4
movq %rbp, %r15
movl %eax, %ebp
movzwl %ax, %r14d
movq 0x50(%rsp), %rdi
callq 0x566d
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
shrl $0xf, %r14d
addl %ebp, %r14d
movq %r15, %rbp
movswl %r14w, %ecx
sarl %ecx
subl %ecx, %ebx
jmp 0x1b774
cmpb $0x2, %al
jne 0x1b776
subl %ecx, %r15d
movswl 0x30(%r13), %ecx
movzwl %r15w, %esi
movq 0x10(%rsp), %rdx
movl 0x3c(%rsp), %r8d
callq 0x2b2a4
movq %rbp, %r14
movl %eax, %ebp
movq 0x50(%rsp), %rdi
callq 0x566d
subl %ebp, %ebx
movq %r14, %rbp
addl %eax, %ebx
movw %bx, (%rbp)
movw %r12w, 0x2(%rbp)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq