// File: /workspace/github_c_makefile_star2_O1/aokad[P]sequeeze/seqtk.c
// Function: stk_mutfa
int stk_mutfa(int argc, char *argv[])
{
	khash_t(reg) *h = kh_init(reg);
	gzFile fp;
	kseq_t *seq;
	kstream_t *ks;
	int l, i, dret;
	kstring_t *str;
	khint_t k;
	if (argc < 3) {
		fprintf(stderr, "Usage: seqtk mutfa <in.fa> <in.snp>\n\n");
		fprintf(stderr, "Note: <in.snp> contains at least four columns per line which are:\n");
		fprintf(stderr, "      'chr  1-based-pos  any  base-changed-to'.\n");
		return 1;
	}
	// read the list
	str = calloc(1, sizeof(kstring_t));
	fp = strcmp(argv[2], "-")? gzopen(argv[2], "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) {
		fprintf(stderr, "[E::%s] failed to open the input file/stream.\n", __func__);
		return 1;
	}
	ks = ks_init(fp);
	while (ks_getuntil(ks, 0, str, &dret) >= 0) {
		char *s = strdup(str->s);
		int beg = 0, ret;
		reglist_t *p;
		k = kh_get(reg, h, s);
		if (k == kh_end(h)) {
			k = kh_put(reg, h, s, &ret);
			memset(&kh_val(h, k), 0, sizeof(reglist_t));
		}
		p = &kh_val(h, k);
		if (ks_getuntil(ks, 0, str, &dret) > 0) beg = atol(str->s) - 1; // 2nd col
		ks_getuntil(ks, 0, str, &dret); // 3rd col
		ks_getuntil(ks, 0, str, &dret); // 4th col
		// skip the rest of the line
		if (dret != '\n') while ((dret = ks_getc(ks)) > 0 && dret != '\n');
		if (isalpha(str->s[0]) && str->l == 1) {
			if (p->n == p->m) {
				p->m = p->m? p->m<<1 : 4;
				p->a = realloc(p->a, p->m * 8);
			}
			p->a[p->n++] = (uint64_t)beg<<32 | str->s[0];
		}
	}
	ks_destroy(ks);
	gzclose(fp);
	free(str->s); free(str);
	// mutfa
	fp = strcmp(argv[1], "-")? gzopen(argv[1], "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);
	while ((l = kseq_read(seq)) >= 0) {
		reglist_t *p;
		k = kh_get(reg, h, seq->name.s);
		if (k != kh_end(h)) {
			p = &kh_val(h, k);
			for (i = 0; i < p->n; ++i) {
				int beg = p->a[i]>>32;
				if (beg < seq->seq.l)
					seq->seq.s[beg] = (int)p->a[i];
			}
		}
		printf(">%s", seq->name.s);
		for (i = 0; i < l; ++i) {
			if (i%60 == 0) putchar('\n');
			putchar(seq->seq.s[i]);
		}
		putchar('\n');
	}
	// free
	kseq_destroy(seq);
	gzclose(fp);
	for (k = 0; k < kh_end(h); ++k) {
		if (kh_exist(h, k)) {
			free(kh_val(h, k).a);
			free((char*)kh_key(h, k));
		}
	}
	kh_destroy(reg, h);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %edi
movl $0x28, %esi
callq 0x2160
movq %rax, (%rsp)
cmpl $0x2, %ebp
jle 0x5fb5
movl $0x1, %edi
movl $0x18, %esi
callq 0x2160
movq %rax, %r15
movq 0x10(%rbx), %r14
leaq 0x6a3f(%rip), %rsi      # 0xc3ae
movq %r14, %rdi
callq 0x2170
testl %eax, %eax
je 0x598c
leaq 0x5816(%rip), %rsi      # 0xb198
movq %r14, %rdi
callq 0x2220
jmp 0x59a9
movq 0xa635(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x57f6(%rip), %rsi      # 0xb198
movl %eax, %edi
callq 0x20b0
testq %rax, %rax
je 0x5fbc
movq %rbx, 0x28(%rsp)
movl $0x1, %edi
movl $0x20, %esi
movq %rax, %rbx
callq 0x2160
movq %rax, %r14
movq %rbx, 0x38(%rsp)
movq %rbx, 0x18(%rax)
movl $0x4000, %edi           # imm = 0x4000
callq 0x21d0
movq %rax, (%r14)
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x9c69
testl %eax, %eax
js 0x5cae
movq %r14, 0x20(%rsp)
movq %r15, 0x10(%rsp)
movq 0x10(%r15), %rdi
callq 0x2270
movq %rax, %r12
movq (%rsp), %rax
movl (%rax), %edi
movl $0x0, %ebp
testl %edi, %edi
je 0x5b06
movsbl (%r12), %r15d
testl %r15d, %r15d
je 0x5a5d
movb 0x1(%r12), %al
testb %al, %al
je 0x5a60
movq %r12, %rcx
addq $0x2, %rcx
movl %r15d, %edx
shll $0x5, %edx
subl %r15d, %edx
movsbl %al, %r15d
addl %edx, %r15d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x5a42
jmp 0x5a60
xorl %r15d, %r15d
movq %rdi, 0x18(%rsp)
leal -0x1(%rdi), %edx
movl %r15d, %edi
andl %edx, %edi
movl %r15d, %eax
shrl $0x3, %eax
shll $0x3, %r15d
xorl %eax, %r15d
orl $0x1, %r15d
andl %edx, %r15d
movq (%rsp), %rax
movq 0x10(%rax), %r13
movl %edi, %ebp
movl %edi, 0x8(%rsp)
movl %edx, 0x30(%rsp)
movl %ebp, %eax
shrl $0x4, %eax
movl (%r13,%rax,4), %ebx
leal (,%rbp,2), %r14d
andl $0x1e, %r14d
movl %ebx, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5aec
testb $0x1, %al
jne 0x5ada
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rdi
movq %r12, %rsi
callq 0x2170
movl 0x8(%rsp), %edi
movl 0x30(%rsp), %edx
testl %eax, %eax
je 0x5aec
addl %r15d, %ebp
andl %edx, %ebp
cmpl %edi, %ebp
jne 0x5a93
movq 0x18(%rsp), %rdi
movl %edi, %ebp
jmp 0x5afc
movl %r14d, %ecx
shrl %cl, %ebx
testb $0x3, %bl
movq 0x18(%rsp), %rdi
cmovnel %edi, %ebp
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r14
cmpl %edi, %ebp
jne 0x5b31
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x44(%rsp), %rdx
callq 0x354f
movl %eax, %ebp
movq 0x20(%rbx), %rax
movl %ebp, %ecx
shlq $0x4, %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%rcx)
movl %ebp, %ebx
shlq $0x4, %rbx
movq (%rsp), %rax
addq 0x20(%rax), %rbx
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
leaq 0xc(%rsp), %rbp
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x9c69
testl %eax, %eax
jle 0x5b7a
movq 0x10(%r15), %rdi
callq 0x2230
movq %rax, %r12
shlq $0x20, %r12
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rax, %r12
jmp 0x5b7d
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x9c69
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x9c69
cmpl $0xa, 0xc(%rsp)
je 0x5c30
movl 0xc(%r14), %eax
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
testl %eax, %eax
js 0x5c0e
cmpl $0x0, 0x10(%r14)
je 0x5bc8
cmpl %eax, 0x8(%r14)
jge 0x5c09
cmpl %eax, 0x8(%r14)
jl 0x5bed
movl $0x0, 0x8(%r14)
movq (%r14), %rsi
movq 0x18(%r14), %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x2180
testl %eax, %eax
je 0x5c01
js 0x5c1d
movq (%r14), %rcx
movslq 0x8(%r14), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x8(%r14)
movzbl (%rcx,%rdx), %ebp
jmp 0x5c0e
movl $0x1, 0x10(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
jle 0x5c27
cmpl $0xa, %ebp
jne 0x5bb2
jmp 0x5c27
movl $0x1, 0x10(%r14)
jmp 0x5c0e
movl %eax, 0xc(%r14)
leaq 0xc(%rsp), %rbp
callq 0x2290
movq (%rax), %rax
movq 0x10(%r15), %r14
movsbq (%r14), %rcx
testb $0x4, 0x1(%rax,%rcx,2)
je 0x5c8e
cmpq $0x1, (%r15)
jne 0x5c8e
movl 0x4(%rbx), %eax
cmpl %eax, (%rbx)
jne 0x5c77
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x4, %eax
cmovel %eax, %ecx
movl %ecx, 0x4(%rbx)
movq 0x8(%rbx), %rdi
shll $0x3, %ecx
movslq %ecx, %rsi
callq 0x2200
movq %rax, 0x8(%rbx)
movsbq (%r14), %rax
orq %rax, %r12
movq 0x8(%rbx), %rax
movslq (%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rbx)
movq %r12, (%rax,%rcx,8)
movq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x9c69
testl %eax, %eax
jns 0x5a09
movq (%r14), %rdi
callq 0x2050
movq %r14, %rdi
callq 0x2050
movq 0x38(%rsp), %rdi
callq 0x2040
movq 0x10(%r15), %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
movq 0x28(%rsp), %rax
movq 0x8(%rax), %r14
leaq 0x66c5(%rip), %rsi      # 0xc3ae
movq %r14, %rdi
callq 0x2170
testl %eax, %eax
je 0x5d06
leaq 0x549c(%rip), %rsi      # 0xb198
movq %r14, %rdi
callq 0x2220
jmp 0x5d23
movq 0xa2bb(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x547c(%rip), %rsi      # 0xb198
movl %eax, %edi
callq 0x20b0
testq %rax, %rax
je 0x5fc3
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x3e57
movq %rax, %r15
movq %rax, %rdi
callq 0x3ea1
testl %eax, %eax
js 0x5f0e
movl %eax, %ebx
movq (%rsp), %rax
movl (%rax), %r13d
leal -0x1(%r13), %eax
movl %eax, 0x8(%rsp)
movl $0x88888889, %ebp       # imm = 0x88888889
movq %r13, 0x10(%rsp)
movq %r15, 0x20(%rsp)
movl $0x0, %r12d
testl %r13d, %r13d
je 0x5e58
movq 0x10(%r15), %rsi
movsbl (%rsi), %ebp
testl %ebp, %ebp
movl %ebx, 0x18(%rsp)
je 0x5dac
movb 0x1(%rsi), %al
testb %al, %al
je 0x5dae
leaq 0x2(%rsi), %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 0x5d95
jmp 0x5dae
xorl %ebp, %ebp
movl %ebp, %edx
movl 0x8(%rsp), %ecx
andl %ecx, %edx
movl %ebp, %eax
shrl $0x3, %eax
shll $0x3, %ebp
xorl %eax, %ebp
orl $0x1, %ebp
andl %ecx, %ebp
movq (%rsp), %rax
movq 0x10(%rax), %rdi
movl %edx, %r12d
movq %rdi, 0x30(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %r13d
leal (%r12,%r12), %r14d
andl $0x1e, %r14d
movl %r13d, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5e3c
testb $0x1, %al
jne 0x5e25
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rsi, %rbx
movl %edx, %r15d
callq 0x2170
movq 0x30(%rsp), %rdi
movl %r15d, %edx
movq 0x20(%rsp), %r15
movq %rbx, %rsi
testl %eax, %eax
je 0x5e3c
addl %ebp, %r12d
andl 0x8(%rsp), %r12d
cmpl %edx, %r12d
jne 0x5dd5
movq 0x10(%rsp), %r13
movl %r13d, %r12d
jmp 0x5e4f
movl %r14d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x10(%rsp), %r13
cmovnel %r13d, %r12d
movl $0x88888889, %ebp       # imm = 0x88888889
movl 0x18(%rsp), %ebx
cmpl %r13d, %r12d
je 0x5e9e
movq (%rsp), %rax
movq 0x20(%rax), %rax
movl %r12d, %ecx
shlq $0x4, %rcx
cmpl $0x0, (%rax,%rcx)
jle 0x5e9e
addq %rcx, %rax
xorl %ecx, %ecx
movq 0x8(%rax), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, %rsi
sarq $0x20, %rsi
cmpq 0x30(%r15), %rsi
jae 0x5e93
movq 0x40(%r15), %rdi
movb %dl, (%rdi,%rsi)
incq %rcx
movslq (%rax), %rdx
cmpq %rdx, %rcx
jl 0x5e77
movq 0x10(%r15), %rsi
leaq 0x55eb(%rip), %rdi      # 0xb494
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
jle 0x5ef2
movl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
movl %r12d, %eax
imulq %rbp, %rax
shrq $0x25, %rax
imull $0x3c, %eax, %eax
addl %r14d, %eax
jne 0x5ed9
movl $0xa, %edi
callq 0x2060
movq 0x40(%r15), %rax
movsbl (%rax,%r12), %edi
callq 0x2060
incq %r12
decl %r14d
cmpq %r12, %rbx
jne 0x5ebc
movl $0xa, %edi
callq 0x2060
movq %r15, %rdi
callq 0x3ea1
movl %eax, %ebx
testl %eax, %eax
jns 0x5d6c
movq %r15, %rdi
callq 0x4229
movq 0x28(%rsp), %rdi
callq 0x2040
movq (%rsp), %rax
movl (%rax), %ebx
testq %rbx, %rbx
je 0x5f7d
movq (%rsp), %rax
movq 0x10(%rax), %r14
movl $0x1, %r15d
xorl %r12d, %r12d
movq (%rsp), %r13
movl %r12d, %eax
shrl $0x4, %eax
movl (%r14,%rax,4), %eax
leal -0x1(%r15), %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0x5f71
movq 0x20(%r13), %rax
movq (%rax,%r15,8), %rdi
callq 0x2050
movq 0x18(%r13), %rax
movq (%rax,%r12,8), %rdi
callq 0x2050
incq %r12
addq $0x2, %r15
cmpq %r12, %rbx
jne 0x5f40
movq (%rsp), %rbx
movq 0x18(%rbx), %rdi
callq 0x2050
movq 0x10(%rbx), %rdi
callq 0x2050
movq 0x20(%rbx), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x26f7
jmp 0x5fc8
callq 0x26d8
jmp 0x5fc8
callq 0x26b3
movl $0x1, %eax
jmp 0x5fa6