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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ is_gpio_valid(int);
scalar_t__ open_write_close(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
void unexport_sysfs_gpio(int gpio) {
  char gpiostr[4];
  if (!is_gpio_valid(gpio))
    return;
  snprintf(gpiostr, sizeof(gpiostr), "%d", gpio);
  if (open_write_close("/sys/class/gpio/unexport", gpiostr) < 0)
    do {
      fprintf(stderr, "Couldn't unexport gpio %d", gpio);
      fputc('\n', stderr);
    } while (0);
  return;
}


x86 assembly (clang, -O0):
<unexport_sysfs_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <is_gpio_valid@plt>
cmp    $0x0,%eax
jne    1171 <unexport_sysfs_gpio+0x21>
jmp    11dd <unexport_sysfs_gpio+0x8d>
lea    -0x8(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x4,%esi
lea    0xeac(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x8(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1030 <open_write_close@plt>
cmp    $0x0,%rax
jge    11d8 <unexport_sysfs_gpio+0x88>
jmp    11a8 <unexport_sysfs_gpio+0x58>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
jmp    11d8 <unexport_sysfs_gpio+0x88>
jmp    11dd <unexport_sysfs_gpio+0x8d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unexport_sysfs_gpio>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1070 <is_gpio_valid@plt>
test   %eax,%eax
je     11b3 <unexport_sysfs_gpio+0x63>
lea    0xeca(%rip),%rdx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
call   1030 <open_write_close@plt>
test   %rax,%rax
jns    11b3 <unexport_sysfs_gpio+0x63>
mov    0x2e4b(%rip),%r14
mov    (%r14),%edi
lea    0xe7a(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    (%r14),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [25 x i8] c"/sys/class/gpio/unexport\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Couldn't unexport gpio %d\00"
define void @unexport_sysfs_gpio(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i8]
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @is_gpio_valid(i32 %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
br label %24
8: ; preds = %1
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* %2
%11 = call i32 @snprintf(i8* %9, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%13 = call i64 @open_write_close(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %8
br label %16
16: ; preds = %15
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stderr
%21 = call i32 @fputc(i8 signext 10, i32 %20)
br label %22
22: ; preds = %16
br label %23
23: ; preds = %22, %8
br label %24
24: ; preds = %23, %7
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [25 x i8] c"/sys/class/gpio/unexport\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Couldn't unexport gpio %d\00"
define void @unexport_sysfs_gpio(i32 %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @is_gpio_valid(i32 %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = call i32 @snprintf(i8* %3, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i64 @open_write_close(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%13 = load i32, i32* @stderr
%14 = call i32 @fputc(i8 signext 10, i32 %13)
br label %15
15: ; preds = %6, %10, %1
ret void
}