// File: /workspace/github_cpp_makefile_star2_O2/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 0xe8980
movl %esi, %eax
leaq 0x2c910(%rip), %rcx     # 0x11523c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x1
popq %rcx
pushq $0xa
popq %rdi
cmpq $0xa, %rbx
jl 0xe8952
imulq $0xa, %rcx, %rcx
movq %rbx, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rbx
jmp 0xe893b
cmpl $0x3, %esi
jne 0xe8966
cmpq $0x3, %rbx
je 0xe8977
leaq (%rcx,%rcx,2), %rbx
jmp 0xe8a78
cmpl $0x4, %esi
setne %al
cmpq $0x4, %rbx
setne %dl
orb %al, %dl
jne 0xe89ab
imulq $0xa, %rcx, %rbx
jmp 0xe8a78
cmpl $0x63, %esi
je 0xe89e2
cmpl $0x1d, %esi
jne 0xe89c9
pushq $0x1
popq %rcx
pushq $0xa
popq %rsi
cmpq $0x65, %rbx
jl 0xe8a30
imulq $0xa, %rcx, %rcx
movq %rbx, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %rbx
jmp 0xe8990
cmpl $0x5, %esi
setne %al
cmpq $0x2, %rbx
setne %dl
orb %al, %dl
jne 0xe8a42
leaq (%rcx,%rcx,4), %rbx
jmp 0xe8a78
pushq $0x5
popq %rsi
jmp 0xe8935
incq %rbx
jmp 0xe8a78
imulq $0xa, %rbx, %rbx
jmp 0xe8a78
cvtsi2sd %rbx, %xmm0
callq 0x9160
movsd 0x2dca4(%rip), %xmm2    # 0x116698
mulsd %xmm2, %xmm0
addsd 0xa668(%rip), %xmm0     # 0xf3068
cvttsd2si %xmm0, %rax
incq %rax
cvtsi2sd %rax, %xmm1
divsd %xmm2, %xmm1
movsd 0xa68f(%rip), %xmm0     # 0xf30a8
callq 0x96b0
cvttsd2si %xmm0, %rax
cmpq %rbx, %rax
leaq 0x1(%rbx), %rbx
cmovgq %rax, %rbx
jmp 0xe8a78
cmpq $0x15, %rbx
jle 0xe8a5c
cmpq $0x27, %rbx
ja 0xe8a65
addq $0x2, %rbx
jmp 0xe8a5f
cmpl $0x8, %esi
setne %al
cmpq $0x8, %rbx
setne %dl
orb %al, %dl
je 0xe8977
cmpl $0xa, %esi
jne 0xe8a71
incq %rbx
imulq %rcx, %rbx
jmp 0xe8a78
cmpq $0x3b, %rbx
ja 0xe8a82
addq $0x5, %rbx
jmp 0xe8a5f
imulq %rcx, %rbx
addq %rbx, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
addq $0xa, %rbx
jmp 0xe8a5f