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

/* Variables and functions */
void ts_plus(struct timespec *tsp2, const struct timespec *tsp1, int ms) {
  int nsec = tsp1->tv_nsec + (ms % 1000) * 1000000;
  tsp2->tv_sec = tsp1->tv_sec + ms / 1000 + nsec / 1000000000;
  tsp2->tv_nsec = nsec % 1000000000;
}


x86 assembly (clang, -O0):
<ts_plus>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
imul   $0xf4240,%edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x14(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
cltq
add    %rax,%rcx
mov    -0x18(%rbp),%eax
mov    $0x3b9aca00,%esi
cltd
idiv   %esi
cltq
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
mov    %edx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_plus>:
movslq %edx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%edx
sub    %edx,%eax
imul   $0xf4240,%eax,%eax
add    (%rsi),%eax
movslq %ecx,%rcx
add    0x8(%rsi),%rcx
cltq
imul   $0x44b82fa1,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x3c,%rdx
add    %esi,%edx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,0x8(%rdi)
imul   $0x3b9aca00,%edx,%ecx
sub    %ecx,%eax
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
define void @ts_plus(%struct.timespec* %0, %struct.timespec* %1, i32 %2) {
%4 = alloca %struct.timespec*
%5 = alloca %struct.timespec*
%6 = alloca i32
%7 = alloca i32
store %struct.timespec* %0, %struct.timespec** %4
store %struct.timespec* %1, %struct.timespec** %5
store i32 %2, i32* %6
%8 = load %struct.timespec*, %struct.timespec** %5
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* %6
%12 = srem i32 %11, 1000
%13 = mul nsw i32 %12, 1000000
%14 = add nsw i32 %10, %13
store i32 %14, i32* %7
%15 = load %struct.timespec*, %struct.timespec** %5
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = load i32, i32* %6
%19 = sdiv i32 %18, 1000
%20 = sext i32 %19 to i64
%21 = add nsw i64 %17, %20
%22 = load i32, i32* %7
%23 = sdiv i32 %22, 1000000000
%24 = sext i32 %23 to i64
%25 = add nsw i64 %21, %24
%26 = load %struct.timespec*, %struct.timespec** %4
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i32 0, i32 1
store i64 %25, i64* %27
%28 = load i32, i32* %7
%29 = srem i32 %28, 1000000000
%30 = load %struct.timespec*, %struct.timespec** %4
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %30, i32 0, i32 0
store i32 %29, i32* %31
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
define void @ts_plus(%struct.timespec* nocapture writeonly %0, %struct.timespec* nocapture %1, i32 %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = srem i32 %2, 1000
%7 = mul nsw i32 %6, 1000000
%8 = add nsw i32 %5, %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = sdiv i32 %2, 1000
%12 = sext i32 %11 to i64
%13 = add nsw i64 %10, %12
%14 = sdiv i32 %8, 1000000000
%15 = sext i32 %14 to i64
%16 = add nsw i64 %13, %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %16, i64* %17
%18 = srem i32 %8, 1000000000
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i32 %18, i32* %19
ret void
}