// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/sdict.c
// Function: write_fasta_file_from_agp_
void _write_fasta_file_from_agp_(const char *fa, const char *agp, FILE *fo, int line_wd, int allow_unknown_oris)
{
    iostream_t *agp_in;
    char *line;
    sdict_t *dict;
    sd_seq_t s;
    char sname[256], type[4], cname[256], cstarts[16], cends[16], oris[256];
    char *name = NULL;
    uint32_t c;
    int64_t i, l, cstart, cend, ns, L;

    agp_in = iostream_open(agp);
    if (agp_in == NULL) {
        fprintf(stderr, "[E::%s] cannot open file %s for reading\n", __func__, agp);
        exit(EXIT_FAILURE);
    }

    dict = make_sdict_from_fa(fa, 0);
    l = L = ns = 0;
    while ((line = iostream_getline(agp_in)) != NULL) {
        if (is_empty_line(line) || !strncmp(line, "#", 1))
            // header or empty lines
            continue;
        sname[0] = type[0] = cname[0] = cstarts[0] = cends[0] = oris[0] = '\0';
        sscanf(line, "%s %*s %*s %*s %s %s %s %s %s", sname, type, cname, cstarts, cends, oris);
        if (!strncmp(type, "N", 1) || !strncmp(type, "U", 1)) {
            cend = strtoul(cname, NULL, 10);
            for (i = 0; i < cend; ++i) {
                fputc('N', fo);
                if (++l % line_wd == 0)
                    fputc('\n', fo);
            }
            continue;
        }
        if (!name) {
            name = strdup(sname);
            fprintf(fo, ">%s\n", name);
            l = 0;
        }
        if (strcmp(sname, name)) {
            ++ns;
            L += l;
            free(name);
            name = strdup(sname);
            if (l % line_wd != 0)
                fputc('\n', fo);
            fprintf(fo, ">%s\n", name);
            l = 0;
        }

        cstart = strtoul(cstarts, NULL, 10);
        cend = strtoul(cends, NULL, 10);
        c = sd_get(dict, cname);
        if (c == UINT32_MAX) {
            fprintf(stderr, "[E::%s] sequence component '%s' not found\n", __func__, cname);
            exit(EXIT_FAILURE);
        }
        s = dict->s[c];
        if (cstart < 1 || cstart > cend || cend > s.len) {
            fprintf(stderr, "[E::%s] invalid sequence component %s:%ld-%ld on %s\n", __func__, cname, cstart, cend, sname);
            if (cend > s.len)
                fprintf(stderr, "[E::%s] sequence end position (%ld) greater than sequence length (%u)\n", __func__, cend, s.len);
            exit(EXIT_FAILURE);
        }
        if (!strncmp(oris, "+", 1) || (allow_unknown_oris && (!strncmp(oris, "?", 1) || !strncmp(oris, "0", 1) || !strncmp(oris, "na", 2)))) {
            // forward
            for (i = cstart - 1; i < cend; ++i) {
                fputc(s.seq[i], fo);
                if (++l % line_wd == 0)
                    fputc('\n', fo);
            }
        } else if (!strncmp(oris, "-", 1)) {
            // reverse
            for (i = cend; i >= cstart; --i) {
                fputc(comp_table[(int) s.seq[i - 1]], fo);
                if (++l % line_wd == 0)
                    fputc('\n', fo);
            }
        } else {
            fprintf(stderr, "[E::%s] unknown orientation of sequence component %s:%ld-%ld on %s: '%s'\n", __func__, cname, cstart, cend, sname, oris);
            if (allow_unknown_oris) {
                fprintf(stderr, "[E::%s] valid identifiers for unorientated sequence include: '?', '0' and 'na'\n", __func__);
                fprintf(stderr, "[E::%s] see %s\n", __func__, AGP_SPEC_ONLINE_DOC);
            }
            exit(EXIT_FAILURE);
        }
    }
    if (l % line_wd != 0)
        fputc('\n', fo);
    ++ns;
    L += l;
    fprintf(stderr, "[I::%s] Number sequences: %ld\n", __func__, ns);
    fprintf(stderr, "[I::%s] Number bases: %ld\n", __func__, L);

    if (name) 
        free(name);
    iostream_close(agp_in);
    sd_destroy(dict);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq $0x0, -0x388(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2c00
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x8c5a
movq 0x83c4(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rcx
leaq 0x470e(%rip), %rsi      # 0xd350
leaq 0x49e0(%rip), %rdx      # 0xd629
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x5c30
movq %rax, -0x38(%rbp)
movq $0x0, -0x3b8(%rbp)
movq $0x0, -0x3c0(%rbp)
movq $0x0, -0x3a0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2e80
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x92b4
movq -0x30(%rbp), %rdi
callq 0x2ba0
cmpl $0x0, %eax
jne 0x8cc9
movq -0x30(%rbp), %rdi
leaq 0x4761(%rip), %rsi      # 0xd41b
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x8ccb
jmp 0x8c8a
movb $0x0, -0x380(%rbp)
movb $0x0, -0x280(%rbp)
movb $0x0, -0x270(%rbp)
movb $0x0, -0x260(%rbp)
movb $0x0, -0x154(%rbp)
movb $0x0, -0x150(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x150(%rbp), %rdx
leaq -0x154(%rbp), %rcx
leaq -0x260(%rbp), %r8
leaq -0x270(%rbp), %r9
leaq -0x280(%rbp), %r10
leaq -0x380(%rbp), %rax
leaq 0x46f3(%rip), %rsi      # 0xd41d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2270
leaq -0x154(%rbp), %rdi
leaq 0x48fd(%rip), %rsi      # 0xd645
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x8d78
leaq -0x154(%rbp), %rdi
leaq 0x48e2(%rip), %rsi      # 0xd647
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x8e07
leaq -0x260(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2330
movq %rax, -0x3b0(%rbp)
movq $0x0, -0x398(%rbp)
movq -0x398(%rbp), %rax
cmpq -0x3b0(%rbp), %rax
jge 0x8e02
movq -0x18(%rbp), %rsi
movl $0x4e, %edi
callq 0x21b0
movq -0x3a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3a0(%rbp)
movslq -0x1c(%rbp), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x8dec
movq -0x18(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0x8dee
movq -0x398(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x398(%rbp)
jmp 0x8d9f
jmp 0x8c8a
cmpq $0x0, -0x388(%rbp)
jne 0x8e48
leaq -0x150(%rbp), %rdi
callq 0x23c0
movq %rax, -0x388(%rbp)
movq -0x18(%rbp), %rdi
movq -0x388(%rbp), %rdx
leaq 0x4813(%rip), %rsi      # 0xd649
movb $0x0, %al
callq 0x2200
movq $0x0, -0x3a0(%rbp)
leaq -0x150(%rbp), %rdi
movq -0x388(%rbp), %rsi
callq 0x21e0
cmpl $0x0, %eax
je 0x8ef2
movq -0x3b8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3b8(%rbp)
movq -0x3a0(%rbp), %rax
addq -0x3c0(%rbp), %rax
movq %rax, -0x3c0(%rbp)
movq -0x388(%rbp), %rdi
callq 0x2050
leaq -0x150(%rbp), %rdi
callq 0x23c0
movq %rax, -0x388(%rbp)
movq -0x3a0(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x8ece
movq -0x18(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
movq -0x18(%rbp), %rdi
movq -0x388(%rbp), %rdx
leaq 0x4769(%rip), %rsi      # 0xd649
movb $0x0, %al
callq 0x2200
movq $0x0, -0x3a0(%rbp)
leaq -0x270(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2330
movq %rax, -0x3a8(%rbp)
leaq -0x280(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2330
movq %rax, -0x3b0(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x59f0
movl %eax, -0x38c(%rbp)
cmpl $-0x1, -0x38c(%rbp)
jne 0x8f79
movq 0x80a8(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq -0x260(%rbp), %rcx
leaq 0x46ed(%rip), %rsi      # 0xd64e
leaq 0x46c1(%rip), %rdx      # 0xd629
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x38c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x1, -0x3a8(%rbp)
jl 0x8fd2
movq -0x3a8(%rbp), %rax
cmpq -0x3b0(%rbp), %rax
jg 0x8fd2
movq -0x3b0(%rbp), %rax
movl -0x40(%rbp), %ecx
cmpq %rcx, %rax
jle 0x9054
movq 0x801f(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq -0x260(%rbp), %rcx
movq -0x3a8(%rbp), %r8
movq -0x3b0(%rbp), %r9
leaq -0x150(%rbp), %rax
leaq 0x467a(%rip), %rsi      # 0xd679
leaq 0x4623(%rip), %rdx      # 0xd629
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2200
movq -0x3b0(%rbp), %rax
movl -0x40(%rbp), %ecx
cmpq %rcx, %rax
jle 0x904a
movq 0x7fd1(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x3b0(%rbp), %rcx
movl -0x40(%rbp), %r8d
leaq 0x4672(%rip), %rsi      # 0xd6ae
leaq 0x45e6(%rip), %rdx      # 0xd629
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
leaq -0x380(%rbp), %rdi
leaq 0x4693(%rip), %rsi      # 0xd6f5
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x90d6
cmpl $0x0, -0x20(%rbp)
je 0x915a
leaq -0x380(%rbp), %rdi
leaq 0x466e(%rip), %rsi      # 0xd6f7
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x90d6
leaq -0x380(%rbp), %rdi
leaq 0x410f(%rip), %rsi      # 0xd1b5
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x90d6
leaq -0x380(%rbp), %rdi
leaq 0x4636(%rip), %rsi      # 0xd6f9
movl $0x2, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x915a
movq -0x3a8(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x398(%rbp)
movq -0x398(%rbp), %rax
cmpq -0x3b0(%rbp), %rax
jge 0x9155
movq -0x48(%rbp), %rax
movq -0x398(%rbp), %rcx
movsbl (%rax,%rcx), %edi
movq -0x18(%rbp), %rsi
callq 0x21b0
movq -0x3a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3a0(%rbp)
movslq -0x1c(%rbp), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x913f
movq -0x18(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0x9141
movq -0x398(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x398(%rbp)
jmp 0x90e8
jmp 0x92af
leaq -0x380(%rbp), %rdi
leaq 0x4034(%rip), %rsi      # 0xd19c
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x920d
movq -0x3b0(%rbp), %rax
movq %rax, -0x398(%rbp)
movq -0x398(%rbp), %rax
cmpq -0x3a8(%rbp), %rax
jl 0x9208
movq -0x48(%rbp), %rax
movq -0x398(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0x808a(%rip), %rax      # 0x11240
movsbl (%rax,%rcx), %edi
movq -0x18(%rbp), %rsi
callq 0x21b0
movq -0x3a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3a0(%rbp)
movslq -0x1c(%rbp), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x91f2
movq -0x18(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0x91f4
movq -0x398(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x398(%rbp)
jmp 0x9189
jmp 0x92ad
movq 0x7de4(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq -0x260(%rbp), %rcx
movq -0x3a8(%rbp), %r8
movq -0x3b0(%rbp), %r9
leaq -0x150(%rbp), %r10
leaq -0x380(%rbp), %rax
leaq 0x44bb(%rip), %rsi      # 0xd6fc
leaq 0x43e1(%rip), %rdx      # 0xd629
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2200
cmpl $0x0, -0x20(%rbp)
je 0x92a3
movq 0x7d93(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x42d1(%rip), %rsi      # 0xd540
leaq 0x43b3(%rip), %rdx      # 0xd629
movb $0x0, %al
callq 0x2200
movq 0x7d74(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x4302(%rip), %rsi      # 0xd590
leaq 0x4394(%rip), %rdx      # 0xd629
leaq 0x4304(%rip), %rcx      # 0xd5a0
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
jmp 0x92af
jmp 0x8c8a
movq -0x3a0(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x92d8
movq -0x18(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
movq -0x3b8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x3b8(%rbp)
movq -0x3a0(%rbp), %rax
addq -0x3c0(%rbp), %rax
movq %rax, -0x3c0(%rbp)
movq 0x7cf2(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x3b8(%rbp), %rcx
leaq 0x442f(%rip), %rsi      # 0xd746
leaq 0x430b(%rip), %rdx      # 0xd629
movb $0x0, %al
callq 0x2200
movq 0x7ccc(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x3c0(%rbp), %rcx
leaq 0x4428(%rip), %rsi      # 0xd765
leaq 0x42e5(%rip), %rdx      # 0xd629
movb $0x0, %al
callq 0x2200
cmpq $0x0, -0x388(%rbp)
je 0x9361
movq -0x388(%rbp), %rdi
callq 0x2050
movq -0x28(%rbp), %rdi
callq 0x2da0
movq -0x38(%rbp), %rdi
callq 0x5230
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
nopl (%rax)