// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_sort_dedup_patch
int mem_sort_dedup_patch(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, uint8_t *query, int n, mem_alnreg_t *a)
{
	int m, i, j;
	if (n <= 1) return n;
	ks_introsort(mem_ars2, n, a); // sort by the END position, not START!
	for (i = 0; i < n; ++i) a[i].n_comp = 1;
	for (i = 1; i < n; ++i) {
		mem_alnreg_t *p = &a[i];
		if (p->rid != a[i-1].rid || p->rb >= a[i-1].re + opt->max_chain_gap) continue; // then no need to go into the loop below
		for (j = i - 1; j >= 0 && p->rid == a[j].rid && p->rb < a[j].re + opt->max_chain_gap; --j) {
			mem_alnreg_t *q = &a[j];
			int64_t or, oq, mr, mq;
			int score, w;
			if (q->qe == q->qb) continue; // a[j] has been excluded
			or = q->re - p->rb; // overlap length on the reference
			oq = q->qb < p->qb? q->qe - p->qb : p->qe - q->qb; // overlap length on the query
			mr = q->re - q->rb < p->re - p->rb? q->re - q->rb : p->re - p->rb; // min ref len in alignment
			mq = q->qe - q->qb < p->qe - p->qb? q->qe - q->qb : p->qe - p->qb; // min qry len in alignment
			if (or > opt->mask_level_redun * mr && oq > opt->mask_level_redun * mq) { // one of the hits is redundant
				if (p->score < q->score) {
					p->qe = p->qb;
					break;
				} else q->qe = q->qb;
			} else if (q->rb < p->rb && (score = mem_patch_reg(opt, bns, pac, query, q, p, &w)) > 0) { // then merge q into p
				p->n_comp += q->n_comp + 1;
				p->seedcov = p->seedcov > q->seedcov? p->seedcov : q->seedcov;
				p->sub = p->sub > q->sub? p->sub : q->sub;
				p->csub = p->csub > q->csub? p->csub : q->csub;
				p->qb = q->qb, p->rb = q->rb;
				p->truesc = p->score = score;
				p->w = w;
				q->qb = q->qe;
			}
		}
	}
	for (i = 0, m = 0; i < n; ++i) // exclude identical hits
		if (a[i].qe > a[i].qb) {
			if (m != i) a[m++] = a[i];
			else ++m;
		}
	n = m;
	ks_introsort(mem_ars, n, a);
	for (i = 1; i < n; ++i) { // mark identical hits
		if (a[i].score == a[i-1].score && a[i].rb == a[i-1].rb && a[i].qb == a[i-1].qb)
			a[i].qe = a[i].qb;
	}
	for (i = 1, m = 1; i < n; ++i) // exclude identical hits
		if (a[i].qe > a[i].qb) {
			if (m != i) a[m++] = a[i];
			else ++m;
		}
	return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
cmpl $0x1, -0x2c(%rbp)
jg 0x268a4
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x26f1d
movslq -0x2c(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x208b0
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x268e9
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x48(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x1, %ecx
movl %ecx, 0x48(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x268b8
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26d18
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x38(%rbp), %rcx
movl -0x40(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jne 0x26961
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movl -0x40(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
movslq 0x90(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jl 0x26966
jmp 0x26d0a
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x44(%rbp)
movb %al, -0x81(%rbp)
jl 0x269d4
movq -0x50(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x38(%rbp), %rdx
movslq -0x44(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpl 0x18(%rdx), %ecx
movb %al, -0x81(%rbp)
jne 0x269d4
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
movslq 0x90(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
setl %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x269e3
jmp 0x26d08
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x26a0b
jmp 0x26cfa
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x50(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x50(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x26a44
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x88(%rbp)
jmp 0x26a58
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x88(%rbp)
movl -0x88(%rbp), %eax
cltq
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
subq (%rcx), %rax
movq -0x50(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x50(%rbp), %rdx
subq (%rdx), %rcx
cmpq %rcx, %rax
jge 0x26a9f
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x90(%rbp)
jmp 0x26ab5
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x50(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
movq -0x50(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x50(%rbp), %rdx
subl 0x10(%rdx), %ecx
cmpl %ecx, %eax
jge 0x26af6
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x58(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x94(%rbp)
jmp 0x26b0a
movq -0x50(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x50(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
cltq
movq %rax, -0x78(%rbp)
cvtsi2ssq -0x60(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0xa8(%rax), %xmm1
cvtsi2ssq -0x70(%rbp), %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x26b8e
cvtsi2ssq -0x68(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0xa8(%rax), %xmm1
cvtsi2ssq -0x78(%rbp), %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x26b8e
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x26b7b
movq -0x50(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0x26d08
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0x26cf8
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x26cf6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x50(%rbp), %r9
leaq -0x80(%rbp), %rax
movq %rax, (%rsp)
callq 0x262f0
movl %eax, -0x7c(%rbp)
cmpl $0x0, %eax
jle 0x26cf6
movq -0x58(%rbp), %rax
movl 0x48(%rax), %ecx
shll $0x2, %ecx
sarl $0x2, %ecx
addl $0x1, %ecx
movq -0x50(%rbp), %rax
movl 0x48(%rax), %edx
shll $0x2, %edx
sarl $0x2, %edx
addl %ecx, %edx
movl 0x48(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x48(%rax)
movq -0x50(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jle 0x26c25
movq -0x50(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x98(%rbp)
jmp 0x26c32
movq -0x58(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x50(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jle 0x26c5e
movq -0x50(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x9c(%rbp)
jmp 0x26c6b
movq -0x58(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x50(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jle 0x26c97
movq -0x50(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0xa0(%rbp)
jmp 0x26ca4
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movl -0x7c(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x50(%rbp), %rax
movl %ecx, 0x20(%rax)
movl -0x80(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x58(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x26cf8
jmp 0x26cfa
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2696f
jmp 0x26d0a
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x268f0
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26daa
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x38(%rbp), %rcx
movslq -0x40(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jle 0x26d9a
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
je 0x26d8f
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x3c(%rbp)
cltq
imulq $0x60, %rax, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movslq -0x40(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
movl $0x60, %edx
callq 0x3250
jmp 0x26d98
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x26d9a
jmp 0x26d9c
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x26d26
movl -0x3c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21e00
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26e85
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq -0x38(%rbp), %rcx
movl -0x40(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x1c(%rcx), %eax
jne 0x26e75
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movl -0x40(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jne 0x26e75
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq -0x38(%rbp), %rcx
movl -0x40(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jne 0x26e75
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
jmp 0x26e77
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x26dc4
movl $0x1, -0x40(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26f17
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x38(%rbp), %rcx
movslq -0x40(%rbp), %rdx
imulq $0x60, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jle 0x26f07
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
je 0x26efc
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x3c(%rbp)
cltq
imulq $0x60, %rax, %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movslq -0x40(%rbp), %rax
imulq $0x60, %rax, %rax
addq %rax, %rsi
movl $0x60, %edx
callq 0x3250
jmp 0x26f05
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x26f07
jmp 0x26f09
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x26e93
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)