// File: /workspace/github_c_makefile_star2_O3/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 0x7b2b9
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 0x8ab21
testl %eax, %eax
jne 0x7b2c0
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 0x8ab21
testl %eax, %eax
jne 0x7b304
movq 0x180(%r14), %rax
movl (%rax,%rbx,4), %eax
subl 0xc(%rsp), %eax
jl 0x7b346
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 0x7b1fc
xorl %eax, %eax
jmp 0x7b3ab
movq 0x10(%rsp), %r12
addq $0x6c8a, %r12           # imm = 0x6C8A
leaq 0x7311d(%rip), %rsi     # 0xee3f0
leaq 0x9ab38(%rip), %rdx     # 0x115e12
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x72d41(%rip), %rsi     # 0xee034
leaq 0x9ab64(%rip), %rdx     # 0x115e5e
movq %r12, %rdi
movl $0xdf6, %ecx            # imm = 0xDF6
jmp 0x7b341
addq $0x6c8a, %r13           # imm = 0x6C8A
leaq 0x730de(%rip), %rsi     # 0xee3f0
leaq 0x9ab6d(%rip), %rdx     # 0x115e86
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0x72d02(%rip), %rsi     # 0xee034
leaq 0x9ab25(%rip), %rdx     # 0x115e5e
movq %r13, %rdi
movl $0xe03, %ecx            # imm = 0xE03
movq %r14, %r8
jmp 0x7b39f
leaq 0x9ab85(%rip), %rsi     # 0x115ed2
leaq 0x40(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0x72d1f(%rip), %rsi     # 0xee082
leaq 0x9ac49(%rip), %rdx     # 0x115fb3
leaq 0x840(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x6c8a, %r13           # imm = 0x6C8A
leaq 0x72ca7(%rip), %rsi     # 0xee034
leaq 0x9aaca(%rip), %rdx     # 0x115e5e
movq %r13, %rdi
movl $0xe09, %ecx            # imm = 0xE09
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %eax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq