#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;

/* Variables and functions */
int get_calibration_value(int, char *);
float adc_to_temperature(int sensor, char *calibration_file, uint16_t adc) {
  int R2K2 = get_calibration_value(sensor, calibration_file);
  float aT = -167.123;
  float bT = 0.275501;
  float cT = -0.000102316;
  float dT = 1.92025e-08;
  float volt = (2.5 / 1023) * adc;
  float R = R2K2 * adc / (2048.0 - adc);
  return aT + R * (bT + R * (cT + R * dT));
}


x86 assembly (clang, -O0):
<adc_to_temperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <get_calibration_value@plt>
mov    %eax,-0x1c(%rbp)
movss  0xee1(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xed0(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xebf(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  0xeae(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movsd  0xe99(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xe71(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x20(%rbp),%xmm1
movss  -0x34(%rbp),%xmm0
movss  -0x24(%rbp),%xmm3
movss  -0x34(%rbp),%xmm2
movss  -0x28(%rbp),%xmm5
movss  -0x34(%rbp),%xmm4
movss  -0x2c(%rbp),%xmm6
mulss  %xmm6,%xmm4
addss  %xmm5,%xmm4
mulss  %xmm4,%xmm2
addss  %xmm3,%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adc_to_temperature>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <get_calibration_value@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xecd(%rip),%xmm1
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movss  0xebe(%rip),%xmm0
mulss  %xmm1,%xmm0
addss  0xeb6(%rip),%xmm0
mulss  %xmm1,%xmm0
addss  0xeae(%rip),%xmm0
mulss  %xmm1,%xmm0
addss  0xea6(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @adc_to_temperature(i32 %0, i8* %1, double %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca double
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
store i32 %0, i32* %4
store i8* %1, i8** %5
store double %2, double* %6
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = call i32 @get_calibration_value(i32 %14, i8* %15)
store i32 %16, i32* %7
store float 0xC064E3EFA0000000, float* %8
store float 0x3FD1A1CF00000000, float* %9
store float 0xBF1AD24F80000000, float* %10
store float 0x3E549E57C0000000, float* %11
%17 = load double, double* %6
%18 = fmul double 0x3F64050140501405, %17
%19 = fptrunc double %18 to float
store float %19, float* %12
%20 = load i32, i32* %7
%21 = sitofp i32 %20 to double
%22 = load double, double* %6
%23 = fmul double %21, %22
%24 = load double, double* %6
%25 = fsub double 2.048000e+03, %24
%26 = fdiv double %23, %25
%27 = fptrunc double %26 to float
store float %27, float* %13
%28 = load float, float* %8
%29 = load float, float* %13
%30 = load float, float* %9
%31 = load float, float* %13
%32 = load float, float* %10
%33 = load float, float* %13
%34 = load float, float* %11
%35 = call float @llvm.fmuladd.f32(float %33, float %34, float %32)
%36 = call float @llvm.fmuladd.f32(float %31, float %35, float %30)
%37 = call float @llvm.fmuladd.f32(float %29, float %36, float %28)
ret float %37
}

LLVM IR (-O2):
define float @adc_to_temperature(i32 %0, i8* %1, double %2) {
%4 = tail call i32 @get_calibration_value(i32 %0, i8* %1)
%5 = sitofp i32 %4 to double
%6 = fmul double %5, %2
%7 = fsub double 2.048000e+03, %2
%8 = fdiv double %6, %7
%9 = fptrunc double %8 to float
%10 = tail call float @llvm.fmuladd.f32(float %9, float 0x3E549E57C0000000, float 0xBF1AD24F80000000)
%11 = tail call float @llvm.fmuladd.f32(float %9, float %10, float 0x3FD1A1CF00000000)
%12 = tail call float @llvm.fmuladd.f32(float %9, float %11, float 0xC064E3EFA0000000)
ret float %12
}