// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x80(%rsp), %rbp
testq %r9, %r9
setle %al
testq %rbp, %rbp
setle %cl
orb %al, %cl
je 0x202f42
addq $0x38, %rsp
jmp 0x2030ed
movq %r9, %r10
movq 0x90(%rsp), %rcx
movq 0x78(%rsp), %r13
movq 0x70(%rsp), %rbx
movq %rdx, (%rsp)
movq 0x90(%rdx), %r12
leaq -0x1(%r9), %rax
testq %rbx, %rbx
cmoveq %rbx, %rax
movq %r8, 0x18(%rsp)
leaq (%r8,%r9,8), %rdx
movq %rdx, 0x28(%rsp)
addq %r9, %rcx
movq %rcx, 0x20(%rsp)
movq $-0x1, %rcx
xorl %r14d, %r14d
movq %r9, 0x30(%rsp)
testq %rbx, %rbx
je 0x202ff2
movl (%r13), %edx
movl 0x10(%r13), %esi
subq %r10, %rax
addq %rsi, %rax
addq $0x2, %rax
movq %rsi, %r10
notq %r10
movq 0x28(%rsp), %rsi
leaq (%rsi,%r10,8), %r9
addq 0x20(%rsp), %r10
leaq (%r14,%r14,2), %rsi
movq 0x78(%rsp), %rdi
leaq (%rdi,%rsi,8), %r15
movl (%r12,%rdx,4), %r8d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
pushq %r10
pushq 0x90(%rsp)
pushq %rbx
pushq %rax
callq 0x202aad
addq $0x20, %rsp
jmp 0x203040
movq 0x90(%rsp), %rdx
leaq (%rax,%rdx), %r10
movl (%r13), %edx
movl 0x10(%r13), %r11d
incl %r11d
subq %rax, %r11
movq 0x18(%rsp), %rsi
leaq (%rsi,%rax,8), %r9
movl (%r12,%rdx,4), %r8d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
pushq %r10
pushq 0x90(%rsp)
pushq $0x0
pushq %r11
callq 0x202aad
addq $0x20, %rsp
movq %r13, %r15
movl 0x10(%r13), %edx
movq %rdx, %rax
notq %rax
movq 0x30(%rsp), %r10
addq %r10, %rax
testq %rbx, %rbx
cmoveq %rdx, %rax
movl (%r15), %ecx
movl (%r12,%rcx,4), %ecx
incq %r14
addq $0x18, %r13
decq %rbp
jne 0x202f92
testq %rbx, %rbx
je 0x2030a5
subq %rdx, %r10
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq $-0x1, %r8
movq 0x18(%rsp), %r9
pushq 0x90(%rsp)
pushq 0x90(%rsp)
pushq %rbx
pushq %r10
jmp 0x2030e4
movq 0x90(%rsp), %rax
movq %r10, %r11
movq %rax, %r10
addq %rdx, %r10
subq %rdx, %r11
movq 0x18(%rsp), %rax
leaq (%rax,%rdx,8), %r9
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq $-0x1, %r8
pushq %r10
pushq 0x90(%rsp)
pushq $0x0
pushq %r11
callq 0x202aad
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq