#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
char *strtok(char *, char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  const char s[2] = "d";
  char *token;
  int num_of_dices;
  int num_of_faces;
  if (!(token = strtok(argv[1], s))) {
    puts("wrong input, insert NdM");
    exit(-1);
  }
  num_of_dices = atoi(token);
  token = strtok(NULL, s);
  num_of_faces = atoi(token);
  if (num_of_faces <= 0 || num_of_faces > 100) {
    puts("Dice faces must be between 1-100");
    exit(-1);
  }
  printf("%dd%d dice(s) roll... ", num_of_dices, num_of_faces);
  srand(time(NULL));
  for (int i = 0; i < num_of_dices; i++)
    printf("%d ", (rand() % num_of_faces) + 1);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe63(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x12(%rbp),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11d6 <main+0x56>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
lea    -0x12(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    1213 <main+0x93>
cmpl   $0x64,-0x28(%rbp)
jle    1229 <main+0xa9>
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    128c <main+0x10c>
mov    $0x0,%al
call   10a0 <rand@plt>
cltd
idivl  -0x28(%rbp)
mov    %edx,%esi
add    $0x1,%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1254 <main+0xd4>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movw   $0x64,0xe(%rsp)
mov    0x8(%rsi),%rdi
lea    0xe(%rsp),%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1243 <main+0xb3>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    0xe(%rsp),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
lea    -0x65(%r14),%eax
cmp    $0xffffff9b,%eax
jbe    124c <main+0xbc>
lea    0xe51(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
test   %ebx,%ebx
jle    122d <main+0x9d>
lea    0xe43(%rip),%r15
nopl   (%rax)
xor    %eax,%eax
call   10b0 <rand@plt>
cltd
idiv   %r14d
lea    0x1(%rdx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebx
jne    1210 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdb6(%rip),%rdi
jmp    1253 <main+0xc3>
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.s = [2 x i8] c"d\00"
@.str = [24 x i8] c"wrong input, insert NdM\00"
@.str.1 = [33 x i8] c"Dice faces must be between 1-100\00"
@.str.2 = [23 x i8] c"%dd%d dice(s) roll... \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [2 x i8]* %6 to i8*
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%16 = call i8* @strtok(i8* %14, i8* %15)
store i8* %16, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %7
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%25 = call i8* @strtok(i8* null, i8* %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp sle i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %21
%31 = load i32, i32* %9
%32 = icmp sgt i32 %31, 100
br i1 %32, label %33, label %36
33: ; preds = %30, %21
%34 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %30
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %38)
%40 = call i32 @time(i32* null)
%41 = call i32 @srand(i32 %40)
store i32 0, i32* %10
br label %42
42: ; preds = %52, %36
%43 = load i32, i32* %10
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = call i32 (...) @rand()
%48 = load i32, i32* %9
%49 = srem i32 %47, %48
%50 = add nsw i32 %49, 1
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %46
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %42
55: ; preds = %42
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"wrong input, insert NdM\00"
@.str.1 = [33 x i8] c"Dice faces must be between 1-100\00"
@.str.2 = [23 x i8] c"%dd%d dice(s) roll... \00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 100, i16* %3
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i8* @strtok(i8* %6, i8* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = tail call i32 @atoi(i8* %7)
%14 = call i8* @strtok(i8* null, i8* %4)
%15 = tail call i32 @atoi(i8* %14)
%16 = add i32 %15, -101
%17 = icmp ult i32 %16, -100
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %12
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %15)
%23 = tail call i32 @time(i32* null)
%24 = tail call i32 @srand(i32 %23)
%25 = icmp sgt i32 %13, 0
br i1 %25, label %28, label %26
26: ; preds = %28, %21
%27 = tail call i32 @putchar(i32 10)
ret i32 0
28: ; preds = %21, %28
%29 = phi i32 [ %34, %28 ], [ 0, %21 ]
%30 = tail call i32 (...) @rand()
%31 = srem i32 %30, %15
%32 = add nsw i32 %31, 1
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = add nuw nsw i32 %29, 1
%35 = icmp eq i32 %34, %13
br i1 %35, label %26, label %28
}