// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/sdict.c
// Function: write_segs_to_fasta
uint64_t write_segs_to_fasta(sd_seg_t *segs, uint32_t n, sd_aseq_t *aseq, sdict_t *sd, char *name, int line_wd, FILE *fo)
{
    uint32_t i, j;
    uint64_t l, len;
    int64_t k, m;
    sd_seg_t seg;
    char *s;
    if (!name) name = aseq? aseq->name : 0;
    if (!name) {
        fprintf(stderr, "[E::%s] sequence name required\n", __func__);
        exit(EXIT_FAILURE);
    }
    fprintf(fo, ">%s\n", name);
    l = len = 0;
    if (aseq) {
        // with gap information
        for (i = 0, j = 0; i < n; ++i) {
            while (j < aseq->gn && aseq->gs[j] <= i) {
                // print gap
                for (k = 0, m = aseq->gsize[j]; k < m; ++k) {
                    fputc('N', fo);
                    if (++l % line_wd == 0)
                        fputc('\n', fo);
                }
                len += m;
                ++j;
            }
            seg = segs[i];
            s = sd->s[seg.c >> 1].seq;
            if ((seg.c&1) == 0) {
                // forward
                for (k = seg.x, m = seg.x + seg.y; k < m; ++k) {
                    fputc(s[k], fo);
                    if (++l % line_wd == 0)
                        fputc('\n', fo);
                }
            } else {
                // reverse
                for (k = seg.x + seg.y - 1, m = seg.x; k >= m; --k) {
                    fputc(comp_table[(int) s[k]], fo);
                    if (++l % line_wd == 0)
                        fputc('\n', fo);
                }
            }
            len += seg.y;
        }
        while (j < aseq->gn) {
            // print trailing gap
            for (k = 0, m = aseq->gsize[j]; k < m; ++k) {
                fputc('N', fo);
                if (++l % line_wd == 0)
                    fputc('\n', fo);
            }
            len += m;
            ++j;
        }
        if (len != aseq->len + aseq->gap) {
            fprintf(stderr, "[E::%s] sequence length conflict\n", __func__);
            exit(EXIT_FAILURE);
        }
    } else {
        // no gap information provided
        // using default settings
        for (i = 0; i < n; ++i) {
            seg = segs[i];
            s = sd->s[seg.c >> 1].seq;
            if ((seg.c&1) == 0) {
                // forward
                for (k = seg.x, m = seg.x + seg.y; k < m; ++k) {
                    fputc(s[k], fo);
                    if (++l % line_wd == 0)
                        fputc('\n', fo);
                }
            } else {
                // reverse
                for (k = seg.x + seg.y - 1, m = seg.x; k >= m; --k) {
                    fputc(comp_table[(int) s[k]], fo);
                    if (++l % line_wd == 0)
                        fputc('\n', fo);
                }
            }
            len += seg.y;
            
            if (i != n - 1) {
                for (k = 0, m = DEFAULT_AGP_GAP_SIZE; k < m; ++k) {
                    fputc('N', fo);
                    if (++l % line_wd == 0)
                        fputc('\n', fo);
                }
                len += m;
            }
        }
    }

    if (l % line_wd != 0)
        fputc('\n', fo);
    
    return len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x9e1a
cmpq $0x0, -0x18(%rbp)
je 0x9e04
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0x9e0f
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0x9e0f
movq -0x98(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x9e4a
movq 0x71d0(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x394e(%rip), %rsi      # 0xd780
leaq 0x39d1(%rip), %rdx      # 0xd80a
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
movq 0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x37f0(%rip), %rsi      # 0xd649
movb $0x0, %al
callq 0x2200
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xa18f
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0xa0b1
jmp 0x9e97
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x20(%rdx), %ecx
movb %al, -0x99(%rbp)
jae 0x9ec5
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x30(%rbp), %eax
setbe %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x9ed4
jmp 0x9f59
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0x9f3f
movq 0x10(%rbp), %rsi
movl $0x4e, %edi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x9f2f
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0x9f31
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x9eee
movq -0x58(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9e97
movq -0x8(%rbp), %rsi
movl -0x30(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0x88(%rbp), %rdi
movl $0x30, %edx
callq 0x2220
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x70(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x70(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa017
movl -0x6c(%rbp), %eax
movq %rax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
addl -0x68(%rbp), %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0xa012
movq -0x90(%rbp), %rax
movq -0x50(%rbp), %rcx
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xa002
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0xa004
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x9fb7
jmp 0xa098
movl -0x6c(%rbp), %eax
addl -0x68(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jl 0xa096
movq -0x90(%rbp), %rax
movq -0x50(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0x71f0(%rip), %rax      # 0x11240
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xa086
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0xa088
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa02d
jmp 0xa098
movl -0x68(%rbp), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x9e89
jmp 0xa0b3
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0xa148
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0xa12e
movq 0x10(%rbp), %rsi
movl $0x4e, %edi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xa11e
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0xa120
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa0dd
movq -0x58(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xa0b3
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x18(%rbp), %rdx
addq 0x10(%rdx), %rcx
cmpq %rcx, %rax
je 0xa18a
movq 0x6e90(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x36ac(%rip), %rsi      # 0xd81e
leaq 0x3691(%rip), %rdx      # 0xd80a
movb $0x0, %al
callq 0x2200
movl $0x1, %edi
callq 0x2370
jmp 0xa37b
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0xa379
movq -0x8(%rbp), %rsi
movl -0x30(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
leaq -0x88(%rbp), %rdi
movl $0x30, %edx
callq 0x2220
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x70(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x70(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa260
movl -0x6c(%rbp), %eax
movq %rax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
addl -0x68(%rbp), %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0xa25b
movq -0x90(%rbp), %rax
movq -0x50(%rbp), %rcx
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xa24b
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0xa24d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa200
jmp 0xa2e1
movl -0x6c(%rbp), %eax
addl -0x68(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movl -0x6c(%rbp), %eax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jl 0xa2df
movq -0x90(%rbp), %rax
movq -0x50(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0x6fa7(%rip), %rax      # 0x11240
movsbl (%rax,%rcx), %edi
movq 0x10(%rbp), %rsi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xa2cf
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0xa2d1
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa276
jmp 0xa2e1
movl -0x68(%rbp), %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x30(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xa369
movq $0x0, -0x50(%rbp)
movslq 0x6f28(%rip), %rax      # 0x11230
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jge 0xa35d
movq 0x10(%rbp), %rsi
movl $0x4e, %edi
callq 0x21b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0xa34d
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
jmp 0xa34f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa30c
movq -0x58(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xa36b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa196
jmp 0xa37b
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
je 0xa39c
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x21b0
movq -0x48(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)