// File: /workspace/github_c_makefile_star2_O3/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 $0x98, %rsp
movl %r9d, %ebx
movq %r8, 0x68(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x60(%rsp)
movss %xmm2, 0x28(%rsp)
movss %xmm1, 0x24(%rsp)
movss %xmm0, 0x18(%rsp)
testl %esi, %esi
movq %rdi, 0x78(%rsp)
jle 0x3ef16
movl %esi, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2110
testl %ebx, %ebx
jle 0x3f330
movq 0xf8(%rsp), %r14
movq 0xd0(%rsp), %r12
movslq 0xf0(%rsp), %r13
movl %ebx, %eax
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movl $0x0, 0x4(%rsp)
movq %r13, 0x70(%rsp)
movq %rax, %rbx
movq 0x38(%rsp), %rax
movl (%rax,%rbx,4), %eax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rax
movsbl (%rax,%rbx), %edi
callq 0x1f488
movl %eax, %ebp
movq 0x68(%rsp), %rax
movq %rbx, 0x40(%rsp)
movsbl (%rax,%rbx), %edi
callq 0x1f488
movslq %eax, %rcx
leaq 0x3ac57(%rip), %rax     # 0x79be0
movss (%rax,%rcx,4), %xmm0
movl %ebp, 0x20(%rsp)
movslq %ebp, %rdx
subss (%rax,%rdx,4), %xmm0
movq %rdx, 0x48(%rsp)
cmpl $0x14, %edx
sete %al
movq %rcx, 0x50(%rsp)
cmpl $0x14, %ecx
sete %dl
orb %al, %dl
mulss 0x18(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
movb $0x1, %sil
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movb %dl, 0x3(%rsp)
testb %dl, %dl
je 0x3f014
testb $0x1, %sil
movq 0x8(%rsp), %r8
je 0x3f2cc
testl %r8d, %r8d
js 0x3f301
movl %r8d, %eax
movq (%r12,%rax,8), %rax
cmpl $0x0, (%rax)
jg 0x3f311
leal -0x1(%r8), %eax
testl %r8d, %r8d
movl %eax, %r8d
jg 0x3efe9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x8(%rsp)
jmp 0x3f301
movq 0x8(%rsp), %r8
movslq %r8d, %rcx
movq (%r12,%rcx,8), %r15
movl (%r15), %eax
testl %eax, %eax
movq %r8, 0x8(%rsp)
js 0x3f301
movl %esi, 0x1c(%rsp)
movq 0xd8(%rsp), %rdx
movq (%rdx,%rcx,8), %rbp
movslq (%rbp), %rsi
imulq $0xc8, %rsi, %rdx
movq 0xe0(%rsp), %rdi
movl (%rdi,%rdx), %ecx
movl 0x4(%rdi,%rdx), %r9d
movslq %ecx, %r12
imulq $0x70, %r12, %rdx
movl 0x64(%r14,%rdx), %edx
movslq %r9d, %rdi
cmpl %r8d, %edx
jne 0x3f077
movq %rdi, %r12
movl %ecx, %r9d
jmp 0x3f089
imulq $0x70, %rdi, %rcx
movl 0x64(%r14,%rcx), %ecx
cmpl %r8d, %ecx
jne 0x3f34e
movl %r9d, 0x34(%rsp)
movl %eax, %eax
shlq $0x5, %rax
movq 0xe8(%rsp), %rcx
movsbl 0x13(%rcx,%rax), %edi
callq 0x1f488
movl %eax, %r13d
imulq $0x70, %r12, %rbx
movl 0x64(%r14,%rbx), %r14d
cmpl $0x0, 0x29ea3(%rip)     # 0x68f5c
je 0x3f0e3
cmpl 0x14(%rsp), %r14d
jne 0x3f0e3
leaq 0x1d60d(%rip), %rdi     # 0x5c6d6
movl 0x14(%rsp), %esi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x20f0
movl $0x0, 0x29e79(%rip)     # 0x68f5c
movq 0x50(%rsp), %rdi
cmpl $0x14, %edi
sete %cl
movq 0x48(%rsp), %r8
cmpl $0x14, %r8d
sete %sil
movslq %r13d, %rax
leaq 0x2a07b(%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 0x3f295
andb %dl, %cl
jne 0x3f295
movl 0x4(%rsp), %ecx
cmpl 0x29e1b(%rip), %ecx     # 0x68f60
jge 0x3f17f
movslq 0x4(%rsp), %rcx
leaq 0x3a76d(%rip), %rdx     # 0x798c0
movl %r13d, (%rdx,%rcx,4)
leaq 0x3a8f2(%rip), %rdx     # 0x79a50
movl %r14d, (%rdx,%rcx,4)
leaq 0x3a437(%rip), %rdx     # 0x795a0
movl 0x20(%rsp), %esi
movl %esi, (%rdx,%rcx,4)
leaq 0x3a5b9(%rip), %rdx     # 0x79730
movq 0x8(%rsp), %rsi
movl %esi, (%rdx,%rcx,4)
movq 0xf8(%rsp), %rdx
addq %rdx, %rbx
movq 0x50(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
leaq 0x2a632(%rip), %rsi     # 0x697d0
addq %rsi, %rcx
movss (%rcx,%rax,4), %xmm0
movq 0x48(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
addq %rsi, %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), %r14
imulq $0x70, %r14, %rax
addq %rdx, %rax
xorps %xmm0, %xmm0
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm1
subsd (%rbx,%rcx,8), %xmm1
movsd %xmm1, 0x80(%rsp,%rcx,8)
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rcx
cmpq $0x3, %rcx
jne 0x3f1e8
xorps %xmm1, %xmm1
cvtss2sd 0x3a371(%rip), %xmm1    # 0x79588
callq 0x20a0
xorps %xmm1, %xmm1
cvtss2sd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq 0x130(%rsp), %rcx
movslq (%rcx,%r14,4), %rax
movslq (%rcx,%r12,4), %rcx
cvtss2sd %xmm0, %xmm0
leaq (%rax,%rax,2), %rax
movq 0x78(%rsp), %rdx
leaq (%rdx,%rax,4), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,4), %rcx
xorl %edx, %edx
movsd 0x80(%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 0x3f25b
incl 0x4(%rsp)
movq 0xf8(%rsp), %r14
movq 0x8(%rsp), %r8
addq $0x4, %r15
addq $0x4, %rbp
movl (%r15), %eax
testl %eax, %eax
jns 0x3f040
movq 0xd0(%rsp), %r12
movq 0x70(%rsp), %r13
movb 0x3(%rsp), %dl
movl 0x1c(%rsp), %esi
jmp 0x3f301
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
movslq (%rax,%rcx,4), %r8
movq %r8, %rax
incq %rax
cmpq %r13, %rax
jge 0x3f2f9
movq (%r12,%rax,8), %rcx
incl %r8d
incq %rax
cmpl $0x0, (%rcx)
jle 0x3f2e0
jmp 0x3f019
incl %r8d
movq %r8, 0x8(%rsp)
testb %sil, %dl
movl $0x0, %esi
jne 0x3efcd
jmp 0x3f31b
movl %r8d, 0x14(%rsp)
jmp 0x3f019
movq 0x40(%rsp), %rax
incq %rax
cmpq 0x58(%rsp), %rax
jne 0x3ef4c
jmp 0x3f338
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d349(%rip), %rdi     # 0x5c69e
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280