// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpq $0x0, 0x50(%rdi)
je 0xbfc69
movq %rcx, %r15
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %r14
xorl %ebx, %ebx
movq %rdx, %rdi
xorl %esi, %esi
callq 0x590c0
testb %al, %al
je 0xbfc70
pushq $-0x1
popq %rbx
jmp 0xbfde3
xorl %ebx, %ebx
jmp 0xbfde3
leaq 0x28(%r14), %rdi
movq %r12, %rsi
callq 0x63e10
movq %rdx, %r13
movl %r13d, %r12d
subl %eax, %r12d
je 0xbfde3
shrq $0x20, %r13
movq %rax, %rdx
shrq $0x20, %rdx
cmpq %rdx, %r13
je 0xbfde3
movl 0x8(%r15), %ecx
cmpl (%r15), %ecx
je 0xbfde3
movl 0xc(%r15), %ecx
cmpl 0x4(%r15), %ecx
je 0xbfde3
subl %edx, %r13d
movq %rbp, %rdi
movq %rax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
callq 0x582e0
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
callq 0x596e0
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movq %rbp, %rdi
callq 0x596e0
movl 0x4(%rax), %eax
movl %eax, 0x10(%rsp)
movq %rbp, %rdi
callq 0x596e0
movl (%rax), %r8d
shll $0x2, %r8d
pushq $0x1
popq %rsi
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
callq 0x58360
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x592f0
movq %rax, %rbp
movl (%r15), %eax
movl 0x4(%r15), %ecx
cvtsi2sd %eax, %xmm0
cvtsi2sd %ecx, %xmm1
movl 0x8(%r15), %edx
subl %eax, %edx
cvtsi2sd %edx, %xmm2
movl 0xc(%r15), %eax
subl %ecx, %eax
cvtsi2sd %eax, %xmm3
movq %rbp, %rdi
callq 0x576b0
movq %rbp, %rdi
callq 0x58dc0
cvtsi2sdl (%r15), %xmm0
cvtsi2sdl 0x4(%r15), %xmm1
movq %rbp, %rdi
callq 0x56a60
movl 0x8(%r15), %eax
subl (%r15), %eax
cvtsi2ss %eax, %xmm0
cvtsi2ss %r12d, %xmm1
movl 0xc(%r15), %eax
subl 0x4(%r15), %eax
cvtsi2ss %eax, %xmm2
cvtsi2ss %r13d, %xmm3
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
divss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm1
movq %rbp, %rdi
callq 0x591c0
movq 0x18(%rsp), %rax
negl %eax
cvtsi2sd %eax, %xmm0
movq 0xb8(%r14), %rsi
movq 0x20(%rsp), %rax
negl %eax
cvtsi2sd %eax, %xmm1
movq %rbp, %rdi
callq 0x59f30
movq %rbp, %rdi
callq 0x56b10
movq %rbp, %rdi
callq 0x59ec0
movq 0x8(%rsp), %rdi
callq 0x58850
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq