#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 */
int /*<<< orphan*/ assert(int);
void differenceTimeval(const struct timeval *first, struct timeval *second) {
  assert(first != NULL);
  assert(second != NULL);
  second->tv_sec = first->tv_sec - second->tv_sec;
  second->tv_usec = first->tv_usec - second->tv_usec;
  if (second->tv_usec < 0) {
    second->tv_sec -= 1;
    second->tv_usec += 1000000;
    assert(0 <= second->tv_usec && second->tv_usec < 1000000);
  }
}


x86 assembly (clang, -O0):
<differenceTimeval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
sub    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11c9 <differenceTimeval+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xf4240,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
jg     11bc <differenceTimeval+0xac>
mov    -0x10(%rbp),%rax
cmpl   $0xf4240,(%rax)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<differenceTimeval>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    0x8(%r14),%rcx
sub    0x8(%rbx),%rcx
mov    %rcx,0x8(%rbx)
mov    (%r14),%eax
sub    (%rbx),%eax
mov    %eax,(%rbx)
js     1153 <differenceTimeval+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rbx)
lea    0xf4240(%rax),%ecx
mov    %ecx,(%rbx)
mov    %eax,%ecx
shr    $0x1f,%ecx
xor    %edi,%edi
cmp    $0xfff0bdc0,%eax
cmovae %ecx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <assert@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define void @differenceTimeval(%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 = icmp ne %struct.timeval* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = icmp ne %struct.timeval* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%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 = load %struct.timeval*, %struct.timeval** %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sub nsw i64 %15, %18
%20 = load %struct.timeval*, %struct.timeval** %4
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
store i64 %19, i64* %21
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%24 = load i32, i32* %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 = sub nsw i32 %24, %27
%29 = load %struct.timeval*, %struct.timeval** %4
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load %struct.timeval*, %struct.timeval** %4
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %57
35: ; preds = %2
%36 = load %struct.timeval*, %struct.timeval** %4
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = sub nsw i64 %38, 1
store i64 %39, i64* %37
%40 = load %struct.timeval*, %struct.timeval** %4
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1000000
store i32 %43, i32* %41
%44 = load %struct.timeval*, %struct.timeval** %4
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = icmp sle i32 0, %46
br i1 %47, label %48, label %53
48: ; preds = %35
%49 = load %struct.timeval*, %struct.timeval** %4
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = icmp slt i32 %51, 1000000
br label %53
53: ; preds = %48, %35
%54 = phi i1 [ false, %35 ], [ %52, %48 ]
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
br label %57
57: ; preds = %53, %2
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @differenceTimeval(%struct.timeval* %0, %struct.timeval* %1) {
%3 = icmp ne %struct.timeval* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne %struct.timeval* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %10, %12
store i64 %13, i64* %11
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
store i32 %18, i32* %16
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %2
%21 = add nsw i64 %13, -1
store i64 %21, i64* %11
%22 = add nsw i32 %18, 1000000
store i32 %22, i32* %16
%23 = icmp ugt i32 %18, -1000001
%24 = lshr i32 %18, 31
%25 = select i1 %23, i32 %24, i32 0
%26 = tail call i32 @assert(i32 %25)
br label %27
27: ; preds = %20, %2
ret void
}