#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;
scalar_t__ close(int);
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ warnx(char *);
scalar_t__ write(int, char const *, int /*<<< orphan*/);
int unexport_gpio_pin(const char *gpio_pin) {
  int fd;
  char fn[48];
  if (gpio_pin == NULL || *gpio_pin == '\0') {
    return -1;
  }
  memset(fn, 0x00, 48);
  snprintf(fn, 48 - 1,
           "/tmp"
           "/gpio/unexport");
  if ((fd = open(fn, O_WRONLY)) < 0) {
    warnx("open(SYS_GPIO_UNEXPORT) failed");
    return -1;
  }
  if (write(fd, gpio_pin, strlen(gpio_pin)) < 0) {
    warnx("write(SYS_GPIO_UNEXPORT) failed");
    return -1;
  }
  if (close(fd) < 0) {
    warnx("close(SYS_GPIO_UNEXPORT) failed");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<unexport_gpio_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1197 <unexport_gpio_pin+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a3 <unexport_gpio_pin+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <unexport_gpio_pin+0x106>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1070 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    $0x2f,%esi
lea    0xe3d(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11fe <unexport_gpio_pin+0x8e>
lea    0xe26(%rip),%rdi
call   1050 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <unexport_gpio_pin+0x106>
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1245 <unexport_gpio_pin+0xd5>
lea    0xdfe(%rip),%rdi
call   1050 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <unexport_gpio_pin+0x106>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    126f <unexport_gpio_pin+0xff>
lea    0xdf4(%rip),%rdi
call   1050 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <unexport_gpio_pin+0x106>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unexport_gpio_pin>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     121a <unexport_gpio_pin+0xaa>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     121a <unexport_gpio_pin+0xaa>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1070 <memset@plt>
lea    0xe57(%rip),%rdx
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1060 <snprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1200 <unexport_gpio_pin+0x90>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1209 <unexport_gpio_pin+0x99>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    121a <unexport_gpio_pin+0xaa>
lea    0xe54(%rip),%rdi
jmp    1210 <unexport_gpio_pin+0xa0>
lea    0xe0c(%rip),%rdi
jmp    1210 <unexport_gpio_pin+0xa0>
lea    0xe22(%rip),%rdi
call   1050 <warnx@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/gpio/unexport\00"
@O_WRONLY = global i32 0
@.str.1 = [31 x i8] c"open(SYS_GPIO_UNEXPORT) failed\00"
@.str.2 = [32 x i8] c"write(SYS_GPIO_UNEXPORT) failed\00"
@.str.3 = [32 x i8] c"close(SYS_GPIO_UNEXPORT) failed\00"
define i32 @unexport_gpio_pin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [48 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8, %1
store i32 -1, i32* %2
br label %41
14: ; preds = %8
%15 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 48)
%17 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%18 = call i32 @snprintf(i8* %17, i32 47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [48 x i8], [48 x i8]* %5, i64 0, i64 0
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @warnx(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
25: ; preds = %14
%26 = load i32, i32* %4
%27 = load i8*, i8** %3
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
%30 = call i64 @write(i32 %26, i8* %27, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
34: ; preds = %25
%35 = load i32, i32* %4
%36 = call i64 @close(i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
40: ; preds = %34
store i32 0, i32* %2
br label %41
41: ; preds = %40, %38, %32, %23, %13
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/gpio/unexport\00"
@O_WRONLY = global i32 0
@.str.1 = [31 x i8] c"open(SYS_GPIO_UNEXPORT) failed\00"
@.str.2 = [32 x i8] c"write(SYS_GPIO_UNEXPORT) failed\00"
@.str.3 = [32 x i8] c"close(SYS_GPIO_UNEXPORT) failed\00"
define i32 @unexport_gpio_pin(i8* %0) {
%2 = alloca [48 x i8]
%3 = getelementptr inbounds [48 x i8], [48 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = call i32 @memset(i8* %3, i32 0, i32 48)
%10 = call i32 @snprintf(i8* %3, i32 47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %3, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %8
%15 = call i32 @strlen(i8* %0)
%16 = call i64 @write(i32 %12, i8* %0, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = call i64 @close(i32 %12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %14, %8
%22 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), %18 ]
%23 = call i32 @warnx(i8* %22)
br label %24
24: ; preds = %21, %18, %1, %5
%25 = phi i32 [ -1, %5 ], [ -1, %1 ], [ 0, %18 ], [ -1, %21 ]
ret i32 %25
}