// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movsd 0xa8(%rax), %xmm1
movq -0x20(%rbp), %rax
movsd (%rax), %xmm2
movq -0x10(%rbp), %rax
movsd 0xb0(%rax), %xmm0
movq -0x20(%rbp), %rax
mulsd 0x8(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
movsd 0xb8(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x1d807
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd -0x28(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd 0xa8(%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, 0x90(%rax,%rcx,8)
movsd -0x40(%rbp), %xmm0
movsd -0x40(%rbp), %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d776
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1d86c
movsd -0x30(%rbp), %xmm0
callq 0x1220
movaps %xmm0, %xmm1
movsd 0x5881e(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x1d86a
movsd -0x30(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
mulsd 0x90(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x90(%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d83a
jmp 0x1d8c7
cmpq $0x0, -0x18(%rbp)
jne 0x1d88b
leaq 0x5e566(%rip), %rdi     # 0x7bde0
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x1d8c5
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd 0x90(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, 0x90(%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d892
jmp 0x1d8c7
movq -0x10(%rbp), %rdi
addq $0x78, %rdi
movq -0x10(%rbp), %rsi
addq $0xa8, %rsi
movq -0x10(%rbp), %rdx
addq $0x90, %rdx
callq 0x14aa0
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x1d938
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd 0x78(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd 0x78(%rax,%rcx,8), %xmm2
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d8f9
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1d99a
movsd -0x30(%rbp), %xmm0
callq 0x1220
movaps %xmm0, %xmm1
movsd 0x586ed(%rip), %xmm0    # 0x76048
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x1d995
movsd -0x30(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
mulsd 0x78(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x78(%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1d96b
jmp 0x1da43
movsd -0x30(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x18, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %edx
movq -0x10(%rbp), %rax
movsd 0x78(%rax), %xmm1
movq -0x10(%rbp), %rax
movsd 0x80(%rax), %xmm2
movq -0x10(%rbp), %rax
movsd 0x88(%rax), %xmm3
movq -0x10(%rbp), %rax
movsd 0x90(%rax), %xmm4
movq -0x10(%rbp), %rax
movsd 0x98(%rax), %xmm5
movq -0x10(%rbp), %rax
movsd 0xa0(%rax), %xmm6
movq -0x10(%rbp), %rax
movsd 0xa8(%rax), %xmm7
movq -0x10(%rbp), %rax
movsd 0xb0(%rax), %xmm9
movq -0x10(%rbp), %rax
movsd 0xb8(%rax), %xmm8
leaq 0x5e3d2(%rip), %rdi     # 0x7bdf8
movsd %xmm9, (%rsp)
movsd %xmm8, 0x8(%rsp)
movb $0x8, %al
callq 0x10d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1da4a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)