// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x96d6(%rip), %rdx      # 0xd4b5
callq 0x2240
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
jl 0x3e27
movl -0x28(%rbp), %eax
movl %eax, -0xc4(%rbp)
subl $0x72, %eax
je 0x3e12
jmp 0x3dfc
movl -0xc4(%rbp), %eax
subl $0x75, %eax
jne 0x3e25
jmp 0x3e09
movl $0x1, -0x2c(%rbp)
jmp 0x3e25
movq 0xd1bf(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x23a0
movq %rax, -0x38(%rbp)
jmp 0x3dd1
movl -0x8(%rbp), %eax
movq 0xd19f(%rip), %rcx      # 0x10fd0
cmpl (%rcx), %eax
jne 0x3e8c
movq 0xd18c(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
callq 0x2090
cmpl $0x0, %eax
je 0x3e8c
movq 0xd1a1(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x9658(%rip), %rsi      # 0xd4b9
movb $0x0, %al
callq 0x2190
movq 0xd189(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x966e(%rip), %rsi      # 0xd4e7
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x438d
movq 0xd13d(%rip), %rax      # 0x10fd0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0x3ee4
movq -0x10(%rbp), %rax
movq 0xd12b(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xa5e3(%rip), %rsi      # 0xe496
callq 0x2170
cmpl $0x0, %eax
je 0x3ee4
movq -0x10(%rbp), %rax
movq 0xd108(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x93aa(%rip), %rsi      # 0xd280
callq 0x2220
movq %rax, -0xd0(%rbp)
jmp 0x3f08
movq 0xd0dd(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
leaq 0x9384(%rip), %rsi      # 0xd280
callq 0x20b0
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3f45
movq 0xd0d7(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x954e(%rip), %rsi      # 0xd479
leaq 0x9606(%rip), %rdx      # 0xd538
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x438d
movq -0x18(%rbp), %rdi
callq 0x38f0
movq %rax, -0x20(%rbp)
movl $0x1, -0x44(%rbp)
movl $0x1, -0x48(%rbp)
movl $0x1, %edi
movl $0x8, %esi
callq 0x2160
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3930
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jl 0x436b
movq $0x0, -0x58(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x3fce
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2760
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x3fcc
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
jmp 0x3fe1
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movslq -0x24(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x50(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0xd1(%rbp)
je 0x4009
movl -0x50(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
setl %al
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x4018
jmp 0x4357
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x50(%rbp), %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq (%rcx,%rdx,8), %rax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x60(%rbp)
jle 0x408f
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x60(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x68(%rbp)
movslq -0x68(%rbp), %rcx
leaq 0xd0eb(%rip), %rax      # 0x11160
movzbl (%rax,%rcx), %eax
movl %eax, -0x6c(%rbp)
movslq -0x6c(%rbp), %rcx
leaq 0xd309(%rip), %rax      # 0x11390
movl (%rax,%rcx,4), %eax
movl %eax, -0x70(%rbp)
jmp 0x40a4
movl $0x61, -0x68(%rbp)
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x60(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x74(%rbp)
movslq -0x74(%rbp), %rcx
leaq 0xd09e(%rip), %rax      # 0x11160
movzbl (%rax,%rcx), %eax
movl %eax, -0x78(%rbp)
movslq -0x78(%rbp), %rcx
leaq 0xd2bc(%rip), %rax      # 0x11390
movl (%rax,%rcx,4), %eax
movl %eax, -0x7c(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x2c, %edx
callq 0x2120
movl -0x60(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x42d0
movl $0x0, -0xb4(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0xc0(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x74(%rbp)
movslq -0x74(%rbp), %rcx
leaq 0xd019(%rip), %rax      # 0x11160
movzbl (%rax,%rcx), %eax
movl %eax, -0x78(%rbp)
movslq -0x78(%rbp), %rcx
leaq 0xd237(%rip), %rax      # 0x11390
movl (%rax,%rcx,4), %eax
movl %eax, -0x7c(%rbp)
cmpl $0x2, -0xbc(%rbp)
je 0x4171
cmpl $0xa, -0xbc(%rbp)
jne 0x4189
cmpl $0x4, -0x78(%rbp)
je 0x417d
cmpl $0x5, -0x78(%rbp)
jne 0x4187
movl $0x1, -0xb4(%rbp)
jmp 0x41b5
cmpl $0x4, -0xbc(%rbp)
je 0x419b
cmpl $0x5, -0xbc(%rbp)
jne 0x41b3
cmpl $0x2, -0x6c(%rbp)
je 0x41a7
cmpl $0xa, -0x6c(%rbp)
jne 0x41b1
movl $0x1, -0xb4(%rbp)
jmp 0x41b3
jmp 0x41b5
cmpl $0x0, -0x2c(%rbp)
je 0x41dc
callq 0x2280
movq (%rax), %rax
movslq -0xb8(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x42a7
cmpl $0x1, -0xc0(%rbp)
jle 0x4201
movl -0xc0(%rbp), %eax
addl $0x2, %eax
cltq
movl -0xb0(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0xb0(%rbp,%rax,4)
cmpl $0x1, -0xc0(%rbp)
jne 0x422d
movslq -0xbc(%rbp), %rcx
leaq 0xd158(%rip), %rax      # 0x11370
movzbl (%rax,%rcx), %eax
movl -0xb0(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0xb0(%rbp,%rax,4)
cmpl $0xa, -0xbc(%rbp)
je 0x423f
cmpl $0x5, -0xbc(%rbp)
jne 0x4250
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x426a
cmpl $0x2, -0xc0(%rbp)
jne 0x4268
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x426a
cmpl $0x0, -0xb4(%rbp)
je 0x42a5
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
cmpl $0xa, -0xbc(%rbp)
je 0x4294
cmpl $0x5, -0xbc(%rbp)
jne 0x42a3
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x42a5
jmp 0x42a7
movl -0xb8(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x40f3
cmpq $0x0, -0x38(%rbp)
je 0x42f5
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x60(%rbp), %edx
movl -0x64(%rbp), %ecx
leaq 0x9255(%rip), %rdi      # 0xd541
movb $0x0, %al
callq 0x20f0
jmp 0x430e
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x24(%rbp), %edx
leaq 0x9243(%rip), %rdi      # 0xd54a
movb $0x0, %al
callq 0x20f0
movl $0x0, -0x4c(%rbp)
cmpl $0xb, -0x4c(%rbp)
jge 0x433f
movslq -0x4c(%rbp), %rax
movl -0xb0(%rbp,%rax,4), %esi
leaq 0x9219(%rip), %rdi      # 0xd546
movb $0x0, %al
callq 0x20f0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4315
movl $0xa, %edi
callq 0x2050
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x3fe8
movq 0xcc62(%rip), %rax      # 0x10fc0
movq (%rax), %rdi
callq 0x21e0
jmp 0x3f73
movq -0x40(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rdi
callq 0x3d40
movq -0x18(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)