// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x2068, %rsp           # imm = 0x2068
movq 0x2078(%rsp), %rax
movq 0x2070(%rsp), %rax
movq %rdi, 0x2058(%rsp)
movq %rsi, 0x2050(%rsp)
movq %rdx, 0x2048(%rsp)
movq %rcx, 0x2040(%rsp)
movl %r8d, 0x203c(%rsp)
movsd %xmm0, 0x2030(%rsp)
movq %r9, 0x2028(%rsp)
movsd %xmm1, 0x2020(%rsp)
movsd %xmm2, 0x2018(%rsp)
movq 0x2070(%rsp), %rax
movl $0x1, (%rax)
movl $0x0, 0x2014(%rsp)
movl 0x2014(%rsp), %eax
movq 0x2028(%rsp), %rcx
cmpl 0x178(%rcx), %eax
jge 0xd93ad
movq 0x2058(%rsp), %rdi
movq 0x2050(%rsp), %rsi
movq 0x2048(%rsp), %rdx
movq 0x2040(%rsp), %rcx
movl 0x203c(%rsp), %r8d
movsd 0x2030(%rsp), %xmm0
movsd 0x2020(%rsp), %xmm1
movq 0x2028(%rsp), %r9
callq 0xf8d30
cmpl $0x1, %eax
jne 0xd91df
leaq 0x1800(%rsp), %rdi
movq 0x2040(%rsp), %rcx
addq $0x6c8a, %rcx           # imm = 0x6C8A
leaq 0xf9248(%rip), %rsi     # 0x1d23d8
leaq 0x120cb3(%rip), %rdx    # 0x1f9e4a
movb $0x0, %al
callq 0x5b9c0
movq 0x2040(%rsp), %rdi
addq $0x6c8a, %rdi           # imm = 0x6C8A
leaq 0x1800(%rsp), %r8
leaq 0xf8e78(%rip), %rsi     # 0x1d2034
leaq 0x120cd3(%rip), %rdx    # 0x1f9e96
movl $0xdf6, %ecx            # imm = 0xDF6
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2064(%rsp)
jmp 0xd93b8
movq 0x2028(%rsp), %rax
movq 0x180(%rax), %rax
movslq 0x2014(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x2010(%rsp)
movq 0x2058(%rsp), %rdi
movq 0x2050(%rsp), %rsi
movq 0x2048(%rsp), %rdx
movq 0x2040(%rsp), %rcx
movl 0x203c(%rsp), %r8d
movsd 0x2030(%rsp), %xmm0
movsd 0x2018(%rsp), %xmm1
movq 0x2028(%rsp), %r9
callq 0xf8d30
cmpl $0x1, %eax
jne 0xd92b9
leaq 0x1000(%rsp), %rdi
movq 0x2040(%rsp), %rcx
addq $0x6c8a, %rcx           # imm = 0x6C8A
leaq 0xf916e(%rip), %rsi     # 0x1d23d8
leaq 0x120c4d(%rip), %rdx    # 0x1f9ebe
movb $0x0, %al
callq 0x5b9c0
movq 0x2040(%rsp), %rdi
addq $0x6c8a, %rdi           # imm = 0x6C8A
leaq 0x1000(%rsp), %r8
leaq 0xf8d9e(%rip), %rsi     # 0x1d2034
leaq 0x120bf9(%rip), %rdx    # 0x1f9e96
movl $0xe03, %ecx            # imm = 0xE03
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2064(%rsp)
jmp 0xd93b8
movq 0x2028(%rsp), %rax
movq 0x180(%rax), %rax
movslq 0x2014(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x200c(%rsp)
movl 0x200c(%rsp), %eax
cmpl 0x2010(%rsp), %eax
jge 0xd9359
leaq 0x800(%rsp), %rdi
leaq 0x120c11(%rip), %rsi    # 0x1f9f0a
movb $0x0, %al
callq 0x5b9c0
movq %rsp, %rdi
leaq 0x800(%rsp), %rcx
leaq 0xf8d70(%rip), %rsi     # 0x1d2082
leaq 0x120cd2(%rip), %rdx    # 0x1f9feb
movb $0x0, %al
callq 0x5b9c0
movq 0x2040(%rsp), %rdi
addq $0x6c8a, %rdi           # imm = 0x6C8A
movq %rsp, %r8
leaq 0xf8cfb(%rip), %rsi     # 0x1d2034
leaq 0x120b56(%rip), %rdx    # 0x1f9e96
movl $0xe09, %ecx            # imm = 0xE09
movb $0x0, %al
callq 0x5b9c0
movl $0x1, 0x2064(%rsp)
jmp 0xd93b8
movl 0x200c(%rsp), %ecx
subl 0x2010(%rsp), %ecx
movq 0x2070(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl 0x200c(%rsp), %edx
subl 0x2010(%rsp), %edx
addl $0x1, %edx
movq 0x2078(%rsp), %rax
movslq 0x2014(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x2014(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2014(%rsp)
jmp 0xd910b
movl $0x0, 0x2064(%rsp)
movl 0x2064(%rsp), %eax
addq $0x2068, %rsp           # imm = 0x2068
retq
nopw (%rax,%rax)