#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);
int fosphor_gl_cmap_histogram(uint32_t *rgba, int N, void *arg) {
  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));
  }
  return 0;
}


x86 assembly (clang, -O0):
<fosphor_gl_cmap_histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b2 <fosphor_gl_cmap_histogram+0xa2>
cvtsi2ssl -0x1c(%rbp),%xmm1
movss  0xebc(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
movss  -0x24(%rbp),%xmm2
movss  0xea1(%rip),%xmm0
mulss  %xmm0,%xmm2
movss  0xe99(%rip),%xmm0
addss  %xmm0,%xmm2
movss  0xe81(%rip),%xmm0
movss  0xe7d(%rip),%xmm1
call   1030 <_set_rgba_from_hsv@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1133 <fosphor_gl_cmap_histogram+0x23>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12de <fosphor_gl_cmap_histogram+0x1ce>
cvtsi2ssl -0x1c(%rbp),%xmm1
movss  0xe37(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
movss  -0x28(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  0xdef(%rip),%xmm1
mulss  %xmm1,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  0xdd6(%rip),%xmm0
ucomiss -0x28(%rbp),%xmm0
jbe    1241 <fosphor_gl_cmap_histogram+0x131>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
jmp    1263 <fosphor_gl_cmap_histogram+0x153>
movss  -0x28(%rbp),%xmm0
movss  0xdb2(%rip),%xmm1
subss  %xmm1,%xmm0
movss  0xdb2(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm1
movss  0xd98(%rip),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
movss  0xd8f(%rip),%xmm0
ucomiss -0x28(%rbp),%xmm0
jbe    129a <fosphor_gl_cmap_histogram+0x18a>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
jmp    12ac <fosphor_gl_cmap_histogram+0x19c>
movss  0xd6e(%rip),%xmm0
movss  %xmm0,-0x44(%rbp)
jmp    12ac <fosphor_gl_cmap_histogram+0x19c>
movss  -0x40(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
mov    -0x38(%rbp),%rdi
movss  -0x44(%rbp),%xmm3
movss  0xd4d(%rip),%xmm2
addss  %xmm3,%xmm2
call   1030 <_set_rgba_from_hsv@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b8 <fosphor_gl_cmap_histogram+0xa8>
xor    %eax,%eax
add    $0x50,%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>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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