#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
long long get_ustime_sec();
int /*<<< orphan*/ stderr;
long long bench_urandom(int times) {
  int i;
  FILE *urandom;
  unsigned char key[1024];
  long long start = get_ustime_sec();
  for (i = 0; i < times; i++) {
    urandom = fopen("/dev/urandom", "r");
    if (urandom == NULL) {
      fprintf(stderr, "Cannot open /dev/urandom!\n");
      return 0;
    }
    fread(key, sizeof(char), 1024, urandom);
    fclose(urandom);
  }
  return (get_ustime_sec() - start);
}


x86 assembly (clang, -O0):
<bench_urandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x0,%al
call   1070 <get_ustime_sec@plt>
mov    %rax,-0x428(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f4 <bench_urandom+0xa4>
lea    0xe7a(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <bench_urandom+0x73>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1206 <bench_urandom+0xb6>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1173 <bench_urandom+0x23>
mov    $0x0,%al
call   1070 <get_ustime_sec@plt>
sub    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_urandom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <get_ustime_sec@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11c5 <bench_urandom+0x75>
lea    0xe88(%rip),%r15
lea    0xe8e(%rip),%r13
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d1 <bench_urandom+0x81>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0xffffffff,%ebp
jne    1190 <bench_urandom+0x40>
xor    %eax,%eax
call   1070 <get_ustime_sec@plt>
sub    %r14,%rax
jmp    11e8 <bench_urandom+0x98>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Cannot open /dev/urandom!\0A\00"
define i64 @bench_urandom(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca i64
store i32 %0, i32* %3
%8 = call i64 (...) @get_ustime_sec()
store i64 %8, i64* %7
store i32 0, i32* %4
br label %9
9: ; preds = %26, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %2
br label %33
20: ; preds = %13
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32 @fread(i8* %21, i32 1, i32 1024, i32* %22)
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %9
29: ; preds = %9
%30 = call i64 (...) @get_ustime_sec()
%31 = load i64, i64* %7
%32 = sub nsw i64 %30, %31
store i64 %32, i64* %2
br label %33
33: ; preds = %29, %17
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Cannot open /dev/urandom!\0A\00"
define i64 @bench_urandom(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i64 (...) @get_ustime_sec()
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %18
6: ; preds = %1, %13
%7 = phi i32 [ %16, %13 ], [ 0, %1 ]
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %21
13: ; preds = %6
%14 = call i32 @fread(i8* %3, i32 1, i32 1024, i32* %8)
%15 = tail call i32 @fclose(i32* %8)
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, %0
br i1 %17, label %18, label %6
18: ; preds = %13, %1
%19 = tail call i64 (...) @get_ustime_sec()
%20 = sub nsw i64 %19, %4
br label %21
21: ; preds = %18, %10
%22 = phi i64 [ 0, %10 ], [ %20, %18 ]
ret i64 %22
}