// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/tools/gt_fastq_sample.c
// Function: gt_fastq_sample_print
static int gt_fastq_sample_print(GtStrArray *filenames,
                                 GtFastqSampleArguments *args, GtError *err)
{
  GtSeqIterator* fastq_iterator;
  GtUword sum, num_seq, len_count, seq_count, pos;
  GtBittab *vector;
  GtArray *lengths;
  int had_err = 0;
  GtUword len = 0;
  const GtUchar *qualities = NULL;
  const GtUchar *sequence = NULL;
  char *description = NULL;

  /* iterate through seq's: sum up lengths and count number of seq's */
  sum = 0;
  num_seq = 0;
  lengths = gt_array_new(sizeof(GtUword));
  fastq_iterator = gt_seq_iterator_fastq_new(filenames, err);
  if (gt_seq_iterator_has_qualities(fastq_iterator)) {
    gt_seq_iterator_set_quality_buffer(fastq_iterator, &qualities);
  }
  while ((had_err = gt_seq_iterator_next(fastq_iterator, &sequence, &len,
        &description, err)) == 1) {
    sum += len;
    num_seq += 1;
    gt_array_add(lengths, len);
  }
  gt_seq_iterator_delete(fastq_iterator);

  /* check input data for errors */
  if (had_err) return had_err;
  if (num_seq == 0) {
    gt_array_delete(lengths);
    gt_error_set(err, "file does not contain any sequence data");
    return -1;
  }
  if (sum < args->length) {
    gt_array_delete(lengths);
    gt_error_set(err, "requested length "GT_WU" exceeds length of sequences"
                 " ("GT_WU")", args->length, sum);
    return -1;
  }

  /* fill bit vector randomly until args->length is reached */
  vector = gt_bittab_new(num_seq);
  len_count = 0;
  seq_count = 0;
  pos = (num_seq != 1) ? gt_rand_max(num_seq-1): 0; /* random start position */
  while (len_count < args->length) {
    /* probability for setting a bit = args->length / sum    */
    if (gt_rand_max(sum-1) < args->length &&
        !gt_bittab_bit_is_set(vector, pos)) {
      gt_bittab_set_bit(vector, pos);
      len_count += *((GtUword *) gt_array_get(lengths, pos));
      seq_count += 1;
    }
    pos = (pos+1) % num_seq; /* iterate through bit vector cyclically */
  }
  gt_array_delete(lengths);

  /* print fastq entries according to bitvector */
  printf("total length "GT_WU" from "GT_WU" entries\n", len_count, seq_count);
  fastq_iterator = gt_seq_iterator_fastq_new(filenames, err);
  if (gt_seq_iterator_has_qualities(fastq_iterator)) {
    gt_seq_iterator_set_quality_buffer(fastq_iterator, &qualities);
  }
  pos = 0;
  while ((had_err = gt_seq_iterator_next(fastq_iterator, &sequence, &len,
        &description, err)) == 1) {
    gt_assert(pos < num_seq);
    if (gt_bittab_bit_is_set(vector, pos)) {
      if (gt_seq_iterator_has_qualities(fastq_iterator)) {
        gt_fastq_show_entry(description, (const char *) sequence,
                            (const char *) qualities, len, 0, false, NULL);
      } else {
        gt_fasta_show_entry(description, (const char *) sequence, len, 0, NULL);
      }
    }
    pos += 1;
  }
  gt_seq_iterator_delete(fastq_iterator);
  gt_bittab_delete(vector);
  return had_err;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movl $0x8, %edi
callq 0x80990
movq %rax, 0x38(%rsp)
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x1126d0
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0x111930
testb $0x1, %al
jne 0x36ce0
jmp 0x36cef
movq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x111990
jmp 0x36cf1
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %r8
leaq 0x18(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x111ab0
movl %eax, 0x34(%rsp)
cmpl $0x1, %eax
jne 0x36d4b
movq 0x28(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl $0x8, %edx
callq 0x81100
jmp 0x36cf1
movq 0x70(%rsp), %rdi
callq 0x111c10
cmpl $0x0, 0x34(%rsp)
je 0x36d6c
movl 0x34(%rsp), %eax
movl %eax, 0x94(%rsp)
jmp 0x3704e
cmpq $0x0, 0x60(%rsp)
jne 0x36da1
movq 0x38(%rsp), %rdi
callq 0x81f80
movq 0x78(%rsp), %rdi
leaq 0x4e6e0f(%rip), %rsi    # 0x51db99
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x3704e
movq 0x68(%rsp), %rax
movq 0x80(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x36df0
movq 0x38(%rsp), %rdi
callq 0x81f80
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rax
movq (%rax), %rdx
movq 0x68(%rsp), %rcx
leaq 0x4e629e(%rip), %rsi    # 0x51d077
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x3704e
movq 0x60(%rsp), %rdi
callq 0x89a20
movq %rax, 0x40(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
cmpq $0x1, 0x60(%rsp)
je 0x36e2e
movq 0x60(%rsp), %rdi
subq $0x1, %rdi
callq 0xec350
movq %rax, 0x8(%rsp)
jmp 0x36e37
xorl %eax, %eax
movq %rax, 0x8(%rsp)
jmp 0x36e37
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rax
movq 0x80(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x36eda
movq 0x68(%rsp), %rdi
subq $0x1, %rdi
callq 0xec350
movq 0x80(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x36ebe
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x8a780
testb $0x1, %al
jne 0x36ebe
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x89b00
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x80b60
movq (%rax), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x48(%rsp), %rax
addq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x60(%rsp)
movq %rdx, 0x48(%rsp)
jmp 0x36e41
movq 0x38(%rsp), %rdi
callq 0x81f80
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x4e6ccc(%rip), %rdi    # 0x51dbc1
movb $0x0, %al
callq 0x19070
movq 0x88(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x1126d0
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0x111930
testb $0x1, %al
jne 0x36f23
jmp 0x36f32
movq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x111990
movq $0x0, 0x48(%rsp)
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %r8
leaq 0x18(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x111ab0
movl %eax, 0x34(%rsp)
cmpl $0x1, %eax
jne 0x3702f
jmp 0x36f68
movq 0x48(%rsp), %rax
cmpq 0x60(%rsp), %rax
jb 0x36fac
movq 0x605025(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x4df08e(%rip), %rsi    # 0x516013
leaq 0x4e6c58(%rip), %rdx    # 0x51dbe4
leaq 0x4e6c5f(%rip), %rcx    # 0x51dbf2
leaq 0x4e6a48(%rip), %r8     # 0x51d9e2
movl $0xa5, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x36fae
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x8a780
testb $0x1, %al
jne 0x36fc3
jmp 0x3701c
movq 0x70(%rsp), %rdi
callq 0x111930
testb $0x1, %al
jne 0x36fd3
jmp 0x36ffe
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
movq $0x0, (%rsp)
callq 0xdcef0
jmp 0x3701a
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0xdbd10
jmp 0x3701c
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x36f3b
movq 0x70(%rsp), %rdi
callq 0x111c10
movq 0x40(%rsp), %rdi
callq 0x8af40
movl 0x34(%rsp), %eax
movl %eax, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopl (%rax)