// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x32fbf9
cmpq $0x0, -0x30(%rbp)
jne 0x32f758
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
jmp 0x32f799
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
subq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rdx
subq -0x38(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
jmp 0x32f79b
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x32f803
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x32f7c8
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x32f7d3
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x32f7d3
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rax
movl (%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0x327090
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x38(%rbp)
jle 0x32fbe6
jmp 0x32f872
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x32f8db
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x32f8a0
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x32f8ab
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x32f8ab
movq -0x70(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x18(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x18(%rdx)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
subq $0x1, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rcx
shlq $0x21, %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x2, %rax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x32f9d9
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x32f99e
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x32f9a9
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x32f9a9
movq -0x78(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x18(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x18(%rdx)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
subq $0x2, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rcx
shlq $0x21, %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0xd0(%rcx), %rax
jne 0x32facb
movq -0x18(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x32fa87
movq -0x18(%rbp), %rax
movq 0xd0(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x32fa92
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x32fa92
movq -0x80(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x18(%rbp), %rax
movq 0xd8(%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x18, 0xd0(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x18(%rbp), %rax
movq 0xd8(%rax), %rax
movq -0x18(%rbp), %rdx
movq 0xc8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0xc8(%rdx)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
subq $0x2, %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
subq $0x1, %rcx
movq -0x60(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq 0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x32fb52
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x32fb61
movq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rcx
movq -0x90(%rbp), %rax
addq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rcx
shlq $0x20, %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x32fbb1
movq -0x28(%rbp), %rax
subq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x32fbbc
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rax
addq %rax, %rcx
movq -0x60(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x32fbe8
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x32f713
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)