// File: /workspace/github_c_makefile_star2_O3/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
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x24(%rsp), %r13
movl $0x1a412743, (%r13)     # imm = 0x1A412743
xorl %eax, %eax
movl %edx, 0x4(%rsp)
testl %edx, %edx
setne %al
leaq 0x20(%rsp), %rbp
movl %eax, (%rbp)
callq 0x200ac
leaq 0x1c(%rsp), %r12
movl %eax, (%r12)
leaq 0x18(%rsp), %r15
movl $0x0, (%r15)
movl $0x4, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x23138
movl $0x4, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x23138
movl $0x4, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x23138
movl $0x4, %edx
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x23138
movl $0x10, (%rsp)
movq $0x10, 0x8(%rsp)
testq %r14, %r14
je 0x3e2f8
movl $0x10, %r12d
movl $0x10, %ebx
movq %r14, %r15
movq 0x8(%r15), %rbp
movq %rbp, %rdi
callq 0x62d0
movq %rax, %r13
cmpl $0x100, %r13d           # imm = 0x100
jl 0x3e22c
leaq 0x56648(%rip), %rdi     # 0x9486a
movq %rbp, %rsi
xorl %eax, %eax
callq 0x26e94
cmpl $0x0, 0x4(%rsp)
je 0x3e247
incl %r13d
movslq %r13d, %rax
addq %rax, %rbx
addq $0x8, %rbx
movq %rbx, 0x8(%rsp)
jmp 0x3e252
addl %r13d, %r12d
addl $0x5, %r12d
movl %r12d, (%rsp)
movq (%r15), %r15
testq %r15, %r15
jne 0x3e203
leaq 0x8(%rsp), %r12
xorl %r13d, %r13d
movq 0x10(%rsp), %rbp
movl 0x18(%r14), %ebx
addl $0x3, %ebx
sarl $0x2, %ebx
movl 0x30(%r14), %r15d
addl 0x1c(%r14), %r15d
movq 0x8(%r14), %rsi
movq %rbp, %rdi
callq 0x23208
leal (%rbx,%r15,8), %eax
addl $0x10, %eax
movslq %eax, %rbx
cmpl $0x0, 0x4(%rsp)
je 0x3e2b0
movl $0x8, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x23138
addq %rbx, 0x8(%rsp)
addq %rbx, %r13
jmp 0x3e2ec
movl $0x4, %edx
movq %rbp, %rdi
movq %rsp, %rsi
callq 0x23138
addl %ebx, (%rsp)
addq %rbx, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %r13
jl 0x3e2ec
movq 0x8(%r14), %rsi
leaq 0x5659b(%rip), %rdi     # 0x9487b
movl $0x4, %edx
xorl %eax, %eax
callq 0x26e94
movq (%r14), %r14
testq %r14, %r14
jne 0x3e267
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq