// File: /workspace/github_c_makefile_star2_O2/aokad[P]sequeeze/seqtk.c
// Function: stk_rename
int stk_rename(int argc, char *argv[])
{
	gzFile fp;
	kseq_t *seq, last;
	char *prefix = 0;
	uint64_t n = 1;

	if (argc == 1 && isatty(fileno(stdin))) {
		fprintf(stderr, "Usage: seqtk rename <in.fq> [prefix]\n");
		return 1;
	}
	fp = argc > 1 && 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);
	if (argc > 2) prefix = argv[2];

	memset(&last, 0, sizeof(kseq_t));
	while (kseq_read(seq) >= 0) {
		if (last.name.l) {
			kstring_t *p = &last.name, *q = &seq->name;
			int is_diff;
			if (p->l == q->l) {
				int l = (p->l > 2 && p->s[p->l-2] == '/' && q->s[q->l-2] == '/' && isdigit(p->s[p->l-1]) && isdigit(q->s[q->l-1]))? p->l - 2 : p->l;
				is_diff = strncmp(p->s, q->s, l);
			} else is_diff = 1;
			if (!is_diff) {
				stk_printseq_renamed(&last, 0, prefix, n);
				stk_printseq_renamed(seq,   0, prefix, n);
				last.name.l = 0;
				++n;
			} else {
				stk_printseq_renamed(&last, 0, prefix, n);
				++n;
				cpy_kseq(&last, seq);
			}
		} else cpy_kseq(&last, seq);
	}
	if (last.name.l) stk_printseq_renamed(&last, 0, prefix, n);

	kseq_destroy(seq);
	gzclose(fp);
	// free last!
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r15
movl %edi, %ebp
cmpl $0x1, %edi
jne 0x700b
movq 0x6ff1(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
callq 0x2090
testl %eax, %eax
je 0x702a
movq 0x7007(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x331e(%rip), %rdi      # 0xa319
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x2260
jmp 0x71df
jle 0x702a
movq 0x8(%r15), %rdi
cmpb $0x2d, (%rdi)
jne 0x701c
cmpb $0x0, 0x1(%rdi)
je 0x702a
leaq 0x2185(%rip), %rsi      # 0x91a8
callq 0x2220
jmp 0x7047
movq 0x6f97(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x2168(%rip), %rsi      # 0x91a8
movl %eax, %edi
callq 0x20b0
movq %rax, %rbx
testq %rax, %rax
je 0x71c0
movq %rbx, %rdi
callq 0x3102
movq %rax, %r14
cmpl $0x3, %ebp
jl 0x7069
movq 0x10(%r15), %rbp
jmp 0x706b
xorl %ebp, %ebp
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, 0x60(%r13)
movaps %xmm0, 0x50(%r13)
movaps %xmm0, 0x40(%r13)
movaps %xmm0, 0x30(%r13)
movaps %xmm0, 0x20(%r13)
movaps %xmm0, 0x10(%r13)
movaps %xmm0, (%r13)
pushq $0x1
popq %r12
movq %r14, %rdi
callq 0x312e
movq 0x10(%rsp), %r15
testl %eax, %eax
js 0x7185
testq %r15, %r15
jne 0x70c1
movq %r13, %rdi
movq %r14, %rsi
callq 0x5dc4
jmp 0x709a
cmpq (%r14), %r15
jne 0x7121
movq %rbp, 0x8(%rsp)
movq 0x20(%rsp), %rbp
cmpq $0x2, %r15
jbe 0x7109
cmpb $0x2f, -0x2(%rbp,%r15)
movq 0x10(%r14), %rsi
jne 0x710d
cmpb $0x2f, -0x2(%rsi,%r15)
jne 0x710d
movq %rsi, (%rsp)
callq 0x2290
movq (%rax), %rax
movsbq -0x1(%rbp,%r15), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x716c
movq (%rsp), %rsi
jmp 0x710d
movq 0x10(%r14), %rsi
movslq %r15d, %rdx
movq %rbp, %rdi
callq 0x2070
testl %eax, %eax
movq 0x8(%rsp), %rbp
je 0x7144
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x71e4
movq %r13, %rdi
movq %r14, %rsi
callq 0x5dc4
incq %r12
jmp 0x709a
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x71e4
movq %r14, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x71e4
andq $0x0, 0x10(%rsp)
jmp 0x713c
leaq -0x2(%r15), %rcx
movq (%rsp), %rsi
movsbq -0x1(%rsi,%r15), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
cmovneq %rcx, %r15
jmp 0x710d
testq %r15, %r15
je 0x719c
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x71e4
movq %r14, %rdi
callq 0x3329
movq %rbx, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6e31(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x21d0(%rip), %rsi      # 0x93a1
leaq 0x3167(%rip), %rdx      # 0xa33f
xorl %eax, %eax
callq 0x2190
pushq $0x1
popq %rax
jmp 0x71ae