#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 /*<<< orphan*/ O_RDONLY;
scalar_t__ close(int);
int /*<<< orphan*/ log_message(char *, char *, char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
float tempsensor_current_temp(int sensor) {
  int fd;
  char buf[80];
  int raw;
  float temp;
  fd = open("/sys/devices/w1_bus_master1/28-000003ea41b5/w1_slave", O_RDONLY);
  if (fd < 0) {
    return -1;
  }
  if (read(fd, buf, 75) < 0) {
    return -1;
  }
  buf[79] = '\0';
  log_message("[DEBUG][%d-%d-%d %d:%d:%d] ",
              "Read '%s' from temperature sensor\r\n", buf);
  if (close(fd) < 0) {
    return -1;
  }
  sscanf(buf + 69, "%d", &raw);
  temp = (float)raw / 1000.0;
  return temp;
}


x86 assembly (clang, -O0):
<tempsensor_current_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118f <tempsensor_current_temp+0x3f>
movss  0xe83(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    123b <tempsensor_current_temp+0xeb>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x4b,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jge    11bc <tempsensor_current_temp+0x6c>
movss  0xe56(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    123b <tempsensor_current_temp+0xeb>
movb   $0x0,-0x11(%rbp)
lea    -0x60(%rbp),%rdx
lea    0xe76(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <log_message@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
jge    11fb <tempsensor_current_temp+0xab>
movss  0xe17(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    123b <tempsensor_current_temp+0xeb>
lea    -0x60(%rbp),%rdi
add    $0x45,%rdi
lea    0xe77(%rip),%rsi
lea    -0x64(%rbp),%rdx
call   1050 <sscanf@plt>
cvtsi2ssl -0x64(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xddc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x68(%rbp)
movss  -0x68(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tempsensor_current_temp>:
push   %rbx
sub    $0x60,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1070 <open@plt>
movss  0xe8e(%rip),%xmm0
test   %eax,%eax
js     11f0 <tempsensor_current_temp+0xa0>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x4b,%edx
call   1040 <read@plt>
test   %rax,%rax
js     11e8 <tempsensor_current_temp+0x98>
movb   $0x0,0x5f(%rsp)
lea    0xea3(%rip),%rdi
lea    0xeb8(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1060 <log_message@plt>
mov    %ebx,%edi
call   1030 <close@plt>
test   %rax,%rax
movss  0xe43(%rip),%xmm0
js     11f0 <tempsensor_current_temp+0xa0>
lea    0x55(%rsp),%rdi
lea    0xeb2(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0xc(%rsp),%xmm0
divss  0xe1e(%rip),%xmm0
jmp    11f0 <tempsensor_current_temp+0xa0>
movss  0xe10(%rip),%xmm0
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [53 x i8] c"/sys/devices/w1_bus_master1/28-000003ea41b5/w1_slave\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"[DEBUG][%d-%d-%d %d:%d:%d] \00"
@.str.2 = [36 x i8] c"Read '%s' from temperature sensor\0D\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define float @tempsensor_current_temp(i32 %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca float
store i32 %0, i32* %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store float -1.000000e+00, float* %2
br label %37
13: ; preds = %1
%14 = load i32, i32* %4
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%16 = call i64 @read(i32 %14, i8* %15, i32 75)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store float -1.000000e+00, float* %2
br label %37
19: ; preds = %13
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 79
store i8 0, i8* %20
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%22 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %4
%24 = call i64 @close(i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store float -1.000000e+00, float* %2
br label %37
27: ; preds = %19
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 69
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%31 = load i32, i32* %6
%32 = sitofp i32 %31 to float
%33 = fpext float %32 to double
%34 = fdiv double %33, 1.000000e+03
%35 = fptrunc double %34 to float
store float %35, float* %7
%36 = load float, float* %7
store float %36, float* %2
br label %37
37: ; preds = %27, %26, %18, %12
%38 = load float, float* %2
ret float %38
}

LLVM IR (-O2):
@.str = [53 x i8] c"/sys/devices/w1_bus_master1/28-000003ea41b5/w1_slave\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"[DEBUG][%d-%d-%d %d:%d:%d] \00"
@.str.2 = [36 x i8] c"Read '%s' from temperature sensor\0D\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define float @tempsensor_current_temp(i32 %0) {
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = call i64 @read(i32 %7, i8* %4, i32 75)
%11 = icmp slt i64 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 79
store i8 0, i8* %13
%14 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = call i64 @close(i32 %7)
%16 = icmp slt i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 69
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%20 = load i32, i32* %3
%21 = sitofp i32 %20 to float
%22 = fdiv float %21, 1.000000e+03
br label %23
23: ; preds = %12, %9, %1, %17
%24 = phi float [ %22, %17 ], [ -1.000000e+00, %1 ], [ -1.000000e+00, %9 ], [ -1.000000e+00, %12 ]
ret float %24
}