// File: 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
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd 0x16e7e7(%rip), %xmm0   # 0x1f2778
movsd %xmm0, -0x28(%rbp)
movl $0x3e8, -0x2c(%rbp)     # imm = 0x3E8
movq -0x10(%rbp), %rdi
callq 0x17c60
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jge 0x83fca
movl -0x30(%rbp), %esi
leaq 0x173236(%rip), %rdi    # 0x1f71ef
movb $0x0, %al
callq 0x5070
movl $0x1, %edi
callq 0x67c0
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x85460
movl (%rax), %eax
movl %eax, -0x34(%rbp)
cvtsi2sdl -0x30(%rbp), %xmm0
cvtsi2sdl -0x34(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xd0d0
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x84052
cvtsi2sdl -0x5c(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xffc0
jmp 0x8402b
jmp 0x8402d
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x83fff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xec80
jmp 0x845b8
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x842b8
movq -0x10(%rbp), %rax
movq %rax, -0x118(%rbp)
movslq -0x70(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xed60
movq -0x118(%rbp), %rdi
movslq (%rax), %rsi
callq 0x59c60
movq %rax, -0x110(%rbp)
jmp 0x84095
movq -0x110(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x842a8
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movslq -0x8c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xed60
movq -0x128(%rbp), %rdi
movslq (%rax), %rsi
callq 0x59c60
movq %rax, -0x120(%rbp)
jmp 0x84104
movq -0x120(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0xa0(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x130(%rbp)
jmp 0x84142
movq -0x130(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x148(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x140(%rbp)
jmp 0x8416f
movq -0x140(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x158(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x150(%rbp)
jmp 0x8419c
movq -0x150(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x160(%rbp)
jmp 0x841c6
movq -0x160(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
leaq -0xb0(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x170(%rbp)
jmp 0x841f3
movq -0x170(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
leaq -0xb0(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x180(%rbp)
jmp 0x84220
movsd -0x188(%rbp), %xmm4
movsd -0x178(%rbp), %xmm3
movsd -0x168(%rbp), %xmm2
movsd -0x158(%rbp), %xmm1
movsd -0x148(%rbp), %xmm0
movq -0x138(%rbp), %rdi
movq -0x180(%rbp), %rax
movsd (%rax), %xmm5
callq 0x97720
movsd %xmm0, -0x190(%rbp)
jmp 0x84269
movsd -0x190(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x840c2
jmp 0x842aa
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x84059
cvtsi2sdl -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x845a3
movq -0x10(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movslq -0xbc(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xed60
movq -0x1a0(%rbp), %rdi
movslq (%rax), %rsi
callq 0x59c60
movq %rax, -0x198(%rbp)
jmp 0x84317
movq -0x198(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xd8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xd0(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0xc8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xe0(%rbp)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x8455e
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movslq -0xe4(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xed60
movq -0x1b0(%rbp), %rdi
movslq (%rax), %rsi
callq 0x59c60
movq %rax, -0x1a8(%rbp)
jmp 0x8439a
movq -0x1a8(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0xf0(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x100(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x1b8(%rbp)
jmp 0x843d8
movq -0x1b8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1d0(%rbp)
leaq -0xd8(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x1c8(%rbp)
jmp 0x84405
movq -0x1c8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1e0(%rbp)
leaq -0xd8(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x1d8(%rbp)
jmp 0x84432
movq -0x1d8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1f0(%rbp)
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x1e8(%rbp)
jmp 0x8445c
movq -0x1e8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x200(%rbp)
leaq -0x100(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x1f8(%rbp)
jmp 0x84489
movq -0x1f8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x210(%rbp)
leaq -0x100(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x208(%rbp)
jmp 0x844b6
movsd -0x210(%rbp), %xmm4
movsd -0x200(%rbp), %xmm3
movsd -0x1f0(%rbp), %xmm2
movsd -0x1e0(%rbp), %xmm1
movsd -0x1d0(%rbp), %xmm0
movq -0x1c0(%rbp), %rdi
movq -0x208(%rbp), %rax
movsd (%rax), %xmm5
callq 0x97720
movsd %xmm0, -0x218(%rbp)
jmp 0x844ff
movsd -0x218(%rbp), %xmm0
movsd %xmm0, -0x108(%rbp)
movsd 0x16e261(%rip), %xmm0   # 0x1f2778
mulsd -0x108(%rbp), %xmm0
mulsd -0x108(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
mulsd -0x20(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x5930
addsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x84358
movsd -0xe0(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
ja 0x84577
xorps %xmm0, %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x8458d
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x8458f
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x842d5
leaq -0x58(%rbp), %rdi
callq 0xec80
movl -0x14(%rbp), %eax
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x58f0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)