// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/samtools-0.1.18/bam_sort.c
// Function: bam_merge
int bam_merge(int argc, char *argv[])
{
	int c, is_by_qname = 0, flag = 0, ret = 0;
	char *fn_headers = NULL, *reg = 0;

	while ((c = getopt(argc, argv, "h:nru1R:f")) >= 0) {
		switch (c) {
		case 'r': flag |= MERGE_RG; break;
		case 'f': flag |= MERGE_FORCE; break;
		case 'h': fn_headers = strdup(optarg); break;
		case 'n': is_by_qname = 1; break;
		case '1': flag |= MERGE_LEVEL1; break;
		case 'u': flag |= MERGE_UNCOMP; break;
		case 'R': reg = strdup(optarg); break;
		}
	}
	if (optind + 2 >= argc) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   samtools merge [-nr] [-h inh.sam] <out.bam> <in1.bam> <in2.bam> [...]\n\n");
		fprintf(stderr, "Options: -n       sort by read names\n");
		fprintf(stderr, "         -r       attach RG tag (inferred from file names)\n");
		fprintf(stderr, "         -u       uncompressed BAM output\n");
		fprintf(stderr, "         -f       overwrite the output BAM if exist\n");
		fprintf(stderr, "         -1       compress level 1\n");
		fprintf(stderr, "         -R STR   merge file in the specified region STR [all]\n");
		fprintf(stderr, "         -h FILE  copy the header in FILE to <out.bam> [in1.bam]\n\n");
		fprintf(stderr, "Note: Samtools' merge does not reconstruct the @RG dictionary in the header. Users\n");
		fprintf(stderr, "      must provide the correct header with -h, or uses Picard which properly maintains\n");
		fprintf(stderr, "      the header dictionary in merging.\n\n");
		return 1;
	}
	if (!(flag & MERGE_FORCE) && strcmp(argv[optind], "-")) {
		FILE *fp = fopen(argv[optind], "rb");
		if (fp != NULL) {
			fclose(fp);
			fprintf(stderr, "[%s] File '%s' exists. Please apply '-f' to overwrite. Abort.\n", __func__, argv[optind]);
			return 1;
		}
	}
	if (bam_merge_core(is_by_qname, argv[optind], fn_headers, argc - optind - 1, argv + optind + 1, flag, reg) < 0) ret = 1;
	free(reg);
	free(fn_headers);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xbf2fd(%rip), %rdx     # 0x3c25ef
callq 0x2e000
testl %eax, %eax
js 0x3033a6
xorl %r14d, %r14d
leaq 0xbf2e6(%rip), %r13     # 0x3c25ef
xorl %r15d, %r15d
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
cmpl $0x67, %eax
jle 0x303338
cmpl $0x71, %eax
jg 0x30334d
cmpl $0x68, %eax
je 0x303363
cmpl $0x6e, %eax
jne 0x30338f
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x30338f
cmpl $0x31, %eax
je 0x30335d
cmpl $0x52, %eax
je 0x30337d
cmpl $0x66, %eax
jne 0x30338f
orl $0x8, %r12d
jmp 0x30338f
cmpl $0x75, %eax
je 0x303377
cmpl $0x72, %eax
jne 0x30338f
orl $0x1, %r12d
jmp 0x30338f
orl $0x4, %r12d
jmp 0x30338f
movq 0x18cc06(%rip), %rax    # 0x48ff70
movq (%rax), %rdi
callq 0x30660
movq %rax, %r15
jmp 0x30338f
orl $0x2, %r12d
jmp 0x30338f
movq 0x18cbec(%rip), %rax    # 0x48ff70
movq (%rax), %rdi
callq 0x30660
movq %rax, %r14
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2e000
testl %eax, %eax
jns 0x303318
jmp 0x3033b8
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x18cb69(%rip), %rdx    # 0x48ff28
movslq (%rdx), %rax
leal 0x2(%rax), %ecx
cmpl %ebp, %ecx
jge 0x303459
testb $0x8, %r12b
jne 0x30340c
movq (%rbx,%rax,8), %r13
leaq 0xbb084(%rip), %rsi     # 0x3be462
movq %r13, %rdi
callq 0x308e0
movq 0x18cb3b(%rip), %rdx    # 0x48ff28
testl %eax, %eax
je 0x30340c
leaq 0x92099(%rip), %rsi     # 0x395491
movq %r13, %rdi
callq 0x31620
movq 0x18cb21(%rip), %rdx    # 0x48ff28
testq %rax, %rax
jne 0x303460
movslq (%rdx), %rcx
leaq (%rbx,%rcx,8), %r8
addq $0x8, %r8
movq -0x8(%r8), %rsi
notl %ecx
addl %ebp, %ecx
movq %r14, (%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rdx
movl %r12d, %r9d
callq 0x3029f5
movl %eax, %ebx
shrl $0x1f, %ebx
movq %r14, %rdi
callq 0x32018
movq %r15, %rdi
callq 0x32018
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xab173
jmp 0x30346b
movq %rax, %rdi
movq %rbx, %rsi
callq 0xab27a
movl $0x1, %ebx
jmp 0x303448