#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ _set_rgba_from_hsv(int /*<<< orphan*/ *, float, float,
                                      float);
void fosphor_gl_cmap_histogram(uint32_t *rgba, int N) {
  int i;
  int m = N >> 4;
  for (i = 0; i < m; i++) {
    float p = (1.0f * i) / (N - 1);
    _set_rgba_from_hsv(&rgba[i], 0.90f, 0.50f, 0.15f + 4.0f * p);
  }
  for (i = m; i < N; i++) {
    float p = (1.0f * i) / (N - 1);
    _set_rgba_from_hsv(&rgba[i], 0.80f - p * 0.80f,
                       1.00f - ((p < 0.85f) ? 0.0f : ((p - 0.85f) * 3.0f)),
                       0.60f + ((p < 0.40f) ? p : 0.40f));
  }
}


x86 assembly (clang, -O0):
<fosphor_gl_cmap_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ae <fosphor_gl_cmap_histogram+0x9e>
cvtsi2ssl -0x10(%rbp),%xmm1
movss  0xec0(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
movss  -0x18(%rbp),%xmm2
movss  0xea5(%rip),%xmm0
mulss  %xmm0,%xmm2
movss  0xe9d(%rip),%xmm0
addss  %xmm0,%xmm2
movss  0xe85(%rip),%xmm0
movss  0xe81(%rip),%xmm1
call   1030 <_set_rgba_from_hsv@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112f <fosphor_gl_cmap_histogram+0x1f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12da <fosphor_gl_cmap_histogram+0x1ca>
cvtsi2ssl -0x10(%rbp),%xmm1
movss  0xe3b(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  0xdf3(%rip),%xmm1
mulss  %xmm1,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xdda(%rip),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jbe    123d <fosphor_gl_cmap_histogram+0x12d>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    125f <fosphor_gl_cmap_histogram+0x14f>
movss  -0x1c(%rbp),%xmm0
movss  0xdb6(%rip),%xmm1
subss  %xmm1,%xmm0
movss  0xdb6(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm1
movss  0xd9c(%rip),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xd93(%rip),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jbe    1296 <fosphor_gl_cmap_histogram+0x186>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12a8 <fosphor_gl_cmap_histogram+0x198>
movss  0xd72(%rip),%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    12a8 <fosphor_gl_cmap_histogram+0x198>
movss  -0x30(%rbp),%xmm1
movss  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
movss  -0x34(%rbp),%xmm3
movss  0xd51(%rip),%xmm2
addss  %xmm3,%xmm2
call   1030 <_set_rgba_from_hsv@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b4 <fosphor_gl_cmap_histogram+0xa4>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fosphor_gl_cmap_histogram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%r13d
sar    $0x4,%r13d
cmp    $0x10,%esi
jl     1192 <fosphor_gl_cmap_histogram+0x82>
lea    -0x1(%r15),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
cmp    $0x2,%r13d
mov    $0x1,%r12d
cmovge %r13d,%r12d
xor    %ebp,%ebp
mov    %r14,%rbx
xchg   %ax,%ax
xorps  %xmm2,%xmm2
cvtsi2ss %ebp,%xmm2
divss  0x4(%rsp),%xmm2
mulss  0xe9b(%rip),%xmm2
addss  0xe97(%rip),%xmm2
mov    %rbx,%rdi
movss  0xe90(%rip),%xmm0
movss  0xe8c(%rip),%xmm1
call   1030 <_set_rgba_from_hsv@plt>
add    $0x1,%rbp
add    $0x4,%rbx
cmp    %rbp,%r12
jne    1150 <fosphor_gl_cmap_histogram+0x40>
cmp    %r15d,%r13d
jge    123d <fosphor_gl_cmap_histogram+0x12d>
lea    -0x1(%r15),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
movslq %r13d,%rax
lea    (%r14,%rax,4),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm2,%xmm2
cvtsi2ss %r13d,%xmm2
divss  0x4(%rsp),%xmm2
movaps %xmm2,%xmm1
movss  0xe37(%rip),%xmm0
mulss  %xmm0,%xmm1
subss  %xmm1,%xmm0
movaps %xmm2,%xmm3
addss  0xe28(%rip),%xmm3
mulss  0xe24(%rip),%xmm3
movss  0xe20(%rip),%xmm5
addss  %xmm5,%xmm3
movaps %xmm2,%xmm1
cmpltss 0xe14(%rip),%xmm1
movaps %xmm1,%xmm4
andnps %xmm3,%xmm4
andps  %xmm5,%xmm1
orps   %xmm4,%xmm1
minss  0xe04(%rip),%xmm2
addss  0xe00(%rip),%xmm2
mov    %rbx,%rdi
call   1030 <_set_rgba_from_hsv@plt>
add    $0x4,%rbx
add    $0x1,%r13d
cmp    %r13d,%r15d
jne    11c0 <fosphor_gl_cmap_histogram+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fosphor_gl_cmap_histogram(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = ashr i32 %9, 4
store i32 %10, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %30, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32, i32* %5
%17 = sitofp i32 %16 to float
%18 = fmul float 1.000000e+00, %17
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sitofp i32 %20 to float
%22 = fdiv float %18, %21
store float %22, float* %7
%23 = load i32*, i32** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load float, float* %7
%28 = call float @llvm.fmuladd.f32(float 4.000000e+00, float %27, float 0x3FC3333340000000)
%29 = call i32 @_set_rgba_from_hsv(i32* %26, float 0x3FECCCCCC0000000, float 5.000000e-01, float %28)
br label %30
30: ; preds = %15
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %11
33: ; preds = %11
%34 = load i32, i32* %6
store i32 %34, i32* %5
br label %35
35: ; preds = %73, %33
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %76
39: ; preds = %35
%40 = load i32, i32* %5
%41 = sitofp i32 %40 to float
%42 = fmul float 1.000000e+00, %41
%43 = load i32, i32* %4
%44 = sub nsw i32 %43, 1
%45 = sitofp i32 %44 to float
%46 = fdiv float %42, %45
store float %46, float* %8
%47 = load i32*, i32** %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load float, float* %8
%52 = fneg float %51
%53 = call float @llvm.fmuladd.f32(float %52, float 0x3FE99999A0000000, float 0x3FE99999A0000000)
%54 = load float, float* %8
%55 = fcmp olt float %54, 0x3FEB333340000000
br i1 %55, label %56, label %57
56: ; preds = %39
br label %61
57: ; preds = %39
%58 = load float, float* %8
%59 = fsub float %58, 0x3FEB333340000000
%60 = fmul float %59, 3.000000e+00
br label %61
61: ; preds = %57, %56
%62 = phi float [ 0.000000e+00, %56 ], [ %60, %57 ]
%63 = fsub float 1.000000e+00, %62
%64 = load float, float* %8
%65 = fcmp olt float %64, 0x3FD99999A0000000
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = load float, float* %8
br label %69
68: ; preds = %61
br label %69
69: ; preds = %68, %66
%70 = phi float [ %67, %66 ], [ 0x3FD99999A0000000, %68 ]
%71 = fadd float 0x3FE3333340000000, %70
%72 = call i32 @_set_rgba_from_hsv(i32* %50, float %53, float %63, float %71)
br label %73
73: ; preds = %69
%74 = load i32, i32* %5
%75 = add nsw i32 %74, 1
store i32 %75, i32* %5
br label %35
76: ; preds = %35
ret void
}

LLVM IR (-O2):
define void @fosphor_gl_cmap_histogram(i32* %0, i32 %1) {
%3 = ashr i32 %1, 4
%4 = icmp sgt i32 %1, 15
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = add nsw i32 %1, -1
%7 = sitofp i32 %6 to float
%8 = call i32 @llvm.smax.i32(i32 %3, i32 1)
%9 = zext i32 %8 to i64
br label %16
10: ; preds = %16, %2
%11 = icmp slt i32 %3, %1
br i1 %11, label %12, label %46
12: ; preds = %10
%13 = add nsw i32 %1, -1
%14 = sitofp i32 %13 to float
%15 = sext i32 %3 to i64
br label %26
16: ; preds = %5, %16
%17 = phi i64 [ 0, %5 ], [ %24, %16 ]
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to float
%20 = fdiv float %19, %7
%21 = getelementptr inbounds i32, i32* %0, i64 %17
%22 = tail call float @llvm.fmuladd.f32(float %20, float 4.000000e+00, float 0x3FC3333340000000)
%23 = tail call i32 @_set_rgba_from_hsv(i32* %21, float 0x3FECCCCCC0000000, float 5.000000e-01, float %22)
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %10, label %16
26: ; preds = %12, %26
%27 = phi i64 [ %15, %12 ], [ %43, %26 ]
%28 = trunc i64 %27 to i32
%29 = sitofp i32 %28 to float
%30 = fdiv float %29, %14
%31 = getelementptr inbounds i32, i32* %0, i64 %27
%32 = fneg float %30
%33 = tail call float @llvm.fmuladd.f32(float %32, float 0x3FE99999A0000000, float 0x3FE99999A0000000)
%34 = fcmp olt float %30, 0x3FEB333340000000
%35 = fadd float %30, 0xBFEB333340000000
%36 = fmul float %35, 3.000000e+00
%37 = fsub float 1.000000e+00, %36
%38 = select i1 %34, float 1.000000e+00, float %37
%39 = fcmp olt float %30, 0x3FD99999A0000000
%40 = select i1 %39, float %30, float 0x3FD99999A0000000
%41 = fadd float %40, 0x3FE3333340000000
%42 = tail call i32 @_set_rgba_from_hsv(i32* %31, float %33, float %38, float %41)
%43 = add nsw i64 %27, 1
%44 = trunc i64 %43 to i32
%45 = icmp eq i32 %44, %1
br i1 %45, label %46, label %26
46: ; preds = %26, %10
ret void
}