#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*/ F_OK;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int pwk_init(void) {
  int fd;
  int wr_err = 0;
  if (access("/sys/class/gpio/gpio7", F_OK) == -1) {
    fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd < 0)
      return -1;
    wr_err += write(fd, "7", 1) != 1;
    close(fd);
  }
  fd = open("/sys/class/gpio/gpio7/direction", O_WRONLY);
  if (fd < 0)
    return -1;
  wr_err += write(fd, "in", 2) != 2;
  close(fd);
  fd = open("/sys/class/gpio/gpio7/active_low", O_WRONLY);
  if (fd < 0)
    return -1;
  wr_err += write(fd, "1", 1) != 1;
  close(fd);
  fd = open("/sys/class/gpio/gpio7/edge", O_WRONLY);
  if (fd < 0)
    return -1;
  wr_err += write(fd, "falling", 7) != 7;
  close(fd);
  fd = open("/sys/class/gpio/gpio7/value", O_RDONLY);
  if (wr_err)
    fprintf(stderr, "Write errors during PWK_INIT: %d\n", wr_err);
  return fd;
}


x86 assembly (clang, -O0):
<pwk_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    11d8 <pwk_init+0x88>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ab <pwk_init+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <pwk_init+0x1d9>
mov    -0x8(%rbp),%edi
lea    0xe5f(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1206 <pwk_init+0xb6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <pwk_init+0x1d9>
mov    -0x8(%rbp),%edi
lea    0xe3d(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xe0d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1261 <pwk_init+0x111>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <pwk_init+0x1d9>
mov    -0x8(%rbp),%edi
lea    0xe06(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
lea    0xdd5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12bc <pwk_init+0x16c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1329 <pwk_init+0x1d9>
mov    -0x8(%rbp),%edi
lea    0xdc8(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
cmp    $0x7,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
lea    0xd9d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1323 <pwk_init+0x1d3>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xd94(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwk_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1070 <access@plt>
xor    %r13d,%r13d
cmp    $0xffffffff,%eax
jne    11bb <pwk_init+0x6b>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     12bc <pwk_init+0x16c>
mov    %eax,%ebx
lea    0xe76(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %r13d,%r13d
cmp    $0x1,%eax
setne  %r13b
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2e06(%rip),%r15
mov    (%r15),%esi
lea    0xe61(%rip),%rdi
call   1060 <open@plt>
mov    $0xffffffff,%r12d
test   %eax,%eax
js     12c2 <pwk_init+0x172>
mov    %eax,%ebp
lea    0xe65(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1040 <close@plt>
mov    (%r15),%esi
lea    0xe48(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     12c2 <pwk_init+0x172>
mov    %eax,%ebp
lea    0xe53(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    (%r15),%esi
lea    0xe36(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     12c2 <pwk_init+0x172>
mov    %eax,%r15d
xor    %eax,%eax
cmp    $0x2,%r14d
setne  %al
add    %eax,%r13d
mov    %ebx,%eax
xor    %ebx,%ebx
cmp    $0x1,%eax
setne  %bl
add    %r13d,%ebx
lea    0xe25(%rip),%rsi
mov    %r15d,%edi
mov    $0x7,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
cmp    $0x7,%eax
setne  %bpl
mov    %r15d,%edi
call   1040 <close@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r12d
add    %ebx,%ebp
je     12c2 <pwk_init+0x172>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
jmp    12c2 <pwk_init+0x172>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/sys/class/gpio/gpio7\00"
@F_OK = global i32 0
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.2 = [2 x i8] c"7\00"
@.str.3 = [32 x i8] c"/sys/class/gpio/gpio7/direction\00"
@.str.4 = [3 x i8] c"in\00"
@.str.5 = [33 x i8] c"/sys/class/gpio/gpio7/active_low\00"
@.str.6 = [2 x i8] c"1\00"
@.str.7 = [27 x i8] c"/sys/class/gpio/gpio7/edge\00"
@.str.8 = [8 x i8] c"falling\00"
@.str.9 = [28 x i8] c"/sys/class/gpio/gpio7/value\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.10 = [34 x i8] c"Write errors during PWK_INIT: %d\0A\00"
define i32 @pwk_init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = load i32, i32* @F_OK
%5 = call i32 @access(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %22
7: ; preds = %0
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
store i32 -1, i32* %1
br label %75
13: ; preds = %7
%14 = load i32, i32* %2
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%16 = icmp ne i32 %15, 1
%17 = zext i1 %16 to i32
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %17
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %13, %0
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -1, i32* %1
br label %75
28: ; preds = %22
%29 = load i32, i32* %2
%30 = call i32 @write(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%31 = icmp ne i32 %30, 2
%32 = zext i1 %31 to i32
%33 = load i32, i32* %3
%34 = add nsw i32 %33, %32
store i32 %34, i32* %3
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* @O_WRONLY
%38 = call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %37)
store i32 %38, i32* %2
%39 = load i32, i32* %2
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %28
store i32 -1, i32* %1
br label %75
42: ; preds = %28
%43 = load i32, i32* %2
%44 = call i32 @write(i32 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%45 = icmp ne i32 %44, 1
%46 = zext i1 %45 to i32
%47 = load i32, i32* %3
%48 = add nsw i32 %47, %46
store i32 %48, i32* %3
%49 = load i32, i32* %2
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* @O_WRONLY
%52 = call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %51)
store i32 %52, i32* %2
%53 = load i32, i32* %2
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %42
store i32 -1, i32* %1
br label %75
56: ; preds = %42
%57 = load i32, i32* %2
%58 = call i32 @write(i32 %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%59 = icmp ne i32 %58, 7
%60 = zext i1 %59 to i32
%61 = load i32, i32* %3
%62 = add nsw i32 %61, %60
store i32 %62, i32* %3
%63 = load i32, i32* %2
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* @O_RDONLY
%66 = call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %65)
store i32 %66, i32* %2
%67 = load i32, i32* %3
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %56
%70 = load i32, i32* @stderr
%71 = load i32, i32* %3
%72 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %69, %56
%74 = load i32, i32* %2
store i32 %74, i32* %1
br label %75
75: ; preds = %73, %55, %41, %27, %12
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str = [22 x i8] c"/sys/class/gpio/gpio7\00"
@F_OK = global i32 0
@.str.1 = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@.str.2 = [2 x i8] c"7\00"
@.str.3 = [32 x i8] c"/sys/class/gpio/gpio7/direction\00"
@.str.4 = [3 x i8] c"in\00"
@.str.5 = [33 x i8] c"/sys/class/gpio/gpio7/active_low\00"
@.str.6 = [2 x i8] c"1\00"
@.str.7 = [27 x i8] c"/sys/class/gpio/gpio7/edge\00"
@.str.8 = [8 x i8] c"falling\00"
@.str.9 = [28 x i8] c"/sys/class/gpio/gpio7/value\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.10 = [34 x i8] c"Write errors during PWK_INIT: %d\0A\00"
define i32 @pwk_init() {
%1 = load i32, i32* @F_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %13
4: ; preds = %0
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %48, label %8
8: ; preds = %4
%9 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%10 = icmp ne i32 %9, 1
%11 = zext i1 %10 to i32
%12 = tail call i32 @close(i32 %6)
br label %13
13: ; preds = %8, %0
%14 = phi i32 [ %11, %8 ], [ 0, %0 ]
%15 = load i32, i32* @O_WRONLY
%16 = tail call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %48, label %18
18: ; preds = %13
%19 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%20 = tail call i32 @close(i32 %16)
%21 = load i32, i32* @O_WRONLY
%22 = tail call i32 @open(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %48, label %24
24: ; preds = %18
%25 = tail call i32 @write(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%26 = tail call i32 @close(i32 %22)
%27 = load i32, i32* @O_WRONLY
%28 = tail call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %48, label %30
30: ; preds = %24
%31 = icmp ne i32 %19, 2
%32 = zext i1 %31 to i32
%33 = add nuw nsw i32 %14, %32
%34 = icmp ne i32 %25, 1
%35 = zext i1 %34 to i32
%36 = add nuw nsw i32 %33, %35
%37 = tail call i32 @write(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%38 = icmp ne i32 %37, 7
%39 = zext i1 %38 to i32
%40 = add nuw nsw i32 %36, %39
%41 = tail call i32 @close(i32 %28)
%42 = load i32, i32* @O_RDONLY
%43 = tail call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %42)
%44 = icmp eq i32 %40, 0
br i1 %44, label %48, label %45
45: ; preds = %30
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 %40)
br label %48
48: ; preds = %30, %45, %24, %18, %13, %4
%49 = phi i32 [ -1, %4 ], [ -1, %13 ], [ -1, %18 ], [ -1, %24 ], [ %43, %45 ], [ %43, %30 ]
ret i32 %49
}