#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 numar, flip;
  int heads = 0;
  int tails = 0;
  float tailsp;
  float headsp;
  srand((unsigned)time(NULL));
  printf("Let's see how the coin flips .. \n\n");
  for (numar = 0; numar < 1000; numar++) {
    flip = rand() % 2;
    if (flip)
      printf("Heads\t");
    else
      printf("Tails\t");
    heads += flip;
    tails = 1000 - heads;
  }
  printf("\n\n /There are %d heads", heads);
  printf("\n /There are %d tails", tails);
  headsp = (float)heads / 1000 * 100.0;
  tailsp = 100.0 - headsp;
  printf("\n\nThe results just came in...\n\tAre you curious..?\n\n");
  printf("Heads percentage = %.2f\n", headsp);
  printf("Tails percent = %.2f\n", tailsp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11ee <main+0xae>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11be <main+0x7e>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cc <main+0x8c>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x3e8,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1182 <main+0x42>
mov    -0x10(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cvtsi2ssl -0x10(%rbp),%xmm0
movss  0xdeb(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdd3(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdb5(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2a(%rip),%rdi
mov    $0x1,%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   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3e8,%ebx
lea    0xe8a(%rip),%r15
lea    0xe7c(%rip),%r12
jmp    119f <main+0x4f>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <printf@plt>
add    %ebp,%r14d
add    $0xffffffff,%ebx
je     11bc <main+0x6c>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
shr    $0x1f,%eax
add    %ebp,%eax
and    $0xfffffffe,%eax
mov    %r15,%rdi
sub    %eax,%ebp
je     1190 <main+0x40>
mov    %r12,%rdi
jmp    1190 <main+0x40>
mov    $0x3e8,%ebp
sub    %r14d,%ebp
lea    0xe4b(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe51(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cvtsi2ss %r14d,%xmm0
divss  0xe0e(%rip),%xmm0
movss  0xe0a(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
subss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1e(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe19(%rip),%rdi
mov    $0x1,%al
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 = [35 x i8] c"Let's see how the coin flips .. \0A\0A\00"
@.str.1 = [7 x i8] c"Heads\09\00"
@.str.2 = [7 x i8] c"Tails\09\00"
@.str.3 = [23 x i8] c"\0A\0A /There are %d heads\00"
@.str.4 = [22 x i8] c"\0A /There are %d tails\00"
@.str.5 = [52 x i8] c"\0A\0AThe results just came in...\0A\09Are you curious..?\0A\0A\00"
@.str.6 = [25 x i8] c"Heads percentage = %.2f\0A\00"
@.str.7 = [22 x i8] c"Tails percent = %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
%8 = call i64 @time(i32* null)
%9 = trunc i64 %8 to i32
%10 = call i32 @srand(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %12
12: ; preds = %30, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 2
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = add nsw i32 %26, %25
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = sub nsw i32 1000, %28
store i32 %29, i32* %5
br label %30
30: ; preds = %24
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %12
33: ; preds = %12
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %4
%39 = sitofp i32 %38 to float
%40 = fdiv float %39, 1.000000e+03
%41 = fpext float %40 to double
%42 = fmul double %41, 1.000000e+02
%43 = fptrunc double %42 to float
store float %43, float* %7
%44 = load float, float* %7
%45 = fpext float %44 to double
%46 = fsub double 1.000000e+02, %45
%47 = fptrunc double %46 to float
store float %47, float* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
%49 = load float, float* %7
%50 = fpext float %49 to double
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), double %50)
%52 = load float, float* %6
%53 = fpext float %52 to double
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), double %53)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"Heads\09\00"
@.str.2 = [7 x i8] c"Tails\09\00"
@.str.3 = [23 x i8] c"\0A\0A /There are %d heads\00"
@.str.4 = [22 x i8] c"\0A /There are %d tails\00"
@.str.6 = [25 x i8] c"Heads percentage = %.2f\0A\00"
@.str.7 = [22 x i8] c"Tails percent = %.2f\0A\00"
@str = [34 x i8] c"Let's see how the coin flips .. \0A\00"
@str.8 = [51 x i8] c"\0A\0AThe results just came in...\0A\09Are you curious..?\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)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %14, %5 ]
%7 = phi i32 [ 0, %0 ], [ %13, %5 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 2
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %11)
%13 = add nsw i32 %9, %7
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 1000
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = sub nsw i32 1000, %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%20 = sitofp i32 %13 to float
%21 = fdiv float %20, 1.000000e+03
%22 = fmul float %21, 1.000000e+02
%23 = fpext float %22 to double
%24 = fsub float 1.000000e+02, %22
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.8, i64 0, i64 0))
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), double %23)
%27 = fpext float %24 to double
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), double %27)
ret i32 0
}