#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 rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int coin, loop;
  int total_heads = 0;
  float hpercent, tpercent;
  srand((unsigned)time(NULL));
  for (loop = 0; loop <= 10000; loop++) {
    coin = rand() % 2;
    total_heads += coin;
    if (coin)
      printf("Heads\t");
    else
      printf("Tails\t");
  }
  hpercent = (float)total_heads / 10000 * 100;
  tpercent = 100.0 - hpercent;
  printf("Total Flips: %d\nHeads: %.2f\nTails: %.2f\n", 10000, hpercent,
         tpercent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jg     11d3 <main+0x93>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11b2 <main+0x72>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c0 <main+0x80>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <main+0x85>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116d <main+0x2d>
cvtsi2ssl -0x10(%rbp),%xmm0
movss  0xe2c(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe1c(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdfa(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdf2(%rip),%rdi
mov    $0x2710,%esi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x2711,%ebp
lea    0xeac(%rip),%r14
lea    0xe9e(%rip),%r15
jmp    117e <main+0x3e>
nopl   0x0(%rax)
add    %eax,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffff,%ebp
je     119b <main+0x5b>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
mov    %r14,%rdi
sub    %ecx,%eax
je     1170 <main+0x30>
mov    %r15,%rdi
jmp    1170 <main+0x30>
cvtsi2ss %ebx,%xmm1
divss  0xe59(%rip),%xmm1
movss  0xe55(%rip),%xmm2
mulss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm0
subss  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
lea    0xe4d(%rip),%rdi
mov    $0x2710,%esi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Heads\09\00"
@.str.1 = [7 x i8] c"Tails\09\00"
@.str.2 = [41 x i8] c"Total Flips: %d\0AHeads: %.2f\0ATails: %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store i32 0, i32* %4
%7 = call i64 @time(i32* null)
%8 = trunc i64 %7 to i32
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %26, %0
%11 = load i32, i32* %3
%12 = icmp sle i32 %11, 10000
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 2
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = add nsw i32 %17, %16
store i32 %18, i32* %4
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %25
23: ; preds = %13
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %10
29: ; preds = %10
%30 = load i32, i32* %4
%31 = sitofp i32 %30 to float
%32 = fdiv float %31, 1.000000e+04
%33 = fmul float %32, 1.000000e+02
store float %33, float* %5
%34 = load float, float* %5
%35 = fpext float %34 to double
%36 = fsub double 1.000000e+02, %35
%37 = fptrunc double %36 to float
store float %37, float* %6
%38 = load float, float* %5
%39 = fpext float %38 to double
%40 = load float, float* %6
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 10000, double %39, double %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"Heads\09\00"
@.str.1 = [7 x i8] c"Tails\09\00"
@.str.2 = [41 x i8] c"Total Flips: %d\0AHeads: %.2f\0ATails: %.2f\0A\00"
define i32 @main() {
%1 = tail call i64 @time(i32* null)
%2 = trunc i64 %1 to i32
%3 = tail call i32 @srand(i32 %2)
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %13, %4 ]
%6 = phi i32 [ 0, %0 ], [ %9, %4 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 2
%9 = add nsw i32 %8, %6
%10 = icmp eq i32 %8, 0
%11 = select i1 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %11)
%13 = add nuw nsw i32 %5, 1
%14 = icmp eq i32 %13, 10001
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = sitofp i32 %9 to float
%17 = fdiv float %16, 1.000000e+04
%18 = fmul float %17, 1.000000e+02
%19 = fpext float %18 to double
%20 = fsub float 1.000000e+02, %18
%21 = fpext float %20 to double
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 10000, double %19, double %21)
ret i32 0
}