#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 */
int /*<<< orphan*/ msg(char *);
scalar_t__ select(int, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/, struct timeval *);
void msleep(int t) {
  struct timeval timeout;
  timeout.tv_sec = t / 1000;
  timeout.tv_usec = (t % 1000) * 1000;
  if (select(1, 0, 0, 0, &timeout) < 0)
    msg("ES2select failed in msleep:");
}


x86 assembly (clang, -O0):
<msleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
xor    %ecx,%ecx
lea    -0x10(%rbp),%r8
mov    %ecx,%esi
mov    %ecx,%edx
call   1030 <select@plt>
cmp    $0x0,%rax
jge    1177 <msleep+0x57>
lea    0xe8e(%rip),%rdi
call   1040 <msg@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msleep>:
push   %rax
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%r8
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <select@plt>
test   %rax,%rax
js     1167 <msleep+0x47>
pop    %rax
ret
lea    0xe92(%rip),%rdi
call   1040 <msg@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [28 x i8] c"ES2select failed in msleep:\00"
define void @msleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = sdiv i32 %4, 1000
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* %2
%8 = srem i32 %7, 1000
%9 = mul nsw i32 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %9, i32* %10
%11 = call i64 @select(i32 1, i32 0, i32 0, i32 0, %struct.timeval* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [28 x i8] c"ES2select failed in msleep:\00"
define void @msleep(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = sdiv i32 %0, 1000
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %4, i32* %5
%6 = srem i32 %0, 1000
%7 = mul nsw i32 %6, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = call i64 @select(i32 1, i32 0, i32 0, i32 0, %struct.timeval* %2)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
ret void
}