// File: /workspace/github_cpp_makefile_star2_O1/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, 0x90(%rsp)
movq %rdx, %r15
movq %rsi, %rbp
movq 0x110(%rsp), %r8
movq 0x230(%rdi), %rsi
movq 0x18(%rsi), %r14
movl 0x4(%rbp), %edx
movq (%r15), %r12
movq %rcx, 0x88(%rsp)
movq (%rcx), %rax
movq %rax, 0x20(%rsp)
movq $-0x1, %rax
movq %rax, (%r8)
movq %r9, 0x98(%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 %rsi, 0x80(%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x202015
movq %r15, 0x58(%rsp)
movq (%r15), %r15
movl %r12d, %eax
movq %rax, 0x78(%rsp)
movl %r15d, %eax
subl %r12d, %eax
cmpl $0x2, %eax
jb 0x204eee
movl %eax, %ecx
shrl %ecx
movq 0x58(%rsp), %rdx
movq 0x10(%rdx), %rdx
cmpl $0x1, %ecx
adcl $0x0, %ecx
leaq -0x1(%r15), %rsi
xorl %r13d, %r13d
leal (%r12,%r13), %edi
movl (%rdx,%rdi,8), %r8d
movl %esi, %r9d
movq (%rdx,%r9,8), %r10
xorq $0x1, %r10
movq %r10, (%rdx,%rdi,8)
xorq $0x1, %r8
movq %r8, (%rdx,%r9,8)
incq %r13
decq %rsi
cmpq %r13, %rcx
jne 0x204ec4
testb $0x1, %al
je 0x204f03
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
addl %r12d, %r13d
xorq $0x1, (%rax,%r13,8)
movl 0x4(%rbp), %r12d
movl 0x8(%rbp), %edx
movq 0x58(%rsp), %r13
movq %r13, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
leaq 0x74(%rsp), %r9
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x80(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x202015
movq 0x78(%rsp), %rax
leaq (,%rax,8), %rcx
movq 0x10(%r13), %rsi
movq %rcx, 0xc8(%rsp)
addq %rcx, %rsi
movq (%r13), %rdx
subq %rax, %rdx
movq %rbx, %rdi
movq 0x88(%rsp), %rcx
callq 0x202e9a
movq %rax, %rsi
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x205278
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x3, %rdi
addq 0x8(%r14), %rdi
movl %r15d, %ecx
movq %rcx, 0xc0(%rsp)
movq 0x20(%rsp), %rdx
leal (%rsi,%rdx), %ecx
movq %rcx, 0xb8(%rsp)
movl %edx, %ecx
movl %esi, %edx
movl %eax, %r8d
movq %rdx, 0x20(%rsp)
leaq (,%rdx,8), %rax
movq %rcx, 0xb0(%rsp)
leaq (%rax,%rcx,8), %rax
movq %rax, 0xa0(%rsp)
xorl %ebx, %ebx
movq $-0x1, 0x50(%rsp)
movq $-0x1, %r9
xorl %ecx, %ecx
movq %rbp, 0xa8(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdi, 0x48(%rsp)
movq %r8, 0x40(%rsp)
leaq (%rbx,%rbx,2), %rax
cmpl $0x0, 0xc(%rdi,%rax,8)
js 0x20526a
leaq (%rdi,%rax,8), %rax
movl 0x8(%rax), %edx
cmpl 0x8(%rbp), %edx
je 0x20526a
movq %r9, 0xd0(%rsp)
movq %rcx, 0x60(%rsp)
movq 0x58(%rsp), %r15
movq 0xc0(%rsp), %rax
movq %rax, (%r15)
movq 0x88(%rsp), %r14
movq 0xb8(%rsp), %rax
movq %rax, (%r14)
movq %r15, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
xorl %ebp, %ebp
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq 0x80(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x70(%rsp), %r9
callq 0x202015
movq 0x10(%r15), %rsi
addq 0xc8(%rsp), %rsi
movq (%r15), %rdx
subq 0x78(%rsp), %rdx
movq %r12, %rdi
movq %r14, %rcx
callq 0x202e9a
movq 0x68(%rsp), %rsi
movq %rax, %r13
movq 0x10(%r14), %rax
movq 0xb0(%rsp), %rcx
leaq (%rax,%rcx,8), %r15
cmpl %r13d, %esi
movl %r13d, %r12d
cmovbl %esi, %r12d
movl $0x0, %r14d
testl %r12d, %r12d
je 0x2050f8
movl %r13d, %ecx
movq 0x20(%rsp), %rdx
cmpq %rdx, %rcx
cmovaeq %rdx, %rcx
addq 0xa0(%rsp), %rax
xorl %r14d, %r14d
movq (%r15,%r14,8), %rdx
cmpq (%rax,%r14,8), %rdx
jne 0x2050f8
incq %r14
cmpl %r14d, %ecx
jne 0x2050e3
movl %r12d, %r14d
cmpl $0x0, 0x90(%rsp)
je 0x20512c
movq 0x90(%rsp), %rbp
cmpl %esi, %r14d
jae 0x20512c
leal -0x1(%r14), %ecx
movq 0x28(%rsp), %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
callq 0x2048bb
movq 0x68(%rsp), %rsi
movl %eax, %ebp
movq 0x20(%rsp), %rax
leaq (%r15,%rax,8), %r8
testl %ebp, %ebp
je 0x205161
cmpl %r13d, %r14d
jae 0x205163
movl %r13d, %edx
leal -0x1(%r14), %ecx
movq 0x28(%rsp), %rdi
movq %r8, %rsi
movq %r8, %rbp
callq 0x2048bb
movq %rbp, %r8
movq 0x68(%rsp), %rsi
movl %eax, %ebp
jmp 0x205163
xorl %ebp, %ebp
testl %r14d, %r14d
je 0x2052b9
movq $-0x1, %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movl %ebp, %ebp
cmpl %esi, %r14d
jae 0x2051af
leal -0x1(%r14), %ecx
leaq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq %r8, %r15
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x2034cf
movq %r15, %r8
cmpl %r13d, %r14d
jae 0x2051d7
movl %r13d, %edx
leal -0x1(%r14), %ecx
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movq %r8, %rsi
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x2034cf
movq 0x38(%rsp), %rax
cmpq $-0x1, %rax
movl $0x0, %ecx
cmoveq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x30(%rsp), %rax
cmpq $-0x1, %rax
cmoveq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0xd0(%rsp), %r9
cmpq $-0x1, %r9
movq 0xa8(%rsp), %rbp
je 0x205230
cmpl %r12d, %r14d
je 0x205230
cmpq 0x38(%rsp), %r9
ja 0x205230
jne 0x20525b
movq 0x50(%rsp), %rax
cmpq 0x30(%rsp), %rax
jae 0x20525b
movq 0x38(%rsp), %r9
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpl %r12d, %r14d
jne 0x20525b
movl 0x74(%rsp), %eax
cmpl 0x70(%rsp), %eax
movq 0x60(%rsp), %rcx
movl $0x1, %eax
cmovbl %eax, %ecx
jmp 0x205260
movq 0x60(%rsp), %rcx
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %r8
incq %rbx
cmpq %r8, %rbx
jne 0x205001
jmp 0x20528a
movq $-0x1, %r9
movq $-0x1, 0x50(%rsp)
xorl %ecx, %ecx
movq 0x98(%rsp), %rax
movq %r9, (%rax)
movq 0x110(%rsp), %rax
movq 0x50(%rsp), %rdx
movq %rdx, (%rax)
movl %ecx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36bf9(%rip), %rdi     # 0x23beb9
leaq 0x3405e(%rip), %rsi     # 0x239325
leaq 0x36c63(%rip), %rcx     # 0x23bf31
movl $0x25f1, %edx           # imm = 0x25F1
callq 0x2110