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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int GPIO_unexport(int pin) {
  char name_buffer[4];
  ssize_t bytes_written;
  int fd;
  int ret_err;
  fd = open("/sys/class/gpio/unexport", O_WRONLY);
  if (-1 != fd) {
    bytes_written = snprintf(name_buffer, 4, "%d", pin);
    write(fd, name_buffer, bytes_written);
    close(fd);
    ret_err = 0;
  } else
    ret_err = errno;
  return (ret_err);
}


x86 assembly (clang, -O0):
<GPIO_unexport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
mov    $0xffffffff,%eax
cmp    -0x10(%rbp),%eax
je     11af <GPIO_unexport+0x6f>
lea    -0x8(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x4,%esi
lea    0xe95(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x14(%rbp)
jmp    11bb <GPIO_unexport+0x7b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%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    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1198 <GPIO_unexport+0x58>
mov    %eax,%ebx
lea    0xeac(%rip),%rdx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%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    11a1 <GPIO_unexport+0x61>
mov    0x2e41(%rip),%rax
mov    (%rax),%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"
@errno = global i32 0
define i32 @GPIO_unexport(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%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* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 -1, %9
br i1 %10, label %11, label %21
11: ; preds = %1
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %2
%14 = call i32 @snprintf(i8* %12, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %5
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @close(i32 %19)
store i32 0, i32* %6
br label %23
21: ; preds = %1
%22 = load i32, i32* @errno
store i32 %22, i32* %6
br label %23
23: ; preds = %21, %11
%24 = load i32, i32* %6
ret i32 %24
}

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"
@errno = global i32 0
define i32 @GPIO_unexport(i32 %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 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 %11, label %7
7: ; preds = %1
%8 = call i32 @snprintf(i8* %3, i32 4, 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 %13
11: ; preds = %1
%12 = load i32, i32* @errno
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ 0, %7 ], [ %12, %11 ]
ret i32 %14
}