// File: /workspace/github_c_makefile_star2_O2/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 0xbfc02
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
xorl %ebp, %ebp
movq %rsi, %rdi
xorl %esi, %esi
callq 0x590c0
testb %al, %al
je 0xbf96b
pushq $-0x1
popq %rbp
jmp 0xbfc04
leaq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0x63e10
movq %rax, %r13
movl 0x8(%r14), %eax
cmpl (%r14), %eax
je 0xbfc04
movl 0xc(%r14), %eax
cmpl 0x4(%r14), %eax
je 0xbfc04
movq %rdx, %r15
movl %r15d, %eax
movl %r13d, 0x18(%rsp)
subl %r13d, %eax
movl %eax, 0xc(%rsp)
je 0xbfc04
shrq $0x20, %r15
shrq $0x20, %r13
cmpq %r13, %r15
je 0xbfc04
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x58350
movq %rbp, %rdi
callq 0x624ce
leaq 0x20(%rsp), %rdi
callq 0x596e0
movl (%rax), %r12d
movl 0x4(%rax), %eax
movl %eax, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x57da0
movl %eax, %ebp
leaq 0x20(%rsp), %rdi
callq 0x582e0
xorl %esi, %esi
cmpb $0x20, %bpl
setne %sil
leal (,%r12,4), %r8d
movq %rax, %rdi
movl %r12d, %edx
movl 0x10(%rsp), %ecx
callq 0x58360
movq %rax, %r12
subl %r13d, %r15d
cmpw $0x0, 0xa(%rbx)
cvtsi2sdl 0x18(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x10(%rsp)
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x28(%rsp)
jne 0xbfb24
movq %rbx, %rdi
callq 0xbdda4
movq 0xc0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
callq 0x576b0
movq 0xc0(%rbx), %rdi
callq 0x58dc0
movq 0xc0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x56a60
cvtsi2ssl 0xc(%rsp), %xmm0
movl 0x8(%r14), %eax
subl (%r14), %eax
cvtsi2ss %eax, %xmm1
cvtsi2ss %r15d, %xmm2
movl 0xc(%r14), %eax
subl 0x4(%r14), %eax
divss %xmm1, %xmm0
cvtsi2ss %eax, %xmm1
movq 0xc0(%rbx), %rdi
cvtss2sd %xmm0, %xmm0
divss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
callq 0x591c0
movq 0xc0(%rbx), %rdi
xorl %eax, %eax
xorl %ecx, %ecx
subl (%r14), %ecx
cvtsi2sd %ecx, %xmm0
subl 0x4(%r14), %eax
cvtsi2sd %eax, %xmm1
movq %r12, %rsi
callq 0x59f30
movq 0xc0(%rbx), %rdi
callq 0x56b10
movq %rbx, %rdi
callq 0xbddf8
movq 0xd0(%rbx), %rdi
callq 0x58000
movq 0xd0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
callq 0x576b0
movq 0xd0(%rbx), %rdi
callq 0x58dc0
movq 0xd0(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x56a60
cvtsi2ssl 0xc(%rsp), %xmm0
movl 0x8(%r14), %eax
subl (%r14), %eax
cvtsi2ss %eax, %xmm1
cvtsi2ss %r15d, %xmm2
movl 0xc(%r14), %eax
subl 0x4(%r14), %eax
divss %xmm1, %xmm0
cvtsi2ss %eax, %xmm1
movq 0xd0(%rbx), %rdi
cvtss2sd %xmm0, %xmm0
divss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
callq 0x591c0
movq 0xd0(%rbx), %rdi
xorl %eax, %eax
xorl %ecx, %ecx
subl (%r14), %ecx
cvtsi2sd %ecx, %xmm0
subl 0x4(%r14), %eax
cvtsi2sd %eax, %xmm1
movq %r12, %rsi
callq 0x59f30
movq 0xd0(%rbx), %rdi
callq 0x56b10
movq 0xd0(%rbx), %rdi
callq 0x58d10
movq %r12, %rdi
callq 0x58850
leaq 0x20(%rsp), %rdi
callq 0x5a4c8
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xbfc1b
jmp 0xbfc1b
jmp 0xbfc1b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5a4c8
movq %rbx, %rdi
callq 0x58260