// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movq %rsi, %r15
movl %edi, %ebp
cmpl $0x1, %edi
jne 0x8315
movq 0x7cca(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
callq 0x2090
testl %eax, %eax
jne 0x8717
cmpl $0x2, %ebp
jl 0x8342
movq 0x8(%r15), %rbx
leaq 0x4089(%rip), %rsi      # 0xc3ae
movq %rbx, %rdi
callq 0x2170
testl %eax, %eax
je 0x8342
leaq 0x2e60(%rip), %rsi      # 0xb198
movq %rbx, %rdi
callq 0x2220
jmp 0x835f
movq 0x7c7f(%rip), %rax      # 0xffc8
movq (%rax), %rdi
callq 0x21b0
leaq 0x2e40(%rip), %rsi      # 0xb198
movl %eax, %edi
callq 0x20b0
testq %rax, %rax
je 0x8710
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x3e57
movq %rax, %r14
cmpl $0x3, %ebp
jl 0x8383
movq 0x10(%r15), %r15
jmp 0x8386
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %r14, %rdi
callq 0x3ea1
movl $0x1, %r12d
testl %eax, %eax
js 0x864b
leaq 0x20(%rsp), %r13
movq 0x20(%rsp), %rbp
testq %rbp, %rbp
je 0x84a2
movq (%r14), %rbx
cmpq %rbx, %rbp
jne 0x845a
movq %r12, 0x18(%rsp)
movq %r13, %r12
cmpq $0x3, %rbp
jb 0x8436
movq 0x30(%rsp), %r13
cmpb $0x2f, -0x2(%r13,%rbp)
jne 0x8436
movq 0x10(%r14), %rax
cmpb $0x2f, -0x2(%rax,%rbx)
jne 0x8436
movq %rax, 0x8(%rsp)
callq 0x2290
movq (%rax), %rax
movsbq -0x1(%r13,%rbp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
movq 0x8(%rsp), %rcx
je 0x8436
movsbq -0x1(%rcx,%rbx), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x8436
addq $-0x2, %rbp
movq 0x30(%rsp), %rbx
movq 0x10(%r14), %rsi
movslq %ebp, %rdx
movq %rbx, %rdi
callq 0x2070
testl %eax, %eax
movq %r12, %r13
movq 0x18(%rsp), %r12
je 0x851d
movq 0x68(%rsp), %rbx
xorl %eax, %eax
testq %rbx, %rbx
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
testq %r12, %r12
js 0x84af
testq %r15, %r15
je 0x848f
movq 0x7b3c(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2110
leaq 0x40dd(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x84c3
movq %r13, %rdi
movq %r14, %rsi
callq 0x6ee7
jmp 0x8508
movq 0x30(%rsp), %rdi
movq 0x7b05(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2080
testq %rbx, %rbx
je 0x84fa
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x78(%rsp), %rdi
callq 0x2080
movq %r13, %rdi
movq %r14, %rsi
callq 0x6ee7
incq %r12
movq %r14, %rdi
callq 0x3ea1
testl %eax, %eax
jns 0x83ca
jmp 0x864b
movq 0x68(%rsp), %rbp
xorl %eax, %eax
testq %rbp, %rbp
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
testq %r12, %r12
js 0x8565
testq %r15, %r15
je 0x8552
movq 0x7a79(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2110
leaq 0x401a(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x8577
movq 0x7a54(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2080
testq %rbp, %rbp
je 0x85ae
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x78(%rsp), %rdi
callq 0x2080
xorl %eax, %eax
cmpq $0x0, 0x48(%r14)
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
testq %r12, %r12
js 0x85f3
testq %r15, %r15
je 0x85e0
movq 0x79eb(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2110
leaq 0x3f8c(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x8606
movq 0x10(%r14), %rdi
movq 0x79c2(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x40(%r14), %rdi
callq 0x2080
cmpq $0x0, 0x48(%r14)
je 0x863d
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x58(%r14), %rdi
callq 0x2080
movq $0x0, 0x20(%rsp)
jmp 0x8505
cmpq $0x0, 0x20(%rsp)
je 0x86ea
movq 0x68(%rsp), %rbx
xorl %eax, %eax
testq %rbx, %rbx
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
testq %r12, %r12
js 0x869f
testq %r15, %r15
je 0x868c
movq 0x793f(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2110
leaq 0x3ee0(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x86b3
movq 0x30(%rsp), %rdi
movq 0x7915(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2080
testq %rbx, %rbx
je 0x86ea
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x78(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x4229
movq 0x10(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2d04
jmp 0x871c
callq 0x2ce8
movl $0x1, %eax
jmp 0x86fe