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

	Rect	 destRect = rightToLeft.TranslateRect(iDestRect);

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

	/* Copy the image.
	 */
	Bitmap	 premultipliedBitmap = bitmap;

	PremultiplyAlpha(premultipliedBitmap);

	Size		 srcSize    = premultipliedBitmap.GetSize();
	cairo_format_t	 srcFormat  = premultipliedBitmap.GetDepth() == 32 ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24;
	cairo_surface_t	*srcSurface = cairo_image_surface_create_for_data(premultipliedBitmap.GetBytes(), srcFormat, srcSize.cx, srcSize.cy, srcSize.cx * 4);

	if (!painting)
	{
		CreateCairoContext();

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

		DestroyCairoContext();
	}

	cairo_save(paintContextCairo);

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

	cairo_restore(paintContextCairo);

	cairo_surface_destroy(srcSurface);

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpq $0x0, 0x50(%rdi)
je 0xc6f8d
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
xorl %esi, %esi
callq 0x57e30
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
jne 0xc6f8f
leaq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0x63296
movq %rax, %r13
movl 0x8(%r14), %eax
cmpl (%r14), %eax
je 0xc6f8d
movl 0xc(%r14), %eax
cmpl 0x4(%r14), %eax
je 0xc6f8d
movq %rdx, %r15
movl %r15d, %eax
subl %r13d, %eax
movl %eax, 0xc(%rsp)
je 0xc6f8d
movl %r13d, %ebp
shrq $0x20, %r15
shrq $0x20, %r13
movl $0x0, %eax
cmpq %r13, %r15
je 0xc6f8f
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x57160
leaq 0x20(%rsp), %rdi
callq 0x61742
leaq 0x20(%rsp), %rdi
callq 0x58410
movl (%rax), %r12d
movl 0x4(%rax), %eax
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x56c20
movb %al, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x57100
xorl %esi, %esi
cmpb $0x20, 0x10(%rsp)
setne %sil
leal (,%r12,4), %r8d
movq %rax, %rdi
movl %r12d, %edx
movl 0x18(%rsp), %ecx
callq 0x57170
movq %rax, %r12
subl %r13d, %r15d
cmpw $0x0, 0xa(%rbx)
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x28(%rsp)
jne 0xc6e9a
movq %rbx, %rdi
callq 0xc508a
movq 0xc0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
callq 0x565a0
movq 0xc0(%rbx), %rdi
callq 0x57b50
movq 0xc0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x559f0
xorps %xmm0, %xmm0
cvtsi2ssl 0xc(%rsp), %xmm0
movl 0x8(%r14), %eax
subl (%r14), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
xorps %xmm2, %xmm2
cvtsi2ss %r15d, %xmm2
movl 0xc(%r14), %eax
subl 0x4(%r14), %eax
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movq 0xc0(%rbx), %rdi
cvtss2sd %xmm0, %xmm0
divss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
callq 0x57f30
movq 0xc0(%rbx), %rdi
xorl %eax, %eax
xorl %ecx, %ecx
subl (%r14), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
subl 0x4(%r14), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movq %r12, %rsi
callq 0x58be0
movq 0xc0(%rbx), %rdi
callq 0x55a90
movq %rbx, %rdi
callq 0xc50e0
movq 0xd0(%rbx), %rdi
callq 0x56e50
movq 0xd0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
callq 0x565a0
movq 0xd0(%rbx), %rdi
callq 0x57b50
movq 0xd0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x559f0
xorps %xmm0, %xmm0
cvtsi2ssl 0xc(%rsp), %xmm0
movl 0x8(%r14), %eax
subl (%r14), %eax
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
xorps %xmm2, %xmm2
cvtsi2ss %r15d, %xmm2
movl 0xc(%r14), %eax
subl 0x4(%r14), %eax
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movq 0xd0(%rbx), %rdi
cvtss2sd %xmm0, %xmm0
divss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
callq 0x57f30
movq 0xd0(%rbx), %rdi
xorl %eax, %eax
xorl %ecx, %ecx
subl (%r14), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
subl 0x4(%r14), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movq %r12, %rsi
callq 0x58be0
movq 0xd0(%rbx), %rdi
callq 0x55a90
movq 0xd0(%rbx), %rdi
callq 0x57ab0
movq %r12, %rdi
callq 0x57630
leaq 0x20(%rsp), %rdi
callq 0x59148
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc6fa4
jmp 0xc6fa4
jmp 0xc6fa4
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x59148
movq %rbx, %rdi
callq 0x57090
nop