#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();
void fig05_12() {
  unsigned int frequency1 = 0;
  unsigned int frequency2 = 0;
  unsigned int frequency3 = 0;
  unsigned int frequency4 = 0;
  unsigned int frequency5 = 0;
  unsigned int frequency6 = 0;
  unsigned int roll;
  int face;
  for (roll = 1; roll <= 6000000; ++roll) {
    face = 1 + rand() % 6;
    switch (face) {
    case 1:
      ++frequency1;
      break;
    case 2:
      ++frequency2;
      break;
    case 3:
      ++frequency3;
      break;
    case 4:
      ++frequency4;
      break;
    case 5:
      ++frequency5;
      break;
    case 6:
      ++frequency6;
      break;
    }
  }
  printf("%s%13s\n", "Face", "Frequency");
  printf("   1%13u\n", frequency1);
  printf("   2%13u\n", frequency2);
  printf("   3%13u\n", frequency3);
  printf("   4%13u\n", frequency4);
  printf("   5%13u\n", frequency5);
  printf("   6%13u\n", frequency6);
}


x86 assembly (clang, -O0):
<fig05_12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x5b8d80,-0x1c(%rbp)
ja     1225 <fig05_12+0x105>
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ecx
movslq %ecx,%rax
imul   $0x2aaaaaab,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x20,%rdx
add    %eax,%edx
add    %edx,%edx
mov    %edx,%eax
lea    (%rax,%rax,2),%edx
mov    %ecx,%eax
neg    %edx
mov    %edx,%ecx
lea    0x1(%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     1212 <fig05_12+0xf2>
mov    -0x28(%rbp),%rax
lea    0xe46(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1212 <fig05_12+0xf2>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1212 <fig05_12+0xf2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1212 <fig05_12+0xf2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1212 <fig05_12+0xf2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1212 <fig05_12+0xf2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <fig05_12+0xf7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <fig05_12+0x39>
lea    0xdec(%rip),%rdi
lea    0xded(%rip),%rsi
lea    0xdeb(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig05_12>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x5b8d80,%r14d
lea    0xec8(%rip),%r15
xor    %ebp,%ebp
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    1166 <fig05_12+0x46>
addl   $0x1,0x4(%rsp)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r14d
je     11b4 <fig05_12+0x94>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x5,%eax
ja     1160 <fig05_12+0x40>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
add    $0x1,%ebp
jmp    1160 <fig05_12+0x40>
add    $0x1,%ebx
jmp    1160 <fig05_12+0x40>
add    $0x1,%r13d
jmp    1160 <fig05_12+0x40>
add    $0x1,%r12d
jmp    1160 <fig05_12+0x40>
addl   $0x1,(%rsp)
jmp    1160 <fig05_12+0x40>
lea    0xe5d(%rip),%rdi
lea    0xe5e(%rip),%rsi
lea    0xe5c(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe58(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe52(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe45(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    (%rsp),%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe37(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%s%13s\0A\00"
@.str.1 = [5 x i8] c"Face\00"
@.str.2 = [10 x i8] c"Frequency\00"
@.str.3 = [10 x i8] c" 1%13u\0A\00"
@.str.4 = [10 x i8] c" 2%13u\0A\00"
@.str.5 = [10 x i8] c" 3%13u\0A\00"
@.str.6 = [10 x i8] c" 4%13u\0A\00"
@.str.7 = [10 x i8] c" 5%13u\0A\00"
@.str.8 = [10 x i8] c" 6%13u\0A\00"
define void @fig05_12() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 1, i32* %7
br label %9
9: ; preds = %36, %0
%10 = load i32, i32* %7
%11 = icmp ule i32 %10, 6000000
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 6
%15 = add nsw i32 1, %14
store i32 %15, i32* %8
%16 = load i32, i32* %8
switch i32 %16, label %35 [
i32 1, label %17
i32 2, label %20
i32 3, label %23
i32 4, label %26
i32 5, label %29
i32 6, label %32
]
17: ; preds = %12
%18 = load i32, i32* %1
%19 = add i32 %18, 1
store i32 %19, i32* %1
br label %35
20: ; preds = %12
%21 = load i32, i32* %2
%22 = add i32 %21, 1
store i32 %22, i32* %2
br label %35
23: ; preds = %12
%24 = load i32, i32* %3
%25 = add i32 %24, 1
store i32 %25, i32* %3
br label %35
26: ; preds = %12
%27 = load i32, i32* %4
%28 = add i32 %27, 1
store i32 %28, i32* %4
br label %35
29: ; preds = %12
%30 = load i32, i32* %5
%31 = add i32 %30, 1
store i32 %31, i32* %5
br label %35
32: ; preds = %12
%33 = load i32, i32* %6
%34 = add i32 %33, 1
store i32 %34, i32* %6
br label %35
35: ; preds = %12, %32, %29, %26, %23, %20, %17
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add i32 %37, 1
store i32 %38, i32* %7
br label %9
39: ; preds = %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %1
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %3
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %51)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s%13s\0A\00"
@.str.1 = [5 x i8] c"Face\00"
@.str.2 = [10 x i8] c"Frequency\00"
@.str.3 = [10 x i8] c" 1%13u\0A\00"
@.str.4 = [10 x i8] c" 2%13u\0A\00"
@.str.5 = [10 x i8] c" 3%13u\0A\00"
@.str.6 = [10 x i8] c" 4%13u\0A\00"
@.str.7 = [10 x i8] c" 5%13u\0A\00"
@.str.8 = [10 x i8] c" 6%13u\0A\00"
define void @fig05_12() {
br label %1
1: ; preds = %0, %23
%2 = phi i32 [ 0, %0 ], [ %29, %23 ]
%3 = phi i32 [ 1, %0 ], [ %30, %23 ]
%4 = phi i32 [ 0, %0 ], [ %28, %23 ]
%5 = phi i32 [ 0, %0 ], [ %27, %23 ]
%6 = phi i32 [ 0, %0 ], [ %26, %23 ]
%7 = phi i32 [ 0, %0 ], [ %25, %23 ]
%8 = phi i32 [ 0, %0 ], [ %24, %23 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 6
switch i32 %10, label %23 [
i32 0, label %11
i32 1, label %13
i32 2, label %15
i32 3, label %17
i32 4, label %19
i32 5, label %21
]
11: ; preds = %1
%12 = add i32 %2, 1
br label %23
13: ; preds = %1
%14 = add i32 %8, 1
br label %23
15: ; preds = %1
%16 = add i32 %7, 1
br label %23
17: ; preds = %1
%18 = add i32 %6, 1
br label %23
19: ; preds = %1
%20 = add i32 %5, 1
br label %23
21: ; preds = %1
%22 = add i32 %4, 1
br label %23
23: ; preds = %11, %13, %15, %17, %19, %21, %1
%24 = phi i32 [ %8, %1 ], [ %8, %21 ], [ %8, %19 ], [ %8, %17 ], [ %8, %15 ], [ %14, %13 ], [ %8, %11 ]
%25 = phi i32 [ %7, %1 ], [ %7, %21 ], [ %7, %19 ], [ %7, %17 ], [ %16, %15 ], [ %7, %13 ], [ %7, %11 ]
%26 = phi i32 [ %6, %1 ], [ %6, %21 ], [ %6, %19 ], [ %18, %17 ], [ %6, %15 ], [ %6, %13 ], [ %6, %11 ]
%27 = phi i32 [ %5, %1 ], [ %5, %21 ], [ %20, %19 ], [ %5, %17 ], [ %5, %15 ], [ %5, %13 ], [ %5, %11 ]
%28 = phi i32 [ %4, %1 ], [ %22, %21 ], [ %4, %19 ], [ %4, %17 ], [ %4, %15 ], [ %4, %13 ], [ %4, %11 ]
%29 = phi i32 [ %2, %1 ], [ %2, %21 ], [ %2, %19 ], [ %2, %17 ], [ %2, %15 ], [ %2, %13 ], [ %12, %11 ]
%30 = add nuw nsw i32 %3, 1
%31 = icmp eq i32 %30, 6000001
br i1 %31, label %32, label %1
32: ; preds = %23
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %28)
ret void
}