// File: chhylp123[P]hifiasm/inter.cpp
// Function: refine_rid_chain(asg_t const*, mg_tbuf_s*, ul_vec_t*, unsigned long)
uint32_t refine_rid_chain(const asg_t *rg, mg_tbuf_t *b, ul_vec_t *rch, uint64_t ulid)
{
	if(rch->bb.n == 1 && rch->bb.a[0].base) return 1;///no alignment
	if(rch->bb.n == 0) return 1;///no alignment
	uint64_t i, m, c[2], nc, cc/**, ni[2]**/; 
	for (i = c[1] = rch->bb.n-1, m = nc = 0; i != (uint32_t)-1; i = rch->bb.a[i].pidx) {
		m++; c[0] = i; if(!(rg->seq[rch->bb.a[i].hid].del)) nc++; 
	}
	if(m == rch->bb.n) {///only one chain
		if(nc == m || nc == 0) return 1;///all alignments are non-contained/contained
		cc = 0;
		for (i = c[1]; i != (uint32_t)-1; i = rch->bb.a[i].pidx) {
			if(rg->seq[rch->bb.a[i].hid].del) cc++;
			else break;
		}
		// ni[1] = i;
		for (i = c[0]; i != (uint32_t)-1; i = rch->bb.a[i].aidx) {
			if(rg->seq[rch->bb.a[i].hid].del) cc++;
			else break;
		}
		// ni[0] = i;
		if(nc + cc == m) return 1;
		// assert(ni[1] > ni[0] && ni[0] != (uint32_t)-1 && ni[1] != (uint32_t)-1);
		return 2;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x1, 0x20(%rax)
jne 0x2e3e6f
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
je 0x2e3e6f
movl $0x1, -0x4(%rbp)
jmp 0x2e4039
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x2e3e86
movl $0x1, -0x4(%rbp)
jmp 0x2e4039
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq %rax, -0x30(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
je 0x2e3f15
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x2e3efa
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x2e3efc
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq %rax, -0x30(%rbp)
jmp 0x2e3eaa
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x2e4032
movq -0x58(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x2e3f38
cmpq $0x0, -0x58(%rbp)
jne 0x2e3f44
movl $0x1, -0x4(%rbp)
jmp 0x2e4039
movq $0x0, -0x60(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
je 0x2e3faf
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e3f92
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x2e3f94
jmp 0x2e3faf
jmp 0x2e3f96
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movq %rax, -0x30(%rbp)
jmp 0x2e3f54
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
je 0x2e4012
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x30(%rcx), %rcx
imulq $0x24, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e3ff5
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x2e3ff7
jmp 0x2e4012
jmp 0x2e3ff9
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq %rax, -0x30(%rbp)
jmp 0x2e3fb7
movq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x2e4029
movl $0x1, -0x4(%rbp)
jmp 0x2e4039
movl $0x2, -0x4(%rbp)
jmp 0x2e4039
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nop