#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 dummy;
};

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ timersub(struct timeval const *, struct timeval const *,
                            struct timeval *);
int /*<<< orphan*/ timeval_delta_valid(struct timeval const *,
                                       struct timeval const *);
int timeval_delta(const struct timeval *start, const struct timeval *end,
                  struct timeval *delta) {
  if (!start || !end || !delta || !timeval_delta_valid(start, end))
    return EINVAL;
  timersub(end, start, delta);
  return 0;
}


x86 assembly (clang, -O0):
<timeval_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <timeval_delta+0x4b>
cmpq   $0x0,-0x18(%rbp)
je     116b <timeval_delta+0x4b>
cmpq   $0x0,-0x20(%rbp)
je     116b <timeval_delta+0x4b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <timeval_delta_valid@plt>
cmp    $0x0,%eax
jne    117c <timeval_delta+0x5c>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <timeval_delta+0x74>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <timersub@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_delta>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     115b <timeval_delta+0x3b>
mov    %rsi,%r15
test   %rsi,%rsi
je     115b <timeval_delta+0x3b>
mov    %rdx,%r14
test   %rdx,%rdx
je     115b <timeval_delta+0x3b>
mov    %rdi,%rbx
mov    %r15,%rsi
call   1030 <timeval_delta_valid@plt>
test   %eax,%eax
je     115b <timeval_delta+0x3b>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <timersub@plt>
xor    %eax,%eax
jmp    1164 <timeval_delta+0x44>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@EINVAL = global i32 0
define i32 @timeval_delta(%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** %5
%9 = icmp ne %struct.timeval* %8, null
br i1 %9, label %10, label %21
10: ; preds = %3
%11 = load %struct.timeval*, %struct.timeval** %6
%12 = icmp ne %struct.timeval* %11, null
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load %struct.timeval*, %struct.timeval** %7
%15 = icmp ne %struct.timeval* %14, null
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load %struct.timeval*, %struct.timeval** %5
%18 = load %struct.timeval*, %struct.timeval** %6
%19 = call i32 @timeval_delta_valid(%struct.timeval* %17, %struct.timeval* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16, %13, %10, %3
%22 = load i32, i32* @EINVAL
store i32 %22, i32* %4
br label %28
23: ; preds = %16
%24 = load %struct.timeval*, %struct.timeval** %6
%25 = load %struct.timeval*, %struct.timeval** %5
%26 = load %struct.timeval*, %struct.timeval** %7
%27 = call i32 @timersub(%struct.timeval* %24, %struct.timeval* %25, %struct.timeval* %26)
store i32 0, i32* %4
br label %28
28: ; preds = %23, %21
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@EINVAL = global i32 0
define i32 @timeval_delta(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = icmp ne %struct.timeval* %0, null
%5 = icmp ne %struct.timeval* %1, null
%6 = and i1 %4, %5
%7 = icmp ne %struct.timeval* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @timeval_delta_valid(%struct.timeval* %0, %struct.timeval* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9, %3
%13 = load i32, i32* @EINVAL
br label %16
14: ; preds = %9
%15 = tail call i32 @timersub(%struct.timeval* %1, %struct.timeval* %0, %struct.timeval* %2)
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ 0, %14 ], [ %13, %12 ]
ret i32 %17
}