// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x11c227(%rip), %rax    # 0x2053d9
cmpb $0x0, (%rax)
je 0xe9539
leaq 0x1196a6(%rip), %rax    # 0x202868
movb $0x1, (%rax)
leaq 0x13dab4(%rip), %r14    # 0x226c80
movl (%r14), %eax
pushq $0x1
popq %rbx
xorl %r15d, %r15d
leaq 0x13daa0(%rip), %r12    # 0x226c7c
cmpl %eax, %r15d
jge 0xe9209
leaq 0x124428(%rip), %rcx    # 0x20d610
cmpl $0x9, (%rcx)
jne 0xe91f2
addq %rbx, %rbx
jmp 0xe9204
movl (%r12), %esi
movq %rbx, %rdi
callq 0xe8915
movq %rax, %rbx
movl (%r14), %eax
incl %r15d
jmp 0xe91dc
leaq 0x1195b4(%rip), %rax    # 0x2027c4
andl $0x0, (%rax)
leaq 0x23d006(%rip), %r14    # 0x326220
leaq 0x119653(%rip), %r15    # 0x202874
xorl %r13d, %r13d
xorl %r12d, %r12d
leaq 0x119656(%rip), %rax    # 0x202884
cmpl (%rax), %r12d
jge 0xe931e
cvtsi2sd %rbx, %xmm0
leaq 0x13dab5(%rip), %rax    # 0x226cf8
mulsd (%rax), %xmm0
movq %r14, %rdi
leaq 0x301a6(%rip), %rsi     # 0x1193f7
movb $0x1, %al
callq 0x9060
testl %r12d, %r12d
je 0xe9278
movq %r14, %rdi
callq 0x9120
leaq 0x1195a4(%rip), %rcx    # 0x202810
movslq (%rcx), %rcx
imulq %rax, %rcx
shrq %rcx
jmp 0xe927a
xorl %ecx, %ecx
movl %r12d, %eax
subl %ecx, %eax
leaq 0x1195fe(%rip), %rcx    # 0x202884
movl (%rcx), %edx
movl (%r15), %ecx
subl %ecx, %edx
subl %ecx, %edx
cmpl %edx, %eax
jg 0xe931e
leaq 0x119572(%rip), %rdx    # 0x202810
imull $0x6, (%rdx), %edx
cmpl %edx, %ecx
jge 0xe92aa
testl %r13d, %r13d
jne 0xe92cf
leaq 0x1195cb(%rip), %rcx    # 0x20287c
movl (%rcx), %edi
addl $0x2, %edi
leaq 0x1195c3(%rip), %rcx    # 0x202880
movl (%rcx), %ecx
leal (%rax,%rcx), %esi
incl %esi
pushq $0xa
popq %rdx
movq %r14, %rcx
callq 0xe2d2
leaq 0x1194ee(%rip), %rax    # 0x2027c4
incl (%rax)
incl %r13d
cmpl $0x3, %r13d
movl $0x0, %eax
cmovel %eax, %r13d
leaq 0x124321(%rip), %rax    # 0x20d610
cmpl $0x9, (%rax)
jne 0xe92f9
addq %rbx, %rbx
jmp 0xe930d
leaq 0x13d97c(%rip), %rax    # 0x226c7c
movl (%rax), %esi
movq %rbx, %rdi
callq 0xe8915
movq %rax, %rbx
cmpq $0x186a0, %rbx          # imm = 0x186A0
jg 0xe931e
addl (%r15), %r12d
jmp 0xe9227
leaq 0x13d7c3(%rip), %rax    # 0x226ae8
movsd (%rax), %xmm2
movsd 0x9d3f(%rip), %xmm0     # 0xf3070
xorl %eax, %eax
cmpl $0x13, %eax
ja 0xe934a
ucomisd %xmm0, %xmm2
jae 0xe934a
divsd 0x9d62(%rip), %xmm0     # 0xf30a8
incl %eax
jmp 0xe9333
leaq 0x11952b(%rip), %rax    # 0x20287c
movl (%rax), %edi
leaq 0x11952e(%rip), %rax    # 0x202888
movl (%rax), %eax
leaq 0x119509(%rip), %rcx    # 0x20286c
movl (%rcx), %r14d
leal (%r14,%r14), %esi
cltd
idivl %esi
movl %eax, %ecx
movl %edx, %eax
pushq $0x2
popq %r8
cltd
idivl %r8d
xorl %r12d, %r12d
testb $0x1, %cl
movl $0x0, %ecx
cmovel %r14d, %ecx
addl %eax, %ecx
movl %ecx, %eax
addl %edi, %eax
movl %edi, %r15d
movl %eax, -0x34(%rbp)
cmovnel %eax, %r15d
testl %ecx, %ecx
cmovlel %edi, %r15d
leaq 0x11945f(%rip), %rcx    # 0x202804
leaq 0x20d3fc(%rip), %rax    # 0x2f67a8
cmpb $0x50, (%rax)
movl (%rcx), %eax
cmovel %esi, %r14d
cmpl $0x259, %eax            # imm = 0x259
cmovgel %esi, %r14d
cvtsi2sd %r14d, %xmm1
leaq 0x13d926(%rip), %rcx    # 0x226cf0
movsd %xmm1, (%rcx)
leaq 0x12423b(%rip), %rcx    # 0x20d610
cmpl $0x9, (%rcx)
jne 0xe93f6
xorpd %xmm0, %xmm0
movsd 0x9c8a(%rip), %xmm1     # 0xf3070
movl %r15d, %ecx
cmpl %eax, %ecx
jge 0xe9409
addsd %xmm1, %xmm0
addl %r14d, %ecx
jmp 0xe93e9
mulsd 0x9caa(%rip), %xmm0     # 0xf30a8
xorpd %xmm3, %xmm3
movsd %xmm0, -0x30(%rbp)
jmp 0xe9441
movsd 0x2d28f(%rip), %xmm1    # 0x1166a0
movapd %xmm2, %xmm3
mulsd %xmm1, %xmm3
leaq 0x13d6d0(%rip), %rcx    # 0x226af0
movsd (%rcx), %xmm2
divsd %xmm1, %xmm2
movsd %xmm3, -0x30(%rbp)
subsd %xmm2, %xmm3
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xe943d
jnp 0xe9441
divsd %xmm0, %xmm3
leal 0x2(%r15), %r13d
leaq 0x23cdd4(%rip), %rbx    # 0x326220
movsd %xmm3, -0x40(%rbp)
cmpl %eax, %r15d
jge 0xe9522
leaq 0x1241af(%rip), %rax    # 0x20d610
cmpl $0x9, (%rax)
jne 0xe9488
movq %rbx, %rdi
leaq 0x36546(%rip), %rsi     # 0x11f9b6
movsd -0x30(%rbp), %xmm0
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
jmp 0xe94ab
movq %rbx, %rdi
leaq 0x2ff65(%rip), %rsi     # 0x1193f7
movsd -0x30(%rbp), %xmm0
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm0
divsd 0x9bfd(%rip), %xmm0     # 0xf30a8
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
callq 0x9120
movq %rax, %rsi
notl %esi
leaq 0x11934c(%rip), %rax    # 0x202810
imull (%rax), %esi
testl %r12d, %r12d
jne 0xe94dd
movl %r13d, %edi
leaq 0x1193a6(%rip), %rax    # 0x20287c
movl -0x34(%rbp), %ecx
cmpl %ecx, (%rax)
je 0xe94f1
leaq 0x119330(%rip), %rax    # 0x202814
movl (%rax), %eax
cltd
pushq $-0x2
popq %rcx
idivl %ecx
movl %eax, %edi
addl %r15d, %edi
leaq 0x119388(%rip), %rax    # 0x202880
addl (%rax), %esi
leaq 0x119383(%rip), %rax    # 0x202884
addl (%rax), %esi
pushq $0xa
popq %rdx
movq %rbx, %rcx
callq 0xe2d2
addl %r14d, %r15d
leaq 0x1192ec(%rip), %rax    # 0x202804
movl (%rax), %eax
addl %r14d, %r12d
jmp 0xe9451
cvtsd2ss -0x30(%rbp), %xmm0
movss %xmm0, 0x27b089(%rip)   # 0x3645b8
leaq 0x119332(%rip), %rax    # 0x202868
movb $0x0, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq