// File: /workspace/github_cpp_makefile_star2_O3/zeeev[P]DASVC/bamtools/src/api/internal/bam/BamWriter_p.cpp
// Function: BamTools::Internal::BamWriterPrivate::WriteCoreAlignment(BamTools::BamAlignment const&)
void BamWriterPrivate::WriteCoreAlignment(const BamAlignment& al) {

    // write the block size
    unsigned int blockSize = al.SupportData.BlockLength;
    if ( m_isBigEndian ) BamTools::SwapEndian_32(blockSize);
    m_stream.Write((char*)&blockSize, Constants::BAM_SIZEOF_INT);

    // re-calculate bin (in case BamAlignment's position has been previously modified)
    const uint32_t alignmentBin = CalculateMinimumBin(al.Position, al.GetEndPosition());

    // assign the BAM core data
    uint32_t buffer[Constants::BAM_CORE_BUFFER_SIZE];
    buffer[0] = al.RefID;
    buffer[1] = al.Position;
    buffer[2] = (alignmentBin << 16) | (al.MapQuality << 8) | al.SupportData.QueryNameLength;
    buffer[3] = (al.AlignmentFlag << 16) | al.SupportData.NumCigarOperations;
    buffer[4] = al.SupportData.QuerySequenceLength;
    buffer[5] = al.MateRefID;
    buffer[6] = al.MatePosition;
    buffer[7] = al.InsertSize;

    // swap BAM core endian-ness, if necessary
    if ( m_isBigEndian ) {
        for ( int i = 0; i < 8; ++i )
            BamTools::SwapEndian_32(buffer[i]);
    }

    // write the BAM core
    m_stream.Write((char*)&buffer, Constants::BAM_CORE_SIZE);

    // write the raw char data
    m_stream.Write((char*)al.SupportData.AllCharData.data(),
                   al.SupportData.BlockLength-Constants::BAM_CORE_SIZE);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x120(%rsi), %eax
movl %eax, 0xc(%rsp)
cmpb $0x1, 0x40(%rdi)
jne 0x3cf68
bswapl %eax
movl %eax, 0xc(%rsp)
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
movq %rbx, %rdi
callq 0x28c90
movl 0xac(%r14), %ebp
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x274a0
movl %ebp, %esi
movl %eax, %edx
callq 0x26960
movq 0xa8(%r14), %rcx
movq %rcx, 0x10(%rsp)
shll $0x10, %eax
movzwl 0xb2(%r14), %ecx
orl 0x128(%r14), %eax
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x18(%rsp)
movl 0xb4(%r14), %eax
shll $0x10, %eax
orl 0x124(%r14), %eax
movl %eax, 0x1c(%rsp)
movl 0x12c(%r14), %eax
movl %eax, 0x20(%rsp)
movq 0xd0(%r14), %rax
movq %rax, 0x24(%rsp)
movl 0xd8(%r14), %eax
movl %eax, 0x2c(%rsp)
cmpb $0x1, 0x40(%rbx)
jne 0x3d03a
xorl %eax, %eax
pxor %xmm0, %xmm0
movdqa 0x10(%rsp,%rax,4), %xmm1
movdqa %xmm1, %xmm2
punpckhbw %xmm0, %xmm2    # xmm2 = xmm2[8],xmm0[8],xmm2[9],xmm0[9],xmm2[10],xmm0[10],xmm2[11],xmm0[11],xmm2[12],xmm0[12],xmm2[13],xmm0[13],xmm2[14],xmm0[14],xmm2[15],xmm0[15]
pshuflw $0x1b, %xmm2, %xmm2     # xmm2 = xmm2[3,2,1,0,4,5,6,7]
pshufhw $0x1b, %xmm2, %xmm2     # xmm2 = xmm2[0,1,2,3,7,6,5,4]
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
pshuflw $0x1b, %xmm1, %xmm1     # xmm1 = xmm1[3,2,1,0,4,5,6,7]
pshufhw $0x1b, %xmm1, %xmm1     # xmm1 = xmm1[0,1,2,3,7,6,5,4]
packuswb %xmm2, %xmm1
movdqa %xmm1, 0x10(%rsp,%rax,4)
addq $0x4, %rax
cmpq $0x8, %rax
jne 0x3d000
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %rbx, %rdi
callq 0x28c90
movq 0x100(%r14), %rsi
movl 0x120(%r14), %edx
addl $-0x20, %edx
movq %rbx, %rdi
callq 0x28c90
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq