// File: /workspace/github_cpp_makefile_star2_O1/BenLangmead[P]bowtie/./ref_read.h
// Function: RefRecord fastaRefReadAppend<SString<char>>(FileBuf&, bool, SString<char>&, unsigned int&, RefReadInParams&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
static RefRecord fastaRefReadAppend(FileBuf& in,
                                    bool first,
                                    TStr& dst,
				    TIndexOffU& dstoff,
                                    RefReadInParams& rparms,
                                    string* name = NULL)
{
	int c;
	static int lastc = '>';
	if(first) {
		c = in.getPastWhitespace();
		if(c != '>') {
			cerr << "Reference file does not seem to be a FASTA file" << endl;
			throw 1;
		}
		lastc = c;
	}
	assert_neq(-1, lastc);

	// RefRecord params
	size_t len = 0;
	size_t off = 0;
	first = true;

	size_t ilen = dstoff;

	// Chew up the id line; if the next line is either
	// another id line or a comment line, keep chewing
	c = lastc;
	if(c == '>' || c == '#') {
		do {
			while (c == '#') {
				if((c = in.getPastNewline()) == -1) {
					lastc = -1;
					goto bail;
				}
			}
			assert_eq('>', c);
			while(true) {
				c = in.get();
				if(c == -1) {
					lastc = -1;
					goto bail;
				}
				if(c == '\n' || c == '\r') {
					while(c == '\r' || c == '\n') c = in.get();
					if(c == -1) {
						lastc = -1;
						goto bail;
					}
					break;
				}
				if (name) name->push_back(c);
			}
			// c holds the first character on the line after the name
			// line
		} while (c == '>' || c == '#');
	} else {
		ASSERT_ONLY(int cc = toupper(c));
		assert(cc != 'A' && cc != 'C' && cc != 'G' && cc != 'T');
		first = false;
	}

	// Skip over an initial stretch of gaps or ambiguous characters.
	while(true) {
		int cat = dna4Cat[c];
		if(rparms.nsToAs && cat == 2) {
			c = 'A';
		}
		int cc = toupper(c);
		if(rparms.bisulfite && cc == 'C') c = cc = 'T';
		if(cat == 1) {
			break; // to read-in loop
		} else if(cat == 2) {
			off++; // skip it
		} else if(c == '>') {
			lastc = '>';
			goto bail;
		}
		c = in.get();
		if(c == -1) {
			lastc = -1;
			goto bail;
		}
	}
	assert_eq(1, dna4Cat[c]);

	// in now points just past the first character of a sequence
	// line, and c holds the first character
	while(true) {
		// Note: can't have a comment in the middle of a sequence,
		// though a comment can end a sequence
		int cat = asc2dnacat[c];
		assert_neq(2, cat);
		if(cat == 1) {
			// Consume it
			len++;
			// Add it to referenece buffer
			dst.set(asc2dna[c], dstoff++);
			assert_lt((int)dst[dstoff-1], 4);
		}
		c = in.get();
		if(rparms.nsToAs && dna4Cat[c] == 2) c = 'A';
		if (c == -1 || c == '>' || c == '#' || dna4Cat[c] == 2) {
			lastc = c;
			break;
		}
		if(rparms.bisulfite && toupper(c) == 'C') c = 'T';
	}

  bail:
	// Optionally reverse the portion that we just appended.
	// ilen = length of buffer before this last sequence was appended.
	if(rparms.reverse == REF_READ_REVERSE_EACH) {
		// Find limits of the portion we just appended
		dst.reverseWindow(ilen, len);
	}
	return RefRecord((TIndexOffU)off, (TIndexOffU)len, first);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbp
movq %r8, %r14
movq %rcx, 0x20(%rsp)
movq %rdx, %rbx
movq %rdi, %r12
testl %esi, %esi
je 0xd103
movq %r12, %rdi
callq 0x173b8
cmpl $0x3e, %eax
jne 0xd3a5
movl $0x3e, 0x2e65d(%rip)    # 0x3b760
movq %rbx, 0x18(%rsp)
movq 0x20(%rsp), %rax
movl (%rax), %ebx
movl 0x2e64a(%rip), %r15d    # 0x3b760
cmpl $0x3e, %r15d
je 0xd122
cmpl $0x23, %r15d
jne 0xd193
cmpl $0x23, %r15d
jne 0xd13a
movq %r12, %rdi
callq 0x173e2
movl %eax, %r15d
cmpl $-0x1, %eax
jne 0xd122
jmp 0xd1a3
movq %r12, %rdi
callq 0x1741e
cmpl $-0x1, %eax
je 0xd1a3
movl %eax, %r15d
cmpl $0xd, %eax
je 0xd179
cmpl $0xa, %r15d
je 0xd179
testq %rbp, %rbp
je 0xd13a
movsbl %r15b, %esi
movq %rbp, %rdi
callq 0x52c0
jmp 0xd13a
cmpl $0xa, %r15d
jne 0xd19d
movq %r12, %rdi
callq 0x1741e
movl %eax, %r15d
cmpl $0xc, %r15d
jle 0xd168
cmpl $0xd, %r15d
je 0xd16e
cmpl $0x23, %r15d
je 0xd122
cmpl $0x3e, %r15d
je 0xd122
jmp 0xd1ba
movl $0x0, 0xc(%rsp)
jmp 0xd1c0
cmpl $-0x1, %r15d
jne 0xd1ba
movl $0xffffffff, 0x2e5b3(%rip) # imm = 0xFFFFFFFF
movb $0x1, %dl
xorl %r10d, %r10d
xorl %r13d, %r13d
jmp 0xd347
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
movslq %r15d, %r13
cmpb $0x0, 0x4(%r14)
leaq 0x2fff8(%rip), %rax     # 0x3d1d0
movb (%rax,%r13), %bpl
movl $0x41, %eax
cmovnel %eax, %r13d
cmpb $0x2, %bpl
je 0xd1ee
movl %r15d, %r13d
movl %r13d, %edi
callq 0x56e0
movl $0x54, %ecx
cmpl $0x43, %eax
je 0xd203
movl %r13d, %ecx
cmpb $0x0, 0x5(%r14)
cmovnel %ecx, %r13d
movl $0xc, %eax
cmpb $0x1, %bpl
jne 0xd21c
movl %r13d, %r15d
jmp 0xd25b
cmpb $0x2, %bpl
jne 0xd229
incq 0x10(%rsp)
jmp 0xd235
movl $0x3e, %r15d
cmpl $0x3e, %r13d
je 0xd24f
movq %r12, %rdi
callq 0x1741e
cmpl $-0x1, %eax
je 0xd249
movl %eax, %r15d
xorl %eax, %eax
jmp 0xd25b
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, 0x2e50a(%rip)    # 0x3b760
movl $0x6, %eax
testl %eax, %eax
je 0xd1c9
cmpl $0x6, %eax
je 0xd33b
cmpl $0xc, %eax
jne 0xd3a1
xorl %r13d, %r13d
movslq %r15d, %rax
leaq 0x3054e(%rip), %rcx     # 0x3d7d0
cmpb $0x1, (%rcx,%rax)
jne 0xd2ad
incq %r13
leaq 0x3033e(%rip), %rcx     # 0x3d5d0
movb (%rcx,%rax), %al
movq 0x20(%rsp), %rsi
movl (%rsi), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %rdx
movb %al, (%rdx,%rcx)
movq %r12, %rdi
callq 0x1741e
movl %eax, %r15d
cmpb $0x1, 0x4(%r14)
jne 0xd2da
movslq %r15d, %rax
leaq 0x2ff07(%rip), %rcx     # 0x3d1d0
cmpb $0x2, (%rcx,%rax)
movl $0x41, %eax
je 0xd2d7
movl %r15d, %eax
movl %eax, %r15d
leal 0x1(%r15), %eax
cmpl $0x3f, %eax
ja 0xd307
movabsq $-0x7fffffefffffffff, %rcx # imm = 0x8000001000000001
btq %rax, %rcx
jae 0xd307
movl %r15d, 0x2e466(%rip)    # 0x3b760
xorl %ebp, %ebp
testb %bpl, %bpl
jne 0xd278
jmp 0xd33e
movslq %r15d, %rax
leaq 0x2febf(%rip), %rcx     # 0x3d1d0
cmpb $0x2, (%rcx,%rax)
je 0xd2f3
movb $0x1, %bpl
cmpb $0x1, 0x5(%r14)
jne 0xd2fc
movl %r15d, %edi
callq 0x56e0
movl $0x54, %ecx
cmpl $0x43, %eax
je 0xd336
movl %r15d, %ecx
movl %ecx, %r15d
jmp 0xd2fc
xorl %r13d, %r13d
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %r10
cmpl $0x2, (%r14)
movq 0x18(%rsp), %r8
jne 0xd388
cmpq $0x2, %r13
jb 0xd388
movq %r13, %rax
shrq %rax
leaq (%rbx,%r13), %rcx
decq %rcx
movq 0x8(%r8), %r9
movb (%r9,%rbx), %sil
movb (%r9,%rcx), %dil
movb %dil, (%r9,%rbx)
movq 0x8(%r8), %rdi
movb %sil, (%rdi,%rcx)
decq %rcx
incq %rbx
decq %rax
jne 0xd365
shlq $0x20, %r13
movl %r10d, %eax
orq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0xd392
movq 0x2dc44(%rip), %rdi     # 0x3aff0
leaq 0x23150(%rip), %rsi     # 0x30503
callq 0x5350
movq %rax, %rdi
callq 0x5170
movl $0x4, %edi
callq 0x5180
movl $0x1, (%rax)
movq 0x2db71(%rip), %rsi     # 0x3af48
movq %rax, %rdi
xorl %edx, %edx
callq 0x5650