#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 atoi(char *);
int /*<<< orphan*/ close(int);
int odroid_open_file(char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int odroid_check_sensor_enabled(char *sensor) {
  char enable_filename[64];
  int fd;
  char cdata[24];
  int val;
  int read_ret;
  sprintf(enable_filename,
          "/sys/bus/i2c/drivers/INA231"
          "/%s/enable",
          sensor);
  fd = odroid_open_file(enable_filename);
  if (fd < 0) {
    return -1;
  }
  read_ret = read(fd, cdata, sizeof(cdata));
  close(fd);
  if (read_ret < 0) {
    return -1;
  }
  val = atoi(cdata);
  return val == 0 ? 1 : 0;
}


x86 assembly (clang, -O0):
<odroid_check_sensor_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe92(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1070 <odroid_open_file@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1195 <odroid_check_sensor_enabled+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <odroid_check_sensor_enabled+0x96>
mov    -0x54(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x18,%edx
call   1040 <read@plt>
mov    %eax,-0x78(%rbp)
mov    -0x54(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x78(%rbp)
jge    11c7 <odroid_check_sensor_enabled+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <odroid_check_sensor_enabled+0x96>
lea    -0x70(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<odroid_check_sensor_enabled>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%rdx
lea    0xe9e(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <odroid_open_file@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     11af <odroid_check_sensor_enabled+0x5f>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1040 <read@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <close@plt>
test   %r14d,%r14d
js     11af <odroid_check_sensor_enabled+0x5f>
mov    %rsp,%rdi
call   1050 <atoi@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/sys/bus/i2c/drivers/INA231/%s/enable\00"
define i32 @odroid_check_sensor_enabled(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca i32
%6 = alloca [24 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = call i32 @odroid_open_file(i8* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %33
17: ; preds = %1
%18 = load i32, i32* %5
%19 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 24)
store i32 %20, i32* %8
%21 = load i32, i32* %5
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 -1, i32* %2
br label %33
26: ; preds = %17
%27 = getelementptr inbounds [24 x i8], [24 x i8]* %6, i64 0, i64 0
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1, i32 0
store i32 %32, i32* %2
br label %33
33: ; preds = %26, %25, %16
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [38 x i8] c"/sys/bus/i2c/drivers/INA231/%s/enable\00"
define i32 @odroid_check_sensor_enabled(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [24 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @odroid_open_file(i8* %4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %1
%10 = call i32 @read(i32 %7, i8* %5, i32 24)
%11 = call i32 @close(i32 %7)
%12 = icmp slt i32 %10, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = call i32 @atoi(i8* %5)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %9, %1, %13
%18 = phi i32 [ %16, %13 ], [ -1, %1 ], [ -1, %9 ]
ret i32 %18
}