// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq %rdi, %r15
movq %rsi, 0x28(%rsp)
movq (%rsi), %r12
movq %r12, 0x10(%rsp)
shrq $0x20, %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %r12d, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eac53
leaq 0x30(%rsp), %r13
leaq 0x18(%rsp), %rbx
cmpl $0x0, 0xc(%rax)
js 0x1eac40
movl 0x8(%rax), %r14d
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ebp
xorl %eax, %eax
cmpl %ebp, %r14d
je 0x1eadcd
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x30(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eac40
cmpl $0x0, 0xc(%rax)
js 0x1eac1d
cmpl %ebp, 0x8(%rax)
jne 0x1eac1d
jmp 0x1eadba
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x1ea827
testq %rax, %rax
jne 0x1eabf1
movq 0x8(%rsp), %rdi
movq (%rdi), %r14
movq 0x8(%rdi), %rax
movl 0x10(%rsp), %ecx
addq 0x28(%r15), %rcx
movq %rcx, 0x10(%rsp)
cmpq %rax, %r14
jne 0x1eaca0
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rdi)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rdi)
movq (%rdi), %rax
movq 0x10(%rdi), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rdi)
movq %r12, (%rcx,%rax,8)
movl %r14d, %ecx
movq (%rdi), %rsi
movl $0x1, %eax
movq %rcx, 0x20(%rsp)
cmpq %rcx, %rsi
jbe 0x1eadc5
leaq 0x18(%rsp), %rbp
movq 0x10(%rdi), %rcx
leaq -0x1(%rsi), %rdx
movq %rdx, (%rdi)
movq -0x8(%rcx,%rsi,8), %r13
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eada0
movq %r13, %rbx
shrq $0x20, %rbx
cmpl $0x0, 0xc(%rax)
js 0x1ead89
movl (%rax), %r14d
addq %rbx, %r14
cmpq 0x10(%rsp), %r14
ja 0x1ead89
movl 0x8(%rax), %r12d
movq 0x28(%rsp), %rax
cmpl 0x8(%rax), %r12d
je 0x1eadbe
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, (%rdi)
jne 0x1ead70
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rdi)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rdi)
shlq $0x20, %r14
orq %r12, %r14
movq (%rdi), %rax
movq 0x10(%rdi), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rdi)
movq %r14, (%rcx,%rax,8)
movq %r15, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x1ea827
testq %rax, %rax
jne 0x1ead0d
movq 0x8(%rsp), %rdi
movq (%rdi), %rsi
cmpq 0x20(%rsp), %rsi
ja 0x1eacd0
movl $0x1, %eax
jmp 0x1eadc5
xorl %eax, %eax
jmp 0x1eadcd
xorl %eax, %eax
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq %rcx, (%rdi)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq