// File: /workspace/github_c_makefile_star2_O3/algorithm-archivists[P]GathVL/src/objects/image.cpp
// Function: image::draw(_cairo*) const
void image::draw(cairo_t *ctx) const {
    if (image_data) {
        int stride = 0;
        unsigned char *data = nullptr;
        cairo_surface_t *surface;

        if (size.x <= 0 || size.y <= 0 ||
            (size.x == width && size.y == height)) {

            stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
            data = new unsigned char[stride * height];

            if (!data) {
                std::cout << "Malloc for data failed in image." << std::endl;
                return;
            }

            format_converter(image_data, data, width, height);

            surface =
                cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
                                                    width, height, stride);
        } else {
            stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
                                                   (int)size.x);

            data = new unsigned char[stride * (int)size.y];

            if (!data) {
                std::cout << "Malloc for data failed in image." << std::endl;
                return;
            }

            unsigned char *tmp = new unsigned char[(int)(size.x * size.y * 4)];

            if (!tmp) {
                std::cout << "Malloc failed in image." << std::endl;
                delete[] data;
                return;
            }

            stbir_resize_uint8(image_data, width, height, 0,
                               tmp, size.x, size.y, 0, 4);

            format_converter(tmp, data, (int)size.x, (int)size.y);

            surface =
                cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
                                                    (int)size.x, (int)size.y,
                                                    stride);

            delete[] tmp;
        }

        cairo_save(ctx);
        cairo_translate(ctx, location.x, location.y);
        cairo_rotate(ctx, rotation);

        cairo_set_source_surface(ctx, surface, 0, 0);

        if (size.x <= 0 || size.y <= 0 ||
            (size.x == width && size.y == height)) {
            cairo_rectangle(ctx, 0, 0, width, height);
        } else {
            cairo_rectangle(ctx, 0, 0, size.x, size.y);
        }

        cairo_clip(ctx);
        cairo_paint(ctx);

        cairo_restore(ctx);

        cairo_surface_destroy(surface);
        delete[] data;
    }
}

// Assembly:
cmpq $0x0, 0x48(%rdi)
je 0xcc40
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x30(%rdi), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
jae 0xcade
movsd 0x38(%r14), %xmm1
ucomisd %xmm1, %xmm2
jae 0xcade
xorps %xmm2, %xmm2
cvtsi2sdl 0x50(%r14), %xmm2
ucomisd %xmm2, %xmm0
jne 0xcc41
jp 0xcc41
xorps %xmm2, %xmm2
cvtsi2sdl 0x54(%r14), %xmm2
ucomisd %xmm2, %xmm1
jne 0xcc41
jp 0xcc41
movl 0x50(%r14), %esi
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x5440
movl %eax, %ebp
movl 0x54(%r14), %r12d
imull %r12d, %eax
movslq %eax, %rdi
callq 0x5390
movq %rax, %r15
movslq 0x50(%r14), %rdx
testl %r12d, %r12d
jle 0xcb5c
movq 0x48(%r14), %rax
leaq (,%rdx,4), %rcx
movq %r15, %rsi
testl %edx, %edx
jle 0xcb4e
xorl %edi, %edi
movb (%rax,%rdi), %r8b
movb %r8b, 0x2(%rsi,%rdi)
movb 0x1(%rax,%rdi), %r8b
movb %r8b, 0x1(%rsi,%rdi)
movb 0x2(%rax,%rdi), %r8b
movb %r8b, (%rsi,%rdi)
movb 0x3(%rax,%rdi), %r8b
movb %r8b, 0x3(%rsi,%rdi)
addq $0x4, %rdi
cmpq %rcx, %rdi
jl 0xcb1f
addq %rcx, %rsi
addq %rcx, %rax
incl %r13d
cmpl %r12d, %r13d
jne 0xcb19
movq %r15, %rdi
xorl %esi, %esi
movl %r12d, %ecx
movl %ebp, %r8d
callq 0x5530
movq %rax, %r13
movq %rbx, %rdi
callq 0x54b0
movsd 0x20(%r14), %xmm0
movsd 0x28(%r14), %xmm1
movq %rbx, %rdi
callq 0x5180
movsd 0x40(%r14), %xmm0
movq %rbx, %rdi
callq 0x5480
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5820
xorpd %xmm0, %xmm0
movsd 0x30(%r14), %xmm2
ucomisd %xmm2, %xmm0
jae 0xcbe9
movsd 0x38(%r14), %xmm3
ucomisd %xmm3, %xmm0
jae 0xcbe9
xorps %xmm0, %xmm0
cvtsi2sdl 0x50(%r14), %xmm0
ucomisd %xmm0, %xmm2
jne 0xcbfb
jp 0xcbfb
xorps %xmm0, %xmm0
cvtsi2sdl 0x54(%r14), %xmm0
ucomisd %xmm0, %xmm3
jne 0xcbfb
jp 0xcbfb
xorps %xmm2, %xmm2
cvtsi2sdl 0x50(%r14), %xmm2
xorps %xmm3, %xmm3
cvtsi2sdl 0x54(%r14), %xmm3
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %rbx, %rdi
callq 0x5360
movq %rbx, %rdi
callq 0x5610
movq %rbx, %rdi
callq 0x51a0
movq %rbx, %rdi
callq 0x5600
movq %r13, %rdi
callq 0x5888
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5290
retq
cvttsd2si %xmm0, %esi
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x5440
movsd 0x38(%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
cvttsd2si %xmm0, %ebp
movl %eax, 0x4(%rsp)
imull %ebp, %eax
movslq %eax, %rdi
callq 0x5390
movsd 0x30(%r14), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x17774(%rip), %xmm0    # 0x24400
movq %rax, %r15
cvttsd2si %xmm0, %eax
movslq %eax, %rdi
callq 0x5390
movq %rax, %r12
movq 0x48(%r14), %rdi
movl 0x50(%r14), %esi
movl 0x54(%r14), %edx
cvttsd2si 0x10(%rsp), %r9d
movl $0x1, %eax
movss 0x1673e(%rip), %xmm2    # 0x233fc
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq %r12, %r8
movapd %xmm2, %xmm3
pushq %r13
pushq %rax
pushq %rax
pushq %r13
pushq %r13
pushq %r13
pushq %r13
pushq $-0x1
pushq $0x4
pushq $0x0
pushq %r13
pushq %rbp
callq 0xb3f0
addq $0x60, %rsp
cvttsd2si 0x30(%r14), %edx
cvttsd2si 0x38(%r14), %ecx
testl %ecx, %ecx
jle 0xcd47
leal (,%rdx,4), %eax
cltq
xorpd %xmm0, %xmm0
movq %r12, %rsi
movq %r15, %rdi
testl %edx, %edx
jle 0xcd39
xorl %r8d, %r8d
movd (%rsi,%r8), %xmm1
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
pshuflw $0xc6, %xmm1, %xmm1     # xmm1 = xmm1[2,1,0,3,4,5,6,7]
packuswb %xmm1, %xmm1
movd %xmm1, (%rdi,%r8)
addq $0x4, %r8
cmpq %rax, %r8
jl 0xcd17
addq %rax, %rdi
addq %rax, %rsi
incl %r13d
cmpl %ecx, %r13d
jne 0xcd10
movq %r15, %rdi
xorl %esi, %esi
movl 0x4(%rsp), %r8d
callq 0x5530
movq %rax, %r13
movq %r12, %rdi
callq 0x5290
jmp 0xcb6f