#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_gray(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 * nval);
  rgb[0] = c;
  rgb[1] = c;
  rgb[2] = c;
}


x86 assembly (clang, -O0):
<groj_palette_gray>:
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_gray+0x3c>
movsd  -0x8(%rbp),%xmm0
movsd  0xebe(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a4 <groj_palette_gray+0x94>
cmpb   $0x0,-0x11(%rbp)
je     1172 <groj_palette_gray+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    11d6 <groj_palette_gray+0xc6>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    118d <groj_palette_gray+0x7d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119a <groj_palette_gray+0x8a>
movsd  0xe6b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119f <groj_palette_gray+0x8f>
jmp    11a4 <groj_palette_gray+0x94>
movsd  0xe5c(%rip),%xmm0
mulsd  -0x8(%rbp),%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_gray>:
push   %rbx
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1128 <groj_palette_gray+0x18>
ucomisd 0xeda(%rip),%xmm0
jbe    1148 <groj_palette_gray+0x38>
test   %sil,%sil
je     1133 <groj_palette_gray+0x23>
mov    $0xff,%cl
xor    %eax,%eax
jmp    1157 <groj_palette_gray+0x47>
xorpd  %xmm1,%xmm1
cmpltsd %xmm1,%xmm0
movsd  0xebc(%rip),%xmm1
andnpd %xmm1,%xmm0
mulsd  0xeb8(%rip),%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_gray(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 %43
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 = fmul double 2.559900e+02, %31
%33 = call zeroext i8 @floor(double %32)
store i8 %33, i8* %7
%34 = load i8, i8* %7
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 0
store i8 %34, i8* %36
%37 = load i8, i8* %7
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8 %37, i8* %39
%40 = load i8, i8* %7
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 2
store i8 %40, i8* %42
br label %43
43: ; preds = %30, %16
ret void
}

LLVM IR (-O2):
define void @groj_palette_gray(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 %15
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 = fmul double %12, 2.559900e+02
%14 = tail call zeroext i8 @floor(double %13)
br label %15
15: ; preds = %7, %11
%16 = phi i8 [ %14, %11 ], [ 0, %7 ]
%17 = phi i8 [ %14, %11 ], [ -1, %7 ]
store i8 %16, i8* %1
%18 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %17, i8* %18
%19 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %16, i8* %19
ret void
}