// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/graphics/backends/cairo/surfacecairo.cpp
// Function: smooth::GUI::SurfaceCairo::BlitToBitmap(smooth::GUI::Rect const&, smooth::GUI::Bitmap&, smooth::GUI::Rect const&)
S::Int S::GUI::SurfaceCairo::BlitToBitmap(const Rect &iSrcRect, Bitmap &bitmap, const Rect &destRect)
{
	if (window == NIL) return Success();
	if (bitmap == NIL) return Error();

	Rect	 srcRect = rightToLeft.TranslateRect(iSrcRect);

	if (srcRect.GetWidth()  == 0 || srcRect.GetHeight()  == 0 ||
	    destRect.GetWidth() == 0 || destRect.GetHeight() == 0) return Success();

	/* Copy the image.
	 */
	cairo_surface_t	*bitmapSurface = cairo_image_surface_create_for_data(bitmap.GetBytes(), CAIRO_FORMAT_RGB24, bitmap.GetSize().cx, bitmap.GetSize().cy, bitmap.GetSize().cx * 4);
	cairo_t		*bitmapContext = cairo_create(bitmapSurface);

	cairo_rectangle(bitmapContext, destRect.left, destRect.top, destRect.GetWidth(), destRect.GetHeight());
	cairo_clip(bitmapContext);
	cairo_translate(bitmapContext, destRect.left, destRect.top);
	cairo_scale(bitmapContext, (float) destRect.GetWidth() / srcRect.GetWidth(), (float) destRect.GetHeight() / srcRect.GetHeight());
	cairo_set_source_surface(bitmapContext, surface, -srcRect.left, -srcRect.top);
	cairo_paint(bitmapContext);

	cairo_destroy(bitmapContext);
	cairo_surface_destroy(bitmapSurface);

	return Success();
}

// Assembly:
cmpq $0x0, 0x50(%rdi)
je 0xc6233
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
movq %rdx, %rdi
xorl %esi, %esi
callq 0x57e30
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
jne 0xc6224
leaq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0x632ca
movq %rax, %r15
movq %rdx, %r12
movl %r12d, %ebp
subl %r15d, %ebp
je 0xc6222
shrq $0x20, %r12
movq %r15, %rcx
shrq $0x20, %rcx
cmpq %rcx, %r12
je 0xc6222
movl 0x8(%r14), %eax
cmpl (%r14), %eax
je 0xc6222
movl 0xc(%r14), %eax
cmpl 0x4(%r14), %eax
je 0xc6222
subl %ecx, %r12d
movq %r13, %rdi
movq %rcx, 0x10(%rsp)
callq 0x57100
movq %rax, (%rsp)
movq %r13, %rdi
callq 0x58410
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq %r13, %rdi
callq 0x58410
movl 0x4(%rax), %eax
movl %eax, 0x8(%rsp)
movq %r13, %rdi
callq 0x58410
movl (%rax), %r8d
shll $0x2, %r8d
movq (%rsp), %rdi
movl $0x1, %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
callq 0x57170
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x58060
movq %rax, %r13
movl (%r14), %eax
movl 0x4(%r14), %ecx
cvtsi2sd %eax, %xmm0
cvtsi2sd %ecx, %xmm1
movl 0x8(%r14), %edx
subl %eax, %edx
cvtsi2sd %edx, %xmm2
movl 0xc(%r14), %eax
subl %ecx, %eax
cvtsi2sd %eax, %xmm3
movq %r13, %rdi
callq 0x565a0
movq %r13, %rdi
callq 0x57b50
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x4(%r14), %xmm1
movq %r13, %rdi
callq 0x559f0
movl 0x8(%r14), %eax
subl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
movl 0xc(%r14), %eax
subl 0x4(%r14), %eax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
xorps %xmm3, %xmm3
cvtsi2ss %r12d, %xmm3
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
divss %xmm3, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
movq %r13, %rdi
callq 0x57f30
negl %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movq 0xb8(%rbx), %rsi
movq 0x10(%rsp), %rax
negl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movq %r13, %rdi
callq 0x58be0
movq %r13, %rdi
callq 0x55a90
movq %r13, %rdi
callq 0x58b80
movq (%rsp), %rdi
callq 0x57630
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq