// File: /workspace/github_c_makefile_star2_O1/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 0xc56bd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x28(%rdi), %r13
movq %r13, %rdi
callq 0x63272
movq %rax, %r14
movq %rax, %rbp
shrq $0x20, %rbp
movq %r13, %rdi
movq %r12, %rsi
callq 0x63272
movq %rax, %rcx
shrq $0x20, %rcx
movl %eax, %edx
subl %r14d, %edx
sete %sil
cmpq %rcx, %rbp
sete %dil
orb %sil, %dil
je 0xc547b
cmpw $0x0, 0xa(%rbx)
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x8(%rsp)
jne 0xc53b6
movq %rbx, %rdi
callq 0xc508a
movq 0xc0(%rbx), %rdi
movl 0x8(%r15), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2f04d(%rip), %xmm3    # 0xf4368
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 0x2f039(%rip), %xmm0    # 0xf4388
callq 0x56d40
movq 0xc0(%rbx), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x4f11d(%rip), %xmm2    # 0x114488
addsd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
addsd %xmm2, %xmm1
callq 0x572e0
movq 0xc0(%rbx), %rdi
movsd (%rsp), %xmm0
movsd 0x4f0f5(%rip), %xmm1    # 0x114488
addsd %xmm1, %xmm0
addsd 0x8(%rsp), %xmm1
callq 0x56480
movq 0xc0(%rbx), %rdi
callq 0x57010
movq %rbx, %rdi
callq 0xc50e0
movq 0xd0(%rbx), %rdi
movl 0x8(%r15), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2ef8f(%rip), %xmm3    # 0xf4368
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 0x2ef75(%rip), %xmm0    # 0xf4388
callq 0x56d40
movq 0xd0(%rbx), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x4f059(%rip), %xmm2    # 0x114488
addsd %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
addsd %xmm2, %xmm1
callq 0x572e0
movq 0xd0(%rbx), %rdi
movsd (%rsp), %xmm0
movsd 0x4f031(%rip), %xmm2    # 0x114488
addsd %xmm2, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm2, %xmm1
callq 0x56480
movq 0xd0(%rbx), %rdi
callq 0x57010
jmp 0xc56af
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
subl %ebp, %ecx
movl %ecx, %r12d
negl %r12d
cmovsl %ecx, %r12d
cmpl %r12d, %eax
cmovgl %eax, %r12d
cvtsi2sd %r12d, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testl %r12d, %r12d
je 0xc54b2
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
je 0xc54c5
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
cmpw $0x0, 0xa(%rbx)
jne 0xc55cc
movq %rbx, %rdi
callq 0xc508a
movq 0xc0(%rbx), %rdi
movl 0x8(%r15), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2ee67(%rip), %xmm3    # 0xf4368
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 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
je 0xc55b8
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movl %r12d, %r13d
movsd %xmm0, (%rsp)
movq 0xc0(%rbx), %rdi
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x20(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd 0x18(%rsp), %xmm1
movsd 0x2edf7(%rip), %xmm2    # 0xf4388
movapd %xmm2, %xmm3
callq 0x565a0
movsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addsd 0x2edd5(%rip), %xmm0    # 0xf4388
decl %r13d
jne 0xc555f
movq 0xc0(%rbx), %rdi
callq 0x57d40
movq %rbx, %rdi
callq 0xc50e0
movq 0xd0(%rbx), %rdi
movl 0x8(%r15), %eax
movl $0xff, %ecx
movl %eax, %edx
andl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x2ed79(%rip), %xmm3    # 0xf4368
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 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
je 0xc56a3
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x18(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq 0xd0(%rbx), %rdi
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0x20(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd %xmm2, %xmm1
addsd 0x18(%rsp), %xmm1
movsd 0x2ed0c(%rip), %xmm2    # 0xf4388
movapd %xmm2, %xmm3
callq 0x565a0
movsd (%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addsd 0x2ecea(%rip), %xmm0    # 0xf4388
decl %r12d
jne 0xc564a
movq 0xd0(%rbx), %rdi
callq 0x57d40
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq