// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movl %edi, %ebp
leaq 0x1029f(%rip), %rdx     # 0x441ad
callq 0x3210
testl %eax, %eax
js 0x34003
movq $0x0, 0x8(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x18(%rsp)
movq 0x1b0ab(%rip), %r14     # 0x4efe0
leaq 0x10271(%rip), %r12     # 0x441ad
leaq 0x1003d(%rip), %r15     # 0x43f80
movq $0x0, 0x20(%rsp)
movq $0x0, (%rsp)
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
cmpl $0x65, %eax
jle 0x33f7c
leal -0x66(%rax), %ecx
cmpl $0x8, %ecx
ja 0x33f9a
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
orl $0x8, %r13d
jmp 0x33fec
cmpl $0x31, %eax
je 0x33fd4
cmpl $0x40, %eax
je 0x33fda
cmpl $0x52, %eax
jne 0x33fec
movq (%r14), %rdi
callq 0x3570
movq %rax, 0x8(%rsp)
jmp 0x33fec
cmpl $0x75, %eax
je 0x33fe8
cmpl $0x72, %eax
jne 0x33fec
orl $0x1, %r13d
jmp 0x33fec
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x33fec
movq (%r14), %rdi
callq 0x3570
movq %rax, 0x20(%rsp)
jmp 0x33fec
movq (%r14), %rdi
callq 0x34c0
movq %rax, 0x18(%rsp)
jmp 0x33fec
orl $0x4, %r13d
jmp 0x33fec
movq (%r14), %rdi
callq 0x34c0
movq %rax, (%rsp)
jmp 0x33fec
orl $0x2, %r13d
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3210
testl %eax, %eax
jns 0x33f60
jmp 0x34033
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
movq $0x0, (%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x1af7e(%rip), %r14     # 0x4efb8
movslq (%r14), %rax
leal 0x2(%rax), %ecx
cmpl %ebp, %ecx
jge 0x340de
testb $0x8, %r13b
jne 0x34079
movq (%rbx,%rax,8), %r12
leaq 0xadff(%rip), %rsi      # 0x3ee58
movq %r12, %rdi
callq 0x35a0
testl %eax, %eax
je 0x34079
leaq 0xc050(%rip), %rsi      # 0x400bc
movq %r12, %rdi
callq 0x36f0
testq %rax, %rax
jne 0x340e5
movslq (%r14), %rcx
leaq (%rbx,%rcx,8), %r8
addq $0x8, %r8
movq -0x8(%r8), %rsi
notl %ecx
addl %ebp, %ecx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %r15
movq %r15, %rdx
movl %r13d, %r9d
pushq 0x20(%rsp)
pushq 0x10(%rsp)
movq 0x20(%rsp), %r14
pushq %r14
callq 0x3363c
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 0x55f6
jmp 0x340f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5727
movl $0x1, %ebx
jmp 0x340cd