// File: /workspace/github_c_makefile_star2_O2/zhou-lab[P]tbmate/bundle.c
// Function: main_bundle
int main_bundle(int argc, char *argv[]) {

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

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

  FILE *out = fopen(argv[optind++], "wb");

  tbf_t tbf;
  tbk_t tbk = {0};
  for(; optind < argc; optind++) {
    tbf_open1(argv[optind], &tbf, NULL);
    fprintf(stderr, "Adding %s\n", argv[optind]);
    fflush(stderr);
    while (1) {
      tbf_next(&tbf, &tbk);

      /* all except last will have triple-digit version number */
      if (optind + 1 < argc && tbk.version < 100) tbk.version = 100;
      else tbk.version = 1;

      tbk_set_sname_by_fname(&tbk);

      if (strlen(tbk.extra) + strlen(tbk.sname) >= HDR_EXTRA-5) {
        wzfatal(
          "%s index and %s sname is too long. Consider shorter sample names.",
          tbk.extra, tbk.sname);
      }
      strcpy(tbk.extra + strlen(tbk.extra) + 2, tbk.sname);
      tbk_write_hdr(tbk.version, tbk.dtype, tbk.nmax, tbk.extra, out);
    
      char data; unsigned j;
      for (j=0; j<tbk.nmax * unit_size(tbk.dtype); ++j) {
        tbf_read(tbk.tbf, &data, 1, 1);
        fwrite(&data, 1, 1, out);
      }
      tbk_close(&tbk);
      free(tbk.sname);
      tbf_close(&tbf);
      
      if (tbk.version < 100) break;
    }
  }

  fclose(out);
  
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2078, %rsp           # imm = 0x2078
cmpl $0x2, %edi
jg 0x8601
callq 0x8b16
jmp 0x8627
movq %rsi, %r14
movl %edi, %r12d
leaq 0x391e3(%rip), %rdx     # 0x417f1
callq 0x3200
testl %eax, %eax
js 0x863c
movl %eax, %ebx
callq 0x8b16
cmpl $0x68, %ebx
jne 0x8a3e
pushq $0x1
popq %rax
addq $0x2078, %rsp           # imm = 0x2078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4a97d(%rip), %rbx     # 0x52fc0
movslq (%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
movq %r14, 0x40(%rsp)
movq (%r14,%rax,8), %rdi
leaq 0x37587(%rip), %rsi     # 0x3fbe2
callq 0x3250
movq %rax, %r14
leaq 0x50(%rsp), %rdi
movl $0x2028, %edx           # imm = 0x2028
xorl %esi, %esi
callq 0x3090
movl (%rbx), %eax
leaq 0x10(%rsp), %r15
pushq $0x1
popq %rbp
movl %r12d, 0x18(%rsp)
cmpl %r12d, %eax
jge 0x89fa
cltq
movq 0x40(%rsp), %r13
movq (%r13,%rax,8), %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %r12, %rdi
callq 0x3600
movq %rax, 0x30(%rsp)
movq %r12, %rdi
leaq 0x37146(%rip), %rsi     # 0x3f802
callq 0x3250
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x8a2b
movq 0x4a912(%rip), %rbx     # 0x52fe8
movq (%rbx), %rdi
movq 0x4a8e0(%rip), %rax     # 0x52fc0
movslq (%rax), %rax
movq (%r13,%rax,8), %rdx
leaq 0x378b4(%rip), %rsi     # 0x3ffa3
xorl %eax, %eax
callq 0x37f0
movq (%rbx), %rdi
callq 0x38c0
movl $0x2028, %edx           # imm = 0x2028
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x3090
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x20(%rsp), %rdi
movq %rdi, 0x58(%rsp)
movq %r15, %rsi
pushq $0x3
popq %rdx
callq 0x8aef
cmpb $0x74, 0x10(%rsp)
leaq 0x78(%rsp), %rbx
jne 0x8a1d
cmpb $0x62, 0x11(%rsp)
jne 0x8a1d
cmpb $0x6b, 0x12(%rsp)
jne 0x8a1d
leaq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x8aef
movq %r13, %rdi
leaq 0x2068(%rsp), %rsi
pushq $0x8
popq %r12
movq %r12, %rdx
callq 0x8aef
movq %r13, %rdi
leaq 0x68(%rsp), %rsi
movq %r12, %rdx
callq 0x8aef
movl $0x1fe9, %edx           # imm = 0x1FE9
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8aef
cmpq $0x0, 0x50(%rsp)
jne 0x87c9
movq %rbx, %rdi
callq 0x3380
cmpb $0x0, 0x7a(%rsp,%rax)
je 0x87c9
leaq (%rax,%rbx), %rdi
addq $0x2, %rdi
callq 0x3600
movq %rax, 0x50(%rsp)
movq 0x4a7f0(%rip), %rax     # 0x52fc0
movl (%rax), %eax
incl %eax
cmpl $0x64, 0x60(%rsp)
pushq $0x1
popq %rsi
movl %esi, %ecx
pushq $0x64
popq %rdx
cmovll %edx, %ecx
cmpl 0x18(%rsp), %eax
cmovgel %esi, %ecx
movl %ecx, 0x60(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x3600
movq %rax, %r12
movq %rax, %rdi
callq 0x33f0
movq %rax, %r13
movq %rax, %rdi
callq 0x3380
cmpl $0x5, %eax
jl 0x8862
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
addl %eax, %ecx
cmpb $0x2e, (%r13,%rcx)
jne 0x8862
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %eax, %edx
incl %edx
cmpb $0x74, (%r13,%rdx)
jne 0x8862
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %eax, %edx
addl $0x2, %edx
cmpb $0x62, (%r13,%rdx)
jne 0x8862
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %edx, %eax
addl $0x3, %eax
cmpb $0x6b, (%r13,%rax)
jne 0x8862
movb $0x0, (%r13,%rcx)
movq %r13, %rdi
callq 0x3600
movq %rax, %r13
movq %rax, 0x50(%rsp)
movq %r12, %rdi
callq 0x3370
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x3380
movq %rax, %r12
movq %r13, %rdi
callq 0x3380
addq %r12, %rax
cmpq $0x1fe4, %rax           # imm = 0x1FE4
jae 0x8a09
leaq 0x7a(%rsp), %rax
addq %rax, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x3660
movl 0x60(%rsp), %eax
movq 0x2068(%rsp), %rcx
movq 0x68(%rsp), %rdx
movl %eax, 0x1c(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x48(%rsp)
movb $0x6b, 0xe(%rsp)
movw $0x6274, 0xc(%rsp)      # imm = 0x6274
leaq 0xc(%rsp), %rdi
pushq $0x3
popq %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x3780
leaq 0x1c(%rsp), %rdi
pushq $0x4
popq %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x3780
movq %r15, %rdi
pushq $0x8
popq %r12
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x3780
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x3780
movl $0x1fe9, %esi           # imm = 0x1FE9
movq %rbx, %rdi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x3780
xorl %r12d, %r12d
xorl %r13d, %r13d
leaq 0x366c3(%rip), %rbx     # 0x3f010
movl %r12d, %eax
movq 0x2068(%rsp), %rcx
movzbl %cl, %edx
movl %edx, %esi
shrq $0x8, %rcx
cmpq $0x7, %rdx
cmovnel %r13d, %ecx
addl (%rbx,%rsi,4), %ecx
movslq %ecx, %rcx
imulq 0x68(%rsp), %rcx
cmpq %rax, %rcx
jle 0x899c
movq 0x58(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x8aef
movsbl 0x10(%rsp), %edi
movq %r14, %rsi
callq 0x3350
incl %r12d
jmp 0x894d
movq 0x50(%rsp), %r12
movl $0x2020, %edx           # imm = 0x2020
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
callq 0x3090
movq %r12, %rdi
callq 0x3370
movq 0x20(%rsp), %rdi
callq 0x36d0
movq 0x38(%rsp), %rdi
callq 0x3370
movq 0x30(%rsp), %rdi
callq 0x3370
cmpl $0x63, 0x60(%rsp)
movl 0x18(%rsp), %r12d
jg 0x86fe
movq 0x4a5d1(%rip), %rcx     # 0x52fc0
movl (%rcx), %eax
incl %eax
movl %eax, (%rcx)
jmp 0x8683
movq %r14, %rdi
callq 0x36d0
xorl %eax, %eax
jmp 0x862a
leaq 0x3759e(%rip), %rdi     # 0x3ffae
movq %rbx, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x8a4e
movq 0x30(%rsp), %rsi
leaq 0x369a4(%rip), %rdi     # 0x3f3cd
jmp 0x8a37
movq 0x30(%rsp), %rsi
leaq 0x36dce(%rip), %rdi     # 0x3f805
xorl %eax, %eax
callq 0x8a4e
leaq 0x3693a(%rip), %rdi     # 0x3f37f
movl %ebx, %esi
xorl %eax, %eax
callq 0x8a4e