#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 {
  long tv_sec;
  long tv_usec;
};

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
int /*<<< orphan*/ stderr;
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  long int ms;
  char *endp;
  if (argc != 2) {
    fprintf(stderr, "Invalid argument count: %d\n", argc);
    exit(1);
  }
  errno = 0;
  ms = strtol(argv[1], &endp, 10);
  if (errno || argv[1] == endp || *endp != '\0' || ms < 0) {
    if (errno == 0)
      errno = EINVAL;
    perror("Invalid timeout value");
    exit(1);
  }
  {
    struct timeval t;
    t.tv_sec = ms / 1000;
    t.tv_usec = (ms % 1000) * 1000;
    select(0, NULL, NULL, NULL, &t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1192 <main+0x42>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe7d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e3f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e17(%rip),%rax
cmpq   $0x0,(%rax)
jne    11f8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmp    -0x20(%rbp),%rax
je     11f8 <main+0xa8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f8 <main+0xa8>
cmpq   $0x0,-0x18(%rbp)
jge    1233 <main+0xe3>
mov    0x2dd9(%rip),%rax
cmpq   $0x0,(%rax)
jne    121d <main+0xcd>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rcx
mov    0x2dbe(%rip),%rax
mov    %rcx,(%rax)
lea    0xdf8(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
imul   $0x3e8,%rdx,%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1050 <select@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1211 <main+0xc1>
mov    %rsi,%rbx
mov    0x2e6e(%rip),%r14
movq   $0x0,(%r14)
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%r14)
jne    11fb <main+0xab>
mov    %rax,%rcx
mov    (%rsp),%rax
cmp    %rax,0x8(%rbx)
je     11ee <main+0x9e>
cmpb   $0x0,(%rax)
jne    11ee <main+0x9e>
test   %rcx,%rcx
js     11ee <main+0x9e>
mov    %rcx,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
shr    $0x4,%rdx
mov    %rdx,0x8(%rsp)
imul   $0x3e8,%rdx,%rax
sub    %rax,%rcx
imul   $0x3e8,%rcx,%rax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2ddb(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
lea    0xe1a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %edi,%edx
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"Invalid argument count: %d\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [22 x i8] c"Invalid timeout value\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* %4
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i64 0, i64* @errno
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strtol(i8* %19, i8** %7, i32 10)
store i64 %20, i64* %6
%21 = load i64, i64* @errno
%22 = icmp ne i64 %21, 0
br i1 %22, label %37, label %23
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i8*, i8** %7
%28 = icmp eq i8* %26, %27
br i1 %28, label %37, label %29
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = load i64, i64* %6
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34, %29, %23, %16
%38 = load i64, i64* @errno
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = load i64, i64* @EINVAL
store i64 %41, i64* @errno
br label %42
42: ; preds = %40, %37
%43 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %34
%46 = load i64, i64* %6
%47 = sdiv i64 %46, 1000
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i64 %47, i64* %48
%49 = load i64, i64* %6
%50 = srem i64 %49, 1000
%51 = mul nsw i64 %50, 1000
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 %51, i64* %52
%53 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %8)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [28 x i8] c"Invalid argument count: %d\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [22 x i8] c"Invalid timeout value\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca %struct.timeval
%5 = bitcast i8** %3 to i8*
%6 = icmp eq i32 %0, 2
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
store i64 0, i64* @errno
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strtol(i8* %13, i8** %3, i32 10)
%15 = load i64, i64* @errno
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %11
%18 = load i8*, i8** %12
%19 = load i8*, i8** %3
%20 = icmp eq i8* %18, %19
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = load i8, i8* %19
%23 = icmp ne i8 %22, 0
%24 = icmp slt i64 %14, 0
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %26, label %31
26: ; preds = %21, %17
%27 = load i64, i64* @EINVAL
store i64 %27, i64* @errno
br label %28
28: ; preds = %11, %26
%29 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = bitcast %struct.timeval* %4 to i8*
%33 = udiv i64 %14, 1000
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i64 %33, i64* %34
%35 = urem i64 %14, 1000
%36 = mul nuw nsw i64 %35, 1000
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 %36, i64* %37
%38 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %4)
ret i32 0
}