// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: integer_align_extention(ma_ug_t*, all_ul_t*, long, ul_str_t*, long, ul_str_t*, long, unsigned long*, unsigned long*, integer_aln_t*, long, long*, long*)
void integer_align_extention(ma_ug_t *ug, all_ul_t *ul_idx, int64_t qid, ul_str_t *q_str, int64_t tid, ul_str_t *t_str, int64_t is_rev,
uint64_t *q_cov_buf, uint64_t *t_cov_buf, integer_aln_t *aln_pair, int64_t is_backward, int64_t *r_q_end, int64_t *r_t_end)
{
    int64_t qk, tk, qoff, toff, qlen, tlen, ext, q_end, t_end; uc_block_t *q_b, *t_b;
    qk = (uint32_t)(aln_pair->tn_rev_qk); tk = ((is_rev == 0)? (aln_pair->tk):(t_str->cn - aln_pair->tk - 1));
    q_b = &(ul_idx->a[qid].bb.a[q_str->a[qk]>>32]); t_b = &(ul_idx->a[tid].bb.a[t_str->a[tk]>>32]);
    qlen = ul_idx->a[qid].rlen; tlen = ul_idx->a[tid].rlen;

    if(is_backward) {
        qoff = q_b->qs; toff = (is_rev?(tlen-t_b->qe):(t_b->qs));
    } else {
        qoff = qlen - q_b->qe; toff = (is_rev?(t_b->qs):(tlen-t_b->qe));
    }

    if (qoff <= toff) ext = qoff;
    else ext = toff;
    
    if(is_backward) {
        q_end = estimate_ul_len(ug, &(ul_idx->a[qid]), q_str, qk, -ext, q_cov_buf);
        t_end = estimate_ul_len(ug, &(ul_idx->a[tid]), t_str, tk, ((is_rev)?(ext):(-ext)), t_cov_buf);
    } else {
        q_end = estimate_ul_len(ug, &(ul_idx->a[qid]), q_str, qk, ext, q_cov_buf);
        t_end = estimate_ul_len(ug, &(ul_idx->a[tid]), t_str, tk, ((is_rev)?(-ext):(ext)), t_cov_buf);
    }

    (*r_q_end) = q_end; (*r_t_end) = t_end;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %rdi, %r14
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %r10
movl 0x10(%r10), %eax
cmpq $0x0, 0x40(%rsp)
je 0x1b4d97
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl 0x18(%rbx), %r9d
movl (%r10), %r10d
notl %r10d
addl %r9d, %r10d
jmp 0x1b4d9a
movl (%r10), %r10d
movq 0x70(%rsp), %r15
movq 0x48(%rsp), %r9
movl %r10d, %r13d
movq %rsi, (%rsp)
movq 0x48(%rsi), %r11
imulq $0x58, %rdx, %rdx
leaq (%r11,%rdx), %rsi
movq 0x10(%rcx), %r10
movl 0x4(%r10,%rax,8), %r10d
imulq $0x24, %r10, %r10
addq 0x30(%r11,%rdx), %r10
imulq $0x58, %r8, %rbp
movq 0x10(%rbx), %rdx
movl 0x4(%rdx,%r13,8), %edx
imulq $0x24, %rdx, %rdx
addq 0x30(%r11,%rbp), %rdx
movl 0x18(%r11,%rbp), %r12d
testq %rdi, %rdi
je 0x1b4dfd
movl 0x4(%r10), %r15d
cmpq $0x0, 0x40(%rsp)
je 0x1b4e15
movl 0x8(%rdx), %edx
subq %rdx, %r12
jmp 0x1b4e19
movl 0x18(%rsi), %edi
movl 0x8(%r10), %r8d
subq %r8, %rdi
cmpq $0x0, 0x40(%rsp)
je 0x1b4e6c
movl 0x4(%rdx), %r12d
jmp 0x1b4e72
movl 0x4(%rdx), %r12d
cmpq %r15, %r12
cmovlq %r12, %r15
movq %r15, %r12
negq %r12
movq %r14, %rdi
movq %rcx, %rdx
movq %rax, %rcx
movq %r12, %r8
callq 0x1b49b5
movq (%rsp), %rcx
addq 0x48(%rcx), %rbp
movq %r14, %rdi
movq %rax, %r14
cmpq $0x0, 0x40(%rsp)
cmovneq %r15, %r12
movq %rbp, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq %r12, %r8
movq 0x50(%rsp), %r9
callq 0x1b49b5
movq 0x70(%rsp), %r15
jmp 0x1b4ebb
movl 0x8(%rdx), %edx
subq %rdx, %r12
cmpq %r12, %rdi
cmovlq %rdi, %r12
movq %r14, %rdi
movq %rcx, %rdx
movq %rax, %rcx
movq %r12, %r8
callq 0x1b49b5
movq %r14, %rdi
movq %rax, %r14
movq (%rsp), %rax
addq 0x48(%rax), %rbp
movq %r12, %r8
negq %r8
cmpq $0x0, 0x40(%rsp)
cmoveq %r12, %r8
movq %rbp, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq 0x50(%rsp), %r9
callq 0x1b49b5
movq 0x68(%rsp), %rcx
movq %r14, (%rcx)
movq %rax, (%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq