#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(char *);
char *get_file_contents(char *);
float rpi_soc_temp() {
  char *tmp = NULL;
  float temp = 0.0f;
  tmp = get_file_contents("/sys/class/thermal/thermal_zone0/temp");
  if (tmp != NULL)
    temp = (float)atoi(tmp);
  if (temp)
    temp /= 1000.0f;
  free(tmp);
  return temp;
}


x86 assembly (clang, -O0):
<rpi_soc_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xeb5(%rip),%rdi
call   1040 <get_file_contents@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1176 <rpi_soc_temp+0x46>
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1192 <rpi_soc_temp+0x62>
jp     1192 <rpi_soc_temp+0x62>
jmp    11a8 <rpi_soc_temp+0x78>
movss  -0xc(%rbp),%xmm0
movss  0xe61(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpi_soc_temp>:
push   %rbx
sub    $0x10,%rsp
lea    0xec8(%rip),%rdi
call   1040 <get_file_contents@plt>
mov    %rax,%rbx
xorps  %xmm1,%xmm1
xorps  %xmm0,%xmm0
test   %rax,%rax
je     1162 <rpi_soc_temp+0x32>
mov    %rbx,%rdi
call   1050 <atoi@plt>
xorps  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss %xmm1,%xmm0
jne    1169 <rpi_soc_temp+0x39>
jnp    1171 <rpi_soc_temp+0x41>
divss  0xe8f(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movss  0xc(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/sys/class/thermal/thermal_zone0/temp\00"
define float @rpi_soc_temp() {
%1 = alloca i8*
%2 = alloca float
store i8* null, i8** %1
store float 0.000000e+00, float* %2
%3 = call i8* @get_file_contents(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i8*, i8** %1
%8 = call i64 @atoi(i8* %7)
%9 = sitofp i64 %8 to float
store float %9, float* %2
br label %10
10: ; preds = %6, %0
%11 = load float, float* %2
%12 = fcmp une float %11, 0.000000e+00
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load float, float* %2
%15 = fdiv float %14, 1.000000e+03
store float %15, float* %2
br label %16
16: ; preds = %13, %10
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
%19 = load float, float* %2
ret float %19
}

LLVM IR (-O2):
@.str = [38 x i8] c"/sys/class/thermal/thermal_zone0/temp\00"
define float @rpi_soc_temp() {
%1 = tail call i8* @get_file_contents(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i64 @atoi(i8* %1)
%5 = sitofp i64 %4 to float
br label %6
6: ; preds = %3, %0
%7 = phi float [ %5, %3 ], [ 0.000000e+00, %0 ]
%8 = fcmp une float %7, 0.000000e+00
%9 = fdiv float %7, 1.000000e+03
%10 = select i1 %8, float %9, float %7
%11 = tail call i32 @free(i8* %1)
ret float %10
}