#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;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int);
void gpioSetEdge(int gpio, const char *edge) {
  char path[PATH_MAX];
  snprintf(path, sizeof(path), "/sys/class/gpio/gpio%d/edge", gpio);
  int fd = open(path, O_WRONLY, 0);
  if (fd < 0) {
    return;
  }
  write(fd, edge, strlen(edge));
  write(fd, "\n", 1);
  close(fd);
}


x86 assembly (clang, -O0):
<gpioSetEdge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
mov    -0x4(%rbp),%ecx
lea    0xe69(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c9 <gpioSetEdge+0x79>
movl   $0x1,-0x28(%rbp)
jmp    1211 <gpioSetEdge+0xc1>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
lea    0xe24(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpioSetEdge>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ecx
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe80(%rip),%rdx
mov    %rbx,%rdi
call   1050 <snprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11cf <gpioSetEdge+0x7f>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe60(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [28 x i8] c"/sys/class/gpio/gpio%d/edge\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define void @gpioSetEdge(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = trunc i64 %10 to i32
%14 = load i32, i32* %3
%15 = call i32 @snprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* %12, i32 %16, i32 0)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 1, i32* %8
br label %31
21: ; preds = %2
%22 = load i32, i32* %7
%23 = load i8*, i8** %4
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
%27 = load i32, i32* %7
%28 = call i32 @write(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%29 = load i32, i32* %7
%30 = call i32 @close(i32 %29)
store i32 0, i32* %8
br label %31
31: ; preds = %21, %20
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
switch i32 %33, label %35 [
i32 0, label %34
i32 1, label %34
]
34: ; preds = %31, %31
ret void
35: ; preds = %31
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [28 x i8] c"/sys/class/gpio/gpio%d/edge\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define void @gpioSetEdge(i32 %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* %5, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = call i32 @strlen(i8* %1)
%12 = call i32 @write(i32 %8, i8* %1, i32 %11)
%13 = call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%14 = call i32 @close(i32 %8)
br label %15
15: ; preds = %2, %10
ret void
}