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

/* Variables and functions */
void update_dt(struct timeval *dt, const struct timeval *t1,
               const struct timeval *t2) {
  dt->tv_sec += t2->tv_sec - t1->tv_sec;
  dt->tv_usec += t2->tv_usec - t1->tv_usec;
  if (dt->tv_usec >= 1000000) {
    dt->tv_sec++;
    dt->tv_usec -= 1000000;
  }
}


x86 assembly (clang, -O0):
<update_dt>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
sub    (%rax),%ecx
mov    -0x8(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xf4240,(%rax)
jl     116e <update_dt+0x6e>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_dt>:
mov    0x8(%rdx),%rax
sub    0x8(%rsi),%rax
add    0x8(%rdi),%rax
mov    %rax,0x8(%rdi)
mov    (%rdx),%ecx
sub    (%rsi),%ecx
add    (%rdi),%ecx
mov    %ecx,(%rdi)
cmp    $0xf4240,%ecx
jl     1130 <update_dt+0x30>
add    $0x1,%rax
mov    %rax,0x8(%rdi)
add    $0xfff0bdc0,%ecx
mov    %ecx,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @update_dt(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
%8 = sub nsw i64 %5, %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%10 = load i64, i64* %9
%11 = add nsw i64 %10, %8
store i64 %11, i64* %9
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%18 = load i32, i32* %17
%19 = add nsw i32 %18, %16
store i32 %19, i32* %17
%20 = icmp sgt i32 %19, 999999
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = add nsw i64 %11, 1
store i64 %22, i64* %9
%23 = add nsw i32 %19, -1000000
store i32 %23, i32* %17
br label %24
24: ; preds = %21, %3
ret void
}