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

/* Variables and functions */
void timeval_increment(struct timeval *tv, int ms) {
  tv->tv_usec += (ms % 1000000);
  tv->tv_sec += (ms / 1000000);
  tv->tv_sec += tv->tv_usec / 1000000;
  tv->tv_usec = tv->tv_usec % 1000000;
}


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

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

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

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