// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
testq %r8, %r8
jle 0x1f720d
movq %r8, %r14
movq %rdx, %r12
decq %r14
xorl %r15d, %r15d
cmpq $0x0, 0x10(%rsp)
je 0x1f6fd1
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %r13
movl %r13d, %ebp
xorl $0x1, %ebp
jmp 0x1f6fdd
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rbp
movq %rbp, %r13
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x1f7010
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
shrq $0x20, %r13
leaq (,%r13,8), %rax
addq %r13, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq (%r12), %r13
movq 0x10(%r12), %rbx
leaq 0x1(%r13), %rcx
movq %rcx, (%r12)
movl %ebp, 0x4(%rbx,%r13,8)
movl (%rax), %ecx
movl 0xc(%rax), %edi
movl 0x10(%rax), %esi
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
movq 0x18(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1f2d50
movl %eax, (%rbx,%r13,8)
testq %r15, %r15
je 0x1f7200
movq 0x20(%r12), %rax
cmpq %rax, 0x18(%r12)
jne 0x1f709d
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x20(%r12)
movq 0x28(%r12), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, 0x28(%r12)
movq 0x28(%r12), %rdi
movq (%r12), %rax
movq 0x18(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x18(%r12)
shlq $0x4, %rcx
leal -0x3(,%rax,2), %esi
shlq $0x21, %rax
movabsq $-0xffffffff, %r8       # imm = 0xFFFFFFFF00000001
addq %r8, %rax
movq %rax, (%rdi,%rcx)
movl %esi, 0x8(%rdi,%rcx)
movq 0x20(%r12), %rax
cmpq %rax, %rdx
jne 0x1f7105
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x20(%r12)
shlq $0x4, %rsi
callq 0x2370
movq %rax, 0x28(%r12)
movq 0x28(%r12), %rax
movq (%r12), %rcx
movq 0x18(%r12), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x18(%r12)
shlq $0x4, %rdx
leal -0x2(,%rcx,2), %esi
shlq $0x21, %rcx
movabsq $-0x3ffffffff, %rdi     # imm = 0xFFFFFFFC00000001
addq %rdi, %rcx
movq %rcx, (%rax,%rdx)
movl %esi, 0x8(%rax,%rdx)
movq 0xd0(%r12), %rax
cmpq %rax, 0xc8(%r12)
jne 0x1f7187
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0xd0(%r12)
movq 0xd8(%r12), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0xd8(%r12)
movq 0xc8(%r12), %rcx
movq 0xd8(%r12), %rax
leaq 0x1(%rcx), %rdx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq 0x2(%r8), %rsi
imulq (%r12), %rsi
movabsq $-0x200000001, %rdi     # imm = 0xFFFFFFFDFFFFFFFF
addq %rdi, %rsi
leal 0x1(%r14), %edi
addl %r15d, %r8d
cmpq $0x0, 0x10(%rsp)
movq %rdx, 0xc8(%r12)
leaq (%rcx,%rcx,2), %rcx
movq %rsi, (%rax,%rcx,8)
cmovnel %edi, %r8d
movq %r14, %rdx
cmoveq %r15, %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 %r15
addq $-0x1, %r14
jb 0x1f6fb8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq