// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path.c
// Function: asg_read
asg_t *asg_read(const char *fn)
{
    int dret, ret, is_fa, is_fq, is_gfa;
    gzFile fp;
    kstream_t *ks;
    asg_seg_t *fa_seg;
    uint64_t lineno;
    asg_t *g;
    kstring_t s = {0, 0, 0}, fa_seq = {0, 0, 0};

    fp = fn && strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(0, "r");
    if (fp == 0) return 0;
    ks = ks_init(fp);
    g = asg_init();
    lineno = 0;
    fa_seg = 0;
    is_fa = is_fq = is_gfa = 0;
    
    while (ks_getuntil(ks, KS_SEP_LINE, &s, &dret) >= 0) {
        ++lineno;
        if (s.l == 0) // empty line
            continue;

        ret = 0;
        if (!is_gfa && s.s[0] == '>') { // FASTA header
            is_fa = 1;
            if (fa_seg) asg_update_seg_seq(fa_seg, fa_seq.l, fa_seq.s);
            // parse header
            asg_parse_fa_hdr(g, s.s, &fa_seg);
            fa_seq.l = 0;
        } else if (!is_gfa && s.s[0] == '@') { // FASTQ header
            is_fq = 1;
            // parse and write header
            asg_parse_fa_hdr(g, s.s, &fa_seg);
            // parse sequence
            if(ks_getuntil(ks, KS_SEP_LINE, &s, &dret) < 0)
                ret = PARSE_Q_ERR;
            else
                asg_update_seg_seq(fa_seg, s.l, s.s);
            ++lineno;
            // skip quality score lines
            if (ks_getuntil(ks, KS_SEP_LINE, &s, &dret) < 0 ||
                    ks_getuntil(ks, KS_SEP_LINE, &s, &dret) < 0)
                ret = PARSE_Q_ERR;
            lineno += 2;
        } else if (is_fa) { // FASTA sequence line
            // append sequence to seg
            kputsn(s.s, s.l, &fa_seq);
        } else {
            is_gfa = 1;
            if (s.s[0] == 'S')
                ret = gfa_parse_S(g, s.s);
            else if (s.s[0] == 'L')
                ret = gfa_parse_L(g, s.s);
        }

        if (ret < 0) {
            fprintf(stderr, "[E::%s] failed to parse %s file: %c-line at line %lu (error code %d)\n",
                    __func__, is_fa? "FASTA" : (is_fq? "FASTQ" : "GFA"), s.s[0], lineno, ret);
            exit(EXIT_FAILURE);
        }
    }
    if (is_fa && fa_seg) asg_update_seg_seq(fa_seg, fa_seq.l, fa_seq.s);

    free(fa_seq.s);
    free(s.s);
    ks_destroy(ks);
    gzclose(fp);

    // add vtx, fix symmetric arcs, sort and index etc
    asg_finalize_asmg(g);

    return g;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21c0
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21c0
cmpq $0x0, -0x10(%rbp)
je 0xc3f4
movq -0x10(%rbp), %rdi
leaq 0x173ac(%rip), %rsi     # 0x2377d
callq 0x2250
cmpl $0x0, %eax
je 0xc3f4
movq -0x10(%rbp), %rdi
leaq 0x17084(%rip), %rsi     # 0x2346a
callq 0x2350
movq %rax, -0x88(%rbp)
jmp 0xc409
xorl %edi, %edi
leaq 0x1706d(%rip), %rsi     # 0x2346a
callq 0x2110
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xc428
movq $0x0, -0x8(%rbp)
jmp 0xc6fc
movq -0x30(%rbp), %rdi
callq 0xc710
movq %rax, -0x38(%rbp)
callq 0xb1a0
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x38(%rbp), %rdi
movl $0x2, %esi
leaq -0x68(%rbp), %rdx
leaq -0x14(%rbp), %rcx
callq 0xc770
cmpl $0x0, %eax
jl 0xc6a7
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0xc497
jmp 0xc463
movl $0x0, -0x18(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xc4ef
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0xc4ef
movl $0x1, -0x1c(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0xc4d1
movq -0x40(%rbp), %rdi
movq -0x80(%rbp), %rax
movl %eax, %esi
movq -0x70(%rbp), %rdx
callq 0xc7b0
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xc840
movq $0x0, -0x80(%rbp)
jmp 0xc613
cmpl $0x0, -0x24(%rbp)
jne 0xc5af
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0xc5af
movl $0x1, -0x20(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xc840
movq -0x38(%rbp), %rdi
movl $0x2, %esi
leaq -0x68(%rbp), %rdx
leaq -0x14(%rbp), %rcx
callq 0xc770
cmpl $0x0, %eax
jge 0xc545
movl $0xfffffffe, -0x18(%rbp) # imm = 0xFFFFFFFE
jmp 0xc558
movq -0x40(%rbp), %rdi
movq -0x68(%rbp), %rax
movl %eax, %esi
movq -0x58(%rbp), %rdx
callq 0xc7b0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movl $0x2, %esi
leaq -0x68(%rbp), %rdx
leaq -0x14(%rbp), %rcx
callq 0xc770
cmpl $0x0, %eax
jl 0xc59a
movq -0x38(%rbp), %rdi
movl $0x2, %esi
leaq -0x68(%rbp), %rdx
leaq -0x14(%rbp), %rcx
callq 0xc770
cmpl $0x0, %eax
jge 0xc5a1
movl $0xfffffffe, -0x18(%rbp) # imm = 0xFFFFFFFE
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0xc611
cmpl $0x0, -0x1c(%rbp)
je 0xc5ca
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rax
movl %eax, %esi
leaq -0x80(%rbp), %rdx
callq 0xc910
jmp 0xc60f
movl $0x1, -0x24(%rbp)
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x53, %eax
jne 0xc5ef
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0xca60
movl %eax, -0x18(%rbp)
jmp 0xc60d
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4c, %eax
jne 0xc60b
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0xcfc0
movl %eax, -0x18(%rbp)
jmp 0xc60d
jmp 0xc60f
jmp 0xc611
jmp 0xc613
cmpl $0x0, -0x18(%rbp)
jge 0xc6a2
movq 0x1d9d4(%rip), %rax     # 0x29ff8
movq (%rax), %rax
movq %rax, -0x90(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xc644
leaq 0x17493(%rip), %rax     # 0x23ace
movq %rax, -0x98(%rbp)
jmp 0xc663
movl -0x20(%rbp), %edx
leaq 0x1748c(%rip), %rax     # 0x23ada
leaq 0x1747f(%rip), %rcx     # 0x23ad4
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rcx
movq -0x58(%rbp), %rax
movsbl (%rax), %r8d
movq -0x48(%rbp), %r9
movl -0x18(%rbp), %eax
leaq 0x173f8(%rip), %rsi     # 0x23a7f
leaq 0x17437(%rip), %rdx     # 0x23ac5
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2290
movl $0x1, %edi
callq 0x2430
jmp 0xc463
cmpl $0x0, -0x1c(%rbp)
je 0xc6c7
cmpq $0x0, -0x40(%rbp)
je 0xc6c7
movq -0x40(%rbp), %rdi
movq -0x80(%rbp), %rax
movl %eax, %esi
movq -0x70(%rbp), %rdx
callq 0xc7b0
movq -0x70(%rbp), %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
callq 0x2060
movq -0x38(%rbp), %rdi
callq 0xd6a0
movq -0x30(%rbp), %rdi
callq 0x2050
movq -0x50(%rbp), %rdi
callq 0xd6e0
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)