// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/cut_target.c
// Function: main_cut_target
int main_cut_target(int argc, char *argv[])
{
	int c, tid, pos, n, lasttid = -1, lastpos = -1, l, max_l;
	const bam_pileup1_t *p;
	bam_plp_t plp;
	uint16_t *cns;
	ct_t g;

	memset(&g, 0, sizeof(ct_t));
	g.min_baseQ = 13; g.tid = -1;
	while ((c = getopt(argc, argv, "f:Q:i:o:0:1:2:")) >= 0) {
		switch (c) {
			case 'Q': g.min_baseQ = atoi(optarg); break; // quality cutoff
			case 'i': g_param.p[0][1] = -atoi(optarg); break; // 0->1 transition (in) PENALTY
			case '0': g_param.e[1][0] = atoi(optarg); break; // emission SCORE
			case '1': g_param.e[1][1] = atoi(optarg); break;
			case '2': g_param.e[1][2] = atoi(optarg); break;
			case 'f': g.fai = fai_load(optarg);
				if (g.fai == 0) fprintf(stderr, "[%s] fail to load the fasta index.\n", __func__);
				break;
		}
	}
	if (argc == optind) {
		fprintf(stderr, "Usage: samtools targetcut [-Q minQ] [-i inPen] [-0 em0] [-1 em1] [-2 em2] [-f ref] <in.bam>\n");
		return 1;
	}
	l = max_l = 0; cns = 0;
	g.fp = strcmp(argv[optind], "-")? bam_open(argv[optind], "r") : bam_dopen(fileno(stdin), "r");
	g.h = bam_header_read(g.fp);
	g.em = errmod_init(1 - ERR_DEP);
	plp = bam_plp_init(read_aln, &g);
	while ((p = bam_plp_auto(plp, &tid, &pos, &n)) != 0) {
		if (tid < 0) break;
		if (tid != lasttid) { // change of chromosome
			if (cns) process_cns(g.h, lasttid, l, cns);
			if (max_l < g.h->target_len[tid]) {
				max_l = g.h->target_len[tid];
				kroundup32(max_l);
				cns = realloc(cns, max_l * 2);
			}
			l = g.h->target_len[tid];
			memset(cns, 0, max_l * 2);
			lasttid = tid;
		}
		cns[pos] = gencns(&g, n, p);
		lastpos = pos;
	}
	process_cns(g.h, lasttid, l, cns);
	free(cns);
	bam_header_destroy(g.h);
	bam_plp_destroy(plp);
	bam_close(g.fp);
	if (g.fai) {
		fai_destroy(g.fai); free(g.ref);
	}
	errmod_destroy(g.em);
	free(g.bases);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorpd %xmm0, %xmm0
movupd %xmm0, 0x48(%rsp)
movupd %xmm0, 0x38(%rsp)
movupd %xmm0, 0x28(%rsp)
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
leaq 0x2a731(%rip), %rdx     # 0x41e24
callq 0x3210
movl $0xd, %r14d
testl %eax, %eax
js 0x177c5
xorl %r12d, %r12d
movq 0x388d0(%rip), %r13     # 0x4ffe0
leaq 0x2a70d(%rip), %r15     # 0x41e24
cmpl $0x50, %eax
jg 0x1773c
cmpl $0x30, %eax
je 0x17759
cmpl $0x31, %eax
je 0x1777d
cmpl $0x32, %eax
jne 0x1779f
movq (%r13), %rdi
callq 0x34c0
movl %eax, 0x39662(%rip)     # 0x50d9c
jmp 0x1779f
cmpl $0x69, %eax
je 0x1776a
cmpl $0x66, %eax
je 0x1778e
cmpl $0x51, %eax
jne 0x1779f
movq (%r13), %rdi
callq 0x34c0
movl %eax, %r14d
jmp 0x1779f
movq (%r13), %rdi
callq 0x34c0
movl %eax, 0x3962c(%rip)     # 0x50d94
jmp 0x1779f
movq (%r13), %rdi
callq 0x34c0
negl %eax
movl %eax, 0x39629(%rip)     # 0x50da4
jmp 0x1779f
movq (%r13), %rdi
callq 0x34c0
movl %eax, 0x3960c(%rip)     # 0x50d98
jmp 0x1779f
movq (%r13), %rdi
callq 0x2faa6
testq %rax, %rax
je 0x177b6
movq %rax, %r12
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3210
testl %eax, %eax
jns 0x17717
jmp 0x177c0
callq 0x4218
xorl %r12d, %r12d
jmp 0x1779f
movq %r12, 0x50(%rsp)
movl %r14d, 0x20(%rsp)
movq 0x387e7(%rip), %rax     # 0x4ffb8
movslq (%rax), %rax
cmpl %ebp, %eax
je 0x17c14
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x177ef
cmpb $0x0, 0x1(%rdi)
je 0x17bf2
leaq 0x2e559(%rip), %rsi     # 0x45d4f
callq 0x20308
leaq 0x20(%rsp), %rbx
movq %rax, 0x18(%rbx)
movq %rax, %rdi
callq 0x235fb
movq %rax, 0x20(%rbx)
movss 0x2a608(%rip), %xmm0    # 0x41e20
callq 0x16057
movq %rax, 0x38(%rbx)
leaq 0x3f8(%rip), %rdi       # 0x17c20
movq %rbx, %rsi
callq 0x2b2cc
leaq 0x4(%rsp), %r14
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %rax, 0x68(%rsp)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2bd1d
movq %rax, %r13
testq %rax, %rax
sete %cl
movl (%r14), %eax
testl %eax, %eax
sets %dl
orb %cl, %dl
je 0x17875
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
xorl %r14d, %r14d
jmp 0x17b78
xorl %r14d, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq $0x0, 0x60(%rsp)
xorl %r15d, %r15d
cmpl %r12d, %eax
jne 0x17897
movl %eax, %r12d
jmp 0x1793d
testq %r14, %r14
je 0x178b3
movq 0x40(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movq %r14, %rcx
callq 0x17ca4
movl 0x4(%rsp), %eax
movq 0x40(%rsp), %rcx
movq 0x10(%rcx), %rcx
cltq
movl (%rcx,%rax,4), %r15d
movq 0x60(%rsp), %rax
cmpl %r15d, %eax
jae 0x17926
decl %r15d
movl %r15d, %eax
sarl %eax
orl %r15d, %eax
movl %eax, %ecx
sarl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x10, %eax
orl %ecx, %eax
leal 0x2(,%rax,2), %ecx
incl %eax
movq %rax, 0x60(%rsp)
movslq %ecx, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x3720
movq %rax, %r14
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x4(%rsp), %rcx
movl (%rax,%rcx,4), %r15d
jmp 0x1792b
addl %eax, %eax
movslq %eax, %r12
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3080
movl 0x4(%rsp), %r12d
movl 0x8(%rsp), %ebx
cmpl %ebx, 0x28(%rsp)
jge 0x1798c
leal -0x1(%rbx), %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x28(%rsp)
movq 0x30(%rsp), %rdi
leal 0x2(,%rcx,2), %eax
movslq %eax, %rsi
callq 0x3720
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
testl %ebx, %ebx
jle 0x17b41
movl 0x20(%rsp), %eax
movq 0x30(%rsp), %rdx
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rsi
xorl %edi, %edi
leaq 0x39740(%rip), %rbx     # 0x510f0
testb $0x9, 0x14(%r13,%rdi)
jne 0x17a6b
movq (%r13,%rdi), %rcx
movq 0x8(%rcx), %r8
movq %r8, %r9
shrq $0x30, %r9
shlq $0x2, %r9
addq 0x30(%rcx), %r9
movl %r8d, %r10d
shrl $0x18, %r10d
addq %r9, %r10
movl 0x10(%rcx), %ecx
incl %ecx
sarl %ecx
movslq %ecx, %r9
addq %r10, %r9
movslq 0x8(%r13,%rdi), %rcx
movzbl (%rcx,%r9), %r9d
cmpl %r9d, %eax
jg 0x17a6b
movl %ecx, %r11d
sarl %r11d
movslq %r11d, %r11
movzbl (%r10,%r11), %r10d
shll $0x2, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %r10d
andl $0xf, %r10d
movsbl (%rbx,%r10), %ecx
cmpl $0x3, %ecx
jg 0x17a6b
movl %r8d, %r10d
shrl $0x10, %r10d
movzbl %r10b, %r10d
cmpl %r9d, %r10d
cmovbl %r10d, %r9d
cmpl $0x5, %r9d
movl $0x4, %r10d
cmovbl %r10d, %r9d
cmpl $0x3f, %r9d
movl $0x3f, %r10d
cmovael %r10d, %r9d
shll $0x5, %r9d
shrq $0x20, %r8
andl $0x10, %r8d
orl %r9d, %r8d
orl %ecx, %r8d
movslq %ebp, %rcx
incl %ebp
movw %r8w, (%rdx,%rcx,2)
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0x179b0
testl %ebp, %ebp
je 0x17b3f
movq 0x30(%rsp), %rcx
movq 0x58(%rsp), %rdi
movl %ebp, %esi
movl $0x4, %edx
leaq 0x70(%rsp), %rbx
movq %rbx, %r8
callq 0x163bf
movsd 0x2758a(%rip), %xmm1    # 0x3f030
xorl %ecx, %ecx
xorps %xmm0, %xmm0
cvtss2sd (%rbx), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
leal (%rcx,%rdx,4), %edx
movl %edx, 0x10(%rsp,%rcx,4)
incq %rcx
addq $0x14, %rbx
cmpq $0x4, %rcx
jne 0x17aa8
movl $0x1, %eax
movl $0x2, %ecx
movl 0x10(%rsp,%rax,4), %edx
movq %rcx, %rsi
leal -0x2(%rsi), %edi
movl 0x10(%rsp,%rdi,4), %r8d
cmpl %r8d, %edx
jge 0x17afb
movl %r8d, 0xc(%rsp,%rsi,4)
movl %edx, 0x10(%rsp,%rdi,4)
decq %rsi
cmpq $0x1, %rsi
jg 0x17adc
incq %rax
incq %rcx
cmpq $0x4, %rax
jne 0x17ad5
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
sarl $0x2, %ecx
movl %eax, %edx
sarl $0x2, %edx
subl %edx, %ecx
movl $0xff, %edx
cmpl %edx, %ebp
cmovgel %edx, %ebp
cmpl $0x3f, %ecx
movl $0x3f, %edx
cmovgel %edx, %ecx
shll $0xa, %ecx
andl $0x3, %eax
shll $0x8, %eax
orl %ecx, %eax
orl %ebp, %eax
movl %eax, %ebp
jmp 0x17b41
xorl %ebp, %ebp
movslq 0xc(%rsp), %rax
movw %bp, (%r14,%rax,2)
movq 0x68(%rsp), %rdi
leaq 0x4(%rsp), %rsi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x2bd1d
testq %rax, %rax
je 0x17b78
movq %rax, %r13
movl 0x4(%rsp), %eax
testl %eax, %eax
jns 0x1788a
movq 0x40(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movq %r14, %rcx
callq 0x17ca4
movq %r14, %rdi
callq 0x3350
movq 0x40(%rsp), %rdi
callq 0x23577
movq 0x68(%rsp), %rdi
callq 0x2b378
movq 0x38(%rsp), %rdi
callq 0x21311
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x17bca
callq 0x2f578
movq 0x48(%rsp), %rdi
callq 0x3350
movq 0x58(%rsp), %rdi
callq 0x1637d
movq 0x30(%rsp), %rdi
callq 0x3350
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x383d7(%rip), %rax     # 0x4ffd0
movq (%rax), %rdi
callq 0x3030
leaq 0x2e147(%rip), %rsi     # 0x45d4f
movl %eax, %edi
callq 0x20487
jmp 0x177fb
callq 0x4237
movl $0x1, %eax
jmp 0x17be0