// File: /workspace/github_c_makefile_star2_O2/zhou-lab[P]tbmate/chunk.c
// Function: query_one_chunk
static void query_one_chunk(int *offsets, int n_offsets, tbk_t *tbks, int n_tbks, view_conf_t *conf, kstring_t *ks_out, FILE*out_fh) {

  if (n_offsets == 0) return;
  
  int k;
  tbk_data_t data = {0};
  for(k=0; k<n_tbks; ++k) {     /* iterate through samples */
    int chunk_beg = 0;
    for (chunk_beg = 0; chunk_beg < tbks[k].nmax; chunk_beg += conf->n_chunk_data) { /* iterate data chunk */
      int chunk_end = (chunk_beg + conf->n_chunk_data > tbks[k].nmax) ? tbks[k].nmax : (chunk_beg + conf->n_chunk_data);
      tbk_query_n(&tbks[k], chunk_beg, conf->n_chunk_data, &data);
      if (chunk_end - chunk_beg != data.n) {
        wzfatal("Unequal number of records read %d, expecting %d\n", data.n, chunk_end-chunk_beg);
      }

      /* save to output */
      int i;
      for(i=0; i<n_offsets; ++i) {
        if (offsets[i] >= chunk_beg && offsets[i] < chunk_end) {
          tbk_print1(&data, offsets[i]-chunk_beg, conf, &ks_out[i]);
        }
      }
    }
  }

  /* output and reset */
  int i;
  for (i=0; i < n_offsets; ++i) {
    if (ks_out[i].s) {
      if (offsets[i] >= 0) {
        fputs(ks_out[i].s, out_fh); fputc('\n', out_fh);
      } else if (conf->show_unaddressed) {
        fputs(ks_out[i].s, out_fh);
        for (k=0; k<n_tbks; ++k) fputs("\t-1", out_fh);
        fputc('\n', out_fh);
      }
      free(ks_out[i].s); memset(&ks_out[i], 0 , sizeof(kstring_t));
    }
  }
  memset(offsets, 0, sizeof(int) * conf->n_chunk_index);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x8(%rsp)
movq %r8, (%rsp)
movq %rdx, 0x18(%rsp)
testl %esi, %esi
je 0x6c47
movl %esi, %r13d
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rax
andq $0x0, 0x10(%rax)
xorl %edx, %edx
testl %esi, %esi
cmovlel %edx, %r13d
movaps %xmm0, (%rax)
testl %ecx, %ecx
cmovlel %edx, %ecx
movq %rcx, 0x10(%rsp)
cmpq %rcx, %rdx
je 0x6b91
movq %rdx, 0x20(%rsp)
imulq $0x2028, %rdx, %r14     # imm = 0x2028
addq 0x18(%rsp), %r14
xorl %ebp, %ebp
movq %r14, 0x28(%rsp)
movslq %ebp, %rsi
movq 0x18(%r14), %rax
cmpq %rsi, %rax
jle 0x6b7f
movq (%rsp), %rcx
movl 0x2c(%rcx), %edx
leal (%rdx,%rbp), %ecx
movslq %ecx, %r12
cmpq %r12, %rax
cmovll %eax, %r12d
movq %r14, %rdi
leaq 0x30(%rsp), %rcx
callq 0x5ff9
movl %r12d, %edx
subl %ebp, %edx
movl 0x40(%rsp), %esi
cmpl %esi, %edx
jne 0x6c56
movq 0x8(%rsp), %r15
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x6b6e
movl (%rbx,%r14,4), %eax
movl %eax, %esi
subl %ebp, %esi
jl 0x6b65
cmpl %r12d, %eax
jge 0x6b65
leaq 0x30(%rsp), %rdi
movq (%rsp), %rdx
movq %r15, %rcx
callq 0x5b5c
incq %r14
addq $0x18, %r15
jmp 0x6b40
movq (%rsp), %rax
addl 0x2c(%rax), %ebp
movq 0x28(%rsp), %r14
jmp 0x6afa
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x10(%rsp), %rcx
jmp 0x6ad9
xorl %r15d, %r15d
leaq 0x38765(%rip), %r12     # 0x3f300
cmpq %r13, %r15
je 0x6c31
imulq $0x18, %r15, %rbp
movq 0x8(%rsp), %rax
movq 0x10(%rax,%rbp), %rdi
testq %rdi, %rdi
je 0x6bf5
cmpl $0x0, (%rbx,%r15,4)
js 0x6bfa
movq 0x80(%rsp), %rsi
callq 0x3530
pushq $0xa
popq %rdi
movq 0x80(%rsp), %rsi
callq 0x3350
addq 0x8(%rsp), %rbp
movq 0x10(%rbp), %rdi
callq 0x3370
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
incq %r15
jmp 0x6b9b
movq (%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0x6bdb
movq 0x80(%rsp), %rsi
callq 0x3530
movq 0x10(%rsp), %rax
movl %eax, %r14d
subl $0x1, %r14d
jb 0x6bcb
movq %r12, %rdi
movq 0x80(%rsp), %rsi
callq 0x3530
jmp 0x6c19
movq (%rsp), %rax
movslq 0x28(%rax), %rdx
shlq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3090
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38dd6(%rip), %rdi     # 0x3fa33
xorl %eax, %eax
callq 0x5f58