// File: /workspace/github_c_makefile_star2_O0/DavidSM64[P]n64graphics_ci/exoquant/exoquant.c
// Function: exq_map_image
void exq_map_image(exq_data *pExq, int nPixels, unsigned char *pIn,
				   unsigned char *pOut)
{
	int i;
	exq_color c;
	exq_histogram *pHist;

	if(!pExq->optimized)
		exq_optimize_palette(pExq, 4);

	for(i = 0; i < nPixels; i++)
	{
		pHist = exq_find_histogram(pExq, pIn);
		if(pHist != NULL && pHist->palIndex != -1)
		{
			*pOut++ = (unsigned char)pHist->palIndex;
			pIn += 4;
		}
		else
		{
			c.r = *pIn++ / 255.0f * SCALE_R;
			c.g = *pIn++ / 255.0f * SCALE_G;
			c.b = *pIn++ / 255.0f * SCALE_B;
			c.a = *pIn++ / 255.0f * SCALE_A;

			if(pExq->transparency)
			{
				c.r *= c.a; c.g *= c.a; c.b *= c.a;
			}

			*pOut = exq_find_nearest_color(pExq, &c);
			if(pHist != NULL)
				pHist->palIndex = *pOut;
			pOut++;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x86808(%rax)
jne 0x3342
movq -0x8(%rbp), %rdi
movl $0x4, %esi
callq 0x2950
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x34fe
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3510
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x33a2
movq -0x50(%rbp), %rax
cmpl $-0x1, 0x24(%rax)
je 0x33a2
movq -0x50(%rbp), %rax
movl 0x24(%rax), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
jmp 0x34ee
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm0
movss 0x1dc48(%rip), %xmm1    # 0x21008
divss %xmm1, %xmm0
movss 0x1dc38(%rip), %xmm1    # 0x21004
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm0
movss 0x1dc11(%rip), %xmm1    # 0x21008
divss %xmm1, %xmm0
movss 0x1dc0d(%rip), %xmm1    # 0x21010
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm0
movss 0x1dbda(%rip), %xmm1    # 0x21008
divss %xmm1, %xmm0
movss 0x1dbd2(%rip), %xmm1    # 0x2100c
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cvtsi2ss %eax, %xmm0
movss 0x1dba3(%rip), %xmm1    # 0x21008
divss %xmm1, %xmm0
movss 0x1db93(%rip), %xmm1    # 0x21004
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8680c(%rax)
je 0x34b8
movsd -0x30(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3180
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
cmpq $0x0, -0x50(%rbp)
je 0x34e2
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x34f0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3349
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)