// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/distortions.c
// Function: distortions_compute_branching_ratios
int distortions_compute_branching_ratios(struct precision * ppr,
                                         struct distortions* psd){

  /** Define local variables */
  int index_z,index_type,index_k;
  double f_g, f_y, f_mu;
  double *f_E;
  double bb_vis;
  int last_index = 0;

  /** Allocate space for branching ratios in br_table */
  class_alloc(psd->br_table,
              psd->type_size*sizeof(double*),
              psd->error_message);
  for (index_type=0; index_type<psd->type_size; ++index_type){
    class_alloc(psd->br_table[index_type],
                psd->z_size*sizeof(double),
                psd->error_message);
  }

  /** Calulate branching ratios */
  if (psd->sd_branching_approx != bra_exact) {
    for (index_z=0; index_z<psd->z_size; ++index_z){
      bb_vis = exp(-pow(psd->z[index_z]/psd->z_th,2.5));

      /* 1) Calculate branching ratios using sharp_sharp transition */
      if (psd->sd_branching_approx == bra_sharp_sharp) {
        if (psd->z[index_z]>psd->z_th) {
          f_g = 1.;
          f_y = 0.;
          f_mu = 0.;
        }
        if (psd->z[index_z]<psd->z_th && psd->z[index_z]>psd->z_muy) {
          f_g = 0.;
          f_y = 0.;
          f_mu = 1.;
        }
        if (psd->z[index_z]<psd->z_muy) {
          f_g = 0.;
          f_y = 1.;
          f_mu = 0.;
        }
      }

      /* 2) Calculate branching ratios using sharp_soft transition */
      if (psd->sd_branching_approx == bra_sharp_soft) {
        f_g = 1.-bb_vis;
        if (psd->z[index_z]>psd->z_muy) {
          f_y = 0.;
          f_mu = bb_vis;
        }
        if (psd->z[index_z]<psd->z_muy) {
          f_y = 1.;
          f_mu = 0.;
        }
      }

      /* 3) Calculate branching ratios unsing soft_soft transitions */
      if (psd->sd_branching_approx == bra_soft_soft) {
        f_g = 1.-bb_vis;
        f_y = 1.0/(1.0+pow((1.0+psd->z[index_z])/(6.0e4),2.58));
        f_mu = bb_vis*(1.-exp(-pow((1.0+psd->z[index_z])/(5.8e4),1.88)));
      }

      /* 4) Calculate branching ratios unsing soft_soft_cons transitions */
      if (psd->sd_branching_approx == bra_soft_soft_cons) {
        f_g = 1.-bb_vis;
        f_y = 1.0/(1.0+pow((1.0+psd->z[index_z])/(6.0e4),2.58));
        f_mu = bb_vis*(1.-f_y);
      }

      psd->br_table[psd->index_type_g][index_z] = f_g;
      psd->br_table[psd->index_type_y][index_z] = f_y;
      psd->br_table[psd->index_type_mu][index_z] = f_mu;

    }
  }
  else {
    /* 5) Calculate branching ratios according to Chluba & Jeong 2014 */

    /* Read and spline data from file branching_ratios.dat */
    class_call(distortions_read_br_data(ppr,psd),
               psd->error_message,
               psd->error_message);
    class_call(distortions_spline_br_data(psd),
               psd->error_message,
               psd->error_message);

    /* Allocate local variable */
    class_alloc(f_E,
                psd->sd_PCA_size*sizeof(double),
                psd->error_message);

    /* Interpolate over z */
    for (index_z=0; index_z<psd->z_size; ++index_z){
      class_call(distortions_interpolate_br_data(psd,
                                                 psd->z[index_z],
                                                 &f_g,
                                                 &f_y,
                                                 &f_mu,
                                                 f_E,
                                                 &last_index),
                 psd->error_message,
                 psd->error_message);

      /* Store quantities in the table*/
      psd->br_table[psd->index_type_g][index_z] = f_g;
      psd->br_table[psd->index_type_y][index_z] = f_y;
      psd->br_table[psd->index_type_mu][index_z] = f_mu;
      for (index_k=0; index_k<psd->sd_PCA_size; ++index_k){
        psd->br_table[psd->index_type_PCA+index_k][index_z] = f_E[index_k];
      }

    }

    /* Free space allocated in distortions_read_br_data */
    class_call(distortions_free_br_data(psd),
               psd->error_message,
               psd->error_message);
    free(f_E);

  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x858, %rsp            # imm = 0x858
movq %rsi, %rbx
movq %rdi, %r15
movl $0x0, 0x2c(%rsp)
movslq 0xbf0(%rsi), %r14
leaq (,%r14,8), %rdi
callq 0x8460
movq %rax, 0xbc0(%rbx)
testq %rax, %rax
je 0xcbfb4
testl %r14d, %r14d
jle 0xcbf56
movslq 0x330(%rbx), %r13
movq %r13, %r12
shlq $0x3, %r12
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x8460
movq 0xbc0(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0xbc0(%rbx), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0xcc336
incq %rbp
cmpq %rbp, %r14
jne 0xcbf29
cmpl $0x4, (%rbx)
jne 0xcbffd
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcdfa2
testl %eax, %eax
je 0xcc37a
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x25470(%rip), %rsi     # 0xf13f0
leaq 0x5ddc8(%rip), %rdx     # 0x129d4f
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x25094(%rip), %rsi     # 0xf1034
leaq 0x5dd69(%rip), %rdx     # 0x129d10
movq %rbx, %rdi
movl $0x2d9, %ecx            # imm = 0x2D9
jmp 0xcc3c3
shll $0x3, %r14d
leaq 0x25045(%rip), %rsi     # 0xf1004
leaq 0x5dd3c(%rip), %rdx     # 0x129d02
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x2504e(%rip), %rsi     # 0xf1034
leaq 0x5dd23(%rip), %rdx     # 0x129d10
movq %rbx, %rdi
movl $0x293, %ecx            # imm = 0x293
movq %r15, %r8
jmp 0xcc3c6
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm4
cmpl $0x0, 0x330(%rbx)
jle 0xcc312
xorl %r14d, %r14d
movapd %xmm4, 0x40(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
divsd 0x318(%rbx), %xmm0
movsd 0x25283(%rip), %xmm1    # 0xf12d0
callq 0x8620
xorpd 0x251d6(%rip), %xmm0    # 0xf1230
callq 0x8670
movapd 0x40(%rsp), %xmm4
movapd %xmm0, %xmm6
movl (%rbx), %eax
cmpl $0x2, %eax
movapd %xmm0, 0x30(%rsp)
je 0xcc17a
cmpl $0x1, %eax
je 0xcc135
testl %eax, %eax
jne 0xcc252
movq 0x340(%rbx), %rcx
movsd (%rcx,%r14,8), %xmm0
movsd 0x318(%rbx), %xmm1
ucomisd %xmm1, %xmm0
xorpd %xmm2, %xmm2
ja 0xcc0af
movsd (%rsp), %xmm2
movsd 0x251a9(%rip), %xmm3    # 0xf1260
ja 0xcc0bf
movsd 0x8(%rsp), %xmm3
ucomisd %xmm0, %xmm1
cmpltsd %xmm0, %xmm1
andnpd %xmm4, %xmm1
jbe 0xcc0e8
ucomisd 0x310(%rbx), %xmm0
jbe 0xcc0e8
xorpd %xmm2, %xmm2
movsd 0x2517c(%rip), %xmm1    # 0xf1260
xorpd %xmm3, %xmm3
movsd 0x310(%rbx), %xmm4
ucomisd %xmm0, %xmm4
movsd 0x25164(%rip), %xmm5    # 0xf1260
movsd %xmm5, (%rsp)
ja 0xcc108
movsd %xmm2, (%rsp)
xorpd %xmm2, %xmm2
movsd %xmm2, 0x8(%rsp)
ja 0xcc11a
movsd %xmm3, 0x8(%rsp)
cmpl $0x2, %eax
je 0xcc17a
cmpltsd %xmm4, %xmm0
andnpd %xmm1, %xmm0
movapd %xmm0, %xmm4
cmpl $0x1, %eax
jne 0xcc252
movq 0x340(%rbx), %rcx
movsd (%rcx,%r14,8), %xmm0
movsd 0x310(%rbx), %xmm1
ucomisd %xmm1, %xmm0
xorpd %xmm2, %xmm2
ja 0xcc159
movsd (%rsp), %xmm2
ucomisd %xmm0, %xmm1
movsd 0x250fb(%rip), %xmm3    # 0xf1260
movsd %xmm3, (%rsp)
ja 0xcc171
movsd %xmm2, (%rsp)
cmpl $0x2, %eax
jne 0xcc21a
movsd 0x250de(%rip), %xmm1    # 0xf1260
movapd %xmm1, %xmm0
subsd %xmm6, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
addsd %xmm1, %xmm0
divsd 0x5cc6f(%rip), %xmm0    # 0x128e18
movsd 0x5cc6f(%rip), %xmm1    # 0x128e20
callq 0x8620
movsd 0x250a2(%rip), %xmm2    # 0xf1260
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
addsd %xmm2, %xmm0
divsd 0x5cc40(%rip), %xmm0    # 0x128e28
movsd 0x5cc40(%rip), %xmm1    # 0x128e30
callq 0x8620
xorpd 0x25033(%rip), %xmm0    # 0xf1230
callq 0x8670
movapd 0x30(%rsp), %xmm6
movsd 0x25050(%rip), %xmm4    # 0xf1260
subsd %xmm0, %xmm4
mulsd %xmm6, %xmm4
jmp 0xcc252
movsd 0x2503e(%rip), %xmm2    # 0xf1260
subsd %xmm6, %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, %xmm2
cmpltsd %xmm0, %xmm2
movapd %xmm2, %xmm3
andpd %xmm6, %xmm3
andnpd %xmm4, %xmm2
orpd %xmm3, %xmm2
cmpltsd %xmm1, %xmm0
andnpd %xmm2, %xmm0
movapd %xmm0, %xmm4
cmpl $0x3, (%rbx)
jne 0xcc2ba
movsd 0x25001(%rip), %xmm1    # 0xf1260
movapd %xmm1, %xmm0
subsd %xmm6, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
addsd %xmm1, %xmm0
divsd 0x5cb92(%rip), %xmm0    # 0x128e18
movsd 0x5cb92(%rip), %xmm1    # 0x128e20
callq 0x8620
movsd 0x24fc5(%rip), %xmm2    # 0xf1260
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
movapd %xmm2, %xmm4
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
subsd %xmm1, %xmm4
mulsd 0x30(%rsp), %xmm4
movq 0xbc0(%rbx), %rax
movslq 0xbe0(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rcx,%r14,8)
movslq 0xbe8(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd (%rsp), %xmm0
movsd %xmm0, (%rcx,%r14,8)
movslq 0xbe4(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm4, (%rax,%r14,8)
incq %r14
movslq 0x330(%rbx), %rax
cmpq %rax, %r14
jl 0xcc02a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd %xmm4, 0x10(%rsp)
xorl %eax, %eax
jmp 0xcc3d2
leal (,%r13,8), %ecx
leaq 0x24cbf(%rip), %rsi     # 0xf1004
leaq 0x5d9e9(%rip), %rdx     # 0x129d35
leaq 0x50(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x24ccb(%rip), %rsi     # 0xf1034
leaq 0x5d9a0(%rip), %rdx     # 0x129d10
movq %rbx, %rdi
movl $0x297, %ecx            # imm = 0x297
jmp 0xcc3c3
movq %rbx, %rdi
callq 0xce66e
testl %eax, %eax
je 0xcc3e4
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x2505c(%rip), %rsi     # 0xf13f0
leaq 0x5d9d6(%rip), %rdx     # 0x129d71
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x24c80(%rip), %rsi     # 0xf1034
leaq 0x5d955(%rip), %rdx     # 0x129d10
movq %rbx, %rdi
movl $0x2dc, %ecx            # imm = 0x2DC
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x858, %rsp            # imm = 0x858
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x4(%rbx), %r15
leaq (,%r15,8), %rdi
callq 0x8460
testq %rax, %rax
je 0xcc4f0
movq %rax, %r14
cmpl $0x0, 0x330(%rbx)
jle 0xcc4db
xorl %r15d, %r15d
leaq 0x18(%rsp), %r12
leaq 0x10(%rsp), %r13
leaq 0x2c(%rsp), %rbp
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0xcea13
testl %eax, %eax
jne 0xcc536
movsd 0x20(%rsp), %xmm0
movq 0xbc0(%rbx), %rcx
movslq 0xbe0(%rbx), %rax
movq (%rcx,%rax,8), %rax
movsd %xmm0, (%rax,%r15,8)
movsd 0x18(%rsp), %xmm0
movslq 0xbe8(%rbx), %rax
movq (%rcx,%rax,8), %rax
movsd %xmm0, (%rax,%r15,8)
movsd 0x10(%rsp), %xmm0
movslq 0xbe4(%rbx), %rax
movq (%rcx,%rax,8), %rax
movsd %xmm0, (%rax,%r15,8)
movslq 0x4(%rbx), %rax
testq %rax, %rax
jle 0xcc4c8
movslq 0xbec(%rbx), %rdx
leaq (%rcx,%rdx,8), %rcx
xorl %edx, %edx
movsd (%r14,%rdx,8), %xmm0
movq (%rcx,%rdx,8), %rsi
movsd %xmm0, (%rsi,%r15,8)
incq %rdx
cmpq %rdx, %rax
jne 0xcc4b0
incq %r15
movslq 0x330(%rbx), %rax
cmpq %rax, %r15
jl 0xcc420
movq %rbx, %rdi
callq 0xcecb4
movq %r14, %rdi
callq 0x8410
jmp 0xcc32f
shll $0x3, %r15d
leaq 0x24b09(%rip), %rsi     # 0xf1004
leaq 0x5d88f(%rip), %rdx     # 0x129d91
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x24b12(%rip), %rsi     # 0xf1034
leaq 0x5d7e7(%rip), %rdx     # 0x129d10
movq %rbx, %rdi
movl $0x2e1, %ecx            # imm = 0x2E1
jmp 0xcc3c3
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x24eac(%rip), %rsi     # 0xf13f0
leaq 0x5d84a(%rip), %rdx     # 0x129d95
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x24ad0(%rip), %rsi     # 0xf1034
leaq 0x5d7a5(%rip), %rdx     # 0x129d10
movq %rbx, %rdi
movl $0x2ed, %ecx            # imm = 0x2ED
jmp 0xcc3c3