#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 */
struct timespec Timespec_add2(const struct timespec x, long long usec) {
  struct timespec retval;
  long long n, m;
  const long long K = (1000LL * 1000LL);
  n = usec / K;
  m = usec % K + ((long long)x.tv_nsec / 1000LL);
  n += m / K;
  m = (m % K) * 1000LL;
  retval.tv_sec = x.tv_sec + (int)n;
  retval.tv_nsec = (int)m;
  return retval;
}


x86 assembly (clang, -O0):
<Timespec_add2>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x28(%rbp)
movq   $0xf4240,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
imul   %rcx
mov    %rdx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x12,%rax
add    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
imul   %rcx
mov    -0x58(%rbp),%rax
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x12,%rdx
add    %rsi,%rdx
imul   $0xf4240,%rdx,%rdx
sub    %rdx,%rax
mov    %rax,-0x50(%rbp)
movslq -0x20(%rbp),%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
imul   %rdx
mov    -0x50(%rbp),%rax
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x7,%rdx
add    %rsi,%rdx
add    %rdx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
mov    -0x30(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
imul   %rcx
mov    -0x48(%rbp),%rax
mov    %rdx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x12,%rcx
add    %rdx,%rcx
imul   $0xf4240,%rcx,%rcx
sub    %rcx,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<Timespec_add2>:
mov    %rdx,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x12,%rdx
add    %eax,%edx
imul   $0xf4240,%edx,%eax
sub    %eax,%ecx
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
sar    $0x26,%rax
add    %edi,%eax
add    %ecx,%eax
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x32,%rcx
add    %edi,%ecx
add    %ecx,%edx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
movslq %edx,%rdx
add    %rsi,%rdx
imul   $0x3e8,%eax,%eax
ret

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

LLVM IR (-O2):
define { i32, i64 } @Timespec_add2(i32 %0, i64 %1, i64 %2) {
%4 = sdiv i64 %2, 1000000
%5 = srem i64 %2, 1000000
%6 = sdiv i32 %0, 1000
%7 = trunc i64 %5 to i32
%8 = add nsw i32 %6, %7
%9 = sdiv i32 %8, 1000000
%10 = zext i32 %9 to i64
%11 = add nsw i64 %4, %10
%12 = srem i32 %8, 1000000
%13 = shl i64 %11, 32
%14 = ashr exact i64 %13, 32
%15 = add nsw i64 %14, %1
%16 = mul nsw i32 %12, 1000
%17 = insertvalue { i32, i64 } poison, i32 %16, 0
%18 = insertvalue { i32, i64 } %17, i64 %15, 1
ret { i32, i64 } %18
}