// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: check_ul_contain_arc_supports(ul_resolve_t*, asg_arc_t*, asg64_v*, asg64_v*, unsigned long, unsigned long*, unsigned long*)
uint32_t check_ul_contain_arc_supports(ul_resolve_t *uidx, asg_arc_t *ve, asg64_v *b_int, asg64_v *b_raw, uint64_t skip_hom, uint64_t *retrun_w_v, uint64_t *retrun_w_r)
{
    ma_ug_t *iug = uidx->uovl.i_ug; asg_t *g = iug->g; uint32_t v, k, z, zn, nv, n_pre, l_v, l_r, skip_hom_local; 
    asg_arc_t *av; v = ve->ul>>32; uint32_t b_int_s = b_int->n, b_raw_s = b_raw->n, is_collapse = 0, v_occ, r_occ;
    (*retrun_w_v) = (*retrun_w_r) = (uint64_t)-1; uint64_t *raw_v, *raw_r, w_v, w_r, min_w_v, min_w_r;

    get_ul_path_info(uidx, iug, v^1, NULL, NULL, NULL, NULL, NULL, b_int); nv = b_int->n-b_int_s;
    for (k = 0, n_pre = b_int->n; k < (nv>>1); k++) {
        v = b_int->a[k+b_int_s]; 
        b_int->a[k+b_int_s] = b_int->a[b_int_s+nv-k-1]^1; 
        b_int->a[b_int_s+nv-k-1] = v^1;
    }
    if(nv&1) b_int->a[k+b_int_s] ^= 1;
    v = ve->ul>>32;

    get_ul_path_info(uidx, iug, ve->v, NULL, NULL, &v_occ, NULL, NULL, b_int);
    l_v = gen_ug_integer_seq_on_fly(uidx, b_int->a+b_int_s, b_int->n-b_int_s, b_raw);
    
    av = asg_arc_a(g, v); nv = asg_arc_n(g, v); 
    for (k = 0, min_w_v = min_w_r = (uint64_t)-1; k < nv; k++) {
        if(av[k].del || av[k].v == ve->v) continue;

        b_int->n = n_pre; b_raw->n = b_raw_s + l_v;
        get_ul_path_info(uidx, iug, av[k].v, NULL, NULL, &r_occ, NULL, NULL, b_int);
        l_r = gen_ug_integer_seq_on_fly(uidx, b_int->a+b_int_s, b_int->n-b_int_s, b_raw);

        raw_v = b_raw->a + b_raw_s; raw_r = b_raw->a + b_raw_s + l_v; zn = MIN(l_v, l_r);
        for (z = 0; z < zn && raw_v[z] == raw_r[z]; z++); 
        skip_hom_local = skip_hom;
        if(skip_hom_local && z < l_v) {
            skip_hom_local = is_het_bridge(uidx, raw_v, l_v, z - 1);///, (v>>1) == 191 && (ve->v>>1) == 450);
        }
        if(skip_hom_local && z < l_r) {
            skip_hom_local = is_het_bridge(uidx, raw_r, l_r, z - 1);///, (v>>1) == 191 && (ve->v>>1) == 450);
        }

        assert(z > 0); w_v = w_r = (uint64_t)-1;
        if(z < l_v) get_integer_seq_ovlps(uidx, raw_v, l_v, z - 1, skip_hom_local, NULL, &w_v);
        if(z < l_r) get_integer_seq_ovlps(uidx, raw_r, l_r, z - 1, skip_hom_local, NULL, &w_r);
        if(w_v == (uint64_t)-1) w_v = 0;
        if(w_r == (uint64_t)-1) w_r = 0;
        // if((v>>1) == 409 && (ve->v>>1) == 407) {
        //     fprintf(stderr, "[M::%s::v>>1::%u] l_v::%u, l_r::%u, z::%u, w_v::%lu, w_r::%lu, v_occ::%u, r_occ::%u, skip_hom_local::%u\n", 
        //     __func__, av[k].v>>1, l_v, l_r, z, w_v, w_r, v_occ, r_occ, skip_hom_local);
        // }
        ///z == zn: -> prefer collapse
        if((min_w_v == (uint64_t)-1) || (z == zn) || (min_w_v > w_v) || (min_w_v == w_v && min_w_r < w_r)) {
            min_w_v = w_v; min_w_r = w_r;
            if(z == zn && v_occ < r_occ) {
                is_collapse = 1;
            }
        }
    }

    (*retrun_w_v) = min_w_v; (*retrun_w_r) = min_w_r;
    return is_collapse;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r8, 0xd0(%rsp)
movq %rdx, %r15
movq 0x110(%rsp), %r8
movq 0x230(%rdi), %r10
movq 0x18(%r10), %r14
movq %rsi, 0x98(%rsp)
movl 0x4(%rsi), %edx
movq (%r15), %r12
movq %rcx, 0x80(%rsp)
movq (%rcx), %rbx
movq $-0x1, %rax
movq %rax, (%r8)
movq %r9, 0xa0(%rsp)
movq %rax, (%r9)
xorl $0x1, %edx
movq %r15, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
xorl %r13d, %r13d
movq %rdi, 0x28(%rsp)
movq %r10, 0x78(%rsp)
movq %r10, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20d67b
movq %r15, 0x38(%rsp)
movq (%r15), %r15
movl %r12d, %eax
movq %rax, 0x70(%rsp)
movl %r15d, %eax
subl %r12d, %eax
cmpl $0x2, %eax
jb 0x2103fe
movl %eax, %r13d
shrl %r13d
movq 0x38(%rsp), %rcx
movq 0x10(%rcx), %rcx
leaq -0x1(%r15), %rdx
movq %r13, %rsi
movq %r12, %rdi
movl %edi, %r8d
movl (%rcx,%r8,8), %r9d
movl %edx, %r10d
movq (%rcx,%r10,8), %r11
xorq $0x1, %r11
movq %r11, (%rcx,%r8,8)
xorq $0x1, %r9
movq %r9, (%rcx,%r10,8)
decq %rdx
incq %rdi
decq %rsi
jne 0x2103d5
testb $0x1, %al
je 0x210413
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
addl %r12d, %r13d
xorq $0x1, (%rax,%r13,8)
movq 0x98(%rsp), %rax
movl 0x4(%rax), %r12d
movl 0x8(%rax), %edx
movq 0x38(%rsp), %r13
movq %r13, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
leaq 0x5c(%rsp), %r9
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq 0x78(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20d67b
movq 0x70(%rsp), %rax
leaq (,%rax,8), %rcx
movq 0x10(%r13), %rsi
movq %rcx, 0xc8(%rsp)
addq %rcx, %rsi
movq (%r13), %rdx
subq %rax, %rdx
movq %rbp, %rdi
movq 0x80(%rsp), %rcx
callq 0x20e46d
movq %rax, %rdi
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x2107b8
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r8
shlq $0x3, %r8
addq 0x8(%r14), %r8
movl %r15d, %ecx
movq %rcx, 0xc0(%rsp)
leal (%rdi,%rbx), %ecx
movq %rcx, 0xb8(%rsp)
movl %ebx, %ecx
movl %edi, %edx
movl %eax, %r9d
movq %rdx, 0x48(%rsp)
leaq (,%rdx,8), %rax
movq %rax, 0xa8(%rsp)
shlq $0x3, %rcx
movq %rcx, 0xb0(%rsp)
xorl %ebx, %ebx
movq $-0x1, %rbp
movq $-0x1, %r12
xorl %esi, %esi
movq %rdi, 0x40(%rsp)
movq %r8, 0x68(%rsp)
movq %r9, 0x60(%rsp)
leaq (%rbx,%rbx,2), %rax
cmpl $0x0, 0xc(%r8,%rax,8)
js 0x210527
leaq (%r8,%rax,8), %rax
movl 0x8(%rax), %edx
movq 0x98(%rsp), %rax
cmpl 0x8(%rax), %edx
jne 0x210540
movq %r12, %rax
movq %rbp, %rcx
incq %rbx
movq %rcx, %rbp
movq %rax, %r12
cmpq %r9, %rbx
jne 0x210507
jmp 0x2107c8
movq %rsi, 0x90(%rsp)
movq 0x38(%rsp), %r15
movq 0xc0(%rsp), %rax
movq %rax, (%r15)
movq 0x80(%rsp), %r14
movq 0xb8(%rsp), %rax
movq %rax, (%r14)
movq %r15, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
movq 0x28(%rsp), %r13
movq %r13, %rdi
movq 0x78(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x58(%rsp), %r9
callq 0x20d67b
movq 0x10(%r15), %rsi
addq 0xc8(%rsp), %rsi
movq (%r15), %rdx
subq 0x70(%rsp), %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x20e46d
movq 0x40(%rsp), %rdi
movq %rax, %r13
movq 0x10(%r14), %r14
addq 0xb0(%rsp), %r14
cmpl %r13d, %edi
movl %r13d, %r10d
cmovbl %edi, %r10d
movl $0x0, %r15d
testl %r10d, %r10d
je 0x210601
movl %r10d, %eax
movq 0xa8(%rsp), %rcx
addq %r14, %rcx
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdx
cmpq (%rcx,%r15,8), %rdx
jne 0x210601
incq %r15
cmpq %r15, %rax
jne 0x2105ec
movl %r10d, %r15d
movq 0x48(%rsp), %rax
leaq (%r14,%rax,8), %rax
movq %rax, 0x88(%rsp)
movq 0xd0(%rsp), %rax
testl %eax, %eax
movl %r10d, 0x24(%rsp)
je 0x210683
movl %eax, %ecx
cmpl %edi, %r15d
jae 0x210655
leal -0x1(%r15), %ecx
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq 0x48(%rsp), %rdx
callq 0x20fdbb
xorl %edx, %edx
movl 0x24(%rsp), %r10d
movq 0x40(%rsp), %rdi
movl $0x1, %ecx
testl %eax, %eax
je 0x210685
movl %ecx, %edx
cmpl %r13d, %r15d
jae 0x210685
movl %r13d, %edx
leal -0x1(%r15), %ecx
movq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x20fdbb
movl 0x24(%rsp), %r10d
movq 0x40(%rsp), %rdi
movl %eax, %edx
jmp 0x210685
xorl %edx, %edx
testl %r15d, %r15d
je 0x2107f2
movq $-0x1, %rax
movq %rax, 0x50(%rsp)
movq %rax, 0x30(%rsp)
movl %edx, %r8d
cmpl %edi, %r15d
jae 0x2106d4
leal -0x1(%r15), %ecx
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq 0x48(%rsp), %rdx
movq %r8, %r14
xorl %r9d, %r9d
callq 0x20eadf
movq %r14, %r8
movl 0x24(%rsp), %r10d
cmpl %r13d, %r15d
jae 0x210729
movl %r13d, %edx
leal -0x1(%r15), %ecx
leaq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movq 0x88(%rsp), %rsi
xorl %r9d, %r9d
callq 0x20eadf
movl 0x24(%rsp), %r10d
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %rax
cmpq $-0x1, %rax
movl $0x0, %edx
cmoveq %rdx, %rax
movq %rax, 0x30(%rsp)
cmpq $-0x1, %rcx
cmoveq %rdx, %rcx
jmp 0x210742
movq 0x30(%rsp), %rax
cmpq $-0x1, %rax
movl $0x0, %ecx
cmoveq %rcx, %rax
movq %rax, 0x30(%rsp)
xorl %ecx, %ecx
movq 0x68(%rsp), %r8
movq 0x60(%rsp), %r9
movq %rcx, 0x50(%rsp)
cmpq $-0x1, %r12
sete %dl
cmpl %r10d, %r15d
sete %sil
orb %dl, %sil
cmpq %rax, %r12
seta %dl
orb %sil, %dl
je 0x210793
cmpl %r10d, %r15d
movq 0x90(%rsp), %rsi
jne 0x21052d
movl 0x5c(%rsp), %edx
cmpl 0x58(%rsp), %edx
movl $0x1, %edx
cmovbl %edx, %esi
jmp 0x21052d
cmpq %rax, %r12
setne %dl
cmpq %rcx, %rbp
setae %sil
orb %dl, %sil
cmovneq %r12, %rax
cmovneq %rbp, %rcx
movq 0x90(%rsp), %rsi
jmp 0x21052d
movq $-0x1, %rax
movq $-0x1, %rcx
xorl %esi, %esi
movq 0xa0(%rsp), %rdx
movq %rax, (%rdx)
movq 0x110(%rsp), %rax
movq %rcx, (%rax)
movl %esi, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x379a4(%rip), %rdi     # 0x24819d
leaq 0x34e09(%rip), %rsi     # 0x245609
leaq 0x37a0e(%rip), %rcx     # 0x248215
movl $0x25f1, %edx           # imm = 0x25F1
callq 0x2110