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

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int adc_enabled() {
  int fd;
  char filepath[64];
  snprintf(filepath, sizeof(filepath), "%s/name",
           "/sys/bus/iio/devices/iio:device0");
  if ((fd = open(filepath, O_RDONLY | O_NONBLOCK)) < 0)
    return 0;
  close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<adc_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
lea    0xeb8(%rip),%rdx
lea    0xeb9(%rip),%rcx
call   1030 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1187 <adc_enabled+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1196 <adc_enabled+0x66>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adc_enabled>:
push   %rbx
sub    $0x40,%rsp
lea    0xec4(%rip),%rdx
lea    0xec5(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
mov    0x2e86(%rip),%rax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     117f <adc_enabled+0x4f>
mov    %eax,%edi
call   1040 <close@plt>
mov    $0x1,%eax
jmp    1181 <adc_enabled+0x51>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s/name\00"
@.str.1 = [33 x i8] c"/sys/bus/iio/devices/iio:device0\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @adc_enabled() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 0, i32* %1
br label %16
13: ; preds = %0
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
store i32 1, i32* %1
br label %16
16: ; preds = %13, %12
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s/name\00"
@.str.1 = [33 x i8] c"/sys/bus/iio/devices/iio:device0\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @adc_enabled() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @O_RDONLY
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = call i32 @open(i8* %2, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @close(i32 %7)
br label %11
11: ; preds = %0, %9
%12 = phi i32 [ 1, %9 ], [ 0, %0 ]
ret i32 %12
}