#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*/ select(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/,
                          struct timeval *);
void millisleep_(int msec) {
  struct timeval dtime;
  if (msec < 1)
    return;
  dtime.tv_sec = msec / 1000;
  dtime.tv_usec = (msec - dtime.tv_sec * 1000) * 1000;
  select(0, 0, 0, 0, &dtime);
}


x86 assembly (clang, -O0):
<millisleep_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    112a <millisleep_+0x1a>
jmp    115e <millisleep_+0x4e>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x3e8,-0x10(%rbp),%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0xc(%rbp)
xor    %ecx,%ecx
lea    -0x10(%rbp),%r8
mov    %ecx,%edi
mov    %ecx,%esi
mov    %ecx,%edx
call   1030 <select@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<millisleep_>:
test   %edi,%edi
jle    114b <millisleep_+0x3b>
push   %rax
mov    %edi,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,(%rsp)
imul   $0xfffffc18,%eax,%eax
add    %edi,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <select@plt>
add    $0x8,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @millisleep_(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
br label %19
7: ; preds = %1
%8 = load i32, i32* %2
%9 = sdiv i32 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %2
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 1000
%15 = sub nsw i32 %11, %14
%16 = mul nsw i32 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @select(i32 0, i32 0, i32 0, i32 0, %struct.timeval* %3)
br label %19
19: ; preds = %7, %6
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @millisleep_(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = icmp slt i32 %0, 1
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = udiv i32 %0, 1000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %6, i32* %7
%8 = mul nsw i32 %6, -1000
%9 = add nsw i32 %8, %0
%10 = mul nsw i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @select(i32 0, i32 0, i32 0, i32 0, %struct.timeval* %2)
br label %13
13: ; preds = %1, %5
ret void
}