// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x5b26a(%rip), %rdi     # 0x7c1a7
movb $0x0, %al
callq 0x10d0
leaq 0x6b0dd(%rip), %rax     # 0x8c028
movss (%rax), %xmm0
leaq 0x6b0da(%rip), %rax     # 0x8c030
movss %xmm0, (%rax)
leaq 0x6b0cf(%rip), %rax     # 0x8c030
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6b0b8(%rip), %rax     # 0x8c028
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x5b242(%rip), %rdi     # 0x7c1c1
movb $0x2, %al
callq 0x10d0
leaq 0x6b09b(%rip), %rax     # 0x8c028
movss (%rax), %xmm0
leaq 0x6b098(%rip), %rax     # 0x8c030
ucomiss (%rax), %xmm0
jbe 0x20fd3
leaq 0x6b094(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
leaq 0x6b079(%rip), %rax     # 0x8c028
movss (%rax), %xmm1
leaq 0x6b076(%rip), %rax     # 0x8c030
subss (%rax), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6b07b(%rip), %rax     # 0x8c048
movsd %xmm0, (%rax)
jmp 0x20fe1
leaq 0x6b06e(%rip), %rax     # 0x8c048
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x6a5c4(%rip), %rax     # 0x8b5ac
cmpl $0x0, (%rax)
je 0x210d6
leaq 0x6b040(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
leaq 0x6b025(%rip), %rax     # 0x8c034
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6b00e(%rip), %rax     # 0x8c02c
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
callq 0x1080
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
mulsd %xmm1, %xmm0
leaq 0x6afff(%rip), %rax     # 0x8c040
movsd %xmm0, (%rax)
leaq 0x6afe4(%rip), %rax     # 0x8c030
movss (%rax), %xmm0
leaq 0x6afdd(%rip), %rax     # 0x8c034
divss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6afc6(%rip), %rax     # 0x8c02c
movss (%rax), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
cvtss2sd %xmm1, %xmm1
callq 0x1080
leaq 0x6afc1(%rip), %rax     # 0x8c048
mulsd (%rax), %xmm0
leaq 0x6afb6(%rip), %rax     # 0x8c048
movsd %xmm0, (%rax)
leaq 0x6af9b(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6af88(%rip), %rax     # 0x8c034
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x6af71(%rip), %rax     # 0x8c02c
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x5b124(%rip), %rdi     # 0x7c1ee
movb $0x3, %al
callq 0x10d0
jmp 0x211a1
leaq 0x6af5b(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x108(%rbp)
leaq 0x6af40(%rip), %rax     # 0x8c034
movss (%rax), %xmm0
leaq 0x6af2d(%rip), %rax     # 0x8c02c
mulss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1230
movaps %xmm0, %xmm1
movsd -0x108(%rbp), %xmm0
mulsd %xmm1, %xmm0
leaq 0x6af1e(%rip), %rax     # 0x8c040
movsd %xmm0, (%rax)
leaq 0x6af07(%rip), %rax     # 0x8c034
movss (%rax), %xmm0
leaq 0x6aef8(%rip), %rax     # 0x8c030
subss (%rax), %xmm0
leaq 0x6aee9(%rip), %rax     # 0x8c02c
mulss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1230
leaq 0x6aef1(%rip), %rax     # 0x8c048
mulsd (%rax), %xmm0
leaq 0x6aee6(%rip), %rax     # 0x8c048
movsd %xmm0, (%rax)
leaq 0x6aecb(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6aeb8(%rip), %rax     # 0x8c034
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x6aea1(%rip), %rax     # 0x8c02c
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x5b076(%rip), %rdi     # 0x7c210
movb $0x3, %al
callq 0x10d0
cmpq $0x0, -0x18(%rbp)
je 0x213cd
leaq -0xe0(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x5b07e(%rip), %rsi     # 0x7c23c
movb $0x0, %al
callq 0x1200
leaq -0xe0(%rbp), %rdi
leaq 0x5b19f(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
leaq 0x6a3bf(%rip), %rax     # 0x8b5ac
movl (%rax), %edx
leaq 0x6ae36(%rip), %rax     # 0x8c02c
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6ae2f(%rip), %rax     # 0x8c034
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x6ae24(%rip), %rax     # 0x8c038
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x5b035(%rip), %rsi     # 0x7c258
movb $0x3, %al
callq 0x1150
leaq 0x6a37b(%rip), %rax     # 0x8b5ac
cmpl $0x0, (%rax)
je 0x21289
movq -0xe8(%rbp), %rdi
leaq 0x6adf4(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6ade1(%rip), %rax     # 0x8c034
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x6adca(%rip), %rax     # 0x8c02c
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x6adbf(%rip), %rax     # 0x8c030
movss (%rax), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x5b003(%rip), %rsi     # 0x7c283
movb $0x4, %al
callq 0x1150
jmp 0x212da
movq -0xe8(%rbp), %rdi
leaq 0x6ada1(%rip), %rax     # 0x8c038
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6ad8e(%rip), %rax     # 0x8c034
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x6ad77(%rip), %rax     # 0x8c02c
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x6ad6c(%rip), %rax     # 0x8c030
movss (%rax), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x5afd7(%rip), %rsi     # 0x7c2aa
movb $0x4, %al
callq 0x1150
movq -0xe8(%rbp), %rdi
leaq 0x6ad40(%rip), %rax     # 0x8c028
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x5afde(%rip), %rsi     # 0x7c2d5
movb $0x1, %al
callq 0x1150
movq -0xe8(%rbp), %rdi
leaq 0x6ad24(%rip), %rax     # 0x8c030
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x6ad0d(%rip), %rax     # 0x8c028
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x5afbf(%rip), %rsi     # 0x7c2e9
movb $0x2, %al
callq 0x1150
movss 0x54d5b(%rip), %xmm0    # 0x76094
movss %xmm0, -0xec(%rbp)
movss -0xec(%rbp), %xmm1
leaq 0x6acd8(%rip), %rax     # 0x8c028
movss (%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x213c1
movss -0xec(%rbp), %xmm0
callq 0x22100
movss %xmm0, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
movss -0xec(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0xf0(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x5af83(%rip), %rsi     # 0x7c317
movb $0x2, %al
callq 0x1150
movss -0xec(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x54c79(%rip), %xmm1    # 0x76028
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xec(%rbp)
jmp 0x21341
movq -0xe8(%rbp), %rdi
callq 0x10a0
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x21491
movq -0x8(%rbp), %rax
movslq -0xf4(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
ucomisd 0x20(%rax), %xmm0
jb 0x21437
movq -0x8(%rbp), %rax
movslq -0xf4(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
leaq 0x5aefc(%rip), %rdi     # 0x7c322
movb $0x1, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movq -0x8(%rbp), %rax
movslq -0xf4(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x22100
cvtss2sd %xmm0, %xmm0
movq -0x8(%rbp), %rax
movslq -0xf4(%rbp), %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
mulsd 0x28(%rax), %xmm0
movsd %xmm0, 0x28(%rax)
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x213d7
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw (%rax,%rax)