#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, int);
int random();
int main() {
  int i, roll;
  int counts[13];
  for (i = 0; i < 13; i++)
    counts[i] = 0;
  for (i = 0; i < 10000; i++) {
    roll = 2 * (random() % 6) + 2;
    counts[roll]++;
  }
  for (i = 2; i < 13; i++)
    printf("%d throws yielded %d rolls of %d\n", 10000, i, counts[i]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xd,-0x8(%rbp)
jge    115a <main+0x3a>
movslq -0x8(%rbp),%rax
movl   $0x0,-0x40(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    11a5 <main+0x85>
mov    $0x0,%al
call   1040 <random@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
shl    $0x1,%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1161 <main+0x41>
movl   $0x2,-0x8(%rbp)
cmpl   $0xd,-0x8(%rbp)
jge    11e0 <main+0xc0>
mov    -0x8(%rbp),%edx
movslq -0x8(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
lea    0xe38(%rip),%rdi
mov    $0x2710,%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ac <main+0x8c>
mov    -0x4(%rbp),%eax
add    $0x40,%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)
mov    $0x2710,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <random@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
add    %eax,%eax
cltq
addl   $0x1,0x8(%rsp,%rax,4)
add    $0xffffffff,%ebx
jne    1150 <main+0x30>
mov    0x8(%rsp),%ecx
lea    0xe73(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x2,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1030 <printf@plt>
mov    0x10(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x4,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1030 <printf@plt>
mov    0x18(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x6,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x7,%edx
xor    %ecx,%ecx
call   1030 <printf@plt>
mov    0x20(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x8,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1030 <printf@plt>
mov    0x28(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0xa,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0xb,%edx
xor    %ecx,%ecx
call   1030 <printf@plt>
mov    0x30(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x2710,%esi
mov    $0xc,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [34 x i8] c"%d throws yielded %d rolls of %d\0A\00"
define i32 @main() {
%1 = alloca [13 x i32]
%2 = bitcast [13 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ %13, %3 ], [ 0, %0 ]
%5 = tail call i32 (...) @random()
%6 = srem i32 %5, 6
%7 = shl nsw i32 %6, 1
%8 = add nsw i32 %7, 2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [13 x i32], [13 x i32]* %1, 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 %4, 1
%14 = icmp eq i32 %13, 10000
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 2
%17 = load i32, i32* %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 2, i32 %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 3, i32 0)
%20 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 4
%21 = load i32, i32* %20
%22 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 4, i32 %21)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 5, i32 0)
%24 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 6
%25 = load i32, i32* %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 6, i32 %25)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 7, i32 0)
%28 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 8
%29 = load i32, i32* %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 8, i32 %29)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 9, i32 0)
%32 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 10
%33 = load i32, i32* %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 10, i32 %33)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 11, i32 0)
%36 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 12
%37 = load i32, i32* %36
%38 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10000, i32 12, i32 %37)
ret i32 0
}