#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*/ printf(char *, int, unsigned int, float);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  unsigned i, j, k, choice, winsbyswitch = 0, door[3];
  srand(time(NULL));
  for (i = 0; i < 1000000; i++) {
    door[0] = (!(rand() % 2)) ? 1 : 0;
    if (door[0])
      door[1] = door[2] = 0;
    else {
      door[1] = (!(rand() % 2)) ? 1 : 0;
      door[2] = (!door[1]) ? 1 : 0;
    }
    choice = rand() % 3;
    if (((!(door[((choice + 1) % 3)])) && (door[((choice + 2) % 3)])) ||
        (!(door[((choice + 2) % 3)]) && (door[((choice + 1) % 3)])))
      winsbyswitch++;
  }
  printf("\nAfter %u games, I won %u by switching.  That is %f%%. ", 1000000,
         winsbyswitch, (float)winsbyswitch * 100.0 / (float)i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jae    129f <main+0x15f>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
setne  %dl
xor    $0xff,%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11bf <main+0x7f>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
jmp    1201 <main+0xc1>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
setne  %dl
xor    $0xff,%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setne  %dl
xor    $0xff,%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
cmpl   $0x0,-0x24(%rbp,%rax,4)
jne    124b <main+0x10b>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
cmpl   $0x0,-0x24(%rbp,%rax,4)
jne    1283 <main+0x143>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
cmpl   $0x0,-0x24(%rbp,%rax,4)
jne    128c <main+0x14c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
cmpl   $0x0,-0x24(%rbp,%rax,4)
je     128c <main+0x14c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1291 <main+0x151>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116d <main+0x2d>
mov    -0x18(%rbp),%eax
mov    %eax,%edx
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd4b(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%eax
cvtsi2ss %rax,%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xd34(%rip),%rdi
mov    $0xf4240,%esi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0xf4240,%ebp
mov    $0xaaaaaaab,%r14d
xor    %ebx,%ebx
jmp    1180 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
je     1177 <main+0x37>
add    $0x1,%ebx
add    $0xffffffff,%ebp
je     1235 <main+0xf5>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ecx
not    %ecx
and    $0x1,%ecx
mov    %ecx,0x4(%rsp)
test   $0x1,%al
jne    11b0 <main+0x70>
movq   $0x0,0x8(%rsp)
jmp    11c7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
and    $0x1,%eax
mov    %eax,%ecx
xor    $0x1,%ecx
mov    %ecx,0x8(%rsp)
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%edx
sub    %ecx,%edx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %rax,%rcx
imul   %r14,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
add    $0x2,%dl
movzbl %dl,%ecx
imul   $0xab,%ecx,%edx
shr    $0x9,%edx
lea    (%rdx,%rdx,2),%edx
sub    %dl,%cl
cmpl   $0x0,0x4(%rsp,%rax,4)
movzbl %cl,%eax
mov    0x4(%rsp,%rax,4),%eax
je     1170 <main+0x30>
test   %eax,%eax
jne    1177 <main+0x37>
jmp    1174 <main+0x34>
mov    %ebx,%eax
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xdb8(%rip),%xmm0
divsd  0xdb8(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xdb5(%rip),%rdi
mov    $0xf4240,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"\0AAfter %u games, I won %u by switching. That is %f%%. \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]
store i32 0, i32* %1
store i32 0, i32* %6
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %2
br label %10
10: ; preds = %80, %0
%11 = load i32, i32* %2
%12 = icmp ult i32 %11, 1000000
br i1 %12, label %13, label %83
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 2
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 1, i32 0
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
store i32 %19, i32* %20
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
store i32 0, i32* %25
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
store i32 0, i32* %26
br label %42
27: ; preds = %13
%28 = call i32 (...) @rand()
%29 = srem i32 %28, 2
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 1, i32 0
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
store i32 %33, i32* %34
%35 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 1
%36 = load i32, i32* %35
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 1, i32 0
%41 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 2
store i32 %40, i32* %41
br label %42
42: ; preds = %27, %24
%43 = call i32 (...) @rand()
%44 = srem i32 %43, 3
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = add i32 %45, 1
%47 = urem i32 %46, 3
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %60, label %52
52: ; preds = %42
%53 = load i32, i32* %5
%54 = add i32 %53, 2
%55 = urem i32 %54, 3
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = icmp ne i32 %58, 0
br i1 %59, label %76, label %60
60: ; preds = %52, %42
%61 = load i32, i32* %5
%62 = add i32 %61, 2
%63 = urem i32 %62, 3
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = icmp ne i32 %66, 0
br i1 %67, label %79, label %68
68: ; preds = %60
%69 = load i32, i32* %5
%70 = add i32 %69, 1
%71 = urem i32 %70, 3
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %68, %52
%77 = load i32, i32* %6
%78 = add i32 %77, 1
store i32 %78, i32* %6
br label %79
79: ; preds = %76, %68, %60
br label %80
80: ; preds = %79
%81 = load i32, i32* %2
%82 = add i32 %81, 1
store i32 %82, i32* %2
br label %10
83: ; preds = %10
%84 = load i32, i32* %6
%85 = load i32, i32* %6
%86 = uitofp i32 %85 to float
%87 = fpext float %86 to double
%88 = fmul double %87, 1.000000e+02
%89 = load i32, i32* %2
%90 = uitofp i32 %89 to float
%91 = fpext float %90 to double
%92 = fdiv double %88, %91
%93 = fptrunc double %92 to float
%94 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 1000000, i32 %84, float %93)
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
@.str = [56 x i8] c"\0AAfter %u games, I won %u by switching. That is %f%%. \00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
br label %8
8: ; preds = %0, %40
%9 = phi i32 [ 0, %0 ], [ %41, %40 ]
%10 = phi i32 [ 0, %0 ], [ %42, %40 ]
%11 = tail call i32 (...) @rand()
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
%14 = xor i32 %12, 1
store i32 %14, i32* %5
br i1 %13, label %15, label %16
15: ; preds = %8
store i32 0, i32* %7
store i32 0, i32* %6
br label %20
16: ; preds = %8
%17 = tail call i32 (...) @rand()
%18 = and i32 %17, 1
%19 = xor i32 %18, 1
store i32 %19, i32* %6
store i32 %18, i32* %7
br label %20
20: ; preds = %16, %15
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 3
%23 = add nsw i32 %22, 1
%24 = urem i32 %23, 3
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 0
%29 = trunc i32 %22 to i8
%30 = add nsw i8 %29, 2
%31 = urem i8 %30, 3
%32 = zext i8 %31 to i64
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 0
br i1 %28, label %36, label %37
36: ; preds = %20
br i1 %35, label %40, label %38
37: ; preds = %20
br i1 %35, label %38, label %40
38: ; preds = %37, %36
%39 = add i32 %9, 1
br label %40
40: ; preds = %36, %37, %38
%41 = phi i32 [ %39, %38 ], [ %9, %37 ], [ %9, %36 ]
%42 = add nuw nsw i32 %10, 1
%43 = icmp eq i32 %42, 1000000
br i1 %43, label %44, label %8
44: ; preds = %40
%45 = uitofp i32 %41 to float
%46 = fpext float %45 to double
%47 = fmul double %46, 1.000000e+02
%48 = fdiv double %47, 1.000000e+06
%49 = fptrunc double %48 to float
%50 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 1000000, i32 %41, float %49)
ret i32 0
}