#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*/ F_GETFL;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/);
char getopt(int, char **, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage();
main(int argc, char **argv) {
  struct timeval starttime, endtime;
  int count = 1000000;
  int debug = 0;
  int flags;
  int fd;
  int i;
  char word[8192];
  extern int optind, opterr;
  extern char *optarg;
  while ((word[0] = getopt(argc, argv, "c:d?")) != (char)EOF) {
    switch (word[0]) {
    case 'd':
      debug++;
      break;
    case 'c':
      count = atoi(optarg);
      break;
    case '?':
      usage();
      return (0);
    default:
      usage();
      return (-1);
    }
  }
  if ((fd = open("/dev/zero", 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 ((flags = fcntl(0, F_GETFL)) < 0) {
      perror("fcntl 1st GETFL");
    }
  }
  if (gettimeofday(&endtime, NULL)) {
    printf("Error: gettimeofday\n");
    exit(0);
  }
  printf("%d fcntls of /dev/null 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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3b(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x2040(%rbp)
movsbl %al,%eax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%rcx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     127b <main+0xeb>
movsbl -0x2040(%rbp),%eax
mov    %eax,-0x2044(%rbp)
sub    $0x3f,%eax
je     1250 <main+0xc0>
jmp    1203 <main+0x73>
mov    -0x2044(%rbp),%eax
sub    $0x63,%eax
je     1239 <main+0xa9>
jmp    1217 <main+0x87>
mov    -0x2044(%rbp),%eax
sub    $0x64,%eax
jne    1263 <main+0xd3>
jmp    122b <main+0x9b>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1276 <main+0xe6>
mov    0x2d90(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    1276 <main+0xe6>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    137c <main+0x1ec>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137c <main+0x1ec>
jmp    11b7 <main+0x27>
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
lea    0xd7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    12b1 <main+0x121>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     12dd <main+0x14d>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    132b <main+0x19b>
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1030 <fcntl@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1318 <main+0x188>
lea    0xd1e(%rip),%rdi
call   1080 <perror@plt>
jmp    131d <main+0x18d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12e4 <main+0x154>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     1357 <main+0x1c7>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <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    0xccc(%rip),%rdi
mov    $0x0,%al
call   1040 <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    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe46(%rip),%rdx
call   10a0 <getopt@plt>
movsbl %al,%eax
mov    0x2e17(%rip),%r12
movsbl (%r12),%ecx
mov    $0xf4240,%r14d
cmp    %eax,%ecx
jne    129e <main+0xfe>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0xe19(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     131d <main+0x17d>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
jne    1314 <main+0x174>
test   %r14d,%r14d
jle    124d <main+0xad>
mov    0x2dae(%rip),%rbp
lea    0xdee(%rip),%r15
mov    %r14d,%ebx
jmp    1235 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     124d <main+0xad>
mov    0x0(%rbp),%esi
xor    %edi,%edi
call   1040 <fcntl@plt>
test   %eax,%eax
jns    1230 <main+0x90>
mov    %r15,%rdi
call   1090 <perror@plt>
jmp    1230 <main+0x90>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
jne    1314 <main+0x174>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%edx
sub    0x10(%rsp),%eax
imul   $0xf4240,%eax,%eax
sub    0x14(%rsp),%edx
add    %eax,%edx
lea    0xd9c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xf4240,%r14d
mov    0x2d25(%rip),%r13
lea    0xd4e(%rip),%r15
jmp    12e9 <main+0x149>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
movsbl %al,%eax
movsbl (%r12),%ecx
cmp    %eax,%ecx
je     11dc <main+0x3c>
cmp    $0x63,%eax
je     12c0 <main+0x120>
cmp    $0x64,%eax
je     12cc <main+0x12c>
cmp    $0x3f,%eax
jne    1303 <main+0x163>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <usage@plt>
jmp    128d <main+0xed>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0xffffffff,%ebx
jmp    128d <main+0xed>
lea    0xd2b(%rip),%rdi
jmp    1324 <main+0x184>
lea    0xd36(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [5 x i8] c"c:d?\00"
@EOF = global i64 0
@optarg = external global i8*
@.str.1 = [10 x i8] c"/dev/zero\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"
@F_GETFL = global i32 0
@.str.4 = [16 x i8] c"fcntl 1st GETFL\00"
@.str.5 = [39 x i8] c"%d fcntls of /dev/null 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
br label %14
14: ; preds = %38, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call signext i8 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([5 x i8], [5 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 %39
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 %36 [
i32 100, label %28
i32 99, label %31
i32 63, label %34
]
28: ; preds = %24
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %38
31: ; preds = %24
%32 = load i8*, i8** @optarg
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
br label %38
34: ; preds = %24
%35 = call i32 (...) @usage()
store i32 0, i32* %3
br label %88
36: ; preds = %24
%37 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %88
38: ; preds = %31, %28
br label %14
39: ; preds = %14
%40 = load i32, i32* @O_RDONLY
%41 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 %41, i32* %11
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %39
%47 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %46
store i32 0, i32* %12
br label %53
53: ; preds = %64, %52
%54 = load i32, i32* %12
%55 = load i32, i32* %8
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %67
57: ; preds = %53
%58 = load i32, i32* @F_GETFL
%59 = call i32 @fcntl(i32 0, i32 %58)
store i32 %59, i32* %10
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %57
br label %64
64: ; preds = %63
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 1
store i32 %66, i32* %12
br label %53
67: ; preds = %53
%68 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%72 = call i32 @exit(i32 0)
unreachable
73: ; preds = %67
%74 = load i32, i32* %8
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%78 = load i32, i32* %77
%79 = sub nsw i32 %76, %78
%80 = mul nsw i32 %79, 1000000
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%82 = load i32, i32* %81
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%84 = load i32, i32* %83
%85 = sub nsw i32 %82, %84
%86 = add nsw i32 %80, %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 %74, i32 %86)
br label %88
88: ; preds = %73, %36, %34
%89 = load i32, i32* %3
ret i32 %89
}

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