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

/* Variables and functions */
int _error(char const *, char *, int);
int /*<<< orphan*/ printf(char *, char const *, char *, unsigned int);
scalar_t__ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *, struct timeval *);
unsigned int time(int /*<<< orphan*/ *);
int _select2(char const *progname, unsigned int t) {
  struct timeval timeout;
  time_t before;
  time_t after;
  printf("%s: Testing %s() (sleeping %us)\n", progname, "select", t);
  timeout.tv_sec = t;
  timeout.tv_usec = 0;
  before = time(NULL);
  if (select(0, NULL, NULL, NULL, &timeout) != 0)
    return _error(progname, "select", 2);
  after = time(NULL);
  return (after - before == t) ? 0 : 2;
}


x86 assembly (clang, -O0):
<_select2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xea3(%rip),%rdi
lea    0xebd(%rip),%rdx
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1050 <select@plt>
cmp    $0x0,%rax
je     11bf <_select2+0x7f>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
mov    $0x2,%edx
call   1060 <_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11e3 <_select2+0xa3>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edx
sub    -0x2c(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_select2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xeac(%rip),%rdi
lea    0xec6(%rip),%rdx
mov    %r14,%rsi
mov    %ebx,%ecx
call   1030 <printf@plt>
mov    %ebx,(%rsp)
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
mov    %rsp,%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %rax,%rax
je     11a5 <_select2+0x65>
lea    0xe8b(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1060 <_error@plt>
jmp    11b9 <_select2+0x79>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ecx
sub    %ebp,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setne  %al
add    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [33 x i8] c"%s: Testing %s() (sleeping %us)\0A\00"
@.str.1 = [7 x i8] c"select\00"
define i32 @_select2(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i64 0, i64* %14
%15 = call i32 @time(i32* null)
store i32 %15, i32* %7
%16 = call i64 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %6)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @_error(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %20, i32* %3
br label %30
21: ; preds = %2
%22 = call i32 @time(i32* null)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = sub i32 %23, %24
%26 = load i32, i32* %5
%27 = icmp eq i32 %25, %26
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 0, i32 2
store i32 %29, i32* %3
br label %30
30: ; preds = %21, %18
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [33 x i8] c"%s: Testing %s() (sleeping %us)\0A\00"
@.str.1 = [7 x i8] c"select\00"
define i32 @_select2(i8* %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %1, i32* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %7
%8 = tail call i32 @time(i32* null)
%9 = call i64 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @_error(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %18
13: ; preds = %2
%14 = call i32 @time(i32* null)
%15 = sub i32 %14, %8
%16 = icmp eq i32 %15, %1
%17 = select i1 %16, i32 0, i32 2
br label %18
18: ; preds = %13, %11
%19 = phi i32 [ %12, %11 ], [ %17, %13 ]
ret i32 %19
}