#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 *);
unsigned int randomMT();
unsigned int polyRollDice(int number, int die) {
  unsigned int result = 0, random;
  static int tally = 0;
  for (; number > 0; --number) {
    random = randomMT();
    if (random == 0) {
      printf("Uh oh, PRNG returned a zero!!!");
      printf("\a");
    }
    result += (random % die) + 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<polyRollDice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    118c <polyRollDice+0x6c>
mov    $0x0,%al
call   1040 <randomMT@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    116b <polyRollDice+0x4b>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %edx,%eax
add    $0x1,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1135 <polyRollDice+0x15>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polyRollDice>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    1187 <polyRollDice+0x57>
mov    %esi,%r14d
mov    %edi,%ebp
add    $0x1,%ebp
lea    0xeb5(%rip),%r15
xor    %ebx,%ebx
jmp    1165 <polyRollDice+0x35>
nop
mov    %r12d,%eax
xor    %edx,%edx
div    %r14d
add    %edx,%ebx
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1189 <polyRollDice+0x59>
xor    %eax,%eax
call   1050 <randomMT@plt>
mov    %eax,%r12d
test   %eax,%eax
jne    1150 <polyRollDice+0x20>
mov    %r15,%rdi
call   1040 <printf@plt>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    1150 <polyRollDice+0x20>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@polyRollDice.tally = internal global i32 0
@.str = [31 x i8] c"Uh oh, PRNG returned a zero!!!\00"
@.str.1 = [2 x i8] c"\07\00"
define i32 @polyRollDice(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = call i32 (...) @randomMT()
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %10
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = urem i32 %18, %19
%21 = add i32 %20, 1
%22 = load i32, i32* %5
%23 = add i32 %22, %21
store i32 %23, i32* %5
br label %24
24: ; preds = %17
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
br label %7
27: ; preds = %7
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@.str = [31 x i8] c"Uh oh, PRNG returned a zero!!!\00"
define i32 @polyRollDice(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %18
4: ; preds = %2, %12
%5 = phi i32 [ %16, %12 ], [ %0, %2 ]
%6 = phi i32 [ %15, %12 ], [ 0, %2 ]
%7 = tail call i32 (...) @randomMT()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @putchar(i32 7)
br label %12
12: ; preds = %9, %4
%13 = urem i32 %7, %1
%14 = add i32 %6, 1
%15 = add i32 %14, %13
%16 = add nsw i32 %5, -1
%17 = icmp sgt i32 %5, 1
br i1 %17, label %4, label %18
18: ; preds = %12, %2
%19 = phi i32 [ 0, %2 ], [ %15, %12 ]
ret i32 %19
}