#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, count, i;
  printf("Enter range: ");
  scanf("%d", &range);
  printf("Enter length: ");
  scanf("%d", &length);
  printf("Enter array: ");
  if (length > 1000) {
    printf("Max length 1000.\n");
    return 0;
  }
  int numbers[1000];
  for (count = 0; count < length; count++) {
    scanf("%d ", &numbers[count]);
  }
  int counts[1000];
  for (count = 0; count < length; ++count) {
    if (numbers[count] >= 0 && numbers[count] <= range) {
      counts[numbers[count]]++;
    }
  }
  printf("Histogram:\n");
  for (count = 0; count <= range; ++count) {
    printf("%d: ", count);
    for (i = 0; i < counts[count]; ++i) {
      printf("*");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x3e8,-0xc(%rbp)
jle    11a3 <main+0x83>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d7 <main+0x1b7>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e2 <main+0xc2>
movslq -0x10(%rbp),%rax
lea    -0xfc0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe71(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11aa <main+0x8a>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124b <main+0x12b>
movslq -0x10(%rbp),%rax
cmpl   $0x0,-0xfc0(%rbp,%rax,4)
jl     1238 <main+0x118>
movslq -0x10(%rbp),%rax
mov    -0xfc0(%rbp,%rax,4),%eax
cmp    -0x8(%rbp),%eax
jg     1238 <main+0x118>
movslq -0x10(%rbp),%rax
movslq -0xfc0(%rbp,%rax,4),%rax
ff
mov    -0x1f60(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1f60(%rbp,%rax,4)
jmp    123d <main+0x11d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e9 <main+0xc9>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12d0 <main+0x1b0>
mov    -0x10(%rbp),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movslq -0x10(%rbp),%rcx
cmp    -0x1f60(%rbp,%rcx,4),%eax
jge    12b4 <main+0x194>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1284 <main+0x164>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1260 <main+0x140>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1f60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1f58,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeac(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3e9,%eax
jl     11b4 <main+0x74>
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
jmp    1281 <main+0x141>
test   %eax,%eax
jle    121b <main+0xdb>
lea    0xfb0(%rsp),%r15
xor    %ebx,%ebx
lea    0xe65(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     11d0 <main+0x90>
mov    %eax,%ecx
test   %ecx,%ecx
jle    121b <main+0xdb>
mov    0x8(%rsp),%eax
cmp    $0x1,%ecx
jne    1291 <main+0x151>
xor    %edx,%edx
test   $0x1,%cl
je     121b <main+0xdb>
mov    0xfb0(%rsp,%rdx,4),%ecx
test   %ecx,%ecx
js     121b <main+0xdb>
cmp    %eax,%ecx
jg     121b <main+0xdb>
addl   $0x1,0x10(%rsp,%rcx,4)
lea    0xe15(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
js     1281 <main+0x141>
lea    0xdfd(%rip),%r14
xor    %ebx,%ebx
jmp    125b <main+0x11b>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%rax
movslq 0x8(%rsp),%rcx
cmp    %rcx,%rbx
mov    %rax,%rbx
jge    1281 <main+0x141>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp,%rbx,4),%ebp
test   %ebp,%ebp
jle    1240 <main+0x100>
nop
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1270 <main+0x130>
jmp    1240 <main+0x100>
xor    %eax,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ecx,%esi
and    $0xfffffffe,%esi
xor    %edx,%edx
jmp    12ad <main+0x16d>
nopw   0x0(%rax,%rax,1)
add    $0x2,%rdx
cmp    %rdx,%rsi
je     1202 <main+0xc2>
mov    0xfb0(%rsp,%rdx,4),%edi
test   %edi,%edi
js     12c1 <main+0x181>
cmp    %eax,%edi
jg     12c1 <main+0x181>
addl   $0x1,0x10(%rsp,%rdi,4)
mov    0xfb4(%rsp,%rdx,4),%edi
test   %edi,%edi
js     12a0 <main+0x160>
cmp    %eax,%edi
jg     12a0 <main+0x160>
addl   $0x1,0x10(%rsp,%rdi,4)
jmp    12a0 <main+0x160>

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 = [18 x i8] c"Max length 1000.\0A\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [12 x i8] c"Histogram:\0A\00"
@.str.7 = [5 x i8] c"%d: \00"
@.str.8 = [2 x i8] c"*\00"
@.str.9 = [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 [1000 x i32]
%7 = alloca [1000 x i32]
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* %2)
%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* %3)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 1000
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %88
17: ; preds = %0
store i32 0, i32* %4
br label %18
18: ; preds = %27, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %22
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %18
30: ; preds = %18
store i32 0, i32* %4
br label %31
31: ; preds = %58, %30
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %61
35: ; preds = %31
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %57
41: ; preds = %35
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = load i32, i32* %2
%47 = icmp sle i32 %45, %46
br i1 %47, label %48, label %57
48: ; preds = %41
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
store i32 %56, i32* %54
br label %57
57: ; preds = %48, %41, %35
br label %58
58: ; preds = %57
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %31
61: ; preds = %31
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %4
br label %63
63: ; preds = %84, %61
%64 = load i32, i32* %4
%65 = load i32, i32* %2
%66 = icmp sle i32 %64, %65
br i1 %66, label %67, label %87
67: ; preds = %63
%68 = load i32, i32* %4
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %68)
store i32 0, i32* %5
br label %70
70: ; preds = %79, %67
%71 = load i32, i32* %5
%72 = load i32, i32* %4
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [1000 x i32], [1000 x i32]* %7, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = icmp slt i32 %71, %75
br i1 %76, label %77, label %82
77: ; preds = %70
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %79
79: ; preds = %77
%80 = load i32, i32* %5
%81 = add nsw i32 %80, 1
store i32 %81, i32* %5
br label %70
82: ; preds = %70
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %84
84: ; preds = %82
%85 = load i32, i32* %4
%86 = add nsw i32 %85, 1
store i32 %86, i32* %4
br label %63
87: ; preds = %63
store i32 0, i32* %1
br label %88
88: ; preds = %87, %15
%89 = load i32, i32* %1
ret i32 %89
}

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 = [4 x i8] c"%d \00"
@.str.7 = [5 x i8] c"%d: \00"
@str = [11 x i8] c"Histogram:\00"
@str.10 = [17 x i8] c"Max length 1000.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i32]
%4 = alloca [1000 x i32]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 1000
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
br label %106
16: ; preds = %0
%17 = bitcast [1000 x i32]* %3 to i8*
%18 = icmp sgt i32 %12, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = bitcast [1000 x i32]* %4 to i8*
br label %82
21: ; preds = %16, %21
%22 = phi i64 [ %25, %21 ], [ 0, %16 ]
%23 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %23)
%25 = add nuw nsw i64 %22, 1
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %21, label %29
29: ; preds = %21
%30 = bitcast [1000 x i32]* %4 to i8*
%31 = icmp sgt i32 %26, 0
br i1 %31, label %32, label %82
32: ; preds = %29
%33 = load i32, i32* %1
%34 = zext i32 %26 to i64
%35 = and i64 %34, 1
%36 = icmp eq i32 %26, 1
br i1 %36, label %68, label %37
37: ; preds = %32
%38 = and i64 %34, 4294967294
br label %39
39: ; preds = %64, %37
%40 = phi i64 [ 0, %37 ], [ %65, %64 ]
%41 = phi i64 [ 0, %37 ], [ %66, %64 ]
%42 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %40
%43 = load i32, i32* %42
%44 = icmp slt i32 %43, 0
%45 = icmp sgt i32 %43, %33
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %52, label %47
47: ; preds = %39
%48 = zext i32 %43 to i64
%49 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = add nsw i32 %50, 1
store i32 %51, i32* %49
br label %52
52: ; preds = %39, %47
%53 = or i64 %40, 1
%54 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = icmp slt i32 %55, 0
%57 = icmp sgt i32 %55, %33
%58 = select i1 %56, i1 true, i1 %57
br i1 %58, label %64, label %59
59: ; preds = %52
%60 = zext i32 %55 to i64
%61 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = add nsw i32 %62, 1
store i32 %63, i32* %61
br label %64
64: ; preds = %59, %52
%65 = add nuw nsw i64 %40, 2
%66 = add i64 %41, 2
%67 = icmp eq i64 %66, %38
br i1 %67, label %68, label %39
68: ; preds = %64, %32
%69 = phi i64 [ 0, %32 ], [ %65, %64 ]
%70 = icmp eq i64 %35, 0
br i1 %70, label %82, label %71
71: ; preds = %68
%72 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %69
%73 = load i32, i32* %72
%74 = icmp slt i32 %73, 0
%75 = icmp sgt i32 %73, %33
%76 = select i1 %74, i1 true, i1 %75
br i1 %76, label %82, label %77
77: ; preds = %71
%78 = zext i32 %73 to i64
%79 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = add nsw i32 %80, 1
store i32 %81, i32* %79
br label %82
82: ; preds = %68, %77, %71, %19, %29
%83 = bitcast [1000 x i32]* %4 to i8*
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%85 = load i32, i32* %1
%86 = icmp slt i32 %85, 0
br i1 %86, label %105, label %87
87: ; preds = %82, %99
%88 = phi i64 [ %101, %99 ], [ 0, %82 ]
%89 = trunc i64 %88 to i32
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %89)
%91 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 %88
%92 = load i32, i32* %91
%93 = icmp sgt i32 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %87, %94
%95 = phi i32 [ %97, %94 ], [ 0, %87 ]
%96 = call i32 @putchar(i32 42)
%97 = add nuw nsw i32 %95, 1
%98 = icmp eq i32 %97, %92
br i1 %98, label %99, label %94
99: ; preds = %94, %87
%100 = call i32 @putchar(i32 10)
%101 = add nuw nsw i64 %88, 1
%102 = load i32, i32* %1
%103 = sext i32 %102 to i64
%104 = icmp slt i64 %88, %103
br i1 %104, label %87, label %105
105: ; preds = %99, %82
br label %106
106: ; preds = %105, %14
ret i32 0
}