#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 scalar_t__ time_t;
struct tm {
  int tm_mon;
  int tm_mday;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ fname;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ W_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
double difftime(scalar_t__, scalar_t__);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct tm *localtime(scalar_t__ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int);
int /*<<< orphan*/ srand(scalar_t__);
char *strerror(int /*<<< orphan*/);
scalar_t__ time(scalar_t__ *);
int main(int argc, char **argv) {
  char buffer[1000];
  char fname[30];
  int fd, ret, magic_buffer_size, cnt = 0;
  time_t t1, t2;
  double dif;
  time_t current;
  struct tm *timep;
  FILE *fd_file;
  if (argc != 2) {
    printf("Usage: %s /dev/device_to_test\n", argv[0]);
    return -1;
  }
  current = time(NULL);
  timep = localtime(&current);
  memset(fname, 0, sizeof(fname));
  snprintf(fname, sizeof(fname), "stats-%.2d-%.2d-%.2d-%.2d-%.2d-%.2d.txt",
           timep->tm_mon + 1, timep->tm_mday, timep->tm_year + 1900,
           timep->tm_hour, timep->tm_min, timep->tm_sec);
  fd_file = fopen(fname, "a+");
  if (!fd_file) {
    perror("error opening file");
    return -1;
  }
  srand(time(NULL));
  while (1) {
    if (time(&t1) < 0) {
      perror("time_t t1");
      fclose(fd_file);
      return -1;
    }
    fd = open(argv[1], O_RDONLY);
    if (fd < 0) {
      perror("error opening device");
      fclose(fd_file);
      return -1;
    }
    magic_buffer_size = rand() % sizeof(buffer);
    memset(buffer, 0, sizeof(buffer));
    ret = access(fname, W_OK);
    if (ret < 0) {
      close(fd);
      perror("Error");
      return -1;
    }
    ret = read(fd, buffer, magic_buffer_size);
    if (ret < 0) {
      fprintf(fd_file, "[%s] error reading buffer - [%s]\n", argv[1],
              strerror(errno));
      fflush(fd_file);
      perror("error reading buffer from device");
      return -1;
    }
    if (time(&t2) < 0) {
      perror("time_t t2");
      fclose(fd_file);
      return -1;
    }
    dif = difftime(t2, t1);
    printf("Seconds: [%d] - Test Number: [%d] - Read [%d] bytes\n", (int)dif,
           cnt, ret);
    fprintf(fd_file, "Seconds: [%.2f] - Test number: [%d] - Read [%d] bytes\n",
            dif, cnt, ret);
    fflush(fd_file);
    cnt++;
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x430(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     126e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %rax,-0x450(%rbp)
lea    -0x450(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x458(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1080 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x458(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x458(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x458(%rbp),%rax
mov    0x8(%rax),%r9d
add    $0x76c,%r9d
mov    -0x458(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x458(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x458(%rbp),%rax
mov    0x14(%rax),%eax
mov    $0x1e,%esi
lea    0xd1f(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xd27(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x460(%rbp)
cmpq   $0x0,-0x460(%rbp)
jne    1352 <main+0x132>
lea    0xd09(%rip),%rdi
call   1120 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %rax,%rdi
call   10b0 <srand@plt>
lea    -0x438(%rbp),%rdi
call   10d0 <time@plt>
cmp    $0x0,%rax
jge    139d <main+0x17d>
lea    0xcdd(%rip),%rdi
call   1120 <perror@plt>
mov    -0x460(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    13ea <main+0x1ca>
lea    0xc9a(%rip),%rdi
call   1120 <perror@plt>
mov    -0x460(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
mov    $0x0,%al
call   1140 <rand@plt>
cltq
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x42c(%rbp)
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    0x2bba(%rip),%rax
mov    (%rax),%esi
call   1100 <access@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jge    1463 <main+0x243>
mov    -0x424(%rbp),%edi
call   1090 <close@plt>
lea    0xc2a(%rip),%rdi
call   1120 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
mov    -0x424(%rbp),%edi
lea    -0x400(%rbp),%rsi
mov    -0x42c(%rbp),%edx
call   10a0 <read@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jge    14fc <main+0x2dc>
mov    -0x460(%rbp),%rax
mov    %rax,-0x470(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x468(%rbp)
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x470(%rbp),%rdi
mov    -0x468(%rbp),%rdx
mov    %rax,%rcx
lea    0xbb1(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x460(%rbp),%rdi
call   10e0 <fflush@plt>
lea    0xbb9(%rip),%rdi
call   1120 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
lea    -0x440(%rbp),%rdi
call   10d0 <time@plt>
cmp    $0x0,%rax
jge    1536 <main+0x316>
lea    0xbac(%rip),%rdi
call   1120 <perror@plt>
mov    -0x460(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c7 <main+0x3a7>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   1060 <difftime@plt>
movsd  %xmm0,-0x448(%rbp)
ff
cvttsd2si -0x448(%rbp),%esi
ff
mov    -0x430(%rbp),%edx
mov    -0x428(%rbp),%ecx
lea    0xb63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x460(%rbp),%rdi
movsd  -0x448(%rbp),%xmm0
ff
mov    -0x430(%rbp),%edx
mov    -0x428(%rbp),%ecx
lea    0xb6f(%rip),%rsi
mov    $0x1,%al
call   10c0 <fprintf@plt>
mov    -0x460(%rbp),%rdi
call   10e0 <fflush@plt>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
mov    -0x424(%rbp),%edi
call   1090 <close@plt>
jmp    1363 <main+0x143>
mov    -0x4(%rbp),%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
je     1261 <main+0x41>
mov    (%r15),%rsi
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10d0 <time@plt>
mov    %rax,0x20(%rsp)
lea    0x20(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
lea    0x30(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1080 <memset@plt>
mov    (%rbx),%ecx
mov    0x4(%rbx),%r8d
mov    $0x76c,%r9d
add    0x8(%rbx),%r9d
add    $0x1,%ecx
mov    0xc(%rbx),%eax
mov    0x10(%rbx),%ebp
mov    0x14(%rbx),%ebx
sub    $0x8,%rsp
lea    0xd6a(%rip),%rdx
mov    %r14,%rdi
mov    $0x1e,%esi
push   %rbx
push   %rbp
push   %rax
call   1070 <snprintf@plt>
add    $0x20,%rsp
lea    0xd77(%rip),%rsi
mov    %r14,%rdi
call   1110 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    12f3 <main+0xd3>
lea    0xd61(%rip),%rdi
call   1120 <perror@plt>
jmp    124a <main+0x2a>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %rax,%rdi
call   10b0 <srand@plt>
lea    0x10(%rsp),%rdi
call   10d0 <time@plt>
test   %rax,%rax
jns    132c <main+0x10c>
lea    0xd45(%rip),%rdi
call   1120 <perror@plt>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
jmp    124a <main+0x2a>
lea    0x50(%rsp),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%r15),%rdi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
test   %eax,%eax
js     145f <main+0x23f>
mov    %eax,%r12d
xor    %eax,%eax
call   1140 <rand@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
lea    0x30(%rsp),%rdi
call   1100 <access@plt>
test   %eax,%eax
js     146b <main+0x24b>
movslq %ebx,%rcx
mov    %rcx,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
shr    $0x4,%rdx
imul   $0x3e8,%edx,%eax
sub    %eax,%ecx
mov    %r12d,%edi
mov    %rbp,%rbx
mov    %rbp,%rsi
mov    %ecx,%edx
call   10a0 <read@plt>
test   %eax,%eax
js     1484 <main+0x264>
mov    %eax,%r13d
lea    0x28(%rsp),%rdi
call   10d0 <time@plt>
test   %rax,%rax
js     14cb <main+0x2ab>
mov    0x28(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1060 <difftime@plt>
movsd  %xmm0,0x18(%rsp)
cvttsd2si %xmm0,%esi
lea    0xcce(%rip),%rdi
mov    %r14d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
lea    0xce7(%rip),%rsi
movsd  0x18(%rsp),%xmm0
mov    %r14d,%edx
mov    %r13d,%ecx
mov    $0x1,%al
call   10c0 <fprintf@plt>
mov    %rbp,%rdi
call   10e0 <fflush@plt>
add    $0x1,%r14d
mov    %r12d,%edi
call   1090 <close@plt>
lea    0x10(%rsp),%rdi
call   10d0 <time@plt>
test   %rax,%rax
mov    %rbx,%rbp
jns    1340 <main+0x120>
jmp    1311 <main+0xf1>
lea    0xc01(%rip),%rdi
jmp    1318 <main+0xf8>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xc02(%rip),%rdi
call   1120 <perror@plt>
jmp    124a <main+0x2a>
mov    0x8(%r15),%rbx
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xbe5(%rip),%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %rbp,%rdi
call   10e0 <fflush@plt>
lea    0xbe3(%rip),%rdi
call   1120 <perror@plt>
jmp    124a <main+0x2a>
lea    0xbf3(%rip),%rdi
jmp    1318 <main+0xf8>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"Usage: %s /dev/device_to_test\0A\00"
@.str.1 = [40 x i8] c"stats-%.2d-%.2d-%.2d-%.2d-%.2d-%.2d.txt\00"
@.str.2 = [3 x i8] c"a+\00"
@.str.3 = [19 x i8] c"error opening file\00"
@.str.4 = [10 x i8] c"time_t t1\00"
@O_RDONLY = global i32 0
@.str.5 = [21 x i8] c"error opening device\00"
@W_OK = global i32 0
@.str.6 = [6 x i8] c"Error\00"
@.str.7 = [34 x i8] c"[%s] error reading buffer - [%s]\0A\00"
@errno = global i32 0
@.str.8 = [33 x i8] c"error reading buffer from device\00"
@.str.9 = [10 x i8] c"time_t t2\00"
@.str.10 = [53 x i8] c"Seconds: [%d] - Test Number: [%d] - Read [%d] bytes\0A\00"
@.str.11 = [55 x i8] c"Seconds: [%.2f] - Test number: [%d] - Read [%d] bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca [30 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca double
%15 = alloca i64
%16 = alloca %struct.tm*
%17 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 -1, i32* %3
br label %141
25: ; preds = %2
%26 = call i64 @time(i64* null)
store i64 %26, i64* %15
%27 = call %struct.tm* @localtime(i64* %15)
store %struct.tm* %27, %struct.tm** %16
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 30)
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%31 = load %struct.tm*, %struct.tm** %16
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
%35 = load %struct.tm*, %struct.tm** %16
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = load %struct.tm*, %struct.tm** %16
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1900
%42 = load %struct.tm*, %struct.tm** %16
%43 = getelementptr inbounds %struct.tm, %struct.tm* %42, i32 0, i32 3
%44 = load i32, i32* %43
%45 = load %struct.tm*, %struct.tm** %16
%46 = getelementptr inbounds %struct.tm, %struct.tm* %45, i32 0, i32 4
%47 = load i32, i32* %46
%48 = load %struct.tm*, %struct.tm** %16
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 5
%50 = load i32, i32* %49
%51 = call i32 @snprintf(i8* %30, i32 30, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %37, i32 %41, i32 %44, i32 %47, i32 %50)
%52 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %53, i32** %17
%54 = load i32*, i32** %17
%55 = icmp ne i32* %54, null
br i1 %55, label %58, label %56
56: ; preds = %25
%57 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %141
58: ; preds = %25
%59 = call i64 @time(i64* null)
%60 = call i32 @srand(i64 %59)
br label %61
61: ; preds = %58, %121
%62 = call i64 @time(i64* %12)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32*, i32** %17
%67 = call i32 @fclose(i32* %66)
store i32 -1, i32* %3
br label %141
68: ; preds = %61
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 1
%71 = load i8*, i8** %70
%72 = load i32, i32* @O_RDONLY
%73 = call i32 @open(i8* %71, i32 %72)
store i32 %73, i32* %8
%74 = load i32, i32* %8
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %68
%77 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%78 = load i32*, i32** %17
%79 = call i32 @fclose(i32* %78)
store i32 -1, i32* %3
br label %141
80: ; preds = %68
%81 = call i32 (...) @rand()
%82 = sext i32 %81 to i64
%83 = urem i64 %82, 1000
%84 = trunc i64 %83 to i32
store i32 %84, i32* %10
%85 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%86 = call i32 @memset(i8* %85, i32 0, i32 1000)
%87 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%88 = load i32, i32* @W_OK
%89 = call i32 @access(i8* %87, i32 %88)
store i32 %89, i32* %9
%90 = load i32, i32* %9
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %80
%93 = load i32, i32* %8
%94 = call i32 @close(i32 %93)
%95 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %141
96: ; preds = %80
%97 = load i32, i32* %8
%98 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%99 = load i32, i32* %10
%100 = call i32 @read(i32 %97, i8* %98, i32 %99)
store i32 %100, i32* %9
%101 = load i32, i32* %9
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %114
103: ; preds = %96
%104 = load i32*, i32** %17
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 1
%107 = load i8*, i8** %106
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %104, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %107, i8* %109)
%111 = load i32*, i32** %17
%112 = call i32 @fflush(i32* %111)
%113 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %141
114: ; preds = %96
%115 = call i64 @time(i64* %13)
%116 = icmp slt i64 %115, 0
br i1 %116, label %117, label %121
117: ; preds = %114
%118 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%119 = load i32*, i32** %17
%120 = call i32 @fclose(i32* %119)
store i32 -1, i32* %3
br label %141
121: ; preds = %114
%122 = load i64, i64* %13
%123 = load i64, i64* %12
%124 = call double @difftime(i64 %122, i64 %123)
store double %124, double* %14
%125 = load double, double* %14
%126 = fptosi double %125 to i32
%127 = load i32, i32* %11
%128 = load i32, i32* %9
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0), i32 %126, i32 %127, i32 %128)
%130 = load i32*, i32** %17
%131 = load double, double* %14
%132 = load i32, i32* %11
%133 = load i32, i32* %9
%134 = call i32 (i32*, i8*, ...) @fprintf(i32* %130, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0), double %131, i32 %132, i32 %133)
%135 = load i32*, i32** %17
%136 = call i32 @fflush(i32* %135)
%137 = load i32, i32* %11
%138 = add nsw i32 %137, 1
store i32 %138, i32* %11
%139 = load i32, i32* %8
%140 = call i32 @close(i32 %139)
br label %61
141: ; preds = %117, %103, %92, %76, %64, %56, %20
%142 = load i32, i32* %3
ret i32 %142
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [31 x i8] c"Usage: %s /dev/device_to_test\0A\00"
@.str.1 = [40 x i8] c"stats-%.2d-%.2d-%.2d-%.2d-%.2d-%.2d.txt\00"
@.str.2 = [3 x i8] c"a+\00"
@.str.3 = [19 x i8] c"error opening file\00"
@.str.4 = [10 x i8] c"time_t t1\00"
@O_RDONLY = global i32 0
@.str.5 = [21 x i8] c"error opening device\00"
@W_OK = global i32 0
@.str.6 = [6 x i8] c"Error\00"
@.str.7 = [34 x i8] c"[%s] error reading buffer - [%s]\0A\00"
@errno = global i32 0
@.str.8 = [33 x i8] c"error reading buffer from device\00"
@.str.9 = [10 x i8] c"time_t t2\00"
@.str.10 = [53 x i8] c"Seconds: [%d] - Test Number: [%d] - Read [%d] bytes\0A\00"
@.str.11 = [55 x i8] c"Seconds: [%.2f] - Test number: [%d] - Read [%d] bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca [30 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%10 = bitcast i64* %5 to i8*
%11 = bitcast i64* %6 to i8*
%12 = bitcast i64* %7 to i8*
%13 = icmp eq i32 %0, 2
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %99
17: ; preds = %2
%18 = tail call i64 @time(i64* null)
store i64 %18, i64* %7
%19 = call %struct.tm* @localtime(i64* %7)
%20 = call i32 @memset(i8* %9, i32 0, i32 30)
%21 = getelementptr inbounds %struct.tm, %struct.tm* %19, i64 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
%24 = getelementptr inbounds %struct.tm, %struct.tm* %19, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %19, i64 0, i32 2
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1900
%29 = getelementptr inbounds %struct.tm, %struct.tm* %19, i64 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.tm, %struct.tm* %19, i64 0, i32 4
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.tm, %struct.tm* %19, i64 0, i32 5
%34 = load i32, i32* %33
%35 = call i32 @snprintf(i8* %9, i32 30, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %25, i32 %28, i32 %30, i32 %32, i32 %34)
%36 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %40
38: ; preds = %17
%39 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %99
40: ; preds = %17
%41 = call i64 @time(i64* null)
%42 = call i32 @srand(i64 %41)
%43 = call i64 @time(i64* %5)
%44 = icmp slt i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %40
%46 = getelementptr inbounds i8*, i8** %1, i64 1
br label %50
47: ; preds = %87, %40
%48 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @fclose(i32* %36)
br label %99
50: ; preds = %45, %87
%51 = phi i32 [ 0, %45 ], [ %95, %87 ]
%52 = load i8*, i8** %46
%53 = load i32, i32* @O_RDONLY
%54 = call i32 @open(i8* %52, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%58 = call i32 @fclose(i32* %36)
br label %99
59: ; preds = %50
%60 = call i32 (...) @rand()
%61 = call i32 @memset(i8* %8, i32 0, i32 1000)
%62 = load i32, i32* @W_OK
%63 = call i32 @access(i8* %9, i32 %62)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %59
%66 = call i32 @close(i32 %54)
%67 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %99
68: ; preds = %59
%69 = sext i32 %60 to i64
%70 = urem i64 %69, 1000
%71 = trunc i64 %70 to i32
%72 = call i32 @read(i32 %54, i8* %8, i32 %71)
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %68
%75 = load i8*, i8** %46
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %75, i8* %77)
%79 = call i32 @fflush(i32* %36)
%80 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %99
81: ; preds = %68
%82 = call i64 @time(i64* %6)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%86 = call i32 @fclose(i32* %36)
br label %99
87: ; preds = %81
%88 = load i64, i64* %6
%89 = load i64, i64* %5
%90 = call double @difftime(i64 %88, i64 %89)
%91 = fptosi double %90 to i32
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0), i32 %91, i32 %51, i32 %72)
%93 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0), double %90, i32 %51, i32 %72)
%94 = call i32 @fflush(i32* %36)
%95 = add nuw nsw i32 %51, 1
%96 = call i32 @close(i32 %54)
%97 = call i64 @time(i64* %5)
%98 = icmp slt i64 %97, 0
br i1 %98, label %47, label %50
99: ; preds = %84, %74, %65, %56, %47, %38, %14
ret i32 -1
}