// File: /workspace/github_c_makefile_star2_O1/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 0x80d4
testb %al, %al
je 0x23973
movq %r15, %rdi
callq 0x3c49f
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6ad8
movq %rax, %r14
cmpb $0x3, %bpl
jne 0x23984
movb 0x10(%r14), %al
andb $0x3, %al
decb %al
cmpb $0x1, %al
ja 0x23962
movq (%r14), %rdi
callq 0x29984
movq $0x0, (%r14)
orb $0x3, 0x10(%r14)
jmp 0x23ad7
leaq 0x1b7ba(%rip), %rdi     # 0x3f134
movq %rbx, %rsi
callq 0x829e
jmp 0x23982
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3e0f7
testb %bpl, %bpl
je 0x23a01
cmpb $0x2, %bpl
ja 0x23a18
movq (%r14), %rax
cmpq %r15, %rax
je 0x23a18
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 0x298d9
movq %rax, %r13
movq %rax, %rdi
callq 0x80d4
testb %al, %al
je 0x23ae6
testq %r13, %r13
je 0x23ad7
movq %r13, %rdi
movq %r15, %rsi
callq 0x2040
movq %r13, (%r14)
testq %r12, %r12
je 0x23a18
movq %r12, %rdi
callq 0x29984
jmp 0x23a18
movb 0x10(%r14), %al
andb $0x3, %al
decb %al
cmpb $0x1, %al
ja 0x23a15
movq (%r14), %rdi
callq 0x29984
movq %r15, (%r14)
cmpb $0x2, %bpl
jne 0x23a77
movq %rbx, %rdi
callq 0x6697
movq 0x28(%rax), %rdx
movswl 0x30(%rax), %ecx
movswl 0x32(%rax), %r8d
movl $0x0, (%rsp)
leaq 0x14(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl $0x7c18, %r9d           # imm = 0x7C18
callq 0x2a643
movzwl (%r12), %eax
andl $0x7ff, %eax            # imm = 0x7FF
shll $0xa, %eax
movl $0x3ff, %ecx            # imm = 0x3FF
andl 0x10(%rsp), %ecx
orl %eax, %ecx
movzwl 0x2(%r12), %eax
shll $0x15, %eax
orl %ecx, %eax
movl %eax, 0x10(%rsp)
movb 0x10(%r14), %al
andb $0x3, %bpl
andb $-0x4, %al
orb %bpl, %al
movb %al, 0x10(%r14)
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
andb $0x7, %al
orb %cl, %al
movb %al, 0x10(%r14)
movq %rbx, %rdi
callq 0x23af7
testb %al, %al
je 0x23acf
movswl 0xc(%r14), %esi
movswl 0xe(%r14), %edx
movq %rbx, %rdi
callq 0x553f
movq %rbx, %rdi
callq 0x4c36
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b553(%rip), %rdi     # 0x3f040
movq %r13, %rsi
callq 0x829e
jmp 0x23af5