// File: /workspace/github_c_makefile_star2_O0/eitijupaenoithoowohd[P]TBezierInterpolation/TBezierInterpolation.c
// Function: CalculateSpline
bool CalculateSpline( Point2D values[], int valuesSize, Segment bezier[])
{
	if (valuesSize < 3) {
		return false;
	}

	int n = valuesSize - 1;

	Point2D tgL= {0.0,0.0};
	Point2D tgR= {0.0,0.0};
	Point2D cur= {0.0,0.0};
	Point2D next = Point2DSubtract(&values[1] ,&values[0]);
	Point2D tmpPoint= {0.0,0.0};
	Point2DNormalize(&next);

	double l1 = 0.0, l2= 0.0, tmp= 0.0, x= 0.0;

	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];

		cur = next;
		tgL = tgR;

		if(i+1 < n){
			next = Point2DSubtract(&values[i + 2],&values[i + 1]);
			Point2DNormalize(&next);

			tgR = Point2DAdd(&cur,&next);
			Point2DNormalize(&tgR);
		}else{
			tgR.x= 0.0;
			tgR.y= 0.0;
		}

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

		if (fabs(tgL.x) > EPSILON && fabs(tgR.x) > EPSILON) {
			tmp = tgL.y / tgL.x - tgR.y / tgR.x;
			if (fabs(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;
					}
				}
			}
		}
		tmpPoint = Point2DMultiply(&tgL , l1);
		bezier[i].points[1] = Point2DAdd(&bezier[i].points[1],&tmpPoint);
		tmpPoint = Point2DMultiply(&tgR , l2);
		bezier[i].points[2] = Point2DSubtract(&bezier[i].points[2],&tmpPoint);
	}

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x1455
movb $0x0, -0x1(%rbp)
jmp 0x1b28
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rsi
callq 0x11c0
movsd %xmm0, -0x68(%rbp)
movsd %xmm1, -0x60(%rbp)
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq -0x68(%rbp), %rdi
callq 0x1260
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1b24
movq -0x20(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movq -0x10(%rbp), %rdx
movslq -0x9c(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movq (%rdx), %rsi
movq %rsi, 0x10(%rcx)
movq 0x8(%rdx), %rdx
movq %rdx, 0x18(%rcx)
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movq -0x10(%rbp), %rdx
movl -0x9c(%rbp), %esi
addl $0x1, %esi
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movq (%rdx), %rsi
movq %rsi, 0x30(%rcx)
movq 0x8(%rdx), %rdx
movq %rdx, 0x38(%rcx)
movq 0x30(%rcx), %rdx
movq %rdx, 0x20(%rax)
movq 0x38(%rcx), %rcx
movq %rcx, 0x28(%rax)
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
cmpl -0x24(%rbp), %eax
jge 0x1682
movq -0x10(%rbp), %rdi
movl -0x9c(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x4, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x9c(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x4, %rax
addq %rax, %rsi
callq 0x11c0
movsd %xmm0, -0xb0(%rbp)
movsd %xmm1, -0xa8(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x1260
leaq -0x58(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x1170
movsd %xmm0, -0xc0(%rbp)
movsd %xmm1, -0xb8(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1260
jmp 0x1692
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl -0x9c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq -0x10(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
movaps 0x964(%rip), %xmm0      # 0x2030
pand %xmm0, %xmm1
movsd 0x940(%rip), %xmm0      # 0x2018
ucomisd %xmm1, %xmm0
jbe 0x16f6
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x17f2
movq -0x10(%rbp), %rax
movl -0x9c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd (%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x38(%rbp), %xmm0
movaps 0x8f5(%rip), %xmm1      # 0x2030
pand %xmm1, %xmm0
movsd 0x8d1(%rip), %xmm1      # 0x2018
ucomisd %xmm1, %xmm0
jbe 0x1770
movsd -0x90(%rbp), %xmm0
movsd 0x8c3(%rip), %xmm1      # 0x2020
mulsd -0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
jmp 0x1782
movsd 0x898(%rip), %xmm0      # 0x2010
movsd %xmm0, -0x108(%rbp)
jmp 0x1782
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x48(%rbp), %xmm0
movaps 0x895(%rip), %xmm1      # 0x2030
pand %xmm1, %xmm0
movsd 0x871(%rip), %xmm1      # 0x2018
ucomisd %xmm1, %xmm0
jbe 0x17d0
movsd -0x90(%rbp), %xmm0
movsd 0x863(%rip), %xmm1      # 0x2020
mulsd -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
jmp 0x17e2
movsd 0x838(%rip), %xmm0      # 0x2010
movsd %xmm0, -0x110(%rbp)
jmp 0x17e2
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x38(%rbp), %xmm0
movaps 0x832(%rip), %xmm1      # 0x2030
pand %xmm1, %xmm0
movsd 0x80e(%rip), %xmm1      # 0x2018
ucomisd %xmm1, %xmm0
jbe 0x19db
movsd -0x48(%rbp), %xmm0
movaps 0x810(%rip), %xmm1      # 0x2030
pand %xmm1, %xmm0
movsd 0x7ec(%rip), %xmm1      # 0x2018
ucomisd %xmm1, %xmm0
jbe 0x19db
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
divsd -0x48(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movaps 0x7cb(%rip), %xmm1      # 0x2030
pand %xmm1, %xmm0
movsd 0x7a7(%rip), %xmm1      # 0x2018
ucomisd %xmm1, %xmm0
jbe 0x19d9
movq -0x10(%rbp), %rax
movl -0x9c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd -0x40(%rbp), %xmm1
divsd -0x48(%rbp), %xmm1
movq -0x10(%rbp), %rax
movl -0x9c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
ucomisd (%rax), %xmm0
jbe 0x19d7
movsd -0x98(%rbp), %xmm1
movq -0x10(%rbp), %rax
movl -0x9c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x19d7
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x19ab
movsd -0x80(%rbp), %xmm0
ucomisd -0x88(%rbp), %xmm0
jbe 0x199e
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x19a9
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x19d5
movsd -0x80(%rbp), %xmm1
movsd -0x88(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x19c8
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x19d3
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x19d5
jmp 0x19d7
jmp 0x19d9
jmp 0x19db
movsd -0x80(%rbp), %xmm0
leaq -0x38(%rbp), %rdi
callq 0x1210
movsd %xmm0, -0xd0(%rbp)
movsd %xmm1, -0xc8(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x120(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x9c(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
addq $0x10, %rdi
leaq -0x78(%rbp), %rsi
callq 0x1170
movq -0x120(%rbp), %rax
movsd %xmm0, -0xe0(%rbp)
movsd %xmm1, -0xd8(%rbp)
movq -0xe0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0xd8(%rbp), %rcx
movq %rcx, 0x18(%rax)
movsd -0x88(%rbp), %xmm0
leaq -0x48(%rbp), %rdi
callq 0x1210
movsd %xmm0, -0xf0(%rbp)
movsd %xmm1, -0xe8(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x118(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x9c(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
addq $0x20, %rdi
leaq -0x78(%rbp), %rsi
callq 0x11c0
movq -0x118(%rbp), %rax
movsd %xmm0, -0x100(%rbp)
movsd %xmm1, -0xf8(%rbp)
movq -0x100(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq -0xf8(%rbp), %rcx
movq %rcx, 0x28(%rax)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x14f5
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)