// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/twoBit.c
// Function: twoBitFromDnaSeq
struct twoBit *twoBitFromDnaSeq(struct dnaSeq *seq, boolean doMask)
/* Convert dnaSeq representation in memory to twoBit representation.
 * If doMask is true interpret lower-case letters as masked. */
{
int ubyteSize = packedSize(seq->size);
UBYTE *pt;
struct twoBit *twoBit;
DNA last4[4];	/* Holds few bases. */
DNA *dna;
int i, end;

/* Allocate structure and fill in name. */
AllocVar(twoBit);
pt = AllocArray(twoBit->data, ubyteSize);
twoBit->name = cloneString(seq->name);
twoBit->size = seq->size;

/* Convert to 4-bases per byte representation. */
dna = seq->dna;
end = seq->size - 4;
for (i=0; i<end; i += 4)
    {
    *pt++ = packDna4(dna+i);
    }

/* Take care of conversion of last few bases. */
last4[0] = last4[1] = last4[2] = last4[3] = 'T';
memcpy(last4, dna+i, seq->size-i);
*pt = packDna4(last4);

/* Deal with blocks of N. */
twoBit->nBlockCount = countBlocksOfN(dna, seq->size);
if (twoBit->nBlockCount > 0)
    {
    AllocArray(twoBit->nStarts, twoBit->nBlockCount);
    AllocArray(twoBit->nSizes, twoBit->nBlockCount);
    storeBlocksOfN(dna, seq->size, twoBit->nStarts, twoBit->nSizes);
    }

/* Deal with masking */
if (doMask)
    {
    twoBit->maskBlockCount = countBlocksOfLower(dna, seq->size);
    if (twoBit->maskBlockCount > 0)
        {
	AllocArray(twoBit->maskStarts, twoBit->maskBlockCount);
	AllocArray(twoBit->maskSizes, twoBit->maskBlockCount);
	storeBlocksOfLower(dna, seq->size, 
		twoBit->maskStarts, twoBit->maskSizes);
	}
    }
return twoBit;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %r14
movl 0x18(%rdi), %ebx
addl $0x3, %ebx
sarl $0x2, %ebx
pushq $0x50
popq %rdi
callq 0x28bb0
movq %rax, %r13
movslq %ebx, %rdi
callq 0x28a1f
movq %rax, %r15
movq %rax, 0x10(%r13)
movq 0x8(%r14), %rdi
callq 0x1c306
movq %rax, 0x8(%r13)
movslq 0x18(%r14), %r12
movq %r13, (%rsp)
movl %r12d, 0x18(%r13)
movq 0x10(%r14), %r13
addq $-0x4, %r12
xorl %ebx, %ebx
cmpq %r12, %rbx
jge 0x37eaf
leaq (%rbx,%r13), %rdi
callq 0x211b7
movb %al, (%r15)
incq %r15
addq $0x4, %rbx
jmp 0x37e95
leaq (%rbx,%r13), %rsi
leaq 0x14(%rsp), %r12
movl $0x54545454, (%r12)     # imm = 0x54545454
movslq 0x18(%r14), %rdx
subq %rbx, %rdx
movq %r12, %rdi
callq 0x6570
movq %r12, %rdi
callq 0x211b7
movb %al, (%r15)
movl 0x18(%r14), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
xorl %esi, %esi
xorl %edx, %edx
movq (%rsp), %r15
cmpq %rcx, %rax
je 0x37f17
movb (%r13,%rcx), %dil
andb $-0x21, %dil
cmpb $0x4e, %dil
sete %dil
xorb $0x1, %sil
andb %dil, %sil
movzbl %sil, %esi
addl %esi, %edx
incq %rcx
movl %edi, %esi
jmp 0x37eed
movl %edx, 0x1c(%r15)
testl %edx, %edx
je 0x37fa8
movl %edx, %edi
shlq $0x2, %rdi
callq 0x28a1f
movq %rax, 0x20(%r15)
movl 0x1c(%r15), %edi
shlq $0x2, %rdi
callq 0x28a1f
movq %rax, 0x28(%r15)
movl 0x18(%r14), %ecx
movq 0x20(%r15), %rdx
xorl %esi, %esi
testl %ecx, %ecx
cmovlel %esi, %ecx
xorl %r10d, %r10d
xorl %edi, %edi
cmpq %rsi, %rcx
je 0x37f9d
movb (%r13,%rsi), %r9b
andb $-0x21, %r9b
xorl %r8d, %r8d
cmpb $0x4e, %r9b
sete %r9b
jne 0x37f7a
testl %r10d, %r10d
cmovel %esi, %edi
jmp 0x37f92
testl %r10d, %r10d
je 0x37f92
movl %edi, (%rdx)
addq $0x4, %rdx
movl %esi, %r10d
subl %edi, %r10d
movl %r10d, (%rax)
addq $0x4, %rax
movb %r9b, %r8b
incq %rsi
movl %r8d, %r10d
jmp 0x37f57
testl %r10d, %r10d
je 0x37fa8
movl %edi, (%rdx)
subl %edi, %ecx
movl %ecx, (%rax)
testl %ebp, %ebp
je 0x380ab
movl 0x18(%r14), %ebx
xorl %r15d, %r15d
testl %ebx, %ebx
cmovlel %r15d, %ebx
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq %r15, %rbx
je 0x37ff9
callq 0x6790
movq (%rax), %rax
movsbq (%r13,%r15), %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, %ecx
andl $0x200, %ecx            # imm = 0x200
shrl $0x9, %eax
testl %r12d, %r12d
sete %dl
andb %al, %dl
movzbl %dl, %eax
addl %eax, %ebp
incq %r15
movl %ecx, %r12d
jmp 0x37fc2
movq (%rsp), %r15
movl %ebp, 0x30(%r15)
testl %ebp, %ebp
je 0x380ab
movl %ebp, %edi
shlq $0x2, %rdi
callq 0x28a1f
movq %rax, 0x38(%r15)
movl 0x30(%r15), %edi
shlq $0x2, %rdi
callq 0x28a1f
movq %rax, 0x8(%rsp)
movq %rax, 0x40(%r15)
movl 0x18(%r14), %r14d
movq 0x38(%r15), %r12
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpq %rbp, %r14
je 0x38093
callq 0x6790
movq (%rax), %rax
movsbq (%r13,%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x200, %eax            # imm = 0x200
je 0x3806a
testl %r15d, %r15d
cmovel %ebp, %ebx
jmp 0x3808b
testl %r15d, %r15d
je 0x3808b
movl %ebx, (%r12)
addq $0x4, %r12
movl %ebp, %ecx
subl %ebx, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
addq $0x4, %rdx
movq %rdx, 0x8(%rsp)
incq %rbp
movl %eax, %r15d
jmp 0x38044
testl %r15d, %r15d
movq (%rsp), %r15
je 0x380ab
movl %ebx, (%r12)
subl %ebx, %r14d
movq 0x8(%rsp), %rax
movl %r14d, (%rax)
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq