// File: /workspace/github_c_makefile_star2_O1/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:
xorl %eax, %eax
testl %esi, %esi
je 0x2817b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18(%rdi), %r12
cmpl %esi, 0x24(%r12)
jne 0x2801b
movl 0x28(%r12), %eax
jmp 0x2816d
movzwl 0x22(%r12), %eax
testl $0x3ff, %eax            # imm = 0x3FF
je 0x28159
xorl %r13d, %r13d
leaq 0x17aca(%rip), %rdi     # 0x3fb00
xorl %r15d, %r15d
movl %esi, (%rsp)
movq 0x10(%r12), %rax
movl %esi, %ebp
subl (%rax,%r13), %ebp
movl %ebp, 0x4(%rsp)
movzwl 0x4(%rax,%r13), %r14d
cmpl %r14d, %ebp
ja 0x28138
movzbl 0x1a(%rax,%r13), %ecx
xorl %ebx, %ebx
cmpq $0x3, %rcx
ja 0x2812e
movslq (%rdi,%rcx,4), %rcx
addq %rdi, %rcx
jmpq *%rcx
movzwl 0x6(%rax,%r13), %ebx
addl %ebp, %ebx
jmp 0x2812e
movq 0x8(%rax,%r13), %rsi
movzwl 0x18(%rax,%r13), %edx
leaq 0x4(%rsp), %rdi
movl $0x2, %ecx
leaq 0x284(%rip), %r8        # 0x28322
callq 0x2b004
leaq 0x17a56(%rip), %rdi     # 0x3fb00
movl (%rsp), %esi
testq %rax, %rax
je 0x2812e
movq 0x10(%r12), %rcx
subq 0x8(%rcx,%r13), %rax
shrq %rax
movzwl 0x6(%rcx,%r13), %ecx
addl %ecx, %eax
movl %eax, %ebx
jmp 0x2812e
movq 0x8(%rax,%r13), %rsi
movzwl 0x18(%rax,%r13), %edx
leaq 0x4(%rsp), %rdi
movl $0x2, %ecx
leaq 0x23b(%rip), %r8        # 0x28322
callq 0x2b004
leaq 0x17a0d(%rip), %rdi     # 0x3fb00
movl (%rsp), %esi
testq %rax, %rax
je 0x2812e
movq 0x10(%r12), %rcx
subq 0x8(%rcx,%r13), %rax
shrq %rax
movq 0x10(%rcx,%r13), %rdx
movzwl 0x6(%rcx,%r13), %ecx
movzbl (%rdx,%rax), %ebx
addl %ecx, %ebx
jmp 0x2812e
movq 0x10(%rax,%r13), %rcx
movzwl 0x6(%rax,%r13), %eax
movl %ebp, %edx
movzbl (%rcx,%rdx), %ebx
addl %eax, %ebx
movl %esi, 0x24(%r12)
movl %ebx, 0x28(%r12)
cmpl %r14d, %ebp
jbe 0x2816b
incl %r15d
movzwl 0x22(%r12), %eax
andl $0x3ff, %eax            # imm = 0x3FF
addq $0x20, %r13
cmpw %ax, %r15w
jb 0x2803c
movl %esi, 0x24(%r12)
movl $0x0, 0x28(%r12)
xorl %eax, %eax
jmp 0x2816d
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq