#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 *, ...);
void fig06_07() {
  size_t answer;
  size_t rating;
  int frequency[11] = {0};
  int responses[40] = {1, 2,  6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8,
                       6, 10, 3, 8, 2, 7, 6, 5, 7, 6,  8, 6, 7, 5,
                       6, 6,  5, 6, 7, 5, 6, 4, 8, 6,  8, 10};
  for (answer = 0; answer < 40; ++answer) {
    ++frequency[responses[answer]];
  }
  printf("%s%17s\n", "Rating", "Frequency");
  for (rating = 1; rating < 11; ++rating) {
    printf("%6d%17d\n", rating, frequency[rating]);
  }
}


x86 assembly (clang, -O0):
<fig06_07>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x2c,%edx
call   1040 <memset@plt>
lea    -0xe0(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0xa0,%edx
call   1050 <memcpy@plt>
movq   $0x0,-0x8(%rbp)
cmpq   $0x28,-0x8(%rbp)
jae    119e <fig06_07+0x6e>
mov    -0x8(%rbp),%rax
movslq -0xe0(%rbp,%rax,4),%rax
ff
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116b <fig06_07+0x3b>
lea    0xefb(%rip),%rdi
lea    0xefc(%rip),%rsi
lea    0xefc(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x1,-0x10(%rbp)
cmpq   $0xb,-0x10(%rbp)
jae    11f8 <fig06_07+0xc8>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c2 <fig06_07+0x92>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig06_07>:
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x1c(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    $0x1,%eax
lea    0xece(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq -0x4(%rcx,%rax,4),%rdx
addl   $0x1,(%rsp,%rdx,4)
movslq (%rcx,%rax,4),%rdx
addl   $0x1,(%rsp,%rdx,4)
add    $0x2,%rax
cmp    $0x29,%rax
jne    1140 <fig06_07+0x30>
lea    0xf3e(%rip),%rdi
lea    0xf3f(%rip),%rsi
lea    0xf3f(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
lea    0xf37(%rip),%rbx
mov    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%edx
mov    $0x2,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    $0x3,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
mov    $0x4,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
mov    $0x5,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
mov    $0x6,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
mov    $0x7,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
mov    $0x8,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
mov    $0x9,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x28(%rsp),%edx
mov    $0xa,%esi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.fig06_07.responses = [40 x i32] [i32 1, i32 2, i32 6, i32 4, i32 8, i32 5, i32 9, i32 7, i32 8, i32 10, i32 1, i32 6, i32 3, i32 8, i32 6, i32 10, i32 3, i32 8, i32 2, i32 7, i32 6, i32 5, i32 7, i32 6, i32 8, i32 6, i32 7, i32 5, i32 6, i32 6, i32 5, i32 6, i32 7, i32 5, i32 6, i32 4, i32 8, i32 6, i32 8, i32 10]
@.str = [8 x i8] c"%s%17s\0A\00"
@.str.1 = [7 x i8] c"Rating\00"
@.str.2 = [10 x i8] c"Frequency\00"
@.str.3 = [9 x i8] c"%6d%17d\0A\00"
define void @fig06_07() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca [11 x i32]
%4 = alloca [40 x i32]
%5 = bitcast [11 x i32]* %3 to i8*
%6 = bitcast [40 x i32]* %4 to i8*
store i64 0, i64* %1
br label %7
7: ; preds = %18, %0
%8 = load i64, i64* %1
%9 = icmp ult i64 %8, 40
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = load i64, i64* %1
%12 = getelementptr inbounds [40 x i32], [40 x i32]* %4, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
br label %18
18: ; preds = %10
%19 = load i64, i64* %1
%20 = add i64 %19, 1
store i64 %20, i64* %1
br label %7
21: ; preds = %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i64 1, i64* %2
br label %23
23: ; preds = %32, %21
%24 = load i64, i64* %2
%25 = icmp ult i64 %24, 11
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i64, i64* %2
%28 = load i64, i64* %2
%29 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %27, i32 %30)
br label %32
32: ; preds = %26
%33 = load i64, i64* %2
%34 = add i64 %33, 1
store i64 %34, i64* %2
br label %23
35: ; preds = %23
ret void
}

LLVM IR (-O2):
@__const.fig06_07.responses = [40 x i32] [i32 1, i32 2, i32 6, i32 4, i32 8, i32 5, i32 9, i32 7, i32 8, i32 10, i32 1, i32 6, i32 3, i32 8, i32 6, i32 10, i32 3, i32 8, i32 2, i32 7, i32 6, i32 5, i32 7, i32 6, i32 8, i32 6, i32 7, i32 5, i32 6, i32 6, i32 5, i32 6, i32 7, i32 5, i32 6, i32 4, i32 8, i32 6, i32 8, i32 10]
@.str = [8 x i8] c"%s%17s\0A\00"
@.str.1 = [7 x i8] c"Rating\00"
@.str.2 = [10 x i8] c"Frequency\00"
@.str.3 = [9 x i8] c"%6d%17d\0A\00"
define void @fig06_07() {
%1 = alloca [11 x i32]
%2 = bitcast [11 x i32]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %18, %3 ]
%5 = getelementptr inbounds [40 x i32], [40 x i32]* @__const.fig06_07.responses, i64 0, i64 %4
%6 = load i32, i32* %5
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
store i32 %10, i32* %8
%11 = or i64 %4, 1
%12 = getelementptr inbounds [40 x i32], [40 x i32]* @__const.fig06_07.responses, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
%18 = add nuw nsw i64 %4, 2
%19 = icmp eq i64 %18, 40
br i1 %19, label %20, label %3
20: ; preds = %3
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 1, i32 %23)
%25 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 2
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 2, i32 %26)
%28 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 3
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 3, i32 %29)
%31 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 4
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 4, i32 %32)
%34 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 5
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 5, i32 %35)
%37 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 6
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 6, i32 %38)
%40 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 7
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 7, i32 %41)
%43 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 8
%44 = load i32, i32* %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 8, i32 %44)
%46 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 9
%47 = load i32, i32* %46
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 9, i32 %47)
%49 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 10
%50 = load i32, i32* %49
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 10, i32 %50)
ret void
}