#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  int up_to;
  int how_many = 1;
  long my_random();
  if (argc < 2 || argc > 3) {
    fprintf(stderr, "Usage: %s up_to [how_many]\n", argv[0]);
    exit(1);
  }
  up_to = atoi(argv[1]);
  if (argc == 3) {
    how_many = atoi(argv[2]);
  }
  srandom(time(0));
  for (i = 0; i < how_many; i++) {
    printf("%ld\n", my_random(up_to));
  }
  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)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11a1 <main+0x31>
cmpl   $0x3,-0x8(%rbp)
jle    11c7 <main+0x57>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11f1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1239 <main+0xc9>
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1030 <my_random@plt>
mov    %rax,%rsi
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1206 <main+0x96>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    -0x4(%r15),%eax
cmp    $0xfffffffd,%eax
jbe    11e6 <main+0x76>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    $0x1,%ebp
cmp    $0x3,%r15d
jne    11a7 <main+0x37>
mov    0x10(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
test   %ebp,%ebp
jle    11d9 <main+0x69>
lea    0xe5c(%rip),%r14
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <my_random@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe07(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s up_to [how_many]\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp eq i32 %0, 3
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %15, %10
%20 = phi i32 [ %18, %15 ], [ 1, %10 ]
%21 = tail call i32 @time(i32 0)
%22 = tail call i32 @srandom(i32 %21)
%23 = icmp sgt i32 %20, 0
br i1 %23, label %24, label %30
24: ; preds = %19, %24
%25 = phi i32 [ %28, %24 ], [ 0, %19 ]
%26 = tail call i64 (i32, ...) bitcast (i64 (...)* @my_random to i64 (i32, ...)*)(i32 %13)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %26)
%28 = add nuw nsw i32 %25, 1
%29 = icmp eq i32 %28, %20
br i1 %29, label %30, label %24
30: ; preds = %24, %19
ret i32 0
}