// File: /workspace/github_cpp_makefile_star2_O1/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), %r12
movq %r12, %rdi
callq 0x2846
movaps %xmm0, 0x20(%rsp)
movq %r12, %rdi
callq 0x2846
movaps 0x20(%rsp), %xmm1
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
addps %xmm1, %xmm1
addps 0x5e24(%rip), %xmm1     # 0xa4b0
leaq 0x8(%rsp), %r15
movlps %xmm1, (%r15)
movl $0x10, %edi
callq 0x21a0
movq %rax, %r14
movss 0x13d0(%rbx), %xmm1
movaps %xmm1, %xmm0
addss %xmm1, %xmm0
mulss 0x5dd3(%rip), %xmm1     # 0xa48c
movss 0x5de3(%rip), %xmm2     # 0xa4a4
movq %rax, %rdi
movq %r15, %rsi
callq 0x856a
leaq 0x38(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %rax, 0x10(%rsp)
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x3298
movq 0x13c0(%rbx), %rax
subq 0x13b8(%rbx), %rax
shrq $0x3, %rax
decl %eax
leaq 0x1c(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x30(%rsp), %rdi
callq 0x5132
movq %r14, (%rax)
movq 0x13c0(%rbx), %rsi
subq 0x13b8(%rbx), %rsi
shrq $0x3, %rsi
decl %esi
movss 0xc(%r14), %xmm0
leaq 0x10(%rsp), %rdi
callq 0x5196
cmpq $0x0, 0x58(%rsp)
leaq 0x38(%rsp), %r14
je 0x4b31
leaq 0x8(%rsp), %r15
movq %r12, 0x60(%rsp)
movq %r12, %rdi
callq 0x2846
leaq 0x10(%rsp), %rdi
callq 0x52d8
movq 0x40(%rsp), %rdx
movq %r14, %rcx
testq %rdx, %rdx
je 0x479c
movq %r14, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setl %sil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x4785
movq %r14, %rdx
cmpq %r14, %rcx
je 0x47ae
cmpl 0x20(%rcx), %eax
cmovlq %r14, %rcx
movq %rcx, %rdx
movq 0x28(%rdx), %rdi
movq %r12, %rsi
callq 0x88a6
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
cmpb $0x1, 0x13d4(%rbx)
jne 0x481a
movss 0x5caa(%rip), %xmm2     # 0xa47c
ucomiss %xmm0, %xmm2
jbe 0x47e1
addss 0x5c99(%rip), %xmm0     # 0xa478
jmp 0x47f2
ucomiss 0x5c98(%rip), %xmm0     # 0xa480
jbe 0x47f2
addss 0x5c92(%rip), %xmm0     # 0xa484
movss 0x5c82(%rip), %xmm2     # 0xa47c
ucomiss %xmm1, %xmm2
jbe 0x4809
addss 0x5c71(%rip), %xmm1     # 0xa478
jmp 0x481a
ucomiss 0x5c70(%rip), %xmm1     # 0xa480
jbe 0x481a
addss 0x5c6a(%rip), %xmm1     # 0xa484
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movlps %xmm0, 0x8(%rsp)
movl $0x10, %edi
callq 0x21a0
movq %rax, %r14
movss 0x13d0(%rbx), %xmm1
movaps %xmm1, %xmm0
addss %xmm1, %xmm0
mulss 0x5c46(%rip), %xmm1     # 0xa48c
movq %rax, %rdi
movq %r15, %rsi
movss 0x5c50(%rip), %xmm2     # 0xa4a4
callq 0x856a
movss 0x13d0(%rbx), %xmm0
mulss 0x5c3f(%rip), %xmm0     # 0xa4a8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3372
movq %r14, 0x20(%rsp)
movq 0x1390(%rbx), %rbp
cmpq 0x1398(%rbx), %rbp
je 0x4a91
movslq (%rbp), %r12
movq 0x13b8(%rbx), %r15
movsd 0x8(%rsp), %xmm0
movsd (%r15,%r12,8), %xmm1
subps %xmm0, %xmm1
cmpb $0x1, 0x13d4(%rbx)
jne 0x48cf
movaps %xmm1, %xmm0
movss 0x5bc1(%rip), %xmm2     # 0xa47c
ucomiss %xmm1, %xmm2
leaq 0x38(%rsp), %r14
jbe 0x48d6
addss 0x5bab(%rip), %xmm0     # 0xa478
jmp 0x48e7
leaq 0x38(%rsp), %r14
jmp 0x492a
ucomiss 0x5ba3(%rip), %xmm0     # 0xa480
jbe 0x48e7
addss 0x5b9d(%rip), %xmm0     # 0xa484
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
movss 0x5b86(%rip), %xmm3     # 0xa47c
ucomiss %xmm2, %xmm3
jbe 0x490b
addss 0x5b75(%rip), %xmm2     # 0xa478
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movaps %xmm0, %xmm1
jmp 0x492a
ucomiss 0x5b6e(%rip), %xmm2     # 0xa480
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
jbe 0x492a
addss 0x5b64(%rip), %xmm2     # 0xa484
movlhps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
shufps $0xe2, %xmm1, %xmm2     # xmm2 = xmm2[2,0],xmm1[2,3]
movaps %xmm2, %xmm1
movsd 0x8(%rsp), %xmm0
addps %xmm1, %xmm0
movss 0x13d0(%rbx), %xmm1
mulss 0x5b49(%rip), %xmm1     # 0xa48c
movq 0x20(%rsp), %rdi
callq 0x8658
movq 0x40(%rsp), %rcx
movq %r14, %rax
testq %rcx, %rcx
je 0x4974
movq %r14, %rax
xorl %edx, %edx
cmpl %r12d, 0x20(%rcx)
setl %dl
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x495d
movq %r14, %rcx
cmpq %r14, %rax
je 0x4987
cmpl 0x20(%rax), %r12d
cmovlq %rcx, %rax
movq %rax, %r14
cmpq %rcx, %r14
je 0x4a88
movsd (%r15,%r12,8), %xmm0
movsd 0x8(%rsp), %xmm1
subps %xmm0, %xmm1
cmpb $0x1, 0x13d4(%rbx)
jne 0x4a16
movaps %xmm1, %xmm0
movss 0x5ac9(%rip), %xmm2     # 0xa47c
ucomiss %xmm1, %xmm2
jbe 0x49c2
addss 0x5ab8(%rip), %xmm0     # 0xa478
jmp 0x49d3
ucomiss 0x5ab7(%rip), %xmm0     # 0xa480
jbe 0x49d3
addss 0x5ab1(%rip), %xmm0     # 0xa484
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
movss 0x5a9a(%rip), %xmm3     # 0xa47c
ucomiss %xmm2, %xmm3
jbe 0x49f7
addss 0x5a89(%rip), %xmm2     # 0xa478
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movaps %xmm0, %xmm1
jmp 0x4a16
ucomiss 0x5a82(%rip), %xmm2     # 0xa480
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
jbe 0x4a16
addss 0x5a78(%rip), %xmm2     # 0xa484
movlhps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
shufps $0xe2, %xmm1, %xmm2     # xmm2 = xmm2[2,0],xmm1[2,3]
movaps %xmm2, %xmm1
movq 0x28(%r14), %r13
movsd (%r15,%r12,8), %xmm0
addps %xmm1, %xmm0
movss 0x13d0(%rbx), %xmm1
addss %xmm1, %xmm1
movq %r13, %rdi
callq 0x8658
movq (%r13), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x4a59
movss 0xc(%r13), %xmm0
leaq 0x10(%rsp), %rdi
movl %r12d, %esi
callq 0x5508
jmp 0x4a88
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x7120
leaq 0x10(%rsp), %rdi
movl %r12d, %esi
callq 0x53ac
movq %r13, %rdi
callq 0x862a
movl $0x10, %esi
movq %r13, %rdi
callq 0x21b0
addq $0x4, %rbp
jmp 0x4880
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
callq 0x3298
movq 0x60(%rsp), %r12
leaq 0x38(%rsp), %r14
leaq 0x8(%rsp), %r15
movq 0x20(%rsp), %r13
movq (%r13), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x4b10
movq 0x13c0(%rbx), %rax
subq 0x13b8(%rbx), %rax
shrq $0x3, %rax
decl %eax
movl %eax, 0x1c(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x5132
movq %r13, (%rax)
movq 0x13c0(%rbx), %rsi
subq 0x13b8(%rbx), %rsi
shrq $0x3, %rsi
decl %esi
movss 0xc(%r13), %xmm0
leaq 0x10(%rsp), %rdi
callq 0x5196
jmp 0x4b25
movq %r13, %rdi
callq 0x862a
movl $0x10, %esi
movq %r13, %rdi
callq 0x21b0
cmpq $0x0, 0x58(%rsp)
jne 0x4763
leaq 0x10(%rsp), %rdi
callq 0x55ba
leaq 0x30(%rsp), %rdi
callq 0x577e
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4b84
movq %rax, %rbx
movl $0x10, %esi
movq %r14, %rdi
callq 0x21b0
jmp 0x4b9b
jmp 0x4b84
jmp 0x4b84
jmp 0x4b84
movq %rax, %rbx
movl $0x10, %esi
movq %r14, %rdi
callq 0x21b0
jmp 0x4b87
jmp 0x4b84
jmp 0x4b84
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x55ba
leaq 0x30(%rsp), %rdi
callq 0x577e
movq %rbx, %rdi
callq 0x2310
nop