// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %r8, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, %r15
movq %rdi, %rbp
cmpq $0x0, (%rsi)
jne 0x439a
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, (%r15)
movl $0x4000, %edi           # imm = 0x4000
callq 0x92c8
movq %rax, 0x8(%rsp)
movl $0x4008, %edi           # imm = 0x4008
callq 0x92c8
movq %rbx, 0x18(%rsp)
movq %rax, (%rbx)
andq $0x0, (%rax)
leaq 0x60(%rsp), %r14
andq $0x0, (%r14)
leaq 0x58(%rsp), %r13
andq $0x0, (%r13)
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2250
movq (%r14), %rdi
callq 0x939e
movl $0x800, 0x4(%rsp)       # imm = 0x800
xorl %ecx, %ecx
leaq 0x10(%rsp), %r14
xorl %edx, %edx
xorl %eax, %eax
xorl %ebx, %ebx
movq %r15, 0x28(%rsp)
cmpq %rcx, (%r15)
jle 0x4560
movq %rdx, 0x50(%rsp)
movq %rcx, 0x38(%rsp)
andq $0x0, 0x10(%rsp)
andq $0x0, 0x58(%rsp)
movq %rax, 0x48(%rsp)
movq %rax, %r15
xorl %r12d, %r12d
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2250
cmpq $-0x1, %rax
je 0x4533
movq 0x10(%rsp), %rdi
cmpb $0x3e, (%rdi)
je 0x446b
movq %rbp, %rdi
callq 0x21a0
movq %rax, %r15
movq 0x10(%rsp), %rdi
callq 0x20d0
addq %rax, %r12
decq %r12
jmp 0x442c
callq 0x939e
movq 0x50(%rsp), %rdx
addq %r12, %rdx
incq %rdx
incq %r12
cmpq 0x40(%rsp), %rdx
jbe 0x450b
cmpq $0x2, %rbx
pushq $0x1
popq %rsi
cmovlq %rsi, %rbx
movq 0x20(%rsp), %rdx
movq (%rdx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rdx)
movq 0x8(%rsp), %rdi
movq %rbx, (%rdi,%rax,8)
movq 0x18(%rsp), %r9
movq (%r9), %rax
movq (%rdx), %rcx
movq 0x48(%rsp), %r8
movq %r8, (%rax,%rcx,8)
movslq 0x4(%rsp), %rbx
cmpq %rbx, (%rdx)
jle 0x4510
leal 0x800(%rbx), %eax
movl %eax, 0x4(%rsp)
leaq 0x4000(,%rbx,8), %rsi
callq 0x9470
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0x4008(,%rbx,8), %rsi
callq 0x9470
pushq $0x1
popq %rbx
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq %r12, %rdx
jmp 0x4516
incq %rbx
jmp 0x4516
movq %r12, %rdx
movq %rsi, %rbx
movq 0x38(%rsp), %rcx
incq %rcx
movq 0x30(%rsp), %rax
addq %r12, (%rax)
movq %r15, %rax
movq 0x28(%rsp), %r15
jmp 0x4402
incq %rbx
movq 0x38(%rsp), %rcx
incl %ecx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rdi
callq 0x939e
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
addq %r12, %rax
incq %rax
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rdx
movq (%rdx), %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, (%rdx)
movq %rbx, (%rax,%rsi,8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq