// File: /workspace/github_c_makefile_star2_O3/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 0x80e4
testb %al, %al
je 0x240cc
movq %r15, %rdi
callq 0x3c88e
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6af7
movq %rax, %r14
cmpb $0x3, %bpl
jne 0x240dd
movb 0x10(%r14), %al
movl %eax, %ecx
andb $0x3, %cl
decb %cl
cmpb $0x1, %cl
ja 0x240ba
movq (%r14), %rdi
callq 0x2a006
movb 0x10(%r14), %al
movq $0x0, (%r14)
orb $0x3, %al
movb %al, 0x10(%r14)
jmp 0x24232
leaq 0x1b111(%rip), %rdi     # 0x3f1e4
movq %rbx, %rsi
callq 0x8294
jmp 0x240db
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3e49e
testb %bpl, %bpl
je 0x241c1
cmpb $0x2, %bpl
ja 0x241d8
movq (%r14), %rax
cmpq %r15, %rax
je 0x24160
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 0x29f85
movq %rax, %r13
movq %rax, %rdi
callq 0x80e4
testb %al, %al
je 0x24241
testq %r13, %r13
je 0x24232
movq %r13, %rdi
movq %r15, %rsi
callq 0x2040
movq %r13, (%r14)
testq %r12, %r12
je 0x24160
movq %r12, %rdi
callq 0x2a006
cmpb $0x2, %bpl
jne 0x241d8
movq %rbx, %rdi
callq 0x66b6
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 0x2acd4
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 0x241d8
movb 0x10(%r14), %al
andb $0x3, %al
decb %al
cmpb $0x1, %al
ja 0x241d5
movq (%r14), %rdi
callq 0x2a006
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 0x24252
testb %al, %al
je 0x2422a
movswl 0xc(%r14), %esi
movswl 0xe(%r14), %edx
movq %rbx, %rdi
callq 0x5557
movq %rbx, %rdi
callq 0x4c4d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ae88(%rip), %rdi     # 0x3f0d0
movq %r13, %rsi
callq 0x8294
jmp 0x24250