// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: u2g_n_hybrid_thread(usg_t*, unsigned int, asg64_v*, asg64_v*)
uint32_t u2g_n_hybrid_thread(usg_t *ng, uint32_t no_inconsist, asg64_v *in, asg64_v *buf)
{
    if(in->n < 1) return 0;
    uint32_t k, i, v, w, in_n = in->n, mm, ov[2], kv[2], cnt = 0; uint64_t *a, a_n;
    for (k = 0; k < in->n; k++) {
        v = (uint32_t)in->a[k]; in_n = in->n;
        if(get_usg_unitig(ng, v^1, &w, NULL, NULL, NULL, NULL) == LOOP) continue;
        mm = get_junction_w(ng, v, w, no_inconsist, in);
        if(mm == (uint32_t)-1) {
            in->n = in_n; continue;
        }
        if(in->n == in_n) continue;

        ov[0] = ov[1] = 0; a = in->a + in_n; a_n = in->n - in_n;
        for (i = 0; i < a_n; i++) {
            if((a[i]>>32) == v) ov[0]++;
            if((a[i]>>32) == w) ov[1]++;
        }

        kv[0] = undel_arcs(ng, v, NULL); kv[1] = undel_arcs(ng, w, NULL);
        assert(ov[0] == ov[1] && ov[0] <= kv[0] && ov[1] <= kv[1]); 
        if((ov[0] == kv[0] && ov[1] < kv[1]) || (ov[0] < kv[0] && ov[1] == kv[1])) {
            in->n = in_n; continue;
        }
        
        for (i = 0; i < a_n; i += 2) {
            update_dual_junction(ng, a[i]>>32, (uint32_t)a[i], a[i+1]>>32, (uint32_t)a[i+1], buf);
        }
        cnt++; in->n = in_n;
    }

    return cnt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x1, (%rax)
jae 0x354130
movl $0x0, -0x4(%rbp)
jmp 0x3543bc
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x3543b6
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
leaq -0x38(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rcx
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x37d4d0
cmpl $0x7, %eax
jne 0x3541a4
jmp 0x3543a8
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %r8
callq 0x3529b0
movl %eax, -0x40(%rbp)
cmpl $-0x1, -0x40(%rbp)
jne 0x3541d4
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x3543a8
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x3541e8
jmp 0x3543a8
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpq -0x68(%rbp), %rax
jae 0x35427a
movq -0x60(%rbp), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x34(%rbp), %ecx
cmpq %rcx, %rax
jne 0x35424d
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x60(%rbp), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x38(%rbp), %ecx
cmpq %rcx, %rax
jne 0x35426d
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x35426f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x354224
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x37d7e0
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x37d7e0
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %ecx
xorl %eax, %eax
cmpl -0x44(%rbp), %ecx
movb %al, -0x69(%rbp)
jne 0x3542c6
movl -0x48(%rbp), %ecx
xorl %eax, %eax
cmpl -0x50(%rbp), %ecx
movb %al, -0x69(%rbp)
ja 0x3542c6
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
setbe %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x3542cf
jmp 0x3542d1
jmp 0x3542f0
leaq 0x450fc(%rip), %rdi     # 0x3993d4
leaq 0x41eda(%rip), %rsi     # 0x3961b9
movl $0x2dd2, %edx           # imm = 0x2DD2
leaq 0x4511c(%rip), %rcx     # 0x399407
callq 0x2130
movl -0x48(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x354300
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jb 0x354310
movl -0x48(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x354321
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jne 0x354321
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x3543a8
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpq -0x68(%rbp), %rax
jae 0x354393
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %esi
movq -0x60(%rbp), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x60(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl -0x30(%rbp), %r8d
addl $0x1, %r8d
movl %r8d, %r8d
movq (%rax,%r8,8), %rax
movl %eax, %r8d
movq -0x28(%rbp), %r9
callq 0x353680
movl -0x30(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x354328
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x354148
movl -0x54(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)