#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getopt(int, char **, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ usage();
main(int argc, char **argv) {
  struct timeval starttime, endtime;
  int count = 1000000;
  int debug = 0;
  int size = 1;
  int fd;
  int i;
  char word[8192];
  extern int optind, opterr;
  extern char *optarg;
  while ((word[0] = getopt(argc, argv, "s:c:d?")) != (char)EOF) {
    switch (word[0]) {
    case 'd':
      debug++;
      break;
    case 'c':
      count = atoi(optarg);
      break;
    case 's':
      if ((size = atoi(optarg)) > 8192) {
        size = 8192;
      }
      break;
    case '?':
      usage();
      return (0);
    default:
      usage();
      return (-1);
    }
  }
  if ((fd = open("/netbsd", O_RDONLY)) < 0) {
    printf("Error: open\n");
    exit(0);
  }
  if (gettimeofday(&starttime, NULL)) {
    printf("Error: gettimeofday\n");
    exit(0);
  }
  for (i = 0; i < count; i++) {
    if (read(fd, word, size) < 0) {
      printf("Error: read\n");
      exit(0);
    }
  }
  if (gettimeofday(&endtime, NULL)) {
    printf("Error: gettimeofday\n");
    exit(0);
  }
  printf("%d reads of /netbsd took %d usecs.\n", count,
         (endtime.tv_sec - starttime.tv_sec) * 1000000 +
             (endtime.tv_usec - starttime.tv_usec));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xf4240,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe44(%rip),%rdx
call   1080 <getopt@plt>
mov    %al,-0x2040(%rbp)
movsbl %al,%eax
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     12af <main+0x12f>
movsbl -0x2040(%rbp),%eax
mov    %eax,-0x2044(%rbp)
sub    $0x3f,%eax
je     1284 <main+0x104>
jmp    11fa <main+0x7a>
mov    -0x2044(%rbp),%eax
sub    $0x63,%eax
je     1244 <main+0xc4>
jmp    120e <main+0x8e>
mov    -0x2044(%rbp),%eax
sub    $0x64,%eax
je     1236 <main+0xb6>
jmp    1222 <main+0xa2>
mov    -0x2044(%rbp),%eax
sub    $0x73,%eax
je     125b <main+0xdb>
jmp    1297 <main+0x117>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12aa <main+0x12a>
mov    0x2d85(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    12aa <main+0x12a>
mov    0x2d6e(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x2000,%eax
jle    127f <main+0xff>
movl   $0x2000,-0x2c(%rbp)
jmp    12aa <main+0x12a>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b9 <main+0x239>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b9 <main+0x239>
jmp    11ae <main+0x2e>
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
lea    0xd48(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    12e5 <main+0x165>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     1311 <main+0x191>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1368 <main+0x1e8>
mov    -0x30(%rbp),%edi
lea    -0x2040(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jge    1355 <main+0x1d5>
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    135a <main+0x1da>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1318 <main+0x198>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     1394 <main+0x214>
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0xf4240,%eax,%edx
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
add    %eax,%edx
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xe53(%rip),%rdx
call   1090 <getopt@plt>
movsbl %al,%ecx
mov    0x2e24(%rip),%r13
movsbl 0x0(%r13),%edx
cmp    %ecx,%edx
jne    11d6 <main+0x46>
mov    $0x1,%r14d
mov    $0xf4240,%r12d
jmp    125c <main+0xcc>
mov    $0xf4240,%ebp
mov    $0x1,%r14d
lea    0xe18(%rip),%r12
jmp    1209 <main+0x79>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
movsbl %al,%ecx
movsbl 0x0(%r13),%edx
cmp    %ecx,%edx
je     1259 <main+0xc9>
cmp    $0x63,%ecx
jle    1240 <main+0xb0>
cmp    $0x64,%ecx
je     11f0 <main+0x60>
cmp    $0x73,%ecx
jne    1324 <main+0x194>
mov    0x2dad(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
cmp    $0x2000,%eax
mov    $0x2000,%eax
cmovge %eax,%r14d
jmp    11f0 <main+0x60>
xchg   %ax,%ax
jne    1314 <main+0x184>
mov    0x2d83(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
jmp    11f0 <main+0x60>
mov    %ebp,%r12d
mov    %al,0x10(%rsp)
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
lea    0xd97(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     134e <main+0x1be>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    1345 <main+0x1b5>
test   %r12d,%r12d
jle    12c7 <main+0x137>
lea    0x10(%rsp),%r15
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1060 <read@plt>
test   %rax,%rax
js     1332 <main+0x1a2>
add    $0xffffffff,%ebp
jne    12b0 <main+0x120>
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    1345 <main+0x1b5>
mov    (%rsp),%eax
mov    0x4(%rsp),%edx
sub    0x8(%rsp),%eax
imul   $0xf4240,%eax,%eax
sub    0xc(%rsp),%edx
add    %eax,%edx
lea    0xd19(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x3f,%ecx
jne    1324 <main+0x194>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <usage@plt>
jmp    1300 <main+0x170>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0xffffffff,%ebx
jmp    1300 <main+0x170>
lea    0xcfa(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xcf3(%rip),%rdi
jmp    1339 <main+0x1a9>
lea    0xcfe(%rip),%rdi
jmp    1339 <main+0x1a9>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [7 x i8] c"s:c:d?\00"
@EOF = global i64 0
@optarg = external global i8*
@.str.1 = [8 x i8] c"/netbsd\00"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"Error: open\0A\00"
@.str.3 = [21 x i8] c"Error: gettimeofday\0A\00"
@.str.4 = [13 x i8] c"Error: read\0A\00"
@.str.5 = [36 x i8] c"%d reads of /netbsd took %d usecs.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1000000, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
br label %14
14: ; preds = %44, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call signext i8 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
store i8 %17, i8* %18
%19 = sext i8 %17 to i32
%20 = load i64, i64* @EOF
%21 = trunc i64 %20 to i8
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %19, %22
br i1 %23, label %24, label %45
24: ; preds = %14
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %42 [
i32 100, label %28
i32 99, label %31
i32 115, label %34
i32 63, label %40
]
28: ; preds = %24
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %44
31: ; preds = %24
%32 = load i8*, i8** @optarg
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
br label %44
34: ; preds = %24
%35 = load i8*, i8** @optarg
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %10
%37 = icmp sgt i32 %36, 8192
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 8192, i32* %10
br label %39
39: ; preds = %38, %34
br label %44
40: ; preds = %24
%41 = call i32 (...) @usage()
store i32 0, i32* %3
br label %97
42: ; preds = %24
%43 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %97
44: ; preds = %39, %31, %28
br label %14
45: ; preds = %14
%46 = load i32, i32* @O_RDONLY
%47 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %46)
store i32 %47, i32* %11
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %45
%53 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %52
store i32 0, i32* %12
br label %59
59: ; preds = %73, %58
%60 = load i32, i32* %12
%61 = load i32, i32* %8
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %76
63: ; preds = %59
%64 = load i32, i32* %11
%65 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%66 = load i32, i32* %10
%67 = call i64 @read(i32 %64, i8* %65, i32 %66)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %63
br label %73
73: ; preds = %72
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
br label %59
76: ; preds = %59
%77 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%81 = call i32 @exit(i32 0)
unreachable
82: ; preds = %76
%83 = load i32, i32* %8
%84 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%85 = load i32, i32* %84
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%87 = load i32, i32* %86
%88 = sub nsw i32 %85, %87
%89 = mul nsw i32 %88, 1000000
%90 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%91 = load i32, i32* %90
%92 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%93 = load i32, i32* %92
%94 = sub nsw i32 %91, %93
%95 = add nsw i32 %89, %94
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %83, i32 %95)
br label %97
97: ; preds = %82, %42, %40
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [7 x i8] c"s:c:d?\00"
@EOF = global i64 0
@optarg = external global i8*
@.str.1 = [8 x i8] c"/netbsd\00"
@O_RDONLY = global i32 0
@.str.5 = [36 x i8] c"%d reads of /netbsd took %d usecs.\0A\00"
@str.6 = [12 x i8] c"Error: read\00"
@str.7 = [20 x i8] c"Error: gettimeofday\00"
@str.8 = [12 x i8] c"Error: open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca [8192 x i8]
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%9 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = sext i8 %9 to i32
%11 = load i64, i64* @EOF
%12 = trunc i64 %11 to i32
%13 = shl i32 %12, 24
%14 = ashr exact i32 %13, 24
%15 = icmp eq i32 %14, %10
br i1 %15, label %42, label %16
16: ; preds = %2, %32
%17 = phi i32 [ %36, %32 ], [ %10, %2 ]
%18 = phi i32 [ %34, %32 ], [ 1, %2 ]
%19 = phi i32 [ %33, %32 ], [ 1000000, %2 ]
switch i32 %17, label %30 [
i32 100, label %32
i32 99, label %20
i32 115, label %23
i32 63, label %28
]
20: ; preds = %16
%21 = load i8*, i8** @optarg
%22 = tail call i32 @atoi(i8* %21)
br label %32
23: ; preds = %16
%24 = load i8*, i8** @optarg
%25 = tail call i32 @atoi(i8* %24)
%26 = icmp slt i32 %25, 8192
%27 = select i1 %26, i32 %25, i32 8192
br label %32
28: ; preds = %16
%29 = tail call i32 (...) @usage()
br label %90
30: ; preds = %16
%31 = tail call i32 (...) @usage()
br label %90
32: ; preds = %16, %23, %20
%33 = phi i32 [ %19, %23 ], [ %22, %20 ], [ %19, %16 ]
%34 = phi i32 [ %27, %23 ], [ %18, %20 ], [ %18, %16 ]
%35 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%36 = sext i8 %35 to i32
%37 = load i64, i64* @EOF
%38 = trunc i64 %37 to i32
%39 = shl i32 %38, 24
%40 = ashr exact i32 %39, 24
%41 = icmp eq i32 %40, %36
br i1 %41, label %42, label %16
42: ; preds = %32, %2
%43 = phi i8 [ %9, %2 ], [ %35, %32 ]
%44 = phi i32 [ 1000000, %2 ], [ %33, %32 ]
%45 = phi i32 [ 1, %2 ], [ %34, %32 ]
store i8 %43, i8* %8
%46 = load i32, i32* @O_RDONLY
%47 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%51 = tail call i32 @exit(i32 0)
unreachable
52: ; preds = %42
%53 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = icmp sgt i32 %44, 0
br i1 %56, label %62, label %70
57: ; preds = %52
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
%59 = tail call i32 @exit(i32 0)
unreachable
60: ; preds = %62
%61 = icmp eq i32 %66, %44
br i1 %61, label %70, label %62
62: ; preds = %55, %60
%63 = phi i32 [ %66, %60 ], [ 0, %55 ]
%64 = call i64 @read(i32 %47, i8* %8, i32 %45)
%65 = icmp slt i64 %64, 0
%66 = add nuw nsw i32 %63, 1
br i1 %65, label %67, label %60
67: ; preds = %62
%68 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
%69 = tail call i32 @exit(i32 0)
unreachable
70: ; preds = %60, %55
%71 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%72 = icmp eq i64 %71, 0
br i1 %72, label %76, label %73
73: ; preds = %70
%74 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
%75 = tail call i32 @exit(i32 0)
unreachable
76: ; preds = %70
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%78 = load i32, i32* %77
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%80 = load i32, i32* %79
%81 = sub nsw i32 %78, %80
%82 = mul nsw i32 %81, 1000000
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%84 = load i32, i32* %83
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%86 = load i32, i32* %85
%87 = sub i32 %84, %86
%88 = add nsw i32 %87, %82
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %88)
br label %90
90: ; preds = %76, %30, %28
%91 = phi i32 [ -1, %30 ], [ 0, %28 ], [ 0, %76 ]
ret i32 %91
}