// File: /workspace/github_c_makefile_star2_O3/zhou-lab[P]tbmate/header.c
// Function: main_header
int main_header(int argc, char *argv[]) {

  int c;
  if (argc<1) return usage();

  char *msg = NULL;
  while ((c = getopt(argc, argv, "m:h"))>=0) {
    switch (c) {
    case 'm': msg = optarg; break;
    case 'h': return usage(); break;
    default: usage(); wzfatal("Unrecognized option: %c.\n", c);
    }
  }

  if (optind > argc) { 
    usage(); 
    wzfatal("Please supply tbk file.\n"); 
  }

  tbf_t *tbf = NULL; tbk_t tbk = {0}; int i=0; int j=0;
  for (;optind < argc; optind++, i++) {
    /* set message  */
    if(msg) {
      
      tbf = tbf_open_update(argv[optind]);
      fseek(tbf->fh, HDR_ID+HDR_VERSION+HDR_DATA_TYPE+HDR_NMAX, SEEK_SET);
      /* truncate if too long */
      if (strlen(msg) >= HDR_EXTRA-1) {
        fprintf(stderr, "[Warning] Message too long, truncated to %d:\n%s", HDR_EXTRA-1, msg);
        msg[HDR_EXTRA-1] = '\0';
      }
      fwrite(msg, strlen(msg)+1, 1, tbf->fh);
      tbf_close(tbf);

    } else {

      tbf = tbf_open(argv[optind]);
      fprintf(stdout, "\nTBK File: %s\n", tbf->fname);
      fprintf(stderr, "Number of samples: %d\n", tbf_num_samples(argv[optind]));

      j = 1;
      while (1) {
        tbf_next(tbf, &tbk);
        fprintf(stdout, "  Sample %d: %s\n", j++, tbk.sname);
        fprintf(stdout, "  TBK Version: %d\n", tbk.version);
        fputs("  Data type: ", stdout);
        switch(DATA_TYPE(tbk.dtype)) {
        case DT_INT1:        fputs("INT1\n", stdout);        break;
        case DT_INT2:        fputs("INT2\n", stdout);        break;
        case DT_INT32:       fputs("INT32\n", stdout);       break;
        case DT_FLOAT:       fputs("FLOAT\n", stdout);       break;
        case DT_DOUBLE:      fputs("DOUBLE\n", stdout);      break;
        case DT_STRINGF:     fprintf(stdout, "STRINGF (n=%"PRIu64")\n", STRING_MAX(tbk.dtype)); break;
        case DT_STRINGD:     fputs("STRINGD\n", stdout);     break;
        case DT_ONES:        fputs("ONES\n", stdout);        break;
        case DT_FLOAT_INT:   fputs("FLOAT.INT\n", stdout);   break;
        case DT_FLOAT_FLOAT: fputs("FLOAT.FLOAT\n", stdout); break;
        default: wzfatal("  Data type %"PRIu64" unrecognized.\n", tbk.dtype);
        }
        fprintf(stdout, "  Number of data: %"PRId64"\n", tbk.nmax);
        fputs("  Message: ", stdout);
        if (tbk.extra[0]) fputs(tbk.extra, stdout);
        fputs("\n\n", stdout);
        if (tbk.version < 100) break;
        tbf_skip_data(&tbk);
      }

      tbf_close(tbf);
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4078, %rsp           # imm = 0x4078
testl %edi, %edi
jle 0xad72
movq %rsi, %r13
movl %edi, %ebp
leaq 0x43567(%rip), %rdx     # 0x4ddfc
callq 0x3200
testl %eax, %eax
js 0xa8cf
movl %eax, %ebx
movq 0x54739(%rip), %r14     # 0x5efe0
leaq 0x4354e(%rip), %r15     # 0x4ddfc
cmpl $0x6d, %ebx
jne 0xad6d
movq (%r14), %r12
movl %ebp, %edi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3200
movl %eax, %ebx
testl %eax, %eax
jns 0xa8ae
jmp 0xa8d2
xorl %r12d, %r12d
movq %r13, 0x10(%rsp)
movq %r12, 0x20(%rsp)
movq 0x546dd(%rip), %rax     # 0x5efc0
movl (%rax), %ebx
cmpl %ebp, %ebx
jg 0xadc2
leaq 0x28(%rsp), %rdi
movl $0x2028, %edx           # imm = 0x2028
xorl %esi, %esi
callq 0x3090
cmpl %ebp, %ebx
jge 0xad59
leaq 0x42ef5(%rip), %r12     # 0x4d802
xorl %r14d, %r14d
leaq 0x426f9(%rip), %r13     # 0x4d010
movl %ebp, 0xc(%rsp)
movslq %ebx, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %r15
cmpq $0x0, 0x20(%rsp)
je 0xa9ce
movq %r15, %rdi
callq 0x35f0
movq %rax, %rbx
movq %r15, %rdi
leaq 0x4363c(%rip), %rsi     # 0x4df84
callq 0x3250
testq %rax, %rax
je 0xad93
movq %rax, %r15
movl $0x17, %esi
movq %rax, %rdi
xorl %edx, %edx
callq 0x3120
movq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x3380
cmpq $0x1fe8, %rax           # imm = 0x1FE8
jae 0xad2b
movq %r12, %rdi
callq 0x3380
leaq 0x1(%rax), %rsi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x3770
movq %r15, %rdi
callq 0x36c0
leaq 0x42e56(%rip), %r12     # 0x4d802
movq %rbx, %rdi
callq 0x3370
movq 0x54605(%rip), %rax     # 0x5efc0
movl (%rax), %ebx
incl %ebx
movl %ebx, (%rax)
cmpl %ebp, %ebx
jl 0xa91b
jmp 0xad59
movl $0x1, %edi
movl $0x20, %esi
callq 0x36a0
movq %rax, %rbp
movq %r15, %rdi
callq 0x35f0
movq %rax, %rbx
movq %rax, 0x10(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3250
movq %rax, (%rbp)
testq %rax, %rax
je 0xad9c
movq 0x545ea(%rip), %rax     # 0x5eff8
movq (%rax), %rdi
movq %rbp, 0x18(%rsp)
movq 0x10(%rbp), %rdx
leaq 0x4340f(%rip), %rsi     # 0x4de30
xorl %eax, %eax
callq 0x37e0
movq 0x545b9(%rip), %rax     # 0x5efe8
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x54583(%rip), %rax     # 0x5efc0
movslq (%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rbp
movl $0x1, %edi
movl $0x20, %esi
callq 0x36a0
movq %rax, %r15
movq %rbp, %rdi
callq 0x35f0
movq %rax, %r12
movq %rax, 0x10(%r15)
movq %rbp, %rdi
leaq 0x42d8e(%rip), %rsi     # 0x4d802
callq 0x3250
movq %rax, (%r15)
testq %rax, %rax
je 0xada8
xorl %ebp, %ebp
movl $0x2028, %edx           # imm = 0x2028
leaq 0x2050(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3090
movq %r15, %rdi
movq %rbx, %rsi
callq 0xae78
movq 0x2058(%rsp), %rbx
movq 0x4068(%rsp), %rax
movzbl %al, %ecx
movl %ecx, %edx
shrq $0x8, %rax
cmpq $0x7, %rcx
cmovnel %r14d, %eax
addl (%r13,%rdx,4), %eax
movq (%rbx), %rdi
movslq %eax, %r12
imulq 0x2068(%rsp), %r12
movq %r12, %rsi
movl $0x1, %edx
callq 0x3120
addq %r12, 0x8(%rbx)
leaq 0x2050(%rsp), %rbx
incl %ebp
cmpl $0x63, 0x2060(%rsp)
jg 0xaa9e
movq (%r15), %rdi
callq 0x36c0
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0xab19
callq 0x3370
movq 0x10(%r15), %rdi
callq 0x3370
movq (%rsp), %rdi
leaq 0x43312(%rip), %rsi     # 0x4de3f
movl %ebp, %edx
xorl %eax, %eax
callq 0x37e0
movl $0x1, %r15d
movq 0x544b5(%rip), %r12     # 0x5eff8
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xae78
movq (%r12), %rdi
movq 0x28(%rsp), %rcx
leaq 0x432f4(%rip), %rsi     # 0x4de56
movl %r15d, %edx
xorl %eax, %eax
callq 0x37e0
movq (%r12), %rdi
movl 0x38(%rsp), %ebp
leaq 0x432ec(%rip), %rsi     # 0x4de67
movl %ebp, %edx
xorl %eax, %eax
callq 0x37e0
movq (%r12), %rsi
leaq 0x432eb(%rip), %rdi     # 0x4de7a
callq 0x3520
movq 0x2040(%rsp), %rbx
movzbl %bl, %eax
cmpl $0x1d, %eax
movl %r15d, (%rsp)
jg 0xabd0
decl %eax
cmpl $0x6, %eax
ja 0xadb9
leaq 0x43226(%rip), %rcx     # 0x4dde0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %rsi
leaq 0x432ba(%rip), %rdi     # 0x4de88
jmp 0xac49
cmpl $0x1e, %eax
je 0xac3e
cmpl $0x1f, %eax
je 0xac17
cmpl $0x20, %eax
jne 0xadb9
movq (%r12), %rsi
leaq 0x432e0(%rip), %rdi     # 0x4dece
jmp 0xac49
movq (%r12), %rsi
leaq 0x432a0(%rip), %rdi     # 0x4de9b
jmp 0xac49
movq (%r12), %rsi
leaq 0x4328c(%rip), %rdi     # 0x4de94
jmp 0xac49
movq (%r12), %rsi
leaq 0x432bf(%rip), %rdi     # 0x4ded4
jmp 0xac49
movq (%r12), %rsi
leaq 0x432a1(%rip), %rdi     # 0x4dec3
jmp 0xac49
movq (%r12), %rsi
leaq 0x4325f(%rip), %rdi     # 0x4de8e
jmp 0xac49
movq (%r12), %rsi
leaq 0x43278(%rip), %rdi     # 0x4deb4
jmp 0xac49
movq (%r12), %rsi
leaq 0x43274(%rip), %rdi     # 0x4debd
callq 0x3520
movq (%r12), %rdi
movq 0x40(%rsp), %r15
leaq 0x4329c(%rip), %rsi     # 0x4defa
movq %r15, %rdx
xorl %eax, %eax
callq 0x37e0
movq (%r12), %rsi
leaq 0x4329e(%rip), %rdi     # 0x4df11
callq 0x3520
cmpb $0x0, 0x50(%rsp)
je 0xac8d
movq (%r12), %rsi
leaq 0x50(%rsp), %rdi
callq 0x3520
movq (%r12), %rsi
leaq 0x424c4(%rip), %rdi     # 0x4d15c
callq 0x3520
cmpl $0x64, %ebp
jl 0xad03
movq 0x30(%rsp), %rbp
movq (%rbp), %rdi
movzbl %bl, %eax
movl %eax, %ecx
shrq $0x8, %rbx
cmpq $0x7, %rax
cmovnel %r14d, %ebx
addl (%r13,%rcx,4), %ebx
movslq %ebx, %rax
imulq %rax, %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x3120
addq %r15, 0x8(%rbp)
movl (%rsp), %r15d
incl %r15d
jmp 0xab3c
movq (%r12), %rdi
movq %rbx, %rdx
shrq $0x8, %rdx
leaq 0x431ac(%rip), %rsi     # 0x4dea3
xorl %eax, %eax
callq 0x37e0
jmp 0xac4e
movq 0x18(%rsp), %rbx
movq (%rbx), %rdi
callq 0x36c0
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xad1e
callq 0x3370
movq 0x10(%rbx), %rbx
movl 0xc(%rsp), %ebp
jmp 0xa9a5
movq 0x542b6(%rip), %rax     # 0x5efe8
movq (%rax), %rdi
leaq 0x430c4(%rip), %rsi     # 0x4de00
movl $0x1fe8, %edx           # imm = 0x1FE8
movq %r12, %rcx
xorl %eax, %eax
callq 0x37e0
movb $0x0, 0x1fe8(%r12)
jmp 0xa981
xorl %eax, %eax
addq $0x4078, %rsp           # imm = 0x4078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x68, %ebx
jne 0xad7e
callq 0x3ee6
movl $0x1, %eax
jmp 0xad5b
callq 0x3ee6
leaq 0x425f5(%rip), %rdi     # 0x4d37f
movl %ebx, %esi
xorl %eax, %eax
callq 0xadd5
leaq 0x431ee(%rip), %rdi     # 0x4df88
jmp 0xada3
leaq 0x42a62(%rip), %rdi     # 0x4d805
movq %rbx, %rsi
jmp 0xadb2
leaq 0x42a56(%rip), %rdi     # 0x4d805
movq %r12, %rsi
xorl %eax, %eax
callq 0xadd5
leaq 0x4311b(%rip), %rdi     # 0x4dedb
jmp 0xada3
callq 0x3ee6
leaq 0x425cb(%rip), %rdi     # 0x4d399
xorl %eax, %eax
callq 0xadd5