#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*/ scanf(char *, int *);
int main() {
  int i, e;
  int range;
  int length;
  printf("Enter range: ");
  scanf("%d", &range);
  printf("Enter length: ");
  scanf("%d", &length);
  int input[length];
  printf("Enter array: ");
  for (i = 0; i < length; i++) {
    scanf("%d", &input[i]);
  }
  printf("Histogram: \n");
  for (e = 0; e <= range; e++) {
    printf("%d: ", e);
    for (i = 0; i < length; i++) {
      if (e == input[i]) {
        printf("*");
      }
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
mov    %rdi,-0x38(%rbp)
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x39(%rbp),%al
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e1 <main+0xc1>
mov    -0x30(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe40(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ac <main+0x8c>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1277 <main+0x157>
mov    -0xc(%rbp),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125b <main+0x13b>
mov    -0x30(%rbp),%rcx
mov    -0xc(%rbp),%eax
movslq -0x8(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1248 <main+0x128>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <main+0x12d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    121a <main+0xfa>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f6 <main+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeab(%rip),%rbx
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x2c(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11ec <main+0xac>
xor    %r13d,%r13d
lea    0xe4c(%rip),%r14
mov    %r12,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11d0 <main+0x90>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x30(%rbp)
js     1261 <main+0x121>
lea    0xe29(%rip),%r14
xor    %r13d,%r13d
jmp    1227 <main+0xe7>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%r13),%eax
cmp    -0x30(%rbp),%r13d
mov    %eax,%r13d
jge    1261 <main+0x121>
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    1210 <main+0xd0>
xor    %ebx,%ebx
jmp    124c <main+0x10c>
nop
add    $0x1,%rbx
movslq %eax,%rcx
cmp    %rcx,%rbx
jge    1210 <main+0xd0>
cmp    (%r12,%rbx,4),%r13d
jne    1240 <main+0x100>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
jmp    1240 <main+0x100>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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