#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);
scalar_t__ write(int, char *, int);
int gpio_unexport(unsigned int gpio) {
  int fd, len;
  char str_gpio[5];
  if ((fd = open("/sys/class/gpio/unexport", O_WRONLY)) < 0)
    return -1;
  len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio);
  ;
  if (write(fd, str_gpio, len) < 0)
    return -1;
  close(fd);
  return 0;
}


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    11c7 <gpio_unexport+0x87>
lea    -0x15(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x5,%esi
lea    0xe8e(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b8 <gpio_unexport+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <gpio_unexport+0x87>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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