// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: append_trans_check(flex_asg_t*, unsigned long*, unsigned long)
uint32_t append_trans_check(flex_asg_t *fg, uint64_t *a, uint64_t a_n)
{
    ma_hit_t_alloc* src = fg->src; int32_t idx, r; 
    uint32_t i, k, v, w; ma_hit_t_alloc *z; asg_arc_t t0, t1; 
    for (i = 0; i < a_n; i++) {
        v = a[i]; 
        z = &(src[v>>1]);
        for (k = i + 1; k < a_n; k++) {
            w = a[k]^1;
            idx = get_specific_overlap(z, v>>1, w>>1);
            if(idx < 0 || z->buffer[idx].del) return 0;
            r = ma_hit2arc(&(z->buffer[idx]), Get_READ_LENGTH(R_INF, v>>1), Get_READ_LENGTH(R_INF, w>>1),
                        fg->max_hang, fg->max_hang_rate, fg->min_ovlp, &t0);
            if(r < 0) return 0;
            if((t0.ul>>32) != v || t0.v != w) return 0;
            t0.ou = ((z->buffer[idx].bl>OU_MASK)?OU_MASK:z->buffer[idx].bl);
            // if((v>>1) == 8340 && (w>>1) == 8352) {
            //     fprintf(stderr, "[M::%s] v>>1::%u(%c), w>>1::%u(%c), t0.ou::%u\n", 
            //     __func__, (v>>1), "+-"[v&1], (w>>1), "+-"[w&1], t0.ou);
            // }


            idx = get_specific_overlap(&(src[w>>1]), w>>1, v>>1);
            if(idx < 0 || src[w>>1].buffer[idx].del) return 0;
            r = ma_hit2arc(&(src[w>>1].buffer[idx]), Get_READ_LENGTH(R_INF, w>>1), Get_READ_LENGTH(R_INF, v>>1),
                        fg->max_hang, fg->max_hang_rate, fg->min_ovlp, &t1);
            if(r < 0) return 0;
            if((t1.ul>>32) != (w^1) || t1.v != (v^1)) return 0;
            t1.ou = ((src[w>>1].buffer[idx].bl>OU_MASK)?OU_MASK:src[w>>1].buffer[idx].bl);
        }
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbp
movq %rsi, 0x20(%rsp)
movq %rdi, %r15
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movq %rdx, 0x28(%rsp)
movl %eax, %eax
cmpq %rbp, %rax
jae 0x1ab00b
movq 0x20(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movl %ecx, %edx
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
shrl %ecx
movq %rcx, 0x8(%rsp)
imulq $0x18, %rcx, %rbx
addq 0x18(%rsp), %rbx
incl %eax
movl %eax, 0x14(%rsp)
movl %eax, %r13d
movq %rbx, 0x30(%rsp)
movl %r13d, %r13d
cmpq %rbp, %r13
jae 0x1ab002
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %r12
movl %r12d, %r14d
shrl %r14d
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl %r14d, %edx
callq 0x696ab
movl $0x0, 0x4(%rsp)
testl %eax, %eax
js 0x1ab012
movq (%rbx), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
imulq $0x28, %rax, %rax
movq 0x18(%rdi,%rax), %rbx
testq %rbx, %rbx
js 0x1ab012
addq %rax, %rdi
leaq 0xa9377(%rip), %rax     # 0x254230
movq 0x18(%rax), %rax
movq 0x8(%rsp), %rcx
movl (%rax,%rcx,8), %esi
movl %r14d, %ebp
movl (%rax,%rbp,8), %edx
movl 0x8(%r15), %r8d
movl 0x10(%r15), %ecx
cvtsi2ssq 0x18(%r15), %xmm0
leaq 0x60(%rsp), %r9
callq 0x1aac6d
testl %eax, %eax
js 0x1ab012
movq 0x40(%rsp), %rax
cmpl %eax, 0x64(%rsp)
jne 0x1ab012
movl 0x68(%rsp), %eax
xorl %r12d, %eax
cmpl $0x1, %eax
jne 0x1ab012
movq %rbx, %rax
shrq $0x20, %rax
movl $0x3fff, %edx           # imm = 0x3FFF
andl %edx, %eax
movabsq $0x400000000000, %rcx   # imm = 0x400000000000
cmpq %rcx, %rbx
cmovael %edx, %eax
movl 0x70(%rsp), %ecx
movl $0xffffc000, %edx       # imm = 0xFFFFC000
andl %edx, %ecx
orl %eax, %ecx
movw %cx, 0x70(%rsp)
imulq $0x18, %rbp, %rbx
addq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
movq 0x8(%rsp), %rdx
callq 0x696ab
testl %eax, %eax
js 0x1ab012
movq (%rbx), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
imulq $0x28, %rax, %rax
movq 0x18(%rdi,%rax), %rbx
testq %rbx, %rbx
js 0x1ab012
addq %rax, %rdi
leaq 0xa92b1(%rip), %rax     # 0x254230
movq 0x18(%rax), %rax
movl (%rax,%rbp,8), %esi
movq 0x8(%rsp), %rcx
movl (%rax,%rcx,8), %edx
movl 0x8(%r15), %r8d
movl 0x10(%r15), %ecx
cvtsi2ssq 0x18(%r15), %xmm0
leaq 0x48(%rsp), %r9
callq 0x1aac6d
testl %eax, %eax
js 0x1ab012
movl %r12d, %eax
cmpl %eax, 0x4c(%rsp)
jne 0x1ab012
movl 0x50(%rsp), %eax
xorl 0x38(%rsp), %eax
cmpl $0x1, %eax
jne 0x1ab012
movq %rbx, %rax
shrq $0x20, %rax
movl $0x3fff, %edx           # imm = 0x3FFF
andl %edx, %eax
movabsq $0x400000000000, %rcx   # imm = 0x400000000000
cmpq %rcx, %rbx
cmovael %edx, %eax
movl 0x58(%rsp), %ecx
movl $0xffffc000, %edx       # imm = 0xFFFFC000
andl %edx, %ecx
orl %eax, %ecx
movw %cx, 0x58(%rsp)
incl %r13d
movq 0x28(%rsp), %rbp
movq 0x30(%rsp), %rbx
jmp 0x1aae5a
movl 0x14(%rsp), %eax
jmp 0x1aae1c
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq