// File: /workspace/github_c_makefile_star2_O2/lh3[P]pre-pe/pre-dip-c.c
// Function: lt_process
void lt_process(const lt_global_t *g, bseq1_t s[2])
{
	int i, k, mlen;
	mlen = s[0].l_seq > s[1].l_seq? s[0].l_seq : s[1].l_seq;

	// trim heading and trailing N
	for (k = 0; k < 2; ++k) {
		bseq1_t *sk = &s[k];
		for (i = sk->l_seq - 1; i >= 0; --i) // trim trailing "N"
			if (sk->seq[i] != 'N') break;
		sk->l_seq = i + 1;
		sk->seq[sk->l_seq] = sk->qual[sk->l_seq] = 0;
		for (i = 0; i < sk->l_seq; ++i) // trim heading "N"
			if (sk->seq[i] != 'N') break;
		if (i) trim_bseq_5(sk, i);
	}
	
	// trim Illumina PE adapters
	trim_adap(&s[0], lt_adapter1, 0, g->opt.min_adap_len, g->opt.max_adap_pen, 1);
	trim_adap(&s[1], lt_adapter2, 0, g->opt.min_adap_len, g->opt.max_adap_pen, 1);
	
	// trim transposon sequences and store barcodes
	int olig_pos[2];
	char *bc[2];
	
	for (k = 0; k < 2; ++k) {
		olig_pos[k] = 0;
		bc[k] = (char*)alloca(mlen + 1);
		bc[k][0] = 0;
		trim_olig(&s[k], lt_oligo_for, 1, g->opt.min_olig_len, g->opt.max_olig_pen, &olig_pos[k], bc[k], 1);
		trim_olig(&s[k], lt_oligo_rev, 0, g->opt.min_olig_len, g->opt.max_olig_pen, 0, 0, 0);
        trim_adap(&s[k], lt_oligo_rev, 0, g->opt.min_adap_len, g->opt.max_adap_pen, 1);
	}

	
	// merge the two ends
	int n_fh;
	uint64_t fh[2];
	char *rseq, *rqual, *xseq, *xqual;
	rseq = (char*)alloca(mlen + 1);
	rqual = (char*)alloca(mlen + 1);
	xseq = (char*)alloca(s[0].l_seq + s[1].l_seq + 1);
	xqual = (char*)alloca(s[0].l_seq + s[1].l_seq + 1);
	// reverse the other read
	lt_seq_revcomp(s[1].l_seq, s[1].seq, rseq);
	lt_seq_rev(s[1].l_seq, s[1].qual, rqual);
	// find overlaps
	n_fh = lt_ue_for(s[0].l_seq, s[0].seq, s[0].qual, s[1].l_seq, rseq, rqual, g->opt.max_ovlp_pen, g->opt.min_ovlp_len, 2, fh);
	if (n_fh == 1) {
    	int l = (uint32_t)fh[0], st = fh[0]>>32;
        if (st + l == s[0].l_seq) { // good stitch
            //printf("%s\n%s\n%s\n%s\n%d,%d,%d,%d\n",s[0].seq,s[0].qual,rseq,rqual,st,l,s[0].l_seq,s[1].l_seq);
    		int x = 0;
    		s[0].type = s[1].type = LT_MERGED;
    		for (i = 0; i < st; ++i)
    			xseq[x] = s[0].seq[i], xqual[x++] = s[0].qual[i];
    		for (i = 0; i < l; ++i) {
    			int j = st + i, y;
    			y = merge_base(g->opt.max_qual, s[0].seq[j], s[0].qual[j], rseq[i], rqual[i]);
    			xseq[x] = (uint8_t)y, xqual[x++] = y>>8;
    		}
    		for (i = l; i < s[1].l_seq; ++i)
    			xseq[x] = rseq[i], xqual[x++] = rqual[i];
            //printf("%s\n%s\n%d\n",xseq,xqual,x);
    		xseq[x] = xqual[x] = 0;
    		free(s[0].seq); free(s[0].qual);
    		s[0].seq = strdup(xseq);
    		s[0].qual = strdup(xqual);
    		s[0].l_seq = x;
            s[1].seq[0] = 0;
    		s[1].l_seq = 0;
        } else {
            s[0].type = s[1].type = LT_NO_MERGE;
        }
	} else {
		s[0].type = s[1].type = LT_NO_MERGE;
	}
	
	// check whether read length is too short
    if (s[0].l_seq < g->opt.min_seq_len) {
        if (s[0].type == LT_MERGED) { // single-end
            s[0].type = s[1].type = LT_SHORT_SEQ;
        } else if (s[1].l_seq >= g->opt.min_seq_len) { // read 1 is short, but read 2 is not => swap
			char *tmp;
			tmp = s[0].seq, s[0].seq = s[1].seq, s[1].seq = tmp;
			tmp = s[0].qual, s[0].qual = s[1].qual, s[1].qual = tmp;
			tmp = bc[0], bc[0] = bc[1], bc[1] = tmp;
			i = olig_pos[0], olig_pos[0] = olig_pos[1], olig_pos[1] = i;
			i = s[0].l_seq, s[0].l_seq = s[1].l_seq, s[1].l_seq = i;
            s[0].type = s[1].type = LT_SHORT_PE_SWAP;
        } else {
            s[0].type = s[1].type = LT_SHORT_SEQ;
        }
    } else if (s[0].type != LT_MERGED && s[1].l_seq < g->opt.min_seq_len) { // read 2 is short, but read 1 is not
        s[0].type = s[1].type = LT_SHORT_PE;
    }
    
    // record the barcodes
	for (k = 0; k < 2; ++k) {
		s[k].olig_pos_f = olig_pos[0];
		s[k].olig_pos_r = olig_pos[1];
		s[k].bc_f = strdup(bc[0]);
		s[k].bc_r = strdup(bc[1]);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r13
movq %rdi, %r14
movl (%rsi), %eax
movq %rax, -0x60(%rbp)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x38(%rsi), %eax
movl %eax, -0x30(%rbp)
leaq 0x38(%rsi), %rax
movq %rax, -0x40(%rbp)
xorl %r15d, %r15d
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0x2f77
imulq $0x38, %rbx, %rax
leaq (%rax,%r13), %rdi
movl (%r13,%rax), %eax
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
testq %rdx, %rdx
jle 0x2f27
leaq -0x1(%rdx), %rcx
movq 0x18(%rdi), %rsi
cmpb $0x4e, -0x1(%rsi,%rdx)
movq %rcx, %rdx
je 0x2f06
incl %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x2f29
xorl %ecx, %ecx
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, (%rdi)
movq 0x20(%rdi), %rax
movl %ecx, %ecx
movb %r15b, (%rax,%rcx)
movq 0x18(%rdi), %rax
movl (%rdi), %ecx
andq %r12, %rcx
movb %r15b, (%rax,%rcx)
movl (%rdi), %esi
andq %r12, %rsi
xorl %eax, %eax
cmpq %rax, %rsi
je 0x2f66
movq 0x18(%rdi), %rcx
cmpb $0x4e, (%rcx,%rax)
jne 0x2f64
incq %rax
jmp 0x2f50
movl %eax, %esi
testl %esi, %esi
je 0x2f6f
callq 0x3453
incq %rbx
jmp 0x2ee7
movq -0x60(%rbp), %r15
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl -0x30(%rbp), %eax
cmpl %eax, %r15d
cmovbel %eax, %r15d
movq 0x31bd(%rip), %rsi      # 0x6150
movl 0x18(%r14), %ecx
movl 0x1c(%r14), %edx
movq %r13, %rdi
callq 0x34bf
movq 0x31ae(%rip), %rsi      # 0x6158
movl 0x18(%r14), %ecx
movl 0x1c(%r14), %edx
movq -0x40(%rbp), %rdi
callq 0x34bf
incl %r15d
xorl %ebx, %ebx
movq %r13, %r12
cmpq $0x8, %rbx
je 0x3059
leaq (%rbx,%rbp), %r9
addq $-0x80, %r9
andl $0x0, (%r9)
movq %rsp, %rax
leal 0xf(%r15), %ecx
andl $-0x10, %ecx
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0xa0(%rbp,%rbx,2)
movb $0x0, (%rax)
movq 0x3165(%rip), %rsi      # 0x6160
movl 0x20(%r14), %r8d
movl 0x24(%r14), %ecx
movq %r12, %rdi
pushq $0x1
popq %rdx
pushq $0x1
pushq %rax
callq 0x3596
popq %rax
popq %rcx
movq 0x314e(%rip), %rsi      # 0x6168
movl 0x20(%r14), %r8d
movl 0x24(%r14), %ecx
movq %r12, %rdi
xorl %edx, %edx
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
callq 0x3596
popq %rax
popq %rcx
movq 0x312c(%rip), %rsi      # 0x6168
movl 0x18(%r14), %ecx
movl 0x1c(%r14), %edx
movq %r12, %rdi
callq 0x34bf
addq $0x4, %rbx
addq $0x38, %r12
jmp 0x2fc3
movq %rsp, %rax
addl $0xf, %r15d
andl $-0x10, %r15d
subq %r15, %rax
movq %rax, %rsp
movq %rsp, %rcx
subq %r15, %rcx
movq %rcx, -0x60(%rbp)
movq %rax, %r15
movq %rcx, %rsp
movl (%r13), %eax
movl 0x38(%r13), %ebx
movl %eax, -0x38(%rbp)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, -0x30(%rbp)
movq %rbx, -0x50(%rbp)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
addl %ebx, %eax
addl $0x10, %eax
andl $-0x10, %eax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
movq 0x50(%r13), %rsi
movl %ebx, %edi
movq %r15, %rdx
callq 0x2748
movq 0x58(%r13), %rsi
movl %ebx, %edi
movq -0x60(%rbp), %rdx
callq 0x2718
movq 0x18(%r13), %rsi
movq 0x20(%r13), %rdx
movl 0x10(%r14), %eax
movl 0x14(%r14), %r10d
leaq -0xe0(%rbp), %r11
movq -0x30(%rbp), %rdi
movq %rsi, -0x78(%rbp)
movq %rdx, -0x48(%rbp)
movq %rbx, -0xc8(%rbp)
movl %ebx, %ecx
movq %r15, %r8
movq -0x60(%rbp), %r9
pushq %r11
pushq $0x2
pushq %r10
pushq %rax
callq 0x292f
addq $0x20, %rsp
cmpl $0x1, %eax
jne 0x316f
movq -0xe0(%rbp), %rax
movq %rax, %rsi
shrq $0x20, %rsi
movq %rax, -0x88(%rbp)
addl %esi, %eax
movq -0x30(%rbp), %rdi
cmpl %edi, %eax
jne 0x3187
pushq $0x15
popq %rax
movl %eax, 0x3c(%r13)
movl %eax, 0x4(%r13)
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
cmpq %rax, %rsi
je 0x319b
movq -0x78(%rbp), %rcx
movb (%rcx,%rax), %cl
movb %cl, (%r12,%rax)
movb (%rdi,%rax), %cl
movb %cl, (%rdx,%rax)
incq %rax
jmp 0x3154
pushq $0x16
popq %rax
movl %eax, 0x3c(%r13)
movl %eax, 0x4(%r13)
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
jmp 0x3372
pushq $0x16
popq %rax
movl %eax, 0x3c(%r13)
movl %eax, 0x4(%r13)
movq -0x50(%rbp), %rsi
jmp 0x3372
movq -0x88(%rbp), %rcx
movq %rcx, %rax
sarq $0x20, %rax
xorl %edx, %edx
testl %ecx, %ecx
movl $0x0, %r8d
cmovgl %ecx, %r8d
movq %r8, -0x50(%rbp)
movq -0x78(%rbp), %rcx
addq %rax, %rcx
movq %rcx, -0xb8(%rbp)
addq %rax, %rdi
movq -0x40(%rbp), %rax
addq %rsi, %rax
movq %rax, -0xb0(%rbp)
leaq (%r12,%rsi), %rax
movq %rax, -0xa8(%rbp)
movq %r13, -0x70(%rbp)
movq %r15, -0x68(%rbp)
movq %r12, -0xc0(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdi, -0x48(%rbp)
cmpq %rdx, -0x50(%rbp)
je 0x32d4
movq -0xb8(%rbp), %rax
movsbq (%rax,%rdx), %r12
movzbl (%rdi,%rdx), %ebx
movsbq (%r15,%rdx), %r13
movq -0x60(%rbp), %rax
movq %rdx, -0x30(%rbp)
movzbl (%rax,%rdx), %r15d
cmpb %r13b, %r12b
jne 0x326e
movl 0xc(%r14), %r13d
cmpb %r15b, %bl
movl %r15d, %eax
cmovgl %ebx, %eax
cmovll %ebx, %r15d
movsbl %al, %ecx
movsbl %r15b, %eax
addl $-0x21, %eax
cwtd
movw $0x2, %si
idivw %si
cwtl
leal (%rcx,%rax), %ebx
addl $-0x21, %ebx
callq 0x2030
cmpl %r13d, %ebx
jl 0x3265
movl %r13d, %ebx
shlq $0x2, %r12
addq (%rax), %r12
jmp 0x328e
callq 0x2030
movq (%rax), %rax
cmpb %r15b, %bl
jle 0x3284
leaq (%rax,%r12,4), %r12
subl %r15d, %ebx
jmp 0x328e
leaq (%rax,%r13,4), %r12
subl %ebx, %r15d
movl %r15d, %ebx
movq -0x70(%rbp), %r13
movq -0x68(%rbp), %r15
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl (%r12), %eax
shll $0x8, %ebx
addl $0x2100, %ebx           # imm = 0x2100
orl %eax, %ebx
movq -0xa8(%rbp), %rcx
movb %al, (%rcx,%rdx)
movq -0xb0(%rbp), %rax
movb %bh, (%rax,%rdx)
incq %rdx
movq -0xc0(%rbp), %r12
jmp 0x31fc
movslq -0x88(%rbp), %rax
addq %rdx, %rsi
movq -0x40(%rbp), %rdx
cmpq -0xc8(%rbp), %rax
jge 0x3305
movb (%r15,%rax), %cl
movb %cl, (%r12,%rsi)
movq -0x60(%rbp), %rcx
movb (%rcx,%rax), %cl
movb %cl, (%rdx,%rsi)
incq %rsi
incq %rax
jmp 0x32e2
movl %esi, %eax
xorl %ecx, %ecx
movq -0x40(%rbp), %r15
movb %cl, (%r15,%rax)
movb %cl, (%r12,%rax)
movq -0x78(%rbp), %rdi
movq %rsi, %rbx
callq 0x2050
movq 0x20(%r13), %rdi
callq 0x2050
movq %r12, %rdi
callq 0x2240
movq %rax, 0x18(%r13)
movq %r15, %rdi
callq 0x2240
movq %rax, 0x20(%r13)
movl $0x80000000, %esi       # imm = 0x80000000
movl (%r13), %eax
andl %esi, %eax
addl %ebx, %eax
movl %eax, (%r13)
movq 0x50(%r13), %rax
xorl %ecx, %ecx
movb %cl, (%rax)
andl 0x38(%r13), %esi
movl %esi, 0x38(%r13)
movl (%r13), %eax
movl %eax, -0x38(%rbp)
movl %eax, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl 0x8(%r14), %edx
movl 0x4(%r13), %eax
cmpl %edx, %edi
jge 0x33e1
pushq $0x2
popq %rcx
cmpl $0x15, %eax
je 0x33f3
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl %edx, %eax
jb 0x33f3
movups 0x18(%r13), %xmm0
movups 0x50(%r13), %xmm1
movups %xmm1, 0x18(%r13)
movups %xmm0, 0x50(%r13)
pshufd $0x4e, -0xa0(%rbp), %xmm0 # xmm0 = mem[2,3,0,1]
movdqa %xmm0, -0xa0(%rbp)
movq -0x80(%rbp), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x80(%rbp)
movl $0x80000000, %ecx       # imm = 0x80000000
movl -0x38(%rbp), %edx
andl %ecx, %edx
orl %edx, %eax
movl %eax, (%r13)
andl %ecx, %esi
orl %edi, %esi
movl %esi, 0x38(%r13)
pushq $0x4
jmp 0x33f2
cmpl $0x15, %eax
je 0x33fb
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpl %edx, %esi
jge 0x33fb
pushq $0x3
popq %rcx
movl %ecx, 0x3c(%r13)
movl %ecx, 0x4(%r13)
movsd -0x80(%rbp), %xmm0
movaps %xmm0, -0x60(%rbp)
movq -0xa0(%rbp), %r14
movq -0x98(%rbp), %r15
xorl %ebx, %ebx
cmpq $0x70, %rbx
je 0x3444
movaps -0x60(%rbp), %xmm0
movlps %xmm0, 0x8(%r13,%rbx)
movq %r14, %rdi
callq 0x2240
movq %rax, 0x28(%r13,%rbx)
movq %r15, %rdi
callq 0x2240
movq %rax, 0x30(%r13,%rbx)
addq $0x38, %rbx
jmp 0x3414
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq