// File: /workspace/github_c_makefile_star2_O1/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, 0x4(%rsp)
movq %rdi, %r14
movl 0x18(%rdi), %ebx
addl $0x3, %ebx
sarl $0x2, %ebx
movl $0x50, %edi
callq 0x2dc95
movq %rax, %r13
movslq %ebx, %rdi
callq 0x2db04
movq %rax, %r15
movq %rax, 0x10(%r13)
movq 0x8(%r14), %rdi
callq 0x1f9f6
movq %rax, 0x8(%r13)
movl 0x18(%r14), %r12d
movq %r13, 0x8(%rsp)
movl %r12d, 0x18(%r13)
movq 0x10(%r14), %r13
xorl %ebp, %ebp
cmpl $0x5, %r12d
jl 0x3daf8
addl $-0x4, %r12d
xorl %ebx, %ebx
leaq (%rbx,%r13), %rdi
callq 0x2570f
movb %al, (%r15)
incq %r15
addq $0x4, %rbx
cmpl %ebx, %r12d
jg 0x3dade
jmp 0x3dafa
xorl %ebx, %ebx
movl %ebx, %esi
addq %r13, %rsi
leaq 0x14(%rsp), %r12
movl $0x54545454, (%r12)     # imm = 0x54545454
movslq 0x18(%r14), %rdx
movslq %ebx, %rax
subq %rax, %rdx
movq %r12, %rdi
callq 0x6570
movq %r12, %rdi
callq 0x2570f
movb %al, (%r15)
movslq 0x18(%r14), %rax
testq %rax, %rax
jle 0x3db5e
xorl %ecx, %ecx
xorl %ebp, %ebp
xorl %edx, %edx
movb (%r13,%rcx), %sil
andb $-0x21, %sil
cmpb $0x4e, %sil
sete %sil
xorb $0x1, %dl
andb %sil, %dl
movzbl %dl, %edx
addl %edx, %ebp
incq %rcx
movl %esi, %edx
cmpq %rcx, %rax
jne 0x3db38
movq 0x8(%rsp), %rbx
movl %ebp, 0x1c(%rbx)
testl %ebp, %ebp
je 0x3dbff
movl %ebp, %edi
shlq $0x2, %rdi
callq 0x2db04
movq %rax, 0x20(%rbx)
movl 0x1c(%rbx), %edi
shlq $0x2, %rdi
callq 0x2db04
movq %rax, 0x28(%rbx)
movslq 0x18(%r14), %rdi
movq 0x20(%rbx), %rcx
xorl %edx, %edx
testq %rdi, %rdi
jle 0x3dbef
xorl %esi, %esi
xorl %r11d, %r11d
movb (%r13,%rdx), %r8b
andb $-0x21, %r8b
xorl %r9d, %r9d
cmpb $0x4e, %r8b
sete %r10b
jne 0x3dbbf
testl %r11d, %r11d
cmovel %edx, %esi
jmp 0x3dbd7
testl %r11d, %r11d
je 0x3dbd7
movl %esi, (%rcx)
addq $0x4, %rcx
movl %edx, %r11d
subl %esi, %r11d
movl %r11d, (%rax)
addq $0x4, %rax
movb %r10b, %r9b
incq %rdx
movl %r9d, %r11d
cmpq %rdx, %rdi
jne 0x3dba1
cmpb $0x4e, %r8b
setne %dil
jmp 0x3dbf4
movb $0x1, %dil
xorl %esi, %esi
testb %dil, %dil
jne 0x3dbff
movl %esi, (%rcx)
subl %esi, %edx
movl %edx, (%rax)
cmpl $0x0, 0x4(%rsp)
je 0x3dcf3
movslq 0x18(%r14), %r15
testq %r15, %r15
jle 0x3dc54
callq 0x6790
movq (%rax), %rcx
xorl %edx, %edx
xorl %eax, %eax
xorl %esi, %esi
movsbq (%r13,%rdx), %rdi
movzwl (%rcx,%rdi,2), %edi
movl %edi, %r8d
andl $0x200, %r8d            # imm = 0x200
shrl $0x9, %edi
testl %esi, %esi
sete %sil
andb %dil, %sil
movzbl %sil, %esi
addl %esi, %eax
incq %rdx
movl %r8d, %esi
cmpq %rdx, %r15
jne 0x3dc21
jmp 0x3dc56
xorl %eax, %eax
movl %eax, 0x30(%rbx)
testl %eax, %eax
je 0x3dcf3
movl %eax, %edi
shlq $0x2, %rdi
callq 0x2db04
movq %rax, 0x38(%rbx)
movl 0x30(%rbx), %edi
shlq $0x2, %rdi
callq 0x2db04
movq %rax, %r15
movq %rax, 0x40(%rbx)
movslq 0x18(%r14), %r12
movq 0x38(%rbx), %r14
testq %r12, %r12
jle 0x3dce1
callq 0x6790
movq (%rax), %rsi
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edi, %edi
movl %edi, %r8d
movsbq (%r13,%rax), %rdx
movzwl (%rsi,%rdx,2), %edi
andl $0x200, %edi            # imm = 0x200
sete %dl
je 0x3dcbe
testl %r8d, %r8d
cmovel %eax, %ecx
jmp 0x3dcd7
testl %r8d, %r8d
je 0x3dcd7
movl %ecx, (%r14)
addq $0x4, %r14
movl %eax, %r8d
subl %ecx, %r8d
movl %r8d, (%r15)
addq $0x4, %r15
incq %rax
cmpq %rax, %r12
jne 0x3dc9e
jmp 0x3dce7
xorl %eax, %eax
movb $0x1, %dl
xorl %ecx, %ecx
testb %dl, %dl
jne 0x3dcf3
movl %ecx, (%r14)
subl %ecx, %eax
movl %eax, (%r15)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq