// File: /workspace/github_c_makefile_star2_O3/aokad[P]sequeeze/seqtk.c
// Function: stk_gc
int stk_gc(int argc, char *argv[])
{
	int c, is_at = 0, min_l = 20;
	double frac = 0.6f, xdropoff = 10.0f, q;
	gzFile fp;
	kseq_t *seq;

	while ((c = getopt(argc, argv, "wx:f:l:")) >= 0) {
		if (c == 'x') xdropoff = atof(optarg);
		else if (c == 'w') is_at = 1;
		else if (c == 'f') frac = atof(optarg);
		else if (c == 'l') min_l = atoi(optarg);
	}
	if (optind + 1 > argc) {
		fprintf(stderr, "Usage: seqtk gc [options] <in.fa>\n");
		fprintf(stderr, "Options:\n");
		fprintf(stderr, "  -w         identify high-AT regions\n");
		fprintf(stderr, "  -f FLOAT   min GC fraction (or AT fraction for -w) [%.2f]\n", frac);
		fprintf(stderr, "  -l INT     min region length to output [%d]\n", min_l);
		fprintf(stderr, "  -x FLOAT   X-dropoff [%.1f]\n", xdropoff);
		return 1;
	}
	q = (1.0f - frac) / frac;

	fp = strcmp(argv[optind], "-")? gzopen(argv[optind], "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) {
		fprintf(stderr, "[E::%s] failed to open the input file/stream.\n", __func__);
		return 1;
	}
	seq = kseq_init(fp);
	while (kseq_read(seq) >= 0) {
		int i, start = 0, max_i = 0, n_hits = 0, start_hits = 0, max_hits = 0;
		double sc = 0., max = 0.;
		for (i = 0; i < seq->seq.l; ++i) {
			int hit;
			c = seq_nt16_table[(int)seq->seq.s[i]];
			if (is_at) hit = (c == 1 || c == 8 || c == 9);
			else hit = (c == 2 || c == 4 || c == 6);
			n_hits += hit;
			if (hit) {
				if (sc == 0) start = i, start_hits = n_hits;
				sc += q;
				if (sc > max) max = sc, max_i = i, max_hits = n_hits;
			} else if (sc > 0) {
				sc += -1.0f;
				if (sc < 0 || max - sc > xdropoff) {
					if (max_i + 1 - start >= min_l)
						printf("%s\t%d\t%d\t%d\n", seq->name.s, start, max_i + 1, max_hits - start_hits + 1);
					sc = max = 0;
					i = max_i;
				}
			}
		}
		if (max > 0. && max_i + 1 - start >= min_l)
			printf("%s\t%d\t%d\t%d\n", seq->name.s, start, max_i + 1, max_hits - start_hits + 1);
	}
	kseq_destroy(seq);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl %edi, %ebp
leaq 0x43d7(%rip), %rdx      # 0xc170
callq 0x2240
testl %eax, %eax
js 0x7e42
movl $0x14, 0x4(%rsp)
movsd 0x32ea(%rip), %xmm0     # 0xb0a0
movsd %xmm0, 0x8(%rsp)
movsd 0x32a4(%rip), %xmm0     # 0xb068
movsd %xmm0, 0x10(%rsp)
xorl %ebx, %ebx
movq 0x8205(%rip), %r12      # 0xffd8
leaq 0x4396(%rip), %r15      # 0xc170
cmpl $0x76, %eax
jg 0x7df8
cmpl $0x66, %eax
je 0x7e13
cmpl $0x6c, %eax
jne 0x7e29
movq (%r12), %rdi
callq 0x2250
movl %eax, 0x4(%rsp)
jmp 0x7e29
cmpl $0x77, %eax
je 0x7e24
cmpl $0x78, %eax
jne 0x7e29
movq (%r12), %rdi
callq 0x20a0
movsd %xmm0, 0x10(%rsp)
jmp 0x7e29
movq (%r12), %rdi
callq 0x20a0
movsd %xmm0, 0x8(%rsp)
jmp 0x7e29
movl $0x1, %ebx
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2240
testl %eax, %eax
jns 0x7dda
testl %ebx, %ebx
sete %r12b
jmp 0x7e69
movb $0x1, %r12b
movsd 0x321b(%rip), %xmm0     # 0xb068
movsd %xmm0, 0x10(%rsp)
movsd 0x3245(%rip), %xmm0     # 0xb0a0
movsd %xmm0, 0x8(%rsp)
movl $0x14, 0x4(%rsp)
movq 0x8160(%rip), %rax      # 0xffd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x80cb
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x7e8e
cmpb $0x0, 0x1(%rdi)
je 0x80a9
leaq 0x3313(%rip), %rsi      # 0xb1a8
callq 0x2220
testq %rax, %rax
je 0x80e2
movq %rax, 0x20(%rsp)
movq %rax, %rdi
callq 0x3edd
movq %rax, %r14
movq %rax, %rdi
callq 0x3f27
testl %eax, %eax
js 0x8086
movsd 0x31ad(%rip), %xmm0     # 0xb078
movsd 0x8(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x828a(%rip), %rsi      # 0x10170
xorpd %xmm3, %xmm3
movq %r14, 0x18(%rsp)
movq 0x30(%r14), %rbx
testq %rbx, %rbx
je 0x806b
movq 0x40(%r14), %r13
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
xorl %edx, %edx
xorpd %xmm4, %xmm4
xorl %r9d, %r9d
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r10d, %r10d
xorl %ebp, %ebp
xorl %eax, %eax
movsd 0x8(%rsp), %xmm2
movl $0x54, %edi
movl $0x302, %r8d            # imm = 0x302
movsbq (%r13,%rcx), %rcx
movzbl (%rcx,%rsi), %ecx
testb %r12b, %r12b
je 0x7f48
cmpl $0x6, %ecx
ja 0x7f8a
btl %ecx, %edi
jb 0x7f53
jmp 0x7f8a
cmpl $0x9, %ecx
ja 0x7f8a
btl %ecx, %r8d
jae 0x7f8a
incl %r14d
ucomisd %xmm3, %xmm4
movl %eax, %ecx
cmovnel %ebp, %ecx
cmovnpl %ecx, %ebp
movl %r14d, %ecx
cmovnel %r15d, %ecx
cmovnpl %ecx, %r15d
addsd %xmm2, %xmm4
ucomisd %xmm0, %xmm4
jbe 0x801f
movl %eax, %r10d
movl %r14d, %r9d
movapd %xmm4, %xmm0
jmp 0x801f
ucomisd %xmm3, %xmm4
jbe 0x801f
addsd 0x310c(%rip), %xmm4     # 0xb0a8
ucomisd %xmm4, %xmm3
ja 0x7fb2
movapd %xmm0, %xmm1
subsd %xmm4, %xmm1
ucomisd 0x10(%rsp), %xmm1
jbe 0x801f
leal 0x1(%r10), %ecx
movl %ecx, %eax
subl %ebp, %eax
xorpd %xmm4, %xmm4
cmpl 0x4(%rsp), %eax
jl 0x8018
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rsi
leal (%rdx,%r9), %r8d
incl %r8d
leaq 0x4283(%rip), %rdi      # 0xc25e
movl %ebp, %edx
xorl %eax, %eax
movq %r9, 0x30(%rsp)
movq %r10, 0x28(%rsp)
callq 0x20f0
xorpd %xmm4, %xmm4
movq 0x28(%rsp), %r10
movq 0x30(%rsp), %r9
movl $0x302, %r8d            # imm = 0x302
xorpd %xmm3, %xmm3
movl $0x54, %edi
leaq 0x815e(%rip), %rsi      # 0x10170
movsd 0x8(%rsp), %xmm2
movl %r10d, %eax
xorpd %xmm0, %xmm0
incl %eax
movl %r15d, %edx
negl %edx
movslq %eax, %rcx
cmpq %rcx, %rbx
ja 0x7f2d
ucomisd %xmm3, %xmm0
movq 0x18(%rsp), %r14
jbe 0x806b
incl %r10d
movl %r10d, %eax
subl %ebp, %eax
cmpl 0x4(%rsp), %eax
jl 0x806b
movq 0x10(%r14), %rsi
subl %r15d, %r9d
incl %r9d
leaq 0x4202(%rip), %rdi      # 0xc25e
movl %ebp, %edx
movl %r10d, %ecx
movl %r9d, %r8d
xorl %eax, %eax
callq 0x20f0
movq %r14, %rdi
callq 0x3f27
xorpd %xmm3, %xmm3
leaq 0x80f2(%rip), %rsi      # 0x10170
testl %eax, %eax
jns 0x7eef
movq %r14, %rdi
callq 0x428d
movq 0x20(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7f18(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x30e9(%rip), %rsi      # 0xb1a8
movl %eax, %edi
callq 0x20b0
jmp 0x7e9a
movsd 0x8(%rsp), %xmm0
movl 0x4(%rsp), %edi
movsd 0x10(%rsp), %xmm1
callq 0x2b6c
jmp 0x80e7
callq 0x2c15
movl $0x1, %eax
jmp 0x809a