#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 /*<<< orphan*/ uint64_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/);
size_t rand_to_max(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  srand(time(NULL));
  uint64_t counter[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < 1000000; i++)
    counter[rand_to_max(9)]++;
  for (int i = 0; i < 10; i++)
    printf("%d: %lu\n", i, counter[i]);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0xf4240,-0x44(%rbp)
jge    11bd <main+0x6d>
mov    $0x9,%edi
call   1040 <rand_to_max@plt>
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    118d <main+0x3d>
movl   $0x0,-0x48(%rbp)
cmpl   $0xa,-0x48(%rbp)
jge    11f3 <main+0xa3>
mov    -0x48(%rbp),%esi
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11c4 <main+0x74>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x20(%rsp)
mov    $0xf4240,%ebx
nopl   (%rax)
mov    $0x9,%edi
call   1040 <rand_to_max@plt>
addl   $0x1,(%rsp,%rax,4)
add    $0xffffffff,%ebx
jne    1170 <main+0x30>
mov    (%rsp),%edx
lea    0xe73(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
ret

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

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