// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_arc_mm_consist(usg_t*, usg_arc_t*, usg_arc_t*, unsigned int*, asg64_v*)
uint32_t usg_arc_mm_consist(usg_t *g, usg_arc_t *v, usg_arc_t *w, uint32_t *inconsist, asg64_v *b)
{
    usg_arc_mm_t *v_a = NULL, *w_a = NULL; uint32_t v_n, w_n, v_k, w_k, occ = 0, n_occ = 0, cov; uint64_t l = 0;
    get_usg_unitig(g, (v->ul>>32)^1, &cov, NULL, NULL, &l, NULL); assert(cov == (w->ul>>32));
    
    v_n = get_usg_arc_mm(g, v, &v_a); w_n = get_usg_arc_mm(g, w, &w_a);
    // if((v->ul>>33) == 257 || (v->ul>>33) == 256) {
    //     fprintf(stderr, "****[M::%s::] v>>1::%u, v&1::%u, v->des::%u, v_n::%u, v_ou::%u, w>>1::%u, w&1::%u, w->des::%u, w_n::%u, w_ou::%u\n", 
    //     __func__, (uint32_t)(v->ul>>33), (uint32_t)(v->ul>>32)&1, v->v>>1, v_n, v->ou, cov>>1, cov&1, w->v>>1, w_n, w->ou);
    // }

    for (v_k = 0; v_k < v_n; v_k++) {
        for (w_k = 0; w_k < w_n; w_k++) {
            // if((v->ul>>33) == 257 || (v->ul>>33) == 256) {
            //     fprintf(stderr, "[M::%s::] v_a->uid::%u, v_a->off::%u, w_a->uid::%u, w_a->off::%u\n", 
            //     __func__, v_a[v_k].uid, v_a[v_k].off, w_a[w_k].uid, w_a[w_k].off);
            // }
            if(v_a[v_k].uid != w_a[w_k].uid) continue;
            if(v_a[v_k].off + l == w_a[w_k].off) {
                if(b) kv_push(uint64_t, *b, (((uint64_t)v_a[v_k].uid)<<32)|((uint64_t)v_a[v_k].off));
                occ++; 
            } else if(v_a[v_k].off == w_a[w_k].off + l) {
                if(b) kv_push(uint64_t, *b, (((uint64_t)v_a[v_k].uid)<<32)|((uint64_t)w_a[w_k].off));
                occ++;
            } else {
                n_occ++;
            }
        }
    }

    if(inconsist) (*inconsist) = n_occ;
    return occ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %esi
leaq -0x54(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x60(%rbp), %r9
movq %r8, %rcx
movq $0x0, (%rsp)
callq 0x37d4d0
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x35256c
jmp 0x35258b
leaq 0x46c99(%rip), %rdi     # 0x39920c
leaq 0x43c3f(%rip), %rsi     # 0x3961b9
movl $0x2cda, %edx           # imm = 0x2CDA
leaq 0x46c99(%rip), %rcx     # 0x39921f
callq 0x2130
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x352440
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x352440
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x352822
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x352812
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x38(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
je 0x352602
jmp 0x352804
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
addq -0x60(%rbp), %rax
movq -0x38(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jne 0x3526fe
cmpq $0x0, -0x28(%rbp)
je 0x3526f0
jmp 0x35263e
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3526a6
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x35266b
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x352676
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x352676
movq -0x68(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %edx
shlq $0x20, %rdx
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
orq %rax, %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x3526f0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x352802
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x38(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
addq -0x60(%rbp), %rcx
cmpq %rcx, %rax
jne 0x3527f7
cmpq $0x0, -0x28(%rbp)
je 0x3527ec
jmp 0x35273a
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3527a2
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x352767
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x352772
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x352772
movq -0x70(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %edx
shlq $0x20, %rdx
movq -0x38(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
orq %rax, %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x3527ec
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x352800
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x352802
jmp 0x352804
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x3525cd
jmp 0x352814
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3525ba
cmpq $0x0, -0x20(%rbp)
je 0x352832
movl -0x50(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x4c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop