// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl $0x80, %edi
callq 0x2280
movq %rax, %rbx
leaq 0xaecc7(%rip), %rsi     # 0x1f0295
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2050
leaq 0xb90bc(%rip), %rsi     # 0x1fa6a1
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movl $0x54474341, 0xc(%rsp)  # imm = 0x54474341
movq 0x10(%r14), %rax
movl (%rax), %eax
andl $0x3, %eax
movsbl 0xc(%rsp,%rax), %edx
leaq 0xaec9b(%rip), %rsi     # 0x1f02a8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl (%rax), %eax
andl $0x3, %eax
movsbl 0xc(%rsp,%rax), %r8d
leaq 0xaec82(%rip), %r12     # 0x1f02af
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 0xc(%rsp,%rax), %edx
leaq 0xaec72(%rip), %rsi     # 0x1f02c7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl 0x28(%rax), %eax
andl $0x3, %eax
movsbl 0xc(%rsp,%rax), %r8d
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x22b0
pushq $0x2
popq %r12
pushq $0x50
popq %r13
leaq 0xaec48(%rip), %rbp     # 0x1f02d8
movq (%r14), %rax
cmpq %rax, %r12
jae 0x141706
movq 0x10(%r14), %rax
movl (%rax,%r13), %eax
movl %eax, %ecx
shrl $0x3, %ecx
cmpl $0x1ffffffe, %ecx       # imm = 0x1FFFFFFE
ja 0x1416fd
movl 0x24(%r14), %ecx
cmpq %rcx, %r12
pushq $0x6e
popq %rdx
pushq $0x62
popq %rcx
cmovbl %ecx, %edx
andl $0x3, %eax
movsbl 0xc(%rsp,%rax), %r8d
movq %rbx, %rdi
leaq 0xaebfe(%rip), %rsi     # 0x1f02ce
movq %r12, %rcx
xorl %eax, %eax
callq 0x2050
movq 0x10(%r14), %rax
movl (%rax,%r13), %eax
andl $0x3, %eax
movsbl 0xc(%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
jmp 0x141690
pushq $0x73
popq %r12
xorl %ecx, %ecx
cmpq %rax, %rcx
jae 0x141824
movq 0x10(%r14), %rdx
imulq $0x28, %rcx, %rbp
movl (%rdx,%rbp), %esi
movl %esi, %edx
shrl $0x3, %edx
cmpl $0x1ffffffe, %edx       # imm = 0x1FFFFFFE
ja 0x14181c
movl %r12d, %edx
testq %rcx, %rcx
je 0x141754
cmpq $0x1, %rcx
jne 0x141744
pushq $0x65
popq %rdx
jmp 0x141754
movl 0x24(%r14), %eax
cmpq %rax, %rcx
pushq $0x6e
popq %rdx
pushq $0x62
popq %rax
cmovbl %eax, %edx
andl $0x3, %esi
movsbl 0xc(%rsp,%rsi), %r8d
movq %rbx, %rdi
leaq 0xaeb67(%rip), %rsi     # 0x1f02ce
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
callq 0x2050
xorl %r13d, %r13d
movq 0x10(%r14), %rdx
cmpq 0x8(%rdx,%rbp), %r13
jae 0x141814
leaq (%rdx,%rbp), %rcx
addq $0x8, %rcx
movq 0x18(%rcx), %rax
movl (%rax,%r13,8), %r9d
movl %r12d, %r8d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
je 0x1417c5
cmpl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
je 0x14180c
cmpl $0x1, %r9d
jne 0x1417b6
pushq $0x65
popq %r8
jmp 0x1417c5
cmpl 0x24(%r14), %r9d
pushq $0x6e
popq %r8
pushq $0x62
popq %rsi
cmovbl %esi, %r8d
xorl %esi, %esi
cmpq 0x10(%rcx), %r13
setae %sil
leal 0x2b(,%rsi,2), %ecx
imulq $0x28, %r9, %rsi
movl (%rdx,%rsi), %edx
andl $0x3, %edx
movsbl 0xc(%rsp,%rdx), %r10d
movl 0x4(%rax,%r13,8), %r11d
subq $0x8, %rsp
movq %r15, %rdi
leaq 0xaeaf7(%rip), %rsi     # 0x1f02f0
movq %rbx, %rdx
xorl %eax, %eax
pushq %r11
pushq %rcx
pushq %r10
callq 0x22b0
addq $0x20, %rsp
incq %r13
jmp 0x141776
movq (%r14), %rax
movq 0x10(%rsp), %rcx
incq %rcx
jmp 0x14170c
movq %r15, %rdi
callq 0x2190
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220