// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %r9, %rbx
movq %r8, 0x40(%rsp)
movq %rcx, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, %rbp
movq %rdi, %r13
cmpq $0x0, (%rsi)
jne 0x4953
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, (%rbp)
movl $0x4000, %edi           # imm = 0x4000
callq 0x9fd2
movq %rax, 0x30(%rsp)
movl $0x4008, %edi           # imm = 0x4008
callq 0x9fd2
movq %rax, (%rbx)
xorl %r12d, %r12d
movq %r12, (%rax)
leaq 0x70(%rsp), %r14
movq %r12, (%r14)
leaq 0x38(%rsp), %rsi
movq %r12, (%rsi)
movq %r14, %rdi
movq %r13, %rdx
callq 0x2250
movq (%r14), %rdi
callq 0xa089
cmpq %r12, (%rbp)
jle 0x4ba4
movq %rbx, 0x28(%rsp)
movl $0x800, 0x1c(%rsp)      # imm = 0x800
xorl %ebx, %ebx
xorl %ecx, %ecx
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
xorl %r14d, %r14d
xorl %edx, %edx
movq %rbp, 0x48(%rsp)
movq $0x0, 0x10(%rsp)
movl %ecx, %eax
movl $0x1, %r12d
cmpq %rax, %rbx
jne 0x4b86
movq %r15, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movl %ecx, 0xc(%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x38(%rsp)
leaq 0x10(%rsp), %r12
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0x2250
cmpq $-0x1, %rax
sete %al
je 0x4a29
movq 0x10(%rsp), %rcx
cmpb $0x3e, (%rcx)
jne 0x4a2d
xorl %ebp, %ebp
jmp 0x4a6d
xorl %ebp, %ebp
jmp 0x4a71
xorl %ebp, %ebp
movq %r13, %rdi
callq 0x21a0
movq %rax, %r14
movq 0x10(%rsp), %rdi
callq 0x20d0
addq %rax, %rbp
decq %rbp
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0x2250
cmpq $-0x1, %rax
sete %al
je 0x4a71
movq 0x10(%rsp), %rcx
cmpb $0x3e, (%rcx)
jne 0x4a2f
incl 0xc(%rsp)
movq 0x58(%rsp), %rcx
leaq 0x1(%rcx), %r15
testb %al, %al
je 0x4aad
leaq 0x1(%rbx), %rax
movq 0x48(%rsp), %rcx
movq %rax, (%rcx)
movq 0x10(%rsp), %rdi
callq 0xa089
movq 0x50(%rsp), %rdx
addq %rbp, %rdx
incq %rdx
incq %rbp
movl $0x2, %r12d
jmp 0x4b6f
movq 0x10(%rsp), %rdi
callq 0xa089
movq 0x50(%rsp), %rdx
addq %rbp, %rdx
incq %rdx
incq %rbp
xorl %r12d, %r12d
cmpq 0x60(%rsp), %rdx
jbe 0x4b6a
movq 0x58(%rsp), %r15
cmpq $0x2, %r15
movl $0x1, %r8d
cmovlq %r8, %r15
movq 0x40(%rsp), %rsi
movq (%rsi), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rsi)
movq 0x30(%rsp), %rdi
movq %r15, (%rdi,%rax,8)
movq 0x28(%rsp), %r9
movq (%r9), %rax
movq (%rsi), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
movslq 0x1c(%rsp), %r15
cmpq %r15, (%rsi)
jle 0x4b5c
leal 0x800(%r15), %eax
movl %eax, 0x1c(%rsp)
leaq 0x4000(,%r15,8), %rsi
callq 0xa152
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rdi
leaq 0x4008(,%r15,8), %rsi
callq 0xa152
movl $0x1, %r8d
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movq %rbp, %rdx
movq %r14, 0x20(%rsp)
movl 0xc(%rsp), %ecx
jmp 0x4b76
movq %r14, 0x20(%rsp)
movl 0xc(%rsp), %ecx
movq %r15, %r8
movq 0x68(%rsp), %rax
addq %rbp, (%rax)
movq %r8, %r15
movq 0x48(%rsp), %rbp
testl %r12d, %r12d
jne 0x4b9a
incq %rbx
cmpq %rbx, (%rbp)
jg 0x49c9
jmp 0x4ba7
cmpl $0x2, %r12d
je 0x4ba7
xorl %eax, %eax
jmp 0x4bc2
xorl %r15d, %r15d
movq 0x40(%rsp), %rdx
movq (%rdx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rdx)
movq 0x30(%rsp), %rcx
movq %r15, (%rcx,%rax,8)
movq %rcx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq