// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x562e
movq -0x18(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, (%rax)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x800, -0x4c(%rbp)     # imm = 0x800
movslq -0x4c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x10960
movq %rax, -0x58(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x10960
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x10(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2250
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rdi
callq 0x10ad0
movq $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movslq -0x88(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x592c
movq $0x0, -0x90(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x84(%rbp), %eax
je 0x5714
movq $0x0, -0x8(%rbp)
jmp 0x5951
movq $0x0, -0x98(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x10(%rbp), %rdx
leaq -0x90(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2250
movq %rax, -0x48(%rbp)
cmpq $-0x1, %rax
je 0x579d
movq -0x90(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x5770
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x579d
movq -0x10(%rbp), %rdi
callq 0x21a0
movq %rax, -0x60(%rbp)
movq -0x90(%rbp), %rdi
callq 0x20d0
subq $0x1, %rax
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x5732
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
cmpq $-0x1, -0x48(%rbp)
jne 0x57fc
movl -0x88(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x90(%rbp), %rdi
callq 0x10ad0
movq -0x98(%rbp), %rax
addq $0x1, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x98(%rbp), %rcx
addq $0x1, %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x592c
movq -0x90(%rbp), %rdi
callq 0x10ad0
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x58fb
movq -0x80(%rbp), %rcx
subq $0x1, %rcx
movl $0x1, %eax
cmpq %rcx, %rax
jle 0x5851
movl $0x1, %eax
movq %rax, -0xa0(%rbp)
jmp 0x5860
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdx
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x1, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x4c(%rbp), %rcx
cmpq %rcx, %rax
jle 0x58f9
movl -0x4c(%rbp), %eax
addl $0x800, %eax            # imm = 0x800
movl %eax, -0x4c(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
shlq $0x3, %rsi
callq 0x10c50
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x10c50
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x58fb
movq -0x98(%rbp), %rcx
addq $0x1, %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x56da
movq -0x80(%rbp), %rdx
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nop