// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rdx, 0x8(%rsp)
movq %rdi, %r15
movq %rsi, 0x28(%rsp)
movq (%rsi), %rbx
movq %rbx, %r13
shrq $0x20, %r13
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
movl %r13d, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f5763
leaq 0x40(%rsp), %r12
cmpl $0x0, 0xc(%rax)
js 0x1f574e
movl 0x8(%rax), %ebp
movq 0x28(%rsp), %rax
movl 0x8(%rax), %r14d
xorl %eax, %eax
cmpl %r14d, %ebp
je 0x1f5911
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x40(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f574e
cmpl $0x0, 0xc(%rax)
js 0x1f572e
cmpl %r14d, 0x8(%rax)
jne 0x1f572e
jmp 0x1f57ac
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movl %r13d, %edx
callq 0x1f5346
testq %rax, %rax
jne 0x1f5702
movq %rbx, %rax
movq 0x8(%rsp), %rbx
movq (%rbx), %rbp
movl %eax, %r12d
addq 0x28(%r15), %r12
cmpq 0x8(%rbx), %rbp
jne 0x1f57b3
leaq (,%rbp,2), %rax
testq %rbp, %rbp
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, %rdx
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
jmp 0x1f57ba
xorl %eax, %eax
jmp 0x1f5911
movq 0x10(%rbx), %rdx
movq %rbp, %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movq %r13, (%rdx,%rax,8)
movl %ebp, %ecx
movq (%rbx), %r14
movl $0x1, %eax
movq %rcx, 0x20(%rsp)
cmpq %rcx, %r14
jbe 0x1f5904
leaq 0x18(%rsp), %rbx
movq %r14, %rax
decq %r14
movq 0x8(%rsp), %rcx
movq %r14, (%rcx)
movq %rdx, 0x10(%rsp)
movq -0x8(%rdx,%rax,8), %rbp
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f58eb
movq %rbp, %r14
shrq $0x20, %r14
movq %rbp, 0x38(%rsp)
movq %r14, 0x30(%rsp)
cmpl $0x0, 0xc(%rax)
js 0x1f58cd
movl (%rax), %r13d
addq %r14, %r13
cmpq %r12, %r13
ja 0x1f58cd
movq %r15, %rbp
movq %rbx, %r15
movq %r12, %rbx
movl 0x8(%rax), %r12d
movq 0x28(%rsp), %rax
cmpl 0x8(%rax), %r12d
je 0x1f5902
movq 0x8(%rsp), %r14
movq (%r14), %rdx
cmpq 0x8(%r14), %rdx
jne 0x1f589e
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq 0x10(%rsp), %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rdx
jmp 0x1f58a3
movq 0x10(%rsp), %rax
shlq $0x20, %r13
orq %r12, %r13
leaq 0x1(%rdx), %rcx
movq %rcx, (%r14)
movq %rax, 0x10(%rsp)
movq %r13, (%rax,%rdx,8)
movq %rbx, %r12
movq %r15, %rbx
movq %rbp, %r15
movq 0x38(%rsp), %rbp
movq 0x30(%rsp), %r14
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
jne 0x1f5830
movq 0x8(%rsp), %rax
movq (%rax), %r14
cmpq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdx
ja 0x1f57e2
movl $0x1, %eax
jmp 0x1f5904
xorl %eax, %eax
movq 0x8(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, (%rcx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq