// File: /workspace/github_cpp_makefile_star2_O1/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 0x100cc0
movl %r14d, %eax
leaq 0x2a678(%rip), %rcx     # 0x12b2a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x12f790(%rip), %rax    # 0x2303d0
jmp 0x100d1f
leaq 0x137c44(%rip), %rax    # 0x238890
jmp 0x100d1f
movl $0x2, %edi
jmp 0x100ebf
leaq 0x1323ae(%rip), %rax    # 0x233010
jmp 0x100d1f
movl $0x1, %edi
jmp 0x100ebf
leaq 0x1339b8(%rip), %rax    # 0x234630
jmp 0x100d1f
xorl %edi, %edi
jmp 0x100ebf
leaq 0x12cb05(%rip), %rax    # 0x22d790
jmp 0x100d1f
leaq 0x1365d9(%rip), %rax    # 0x237270
jmp 0x100d1f
leaq 0x12e10d(%rip), %rax    # 0x22edb0
jmp 0x100d1f
leaq 0x128884(%rip), %rax    # 0x229530
jmp 0x100d1f
leaq 0x12b4bb(%rip), %rax    # 0x22c170
jmp 0x100d1f
leaq 0x1391f2(%rip), %rax    # 0x239eb0
jmp 0x100d1f
movzbl %r14b, %edx
leaq 0x23b555(%rip), %r15    # 0x33c220
leaq 0x34cd9(%rip), %rsi     # 0x1359ab
movq %r15, %rdi
xorl %eax, %eax
callq 0x9060
movl $0x5c, %edi
movq %r15, %rsi
callq 0xb425
jmp 0x100d1f
leaq 0x125bfe(%rip), %rax    # 0x2268f0
jmp 0x100d1f
leaq 0x134f55(%rip), %rax    # 0x235c50
jmp 0x100d1f
leaq 0x12720c(%rip), %rax    # 0x227f10
jmp 0x100d1f
leaq 0x13a7c3(%rip), %rax    # 0x23b4d0
jmp 0x100d1f
leaq 0x130cda(%rip), %rax    # 0x2319f0
jmp 0x100d1f
leaq 0x129e31(%rip), %rax    # 0x22ab50
movl $0xefa18f08, 0x650(%rbx) # imm = 0xEFA18F08
movabsq $0x6fa18f0800000000, %rcx # imm = 0x6FA18F0800000000
movq %rcx, 0x648(%rbx)
movb %r14b, (%rbx)
leaq 0x13bf78(%rip), %rcx    # 0x23ccbc
movl (%rcx), %edx
addq $0x18, %rax
xorl %ecx, %ecx
movslq -0x14(%rax), %rsi
cmpl %edx, %esi
jl 0x100dca
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)
incq %rcx
movl %ecx, 0x648(%rbx)
xorps %xmm2, %xmm2
cvtss2sd 0x650(%rbx), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x100da0
movss %xmm0, 0x650(%rbx)
xorps %xmm2, %xmm2
cvtss2sd 0x64c(%rbx), %xmm2
ucomisd %xmm1, %xmm2
jbe 0x100db9
movss %xmm0, 0x64c(%rbx)
addq $0x38, %rax
cmpq $0x64, %rcx
jne 0x100d4c
movl $0x64, %ecx
jmp 0x100de3
movq $0x0, 0x328(%rbx,%rcx,8)
xorl %eax, %eax
movl %eax, 0x4(%rbx,%rcx,4)
movl %eax, 0x194(%rbx,%rcx,4)
leaq 0x13bcfe(%rip), %rax    # 0x23cae8
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x100dfa
jnp 0x100e06
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x650(%rbx)
movss 0x650(%rbx), %xmm1
ucomiss 0xc1bf(%rip), %xmm1     # 0x10cfd4
jbe 0x100e21
movss 0xc1c1(%rip), %xmm0     # 0x10cfe0
jmp 0x100e4f
movss 0xc1ab(%rip), %xmm0     # 0x10cfd4
movss 0xc1af(%rip), %xmm2     # 0x10cfe0
movss 0x2b8eb(%rip), %xmm3    # 0x12c724
divss %xmm2, %xmm0
ucomiss %xmm3, %xmm0
jb 0x100e47
ucomiss %xmm0, %xmm1
jbe 0x100e39
mulss 0xc191(%rip), %xmm0     # 0x10cfe0
movss %xmm0, 0x650(%rbx)
leaq 0x117a2a(%rip), %rax    # 0x218888
movl (%rax), %eax
leaq 0x117a05(%rip), %rsi    # 0x21886c
cltd
idivl (%rsi)
movss 0x2b8c2(%rip), %xmm1    # 0x12c734
cmpl $0x7, %eax
jl 0x100fa5
cmpl $0x9, %eax
jge 0x100e8d
movss 0x2b8a4(%rip), %xmm1    # 0x12c72c
jmp 0x100fa5
cmpl $0xb, %eax
jge 0x100e9f
movss 0x2b896(%rip), %xmm1    # 0x12c730
jmp 0x100fa5
cmpl $0xd, %eax
jl 0x100fa5
cmpl $0xf, %eax
jge 0x100ed1
movss 0x2b883(%rip), %xmm1    # 0x12c738
jmp 0x100fa5
movl $0x3, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xfdee3
cmpl $0x11, %eax
jge 0x100ee3
movss 0x2b85e(%rip), %xmm1    # 0x12c73c
jmp 0x100fa5
cmpl $0x13, %eax
jge 0x100ef5
movss 0x2b850(%rip), %xmm1    # 0x12c740
jmp 0x100fa5
cmpl $0x15, %eax
jge 0x100f07
movss 0x1daa2(%rip), %xmm1    # 0x11e9a4
jmp 0x100fa5
cmpl $0x17, %eax
jge 0x100f19
movss 0x2b830(%rip), %xmm1    # 0x12c744
jmp 0x100fa5
cmpl $0x19, %eax
jge 0x100f28
movss 0x2b822(%rip), %xmm1    # 0x12c748
jmp 0x100fa5
cmpl $0x1b, %eax
jge 0x100f37
movss 0x2b817(%rip), %xmm1    # 0x12c74c
jmp 0x100fa5
cmpl $0x1d, %eax
jge 0x100f46
movss 0x2b80c(%rip), %xmm1    # 0x12c750
jmp 0x100fa5
cmpl $0x1f, %eax
jge 0x100f55
movss 0x2b801(%rip), %xmm1    # 0x12c754
jmp 0x100fa5
cmpl $0x21, %eax
jge 0x100f64
movss 0x2b7f6(%rip), %xmm1    # 0x12c758
jmp 0x100fa5
cmpl $0x23, %eax
jge 0x100f73
movss 0x2b7eb(%rip), %xmm1    # 0x12c75c
jmp 0x100fa5
cmpl $0x25, %eax
jge 0x100f82
movss 0x2b7e0(%rip), %xmm1    # 0x12c760
jmp 0x100fa5
cmpl $0x27, %eax
jge 0x100f91
movss 0x2b795(%rip), %xmm1    # 0x12c724
jmp 0x100fa5
xorl %edx, %edx
cmpl $0x29, %eax
setl %dl
leaq 0x2b708(%rip), %rsi     # 0x12c6a8
movss (%rsi,%rdx,4), %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x64c(%rbx)
testb $0x1, %al
je 0x100fdd
mulss 0xc027(%rip), %xmm0     # 0x10cfe4
movss %xmm0, 0x650(%rbx)
movss 0x64c(%rbx), %xmm0
mulss 0x1d9d7(%rip), %xmm0    # 0x11e9ac
movss %xmm0, 0x64c(%rbx)
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq