// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/area_and_volume.cc
// Function: get_most_dense_index(ATOM_NETWORK*, std::vector<Point, std::allocator<Point>>*)
int get_most_dense_index(ATOM_NETWORK *atmnet, vector<Point> *points_vector) { //return the most dense point in a vector - if the vector is sufficiently large, only sample a subset of the points
	int most_dense_index = -1, count = 0;
	double average_dist = 0, max_density = -1;

//  int MAX_POCKET_SIZE_FOR_DENSITY_CALCULATION = 10000;
  int MAX_SAMPLES = 1000;
  int num_points = points_vector->size();
	if(num_points<1) {
		printf("ERROR: get_most_dense_index called on a vector with %d entries\n", num_points);
		exit(EXIT_FAILURE);
//} else if(num_points>=MAX_POCKET_SIZE_FOR_DENSITY_CALCULATION) { //too many points, so use sampling
//  int max_samples = MAX_POCKET_SIZE_FOR_DENSITY_CALCULATION/2;
//		double step = ((double)(num_points))/((double)(max_samples)); //step will always be at least 2
  } else {
    int max_samples = min(MAX_SAMPLES, num_points);
		double step = ((double)(num_points))/((double)(max_samples)); //step will always be at least 1
		vector<int> list;
		for(int i=0; i<max_samples; i++) {
			list.push_back((int)(((double)i)*step));
		}
		for(int i=0; i<max_samples; i++) {
			Point c1 = points_vector->at(list[i]);
			for(int j=i+1; j<max_samples; j++) {
				Point c2 = points_vector->at(list[j]);
        double dist = atmnet->calcDistanceABC(c1[0], c1[1], c1[2], c2[0], c2[1], c2[2]);
				average_dist+=dist;
				count++;
			}
		}
		average_dist/=((double)count);
		for(int i=0; i<max_samples; i++) {
			Point c1 = points_vector->at(list[i]);
			double density = 0;
			for(int j=i+1; j<max_samples; j++) {
				Point c2 = points_vector->at(list[j]);
        double dist = atmnet->calcDistanceABC(c1[0], c1[1], c1[2], c2[0], c2[1], c2[2]);
				density += exp(-1*dist*dist/(average_dist*average_dist));
			}
			if(density>max_density || max_density<0) {
				max_density = density;
				most_dense_index = i;
			}
		}
	}
/*
  else { //few enough points not to require sampling
		for(int i=0; i<num_points; i++) {
			Point c1 = points_vector->at(i);
			for(int j=i+1; j<num_points; j++) {
				Point c2 = points_vector->at(j);
        double dist = atmnet->calcDistanceABC(c1[0], c1[1], c1[2], c2[0], c2[1], c2[2]);
				average_dist+=dist;
				count++;
			}
		}
		average_dist/=((double)count);
		for(int i=0; i<num_points; i++) {
			Point c1 = points_vector->at(i);
			double density = 0;
			for(int j=i+1; j<num_points; j++) {
				Point c2 = points_vector->at(j);
        double dist = atmnet->calcDistanceABC(c1[0], c1[1], c1[2], c2[0], c2[1], c2[2]);
				density += exp(-1*dist*dist/(average_dist*average_dist));
			}
			if(density>max_density || max_density<0) {
				max_density = density;
				most_dense_index = i;
			}
		}
	}
*/
	return most_dense_index;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, 0x48(%rsp)
movq 0x8(%rsi), %rax
movq %rsi, 0x18(%rsp)
subq (%rsi), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
testl %eax, %eax
jle 0x36bbb
movl $0x3e8, %ebx            # imm = 0x3E8
cmpl %ebx, %eax
cmovbl %eax, %ebx
cvtsi2sd %eax, %xmm1
cvtsi2sd %ebx, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
leaq 0x70(%rsp), %r15
andq $0x0, 0x10(%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
xorl %ebp, %ebp
leaq 0x50(%rsp), %r12
cmpl %ebp, %ebx
je 0x36830
cvtsi2sd %ebp, %xmm0
mulsd (%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x50(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x10324
incl %ebp
jmp 0x3680c
movl %ebx, %eax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
leaq 0x50(%rsp), %r15
pushq $0x1
popq %rbp
pushq $0x2
popq %r12
leaq 0xa0(%rsp), %r13
xorl %ebx, %ebx
cmpq 0x20(%rsp), %r14
je 0x3699f
movq 0x70(%rsp), %rax
movslq (%rax,%r14,4), %rsi
movq 0x18(%rsp), %rdi
callq 0x246b4
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movupd (%rax), %xmm0
movapd %xmm0, 0x50(%rsp)
incq %r14
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %r14
cmpq 0x20(%rsp), %r14
jae 0x36990
movq 0x70(%rsp), %rax
movslq (%rax,%r14,4), %rsi
movq 0x18(%rsp), %rdi
callq 0x246b4
movq 0x10(%rax), %rcx
movq %rcx, 0xb0(%rsp)
movupd (%rax), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
movq %r15, %rdi
movl %ebp, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
movl %ebp, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x63c78
movsd (%rax), %xmm5
movq 0x48(%rsp), %rdi
movsd 0x90(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
callq 0x3f440
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
incl %ebx
incq %r14
jmp 0x3689f
incq 0x10(%rsp)
movq 0x8(%rsp), %r14
jmp 0x36861
cvtsi2sd %ebx, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, (%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
movsd 0xc9924(%rip), %xmm0    # 0x1002e8
pushq $0x1
popq %rbx
xorl %r14d, %r14d
leaq 0x50(%rsp), %r15
pushq $0x1
popq %r12
pushq $0x2
popq %r13
leaq 0xa0(%rsp), %rbp
cmpq 0x20(%rsp), %r14
je 0x36b9b
movapd %xmm0, 0xd0(%rsp)
movq 0x70(%rsp), %rax
movslq (%rax,%r14,4), %rsi
movq 0x18(%rsp), %rdi
callq 0x246b4
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movupd (%rax), %xmm0
movapd %xmm0, 0x50(%rsp)
movq %r14, 0xc8(%rsp)
leaq 0x1(%r14), %rax
movq %rax, 0xc0(%rsp)
xorpd %xmm4, %xmm4
movq %rbx, %r14
cmpq 0x20(%rsp), %rbx
jae 0x36b45
movapd %xmm4, 0x90(%rsp)
movq 0x70(%rsp), %rax
movslq (%rax,%rbx,4), %rsi
movq 0x18(%rsp), %rdi
callq 0x246b4
movq 0x10(%rax), %rcx
movq %rcx, 0xb0(%rsp)
movupd (%rax), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r15, %rdi
movl %r13d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
movl %r12d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbp, %rdi
movl %r13d, %esi
callq 0x63c78
movsd (%rax), %xmm5
movq 0x48(%rsp), %rdi
movsd 0x40(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
movsd 0x10(%rsp), %xmm4
callq 0x3f440
movapd %xmm0, %xmm1
xorpd 0xc9ab2(%rip), %xmm1    # 0x1005d0
mulsd %xmm0, %xmm1
divsd (%rsp), %xmm1
movapd %xmm1, %xmm0
callq 0x47b0
movapd 0x90(%rsp), %xmm4
addsd %xmm0, %xmm4
incq %rbx
jmp 0x36a34
movapd 0xd0(%rsp), %xmm3
movapd %xmm3, %xmm0
cmpltpd %xmm4, %xmm0
movapd %xmm3, %xmm1
xorpd %xmm2, %xmm2
cmpltpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movd %xmm1, %eax
testb $0x1, %al
jne 0x36b74
movapd %xmm3, %xmm4
movl 0x8(%rsp), %eax
cmovnel 0xc8(%rsp), %eax
movl %eax, 0x8(%rsp)
movq %r14, %rbx
incq %rbx
movq 0xc0(%rsp), %r14
movapd %xmm4, %xmm0
jmp 0x369df
leaq 0x70(%rsp), %rdi
callq 0xb290
movl 0x8(%rsp), %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xca44d(%rip), %rdi     # 0x10100f
movl %eax, %esi
xorl %eax, %eax
callq 0x4050
pushq $0x1
popq %rdi
callq 0x524c
jmp 0x36bdf
jmp 0x36bdf
jmp 0x36bdf
jmp 0x36bdf
jmp 0x36bdf
jmp 0x36bdf
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780