#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;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
double getTimeval();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int main(int argc, char **argv) {
  int fd, retval;
  char buf[6];
  fd_set readfds;
  struct timeval tv;
  double t1, t2;
  int flag = 0;
  if ((fd = open("/dev/input/mice", O_RDONLY)) < 0) {
    printf("Failed to open \"/dev/input/mice\".\n");
    printf("You should try root adminstrator to execute\n");
    return 1;
  } else {
    printf("open \"/dev/input/mice\" successfuly.\n");
  }
  while (1) {
    tv.tv_sec = 5;
    tv.tv_usec = 0;
    FD_ZERO(&readfds);
    FD_SET(fd, &readfds);
    retval = select(fd + 1, &readfds, NULL, NULL, &tv);
    if (retval == 0)
      printf("Read mouse input time out!\n");
    if (FD_ISSET(fd, &readfds)) {
      if (read(fd, buf, 6) <= 0) {
        continue;
      }
      if ((buf[0] & 0x07) == 1 && flag == 0) {
        flag = 1;
        printf("%s\n", "Left click, application start...");
        t1 = getTimeval();
      }
      if ((buf[0] & 0x07) == 2 && flag == 1) {
        t2 = getTimeval() - t1;
        printf("Loading Application using:%lfs\n", t2);
        flag = 0;
      }
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e5 <main+0x65>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <main+0x78>
movl   $0x5,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x24(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x38(%rbp),%r8
mov    %rcx,%rdx
call   1080 <select@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1251 <main+0xd1>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1313 <main+0x193>
mov    -0x14(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x6,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jg     1287 <main+0x107>
jmp    11f8 <main+0x78>
movsbl -0x1e(%rbp),%eax
and    $0x7,%eax
cmp    $0x1,%eax
jne    12c9 <main+0x149>
cmpl   $0x0,-0x4c(%rbp)
jne    12c9 <main+0x149>
movl   $0x1,-0x4c(%rbp)
lea    0xdf2(%rip),%rdi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getTimeval@plt>
movsd  %xmm0,-0x40(%rbp)
movsbl -0x1e(%rbp),%eax
and    $0x7,%eax
cmp    $0x2,%eax
jne    130e <main+0x18e>
cmpl   $0x1,-0x4c(%rbp)
jne    130e <main+0x18e>
mov    $0x0,%al
call   1050 <getTimeval@plt>
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4c(%rbp)
jmp    1313 <main+0x193>
jmp    11f8 <main+0x78>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe52(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     12d1 <main+0x141>
mov    %eax,%ebx
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%r14d
add    $0x1,%r14d
lea    0x24(%rsp),%rbp
lea    0x28(%rsp),%r15
lea    0xe94(%rip),%r12
lea    0x12(%rsp),%r13
movl   $0x0,0xc(%rsp)
jmp    1220 <main+0x90>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getTimeval@plt>
movsd  %xmm0,0x18(%rsp)
movl   $0x1,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x5,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    %rbp,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10b0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <select@plt>
test   %eax,%eax
jne    1261 <main+0xd1>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1220 <main+0x90>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x6,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    1220 <main+0x90>
movzbl 0x12(%rsp),%eax
and    $0x7,%al
cmp    $0x1,%al
jne    129a <main+0x10a>
cmpl   $0x0,0xc(%rsp)
je     11f0 <main+0x60>
cmp    $0x2,%al
jne    1220 <main+0x90>
cmpl   $0x1,0xc(%rsp)
jne    1220 <main+0x90>
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1060 <getTimeval@plt>
subsd  0x18(%rsp),%xmm0
lea    0xd6c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1220 <main+0x90>
lea    0xdb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.1 = [35 x i8] c"Failed to open \22/dev/input/mice\22.\0A\00"
@.str.2 = [45 x i8] c"You should try root adminstrator to execute\0A\00"
@.str.3 = [37 x i8] c"open \22/dev/input/mice\22 successfuly.\0A\00"
@.str.4 = [28 x i8] c"Read mouse input time out!\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [33 x i8] c"Left click, application start...\00"
@.str.7 = [32 x i8] c"Loading Application using:%lfs\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [6 x i8]
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = alloca double
%12 = alloca double
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20
br label %23
23: ; preds = %22, %45, %74
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
store i32 5, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i64 0, i64* %25
%26 = call i32 @FD_ZERO(i32* %9)
%27 = load i32, i32* %6
%28 = call i32 @FD_SET(i32 %27, i32* %9)
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = call i32 @select(i32 %30, i32* %9, i32* null, i32* null, %struct.timeval* %10)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %23
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %23
%37 = load i32, i32* %6
%38 = call i64 @FD_ISSET(i32 %37, i32* %9)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %74
40: ; preds = %36
%41 = load i32, i32* %6
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%43 = call i64 @read(i32 %41, i8* %42, i32 6)
%44 = icmp sle i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
br label %23
46: ; preds = %40
%47 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = and i32 %49, 7
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = load i32, i32* %13
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
store i32 1, i32* %13
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%57 = call double (...) @getTimeval()
store double %57, double* %11
br label %58
58: ; preds = %55, %52, %46
%59 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = and i32 %61, 7
%63 = icmp eq i32 %62, 2
br i1 %63, label %64, label %73
64: ; preds = %58
%65 = load i32, i32* %13
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %73
67: ; preds = %64
%68 = call double (...) @getTimeval()
%69 = load double, double* %11
%70 = fsub double %68, %69
store double %70, double* %12
%71 = load double, double* %12
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), double %71)
store i32 0, i32* %13
br label %73
73: ; preds = %67, %64, %58
br label %74
74: ; preds = %73, %36
br label %23
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [16 x i8] c"/dev/input/mice\00"
@O_RDONLY = global i32 0
@.str.6 = [33 x i8] c"Left click, application start...\00"
@.str.7 = [32 x i8] c"Loading Application using:%lfs\0A\00"
@str = [36 x i8] c"open \22/dev/input/mice\22 successfuly.\00"
@str.8 = [27 x i8] c"Read mouse input time out!\00"
@str.9 = [34 x i8] c"Failed to open \22/dev/input/mice\22.\00"
@str.10 = [44 x i8] c"You should try root adminstrator to execute\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [6 x i8]
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0))
ret i32 1
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%19 = add nuw nsw i32 %10, 1
br label %20
20: ; preds = %46, %15
%21 = phi double [ %48, %46 ], [ undef, %15 ]
%22 = phi i32 [ 1, %46 ], [ 0, %15 ]
br label %23
23: ; preds = %20, %53
%24 = phi i32 [ %22, %20 ], [ 0, %53 ]
%25 = icmp eq i32 %24, 0
%26 = icmp eq i32 %24, 1
br label %27
27: ; preds = %52, %23
br label %28
28: ; preds = %27, %38
store i32 5, i32* %17
store i64 0, i64* %18
%29 = call i32 @FD_ZERO(i32* %4)
%30 = call i32 @FD_SET(i32 %10, i32* %4)
%31 = call i32 @select(i32 %19, i32* %4, i32* null, i32* null, %struct.timeval* %5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.8, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = call i64 @FD_ISSET(i32 %10, i32* %4)
%37 = icmp eq i64 %36, 0
br i1 %37, label %52, label %38
38: ; preds = %35
%39 = call i64 @read(i32 %10, i8* %6, i32 6)
%40 = icmp slt i64 %39, 1
br i1 %40, label %28, label %41
41: ; preds = %38
%42 = load i8, i8* %6
%43 = and i8 %42, 7
%44 = icmp eq i8 %43, 1
%45 = and i1 %44, %25
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
%48 = call double (...) @getTimeval()
br label %20
49: ; preds = %41
%50 = icmp eq i8 %43, 2
%51 = and i1 %50, %26
br i1 %51, label %53, label %52
52: ; preds = %35, %49
br label %27
53: ; preds = %49
%54 = call double (...) @getTimeval()
%55 = fsub double %54, %21
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), double %55)
br label %23
}