// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1c(%rsp), %rax
movl $0x1a412743, (%rax)     # imm = 0x1A412743
xorl %eax, %eax
movl %edx, 0xc(%rsp)
testl %edx, %edx
setne %al
leaq 0x34(%rsp), %r13
movl %eax, (%r13)
callq 0x1c4aa
leaq 0x30(%rsp), %rbp
movl %eax, (%rbp)
leaq 0x2c(%rsp), %r15
andl $0x0, (%r15)
pushq $0x4
popq %r12
movq %rbx, %rdi
leaq 0x1c(%rsp), %rsi
movq %r12, %rdx
callq 0x1ed3f
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1ed3f
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1ed3f
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1ed3f
movl $0x10, 0x8(%rsp)
movq $0x10, 0x10(%rsp)
pushq $0x10
popq %r12
pushq $0x10
popq %rbx
movq %r14, %r15
testq %r15, %r15
je 0x38285
movq 0x8(%r15), %rbp
movq %rbp, %rdi
callq 0x62d0
movq %rax, %r13
cmpl $0x100, %r13d           # imm = 0x100
jl 0x38259
leaq 0x4b51b(%rip), %rdi     # 0x8376a
movq %rbp, %rsi
xorl %eax, %eax
callq 0x223fb
cmpl $0x0, 0xc(%rsp)
je 0x38274
incl %r13d
movslq %r13d, %rax
addq %rax, %rbx
addq $0x8, %rbx
movq %rbx, 0x10(%rsp)
jmp 0x38280
addl %r13d, %r12d
addl $0x5, %r12d
movl %r12d, 0x8(%rsp)
movq (%r15), %r15
jmp 0x3822b
pushq $0x8
popq %r13
xorl %ebp, %ebp
movq 0x20(%rsp), %r12
testq %r14, %r14
je 0x38325
movl 0x18(%r14), %ebx
addl $0x3, %ebx
sarl $0x2, %ebx
movl 0x30(%r14), %r15d
addl 0x1c(%r14), %r15d
movq 0x8(%r14), %rsi
movq %r12, %rdi
callq 0x1ee0b
leal (%rbx,%r15,8), %eax
addl $0x10, %eax
movslq %eax, %rbx
cmpl $0x0, 0xc(%rsp)
je 0x382e2
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x1ed3f
addq %rbx, 0x10(%rsp)
addq %rbx, %rbp
jmp 0x3831d
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x1ed3f
addl %ebx, 0x8(%rsp)
addq %rbx, %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %rbp
jl 0x3831d
movq 0x8(%r14), %rsi
leaq 0x4b468(%rip), %rdi     # 0x8377b
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x223fb
movq (%r14), %r14
jmp 0x38290
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq