// File: BenLangmead[P]bowtie/sam.cpp
// Function: SAMHitSink::reportUnOrMax(PatternSourcePerThread&, EList<Hit, 128>*, unsigned long, bool)
void SAMHitSink::reportUnOrMax(
	PatternSourcePerThread& p,
	EList<Hit>* hs,
	size_t threadId,
	bool un)
{
	if(un) {
		HitSink::reportUnaligned(threadId, p);
		if (noUnal) {
			if (reorder_) {
				ptCounts_[threadId]++;
				maybeFlush(threadId);
			}
			return;
		}
	} else {
		HitSink::reportMaxed(*hs, threadId, p);
	}
	bool paired = !p.bufb().empty();
	assert(paired || p.bufa().mate == 0);
	assert(!paired || p.bufa().mate > 0);
	assert(un || hs->size() > 0);
	assert(!un || hs == NULL || hs->size() == 0);
	size_t hssz = 0;
	if(hs != NULL) hssz = hs->size();
	BTString& o = ptBufs_[threadId];
	for(int i = 0; i < (int)p.bufa().name.length() - (paired ? 2 : 0); i++) {
		if(!noQnameTrunc_ && isspace((int)p.bufa().name[i])) break;
		o << p.bufa().name[i];
	}
	o << '\t'
	  << (SAM_FLAG_UNMAPPED | (paired ? (SAM_FLAG_PAIRED | SAM_FLAG_FIRST_IN_PAIR | SAM_FLAG_MATE_UNMAPPED) : 0)) << "\t*"
	  << "\t0\t0\t*\t*\t0\t0\t";
	for(size_t i = 0; i < p.bufa().patFw.length(); i++) {
		o << (char)p.bufa().patFw.toChar(i);
	}
	o << '\t';
	for(size_t i = 0; i < p.bufa().qual.length(); i++) {
		o << (char)p.bufa().qual[i];
	}
	o << "\tXM:i:" << (paired ? (hssz+1)/2 : hssz);
	o << '\n';
	if(paired) {
		// truncate final 2 chars
		for(int i = 0; i < (int)p.bufb().name.length()-2; i++) {
			if(!noQnameTrunc_ && isspace((int)p.bufb().name[i])) break;
			o << p.bufb().name[i];
		}
		o << '\t'
		  << (SAM_FLAG_UNMAPPED | (paired ? (SAM_FLAG_PAIRED | SAM_FLAG_SECOND_IN_PAIR | SAM_FLAG_MATE_UNMAPPED) : 0)) << "\t*"
		  << "\t0\t0\t*\t*\t0\t0\t";
		for(size_t i = 0; i < p.bufb().patFw.length(); i++) {
			o << (char)p.bufb().patFw.toChar(i);
		}
		o << '\t';
		for(size_t i = 0; i < p.bufb().qual.length(); i++) {
			o << (char)p.bufb().qual[i];
		}
		o << "\tXM:i:" << (hssz+1)/2;
		o << '\n';
	}
	ptCounts_[threadId]++;
	if (reorder_ && reorderInfo_[threadId].flushed) {
		reorderInfo_[threadId].batchId = p.batch_id();
		reorderInfo_[threadId].flushed = false;
	}
	maybeFlush(threadId);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
testb $0x1, -0x21(%rbp)
je 0x84fe7
movq -0x80(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x2d7c0
leaq 0x26388(%rip), %rax     # 0xab331
testb $0x1, (%rax)
je 0x84fe5
movq -0x80(%rbp), %rax
testb $0x1, 0x78(%rax)
je 0x84fe0
movq -0x80(%rbp), %rdi
addq $0x48, %rdi
movq -0x20(%rbp), %rsi
callq 0x2a100
movq -0x80(%rbp), %rdi
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rsi
callq 0x2eec0
jmp 0x85583
jmp 0x84ffc
movq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
callq 0x2d780
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
callq 0x86360
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x22(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x85030
movq -0x18(%rbp), %rdi
callq 0x37e60
movq %rax, -0x30(%rbp)
movq -0x80(%rbp), %rdi
addq $0x28, %rdi
movq -0x20(%rbp), %rsi
callq 0x2ed00
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x2ef90
movq %rax, %rcx
movl -0x84(%rbp), %eax
movb -0x22(%rbp), %dil
xorl %edx, %edx
movl $0x2, %esi
testb $0x1, %dil
cmovnel %esi, %edx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x8510a
movq -0x80(%rbp), %rax
testb $0x1, 0x1f2(%rax)
jne 0x850c6
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
movslq -0x3c(%rbp), %rsi
callq 0x46bf0
movsbl (%rax), %edi
callq 0xa0a0
cmpl $0x0, %eax
je 0x850c6
jmp 0x8510a
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
movslq -0x3c(%rbp), %rsi
callq 0x46bf0
movq -0x90(%rbp), %rdi
movsbl (%rax), %esi
callq 0x862e0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x8504c
movq -0x38(%rbp), %rdi
movl $0x9, %esi
callq 0x862e0
movq %rax, %rdi
movb -0x22(%rbp), %dl
xorl %eax, %eax
movl $0x49, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
orl $0x4, %eax
movl %eax, -0x40(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x86380
movq %rax, %rdi
leaq 0x9722(%rip), %rsi      # 0x8e866
callq 0x86190
movq %rax, %rdi
leaq 0x9716(%rip), %rsi      # 0x8e869
callq 0x86190
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x851c8
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
movq -0x48(%rbp), %rsi
callq 0x45080
movq -0xa0(%rbp), %rdi
movsbl %al, %esi
callq 0x862e0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x85160
movq -0x38(%rbp), %rdi
movl $0x9, %esi
callq 0x862e0
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
addq $0x60, %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8524e
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37f00
movq %rax, %rdi
addq $0x60, %rdi
movq -0x50(%rbp), %rsi
callq 0x46bf0
movq -0xb0(%rbp), %rdi
movsbl (%rax), %esi
callq 0x862e0
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x851de
movq -0x38(%rbp), %rdi
leaq 0x961e(%rip), %rsi      # 0x8e877
callq 0x86190
movq %rax, -0xb8(%rbp)
testb $0x1, -0x22(%rbp)
je 0x8527f
movq -0x30(%rbp), %rax
addq $0x1, %rax
shrq %rax
movq %rax, -0xc0(%rbp)
jmp 0x8528a
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x86280
movq -0x38(%rbp), %rdi
movl $0xa, %esi
callq 0x862e0
testb $0x1, -0x22(%rbp)
je 0x854ee
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x2ef90
movq %rax, %rcx
movl -0xc4(%rbp), %eax
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x85371
movq -0x80(%rbp), %rax
testb $0x1, 0x1f2(%rax)
jne 0x8532d
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
movslq -0x5c(%rbp), %rsi
callq 0x46bf0
movsbl (%rax), %edi
callq 0xa0a0
cmpl $0x0, %eax
je 0x8532d
jmp 0x85371
movq -0x38(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
movslq -0x5c(%rbp), %rsi
callq 0x46bf0
movq -0xd0(%rbp), %rdi
movsbl (%rax), %esi
callq 0x862e0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x852c4
movq -0x38(%rbp), %rdi
movl $0x9, %esi
callq 0x862e0
movq %rax, %rdi
movb -0x22(%rbp), %dl
xorl %eax, %eax
movl $0x89, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
orl $0x4, %eax
movl %eax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x86380
movq %rax, %rdi
leaq 0x94bb(%rip), %rsi      # 0x8e866
callq 0x86190
movq %rax, %rdi
leaq 0x94af(%rip), %rsi      # 0x8e869
callq 0x86190
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jae 0x8542f
movq -0x38(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
movq -0x68(%rbp), %rsi
callq 0x45080
movq -0xe0(%rbp), %rdi
movsbl %al, %esi
callq 0x862e0
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x853c7
movq -0x38(%rbp), %rdi
movl $0x9, %esi
callq 0x862e0
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
addq $0x60, %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0xe8(%rbp), %rax
cmpq %rcx, %rax
jae 0x854b5
movq -0x38(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38890
movq %rax, %rdi
addq $0x60, %rdi
movq -0x70(%rbp), %rsi
callq 0x46bf0
movq -0xf0(%rbp), %rdi
movsbl (%rax), %esi
callq 0x862e0
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x85445
movq -0x38(%rbp), %rdi
leaq 0x93b7(%rip), %rsi      # 0x8e877
callq 0x86190
movq %rax, %rdi
movq -0x30(%rbp), %rax
addq $0x1, %rax
shrq %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x86280
movq -0x38(%rbp), %rdi
movl $0xa, %esi
callq 0x862e0
movq -0x80(%rbp), %rdi
addq $0x48, %rdi
movq -0x20(%rbp), %rsi
callq 0x2a100
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq (%rcx), %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
testb $0x1, 0x78(%rax)
je 0x85576
movq -0x80(%rbp), %rdi
addq $0x80, %rdi
movq -0x20(%rbp), %rsi
callq 0x2d3f0
testb $0x1, 0x8(%rax)
je 0x85576
movq -0x10(%rbp), %rdi
callq 0x2eea0
movq -0x80(%rbp), %rdi
movq %rax, -0xf8(%rbp)
addq $0x80, %rdi
movq -0x20(%rbp), %rsi
callq 0x2d3f0
movq -0xf8(%rbp), %rcx
movq -0x80(%rbp), %rdi
movq %rcx, (%rax)
addq $0x80, %rdi
movq -0x20(%rbp), %rsi
callq 0x2d3f0
movb $0x0, 0x8(%rax)
movq -0x80(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2eec0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)