#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 N, l, i, nothing;
  printf("Enter range: ");
  scanf("%d", &N);
  printf("Enter length: ");
  scanf("%d", &l);
  int arr[N + 1];
  printf("Enter array: ");
  for (i = 0; i < N + 1; i++)
    arr[i] = 0;
  for (i = 0; i < l; i++) {
    scanf("%d", &nothing);
    arr[nothing]++;
  }
  printf("Histogram:\n");
  for (i = 0; i < N + 1; i++)
    printf("%d: %d\n", i, arr[i]);
  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    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x39(%rbp),%al
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%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    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11dd <main+0xbd>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11af <main+0x8f>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121f <main+0xff>
lea    0xe17(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e4 <main+0xc4>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    126f <main+0x14f>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%esi
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1234 <main+0x114>
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
sub    $0x18,%rsp
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea8(%rip),%rbx
lea    -0x2c(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
js     11d1 <main+0x91>
lea    0x4(,%rax,4),%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
cmpl   $0x0,-0x30(%rbp)
jle    120c <main+0xcc>
xor    %ebx,%ebx
lea    0xe2e(%rip),%r14
lea    -0x34(%rbp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
movslq -0x34(%rbp),%rax
addl   $0x1,(%r15,%rax,4)
add    $0x1,%ebx
cmp    -0x30(%rbp),%ebx
jl     11f0 <main+0xb0>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
js     1250 <main+0x110>
lea    0xe09(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rbx),%rax
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rbx
mov    %rax,%rbx
jl     1230 <main+0xf0>
mov    %r12,%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 = [12 x i8] c"Histogram:\0A\00"
@.str.5 = [8 x i8] c"%d: %d\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* %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 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i32, i64 %14
store i64 %14, i64* %7
%17 = 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 %18
18: ; preds = %27, %0
%19 = load i32, i32* %4
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %16, i64 %25
store i32 0, i32* %26
br label %27
27: ; preds = %23
%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 = %42, %30
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %16, i64 %38
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
br label %42
42: ; preds = %35
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %31
45: ; preds = %31
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %47
47: ; preds = %59, %45
%48 = load i32, i32* %4
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
%51 = icmp slt i32 %48, %50
br i1 %51, label %52, label %62
52: ; preds = %47
%53 = load i32, i32* %4
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %16, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %57)
br label %59
59: ; preds = %52
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %47
62: ; preds = %47
store i32 0, i32* %1
%63 = load i8*, i8** %6
%64 = load i32, i32* %1
ret i32 %64
}

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