// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/force2confchange.c
// Function: Force2Confchange
int Force2Confchange(float *atom_move, char *FILE_FORCE,
		     int naxe1, int N_ref, atom *atoms1, int natoms1,
		     int *atom_num1, float **Jacobian_ar, float *eigen_value,
		     float **Tors_mode, int *select, struct axe *axe1,
		     char *chain1, int nres1, struct residue *seq1,
		     struct bond *bonds)
{
  int N_cart=3*N_ref, i, ia, j, k;
  double Delta_theta[naxe1];
  float Force_input_cart[N_cart];
  float Force_input_tors[naxe1];
  float Force_input_coef[naxe1];
  double sum;

  //i=Read_force(Force_input_cart, atoms1, atom_num1, N_ref, FILE_FORCE);

  // Read force
  int nres, nmr, ANISOU;
  //~ int natoms;
  atom atom_read[natoms1], *atom;
  struct residue seq[nres1];
  printf("Reading force in file %s\n", FILE_FORCE);
  nres=Read_coord(FILE_FORCE, &nmr, seq, atom_read, chain1, &ANISOU, NULL);
  if(nres<0)return(-1); // file not found
  if(nres!=nres1){
    printf("ERROR, wrong number of residues in force file:");
    printf(" %d instead of %d\n", nres, nres1); return(-1);
  }
  for(i=0; i<nres; i++){
    if(seq[i].amm!=seq1[i].amm){
      printf("ERROR, wrong amino acid in force file\n");
      printf("Position %d, %c instead of %c\n", i, seq[i].amm, seq1[i].amm);
      return(-1);
    }
  }
  for(i=0; i<3*N_ref; i++)Force_input_cart[i]=0;
  for(i=0; i<N_ref; i++){
    atom=Find_atom_seq(seq, nres, atoms1[atom_num1[i]]);
    if(atom==NULL)continue;
    k=3*i; for(j=0; j<3; j++){Force_input_cart[k]=atom->r[j]; k++;}
  }
  // End read force

  for(i=0; i<naxe1; i++){  // Torsional force F^tors_a = sum_i F_i*J_ia
    sum=0; for(j=0; j<N_cart; j++)sum+=Jacobian_ar[i][j]*Force_input_cart[j];
    Force_input_tors[i]=sum;
  }
  for(ia=0; ia<naxe1; ia++){  // c^alpha =(F^tors,u^alpha)
    if(select[ia]==0)continue;
    float *ua=Tors_mode[ia];
    sum=0; for(i=0; i<naxe1; i++)sum+=ua[i]*Force_input_tors[i];
    Force_input_coef[ia]=sum;
  }
  for(i=0; i<naxe1; i++)Delta_theta[i]=0;
  for(ia=0; ia<naxe1; ia++){  // Delta_theta= H^{-1} F^tors
    if(select[ia]==0)continue;
    float *ua=Tors_mode[ia];
    float w=Force_input_coef[ia]/eigen_value[ia];
    for(i=0; i<naxe1; i++)Delta_theta[i]+=w*ua[i];
  }

  // Initialize build up
  Set_bonds_measure(bonds, natoms1, atoms1);
  // Build up Cartesian coordinates from Delta_theta
  Build_up(bonds, natoms1, Delta_theta, naxe1);
  k=3;
  for(i=1;i<N_ref;i++){
    struct bond *bond=bonds+atom_num1[i];
    for(j=0; j<3; j++){
      atom_move[k]=bond->r[j]; k++;
    }
  }
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r8, -0x60(%rbp)
movq %rsi, %r14
movq %rdi, -0x80(%rbp)
movl 0x48(%rbp), %edi
movq %rcx, -0x38(%rbp)
leal (%rcx,%rcx,2), %r8d
movl %edx, -0x2c(%rbp)
movl %edx, %edx
movq %rsp, %rcx
leaq 0xf(,%rdx,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movq %r8, -0x58(%rbp)
leaq 0xf(,%r8,4), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r15
movq %rdx, -0x88(%rbp)
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movl %r9d, -0x3c(%rbp)
movl %r9d, %eax
movq %rsp, %r13
imulq $0x70, %rax, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %rbx
movq %rdi, %rax
shlq $0x5, %rax
subq %rax, %rbx
movq %rbx, %rsp
leaq 0x20c03(%rip), %rdi     # 0x5be9c
xorl %eax, %eax
callq 0x20f0
subq $0x8, %rsp
leaq -0x98(%rbp), %rsi
leaq -0x94(%rbp), %r9
movq %r14, %rdi
movq %rbx, -0x68(%rbp)
movq %rbx, %rdx
movq %r13, %rcx
movq 0x40(%rbp), %r8
pushq $0x0
callq 0xd04a
addq $0x10, %rsp
movl %eax, %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r13d, %r13d
js 0x3b626
movl 0x48(%rbp), %ecx
cmpl %ecx, %r13d
jne 0x3b420
movq %r15, -0x78(%rbp)
testl %ecx, %ecx
movq -0x68(%rbp), %r14
je 0x3b31e
movq 0x50(%rbp), %rbx
movl $0x13, %r15d
xorl %r13d, %r13d
movb (%r14,%r15), %al
cmpb (%rbx,%r15), %al
jne 0x3b5fa
incq %r13
addq $0x20, %r15
cmpq %r13, %rcx
jne 0x3b304
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq %rcx, -0x70(%rbp)
testl %eax, %eax
jle 0x3b449
movq -0x58(%rbp), %rax
cmpl $0x2, %eax
movl $0x1, %edx
cmovgel %eax, %edx
shlq $0x2, %rdx
xorl %r13d, %r13d
movq %r12, %rdi
xorl %esi, %esi
callq 0x2110
movl $0x0, -0x30(%rbp)
movq 0x10(%rbp), %rax
movslq (%rax,%r13,4), %rax
imulq $0x70, %rax, %rsi
addq -0x60(%rbp), %rsi
movl $0x70, %edx
leaq -0x108(%rbp), %rdi
callq 0x21b0
movslq -0xa4(%rbp), %rax
shlq $0x5, %rax
movb 0x13(%r14,%rax), %cl
cmpb -0xa0(%rbp), %cl
jne 0x3b3d7
addq %r14, %rax
movl 0x8(%rax), %r15d
testl %r15d, %r15d
jle 0x3b3e3
movl -0x30(%rbp), %ecx
leaq (%r12,%rcx,4), %rcx
movq %rcx, -0x90(%rbp)
movq (%rax), %rbx
xorl %r14d, %r14d
leaq 0x18(%rbx), %rdi
movl $0x3, %edx
leaq -0xf0(%rbp), %rsi
callq 0x2070
testl %eax, %eax
je 0x3b3fa
addq $0x70, %rbx
incl %r14d
cmpl %r15d, %r14d
jne 0x3b3b0
jmp 0x3b3e3
leaq 0x20b9e(%rip), %rdi     # 0x5bf7c
callq 0x2090
incq %r13
addl $0x3, -0x30(%rbp)
cmpq -0x70(%rbp), %r13
movq -0x68(%rbp), %r14
jne 0x3b357
jmp 0x3b449
testq %rbx, %rbx
movq -0x90(%rbp), %rcx
je 0x3b3e3
xorl %eax, %eax
xorps %xmm0, %xmm0
cvtsd2ss (%rbx,%rax,8), %xmm0
movss %xmm0, (%rcx,%rax,4)
incq %rax
cmpq $0x3, %rax
jne 0x3b408
jmp 0x3b3e3
leaq 0x20a8f(%rip), %rdi     # 0x5beb6
xorl %eax, %eax
movq %rcx, %rbx
callq 0x20f0
leaq 0x20aad(%rip), %rdi     # 0x5bee5
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
jmp 0x3b621
movq 0x58(%rbp), %r13
cmpl $0x0, -0x2c(%rbp)
movq -0x50(%rbp), %r9
movq -0x88(%rbp), %r14
movq -0x48(%rbp), %r10
movq -0x78(%rbp), %r11
jle 0x3b57d
movq 0x30(%rbp), %r15
movq 0x28(%rbp), %rbx
movq 0x18(%rbp), %rax
movq -0x58(%rbp), %rdx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
xorl %edx, %edx
movq -0x38(%rbp), %r8
testl %r8d, %r8d
jle 0x3b4ba
movq (%rax,%rdx,8), %rsi
xorps %xmm0, %xmm0
xorl %edi, %edi
movss (%rsi,%rdi,4), %xmm1
mulss (%r12,%rdi,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rdi
cmpq %rdi, %rcx
jne 0x3b499
cvtsd2ss %xmm0, %xmm0
jmp 0x3b4bd
xorps %xmm0, %xmm0
movss %xmm0, (%r11,%rdx,4)
incq %rdx
cmpq %r14, %rdx
jne 0x3b48b
cmpl $0x0, -0x2c(%rbp)
jle 0x3b57d
movq %rbx, %r12
xorl %eax, %eax
cmpl $0x0, (%r15,%rax,4)
je 0x3b50f
movq (%r12,%rax,8), %rcx
xorps %xmm0, %xmm0
xorl %edx, %edx
movss (%rcx,%rdx,4), %xmm1
mulss (%r11,%rdx,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %r14
jne 0x3b4ea
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r10,%rax,4)
incq %rax
cmpq %r14, %rax
jne 0x3b4da
cmpl $0x0, -0x2c(%rbp)
jle 0x3b57d
leaq (,%r14,8), %rdx
xorl %ebx, %ebx
movq %r9, %rdi
xorl %esi, %esi
callq 0x2110
movq 0x20(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %r9
cmpl $0x0, (%r15,%rbx,4)
je 0x3b575
movq (%r12,%rbx,8), %rax
movss (%rdx,%rbx,4), %xmm0
divss (%rsi,%rbx,4), %xmm0
xorl %ecx, %ecx
movss (%rax,%rcx,4), %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
addsd (%r9,%rcx,8), %xmm1
movsd %xmm1, (%r9,%rcx,8)
incq %rcx
cmpq %rcx, %r14
jne 0x3b554
incq %rbx
cmpq %r14, %rbx
jne 0x3b53d
movq %r13, %rdi
movl -0x3c(%rbp), %ebx
movl %ebx, %esi
movq -0x60(%rbp), %rdx
movq %r9, %r14
callq 0x14cf3
movq %r13, %rdi
movl %ebx, %esi
movq %r14, %rdx
movl -0x2c(%rbp), %ecx
callq 0x15083
cmpl $0x2, -0x38(%rbp)
jl 0x3b5f6
addq $0x8, %r13
movl $0x3, %eax
movl $0x1, %ecx
movq -0x80(%rbp), %r8
movq 0x10(%rbp), %rdx
movslq (%rdx,%rcx,4), %rsi
cltq
leaq (%r8,%rax,4), %rdx
leaq (%rsi,%rsi,2), %rsi
shlq $0x6, %rsi
addq %r13, %rsi
xorl %edi, %edi
xorps %xmm0, %xmm0
cvtsd2ss (%rsi,%rdi,8), %xmm0
movss %xmm0, (%rdx,%rdi,4)
incq %rdi
cmpq $0x3, %rdi
jne 0x3b5d4
incq %rcx
addq %rdi, %rax
cmpq -0x70(%rbp), %rcx
jne 0x3b5b9
xorl %eax, %eax
jmp 0x3b626
leaq 0x20955(%rip), %rdi     # 0x5bf56
callq 0x2090
movsbl (%r14,%r15), %edx
movsbl (%rbx,%r15), %ecx
leaq 0x208e1(%rip), %rdi     # 0x5bef8
movl %r13d, %esi
xorl %eax, %eax
callq 0x20f0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq