// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movq %r8, %r13
movq %rcx, %r15
movl %edx, %r14d
movq %rsi, %rbx
testq %r8, %r8
je 0x226656
movq %r13, %rdi
callq 0x101a9a
testb %al, %al
jne 0x226df3
callq 0x148ed1
movq %rax, 0x10(%rsp)
callq 0x17ce0
cmpl $0x2a35, %eax           # imm = 0x2A35
jg 0x226682
callq 0x17a80
leaq 0x1a866a(%rip), %rdi    # 0x3cece2
movq %rax, %rsi
xorl %eax, %eax
callq 0x125448
movq %r13, %rdi
callq 0x228fe4
movq %rax, 0x18(%rsp)
movq 0x40(%r15), %rdi
callq 0x120d4c
testq %rax, %rax
je 0x2266ab
movq 0x40(%r15), %rdi
callq 0x120e79
movq %rax, %rbp
jmp 0x2266fe
callq 0x1208f8
movq %rax, %r12
movq (%rbx), %rbp
movq %rbp, %rdi
movl $0x20, %esi
callq 0xe885c
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x120a9d
movq %r12, %rdi
callq 0x120d23
movq %rax, %rdi
movq %r13, %rsi
callq 0x105688
movq %rax, %rbp
movq %r12, %rdi
callq 0x121b03
leaq 0x1a859e(%rip), %rsi    # 0x3cec94
movq %rbp, %rdi
callq 0x12097f
movq %rbp, 0x80(%rsp)
movq %rbp, %rdi
callq 0x120d23
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x2293f6
movl %eax, %ebp
testl %eax, %eax
jne 0x226744
movq 0x30(%r15), %rdi
callq 0x120d23
leaq 0x7(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq %rax, %rdx
movq %r13, %rcx
callq 0x147f52
movl %eax, %ebp
movslq %r14d, %r12
movq (%rbx,%r12,8), %r14
testl %ebp, %ebp
jne 0x22676b
movq 0x8(%rbx,%r12,8), %rsi
movq 0x10(%rsp), %rdi
movq %r13, %rdx
callq 0x147b0c
testl %eax, %eax
je 0x22682d
movl %eax, %ebp
movq $0x0, 0x8(%rsp)
movq 0x48(%r15), %rdi
callq 0x120d4c
testq %rax, %rax
jne 0x226799
movq 0x48(%r15), %rdi
callq 0x121b03
movq 0x8(%rbx,%r12,8), %rdi
callq 0x120955
movq %rax, 0x48(%r15)
testl %ebp, %ebp
jne 0x2267b9
leaq 0x98(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rdx
movq %r13, %rcx
callq 0x147e84
movl %eax, %ebp
testl %ebp, %ebp
jne 0x226d7f
movq 0x20(%r15), %r12
movq 0x28(%r15), %rax
cmpq $-0x1, %r12
jne 0x2267d7
movq 0x98(%rsp), %r12
cmpq $-0x1, %rax
jne 0x2267e5
movq 0xa0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x38(%r15), %rdi
callq 0x120d23
leaq 0x1c258f(%rip), %rsi    # 0x3e8d89
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x226860
movq 0x38(%r15), %rdi
callq 0x120d23
leaq 0x1c258d(%rip), %rsi    # 0x3e8da3
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x226882
movq $0x0, 0x38(%rsp)
jmp 0x2268a7
movq 0x30(%r15), %rdi
callq 0x120d4c
testq %rax, %rax
je 0x226d93
movq 0x30(%r15), %rdi
movb 0x7(%rsp), %bpl
callq 0x120d23
testb %bpl, %bpl
je 0x226db1
movq %rax, 0x8(%rsp)
jmp 0x226daa
movsd 0x1a81f8(%rip), %xmm1   # 0x3cea60
movsd 0x8(%r15), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movq %r14, %rdi
callq 0x17c50
jmp 0x2268a2
movsd 0x1a81d6(%rip), %xmm1   # 0x3cea60
movsd 0x8(%r15), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movq %r14, %rdi
callq 0x17190
movq %rax, 0x38(%rsp)
movsd 0x1a81b1(%rip), %xmm2   # 0x3cea60
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
leaq 0x1a849c(%rip), %rdi    # 0x3ced66
movb $0x2, %al
callq 0x108e02
movsd 0x18(%r15), %xmm0
movaps %xmm0, 0x20(%rsp)
movsd 0x10(%r15), %xmm0
mulsd 0x1a8176(%rip), %xmm0   # 0x3cea60
movsd %xmm0, 0x48(%rsp)
movq 0x50(%r15), %rdi
callq 0x120d4c
xorl %ebp, %ebp
testq %rax, %rax
movq 0x8(%rsp), %r14
je 0x226920
movq 0x50(%r15), %rdi
callq 0x120d23
movq %rax, %rdi
movq %r13, %rsi
callq 0xd69c0
movq %rax, 0x58(%rsp)
jmp 0x226929
movq $0x0, 0x58(%rsp)
movq 0x38(%rsp), %rdi
callq 0x17250
movq %rax, %rbx
movsd 0x15e752(%rip), %xmm0   # 0x385090
movq %rax, %rdi
callq 0x17aa0
movq %rbx, 0x50(%rsp)
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
callq 0x22bb1f
movq %rax, 0x78(%rsp)
movq 0x40(%rsp), %rcx
cmpq %rcx, %r12
jbe 0x226978
movq $0x0, 0x30(%rsp)
jmp 0x226ca9
movsd 0x15e710(%rip), %xmm0   # 0x385090
movsd 0x48(%rsp), %xmm1
movapd 0x20(%rsp), %xmm2
subsd %xmm2, %xmm1
subsd %xmm2, %xmm1
addsd %xmm0, %xmm2
addsd 0x1a80c8(%rip), %xmm1   # 0x3cea68
addsd 0x1a4750(%rip), %xmm1   # 0x3cb0f8
addsd %xmm0, %xmm2
movapd %xmm2, 0x20(%rsp)
addsd 0x1a80b6(%rip), %xmm1   # 0x3cea70
movsd %xmm1, 0x48(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x30(%rsp)
movq $0x0, 0x68(%rsp)
movq %r12, 0x88(%rsp)
movq (%r15), %rax
addq %r12, %rax
movq %rax, 0x90(%rsp)
testl %ebp, %ebp
je 0x2269f5
xorl %ebx, %ebx
jmp 0x226c99
movq 0x10(%rsp), %rdi
movq %r14, %rsi
leaq 0x88(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %r13, %r8
callq 0x222670
testq %rax, %rax
je 0x226a70
movq %rax, %r14
movq 0x58(%rsp), %rbp
testq %rbp, %rbp
je 0x226a7c
movq %rbp, %rdi
xorl %esi, %esi
callq 0xd7118
movq %rax, %rbx
movq %rbp, %rdi
xorl %esi, %esi
callq 0xd71ae
movl $0x320, %edx            # imm = 0x320
movl $0x46, %ecx
movq %rbx, %rdi
movq %rax, %rsi
movsd 0x1a8025(%rip), %xmm0   # 0x3cea78
movl $0x1, %r8d
callq 0x33b196
movq %r14, %rdi
movq %rax, 0x70(%rsp)
movq %rax, %rsi
callq 0x222ab4
jmp 0x226a85
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %ebx, %ebx
jmp 0x226c8f
movq $0x0, 0x70(%rsp)
movsd (%r15), %xmm0
movsd 0x129e4e(%rip), %xmm1   # 0x3508e0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x129e53(%rip), %xmm1   # 0x3508f0
subpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1a7fab(%rip), %xmm1   # 0x3cea60
cvttsd2si %xmm1, %rsi
movq %r14, %rdi
movq 0x18(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq %r13, %r8
callq 0x22743d
movq %rax, %rbx
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0x227840
testl %eax, %eax
je 0x226af2
movl %eax, %ebp
movq 0x68(%rsp), %rsi
jmp 0x226c61
movsd 0x48(%rsp), %xmm0
subsd 0x18(%r15), %xmm0
movsd 0x60(%rsp), %xmm2
unpcklps 0x129dd5(%rip), %xmm2   # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x129ddd(%rip), %xmm2   # 0x3508f0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
addsd 0x20(%rsp), %xmm1
callq 0x10ad54
testb %al, %al
je 0x226bb7
movq 0x48(%r15), %rdi
callq 0x120d23
movsd 0x8(%r15), %xmm0
movsd 0x1a7f17(%rip), %xmm2   # 0x3cea60
mulsd %xmm2, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
movsd 0x18(%r15), %xmm2
movq %rbx, 0x20(%rsp)
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
movq 0x8(%rsp), %rdx
movq 0x30(%rsp), %rbp
movq %rbp, %rcx
callq 0x226df8
movq %rbx, %rdi
callq 0x175c0
movsd 0x1a7ed1(%rip), %xmm2   # 0x3cea60
movq %rbx, %rsi
movq 0x20(%rsp), %rbx
movsd 0x18(%r15), %xmm1
movsd 0x15e4eb(%rip), %xmm0   # 0x385090
addsd %xmm0, %xmm1
addsd %xmm0, %xmm1
incq %rbp
movq %rbp, 0x30(%rsp)
jmp 0x226bca
movsd 0x1a7ea1(%rip), %xmm2   # 0x3cea60
movq 0x50(%rsp), %rsi
movapd 0x20(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x12a136(%rip), %xmm0   # 0x350d20
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
movq 0x60(%rsp), %rcx
movq 0x18(%rsp), %rdi
movapd %xmm1, %xmm0
xorl %r8d, %r8d
movq %r13, %r9
callq 0x33a1d0
movq %rax, %rsi
movsd 0x60(%rsp), %xmm0
unpcklps 0x129cbe(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x129cc6(%rip), %xmm0   # 0x3508f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0x20(%rsp), %xmm1
movapd %xmm1, 0x20(%rsp)
testq %rax, %rax
je 0x226c5c
movq %rbx, %rdi
movq %r13, %rdx
movq %rsi, %rbp
callq 0x227604
movq %rbp, %rsi
movl %eax, %ebp
jmp 0x226c61
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rsi, 0x68(%rsp)
movq %rsi, %rdi
callq 0x222462
movq %rbx, %rdi
callq 0x227596
movq %r14, %rdi
callq 0x222cb7
movb $0x1, %bl
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x226c8f
callq 0x33a8dd
movq 0x8(%rsp), %r14
movq 0x40(%rsp), %rcx
testb %bl, %bl
je 0x226ca9
addq (%r15), %r12
cmpq %rcx, %r12
jbe 0x2269d4
movq 0x48(%r15), %rdi
callq 0x120d23
movsd 0x8(%r15), %xmm0
movsd 0x1a7da0(%rip), %xmm1   # 0x3cea60
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movsd 0x18(%r15), %xmm2
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
movq 0x30(%rsp), %r15
movq %r15, %rcx
callq 0x226df8
movq %rbx, %rdi
callq 0x175c0
incq %r15
leaq 0x1a8091(%rip), %rdi    # 0x3ced8e
movq %r15, %rsi
xorl %eax, %eax
callq 0x108e02
movq 0x78(%rsp), %rdi
callq 0x22b8ca
movq %rbx, %rdi
callq 0x17a90
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x17d70
movq %rbx, %rdi
callq 0x172a0
movq %rbx, %rdi
callq 0x17920
callq 0x17f40
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x226d4a
callq 0xd6f28
movq 0x18(%rsp), %rdi
callq 0x22a740
leaq 0x1a7d35(%rip), %rsi    # 0x3cea90
movq %r14, %rdi
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x109670
movq 0x80(%rsp), %rdi
callq 0x121b03
movq 0x10(%rsp), %rdi
callq 0x147952
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x147d91
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x226dcf
xorl %ebp, %ebp
jmp 0x226774
leaq 0x1a7c03(%rip), %rsi    # 0x3ce9bb
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x22676b
leaq 0x1a7bb6(%rip), %rsi    # 0x3ce98c
movq $0x0, 0x8(%rsp)
movq %r13, %rdi
xorl %eax, %eax
callq 0x1019cf
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x226774
callq 0x866ac