// File: /workspace/github_cpp_makefile_star2_O1/BenLangmead[P]bowtie/ref_read.cpp
// Function: fastaRefReadSize(FileBuf&, RefReadInParams const&, bool, BitpairOutFileBuf*)
RefRecord fastaRefReadSize(FileBuf& in,
                           const RefReadInParams& rparms,
                           bool first,
                           BitpairOutFileBuf* bpout)
{
	int c;
	static int lastc = '>'; // last character seen

	// RefRecord params
	TIndexOffU len = 0; // 'len' counts toward total length
	// 'off' counts number of ambiguous characters before first
	// unambiguous character
	size_t off = 0;

	// Pick off the first carat and any preceding whitespace
	if(first) {
		assert(!in.eof());
		lastc = '>';
		c = in.getPastWhitespace();
		if(in.eof()) {
			// Got eof right away; emit warning
			cerr << "Warning: Empty input file" << endl;
			lastc = -1;
			return RefRecord(0, 0, true);
		}
		assert(c == '>');
	}

	first = true;
	// Skip to the end of the id line; if the next line is either
	// another id line or a comment line, keep skipping
	if(lastc == '>') {
		// Skip to the end of the name line
		do {
			if((c = in.getPastNewline()) == -1) {
				// No more input
				cerr << "Warning: Encountered empty reference sequence" << endl;
				lastc = -1;
				return RefRecord(0, 0, true);
			}
			if(c == '>') {
				cerr << "Warning: Encountered empty reference sequence" << endl;
			}
			// continue until a non-name, non-comment line
		} while (c == '>');
	} else {
		first = false; // not the first in a sequence
		off = 1; // The gap has already been consumed, so count it
		if((c = in.get()) == -1) {
			// Don't emit a warning, since this might legitimately be
			// a gap on the end of the final sequence in the file
			lastc = -1;
			return RefRecord((TIndexOffU)off, (TIndexOffU)len, first);
		}
	}

	// Now skip to the first DNA character, counting gap characters
	// as we go
	while(true) {
		int cat = dna4Cat[c];
		if(rparms.nsToAs && cat == 2) c = 'A';
		if(cat == 1) {
			// This is a DNA character
			break; // to read-in loop
                } else if (cat == 2) {
			off++; // skip over gap character and increment
                } else if (c == '>') {
                  if (off > 0 && lastc == '>') {
                    cerr << "Warning: Encountered reference sequence with only "
                            "gaps"
                         << endl;
                  } else if (lastc == '>') {
                    cerr << "Warning: Encountered empty reference sequence"
                         << endl;
                  }
                  lastc = '>';
                  return RefRecord((TIndexOffU)off, 0, first);
                }
                c = in.get();
		if(c == -1) {
			// End-of-file
			if(off > 0 && lastc == '>') {
				cerr << "Warning: Encountered reference sequence with only gaps" << endl;
			} else if(lastc == '>') {
				cerr << "Warning: Encountered empty reference sequence" << endl;
			}
			lastc = -1;
			return RefRecord((TIndexOffU)off, 0, first);
		}
	}
	assert_eq(1, dna4Cat[c]); // C must be unambiguous base

	// in now points just past the first character of a sequence
	// line, and c holds the first character
	while(c != -1 && c != '>') {
		if(rparms.nsToAs && dna4Cat[c] == 2) c = 'A';
		uint8_t cat = dna4Cat[c];
		int cc = toupper(c);
		if(rparms.bisulfite && cc == 'C') c = cc = 'T';
		if(cat == 1) {
			// It's a DNA character
			assert(cc == 'A' || cc == 'C' || cc == 'G' || cc == 'T');
			// Consume it
			len++;
			// Output it
			if(bpout != NULL) {
				// output nucleotide
				bpout->write(asc2dna[c]);
			}
		} else if(cat == 2) {
			// It's an N or a gap
			lastc = c;
			assert(cc != 'A' && cc != 'C' && cc != 'G' && cc != 'T');
			return RefRecord((TIndexOffU)off, (TIndexOffU)len, first);
		} else {
			// Not DNA and not a gap, ignore it
#ifndef NDEBUG
			if(!isspace(c)) {
				cerr << "Unexpected character in sequence: ";
				if(isprint(c)) {
					cerr << ((char)c) << endl;
				} else {
					cerr << "(" << c << ")" << endl;
				}
			}
#endif
		}
		c = in.get();
	}
	lastc = c;
	return RefRecord((TIndexOffU)off, (TIndexOffU)len, first);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
testl %ecx, %ecx
je 0x29e4f
movq 0x20(%r15), %rax
cmpq 0x28(%r15), %rax
jne 0x29de9
testb $0x1, 0x30(%r15)
jne 0x2a3bc
movl $0x3e, 0xe73d(%rip)     # 0x38530
movq %r15, %rdi
callq 0x2b558
movq 0x20(%r15), %rcx
cmpq 0x28(%r15), %rcx
jne 0x29e46
testb $0x1, 0x30(%r15)
je 0x29e46
movq 0xd1dd(%rip), %r14      # 0x36ff0
leaq 0x729b(%rip), %rsi      # 0x310b5
movl $0x19, %edx
movq %r14, %rdi
callq 0x43b0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r14, %rdi
jmp 0x29f0d
cmpl $0x3e, %eax
jne 0x2a3db
movl 0xe6db(%rip), %eax      # 0x38530
movl %eax, 0x24(%rsp)
cmpl $0x3e, %eax
jne 0x29eb3
movq 0xd18b(%rip), %r13      # 0x36ff0
leaq 0x726c(%rip), %r14      # 0x310d8
movq %r15, %rdi
callq 0x2b582
cmpl $0x3e, %eax
jne 0x29ed7
movl $0x2d, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x43b0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
jmp 0x29e6c
movq %r15, %rdi
callq 0x213fa
cmpl $-0x1, %eax
je 0x2a35e
movl %eax, %ebp
movq %r15, 0x38(%rsp)
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x29f41
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x29f33
leaq 0x71f3(%rip), %rsi      # 0x310d8
movl $0x2d, %edx
movq %r13, %rdi
callq 0x43b0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl $0xffffffff, 0xe60c(%rip) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movb $0x1, 0x10(%rbx)
jmp 0x2a37b
movq %r15, 0x38(%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x3e, 0x24(%rsp)
sete 0x18(%rsp)
movq (%rbx), %r15
movq 0x8(%rbx), %r13
movq %rbx, 0x28(%rsp)
movb 0x10(%rbx), %bl
movl $0x41, %r14d
movslq %ebp, %rax
leaq 0xe5d6(%rip), %rcx      # 0x38540
movb (%rcx,%rax), %cl
cmpb $0x0, 0x4(%r12)
movl %eax, %ebp
cmovnel %r14d, %ebp
cmpb $0x2, %cl
cmovnel %eax, %ebp
movl $0x5, %eax
cmpb $0x1, %cl
je 0x2a0b9
cmpb $0x2, %cl
jne 0x29f99
incq 0x10(%rsp)
jmp 0x29fd9
cmpl $0x3e, %ebp
jne 0x29fd9
cmpq $0x0, 0x10(%rsp)
setne %cl
movl 0xe583(%rip), %eax      # 0x38530
cmpl $0x3e, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2a051
movl $0x36, %edx
movq 0xd026(%rip), %rbx      # 0x36ff0
movq %rbx, %rdi
leaq 0x7132(%rip), %rsi      # 0x31106
jmp 0x2a071
movq 0x38(%rsp), %rdi
callq 0x213fa
cmpl $-0x1, %eax
je 0x29ff1
movl %eax, %ebp
xorl %eax, %eax
jmp 0x2a0b9
cmpq $0x0, 0x10(%rsp)
setne %cl
movl 0xe530(%rip), %eax      # 0x38530
cmpl $0x3e, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2a025
movl $0x36, %edx
movq 0xcfd7(%rip), %rbx      # 0x36ff0
movq %rbx, %rdi
leaq 0x70e3(%rip), %rsi      # 0x31106
jmp 0x2a045
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x3e, %eax
movq 0xcfbc(%rip), %rbx      # 0x36ff0
jne 0x2a0a2
movl $0x2d, %edx
movq %rbx, %rdi
leaq 0x7093(%rip), %rsi      # 0x310d8
callq 0x43b0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2a07b
movl $0x3e, %ebp
cmpl $0x3e, %eax
movq 0xcf90(%rip), %rbx      # 0x36ff0
jne 0x2a0a2
movl $0x2d, %edx
movq %rbx, %rdi
leaq 0x7067(%rip), %rsi      # 0x310d8
callq 0x43b0
movl $0x3e, %ebp
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl %ebp, 0xe488(%rip)      # 0x38530
movl $0x1, %eax
movb 0x18(%rsp), %bl
xorl %r13d, %r13d
movq 0x10(%rsp), %r15
testl %eax, %eax
je 0x29f60
cmpl $0x5, %eax
jne 0x2a315
movq 0x28(%rsp), %rax
movq %r13, 0x8(%rax)
movb %bl, 0x10(%rax)
movq %r15, (%rax)
movslq %ebp, %r15
leaq 0xe45d(%rip), %rcx      # 0x38540
cmpb $0x1, (%rcx,%r15)
jne 0x2a3fa
cmpl $0x3e, 0x24(%rsp)
sete 0xe(%rsp)
movq (%rax), %rdx
movq 0x8(%rax), %rcx
movb 0x10(%rax), %al
movq $0x0, 0x30(%rsp)
movq %r12, 0x18(%rsp)
movq %rdx, %rbx
movq %rcx, %r15
movl %eax, %r14d
cmpl $-0x1, %ebp
je 0x2a329
cmpl $0x3e, %ebp
je 0x2a329
cmpb $0x1, 0x4(%r12)
jne 0x2a14c
movslq %ebp, %rax
leaq 0xe403(%rip), %rcx      # 0x38540
cmpb $0x2, (%rcx,%rax)
movl $0x41, %eax
je 0x2a14a
movl %ebp, %eax
movl %eax, %ebp
movslq %ebp, %rdi
leaq 0xe3ea(%rip), %rax      # 0x38540
movzbl (%rax,%rdi), %r12d
callq 0x4660
cmpl $0x43, %eax
sete %dl
movl $0x54, %r13d
movl $0x54, %ecx
movq 0x18(%rsp), %rsi
testb %dl, 0x5(%rsi)
jne 0x2a180
movl %ebp, %r13d
movl %eax, %ecx
cmpl $0x2, %r12d
je 0x2a1e1
cmpl $0x1, %r12d
movq 0xce5f(%rip), %rbp      # 0x36ff0
jne 0x2a218
addl $-0x41, %ecx
cmpl $0x13, %ecx
ja 0x2a533
movl $0x80045, %eax          # imm = 0x80045
btl %ecx, %eax
jae 0x2a533
incq 0x30(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %r12
je 0x2a2df
movslq %r13d, %rax
leaq 0xe76d(%rip), %rcx      # 0x38940
movzbl (%rcx,%rax), %esi
callq 0x2b5be
jmp 0x2a2df
movl %r13d, 0xe348(%rip)     # 0x38530
xorl %esi, %esi
addl $-0x41, %ecx
cmpl $0x13, %ecx
ja 0x2a26c
movl $0x80045, %eax          # imm = 0x80045
btl %ecx, %eax
movb 0xe(%rsp), %al
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %r12
jae 0x2a2f8
jmp 0x2a38d
movl %r13d, %edi
callq 0x4060
testl %eax, %eax
movq 0x18(%rsp), %r12
jne 0x2a2df
movl $0x22, %edx
movq %rbp, %rdi
leaq 0x6f63(%rip), %rsi      # 0x3119f
callq 0x43b0
movl %r13d, %edi
callq 0x4630
testl %eax, %eax
je 0x2a281
movb %r13b, 0xf(%rsp)
movl $0x1, %edx
movq %rbp, %rdi
leaq 0xf(%rsp), %rsi
callq 0x43b0
movq %rax, %r13
movq (%rax), %rax
jmp 0x2a2bb
movb 0xe(%rsp), %al
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %r12
jmp 0x2a2f8
movl $0x1, %edx
movq %rbp, %rdi
leaq 0x3afc(%rip), %rsi      # 0x2dd8c
callq 0x43b0
movq %rbp, %rdi
movl %r13d, %esi
callq 0x4610
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5063(%rip), %rsi      # 0x2f315
callq 0x43b0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r13, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq 0x38(%rsp), %rdi
callq 0x213fa
movl %eax, %r13d
movb $0x1, %sil
movl %r14d, %eax
movq %r15, %rcx
movq %rbx, %rdx
movl %r13d, %ebp
testb %sil, %sil
jne 0x2a110
movq 0x28(%rsp), %rbx
movq %rcx, 0x8(%rbx)
movb %al, 0x10(%rbx)
movq %rdx, (%rbx)
jmp 0x2a37b
movq 0x28(%rsp), %rax
movq %r13, 0x8(%rax)
movb %bl, 0x10(%rax)
movq %rax, %rbx
movq %r15, (%rax)
jmp 0x2a37b
cmpl $0x3e, 0x24(%rsp)
movq 0x28(%rsp), %rax
movq %r15, 0x8(%rax)
movb %r14b, 0x10(%rax)
movq %rbx, (%rax)
movq %rax, %rbx
movl %ebp, 0xe1e9(%rip)      # 0x38530
movq 0x10(%rsp), %rax
movq %rax, (%rbx)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rbx)
sete 0x10(%rbx)
jmp 0x2a37b
movl $0xffffffff, 0xe1c8(%rip) # imm = 0xFFFFFFFF
movq $0x1, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %rax
movq %r15, 0x8(%rax)
movb %r14b, 0x10(%rax)
movq %rbx, (%rax)
leaq 0x6dca(%rip), %rdi      # 0x3116e
leaq 0x6ca3(%rip), %rsi      # 0x3104e
leaq 0x6ca9(%rip), %rcx      # 0x3105b
movl $0x7a, %edx
callq 0x41c0
leaq 0x6c81(%rip), %rdi      # 0x31044
leaq 0x6c84(%rip), %rsi      # 0x3104e
leaq 0x6c8a(%rip), %rcx      # 0x3105b
movl $0x1a, %edx
callq 0x41c0
leaq 0x6ced(%rip), %rdi      # 0x310cf
leaq 0x6c65(%rip), %rsi      # 0x3104e
leaq 0x6c6b(%rip), %rcx      # 0x3105b
movl $0x23, %edx
callq 0x41c0
movq 0xcbb7(%rip), %rbx      # 0x36fb8
leaq 0x2d2e(%rip), %rsi      # 0x2d136
movq %rbx, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x1, %esi
callq 0x4610
leaq 0x2d28(%rip), %r14      # 0x2d14c
movq %rax, %rdi
movq %r14, %rsi
callq 0x4310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movl $0x1, %esi
callq 0x4610
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x2ce4(%rip), %rsi      # 0x2d151
movq %rax, %rdi
callq 0x4310
leaq 0xe0c4(%rip), %r12      # 0x38540
movzbl (%r12,%r15), %esi
movq %rax, %rdi
callq 0x4500
movq %rax, %rdi
movq %r14, %rsi
callq 0x4310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movzbl (%r12,%r15), %esi
movq %rax, %rdi
callq 0x4500
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x4e43(%rip), %rsi      # 0x2f315
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x6b65(%rip), %r14      # 0x3104e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x421d(%rip), %rsi      # 0x2e718
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x64, %esi
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x40d9(%rip), %rdi      # 0x2e5f8
leaq 0x6b35(%rip), %rcx      # 0x3105b
movq %r14, %rsi
movl $0x64, %edx
callq 0x41c0
movq 0x28(%rsp), %rax
movq %r15, 0x8(%rax)
movb %r14b, 0x10(%rax)
movq %rbx, (%rax)
leaq 0x6bf3(%rip), %rdi      # 0x3113d
leaq 0x6afd(%rip), %rsi      # 0x3104e
leaq 0x6b03(%rip), %rcx      # 0x3105b
movl $0x6f, %edx
callq 0x41c0