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

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

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

    size_t len = 0;
    char* c_buffer = NULL;
      
    ssize_t size = getline(&c_buffer, &len, f_in);
    if (size == -1){//EOF
      *k = i;
      free(c_buffer);
      break;   
      //return 0;
    }
    free(c_buffer);

    d++;//number of strings
    sum += size;//sum of lengths

    if(sum > chunk_size){
      //printf("K[%d] = %d\tsum = %lu\n", (*chunks), max(1,d-1), sum);
      
      K[(*chunks)++]=max(1,d-1);
      (*pos)[(*chunks)]=tell;
			if(d==1) d=0;
      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;
		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 0x511e
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, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x52fd
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2250
movq %rax, -0x78(%rbp)
cmpq $-0x1, -0x78(%rbp)
jne 0x51d5
movslq -0x54(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x70(%rbp), %rdi
callq 0x10ad0
jmp 0x52fd
movq -0x70(%rbp), %rdi
callq 0x10ad0
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x78(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0x52d4
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
movl $0x1, %eax
cmpq %rcx, %rax
jle 0x5221
movl $0x1, %eax
movq %rax, -0x80(%rbp)
jmp 0x522d
movq -0x60(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%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 -0x50(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
cmpq $0x1, -0x60(%rbp)
jne 0x526f
movq $0x0, -0x60(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x1, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
cmpq %rcx, %rax
jle 0x52d2
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 0x52d4
movq -0x78(%rbp), %rcx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
callq 0x21a0
movq %rax, -0x50(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x517f
movq -0x60(%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 (%rax,%rax)