#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int,
                            int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int wiringPiFailure(int, char *, ...);
int /*<<< orphan*/ write(int, char const *, scalar_t__);
int gpio_set_edge(unsigned int gpio, unsigned int mode) {
  const char *modeS;
  pid_t pid;
  if (mode != 0) {
    if (mode == 1) {
      modeS = "falling";
    } else if (mode == 2) {
      modeS = "rising";
    } else {
      modeS = "both";
    }
    if ((pid = fork()) < 0)
      return wiringPiFailure((1 == 1), "wiringPiISR: fork failed: %s\n",
                             strerror(errno));
    if (pid == 0) {
      int fd;
      char filename[29];
      ;
      snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/edge", gpio,
               strerror(errno));
      if ((fd = open(filename, O_WRONLY)) < 0) {
        return wiringPiFailure((1 == 1), "wiringPiISR: open edge failed.\n");
      }
      write(fd, modeS, strlen(modeS) + 1);
      close(fd);
      ;
    } else
      wait(NULL);
  }
}


x86 assembly (clang, -O0):
<gpio_set_edge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     12ec <gpio_set_edge+0x15c>
cmpl   $0x1,-0xc(%rbp)
jne    11c2 <gpio_set_edge+0x32>
lea    0xe47(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <gpio_set_edge+0x5c>
cmpl   $0x2,-0xc(%rbp)
jne    11dc <gpio_set_edge+0x4c>
lea    0xe35(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11e7 <gpio_set_edge+0x57>
lea    0xe2c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <gpio_set_edge+0x5c>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    122c <gpio_set_edge+0x9c>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1070 <wiringPiFailure@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <gpio_set_edge+0x15c>
cmpq   $0x0,-0x20(%rbp)
jne    12de <gpio_set_edge+0x14e>
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%ecx
mov    %eax,%r8d
mov    $0x1d,%esi
lea    0xdc9(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    12a7 <gpio_set_edge+0x117>
mov    $0x1,%edi
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1070 <wiringPiFailure@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <gpio_set_edge+0x15c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
jmp    12e7 <gpio_set_edge+0x157>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
jmp    12ec <gpio_set_edge+0x15c>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_set_edge>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %esi,%esi
je     1268 <gpio_set_edge+0xd8>
mov    %edi,%ebp
cmp    $0x1,%esi
je     11b5 <gpio_set_edge+0x25>
cmp    $0x2,%esi
jne    11be <gpio_set_edge+0x2e>
lea    0xe55(%rip),%rbx
jmp    11c5 <gpio_set_edge+0x35>
lea    0xe44(%rip),%rbx
jmp    11c5 <gpio_set_edge+0x35>
lea    0xe4a(%rip),%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     11df <gpio_set_edge+0x4f>
je     120a <gpio_set_edge+0x7a>
xor    %edi,%edi
call   10a0 <wait@plt>
jmp    1268 <gpio_set_edge+0xd8>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe20(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <wiringPiFailure@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe13(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1d,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
call   1050 <snprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1271 <gpio_set_edge+0xe1>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd6(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <wiringPiFailure@plt>
jmp    1268 <gpio_set_edge+0xd8>

LLVM IR (-O0):
@.str = [8 x i8] c"falling\00"
@.str.1 = [7 x i8] c"rising\00"
@.str.2 = [5 x i8] c"both\00"
@.str.3 = [30 x i8] c"wiringPiISR: fork failed: %s\0A\00"
@errno = global i32 0
@.str.4 = [28 x i8] c"/sys/class/gpio/gpio%d/edge\00"
@O_WRONLY = global i32 0
@.str.5 = [32 x i8] c"wiringPiISR: open edge failed.\0A\00"
define i32 @gpio_set_edge(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [29 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %56
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
br label %22
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %16
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %21
20: ; preds = %16
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %21
21: ; preds = %20, %19
br label %22
22: ; preds = %21, %15
%23 = call i64 (...) @fork()
store i64 %23, i64* %7
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = call i32 (i32, i8*, ...) @wiringPiFailure(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %27)
store i32 %28, i32* %3
br label %56
29: ; preds = %22
%30 = load i64, i64* %7
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = getelementptr inbounds [29 x i8], [29 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* %4
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @snprintf(i8* %33, i32 29, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %36)
%38 = getelementptr inbounds [29 x i8], [29 x i8]* %9, i64 0, i64 0
%39 = load i32, i32* @O_WRONLY
%40 = call i32 @open(i8* %38, i32 %39)
store i32 %40, i32* %8
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 (i32, i8*, ...) @wiringPiFailure(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
store i32 %43, i32* %3
br label %56
44: ; preds = %32
%45 = load i32, i32* %8
%46 = load i8*, i8** %6
%47 = load i8*, i8** %6
%48 = call i64 @strlen(i8* %47)
%49 = add nsw i64 %48, 1
%50 = call i32 @write(i32 %45, i8* %46, i64 %49)
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
br label %55
53: ; preds = %29
%54 = call i32 @wait(i32* null)
br label %55
55: ; preds = %53, %44
br label %56
56: ; preds = %25, %42, %55, %2
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [8 x i8] c"falling\00"
@.str.1 = [7 x i8] c"rising\00"
@.str.2 = [5 x i8] c"both\00"
@.str.3 = [30 x i8] c"wiringPiISR: fork failed: %s\0A\00"
@errno = global i32 0
@.str.4 = [28 x i8] c"/sys/class/gpio/gpio%d/edge\00"
@O_WRONLY = global i32 0
@.str.5 = [32 x i8] c"wiringPiISR: open edge failed.\0A\00"
define i32 @gpio_set_edge(i32 %0, i32 %1) {
%3 = alloca [29 x i8]
switch i32 %1, label %5 [
i32 0, label %35
i32 1, label %6
i32 2, label %4
]
4: ; preds = %2
br label %6
5: ; preds = %2
br label %6
6: ; preds = %2, %4, %5
%7 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %2 ]
%8 = tail call i64 (...) @fork()
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 (i32, i8*, ...) @wiringPiFailure(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %35
14: ; preds = %6
%15 = icmp eq i64 %8, 0
br i1 %15, label %16, label %33
16: ; preds = %14
%17 = getelementptr inbounds [29 x i8], [29 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* @errno
%19 = tail call i32 @strerror(i32 %18)
%20 = call i32 @snprintf(i8* %17, i32 29, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %0, i32 %19)
%21 = load i32, i32* @O_WRONLY
%22 = call i32 @open(i8* %17, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 (i32, i8*, ...) @wiringPiFailure(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %31
26: ; preds = %16
%27 = call i64 @strlen(i8* dereferenceable(1) %7)
%28 = add nsw i64 %27, 1
%29 = call i32 @write(i32 %22, i8* %7, i64 %28)
%30 = call i32 @close(i32 %22)
br label %31
31: ; preds = %26, %24
%32 = phi i32 [ %25, %24 ], [ undef, %26 ]
br label %35
33: ; preds = %14
%34 = tail call i32 @wait(i32* null)
br label %35
35: ; preds = %31, %33, %2, %10
%36 = phi i32 [ %13, %10 ], [ %32, %31 ], [ undef, %33 ], [ undef, %2 ]
ret i32 %36
}