// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rax), %rdi
callq 0xa43d0
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x154(%rsp)
movq 0x8(%rax), %rdi
callq 0xab450
movq %rax, 0x148(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, %rcx
addq $0x24, %rcx
movq %rcx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xab3a0
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
addq $0xc, %rax
cmpq %rcx, %rax
movq %rax, 0x48(%rsp)
jne 0xade45
movq 0x38(%rsp), %rax
movq %rax, %rdi
addq $0x20, %rdi
movl 0x28(%rax), %ecx
movl %ecx, 0x128(%rsp)
movq 0x20(%rax), %rcx
movq %rcx, 0x120(%rsp)
movq %rax, %rcx
addq $0x2c, %rcx
movq %rcx, 0x10(%rsp)
movl 0x34(%rax), %ecx
movl %ecx, 0x134(%rsp)
movq 0x2c(%rax), %rax
movq %rax, 0x12c(%rsp)
movss 0x8710(%rip), %xmm0     # 0xb65c8
movss %xmm0, 0x1c(%rsp)
callq 0xad3c0
movq 0x10(%rsp), %rdi
movaps %xmm0, %xmm2
movss 0x1c(%rsp), %xmm0
movaps %xmm2, 0x20(%rsp)
movaps %xmm1, %xmm2
movaps 0x20(%rsp), %xmm1
movss %xmm2, 0x100(%rsp)
movlpd %xmm1, 0xf8(%rsp)
movl 0x100(%rsp), %eax
movl %eax, 0x110(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x108(%rsp)
callq 0xad3c0
movss %xmm1, 0xe0(%rsp)
movlpd %xmm0, 0xd8(%rsp)
movl 0xe0(%rsp), %eax
movl %eax, 0xf0(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0xae990
movss %xmm1, 0xd0(%rsp)
movlpd %xmm0, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x114(%rsp)
movl 0xd0(%rsp), %eax
movl %eax, 0x11c(%rsp)
movq 0x114(%rsp), %rax
movq %rax, 0x138(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, 0x140(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xac(%rsp)
movl $0x0, 0xa8(%rsp)
movl 0xa8(%rsp), %eax
cmpl 0x154(%rsp), %eax
jge 0xae14d
movss 0xca9b(%rip), %xmm0     # 0xbaa74
movss %xmm0, 0xa4(%rsp)
movl $0x0, 0xa0(%rsp)
movl $0x0, 0x9c(%rsp)
cmpl $0x3, 0x9c(%rsp)
jge 0xae104
movq 0x38(%rsp), %rax
addq $0x14, %rax
movq %rax, 0x8(%rsp)
movq 0x148(%rsp), %rax
movslq 0xa8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %rdi
movslq 0x9c(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq 0x120(%rsp,%rax,4), %rsi
callq 0xad530
movq 0x8(%rsp), %rdi
movss %xmm1, 0x78(%rsp)
movlpd %xmm0, 0x70(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x88(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x80(%rsp), %rsi
callq 0xae800
movss %xmm1, 0x68(%rsp)
movlpd %xmm0, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x8c(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x94(%rsp)
leaq 0x8c(%rsp), %rdi
callq 0xaea00
movss %xmm0, 0x98(%rsp)
movss 0x98(%rsp), %xmm1
movss 0xa4(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xae0ec
movss 0x98(%rsp), %xmm0
movss %xmm0, 0xa4(%rsp)
movl 0x9c(%rsp), %eax
movl %eax, 0xa0(%rsp)
jmp 0xae0ee
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0xadff8
movl 0xa0(%rsp), %eax
movb %al, %cl
movslq 0xa8(%rsp), %rax
movb %cl, 0xb0(%rsp,%rax)
movss 0xa4(%rsp), %xmm0
addss 0xac(%rsp), %xmm0
movss %xmm0, 0xac(%rsp)
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0xadfbd
movq 0x38(%rsp), %rax
movss 0xac(%rsp), %xmm1
movss 0x38(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xae1b5
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0xacb60
movq 0x38(%rsp), %rsi
movq %rsi, %rdi
addq $0x20, %rdi
addq $0x2c, %rsi
leaq 0x50(%rsp), %rdx
movq 0x158(%rsp), %rcx
callq 0xabe50
movq 0x38(%rsp), %rax
movss 0xac(%rsp), %xmm0
movss %xmm0, 0x38(%rax)
addq $0x168, %rsp            # imm = 0x168
retq
nopl (%rax)