// File: /workspace/github_c_makefile_star2_O3/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, 0x34(%rsp)
movslq 0xbf0(%rsi), %r14
leaq (,%r14,8), %rdi
callq 0x8460
movq %rax, 0xbc0(%rbx)
testq %rax, %rax
je 0xc874c
movq %r15, 0x10(%rsp)
testl %r14d, %r14d
jle 0xc86ec
movq %rax, %r12
movslq 0x330(%rbx), %rbp
movq %rbp, %r13
shlq $0x3, %r13
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x8460
movq %rax, (%r12,%r15,8)
movq 0xbc0(%rbx), %r12
cmpq $0x0, (%r12,%r15,8)
je 0xc8a91
incq %r15
cmpq %r15, %r14
jne 0xc86c6
cmpl $0x4, (%rbx)
jne 0xc8795
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xca730
testl %eax, %eax
je 0xc8ad4
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x25cd8(%rip), %rsi     # 0xee3f0
leaq 0x5e658(%rip), %rdx     # 0x126d77
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x258fc(%rip), %rsi     # 0xee034
leaq 0x5e5f9(%rip), %rdx     # 0x126d38
movq %rbx, %rdi
movl $0x2d9, %ecx            # imm = 0x2D9
jmp 0xc8b1d
shll $0x3, %r14d
leaq 0x258ad(%rip), %rsi     # 0xee004
leaq 0x5e5cc(%rip), %rdx     # 0x126d2a
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x258b6(%rip), %rsi     # 0xee034
leaq 0x5e5b3(%rip), %rdx     # 0x126d38
movq %rbx, %rdi
movl $0x293, %ecx            # imm = 0x293
movq %r15, %r8
jmp 0xc8b20
cmpl $0x0, 0x330(%rbx)
jle 0xc8a8a
xorl %r14d, %r14d
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
divsd 0x318(%rbx), %xmm0
movsd 0x25b0e(%rip), %xmm1    # 0xee2d0
callq 0x8620
xorpd 0x25a61(%rip), %xmm0    # 0xee230
callq 0x8670
movapd %xmm0, %xmm4
movl (%rbx), %eax
cmpl $0x2, %eax
je 0xc88ef
cmpl $0x1, %eax
movsd 0x25a71(%rip), %xmm8    # 0xee260
je 0xc88a3
testl %eax, %eax
jne 0xc89a4
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
movsd 0x318(%rbx), %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm8, %xmm3
ja 0xc8823
movapd 0x10(%rsp), %xmm3
xorpd %xmm1, %xmm1
xorpd %xmm5, %xmm5
ja 0xc8833
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
movapd %xmm8, %xmm6
xorpd %xmm7, %xmm7
movapd %xmm7, 0x10(%rsp)
testb $0x1, %al
jne 0xc8881
cmpltsd %xmm0, %xmm2
andnpd 0x20(%rsp), %xmm2
movapd %xmm2, %xmm6
movapd %xmm5, %xmm1
movapd %xmm3, 0x10(%rsp)
ucomisd %xmm0, %xmm4
jbe 0xc8a2c
xorpd %xmm6, %xmm6
movapd %xmm8, %xmm1
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
jmp 0xc8a2c
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm2
movsd 0x310(%rbx), %xmm0
ucomisd %xmm0, %xmm2
xorpd %xmm1, %xmm1
ja 0xc88c8
movsd 0x8(%rsp), %xmm1
movapd %xmm8, %xmm3
subsd %xmm4, %xmm3
movapd %xmm3, 0x10(%rsp)
ucomisd %xmm2, %xmm0
jbe 0xc8a15
xorpd %xmm6, %xmm6
movapd %xmm8, %xmm1
jmp 0xc8a2c
movsd 0x25969(%rip), %xmm1    # 0xee260
movapd %xmm1, %xmm0
subsd %xmm4, %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
addsd %xmm1, %xmm0
divsd 0x5d52a(%rip), %xmm0    # 0x125e48
movsd 0x5d52a(%rip), %xmm1    # 0x125e50
movapd %xmm4, 0x20(%rsp)
callq 0x8620
movsd 0x25927(%rip), %xmm1    # 0xee260
addsd %xmm1, %xmm0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
addsd %xmm1, %xmm0
divsd 0x5d4f4(%rip), %xmm0    # 0x125e58
movsd 0x5d4f4(%rip), %xmm1    # 0x125e60
callq 0x8620
xorpd 0x258b7(%rip), %xmm0    # 0xee230
callq 0x8670
movsd 0x8(%rsp), %xmm1
movapd 0x20(%rsp), %xmm4
movsd 0x258cd(%rip), %xmm8    # 0xee260
movapd %xmm8, %xmm6
subsd %xmm0, %xmm6
mulsd %xmm4, %xmm6
movl (%rbx), %eax
jmp 0xc89b0
movapd 0x20(%rsp), %xmm6
movsd 0x8(%rsp), %xmm1
cmpl $0x3, %eax
jne 0xc8a2c
movapd %xmm8, %xmm0
subsd %xmm4, %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x340(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
addsd %xmm8, %xmm0
divsd 0x5d46a(%rip), %xmm0    # 0x125e48
movsd 0x5d46a(%rip), %xmm1    # 0x125e50
movapd %xmm4, 0x20(%rsp)
callq 0x8620
movsd 0x25867(%rip), %xmm2    # 0xee260
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movapd %xmm2, %xmm6
subsd %xmm1, %xmm6
mulsd 0x20(%rsp), %xmm6
jmp 0xc8a2c
cmpltsd %xmm2, %xmm0
andpd %xmm0, %xmm4
andnpd 0x20(%rsp), %xmm0
orpd %xmm4, %xmm0
movapd %xmm0, %xmm6
movq 0xbc0(%rbx), %rax
movslq 0xbe0(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movaps 0x10(%rsp), %xmm0
movsd %xmm0, (%rcx,%r14,8)
movslq 0xbe8(%rbx), %rcx
movq (%rax,%rcx,8), %rcx
movsd %xmm1, (%rcx,%r14,8)
movslq 0xbe4(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movapd %xmm6, 0x20(%rsp)
movsd %xmm6, (%rax,%r14,8)
incq %r14
movslq 0x330(%rbx), %rax
movsd %xmm1, 0x8(%rsp)
cmpq %rax, %r14
jl 0xc87a5
xorl %eax, %eax
jmp 0xc8b2c
leal (,%rbp,8), %ecx
leaq 0x25565(%rip), %rsi     # 0xee004
leaq 0x5e2b7(%rip), %rdx     # 0x126d5d
leaq 0x50(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x25571(%rip), %rsi     # 0xee034
leaq 0x5e26e(%rip), %rdx     # 0x126d38
movq %rbx, %rdi
movl $0x297, %ecx            # imm = 0x297
jmp 0xc8b1d
movq %rbx, %rdi
callq 0xcadfe
testl %eax, %eax
je 0xc8b3e
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x25902(%rip), %rsi     # 0xee3f0
leaq 0x5e2a4(%rip), %rdx     # 0x126d99
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x25526(%rip), %rsi     # 0xee034
leaq 0x5e223(%rip), %rdx     # 0x126d38
movq %rbx, %rdi
movl $0x2dc, %ecx            # imm = 0x2DC
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
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 0xc8c4a
movq %rax, %r14
cmpl $0x0, 0x330(%rbx)
jle 0xc8c35
xorl %r15d, %r15d
leaq 0x40(%rsp), %r12
leaq 0x38(%rsp), %r13
leaq 0x34(%rsp), %rbp
movq 0x340(%rbx), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbx, %rdi
leaq 0x48(%rsp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0xcb1a3
testl %eax, %eax
jne 0xc8c90
movsd 0x48(%rsp), %xmm0
movq 0xbc0(%rbx), %rcx
movslq 0xbe0(%rbx), %rax
movq (%rcx,%rax,8), %rax
movsd %xmm0, (%rax,%r15,8)
movsd 0x40(%rsp), %xmm0
movslq 0xbe8(%rbx), %rax
movq (%rcx,%rax,8), %rax
movsd %xmm0, (%rax,%r15,8)
movsd 0x38(%rsp), %xmm0
movslq 0xbe4(%rbx), %rax
movq (%rcx,%rax,8), %rax
movsd %xmm0, (%rax,%r15,8)
movslq 0x4(%rbx), %rax
testq %rax, %rax
jle 0xc8c22
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 0xc8c0a
incq %r15
movslq 0x330(%rbx), %rax
cmpq %rax, %r15
jl 0xc8b7a
movq %rbx, %rdi
callq 0xcb444
movq %r14, %rdi
callq 0x8410
jmp 0xc8a8a
shll $0x3, %r15d
leaq 0x253af(%rip), %rsi     # 0xee004
leaq 0x5e15d(%rip), %rdx     # 0x126db9
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x253b8(%rip), %rsi     # 0xee034
leaq 0x5e0b5(%rip), %rdx     # 0x126d38
movq %rbx, %rdi
movl $0x2e1, %ecx            # imm = 0x2E1
jmp 0xc8b1d
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x25752(%rip), %rsi     # 0xee3f0
leaq 0x5e118(%rip), %rdx     # 0x126dbd
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x25376(%rip), %rsi     # 0xee034
leaq 0x5e073(%rip), %rdx     # 0x126d38
movq %rbx, %rdi
movl $0x2ed, %ecx            # imm = 0x2ED
jmp 0xc8b1d