#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_MAX;
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: %s [count] (max)\n", argv[0]);
    return 1;
  }
  srand(time(NULL));
  for (int i = 0; i < atoi(argv[1]); ++i)
    printf("%d\n", rand() % ((argc == 3) ? atoi(argv[2]) : RAND_MAX));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122b <main+0xdb>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1224 <main+0xd4>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11f1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    11fd <main+0xad>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <main+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x1,%edi
jg     117c <main+0x2c>
mov    0x0(%r13),%rsi
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebp
jmp    11f3 <main+0xa3>
mov    %edi,%r15d
xor    %ebp,%ebp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    0x8(%r13),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11f3 <main+0xa3>
lea    0xe76(%rip),%r14
mov    0x2e3e(%rip),%r12
xor    %ebx,%ebx
jmp    11d7 <main+0x87>
xchg   %ax,%ax
mov    (%r12),%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
mov    0x8(%r13),%rdi
call   1060 <atoi@plt>
cmp    %eax,%ebx
jge    11f3 <main+0xa3>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
cmp    $0x3,%r15d
jne    11b0 <main+0x60>
mov    0x10(%r13),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
jmp    11b4 <main+0x64>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Usage: %s [count] (max)\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@RAND_MAX = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %3
br label %43
14: ; preds = %2
%15 = call i32 @time(i32* null)
%16 = call i32 @srand(i32 %15)
store i32 0, i32* %6
br label %17
17: ; preds = %39, %14
%18 = load i32, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp slt i32 %18, %22
br i1 %23, label %24, label %42
24: ; preds = %17
%25 = call i32 (...) @rand()
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
br label %35
33: ; preds = %24
%34 = load i32, i32* @RAND_MAX
br label %35
35: ; preds = %33, %28
%36 = phi i32 [ %32, %28 ], [ %34, %33 ]
%37 = srem i32 %25, %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %17
42: ; preds = %17
store i32 0, i32* %3
br label %43
43: ; preds = %42, %9
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [25 x i8] c"Usage: %s [count] (max)\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@RAND_MAX = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %33
7: ; preds = %2
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srand(i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %7
%15 = icmp eq i32 %0, 3
%16 = getelementptr inbounds i8*, i8** %1, i64 2
br label %17
17: ; preds = %14, %25
%18 = phi i32 [ 0, %14 ], [ %29, %25 ]
%19 = tail call i32 (...) @rand()
br i1 %15, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %16
%22 = tail call i32 @atoi(i8* %21)
br label %25
23: ; preds = %17
%24 = load i32, i32* @RAND_MAX
br label %25
25: ; preds = %23, %20
%26 = phi i32 [ %22, %20 ], [ %24, %23 ]
%27 = srem i32 %19, %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i32 %18, 1
%30 = load i8*, i8** %10
%31 = tail call i32 @atoi(i8* %30)
%32 = icmp slt i32 %29, %31
br i1 %32, label %17, label %33
33: ; preds = %25, %7, %4
%34 = phi i32 [ 1, %4 ], [ 0, %7 ], [ 0, %25 ]
ret i32 %34
}