// File: /workspace/github_cpp_makefile_star2_O1/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, 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 0x204a1c
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 0x2049f2
testb $0x1, %al
je 0x204a31
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, %rdi
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x204d9e
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%r14), %rcx
movl %r15d, %edx
movq %rdx, 0xc0(%rsp)
movq 0x20(%rsp), %rsi
leal (%rdi,%rsi), %edx
movq %rdx, 0xb8(%rsp)
movl %esi, %edx
movl %edi, %esi
movl %eax, %r8d
movq %rsi, 0x20(%rsp)
leaq (,%rsi,8), %rax
movq %rdx, 0xb0(%rsp)
leaq (%rax,%rdx,8), %rax
movq %rax, 0xa0(%rsp)
xorl %r14d, %r14d
movq $-0x1, 0x50(%rsp)
movq $-0x1, %r9
xorl %esi, %esi
movq %rbp, 0xa8(%rsp)
movq %rdi, 0x68(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
leaq (%r14,%r14,2), %rax
cmpl $0x0, 0xc(%rcx,%rax,8)
js 0x204d90
leaq (%rcx,%rax,8), %rax
movl 0x8(%rax), %edx
cmpl 0x8(%rbp), %edx
je 0x204d90
movq %r9, 0xd0(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x58(%rsp), %r15
movq 0xc0(%rsp), %rax
movq %rax, (%r15)
movq 0x88(%rsp), %rbx
movq 0xb8(%rsp), %rax
movq %rax, (%rbx)
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 %rbx, %rcx
callq 0x202e9a
movq 0x68(%rsp), %rdi
movq %rax, %r13
movq 0x10(%rbx), %rax
movq 0xb0(%rsp), %rcx
leaq (%rax,%rcx,8), %r15
cmpl %r13d, %edi
movl %r13d, %r12d
cmovbl %edi, %r12d
movl $0x0, %ebx
testl %r12d, %r12d
je 0x204c24
movl %r13d, %ecx
movq 0x20(%rsp), %rdx
cmpq %rdx, %rcx
cmovaeq %rdx, %rcx
addq 0xa0(%rsp), %rax
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdx
cmpq (%rax,%rbx,8), %rdx
jne 0x204c24
incq %rbx
cmpl %ebx, %ecx
jne 0x204c10
movl %r12d, %ebx
cmpl $0x0, 0x90(%rsp)
je 0x204c56
movq 0x90(%rsp), %rbp
cmpl %edi, %ebx
jae 0x204c56
leal -0x1(%rbx), %ecx
movq 0x28(%rsp), %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
callq 0x2048bb
movq 0x68(%rsp), %rdi
movl %eax, %ebp
movq 0x20(%rsp), %rax
leaq (%r15,%rax,8), %rsi
testl %ebp, %ebp
je 0x204c87
cmpl %r13d, %ebx
jae 0x204c89
movl %r13d, %edx
leal -0x1(%rbx), %ecx
movq 0x28(%rsp), %rdi
movq %rsi, %rbp
callq 0x2048bb
movq %rbp, %rsi
movq 0x68(%rsp), %rdi
movl %eax, %ebp
jmp 0x204c89
xorl %ebp, %ebp
testl %ebx, %ebx
je 0x204de7
movq $-0x1, %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movl %ebp, %r8d
cmpl %edi, %ebx
jae 0x204cdc
leal -0x1(%rbx), %ecx
leaq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
movl %r12d, %ebp
movq %rsi, %r12
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq %r8, %r15
xorl %r9d, %r9d
callq 0x2034cf
movq %r15, %r8
movq %r12, %rsi
movl %ebp, %r12d
cmpl %r13d, %ebx
jae 0x204cfd
movl %r13d, %edx
leal -0x1(%rbx), %ecx
leaq 0x30(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
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 0x204d56
cmpl %r12d, %ebx
je 0x204d56
cmpq 0x38(%rsp), %r9
ja 0x204d56
jne 0x204d81
movq 0x50(%rsp), %rax
cmpq 0x30(%rsp), %rax
jae 0x204d81
movq 0x38(%rsp), %r9
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpl %r12d, %ebx
jne 0x204d81
movl 0x74(%rsp), %eax
cmpl 0x70(%rsp), %eax
movq 0x60(%rsp), %rsi
movl $0x1, %eax
cmovbl %eax, %esi
jmp 0x204d86
movq 0x60(%rsp), %rsi
movq 0x48(%rsp), %rcx
movq 0x40(%rsp), %r8
incq %r14
cmpq %r8, %r14
jne 0x204b30
jmp 0x204db0
movq $-0x1, %r9
movq $-0x1, 0x50(%rsp)
xorl %esi, %esi
xorl %eax, %eax
testl %esi, %esi
cmoveq %r9, %rax
movq 0x98(%rsp), %rcx
movq %rax, (%rcx)
movq 0x110(%rsp), %rax
movq 0x50(%rsp), %rcx
movq %rcx, (%rax)
movl %esi, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x370cb(%rip), %rdi     # 0x23beb9
leaq 0x34530(%rip), %rsi     # 0x239325
leaq 0x370c3(%rip), %rcx     # 0x23bebf
movl $0x25a6, %edx           # imm = 0x25A6
callq 0x2110