// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: dis_check_integer_aln_t(all_ul_t*, ul_str_idx_t*, ma_ug_t*, integer_aln_t*, integer_aln_t*, unsigned int, unsigned int, unsigned int, double, long)
uint32_t dis_check_integer_aln_t(all_ul_t *ul_idx, ul_str_idx_t *str_idx, ma_ug_t *ug, integer_aln_t *li, integer_aln_t *lk, 
uint32_t qid, uint32_t tid, uint32_t is_rev, double diff_rate, int64_t hard_thres)
{
    assert(((uint32_t)li->tn_rev_qk) >= ((uint32_t)lk->tn_rev_qk));
    if(((uint32_t)li->tn_rev_qk) == ((uint32_t)lk->tn_rev_qk)) return 0;
    if(li->tk <= lk->tk) return 0;
    ul_str_t *q = &(str_idx->str.a[qid]), *t = &(str_idx->str.a[tid]);
    uc_block_t *iq, *it, *kq, *kt; int64_t qlen, tlen, mm, dd, i_qk, k_qk, i_tk, k_tk;
    i_qk = ((uint32_t)li->tn_rev_qk); k_qk = ((uint32_t)lk->tn_rev_qk);
    if(!is_rev) {
        i_tk = li->tk; k_tk = lk->tk;
    } else {
        i_tk = t->cn - lk->tk - 1; k_tk = t->cn - li->tk - 1;
    }
    iq = &(ul_idx->a[qid].bb.a[(q->a[i_qk]>>32)]);
    it = &(ul_idx->a[tid].bb.a[(t->a[i_tk]>>32)]);

    kq = &(ul_idx->a[qid].bb.a[(q->a[k_qk]>>32)]); 
    kt = &(ul_idx->a[tid].bb.a[(t->a[k_tk]>>32)]);
    qlen = normlize_gdis(ug, iq, kq, 0); tlen = normlize_gdis(ug, it, kt, is_rev);
    if(qlen < tlen) {
        mm = qlen; dd = tlen - qlen;
    } else {
        mm = tlen; dd = qlen - tlen;
    }

    // if(tid == 3074) {
    //     fprintf(stderr, "\n+++[M::%s::] qlen::%ld, tlen::%ld, iq->hid::%u, kq->hid::%u, (q->a[i_qk]>>32)::%lu, (q->a[k_qk]>>32)::%lu, (t->a[i_tk]>>32)::%lu, (t->a[k_tk]>>32)::%lu\n", 
    //     __func__, qlen, tlen, iq->hid, kq->hid, 
    //     (q->a[i_qk]>>32), (q->a[k_qk]>>32), (t->a[i_tk]>>32), (t->a[k_tk]>>32));
    // }

    if(dd <= (mm*diff_rate) || dd < hard_thres) return 1;
    
    qlen = normlize_gdis_exact(ug, ul_idx->a[qid].bb.a, (q->a[i_qk]>>32), (q->a[k_qk]>>32), 0);
    tlen = normlize_gdis_exact(ug, ul_idx->a[tid].bb.a, (t->a[i_tk]>>32), (t->a[k_tk]>>32), is_rev);
    if(qlen < tlen) {
        mm = qlen; dd = tlen - qlen;
    } else {
        mm = tlen; dd = qlen - tlen;
    }

    if(dd <= (mm*diff_rate) || dd < hard_thres) return 1;

    // if(tid == 3074) {
    //     fprintf(stderr, "---[M::%s::] qlen::%ld, tlen::%ld, iq->hid::%u, kq->hid::%u\n", 
    //     __func__, qlen, tlen, iq->hid, kq->hid);
    // }
    

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movsd %xmm0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl %ecx, %eax
jb 0x329038
jmp 0x329057
leaq 0x6de51(%rip), %rdi     # 0x396e90
leaq 0x6d173(%rip), %rsi     # 0x3961b9
movl $0x1168, %edx           # imm = 0x1168
leaq 0x6de75(%rip), %rcx     # 0x396ec7
callq 0x2130
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl %ecx, %eax
jne 0x329077
movl $0x0, -0x4(%rbp)
jmp 0x3293f5
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
ja 0x329091
movl $0x0, -0x4(%rbp)
jmp 0x3293f5
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x34(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x10(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0xa0(%rbp)
cmpl $0x0, 0x18(%rbp)
jne 0x329101
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq %rax, -0xb0(%rbp)
jmp 0x32913d
movq -0x50(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rcx
subl (%rcx), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0xa8(%rbp)
movq -0x50(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x28(%rbp), %rcx
subl (%rcx), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x98(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x10(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xa8(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xa0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x10(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rax
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xb0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x68(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x328b90
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl 0x18(%rbp), %eax
movl %eax, %ecx
callq 0x328b90
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x329276
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x329290
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
subq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
cvtsi2sdq -0x90(%rbp), %xmm1
cvtsi2sdq -0x88(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x3292ba
movq -0x90(%rbp), %rax
cmpq 0x20(%rbp), %rax
jge 0x3292c6
movl $0x1, -0x4(%rbp)
jmp 0x3293f5
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rsi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %edx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xa0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x328ce0
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x10(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rsi
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xa8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xb0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
movl 0x18(%rbp), %eax
movl %eax, %r8d
callq 0x328ce0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x3293a1
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
subq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x3293bb
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
subq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
cvtsi2sdq -0x90(%rbp), %xmm1
cvtsi2sdq -0x88(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x3293e5
movq -0x90(%rbp), %rax
cmpq 0x20(%rbp), %rax
jge 0x3293ee
movl $0x1, -0x4(%rbp)
jmp 0x3293f5
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)