#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 rand();
void DoPlayerRoll(long long int *playerXroll, unsigned int numberofdice,
                  unsigned int numberofsides, const int *MaxAcceptedRand) {
  int i;
  int Rand;
  for (i = 0; i < numberofdice; i++) {
    do {
      Rand = rand();
    } while (Rand > (*MaxAcceptedRand));
    *playerXroll = (*playerXroll) + (Rand % numberofsides);
  }
}


x86 assembly (clang, -O0):
<DoPlayerRoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1180 <DoPlayerRoll+0x70>
jmp    113e <DoPlayerRoll+0x2e>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jg     113e <DoPlayerRoll+0x2e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %edx,%eax
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <DoPlayerRoll+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoPlayerRoll>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     114b <DoPlayerRoll+0x3b>
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cmp    (%rbx),%eax
jg     1130 <DoPlayerRoll+0x20>
xor    %edx,%edx
div    %r14d
add    %rdx,(%r15)
add    $0x1,%ebp
cmp    %r12d,%ebp
jne    1130 <DoPlayerRoll+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @DoPlayerRoll(i64* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i64* %0, i64** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
br label %11
11: ; preds = %32, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
br label %16
16: ; preds = %18, %15
%17 = call i32 (...) @rand()
store i32 %17, i32* %10
br label %18
18: ; preds = %16
%19 = load i32, i32* %10
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = icmp sgt i32 %19, %21
br i1 %22, label %16, label %23
23: ; preds = %18
%24 = load i64*, i64** %5
%25 = load i64, i64* %24
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = urem i32 %26, %27
%29 = zext i32 %28 to i64
%30 = add nsw i64 %25, %29
%31 = load i64*, i64** %5
store i64 %30, i64* %31
br label %32
32: ; preds = %23
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %11
35: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @DoPlayerRoll(i64* nocapture %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %19, label %6
6: ; preds = %4, %12
%7 = phi i32 [ %17, %12 ], [ 0, %4 ]
br label %8
8: ; preds = %6, %8
%9 = tail call i32 (...) @rand()
%10 = load i32, i32* %3
%11 = icmp sgt i32 %9, %10
br i1 %11, label %8, label %12
12: ; preds = %8
%13 = load i64, i64* %0
%14 = urem i32 %9, %2
%15 = zext i32 %14 to i64
%16 = add nsw i64 %13, %15
store i64 %16, i64* %0
%17 = add nuw i32 %7, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %19, label %6
19: ; preds = %12, %4
ret void
}