#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_WRONLY;
int /*<<< orphan*/ adc_enabled();
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
int adc_enable() {
  if (!adc_enabled()) {
    int fd;
    if ((fd = open("/sys/devices/bone_capemgr.8/slots", O_WRONLY)) < 0)
      return -1;
    const char *cape_bone_iio = "cape-bone-iio";
    write(fd, cape_bone_iio, strlen(cape_bone_iio));
    close(fd);
    return 0;
  }
}


x86 assembly (clang, -O0):
<adc_enable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1070 <adc_enabled@plt>
cmp    $0x0,%eax
jne    11d4 <adc_enable+0x84>
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1195 <adc_enable+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <adc_enable+0x84>
lea    0xe86(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adc_enable>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <adc_enabled@plt>
mov    %eax,%ecx
test   %ecx,%ecx
jne    11a7 <adc_enable+0x57>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a2 <adc_enable+0x52>
mov    %eax,%ebx
lea    0xe9f(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11a7 <adc_enable+0x57>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [34 x i8] c"/sys/devices/bone_capemgr.8/slots\00"
@O_WRONLY = global i32 0
@.str.1 = [14 x i8] c"cape-bone-iio\00"
define i32 @adc_enable() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 (...) @adc_enabled()
%5 = icmp ne i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %0
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %6
store i32 -1, i32* %1
br label %19
11: ; preds = %6
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %3
%12 = load i32, i32* %2
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 %12, i8* %13, i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
store i32 0, i32* %1
br label %19
19: ; preds = %10, %11, %0
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [34 x i8] c"/sys/devices/bone_capemgr.8/slots\00"
@O_WRONLY = global i32 0
@.str.1 = [14 x i8] c"cape-bone-iio\00"
define i32 @adc_enable() {
%1 = tail call i32 (...) @adc_enabled()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 @close(i32 %5)
br label %11
11: ; preds = %7, %3, %0
%12 = phi i32 [ undef, %0 ], [ 0, %7 ], [ -1, %3 ]
ret i32 %12
}