// 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_open
lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{
    /*Open the file if it's a file*/
    if(dsc->src_type == LV_IMG_SRC_FILE) {
#if LV_USE_FILESYSTEM

        /*Support only "*.bin" files*/
        if(strcmp(lv_fs_get_ext(dsc->src), "bin")) return LV_RES_INV;

        lv_fs_file_t f;
        lv_fs_res_t res = lv_fs_open(&f, dsc->src, LV_FS_MODE_RD);
        if(res != LV_FS_RES_OK) {
            LV_LOG_WARN("Built-in image decoder can't open the file");
            return LV_RES_INV;
        }

        /*If the file was open successfully save the file descriptor*/
        if(dsc->user_data == NULL) {
            dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t));
            if(dsc->user_data == NULL) {
                LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
                LV_ASSERT_MEM(dsc->user_data);
            }
            memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t));
        }

        lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
        user_data->f                               = lv_mem_alloc(sizeof(f));
        if(user_data->f == NULL) {
            LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
            LV_ASSERT_MEM(user_data->f);
        }

        memcpy(user_data->f, &f, sizeof(f));

#else
        LV_LOG_WARN("Image built-in decoder cannot read file because LV_USE_FILESYSTEM = 0");
        return LV_RES_INV;
#endif
    }

    lv_img_cf_t cf = dsc->header.cf;
    /*Process true color formats*/
    if(cf == LV_IMG_CF_TRUE_COLOR || cf == LV_IMG_CF_TRUE_COLOR_ALPHA || cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
        if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
            /* In case of uncompressed formats the image stored in the ROM/RAM.
             * So simply give its pointer*/
            dsc->img_data = ((lv_img_dsc_t *)dsc->src)->data;
            return LV_RES_OK;
        } else {
            /*If it's a file it need to be read line by line later*/
            dsc->img_data = NULL;
            return LV_RES_OK;
        }
    }
    /*Process indexed images. Build a palette*/
    else if(cf == LV_IMG_CF_INDEXED_1BIT || cf == LV_IMG_CF_INDEXED_2BIT || cf == LV_IMG_CF_INDEXED_4BIT ||
            cf == LV_IMG_CF_INDEXED_8BIT) {

#if LV_IMG_CF_INDEXED
        uint8_t px_size       = lv_img_color_format_get_px_size(cf);
        uint32_t palette_size = 1 << px_size;

        /*Allocate the palette*/
        if(dsc->user_data == NULL) {
            dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t));
            if(dsc->user_data == NULL) {
                LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
                LV_ASSERT_MEM(dsc->user_data);
            }
            memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t));
        }

        lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
        user_data->palette                         = lv_mem_alloc(palette_size * sizeof(lv_color_t));
        user_data->opa                             = lv_mem_alloc(palette_size * sizeof(lv_opa_t));
        if(user_data->palette == NULL || user_data->opa == NULL) {
            LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
#if LV_USE_FILESYSTEM
            LV_ASSERT_MEM(user_data->f);
#endif
        }

        if(dsc->src_type == LV_IMG_SRC_FILE) {
            /*Read the palette from file*/
#if LV_USE_FILESYSTEM
            lv_fs_seek(user_data->f, 4); /*Skip the header*/
            lv_color32_t cur_color;
            uint32_t i;
            for(i = 0; i < palette_size; i++) {
                lv_fs_read(user_data->f, &cur_color, sizeof(lv_color32_t), NULL);
                user_data->palette[i] = lv_color_make(cur_color.ch.red, cur_color.ch.green, cur_color.ch.blue);
                user_data->opa[i]     = cur_color.ch.alpha;
            }
#else
            LV_LOG_WARN("Image built-in decoder can read the palette because LV_USE_FILESYSTEM = 0");
            return LV_RES_INV;
#endif
        } else {
            /*The palette begins in the beginning of the image data. Just point to it.*/
            lv_color32_t * palette_p = (lv_color32_t *)((lv_img_dsc_t *)dsc->src)->data;

            uint32_t i;
            for(i = 0; i < palette_size; i++) {
                user_data->palette[i] = lv_color_make(palette_p[i].ch.red, palette_p[i].ch.green, palette_p[i].ch.blue);
                user_data->opa[i]     = palette_p[i].ch.alpha;
            }
        }

        dsc->img_data = NULL;
        return LV_RES_OK;
#else
        LV_LOG_WARN("Indexed (palette) images are not enabled in lv_conf.h. See LV_IMG_CF_INDEXED");
        return LV_RES_INV;
#endif
    }
    /*Alpha indexed images. */
    else if(cf == LV_IMG_CF_ALPHA_1BIT || cf == LV_IMG_CF_ALPHA_2BIT || cf == LV_IMG_CF_ALPHA_4BIT ||
            cf == LV_IMG_CF_ALPHA_8BIT) {
#if LV_IMG_CF_ALPHA
        dsc->img_data = NULL;
        return LV_RES_OK; /*Nothing to process*/
#else
        LV_LOG_WARN("Alpha indexed images are not enabled in lv_conf.h. See LV_IMG_CF_ALPHA");
        return LV_RES_INV;
#endif
    }
    /*Unknown format. Can't decode it.*/
    else {
        /*Free the potentially allocated memories*/
        lv_img_decoder_built_in_close(decoder, dsc);

        LV_LOG_WARN("Image decoder open: unknown color format")
        return LV_RES_INV;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x1, %eax
jne 0x65468
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x43f60
movq %rax, %rdi
leaq 0x6d57(%rip), %rsi      # 0x6c0b2
callq 0x20d0
cmpl $0x0, %eax
je 0x6536e
movb $0x0, -0x1(%rbp)
jmp 0x657a0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x28(%rbp), %rdi
movl $0x2, %edx
callq 0x43440
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
je 0x65399
movb $0x0, -0x1(%rbp)
jmp 0x657a0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x65401
movl $0x18, %edi
callq 0x44d20
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x653ed
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xd120
testb $0x1, %al
jne 0x653eb
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
leaq 0x2c60(%rip), %rdi      # 0x68044
callq 0xd410
jmp 0x653e9
jmp 0x653ed
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2090
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x10, %edi
callq 0x44d20
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x65452
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0xd120
testb $0x1, %al
jne 0x65450
movq -0x38(%rbp), %rax
movq (%rax), %rsi
leaq 0x2bfb(%rip), %rdi      # 0x68044
callq 0xd410
jmp 0x6544e
jmp 0x65452
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x1f, %eax
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x4, %eax
je 0x65490
movzbl -0x39(%rbp), %eax
cmpl $0x5, %eax
je 0x65490
movzbl -0x39(%rbp), %eax
cmpl $0x6, %eax
jne 0x654cf
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x654ba
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x657a0
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x657a0
movzbl -0x39(%rbp), %eax
cmpl $0x7, %eax
je 0x654f7
movzbl -0x39(%rbp), %eax
cmpl $0x8, %eax
je 0x654f7
movzbl -0x39(%rbp), %eax
cmpl $0x9, %eax
je 0x654f7
movzbl -0x39(%rbp), %eax
cmpl $0xa, %eax
jne 0x65759
movzbl -0x39(%rbp), %edi
callq 0x62530
movb %al, -0x3a(%rbp)
movzbl -0x3a(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x65579
movl $0x18, %edi
callq 0x44d20
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x65565
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xd120
testb $0x1, %al
jne 0x65563
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
leaq 0x2ae8(%rip), %rdi      # 0x68044
callq 0xd410
jmp 0x65561
jmp 0x65565
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2090
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x40(%rbp), %eax
movl %eax, %edi
shlq %rdi
callq 0x44d20
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x40(%rbp), %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x44d20
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x655cc
movq -0x48(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x655f3
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0xd120
testb $0x1, %al
jne 0x655f1
movq -0x48(%rbp), %rax
movq (%rax), %rsi
leaq 0x2a5a(%rip), %rdi      # 0x68044
callq 0xd410
jmp 0x655ef
jmp 0x655f3
movq -0x18(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x1, %eax
jne 0x6569d
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl $0x4, %esi
callq 0x438e0
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x65698
movq -0x48(%rbp), %rax
movq (%rax), %rdi
leaq -0x4c(%rbp), %rsi
movl $0x4, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x437a0
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x50(%rbp), %eax
movq %rax, -0x78(%rbp)
movb -0x4a(%rbp), %cl
movb -0x4b(%rbp), %al
movzbl %cl, %edi
movzbl %al, %esi
movzbl -0x4c(%rbp), %edx
callq 0x65d00
movq -0x78(%rbp), %rcx
movw %ax, %dx
movq -0x70(%rbp), %rax
movw %dx, -0x52(%rbp)
movw -0x52(%rbp), %dx
movw %dx, (%rax,%rcx,2)
movb -0x49(%rbp), %dl
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x6561c
jmp 0x65747
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x65745
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x64(%rbp), %eax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movb 0x2(%rax,%rcx,4), %sil
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movb 0x1(%rax,%rcx,4), %dl
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movzbl %sil, %edi
movzbl %dl, %esi
movzbl (%rax,%rcx,4), %edx
callq 0x65d00
movq -0x88(%rbp), %rcx
movw %ax, %dx
movq -0x80(%rbp), %rax
movw %dx, -0x66(%rbp)
movw -0x66(%rbp), %dx
movw %dx, (%rax,%rcx,2)
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movb 0x3(%rax,%rcx,4), %dl
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x656b4
jmp 0x65747
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x657a0
movzbl -0x39(%rbp), %eax
cmpl $0xb, %eax
je 0x6577d
movzbl -0x39(%rbp), %eax
cmpl $0xc, %eax
je 0x6577d
movzbl -0x39(%rbp), %eax
cmpl $0xd, %eax
je 0x6577d
movzbl -0x39(%rbp), %eax
cmpl $0xe, %eax
jne 0x6578f
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x657a0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x65960
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)