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


x86 assembly (clang, -O0):
<gpio_unexport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <gpioToSysPin@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1193 <gpio_unexport+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <gpio_unexport+0x7c>
lea    -0x17(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x3,%esi
lea    0xe73(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    -0x10(%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   %r14
push   %rbx
sub    $0x10,%rsp
call   1060 <gpioToSysPin@plt>
mov    %eax,%ebp
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11ac <gpio_unexport+0x5c>
mov    %eax,%ebx
lea    0xe98(%rip),%rdx
lea    0xd(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%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>
xor    %eax,%eax
jmp    11b1 <gpio_unexport+0x61>
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 i32
%7 = alloca [3 x i8]
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = call i32 @gpioToSysPin(i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %24
14: ; preds = %1
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @snprintf(i8* %15, i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %5
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%20 = load i32, i32* %6
%21 = call i32 @write(i32 %18, i8* %19, i32 %20)
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
store i32 0, i32* %2
br label %24
24: ; preds = %14, %13
%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 [3 x i8]
%3 = tail call i32 @gpioToSysPin(i32 %0)
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i32 @snprintf(i8* %4, i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%10 = call i32 @write(i32 %6, i8* %4, i32 %9)
%11 = call i32 @close(i32 %6)
br label %12
12: ; preds = %1, %8
%13 = phi i32 [ 0, %8 ], [ -1, %1 ]
ret i32 %13
}