#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 */

/* Variables and functions */
int /*<<< orphan*/ initializeDoors(int *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ report(int, int, int *);
int revealDoor(int, int *);
int /*<<< orphan*/ srand(unsigned int);
int swapDoors(int, int, int *);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  int x, chosenDoor, revealedDoor, nonSwapCount = 0, swapCount = 0;
  int doors[3];
  unsigned int iseed = (unsigned int)time(NULL);
  srand(iseed);
  printf("Non-Swap Results\n");
  for (x = 0; x < 100; x++) {
    initializeDoors(doors);
    chosenDoor = rand() % 3;
    revealedDoor = revealDoor(chosenDoor, doors);
    if (doors[chosenDoor] == 1) {
      ++nonSwapCount;
    }
    report(chosenDoor, revealedDoor, doors);
  }
  printf("-----------------------------------------\n");
  printf("Swap Results\n");
  for (x = 0; x < 100; x++) {
    initializeDoors(doors);
    chosenDoor = rand() % 3;
    revealedDoor = revealDoor(chosenDoor, doors);
    chosenDoor = swapDoors(chosenDoor, revealedDoor, doors);
    if (doors[chosenDoor] == 1) {
      ++swapCount;
    }
    report(chosenDoor, revealedDoor, doors);
  }
  printf("Swap Win Average - %.0f%%\n", ((double)swapCount / 100) * 100);
  printf("Non-Swap Win Average - %.0f%%\n", ((double)nonSwapCount / 100) * 100);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <srand@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    122f <main+0xaf>
lea    -0x24(%rbp),%rdi
call   1090 <initializeDoors@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1050 <revealDoor@plt>
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rax
cmpl   $0x1,-0x24(%rbp,%rax,4)
jne    1212 <main+0x92>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x24(%rbp),%rdx
call   1080 <report@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c6 <main+0x46>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    12cd <main+0x14d>
lea    -0x24(%rbp),%rdi
call   1090 <initializeDoors@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1050 <revealDoor@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x24(%rbp),%rdx
call   1070 <swapDoors@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmpl   $0x1,-0x24(%rbp,%rax,4)
jne    12b0 <main+0x130>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
lea    -0x24(%rbp),%rdx
call   1080 <report@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1252 <main+0xd2>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xd26(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xd1a(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xd58(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xcfb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xcef(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xd29(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%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    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%ebp
lea    0xc(%rsp),%r14
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   10a0 <initializeDoors@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <revealDoor@plt>
movslq %ebx,%rdi
xor    %ecx,%ecx
cmpl   $0x1,0xc(%rsp,%rdi,4)
sete   %cl
add    %ecx,%r15d
mov    %eax,%esi
mov    %r14,%rdx
call   1090 <report@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x40>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%r12d
lea    0xc(%rsp),%r14
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10a0 <initializeDoors@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <revealDoor@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1080 <swapDoors@plt>
movslq %eax,%rdi
xor    %eax,%eax
cmpl   $0x1,0xc(%rsp,%rdi,4)
sete   %al
add    %eax,%r13d
mov    %ebp,%esi
mov    %r14,%rdx
call   1090 <report@plt>
add    $0xffffffff,%r12d
jne    1250 <main+0xc0>
cvtsi2sd %r13d,%xmm0
movsd  0xd40(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
lea    0xd3d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  0xd1a(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
lea    0xd13(%rip),%rdi
mov    $0x1,%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 = [18 x i8] c"Non-Swap Results\0A\00"
@.str.1 = [43 x i8] c"-----------------------------------------\0A\00"
@.str.2 = [14 x i8] c"Swap Results\0A\00"
@.str.3 = [27 x i8] c"Swap Win Average - %.0f%%\0A\00"
@.str.4 = [31 x i8] c"Non-Swap Win Average - %.0f%%\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3 x i32]
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = call i32 @srand(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %14
14: ; preds = %38, %0
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 100
br i1 %16, label %17, label %41
17: ; preds = %14
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%19 = call i32 @initializeDoors(i32* %18)
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 3
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%24 = call i32 @revealDoor(i32 %22, i32* %23)
store i32 %24, i32* %4
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %17
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30, %17
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%37 = call i32 @report(i32 %34, i32 %35, i32* %36)
br label %38
38: ; preds = %33
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %14
41: ; preds = %14
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %44
44: ; preds = %72, %41
%45 = load i32, i32* %2
%46 = icmp slt i32 %45, 100
br i1 %46, label %47, label %75
47: ; preds = %44
%48 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%49 = call i32 @initializeDoors(i32* %48)
%50 = call i32 (...) @rand()
%51 = srem i32 %50, 3
store i32 %51, i32* %3
%52 = load i32, i32* %3
%53 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%54 = call i32 @revealDoor(i32 %52, i32* %53)
store i32 %54, i32* %4
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%58 = call i32 @swapDoors(i32 %55, i32 %56, i32* %57)
store i32 %58, i32* %3
%59 = load i32, i32* %3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %67
64: ; preds = %47
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %67
67: ; preds = %64, %47
%68 = load i32, i32* %3
%69 = load i32, i32* %4
%70 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%71 = call i32 @report(i32 %68, i32 %69, i32* %70)
br label %72
72: ; preds = %67
%73 = load i32, i32* %2
%74 = add nsw i32 %73, 1
store i32 %74, i32* %2
br label %44
75: ; preds = %44
%76 = load i32, i32* %6
%77 = sitofp i32 %76 to double
%78 = fdiv double %77, 1.000000e+02
%79 = fmul double %78, 1.000000e+02
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %79)
%81 = load i32, i32* %5
%82 = sitofp i32 %81 to double
%83 = fdiv double %82, 1.000000e+02
%84 = fmul double %83, 1.000000e+02
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), double %84)
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [27 x i8] c"Swap Win Average - %.0f%%\0A\00"
@.str.4 = [31 x i8] c"Non-Swap Win Average - %.0f%%\0A\00"
@str = [17 x i8] c"Non-Swap Results\00"
@str.5 = [42 x i8] c"-----------------------------------------\00"
@str.6 = [13 x i8] c"Swap Results\00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %22, %8 ]
%10 = phi i32 [ 0, %0 ], [ %20, %8 ]
%11 = call i32 @initializeDoors(i32* %7)
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 3
%14 = call i32 @revealDoor(i32 %13, i32* %7)
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 1
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %10, %19
%21 = call i32 @report(i32 %13, i32 %14, i32* %7)
%22 = add nuw nsw i32 %9, 1
%23 = icmp eq i32 %22, 100
br i1 %23, label %24, label %8
24: ; preds = %8
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %27
27: ; preds = %24, %27
%28 = phi i32 [ 0, %24 ], [ %42, %27 ]
%29 = phi i32 [ 0, %24 ], [ %40, %27 ]
%30 = call i32 @initializeDoors(i32* %7)
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 3
%33 = call i32 @revealDoor(i32 %32, i32* %7)
%34 = call i32 @swapDoors(i32 %32, i32 %33, i32* %7)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 1
%39 = zext i1 %38 to i32
%40 = add nuw nsw i32 %29, %39
%41 = call i32 @report(i32 %34, i32 %33, i32* %7)
%42 = add nuw nsw i32 %28, 1
%43 = icmp eq i32 %42, 100
br i1 %43, label %44, label %27
44: ; preds = %27
%45 = sitofp i32 %40 to double
%46 = fdiv double %45, 1.000000e+02
%47 = fmul double %46, 1.000000e+02
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %47)
%49 = sitofp i32 %20 to double
%50 = fdiv double %49, 1.000000e+02
%51 = fmul double %50, 1.000000e+02
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), double %51)
ret i32 0
}