// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/mindist.cc
// Function: MIN_PER_DISTANCE::minimum_periodic_distance(double, double, double, double, double, double, double&, double&, double&)
double MIN_PER_DISTANCE::minimum_periodic_distance(double a1, double b1, double c1, double a2, double b2, double c2, double &minDa, double &minDb, double &minDc){
  double va_a = a1, va_b = b1, va_c = c1;
  double vb_a = a2, vb_b = b2, vb_c = c2;
  double vc_a = 0.5, vc_b = 0.5, vc_c = 0.5;
  
  double vd_a = vb_a - va_a + vc_a;
  double vd_b = vb_b - va_b + vc_b;
  double vd_c = vb_c - va_c + vc_c;
  double ve_a = trans_to_origuc(vd_a);
  double ve_b = trans_to_origuc(vd_b);
  double ve_c = trans_to_origuc(vd_c);
  
  double minDist = DBL_MAX;
  
  for(unsigned int index = 0; index < ivals.size(); index++){
    double vi_a = ivals[index], vi_b = jvals[index], vi_c = kvals[index];
    double da = vc_a - (ve_a+vi_a);
    double db = vc_b - (ve_b+vi_b);
    double dc = vc_c - (ve_c+vi_c);
    double dx, dy, dz;
    abc_to_xyz(da, db, dc, dx, dy, dz);
    //cout << "a: " << da << "   b: " << db << "    c: " << dc << endl;
    //cout << "x: " << dx << "   y: " << dy << "    z: " << dz << endl;
    double dist = sqrt(dx*dx + dy*dy + dz*dz);
    if(dist < minDist){
      minDist = dist;
      minDa = -da; minDb = -db; minDc = -dc;
    }
  }
  //cout << "minDist here: " << minDist << endl;
  return minDist;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
subsd %xmm0, %xmm3
movsd 0xd5403(%rip), %xmm0    # 0x14d038
addsd %xmm0, %xmm3
subsd %xmm1, %xmm4
addsd %xmm0, %xmm4
movsd %xmm4, (%rsp)
subsd %xmm2, %xmm5
addsd %xmm0, %xmm5
movsd %xmm5, 0x10(%rsp)
movapd %xmm3, %xmm0
callq 0x839b6
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x839b6
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x839b6
movq (%r12), %rax
movq 0x8(%r12), %rcx
subq %rax, %rcx
je 0x77da8
sarq $0x2, %rcx
movq 0x18(%r12), %rdx
movq 0x30(%r12), %rsi
movsd 0xdaad3(%rip), %xmm1    # 0x152778
xorl %edi, %edi
movapd 0xd9991(%rip), %xmm2    # 0x151640
movsd 0xd5380(%rip), %xmm9    # 0x14d038
movsd 0x8(%rsp), %xmm10
movsd (%rsp), %xmm11
xorps %xmm4, %xmm4
cvtsi2sdl (%rax,%rdi,4), %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl (%rdx,%rdi,4), %xmm5
xorps %xmm6, %xmm6
cvtsi2sdl (%rsi,%rdi,4), %xmm6
addsd %xmm10, %xmm4
movapd %xmm9, %xmm3
subsd %xmm4, %xmm3
addsd %xmm11, %xmm5
movapd %xmm9, %xmm4
subsd %xmm5, %xmm4
addsd %xmm0, %xmm6
movapd %xmm9, %xmm5
subsd %xmm6, %xmm5
movsd 0x50(%r12), %xmm6
mulsd %xmm4, %xmm6
movsd 0x48(%r12), %xmm7
mulsd %xmm3, %xmm7
addsd %xmm6, %xmm7
movsd 0x60(%r12), %xmm6
mulsd %xmm5, %xmm6
addsd %xmm7, %xmm6
movsd 0x68(%r12), %xmm7
mulsd %xmm5, %xmm7
movsd 0x58(%r12), %xmm8
mulsd %xmm4, %xmm8
addsd %xmm7, %xmm8
movsd 0x70(%r12), %xmm7
mulsd %xmm5, %xmm7
mulsd %xmm8, %xmm8
mulsd %xmm6, %xmm6
addsd %xmm8, %xmm6
mulsd %xmm7, %xmm7
addsd %xmm6, %xmm7
xorps %xmm6, %xmm6
sqrtsd %xmm7, %xmm6
ucomisd %xmm6, %xmm1
jbe 0x77d97
xorpd %xmm2, %xmm3
movlpd %xmm3, (%r15)
xorpd %xmm2, %xmm4
movlpd %xmm4, (%r14)
xorpd %xmm2, %xmm5
movlpd %xmm5, (%rbx)
movapd %xmm6, %xmm1
incq %rdi
movl %edi, %r8d
cmpq %r8, %rcx
ja 0x77cc5
jmp 0x77db0
movsd 0xda9c8(%rip), %xmm1    # 0x152778
movapd %xmm1, %xmm0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq