// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movl %r8d, %ebp
movq %rdi, 0x78(%rsp)
movl 0x8(%rdx), %r15d
movl $0xff, %eax
movl %r15d, %edx
andl %eax, %edx
movl %edx, 0x28(%rsp)
cvtsi2sd %edx, %xmm0
movsd %xmm0, 0x18(%rsp)
movl %r15d, %r13d
shrl $0x8, %r13d
andl %eax, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x10(%rsp)
shrl $0x10, %r15d
andl %eax, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x8(%rcx), %r12d
movl %r12d, %ebx
andl %eax, %ebx
movl %r12d, %r14d
shrl $0x8, %r14d
andl %eax, %r14d
shrl $0x10, %r12d
andl %eax, %r12d
movq 0x8(%rsi), %xmm1
movq %rsi, 0x80(%rsp)
movq (%rsi), %xmm0
psubd %xmm0, %xmm1
leaq 0x40(%rsp), %rsi
movdqa %xmm1, 0x60(%rsp)
movq %xmm1, (%rsi)
leaq 0x30(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x55960
cmpl $0x2, %ebp
je 0x612dc
cmpl $0x1, %ebp
jne 0x614a2
movq 0x78(%rsp), %rax
leaq 0x28(%rax), %rdi
callq 0x6330c
subl 0x28(%rsp), %ebx
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movdqa 0x60(%rsp), %xmm0
movd %xmm0, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
subl %r13d, %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
subl %r15d, %r12d
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
testb %al, %al
je 0x613f0
testl %ebp, %ebp
jle 0x614a2
pshufd $0x55, 0x60(%rsp), %xmm0 # xmm0 = mem[1,1,1,1]
movd %xmm0, %ebx
leaq 0x20(%rsp), %r12
leaq 0x40(%rsp), %r13
movl %ebp, %ecx
movq %rcx, 0x58(%rsp)
leal -0x1(%rcx), %ebp
movsd 0x18(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
testl %ebx, %ebx
jle 0x612cc
cvttsd2si 0x18(%rsp), %eax
cvttsd2si 0x10(%rsp), %ecx
cvttsd2si 0x8(%rsp), %edx
shll $0x10, %edx
orl %eax, %edx
shll $0x8, %ecx
orl %edx, %ecx
movslq %ecx, %r14
xorl %r15d, %r15d
movl %ebp, 0x20(%rsp)
movl %r15d, 0x24(%rsp)
movq %r14, 0x48(%rsp)
movl $0x0, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x56080
incl %r15d
cmpl %r15d, %ebx
jne 0x6129e
cmpl $0x1, 0x58(%rsp)
jg 0x61238
jmp 0x614a2
pshufd $0x55, 0x60(%rsp), %xmm0 # xmm0 = mem[1,1,1,1]
movd %xmm0, %eax
movl %eax, 0x38(%rsp)
testl %eax, %eax
jle 0x614a2
subl 0x28(%rsp), %ebx
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl 0x38(%rsp), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
subl %r13d, %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
subl %r15d, %r12d
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movdqa 0x60(%rsp), %xmm0
movd %xmm0, %ebx
xorl %r14d, %r14d
leaq 0x20(%rsp), %r12
leaq 0x40(%rsp), %r13
movsd 0x8(%rsp), %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
testl %ebx, %ebx
jle 0x613dd
cvttsd2si 0x18(%rsp), %eax
cvttsd2si 0x10(%rsp), %ecx
cvttsd2si 0x8(%rsp), %edx
shll $0x10, %edx
orl %eax, %edx
shll $0x8, %ecx
orl %edx, %ecx
movslq %ecx, %rbp
xorl %r15d, %r15d
movl %r15d, 0x20(%rsp)
movl %r14d, 0x24(%rsp)
movq %rbp, 0x48(%rsp)
movl $0x0, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x56080
incl %r15d
cmpl %r15d, %ebx
jne 0x613ae
incl %r14d
cmpl 0x38(%rsp), %r14d
jne 0x61352
jmp 0x614a2
testl %ebp, %ebp
jle 0x614a2
pshufd $0x55, 0x60(%rsp), %xmm0 # xmm0 = mem[1,1,1,1]
movd %xmm0, %r14d
xorl %ebx, %ebx
leaq 0x40(%rsp), %r13
movsd 0x18(%rsp), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
testl %r14d, %r14d
jle 0x61498
cvttsd2si 0x18(%rsp), %eax
cvttsd2si 0x10(%rsp), %ecx
cvttsd2si 0x8(%rsp), %edx
shll $0x10, %edx
orl %eax, %edx
shll $0x8, %ecx
orl %edx, %ecx
movslq %ecx, %r15
xorl %r12d, %r12d
movl %ebx, 0x20(%rsp)
movl %r12d, 0x24(%rsp)
movq %r15, 0x48(%rsp)
movl $0x0, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x56080
incl %r12d
cmpl %r12d, %r14d
jne 0x61468
incl %ebx
cmpl %ebp, %ebx
jne 0x6140b
leaq 0x40(%rsp), %rdx
movq $0x0, (%rdx)
movq 0x80(%rsp), %rcx
movq 0x8(%rcx), %xmm0
movq (%rcx), %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x8(%rdx)
movq 0x78(%rsp), %rdi
movq (%rdi), %rax
leaq 0x30(%rsp), %rsi
callq *0x90(%rax)
leaq 0x30(%rsp), %rdi
callq 0x59148
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x61501
jmp 0x61501
jmp 0x61501
jmp 0x61501
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x59148
movq %rbx, %rdi
callq 0x57090