#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
scalar_t__ stat(char *, struct stat *);
void _unexport(int pin) {
  struct stat sb;
  char path[1024];
  char msg[16];
  FILE *fp;
  snprintf(path, sizeof(path), "/sys/class/gpio/gpio%d", pin);
  if (stat(path, &sb) < 0)
    return;
  snprintf(path, sizeof(path), "/sys/class/gpio/unexport");
  fp = fopen(path, "w");
  if (!fp) {
    perror(path);
    exit(1);
  }
  snprintf(msg, sizeof(msg), "%d", pin);
  if (fputs(msg, fp) < 0) {
    perror(path);
    exit(1);
  }
  if (fclose(fp) != 0) {
    perror(path);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<_unexport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x400,%esi
lea    0xe6c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11ba <_unexport+0x4a>
jmp    128e <_unexport+0x11e>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xe4a(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1212 <_unexport+0xa2>
lea    -0x410(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x10,%esi
lea    0xdec(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1050 <fputs@plt>
cmp    $0x0,%rax
jge    1262 <_unexport+0xf2>
lea    -0x410(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     128e <_unexport+0x11e>
lea    -0x410(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_unexport>:
push   %rbp
push   %r14
push   %rbx
sub    $0x420,%rsp
mov    %edi,%ebp
lea    0xe7c(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %rax,%rax
js     1218 <_unexport+0xa8>
lea    0xe64(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1224 <_unexport+0xb4>
mov    %rax,%rbx
lea    0xe2f(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
test   %rax,%rax
js     1224 <_unexport+0xb4>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    1224 <_unexport+0xb4>
add    $0x420,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x20(%rsp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [23 x i8] c"/sys/class/gpio/gpio%d\00"
@.str.1 = [25 x i8] c"/sys/class/gpio/unexport\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%d\00"
define void @_unexport(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca [1024 x i8]
%5 = alloca [16 x i8]
%6 = alloca i32*
store i32 %0, i32* %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i64 @stat(i8* %10, %struct.stat* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
br label %45
14: ; preds = %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %15, i32 1024, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %14
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = call i32 @perror(i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %14
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%27 = load i32, i32* %2
%28 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %26, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i64 @fputs(i8* %29, i32* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %25
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%35 = call i32 @perror(i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %25
%38 = load i32*, i32** %6
%39 = call i64 @fclose(i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%43 = call i32 @perror(i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %13, %37
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [23 x i8] c"/sys/class/gpio/gpio%d\00"
@.str.1 = [25 x i8] c"/sys/class/gpio/unexport\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%d\00"
define void @_unexport(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca [1024 x i8]
%4 = alloca [16 x i8]
%5 = bitcast %struct.stat* %2 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = call i64 @stat(i8* %6, %struct.stat* %2)
%10 = icmp slt i64 %9, 0
br i1 %10, label %31, label %11
11: ; preds = %1
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* %6)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%20 = call i64 @fputs(i8* %7, i32* %13)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @perror(i8* %6)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = call i64 @fclose(i32* %13)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call i32 @perror(i8* %6)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25, %1
ret void
}