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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ WRITE_MSG(int, char *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ atoi(char *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
int /*<<< orphan*/ showHelp(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ showVersion();
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int fd;
  int idx = 1;
  struct timeval timeout;
  if (argc >= 2) {
    if (strcmp(argv[1], "--help") == 0)
      showHelp(1, argv[0], 0);
    if (strcmp(argv[1], "--version") == 0)
      showVersion();
    if (strcmp(argv[1], "--") == 0)
      ++idx;
  }
  if (argc < idx + 2) {
    WRITE_MSG(2, "Not enough parameters; use '--help' for more information\n");
    return EXIT_FAILURE;
  }
  fd = open(argv[idx], O_RDONLY | O_NONBLOCK, 0);
  if (fd == -1) {
    perror("vshelper-sync: open()");
    return EXIT_FAILURE;
  }
  timeout.tv_sec = atoi(argv[idx + 1]);
  timeout.tv_usec = 0;
  for (;;) {
    char buf[512];
    ssize_t len;
    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(fd, &fds);
    switch (select(fd + 1, &fds, 0, 0, &timeout)) {
    case 0:
      return EXIT_FAILURE;
    case -1:
      perror("vshelper: select()");
      return EXIT_FAILURE;
    default:
      break;
    }
    assert(FD_ISSET(fd, &fds));
    len = read(fd, buf, sizeof buf);
    if (len == 0)
      break;
    if (len == -1) {
      perror("vshelper-sync: read()");
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     127c <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    122b <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
xor    %edx,%edx
call   1030 <showHelp@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdcd(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1250 <main+0x80>
mov    $0x0,%al
call   1050 <showVersion@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1277 <main+0xa7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    127c <main+0xac>
mov    -0x8(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    12af <main+0xdf>
mov    $0x2,%edi
lea    0xd7b(%rip),%rsi
call   10b0 <WRITE_MSG@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1434 <main+0x264>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    0x2d1d(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12fe <main+0x12e>
lea    0xd66(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1434 <main+0x264>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x238(%rbp),%rdi
mov    %rdi,-0x248(%rbp)
call   1090 <FD_ZERO@plt>
mov    -0x248(%rbp),%rsi
mov    -0x14(%rbp),%edi
call   10f0 <FD_SET@plt>
mov    -0x248(%rbp),%rsi
mov    -0x14(%rbp),%edi
add    $0x1,%edi
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
mov    %ecx,%edx
call   10a0 <select@plt>
mov    %eax,%ecx
mov    %ecx,-0x23c(%rbp)
sub    $0xffffffff,%eax
je     1395 <main+0x1c5>
jmp    1371 <main+0x1a1>
mov    -0x23c(%rbp),%eax
test   %eax,%eax
jne    13b2 <main+0x1e2>
jmp    1384 <main+0x1b4>
mov    0x2c45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1434 <main+0x264>
lea    0xcc8(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1434 <main+0x264>
jmp    13b7 <main+0x1e7>
mov    -0x14(%rbp),%edi
lea    -0x238(%rbp),%rsi
call   1040 <FD_ISSET@plt>
mov    %eax,%edi
call   1080 <assert@plt>
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0x0,-0x234(%rbp)
jne    13f9 <main+0x229>
jmp    1428 <main+0x258>
cmpl   $0xffffffff,-0x234(%rbp)
jne    1423 <main+0x253>
lea    0xc6a(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2bb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1434 <main+0x264>
jmp    131f <main+0x14f>
mov    0x2b99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%eax
cmp    $0x2,%edi
jl     124c <main+0x7c>
mov    0x8(%rbx),%rdi
lea    0xe05(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1214 <main+0x44>
mov    (%rbx),%rsi
mov    $0x1,%edi
xor    %edx,%edx
call   1030 <showHelp@plt>
mov    0x8(%rbx),%rdi
lea    0xde8(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1230 <main+0x60>
xor    %eax,%eax
call   1050 <showVersion@plt>
mov    0x8(%rbx),%rdi
lea    0xdd6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x1,%rax
mov    $0x1,%eax
adc    $0x0,%eax
lea    0x2(%rax),%ecx
cmp    %ebp,%ecx
jle    1270 <main+0xa0>
lea    0xdba(%rip),%rsi
mov    $0x2,%edi
call   10b0 <WRITE_MSG@plt>
mov    0x2d65(%rip),%rax
jmp    133d <main+0x16d>
mov    %eax,%r14d
mov    (%rbx,%r14,8),%rdi
mov    0x2d62(%rip),%rax
mov    0x2d63(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %edx,%edx
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     1351 <main+0x181>
mov    %eax,%ebp
mov    0x8(%rbx,%r14,8),%rdi
call   10e0 <atoi@plt>
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    %ebp,%r15d
add    $0x1,%r15d
lea    0xc(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0xd9a(%rip),%r14
lea    0x20(%rsp),%r13
nop
mov    %rbx,%rdi
call   1090 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10f0 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10a0 <select@plt>
test   %eax,%eax
je     1264 <main+0x94>
cmp    $0xffffffff,%eax
je     1331 <main+0x161>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
mov    %eax,%edi
call   1080 <assert@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x200,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1336 <main+0x166>
cmp    $0xffffffff,%eax
jne    12d0 <main+0x100>
lea    0xd46(%rip),%r14
mov    %r14,%rdi
jmp    1358 <main+0x188>
mov    0x2c8b(%rip),%rax
mov    (%rax),%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf6(%rip),%rdi
call   10d0 <perror@plt>
jmp    1264 <main+0x94>

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
@.str = [7 x i8] c"--help\00"
@.str.1 = [10 x i8] c"--version\00"
@.str.2 = [3 x i8] c"--\00"
@.str.3 = [58 x i8] c"Not enough parameters; use '--help' for more information\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [22 x i8] c"vshelper-sync: open()\00"
@.str.5 = [19 x i8] c"vshelper: select()\00"
@.str.6 = [22 x i8] c"vshelper-sync: read()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 2
br i1 %13, label %14, label %43
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @showHelp(i32 1, i8* %23, i32 0)
br label %25
25: ; preds = %20, %14
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 (...) @showVersion()
br label %33
33: ; preds = %31, %25
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %42
42: ; preds = %39, %33
br label %43
43: ; preds = %42, %2
%44 = load i32, i32* %4
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 2
%47 = icmp slt i32 %44, %46
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = call i32 @WRITE_MSG(i32 2, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %3
br label %108
51: ; preds = %43
%52 = load i8**, i8*** %5
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = load i32, i32* @O_RDONLY
%58 = load i32, i32* @O_NONBLOCK
%59 = or i32 %57, %58
%60 = call i32 @open(i8* %56, i32 %59, i32 0)
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %51
%64 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %3
br label %108
66: ; preds = %51
%67 = load i8**, i8*** %5
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %67, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @atoi(i8* %72)
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i32 %73, i32* %74
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i64 0, i64* %75
br label %76
76: ; preds = %105, %66
%77 = call i32 @FD_ZERO(i32* %11)
%78 = load i32, i32* %6
%79 = call i32 @FD_SET(i32 %78, i32* %11)
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
%82 = call i32 @select(i32 %81, i32* %11, i32 0, i32 0, %struct.timeval* %8)
switch i32 %82, label %88 [
i32 0, label %83
i32 -1, label %85
]
83: ; preds = %76
%84 = load i32, i32* @EXIT_FAILURE
store i32 %84, i32* %3
br label %108
85: ; preds = %76
%86 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
store i32 %87, i32* %3
br label %108
88: ; preds = %76
br label %89
89: ; preds = %88
%90 = load i32, i32* %6
%91 = call i32 @FD_ISSET(i32 %90, i32* %11)
%92 = call i32 @assert(i32 %91)
%93 = load i32, i32* %6
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%95 = call i32 @read(i32 %93, i8* %94, i32 512)
store i32 %95, i32* %10
%96 = load i32, i32* %10
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %89
br label %106
99: ; preds = %89
%100 = load i32, i32* %10
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %105
102: ; preds = %99
%103 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
store i32 %104, i32* %3
br label %108
105: ; preds = %99
br label %76
106: ; preds = %98
%107 = load i32, i32* @EXIT_SUCCESS
store i32 %107, i32* %3
br label %108
108: ; preds = %106, %102, %85, %83, %63, %48
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
@.str = [7 x i8] c"--help\00"
@.str.1 = [10 x i8] c"--version\00"
@.str.2 = [3 x i8] c"--\00"
@.str.3 = [58 x i8] c"Not enough parameters; use '--help' for more information\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [22 x i8] c"vshelper-sync: open()\00"
@.str.5 = [19 x i8] c"vshelper: select()\00"
@.str.6 = [22 x i8] c"vshelper-sync: read()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca [512 x i8]
%5 = alloca i32
%6 = bitcast %struct.timeval* %3 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %27
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = tail call i32 @showHelp(i32 1, i8* %14, i32 0)
br label %16
16: ; preds = %13, %8
%17 = load i8*, i8** %9
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 (...) @showVersion()
br label %22
22: ; preds = %20, %16
%23 = load i8*, i8** %9
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i32 2, i32 1
br label %27
27: ; preds = %22, %2
%28 = phi i32 [ 1, %2 ], [ %26, %22 ]
%29 = add nuw nsw i32 %28, 2
%30 = icmp sgt i32 %29, %0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = tail call i32 @WRITE_MSG(i32 2, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
br label %73
34: ; preds = %27
%35 = zext i32 %28 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDONLY
%39 = load i32, i32* @O_NONBLOCK
%40 = or i32 %39, %38
%41 = tail call i32 @open(i8* %37, i32 %40, i32 0)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %34
%44 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
br label %73
46: ; preds = %34
%47 = add nuw nsw i32 %28, 1
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %1, i64 %48
%50 = load i8*, i8** %49
%51 = tail call i32 @atoi(i8* %50)
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i32 %51, i32* %52
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i64 0, i64* %53
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%55 = bitcast i32* %5 to i8*
%56 = add nuw nsw i32 %41, 1
br label %57
57: ; preds = %70, %46
%58 = call i32 @FD_ZERO(i32* %5)
%59 = call i32 @FD_SET(i32 %41, i32* %5)
%60 = call i32 @select(i32 %56, i32* %5, i32 0, i32 0, %struct.timeval* %3)
switch i32 %60, label %61 [
i32 0, label %68
i32 -1, label %65
]
61: ; preds = %57
%62 = call i32 @FD_ISSET(i32 %41, i32* %5)
%63 = call i32 @assert(i32 %62)
%64 = call i32 @read(i32 %41, i8* %54, i32 512)
switch i32 %64, label %70 [
i32 0, label %71
i32 -1, label %65
]
65: ; preds = %61, %57
%66 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), %57 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), %61 ]
%67 = call i32 @perror(i8* %66)
br label %68
68: ; preds = %57, %65
%69 = load i32, i32* @EXIT_FAILURE
br label %73
70: ; preds = %61
br label %57
71: ; preds = %61
%72 = load i32, i32* @EXIT_SUCCESS
br label %73
73: ; preds = %68, %71, %43, %31
%74 = phi i32 [ %33, %31 ], [ %45, %43 ], [ %72, %71 ], [ %69, %68 ]
ret i32 %74
}