// File: /workspace/github_cpp_makefile_star2_O1/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 0xfe262
movl %esi, %eax
leaq 0x2d03a(%rip), %rcx     # 0x12b22c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, %ecx
cmpq $0xa, %rbx
jl 0xfe22c
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 0xfe210
jmp 0xfe22f
movq %rbx, %rdx
cmpl $0x3, %esi
jne 0xfe243
cmpq $0x3, %rdx
je 0xfe256
leaq (%rcx,%rcx,2), %rbx
jmp 0xfe388
cmpl $0x4, %esi
setne %al
cmpq $0x4, %rdx
setne %dil
orb %al, %dil
jne 0xfe2ab
addq %rcx, %rcx
leaq (%rcx,%rcx,4), %rbx
jmp 0xfe388
cmpl $0x63, %esi
je 0xfe309
cmpl $0x1d, %esi
jne 0xfe2e6
movl $0x1, %ecx
cmpq $0x65, %rbx
jl 0xfe357
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 0xfe289
jmp 0xfe35a
cmpl $0x5, %esi
setne %al
cmpq $0x2, %rdx
setne %dil
orb %al, %dil
je 0xfe259
cmpl $0x8, %esi
setne %al
cmpq $0x8, %rdx
setne %dil
orb %al, %dil
je 0xfe256
cmpl $0xa, %esi
je 0xfe360
imulq %rcx, %rdx
addq %rdx, %rdx
jmp 0xfe385
movl $0x5, %esi
jmp 0xfe1fb
incq %rbx
jmp 0xfe388
addq %rbx, %rbx
leaq (%rbx,%rbx,4), %rbx
jmp 0xfe388
addq %rbx, %rbx
jmp 0xfe388
cvtsi2sd %rbx, %xmm0
callq 0x9160
movsd 0x2e375(%rip), %xmm2    # 0x12c690
mulsd %xmm2, %xmm0
addsd 0xad41(%rip), %xmm0     # 0x109068
cvttsd2si %xmm0, %rax
incq %rax
cvtsi2sd %rax, %xmm1
divsd %xmm2, %xmm1
movsd 0xad68(%rip), %xmm0     # 0x1090a8
callq 0x96b0
cvttsd2si %xmm0, %rax
cmpq %rbx, %rax
leaq 0x1(%rbx), %rbx
cmovgq %rax, %rbx
jmp 0xfe388
movq %rbx, %rdx
cmpq $0x15, %rdx
jg 0xfe365
incq %rdx
jmp 0xfe381
cmpq $0x27, %rdx
jg 0xfe371
addq $0x2, %rdx
jmp 0xfe381
cmpq $0x3b, %rdx
jg 0xfe37d
addq $0x5, %rdx
jmp 0xfe381
addq $0xa, %rdx
imulq %rcx, %rdx
movq %rdx, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq