// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/graphics/backends/cairo/surfacecairo.cpp
// Function: smooth::GUI::SurfaceCairo::Gradient(smooth::GUI::Rect const&, smooth::GUI::Color const&, smooth::GUI::Color const&, int)
S::Int S::GUI::SurfaceCairo::Gradient(const Rect &iRect, const Color &color1, const Color &color2, Int style)
{
	if (window == NIL) return Success();

	Rect	 rect = rightToLeft.TranslateRect(iRect);

	/* Setup colors.
	 */
	Color	 c1   = (style == OR_HORZ && rightToLeft.GetRightToLeft()) ? color2 : color1;
	Color	 c2   = (style == OR_HORZ && rightToLeft.GetRightToLeft()) ? color1 : color2;

	/* Setup Cairo objects and draw gradient.
	 */
	cairo_pattern_t	*pattern = cairo_pattern_create_linear(0, 0, style == OR_HORZ ? rect.GetWidth()	 : 0,
								     style == OR_VERT ? rect.GetHeight() : 0);

	cairo_pattern_add_color_stop_rgb(pattern, 0, c1.GetRed() / 255.0, c1.GetGreen() / 255.0, c1.GetBlue() / 255.0);
	cairo_pattern_add_color_stop_rgb(pattern, 1, c2.GetRed() / 255.0, c2.GetGreen() / 255.0, c2.GetBlue() / 255.0);

	if (!painting)
	{
		CreateCairoContext();

		cairo_set_source(context, pattern);
		cairo_rectangle(context, rect.left, rect.top, rect.GetWidth(), rect.GetHeight());
		cairo_fill(context);

		DestroyCairoContext();
	}

	cairo_set_source(paintContextCairo, pattern);
	cairo_rectangle(paintContextCairo, rect.left, rect.top, rect.GetWidth(), rect.GetHeight());
	cairo_fill(paintContextCairo);

	cairo_pattern_destroy(pattern);

	return Success();
}

// Assembly:
cmpq $0x0, 0x50(%rdi)
je 0xc5d22
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebp
movq %rcx, %r12
movq %rdx, %r13
movq %rdi, 0x20(%rsp)
leaq 0x28(%rdi), %r15
movq %r15, %rdi
callq 0x632ca
movq %rdx, %rbx
cmpl $0x1, %ebp
jne 0xc5b1f
movq %r15, %rdi
movq %rax, %rbp
callq 0x6330c
testb %al, %al
movq %r13, %rax
cmovneq %r12, %rax
movq 0x8(%rax), %r14
movq %r15, %rdi
callq 0x6330c
testb %al, %al
cmovneq %r13, %r12
movq 0x8(%r12), %r15
movl %ebx, %eax
subl %ebp, %eax
cvtsi2sd %eax, %xmm2
xorpd %xmm3, %xmm3
movq %rbp, %r13
jmp 0xc5b51
movq %rax, %rcx
movq 0x8(%r13), %r14
movq 0x8(%r12), %r15
xorpd %xmm2, %xmm2
cmpl $0x2, %ebp
jne 0xc5b4a
movq %rbx, %rax
shrq $0x20, %rax
movq %rcx, %r13
shrq $0x20, %rcx
subl %ecx, %eax
cvtsi2sd %eax, %xmm3
jmp 0xc5b51
xorpd %xmm3, %xmm3
movq %rcx, %r13
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
callq 0x58070
movq %rax, %r12
movl $0xff, %ebp
movl %r14d, %eax
andl %ebp, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x2d7f0(%rip), %xmm0    # 0xf3368
divsd %xmm0, %xmm1
movl %r14d, %eax
shrl $0x8, %eax
andl %ebp, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm0, %xmm2
shrl $0x10, %r14d
andl %ebp, %r14d
xorps %xmm3, %xmm3
cvtsi2sd %r14d, %xmm3
divsd %xmm0, %xmm3
xorpd %xmm0, %xmm0
movq %r12, %rdi
callq 0x57f00
movl %r15d, %eax
andl %ebp, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x2d7a6(%rip), %xmm0    # 0xf3368
divsd %xmm0, %xmm1
movl %r15d, %eax
shrl $0x8, %eax
andl %ebp, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm0, %xmm2
shrl $0x10, %r15d
andl %ebp, %r15d
xorps %xmm3, %xmm3
cvtsi2sd %r15d, %xmm3
divsd %xmm0, %xmm3
movsd 0x2d794(%rip), %xmm0    # 0xf3388
movq %r12, %rdi
callq 0x57f00
movq 0x20(%rsp), %r14
cmpw $0x0, 0xa(%r14)
je 0xc5c51
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r13, %rax
shrq $0x20, %rax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
movl %ebx, %ecx
subl %r13d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x8(%rsp)
shrq $0x20, %rbx
subl %eax, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, (%rsp)
jmp 0xc5cce
movq %r14, %rdi
callq 0xc3f18
movq 0xc0(%r14), %rdi
movq %r12, %rsi
callq 0x58720
movq 0xc0(%r14), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movq %r13, %rax
shrq $0x20, %rax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl %ebx, %ecx
subl %r13d, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
shrq $0x20, %rbx
subl %eax, %ebx
xorps %xmm3, %xmm3
cvtsi2sd %ebx, %xmm3
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm2, 0x8(%rsp)
movsd %xmm3, (%rsp)
callq 0x565a0
movq 0xc0(%r14), %rdi
callq 0x57d40
movq %r14, %rdi
callq 0xc3f6e
movq 0xd0(%r14), %rdi
movq %r12, %rsi
callq 0x58720
movq 0xd0(%r14), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movsd (%rsp), %xmm3
callq 0x565a0
movq 0xd0(%r14), %rdi
callq 0x57d40
movq %r12, %rdi
callq 0x58170
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq
nop