// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movq 0x1f0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x8(%rax), %rdi
callq 0xa43d0
movl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x1e4(%rsp)
movq 0x8(%rax), %rdi
callq 0xab450
movq %rax, 0x1d8(%rsp)
leaq 0x1a0(%rsp), %rax
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xab3a0
movq 0x50(%rsp), %rax
movq 0x60(%rsp), %rcx
addq $0xc, %rax
cmpq %rcx, %rax
movq %rax, 0x68(%rsp)
jne 0xae225
movq 0x58(%rsp), %rax
movq %rax, %rdi
addq $0x20, %rdi
movq %rdi, 0x10(%rsp)
movl 0x28(%rax), %ecx
movl %ecx, 0x1a8(%rsp)
movq 0x20(%rax), %rcx
movq %rcx, 0x1a0(%rsp)
movq %rax, %rcx
addq $0x2c, %rcx
movq %rcx, 0x30(%rsp)
movl 0x34(%rax), %ecx
movl %ecx, 0x1b4(%rsp)
movq 0x2c(%rax), %rax
movq %rax, 0x1ac(%rsp)
movss 0xc7ef(%rip), %xmm0     # 0xbaa8c
movss %xmm0, 0x3c(%rsp)
callq 0xad3c0
movq 0x30(%rsp), %rdi
movss %xmm1, 0x178(%rsp)
movlpd %xmm0, 0x170(%rsp)
movl 0x178(%rsp), %eax
movl %eax, 0x188(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0x180(%rsp)
movss 0xc7af(%rip), %xmm0     # 0xbaa94
movss %xmm0, 0x1c(%rsp)
callq 0xad3c0
movss %xmm1, 0x158(%rsp)
movlpd %xmm0, 0x150(%rsp)
movl 0x158(%rsp), %eax
movl %eax, 0x168(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x160(%rsp)
leaq 0x180(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0xae990
movq 0x10(%rsp), %rdi
movaps %xmm0, %xmm2
movss 0x1c(%rsp), %xmm0
movaps %xmm2, 0x20(%rsp)
movaps %xmm1, %xmm2
movaps 0x20(%rsp), %xmm1
movss %xmm2, 0x148(%rsp)
movlpd %xmm1, 0x140(%rsp)
movl 0x148(%rsp), %eax
movl %eax, 0x198(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x190(%rsp)
movl 0x198(%rsp), %eax
movl %eax, 0x1c0(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x1b8(%rsp)
callq 0xad3c0
movq 0x30(%rsp), %rdi
movaps %xmm0, %xmm2
movss 0x3c(%rsp), %xmm0
movaps %xmm2, 0x40(%rsp)
movaps %xmm1, %xmm2
movaps 0x40(%rsp), %xmm1
movss %xmm2, 0x120(%rsp)
movlpd %xmm1, 0x118(%rsp)
movl 0x120(%rsp), %eax
movl %eax, 0x130(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x128(%rsp)
callq 0xad3c0
movss %xmm1, 0x100(%rsp)
movlpd %xmm0, 0xf8(%rsp)
movl 0x100(%rsp), %eax
movl %eax, 0x110(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0xae990
movss %xmm1, 0xf0(%rsp)
movlpd %xmm0, 0xe8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x134(%rsp)
movl 0xf0(%rsp), %eax
movl %eax, 0x13c(%rsp)
movq 0x134(%rsp), %rax
movq %rax, 0x1c4(%rsp)
movl 0x13c(%rsp), %eax
movl %eax, 0x1cc(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xcc(%rsp)
movl $0x0, 0xc8(%rsp)
movl 0xc8(%rsp), %eax
cmpl 0x1e4(%rsp), %eax
jge 0xae645
movss 0xc5bb(%rip), %xmm0     # 0xbaa74
movss %xmm0, 0xc4(%rsp)
movl $0x0, 0xc0(%rsp)
movl $0x0, 0xbc(%rsp)
cmpl $0x4, 0xbc(%rsp)
jge 0xae5fc
movq 0x58(%rsp), %rax
addq $0x14, %rax
movq %rax, 0x8(%rsp)
movq 0x1d8(%rsp), %rax
movslq 0xc8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %rdi
movslq 0xbc(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0x1a0(%rsp,%rax,4), %rsi
callq 0xad530
movq 0x8(%rsp), %rdi
movss %xmm1, 0x98(%rsp)
movlpd %xmm0, 0x90(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0xa8(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rsi
callq 0xae800
movss %xmm1, 0x88(%rsp)
movlpd %xmm0, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0xac(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0xb4(%rsp)
leaq 0xac(%rsp), %rdi
callq 0xaea00
movss %xmm0, 0xb8(%rsp)
movss 0xb8(%rsp), %xmm1
movss 0xc4(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xae5e4
movss 0xb8(%rsp), %xmm0
movss %xmm0, 0xc4(%rsp)
movl 0xbc(%rsp), %eax
movl %eax, 0xc0(%rsp)
jmp 0xae5e6
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0xae4d8
movl 0xc0(%rsp), %eax
movb %al, %cl
movslq 0xc8(%rsp), %rax
movb %cl, 0xd0(%rsp,%rax)
movss 0xc4(%rsp), %xmm0
addss 0xcc(%rsp), %xmm0
movss %xmm0, 0xcc(%rsp)
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0xae49d
movq 0x58(%rsp), %rax
movss 0xcc(%rsp), %xmm1
movss 0x38(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xae6ad
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0xacb60
movq 0x58(%rsp), %rsi
movq %rsi, %rdi
addq $0x20, %rdi
addq $0x2c, %rsi
leaq 0x70(%rsp), %rdx
movq 0x1e8(%rsp), %rcx
callq 0xac0f0
movq 0x58(%rsp), %rax
movss 0xcc(%rsp), %xmm0
movss %xmm0, 0x38(%rax)
addq $0x1f8, %rsp            # imm = 0x1F8
retq
nopw %cs:(%rax,%rax)
nop