// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: insert_poa_nodes_0(ma_ug_t*, uc_block_t*, poa_g_t*, unsigned long*, long, unsigned long, long, long)
void insert_poa_nodes_0(ma_ug_t *ug, uc_block_t *raw, poa_g_t *g, uint64_t *str, int64_t str_occ, uint64_t is_rev, int64_t str_id, int64_t str_off)
{
    int64_t k; poa_nid_t *nn; poa_arc_t *ae; uint32_t v; uc_block_t *z; emap_t *em;
    for (k = 0; k < str_occ; k++) {
        if(is_rev == 0) {
            v = ((uint32_t)str[k]); z = &(raw[str[k]>>32]);
        } else {
            v = ((uint32_t)str[str_occ-k-1])^1; z = &(raw[str[str_occ-k-1]>>32]);
        }
        
        kv_pushp(poa_nid_t, g->seq, &nn);
        nn->nid = v; nn->occ = ug_occ_w(z->ts, z->te, &(ug->u.a[z->hid]));

        if(k > 0) {
            kv_pushp(poa_arc_t, g->arc, &ae);
            ae->ul = g->seq.n-1; ae->ul <<= 33; ae->ul += ((uint64_t)(0x100000000)); ae->ul += 1;
            ae->v = g->seq.n-2; ae->v <<= 1; ae->v += 1;

            kv_pushp(poa_arc_t, g->arc, &ae);
            ae->ul = g->seq.n-2; ae->ul <<= 33; ae->ul += 1;
            ae->v = g->seq.n-1; ae->v <<= 1;

            kv_pushp(emap_t, g->e_idx, &em);
            em->pge = g->seq.n-2; em->pge <<= 32; em->pge += g->seq.n-1;
            em->ule = str_off + (is_rev?(str_occ-k):(k-1)); em->ule <<= 32; 
            em->ule += str_off + (is_rev?(str_occ-k-1):(k));
            em->ulid = str_id;

            // if(!((g->seq.a[em->pge>>32].nid^(is_rev?1:0)) == ((uint32_t)debug_str->a[em->ule>>32]))) {
            //     fprintf(stderr, "[M::%s::k->%ld::str_occ->%ld] is_rev->%lu, pg_v->%u, str_v->%u, str_off->%ld, str_k->%lu, str_cn->%u, address_diff->%u\n", 
            //             __func__, k, str_occ, is_rev, (g->seq.a[em->pge>>32].nid^(is_rev?1:0)), 
            //             ((uint32_t)debug_str->a[em->ule>>32]), str_off, em->ule>>32, debug_str->cn, (uint32_t)(str - debug_str->a));
            //     uint64_t debug_k;
            //     for (debug_k = 0; debug_k < debug_str->cn; debug_k++) {
            //         fprintf(stderr, "[M::%s::debug_k->%lu] str_v->%u\n", 
            //             __func__, debug_k, ((uint32_t)debug_str->a[debug_k]));
            //     }
                
            // }
            // assert((g->seq.a[em->pge>>32].nid^(is_rev?1:0)) == ((uint32_t)debug_str->a[em->ule>>32]));
            // assert((g->seq.a[(uint32_t)em->pge].nid^(is_rev?1:0)) == ((uint32_t)debug_str->a[(uint32_t)em->ule]));
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %rcx, (%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
testq %r8, %r8
jle 0x2027ad
movq %r8, %rbx
movq %rdx, %r12
decq %rbx
xorl %r13d, %r13d
cmpq $0x0, 0x8(%rsp)
movq %rbx, 0x20(%rsp)
je 0x202566
movq (%rsp), %rax
movq (%rax,%rbx,8), %rbp
movl %ebp, %ebx
xorl $0x1, %ebx
jmp 0x202571
movq (%rsp), %rax
movq (%rax,%r13,8), %rbx
movq %rbx, %rbp
movq (%r12), %r14
movq 0x10(%r12), %r15
cmpq 0x8(%r12), %r14
jne 0x2025ae
leaq (%r14,%r14), %rsi
testq %r14, %r14
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %rax, 0x10(%r12)
movq (%r12), %r14
shrq $0x20, %rbp
leaq (,%rbp,8), %rax
addq %rbp, %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
leaq 0x1(%r14), %rbp
movq %rbp, (%r12)
movl %ebx, 0x4(%r15,%r14,8)
movl (%rax), %ecx
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
movq 0x10(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1fe266
movl %eax, (%r15,%r14,8)
testq %r13, %r13
movq 0x20(%rsp), %rbx
je 0x2027a0
movq 0x18(%r12), %r8
movq 0x20(%r12), %rdi
movq 0x28(%r12), %rax
cmpq %rdi, %r8
jne 0x20264b
leaq (%r8,%r8), %rsi
testq %r8, %r8
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x20(%r12)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x28(%r12)
movq (%r12), %rbp
movq 0x18(%r12), %r8
movq 0x20(%r12), %rdi
leaq 0x1(%r8), %rcx
movq %rcx, 0x18(%r12)
shlq $0x4, %r8
movq %rbp, %rdx
shlq $0x21, %rdx
movabsq $-0xffffffff, %rsi      # imm = 0xFFFFFFFF00000001
addq %rdx, %rsi
movq %rsi, (%rax,%r8)
leal -0x3(,%rbp,2), %esi
movl %esi, 0x8(%rax,%r8)
cmpq %rdi, %rcx
jne 0x2026b7
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x20(%r12)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x28(%r12)
movq (%r12), %rbp
movq 0x18(%r12), %rcx
movq %rbp, %rdx
shlq $0x21, %rdx
leal (,%rbp,2), %esi
movabsq $-0x3ffffffff, %rdi     # imm = 0xFFFFFFFC00000001
addq %rdi, %rdx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x18(%r12)
shlq $0x4, %rcx
movq %rdx, (%rax,%rcx)
addl $-0x2, %esi
movl %esi, 0x8(%rax,%rcx)
movq 0xc8(%r12), %rcx
movq 0xd8(%r12), %rax
cmpq 0xd0(%r12), %rcx
jne 0x202739
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0xd0(%r12)
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xd8(%r12)
movq (%r12), %rbp
movq 0xc8(%r12), %rcx
leaq 0x1(%rcx), %rdx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x2(%r8), %rsi
imulq %rbp, %rsi
movabsq $-0x200000001, %rdi     # imm = 0xFFFFFFFDFFFFFFFF
addq %rdi, %rsi
leal 0x1(%rbx), %edi
addl %r13d, %r8d
cmpq $0x0, 0x8(%rsp)
movq %rdx, 0xc8(%r12)
leaq (%rcx,%rcx,2), %rcx
movq %rsi, (%rax,%rcx,8)
cmovnel %edi, %r8d
movq %rbx, %rdx
cmoveq %r13, %rdx
movq 0x68(%rsp), %rdi
leal (%rdi,%r8), %esi
shlq $0x20, %rsi
addq %rdi, %rdx
addq %rsi, %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movq 0x60(%rsp), %rdx
movl %edx, 0x10(%rax,%rcx,8)
incq %r13
addq $-0x1, %rbx
jb 0x20254a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq