// File: /workspace/github_c_makefile_star2_O1/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 $0xc8, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movabsq $-0xfffffff3, %rax      # imm = 0xFFFFFFFF0000000D
movq %rax, 0x30(%rsp)
leaq 0x299c8(%rip), %rdx     # 0x40de4
callq 0x3210
testl %eax, %eax
js 0x174da
movq 0x37bb0(%rip), %r15     # 0x4efe0
leaq 0x299ad(%rip), %r14     # 0x40de4
cmpl $0x50, %eax
jg 0x1745b
cmpl $0x30, %eax
je 0x17478
cmpl $0x31, %eax
je 0x1749a
cmpl $0x32, %eax
jne 0x174bc
movq (%r15), %rdi
callq 0x34c0
movl %eax, 0x38943(%rip)     # 0x4fd9c
jmp 0x174bc
cmpl $0x69, %eax
je 0x17488
cmpl $0x66, %eax
je 0x174aa
cmpl $0x51, %eax
jne 0x174bc
movq (%r15), %rdi
callq 0x34c0
movl %eax, 0x30(%rsp)
jmp 0x174bc
movq (%r15), %rdi
callq 0x34c0
movl %eax, 0x3890e(%rip)     # 0x4fd94
jmp 0x174bc
movq (%r15), %rdi
callq 0x34c0
negl %eax
movl %eax, 0x3890c(%rip)     # 0x4fda4
jmp 0x174bc
movq (%r15), %rdi
callq 0x34c0
movl %eax, 0x388f0(%rip)     # 0x4fd98
jmp 0x174bc
movq (%r15), %rdi
callq 0x2ee9e
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x174d3
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3210
testl %eax, %eax
jns 0x17437
jmp 0x174da
callq 0x4219
jmp 0x174bc
movq 0x37ad7(%rip), %rax     # 0x4efb8
movslq (%rax), %rax
cmpl %ebp, %eax
je 0x1792d
movq (%rbx,%rax,8), %rbx
leaq 0x27961(%rip), %rsi     # 0x3ee58
movq %rbx, %rdi
callq 0x35a0
testl %eax, %eax
je 0x17514
leaq 0x2d765(%rip), %rsi     # 0x44c6f
movq %rbx, %rdi
callq 0x1fdb8
jmp 0x17531
movq 0x37ab5(%rip), %rax     # 0x4efd0
movq (%rax), %rdi
callq 0x3030
leaq 0x2d745(%rip), %rsi     # 0x44c6f
movl %eax, %edi
callq 0x1ff6b
leaq 0x30(%rsp), %rbx
movq %rax, 0x18(%rbx)
movq %rax, %rdi
callq 0x22efa
movq %rax, 0x20(%rbx)
movss 0x29892(%rip), %xmm0    # 0x40de0
callq 0x15d95
movq %rax, 0x38(%rbx)
leaq 0x3db(%rip), %rdi       # 0x17939
movq %rbx, %rsi
callq 0x2a940
leaq 0xc(%rsp), %r14
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rax, 0x78(%rsp)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2b372
movq %rax, %r13
testq %rax, %rax
sete %cl
movl (%r14), %eax
testl %eax, %eax
sets %dl
orb %cl, %dl
je 0x175b1
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq $0x0, 0x18(%rsp)
xorl %r14d, %r14d
jmp 0x178b1
xorl %r14d, %r14d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
leaq 0x38b2f(%rip), %rbx     # 0x500f0
xorl %r12d, %r12d
movq $0x0, 0x18(%rsp)
cmpl %r15d, %eax
je 0x17672
testq %r14, %r14
je 0x175f0
movq 0x50(%rsp), %rdi
movl %r15d, %esi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
callq 0x179bb
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0xc(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl %eax, %r12d
jae 0x17646
decl %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, %r12d
sarl $0x10, %r12d
orl %eax, %r12d
leal 0x2(,%r12,2), %eax
incl %r12d
movslq %eax, %rsi
movq %r14, %rdi
callq 0x3720
movq %rax, %r14
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0xc(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, 0x18(%rsp)
leal (%r12,%r12), %eax
movslq %eax, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x3080
movl 0xc(%rsp), %r15d
movl 0x10(%rsp), %ebp
cmpl %ebp, 0x38(%rsp)
jge 0x176c1
leal -0x1(%rbp), %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, 0x38(%rsp)
movq 0x40(%rsp), %rdi
leal 0x2(,%rcx,2), %eax
movslq %eax, %rsi
callq 0x3720
movq %rax, 0x40(%rsp)
testl %ebp, %ebp
jle 0x177af
movl 0x30(%rsp), %eax
movq 0x40(%rsp), %rdx
shlq $0x3, %rbp
leaq (,%rbp,2), %rsi
addq %rbp, %rsi
xorl %edi, %edi
xorl %ebp, %ebp
testb $0x9, 0x14(%r13,%rdi)
jne 0x177a0
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 0x177a0
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 0x177a0
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 0x176e5
jmp 0x177b1
xorl %ebp, %ebp
testl %ebp, %ebp
je 0x17878
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %rdi
movl %ebp, %esi
movl $0x4, %edx
leaq 0x80(%rsp), %r13
movq %r13, %r8
callq 0x160f4
movsd 0x2683e(%rip), %xmm1    # 0x3e020
xorl %ecx, %ecx
xorps %xmm0, %xmm0
cvtss2sd (%r13), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
leal (%rcx,%rdx,4), %edx
movl %edx, 0x20(%rsp,%rcx,4)
incq %rcx
addq $0x14, %r13
cmpq $0x4, %rcx
jne 0x177e4
movl $0x1, %eax
movl $0x2, %ecx
movl %ecx, %edx
movl %edx, %esi
leal -0x1(%rsi), %edx
movl 0x20(%rsp,%rdx,4), %edi
addl $-0x2, %esi
movl 0x20(%rsp,%rsi,4), %r8d
cmpl %r8d, %edi
jge 0x17839
movl %r8d, 0x20(%rsp,%rdx,4)
movl %edi, 0x20(%rsp,%rsi,4)
cmpl $0x1, %edx
jg 0x17815
incl %eax
incl %ecx
cmpl $0x4, %eax
jne 0x17813
movl 0x20(%rsp), %eax
movl 0x24(%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
jmp 0x1787a
xorl %eax, %eax
movslq 0x14(%rsp), %rcx
movw %ax, (%r14,%rcx,2)
movq 0x78(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x2b372
testq %rax, %rax
je 0x178b1
movq %rax, %r13
movl 0xc(%rsp), %eax
testl %eax, %eax
jns 0x175cd
movq 0x50(%rsp), %rdi
movl %r15d, %esi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
callq 0x179bb
movq %r14, %rdi
callq 0x3350
movq 0x50(%rsp), %rdi
callq 0x22e78
movq 0x78(%rsp), %rdi
callq 0x2aa34
movq 0x48(%rsp), %rdi
callq 0x20aae
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x17905
callq 0x2e970
movq 0x58(%rsp), %rdi
callq 0x3350
movq 0x68(%rsp), %rdi
callq 0x160b2
movq 0x40(%rsp), %rdi
callq 0x3350
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4238
movl $0x1, %eax
jmp 0x1791b