// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jle 0x330d36
cmpq $0x0, 0x20(%rbp)
jg 0x330d3b
jmp 0x33105a
movq -0x20(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x40(%rbp)
movq $-0x1, -0x50(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x330d6f
movq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x330d77
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x330d77
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x20(%rbp), %rax
jge 0x330fc7
cmpq $0x0, 0x10(%rbp)
jne 0x330dd5
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq 0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
addl $0x1, %eax
movl %eax, %eax
subq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
addq 0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x330ef8
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x330e0a
movq -0x38(%rbp), %rax
movq 0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl %ecx, %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x330e23
movq 0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x330e75
movq -0x38(%rbp), %rax
movq 0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl %ecx, %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x330e8e
movq 0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x330ed0
movq -0x38(%rbp), %rax
movq 0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl %ecx, %ecx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x330ee9
movq 0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
addq 0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x70(%rbp), %rax
movq 0x18(%rbp), %r8
imulq $0x18, -0x40(%rbp), %r9
addq %r9, %r8
movl (%r8), %r8d
movl (%rax,%r8,4), %eax
movl %eax, %r8d
movq -0x58(%rbp), %r9
movq -0x60(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x28(%rbp), %r10
movq -0x68(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x3301c0
movq 0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl %eax, %eax
movq %rax, -0x48(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x330f9d
cmpq $0x0, 0x10(%rbp)
je 0x330f87
movq -0x38(%rbp), %rax
subq -0x48(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x330f92
movq -0x48(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
movq 0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x330d7f
cmpq $0x0, 0x10(%rbp)
jne 0x330ffb
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
addq 0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x331017
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq 0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r9
movq -0x60(%rbp), %rbx
movq 0x10(%rbp), %r11
movq 0x28(%rbp), %r10
movq -0x68(%rbp), %rax
movq $-0x1, %r8
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x3301c0
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)