// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x1a412743, -0x18(%rbp) # imm = 0x1A412743
movl $0x0, -0x1c(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5928e
movl $0x1, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2a810
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
callq 0x2f8b0
movq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0x4, %edx
callq 0x2f8b0
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x2f8b0
movq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
callq 0x2f8b0
movl $0x10, -0x28(%rbp)
movq $0x10, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5938e
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x62c0
movl %eax, -0x44(%rbp)
cmpl $0xff, -0x44(%rbp)
jle 0x5934d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x852d9(%rip), %rdi     # 0xde61f
movb $0x0, %al
callq 0x35d40
cmpl $0x0, -0x14(%rbp)
je 0x59369
movl -0x44(%rbp), %eax
addl $0x1, %eax
cltq
addq $0x8, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x5937f
movl -0x44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
addq $0x4, %rcx
movl -0x28(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x28(%rbp)
jmp 0x59381
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x59317
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x59449
movq -0x38(%rbp), %rdi
callq 0x59450
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x2f9b0
cmpl $0x0, -0x14(%rbp)
je 0x593e4
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x2f8b0
movslq -0x48(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x593ff
movq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x4, %edx
callq 0x2f8b0
movl -0x48(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movslq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x59437
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x40(%rbp)
jle 0x59437
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x85205(%rip), %rdi     # 0xde630
movl $0x4, %edx
movb $0x0, %al
callq 0x35d40
jmp 0x59439
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x59396
addq $0x50, %rsp
popq %rbp
retq
nop