// File: /workspace/github_cpp_makefile_star2_O3/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 0x11c24c(%rip), %rax    # 0x21b3d9
cmpb $0x0, (%rax)
je 0xff597
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x1196ba(%rip), %rax    # 0x218868
movb $0x1, (%rax)
leaq 0x13dac8(%rip), %r14    # 0x23cc80
movl (%r14), %eax
testl %eax, %eax
jle 0xff206
leaq 0x12444a(%rip), %r15    # 0x223610
movl (%r15), %ecx
xorl %r12d, %r12d
movl $0x1, %ebx
leaq 0x13daa4(%rip), %r13    # 0x23cc7c
cmpl $0x9, %ecx
jne 0xff1e7
addq %rbx, %rbx
movl $0x9, %ecx
jmp 0xff1fc
movl (%r13), %esi
movq %rbx, %rdi
callq 0xfe862
movq %rax, %rbx
movl (%r15), %ecx
movl (%r14), %eax
incl %r12d
cmpl %eax, %r12d
jl 0xff1d8
jmp 0xff20b
movl $0x1, %ebx
leaq 0x1195b2(%rip), %rax    # 0x2187c4
movl $0x0, (%rax)
leaq 0x119665(%rip), %rax    # 0x218884
cmpl $0x0, (%rax)
jle 0xff33a
leaq 0x23cff1(%rip), %r14    # 0x33c220
leaq 0x11963e(%rip), %r13    # 0x218874
xorl %r12d, %r12d
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
leaq 0x13daad(%rip), %rax    # 0x23ccf8
mulsd (%rax), %xmm0
movq %r14, %rdi
leaq 0x3027e(%rip), %rsi     # 0x12f4d7
movb $0x1, %al
callq 0x9060
movl $0x0, %ecx
testl %r12d, %r12d
je 0xff283
movq %r14, %rdi
callq 0x9120
leaq 0x119597(%rip), %rcx    # 0x218810
movslq (%rcx), %rcx
imulq %rax, %rcx
shrq %rcx
movl %r12d, %eax
subl %ecx, %eax
leaq 0x1195f5(%rip), %rcx    # 0x218884
movl (%rcx), %edx
movl (%r13), %ecx
subl %ecx, %edx
subl %ecx, %edx
cmpl %edx, %eax
jg 0xff33a
leaq 0x119568(%rip), %rdx    # 0x218810
movl (%rdx), %edx
addl %edx, %edx
leal (%rdx,%rdx,2), %edx
cmpl %edx, %ecx
jge 0xff2b8
testl %r15d, %r15d
jne 0xff2df
leaq 0x1195bd(%rip), %rcx    # 0x21887c
movl (%rcx), %edi
addl $0x2, %edi
leaq 0x1195b5(%rip), %rcx    # 0x218880
movl (%rcx), %ecx
leal (%rax,%rcx), %esi
incl %esi
movl $0xa, %edx
movq %r14, %rcx
callq 0xe787
leaq 0x1194de(%rip), %rax    # 0x2187c4
incl (%rax)
incl %r15d
cmpl $0x3, %r15d
movl $0x0, %eax
cmovel %eax, %r15d
leaq 0x124311(%rip), %rax    # 0x223610
cmpl $0x9, (%rax)
jne 0xff309
addq %rbx, %rbx
jmp 0xff31d
leaq 0x13d96c(%rip), %rax    # 0x23cc7c
movl (%rax), %esi
movq %rbx, %rdi
callq 0xfe862
movq %rax, %rbx
cmpq $0x186a0, %rbx          # imm = 0x186A0
jg 0xff33a
addl (%r13), %r12d
leaq 0x119553(%rip), %rax    # 0x218884
cmpl (%rax), %r12d
jl 0xff23c
leaq 0x13d7a7(%rip), %rax    # 0x23cae8
movsd (%rax), %xmm4
ucomisd 0x9d23(%rip), %xmm4     # 0x109070
jae 0xff37c
xorl %eax, %eax
movsd 0x9d17(%rip), %xmm0     # 0x109070
movsd 0x9d47(%rip), %xmm1     # 0x1090a8
divsd %xmm1, %xmm0
cmpl $0x12, %eax
ja 0xff372
incl %eax
ucomisd %xmm0, %xmm4
jb 0xff361
mulsd 0x9d2e(%rip), %xmm0     # 0x1090a8
jmp 0xff384
movsd 0x9d24(%rip), %xmm0     # 0x1090a8
leaq 0x1194f1(%rip), %rax    # 0x21887c
movl (%rax), %esi
leaq 0x1194f4(%rip), %rax    # 0x218888
movl (%rax), %eax
leaq 0x1194cf(%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, %eax
addl %esi, %eax
movl %esi, %r15d
movl %eax, -0x34(%rbp)
cmovnel %eax, %r15d
testl %edx, %edx
cmovlel %esi, %r15d
leaq 0x11942f(%rip), %rdx    # 0x218804
leaq 0x20d3cc(%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 0x13d8f3(%rip), %rcx    # 0x23ccf0
movsd %xmm1, (%rcx)
leaq 0x124208(%rip), %rcx    # 0x223610
xorpd %xmm5, %xmm5
cmpl $0x9, (%rcx)
jne 0xff48c
cmpl %eax, %r15d
jge 0xff465
xorpd %xmm1, %xmm1
movsd 0x9c4e(%rip), %xmm2     # 0x109070
movl %r15d, %ecx
addsd %xmm2, %xmm1
addl %r12d, %ecx
cmpl %eax, %ecx
jl 0xff425
movsd 0x2d348(%rip), %xmm2    # 0x12c780
mulsd %xmm2, %xmm4
leaq 0x13d6ad(%rip), %rcx    # 0x23caf0
movsd (%rcx), %xmm3
divsd %xmm2, %xmm3
movapd %xmm4, %xmm5
subsd %xmm3, %xmm5
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xff45f
jnp 0xff488
divsd %xmm1, %xmm5
jmp 0xff488
movsd 0x2d313(%rip), %xmm1    # 0x12c780
mulsd %xmm1, %xmm4
leaq 0x13d678(%rip), %rcx    # 0x23caf0
movsd (%rcx), %xmm2
divsd %xmm1, %xmm2
movapd %xmm4, %xmm5
subsd %xmm2, %xmm5
movapd %xmm4, %xmm0
cmpl %eax, %r15d
jge 0xff573
movsd %xmm5, -0x40(%rbp)
leal 0x2(%r15), %r13d
xorl %r14d, %r14d
leaq 0x23cd78(%rip), %rbx    # 0x33c220
leaq 0x124161(%rip), %rax    # 0x223610
cmpl $0x9, (%rax)
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
jne 0xff4d6
leaq 0x365d3(%rip), %rsi     # 0x135a96
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
jmp 0xff4f1
leaq 0x2fffa(%rip), %rsi     # 0x12f4d7
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm0
divsd 0x9bb7(%rip), %xmm0     # 0x1090a8
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
callq 0x9120
notl %eax
leaq 0x119309(%rip), %rcx    # 0x218810
imull (%rcx), %eax
testl %r14d, %r14d
jne 0xff520
movl %r13d, %edi
leaq 0x119363(%rip), %rcx    # 0x21887c
movl -0x34(%rbp), %edx
cmpl %edx, (%rcx)
je 0xff537
leaq 0x1192ed(%rip), %rcx    # 0x218814
movl (%rcx), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
movl %r15d, %edi
subl %edx, %edi
leaq 0x119342(%rip), %rcx    # 0x218880
addl (%rcx), %eax
leaq 0x11933d(%rip), %rcx    # 0x218884
addl (%rcx), %eax
movl %eax, %esi
movl $0xa, %edx
movq %rbx, %rcx
callq 0xe787
addl %r12d, %r15d
subl %r12d, %r14d
leaq 0x11929f(%rip), %rax    # 0x218804
cmpl (%rax), %r15d
movsd -0x30(%rbp), %xmm0
jl 0xff4a8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x27b039(%rip)   # 0x37a5b8
leaq 0x1192e2(%rip), %rax    # 0x218868
movb $0x0, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq