#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*/ snprintf(char *, int, char *, unsigned int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int gpio_unexport(unsigned int gpio_number) {
  char buf[3 + 1];
  snprintf(buf, 3 + 1, "%u", gpio_number);
  int fd = open("/sys/class/gpio/unexport", O_WRONLY);
  if (fd == -1)
    return -1;
  if (write(fd, buf, strlen(buf)) == -1)
    return -1;
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_unexport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x4,%esi
lea    0xe92(%rip),%rdx
call   1050 <snprintf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11a1 <gpio_unexport+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <gpio_unexport+0x9a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11db <gpio_unexport+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <gpio_unexport+0x9a>
mov    -0x10(%rbp),%edi
call   1060 <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
mov    %edi,%ecx
lea    0xe9f(%rip),%rdx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1050 <snprintf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1070 <open@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11b8 <gpio_unexport+0x68>
mov    %eax,%ebp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11b8 <gpio_unexport+0x68>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [25 x i8] c"/sys/class/gpio/unexport\00"
@O_WRONLY = 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 = call i32 @snprintf(i8* %3, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = call i32 @strlen(i8* %3)
%10 = call i32 @write(i32 %6, i8* %3, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @close(i32 %6)
br label %14
14: ; preds = %8, %1, %12
%15 = phi i32 [ 0, %12 ], [ -1, %1 ], [ -1, %8 ]
ret i32 %15
}