// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebp
movl $0x0, 0x4(%rsp)
movsd 0x278d(%rip), %xmm0     # 0x9068
movsd %xmm0, 0x10(%rsp)
movsd 0x27b7(%rip), %xmm0     # 0x90a0
movsd %xmm0, 0x8(%rsp)
pushq $0x14
popq %rax
movl %eax, (%rsp)
leaq 0x3874(%rip), %r15      # 0xa170
movq 0x76d5(%rip), %rbx      # 0xdfd8
pushq $0x1
popq %r12
movl %ebp, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2240
testl %eax, %eax
js 0x6960
cmpl $0x66, %eax
je 0x693c
cmpl $0x6c, %eax
je 0x694c
cmpl $0x77, %eax
je 0x6959
cmpl $0x78, %eax
jne 0x6907
movq (%rbx), %rdi
callq 0x20a0
movsd %xmm0, 0x10(%rsp)
jmp 0x6907
movq (%rbx), %rdi
callq 0x20a0
movsd %xmm0, 0x8(%rsp)
jmp 0x6907
movq (%rbx), %rdi
callq 0x2250
movl %eax, (%rsp)
jmp 0x6907
movl %r12d, 0x4(%rsp)
jmp 0x6907
movq 0x7669(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x6b93
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x6985
cmpb $0x0, 0x1(%rdi)
je 0x6b71
leaq 0x281c(%rip), %rsi      # 0x91a8
callq 0x2220
testq %rax, %rax
je 0x6c21
movsd 0x26d6(%rip), %xmm0     # 0x9078
movsd 0x8(%rsp), %xmm1
subsd %xmm1, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, %rdi
callq 0x3102
movq %rax, %r15
movq %r15, %rdi
callq 0x312e
testl %eax, %eax
js 0x6b4e
movq 0x30(%r15), %rbx
xorpd %xmm4, %xmm4
xorl %eax, %eax
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r8d, %r8d
xorpd %xmm0, %xmm0
movl 0x4(%rsp), %esi
movsd 0x18(%rsp), %xmm2
leaq 0x776d(%rip), %rdi      # 0xe170
xorpd %xmm3, %xmm3
movslq %eax, %rcx
cmpq %rcx, %rbx
jbe 0x6b0f
movq 0x40(%r15), %rdx
movsbq (%rdx,%rcx), %rcx
movzbl (%rcx,%rdi), %ecx
testl %esi, %esi
je 0x6a30
cmpl $0x9, %ecx
ja 0x6a74
movl $0x302, %edx            # imm = 0x302
jmp 0x6a38
cmpl $0x6, %ecx
ja 0x6a74
pushq $0x54
popq %rdx
btl %ecx, %edx
jae 0x6a74
incl %ebp
ucomisd %xmm3, %xmm4
movl %eax, %ecx
cmovnel %r14d, %ecx
cmovpl %r14d, %ecx
movl %ebp, %edx
cmovnel %r12d, %edx
cmovpl %r12d, %edx
addsd %xmm2, %xmm4
ucomisd %xmm0, %xmm4
jbe 0x6b02
movl %eax, %r13d
movl %ebp, %r8d
movapd %xmm4, %xmm0
jmp 0x6b02
ucomisd %xmm3, %xmm4
jbe 0x6a98
addsd 0x2626(%rip), %xmm4     # 0x90a8
ucomisd %xmm4, %xmm3
ja 0x6aa0
movapd %xmm0, %xmm1
subsd %xmm4, %xmm1
ucomisd 0x10(%rsp), %xmm1
ja 0x6aa0
movl %r14d, %ecx
movl %r12d, %edx
jmp 0x6b02
leal 0x1(%r13), %ecx
movl %ecx, %eax
subl %r14d, %eax
xorpd %xmm4, %xmm4
cmpl (%rsp), %eax
jl 0x6af5
movq 0x10(%r15), %rsi
movl %r8d, 0x8(%rsp)
movl 0x8(%rsp), %r8d
subl %r12d, %r8d
incl %r8d
leaq 0x3791(%rip), %rdi      # 0xa25e
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
xorpd %xmm4, %xmm4
movl 0x8(%rsp), %r8d
xorpd %xmm3, %xmm3
leaq 0x7685(%rip), %rdi      # 0xe170
movsd 0x18(%rsp), %xmm2
movl 0x4(%rsp), %esi
movl %r13d, %eax
movl %r14d, %ecx
movl %r12d, %edx
xorpd %xmm0, %xmm0
incl %eax
movl %ecx, %r14d
movl %edx, %r12d
jmp 0x6a07
ucomisd %xmm3, %xmm0
jbe 0x69c6
incl %r13d
movl %r13d, %eax
subl %r14d, %eax
cmpl (%rsp), %eax
jl 0x69c6
movq 0x10(%r15), %rsi
subl %r12d, %r8d
incl %r8d
leaq 0x3722(%rip), %rdi      # 0xa25e
movl %r14d, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x20f0
jmp 0x69c6
movq %r15, %rdi
callq 0x3329
movq 0x20(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7450(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x2621(%rip), %rsi      # 0x91a8
movl %eax, %edi
callq 0x20b0
jmp 0x6991
movq 0x745e(%rip), %rbx      # 0xdff8
movq (%rbx), %rcx
leaq 0x35d4(%rip), %rdi      # 0xa178
pushq $0x22
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x2260
movq (%rbx), %rcx
leaq 0x35de(%rip), %rdi      # 0xa19b
pushq $0x9
popq %rsi
movq %r14, %rdx
callq 0x2260
movq (%rbx), %rcx
leaq 0x35d3(%rip), %rdi      # 0xa1a5
pushq $0x26
popq %rsi
movq %r14, %rdx
callq 0x2260
movq (%rbx), %rdi
leaq 0x35e5(%rip), %rsi      # 0xa1cc
movsd 0x8(%rsp), %xmm0
movb $0x1, %al
callq 0x2190
movq (%rbx), %rdi
leaq 0x360b(%rip), %rsi      # 0xa209
movl (%rsp), %edx
xorl %eax, %eax
callq 0x2190
movq (%rbx), %rdi
leaq 0x3626(%rip), %rsi      # 0xa238
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x2190
jmp 0x6c40
movq 0x73d0(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x276f(%rip), %rsi      # 0x93a1
leaq 0x361e(%rip), %rdx      # 0xa257
xorl %eax, %eax
callq 0x2190
pushq $0x1
popq %rax
jmp 0x6b62