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

/* Variables and functions */
int EINVAL;
int ENODEV;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int gpio_close(int gpio) {
  FILE *fd;
  if (gpio < 0)
    return -EINVAL;
  fd = fopen("/sys/class/gpio/unexport", "w");
  if (fd < 0)
    return -ENODEV;
  fprintf(fd, "%d", gpio);
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1158 <gpio_close+0x28>
xor    %eax,%eax
mov    0x2e92(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <gpio_close+0x80>
lea    0xea1(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jae    118d <gpio_close+0x5d>
xor    %eax,%eax
mov    0x2e55(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <gpio_close+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_close>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     116d <gpio_close+0x3d>
mov    %edi,%ebx
lea    0xebf(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
lea    0xec4(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1178 <gpio_close+0x48>
mov    0x2e6c(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@.str.1 = [2 x i8] c"w\00"
@ENODEV = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @gpio_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
store i32 %9, i32* %2
br label %23
10: ; preds = %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ult i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @ENODEV
%16 = sub nsw i32 0, %15
store i32 %16, i32* %2
br label %23
17: ; preds = %10
%18 = load i32*, i32** %4
%19 = load i32, i32* %3
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %2
br label %23
23: ; preds = %17, %14, %7
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str = [25 x i8] c"/sys/class/gpio/unexport\00"
@.str.1 = [2 x i8] c"w\00"
@ENODEV = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @gpio_close(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @EINVAL
%5 = sub nsw i32 0, %4
br label %10
6: ; preds = %1
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%9 = tail call i32 @fclose(i32* %7)
br label %10
10: ; preds = %6, %3
%11 = phi i32 [ %5, %3 ], [ 0, %6 ]
ret i32 %11
}