// File: /workspace/github_c_makefile_star2_O3/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 $0x2088, %rsp           # imm = 0x2088
cmpl $0x2, %edi
jle 0xb45d
movq %rsi, %r14
movl %edi, %r13d
leaq 0x449f2(%rip), %rdx     # 0x4f9b1
callq 0x3200
testl %eax, %eax
jns 0xb469
movq 0x53fed(%rip), %rbx     # 0x5efc0
movslq (%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
movq %r14, 0x50(%rsp)
movq (%r14,%rax,8), %rdi
leaq 0x42bf7(%rip), %rsi     # 0x4dbe2
callq 0x3250
movq %rax, %r15
leaq 0x60(%rsp), %rdi
movl $0x2028, %edx           # imm = 0x2028
xorl %esi, %esi
callq 0x3090
movl (%rbx), %eax
cmpl %r13d, %eax
jge 0xb441
leaq 0x10(%rsp), %rbx
leaq 0x41ff5(%rip), %r12     # 0x4d010
movl %r13d, 0x1c(%rsp)
cltq
movq 0x50(%rsp), %r13
movq (%r13,%rax,8), %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %r14, %rdi
callq 0x35f0
movq %rax, 0x30(%rsp)
movq %r14, %rdi
leaq 0x427b2(%rip), %rsi     # 0x4d802
callq 0x3250
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0xb4ac
movq 0x53f7e(%rip), %r14     # 0x5efe8
movq (%r14), %rdi
movq 0x53f4c(%rip), %rax     # 0x5efc0
movslq (%rax), %rax
movq (%r13,%rax,8), %rdx
leaq 0x42f20(%rip), %rsi     # 0x4dfa3
xorl %eax, %eax
callq 0x37e0
movq (%r14), %rdi
callq 0x38b0
movl 0x1c(%rsp), %r13d
leaq 0x88(%rsp), %r14
movl $0x2028, %edx           # imm = 0x2028
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x3090
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x68(%rsp)
movl $0x3, %esi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x35b0
addq $0x3, 0x28(%rsp)
cmpb $0x74, 0x10(%rsp)
jne 0xb48a
cmpb $0x62, 0x11(%rsp)
jne 0xb48a
cmpb $0x6b, 0x12(%rsp)
jne 0xb48a
movq 0x20(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
leaq 0x70(%rsp), %rdi
callq 0x35b0
addq $0x4, 0x28(%rsp)
movq 0x20(%rsp), %rcx
movl $0x8, %esi
movl $0x1, %edx
leaq 0x2078(%rsp), %rdi
callq 0x35b0
addq $0x8, 0x28(%rsp)
movq 0x20(%rsp), %rcx
movl $0x8, %esi
movl $0x1, %edx
leaq 0x78(%rsp), %rdi
callq 0x35b0
addq $0x8, 0x28(%rsp)
movq 0x20(%rsp), %rcx
movl $0x1fe9, %esi           # imm = 0x1FE9
movl $0x1, %edx
movq %r14, %rdi
callq 0x35b0
addq $0x1fe9, 0x28(%rsp)     # imm = 0x1FE9
cmpq $0x0, 0x60(%rsp)
jne 0xb1b1
movq %r14, %rdi
callq 0x3380
cmpb $0x0, 0x8a(%rsp,%rax)
je 0xb1b1
leaq (%rax,%r14), %rdi
addq $0x2, %rdi
callq 0x35f0
movq %rax, 0x60(%rsp)
movq 0x53e08(%rip), %rax     # 0x5efc0
movl (%rax), %eax
incl %eax
cmpl $0x64, 0x70(%rsp)
movl $0x1, %ecx
movl $0x64, %edx
cmovll %edx, %ecx
cmpl %r13d, %eax
movl $0x1, %eax
cmovgel %eax, %ecx
movl %ecx, 0x70(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x35f0
movq %rax, %r14
movq %rax, %rdi
callq 0x33f0
movq %rax, %r13
movq %rax, %rdi
callq 0x3380
cmpl $0x5, %eax
jl 0xb250
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
addl %eax, %ecx
cmpb $0x2e, (%r13,%rcx)
jne 0xb250
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %eax, %edx
incl %edx
cmpb $0x74, (%r13,%rdx)
jne 0xb250
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %eax, %edx
addl $0x2, %edx
cmpb $0x62, (%r13,%rdx)
jne 0xb250
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %edx, %eax
addl $0x3, %eax
cmpb $0x6b, (%r13,%rax)
jne 0xb250
movb $0x0, (%r13,%rcx)
movq %r13, %rdi
callq 0x35f0
movq %rax, %r13
movq %rax, 0x60(%rsp)
movq %r14, %rdi
callq 0x3370
leaq 0x88(%rsp), %rbp
movq %rbp, %rdi
callq 0x3380
movq %rax, %r14
movq %r13, %rdi
callq 0x3380
addq %r14, %rax
cmpq $0x1fe4, %rax           # imm = 0x1FE4
jae 0xb498
leaq 0x8a(%rsp), %rax
addq %rax, %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x3650
movl 0x70(%rsp), %eax
movq 0x2078(%rsp), %rcx
movq 0x78(%rsp), %rdx
movl %eax, 0x4c(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x58(%rsp)
movb $0x6b, 0xe(%rsp)
movw $0x6274, 0xc(%rsp)      # imm = 0x6274
movl $0x3, %esi
movl $0x1, %edx
leaq 0xc(%rsp), %rdi
movq %r15, %rcx
callq 0x3770
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4c(%rsp), %rdi
movq %r15, %rcx
callq 0x3770
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x3770
movl $0x8, %esi
movl $0x1, %edx
leaq 0x58(%rsp), %rdi
movq %r15, %rcx
callq 0x3770
movl $0x1fe9, %esi           # imm = 0x1FE9
movl $0x1, %edx
movq %rbp, %rdi
movq %r15, %rcx
callq 0x3770
movq 0x2078(%rsp), %rax
movzbl %al, %ecx
movl %ecx, %edx
shrq $0x8, %rax
cmpq $0x7, %rcx
movl $0x0, %ebp
cmovnel %ebp, %eax
addl (%r12,%rdx,4), %eax
cltq
imulq 0x78(%rsp), %rax
testq %rax, %rax
jle 0xb3d2
movl $0x1, %r14d
movq 0x68(%rsp), %r13
movq (%r13), %rcx
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x35b0
incq 0x8(%r13)
movsbl 0x10(%rsp), %edi
movq %r15, %rsi
callq 0x3350
movl %r14d, %eax
movq 0x2078(%rsp), %rcx
movzbl %cl, %edx
shrq $0x8, %rcx
cmpq $0x7, %rdx
cmovnel %ebp, %ecx
movl %edx, %edx
addl (%r12,%rdx,4), %ecx
movslq %ecx, %rcx
imulq 0x78(%rsp), %rcx
incl %r14d
cmpq %rax, %rcx
jg 0xb376
movq 0x60(%rsp), %r14
movl $0x2020, %edx           # imm = 0x2020
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0x3090
movq %r14, %rdi
callq 0x3370
movq 0x20(%rsp), %rdi
callq 0x36c0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xb409
callq 0x3370
movq 0x30(%rsp), %rdi
callq 0x3370
cmpl $0x63, 0x70(%rsp)
movl 0x1c(%rsp), %r13d
leaq 0x88(%rsp), %r14
jg 0xb09f
movq 0x53b8e(%rip), %rcx     # 0x5efc0
movl (%rcx), %eax
incl %eax
movl %eax, (%rcx)
cmpl %r13d, %eax
jl 0xb020
movq %r15, %rdi
callq 0x36c0
xorl %eax, %eax
addq $0x2088, %rsp           # imm = 0x2088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3f70
movl $0x1, %eax
jmp 0xb44b
movl %eax, %ebx
callq 0x3f70
movl $0x1, %eax
cmpl $0x68, %ebx
je 0xb44b
leaq 0x41efe(%rip), %rdi     # 0x4d37f
movl %ebx, %esi
xorl %eax, %eax
callq 0xb4bf
movq 0x30(%rsp), %rsi
leaq 0x41f37(%rip), %rdi     # 0x4d3cd
jmp 0xb4b8
leaq 0x42b0f(%rip), %rdi     # 0x4dfae
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xb4bf
movq 0x30(%rsp), %rsi
leaq 0x4234d(%rip), %rdi     # 0x4d805
xorl %eax, %eax
callq 0xb4bf