#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 */
typedef int uint64_t;
struct timespec {
  unsigned int tv_nsec;
  unsigned int tv_sec;
};

/* Variables and functions */
void timespec_mult(struct timespec a, unsigned times, struct timespec *res) {
  uint64_t nano = a.tv_nsec * times;
  res->tv_sec = a.tv_sec * times;
  res->tv_sec += nano / 1000000000;
  res->tv_nsec = nano % 1000000000;
}


x86 assembly (clang, -O0):
<timespec_mult>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%ecx
imul   -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
add    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_mult>:
mov    %rdi,%rax
shr    $0x20,%rax
imul   %esi,%edi
imul   %esi,%eax
movslq %edi,%rcx
imul   $0x44b82fa1,%rcx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x3c,%rsi
add    %edi,%esi
add    %esi,%eax
mov    %eax,0x4(%rdx)
imul   $0x3b9aca00,%esi,%eax
sub    %eax,%ecx
mov    %ecx,(%rdx)
ret

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

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @timespec_mult(i64 %0, i32 %1, %struct.timespec* nocapture writeonly %2) {
%4 = trunc i64 %0 to i32
%5 = lshr i64 %0, 32
%6 = trunc i64 %5 to i32
%7 = mul i32 %4, %1
%8 = mul i32 %6, %1
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%10 = sdiv i32 %7, 1000000000
%11 = add i32 %8, %10
store i32 %11, i32* %9
%12 = srem i32 %7, 1000000000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %12, i32* %13
ret void
}