#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*/ path;
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 *, int);
void _edge(int pin) {
  char path[1024];
  FILE *fp;
  snprintf(path, sizeof(path), "/sys/class/gpio/gpio%d/edge", pin);
  fp = fopen(path, "w");
  if (!fp) {
    perror(path);
    exit(1);
  }
  if (fputs("both", fp) < 0) {
    perror(path);
    exit(1);
  }
  if (fclose(fp) != 0) {
    perror(path);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<_edge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x400,%esi
lea    0xe7c(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11c7 <_edge+0x67>
lea    -0x410(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x418(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1050 <fputs@plt>
cmp    $0x0,%rax
jge    11fa <_edge+0x9a>
lea    -0x410(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1226 <_edge+0xc6>
lea    -0x410(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_edge>:
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ecx
lea    0xe8f(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <snprintf@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c2 <_edge+0x62>
mov    %rax,%rbx
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
test   %rax,%rax
js     11c2 <_edge+0x62>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    11c2 <_edge+0x62>
add    $0x400,%rsp
pop    %rbx
ret
mov    %rsp,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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