// File: /workspace/github_c_makefile_star2_O2/algorithm-archivists[P]GathVL/src/objects/tex_string.cpp
// Function: tex_string::draw(_cairo*) const
void tex_string::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 failed in tex_string." << 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 tex_string."
                    << std::endl;
                return;
            }

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

            if (!tmp) {
                std::cout << "Malloc failed in tex_string." << 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_rgba(ctx, clr.r, clr.g, clr.b, clr.a);
        cairo_mask_surface(ctx, surface, 0, 0);
        cairo_fill(ctx);

        cairo_restore(ctx);

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

// Assembly:
cmpq $0x0, 0x88(%rdi)
je 0x1864b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x50(%rdi), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
jae 0x18563
movsd 0x58(%r14), %xmm1
ucomisd %xmm1, %xmm2
jae 0x18563
cvtsi2sdl 0x90(%r14), %xmm2
ucomisd %xmm2, %xmm0
jne 0x1864c
jp 0x1864c
cvtsi2sdl 0x94(%r14), %xmm2
ucomisd %xmm2, %xmm1
jne 0x1864c
jp 0x1864c
movl 0x90(%r14), %esi
xorl %edi, %edi
callq 0x5450
movl %eax, %ebp
movl 0x94(%r14), %r12d
movl %r12d, %eax
imull %ebp, %eax
movslq %eax, %rdi
callq 0x53b0
movq %rax, %r15
movq 0x88(%r14), %rdi
movl 0x90(%r14), %edx
movq %rax, %rsi
movl %r12d, %ecx
callq 0x1871a
movl 0x90(%r14), %edx
movl 0x94(%r14), %ecx
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %r8d
callq 0x5530
movq %rax, %r12
movq %rbx, %rdi
callq 0x54c0
movsd 0x40(%r14), %xmm0
movsd 0x48(%r14), %xmm1
movq %rbx, %rdi
callq 0x5180
movsd 0x60(%r14), %xmm0
movq %rbx, %rdi
callq 0x5490
movsd 0x20(%r14), %xmm0
movsd 0x28(%r14), %xmm1
movsd 0x30(%r14), %xmm2
movsd 0x38(%r14), %xmm3
movq %rbx, %rdi
callq 0x5340
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5870
movq %rbx, %rdi
callq 0x5690
movq %rbx, %rdi
callq 0x5610
movq %r12, %rdi
callq 0x5888
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x52a0
retq
cvttsd2si %xmm0, %esi
xorl %edi, %edi
callq 0x5450
movsd 0x58(%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
cvttsd2si %xmm0, %r12d
movl %eax, %ebp
imull %r12d, %eax
movslq %eax, %rdi
callq 0x53b0
movsd 0x50(%r14), %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x3bfc(%rip), %xmm0     # 0x1c290
movq %rax, %r15
cvttsd2si %xmm0, %eax
movslq %eax, %rdi
callq 0x53b0
movq %rax, %r13
movq 0x88(%r14), %rdi
movl 0x90(%r14), %esi
movl 0x94(%r14), %edx
cvttsd2si 0x10(%rsp), %r9d
subq $0x8, %rsp
xorl %ecx, %ecx
movq %rax, %r8
pushq $0x4
pushq $0x0
pushq %r12
callq 0xb144
addq $0x20, %rsp
cvttsd2si 0x50(%r14), %edx
cvttsd2si 0x58(%r14), %ecx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1871a
cvttsd2si 0x50(%r14), %edx
cvttsd2si 0x58(%r14), %ecx
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %r8d
callq 0x5530
movq %rax, %r12
movq %r13, %rdi
callq 0x52a0
jmp 0x185c2