// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movq %r8, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %r15
movq %rdi, %r14
movq %rsi, 0x28(%rsp)
movl %esi, %r13d
xorl %ebp, %ebp
movq %rdi, 0x18(%rsp)
movq %rdx, 0x30(%rsp)
movl %r13d, %r12d
shrl %r12d
cmpq %r12, (%r15)
jbe 0x18f648
movq 0x8(%r15), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x18f648
movq %r14, %rdi
movl %r13d, %esi
leaq 0xc(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x1a5422
cmpl $0x1, %eax
ja 0x18f648
movl %eax, %r8d
movq 0x20(%r14), %rax
movl (%rax,%r12,8), %r15d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x18f5a2
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
movl %r8d, %r14d
callq 0x2370
movl %r14d, %r8d
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x10(%rsp), %r9
leal (%r15,%r9), %edx
shll $0x1f, %r13d
leaq 0x1(%rcx), %rsi
movq %rbx, %r14
movq %rsi, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
andl $0x0, (%rax,%rcx)
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %ebp
movl %r13d, %ebx
movl %r9d, 0x4(%rax,%rcx)
movl %edx, 0x8(%rax,%rcx)
movl %r12d, 0xc(%rax,%rcx)
andl $0x0, 0x10(%rax,%rcx)
orl %ebp, %ebx
movl %r15d, 0x14(%rax,%rcx)
movl %ebx, 0x18(%rax,%rcx)
testl %r8d, %r8d
je 0x18f6f4
movl %r8d, %r15d
movq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rax
movl 0xc(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addl (%rax,%rcx), %r9d
movq %r9, 0x10(%rsp)
movl 0x8(%rax,%rcx), %esi
movl %esi, 0xc(%rsp)
xorl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x1, %eax
jne 0x18f64f
movl 0xc(%rsp), %r13d
movl %ebx, %ebp
cmpq 0x28(%rsp), %r13
movq %r14, %rbx
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %r15
jne 0x18f51d
xorl %eax, %eax
jmp 0x18f708
testl %eax, %eax
je 0x18f717
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movl 0xc(%rsp), %r12d
movl %r12d, %ebx
shrl %ebx
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
andl (%rax,%rbx,8), %r13d
movq 0x10(%rsp), %rsi
leal (%rsi,%r13), %edi
shll $0x1f, %r12d
orl %ebp, %r12d
orl $0x40000000, %r12d      # imm = 0x40000000
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x18f6c6
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r14)
imulq $0x1c, %rdx, %rsi
movl %edi, %ebp
movq %rax, %rdi
callq 0x2370
movl %ebp, %edi
movq 0x10(%rsp), %rsi
movq %rax, (%r14)
movq 0x8(%r14), %rcx
movl %r15d, %r8d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
imulq $0x1c, %rcx, %rcx
andl $0x0, (%rax,%rcx)
movl %esi, 0x4(%rax,%rcx)
movl %edi, 0x8(%rax,%rcx)
movl %ebx, 0xc(%rax,%rcx)
andl $0x0, 0x10(%rax,%rcx)
movl %r13d, 0x14(%rax,%rcx)
movl %r12d, 0x18(%rax,%rcx)
testl %r8d, %r8d
sete %al
cmpq $0x0, 0x20(%rsp)
sete %cl
orb %al, %cl
movzbl %cl, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x660d3(%rip), %rdi     # 0x1f57f1
leaq 0x623fe(%rip), %rsi     # 0x1f1b23
leaq 0x660cd(%rip), %rcx     # 0x1f57f9
movl $0x47e9, %edx           # imm = 0x47E9
callq 0x2110