#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 long tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
void util_timeval_add(struct timeval *tv, long long interval) {
  long long usec;
  if (!tv)
    return;
  tv->tv_sec += (interval / 1000000);
  usec = tv->tv_usec + (interval % 1000000);
  if (usec > 1000000) {
    tv->tv_usec = usec % 1000000;
    tv->tv_sec++;
  } else
    tv->tv_usec = usec;
}


x86 assembly (clang, -O0):
<util_timeval_add>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    111c <util_timeval_add+0x1c>
jmp    11a0 <util_timeval_add+0xa0>
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x20(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xf4240,-0x18(%rbp)
jle    1195 <util_timeval_add+0x95>
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x8(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
jmp    11a0 <util_timeval_add+0xa0>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_timeval_add>:
test   %rdi,%rdi
je     1167 <util_timeval_add+0x67>
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    0x8(%rdi),%rcx
mov    %rcx,0x8(%rdi)
sub    %rax,%rsi
add    (%rdi),%rsi
cmp    $0xf4241,%rsi
jl     1164 <util_timeval_add+0x64>
mov    %rsi,%rax
mul    %r8
shr    $0x12,%rdx
imul   $0xf4240,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,(%rdi)
add    $0x1,%rcx
mov    %rcx,0x8(%rdi)
ret
mov    %rsi,(%rdi)
ret

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

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