// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/tools/lib/file.c
// Function: count_multiple_fastq
int_t* count_multiple_fastq(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;

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

  int i;
  int_t d=0;
  size_t len = 0;
  char *buf = NULL;
	ssize_t tell=0;
	(*pos)[0]=tell;

  for(i=0; i<(*k); i++){

    buf = NULL; len = 0;  
    ssize_t size = getline(&buf, &len, f_in); // @'s line
    //printf("Line of size: %d\n", strlen(buf));
    free(buf);buf = NULL;
    //if (size <= 1) return 0;
    if (size == -1){//EOF
      *k = i;
      break;   
      //return 0;
    }

    char* c_buffer = NULL; len = 0; 
    size = getline(&c_buffer, &len, f_in); // read line
    //printf("Line of size: %d\n", strlen(c_buffer[i]));
    free(c_buffer);
    
    d++;//number of strings
    sum += size;//sum of lengths

    if(sum > chunk_size){
      //printf("K[%d] = %d\tsum = %lu\n", (*chunks), d-1, sum-size);
      
      K[(*chunks)++]=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) += (size_t)size;

    buf = NULL; len = 0;  
    size = getline(&buf, &len, f_in); // +'s line
    // printf("Line of size: %d\n", strlen(buf));
    free(buf);
    buf = NULL; len = 0;  
    size = getline(&buf, &len, f_in); // @'s line
    //printf("Line of size: %d\n", strlen(buf));
    free(buf);buf = NULL;
    //printf("Line %d OK\n", i);
		tell = ftell(f_in);
  }

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

return K;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x536e
movq -0x10(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, (%rax)
movq $0x0, -0x38(%rbp)
movl $0x800, -0x3c(%rbp)     # imm = 0x800
movslq -0x3c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x10960
movq %rax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x10960
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movl $0x0, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x55ba
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2250
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rdi
callq 0x10ad0
movq $0x0, -0x68(%rbp)
cmpq $-0x1, -0x78(%rbp)
jne 0x543d
movslq -0x4c(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x55ba
movq $0x0, -0x80(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2250
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rdi
callq 0x10ad0
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0x552d
movq -0x58(%rbp), %rdx
subq $0x1, %rdx
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x70(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x1, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jle 0x552b
movl -0x3c(%rbp), %eax
addl $0x800, %eax            # imm = 0x800
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
shlq $0x3, %rsi
callq 0x10c50
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x10c50
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x552d
movq -0x78(%rbp), %rcx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2250
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rdi
callq 0x10ad0
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x68(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2250
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rdi
callq 0x10ad0
movq $0x0, -0x68(%rbp)
movq -0x8(%rbp), %rdi
callq 0x21a0
movq %rax, -0x70(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x53df
movq -0x58(%rbp), %rdx
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)