// File: /workspace/github_cpp_makefile_star2_O1/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 0x8(%rdi), %rax
cmpq (%rdi), %rax
je 0x8dfcd
movq %rdi, %r13
movl $0x38, %r12d
movl $0x2, %r15d
xorl %esi, %esi
leaq 0x1(%rsi), %rcx
movq (%r13), %rax
movq 0x8(%r13), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
movb $0x1, %dil
movl %edi, 0x4(%rsp)
movq %rcx, 0x68(%rsp)
cmpq %rcx, %rdx
movq %r12, 0x78(%rsp)
movq %r15, 0x70(%rsp)
jbe 0x8df37
movb $0x1, %cl
movl %ecx, 0x4(%rsp)
movq %rsi, %rbx
shlq $0x5, %rbx
cmpq %rsi, %rdx
jbe 0x8dfdf
movq %rsi, %r14
movsd 0x18(%rax,%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd (%rax,%r12), %xmm0
movaps %xmm0, 0x90(%rsp)
movq 0x10(%rax,%rbx), %rcx
movq %rcx, 0x20(%rsp)
movups (%rax,%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movq -0x8(%rax,%r12), %rcx
movq %rcx, 0xb0(%rsp)
movups -0x18(%rax,%r12), %xmm0
movaps %xmm0, 0xa0(%rsp)
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbp, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0xa0(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%rsp)
movq %rbp, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm5
movsd 0x50(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x88(%rsp), %xmm3
movsd 0x80(%rsp), %xmm4
callq 0x868fa
movsd 0x8(%rsp), %xmm5
movapd 0x90(%rsp), %xmm4
movapd %xmm5, %xmm2
addsd %xmm4, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x8df0e
movapd %xmm5, %xmm1
subsd %xmm4, %xmm1
movapd %xmm1, %xmm3
andpd 0xc128d(%rip), %xmm3    # 0x14f090
ucomisd %xmm0, %xmm3
jae 0x8df0e
movapd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
movapd %xmm3, 0x50(%rsp)
movapd %xmm4, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
movapd %xmm3, 0x40(%rsp)
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
movapd %xmm0, %xmm4
mulsd 0xc63ab(%rip), %xmm4    # 0x1541f0
movsd 0xc5733(%rip), %xmm5    # 0x153580
divsd %xmm4, %xmm5
movapd %xmm2, %xmm4
subsd %xmm0, %xmm4
mulsd %xmm4, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm0, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm3, %xmm0
movapd %xmm1, %xmm2
mulsd 0xc9aa7(%rip), %xmm2    # 0x157920
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
mulsd %xmm5, %xmm2
movapd %xmm2, 0x30(%rsp)
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xd0(%rsp), %rdi
callq 0x85436
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xb8(%rsp), %rdi
callq 0x85436
movapd 0x90(%rsp), %xmm0
cmpltsd 0x8(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
andpd %xmm0, %xmm1
andnpd 0x50(%rsp), %xmm0
orpd %xmm1, %xmm0
mulsd 0xc9a3f(%rip), %xmm0    # 0x157928
movapd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
ucomisd 0xc9a35(%rip), %xmm1    # 0x157930
movl 0x4(%rsp), %ecx
movzbl %cl, %ecx
movl $0x0, %eax
cmovael %eax, %ecx
movl %ecx, 0x4(%rsp)
movq %r14, %rsi
movq (%r13), %rax
movq 0x8(%r13), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r15, %rdx
jbe 0x8df37
addq $0x20, %r12
incq %r15
testb $0x1, 0x4(%rsp)
jne 0x8dcc0
testb $0x1, 0x4(%rsp)
movq 0x78(%rsp), %r12
movq 0x70(%rsp), %r15
je 0x8dfa9
cmpq %rsi, %rdx
jbe 0x8dfdf
shlq $0x5, %rsi
movq 0x10(%rax,%rsi), %rcx
movq %rcx, 0x20(%rsp)
movups (%rax,%rsi), %xmm0
movaps %xmm0, 0x10(%rsp)
movsd 0x18(%rax,%rsi), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x60(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x8df9f
movapd 0x10(%rsp), %xmm0
movapd 0x20(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x20, 0x8(%rdi)
jmp 0x8dfa9
leaq 0x10(%rsp), %rdx
callq 0x8e214
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x5, %rax
addq $0x20, %r12
incq %r15
movq 0x68(%rsp), %rcx
movq %rcx, %rsi
cmpq %rcx, %rax
ja 0x8dc81
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc16bf(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630