// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/graphics/backends/surfacebackend.cpp
// Function: smooth::GUI::SurfaceBackend::Gradient(smooth::GUI::Rect const&, smooth::GUI::Color const&, smooth::GUI::Color const&, int)
S::Int S::GUI::SurfaceBackend::Gradient(const Rect &rect, const Color &color1, const Color &color2, Int style)
{
	Float	 red1	= color1.GetRed();
	Float	 green1	= color1.GetGreen();
	Float	 blue1	= color1.GetBlue();
	Float	 red2	= color2.GetRed();
	Float	 green2	= color2.GetGreen();
	Float	 blue2	= color2.GetBlue();
	Int	 xmax	= rect.GetWidth();
	Int	 ymax	= rect.GetHeight();

	Bitmap	 bmp(Size(xmax, ymax));

	switch (style)
	{
		case OR_HORZ:
		{
			Float	 biasr = (red2 - red1) / xmax;
			Float	 biasg = (green2 - green1) / xmax;
			Float	 biasb = (blue2 - blue1) / xmax;

			if (rightToLeft.GetRightToLeft())
			{
				for (Int x = xmax - 1; x >= 0; x--)
				{
					red1	= red1 + biasr;
					green1	= green1 + biasg;
					blue1	= blue1 + biasb;

					for (Int y = 0; y < ymax; y++) bmp.SetPixel(Point(x, y), Color((Int) red1, (Int) green1, (Int) blue1));
				}
			}
			else
			{
				for (Int x = 0; x < xmax; x++)
				{
					red1	= red1 + biasr;
					green1	= green1 + biasg;
					blue1	= blue1 + biasb;

					for (Int y = 0; y < ymax; y++) bmp.SetPixel(Point(x, y), Color((Int) red1, (Int) green1, (Int) blue1));
				}
			}
		}
		break;

		case OR_VERT:
		{
			Float	 biasr = (red2 - red1) / ymax;
			Float	 biasg = (green2 - green1) / ymax;
			Float	 biasb = (blue2 - blue1) / ymax;

			for (Int y = 0; y < ymax; y++)
			{
				red1	= red1 + biasr;
				green1	= green1 + biasg;
				blue1	= blue1 + biasb;

				for (Int x = 0; x < xmax; x++) bmp.SetPixel(Point(x, y), Color((Int) red1, (Int) green1, (Int) blue1));
			}
		}
		break;
	}

	BlitFromBitmap(bmp, Rect(Point(0, 0), rect.GetSize()), rect);

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r8d, 0x10(%rsp)
movq %rdi, 0x58(%rsp)
movl 0x8(%rdx), %r14d
movl $0xff, %eax
movl %r14d, %r13d
andl %eax, %r13d
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x28(%rsp)
movl %r14d, %r15d
shrl $0x8, %r15d
andl %eax, %r15d
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x20(%rsp)
shrl $0x10, %r14d
andl %eax, %r14d
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x8(%rcx), %ebx
movl %ebx, %ebp
andl %eax, %ebp
movl %ebx, %r12d
shrl $0x8, %r12d
andl %eax, %r12d
shrl $0x10, %ebx
andl %eax, %ebx
movq 0x8(%rsi), %xmm1
movq %rsi, 0x70(%rsp)
movq (%rsi), %xmm0
psubd %xmm0, %xmm1
leaq 0x38(%rsp), %rsi
movdqa %xmm1, 0x60(%rsp)
movq %xmm1, (%rsi)
leaq 0x30(%rsp), %rdi
pushq $-0x1
popq %rdx
callq 0x569c0
movl 0x10(%rsp), %eax
cmpl $0x2, %eax
je 0x61fb9
cmpl $0x1, %eax
jne 0x6214e
movq 0x58(%rsp), %rax
leaq 0x28(%rax), %rdi
callq 0x63e62
subl %r13d, %ebp
cvtsi2sd %ebp, %xmm1
movdqa 0x60(%rsp), %xmm2
movd %xmm2, %ebp
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
subl %r15d, %r12d
cvtsi2sd %r12d, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
subl %r14d, %ebx
cvtsi2sd %ebx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
pshufd $0x55, %xmm2, %xmm0     # xmm0 = xmm2[1,1,1,1]
movd %xmm0, %r14d
xorl %ebx, %ebx
testl %r14d, %r14d
cmovlel %ebx, %r14d
testb %al, %al
je 0x620b4
leaq 0x8(%rsp), %r12
leaq 0x38(%rsp), %r13
testl %ebp, %ebp
jle 0x6214e
decl %ebp
movsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x48(%rsp), %xmm2
movsd %xmm0, 0x28(%rsp)
cvttsd2si %xmm0, %eax
movsd %xmm1, 0x20(%rsp)
cvttsd2si %xmm1, %ecx
movsd %xmm2, 0x18(%rsp)
cvttsd2si %xmm2, %edx
shll $0x10, %edx
orl %eax, %edx
shll $0x8, %ecx
orl %edx, %ecx
movslq %ecx, %rbx
xorl %r15d, %r15d
cmpl %r15d, %r14d
je 0x61f30
movl %ebp, 0x8(%rsp)
movl %r15d, 0xc(%rsp)
movq %rbx, 0x40(%rsp)
andl $0x0, 0x38(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x57160
incl %r15d
jmp 0x61f8c
subl %r13d, %ebp
cvtsi2sd %ebp, %xmm1
movdqa 0x60(%rsp), %xmm3
pshufd $0x55, %xmm3, %xmm0     # xmm0 = xmm3[1,1,1,1]
movd %xmm0, %eax
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
subl %r15d, %r12d
cvtsi2sd %r12d, %xmm1
subl %r14d, %ebx
cvtsi2sd %ebx, %xmm2
movd %xmm3, %ebx
xorl %r14d, %r14d
testl %ebx, %ebx
cmovlel %r14d, %ebx
divsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
testl %eax, %eax
cmovlel %r14d, %eax
movl %eax, 0x10(%rsp)
divsd %xmm0, %xmm2
movsd %xmm2, 0x60(%rsp)
leaq 0x8(%rsp), %r12
leaq 0x38(%rsp), %r13
cmpl 0x10(%rsp), %r14d
je 0x6214e
movsd 0x28(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd 0x48(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x60(%rsp), %xmm2
movsd %xmm0, 0x28(%rsp)
cvttsd2si %xmm0, %eax
movsd %xmm1, 0x20(%rsp)
cvttsd2si %xmm1, %ecx
movsd %xmm2, 0x18(%rsp)
cvttsd2si %xmm2, %edx
shll $0x10, %edx
orl %eax, %edx
shll $0x8, %ecx
orl %edx, %ecx
movslq %ecx, %rbp
xorl %r15d, %r15d
cmpl %r15d, %ebx
je 0x620ac
movl %r15d, 0x8(%rsp)
movl %r14d, 0xc(%rsp)
movq %rbp, 0x40(%rsp)
andl $0x0, 0x38(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x57160
incl %r15d
jmp 0x6207e
incl %r14d
jmp 0x62021
testl %ebp, %ebp
cmovlel %ebx, %ebp
leaq 0x38(%rsp), %r13
cmpl %ebp, %ebx
je 0x6214e
movsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x48(%rsp), %xmm2
movsd %xmm0, 0x28(%rsp)
cvttsd2si %xmm0, %eax
movsd %xmm1, 0x20(%rsp)
cvttsd2si %xmm1, %ecx
movsd %xmm2, 0x18(%rsp)
cvttsd2si %xmm2, %edx
shll $0x10, %edx
orl %eax, %edx
shll $0x8, %ecx
orl %edx, %ecx
movslq %ecx, %r15
xorl %r12d, %r12d
cmpl %r12d, %r14d
je 0x62147
movl %ebx, 0x8(%rsp)
movl %r12d, 0xc(%rsp)
movq %r15, 0x40(%rsp)
andl $0x0, 0x38(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x57160
incl %r12d
jmp 0x62118
incl %ebx
jmp 0x620be
movq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x56c50
movq %rax, %rcx
leaq 0x38(%rsp), %rdx
andq $0x0, (%rdx)
shrq $0x20, %rcx
movl %eax, 0x8(%rdx)
movl %ecx, 0xc(%rdx)
movq 0x58(%rsp), %rdi
movq (%rdi), %rax
leaq 0x30(%rsp), %rsi
movq %rbx, %rcx
callq *0x90(%rax)
leaq 0x30(%rsp), %rdi
callq 0x5a4c8
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x621aa
jmp 0x621aa
jmp 0x621aa
jmp 0x621aa
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5a4c8
movq %rbx, %rdi
callq 0x58260
nop