// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/libsquish/rangefit.cpp
// Function: squish::RangeFit::Compress4(void*)
void RangeFit::Compress4( void* block )
{
    // cache some values
    int const count = m_colours->GetCount();
    Vec3 const* values = m_colours->GetPoints();

    // create a codebook
    Vec3 codes[4];
    codes[0] = m_start;
    codes[1] = m_end;
    codes[2] = ( 2.0f/3.0f )*m_start + ( 1.0f/3.0f )*m_end;
    codes[3] = ( 1.0f/3.0f )*m_start + ( 2.0f/3.0f )*m_end;

    // match each point to the closest code
    u8 closest[16];
    float error = 0.0f;
    for( int i = 0; i < count; ++i )
    {
        // find the closest code
        float dist = FLT_MAX;
        int idx = 0;
        for( int j = 0; j < 4; ++j )
        {
            float d = LengthSquared( m_metric*( values[i] - codes[j] ) );
            if( d < dist )
            {
                dist = d;
                idx = j;
            }
        }

        // save the index
        closest[i] = ( u8 )idx;

        // accumulate the error
        error += dist;
    }

    // save this scheme if it wins
    if( error < m_besterror )
    {
        // remap the indices
        u8 indices[16];
        m_colours->RemapIndices( closest, indices );

        // save the block
        WriteColourBlock4( m_start, m_end, indices, block );

        // save the error
        m_besterror = error;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movslq (%rdi), %rax
movl 0x28(%rbx), %ecx
movl %ecx, 0x18(%rsp)
movq 0x20(%rbx), %rcx
movq %rcx, 0x10(%rsp)
movq 0x2c(%rbx), %rcx
movq %rcx, 0x1c(%rsp)
movl 0x34(%rbx), %ecx
movl %ecx, 0x24(%rsp)
movsd 0x20(%rbx), %xmm0
movss 0x28(%rbx), %xmm1
movss 0xc472(%rip), %xmm2     # 0x7edc0
movaps %xmm1, %xmm3
mulss %xmm2, %xmm3
movsd 0x2c(%rbx), %xmm4
movss 0x34(%rbx), %xmm5
movss 0xc451(%rip), %xmm6     # 0x7edb8
movaps %xmm5, %xmm7
mulss %xmm6, %xmm7
addss %xmm3, %xmm7
movaps 0xc3e7(%rip), %xmm3     # 0x7ed60
movaps %xmm0, %xmm8
mulps %xmm3, %xmm8
movaps 0xc3f7(%rip), %xmm9     # 0x7ed80
movaps %xmm4, %xmm10
mulps %xmm9, %xmm10
addps %xmm8, %xmm10
movlps %xmm10, 0x28(%rsp)
movss %xmm7, 0x30(%rsp)
mulss %xmm6, %xmm1
mulss %xmm2, %xmm5
addss %xmm1, %xmm5
mulps %xmm9, %xmm0
mulps %xmm3, %xmm4
addps %xmm0, %xmm4
movlps %xmm4, 0x34(%rsp)
movss %xmm5, 0x3c(%rsp)
testq %rax, %rax
jle 0x72a8f
leaq 0x4(%rdi), %rcx
movsd 0x14(%rbx), %xmm0
movss 0x1c(%rbx), %xmm1
movaps %xmm0, %xmm2
shufps $0x55, %xmm0, %xmm2     # xmm2 = xmm2[1,1],xmm0[1,1]
xorps %xmm11, %xmm11
leaq 0x18(%rsp), %rdx
xorl %esi, %esi
movss 0xc42d(%rip), %xmm3     # 0x7ee20
leaq (%rsi,%rsi,2), %r8
movsd (%rcx,%r8,4), %xmm4
movss 0x8(%rcx,%r8,4), %xmm5
movaps %xmm4, %xmm6
shufps $0x55, %xmm4, %xmm6     # xmm6 = xmm6[1,1],xmm4[1,1]
movq %rdx, %r8
xorl %r10d, %r10d
movaps %xmm3, %xmm7
xorl %r9d, %r9d
movaps %xmm7, %xmm8
movaps %xmm4, %xmm9
subss -0x8(%r8), %xmm9
movaps %xmm6, %xmm10
subss -0x4(%r8), %xmm10
movaps %xmm5, %xmm7
subss (%r8), %xmm7
mulss %xmm1, %xmm7
mulss %xmm0, %xmm9
mulss %xmm2, %xmm10
mulss %xmm10, %xmm10
mulss %xmm9, %xmm9
addss %xmm10, %xmm9
mulss %xmm7, %xmm7
addss %xmm9, %xmm7
ucomiss %xmm7, %xmm8
cmoval %r10d, %r9d
minss %xmm8, %xmm7
incq %r10
addq $0xc, %r8
cmpq $0x4, %r10
jne 0x72a17
movb %r9b, 0x40(%rsp,%rsi)
addss %xmm7, %xmm11
incq %rsi
cmpq %rax, %rsi
jne 0x729f3
jmp 0x72a93
xorps %xmm11, %xmm11
movss 0x38(%rbx), %xmm0
ucomiss %xmm11, %xmm0
jbe 0x72adb
leaq 0x20(%rbx), %r15
leaq 0x2c(%rbx), %r12
leaq 0x40(%rsp), %rsi
leaq 0x50(%rsp), %r13
movq %r13, %rdx
movss %xmm11, 0xc(%rsp)
callq 0x72196
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x71d52
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x38(%rbx)
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop