// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
subsd %xmm0, %xmm3
movsd 0xd6514(%rip), %xmm0    # 0x14f038
addsd %xmm0, %xmm3
subsd %xmm1, %xmm4
addsd %xmm0, %xmm4
movsd %xmm4, 0x8(%rsp)
subsd %xmm2, %xmm5
addsd %xmm0, %xmm5
movsd %xmm5, (%rsp)
movapd %xmm3, %xmm0
callq 0x84e6b
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x84e6b
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x84e6b
movq (%r12), %rax
cmpq %rax, 0x8(%r12)
je 0x78ce4
movapd %xmm0, %xmm4
movsd 0xdbb48(%rip), %xmm6    # 0x1546d0
movl $0x1, %ebp
xorl %ecx, %ecx
xorpd %xmm5, %xmm5
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rcx,4), %xmm0
movq 0x18(%r12), %rax
movq 0x30(%r12), %rdx
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%rcx,4), %xmm1
xorps %xmm2, %xmm2
cvtsi2sdl (%rdx,%rcx,4), %xmm2
addsd 0x18(%rsp), %xmm0
movsd 0xd646f(%rip), %xmm3    # 0x14f038
movapd %xmm3, %xmm7
subsd %xmm0, %xmm7
addsd 0x8(%rsp), %xmm1
movapd %xmm3, %xmm8
subsd %xmm1, %xmm8
addsd %xmm4, %xmm2
subsd %xmm2, %xmm3
movsd 0x50(%r12), %xmm0
mulsd %xmm8, %xmm0
movsd 0x48(%r12), %xmm1
mulsd %xmm7, %xmm1
addsd %xmm0, %xmm1
movsd 0x60(%r12), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x68(%r12), %xmm0
mulsd %xmm3, %xmm0
movsd 0x58(%r12), %xmm1
mulsd %xmm8, %xmm1
addsd %xmm0, %xmm1
movsd 0x70(%r12), %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm1, %xmm1
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm5, %xmm0
jb 0x78c59
sqrtsd %xmm0, %xmm0
jmp 0x78c98
movsd %xmm6, (%rsp)
movapd %xmm7, 0x40(%rsp)
movapd %xmm8, 0x30(%rsp)
movapd %xmm3, 0x20(%rsp)
callq 0x4350
movapd 0x20(%rsp), %xmm3
movapd 0x30(%rsp), %xmm8
movapd 0x40(%rsp), %xmm7
movsd (%rsp), %xmm6
xorpd %xmm5, %xmm5
movsd 0x10(%rsp), %xmm4
ucomisd %xmm0, %xmm6
jbe 0x78cc5
movapd 0xda90a(%rip), %xmm1    # 0x1535b0
xorpd %xmm1, %xmm7
movlpd %xmm7, (%r15)
xorpd %xmm1, %xmm8
movlpd %xmm8, (%r14)
xorpd %xmm1, %xmm3
movlpd %xmm3, (%rbx)
movapd %xmm0, %xmm6
movl %ebp, %ecx
movq (%r12), %rax
movq 0x8(%r12), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x78b99
jmp 0x78cec
movsd 0xdb9e4(%rip), %xmm6    # 0x1546d0
movapd %xmm6, %xmm0
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop