#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
float get_rpi_cpu_temp(void) {
  FILE *fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
  int iTemp = 0;
  int ret = 0;
  if (NULL != fp) {
    ret = fscanf(fp, "%d", &iTemp);
    fclose(fp);
    fp = NULL;
    if (ret < 0) {
      return 0.0;
    }
    return ((float)iTemp) / 1000.0;
  } else {
    return 0.0;
  }
}


x86 assembly (clang, -O0):
<get_rpi_cpu_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec9(%rip),%rdi
lea    0xee8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11cb <get_rpi_cpu_temp+0x9b>
mov    -0x10(%rbp),%rdi
lea    0xebc(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11a8 <get_rpi_cpu_temp+0x78>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d3 <get_rpi_cpu_temp+0xa3>
cvtsi2ssl -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe47(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d3 <get_rpi_cpu_temp+0xa3>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rpi_cpu_temp>:
push   %rbp
push   %rbx
push   %rax
lea    0xeca(%rip),%rdi
lea    0xee9(%rip),%rsi
call   1050 <fopen@plt>
movl   $0x0,0x4(%rsp)
xorps  %xmm0,%xmm0
test   %rax,%rax
je     118f <get_rpi_cpu_temp+0x5f>
mov    %rax,%rbx
lea    0xecc(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
xorps  %xmm0,%xmm0
test   %ebp,%ebp
js     118f <get_rpi_cpu_temp+0x5f>
xorps  %xmm0,%xmm0
cvtsi2ssl 0x4(%rsp),%xmm0
divss  0xe71(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/sys/class/thermal/thermal_zone0/temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define float @get_rpi_cpu_temp() {
%1 = alloca float
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = load i32*, i32** %2
%7 = icmp ne i32* null, %6
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i32 %10, i32* %4
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
store i32* null, i32** %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
store float 0.000000e+00, float* %1
br label %23
16: ; preds = %8
%17 = load i32, i32* %3
%18 = sitofp i32 %17 to float
%19 = fpext float %18 to double
%20 = fdiv double %19, 1.000000e+03
%21 = fptrunc double %20 to float
store float %21, float* %1
br label %23
22: ; preds = %0
store float 0.000000e+00, float* %1
br label %23
23: ; preds = %22, %16, %15
%24 = load float, float* %1
ret float %24
}

LLVM IR (-O2):
@.str = [38 x i8] c"/sys/class/thermal/thermal_zone0/temp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define float @get_rpi_cpu_temp() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = icmp eq i32* %2, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = call i32 @fclose(i32* %2)
%8 = icmp slt i32 %6, 0
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = load i32, i32* %1
%11 = sitofp i32 %10 to float
%12 = fdiv float %11, 1.000000e+03
br label %13
13: ; preds = %0, %5, %9
%14 = phi float [ %12, %9 ], [ 0.000000e+00, %5 ], [ 0.000000e+00, %0 ]
ret float %14
}