// File: chhylp123[P]hifiasm/inter.cpp
// Function: filter_short_ulalignments(void*, long, int)
static void filter_short_ulalignments(void *data, long i, int tid) // callback for kt_for()
{
	const ma_ug_t *ug = (ma_ug_t *)data;
	uc_block_t *a = NULL; uc_block_t *p; int64_t k, a_n; uint32_t z, fz, lz, l, bz;
	a = UL_INF.a[i].bb.a; a_n = UL_INF.a[i].bb.n; 

	for (k = a_n - 1; k >= 0; k--) {
		p = &(a[k]);
		// if(i == 338344) {
		// 	fprintf(stderr, "+[M::%s::id->%ld::rlen->%u::glen->%u] (%ld) utg%.6dl, q::[%u, %u), t::[%u, %u), pidx::%u, aidx::%u, pdis::%u, a[k].base::%u, a[k].el::%u, a[k].pchain::%u\n", 
		// 	__func__, i, UL_INF.a[i].rlen, ug->u.a[p->hid].len, k, (int32_t)a[k].hid+1, a[k].qs, a[k].qe, a[k].ts, a[k].te, a[k].pidx, a[k].aidx, a[k].pdis, 
		// 	a[k].base, a[k].el, a[k].pchain);
		// }
		if(p->base || (!p->el) || (!p->pchain)) continue;
		if(p->pidx == (uint32_t)-1) {
			if(!ugl_cover_check(p->ts, p->te, &(ug->u.a[p->hid]))) {
				p->pchain = 0;
				if(p->aidx != (uint32_t)-1) {
					a[p->aidx].pidx = a[p->aidx].pdis = (uint32_t)-1; p->aidx = (uint32_t)-1;
				}
			}
			continue;
		}
		if(ugl_cover_check(p->ts, p->te, &(ug->u.a[p->hid]))) continue;
		for (z = p->pidx; z != (uint32_t)-1; z = a[z].pidx) {
			if(ugl_cover_check(a[z].ts, a[z].te, &(ug->u.a[a[z].hid]))) break;
		}
		lz = z; fz = p->aidx; l = 0; if(fz != (uint32_t)-1) l = a[fz].pdis;
		for (z = k; z != lz; z = bz) {
			bz = a[z].pidx; l += a[z].pdis;
			a[z].pidx = a[z].pdis = a[z].aidx = (uint32_t)-1; a[z].pchain = 0;
		}

		if(fz != (uint32_t)-1 && lz != (uint32_t)-1) {
			a[fz].pdis = l; a[fz].pidx = lz; a[lz].aidx = fz;
		} else if(fz != (uint32_t)-1) {
			a[fz].pdis = a[fz].pidx = (uint32_t)-1;
		} else if(lz != (uint32_t)-1) {
			a[lz].aidx = (uint32_t)-1;
		}
	}

	for (k = a_n - 1; k >= 0; k--) {
		p = &(a[k]);
		if(p->base || (!p->el) || (!p->pchain)) continue;
		if(p->pidx != (uint32_t)-1) {		
			if((a[p->pidx].aidx != ((uint32_t)k)) && (a[p->pidx].aidx == ((uint32_t)-1))) {
				p->pidx = (uint32_t)-1;
			} else {
				assert(a[p->pidx].aidx == (uint32_t)k);
				assert(a[p->pidx].pchain);
			}
		}
		if(p->aidx != (uint32_t)-1) {
			if((a[p->aidx].pidx != (uint32_t)k) && (a[p->aidx].pidx == ((uint32_t)-1))) {
				p->aidx = (uint32_t)-1;
			} else {
				assert(a[p->aidx].pidx == (uint32_t)k);
				assert(a[p->aidx].pchain);
			}
			
		}
	}

	for (k = a_n - 1; k >= 0; k--) {
		p = &(a[k]);
		if(p->base || (!p->el) || (!p->pchain)) continue;
		// if(i == 338344) {
		// 	fprintf(stderr, "-[M::%s::id->%ld::rlen->%u::glen->%u] (%ld) utg%.6dl, q::[%u, %u), t::[%u, %u), pidx::%u, aidx::%u, pdis::%u, a[k].base::%u, a[k].el::%u, a[k].pchain::%u\n", 
		// 	__func__, i, UL_INF.a[i].rlen, ug->u.a[p->hid].len, k, (int32_t)a[k].hid+1, a[k].qs, a[k].qe, a[k].ts, a[k].te, a[k].pidx, a[k].aidx, a[k].pdis, 
		// 	a[k].base, a[k].el, a[k].pchain);
		// }
		if(p->pidx != (uint32_t)-1) {
			// if(!(a[p->pidx].aidx == (uint32_t)k)) {
			// 	fprintf(stderr, "[M::%s::id->%ld] name::%.*s, a_n::%ld\n", __func__, 
			// 		i, (int32_t)UL_INF.nid.a[i].n, UL_INF.nid.a[i].a, a_n);
			// }			
			assert(a[p->pidx].aidx == (uint32_t)k);
			assert(a[p->pidx].pchain);
		}
		if(p->aidx != (uint32_t)-1) {
			// if(a[p->aidx].pidx != (uint32_t)k) {
			// 	fprintf(stderr, "[M::%s::id->%ld] name::%.*s, a_n::%ld, p->aidx::%u, p->pidx::%u, a[p->aidx].pidx::%u\n", __func__, i, (int32_t)UL_INF.nid.a[i].n, UL_INF.nid.a[i].a, a_n, 
			// 	p->aidx, p->pidx, a[p->aidx].pidx);
			// }
			assert(a[p->aidx].pidx == (uint32_t)k);
			assert(a[p->aidx].pchain);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
leaq 0xd3b4e(%rip), %rax     # 0x3c53b8
movq 0x48(%rax), %rax
imulq $0x58, -0x10(%rbp), %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0xd3b33(%rip), %rax     # 0x3c53b8
movq 0x48(%rax), %rax
imulq $0x58, -0x10(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x2f1bbd
movq -0x28(%rbp), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x2f18eb
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x2f18eb
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
jne 0x2f18f0
jmp 0x2f1bac
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x14(%rax)
jne 0x2f198d
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x30(%rbp), %rax
movl (%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0x2f10d0
cmpl $0x0, %eax
jne 0x2f1988
movq -0x30(%rbp), %rax
movb 0x20(%rax), %cl
andb $-0x20, %cl
orb $0x0, %cl
movb %cl, 0x20(%rax)
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
je 0x2f1986
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
jmp 0x2f1988
jmp 0x2f1bac
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x30(%rbp), %rax
movl (%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0x2f10d0
cmpl $0x0, %eax
je 0x2f19c3
jmp 0x2f1bac
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
je 0x2f1a3c
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0x2f10d0
cmpl $0x0, %eax
je 0x2f1a24
jmp 0x2f1a3c
jmp 0x2f1a26
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x2f19cd
movl -0x44(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
cmpl $-0x1, -0x48(%rbp)
je 0x2f1a6d
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
je 0x2f1b0f
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %cl
andb $-0x20, %cl
orb $0x0, %cl
movb %cl, 0x20(%rax)
movl -0x54(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x2f1a74
cmpl $-0x1, -0x48(%rbp)
je 0x2f1b59
cmpl $-0x1, -0x4c(%rbp)
je 0x2f1b59
movl -0x50(%rbp), %ecx
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movl -0x4c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movl -0x4c(%rbp), %edx
imulq $0x24, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x1c(%rax)
jmp 0x2f1baa
cmpl $-0x1, -0x48(%rbp)
je 0x2f1b8b
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
jmp 0x2f1ba8
cmpl $-0x1, -0x4c(%rbp)
je 0x2f1ba6
movq -0x28(%rbp), %rax
movl -0x4c(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
jmp 0x2f1ba8
jmp 0x2f1baa
jmp 0x2f1bac
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2f18a5
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x2f1dc3
movq -0x28(%rbp), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x2f1c0f
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x2f1c0f
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
jne 0x2f1c14
jmp 0x2f1db2
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x14(%rax)
je 0x2f1ce2
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl %ecx, %eax
je 0x2f1c64
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x1c(%rax)
jne 0x2f1c64
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
jmp 0x2f1ce0
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl %ecx, %eax
jne 0x2f1c83
jmp 0x2f1ca2
leaq 0xa3ee0(%rip), %rdi     # 0x395b6a
leaq 0x9eb9e(%rip), %rsi     # 0x39082f
movl $0x4cf3, %edx           # imm = 0x4CF3
leaq 0xa3eec(%rip), %rcx     # 0x395b89
callq 0x2130
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
je 0x2f1cbf
jmp 0x2f1cde
leaq 0xa3ef5(%rip), %rdi     # 0x395bbb
leaq 0x9eb62(%rip), %rsi     # 0x39082f
movl $0x4cf4, %edx           # imm = 0x4CF4
leaq 0xa3eb0(%rip), %rcx     # 0x395b89
callq 0x2130
jmp 0x2f1ce0
jmp 0x2f1ce2
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
je 0x2f1db0
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl %ecx, %eax
je 0x2f1d32
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x14(%rax)
jne 0x2f1d32
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
jmp 0x2f1dae
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl %ecx, %eax
jne 0x2f1d51
jmp 0x2f1d70
leaq 0xa3e75(%rip), %rdi     # 0x395bcd
leaq 0x9ead0(%rip), %rsi     # 0x39082f
movl $0x4cfb, %edx           # imm = 0x4CFB
leaq 0xa3e1e(%rip), %rcx     # 0x395b89
callq 0x2130
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
je 0x2f1d8d
jmp 0x2f1dac
leaq 0xa3e58(%rip), %rdi     # 0x395bec
leaq 0x9ea94(%rip), %rsi     # 0x39082f
movl $0x4cfc, %edx           # imm = 0x4CFC
leaq 0xa3de2(%rip), %rcx     # 0x395b89
callq 0x2130
jmp 0x2f1dae
jmp 0x2f1db0
jmp 0x2f1db2
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2f1bc9
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x2f1f39
movq -0x28(%rbp), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x2f1e15
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x2f1e15
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
jne 0x2f1e1a
jmp 0x2f1f28
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x14(%rax)
je 0x2f1ea0
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl %ecx, %eax
jne 0x2f1e43
jmp 0x2f1e62
leaq 0xa3d20(%rip), %rdi     # 0x395b6a
leaq 0x9e9de(%rip), %rsi     # 0x39082f
movl $0x4d0f, %edx           # imm = 0x4D0F
leaq 0xa3d2c(%rip), %rcx     # 0x395b89
callq 0x2130
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
je 0x2f1e7f
jmp 0x2f1e9e
leaq 0xa3d35(%rip), %rdi     # 0x395bbb
leaq 0x9e9a2(%rip), %rsi     # 0x39082f
movl $0x4d10, %edx           # imm = 0x4D10
leaq 0xa3cf0(%rip), %rcx     # 0x395b89
callq 0x2130
jmp 0x2f1ea0
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
je 0x2f1f26
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl %ecx, %eax
jne 0x2f1ec9
jmp 0x2f1ee8
leaq 0xa3cfd(%rip), %rdi     # 0x395bcd
leaq 0x9e958(%rip), %rsi     # 0x39082f
movl $0x4d17, %edx           # imm = 0x4D17
leaq 0xa3ca6(%rip), %rcx     # 0x395b89
callq 0x2130
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
andb $0x1f, %al
cmpb $0x0, %al
je 0x2f1f05
jmp 0x2f1f24
leaq 0xa3ce0(%rip), %rdi     # 0x395bec
leaq 0x9e91c(%rip), %rsi     # 0x39082f
movl $0x4d18, %edx           # imm = 0x4D18
leaq 0xa3c6a(%rip), %rcx     # 0x395b89
callq 0x2130
jmp 0x2f1f26
jmp 0x2f1f28
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2f1dcf
addq $0x60, %rsp
popq %rbp
retq
nop