// File: /workspace/github_c_makefile_star2_O1/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 0x4c62
movq %rsi, %r14
movl %edi, %r15d
leaq 0x6bd5(%rip), %rdx      # 0xb552
callq 0x2240
testl %eax, %eax
js 0x49f1
movl $0x5, %ebp
xorl %r13d, %r13d
movl $0xc350, %ebx           # imm = 0xC350
leaq 0x6bb8(%rip), %r12      # 0xb552
cmpl $0x6d, %eax
je 0x49cf
cmpl $0x74, %eax
je 0x49bc
cmpl $0x77, %eax
jne 0x49d5
movq 0xb628(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x2250
movl %eax, %ebx
jmp 0x49d5
movq 0xb615(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x2250
movl %eax, %ebp
jmp 0x49d5
movl $0x1, %r13d
movl %r15d, %edi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
jns 0x499a
testl %r13d, %r13d
sete 0x3(%rsp)
jmp 0x4a00
movl $0xc350, %ebx           # imm = 0xC350
movb $0x1, 0x3(%rsp)
movl $0x5, %ebp
movq 0xb5c9(%rip), %rax      # 0xffd0
movslq (%rax), %rax
movq (%r14,%rax,8), %r14
leaq 0x7999(%rip), %rsi      # 0xc3ae
movq %r14, %rdi
callq 0x2170
testl %eax, %eax
je 0x4a32
leaq 0x6770(%rip), %rsi      # 0xb198
movq %r14, %rdi
callq 0x2220
jmp 0x4a4f
movq 0xb58f(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x6750(%rip), %rsi      # 0xb198
movl %eax, %edi
callq 0x20b0
testq %rax, %rax
je 0x4c69
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x3e57
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 0x3ea1
testl %eax, %eax
js 0x4c35
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 0x4ae9
cmpq %rsi, %rbp
je 0x4afd
jmp 0x4b7d
movl %ebp, %eax
cltd
idivl 0x1c(%rsp)
cmpq %rsi, %rbp
je 0x4afd
testl %edx, %edx
jne 0x4b7d
cmpq %rsi, %rbp
jne 0x4b2a
cmpl %ebx, %esi
jl 0x4b2a
cmpl %r15d, 0x4(%rsp)
jge 0x4b2a
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 0x4b11
movl 0x18(%rsp), %r9d
movl 0x14(%rsp), %r8d
addl %r9d, %r8d
je 0x4b7a
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 0x69f8(%rip), %rdi      # 0xb561
movl %r15d, %edx
movl %ebp, %ecx
movb $0x1, %al
callq 0x20f0
movq 0x20(%rsp), %rsi
movl %ebp, %r15d
cmpq %rsi, %rbp
jae 0x4c14
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 0x4bc2
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 0xb5a4(%rip), %rcx      # 0x10170
movzbl (%rax,%rcx), %eax
leaq 0xb7c9(%rip), %rcx      # 0x103a0
movl (%rcx,%rax,4), %ecx
movl %r14d, %eax
movq 0x38(%rsp), %r12
cmpq %r12, %rbp
jl 0x4bf1
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 0x4ada
movq 0x8(%rsp), %rdi
callq 0x3ea1
movl %eax, %r14d
testl %eax, %eax
jns 0x4aab
movq %r13, %rdi
callq 0x2050
movq 0x8(%rsp), %rdi
callq 0x4229
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
callq 0x2463
jmp 0x4c6e
callq 0x2444
movl $0x1, %eax
jmp 0x4c53