// File: /workspace/github_c_makefile_star2_O1/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 0xb31c
movq %rsi, %r14
movl %edi, %ebp
leaq 0x44983(%rip), %rdx     # 0x4f7f9
callq 0x3200
testl %eax, %eax
jns 0xb328
movq 0x53136(%rip), %rbx     # 0x5dfc0
movslq (%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
movq %r14, 0x50(%rsp)
movq (%r14,%rax,8), %rdi
leaq 0x42d40(%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 %ebp, %eax
jge 0xb300
leaq 0x60(%rsp), %r13
leaq 0x10(%rsp), %r14
leaq 0x4213a(%rip), %r12     # 0x4d010
movl %ebp, 0x1c(%rsp)
cltq
movq 0x50(%rsp), %rbp
movq (%rbp,%rax,8), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %rbx, %rdi
callq 0x35f0
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
leaq 0x428f4(%rip), %rsi     # 0x4d7fe
callq 0x3250
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0xb36b
movq 0x530c4(%rip), %rbx     # 0x5dfe8
movq (%rbx), %rdi
movq 0x53092(%rip), %rax     # 0x5dfc0
movslq (%rax), %rax
movq (%rbp,%rax,8), %rdx
leaq 0x43066(%rip), %rsi     # 0x4dfa3
xorl %eax, %eax
callq 0x37e0
movq (%rbx), %rdi
callq 0x38b0
movl 0x1c(%rsp), %ebp
leaq 0x88(%rsp), %rbx
movl $0x2028, %edx           # imm = 0x2028
movq %r13, %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 %r14, %rdi
callq 0x35b0
addq $0x3, 0x28(%rsp)
cmpb $0x74, 0x10(%rsp)
jne 0xb349
cmpb $0x62, 0x11(%rsp)
jne 0xb349
cmpb $0x6b, 0x12(%rsp)
jne 0xb349
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 %rbx, %rdi
callq 0x35b0
addq $0x1fe9, 0x28(%rsp)     # imm = 0x1FE9
cmpq $0x0, 0x60(%rsp)
jne 0xb068
movq %rbx, %rdi
callq 0x3380
cmpb $0x0, 0x8a(%rsp,%rax)
je 0xb068
leaq (%rax,%rbx), %rdi
addq $0x2, %rdi
callq 0x35f0
movq %rax, 0x60(%rsp)
movq 0x52f51(%rip), %rax     # 0x5dfc0
movl (%rax), %eax
incl %eax
cmpl $0x64, 0x70(%rsp)
movl $0x1, %ecx
movl $0x64, %edx
cmovll %edx, %ecx
cmpl %ebp, %eax
movl $0x1, %eax
cmovgel %eax, %ecx
movl %ecx, 0x70(%rsp)
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x35f0
movq %rax, %rbx
movq %rax, %rdi
callq 0x33f0
movq %rax, %rbp
movq %rax, %rdi
callq 0x3380
cmpl $0x5, %eax
jl 0xb101
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
addl %eax, %ecx
cmpb $0x2e, (%rbp,%rcx)
jne 0xb101
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %eax, %edx
incl %edx
cmpb $0x74, (%rbp,%rdx)
jne 0xb101
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %eax, %edx
addl $0x2, %edx
cmpb $0x62, (%rbp,%rdx)
jne 0xb101
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
addl %edx, %eax
addl $0x3, %eax
cmpb $0x6b, (%rbp,%rax)
jne 0xb101
movb $0x0, (%rbp,%rcx)
movq %rbp, %rdi
callq 0x35f0
movq %rax, %rbp
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
callq 0x3370
leaq 0x88(%rsp), %r13
movq %r13, %rdi
callq 0x3380
movq %rax, %rbx
movq %rbp, %rdi
callq 0x3380
addq %rbx, %rax
cmpq $0x1fe4, %rax           # imm = 0x1FE4
jae 0xb357
movq %r13, %rdi
callq 0x3380
leaq 0x8a(%rsp), %rcx
leaq (%rax,%rcx), %rdi
movq 0x60(%rsp), %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 %r14, %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 %r13, %rdi
movq %r15, %rcx
callq 0x3770
movq 0x2078(%rsp), %rax
movzbl %al, %ecx
movl %ecx, %edx
shrq $0x8, %rax
cmpq $0x7, %rcx
movl $0x0, %r13d
cmovnel %r13d, %eax
addl (%r12,%rdx,4), %eax
cltq
imulq 0x78(%rsp), %rax
testq %rax, %rax
jle 0xb28b
movl $0x1, %ebx
movq 0x68(%rsp), %rbp
movq (%rbp), %rcx
movl $0x1, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x35b0
incq 0x8(%rbp)
movsbl 0x10(%rsp), %edi
movq %r15, %rsi
callq 0x3350
movl %ebx, %eax
movq 0x2078(%rsp), %rcx
movzbl %cl, %edx
shrq $0x8, %rcx
cmpq $0x7, %rdx
cmovnel %r13d, %ecx
movl %edx, %edx
addl (%r12,%rdx,4), %ecx
movslq %ecx, %rcx
imulq 0x78(%rsp), %rcx
incl %ebx
cmpq %rax, %rcx
jg 0xb230
movq 0x60(%rsp), %rbx
movl $0x2028, %edx           # imm = 0x2028
leaq 0x60(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x3090
movq %rbx, 0x60(%rsp)
movq %rbx, %rdi
callq 0x3370
movq 0x20(%rsp), %rdi
callq 0x36c0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xb2ca
callq 0x3370
movq 0x30(%rsp), %rdi
callq 0x3370
cmpl $0x63, 0x70(%rsp)
movl 0x1c(%rsp), %ebp
leaq 0x88(%rsp), %rbx
jg 0xaf58
movq 0x52cce(%rip), %rcx     # 0x5dfc0
movl (%rcx), %eax
incl %eax
movl %eax, (%rcx)
cmpl %ebp, %eax
jl 0xaeda
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 0x3f76
movl $0x1, %eax
jmp 0xb30a
movl %eax, %ebx
callq 0x3f76
movl $0x1, %eax
cmpl $0x68, %ebx
je 0xb30a
leaq 0x4203b(%rip), %rdi     # 0x4d37b
movl %ebx, %esi
xorl %eax, %eax
callq 0xb37e
movq 0x30(%rsp), %rsi
leaq 0x42074(%rip), %rdi     # 0x4d3c9
jmp 0xb377
leaq 0x42c50(%rip), %rdi     # 0x4dfae
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb37e
movq 0x30(%rsp), %rsi
leaq 0x4248a(%rip), %rdi     # 0x4d801
xorl %eax, %eax
callq 0xb37e