#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int rand();
void playgame(void) {
  char input;
  int goal;
  clock_t start, end;
  double elapsed, range;
  goal = rand() % 9 + 1;
  printf("\nYour goal this time is %d seconds exactly\n"
         "Press ENTER when ready to start the timer...\n",
         goal);
  getchar();
  start = clock();
  printf("Press ENTER to stop the timer\n");
  getchar();
  end = clock();
  elapsed = (double)(end - start) / CLOCKS_PER_SEC;
  printf("%.2f seconds.\n", elapsed);
  range = (elapsed > goal) ? elapsed - goal : goal - elapsed;
  if (range == 0)
    printf("UNBELIEVABLE! Are you sure you're not a computer?\n");
  else if (range <= 0.1)
    printf("Close enough. You get a win for that one!\n");
  else
    printf("Oh, %.2f away. Not close enough.\n", range);
}


x86 assembly (clang, -O0):
<playgame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x9,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e34(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xeb7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11fc <playgame+0xbc>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    120b <playgame+0xcb>
cvtsi2sdl -0x8(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1240 <playgame+0x100>
jp     1240 <playgame+0x100>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127e <playgame+0x13e>
movsd  0xdb8(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     1266 <playgame+0x126>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1279 <playgame+0x139>
movsd  -0x28(%rbp),%xmm0
lea    0xe7b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    127e <playgame+0x13e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<playgame>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,8),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
lea    0xe86(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e23(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,(%rsp)
lea    0xe8c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rsp),%xmm3
movapd %xmm3,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm3,%xmm2
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    121e <playgame+0xce>
jp     121e <playgame+0xce>
lea    0xebe(%rip),%rdi
jmp    1247 <playgame+0xf7>
movsd  0xdda(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1240 <playgame+0xf0>
lea    0xe3d(%rip),%rdi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>
lea    0xe69(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [89 x i8] c"\0AYour goal this time is %d seconds exactly\0APress ENTER when ready to start the timer...\0A\00"
@.str.1 = [31 x i8] c"Press ENTER to stop the timer\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [15 x i8] c"%.2f seconds.\0A\00"
@.str.3 = [51 x i8] c"UNBELIEVABLE! Are you sure you're not a computer?\0A\00"
@.str.4 = [43 x i8] c"Close enough. You get a win for that one!\0A\00"
@.str.5 = [34 x i8] c"Oh, %.2f away. Not close enough.\0A\00"
define void @playgame() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 9
%9 = add nsw i32 %8, 1
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @getchar()
%13 = call i64 (...) @clock()
store i64 %13, i64* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @getchar()
%16 = call i64 (...) @clock()
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = load i64, i64* %3
%19 = sub nsw i64 %17, %18
%20 = sitofp i64 %19 to double
%21 = load double, double* @CLOCKS_PER_SEC
%22 = fdiv double %20, %21
store double %22, double* %5
%23 = load double, double* %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = load double, double* %5
%26 = load i32, i32* %2
%27 = sitofp i32 %26 to double
%28 = fcmp ogt double %25, %27
br i1 %28, label %29, label %34
29: ; preds = %0
%30 = load double, double* %5
%31 = load i32, i32* %2
%32 = sitofp i32 %31 to double
%33 = fsub double %30, %32
br label %39
34: ; preds = %0
%35 = load i32, i32* %2
%36 = sitofp i32 %35 to double
%37 = load double, double* %5
%38 = fsub double %36, %37
br label %39
39: ; preds = %34, %29
%40 = phi double [ %33, %29 ], [ %38, %34 ]
store double %40, double* %6
%41 = load double, double* %6
%42 = fcmp oeq double %41, 0.000000e+00
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %54
45: ; preds = %39
%46 = load double, double* %6
%47 = fcmp ole double %46, 1.000000e-01
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %53
50: ; preds = %45
%51 = load double, double* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), double %51)
br label %53
53: ; preds = %50, %48
br label %54
54: ; preds = %53, %43
ret void
}

LLVM IR (-O2):
@.str = [89 x i8] c"\0AYour goal this time is %d seconds exactly\0APress ENTER when ready to start the timer...\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [15 x i8] c"%.2f seconds.\0A\00"
@.str.5 = [34 x i8] c"Oh, %.2f away. Not close enough.\0A\00"
@str = [30 x i8] c"Press ENTER to stop the timer\00"
@str.6 = [42 x i8] c"Close enough. You get a win for that one!\00"
@str.7 = [50 x i8] c"UNBELIEVABLE! Are you sure you're not a computer?\00"
define void @playgame() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 9
%3 = add nsw i32 %2, 1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @getchar()
%6 = tail call i64 (...) @clock()
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (...) @getchar()
%9 = tail call i64 (...) @clock()
%10 = sub nsw i64 %9, %6
%11 = sitofp i64 %10 to double
%12 = load double, double* @CLOCKS_PER_SEC
%13 = fdiv double %11, %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %13)
%15 = sitofp i32 %3 to double
%16 = fcmp ogt double %13, %15
%17 = fsub double %13, %15
%18 = fsub double %15, %13
%19 = select i1 %16, double %17, double %18
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.7, i64 0, i64 0))
br label %29
23: ; preds = %0
%24 = fcmp ugt double %19, 1.000000e-01
br i1 %24, label %27, label %25
25: ; preds = %23
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.6, i64 0, i64 0))
br label %29
27: ; preds = %23
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), double %19)
br label %29
29: ; preds = %25, %27, %21
ret void
}