#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*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int unsetGpio(unsigned int index) {
  int fd;
  char buf[50];
  if ((fd = open("/sys/class/gpio/unexport", O_WRONLY)) == -1)
    return -1;
  sprintf(buf, "%d", index);
  if (write(fd, buf, strlen(buf)))
    return -1;
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<unsetGpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1188 <unsetGpio+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <unsetGpio+0x95>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe83(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
je     11d6 <unsetGpio+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <unsetGpio+0x95>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsetGpio>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edi,%r14d
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1060 <open@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11b5 <unsetGpio+0x65>
mov    %eax,%ebp
lea    0xe94(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14d,%edx
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jne    11b5 <unsetGpio+0x65>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @unsetGpio(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [50 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %24
10: ; preds = %1
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* %3
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i64 @write(i32 %14, i8* %15, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %10
store i32 -1, i32* %2
br label %24
21: ; preds = %10
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
store i32 0, i32* %2
br label %24
24: ; preds = %21, %20, %9
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @unsetGpio(i32 %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%9 = call i32 @strlen(i8* %3)
%10 = call i64 @write(i32 %5, i8* %3, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @close(i32 %5)
br label %14
14: ; preds = %7, %1, %12
%15 = phi i32 [ 0, %12 ], [ -1, %1 ], [ -1, %7 ]
ret i32 %15
}