#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 */

/* Variables and functions */
unsigned char floor(double);
void groj_palette_igray(double nval, unsigned char *rgb, char diffout) {
  if (nval < 0.0 || nval > 1.0) {
    if (diffout) {
      rgb[0] = 0;
      rgb[1] = 255;
      rgb[2] = 0;
      return;
    } else {
      if (nval < 0.0)
        nval = 0.0;
      else
        nval = 1.0;
    }
  }
  unsigned char c = floor(255.99 * (1.0 - nval));
  rgb[0] = c;
  rgb[1] = c;
  rgb[2] = c;
}


x86 assembly (clang, -O0):
<groj_palette_igray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     114c <groj_palette_igray+0x3c>
movsd  -0x8(%rbp),%xmm0
movsd  0xebe(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a4 <groj_palette_igray+0x94>
cmpb   $0x0,-0x11(%rbp)
je     1172 <groj_palette_igray+0x62>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
jmp    11e2 <groj_palette_igray+0xd2>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    118d <groj_palette_igray+0x7d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119a <groj_palette_igray+0x8a>
movsd  0xe6b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119f <groj_palette_igray+0x8f>
jmp    11a4 <groj_palette_igray+0x94>
movsd  0xe54(%rip),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe4f(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <floor@plt>
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x12(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x12(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<groj_palette_igray>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1128 <groj_palette_igray+0x18>
ucomisd 0xeda(%rip),%xmm0
jbe    1148 <groj_palette_igray+0x38>
test   %sil,%sil
je     1133 <groj_palette_igray+0x23>
mov    $0xff,%cl
xor    %eax,%eax
jmp    1167 <groj_palette_igray+0x57>
xorpd  %xmm1,%xmm1
cmpltsd %xmm1,%xmm0
movsd  0xebc(%rip),%xmm1
andnpd %xmm1,%xmm0
movsd  0xeb0(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xeac(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <floor@plt>
mov    %eax,%ecx
mov    %al,(%rbx)
mov    %cl,0x1(%rbx)
mov    %al,0x2(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @groj_palette_igray(double %0, i8* %1, i8 signext %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
store double %0, double* %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%8 = load double, double* %4
%9 = fcmp olt double %8, 0.000000e+00
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load double, double* %4
%12 = fcmp ogt double %11, 1.000000e+00
br i1 %12, label %13, label %30
13: ; preds = %10, %3
%14 = load i8, i8* %6
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 0, i8* %18
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 -1, i8* %20
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8 0, i8* %22
br label %44
23: ; preds = %13
%24 = load double, double* %4
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %26, label %27
26: ; preds = %23
store double 0.000000e+00, double* %4
br label %28
27: ; preds = %23
store double 1.000000e+00, double* %4
br label %28
28: ; preds = %27, %26
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29, %10
%31 = load double, double* %4
%32 = fsub double 1.000000e+00, %31
%33 = fmul double 2.559900e+02, %32
%34 = call zeroext i8 @floor(double %33)
store i8 %34, i8* %7
%35 = load i8, i8* %7
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 0
store i8 %35, i8* %37
%38 = load i8, i8* %7
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8 %38, i8* %40
%41 = load i8, i8* %7
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8 %41, i8* %43
br label %44
44: ; preds = %30, %16
ret void
}

LLVM IR (-O2):
define void @groj_palette_igray(double %0, i8* nocapture writeonly %1, i8 signext %2) {
%4 = fcmp olt double %0, 0.000000e+00
%5 = fcmp ogt double %0, 1.000000e+00
%6 = or i1 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = icmp eq i8 %2, 0
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = select i1 %4, double 0.000000e+00, double 1.000000e+00
br label %11
11: ; preds = %9, %3
%12 = phi double [ %0, %3 ], [ %10, %9 ]
%13 = fsub double 1.000000e+00, %12
%14 = fmul double %13, 2.559900e+02
%15 = tail call zeroext i8 @floor(double %14)
br label %16
16: ; preds = %7, %11
%17 = phi i8 [ %15, %11 ], [ 0, %7 ]
%18 = phi i8 [ %15, %11 ], [ -1, %7 ]
store i8 %17, i8* %1
%19 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %18, i8* %19
%20 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %17, i8* %20
ret void
}