#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, int);
void histogram() {
  int input[] = {35, 25, 56, 78, 43,  66, 71, 73, 80, 90,
                 0,  73, 35, 65, 100, 78, 80, 85, 35, 50};
  int i, rank, histo[11];
  for (i = 0; i < 10; i++) {
    histo[i] = 0;
  }
  for (i = 0; i < 20; i++) {
    rank = input[i] / 10;
    if (0 <= rank && rank <= 10) {
      histo[rank]++;
    }
  }
  for (i = 0; i <= 10; i++) {
    printf("%3d - :%3d\n", i * 10, histo[i]);
  }
}


x86 assembly (clang, -O0):
<histogram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x50(%rbp),%rdi
lea    0xeca(%rip),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0xa,-0x54(%rbp)
jge    116e <histogram+0x4e>
movslq -0x54(%rbp),%rax
movl   $0x0,-0x90(%rbp,%rax,4)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1147 <histogram+0x27>
movl   $0x0,-0x54(%rbp)
cmpl   $0x14,-0x54(%rbp)
jge    11cf <histogram+0xaf>
movslq -0x54(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
xor    %eax,%eax
cmp    -0x58(%rbp),%eax
jg     11bc <histogram+0x9c>
cmpl   $0xa,-0x58(%rbp)
jg     11bc <histogram+0x9c>
movslq -0x58(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x90(%rbp,%rax,4)
jmp    11c1 <histogram+0xa1>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1175 <histogram+0x55>
movl   $0x0,-0x54(%rbp)
cmpl   $0xa,-0x54(%rbp)
jg     1209 <histogram+0xe9>
imul   $0xa,-0x54(%rbp),%esi
movslq -0x54(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edx
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11d6 <histogram+0xb6>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<histogram>:
push   %rbx
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x20(%rsp)
mov    $0x1,%eax
lea    0xeca(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
movslq -0x4(%rcx,%rax,4),%rdx
imul   $0x66666667,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
movslq %edx,%rdx
addl   $0x1,(%rsp,%rdx,4)
movslq (%rcx,%rax,4),%rdx
imul   $0x66666667,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
movslq %edx,%rdx
addl   $0x1,(%rsp,%rdx,4)
add    $0x2,%rax
cmp    $0x15,%rax
jne    1140 <histogram+0x30>
mov    (%rsp),%edx
lea    0xebd(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    $0x28,%esi
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x46,%esi
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
mov    $0x5a,%esi
call   1030 <printf@plt>
mov    0x28(%rsp),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
add    $0x30,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.histogram.input = [20 x i32] [i32 35, i32 25, i32 56, i32 78, i32 43, i32 66, i32 71, i32 73, i32 80, i32 90, i32 0, i32 73, i32 35, i32 65, i32 100, i32 78, i32 80, i32 85, i32 35, i32 50]
@.str = [12 x i8] c"%3d - :%3d\0A\00"
define void @histogram() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [11 x i32]
%5 = bitcast [20 x i32]* %1 to i8*
store i32 0, i32* %2
br label %6
6: ; preds = %13, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 %11
store i32 0, i32* %12
br label %13
13: ; preds = %9
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %6
16: ; preds = %6
store i32 0, i32* %2
br label %17
17: ; preds = %38, %16
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 20
br i1 %19, label %20, label %41
20: ; preds = %17
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = sdiv i32 %24, 10
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = icmp sle i32 0, %26
br i1 %27, label %28, label %37
28: ; preds = %20
%29 = load i32, i32* %3
%30 = icmp sle i32 %29, 10
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
br label %37
37: ; preds = %31, %28, %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %17
41: ; preds = %17
store i32 0, i32* %2
br label %42
42: ; preds = %53, %41
%43 = load i32, i32* %2
%44 = icmp sle i32 %43, 10
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32, i32* %2
%47 = mul nsw i32 %46, 10
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %47, i32 %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %42
56: ; preds = %42
ret void
}

LLVM IR (-O2):
@__const.histogram.input = [20 x i32] [i32 35, i32 25, i32 56, i32 78, i32 43, i32 66, i32 71, i32 73, i32 80, i32 90, i32 0, i32 73, i32 35, i32 65, i32 100, i32 78, i32 80, i32 85, i32 35, i32 50]
@.str = [12 x i8] c"%3d - :%3d\0A\00"
define void @histogram() {
%1 = alloca [11 x i32]
%2 = bitcast [11 x i32]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %20, %3 ]
%5 = getelementptr inbounds [20 x i32], [20 x i32]* @__const.histogram.input, i64 0, i64 %4
%6 = load i32, i32* %5
%7 = sdiv i32 %6, 10
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
store i32 %11, i32* %9
%12 = or i64 %4, 1
%13 = getelementptr inbounds [20 x i32], [20 x i32]* @__const.histogram.input, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = add nuw nsw i64 %4, 2
%21 = icmp eq i64 %20, 20
br i1 %21, label %22, label %3
22: ; preds = %3
%23 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
%24 = load i32, i32* %23
%25 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 0, i32 %24)
%26 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 1
%27 = load i32, i32* %26
%28 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 10, i32 %27)
%29 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 2
%30 = load i32, i32* %29
%31 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 20, i32 %30)
%32 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 3
%33 = load i32, i32* %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 30, i32 %33)
%35 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 4
%36 = load i32, i32* %35
%37 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 40, i32 %36)
%38 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 5
%39 = load i32, i32* %38
%40 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 50, i32 %39)
%41 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 6
%42 = load i32, i32* %41
%43 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 60, i32 %42)
%44 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 7
%45 = load i32, i32* %44
%46 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 70, i32 %45)
%47 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 8
%48 = load i32, i32* %47
%49 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 80, i32 %48)
%50 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 9
%51 = load i32, i32* %50
%52 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 90, i32 %51)
%53 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 10
%54 = load i32, i32* %53
%55 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 100, i32 %54)
ret void
}