// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/annotationsketch/gt_sketch_page.c
// Function: gt_sketch_page_runner
static int gt_sketch_page_runner(GT_UNUSED int argc,
                                 const char **argv,
                                 int parsed_args,
                                 void *tool_arguments,
                                 GtError *err)
{
  SketchPageArguments *arguments = tool_arguments;
  int had_err = 0;
  GtFeatureIndex *features = NULL;
  GtRange qry_range, sequence_region_range;
  GtStyle *sty = NULL;
  GtStr *prog, *gt_style_file;
  GtDiagram *d = NULL;
  GtLayout *l = NULL;
  GtBioseq *bioseq = NULL;
  GtCanvas *canvas = NULL;
  char *seqid = NULL;
  const char *outfile = NULL;
  GtUword start, height, num_pages = 0;
  double offsetpos, usable_height;
  cairo_surface_t *surf = NULL;
  cairo_t *cr = NULL;
  bool has_seqid;
  GtTextWidthCalculator *twc;
  gt_error_check(err);

  features = gt_feature_index_memory_new();

  if (cairo_version() < CAIRO_VERSION_ENCODE(1, 8, 6))
    gt_warning("Your cairo library (version %s) is older than version 1.8.6! "
               "These versions contain a bug which may result in "
               "corrupted PDF output!", cairo_version_string());

  /* get style */
  sty = gt_style_new(err);
  if (gt_str_length(arguments->stylefile) == 0)
  {
    prog = gt_str_new();
    gt_str_append_cstr_nt(prog, argv[0],
                          gt_cstr_length_up_to_char(argv[0], ' '));
    gt_style_file = gt_get_gtdata_path(gt_str_get(prog), err);
    gt_str_delete(prog);
    gt_str_append_cstr(gt_style_file, "/sketch/default.style");
  }
  else
  {
    gt_style_file = gt_str_ref(arguments->stylefile);
  }
  had_err = gt_style_load_file(sty, gt_str_get(gt_style_file), err);
  if (!had_err) {
    had_err = gt_feature_index_has_seqid(features, &has_seqid,
                                         gt_str_get(arguments->seqid), err);
  }

  outfile = argv[parsed_args];
  if (!had_err)
  {
    /* get features */
    had_err = gt_feature_index_add_gff3file(features, argv[parsed_args+1], err);
     if (!had_err && gt_str_length(arguments->seqid) == 0) {
      seqid = gt_feature_index_get_first_seqid(features, err);
      if (seqid == NULL)
      {
        gt_error_set(err, "GFF input file must contain a sequence region!");
        had_err = -1;
      }
    }
    else if (!had_err && !has_seqid)
    {
      gt_error_set(err, "sequence region '%s' does not exist in GFF input file",
                   gt_str_get(arguments->seqid));
      had_err = -1;
    }
    else if (!had_err)
      seqid = gt_str_get(arguments->seqid);
  }

  /* set text */
  if (gt_str_length(arguments->text) == 0)
  {
    gt_str_delete(arguments->text);
    arguments->text = gt_str_new_cstr(argv[parsed_args+1]);
  }

  if (!had_err)
  {
    /* set display range */
    had_err = gt_feature_index_get_range_for_seqid(features,
                                                   &sequence_region_range,
                                                   seqid, err);
  }
  if (!had_err)
  {
    qry_range.start = (arguments->range.start == GT_UNDEF_UWORD ?
                         sequence_region_range.start :
                         arguments->range.start);
    qry_range.end   = (arguments->range.end == GT_UNDEF_UWORD ?
                         sequence_region_range.end :
                         arguments->range.end);

    /* set output format */
    if (strcmp(gt_str_get(arguments->format), "pdf") == 0)
    {
      surf = cairo_pdf_surface_create(outfile,
                                      mm_to_pt(arguments->pwidth),
                                      mm_to_pt(arguments->pheight));
    }
    else if (strcmp(gt_str_get(arguments->format), "ps") == 0)
    {
      surf =  cairo_ps_surface_create(outfile,
                                      mm_to_pt(arguments->pwidth),
                                      mm_to_pt(arguments->pheight));
    }
    gt_log_log("created page with %.2f:%.2f dimensions\n",
                                                  mm_to_pt(arguments->pwidth),
                                                  mm_to_pt(arguments->pheight));

    offsetpos = TEXT_SPACER + arguments->theight + TEXT_SPACER;
    usable_height = mm_to_pt(arguments->pheight)
                              - arguments->theight
                              - arguments->theight
                              - 4*TEXT_SPACER;

    if (gt_str_length(arguments->seqfile) > 0) {
      bioseq = gt_bioseq_new(gt_str_get(arguments->seqfile), err);
    }

    cr = cairo_create(surf);
    cairo_set_font_size(cr, 8);
    twc = gt_text_width_calculator_cairo_new(cr, sty, err);
    for (start = qry_range.start; start <= qry_range.end;
         start += arguments->width)
    {
      GtRange single_range;
      GtCustomTrack *ct = NULL;
      const char *seq;
      single_range.start = start;
      single_range.end = start + arguments->width;

      if (had_err)
        break;

      d = gt_diagram_new(features, seqid, &single_range, sty, err);
      if (!d) {
        had_err = -1;
        break;
      }
      if (bioseq) {
        seq = gt_bioseq_get_sequence(bioseq, 0);
        ct = gt_custom_track_gc_content_new(seq,
                                      gt_bioseq_get_sequence_length(bioseq, 0),
                                      800, 70, 0.4, true);
        gt_diagram_add_custom_track(d, ct);
      }

      l = gt_layout_new_with_twc(d, mm_to_pt(arguments->width), sty, twc, err);
      had_err = gt_layout_get_height(l, &height, err);
      if (!had_err) {
        if (gt_double_smaller_double(usable_height - 10 - 2*TEXT_SPACER
              - arguments->theight, offsetpos + height))
        {
            draw_header(cr, gt_str_get(arguments->text), argv[parsed_args+1],
                        seqid, num_pages, mm_to_pt(arguments->pwidth),
                        mm_to_pt(arguments->pheight),
                        arguments->theight);
          cairo_show_page(cr);
          offsetpos = TEXT_SPACER + arguments->theight + TEXT_SPACER;
          num_pages++;
        }
        canvas = gt_canvas_cairo_context_new(sty,
                                             cr,
                                             offsetpos,
                                             mm_to_pt(arguments->pwidth),
                                             height,
                                             NULL,
                                             err);
        if (!canvas)
          had_err = -1;
        offsetpos += height;
        if (!had_err)
          had_err = gt_layout_sketch(l, canvas, err);
      }
      gt_canvas_delete(canvas);
      gt_layout_delete(l);
      gt_diagram_delete(d);
      if (ct)
        gt_custom_track_delete(ct);
    }
    draw_header(cr, gt_str_get(arguments->text), argv[parsed_args+1], seqid,
                num_pages, mm_to_pt(arguments->pwidth),
                mm_to_pt(arguments->pheight),
                arguments->theight);
    cairo_show_page(cr);
    num_pages++;
    gt_log_log("finished, should be "GT_WU" pages\n", num_pages);
    gt_text_width_calculator_delete(twc);
    cairo_destroy(cr);
    cairo_surface_flush(surf);
    cairo_surface_finish(surf);
    cairo_surface_destroy(surf);
    cairo_debug_reset_static_data();
    if (bioseq)
      gt_bioseq_delete(bioseq);
    gt_style_delete(sty);
    gt_free(seqid);
    gt_str_delete(gt_style_file);
    gt_feature_index_delete(features);
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, %rbp
movq %rcx, %r15
movl %edx, %r14d
movq %rsi, %rbx
testq %r8, %r8
je 0x1d31bb
movq %rbp, %rdi
callq 0x89eb7
testb %al, %al
jne 0x1d39a1
callq 0xd9354
movq %rax, %r13
callq 0x17c60
cmpl $0x2a35, %eax           # imm = 0x2A35
jg 0x1d31e5
callq 0x17a20
leaq 0x1927ef(%rip), %rdi    # 0x3659ca
movq %rax, %rsi
xorl %eax, %eax
callq 0xb2cd0
movq %rbp, %rdi
callq 0x1d6418
movq %rax, 0x30(%rsp)
movq 0x40(%r15), %rdi
callq 0xad289
testq %rax, %rax
movq %rbp, 0x18(%rsp)
movq %r13, 0x38(%rsp)
je 0x1d3218
movq 0x40(%r15), %rdi
callq 0xad4d2
movq %rax, %r13
jmp 0x1d326e
callq 0xacb84
movq %rax, %r12
movq (%rbx), %r13
pushq $0x20
popq %rsi
movq %r13, %rdi
callq 0x6c46d
movq %r12, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rbp
movq %rax, %rdx
callq 0xacd9e
movq %r12, %rdi
callq 0xad1fa
movq %rax, %rdi
movq %rbp, %rsi
callq 0x8f124
movq %rax, %r13
movq %r12, %rdi
callq 0xae103
leaq 0x192716(%rip), %rsi    # 0x36597c
movq %r13, %rdi
callq 0xacbfb
movq %r13, 0x88(%rsp)
movq %r13, %rdi
callq 0xad1fa
movq 0x30(%rsp), %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x1d6a41
testl %eax, %eax
je 0x1d32a0
movl %eax, %ebp
movslq %r14d, %r12
movq (%rbx,%r12,8), %r14
xorl %r13d, %r13d
jmp 0x1d330a
movq %rbp, %r13
movq 0x30(%r15), %rdi
callq 0xad1fa
leaq 0xf(%rsp), %rsi
movl %r14d, %r12d
movq 0x38(%rsp), %r14
movq %r14, %rdi
movq %rax, %rdx
movq %rbp, %rcx
callq 0xd8050
movl %eax, %ebp
movslq %r12d, %r12
movq (%rbx,%r12,8), %rax
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
je 0x1d32de
xorl %r13d, %r13d
jmp 0x1d3305
movq %rbx, 0x20(%rsp)
movq 0x8(%rbx,%r12,8), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0xd79fd
testl %eax, %eax
je 0x1d33d5
movl %eax, %ebp
xorl %r13d, %r13d
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x48(%r15), %rdi
callq 0xad289
testq %rax, %rax
jne 0x1d332f
movq 0x48(%r15), %rdi
callq 0xae103
movq 0x8(%rbx,%r12,8), %rdi
callq 0xacbd1
movq %rax, 0x48(%r15)
testl %ebp, %ebp
jne 0x1d3903
leaq 0xa8(%rsp), %rsi
movq 0x38(%rsp), %rdi
movq %r13, %rdx
movq 0x18(%rsp), %rcx
callq 0xd7f1c
movl %eax, %ebp
testl %eax, %eax
jne 0x1d3903
movq %r13, 0x70(%rsp)
movq 0x20(%r15), %r13
movq 0x28(%r15), %rax
movq %rax, 0x68(%rsp)
cmpq $-0x1, %r13
jne 0x1d337b
movq 0xa8(%rsp), %r13
cmpq $-0x1, 0x68(%rsp)
jne 0x1d3390
movq 0xb0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x38(%r15), %rdi
callq 0xad1fa
leaq 0x1ac6b2(%rip), %rsi    # 0x37fa52
movq %rax, %rdi
callq 0x179e0
testl %eax, %eax
je 0x1d3412
movq 0x38(%r15), %rdi
callq 0xad1fa
cmpb $0x70, (%rax)
jne 0x1d33ca
cmpb $0x73, 0x1(%rax)
jne 0x1d33ca
cmpb $0x0, 0x2(%rax)
je 0x1d3960
movq $0x0, 0x28(%rsp)
jmp 0x1d3437
movq 0x30(%r15), %rdi
callq 0xad289
testq %rax, %rax
je 0x1d3917
movq 0x30(%r15), %rdi
movb 0xf(%rsp), %bpl
callq 0xad1fa
movq %rax, %r13
testb %bpl, %bpl
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r14
je 0x1d3942
xorl %ebp, %ebp
jmp 0x1d330a
movsd 0x19232e(%rip), %xmm1   # 0x365748
movsd 0x8(%r15), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movq %r14, %rdi
callq 0x17be0
movq %rax, 0x28(%rsp)
movsd 0x192309(%rip), %xmm2   # 0x365748
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
leaq 0x1925f4(%rip), %rdi    # 0x365a4e
movb $0x2, %al
callq 0x92a82
movsd 0x18(%r15), %xmm0
movsd 0x10(%r15), %xmm1
mulsd 0x1922d3(%rip), %xmm1   # 0x365748
subsd %xmm0, %xmm1
subsd %xmm0, %xmm1
addsd 0x148c3b(%rip), %xmm0   # 0x31c0c0
movapd %xmm0, 0x40(%rsp)
addsd 0x1922bd(%rip), %xmm1   # 0x365750
movsd %xmm1, 0x60(%rsp)
movq 0x50(%r15), %rdi
callq 0xad289
xorl %ebp, %ebp
testq %rax, %rax
je 0x1d34c7
movq 0x50(%r15), %rdi
callq 0xad1fa
movq %rax, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x5a868
movq %rax, %r12
jmp 0x1d34cf
xorl %r12d, %r12d
movq 0x18(%rsp), %rbx
movsd 0x148be9(%rip), %xmm1   # 0x31c0c0
movapd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
movapd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %rdi
callq 0x17230
movq %rax, %r14
movq %rax, %rdi
movsd 0x148bc1(%rip), %xmm0   # 0x31c0c0
callq 0x17a40
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x1d996a
movq %rax, 0x80(%rsp)
movsd 0x60(%rsp), %xmm0
addsd 0x18e8b6(%rip), %xmm0   # 0x361de0
addsd 0x192226(%rip), %xmm0   # 0x365758
movsd %xmm0, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x58(%rsp)
movq %r12, 0x90(%rsp)
movq %r14, 0x20(%rsp)
cmpq 0x68(%rsp), %r13
ja 0x1d3826
movq %r13, 0x98(%rsp)
movq (%r15), %rax
addq %r13, %rax
movq %rax, 0xa0(%rsp)
testl %ebp, %ebp
jne 0x1d3826
movq 0x38(%rsp), %rdi
movq 0x70(%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %rbp
movq %rbp, %r8
callq 0x1ce0d0
testq %rax, %rax
je 0x1d3821
movq %rax, %rbx
testq %r12, %r12
je 0x1d35fb
movq %r12, %rdi
xorl %esi, %esi
callq 0x5b1f9
movq %rax, %r14
movq %r12, %rdi
xorl %esi, %esi
callq 0x5b2f1
movl $0x320, %edx            # imm = 0x320
movq %r14, %rdi
movq %rax, %rsi
pushq $0x46
popq %rcx
movsd 0x19217e(%rip), %xmm0   # 0x365760
pushq $0x1
popq %r8
callq 0x2d2208
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1ce6b0
jmp 0x1d35fe
xorl %r14d, %r14d
movsd (%r15), %xmm0
movsd 0x1142d5(%rip), %xmm1   # 0x2e78e0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1142da(%rip), %xmm1   # 0x2e78f0
subpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x19211a(%rip), %xmm1   # 0x365748
cvttsd2si %xmm1, %rsi
movq %rbx, %rdi
movq 0x30(%rsp), %rdx
movq 0x80(%rsp), %rcx
movq %rbp, %r8
callq 0x1d41f8
movq %rax, %r12
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
movq %rbp, %rdx
callq 0x1d48e9
testl %eax, %eax
je 0x1d366e
movl %eax, %ebp
movq 0x10(%rsp), %rdi
jmp 0x1d37e5
movq %r13, 0x10(%rsp)
movsd 0x60(%rsp), %xmm0
subsd 0x18(%r15), %xmm0
movsd 0x78(%rsp), %xmm2
unpcklps 0x114254(%rip), %xmm2   # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x11425c(%rip), %xmm2   # 0x2e78f0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
addsd 0x40(%rsp), %xmm1
callq 0x955e2
testb %al, %al
je 0x1d372c
movq 0x48(%r15), %rdi
callq 0xad1fa
movsd 0x8(%r15), %xmm0
movsd 0x192082(%rip), %xmm2   # 0x365748
mulsd %xmm2, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
movsd 0x18(%r15), %xmm2
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movq 0x70(%rsp), %rdx
movq 0x58(%rsp), %rbp
movq %rbp, %rcx
callq 0x1d39d9
movq %r13, %rdi
callq 0x17590
movsd 0x192041(%rip), %xmm2   # 0x365748
movsd 0x18(%r15), %xmm1
movsd 0x1489ab(%rip), %xmm0   # 0x31c0c0
addsd %xmm0, %xmm1
addsd %xmm0, %xmm1
incq %rbp
movq %rbp, 0x58(%rsp)
movq 0x18(%rsp), %rbp
jmp 0x1d3744
movq 0x18(%rsp), %rbp
movsd 0x19200f(%rip), %xmm2   # 0x365748
movq 0x20(%rsp), %r13
movapd 0x40(%rsp), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x1145bc(%rip), %xmm0   # 0x2e7d20
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
movq 0x78(%rsp), %rcx
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movapd %xmm1, %xmm0
xorl %r8d, %r8d
movq %rbp, %r9
callq 0x2d1002
movsd 0x78(%rsp), %xmm0
unpcklps 0x114144(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x11414c(%rip), %xmm0   # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0x40(%rsp), %xmm1
movapd %xmm1, 0x40(%rsp)
testq %rax, %rax
je 0x1d37d9
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x1d4469
movl %eax, %ebp
movq %r13, %rdi
jmp 0x1d37e0
xorl %edi, %edi
pushq $-0x1
popq %rax
movl %eax, %ebp
movq 0x10(%rsp), %r13
movq %rdi, 0x10(%rsp)
callq 0x1cdbef
movq %r12, %rdi
callq 0x1d43fb
movq %rbx, %rdi
callq 0x1ce90d
testq %r14, %r14
je 0x1d380c
movq %r14, %rdi
callq 0x2d1825
addq (%r15), %r13
movq 0x90(%rsp), %r12
movq 0x20(%rsp), %r14
jmp 0x1d3557
pushq $-0x1
popq %rax
movl %eax, %ebp
movq 0x48(%r15), %rdi
callq 0xad1fa
movsd 0x8(%r15), %xmm0
movsd 0x191f0b(%rip), %xmm1   # 0x365748
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movsd 0x18(%r15), %xmm2
movq %r14, %rdi
movq %rax, %rsi
movq 0x70(%rsp), %r15
movq %r15, %rdx
movq 0x58(%rsp), %rbx
movq %rbx, %rcx
callq 0x1d39d9
movq %r14, %rdi
callq 0x17590
incq %rbx
leaq 0x1921fc(%rip), %rdi    # 0x365a76
movq %rbx, %rsi
xorl %eax, %eax
callq 0x92a82
movq 0x80(%rsp), %rdi
callq 0x1d95e3
movq %r14, %rdi
callq 0x17a30
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x17cf0
movq %rbx, %rdi
callq 0x17280
movq %rbx, %rdi
callq 0x178d0
callq 0x17eb0
testq %r12, %r12
movq 0x38(%rsp), %rbx
movq 0x88(%rsp), %r14
je 0x1d38d5
movq %r12, %rdi
callq 0x5af87
movq 0x30(%rsp), %rdi
callq 0x1d84ed
leaq 0x191e92(%rip), %rsi    # 0x365778
movq %r15, %rdi
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x936f9
movq %r14, %rdi
callq 0xae103
movq %rbx, %rdi
callq 0xd7777
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %r13
movq %r13, %rsi
callq 0xd7d67
testq %rax, %rax
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r14
je 0x1d3985
xorl %ebp, %ebp
movq %rax, %r13
jmp 0x1d330a
leaq 0x191d5a(%rip), %rsi    # 0x3656a3
movq 0x18(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %rbp
jmp 0x1d329b
movsd 0x191de0(%rip), %xmm1   # 0x365748
movsd 0x8(%r15), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movq %r14, %rdi
callq 0x17180
jmp 0x1d3432
leaq 0x191ce8(%rip), %rsi    # 0x365674
movq %r13, %rdi
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %rbp
jmp 0x1d330a
movq 0x2645c0(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x111661(%rip), %rsi    # 0x2e5013
leaq 0x111806(%rip), %rdx    # 0x2e51bf
leaq 0x191ff4(%rip), %rcx    # 0x3659b4
leaq 0x191db1(%rip), %r8     # 0x365778
movl $0xf5, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390