// File: /workspace/github_cpp_makefile_star2_O3/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 0xb89ac(%rip), %rsi     # 0x23e3d5
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2050
leaq 0xc2ca2(%rip), %rsi     # 0x2486e2
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 0xb8980(%rip), %rsi     # 0x23e3e8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl (%rax), %eax
andl $0x3, %eax
movsbl 0x4(%rsp,%rax), %r8d
leaq 0xb8967(%rip), %r12     # 0x23e3ef
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 0xb8957(%rip), %rsi     # 0x23e407
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
movq (%r14), %rax
cmpq $0x3, %rax
jb 0x185b74
movl $0x2, %r12d
movl $0x50, %r13d
leaq 0xb891c(%rip), %rbp     # 0x23e418
movq 0x10(%r14), %rcx
movl (%rcx,%r13), %ecx
movl %ecx, %edx
shrl $0x3, %edx
cmpl $0x1ffffffe, %edx       # imm = 0x1FFFFFFE
ja 0x185b68
movl 0x24(%r14), %eax
cmpq %rax, %r12
movl $0x6e, %edx
movl $0x62, %eax
cmovbl %eax, %edx
andl $0x3, %ecx
movsbl 0x4(%rsp,%rcx), %r8d
movq %rbx, %rdi
leaq 0xb88d6(%rip), %rsi     # 0x23e40e
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
movq (%r14), %rax
incq %r12
addq $0x28, %r13
cmpq %rax, %r12
jb 0x185afc
testq %rax, %rax
je 0x185cb6
movq 0x10(%r14), %rax
xorl %ebp, %ebp
leaq (,%rbp,4), %r12
addq %rbp, %r12
movl (%rax,%r12,8), %ecx
movl %ecx, %edx
shrl $0x3, %edx
cmpl $0x1ffffffe, %edx       # imm = 0x1FFFFFFE
ja 0x185caa
testq %rbp, %rbp
je 0x185bb5
cmpq $0x1, %rbp
jne 0x185bbc
movl $0x65, %edx
jmp 0x185bd0
movl $0x73, %edx
jmp 0x185bd0
movl 0x24(%r14), %eax
cmpq %rax, %rbp
movl $0x6e, %edx
movl $0x62, %eax
cmovbl %eax, %edx
andl $0x3, %ecx
movsbl 0x4(%rsp,%rcx), %r8d
movq %rbx, %rdi
leaq 0xb882b(%rip), %rsi     # 0x23e40e
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
cmpq $0x0, 0x8(%rax,%r12,8)
je 0x185caa
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 0x185c30
cmpl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
je 0x185c96
cmpl $0x1, %r9d
jne 0x185c38
movl $0x65, %r8d
jmp 0x185c4b
movl $0x73, %r8d
jmp 0x185c4b
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 0xb87b1(%rip), %rsi     # 0x23e430
movq %rbx, %rdx
xorl %eax, %eax
pushq %r11
pushq %rcx
pushq %r10
callq 0x22b0
addq $0x20, %rsp
movq 0x10(%r14), %rax
incq %r13
leaq (%rax,%r12,8), %rcx
addq $0x8, %rcx
cmpq (%rcx), %r13
jb 0x185c08
incq %rbp
cmpq (%r14), %rbp
jb 0x185b83
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