#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 */
typedef int uint16_t;

/* Variables and functions */
int *calloc(int, int);
int /*<<< orphan*/ printf(char *, int, int);
size_t randrange(int /*<<< orphan*/, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  srand(time(NULL));
  int r;
  uint16_t *amounts = calloc(sizeof(uint16_t), (9 - 0 + 1));
  for (int i = 0; i < 1000; i++)
    amounts[randrange(0, 9) - 0]++;
  for (int i = 0; i < 9 - 0 + 1; i++)
    printf("%d: %d\n", i, amounts[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x4,%edi
mov    $0xa,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    11d3 <main+0x83>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
xor    %edi,%edi
mov    $0x9,%esi
call   1070 <randrange@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    $0x0,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1190 <main+0x40>
movl   $0x0,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jge    120c <main+0xbc>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11da <main+0x8a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x4,%edi
mov    $0xa,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    $0x3e8,%ebp
nopl   0x0(%rax)
xor    %edi,%edi
mov    $0x9,%esi
call   1070 <randrange@plt>
addl   $0x1,(%rbx,%rax,4)
add    $0xffffffff,%ebp
jne    1180 <main+0x30>
mov    (%rbx),%edx
lea    0xe62(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x4(%rbx),%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    0x8(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    0xc(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    0x10(%rbx),%edx
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x14(%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    0x18(%rbx),%edx
mov    %r14,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %r14,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    0x20(%rbx),%edx
mov    %r14,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    0x24(%rbx),%edx
mov    %r14,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%d: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
%12 = call i32* @calloc(i32 4, i32 10)
store i32* %12, i32** %7
store i32 0, i32* %8
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 1000
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32*, i32** %7
%18 = call i64 @randrange(i32 0, i32 9)
%19 = sub i64 %18, 0
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
br label %23
23: ; preds = %16
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %13
26: ; preds = %13
store i32 0, i32* %9
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %9
%29 = icmp slt i32 %28, 10
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = load i32, i32* %9
%32 = load i32*, i32** %7
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %27
41: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"%d: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32* @calloc(i32 4, i32 10)
br label %6
6: ; preds = %2, %6
%7 = phi i32 [ 0, %2 ], [ %12, %6 ]
%8 = tail call i64 @randrange(i32 0, i32 9)
%9 = getelementptr inbounds i32, i32* %5, i64 %8
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
store i32 %11, i32* %9
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, 1000
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = load i32, i32* %5
%16 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i32 %15)
%17 = getelementptr inbounds i32, i32* %5, i64 1
%18 = load i32, i32* %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 1, i32 %18)
%20 = getelementptr inbounds i32, i32* %5, i64 2
%21 = load i32, i32* %20
%22 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 2, i32 %21)
%23 = getelementptr inbounds i32, i32* %5, i64 3
%24 = load i32, i32* %23
%25 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 3, i32 %24)
%26 = getelementptr inbounds i32, i32* %5, i64 4
%27 = load i32, i32* %26
%28 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 4, i32 %27)
%29 = getelementptr inbounds i32, i32* %5, i64 5
%30 = load i32, i32* %29
%31 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 5, i32 %30)
%32 = getelementptr inbounds i32, i32* %5, i64 6
%33 = load i32, i32* %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 6, i32 %33)
%35 = getelementptr inbounds i32, i32* %5, i64 7
%36 = load i32, i32* %35
%37 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7, i32 %36)
%38 = getelementptr inbounds i32, i32* %5, i64 8
%39 = load i32, i32* %38
%40 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 8, i32 %39)
%41 = getelementptr inbounds i32, i32* %5, i64 9
%42 = load i32, i32* %41
%43 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 9, i32 %42)
ret i32 0
}