// File: /workspace/github_c_makefile_star2_O1/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, 0x20(%rsp)
leaq 0x2b6f(%rip), %rsi      # 0x60c6
callq 0x2210
testq %rax, %rax
jne 0x3578
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r14
movq %rbx, 0x38(%rsp)
movq %rbx, 0x10(%rax)
movl 0x8(%rax), %eax
andl $0x3, %eax
orl $0x10000, %eax          # imm = 0x10000
movl %eax, 0x8(%r14)
movl $0x4000, %edi           # imm = 0x4000
callq 0x21c0
movq %r14, 0x18(%rsp)
movq %rax, 0x18(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0xc(%rsp)
xorl %r13d, %r13d
movq 0x18(%rsp), %rdi
movl $0x2, %esi
leaq 0x20(%rsp), %rdx
leaq 0x4c(%rsp), %rcx
xorl %r8d, %r8d
callq 0x5337
testl %eax, %eax
js 0x36f0
movl %eax, 0x14(%rsp)
movl 0x20(%rsp), %ebx
movq 0x28(%rsp), %r12
leaq (,%r13,2), %rax
addq %r13, %rax
leaq (%rsp,%rax,8), %r14
addq $0x50, %r14
leal 0x1(%rbx), %eax
movq %rax, (%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %r13, 0x40(%rsp)
cmpq %rbp, %rbx
je 0x3647
callq 0x22a0
movq (%rax), %rax
movsbq (%r12,%rbp), %rcx
testb $0x4, (%rax,%rcx,2)
je 0x36cc
movb $0x0, (%r12,%rbp)
movl 0xc(%rsp,%r13,4), %eax
testl %eax, %eax
je 0x3660
movl %ebp, %ecx
subl %r15d, %ecx
cmpl %eax, %ecx
je 0x366a
jmp 0x36c8
movl %ebp, %eax
subl %r15d, %eax
movl %eax, 0xc(%rsp,%r13,4)
cmpl $0x0, 0xc(%rsp,%r13,4)
jle 0x36c8
movq %rbx, %r13
movq (%r14), %rbx
movq 0x8(%r14), %rax
cmpq %rax, %rbx
jne 0x36a6
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x21e0
movq %rax, 0x10(%r14)
movslq %r15d, %rdi
addq %r12, %rdi
callq 0x2270
movq 0x10(%r14), %rcx
leaq 0x1(%rbx), %rdx
movq %rdx, (%r14)
movq %rax, (%rcx,%rbx,8)
movq %r13, %rbx
movq 0x40(%rsp), %r13
leal 0x1(%rbp), %r15d
incq %rbp
cmpq %rbp, (%rsp)
jne 0x362b
cmpl $0x0, 0x14(%rsp)
js 0x36f0
leaq 0x1(%r13), %rax
testq %r13, %r13
movq %rax, %r13
je 0x35d6
movq 0x28(%rsp), %rdi
callq 0x2050
movq 0x18(%rsp), %rdi
callq 0x37c6
movq 0x38(%rsp), %rdi
callq 0x2040
movq 0x48e3(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x50(%rsp), %rcx
movq 0x68(%rsp), %r8
leaq 0x299f(%rip), %rsi      # 0x60c8
leaq 0x29d0(%rip), %rdx      # 0x6100
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x2150
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %rbx
leaq (%r15,%r15,2), %rax
leaq (%rsp,%rax,8), %rax
addq $0x50, %rax
movq %rax, (%rsp)
movq (%rax), %r13
movl %r13d, (%rbx,%r15,4)
movl 0xc(%rsp,%r15,4), %eax
movl %eax, 0x8(%rbx,%r15,4)
movslq %r13d, %rdi
movl $0x8, %esi
callq 0x2120
movq %rax, 0x10(%rbx,%r15,8)
testq %r13, %r13
je 0x37a8
movq %rax, %r14
movq (%rsp), %rax
movq 0x10(%rax), %rbp
xorl %r12d, %r12d
movq (%rbp,%r12,8), %rdi
callq 0x29bc
movq %rax, (%r14,%r12,8)
incq %r12
cmpq %r12, %r13
jne 0x3792
movq (%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rbx,%r15,8)
leaq 0x1(%r15), %rax
testq %r15, %r15
movq %rax, %r15
je 0x374c
jmp 0x3563