#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
float pi_get_cpu_temperature() {
  FILE *cpuTempFile;
  char tempBuff[6];
  cpuTempFile = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
  fscanf(cpuTempFile, "%s", tempBuff);
  fclose(cpuTempFile);
  int cpuTempInt = atoi(tempBuff);
  float cpuTempFloat = cpuTempInt / 1000.0;
  return cpuTempFloat;
}


x86 assembly (clang, -O0):
<pi_get_cpu_temperature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb9(%rip),%rdi
lea    0xed8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xe(%rbp),%rdx
lea    0xec2(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xe(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe6b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_get_cpu_temperature>:
push   %r14
push   %rbx
push   %rax
lea    0xebd(%rip),%rdi
lea    0xedc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xecf(%rip),%rsi
lea    0x2(%rsp),%r14
mov    %rax,%rdi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1060 <atoi@plt>
cvtsi2sd %eax,%xmm0
divsd  0xe73(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
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"%s\00"
define float @pi_get_cpu_temperature() {
%1 = alloca i32*
%2 = alloca [6 x i8]
%3 = alloca i32
%4 = alloca float
%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** %1
%6 = load i32*, i32** %1
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%8 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = load i32*, i32** %1
%10 = call i32 @fclose(i32* %9)
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 1.000000e+03
%16 = fptrunc double %15 to float
store float %16, float* %4
%17 = load float, float* %4
ret float %17
}

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"%s\00"
define float @pi_get_cpu_temperature() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%5 = call i32 @fclose(i32* %3)
%6 = call i32 @atoi(i8* %2)
%7 = sitofp i32 %6 to double
%8 = fdiv double %7, 1.000000e+03
%9 = fptrunc double %8 to float
ret float %9
}