#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLPRI;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int epoll_create(int);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ errno;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, char, ...);
int read(int, char *, int);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int n;
  int epfd = epoll_create(1);
  int fd = open("/sys/class/gpio/gpio17/value", O_RDWR | O_NONBLOCK);
  printf("open returned %d: %s\n", fd, strerror(errno));
  if (fd > 0) {
    char buf = 0;
    struct epoll_event ev;
    struct epoll_event events;
    ev.events = EPOLLPRI;
    ev.data.fd = fd;
    n = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
    printf("epoll_ctl returned %d: %s\n", n, strerror(errno));
    while (1) {
      n = epoll_wait(epfd, &events, 1, -1);
      printf("epoll returned %d: %s\n", n, strerror(errno));
      if (n > 0) {
        n = lseek(fd, 0, SEEK_SET);
        printf("seek %d bytes: %s\n", n, strerror(errno));
        n = read(fd, &buf, 1);
        printf("read %d bytes: %s\n", n, strerror(errno));
        printf("buf = 0x%x\n", buf);
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1090 <epoll_create@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2e25(%rip),%rax
or     (%rax),%esi
lea    0xe44(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,-0x31(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
mov    -0x31(%rbp),%al
lea    0xe38(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    133a <main+0x1ba>
movb   $0x0,-0x1d(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1050 <epoll_ctl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x32(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
mov    -0x32(%rbp),%al
lea    0xde8(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
call   1070 <epoll_wait@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x33(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
mov    -0x33(%rbp),%al
lea    0xdbf(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1335 <main+0x1b5>
mov    -0x1c(%rbp),%edi
mov    0x2d0b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x35(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
mov    -0x35(%rbp),%al
lea    0xd8b(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x34(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rdx
mov    -0x34(%rbp),%al
lea    0xd5f(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd61(%rip),%rdi
movsbl -0x1d(%rbp),%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1255 <main+0xd5>
xor    %eax,%eax
add    $0x40,%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    $0x1,%edi
call   1090 <epoll_create@plt>
mov    %eax,%r13d
mov    0x2e3e(%rip),%rax
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    0x2dfe(%rip),%r14
mov    (%r14),%edi
call   10a0 <strerror@plt>
movsbl %bpl,%esi
lea    0xe48(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
jle    12ef <main+0x16f>
movb   $0x0,0x7(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %r13d,%edi
mov    %ebp,%edx
call   1050 <epoll_ctl@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   10a0 <strerror@plt>
movsbl %bl,%esi
lea    0xe0a(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe14(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
call   1070 <epoll_wait@plt>
mov    %eax,%r12d
mov    (%r14),%edi
call   10a0 <strerror@plt>
movsbl %r12b,%esi
mov    %r15,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
test   %r12d,%r12d
jle    1240 <main+0xc0>
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   10a0 <strerror@plt>
movsbl %bl,%esi
lea    0xdc7(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   10a0 <strerror@plt>
movsbl %bl,%esi
lea    0xdab(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
movsbl 0x7(%rsp),%esi
lea    0xda8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1240 <main+0xc0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [29 x i8] c"/sys/class/gpio/gpio17/value\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [22 x i8] c"open returned %d: %s\0A\00"
@errno = global i32 0
@EPOLLPRI = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [27 x i8] c"epoll_ctl returned %d: %s\0A\00"
@.str.3 = [23 x i8] c"epoll returned %d: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [19 x i8] c"seek %d bytes: %s\0A\00"
@.str.5 = [19 x i8] c"read %d bytes: %s\0A\00"
@.str.6 = [12 x i8] c"buf = 0x%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca %struct.epoll_event
%11 = alloca %struct.epoll_event
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @epoll_create(i32 1)
store i32 %12, i32* %7
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %13, %14
%16 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = trunc i32 %17 to i8
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8 signext %18, i8* %20)
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %68
24: ; preds = %2
store i8 0, i8* %9
%25 = load i32, i32* @EPOLLPRI
%26 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* %8
%28 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %7
%31 = load i32, i32* @EPOLL_CTL_ADD
%32 = load i32, i32* %8
%33 = call i32 @epoll_ctl(i32 %30, i32 %31, i32 %32, %struct.epoll_event* %10)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = trunc i32 %34 to i8
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8 signext %35, i8* %37)
br label %39
39: ; preds = %24, %67
%40 = load i32, i32* %7
%41 = call i32 @epoll_wait(i32 %40, %struct.epoll_event* %11, i32 1, i32 -1)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = trunc i32 %42 to i8
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8 signext %43, i8* %45)
%47 = load i32, i32* %6
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %67
49: ; preds = %39
%50 = load i32, i32* %8
%51 = load i32, i32* @SEEK_SET
%52 = call i32 @lseek(i32 %50, i32 0, i32 %51)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = trunc i32 %53 to i8
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8 signext %54, i8* %56)
%58 = load i32, i32* %8
%59 = call i32 @read(i32 %58, i8* %9, i32 1)
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = trunc i32 %60 to i8
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8 signext %61, i8* %63)
%65 = load i8, i8* %9
%66 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8 signext %65)
br label %67
67: ; preds = %49, %39
br label %39
68: ; preds = %2
ret i32 0
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [29 x i8] c"/sys/class/gpio/gpio17/value\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [22 x i8] c"open returned %d: %s\0A\00"
@errno = global i32 0
@EPOLLPRI = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [27 x i8] c"epoll_ctl returned %d: %s\0A\00"
@.str.3 = [23 x i8] c"epoll returned %d: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [19 x i8] c"seek %d bytes: %s\0A\00"
@.str.5 = [19 x i8] c"read %d bytes: %s\0A\00"
@.str.6 = [12 x i8] c"buf = 0x%x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca %struct.epoll_event
%5 = alloca %struct.epoll_event
%6 = tail call i32 @epoll_create(i32 1)
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = trunc i32 %10 to i8
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8 signext %11, i8* %13)
%15 = icmp sgt i32 %10, 0
br i1 %15, label %16, label %50
16: ; preds = %2
store i8 0, i8* %3
%17 = bitcast %struct.epoll_event* %4 to i8*
%18 = bitcast %struct.epoll_event* %5 to i8*
%19 = load i32, i32* @EPOLLPRI
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0, i32 0
store i32 %10, i32* %21
%22 = load i32, i32* @EPOLL_CTL_ADD
%23 = call i32 @epoll_ctl(i32 %6, i32 %22, i32 %10, %struct.epoll_event* %4)
%24 = trunc i32 %23 to i8
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8 signext %24, i8* %26)
br label %28
28: ; preds = %49, %16
%29 = call i32 @epoll_wait(i32 %6, %struct.epoll_event* %5, i32 1, i32 -1)
%30 = trunc i32 %29 to i8
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8 signext %30, i8* %32)
%34 = icmp sgt i32 %29, 0
br i1 %34, label %35, label %49
35: ; preds = %28
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @lseek(i32 %10, i32 0, i32 %36)
%38 = trunc i32 %37 to i8
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8 signext %38, i8* %40)
%42 = call i32 @read(i32 %10, i8* %3, i32 1)
%43 = trunc i32 %42 to i8
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8 signext %43, i8* %45)
%47 = load i8, i8* %3
%48 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8 signext %47)
br label %49
49: ; preds = %35, %28
br label %28
50: ; preds = %2
ret i32 0
}