// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: trans_check(flex_asg_t*, asg_arc_t*, asg64_v*)
uint32_t trans_check(flex_asg_t *fg, asg_arc_t *z, asg64_v *b)
{
    flex_asg_e_retrive_t rv, rw; asg_arc_t *sv, *sw; 
    uint32_t v = z->ul>>32, w;

    rv.i[0] = 0; rv.i[1] = (uint32_t)-1;
    while(1) {
        sv = iter_flex_asg(fg, &rv, v);
        if(!sv) break;
        if(sv->del) continue;
        if(sv->v == z->v) return 0;
        w = sv->v;
        // if((z->ul>>33) == 8340 && (z->v>>1) == 8352) {
        //     fprintf(stderr, "+[M::%s] v>>1::%u(%c), w>>1::%u(%c), sv->v::%u\n", 
        //     __func__, (z->ul>>33), "+-"[(z->ul>>32)&1], (z->v>>1), "+-"[z->v&1], sv->v);
        // }

        rw.i[0] = 0; rw.i[1] = (uint32_t)-1;
        while (1) {
            sw = iter_flex_asg(fg, &rw, w);
            if(!sw) break;
            if(sw->del) continue;
            if(sw->v == z->v) return 0;
        }
    }


    uint32_t bn = b->n; uint64_t vl, d, L = asg_arc_len((*z)) + fg->gap_fuzz;
    kv_push(uint64_t, *b, v);
    while (b->n > bn) {
        vl = kv_pop(*b); v = (uint32_t)vl; vl >>= 32;
        rv.i[0] = 0; rv.i[1] = (uint32_t)-1;
         while(1) {
            sv = iter_flex_asg(fg, &rv, v);
            if(!sv) break;
            if(sv->del) continue;
            d = vl + asg_arc_len((*sv));
            if(d > L) continue;
            if(sv->v == z->v) {
                b->n = bn;
                return 0;
            }
            d <<= 32; d |= sv->v;
            kv_push(uint64_t, *b, d); 
         }
    }

    b->n = bn;
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x10(%rsp)
movq %rdi, %r15
movq %rsi, 0x20(%rsp)
movq (%rsi), %r13
movq %r13, 0x8(%rsp)
shrq $0x20, %r13
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x28(%rsp), %rcx
movq %rcx, %rbp
movq %rax, (%rcx)
leaq 0x30(%rsp), %r12
movq %r15, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa742
cmpl $0x0, 0xc(%rax)
js 0x1aa6d8
movl 0x8(%rax), %r14d
movq 0x20(%rsp), %rax
movl 0x8(%rax), %ebx
xorl %eax, %eax
cmpl %ebx, %r14d
je 0x1aa733
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x30(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa6d8
cmpl $0x0, 0xc(%rax)
js 0x1aa713
cmpl %ebx, 0x8(%rax)
jne 0x1aa713
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%rsp), %r12d
addq 0x28(%r15), %r12
movq 0x10(%rsp), %rdx
movq (%rdx), %rbx
pushq $0x2
popq %rax
cmpq 0x8(%rdx), %rbx
jne 0x1aa786
leaq (%rbx,%rbx), %rsi
testq %rbx, %rbx
cmoveq %rax, %rsi
movq %rsi, 0x8(%rdx)
movq 0x10(%rdx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x10(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq (%rdx), %rsi
jmp 0x1aa78d
movq 0x10(%rdx), %rax
movq %rbx, %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, (%rdx)
movq %r13, (%rax,%rsi,8)
movl %ebx, %ecx
movq %rcx, 0x18(%rsp)
leaq 0x28(%rsp), %r13
movq (%rdx), %rsi
cmpq 0x18(%rsp), %rsi
jbe 0x1aa883
leaq -0x1(%rsi), %rcx
movq %rcx, (%rdx)
movq %rax, 0x8(%rsp)
movq -0x8(%rax,%rsi,8), %r14
movq %r14, %rbp
shrq $0x20, %rbp
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x28(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x1aa378
testq %rax, %rax
je 0x1aa874
cmpl $0x0, 0xc(%rax)
js 0x1aa7d9
movl (%rax), %ebx
addq %rbp, %rbx
cmpq %r12, %rbx
ja 0x1aa7d9
movl 0x8(%rax), %ecx
movq 0x20(%rsp), %rax
cmpl 0x8(%rax), %ecx
je 0x1aa888
movq 0x10(%rsp), %rdx
movq (%rdx), %rdi
cmpq 0x8(%rdx), %rdi
jne 0x1aa853
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x3, %rsi
movq 0x8(%rsp), %rdi
movq %rcx, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq %rax, 0x10(%rdx)
movq (%rdx), %rdi
jmp 0x1aa858
movq 0x8(%rsp), %rax
shlq $0x20, %rbx
orq %rcx, %rbx
leaq 0x1(%rdi), %rcx
movq %rcx, (%rdx)
movq %rax, 0x8(%rsp)
movq %rbx, (%rax,%rdi,8)
jmp 0x1aa7d9
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rax
jmp 0x1aa7a4
pushq $0x1
popq %rax
jmp 0x1aa88f
xorl %eax, %eax
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %rcx, (%rdx)
jmp 0x1aa733