// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2090, %rsp           # imm = 0x2090
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jge 0x9fd5
callq 0xa8a0
movl %eax, -0x4(%rbp)
jmp 0xa47a
movq $0x0, -0x20(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x6c16d(%rip), %rdx     # 0x76158
callq 0x3210
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jl 0xa04a
movl -0x14(%rbp), %eax
movl %eax, -0x205c(%rbp)
subl $0x68, %eax
je 0xa025
jmp 0xa008
movl -0x205c(%rbp), %eax
subl $0x6d, %eax
jne 0xa032
jmp 0xa015
movq 0x7afc4(%rip), %rax     # 0x84fe0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xa048
callq 0xa8a0
movl %eax, -0x4(%rbp)
jmp 0xa47a
callq 0xa8a0
movl -0x14(%rbp), %esi
leaq 0x6b3be(%rip), %rdi     # 0x753ff
movb $0x0, %al
callq 0xa490
jmp 0x9fdd
movq 0x7af6f(%rip), %rax     # 0x84fc0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jle 0xa06b
callq 0xa8a0
leaq 0x6b3b5(%rip), %rdi     # 0x75419
movb $0x0, %al
callq 0xa490
movq $0x0, -0x28(%rbp)
leaq -0x2050(%rbp), %rdi
xorl %esi, %esi
movl $0x2028, %edx           # imm = 0x2028
callq 0x3090
movl $0x0, -0x2054(%rbp)
movl $0x0, -0x2058(%rbp)
movq 0x7af1f(%rip), %rax     # 0x84fc0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0xa473
cmpq $0x0, -0x20(%rbp)
je 0xa163
movq -0x10(%rbp), %rax
movq 0x7aefe(%rip), %rcx     # 0x84fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa550
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x17, %esi
xorl %edx, %edx
callq 0x3120
movq -0x20(%rbp), %rdi
callq 0x3380
cmpq $0x1fe8, %rax           # imm = 0x1FE8
jb 0xa122
movq 0x7aeeb(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x20(%rbp), %rcx
leaq 0x6c051(%rip), %rsi     # 0x7615c
movl $0x1fe8, %edx           # imm = 0x1FE8
movb $0x0, %al
callq 0x37f0
movq -0x20(%rbp), %rax
movb $0x0, 0x1fe8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x2068(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3380
movq -0x2068(%rbp), %rdi
movq %rax, %rsi
addq $0x1, %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x3780
movq -0x28(%rbp), %rdi
callq 0xa5e0
jmp 0xa448
movq -0x10(%rbp), %rax
movq 0x7ae52(%rip), %rcx     # 0x84fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa630
movq %rax, -0x28(%rbp)
movq 0x7ae73(%rip), %rax     # 0x84ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x6bff5(%rip), %rsi     # 0x7618c
movb $0x0, %al
callq 0x37f0
movq 0x7ae43(%rip), %rax     # 0x84fe8
movq (%rax), %rax
movq %rax, -0x2070(%rbp)
movq -0x10(%rbp), %rax
movq 0x7ae06(%rip), %rcx     # 0x84fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xa670
movq -0x2070(%rbp), %rdi
movl %eax, %edx
leaq 0x6bfc5(%rip), %rsi     # 0x7619b
movb $0x0, %al
callq 0x37f0
movl $0x1, -0x2058(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x2050(%rbp), %rsi
callq 0xa700
movq 0x7adfa(%rip), %rax     # 0x84ff8
movq %rax, -0x2080(%rbp)
movq (%rax), %rdi
movl -0x2058(%rbp), %edx
movl %edx, %eax
incl %eax
movl %eax, -0x2058(%rbp)
movq -0x2050(%rbp), %rcx
leaq 0x6bf8c(%rip), %rsi     # 0x761b2
xorl %eax, %eax
movb %al, -0x2081(%rbp)
callq 0x37f0
movq -0x2080(%rbp), %rcx
movb -0x2081(%rbp), %al
movq (%rcx), %rdi
movl -0x2040(%rbp), %edx
leaq 0x6bf73(%rip), %rsi     # 0x761c3
callq 0x37f0
movq -0x2080(%rbp), %rax
movq (%rax), %rsi
leaq 0x6bf70(%rip), %rdi     # 0x761d6
callq 0x3520
movzbl -0x38(%rbp), %eax
decq %rax
movq %rax, -0x2078(%rbp)
subq $0x1f, %rax
ja 0xa3a3
movq -0x2078(%rbp), %rax
leaq 0x6be47(%rip), %rcx     # 0x760d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x7ad57(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bf39(%rip), %rdi     # 0x761e4
callq 0x3520
jmp 0xa3b5
movq 0x7ad3c(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bf24(%rip), %rdi     # 0x761ea
callq 0x3520
jmp 0xa3b5
movq 0x7ad21(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bf0f(%rip), %rdi     # 0x761f0
callq 0x3520
jmp 0xa3b5
movq 0x7ad06(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bf34(%rip), %rdi     # 0x76230
callq 0x3520
jmp 0xa3b5
movq 0x7aceb(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bee0(%rip), %rdi     # 0x761f7
callq 0x3520
jmp 0xa3b5
movq 0x7acd0(%rip), %rax     # 0x84ff8
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
shrq $0x8, %rdx
leaq 0x6bec5(%rip), %rsi     # 0x761ff
movb $0x0, %al
callq 0x37f0
jmp 0xa3b5
movq 0x7acae(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bebc(%rip), %rdi     # 0x76210
callq 0x3520
jmp 0xa3b5
movq 0x7ac96(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6bead(%rip), %rdi     # 0x76219
callq 0x3520
jmp 0xa3b5
movq 0x7ac7e(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6be9b(%rip), %rdi     # 0x7621f
callq 0x3520
jmp 0xa3b5
movq 0x7ac66(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6be8e(%rip), %rdi     # 0x7622a
callq 0x3520
jmp 0xa3b5
movq -0x38(%rbp), %rsi
leaq 0x6be89(%rip), %rdi     # 0x76237
movb $0x0, %al
callq 0xa490
movq 0x7ac3c(%rip), %rax     # 0x84ff8
movq (%rax), %rdi
movq -0x2038(%rbp), %rdx
leaq 0x6be89(%rip), %rsi     # 0x76256
movb $0x0, %al
callq 0x37f0
movq 0x7ac1d(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6be88(%rip), %rdi     # 0x7626d
callq 0x3520
cmpb $0x0, -0x2028(%rbp)
je 0xa40d
leaq -0x2050(%rbp), %rdi
addq $0x28, %rdi
movq 0x7abf3(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
callq 0x3520
movq 0x7abe4(%rip), %rax     # 0x84ff8
movq (%rax), %rsi
leaq 0x6ad3e(%rip), %rdi     # 0x7515c
callq 0x3520
cmpl $0x64, -0x2040(%rbp)
jge 0xa42e
jmp 0xa43f
leaq -0x2050(%rbp), %rdi
callq 0xa810
jmp 0xa1e7
movq -0x28(%rbp), %rdi
callq 0xa5e0
jmp 0xa44a
movq 0x7ab6f(%rip), %rax     # 0x84fc0
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x7ab63(%rip), %rax     # 0x84fc0
movl %ecx, (%rax)
movl -0x2054(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2054(%rbp)
jmp 0xa09a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2090, %rsp           # imm = 0x2090
popq %rbp
retq
nopw %cs:(%rax,%rax)