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

/* Variables and functions */
int /*<<< orphan*/ warn(char *, unsigned int, unsigned int, unsigned int,
                        unsigned int);
int timeDiff(struct timeval *t1, struct timeval *t2) {
  int secDiff = t2->tv_sec - t1->tv_sec;
  int microDiff = 0;
  if (secDiff != 0)
    microDiff = secDiff * 1000000;
  microDiff += (t2->tv_usec - t1->tv_usec);
  if (microDiff < 0) {
    warn("t1 %u.%u, t2 %u.%u.  t1 > t2 but later?!", (unsigned)t1->tv_sec,
         (unsigned)t1->tv_usec, (unsigned)t2->tv_sec, (unsigned)t2->tv_usec);
    microDiff = 0;
  }
  return microDiff;
}


x86 assembly (clang, -O0):
<timeDiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     114a <timeDiff+0x3a>
imul   $0xf4240,-0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x8(%rax),%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11a2 <timeDiff+0x92>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%r8d
lea    0xe6a(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeDiff>:
push   %rax
mov    %rsi,%rax
mov    (%rsi),%ecx
mov    (%rdi),%esi
mov    %ecx,%edx
sub    %esi,%edx
imul   $0xf4240,%edx,%r9d
mov    0x8(%rax),%r8
mov    0x8(%rdi),%rdx
mov    %r8d,%eax
sub    %edx,%eax
add    %r9d,%eax
js     1137 <timeDiff+0x27>
pop    %rcx
ret
lea    0xec2(%rip),%rdi
call   1030 <warn@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [41 x i8] c"t1 %u.%u, t2 %u.%u. t1 > t2 but later?!\00"
define i32 @timeDiff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i32
%6 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%7 = load %struct.timeval*, %struct.timeval** %4
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %9, %12
store i32 %13, i32* %5
store i32 0, i32* %6
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 1000000
store i32 %18, i32* %6
br label %19
19: ; preds = %16, %2
%20 = load %struct.timeval*, %struct.timeval** %4
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
%22 = load i64, i64* %21
%23 = load %struct.timeval*, %struct.timeval** %3
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub nsw i64 %22, %25
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %19
%34 = load %struct.timeval*, %struct.timeval** %3
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load %struct.timeval*, %struct.timeval** %3
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %37, i32 0, i32 1
%39 = load i64, i64* %38
%40 = trunc i64 %39 to i32
%41 = load %struct.timeval*, %struct.timeval** %4
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = load %struct.timeval*, %struct.timeval** %4
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 1
%46 = load i64, i64* %45
%47 = trunc i64 %46 to i32
%48 = call i32 @warn(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %40, i32 %43, i32 %47)
store i32 0, i32* %6
br label %49
49: ; preds = %33, %19
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [41 x i8] c"t1 %u.%u, t2 %u.%u. t1 > t2 but later?!\00"
define i32 @timeDiff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = sub nsw i32 %4, %6
%8 = mul i32 %7, 1000000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %10, %12
%14 = trunc i64 %13 to i32
%15 = add i32 %8, %14
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = trunc i64 %12 to i32
%19 = trunc i64 %10 to i32
%20 = tail call i32 @warn(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %18, i32 %4, i32 %19)
br label %21
21: ; preds = %17, %2
%22 = phi i32 [ 0, %17 ], [ %15, %2 ]
ret i32 %22
}