#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 range, length, i, ii;
  printf("Enter range: ");
  do {
    scanf("%d", &range);
  } while (range < 1 || range > 32767);
  printf("Enter length: ");
  do {
    scanf("%d", &length);
  } while (length < 1 || range > 32767);
  int array[length];
  printf("Enter array: ");
  for (i = 0; i < length; i++) {
    do {
      scanf("%d", &array[i]);
    } while (array[i] < 0 || array[i] > range);
  }
  printf("Histogram:");
  for (i = 0; i <= range; i++) {
    printf("\n%d: ", i);
    for (ii = 0; ii < length; ii++) {
      if (array[ii] == 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
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x29(%rbp)
jl     1169 <main+0x49>
cmpl   $0x7fff,-0x8(%rbp)
setg   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    113d <main+0x1d>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x2a(%rbp)
jl     11ae <main+0x8e>
cmpl   $0x7fff,-0x8(%rbp)
setg   %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1182 <main+0x62>
mov    -0xc(%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,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126a <main+0x14a>
jmp    1206 <main+0xe6>
mov    -0x38(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdf2(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x38(%rbp),%rcx
movslq -0x10(%rbp),%rdx
mov    $0x1,%al
cmpl   $0x0,(%rcx,%rdx,4)
mov    %al,-0x39(%rbp)
jl     124c <main+0x12c>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
setg   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1206 <main+0xe6>
jmp    125c <main+0x13c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f5 <main+0xd5>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12f7 <main+0x1d7>
mov    -0x10(%rbp),%esi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12e4 <main+0x1c4>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jne    12d1 <main+0x1b1>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d6 <main+0x1b6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12a3 <main+0x183>
jmp    12e9 <main+0x1c9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    127f <main+0x15f>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebb(%rip),%r14
lea    -0x30(%rbp),%r15
mov    $0xffff8000,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    -0x30(%rbp),%eax
add    %ebx,%eax
cmp    $0xffff8001,%eax
jb     1160 <main+0x30>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe82(%rip),%r14
lea    -0x2c(%rbp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    1190 <main+0x60>
cmpl   $0x7fff,-0x30(%rbp)
jg     1190 <main+0x60>
mov    %rsp,%r15
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1223 <main+0xf3>
xor    %r13d,%r13d
lea    0xe2d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%r13,4),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    (%rbx),%eax
test   %eax,%eax
js     1200 <main+0xd0>
cmp    -0x30(%rbp),%eax
jg     1200 <main+0xd0>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
cmp    %rax,%r13
jl     11f0 <main+0xc0>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x30(%rbp)
js     12a1 <main+0x171>
lea    0xdfb(%rip),%r14
xor    %r13d,%r13d
jmp    125d <main+0x12d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%r13),%eax
cmp    -0x30(%rbp),%r13d
mov    %eax,%r13d
jge    12a1 <main+0x171>
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    1250 <main+0x120>
xor    %ebx,%ebx
jmp    128c <main+0x15c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
movslq %eax,%rcx
cmp    %rcx,%rbx
jge    1250 <main+0x120>
cmp    %r13d,(%r12,%rbx,4)
jne    1280 <main+0x150>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
jmp    1280 <main+0x150>
mov    $0xa,%edi
call   1030 <putchar@plt>
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 = [11 x i8] c"Histogram:\00"
@.str.5 = [6 x i8] c"\0A%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))
br label %9
9: ; preds = %17, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %9
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 32767
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ true, %11 ], [ %16, %14 ]
br i1 %18, label %9, label %19
19: ; preds = %17
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %29, %19
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %23
23: ; preds = %21
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %2
%28 = icmp sgt i32 %27, 32767
br label %29
29: ; preds = %26, %23
%30 = phi i1 [ true, %23 ], [ %28, %26 ]
br i1 %30, label %21, label %31
31: ; preds = %29
%32 = load i32, i32* %3
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %6
%35 = alloca i32, i64 %33
store i64 %33, i64* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %37
37: ; preds = %63, %31
%38 = load i32, i32* %4
%39 = load i32, i32* %3
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %66
41: ; preds = %37
br label %42
42: ; preds = %60, %41
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %35, i64 %44
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %45)
br label %47
47: ; preds = %42
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %35, i64 %49
%51 = load i32, i32* %50
%52 = icmp slt i32 %51, 0
br i1 %52, label %60, label %53
53: ; preds = %47
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %35, i64 %55
%57 = load i32, i32* %56
%58 = load i32, i32* %2
%59 = icmp sgt i32 %57, %58
br label %60
60: ; preds = %53, %47
%61 = phi i1 [ true, %47 ], [ %59, %53 ]
br i1 %61, label %42, label %62
62: ; preds = %60
br label %63
63: ; preds = %62
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 1
store i32 %65, i32* %4
br label %37
66: ; preds = %37
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %68
68: ; preds = %93, %66
%69 = load i32, i32* %4
%70 = load i32, i32* %2
%71 = icmp sle i32 %69, %70
br i1 %71, label %72, label %96
72: ; preds = %68
%73 = load i32, i32* %4
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %73)
store i32 0, i32* %5
br label %75
75: ; preds = %89, %72
%76 = load i32, i32* %5
%77 = load i32, i32* %3
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %92
79: ; preds = %75
%80 = load i32, i32* %5
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %35, i64 %81
%83 = load i32, i32* %82
%84 = load i32, i32* %4
%85 = icmp eq i32 %83, %84
br i1 %85, label %86, label %88
86: ; preds = %79
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %86, %79
br label %89
89: ; preds = %88
%90 = load i32, i32* %5
%91 = add nsw i32 %90, 1
store i32 %91, i32* %5
br label %75
92: ; preds = %75
br label %93
93: ; preds = %92
%94 = load i32, i32* %4
%95 = add nsw i32 %94, 1
store i32 %95, i32* %4
br label %68
96: ; preds = %68
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
%98 = load i8*, i8** %6
%99 = load i32, i32* %1
ret i32 %99
}

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.4 = [11 x i8] c"Histogram:\00"
@.str.5 = [6 x i8] c"\0A%d: \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))
br label %6
6: ; preds = %6, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add i32 %8, -32768
%10 = icmp ult i32 %9, -32767
br i1 %10, label %6, label %11
11: ; preds = %6
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %13, %11
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 1
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 32767
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %13, label %20
20: ; preds = %13
%21 = zext i32 %15 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i32, i64 %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %20, %37
%28 = phi i64 [ %38, %37 ], [ 0, %20 ]
%29 = getelementptr inbounds i32, i32* %23, i64 %28
br label %30
30: ; preds = %27, %30
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%32 = load i32, i32* %29
%33 = icmp slt i32 %32, 0
%34 = load i32, i32* %1
%35 = icmp sgt i32 %32, %34
%36 = select i1 %33, i1 true, i1 %35
br i1 %36, label %30, label %37
37: ; preds = %30
%38 = add nuw nsw i64 %28, 1
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %27, label %42
42: ; preds = %37, %20
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* %1
%45 = icmp slt i32 %44, 0
br i1 %45, label %69, label %46
46: ; preds = %42, %65
%47 = phi i32 [ %66, %65 ], [ 0, %42 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %2
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %65
51: ; preds = %46, %60
%52 = phi i32 [ %61, %60 ], [ %49, %46 ]
%53 = phi i64 [ %62, %60 ], [ 0, %46 ]
%54 = getelementptr inbounds i32, i32* %23, i64 %53
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, %47
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = call i32 @putchar(i32 42)
%59 = load i32, i32* %2
br label %60
60: ; preds = %51, %57
%61 = phi i32 [ %52, %51 ], [ %59, %57 ]
%62 = add nuw nsw i64 %53, 1
%63 = sext i32 %61 to i64
%64 = icmp slt i64 %62, %63
br i1 %64, label %51, label %65
65: ; preds = %60, %46
%66 = add nuw nsw i32 %47, 1
%67 = load i32, i32* %1
%68 = icmp slt i32 %47, %67
br i1 %68, label %46, label %69
69: ; preds = %65, %42
%70 = call i32 @putchar(i32 10)
ret i32 0
}