// File: /workspace/github_cpp_makefile_star2_O1/ddunbar[P]PDSample/ScallopedSector.cpp
// Function: ScallopedSector::subtractDisk(Vec2&, float, std::vector<ScallopedSector, std::allocator<ScallopedSector>>*)
void ScallopedSector::subtractDisk(Vec2 &C, float r, std::vector<ScallopedSector> *regions)
{
	std::vector<float> angles;

	Vec2 v(C.x - P.x, C.y-P.y);
	float d = sqrt(v.x*v.x + v.y*v.y);

	if (r<d) {
		float theta = atan2(v.y, v.x);
		float x = sqrt(d*d-r*r);
		float angle, alpha = asin(r/d);
		
		angle = canonizeAngle(theta+alpha);
		if (a1<angle && angle<a2) {
			if (distToCurve(angle,0)<x && x<distToCurve(angle,1))
				angles.push_back(angle);
		}

		angle = canonizeAngle(theta-alpha);
		if (a1<angle && angle<a2) {
			if (distToCurve(angle,0)<x && x<distToCurve(angle,1)) 
				angles.push_back(angle);
		}
	}

	for (int arcIndex=0; arcIndex<2; arcIndex++) {
		Vec2 &C2 = arcs[arcIndex].P;
		float R = arcs[arcIndex].r;
		Vec2 v(C.x - C2.x, C.y - C2.y);
		float d = sqrt(v.x*v.x + v.y*v.y);

		if (d>FLT_EPSILON) {
			float invD = 1.0f/d;
			float x = (d*d - r*r + R*R)*invD*.5f;
			float k = R*R - x*x;

			if (k>0) {
				float y = sqrt(k);
				float vx = v.x*invD;
				float vy = v.y*invD;
				float vx_x = vx*x, vy_x = vy*x;
				float vx_y = vx*y, vy_y = vy*y;
				float angle;

				angle = canonizeAngle(atan2(C2.y + vy_x + vx_y - P.y,
											C2.x + vx_x - vy_y - P.x));
				if (a1<angle && angle<a2) angles.push_back(angle);

				angle = canonizeAngle(atan2(C2.y + vy_x - vx_y - P.y,
											C2.x + vx_x + vy_y - P.x));
				if (a1<angle && angle<a2) angles.push_back(angle);
			}
		}
	}
	
	sort(angles.begin(), angles.end());
	angles.insert(angles.begin(), a1);
	angles.push_back(a2);

	for (unsigned int i=1; i<angles.size(); i++) {
		float a1 = angles[i-1], a2 = angles[i];
		float midA = (a1+a2)*.5f;
		float inner = distToCurve(midA,0);
		float outer = distToCurve(midA,1);
		float d1, d2;

		distToCircle(midA, C, r, &d1, &d2); // d1<=d2

		if (d2<inner || d1>outer) {
			regions->push_back(ScallopedSector(P, a1, a2, arcs[0].P, arcs[0].r, arcs[0].sign, arcs[1].P, arcs[1].r, arcs[1].sign));
		} else {
			if (inner<d1) {
				regions->push_back(ScallopedSector(P, a1, a2, arcs[0].P, arcs[0].r, arcs[0].sign, C, r, -1));
			}
			if (d2<outer) {
				regions->push_back(ScallopedSector(P, a1, a2, C, r, 1, arcs[1].P, arcs[1].r, arcs[1].sign));
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %rsi, %r14
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movss (%rsi), %xmm1
movss 0x4(%rsi), %xmm3
subss (%rdi), %xmm1
subss 0x4(%rdi), %xmm3
movaps %xmm3, %xmm2
mulss %xmm3, %xmm2
movaps %xmm1, %xmm0
mulss %xmm1, %xmm0
addss %xmm2, %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jb 0x7dba
xorps %xmm2, %xmm2
sqrtss %xmm0, %xmm2
jmp 0x7dda
movss %xmm1, 0x30(%rsp)
movss %xmm3, 0x20(%rsp)
callq 0x2320
movss 0x20(%rsp), %xmm3
movss 0x30(%rsp), %xmm1
movaps %xmm0, %xmm2
movaps 0x50(%rsp), %xmm4
ucomiss %xmm4, %xmm2
jbe 0x7fe6
movaps %xmm3, %xmm0
movss %xmm2, 0x40(%rsp)
callq 0x2230
movss 0x40(%rsp), %xmm2
movss %xmm0, 0x30(%rsp)
movaps 0x50(%rsp), %xmm1
mulss %xmm1, %xmm1
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
subss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x7e24
sqrtss %xmm0, %xmm0
jmp 0x7e2f
callq 0x2320
movss 0x40(%rsp), %xmm2
movss %xmm0, 0x20(%rsp)
movaps 0x50(%rsp), %xmm0
divss %xmm2, %xmm0
callq 0x22b0
movaps %xmm0, %xmm1
movss 0x30(%rsp), %xmm0
movss %xmm1, 0x40(%rsp)
addss %xmm1, %xmm0
subss 0x8(%r15), %xmm0
movss 0x2634(%rip), %xmm1     # 0xa498
callq 0x2210
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movss 0x2621(%rip), %xmm0     # 0xa498
addss %xmm0, %xmm2
movaps %xmm1, %xmm0
cmpltss 0x260d(%rip), %xmm0     # 0xa494
andps %xmm0, %xmm2
andnps %xmm1, %xmm0
orps %xmm2, %xmm0
movss 0x8(%r15), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x9c(%rsp)
ucomiss %xmm1, %xmm0
jbe 0x7f19
movss 0xc(%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7f19
movq %r15, %rdi
xorl %esi, %esi
callq 0x7a34
movss 0x20(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7f19
movss 0x9c(%rsp), %xmm0
movq %r15, %rdi
movl $0x1, %esi
callq 0x7a34
ucomiss 0x20(%rsp), %xmm0
jbe 0x7f19
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x7f09
movss 0x9c(%rsp), %xmm0
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x7f19
movq %rsp, %rdi
leaq 0x9c(%rsp), %rdx
callq 0x89f8
movss 0x30(%rsp), %xmm0
subss 0x40(%rsp), %xmm0
subss 0x8(%r15), %xmm0
movss 0x2565(%rip), %xmm1     # 0xa498
callq 0x2210
movaps %xmm0, %xmm1
movss 0x2555(%rip), %xmm3     # 0xa498
addss %xmm0, %xmm3
xorps %xmm2, %xmm2
cmpltss %xmm2, %xmm0
andps %xmm0, %xmm3
andnps %xmm1, %xmm0
orps %xmm3, %xmm0
movss 0x8(%r15), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x9c(%rsp)
ucomiss %xmm1, %xmm0
jbe 0x7fe1
movss 0xc(%r15), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7fe1
movq %r15, %rdi
xorl %esi, %esi
callq 0x7a34
movss 0x20(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x7fe1
movss 0x9c(%rsp), %xmm0
movq %r15, %rdi
movl $0x1, %esi
callq 0x7a34
ucomiss 0x20(%rsp), %xmm0
jbe 0x7fe1
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x7fd1
movss 0x9c(%rsp), %xmm0
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x7fe1
movq %rsp, %rdi
leaq 0x9c(%rsp), %rdx
callq 0x89f8
movaps 0x50(%rsp), %xmm4
movaps 0x45a3(%rip), %xmm0     # 0xc590
xorps %xmm4, %xmm0
mulss %xmm4, %xmm0
movaps %xmm0, 0x40(%rsp)
movl $0x1c, %ebp
movq %rsp, %r12
leaq 0x9c(%rsp), %r13
movss (%r15,%rbp), %xmm3
movsd (%r14), %xmm2
movsd -0x8(%r15,%rbp), %xmm0
subps %xmm0, %xmm2
movaps %xmm2, %xmm1
mulps %xmm2, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm2, 0x30(%rsp)
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
ucomiss 0x2455(%rip), %xmm0     # 0xa494
jb 0x804a
xorps %xmm2, %xmm2
sqrtss %xmm0, %xmm2
jmp 0x805e
movss %xmm3, 0x20(%rsp)
callq 0x2320
movss 0x20(%rsp), %xmm3
movaps %xmm0, %xmm2
ucomiss 0x451b(%rip), %xmm2     # 0xc580
jbe 0x826f
movss 0x240d(%rip), %xmm1     # 0xa480
divss %xmm2, %xmm1
mulss %xmm2, %xmm2
addss 0x40(%rsp), %xmm2
mulss %xmm3, %xmm3
addss %xmm3, %xmm2
mulss %xmm1, %xmm2
mulss 0x1fc7(%rip), %xmm2     # 0xa05c
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
subss %xmm0, %xmm3
ucomiss 0x23ed(%rip), %xmm3     # 0xa494
jbe 0x826f
jb 0x80b8
xorps %xmm0, %xmm0
sqrtss %xmm3, %xmm0
jmp 0x80d4
movaps %xmm3, %xmm0
movaps %xmm2, 0x20(%rsp)
movaps %xmm1, 0x70(%rsp)
callq 0x2320
movaps 0x70(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
shufps $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
movaps 0x30(%rsp), %xmm4
mulps %xmm1, %xmm4
movaps %xmm0, %xmm3
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
mulps %xmm4, %xmm3
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
movaps %xmm3, %xmm1
shufps $0x55, %xmm3, %xmm1     # xmm1 = xmm1[1,1],xmm3[1,1]
movss -0x4(%r15,%rbp), %xmm0
movaps %xmm1, 0x30(%rsp)
addss %xmm1, %xmm0
movaps %xmm3, 0x70(%rsp)
addss %xmm3, %xmm0
subss 0x4(%r15), %xmm0
mulps %xmm4, %xmm2
movss -0x8(%r15,%rbp), %xmm1
addss %xmm2, %xmm1
movaps %xmm2, 0x20(%rsp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm2, 0x80(%rsp)
subss %xmm2, %xmm1
subss (%r15), %xmm1
callq 0x2230
subss 0x8(%r15), %xmm0
movss 0x234b(%rip), %xmm1     # 0xa498
callq 0x2210
movaps %xmm0, %xmm2
addss 0x233b(%rip), %xmm2     # 0xa498
movaps %xmm0, %xmm1
cmpltss 0x232b(%rip), %xmm1     # 0xa494
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm2, %xmm1
movss 0x8(%r15), %xmm0
addss %xmm0, %xmm1
movss %xmm1, 0x9c(%rsp)
ucomiss %xmm0, %xmm1
jbe 0x81bb
movss 0xc(%r15), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x81bb
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x81b0
movss %xmm1, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x81bb
movq %r12, %rdi
movq %r13, %rdx
callq 0x89f8
movaps 0x30(%rsp), %xmm0
addss -0x4(%r15,%rbp), %xmm0
subss 0x70(%rsp), %xmm0
subss 0x4(%r15), %xmm0
movss -0x8(%r15,%rbp), %xmm1
addss 0x20(%rsp), %xmm1
addss 0x80(%rsp), %xmm1
subss (%r15), %xmm1
callq 0x2230
subss 0x8(%r15), %xmm0
movss 0x2297(%rip), %xmm1     # 0xa498
callq 0x2210
movaps %xmm0, %xmm2
addss 0x2287(%rip), %xmm2     # 0xa498
movaps %xmm0, %xmm1
cmpltss 0x2277(%rip), %xmm1     # 0xa494
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm2, %xmm1
movss 0x8(%r15), %xmm0
addss %xmm0, %xmm1
movss %xmm1, 0x9c(%rsp)
ucomiss %xmm0, %xmm1
jbe 0x826f
movss 0xc(%r15), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x826f
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x8264
movss %xmm1, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x826f
movq %r12, %rdi
movq %r13, %rdx
callq 0x89f8
addq $0x24, %rbp
cmpq $0x40, %rbp
je 0x8009
movq (%rsp), %r12
movq 0x8(%rsp), %r13
cmpq %r13, %r12
je 0x82b8
movq %r13, %rax
subq %r12, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x8b37
movq %r12, %rdi
movq %r13, %rsi
callq 0x8c26
movq %rsp, %rdi
movq (%rdi), %rsi
leaq 0x8(%r15), %rdx
callq 0x8964
leaq 0xc(%r15), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x82ea
movss (%rdx), %xmm0
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x82f2
movq %rsp, %rdi
callq 0x89f8
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
cmpq $0x5, %rax
jb 0x8518
leaq 0x14(%r15), %r12
leaq 0x38(%r15), %r13
movl $0x1, %eax
movl $0x2, %ebx
leaq 0x9c(%rsp), %rbp
leal -0x2(%rbx), %ecx
movss (%rdi,%rcx,4), %xmm1
movss (%rdi,%rax,4), %xmm0
movss %xmm1, 0x40(%rsp)
movss %xmm0, 0x20(%rsp)
addss %xmm0, %xmm1
mulss 0x1d15(%rip), %xmm1     # 0xa05c
movss %xmm1, 0x30(%rsp)
movq %r15, %rdi
movaps %xmm1, %xmm0
xorl %esi, %esi
callq 0x7a34
movss %xmm0, 0x70(%rsp)
movq %r15, %rdi
movss 0x30(%rsp), %xmm0
movl $0x1, %esi
callq 0x7a34
movss %xmm0, 0x80(%rsp)
movq %r15, %rdi
movss 0x30(%rsp), %xmm0
movq %r14, %rsi
movaps 0x50(%rsp), %xmm1
leaq 0x6c(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x7c46
movss 0x70(%rsp), %xmm1
movss 0x68(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
ucomiss %xmm0, %xmm1
ja 0x83c3
movss 0x6c(%rsp), %xmm0
ucomiss 0x80(%rsp), %xmm0
jbe 0x842e
movss 0x1c(%r15), %xmm2
movss 0x20(%r15), %xmm3
movss 0x40(%r15), %xmm4
movss 0x44(%r15), %xmm5
movq %rbp, %rdi
movq %r15, %rsi
movss 0x40(%rsp), %xmm0
movss 0x20(%rsp), %xmm1
movq %r12, %rdx
movq %r13, %rcx
callq 0x7684
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x841e
movl $0x17, %ecx
movq %rsi, %rdi
movq %rbp, %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x5c, 0x8(%rax)
jmp 0x84fb
movq %rax, %rdi
movq %rbp, %rdx
callq 0x8ef8
jmp 0x84fb
ucomiss %xmm1, %xmm0
jbe 0x8497
movss 0x1c(%r15), %xmm2
movss 0x20(%r15), %xmm3
movq %rbp, %rdi
movq %r15, %rsi
movss 0x40(%rsp), %xmm0
movss 0x20(%rsp), %xmm1
movq %r12, %rdx
movq %r14, %rcx
movaps 0x50(%rsp), %xmm4
movss 0x2018(%rip), %xmm5     # 0xa47c
callq 0x7684
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x848c
movl $0x17, %ecx
movq %rsi, %rdi
movq %rbp, %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x5c, 0x8(%rax)
jmp 0x8497
movq %rax, %rdi
movq %rbp, %rdx
callq 0x8ef8
movss 0x80(%rsp), %xmm0
ucomiss 0x30(%rsp), %xmm0
jbe 0x84fb
movss 0x40(%r15), %xmm4
movss 0x44(%r15), %xmm5
movq %rbp, %rdi
movq %r15, %rsi
movss 0x40(%rsp), %xmm0
movss 0x20(%rsp), %xmm1
movq %r14, %rdx
movaps 0x50(%rsp), %xmm2
movss 0x1fab(%rip), %xmm3     # 0xa480
movq %r13, %rcx
callq 0x7684
movq 0x60(%rsp), %rax
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
jne 0x8407
movq %rax, %rdi
movq %rbp, %rdx
callq 0x8ef8
movl %ebx, %eax
movq (%rsp), %rdi
movq 0x8(%rsp), %rcx
subq %rdi, %rcx
sarq $0x2, %rcx
incl %ebx
cmpq %rax, %rcx
ja 0x8322
testq %rdi, %rdi
je 0x852a
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8548
jmp 0x8548
jmp 0x8548
jmp 0x8548
jmp 0x8548
jmp 0x8548
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8561
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2310
nop