// File: 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
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xf7030
movl %eax, -0x14(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xd0d0
movl $0x0, -0x34(%rbp)
movslq -0x34(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x8(%rbp), %rdi
callq 0xf7030
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jae 0xf6afc
movb $0x1, -0x35(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x8(%rbp), %rdi
callq 0xf7030
movq -0x178(%rbp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x169(%rbp)
jae 0xf6597
movb -0x35(%rbp), %al
movb %al, -0x169(%rbp)
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0xf65a6
jmp 0xf6a6a
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf7050
movq %rax, -0x180(%rbp)
jmp 0xf65bc
movq -0x180(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0xf7050
movq %rax, -0x188(%rbp)
jmp 0xf65e3
movq -0x188(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf7050
movq %rax, -0x190(%rbp)
jmp 0xf660a
movq -0x190(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x70(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0xf7050
movq %rax, -0x198(%rbp)
jmp 0xf6636
movq -0x198(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x90(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0xa0(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x1a0(%rbp)
jmp 0xf6666
movq -0x1a0(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1b0(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x1a8(%rbp)
jmp 0xf6690
movq -0x1a8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1c0(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x1b8(%rbp)
jmp 0xf66ba
movq -0x1b8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1d0(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x1c8(%rbp)
jmp 0xf66e4
movq -0x1c8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1e0(%rbp)
leaq -0xa0(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x1d8(%rbp)
jmp 0xf6711
movq -0x1d8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1f0(%rbp)
leaq -0xa0(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x1e8(%rbp)
jmp 0xf673e
movsd -0x1f0(%rbp), %xmm4
movsd -0x1e0(%rbp), %xmm3
movsd -0x1d0(%rbp), %xmm2
movsd -0x1c0(%rbp), %xmm1
movsd -0x1b0(%rbp), %xmm0
movq -0x1e8(%rbp), %rax
movsd (%rax), %xmm5
callq 0xebaf0
movsd %xmm0, -0x1f8(%rbp)
jmp 0xf6780
movsd -0x1f8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x48(%rbp), %xmm1
mulsd -0x48(%rbp), %xmm1
mulsd -0x48(%rbp), %xmm1
movsd 0x105f09(%rip), %xmm0   # 0x1fc6b0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x60(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
movsd 0x105ee6(%rip), %xmm0   # 0x1fc6b0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xa8(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movb %al, -0xb9(%rbp)
testb $0x1, -0xb9(%rbp)
je 0xf6a5a
movsd -0x48(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
ucomisd %xmm1, %xmm0
seta -0xba(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x208(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
subsd %xmm1, %xmm0
callq 0x162b0
movsd %xmm0, -0x200(%rbp)
jmp 0xf6846
movsd -0x200(%rbp), %xmm0
movsd -0x208(%rbp), %xmm1
ucomisd %xmm1, %xmm0
setae %al
andb $0x1, %al
movb %al, -0xbb(%rbp)
testb $0x1, -0xbb(%rbp)
jne 0xf6a58
movsd -0xa8(%rbp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x48(%rbp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x60(%rbp), %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xa8(%rbp), %xmm1
movsd 0x100b00(%rip), %xmm0   # 0x1f73b8
movaps %xmm1, %xmm2
mulsd %xmm0, %xmm2
movsd 0xffd69(%rip), %xmm0    # 0x1f6630
divsd %xmm2, %xmm0
movsd -0x48(%rbp), %xmm3
movsd -0x60(%rbp), %xmm2
movaps %xmm3, %xmm5
addsd %xmm2, %xmm5
movaps %xmm5, %xmm4
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movsd -0xc8(%rbp), %xmm4
addsd %xmm1, %xmm1
mulsd %xmm5, %xmm1
addsd %xmm4, %xmm1
subsd %xmm2, %xmm3
movsd 0x105dad(%rip), %xmm4   # 0x1fc6b8
movaps %xmm3, %xmm2
mulsd %xmm4, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd -0xa8(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
leaq -0x120(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xe9c70
jmp 0xf695f
leaq -0x140(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xe9c70
jmp 0xf6976
testb $0x1, -0xba(%rbp)
je 0xf69e7
movsd -0x60(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0xe0(%rbp), %xmm0
divsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
jmp 0xf69e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xec80
jmp 0xf6b0e
testb $0x1, -0xba(%rbp)
jne 0xf6a3c
movsd -0x48(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0xe0(%rbp), %xmm0
divsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd 0x105c74(%rip), %xmm1   # 0x1fc6c0
ucomisd %xmm1, %xmm0
jb 0xf6a56
movb $0x0, -0x35(%rbp)
jmp 0xf6a58
jmp 0xf6a5a
jmp 0xf6a5c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xf6563
testb $0x1, -0x35(%rbp)
je 0xf6aec
movq -0x10(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf7050
movq %rax, -0x210(%rbp)
jmp 0xf6a91
movq -0x210(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf7050
movq %rax, -0x220(%rbp)
jmp 0xf6ab5
movq -0x228(%rbp), %rsi
movq -0x220(%rbp), %rdx
addq $0x18, %rdx
leaq -0x160(%rbp), %rdi
callq 0xf6f60
jmp 0xf6ad5
movq -0x218(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0xf6f30
jmp 0xf6aea
jmp 0xf6aec
jmp 0xf6aee
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xf652f
leaq -0x30(%rbp), %rdi
callq 0xec80
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x58f0
nopw (%rax,%rax)