// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rsi, %rbx
movq 0x8(%rsi), %rax
subq (%rsi), %rax
movq %rdi, 0x68(%rsp)
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %esi # imm = 0xAAAAAAAB
testl %esi, %esi
jle 0x48efd
movl $0x3e8, %eax            # imm = 0x3E8
cmpl %eax, %esi
cmovll %esi, %eax
cvtsi2sd %esi, %xmm1
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movapd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
cmpl $0x2, %eax
movl $0x1, %ebp
movq %rax, 0x8(%rsp)
cmovgel %eax, %ebp
xorl %r14d, %r14d
leaq 0x70(%rsp), %r12
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd (%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x70(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x48a66
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x48a71
movq %r15, %rdi
movq %r12, %rdx
callq 0x1422c
incl %r14d
cmpl %r14d, %ebp
jne 0x48a38
movq 0x8(%rsp), %rax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, 0x30(%rsp)
movl %eax, %r13d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %edi, %edi
movl $0x1, %r14d
leaq 0x70(%rsp), %r15
leaq 0xb0(%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 0x48ee1
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x80(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0x70(%rsp)
incq %rdi
movq %r14, 0x90(%rsp)
movq %rdi, 0x38(%rsp)
cmpq %r13, %rdi
jae 0x48c29
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 0x48ec5
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0xc0(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0xb0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movq %r15, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm5
movq 0x68(%rsp), %rdi
movsd 0xa0(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
movsd 0x48(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
callq 0x5369a
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
incl %ebp
incq %r14
cmpq %r14, %r13
jne 0x48b14
movq 0x90(%rsp), %r14
incq %r14
movq 0x38(%rsp), %rdi
cmpq 0x30(%rsp), %rdi
jne 0x48ab1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, (%rsp)
movq 0x8(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovll %eax, %ecx
movq %rcx, 0x8(%rsp)
movsd 0x10a656(%rip), %xmm0   # 0x1532d0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, %eax
movq %rax, 0x60(%rsp)
xorl %ecx, %ecx
leaq 0x70(%rsp), %r15
leaq 0xb0(%rsp), %r12
movapd %xmm0, 0x90(%rsp)
movq 0x10(%rsp), %rax
movslq (%rax,%rcx,4), %rsi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq %rcx, %rdi
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x48eef
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x80(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0x70(%rsp)
movq %rdi, 0x30(%rsp)
leaq 0x1(%rdi), %rax
xorpd %xmm4, %xmm4
movq %rax, 0xd0(%rsp)
cmpq %r13, %rax
jae 0x48e45
movq 0x60(%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 0x48ed3
movapd %xmm4, 0xa0(%rsp)
leaq (%rsi,%rsi,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0xc0(%rsp)
movupd (%rax,%rcx,8), %xmm0
movapd %xmm0, 0xb0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r15, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm5
movq 0x68(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
callq 0x5369a
movapd %xmm0, %xmm1
xorpd 0x10a796(%rip), %xmm1   # 0x1535b0
mulsd %xmm0, %xmm1
divsd (%rsp), %xmm1
movapd %xmm1, %xmm0
callq 0x47b0
movapd 0xa0(%rsp), %xmm4
addsd %xmm0, %xmm4
incq %rbp
cmpq %rbp, %r13
jne 0x48d12
movapd 0x90(%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 0x48e74
movapd %xmm3, %xmm4
cmovnel 0x30(%rsp), %r14d
incq 0x60(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, %rcx
movapd %xmm4, %xmm0
cmpq 0x8(%rsp), %rax
jne 0x48c99
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x48eb0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl %r14d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1067d9(%rip), %rdi    # 0x14f6a5
xorl %eax, %eax
callq 0x4630
leaq 0x1067cb(%rip), %rdi    # 0x14f6a5
xorl %eax, %eax
callq 0x4630
leaq 0x1067bd(%rip), %rdi    # 0x14f6a5
xorl %eax, %eax
callq 0x4630
leaq 0x1067af(%rip), %rdi    # 0x14f6a5
xorl %eax, %eax
callq 0x4630
leaq 0x10b0eb(%rip), %rdi    # 0x153fef
xorl %eax, %eax
callq 0x4060
movl $0x1, %edi
callq 0x710c
jmp 0x48f21
jmp 0x48f21
jmp 0x48f21
jmp 0x48f21
jmp 0x48f21
jmp 0x48f21
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x48f3b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780
nop