#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 *);
scalar_t__ rollem(int);
int roll_n_dice(int dice, int sides) {
  int d;
  int total = 0;
  if (sides < 2) {
    printf("Need at 2 sides\n");
    return -2;
  }
  if (dice < 1) {
    printf("Need at least 1 die\n");
    return -1;
  }
  for (d = 0; d < dice; d++) {
    total += rollem(sides);
  }
  return total;
}


x86 assembly (clang, -O0):
<roll_n_dice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1157 <roll_n_dice+0x37>
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b5 <roll_n_dice+0x95>
cmpl   $0x1,-0x8(%rbp)
jge    1179 <roll_n_dice+0x59>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <roll_n_dice+0x95>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11af <roll_n_dice+0x8f>
mov    -0xc(%rbp),%edi
call   1040 <rollem@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <roll_n_dice+0x60>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roll_n_dice>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%esi
jge    1137 <roll_n_dice+0x17>
mov    $0xfffffffe,%ebx
lea    0xedf(%rip),%rdi
jmp    116d <roll_n_dice+0x4d>
mov    %edi,%ebp
test   %edi,%edi
jle    1161 <roll_n_dice+0x41>
mov    %esi,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
call   1040 <rollem@plt>
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1150 <roll_n_dice+0x30>
jmp    1172 <roll_n_dice+0x52>
mov    $0xffffffff,%ebx
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Need at 2 sides\0A\00"
@.str.1 = [21 x i8] c"Need at least 1 die\0A\00"
define i32 @roll_n_dice(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %3
br label %34
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
17: ; preds = %12
store i32 0, i32* %6
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i64 @rollem(i32 %23)
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
br label %29
29: ; preds = %22
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %18
32: ; preds = %18
%33 = load i32, i32* %7
store i32 %33, i32* %3
br label %34
34: ; preds = %32, %15, %10
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@str = [20 x i8] c"Need at least 1 die\00"
@str.2 = [16 x i8] c"Need at 2 sides\00"
define i32 @roll_n_dice(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = icmp slt i32 %0, 1
br i1 %5, label %14, label %6
6: ; preds = %4, %6
%7 = phi i32 [ %11, %6 ], [ 0, %4 ]
%8 = phi i32 [ %12, %6 ], [ 0, %4 ]
%9 = tail call i64 @rollem(i32 %1)
%10 = trunc i64 %9 to i32
%11 = add i32 %7, %10
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, %0
br i1 %13, label %18, label %6
14: ; preds = %4, %2
%15 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %4 ]
%16 = phi i32 [ -2, %2 ], [ -1, %4 ]
%17 = tail call i32 @puts(i8* dereferenceable(1) %15)
br label %18
18: ; preds = %6, %14
%19 = phi i32 [ %16, %14 ], [ %11, %6 ]
ret i32 %19
}