// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/tools/gt_splitfasta.c
// Function: split_fasta_file
static int split_fasta_file(const char *filename, GtUword max_filesize,
                            bool force, GtError *err)
{
  GtFile *srcfp = NULL, *destfp = NULL;
  GtStr *destfilename = NULL;
  GtUword filenum = 0, bytecount = 0, separator_pos;
  int read_bytes, had_err = 0;
  char buf[BUFSIZ];

  gt_error_check(err);
  gt_assert(filename && max_filesize);

  /* open source file */
  srcfp = gt_file_xopen(filename, "r");
  gt_assert(srcfp);

  /* read start characters */
  if ((read_bytes = gt_file_xread(srcfp, buf, BUFSIZ)) == 0) {
    gt_error_set(err, "file \"%s\" is empty", filename);
    had_err = -1;
  }
  bytecount += read_bytes;

  /* make sure the file is in fasta format */
  if (!had_err && buf[0] != '>') {
    gt_error_set(err, "file is not in FASTA format");
    had_err = -1;
  }

  if (!had_err) {
    /* open destination file */
    destfilename = gt_str_new();
    gt_str_append_cstr_nt(destfilename, filename,
                          gt_file_basename_length(filename));
    gt_str_append_char(destfilename, '.');
    gt_str_append_uword(destfilename, ++filenum);
    gt_str_append_cstr(destfilename,
                       gt_file_mode_suffix(gt_file_mode(srcfp)));
    if (!(destfp = gt_output_file_xopen_forcecheck(gt_str_get(destfilename),
                                                  "w",
                                                  force, err))) {
      had_err = -1;
    }
    if (!had_err)
      gt_file_xwrite(destfp, buf, read_bytes);

    while (!had_err &&
           (read_bytes = gt_file_xread(srcfp, buf, BUFSIZ)) != 0) {
      if (bytecount + read_bytes > max_filesize) {
        int offset = bytecount < max_filesize ? max_filesize - bytecount : 0;
        if ((separator_pos = buf_contains_separator(buf, offset, read_bytes))) {
          separator_pos--;
          gt_assert(separator_pos < read_bytes);
          if (separator_pos)
            gt_file_xwrite(destfp, buf, separator_pos);
          /* close current file */
          gt_file_delete(destfp);
          /* open new file */
          gt_str_reset(destfilename);
          gt_str_append_cstr_nt(destfilename, filename,
                                gt_file_basename_length(filename));
          gt_str_append_char(destfilename, '.');
          gt_str_append_uword(destfilename, ++filenum);
          gt_str_append_cstr(destfilename,
                             gt_file_mode_suffix(gt_file_mode(srcfp)));
          if (!(destfp =
                  gt_output_file_xopen_forcecheck(gt_str_get(destfilename), "w",
                                                 force, err))) {
            had_err = -1;
            break;
          }
          bytecount = read_bytes - separator_pos; /* reset */
          gt_assert(buf[separator_pos] == '>');
          gt_file_xwrite(destfp, buf + separator_pos,
                         read_bytes - separator_pos);
          continue;
        }
      }
      bytecount += read_bytes;
      gt_file_xwrite(destfp, buf, read_bytes);
    }
  }

  /* free */
  gt_str_delete(destfilename);

  /* close current file */
  gt_file_delete(destfp);

  /* close source file */
  gt_file_delete(srcfp);

  return had_err;
}

// Assembly:
subq $0x20a8, %rsp           # imm = 0x20A8
movb %dl, %al
movq %rdi, 0x20a0(%rsp)
movq %rsi, 0x2098(%rsp)
andb $0x1, %al
movb %al, 0x2097(%rsp)
movq %rcx, 0x2088(%rsp)
movq $0x0, 0x2080(%rsp)
movq $0x0, 0x2078(%rsp)
movq $0x0, 0x2070(%rsp)
movq $0x0, 0x2068(%rsp)
movq $0x0, 0x2060(%rsp)
movl $0x0, 0x2050(%rsp)
cmpq $0x0, 0x2088(%rsp)
je 0x77837
movq 0x2088(%rsp), %rdi
callq 0xd8a60
testb $0x1, %al
jne 0x777ff
jmp 0x77837
movq 0x5c479a(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x49e803(%rip), %rsi    # 0x516013
leaq 0x49e9a8(%rip), %rdx    # 0x5161bf
leaq 0x4b57ce(%rip), %rcx    # 0x52cfec
leaq 0x4b5648(%rip), %r8     # 0x52ce6d
movl $0x9a, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x77839
jmp 0x7783b
cmpq $0x0, 0x20a0(%rsp)
je 0x77851
cmpq $0x0, 0x2098(%rsp)
jne 0x77889
movq 0x5c4748(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x49e7b1(%rip), %rsi    # 0x516013
leaq 0x4b5794(%rip), %rdx    # 0x52cffd
leaq 0x4b577c(%rip), %rcx    # 0x52cfec
leaq 0x4b55f6(%rip), %r8     # 0x52ce6d
movl $0x9b, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x7788b
movq 0x20a0(%rsp), %rdi
leaq 0x4b4740(%rip), %rsi    # 0x52bfda
callq 0xdd9b0
movq %rax, 0x2080(%rsp)
cmpq $0x0, 0x2080(%rsp)
jne 0x778ea
movq 0x5c46e7(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x49e750(%rip), %rsi    # 0x516013
leaq 0x4b574c(%rip), %rdx    # 0x52d016
leaq 0x4b571b(%rip), %rcx    # 0x52cfec
leaq 0x4b5595(%rip), %r8     # 0x52ce6d
movl $0x9f, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x778ec
movq 0x2080(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq 0xde110
movl %eax, 0x2054(%rsp)
cmpl $0x0, %eax
jne 0x77938
movq 0x2088(%rsp), %rdi
movq 0x20a0(%rsp), %rdx
leaq 0x4da91b(%rip), %rsi    # 0x552241
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x2050(%rsp) # imm = 0xFFFFFFFF
movslq 0x2054(%rsp), %rax
addq 0x2060(%rsp), %rax
movq %rax, 0x2060(%rsp)
cmpl $0x0, 0x2050(%rsp)
jne 0x77985
movsbl 0x50(%rsp), %eax
cmpl $0x3e, %eax
je 0x77985
movq 0x2088(%rsp), %rdi
leaq 0x4b56a9(%rip), %rsi    # 0x52d01c
movb $0x0, %al
callq 0xd88c0
movl $0xffffffff, 0x2050(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x2050(%rsp)
jne 0x77dc9
callq 0x11d4a0
movq %rax, 0x2070(%rsp)
movq 0x2070(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x20a0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x20a0(%rsp), %rdi
callq 0xdd240
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %rax, %rdx
callq 0x11d830
movq 0x2070(%rsp), %rdi
movl $0x2e, %esi
callq 0x11da70
movq 0x2070(%rsp), %rdi
movq 0x2068(%rsp), %rsi
addq $0x1, %rsi
movq %rsi, 0x2068(%rsp)
callq 0x11d930
movq 0x2070(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x2080(%rsp), %rdi
callq 0xddac0
movl %eax, %edi
callq 0xdd1a0
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x11d550
movq 0x2070(%rsp), %rdi
callq 0x11dee0
movq %rax, %rdi
movb 0x2097(%rsp), %al
movq 0x2088(%rsp), %rcx
leaq 0x4ee465(%rip), %rsi    # 0x565ec5
andb $0x1, %al
movzbl %al, %edx
callq 0xf8250
movq %rax, 0x2078(%rsp)
cmpq $0x0, %rax
jne 0x77a83
movl $0xffffffff, 0x2050(%rsp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x2050(%rsp)
jne 0x77aa7
movq 0x2078(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movslq 0x2054(%rsp), %rdx
callq 0xde230
jmp 0x77aa9
xorl %eax, %eax
cmpl $0x0, 0x2050(%rsp)
movb %al, 0x2f(%rsp)
jne 0x77ae1
movq 0x2080(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq 0xde110
movl %eax, 0x2054(%rsp)
cmpl $0x0, %eax
setne %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x77aee
jmp 0x77dc7
movq 0x2060(%rsp), %rax
movslq 0x2054(%rsp), %rcx
addq %rcx, %rax
cmpq 0x2098(%rsp), %rax
jbe 0x77d90
movq 0x2060(%rsp), %rax
cmpq 0x2098(%rsp), %rax
jae 0x77b38
movq 0x2098(%rsp), %rax
subq 0x2060(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x77b41
xorl %eax, %eax
movq %rax, 0x20(%rsp)
jmp 0x77b41
movq 0x20(%rsp), %rax
movl %eax, 0x4c(%rsp)
leaq 0x50(%rsp), %rdi
movl 0x4c(%rsp), %esi
movl 0x2054(%rsp), %edx
callq 0x77e00
movq %rax, 0x2058(%rsp)
cmpq $0x0, %rax
je 0x77d8e
movq 0x2058(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x2058(%rsp)
movq 0x2058(%rsp), %rax
movslq 0x2054(%rsp), %rcx
cmpq %rcx, %rax
jb 0x77bd2
movq 0x5c43ff(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x49e468(%rip), %rsi    # 0x516013
leaq 0x4b5486(%rip), %rdx    # 0x52d038
leaq 0x4b5433(%rip), %rcx    # 0x52cfec
leaq 0x4b52ad(%rip), %r8     # 0x52ce6d
movl $0xc5, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x77bd4
cmpq $0x0, 0x2058(%rsp)
je 0x77bf9
movq 0x2078(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq 0x2058(%rsp), %rdx
callq 0xde230
movq 0x2078(%rsp), %rdi
callq 0xde430
movq 0x2070(%rsp), %rdi
callq 0x11e110
movq 0x2070(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x20a0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x20a0(%rsp), %rdi
callq 0xdd240
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x11d830
movq 0x2070(%rsp), %rdi
movl $0x2e, %esi
callq 0x11da70
movq 0x2070(%rsp), %rdi
movq 0x2068(%rsp), %rsi
addq $0x1, %rsi
movq %rsi, 0x2068(%rsp)
callq 0x11d930
movq 0x2070(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x2080(%rsp), %rdi
callq 0xddac0
movl %eax, %edi
callq 0xdd1a0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x11d550
movq 0x2070(%rsp), %rdi
callq 0x11dee0
movq %rax, %rdi
movb 0x2097(%rsp), %al
movq 0x2088(%rsp), %rcx
leaq 0x4ee1f2(%rip), %rsi    # 0x565ec5
andb $0x1, %al
movzbl %al, %edx
callq 0xf8250
movq %rax, 0x2078(%rsp)
cmpq $0x0, %rax
jne 0x77cfb
movl $0xffffffff, 0x2050(%rsp) # imm = 0xFFFFFFFF
jmp 0x77dc7
movslq 0x2054(%rsp), %rax
subq 0x2058(%rsp), %rax
movq %rax, 0x2060(%rsp)
movq 0x2058(%rsp), %rax
movsbl 0x50(%rsp,%rax), %eax
cmpl $0x3e, %eax
je 0x77d5d
movq 0x5c4274(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x49e2dd(%rip), %rsi    # 0x516013
leaq 0x4b5316(%rip), %rdx    # 0x52d053
leaq 0x4b52a8(%rip), %rcx    # 0x52cfec
leaq 0x4b5122(%rip), %r8     # 0x52ce6d
movl $0xd9, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x77d5f
movq 0x2078(%rsp), %rdi
leaq 0x50(%rsp), %rsi
addq 0x2058(%rsp), %rsi
movslq 0x2054(%rsp), %rdx
subq 0x2058(%rsp), %rdx
callq 0xde230
jmp 0x77aa9
jmp 0x77d90
movslq 0x2054(%rsp), %rax
addq 0x2060(%rsp), %rax
movq %rax, 0x2060(%rsp)
movq 0x2078(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movslq 0x2054(%rsp), %rdx
callq 0xde230
jmp 0x77aa9
jmp 0x77dc9
movq 0x2070(%rsp), %rdi
callq 0x11f560
movq 0x2078(%rsp), %rdi
callq 0xde430
movq 0x2080(%rsp), %rdi
callq 0xde430
movl 0x2050(%rsp), %eax
addq $0x20a8, %rsp           # imm = 0x20A8
retq
nop