#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void time_spent(struct timeval *start_time, struct timeval *end_time,
                struct timeval *resulting_time) {
  if ((start_time) == NULL) {
    fprintf(stderr, "usage of a null pointer in function %s \n",
            "time_spent()");
    exit(EXIT_FAILURE);
  }
  if ((end_time) == NULL) {
    fprintf(stderr, "usage of a null pointer in function %s \n",
            "time_spent()");
    exit(EXIT_FAILURE);
  }
  if ((resulting_time) == NULL) {
    fprintf(stderr, "usage of a null pointer in function %s \n",
            "time_spent()");
    exit(EXIT_FAILURE);
  }
  resulting_time->tv_sec = end_time->tv_sec - start_time->tv_sec;
  resulting_time->tv_usec = end_time->tv_usec - start_time->tv_usec;
  if (resulting_time->tv_usec < 0) {
    --resulting_time->tv_sec;
    resulting_time->tv_usec += 1000000;
  }
  return;
}


x86 assembly (clang, -O0):
<time_spent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1169 <time_spent+0x49>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
lea    0xed3(%rip),%rdx
call   1030 <fprintf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    119e <time_spent+0x7e>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
lea    0xe9e(%rip),%rdx
call   1030 <fprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <time_spent+0xb3>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
lea    0xe69(%rip),%rdx
call   1030 <fprintf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
sub    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jge    122f <time_spent+0x10f>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_spent>:
push   %rax
test   %rdi,%rdi
je     115a <time_spent+0x3a>
test   %rsi,%rsi
je     115a <time_spent+0x3a>
test   %rdx,%rdx
je     115a <time_spent+0x3a>
movdqu (%rsi),%xmm0
movdqu (%rdi),%xmm1
psubq  %xmm1,%xmm0
movdqu %xmm0,(%rdx)
movq   %xmm0,%rax
test   %rax,%rax
js     114c <time_spent+0x2c>
pop    %rax
ret
paddq  0xeac(%rip),%xmm0
movdqu %xmm0,(%rdx)
pop    %rax
ret
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
lea    0xec8(%rip),%rdx
call   1030 <fprintf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [41 x i8] c"usage of a null pointer in function %s \0A\00"
@.str.1 = [13 x i8] c"time_spent()\00"
@EXIT_FAILURE = global i32 0
define void @time_spent(%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** %4
%8 = icmp eq %struct.timeval* %7, null
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %3
%15 = load %struct.timeval*, %struct.timeval** %5
%16 = icmp eq %struct.timeval* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = load %struct.timeval*, %struct.timeval** %6
%24 = icmp eq %struct.timeval* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = load %struct.timeval*, %struct.timeval** %5
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 1
%33 = load i64, i64* %32
%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 = sub nsw i64 %33, %36
%38 = load %struct.timeval*, %struct.timeval** %6
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %38, i32 0, i32 1
store i64 %37, i64* %39
%40 = load %struct.timeval*, %struct.timeval** %5
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load %struct.timeval*, %struct.timeval** %4
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i32 0, i32 0
%45 = load i64, i64* %44
%46 = sub nsw i64 %42, %45
%47 = load %struct.timeval*, %struct.timeval** %6
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %47, i32 0, i32 0
store i64 %46, i64* %48
%49 = load %struct.timeval*, %struct.timeval** %6
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %30
%54 = load %struct.timeval*, %struct.timeval** %6
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %54, i32 0, i32 1
%56 = load i64, i64* %55
%57 = add nsw i64 %56, -1
store i64 %57, i64* %55
%58 = load %struct.timeval*, %struct.timeval** %6
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %58, i32 0, i32 0
%60 = load i64, i64* %59
%61 = add nsw i64 %60, 1000000
store i64 %61, i64* %59
br label %62
62: ; preds = %53, %30
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@stderr = global i32 0
@.str = [41 x i8] c"usage of a null pointer in function %s \0A\00"
@.str.1 = [13 x i8] c"time_spent()\00"
@EXIT_FAILURE = global i32 0
define void @time_spent(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = icmp eq %struct.timeval* %0, null
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = icmp eq %struct.timeval* %1, null
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %10
%18 = icmp eq %struct.timeval* %2, null
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %17
%25 = bitcast %struct.timeval* %1 to <2 x i64>*
%26 = load <2 x i64>, <2 x i64>* %25
%27 = bitcast %struct.timeval* %0 to <2 x i64>*
%28 = load <2 x i64>, <2 x i64>* %27
%29 = sub nsw <2 x i64> %26, %28
%30 = bitcast %struct.timeval* %2 to <2 x i64>*
store <2 x i64> %29, <2 x i64>* %30
%31 = extractelement <2 x i64> %29, i64 0
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = add nsw <2 x i64> %29, <i64 1000000, i64 -1>
%35 = bitcast %struct.timeval* %2 to <2 x i64>*
store <2 x i64> %34, <2 x i64>* %35
br label %36
36: ; preds = %33, %24
ret void
}