// File: /workspace/github_c_makefile_star2_O2/aokad[P]sequeeze/seqtk.c
// Function: stk_hety
int stk_hety(int argc, char *argv[])
{
	gzFile fp;
	kseq_t *seq;
	int l, c, win_size = 50000, n_start = 5, win_step, is_lower_mask = 0;
	char *buf;
	uint32_t cnt[3];
	if (argc == 1) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   seqtk hety [options] <in.fa>\n\n");
		fprintf(stderr, "Options: -w INT   window size [%d]\n", win_size);
		fprintf(stderr, "         -t INT   # start positions in a window [%d]\n", n_start);
		fprintf(stderr, "         -m       treat lowercases as masked\n");
		fprintf(stderr, "\n");
		return 1;
	}
	while ((c = getopt(argc, argv, "w:t:m")) >= 0) {
		switch (c) {
		case 'w': win_size = atoi(optarg); break;
		case 't': n_start = atoi(optarg); break;
		case 'm': is_lower_mask = 1; break;
		}
	}
	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);
	win_step = win_size / n_start;
	buf = calloc(win_size, 1);
	while ((l = kseq_read(seq)) >= 0) {
		int x, i, y, z, next = 0;
		cnt[0] = cnt[1] = cnt[2] = 0;
		for (i = 0; i <= l; ++i) {
			if ((i >= win_size && i % win_step == 0) || i == l) {
				if (i == l && l >= win_size) {
					for (y = l - win_size; y < next; ++y) --cnt[(int)buf[y % win_size]];
				}
				if (cnt[1] + cnt[2] > 0)
					printf("%s\t%d\t%d\t%.2lf\t%d\t%d\n", seq->name.s, next, i,
						   (double)cnt[2] / (cnt[1] + cnt[2]) * win_size, cnt[1] + cnt[2], cnt[2]);
				next = i;
			}
			if (i < l) {
				y = i % win_size;
				c = seq->seq.s[i];
				if (is_lower_mask && islower(c)) c = 'N';
				c = seq_nt16_table[c];
				x = bitcnt_table[c];
				if (i >= win_size) --cnt[(int)buf[y]];
				buf[y] = z = x > 2? 0 : x == 2? 2 : 1;
				++cnt[z];
			}
		}
	}
	free(buf);
	kseq_destroy(seq);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
cmpl $0x1, %edi
je 0x3c4d
movq %rsi, %r14
movl %edi, %r15d
movl $0xc350, %ebx           # imm = 0xC350
movl $0x0, 0x4(%rsp)
pushq $0x5
popq %rbp
leaq 0x5ba3(%rip), %r12      # 0x9562
movq 0xa612(%rip), %r13      # 0xdfd8
movl %r15d, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
js 0x3a0a
cmpl $0x6d, %eax
je 0x39f4
cmpl $0x74, %eax
je 0x39fd
cmpl $0x77, %eax
jne 0x39c6
movq (%r13), %rdi
callq 0x2250
movl %eax, %ebx
jmp 0x39c6
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
jmp 0x39c6
movq (%r13), %rdi
callq 0x2250
movl %eax, %ebp
jmp 0x39c6
movq 0xa5bf(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x3a27
cmpb $0x0, 0x1(%rdi)
je 0x3c2b
leaq 0x577a(%rip), %rsi      # 0x91a8
callq 0x2220
testq %rax, %rax
je 0x3cc5
movq %rax, 0x30(%rsp)
movq %rax, %rdi
callq 0x3102
movq %rax, 0x8(%rsp)
movl %ebx, %eax
cltd
idivl %ebp
movl %eax, 0x24(%rsp)
movslq %ebx, %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x2160
movq %rax, %r13
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movq 0x8(%rsp), %rdi
callq 0x312e
testl %eax, %eax
js 0x3bfe
movl %eax, %r12d
andl $0x0, 0x1c(%rsp)
andq $0x0, 0x14(%rsp)
subl %ebx, %eax
movl %eax, 0x20(%rsp)
movl %r12d, %esi
leal 0x1(%r12), %eax
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %rsi, 0x28(%rsp)
movq %r12, 0x48(%rsp)
cmpq 0x50(%rsp), %rbp
je 0x3a78
cmpq %r14, %rbp
jge 0x3acd
cmpq %rsi, %rbp
je 0x3add
jmp 0x3b3e
movl %ebp, %eax
cltd
idivl 0x24(%rsp)
cmpq %rsi, %rbp
je 0x3add
testl %edx, %edx
jne 0x3b3e
cmpl %ebx, %r12d
setl %al
cmpq %rsi, %rbp
setne %cl
orb %al, %cl
je 0x3bdb
movl 0x1c(%rsp), %r9d
movl 0x18(%rsp), %r8d
addl %r9d, %r8d
je 0x3b3b
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movl %r9d, %eax
cvtsi2sd %rax, %xmm0
movl %r8d, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
mulsd 0x38(%rsp), %xmm0
leaq 0x5a47(%rip), %rdi      # 0x9571
movl %r15d, %edx
movl %ebp, %ecx
movb $0x1, %al
callq 0x20f0
movq 0x28(%rsp), %rsi
movl %ebp, %r15d
cmpq %rsi, %rbp
jae 0x3bd3
movl %ebp, %eax
cltd
idivl %ebx
movl %edx, %r14d
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movsbl (%rax,%rbp), %r12d
cmpl $0x0, 0x4(%rsp)
je 0x3b81
callq 0x2290
movq 0x28(%rsp), %rsi
movq (%rax), %rax
movslq %r12d, %r12
testb $0x2, 0x1(%rax,%r12,2)
pushq $0x4e
popq %rax
cmovnel %eax, %r12d
movslq %r12d, %rax
leaq 0xa5e5(%rip), %rcx      # 0xe170
movzbl (%rax,%rcx), %eax
leaq 0xa80a(%rip), %rcx      # 0xe3a0
movl (%rcx,%rax,4), %ecx
movl %r14d, %eax
movq 0x40(%rsp), %r14
cmpq %r14, %rbp
jl 0x3bb0
movsbq (%r13,%rax), %rdx
decl 0x14(%rsp,%rdx,4)
xorl %edx, %edx
cmpl $0x2, %ecx
sete %dl
incl %edx
cmpl $0x3, %ecx
movl $0x0, %ecx
cmovgel %ecx, %edx
movb %dl, (%r13,%rax)
incl 0x14(%rsp,%rdx,4)
movq 0x48(%rsp), %r12
incq %rbp
jmp 0x3aba
movl 0x20(%rsp), %ecx
cmpl %r15d, %ecx
jge 0x3af1
movl %ecx, %eax
cltd
idivl %ebx
movslq %edx, %rax
movsbq (%r13,%rax), %rax
decl 0x14(%rsp,%rax,4)
incl %ecx
jmp 0x3bdf
movq %r13, %rdi
callq 0x2050
movq 0x8(%rsp), %rdi
callq 0x3329
movq 0x30(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa396(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x5567(%rip), %rsi      # 0x91a8
movl %eax, %edi
callq 0x20b0
jmp 0x3a33
movq 0xa3a4(%rip), %r15      # 0xdff8
movq (%r15), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x2140
movq (%r15), %rcx
leaq 0x5847(%rip), %rdi      # 0x94b2
pushq $0x27
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x2260
movq (%r15), %rdi
leaq 0x5856(%rip), %rsi      # 0x94da
movl $0xc350, %edx           # imm = 0xC350
xorl %eax, %eax
callq 0x2190
movq (%r15), %rdi
leaq 0x5864(%rip), %rsi      # 0x94fe
pushq $0x5
popq %rdx
xorl %eax, %eax
callq 0x2190
movq (%r15), %rcx
leaq 0x5886(%rip), %rdi      # 0x9534
pushq $0x2d
popq %rsi
movq %r14, %rdx
callq 0x2260
movq (%r15), %rsi
movl %ebx, %edi
callq 0x2140
jmp 0x3ce4
movq 0xa32c(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x56cb(%rip), %rsi      # 0x93a1
leaq 0x588b(%rip), %rdx      # 0x9568
xorl %eax, %eax
callq 0x2190
pushq $0x1
popq %rax
jmp 0x3c1c