// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_img.c
// Function: lv_img_set_src
void lv_img_set_src(lv_obj_t * img, const void * src_img)
{
    LV_ASSERT_OBJ(img, LV_OBJX_NAME);

    lv_img_src_t src_type = lv_img_src_get_type(src_img);
    lv_img_ext_t * ext    = lv_obj_get_ext_attr(img);

#if LV_USE_LOG && LV_LOG_LEVEL >= LV_LOG_LEVEL_INFO
    switch(src_type) {
        case LV_IMG_SRC_FILE: LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_FILE` type found"); break;
        case LV_IMG_SRC_VARIABLE: LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found"); break;
        case LV_IMG_SRC_SYMBOL: LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_SYMBOL` type found"); break;
        default: LV_LOG_WARN("lv_img_set_src: unknown type");
    }
#endif

    /*If the new source type is unknown free the memories of the old source*/
    if(src_type == LV_IMG_SRC_UNKNOWN) {
        LV_LOG_WARN("lv_img_set_src: unknown image type");
        if(ext->src_type == LV_IMG_SRC_SYMBOL || ext->src_type == LV_IMG_SRC_FILE) {
            lv_mem_free(ext->src);
        }
        ext->src      = NULL;
        ext->src_type = LV_IMG_SRC_UNKNOWN;
        return;
    }

    lv_img_header_t header;
    lv_img_decoder_get_info(src_img, &header);

    /*Save the source*/
    if(src_type == LV_IMG_SRC_VARIABLE) {
        LV_LOG_INFO("lv_img_set_src:  `LV_IMG_SRC_VARIABLE` type found");

        /*If memory was allocated because of the previous `src_type` then free it*/
        if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) {
            lv_mem_free(ext->src);
        }
        ext->src = src_img;
    } else if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_SYMBOL) {
        /* If the new and the old src are the same then it was only a refresh.*/
        if(ext->src != src_img) {
            const void * old_src = NULL;
            /* If memory was allocated because of the previous `src_type` then save its pointer and free after allocation.
             * It's important to allocate first to be sure the new data will be on a new address.
             * Else `img_cache` wouldn't see the change in source.*/
            if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) {
                old_src = ext->src;
            }
            char * new_str = lv_mem_alloc(strlen(src_img) + 1);
            LV_ASSERT_MEM(new_str);
            if(new_str == NULL) return;
            strcpy(new_str, src_img);
            ext->src = new_str;

            if(old_src) lv_mem_free(old_src);
        }
    }

    if(src_type == LV_IMG_SRC_SYMBOL) {
        /*`lv_img_dsc_get_info` couldn't set the with and height of a font so set it here*/
        const lv_style_t * style = lv_img_get_style(img, LV_IMG_STYLE_MAIN);
        lv_point_t size;
        lv_txt_get_size(&size, src_img, style->text.font, style->text.letter_space, style->text.line_space,
                        LV_COORD_MAX, LV_TXT_FLAG_NONE);
        header.w = size.x;
        header.h = size.y;
    }

    ext->src_type = src_type;
    ext->w        = header.w;
    ext->h        = header.h;
    ext->cf       = header.cf;

    if(lv_img_get_auto_size(img) != false) {
        lv_obj_set_size(img, ext->w, ext->h);
    }

    lv_obj_invalidate(img);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x7994
testb %al, %al
je 0x21e7c
movq %r15, %rdi
callq 0x389cd
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6747
movq %rax, %r14
cmpb $0x3, %bpl
jne 0x21e8d
movb 0x10(%r14), %al
movl %eax, %ecx
andb $0x3, %cl
decb %cl
cmpb $0x1, %cl
ja 0x21e6d
movq (%r14), %rdi
callq 0x27a7a
movb 0x10(%r14), %al
andq $0x0, (%r14)
orb $0x3, %al
movb %al, 0x10(%r14)
jmp 0x21fdf
leaq 0x192c1(%rip), %rdi     # 0x3b144
movq %rbx, %rsi
callq 0x7b01
jmp 0x21e8b
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3a521
testb %bpl, %bpl
je 0x21f6e
cmpb $0x2, %bpl
ja 0x21f85
movq (%r14), %rax
cmpq %r15, %rax
je 0x21f10
movb 0x10(%r14), %cl
andb $0x3, %cl
decb %cl
xorl %r12d, %r12d
cmpb $0x2, %cl
cmovbq %rax, %r12
movq %r15, %rdi
callq 0x2070
leaq 0x1(%rax), %rdi
callq 0x279f9
movq %rax, %r13
movq %rax, %rdi
callq 0x7994
testb %al, %al
je 0x21fee
testq %r13, %r13
je 0x21fdf
movq %r13, %rdi
movq %r15, %rsi
callq 0x2040
movq %r13, (%r14)
testq %r12, %r12
je 0x21f10
movq %r12, %rdi
callq 0x27a7a
cmpb $0x2, %bpl
jne 0x21f85
movq %rbx, %rdi
callq 0x6316
movq 0x28(%rax), %rdx
movswl 0x30(%rax), %ecx
movswl 0x32(%rax), %r8d
andl $0x0, (%rsp)
leaq 0x14(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl $0x7c18, %r9d           # imm = 0x7C18
callq 0x28723
movzwl (%r12), %eax
shll $0xa, %eax
movl $0x3ff, %ecx            # imm = 0x3FF
andl 0x10(%rsp), %ecx
movzwl 0x2(%r12), %edx
shll $0x15, %edx
andl $0x1ffc00, %eax         # imm = 0x1FFC00
orl %ecx, %eax
orl %edx, %eax
movl %eax, 0x10(%rsp)
jmp 0x21f85
movb 0x10(%r14), %al
andb $0x3, %al
decb %al
cmpb $0x1, %al
ja 0x21f82
movq (%r14), %rdi
callq 0x27a7a
movq %r15, (%r14)
movb 0x10(%r14), %al
andb $0x3, %bpl
andb $0x4, %al
orb %bpl, %al
movl 0x10(%rsp), %ecx
movl %ecx, %edx
shrl $0xa, %edx
andl $0x7ff, %edx            # imm = 0x7FF
movw %dx, 0xc(%r14)
movl %ecx, %edx
shrl $0x15, %edx
movw %dx, 0xe(%r14)
shlb $0x3, %cl
orb %al, %cl
movb %cl, 0x10(%r14)
movq %rbx, %rdi
callq 0x21fff
testb %al, %al
je 0x21fd7
movswl 0xc(%r14), %esi
movswl 0xe(%r14), %edx
movq %rbx, %rdi
callq 0x520e
movq %rbx, %rdi
callq 0x493a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1904b(%rip), %rdi     # 0x3b040
movq %r13, %rsi
callq 0x7b01
jmp 0x21ffd