// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movq %rsi, %rbx
movq 0x8(%rsi), %rax
subq (%rsi), %rax
movq %rdi, 0x58(%rsp)
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %esi # imm = 0xAAAAAAAB
testl %esi, %esi
jle 0x48623
movl $0x3e8, %ebp            # imm = 0x3E8
cmpl %ebp, %esi
cmovbl %esi, %ebp
cvtsi2sd %esi, %xmm1
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movapd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
xorl %r14d, %r14d
leaq 0x60(%rsp), %r12
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x60(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x481b7
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x481c2
movq %r15, %rdi
movq %r12, %rdx
callq 0x14198
incl %r14d
cmpl %r14d, %ebp
jne 0x48188
movl %ebp, %r13d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %edi, %edi
movl $0x1, %r14d
leaq 0x60(%rsp), %r15
leaq 0xa0(%rsp), %r12
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movslq (%rax,%rdi,4), %rsi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x48607
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x70(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0x60(%rsp)
incq %rdi
movq %r14, 0x80(%rsp)
movq %rdi, 0x28(%rsp)
cmpq %r13, %rdi
jae 0x48365
movq 0x10(%rsp), %rax
movslq (%rax,%r14,4), %rsi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x485eb
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0xb0(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r15, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm5
movq 0x58(%rsp), %rdi
movsd 0x90(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
callq 0x5339c
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incl %ebp
incq %r14
cmpq %r14, %r13
jne 0x4824e
movq 0x80(%rsp), %r14
incq %r14
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
jne 0x481ee
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x108fbf(%rip), %xmm0   # 0x151360
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, %eax
movq %rax, 0x50(%rsp)
xorl %edi, %edi
leaq 0x60(%rsp), %r15
leaq 0xa0(%rsp), %r12
movapd %xmm0, 0x80(%rsp)
movq 0x10(%rsp), %rax
movslq (%rax,%rdi,4), %rsi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x48615
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x70(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0x60(%rsp)
movq %rdi, 0xc0(%rsp)
leaq 0x1(%rdi), %rax
xorpd %xmm4, %xmm4
movq %rax, 0xb8(%rsp)
cmpq %r13, %rax
jae 0x4856a
movq 0x50(%rsp), %rbp
movq 0x10(%rsp), %rax
movslq (%rax,%rbp,4), %rsi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x485f9
movapd %xmm4, 0x90(%rsp)
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0xb0(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm5
movq 0x58(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
callq 0x5339c
movapd %xmm0, %xmm1
xorpd 0x109102(%rip), %xmm1   # 0x151640
mulsd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm0
callq 0x47b0
movapd 0x90(%rsp), %xmm4
addsd %xmm0, %xmm4
incq %rbp
cmpq %rbp, %r13
jne 0x48436
movapd 0x80(%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 0x48599
movapd %xmm3, %xmm4
cmovnel 0xc0(%rsp), %r14d
incq 0x50(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, %rdi
movapd %xmm4, %xmm0
cmpq %r13, %rax
jne 0x483c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x485d6
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl %r14d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x105103(%rip), %rdi    # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x1050f5(%rip), %rdi    # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x1050e7(%rip), %rdi    # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x1050d9(%rip), %rdi    # 0x14d6f5
xorl %eax, %eax
callq 0x4630
leaq 0x109a75(%rip), %rdi    # 0x15209f
xorl %eax, %eax
callq 0x4060
movl $0x1, %edi
callq 0x72bc
jmp 0x48647
jmp 0x48647
jmp 0x48647
jmp 0x48647
jmp 0x48647
jmp 0x48647
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x48661
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780
nop