#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 */
int analogRead(int);
float log(float);
float temperatureRead(int pin, int model) {
  float bValue;
  if (model == 2) {
    bValue = 4250.0f;
  } else if (model == 1) {
    bValue = 4250.0f;
  } else {
    bValue = 3975.0f;
  }
  int a = analogRead(pin);
  float resistance = (float)(1023 - a) * 10000.0f / a;
  float t =
      (float)(1 / (log(resistance / 10000) / bValue + 1 / 298.15) - 273.15);
  return t;
}


x86 assembly (clang, -O0):
<temperatureRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    114a <temperatureRead+0x2a>
movss  0xec4(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1178 <temperatureRead+0x58>
cmpl   $0x1,-0x8(%rbp)
jne    1166 <temperatureRead+0x46>
movss  0xea8(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1173 <temperatureRead+0x53>
movss  0xe92(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1178 <temperatureRead+0x58>
mov    -0x4(%rbp),%edi
call   1040 <analogRead@plt>
mov    %eax,-0x10(%rbp)
mov    $0x3ff,%eax
sub    -0x10(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  0xe71(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe52(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <log@plt>
divss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe50(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe3c(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe28(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<temperatureRead>:
push   %rbx
add    $0xffffffff,%esi
xor    %ebx,%ebx
cmp    $0x2,%esi
setb   %bl
call   1040 <analogRead@plt>
mov    $0x3ff,%ecx
sub    %eax,%ecx
cvtsi2ss %ecx,%xmm0
cvtsi2ss %eax,%xmm1
movss  0xeb8(%rip),%xmm2
mulss  %xmm2,%xmm0
divss  %xmm1,%xmm0
divss  %xmm2,%xmm0
call   1030 <log@plt>
lea    0xea8(%rip),%rax
divss  (%rax,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe9f(%rip),%xmm0
movsd  0xe9f(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe9b(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
pop    %rbx
ret

LLVM IR (-O0):
define float @temperatureRead(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
%7 = alloca float
%8 = alloca float
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store float 4.250000e+03, float* %5
br label %18
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
store float 4.250000e+03, float* %5
br label %17
16: ; preds = %12
store float 3.975000e+03, float* %5
br label %17
17: ; preds = %16, %15
br label %18
18: ; preds = %17, %11
%19 = load i32, i32* %3
%20 = call i32 @analogRead(i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = sub nsw i32 1023, %21
%23 = sitofp i32 %22 to float
%24 = fmul float %23, 1.000000e+04
%25 = load i32, i32* %6
%26 = sitofp i32 %25 to float
%27 = fdiv float %24, %26
store float %27, float* %7
%28 = load float, float* %7
%29 = fdiv float %28, 1.000000e+04
%30 = call float @log(float %29)
%31 = load float, float* %5
%32 = fdiv float %30, %31
%33 = fpext float %32 to double
%34 = fadd double %33, 0x3F6B79E1DCB5DB83
%35 = fdiv double 1.000000e+00, %34
%36 = fsub double %35, 2.731500e+02
%37 = fptrunc double %36 to float
store float %37, float* %8
%38 = load float, float* %8
ret float %38
}

LLVM IR (-O2):
define float @temperatureRead(i32 %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp ult i32 %3, 2
%5 = select i1 %4, float 4.250000e+03, float 3.975000e+03
%6 = tail call i32 @analogRead(i32 %0)
%7 = sub nsw i32 1023, %6
%8 = sitofp i32 %7 to float
%9 = fmul float %8, 1.000000e+04
%10 = sitofp i32 %6 to float
%11 = fdiv float %9, %10
%12 = fdiv float %11, 1.000000e+04
%13 = tail call float @log(float %12)
%14 = fdiv float %13, %5
%15 = fpext float %14 to double
%16 = fadd double %15, 0x3F6B79E1DCB5DB83
%17 = fdiv double 1.000000e+00, %16
%18 = fadd double %17, -2.731500e+02
%19 = fptrunc double %18 to float
ret float %19
}