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

    // create a codebook
    Vec3 codes[3];
    codes[0] = m_start;
    codes[1] = m_end;
    codes[2] = 0.5f*m_start + 0.5f*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 < 3; ++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
        WriteColourBlock3( 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 $0xb8, %rsp
movq %rsi, 0x48(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movl (%rax), %r15d
addq $0x4, %rax
movq %rax, 0x58(%rsp)
addq $0x20, %rdi
movl 0x28(%rbx), %eax
leaq 0x90(%rsp), %r12
movl %eax, 0x8(%r12)
movq 0x20(%rbx), %rax
movq %rax, (%r12)
leaq 0x2c(%rbx), %r14
movq 0x2c(%rbx), %rax
movq %rax, 0xc(%r12)
movl 0x34(%rbx), %eax
movl %eax, 0x14(%r12)
movss 0x841a(%rip), %xmm0     # 0x6f308
movq %rdi, 0x40(%rsp)
callq 0x66ba0
movaps %xmm0, 0x10(%rsp)
movss %xmm1, 0xc(%rsp)
movss 0x83fd(%rip), %xmm0     # 0x6f308
movq %r14, 0x38(%rsp)
movq %r14, %rdi
callq 0x66ba0
addps 0x10(%rsp), %xmm0
addss 0xc(%rsp), %xmm1
movlps %xmm0, 0x18(%r12)
movss %xmm1, 0x20(%r12)
movq %rbx, 0x50(%rsp)
leaq 0x14(%rbx), %r13
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
movq %r15, 0x60(%rsp)
xorps %xmm1, %xmm1
leaq 0x20(%rsp), %r14
cmpq 0x60(%rsp), %rax
movss %xmm1, 0x10(%rsp)
je 0x66ffc
movq %rax, 0x68(%rsp)
imulq $0xc, %rax, %r15
addq 0x58(%rsp), %r15
xorl %ebx, %ebx
leaq 0x90(%rsp), %r12
xorl %ebp, %ebp
movss 0xcca2(%rip), %xmm0     # 0x73c24
cmpq $0x3, %rbx
je 0x66fe3
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 0x66f82
movq 0x68(%rsp), %rax
movb %bpl, 0x80(%rsp,%rax)
addss %xmm0, %xmm1
incq %rax
jmp 0x66f4f
movq 0x50(%rsp), %rbx
movss 0x38(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x67046
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 0x66350
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x38(%rbx)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq