// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x7dad
jmp 0x8048
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3090
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7f27
movl $0x0, -0x54(%rbp)
movl $0x0, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x2028, %rdx, %rdx     # imm = 0x2028
addq %rdx, %rcx
cmpq 0x18(%rcx), %rax
jge 0x7f17
movl -0x54(%rbp), %eax
movq -0x28(%rbp), %rcx
addl 0x2c(%rcx), %eax
cltq
movq -0x18(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x2028, %rdx, %rdx     # imm = 0x2028
addq %rdx, %rcx
cmpq 0x18(%rcx), %rax
jle 0x7e3e
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x2028, %rcx, %rcx     # imm = 0x2028
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x7e4e
movl -0x54(%rbp), %eax
movq -0x28(%rbp), %rcx
addl 0x2c(%rcx), %eax
cltq
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rax
imulq $0x2028, %rax, %rax     # imm = 0x2028
addq %rax, %rdi
movslq -0x54(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x2c(%rax), %edx
leaq -0x50(%rbp), %rcx
callq 0x6e20
movl -0x58(%rbp), %eax
subl -0x54(%rbp), %eax
cmpl -0x40(%rbp), %eax
je 0x7e9d
movl -0x40(%rbp), %esi
movl -0x58(%rbp), %edx
subl -0x54(%rbp), %edx
leaq 0x6dd0d(%rip), %rdi     # 0x75ba3
movb $0x0, %al
callq 0x6d60
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x7f03
movq -0x8(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x54(%rbp), %eax
jl 0x7ef6
movq -0x8(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x58(%rbp), %eax
jge 0x7ef6
movq -0x8(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
subl -0x54(%rbp), %esi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movslq -0x5c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rcx
leaq -0x50(%rbp), %rdi
callq 0x6730
jmp 0x7ef8
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x7ea4
jmp 0x7f05
movq -0x28(%rbp), %rax
movl 0x2c(%rax), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x7dde
jmp 0x7f19
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7dc4
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x8031
movq -0x30(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
je 0x8021
movq -0x8(%rbp), %rax
movslq -0x60(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x7f8e
movq -0x30(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rsi
callq 0x3520
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x3350
jmp 0x7fee
movq -0x28(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x7fec
movq -0x30(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rsi
callq 0x3520
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7fde
movq 0x10(%rbp), %rsi
leaq 0x6d3b2(%rip), %rdi     # 0x75380
callq 0x3520
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x7fbb
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x3350
jmp 0x7fee
movq -0x30(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x3370
movq -0x30(%rbp), %rdi
movslq -0x60(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3090
jmp 0x8023
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x7f2e
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq 0x28(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x3090
addq $0x70, %rsp
popq %rbp
retq
nop