// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/psd.cc
// Function: calcSphereIntersect(std::vector<std::pair<Point, double>, std::allocator<std::pair<Point, double>>>&, std::vector<std::pair<Point, double>, std::allocator<std::pair<Point, double>>>&)
void calcSphereIntersect(vector<pair <Point, double> > &inputNodeSphereAndRadii, vector<pair <Point, double> > &outputNodeSphereAndRadii){
	int size = inputNodeSphereAndRadii.size(); 
	vector <int> overlap_nodes; 
	for (int a=0; a<inputNodeSphereAndRadii.size(); a++){
		bool noOverlap = true;
		for (int b=a+1; b<inputNodeSphereAndRadii.size() && noOverlap; b++){
			double Radius1= inputNodeSphereAndRadii.at(a). second; double Radius2=inputNodeSphereAndRadii.at(b).second;
			Point coord1 = inputNodeSphereAndRadii.at(a).first; Point coord2 = inputNodeSphereAndRadii.at(b).first;

			double dist = calcEuclideanDistance(coord1[0], coord1[1], coord1[2], coord2[0], coord2[1], coord2[2]);
			double vol1 = (4*PI/3)*(Radius1*Radius1*Radius1);
			double vol2 = (4*PI/3)*(Radius2*Radius2*Radius2);

			bool overlap = (dist < (Radius1 + Radius2));
			if (overlap){
				bool size = (Radius1>Radius2);
				bool inside = (dist <= abs(Radius1-Radius2));
				/*if (inside && size) {
					printf("Node %d encompasses Node %d\n", a, b);
				}
				if (inside && !size){
					printf("Node %d encompasses Node %d\n", b, a);
				}*/
				if (!inside){
				double distsq = dist*dist; 
				double Rad1sq = Radius1*Radius1; double Rad2sq = Radius2*Radius2;
				double volIntersect = (PI/(12*dist))*(Radius1 + Radius2 - dist)*(Radius1 + Radius2 - dist)*(distsq+2*dist*(Radius1 + Radius2) - 3*(Radius1 - Radius2)*(Radius1-Radius2));
				double overlapDist = Radius1 + Radius2 - dist;

				double diff; double volFraction;
				int largerID; double largerRadius; Point largerCoord;
				double smallerRadius; Point smallerCoord;
				if (size){
					diff = 2*Radius2 - overlapDist; 
					volFraction = volIntersect/ vol2; 
				}
				if (!size){
					diff = 2*Radius1 - overlapDist; 
					volFraction = volIntersect/vol1;
				}
				if (volFraction>=TOL) {
					noOverlap = false;
				}
			}
	  }
	}
	if (noOverlap) outputNodeSphereAndRadii.push_back(pair <Point, double> (inputNodeSphereAndRadii.at(a).first, inputNodeSphereAndRadii.at(a).second));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, 0x60(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
cmpq %rax, %rdx
je 0x8c006
movq %rdi, %r14
movl $0x38, %ebp
movl $0x2, %ebx
xorl %r13d, %r13d
leaq 0x40(%rsp), %r15
leaq 0xa0(%rsp), %r12
leaq 0x1(%r13), %rcx
subq %rax, %rdx
sarq $0x5, %rdx
movq %rbx, 0x70(%rsp)
movq %rbp, 0x78(%rsp)
movq %rcx, 0x68(%rsp)
cmpq %rcx, %rdx
jbe 0x8bf6f
cmpq %r13, %rdx
jbe 0x8c018
movq %r13, %rcx
shlq $0x5, %rcx
movsd 0x18(%rax,%rcx), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rax,%rbp), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, 0x50(%rsp)
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
movq -0x8(%rax,%rbp), %rcx
movq %rcx, 0xb0(%rsp)
movups -0x18(%rax,%rbp), %xmm0
movaps %xmm0, 0xa0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r15, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm5
movsd 0x30(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movsd 0x88(%rsp), %xmm3
movsd 0x80(%rsp), %xmm4
callq 0x84cbb
movsd 0x8(%rsp), %xmm5
movapd 0x90(%rsp), %xmm4
movapd %xmm5, %xmm1
addsd %xmm4, %xmm1
movb $0x1, %sil
ucomisd %xmm0, %xmm1
jbe 0x8bf44
movapd %xmm5, %xmm2
subsd %xmm4, %xmm2
movapd %xmm2, %xmm3
andpd 0xc1258(%rip), %xmm3    # 0x14d0a0
ucomisd %xmm0, %xmm3
jae 0x8bf44
movapd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
movapd %xmm3, 0x30(%rsp)
movapd %xmm4, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
movapd %xmm3, 0x20(%rsp)
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
movapd %xmm0, %xmm4
mulsd 0xc6416(%rip), %xmm4    # 0x1522a0
movsd 0xc577e(%rip), %xmm5    # 0x151610
divsd %xmm4, %xmm5
movapd %xmm1, %xmm4
subsd %xmm0, %xmm4
mulsd %xmm4, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm0, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movapd %xmm2, %xmm1
mulsd 0xc9bc2(%rip), %xmm1    # 0x155a80
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
mulsd %xmm5, %xmm1
movapd %xmm1, 0x10(%rsp)
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xd0(%rsp), %rdi
callq 0x83f68
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xb8(%rsp), %rdi
callq 0x83f68
movapd 0x90(%rsp), %xmm0
cmpltsd 0x8(%rsp), %xmm0
movapd 0x20(%rsp), %xmm1
andpd %xmm0, %xmm1
andnpd 0x30(%rsp), %xmm0
orpd %xmm1, %xmm0
mulsd 0xc9b5a(%rip), %xmm0    # 0x155a88
movapd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
ucomisd 0xc9b50(%rip), %xmm1    # 0x155a90
setb %sil
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rbx, %rdx
jbe 0x8bf6a
addq $0x20, %rbp
incq %rbx
testb %sil, %sil
jne 0x8bd0d
testb %sil, %sil
je 0x8bfd7
cmpq %r13, %rdx
jbe 0x8c018
shlq $0x5, %r13
movq 0x10(%rax,%r13), %rcx
movq %rcx, 0x50(%rsp)
movups (%rax,%r13), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x18(%rax,%r13), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x60(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x8bfc8
movapd 0x40(%rsp), %xmm0
movapd 0x50(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x20, 0x8(%rdi)
jmp 0x8bfd0
movq %r15, %rdx
callq 0x8c25c
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x5, %rsi
movq 0x78(%rsp), %rbp
addq $0x20, %rbp
movq 0x70(%rsp), %rbx
incq %rbx
movq %rcx, %rdx
movq 0x68(%rsp), %rcx
movq %rcx, %r13
cmpq %rcx, %rsi
ja 0x8bcea
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc16d6(%rip), %rdi     # 0x14d6f5
movq %r13, %rsi
xorl %eax, %eax
callq 0x4630