// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/anharmonic_tnm.c
// Function: Assign_interactions_KB
void Assign_interactions_KB(struct interaction **Int_KB, int Na,
			    int POW, float EXPO, float k0)
{
  // Only repulsion
  printf("Assigning knowledge-based interactions\n");
  printf("--> NPAR = %8d        number of parameters: ", NPAR);
  printf("2 (only repulsion), 3 (barrier)\n");
  printf("--> Na   = %8d        amino acids or atom types\n",Na);
  printf("--> POW  = %8d        1 power law, 0 exponential (kappa)\n", POW);
  printf("--> EXPO = %8.2f        kappa exponent\n",EXPO);
  printf("--> k0   = %8.2f        kappa0 (default value or Bfactor fit)\n",k0);
  printf("--> OUTPUT: Int_KB[%d][%d]\n",Na,Na);
  printf("\n");

  double A4, Scale;
  if(POW){
    lambda=EXPO/4-0.5;
    A4=k0*pow(C0,EXPO); ///(8*lambda*lambda);
    Scale=Scale_Prop_POW/(lambda*lambda);
  }else{
    lambda=EXPO/4;
    A4=k0*exp(C0*EXPO); ///(4*lambda*lambda);
    Scale=Scale_Prop_EXP/(lambda*lambda);
  }
  A4/=(8*lambda*lambda);
  lambda_2=2*lambda;
  lambda_4=4*lambda;
  E_repulsion=A4;
  double A2=2*A4;

  int a, b, n=0, n_err=0; 
  for(a=0; a<Na; a++){
    for(b=a; b<Na; b++){
      double fc2, r3;
      struct interaction *Int_ptr=Int_KB[a]+b;
      Int_ptr->r1=100;
      if(NPAR==2){
	Int_ptr->r0=C_THR;
	Int_ptr->E_min=0;
	if(POW){fc2=pow(C_THR, -lambda_2);}
	else{fc2=exp(-lambda_2*C_THR);}
	Int_ptr->A1=0;
	Int_ptr->A2=-A2*fc2;
	Int_ptr->A4=A4;
	Int_ptr->A0=-Int_ptr->A4*fc2*fc2-Int_ptr->A2*fc2;
	r3=C1_THR;
      }else{ // Three parameters fit
	if(D_Res[a][b]>=C_THR){
	  printf("ERROR, too large KB distance %.2f (> %.2f)",
		 D_Res[a][b], C_THR);
	  printf("for residues %d and %d\n", a, b); exit(8);
	}
	Int_ptr->r0=D_Res[a][b];
	double V0=U_Res[a][b]*Scale;
	if(Determine_Ak(Int_ptr, V0, K_Residues[a][b], n))n_err++;
	r3=(Int_ptr->r0+C_THR)*0.5;
	if(r3>C1_THR)r3=C1_THR;
	Int_ptr->E_min=Compute_V(Int_ptr, Int_ptr->r0);
      }
      Int_ptr->r1=r3;
      Int_ptr->r2=r3;
      Int_ptr->sec_der=Compute_V2(Int_ptr, Int_ptr->r0, 0);
      Int_ptr->a0=0; Int_ptr->a1=0; Int_ptr->a2=0;
      Int_ptr->a3=0; Int_ptr->a4=0; Int_ptr->a5=0;
      //Interpolation(Int_ptr, NULL, r3, C_THR);
      if(b!=a)Int_KB[b][a]=*Int_ptr;
      n++;
    }
  }
  if(n_err){
    printf("ERRORS in KB in %d pairs of residues/atoms out of %d\n",
	   n_err, n); exit(8);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movss %xmm1, 0x8(%rsp)
movss %xmm0, 0x10(%rsp)
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, 0x58(%rsp)
leaq 0x3a15b(%rip), %rdi     # 0x583b1
callq 0x2090
movl 0x4ac1f(%rip), %esi     # 0x68e80
leaq 0x399bf(%rip), %rdi     # 0x57c27
xorl %eax, %eax
callq 0x20f0
leaq 0x3a162(%rip), %rdi     # 0x583d8
callq 0x2090
leaq 0x399d2(%rip), %rdi     # 0x57c54
movl %ebp, %esi
xorl %eax, %eax
callq 0x20f0
leaq 0x399f3(%rip), %rdi     # 0x57c85
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
leaq 0x39a14(%rip), %rdi     # 0x57cbf
movsd %xmm0, 0x20(%rsp)
movb $0x1, %al
callq 0x20f0
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
leaq 0x39a1f(%rip), %rdi     # 0x57ce7
movsd %xmm0, 0x8(%rsp)
movb $0x1, %al
callq 0x20f0
leaq 0x39a4a(%rip), %rdi     # 0x57d26
movl %ebp, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
movl $0xa, %edi
callq 0x2060
movss 0x10(%rsp), %xmm1
movss 0x38fe5(%rip), %xmm0    # 0x572e4
mulss %xmm1, %xmm0
movl %ebx, 0x2c(%rsp)
testl %ebx, %ebx
je 0x1e340
addss 0x38fd5(%rip), %xmm0    # 0x572e8
leaq 0x4adba(%rip), %rax     # 0x690d4
movss %xmm0, (%rax)
leaq 0x4ad4f(%rip), %rax     # 0x69074
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x20a0
leaq 0x4ab62(%rip), %rax     # 0x68ea0
jmp 0x1e369
leaq 0x4ad8d(%rip), %rax     # 0x690d4
movss %xmm0, (%rax)
leaq 0x4ad22(%rip), %rax     # 0x69074
mulss (%rax), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
callq 0x22a0
leaq 0x4ab3f(%rip), %rax     # 0x68ea8
leaq 0x4ad64(%rip), %rcx     # 0x690d4
movss (%rcx), %xmm3
mulsd 0x8(%rsp), %xmm0
movss 0x38f6a(%rip), %xmm1    # 0x572ec
mulss %xmm3, %xmm1
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm0
movaps %xmm3, %xmm1
addss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x5af3b(%rip)    # 0x792e0
movss 0x38b3b(%rip), %xmm1    # 0x56ee8
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x5af2b(%rip)    # 0x792e8
cvtsd2ss %xmm0, %xmm2
movss (%rax), %xmm1
leaq 0x4ad0c(%rip), %rax     # 0x690d8
movss %xmm2, (%rax)
testl %ebp, %ebp
jle 0x1e6f6
mulss %xmm3, %xmm3
divss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x70(%rsp)
movsd 0x38fa6(%rip), %xmm1    # 0x57398
mulsd %xmm0, %xmm1
movsd %xmm1, 0x78(%rsp)
movapd 0x32c8c(%rip), %xmm1    # 0x51090
movaps %xmm0, 0xa0(%rsp)
xorpd %xmm0, %xmm1
movapd %xmm1, 0x90(%rsp)
movl %ebp, %r12d
xorl %r14d, %r14d
leaq 0x4b3aa(%rip), %rax     # 0x697d0
movq %rax, 0x48(%rsp)
leaq 0x4ad5e(%rip), %rax     # 0x69190
movq %rax, 0x40(%rsp)
leaq 0x4a402(%rip), %rax     # 0x68840
movq %rax, 0x38(%rsp)
leaq 0x4ac1e(%rip), %rcx     # 0x69068
movq %r12, 0x60(%rsp)
movq %r12, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
xorl %edx, %edx
xorl %r15d, %r15d
movl $0x0, 0x1c(%rsp)
xorl %eax, %eax
movq %rdx, 0x30(%rsp)
movl %eax, %r12d
movq %r14, 0x68(%rsp)
xorl %r13d, %r13d
movq %r15, 0x80(%rsp)
movq 0x58(%rsp), %rax
movq (%rax,%r15,8), %rbp
leaq (%r14,%rbp), %rbx
movl $0x42c80000, 0x10(%rbp,%r14) # imm = 0x42C80000
cmpl $0x2, 0x4a9de(%rip)     # 0x68e80
jne 0x1e4e3
xorps %xmm0, %xmm0
cvtss2sd (%rcx), %xmm0
movsd %xmm0, 0x20(%rbp,%r14)
movq $0x0, 0xb8(%rbp,%r14)
movsd 0x5ae1a(%rip), %xmm1    # 0x792e0
xorpd 0x32bc2(%rip), %xmm1    # 0x51090
cmpl $0x0, 0x2c(%rsp)
je 0x1e5c7
callq 0x20a0
jmp 0x1e5d0
movq 0x48(%rsp), %rax
movss (%rax,%r13,4), %xmm0
movss (%rcx), %xmm1
ucomiss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
jae 0x1e711
movsd %xmm0, 0x20(%rbp,%r14)
movq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r13,4), %xmm0
movq %r12, %r15
leaq (%r12,%r13), %rsi
mulsd 0x70(%rsp), %xmm0
movq 0x38(%rsp), %rax
xorps %xmm1, %xmm1
cvtss2sd (%rax,%r13,4), %xmm1
movq %rbx, %rdi
movq %rcx, %r12
callq 0x1e752
cmpl $0x1, %eax
sbbl $-0x1, 0x1c(%rsp)
movsd 0x20(%rbp,%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd (%r12), %xmm1
addsd %xmm0, %xmm1
mulsd 0x32afa(%rip), %xmm1    # 0x51058
movsd %xmm1, 0x88(%rsp)
leaq 0x4ab02(%rip), %rax     # 0x69070
movss (%rax), %xmm1
movss %xmm1, 0x8(%rsp)
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x20(%rsp)
cvtsd2ss %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1ccef
movsd 0x88(%rsp), %xmm1
ucomisd 0x20(%rsp), %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb8(%rbp,%r14)
movss 0x8(%rsp), %xmm0
ja 0x1e5ba
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq %r15, %r12
movq 0x80(%rsp), %r15
jmp 0x1e624
mulsd %xmm1, %xmm0
callq 0x22a0
movq $0x0, 0x38(%rbp,%r14)
movsd 0x78(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rbp,%r14)
movaps 0xa0(%rsp), %xmm2
movsd %xmm2, 0x48(%rbp,%r14)
movapd %xmm0, %xmm2
mulsd 0x90(%rsp), %xmm2
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, 0x30(%rbp,%r14)
leaq 0x4aa50(%rip), %rax     # 0x69070
movss (%rax), %xmm0
movss %xmm0, 0x10(%rbp,%r14)
movss %xmm0, 0x14(%rbp,%r14)
xorps %xmm0, %xmm0
cvtsd2ss 0x20(%rbp,%r14), %xmm0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1d8bb
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x28(%rbp,%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbp,%r14)
movups %xmm0, 0x80(%rbp,%r14)
movups %xmm0, 0x90(%rbp,%r14)
testq %r13, %r13
je 0x1e68e
imulq $0xc8, %r15, %rdi
movq 0x50(%rsp), %rax
addq (%rax,%r13,8), %rdi
movl $0xc8, %edx
movq %rbx, %rsi
callq 0x21a0
incq %r13
addq $0xc8, %r14
cmpq %r13, 0x10(%rsp)
leaq 0x4a9c4(%rip), %rcx     # 0x69068
jne 0x1e485
incq %r15
movq 0x30(%rsp), %rdx
decq %rdx
addq $0x8, 0x50(%rsp)
movq 0x68(%rsp), %r14
addq $0xc8, %r14
addq $0x54, 0x48(%rsp)
addq $0x54, 0x40(%rsp)
addq $0x54, 0x38(%rsp)
decq 0x10(%rsp)
leal (%r12,%r13), %eax
cmpq 0x60(%rsp), %r15
jne 0x1e46d
addl %r13d, %r12d
movl 0x1c(%rsp), %esi
jmp 0x1e6fb
xorl %r12d, %r12d
xorl %esi, %esi
testl %esi, %esi
jne 0x1e746
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl 0x30(%rsp), %r13d
cvtss2sd %xmm1, %xmm1
leaq 0x39621(%rip), %rdi     # 0x57d42
movb $0x2, %al
callq 0x20f0
leaq 0x38b62(%rip), %rdi     # 0x57291
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270
leaq 0x39620(%rip), %rdi     # 0x57d6d
movl %r12d, %edx
jmp 0x1e735