#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 */
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
void delay(long pMillisecs, struct timeval *pRes) {
  pRes->tv_sec = pMillisecs / 1000;
  pRes->tv_usec = (pMillisecs - (pRes->tv_sec * 1000)) * 1000;
  select(0, NULL, NULL, NULL, pRes);
}


x86 assembly (clang, -O0):
<delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
imul   $0x3e8,(%rcx),%rcx
sub    %rcx,%rax
imul   $0x3e8,%rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%r8
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay>:
mov    %rsi,%r8
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rdx
add    %rax,%rdx
mov    %rdx,(%rsi)
imul   $0xfffffffffffffc18,%rdx,%rax
add    %rdi,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,0x8(%rsi)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
jmp    1030 <select@plt>

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @delay(i64 %0, %struct.timeval* %1) {
%3 = sdiv i64 %0, 1000
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i64 %3, i64* %4
%5 = mul nsw i64 %3, -1000
%6 = add i64 %5, %0
%7 = mul nsw i64 %6, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 %7, i64* %8
%9 = tail call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %1)
ret void
}