// File: /workspace/github_c_makefile_star2_O2/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 $0x878, %rsp            # imm = 0x878
movq %rsi, %rbx
andl $0x0, 0x14(%rsp)
movq %rdi, %r14
movslq 0xbf0(%rsi), %r12
movq %r12, %rdi
shlq $0x3, %rdi
callq 0x8490
movq %rax, 0xbc0(%rbx)
testq %rax, %rax
je 0xc11cf
movq %rax, %r15
xorl %ebp, %ebp
testl %r12d, %r12d
movl $0x0, %r13d
cmovgl %r12d, %r13d
cmpq %rbp, %r13
je 0xc1216
movslq 0x330(%rbx), %r12
leaq (,%r12,8), %rdi
callq 0x8490
movq %rax, (%r15,%rbp,8)
movq 0xbc0(%rbx), %r15
cmpq $0x0, (%r15,%rbp,8)
leaq 0x1(%rbp), %rbp
jne 0xc1156
shll $0x3, %r12d
leaq 0x23e70(%rip), %rsi     # 0xe5004
leaq 0x5ca72(%rip), %rdx     # 0x11dc0d
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x23e79(%rip), %rsi     # 0xe5034
leaq 0x5ca26(%rip), %rdx     # 0x11dbe8
movq %rbx, %rdi
movl $0x297, %ecx            # imm = 0x297
jmp 0xc15af
leal (,%r12,8), %ecx
leaq 0x23e26(%rip), %rsi     # 0xe5004
leaq 0x5c9f5(%rip), %rdx     # 0x11dbda
leaq 0x70(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x23e32(%rip), %rsi     # 0xe5034
leaq 0x5c9df(%rip), %rdx     # 0x11dbe8
movq %rbx, %rdi
movl $0x293, %ecx            # imm = 0x293
jmp 0xc15af
cmpl $0x4, (%rbx)
jne 0xc1270
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc3102
testl %eax, %eax
je 0xc1566
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x241b4(%rip), %rsi     # 0xe53f0
leaq 0x5c9e4(%rip), %rdx     # 0x11dc27
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x23dd8(%rip), %rsi     # 0xe5034
leaq 0x5c985(%rip), %rdx     # 0x11dbe8
movq %rbx, %rdi
movl $0x2d9, %ecx            # imm = 0x2D9
jmp 0xc15af
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq 0x330(%rbx), %rax
cmpq %rax, %r15
jge 0xc15bd
movsd %xmm1, 0x8(%rsp)
movaps %xmm7, 0x20(%rsp)
movapd %xmm6, 0x40(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
divsd 0x318(%rbx), %xmm0
movsd 0x2401c(%rip), %xmm1    # 0xe52d0
callq 0x8650
xorpd 0x23f6f(%rip), %xmm0    # 0xe5230
callq 0x86a0
movapd %xmm0, %xmm3
movl (%rbx), %eax
movsd 0x23f8c(%rip), %xmm7    # 0xe5260
subsd %xmm0, %xmm7
cmpl $0x2, %eax
je 0xc13d7
cmpl $0x1, %eax
je 0xc1397
testl %eax, %eax
jne 0xc148e
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
movsd 0x318(%rbx), %xmm2
ucomisd %xmm2, %xmm0
movsd 0x23f4d(%rip), %xmm3    # 0xe5260
movapd 0x20(%rsp), %xmm1
ja 0xc131f
movapd %xmm1, %xmm3
xorpd %xmm1, %xmm1
xorpd %xmm5, %xmm5
ja 0xc132f
movsd 0x8(%rsp), %xmm5
movsd 0x310(%rbx), %xmm4
movapd %xmm4, %xmm6
cmpltpd %xmm0, %xmm6
movapd %xmm0, %xmm7
cmpltpd %xmm2, %xmm7
andpd %xmm6, %xmm7
movd %xmm7, %eax
movsd 0x23f07(%rip), %xmm6    # 0xe5260
xorpd %xmm7, %xmm7
testb $0x1, %al
jne 0xc1378
cmpltsd %xmm0, %xmm2
andnpd 0x40(%rsp), %xmm2
movapd %xmm2, %xmm6
movapd %xmm5, %xmm1
movapd %xmm3, %xmm7
ucomisd %xmm0, %xmm4
jbe 0xc1524
xorpd %xmm6, %xmm6
movsd 0x23ed2(%rip), %xmm1    # 0xe5260
xorpd %xmm7, %xmm7
jmp 0xc1524
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm2
movsd 0x310(%rbx), %xmm0
ucomisd %xmm0, %xmm2
xorpd %xmm1, %xmm1
ja 0xc13bc
movsd 0x8(%rsp), %xmm1
ucomisd %xmm2, %xmm0
jbe 0xc150d
xorpd %xmm6, %xmm6
movsd 0x23e8e(%rip), %xmm1    # 0xe5260
jmp 0xc1524
movsd %xmm7, 0x18(%rsp)
movsd 0x23e7b(%rip), %xmm1    # 0xe5260
movapd %xmm1, %xmm0
subsd %xmm3, %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
addsd %xmm1, %xmm0
divsd 0x5b8ec(%rip), %xmm0    # 0x11ccf8
movsd 0x5b8ec(%rip), %xmm1    # 0x11cd00
movapd %xmm3, 0x30(%rsp)
callq 0x8650
movsd 0x23e39(%rip), %xmm1    # 0xe5260
addsd %xmm1, %xmm0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
addsd %xmm1, %xmm0
divsd 0x5b8b6(%rip), %xmm0    # 0x11cd08
movsd 0x5b8b6(%rip), %xmm1    # 0x11cd10
callq 0x8650
xorpd 0x23dc9(%rip), %xmm0    # 0xe5230
callq 0x86a0
movsd 0x8(%rsp), %xmm1
movapd 0x20(%rsp), %xmm7
movsd 0x23de0(%rip), %xmm6    # 0xe5260
subsd %xmm0, %xmm6
mulsd 0x30(%rsp), %xmm6
movl (%rbx), %eax
jmp 0xc14ac
movapd %xmm3, 0x30(%rsp)
movsd %xmm7, 0x18(%rsp)
movapd 0x40(%rsp), %xmm6
movapd 0x20(%rsp), %xmm7
movsd 0x8(%rsp), %xmm1
cmpl $0x3, %eax
jne 0xc1524
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
movsd 0x23d9a(%rip), %xmm1    # 0xe5260
addsd %xmm1, %xmm0
divsd 0x5b826(%rip), %xmm0    # 0x11ccf8
movsd 0x5b826(%rip), %xmm1    # 0x11cd00
callq 0x8650
movsd 0x23d79(%rip), %xmm2    # 0xe5260
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
movapd 0x30(%rsp), %xmm6
mulsd %xmm0, %xmm6
movsd 0x18(%rsp), %xmm7
jmp 0xc1524
cmpltsd %xmm2, %xmm0
andpd %xmm0, %xmm3
andnpd 0x40(%rsp), %xmm0
orpd %xmm3, %xmm0
movapd %xmm0, %xmm6
movq 0xbc0(%rbx), %rax
movslq 0xbe0(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd %xmm7, (%rcx,%r15,8)
movslq 0xbe8(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd %xmm1, (%rcx,%r15,8)
movslq 0xbe4(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm6, (%rax,%r15,8)
incq %r15
jmp 0xc1276
movq %rbx, %rdi
callq 0xc37b8
testl %eax, %eax
je 0xc15d2
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x23e70(%rip), %rsi     # 0xe53f0
leaq 0x5c6c2(%rip), %rdx     # 0x11dc49
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x23a94(%rip), %rsi     # 0xe5034
leaq 0x5c641(%rip), %rdx     # 0x11dbe8
movq %rbx, %rdi
movl $0x2dc, %ecx            # imm = 0x2DC
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %r14
movl %r14d, %eax
addq $0x878, %rsp            # imm = 0x878
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x4(%rbx), %r15
leaq (,%r15,8), %rdi
callq 0x8490
testq %rax, %rax
je 0xc16c6
movq %rax, %r14
leaq 0x60(%rsp), %r12
leaq 0x58(%rsp), %r13
leaq 0x14(%rsp), %rbp
xorl %r15d, %r15d
movslq 0x330(%rbx), %rax
cmpq %rax, %r15
jge 0xc170c
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbx, %rdi
leaq 0x68(%rsp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0xc3b4c
testl %eax, %eax
jne 0xc1724
movsd 0x68(%rsp), %xmm0
movq 0xbc0(%rbx), %rax
movslq 0xbe0(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd %xmm0, (%rcx,%r15,8)
movsd 0x60(%rsp), %xmm0
movslq 0xbe8(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd %xmm0, (%rcx,%r15,8)
movsd 0x58(%rsp), %xmm0
movslq 0xbe4(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd %xmm0, (%rcx,%r15,8)
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0xc16be
movsd (%r14,%rdx,8), %xmm0
movslq 0xbec(%rbx), %rsi
addq %rdx, %rsi
movq (%rax,%rsi,8), %rsi
movsd %xmm0, (%rsi,%r15,8)
incq %rdx
jmp 0xc169a
incq %r15
jmp 0xc1601
shll $0x3, %r15d
leaq 0x23933(%rip), %rsi     # 0xe5004
leaq 0x5c591(%rip), %rdx     # 0x11dc69
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x2393c(%rip), %rsi     # 0xe5034
leaq 0x5c4e9(%rip), %rdx     # 0x11dbe8
movq %rbx, %rdi
movl $0x2e1, %ecx            # imm = 0x2E1
jmp 0xc15af
movq %rbx, %rdi
callq 0xc3def
movq %r14, %rdi
callq 0x8430
xorl %r14d, %r14d
jmp 0xc15bd
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x23cbe(%rip), %rsi     # 0xe53f0
leaq 0x5c534(%rip), %rdx     # 0x11dc6d
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0x238e2(%rip), %rsi     # 0xe5034
leaq 0x5c48f(%rip), %rdx     # 0x11dbe8
movq %rbx, %rdi
movl $0x2ed, %ecx            # imm = 0x2ED
jmp 0xc15af