int quantize(float *B, float **cb, int nt, int ny, int nx, int dim,
             float thresh) {
  int it, i, offset, N;
  float *A, *weight, avgweight;
  int ny2, nx2, ei;
  unsigned char *P;
  int debug = 0;
  ei = nt * ny * nx;
  printf("color quantization\n");
  offset = 2;
  ny2 = ny + 2 * offset;
  nx2 = nx + 2 * offset;
  weight = (float *)calloc(ei, sizeof(float));
  A = (float *)calloc(ny2 * nx2 * dim, sizeof(float));
  avgweight = 0;
  for (it = 0; it < nt; it++) {
    extendboundfloat(B + it * ny * nx * dim, A, ny, nx, offset, dim);
    avgweight += pga(B + it * ny * nx * dim, A, ny, nx, offset,
                     weight + it * ny * nx, dim);
  }
  avgweight /= nt;
  free(A);
  for (i = 0; i < ei; i++)
    weight[i] = exp(-weight[i]);
  P = (unsigned char *)calloc(ei, sizeof(unsigned char));
  N = (((round(2 * avgweight)) > (round(17 * sqrt(dim / 3.0))))
           ? (round(2 * avgweight))
           : (round(17 * sqrt(dim / 3.0))));
  if (N > 256)
    N = 256;
  N = greedy(B, ei, dim, N, cb, 0.05, P, weight);
  N = mergecb(B, cb, P, ei, N, thresh, dim);
  gla(B, ei, dim, N, cb, 0.03, P, weight);
  if (debug)
    printf("N=%d \n", N);
  free(weight);
  free(P);
  return N;
}


x86 assembly (clang, -O0):
<quantize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movss  %xmm0,-0x24(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
movslq -0x58(%rbp),%rdi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%eax
imul   -0x54(%rbp),%eax
imul   -0x20(%rbp),%eax
movslq %eax,%rdi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1305 <quantize+0x155>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    $0x0,%al
call   1070 <extendboundfloat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x48(%rbp),%r9
mov    -0x28(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%r9
mov    -0x20(%rbp),%eax
mov    %eax,(%rsp)
mov    $0x0,%al
call   10b0 <pga@plt>
cvtsi2ss %eax,%xmm0
addss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1259 <quantize+0xa9>
cvtsi2ssl -0x14(%rbp),%xmm1
movss  -0x4c(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1376 <quantize+0x1c6>
mov    -0x48(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
cvtss2sd %xmm0,%xmm0
call   1080 <exp@plt>
cvtsd2ss %xmm0,%xmm0
mov    -0x48(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1328 <quantize+0x178>
movslq -0x58(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x60(%rbp)
movss  0xc90(%rip),%xmm0
mulss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1090 <round@plt>
movsd  %xmm0,-0x70(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xc58(%rip),%xmm1
divsd  %xmm1,%xmm0
call   10a0 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xc3c(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1090 <round@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    13ff <quantize+0x24f>
movss  0xc39(%rip),%xmm0
mulss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1090 <round@plt>
movsd  %xmm0,-0x78(%rbp)
jmp    142e <quantize+0x27e>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xbfc(%rip),%xmm1
divsd  %xmm1,%xmm0
call   10a0 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xbe0(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1090 <round@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x100,-0x34(%rbp)
jle    144e <quantize+0x29e>
movl   $0x100,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x60(%rbp),%r9
mov    -0x48(%rbp),%rax
movsd  0xba9(%rip),%xmm0
mov    %rax,(%rsp)
mov    $0x1,%al
call   1040 <greedy@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%ecx
mov    -0x34(%rbp),%r8d
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%r9d
mov    $0x1,%al
call   10c0 <mergecb@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x60(%rbp),%r9
mov    -0x48(%rbp),%rax
movsd  0xb48(%rip),%xmm0
mov    %rax,(%rsp)
mov    $0x1,%al
call   10d0 <gla@plt>
cmpl   $0x0,-0x64(%rbp)
je     14ee <quantize+0x33e>
mov    -0x34(%rbp),%esi
lea    0xb51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quantize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movss  %xmm0,0x38(%rsp)
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,0x68(%rsp)
mov    %rdi,%r15
mov    %r8d,%ebp
imul   %ecx,%ebp
mov    %ebp,0x44(%rsp)
imul   %edx,%ebp
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,0x48(%rsp)
lea    0x4(%rbx),%eax
mov    %r13,0x50(%rsp)
lea    0x4(%r13),%ebx
imul   %eax,%ebx
mov    %ebp,0x3c(%rsp)
movslq %ebp,%rdi
mov    $0x4,%esi
mov    %rdi,0x60(%rsp)
call   1060 <calloc@plt>
mov    %rax,0x20(%rsp)
imul   %r12d,%ebx
movslq %ebx,%rdi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
test   %r14d,%r14d
mov    %r14d,0x34(%rsp)
mov    %r12d,0x1c(%rsp)
jle    1329 <quantize+0x169>
mov    %r14d,%eax
mov    %r12d,%edx
imul   0x50(%rsp),%edx
imul   0x48(%rsp),%edx
mov    %edx,0x40(%rsp)
xorps  %xmm1,%xmm1
xor    %ebp,%ebp
xor    %r13d,%r13d
mov    %r15,0x58(%rsp)
mov    0x48(%rsp),%rbx
mov    0x50(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,0x28(%rsp)
movss  %xmm1,0x10(%rsp)
movslq %ebp,%rbp
mov    0x58(%rsp),%rax
lea    (%rax,%rbp,4),%rdi
mov    %rdi,0x70(%rsp)
mov    %rcx,%r14
mov    %rcx,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    $0x2,%r8d
mov    0x1c(%rsp),%r15d
mov    %r15d,%r9d
xor    %eax,%eax
call   1070 <extendboundfloat@plt>
movslq %r13d,%r13
mov    0x20(%rsp),%rax
lea    (%rax,%r13,4),%r9
mov    %r15d,(%rsp)
mov    0x70(%rsp),%rdi
mov    0x58(%rsp),%r15
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    $0x2,%r8d
xor    %eax,%eax
call   10c0 <pga@plt>
mov    %r14,%rcx
movss  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mov    0x28(%rsp),%rax
addss  %xmm0,%xmm1
add    0x44(%rsp),%r13d
add    0x40(%rsp),%ebp
add    $0xffffffffffffffff,%rax
jne    1290 <quantize+0xd0>
jmp    132c <quantize+0x16c>
xorps  %xmm1,%xmm1
mov    0x1c(%rsp),%r12d
xorps  %xmm0,%xmm0
cvtsi2ssl 0x34(%rsp),%xmm0
divss  %xmm0,%xmm1
movss  %xmm1,0x10(%rsp)
mov    %rcx,%rdi
call   1030 <free@plt>
mov    0x3c(%rsp),%r14d
test   %r14d,%r14d
mov    0x20(%rsp),%rbx
jle    1387 <quantize+0x1c7>
mov    %r14d,%r13d
xor    %ebp,%ebp
movss  (%rbx,%rbp,4),%xmm0
xorps  0xc94(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
call   1080 <exp@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1360 <quantize+0x1a0>
mov    $0x1,%esi
mov    0x60(%rsp),%rdi
call   1060 <calloc@plt>
mov    %rax,%r13
movss  0x10(%rsp),%xmm0
addss  %xmm0,%xmm0
call   10b0 <roundf@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
divsd  0xc58(%rip),%xmm1
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
jb     13da <quantize+0x21a>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    13e3 <quantize+0x223>
movapd %xmm1,%xmm0
call   10a0 <sqrt@plt>
mulsd  0xc2d(%rip),%xmm0
call   1090 <round@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
ja     1428 <quantize+0x268>
xorpd  %xmm1,%xmm1
movsd  0x28(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jb     1416 <quantize+0x256>
sqrtsd %xmm0,%xmm0
jmp    141b <quantize+0x25b>
call   10a0 <sqrt@plt>
mulsd  0xbf5(%rip),%xmm0
call   1090 <round@plt>
cvttsd2si %xmm0,%eax
cmp    $0x100,%eax
mov    $0x100,%ecx
cmovl  %eax,%ecx
mov    0x20(%rsp),%rbx
mov    %rbx,(%rsp)
movsd  0xbd6(%rip),%xmm0
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r12d,%edx
mov    0x68(%rsp),%rbp
mov    %rbp,%r8
mov    %r13,%r9
mov    $0x1,%al
call   1050 <greedy@plt>
movss  0x38(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
mov    %eax,%r8d
mov    %r12d,%r9d
mov    $0x1,%al
call   10d0 <mergecb@plt>
mov    %r14d,%esi
mov    %eax,%r14d
mov    %rbx,(%rsp)
movsd  0xb8e(%rip),%xmm0
mov    %r15,%rdi
mov    %r12d,%edx
mov    %eax,%ecx
mov    %rbp,%r8
mov    %r13,%r9
mov    $0x1,%al
call   10e0 <gla@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"color quantization\0A\00"
@.str.1 = [7 x i8] c"N=%d \0A\00"
define i32 @quantize(float* %0, float** %1, i32 %2, i32 %3, i32 %4, i32 %5, float %6) {
%8 = alloca float*
%9 = alloca float**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca float*
%20 = alloca float*
%21 = alloca float
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i8*
%26 = alloca i32
store float* %0, float** %8
store float** %1, float*** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store float %6, float* %14
store i32 0, i32* %26
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %12
%31 = mul nsw i32 %29, %30
store i32 %31, i32* %24
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %17
%33 = load i32, i32* %11
%34 = load i32, i32* %17
%35 = mul nsw i32 2, %34
%36 = add nsw i32 %33, %35
store i32 %36, i32* %22
%37 = load i32, i32* %12
%38 = load i32, i32* %17
%39 = mul nsw i32 2, %38
%40 = add nsw i32 %37, %39
store i32 %40, i32* %23
%41 = load i32, i32* %24
%42 = sext i32 %41 to i64
%43 = call i8* @calloc(i64 %42, i64 4)
%44 = bitcast i8* %43 to float*
store float* %44, float** %20
%45 = load i32, i32* %22
%46 = load i32, i32* %23
%47 = mul nsw i32 %45, %46
%48 = load i32, i32* %13
%49 = mul nsw i32 %47, %48
%50 = sext i32 %49 to i64
%51 = call i8* @calloc(i64 %50, i64 4)
%52 = bitcast i8* %51 to float*
store float* %52, float** %19
store float 0.000000e+00, float* %21
store i32 0, i32* %15
br label %53
53: ; preds = %101, %7
%54 = load i32, i32* %15
%55 = load i32, i32* %10
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %104
57: ; preds = %53
%58 = load float*, float** %8
%59 = load i32, i32* %15
%60 = load i32, i32* %11
%61 = mul nsw i32 %59, %60
%62 = load i32, i32* %12
%63 = mul nsw i32 %61, %62
%64 = load i32, i32* %13
%65 = mul nsw i32 %63, %64
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds float, float* %58, i64 %66
%68 = load float*, float** %19
%69 = load i32, i32* %11
%70 = load i32, i32* %12
%71 = load i32, i32* %17
%72 = load i32, i32* %13
%73 = call i32 (float*, float*, i32, i32, i32, i32, ...) bitcast (i32 (...)* @extendboundfloat to i32 (float*, float*, i32, i32, i32, i32, ...)*)(float* %67, float* %68, i32 %69, i32 %70, i32 %71, i32 %72)
%74 = load float*, float** %8
%75 = load i32, i32* %15
%76 = load i32, i32* %11
%77 = mul nsw i32 %75, %76
%78 = load i32, i32* %12
%79 = mul nsw i32 %77, %78
%80 = load i32, i32* %13
%81 = mul nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds float, float* %74, i64 %82
%84 = load float*, float** %19
%85 = load i32, i32* %11
%86 = load i32, i32* %12
%87 = load i32, i32* %17
%88 = load float*, float** %20
%89 = load i32, i32* %15
%90 = load i32, i32* %11
%91 = mul nsw i32 %89, %90
%92 = load i32, i32* %12
%93 = mul nsw i32 %91, %92
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds float, float* %88, i64 %94
%96 = load i32, i32* %13
%97 = call i32 (float*, float*, i32, i32, i32, float*, i32, ...) bitcast (i32 (...)* @pga to i32 (float*, float*, i32, i32, i32, float*, i32, ...)*)(float* %83, float* %84, i32 %85, i32 %86, i32 %87, float* %95, i32 %96)
%98 = sitofp i32 %97 to float
%99 = load float, float* %21
%100 = fadd float %99, %98
store float %100, float* %21
br label %101
101: ; preds = %57
%102 = load i32, i32* %15
%103 = add nsw i32 %102, 1
store i32 %103, i32* %15
br label %53
104: ; preds = %53
%105 = load i32, i32* %10
%106 = sitofp i32 %105 to float
%107 = load float, float* %21
%108 = fdiv float %107, %106
store float %108, float* %21
%109 = load float*, float** %19
%110 = bitcast float* %109 to i8*
store i32 0, i32* %16
br label %111
111: ; preds = %129, %104
%112 = load i32, i32* %16
%113 = load i32, i32* %24
%114 = icmp slt i32 %112, %113
br i1 %114, label %115, label %132
115: ; preds = %111
%116 = load float*, float** %20
%117 = load i32, i32* %16
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds float, float* %116, i64 %118
%120 = load float, float* %119
%121 = fneg float %120
%122 = fpext float %121 to double
%123 = call double @exp(double %122)
%124 = fptrunc double %123 to float
%125 = load float*, float** %20
%126 = load i32, i32* %16
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds float, float* %125, i64 %127
store float %124, float* %128
br label %129
129: ; preds = %115
%130 = load i32, i32* %16
%131 = add nsw i32 %130, 1
store i32 %131, i32* %16
br label %111
132: ; preds = %111
%133 = load i32, i32* %24
%134 = sext i32 %133 to i64
%135 = call i8* @calloc(i64 %134, i64 1)
store i8* %135, i8** %25
%136 = load float, float* %21
%137 = fmul float 2.000000e+00, %136
%138 = fpext float %137 to double
%139 = call double @llvm.round.f64(double %138)
%140 = load i32, i32* %13
%141 = sitofp i32 %140 to double
%142 = fdiv double %141, 3.000000e+00
%143 = call double @sqrt(double %142)
%144 = fmul double 1.700000e+01, %143
%145 = call double @llvm.round.f64(double %144)
%146 = fcmp ogt double %139, %145
br i1 %146, label %147, label %152
147: ; preds = %132
%148 = load float, float* %21
%149 = fmul float 2.000000e+00, %148
%150 = fpext float %149 to double
%151 = call double @llvm.round.f64(double %150)
br label %159
152: ; preds = %132
%153 = load i32, i32* %13
%154 = sitofp i32 %153 to double
%155 = fdiv double %154, 3.000000e+00
%156 = call double @sqrt(double %155)
%157 = fmul double 1.700000e+01, %156
%158 = call double @llvm.round.f64(double %157)
br label %159
159: ; preds = %152, %147
%160 = phi double [ %151, %147 ], [ %158, %152 ]
%161 = fptosi double %160 to i32
store i32 %161, i32* %18
%162 = load i32, i32* %18
%163 = icmp sgt i32 %162, 256
br i1 %163, label %164, label %165
164: ; preds = %159
store i32 256, i32* %18
br label %165
165: ; preds = %164, %159
%166 = load float*, float** %8
%167 = load i32, i32* %24
%168 = load i32, i32* %13
%169 = load i32, i32* %18
%170 = load float**, float*** %9
%171 = load i8*, i8** %25
%172 = load float*, float** %20
%173 = call i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...) bitcast (i32 (...)* @greedy to i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...)*)(float* %166, i32 %167, i32 %168, i32 %169, float** %170, double 5.000000e-02, i8* %171, float* %172)
store i32 %173, i32* %18
%174 = load float*, float** %8
%175 = load float**, float*** %9
%176 = load i8*, i8** %25
%177 = load i32, i32* %24
%178 = load i32, i32* %18
%179 = load float, float* %14
%180 = fpext float %179 to double
%181 = load i32, i32* %13
%182 = call i32 (float*, float**, i8*, i32, i32, double, i32, ...) bitcast (i32 (...)* @mergecb to i32 (float*, float**, i8*, i32, i32, double, i32, ...)*)(float* %174, float** %175, i8* %176, i32 %177, i32 %178, double %180, i32 %181)
store i32 %182, i32* %18
%183 = load float*, float** %8
%184 = load i32, i32* %24
%185 = load i32, i32* %13
%186 = load i32, i32* %18
%187 = load float**, float*** %9
%188 = load i8*, i8** %25
%189 = load float*, float** %20
%190 = call i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...) bitcast (i32 (...)* @gla to i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...)*)(float* %183, i32 %184, i32 %185, i32 %186, float** %187, double 3.000000e-02, i8* %188, float* %189)
%191 = load i32, i32* %26
%192 = icmp ne i32 %191, 0
br i1 %192, label %193, label %196
193: ; preds = %165
%194 = load i32, i32* %18
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %194)
br label %196
196: ; preds = %193, %165
%197 = load float*, float** %20
%198 = bitcast float* %197 to i8*
%199 = load i8*, i8** %25
%200 = load i32, i32* %18
ret i32 %200
}

LLVM IR (-O2):
@str = [19 x i8] c"color quantization\00"
define i32 @quantize(float* %0, float** %1, i32 %2, i32 %3, i32 %4, i32 %5, float %6) {
%8 = mul i32 %4, %3
%9 = mul i32 %8, %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%11 = add nsw i32 %3, 4
%12 = add nsw i32 %4, 4
%13 = sext i32 %9 to i64
%14 = tail call i8* @calloc(i64 %13, i64 4)
%15 = bitcast i8* %14 to float*
%16 = mul nsw i32 %12, %11
%17 = mul nsw i32 %16, %5
%18 = sext i32 %17 to i64
%19 = tail call i8* @calloc(i64 %18, i64 4)
%20 = bitcast i8* %19 to float*
%21 = icmp sgt i32 %2, 0
br i1 %21, label %22, label %40
22: ; preds = %7
%23 = zext i32 %2 to i64
br label %24
24: ; preds = %22, %24
%25 = phi i64 [ 0, %22 ], [ %38, %24 ]
%26 = phi float [ 0.000000e+00, %22 ], [ %37, %24 ]
%27 = trunc i64 %25 to i32
%28 = mul i32 %8, %27
%29 = mul nsw i32 %28, %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds float, float* %0, i64 %30
%32 = tail call i32 (float*, float*, i32, i32, i32, i32, ...) bitcast (i32 (...)* @extendboundfloat to i32 (float*, float*, i32, i32, i32, i32, ...)*)(float* %31, float* %20, i32 %3, i32 %4, i32 2, i32 %5)
%33 = sext i32 %28 to i64
%34 = getelementptr inbounds float, float* %15, i64 %33
%35 = tail call i32 (float*, float*, i32, i32, i32, float*, i32, ...) bitcast (i32 (...)* @pga to i32 (float*, float*, i32, i32, i32, float*, i32, ...)*)(float* %31, float* %20, i32 %3, i32 %4, i32 2, float* %34, i32 %5)
%36 = sitofp i32 %35 to float
%37 = fadd float %26, %36
%38 = add nuw nsw i64 %25, 1
%39 = icmp eq i64 %38, %23
br i1 %39, label %40, label %24
40: ; preds = %24, %7
%41 = phi float [ 0.000000e+00, %7 ], [ %37, %24 ]
%42 = sitofp i32 %2 to float
%43 = fdiv float %41, %42
tail call void @free(i8* %19)
%44 = icmp sgt i32 %9, 0
br i1 %44, label %45, label %57
45: ; preds = %40
%46 = zext i32 %9 to i64
br label %47
47: ; preds = %45, %47
%48 = phi i64 [ 0, %45 ], [ %55, %47 ]
%49 = getelementptr inbounds float, float* %15, i64 %48
%50 = load float, float* %49
%51 = fneg float %50
%52 = fpext float %51 to double
%53 = tail call double @exp(double %52)
%54 = fptrunc double %53 to float
store float %54, float* %49
%55 = add nuw nsw i64 %48, 1
%56 = icmp eq i64 %55, %46
br i1 %56, label %57, label %47
57: ; preds = %47, %40
%58 = tail call i8* @calloc(i64 %13, i64 1)
%59 = fmul float %43, 2.000000e+00
%60 = tail call float @llvm.round.f32(float %59)
%61 = fpext float %60 to double
%62 = sitofp i32 %5 to double
%63 = fdiv double %62, 3.000000e+00
%64 = tail call double @sqrt(double %63)
%65 = fmul double %64, 1.700000e+01
%66 = tail call double @llvm.round.f64(double %65)
%67 = fcmp olt double %66, %61
br i1 %67, label %72, label %68
68: ; preds = %57
%69 = tail call double @sqrt(double %63)
%70 = fmul double %69, 1.700000e+01
%71 = tail call double @llvm.round.f64(double %70)
br label %72
72: ; preds = %57, %68
%73 = phi double [ %71, %68 ], [ %61, %57 ]
%74 = fptosi double %73 to i32
%75 = icmp slt i32 %74, 256
%76 = select i1 %75, i32 %74, i32 256
%77 = tail call i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...) bitcast (i32 (...)* @greedy to i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...)*)(float* %0, i32 %9, i32 %5, i32 %76, float** %1, double 5.000000e-02, i8* %58, float* %15)
%78 = fpext float %6 to double
%79 = tail call i32 (float*, float**, i8*, i32, i32, double, i32, ...) bitcast (i32 (...)* @mergecb to i32 (float*, float**, i8*, i32, i32, double, i32, ...)*)(float* %0, float** %1, i8* %58, i32 %9, i32 %77, double %78, i32 %5)
%80 = tail call i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...) bitcast (i32 (...)* @gla to i32 (float*, i32, i32, i32, float**, double, i8*, float*, ...)*)(float* %0, i32 %9, i32 %5, i32 %79, float** %1, double 3.000000e-02, i8* %58, float* %15)
tail call void @free(i8* %14)
tail call void @free(i8* %58)
ret i32 %79
}