#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 scanf(char *, int *);
int main() {
  int ar[1000];
  int rng, lth, n, i, m, x;
  printf("Enter range: ");
  scanf("%d", &rng);
  printf("Enter length: ");
  scanf("%d", &lth);
  printf("Enter array: \n");
  for (i = 0; i < lth; i++)
    if (scanf("%d", &ar[i]) != 1)
      i--;
  printf("Histogram: \n");
  for (i = 0; i < rng; i++) {
    printf("%d : ", i);
    for (x = 0; x < lth; x++) {
      if (ar[x] == i)
        printf("*");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0xfb4(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0xfb8(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfc0(%rbp)
mov    -0xfc0(%rbp),%eax
cmp    -0xfb8(%rbp),%eax
jge    11f0 <main+0xd0>
movslq -0xfc0(%rbp),%rax
lea    -0xfb0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe54(%rip),%rdi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11d7 <main+0xb7>
mov    -0xfc0(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xfc0(%rbp)
jmp    11dc <main+0xbc>
mov    -0xfc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc0(%rbp)
jmp    118c <main+0x6c>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfc0(%rbp)
mov    -0xfc0(%rbp),%eax
cmp    -0xfb4(%rbp),%eax
jge    12ad <main+0x18d>
mov    -0xfc0(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfc8(%rbp)
mov    -0xfc8(%rbp),%eax
cmp    -0xfb8(%rbp),%eax
jge    128b <main+0x16b>
movslq -0xfc8(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%eax
cmp    -0xfc0(%rbp),%eax
jne    1272 <main+0x152>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <main+0x157>
mov    -0xfc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc8(%rbp)
jmp    1238 <main+0x118>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xfc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc0(%rbp)
jmp    1208 <main+0xe8>
xor    %eax,%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xfb0,%rsp
lea    0xeae(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeac(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    11d8 <main+0x98>
lea    0xe6a(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebp,%rbp
lea    (%rsp,%rbp,4),%rsi
add    $0x10,%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
neg    %ecx
add    %ecx,%ebp
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jl     11b0 <main+0x70>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    1252 <main+0x112>
lea    0xe2e(%rip),%r14
xor    %ebp,%ebp
jmp    1213 <main+0xd3>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    1252 <main+0x112>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    1200 <main+0xc0>
xor    %ebx,%ebx
jmp    123c <main+0xfc>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movslq %eax,%rcx
cmp    %rcx,%rbx
jge    1200 <main+0xc0>
cmp    %ebp,0x10(%rsp,%rbx,4)
jne    1230 <main+0xf0>
mov    $0x2a,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%eax
jmp    1230 <main+0xf0>
xor    %eax,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r14
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 = [15 x i8] c"Enter array: \0A\00"
@.str.4 = [13 x i8] c"Histogram: \0A\00"
@.str.5 = [6 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 [1000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %14
14: ; preds = %28, %0
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %6
%26 = add nsw i32 %25, -1
store i32 %26, i32* %6
br label %27
27: ; preds = %24, %18
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %14
31: ; preds = %14
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %33
33: ; preds = %59, %31
%34 = load i32, i32* %6
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %62
37: ; preds = %33
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %38)
store i32 0, i32* %8
br label %40
40: ; preds = %54, %37
%41 = load i32, i32* %8
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %57
44: ; preds = %40
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = load i32, i32* %6
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %51, %44
br label %54
54: ; preds = %53
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %40
57: ; preds = %40
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %59
59: ; preds = %57
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %33
62: ; preds = %33
ret i32 0
}

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