double temp2celsius(double temperature, char tscale, double toffset) {
  double tempc;
  temperature -= toffset;
  switch (tscale) {
  case 'F':
    tempc = (temperature - 32.0) / 1.8;
    break;
  case 'R':
    tempc = (temperature - 32.0 - 459.67) / 1.8;
    break;
  case 'K':
    tempc = temperature - 273.15;
    break;
  default:
    tempc = temperature;
    break;
  }
  return tempc;
}


x86 assembly (clang, -O0):
<temp2celsius>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
movsd  %xmm0,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x46,%eax
je     115e <temp2celsius+0x5e>
jmp    113c <temp2celsius+0x3c>
mov    -0x24(%rbp),%eax
sub    $0x4b,%eax
je     11b8 <temp2celsius+0xb8>
jmp    114d <temp2celsius+0x4d>
mov    -0x24(%rbp),%eax
sub    $0x52,%eax
je     1185 <temp2celsius+0x85>
jmp    11d3 <temp2celsius+0xd3>
movsd  -0x8(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe91(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11dd <temp2celsius+0xdd>
movsd  -0x8(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe72(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe5e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11dd <temp2celsius+0xdd>
movsd  -0x8(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11dd <temp2celsius+0xdd>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<temp2celsius>:
subsd  %xmm1,%xmm0
cmp    $0x52,%edi
je     1124 <temp2celsius+0x24>
cmp    $0x4b,%edi
je     113d <temp2celsius+0x3d>
cmp    $0x46,%edi
jne    1145 <temp2celsius+0x45>
addsd  0xeed(%rip),%xmm0
divsd  0xef5(%rip),%xmm0
ret
addsd  0xedc(%rip),%xmm0
addsd  0xedc(%rip),%xmm0
divsd  0xedc(%rip),%xmm0
ret
addsd  0xebb(%rip),%xmm0
ret

LLVM IR (-O0):
define double @temp2celsius(double %0, i8 signext %1, double %2) {
%4 = alloca double
%5 = alloca i8
%6 = alloca double
%7 = alloca double
store double %0, double* %4
store i8 %1, i8* %5
store double %2, double* %6
%8 = load double, double* %6
%9 = load double, double* %4
%10 = fsub double %9, %8
store double %10, double* %4
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
switch i32 %12, label %25 [
i32 70, label %13
i32 82, label %17
i32 75, label %22
]
13: ; preds = %3
%14 = load double, double* %4
%15 = fsub double %14, 3.200000e+01
%16 = fdiv double %15, 1.800000e+00
store double %16, double* %7
br label %27
17: ; preds = %3
%18 = load double, double* %4
%19 = fsub double %18, 3.200000e+01
%20 = fsub double %19, 4.596700e+02
%21 = fdiv double %20, 1.800000e+00
store double %21, double* %7
br label %27
22: ; preds = %3
%23 = load double, double* %4
%24 = fsub double %23, 2.731500e+02
store double %24, double* %7
br label %27
25: ; preds = %3
%26 = load double, double* %4
store double %26, double* %7
br label %27
27: ; preds = %25, %22, %17, %13
%28 = load double, double* %7
ret double %28
}

LLVM IR (-O2):
define double @temp2celsius(double %0, i8 signext %1, double %2) {
%4 = fsub double %0, %2
%5 = sext i8 %1 to i32
switch i32 %5, label %15 [
i32 70, label %6
i32 82, label %9
i32 75, label %13
]
6: ; preds = %3
%7 = fadd double %4, -3.200000e+01
%8 = fdiv double %7, 1.800000e+00
br label %15
9: ; preds = %3
%10 = fadd double %4, -3.200000e+01
%11 = fadd double %10, -4.596700e+02
%12 = fdiv double %11, 1.800000e+00
br label %15
13: ; preds = %3
%14 = fadd double %4, -2.731500e+02
br label %15
15: ; preds = %3, %13, %9, %6
%16 = phi double [ %14, %13 ], [ %12, %9 ], [ %8, %6 ], [ %4, %3 ]
ret double %16
}