#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 /*<<< orphan*/ events;
  int /*<<< orphan*/ fd;
};
typedef int /*<<< orphan*/ pfd;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct pollfd *, int /*<<< orphan*/, int);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  struct pollfd pfd;
  char buf[1024];
  memset(&pfd, 0, sizeof(pfd));
  pfd.fd = fileno(stdin);
  pfd.events |= POLLIN;
  printf("Say something within %.2f secs to get a lollipop~\n", 2000 / 1000.0);
  if (poll(&pfd, 1, 2000) == 1) {
    printf("Good boy\n");
    fgets(buf, sizeof(buf), stdin);
  } else {
    printf("oops!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    0xe6f(%rip),%rdi
movsd  0xe5f(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x7d0,%edx
call   1070 <poll@plt>
cmp    $0x1,%eax
jne    11f1 <main+0xa1>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
jmp    11ff <main+0xaf>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e63(%rip),%r14
mov    (%r14),%edi
call   1070 <fileno@plt>
mov    %eax,0xc(%rsp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
or     %eax,0x8(%rsp)
lea    0xe63(%rip),%rdi
movsd  0xe53(%rip),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x7d0,%edx
call   1080 <poll@plt>
cmp    $0x1,%eax
jne    11eb <main+0x8b>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%edx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
jmp    11f7 <main+0x97>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@stdin = global i32 0
@POLLIN = global i32 0
@.str = [51 x i8] c"Say something within %.2f secs to get a lollipop~\0A\00"
@.str.1 = [10 x i8] c"Good boy\0A\00"
@.str.2 = [7 x i8] c"oops!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.pollfd
%3 = alloca [1024 x i8]
store i32 0, i32* %1
%4 = call i32 @memset(%struct.pollfd* %2, i32 0, i32 8)
%5 = load i32, i32* @stdin
%6 = call i32 @fileno(i32 %5)
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @POLLIN
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = or i32 %10, %8
store i32 %11, i32* %9
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double 2.000000e+00)
%13 = call i32 @poll(%struct.pollfd* %2, i32 1, i32 2000)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 1024, i32 %18)
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
ret i32 0
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@stdin = global i32 0
@POLLIN = global i32 0
@.str = [51 x i8] c"Say something within %.2f secs to get a lollipop~\0A\00"
@str = [6 x i8] c"oops!\00"
@str.3 = [9 x i8] c"Good boy\00"
define i32 @main() {
%1 = alloca %struct.pollfd
%2 = alloca [1024 x i8]
%3 = bitcast %struct.pollfd* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(%struct.pollfd* %1, i32 0, i32 8)
%6 = load i32, i32* @stdin
%7 = call i32 @fileno(i32 %6)
%8 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @POLLIN
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = or i32 %11, %9
store i32 %12, i32* %10
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), double 2.000000e+00)
%14 = call i32 @poll(%struct.pollfd* %1, i32 1, i32 2000)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.3, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %4, i32 1024, i32 %18)
br label %22
20: ; preds = %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
ret i32 0
}