#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*/ O_RDONLY;
int atoi(char const *);
int /*<<< orphan*/ bench(int, int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, const char **argv) {
  if (argc > 1) {
    int i;
    int fd = open("/dev/urandom", O_RDONLY);
    if (fd < 0)
      error(1, errno, "Can't open dev/urandom");
    printf("size,      arc4rand,\tsysrand,\tspeed-up\n");
    for (i = 1; i < argc; ++i) {
      int z = atoi(argv[i]);
      if (z <= 0)
        continue;
      bench(fd, z, 8192);
    }
    close(fd);
  }
  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   $0x1,-0x8(%rbp)
jle    1224 <main+0xc4>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11bc <main+0x5c>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe56(%rip),%rdx
call   1060 <error@plt>
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121c <main+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11fe <main+0x9e>
jmp    120e <main+0xae>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x2000,%edx
call   1030 <bench@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <main+0x6f>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x2,%edi
jl     1207 <main+0xa7>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %edi,%r14d
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    11ad <main+0x4d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdx
mov    $0x1,%edi
call   1060 <error@plt>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%ebp
mov    $0x1,%ebx
jmp    11d9 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11f7 <main+0x97>
mov    (%r12,%rbx,8),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    11d0 <main+0x70>
mov    %r15d,%edi
mov    %eax,%esi
mov    $0x2000,%edx
call   1040 <bench@plt>
jmp    11d0 <main+0x70>
mov    %r15d,%edi
call   1050 <close@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [23 x i8] c"Can't open dev/urandom\00"
@.str.2 = [40 x i8] c"size, arc4rand,\09sysrand,\09speed-up\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
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %45
11: ; preds = %2
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = call i32 @error(i32 1, i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %16, %11
%20 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %21
21: ; preds = %39, %19
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp sle i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %25
br label %39
35: ; preds = %25
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = call i32 @bench(i32 %36, i32 %37, i32 8192)
br label %39
39: ; preds = %35, %34
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %21
42: ; preds = %21
%43 = load i32, i32* %7
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %42, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [23 x i8] c"Can't open dev/urandom\00"
@str = [39 x i8] c"size, arc4rand,\09sysrand,\09speed-up\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @errno
%10 = tail call i32 @error(i32 1, i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %4, %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %11, %22
%15 = phi i64 [ 1, %11 ], [ %23, %22 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = icmp slt i32 %18, 1
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = tail call i32 @bench(i32 %6, i32 %18, i32 8192)
br label %22
22: ; preds = %14, %20
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %14
25: ; preds = %22
%26 = tail call i32 @close(i32 %6)
br label %27
27: ; preds = %25, %2
ret i32 0
}