// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x80, %edi
callq 0x2270
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x13bf95(%rip), %rsi    # 0x38efb2
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
leaq 0x1463a3(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x30(%rbp)
movb $0x41, -0x44(%rbp)
movb $0x43, -0x43(%rbp)
movb $0x47, -0x42(%rbp)
movb $0x54, -0x41(%rbp)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %edx
leaq 0x13bf5e(%rip), %rsi    # 0x38efc5
movb $0x0, %al
callq 0x2050
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %r8d
leaq 0x13bf3a(%rip), %rsi    # 0x38efcc
xorl %ecx, %ecx
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x28(%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %edx
leaq 0x13bf29(%rip), %rsi    # 0x38efe4
movb $0x0, %al
callq 0x2050
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x28(%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %r8d
leaq 0x13bee5(%rip), %rsi    # 0x38efcc
xorl %ecx, %ecx
movb $0x0, %al
callq 0x22a0
movq $0x2, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2531d5
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x3, %eax
cmpl $0x1fffffff, %eax       # imm = 0x1FFFFFFF
jne 0x25312a
jmp 0x2531c4
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, %edx
movb $0x62, %al
movb $0x6e, %sil
movb %sil, -0x46(%rbp)
cmpq %rdx, %rcx
movb %al, -0x45(%rbp)
jb 0x253156
movb -0x46(%rbp), %al
movb %al, -0x45(%rbp)
movq -0x50(%rbp), %rdi
movb -0x45(%rbp), %al
movsbl %al, %edx
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rsi
addq %rsi, %rax
movl (%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %r8d
leaq 0x13be63(%rip), %rsi    # 0x38efeb
movb $0x0, %al
callq 0x2050
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %r8d
leaq 0x13be3a(%rip), %rsi    # 0x38eff5
xorl %ecx, %ecx
movb $0x0, %al
callq 0x22a0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2530f8
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x253466
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x3, %eax
cmpl $0x1fffffff, %eax       # imm = 0x1FFFFFFF
jne 0x25320f
jmp 0x253455
cmpq $0x0, -0x38(%rbp)
jne 0x25321c
movb $0x73, -0x21(%rbp)
jmp 0x253247
cmpq $0x1, -0x38(%rbp)
jne 0x253229
movb $0x65, -0x21(%rbp)
jmp 0x253245
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x24(%rcx), %ecx
cmpq %rcx, %rax
jae 0x25323f
movb $0x62, -0x21(%rbp)
jmp 0x253243
movb $0x6e, -0x21(%rbp)
jmp 0x253245
jmp 0x253247
movq -0x20(%rbp), %rdi
movsbl -0x21(%rbp), %edx
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rsi
addq %rsi, %rax
movl (%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %r8d
leaq 0x13bd74(%rip), %rsi    # 0x38efeb
movb $0x0, %al
callq 0x2050
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jae 0x253453
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x2532d0
jmp 0x253442
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x0, %eax
jne 0x2532fb
movb $0x73, -0x21(%rbp)
jmp 0x25335d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x1, %eax
jne 0x253326
movb $0x65, -0x21(%rbp)
jmp 0x25335b
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jae 0x253355
movb $0x62, -0x21(%rbp)
jmp 0x253359
movb $0x6e, -0x21(%rbp)
jmp 0x25335b
jmp 0x25335d
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rax
movq 0x18(%rax), %rdx
movb $0x2b, %al
movb $0x2d, %sil
movb %sil, -0x52(%rbp)
cmpq %rdx, %rcx
movb %al, -0x51(%rbp)
jb 0x25338c
movb -0x52(%rbp), %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
movb %al, -0x22(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rdx
movsbl -0x22(%rbp), %ecx
movsbl -0x21(%rbp), %r8d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rsi
addq %rsi, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rsi
movl (%rax,%rsi,8), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x10(%rsi), %rsi
imulq $0x28, -0x38(%rbp), %r10
addq %r10, %rsi
movq 0x20(%rsi), %rsi
movq -0x40(%rbp), %r10
movl (%rsi,%r10,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl %esi, %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rax
movl (%rax), %eax
andl $0x3, %eax
movl %eax, %eax
movsbl -0x44(%rbp,%rax), %r11d
movsbl -0x22(%rbp), %r10d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rsi
addq %rsi, %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rsi
movl 0x4(%rax,%rsi,8), %eax
leaq 0x13bbdf(%rip), %rsi    # 0x38f00d
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x22a0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x253286
jmp 0x253455
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2531dd
movq -0x30(%rbp), %rdi
callq 0x21a0
movq -0x20(%rbp), %rdi
callq 0x2210
addq $0x70, %rsp
popq %rbp
retq
nop