// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
testq %rsi, %rsi
je 0x813f8
movq %r15, %rdi
callq 0x34fea
testb %al, %al
jne 0x8185b
leaq 0xce429(%rip), %rdi     # 0x14f828
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x7f41e
movq %rax, %r12
movq 0x8(%rbx), %r13
cmpq $0x0, 0x10(%rax)
jne 0x81435
movq 0x18(%r12), %rdi
movq %r15, %rsi
callq 0xa5be5
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x8152f
cmpb $0x1, 0x20(%r12)
jne 0x81456
movb $-0x1, 0x2079(%r13)
incq 0x60(%r13)
movb $0x0, 0x20(%r12)
movl $0x1, %ebx
jmp 0x81458
xorl %ebx, %ebx
movq 0x28(%r12), %rdi
callq 0x3bb86
testq %rax, %rax
movq %r12, 0x8(%rsp)
je 0x8152a
movq 0x28(%r12), %rdi
callq 0x3bb5d
movzbl (%rax), %r12d
testq %r12, %r12
je 0x8155e
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %r14
movq 0x6080(%r14), %rdx
movl %r12d, %ecx
testq %rdx, %rdx
je 0x814e0
movzbl (%rdx,%r12), %ecx
cmpq $0xfd, %rcx
je 0x8153a
leaq 0x60(%r14), %rdx
movq 0x60(%r14), %rsi
cmpb $-0x3, %cl
ja 0x814da
testq %rsi, %rsi
je 0x814ca
movq $0x0, (%rdx)
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0x814e0
leaq (%rdx,%rcx,8), %rdx
movq (%rdx), %rsi
incq %rsi
movq %rsi, (%rdx)
movb %cl, 0x2079(%r14,%rbx)
movb %r12b, 0x4079(%r14,%rbx)
incq 0x68(%r14)
incq %rbx
incq %rax
cmpq $0x2000, %rbx           # imm = 0x2000
jne 0x8147a
cmpb $0x0, (%rax)
je 0x81559
movq 0x8(%rsp), %r12
movq 0x28(%r12), %rdi
movq %rax, %rsi
callq 0x3b81e
movl $0x2000, %ebp           # imm = 0x2000
movl $0x2000, %ebx           # imm = 0x2000
jmp 0x81591
movq %rbx, %rbp
jmp 0x81591
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x8180a
movq 0x70(%r14), %rdi
movl (%r14), %esi
callq 0x3ca6f
movq 0x8(%r14), %r8
leaq 0x71db2(%rip), %rsi     # 0xf3303
movq %r15, %rdi
jmp 0x817f7
movl $0x2000, %ebx           # imm = 0x2000
movq 0x8(%rsp), %r12
movb $-0x1, 0x2079(%r13,%rbx)
incq 0x60(%r13)
movq 0x28(%r12), %rdi
callq 0x3bbee
movq 0x28(%r12), %rdi
callq 0x3bb86
testq %rax, %rax
jne 0x81860
leaq 0x1(%rbx), %rbp
movq 0x28(%r12), %rdi
callq 0x3bb86
testq %rax, %rax
je 0x815b8
movl $0x2000, %eax           # imm = 0x2000
cmpq %rax, %rbp
cmovbq %rbp, %rax
movq %rax, 0x58(%r13)
xorl %r12d, %r12d
jmp 0x8180a
movq 0x28(%r12), %rdi
callq 0x3bb86
testq %rax, %rax
jne 0x81865
movq %rbp, %r14
movq %r13, 0x10(%rsp)
movq %r15, 0x28(%rsp)
movq 0x10(%r12), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %r15, %r8
callq 0xa5259
movq %r12, %rcx
movl %eax, %r12d
movq 0x10(%rcx), %rdi
callq 0xa52d8
movl (%r13), %ecx
cmpq %rcx, %rax
je 0x8162a
movq 0x10(%r13), %rdx
testq %rdx, %rdx
je 0x81622
shlq $0x4, %rcx
addq %rbp, (%rdx,%rcx)
addq %rbx, 0x8(%rdx,%rcx)
movl %eax, (%r13)
xorl %ebp, %ebp
xorl %ebx, %ebx
testl %r12d, %r12d
js 0x8180a
je 0x8181c
cmpq $0x0, 0x20(%rsp)
je 0x8170d
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
cmpq $0x2000, %r14           # imm = 0x2000
jb 0x8166f
movq 0x28(%r12), %rdi
movq 0x38(%rsp), %rax
movsbl (%rax,%r13), %esi
callq 0x3b9df
jmp 0x816fd
movq 0x38(%rsp), %rax
movb (%rax,%r13), %al
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %r15
movq 0x6080(%r15), %rdx
movl %eax, %ecx
testq %rdx, %rdx
je 0x816e0
movzbl %al, %r12d
movzbl (%rdx,%r12), %ecx
cmpq $0xfd, %rcx
je 0x817db
leaq 0x60(%r15), %rdx
movq 0x60(%r15), %rsi
cmpb $-0x3, %cl
jbe 0x816b9
movq 0x8(%rsp), %r12
jmp 0x816da
testq %rsi, %rsi
movq 0x8(%rsp), %r12
je 0x816ca
movq $0x0, (%rdx)
movq 0x38(%r15), %rdx
testq %rdx, %rdx
je 0x816e0
leaq (%rdx,%rcx,8), %rdx
movq (%rdx), %rsi
incq %rsi
movq %rsi, (%rdx)
movb %cl, 0x2079(%r15,%r14)
movb %al, 0x4079(%r15,%r14)
incq 0x68(%r15)
incq %r14
incq %rbx
incq %rbp
incq %r13
cmpq 0x20(%rsp), %r13
jb 0x8164d
jmp 0x81712
movq 0x8(%rsp), %r12
movq 0x28(%r12), %rdi
callq 0x3bb86
testq %rax, %rax
movq 0x10(%rsp), %rax
jne 0x8174a
cmpq $0x2000, %r14           # imm = 0x2000
jb 0x81737
movb $0x1, 0x20(%r12)
jmp 0x8174a
movb $-0x1, 0x2079(%rax,%r14)
incq %r14
incq 0x60(%rax)
incq %rbx
movq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0xb260
movq %rax, %r15
incq %rax
movq 0x10(%rsp), %rcx
addq %rax, 0x68(%rcx)
movq 0x20(%rcx), %rdi
testq %rdi, %rdi
je 0x817bc
cmpb $0x0, (%r13)
je 0x817b7
movq %r15, 0x40(%rsp)
xorl %r15d, %r15d
movq 0x10(%rsp), %r12
movq 0x20(%r12), %rdi
movsbl (%r13,%r15), %esi
callq 0xa3c20
incq %r15
movq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0xb260
cmpq %r15, %rax
ja 0x81783
movq 0x20(%r12), %rdi
movq 0x8(%rsp), %r12
movq 0x40(%rsp), %r15
callq 0xa3cd2
addq %r15, %rbp
incq %rbp
cmpq $0x2000, %r14           # imm = 0x2000
movq 0x28(%rsp), %r15
movq 0x10(%rsp), %r13
jb 0x815d8
jmp 0x81830
movq 0x70(%r15), %rdi
movl (%r15), %esi
callq 0x3ca6f
movq 0x8(%r15), %r8
leaq 0x71b11(%rip), %rsi     # 0xf3303
movq 0x28(%rsp), %rdi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x34f1f
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x18(%r13)
movb $0x0, 0x2078(%r13,%r14)
decq %r14
decq %rbx
movq 0x10(%r13), %rax
testq %rax, %rax
je 0x8184a
movl (%r13), %ecx
shlq $0x4, %rcx
addq %rbp, (%rax,%rcx)
addq %rbx, 0x8(%rax,%rcx)
movl $0x2000, %eax           # imm = 0x2000
cmpq %rax, %r14
cmovbq %r14, %rax
jmp 0x815ac
callq 0x1e055
callq 0x1e08c
callq 0x1e0c3