// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/screened_interactions.c
// Function: Axis_distance_S
int Axis_distance_S(float *d2_nb, float *d2_bo, float S_NB, float S_BO,
		    struct store *store1, float d2_ij,
		    atom *atom_i, atom *atom_j, atom *atoms)
{
  int resi=atom_i->res, resj=atom_j->res;
  float d2, d2_jk, d2_k, d2_c, S, S2;
  float S2_NB=S_NB*S_NB;
  float S2_BO=S_BO*S_BO;
  float S4_NB=4*S2_NB;
  float S4_BO=4*S2_BO;
  float d_ij=sqrt(d2_ij);
  while(store1 != NULL){
    if(store1->x > d2_ij)break;
    atom *atom_k=atoms+store1->i;
    if(atom_k!=atom_j){
      d2_jk=Dist2(atom_j->r, atom_k->r);
      if(d2_jk >= d2_ij)goto next2;
      if(d2_jk > store1->x){
	d2_k=d2_jk;
	d2_c=Scalar(atom_j->r, atom_i->r, atom_k->r);
      }else{
	d2_k=store1->x;
	d2_c=Scalar(atom_i->r, atom_j->r, atom_k->r);
      }
      d2=d2_k-d2_c*d2_c/d2_ij;
      // d2 is the squared distance between atom k and the axis ij
      if(d2 > S4_NB)goto next2; // No screening if d > 2*S
      int bond=Bond(atom_k->res, resi, store1->x, resj, d2_jk);
      if(bond){
	if(d2 > S4_BO)goto next2;
	if(d2 < S2_BO){*d2_bo=0; return(1);} // There is shadow on the axis
	S=S_BO; S2=S2_BO;
      }else{
	if(d2 < S2_NB){*d2_nb=0; return(1);}
	S=S_NB; S2=S2_NB;
      }
      float ang=asin(sqrt(d2/d2_k)); if(ang<0)ang=-ang;
      float ang1=asin(S/d_ij); if(ang1<0)ang1=-ang1;
      float ang2=ang-ang1, s2;
      if(ang2<=0){*d2_nb=0; return(1);}
      else{s2=sin(ang2); s2*=s2;} // s2=sin(ang2)^2
      if(d2_jk > store1->x){d2=s2*d2_jk;}
      else{d2=s2*store1->x;}
      if(d2<S2){*d2_nb=0; return(1);}

      /*float d2_ic=d2_k-d2;       // Sq. dist. from atom i to projection of k
      // Sq. distance from bottom of atom k to axis
      if(bond){d2=(d2+S2_BO-2*S_BO*sqrt(d2));}
      else{d2=(d2+S2_NB-2*S_NB*sqrt(d2));}
      float d2a_ij=d2*d2_ij/d2_ic; // Sq. dist. from shadow to axis at j
      if(bond){if(d2a_ij < *d2_bo)*d2_bo=d2a_ij;}
      else{if(d2a_ij < *d2_nb)*d2_nb=d2a_ij;}*/
    }
  next2:
    store1=store1->next;
  }
  return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %r13
movq %rdi, 0x20(%rsp)
movl 0x64(%rcx), %eax
movl %eax, 0x38(%rsp)
movl 0x64(%r8), %ebx
movss %xmm0, 0x30(%rsp)
mulss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
movss %xmm1, 0x2c(%rsp)
mulss %xmm1, %xmm1
movss %xmm1, 0x18(%rsp)
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
movss %xmm2, 0x4(%rsp)
movq %rsi, 0x50(%rsp)
jb 0x1e7d3
sqrtss %xmm2, %xmm0
jmp 0x1e7e1
movaps %xmm2, %xmm0
callq 0x21c0
movss 0x4(%rsp), %xmm2
movss %xmm0, 0x14(%rsp)
movss 0x1c(%rsp), %xmm1
movss 0x32603(%rip), %xmm0    # 0x50df8
mulss %xmm0, %xmm1
movss %xmm1, 0x3c(%rsp)
mulss 0x18(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
xorl %eax, %eax
testq %r13, %r13
je 0x1e9fb
movss 0x4(%r13), %xmm0
ucomiss %xmm2, %xmm0
ja 0x1e9fb
movslq (%r13), %rax
imulq $0x70, %rax, %rbp
addq %r14, %rbp
cmpq %r15, %rbp
je 0x1e9e7
movq %r15, %rdi
movq %rbp, %rsi
movss %xmm0, 0x8(%rsp)
callq 0x1eb16
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
ucomiss %xmm2, %xmm0
jae 0x1e9e7
ucomiss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
jbe 0x1e889
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x1eb4b
movss 0x10(%rsp), %xmm1
movaps %xmm1, %xmm4
movss 0x8(%rsp), %xmm3
jmp 0x1e8a6
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x1eb4b
movss 0x8(%rsp), %xmm3
movaps %xmm3, %xmm4
movss 0x10(%rsp), %xmm1
mulss %xmm0, %xmm0
movss 0x4(%rsp), %xmm2
divss %xmm2, %xmm0
movaps %xmm4, %xmm5
subss %xmm0, %xmm5
ucomiss 0x3c(%rsp), %xmm5
ja 0x1e9e7
movss %xmm5, 0xc(%rsp)
movss %xmm4, 0x40(%rsp)
movl 0x64(%rbp), %edi
movl 0x38(%rsp), %esi
movaps %xmm3, %xmm0
movl %ebx, %edx
callq 0x173fa
testl %eax, %eax
je 0x1e91a
movss 0xc(%rsp), %xmm3
ucomiss 0x34(%rsp), %xmm3
movss 0x4(%rsp), %xmm2
movss 0x40(%rsp), %xmm1
ja 0x1e9e7
movss 0x18(%rsp), %xmm0
ucomiss %xmm3, %xmm0
movss 0x2c(%rsp), %xmm2
jbe 0x1e93b
jmp 0x1ea0a
movss 0x1c(%rsp), %xmm0
movss 0xc(%rsp), %xmm3
ucomiss %xmm3, %xmm0
movss 0x30(%rsp), %xmm2
movss 0x40(%rsp), %xmm1
ja 0x1e9f0
movss %xmm2, 0x8(%rsp)
movss %xmm0, 0xc(%rsp)
divss %xmm1, %xmm3
cvtss2sd %xmm3, %xmm0
ucomisd 0x2c6f9(%rip), %xmm0    # 0x4b050
jb 0x1e95f
sqrtsd %xmm0, %xmm0
jmp 0x1e964
callq 0x2290
callq 0x2250
movaps %xmm0, 0x40(%rsp)
movss 0x8(%rsp), %xmm0
divss 0x14(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x2250
movaps 0x40(%rsp), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
cvtpd2ps %xmm1, %xmm1
movapd %xmm1, %xmm0
xorpd 0x31ec5(%rip), %xmm0    # 0x50860
maxps %xmm1, %xmm0
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
subss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jae 0x1e9f0
cvtss2sd %xmm0, %xmm0
callq 0x2220
cvtsd2ss %xmm0, %xmm0
mulss %xmm0, %xmm0
movss 0x4(%r13), %xmm1
movss 0x10(%rsp), %xmm2
maxss %xmm1, %xmm2
mulss %xmm0, %xmm2
movss 0xc(%rsp), %xmm0
ucomiss %xmm2, %xmm0
movss 0x4(%rsp), %xmm2
ja 0x1e9f0
movq 0x8(%r13), %r13
jmp 0x1e80b
movq 0x20(%rsp), %rax
andl $0x0, (%rax)
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %rax
jmp 0x1e9f5