// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x70(%rbp), %rax
movq 0x38(%rbp), %rax
movl 0x30(%rbp), %eax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movss %xmm0, -0x10(%rbp)
movss %xmm1, -0x14(%rbp)
movss %xmm2, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x59894
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x59871
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x59e99
movq -0x28(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x2bec0
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x2bec0
movl %eax, -0x58(%rbp)
movslq -0x58(%rbp), %rcx
leaq 0x432c8(%rip), %rax     # 0x9cbb0
movss (%rax,%rcx,4), %xmm0
movslq -0x54(%rbp), %rcx
leaq 0x432b8(%rip), %rax     # 0x9cbb0
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
cmpl $0x14, -0x54(%rbp)
je 0x59912
cmpl $0x14, -0x58(%rbp)
jne 0x5991b
movl $0x2, -0x48(%rbp)
jmp 0x59922
movl $0x1, -0x48(%rbp)
movl $0xffffffff, -0x64(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x59e89
cmpl $0x2, -0x48(%rbp)
jne 0x59a07
cmpl $0x0, -0x68(%rbp)
jne 0x5999e
jmp 0x5994e
xorl %eax, %eax
cmpl $0x0, -0x50(%rbp)
movb %al, -0xd5(%rbp)
jl 0x59974
movq 0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax)
setle %al
movb %al, -0xd5(%rbp)
movb -0xd5(%rbp), %al
testb $0x1, %al
jne 0x59980
jmp 0x5998b
movl -0x50(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x5994e
cmpl $0x0, -0x50(%rbp)
jge 0x59996
jmp 0x59e7b
movl -0x50(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x59a05
cmpl $0x1, -0x68(%rbp)
jne 0x59a03
movq -0x28(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %ecx
xorl %eax, %eax
cmpl 0x30(%rbp), %ecx
movb %al, -0xd6(%rbp)
jge 0x599dd
movq 0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax)
setle %al
movb %al, -0xd6(%rbp)
movb -0xd6(%rbp), %al
testb $0x1, %al
jne 0x599e9
jmp 0x599f4
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x599b5
movl -0x50(%rbp), %eax
cmpl 0x30(%rbp), %eax
jl 0x59a01
jmp 0x59e7b
jmp 0x59a03
jmp 0x59a05
jmp 0x59a07
movq 0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq 0x18(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x59e79
movq 0x20(%rbp), %rax
movq -0x78(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
movq 0x20(%rbp), %rax
movq -0x78(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x80(%rbp)
movq 0x38(%rbp), %rax
movslq -0x7c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x50(%rbp), %eax
jne 0x59a8e
movl -0x7c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x59afb
movq 0x38(%rbp), %rax
movslq -0x80(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
cmpl -0x50(%rbp), %eax
jne 0x59ab3
movl -0x80(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x59af9
movq -0x78(%rbp), %rax
movl (%rax), %esi
movq 0x38(%rbp), %rax
movslq -0x7c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %edx
movq 0x38(%rbp), %rax
movslq -0x80(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %ecx
movl -0x50(%rbp), %r8d
leaq 0x27f5c(%rip), %rdi     # 0x81a44
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x59afb
movq 0x28(%rbp), %rax
movq -0x70(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsbl 0x13(%rax), %edi
callq 0x2bec0
movl %eax, -0x84(%rbp)
movq -0x70(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x78(%rbp)
movq 0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
movl %eax, -0x88(%rbp)
cmpl $0x0, 0x323c9(%rip)     # 0x8bf1c
je 0x59b7e
movl -0x88(%rbp), %eax
cmpl -0x64(%rbp), %eax
jne 0x59b7e
movl -0x64(%rbp), %esi
movl -0x50(%rbp), %edx
leaq 0x27f0f(%rip), %rdi     # 0x81a7c
movb $0x0, %al
callq 0x10d0
movl $0x0, 0x3239e(%rip)     # 0x8bf1c
movss -0x10(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd -0x60(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x8c(%rbp)
movss -0x18(%rbp), %xmm0
movslq -0x58(%rbp), %rcx
leaq 0x32be8(%rip), %rax     # 0x8c790
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x84(%rbp), %rcx
movss (%rax,%rcx,4), %xmm2
movslq -0x54(%rbp), %rcx
leaq 0x32bca(%rip), %rax     # 0x8c790
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq -0x84(%rbp), %rcx
subss (%rax,%rcx,4), %xmm2
movss -0x8c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x8c(%rbp)
leaq 0x32548(%rip), %rax     # 0x8c140
movq (%rax), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x84(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
leaq 0x3252a(%rip), %rax     # 0x8c140
movq (%rax), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x84(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x90(%rbp)
cmpl $0x14, -0x54(%rbp)
jne 0x59c47
xorps %xmm0, %xmm0
ucomiss -0x90(%rbp), %xmm0
ja 0x59c5d
cmpl $0x14, -0x58(%rbp)
jne 0x59c62
movss -0x90(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x59c62
jmp 0x59a27
movss -0x14(%rbp), %xmm0
movss -0x90(%rbp), %xmm2
movss -0x8c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x8c(%rbp)
movl -0x44(%rbp), %eax
cmpl 0x32290(%rip), %eax     # 0x8bf20
jge 0x59cdc
movl -0x84(%rbp), %edx
movslq -0x44(%rbp), %rcx
leaq 0x42bed(%rip), %rax     # 0x9c890
movl %edx, (%rax,%rcx,4)
movl -0x88(%rbp), %edx
movslq -0x44(%rbp), %rcx
leaq 0x42d69(%rip), %rax     # 0x9ca20
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %edx
movslq -0x44(%rbp), %rcx
leaq 0x428a8(%rip), %rax     # 0x9c570
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %edx
movslq -0x44(%rbp), %rcx
leaq 0x42a27(%rip), %rax     # 0x9c700
movl %edx, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
movq 0x38(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq 0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jge 0x59d93
movq -0xc0(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x40(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movslq -0x40(%rbp), %rax
movsd %xmm0, -0xb0(%rbp,%rax,8)
movslq -0x40(%rbp), %rax
movsd -0xb0(%rbp,%rax,8), %xmm0
movslq -0x40(%rbp), %rax
movsd -0xb0(%rbp,%rax,8), %xmm2
movsd -0xb8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x59d23
movsd -0xb8(%rbp), %xmm0
movss 0x427b5(%rip), %xmm1    # 0x9c558
cvtss2sd %xmm1, %xmm1
callq 0x1080
movaps %xmm0, %xmm1
movss -0x8c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x8c(%rbp)
movq 0x70(%rbp), %rax
movslq -0x38(%rbp), %rcx
imull $0x3, (%rax,%rcx,4), %eax
movl %eax, -0xcc(%rbp)
movq 0x70(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imull $0x3, (%rax,%rcx,4), %eax
movl %eax, -0xd0(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jge 0x59e74
movss -0x8c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0x40(%rbp), %rax
mulsd -0xb0(%rbp,%rax,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xd4(%rbp)
movss -0xd4(%rbp), %xmm0
movq -0x8(%rbp), %rax
movl -0xcc(%rbp), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
addss (%rax,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
movss -0xd4(%rbp), %xmm1
movq -0x8(%rbp), %rax
movl -0xd0(%rbp), %ecx
addl -0x40(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
subss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x59df6
jmp 0x59a27
jmp 0x59e7b
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x59930
jmp 0x59e8b
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x5989b
movl -0x44(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)