#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 */
typedef int /*<<< orphan*/ DIE_SIDE_POINTS;

/* Variables and functions */
int const rand();
int RollDiceSum(int count) {
  const static int DIE_SIDE_POINTS[] = {
      [0] = 1, [1] = 2, [2] = 3, [3] = 4, [4] = 5, [5] = 6};
  const int DIE_SIDE_COUNT =
      (int)(sizeof(DIE_SIDE_POINTS) / sizeof(DIE_SIDE_POINTS[0]));
  int sum = 0;
  while (count > 0) {
    sum += DIE_SIDE_POINTS[rand() % DIE_SIDE_COUNT];
    --count;
  }
  return sum;
}


x86 assembly (clang, -O0):
<RollDiceSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x6,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1163 <RollDiceSum+0x53>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xeb4(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1129 <RollDiceSum+0x19>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RollDiceSum>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    1164 <RollDiceSum+0x54>
mov    %edi,%ebx
add    $0x1,%ebx
lea    0xedc(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@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
cltq
add    (%r14,%rax,4),%ebp
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1130 <RollDiceSum+0x20>
jmp    1166 <RollDiceSum+0x56>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@RollDiceSum.DIE_SIDE_POINTS = internal constant [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6]
define i32 @RollDiceSum(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 6, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %8, %1
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 6
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [6 x i32], [6 x i32]* @RollDiceSum.DIE_SIDE_POINTS, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = load i32, i32* %4
%15 = add nsw i32 %14, %13
store i32 %15, i32* %4
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
br label %5
18: ; preds = %5
%19 = load i32, i32* %4
ret i32 %19
}

LLVM IR (-O2):
@RollDiceSum.DIE_SIDE_POINTS = internal unnamed_addr constant [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6]
define i32 @RollDiceSum(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %14
3: ; preds = %1, %3
%4 = phi i32 [ %11, %3 ], [ 0, %1 ]
%5 = phi i32 [ %12, %3 ], [ %0, %1 ]
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 6
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [6 x i32], [6 x i32]* @RollDiceSum.DIE_SIDE_POINTS, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = add nsw i32 %10, %4
%12 = add nsw i32 %5, -1
%13 = icmp ugt i32 %5, 1
br i1 %13, label %3, label %14
14: ; preds = %3, %1
%15 = phi i32 [ 0, %1 ], [ %11, %3 ]
ret i32 %15
}