// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, 0x60(%rsp)
leaq 0x3a85c(%rip), %rdi     # 0x58371
callq 0x2090
movl 0x4b360(%rip), %esi     # 0x68e80
leaq 0x3a0c0(%rip), %rdi     # 0x57be7
xorl %eax, %eax
callq 0x20f0
leaq 0x3a863(%rip), %rdi     # 0x58398
callq 0x2090
leaq 0x3a0d3(%rip), %rdi     # 0x57c14
movl %ebp, %esi
xorl %eax, %eax
callq 0x20f0
leaq 0x3a0f4(%rip), %rdi     # 0x57c45
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rsp), %xmm0
leaq 0x3a115(%rip), %rdi     # 0x57c7f
movsd %xmm0, 0x20(%rsp)
movb $0x1, %al
callq 0x20f0
xorps %xmm0, %xmm0
cvtss2sd 0x10(%rsp), %xmm0
leaq 0x3a120(%rip), %rdi     # 0x57ca7
movsd %xmm0, 0x10(%rsp)
movb $0x1, %al
callq 0x20f0
leaq 0x3a14b(%rip), %rdi     # 0x57ce6
movl %ebp, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
movl $0xa, %edi
callq 0x2060
movss 0xc(%rsp), %xmm1
movss 0x396e6(%rip), %xmm0    # 0x572a4
mulss %xmm1, %xmm0
movl %ebx, 0x2c(%rsp)
testl %ebx, %ebx
je 0x1dbff
addss 0x396d6(%rip), %xmm0    # 0x572a8
leaq 0x4b4fb(%rip), %rax     # 0x690d4
movss %xmm0, (%rax)
leaq 0x4b490(%rip), %rax     # 0x69074
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x20a0
leaq 0x4b2a3(%rip), %rax     # 0x68ea0
jmp 0x1dc28
leaq 0x4b4ce(%rip), %rax     # 0x690d4
movss %xmm0, (%rax)
leaq 0x4b463(%rip), %rax     # 0x69074
mulss (%rax), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
callq 0x22b0
leaq 0x4b280(%rip), %rax     # 0x68ea8
leaq 0x4b4a5(%rip), %rcx     # 0x690d4
movss (%rcx), %xmm3
mulsd 0x10(%rsp), %xmm0
movss 0x3966b(%rip), %xmm1    # 0x572ac
mulss %xmm3, %xmm1
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm0
movaps %xmm3, %xmm1
addss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x5b67c(%rip)    # 0x792e0
movss 0x3923c(%rip), %xmm1    # 0x56ea8
mulss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x5b66c(%rip)    # 0x792e8
cvtsd2ss %xmm0, %xmm2
movss (%rax), %xmm1
leaq 0x4b44d(%rip), %rax     # 0x690d8
movss %xmm2, (%rax)
testl %ebp, %ebp
jle 0x1dfb9
mulss %xmm3, %xmm3
divss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x78(%rsp)
movsd 0x396b7(%rip), %xmm1    # 0x57368
mulsd %xmm0, %xmm1
movsd %xmm1, 0x80(%rsp)
movapd 0x333ca(%rip), %xmm1    # 0x51090
movaps %xmm0, 0xa0(%rsp)
xorpd %xmm0, %xmm1
movapd %xmm1, 0x90(%rsp)
movl %ebp, %r13d
xorl %r14d, %r14d
leaq 0x4bae8(%rip), %rax     # 0x697d0
movq %rax, 0x48(%rsp)
leaq 0x4b49c(%rip), %rax     # 0x69190
movq %rax, 0x40(%rsp)
leaq 0x4ab40(%rip), %rax     # 0x68840
movq %rax, 0x38(%rsp)
leaq 0x4b35c(%rip), %rcx     # 0x69068
movq %r13, 0x68(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x58(%rsp)
xorl %esi, %esi
xorl %r15d, %r15d
movl $0x0, 0x1c(%rsp)
xorl %eax, %eax
movq %rsi, 0x30(%rsp)
movl %eax, %eax
movq %rax, 0x50(%rsp)
movq %r14, 0x70(%rsp)
xorl %r12d, %r12d
movq %r15, 0x88(%rsp)
movq 0x60(%rsp), %rax
movq (%rax,%r15,8), %rbp
leaq (%r14,%rbp), %rbx
movl $0x42c80000, 0x10(%rbp,%r14) # imm = 0x42C80000
cmpl $0x2, 0x4b11d(%rip)     # 0x68e80
jne 0x1dda4
xorps %xmm0, %xmm0
cvtss2sd (%rcx), %xmm0
movsd %xmm0, 0x20(%rbp,%r14)
movq $0x0, 0xb8(%rbp,%r14)
movsd 0x5b559(%rip), %xmm1    # 0x792e0
xorpd 0x33301(%rip), %xmm1    # 0x51090
cmpl $0x0, 0x2c(%rsp)
je 0x1de87
callq 0x20a0
jmp 0x1de90
movq 0x48(%rsp), %rax
movss (%rax,%r12,4), %xmm0
movss (%rcx), %xmm1
ucomiss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
jae 0x1dfcb
movq %r13, %r15
movsd %xmm0, 0x20(%rbp,%r14)
movq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq 0x50(%rsp), %rax
leaq (%rax,%r12), %rsi
mulsd 0x78(%rsp), %xmm0
movq 0x38(%rsp), %rax
xorps %xmm1, %xmm1
cvtss2sd (%rax,%r12,4), %xmm1
movq %rbx, %rdi
movq %rcx, %r13
callq 0x1e00c
cmpl $0x1, %eax
sbbl $-0x1, 0x1c(%rsp)
movsd 0x20(%rbp,%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd (%r13), %xmm1
addsd %xmm0, %xmm1
mulsd 0x3334c(%rip), %xmm1    # 0x51170
movsd %xmm1, 0x20(%rsp)
leaq 0x4b23f(%rip), %rax     # 0x69070
movss (%rax), %xmm1
movss %xmm1, 0xc(%rsp)
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x10(%rsp)
cvtsd2ss %xmm0, %xmm0
movq %rbx, %rdi
callq 0x1c59a
movsd 0x20(%rsp), %xmm1
ucomisd 0x10(%rsp), %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb8(%rbp,%r14)
movss 0xc(%rsp), %xmm0
ja 0x1de7a
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq %r15, %r13
movq 0x88(%rsp), %r15
jmp 0x1dee7
mulsd %xmm1, %xmm0
callq 0x22b0
movq $0x0, 0x38(%rbp,%r14)
movsd 0x80(%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 0x4b18d(%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 0x1d161
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 %r12, %r12
je 0x1df51
imulq $0xc8, %r15, %rdi
movq 0x58(%rsp), %rax
addq (%rax,%r12,8), %rdi
movl $0xc8, %edx
movq %rbx, %rsi
callq 0x21b0
incq %r12
addq $0xc8, %r14
cmpq %r12, %r13
leaq 0x4b103(%rip), %rcx     # 0x69068
jne 0x1dd46
incq %r15
movq 0x30(%rsp), %rsi
decq %rsi
addq $0x8, 0x58(%rsp)
movq 0x70(%rsp), %r14
addq $0xc8, %r14
addq $0x54, 0x48(%rsp)
addq $0x54, 0x40(%rsp)
addq $0x54, 0x38(%rsp)
decq %r13
movq 0x50(%rsp), %rdx
leal (%rdx,%r12), %eax
cmpq 0x68(%rsp), %r15
jne 0x1dd2a
movl 0x1c(%rsp), %esi
testl %esi, %esi
jne 0x1e000
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl 0x30(%rsp), %r12d
cvtss2sd %xmm1, %xmm1
leaq 0x39d27(%rip), %rdi     # 0x57d02
movb $0x2, %al
callq 0x20f0
leaq 0x39268(%rip), %rdi     # 0x57251
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280
addq %r12, %rdx
leaq 0x39d23(%rip), %rdi     # 0x57d2d
jmp 0x1dfef