// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_font/lv_font_fmt_txt.c
// Function: get_glyph_dsc_id
static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
{
    if(letter == '\0') return 0;

    lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc;

    /*Check the cache first*/
    if(letter == fdsc->last_letter) return fdsc->last_glyph_id;

    uint16_t i;
    for(i = 0; i < fdsc->cmap_num; i++) {

        /*Relative code point*/
        uint32_t rcp = letter - fdsc->cmaps[i].range_start;
        if(rcp > fdsc->cmaps[i].range_length) continue;
        uint32_t glyph_id = 0;
        if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY) {
            glyph_id = fdsc->cmaps[i].glyph_id_start + rcp;
        }
        else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL) {
            const uint8_t * gid_ofs_8 = fdsc->cmaps[i].glyph_id_ofs_list;
            glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_8[rcp];
        }
        else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) {
            uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare);

            if(p) {
                lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t *) fdsc->cmaps[i].unicode_list);
                ofs = ofs >> 1;     /*The list stores `uint16_t` so the get the index divide by 2*/
                glyph_id = fdsc->cmaps[i].glyph_id_start + ofs;
            }
        }
        else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) {
            uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare);

            if(p) {
                lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t*) fdsc->cmaps[i].unicode_list);
                ofs = ofs >> 1;     /*The list stores `uint16_t` so the get the index divide by 2*/
                const uint8_t * gid_ofs_16 = fdsc->cmaps[i].glyph_id_ofs_list;
                glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[ofs];
            }
        }

        /*Update the cache*/
        fdsc->last_letter = letter;
        fdsc->last_glyph_id = glyph_id;
        return glyph_id;
    }

    fdsc->last_letter = letter;
    fdsc->last_glyph_id = 0;
    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebp, %ebp
testl %esi, %esi
je 0x28835
movl %esi, %ebx
movq 0x18(%rdi), %r14
cmpl %esi, 0x24(%r14)
jne 0x2871e
movl 0x28(%r14), %ebp
jmp 0x28835
movzwl 0x22(%r14), %ecx
andq $0x3ff, %rcx            # imm = 0x3FF
je 0x28755
movq 0x10(%r14), %rax
xorl %r15d, %r15d
xorl %esi, %esi
movl %ebx, %edx
subl (%rax,%r15), %edx
movl %edx, 0x4(%rsp)
movzwl 0x4(%rax,%r15), %edi
cmpl %edi, %edx
jbe 0x28766
incq %rsi
addq $0x20, %r15
cmpq %rcx, %rsi
jb 0x28735
movl %ebx, 0x24(%r14)
movl $0x0, 0x28(%r14)
jmp 0x28835
movzbl 0x1a(%rax,%r15), %ecx
xorl %ebp, %ebp
cmpq $0x3, %rcx
ja 0x2882d
leaq 0x17519(%rip), %rsi     # 0x3fc98
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movzwl 0x6(%rax,%r15), %eax
addl %eax, %edx
movl %edx, %ebp
jmp 0x2882d
movq 0x8(%rax,%r15), %rsi
movzwl 0x18(%rax,%r15), %edx
leaq 0x22f(%rip), %r8        # 0x289d8
leaq 0x4(%rsp), %rdi
movl $0x2, %ecx
callq 0x2b755
testq %rax, %rax
je 0x2882d
movq 0x10(%r14), %rcx
subq 0x8(%rcx,%r15), %rax
shrq %rax
movzwl 0x6(%rcx,%r15), %ecx
addl %ecx, %eax
movl %eax, %ebp
jmp 0x2882d
movq 0x8(%rax,%r15), %rsi
movzwl 0x18(%rax,%r15), %edx
leaq 0x1f1(%rip), %r8        # 0x289d8
leaq 0x4(%rsp), %rdi
movl $0x2, %ecx
callq 0x2b755
testq %rax, %rax
je 0x2882d
movq 0x10(%r14), %rcx
subq 0x8(%rcx,%r15), %rax
shrq %rax
movq 0x10(%rcx,%r15), %rdx
movzwl 0x6(%rcx,%r15), %ecx
movzbl (%rdx,%rax), %ebp
addl %ecx, %ebp
jmp 0x2882d
movq 0x10(%rax,%r15), %rcx
movzwl 0x6(%rax,%r15), %eax
movl %edx, %edx
movzbl (%rcx,%rdx), %ebp
addl %eax, %ebp
movl %ebx, 0x24(%r14)
movl %ebp, 0x28(%r14)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq