// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/simulation.c
// Function: Change_internal
int Change_internal(double *diff_phi, int naxe,
		    struct bond *bonds, struct bond *bonds2,
		    int natoms, int type, int same)
{
  // type=0: only dofs active in the TNM. Write differences without changing.
  // type=1: change torsion 2: also change angles 3: also change length
  // Pseudo-bonds coordinates (disordered loops) are always changed
  // Same: bonds2 corresponds to same structure, without gaps

  if(diff_phi){
    for(int i=0; i<naxe; i++)diff_phi[i]=0;
  }else if(type==0){
    printf("WARNING in Change_internal, vector for writing differences ");
    printf("has not been provided\n"); return(-1);
  }

  struct bond *bond1=bonds, *b1, *bond2=bonds2; int n=0, m=0;
  for(int i=0; i<natoms; i++){
    bond1=bonds+i;
    if((same==0) && bond1->atom->ali<0)continue;
    //if(bond1->atom->main==0)continue;
    b1=bond1->previous;
    if(same){bond2=bonds2+i;}
    else{bond2=bonds2+bond1->atom->ali;}
    if(b1 && (same || b1->atom->ali>=0)){
      m++;
      if((type >= 3)||(bond1->len >=0)){ // bond length
	if(type){
	  bond1->l=bond2->l; n++;
	}else if(bond1->len >=0){
	  diff_phi[bond1->len]=bond2->l-bond1->l; n++;
	}
      }
      b1=b1->previous;
      if(b1 && (same || b1->atom->ali>=0)){
	m++;
	if((type >= 2)||(bond1->angle >=0)){   // bond angle
	  if(type){
	    bond1->r_cos_theta=bond2->r_cos_theta*(bond1->l/bond2->l);
	    n++;
	  }else if(bond1->angle >=0){
	    diff_phi[bond1->angle]=
	      acos(bond2->r_cos_theta/bond2->l)-
	      acos(bond1->r_cos_theta/bond1->l);
	    n++;
	  }
	}
	b1=b1->previous;
	if(b1 && (same || b1->atom->ali>=0)){
	  m++;
	  if((type)||(bond1->torsion >=0)){  // torsion angle
	    if(type){
	      bond1->phi=bond2->phi; n++;
	    }else if(bond1->torsion >=0){
	      diff_phi[bond1->torsion]=bond2->phi-bond1->phi; n++;
	    }
	  }
	}
      }
    }
  }
  printf("%d out of %d internal coordinates of type<=%d and pseudobonds changed\n",
	 n, m, type);
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x52a85
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x52a83
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x52a60
jmp 0x52ab5
cmpl $0x0, -0x30(%rbp)
jne 0x52ab3
leaq 0x2e1d1(%rip), %rdi     # 0x80c63
movb $0x0, %al
callq 0x10d0
leaq 0x2e1ff(%rip), %rdi     # 0x80c9f
movb $0x0, %al
callq 0x10d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x52db2
jmp 0x52ab5
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x52d94
movq -0x20(%rbp), %rax
movslq -0x5c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, 0x10(%rbp)
jne 0x52b14
movq -0x40(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x54(%rax)
jge 0x52b14
jmp 0x52d86
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x52b3e
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x52b5b
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
movslq 0x54(%rcx), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x52d84
cmpl $0x0, 0x10(%rbp)
jne 0x52b7d
movq -0x48(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x54(%rax)
jl 0x52d84
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x3, -0x30(%rbp)
jge 0x52b96
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jl 0x52bf3
cmpl $0x0, -0x30(%rbp)
je 0x52bb9
movq -0x50(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x58(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x52bf1
movq -0x40(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jl 0x52bef
movq -0x50(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x40(%rbp), %rax
subsd 0x58(%rax), %xmm0
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq 0x34(%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x52bf1
jmp 0x52bf3
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x52d82
cmpl $0x0, 0x10(%rbp)
jne 0x52c21
movq -0x48(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x54(%rax)
jl 0x52d82
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x2, -0x30(%rbp)
jge 0x52c3e
movq -0x40(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0x52cde
cmpl $0x0, -0x30(%rbp)
je 0x52c77
movq -0x50(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd 0x58(%rax), %xmm1
movq -0x50(%rbp), %rax
divsd 0x58(%rax), %xmm1
mulsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x60(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x52cdc
movq -0x40(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0x52cda
movq -0x50(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq -0x50(%rbp), %rax
divsd 0x58(%rax), %xmm0
callq 0x1110
movsd %xmm0, -0x68(%rbp)
movq -0x40(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq -0x40(%rbp), %rax
divsd 0x58(%rax), %xmm0
callq 0x1110
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
subsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x52cdc
jmp 0x52cde
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x52d80
cmpl $0x0, 0x10(%rbp)
jne 0x52d08
movq -0x48(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x54(%rax)
jl 0x52d80
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x52d21
movq -0x40(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
jl 0x52d7e
cmpl $0x0, -0x30(%rbp)
je 0x52d44
movq -0x50(%rbp), %rax
movsd 0x68(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x68(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x52d7c
movq -0x40(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
jl 0x52d7a
movq -0x50(%rbp), %rax
movsd 0x68(%rax), %xmm0
movq -0x40(%rbp), %rax
subsd 0x68(%rax), %xmm0
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq 0x3c(%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x52d7c
jmp 0x52d7e
jmp 0x52d80
jmp 0x52d82
jmp 0x52d84
jmp 0x52d86
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x52ada
movl -0x54(%rbp), %esi
movl -0x58(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq 0x2df12(%rip), %rdi     # 0x80cb6
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)