// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_sort.c
// Function: bam_sort
int bam_sort(int argc, char *argv[])
{
	size_t max_mem = 768<<20; // 512MB
	int c, is_by_qname = 0, is_stdout = 0, n_threads = 0, level = -1, full_path = 0;
	while ((c = getopt(argc, argv, "fnom:@:l:")) >= 0) {
		switch (c) {
		case 'f': full_path = 1; break;
		case 'o': is_stdout = 1; break;
		case 'n': is_by_qname = 1; break;
		case 'm': {
				char *q;
				max_mem = strtol(optarg, &q, 0);
				if (*q == 'k' || *q == 'K') max_mem <<= 10;
				else if (*q == 'm' || *q == 'M') max_mem <<= 20;
				else if (*q == 'g' || *q == 'G') max_mem <<= 30;
				break;
			}
		case '@': n_threads = atoi(optarg); break;
		case 'l': level = atoi(optarg); break;
		}
	}
	if (optind + 2 > argc) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   samtools sort [options] <in.bam> <out.prefix>\n\n");
		fprintf(stderr, "Options: -n        sort by read name\n");
		fprintf(stderr, "         -f        use <out.prefix> as full file name instead of prefix\n");
		fprintf(stderr, "         -o        final output to stdout\n");
		fprintf(stderr, "         -l INT    compression level, from 0 to 9 [-1]\n");
		fprintf(stderr, "         -@ INT    number of sorting and compression threads [1]\n");
		fprintf(stderr, "         -m INT    max memory per thread; suffix K/M/G recognized [768M]\n");
		fprintf(stderr, "\n");
		return 1;
	}
	bam_sort_core_ext(is_by_qname, argv[optind], argv[optind+1], max_mem, is_stdout, n_threads, level, full_path);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xf07a(%rip), %rdx      # 0x45651
callq 0x3210
testl %eax, %eax
js 0x3670a
movl $0x30000000, %r15d      # imm = 0x30000000
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0xf04d(%rip), %r14      # 0x45651
leaq 0xea79(%rip), %r12      # 0x45084
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
leal -0x66(%rax), %ecx
cmpl $0x9, %ecx
ja 0x3663e
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x366f3
cmpl $0x40, %eax
jne 0x366f3
movq 0x19992(%rip), %rax     # 0x4ffe0
movq (%rax), %rdi
callq 0x34c0
movl %eax, 0x8(%rsp)
jmp 0x366f3
movl $0x1, 0xc(%rsp)
jmp 0x366f3
movq 0x1996d(%rip), %rax     # 0x4ffe0
movq (%rax), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x34b0
movq %rax, %r15
movq 0x20(%rsp), %rax
movzbl (%rax), %eax
addl $-0x47, %eax
cmpl $0x26, %eax
ja 0x366f3
movabsq $0x100000001, %rcx      # imm = 0x100000001
btq %rax, %rcx
jb 0x366ef
movabsq $0x1000000010, %rcx     # imm = 0x1000000010
btq %rax, %rcx
jb 0x366e9
movabsq $0x4000000040, %rcx     # imm = 0x4000000040
btq %rax, %rcx
jae 0x366f3
shlq $0x14, %r15
jmp 0x366f3
movq 0x1990e(%rip), %rax     # 0x4ffe0
movq (%rax), %rdi
callq 0x34c0
movq %rax, 0x18(%rsp)
jmp 0x366f3
movl $0x1, %r13d
jmp 0x366f3
shlq $0xa, %r15
jmp 0x366f3
shlq $0x1e, %r15
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3210
testl %eax, %eax
jns 0x3661e
jmp 0x36736
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movl $0x30000000, %r15d      # imm = 0x30000000
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x1987b(%rip), %rax     # 0x4ffb8
movslq (%rax), %rax
leal 0x2(%rax), %ecx
cmpl %ebp, %ecx
jg 0x36782
movq (%rbx,%rax,8), %rsi
movq 0x8(%rbx,%rax,8), %rdx
movl %r13d, %edi
movq %r15, %rcx
movl 0xc(%rsp), %r8d
movl 0x8(%rsp), %r9d
pushq 0x10(%rsp)
pushq 0x20(%rsp)
callq 0x35de7
addq $0x10, %rsp
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x59db
movl $0x1, %eax
jmp 0x36773