#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 get_roll_counts(int, int, int);
void fill_roll_counts(int *counts, int dice, int sides) {
  int max_roll = dice * sides;
  for (int i = 0; i < max_roll; i++)
    counts[i] = get_roll_counts(i + 1, dice, sides);
}


x86 assembly (clang, -O0):
<fill_roll_counts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116b <fill_roll_counts+0x5b>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <get_roll_counts@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1133 <fill_roll_counts+0x23>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_roll_counts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%eax
imul   %esi,%eax
test   %eax,%eax
jle    115d <fill_roll_counts+0x4d>
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
mov    %eax,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%rbp
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <get_roll_counts@plt>
mov    %eax,(%r14,%rbx,4)
mov    %rbp,%rbx
cmp    %rbp,%r13
jne    1140 <fill_roll_counts+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fill_roll_counts(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = mul nsw i32 %9, %10
store i32 %11, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %26, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 1
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @get_roll_counts(i32 %18, i32 %19, i32 %20)
%22 = load i32*, i32** %4
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %26
26: ; preds = %16
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %12
29: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @fill_roll_counts(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = mul i32 %2, %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %9
8: ; preds = %9, %3
ret void
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %11, %9 ]
%11 = add nuw nsw i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = tail call i32 @get_roll_counts(i32 %12, i32 %1, i32 %2)
%14 = getelementptr inbounds i32, i32* %0, i64 %10
store i32 %13, i32* %14
%15 = icmp eq i64 %11, %7
br i1 %15, label %8, label %9
}