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

/* Variables and functions */
double log(double);
double pow(double, int);
long uint16_to_temp(uint16_t value) {
  long l;
  double R1 = 10000.0;
  double ADC_FS = 1023.0;
  double Rth, Kelvin_Inv;
  double a = 0.001010024F;
  double b = 0.000242127F;
  double c = 0.000000146F;
  double res;
  Rth = (R1 * (ADC_FS - (double)value)) / (double)value;
  Kelvin_Inv = a + b * log(Rth) + c * pow(log(Rth), 3);
  res = (1.0 / Kelvin_Inv) - 272.15;
  l = (long)(res * 1000);
  return (l < -272150) ? -272150 : l;
}


x86 assembly (clang, -O0):
<uint16_to_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movsd  0xf01(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeec(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xed7(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xec2(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xead(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
cvtsi2sdq -0x8(%rbp),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
mov    $0x3,%edi
call   1040 <pow@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe01(%rip),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  0xdec(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdd3(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0xfffffffffffbd8ea,-0x10(%rbp)
ff
jge    1259 <uint16_to_temp+0x139>
mov    $0xfffffffffffbd8ea,%rax
mov    %rax,-0x78(%rbp)
jmp    1261 <uint16_to_temp+0x141>
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uint16_to_temp>:
sub    $0x18,%rsp
cvtsi2sd %rdi,%xmm1
movsd  0xecf(%rip),%xmm0
subsd  %xmm1,%xmm0
mulsd  0xecb(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
mulsd  0xebc(%rip),%xmm0
addsd  0xebc(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <log@plt>
mov    $0x3,%edi
call   1040 <pow@plt>
mulsd  0xea1(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe97(%rip),%xmm1
mulsd  0xe97(%rip),%xmm1
cvttsd2si %xmm1,%rcx
cmp    $0xfffffffffffbd8eb,%rcx
mov    $0xfffffffffffbd8ea,%rax
cmovge %rcx,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i64 @uint16_to_temp(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i64 %0, i64* %2
store double 1.000000e+04, double* %4
store double 1.023000e+03, double* %5
store double 0x3F508C5900000000, double* %8
store double 0x3F2FBC6F20000000, double* %9
store double 0x3E839885A0000000, double* %10
%12 = load double, double* %4
%13 = load double, double* %5
%14 = load i64, i64* %2
%15 = sitofp i64 %14 to double
%16 = fsub double %13, %15
%17 = fmul double %12, %16
%18 = load i64, i64* %2
%19 = sitofp i64 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %6
%21 = load double, double* %8
%22 = load double, double* %9
%23 = load double, double* %6
%24 = call double @log(double %23)
%25 = call double @llvm.fmuladd.f64(double %22, double %24, double %21)
%26 = load double, double* %10
%27 = load double, double* %6
%28 = call double @log(double %27)
%29 = call double @pow(double %28, i32 3)
%30 = call double @llvm.fmuladd.f64(double %26, double %29, double %25)
store double %30, double* %7
%31 = load double, double* %7
%32 = fdiv double 1.000000e+00, %31
%33 = fsub double %32, 2.721500e+02
store double %33, double* %11
%34 = load double, double* %11
%35 = fmul double %34, 1.000000e+03
%36 = fptosi double %35 to i64
store i64 %36, i64* %3
%37 = load i64, i64* %3
%38 = icmp slt i64 %37, -272150
br i1 %38, label %39, label %40
39: ; preds = %1
br label %42
40: ; preds = %1
%41 = load i64, i64* %3
br label %42
42: ; preds = %40, %39
%43 = phi i64 [ -272150, %39 ], [ %41, %40 ]
ret i64 %43
}

LLVM IR (-O2):
define i64 @uint16_to_temp(i64 %0) {
%2 = sitofp i64 %0 to double
%3 = fsub double 1.023000e+03, %2
%4 = fmul double %3, 1.000000e+04
%5 = fdiv double %4, %2
%6 = tail call double @log(double %5)
%7 = tail call double @llvm.fmuladd.f64(double %6, double 0x3F2FBC6F20000000, double 0x3F508C5900000000)
%8 = tail call double @log(double %5)
%9 = tail call double @pow(double %8, i32 3)
%10 = tail call double @llvm.fmuladd.f64(double %9, double 0x3E839885A0000000, double %7)
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %11, -2.721500e+02
%13 = fmul double %12, 1.000000e+03
%14 = fptosi double %13 to i64
%15 = icmp sgt i64 %14, -272150
%16 = select i1 %15, i64 %14, i64 -272150
ret i64 %16
}