#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*/ getmonotime(struct timeval *);
int /*<<< orphan*/ timeradd(struct timeval *, struct timeval *,
                            struct timeval *);
void settimeout(struct timeval *timeout, int msec) {
  struct timeval s = {
      .tv_sec = (msec / 1000),
      .tv_usec = (msec % 1000) * 1000,
  };
  getmonotime(timeout);
  timeradd(timeout, &s, timeout);
}


x86 assembly (clang, -O0):
<settimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getmonotime@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1040 <timeradd@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<settimeout>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movslq %esi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,0x8(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,0xc(%rsp)
call   1030 <getmonotime@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
call   1040 <timeradd@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @settimeout(%struct.timeval* %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%6 = sdiv i32 %1, 1000
store i32 %6, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%8 = srem i32 %1, 1000
%9 = mul nsw i32 %8, 1000
store i32 %9, i32* %7
%10 = tail call i32 @getmonotime(%struct.timeval* %0)
%11 = call i32 @timeradd(%struct.timeval* %0, %struct.timeval* %3, %struct.timeval* %0)
ret void
}