// File: chhylp123[P]hifiasm/inter.cpp
// Function: extract_contain_tig(asg_t*, unsigned long, R_to_U*, unsigned long, unsigned long, kv_ul_ov_t*)
uint32_t extract_contain_tig(asg_t *g, uint64_t v0, R_to_U *ri, uint64_t offset, uint64_t must_tip, kv_ul_ov_t *res)
{
	uint32_t v = v0, w, kv, kw, is_tip = 0, l = offset;
	ul_ov_t p; memset(&p, 0, sizeof(p));

	while (1) {
		if(!is_contain_r((*ri), (v>>1))) return 0;
		kv = get_arcs(g, v, &w, 1);        
		if(kv > 1) return 0;

		p.qn = 0; p.qs = l; p.qe = l + g->seq[v>>1].len; 
		p.tn = v>>1; p.ts = 0; p.te = g->seq[v>>1].len;
		p.el = 0; p.rev = v&1; kv_push(ul_ov_t, *res, p);

		if(kv == 0) {is_tip = 1; break;}

		l += asg_arc_len(g->arc[w]);
		w = g->arc[w].v;
        ///kv must be 1 here
        kw = get_arcs(g, w^1, NULL, 0);
		assert(kw >= 1);
		if(kw > 1) {
			p.qn = 0; p.qs = l; p.qe = l + g->seq[w>>1].len; 
			p.tn = w>>1; p.ts = 0; p.te = g->seq[w>>1].len;
			p.el = 1; p.rev = w&1; kv_push(ul_ov_t, *res, p);
			break;
		}
        v = w;
        if(v == v0) return 0;
    }
	if((must_tip) && (!is_tip)) return 0;
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x50(%rbp)
leaq -0x6c(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movl -0x3c(%rbp), %eax
shrl %eax
movl %eax, %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2e8db7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x2e8db7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2e8dc3
movl $0x0, -0x4(%rbp)
jmp 0x2e90f7
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
leaq -0x40(%rbp), %rdx
movl $0x1, %ecx
callq 0x311ba0
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
jbe 0x2e8ded
movl $0x0, -0x4(%rbp)
jmp 0x2e90f7
movl $0x0, -0x6c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x50(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x3c(%rbp), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x3c(%rbp), %eax
shrl %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x0, %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %ecx
andl $0x1, %ecx
movl -0x54(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2e8ece
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2e8e98
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x2e8ea3
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x2e8ea3
movq -0x78(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x6c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x64(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x5c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x54(%rbp), %ecx
movl %ecx, 0x18(%rax)
cmpl $0x0, -0x44(%rbp)
jne 0x2e8f1e
movl $0x1, -0x4c(%rbp)
jmp 0x2e90da
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
movl %eax, -0x48(%rbp)
cmpl $0x1, -0x48(%rbp)
jb 0x2e8f71
jmp 0x2e8f90
leaq 0xab585(%rip), %rdi     # 0x3944fd
leaq 0xa78b0(%rip), %rsi     # 0x39082f
movl $0x47e9, %edx           # imm = 0x47E9
leaq 0xab57a(%rip), %rcx     # 0x394505
callq 0x2130
cmpl $0x1, -0x48(%rbp)
jbe 0x2e90bd
movl $0x0, -0x6c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x50(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x40(%rbp), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x40(%rbp), %eax
shrl %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x54(%rbp)
movl -0x40(%rbp), %ecx
andl $0x1, %ecx
movl -0x54(%rbp), %eax
andl $0x1, %ecx
shll $0x1f, %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2e907d
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2e9047
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x2e9052
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x2e9052
movq -0x80(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x6c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x64(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x5c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x54(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2e90da
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpq -0x18(%rbp), %rax
jne 0x2e90d5
movl $0x0, -0x4(%rbp)
jmp 0x2e90f7
jmp 0x2e8d78
cmpq $0x0, -0x30(%rbp)
je 0x2e90f0
cmpl $0x0, -0x4c(%rbp)
jne 0x2e90f0
movl $0x0, -0x4(%rbp)
jmp 0x2e90f7
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)