// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/view.c
// Function: tbk_query
void tbk_query(tbk_t *tbk, int64_t offset, view_conf_t *conf, FILE *out_fh, char **aux) {

  /* when the offset is unfound */
  if (offset < 0) { fputs("\t-1", out_fh); return; }
  if (offset >= tbk->nmax) {wzfatal("Error: query %d out of range. Wrong idx file?", offset);}

  switch(DATA_TYPE(tbk->dtype)) {
  /* case DT_INT1: { */
  /*   if(tbk->offset == 0 || offset/8 != tbk->offset-1) { /\* need to read? *\/ */
  /*     if(offset/8 != tbk->offset) {                     /\* need to seek? *\/ */
  /*       tbk->offset = offset/8; */
  /*       if(fseek(tbk->fh, offset/8+HDR_TOTALBYTES, SEEK_SET)) */
  /*         wzfatal("File %s cannot be seeked.\n", tbk->fname); */
  /*     } */
  /*     fread(&(tbk->data), 1, 1, tbk->fh); tbk->offset++; */
  /*   } */
  /*   fprintf(out_fh, "\t%d", ((tbk->data)>>(offset%8)) & 0x1); */
  /*   break; */
  /* } */
  /* case DT_INT2: { */
  /*   if(tbk->offset == 0 || offset/4 != tbk->offset-1) { /\* need to read? *\/ */
  /*     if(offset/4 != tbk->offset) {                       /\* need to seek? *\/ */
  /*       tbk->offset = offset/4; */
  /*       if(fseek(tbk->fh, offset/4+HDR_TOTALBYTES, SEEK_SET)) */
  /*         wzfatal("File %s cannot be seeked.\n", tbk->fname); */
  /*     } */
  /*     fread(&(tbk->data), 1, 1, tbk->fh); tbk->offset++; */
  /*   } */
  /*   fprintf(out_fh, "\t%d", ((tbk->data)>>((offset%4)*2)) & 0x3); */
  /*   break; */
  /* } */
  case DT_INT32: {
    tbk_seek_n(tbk, offset);
    int data;
    tbf_read(tbk->tbf, &data, 4, 1);
    if (conf->na_for_negative && data < 0) {
      fputc('\t', out_fh); fputs(conf->na_token, out_fh);
    } else fprintf(out_fh, "\t%d", data);
    break;
  }
  case DT_FLOAT: {
    tbk_seek_n(tbk, offset);    
    float data;
    tbf_read(tbk->tbf, &data, 4, 1);
    if (conf->na_for_negative && data < 0) {
      fputc('\t', out_fh); fputs(conf->na_token, out_fh);
    } else fprintf(out_fh, "\t%f", data);
    break;
  }
  case DT_DOUBLE: {
    tbk_seek_n(tbk, offset);
    double data;
    tbf_read(tbk->tbf, &data, 8, 1);
    if (conf->na_for_negative && data < 0) {
      fputc('\t', out_fh); fputs(conf->na_token, out_fh);
    } else fprintf(out_fh, "\t%f", data);
    break;
  }
  case DT_STRINGF: {
    tbk_seek_n(tbk, offset);
    
    uint64_t n = STRING_MAX(tbk->dtype);
    if (!*aux) *aux = malloc(n+1);
    tbf_read(tbk->tbf, *aux, 1, n);
    if ((*aux)[n-1] != '\0') (*aux)[n] = '\0';
    fputc('\t', out_fh);
    fputs(*aux, out_fh);
    break;
  }
  case DT_STRINGD: {
    tbk_seek_n(tbk, offset);

    int64_t string_offset;
    tbf_read(tbk->tbf, &string_offset, 8, 1);
    tbk_seek_offset(tbk, string_offset + 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;
    }
    if (ks.s) { fputc('\t', out_fh); fputs(ks.s, out_fh); }
    free(ks.s);
    break;
  }
  case DT_ONES: {
    tbk_seek_n(tbk, offset);
    
    uint16_t data;
    tbf_read(tbk->tbf, &data, 2, 1);
    float dataf = uint16_to_float(data);
    if (conf->na_for_negative && dataf < 0) {
      fputc('\t', out_fh); fputs(conf->na_token, out_fh);
    } else fprintf(out_fh, "\t%.*f", conf->precision, dataf);
    /* fprintf(out_fh, "\t%d", data); */
    break;
  }
  case DT_FLOAT_INT: {
    tbk_seek_n(tbk, offset);
    
    float data; int data2;
    tbf_read(tbk->tbf, &data, 4, 1);
    tbf_read(tbk->tbf, &data2, 4, 1);

    if (conf->na_for_negative && data < 0) {
      fputc('\t', out_fh); fputs(conf->na_token, out_fh);
    } else {
      if (conf->min_coverage >= 0 && data2 < conf->min_coverage) {
        fputc('\t', out_fh); fputs(conf->na_token, out_fh);
      } else {
        fprintf(out_fh, "\t%f", data);
      }
    }
    if (conf->print_all_units) fprintf(out_fh, "\t%d", data2);
    break;
  }
  case DT_FLOAT_FLOAT: {
    tbk_seek_n(tbk, offset);
    
    float data,  data2;
    tbf_read(tbk->tbf, &data, 4, 1);
    tbf_read(tbk->tbf, &data2, 4, 1);
    
    if (conf->na_for_negative && data < 0) {
      fputc('\t', out_fh); fputs(conf->na_token, out_fh);
    } else {
      if (conf->max_pval >= 0 && data2 > conf->max_pval) {
        fputc('\t', out_fh); fputs(conf->na_token, out_fh);
      } else {
        fprintf(out_fh, "\t%f", data);
      }
    }
    if (conf->print_all_units) fprintf(out_fh, "\t%f", data2);
    break;
  }
  default: wzfatal("Unrecognized data type: %d.\n", DATA_TYPE(tbk->dtype));
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
jge 0x3cab
movq -0x20(%rbp), %rsi
leaq 0x716df(%rip), %rdi     # 0x75380
callq 0x3520
jmp 0x425d
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x3ccb
movq -0x10(%rbp), %rsi
leaq 0x716c0(%rip), %rdi     # 0x75384
movb $0x0, %al
callq 0x4270
movq -0x8(%rbp), %rax
movzbl 0x2018(%rax), %eax
addq $-0x3, %rax
movq %rax, -0x80(%rbp)
subq $0x1d, %rax
ja 0x423d
movq -0x80(%rbp), %rax
leaq 0x7154d(%rip), %rcx     # 0x75240
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x3d55
cmpl $0x0, -0x2c(%rbp)
jge 0x3d55
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x3d6a
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0x7164f(%rip), %rsi     # 0x753b2
movb $0x0, %al
callq 0x37f0
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x30(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x3dcb
xorps %xmm0, %xmm0
ucomiss -0x30(%rbp), %xmm0
jbe 0x3dcb
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x3de6
movq -0x20(%rbp), %rdi
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x715d7(%rip), %rsi     # 0x753b6
movb $0x1, %al
callq 0x37f0
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x38(%rbp), %rsi
movl $0x8, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x3e48
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x3e48
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x3e5f
movq -0x20(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
leaq 0x7155e(%rip), %rsi     # 0x753b6
movb $0x1, %al
callq 0x37f0
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x2018(%rax), %rax
shrq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3ea5
movq -0x40(%rbp), %rdi
addq $0x1, %rdi
callq 0x3250
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movq -0x40(%rbp), %rcx
movl $0x1, %edx
callq 0x43f0
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x3ee9
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x48(%rbp), %rsi
movl $0x8, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x4440
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3090
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x61(%rbp), %rsi
movl $0x1, %ecx
movq %rcx, %rdx
callq 0x43f0
cmpb $0x0, -0x61(%rbp)
je 0x3f8e
movsbl -0x61(%rbp), %edi
leaq -0x60(%rbp), %rsi
callq 0x44d0
jmp 0x3f90
jmp 0x3f92
jmp 0x3f60
cmpq $0x0, -0x50(%rbp)
je 0x3fb4
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
movq -0x50(%rbp), %rdi
callq 0x3370
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x64(%rbp), %rsi
movl $0x2, %edx
movl $0x1, %ecx
callq 0x43f0
movzwl -0x64(%rbp), %edi
callq 0x4620
movss %xmm0, -0x68(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x402c
xorps %xmm0, %xmm0
ucomiss -0x68(%rbp), %xmm0
jbe 0x402c
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x404d
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %edx
movss -0x68(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x71374(%rip), %rsi     # 0x753ba
movb $0x1, %al
callq 0x37f0
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x6c(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x70(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x40c9
xorps %xmm0, %xmm0
ucomiss -0x6c(%rbp), %xmm0
jbe 0x40c9
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x411d
movq -0x18(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jl 0x4100
movl -0x70(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jge 0x4100
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x411b
movq -0x20(%rbp), %rdi
movss -0x6c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x712a2(%rip), %rsi     # 0x753b6
movb $0x1, %al
callq 0x37f0
jmp 0x411d
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x413c
movq -0x20(%rbp), %rdi
movl -0x70(%rbp), %edx
leaq 0x7127d(%rip), %rsi     # 0x753b2
movb $0x0, %al
callq 0x37f0
jmp 0x425d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x74(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x78(%rbp), %rsi
movl $0x4, %edx
movl $0x1, %ecx
callq 0x43f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x41b8
xorps %xmm0, %xmm0
ucomiss -0x74(%rbp), %xmm0
jbe 0x41b8
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x4216
movq -0x18(%rbp), %rax
movss 0x30(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x41f9
movss -0x78(%rbp), %xmm0
movq -0x18(%rbp), %rax
ucomiss 0x30(%rax), %xmm0
jbe 0x41f9
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3350
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3520
jmp 0x4214
movq -0x20(%rbp), %rdi
movss -0x74(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x711a9(%rip), %rsi     # 0x753b6
movb $0x1, %al
callq 0x37f0
jmp 0x4216
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x423b
movq -0x20(%rbp), %rdi
movss -0x78(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x71182(%rip), %rsi     # 0x753b6
movb $0x1, %al
callq 0x37f0
jmp 0x425d
movq -0x8(%rbp), %rax
movq 0x2018(%rax), %rsi
andq $0xff, %rsi
leaq 0x7116a(%rip), %rdi     # 0x753c0
movb $0x0, %al
callq 0x4270
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)