// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/buildup.c
// Function: Make_frame
int Make_frame(struct bond *bond, struct bond *previous, double *pz)
{
  double dr_dr1=
    bond->dz[0]*pz[0]+bond->dz[1]*pz[1]+bond->dz[2]*pz[2];

  double norm=0; int j;
  for(j=0; j<3; j++){
    double dx=-pz[j]+dr_dr1*bond->dz[j]; // Standard definition
    //double dx=pz[j]-dr_dr1*bond->dz[j];
    bond->dx[j]=dx; norm+=dx*dx;
  }
  if(norm>0){ 
    norm=1./sqrt(norm);
    for(j=0; j<3; j++)bond->dx[j]*=norm;
  }else{  // Collinear bonds, theta=0 or pi. Use previous axis
    //double dx3[3]; for(j=0; j<3; j++)dx3[j]=bond->dx[j];
    if(previous==NULL){printf("ERROR no previous bond\n"); exit(8);}
    for(j=0; j<3; j++)bond->dx[j]=previous->dx[j];
  } 
  
  Vector_product_d(bond->dy, bond->dz, bond->dx);
  norm=0; for(j=0; j<3; j++)norm+=bond->dy[j]*bond->dy[j];
  if(norm>0){
    norm= 1./sqrt(norm);
    for(j=0; j<3; j++)bond->dy[j]*=norm;
  }else{
    printf("ERROR in Make_frame norm_y= %.2g atom= %s res=%d\n"
	   "dy=%.2g %.2g %.2g dx= %.2g %.2g %.2g dz= %.2g %.2g %.2g\n",
	   norm, bond->atom->name, bond->atom->res,
	   bond->dy[0], bond->dy[1], bond->dy[2],
	   bond->dx[0], bond->dx[1], bond->dx[2],
	   bond->dz[0], bond->dz[1], bond->dz[2]);
    return(-1);
  }
  return(0);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0xa8(%rdi), %r14
movsd 0xa8(%rdi), %xmm0
movsd 0xb0(%rdi), %xmm1
mulsd 0x8(%rdx), %xmm1
mulsd (%rdx), %xmm0
addsd %xmm1, %xmm0
movsd 0xb8(%rdi), %xmm1
mulsd 0x10(%rdx), %xmm1
addsd %xmm0, %xmm1
leaq 0x90(%rdi), %r15
xorpd %xmm0, %xmm0
pushq $0x12
popq %rax
cmpq $0x15, %rax
je 0x14eb7
movsd 0x18(%rbx,%rax,8), %xmm2
mulsd %xmm1, %xmm2
subsd -0x90(%rdx,%rax,8), %xmm2
movsd %xmm2, (%rbx,%rax,8)
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rax
jmp 0x14e8c
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14ec9
jb 0x14eee
sqrtsd %xmm0, %xmm0
jmp 0x14ef3
testq %rsi, %rsi
je 0x14ff8
xorl %eax, %eax
cmpq $0x3, %rax
je 0x14f1c
movsd 0x90(%rsi,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x14ed4
callq 0x2290
movsd 0x3614d(%rip), %xmm1    # 0x4b048
divsd %xmm0, %xmm1
xorl %eax, %eax
cmpq $0x3, %rax
je 0x14f1c
movsd (%r15,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x14f01
leaq 0x78(%rbx), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xf8f7
xorpd %xmm0, %xmm0
pushq $0xf
popq %rax
cmpq $0x12, %rax
je 0x14f4d
movsd (%rbx,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
jmp 0x14f35
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14f5f
jb 0x14fc8
sqrtsd %xmm0, %xmm0
jmp 0x14fcd
movq (%rbx), %rsi
movl 0x64(%rsi), %edx
addq $0x18, %rsi
movsd 0x78(%rbx), %xmm1
movsd 0x80(%rbx), %xmm2
movsd 0x88(%rbx), %xmm3
movsd 0x90(%rbx), %xmm4
movsd 0x98(%rbx), %xmm5
movsd 0xa0(%rbx), %xmm6
movsd 0xa8(%rbx), %xmm7
movups 0xb0(%rbx), %xmm8
movups %xmm8, (%rsp)
leaq 0x3bc33(%rip), %rdi     # 0x50be5
movb $0x8, %al
callq 0x20f0
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x2290
movsd 0x36073(%rip), %xmm1    # 0x4b048
divsd %xmm0, %xmm1
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x14fbc
movsd (%r12,%rcx,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rcx,8)
incq %rcx
jmp 0x14fdd
leaq 0x3bdbb(%rip), %rdi     # 0x50dba
callq 0x2090
pushq $0x8
popq %rdi
callq 0x2270