// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
testl %esi, %esi
je 0x94b9
movl %esi, %r14d
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movl %esi, %r12d
movl %ecx, 0x4(%rsp)
testl %ecx, %ecx
jle 0x93e8
movl 0x4(%rsp), %eax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movl %r14d, 0x24(%rsp)
movq %rax, 0x38(%rsp)
imulq $0x2028, %rax, %r15     # imm = 0x2028
movq 0x28(%rsp), %rax
movq 0x18(%rax,%r15), %rax
testq %rax, %rax
jle 0x93d5
addq 0x28(%rsp), %r15
movq 0x8(%rsp), %rcx
movl 0x2c(%rcx), %edx
xorl %esi, %esi
xorl %r13d, %r13d
movq %r15, 0x10(%rsp)
leal (%rdx,%r13), %ecx
movslq %ecx, %rbp
cmpq %rbp, %rax
cmovll %eax, %ebp
movq %r15, %rdi
leaq 0x40(%rsp), %rcx
callq 0x82ee
movl %ebp, %edx
subl %r13d, %edx
movl 0x50(%rsp), %esi
cmpl %esi, %edx
jne 0x94c8
testl %r14d, %r14d
jle 0x93b0
movq 0x18(%rsp), %r15
xorl %r14d, %r14d
movl (%rbx,%r14,4), %eax
movl %eax, %esi
subl %r13d, %esi
jl 0x93a4
cmpl %ebp, %eax
jge 0x93a4
leaq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rdx
movq %r15, %rcx
callq 0x7a7c
incq %r14
addq $0x18, %r15
cmpq %r14, %r12
jne 0x9383
movq 0x8(%rsp), %rax
movl 0x2c(%rax), %edx
addl %edx, %r13d
movslq %r13d, %rsi
movq 0x10(%rsp), %r15
movq 0x18(%r15), %rax
cmpq %rsi, %rax
movl 0x24(%rsp), %r14d
jg 0x934b
movq 0x38(%rsp), %rax
incq %rax
cmpq 0x30(%rsp), %rax
jne 0x9315
testl %r14d, %r14d
jle 0x94a2
movq 0x90(%rsp), %r13
xorl %ebp, %ebp
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movq 0x18(%rsp), %rax
movq 0x10(%rax,%rcx,8), %rdi
testq %rdi, %rdi
je 0x945b
cmpl $0x0, (%rbx,%rbp,4)
js 0x9465
movq %rcx, 0x10(%rsp)
movq %r13, %rsi
callq 0x3520
movl $0xa, %edi
movq %r13, %rsi
callq 0x3350
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
leaq (%rax,%rcx,8), %r14
movq 0x10(%r14), %rdi
callq 0x3370
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
incq %rbp
cmpq %r12, %rbp
jne 0x93fb
jmp 0x94a2
movq 0x8(%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0x943a
movq %rcx, 0x10(%rsp)
movq %r13, %rsi
callq 0x3520
cmpl $0x0, 0x4(%rsp)
leaq 0x43e77(%rip), %r15     # 0x4d300
jle 0x9428
movl 0x4(%rsp), %r14d
movq %r15, %rdi
movq %r13, %rsi
callq 0x3520
decl %r14d
jne 0x9490
jmp 0x9428
movq 0x8(%rsp), %rax
movslq 0x28(%rax), %rdx
shlq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3090
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x44564(%rip), %rdi     # 0x4da33
xorl %eax, %eax
callq 0x824b
nop