// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r12
callq 0x80d4
testb %al, %al
je 0x1ae4a
movq %r14, %rdi
callq 0x80d4
testb %al, %al
je 0x1ae5b
movq %r14, 0x30(%rsp)
movq %r12, %rdi
callq 0x1a239
movq %rax, %r15
movq %r12, %rdi
callq 0x6ad8
movq %rax, %rbp
movq %r12, %rdi
callq 0x5651
movl %eax, 0x4(%rsp)
movq %r12, %rdi
callq 0x6697
movq %rax, 0x8(%rsp)
movq 0x28(%rax), %rax
movq %rax, 0x10(%rsp)
movzbl 0x10(%rax), %r13d
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 %r12, 0x28(%rsp)
movq %r12, %rdi
callq 0x1a1ff
leal 0x4(%r14), %ecx
cmpb $0x1, %al
movzbl %cl, %edx
cmovnel %r14d, %edx
movl %edx, %ecx
orb $0x8, %cl
movb %al, 0x3(%rsp)
cmpb $0x2, %al
movzbl %cl, %r14d
cmovnel %edx, %r14d
movzwl 0x18(%rbp), %eax
testb $0x7, %al
movl $0x7c18, %ebp           # imm = 0x7C18
cmovnel 0x4(%rsp), %ebp
leaq 0x38889(%rip), %rax     # 0x53640
movzwl %bx, %esi
movq %r15, %rdi
movl %esi, 0x20(%rsp)
callq *(%rax)
movl %eax, %ecx
cmpb $0x0, (%r15)
movzbl %r14b, %eax
movl %eax, 0x4(%rsp)
movl %r13d, 0x18(%rsp)
movl %ecx, 0x1c(%rsp)
je 0x1ae71
movzwl %cx, %r14d
movl %r13d, %eax
xorl %r13d, %r13d
movswl %bp, %ebx
movzwl %ax, %eax
movl %eax, 0x24(%rsp)
movq %r15, %rdi
xorl %r12d, %r12d
movq 0x8(%rsp), %rdx
movswl 0x30(%rdx), %edx
movq 0x10(%rsp), %rsi
movl %ebx, %ecx
movl 0x4(%rsp), %r8d
callq 0x2a787
movl %r13d, %ecx
movzwl %ax, %ebp
addq %rcx, %rbp
cmpl %ebp, %r14d
jb 0x1ae6c
cmpb $0x0, (%r15,%rbp)
je 0x1ae6c
addl 0x24(%rsp), %r12d
leaq (%r15,%rbp), %rdi
movl %ebp, %r13d
movl %ebp, %eax
movq 0x8(%rsp), %rdx
addw 0x32(%rdx), %r12w
cmpb $0x0, (%r15,%rbp)
jne 0x1adff
jmp 0x1ae7d
leaq 0x242e3(%rip), %rdi     # 0x3f134
movq %r12, %rsi
callq 0x829e
jmp 0x1ae59
leaq 0x242d2(%rip), %rdi     # 0x3f134
movq %r14, %rsi
callq 0x829e
jmp 0x1ae6a
movl %r13d, %eax
jmp 0x1ae78
xorl %r12d, %r12d
xorl %eax, %eax
xorl %ebp, %ebp
movq 0x8(%rsp), %rdx
movl 0x1c(%rsp), %esi
movzwl %si, %ebx
testl %ebx, %ebx
je 0x1aea8
movzbl -0x1(%r15,%rbx), %ecx
cmpl $0xd, %ecx
movq 0x30(%rsp), %r14
je 0x1ae9d
cmpl $0xa, %ecx
jne 0x1aea4
cmpb $0x0, (%r15,%rbx)
je 0x1aeb1
movl %eax, %ebx
jmp 0x1aebe
movl %eax, %ebx
movq 0x30(%rsp), %r14
jmp 0x1aebe
movzwl 0x18(%rsp), %eax
addl %eax, %r12d
addw 0x32(%rdx), %r12w
movl %ebx, %eax
addq %rax, %r15
subl %ebx, %esi
movswl 0x30(%rdx), %ecx
movzwl %si, %esi
movq %r15, %rdi
movq %rdx, %r13
movq 0x10(%rsp), %rdx
movl 0x4(%rsp), %r8d
callq 0x2ab49
movl %eax, %edx
cmpl 0x20(%rsp), %ebx
je 0x1aeee
addw 0x30(%r13), %dx
movq %r13, %rax
movb 0x3(%rsp), %cl
cmpb $0x1, %cl
jne 0x1af45
subl %ebx, %ebp
movswl 0x30(%rax), %ecx
movzwl %bp, %esi
movq %r15, %rdi
movl %edx, %r15d
movq 0x10(%rsp), %rdx
movl 0x4(%rsp), %r8d
callq 0x2ab49
movl %eax, %ebp
movzwl %ax, %ebx
movq 0x28(%rsp), %rdi
callq 0x5651
movl %r15d, %edx
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
shrl $0xf, %ebx
addl %ebp, %ebx
movswl %bx, %ecx
sarl %ecx
subl %ecx, %edx
jmp 0x1af77
cmpb $0x2, %cl
jne 0x1af79
subl %ebx, %ebp
movswl 0x30(%rax), %ecx
movzwl %bp, %esi
movq %r15, %rdi
movl %edx, %ebx
movq 0x10(%rsp), %rdx
movl 0x4(%rsp), %r8d
callq 0x2ab49
movl %eax, %ebp
movq 0x28(%rsp), %rdi
callq 0x5651
movl %ebx, %edx
subl %ebp, %edx
addl %eax, %edx
movw %dx, (%r14)
movw %r12w, 0x2(%r14)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq