#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 worker {
  int dummy;
};
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ worker_sendmsg_deferred(struct worker *, void *,
                                           struct timespec *);
void worker_sendmsg_deferred_ms(struct worker *w, void *m, int ms) {
  struct timespec ts;
  int s;
  clock_gettime(CLOCK_REALTIME, &ts);
  s = ms / 1000;
  ts.tv_sec += s;
  ms -= (s * 1000);
  ts.tv_nsec += (ms * 1000);
  if (ts.tv_nsec > 1000000000L) {
    ts.tv_sec++;
    ts.tv_nsec -= 1000000000L;
  }
  worker_sendmsg_deferred(w, m, &ts);
}


x86 assembly (clang, -O0):
<worker_sendmsg_deferred_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
imul   $0x3e8,-0x2c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
imul   $0x3e8,-0x14(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    $0x3b9aca00,%rax
jle    11a4 <worker_sendmsg_deferred_ms+0x84>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movslq -0x28(%rbp),%rax
sub    $0x3b9aca00,%rax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <worker_sendmsg_deferred@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<worker_sendmsg_deferred_ms>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <clock_gettime@plt>
movslq %ebp,%rcx
imul   $0x10624dd3,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
movslq %eax,%rdx
mov    0x8(%rsp),%rax
add    %rdx,%rax
mov    %rax,0x8(%rsp)
imul   $0xfffffc18,%edx,%edx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
add    (%rsp),%ecx
mov    %ecx,(%rsp)
cmp    $0x3b9aca01,%ecx
jl     1196 <worker_sendmsg_deferred_ms+0x76>
add    $0x1,%rax
mov    %rax,0x8(%rsp)
add    $0xc4653600,%ecx
mov    %ecx,(%rsp)
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <worker_sendmsg_deferred@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.worker = type { i32 }
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
define void @worker_sendmsg_deferred_ms(%struct.worker* %0, i8* %1, i32 %2) {
%4 = alloca %struct.worker*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.timespec
%8 = alloca i32
store %struct.worker* %0, %struct.worker** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* @CLOCK_REALTIME
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %7)
%11 = load i32, i32* %6
%12 = sdiv i32 %11, 1000
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%16 = load i64, i64* %15
%17 = add nsw i64 %16, %14
store i64 %17, i64* %15
%18 = load i32, i32* %8
%19 = mul nsw i32 %18, 1000
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, %19
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = mul nsw i32 %22, 1000
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 %25, %23
store i32 %26, i32* %24
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = icmp sgt i64 %29, 1000000000
br i1 %30, label %31, label %40
31: ; preds = %3
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%33 = load i64, i64* %32
%34 = add nsw i64 %33, 1
store i64 %34, i64* %32
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %37, 1000000000
%39 = trunc i64 %38 to i32
store i32 %39, i32* %35
br label %40
40: ; preds = %31, %3
%41 = load %struct.worker*, %struct.worker** %4
%42 = load i8*, i8** %5
%43 = call i32 @worker_sendmsg_deferred(%struct.worker* %41, i8* %42, %struct.timespec* %7)
ret void
}

LLVM IR (-O2):
%struct.worker = type { i32 }
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
define void @worker_sendmsg_deferred_ms(%struct.worker* %0, i8* %1, i32 %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %4)
%8 = sdiv i32 %2, 1000
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%11 = load i64, i64* %10
%12 = add nsw i64 %11, %9
store i64 %12, i64* %10
%13 = mul nsw i32 %8, -1000
%14 = add i32 %13, %2
%15 = mul nsw i32 %14, 1000
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%17 = load i32, i32* %16
%18 = add nsw i32 %17, %15
store i32 %18, i32* %16
%19 = icmp sgt i32 %18, 1000000000
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = add nsw i64 %12, 1
store i64 %21, i64* %10
%22 = add nsw i32 %18, -1000000000
store i32 %22, i32* %16
br label %23
23: ; preds = %20, %3
%24 = call i32 @worker_sendmsg_deferred(%struct.worker* %0, i8* %1, %struct.timespec* %4)
ret void
}