// File: /workspace/github_cpp_makefile_star2_O2/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, 0xc0(%rsp)
movq %rdx, %rbp
movq 0x110(%rsp), %rax
movq 0x230(%rdi), %r8
movq 0x18(%r8), %r14
movq %rsi, 0x88(%rsp)
movl 0x4(%rsi), %edx
movq (%rbp), %r12
movq %rcx, 0x78(%rsp)
movq (%rcx), %rbx
orq $-0x1, (%rax)
movq %r9, 0x90(%rsp)
orq $-0x1, (%r9)
xorl $0x1, %edx
movq %rbp, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
movq %rdi, 0x20(%rsp)
movq %r8, 0x70(%rsp)
movq %r8, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1c0c77
movq (%rbp), %r15
movl %r15d, %ecx
subl %r12d, %ecx
movl %ecx, %eax
shrl %eax
leaq -0x1(%r15), %rdx
movq %rax, %rsi
movq %r12, %rdi
subq $0x1, %rsi
jb 0x1c3151
movq 0x10(%rbp), %r8
movl %edi, %r9d
movl (%r8,%r9,8), %r10d
movl %edx, %r11d
movq (%r8,%r11,8), %r13
xorq $0x1, %r13
movq %r13, (%r8,%r9,8)
xorq $0x1, %r10
movq %r10, (%r8,%r11,8)
decq %rdx
incq %rdi
jmp 0x1c3121
movl %r12d, %edx
movq %rdx, 0x68(%rsp)
testb $0x1, %cl
je 0x1c316a
movq 0x10(%rbp), %rcx
addl %r12d, %eax
xorq $0x1, (%rcx,%rax,8)
movq 0x88(%rsp), %rax
movl 0x4(%rax), %r12d
movl 0x8(%rax), %edx
movq %rbp, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
leaq 0x5c(%rsp), %r9
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq 0x70(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1c0c77
movq 0x68(%rsp), %rax
leaq (,%rax,8), %rcx
movq 0x10(%rbp), %rsi
movq %rcx, 0xb8(%rsp)
addq %rcx, %rsi
movq (%rbp), %rdx
subq %rax, %rdx
movq %r13, %rdi
movq 0x78(%rsp), %rcx
callq 0x1c1740
movq 0x28(%r14), %rcx
movq (%rcx,%r12,8), %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rsi
addq 0x8(%r14), %rsi
movl %edx, %edi
movl %r15d, %ecx
movq %rcx, 0xb0(%rsp)
leal (%rax,%rbx), %ecx
movq %rcx, 0xa8(%rsp)
movl %ebx, %ecx
movq %rax, 0x40(%rsp)
movl %eax, %eax
movq %rax, 0x38(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x98(%rsp)
pushq $-0x1
popq %rax
shlq $0x3, %rcx
movq %rcx, 0xa0(%rsp)
xorl %ebx, %ebx
movl $0x0, 0x1c(%rsp)
movq %rax, %rcx
movq %rax, %r8
movq %rbp, 0x60(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
cmpq %rdi, %rbx
je 0x1c34b5
imulq $0x18, %rbx, %rax
cmpl $0x0, 0xc(%rsi,%rax)
js 0x1c3273
addq %rsi, %rax
movl 0x8(%rax), %edx
movq 0x88(%rsp), %rax
cmpl 0x8(%rax), %edx
jne 0x1c327b
movq %r8, %rax
jmp 0x1c34aa
movq %rcx, 0xd0(%rsp)
movq %r8, 0xc8(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, (%rbp)
movq 0x78(%rsp), %r14
movq 0xa8(%rsp), %rax
movq %rax, (%r14)
movq %rbp, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq 0x70(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x58(%rsp), %r9
callq 0x1c0c77
movq 0x10(%rbp), %rsi
addq 0xb8(%rsp), %rsi
movq (%rbp), %rdx
subq 0x68(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rcx
callq 0x1c1740
movq %rax, %r12
movq 0x10(%r14), %r15
addq 0xa0(%rsp), %r15
movq 0x38(%rsp), %rax
leaq (%r15,%rax,8), %rax
movq %rax, 0x80(%rsp)
movq 0x40(%rsp), %rax
cmpl %r12d, %eax
movl %r12d, %r13d
cmovbl %eax, %r13d
movq 0x98(%rsp), %rax
addq %r15, %rax
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x1c3340
movq (%r15,%r14,8), %rcx
cmpq (%rax,%r14,8), %rcx
jne 0x1c3343
incq %r14
jmp 0x1c332c
movl %r13d, %r14d
xorl %ebp, %ebp
movq 0xc0(%rsp), %rax
testl %eax, %eax
je 0x1c3399
movl %eax, %ecx
cmpl 0x40(%rsp), %r14d
jae 0x1c3377
leal -0x1(%r14), %ecx
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq 0x38(%rsp), %rdx
callq 0x1c2bb1
pushq $0x1
popq %rcx
testl %eax, %eax
je 0x1c3399
movl %ecx, %ebp
cmpl %r12d, %r14d
jae 0x1c3399
movl %r12d, %edx
leal -0x1(%r14), %ecx
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x1c2bb1
movl %eax, %ebp
testl %r14d, %r14d
je 0x1c34e1
orq $-0x1, 0x48(%rsp)
orq $-0x1, 0x50(%rsp)
movl %ebp, %ebp
cmpl 0x40(%rsp), %r14d
jae 0x1c33dc
leal -0x1(%r14), %ecx
leaq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq 0x38(%rsp), %rdx
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x1c1c92
pushq $-0x1
popq %rax
cmpl %r12d, %r14d
jae 0x1c3411
movl %r12d, %edx
leal -0x1(%r14), %ecx
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x1c1c92
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rcx
cmpq $-0x1, %rcx
movl $0x0, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x50(%rsp)
cmpq $-0x1, %rax
cmoveq %rdx, %rax
movq %rax, 0x48(%rsp)
movq 0xd0(%rsp), %r8
cmpq $-0x1, %r8
sete %dl
cmpl %r13d, %r14d
sete %sil
orb %dl, %sil
cmpq %rcx, %r8
seta %dl
orb %sil, %dl
je 0x1c347b
cmpl %r13d, %r14d
movq 0x60(%rsp), %rbp
jne 0x1c34a0
movl 0x5c(%rsp), %edx
cmpl 0x58(%rsp), %edx
movl 0x1c(%rsp), %edx
pushq $0x1
popq %rsi
cmovbl %esi, %edx
movl %edx, 0x1c(%rsp)
jmp 0x1c34a0
cmpq %rcx, %r8
setne %dl
movq 0xc8(%rsp), %rdi
cmpq %rax, %rdi
setae %sil
orb %dl, %sil
cmovneq %r8, %rcx
cmovneq %rdi, %rax
movq 0x60(%rsp), %rbp
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
incq %rbx
movq %rax, %r8
jmp 0x1c324c
movq 0x90(%rsp), %rax
movq %rcx, (%rax)
movq 0x110(%rsp), %rax
movq %r8, (%rax)
movl 0x1c(%rsp), %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36c74(%rip), %rdi     # 0x1fa15c
leaq 0x33fea(%rip), %rsi     # 0x1f74d9
leaq 0x36cde(%rip), %rcx     # 0x1fa1d4
movl $0x25f1, %edx           # imm = 0x25F1
callq 0x2110