// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: next_tau(long, int)
long next_tau(long tau, int bin_scale)
{
long pow10;
long n;

    switch (bin_scale) {
       case 0 :    // all tau (not practical)
           return tau + 1;

       case 1 :    // one per decade
           return tau * 10;

       case 2 :    // one per octave  (1-2-4-8-16...)
           return tau * 2;

       case 3 :    // 3 dB
       case 4 :    // 1-2-4 decade
       case 5 :    // 1-2-5 decade
       case 8 :    // 1-2-4-8 decade
       case 10 :   // ten per decade
           space_bins:
           pow10 = 1;
           while(tau >= 10) {  // reduce the decade
               pow10 *= 10;
               tau /= 10;
           }

           if(bin_scale == 3) {
               if(tau == 3) return 10 * pow10;
               else         return 3 * pow10;
           }
           if((bin_scale == 4) && (tau == 4)) {
               return 10 * pow10;
           }
           if((bin_scale == 5) && (tau == 2)) {
               return 5 * pow10;
           }
           if((bin_scale == 8) && (tau == 8)) {
               return 10 * pow10;
           }
           if(bin_scale == 10) {
               return (tau + 1) * pow10;
           }
           return tau * 2 * pow10;

       case 29 :    // 29 nice round numbers per decade
           pow10 = 1;
           while(tau > 100) {  // reduce the decade
               pow10 *= 10;
               tau /= 10;
           }

           if(tau < 22) {
               return (tau + 1) * pow10;
           } 
           else if(tau < 40) {
               return (tau + 2) * pow10;
           } 
           else if(tau < 60) {
               return (tau + 5) * pow10;
           } 
           else {
               return (tau + 10) * pow10;
           }

       case 99 :   // logarithmically evenly spaced divisions
           n = (long) (log10((double) tau) * (double)bin_scale + 0.5) + 1;
           n = (long) pow(10.0, (double)n / (double)bin_scale);
           return (n > tau) ? n : tau + 1;

       default : 
          bin_scale = 5;    // 1-2-5 sequence
          goto space_bins;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0xa, %esi
ja 0xfe8e9
movl %esi, %eax
leaq 0x2ca83(%rip), %rcx     # 0x12b2fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, %ecx
cmpq $0xa, %rbx
jl 0xfe8b3
movabsq $-0x3333333333333333, %rdi # imm = 0xCCCCCCCCCCCCCCCD
addq %rcx, %rcx
leaq (%rcx,%rcx,4), %rcx
movq %rbx, %rax
mulq %rdi
shrq $0x3, %rdx
cmpq $0x63, %rbx
movq %rdx, %rbx
ja 0xfe897
jmp 0xfe8b6
movq %rbx, %rdx
cmpl $0x3, %esi
jne 0xfe8ca
cmpq $0x3, %rdx
je 0xfe8dd
leaq (%rcx,%rcx,2), %rbx
jmp 0xfea0f
cmpl $0x4, %esi
setne %al
cmpq $0x4, %rdx
setne %dil
orb %al, %dil
jne 0xfe932
addq %rcx, %rcx
leaq (%rcx,%rcx,4), %rbx
jmp 0xfea0f
cmpl $0x63, %esi
je 0xfe990
cmpl $0x1d, %esi
jne 0xfe96d
movl $0x1, %ecx
cmpq $0x65, %rbx
jl 0xfe9de
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
addq %rcx, %rcx
leaq (%rcx,%rcx,4), %rcx
movq %rbx, %rax
mulq %rsi
shrq $0x3, %rdx
cmpq $0x3f1, %rbx            # imm = 0x3F1
movq %rdx, %rbx
ja 0xfe910
jmp 0xfe9e1
cmpl $0x5, %esi
setne %al
cmpq $0x2, %rdx
setne %dil
orb %al, %dil
je 0xfe8e0
cmpl $0x8, %esi
setne %al
cmpq $0x8, %rdx
setne %dil
orb %al, %dil
je 0xfe8dd
cmpl $0xa, %esi
je 0xfe9e7
imulq %rcx, %rdx
addq %rdx, %rdx
jmp 0xfea0c
movl $0x5, %esi
jmp 0xfe882
incq %rbx
jmp 0xfea0f
addq %rbx, %rbx
leaq (%rbx,%rbx,4), %rbx
jmp 0xfea0f
addq %rbx, %rbx
jmp 0xfea0f
cvtsi2sd %rbx, %xmm0
callq 0x9160
movsd 0x2ddd6(%rip), %xmm2    # 0x12c778
mulsd %xmm2, %xmm0
addsd 0xa6ba(%rip), %xmm0     # 0x109068
cvttsd2si %xmm0, %rax
incq %rax
cvtsi2sd %rax, %xmm1
divsd %xmm2, %xmm1
movsd 0xa6e1(%rip), %xmm0     # 0x1090a8
callq 0x96b0
cvttsd2si %xmm0, %rax
cmpq %rbx, %rax
leaq 0x1(%rbx), %rbx
cmovgq %rax, %rbx
jmp 0xfea0f
movq %rbx, %rdx
cmpq $0x15, %rdx
jg 0xfe9ec
incq %rdx
jmp 0xfea08
cmpq $0x27, %rdx
ja 0xfe9f8
addq $0x2, %rdx
jmp 0xfea08
cmpq $0x3b, %rdx
ja 0xfea04
addq $0x5, %rdx
jmp 0xfea08
addq $0xa, %rdx
imulq %rcx, %rdx
movq %rdx, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq