// File: 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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movsd %xmm2, -0x20(%rbp)
movsd %xmm3, -0x28(%rbp)
movsd %xmm4, -0x30(%rbp)
movsd %xmm5, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x130(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x11aa20(%rip), %xmm0   # 0x1f2078
movsd %xmm0, -0x88(%rbp)
movsd 0x11aa10(%rip), %xmm0   # 0x1f2078
movsd %xmm0, -0x90(%rbp)
movsd 0x11aa00(%rip), %xmm0   # 0x1f2078
movsd %xmm0, -0x98(%rbp)
movsd -0x70(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x78(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x80(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
addsd -0x98(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xa0(%rbp), %xmm0
callq 0xe9290
movsd %xmm0, -0xb8(%rbp)
movsd -0xa8(%rbp), %xmm0
callq 0xe9290
movsd %xmm0, -0xc0(%rbp)
movsd -0xb0(%rbp), %xmm0
callq 0xe9290
movsd %xmm0, -0xc8(%rbp)
movsd 0x11ec33(%rip), %xmm0   # 0x1f6348
movsd %xmm0, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movq -0x130(%rbp), %rdi
movl -0xd4(%rbp), %eax
movq %rax, -0x138(%rbp)
callq 0x10090
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
jae 0xd7962
movq -0x130(%rbp), %rdi
movl -0xd4(%rbp), %eax
movl %eax, %esi
callq 0xed60
movq -0x130(%rbp), %rdi
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0xe0(%rbp)
addq $0x18, %rdi
movl -0xd4(%rbp), %eax
movl %eax, %esi
callq 0xed60
movq -0x130(%rbp), %rdi
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0xe8(%rbp)
addq $0x30, %rdi
movl -0xd4(%rbp), %eax
movl %eax, %esi
callq 0xed60
movq -0x130(%rbp), %rdi
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0x88(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm1
addsd -0xe0(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0x90(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
addsd -0xe8(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
movsd -0x98(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
addsd -0xf0(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd -0x100(%rbp), %xmm1
movsd -0x108(%rbp), %xmm2
leaq -0x110(%rbp), %rsi
leaq -0x118(%rbp), %rdx
leaq -0x120(%rbp), %rcx
callq 0xd72e0
movsd -0x110(%rbp), %xmm1
movsd -0x110(%rbp), %xmm2
movsd -0x118(%rbp), %xmm0
mulsd -0x118(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x120(%rbp), %xmm0
movsd -0x120(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x53f0
movsd %xmm0, -0x128(%rbp)
movsd -0x128(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xd794c
movsd -0x128(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xf8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x100(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x108(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0xd794e
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0xd7727
movsd -0xd0(%rbp), %xmm0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)