// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movl 0xc(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x80(%rbp), %rdi
movl -0x1c(%rbp), %eax
movq %rax, -0x88(%rbp)
addq $0x10, %rdi
callq 0x29fa0
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0x7ef63
movq -0x80(%rbp), %rdi
addq $0x30, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x29fc0
cmpq $0x0, (%rax)
jne 0x7ed46
movq -0x80(%rbp), %rdi
addq $0x10, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x29fc0
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq (%rdi), %rax
movl $0x1, %ecx
movl %ecx, %edx
callq *0x10(%rax)
movq %rax, -0x24(%rbp)
movb -0x24(%rbp), %al
andb $0x1, %al
movb %al, -0x25(%rbp)
testb $0x1, -0x25(%rbp)
jne 0x7ed2c
cmpl $0x0, -0x20(%rbp)
jne 0x7ed2c
movq -0x80(%rbp), %rsi
addq $0x8, %rsi
leaq -0x30(%rbp), %rdi
callq 0x2f3b0
movq -0x80(%rbp), %rcx
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jbe 0x7ed14
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x80(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x1c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2f3e0
jmp 0x7ec61
leaq -0x24(%rbp), %rsi
addq $0x4, %rsi
leaq -0x25(%rbp), %rdi
callq 0x82b50
movq %rax, -0x8(%rbp)
jmp 0x7ef7f
leaq -0x38(%rbp), %rdi
callq 0x82ad0
leaq -0x40(%rbp), %rdi
callq 0x82ad0
movq -0x80(%rbp), %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %rdi
callq 0x2f3b0
movq -0x80(%rbp), %rdi
addq $0x10, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x29fc0
movq %rax, -0x90(%rbp)
jmp 0x7ed84
movq -0x90(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
movl $0x1, %edx
xorl %ecx, %ecx
callq *%rax
movq %rax, -0x98(%rbp)
jmp 0x7edab
movq -0x98(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x82af0
movq -0x80(%rbp), %rdi
addq $0x30, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x29fc0
movq %rax, -0xa0(%rbp)
jmp 0x7edde
movq -0xa0(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movq %rax, -0xa8(%rbp)
jmp 0x7ee02
movq -0xa8(%rbp), %rax
movq %rax, -0x64(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x82af0
leaq -0x48(%rbp), %rdi
callq 0x2f3e0
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x7ee99
movq 0x291be(%rip), %rdi     # 0xa7ff0
leaq 0xf3ff(%rip), %rsi      # 0x8e238
callq 0xa5d0
movq %rax, %rdi
leaq 0xf41e(%rip), %rsi      # 0x8e266
callq 0xa5d0
movq %rax, %rdi
movq 0x29111(%rip), %rsi     # 0xa7f68
callq 0xa640
movl $0x4, %edi
callq 0xa290
movq %rax, %rdi
movl $0x1, (%rdi)
movq 0x290da(%rip), %rsi     # 0xa7f50
xorl %eax, %eax
movl %eax, %edx
callq 0xab10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2f3e0
jmp 0x7ef8c
cmpl $0x0, -0x34(%rbp)
jne 0x7eeec
cmpl $0x0, -0x3c(%rbp)
jne 0x7eeec
movq -0x80(%rbp), %rsi
addq $0x8, %rsi
leaq -0x70(%rbp), %rdi
callq 0x2f3b0
movq -0x80(%rbp), %rcx
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jbe 0x7eed4
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x80(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x1c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2f3e0
jmp 0x7ec61
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x7ef48
movq 0x290f5(%rip), %rdi     # 0xa7ff0
leaq 0xf383(%rip), %rsi      # 0x8e285
callq 0xa5d0
movq %rax, %rdi
leaq 0xf3a2(%rip), %rsi      # 0x8e2b3
callq 0xa5d0
movq %rax, %rdi
movq 0x29048(%rip), %rsi     # 0xa7f68
callq 0xa640
movl $0x4, %edi
callq 0xa290
movq %rax, %rdi
movl $0x1, (%rdi)
movq 0x29011(%rip), %rsi     # 0xa7f50
xorl %eax, %eax
movl %eax, %edx
callq 0xab10
jmp 0x7ef4a
jmp 0x7ef4c
leaq -0x38(%rbp), %rdi
leaq -0x38(%rbp), %rsi
addq $0x4, %rsi
callq 0x82b50
movq %rax, -0x8(%rbp)
jmp 0x7ef7f
movb $0x1, -0x71(%rbp)
movl $0x0, -0x78(%rbp)
leaq -0x71(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x82b20
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0xab60
nopw %cs:(%rax,%rax)