// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq %r8, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
testl %ecx, %ecx
je 0x2941b
movq 0x20(%r12), %rax
cmpq 0x28(%r12), %rax
jne 0x293b2
testb $0x1, 0x30(%r12)
jne 0x29884
movl $0x3e, 0xf174(%rip)     # 0x38530
movq %r12, %rdi
callq 0x2a9ee
movq 0x20(%r12), %rcx
cmpq 0x28(%r12), %rcx
jne 0x29412
testb $0x1, 0x30(%r12)
je 0x29412
movq 0xdc11(%rip), %r14      # 0x36ff0
leaq 0x6d5f(%rip), %rsi      # 0x30145
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 0x294d6
cmpl $0x3e, %eax
jne 0x298a3
movl 0xf10e(%rip), %r15d     # 0x38530
cmpl $0x3e, %r15d
jne 0x2947d
movq 0xdbc1(%rip), %r13      # 0x36ff0
leaq 0x6d32(%rip), %r14      # 0x30168
movq %r12, %rdi
callq 0x2aa18
cmpl $0x3e, %eax
jne 0x294a0
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 0x29436
movq %r12, %rdi
callq 0x20ecc
cmpl $-0x1, %eax
je 0x29579
movl %eax, %ebp
movl %r15d, (%rsp)
movq %rbx, 0x8(%rsp)
movl $0x1, %ebx
jmp 0x29507
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x294fc
leaq 0x6cba(%rip), %rsi      # 0x30168
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, 0xf043(%rip) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movb $0x1, 0x10(%rbx)
jmp 0x2984c
movl %r15d, (%rsp)
movq %rbx, 0x8(%rsp)
xorl %ebx, %ebx
leaq 0xf032(%rip), %r15      # 0x38540
movslq %ebp, %r13
movzbl (%r15,%r13), %eax
cmpl $0x2, %eax
je 0x2952a
cmpl $0x1, %eax
je 0x2959b
cmpl $0x3e, %ebp
jne 0x2952d
jmp 0x2971c
incq %rbx
movq %r12, %rdi
callq 0x20ecc
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x2950e
testq %rbx, %rbx
setne %cl
movl 0xefe8(%rip), %eax      # 0x38530
cmpl $0x3e, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x29759
movq 0xda90(%rip), %rdi      # 0x36ff0
leaq 0x6c2f(%rip), %rsi      # 0x30196
movl $0x36, %edx
callq 0x43b0
movl (%rsp), %ebp
jmp 0x29779
movl $0xffffffff, 0xefad(%rip) # imm = 0xFFFFFFFF
movq $0x1, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
jmp 0x2984c
cmpb $0x1, (%r15,%r13)
jne 0x298e1
movq $0x0, 0x10(%rsp)
cmpl $-0x1, %ebp
je 0x297b6
cmpl $0x3e, %ebp
je 0x297b6
movq 0x18(%rsp), %rax
cmpb $0x1, 0x4(%rax)
jne 0x295df
movslq %ebp, %rax
cmpb $0x2, (%r15,%rax)
movl $0x41, %eax
je 0x295dd
movl %ebp, %eax
movl %eax, %ebp
movslq %ebp, %rdi
movzbl (%r15,%rdi), %r14d
callq 0x4660
cmpl $0x43, %eax
sete %dl
movl $0x54, %r13d
movl $0x54, %ecx
movq 0x18(%rsp), %rsi
testb %dl, 0x5(%rsi)
jne 0x2960c
movl %ebp, %r13d
movl %eax, %ecx
cmpl $0x1, %r14d
je 0x29672
cmpl $0x2, %r14d
movq 0xd9d3(%rip), %r14      # 0x36ff0
je 0x2985e
movl %r13d, %edi
callq 0x4060
testl %eax, %eax
jne 0x2970d
movl $0x22, %edx
movq %r14, %rdi
leaq 0x6bed(%rip), %rsi      # 0x3022f
callq 0x43b0
movl %r13d, %edi
callq 0x4630
testl %eax, %eax
je 0x296b0
movb %r13b, 0x7(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x7(%rsp), %rsi
callq 0x43b0
movq %rax, %r14
movq (%rax), %rax
jmp 0x296e9
addl $-0x41, %ecx
cmpl $0x13, %ecx
ja 0x298c2
movl $0x80045, %eax          # imm = 0x80045
btl %ecx, %eax
jae 0x298c2
incq 0x10(%rsp)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2970d
movslq %r13d, %rax
leaq 0xf29b(%rip), %rcx      # 0x38940
movzbl (%rcx,%rax), %esi
callq 0x2aa54
jmp 0x2970d
movl $0x1, %edx
movq %r14, %rdi
leaq 0x375d(%rip), %rsi      # 0x2ce1c
callq 0x43b0
movq %r14, %rdi
movl %r13d, %esi
callq 0x4610
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4cc4(%rip), %rsi      # 0x2e3a5
callq 0x43b0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %r12, %rdi
callq 0x20ecc
movl %eax, %ebp
jmp 0x295af
testq %rbx, %rbx
setne %cl
movl 0xee08(%rip), %eax      # 0x38530
cmpl $0x3e, %eax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x297da
movq 0xd8b0(%rip), %rdi      # 0x36ff0
leaq 0x6a4f(%rip), %rsi      # 0x30196
movl $0x36, %edx
callq 0x43b0
movl (%rsp), %ebp
jmp 0x297fa
cmpl $0x3e, %eax
movl (%rsp), %ebp
jne 0x297a7
movq 0xd888(%rip), %rdi      # 0x36ff0
leaq 0x69f9(%rip), %rsi      # 0x30168
movl $0x2d, %edx
callq 0x43b0
movq 0xd870(%rip), %r14      # 0x36ff0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
cmpl $0x3e, %ebp
movl $0xffffffff, 0xed7c(%rip) # imm = 0xFFFFFFFF
jmp 0x29835
cmpl $0x3e, (%rsp)
movl %ebp, 0xed70(%rip)      # 0x38530
movq 0x8(%rsp), %rax
movq %rbx, (%rax)
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
sete 0x10(%rbx)
jmp 0x2984c
cmpl $0x3e, %eax
movl (%rsp), %ebp
jne 0x29828
movq 0xd807(%rip), %rdi      # 0x36ff0
leaq 0x6978(%rip), %rsi      # 0x30168
movl $0x2d, %edx
callq 0x43b0
movq 0xd7ef(%rip), %r14      # 0x36ff0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
cmpl $0x3e, %ebp
movl $0x3e, 0xecfb(%rip)     # 0x38530
movq 0x8(%rsp), %rax
movq %rbx, (%rax)
movq %rax, %rbx
movq $0x0, 0x8(%rax)
sete 0x10(%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, 0xeccb(%rip)     # 0x38530
addl $-0x41, %ecx
cmpl $0x13, %ecx
ja 0x2987b
movl $0x80045, %eax          # imm = 0x80045
btl %ecx, %eax
jb 0x29a13
cmpl $0x3e, (%rsp)
jmp 0x297c0
leaq 0x6849(%rip), %rdi      # 0x300d4
leaq 0x684c(%rip), %rsi      # 0x300de
leaq 0x6852(%rip), %rcx      # 0x300eb
movl $0x1a, %edx
callq 0x41c0
leaq 0x68b5(%rip), %rdi      # 0x3015f
leaq 0x682d(%rip), %rsi      # 0x300de
leaq 0x6833(%rip), %rcx      # 0x300eb
movl $0x23, %edx
callq 0x41c0
leaq 0x6904(%rip), %rdi      # 0x301cd
leaq 0x680e(%rip), %rsi      # 0x300de
leaq 0x6814(%rip), %rcx      # 0x300eb
movl $0x6f, %edx
callq 0x41c0
movq 0xd6d0(%rip), %rbx      # 0x36fb8
leaq 0x28d7(%rip), %rsi      # 0x2c1c6
movq %rbx, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x1, %esi
callq 0x4610
leaq 0x28d1(%rip), %r14      # 0x2c1dc
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 0x288d(%rip), %rsi      # 0x2c1e1
movq %rax, %rdi
callq 0x4310
movzbl (%r15,%r13), %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 (%r15,%r13), %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 0x49f3(%rip), %rsi      # 0x2e3a5
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x6715(%rip), %r14      # 0x300de
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x3dcd(%rip), %rsi      # 0x2d7a8
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x64, %esi
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x3c89(%rip), %rdi      # 0x2d688
leaq 0x66e5(%rip), %rcx      # 0x300eb
movq %r14, %rsi
movl $0x64, %edx
callq 0x41c0
leaq 0x67e4(%rip), %rdi      # 0x301fe
leaq 0x66bd(%rip), %rsi      # 0x300de
leaq 0x66c3(%rip), %rcx      # 0x300eb
movl $0x7a, %edx
callq 0x41c0