// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathmsc.cpp
// Function: label_adev_grid(int)
void label_adev_grid(int top)
{
int row, col;
int row_step;
int top_row;
int i,j;
int k;
double val;
double range;
double steps;
int adev_top_row;   // calculate where the adev decades are in the plot area
int vert_scale;
int vert_ofs;
long m;

   if(all_adevs == SINGLE_ADEVS) {
      if(plot_adev_data == 0) return;   // no adevs on screen, don't label the plots
   }
   if(plot_adev_data == 0) return;   // no adevs on screen, don't label the plots

   graphics_coords = 1;

   m = 1L;
   for(i=0; i<first_show_bin; i++) {  // find tau of the first displayed bin
      if(ATYPE == A_MTIE) m *= 2;
      else                m = next_tau(m, bin_scale);
   }

   i = k = 0;
   adev_decades_shown = 0;
   for(col=0; col<PLOT_WIDTH; col+=HORIZ_MAJOR) {  // aaaaaapppppp
//      sprintf(out, "%ld", m);
      sprintf(out, "%g", adev_period * (double) m);

      if(col == 0) j = 0;
      else         j = (strlen(out)*TEXT_WIDTH) / 2;

      if((col-j) > (PLOT_WIDTH-(HORIZ_MAJOR*2))) break;
      else if((HORIZ_MAJOR < (6*TEXT_WIDTH)) && (k != 0)) ;
      else {
         vidstr(PLOT_ROW+2, 1+PLOT_COL+col-j, ADEV_LABEL_COLOR, out); // xyzzy
      }
      ++adev_decades_shown;

      k = (k + 1) % 3;
      if(ATYPE == A_MTIE) m *= 2;
      else                m = next_tau(m, bin_scale);
      if(m > 100000) break;
   }

   range = 0.0;
   val = 1.0;
   for(i=0; i<20; i++) {  // find decade value of the largest xDEV value
      if(global_adev_max >= val) break;
      val /= 10.0;
   }
   val *= 10.0;

   top_row = PLOT_ROW; // top;
   vert_scale = (PLOT_HEIGHT / (VERT_MAJOR*2)) * (VERT_MAJOR*2);  // two major divisions per decade
   vert_ofs = (PLOT_HEIGHT - vert_scale) / 2;
   if(((PLOT_HEIGHT / (VERT_MAJOR*2)) & 0x01) == 0x00) {  // align adevs to cyan dotted lines
      vert_ofs += VERT_MAJOR;
   }
   adev_top_row = PLOT_ROW + vert_ofs;
   if(adev_top_row && (adev_top_row > top_row)) top_row = adev_top_row;
//sprintf(debug_text, "plot:%d  top:%d  hmajor:%d  verts:%d  atr:%d  gam:%g  val:%g", PLOT_ROW, top, HORIZ_MAJOR, PLOT_HEIGHT/VERT_MAJOR, adev_top_row, global_adev_max, val);

   row_step = VERT_MAJOR;
   if(SCREEN_HEIGHT > SHORT_SCREEN) {
      row_step *= 2;
   }
   else if(zoom_screen == 'P') {  // aaaahhhh
      row_step *= 2;
   }
   adev_decade_height = (double) row_step;

   if(ATYPE == A_MTIE) {  // calculate vertical scale
      steps = 0.0;
      for(row=top_row; row<SCREEN_HEIGHT; row+=row_step) {
         steps += 1.0;
      }
      val = global_adev_max * MTIE_SCALE;
      range = val - (global_adev_min / MTIE_SCALE);
      if(steps) range /= steps;
   //sprintf(debug_text, "steps:%g", steps);
   }

   for(row=top_row; row<SCREEN_HEIGHT; row+=row_step) {
      if(ATYPE == A_MTIE) {
         sprintf(out, "%.3g", val);   // aaahhh %le
         val -= range;
      }
      else {
         sprintf(out, "%g", val);   // aaahhh %le
         val /= 10.0;
      }

      i = (strlen(out)+1) * TEXT_WIDTH;
      if((row == top_row) && (PLOT_ROW == adev_top_row)) {
         vidstr(row+2, PLOT_COL+PLOT_WIDTH-i, ADEV_LABEL_COLOR, out);
      }
      else {
         vidstr(row-TEXT_HEIGHT/2, PLOT_COL+PLOT_WIDTH-i, ADEV_LABEL_COLOR, out);
      }
   }

   bottom_adev_decade = (float) val;
   graphics_coords = 0;
}

// Assembly:
leaq 0x11c8f5(%rip), %rax    # 0x21b3d9
cmpb $0x0, (%rax)
je 0xfeebf
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x119d63(%rip), %rax    # 0x218868
movb $0x1, (%rax)
leaq 0x13e171(%rip), %r14    # 0x23cc80
cmpl $0x0, (%r14)
jle 0xfeb50
xorl %r15d, %r15d
movl $0x1, %ebx
leaq 0x124aec(%rip), %r12    # 0x223610
leaq 0x13e151(%rip), %r13    # 0x23cc7c
cmpl $0x9, (%r12)
jne 0xfeb37
addq %rbx, %rbx
jmp 0xfeb46
movl (%r13), %esi
movq %rbx, %rdi
callq 0xfe1db
movq %rax, %rbx
incl %r15d
cmpl (%r14), %r15d
jl 0xfeb2b
jmp 0xfeb55
movl $0x1, %ebx
leaq 0x119c68(%rip), %rax    # 0x2187c4
movl $0x0, (%rax)
leaq 0x119d1b(%rip), %rax    # 0x218884
cmpl $0x0, (%rax)
jle 0xfec84
leaq 0x23d6a7(%rip), %r14    # 0x33c220
leaq 0x119cf4(%rip), %r13    # 0x218874
xorl %r12d, %r12d
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
leaq 0x13e163(%rip), %rax    # 0x23ccf8
mulsd (%rax), %xmm0
movq %r14, %rdi
leaq 0x30844(%rip), %rsi     # 0x12f3e7
movb $0x1, %al
callq 0x9060
movl $0x0, %ecx
testl %r12d, %r12d
je 0xfebcd
movq %r14, %rdi
callq 0x9120
leaq 0x119c4d(%rip), %rcx    # 0x218810
movslq (%rcx), %rcx
imulq %rax, %rcx
shrq %rcx
movl %r12d, %eax
subl %ecx, %eax
leaq 0x119cab(%rip), %rcx    # 0x218884
movl (%rcx), %edx
movl (%r13), %ecx
subl %ecx, %edx
subl %ecx, %edx
cmpl %edx, %eax
jg 0xfec84
leaq 0x119c1e(%rip), %rdx    # 0x218810
movl (%rdx), %edx
addl %edx, %edx
leal (%rdx,%rdx,2), %edx
cmpl %edx, %ecx
jge 0xfec02
testl %r15d, %r15d
jne 0xfec29
leaq 0x119c73(%rip), %rcx    # 0x21887c
movl (%rcx), %edi
addl $0x2, %edi
leaq 0x119c6b(%rip), %rcx    # 0x218880
movl (%rcx), %ecx
leal (%rax,%rcx), %esi
incl %esi
movl $0xa, %edx
movq %r14, %rcx
callq 0xe7d0
leaq 0x119b94(%rip), %rax    # 0x2187c4
incl (%rax)
incl %r15d
cmpl $0x3, %r15d
movl $0x0, %eax
cmovel %eax, %r15d
leaq 0x1249c7(%rip), %rax    # 0x223610
cmpl $0x9, (%rax)
jne 0xfec53
addq %rbx, %rbx
jmp 0xfec67
leaq 0x13e022(%rip), %rax    # 0x23cc7c
movl (%rax), %esi
movq %rbx, %rdi
callq 0xfe1db
movq %rax, %rbx
cmpq $0x186a0, %rbx          # imm = 0x186A0
jg 0xfec84
addl (%r13), %r12d
leaq 0x119c09(%rip), %rax    # 0x218884
cmpl (%rax), %r12d
jl 0xfeb86
leaq 0x13de5d(%rip), %rax    # 0x23cae8
movsd (%rax), %xmm5
ucomisd 0xa3d9(%rip), %xmm5     # 0x109070
jae 0xfecc6
xorl %eax, %eax
movsd 0xa3cd(%rip), %xmm0     # 0x109070
movsd 0xa3fd(%rip), %xmm1     # 0x1090a8
divsd %xmm1, %xmm0
cmpl $0x12, %eax
ja 0xfecbc
incl %eax
ucomisd %xmm0, %xmm5
jb 0xfecab
mulsd 0xa3e4(%rip), %xmm0     # 0x1090a8
jmp 0xfecce
movsd 0xa3da(%rip), %xmm0     # 0x1090a8
leaq 0x119ba7(%rip), %rax    # 0x21887c
movl (%rax), %esi
leaq 0x119baa(%rip), %rax    # 0x218888
movl (%rax), %eax
leaq 0x119b85(%rip), %rcx    # 0x21886c
movl (%rcx), %r12d
leal (%r12,%r12), %ecx
cltd
idivl %ecx
movl %edx, %edi
shrl $0x1f, %edi
addl %edx, %edi
sarl %edi
xorl %edx, %edx
testb $0x1, %al
cmovel %r12d, %edx
addl %edi, %edx
movl %edx, %r14d
addl %esi, %r14d
movl %esi, %r15d
cmovnel %r14d, %r15d
testl %edx, %edx
cmovlel %esi, %r15d
leaq 0x119ae6(%rip), %rdx    # 0x218804
leaq 0x20da83(%rip), %rax    # 0x30c7a8
cmpb $0x50, (%rax)
cmovel %ecx, %r12d
movl (%rdx), %eax
cmpl $0x259, %eax            # imm = 0x259
cmovgel %ecx, %r12d
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
leaq 0x13dfaa(%rip), %rcx    # 0x23ccf0
movsd %xmm1, (%rcx)
leaq 0x1248bf(%rip), %rcx    # 0x223610
xorpd %xmm3, %xmm3
cmpl $0x9, (%rcx)
jne 0xfedb0
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
cmpl %eax, %r15d
jge 0xfed7d
movsd 0xa301(%rip), %xmm3     # 0x109070
movl %r15d, %ecx
addsd %xmm3, %xmm1
addl %r12d, %ecx
cmpl %eax, %ecx
jl 0xfed72
movsd 0x2d913(%rip), %xmm3    # 0x12c698
mulsd %xmm3, %xmm5
leaq 0x13dd60(%rip), %rax    # 0x23caf0
movsd (%rax), %xmm4
divsd %xmm3, %xmm4
movapd %xmm5, %xmm3
subsd %xmm4, %xmm3
ucomisd %xmm2, %xmm1
jne 0xfeda8
jnp 0xfedac
divsd %xmm1, %xmm3
movapd %xmm5, %xmm0
leaq 0x119a4d(%rip), %rax    # 0x218804
cmpl (%rax), %r15d
jge 0xfee9b
movsd %xmm3, -0x38(%rbp)
xorl %r13d, %r13d
leaq 0x23d451(%rip), %rbx    # 0x33c220
leaq 0x12483a(%rip), %rax    # 0x223610
cmpl $0x9, (%rax)
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
jne 0xfedfd
leaq 0x36bbc(%rip), %rsi     # 0x1359a6
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm0
subsd -0x38(%rbp), %xmm0
jmp 0xfee18
leaq 0x305e3(%rip), %rsi     # 0x12f3e7
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm0
divsd 0xa290(%rip), %xmm0     # 0x1090a8
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
callq 0x9120
notl %eax
leaq 0x1199e2(%rip), %rcx    # 0x218810
imull (%rcx), %eax
testl %r13d, %r13d
jne 0xfee48
leaq 0x119a3f(%rip), %rcx    # 0x21887c
cmpl %r14d, (%rcx)
jne 0xfee48
leal 0x2(%r15), %edi
jmp 0xfee5f
leaq 0x1199c5(%rip), %rcx    # 0x218814
movl (%rcx), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
movl %r15d, %edi
subl %edx, %edi
leaq 0x119a1a(%rip), %rcx    # 0x218880
addl (%rcx), %eax
leaq 0x119a15(%rip), %rcx    # 0x218884
addl (%rcx), %eax
movl %eax, %esi
movl $0xa, %edx
movq %rbx, %rcx
callq 0xe7d0
addl %r12d, %r15d
addl %r12d, %r13d
leaq 0x119977(%rip), %rax    # 0x218804
cmpl (%rax), %r15d
movsd -0x30(%rbp), %xmm0
jl 0xfedcf
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x27b711(%rip)   # 0x37a5b8
leaq 0x1199ba(%rip), %rax    # 0x218868
movb $0x0, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq