// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, 0x48(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movl (%rax), %r12d
addq $0x4, %rax
movq %rax, 0x58(%rsp)
leaq 0x20(%rdi), %r14
movl 0x28(%rdi), %eax
leaq 0x90(%rsp), %r13
movl %eax, 0x8(%r13)
movq 0x20(%rdi), %rax
movq %rax, (%r13)
leaq 0x2c(%rdi), %r15
movq 0x2c(%rdi), %rax
movq %rax, 0xc(%r13)
movl 0x34(%rdi), %eax
movl %eax, 0x14(%r13)
movss 0xcb71(%rip), %xmm0     # 0x73c28
movq %r14, %rdi
callq 0x66ba0
movaps %xmm0, 0x10(%rsp)
movss %xmm1, 0xc(%rsp)
movss 0xcb5a(%rip), %xmm0     # 0x73c2c
movq %r15, %rdi
callq 0x66ba0
addps 0x10(%rsp), %xmm0
addss 0xc(%rsp), %xmm1
movlps %xmm0, 0x18(%r13)
movss %xmm1, 0x20(%r13)
movss 0xcb34(%rip), %xmm0     # 0x73c2c
movq %r14, 0x40(%rsp)
movq %r14, %rdi
callq 0x66ba0
movaps %xmm0, 0x10(%rsp)
movss %xmm1, 0xc(%rsp)
movss 0xcb10(%rip), %xmm0     # 0x73c28
movq %r15, 0x38(%rsp)
movq %r15, %rdi
callq 0x66ba0
addps 0x10(%rsp), %xmm0
addss 0xc(%rsp), %xmm1
movlps %xmm0, 0x24(%r13)
movss %xmm1, 0x2c(%r13)
movq %rbx, 0x50(%rsp)
leaq 0x14(%rbx), %r13
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
movq %r12, 0x60(%rsp)
xorps %xmm1, %xmm1
leaq 0x20(%rsp), %r14
cmpq 0x60(%rsp), %rax
movss %xmm1, 0x10(%rsp)
je 0x67207
movq %rax, 0x68(%rsp)
imulq $0xc, %rax, %r15
addq 0x58(%rsp), %r15
xorl %ebx, %ebx
leaq 0x90(%rsp), %r12
xorl %ebp, %ebp
movss 0xca97(%rip), %xmm0     # 0x73c24
cmpq $0x4, %rbx
je 0x671ee
movq %r15, %rdi
movq %r12, %rsi
movss %xmm0, 0xc(%rsp)
callq 0x66bc7
movlps %xmm0, 0x70(%rsp)
movss %xmm1, 0x78(%rsp)
movq %r13, %rdi
leaq 0x70(%rsp), %rsi
callq 0x6728f
movlps %xmm0, 0x20(%rsp)
movss %xmm1, 0x28(%rsp)
movq %r14, %rdi
callq 0x67312
movss 0x10(%rsp), %xmm1
movss 0xc(%rsp), %xmm2
ucomiss %xmm0, %xmm2
cmoval %ebx, %ebp
minss %xmm2, %xmm0
incq %rbx
addq $0xc, %r12
jmp 0x6718d
movq 0x68(%rsp), %rax
movb %bpl, 0x80(%rsp,%rax)
addss %xmm0, %xmm1
incq %rax
jmp 0x6715a
movq 0x50(%rsp), %rbx
movss 0x38(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x67251
movq 0x8(%rbx), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdx
callq 0x668a8
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r14, %rdx
movq 0x48(%rsp), %rcx
callq 0x6649a
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x38(%rbx)
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq