// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_img_decoder.c
// Function: lv_img_decoder_built_in_line_indexed
static lv_res_t lv_img_decoder_built_in_line_indexed(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
                                                     lv_coord_t len, uint8_t * buf)
{

#if LV_IMG_CF_INDEXED
    uint8_t px_size = lv_img_color_format_get_px_size(dsc->header.cf);
    uint16_t mask   = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/

    lv_coord_t w = 0;
    int8_t pos   = 0;
    uint32_t ofs = 0;
    switch(dsc->header.cf) {
        case LV_IMG_CF_INDEXED_1BIT:
            w = (dsc->header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/
            if(dsc->header.w & 0x7) w++;
            ofs += w * y + (x >> 3); /*First pixel*/
            ofs += 8;                /*Skip the palette*/
            pos = 7 - (x & 0x7);
            break;
        case LV_IMG_CF_INDEXED_2BIT:
            w = (dsc->header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
            if(dsc->header.w & 0x3) w++;
            ofs += w * y + (x >> 2); /*First pixel*/
            ofs += 16;               /*Skip the palette*/
            pos = 6 - ((x & 0x3) * 2);
            break;
        case LV_IMG_CF_INDEXED_4BIT:
            w = (dsc->header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
            if(dsc->header.w & 0x1) w++;
            ofs += w * y + (x >> 1); /*First pixel*/
            ofs += 64;               /*Skip the palette*/
            pos = 4 - ((x & 0x1) * 4);
            break;
        case LV_IMG_CF_INDEXED_8BIT:
            w = dsc->header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
            ofs += w * y + x;  /*First pixel*/
            ofs += 1024;       /*Skip the palette*/
            pos = 0;
            break;
    }

    lv_img_decoder_built_in_data_t * user_data = dsc->user_data;

#if LV_USE_FILESYSTEM
    uint8_t fs_buf[LV_HOR_RES_MAX];
#endif
    const uint8_t * data_tmp = NULL;
    if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
        const lv_img_dsc_t * img_dsc = dsc->src;
        data_tmp                     = img_dsc->data + ofs;
    } else {
#if LV_USE_FILESYSTEM
        lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/
        lv_fs_read(user_data->f, fs_buf, w, NULL);
        data_tmp = fs_buf;
#else
        LV_LOG_WARN("Image built-in indexed line reader can't read file because LV_USE_FILESYSTEM = 0");
        data_tmp = NULL; /*To avoid warnings*/
        return LV_RES_INV;
#endif
    }

    uint8_t val_act;
    lv_coord_t i;
    for(i = 0; i < len; i++) {
        val_act = (*data_tmp & (mask << pos)) >> pos;

        lv_color_t color = user_data->palette[val_act];
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = color.full;
#elif LV_COLOR_DEPTH == 16
        /*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = color.full & 0xFF;
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (color.full >> 8) & 0xFF;
#elif LV_COLOR_DEPTH == 32
        *((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = color.full;
#else
#error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h"
#endif
        buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] = user_data->opa[val_act];

        pos -= px_size;
        if(pos < 0) {
            pos = 8 - px_size;
            data_tmp++;
        }
    }

    return LV_RES_OK;
#else
    LV_LOG_WARN("Image built-in indexed line reader failed because LV_IMG_CF_INDEXED is 0 in lv_conf.h");
    return LV_RES_INV;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movw %cx, %ax
movw %dx, %cx
movw %si, %dx
movq %rdi, -0x8(%rbp)
movw %dx, -0xa(%rbp)
movw %cx, -0xc(%rbp)
movw %ax, -0xe(%rbp)
movq %r8, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %edi
andl $0x1f, %edi
callq 0x62530
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %cl
movl $0x1, %eax
shll %cl, %eax
decl %eax
movw %ax, -0x1c(%rbp)
movw $0x0, -0x1e(%rbp)
movb $0x0, -0x1f(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x1f, %eax
addl $-0x7, %eax
movl %eax, %ecx
movq %rcx, -0x190(%rbp)
subl $0x3, %eax
ja 0x664c0
movq -0x190(%rbp), %rax
leaq 0x5d78(%rip), %rcx      # 0x6c0a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
sarl $0x3, %eax
movw %ax, -0x1e(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
andl $0x7, %eax
cmpl $0x0, %eax
je 0x6636a
movw -0x1e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1e(%rbp)
movswl -0x1e(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
sarl $0x3, %ecx
addl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x24(%rbp)
movswl -0xa(%rbp), %ecx
andl $0x7, %ecx
movl $0x7, %eax
subl %ecx, %eax
movb %al, -0x1f(%rbp)
jmp 0x664c0
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
sarl $0x2, %eax
movw %ax, -0x1e(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
andl $0x3, %eax
cmpl $0x0, %eax
je 0x663dc
movw -0x1e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1e(%rbp)
movswl -0x1e(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
sarl $0x2, %ecx
addl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x24(%rbp)
movswl -0xa(%rbp), %ecx
andl $0x3, %ecx
shll %ecx
movl $0x6, %eax
subl %ecx, %eax
movb %al, -0x1f(%rbp)
jmp 0x664c0
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
sarl %eax
movw %ax, -0x1e(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6644f
movw -0x1e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1e(%rbp)
movswl -0x1e(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
sarl %ecx
addl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x24(%rbp)
movswl -0xa(%rbp), %ecx
andl $0x1, %ecx
shll $0x2, %ecx
movl $0x4, %eax
subl %ecx, %eax
movb %al, -0x1f(%rbp)
jmp 0x664c0
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movw %ax, -0x1e(%rbp)
movswl -0x1e(%rbp), %eax
movswl -0xc(%rbp), %ecx
imull %ecx, %eax
movswl -0xa(%rbp), %ecx
addl %ecx, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x400, %eax            # imm = 0x400
movl %eax, -0x24(%rbp)
movb $0x0, -0x1f(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x178(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x6650d
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x178(%rbp)
jmp 0x66548
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movl -0x24(%rbp), %esi
addl $0x4, %esi
callq 0x438e0
movq -0x30(%rbp), %rax
movq (%rax), %rdi
leaq -0x170(%rbp), %rsi
movswl -0x1e(%rbp), %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x437a0
leaq -0x170(%rbp), %rax
movq %rax, -0x178(%rbp)
movw $0x0, -0x184(%rbp)
movswl -0x184(%rbp), %eax
movswl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jge 0x66667
movq -0x178(%rbp), %rax
movzbl (%rax), %eax
movzwl -0x1c(%rbp), %edx
movsbl -0x1f(%rbp), %ecx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movsbl -0x1f(%rbp), %ecx
sarl %cl, %eax
movb %al, -0x181(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movzbl -0x181(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x186(%rbp)
movzwl -0x186(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movswl -0x184(%rbp), %ecx
imull $0x3, %ecx, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl -0x186(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movswl -0x184(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movzbl -0x181(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movswl -0x184(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x3, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzbl -0x19(%rbp), %ecx
movsbl -0x1f(%rbp), %eax
subl %ecx, %eax
movb %al, -0x1f(%rbp)
movsbl -0x1f(%rbp), %eax
cmpl $0x0, %eax
jge 0x6664e
movzbl -0x19(%rbp), %ecx
movl $0x8, %eax
subl %ecx, %eax
movb %al, -0x1f(%rbp)
movq -0x178(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x178(%rbp)
jmp 0x66650
movw -0x184(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x184(%rbp)
jmp 0x66551
movb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)