// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rsi, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
movq 0x8(%rdi), %rax
movq 0x58(%rax), %rdi
callq 0x2c939
movsd %xmm0, 0x48(%rsp)
leaq 0x2f(%rsp), %rcx
movb $0x1, (%rcx)
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5bb50(%rip), %rsi     # 0xca196
leaq 0x712b9(%rip), %rdx     # 0xdf906
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x3440a
pushq $-0x1
popq %r13
cmpl $0x2, %eax
je 0x6ebf3
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5bb22(%rip), %rsi     # 0xca196
leaq 0x71295(%rip), %rdx     # 0xdf910
leaq 0x48(%rsp), %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x33ff8
cmpl $0x2, %eax
je 0x6ebf3
leaq 0xb8(%rsp), %rcx
andq $0x0, (%rcx)
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5bae7(%rip), %rsi     # 0xca196
leaq 0x7126a(%rip), %rdx     # 0xdf920
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x33ff8
cmpl $0x2, %eax
je 0x6ebf3
leaq 0x2e(%rsp), %rcx
movb $0x0, (%rcx)
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5bab5(%rip), %rsi     # 0xca196
leaq 0x71245(%rip), %rdx     # 0xdf92d
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x3440a
cmpl $0x2, %eax
je 0x6ebf3
callq 0x13d5c
movq %rax, %rbx
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5ba83(%rip), %rsi     # 0xca196
leaq 0x71223(%rip), %rdx     # 0xdf93d
movq %rbx, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x33b98
cmpl $0x2, %eax
jne 0x6e736
pushq $-0x1
popq %r13
jmp 0x6ebeb
callq 0x13d5c
movq %rax, %r15
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5ba49(%rip), %rsi     # 0xca196
leaq 0x711ee(%rip), %rdx     # 0xdf942
movq %r15, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x33b98
cmpl $0x2, %eax
je 0x6e808
cmpl $0x1, %eax
jne 0x6e77f
leaq 0x711db(%rip), %rsi     # 0xdf952
movq %r15, %rdi
callq 0x13dd3
callq 0x13d5c
movq %rax, %r12
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5ba00(%rip), %rsi     # 0xca196
leaq 0x711b8(%rip), %rdx     # 0xdf955
movq %r12, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x33b98
cmpl $0x2, %eax
je 0x6e811
cmpl $0x1, %eax
jne 0x6e7c4
leaq 0x711aa(%rip), %rsi     # 0xdf966
movq %r12, %rdi
callq 0x13dd3
leaq 0x67494(%rip), %rdi     # 0xd5c5f
callq 0x13da9
movq %rax, %r13
movq 0x8(%r14), %rax
movq 0x38(%rax), %rdi
leaq 0x5b9b4(%rip), %rsi     # 0xca196
leaq 0x71180(%rip), %rdx     # 0xdf969
movq %r13, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x33b98
cmpl $0x2, %eax
jne 0x6e81a
movq %r13, %rdi
pushq $-0x1
popq %r13
jmp 0x6ebcd
pushq $-0x1
popq %r13
jmp 0x6ebe0
pushq $-0x1
popq %r13
jmp 0x6ebd2
movq %r12, 0xb0(%rsp)
movq 0x8(%r14), %rax
movq 0x58(%rax), %r12
movq %r13, 0xa8(%rsp)
movq %r13, %rdi
callq 0x143d2
movsd 0x48(%rsp), %xmm0
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cad8
movaps 0x70dca(%rip), %xmm0    # 0xdf620
movaps %xmm0, 0x80(%rsp)
movaps 0x70dcb(%rip), %xmm0    # 0xdf630
movaps %xmm0, 0x90(%rsp)
movaps 0x70dcc(%rip), %xmm0    # 0xdf640
movaps %xmm0, 0xc0(%rsp)
movaps 0x70dcd(%rip), %xmm0    # 0xdf650
movaps %xmm0, 0xd0(%rsp)
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x5d05e
cvtsi2sd %rax, %xmm0
callq 0xb2b0
callq 0xb0e0
movapd %xmm0, %xmm1
addsd 0x6584d(%rip), %xmm1    # 0xd4100
movsd 0x70ced(%rip), %xmm0    # 0xdf5a8
callq 0xbaf0
movsd %xmm0, 0x30(%rsp)
movapd %xmm0, %xmm1
movsd (%r12), %xmm0
unpcklps 0x5bba9(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
divsd 0x70cc9(%rip), %xmm1    # 0xdf5a8
subpd 0x5bba9(%rip), %xmm0    # 0xca490
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 0xbab0
movsd %xmm0, 0xa0(%rsp)
movapd 0x50(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
callq 0xbab0
mulsd 0x30(%rsp), %xmm0
leaq 0xe0(%rsp), %r13
cvttsd2si %xmm0, %rbp
movq 0x70(%rsp), %rsi
cmpq %rbp, %rsi
jb 0x6ea50
movq 0x68(%rsp), %rdi
movq %rbp, %rdx
callq 0x6ee9c
cmpq %rbp, 0x68(%rsp)
ja 0x6ea40
cvttsd2si 0xb8(%rsp), %r12
addq %rbp, %r12
movzbl 0x2e(%rsp), %eax
testq %r12, %r12
movl $0x0, %ecx
cmovleq %rax, %rcx
subq %rcx, %r12
movq 0x8(%r14), %rax
movsd 0x20(%rax), %xmm3
movsd 0x28(%rax), %xmm1
unpcklps 0x5baeb(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x5baf3(%rip), %xmm1    # 0xca490
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 0x6649c(%rip), %xmm1    # 0xd4e70
movaps 0x80(%rsp), %xmm3
movaps 0x90(%rsp), %xmm2
movups %xmm2, 0x10(%rsp)
movups %xmm3, (%rsp)
movsd 0x70bb3(%rip), %xmm2    # 0xdf5a8
movsd 0x5bef3(%rip), %xmm3    # 0xca8f0
callq 0x2cf85
movq %rbx, %rdi
callq 0x143d2
movl $0x2000, %ecx           # imm = 0x2000
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x29c3a
movq 0x8(%r14), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x70b8e(%rip), %xmm1    # 0xdf5c0
movsd 0x50(%rsp), %xmm0
movq %r13, %rsi
callq 0x2c750
cvtsi2sd %rbp, %xmm0
addsd 0x30(%rsp), %xmm0
jmp 0x6e934
movsd 0x78(%rsp), %xmm0
ucomisd 0x5be92(%rip), %xmm0    # 0xca8f0
jae 0x6ec08
movq 0x8(%r14), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
movsd 0x20(%rax), %xmm0
addsd 0x65e52(%rip), %xmm1    # 0xd48d0
movsd 0x28(%rax), %xmm3
movsd 0x5b9f5(%rip), %xmm2    # 0xca480
unpcklps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
subpd 0x5b9fa(%rip), %xmm3    # 0xca490
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 0x70b01(%rip), %xmm3    # 0xdf5d0
callq 0x2cec7
movq 0x8(%r14), %rax
movsd 0x20(%rax), %xmm0
addsd 0x70acb(%rip), %xmm0    # 0xdf5b0
movsd %xmm0, 0x30(%rsp)
movq 0x58(%rax), %r12
movsd 0x18(%rax), %xmm0
addsd 0x70adc(%rip), %xmm0    # 0xdf5d8
movsd 0x48(%rsp), %xmm1
mulsd 0x64b36(%rip), %xmm1    # 0xd3640
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
movq %r15, %rdi
callq 0x143d2
movq %r12, %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movq %rax, %rsi
callq 0x2c7ea
movq 0x8(%r14), %rax
movsd 0x28(%rax), %xmm0
unpcklps 0x5b93d(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5b945(%rip), %xmm0    # 0xca490
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
subsd 0x20(%rax), %xmm1
addsd 0x70a44(%rip), %xmm1    # 0xdf5a8
movapd %xmm1, 0x30(%rsp)
movsd 0x70a66(%rip), %xmm1    # 0xdf5d8
addsd 0x18(%rax), %xmm1
movq 0x58(%rax), %r14
movsd 0x64abd(%rip), %xmm0    # 0xd3640
mulsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0xb0(%rsp), %r12
movq %r12, %rdi
callq 0x143d2
movq %r14, %rdi
movaps 0x30(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movq %rax, %rsi
callq 0x2c61c
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r15, %rbx
movq %r12, %r15
movq 0xa8(%rsp), %r12
callq 0x152db
movq %rbx, %rdi
callq 0x152db
movq %r15, %rbx
movq %r12, %r15
movq %rbx, %rdi
callq 0x152db
movq %r15, %rbx
movq %rbx, %rdi
callq 0x152db
movl %r13d, %eax
addq $0x20e8, %rsp           # imm = 0x20E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0xa0(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r13
cmpq %r13, %rsi
jb 0x6ea64
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
ja 0x6ed49
movq %r13, %rdx
callq 0x6ee9c
movapd 0x5b84f(%rip), %xmm4    # 0xca490
movq 0x8(%r14), %rax
movsd 0x28(%rax), %xmm1
movsd 0x5b82e(%rip), %xmm3    # 0xca480
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 0x6ecfb
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x65c3a(%rip), %xmm1    # 0xd48d0
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 0x5bc14(%rip), %xmm3    # 0xca8f0
movapd %xmm5, 0x30(%rsp)
callq 0x2cf85
movsd 0x5bc01(%rip), %xmm3    # 0xca8f0
movapd 0x30(%rsp), %xmm5
movq 0x8(%r14), %rax
jmp 0x6ed03
movsd 0x5bbed(%rip), %xmm3    # 0xca8f0
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x708b4(%rip), %xmm1    # 0xdf5c8
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm2
movups %xmm2, 0x10(%rsp)
movups %xmm0, (%rsp)
movapd %xmm5, %xmm0
movsd 0x653cf(%rip), %xmm2    # 0xd4108
callq 0x2cf85
movq 0x70(%rsp), %rsi
movsd 0x78(%rsp), %xmm0
cvtsi2sd %r13, %xmm1
addsd %xmm0, %xmm1
jmp 0x6ec15
nop