#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_waterfall(uint32_t *rgba, int N, void *arg) {
  int i;
  for (i = 0; i < N; i++) {
    float p = (1.0f * i) / (N - 1);
    _set_rgba_from_hsv(&rgba[i], 0.75f - (p * 0.75f), 1.0f,
                       ((p * 0.95f) + 0.05f));
  }
  return 0;
}


x86 assembly (clang, -O0):
<fosphor_gl_cmap_waterfall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c3 <fosphor_gl_cmap_waterfall+0xb3>
cvtsi2ssl -0x1c(%rbp),%xmm1
movss  0xebd(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
movss  -0x20(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  0xe89(%rip),%xmm1
mulss  %xmm1,%xmm0
addss  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm2
movss  0xe6c(%rip),%xmm1
mulss  %xmm1,%xmm2
movss  0xe64(%rip),%xmm1
addss  %xmm1,%xmm2
movss  0xe50(%rip),%xmm1
call   1030 <_set_rgba_from_hsv@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <fosphor_gl_cmap_waterfall+0x1a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fosphor_gl_cmap_waterfall>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    118d <fosphor_gl_cmap_waterfall+0x7d>
mov    %rdi,%r15
lea    -0x1(%rsi),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %esi,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm2,%xmm2
cvtsi2ss %ebx,%xmm2
divss  0xc(%rsp),%xmm2
movaps %xmm2,%xmm1
movss  0xea8(%rip),%xmm0
mulss  %xmm0,%xmm1
subss  %xmm1,%xmm0
mulss  0xe9c(%rip),%xmm2
addss  0xe98(%rip),%xmm2
mov    %r15,%rdi
movss  0xe91(%rip),%xmm1
call   1030 <_set_rgba_from_hsv@plt>
add    $0x1,%rbx
add    $0x4,%r15
cmp    %rbx,%r14
jne    1140 <fosphor_gl_cmap_waterfall+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @fosphor_gl_cmap_waterfall(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca float
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %31, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i32, i32* %7
%15 = sitofp i32 %14 to float
%16 = fmul float 1.000000e+00, %15
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1
%19 = sitofp i32 %18 to float
%20 = fdiv float %16, %19
store float %20, float* %8
%21 = load i32*, i32** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load float, float* %8
%26 = fneg float %25
%27 = call float @llvm.fmuladd.f32(float %26, float 7.500000e-01, float 7.500000e-01)
%28 = load float, float* %8
%29 = call float @llvm.fmuladd.f32(float %28, float 0x3FEE666660000000, float 0x3FA99999A0000000)
%30 = call i32 @_set_rgba_from_hsv(i32* %24, float %27, float 1.000000e+00, float %29)
br label %31
31: ; preds = %13
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %9
34: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
define i32 @fosphor_gl_cmap_waterfall(i32* %0, i32 %1, i8* nocapture readnone %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %21
5: ; preds = %3
%6 = add nsw i32 %1, -1
%7 = sitofp i32 %6 to float
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %19, %9 ]
%11 = trunc i64 %10 to i32
%12 = sitofp i32 %11 to float
%13 = fdiv float %12, %7
%14 = getelementptr inbounds i32, i32* %0, i64 %10
%15 = fneg float %13
%16 = tail call float @llvm.fmuladd.f32(float %15, float 7.500000e-01, float 7.500000e-01)
%17 = tail call float @llvm.fmuladd.f32(float %13, float 0x3FEE666660000000, float 0x3FA99999A0000000)
%18 = tail call i32 @_set_rgba_from_hsv(i32* %14, float %16, float 1.000000e+00, float %17)
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %9
21: ; preds = %9, %3
ret i32 0
}