// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %edi
movl $0x28, %esi
callq 0x2160
movq %rax, 0x8(%rsp)
cmpl $0x2, %ebp
jle 0x60d2
movl $0x1, %edi
movl $0x18, %esi
callq 0x2160
movq %rax, %r12
movq 0x10(%rbx), %rdi
cmpb $0x2d, (%rdi)
jne 0x5a51
cmpb $0x0, 0x1(%rdi)
je 0x608e
leaq 0x5750(%rip), %rsi      # 0xb1a8
callq 0x2220
movq %rax, %r14
testq %rax, %rax
je 0x60d9
movq %rbx, 0x30(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x2160
movq %rax, %r13
movq %r14, 0x48(%rsp)
movq %r14, 0x18(%rax)
movl $0x4000, %edi           # imm = 0x4000
callq 0x21d0
movq %rax, (%r13)
leaq 0x4(%rsp), %rcx
xorl %ebp, %ebp
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %r8d, %r8d
callq 0x9f07
testl %eax, %eax
js 0x5da3
xorl %ebp, %ebp
movq %r12, 0x40(%rsp)
movq %r13, 0x38(%rsp)
movq 0x10(%r12), %rdi
callq 0x2270
movq %rax, %rsi
movq 0x8(%rsp), %rax
movl (%rax), %edi
movl $0x0, %r12d
testl %edi, %edi
je 0x5bbe
movsbl (%rsi), %r13d
testl %r13d, %r13d
movq %rbp, 0x18(%rsp)
je 0x5b1b
movb 0x1(%rsi), %al
testb %al, %al
je 0x5b1e
movq %rsi, %rcx
addq $0x2, %rcx
movl %r13d, %edx
shll $0x5, %edx
subl %r13d, %edx
movsbl %al, %r13d
addl %edx, %r13d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x5b00
jmp 0x5b1e
xorl %r13d, %r13d
movq %rdi, 0x28(%rsp)
leal -0x1(%rdi), %edx
movl %r13d, %edi
andl %edx, %edi
movl %r13d, %eax
shrl $0x3, %eax
shll $0x3, %r13d
xorl %eax, %r13d
orl $0x1, %r13d
andl %edx, %r13d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %r15
movl %edi, %r12d
movl %edi, 0x14(%rsp)
movl %edx, 0x20(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %ebx
leal (%r12,%r12), %r14d
andl $0x1e, %r14d
movl %ebx, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5ba8
testb $0x1, %al
jne 0x5b9b
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rsi, %rbp
callq 0x2170
movl 0x14(%rsp), %edi
movl 0x20(%rsp), %edx
movq %rbp, %rsi
testl %eax, %eax
je 0x5ba8
addl %r13d, %r12d
andl %edx, %r12d
cmpl %edi, %r12d
jne 0x5b53
jmp 0x5bc3
movl %r14d, %ecx
shrl %cl, %ebx
testb $0x3, %bl
movq 0x28(%rsp), %rdi
cmovnel %edi, %r12d
movq 0x18(%rsp), %rbp
cmpl %edi, %r12d
jne 0x5bec
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x54(%rsp), %rdx
callq 0x35b6
movq 0x20(%rbx), %rbp
movl %eax, %ebx
movq %rbx, %rax
shlq $0x4, %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rbp,%rax)
jmp 0x5bef
movl %r12d, %ebx
movq 0x38(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %r12
movq %r12, %rdx
leaq 0x4(%rsp), %rcx
xorl %r8d, %r8d
callq 0x9f07
testl %eax, %eax
jle 0x5c32
movq 0x10(%r12), %rdi
callq 0x2230
movq %rax, %r15
shlq $0x20, %r15
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rax, %r15
jmp 0x5c35
xorl %r15d, %r15d
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x4(%rsp), %r14
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x9f07
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x9f07
cmpl $0xa, 0x4(%rsp)
je 0x5ceb
movl 0xc(%r13), %eax
testl %eax, %eax
js 0x5cd7
cmpl $0x0, 0x10(%r13)
movl 0x8(%r13), %ecx
je 0x5c82
cmpl %eax, %ecx
jge 0x5cde
movq (%r13), %r14
cmpl %eax, %ecx
jl 0x5cb5
movl $0x0, 0x8(%r13)
movq 0x18(%r13), %rdi
movq %r14, %rsi
movl $0x4000, %edx           # imm = 0x4000
callq 0x2180
testl %eax, %eax
je 0x5d75
xorl %ecx, %ecx
testl %eax, %eax
js 0x5d8d
leal 0x1(%rcx), %edx
movl %edx, 0x8(%r13)
movslq %ecx, %rcx
movzbl (%r14,%rcx), %ecx
movl %ecx, 0x4(%rsp)
cmpl $0xa, %ecx
je 0x5cd1
testl %ecx, %ecx
jne 0x5c6f
movl %eax, 0xc(%r13)
jmp 0x5ceb
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
jmp 0x5ce3
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %eax, 0xc(%r13)
movl %ecx, 0x4(%rsp)
callq 0x2290
movq (%rax), %rax
movq 0x10(%r12), %r14
movsbq (%r14), %rcx
testb $0x4, 0x1(%rax,%rcx,2)
je 0x5d56
cmpq $0x1, (%r12)
jne 0x5d56
shlq $0x4, %rbx
addq %rbp, %rbx
movl (%rbx), %edx
cmpl 0x4(%rbx), %edx
jne 0x5d43
leal (%rdx,%rdx), %eax
testl %edx, %edx
movl $0x4, %ecx
cmovel %ecx, %eax
movl %eax, 0x4(%rbx)
movq 0x8(%rbx), %rdi
shll $0x3, %eax
movslq %eax, %rsi
callq 0x2200
movq %rax, 0x8(%rbx)
movsbq (%r14), %rcx
movl (%rbx), %edx
jmp 0x5d47
movq 0x8(%rbx), %rax
orq %rcx, %r15
leal 0x1(%rdx), %ecx
movl %ecx, (%rbx)
movslq %edx, %rcx
movq %r15, (%rax,%rcx,8)
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
leaq 0x4(%rsp), %rcx
xorl %r8d, %r8d
callq 0x9f07
testl %eax, %eax
jns 0x5ac2
jmp 0x5da3
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xc(%r13)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x5ce7
movl %eax, 0xc(%r13)
movl $0x1, 0x10(%r13)
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
jmp 0x5ce7
movq (%r13), %rdi
callq 0x2050
movq %r13, %rdi
callq 0x2050
movq 0x48(%rsp), %rdi
callq 0x2040
movq 0x10(%r12), %rdi
callq 0x2050
movq %r12, %rdi
callq 0x2050
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
cmpb $0x2d, (%rdi)
jne 0x5de8
cmpb $0x0, 0x1(%rdi)
je 0x60b0
leaq 0x53b9(%rip), %rsi      # 0xb1a8
callq 0x2220
testq %rax, %rax
je 0x60e0
movq %rbp, 0x18(%rsp)
movq %rax, 0x30(%rsp)
movq %rax, %rdi
callq 0x3edd
movq %rax, %r12
movq %rax, %rdi
callq 0x3f27
testl %eax, %eax
js 0x5fe8
movl %eax, %edx
movq 0x8(%rsp), %rax
movl (%rax), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x14(%rsp)
movq %rax, 0x28(%rsp)
movq %r12, 0x20(%rsp)
movl %edx, 0x38(%rsp)
movq 0x10(%r12), %rbx
movl $0x0, %r13d
testl %eax, %eax
je 0x5f0d
movsbl (%rbx), %ebp
testl %ebp, %ebp
je 0x5e7c
movb 0x1(%rbx), %al
testb %al, %al
je 0x5e7e
leaq 0x2(%rbx), %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 0x5e65
jmp 0x5e7e
xorl %ebp, %ebp
movl %ebp, %edi
movl 0x14(%rsp), %ecx
andl %ecx, %edi
movl %ebp, %eax
shrl $0x3, %eax
shll $0x3, %ebp
xorl %eax, %ebp
orl $0x1, %ebp
andl %ecx, %ebp
movq 0x8(%rsp), %rax
movq 0x10(%rax), %r15
movl %edi, %r13d
movl %edi, 0x40(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %r12d
leal (,%r13,2), %r14d
andl $0x1e, %r14d
movl %r12d, %eax
movl %r14d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x5efa
testb $0x1, %al
jne 0x5eeb
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x2170
movl 0x40(%rsp), %edi
testl %eax, %eax
je 0x5efa
addl %ebp, %r13d
andl 0x14(%rsp), %r13d
cmpl %edi, %r13d
jne 0x5ea5
jmp 0x5f64
movl %r14d, %ecx
shrl %cl, %r12d
testb $0x3, %r12b
movq 0x28(%rsp), %rax
cmovnel %eax, %r13d
cmpl %eax, %r13d
je 0x5f64
movl %r13d, %eax
shlq $0x4, %rax
movq 0x18(%rsp), %rcx
movl (%rcx,%rax), %ecx
testl %ecx, %ecx
jle 0x5f64
addq 0x18(%rsp), %rax
movq 0x20(%rsp), %rdx
movq 0x30(%rdx), %rdx
xorl %r9d, %r9d
movq 0x8(%rax), %rdi
movq (%rdi,%r9,8), %rdi
movq %rdi, %r8
sarq $0x20, %r8
cmpq %rdx, %r8
jae 0x5f59
movq 0x20(%rsp), %rcx
movq 0x40(%rcx), %rcx
movb %dil, (%rcx,%r8)
movl (%rax), %ecx
incq %r9
movslq %ecx, %rdi
cmpq %rdi, %r9
jl 0x5f36
leaq 0x5539(%rip), %rdi      # 0xb4a4
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movl 0x38(%rsp), %eax
testl %eax, %eax
movq 0x20(%rsp), %r12
movl $0x88888889, %r13d      # imm = 0x88888889
jle 0x5fc7
movl %eax, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %r15d, %eax
imulq %r13, %rax
shrq $0x25, %rax
imull $0x3c, %eax, %eax
addl %r14d, %eax
jne 0x5fad
movl $0xa, %edi
callq 0x2060
movq 0x40(%r12), %rax
movsbl (%rax,%r15), %edi
callq 0x2060
incq %r15
decl %r14d
cmpq %r15, %rbx
jne 0x5f90
movl $0xa, %edi
callq 0x2060
movq %r12, %rdi
callq 0x3f27
movl %eax, %edx
testl %eax, %eax
movq 0x28(%rsp), %rax
jns 0x5e3c
movq %r12, %rdi
callq 0x428d
movq 0x30(%rsp), %rdi
callq 0x2040
movq 0x8(%rsp), %rax
movl (%rax), %ebx
movq 0x10(%rax), %r15
testq %rbx, %rbx
movq 0x18(%rsp), %r13
je 0x6057
movl $0x1, %r14d
xorl %r12d, %r12d
movl %r12d, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %eax
leal -0x1(%r14), %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0x604b
movq (%r13,%r14,8), %rdi
callq 0x2050
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0x2050
incq %r12
addq $0x2, %r14
cmpq %r12, %rbx
jne 0x6018
movq 0x8(%rsp), %rbx
movq 0x18(%rbx), %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9f33(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x5104(%rip), %rsi      # 0xb1a8
movl %eax, %edi
callq 0x20b0
jmp 0x5a5d
movq 0x9f11(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x50e2(%rip), %rsi      # 0xb1a8
movl %eax, %edi
callq 0x20b0
jmp 0x5df4
callq 0x26f7
jmp 0x60e5
callq 0x26d8
jmp 0x60e5
callq 0x26b3
movl $0x1, %eax
jmp 0x607f