// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/perturbations.c
// Function: perturbations_find_approximation_number
int perturbations_find_approximation_number(
                                            struct precision * ppr,
                                            struct background * pba,
                                            struct thermodynamics * pth,
                                            struct perturbations * ppt,
                                            int index_md,
                                            double k,
                                            struct perturbations_workspace * ppw,
                                            double tau_ini,
                                            double tau_end,
                                            int * interval_number,
                                            int * interval_number_of /* interval_number_of[index_ap] (already allocated) */
                                            ){

  /** Summary: */
  /* index running over approximations */
  int index_ap;

  /* value of a given approximation at tau_ini and tau_end */
  int flag_ini,flag_end;

  /** - fix default number of intervals to one (if no approximation switch) */

  *interval_number=1;

  /** - loop over each approximation and add the number of approximation switching times */

  for (index_ap=0; index_ap<ppw->ap_size; index_ap++) {

    class_call(perturbations_approximations(ppr,
                                            pba,
                                            pth,
                                            ppt,
                                            index_md,
                                            k,
                                            tau_ini,
                                            ppw),
               ppt->error_message,
               ppt->error_message);

    flag_ini = ppw->approx[index_ap];

    class_call(perturbations_approximations(ppr,
                                            pba,
                                            pth,
                                            ppt,
                                            index_md,
                                            k,
                                            tau_end,
                                            ppw),
               ppt->error_message,
               ppt->error_message);

    flag_end = ppw->approx[index_ap];

    class_test(flag_end<flag_ini,
               ppt->error_message,
               "For each approximation scheme, the declaration of approximation labels in the enumeration must follow chronological order, e.g: enum approx_flags {flag1, flag2, flag3} with flag1 being the initial one and flag3 the final one");

    *interval_number += flag_end-flag_ini;

    interval_number_of[index_ap] = flag_end-flag_ini+1;
  }

  return _SUCCESS_;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
movsd %xmm2, 0x30(%rsp)
movsd %xmm1, 0x38(%rsp)
movq 0x1080(%rsp), %rax
movl $0x1, (%rax)
cmpl $0x0, 0x178(%r9)
jle 0x7de7a
movq %r9, %r14
movl %r8d, %ebp
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
xorl %ebx, %ebx
movsd %xmm0, 0x18(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl %ebp, %r8d
movsd 0x38(%rsp), %xmm1
movq %r14, %r9
callq 0x8d6b1
testl %eax, %eax
jne 0x7de81
movq 0x180(%r14), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rbx,4), %eax
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %r12
movq %r13, %rdx
movq %rcx, %r13
movl %ebp, %r15d
movl %ebp, %r8d
movsd 0x18(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movq %r14, %r9
callq 0x8d6b1
testl %eax, %eax
jne 0x7dec5
movq 0x180(%r14), %rax
movl (%rax,%rbx,4), %eax
subl 0xc(%rsp), %eax
jl 0x7df07
movq 0x1080(%rsp), %rcx
addl %eax, (%rcx)
incl %eax
movq 0x1088(%rsp), %rcx
movl %eax, (%rcx,%rbx,4)
incq %rbx
movslq 0x178(%r14), %rax
cmpq %rax, %rbx
movq %r13, %rcx
movsd 0x18(%rsp), %xmm0
movl %r15d, %ebp
movq %r12, %r13
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r15
jl 0x7ddbd
xorl %eax, %eax
jmp 0x7df6c
movq 0x10(%rsp), %r12
addq $0x6c8a, %r12           # imm = 0x6C8A
leaq 0x7355c(%rip), %rsi     # 0xf13f0
leaq 0x9af37(%rip), %rdx     # 0x118dd2
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x73180(%rip), %rsi     # 0xf1034
leaq 0x9af63(%rip), %rdx     # 0x118e1e
movq %r12, %rdi
movl $0xdf6, %ecx            # imm = 0xDF6
jmp 0x7df02
addq $0x6c8a, %r13           # imm = 0x6C8A
leaq 0x7351d(%rip), %rsi     # 0xf13f0
leaq 0x9af6c(%rip), %rdx     # 0x118e46
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x30c2c
leaq 0x73141(%rip), %rsi     # 0xf1034
leaq 0x9af24(%rip), %rdx     # 0x118e1e
movq %r13, %rdi
movl $0xe03, %ecx            # imm = 0xE03
movq %r14, %r8
jmp 0x7df60
leaq 0x9af84(%rip), %rsi     # 0x118e92
leaq 0x40(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
leaq 0x7315e(%rip), %rsi     # 0xf1082
leaq 0x9b048(%rip), %rdx     # 0x118f73
leaq 0x840(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x6c8a, %r13           # imm = 0x6C8A
leaq 0x730e6(%rip), %rsi     # 0xf1034
leaq 0x9aec9(%rip), %rdx     # 0x118e1e
movq %r13, %rdi
movl $0xe09, %ecx            # imm = 0xE09
movq %rbx, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq