#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 emperor_opens_the_door_with_lion(int, int *);
int gladiator_chooses_the_door();
scalar_t__ gladiator_gets_the_girl(int, int, int *);
int /*<<< orphan*/ place_lions_and_girl(int *);
int /*<<< orphan*/ printf(char *, int, int, double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  bool is_girl[3];
  int door_gladiator;
  int door_emperor;
  int nr_got_girl;
  int i;
  srand(time(NULL));
  nr_got_girl = 0;
  for (i = 0; i < (1 << 15); i++) {
    place_lions_and_girl(is_girl);
    door_gladiator = gladiator_chooses_the_door();
    door_emperor = emperor_opens_the_door_with_lion(door_gladiator, is_girl);
    if (gladiator_gets_the_girl(true, door_gladiator, is_girl))
      nr_got_girl++;
  }
  printf("If the gladiator retains his choice:\n"
         "    Number of steps: %d\n"
         "    Number of instances he got the girl: %d\n"
         "    Frequency: %f\n\n",
         (1 << 15), nr_got_girl, (double)nr_got_girl / (double)(1 << 15));
  nr_got_girl = 0;
  for (i = 0; i < (1 << 15); i++) {
    place_lions_and_girl(is_girl);
    door_gladiator = gladiator_chooses_the_door();
    door_emperor = emperor_opens_the_door_with_lion(door_gladiator, is_girl);
    if (gladiator_gets_the_girl(false, door_gladiator, is_girl))
      nr_got_girl++;
  }
  printf("If the gladiator changes his mind:\n"
         "    Number of steps: %d\n"
         "    Number of instances he got the girl: %d\n"
         "    Frequency: %f\n",
         (1 << 15), nr_got_girl, (double)nr_got_girl / (double)(1 << 15));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x8000,-0x20(%rbp)
jge    1203 <main+0x93>
lea    -0x10(%rbp),%rdi
call   1090 <place_lions_and_girl@plt>
mov    $0x0,%al
call   1080 <gladiator_chooses_the_door@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <emperor_opens_the_door_with_lion@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdx
mov    $0x1,%edi
call   1030 <gladiator_gets_the_girl@plt>
cmp    $0x0,%rax
je     11f0 <main+0x80>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f5 <main+0x85>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119d <main+0x2d>
mov    -0x1c(%rbp),%edx
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xded(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdea(%rip),%rdi
mov    $0x8000,%esi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x8000,-0x20(%rbp)
jge    1299 <main+0x129>
lea    -0x10(%rbp),%rdi
call   1090 <place_lions_and_girl@plt>
mov    $0x0,%al
call   1080 <gladiator_chooses_the_door@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <emperor_opens_the_door_with_lion@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdx
xor    %edi,%edi
call   1030 <gladiator_gets_the_girl@plt>
cmp    $0x0,%rax
je     1286 <main+0x116>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    128b <main+0x11b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1236 <main+0xc6>
mov    -0x1c(%rbp),%edx
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xd57(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdd1(%rip),%rdi
mov    $0x8000,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x8000,%ebx
lea    0x4(%rsp),%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <place_lions_and_girl@plt>
xor    %eax,%eax
call   1080 <gladiator_chooses_the_door@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <emperor_opens_the_door_with_lion@plt>
mov    $0x1,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <gladiator_gets_the_girl@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r12d
add    $0xffffffff,%ebx
jne    11a0 <main+0x30>
cvtsi2sd %r12d,%xmm0
mulsd  0xe1c(%rip),%xmm0
lea    0xe1d(%rip),%rdi
mov    $0x8000,%r15d
mov    $0x8000,%esi
mov    %r12d,%edx
call   1040 <printf@plt>
lea    0x4(%rsp),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1090 <place_lions_and_girl@plt>
xor    %eax,%eax
call   1080 <gladiator_chooses_the_door@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <emperor_opens_the_door_with_lion@plt>
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <gladiator_gets_the_girl@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
add    $0xffffffff,%r15d
jne    1210 <main+0xa0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xdad(%rip),%xmm0
lea    0xe2b(%rip),%rdi
mov    $0x8000,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [125 x i8] c"If the gladiator retains his choice:\0A Number of steps: %d\0A Number of instances he got the girl: %d\0A Frequency: %f\0A\0A\00"
@.str.1 = [122 x i8] c"If the gladiator changes his mind:\0A Number of steps: %d\0A Number of instances he got the girl: %d\0A Frequency: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %27, %0
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 32768
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%14 = call i32 @place_lions_and_girl(i32* %13)
%15 = call i32 (...) @gladiator_chooses_the_door()
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%18 = call i32 @emperor_opens_the_door_with_lion(i32 %16, i32* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%21 = call i64 @gladiator_gets_the_girl(i32 1, i32 %19, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %9
30: ; preds = %9
%31 = load i32, i32* %5
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = fdiv double %33, 3.276800e+04
%35 = call i32 @printf(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0), i32 32768, i32 %31, double %34)
store i32 0, i32* %5
store i32 0, i32* %6
br label %36
36: ; preds = %54, %30
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 32768
br i1 %38, label %39, label %57
39: ; preds = %36
%40 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%41 = call i32 @place_lions_and_girl(i32* %40)
%42 = call i32 (...) @gladiator_chooses_the_door()
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%45 = call i32 @emperor_opens_the_door_with_lion(i32 %43, i32* %44)
store i32 %45, i32* %4
%46 = load i32, i32* %3
%47 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%48 = call i64 @gladiator_gets_the_girl(i32 0, i32 %46, i32* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %39
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %53
53: ; preds = %50, %39
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %36
57: ; preds = %36
%58 = load i32, i32* %5
%59 = load i32, i32* %5
%60 = sitofp i32 %59 to double
%61 = fdiv double %60, 3.276800e+04
%62 = call i32 @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.1, i64 0, i64 0), i32 32768, i32 %58, double %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [125 x i8] c"If the gladiator retains his choice:\0A Number of steps: %d\0A Number of instances he got the girl: %d\0A Frequency: %f\0A\0A\00"
@.str.1 = [122 x i8] c"If the gladiator changes his mind:\0A Number of steps: %d\0A Number of instances he got the girl: %d\0A Frequency: %f\0A\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
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %16, %6 ]
%8 = phi i32 [ 0, %0 ], [ %15, %6 ]
%9 = call i32 @place_lions_and_girl(i32* %5)
%10 = call i32 (...) @gladiator_chooses_the_door()
%11 = call i32 @emperor_opens_the_door_with_lion(i32 %10, i32* %5)
%12 = call i64 @gladiator_gets_the_girl(i32 1, i32 %10, i32* %5)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %8, %14
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, 32768
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = sitofp i32 %15 to double
%20 = fmul double %19, 0x3F00000000000000
%21 = call i32 @printf(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0), i32 32768, i32 %15, double %20)
br label %22
22: ; preds = %18, %22
%23 = phi i32 [ 0, %18 ], [ %32, %22 ]
%24 = phi i32 [ 0, %18 ], [ %31, %22 ]
%25 = call i32 @place_lions_and_girl(i32* %5)
%26 = call i32 (...) @gladiator_chooses_the_door()
%27 = call i32 @emperor_opens_the_door_with_lion(i32 %26, i32* %5)
%28 = call i64 @gladiator_gets_the_girl(i32 0, i32 %26, i32* %5)
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
%31 = add nuw nsw i32 %24, %30
%32 = add nuw nsw i32 %23, 1
%33 = icmp eq i32 %32, 32768
br i1 %33, label %34, label %22
34: ; preds = %22
%35 = sitofp i32 %31 to double
%36 = fmul double %35, 0x3F00000000000000
%37 = call i32 @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str.1, i64 0, i64 0), i32 32768, i32 %31, double %36)
ret i32 0
}