// File: /workspace/github_c_makefile_star2_O0/aokad[P]sequeeze/seqtk.c
// Function: stk_subseq
int stk_subseq(int argc, char *argv[])
{
	khash_t(reg) *h = kh_init(reg);
	gzFile fp;
	kseq_t *seq;
	int l, i, j, c, is_tab = 0, line = 0;
	khint_t k;
	while ((c = getopt(argc, argv, "tl:")) >= 0) {
		switch (c) {
		case 't': is_tab = 1; break;
		case 'l': line = atoi(optarg); break;
		}
	}
	if (optind + 2 > argc) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   seqtk subseq [options] <in.fa> <in.bed>|<name.list>\n\n");
		fprintf(stderr, "Options: -t       TAB delimited output\n");
		fprintf(stderr, "         -l INT   sequence line length [%d]\n\n", line);
		fprintf(stderr, "Note: Use 'samtools faidx' if only a few regions are intended.\n\n");
		return 1;
	}
	h = stk_reg_read(argv[optind+1]);
	if (h == 0) {
		fprintf(stderr, "[E::%s] failed to read the list of regions in file '%s'\n", __func__, argv[optind+1]);
		return 1;
	}
	// subseq
	fp = strcmp(argv[optind], "-")? gzopen(argv[optind], "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)) continue;
		p = &kh_val(h, k);
		for (i = 0; i < p->n; ++i) {
			int beg = p->a[i]>>32, end = p->a[i];
			if (beg >= seq->seq.l) {
				fprintf(stderr, "[subseq] %s: %d >= %ld\n", seq->name.s, beg, seq->seq.l);
				continue;
			}
			if (end > seq->seq.l) end = seq->seq.l;
			if (is_tab == 0) {
				printf("%c%s", seq->qual.l == seq->seq.l? '@' : '>', seq->name.s);
				if (beg > 0 || (int)p->a[i] != INT_MAX) {
					if (end == INT_MAX) {
						if (beg) printf(":%d", beg+1);
					} else printf(":%d-%d", beg+1, end);
				}
				if (seq->comment.l) printf(" %s", seq->comment.s);
			} else printf("%s\t%d\t", seq->name.s, beg + 1);
			if (end > seq->seq.l) end = seq->seq.l;
			for (j = 0; j < end - beg; ++j) {
				if (is_tab == 0 && (j == 0 || (line > 0 && j % line == 0))) putchar('\n');
				putchar(seq->seq.s[j + beg]);
			}
			putchar('\n');
			if (seq->qual.l != seq->seq.l || is_tab) continue;
			printf("+");
			for (j = 0; j < end - beg; ++j) {
				if (j == 0 || (line > 0 && j % line == 0)) putchar('\n');
				putchar(seq->qual.s[j + beg]);
			}
			putchar('\n');
		}
	}
	// free
	kseq_destroy(seq);
	gzclose(fp);
	stk_reg_destroy(h);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0xb1c0
movq %rax, -0x18(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x8bcb(%rip), %rdx      # 0xd65f
callq 0x2240
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
jl 0x4ad5
movl -0x38(%rbp), %eax
movl %eax, -0x5c(%rbp)
subl $0x6c, %eax
je 0x4ac1
jmp 0x4aae
movl -0x5c(%rbp), %eax
subl $0x74, %eax
jne 0x4ad3
jmp 0x4ab8
movl $0x1, -0x3c(%rbp)
jmp 0x4ad3
movq 0xc510(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x2250
movl %eax, -0x40(%rbp)
jmp 0x4a86
movq 0xc4f4(%rip), %rax      # 0x10fd0
movl (%rax), %eax
addl $0x2, %eax
cmpl -0x8(%rbp), %eax
jle 0x4b71
movq 0xc507(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8c3c(%rip), %rsi      # 0xd737
movb $0x0, %al
callq 0x2190
movq 0xc4ef(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8b50(%rip), %rsi      # 0xd663
movb $0x0, %al
callq 0x2190
movq 0xc4d7(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8b77(%rip), %rsi      # 0xd6a2
movb $0x0, %al
callq 0x2190
movq 0xc4bf(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movl -0x40(%rbp), %edx
leaq 0x8b84(%rip), %rsi      # 0xd6ca
movb $0x0, %al
callq 0x2190
movq 0xc4a4(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8b9a(%rip), %rsi      # 0xd6f8
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x4f8c
movq -0x10(%rbp), %rax
movq 0xc454(%rip), %rcx      # 0x10fd0
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x23a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4bda
movq 0xc459(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xc423(%rip), %rcx      # 0x10fd0
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x8b79(%rip), %rsi      # 0xd739
leaq 0x8bab(%rip), %rdx      # 0xd772
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x4f8c
movq -0x10(%rbp), %rax
movq 0xc3eb(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x98a3(%rip), %rsi      # 0xe496
callq 0x2170
cmpl $0x0, %eax
je 0x4c21
movq -0x10(%rbp), %rax
movq 0xc3c8(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x866a(%rip), %rsi      # 0xd280
callq 0x2220
movq %rax, -0x68(%rbp)
jmp 0x4c42
movq 0xc3a0(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
leaq 0x8647(%rip), %rsi      # 0xd280
callq 0x20b0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4c7c
movq 0xc3a0(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8b1b(%rip), %rsi      # 0xd77d
leaq 0x8b09(%rip), %rdx      # 0xd772
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x4f8c
movq -0x20(%rbp), %rdi
callq 0x38f0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3930
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jl 0x4f6a
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2760
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x4cbf
jmp 0x4c89
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x4f65
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x58(%rbp)
movslq -0x54(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jb 0x4d53
movq 0xc2ce(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x54(%rbp), %ecx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %r8
leaq 0x8a64(%rip), %rsi      # 0xd7ab
movb $0x0, %al
callq 0x2190
jmp 0x4f57
movslq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jbe 0x4d6c
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x4e2a
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdx
movl $0x3e, %esi
movl $0x40, %eax
cmpq %rdx, %rcx
cmovel %eax, %esi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x8a1e(%rip), %rdi      # 0xd7c3
movb $0x0, %al
callq 0x20f0
cmpl $0x0, -0x54(%rbp)
jg 0x4dc9
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x4e07
cmpl $0x7fffffff, -0x58(%rbp) # imm = 0x7FFFFFFF
jne 0x4dee
cmpl $0x0, -0x54(%rbp)
je 0x4dec
movl -0x54(%rbp), %esi
addl $0x1, %esi
leaq 0x89e3(%rip), %rdi      # 0xd7c8
movb $0x0, %al
callq 0x20f0
jmp 0x4e05
movl -0x54(%rbp), %esi
addl $0x1, %esi
movl -0x58(%rbp), %edx
leaq 0x984e(%rip), %rdi      # 0xe64c
movb $0x0, %al
callq 0x20f0
jmp 0x4e07
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x4e28
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
leaq 0x89ab(%rip), %rdi      # 0xd7cc
movb $0x0, %al
callq 0x20f0
jmp 0x4e46
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x54(%rbp), %edx
addl $0x1, %edx
leaq 0x8991(%rip), %rdi      # 0xd7d0
movb $0x0, %al
callq 0x20f0
movslq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jbe 0x4e5f
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x58(%rbp), %ecx
subl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4ec0
cmpl $0x0, -0x3c(%rbp)
jne 0x4e9b
cmpl $0x0, -0x34(%rbp)
je 0x4e91
cmpl $0x0, -0x40(%rbp)
jle 0x4e9b
movl -0x34(%rbp), %eax
cltd
idivl -0x40(%rbp)
cmpl $0x0, %edx
jne 0x4e9b
movl $0xa, %edi
callq 0x2050
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x34(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %edi
callq 0x2050
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4e66
movl $0xa, %edi
callq 0x2050
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jne 0x4ee2
cmpl $0x0, -0x3c(%rbp)
je 0x4ee4
jmp 0x4f57
leaq 0x85c8(%rip), %rdi      # 0xd4b3
movb $0x0, %al
callq 0x20f0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x58(%rbp), %ecx
subl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4f4d
cmpl $0x0, -0x34(%rbp)
je 0x4f1e
cmpl $0x0, -0x40(%rbp)
jle 0x4f28
movl -0x34(%rbp), %eax
cltd
idivl -0x40(%rbp)
cmpl $0x0, %edx
jne 0x4f28
movl $0xa, %edi
callq 0x2050
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x34(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %edi
callq 0x2050
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4ef9
movl $0xa, %edi
callq 0x2050
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x4cdc
jmp 0x4c89
movq -0x28(%rbp), %rdi
callq 0x3d40
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rdi
callq 0x2d10
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)