// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: init_cns_g(cns_gfa*, char*, unsigned long, unsigned int)
void init_cns_g(cns_gfa *cns, char *s, uint64_t sl, uint32_t rid)
{
    uint32_t m0 = cns->m, m1 = sl + 2, k; cns_t *p;
    if ((*cns).m < (m1)) { ///equal to kv_resize()
        (*cns).m = (m1); 
        (--((*cns).m), ((*cns).m)|=((*cns).m)>>1, ((*cns).m)|=((*cns).m)>>2, ((*cns).m)|=((*cns).m)>>4, ((*cns).m)|=((*cns).m)>>8, ((*cns).m)|=((*cns).m)>>16, ++((*cns).m)); 
        (*cns).a = (cns_t*)realloc((*cns).a, sizeof(cns_t) * (*cns).m); 
        if((*cns).m > m0) {
            memset((*cns).a + m0, 0, sizeof(cns_t)*((*cns).m-m0));
        }
    }
    (*cns).n = 0; (*cns).si = 0; (*cns).ei = 1; (*cns).off = 2;

    p = &((*cns).a[(*cns).n++]); p->arc.nou = p->arc.n = p->c = p->f = p->sc = 0; ///beg
    p = &((*cns).a[(*cns).n++]); p->arc.nou = p->arc.n = p->c = p->f = p->sc = 0; ///end
    (*cns).bb0 = (*cns).n;

    for (k = 0; k < sl; k++) {
        p = &((*cns).a[(*cns).n++]); p->arc.nou = p->arc.n = p->f = 0;
        p->c = seq_nt6_table[(uint32_t)(s[k])]; p->sc = 1;
        
        if(k + 1 < sl) insert_cns_arc(cns, k + (*cns).off, k + 1 + (*cns).off, 1, 1, rid);

        if(k > 0) insert_cns_arc(cns, k + (*cns).off, k - 1 + (*cns).off, 0, 1, rid);
    }
    
    if(sl) {
        insert_cns_arc(cns, (*cns).si, 0 + (*cns).off, 1, 1, rid); insert_cns_arc(cns, 0 + (*cns).off, (*cns).si, 0, 1, rid);
        insert_cns_arc(cns, sl - 1 + (*cns).off, (*cns).ei, 1, 1, rid); insert_cns_arc(cns, (*cns).ei, sl - 1 + (*cns).off, 0, 1, rid);
    } else {
        insert_cns_arc(cns, (*cns).si, (*cns).ei, 1, 1, rid); 
        insert_cns_arc(cns, (*cns).ei, (*cns).si, 0, 1, rid);
    }

    // prt_cns_arc(cns, 0, __func__);
    // prt_cns_arc(cns, 1, __func__);

    (*cns).bn = (*cns).n; (*cns).bb1 = (*cns).n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
movq %rdx, %r14
movq %rsi, (%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r13
leal 0x2(%rdx), %eax
cmpq %rax, %r13
jae 0x13dca0
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
imulq $0x28, %rcx, %rsi
callq 0x2370
movq %rax, %r12
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %rax
subq %r13, %rax
jbe 0x13dca4
imulq $0x28, %r13, %rcx
movq %r12, %rdi
addq %rcx, %rdi
imulq $0x28, %rax, %rdx
xorl %esi, %esi
callq 0x20e0
jmp 0x13dca4
movq 0x10(%rbx), %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x18(%rbx)
movl $0x2, 0x20(%rbx)
movq $0x1, (%rbx)
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
andq $0x0, 0x18(%r12)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
imulq $0x28, %rax, %rax
andl $0x0, (%rcx,%rax)
andq $0x0, 0x8(%rcx,%rax)
andq $0x0, 0x18(%rcx,%rax)
movl (%rbx), %eax
movl %eax, 0x28(%rbx)
xorl %r13d, %r13d
pushq $0x1
popq %r12
movl %r13d, %ebp
cmpq %r14, %rbp
jae 0x13dd96
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
imulq $0x28, %rax, %rax
andb $-0x5, (%rcx,%rax)
andq $0x0, 0x8(%rcx,%rax)
andq $0x0, 0x18(%rcx,%rax)
movq (%rsp), %rdx
movsbq (%rdx,%rbp), %rdx
movl %edx, %edx
leaq 0x1158f1(%rip), %rsi    # 0x253630
movzbl (%rsi,%rdx), %edx
andl $0x3, %edx
orl $0x8, %edx
movl %edx, (%rcx,%rax)
leal 0x1(%rbp), %r13d
cmpq %r14, %r13
jae 0x13dd71
movl 0x20(%rbx), %eax
leal (%rax,%rbp), %esi
leal (%rax,%rbp), %edx
incl %edx
movq %rbx, %rdi
movl %r12d, %ecx
movl %r12d, %r8d
movl %r15d, %r9d
callq 0x14ef91
testq %rbp, %rbp
je 0x13dcff
movl 0x20(%rbx), %eax
leal (%rax,%rbp), %esi
leal (%rax,%rbp), %edx
decl %edx
movq %rbx, %rdi
xorl %ecx, %ecx
movl %r12d, %r8d
movl %r15d, %r9d
callq 0x14ef91
jmp 0x13dcff
movl 0x18(%rbx), %esi
testq %r14, %r14
je 0x13ddfa
movl 0x20(%rbx), %edx
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %ecx
movl %ebp, %r8d
movl %r15d, %r9d
callq 0x14ef91
movl 0x18(%rbx), %edx
movl 0x20(%rbx), %esi
movq %rbx, %rdi
xorl %ecx, %ecx
movl %ebp, %r8d
movl %r15d, %r9d
callq 0x14ef91
decl %r14d
movl 0x20(%rbx), %esi
addl %r14d, %esi
movl 0x1c(%rbx), %edx
movq %rbx, %rdi
movl %ebp, %ecx
movl %ebp, %r8d
movl %r15d, %r9d
callq 0x14ef91
movl 0x1c(%rbx), %esi
addl 0x20(%rbx), %r14d
movq %rbx, %rdi
movl %r14d, %edx
xorl %ecx, %ecx
movl %ebp, %r8d
jmp 0x13de20
movl 0x1c(%rbx), %edx
pushq $0x1
popq %r14
movq %rbx, %rdi
movl %r14d, %ecx
movl %r14d, %r8d
movl %r15d, %r9d
callq 0x14ef91
movl 0x18(%rbx), %edx
movl 0x1c(%rbx), %esi
movq %rbx, %rdi
xorl %ecx, %ecx
movl %r14d, %r8d
movl %r15d, %r9d
callq 0x14ef91
movl (%rbx), %eax
movl %eax, 0x24(%rbx)
movl %eax, 0x2c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq