// File: /workspace/github_c_makefile_star2_O1/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 $0xd8, %rsp
movq %r8, -0x68(%rbp)
movq %rsi, -0x48(%rbp)
movq %rdi, -0x88(%rbp)
movl 0x48(%rbp), %edi
movq %rcx, -0x38(%rbp)
leal (%rcx,%rcx,2), %ecx
movl %edx, -0x2c(%rbp)
movl %edx, %ebx
movq %rsp, %r15
leaq 0xf(,%rbx,8), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %rcx, -0x58(%rbp)
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %rcx
leaq 0xf(,%rbx,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movl %r9d, -0x4c(%rbp)
movl %r9d, %eax
movq %rsp, %r14
imulq $0x70, %rax, %rax
subq %rax, %r14
movq %r14, %rsp
movq %rsp, %r13
movq %rdi, %rax
shlq $0x5, %rax
subq %rax, %r13
movq %r13, %rsp
leaq 0x20bdb(%rip), %rdi     # 0x5bedc
xorl %eax, %eax
callq 0x20f0
subq $0x8, %rsp
leaq -0x90(%rbp), %rsi
leaq -0x8c(%rbp), %r9
movq -0x48(%rbp), %rdi
movq %r13, -0x70(%rbp)
movq %r13, %rdx
movq %r14, %rcx
movq 0x40(%rbp), %r8
pushq $0x0
callq 0xd00d
addq $0x10, %rsp
movl %eax, %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r14d, %r14d
js 0x3b685
movl 0x48(%rbp), %r13d
cmpl %r13d, %r14d
jne 0x3b62f
testl %r14d, %r14d
movq -0x70(%rbp), %rdx
je 0x3b388
movq 0x50(%rbp), %rsi
movl %r14d, %eax
movl $0x13, %r13d
xorl %r14d, %r14d
movb (%rdx,%r13), %cl
cmpb (%rsi,%r13), %cl
jne 0x3b653
incq %r14
addq $0x20, %r13
cmpq %r14, %rax
jne 0x3b36e
cmpl $0x0, -0x38(%rbp)
jle 0x3b3ab
movq -0x58(%rbp), %rax
cmpl $0x2, %eax
movl $0x1, %edx
cmovgel %eax, %edx
shlq $0x2, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2110
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq %rcx, -0x80(%rbp)
testl %eax, %eax
movq -0x60(%rbp), %r8
jle 0x3b48d
xorl %r13d, %r13d
xorl %edx, %edx
movl %edx, -0x48(%rbp)
movq 0x10(%rbp), %rax
movslq (%rax,%r13,4), %rax
imulq $0x70, %rax, %rsi
addq -0x68(%rbp), %rsi
movl $0x70, %edx
leaq -0x100(%rbp), %rdi
callq 0x21a0
movslq -0x9c(%rbp), %rax
shlq $0x5, %rax
movq -0x70(%rbp), %rdx
movb 0x13(%rdx,%rax), %cl
cmpb -0x98(%rbp), %cl
jne 0x3b443
movq %r13, -0x40(%rbp)
addq %rdx, %rax
movl 0x8(%rax), %r13d
testl %r13d, %r13d
jle 0x3b43a
movq (%rax), %r14
leaq 0x18(%r14), %rdi
movl $0x3, %edx
leaq -0xe8(%rbp), %rsi
callq 0x2070
testl %eax, %eax
je 0x3b43d
addq $0x70, %r14
decl %r13d
jne 0x3b418
xorl %r14d, %r14d
movq -0x40(%rbp), %r13
jmp 0x3b452
leaq 0x20b72(%rip), %rdi     # 0x5bfbc
callq 0x2090
xorl %r14d, %r14d
testq %r14, %r14
movl -0x48(%rbp), %edx
je 0x3b479
movl %edx, %eax
leaq (%r12,%rax,4), %rax
xorl %ecx, %ecx
xorps %xmm0, %xmm0
cvtsd2ss (%r14,%rcx,8), %xmm0
movss %xmm0, (%rax,%rcx,4)
incq %rcx
cmpq $0x3, %rcx
jne 0x3b462
incq %r13
addl $0x3, %edx
cmpq -0x80(%rbp), %r13
movq -0x60(%rbp), %r8
jne 0x3b3c6
cmpl $0x0, -0x2c(%rbp)
movq -0x88(%rbp), %r13
jle 0x3b4f0
movq 0x18(%rbp), %rax
movq -0x58(%rbp), %rdx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
xorl %edx, %edx
cmpl $0x0, -0x38(%rbp)
jle 0x3b4df
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 0x3b4be
cvtsd2ss %xmm0, %xmm0
jmp 0x3b4e2
xorps %xmm0, %xmm0
movss %xmm0, (%r8,%rdx,4)
incq %rdx
cmpq %rbx, %rdx
jne 0x3b4af
movq 0x30(%rbp), %r12
movq 0x28(%rbp), %rdi
cmpl $0x0, -0x2c(%rbp)
jle 0x3b540
xorl %eax, %eax
cmpl $0x0, (%r12,%rax,4)
je 0x3b538
movq (%rdi,%rax,8), %rcx
xorps %xmm0, %xmm0
xorl %edx, %edx
movss (%rcx,%rdx,4), %xmm1
mulss (%r8,%rdx,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %rbx
jne 0x3b510
cvtsd2ss %xmm0, %xmm0
movq -0x78(%rbp), %rcx
movss %xmm0, (%rcx,%rax,4)
incq %rax
cmpq %rbx, %rax
jne 0x3b500
cmpl $0x0, -0x2c(%rbp)
jle 0x3b55e
leaq (,%rbx,8), %rdx
movq %rdi, %r14
movq %r15, %rdi
xorl %esi, %esi
callq 0x2110
movq %r14, %rdi
movq 0x58(%rbp), %r14
cmpl $0x0, -0x2c(%rbp)
jle 0x3b5b2
movq 0x20(%rbp), %rax
xorl %ecx, %ecx
cmpl $0x0, (%r12,%rcx,4)
je 0x3b5aa
movq (%rdi,%rcx,8), %rdx
movq -0x78(%rbp), %rsi
movss (%rsi,%rcx,4), %xmm0
divss (%rax,%rcx,4), %xmm0
xorl %esi, %esi
movss (%rdx,%rsi,4), %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
addsd (%r15,%rsi,8), %xmm1
movsd %xmm1, (%r15,%rsi,8)
incq %rsi
cmpq %rsi, %rbx
jne 0x3b589
incq %rcx
cmpq %rbx, %rcx
jne 0x3b56e
movq %r14, %rdi
movl -0x4c(%rbp), %ebx
movl %ebx, %esi
movq -0x68(%rbp), %rdx
callq 0x1512b
movq %r14, %rdi
movl %ebx, %esi
movq %r15, %rdx
movl -0x2c(%rbp), %ecx
callq 0x154bb
cmpl $0x2, -0x38(%rbp)
jl 0x3b62b
addq $0x8, %r14
movl $0x3, %eax
movl $0x1, %ecx
movq 0x10(%rbp), %rdx
movslq (%rdx,%rcx,4), %rsi
cltq
leaq (,%rax,4), %rdx
addq %r13, %rdx
leaq (%rsi,%rsi,2), %rsi
shlq $0x6, %rsi
addq %r14, %rsi
xorl %edi, %edi
xorps %xmm0, %xmm0
cvtsd2ss (%rsi,%rdi,8), %xmm0
movss %xmm0, (%rdx,%rdi,4)
incq %rdi
cmpq $0x3, %rdi
jne 0x3b609
incq %rcx
addq %rdi, %rax
cmpq -0x80(%rbp), %rcx
jne 0x3b5e7
xorl %eax, %eax
jmp 0x3b685
leaq 0x208c0(%rip), %rdi     # 0x5bef6
xorl %eax, %eax
callq 0x20f0
leaq 0x208e1(%rip), %rdi     # 0x5bf25
movl %r14d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
jmp 0x3b680
leaq 0x2093c(%rip), %rdi     # 0x5bf96
movq %rdx, %rbx
movq %rsi, %r15
callq 0x2090
movsbl (%rbx,%r13), %edx
movsbl (%r15,%r13), %ecx
leaq 0x208c2(%rip), %rdi     # 0x5bf38
movl %r14d, %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