// File: /workspace/github_cpp_makefile_star2_O1/BenLangmead[P]bowtie/pat.cpp
// Function: DualPatternComposer::nextBatch(PerThreadReadBuf&)
pair<bool, int> DualPatternComposer::nextBatch(PerThreadReadBuf& pt) {
	// 'cur' indexes the current pair of PatternSources
	uint32_t cur = cur_;
	while(cur < srca_.size()) {
		if(srcb_[cur] == NULL) {
			pair<bool, int> res = srca_[cur]->nextBatch(
				pt,
				true,  // batch A (or pairs)
				true); // grab lock below
			bool done = res.first;
			if(!done && res.second == 0) {
				ThreadSafe ts(&mutex_m);
				if(cur + 1 > cur_) cur_++;
				cur = cur_; // Move on to next PatternSource
				continue; // on to next pair of PatternSources
			}
			return make_pair(done, res.second);
		} else {
			pair<bool, int> resa, resb;
			// Lock to ensure that this thread gets parallel reads
			// in the two mate files
			{
				ThreadSafe ts(&mutex_m);
				resa = srca_[cur]->nextBatch(
					pt,
					true,   // batch A
					false); // don't grab lock below
				resb = srcb_[cur]->nextBatch(
					pt,
					false,  // batch B
					false); // don't grab lock below
				assert_eq(srca_[cur]->readCount(),
					  srcb_[cur]->readCount());
			}
			if(resa.second < resb.second) {
				cerr << "Error, fewer reads in file specified with -1 "
					 << "than in file specified with -2" << endl;
				throw 1;
			} else if(resa.second == 0 && resb.second == 0) {
				ThreadSafe ts(&mutex_m);
				if(cur + 1 > cur_) {
					cur_++;
				}
				cur = cur_; // Move on to next PatternSource
				continue; // on to next pair of PatternSources
			} else if(resb.second < resa.second) {
				cerr << "Error, fewer reads in file specified with -2 "
					 << "than in file specified with -1" << endl;
				throw 1;
			}
			assert_eq(resa.first, resb.first);
			assert_eq(resa.second, resb.second);
			return make_pair(resa.first, resa.second);
		}
	}
	assert_leq(cur, srca_.size());
	return make_pair(true, 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0xc(%rdi), %ebp
cmpq %rbp, 0x28(%rdi)
jbe 0x4c549
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x8(%rdi), %rax
movq %rax, 0x8(%rsp)
movl %ebp, %r12d
movq 0x38(%r15), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0x4c4a2
movq 0x8(%rsp), %rdi
callq 0x4bff0
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq %rax, %r13
movq 0x38(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq %rax, %rbp
movq 0x8(%rsp), %rdi
callq 0x4c02c
movq %r13, %rax
shrq $0x20, %rax
shrq $0x20, %rbp
cmpl %ebp, %eax
jl 0x4c567
movl %ebp, %r14d
orl %eax, %r14d
je 0x4c4e5
cmpl %eax, %ebp
jl 0x4c583
movabsq $-0xffffff01, %rax      # imm = 0xFFFFFFFF000000FF
andq %rax, %r13
movq %r13, 0x10(%rsp)
jmp 0x4c50a
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq *0x10(%rax)
movq %rax, %rcx
shrq $0x20, %rcx
setne %bpl
orb %al, %bpl
testb $0x1, %bpl
je 0x4c511
movabsq $-0xffffff01, %rcx      # imm = 0xFFFFFFFF000000FF
andq %rcx, %rax
movq %rax, 0x10(%rsp)
jmp 0x4c536
movq 0x8(%rsp), %rdi
callq 0x4bff0
incl %r12d
cmpl 0xc(%r15), %r12d
jbe 0x4c4fc
incl 0xc(%r15)
movl 0xc(%r15), %r12d
movq 0x8(%rsp), %rdi
callq 0x4c02c
testl %r14d, %r14d
je 0x4c53c
jmp 0x4c553
movq 0x8(%rsp), %rdi
callq 0x4bff0
incl %r12d
cmpl 0xc(%r15), %r12d
jbe 0x4c528
incl 0xc(%r15)
movl 0xc(%r15), %r12d
movq 0x8(%rsp), %rdi
callq 0x4c02c
testb $0x1, %bpl
jne 0x4c553
movl %r12d, %ebp
cmpq %rbp, 0x28(%r15)
ja 0x4c419
movl $0x1, %eax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1ea82(%rip), %rdi     # 0x6aff0
leaq 0xb97d(%rip), %rsi      # 0x57ef2
callq 0x9490
leaq 0xb99f(%rip), %rsi      # 0x57f20
jmp 0x4c59d
movq 0x1ea66(%rip), %rdi     # 0x6aff0
leaq 0xb9ae(%rip), %rsi      # 0x57f3f
callq 0x9490
leaq 0xb9d0(%rip), %rsi      # 0x57f6d
movq %rax, %rdi
callq 0x9490
movq %rax, %rdi
callq 0x91f0
movl $0x4, %edi
callq 0x9200
movl $0x1, (%rax)
movq 0x1e974(%rip), %rsi     # 0x6af38
movq %rax, %rdi
xorl %edx, %edx
callq 0x98f0
jmp 0x4c5eb
jmp 0x4c5eb
jmp 0x4c5eb
jmp 0x4c5d6
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x4c02c
movq %r14, %rdi
callq 0x9930
movq %rax, %rdi
callq 0x1b23d
nop