// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq 0x10(%rcx), %rdx
movq 0x10(%r8), %r10
cmpl %r10d, %edx
jb 0x1b377e
xorl %eax, %eax
cmpl %r10d, %edx
je 0x1b376f
movl (%rcx), %ebp
movl (%r8), %r8d
cmpl %r8d, %ebp
jbe 0x1b376f
movl %edx, %ecx
movl %r10d, %eax
movq 0x40(%rsi), %rsi
movl %r9d, %r9d
movl 0x70(%rsp), %edx
movq %rdx, %rbx
shlq $0x5, %rbx
addq %rsi, %rbx
cmpl $0x0, 0x78(%rsp)
movsd %xmm0, (%rsp)
je 0x1b35ff
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl 0x18(%rbx), %r10d
notl %r8d
addl %r10d, %r8d
notl %ebp
movl %ebp, %r11d
addl %r10d, %r11d
movl %r8d, %ebp
movl %r11d, %r8d
movl %r8d, %r10d
movl %ebp, %r11d
movq %rdi, 0x28(%rsp)
movq 0x48(%rdi), %rdi
imulq $0x58, %r9, %r8
movq 0x30(%rdi,%r8), %r14
shlq $0x5, %r9
movq 0x10(%rsi,%r9), %r8
movq (%r8,%rcx,8), %r12
shrq $0x20, %r12
imulq $0x24, %r12, %rsi
addq %r14, %rsi
imulq $0x58, %rdx, %rcx
movq %rcx, 0x8(%rsp)
movq 0x30(%rdi,%rcx), %rcx
movq 0x10(%rbx), %rdi
movq %r11, 0x18(%rsp)
movl 0x4(%rdi,%r11,8), %edx
imulq $0x24, %rdx, %rbp
addq %rcx, %rbp
movq (%r8,%rax,8), %r13
shrq $0x20, %r13
imulq $0x24, %r13, %rdx
movq %r14, 0x10(%rsp)
addq %r14, %rdx
movq %r10, 0x20(%rsp)
movl 0x4(%rdi,%r10,8), %eax
imulq $0x24, %rax, %r14
addq %rcx, %r14
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x1b3351
movq %r15, %rdi
movq %rax, %r15
movl 0x78(%rsp), %ecx
movq %rdi, 0x30(%rsp)
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1b3351
movq %rax, %rcx
movq %r15, %rax
subq %rcx, %rax
cmovlq %r15, %rcx
movq %rax, %rdx
negq %rdx
cmovsq %rax, %rdx
pushq $0x1
popq %rax
movq 0x80(%rsp), %rbp
cmpq %rbp, %rdx
jl 0x1b376f
cvtsi2sd %rdx, %xmm0
cvtsi2sd %rcx, %xmm1
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r14
jae 0x1b376f
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x1b33db
movq %r14, %rcx
movq %rax, %r14
movq 0x48(%rcx), %rax
movq 0x8(%rsp), %rcx
movq 0x30(%rax,%rcx), %rsi
movq 0x10(%rbx), %rax
movq 0x18(%rsp), %rcx
movl 0x4(%rax,%rcx,8), %edx
movq 0x20(%rsp), %rcx
movl 0x4(%rax,%rcx,8), %ecx
movq %r15, %rdi
movl 0x78(%rsp), %r8d
callq 0x1b33db
movq %r14, %rcx
subq %rax, %rcx
cmovlq %r14, %rax
movq %rcx, %rdx
negq %rdx
cmovsq %rcx, %rdx
cvtsi2sd %rdx, %xmm0
cvtsi2sd %rax, %xmm1
mulsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
setae %al
cmpq %rbp, %rdx
setl %cl
orb %al, %cl
movzbl %cl, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x44a2b(%rip), %rdi     # 0x1f81b0
leaq 0x43d4d(%rip), %rsi     # 0x1f74d9
leaq 0x44a54(%rip), %rcx     # 0x1f81e7
movl $0x1168, %edx           # imm = 0x1168
callq 0x2110