// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %r9, 0x10(%rsp)
movq %r8, %rbx
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
xorl %r14d, %r14d
testq %r8, %r8
movl $0x0, %eax
cmovgq %r8, %rax
movq %rax, 0x28(%rsp)
decq %rbx
cmpq %r14, 0x28(%rsp)
je 0x1b6abb
cmpq $0x0, 0x10(%rsp)
movq %rbx, 0x30(%rsp)
je 0x1b688f
movq %r14, %r13
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rbp
movl %ebp, %ebx
xorl $0x1, %ebx
jmp 0x1b689e
movq 0x8(%rsp), %rax
movq %r14, %r13
movq (%rax,%r14,8), %rbx
movq %rbx, %rbp
movq (%r12), %r14
movq 0x10(%r12), %r15
cmpq 0x8(%r12), %r14
jne 0x1b68d9
leaq (%r14,%r14), %rsi
testq %r14, %r14
pushq $0x2
popq %rax
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
imulq $0x24, %rbp, %rax
addq 0x20(%rsp), %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
imulq $0x28, %rcx, %rdx
movq 0x18(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1b2312
movl %eax, (%r15,%r14,8)
movq %r13, %r14
testq %r13, %r13
movq 0x30(%rsp), %rbx
je 0x1b6ab3
movq 0x18(%r12), %r8
movq 0x20(%r12), %rdi
movq 0x28(%r12), %rax
cmpq %rdi, %r8
jne 0x1b6968
leaq (%r8,%r8), %rsi
testq %r8, %r8
pushq $0x2
popq %rcx
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 0x1b69d2
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rcx
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 0x1b6a4e
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0xd0(%r12)
imulq $0x18, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xd8(%r12)
movq (%r12), %rbp
movq 0xc8(%r12), %rcx
imulq $0x18, %rcx, %rdx
incq %rcx
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 %r14d, %r8d
cmpq $0x0, 0x10(%rsp)
movq %rcx, 0xc8(%r12)
movq %rsi, (%rax,%rdx)
cmovnel %edi, %r8d
movq %rbx, %rcx
cmoveq %r14, %rcx
movq 0x78(%rsp), %rdi
leal (%rdi,%r8), %esi
shlq $0x20, %rsi
addq %rdi, %rcx
addq %rsi, %rcx
movq %rcx, 0x8(%rax,%rdx)
movl 0x70(%rsp), %ecx
movl %ecx, 0x10(%rax,%rdx)
incq %r14
jmp 0x1b6861
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq