// File: /workspace/github_c_makefile_star2_O1/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, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq 0x8(%rdi), %rax
movq 0x58(%rax), %rdi
callq 0x4eae0
movsd %xmm0, 0x48(%rsp)
movb $0x1, 0x2f(%rsp)
movb $0x0, 0x2e(%rsp)
testq %rbx, %rbx
je 0x8e0b2
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53821(%rip), %rsi     # 0xe1196
leaq 0x68cb5(%rip), %rdx     # 0xf6631
leaq 0x2f(%rsp), %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5488a
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
je 0x8df55
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x537ec(%rip), %rsi     # 0xe1196
leaq 0x68c8a(%rip), %rdx     # 0xf663b
leaq 0x48(%rsp), %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x545d2
cmpl $0x2, %eax
je 0x8df55
leaq 0xb8(%rsp), %rcx
movq $0x0, (%rcx)
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x537ae(%rip), %rsi     # 0xe1196
leaq 0x68c5c(%rip), %rdx     # 0xf664b
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x545d2
cmpl $0x2, %eax
je 0x8df55
leaq 0x2e(%rsp), %rcx
movb $0x0, (%rcx)
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x5377c(%rip), %rsi     # 0xe1196
leaq 0x68c37(%rip), %rdx     # 0xf6658
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x5488a
cmpl $0x2, %eax
je 0x8df55
callq 0x3bfe0
movq %rax, %r14
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x5374a(%rip), %rsi     # 0xe1196
leaq 0x68c15(%rip), %rdx     # 0xf6668
movq %r14, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x542cf
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
je 0x8df4d
callq 0x3bfe0
movq %rax, %r15
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x5370f(%rip), %rsi     # 0xe1196
leaq 0x68bdf(%rip), %rdx     # 0xf666d
movq %r15, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x542cf
cmpl $0x2, %eax
je 0x8db4e
cmpl $0x1, %eax
jne 0x8dab9
leaq 0x68bcc(%rip), %rsi     # 0xf667d
movq %r15, %rdi
callq 0x3c067
callq 0x3bfe0
movq %rax, %r12
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x536c6(%rip), %rsi     # 0xe1196
leaq 0x68ba9(%rip), %rdx     # 0xf6680
movq %r12, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x542cf
cmpl $0x2, %eax
je 0x8db59
movq %r15, 0x70(%rsp)
cmpl $0x1, %eax
jne 0x8db03
leaq 0x68b96(%rip), %rsi     # 0xf6691
movq %r12, %rdi
callq 0x3c067
leaq 0x5f1b5(%rip), %rdi     # 0xeccbf
callq 0x3c03d
movq %rax, %r15
movq 0x8(%rbx), %rax
movq 0x38(%rax), %rdi
leaq 0x53675(%rip), %rsi     # 0xe1196
leaq 0x68b6c(%rip), %rdx     # 0xf6694
movq %r15, %rcx
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x542cf
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jne 0x8db64
movq %r15, %rdi
movq 0x70(%rsp), %r15
jmp 0x8df2f
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x8df42
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x8df34
movq %r12, 0xb0(%rsp)
movq 0x8(%rbx), %rax
movq 0x58(%rax), %r12
movq %r15, 0xa8(%rsp)
movq %r15, %rdi
callq 0x3c40b
movsd 0x48(%rsp), %xmm0
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4ebe6
movaps 0x68790(%rip), %xmm0    # 0xf6330
movaps %xmm0, 0x80(%rsp)
movaps 0x68791(%rip), %xmm0    # 0xf6340
movaps %xmm0, 0x90(%rsp)
movaps 0x68792(%rip), %xmm0    # 0xf6350
movaps %xmm0, 0xc0(%rsp)
movaps 0x68793(%rip), %xmm0    # 0xf6360
movaps %xmm0, 0xd0(%rsp)
leaq 0x50(%rsp), %r12
movq %r12, %rdi
callq 0x7e05b
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0xb2b0
callq 0xb0e0
movapd %xmm0, %xmm1
addsd 0x5d560(%rip), %xmm1    # 0xeb160
movsd 0x686a0(%rip), %xmm0    # 0xf62a8
callq 0xbb00
movsd %xmm0, 0x30(%rsp)
movapd %xmm0, %xmm1
movsd (%r12), %xmm0
unpcklps 0x5385c(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
divsd 0x6867c(%rip), %xmm1    # 0xf62a8
subpd 0x5385c(%rip), %xmm0    # 0xe1490
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
movapd %xmm2, 0x60(%rsp)
movapd %xmm2, %xmm0
movsd %xmm1, 0x78(%rsp)
divsd %xmm1, %xmm0
callq 0xbac0
movsd %xmm0, 0xa0(%rsp)
movapd 0x60(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
callq 0xbac0
mulsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %r13
movq 0x8(%r12), %rsi
cmpq %r13, %rsi
movq 0x70(%rsp), %r15
jb 0x8ddb3
leaq 0xe0(%rsp), %rbp
movq 0x50(%rsp), %rdi
movq %r13, %rdx
callq 0x8e1a0
cmpq %r13, 0x50(%rsp)
ja 0x8dd92
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 0x53799(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x537a1(%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, 0x60(%rsp)
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x5e1aa(%rip), %xmm1    # 0xebed0
movaps 0x80(%rsp), %xmm3
movaps 0x90(%rsp), %xmm2
movups %xmm2, 0x10(%rsp)
movups %xmm3, (%rsp)
movsd 0x68561(%rip), %xmm2    # 0xf62a8
movsd 0x53ba1(%rip), %xmm3    # 0xe18f0
callq 0x4eefb
movq %r14, %rdi
callq 0x3c40b
movl $0x2000, %ecx           # imm = 0x2000
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4c7cc
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x68544(%rip), %xmm1    # 0xf62c8
movsd 0x60(%rsp), %xmm0
movq %rbp, %rsi
callq 0x4e990
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
addsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %r13
movq 0x58(%rsp), %rsi
cmpq %r13, %rsi
jae 0x8dc99
movsd 0x78(%rsp), %xmm1
ucomisd 0x53b2f(%rip), %xmm1    # 0xe18f0
movq 0xa8(%rsp), %rbp
jae 0x8df6a
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x5db4c(%rip), %xmm1    # 0xeb930
movsd 0x20(%rax), %xmm0
movsd 0x28(%rax), %xmm3
unpcklps 0x5368b(%rip), %xmm3    # xmm3 = xmm3[0],mem[0],xmm3[1],mem[1]
subpd 0x53693(%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 0x684a2(%rip), %xmm3    # 0xf62d8
callq 0x4ee70
movq 0x8(%rbx), %rax
movsd 0x20(%rax), %xmm0
addsd 0x6846c(%rip), %xmm0    # 0xf62b8
movsd %xmm0, 0x30(%rsp)
movq 0x58(%rax), %r12
movsd 0x18(%rax), %xmm0
addsd 0x6847d(%rip), %xmm0    # 0xf62e0
movsd 0x48(%rsp), %xmm1
mulsd 0x5c82f(%rip), %xmm1    # 0xea6a0
addsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movq %r15, %rdi
callq 0x3c40b
movq %r12, %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movq %rax, %rsi
callq 0x4e9f7
movq 0x8(%rbx), %rax
movsd 0x28(%rax), %xmm0
unpcklps 0x535d6(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x535de(%rip), %xmm0    # 0xe1490
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
subsd 0x20(%rax), %xmm1
addsd 0x683dd(%rip), %xmm1    # 0xf62a8
movapd %xmm1, 0x30(%rsp)
movsd 0x68407(%rip), %xmm1    # 0xf62e0
addsd 0x18(%rax), %xmm1
movq 0x58(%rax), %rbx
movsd 0x5c7b6(%rip), %xmm0    # 0xea6a0
mulsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0xb0(%rsp), %r12
movq %r12, %rdi
callq 0x3c40b
movq %rbx, %rdi
movaps 0x30(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movq %rax, %rsi
callq 0x4e8c2
xorl %r13d, %r13d
movq %r14, %rdi
movq %r15, %r14
movq %r12, %r15
movq %rbp, %r12
callq 0x3d1eb
movq %r14, %rdi
callq 0x3d1eb
movq %r15, %r14
movq %r12, %r15
movq %r14, %rdi
callq 0x3d1eb
movq %r15, %r14
movq %r14, %rdi
callq 0x3d1eb
movl %r13d, %eax
addq $0x20e8, %rsp           # imm = 0x20E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0xa0(%rsp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r13
movq 0x58(%rsp), %rsi
cmpq %r13, %rsi
jb 0x8ddcf
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
ja 0x8e0a1
movq %r13, %rdx
callq 0x8e1a0
movq 0x8(%rbx), %rax
movsd 0x28(%rax), %xmm1
unpcklps 0x534d0(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x534d8(%rip), %xmm1    # 0xe1490
movapd %xmm1, %xmm4
unpckhpd %xmm1, %xmm4            # xmm4 = xmm4[1],xmm1[1]
addsd %xmm1, %xmm4
movsd 0x20(%rax), %xmm1
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
subsd %xmm2, %xmm4
mulsd %xmm0, %xmm4
addsd %xmm1, %xmm4
cmpb $0x1, 0x2f(%rsp)
jne 0x8e054
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x5d93b(%rip), %xmm1    # 0xeb930
movq 0x30(%rax), %rax
addq $-0x37, %rax
movq %rax, %xmm0
punpckldq 0x53476(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5347e(%rip), %xmm0    # 0xe1490
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 %xmm4, %xmm0
movsd 0x538ad(%rip), %xmm3    # 0xe18f0
movapd %xmm4, 0x30(%rsp)
callq 0x4eefb
movapd 0x30(%rsp), %xmm4
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movsd 0x18(%rax), %xmm1
addsd 0x68267(%rip), %xmm1    # 0xf62d0
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm2
movups %xmm2, 0x10(%rsp)
movups %xmm0, (%rsp)
movapd %xmm4, %xmm0
movsd 0x5d0da(%rip), %xmm2    # 0xeb168
movsd 0x5385a(%rip), %xmm3    # 0xe18f0
callq 0x4eefb
movsd 0x78(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
addsd %xmm1, %xmm0
jmp 0x8df77
callq 0x216b4
nop