// File: /workspace/github_c_makefile_star2_O3/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 $0x98, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
leaq 0x29d2(%rip), %rsi      # 0x60e2
callq 0x2200
xorl %r15d, %r15d
testq %rax, %rax
jne 0x3732
movq %r15, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0x78(%rsp), %rbx
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
xorl %r12d, %r12d
movq %rax, %r15
movq %r14, 0x38(%rsp)
movq %r14, 0x10(%rax)
movl $0x10000, 0x8(%rax)     # imm = 0x10000
movl $0x4000, %edi           # imm = 0x4000
callq 0x21b0
movq %r15, 0x18(%rsp)
movq %rax, 0x18(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, -0x18(%rbx)
movaps %xmm0, -0x8(%rbx)
movaps %xmm0, 0x8(%rbx)
leaq 0x4(%rsp), %rax
movl %r12d, (%rax)
leaq 0x14(%rsp), %r15
movl %r12d, (%r15)
leaq 0x60(%rsp), %r14
movb $0x1, %bl
movq 0x18(%rsp), %rdi
movl $0x2, %esi
leaq 0x20(%rsp), %rdx
leaq 0x5c(%rsp), %rcx
xorl %r8d, %r8d
callq 0x5406
movq 0x28(%rsp), %r13
testl %eax, %eax
js 0x38b1
movq %r14, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl 0x20(%rsp), %r14d
leal 0x1(%r14), %ebp
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %r15, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
cmpq %r12, %r14
je 0x3804
callq 0x2290
movq (%rax), %rax
movsbq (%r13,%r12), %rcx
testb $0x4, (%rax,%rcx,2)
je 0x388b
movb $0x0, (%r13,%r12)
movl (%r15), %eax
movl %ebx, %ecx
negl %ecx
addq %r12, %rcx
testl %eax, %eax
je 0x381e
cmpl %eax, %ecx
je 0x3823
jmp 0x3886
movl %ecx, (%r15)
movl %ecx, %eax
testl %eax, %eax
jle 0x3886
movq 0x8(%rsp), %r14
movq (%r14), %r15
movq 0x10(%r14), %rbp
cmpq 0x8(%r14), %r15
jne 0x3860
leaq (%r15,%r15), %rsi
testq %r15, %r15
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rbp, %rdi
callq 0x21d0
movq %rax, %rbp
movq %rax, 0x10(%r14)
movslq %ebx, %rdi
addq %r13, %rdi
callq 0x2260
leaq 0x1(%r15), %rcx
movq %rcx, (%r14)
movq %rax, (%rbp,%r15,8)
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %r14
movq 0x40(%rsp), %rbp
leal 0x1(%r12), %ebx
incq %r12
cmpq %r12, %rbp
jne 0x37e7
leaq 0x78(%rsp), %r14
leaq 0x4(%rsp), %r15
testb $0x1, 0x10(%rsp)
movl $0x0, %ebx
jne 0x3798
movq %r13, %rdi
callq 0x2050
movq 0x18(%rsp), %rdi
callq 0x398b
movq 0x38(%rsp), %rdi
callq 0x2040
movq 0x4724(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x60(%rsp), %r13
movq (%r13), %rcx
movq 0x18(%r13), %r8
leaq 0x27f9(%rip), %rsi      # 0x60e4
leaq 0x282a(%rip), %rdx      # 0x611c
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x2140
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %r15
leaq 0x14(%rsp), %rax
movb $0x1, %bpl
movq %r15, 0x8(%rsp)
movq (%r13), %r12
movl %r12d, (%r15,%r14,4)
movl (%rax), %eax
movl %eax, 0x8(%r15,%r14,4)
movslq %r12d, %rdi
movl $0x8, %esi
callq 0x2120
movq %rax, 0x10(%r15,%r14,8)
movq 0x10(%r13), %r13
testq %r12, %r12
je 0x3961
movq %rax, %rbx
xorl %r15d, %r15d
movq (%r13,%r15,8), %rdi
callq 0x2bd7
movq %rax, (%rbx,%r15,8)
incq %r15
cmpq %r15, %r12
jne 0x394b
movq 0x8(%rsp), %r15
movq %r13, 0x20(%r15,%r14,8)
movl $0x1, %r14d
leaq 0x78(%rsp), %r13
leaq 0x4(%rsp), %rax
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x391b
jmp 0x371d