// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/trim.c
// Function: ad_bc_read
ad_barcode_t *ad_bc_read(const char *fn)
{
	gzFile fp;
	kstream_t *ks;
	kstring_t s = {0,0,0};
	ad_barcode_t *bc = 0;
	int dret, i, len[2];
	kvec_t(cstr_t) x[2];

	fp = gzopen(fn, "r");
	if (fp == 0) return 0;
	ks = ks_init(fp);
	kv_init(x[0]); kv_init(x[1]);
	len[0] = len[1] = 0;
	for (i = 0; i < 2; ++i) {
		int j, j0;
		if (ks_getuntil(ks, KS_SEP_LINE, &s, &dret) < 0) break;
		for (j = j0 = 0; j <= s.l; ++j) {
			if (j == s.l || ispunct(s.s[j])) {
				s.s[j] = 0;
				if (len[i] == 0) len[i] = j - j0;
				else if (len[i] != j - j0) {
					j0 = j + 1;
					continue;
				}
				if (len[i] > 0) kv_push(cstr_t, x[i], strdup(&s.s[j0]));
				j0 = j + 1;
			}
		}
	}
	free(s.s);
	ks_destroy(ks);
	gzclose(fp);

	fprintf(stderr, "[M::%s] read %ld read1 barcodes and %ld read2 barcodes\n", __func__, x[0].n, x[1].n);

	bc = (ad_barcode_t*)calloc(1, sizeof(ad_barcode_t));
	for (i = 0; i < 2; ++i) {
		int j;
		bc->n[i] = x[i].n, bc->len[i] = len[i];
		bc->bc[i] = (lt_seqcloud_t**)calloc(bc->n[i], sizeof(lt_seqcloud_t*));
		for (j = 0; j < x[i].n; ++j)
			bc->bc[i][j] = lt_sc_gen(x[i].a[j]);
		bc->seq[i] = x[i].a;
	}
	return bc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x1b2e(%rip), %rsi      # 0x50c2
callq 0x2200
testq %rax, %rax
jne 0x35b5
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x379d
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, (%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0x36ea
movq 0x8(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x10(%rsp), %rdx
leaq 0x4c(%rsp), %rcx
callq 0x37d6
movq 0x18(%rsp), %r12
testl %eax, %eax
js 0x36ea
movl 0x10(%rsp), %ebp
imulq $0x18, %rbx, %rax
leaq (%rsp,%rax), %r14
addq $0x50, %r14
leaq 0x1(%rbp), %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %rbx, 0x38(%rsp)
movq %rbp, 0x30(%rsp)
cmpq %r15, 0x40(%rsp)
je 0x36e2
cmpq %r15, %rbp
je 0x365d
callq 0x2290
movq (%rax), %rax
movsbq (%r12,%r15), %rcx
testb $0x4, (%rax,%rcx,2)
je 0x36da
movb $0x0, (%r12,%r15)
movl (%rsp,%rbx,4), %eax
movl %r13d, %ecx
negl %ecx
addq %r15, %rcx
testl %eax, %eax
je 0x3677
cmpl %eax, %ecx
je 0x367c
jmp 0x36d6
movl %ecx, (%rsp,%rbx,4)
movl %ecx, %eax
testl %eax, %eax
jle 0x36d6
movq (%r14), %rbp
movq 0x10(%r14), %rbx
cmpq 0x8(%r14), %rbp
jne 0x36b6
leaq (,%rbp,2), %rsi
testq %rbp, %rbp
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rbx
movq %rax, 0x10(%r14)
movslq %r13d, %rdi
addq %r12, %rdi
callq 0x2260
leaq 0x1(%rbp), %rcx
movq %rcx, (%r14)
movq %rax, (%rbx,%rbp,8)
movq 0x38(%rsp), %rbx
movq 0x30(%rsp), %rbp
leal 0x1(%r15), %r13d
incq %r15
jmp 0x363a
incq %rbx
jmp 0x35e3
movq %r12, %rdi
callq 0x2050
movq 0x8(%rsp), %rdi
callq 0x37de
movq 0x28(%rsp), %rdi
callq 0x2040
movq 0x48eb(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x50(%rsp), %rcx
movq 0x68(%rsp), %r8
leaq 0x19a3(%rip), %rsi      # 0x50c4
leaq 0x19d4(%rip), %rdx      # 0x50fc
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x2140
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x2120
movq %rax, %rbx
cmpq $0x2, %r12
je 0x35a0
imulq $0x18, %r12, %r14
movq 0x50(%rsp,%r14), %r13
movl %r13d, (%rbx,%r12,4)
movl (%rsp,%r12,4), %eax
movl %eax, 0x8(%rbx,%r12,4)
movslq %r13d, %rdi
pushq $0x8
popq %rsi
callq 0x2120
movq %rax, %r15
movq %rax, 0x10(%rbx,%r12,8)
movq 0x60(%rsp,%r14), %rbp
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x3793
movq (%rbp,%r14,8), %rdi
callq 0x2bbf
movq %rax, (%r15,%r14,8)
incq %r14
jmp 0x377b
movq %rbp, 0x20(%rbx,%r12,8)
incq %r12
jmp 0x3740