// File: /workspace/github_c_makefile_star2_O2/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, %r13d
movq $0x0, 0x10(%rsp)
leaq 0xb88b9(%rip), %r15     # 0x35c1bf
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r12d, %r12d
movl %r13d, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2f020
testl %eax, %eax
js 0x2a3988
cmpl $0x31, %eax
je 0x2a396a
cmpl $0x52, %eax
je 0x2a3974
cmpl $0x66, %eax
je 0x2a396f
cmpl $0x68, %eax
je 0x2a3947
cmpl $0x6e, %eax
je 0x2a3960
cmpl $0x75, %eax
je 0x2a395b
cmpl $0x72, %eax
jne 0x2a390d
orl $0x1, %ebp
jmp 0x2a390d
movq 0x1675ea(%rip), %rax    # 0x40af38
movq (%rax), %rdi
callq 0x316c0
movq %rax, %rbx
jmp 0x2a390d
orl $0x2, %ebp
jmp 0x2a390d
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
jmp 0x2a390d
orl $0x4, %ebp
jmp 0x2a390d
orl $0x8, %ebp
jmp 0x2a390d
movq 0x1675bd(%rip), %rax    # 0x40af38
movq (%rax), %rdi
callq 0x316c0
movq %rax, %r12
jmp 0x2a390d
movq 0x167559(%rip), %r15    # 0x40aee8
movl (%r15), %eax
leal 0x2(%rax), %ecx
cmpl %r13d, %ecx
jge 0x2a3a18
testb $0x8, %bpl
jne 0x2a39ca
movslq %eax, %rcx
movq (%r14,%rcx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x2a39b2
cmpb $0x0, 0x1(%rdi)
je 0x2a39ca
leaq 0x8b961(%rip), %rsi     # 0x32f31a
callq 0x32660
testq %rax, %rax
jne 0x2a3b16
movl (%r15), %eax
movslq %eax, %rcx
leaq (%r14,%rcx,8), %r8
addq $0x8, %r8
movq -0x8(%r8), %rsi
notl %ecx
addl %r13d, %ecx
movq %r12, (%rsp)
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
movl %ebp, %r9d
callq 0x2a3080
movl %eax, %ebp
shrl $0x1f, %ebp
movq %r12, %rdi
callq 0x33058
movq %rbx, %rdi
callq 0x33058
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x167591(%rip), %r14    # 0x40afb0
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x2fcd0
movq (%r14), %rcx
leaq 0xb8795(%rip), %rdi     # 0x35c1c9
pushq $0x50
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb87ce(%rip), %rdi     # 0x35c21a
pushq $0x25
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb87df(%rip), %rdi     # 0x35c240
pushq $0x3b
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb8806(%rip), %rdi     # 0x35c27c
pushq $0x2a
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb881c(%rip), %rdi     # 0x35c2a7
pushq $0x34
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb883c(%rip), %rdi     # 0x35c2dc
pushq $0x23
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb884b(%rip), %rdi     # 0x35c300
pushq $0x3f
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb8876(%rip), %rdi     # 0x35c340
pushq $0x42
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb88a4(%rip), %rdi     # 0x35c383
pushq $0x53
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb88e3(%rip), %rdi     # 0x35c3d7
pushq $0x57
popq %rsi
movq %rbx, %rdx
callq 0x32760
movq (%r14), %rcx
leaq 0xb8926(%rip), %rdi     # 0x35c42f
pushq $0x29
popq %rsi
movq %rbx, %rdx
callq 0x32760
jmp 0x2a3b44
movq %rax, %rdi
callq 0x320a0
movq 0x16748b(%rip), %rax    # 0x40afb0
movq (%rax), %rdi
movslq (%r15), %rax
movq (%r14,%rax,8), %rcx
leaq 0xb8923(%rip), %rsi     # 0x35c459
leaq 0xb895b(%rip), %rdx     # 0x35c498
xorl %eax, %eax
callq 0x32960
pushq $0x1
popq %rbp
jmp 0x2a3a07