// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/annotationsketch/canvas_cairo.c
// Function: gt_canvas_cairo_draw_ruler
int gt_canvas_cairo_draw_ruler(GtCanvas *canvas, GtRange viewrange,
                                GtError *err)
{
  double step, minorstep, vmajor, vminor, offset,
         theight = gt_graphics_get_text_height(canvas->pvt->g);
  GtWord base_length, tick;
  GtColor rulercol, gridcol;
  GtStr *left_str = NULL, *right_str = NULL, *unit = NULL, *fontfam = NULL;
  char str[BUFSIZ];
  GtStyleQueryStatus rval;
  bool showgrid = true, nozeropos = false;
  gt_assert(canvas);

  if (gt_style_get_bool(canvas->pvt->sty, "format", "show_grid", &showgrid,
                        NULL, err) == GT_STYLE_QUERY_ERROR) {
    return -1;
  }
  if (gt_style_get_num(canvas->pvt->sty, "format", "ruler_font_size",
                       &theight, NULL, err) == GT_STYLE_QUERY_ERROR) {
    return -1;
  }

  /* get offset value from style, default: 0 */
  offset = 0;
  if (gt_style_get_num(canvas->pvt->sty, "format", "ruler_offset",
                       &offset, NULL, err) == GT_STYLE_QUERY_ERROR) {
    return -1;
  }

  nozeropos = false;
  if (gt_style_get_bool(canvas->pvt->sty, "format", "ruler_nozeropos",
                        &nozeropos, NULL, err) == GT_STYLE_QUERY_ERROR) {
    return -1;
  }

  /* get unit value from style, default: empty */
  unit = gt_str_new();
  if (gt_style_get_str(canvas->pvt->sty,
                       "format", "unit",
                       unit, NULL, err) == GT_STYLE_QUERY_ERROR) {
    gt_str_delete(unit);
    return -1;
  }

  /* get additional description texts from style */
  left_str = gt_str_new();
  rval = gt_style_get_str(canvas->pvt->sty, "format",
                          "ruler_left_text", left_str, NULL, err);
  switch (rval) {
    case GT_STYLE_QUERY_NOT_SET:
      gt_str_append_cstr(left_str, FIVE_PRIME_STRING);
      break;
    case GT_STYLE_QUERY_ERROR:
      gt_str_delete(unit);
      gt_str_delete(left_str);
      return -1;
      break;  /* shouldn't reach this */
    default:
      break;
  }

  right_str = gt_str_new();
  rval = gt_style_get_str(canvas->pvt->sty, "format",
                        "ruler_right_text", right_str, NULL, err);
  switch (rval) {
    case GT_STYLE_QUERY_NOT_SET:
      gt_str_append_cstr(right_str, THREE_PRIME_STRING);
      break;
    case GT_STYLE_QUERY_ERROR:
      gt_str_delete(unit);
      gt_str_delete(left_str);
      gt_str_delete(right_str);
      return -1;
      break;  /* shouldn't reach this */
    default:
      break;
  }

  fontfam = gt_str_new_cstr("Sans");
  if (gt_style_get_str(canvas->pvt->sty,
                       "format", "ruler_font_family",
                       fontfam, NULL, err ) == GT_STYLE_QUERY_ERROR) {
    gt_str_delete(fontfam);
    gt_str_delete(unit);
    gt_str_delete(left_str);
    gt_str_delete(right_str);
    return -1;
  }

  /* reset font to default */
  gt_graphics_set_font(canvas->pvt->g,
                       gt_str_get(fontfam),
                       SLANT_NORMAL,
                       WEIGHT_NORMAL,
                       theight);

  rulercol.red = rulercol.green = rulercol.blue = RULER_GREY;
  rulercol.alpha = 1.0;
  gridcol.red = gridcol.green = gridcol.blue = GRID_GREY;
  gridcol.alpha = 1.0;

  /* determine range and step of the scale */
  base_length = gt_range_length(&viewrange);

  /* determine tick steps */
  step = pow(10,ceil(log10(base_length))-1);
  minorstep = step/10.0;

  /* calculate starting positions */
  vminor = (double) (floor(viewrange.start / minorstep))*minorstep;
  vmajor = (double) (floor(viewrange.start / step))*step;

  /* draw major ticks */
  for (tick = vmajor; tick <= viewrange.end; tick += step)
  {
    double drawtick = (gt_coords_convert_point(viewrange, tick)
                       * (canvas->pvt->width-2*canvas->pvt->margins))
                       + canvas->pvt->margins;
    GtWord pos = tick + (GtWord)offset;
    if (pos <= 0 && nozeropos)
      pos--;
    if (tick < viewrange.start) continue;
    gt_graphics_draw_vertical_line(canvas->pvt->g,
                                   drawtick,
                                   canvas->pvt->y + 30,
                                   rulercol,
                                   10,
                                   1.0);
    gt_format_ruler_label(str, pos, gt_str_get(unit), BUFSIZ);
    gt_graphics_draw_text_centered(canvas->pvt->g,
                                   drawtick,
                                   canvas->pvt->y + 20,
                                   str);
  }
  /* draw minor ticks */
  if (minorstep >= 1)
  {
    for (tick = vminor; tick <= viewrange.end; tick += minorstep)
    {
      double drawtick;
      if (tick < viewrange.start)
        continue;
      drawtick = (gt_coords_convert_point(viewrange, tick)
                    * (canvas->pvt->width-2*canvas->pvt->margins))
                  + canvas->pvt->margins;
      if (showgrid)
      {
        gt_graphics_draw_vertical_line(canvas->pvt->g,
                                       drawtick,
                                       canvas->pvt->y + 40,
                                       gridcol,
                                       canvas->pvt->height - 40 - 15,
                                       1.0);
      }
      gt_graphics_draw_vertical_line(canvas->pvt->g,
                                     drawtick,
                                     canvas->pvt->y + 35,
                                     rulercol,
                                     5,
                                     1.0);
    }
  }
  /* draw ruler line */
  gt_graphics_draw_horizontal_line(canvas->pvt->g,
                                   canvas->pvt->margins,
                                   canvas->pvt->y + 40,
                                   rulercol,
                                   canvas->pvt->width - 2
                                     * canvas->pvt->margins,
                                   1.25);

  gt_graphics_draw_text_right(canvas->pvt->g,
                              canvas->pvt->margins - 10,
                              canvas->pvt->y + 39 + (theight/2),
                              gt_str_get(left_str));
  gt_graphics_draw_text(canvas->pvt->g,
                        canvas->pvt->width - canvas->pvt->margins + 10,
                        canvas->pvt->y + 39 + (theight/2),
                        gt_str_get(right_str));

  gt_str_delete(unit);
  gt_str_delete(left_str);
  gt_str_delete(right_str);
  gt_str_delete(fontfam);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20e8, %rsp           # imm = 0x20E8
movq %rcx, %rbp
movq %rdi, %rbx
movq %rsi, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
movq 0x8(%rdi), %rax
movq 0x58(%rax), %rdi
callq 0x4de34
movsd %xmm0, 0x48(%rsp)
leaq 0x2f(%rsp), %rcx
movb $0x1, (%rcx)
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53d4a(%rip), %rsi     # 0xe1196
leaq 0x69163(%rip), %rdx     # 0xf65b6
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x53bf6
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
je 0x8db7f
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53d1a(%rip), %rsi     # 0xe1196
leaq 0x6913d(%rip), %rdx     # 0xf65c0
leaq 0x48(%rsp), %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5393e
cmpl $0x2, %eax
je 0x8db7f
leaq 0xb8(%rsp), %rcx
movq $0x0, (%rcx)
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53cdc(%rip), %rsi     # 0xe1196
leaq 0x6910f(%rip), %rdx     # 0xf65d0
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5393e
cmpl $0x2, %eax
je 0x8db7f
leaq 0x2e(%rsp), %rcx
movb $0x0, (%rcx)
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53caa(%rip), %rsi     # 0xe1196
leaq 0x690ea(%rip), %rdx     # 0xf65dd
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x53bf6
cmpl $0x2, %eax
je 0x8db7f
callq 0x3b728
movq %rax, %r14
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53c78(%rip), %rsi     # 0xe1196
leaq 0x690c8(%rip), %rdx     # 0xf65ed
movq %r14, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5363b
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
je 0x8db77
callq 0x3b728
movq %rax, %r15
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53c3d(%rip), %rsi     # 0xe1196
leaq 0x69092(%rip), %rdx     # 0xf65f2
movq %r15, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5363b
cmpl $0x2, %eax
je 0x8d620
cmpl $0x1, %eax
jne 0x8d58b
leaq 0x6907f(%rip), %rsi     # 0xf6602
movq %r15, %rdi
callq 0x3b7af
callq 0x3b728
movq %rax, %r12
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53bf4(%rip), %rsi     # 0xe1196
leaq 0x6905c(%rip), %rdx     # 0xf6605
movq %r12, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5363b
cmpl $0x2, %eax
je 0x8d62b
movq %r15, 0x60(%rsp)
cmpl $0x1, %eax
jne 0x8d5d5
leaq 0x69049(%rip), %rsi     # 0xf6616
movq %r12, %rdi
callq 0x3b7af
leaq 0x5f693(%rip), %rdi     # 0xecc6f
callq 0x3b785
movq %rax, %r15
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53ba3(%rip), %rsi     # 0xe1196
leaq 0x6901f(%rip), %rdx     # 0xf6619
movq %r15, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5363b
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jne 0x8d636
movq %r15, %rdi
movq 0x60(%rsp), %r15
jmp 0x8db59
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x8db6c
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x8db5e
movq %r12, 0xb0(%rsp)
movq 0x8(%rbx), %rax
movq 0x58(%rax), %r12
movq %r15, 0xa8(%rsp)
movq %r15, %rdi
callq 0x3bb5d
movsd 0x48(%rsp), %xmm0
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4df3a
movaps 0x68c5e(%rip), %xmm0    # 0xf62d0
movaps %xmm0, 0x80(%rsp)
movaps 0x68c5f(%rip), %xmm0    # 0xf62e0
movaps %xmm0, 0x90(%rsp)
movaps 0x68c60(%rip), %xmm0    # 0xf62f0
movaps %xmm0, 0xc0(%rsp)
movaps 0x68c61(%rip), %xmm0    # 0xf6300
movaps %xmm0, 0xd0(%rsp)
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x7e19f
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0xb2b0
callq 0xb0e0
movapd %xmm0, %xmm1
addsd 0x5da3e(%rip), %xmm1    # 0xeb110
movsd 0x68b6e(%rip), %xmm0    # 0xf6248
callq 0xbb00
movsd %xmm0, 0x30(%rsp)
movapd %xmm0, %xmm1
movsd (%r12), %xmm0
unpcklps 0x53d8a(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
divsd 0x68b4a(%rip), %xmm1    # 0xf6248
subpd 0x53d8a(%rip), %xmm0    # 0xe1490
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
movapd %xmm2, 0x50(%rsp)
movapd %xmm2, %xmm0
movsd %xmm1, 0x78(%rsp)
divsd %xmm1, %xmm0
callq 0xbac0
movsd %xmm0, 0xa0(%rsp)
movapd 0x50(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
callq 0xbac0
mulsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %r13
movq 0x8(%r12), %rsi
cmpq %r13, %rsi
jae 0x8d764
movq 0x60(%rsp), %r15
jmp 0x8d88b
leaq 0xe0(%rsp), %rbp
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %rdi
movq %r13, %rdx
callq 0x8dc7c
cmpq %r13, 0x68(%rsp)
ja 0x8d86a
cvttsd2si 0xb8(%rsp), %r12
addq %r13, %r12
movzbl 0x2e(%rsp), %eax
testq %r12, %r12
movl $0x0, %ecx
cmovgq %rcx, %rax
subq %rax, %r12
movq 0x8(%rbx), %rax
movsd 0x20(%rax), %xmm3
movsd 0x28(%rax), %xmm1
unpcklps 0x53cc1(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x53cc9(%rip), %xmm1    # 0xe1490
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movapd %xmm3, %xmm1
addsd %xmm3, %xmm1
subsd %xmm1, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x5e682(%rip), %xmm1    # 0xebe80
movaps 0x80(%rsp), %xmm3
movaps 0x90(%rsp), %xmm2
movups %xmm2, 0x10(%rsp)
movups %xmm3, (%rsp)
movsd 0x68a29(%rip), %xmm2    # 0xf6248
movsd 0x540c9(%rip), %xmm3    # 0xe18f0
callq 0x4e24f
movq %r14, %rdi
callq 0x3bb5d
movl $0x2000, %ecx           # imm = 0x2000
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4bb48
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x68a0c(%rip), %xmm1    # 0xf6268
movsd 0x50(%rsp), %xmm0
movq %rbp, %rsi
callq 0x4dce4
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
addsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %r13
movq 0x70(%rsp), %rsi
cmpq %r13, %rsi
jae 0x8d771
movsd 0x78(%rsp), %xmm1
ucomisd 0x54057(%rip), %xmm1    # 0xe18f0
movq 0xa8(%rsp), %rbp
jb 0x8d9f9
movsd 0xa0(%rsp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13
cmpq %r13, %rsi
jb 0x8d9f9
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
ja 0x8d9e8
movq %r13, %rdx
callq 0x8dc7c
movapd 0x53bb0(%rip), %xmm4    # 0xe1490
movsd 0x53b98(%rip), %xmm3    # 0xe1480
movq 0x8(%rbx), %rax
movsd 0x28(%rax), %xmm1
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm4, %xmm1
movapd %xmm1, %xmm5
unpckhpd %xmm1, %xmm5            # xmm5 = xmm5[1],xmm1[1]
addsd %xmm1, %xmm5
movsd 0x20(%rax), %xmm1
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
subsd %xmm2, %xmm5
mulsd %xmm0, %xmm5
addsd %xmm1, %xmm5
cmpb $0x1, 0x2f(%rsp)
jne 0x8d99a
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x5dfab(%rip), %xmm1    # 0xeb8e0
movq 0x30(%rax), %rax
addq $-0x37, %rax
movq %rax, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
movaps 0xc0(%rsp), %xmm0
movaps 0xd0(%rsp), %xmm3
movups %xmm3, 0x10(%rsp)
movups %xmm0, (%rsp)
movapd %xmm5, %xmm0
movsd 0x53f75(%rip), %xmm3    # 0xe18f0
movapd %xmm5, 0x30(%rsp)
callq 0x4e24f
movsd 0x53f62(%rip), %xmm3    # 0xe18f0
movapd 0x30(%rsp), %xmm5
movq 0x8(%rbx), %rax
jmp 0x8d9a2
movsd 0x53f4e(%rip), %xmm3    # 0xe18f0
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x688bd(%rip), %xmm1    # 0xf6270
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm2
movups %xmm2, 0x10(%rsp)
movups %xmm0, (%rsp)
movapd %xmm5, %xmm0
movsd 0x5d740(%rip), %xmm2    # 0xeb118
callq 0x4e24f
movq 0x70(%rsp), %rsi
movsd 0x78(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
addsd %xmm1, %xmm0
jmp 0x8d8b4
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x5ded2(%rip), %xmm1    # 0xeb8e0
movsd 0x20(%rax), %xmm0
movsd 0x28(%rax), %xmm3
unpcklps 0x53a61(%rip), %xmm3    # xmm3 = xmm3[0],mem[0],xmm3[1],mem[1]
subpd 0x53a69(%rip), %xmm3    # 0xe1490
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
movapd %xmm0, %xmm3
addsd %xmm0, %xmm3
subsd %xmm3, %xmm2
movaps 0x80(%rsp), %xmm3
movaps 0x90(%rsp), %xmm4
movups %xmm4, 0x10(%rsp)
movups %xmm3, (%rsp)
movsd 0x68818(%rip), %xmm3    # 0xf6278
callq 0x4e1c4
movq 0x8(%rbx), %rax
movsd 0x20(%rax), %xmm0
addsd 0x687e2(%rip), %xmm0    # 0xf6258
movsd %xmm0, 0x30(%rsp)
movq 0x58(%rax), %r12
movsd 0x18(%rax), %xmm0
addsd 0x687f3(%rip), %xmm0    # 0xf6280
movsd 0x48(%rsp), %xmm1
mulsd 0x5cbb5(%rip), %xmm1    # 0xea650
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movq %r15, %rdi
callq 0x3bb5d
movq %r12, %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movq %rax, %rsi
callq 0x4dd4b
movq 0x8(%rbx), %rax
movsd 0x28(%rax), %xmm0
unpcklps 0x539ac(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x539b4(%rip), %xmm0    # 0xe1490
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
subsd 0x20(%rax), %xmm1
addsd 0x68753(%rip), %xmm1    # 0xf6248
movapd %xmm1, 0x30(%rsp)
movsd 0x6877d(%rip), %xmm1    # 0xf6280
addsd 0x18(%rax), %xmm1
movq 0x58(%rax), %rbx
movsd 0x5cb3c(%rip), %xmm0    # 0xea650
mulsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0xb0(%rsp), %r12
movq %r12, %rdi
callq 0x3bb5d
movq %rbx, %rdi
movaps 0x30(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movq %rax, %rsi
callq 0x4dc16
xorl %r13d, %r13d
movq %r14, %rdi
movq %r15, %r14
movq %r12, %r15
movq %rbp, %r12
callq 0x3c87b
movq %r14, %rdi
callq 0x3c87b
movq %r15, %r14
movq %r12, %r15
movq %r14, %rdi
callq 0x3c87b
movq %r15, %r14
movq %r14, %rdi
callq 0x3c87b
movl %r13d, %eax
addq $0x20e8, %rsp           # imm = 0x20E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq