#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 */
int floor(double);
void groj_palette_phase(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;
    }
  }
  if (nval < 0.25) {
    double v = 4 * nval;
    rgb[0] = floor(255.99 * v);
    rgb[1] = 0;
    rgb[2] = 0;
    return;
  }
  if (nval >= 0.25 && nval < 0.5) {
    double v = 4 * (nval - 0.25);
    rgb[0] = 255;
    rgb[1] = floor(255.99 * v);
    rgb[2] = floor(255.99 * v);
    return;
  }
  if (nval >= 0.5 && nval < 0.75) {
    double v = 4 * (nval - 0.5);
    rgb[0] = 255 - floor(255.99 * v);
    rgb[1] = 255 - floor(255.99 * v);
    rgb[2] = 255;
    return;
  }
  double v = 4 * (nval - 0.75);
  rgb[0] = 0;
  rgb[1] = 0;
  rgb[2] = 255 - floor(255.99 * v);
}


x86 assembly (clang, -O0):
<groj_palette_phase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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_phase+0x3c>
movsd  -0x8(%rbp),%xmm0
movsd  0xebe(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a4 <groj_palette_phase+0x94>
cmpb   $0x0,-0x11(%rbp)
je     1172 <groj_palette_phase+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    137b <groj_palette_phase+0x26b>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    118d <groj_palette_phase+0x7d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119a <groj_palette_phase+0x8a>
movsd  0xe6b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119f <groj_palette_phase+0x8f>
jmp    11a4 <groj_palette_phase+0x94>
movsd  0xe5c(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11f8 <groj_palette_phase+0xe8>
movsd  0xe69(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe4f(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <floor@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
jmp    137b <groj_palette_phase+0x26b>
movsd  -0x8(%rbp),%xmm0
movsd  0xe03(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1286 <groj_palette_phase+0x176>
movsd  0xdf9(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1286 <groj_palette_phase+0x176>
movsd  -0x8(%rbp),%xmm1
movsd  0xdd9(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xded(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
movsd  0xdcd(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1030 <floor@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movsd  0xdb2(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1030 <floor@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
jmp    137b <groj_palette_phase+0x26b>
movsd  -0x8(%rbp),%xmm0
movsd  0xd7d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1326 <groj_palette_phase+0x216>
movsd  0xd73(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1326 <groj_palette_phase+0x216>
movsd  -0x8(%rbp),%xmm1
movsd  0xd53(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd5f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd46(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1030 <floor@plt>
mov    %eax,%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movsd  0xd23(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1030 <floor@plt>
mov    %eax,%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x2(%rax)
jmp    137b <groj_palette_phase+0x26b>
movsd  -0x8(%rbp),%xmm1
movsd  0xce5(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xce9(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
movsd  0xcc1(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1030 <floor@plt>
mov    %eax,%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<groj_palette_phase>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     118f <groj_palette_phase+0x7f>
ucomisd 0xed6(%rip),%xmm0
ja     118f <groj_palette_phase+0x7f>
movsd  0xed4(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     11ae <groj_palette_phase+0x9e>
ucomisd 0xec6(%rip),%xmm0
jb     11cd <groj_palette_phase+0xbd>
movsd  0xec0(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11cd <groj_palette_phase+0xbd>
addsd  0xeda(%rip),%xmm0
mulsd  0xec2(%rip),%xmm0
movb   $0xff,(%rbx)
mulsd  0xebf(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <floor@plt>
mov    %al,0x1(%rbx)
movsd  0x8(%rsp),%xmm0
call   1030 <floor@plt>
jmp    124c <groj_palette_phase+0x13c>
test   %sil,%sil
je     11a0 <groj_palette_phase+0x90>
movw   $0xff00,(%rbx)
xor    %eax,%eax
jmp    124c <groj_palette_phase+0x13c>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
jbe    1220 <groj_palette_phase+0x110>
mulsd  0xe72(%rip),%xmm0
mulsd  0xe72(%rip),%xmm0
call   1030 <floor@plt>
mov    %al,(%rbx)
movb   $0x0,0x1(%rbx)
xor    %eax,%eax
jmp    124c <groj_palette_phase+0x13c>
ucomisd 0xe3b(%rip),%xmm0
jb     1228 <groj_palette_phase+0x118>
movsd  0xe39(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1228 <groj_palette_phase+0x118>
addsd  0xe33(%rip),%xmm0
mulsd  0xe33(%rip),%xmm0
mulsd  0xe33(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <floor@plt>
not    %al
mov    %al,(%rbx)
movsd  0x8(%rsp),%xmm0
call   1030 <floor@plt>
not    %al
mov    %al,0x1(%rbx)
mov    $0xff,%al
jmp    124c <groj_palette_phase+0x13c>
movsd  0xdd8(%rip),%xmm0
addsd  0xe10(%rip),%xmm0
mulsd  0xdf0(%rip),%xmm0
movw   $0x0,(%rbx)
mulsd  0xdeb(%rip),%xmm0
call   1030 <floor@plt>
not    %al
mov    %al,0x2(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @groj_palette_phase(double %0, i8* %1, i8 signext %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i8
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%11 = load double, double* %4
%12 = fcmp olt double %11, 0.000000e+00
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load double, double* %4
%15 = fcmp ogt double %14, 1.000000e+00
br i1 %15, label %16, label %33
16: ; preds = %13, %3
%17 = load i8, i8* %6
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 -1, i8* %23
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8 0, i8* %25
br label %114
26: ; preds = %16
%27 = load double, double* %4
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %26
store double 0.000000e+00, double* %4
br label %31
30: ; preds = %26
store double 1.000000e+00, double* %4
br label %31
31: ; preds = %30, %29
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32, %13
%34 = load double, double* %4
%35 = fcmp olt double %34, 2.500000e-01
br i1 %35, label %36, label %49
36: ; preds = %33
%37 = load double, double* %4
%38 = fmul double 4.000000e+00, %37
store double %38, double* %7
%39 = load double, double* %7
%40 = fmul double 2.559900e+02, %39
%41 = call i32 @floor(double %40)
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 %42, i8* %44
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8 0, i8* %46
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i64 2
store i8 0, i8* %48
br label %114
49: ; preds = %33
%50 = load double, double* %4
%51 = fcmp oge double %50, 2.500000e-01
br i1 %51, label %52, label %73
52: ; preds = %49
%53 = load double, double* %4
%54 = fcmp olt double %53, 5.000000e-01
br i1 %54, label %55, label %73
55: ; preds = %52
%56 = load double, double* %4
%57 = fsub double %56, 2.500000e-01
%58 = fmul double 4.000000e+00, %57
store double %58, double* %8
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 0
store i8 -1, i8* %60
%61 = load double, double* %8
%62 = fmul double 2.559900e+02, %61
%63 = call i32 @floor(double %62)
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i64 1
store i8 %64, i8* %66
%67 = load double, double* %8
%68 = fmul double 2.559900e+02, %67
%69 = call i32 @floor(double %68)
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i64 2
store i8 %70, i8* %72
br label %114
73: ; preds = %52, %49
%74 = load double, double* %4
%75 = fcmp oge double %74, 5.000000e-01
br i1 %75, label %76, label %99
76: ; preds = %73
%77 = load double, double* %4
%78 = fcmp olt double %77, 7.500000e-01
br i1 %78, label %79, label %99
79: ; preds = %76
%80 = load double, double* %4
%81 = fsub double %80, 5.000000e-01
%82 = fmul double 4.000000e+00, %81
store double %82, double* %9
%83 = load double, double* %9
%84 = fmul double 2.559900e+02, %83
%85 = call i32 @floor(double %84)
%86 = sub nsw i32 255, %85
%87 = trunc i32 %86 to i8
%88 = load i8*, i8** %5
%89 = getelementptr inbounds i8, i8* %88, i64 0
store i8 %87, i8* %89
%90 = load double, double* %9
%91 = fmul double 2.559900e+02, %90
%92 = call i32 @floor(double %91)
%93 = sub nsw i32 255, %92
%94 = trunc i32 %93 to i8
%95 = load i8*, i8** %5
%96 = getelementptr inbounds i8, i8* %95, i64 1
store i8 %94, i8* %96
%97 = load i8*, i8** %5
%98 = getelementptr inbounds i8, i8* %97, i64 2
store i8 -1, i8* %98
br label %114
99: ; preds = %76, %73
%100 = load double, double* %4
%101 = fsub double %100, 7.500000e-01
%102 = fmul double 4.000000e+00, %101
store double %102, double* %10
%103 = load i8*, i8** %5
%104 = getelementptr inbounds i8, i8* %103, i64 0
store i8 0, i8* %104
%105 = load i8*, i8** %5
%106 = getelementptr inbounds i8, i8* %105, i64 1
store i8 0, i8* %106
%107 = load double, double* %10
%108 = fmul double 2.559900e+02, %107
%109 = call i32 @floor(double %108)
%110 = sub nsw i32 255, %109
%111 = trunc i32 %110 to i8
%112 = load i8*, i8** %5
%113 = getelementptr inbounds i8, i8* %112, i64 2
store i8 %111, i8* %113
br label %114
114: ; preds = %99, %79, %55, %36, %19
ret void
}

LLVM IR (-O2):
define void @groj_palette_phase(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 %12
7: ; preds = %3
%8 = icmp eq i8 %2, 0
br i1 %8, label %11, label %9
9: ; preds = %7
store i8 0, i8* %1
%10 = getelementptr inbounds i8, i8* %1, i64 1
store i8 -1, i8* %10
br label %58
11: ; preds = %7
br i1 %4, label %14, label %49
12: ; preds = %3
%13 = fcmp olt double %0, 2.500000e-01
br i1 %13, label %14, label %21
14: ; preds = %11, %12
%15 = phi double [ %0, %12 ], [ 0.000000e+00, %11 ]
%16 = fmul double %15, 4.000000e+00
%17 = fmul double %16, 2.559900e+02
%18 = tail call i32 @floor(double %17)
%19 = trunc i32 %18 to i8
store i8 %19, i8* %1
%20 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %20
br label %58
21: ; preds = %12
%22 = fcmp oge double %0, 2.500000e-01
%23 = fcmp olt double %0, 5.000000e-01
%24 = and i1 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = fadd double %0, -2.500000e-01
%27 = fmul double %26, 4.000000e+00
store i8 -1, i8* %1
%28 = fmul double %27, 2.559900e+02
%29 = tail call i32 @floor(double %28)
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %30, i8* %31
%32 = tail call i32 @floor(double %28)
%33 = trunc i32 %32 to i8
br label %58
34: ; preds = %21
%35 = fcmp oge double %0, 5.000000e-01
%36 = fcmp olt double %0, 7.500000e-01
%37 = and i1 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = fadd double %0, -5.000000e-01
%40 = fmul double %39, 4.000000e+00
%41 = fmul double %40, 2.559900e+02
%42 = tail call i32 @floor(double %41)
%43 = trunc i32 %42 to i8
%44 = xor i8 %43, -1
store i8 %44, i8* %1
%45 = tail call i32 @floor(double %41)
%46 = trunc i32 %45 to i8
%47 = xor i8 %46, -1
%48 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %47, i8* %48
br label %58
49: ; preds = %11, %34
%50 = phi double [ %0, %34 ], [ 1.000000e+00, %11 ]
%51 = fadd double %50, -7.500000e-01
%52 = fmul double %51, 4.000000e+00
store i8 0, i8* %1
%53 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %53
%54 = fmul double %52, 2.559900e+02
%55 = tail call i32 @floor(double %54)
%56 = trunc i32 %55 to i8
%57 = xor i8 %56, -1
br label %58
58: ; preds = %49, %38, %25, %14, %9
%59 = phi i8 [ %57, %49 ], [ -1, %38 ], [ %33, %25 ], [ 0, %14 ], [ 0, %9 ]
%60 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %59, i8* %60
ret void
}