#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 uint32_t;
struct timeval {
  int tv_usec;
  int tv_sec;
};

/* Variables and functions */
void timeval_addMsecs(struct timeval *a, uint32_t msecs) {
  int uSecs = (msecs % 1000) * 1000 + a->tv_usec;
  a->tv_usec = uSecs % 1000000;
  a->tv_sec += msecs / 1000 + uSecs / 1000000;
}


x86 assembly (clang, -O0):
<timeval_addMsecs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    -0x8(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
mov    %edx,(%rax)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
mov    $0xf4240,%esi
cltd
idiv   %esi
add    %eax,%ecx
mov    -0x8(%rbp),%rax
add    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_addMsecs>:
movslq %esi,%rcx
imul   $0x10624dd3,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
imul   $0x3e8,%eax,%edx
sub    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
add    (%rdi),%ecx
movslq %ecx,%rcx
imul   $0x431bde83,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x32,%rdx
add    %esi,%edx
imul   $0xf4240,%edx,%esi
sub    %esi,%ecx
mov    %ecx,(%rdi)
add    %eax,%edx
add    %edx,0x4(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @timeval_addMsecs(%struct.timeval* %0, i32 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i32
%5 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = srem i32 %6, 1000
%8 = mul nsw i32 %7, 1000
%9 = load %struct.timeval*, %struct.timeval** %3
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %8, %11
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = srem i32 %13, 1000000
%15 = load %struct.timeval*, %struct.timeval** %3
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %4
%18 = sdiv i32 %17, 1000
%19 = load i32, i32* %5
%20 = sdiv i32 %19, 1000000
%21 = add nsw i32 %18, %20
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %21
store i32 %25, i32* %23
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @timeval_addMsecs(%struct.timeval* nocapture %0, i32 %1) {
%3 = srem i32 %1, 1000
%4 = mul nsw i32 %3, 1000
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = add nsw i32 %6, %4
%8 = srem i32 %7, 1000000
store i32 %8, i32* %5
%9 = sdiv i32 %1, 1000
%10 = sdiv i32 %7, 1000000
%11 = add nsw i32 %10, %9
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%13 = load i32, i32* %12
%14 = add nsw i32 %11, %13
store i32 %14, i32* %12
ret void
}