#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 pollfd {
  int fd;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ POLLPRI;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int daemon(int, int /*<<< orphan*/);
int execl(char *, char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct pollfd *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int poll(struct pollfd *, int, int);
int read(int, char **, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
int main() {
  int fd = 0;
  int er = 0;
  char a[2];
  struct pollfd in[1];
  fd = open("/sys/class/gpio/export", O_WRONLY);
  if (fd == -1) {
    fprintf(stderr, "%s", strerror(fd));
    return 1;
  };
  er = write(fd, "3", 1);
  close(fd);
  if (er == -1) {
    fprintf(stderr, "%s", strerror(er));
    return 1;
  };
  usleep(100000);
  fd = open("/sys/class/gpio/gpio3/edge", O_WRONLY);
  if (fd == -1) {
    fprintf(stderr, "%s", strerror(fd));
    return 1;
  };
  er = write(fd, "both", 4);
  close(fd);
  if (er == -1) {
    fprintf(stderr, "%s", strerror(er));
    return 1;
  };
  fd = open("/sys/class/gpio/gpio3/value", O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "%s", strerror(fd));
    return 1;
  };
  er = read(fd, &a, 2);
  if (er == -1) {
    fprintf(stderr, "%s", strerror(er));
    return 1;
  };
  lseek(fd, 0, SEEK_SET);
  if (er == -1) {
    fprintf(stderr, "%s", strerror(er));
    return 1;
  };
  er = daemon(1, 0);
  if (er == -1) {
    fprintf(stderr, "%s", strerror(er));
    return 1;
  };
  if (fd == -1)
    return 0;
  memset(&in[0], 0, sizeof(struct pollfd));
  in[0].events = POLLPRI;
  in[0].fd = fd;
  while (1) {
    er = poll(in, 1, -1);
    if (er == -1) {
      fprintf(stderr, "%s", strerror(er));
      return 1;
    };
    er = read(fd, &a, 2);
    if (er == -1) {
      fprintf(stderr, "%s", strerror(er));
      return 1;
    };
    if (a[0] == '0') {
      er = execl("/usr/bin/sudo", "sudo", "shutdown", "-h", "now", NULL);
      if (er == -1) {
        fprintf(stderr, "%s", strerror(er));
        return 1;
      };
    }
    er = lseek(fd, 0, SEEK_SET);
    if (er == -1) {
      fprintf(stderr, "%s", strerror(er));
      return 1;
    };
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1231 <main+0x71>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf7(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    -0x8(%rbp),%edi
lea    0xddf(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    128c <main+0xcc>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xd9c(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    $0x186a0,%edi
call   10e0 <usleep@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
lea    0xd76(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12ea <main+0x12a>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xd3e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    -0x8(%rbp),%edi
lea    0xd43(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1345 <main+0x185>
mov    0x2cb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xce3(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    0x2c94(%rip),%rax
mov    (%rax),%esi
lea    0xce7(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1399 <main+0x1d9>
mov    0x2c62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xc8f(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    -0x8(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x2,%edx
call   1070 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    13e9 <main+0x229>
mov    0x2c12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xc3f(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    -0x8(%rbp),%edi
mov    0x2bd5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1438 <main+0x278>
mov    0x2bc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xbf0(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    $0x1,%edi
xor    %esi,%esi
call   1090 <daemon@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1483 <main+0x2c3>
mov    0x2b78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xba5(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1499 <main+0x2d9>
movl   $0x0,-0x4(%rbp)
jmp    1632 <main+0x472>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2b40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    150d <main+0x34d>
mov    0x2aee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xb1b(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
mov    -0x8(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x2,%edx
call   1070 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    155d <main+0x39d>
mov    0x2a9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xacb(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
movsbl -0xe(%rbp),%eax
cmp    $0x30,%eax
jne    15db <main+0x41b>
lea    0xae7(%rip),%rdi
lea    0xae9(%rip),%rsi
lea    0xae7(%rip),%rdx
lea    0xae9(%rip),%rcx
lea    0xae5(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   10d0 <execl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    15d6 <main+0x416>
mov    0x2a25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xa52(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
jmp    15db <main+0x41b>
mov    -0x8(%rbp),%edi
mov    0x29e3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    162d <main+0x46d>
mov    0x29ce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0x9fb(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1632 <main+0x472>
jmp    14bb <main+0x2fb>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2de3(%rip),%r14
mov    (%r14),%esi
lea    0xe21(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
mov    %eax,%ebx
lea    0xe24(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%ebp
je     136b <main+0x1ab>
mov    $0x186a0,%edi
call   10e0 <usleep@plt>
mov    (%r14),%esi
lea    0xdf4(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
mov    %eax,%ebx
lea    0xdf8(%rip),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%ebp
je     136b <main+0x1ab>
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    0xdcf(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
mov    %eax,%ebx
lea    0xe(%rsp),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
mov    0x2d2a(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    $0x1,%edi
xor    %esi,%esi
call   1090 <daemon@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %ebx,0x10(%rsp)
lea    0xe(%rsp),%r15
lea    0xd7f(%rip),%r12
lea    0xd7b(%rip),%r13
jmp    1311 <main+0x151>
nopl   0x0(%rax)
mov    0x0(%rbp),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     136b <main+0x1ab>
cmpb   $0x30,0xe(%rsp)
jne    1300 <main+0x140>
lea    0xd0e(%rip),%rdi
lea    0xd10(%rip),%rsi
lea    0xd0e(%rip),%rdx
mov    %r12,%rcx
mov    %r13,%r8
xor    %r9d,%r9d
call   10d0 <execl@plt>
cmp    $0xffffffff,%eax
jne    1300 <main+0x140>
mov    0x2c5e(%rip),%rax
mov    (%rax),%ebx
mov    $0xffffffff,%edi
call   10c0 <strerror@plt>
lea    0xc92(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"3\00"
@.str.3 = [27 x i8] c"/sys/class/gpio/gpio3/edge\00"
@.str.4 = [5 x i8] c"both\00"
@.str.5 = [28 x i8] c"/sys/class/gpio/gpio3/value\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@POLLPRI = global i32 0
@.str.6 = [14 x i8] c"/usr/bin/sudo\00"
@.str.7 = [5 x i8] c"sudo\00"
@.str.8 = [9 x i8] c"shutdown\00"
@.str.9 = [3 x i8] c"-h\00"
@.str.10 = [4 x i8] c"now\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca [1 x %struct.pollfd]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* %2
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %1
br label %152
15: ; preds = %0
%16 = load i32, i32* %2
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i32, i32* %3
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 1, i32* %1
br label %152
27: ; preds = %15
%28 = call i32 @usleep(i32 100000)
%29 = load i32, i32* @O_WRONLY
%30 = call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %29)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i32, i32* %2
%36 = call i8* @strerror(i32 %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i32 1, i32* %1
br label %152
38: ; preds = %27
%39 = load i32, i32* %2
%40 = call i32 @write(i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
store i32 %40, i32* %3
%41 = load i32, i32* %2
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %3
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = load i32, i32* %3
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %48)
store i32 1, i32* %1
br label %152
50: ; preds = %38
%51 = load i32, i32* @O_RDONLY
%52 = call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %51)
store i32 %52, i32* %2
%53 = load i32, i32* %2
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = load i32, i32* %2
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %58)
store i32 1, i32* %1
br label %152
60: ; preds = %50
%61 = load i32, i32* %2
%62 = bitcast [2 x i8]* %4 to i8**
%63 = call i32 @read(i32 %61, i8** %62, i32 2)
store i32 %63, i32* %3
%64 = load i32, i32* %3
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %71
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = load i32, i32* %3
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %69)
store i32 1, i32* %1
br label %152
71: ; preds = %60
%72 = load i32, i32* %2
%73 = load i32, i32* @SEEK_SET
%74 = call i32 @lseek(i32 %72, i32 0, i32 %73)
%75 = load i32, i32* %3
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %82
77: ; preds = %71
%78 = load i32, i32* @stderr
%79 = load i32, i32* %3
%80 = call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %80)
store i32 1, i32* %1
br label %152
82: ; preds = %71
%83 = call i32 @daemon(i32 1, i32 0)
store i32 %83, i32* %3
%84 = load i32, i32* %3
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %91
86: ; preds = %82
%87 = load i32, i32* @stderr
%88 = load i32, i32* %3
%89 = call i8* @strerror(i32 %88)
%90 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %89)
store i32 1, i32* %1
br label %152
91: ; preds = %82
%92 = load i32, i32* %2
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %95
94: ; preds = %91
store i32 0, i32* %1
br label %152
95: ; preds = %91
%96 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%97 = call i32 @memset(%struct.pollfd* %96, i32 0, i32 8)
%98 = load i32, i32* @POLLPRI
%99 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%100 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %99, i32 0, i32 1
store i32 %98, i32* %100
%101 = load i32, i32* %2
%102 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%103 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %102, i32 0, i32 0
store i32 %101, i32* %103
br label %104
104: ; preds = %95, %151
%105 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%106 = call i32 @poll(%struct.pollfd* %105, i32 1, i32 -1)
store i32 %106, i32* %3
%107 = load i32, i32* %3
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %114
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i32, i32* %3
%112 = call i8* @strerror(i32 %111)
%113 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %112)
store i32 1, i32* %1
br label %152
114: ; preds = %104
%115 = load i32, i32* %2
%116 = bitcast [2 x i8]* %4 to i8**
%117 = call i32 @read(i32 %115, i8** %116, i32 2)
store i32 %117, i32* %3
%118 = load i32, i32* %3
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %125
120: ; preds = %114
%121 = load i32, i32* @stderr
%122 = load i32, i32* %3
%123 = call i8* @strerror(i32 %122)
%124 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %123)
store i32 1, i32* %1
br label %152
125: ; preds = %114
%126 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = icmp eq i32 %128, 48
br i1 %129, label %130, label %140
130: ; preds = %125
%131 = call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* null)
store i32 %131, i32* %3
%132 = load i32, i32* %3
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %139
134: ; preds = %130
%135 = load i32, i32* @stderr
%136 = load i32, i32* %3
%137 = call i8* @strerror(i32 %136)
%138 = call i32 @fprintf(i32 %135, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %137)
store i32 1, i32* %1
br label %152
139: ; preds = %130
br label %140
140: ; preds = %139, %125
%141 = load i32, i32* %2
%142 = load i32, i32* @SEEK_SET
%143 = call i32 @lseek(i32 %141, i32 0, i32 %142)
store i32 %143, i32* %3
%144 = load i32, i32* %3
%145 = icmp eq i32 %144, -1
br i1 %145, label %146, label %151
146: ; preds = %140
%147 = load i32, i32* @stderr
%148 = load i32, i32* %3
%149 = call i8* @strerror(i32 %148)
%150 = call i32 @fprintf(i32 %147, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %149)
store i32 1, i32* %1
br label %152
151: ; preds = %140
br label %104
152: ; preds = %146, %134, %120, %109, %94, %86, %77, %66, %55, %45, %33, %22, %10
%153 = load i32, i32* %1
ret i32 %153
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@.str = [23 x i8] c"/sys/class/gpio/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"3\00"
@.str.3 = [27 x i8] c"/sys/class/gpio/gpio3/edge\00"
@.str.4 = [5 x i8] c"both\00"
@.str.5 = [28 x i8] c"/sys/class/gpio/gpio3/value\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@POLLPRI = global i32 0
@.str.6 = [14 x i8] c"/usr/bin/sudo\00"
@.str.7 = [5 x i8] c"sudo\00"
@.str.8 = [9 x i8] c"shutdown\00"
@.str.9 = [3 x i8] c"-h\00"
@.str.10 = [4 x i8] c"now\00"
define i32 @main() {
%1 = alloca [2 x i8]
%2 = alloca [1 x %struct.pollfd]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%4 = bitcast [1 x %struct.pollfd]* %2 to i8*
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i32 -1)
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %100
12: ; preds = %0
%13 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%14 = tail call i32 @close(i32 %6)
%15 = icmp eq i32 %13, -1
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i8* @strerror(i32 -1)
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %100
20: ; preds = %12
%21 = tail call i32 @usleep(i32 100000)
%22 = load i32, i32* @O_WRONLY
%23 = tail call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = tail call i8* @strerror(i32 -1)
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %100
29: ; preds = %20
%30 = tail call i32 @write(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%31 = tail call i32 @close(i32 %23)
%32 = icmp eq i32 %30, -1
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = tail call i8* @strerror(i32 -1)
%36 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %100
37: ; preds = %29
%38 = load i32, i32* @O_RDONLY
%39 = tail call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = tail call i8* @strerror(i32 -1)
%44 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %100
45: ; preds = %37
%46 = bitcast [2 x i8]* %1 to i8**
%47 = call i32 @read(i32 %39, i8** %46, i32 2)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = tail call i8* @strerror(i32 -1)
%52 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %51)
br label %100
53: ; preds = %45
%54 = load i32, i32* @SEEK_SET
%55 = tail call i32 @lseek(i32 %39, i32 0, i32 %54)
%56 = tail call i32 @daemon(i32 1, i32 0)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = tail call i8* @strerror(i32 -1)
%61 = tail call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %60)
br label %100
62: ; preds = %53
%63 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%64 = call i32 @memset(%struct.pollfd* %63, i32 0, i32 8)
%65 = load i32, i32* @POLLPRI
%66 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 1
store i32 %65, i32* %66
%67 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0, i32 0
store i32 %39, i32* %67
br label %68
68: ; preds = %92, %62
%69 = call i32 @poll(%struct.pollfd* %63, i32 1, i32 -1)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = load i32, i32* @stderr
%73 = call i8* @strerror(i32 -1)
%74 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %73)
br label %100
75: ; preds = %68
%76 = call i32 @read(i32 %39, i8** %46, i32 2)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = call i8* @strerror(i32 -1)
%81 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %80)
br label %100
82: ; preds = %75
%83 = load i8, i8* %3
%84 = icmp eq i8 %83, 48
br i1 %84, label %85, label %92
85: ; preds = %82
%86 = call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32* null)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %92
88: ; preds = %85
%89 = load i32, i32* @stderr
%90 = call i8* @strerror(i32 -1)
%91 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %90)
br label %100
92: ; preds = %85, %82
%93 = load i32, i32* @SEEK_SET
%94 = call i32 @lseek(i32 %39, i32 0, i32 %93)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %68
96: ; preds = %92
%97 = load i32, i32* @stderr
%98 = call i8* @strerror(i32 -1)
%99 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %96, %88, %78, %71, %58, %49, %41, %33, %25, %16, %8
ret i32 1
}