// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/trim.c
// Function: main
int main(int argc, char *argv[])
{
	int c;
	lt_global_t g;
	gzFile fp;
	char *p, *pe_prefix = 0, *fn_bc = 0;

	lt_global_init(&g);
	while ((c = getopt(argc, argv, "dt:b:l:o:p:B:T:P")) >= 0) {
		if (c == 't') g.opt.n_threads = atoi(optarg);
		else if (c == 'd') g.opt.tab_out = 1;
		else if (c == 'P') g.opt.retain_pe = 1;
		else if (c == 'l') g.opt.min_seq_len = atoi(optarg);
		else if (c == 'o') g.opt.min_ovlp_len = atoi(optarg);
		else if (c == 'p') pe_prefix = optarg;
		else if (c == 'b') fn_bc = optarg;
		else if (c == 'T') g.opt.trim_len = atoi(optarg);
		else if (c == 'B') {
			g.opt.bc_len[0] = g.opt.bc_len[1] = strtol(optarg, &p, 10);
			if (*p == ',') g.opt.bc_len[1] = strtol(p+1, &p, 10);
		}
	}
	if (argc - optind < 1) {
		fprintf(stderr, "Usage: seqtk mergepe <read1.fq> <read2.fq> | adna-trim [options] -\n");
		fprintf(stderr, "Options:\n");
		fprintf(stderr, "  -b FILE      barcode file (overriding -B) []\n");
		fprintf(stderr, "  -B INT[,INT] barcode length [%d,%d]\n", g.opt.bc_len[0], g.opt.bc_len[1]);
		fprintf(stderr, "  -t INT       number of threads [%d]\n", g.opt.n_threads);
		fprintf(stderr, "  -l INT       min read/fragment length to output [%d]\n", g.opt.min_seq_len);
		fprintf(stderr, "  -o INT       min overlap length [%d]\n", g.opt.min_ovlp_len);
		fprintf(stderr, "  -p STR       output PE reads to STR.R[12].fq.gz (overriding -P) [discard pe]\n");
		fprintf(stderr, "  -T INT       trim INT-bp [%d]\n", g.opt.trim_len);
		fprintf(stderr, "  -P           output paired reads also to stdout [discard pe]\n");
		fprintf(stderr, "  -d           tabular output for debugging\n");
		return 1;
	}

	fp = strcmp(argv[optind], "-")? gzopen(argv[optind], "r") : gzdopen(fileno(stdin), "r");
	g.ks = kseq_init(fp);
	if (fn_bc) g.bc = ad_bc_read(fn_bc), g.opt.bc_len[0] = g.opt.bc_len[1] = 0;
	if (pe_prefix) {
		kstring_t str = {0,0,0};
		for (c = 0; c < 2; ++c) {
			str.l = 0;
			ksprintf(&str, "%s.R%d.fq.gz", pe_prefix, c+1);
			g.fp_pe[c] = gzopen(str.s, "w1");
		}
		g.opt.retain_pe = 0;
	}

	kt_pipeline(2, worker_pipeline, &g, 3);
	for (c = 0; c <= AD_MAX_TYPE; ++c)
		if (g.types[c] > 0)
			fprintf(stderr, "[M::%s] %2d  %ld\n", __func__, c, (long)g.types[c]);

	if (g.fp_pe[0]) gzclose(g.fp_pe[0]);
	if (g.fp_pe[1]) gzclose(g.fp_pe[1]);
	kseq_destroy(g.ks);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x78(%rsp), %r14
movq $0x0, 0x28(%rsp)
movl $0x178, %edx            # imm = 0x178
movq %r14, %rdi
xorl %esi, %esi
callq 0x2110
movaps 0xddd(%rip), %xmm0      # 0x5020
movaps %xmm0, -0x28(%r14)
movaps 0xde1(%rip), %xmm0      # 0x5030
movaps %xmm0, -0x18(%r14)
andq $0x0, -0x8(%r14)
pushq $0x2
popq %rax
movl %eax, 0x14(%rsp)
pushq $0x1e
popq %rax
movl %eax, 0x18(%rsp)
pushq $0xa
popq %rax
leaq 0xe96(%rip), %r12       # 0x5107
movq 0x3d60(%rip), %r15      # 0x7fd8
leaq 0xdc1(%rip), %r13       # 0x5040
movl %eax, 0x1c(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x30(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2220
testl %eax, %eax
js 0x43b2
leal -0x6c(%rax), %ecx
cmpl $0x8, %ecx
jbe 0x42e9
cmpl $0x42, %eax
je 0x433e
cmpl $0x50, %eax
je 0x43a2
cmpl $0x54, %eax
je 0x438c
cmpl $0x62, %eax
je 0x4331
cmpl $0x64, %eax
jne 0x42a1
movl $0x1, 0x7c(%rsp)
jmp 0x42a1
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x2230
movl %eax, 0x18(%rsp)
movl %eax, 0x58(%rsp)
jmp 0x42a1
movq (%r15), %r14
jmp 0x42a1
movq (%r15), %rdi
callq 0x2230
movl %eax, 0x14(%rsp)
movl %eax, 0x50(%rsp)
jmp 0x42a1
movq (%r15), %rdi
callq 0x2230
movl %eax, 0x1c(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x42a1
movq (%r15), %rax
movq %rax, 0x30(%rsp)
jmp 0x42a1
movq (%r15), %rdi
leaq 0x38(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x2150
movl %eax, 0x74(%rsp)
movl %eax, 0x70(%rsp)
movq 0x38(%rsp), %rdi
cmpb $0x2c, (%rdi)
movq %rax, 0x20(%rsp)
movq %rax, 0x8(%rsp)
jne 0x42a1
incq %rdi
leaq 0x38(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x2150
movq %rax, 0x8(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x42a1
movq (%r15), %rdi
callq 0x2230
movq %rax, 0x28(%rsp)
movl %eax, 0x78(%rsp)
jmp 0x42a1
movl $0x1, 0x80(%rsp)
jmp 0x42a1
movq 0x3c17(%rip), %rax      # 0x7fd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x4594
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x43d7
cmpb $0x0, 0x1(%rdi)
je 0x4572
leaq 0xce4(%rip), %rsi       # 0x50c2
callq 0x2200
movq %rax, %rbx
pushq $0x1
popq %rdi
pushq $0x50
popq %rsi
callq 0x2120
movq %rax, %r15
movq %rbx, %rdi
callq 0x379d
movq %rax, 0x48(%r15)
movq %r15, 0x88(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4425
callq 0x3574
movq %rax, 0x1e8(%rsp)
andq $0x0, 0x70(%rsp)
testq %r14, %r14
je 0x4493
movq %rbx, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r15
movaps %xmm0, (%r15)
leaq 0xee0(%rip), %r12       # 0x5322
leaq 0xee6(%rip), %r13       # 0x532f
xorl %ebp, %ebp
cmpq $0x2, %rbp
je 0x4486
andl $0x0, 0x40(%rsp)
leaq 0x1(%rbp), %rbx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x4694
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x2200
movq %rax, 0x90(%rsp,%rbp,8)
movq %rbx, %rbp
jmp 0x444b
andl $0x0, 0x80(%rsp)
movq 0x8(%rsp), %rbx
leaq 0x311(%rip), %rsi       # 0x47ab
pushq $0x2
popq %rdi
leaq 0x50(%rsp), %rdx
pushq $0x3
popq %rcx
callq 0x2529
movq 0x3b47(%rip), %r13      # 0x7ff8
leaq 0xe7a(%rip), %r14       # 0x5332
leaq 0xe85(%rip), %r15       # 0x5344
xorl %r12d, %r12d
cmpq $0x29, %r12
je 0x44f0
movq 0xa0(%rsp,%r12,8), %r8
testq %r8, %r8
jne 0x44da
incq %r12
jmp 0x44c2
movq (%r13), %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2140
jmp 0x44d5
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x4502
callq 0x2040
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x4514
callq 0x2040
movq 0x88(%rsp), %r14
testq %r14, %r14
je 0x4556
movq 0x8(%r14), %rdi
callq 0x2050
movq 0x18(%r14), %rdi
callq 0x2050
movq 0x28(%r14), %rdi
callq 0x2050
movq 0x38(%r14), %rdi
callq 0x2050
movq 0x48(%r14), %rdi
callq 0x37de
movq %r14, %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3a4f(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
callq 0x2170
leaq 0xb3a(%rip), %rsi       # 0x50c2
movl %eax, %edi
callq 0x20b0
jmp 0x43e3
movq 0x3a5d(%rip), %r14      # 0x7ff8
movq (%r14), %rcx
leaq 0xb73(%rip), %rdi       # 0x5118
pushq $0x43
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2240
movq (%r14), %rcx
leaq 0xb9f(%rip), %rdi       # 0x515c
pushq $0x9
popq %rsi
movq %rbx, %rdx
callq 0x2240
movq (%r14), %rcx
leaq 0xb94(%rip), %rdi       # 0x5166
pushq $0x2f
popq %rsi
movq %rbx, %rdx
callq 0x2240
movq (%r14), %rdi
leaq 0xbaf(%rip), %rsi       # 0x5196
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %eax, %eax
callq 0x2140
movq (%r14), %rdi
leaq 0xbbb(%rip), %rsi       # 0x51bd
movl 0x14(%rsp), %edx
xorl %eax, %eax
callq 0x2140
movq (%r14), %rdi
leaq 0xbcd(%rip), %rsi       # 0x51e4
movl 0x18(%rsp), %edx
xorl %eax, %eax
callq 0x2140
movq (%r14), %rdi
leaq 0xbf0(%rip), %rsi       # 0x521c
movl 0x1c(%rsp), %edx
xorl %eax, %eax
callq 0x2140
movq (%r14), %rcx
leaq 0xc03(%rip), %rdi       # 0x5244
pushq $0x4f
popq %rsi
movq %rbx, %rdx
callq 0x2240
movq (%r14), %rdi
leaq 0xc3e(%rip), %rsi       # 0x5294
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x2140
movq (%r14), %rcx
leaq 0xc49(%rip), %rdi       # 0x52b5
pushq $0x3f
popq %rsi
movq %rbx, %rdx
callq 0x2240
movq (%r14), %rcx
leaq 0xc74(%rip), %rdi       # 0x52f5
pushq $0x2c
popq %rsi
movq %rbx, %rdx
callq 0x2240
pushq $0x1
popq %rax
jmp 0x4560