#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  unsigned long tv_sec;
  unsigned long tv_usec;
};
struct TYPE_3__ {
  unsigned long tv_sec;
  unsigned long tv_usec;
};
struct rusage {
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ RUSAGE_SELF;
int getrusage(int /*<<< orphan*/, struct rusage *);
char *malloc(unsigned long);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned long);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, double);
int /*<<< orphan*/ read(int, char *, unsigned long);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  if (argc < 3) {
    perror("not enough arguments\n");
    return -1;
  }
  unsigned long iter = strtoul(argv[1], NULL, 10);
  unsigned long size = strtoul(argv[2], NULL, 10);
  char *data = malloc(size);
  if (data == NULL) {
    perror("malloc fail\n");
    return 1;
  }
  int urandom_desc = open("/dev/urandom", O_RDONLY);
  if (urandom_desc == -1) {
    perror("open fail");
    return 2;
  }
  for (unsigned long i = 0; i < iter; i++) {
    read(urandom_desc, data, size);
  }
  struct rusage u;
  int c = getrusage(RUSAGE_SELF, &u);
  if (c == -1) {
    perror("getrusage fail\n");
    return 3;
  }
  unsigned long s = u.ru_utime.tv_sec + u.ru_stime.tv_sec;
  unsigned long us = u.ru_utime.tv_usec + u.ru_stime.tv_usec;
  double t = s + ((double)us / (double)1000000);
  printf("Urandom:%lu * %lu B in %lf s\n", iter, size, t);
  memset(data, 0, size);
  data[0] = 'a';
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe86(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <main+0x1ef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121f <main+0x9f>
lea    0xe38(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    136f <main+0x1ef>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1259 <main+0xd9>
lea    0xe18(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    136f <main+0x1ef>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1290 <main+0x110>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <read@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1261 <main+0xe1>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    -0x58(%rbp),%rsi
call   1080 <getrusage@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    12c7 <main+0x147>
lea    0xdb4(%rip),%rdi
call   1090 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    136f <main+0x1ef>
mov    -0x58(%rbp),%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x70(%rbp)
movaps 0xd24(%rip),%xmm3
movq   -0x68(%rbp),%xmm0
punpckldq %xmm3,%xmm0
movapd 0xd23(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x70(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0xcd4(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsd  -0x78(%rbp),%xmm0
lea    0xd2d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rax
movb   $0x61,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x2,%edi
jle    12c3 <main+0x143>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     12d6 <main+0x156>
mov    %rax,%r12
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12e9 <main+0x169>
test   %r14,%r14
je     1213 <main+0x93>
mov    %eax,%ebp
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <read@plt>
add    $0xffffffffffffffff,%rbx
jne    1200 <main+0x80>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1080 <getrusage@plt>
cmp    $0xffffffff,%eax
je     12fc <main+0x17c>
mov    (%rsp),%rax
mov    0x8(%rsp),%rcx
add    0x10(%rsp),%rax
add    0x18(%rsp),%rcx
movq   %rax,%xmm0
movdqa 0xdb3(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xdb7(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movq   %rcx,%xmm4
punpckldq %xmm1,%xmm4
subpd  %xmm2,%xmm4
movapd %xmm4,%xmm0
unpckhpd %xmm4,%xmm0
addsd  %xmm4,%xmm0
divsd  0xd96(%rip),%xmm0
addsd  %xmm3,%xmm0
lea    0xddd(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <printf@plt>
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
movb   $0x61,(%r12)
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5e(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%ebp
jmp    12b4 <main+0x134>
lea    0xd61(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebp
jmp    12b4 <main+0x134>
lea    0xd68(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%ebp
jmp    12b4 <main+0x134>
lea    0xd5f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%ebp
jmp    12b4 <main+0x134>

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@.str = [22 x i8] c"not enough arguments\0A\00"
@.str.1 = [13 x i8] c"malloc fail\0A\00"
@.str.2 = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.3 = [10 x i8] c"open fail\00"
@RUSAGE_SELF = global i32 0
@.str.4 = [16 x i8] c"getrusage fail\0A\00"
@.str.5 = [30 x i8] c"Urandom:%lu * %lu B in %lf s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca %struct.rusage
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %92
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strtoul(i8* %23, i32* null, i32 10)
store i64 %24, i64* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strtoul(i8* %27, i32* null, i32 10)
store i64 %28, i64* %7
%29 = load i64, i64* %7
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %92
35: ; preds = %20
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %92
42: ; preds = %35
store i64 0, i64* %10
br label %43
43: ; preds = %52, %42
%44 = load i64, i64* %10
%45 = load i64, i64* %6
%46 = icmp ult i64 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i32, i32* %9
%49 = load i8*, i8** %8
%50 = load i64, i64* %7
%51 = call i32 @read(i32 %48, i8* %49, i64 %50)
br label %52
52: ; preds = %47
%53 = load i64, i64* %10
%54 = add i64 %53, 1
store i64 %54, i64* %10
br label %43
55: ; preds = %43
%56 = load i32, i32* @RUSAGE_SELF
%57 = call i32 @getrusage(i32 %56, %struct.rusage* %11)
store i32 %57, i32* %12
%58 = load i32, i32* %12
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %92
62: ; preds = %55
%63 = getelementptr inbounds %struct.rusage, %struct.rusage* %11, i32 0, i32 1
%64 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %63, i32 0, i32 0
%65 = load i64, i64* %64
%66 = getelementptr inbounds %struct.rusage, %struct.rusage* %11, i32 0, i32 0
%67 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %66, i32 0, i32 0
%68 = load i64, i64* %67
%69 = add i64 %65, %68
store i64 %69, i64* %13
%70 = getelementptr inbounds %struct.rusage, %struct.rusage* %11, i32 0, i32 1
%71 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %70, i32 0, i32 1
%72 = load i64, i64* %71
%73 = getelementptr inbounds %struct.rusage, %struct.rusage* %11, i32 0, i32 0
%74 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %73, i32 0, i32 1
%75 = load i64, i64* %74
%76 = add i64 %72, %75
store i64 %76, i64* %14
%77 = load i64, i64* %13
%78 = uitofp i64 %77 to double
%79 = load i64, i64* %14
%80 = uitofp i64 %79 to double
%81 = fdiv double %80, 1.000000e+06
%82 = fadd double %78, %81
store double %82, double* %15
%83 = load i64, i64* %6
%84 = load i64, i64* %7
%85 = load double, double* %15
%86 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %83, i64 %84, double %85)
%87 = load i8*, i8** %8
%88 = load i64, i64* %7
%89 = call i32 @memset(i8* %87, i32 0, i64 %88)
%90 = load i8*, i8** %8
%91 = getelementptr inbounds i8, i8* %90, i64 0
store i8 97, i8* %91
store i32 0, i32* %3
br label %92
92: ; preds = %62, %60, %40, %33, %18
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@.str = [22 x i8] c"not enough arguments\0A\00"
@.str.1 = [13 x i8] c"malloc fail\0A\00"
@.str.2 = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.3 = [10 x i8] c"open fail\00"
@RUSAGE_SELF = global i32 0
@.str.4 = [16 x i8] c"getrusage fail\0A\00"
@.str.5 = [30 x i8] c"Urandom:%lu * %lu B in %lf s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.rusage
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %57
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strtoul(i8* nocapture %9, i32* null, i32 10)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoul(i8* nocapture %12, i32* null, i32 10)
%14 = tail call i8* @malloc(i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %57
18: ; preds = %7
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = icmp eq i64 %10, 0
br i1 %23, label %26, label %31
24: ; preds = %18
%25 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %57
26: ; preds = %31, %22
%27 = bitcast %struct.rusage* %3 to i8*
%28 = load i32, i32* @RUSAGE_SELF
%29 = call i32 @getrusage(i32 %28, %struct.rusage* %3)
%30 = icmp eq i32 %29, -1
br i1 %30, label %36, label %38
31: ; preds = %22, %31
%32 = phi i64 [ %34, %31 ], [ 0, %22 ]
%33 = tail call i32 @read(i32 %20, i8* %14, i64 %13)
%34 = add nuw i64 %32, 1
%35 = icmp eq i64 %34, %10
br i1 %35, label %26, label %31
36: ; preds = %26
%37 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %55
38: ; preds = %26
%39 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 1, i32 0
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 0
%42 = load i64, i64* %41
%43 = add i64 %42, %40
%44 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 1, i32 1
%45 = load i64, i64* %44
%46 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0, i32 1
%47 = load i64, i64* %46
%48 = add i64 %47, %45
%49 = uitofp i64 %43 to double
%50 = uitofp i64 %48 to double
%51 = fdiv double %50, 1.000000e+06
%52 = fadd double %51, %49
%53 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i64 %10, i64 %13, double %52)
%54 = call i32 @memset(i8* %14, i32 0, i64 %13)
store i8 97, i8* %14
br label %55
55: ; preds = %38, %36
%56 = phi i32 [ 3, %36 ], [ 0, %38 ]
br label %57
57: ; preds = %16, %55, %24, %5
%58 = phi i32 [ -1, %5 ], [ 1, %16 ], [ 2, %24 ], [ %56, %55 ]
ret i32 %58
}