// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/chunk.c
// Function: tbk_query_n
void tbk_query_n(tbk_t *tbk, int64_t chunk_beg, int n, tbk_data_t *data) {
  if (chunk_beg >= tbk->nmax) {wzfatal("Error: query %d out of range. Wrong idx file?", chunk_beg);}
  if (chunk_beg + n >= tbk->nmax) {
    n = tbk->nmax - chunk_beg;
  }
  if (n <= 0) return;
  
  data->n = n;
  data->dtype = tbk->dtype;

  switch(DATA_TYPE(tbk->dtype)) {
  /* case DT_INT1: { */
  /*   tbk->offset = offset/8;                           /\* always seek *\/ */
  /*   if(fseek(tbk->fh, offset/8+HDR_TOTALBYTES, SEEK_SET)) wzfatal("File %s cannot be seeked.\n", tbk->fname); */
    
  /*   int nb = (offset + n) / 8 - offset / 8 + 1; */
  /*   uint8_t *tmp = calloc(nb, 1); */
  /*   fread(tmp, 1, nb, tbk->fh); tbk->offset += n; */
  /*   data->data = realloc(data->data, n); */
  /*   int i; */
  /*   for (i=0; i<n; ++i) { */
  /*     ((uint8_t*)data->data)[i] = (tmp[(offset+i)/8 - offset/8] >> (offset+i)%8) & 0x1; */
  /*   } */
  /*   break; */
  /* } */
  /* case DT_INT2: { */
  /*   tbk->offset = offset/4;                           /\* always seek *\/ */
  /*   if(fseek(tbk->fh, offset/4+HDR_TOTALBYTES, SEEK_SET)) wzfatal("File %s cannot be seeked.\n", tbk->fname); */
    
  /*   int nb = (offset + n) / 4 - offset / 4; */
  /*   uint8_t *tmp = calloc(nb, 1); */
  /*   fread(tmp, 1, nb, tbk->fh); tbk->offset += n; */
  /*   data->data = realloc(data->data, n); */
  /*   int i; */
  /*   for (i=0; i<n; ++i) { */
  /*     ((uint8_t*)data->data)[i] = (tmp[(offset+i)/4 - offset/4] >> (((offset+i)%4)*2)) & 0x3; */
  /*   } */
  /*   break; */
  /* } */
  case DT_INT32: {
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, 4*n);
    tbf_read(tbk->tbf, data->data, 4, n);
    break;
  }
  case DT_FLOAT: {
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, 4*n);
    tbf_read(tbk->tbf, data->data, 4, n);
    break;
  }
  case DT_DOUBLE: {
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, 8*n);
    tbf_read(tbk->tbf, data->data, 8, n);
    break;
  }
  case DT_STRINGF: {
    int smax = STRING_MAX(tbk->dtype);
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, n*smax);
    tbf_read(tbk->tbf, data->data, 1, n*smax);
    break;
  }
  case DT_STRINGD: {
    tbk_seek_n(tbk, chunk_beg);

    data->data = realloc(data->data, sizeof(char*)*n);
    uint64_t *string_offsets = malloc(sizeof(uint64_t)*n);
    tbf_read(tbk->tbf, string_offsets, 8, n);

    int i;
    for (i=0; i<n; ++i) {
      tbk_seek_offset(tbk, string_offsets[i]+tbk->nmax*8);
      kstring_t ks = {0}; char c;
      while (1) {
        tbf_read(tbk->tbf, &c, 1, 1);
        if (c) kputc(c, &ks);
        else break;
      }
      ((char**) data->data)[i] = ks.s;
    }
    free(string_offsets);
    break;
  }
  case DT_ONES: {
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, 2*n);
    uint16_t *tmp = calloc(n, 2);
    tbf_read(tbk->tbf, tmp, 2, n);
    int ii;
    for (ii=0; ii<n; ++ii) ((float*)data->data)[ii] = uint16_to_float(tmp[ii]);
    free(tmp);
    break;
  }
  case DT_FLOAT_INT: {
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, 8*n);
    tbf_read(tbk->tbf, data->data, 8, n);
    break;
  }
  case DT_FLOAT_FLOAT: {
    tbk_seek_n(tbk, chunk_beg);
    data->data = realloc(data->data, 8*n);
    tbf_read(tbk->tbf, data->data, 8, n);
    break;
  }
  default: wzfatal("Unrecognized data type: %d.\n", DATA_TYPE(tbk->dtype));
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x6e57
movq -0x10(%rbp), %rsi
leaq 0x6e534(%rip), %rdi     # 0x75384
movb $0x0, %al
callq 0x6d60
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x6e7b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
subq -0x10(%rbp), %rax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jg 0x6e86
jmp 0x7290
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x2018(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movzbl 0x2018(%rax), %eax
addq $-0x3, %rax
movq %rax, -0x70(%rbp)
subq $0x1d, %rax
ja 0x7270
movq -0x70(%rbp), %rax
leaq 0x6ec4e(%rip), %rcx     # 0x75b18
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
shll $0x2, %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x14(%rbp), %rcx
movl $0x4, %edx
callq 0x7360
jmp 0x7290
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
shll $0x2, %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x14(%rbp), %rcx
movl $0x4, %edx
callq 0x7360
jmp 0x7290
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x14(%rbp), %rcx
movl $0x8, %edx
callq 0x7360
jmp 0x7290
movq -0x8(%rbp), %rax
movq 0x2018(%rax), %rax
shrq $0x8, %rax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
imull -0x24(%rbp), %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x14(%rbp), %eax
imull -0x24(%rbp), %eax
movslq %eax, %rcx
movl $0x1, %edx
callq 0x7360
jmp 0x7290
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x14(%rbp), %rsi
shlq $0x3, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x14(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3250
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rsi
movslq -0x14(%rbp), %rcx
movl $0x8, %edx
callq 0x7360
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x7123
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x73b0
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3090
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x51(%rbp), %rsi
movl $0x1, %ecx
movq %rcx, %rdx
callq 0x7360
cmpb $0x0, -0x51(%rbp)
je 0x70fd
movsbl -0x51(%rbp), %edi
leaq -0x50(%rbp), %rsi
callq 0x6bd0
jmp 0x70ff
jmp 0x7101
jmp 0x70cf
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x708f
movq -0x30(%rbp), %rdi
callq 0x3370
jmp 0x7290
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
shll %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x14(%rbp), %rdi
movl $0x2, %esi
callq 0x36b0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x60(%rbp), %rsi
movslq -0x14(%rbp), %rcx
movl $0x2, %edx
callq 0x7360
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x71c6
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzwl (%rax,%rcx,2), %edi
callq 0x7440
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x64(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x7191
movq -0x60(%rbp), %rdi
callq 0x3370
jmp 0x7290
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x14(%rbp), %rcx
movl $0x8, %edx
callq 0x7360
jmp 0x7290
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x72a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0x37c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x14(%rbp), %rcx
movl $0x8, %edx
callq 0x7360
jmp 0x7290
movq -0x8(%rbp), %rax
movq 0x2018(%rax), %rsi
andq $0xff, %rsi
leaq 0x6e137(%rip), %rdi     # 0x753c0
movb $0x0, %al
callq 0x6d60
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)