#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 int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ ULONG_MAX;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
unsigned long rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
unsigned long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  char buffer[11];
  unsigned long choices = 1, random = 0, same = 0, total = 1;
  unsigned short question = 0;
  float randright = 0, sameright = 0;
  printf("+===================================================================="
         "==+\n"
         "|                             TestGuesser                            "
         "  |\n"
         "|              Copyright (C) 2011 William Breathitt Gray             "
         "  |\n"
         "+===================================================================="
         "==+\n"
         "|  This program comes with ABSOLUTELY NO WARRANTY. This is free      "
         "  |\n"
         "|  software, and you are welcome to redistribute it under certain    "
         "  |\n"
         "|  conditions; for further details, please refer to the GNU General  "
         "  |\n"
         "|  Public License provided with this program.                        "
         "  |\n"
         "+===================================================================="
         "==+\n\n");
  do {
    printf("Enter the number of choices per question (<=%lu):\n> ", ULONG_MAX);
    fgets(buffer, sizeof(buffer), stdin);
    choices = strtoul(buffer, NULL, 0);
  } while (!choices);
  do {
    printf("Enter the number of questions (<=%lu):\n> ", ULONG_MAX);
    fgets(buffer, sizeof(buffer), stdin);
    total = strtoul(buffer, NULL, 0);
  } while (!total);
  printf("\nAnswering %lu questions...\n", total);
  unsigned long x;
  for (x = 0; x < total; x++) {
    question = rand() % choices;
    if (question == rand() % choices) {
      random++;
    }
    if (question == 0) {
      same++;
    }
  }
  randright = (float)random / total;
  sameright = (float)same / total;
  printf("Random: %.3f\nSame: %.3f\n", randright, sameright);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movq   $0x1,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
movw   $0x0,-0x32(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
lea    0x10bd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xf(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    $0xb,%esi
call   1050 <fgets@plt>
lea    -0xf(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c6 <main+0x66>
jmp    121e <main+0xbe>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    0x109a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xf(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    $0xb,%esi
call   1050 <fgets@plt>
lea    -0xf(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121e <main+0xbe>
mov    -0x30(%rbp),%rsi
lea    0x1076(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    130e <main+0x1ae>
mov    $0x0,%al
call   1080 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %dx,%ax
mov    %ax,-0x32(%rbp)
movzwl -0x32(%rbp),%eax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    -0x50(%rbp),%rax
cmp    %rdx,%rax
jne    12df <main+0x17f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movzwl -0x32(%rbp),%eax
cmp    $0x0,%eax
jne    12f8 <main+0x198>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    12fd <main+0x19d>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    128b <main+0x12b>
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x58(%rbp)
test   %rax,%rax
movss  %xmm0,-0x54(%rbp)
js     134b <main+0x1eb>
movss  -0x58(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x54(%rbp),%xmm0
movss  %xmm0,-0x64(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x60(%rbp)
test   %rax,%rax
movss  %xmm0,-0x5c(%rbp)
js     1392 <main+0x232>
movss  -0x60(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x64(%rbp),%xmm0
movss  -0x5c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x6c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x68(%rbp)
js     13e2 <main+0x282>
movss  -0x6c(%rbp),%xmm0
movss  %xmm0,-0x68(%rbp)
movss  -0x68(%rbp),%xmm0
movss  %xmm0,-0x78(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x74(%rbp)
test   %rax,%rax
movss  %xmm0,-0x70(%rbp)
js     1429 <main+0x2c9>
movss  -0x74(%rbp),%xmm0
movss  %xmm0,-0x70(%rbp)
movss  -0x78(%rbp),%xmm0
movss  -0x70(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x3c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xeba(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e31(%rip),%r13
lea    0xe5a(%rip),%r14
mov    0x2e3b(%rip),%rbp
lea    0xd(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    $0xb,%esi
call   1060 <fgets@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %rax,%rbx
lea    0xe3c(%rip),%r15
lea    0xd(%rsp),%r12
xchg   %ax,%ax
mov    0x0(%r13),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    $0xb,%esi
call   1060 <fgets@plt>
mov    %r12,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
test   %rax,%rax
je     1200 <main+0x90>
mov    %rax,%r14
lea    0xe26(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rbp
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    1272 <main+0x102>
xchg   %ax,%ax
xor    %edx,%edx
div    %rbx
movzwl %r15w,%eax
xor    %ecx,%ecx
cmp    %rdx,%rax
sete   %cl
add    %rcx,%r13
cmp    $0x1,%rax
adc    $0x0,%r12
add    $0xffffffffffffffff,%rbp
je     12b0 <main+0x140>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     1290 <main+0x120>
xor    %edx,%edx
div    %rbx
mov    %rdx,%r15
jmp    1297 <main+0x127>
nop
xor    %edx,%edx
div    %ebx
mov    %edx,%r15d
xor    %eax,%eax
call   1090 <rand@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    1250 <main+0xe0>
xor    %edx,%edx
div    %ebx
jmp    1255 <main+0xe5>
test   %r13,%r13
js     12f2 <main+0x182>
cvtsi2ss %r13,%xmm0
test   %r12,%r12
jns    130d <main+0x19d>
mov    %r12,%rax
shr    %rax
and    $0x1,%r12d
or     %rax,%r12
cvtsi2ss %r12,%xmm1
addss  %xmm1,%xmm1
test   %r14,%r14
jns    1317 <main+0x1a7>
mov    %r14,%rax
shr    %rax
and    $0x1,%r14d
or     %rax,%r14
cvtsi2ss %r14,%xmm2
addss  %xmm2,%xmm2
jmp    131c <main+0x1ac>
mov    %r13,%rax
shr    %rax
and    $0x1,%r13d
or     %rax,%r13
cvtsi2ss %r13,%xmm0
addss  %xmm0,%xmm0
test   %r12,%r12
js     12bf <main+0x14f>
cvtsi2ss %r12,%xmm1
test   %r14,%r14
js     12da <main+0x16a>
cvtsi2ss %r14,%xmm2
divss  %xmm2,%xmm0
divss  %xmm2,%xmm1
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
lea    0xd49(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [659 x i8] c"+======================================================================+\0A| TestGuesser |\0A| Copyright (C) 2011 William Breathitt Gray |\0A+======================================================================+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A\0A\00"
@.str.1 = [53 x i8] c"Enter the number of choices per question (<=%lu):\0A> \00"
@ULONG_MAX = global i32 0
@stdin = global i32 0
@.str.2 = [42 x i8] c"Enter the number of questions (<=%lu):\0A> \00"
@.str.3 = [29 x i8] c"\0AAnswering %lu questions...\0A\00"
@.str.4 = [25 x i8] c"Random: %.3f\0ASame: %.3f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i16
%8 = alloca float
%9 = alloca float
%10 = alloca i64
store i32 0, i32* %1
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
store i64 1, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
store i64 1, i64* %6
store i16 0, i16* %7
store float 0.000000e+00, float* %8
store float 0.000000e+00, float* %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([659 x i8], [659 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %22, %0
%15 = load i32, i32* @ULONG_MAX
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 11, i32 %18)
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%21 = call i64 @strtoul(i8* %20, i32* null, i32 0)
store i64 %21, i64* %3
br label %22
22: ; preds = %14
%23 = load i64, i64* %3
%24 = icmp ne i64 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %14, label %26
26: ; preds = %22
br label %27
27: ; preds = %35, %26
%28 = load i32, i32* @ULONG_MAX
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %30, i32 11, i32 %31)
%33 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%34 = call i64 @strtoul(i8* %33, i32* null, i32 0)
store i64 %34, i64* %6
br label %35
35: ; preds = %27
%36 = load i64, i64* %6
%37 = icmp ne i64 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %27, label %39
39: ; preds = %35
%40 = load i64, i64* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %40)
store i64 0, i64* %10
br label %42
42: ; preds = %68, %39
%43 = load i64, i64* %10
%44 = load i64, i64* %6
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %71
46: ; preds = %42
%47 = call i64 (...) @rand()
%48 = load i64, i64* %3
%49 = urem i64 %47, %48
%50 = trunc i64 %49 to i16
store i16 %50, i16* %7
%51 = load i16, i16* %7
%52 = zext i16 %51 to i64
%53 = call i64 (...) @rand()
%54 = load i64, i64* %3
%55 = urem i64 %53, %54
%56 = icmp eq i64 %52, %55
br i1 %56, label %57, label %60
57: ; preds = %46
%58 = load i64, i64* %4
%59 = add i64 %58, 1
store i64 %59, i64* %4
br label %60
60: ; preds = %57, %46
%61 = load i16, i16* %7
%62 = zext i16 %61 to i32
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i64, i64* %5
%66 = add i64 %65, 1
store i64 %66, i64* %5
br label %67
67: ; preds = %64, %60
br label %68
68: ; preds = %67
%69 = load i64, i64* %10
%70 = add i64 %69, 1
store i64 %70, i64* %10
br label %42
71: ; preds = %42
%72 = load i64, i64* %4
%73 = uitofp i64 %72 to float
%74 = load i64, i64* %6
%75 = uitofp i64 %74 to float
%76 = fdiv float %73, %75
store float %76, float* %8
%77 = load i64, i64* %5
%78 = uitofp i64 %77 to float
%79 = load i64, i64* %6
%80 = uitofp i64 %79 to float
%81 = fdiv float %78, %80
store float %81, float* %9
%82 = load float, float* %8
%83 = fpext float %82 to double
%84 = load float, float* %9
%85 = fpext float %84 to double
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %83, double %85)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [53 x i8] c"Enter the number of choices per question (<=%lu):\0A> \00"
@ULONG_MAX = global i32 0
@stdin = global i32 0
@.str.2 = [42 x i8] c"Enter the number of questions (<=%lu):\0A> \00"
@.str.3 = [29 x i8] c"\0AAnswering %lu questions...\0A\00"
@.str.4 = [25 x i8] c"Random: %.3f\0ASame: %.3f\0A\00"
@str = [658 x i8] c"+======================================================================+\0A| TestGuesser |\0A| Copyright (C) 2011 William Breathitt Gray |\0A+======================================================================+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([658 x i8], [658 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %6, %0
%7 = load i32, i32* @ULONG_MAX
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %4, i32 11, i32 %9)
%11 = call i64 @strtoul(i8* nocapture %4, i32* null, i32 0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %6, %13
%14 = load i32, i32* @ULONG_MAX
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %4, i32 11, i32 %16)
%18 = call i64 @strtoul(i8* nocapture %4, i32* null, i32 0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %13, label %20
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %18)
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ %37, %22 ], [ 0, %20 ]
%24 = phi i64 [ %36, %22 ], [ 0, %20 ]
%25 = phi i64 [ %33, %22 ], [ 0, %20 ]
%26 = call i64 (...) @rand()
%27 = urem i64 %26, %11
%28 = and i64 %27, 65535
%29 = call i64 (...) @rand()
%30 = urem i64 %29, %11
%31 = icmp eq i64 %28, %30
%32 = zext i1 %31 to i64
%33 = add i64 %25, %32
%34 = icmp eq i64 %28, 0
%35 = zext i1 %34 to i64
%36 = add i64 %24, %35
%37 = add nuw i64 %23, 1
%38 = icmp eq i64 %37, %18
br i1 %38, label %39, label %22
39: ; preds = %22
%40 = uitofp i64 %33 to float
%41 = uitofp i64 %36 to float
%42 = uitofp i64 %18 to float
%43 = fdiv float %40, %42
%44 = fdiv float %41, %42
%45 = fpext float %43 to double
%46 = fpext float %44 to double
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %45, double %46)
ret i32 0
}