// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_ul_arc_supports(ul_resolve_t*, asg_arc_t*, asg64_v*, asg64_v*, unsigned long, unsigned long*, unsigned long*)
uint32_t get_ul_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);
    // if(((ve->ul>>32) == 24093) && (ve->v == 61472)) {
    //     for (z = 0; z < b_int->n-b_int_s; z++) {
    //         fprintf(stderr, "[M::%s::] integ_v[%u]>>1:%lu, integ_v[%u]&1:%lu\n", __func__, 
    //         z, b_int->a[b_int_s+z]>>1, z, b_int->a[b_int_s+z]&1);
    //     }
    // }
    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;///skip ve->v

        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);
        // if(((ve->ul>>32) == 24093) && (ve->v == 61472)) {
        //     for (z = 0; z < b_int->n-b_int_s; z++) {
        //         fprintf(stderr, "[M::%s::k->%u] integ_r[%u]>>1:%lu, integ_r[%u]&1:%lu\n", __func__, 
        //         k, z, b_int->a[b_int_s+z]>>1, z, b_int->a[b_int_s+z]&1);
        //     }
        // }

        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 -> ve->v; raw_r -> av[k].v
        raw_v = b_raw->a + b_raw_s; raw_r = b_raw->a + b_raw_s + l_v; zn = MIN(l_v, l_r);
        // if((v>>1) == 77 && (ve->v>>1) == 78) {
        //     fprintf(stderr, "[M::%s::] l_v::%u\n", __func__, l_v);
        //     for (z = 0; z < l_v; z++) {
        //         fprintf(stderr, "raw_v[%u]>>1::utg%.6dl, raw_v[%u]&1::%lu\n", 
        //         z, (int32_t)(raw_v[z]>>1)+1, z , raw_v[z]&1);
        //     }
        //     fprintf(stderr, "[M::%s::] l_r::%u\n", __func__, l_r);
        //     for (z = 0; z < l_r; z++) {
        //         fprintf(stderr, "raw_r[%u]>>1::utg%.6dl, raw_r[%u]&1::%lu\n", 
        //         z, (int32_t)(raw_r[z]>>1)+1, z, raw_r[z]&1);
        //     }
        // }
        for (z = 0; z < zn && raw_v[z] == raw_r[z]; z++); ///z: first raw unitig that is different between two paths
        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, skip_hom_local::%u\n", 
        //     __func__, av[k].v>>1, l_v, l_r, z, w_v, w_r, 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;
        }
    }
    if(is_collapse) min_w_v = 0;

    (*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, 0xc8(%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, 0x58(%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, 0x18(%rsp)
movq %rsi, 0x80(%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x20d67b
movq %r15, 0x28(%rsp)
movq (%r15), %r15
movl %r12d, %eax
movq %rax, 0x78(%rsp)
movl %r15d, %eax
subl %r12d, %eax
cmpl $0x2, %eax
jb 0x20ff00
movl %eax, %r13d
shrl %r13d
movq 0x28(%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 0x20fed7
testb $0x1, %al
je 0x20ff15
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
addl %r12d, %r13d
xorq $0x1, (%rax,%r13,8)
movl 0x4(%rbp), %r12d
movl 0x8(%rbp), %edx
movq 0x28(%rsp), %r13
movq %r13, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
leaq 0x6c(%rsp), %r9
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x80(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20d67b
movq 0x78(%rsp), %rax
leaq (,%rax,8), %rcx
movq 0x10(%r13), %rsi
movq %rcx, 0xc0(%rsp)
addq %rcx, %rsi
movq (%r13), %rdx
subq %rax, %rdx
movq %rbx, %rdi
movq 0x88(%rsp), %rcx
callq 0x20e46d
movq %rax, %rdi
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x2102bf
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%r14), %rcx
movl %r15d, %edx
movq %rdx, 0xb8(%rsp)
movq 0x58(%rsp), %rsi
leal (%rdi,%rsi), %edx
movq %rdx, 0xb0(%rsp)
movl %esi, %edx
movl %edi, %esi
movl %eax, %r8d
movq %rsi, 0x50(%rsp)
leaq (,%rsi,8), %rax
movq %rax, 0xa0(%rsp)
shlq $0x3, %rdx
movq %rdx, 0xa8(%rsp)
xorl %ebx, %ebx
movq $-0x1, %r9
movq $-0x1, %r10
movq $0x0, 0x30(%rsp)
movq %rbp, 0x40(%rsp)
movq %rdi, 0x48(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x70(%rsp)
leaq (%rbx,%rbx,2), %rax
cmpl $0x0, 0xc(%rcx,%rax,8)
js 0x2102a4
leaq (%rcx,%rax,8), %rax
movl 0x8(%rax), %edx
cmpl 0x8(%rbp), %edx
je 0x2102a4
movq %r10, 0x58(%rsp)
movq %r9, 0xd0(%rsp)
movq 0x28(%rsp), %r12
movq 0xb8(%rsp), %rax
movq %rax, (%r12)
movq 0x88(%rsp), %r14
movq 0xb0(%rsp), %rax
movq %rax, (%r14)
movq %r12, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
xorl %r15d, %r15d
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq 0x80(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x68(%rsp), %r9
callq 0x20d67b
movq 0x10(%r12), %rsi
addq 0xc0(%rsp), %rsi
movq (%r12), %rdx
subq 0x78(%rsp), %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x20e46d
movq 0x48(%rsp), %rdi
movq %rax, %r13
movq 0x10(%r14), %r14
addq 0xa8(%rsp), %r14
cmpl %r13d, %edi
movl %r13d, %ebp
cmovbl %edi, %ebp
movl $0x0, %r12d
testl %ebp, %ebp
je 0x210100
movl %ebp, %eax
movq 0xa0(%rsp), %rcx
addq %r14, %rcx
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdx
cmpq (%rcx,%r12,8), %rdx
jne 0x210100
incq %r12
cmpq %r12, %rax
jne 0x2100eb
movl %ebp, %r12d
movq 0x50(%rsp), %rax
leaq (%r14,%rax,8), %rax
movq %rax, 0x90(%rsp)
movq 0xc8(%rsp), %rax
testl %eax, %eax
je 0x210173
movl %eax, %ecx
cmpl %edi, %r12d
jae 0x210149
leal -0x1(%r12), %ecx
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq 0x50(%rsp), %rdx
callq 0x20fdbb
movq 0x48(%rsp), %rdi
movl $0x1, %ecx
testl %eax, %eax
je 0x210173
movl %ecx, %r15d
cmpl %r13d, %r12d
jae 0x210173
movl %r13d, %edx
leal -0x1(%r12), %ecx
movq 0x18(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x20fdbb
movq 0x48(%rsp), %rdi
movl %eax, %r15d
testl %r12d, %r12d
je 0x2102f9
movq $-0x1, %rax
movq %rax, 0x60(%rsp)
movq %rax, 0x20(%rsp)
movl %r15d, %r15d
cmpl %edi, %r12d
jae 0x2101bb
leal -0x1(%r12), %ecx
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
movq %r14, %rsi
movq 0x50(%rsp), %rdx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x20eadf
cmpl %r13d, %r12d
jae 0x21020f
movl %r13d, %edx
leal -0x1(%r12), %ecx
leaq 0x60(%rsp), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq %r15, %r8
xorl %r9d, %r9d
callq 0x20eadf
movq 0x60(%rsp), %rcx
movq 0x20(%rsp), %rax
cmpq $-0x1, %rax
movl $0x0, %edx
cmoveq %rdx, %rax
movq %rax, 0x20(%rsp)
cmpq $-0x1, %rcx
cmoveq %rdx, %rcx
jmp 0x210228
movq 0x20(%rsp), %rax
cmpq $-0x1, %rax
movl $0x0, %ecx
cmoveq %rcx, %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
movq 0x70(%rsp), %r8
movq %rcx, 0x60(%rsp)
movq 0x58(%rsp), %r10
cmpq $-0x1, %r10
sete %dl
cmpl %ebp, %r12d
sete %sil
orb %dl, %sil
cmpq %rax, %r10
seta %dl
orb %sil, %dl
je 0x21027a
cmpl %ebp, %r12d
jne 0x210272
movl 0x6c(%rsp), %edx
cmpl 0x68(%rsp), %edx
movq 0x30(%rsp), %rdx
movl $0x1, %esi
cmovbl %esi, %edx
movq %rdx, 0x30(%rsp)
movq %rax, %r10
movq %rcx, %r9
jmp 0x21029a
cmpq %rax, %r10
setne %dl
movq 0xd0(%rsp), %r9
cmpq %rcx, %r9
setae %sil
orb %dl, %sil
cmoveq %rax, %r10
cmoveq %rcx, %r9
movq 0x40(%rsp), %rbp
movq 0x38(%rsp), %rcx
incq %rbx
cmpq %r8, %rbx
jne 0x210015
xorl %eax, %eax
movq 0x30(%rsp), %rdx
testl %edx, %edx
cmoveq %r10, %rax
jmp 0x2102cf
movq $-0x1, %r9
movq $-0x1, %rax
xorl %edx, %edx
movq 0x98(%rsp), %rcx
movq %rax, (%rcx)
movq 0x110(%rsp), %rax
movq %r9, (%rax)
movl %edx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x37e9d(%rip), %rdi     # 0x24819d
leaq 0x35302(%rip), %rsi     # 0x245609
leaq 0x37e95(%rip), %rcx     # 0x2481a3
movl $0x25a6, %edx           # imm = 0x25A6
callq 0x2110