// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18(%rsp)
movq %rcx, %rbx
movq %rdx, 0x8(%rsp)
movq %rdi, %r12
testl %esi, %esi
movq %rcx, 0x20(%rsp)
je 0xd05c
movq %r12, %rdi
callq 0x1714a
cmpl $0x3e, %eax
jne 0xd2fa
movl $0x3e, 0x2e6ff(%rip)    # 0x3b750
movl (%rbx), %r14d
movl $0x3e, %r15d
jmp 0xd076
movl 0x2e6ed(%rip), %r15d    # 0x3b750
movl (%rbx), %r14d
cmpl $0x3e, %r15d
je 0xd076
cmpl $0x23, %r15d
jne 0xd10b
cmpl $0x23, %r15d
jne 0xd091
movq %r12, %rdi
callq 0x17174
movl %eax, %r15d
cmpl $-0x1, %eax
jne 0xd076
jmp 0xd2e5
movq %r12, %rdi
callq 0x171b0
movl %eax, %r15d
cmpl $-0x1, %eax
je 0xd0f1
cmpl $0xd, %r15d
je 0xd0d1
cmpl $0xa, %r15d
je 0xd0d1
testq %rbp, %rbp
je 0xd091
movsbl %r15b, %esi
movq %rbp, %rdi
callq 0x52b0
jmp 0xd091
cmpl $0xa, %r15d
jne 0xd0eb
movq %r12, %rdi
callq 0x171b0
movl %eax, %r15d
cmpl $0xc, %r15d
jle 0xd0c0
cmpl $0xd, %r15d
je 0xd0c6
cmpl $0x23, %r15d
je 0xd076
cmpl $0x3e, %r15d
je 0xd076
jmp 0xd103
cmpl $-0x1, %r15d
jne 0xd103
movb $0x1, %dl
xorl %r8d, %r8d
xorl %r10d, %r10d
movq 0x8(%rsp), %rbx
jmp 0xd285
movb $0x1, %al
movl %eax, 0x4(%rsp)
jmp 0xd113
movl $0x0, 0x4(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rbx
cmpb $0x0, 0x4(%rbx)
movslq %r15d, %rax
movl %eax, %r13d
movl $0x41, %ecx
cmovnel %ecx, %r13d
leaq 0x30085(%rip), %rcx     # 0x3d1c0
movb (%rcx,%rax), %bpl
cmpb $0x2, %bpl
cmovnel %eax, %r13d
movl %r13d, %edi
callq 0x56c0
cmpl $0x43, %eax
movl %r13d, %r15d
movl $0x54, %eax
cmovel %eax, %r15d
cmpb $0x0, 0x5(%rbx)
cmovel %r13d, %r15d
cmpb $0x1, %bpl
je 0xd19e
cmpb $0x2, %bpl
jne 0xd179
incq 0x10(%rsp)
jmp 0xd183
cmpl $0x3e, %r15d
je 0xd26e
movq %r12, %rdi
callq 0x171b0
movl %eax, %r15d
cmpl $-0x1, %eax
jne 0xd121
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0xd274
xorl %ebp, %ebp
leaq 0x30619(%rip), %r13     # 0x3d7c0
movq 0x8(%rsp), %rbx
movslq %r15d, %rax
cmpb $0x1, (%r13,%rax)
jne 0xd1d7
incq %rbp
leaq 0x303ff(%rip), %rcx     # 0x3d5c0
movb (%rcx,%rax), %al
movq 0x20(%rsp), %rsi
movl (%rsi), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movq 0x8(%rbx), %rdx
movb %al, (%rdx,%rcx)
movq %r12, %rdi
callq 0x171b0
movq 0x18(%rsp), %rcx
cmpb $0x1, 0x4(%rcx)
jne 0xd200
movslq %eax, %rcx
movl $0x41, %r15d
leaq 0x2ffc6(%rip), %rdx     # 0x3d1c0
cmpb $0x2, (%rdx,%rcx)
je 0xd221
movl %eax, %ecx
incl %ecx
cmpl $0x3f, %ecx
ja 0xd21e
movabsq $-0x7fffffefffffffff, %rdx # imm = 0x8000001000000001
btq %rcx, %rdx
movl %eax, %r15d
jae 0xd221
jmp 0xd25d
movl %eax, %r15d
movslq %r15d, %rax
leaq 0x2ff95(%rip), %rcx     # 0x3d1c0
cmpb $0x2, (%rcx,%rax)
je 0xd260
movq 0x18(%rsp), %rax
cmpb $0x1, 0x5(%rax)
jne 0xd1ac
movl %r15d, %edi
callq 0x56c0
movl $0x54, %ecx
cmpl $0x43, %eax
je 0xd255
movl %r15d, %ecx
movl %ecx, %r15d
jmp 0xd1ac
movl %eax, %r15d
movq 0x10(%rsp), %r8
movl 0x4(%rsp), %edx
movq %rbp, %r10
jmp 0xd285
movl $0x3e, %r15d
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r8
movl 0x4(%rsp), %edx
xorl %r10d, %r10d
movl %r15d, 0x2e4c4(%rip)    # 0x3b750
movq 0x18(%rsp), %rax
cmpl $0x2, (%rax)
jne 0xd2cc
cmpq $0x2, %r10
jb 0xd2cc
movq %r10, %rax
shrq %rax
leaq (%r10,%r14), %rcx
decq %rcx
movq 0x8(%rbx), %r9
movb (%r9,%r14), %sil
movb (%r9,%rcx), %dil
movb %dil, (%r9,%r14)
movq 0x8(%rbx), %rdi
movb %sil, (%rdi,%rcx)
decq %rcx
incq %r14
decq %rax
jne 0xd2a9
shlq $0x20, %r10
movl %r8d, %eax
orq %r10, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %dl
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movq 0x8(%rsp), %rbx
xorl %r8d, %r8d
jmp 0xd285
movq 0x2dcef(%rip), %rdi     # 0x3aff0
leaq 0x2324b(%rip), %rsi     # 0x30553
callq 0x5340
movq %rax, %rdi
callq 0x5170
movl $0x4, %edi
callq 0x5180
movl $0x1, (%rax)
movq 0x2dc1c(%rip), %rsi     # 0x3af48
movq %rax, %rdi
xorl %edx, %edx
callq 0x5630