#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 RAND_MAX;
int /*<<< orphan*/ printf(char *);
int rand();
main() {
  int i;
  for (i = 0; i < 10; i++) {
    if (rand() <= RAND_MAX / 2) {
      printf("Heads\n");
    } else {
      printf("Tails\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1198 <main+0x78>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    %ecx,%eax
jg     1179 <main+0x59>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <main+0x65>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    118a <main+0x6a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <rand@plt>
mov    0x2eb5(%rip),%r14
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
lea    0xeb8(%rip),%r15
lea    0xeb7(%rip),%rbx
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
mov    %rbx,%rdi
cmovg  %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
mov    (%r14),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
cmovg  %r15,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
@.str = [7 x i8] c"Heads\0A\00"
@.str.1 = [7 x i8] c"Tails\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %16, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 10
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = call i32 (...) @rand()
%8 = load i32, i32* @RAND_MAX
%9 = sdiv i32 %8, 2
%10 = icmp sle i32 %7, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %6
%14 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
br label %16
16: ; preds = %15
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %3
19: ; preds = %3
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
@str = [6 x i8] c"Tails\00"
@str.2 = [6 x i8] c"Heads\00"
define i32 @main() {
%1 = tail call i32 (...) @rand()
%2 = load i32, i32* @RAND_MAX
%3 = sdiv i32 %2, 2
%4 = icmp sgt i32 %1, %3
%5 = select i1 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call i32 (...) @rand()
%8 = load i32, i32* @RAND_MAX
%9 = sdiv i32 %8, 2
%10 = icmp sgt i32 %7, %9
%11 = select i1 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = tail call i32 (...) @rand()
%14 = load i32, i32* @RAND_MAX
%15 = sdiv i32 %14, 2
%16 = icmp sgt i32 %13, %15
%17 = select i1 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
%19 = tail call i32 (...) @rand()
%20 = load i32, i32* @RAND_MAX
%21 = sdiv i32 %20, 2
%22 = icmp sgt i32 %19, %21
%23 = select i1 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
%25 = tail call i32 (...) @rand()
%26 = load i32, i32* @RAND_MAX
%27 = sdiv i32 %26, 2
%28 = icmp sgt i32 %25, %27
%29 = select i1 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%30 = tail call i32 @puts(i8* dereferenceable(1) %29)
%31 = tail call i32 (...) @rand()
%32 = load i32, i32* @RAND_MAX
%33 = sdiv i32 %32, 2
%34 = icmp sgt i32 %31, %33
%35 = select i1 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%36 = tail call i32 @puts(i8* dereferenceable(1) %35)
%37 = tail call i32 (...) @rand()
%38 = load i32, i32* @RAND_MAX
%39 = sdiv i32 %38, 2
%40 = icmp sgt i32 %37, %39
%41 = select i1 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%42 = tail call i32 @puts(i8* dereferenceable(1) %41)
%43 = tail call i32 (...) @rand()
%44 = load i32, i32* @RAND_MAX
%45 = sdiv i32 %44, 2
%46 = icmp sgt i32 %43, %45
%47 = select i1 %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%48 = tail call i32 @puts(i8* dereferenceable(1) %47)
%49 = tail call i32 (...) @rand()
%50 = load i32, i32* @RAND_MAX
%51 = sdiv i32 %50, 2
%52 = icmp sgt i32 %49, %51
%53 = select i1 %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%54 = tail call i32 @puts(i8* dereferenceable(1) %53)
%55 = tail call i32 (...) @rand()
%56 = load i32, i32* @RAND_MAX
%57 = sdiv i32 %56, 2
%58 = icmp sgt i32 %55, %57
%59 = select i1 %58, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0)
%60 = tail call i32 @puts(i8* dereferenceable(1) %59)
ret i32 0
}