// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, %r14
andq $0x0, 0xa0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
leaq 0x70(%rsp), %r15
pushq $0x2
popq %r12
leaq 0xb0(%rsp), %r13
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq %rcx, %rax
subq %rdx, %rax
sarq $0x5, %rax
cmpq %rbx, %rax
jbe 0x6a636
leaq 0x1(%rbx), %rax
movq %rax, 0x58(%rsp)
movb $0x1, %al
movq 0x20(%rsp), %rbp
subq %rdx, %rcx
sarq $0x5, %rcx
cmpq %rbp, %rcx
jbe 0x6a5da
testb $0x1, %al
je 0x6a5da
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6a990
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6a990
movsd 0x18(%rax), %xmm0
movapd %xmm0, 0x60(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6a990
movq 0x10(%rax), %rcx
movq %rcx, 0x80(%rsp)
movupd (%rax), %xmm0
movapd %xmm0, 0x70(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6a990
movq 0x10(%rax), %rcx
movq %rcx, 0xc0(%rsp)
movupd (%rax), %xmm0
movapd %xmm0, 0xb0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x63c78
movsd (%rax), %xmm5
movsd 0x18(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
movsd 0x8(%rsp), %xmm4
callq 0x64934
movsd 0x28(%rsp), %xmm2
movapd %xmm2, %xmm3
movapd 0x60(%rsp), %xmm1
addsd %xmm1, %xmm3
movb $0x1, %al
ucomisd %xmm0, %xmm3
jbe 0x6a5cb
subsd %xmm1, %xmm2
movapd %xmm2, %xmm1
andpd 0x91be4(%rip), %xmm1    # 0xfc0a0
ucomisd %xmm0, %xmm1
jae 0x6a5cb
movsd %xmm3, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
mulsd 0x96d2e(%rip), %xmm0    # 0x101208
movsd %xmm0, 0x8(%rsp)
movapd %xmm2, 0x30(%rsp)
movapd %xmm2, %xmm0
mulsd 0x9a4ce(%rip), %xmm0    # 0x1049c0
movapd %xmm0, 0x40(%rsp)
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xe0(%rsp), %rdi
callq 0x63c46
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0xc8(%rsp), %rdi
callq 0x63c46
movsd 0x28(%rsp), %xmm5
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
mulsd %xmm5, %xmm0
movapd 0x60(%rsp), %xmm6
movapd %xmm6, %xmm1
mulsd %xmm6, %xmm1
mulsd %xmm6, %xmm1
movsd 0x18(%rsp), %xmm7
movapd %xmm7, %xmm2
mulsd %xmm7, %xmm2
movsd 0x9604c(%rip), %xmm3    # 0x1005b0
divsd 0x8(%rsp), %xmm3
movsd 0x10(%rsp), %xmm8
movapd %xmm8, %xmm4
subsd %xmm7, %xmm4
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm7, %xmm7
mulsd %xmm8, %xmm7
addsd %xmm2, %xmm7
movapd 0x40(%rsp), %xmm2
mulsd 0x30(%rsp), %xmm2
addsd %xmm7, %xmm2
mulsd %xmm3, %xmm2
cmpltsd %xmm5, %xmm6
andpd %xmm6, %xmm1
andnpd %xmm0, %xmm6
orpd %xmm1, %xmm6
mulsd 0x9a40c(%rip), %xmm6    # 0x1049c8
divsd %xmm6, %xmm2
ucomisd 0x9a408(%rip), %xmm2    # 0x1049d0
setb %al
incq %rbp
movq (%r14), %rdx
movq 0x8(%r14), %rcx
jmp 0x6a36a
testb $0x1, %al
je 0x6a627
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6a990
movq %rax, %rbp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6a990
movq 0x10(%rbp), %rcx
movq %rcx, 0x80(%rsp)
movups (%rbp), %xmm0
movaps %xmm0, 0x70(%rsp)
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x6aa2a
incq 0x20(%rsp)
movq 0x58(%rsp), %rbx
jmp 0x6a340
leaq 0x90(%rsp), %rdi
callq 0xb290
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6a663
jmp 0x6a663
jmp 0x6a663
jmp 0x6a663
jmp 0x6a663
jmp 0x6a663
jmp 0x6a663
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780