// File: /workspace/github_cpp_makefile_star2_O3/ddunbar[P]PDSample/PDSampling.cpp
// Function: PureSampler::complete()
void PureSampler::complete()
{
	Vec2 pt = randomPoint();
	ScallopedRegion *rgn = new ScallopedRegion(pt, radius*2, radius*4);
	RegionMap regions;
	WeightedDiscretePDF<int> regionsPDF;

	addPoint(pt);
	regions[(int) points.size()-1] = rgn;
	regionsPDF.insert((int) points.size()-1, rgn->area);

	while (regions.size()) {
		int idx = regionsPDF.choose(m_rng.getFloatL());
		
		pt = getTiled(((*regions.find(idx)).second)->sample(m_rng));
		rgn = new ScallopedRegion(pt, radius*2, radius*4);

		findNeighbors(pt, radius*8);
		for (IntVector::const_iterator it=m_neighbors.begin(); it!=m_neighbors.end(); it++) {
			int nIdx = *it;
			Vec2 &n = points[nIdx];
			
			rgn->subtractDisk(pt+getTiled(n-pt), radius*4);

			RegionMap::iterator entry = regions.find(nIdx);
			if (entry!=regions.end()) {
				ScallopedRegion *nRgn = (*entry).second;
				nRgn->subtractDisk(n+getTiled(pt-n), radius*2);

				if (nRgn->isEmpty()) {
					regions.erase(entry);
					regionsPDF.remove(nIdx);
					delete nRgn;
				} else {
					regionsPDF.update(nIdx, nRgn->area);
				}
			}
		}

		addPoint(pt);

		if (!rgn->isEmpty()) {
			regions[(int) points.size()-1] = rgn;
			regionsPDF.insert((int) points.size()-1, rgn->area);
		} else {
			delete rgn;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x2838
movaps %xmm0, 0x20(%rsp)
movq %r15, %rdi
callq 0x2838
movaps 0x20(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
addps %xmm1, %xmm1
addps 0x5ef8(%rip), %xmm1     # 0xa4a0
leaq 0x10(%rsp), %r14
movlps %xmm1, (%r14)
movl $0x10, %edi
callq 0x21a0
movq %rax, %r12
movss 0x13d0(%rbx), %xmm1
movaps %xmm1, %xmm0
addss %xmm1, %xmm0
mulss 0x5ea7(%rip), %xmm1     # 0xa47c
movss 0x5eb3(%rip), %xmm2     # 0xa490
movq %rax, %rdi
movq %r14, %rsi
callq 0x890a
leaq 0x40(%rsp), %rbp
movl $0x0, (%rbp)
xorl %eax, %eax
movq %rax, 0x8(%rbp)
movq %rbp, 0x10(%rbp)
movq %rbp, 0x18(%rbp)
movq %rax, 0x20(%rbp)
movq %rax, 0x8(%rsp)
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x31f0
movq 0x13c0(%rbx), %rax
subq 0x13b8(%rbx), %rax
shrq $0x3, %rax
decl %eax
leaq 0x1c(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x38(%rsp), %rdi
callq 0x505c
movq %r12, (%rax)
movq 0x13c0(%rbx), %rsi
subq 0x13b8(%rbx), %rsi
shrq $0x3, %rsi
decl %esi
movss 0xc(%r12), %xmm0
leaq 0x8(%rsp), %rdi
callq 0x50c2
cmpq $0x0, 0x60(%rsp)
je 0x4a4c
leaq 0x10(%rsp), %r14
movq %r15, 0x30(%rsp)
movq %r15, %rdi
callq 0x2838
leaq 0x8(%rsp), %rdi
callq 0x5204
movq 0x48(%rsp), %r8
movq %rbp, %r9
testq %r8, %r8
je 0x46da
movq %rbp, %rsi
movq %rsi, %rcx
movq %r8, %rdx
movl 0x20(%r8), %edi
xorl %r8d, %r8d
cmpl %eax, %edi
setl %r8b
movq %rdx, %rsi
cmovlq %rcx, %rsi
movq 0x10(%rdx,%r8,8), %r8
testq %r8, %r8
jne 0x469e
movq %rbp, %r9
cmpq %rbp, %rsi
je 0x46da
cmpl %eax, %edi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
cmovlq %rbp, %rsi
movq %rsi, %r9
movq 0x28(%r9), %rdi
movq %r15, %rsi
callq 0x8c44
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
cmpb $0x1, 0x13d4(%rbx)
jne 0x4746
movss 0x5d6e(%rip), %xmm2     # 0xa46c
ucomiss %xmm0, %xmm2
jbe 0x470d
addss 0x5d5d(%rip), %xmm0     # 0xa468
jmp 0x471e
ucomiss 0x5d5c(%rip), %xmm0     # 0xa470
jbe 0x471e
addss 0x5d56(%rip), %xmm0     # 0xa474
movss 0x5d46(%rip), %xmm2     # 0xa46c
ucomiss %xmm1, %xmm2
jbe 0x4735
addss 0x5d35(%rip), %xmm1     # 0xa468
jmp 0x4746
ucomiss 0x5d34(%rip), %xmm1     # 0xa470
jbe 0x4746
addss 0x5d2e(%rip), %xmm1     # 0xa474
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movlps %xmm0, 0x10(%rsp)
movl $0x10, %edi
callq 0x21a0
movq %rax, 0x20(%rsp)
movss 0x13d0(%rbx), %xmm1
movaps %xmm1, %xmm0
addss %xmm1, %xmm0
mulss 0x5d08(%rip), %xmm1     # 0xa47c
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movss 0x5d0c(%rip), %xmm2     # 0xa490
callq 0x890a
movss 0x13d0(%rbx), %xmm0
mulss 0x5cfb(%rip), %xmm0     # 0xa494
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32bc
movq 0x1390(%rbx), %r15
cmpq 0x1398(%rbx), %r15
je 0x49ad
movslq (%r15), %r12
movq 0x13b8(%rbx), %r14
movsd 0x10(%rsp), %xmm1
movsd (%r14,%r12,8), %xmm0
subps %xmm1, %xmm0
cmpb $0x1, 0x13d4(%rbx)
jne 0x4848
movaps %xmm0, %xmm2
movss 0x5c87(%rip), %xmm3     # 0xa46c
ucomiss %xmm0, %xmm3
jbe 0x47f4
addss 0x5c76(%rip), %xmm2     # 0xa468
jmp 0x4805
ucomiss 0x5c75(%rip), %xmm2     # 0xa470
jbe 0x4805
addss 0x5c6f(%rip), %xmm2     # 0xa474
movaps %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm3     # xmm3 = xmm3[1,1],xmm0[1,1]
movss 0x5c58(%rip), %xmm4     # 0xa46c
ucomiss %xmm3, %xmm4
jbe 0x4829
addss 0x5c47(%rip), %xmm3     # 0xa468
unpcklps %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
movaps %xmm2, %xmm0
jmp 0x4848
ucomiss 0x5c40(%rip), %xmm3     # 0xa470
movss %xmm2, %xmm0            # xmm0 = xmm2[0],xmm0[1,2,3]
jbe 0x4848
addss 0x5c36(%rip), %xmm3     # 0xa474
movlhps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
shufps $0xe2, %xmm0, %xmm3     # xmm3 = xmm3[2,0],xmm0[2,3]
movaps %xmm3, %xmm0
addps %xmm1, %xmm0
movss 0x13d0(%rbx), %xmm1
mulss 0x5c21(%rip), %xmm1     # 0xa47c
movq 0x20(%rsp), %rdi
callq 0x89f6
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0x49a4
movq %rbp, %r13
movq %r13, %rax
movq %rsi, %rcx
movl 0x20(%rsi), %edx
xorl %esi, %esi
cmpl %r12d, %edx
setl %sil
movq %rcx, %r13
cmovlq %rax, %r13
movq 0x10(%rcx,%rsi,8), %rsi
testq %rsi, %rsi
jne 0x4876
cmpq %rbp, %r13
je 0x49a4
cmpl %r12d, %edx
cmovlq %rax, %rcx
cmpl 0x20(%rcx), %r12d
jl 0x49a4
movsd (%r14,%r12,8), %xmm1
movsd 0x10(%rsp), %xmm0
subps %xmm1, %xmm0
cmpb $0x1, 0x13d4(%rbx)
jne 0x4939
movaps %xmm0, %xmm2
movss 0x5b96(%rip), %xmm3     # 0xa46c
ucomiss %xmm0, %xmm3
jbe 0x48e5
addss 0x5b85(%rip), %xmm2     # 0xa468
jmp 0x48f6
ucomiss 0x5b84(%rip), %xmm2     # 0xa470
jbe 0x48f6
addss 0x5b7e(%rip), %xmm2     # 0xa474
movaps %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm3     # xmm3 = xmm3[1,1],xmm0[1,1]
movss 0x5b67(%rip), %xmm4     # 0xa46c
ucomiss %xmm3, %xmm4
jbe 0x491a
addss 0x5b56(%rip), %xmm3     # 0xa468
unpcklps %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
movaps %xmm2, %xmm0
jmp 0x4939
ucomiss 0x5b4f(%rip), %xmm3     # 0xa470
movss %xmm2, %xmm0            # xmm0 = xmm2[0],xmm0[1,2,3]
jbe 0x4939
addss 0x5b45(%rip), %xmm3     # 0xa474
movlhps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
shufps $0xe2, %xmm0, %xmm3     # xmm3 = xmm3[2,0],xmm0[2,3]
movaps %xmm3, %xmm0
movq 0x28(%r13), %r14
addps %xmm1, %xmm0
movss 0x13d0(%rbx), %xmm1
addss %xmm1, %xmm1
movq %r14, %rdi
callq 0x89f6
movq (%r14), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x4975
movss 0xc(%r14), %xmm0
leaq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x542a
jmp 0x49a4
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x6fda
leaq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x52d8
movq %r14, %rdi
callq 0x89ca
movl $0x10, %esi
movq %r14, %rdi
callq 0x21b0
addq $0x4, %r15
jmp 0x47ab
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x31f0
movq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r14
movq 0x20(%rsp), %r12
movq (%r12), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x4a2b
movq 0x13c0(%rbx), %rax
subq 0x13b8(%rbx), %rax
shrq $0x3, %rax
decl %eax
movl %eax, 0x1c(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x505c
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq 0x13c0(%rbx), %rsi
subq 0x13b8(%rbx), %rsi
shrq $0x3, %rsi
decl %esi
movss 0xc(%rcx), %xmm0
leaq 0x8(%rsp), %rdi
callq 0x50c2
jmp 0x4a40
movq %r12, %rdi
callq 0x89ca
movl $0x10, %esi
movq %r12, %rdi
callq 0x21b0
cmpq $0x0, 0x60(%rsp)
jne 0x467c
leaq 0x8(%rsp), %rdi
callq 0x54bc
leaq 0x38(%rsp), %rdi
callq 0x5680
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4aa1
movq %rax, %rbx
movl $0x10, %esi
movq %r12, %rdi
callq 0x21b0
jmp 0x4ab8
jmp 0x4aa1
jmp 0x4aa1
jmp 0x4aa1
movq %rax, %rbx
movl $0x10, %esi
movq 0x20(%rsp), %rdi
callq 0x21b0
jmp 0x4aa4
jmp 0x4aa1
jmp 0x4aa1
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x54bc
leaq 0x38(%rsp), %rdi
callq 0x5680
movq %rbx, %rdi
callq 0x2310