// File: /workspace/github_c_makefile_star2_O3/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, %r13
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r12
testq %r8, %r8
je 0x21c9c1
movq %r13, %rdi
callq 0xfcc32
testb %al, %al
jne 0x21d172
callq 0x141cb1
movq %rax, %r14
callq 0x17ce0
cmpl $0x2a35, %eax           # imm = 0x2A35
jg 0x21c9eb
callq 0x17a80
leaq 0x1a8bd9(%rip), %rdi    # 0x3c55ba
movq %rax, %rsi
xorl %eax, %eax
callq 0x11f68c
movq %r13, %rdi
callq 0x21f2c0
movq %rax, 0x20(%rsp)
movq 0x40(%r15), %rdi
callq 0x11b0ca
testq %rax, %rax
movq %r14, 0x28(%rsp)
je 0x21ca19
movq 0x40(%r15), %rdi
callq 0x11b1f3
movq %rax, %rbx
jmp 0x21ca72
callq 0x11ac6c
movq %rax, %rbx
movq (%r12), %r14
movq %r14, %rdi
movl $0x20, %esi
callq 0xe438c
movq %rbx, %rdi
movq %r14, %rsi
movq 0x28(%rsp), %r14
movq %rax, %rdx
callq 0x11ae1b
movq %rbx, %rdi
callq 0x11b0a1
movq %rax, %rdi
movq %r13, %rsi
callq 0x100758
movq %rbx, %rdi
movq %rax, %rbx
callq 0x11bdbf
leaq 0x1a8b02(%rip), %rsi    # 0x3c556c
movq %rbx, %rdi
callq 0x11acf3
movq %rbx, 0x90(%rsp)
movq %rbx, %rdi
callq 0x11b0a1
movq 0x20(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x21f6bf
testl %eax, %eax
je 0x21caa1
movl %eax, %ebx
movslq %ebp, %r14
movq (%r12,%r14,8), %rbp
jmp 0x21cae2
movq 0x30(%r15), %rdi
callq 0x11b0a1
leaq 0xf(%rsp), %rsi
movq %r14, %rdi
movq %rax, %rdx
movq %r13, %rcx
callq 0x140d0e
movq %r14, %rdi
movslq %ebp, %r14
movq (%r12,%r14,8), %rbp
testl %eax, %eax
jne 0x21cae0
movq 0x8(%r12,%r14,8), %rsi
movq %r13, %rdx
callq 0x1408c8
testl %eax, %eax
je 0x21cbb6
movl %eax, %ebx
movq $0x0, 0x10(%rsp)
movq 0x48(%r15), %rdi
callq 0x11b0ca
testq %rax, %rax
jne 0x21cb10
movq 0x48(%r15), %rdi
callq 0x11bdbf
movq 0x8(%r12,%r14,8), %rdi
callq 0x11acc9
movq %rax, 0x48(%r15)
testl %ebx, %ebx
jne 0x21d0d9
leaq 0xa8(%rsp), %rsi
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq %r13, %rcx
callq 0x140c40
movl %eax, %ebx
testl %eax, %eax
jne 0x21d0d9
movq 0x20(%r15), %r12
movq 0x28(%r15), %rax
movq %rax, 0x38(%rsp)
cmpq $-0x1, %r12
jne 0x21cb57
movq 0xa8(%rsp), %r12
cmpq $-0x1, 0x38(%rsp)
movq 0x28(%rsp), %r14
jne 0x21cb71
movq 0xb0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%r15), %rdi
callq 0x11b0a1
leaq 0x1c2b27(%rip), %rsi    # 0x3df6a8
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x21cbe7
movq 0x38(%r15), %rdi
callq 0x11b0a1
cmpb $0x70, (%rax)
jne 0x21cbab
cmpb $0x73, 0x1(%rax)
jne 0x21cbab
cmpb $0x0, 0x2(%rax)
je 0x21d129
movq $0x0, 0x18(%rsp)
jmp 0x21cc0c
movq 0x30(%r15), %rdi
callq 0x11b0ca
testq %rax, %rax
je 0x21d0ed
movq 0x30(%r15), %rdi
movb 0xf(%rsp), %bl
callq 0x11b0a1
testb %bl, %bl
je 0x21d10b
movq %rax, 0x10(%rsp)
jmp 0x21d104
movsd 0x1a8749(%rip), %xmm1   # 0x3c5338
movsd 0x8(%r15), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movq %rbp, %rdi
callq 0x17c50
movq %rax, 0x18(%rsp)
movsd 0x1a8724(%rip), %xmm2   # 0x3c5338
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
leaq 0x1a8a0f(%rip), %rdi    # 0x3c563e
movb $0x2, %al
callq 0x103d72
movsd 0x18(%r15), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x10(%r15), %xmm0
mulsd 0x1a86e9(%rip), %xmm0   # 0x3c5338
movsd %xmm0, 0x58(%rsp)
movq 0x50(%r15), %rdi
callq 0x11b0ca
xorl %ebx, %ebx
testq %rax, %rax
je 0x21cc80
movq 0x50(%r15), %rdi
callq 0x11b0a1
movq %rax, %rdi
movq %r13, %rsi
callq 0xd4388
movq %rax, 0x68(%rsp)
jmp 0x21cc89
movq $0x0, 0x68(%rsp)
movq 0x18(%rsp), %rdi
callq 0x17250
movq %rax, %rbp
movsd 0x15f082(%rip), %xmm0   # 0x37bd20
movq %rax, %rdi
callq 0x17aa0
movq %rbp, 0x60(%rsp)
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x221cab
movq %rax, 0x80(%rsp)
cmpq 0x38(%rsp), %r12
jbe 0x21ccd8
movq $0x0, 0x30(%rsp)
jmp 0x21cffd
movq %r13, 0x70(%rsp)
movsd 0x15f03b(%rip), %xmm0   # 0x37bd20
movsd 0x58(%rsp), %xmm1
movapd 0x40(%rsp), %xmm2
subsd %xmm2, %xmm1
subsd %xmm2, %xmm1
addsd %xmm0, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x40(%rsp)
addsd 0x1a8631(%rip), %xmm1   # 0x3c5340
addsd 0x1a4cb9(%rip), %xmm1   # 0x3c19d0
addsd 0x1a8629(%rip), %xmm1   # 0x3c5348
movsd %xmm1, 0x58(%rsp)
movq (%r15), %rax
xorl %ebx, %ebx
movq $0x0, 0x30(%rsp)
xorl %r13d, %r13d
movq %r12, 0x98(%rsp)
addq %r12, %rax
movq %rax, 0xa0(%rsp)
testl %ebx, %ebx
jne 0x21cffd
movq %r14, %rdi
movq 0x10(%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x70(%rsp), %r8
callq 0x218930
testq %rax, %rax
je 0x21cff8
movq %rax, %rbp
movq 0x68(%rsp), %r14
testq %r14, %r14
je 0x21cdd5
movq %r14, %rdi
xorl %esi, %esi
callq 0xd4b0d
movq %rax, %rbx
movq %r14, %rdi
xorl %esi, %esi
callq 0xd4ba3
movl $0x320, %edx            # imm = 0x320
movl $0x46, %ecx
movq %rbx, %rdi
movq %rax, %rsi
movsd 0x1a859b(%rip), %xmm0   # 0x3c5350
movl $0x1, %r8d
callq 0x330423
movq %rbp, %rdi
movq %rax, 0x88(%rsp)
movq %rax, %rsi
callq 0x218d72
jmp 0x21cde1
movq $0x0, 0x88(%rsp)
movsd (%r15), %xmm0
movsd 0x12aaf2(%rip), %xmm1   # 0x3478e0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x12aaf7(%rip), %xmm1   # 0x3478f0
subpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1a8527(%rip), %xmm1   # 0x3c5338
cvttsd2si %xmm1, %rsi
movq %rbp, %rdi
movq 0x20(%rsp), %rdx
movq 0x80(%rsp), %rcx
movq 0x70(%rsp), %rbx
movq %rbx, %r8
callq 0x21d7de
movq %rax, %r14
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
movq %rbx, %rdx
callq 0x21dbe1
testl %eax, %eax
jne 0x21cfa8
movsd 0x58(%rsp), %xmm0
subsd 0x18(%r15), %xmm0
movsd 0x78(%rsp), %xmm2
unpcklps 0x12aa79(%rip), %xmm2   # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x12aa81(%rip), %xmm2   # 0x3478f0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
addsd 0x40(%rsp), %xmm1
callq 0x105c97
testb %al, %al
je 0x21cf02
movq 0x48(%r15), %rdi
callq 0x11b0a1
movsd 0x8(%r15), %xmm0
movsd 0x1a8497(%rip), %xmm2   # 0x3c5338
mulsd %xmm2, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
movsd 0x18(%r15), %xmm2
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
movq 0x10(%rsp), %rdx
movq 0x30(%rsp), %r13
movq %r13, %rcx
callq 0x21d177
movq %rbx, %rdi
callq 0x175c0
movsd 0x1a8456(%rip), %xmm2   # 0x3c5338
movsd 0x18(%r15), %xmm1
movsd 0x15ee30(%rip), %xmm0   # 0x37bd20
addsd %xmm0, %xmm1
addsd %xmm0, %xmm1
incq %r13
movq %r13, 0x30(%rsp)
jmp 0x21cf15
movsd 0x1a842e(%rip), %xmm2   # 0x3c5338
movq 0x60(%rsp), %rbx
movapd 0x40(%rsp), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x8(%r15), %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x12adeb(%rip), %xmm0   # 0x347d20
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
movq 0x78(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movapd %xmm1, %xmm0
xorl %r8d, %r8d
movq 0x70(%rsp), %rbx
movq %rbx, %r9
callq 0x32f450
movsd 0x78(%rsp), %xmm0
unpcklps 0x12a96e(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x12a976(%rip), %xmm0   # 0x3478f0
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 0x21cfef
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
movq %rax, %r13
callq 0x21d9a5
movl %eax, %ebx
movq %r13, %rdi
movq %rdi, %r13
callq 0x21871c
movq %r14, %rdi
callq 0x21d937
movq %rbp, %rdi
callq 0x218f72
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x21cfd7
callq 0x32fb5d
movq (%r15), %rax
addq %rax, %r12
cmpq 0x38(%rsp), %r12
movq 0x28(%rsp), %r14
jbe 0x21cd36
jmp 0x21cffd
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %edi, %edi
jmp 0x21cfad
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x48(%r15), %rdi
callq 0x11b0a1
movsd 0x8(%r15), %xmm0
movsd 0x1a8324(%rip), %xmm1   # 0x3c5338
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movsd 0x18(%r15), %xmm2
movq 0x60(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
movq 0x30(%rsp), %r13
movq %r13, %rcx
callq 0x21d177
movq %r12, %rdi
callq 0x175c0
incq %r13
leaq 0x1a8610(%rip), %rdi    # 0x3c5666
movq %r13, %rsi
xorl %eax, %eax
callq 0x103d72
movq 0x80(%rsp), %rdi
callq 0x221a56
movq %r12, %rdi
callq 0x17a90
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x17d70
movq %r12, %rdi
callq 0x172a0
movq %r12, %rdi
callq 0x17920
callq 0x17f40
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x21d0a6
callq 0xd491d
movq 0x20(%rsp), %rdi
callq 0x220a00
leaq 0x1a82b1(%rip), %rsi    # 0x3c5368
movq %r15, %rdi
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x1045eb
movq 0x90(%rsp), %rdi
callq 0x11bdbf
movq %r14, %rdi
callq 0x14070e
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x140b4d
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x21d14e
xorl %ebx, %ebx
jmp 0x21caeb
leaq 0x1a8181(%rip), %rsi    # 0x3c5293
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x21cae2
movsd 0x1a8207(%rip), %xmm1   # 0x3c5338
movsd 0x8(%r15), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x10(%r15), %xmm1
movq %rbp, %rdi
callq 0x17190
jmp 0x21cc07
leaq 0x1a810f(%rip), %rsi    # 0x3c5264
movq $0x0, 0x10(%rsp)
movq %r13, %rdi
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x21caeb
callq 0x845bf