#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 */
scalar_t__ changeiter();
int /*<<< orphan*/ printf(char *, double);
scalar_t__ stayiter();
void montyhall(int elements) {
  double change = 0;
  double stay = 0;
  int i;
  for (i = 1; i <= elements; ++i)
    change += changeiter();
  for (i = 1; i <= elements; ++i)
    stay += stayiter();
  change = change / elements * 100;
  stay = stay / elements * 100;
  printf("Change Accuracy: %.5f%%\n", change);
  printf("Stay Accuracy: %.5f%%\n", stay);
}


x86 assembly (clang, -O0):
<montyhall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1182 <montyhall+0x52>
mov    $0x0,%al
call   1040 <changeiter@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <montyhall+0x22>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11b9 <montyhall+0x89>
mov    $0x0,%al
call   1050 <stayiter@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <montyhall+0x59>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe31(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe12(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe05(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<montyhall>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
xorpd  %xmm0,%xmm0
test   %edi,%edi
jle    11bc <montyhall+0x8c>
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <changeiter@plt>
movsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
add    $0xffffffff,%ebp
jne    1150 <montyhall+0x20>
test   %ebx,%ebx
jle    11bc <montyhall+0x8c>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm3,%xmm3
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm3,0x8(%rsp)
xor    %eax,%eax
call   1050 <stayiter@plt>
movsd  0x8(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm3
add    $0xffffffff,%ebp
jne    1190 <montyhall+0x60>
movsd  0x10(%rsp),%xmm0
jmp    11c0 <montyhall+0x90>
xorpd  %xmm3,%xmm3
cvtsi2sd %ebx,%xmm2
divsd  %xmm2,%xmm0
movsd  0xe30(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rsp)
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
lea    0xe2c(%rip),%rdi
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Change Accuracy: %.5f%%\0A\00"
@.str.1 = [23 x i8] c"Stay Accuracy: %.5f%%\0A\00"
define void @montyhall(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 %0, i32* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store i32 1, i32* %5
br label %6
6: ; preds = %15, %1
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = call i64 (...) @changeiter()
%12 = sitofp i64 %11 to double
%13 = load double, double* %3
%14 = fadd double %13, %12
store double %14, double* %3
br label %15
15: ; preds = %10
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
br label %6
18: ; preds = %6
store i32 1, i32* %5
br label %19
19: ; preds = %28, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = call i64 (...) @stayiter()
%25 = sitofp i64 %24 to double
%26 = load double, double* %4
%27 = fadd double %26, %25
store double %27, double* %4
br label %28
28: ; preds = %23
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
%32 = load double, double* %3
%33 = load i32, i32* %2
%34 = sitofp i32 %33 to double
%35 = fdiv double %32, %34
%36 = fmul double %35, 1.000000e+02
store double %36, double* %3
%37 = load double, double* %4
%38 = load i32, i32* %2
%39 = sitofp i32 %38 to double
%40 = fdiv double %37, %39
%41 = fmul double %40, 1.000000e+02
store double %41, double* %4
%42 = load double, double* %3
%43 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %42)
%44 = load double, double* %4
%45 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %44)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Change Accuracy: %.5f%%\0A\00"
@.str.1 = [23 x i8] c"Stay Accuracy: %.5f%%\0A\00"
define void @montyhall(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %20, label %4
3: ; preds = %4
br i1 %2, label %20, label %12
4: ; preds = %1, %4
%5 = phi i32 [ %10, %4 ], [ 1, %1 ]
%6 = phi double [ %9, %4 ], [ 0.000000e+00, %1 ]
%7 = tail call i64 (...) @changeiter()
%8 = sitofp i64 %7 to double
%9 = fadd double %6, %8
%10 = add nuw i32 %5, 1
%11 = icmp eq i32 %5, %0
br i1 %11, label %3, label %4
12: ; preds = %3, %12
%13 = phi i32 [ %18, %12 ], [ 1, %3 ]
%14 = phi double [ %17, %12 ], [ 0.000000e+00, %3 ]
%15 = tail call i64 (...) @stayiter()
%16 = sitofp i64 %15 to double
%17 = fadd double %14, %16
%18 = add nuw i32 %13, 1
%19 = icmp eq i32 %13, %0
br i1 %19, label %20, label %12
20: ; preds = %12, %1, %3
%21 = phi double [ %9, %3 ], [ 0.000000e+00, %1 ], [ %9, %12 ]
%22 = phi double [ 0.000000e+00, %3 ], [ 0.000000e+00, %1 ], [ %17, %12 ]
%23 = sitofp i32 %0 to double
%24 = fdiv double %21, %23
%25 = fmul double %24, 1.000000e+02
%26 = fdiv double %22, %23
%27 = fmul double %26, 1.000000e+02
%28 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %25)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %27)
ret void
}