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

/* Variables and functions */
int BUFSIZ;
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[BUFSIZ];
  int fd;
  char cdata[BUFSIZ];
  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(val));
  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    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe4f(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x48(%rbp),%rdi
call   1070 <odroid_open_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11df <odroid_check_sensor_enabled+0x8f>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    123e <odroid_check_sensor_enabled+0xee>
mov    -0x50(%rbp),%rsi
mov    -0x24(%rbp),%edi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x38(%rbp)
jge    1218 <odroid_check_sensor_enabled+0xc8>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    123e <odroid_check_sensor_enabled+0xee>
mov    -0x50(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<odroid_check_sensor_enabled>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rdx
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <odroid_open_file@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     11d3 <odroid_check_sensor_enabled+0x83>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1030 <close@plt>
test   %r12d,%r12d
js     11d3 <odroid_check_sensor_enabled+0x83>
mov    %r15,%rdi
call   1050 <atoi@plt>
xor    %r14d,%r14d
test   %eax,%eax
sete   %r14b
mov    %r14d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.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 i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = load i32, i32* @BUFSIZ
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
store i64 %16, i64* %7
%18 = load i8*, i8** %3
%19 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @odroid_open_file(i8* %14)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %10
br label %38
24: ; preds = %1
%25 = load i32, i32* %6
%26 = call i32 @read(i32 %25, i8* %17, i32 4)
store i32 %26, i32* %9
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 -1, i32* %2
store i32 1, i32* %10
br label %38
32: ; preds = %24
%33 = call i32 @atoi(i8* %17)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 1, i32 0
store i32 %37, i32* %2
store i32 1, i32* %10
br label %38
38: ; preds = %32, %31, %23
%39 = load i8*, i8** %4
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [38 x i8] c"/sys/bus/i2c/drivers/INA231/%s/enable\00"
define i32 @odroid_check_sensor_enabled(i8* %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = alloca i8, i64 %3
%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 4)
%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
}