#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 getpeak(int *, int);
int /*<<< orphan*/ printf(char *, ...);
void painth(int counts[], int len) {
  printf("\nHorizontal histogram:\n\n");
  int peak = getpeak(counts, len);
  int i;
  for (i = 0; i < len; i++) {
    int barlen = counts[i] * 20 / peak + 1;
    char bar[barlen];
    int j;
    for (j = 0; j < barlen - 1; j++) {
      bar[j] = '+';
    }
    bar[j] = '\0';
    char *format = "  %2d: %s %d\n";
    if (i == len - 1) {
      format = ">=%2d: %s %d\n";
    }
    printf(format, i + 1, bar, counts[i]);
  }
}


x86 assembly (clang, -O0):
<painth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <getpeak@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123e <painth+0x11e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
shl    $0x2,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,4),%eax
mov    -0x10(%rbp),%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d6 <painth+0xb6>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x2b,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ab <painth+0x8b>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xe30(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1209 <painth+0xe9>
lea    0xe22(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <painth+0x33>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<painth>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1060 <getpeak@plt>
mov    %eax,-0x2c(%rbp)
test   %ebx,%ebx
jle    120e <painth+0xce>
lea    -0x1(%rbx),%eax
mov    %rax,-0x40(%rbp)
mov    %ebx,%eax
mov    %rax,-0x38(%rbp)
xor    %r13d,%r13d
jmp    11df <painth+0x9f>
nopl   0x0(%rax)
mov    %ebx,%edx
mov    %r12,%rdi
mov    $0x2b,%esi
call   1050 <memset@plt>
add    $0xffffffff,%ebx
add    $0x1,%rbx
movb   $0x0,(%r12,%rbx,1)
cmp    %r13,-0x40(%rbp)
lea    0xe4a(%rip),%rdi
lea    0xe51(%rip),%rax
cmove  %rax,%rdi
mov    (%r15,%r13,4),%ecx
add    $0x1,%r13
mov    %r13d,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rsp
cmp    %r13,-0x38(%rbp)
je     120e <painth+0xce>
mov    %rsp,%r14
mov    (%r15,%r13,4),%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,%ebx
lea    0x1(%rbx),%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
test   %ebx,%ebx
jg     1190 <painth+0x50>
xor    %ebx,%ebx
jmp    11a6 <painth+0x66>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"\0AHorizontal histogram:\0A\0A\00"
@.str.1 = [14 x i8] c" %2d: %s %d\0A\00"
@.str.2 = [14 x i8] c">=%2d: %s %d\0A\00"
define void @painth(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
store i32* %0, i32** %3
store i32 %1, i32* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = load i32*, i32** %3
%14 = load i32, i32* %4
%15 = call i32 @getpeak(i32* %13, i32 %14)
store i32 %15, i32* %5
store i32 0, i32* %6
br label %16
16: ; preds = %66, %2
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %69
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = mul nsw i32 %25, 20
%27 = load i32, i32* %5
%28 = sdiv i32 %26, %27
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %8
%33 = alloca i8, i64 %31
store i64 %31, i64* %9
store i32 0, i32* %10
br label %34
34: ; preds = %43, %20
%35 = load i32, i32* %10
%36 = load i32, i32* %7
%37 = sub nsw i32 %36, 1
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %33, i64 %41
store i8 43, i8* %42
br label %43
43: ; preds = %39
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %34
46: ; preds = %34
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %33, i64 %48
store i8 0, i8* %49
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %11
%50 = load i32, i32* %6
%51 = load i32, i32* %4
%52 = sub nsw i32 %51, 1
%53 = icmp eq i32 %50, %52
br i1 %53, label %54, label %55
54: ; preds = %46
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %11
br label %55
55: ; preds = %54, %46
%56 = load i8*, i8** %11
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 1
%59 = load i32*, i32** %3
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* %56, i32 %58, i8* %33, i32 %63)
%65 = load i8*, i8** %8
br label %66
66: ; preds = %55
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %16
69: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c" %2d: %s %d\0A\00"
@.str.2 = [14 x i8] c">=%2d: %s %d\0A\00"
@str = [24 x i8] c"\0AHorizontal histogram:\0A\00"
define void @painth(i32* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @getpeak(i32* %0, i32 %1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %36
6: ; preds = %2
%7 = add nsw i32 %1, -1
%8 = zext i32 %7 to i64
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %6, %26
%11 = phi i64 [ 0, %6 ], [ %31, %26 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 20
%15 = sdiv i32 %14, %4
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = icmp sgt i32 %15, 0
br i1 %20, label %21, label %26
21: ; preds = %10
%22 = zext i32 %15 to i64
%23 = add nsw i32 %15, -1
%24 = zext i32 %23 to i64
%25 = add nuw nsw i64 %24, 1
br label %26
26: ; preds = %21, %10
%27 = phi i64 [ 0, %10 ], [ %25, %21 ]
%28 = getelementptr inbounds i8, i8* %19, i64 %27
store i8 0, i8* %28
%29 = icmp eq i64 %11, %8
%30 = select i1 %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%31 = add nuw nsw i64 %11, 1
%32 = load i32, i32* %12
%33 = trunc i64 %31 to i32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %30, i32 %33, i8* %19, i32 %32)
%35 = icmp eq i64 %31, %9
br i1 %35, label %36, label %10
36: ; preds = %26, %2
ret void
}