// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: append_aligned_integer_seq_by_aln_pair(ma_ug_t*, uc_block_t*, poa_g_t*, long, unsigned long*, long, unsigned long, integer_aln_t*, long, long, long)
void append_aligned_integer_seq_by_aln_pair(ma_ug_t *ug, uc_block_t *raw, poa_g_t *g, int64_t g_occ, uint64_t *str, int64_t str_occ, uint64_t is_rev, integer_aln_t *a, int64_t a_n, int64_t str_id, int64_t str_off)
{
    if(str_occ <= 0 || a_n <= 0) return;
    int64_t k, p_str, p_g; uint64_t *qstr_a, qstr_n, qoff; uint32_t *gidx = g->srt_b.res.a;

    for (k = 0, p_g = -1, p_str = (is_rev?(str_occ-1):(0)); k < a_n; k++) {
        if(!is_rev) {
            qstr_a = str+p_str; qstr_n = ((uint32_t)a[k].tn_rev_qk)+1-p_str; qoff = p_str + str_off;
        } else {
            qstr_a = str+poa_str_idx(((uint32_t)a[k].tn_rev_qk), str_occ, is_rev);
            qstr_n = p_str+1-(poa_str_idx(((uint32_t)a[k].tn_rev_qk), str_occ, is_rev));
            qoff = poa_str_idx(((uint32_t)a[k].tn_rev_qk), str_occ, is_rev) + str_off;
        }
        // if(str_id == 47072) {
        //     fprintf(stderr, "+[M::%s::k->%ld] p_g::%ld, c_g::%u, p_str::%ld, c_str::%ld, str_off::%ld, qoff::%lu, qstr_n::%lu\n", 
        //         __func__, k, p_g, gidx[a[k].tk], p_str, poa_str_idx(((uint32_t)a[k].tn_rev_qk), str_occ, is_rev), 
        //         str_off, qoff, qstr_n);
        // }

        append_integer_seq_frag(ug, raw, g, p_g, gidx[a[k].tk], qstr_a, qstr_n, is_rev, str_id, qoff);

        p_str = (uint32_t)a[k].tn_rev_qk;
        if(is_rev) p_str = poa_str_idx(p_str, str_occ, is_rev);
        p_g = gidx[a[k].tk];
    }
    if(!is_rev) {
        qstr_a = str+p_str; qstr_n = str_occ-p_str; qoff = p_str + str_off;
    } else {
        qstr_a = str; qstr_n = p_str+1; qoff = str_off;
    }
    append_integer_seq_frag(ug, raw, g, p_g, -1, qstr_a, qstr_n, is_rev, str_id, qoff);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x70(%rsp), %r13
testq %r9, %r9
setle %al
testq %r13, %r13
setle %cl
orb %al, %cl
je 0x1b729e
addq $0x28, %rsp
jmp 0x1b73b8
movq %r9, %rbx
movq %rdx, %r14
movq 0x68(%rsp), %r15
movq 0x60(%rsp), %rbp
leaq -0x1(%r9), %rax
testq %rbp, %rbp
cmoveq %rbp, %rax
movq 0x90(%rdx), %r12
movq %r8, 0x8(%rsp)
leaq (%r8,%r9,8), %rcx
movq %rcx, 0x20(%rsp)
addq $0x10, %r15
pushq $-0x1
popq %rcx
subq $0x1, %r13
jb 0x1b736d
testq %rbp, %rbp
je 0x1b7306
movl (%r15), %edx
subq %rbx, %rax
leaq (%rax,%rdx), %r10
addq $0x2, %r10
movq %rdx, %rax
notq %rax
movq 0x20(%rsp), %rdx
leaq (%rdx,%rax,8), %r9
addq %rbx, %rax
jmp 0x1b7318
movq 0x8(%rsp), %rdx
leaq (%rdx,%rax,8), %r9
movl (%r15), %r10d
incl %r10d
subq %rax, %r10
addq 0x80(%rsp), %rax
movl -0x10(%r15), %edx
movl (%r12,%rdx,4), %r8d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
pushq %rax
pushq 0x80(%rsp)
pushq %rbp
pushq %r10
callq 0x1b6dad
addq $0x20, %rsp
movl -0x10(%r15), %ecx
movl (%r15), %edx
movq %rdx, %rax
notq %rax
addq %rbx, %rax
testq %rbp, %rbp
cmoveq %rdx, %rax
movl (%r12,%rcx,4), %ecx
addq $0x18, %r15
jmp 0x1b72d5
leaq 0x1(%rax), %rdx
subq %rax, %rbx
xorl %r10d, %r10d
testq %rbp, %rbp
cmoveq %rax, %r10
movq 0x8(%rsp), %rax
leaq (%rax,%r10,8), %r9
cmovneq %rdx, %rbx
addq 0x80(%rsp), %r10
pushq $-0x1
popq %r8
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
pushq %r10
pushq 0x80(%rsp)
pushq %rbp
pushq %rbx
callq 0x1b6dad
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq