// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: fetch_adev_info(unsigned char, ADEV_INFO*)
int fetch_adev_info(u08 dev_id, struct ADEV_INFO *bins)
{
double adev;
double tau;
long on;
struct BIN *table;

    if     (dev_id == PPS_ADEV) table = &pps_adev_bins[0];
    else if(dev_id == OSC_ADEV) table = &osc_adev_bins[0];
    else if(dev_id == CHC_ADEV) table = &chc_adev_bins[0];
    else if(dev_id == CHD_ADEV) table = &chd_adev_bins[0];

    else if(dev_id == PPS_HDEV) table = &pps_hdev_bins[0];
    else if(dev_id == OSC_HDEV) table = &osc_hdev_bins[0];
    else if(dev_id == CHC_HDEV) table = &chc_hdev_bins[0];
    else if(dev_id == CHD_HDEV) table = &chd_hdev_bins[0];

    else if(dev_id == PPS_MDEV) table = &pps_mdev_bins[0];
    else if(dev_id == OSC_MDEV) table = &osc_mdev_bins[0];
    else if(dev_id == CHC_MDEV) table = &chc_mdev_bins[0];
    else if(dev_id == CHD_MDEV) table = &chd_mdev_bins[0];

    else if(dev_id == PPS_TDEV) table = &pps_tdev_bins[0];
    else if(dev_id == OSC_TDEV) table = &osc_tdev_bins[0];
    else if(dev_id == CHC_TDEV) table = &chc_tdev_bins[0];
    else if(dev_id == CHD_TDEV) table = &chd_tdev_bins[0];

    else if(dev_id == A_MTIE) return fetch_mtie_info(CHA_MTIE, bins);
    else if(dev_id == B_MTIE) return fetch_mtie_info(CHB_MTIE, bins);
    else if(dev_id == C_MTIE) return fetch_mtie_info(CHC_MTIE, bins);
    else if(dev_id == D_MTIE) return fetch_mtie_info(CHD_MTIE, bins);
    else {
       sprintf(out, "Bad dev_id in calc_adevs: %d\n", dev_id);
       error_exit(92, out);
    }

    bins->adev_min = 1.0e29F;
    bins->adev_max = (-1.0e29F);
    bins->bin_count = 0;
    bins->adev_type = dev_id;

    // convert data from the incremental adev bins into the
    // old style adev tables (so we don't have to mess with changing
    // all that old well-debugged display code).
    while(bins->bin_count < MAX_ADEV_BINS) {
        on = table[bins->bin_count].n;
        if(on < min_points_per_bin) {
           if(1) {  // zap unused entries   // aaaahhhh
              bins->adev_on[bins->bin_count] = 0;
              bins->adev_taus[bins->bin_count] = (float) 0.0;
              bins->adev_bins[bins->bin_count] = (float) 0.0;
           }
////bins->bin_count += 1;
////continue;
           break;
        }

        tau = (double) table[bins->bin_count].tau;

        adev = table[bins->bin_count].value;

        bins->adev_on[bins->bin_count] = on;
        bins->adev_taus[bins->bin_count] = (float) tau;
        bins->adev_bins[bins->bin_count] = (float) adev;

        bins->bin_count += 1;
        if(adev > bins->adev_max) bins->adev_max = (float) adev;
        if(adev < bins->adev_min) bins->adev_min = (float) adev;
    }

    if(1 && global_adev_max) {  // give all adev plots the same top decade
       bins->adev_max = (float) global_adev_max;
    }

    bins->adev_max = adev_decade(bins->adev_max);

    // !!!!!! force tidy ADEV graph scale factors
    // aaaahhhh - we need to do this better... what if one VERT_MAJOR per decade
    if((PLOT_HEIGHT/VERT_MAJOR) <= 6) {  // three decades (/VS - makes for a cramped plot) 
       bins->adev_min = bins->adev_max * 1.0e-6F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 8) {  // four decades
       bins->adev_min = bins->adev_max * 1.0e-4F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 10) {  // five decades (/VM)
       bins->adev_min = bins->adev_max * 1.0e-5F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 12) {  // six decades
       bins->adev_min = bins->adev_max * 1.0e-6F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 14) {  // seven decades
       bins->adev_min = bins->adev_max * 1.0e-7F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 16) {  // eight decades (/VL)
       bins->adev_min = bins->adev_max * 1.0e-8F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 18) {  // nine decades
       bins->adev_min = bins->adev_max * 1.0e-9F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 20) {  // ten decades
       bins->adev_min = bins->adev_max * 1.0e-10F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 22) {  // eleven decades
       bins->adev_min = bins->adev_max * 1.0e-11F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 24) {  // twelve decades
       bins->adev_min = bins->adev_max * 1.0e-12F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 26) {  // 13 decades
       bins->adev_min = bins->adev_max * 1.0e-13F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 28) {  // 14 decades
       bins->adev_min = bins->adev_max * 1.0e-14F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 30) {  // 15 decades
       bins->adev_min = bins->adev_max * 1.0e-15F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 32) {  // 16 decades
       bins->adev_min = bins->adev_max * 1.0e-16F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 34) {  // 17 decades
       bins->adev_min = bins->adev_max * 1.0e-17F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 36) {  // 18 decades
       bins->adev_min = bins->adev_max * 1.0e-18F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 38) {  // 19 decades
       bins->adev_min = bins->adev_max * 1.0e-19F;
    }
    else if((PLOT_HEIGHT/VERT_MAJOR) <= 40) {  // 20 decades
       bins->adev_min = bins->adev_max * 1.0e-20F;
    }
    else { // ten decades?
       bins->adev_min = bins->adev_max * 1.0e-10F;
    }

    if((PLOT_HEIGHT/VERT_MAJOR) & 0x01) {  // odd number of decade bins are off-centered
       bins->adev_max /= 2.0F;
       bins->adev_min *= 5.0F;
    }

    return bins->bin_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %r14d
cmpl $0x13, %edi
ja 0xeaff2
movl %r14d, %eax
leaq 0x2a300(%rip), %rcx     # 0x115268
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x12f458(%rip), %rax    # 0x21a3d0
jmp 0xeb04f
leaq 0x13790c(%rip), %rax    # 0x222890
jmp 0xeb04f
pushq $0x2
jmp 0xeb1a3
leaq 0x132079(%rip), %rax    # 0x21d010
jmp 0xeb04f
pushq $0x1
jmp 0xeb1a3
leaq 0x133686(%rip), %rax    # 0x21e630
jmp 0xeb04f
xorl %edi, %edi
jmp 0xeb1a4
leaq 0x12c7d3(%rip), %rax    # 0x217790
jmp 0xeb04f
leaq 0x1362a7(%rip), %rax    # 0x221270
jmp 0xeb04f
leaq 0x12dddb(%rip), %rax    # 0x218db0
jmp 0xeb04f
leaq 0x128552(%rip), %rax    # 0x213530
jmp 0xeb04f
leaq 0x12b189(%rip), %rax    # 0x216170
jmp 0xeb04f
leaq 0x138ec0(%rip), %rax    # 0x223eb0
jmp 0xeb04f
movzbl %r14b, %edx
leaq 0x23b223(%rip), %r15    # 0x326220
leaq 0x349b7(%rip), %rsi     # 0x11f9bb
movq %r15, %rdi
xorl %eax, %eax
callq 0x9060
pushq $0x5c
popq %rdi
movq %r15, %rsi
callq 0xb290
jmp 0xeb04f
leaq 0x1258ce(%rip), %rax    # 0x2108f0
jmp 0xeb04f
leaq 0x134c25(%rip), %rax    # 0x21fc50
jmp 0xeb04f
leaq 0x126edc(%rip), %rax    # 0x211f10
jmp 0xeb04f
leaq 0x13a493(%rip), %rax    # 0x2254d0
jmp 0xeb04f
leaq 0x1309aa(%rip), %rax    # 0x21b9f0
jmp 0xeb04f
leaq 0x129b01(%rip), %rax    # 0x214b50
movl $0xefa18f08, 0x650(%rbx) # imm = 0xEFA18F08
movabsq $0x6fa18f0800000000, %rcx # imm = 0x6FA18F0800000000
movq %rcx, 0x648(%rbx)
movb %r14b, (%rbx)
leaq 0x13bc48(%rip), %rcx    # 0x226cbc
movl (%rcx), %ecx
addq $0x18, %rax
xorl %r14d, %r14d
cmpl $0x63, %r14d
ja 0xeb10c
movslq -0x14(%rax), %rdx
cmpl %ecx, %edx
jl 0xeb0f4
cvtsd2ss (%rax), %xmm2
movsd -0x8(%rax), %xmm1
movq %rdx, 0x328(%rbx,%r14,8)
cvtsd2ss %xmm1, %xmm0
movss %xmm2, 0x4(%rbx,%r14,4)
movss %xmm0, 0x194(%rbx,%r14,4)
leal 0x1(%r14), %edx
movl %edx, 0x648(%rbx)
cvtss2sd 0x650(%rbx), %xmm2
ucomisd %xmm2, %xmm1
jbe 0xeb0d5
movss %xmm0, 0x650(%rbx)
cvtss2sd 0x64c(%rbx), %xmm2
ucomisd %xmm1, %xmm2
jbe 0xeb0eb
movss %xmm0, 0x64c(%rbx)
incq %r14
addq $0x38, %rax
jmp 0xeb07d
andq $0x0, 0x328(%rbx,%r14,8)
andl $0x0, 0x4(%rbx,%r14,4)
andl $0x0, 0x194(%rbx,%r14,4)
leaq 0x13b9d5(%rip), %rax    # 0x226ae8
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xeb123
jnp 0xeb129
cvtsd2ss %xmm0, %xmm0
jmp 0xeb131
movss 0x650(%rbx), %xmm0
callq 0xe8ddc
movss %xmm0, 0x650(%rbx)
leaq 0x117743(%rip), %rax    # 0x202888
movl (%rax), %eax
leaq 0x11771e(%rip), %rcx    # 0x20286c
cltd
idivl (%rcx)
movss 0x2b5e3(%rip), %xmm1    # 0x11673c
cmpl $0x7, %eax
jl 0xeb28a
cmpl $0x9, %eax
jae 0xeb174
movss 0x2b5c5(%rip), %xmm1    # 0x116734
jmp 0xeb28a
cmpl $0xb, %eax
jae 0xeb186
movss 0x2b5b7(%rip), %xmm1    # 0x116738
jmp 0xeb28a
cmpl $0xd, %eax
jb 0xeb28a
cmpl $0xf, %eax
jae 0xeb1b6
movss 0x2b5a4(%rip), %xmm1    # 0x116740
jmp 0xeb28a
pushq $0x3
popq %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xe86c9
cmpl $0x11, %eax
jae 0xeb1c8
movss 0x2b581(%rip), %xmm1    # 0x116744
jmp 0xeb28a
cmpl $0x13, %eax
jae 0xeb1da
movss 0x2b573(%rip), %xmm1    # 0x116748
jmp 0xeb28a
cmpl $0x15, %eax
jae 0xeb1ec
movss 0x1d7e5(%rip), %xmm1    # 0x1089cc
jmp 0xeb28a
cmpl $0x17, %eax
jae 0xeb1fe
movss 0x2b553(%rip), %xmm1    # 0x11674c
jmp 0xeb28a
cmpl $0x19, %eax
jae 0xeb20d
movss 0x2b545(%rip), %xmm1    # 0x116750
jmp 0xeb28a
cmpl $0x1b, %eax
jae 0xeb21c
movss 0x2b53a(%rip), %xmm1    # 0x116754
jmp 0xeb28a
cmpl $0x1d, %eax
jae 0xeb22b
movss 0x2b52f(%rip), %xmm1    # 0x116758
jmp 0xeb28a
cmpl $0x1f, %eax
jae 0xeb23a
movss 0x2b524(%rip), %xmm1    # 0x11675c
jmp 0xeb28a
cmpl $0x21, %eax
jae 0xeb249
movss 0x2b519(%rip), %xmm1    # 0x116760
jmp 0xeb28a
cmpl $0x23, %eax
jae 0xeb258
movss 0x2b50e(%rip), %xmm1    # 0x116764
jmp 0xeb28a
cmpl $0x25, %eax
jae 0xeb267
movss 0x2b503(%rip), %xmm1    # 0x116768
jmp 0xeb28a
cmpl $0x27, %eax
jae 0xeb276
movss 0x2b4b8(%rip), %xmm1    # 0x11672c
jmp 0xeb28a
xorl %ecx, %ecx
cmpl $0x29, %eax
setb %cl
leaq 0x2b42b(%rip), %rdx     # 0x1166b0
movss (%rdx,%rcx,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x64c(%rbx)
testb $0x1, %al
je 0xeb2ba
mulss 0xbe56(%rip), %xmm0     # 0xf70f8
movss %xmm0, 0x650(%rbx)
mulss 0x1d722(%rip), %xmm1    # 0x1089d4
movss %xmm1, 0x64c(%rbx)
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq