#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 {
  long tv_sec;
  long tv_usec;
};
typedef long int64_t;

/* Variables and functions */
void add_usecs(struct timeval *t, int64_t usecs) {
  t->tv_sec += usecs / 1000000L;
  t->tv_usec += usecs % 1000000L;
  if (t->tv_usec >= 1000000L) {
    t->tv_sec += t->tv_usec / 1000000L;
    t->tv_usec %= 1000000L;
  }
}


x86 assembly (clang, -O0):
<add_usecs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rdx
mov    %rdx,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0xf4240,0x8(%rax)
jl     1190 <add_usecs+0x90>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x8(%rax),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%rax
mov    %rdx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_usecs>:
movabs $0x431bde82d7b634db,%r8
de 1b 43
mov    %rsi,%rax
imul   %r8
mov    %rdx,%rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rcx
add    %rax,%rcx
imul   $0xf4240,%rcx,%rax
add    (%rdi),%rcx
mov    %rcx,(%rdi)
sub    %rax,%rsi
add    0x8(%rdi),%rsi
mov    %rsi,0x8(%rdi)
cmp    $0xf4240,%rsi
jl     1160 <add_usecs+0x60>
mov    %rsi,%rax
mul    %r8
shr    $0x12,%rdx
add    %rdx,%rcx
mov    %rcx,(%rdi)
imul   $0xf4240,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,0x8(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @add_usecs(%struct.timeval* nocapture %0, i64 %1) {
%3 = sdiv i64 %1, 1000000
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = add nsw i64 %5, %3
store i64 %6, i64* %4
%7 = srem i64 %1, 1000000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %7
store i64 %10, i64* %8
%11 = icmp sgt i64 %10, 999999
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = udiv i64 %10, 1000000
%14 = add nsw i64 %13, %6
store i64 %14, i64* %4
%15 = urem i64 %10, 1000000
store i64 %15, i64* %8
br label %16
16: ; preds = %12, %2
ret void
}