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

/* Variables and functions */
bool getDuration(const struct timeval *in_begin, const struct timeval *in_end,
                 struct timeval *out_result) {
  for (*out_result = *in_end; in_begin->tv_usec > out_result->tv_usec;) {
    out_result->tv_usec += 1000000;
    out_result->tv_sec -= 1;
  }
  if (in_begin->tv_sec > out_result->tv_sec) {
    return false;
  } else {
    out_result->tv_sec -= in_begin->tv_sec;
    out_result->tv_usec -= in_begin->tv_usec;
    return true;
  }
}


x86 assembly (clang, -O0):
<getDuration>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rdx
mov    %rdx,(%rax)
mov    0x8(%rcx),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jle    1160 <getDuration+0x60>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
jmp    1126 <getDuration+0x26>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    1182 <getDuration+0x82>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <getDuration+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDuration>:
movups (%rsi),%xmm0
movups %xmm0,(%rdx)
mov    (%rdi),%r8
mov    (%rdx),%rcx
mov    0x8(%rdx),%rsi
cmp    %r8,%rcx
jge    113a <getDuration+0x3a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xf4240,%rcx
mov    %rcx,(%rdx)
add    $0xffffffffffffffff,%rsi
mov    (%rdi),%r8
cmp    %r8,%rcx
jl     1120 <getDuration+0x20>
mov    %rsi,0x8(%rdx)
xor    %eax,%eax
sub    0x8(%rdi),%rsi
jl     1151 <getDuration+0x51>
mov    %rsi,0x8(%rdx)
sub    %r8,%rcx
mov    %rcx,(%rdx)
mov    $0x1,%eax
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @getDuration(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2) {
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %1 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 dereferenceable(16) %4, i8* align 8 dereferenceable(16) %5, i64 16, i1 false)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i64, i64* %6
%9 = load i64, i64* %7
%10 = icmp slt i64 %9, %8
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%12 = load i64, i64* %11
br i1 %10, label %13, label %21
13: ; preds = %3, %13
%14 = phi i64 [ %17, %13 ], [ %12, %3 ]
%15 = phi i64 [ %16, %13 ], [ %9, %3 ]
%16 = add nsw i64 %15, 1000000
store i64 %16, i64* %7
%17 = add nsw i64 %14, -1
%18 = load i64, i64* %6
%19 = icmp slt i64 %16, %18
br i1 %19, label %13, label %20
20: ; preds = %13
store i64 %17, i64* %11
br label %21
21: ; preds = %3, %20
%22 = phi i64 [ %17, %20 ], [ %12, %3 ]
%23 = phi i64 [ %18, %20 ], [ %8, %3 ]
%24 = phi i64 [ %16, %20 ], [ %9, %3 ]
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%26 = load i64, i64* %25
%27 = icmp slt i64 %22, %26
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%30 = sub nsw i64 %22, %26
store i64 %30, i64* %29
%31 = sub nsw i64 %24, %23
store i64 %31, i64* %7
br label %32
32: ; preds = %21, %28
%33 = phi i32 [ 1, %28 ], [ 0, %21 ]
ret i32 %33
}