// File: gpertea[P]gclib/GBase.cpp
// Function: writeFasta(_IO_FILE*, char const*, char const*, char const*, int, int)
void writeFasta(FILE *fw, const char* seqid, const char* descr,
        const char* seq, int linelen, int seqlen) {
  fflush(fw);
  // write header line only if given!
  if (seqid!=NULL) {
    if (descr==NULL || descr[0]==0)
             fprintf(fw,">%s\n",seqid);
        else fprintf(fw,">%s %s\n",seqid, descr);
    }
  fflush(fw);
  if (seq==NULL || *seq==0) return; //nothing to print
  if (linelen==0) { //unlimited line length: write the whole sequence on a line
     if (seqlen>0)
             fwrite((const void*)seq, 1, seqlen,fw);
        else fprintf(fw,"%s",seq);
     fprintf(fw,"\n");
     fflush(fw);
     return;
     }
  int ilen=0;
  if (seqlen>0) { //seq length given, so we know when to stop
    for (int i=0; i < seqlen; i++, ilen++) {
            if (ilen == linelen) {
                 fputc('\n', fw);
                 ilen = 0;
                 }
            fputc(seq[i], fw);
            }
    fputc('\n', fw);
    }
  else { //seq length not given, stop when 0 encountered
    for (int i=0; seq[i]!=0; i++, ilen++) {
            if (ilen == linelen) {
                 fputc('\n', fw);
                 ilen = 0;
                 }
            fputc(seq[i], fw);
            } //for
    fputc('\n', fw);
    }
  fflush(fw);
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x22c0
cmpq $0x0, -0x10(%rbp)
je 0x56c7
cmpq $0x0, -0x18(%rbp)
je 0x5693
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x56ab
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0xea4a(%rip), %rsi      # 0x140ec
movb $0x0, %al
callq 0x2370
jmp 0x56c5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0xea33(%rip), %rsi      # 0x140f1
movb $0x0, %al
callq 0x2370
jmp 0x56c7
movq -0x8(%rbp), %rdi
callq 0x22c0
cmpq $0x0, -0x20(%rbp)
je 0x56e3
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x56e8
jmp 0x5829
cmpl $0x0, -0x24(%rbp)
jne 0x5742
cmpl $0x0, -0x28(%rbp)
jle 0x570c
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl $0x1, %esi
callq 0x2460
jmp 0x5722
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0xe905(%rip), %rsi      # 0x14020
movb $0x0, %al
callq 0x2370
movq -0x8(%rbp), %rdi
leaq 0xef1a(%rip), %rsi      # 0x14647
movb $0x0, %al
callq 0x2370
movq -0x8(%rbp), %rdi
callq 0x22c0
jmp 0x5829
movl $0x0, -0x2c(%rbp)
cmpl $0x0, -0x28(%rbp)
jle 0x57b4
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x57a4
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x577b
movq -0x8(%rbp), %rsi
movl $0xa, %edi
callq 0x2300
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %edi
movq -0x8(%rbp), %rsi
callq 0x2300
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5756
movq -0x8(%rbp), %rsi
movl $0xa, %edi
callq 0x2300
jmp 0x5820
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x5812
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x57e9
movq -0x8(%rbp), %rsi
movl $0xa, %edi
callq 0x2300
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %edi
movq -0x8(%rbp), %rsi
callq 0x2300
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x57bb
movq -0x8(%rbp), %rsi
movl $0xa, %edi
callq 0x2300
movq -0x8(%rbp), %rdi
callq 0x22c0
addq $0x40, %rsp
popq %rbp
retq
nop