#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*/ cdata;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
scalar_t__ close(int);
int errno;
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
scalar_t__ read(int, char *, int);
int is_sensor_enabled(const char *file) {
  int fd;
  char cdata[24];
  int err_save = 0;
  if ((fd = open(file, O_RDONLY)) > 0) {
    if (read(fd, cdata, sizeof(cdata)) < 0) {
      err_save = errno;
    }
    if (close(fd)) {
      perror(file);
    }
    errno = err_save;
  }
  return errno ? 0 : atoi(cdata);
}


x86 assembly (clang, -O0):
<is_sensor_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    11cf <is_sensor_enabled+0x7f>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jge    11a8 <is_sensor_enabled+0x58>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     11c3 <is_sensor_enabled+0x73>
mov    -0x8(%rbp),%rdi
call   1060 <perror@plt>
mov    -0x34(%rbp),%ecx
mov    0x2e0b(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e02(%rip),%rax
cmpl   $0x0,(%rax)
je     11e9 <is_sensor_enabled+0x99>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    11f5 <is_sensor_enabled+0xa5>
lea    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_sensor_enabled>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
jle    11a2 <is_sensor_enabled+0x52>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1040 <read@plt>
mov    %rax,%rbx
mov    0x2e4e(%rip),%r15
sar    $0x3f,%rbx
and    (%r15),%ebx
mov    %ebp,%edi
call   1030 <close@plt>
test   %rax,%rax
jne    11c4 <is_sensor_enabled+0x74>
mov    %ebx,(%r15)
jmp    11ab <is_sensor_enabled+0x5b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
test   %ebx,%ebx
jne    11b9 <is_sensor_enabled+0x69>
mov    %rsp,%rdi
call   1070 <atoi@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1060 <perror@plt>
jmp    119d <is_sensor_enabled+0x4d>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @is_sensor_enabled(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [24 x i8]
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %1
%11 = load i32, i32* %3
%12 = getelementptr inbounds [24 x i8], [24 x i8]* %4, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 24)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* @errno
store i32 %16, i32* %5
br label %17
17: ; preds = %15, %10
%18 = load i32, i32* %3
%19 = call i64 @close(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i32 @perror(i8* %22)
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* %5
store i32 %25, i32* @errno
br label %26
26: ; preds = %24, %1
%27 = load i32, i32* @errno
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %33
30: ; preds = %26
%31 = getelementptr inbounds [24 x i8], [24 x i8]* %4, i64 0, i64 0
%32 = call i32 @atoi(i8* %31)
br label %33
33: ; preds = %30, %29
%34 = phi i32 [ 0, %29 ], [ %32, %30 ]
ret i32 %34
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @is_sensor_enabled(i8* nocapture %0) {
%2 = alloca [24 x i8]
%3 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = call i64 @read(i32 %5, i8* %3, i32 24)
%9 = icmp slt i64 %8, 0
%10 = load i32, i32* @errno
%11 = select i1 %9, i32 %10, i32 0
%12 = tail call i64 @close(i32 %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %7
%15 = tail call i32 @perror(i8* %0)
br label %16
16: ; preds = %14, %7
store i32 %11, i32* @errno
br label %19
17: ; preds = %1
%18 = load i32, i32* @errno
br label %19
19: ; preds = %17, %16
%20 = phi i32 [ %18, %17 ], [ %11, %16 ]
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @atoi(i8* %3)
br label %24
24: ; preds = %19, %22
%25 = phi i32 [ %23, %22 ], [ 0, %19 ]
ret i32 %25
}