// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/nib.c
// Function: nibWriteMasked
static void nibOutput(int options, struct dnaSeq *seq, char *fileName)
/* Write out file in format of four bits per nucleotide, with control over
 * handling of masked positions. */
{
UBYTE byte;
DNA *dna = seq->dna;
int dVal1, dVal2;
bits32 size = seq->size;
int byteCount = (size>>1);
bits32 sig = nibSig;
int *ntValTbl = ((options & NIB_MASK_MIXED) ? ntValMasked : ntVal5);
Bits* mask = ((options & NIB_MASK_MAP) ? seq->mask : NULL);
int maskIdx = 0;
FILE *f = mustOpen(fileName, "w");

assert(sizeof(bits32) == 4);

writeOne(f, sig);
writeOne(f, seq->size);

printf("Writing %d bases in %d bytes\n", seq->size, ((seq->size+1)/2) + 8);
while (--byteCount >= 0)
    {
    dVal1 = ntValTbl[(int)dna[0]];
    dVal2 = ntValTbl[(int)dna[1]];
    /* Set from mask, remember bit in character is opposite sense of bit
     * in mask. */
    if (mask != NULL)
        {
        if (!bitReadOne(mask, maskIdx))
            dVal1 |= MASKED_BASE_BIT;
        if (!bitReadOne(mask, maskIdx+1))
            dVal2 |= MASKED_BASE_BIT;
        maskIdx += 2;
        }
    byte = (dVal1<<4) | dVal2;
    if (putc(byte, f) < 0)
	{
	perror("");
	errAbort("Couldn't write all of %s", fileName);
	}
    dna += 2;
    }
if (size & 1)
    {
    dVal1 = ntValTbl[(int)dna[0]];
    if ((mask != NULL) && !bitReadOne(mask, maskIdx))
        dVal1 |= MASKED_BASE_BIT;
    byte = (dVal1<<4);
    putc(byte, f);
    }
carefulClose(&f);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x10(%rsi), %rbp
movl 0x18(%rsi), %r13d
movl $0x6be93d3a, 0x1c(%rsp) # imm = 0x6BE93D3A
testb $0x1, %dil
jne 0x31f11
leaq 0x90981(%rip), %rax     # 0xc2890
jmp 0x31f18
leaq 0x90d78(%rip), %rax     # 0xc2c90
movq %rax, 0x10(%rsp)
leaq 0x18(%rsi), %r12
xorl %r15d, %r15d
testb $0x2, %dil
jne 0x31f2f
xorl %r14d, %r14d
jmp 0x31f33
movq 0x20(%rsi), %r14
leaq 0x5cd4f(%rip), %rsi     # 0x8ec89
movq %rdx, 0x20(%rsp)
movq %rdx, %rdi
callq 0x22d5a
movq %rax, 0x8(%rsp)
leaq 0x1c(%rsp), %rsi
movl $0x4, %edx
movq %rax, %rdi
callq 0x22e1e
movq 0x8(%rsp), %rdi
movl $0x4, %edx
movq %r12, %rsi
callq 0x22e1e
movl (%r12), %esi
leal 0x1(%rsi), %eax
shrl $0x1f, %eax
leal (%rsi,%rax), %edx
incl %edx
sarl %edx
addl $0x8, %edx
leaq 0x60d00(%rip), %rdi     # 0x92c8b
xorl %eax, %eax
callq 0x6070
cmpl $0x2, %r13d
movl %r13d, 0x18(%rsp)
jae 0x31ff4
testb $0x1, 0x18(%rsp)
je 0x31fdb
movsbq (%rbp), %rax
movq 0x10(%rsp), %rcx
movl (%rcx,%rax,4), %ebx
testq %r14, %r14
je 0x31fcb
movq %r14, %rdi
movl %r15d, %esi
callq 0x1b913
movl %ebx, %ecx
orl $0x8, %ecx
testl %eax, %eax
cmovel %ecx, %ebx
shll $0x4, %ebx
movzbl %bl, %edi
movq 0x8(%rsp), %rsi
callq 0x6e50
leaq 0x8(%rsp), %rdi
callq 0x23400
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
shrl %r13d
incl %r13d
xorl %r15d, %r15d
movsbq (%rbp), %rax
movq 0x10(%rsp), %rcx
movl (%rcx,%rax,4), %r12d
movsbq 0x1(%rbp), %rax
movl (%rcx,%rax,4), %ebx
testq %r14, %r14
je 0x32049
movq %r14, %rdi
movl %r15d, %esi
callq 0x1b913
movl %r12d, %ecx
orl $0x8, %ecx
testl %eax, %eax
cmovel %ecx, %r12d
leal 0x1(%r15), %esi
movq %r14, %rdi
callq 0x1b913
movl %ebx, %ecx
orl $0x8, %ecx
testl %eax, %eax
cmovel %ecx, %ebx
addl $0x2, %r15d
shll $0x4, %r12d
orl %ebx, %r12d
movzbl %r12b, %edi
movq 0x8(%rsp), %rsi
callq 0x6e50
testl %eax, %eax
js 0x32074
addq $0x2, %rbp
decl %r13d
cmpl $0x1, %r13d
jg 0x31ffd
jmp 0x31f9d
leaq 0x662e5(%rip), %rdi     # 0x98360
callq 0x6590
leaq 0x60c22(%rip), %rdi     # 0x92ca9
movq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x26b6f
jmp 0x32062