// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpq -0x20(%rbp), %rax
jae 0x31a730
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpq -0x20(%rbp), %rax
jae 0x31a720
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
xorq $0x1, %rax
movl %eax, -0x40(%rbp)
movq -0x48(%rbp), %rdi
movl -0x3c(%rbp), %esi
shrl %esi
movl -0x40(%rbp), %edx
shrl %edx
callq 0xce1b0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x31a44d
movq -0x48(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0x31a459
movl $0x0, -0x4(%rbp)
jmp 0x31a737
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq 0xaae5e(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0xaae46(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
cvtsi2ssq 0x18(%rax), %xmm0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %r8d
leaq -0x60(%rbp), %r9
callq 0x31a080
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0x31a4d8
movl $0x0, -0x4(%rbp)
jmp 0x31a737
movq -0x60(%rbp), %rax
shrq $0x20, %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
jne 0x31a4f0
movl -0x58(%rbp), %eax
cmpl -0x40(%rbp), %eax
je 0x31a4fc
movl $0x0, -0x4(%rbp)
jmp 0x31a737
movq -0x48(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
cmpl $0x3fff, %eax           # imm = 0x3FFF
jbe 0x31a52d
movl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0x7c(%rbp)
jmp 0x31a550
movq -0x48(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movw %ax, %cx
movw -0x50(%rbp), %ax
andw $0x3fff, %cx            # imm = 0x3FFF
andw $0xc000, %ax            # imm = 0xC000
orw %cx, %ax
movw %ax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
movl -0x40(%rbp), %eax
shrl %eax
movl %eax, %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl -0x40(%rbp), %esi
shrl %esi
movl -0x3c(%rbp), %edx
shrl %edx
callq 0xce1b0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x31a5c1
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0x31a5cd
movl $0x0, -0x4(%rbp)
jmp 0x31a737
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq 0xaacdc(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
leaq 0xaacc4(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
cvtsi2ssq 0x18(%rax), %xmm0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %r8d
leaq -0x78(%rbp), %r9
callq 0x31a080
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0x31a65a
movl $0x0, -0x4(%rbp)
jmp 0x31a737
movq -0x78(%rbp), %rax
shrq $0x20, %rax
movl -0x40(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x31a67c
movl -0x70(%rbp), %eax
movl -0x3c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
je 0x31a688
movl $0x0, -0x4(%rbp)
jmp 0x31a737
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
cmpl $0x3fff, %eax           # imm = 0x3FFF
jbe 0x31a6c7
movl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0x80(%rbp)
jmp 0x31a6f8
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movw %ax, %cx
movw -0x68(%rbp), %ax
andw $0x3fff, %cx            # imm = 0x3FFF
andw $0xc000, %ax            # imm = 0xC000
orw %cx, %ax
movw %ax, -0x68(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x31a3f3
jmp 0x31a722
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x31a3b9
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)