// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_sort.c
// Function: bam_merge
int bam_merge(int argc, char *argv[])
{
	int c, is_by_qname = 0, flag = 0, ret = 0, n_threads = 0, level = -1;
	char *fn_headers = NULL, *reg = 0;

	while ((c = getopt(argc, argv, "h:nru1R:f@:l:")) >= 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;
		case 'l': level = atoi(optarg); break;
		case '@': n_threads = atoi(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, "         -l INT   compression level, from 0 to 9 [-1]\n");
		fprintf(stderr, "         -@ INT   number of BAM compression threads [0]\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_core2(is_by_qname, argv[optind], fn_headers, argc - optind - 1, argv + optind + 1, flag, reg, n_threads, level) < 0) ret = 1;
	free(reg);
	free(fn_headers);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebx
leaq 0x10a69(%rip), %rdx     # 0x4528d
callq 0x3210
testl %eax, %eax
js 0x34914
movq $0x0, 0x8(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x18(%rsp)
movq 0x1b795(%rip), %r15     # 0x4ffe0
leaq 0x10a3b(%rip), %r13     # 0x4528d
leaq 0x10807(%rip), %r12     # 0x45060
movq $0x0, 0x20(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
cmpl $0x65, %eax
jle 0x34890
leal -0x66(%rax), %ecx
cmpl $0x8, %ecx
ja 0x348ae
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
orl $0x8, %ebp
jmp 0x348fd
cmpl $0x31, %eax
je 0x348e7
cmpl $0x40, %eax
je 0x348ec
cmpl $0x52, %eax
jne 0x348fd
movq (%r15), %rdi
callq 0x3570
movq %rax, 0x8(%rsp)
jmp 0x348fd
cmpl $0x75, %eax
je 0x348fa
cmpl $0x72, %eax
jne 0x348fd
orl $0x1, %ebp
jmp 0x348fd
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x348fd
movq (%r15), %rdi
callq 0x3570
movq %rax, 0x20(%rsp)
jmp 0x348fd
movq (%r15), %rdi
callq 0x34c0
movq %rax, 0x18(%rsp)
jmp 0x348fd
orl $0x4, %ebp
jmp 0x348fd
movq (%r15), %rdi
callq 0x34c0
movq %rax, (%rsp)
jmp 0x348fd
orl $0x2, %ebp
movl %ebx, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3210
testl %eax, %eax
jns 0x34875
jmp 0x34943
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq $0x0, (%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x1b66e(%rip), %r15     # 0x4ffb8
movl (%r15), %eax
leal 0x2(%rax), %ecx
cmpl %ebx, %ecx
jge 0x349e9
testb $0x8, %bpl
jne 0x34984
movslq %eax, %rcx
movq (%r14,%rcx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x34970
cmpb $0x0, 0x1(%rdi)
je 0x34984
leaq 0xc785(%rip), %rsi      # 0x410fc
callq 0x36f0
testq %rax, %rax
jne 0x349f0
movl (%r15), %eax
movslq %eax, %rcx
leaq (%r14,%rcx,8), %r8
addq $0x8, %r8
movq -0x8(%r8), %rsi
notl %ecx
addl %ebx, %ecx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %r15
movq %r15, %rdx
movl %ebp, %r9d
pushq 0x20(%rsp)
pushq 0x10(%rsp)
movq 0x20(%rsp), %r14
pushq %r14
callq 0x33f31
addq $0x20, %rsp
movl %eax, %ebx
shrl $0x1f, %ebx
movq %r14, %rdi
callq 0x3350
movq %r15, %rdi
callq 0x3350
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5857
jmp 0x349fb
movq %rax, %rdi
movq %r14, %rsi
callq 0x5988
movl $0x1, %ebx
jmp 0x349d8