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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int write(int, char *, int);
int gpio_export_unexport(char *path, int gpio) {
  int fd;
  char str[16];
  int bytes;
  fd = open(path, O_WRONLY);
  if (fd == -1) {
    perror("Unable to find GPIO files -- /sys/class/gpio enabled?");
    return -errno;
  }
  bytes = snprintf(str, sizeof(str) - 1, "%d", gpio) + 1;
  if (-1 == write(fd, str, bytes)) {
    fprintf(stderr, "Unable to modify gpio%d: %s", gpio, strerror(errno));
    close(fd);
    return -errno;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_export_unexport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11bd <gpio_export_unexport+0x4d>
lea    0xe5b(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
mov    0x2e25(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <gpio_export_unexport+0xe8>
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0xf,%esi
lea    0xe66(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1249 <gpio_export_unexport+0xd9>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    0x2d99(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <gpio_export_unexport+0xe8>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_export_unexport>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     120c <gpio_export_unexport+0x9c>
mov    %eax,%ebp
lea    0xe9d(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xf,%esi
mov    %r14d,%ecx
call   1040 <snprintf@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11c9 <gpio_export_unexport+0x59>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1201 <gpio_export_unexport+0x91>
mov    0x2e10(%rip),%rax
mov    (%rax),%ebx
mov    0x2dff(%rip),%r15
mov    (%r15),%edi
call   1090 <strerror@plt>
lea    0xe51(%rip),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
sub    (%r15),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xded(%rip),%rdi
call   1080 <perror@plt>
mov    0x2db9(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1201 <gpio_export_unexport+0x91>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [54 x i8] c"Unable to find GPIO files -- /sys/class/gpio enabled?\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Unable to modify gpio%d: %s\00"
define i32 @gpio_export_unexport(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [16 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
store i32 %17, i32* %3
br label %41
18: ; preds = %2
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %5
%21 = call i32 @snprintf(i8* %19, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = load i32, i32* %6
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %8
%26 = call i32 @write(i32 %23, i8* %24, i32 %25)
%27 = icmp eq i32 -1, %26
br i1 %27, label %28, label %38
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = load i32, i32* %5
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %32)
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @errno
%37 = sub nsw i32 0, %36
store i32 %37, i32* %3
br label %41
38: ; preds = %18
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %28, %14
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [54 x i8] c"Unable to find GPIO files -- /sys/class/gpio enabled?\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Unable to modify gpio%d: %s\00"
define i32 @gpio_export_unexport(i8* nocapture %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
br label %27
12: ; preds = %2
%13 = call i32 @snprintf(i8* %4, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%14 = add nsw i32 %13, 1
%15 = call i32 @write(i32 %6, i8* %4, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %1, i8* %20)
%22 = call i32 @close(i32 %6)
%23 = load i32, i32* @errno
%24 = sub nsw i32 0, %23
br label %27
25: ; preds = %12
%26 = call i32 @close(i32 %6)
br label %27
27: ; preds = %25, %17, %8
%28 = phi i32 [ %11, %8 ], [ %24, %17 ], [ 0, %25 ]
ret i32 %28
}