void temperature_to_colour(double temperature, unsigned char *r,
                           unsigned char *g, unsigned char *b,
                           unsigned char *transparency) {
  const double max_temperature = 1600;
  const double medium_temperature = 800;
  const double min_temperature = 500;
  const int transparency_hot = 100;
  const int transparency_cold = 230;
  int colour_hot[] = {252, 157, 153};
  int colour_medium[] = {148, 24, 24};
  int colour_cold[] = {200, 200, 200};
  if (temperature < min_temperature) {
    temperature = min_temperature;
  }
  if (temperature > max_temperature) {
    temperature = max_temperature;
  }
  if (temperature > medium_temperature) {
    *r = (unsigned char)(colour_medium[0] +
                         ((temperature - medium_temperature) *
                          (colour_hot[0] - colour_medium[0]) /
                          (max_temperature - medium_temperature)));
    *g = (unsigned char)(colour_medium[1] +
                         ((temperature - medium_temperature) *
                          (colour_hot[1] - colour_medium[1]) /
                          (max_temperature - medium_temperature)));
    *b = (unsigned char)(colour_medium[2] +
                         ((temperature - medium_temperature) *
                          (colour_hot[2] - colour_medium[2]) /
                          (max_temperature - medium_temperature)));
  } else {
    *r = (unsigned char)(colour_cold[0] +
                         ((temperature - min_temperature) *
                          (colour_medium[0] - colour_cold[0]) /
                          (medium_temperature - min_temperature)));
    *g = (unsigned char)(colour_cold[1] +
                         ((temperature - min_temperature) *
                          (colour_medium[1] - colour_cold[1]) /
                          (medium_temperature - min_temperature)));
    *b = (unsigned char)(colour_cold[2] +
                         ((temperature - min_temperature) *
                          (colour_medium[2] - colour_cold[2]) /
                          (medium_temperature - min_temperature)));
  }
  *transparency = (unsigned char)(transparency_cold +
                                  ((temperature - min_temperature) *
                                   (transparency_hot - transparency_cold) /
                                   (max_temperature - min_temperature)));
}


x86 assembly (clang, -O0):
<temperature_to_colour>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movsd  0xeef(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeda(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x64,-0x44(%rbp)
movl   $0xe6,-0x48(%rbp)
mov    0xeeb(%rip),%rax
mov    %rax,-0x54(%rbp)
mov    0xee9(%rip),%eax
mov    %eax,-0x4c(%rbp)
mov    0xee3(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xee1(%rip),%eax
mov    %eax,-0x58(%rbp)
mov    0xedb(%rip),%rax
mov    %rax,-0x6c(%rbp)
mov    0xed9(%rip),%eax
mov    %eax,-0x64(%rbp)
movsd  0xe6e(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11aa <temperature_to_colour+0xaa>
movsd  0xe5b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe59(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ce <temperature_to_colour+0xce>
movsd  0xe47(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe2d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1285 <temperature_to_colour+0x185>
mov    -0x60(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xe0f(%rip),%xmm2
subsd  %xmm2,%xmm1
mov    -0x54(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm3
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x5c(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  %xmm2,%xmm1
mov    -0x50(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm3
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x58(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  %xmm2,%xmm1
mov    -0x4c(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm3
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    1328 <temperature_to_colour+0x228>
mov    -0x6c(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xd67(%rip),%xmm3
subsd  %xmm3,%xmm1
mov    -0x60(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd66(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x68(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  %xmm3,%xmm1
mov    -0x5c(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm4
mulsd  %xmm4,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x64(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  %xmm3,%xmm1
mov    -0x58(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm3
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
movsd  -0x8(%rbp),%xmm0
movsd  0xceb(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xce7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xce3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xcdf(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<temperature_to_colour>:
movsd  0xef8(%rip),%xmm1
maxsd  %xmm0,%xmm1
movsd  0xef4(%rip),%xmm0
minsd  %xmm1,%xmm0
ucomisd 0xef0(%rip),%xmm0
jbe    1194 <temperature_to_colour+0x94>
movsd  0xf16(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xf12(%rip),%xmm2
mulsd  %xmm1,%xmm2
movsd  0xece(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  0xf02(%rip),%xmm2
cvttsd2si %xmm2,%eax
mov    %al,(%rdi)
movsd  0xefc(%rip),%xmm2
mulsd  %xmm1,%xmm2
divsd  %xmm3,%xmm2
movsd  0xef4(%rip),%xmm4
addsd  %xmm4,%xmm2
cvttsd2si %xmm2,%eax
mov    %al,(%rsi)
mulsd  0xeea(%rip),%xmm1
divsd  %xmm3,%xmm1
addsd  %xmm4,%xmm1
cvttsd2si %xmm1,%eax
addsd  0xe86(%rip),%xmm0
jmp    11e0 <temperature_to_colour+0xe0>
addsd  0xe7c(%rip),%xmm0
movsd  0xe7c(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe78(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe74(%rip),%xmm3
addsd  %xmm3,%xmm1
cvttsd2si %xmm1,%eax
mov    %al,(%rdi)
movsd  0xe6a(%rip),%xmm1
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm3,%xmm1
cvttsd2si %xmm1,%eax
mov    %al,(%rsi)
mulsd  0xe88(%rip),%xmm0
divsd  0xe88(%rip),%xmm0
addsd  0xe88(%rip),%xmm0
mov    %al,(%rdx)
cvttsd2si %xmm0,%eax
mov    %al,(%rcx)
ret

LLVM IR (-O0):
@__const.temperature_to_colour.colour_hot = [3 x i32] [i32 252, i32 157, i32 153]
@__const.temperature_to_colour.colour_medium = [3 x i32] [i32 148, i32 24, i32 24]
@__const.temperature_to_colour.colour_cold = [3 x i32] [i32 200, i32 200, i32 200]
define void @temperature_to_colour(double %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca double
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca [3 x i32]
%17 = alloca [3 x i32]
%18 = alloca [3 x i32]
store double %0, double* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store double 1.600000e+03, double* %11
store double 8.000000e+02, double* %12
store double 5.000000e+02, double* %13
store i32 100, i32* %14
store i32 230, i32* %15
%19 = bitcast [3 x i32]* %16 to i8*
%20 = bitcast [3 x i32]* %17 to i8*
%21 = bitcast [3 x i32]* %18 to i8*
%22 = load double, double* %6
%23 = fcmp olt double %22, 5.000000e+02
br i1 %23, label %24, label %25
24: ; preds = %5
store double 5.000000e+02, double* %6
br label %25
25: ; preds = %24, %5
%26 = load double, double* %6
%27 = fcmp ogt double %26, 1.600000e+03
br i1 %27, label %28, label %29
28: ; preds = %25
store double 1.600000e+03, double* %6
br label %29
29: ; preds = %28, %25
%30 = load double, double* %6
%31 = fcmp ogt double %30, 8.000000e+02
br i1 %31, label %32, label %81
32: ; preds = %29
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%34 = load i32, i32* %33
%35 = sitofp i32 %34 to double
%36 = load double, double* %6
%37 = fsub double %36, 8.000000e+02
%38 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%41 = load i32, i32* %40
%42 = sub nsw i32 %39, %41
%43 = sitofp i32 %42 to double
%44 = fmul double %37, %43
%45 = fdiv double %44, 8.000000e+02
%46 = fadd double %35, %45
%47 = fptoui double %46 to i8
%48 = load i8*, i8** %7
store i8 %47, i8* %48
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 1
%50 = load i32, i32* %49
%51 = sitofp i32 %50 to double
%52 = load double, double* %6
%53 = fsub double %52, 8.000000e+02
%54 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 1
%55 = load i32, i32* %54
%56 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 1
%57 = load i32, i32* %56
%58 = sub nsw i32 %55, %57
%59 = sitofp i32 %58 to double
%60 = fmul double %53, %59
%61 = fdiv double %60, 8.000000e+02
%62 = fadd double %51, %61
%63 = fptoui double %62 to i8
%64 = load i8*, i8** %8
store i8 %63, i8* %64
%65 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 2
%66 = load i32, i32* %65
%67 = sitofp i32 %66 to double
%68 = load double, double* %6
%69 = fsub double %68, 8.000000e+02
%70 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i64 0, i64 2
%71 = load i32, i32* %70
%72 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 2
%73 = load i32, i32* %72
%74 = sub nsw i32 %71, %73
%75 = sitofp i32 %74 to double
%76 = fmul double %69, %75
%77 = fdiv double %76, 8.000000e+02
%78 = fadd double %67, %77
%79 = fptoui double %78 to i8
%80 = load i8*, i8** %9
store i8 %79, i8* %80
br label %130
81: ; preds = %29
%82 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 0
%83 = load i32, i32* %82
%84 = sitofp i32 %83 to double
%85 = load double, double* %6
%86 = fsub double %85, 5.000000e+02
%87 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 0
%88 = load i32, i32* %87
%89 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 0
%90 = load i32, i32* %89
%91 = sub nsw i32 %88, %90
%92 = sitofp i32 %91 to double
%93 = fmul double %86, %92
%94 = fdiv double %93, 3.000000e+02
%95 = fadd double %84, %94
%96 = fptoui double %95 to i8
%97 = load i8*, i8** %7
store i8 %96, i8* %97
%98 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 1
%99 = load i32, i32* %98
%100 = sitofp i32 %99 to double
%101 = load double, double* %6
%102 = fsub double %101, 5.000000e+02
%103 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 1
%104 = load i32, i32* %103
%105 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 1
%106 = load i32, i32* %105
%107 = sub nsw i32 %104, %106
%108 = sitofp i32 %107 to double
%109 = fmul double %102, %108
%110 = fdiv double %109, 3.000000e+02
%111 = fadd double %100, %110
%112 = fptoui double %111 to i8
%113 = load i8*, i8** %8
store i8 %112, i8* %113
%114 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 2
%115 = load i32, i32* %114
%116 = sitofp i32 %115 to double
%117 = load double, double* %6
%118 = fsub double %117, 5.000000e+02
%119 = getelementptr inbounds [3 x i32], [3 x i32]* %17, i64 0, i64 2
%120 = load i32, i32* %119
%121 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 2
%122 = load i32, i32* %121
%123 = sub nsw i32 %120, %122
%124 = sitofp i32 %123 to double
%125 = fmul double %118, %124
%126 = fdiv double %125, 3.000000e+02
%127 = fadd double %116, %126
%128 = fptoui double %127 to i8
%129 = load i8*, i8** %9
store i8 %128, i8* %129
br label %130
130: ; preds = %81, %32
%131 = load double, double* %6
%132 = fsub double %131, 5.000000e+02
%133 = fmul double %132, -1.300000e+02
%134 = fdiv double %133, 1.100000e+03
%135 = fadd double 2.300000e+02, %134
%136 = fptoui double %135 to i8
%137 = load i8*, i8** %10
store i8 %136, i8* %137
ret void
}

LLVM IR (-O2):
define void @temperature_to_colour(double %0, i8* nocapture writeonly %1, i8* nocapture writeonly %2, i8* nocapture writeonly %3, i8* nocapture writeonly %4) {
%6 = fcmp olt double %0, 5.000000e+02
%7 = select i1 %6, double 5.000000e+02, double %0
%8 = fcmp ogt double %7, 1.600000e+03
%9 = select i1 %8, double 1.600000e+03, double %7
%10 = fcmp ogt double %9, 8.000000e+02
br i1 %10, label %11, label %26
11: ; preds = %5
%12 = fadd double %9, -8.000000e+02
%13 = fmul double %12, 1.040000e+02
%14 = fdiv double %13, 8.000000e+02
%15 = fadd double %14, 1.480000e+02
%16 = fptoui double %15 to i8
store i8 %16, i8* %1
%17 = fmul double %12, 1.330000e+02
%18 = fdiv double %17, 8.000000e+02
%19 = fadd double %18, 2.400000e+01
%20 = fptoui double %19 to i8
store i8 %20, i8* %2
%21 = fmul double %12, 1.290000e+02
%22 = fdiv double %21, 8.000000e+02
%23 = fadd double %22, 2.400000e+01
%24 = fptoui double %23 to i8
%25 = fadd double %9, -5.000000e+02
br label %36
26: ; preds = %5
%27 = fadd double %9, -5.000000e+02
%28 = fmul double %27, 5.200000e+01
%29 = fdiv double %28, 3.000000e+02
%30 = fsub double 2.000000e+02, %29
%31 = fptoui double %30 to i8
store i8 %31, i8* %1
%32 = fmul double %27, 1.760000e+02
%33 = fdiv double %32, 3.000000e+02
%34 = fsub double 2.000000e+02, %33
%35 = fptoui double %34 to i8
store i8 %35, i8* %2
br label %36
36: ; preds = %26, %11
%37 = phi double [ %27, %26 ], [ %25, %11 ]
%38 = phi i8 [ %35, %26 ], [ %24, %11 ]
store i8 %38, i8* %3
%39 = fmul double %37, 1.300000e+02
%40 = fdiv double %39, 1.100000e+03
%41 = fsub double 2.300000e+02, %40
%42 = fptoui double %41 to i8
store i8 %42, i8* %4
ret void
}