// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x6a0, %rsp            # imm = 0x6A0
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x7fffffff, -0x34(%rbp) # imm = 0x7FFFFFFF
movl $0x0, -0x38(%rbp)
movl $0x21, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x14, -0x44(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x670(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x3c66(%rip), %rdx      # 0xd7db
callq 0x2240
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
jl 0x9b9c
cmpl $0x71, -0x28(%rbp)
jne 0x9b9a
movq 0x7449(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x2250
movl %eax, -0x44(%rbp)
jmp 0x9b67
movq 0x742d(%rip), %rax      # 0x10fd0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x9be9
movq 0x7447(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movl -0x44(%rbp), %edx
leaq 0x48da(%rip), %rsi      # 0xe498
movb $0x0, %al
callq 0x2190
movq 0x742c(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x48e6(%rip), %rsi      # 0xe4bc
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0xa1c7
movq -0x10(%rbp), %rax
movq 0x73dc(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4894(%rip), %rsi      # 0xe496
callq 0x2170
cmpl $0x0, %eax
jne 0x9c32
movq 0x73b5(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
leaq 0x365c(%rip), %rsi      # 0xd280
callq 0x20b0
movq %rax, -0x688(%rbp)
jmp 0x9c57
movq -0x10(%rbp), %rax
movq 0x7393(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3635(%rip), %rsi      # 0xd280
callq 0x2220
movq %rax, -0x688(%rbp)
movq -0x688(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x9c94
movq 0x7388(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x37ff(%rip), %rsi      # 0xd479
leaq 0x4878(%rip), %rdx      # 0xe4f9
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0xa1c7
movq -0x18(%rbp), %rdi
callq 0x38f0
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x5d, -0x2c(%rbp)
jg 0x9ce4
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd 0x3395(%rip), %xmm1     # 0xd050
mulsd %xmm0, %xmm1
movsd 0x3349(%rip), %xmm0     # 0xd010
callq 0x20c0
movslq -0x2c(%rbp), %rax
movsd %xmm0, -0x350(%rbp,%rax,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x9ca8
movsd 0x332c(%rip), %xmm0     # 0xd018
movsd %xmm0, -0x338(%rbp)
movsd 0x331c(%rip), %xmm0     # 0xd018
movsd %xmm0, -0x340(%rbp)
movsd 0x330c(%rip), %xmm0     # 0xd018
movsd %xmm0, -0x348(%rbp)
movsd 0x32fc(%rip), %xmm0     # 0xd018
movsd %xmm0, -0x350(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3930
cmpl $0x0, %eax
jl 0x9fa2
movq -0x20(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x9d43
jmp 0x9d24
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movslq -0x34(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x9d7a
movslq -0x34(%rbp), %rax
movq %rax, -0x690(%rbp)
jmp 0x9d89
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x690(%rbp)
movq -0x690(%rbp), %rax
movl %eax, -0x34(%rbp)
movslq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jbe 0x9dae
movslq -0x30(%rbp), %rax
movq %rax, -0x698(%rbp)
jmp 0x9dbd
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x698(%rbp)
movq -0x698(%rbp), %rax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x9e7e
movl -0x38(%rbp), %eax
movl %eax, -0x674(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
sarl %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
sarl $0x2, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
sarl $0x4, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
sarl $0x8, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
sarl $0x10, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x670(%rbp), %rdi
movslq -0x38(%rbp), %rax
imulq $0x318, %rax, %rsi      # imm = 0x318
callq 0x2200
movq %rax, -0x670(%rbp)
movq -0x670(%rbp), %rdi
movslq -0x674(%rbp), %rax
imulq $0x318, %rax, %rax      # imm = 0x318
addq %rax, %rdi
movl -0x38(%rbp), %eax
subl -0x674(%rbp), %eax
cltq
imulq $0x318, %rax, %rdx      # imm = 0x318
xorl %esi, %esi
callq 0x2120
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x9f9d
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x678(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movslq %eax, %rcx
leaq 0x7396(%rip), %rax      # 0x11260
movzbl (%rax,%rcx), %eax
movl %eax, -0x67c(%rbp)
cmpl $0x0, -0x67c(%rbp)
je 0x9eee
movl -0x67c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x69c(%rbp)
jmp 0x9efb
movl $0x4, %eax
movl %eax, -0x69c(%rbp)
jmp 0x9efb
movl -0x69c(%rbp), %eax
movl %eax, -0x67c(%rbp)
cmpl $0x5d, -0x678(%rbp)
jge 0x9f1e
movl -0x678(%rbp), %eax
movl %eax, -0x6a0(%rbp)
jmp 0x9f2b
movl $0x5d, %eax
movl %eax, -0x6a0(%rbp)
jmp 0x9f2b
movl -0x6a0(%rbp), %eax
movl %eax, -0x678(%rbp)
movq -0x670(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x318, %rcx, %rcx      # imm = 0x318
addq %rcx, %rax
movslq -0x678(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x670(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x318, %rcx, %rcx      # imm = 0x318
addq %rcx, %rax
movslq -0x67c(%rbp), %rcx
movq 0x2f0(%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, 0x2f0(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x9e85
jmp 0x9d24
movq -0x20(%rbp), %rdi
callq 0x3d40
movq -0x18(%rbp), %rdi
callq 0x2030
leaq -0x668(%rbp), %rdi
xorl %esi, %esi
movl $0x318, %edx            # imm = 0x318
callq 0x2120
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0xa080
movl $0x0, -0x2c(%rbp)
cmpl $0x5d, -0x2c(%rbp)
jg 0xa023
movq -0x670(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x318, %rcx, %rcx      # imm = 0x318
addq %rcx, %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movslq -0x2c(%rbp), %rax
addq -0x668(%rbp,%rax,8), %rcx
movq %rcx, -0x668(%rbp,%rax,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x9fe1
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jg 0xa070
movq -0x670(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x318, %rcx, %rcx      # imm = 0x318
addq %rcx, %rax
movslq -0x2c(%rbp), %rcx
movq 0x2f0(%rax,%rcx,8), %rcx
movslq -0x2c(%rbp), %rax
addq -0x378(%rbp,%rax,8), %rcx
movq %rcx, -0x378(%rbp,%rax,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa02a
jmp 0xa072
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x9fce
movl $0x0, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x5d, -0x2c(%rbp)
jg 0xa0b9
movslq -0x2c(%rbp), %rax
cmpq $0x0, -0x668(%rbp,%rax,8)
je 0xa0ac
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xa0ae
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa08e
movl -0x34(%rbp), %esi
movl -0x30(%rbp), %edx
cvtsi2sdq -0x50(%rbp), %xmm0
cvtsi2sdq -0x58(%rbp), %xmm1
divsd %xmm1, %xmm0
movl -0x40(%rbp), %ecx
leaq 0x442a(%rip), %rdi      # 0xe503
movb $0x1, %al
callq 0x20f0
leaq 0x4461(%rip), %rdi      # 0xe548
movb $0x0, %al
callq 0x20f0
cmpl $0x0, -0x44(%rbp)
jg 0xa130
movl $0x0, -0x2c(%rbp)
cmpl $0x5d, -0x2c(%rbp)
jg 0xa12e
movslq -0x2c(%rbp), %rax
cmpq $0x0, -0x668(%rbp,%rax,8)
jle 0xa121
movl -0x2c(%rbp), %esi
leaq 0x4457(%rip), %rdi      # 0xe571
movb $0x0, %al
callq 0x20f0
jmp 0xa123
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa0fb
jmp 0xa13e
leaq 0x4441(%rip), %rdi      # 0xe578
movb $0x0, %al
callq 0x20f0
movl $0xa, %edi
callq 0x2050
leaq -0x668(%rbp), %rdx
leaq -0x350(%rbp), %rcx
movl -0x44(%rbp), %r8d
leaq -0x668(%rbp), %rdi
xorl %esi, %esi
callq 0xa1e0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0xa1b4
movq -0x670(%rbp), %rdi
movslq -0x24(%rbp), %rax
imulq $0x318, %rax, %rax      # imm = 0x318
addq %rax, %rdi
movl -0x24(%rbp), %esi
addl $0x1, %esi
leaq -0x668(%rbp), %rdx
leaq -0x350(%rbp), %rcx
movl -0x44(%rbp), %r8d
callq 0xa1e0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa16f
movq -0x670(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x6a0, %rsp            # imm = 0x6A0
popq %rbp
retq
nopw %cs:(%rax,%rax)