#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 *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void roll(int nTimes) {
  if (nTimes <= 0) {
    printf("cannot roll 0 or less times.\n");
    return;
  }
  int i = 1;
  srand(time(NULL));
  printf("Rolling the Dice...\n");
  while (i <= nTimes) {
    int d1 = rand() % 20 + 1;
    int d2 = rand() % 20 + 1;
    if (d1 == 20) {
      printf("Natural twenty!\n");
    }
    printf("die1 was:%d  \ndie2 was:%d\n", d1, d2);
    if (d2 == 20) {
      printf("Natural twenty!\n");
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<roll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1168 <roll+0x28>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1215 <roll+0xd5>
movl   $0x1,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1215 <roll+0xd5>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cmpl   $0x14,-0xc(%rbp)
jne    11db <roll+0x9b>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x14,-0x10(%rbp)
jne    1207 <roll+0xc7>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118d <roll+0x4d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roll>:
test   %edi,%edi
jle    1235 <roll+0xe5>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%r14
lea    0xe72(%rip),%r15
jmp    119a <roll+0x4a>
add    $0xffffffff,%r12d
je     1226 <roll+0xd6>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r13d
add    $0x1,%r13d
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebx
cltq
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%ebp
neg    %ebp
cmp    $0x14,%r13d
jne    11fc <roll+0xac>
mov    %r14,%rdi
call   1030 <puts@plt>
add    %ebp,%ebx
add    $0x1,%ebx
mov    %r15,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x14,%ebx
jne    1190 <roll+0x40>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1190 <roll+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe03(%rip),%rdi
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"cannot roll 0 or less times.\0A\00"
@.str.1 = [21 x i8] c"Rolling the Dice...\0A\00"
@.str.2 = [17 x i8] c"Natural twenty!\0A\00"
@.str.3 = [27 x i8] c"die1 was:%d \0Adie2 was:%d\0A\00"
define void @roll(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %40
10: ; preds = %1
store i32 1, i32* %3
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %37, %10
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %40
18: ; preds = %14
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 20
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 20
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 20
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %18
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 20
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %14
40: ; preds = %8, %14
ret void
}

LLVM IR (-O2):
@.str.3 = [27 x i8] c"die1 was:%d \0Adie2 was:%d\0A\00"
@str = [20 x i8] c"Rolling the Dice...\00"
@str.5 = [16 x i8] c"Natural twenty!\00"
@str.6 = [29 x i8] c"cannot roll 0 or less times.\00"
define void @roll(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
br label %28
5: ; preds = %1
%6 = tail call i32 @time(i32* null)
%7 = tail call i32 @srand(i32 %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %5, %25
%10 = phi i32 [ 1, %5 ], [ %26, %25 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 20
%13 = add nsw i32 %12, 1
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 20
%16 = add nsw i32 %15, 1
%17 = icmp eq i32 %13, 20
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
br label %20
20: ; preds = %18, %9
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %16)
%22 = icmp eq i32 %16, 20
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = add nuw i32 %10, 1
%27 = icmp eq i32 %10, %0
br i1 %27, label %28, label %9
28: ; preds = %25, %3
ret void
}