// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/confchange.c
// Function: Test_Renyi
float Test_Renyi(float *wminus2, float *P, int N, char *name, FILE *file1)
{
  /* Tests the Renyi probabilities P^(q-1)\propto -ene -mu
     for various values of the Reniy parameter q
     Returns the value of q that yields best correlation */
  int Newfile=0, i;
  float *y=malloc(N*sizeof(float));
  float q, q1=0, r, slope, offset, qmax=0, rmax=0;
  FILE *file2; char filename[80];
  if(Newfile){
    sprintf(filename, "Renyi_%s.dat", name);
    file2=fopen(filename, "w");
    fprintf(file2, "# Correlation between w_a^-2 and P_q(a)=c_a^2(q-1)\n");
    fprintf(file2, "# q Corr\n");
  }else{
    fprintf(file1, "# P_q(a)=c_a^2(q-1), d_KL r[P_q,1/w^2]\n");
  }

  float wmin=1000, mu;
  for(i=0; i<N; i++)if(wminus2[i]<wmin)wmin=wminus2[i];
  wmin-=0.0001;
  for(q=1; q<=3.5; q+=0.25){
    double d_KL=0, q2=0, Z=0, lnp;
    if(q==1){for(i=0; i<N; i++)y[i]=log(P[i]);}  // q=1: Shannon
    else{for(i=0; i<N; i++)y[i]=pow(P[i], q1);}
    r= Corr_coeff(wminus2, y, N, &slope, &offset);
    if(q==1){
      for(i=0; i<N; i++){
	d_KL+=P[i]*(y[i]-slope*wminus2[i]);
	Z+=exp(slope*wminus2[i]);
      }
    }else{
      q1=q-1; q2=1/q1; 
      if(offset<0){mu=-wmin;}else{mu=offset/slope;}
      for(i=0; i<N; i++){
	lnp=q2*log(wminus2[i]+mu); Z+=exp(lnp);
	d_KL+=P[i]*(log(P[i])-lnp);
      }
    }
    d_KL+=log(Z);
    if(r > rmax){rmax=r; qmax=q;}
    if(Newfile){fprintf(file2, "%.3f  %.3f  %.3f\n", q, d_KL, r);}
    else{fprintf(file1, "q=%.2f                %.3f  %.3f\n",q,d_KL,r);}
  }
  fprintf(file1, "Renyi parameter qopt  %.3f\n", qmax);
  fprintf(file1, "r[P_qopt,1/w^2]       %.3f\n#\n", rmax);
  if(Newfile){
    fclose(file2);
    printf("Writing %s\n", filename);
  }
  free(y);
  return(qmax);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movslq -0x14(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x44eda
leaq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x3ac92(%rip), %rsi     # 0x7fb28
movb $0x0, %al
callq 0x1200
leaq -0xb0(%rbp), %rdi
leaq 0x374c7(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq 0x3ac76(%rip), %rsi     # 0x7fb35
movb $0x0, %al
callq 0x1150
movq -0x60(%rbp), %rdi
leaq 0x3ac98(%rip), %rsi     # 0x7fb69
movb $0x0, %al
callq 0x1150
jmp 0x44eec
movq -0x28(%rbp), %rdi
leaq 0x3ac8e(%rip), %rsi     # 0x7fb73
movb $0x0, %al
callq 0x1150
movss 0x374ec(%rip), %xmm0    # 0x7c3e0
movss %xmm0, -0xb4(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x44f47
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0xb4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x44f3a
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0xb4(%rbp)
jmp 0x44f3c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x44f03
movss -0xb4(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x35cbd(%rip), %xmm1    # 0x7ac18
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xb4(%rbp)
movss 0x3111d(%rip), %xmm0    # 0x76090
movss %xmm0, -0x3c(%rbp)
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x39db7(%rip), %xmm0    # 0x7ed40
ucomisd %xmm1, %xmm0
jb 0x45343
xorps %xmm0, %xmm0
movsd %xmm0, -0xc0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xd0(%rbp)
movss -0x3c(%rbp), %xmm0
movss 0x310cf(%rip), %xmm1    # 0x76090
ucomiss %xmm1, %xmm0
jne 0x4500b
jp 0x4500b
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x45009
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
cvtsd2ss %xmm0, %xmm0
movq -0x38(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x44fcf
jmp 0x45057
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x45055
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x40(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
callq 0x1080
cvtsd2ss %xmm0, %xmm0
movq -0x38(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x45012
jmp 0x45057
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x48(%rbp), %rcx
leaq -0x4c(%rbp), %r8
callq 0x15750
movss %xmm0, -0x44(%rbp)
movss -0x3c(%rbp), %xmm0
movss 0x3100f(%rip), %xmm1    # 0x76090
ucomiss %xmm1, %xmm0
jne 0x4513a
jp 0x4513a
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x45135
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x38(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm2
movss -0x48(%rbp), %xmm1
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm3
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movss -0x48(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1230
addsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x45097
jmp 0x45282
movss -0x3c(%rbp), %xmm0
movss 0x30f49(%rip), %xmm1    # 0x76090
subss %xmm1, %xmm0
movss %xmm0, -0x40(%rbp)
movss 0x30f38(%rip), %xmm0    # 0x76090
divss -0x40(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x4c(%rbp), %xmm0
jbe 0x45191
movss -0xb4(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0xb8(%rbp)
jmp 0x451a3
movss -0x4c(%rbp), %xmm0
divss -0x48(%rbp), %xmm0
movss %xmm0, -0xb8(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x45280
movsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
addss -0xb8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
movaps %xmm0, %xmm1
movsd -0xe8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xd8(%rbp), %xmm0
callq 0x1230
addsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
movaps %xmm0, %xmm2
movsd -0xe0(%rbp), %xmm0
subsd -0xd8(%rbp), %xmm2
movsd -0xc0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x451aa
jmp 0x45282
movsd -0xd0(%rbp), %xmm0
callq 0x10f0
addsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movss -0x44(%rbp), %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0x452be
movss -0x44(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x3c(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x452f2
movq -0x60(%rbp), %rdi
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd -0xc0(%rbp), %xmm1
movss -0x44(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x3a8b2(%rip), %rsi     # 0x7fb9b
movb $0x3, %al
callq 0x1150
jmp 0x4531e
movq -0x28(%rbp), %rdi
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd -0xc0(%rbp), %xmm1
movss -0x44(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x3a896(%rip), %rsi     # 0x7fbad
movb $0x3, %al
callq 0x1150
jmp 0x45320
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x39a17(%rip), %xmm1    # 0x7ed48
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
jmp 0x44f78
movq -0x28(%rbp), %rdi
movss -0x50(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x3a878(%rip), %rsi     # 0x7fbcf
movb $0x1, %al
callq 0x1150
movq -0x28(%rbp), %rdi
movss -0x54(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x3a879(%rip), %rsi     # 0x7fbeb
movb $0x1, %al
callq 0x1150
cmpl $0x0, -0x2c(%rbp)
je 0x4539d
movq -0x60(%rbp), %rdi
callq 0x10a0
leaq -0xb0(%rbp), %rsi
leaq 0x32158(%rip), %rdi     # 0x774ee
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rdi
callq 0x1040
movss -0x50(%rbp), %xmm0
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)