// File: /workspace/github_cpp_makefile_star2_O3/ddunbar[P]PDSample/ScallopedSector.cpp
// Function: ScallopedRegion::subtractDisk(Vec2, float)
void ScallopedRegion::subtractDisk(Vec2 C, float r)
{
	std::vector<ScallopedSector> *newRegions = new std::vector<ScallopedSector>;

	area = 0;
	for (unsigned int i=0; i<regions->size(); i++) {
		ScallopedSector &ss = (*regions)[i];
		std::vector<ScallopedSector> *tmp = new std::vector<ScallopedSector>;

		ss.subtractDisk(C, r, tmp);

		for (unsigned int j=0; j<tmp->size(); j++) {
			ScallopedSector &nss = (*tmp)[j];

			if (nss.area>minArea) {
				area += nss.area;

				if (newRegions->size()) {
					ScallopedSector &last = (*newRegions)[newRegions->size()-1];
					if (last.a2==nss.a1 && (last.arcs[0].P==nss.arcs[0].P && last.arcs[0].r==nss.arcs[0].r && last.arcs[0].sign==nss.arcs[0].sign) &&
						(last.arcs[1].P==nss.arcs[1].P && last.arcs[1].r==nss.arcs[1].r && last.arcs[1].sign==nss.arcs[1].sign)) {
						last.a2 = nss.a2;
						last.area = last.calcAreaToAngle(last.a2);
						continue;
					}
				}

				newRegions->push_back(nss);
			}
		}

		delete tmp;
	}

	delete regions;
	regions = newRegions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movss %xmm1, 0x4(%rsp)
movq %rdi, %rbx
movlps %xmm0, 0x10(%rsp)
movl $0x18, %edi
callq 0x21a0
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl $0x0, 0xc(%rbx)
movq (%rbx), %r12
movq (%r12), %rdi
cmpq %rdi, 0x8(%r12)
je 0x8c12
xorl %ecx, %ecx
movabsq $-0x2c8590b21642c859, %r15 # imm = 0xD37A6F4DE9BD37A7
movq %rcx, 0x8(%rsp)
imulq $0x5c, %rcx, %r13
addq %rdi, %r13
movl $0x18, %edi
callq 0x21a0
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
movss 0x4(%rsp), %xmm0
movq %rax, %rdx
callq 0x7d0e
movq (%r12), %rdx
cmpq %rdx, 0x8(%r12)
je 0x8bc9
movl $0x1, %ebp
xorl %eax, %eax
imulq $0x5c, %rax, %rax
movss 0x10(%rdx,%rax), %xmm0
ucomiss 0x8(%rbx), %xmm0
jbe 0x8ba8
addq %rax, %rdx
addss 0xc(%rbx), %xmm0
movss %xmm0, 0xc(%rbx)
movq 0x8(%r14), %r13
cmpq (%r14), %r13
je 0x8b80
movss -0x50(%r13), %xmm0
ucomiss 0x8(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x48(%r13), %xmm0
ucomiss 0x14(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x44(%r13), %xmm0
ucomiss 0x18(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x40(%r13), %xmm0
ucomiss 0x1c(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x3c(%r13), %xmm0
ucomiss 0x20(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x24(%r13), %xmm0
ucomiss 0x38(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x20(%r13), %xmm0
ucomiss 0x3c(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x1c(%r13), %xmm0
ucomiss 0x40(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movss -0x18(%r13), %xmm0
ucomiss 0x44(%rdx), %xmm0
jne 0x8b80
jp 0x8b80
movq %r13, %rdi
addq $-0x5c, %rdi
movss 0xc(%rdx), %xmm0
movss %xmm0, -0x50(%r13)
callq 0x77ae
movss %xmm0, -0x4c(%r13)
jmp 0x8ba8
cmpq 0x10(%r14), %r13
je 0x8b9d
movl $0x17, %ecx
movq %r13, %rdi
movq %rdx, %rsi
rep  movsl (%rsi), %es:(%rdi)
addq $0x5c, %r13
movq %r13, 0x8(%r14)
jmp 0x8ba8
movq %r14, %rdi
movq %r13, %rsi
callq 0x93e4
movl %ebp, %eax
movq (%r12), %rdx
movq 0x8(%r12), %rcx
subq %rdx, %rcx
sarq $0x2, %rcx
imulq %r15, %rcx
incl %ebp
cmpq %rax, %rcx
ja 0x8aa5
testq %rdx, %rdx
je 0x8bde
movq 0x10(%r12), %rsi
subq %rdx, %rsi
movq %rdx, %rdi
callq 0x21b0
movl $0x18, %esi
movq %r12, %rdi
callq 0x21b0
movq 0x8(%rsp), %rcx
incl %ecx
movq (%rbx), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rax
subq %rdi, %rax
sarq $0x2, %rax
imulq %r15, %rax
cmpq %rcx, %rax
ja 0x8a52
testq %rdi, %rdi
je 0x8c24
movq 0x10(%r12), %rsi
subq %rdi, %rsi
callq 0x21b0
movl $0x18, %esi
movq %r12, %rdi
callq 0x21b0
movq %r14, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop