// File: /workspace/github_c_makefile_star2_O2/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, 0x58(%rsp)
leaq 0x361fc(%rip), %rdi     # 0x522d1
callq 0x2090
movl 0x47da0(%rip), %esi     # 0x63e80
leaq 0x35a60(%rip), %rdi     # 0x51b47
xorl %eax, %eax
callq 0x20f0
leaq 0x36203(%rip), %rdi     # 0x522f8
callq 0x2090
leaq 0x35a73(%rip), %rdi     # 0x51b74
movl %ebp, %esi
xorl %eax, %eax
callq 0x20f0
leaq 0x35a94(%rip), %rdi     # 0x51ba5
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
cvtss2sd 0xc(%rsp), %xmm0
leaq 0x35ab8(%rip), %rdi     # 0x51bdf
movsd %xmm0, 0x20(%rsp)
movb $0x1, %al
callq 0x20f0
cvtss2sd 0x10(%rsp), %xmm0
leaq 0x35ac6(%rip), %rdi     # 0x51c07
movsd %xmm0, 0x10(%rsp)
movb $0x1, %al
callq 0x20f0
leaq 0x35af1(%rip), %rdi     # 0x51c46
movl %ebp, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
pushq $0xa
popq %rdi
callq 0x2060
movss 0xc(%rsp), %xmm1
movss 0x3507e(%rip), %xmm0    # 0x511f4
mulss %xmm1, %xmm0
movl %ebx, 0x2c(%rsp)
testl %ebx, %ebx
je 0x1c1b4
addss 0x3506e(%rip), %xmm0    # 0x511f8
leaq 0x47f43(%rip), %rax     # 0x640d4
movss %xmm0, (%rax)
leaq 0x47ed8(%rip), %rax     # 0x64074
cvtss2sd (%rax), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x20a0
leaq 0x47cee(%rip), %rax     # 0x63ea0
jmp 0x1c1da
leaq 0x47f19(%rip), %rax     # 0x640d4
movss %xmm0, (%rax)
leaq 0x47eae(%rip), %rax     # 0x64074
mulss (%rax), %xmm1
cvtss2sd %xmm1, %xmm0
callq 0x22a0
leaq 0x47cce(%rip), %rax     # 0x63ea8
movss (%rax), %xmm3
leaq 0x47eef(%rip), %rax     # 0x640d4
movss (%rax), %xmm1
movaps %xmm1, %xmm2
mulss %xmm1, %xmm2
divss %xmm2, %xmm3
mulsd 0x10(%rsp), %xmm0
cvtss2sd %xmm3, %xmm2
movsd %xmm2, 0x70(%rsp)
movss 0x34ff0(%rip), %xmm2    # 0x511fc
mulss %xmm1, %xmm2
mulss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm2
divsd %xmm2, %xmm0
movapd %xmm0, 0xa0(%rsp)
movaps %xmm1, %xmm2
addss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm2
movsd %xmm2, 0x580a8(%rip)    # 0x742e0
mulss 0x34bb8(%rip), %xmm1    # 0x50df8
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x5809c(%rip)    # 0x742e8
cvtsd2ss %xmm0, %xmm1
leaq 0x47e81(%rip), %rax     # 0x640d8
movss %xmm1, (%rax)
movsd 0x35065(%rip), %xmm1    # 0x512c8
mulsd %xmm0, %xmm1
movsd %xmm1, 0x78(%rsp)
movapd 0x2ee4b(%rip), %xmm1    # 0x4b0c0
xorpd %xmm0, %xmm1
movapd %xmm1, 0x90(%rsp)
xorl %r14d, %r14d
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movq %rax, 0x60(%rsp)
movl %ebp, %ebx
leaq 0x48533(%rip), %rax     # 0x647d0
movq %rax, 0x48(%rsp)
leaq 0x47ee7(%rip), %rax     # 0x64190
movq %rax, 0x40(%rsp)
leaq 0x4758b(%rip), %rax     # 0x63840
movq %rax, 0x38(%rsp)
leaq 0x47da7(%rip), %rcx     # 0x64068
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r15d, %r15d
xorl %edx, %edx
movl $0x0, 0x1c(%rsp)
cmpq 0x60(%rsp), %r15
je 0x1c555
movl %edx, 0x28(%rsp)
movl %edx, %eax
movq %rax, 0x80(%rsp)
movq %r14, 0x68(%rsp)
xorl %r13d, %r13d
movq %r15, 0x88(%rsp)
cmpq %r13, %rbx
je 0x1c51a
movq 0x58(%rsp), %rax
movq (%rax,%r15,8), %r12
leaq (%r12,%r14), %rbp
movl $0x42c80000, 0x10(%r12,%r14) # imm = 0x42C80000
cmpl $0x2, 0x47b50(%rip)     # 0x63e80
jne 0x1c36b
cvtss2sd (%rcx), %xmm0
andq $0x0, 0xb8(%r12,%r14)
movsd %xmm0, 0x20(%r12,%r14)
movsd 0x57f92(%rip), %xmm1    # 0x742e0
xorpd 0x2ed6a(%rip), %xmm1    # 0x4b0c0
cmpl $0x0, 0x2c(%rsp)
je 0x1c443
callq 0x20a0
jmp 0x1c44c
movq 0x48(%rsp), %rax
movss (%rax,%r13,4), %xmm0
movss (%rcx), %xmm1
ucomiss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
jae 0x1c56f
movq %rbx, %r15
movsd %xmm0, 0x20(%r12,%r14)
movq 0x40(%rsp), %rax
cvtss2sd (%rax,%r13,4), %xmm0
movq 0x80(%rsp), %rax
leaq (%rax,%r13), %rsi
mulsd 0x70(%rsp), %xmm0
movq 0x38(%rsp), %rax
cvtss2sd (%rax,%r13,4), %xmm1
movq %rbp, %rdi
movq %rcx, %rbx
callq 0x1c5ab
cmpl $0x1, %eax
sbbl $-0x1, 0x1c(%rsp)
movsd 0x20(%r12,%r14), %xmm0
cvtss2sd (%rbx), %xmm1
addsd %xmm0, %xmm1
mulsd 0x2ec8d(%rip), %xmm1    # 0x4b070
movsd %xmm1, 0x20(%rsp)
leaq 0x47c80(%rip), %rax     # 0x64070
movss (%rax), %xmm1
movss %xmm1, 0xc(%rsp)
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x10(%rsp)
cvtsd2ss %xmm0, %xmm0
movq %rbp, %rdi
callq 0x1ac14
movsd 0x20(%rsp), %xmm1
ucomisd 0x10(%rsp), %xmm1
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb8(%r12,%r14)
movss 0xc(%rsp), %xmm0
ja 0x1c436
cvtsd2ss %xmm1, %xmm0
movq %r15, %rbx
movq 0x88(%rsp), %r15
jmp 0x1c49d
mulsd %xmm1, %xmm0
callq 0x22a0
andq $0x0, 0x38(%r12,%r14)
movsd 0x78(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x40(%r12,%r14)
movaps 0xa0(%rsp), %xmm2
movsd %xmm2, 0x48(%r12,%r14)
movapd %xmm0, %xmm2
mulsd 0x90(%rsp), %xmm2
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, 0x30(%r12,%r14)
leaq 0x47bd7(%rip), %rax     # 0x64070
movss (%rax), %xmm0
movss %xmm0, 0x10(%r12,%r14)
movss %xmm0, 0x14(%r12,%r14)
cvtsd2ss 0x20(%r12,%r14), %xmm0
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1b776
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x28(%r12,%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%r12,%r14)
movups %xmm0, 0x80(%r12,%r14)
movups %xmm0, 0x90(%r12,%r14)
testq %r13, %r13
je 0x1c504
imulq $0xc8, %r15, %rdi
movq 0x50(%rsp), %rax
addq (%rax,%r13,8), %rdi
movl $0xc8, %edx
movq %rbp, %rsi
callq 0x21a0
incq %r13
addq $0xc8, %r14
leaq 0x47b53(%rip), %rcx     # 0x64068
jmp 0x1c30a
incq %r15
decq 0x30(%rsp)
decq %rbx
addq $0x8, 0x50(%rsp)
movq 0x68(%rsp), %r14
addq $0xc8, %r14
addq $0x54, 0x48(%rsp)
addq $0x54, 0x40(%rsp)
addq $0x54, 0x38(%rsp)
movl 0x28(%rsp), %edx
addl %r13d, %edx
jmp 0x1c2e1
movl 0x1c(%rsp), %esi
testl %esi, %esi
jne 0x1c5a2
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl 0x30(%rsp), %r13d
cvtss2sd %xmm1, %xmm1
leaq 0x356e3(%rip), %rdi     # 0x51c62
movb $0x2, %al
callq 0x20f0
leaq 0x34c14(%rip), %rdi     # 0x511a1
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270
leaq 0x356e4(%rip), %rdi     # 0x51c8d
jmp 0x1c593