// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/libsquish/colourset.cpp
// Function: squish::ColourSet::ColourSet(unsigned char const*, int, int)
ColourSet::ColourSet( u8 const* rgba, int mask, int flags )
  : m_count( 0 ),
    m_transparent( false )
{
    // check the compression mode for dxt1
    bool isDxt1 = ( ( flags & kDxt1 ) != 0 );
    bool weightByAlpha = ( ( flags & kWeightColourByAlpha ) != 0 );

    // create the minimal set
    for( int i = 0; i < 16; ++i )
    {
        // check this pixel is enabled
        int bit = 1 << i;
        if( ( mask & bit ) == 0 )
        {
            m_remap[i] = -1;
            continue;
        }

        // check for transparent pixels when using dxt1
        if( isDxt1 && rgba[4*i + 3] < 128 )
        {
            m_remap[i] = -1;
            m_transparent = true;
            continue;
        }

        // loop over previous points for a match
        for( int j = 0;; ++j )
        {
            // allocate a new point
            if( j == i )
            {
                // normalise coordinates to [0,1]
                float x = ( float )rgba[4*i] / 255.0f;
                float y = ( float )rgba[4*i + 1] / 255.0f;
                float z = ( float )rgba[4*i + 2] / 255.0f;

                // ensure there is always non-zero weight even for zero alpha
                float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;

                // add the point
                m_points[m_count] = Vec3( x, y, z );
                m_weights[m_count] = ( weightByAlpha ? w : 1.0f );
                m_remap[i] = m_count;

                // advance
                ++m_count;
                break;
            }

            // check for a match
            int oldbit = 1 << j;
            bool match = ( ( mask & oldbit ) != 0 )
                && ( rgba[4*i] == rgba[4*j] )
                && ( rgba[4*i + 1] == rgba[4*j + 1] )
                && ( rgba[4*i + 2] == rgba[4*j + 2] )
                && ( rgba[4*j + 3] >= 128 || !isDxt1 );
            if( match )
            {
                // get the index of the match
                int index = m_remap[j];

                // ensure there is always non-zero weight even for zero alpha
                float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;

                // map to this point and increase the weight
                m_weights[index] += ( weightByAlpha ? w : 1.0f );
                m_remap[i] = index;
                break;
            }
        }
    }

    // square root the weights
    for( int i = 0; i < m_count; ++i )
        m_weights[i] = std::sqrt( m_weights[i] );
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl %edx, 0x74(%rsp)
movl %ecx, 0x70(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, (%rax)
addq $0x4, %rax
movq %rax, %rcx
addq $0xc0, %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xab3a0
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
addq $0xc, %rax
cmpq %rcx, %rax
movq %rax, 0x28(%rsp)
jne 0xac6f7
movq 0x18(%rsp), %rax
movb $0x0, 0x144(%rax)
movl 0x70(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x6f(%rsp)
movl 0x70(%rsp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x6e(%rsp)
movl $0x0, 0x68(%rsp)
cmpl $0x10, 0x68(%rsp)
jge 0xacb03
movl 0x68(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x64(%rsp)
movl 0x74(%rsp), %eax
andl 0x64(%rsp), %eax
cmpl $0x0, %eax
jne 0xac79b
movq 0x18(%rsp), %rax
movslq 0x68(%rsp), %rcx
movl $0xffffffff, 0x104(%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0xacaf3
testb $0x1, 0x6f(%rsp)
je 0xac7e0
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jge 0xac7e0
movq 0x18(%rsp), %rax
movslq 0x68(%rsp), %rcx
movl $0xffffffff, 0x104(%rax,%rcx,4) # imm = 0xFFFFFFFF
movb $0x1, 0x144(%rax)
jmp 0xacaf3
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0x68(%rsp), %eax
jne 0xac931
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cvtsi2ss %eax, %xmm0
movss 0x9dc3(%rip), %xmm1     # 0xb65d8
divss %xmm1, %xmm0
movss %xmm0, 0x5c(%rsp)
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movzbl 0x1(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
movss %xmm0, 0x58(%rsp)
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movzbl 0x2(%rax,%rcx), %eax
cvtsi2ss %eax, %xmm0
movss 0x9d77(%rip), %xmm1     # 0xb65d8
divss %xmm1, %xmm0
movss %xmm0, 0x54(%rsp)
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
movss 0x9d6c(%rip), %xmm1     # 0xb65fc
divss %xmm1, %xmm0
movss %xmm0, 0x50(%rsp)
movss 0x5c(%rsp), %xmm0
movss 0x58(%rsp), %xmm1
movss 0x54(%rsp), %xmm2
leaq 0x44(%rsp), %rdi
callq 0xabe10
movq 0x18(%rsp), %rcx
movq %rcx, %rax
addq $0x4, %rax
movslq (%rcx), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq 0x44(%rsp), %rcx
movq %rcx, (%rax)
movl 0x4c(%rsp), %ecx
movl %ecx, 0x8(%rax)
testb $0x1, 0x6e(%rsp)
je 0xac8f0
movss 0x50(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
jmp 0xac900
movss 0x6508(%rip), %xmm0     # 0xb2e00
movss %xmm0, 0xc(%rsp)
jmp 0xac900
movq 0x18(%rsp), %rax
movss 0xc(%rsp), %xmm0
movslq (%rax), %rcx
movss %xmm0, 0xc4(%rax,%rcx,4)
movl (%rax), %edx
movslq 0x68(%rsp), %rcx
movl %edx, 0x104(%rax,%rcx,4)
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xacaf1
movl 0x60(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x40(%rsp)
movl 0x74(%rsp), %ecx
andl 0x40(%rsp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xb(%rsp)
je 0xaca2d
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movq 0x78(%rsp), %rax
movl 0x60(%rsp), %edx
shll $0x2, %edx
movslq %edx, %rdx
movzbl (%rax,%rdx), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0xb(%rsp)
jne 0xaca2d
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movq 0x78(%rsp), %rax
movl 0x60(%rsp), %edx
shll $0x2, %edx
addl $0x1, %edx
movslq %edx, %rdx
movzbl (%rax,%rdx), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0xb(%rsp)
jne 0xaca2d
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movq 0x78(%rsp), %rax
movl 0x60(%rsp), %edx
shll $0x2, %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rax,%rdx), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, 0xb(%rsp)
jne 0xaca2d
movq 0x78(%rsp), %rax
movl 0x60(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x80, %ecx
movb %al, 0xa(%rsp)
jge 0xaca25
movb 0x6f(%rsp), %al
xorb $-0x1, %al
movb %al, 0xa(%rsp)
movb 0xa(%rsp), %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
andb $0x1, %al
movb %al, 0x3f(%rsp)
testb $0x1, 0x3f(%rsp)
je 0xacadf
movq 0x18(%rsp), %rax
movslq 0x60(%rsp), %rcx
movl 0x104(%rax,%rcx,4), %eax
movl %eax, 0x38(%rsp)
movq 0x78(%rsp), %rax
movl 0x68(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
movss 0x9b80(%rip), %xmm1     # 0xb65fc
divss %xmm1, %xmm0
movss %xmm0, 0x34(%rsp)
testb $0x1, 0x6e(%rsp)
je 0xaca9b
movss 0x34(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
jmp 0xacaab
movss 0x635d(%rip), %xmm0     # 0xb2e00
movss %xmm0, 0x4(%rsp)
jmp 0xacaab
movq 0x18(%rsp), %rax
movss 0x4(%rsp), %xmm0
movslq 0x38(%rsp), %rcx
addss 0xc4(%rax,%rcx,4), %xmm0
movss %xmm0, 0xc4(%rax,%rcx,4)
movl 0x38(%rsp), %edx
movslq 0x68(%rsp), %rcx
movl %edx, 0x104(%rax,%rcx,4)
jmp 0xacaf1
jmp 0xacae1
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xac7e8
jmp 0xacaf3
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0xac75a
movl $0x0, 0x30(%rsp)
movq 0x18(%rsp), %rcx
movl 0x30(%rsp), %eax
cmpl (%rcx), %eax
jge 0xacb50
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movss 0xc4(%rax,%rcx,4), %xmm0
callq 0xacbe0
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movss %xmm0, 0xc4(%rax,%rcx,4)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0xacb0b
addq $0x88, %rsp
retq
nopl (%rax,%rax)