// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x230(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x74(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movq 0x10(%rbp), %rax
movq $-0x1, (%rax)
movq -0x30(%rbp), %rax
movq $-0x1, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x44(%rbp), %edx
xorl $0x1, %edx
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %r9d
movq %r9, %rcx
movq %r9, %r8
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x344830
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x74(%rbp), %ecx
subq %rcx, %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
movl -0x54(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x348ae1
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x48(%rbp), %ecx
addl -0x74(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x74(%rbp), %ecx
addl -0x54(%rbp), %ecx
subl -0x48(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
xorq $0x1, %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x48(%rbp), %ecx
addl -0x74(%rbp), %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
xorl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x74(%rbp), %ecx
addl -0x54(%rbp), %ecx
subl -0x48(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x348a5a
movl -0x54(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x348b08
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x48(%rbp), %ecx
addl -0x74(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
xorq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %r8d
leaq -0x80(%rbp), %r9
movq %r8, %rcx
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x344830
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x74(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movl -0x74(%rbp), %eax
subq %rax, %rdx
movq -0x20(%rbp), %rcx
callq 0x345a40
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x44(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x48(%rbp)
movq $-0x1, -0xb8(%rbp)
movq $-0x1, -0xb0(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x348f33
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x348c13
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x348c18
jmp 0x348f25
movl -0x58(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x78(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %r8d
leaq -0x84(%rbp), %r9
movq %r8, %rcx
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x344830
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x74(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movl -0x74(%rbp), %eax
subq %rax, %rdx
movq -0x20(%rbp), %rcx
callq 0x345a40
movl %eax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x78(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x78(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movl -0x5c(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x60(%rbp), %eax
ja 0x348cfa
movl -0x5c(%rbp), %eax
movl %eax, -0xbc(%rbp)
jmp 0x348d03
movl -0x60(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x50(%rbp), %ecx
movb %al, -0xbd(%rbp)
jae 0x348d48
movq -0x90(%rbp), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x98(%rbp), %rcx
movl -0x4c(%rbp), %edx
cmpq (%rcx,%rdx,8), %rax
sete %al
movb %al, -0xbd(%rbp)
movb -0xbd(%rbp), %al
testb $0x1, %al
jne 0x348d54
jmp 0x348d61
jmp 0x348d56
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x348d13
movq -0x28(%rbp), %rax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x348d98
movl -0x4c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x348d98
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rsi
movl -0x5c(%rbp), %eax
movl %eax, %edx
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x348270
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x348dc8
movl -0x4c(%rbp), %eax
cmpl -0x60(%rbp), %eax
jae 0x348dc8
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movl -0x60(%rbp), %eax
movl %eax, %edx
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
callq 0x348270
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x4c(%rbp)
jbe 0x348dd0
jmp 0x348def
leaq 0x500b6(%rip), %rdi     # 0x398e8d
leaq 0x4d3db(%rip), %rsi     # 0x3961b9
movl $0x25f1, %edx           # imm = 0x25F1
leaq 0x5011b(%rip), %rcx     # 0x398f05
callq 0x2130
movq $-0x1, -0xa8(%rbp)
movq $-0x1, -0xa0(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x348e42
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rsi
movl -0x5c(%rbp), %eax
movl %eax, %edx
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl -0x64(%rbp), %eax
movl %eax, %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq -0xa0(%rbp), %rax
movq %rax, (%rsp)
callq 0x3465d0
movl -0x4c(%rbp), %eax
cmpl -0x60(%rbp), %eax
jae 0x348e7f
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movl -0x60(%rbp), %eax
movl %eax, %edx
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl -0x64(%rbp), %eax
movl %eax, %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq -0xa8(%rbp), %rax
movq %rax, (%rsp)
callq 0x3465d0
cmpq $-0x1, -0xa0(%rbp)
jne 0x348e94
movq $0x0, -0xa0(%rbp)
cmpq $-0x1, -0xa8(%rbp)
jne 0x348ea9
movq $0x0, -0xa8(%rbp)
cmpq $-0x1, -0xb0(%rbp)
je 0x348eeb
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
je 0x348eeb
movq -0xb0(%rbp), %rax
cmpq -0xa0(%rbp), %rax
ja 0x348eeb
movq -0xb0(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jne 0x348f23
movq -0xb8(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jae 0x348f23
movq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x348f21
movl -0x80(%rbp), %eax
cmpl -0x84(%rbp), %eax
jae 0x348f21
movl $0x1, -0x7c(%rbp)
jmp 0x348f23
jmp 0x348f25
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x348bd4
movq -0xb0(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0xb8(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x7c(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)