// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/twoBit.c
// Function: twoBitWriteHeaderExt
void twoBitWriteHeaderExt(struct twoBit *twoBitList, FILE *f, boolean useLong)
/* Write out header portion of twoBit file, including initial
 * index. If useLong is True, use 64 bit quantities for the index offsets to support >4Gb assemblies */
{
bits32 sig = twoBitSig;
bits32 version = 0;
if (useLong)
    version = 1;

bits32 seqCount = slCount(twoBitList);
bits32 reserved = 0;
bits32 offset = 0;
bits64 longOffset = 0;
struct twoBit *twoBit;
long long counter = 0; /* check for 32 bit overflow */

/* Write out fixed parts of header. */
writeOne(f, sig);
writeOne(f, version);
writeOne(f, seqCount);
writeOne(f, reserved);

/* Figure out location of first byte past index.
 * Each index entry contains 4 bytes of offset information
 * and the name of the sequence, which is variable length. */
longOffset = offset = sizeof(sig) + sizeof(version) + sizeof(seqCount) + sizeof(reserved);
for (twoBit = twoBitList; twoBit != NULL; twoBit = twoBit->next)
    {
    int nameLen = strlen(twoBit->name);
    if (nameLen > 255)
        errAbort("name %s too long", twoBit->name);
    if (useLong)
        longOffset += nameLen + 1 + sizeof(bits64);
    else
        offset += nameLen + 1 + sizeof(bits32);
    }

/* Write out index. */
for (twoBit = twoBitList; twoBit != NULL; twoBit = twoBit->next)
    {
    int size = twoBitSizeInFile(twoBit);
    writeString(f, twoBit->name);
    if (useLong)
        {
        writeOne(f, longOffset);
        longOffset += size;
        }
    else
        {
        writeOne(f, offset);
        offset += size;
        }
    counter += (long long)size;
    if (!useLong && (counter > UINT_MAX ))
        errAbort("Error in faToTwoBit, index overflow at %s. The 2bit format "
                "does not support indexes larger than %dGb, \n"
                "please split up into smaller files, or use -long option.\n", 
                twoBit->name, UINT_MAX/1000000000);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x24(%rsp), %r13
movl $0x1a412743, (%r13)     # imm = 0x1A412743
xorl %eax, %eax
testl %edx, %edx
setne %al
leaq 0x20(%rsp), %rbp
movl %eax, (%rbp)
callq 0x1fbec
leaq 0x1c(%rsp), %r15
movl %eax, (%r15)
xorl %eax, %eax
leaq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movl %eax, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x22e1e
movl $0x4, %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x22e1e
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x22e1e
movl $0x4, %edx
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x22e1e
movl $0x10, 0xc(%rsp)
movq $0x10, 0x10(%rsp)
testq %r12, %r12
je 0x3df80
movq %r12, %r15
movq 0x8(%r15), %rbp
movq %rbp, %rdi
callq 0x62d0
movq %rax, %r13
cmpl $0x100, %r13d           # imm = 0x100
jl 0x3deae
leaq 0x568f3(%rip), %rdi     # 0x94797
movq %rbp, %rsi
xorl %eax, %eax
callq 0x26b6f
testl %ebx, %ebx
je 0x3decb
incl %r13d
movslq %r13d, %rax
movq 0x10(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x10(%rsp)
jmp 0x3ded9
movl 0xc(%rsp), %eax
addl %r13d, %eax
addl $0x5, %eax
movl %eax, 0xc(%rsp)
movq (%r15), %r15
testq %r15, %r15
jne 0x3de85
xorl %r13d, %r13d
movl 0x18(%r12), %r15d
addl $0x3, %r15d
sarl $0x2, %r15d
movl 0x30(%r12), %ebp
addl 0x1c(%r12), %ebp
movq 0x8(%r12), %rsi
movq %r14, %rdi
callq 0x22eee
leal (%r15,%rbp,8), %ebp
addl $0x10, %ebp
movslq %ebp, %r15
testl %ebx, %ebx
je 0x3df2f
movl $0x8, %edx
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x22e1e
addq %r15, 0x10(%rsp)
jmp 0x3df45
movl $0x4, %edx
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x22e1e
addl %ebp, 0xc(%rsp)
addq %r15, %r13
testl %ebx, %ebx
jne 0x3df73
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %r13
jl 0x3df73
movq 0x8(%r12), %rsi
leaq 0x56841(%rip), %rdi     # 0x947a8
movl $0x4, %edx
xorl %eax, %eax
callq 0x26b6f
movq (%r12), %r12
testq %r12, %r12
jne 0x3dee4
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq