// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
cmpl $0x1, %edi
je 0x4cd6
movq %rsi, %r14
movl %edi, %r15d
leaq 0x6b6d(%rip), %rdx      # 0xb562
callq 0x2240
testl %eax, %eax
js 0x4a69
movl $0x5, %ebp
xorl %r13d, %r13d
movl $0xc350, %ebx           # imm = 0xC350
leaq 0x6b50(%rip), %r12      # 0xb562
cmpl $0x6d, %eax
je 0x4a47
cmpl $0x74, %eax
je 0x4a34
cmpl $0x77, %eax
jne 0x4a4d
movq 0xb5b0(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x2250
movl %eax, %ebx
jmp 0x4a4d
movq 0xb59d(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x2250
movl %eax, %ebp
jmp 0x4a4d
movl $0x1, %r13d
movl %r15d, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
jns 0x4a12
testl %r13d, %r13d
sete 0x3(%rsp)
jmp 0x4a78
movl $0xc350, %ebx           # imm = 0xC350
movb $0x1, 0x3(%rsp)
movl $0x5, %ebp
movq 0xb551(%rip), %rax      # 0xffd0
movslq (%rax), %rax
movq (%r14,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x4a95
cmpb $0x0, 0x1(%rdi)
je 0x4cb4
leaq 0x670c(%rip), %rsi      # 0xb1a8
callq 0x2220
testq %rax, %rax
je 0x4cdd
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x3edd
movq %rax, %r14
movl %ebx, %eax
cltd
idivl %ebp
movl %eax, 0x1c(%rsp)
movslq %ebx, %r12
movl $0x1, %esi
movq %r12, %rdi
callq 0x2160
movq %rax, %r13
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x3f27
testl %eax, %eax
js 0x4c87
movl %eax, %r14d
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, 0x38(%rsp)
movl $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movl %r14d, %eax
subl %ebx, %eax
movl %eax, 0x4(%rsp)
movl %r14d, %esi
incl %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %rsi, 0x20(%rsp)
movq %r14, 0x40(%rsp)
cmpq %r12, %rbp
jge 0x4b3b
cmpq %rsi, %rbp
je 0x4b4f
jmp 0x4bcf
movl %ebp, %eax
cltd
idivl 0x1c(%rsp)
cmpq %rsi, %rbp
je 0x4b4f
testl %edx, %edx
jne 0x4bcf
cmpq %rsi, %rbp
jne 0x4b7c
cmpl %ebx, %esi
jl 0x4b7c
cmpl %r15d, 0x4(%rsp)
jge 0x4b7c
movl 0x4(%rsp), %ecx
movl %ecx, %eax
cltd
idivl %ebx
movslq %edx, %rax
movsbq (%r13,%rax), %rax
decl 0x10(%rsp,%rax,4)
incl %ecx
cmpl %ecx, %r15d
jne 0x4b63
movl 0x18(%rsp), %r9d
movl 0x14(%rsp), %r8d
addl %r9d, %r8d
je 0x4bcc
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movl %r9d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %r8d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
mulsd 0x30(%rsp), %xmm0
leaq 0x69b6(%rip), %rdi      # 0xb571
movl %r15d, %edx
movl %ebp, %ecx
movb $0x1, %al
callq 0x20f0
movq 0x20(%rsp), %rsi
movl %ebp, %r15d
cmpq %rsi, %rbp
jae 0x4c66
movl %ebp, %eax
cltd
idivl %ebx
movl %edx, %r14d
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movsbl (%rax,%rbp), %r12d
cmpb $0x0, 0x3(%rsp)
jne 0x4c14
callq 0x2290
movq 0x20(%rsp), %rsi
movq (%rax), %rax
movslq %r12d, %r12
testb $0x2, 0x1(%rax,%r12,2)
movl $0x4e, %eax
cmovnel %eax, %r12d
movslq %r12d, %rax
leaq 0xb552(%rip), %rcx      # 0x10170
movzbl (%rax,%rcx), %eax
leaq 0xb777(%rip), %rcx      # 0x103a0
movl (%rcx,%rax,4), %ecx
movl %r14d, %eax
movq 0x38(%rsp), %r12
cmpq %r12, %rbp
jl 0x4c43
movsbq (%r13,%rax), %rdx
decl 0x10(%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 0x10(%rsp,%rdx,4)
movq 0x40(%rsp), %r14
incq %rbp
cmpq %r14, %rbp
jne 0x4b2c
movq 0x8(%rsp), %rdi
callq 0x3f27
movl %eax, %r14d
testl %eax, %eax
jns 0x4afd
movq %r13, %rdi
callq 0x2050
movq 0x8(%rsp), %rdi
callq 0x428d
movq 0x28(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb30d(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x64de(%rip), %rsi      # 0xb1a8
movl %eax, %edi
callq 0x20b0
jmp 0x4aa1
callq 0x2463
jmp 0x4ce2
callq 0x2444
movl $0x1, %eax
jmp 0x4ca5