#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 */
typedef double uint16_t;
typedef int uint;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const);
float sot_to_temperature(uint16_t sot, const char units, uint temp_resolution) {
  float temperature;
  if (temp_resolution == 12) {
    if (units == 'c' || units == 'C') {
      temperature = -39.65 + 0.04 * sot;
    } else if (units == 'f' || units == 'F') {
      temperature = -39.4 + 0.072 * sot;
    } else {
      printf("[ERROR] Units must be 'C' or 'F'. '%c' was specified.", units);
      return -1;
    }
  } else if (temp_resolution == 14) {
    if (units == 'c' || units == 'C') {
      temperature = -39.65 + 0.01 * sot;
    } else if (units == 'f' || units == 'F') {
      temperature = -39.4 + 0.018 * sot;
    } else {
      printf("[ERROR] Units must be 'C' or 'F'. '%c' was specified.", units);
      return -1;
    }
  } else {
    printf("[ERROR] Temperature resolution must be 12 or 14 bit.  %d was "
           "selected.\n",
           temp_resolution);
    return -1;
  }
  return temperature;
}


x86 assembly (clang, -O0):
<sot_to_temperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
movsd  %xmm0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %esi,-0x18(%rbp)
cmpl   $0xc,-0x18(%rbp)
jne    11e6 <sot_to_temperature+0xd6>
movsbl -0x11(%rbp),%eax
cmp    $0x63,%eax
je     114a <sot_to_temperature+0x3a>
movsbl -0x11(%rbp),%eax
cmp    $0x43,%eax
jne    1175 <sot_to_temperature+0x65>
movsd  -0x10(%rbp),%xmm0
movsd  0xed9(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xebd(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11e1 <sot_to_temperature+0xd1>
movsbl -0x11(%rbp),%eax
cmp    $0x66,%eax
je     118f <sot_to_temperature+0x7f>
movsbl -0x11(%rbp),%eax
cmp    $0x46,%eax
jne    11ba <sot_to_temperature+0xaa>
movsd  -0x10(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe68(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11dc <sot_to_temperature+0xcc>
lea    0xe77(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <printf@plt>
movss  0xe2e(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12d9 <sot_to_temperature+0x1c9>
jmp    11e1 <sot_to_temperature+0xd1>
jmp    12cf <sot_to_temperature+0x1bf>
cmpl   $0xe,-0x18(%rbp)
jne    12a6 <sot_to_temperature+0x196>
movsbl -0x11(%rbp),%eax
cmp    $0x63,%eax
je     120a <sot_to_temperature+0xfa>
movsbl -0x11(%rbp),%eax
cmp    $0x43,%eax
jne    1235 <sot_to_temperature+0x125>
movsd  -0x10(%rbp),%xmm0
movsd  0xe01(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdfd(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    12a1 <sot_to_temperature+0x191>
movsbl -0x11(%rbp),%eax
cmp    $0x66,%eax
je     124f <sot_to_temperature+0x13f>
movsbl -0x11(%rbp),%eax
cmp    $0x46,%eax
jne    127a <sot_to_temperature+0x16a>
movsd  -0x10(%rbp),%xmm0
movsd  0xdac(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xda8(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    129c <sot_to_temperature+0x18c>
lea    0xdb7(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <printf@plt>
movss  0xd6e(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12d9 <sot_to_temperature+0x1c9>
jmp    12a1 <sot_to_temperature+0x191>
jmp    12ca <sot_to_temperature+0x1ba>
mov    -0x18(%rbp),%eax
lea    0xdbe(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
movss  0xd40(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12d9 <sot_to_temperature+0x1c9>
jmp    12cf <sot_to_temperature+0x1bf>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sot_to_temperature>:
push   %rax
cmp    $0xe,%esi
je     1139 <sot_to_temperature+0x29>
cmp    $0xc,%esi
jne    1157 <sot_to_temperature+0x47>
mov    %edi,%eax
and    $0xdf,%al
cmp    $0x46,%al
je     117e <sot_to_temperature+0x6e>
cmp    $0x43,%al
jne    1164 <sot_to_temperature+0x54>
mulsd  0xef9(%rip),%xmm0
addsd  0xee1(%rip),%xmm0
jmp    1198 <sot_to_temperature+0x88>
mov    %edi,%eax
and    $0xdf,%al
cmp    $0x46,%al
je     1188 <sot_to_temperature+0x78>
cmp    $0x43,%al
jne    1164 <sot_to_temperature+0x54>
mulsd  0xec3(%rip),%xmm0
addsd  0xec3(%rip),%xmm0
jmp    1198 <sot_to_temperature+0x88>
movsbl %sil,%esi
lea    0xf08(%rip),%rdi
jmp    116f <sot_to_temperature+0x5f>
movsbl %dil,%esi
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
movss  0xeb4(%rip),%xmm0
pop    %rax
ret
mulsd  0xe9a(%rip),%xmm0
jmp    1190 <sot_to_temperature+0x80>
mulsd  0xe70(%rip),%xmm0
addsd  0xe70(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [54 x i8] c"[ERROR] Units must be 'C' or 'F'. '%c' was specified.\00"
@.str.1 = [72 x i8] c"[ERROR] Temperature resolution must be 12 or 14 bit. %d was selected.\0A\00"
define float @sot_to_temperature(double %0, i8 signext %1, i32 %2) {
%4 = alloca float
%5 = alloca double
%6 = alloca i8
%7 = alloca i32
%8 = alloca float
store double %0, double* %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 12
br i1 %10, label %11, label %40
11: ; preds = %3
%12 = load i8, i8* %6
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 99
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i8, i8* %6
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 67
br i1 %18, label %19, label %23
19: ; preds = %15, %11
%20 = load double, double* %5
%21 = call double @llvm.fmuladd.f64(double 4.000000e-02, double %20, double -3.965000e+01)
%22 = fptrunc double %21 to float
store float %22, float* %8
br label %39
23: ; preds = %15
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 102
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 70
br i1 %30, label %31, label %35
31: ; preds = %27, %23
%32 = load double, double* %5
%33 = call double @llvm.fmuladd.f64(double 0x3FB26E978D4FDF3B, double %32, double -3.940000e+01)
%34 = fptrunc double %33 to float
store float %34, float* %8
br label %38
35: ; preds = %27
%36 = load i8, i8* %6
%37 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8 signext %36)
store float -1.000000e+00, float* %4
br label %79
38: ; preds = %31
br label %39
39: ; preds = %38, %19
br label %77
40: ; preds = %3
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 14
br i1 %42, label %43, label %72
43: ; preds = %40
%44 = load i8, i8* %6
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 99
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = load i8, i8* %6
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 67
br i1 %50, label %51, label %55
51: ; preds = %47, %43
%52 = load double, double* %5
%53 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %52, double -3.965000e+01)
%54 = fptrunc double %53 to float
store float %54, float* %8
br label %71
55: ; preds = %47
%56 = load i8, i8* %6
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 102
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i8, i8* %6
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 70
br i1 %62, label %63, label %67
63: ; preds = %59, %55
%64 = load double, double* %5
%65 = call double @llvm.fmuladd.f64(double 1.800000e-02, double %64, double -3.940000e+01)
%66 = fptrunc double %65 to float
store float %66, float* %8
br label %70
67: ; preds = %59
%68 = load i8, i8* %6
%69 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8 signext %68)
store float -1.000000e+00, float* %4
br label %79
70: ; preds = %63
br label %71
71: ; preds = %70, %51
br label %76
72: ; preds = %40
%73 = load i32, i32* %7
%74 = trunc i32 %73 to i8
%75 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8 signext %74)
store float -1.000000e+00, float* %4
br label %79
76: ; preds = %71
br label %77
77: ; preds = %76, %39
%78 = load float, float* %8
store float %78, float* %4
br label %79
79: ; preds = %77, %72, %67, %35
%80 = load float, float* %4
ret float %80
}

LLVM IR (-O2):
@.str = [54 x i8] c"[ERROR] Units must be 'C' or 'F'. '%c' was specified.\00"
@.str.1 = [72 x i8] c"[ERROR] Temperature resolution must be 12 or 14 bit. %d was selected.\0A\00"
define float @sot_to_temperature(double %0, i8 signext %1, i32 %2) {
switch i32 %2, label %20 [
i32 12, label %4
i32 14, label %12
]
4: ; preds = %3
%5 = and i8 %1, -33
switch i8 %5, label %10 [
i8 67, label %6
i8 70, label %8
]
6: ; preds = %4
%7 = tail call double @llvm.fmuladd.f64(double %0, double 4.000000e-02, double -3.965000e+01)
br label %23
8: ; preds = %4
%9 = tail call double @llvm.fmuladd.f64(double %0, double 0x3FB26E978D4FDF3B, double -3.940000e+01)
br label %23
10: ; preds = %4
%11 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8 signext %1)
br label %26
12: ; preds = %3
%13 = and i8 %1, -33
switch i8 %13, label %18 [
i8 67, label %14
i8 70, label %16
]
14: ; preds = %12
%15 = tail call double @llvm.fmuladd.f64(double %0, double 1.000000e-02, double -3.965000e+01)
br label %23
16: ; preds = %12
%17 = tail call double @llvm.fmuladd.f64(double %0, double 1.800000e-02, double -3.940000e+01)
br label %23
18: ; preds = %12
%19 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8 signext %1)
br label %26
20: ; preds = %3
%21 = trunc i32 %2 to i8
%22 = tail call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8 signext %21)
br label %26
23: ; preds = %16, %14, %6, %8
%24 = phi double [ %7, %6 ], [ %9, %8 ], [ %15, %14 ], [ %17, %16 ]
%25 = fptrunc double %24 to float
br label %26
26: ; preds = %23, %20, %18, %10
%27 = phi float [ %25, %23 ], [ -1.000000e+00, %10 ], [ -1.000000e+00, %18 ], [ -1.000000e+00, %20 ]
ret float %27
}