#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 /*<<< orphan*/ fd;
};
struct epoll_event {
  int /*<<< orphan*/ events;
  TYPE_1__ data;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ close(int);
int epoll_create(int const);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int /*<<< orphan*/,
                     struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int const, int const);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(void) {
  const int nfds = 1;
  int epfd = epoll_create(nfds);
  if (epfd == -1) {
    printf("epoll_create: cannot create an epoll file descriptor\n");
    exit(EXIT_FAILURE);
  }
  const int nevents = 1;
  struct epoll_event events[nevents];
  events[0].data.fd = STDIN_FILENO;
  events[0].events = EPOLLIN;
  if (epoll_ctl(epfd, EPOLL_CTL_ADD, STDIN_FILENO, &events[0])) {
    printf("epoll_ctl: cannot control an epoll file descriptor\n");
    close(epfd);
    exit(EXIT_FAILURE);
  }
  for (int i = 10; i > 0; i--) {
    printf("%2d: Please press Enter...\n", i);
    const int timeout = 1000;
    int npolled = epoll_wait(epfd, events, nevents, timeout);
    if (npolled == -1) {
      printf("epoll_wait: cannot poll events\n");
      close(epfd);
      exit(EXIT_FAILURE);
    }
    if (npolled > 0) {
      printf("%2d: Splendid! You are a gentleman and a scholar.\n", i);
      while (fgetc(stdin) != '\n')
        ;
    }
  }
  close(epfd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    $0x1,%edi
call   1080 <epoll_create@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b9 <main+0x49>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x1,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
mov    %rsp,%rcx
add    $0xfffffffffffffff0,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rcx)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
mov    -0xc(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
call   1060 <epoll_ctl@plt>
cmp    $0x0,%rax
je     1234 <main+0xc4>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0xa,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12f6 <main+0x186>
mov    -0x1c(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
movl   $0x3e8,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%edx
mov    $0x3e8,%ecx
call   1070 <epoll_wait@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12a4 <main+0x134>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jle    12e3 <main+0x173>
mov    -0x1c(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12de <main+0x16e>
jmp    12bf <main+0x14f>
jmp    12e3 <main+0x173>
jmp    12e8 <main+0x178>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    123b <main+0xcb>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%edi
call   1090 <epoll_create@plt>
cmp    $0xffffffff,%eax
jne    11ae <main+0x2e>
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
jmp    12a2 <main+0x122>
mov    %eax,%r14d
mov    %rsp,%rax
lea    -0x10(%rax),%r12
mov    %r12,%rsp
mov    0x2df6(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,-0xc(%rax)
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x10(%rax)
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %r12,%rcx
call   1070 <epoll_ctl@plt>
test   %rax,%rax
jne    126f <main+0xef>
mov    $0xa,%ebx
lea    0xe04(%rip),%r15
mov    0x2ddd(%rip),%r13
jmp    121a <main+0x9a>
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
jbe    1278 <main+0xf8>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    $0x3e8,%ecx
call   1080 <epoll_wait@plt>
cmp    $0xffffffff,%eax
je     128e <main+0x10e>
test   %eax,%eax
jle    1210 <main+0x90>
lea    0xdd1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%edi
call   1050 <fgetc@plt>
cmp    $0xa,%al
jne    1260 <main+0xe0>
jmp    1210 <main+0x90>
lea    0xdf8(%rip),%rdi
jmp    1295 <main+0x115>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdba(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [54 x i8] c"epoll_create: cannot create an epoll file descriptor\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [52 x i8] c"epoll_ctl: cannot control an epoll file descriptor\0A\00"
@.str.2 = [28 x i8] c"%2d: Please press Enter...\0A\00"
@.str.3 = [32 x i8] c"epoll_wait: cannot poll events\0A\00"
@.str.4 = [51 x i8] c"%2d: Splendid! You are a gentleman and a scholar.\0A\00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%9 = call i32 @epoll_create(i32 1)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
store i32 1, i32* %4
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca %struct.epoll_event, i64 1
%19 = load i32, i32* @STDIN_FILENO
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %18, i64 0
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %20, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %19, i32* %22
%23 = load i32, i32* @EPOLLIN
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %18, i64 0
%25 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %3
%27 = load i32, i32* @EPOLL_CTL_ADD
%28 = load i32, i32* @STDIN_FILENO
%29 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %18, i64 0
%30 = call i64 @epoll_ctl(i32 %26, i32 %27, i32 %28, %struct.epoll_event* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %16
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %16
store i32 10, i32* %6
br label %39
39: ; preds = %69, %38
%40 = load i32, i32* %6
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %72
42: ; preds = %39
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %43)
store i32 1000, i32* %7
%45 = load i32, i32* %3
%46 = call i32 @epoll_wait(i32 %45, %struct.epoll_event* %18, i32 1, i32 1000)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* %3
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %42
%56 = load i32, i32* %8
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i32, i32* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %66, %58
%62 = load i32, i32* @stdin
%63 = call signext i8 @fgetc(i32 %62)
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 10
br i1 %65, label %66, label %67
66: ; preds = %61
br label %61
67: ; preds = %61
br label %68
68: ; preds = %67, %55
br label %69
69: ; preds = %68
%70 = load i32, i32* %6
%71 = add nsw i32 %70, -1
store i32 %71, i32* %6
br label %39
72: ; preds = %39
%73 = load i32, i32* %3
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* @EXIT_SUCCESS
%76 = call i32 @exit(i32 %75)
unreachable
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [28 x i8] c"%2d: Please press Enter...\0A\00"
@.str.4 = [51 x i8] c"%2d: Splendid! You are a gentleman and a scholar.\0A\00"
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [31 x i8] c"epoll_wait: cannot poll events\00"
@str.5 = [51 x i8] c"epoll_ctl: cannot control an epoll file descriptor\00"
@str.6 = [53 x i8] c"epoll_create: cannot create an epoll file descriptor\00"
define i32 @main() {
%1 = tail call i32 @epoll_create(i32 1)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.6, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = alloca %struct.epoll_event
%9 = load i32, i32* @STDIN_FILENO
%10 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i64 0, i32 1, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @EPOLLIN
%12 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i64 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* @EPOLL_CTL_ADD
%14 = call i64 @epoll_ctl(i32 %1, i32 %13, i32 %9, %struct.epoll_event* %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %7
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.5, i64 0, i64 0))
%18 = call i32 @close(i32 %1)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %43
%22 = call i32 @close(i32 %1)
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %7, %43
%26 = phi i32 [ %44, %43 ], [ 10, %7 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 @epoll_wait(i32 %1, %struct.epoll_event* %8, i32 1, i32 1000)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%32 = call i32 @close(i32 %1)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25
%36 = icmp sgt i32 %28, 0
br i1 %36, label %37, label %43
37: ; preds = %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %39
39: ; preds = %39, %37
%40 = load i32, i32* @stdin
%41 = call signext i8 @fgetc(i32 %40)
%42 = icmp eq i8 %41, 10
br i1 %42, label %43, label %39
43: ; preds = %39, %35
%44 = add nsw i32 %26, -1
%45 = icmp ugt i32 %26, 1
br i1 %45, label %25, label %21
}