// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/graphics/backends/cairo/surfacecairo.cpp
// Function: smooth::GUI::SurfaceCairo::Line(smooth::GUI::Point const&, smooth::GUI::Point const&, smooth::GUI::Color const&)
S::Int S::GUI::SurfaceCairo::Line(const Point &iPos1, const Point &iPos2, const Color &color)
{
	if (window == NIL) return Success();

	Point	 pos1 = rightToLeft.TranslatePoint(iPos1);
	Point	 pos2 = rightToLeft.TranslatePoint(iPos2);

	/* Draw non-straight lines manually to work around bugs in XWayland.
	 */
	if (pos1.x != pos2.x && pos1.y != pos2.y)
	{
		Int	 steps	  = Math::Max(Math::Abs(pos2.x - pos1.x), Math::Abs(pos2.y - pos1.y));
		Float	 xAdvance = steps ? Float(pos2.x - pos1.x) / steps : 0;
		Float	 yAdvance = steps ? Float(pos2.y - pos1.y) / steps : 0;

		if (!painting)
		{
			CreateCairoContext();

			cairo_set_source_rgb(context, color.GetRed() / 255.0, color.GetGreen() / 255.0, color.GetBlue() / 255.0);

			for (Int i = 0; i < steps; i++) cairo_rectangle(context, pos1.x + i * xAdvance, pos1.y + i * yAdvance, 1.0, 1.0);
		
			cairo_fill(context);

			DestroyCairoContext();
		}

		cairo_set_source_rgb(paintContextCairo, color.GetRed() / 255.0, color.GetGreen() / 255.0, color.GetBlue() / 255.0);

		for (Int i = 0; i < steps; i++) cairo_rectangle(paintContextCairo, pos1.x + i * xAdvance, pos1.y + i * yAdvance, 1.0, 1.0);
		
		cairo_fill(paintContextCairo);
	}
	else
	{
		if (!painting)
		{
			CreateCairoContext();

			cairo_set_source_rgb(context, color.GetRed() / 255.0, color.GetGreen() / 255.0, color.GetBlue() / 255.0);
			cairo_set_line_width(context, 1.0);
			cairo_move_to(context, pos1.x + 0.01, pos1.y + 0.01);
			cairo_line_to(context, pos2.x + 0.01, pos2.y + 0.01);
			cairo_stroke(context);

			DestroyCairoContext();
		}

		cairo_set_source_rgb(paintContextCairo, color.GetRed() / 255.0, color.GetGreen() / 255.0, color.GetBlue() / 255.0);
		cairo_set_line_width(paintContextCairo, 1.0);
		cairo_move_to(paintContextCairo, pos1.x + 0.01, pos1.y + 0.01);
		cairo_line_to(paintContextCairo, pos2.x + 0.01, pos2.y + 0.01);
		cairo_stroke(paintContextCairo);
	}

	return Success();
}

// Assembly:
cmpq $0x0, 0x50(%rdi)
je 0xc4610
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %rbx
leaq 0x28(%rdi), %r13
movq %r13, %rdi
callq 0x632a6
movq %rax, %r12
movq %rax, %rbp
shrq $0x20, %rbp
movq %r13, %rdi
movq %r15, %rsi
callq 0x632a6
movq %rax, %r15
movq %rax, %r13
shrq $0x20, %r13
movl %r12d, %edx
subl %r15d, %edx
sete %al
cmpq %r13, %rbp
sete %cl
orb %al, %cl
je 0xc41d1
cmpw $0x0, 0xa(%rbx)
je 0xc4480
cvtsi2sd %r12d, %xmm1
movsd 0x4f508(%rip), %xmm0    # 0x113698
cvtsi2sd %ebp, %xmm2
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
addsd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
jmp 0xc4564
movq %r12, 0x38(%rsp)
subl %r12d, %r15d
movl %r15d, %eax
negl %eax
cmovsl %r15d, %eax
movl %r13d, %ecx
subl %ebp, %ecx
movl %ecx, %r12d
negl %r12d
cmovsl %ecx, %r12d
cmpl %r12d, %eax
cmoval %eax, %r12d
cvtsi2sd %r12d, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testl %r12d, %r12d
je 0xc4216
xorps %xmm2, %xmm2
cvtsi2sd %r15d, %xmm2
divsd %xmm0, %xmm2
movl %edx, 0x2c(%rsp)
movsd %xmm2, 0x10(%rsp)
je 0xc422d
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm0, %xmm1
movl %ecx, 0x28(%rsp)
movsd %xmm1, 0x18(%rsp)
cmpw $0x0, 0xa(%rbx)
jne 0xc4370
movq %rbx, %rdi
callq 0xc3f18
movq 0xc0(%rbx), %rdi
movq %r14, 0x40(%rsp)
movl 0x8(%r14), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2f0f6(%rip), %xmm3    # 0xf3368
divsd %xmm3, %xmm0
movl %eax, %edx
shrl $0x8, %edx
andl %ecx, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm3, %xmm1
shrl $0x10, %eax
andl %ecx, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
callq 0x58030
testl %r12d, %r12d
movsd 0x18(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
je 0xc4357
xorps %xmm0, %xmm0
cvtsi2sdl 0x38(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x2c(%rsp), %ecx
cmpl %r15d, %ecx
movl %r15d, %eax
cmovgl %ecx, %eax
movl %ebp, %r14d
subl %r13d, %r14d
movl 0x28(%rsp), %ecx
cmpl %ecx, %r14d
cmovlel %ecx, %r14d
cmpl %r14d, %eax
cmoval %eax, %r14d
negl %r14d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xc0(%rbx), %rdi
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0x2f059(%rip), %xmm2    # 0xf3388
movapd %xmm2, %xmm3
callq 0x565a0
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x2f036(%rip), %xmm0    # 0xf3388
incl %r14d
jne 0xc42fa
movq 0xc0(%rbx), %rdi
callq 0x57d40
movq %rbx, %rdi
callq 0xc3f6e
movq 0x40(%rsp), %r14
movq 0xd0(%rbx), %rdi
movl 0x8(%r14), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2efd5(%rip), %xmm3    # 0xf3368
divsd %xmm3, %xmm0
movl %eax, %edx
shrl $0x8, %edx
andl %ecx, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm3, %xmm1
shrl $0x10, %eax
andl %ecx, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
callq 0x58030
testl %r12d, %r12d
movsd 0x18(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
je 0xc446f
xorps %xmm0, %xmm0
cvtsi2sdl 0x38(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x2c(%rsp), %eax
cmpl %r15d, %eax
cmovgl %eax, %r15d
subl %r13d, %ebp
movl 0x28(%rsp), %eax
cmpl %eax, %ebp
cmovlel %eax, %ebp
cmpl %ebp, %r15d
cmoval %r15d, %ebp
negl %ebp
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xd0(%rbx), %rdi
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0x2ef40(%rip), %xmm2    # 0xf3388
movapd %xmm2, %xmm3
callq 0x565a0
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x2ef1d(%rip), %xmm0    # 0xf3388
incl %ebp
jne 0xc4413
movq 0xd0(%rbx), %rdi
callq 0x57d40
jmp 0xc4602
movq %rbx, %rdi
callq 0xc3f18
movq 0xc0(%rbx), %rdi
movl 0x8(%r14), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
cvtsi2sd %edx, %xmm0
movsd 0x2eec0(%rip), %xmm3    # 0xf3368
divsd %xmm3, %xmm0
movl %eax, %edx
shrl $0x8, %edx
andl %ecx, %edx
cvtsi2sd %edx, %xmm1
divsd %xmm3, %xmm1
shrl $0x10, %eax
andl %ecx, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
callq 0x58030
movq 0xc0(%rbx), %rdi
movsd 0x2eeac(%rip), %xmm0    # 0xf3388
callq 0x56d40
movq 0xc0(%rbx), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd 0x4f1a0(%rip), %xmm2    # 0x113698
addsd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
addsd %xmm2, %xmm1
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x18(%rsp)
callq 0x572e0
movq 0xc0(%rbx), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x4f169(%rip), %xmm2    # 0x113698
addsd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
addsd %xmm2, %xmm1
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x20(%rsp)
callq 0x56480
movq 0xc0(%rbx), %rdi
callq 0x57010
movq %rbx, %rdi
callq 0xc3f6e
movq 0xd0(%rbx), %rdi
movl 0x8(%r14), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2ede1(%rip), %xmm3    # 0xf3368
divsd %xmm3, %xmm0
movl %eax, %edx
shrl $0x8, %edx
andl %ecx, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm3, %xmm1
shrl $0x10, %eax
andl %ecx, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
callq 0x58030
movq 0xd0(%rbx), %rdi
movsd 0x2edc7(%rip), %xmm0    # 0xf3388
callq 0x56d40
movq 0xd0(%rbx), %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x572e0
movq 0xd0(%rbx), %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x56480
movq 0xd0(%rbx), %rdi
callq 0x57010
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq
nop