// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movl %edi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl 0x40(%rsp), %edi
movq 0x38(%rsp), %rsi
leaq 0xf3caf(%rip), %rdx     # 0x57b3d6
callq 0x30020
movl %eax, 0x34(%rsp)
cmpl $0x0, %eax
jl 0x4877ce
movl 0x34(%rsp), %eax
addl $-0x31, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x44, %eax
ja 0x4877c9
movq 0x8(%rsp), %rax
leaq 0xf3984(%rip), %rcx     # 0x57b0dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2c(%rsp), %eax
orl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x4877c9
movl 0x2c(%rsp), %eax
orl $0x8, %eax
movl %eax, 0x2c(%rsp)
jmp 0x4877c9
movq 0x1747de(%rip), %rax    # 0x5fbf60
movq (%rax), %rdi
callq 0x326e0
movq %rax, 0x20(%rsp)
jmp 0x4877c9
movl $0x1, 0x30(%rsp)
jmp 0x4877c9
movl 0x2c(%rsp), %eax
orl $0x4, %eax
movl %eax, 0x2c(%rsp)
jmp 0x4877c9
movl 0x2c(%rsp), %eax
orl $0x2, %eax
movl %eax, 0x2c(%rsp)
jmp 0x4877c9
movq 0x1747a4(%rip), %rax    # 0x5fbf60
movq (%rax), %rdi
callq 0x326e0
movq %rax, 0x18(%rsp)
jmp 0x487717
movq 0x174743(%rip), %rax    # 0x5fbf18
movl (%rax), %eax
addl $0x2, %eax
cmpl 0x40(%rsp), %eax
jl 0x487911
movq 0x1747dd(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xe6852(%rip), %rsi     # 0x56e047
movb $0x0, %al
callq 0x33960
movq 0x1747c5(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3bd3(%rip), %rsi     # 0x57b3e0
movb $0x0, %al
callq 0x33960
movq 0x1747ad(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3c0c(%rip), %rsi     # 0x57b431
movb $0x0, %al
callq 0x33960
movq 0x174795(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3c1a(%rip), %rsi     # 0x57b457
movb $0x0, %al
callq 0x33960
movq 0x17477d(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3c3e(%rip), %rsi     # 0x57b493
movb $0x0, %al
callq 0x33960
movq 0x174765(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3c51(%rip), %rsi     # 0x57b4be
movb $0x0, %al
callq 0x33960
movq 0x17474d(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3c6e(%rip), %rsi     # 0x57b4f3
movb $0x0, %al
callq 0x33960
movq 0x174735(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3c7a(%rip), %rsi     # 0x57b517
movb $0x0, %al
callq 0x33960
movq 0x17471d(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3ca2(%rip), %rsi     # 0x57b557
movb $0x0, %al
callq 0x33960
movq 0x174705(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3ccd(%rip), %rsi     # 0x57b59a
movb $0x0, %al
callq 0x33960
movq 0x1746ed(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3d09(%rip), %rsi     # 0x57b5ee
movb $0x0, %al
callq 0x33960
movq 0x1746d5(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf3d49(%rip), %rsi     # 0x57b646
movb $0x0, %al
callq 0x33960
movl $0x1, 0x44(%rsp)
jmp 0x487a3e
movl 0x2c(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x4879bc
movq 0x38(%rsp), %rax
movq 0x1745eb(%rip), %rcx    # 0x5fbf18
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xefc94(%rip), %rsi     # 0x5775cf
callq 0x32950
cmpl $0x0, %eax
je 0x4879bc
movq 0x38(%rsp), %rax
movq 0x1745c7(%rip), %rcx    # 0x5fbf18
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xc5d73(%rip), %rsi     # 0x54d6d2
callq 0x33670
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x4879ba
movq 0x10(%rsp), %rdi
callq 0x330b0
movq 0x174646(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0x38(%rsp), %rax
movq 0x174587(%rip), %rcx    # 0x5fbf18
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xf3cd1(%rip), %rsi     # 0x57b670
leaq 0xf3d09(%rip), %rdx     # 0x57b6af
movb $0x0, %al
callq 0x33960
movl $0x1, 0x44(%rsp)
jmp 0x487a3e
jmp 0x4879bc
movl 0x30(%rsp), %edi
movq 0x38(%rsp), %rax
movq 0x17454c(%rip), %rcx    # 0x5fbf18
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x20(%rsp), %rdx
movl 0x40(%rsp), %ecx
movq 0x174535(%rip), %rax    # 0x5fbf18
subl (%rax), %ecx
subl $0x1, %ecx
movq 0x38(%rsp), %r8
movq 0x174524(%rip), %rax    # 0x5fbf18
movslq (%rax), %rax
shlq $0x3, %rax
addq %rax, %r8
addq $0x8, %r8
movl 0x2c(%rsp), %r9d
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
callq 0x4867c0
cmpl $0x0, %eax
jge 0x487a22
movl $0x1, 0x28(%rsp)
movq 0x18(%rsp), %rdi
callq 0x34078
movq 0x20(%rsp), %rdi
callq 0x34078
movl 0x28(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw (%rax,%rax)