#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 rollDie(int, int);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  unsigned int buckets[13] = {0};
  int i;
  int roll;
  srand((unsigned int)time(NULL));
  for (i = 0; i < 100000; i++) {
    roll = rollDie(2, 12);
    buckets[roll]++;
  }
  printf("%d total rolls\n", 100000);
  printf("Random numbers from 2 - 12\n");
  for (i = 2; i <= 12; i++)
    printf("[%d]: %d\n", i, buckets[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x34,%edx
call   1040 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x186a0,-0x54(%rbp)
jge    11c9 <main+0x79>
mov    $0x2,%edi
mov    $0xc,%esi
call   1060 <rollDie@plt>
mov    %eax,-0x58(%rbp)
movslq -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    118d <main+0x3d>
lea    0xe30(%rip),%rdi
mov    $0x186a0,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x54(%rbp)
cmpl   $0xc,-0x54(%rbp)
jg     1222 <main+0xd2>
mov    -0x54(%rbp),%esi
movslq -0x54(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f1 <main+0xa1>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x30(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x186a0,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    $0xc,%esi
call   1060 <rollDie@plt>
cltq
addl   $0x1,(%rsp,%rax,4)
add    $0xffffffff,%ebx
jne    1190 <main+0x40>
lea    0xe4f(%rip),%rdi
mov    $0x186a0,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edx
lea    0xe3c(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rsp),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c(%rsp),%edx
mov    %rbx,%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x30(%rsp),%edx
mov    %rbx,%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%d total rolls\0A\00"
@.str.1 = [28 x i8] c"Random numbers from 2 - 12\0A\00"
@.str.2 = [10 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 [13 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [13 x i32]* %6 to i8*
%10 = call i64 @time(i32* null)
%11 = trunc i64 %10 to i32
%12 = call i32 @srand(i32 %11)
store i32 0, i32* %7
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 100000
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = call i32 @rollDie(i32 2, i32 12)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = add i32 %21, 1
store i32 %22, i32* %20
br label %23
23: ; preds = %16
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %13
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 100000)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %7
br label %29
29: ; preds = %39, %26
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 12
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i32, i32* %7
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %29
42: ; preds = %29
ret i32 0
}

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