// File: /workspace/github_c_makefile_star2_O1/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 $0x4088, %rsp           # imm = 0x4088
testl %edi, %edi
jle 0xac30
movq %rsi, %rbp
movl %edi, %r12d
leaq 0x436ee(%rip), %rdx     # 0x4ddfc
callq 0x3200
testl %eax, %eax
js 0xa749
movl %eax, %ebx
movq 0x538c0(%rip), %r15     # 0x5dfe0
leaq 0x436d5(%rip), %r14     # 0x4ddfc
cmpl $0x6d, %ebx
jne 0xac2b
movq (%r15), %r13
movl %r12d, %edi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x3200
movl %eax, %ebx
testl %eax, %eax
jns 0xa727
jmp 0xa74c
xorl %r13d, %r13d
movq %r13, 0x20(%rsp)
movq 0x53868(%rip), %rbx     # 0x5dfc0
cmpl %r12d, (%rbx)
jg 0xac77
leaq 0x38(%rsp), %rdi
movl $0x2028, %edx           # imm = 0x2028
xorl %esi, %esi
callq 0x3090
movl (%rbx), %eax
movl %r12d, 0x1c(%rsp)
cmpl %r12d, %eax
movq 0x20(%rsp), %r15
jge 0xac17
xorl %r12d, %r12d
leaq 0x4287f(%rip), %r13     # 0x4d010
movq %rbp, 0x8(%rsp)
cltq
movq (%rbp,%rax,8), %rbp
movl $0x1, %edi
movl $0x20, %esi
callq 0x36a0
movq %rax, %rbx
testq %r15, %r15
je 0xa882
movq $0x0, 0x8(%rbx)
movq %rbp, %rdi
callq 0x35f0
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq %rbp, %rdi
leaq 0x437ab(%rip), %rsi     # 0x4df84
callq 0x3250
movq %rax, (%rbx)
testq %rax, %rax
je 0xac5a
movq %rbx, %rbp
movl $0x17, %esi
movq %rax, %rdi
xorl %edx, %edx
callq 0x3120
movq %r15, %rdi
callq 0x3380
cmpq $0x1fe8, %rax           # imm = 0x1FE8
movq 0x537af(%rip), %r14     # 0x5dfc0
jae 0xabea
movq %rbp, %rax
addq $0x10, %rax
movq %rax, 0x30(%rsp)
movq %r15, %rdi
callq 0x3380
leaq 0x1(%rax), %rsi
movq (%rbp), %rbx
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x3770
movq %rbx, %rdi
callq 0x36c0
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbp
je 0xa85e
callq 0x3370
movq 0x30(%rsp), %rax
movq (%rax), %rdi
callq 0x3370
movl (%r14), %eax
incl %eax
movl %eax, (%r14)
cmpl 0x1c(%rsp), %eax
jl 0xa796
jmp 0xac17
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movq %rbp, %rdi
callq 0x35f0
movq %rbx, %r15
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq %rbp, %rdi
leaq 0x42f56(%rip), %rbx     # 0x4d7fe
movq %rbx, %rsi
callq 0x3250
movq %rax, (%r15)
testq %rax, %rax
je 0xac3c
movq %r15, 0x28(%rsp)
addq $0x10, %r15
movq 0x5372c(%rip), %rax     # 0x5dff8
movq (%rax), %rdi
movq %r15, 0x30(%rsp)
movq (%r15), %rdx
leaq 0x43552(%rip), %rsi     # 0x4de30
xorl %eax, %eax
callq 0x37e0
movq 0x536fc(%rip), %rax     # 0x5dfe8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x536c5(%rip), %rax     # 0x5dfc0
movslq (%rax), %rax
movq 0x8(%rsp), %rbp
movq (%rbp,%rax,8), %rbp
movl $0x1, %edi
movl $0x20, %esi
callq 0x36a0
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq %rbp, %rdi
callq 0x35f0
movq %rax, %r14
movq %rax, 0x10(%r15)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, (%r15)
testq %rax, %rax
je 0xac3c
xorl %ebp, %ebp
movl $0x2028, %edx           # imm = 0x2028
leaq 0x2060(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3090
movq %r15, %rdi
movq %rbx, %rsi
callq 0xad2d
movq 0x2068(%rsp), %rbx
movq 0x4078(%rsp), %rax
movzbl %al, %ecx
movl %ecx, %edx
shrq $0x8, %rax
cmpq $0x7, %rcx
cmovnel %r12d, %eax
addl (%r13,%rdx,4), %eax
movq (%rbx), %rdi
movslq %eax, %r14
imulq 0x2078(%rsp), %r14
movq %r14, %rsi
movl $0x1, %edx
callq 0x3120
addq %r14, 0x8(%rbx)
leaq 0x2060(%rsp), %rbx
incl %ebp
cmpl $0x63, 0x2070(%rsp)
jg 0xa963
movq (%r15), %rdi
callq 0x36c0
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0xa9de
callq 0x3370
movq 0x10(%r15), %rdi
callq 0x3370
movq 0x10(%rsp), %rdi
leaq 0x4344c(%rip), %rsi     # 0x4de3f
movl %ebp, %edx
xorl %eax, %eax
callq 0x37e0
movl $0x1, %r15d
movq 0x535ef(%rip), %r14     # 0x5dff8
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xad2d
movq (%r14), %rdi
movq 0x38(%rsp), %rcx
leaq 0x4342f(%rip), %rsi     # 0x4de56
movl %r15d, %edx
xorl %eax, %eax
callq 0x37e0
movq (%r14), %rdi
movl 0x48(%rsp), %ebp
leaq 0x43428(%rip), %rsi     # 0x4de67
movl %ebp, %edx
xorl %eax, %eax
callq 0x37e0
movq (%r14), %rsi
leaq 0x43428(%rip), %rdi     # 0x4de7a
callq 0x3520
movq 0x2050(%rsp), %rbx
movzbl %bl, %eax
cmpl $0x1d, %eax
movl %r15d, 0x10(%rsp)
jg 0xaa93
decl %eax
cmpl $0x6, %eax
ja 0xac6b
leaq 0x43362(%rip), %rcx     # 0x4dde0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rsi
leaq 0x433f7(%rip), %rdi     # 0x4de88
jmp 0xab04
cmpl $0x1e, %eax
je 0xaafa
cmpl $0x1f, %eax
je 0xaad6
cmpl $0x20, %eax
jne 0xac6b
movq (%r14), %rsi
leaq 0x4341e(%rip), %rdi     # 0x4dece
jmp 0xab04
movq (%r14), %rsi
leaq 0x433df(%rip), %rdi     # 0x4de9b
jmp 0xab04
movq (%r14), %rsi
leaq 0x433cc(%rip), %rdi     # 0x4de94
jmp 0xab04
movq (%r14), %rsi
leaq 0x43400(%rip), %rdi     # 0x4ded4
jmp 0xab04
movq (%r14), %rsi
leaq 0x433e3(%rip), %rdi     # 0x4dec3
jmp 0xab04
movq (%r14), %rsi
leaq 0x433a2(%rip), %rdi     # 0x4de8e
jmp 0xab04
movq (%r14), %rsi
leaq 0x433bc(%rip), %rdi     # 0x4deb4
jmp 0xab04
movq (%r14), %rsi
leaq 0x433b9(%rip), %rdi     # 0x4debd
callq 0x3520
movq (%r14), %rdi
movq 0x50(%rsp), %r15
leaq 0x433e2(%rip), %rsi     # 0x4defa
movq %r15, %rdx
xorl %eax, %eax
callq 0x37e0
movq (%r14), %rsi
leaq 0x433e5(%rip), %rdi     # 0x4df11
callq 0x3520
cmpb $0x0, 0x60(%rsp)
je 0xab45
movq (%r14), %rsi
leaq 0x60(%rsp), %rdi
callq 0x3520
movq (%r14), %rsi
leaq 0x4260d(%rip), %rdi     # 0x4d15c
callq 0x3520
cmpl $0x64, %ebp
jl 0xabba
movq 0x40(%rsp), %rbp
movq (%rbp), %rdi
movzbl %bl, %eax
movl %eax, %ecx
shrq $0x8, %rbx
cmpq $0x7, %rax
cmovnel %r12d, %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 0x10(%rsp), %r15d
incl %r15d
jmp 0xaa02
movq (%r14), %rdi
movq %rbx, %rdx
shrq $0x8, %rdx
leaq 0x432f5(%rip), %rsi     # 0x4dea3
xorl %eax, %eax
callq 0x37e0
jmp 0xab09
movq 0x28(%rsp), %rbx
movq (%rbx), %rdi
callq 0x36c0
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbp
movq 0x20(%rsp), %r15
movq 0x533e1(%rip), %r14     # 0x5dfc0
jne 0xa859
jmp 0xa85e
movq 0x533f7(%rip), %rax     # 0x5dfe8
movq (%rax), %rdi
leaq 0x43205(%rip), %rsi     # 0x4de00
movl $0x1fe8, %edx           # imm = 0x1FE8
movq %r15, %rcx
xorl %eax, %eax
callq 0x37e0
movb $0x0, 0x1fe8(%r15)
jmp 0xa817
xorl %eax, %eax
addq $0x4088, %rsp           # imm = 0x4088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x68, %ebx
jne 0xac45
callq 0x3eec
movl $0x1, %eax
jmp 0xac19
leaq 0x42bbe(%rip), %rdi     # 0x4d801
jmp 0xac61
callq 0x3eec
leaq 0x4272a(%rip), %rdi     # 0x4d37b
movl %ebx, %esi
xorl %eax, %eax
callq 0xac8a
leaq 0x43327(%rip), %rdi     # 0x4df88
movq %r14, %rsi
xorl %eax, %eax
callq 0xac8a
leaq 0x43269(%rip), %rdi     # 0x4dedb
movq %rbx, %rsi
jmp 0xac64
callq 0x3eec
leaq 0x42712(%rip), %rdi     # 0x4d395
xorl %eax, %eax
callq 0xac8a