// File: /workspace/github_c_makefile_star2_O3/aokad[P]sequeeze/seqtk.c
// Function: stk_fqchk
int stk_fqchk(int argc, char *argv[])
{
	gzFile fp;
	kseq_t *seq;
	int i, c, k, max_len = 0, min_len = 0x7fffffff, max_alloc = 0, offset = 33, n_diffQ = 0, qthres = 20;
	int64_t tot_len = 0, n = 0;
	double perr[94];
	posstat_t all, *pos = 0;

	while ((c = getopt(argc, argv, "q:")) >= 0)
		if (c == 'q') qthres = atoi(optarg);

	if (optind == argc) {
		fprintf(stderr, "Usage: seqtk fqchk [-q %d] <in.fq>\n", qthres);
		fprintf(stderr, "Note: use -q0 to get the distribution of all quality values\n");
		return 1;
	}
	fp = (strcmp(argv[optind], "-") == 0)? gzdopen(fileno(stdin), "r") : gzopen(argv[optind], "r");
	if (fp == 0) {
		fprintf(stderr, "[E::%s] failed to open the input file/stream.\n", __func__);
		return 1;
	}
	seq = kseq_init(fp);
	for (k = 0; k <= 93; ++k)
		perr[k] = pow(10., -.1 * k);
	perr[0] = perr[1] = perr[2] = perr[3] = .5;
	while (kseq_read(seq) >= 0) {
		if (seq->qual.l == 0) continue;
		++n;
		tot_len += seq->seq.l;
		min_len = min_len < seq->seq.l? min_len : seq->seq.l;
		max_len = max_len > seq->seq.l? max_len : seq->seq.l;
		if (max_len > max_alloc) {
			int old_max = max_alloc;
			max_alloc = max_len;
			kroundup32(max_alloc);
			pos = realloc(pos, max_alloc * sizeof(posstat_t));
			memset(&pos[old_max], 0, (max_alloc - old_max) * sizeof(posstat_t));
		}
		for (i = 0; i < seq->qual.l; ++i) {
			int q = seq->qual.s[i] - offset;
			int b = seq_nt6_table[(int)seq->seq.s[i]];
			b = b? b - 1 : 4;
			q = q < 93? q : 93;
			++pos[i].q[q];
			++pos[i].b[b];
		}
	}
	kseq_destroy(seq);
	gzclose(fp);

	memset(&all, 0, sizeof(posstat_t));
	for (i = 0; i < max_len; ++i) {
		for (k = 0; k <= 93; ++k)
			all.q[k] += pos[i].q[k];
		for (k = 0; k <= 4; ++k)
			all.b[k] += pos[i].b[k];
	}
	for (k = n_diffQ = 0; k <= 93; ++k)
		if (all.q[k]) ++n_diffQ;
	printf("min_len: %d; max_len: %d; avg_len: %.2f; %d distinct quality values\n", min_len, max_len, (double)tot_len/n, n_diffQ);
	printf("POS\t#bases\t%%A\t%%C\t%%G\t%%T\t%%N\tavgQ\terrQ");
	if (qthres <= 0) {
		for (k = 0; k <= 93; ++k)
			if (all.q[k] > 0) printf("\t%%Q%d", k);
	} else printf("\t%%low\t%%high");
	putchar('\n');
	fqc_aux(&all, 0, all.q, perr, qthres);
	for (i = 0; i < max_len; ++i)
		fqc_aux(&pos[i], i + 1, all.q, perr, qthres);
	free(pos);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x648, %rsp            # imm = 0x648
movq %rsi, %r14
movl %edi, %ebp
leaq 0x2a91(%rip), %rdx      # 0xb703
callq 0x2240
movl $0x14, %ebx
testl %eax, %eax
js 0x8caf
movq 0x7351(%rip), %r12      # 0xffd8
leaq 0x2a75(%rip), %r15      # 0xb703
cmpl $0x71, %eax
jne 0x8c9e
movq (%r12), %rdi
callq 0x2250
movl %eax, %ebx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2240
testl %eax, %eax
jns 0x8c8e
movq 0x731a(%rip), %rax      # 0xffd0
movslq (%rax), %rax
cmpl %ebp, %eax
je 0x907f
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x8cd4
cmpb $0x0, 0x1(%rdi)
je 0x905d
leaq 0x24cd(%rip), %rsi      # 0xb1a8
callq 0x2220
testq %rax, %rax
je 0x9088
movq %rax, 0x30(%rsp)
movq %rax, %rdi
callq 0x3edd
movq %rax, %r13
xorl %r14d, %r14d
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd 0x23a4(%rip), %xmm1     # 0xb0b0
movsd 0x2354(%rip), %xmm0     # 0xb068
callq 0x20c0
movsd %xmm0, 0x350(%rsp,%r14,8)
incq %r14
cmpq $0x5e, %r14
jne 0x8cfc
movdqa 0x230c(%rip), %xmm0     # 0xb040
movdqa %xmm0, 0x360(%rsp)
movdqa %xmm0, 0x350(%rsp)
xorl %eax, %eax
movl $0x7fffffff, 0x4(%rsp)  # imm = 0x7FFFFFFF
leaq 0x7519(%rip), %rbp      # 0x10270
movl $0x7e, %r14d
movl $0x4, %r12d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %r15
movq %r13, %rdi
callq 0x3f27
testl %eax, %eax
js 0x8eb6
cmpq $0x0, 0x48(%r13)
je 0x8d91
incq 0x18(%rsp)
movq 0x30(%r13), %rax
addq %rax, 0x10(%rsp)
movl 0x4(%rsp), %edx
movl %edx, %ecx
cmpq %rcx, %rax
cmovbel %eax, %edx
movl %edx, 0x4(%rsp)
movq %r15, %rdx
movslq %edx, %rcx
cmpq %rcx, %rax
cmovael %eax, %edx
movq 0x20(%rsp), %r15
cmpl %r15d, %edx
movq %rdx, 0x28(%rsp)
jle 0x8e57
leal -0x1(%rdx), %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %r15d
shrl $0x10, %r15d
orl %eax, %r15d
incl %r15d
imulq $0x318, %r15, %rsi      # imm = 0x318
movq 0x8(%rsp), %rdi
callq 0x2200
movq 0x20(%rsp), %rdx
movl %edx, %ecx
imulq $0x318, %rcx, %rdi      # imm = 0x318
movq %rax, 0x8(%rsp)
addq %rax, %rdi
movl %r15d, %eax
subl %edx, %eax
cltq
imulq $0x318, %rax, %rdx      # imm = 0x318
xorl %esi, %esi
callq 0x2120
cmpq $0x0, 0x48(%r13)
movl %r15d, %eax
jne 0x8e57
jmp 0x8d87
movq 0x40(%r13), %rax
movq 0x58(%r13), %rcx
movq 0x8(%rsp), %rdx
addq $0x2f0, %rdx            # imm = 0x2F0
xorl %esi, %esi
movzbl (%rcx,%rsi), %edi
movsbq (%rax,%rsi), %r8
movzbl (%r8,%rbp), %r8d
cmpb $0x7e, %dil
cmovgel %r14d, %edi
movsbq %dil, %rdi
incq -0x3f8(%rdx,%rdi,8)
leaq -0x1(%r8), %rdi
testq %r8, %r8
cmoveq %r12, %rdi
incq (%rdx,%rdi,8)
incq %rsi
addq $0x318, %rdx            # imm = 0x318
cmpq %rsi, 0x48(%r13)
ja 0x8e6d
movl %r15d, %eax
jmp 0x8d87
movq %r13, %rdi
callq 0x428d
movq 0x30(%rsp), %rdi
callq 0x2040
leaq 0x38(%rsp), %rdi
movl $0x318, %edx            # imm = 0x318
xorl %esi, %esi
callq 0x2120
movl %r15d, %ebp
testl %r15d, %r15d
jle 0x8f22
xorl %eax, %eax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
addq %rsi, 0x38(%rsp,%rdx,8)
incq %rdx
cmpq $0x5e, %rdx
jne 0x8eea
movl $0x5e, %edx
movq (%rcx,%rdx,8), %rsi
addq %rsi, 0x38(%rsp,%rdx,8)
incq %rdx
cmpq $0x63, %rdx
jne 0x8f01
incq %rax
addq $0x318, %rcx            # imm = 0x318
cmpq %rbp, %rax
jne 0x8ee8
pxor %xmm0, %xmm0
xorl %eax, %eax
pcmpeqd %xmm2, %xmm2
xorpd %xmm1, %xmm1
movdqu 0x38(%rsp,%rax,8), %xmm3
pcmpeqd %xmm0, %xmm3
pshufd $0xbd, %xmm3, %xmm4     # xmm4 = xmm3[1,3,3,2]
pshufd $0xe8, %xmm3, %xmm3     # xmm3 = xmm3[0,2,2,3]
pand %xmm4, %xmm3
paddd %xmm3, %xmm1
psubd %xmm2, %xmm1
addq $0x2, %rax
cmpq $0x5e, %rax
jne 0x8f30
pshufd $0x55, %xmm1, %xmm2     # xmm2 = xmm1[1,1,1,1]
paddd %xmm1, %xmm2
xorps %xmm0, %xmm0
cvtsi2sdq 0x10(%rsp), %xmm0
movd %xmm2, %ecx
xorps %xmm1, %xmm1
cvtsi2sdq 0x18(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0x34a5(%rip), %rdi      # 0xc42b
movl 0x4(%rsp), %esi
movl %r15d, %edx
movb $0x1, %al
callq 0x20f0
leaq 0x34d5(%rip), %rdi      # 0xc470
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
jle 0x8fb6
leaq 0x34f3(%rip), %rdi      # 0xc4a0
xorl %eax, %eax
callq 0x20f0
jmp 0x8fde
leaq 0x34dc(%rip), %r12      # 0xc499
xorl %r13d, %r13d
cmpq $0x0, 0x38(%rsp,%r13,8)
jle 0x8fd5
movq %r12, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x20f0
incq %r13
cmpq $0x5e, %r13
jne 0x8fc0
movl $0xa, %edi
callq 0x2060
leaq 0x38(%rsp), %rdi
leaq 0x350(%rsp), %rcx
xorl %esi, %esi
movq %rdi, %rdx
movl %ebx, %r8d
callq 0x9094
testl %r15d, %r15d
jle 0x903f
xorl %r15d, %r15d
leaq 0x38(%rsp), %r12
leaq 0x350(%rsp), %r13
movq 0x8(%rsp), %r14
incq %r15
movq %r14, %rdi
movl %r15d, %esi
movq %r12, %rdx
movq %r13, %rcx
movl %ebx, %r8d
callq 0x9094
addq $0x318, %r14            # imm = 0x318
cmpq %r15, %rbp
jne 0x901c
movq 0x8(%rsp), %rdi
callq 0x2050
xorl %eax, %eax
addq $0x648, %rsp            # imm = 0x648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6f64(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x2135(%rip), %rsi      # 0xb1a8
movl %eax, %edi
callq 0x20b0
jmp 0x8ce0
movl %ebx, %edi
callq 0x2d7d
jmp 0x908d
callq 0x2d5e
movl $0x1, %eax
jmp 0x904b