// File: /workspace/github_c_makefile_star2_O1/aokad[P]sequeeze/seqtk.c
// Function: stk_comp
int stk_comp(int argc, char *argv[])
{
	gzFile fp;
	kseq_t *seq;
	int l, c, upper_only = 0;
	reghash_t *h = 0;
	reglist_t dummy;

	while ((c = getopt(argc, argv, "ur:")) >= 0) {
		switch (c) {
			case 'u': upper_only = 1; break;
			case 'r': h = stk_reg_read(optarg); break;
		}
	}
	if (argc == optind && isatty(fileno(stdin))) {
		fprintf(stderr, "Usage:  seqtk comp [-u] [-r in.bed] <in.fa>\n\n");
		fprintf(stderr, "Output format: chr, length, #A, #C, #G, #T, #2, #3, #4, #CpG, #tv, #ts, #CpG-ts\n");
		return 1;
	}
	fp = optind < argc && 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);
	dummy.n= dummy.m = 1; dummy.a = calloc(1, 8);
	while ((l = kseq_read(seq)) >= 0) {
		int i, k;
		reglist_t *p = 0;
		if (h) {
			khint_t k = kh_get(reg, h, seq->name.s);
			if (k != kh_end(h)) p = &kh_val(h, k);
		} else {
			p = &dummy;
			dummy.a[0] = l;
		}
		for (k = 0; p && k < p->n; ++k) {
			int beg = p->a[k]>>32, end = p->a[k]&0xffffffff;
			int la, lb, lc, na, nb, nc, cnt[11];
			if (beg > 0) la = seq->seq.s[beg-1], lb = seq_nt16_table[la], lc = bitcnt_table[lb];
			else la = 'a', lb = -1, lc = 0;
			na = seq->seq.s[beg]; nb = seq_nt16_table[na]; nc = bitcnt_table[nb];
			memset(cnt, 0, 11 * sizeof(int));
			for (i = beg; i < end; ++i) {
				int is_CpG = 0, a, b, c;
				a = na; b = nb; c = nc;
				na = seq->seq.s[i+1]; nb = seq_nt16_table[na]; nc = bitcnt_table[nb];
				if (b == 2 || b == 10) { // C or Y
					if (nb == 4 || nb == 5) is_CpG = 1;
				} else if (b == 4 || b == 5) { // G or R
					if (lb == 2 || lb == 10) is_CpG = 1;
				}
				if (upper_only == 0 || isupper(a)) {
					if (c > 1) ++cnt[c+2];
					if (c == 1) ++cnt[seq_nt16to4_table[b]];
					if (b == 10 || b == 5) ++cnt[9];
					else if (c == 2) {
						++cnt[8];
					}
					if (is_CpG) {
						++cnt[7];
						if (b == 10 || b == 5) ++cnt[10];
					}
				}
				la = a; lb = b; lc = c;
			}
			if (h) printf("%s\t%d\t%d", seq->name.s, beg, end);
			else printf("%s\t%d", seq->name.s, l);
			for (i = 0; i < 11; ++i) printf("\t%d", cnt[i]);
			putchar('\n');
		}
		fflush(stdout);
	}
	free(dummy.a);
	kseq_destroy(seq);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
movl %edi, %r12d
leaq 0x712d(%rip), %rdx      # 0xb3cd
callq 0x2240
xorl %ebx, %ebx
testl %eax, %eax
js 0x42f6
movq 0xbd26(%rip), %r13      # 0xffd8
leaq 0x7114(%rip), %r15      # 0xb3cd
xorl %ebp, %ebp
cmpl $0x72, %eax
je 0x42cc
cmpl $0x75, %eax
jne 0x42d8
movl $0x1, %ebx
jmp 0x42d8
movq (%r13), %rdi
callq 0x314c
movq %rax, %rbp
movl %r12d, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2240
testl %eax, %eax
jns 0x42bb
testl %ebx, %ebx
sete 0x7(%rsp)
movq %rbp, %r13
jmp 0x42fe
movb $0x1, 0x7(%rsp)
xorl %r13d, %r13d
movq 0xbccb(%rip), %rbx      # 0xffd0
cmpl %r12d, (%rbx)
jne 0x4328
movq 0xbcb7(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
callq 0x2090
testl %eax, %eax
jne 0x4787
movslq (%rbx), %rax
cmpl %r12d, %eax
jge 0x4358
movq (%r14,%rax,8), %r14
leaq 0x8073(%rip), %rsi      # 0xc3ae
movq %r14, %rdi
callq 0x2170
testl %eax, %eax
je 0x4358
leaq 0x6e4a(%rip), %rsi      # 0xb198
movq %r14, %rdi
callq 0x2220
jmp 0x4375
movq 0xbc69(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x6e2a(%rip), %rsi      # 0xb198
movl %eax, %edi
callq 0x20b0
testq %rax, %rax
je 0x4780
movq %rax, 0x48(%rsp)
movq %rax, %rdi
callq 0x3e57
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x38(%rsp)
movl $0x1, %edi
movl $0x8, %esi
callq 0x2160
movq %rax, 0x40(%rsp)
movq %r14, %rdi
callq 0x3ea1
movl %eax, 0x8(%rsp)
testl %eax, %eax
js 0x4750
movq %r13, 0x18(%rsp)
movq %r14, 0x10(%rsp)
testq %r13, %r13
je 0x440b
movl (%r13), %edi
testl %edi, %edi
je 0x4421
movq 0x10(%r14), %r14
movsbl (%r14), %ebp
testl %ebp, %ebp
je 0x4429
movb 0x1(%r14), %al
testb %al, %al
je 0x442b
leaq 0x2(%r14), %rcx
movl %ebp, %edx
shll $0x5, %edx
subl %ebp, %edx
movsbl %al, %ebp
addl %edx, %ebp
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x43f4
jmp 0x442b
movl 0x8(%rsp), %eax
movq 0x40(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x38(%rsp), %rcx
jmp 0x44e3
xorl %r15d, %r15d
jmp 0x44cf
xorl %ebp, %ebp
movq %rdi, 0x20(%rsp)
leal -0x1(%rdi), %ebx
movl %ebp, %edi
andl %ebx, %edi
movl %ebp, %eax
shrl $0x3, %eax
shll $0x3, %ebp
xorl %eax, %ebp
orl $0x1, %ebp
andl %ebx, %ebp
movq 0x10(%r13), %r8
movl %edi, %r15d
movl %edi, 0xc(%rsp)
movq %r8, 0x28(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %r13d
leal (%r15,%r15), %r12d
andl $0x1e, %r12d
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x44b2
testb $0x1, %al
jne 0x449d
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r14, %rsi
callq 0x2170
movq 0x28(%rsp), %r8
movl 0xc(%rsp), %edi
testl %eax, %eax
je 0x44b2
addl %ebp, %r15d
andl %ebx, %r15d
cmpl %edi, %r15d
jne 0x4456
movq 0x20(%rsp), %rdi
movl %edi, %r15d
jmp 0x44c5
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x20(%rsp), %rdi
cmovnel %edi, %r15d
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %r14
cmpl %edi, %r15d
jne 0x44d8
xorl %ecx, %ecx
jmp 0x44e3
movl %r15d, %ecx
shlq $0x4, %rcx
addq 0x20(%r13), %rcx
testq %rcx, %rcx
je 0x472d
xorl %edx, %edx
movq %rcx, 0x50(%rsp)
movslq (%rcx), %rax
cmpq %rax, %rdx
jge 0x472d
movq 0x8(%rcx), %rax
movq %rdx, 0x60(%rsp)
movq (%rax,%rdx,8), %rsi
movq %rsi, %rdi
shrq $0x20, %rdi
testl %edi, %edi
jle 0x4532
movq 0x40(%r14), %rax
movl %edi, %ecx
decl %ecx
movsbq (%rax,%rcx), %rax
leaq 0xbc45(%rip), %rdx      # 0x10170
movzbl (%rax,%rdx), %r13d
jmp 0x453f
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0xbc31(%rip), %rdx      # 0x10170
movq 0x40(%r14), %r12
movq %rsi, %rbp
sarq $0x20, %rbp
movsbq (%r12,%rbp), %rbx
movzbl (%rbx,%rdx), %r9d
leaq 0xbe45(%rip), %rax      # 0x103a0
movl (%rax,%r9,4), %r11d
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movups %xmm0, 0x8c(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x58(%rsp)
cmpl %esi, %edi
jge 0x46a5
movslq 0x30(%rsp), %rsi
movl %r13d, %eax
movl %r11d, %r14d
movzbl %r9b, %r13d
movsbq 0x1(%r12,%rbp), %rdi
movzbl (%rdi,%rdx), %r9d
movl %r13d, %ecx
orl $0x8, %ecx
cmpl $0xa, %ecx
jne 0x45b7
movl %r9d, %eax
andb $-0x2, %al
cmpb $0x4, %al
jmp 0x45c8
movl %r13d, %ecx
andl $-0x2, %ecx
xorl $0x4, %ecx
andl $-0x9, %eax
xorl $0x2, %eax
orl %ecx, %eax
setne %r15b
leaq 0xbdcd(%rip), %rax      # 0x103a0
movl (%rax,%r9,4), %r11d
cmpb $0x0, 0x7(%rsp)
jne 0x462f
movb %r15b, 0x20(%rsp)
movq %rsi, %r15
movl %r14d, 0x28(%rsp)
movq %r9, %r14
movq %rbx, 0x68(%rsp)
movq %rdi, %rbx
movl %r11d, 0xc(%rsp)
callq 0x2290
movl 0xc(%rsp), %r11d
movq %rbx, %rdi
movq %r14, %r9
movl 0x28(%rsp), %r14d
movq %r15, %rsi
movb 0x20(%rsp), %r15b
leaq 0xbb51(%rip), %rdx      # 0x10170
movq (%rax), %rax
movsbq 0x68(%rsp), %rcx
testb $0x1, 0x1(%rax,%rcx,2)
je 0x4686
cmpl $0x2, %r14d
jl 0x463c
movl %r14d, %eax
incl 0x78(%rsp,%rax,4)
cmpl $0x1, %r14d
jne 0x4654
movl %r13d, %eax
leaq 0xbd34(%rip), %rcx      # 0x10380
movzbl (%rax,%rcx), %eax
incl 0x70(%rsp,%rax,4)
cmpl $0xa, %r13d
je 0x4660
cmpl $0x5, %r13d
jne 0x4696
incl 0x94(%rsp)
testb %r15b, %r15b
jne 0x4686
incl 0x8c(%rsp)
cmpl $0xa, %r13d
je 0x467f
cmpl $0x5, %r13d
jne 0x4686
incl 0x98(%rsp)
incq %rbp
movl %edi, %ebx
cmpq %rbp, %rsi
jne 0x458e
jmp 0x46a5
cmpl $0x2, %r14d
jne 0x4667
incl 0x90(%rsp)
jmp 0x4667
movq 0x18(%rsp), %r13
testq %r13, %r13
je 0x46d2
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rsi
leaq 0x6d9a(%rip), %rdi      # 0xb459
movq 0x58(%rsp), %rdx
movq 0x30(%rsp), %rcx
xorl %eax, %eax
callq 0x20f0
jmp 0x46ed
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rsi
leaq 0x6d80(%rip), %rdi      # 0xb462
movl 0x8(%rsp), %edx
xorl %eax, %eax
callq 0x20f0
leaq 0x6d6a(%rip), %r15      # 0xb45e
xorl %ebx, %ebx
movl 0x70(%rsp,%rbx,4), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x20f0
incq %rbx
cmpq $0xb, %rbx
jne 0x46f6
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdx
incq %rdx
movq 0x50(%rsp), %rcx
testq %rcx, %rcx
jne 0x44f3
movq 0xb88c(%rip), %rax      # 0xffc0
movq (%rax), %rdi
callq 0x21e0
movq %r14, %rdi
callq 0x3ea1
movl %eax, 0x8(%rsp)
testl %eax, %eax
jns 0x43cf
movq 0x40(%rsp), %rdi
callq 0x2050
movq %r14, %rdi
callq 0x4229
movq 0x48(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x23ea
jmp 0x478c
callq 0x23ab
movl $0x1, %eax
jmp 0x476e