// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/buildup.c
// Function: Compare_build_up
void Compare_build_up(struct bond *bonds, int N_atoms,
		      double *d_phi, int N_axes,
		      struct bond *bonds2)
{
  struct bond *bond, *previous; int i, j, error=0;
  double dr_dr;

  printf("Testing differences atom by atom\n");

  for(i=0; i<N_atoms; i++){
    bond=bonds+i;
    if(bond->i_atom<0)break;
    previous=bond->previous;
    if((previous==NULL)||(previous->previous==NULL)||
       (previous->previous->previous==NULL)){
      if(bonds2){
	for(j=0; j<3; j++){
	  bond->r[j]=bonds2[i].r[j];
	  bond->dr[j]=bonds2[i].dr[j];
	  bond->dz[j]=bonds2[i].dz[j];
	}
      }
      if(previous){
	goto test;
      }else{
	continue;
      }
    }
    if((d_phi)&&(bond->len >= 0)){
      double factor=1.+d_phi[bond->len]/bond->l; //
      if(factor <= 0.1){
	printf("WARNING, bond length too short with buildup! ");
	printf("atoms: %s%d%c  %s%d%c f= %.2g\n",
	       bond->atom->name, bond->atom->res, bond->atom->aa,
	       bond->previous->atom->name, bond->previous->atom->res,
	       bond->previous->atom->aa, factor);
	factor=0.1;
	printf("Setting shrink factor to %.2g\n", factor);
      }
      bond->l*=factor;
      bond->r_cos_theta*=factor;
    }
    double r_sin_theta=
      sqrt(bond->l*bond->l-bond->r_cos_theta*bond->r_cos_theta);
    if((d_phi)&&(bond->angle >= 0)){
      double cos_a=cos(d_phi[bond->angle]);
      double sin_a=-sin(d_phi[bond->angle]);
      bond->r_cos_theta=bond->r_cos_theta*cos_a-r_sin_theta*sin_a;
      r_sin_theta=
	sqrt(bond->l*bond->l-bond->r_cos_theta*bond->r_cos_theta);
    }
    if((d_phi)&&(bond->torsion >= 0)){
      bond->phi += d_phi[bond->torsion];
    }
    double ax= r_sin_theta*cos(bond->phi);
    double ay= r_sin_theta*sin(bond->phi);
    double az= -bond->r_cos_theta;

    for(j=0; j<3; j++){
      double dr=
	az*previous->dz[j]+
	ax*previous->dx[j]+
	ay*previous->dy[j];
      bond->dr[j]=dr;
      bond->r[j]=previous->r[j]+dr;
    }

  test:
    
    dr_dr=Scalar_product_3_d(bond->dr, bond->dr);
    bond->l=sqrt(dr_dr);
    for(j=0; j<3; j++){
      bond->dz[j]=bond->dr[j]/bond->l;
    }

    // Make new orthogonal frame
    if(bond->terminal==0)Make_frame(bond, previous, previous->dz);

    if(bond->atom->main==0)continue;
    if(bonds2){
      double d2=0;
      for(j=0; j<3; j++){
	double d=bond->r[j]-bonds2[i].r[j]; d2+=d*d;
      }
      if(d2>0.005){
	printf("ERROR in Compare_build_up, bond %d atom %s %c%d chain %d",
	       i, bond->atom->name, bond->atom->aa, bond->atom->res,
	       bond->atom->chain);
	printf("d=%.4g\n", sqrt(d2));
	if(bond->len>=0)
	  printf("Len: %.2f %d\n", d_phi[bond->len], bond->len);
	if(bond->angle>=0)
	  printf("Angle: %.2f %d\n", d_phi[bond->angle], bond->angle);
	if(bond->torsion>=0)
	  printf("Torsion: %.2f %d\n", d_phi[bond->torsion], bond->torsion);
	error++; exit(8);
      }
    }

  }
  if(error)exit(8);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
leaq 0x5e20b(%rip), %rdi     # 0x7bc96
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x1e1c5
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jge 0x1daca
jmp 0x1e1c5
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1dafb
movq -0x38(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x1dafb
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x28(%rax)
jne 0x1dbbc
cmpq $0x0, -0x28(%rbp)
je 0x1dbab
movl $0x0, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jge 0x1dba9
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movsd 0x40(%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, 0x40(%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movsd 0xa8(%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, 0xa8(%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1db0d
jmp 0x1dbab
cmpq $0x0, -0x38(%rbp)
je 0x1dbb7
jmp 0x1df75
jmp 0x1e1b7
cmpq $0x0, -0x18(%rbp)
je 0x1dcca
movq -0x30(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jl 0x1dcca
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x34(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x30(%rbp), %rax
divsd 0x58(%rax), %xmm1
movsd 0x58451(%rip), %xmm0    # 0x76048
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x58418(%rip), %xmm0    # 0x76020
ucomisd -0x58(%rbp), %xmm0
jb 0x1dca4
leaq 0x5df2e(%rip), %rdi     # 0x7bb48
movb $0x0, %al
callq 0x10d0
movq -0x30(%rbp), %rax
movq (%rax), %rsi
addq $0x18, %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %edx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %ecx
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %r8
addq $0x18, %r8
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movl 0x64(%rax), %r9d
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %eax
movsd -0x58(%rbp), %xmm0
leaq 0x5defc(%rip), %rdi     # 0x7bb76
movl %eax, (%rsp)
movb $0x1, %al
callq 0x10d0
movsd 0x58394(%rip), %xmm0    # 0x76020
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
leaq 0x5def8(%rip), %rdi     # 0x7bb95
movb $0x1, %al
callq 0x10d0
movsd -0x58(%rbp), %xmm0
movq -0x30(%rbp), %rax
mulsd 0x58(%rax), %xmm0
movsd %xmm0, 0x58(%rax)
movsd -0x58(%rbp), %xmm0
movq -0x30(%rbp), %rax
mulsd 0x60(%rax), %xmm0
movsd %xmm0, 0x60(%rax)
movq -0x30(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd 0x58(%rax), %xmm2
movq -0x30(%rbp), %rax
movsd 0x60(%rax), %xmm1
movq -0x30(%rbp), %rax
mulsd 0x60(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1220
movsd %xmm0, -0x60(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1de0a
movq -0x30(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0x1de0a
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x1100
movsd %xmm0, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x11c0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x30(%rbp), %rax
movsd 0x60(%rax), %xmm0
movsd -0x68(%rbp), %xmm2
movsd -0x60(%rbp), %xmm1
mulsd -0x70(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x60(%rax)
movq -0x30(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd 0x58(%rax), %xmm2
movq -0x30(%rbp), %rax
movsd 0x60(%rax), %xmm1
movq -0x30(%rbp), %rax
mulsd 0x60(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1220
movsd %xmm0, -0x60(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1de3a
movq -0x30(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
jl 0x1de3a
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x3c(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
addsd 0x68(%rax), %xmm0
movsd %xmm0, 0x68(%rax)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movsd 0x68(%rax), %xmm0
callq 0x1100
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movsd 0x68(%rax), %xmm0
callq 0x11c0
movaps %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x30(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x88(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jge 0x1df73
movsd -0x88(%rbp), %xmm1
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd 0xa8(%rax,%rcx,8), %xmm2
movsd -0x78(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
mulsd 0x90(%rax,%rcx,8), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd 0x78(%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, 0x40(%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm0
addsd -0x90(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1dec7
jmp 0x1df75
movq -0x30(%rbp), %rdi
addq $0x40, %rdi
movq -0x30(%rbp), %rsi
addq $0x40, %rsi
callq 0x14c00
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x1220
movq -0x30(%rbp), %rax
movsd %xmm0, 0x58(%rax)
movl $0x0, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jge 0x1dfe2
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd 0x40(%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
divsd 0x58(%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, 0xa8(%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1dfa9
movq -0x30(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x1e004
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0xa8, %rdx
callq 0x1d700
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x48(%rax)
jne 0x1e016
jmp 0x1e1b7
cmpq $0x0, -0x28(%rbp)
je 0x1e1b5
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jge 0x1e09e
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
subsd 0x8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1e033
movsd -0x98(%rbp), %xmm0
movsd 0x5d9d2(%rip), %xmm1    # 0x7ba80
ucomisd %xmm1, %xmm0
jbe 0x1e1b3
movl -0x3c(%rbp), %esi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
addq $0x18, %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %ecx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %r8d
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x6c(%rax), %r9d
leaq 0x5dbca(%rip), %rdi     # 0x7bcb8
movb $0x0, %al
callq 0x10d0
movsd -0x98(%rbp), %xmm0
callq 0x1220
leaq 0x5dbe8(%rip), %rdi     # 0x7bcf1
movb $0x1, %al
callq 0x10d0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jl 0x1e140
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x34(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movl 0x34(%rax), %esi
leaq 0x5dbc0(%rip), %rdi     # 0x7bcf9
movb $0x1, %al
callq 0x10d0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0x1e170
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movl 0x38(%rax), %esi
leaq 0x5db9e(%rip), %rdi     # 0x7bd07
movb $0x1, %al
callq 0x10d0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
jl 0x1e1a0
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0x3c(%rcx), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movl 0x3c(%rax), %esi
leaq 0x5db7e(%rip), %rdi     # 0x7bd17
movb $0x1, %al
callq 0x10d0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x8, %edi
callq 0x1210
jmp 0x1e1b5
jmp 0x1e1b7
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1da99
cmpl $0x0, -0x44(%rbp)
je 0x1e1d5
movl $0x8, %edi
callq 0x1210
addq $0xc0, %rsp
popq %rbp
retq
nop