// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/annotationsketch/gt_sketch.c
// Function: gt_sketch_runner
static int gt_sketch_runner(int argc, const char **argv, int parsed_args,
                              void *tool_arguments, GT_UNUSED GtError *err)
{
  GtSketchArguments *arguments = tool_arguments;
  GtNodeStream *in_stream = NULL,
               *add_introns_stream = NULL,
               *gff3_out_stream = NULL,
               *feature_stream = NULL,
               *sort_stream = NULL,
               *last_stream;
  GtFeatureIndex *features = NULL;
  const char *file;
  char *seqid = NULL;
  GtRange qry_range, sequence_region_range;
  GtArray *results = NULL;
  GtStyle *sty = NULL;
  GtStr *prog, *defaultstylefile = NULL;
  GtDiagram *d = NULL;
  GtLayout *l = NULL;
  GtImageInfo* ii = NULL;
  GtCanvas *canvas = NULL;
  GtUword height;
  bool has_seqid;
  int had_err = 0;
  gt_error_check(err);
  gt_assert(arguments);

  prog = gt_str_new();
  gt_str_append_cstr_nt(prog, argv[0],
                        gt_cstr_length_up_to_char(argv[0], ' '));
  defaultstylefile = gt_get_gtdata_path(gt_str_get(prog), err);
  gt_str_delete(prog);
  if (!defaultstylefile)
    had_err = -1;
  if (!had_err) {
    gt_str_append_cstr(defaultstylefile, "/sketch/default.style");
  }

  file = argv[parsed_args];
  if (!had_err) {
    /* create feature index */
    features = gt_feature_index_memory_new();
    parsed_args++;

    /* create an input stream */
    if (strcmp(gt_str_get(arguments->input), "gff") == 0)
    {
      in_stream = gt_gff3_in_stream_new_unsorted(argc - parsed_args,
                                                 argv + parsed_args);
      if (arguments->verbose)
        gt_gff3_in_stream_show_progress_bar((GtGFF3InStream*) in_stream);
    } else if (strcmp(gt_str_get(arguments->input), "bed") == 0)
    {
      if (argc - parsed_args == 0)
        in_stream = gt_bed_in_stream_new(NULL);
      else
        in_stream = gt_bed_in_stream_new(argv[parsed_args]);
    } else if (strcmp(gt_str_get(arguments->input), "gtf") == 0)
    {
      if (argc - parsed_args == 0)
        in_stream = gt_gtf_in_stream_new(NULL);
      else
        in_stream = gt_gtf_in_stream_new(argv[parsed_args]);
    }
    last_stream = in_stream;

    /* create add introns stream if -addintrons was used */
    if (arguments->addintrons) {
      sort_stream = gt_sort_stream_new(last_stream);
      add_introns_stream = gt_add_introns_stream_new(sort_stream);
      last_stream = add_introns_stream;
    }

    /* create gff3 output stream if -pipe was used */
    if (arguments->pipe) {
      gff3_out_stream = gt_gff3_out_stream_new(last_stream, NULL);
      last_stream = gff3_out_stream;
    }

    /* create feature stream */
    feature_stream = gt_feature_stream_new(last_stream, features);

    /* pull the features through the stream and free them afterwards */
    had_err = gt_node_stream_pull(feature_stream, err);

    gt_node_stream_delete(feature_stream);
    gt_node_stream_delete(gff3_out_stream);
    gt_node_stream_delete(sort_stream);
    gt_node_stream_delete(add_introns_stream);
    gt_node_stream_delete(in_stream);
  }

  if (!had_err) {
    had_err = gt_feature_index_has_seqid(features,
                                         &has_seqid,
                                         gt_str_get(arguments->seqid),
                                         err);
  }

  /* if seqid is empty, take first one added to index */
  if (!had_err && strcmp(gt_str_get(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_cstr_dup(gt_str_get(arguments->seqid));

  results = gt_array_new(sizeof (GtGenomeNode*));
  if (!had_err) {
    had_err = gt_feature_index_get_range_for_seqid(features,
                                                   &sequence_region_range,
                                                   seqid,
                                                   err);
  }
  if (!had_err) {
    qry_range.start = (arguments->start == GT_UNDEF_UWORD ?
                         sequence_region_range.start :
                         arguments->start);
    qry_range.end   = (arguments->end == GT_UNDEF_UWORD ?
                         sequence_region_range.end :
                         arguments->end);
  }

  if (!had_err) {
    if (arguments->verbose)
      fprintf(stderr, "# of results: "GT_WU"\n", gt_array_size(results));

    /* find and load style file */
    if (!(sty = gt_style_new(err)))
      had_err = -1;
    if (gt_str_length(arguments->stylefile) == 0) {
      gt_str_append_str(arguments->stylefile, defaultstylefile);
    } else {
      if (!had_err && gt_file_exists(gt_str_get(arguments->stylefile))) {
        if (arguments->unsafe)
          gt_style_unsafe_mode(sty);
      }
      else
      {
        had_err = -1;
        gt_error_set(err, "style file '%s' does not exist!",
                          gt_str_get(arguments->stylefile));
      }
    }
    if (!had_err)
      had_err = gt_style_load_file(sty, gt_str_get(arguments->stylefile), err);
  }

  if (!had_err) {
    /* create and write image file */
    if (!(d = gt_diagram_new(features, seqid, &qry_range, sty, err)))
      had_err = -1;
    if (!had_err && arguments->flattenfiles)
      gt_diagram_set_track_selector_func(d, flattened_file_track_selector,
                                         NULL);
    if (had_err || !(l = gt_layout_new(d, arguments->width, sty, err)))
      had_err = -1;
    if (!had_err)
      had_err = gt_layout_get_height(l, &height, err);
    if (!had_err) {
      ii = gt_image_info_new();

      if (strcmp(gt_str_get(arguments->format),"pdf")==0) {
        canvas = gt_canvas_cairo_file_new(sty, GT_GRAPHICS_PDF,
                                          arguments->width,
                                          height, ii, err);
      }
      else if (strcmp(gt_str_get(arguments->format),"ps")==0) {
        canvas = gt_canvas_cairo_file_new(sty, GT_GRAPHICS_PS,
                                          arguments->width,
                                          height, ii, err);
      }
      else if (strcmp(gt_str_get(arguments->format),"svg")==0) {
        canvas = gt_canvas_cairo_file_new(sty, GT_GRAPHICS_SVG,
                                          arguments->width,
                                          height, ii, err);
      }
      else {
        canvas = gt_canvas_cairo_file_new(sty, GT_GRAPHICS_PNG,
                                          arguments->width,
                                          height, ii, err);
      }
      if (!canvas)
        had_err = -1;
      if (!had_err) {
        had_err = gt_layout_sketch(l, canvas, err);
      }
      if (!had_err) {
        if (arguments->showrecmaps) {
          GtUword i;
          const GtRecMap *rm;
          for (i = 0; i < gt_image_info_num_of_rec_maps(ii) ;i++) {
            char buf[BUFSIZ];
            rm = gt_image_info_get_rec_map(ii, i);
            (void) gt_rec_map_format_html_imagemap_coords(rm, buf, BUFSIZ);
            printf("%s, %s\n",
                   buf,
                   gt_feature_node_get_type(gt_rec_map_get_genome_feature(rm)));
          }
        }
        if (arguments->use_streams) {
          GtFile *outfile;
          GtStr *str = gt_str_new();
          gt_canvas_cairo_file_to_stream((GtCanvasCairoFile*) canvas, str);
          outfile = gt_file_open(GT_FILE_MODE_UNCOMPRESSED, file, "w+", err);
          if (outfile) {
            gt_file_xwrite(outfile, gt_str_get_mem(str), gt_str_length(str));
            gt_file_delete(outfile);
          } else {
            had_err = -1;
          }
          gt_str_delete(str);
        } else {
          had_err = gt_canvas_cairo_file_to_file((GtCanvasCairoFile*) canvas,
                                                 file,
                                                 err);
        }
      }
    }
  }

  /* free */
  gt_free(seqid);
  gt_canvas_delete(canvas);
  gt_layout_delete(l);
  gt_image_info_delete(ii);
  gt_style_delete(sty);
  gt_diagram_delete(d);
  gt_array_delete(results);
  gt_str_delete(defaultstylefile);
  gt_feature_index_delete(features);

  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2088, %rsp           # imm = 0x2088
movq %r8, %r15
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %rbx
movl %edi, %r14d
testq %r8, %r8
je 0x225c13
movq %r15, %rdi
callq 0x101a9a
testb %al, %al
jne 0x226307
movq %r15, 0x30(%rsp)
movq %r12, 0x8(%rsp)
testq %r12, %r12
je 0x226302
callq 0x1208f8
movq %rax, %r15
movq (%rbx), %r13
movq %r13, %rdi
movl $0x20, %esi
callq 0xe885c
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x120a9d
movq %r15, %rdi
callq 0x120d23
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x105688
movq %rax, %r12
movq %r15, %rdi
callq 0x121b03
testq %r12, %r12
je 0x225c80
leaq 0x1a901c(%rip), %rsi    # 0x3cec94
movq %r12, %rdi
callq 0x12097f
movslq %ebp, %rax
movq (%rbx,%rax,8), %rax
movq %rax, 0x40(%rsp)
testq %r12, %r12
movq 0x8(%rsp), %r13
je 0x225cf8
callq 0x148ed1
movq %rax, %r15
incl %ebp
movq 0x20(%r13), %rdi
callq 0x120d23
leaq 0x12b2df(%rip), %rsi    # 0x350f8f
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x225d06
movq 0x20(%r13), %rdi
callq 0x120d23
leaq 0x13435e(%rip), %rsi    # 0x35a02a
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x225d2c
movq 0x20(%r13), %rdi
callq 0x120d23
leaq 0x128a4b(%rip), %rsi    # 0x34e733
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x225d35
xorl %ebx, %ebx
jmp 0x225d5b
xorl %r14d, %r14d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x225dfe
subl %ebp, %r14d
movslq %ebp, %rax
leaq (%rbx,%rax,8), %rsi
movl %r14d, %edi
callq 0x14d00b
movq %rax, %rbx
cmpb $0x1, 0x1(%r13)
jne 0x225d5b
movq %rbx, %rdi
callq 0x14ce62
jmp 0x225d5b
cmpl %ebp, %r14d
jne 0x225d3e
xorl %edi, %edi
jmp 0x225d45
cmpl %ebp, %r14d
jne 0x225d4c
xorl %edi, %edi
jmp 0x225d53
movslq %ebp, %rax
movq (%rbx,%rax,8), %rdi
callq 0x12c509
jmp 0x225d58
movslq %ebp, %rax
movq (%rbx,%rax,8), %rdi
callq 0x154286
movq %rax, %rbx
cmpb $0x1, 0x2(%r13)
jne 0x225d7f
movq %rbx, %rdi
callq 0x17e1d7
movq %rax, %r14
movq %rax, %rdi
callq 0x126660
movq %rax, %rdi
movq %rax, 0x28(%rsp)
jmp 0x225d8e
xorl %r14d, %r14d
movq %rbx, %rdi
movq $0x0, 0x28(%rsp)
movq %rbx, 0x18(%rsp)
cmpb $0x1, (%r13)
jne 0x225dac
movq %r12, %rbx
xorl %esi, %esi
callq 0x14e310
movq %rax, %rdi
movq %rax, %rbp
jmp 0x225db1
movq %r12, %rbx
xorl %ebp, %ebp
movq %r15, %rsi
callq 0x14b480
movq %rax, %r12
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x16adca
movl %eax, %r13d
movq %r12, %rdi
callq 0x16ac6e
movq %rbp, %rdi
callq 0x16ac6e
movq %r14, %rdi
movq %r15, %r14
callq 0x16ac6e
movq 0x28(%rsp), %rdi
callq 0x16ac6e
movq 0x18(%rsp), %rdi
callq 0x16ac6e
movq %rbx, %r12
testl %r13d, %r13d
movq 0x30(%rsp), %rbp
jne 0x225e2c
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x120d23
leaq 0x7(%rsp), %rsi
movq %r14, %rdi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x147f52
movl %eax, %r13d
testl %r13d, %r13d
je 0x225e36
xorl %r15d, %r15d
jmp 0x225eaf
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0x120d23
cmpb $0x0, (%rax)
je 0x225e64
movq 0x8(%rbx), %rdi
movb 0x7(%rsp), %bl
callq 0x120d23
testb %bl, %bl
je 0x225e7c
movq %rax, %rdi
callq 0xe8760
jmp 0x225e74
movq %r14, %rdi
movq %rbp, %rsi
callq 0x147d91
testq %rax, %rax
je 0x225e95
movq %rax, %r15
xorl %r13d, %r13d
jmp 0x225eaf
leaq 0x1a8b38(%rip), %rsi    # 0x3ce9bb
xorl %r15d, %r15d
movq %rbp, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x225ea9
leaq 0x1a8af0(%rip), %rsi    # 0x3ce98c
xorl %r15d, %r15d
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1019cf
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x8, %edi
callq 0xd46fc
movq %rax, 0x28(%rsp)
testl %r13d, %r13d
jne 0x225ed9
leaq 0x60(%rsp), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x147e84
movl %eax, %r13d
testl %r13d, %r13d
je 0x225eec
movq $0x0, 0x18(%rsp)
jmp 0x225fbd
movq 0x8(%rsp), %rbx
movq 0x28(%rbx), %rax
cmpq $-0x1, %rax
jne 0x225f00
movq 0x60(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x30(%rbx), %rax
cmpq $-0x1, %rax
jne 0x225f14
movq 0x68(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpb $0x1, 0x1(%rbx)
je 0x226115
movq %rbp, %rdi
callq 0x228fe4
movq %rax, %r13
movq 0x18(%rbx), %rdi
callq 0x120d4c
testq %rax, %rax
movq %r13, 0x18(%rsp)
je 0x225f8a
testq %r13, %r13
je 0x225f6b
movq 0x18(%rbx), %rdi
callq 0x120d23
movq %rax, %rdi
callq 0x10415c
testb %al, %al
je 0x225f6b
cmpb $0x1, 0x5(%rbx)
jne 0x225f9b
movq %r13, %rdi
callq 0x229290
jmp 0x225f9b
movq 0x18(%rbx), %rdi
callq 0x120d23
leaq 0x1a8a89(%rip), %rsi    # 0x3cea04
movq %rbp, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
jmp 0x225fb7
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0x120a43
testq %r13, %r13
je 0x225fb7
movq 0x18(%rbx), %rdi
callq 0x120d23
movq %r13, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x2293f6
movl %eax, %r13d
jmp 0x225fbd
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %r13d, %r13d
movq %r14, 0x58(%rsp)
movq %r15, 0x50(%rsp)
je 0x225fdb
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %r14d, %r14d
jmp 0x226166
leaq 0x70(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %r13
movq %r13, %rcx
movq %rbp, %r8
callq 0x222670
movq %rax, 0x10(%rsp)
testq %rax, %rax
movq 0x8(%rsp), %rbx
je 0x22603d
cmpb $0x1, 0x4(%rbx)
jne 0x22601e
leaq 0x2fa(%rip), %rsi       # 0x22630c
movq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x22283a
movl 0x38(%rbx), %esi
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x22730c
testq %rax, %rax
je 0x22603d
movq %rax, %rbx
movb $0x1, %al
jmp 0x226041
xorl %ebx, %ebx
xorl %eax, %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testb %al, %al
je 0x22605e
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x227840
movl %eax, %r13d
movq %rbx, 0x20(%rsp)
testl %r13d, %r13d
je 0x226077
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x10(%rsp), %rbp
jmp 0x226161
callq 0x227018
movq %rax, %rbx
movq 0x8(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x120d23
leaq 0x1c2cf5(%rip), %rsi    # 0x3e8d89
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
je 0x2260f0
movq 0x10(%r14), %rdi
callq 0x120d23
leaq 0x1c2cf3(%rip), %rsi    # 0x3e8da3
movq %rax, %rdi
callq 0x17a40
testl %eax, %eax
movq 0x18(%rsp), %r13
je 0x226102
movq 0x10(%r14), %rdi
callq 0x120d23
leaq 0x1c2ceb(%rip), %rsi    # 0x3e8dbc
movq %rax, %rdi
callq 0x17a40
movl 0x38(%r14), %edx
movq 0x38(%rsp), %rcx
movq %r13, %rdi
testl %eax, %eax
je 0x226124
movl $0x1, %esi
jmp 0x226129
movl 0x38(%r14), %edx
movq 0x38(%rsp), %rcx
movq 0x18(%rsp), %rdi
xorl %esi, %esi
jmp 0x226129
movl 0x38(%r14), %edx
movq 0x38(%rsp), %rcx
movq %r13, %rdi
movl $0x2, %esi
jmp 0x226129
movq 0x28(%rsp), %rdi
callq 0x86614
jmp 0x225f23
movl $0x3, %esi
movq %rbx, %r8
movq %rbp, %r9
callq 0x33a452
movq %rax, %r14
testq %rax, %rax
je 0x226151
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x227604
movl %eax, %r13d
jmp 0x226157
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rbp
testl %r13d, %r13d
je 0x2261d7
movq 0x20(%rsp), %r15
leaq 0x1a84d2(%rip), %rsi    # 0x3ce63f
movq 0x50(%rsp), %rdi
movl $0x1e3, %edx            # imm = 0x1E3
callq 0x109670
movq %r14, %rdi
callq 0x222462
movq %r15, %rdi
callq 0x227596
movq %rbx, %rdi
callq 0x227066
movq 0x18(%rsp), %rdi
callq 0x22a740
movq %rbp, %rdi
callq 0x222cb7
movq 0x28(%rsp), %rdi
callq 0xd4ef4
movq %r12, %rdi
callq 0x121b03
movq 0x58(%rsp), %rdi
callq 0x147952
movl %r13d, %eax
addq $0x2088, %rsp           # imm = 0x2088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
cmpb $0x1, 0x3(%rax)
jne 0x22624b
movq %rbx, %rdi
callq 0x2270e0
testq %rax, %rax
je 0x22624b
leaq 0x80(%rsp), %r13
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x227137
movq %rax, %r15
movl $0x2000, %edx           # imm = 0x2000
movq %rax, %rdi
movq %r13, %rsi
callq 0x228f70
movq %r15, %rdi
callq 0x228f41
movq %rax, %rdi
callq 0x149bb2
leaq 0x1a87f6(%rip), %rdi    # 0x3cea24
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x17070
incq %rbp
movq %rbx, %rdi
callq 0x2270e0
cmpq %rax, %rbp
jb 0x2261f9
movq 0x8(%rsp), %rax
cmpb $0x1, 0x7(%rax)
jne 0x2262c1
movq %r12, 0x8(%rsp)
callq 0x1208f8
movq %rax, %rbp
movq %r14, 0x48(%rsp)
movq %r14, %rdi
movq %rax, %rsi
callq 0x33a3a0
leaq 0x1283ef(%rip), %rdx    # 0x34e669
xorl %r13d, %r13d
xorl %edi, %edi
movq 0x40(%rsp), %rsi
movq 0x30(%rsp), %rcx
callq 0x1039a2
testq %rax, %rax
je 0x2262db
movq %rax, %r15
movq %rbp, %rdi
callq 0x120d3d
movq %rax, %r12
movq %rbp, %rdi
callq 0x120d4c
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x104060
movq %r15, %rdi
callq 0x1040fc
jmp 0x2262e1
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x33a334
movl %eax, %r13d
jmp 0x22606d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %rbp, %rdi
callq 0x121b03
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %rbp
movq 0x20(%rsp), %r15
movq 0x48(%rsp), %r14
jmp 0x226166
callq 0x8663a
callq 0x865db