#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 int time_t;
struct timespec {
  int tv_sec;
  unsigned long tv_nsec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, struct timespec *);
void wait(unsigned long milliseconds) {
  unsigned long millisecs = milliseconds;
  struct timespec req = {0};
  time_t sec = (int)(millisecs / 1000);
  millisecs = millisecs - (sec * 1000);
  req.tv_sec = sec;
  req.tv_nsec = millisecs * 1000000L;
  nanosleep(&req, &req);
}


x86 assembly (clang, -O0):
<wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3e8,-0x2c(%rbp),%ecx
movslq %ecx,%rcx
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
imul   $0xf4240,-0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <nanosleep@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait>:
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
movabs $0x3e800000000,%rax
imul   %rdx,%rax
sar    $0x20,%rax
sub    %rax,%rdi
mov    %edx,(%rsp)
imul   $0xf4240,%rdi,%rax
mov    %rax,0x8(%rsp)
mov    %rsp,%rdi
mov    %rdi,%rsi
call   1030 <nanosleep@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64, i32 }
define void @wait(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca %struct.timespec
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
store i64 %6, i64* %3
%7 = bitcast %struct.timespec* %4 to i8*
%8 = load i64, i64* %3
%9 = udiv i64 %8, 1000
%10 = trunc i64 %9 to i32
store i32 %10, i32* %5
%11 = load i64, i64* %3
%12 = load i32, i32* %5
%13 = mul nsw i32 %12, 1000
%14 = sext i32 %13 to i64
%15 = sub i64 %11, %14
store i64 %15, i64* %3
%16 = load i32, i32* %5
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i64, i64* %3
%19 = mul i64 %18, 1000000
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 %19, i64* %20
%21 = call i32 @nanosleep(%struct.timespec* %4, %struct.timespec* %4)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64, i32 }
define void @wait(i64 %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = udiv i64 %0, 1000
%5 = trunc i64 %4 to i32
%6 = mul i64 %4, 4294967296000
%7 = ashr exact i64 %6, 32
%8 = sub i64 %0, %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %5, i32* %9
%10 = mul i64 %8, 1000000
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %10, i64* %11
%12 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %2)
ret void
}