// File: /workspace/github_cpp_makefile_star2_O3/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 0x101340
movl %r14d, %eax
leaq 0x2a0c8(%rip), %rcx     # 0x12b378
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x12f110(%rip), %rax    # 0x2303d0
jmp 0x10139f
leaq 0x1375c4(%rip), %rax    # 0x238890
jmp 0x10139f
movl $0x2, %edi
jmp 0x10153c
leaq 0x131d2e(%rip), %rax    # 0x233010
jmp 0x10139f
movl $0x1, %edi
jmp 0x10153c
leaq 0x133338(%rip), %rax    # 0x234630
jmp 0x10139f
xorl %edi, %edi
jmp 0x10153c
leaq 0x12c485(%rip), %rax    # 0x22d790
jmp 0x10139f
leaq 0x135f59(%rip), %rax    # 0x237270
jmp 0x10139f
leaq 0x12da8d(%rip), %rax    # 0x22edb0
jmp 0x10139f
leaq 0x128204(%rip), %rax    # 0x229530
jmp 0x10139f
leaq 0x12ae3b(%rip), %rax    # 0x22c170
jmp 0x10139f
leaq 0x138b72(%rip), %rax    # 0x239eb0
jmp 0x10139f
movzbl %r14b, %edx
leaq 0x23aed5(%rip), %r15    # 0x33c220
leaq 0x34749(%rip), %rsi     # 0x135a9b
movq %r15, %rdi
xorl %eax, %eax
callq 0x9060
movl $0x5c, %edi
movq %r15, %rsi
callq 0xb424
jmp 0x10139f
leaq 0x12557e(%rip), %rax    # 0x2268f0
jmp 0x10139f
leaq 0x1348d5(%rip), %rax    # 0x235c50
jmp 0x10139f
leaq 0x126b8c(%rip), %rax    # 0x227f10
jmp 0x10139f
leaq 0x13a143(%rip), %rax    # 0x23b4d0
jmp 0x10139f
leaq 0x13065a(%rip), %rax    # 0x2319f0
jmp 0x10139f
leaq 0x1297b1(%rip), %rax    # 0x22ab50
movl $0xefa18f08, 0x650(%rbx) # imm = 0xEFA18F08
movabsq $0x6fa18f0800000000, %rcx # imm = 0x6FA18F0800000000
movq %rcx, 0x648(%rbx)
movb %r14b, (%rbx)
leaq 0x13b8f8(%rip), %rcx    # 0x23ccbc
movl (%rcx), %edx
addq $0x18, %rax
xorl %ecx, %ecx
movslq -0x14(%rax), %rsi
cmpl %edx, %esi
jl 0x10144a
xorps %xmm2, %xmm2
cvtsd2ss (%rax), %xmm2
movsd -0x8(%rax), %xmm1
movq %rsi, 0x328(%rbx,%rcx,8)
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm2, 0x4(%rbx,%rcx,4)
movss %xmm0, 0x194(%rbx,%rcx,4)
leal 0x1(%rcx), %esi
movl %esi, 0x648(%rbx)
xorps %xmm2, %xmm2
cvtss2sd 0x650(%rbx), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x101420
movss %xmm0, 0x650(%rbx)
xorps %xmm2, %xmm2
cvtss2sd 0x64c(%rbx), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x101439
movss %xmm0, 0x64c(%rbx)
incq %rcx
leal -0x1(%rcx), %esi
addq $0x38, %rax
cmpl $0x63, %esi
jb 0x1013cc
jmp 0x101463
movq $0x0, 0x328(%rbx,%rcx,8)
xorl %eax, %eax
movl %eax, 0x4(%rbx,%rcx,4)
movl %eax, 0x194(%rbx,%rcx,4)
leaq 0x13b67e(%rip), %rax    # 0x23cae8
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x10147a
jnp 0x101483
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
jmp 0x10148b
movss 0x650(%rbx), %xmm1
ucomiss 0xbbda(%rip), %xmm1     # 0x10d06c
jbe 0x10149e
movss 0xbbb4(%rip), %xmm0     # 0x10d050
jmp 0x1014cc
movss 0xbbc6(%rip), %xmm0     # 0x10d06c
movss 0xbba2(%rip), %xmm2     # 0x10d050
movss 0x2b356(%rip), %xmm3    # 0x12c80c
divss %xmm2, %xmm0
ucomiss %xmm3, %xmm0
jb 0x1014c4
ucomiss %xmm0, %xmm1
jbe 0x1014b6
mulss 0xbb84(%rip), %xmm0     # 0x10d050
movss %xmm0, 0x650(%rbx)
leaq 0x1173ad(%rip), %rax    # 0x218888
movl (%rax), %eax
leaq 0x117388(%rip), %rsi    # 0x21886c
cltd
idivl (%rsi)
movss 0x2b32d(%rip), %xmm1    # 0x12c81c
cmpl $0x7, %eax
jl 0x101622
cmpl $0x9, %eax
jae 0x10150a
movss 0x2b30f(%rip), %xmm1    # 0x12c814
jmp 0x101622
cmpl $0xb, %eax
jae 0x10151c
movss 0x2b301(%rip), %xmm1    # 0x12c818
jmp 0x101622
cmpl $0xd, %eax
jb 0x101622
cmpl $0xf, %eax
jae 0x10154e
movss 0x2b2ee(%rip), %xmm1    # 0x12c820
jmp 0x101622
movl $0x3, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xfe5b0
cmpl $0x11, %eax
jae 0x101560
movss 0x2b2c9(%rip), %xmm1    # 0x12c824
jmp 0x101622
cmpl $0x13, %eax
jae 0x101572
movss 0x2b2bb(%rip), %xmm1    # 0x12c828
jmp 0x101622
cmpl $0x15, %eax
jae 0x101584
movss 0x1d4d5(%rip), %xmm1    # 0x11ea54
jmp 0x101622
cmpl $0x17, %eax
jae 0x101596
movss 0x2b29b(%rip), %xmm1    # 0x12c82c
jmp 0x101622
cmpl $0x19, %eax
jae 0x1015a5
movss 0x2b28d(%rip), %xmm1    # 0x12c830
jmp 0x101622
cmpl $0x1b, %eax
jae 0x1015b4
movss 0x2b282(%rip), %xmm1    # 0x12c834
jmp 0x101622
cmpl $0x1d, %eax
jae 0x1015c3
movss 0x2b277(%rip), %xmm1    # 0x12c838
jmp 0x101622
cmpl $0x1f, %eax
jae 0x1015d2
movss 0x2b26c(%rip), %xmm1    # 0x12c83c
jmp 0x101622
cmpl $0x21, %eax
jae 0x1015e1
movss 0x2b261(%rip), %xmm1    # 0x12c840
jmp 0x101622
cmpl $0x23, %eax
jae 0x1015f0
movss 0x2b256(%rip), %xmm1    # 0x12c844
jmp 0x101622
cmpl $0x25, %eax
jae 0x1015ff
movss 0x2b24b(%rip), %xmm1    # 0x12c848
jmp 0x101622
cmpl $0x27, %eax
jae 0x10160e
movss 0x2b200(%rip), %xmm1    # 0x12c80c
jmp 0x101622
xorl %edx, %edx
cmpl $0x29, %eax
setb %dl
leaq 0x2b173(%rip), %rsi     # 0x12c790
movss (%rsi,%rdx,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x64c(%rbx)
testb $0x1, %al
je 0x101652
mulss 0xba3e(%rip), %xmm0     # 0x10d078
movss %xmm0, 0x650(%rbx)
mulss 0x1d412(%rip), %xmm1    # 0x11ea5c
movss %xmm1, 0x64c(%rbx)
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq