#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 uint16_t;
typedef int /*<<< orphan*/ sys_class_gpio_gpioN;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
bool gpio_is_exported(uint16_t gpio) {
  bool r;
  char sys_class_gpio_gpioN[32];
  int access_r;
  memset(sys_class_gpio_gpioN, 0, sizeof(sys_class_gpio_gpioN));
  snprintf(sys_class_gpio_gpioN, sizeof(sys_class_gpio_gpioN) - 1,
           "/sys/class/gpio/gpio%u", gpio);
  access_r = access(sys_class_gpio_gpioN, F_OK);
  r = EXIT_SUCCESS == access_r;
  return r;
}


x86 assembly (clang, -O0):
<gpio_is_exported>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x1f,%esi
lea    0xea2(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    %eax,-0x34(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
cmp    -0x34(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_is_exported>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xeae(%rip),%rdx
mov    %r14,%rdi
mov    $0x1f,%esi
mov    %ebx,%ecx
call   1030 <snprintf@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
mov    0x2e67(%rip),%rdx
xor    %ecx,%ecx
cmp    %eax,(%rdx)
sete   %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/class/gpio/gpio%u\00"
@F_OK = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @gpio_is_exported(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 32)
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @snprintf(i8* %8, i32 31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* @F_OK
%13 = call i32 @access(i8* %11, i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* @EXIT_SUCCESS
%15 = load i32, i32* %5
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
store i32 %17, i32* %3
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/class/gpio/gpio%u\00"
@F_OK = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @gpio_is_exported(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 32)
%5 = call i32 @snprintf(i8* %3, i32 31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @F_OK
%7 = call i32 @access(i8* %3, i32 %6)
%8 = load i32, i32* @EXIT_SUCCESS
%9 = icmp eq i32 %8, %7
%10 = zext i1 %9 to i32
ret i32 %10
}