// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/view.c
// Function: query_regions
static int query_regions(
  char *fname, char **regs, int nregs,
  tbk_t *tbks, int n_tbks, view_conf_t *conf, FILE *out_fh) {
  
  int i;
  htsFile *fp = hts_open(fname,"r");
  if(!fp) error("Could not read %s\n", fname);

  tbx_t *tbx = tbx_index_load(fname);
  if(!tbx) error("Could not load .tbi/.csi index of %s\n", fname);
  kstring_t str = {0,0,0};
  const char **seq = NULL;
  
  char **fields = NULL;
  int nfields = -1;
  char *aux = NULL; char *aux2 = NULL;
  
  int offset, ii, k;
  int linenum=0;
  for(i=0; i<nregs; i++) {
    hts_itr_t *itr = tbx_itr_querys(tbx, regs[i]);
    if(!itr) continue;
    while (tbx_itr_next(fp, tbx, itr, &str) >= 0) {

      line_get_fields2(str.s, "\t", &fields, &nfields, &aux);
      
      if (nfields < 3)
        wzfatal("[%s:%d] Bed file has fewer than 3 columns.\n", __func__, __LINE__);

      if (!linenum && conf->column_name) {
        tbk_print_columnnames(tbks, n_tbks, nfields, out_fh, conf);
      }
      linenum++;
      
      ensure_number2(fields[3]);
      offset = atoi(fields[3]);

      if (offset >= 0 || conf->show_unaddressed) {
        fputs(fields[0], out_fh);
        fputc('\t', out_fh);
        fputs(fields[1], out_fh);
        fputc('\t', out_fh);
        fputs(fields[2], out_fh);
        if (conf->print_all) {
          for(ii=3; ii<nfields; ++ii)
            fprintf(out_fh, "\t%s", fields[ii]);
        }

        for(k=0; k<n_tbks; ++k) tbk_query(&tbks[k], offset, conf, out_fh, &aux2);
        fputc('\n', out_fh);
      }
    }
    tbx_itr_destroy(itr);
  }

  free(aux); free(aux2);
  free_fields(fields, nfields);
  free(seq);
  free(str.s);
  tbx_destroy(tbx);

  if(hts_close(fp)) error("hts_close returned non-zero status: %s\n", fname);

  for(i=0; i<nregs; i++) free(regs[i]);
  free(regs);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x73b22(%rip), %rsi     # 0x79423
callq 0xeba0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5923
movq -0x8(%rbp), %rsi
leaq 0x70042(%rip), %rdi     # 0x7595e
movb $0x0, %al
callq 0x62a0
movq -0x8(%rbp), %rdi
callq 0x19090
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5949
movq -0x8(%rbp), %rsi
leaq 0x7002f(%rip), %rdi     # 0x75971
movb $0x0, %al
callq 0x62a0
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3090
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x5be3
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x48(%rbp), %rcx
leaq 0x12791(%rip), %rdx     # 0x18150
leaq 0xdbda(%rip), %r8       # 0x135a0
leaq 0x12cd3(%rip), %r9      # 0x186a0
callq 0x14420
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x59e8
jmp 0x5bd5
jmp 0x59ea
movq -0x40(%rbp), %rdi
callq 0xfd40
movq %rax, %rdi
movq -0xa0(%rbp), %rsi
movq -0x48(%rbp), %rcx
leaq -0x60(%rbp), %rdx
callq 0x14580
cmpl $0x0, %eax
jl 0x5bc9
movq -0x50(%rbp), %rdi
leaq 0x74485(%rip), %rsi     # 0x79ea3
leaq -0x70(%rbp), %rdx
leaq -0x74(%rbp), %rcx
leaq -0x80(%rbp), %r8
callq 0x6350
cmpl $0x3, -0x74(%rbp)
jge 0x5a4f
leaq 0x6ff5b(%rip), %rdi     # 0x75997
leaq 0x6ff80(%rip), %rsi     # 0x759c3
movl $0x10f, %edx            # imm = 0x10F
movb $0x0, %al
callq 0x4270
cmpl $0x0, -0x98(%rbp)
jne 0x5a79
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x5a79
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x74(%rbp), %edx
movq 0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x6500
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x6660
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3550
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
jge 0x5abf
movq -0x30(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x5bc4
movq -0x70(%rbp), %rax
movq (%rax), %rdi
movq 0x10(%rbp), %rsi
callq 0x3520
movq 0x10(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rbp), %rsi
callq 0x3520
movq 0x10(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x10(%rbp), %rsi
callq 0x3520
movq -0x30(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x5b60
movl $0x3, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x5b5e
movq 0x10(%rbp), %rdi
movq -0x70(%rbp), %rax
movslq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x6fe8b(%rip), %rsi     # 0x759d1
movb $0x0, %al
callq 0x37f0
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x5b21
jmp 0x5b60
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x5bb6
movq -0x20(%rbp), %rdi
movslq -0x94(%rbp), %rax
imulq $0x2028, %rax, %rax     # imm = 0x2028
addq %rax, %rdi
movslq -0x8c(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x10(%rbp), %rcx
leaq -0x88(%rbp), %r8
callq 0x3c70
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x5b6a
movq 0x10(%rbp), %rsi
movl $0xa, %edi
callq 0x3350
jmp 0x59ea
movq -0xa0(%rbp), %rdi
callq 0x13f20
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5994
movq -0x80(%rbp), %rdi
callq 0x3370
movq -0x88(%rbp), %rdi
callq 0x3370
movq -0x70(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x6170
movq -0x68(%rbp), %rdi
callq 0x3370
movq -0x50(%rbp), %rdi
callq 0x3370
movq -0x48(%rbp), %rdi
callq 0x18d60
movq -0x40(%rbp), %rdi
callq 0xf950
cmpl $0x0, %eax
je 0x5c3f
movq -0x8(%rbp), %rsi
leaq 0x6fd9d(%rip), %rdi     # 0x759d5
movb $0x0, %al
callq 0x62a0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x5c6a
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3370
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5c46
movq -0x10(%rbp), %rdi
callq 0x3370
xorl %eax, %eax
addq $0xa0, %rsp
popq %rbp
retq
nop