// File: /workspace/github_c_makefile_star2_O3/felipelouza[P]egap/tools/lib/file.c
// Function: count_multiple_fasta
int_t* count_multiple_fasta(FILE* f_in, int_t *k, uint_t chunk_size, size_t *n, int_t *chunks, ssize_t** pos) {

  if((*k)==0) (*k)=I_MAX;
  size_t sum=0;
  ssize_t size=0;

  int nalloc = N_ALLOC;
  int_t *K = (int_t*) malloc(nalloc*sizeof(int_t));
  (*pos) = (ssize_t*) malloc((nalloc+1)*sizeof(ssize_t));

	ssize_t tell_cat=0, tell=0;
	(*pos)[0]=tell;

/**/
  char *buf = NULL;
  size_t len = 0;

  size = getline(&buf, &len, f_in);// first sequence
  free(buf);

  int_t d=0;
  int count=0;
  int i;
  for(i=0; i<(*k); i++){

    char *buf = NULL;

    if(i!=count) return 0;

    size_t p=0;
    buf = NULL; len = 0;  
    while((size = getline(&buf, &len, f_in))!=-1){

      if(buf[0] == '>'){
        count++;
        break;
      }
			tell_cat = ftell(f_in);
      p+=strlen(buf)-1;
    }

    d++;//number of strings

    if (size == -1){//EOF
      (*k) = i+1;
      free(buf);
      sum+=p+1;
      (*n) += p+1;
      break;   
      //return 0;
    }

    free(buf);
    size = p+1;

    sum += size;//sum of lengths

    if(sum > chunk_size){

      //printf("K[%d] = %d\tsum = %lu\n", (*chunks), d-1, sum-size);

      K[(*chunks)++]=max(1,d-1);
      (*pos)[(*chunks)]=tell;
      sum = size; d=1;

      if((*chunks) > nalloc){
        nalloc += N_ALLOC;
        K = realloc(K, sizeof(int_t) * nalloc);
        (*pos) = realloc((*pos), sizeof(ssize_t) * (nalloc+1));
      }
    }

    (*n) += p+1;
		tell=tell_cat;
  }

  {//last chunk
    //printf("**K[%d] = %d\tsum = %u\n", (*chunks), d, sum);
    K[(*chunks)++]=d;
  }

return K;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r15
movq %r8, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %rbx
movq %rdi, %rbp
cmpq $0x0, (%rsi)
jne 0x49bf
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, (%rbx)
movl $0x4000, %edi           # imm = 0x4000
callq 0x9fe6
movq %rax, 0x18(%rsp)
movl $0x4008, %edi           # imm = 0x4008
callq 0x9fe6
movq %rax, (%r15)
xorl %r12d, %r12d
movq %r12, (%rax)
leaq 0x60(%rsp), %r14
movq %r12, (%r14)
leaq 0x20(%rsp), %rsi
movq %r12, (%rsi)
movq %r14, %rdi
movq %rbp, %rdx
callq 0x2250
movq (%r14), %rdi
callq 0xa09d
cmpq %r12, (%rbx)
jle 0x4b9b
movq %r15, 0x48(%rsp)
movl $0x800, 0x14(%rsp)      # imm = 0x800
xorl %eax, %eax
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %ecx, %ecx
movq %rbx, 0x28(%rsp)
movq %rcx, 0x58(%rsp)
movq %rax, 0x40(%rsp)
movq %r15, %rbx
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
callq 0x2250
cmpq $-0x1, %rax
je 0x4bc2
movq 0x8(%rsp), %rdi
movl $0x1, %r14d
cmpb $0x3e, (%rdi)
movq %rbx, %r15
je 0x4abe
xorl %eax, %eax
movq %rax, %r14
movq %rbp, %rdi
callq 0x21a0
movq %rax, %r15
movq 0x8(%rsp), %rdi
callq 0x20d0
movq %rax, %r12
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
callq 0x2250
cmpq $-0x1, %rax
je 0x4b71
leaq (%r14,%r12), %rax
decq %rax
movq 0x8(%rsp), %rdi
cmpb $0x3e, (%rdi)
jne 0x4a73
addq %r12, %r14
callq 0xa09d
movq 0x58(%rsp), %rcx
addq %r14, %rcx
cmpq 0x50(%rsp), %rcx
jbe 0x4b48
cmpq $0x2, %r13
movl $0x1, %r12d
cmovlq %r12, %r13
movq 0x30(%rsp), %rdx
movq (%rdx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rdx)
movq 0x18(%rsp), %rdi
movq %r13, (%rdi,%rax,8)
movq 0x48(%rsp), %r13
movq (%r13), %rax
movq (%rdx), %rcx
movq %rbx, (%rax,%rcx,8)
movslq 0x14(%rsp), %rbx
cmpq %rbx, (%rdx)
jle 0x4b43
leal 0x800(%rbx), %eax
movl %eax, 0x14(%rsp)
leaq 0x4000(,%rbx,8), %rsi
callq 0xa166
movq %rax, 0x18(%rsp)
movq (%r13), %rdi
leaq 0x4008(,%rbx,8), %rsi
callq 0xa166
movq %rax, (%r13)
movq %r14, %rcx
jmp 0x4b4e
incq %r13
movq %r13, %r12
movq 0x38(%rsp), %rax
addq %r14, (%rax)
movq 0x40(%rsp), %rax
incq %rax
movq %r12, %r13
movq 0x28(%rsp), %rbx
cmpq %rax, (%rbx)
jg 0x4a29
jmp 0x4b9b
addq %r12, %r14
incq %r13
movq 0x40(%rsp), %rcx
incl %ecx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rdi
callq 0xa09d
movq 0x38(%rsp), %rax
addq %r14, (%rax)
movq %r13, %r12
movq 0x30(%rsp), %rdx
movq (%rdx), %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, (%rdx)
movq 0x18(%rsp), %rax
movq %r12, (%rax,%rsi,8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %r14d
jmp 0x4b74