// File: /workspace/github_c_makefile_star2_O0/eitijupaenoithoowohd[P]TBezierInterpolation/TBezierInterpolation.cpp
// Function: calculateSpline(std::vector<Point2D, std::allocator<Point2D>> const&, std::vector<Segment, std::allocator<Segment>>&)
bool calculateSpline(const vector<Point2D> &values, vector<Segment> &bezier)
{
	int n = values.size() - 1;

	if (n < 2)
		return false;

	bezier.resize(n);

	Point2D tgL;
	Point2D tgR;
	Point2D cur;
	Point2D next = values[1] - values[0];
	next.normalize();

	double l1, l2, tmp, x;

	for (int i = 0; i < n; ++i)
	{
		bezier[i].points[0] = bezier[i].points[1] = values[i];
		bezier[i].points[2] = bezier[i].points[3] = values[i + 1];

		tgL = tgR;
		cur = next;

		if(i+1 < n){
			next = values[i + 2] - values[i + 1];
			next.normalize();

			tgR = cur + next;
			tgR.normalize();
		}else{
			tgR.x= 0.0;
			tgR.y= 0.0;
		}

		if (abs(values[i + 1].y - values[i].y) < EPSILON)
		{
			l1 = l2 = 0.0;
		}
		else
		{
			tmp = values[i + 1].x - values[i].x;
			l1 = abs(tgL.x) > EPSILON ? tmp / (2.0 * tgL.x) : 1.0;
			l2 = abs(tgR.x) > EPSILON ? tmp / (2.0 * tgR.x) : 1.0;
		}

		if (abs(tgL.x) > EPSILON && abs(tgR.x) > EPSILON)
		{
			tmp = tgL.y / tgL.x - tgR.y / tgR.x;
			if (abs(tmp) > EPSILON)
			{
				x = (values[i + 1].y - tgR.y / tgR.x * values[i + 1].x - values[i].y + tgL.y / tgL.x * values[i].x) / tmp;
				if (x > values[i].x && x < values[i + 1].x)
				{
					if (tgL.y > 0.0)
					{
						if (l1 > l2)
							l1 = 0.0;
						else
							l2 = 0.0;
					}
					else
					{
						if (l1 < l2)
							l1 = 0.0;
						else
							l2 = 0.0;
					}
				}
			}
		}

		bezier[i].points[1] += tgL * l1;
		bezier[i].points[2] -= tgR * l2;
	}

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1d30
subq $0x1, %rax
movl %eax, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x12c2
movb $0x0, -0x1(%rbp)
jmp 0x1921
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1d50
leaq -0x30(%rbp), %rdi
callq 0x1de0
leaq -0x40(%rbp), %rdi
callq 0x1de0
leaq -0x50(%rbp), %rdi
callq 0x1de0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1e00
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1e00
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x1e20
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1e70
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x191d
movq -0x10(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1e00
movq %rax, -0xf0(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1ee0
movq -0xf0(%rbp), %rcx
movq %rax, -0xe8(%rbp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1ee0
movq -0xe8(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1ee0
movq -0xe0(%rbp), %rcx
movq %rax, -0xd8(%rbp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1ee0
movq -0xd8(%rbp), %rcx
movq 0x30(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq 0x38(%rcx), %rcx
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
cmpl -0x1c(%rbp), %eax
jge 0x1500
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x1e00
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
callq 0x1e20
movsd %xmm0, -0x98(%rbp)
movsd %xmm1, -0x90(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1e70
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1f00
movsd %xmm0, -0xa8(%rbp)
movsd %xmm1, -0xa0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1e70
jmp 0x1510
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1e00
movsd -0x100(%rbp), %xmm0
subsd 0x8(%rax), %xmm0
callq 0x1f50
movaps %xmm0, %xmm1
movsd 0x2aa9(%rip), %xmm0     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x157a
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x166a
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movsd (%rax), %xmm0
movsd %xmm0, -0x108(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1e00
movsd -0x108(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x1f50
movsd 0x2a3a(%rip), %xmm1     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x15f4
movsd -0x78(%rbp), %xmm0
movsd 0x2a37(%rip), %xmm1     # 0x4018
mulsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
jmp 0x1606
movsd 0x2a14(%rip), %xmm0     # 0x4010
movsd %xmm0, -0x110(%rbp)
jmp 0x1606
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x1f50
movsd 0x29e3(%rip), %xmm1     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x164b
movsd -0x78(%rbp), %xmm0
movsd 0x29e0(%rip), %xmm1     # 0x4018
mulsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x118(%rbp)
jmp 0x165d
movsd 0x29bd(%rip), %xmm0     # 0x4010
movsd %xmm0, -0x118(%rbp)
jmp 0x165d
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x1f50
movsd 0x298c(%rip), %xmm1     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x1887
movsd -0x40(%rbp), %xmm0
callq 0x1f50
movsd 0x2970(%rip), %xmm1     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x1887
movsd -0x28(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
divsd -0x40(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
callq 0x1f50
movsd 0x2937(%rip), %xmm1     # 0x4008
ucomisd %xmm1, %xmm0
jbe 0x1885
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
movsd -0x38(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x148(%rbp)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movsd -0x148(%rbp), %xmm0
movsd -0x140(%rbp), %xmm1
movsd (%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1e00
movsd -0x138(%rbp), %xmm0
subsd 0x8(%rax), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x28(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1e00
movsd -0x130(%rbp), %xmm0
movsd -0x128(%rbp), %xmm1
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1e00
movsd -0x120(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x1883
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1e00
movsd -0x150(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1883
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x185d
movsd -0x68(%rbp), %xmm0
ucomisd -0x70(%rbp), %xmm0
jbe 0x1853
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x185b
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x1881
movsd -0x68(%rbp), %xmm1
movsd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1877
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x187f
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x1881
jmp 0x1883
jmp 0x1885
jmp 0x1887
movsd -0x68(%rbp), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x1f70
movsd %xmm0, -0xb8(%rbp)
movsd %xmm1, -0xb0(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1ee0
movq %rax, %rdi
addq $0x10, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x1fc0
movsd -0x70(%rbp), %xmm0
leaq -0x40(%rbp), %rdi
callq 0x1f70
movsd %xmm0, -0xc8(%rbp)
movsd %xmm1, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x84(%rbp), %rsi
callq 0x1ee0
movq %rax, %rdi
addq $0x20, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2000
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1338
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nop