// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x3a2ef
movq -0x8(%rbp), %rsi
leaq 0x2de14(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x3a2ed
movq -0x10(%rbp), %rdi
callq 0x63110
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rdi
callq 0xa8f0
movq %rax, -0x20(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x3, %eax
jne 0x3a35f
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x2, %eax
je 0x3a333
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x3a33f
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x44ec0
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movb 0x10(%rax), %cl
andb $-0x4, %cl
orb $0x3, %cl
movb %cl, 0x10(%rax)
jmp 0x3a597
movq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x659e0
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0x3a3b3
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x3a397
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x3a3a3
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x44ec0
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x3a481
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
je 0x3a3c9
movzbl -0x11(%rbp), %eax
cmpl $0x2, %eax
jne 0x3a47f
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x3a47d
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x3a404
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x3a40f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2060
movq %rax, %rdi
addq $0x1, %rdi
callq 0x44d20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x3a447
movq -0x38(%rbp), %rsi
leaq 0x2dc04(%rip), %rdi     # 0x68044
callq 0xd410
jmp 0x3a445
cmpq $0x0, -0x38(%rbp)
jne 0x3a453
jmp 0x3a597
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2040
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x3a47b
movq -0x30(%rbp), %rdi
callq 0x44ec0
jmp 0x3a47d
jmp 0x3a47f
jmp 0x3a481
movzbl -0x11(%rbp), %eax
cmpl $0x2, %eax
jne 0x3a506
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x3a5a0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x40(%rbp), %rax
movw 0x30(%rax), %cx
movq -0x40(%rbp), %rax
leaq -0x44(%rbp), %rdi
movl $0x7c18, %r9d           # imm = 0x7C18
xorl %r8d, %r8d
movswl %cx, %ecx
movswl 0x32(%rax), %r8d
movl $0x0, (%rsp)
callq 0x46820
movswl -0x44(%rbp), %ecx
movl -0x24(%rbp), %eax
andl $0x7ff, %ecx            # imm = 0x7FF
shll $0xa, %ecx
andl $0xffe003ff, %eax       # imm = 0xFFE003FF
orl %ecx, %eax
movl %eax, -0x24(%rbp)
movswl -0x42(%rbp), %ecx
movl -0x24(%rbp), %eax
andl $0x7ff, %ecx            # imm = 0x7FF
shll $0x15, %ecx
andl $0x1fffff, %eax         # imm = 0x1FFFFF
orl %ecx, %eax
movl %eax, -0x24(%rbp)
movb -0x11(%rbp), %dl
movq -0x20(%rbp), %rax
movb 0x10(%rax), %cl
andb $0x3, %dl
andb $-0x4, %cl
orb %dl, %cl
movb %cl, 0x10(%rax)
movl -0x24(%rbp), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0xc(%rax)
movl -0x24(%rbp), %eax
shrl $0x15, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0xe(%rax)
movl -0x24(%rbp), %eax
andl $0x1f, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movb 0x10(%rax), %cl
andb $0x1f, %dl
shlb $0x3, %dl
andb $0x7, %cl
orb %dl, %cl
movb %cl, 0x10(%rax)
movq -0x8(%rbp), %rdi
callq 0x3a5d0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x3a58e
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movw 0xc(%rax), %cx
movq -0x20(%rbp), %rax
movswl %cx, %esi
movswl 0xe(%rax), %edx
callq 0x8180
movq -0x8(%rbp), %rdi
callq 0x7430
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)