// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/interactions_tnm.c
// Function: Compute_sec_der
void Compute_sec_der(struct interaction *Int_list, int N_int, char *nameout)
{
  // Normalize such that the average contact interaction does
  // not depend on C and E

  // Set parameters for force constant computation
  printf("Computing force constant\n");

  C1_THR=C_THR; //-0.025; // Lower threshold for interpolation
  printf("Interpolating to zero between %.3f and %.3f\n", C1_THR, C_THR);
  if(C_THR>C1_THR){K1=KAPPA/(C_THR-C1_THR);}
  else{K1=0;}

  if(POW){ // power law: C0^-e
    K0=KAPPA*pow(C0,EXP_HESSIAN); 
    K1*=pow((C1_THR/C0),-EXP_HESSIAN);
    printf("Power law k= %.3g (r/%.1f)^-%.1f\n", KAPPA, C0, EXP_HESSIAN);
  }else{
    K0=KAPPA*exp(C0*EXP_HESSIAN);
    K1*=exp((C0-C1_THR)*EXP_HESSIAN);
    printf("Exponential law k= %.3g exp(-(r/%.1f)*%.1f\n",
	   KAPPA, C0, EXP_HESSIAN);
  }

  char name_out[200];
  if(nameout){
    sprintf(name_out,"%s.Inter_Force_constant.dat",nameout);
    // YYY change output file name
    //if(POW){sprintf(name_out, "%s_POW_%.1f.dat", name_out, EXP_HESSIAN);}
    //else{sprintf(name_out, "%s_EXP_%.1f.dat", name_out, EXP_HESSIAN);}
    FILE *file_out=fopen(name_out, "w");
    fprintf(file_out, "# POW= %d EXPO= %.2f C0= %.2f KAPPA= %.2f\n",
	    POW, EXP_HESSIAN, C0, KAPPA);
    
    if(POW){ // power law: C0^-e
      fprintf(file_out, "# f(r)= %.2f (%.2f/r)^%.2f if r< %.2f\n",
	      KAPPA, C0, EXP_HESSIAN, C1_THR);
    }else{ // Exponential
      fprintf(file_out, "# f(r)= %.2f exp((%.2f-r)%.2f) if r< %.2f\n",
	      KAPPA, C0, EXP_HESSIAN, C1_THR);
    }
    fprintf(file_out, "# f(r)= 0 r>= %.2f\n", C_THR);
    fprintf(file_out, "# f(r)= linear interpolation %.2f < r < %.2f\n",
	    C1_THR, C_THR);
    
    for(float r=2.0; r<C_THR; r+=0.05){
      float kappa=Force_constant(r);
      fprintf(file_out, "%.2f %.3g\n", r, kappa);
    }
    fclose(file_out);
  }

  for(int n=0; n<N_int; n++){
    if(Int_list[n].r0<=0){
      printf("ERROR, d2= %.2f\n", Int_list[n].r0); exit(8);
    }
    Int_list[n].sec_der*=Force_constant(Int_list[n].r0);
  }
  if(0){
    printf("\nExpo= %.2f\nV''(r^PDB):\n", EXP_HESSIAN);
    for(int n=0; n<N_int; n++){
      printf("%d-%d %.2g %.2g\n", Int_list[n].res1, Int_list[n].res2,
	     Int_list[n].r0, Int_list[n].sec_der);
    }
    exit(8);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, %r14
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
leaq 0x3e881(%rip), %rdi     # 0x572c0
callq 0x2090
leaq 0x5061d(%rip), %r12     # 0x69068
movss (%r12), %xmm0
leaq 0x50618(%rip), %r15     # 0x69070
movss %xmm0, (%r15)
cvtss2sd %xmm0, %xmm0
leaq 0x3e627(%rip), %rdi     # 0x5708f
movaps %xmm0, %xmm1
movb $0x2, %al
callq 0x20f0
movss (%r12), %xmm1
movss (%r15), %xmm2
ucomiss %xmm2, %xmm1
leaq 0x505f1(%rip), %rax     # 0x69078
movss (%rax), %xmm0
ja 0x18a92
xorps %xmm1, %xmm1
jmp 0x18aa4
subss %xmm2, %xmm1
movaps %xmm0, %xmm2
divss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
leaq 0x505dd(%rip), %r15     # 0x69088
leaq 0x4fb3a(%rip), %rax     # 0x685ec
cmpl $0x0, (%rax)
movsd %xmm1, (%r15)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x505aa(%rip), %rax     # 0x69074
movss (%rax), %xmm0
je 0x18b30
cvtss2sd %xmm0, %xmm0
leaq 0x50591(%rip), %rbp     # 0x6906c
xorps %xmm1, %xmm1
cvtss2sd (%rbp), %xmm1
callq 0x20a0
mulsd (%rsp), %xmm0
leaq 0x5058c(%rip), %rax     # 0x69080
movsd %xmm0, (%rax)
leaq 0x50571(%rip), %rax     # 0x69070
movss (%rax), %xmm0
leaq 0x5056a(%rip), %rax     # 0x69074
divss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movss (%rbp), %xmm1
xorps 0x3de12(%rip), %xmm1    # 0x56930
cvtss2sd %xmm1, %xmm1
callq 0x20a0
leaq 0x3e58e(%rip), %rdi     # 0x570bc
jmp 0x18b83
leaq 0x50535(%rip), %rbp     # 0x6906c
mulss (%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x22a0
mulsd (%rsp), %xmm0
leaq 0x5052f(%rip), %rax     # 0x69080
leaq 0x5051c(%rip), %rcx     # 0x69074
movss (%rcx), %xmm1
leaq 0x5050d(%rip), %rcx     # 0x69070
subss (%rcx), %xmm1
movsd %xmm0, (%rax)
mulss (%rbp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
callq 0x22a0
leaq 0x3e55b(%rip), %rdi     # 0x570de
mulsd (%r15), %xmm0
leaq 0x504e9(%rip), %r13     # 0x69078
cvtss2sd (%r13), %xmm3
leaq 0x504d8(%rip), %rax     # 0x69074
xorps %xmm1, %xmm1
cvtss2sd (%rax), %xmm1
movsd %xmm0, (%r15)
leaq 0x504bd(%rip), %rbp     # 0x6906c
xorps %xmm2, %xmm2
cvtss2sd (%rbp), %xmm2
movaps %xmm3, %xmm0
movb $0x3, %al
callq 0x20f0
testq %r14, %r14
je 0x18d2a
leaq 0x3e539(%rip), %rsi     # 0x5710a
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x3e656(%rip), %rsi     # 0x57240
movq %r15, %rdi
callq 0x2210
movq %rax, %r14
leaq 0x4f9f0(%rip), %r15     # 0x685ec
movl (%r15), %edx
xorps %xmm0, %xmm0
cvtss2sd (%rbp), %xmm0
leaq 0x50466(%rip), %rbp     # 0x69074
xorps %xmm1, %xmm1
cvtss2sd (%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd (%r13), %xmm2
leaq 0x3e500(%rip), %rsi     # 0x57126
movq %rax, %rdi
movb $0x3, %al
callq 0x2190
cmpl $0x0, (%r15)
xorps %xmm0, %xmm0
cvtss2sd (%r13), %xmm0
xorps %xmm1, %xmm1
cvtss2sd (%rbp), %xmm1
leaq 0x50420(%rip), %rax     # 0x6906c
xorps %xmm2, %xmm2
cvtss2sd (%rax), %xmm2
leaq 0x50416(%rip), %r15     # 0x69070
xorps %xmm3, %xmm3
cvtss2sd (%r15), %xmm3
leaq 0x3e50f(%rip), %rax     # 0x57178
leaq 0x3e4e1(%rip), %rsi     # 0x57151
cmoveq %rax, %rsi
movq %r14, %rdi
movb $0x4, %al
callq 0x2190
xorps %xmm0, %xmm0
cvtss2sd (%r12), %xmm0
leaq 0x3e515(%rip), %rsi     # 0x571a3
movq %r14, %rdi
movb $0x1, %al
callq 0x2190
xorps %xmm0, %xmm0
cvtss2sd (%r15), %xmm0
xorps %xmm1, %xmm1
cvtss2sd (%r12), %xmm1
leaq 0x3e507(%rip), %rsi     # 0x571b7
movq %r14, %rdi
movb $0x2, %al
callq 0x2190
movss (%r12), %xmm0
ucomiss 0x3e22d(%rip), %xmm0    # 0x56ef4
jbe 0x18d22
movss 0x3e223(%rip), %xmm0    # 0x56ef4
leaq 0x3e50d(%rip), %r15     # 0x571e5
movss %xmm0, (%rsp)
callq 0x196d6
xorps %xmm2, %xmm2
cvtss2sd (%rsp), %xmm2
movsd %xmm2, (%rsp)
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movq %r14, %rdi
movq %r15, %rsi
movaps %xmm2, %xmm0
movb $0x2, %al
callq 0x2190
movsd (%rsp), %xmm0
addsd 0x38315(%rip), %xmm0    # 0x51028
cvtsd2ss %xmm0, %xmm0
movss (%r12), %xmm1
ucomiss %xmm0, %xmm1
ja 0x18cd8
movq %r14, %rdi
callq 0x20c0
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x18d75
movl %eax, %eax
imulq $0xc8, %rax, %r14
xorl %r15d, %r15d
movsd 0x20(%rbx,%r15), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jae 0x18d87
cvtsd2ss %xmm0, %xmm0
callq 0x196d6
cvtss2sd %xmm0, %xmm0
mulsd 0x28(%rbx,%r15), %xmm0
movsd %xmm0, 0x28(%rbx,%r15)
addq $0xc8, %r15
cmpq %r15, %r14
jne 0x18d3e
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e462(%rip), %rdi     # 0x571f0
movb $0x1, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2270