// File: /workspace/github_c_makefile_star2_O3/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, %r14
movl %edi, %ebx
leaq 0xbe3db(%rip), %rdx     # 0x3b8eff
callq 0x2e000
testl %eax, %eax
js 0x2fabd3
xorl %r15d, %r15d
leaq 0xbe3c4(%rip), %r13     # 0x3b8eff
xorl %r12d, %r12d
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
cmpl $0x67, %eax
jle 0x2fab69
cmpl $0x71, %eax
jg 0x2fab7d
cmpl $0x68, %eax
je 0x2fab91
cmpl $0x6e, %eax
jne 0x2fabbc
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x2fabbc
cmpl $0x31, %eax
je 0x2fab8c
cmpl $0x52, %eax
je 0x2fabaa
cmpl $0x66, %eax
jne 0x2fabbc
orl $0x8, %ebp
jmp 0x2fabbc
cmpl $0x75, %eax
je 0x2faba5
cmpl $0x72, %eax
jne 0x2fabbc
orl $0x1, %ebp
jmp 0x2fabbc
orl $0x4, %ebp
jmp 0x2fabbc
movq 0x18b3d8(%rip), %rax    # 0x485f70
movq (%rax), %rdi
callq 0x30660
movq %rax, %r12
jmp 0x2fabbc
orl $0x2, %ebp
jmp 0x2fabbc
movq 0x18b3bf(%rip), %rax    # 0x485f70
movq (%rax), %rdi
callq 0x30660
movq %rax, %r15
movl %ebx, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2e000
testl %eax, %eax
jns 0x2fab49
jmp 0x2fabe4
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x18b33d(%rip), %r13    # 0x485f28
movl (%r13), %eax
leal 0x2(%rax), %ecx
cmpl %ebx, %ecx
jge 0x2fac70
testb $0x8, %bpl
jne 0x2fac23
movslq %eax, %rcx
movq (%r14,%rcx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x2fac0e
cmpb $0x0, 0x1(%rdi)
je 0x2fac23
leaq 0x913ad(%rip), %rsi     # 0x38bfc2
callq 0x31620
testq %rax, %rax
jne 0x2fac77
movl (%r13), %eax
movslq %eax, %rcx
leaq (%r14,%rcx,8), %r8
addq $0x8, %r8
movq -0x8(%r8), %rsi
notl %ecx
addl %ebx, %ecx
movq %r15, (%rsp)
movq 0x10(%rsp), %rdi
movq %r12, %rdx
movl %ebp, %r9d
callq 0x2fa237
movl %eax, %ebx
shrl $0x1f, %ebx
movq %r15, %rdi
callq 0x32018
movq %r12, %rdi
callq 0x32018
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xa93eb
jmp 0x2fac82
movq %rax, %rdi
movq %r14, %rsi
callq 0xa94f2
movl $0x1, %ebx
jmp 0x2fac5f