#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 */
double fabs(double);
int pow(double, double);
double sin(int);
int color_grad(double val) {
  if (fabs(val - 1.0) < 1.0e-10)
    return 0;
  double sinus = sin(20 * pow(val, 0.1));
  double sinus2 = sin(13 * pow(val, 0.125));
  double sinus3 = sin(17 * pow(val, 0.07));
  return (unsigned char)((sinus + 1) * 127.5) +
         ((unsigned char)((sinus2 + 1) * 127.5) << 8) +
         ((unsigned char)((sinus3 + 1) * 127.5) << 16);
}


x86 assembly (clang, -O0):
<color_grad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  0xece(%rip),%xmm0
subsd  %xmm0,%xmm1
movaps 0xeeb(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xeaf(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1167 <color_grad+0x47>
movl   $0x0,-0x4(%rbp)
jmp    1233 <color_grad+0x113>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
call   1040 <pow@plt>
mov    %eax,%ecx
shl    $0x2,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,4),%edi
call   1030 <sin@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
call   1040 <pow@plt>
mov    %eax,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%edx
mov    %edx,%ecx
lea    (%rax,%rcx,4),%edi
call   1030 <sin@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe5e(%rip),%xmm1
call   1040 <pow@plt>
mov    %eax,%edi
mov    %edi,%eax
shl    $0x4,%eax
add    %eax,%edi
call   1030 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe21(%rip),%xmm2
addsd  %xmm2,%xmm0
movsd  0xe35(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
movzbl %al,%eax
movsd  -0x20(%rbp),%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
movzbl %cl,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsd  -0x28(%rbp),%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
movzbl %cl,%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color_grad>:
sub    $0x18,%rsp
movsd  0xed4(%rip),%xmm2
addsd  %xmm0,%xmm2
andpd  0xf08(%rip),%xmm2
xor    %eax,%eax
movsd  0xec6(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     1203 <color_grad+0xe3>
movsd  0xebc(%rip),%xmm1
movsd  %xmm0,(%rsp)
call   1040 <pow@plt>
shl    $0x2,%eax
lea    (%rax,%rax,4),%edi
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xea1(%rip),%xmm1
movsd  (%rsp),%xmm0
call   1040 <pow@plt>
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rcx,4),%edi
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe86(%rip),%xmm1
movsd  (%rsp),%xmm0
call   1040 <pow@plt>
mov    %eax,%edi
shl    $0x4,%edi
add    %eax,%edi
call   1030 <sin@plt>
movsd  0xe70(%rip),%xmm1
movsd  0x10(%rsp),%xmm3
addsd  %xmm1,%xmm3
movsd  0xe66(%rip),%xmm2
mulsd  %xmm2,%xmm3
cvttsd2si %xmm3,%eax
movzbl %al,%eax
movsd  0x8(%rsp),%xmm3
addsd  %xmm1,%xmm3
mulsd  %xmm2,%xmm3
cvttsd2si %xmm3,%ecx
movzbl %cl,%ecx
shl    $0x8,%ecx
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edx
or     %eax,%ecx
movzbl %dl,%eax
shl    $0x10,%eax
or     %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @color_grad(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %3
%7 = load double, double* %3
%8 = fsub double %7, 1.000000e+00
%9 = call double @llvm.fabs.f64(double %8)
%10 = fcmp olt double %9, 1.000000e-10
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %44
12: ; preds = %1
%13 = load double, double* %3
%14 = call i32 @pow(double %13, double 1.000000e-01)
%15 = mul nsw i32 20, %14
%16 = call double @sin(i32 %15)
store double %16, double* %4
%17 = load double, double* %3
%18 = call i32 @pow(double %17, double 1.250000e-01)
%19 = mul nsw i32 13, %18
%20 = call double @sin(i32 %19)
store double %20, double* %5
%21 = load double, double* %3
%22 = call i32 @pow(double %21, double 7.000000e-02)
%23 = mul nsw i32 17, %22
%24 = call double @sin(i32 %23)
store double %24, double* %6
%25 = load double, double* %4
%26 = fadd double %25, 1.000000e+00
%27 = fmul double %26, 1.275000e+02
%28 = fptoui double %27 to i8
%29 = zext i8 %28 to i32
%30 = load double, double* %5
%31 = fadd double %30, 1.000000e+00
%32 = fmul double %31, 1.275000e+02
%33 = fptoui double %32 to i8
%34 = zext i8 %33 to i32
%35 = shl i32 %34, 8
%36 = add nsw i32 %29, %35
%37 = load double, double* %6
%38 = fadd double %37, 1.000000e+00
%39 = fmul double %38, 1.275000e+02
%40 = fptoui double %39 to i8
%41 = zext i8 %40 to i32
%42 = shl i32 %41, 16
%43 = add nsw i32 %36, %42
store i32 %43, i32* %2
br label %44
44: ; preds = %12, %11
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
define i32 @color_grad(double %0) {
%2 = fadd double %0, -1.000000e+00
%3 = tail call double @llvm.fabs.f64(double %2)
%4 = fcmp olt double %3, 1.000000e-10
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = tail call i32 @pow(double %0, double 1.000000e-01)
%7 = mul nsw i32 %6, 20
%8 = tail call double @sin(i32 %7)
%9 = tail call i32 @pow(double %0, double 1.250000e-01)
%10 = mul nsw i32 %9, 13
%11 = tail call double @sin(i32 %10)
%12 = tail call i32 @pow(double %0, double 7.000000e-02)
%13 = mul nsw i32 %12, 17
%14 = tail call double @sin(i32 %13)
%15 = fadd double %8, 1.000000e+00
%16 = fmul double %15, 1.275000e+02
%17 = fptoui double %16 to i8
%18 = zext i8 %17 to i32
%19 = fadd double %11, 1.000000e+00
%20 = fmul double %19, 1.275000e+02
%21 = fptoui double %20 to i8
%22 = zext i8 %21 to i32
%23 = shl nuw nsw i32 %22, 8
%24 = or i32 %23, %18
%25 = fadd double %14, 1.000000e+00
%26 = fmul double %25, 1.275000e+02
%27 = fptoui double %26 to i8
%28 = zext i8 %27 to i32
%29 = shl nuw nsw i32 %28, 16
%30 = or i32 %29, %24
br label %31
31: ; preds = %1, %5
%32 = phi i32 [ %30, %5 ], [ 0, %1 ]
ret i32 %32
}