// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/core/sequence_buffer_fastq.c
// Function: gt_sequence_buffer_fastq_advance
static int gt_sequence_buffer_fastq_advance(GtSequenceBuffer *sb, GtError *err)
{
  GtUword currentoutpos = 0, currentfileadd = 0, currentfileread = 0,
                seqlen = 0, desclen, cnt, newfilenum;
  GtSequenceBufferMembers *pvt;
  GtSequenceBufferFastQ *sbfq;
  const GtUchar *seq;
  char *desc;
  int had_err = 0;
  gt_error_check(err);

  sbfq = gt_sequence_buffer_fastq_cast(sb);
  pvt = sb->pvt;

  if (!sbfq->seqit) {
    sbfq->seqit = (GtSeqIteratorFastQ*)
                         gt_seq_iterator_fastq_new(sbfq->sequences, err);
    if (!sbfq->seqit) return -1;
  }

  /* did the last buffer end with a sequence boundary?
     if so, we need to provide an additional separator! */
  if (sbfq->carryseparator) {
    pvt->outbuf[currentoutpos++] = (GtUchar) GT_SEPARATOR;
    currentfileread++;
    pvt->lastspeciallength++;
    currentfileadd++;
    sbfq->carryseparator = false;
  }

  if (gt_str_length(sbfq->overflowbuffer) > 0) {
    /* we still have surplus sequence from the last line, process that first */
    const char *overflowedstring;
    char cc;
    overflowedstring = gt_str_get(sbfq->overflowbuffer);
    while (!had_err && currentoutpos < (GtUword) OUTBUFSIZE
             &&(cc = *(overflowedstring)) != '\0')
    {
      if ((had_err = process_char(sb, currentoutpos, cc, err)))
          return had_err;
      currentoutpos++;
      currentfileadd++;
      currentfileread++;
      overflowedstring++;
    }
    /* still sequence left in overflowbuffer? */
    if (*(overflowedstring) != '\0') {
      gt_str_set(sbfq->overflowbuffer, overflowedstring);
    } else {
      pvt->outbuf[currentoutpos++] = (GtUchar) GT_SEPARATOR;
      currentfileread++;
      pvt->lastspeciallength++;
      gt_str_reset(sbfq->overflowbuffer);
      gt_assert(gt_str_length(sbfq->overflowbuffer) == 0);
    }
  }

  /* we need more than one round to deal with the overflowed sequence */
  if (gt_str_length(sbfq->overflowbuffer) > 0) {
    pvt->nextfree = GT_MIN(currentoutpos, OUTBUFSIZE);
    return had_err;
  }

  gt_assert(gt_str_length(sbfq->overflowbuffer) == 0);
  /* iterate over sequences */
  while (true) {
    had_err = gt_seq_iterator_next((GtSeqIterator*) sbfq->seqit, &seq, &seqlen,
                                  &desc, err);
    newfilenum = gt_seq_iterator_fastq_get_file_index(sbfq->seqit);

    /* update current file info */
    if (pvt->filenum != newfilenum) {
      if (pvt->filelengthtab) {
        pvt->filelengthtab[pvt->filenum].length += (uint64_t) currentfileread;
        pvt->filelengthtab[pvt->filenum].effectivelength += (uint64_t)
                                                               currentfileadd;
      }
      currentfileread = currentfileadd = 0;
      pvt->filenum = newfilenum;
    }

    /* error check! */
    if (had_err < 0) {
      return had_err;
    }

    /* end of iterator reached */
    if (had_err == 0) {
      pvt->complete = true;
      /* remove last separator */
      pvt->outbuf[--currentoutpos] = (GtUchar) '\0';
      currentfileadd--;
      break;
    }

    /* copy sequence */
    for (cnt=0;cnt<seqlen;cnt++) {
      if (currentoutpos >= (GtUword) OUTBUFSIZE) {
        gt_str_append_char(sbfq->overflowbuffer, seq[cnt]);
      } else {
        if ((had_err = process_char(sb, currentoutpos, seq[cnt], err)))
          return had_err;
        currentoutpos++;
        currentfileadd++;
        currentfileread++;
      }
    }

    /* place separator after sequence (or defer) */
    if (gt_str_length(sbfq->overflowbuffer) == 0) {
      if (currentoutpos >= (GtUword) OUTBUFSIZE)
        sbfq->carryseparator = true;
      else {
        pvt->outbuf[currentoutpos++] = (GtUchar) GT_SEPARATOR;
        pvt->lastspeciallength++;
        currentfileadd++;
      }
    }

    desclen = strlen(desc)+1;
    currentfileread += desclen; /* XXX: we cannot know whether the desc was */
    pvt->counter += desclen;    /*      repeated before the qualities line  */

    /* enqueue description */
    if (pvt->descptr) {
      int i;
      for (i = 0; i < strlen(desc); i++) {
        gt_desc_buffer_append_char(pvt->descptr, desc[i]);
      }
      gt_desc_buffer_finish(pvt->descptr);
    }

    /* if buffer is full, return it */
    if (currentoutpos >= (GtUword) OUTBUFSIZE) {
      pvt->nextfree = GT_MIN(currentoutpos, OUTBUFSIZE);
      had_err = 0;
      break;
    }
  }

  /* update information about read characters */
  if (pvt->filelengthtab) {
    pvt->filelengthtab[pvt->filenum].length
      += (uint64_t) currentfileread;
    pvt->filelengthtab[pvt->filenum].effectivelength
      += (uint64_t) currentfileadd;
  }
  pvt->nextfree = GT_MIN(currentoutpos, OUTBUFSIZE);
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rsi, %rsi
je 0x814c0
movq %r15, %rdi
callq 0x3566a
testb %al, %al
jne 0x81940
leaq 0xce361(%rip), %rdi     # 0x14f828
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x7f396
movq %rax, %r12
movq 0x8(%rbx), %r14
cmpq $0x0, 0x10(%rax)
jne 0x814fd
movq 0x18(%r12), %rdi
movq %r15, %rsi
callq 0xa6491
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x8164f
xorl %r13d, %r13d
cmpb $0x1, 0x20(%r12)
jne 0x81521
movb $-0x1, 0x2079(%r14)
incq 0x60(%r14)
movb $0x0, 0x20(%r12)
movl $0x1, %ebx
jmp 0x81523
xorl %ebx, %ebx
movq %r15, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq 0x28(%r12), %rdi
callq 0x3c434
testq %rax, %rax
movq %r12, 0x8(%rsp)
je 0x81640
movq 0x28(%r12), %rdi
callq 0x3c40b
movq %rax, %r12
leaq 0x71e0b(%rip), %rbp     # 0xf3364
movzbl (%r12), %r13d
testq %r13, %r13
je 0x81621
movq 0x20(%rsp), %rax
movq 0x8(%rax), %r14
movq 0x6080(%r14), %rcx
movl %r13d, %eax
testq %rcx, %rcx
je 0x815ea
movzbl (%rcx,%r13), %eax
cmpq $0xfd, %rax
jne 0x815bc
movq 0x70(%r14), %rdi
movl (%r14), %esi
callq 0x3d3e2
movq 0x8(%r14), %r8
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
movl %r13d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3559f
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
jmp 0x81604
leaq 0x60(%r14), %rcx
movq 0x60(%r14), %rdx
cmpb $-0x3, %al
ja 0x815e4
testq %rdx, %rdx
je 0x815d4
movq $0x0, (%rcx)
movq 0x38(%r14), %rcx
testq %rcx, %rcx
je 0x815ea
leaq (%rcx,%rax,8), %rcx
movq (%rcx), %rdx
incq %rdx
movq %rdx, (%rcx)
movb %al, 0x2079(%r14,%rbx)
movb %r13b, 0x4079(%r14,%rbx)
incq 0x68(%r14)
xorl %r13d, %r13d
movb $0x1, %r14b
testb %r14b, %r14b
je 0x81648
incq %rbx
incq %r12
cmpq $0x2000, %rbx           # imm = 0x2000
jne 0x81559
movl $0x2000, %ebx           # imm = 0x2000
cmpb $0x0, (%r12)
movq 0x8(%rsp), %r14
je 0x81657
movq 0x28(%r14), %rdi
movq %r12, %rsi
callq 0x3c0cc
movb $0x1, %al
xorl %r13d, %r13d
jmp 0x8164a
movq %rbx, %r14
movq %rbx, %r12
jmp 0x81696
xorl %eax, %eax
movq %rbx, %r12
jmp 0x8168c
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x816be
movq 0x10(%rsp), %rax
movb $-0x1, 0x2079(%rax,%rbx)
incq 0x60(%rax)
movq 0x28(%r14), %rdi
callq 0x3c49c
movq 0x28(%r14), %rdi
callq 0x3c434
testq %rax, %rax
jne 0x8194a
leaq 0x1(%rbx), %r12
movb $0x1, %al
xorl %r13d, %r13d
movq %rbx, %r14
movq %r12, %rbx
testb %al, %al
je 0x816be
movq 0x8(%rsp), %rbp
movq 0x28(%rbp), %rdi
callq 0x3c434
testq %rax, %rax
je 0x816d0
movq 0x10(%rsp), %r15
movl $0x2000, %eax           # imm = 0x2000
cmpq %rax, %r12
cmovbq %r12, %rax
movq %rax, 0x58(%r15)
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rbp), %rdi
callq 0x3c434
testq %rax, %rax
movq 0x10(%rsp), %r15
jne 0x81945
movq 0x18(%rsp), %r8
movq 0x10(%rbp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0xa5ac9
movl %eax, %r13d
movq 0x10(%rbp), %rdi
callq 0xa5b48
movl (%r15), %ecx
cmpq %rcx, %rax
je 0x81736
movq 0x10(%r15), %rdx
testq %rdx, %rdx
je 0x8172e
shlq $0x4, %rcx
addq %rbx, (%rdx,%rcx)
addq %r14, 0x8(%rdx,%rcx)
movl %eax, (%r15)
xorl %ebx, %ebx
xorl %r14d, %r14d
testl %r13d, %r13d
js 0x816be
je 0x81907
cmpq $0x0, 0x30(%rsp)
je 0x81842
xorl %ebp, %ebp
cmpq $0x2000, %r12           # imm = 0x2000
jb 0x81774
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x38(%rsp), %rax
movsbl (%rax,%rbp), %esi
callq 0x3c28d
jmp 0x81834
movq 0x38(%rsp), %rax
movb (%rax,%rbp), %al
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %r15
movq 0x6080(%r15), %rdx
movl %eax, %ecx
testq %rdx, %rdx
je 0x81808
movzbl %al, %r13d
movzbl (%rdx,%r13), %ecx
cmpq $0xfd, %rcx
jne 0x817d9
movq 0x70(%r15), %rdi
movl (%r15), %esi
callq 0x3d3e2
movq 0x8(%r15), %r8
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
leaq 0x71ba0(%rip), %rsi     # 0xf3364
movl %r13d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3559f
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
jmp 0x81822
leaq 0x60(%r15), %rdx
movq 0x60(%r15), %rsi
cmpb $-0x3, %cl
ja 0x81802
testq %rsi, %rsi
je 0x817f2
movq $0x0, (%rdx)
movq 0x38(%r15), %rdx
testq %rdx, %rdx
je 0x81808
leaq (%rdx,%rcx,8), %rdx
movq (%rdx), %rsi
incq %rsi
movq %rsi, (%rdx)
movb %cl, 0x2079(%r15,%r12)
movb %al, 0x4079(%r15,%r12)
incq 0x68(%r15)
xorl %r13d, %r13d
movb $0x1, %r15b
testb %r15b, %r15b
je 0x816be
incq %r12
incq %r14
incq %rbx
incq %rbp
cmpq 0x30(%rsp), %rbp
jb 0x8174f
movq 0x8(%rsp), %rbp
movq 0x28(%rbp), %rdi
callq 0x3c434
testq %rax, %rax
movq 0x10(%rsp), %r15
jne 0x8187c
cmpq $0x2000, %r12           # imm = 0x2000
jb 0x81869
movb $0x1, 0x20(%rbp)
jmp 0x8187c
movb $-0x1, 0x2079(%r15,%r12)
incq %r12
incq 0x60(%r15)
incq %r14
movq 0x28(%rsp), %rdi
callq 0xb260
leaq 0x1(%rax), %rcx
addq %rcx, 0x68(%r15)
cmpq $0x0, 0x20(%r15)
je 0x818e5
movq %rax, 0x40(%rsp)
movq %r15, %r13
movq 0x28(%rsp), %rbp
cmpb $0x0, (%rbp)
je 0x818cf
xorl %r15d, %r15d
movq 0x20(%r13), %rdi
movsbl (%rbp,%r15), %esi
callq 0xa4434
incq %r15
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0xb260
cmpq %r15, %rax
ja 0x818ab
movq 0x20(%r13), %rdi
callq 0xa44e6
movq %r13, %r15
movq 0x8(%rsp), %rbp
movq 0x40(%rsp), %rax
addq %rax, %rbx
incq %rbx
cmpq $0x2000, %r12           # imm = 0x2000
movq 0x18(%rsp), %r8
jb 0x816ec
movq $0x2000, 0x58(%r15)     # imm = 0x2000
jmp 0x8191b
movb $0x1, 0x18(%r15)
movb $0x0, 0x2078(%r15,%r12)
decq %r12
decq %r14
movq 0x10(%r15), %rax
xorl %r13d, %r13d
testq %rax, %rax
je 0x816ae
movl (%r15), %ecx
shlq $0x4, %rcx
addq %rbx, (%rax,%rcx)
addq %r14, 0x8(%rax,%rcx)
jmp 0x816ae
callq 0x1e0bb
callq 0x1e129
callq 0x1e0f2