#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 timeval {
  int tv_sec;
  int tv_usec;
};
typedef int /*<<< orphan*/ funny;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ clrtoeol();
int getch();
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ mvaddstr(int, int, char *);
int rand();
int /*<<< orphan*/ refresh();
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int getcmd(int row, int col) {
  static char *funny[2] = {"You eat quiche!",
                           "Come on, we don't have all day!"};
  struct timeval tv;
  fd_set fdset;
  for (;;) {
    mvaddstr(row, col, "Enter one of the above: ");
    refresh();
    FD_ZERO(&fdset);
    FD_SET(0, &fdset);
    tv.tv_sec = 10;
    tv.tv_usec = 0;
    if (select(1, &fdset, (fd_set *)0, (fd_set *)0, &tv))
      break;
    mvaddstr(row + 2, col, funny[rand() % (sizeof(funny) / sizeof(*(funny)))]);
    refresh();
    tv.tv_sec = 0;
    tv.tv_usec = 500000;
    select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
    move(row + 2, col);
    clrtoeol();
  }
  return getch();
}


x86 assembly (clang, -O0):
<getcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    0xe85(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
lea    -0x14(%rbp),%rdi
call   1030 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1090 <FD_SET@plt>
movl   $0xa,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
cmp    $0x0,%rax
je     1201 <getcmd+0x71>
jmp    1278 <getcmd+0xe8>
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
movslq %eax,%rcx
and    $0x1,%rcx
lea    0x2e45(%rip),%rax
mov    (%rax,%rcx,8),%rdx
call   1080 <mvaddstr@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x7a120,-0xc(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <select@plt>
mov    -0x4(%rbp),%edi
add    $0x2,%edi
mov    -0x8(%rbp),%esi
call   10b0 <move@plt>
mov    $0x0,%al
call   1070 <clrtoeol@plt>
jmp    119e <getcmd+0xe>
mov    $0x0,%al
call   1060 <getch@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
lea    0x2(%r14),%ebp
lea    0x14(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe48(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %ebx,%esi
lea    0xe6c(%rip),%rdx
call   1080 <mvaddstr@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
mov    %r12,%rdi
call   1030 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1090 <FD_SET@plt>
movq   $0xa,0x8(%rsp)
mov    $0x1,%edi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   1040 <select@plt>
test   %rax,%rax
jne    1261 <getcmd+0xd1>
xor    %eax,%eax
call   10a0 <rand@plt>
and    $0x1,%eax
movslq (%r15,%rax,4),%rdx
add    %r15,%rdx
mov    %ebp,%edi
mov    %ebx,%esi
call   1080 <mvaddstr@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
movabs $0x7a12000000000,%rax
mov    %rax,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   1040 <select@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   10b0 <move@plt>
xor    %eax,%eax
call   1070 <clrtoeol@plt>
jmp    11c0 <getcmd+0x30>
xor    %eax,%eax
call   1060 <getch@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@getcmd.funny = internal global [2 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i32 0, i32 0)]
@.str = [16 x i8] c"You eat quiche!\00"
@.str.1 = [32 x i8] c"Come on, we don't have all day!\00"
@.str.2 = [25 x i8] c"Enter one of the above: \00"
define i32 @getcmd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32 @mvaddstr(i32 %8, i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (...) @refresh()
%12 = call i32 @FD_ZERO(i32* %6)
%13 = call i32 @FD_SET(i32 0, i32* %6)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 10, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 0, i32* %15
%16 = call i64 @select(i32 1, i32* %6, i32* null, i32* null, %struct.timeval* %5)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %7
br label %38
19: ; preds = %7
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 2
%22 = load i32, i32* %4
%23 = call i32 (...) @rand()
%24 = sext i32 %23 to i64
%25 = urem i64 %24, 2
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* @getcmd.funny, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @mvaddstr(i32 %21, i32 %22, i8* %27)
%29 = call i32 (...) @refresh()
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 0, i32* %30
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 500000, i32* %31
%32 = call i64 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %5)
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 2
%35 = load i32, i32* %4
%36 = call i32 @move(i32 %34, i32 %35)
%37 = call i32 (...) @clrtoeol()
br label %7
38: ; preds = %18
%39 = call i32 (...) @getch()
ret i32 %39
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@reltable.getcmd = internal unnamed_addr constant [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.getcmd to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.getcmd to i64)) to i32)]
@.str = [16 x i8] c"You eat quiche!\00"
@.str.1 = [32 x i8] c"Come on, we don't have all day!\00"
@.str.2 = [25 x i8] c"Enter one of the above: \00"
define i32 @getcmd(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = add nsw i32 %0, 2
br label %10
10: ; preds = %17, %2
%11 = call i32 @mvaddstr(i32 %0, i32 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (...) @refresh()
%13 = call i32 @FD_ZERO(i32* %4)
%14 = call i32 @FD_SET(i32 0, i32* %4)
store i32 10, i32* %7
store i32 0, i32* %8
%15 = call i64 @select(i32 1, i32* %4, i32* null, i32* null, %struct.timeval* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %10
%18 = call i32 (...) @rand()
%19 = and i32 %18, 1
%20 = zext i32 %19 to i64
%21 = shl i64 %20, 2
%22 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.getcmd to i8*), i64 %21)
%23 = call i32 @mvaddstr(i32 %9, i32 %1, i8* %22)
%24 = call i32 (...) @refresh()
store i32 0, i32* %7
store i32 500000, i32* %8
%25 = call i64 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
%26 = call i32 @move(i32 %9, i32 %1)
%27 = call i32 (...) @clrtoeol()
br label %10
28: ; preds = %10
%29 = call i32 (...) @getch()
ret i32 %29
}