#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_gpio;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, unsigned int);
int /*<<< orphan*/ write(int, char *, int);
int gpio_unexport(unsigned int gpio) {
  int fd, len;
  char str_gpio[10];
  if ((fd = open("/sys/class/gpio/unexport", O_WRONLY)) < 0)
    return -1;
  len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio);
  write(fd, str_gpio, len);
  close(fd);
}


x86 assembly (clang, -O0):
<gpio_unexport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1178 <gpio_unexport+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <gpio_unexport+0x6a>
lea    -0x1a(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0xa,%esi
lea    0xe8e(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_unexport>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1193 <gpio_unexport+0x53>
mov    %eax,%ebx
lea    0xead(%rip),%rdx
lea    0x6(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
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 @gpio_unexport(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
store i32 %0, i32* %3
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %21
11: ; preds = %1
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @snprintf(i8* %12, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %11, %10
%22 = load i32, i32* %2
ret i32 %22
}

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 @gpio_unexport(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 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 slt i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = call i32 @snprintf(i8* %3, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%9 = call i32 @write(i32 %5, i8* %3, i32 %8)
%10 = call i32 @close(i32 %5)
br label %11
11: ; preds = %1, %7
ret i32 -1
}