// File: BenLangmead[P]bowtie/hit.cpp
// Function: VerboseHitSink::reportMaxed(EList<Hit, 128>&, unsigned long, PatternSourcePerThread&)
void VerboseHitSink::reportMaxed(
	EList<Hit>& hs,
	size_t threadId,
	PatternSourcePerThread& p)
{
	HitSink::reportMaxed(hs, threadId, p);
	if(sampleMax_) {
		RandomSource rand;
		rand.init(p.bufa().seed);
		assert_gt(hs.size(), 0);
		bool paired = hs.front().mate > 0;
		size_t num = 1;
		if(paired) {
			num = 0;
			int bestStratum = 999;
			for(size_t i = 0; i < hs.size()-1; i += 2) {
				int strat = min(hs[i].stratum, hs[i+1].stratum);
				if(strat < bestStratum) {
					bestStratum = strat;
					num = 1;
				} else if(strat == bestStratum) {
					num++;
				}
			}
			assert_leq(num, hs.size());
			uint32_t r = rand.nextU32() % num;
			num = 0;
			for(size_t i = 0; i < hs.size()-1; i += 2) {
				int strat = min(hs[i].stratum, hs[i+1].stratum);
				if(strat == bestStratum) {
					if(num == r) {
						hs[i].oms = hs[i+1].oms = (uint32_t)(hs.size()/2);
						reportHits(NULL, &hs, i, i+2, threadId, 0, 0, true, p);
						break;
					}
					num++;
				}
			}
			assert_eq(num, r);
		} else {
			for(size_t i = 1; i < hs.size(); i++) {
				assert_geq(hs[i].stratum, hs[i-1].stratum);
				if(hs[i].stratum == hs[i-1].stratum) num++;
				else break;
			}
			assert_leq(num, hs.size());
			uint32_t r = rand.nextU32() % num;
			Hit& h = hs[r];
			h.oms = (uint32_t)hs.size();
			reportHits(&h, NULL, 0, 1, threadId, 0, 0, true, p);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x2d780
movq -0x88(%rbp), %rax
testb $0x1, 0x169(%rax)
je 0x86c5d
leaq -0x34(%rbp), %rdi
callq 0x3e790
movq -0x20(%rbp), %rdi
callq 0x37f00
movl 0x18c(%rax), %esi
leaq -0x34(%rbp), %rdi
callq 0x403d0
movq -0x10(%rbp), %rdi
callq 0x86470
movzbl 0x188(%rax), %eax
cmpl $0x0, %eax
setg %al
andb $0x1, %al
movb %al, -0x35(%rbp)
movq $0x1, -0x40(%rbp)
testb $0x1, -0x35(%rbp)
je 0x86b4d
movq $0x0, -0x40(%rbp)
movl $0x3e7, -0x44(%rbp)     # imm = 0x3E7
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37e60
movq %rax, %rcx
movq -0x90(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x869e3
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x2ecd0
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
addq $0x1, %rsi
callq 0x2ecd0
movq -0x98(%rbp), %rdi
movq %rax, %rsi
addq $0x180, %rsi            # imm = 0x180
callq 0x86490
movsbl (%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x869ba
movl -0x54(%rbp), %eax
movl %eax, -0x44(%rbp)
movq $0x1, -0x40(%rbp)
jmp 0x869d0
movl -0x54(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x869ce
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x869d0
jmp 0x869d2
movq -0x50(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x50(%rbp)
jmp 0x86930
leaq -0x34(%rbp), %rdi
callq 0x47b20
movl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
movl %edx, %eax
movl %eax, -0x58(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37e60
movq %rax, %rcx
movq -0xa0(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x86b48
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2ecd0
addq $0x180, %rax            # imm = 0x180
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
addq $0x1, %rsi
callq 0x2ecd0
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
addq $0x180, %rsi            # imm = 0x180
callq 0x86490
movsbl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x86b35
movq -0x40(%rbp), %rax
movl -0x58(%rbp), %ecx
cmpq %rcx, %rax
jne 0x86b29
movq -0x10(%rbp), %rdi
callq 0x37e60
shrq %rax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
addq $0x1, %rsi
callq 0x2ecd0
movl -0xac(%rbp), %ecx
movl %ecx, 0x178(%rax)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2ecd0
movl -0xac(%rbp), %ecx
movq -0x88(%rbp), %rdi
movl %ecx, 0x178(%rax)
movq -0x10(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x60(%rbp), %r8
addq $0x2, %r8
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %r10
movq (%rdi), %rax
xorl %esi, %esi
xorl %r11d, %r11d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %r10, 0x18(%rsp)
callq *0x18(%rax)
jmp 0x86b48
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x86b37
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
jmp 0x86a0b
jmp 0x86c5b
movq $0x1, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37e60
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jae 0x86bda
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x2ecd0
movsbl 0x180(%rax), %eax
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
subq $0x1, %rsi
callq 0x2ecd0
movq %rax, %rcx
movl -0xbc(%rbp), %eax
movsbl 0x180(%rcx), %ecx
cmpl %ecx, %eax
jne 0x86bc5
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x86bc7
jmp 0x86bda
jmp 0x86bc9
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x86b55
leaq -0x34(%rbp), %rdi
callq 0x47b20
movl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
movl %edx, %eax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0x2ecd0
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x37e60
movq -0x88(%rbp), %rdi
movl %eax, %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x178(%rax)
movq -0x80(%rbp), %rsi
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %r10
movq (%rdi), %rax
xorl %ecx, %ecx
movl $0x1, %r8d
xorl %edx, %edx
movq %rcx, %rdx
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %r10, 0x18(%rsp)
callq *0x18(%rax)
jmp 0x86c5d
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)