// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0xb1c0
movq %rax, -0x18(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x5ce5
movq 0xb360(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7d70(%rip), %rsi      # 0xda12
movb $0x0, %al
callq 0x2190
movq 0xb348(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7d7e(%rip), %rsi      # 0xda38
movb $0x0, %al
callq 0x2190
movq 0xb330(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7da9(%rip), %rsi      # 0xda7b
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x6213
movl $0x1, %edi
movl $0x18, %esi
callq 0x2160
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x878f(%rip), %rsi      # 0xe496
callq 0x2170
cmpl $0x0, %eax
je 0x5d2b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x7560(%rip), %rsi      # 0xd280
callq 0x2220
movq %rax, -0x80(%rbp)
jmp 0x5d4c
movq 0xb296(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
leaq 0x753d(%rip), %rsi      # 0xd280
callq 0x20b0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5d86
movq 0xb296(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x770d(%rip), %rsi      # 0xd479
leaq 0x7d39(%rip), %rdx      # 0xdaac
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x6213
movq -0x20(%rbp), %rdi
callq 0x26d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rdx
xorl %esi, %esi
leaq -0x3c(%rbp), %rcx
callq 0x2720
cmpl $0x0, %eax
jl 0x5f93
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2270
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x2760
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x5e14
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x28c0
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x4c(%rbp), %eax
shlq $0x4, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2120
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rdx
xorl %esi, %esi
leaq -0x3c(%rbp), %rcx
callq 0x2720
cmpl $0x0, %eax
jle 0x5e56
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2230
subq $0x1, %rax
movl %eax, -0x5c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rdx
xorl %esi, %esi
leaq -0x3c(%rbp), %rcx
callq 0x2720
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rdx
xorl %esi, %esi
leaq -0x3c(%rbp), %rcx
callq 0x2720
cmpl $0xa, -0x3c(%rbp)
je 0x5ebc
jmp 0x5e84
movq -0x30(%rbp), %rdi
callq 0x2bf0
movl %eax, %ecx
movl %ecx, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x81(%rbp)
jle 0x5eac
cmpl $0xa, -0x3c(%rbp)
setne %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x5eb8
jmp 0x5eba
jmp 0x5e84
jmp 0x5ebc
callq 0x2280
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x5f8e
movq -0x48(%rbp), %rax
cmpq $0x1, (%rax)
jne 0x5f8e
movq -0x68(%rbp), %rax
movl (%rax), %eax
movq -0x68(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x5f5b
movq -0x68(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x5f1c
movq -0x68(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
movl %eax, -0x88(%rbp)
jmp 0x5f29
movl $0x4, %eax
movl %eax, -0x88(%rbp)
jmp 0x5f29
movl -0x88(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x68(%rbp), %rax
movl 0x4(%rax), %eax
shll $0x3, %eax
movslq %eax, %rsi
callq 0x2200
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x5c(%rbp), %rdx
shlq $0x20, %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movsbq (%rax), %rax
orq %rax, %rdx
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x68(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x5d93
movq -0x30(%rbp), %rdi
callq 0x2ce0
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2040
movq -0x48(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x84cc(%rip), %rsi      # 0xe496
callq 0x2170
cmpl $0x0, %eax
je 0x5ff1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x729d(%rip), %rsi      # 0xd280
callq 0x2220
movq %rax, -0x90(%rbp)
jmp 0x6015
movq 0xafd0(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
leaq 0x7277(%rip), %rsi      # 0xd280
callq 0x20b0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6052
movq 0xafca(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7441(%rip), %rsi      # 0xd479
leaq 0x7a6d(%rip), %rdx      # 0xdaac
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x6213
movq -0x20(%rbp), %rdi
callq 0x38f0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3930
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jl 0x617e
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2760
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x6110
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x610e
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x74(%rbp)
movslq -0x74(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x6101
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb %al, %dl
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x74(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x6103
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x60b0
jmp 0x6110
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0x745d(%rip), %rdi      # 0xd57c
movb $0x0, %al
callq 0x20f0
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x616f
movl -0x38(%rbp), %eax
movl $0x3c, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x614f
movl $0xa, %edi
callq 0x2050
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x2050
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x612d
movl $0xa, %edi
callq 0x2050
jmp 0x605f
movq -0x28(%rbp), %rdi
callq 0x3d40
movq -0x20(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x6203
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl -0x4c(%rbp), %ecx
andl $0xf, %ecx
shll %ecx
shrl %cl, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x61f6
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2040
jmp 0x61f8
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6197
movq -0x18(%rbp), %rdi
callq 0x2db0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop