// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/ecovlp.cpp
// Function: output_cns_g(cns_gfa*, unsigned long, unsigned long)
void output_cns_g(cns_gfa *cns, uint64_t s, uint64_t e)
{
    // char *gfa_id = NULL, p; MALLOC(gfa_id, Get_NAME_LENGTH(R_INF, qid) + 128); 
    // sprintf(gfa_id, "%.*s.%lu_%lu.cns.gfa", (int)Get_NAME_LENGTH(R_INF, qid), Get_NAME(R_INF, qid), s, e);
    char *gfa_id = NULL, p, f; MALLOC(gfa_id, 128); 
    sprintf(gfa_id, "ec.%lu_%lu.cns.gfa", s, e);

    FILE *fp = fopen(gfa_id, "w"); uint64_t k, z; char cm[4]; cm[0] = 'A'; cm[1] = 'C'; cm[2] = 'G'; cm[3] = 'T';  

    sprintf(gfa_id, "s_0_%c", cm[cns->a[0].c]);
    fprintf(fp, "S\t%s\t*\tLN:i:%u\trd:i:%c\n", gfa_id, 0/**cns->a[0].sc**/, cm[cns->a[0].c]);

    sprintf(gfa_id, "e_1_%c", cm[cns->a[1].c]);
    fprintf(fp, "S\t%s\t*\tLN:i:%u\trd:i:%c\n", gfa_id, 0/**cns->a[1].sc**/, cm[cns->a[1].c]);

    for (k = 2; k < cns->n; k++) {
        if(del_cns_nn((*cns), k)) continue;
        sprintf(gfa_id, "%c_%lu_%c", ((k<cns->bn)?'b':'n'), k, cm[cns->a[k].c]);
        fprintf(fp, "S\t%s\t*\tLN:i:%d\trd:i:%c\n", gfa_id, 0/**cns->a[k].sc**/, cm[cns->a[k].c]);
    }
    
    for (k = 0; k < cns->n; k++) {
        if(del_cns_nn((*cns), k)) continue;

        if(k == 0) {
            p = 's';
        } else if(k == 1) {
            p = 'e';
        } else if (k<cns->bn) {
            p = 'b';
        } else {
            p = 'n';
        }
        
        sprintf(gfa_id, "%c_%lu_%c", p, k, cm[cns->a[k].c]);
        for (z = 0; z < cns->a[k].arc.n; z++) {
            if(del_cns_arc((cns->a[k]), z)) continue;

            if(cns->a[k].arc.a[z].v == 0) {
                p = 's';
            } else if(cns->a[k].arc.a[z].v == 1) {
                p = 'e';
            } else if (cns->a[k].arc.a[z].v < cns->bn) {
                p = 'b';
            } else {
                p = 'n';
            }

            f = ((z < cns->a[k].arc.nou)?('+'):('-'));
            fprintf(fp, "L\t%s\t%c\t%c_%u_%c\t%c\t0M\tL1:i:%u\n", 
                    gfa_id, f, 
                    p, cns->a[k].arc.a[z].v, cm[cns->a[cns->a[k].arc.a[z].v].c], f, 
                    cns->a[k].arc.a[z].sc);
        }
    }

    fclose(fp); free(gfa_id);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl $0x80, %edi
callq 0x2280
movq %rax, %rbx
leaq 0xb3ba5(%rip), %rsi     # 0x232185
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2050
leaq 0xbde07(%rip), %rsi     # 0x23c3fe
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movl $0x54474341, 0x4(%rsp)  # imm = 0x54474341
movq 0x10(%r14), %rax
movl (%rax), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %edx
leaq 0xb3b79(%rip), %rsi     # 0x232198
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl (%rax), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r8d
leaq 0xb3b60(%rip), %r12     # 0x23219f
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x22b0
movq 0x10(%r14), %rax
movl 0x28(%rax), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %edx
leaq 0xb3b50(%rip), %rsi     # 0x2321b7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl 0x28(%rax), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r8d
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x22b0
cmpq $0x3, (%r14)
jb 0x17e725
movl $0x2, %r12d
movl $0x50, %r13d
leaq 0xb3b18(%rip), %rbp     # 0x2321c8
movq 0x10(%r14), %rax
movl (%rax,%r13), %eax
movl %eax, %ecx
shrl $0x3, %ecx
cmpl $0x1ffffffe, %ecx       # imm = 0x1FFFFFFE
ja 0x17e719
movl 0x24(%r14), %ecx
cmpq %rcx, %r12
movl $0x6e, %edx
movl $0x62, %ecx
cmovbl %ecx, %edx
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r8d
movq %rbx, %rdi
leaq 0xb3ad2(%rip), %rsi     # 0x2321be
movq %r12, %rcx
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl (%rax,%r13), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r8d
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x22b0
incq %r12
addq $0x28, %r13
cmpq (%r14), %r12
jb 0x17e6b0
cmpq $0x0, (%r14)
je 0x17e868
xorl %ebp, %ebp
movq 0x10(%r14), %rax
leaq (,%rbp,4), %r12
addq %rbp, %r12
movl (%rax,%r12,8), %eax
movl %eax, %ecx
shrl $0x3, %ecx
cmpl $0x1ffffffe, %ecx       # imm = 0x1FFFFFFE
ja 0x17e85c
testq %rbp, %rbp
je 0x17e767
cmpq $0x1, %rbp
jne 0x17e76e
movl $0x65, %edx
jmp 0x17e782
movl $0x73, %edx
jmp 0x17e782
movl 0x24(%r14), %ecx
cmpq %rcx, %rbp
movl $0x6e, %edx
movl $0x62, %ecx
cmovbl %ecx, %edx
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r8d
movq %rbx, %rdi
leaq 0xb3a29(%rip), %rsi     # 0x2321be
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
cmpq $0x0, 0x8(%rax,%r12,8)
je 0x17e85c
leaq (%rax,%r12,8), %rcx
addq $0x8, %rcx
xorl %r13d, %r13d
movq 0x18(%rcx), %rdx
movl (%rdx,%r13,8), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
je 0x17e7e2
cmpl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
je 0x17e844
cmpl $0x1, %r9d
jne 0x17e7ea
movl $0x65, %r8d
jmp 0x17e7fd
movl $0x73, %r8d
jmp 0x17e7fd
cmpl 0x24(%r14), %r9d
movl $0x6e, %r8d
movl $0x62, %esi
cmovbl %esi, %r8d
xorl %esi, %esi
cmpq 0x10(%rcx), %r13
setae %sil
leal 0x2b(,%rsi,2), %ecx
leaq (%r9,%r9,4), %rsi
movl (%rax,%rsi,8), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r10d
movl 0x4(%rdx,%r13,8), %r11d
subq $0x8, %rsp
movq %r15, %rdi
leaq 0xb39af(%rip), %rsi     # 0x2321e0
movq %rbx, %rdx
xorl %eax, %eax
pushq %r11
pushq %rcx
pushq %r10
callq 0x22b0
addq $0x20, %rsp
incq %r13
movq 0x10(%r14), %rax
leaq (%rax,%r12,8), %rcx
addq $0x8, %rcx
cmpq (%rcx), %r13
jb 0x17e7ba
incq %rbp
cmpq (%r14), %rbp
jb 0x17e731
movq %r15, %rdi
callq 0x2190
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220