#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 /*<<< orphan*/ puts(char *);
void fig06_08() {
  int n[10] = {19, 3, 15, 7, 11, 9, 13, 5, 17, 1};
  size_t i;
  int j;
  printf("%s%13s%17s\n", "Element", "Value", "Histogram");
  for (i = 0; i < 10; ++i) {
    printf("%7u%13d        ", i, n[i]);
    for (j = 1; j <= n[i]; ++j) {
      printf("%c", '*');
    }
    puts("");
  }
}


x86 assembly (clang, -O0):
<fig06_08>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    0xed4(%rip),%rdi
lea    0xed9(%rip),%rsi
lea    0xeda(%rip),%rdx
lea    0xed9(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0xa,-0x38(%rbp)
jae    11f3 <fig06_08+0xc3>
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x38(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jg     11d6 <fig06_08+0xa6>
lea    0xea0(%rip),%rdi
mov    $0x2a,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a4 <fig06_08+0x74>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1178 <fig06_08+0x48>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig06_08>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xef9(%rip),%rdi
lea    0xefe(%rip),%rsi
lea    0xeff(%rip),%rdx
lea    0xefe(%rip),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%r15
lea    0xef3(%rip),%r14
mov    $0x1,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebp
cmovl  %r12d,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1190 <fig06_08+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    $0xa,%rbx
jne    1170 <fig06_08+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.fig06_08.n = [10 x i32] [i32 19, i32 3, i32 15, i32 7, i32 11, i32 9, i32 13, i32 5, i32 17, i32 1]
@.str = [12 x i8] c"%s%13s%17s\0A\00"
@.str.1 = [8 x i8] c"Element\00"
@.str.2 = [6 x i8] c"Value\00"
@.str.3 = [10 x i8] c"Histogram\00"
@.str.4 = [16 x i8] c"%7u%13d \00"
define void @fig06_08() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %2
2: ; preds = %13, %0
%3 = phi i64 [ 0, %0 ], [ %15, %13 ]
%4 = getelementptr inbounds [10 x i32], [10 x i32]* @__const.fig06_08.n, i64 0, i64 %3
%5 = load i32, i32* %4
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 %3, i32 %5)
%7 = call i32 @llvm.smax.i32(i32 %5, i32 1)
br label %8
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 1, %2 ]
%10 = tail call i32 @putchar(i32 42)
%11 = add nuw i32 %9, 1
%12 = icmp eq i32 %9, %7
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = tail call i32 @putchar(i32 10)
%15 = add nuw nsw i64 %3, 1
%16 = icmp eq i64 %15, 10
br i1 %16, label %17, label %2
17: ; preds = %13
ret void
}