// File: /workspace/github_c_makefile_star2_O3/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
xorl %eax, %eax
movsd 0xa8(%rbx,%rax,8), %xmm2
mulsd %xmm1, %xmm2
subsd (%rdx,%rax,8), %xmm2
movsd %xmm2, 0x90(%rbx,%rax,8)
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rax
cmpq $0x3, %rax
jne 0x161e1
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1621f
jb 0x16244
sqrtsd %xmm0, %xmm0
jmp 0x16249
testq %rsi, %rsi
je 0x1634e
xorl %eax, %eax
movsd 0x90(%rsi,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x1622a
jmp 0x16270
callq 0x22a0
movsd 0x3aef7(%rip), %xmm1    # 0x51148
divsd %xmm0, %xmm1
xorl %eax, %eax
movsd (%r15,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
cmpq $0x3, %rax
jne 0x16257
leaq 0x78(%rbx), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x103bb
xorpd %xmm0, %xmm0
movl $0xf, %eax
movsd (%rbx,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq $0x12, %rax
jne 0x1628b
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x162b3
jb 0x16314
sqrtsd %xmm0, %xmm0
jmp 0x16319
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 0x4098f(%rip), %rdi     # 0x56c95
movb $0x8, %al
callq 0x20f0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x16342
callq 0x22a0
movsd 0x3ae27(%rip), %xmm1    # 0x51148
divsd %xmm0, %xmm1
xorl %eax, %eax
xorl %ecx, %ecx
movsd (%r12,%rcx,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rcx,8)
incq %rcx
cmpq $0x3, %rcx
jne 0x16329
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x40b15(%rip), %rdi     # 0x56e6a
callq 0x2090
movl $0x8, %edi
callq 0x2280