#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 timediff(struct timeval *from, struct timeval *to) {
  to->tv_sec -= from->tv_sec;
  if (to->tv_usec >= from->tv_usec)
    to->tv_usec -= from->tv_usec;
  else {
    to->tv_sec--;
    to->tv_usec += 1000000 - from->tv_usec;
  }
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jl     114a <timediff+0x4a>
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
jmp    116d <timediff+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
sub    (%rax),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
mov    0x8(%rsi),%rdx
sub    0x8(%rdi),%rdx
mov    %rdx,0x8(%rsi)
mov    (%rsi),%eax
mov    (%rdi),%ecx
cmp    %ecx,%eax
jge    1121 <timediff+0x21>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rsi)
add    $0xf4240,%eax
sub    %ecx,%eax
mov    %eax,(%rsi)
ret

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

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