// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2090, %rsp           # imm = 0x2090
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0xab45
callq 0xb360
movl %eax, -0x4(%rbp)
jmp 0xae33
jmp 0xab47
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x6d08d(%rip), %rdx     # 0x77be2
callq 0x3210
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jl 0xab91
movl -0x14(%rbp), %eax
subl $0x68, %eax
jne 0xab79
jmp 0xab6c
callq 0xb360
movl %eax, -0x4(%rbp)
jmp 0xae33
callq 0xb360
movl -0x14(%rbp), %esi
leaq 0x6a877(%rip), %rdi     # 0x753ff
movb $0x0, %al
callq 0xae40
jmp 0xab47
movq -0x10(%rbp), %rax
movq 0x7a424(%rip), %rcx     # 0x84fc0
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movq 0x7a416(%rip), %rdx     # 0x84fc0
movl %esi, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x6b31d(%rip), %rsi     # 0x75ed7
callq 0x3260
movq %rax, -0x20(%rbp)
leaq -0x2068(%rbp), %rdi
xorl %esi, %esi
movl $0x2028, %edx           # imm = 0x2028
callq 0x3090
movq 0x7a3e3(%rip), %rax     # 0x84fc0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0xae23
movq -0x10(%rbp), %rax
movq 0x7a3cd(%rip), %rcx     # 0x84fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xaf00
movq 0x7a3da(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x7a3a4(%rip), %rcx     # 0x84fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x6b6d5(%rip), %rsi     # 0x762ff
movb $0x0, %al
callq 0x37f0
movq 0x7a3b0(%rip), %rax     # 0x84fe8
movq (%rax), %rdi
callq 0x38c0
leaq -0x40(%rbp), %rdi
leaq -0x2068(%rbp), %rsi
callq 0xafa0
movq 0x7a369(%rip), %rax     # 0x84fc0
movl (%rax), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jge 0xac76
cmpl $0x64, -0x2058(%rbp)
jge 0xac76
movl $0x64, -0x2058(%rbp)
jmp 0xac80
movl $0x1, -0x2058(%rbp)
leaq -0x2068(%rbp), %rdi
callq 0xb0b0
leaq -0x2068(%rbp), %rdi
addq $0x28, %rdi
callq 0x3380
movq %rax, -0x2078(%rbp)
movq -0x2068(%rbp), %rdi
callq 0x3380
movq %rax, %rcx
movq -0x2078(%rbp), %rax
addq %rcx, %rax
cmpq $0x1fe4, %rax           # imm = 0x1FE4
jb 0xace4
leaq -0x2068(%rbp), %rsi
addq $0x28, %rsi
movq -0x2068(%rbp), %rdx
leaq 0x6b62d(%rip), %rdi     # 0x7630a
movb $0x0, %al
callq 0xae40
leaq -0x2068(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x2080(%rbp)
leaq -0x2068(%rbp), %rdi
addq $0x28, %rdi
callq 0x3380
movq -0x2080(%rbp), %rdi
addq %rax, %rdi
addq $0x2, %rdi
movq -0x2068(%rbp), %rsi
callq 0x3660
movl -0x2058(%rbp), %edi
movq -0x50(%rbp), %rsi
movq -0x2050(%rbp), %rdx
leaq -0x2068(%rbp), %rcx
addq $0x28, %rcx
movq -0x20(%rbp), %r8
callq 0xb180
movl $0x0, -0x2070(%rbp)
movl -0x2070(%rbp), %eax
movq %rax, -0x2088(%rbp)
movq -0x2050(%rbp), %rax
movq %rax, -0x2090(%rbp)
movq -0x50(%rbp), %rdi
callq 0xb230
movq -0x2090(%rbp), %rcx
movl %eax, %edx
movq -0x2088(%rbp), %rax
movslq %edx, %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jge 0xadd6
movq -0x2060(%rbp), %rdi
leaq -0x2069(%rbp), %rsi
movl $0x1, %ecx
movq %rcx, %rdx
callq 0xb280
movq -0x20(%rbp), %rcx
leaq -0x2069(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x3780
movl -0x2070(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2070(%rbp)
jmp 0xad4f
leaq -0x2068(%rbp), %rdi
callq 0xb2d0
movq -0x2068(%rbp), %rdi
callq 0x3370
leaq -0x40(%rbp), %rdi
callq 0xb310
cmpl $0x64, -0x2058(%rbp)
jge 0xae02
jmp 0xae07
jmp 0xac40
jmp 0xae09
movq 0x7a1b0(%rip), %rax     # 0x84fc0
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x7a1a4(%rip), %rax     # 0x84fc0
movl %ecx, (%rax)
jmp 0xabd6
movq -0x20(%rbp), %rdi
callq 0x36d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2090, %rsp           # imm = 0x2090
popq %rbp
retq
nop