// File: /workspace/github_c_makefile_star2_O2/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
testl %esi, %esi
je 0x262c1
movl %esi, %ebx
movq 0x18(%rdi), %r14
cmpl %esi, 0x24(%r14)
jne 0x26283
movl 0x28(%r14), %ebp
jmp 0x26391
movzwl 0x22(%r14), %eax
andl $0x3ff, %eax            # imm = 0x3FF
xorl %r15d, %r15d
xorl %esi, %esi
cmpq %rax, %rsi
jae 0x262b8
movq 0x10(%r14), %rcx
movl %ebx, %edx
subl (%rcx,%r15), %edx
movl %edx, 0x4(%rsp)
movzwl 0x4(%rcx,%r15), %edi
cmpl %edi, %edx
jbe 0x262c8
incq %rsi
addq $0x20, %r15
jmp 0x26292
movl %ebx, 0x24(%r14)
andl $0x0, 0x28(%r14)
xorl %ebp, %ebp
jmp 0x26391
movzbl 0x1a(%rcx,%r15), %eax
xorl %ebp, %ebp
cmpq $0x3, %rax
ja 0x26389
leaq 0x158a3(%rip), %rsi     # 0x3bb84
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
movzwl 0x6(%rcx,%r15), %eax
addl %eax, %edx
movl %edx, %ebp
jmp 0x26389
movq 0x8(%rcx,%r15), %rsi
movzwl 0x18(%rcx,%r15), %edx
leaq 0x225(%rip), %r8        # 0x26530
leaq 0x4(%rsp), %rdi
pushq $0x2
popq %rcx
callq 0x28faf
testq %rax, %rax
je 0x26389
movq 0x10(%r14), %rcx
subq 0x8(%rcx,%r15), %rax
shrq %rax
movzwl 0x6(%rcx,%r15), %ecx
addl %ecx, %eax
movl %eax, %ebp
jmp 0x26389
movq 0x8(%rcx,%r15), %rsi
movzwl 0x18(%rcx,%r15), %edx
leaq 0x1e9(%rip), %r8        # 0x26530
leaq 0x4(%rsp), %rdi
pushq $0x2
popq %rcx
callq 0x28faf
testq %rax, %rax
je 0x26389
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
jmp 0x26387
movq 0x10(%rcx,%r15), %rax
movzwl 0x6(%rcx,%r15), %ecx
movl %edx, %edx
movzbl (%rax,%rdx), %ebp
addl %ecx, %ebp
movl %ebx, 0x24(%r14)
movl %ebp, 0x28(%r14)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq