// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/mutation.c
// Function: Mutation_force
int Mutation_force(float *Force, int N_Cart,
		   float C_size, float C_stab, float C_dist, 
		   char *AAwt, int *Posmut, char *AAmut, int Nmut,
		   int **clist, int **cnum, struct interaction *Int_list,
		   struct residue *seq, int nres, atom *atoms,
		   struct Reference Ref_kin, int *kin_atom)
{

  int am=-1, ai, j, nc=0, iter;
  for(j=0; j<N_Cart; j++)Force[j]=0;
  for(int kmut=0; kmut<Nmut; kmut++){
    int pmut=Posmut[kmut];
    int aaw=Code_AA(AAwt[kmut]);   // wild-type aa
    int aam=Code_AA(AAmut[kmut]);  // mutated aa
    double dsize=(natm_norm[aam]-natm_norm[aaw]);
    if((aaw==20)||(aam==20)){iter=2;} // gap!
    else{iter=1;}
    /* Since atoms in the gap are removed, we have to analyze
       the flanking residues */
    int p1=-1;
    for(int it=0; it<iter; it++){
      if(iter==2){
	if(it==0){
	  while((pmut>=0)&&(clist[pmut][0]<=0))pmut--;
	  if(pmut<0)continue;
	  p1=pmut;
	}else if(it==1){
	  pmut=Posmut[kmut]+1; while((pmut<nres)&&(clist[pmut][0]<=0))pmut++;
	  if(pmut>=nres)continue;
	}
      }
      int *ic=clist[pmut]; // residue in contact with pmut
      int *ii=cnum[pmut];  // interaction label of the contact
      while(*ic >= 0){
	//if(abs(pmut-(*ic))<3)goto next; // short range contact discarded
	int i1=Int_list[*ii].i1, i2=Int_list[*ii].i2;
	if(atoms[i1].res==pmut){
	  am=i1; ai=i2;
	}else if(atoms[i2].res==pmut){
	  am=i2; ai=i1;
	}else{
	  printf("ERROR in mutation, interaction %d res %d - %d pmut= %d\n",
		 *ii, atoms[i1].res, atoms[i2].res, pmut); exit(8);
	}
	int aai=Code_AA(seq[*ic].amm);
	ic++; ii++;
	
	int res_i=atoms[ai].res;
	//if((abs(res_i-pmut)<3))goto next; //&&(FORCE_TYPE==1)

	// contacts of main chain atoms of mutant residue are discarded (?)
	if(PRINT_FLANK &&(res_i==p1)){
	  printf("Gap flanking residues %d and %d\n", p1, pmut);
	  PRINT_FLANK=0;
	  //}else if(Mainchain(atoms[am].name)){
	  //continue; //&& FORCE_TYPE!=3
	}

	float f =C_size*dsize;
	f+=C_dist*(D_Res[aam][aai]-D_Res[aaw][aai]);
	float dE=(Econt[aam][aai]-Econt[aaw][aai]);
	if(((aaw==20)&&(dE<0))|| // Insertion, attracting
	   ((aam==20)&&(dE>0)))continue; // Deletion, repelling
	f+=C_stab*dE;

	// Record contacts considered for force computation
	if(nc<ncmax){
	  mut_cont[nc]=aai; mut_res[nc]=res_i;
	  wt_cont[nc]=aaw; wt_res[nc]=pmut;
	}
	nc++;


	double r[3], r2=0, *rm=atoms[am].r, *ri=atoms[ai].r;
	for(j=0; j<3; j++){
	  r[j]=rm[j]-ri[j]; r2+=r[j]*r[j];
	}
	f/=pow(r2, Exp);

	int km=3*kin_atom[am], ki=3*kin_atom[ai]; 
	for(j=0; j<3; j++){
	  float fj=f*r[j];
	  Force[km+j]+=fj; //?
	  Force[ki+j]-=fj;
	}
      } // end contact
    } // end iter (in case of gap)
  }
  //printf("Force computation based on %d contacts\n", nc);
  return(nc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r9d, %ebx
movq %r8, 0x78(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x70(%rsp)
movss %xmm2, 0x28(%rsp)
movss %xmm1, 0x24(%rsp)
movss %xmm0, 0x1c(%rsp)
testl %esi, %esi
movq %rdi, 0x80(%rsp)
jle 0x3ee98
movl %esi, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2110
testl %ebx, %ebx
jle 0x3f2d4
movq 0x108(%rsp), %r12
movq 0xe0(%rsp), %r14
movslq 0x100(%rsp), %r15
movl %ebx, %eax
movq %rax, 0x68(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x8(%rsp)
movq %r15, 0x48(%rsp)
movq 0x38(%rsp), %rax
movl (%rax,%rcx,4), %r13d
movq 0x70(%rsp), %rax
movsbl (%rax,%rcx), %edi
movq %rcx, %rbx
callq 0x1fbd8
movl %eax, %ebp
movq 0x78(%rsp), %rax
movq %rbx, 0x40(%rsp)
movsbl (%rax,%rbx), %edi
callq 0x1fbd8
movslq %eax, %rcx
leaq 0x3ace9(%rip), %rax     # 0x79bf0
movss (%rax,%rcx,4), %xmm0
movl %ebp, 0x20(%rsp)
movslq %ebp, %rdx
subss (%rax,%rdx,4), %xmm0
movq %rdx, 0x58(%rsp)
cmpl $0x14, %edx
sete %al
movq %rcx, 0x60(%rsp)
cmpl $0x14, %ecx
sete %dil
orb %al, %dil
mulss 0x1c(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movb %dil, 0x7(%rsp)
testb %dil, %dil
je 0x3ef94
testl %r8d, %r8d
je 0x3f283
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rdx
movslq (%rcx,%rdx,4), %r13
movq %r13, %rdx
incq %rdx
cmpq %r15, %rdx
jge 0x3f2a7
movq %rdx, %rcx
movq (%r14,%rdx,8), %rsi
incl %r13d
incq %rdx
cmpl $0x0, (%rsi)
jle 0x3ef6d
movl %eax, %edx
cmpq %r15, %rcx
jl 0x3ef96
jmp 0x3f26b
movl %eax, %edx
movq %r8, 0x50(%rsp)
movslq %r13d, %rcx
movq (%r14,%rcx,8), %rbp
movl (%rbp), %eax
testl %eax, %eax
js 0x3f25a
movl %edx, 0xc(%rsp)
movq 0xe8(%rsp), %rdx
movq (%rdx,%rcx,8), %r14
movq %r13, 0x10(%rsp)
movslq (%r14), %rsi
imulq $0xc8, %rsi, %rcx
movq 0xf0(%rsp), %rdx
movslq (%rdx,%rcx), %rdi
movl 0x4(%rdx,%rcx), %r8d
imulq $0x70, %rdi, %rcx
movl 0x64(%r12,%rcx), %edx
cmpl %r13d, %edx
jne 0x3eff3
movl %r8d, %ebx
movl %edi, %r8d
jmp 0x3f00a
movslq %r8d, %rcx
imulq $0x70, %rcx, %rcx
movl 0x64(%r12,%rcx), %ecx
movl %edi, %ebx
cmpl %r13d, %ecx
jne 0x3f2f2
movl %r8d, 0x34(%rsp)
movl %eax, %eax
shlq $0x5, %rax
movq 0xf8(%rsp), %rcx
movsbl 0x13(%rcx,%rax), %edi
callq 0x1fbd8
movl %eax, %r13d
movslq %ebx, %rcx
movq %rcx, 0x88(%rsp)
imulq $0x70, %rcx, %rbx
movq %r12, %r15
movl 0x64(%r12,%rbx), %r12d
cmpl $0x0, 0x29f14(%rip)     # 0x68f5c
je 0x3f072
cmpl 0xc(%rsp), %r12d
jne 0x3f072
leaq 0x1d6be(%rip), %rdi     # 0x5c716
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x20f0
movl $0x0, 0x29eea(%rip)     # 0x68f5c
movq 0x60(%rsp), %rdi
cmpl $0x14, %edi
sete %cl
movq 0x58(%rsp), %r8
cmpl $0x14, %r8d
sete %sil
movslq %r13d, %rax
leaq 0x2a0ec(%rip), %rdx     # 0x69180
movq (%rdx), %rdx
movq (%rdx,%rdi,8), %rdi
movss (%rdi,%rax,4), %xmm1
movq (%rdx,%r8,8), %rdx
subss (%rdx,%rax,4), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
seta %dil
ucomiss %xmm0, %xmm1
seta %dl
testb %dil, %sil
jne 0x3f231
andb %dl, %cl
jne 0x3f231
movl 0x8(%rsp), %ecx
cmpl 0x29e8c(%rip), %ecx     # 0x68f60
jge 0x3f10e
movslq 0x8(%rsp), %rcx
leaq 0x3a7ee(%rip), %rdx     # 0x798d0
movl %r13d, (%rdx,%rcx,4)
leaq 0x3a973(%rip), %rdx     # 0x79a60
movl %r12d, (%rdx,%rcx,4)
leaq 0x3a4b8(%rip), %rdx     # 0x795b0
movl 0x20(%rsp), %esi
movl %esi, (%rdx,%rcx,4)
leaq 0x3a63a(%rip), %rdx     # 0x79740
movq 0x10(%rsp), %rsi
movl %esi, (%rdx,%rcx,4)
movq %r15, %r12
addq %r15, %rbx
movq 0x60(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
leaq 0x2a6a8(%rip), %rdx     # 0x697d0
addq %rdx, %rcx
movss (%rcx,%rax,4), %xmm0
movq 0x58(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
addq %rdx, %rcx
subss (%rcx,%rax,4), %xmm0
mulss 0x28(%rsp), %xmm0
addss 0x2c(%rsp), %xmm0
mulss 0x24(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x30(%rsp)
movslq 0x34(%rsp), %r15
imulq $0x70, %r15, %rax
addq %r12, %rax
xorps %xmm0, %xmm0
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm1
subsd (%rbx,%rcx,8), %xmm1
movsd %xmm1, 0x90(%rsp,%rcx,8)
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rcx
cmpq $0x3, %rcx
jne 0x3f172
xorps %xmm1, %xmm1
cvtss2sd 0x3a3f7(%rip), %xmm1    # 0x79598
callq 0x20a0
xorps %xmm1, %xmm1
cvtss2sd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq 0x140(%rsp), %rcx
movslq (%rcx,%r15,4), %rax
movq 0x88(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
cvtss2sd %xmm0, %xmm0
leaq (%rax,%rax,2), %rax
movq 0x80(%rsp), %rdx
leaq (%rdx,%rax,4), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,4), %rcx
xorl %edx, %edx
movq 0x10(%rsp), %r13
movsd 0x90(%rsp,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
movss (%rax,%rdx,4), %xmm2
addss %xmm1, %xmm2
movss %xmm2, (%rax,%rdx,4)
movss (%rcx,%rdx,4), %xmm2
subss %xmm1, %xmm2
movss %xmm2, (%rcx,%rdx,4)
incq %rdx
cmpq $0x3, %rdx
jne 0x3f1f5
incl 0x8(%rsp)
jmp 0x3f239
movq %r15, %r12
movq 0x10(%rsp), %r13
addq $0x4, %rbp
addq $0x4, %r14
movl (%rbp), %eax
testl %eax, %eax
jns 0x3efc2
movl 0xc(%rsp), %eax
movq 0xe0(%rsp), %r14
jmp 0x3f25c
movl %edx, %eax
movq 0x48(%rsp), %r15
movb 0x7(%rsp), %dil
movq 0x50(%rsp), %r8
testl %r8d, %r8d
leal 0x1(%r8), %ecx
sete %dl
movl %ecx, %r8d
testb %dl, %dil
jne 0x3ef4b
jmp 0x3f2bf
testl %r13d, %r13d
js 0x3f2ac
movl %r13d, %ecx
movq (%r14,%rcx,8), %rcx
cmpl $0x0, (%rcx)
jg 0x3f2ac
leal -0x1(%r13), %ecx
testl %r13d, %r13d
movl %ecx, %r13d
jg 0x3f288
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x3f2af
incl %r13d
jmp 0x3f26b
movl %r13d, %edx
movl %edx, %r13d
testl %edx, %edx
jns 0x3ef96
movl %edx, %r13d
jmp 0x3f26b
movq 0x40(%rsp), %rcx
incq %rcx
cmpq 0x68(%rsp), %rcx
jne 0x3eece
jmp 0x3f2dc
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d3e5(%rip), %rdi     # 0x5c6de
movl %r13d, %r8d
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270