#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 dprintf(int, char *, unsigned int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int gpio_unexport(unsigned int gpio) {
  int ret;
  int f = open("/sys/class/gpio/unexport", O_WRONLY);
  if (f < 0) {
    perror("open");
    return f;
  }
  ret = dprintf(f, "%u", gpio);
  close(f);
  return ret < 0 ? ret : 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   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1184 <gpio_unexport+0x44>
lea    0xea5(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <gpio_unexport+0x86>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%edx
lea    0xe8d(%rip),%rsi
call   1040 <dprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11b6 <gpio_unexport+0x76>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <gpio_unexport+0x80>
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
jmp    11c0 <gpio_unexport+0x80>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_unexport>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1189 <gpio_unexport+0x49>
lea    0xeb7(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1040 <dprintf@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%ebx
sar    $0x1f,%ebx
and    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
jmp    1180 <gpio_unexport+0x40>

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

LLVM IR (-O2):
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"%u\00"
define i32 @gpio_unexport(i32 %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %12
7: ; preds = %1
%8 = tail call i32 @dprintf(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%9 = tail call i32 @close(i32 %3)
%10 = icmp slt i32 %8, 0
%11 = select i1 %10, i32 %8, i32 0
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ %3, %5 ], [ %11, %7 ]
ret i32 %13
}