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

/* Variables and functions */
int util_timeval_cmp(struct timeval *tv1, struct timeval *tv2) {
  if (!tv1 || !tv2)
    return (tv1) ? 1 : ((tv2) ? -1 : 0);
  if (tv1->tv_sec < tv2->tv_sec)
    return -1;
  if (tv1->tv_sec > tv2->tv_sec)
    return 1;
  if (tv1->tv_usec < tv2->tv_usec)
    return -1;
  if (tv1->tv_usec > tv2->tv_usec)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<util_timeval_cmp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1122 <util_timeval_cmp+0x22>
cmpq   $0x0,-0x18(%rbp)
jne    115a <util_timeval_cmp+0x5a>
cmpq   $0x0,-0x10(%rbp)
je     113a <util_timeval_cmp+0x3a>
mov    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <util_timeval_cmp+0x4f>
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <util_timeval_cmp+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    117a <util_timeval_cmp+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <util_timeval_cmp+0xe5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    119a <util_timeval_cmp+0x9a>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <util_timeval_cmp+0xe5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    11bc <util_timeval_cmp+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <util_timeval_cmp+0xe5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    11de <util_timeval_cmp+0xde>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <util_timeval_cmp+0xe5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_timeval_cmp>:
test   %rdi,%rdi
je     1134 <util_timeval_cmp+0x34>
test   %rsi,%rsi
je     1134 <util_timeval_cmp+0x34>
mov    (%rsi),%rcx
mov    $0xffffffff,%eax
cmp    %rcx,(%rdi)
jl     1133 <util_timeval_cmp+0x33>
mov    $0x1,%eax
jg     1133 <util_timeval_cmp+0x33>
mov    0x8(%rsi),%rcx
mov    $0xffffffff,%eax
cmp    %rcx,0x8(%rdi)
jl     1133 <util_timeval_cmp+0x33>
setg   %al
movzbl %al,%eax
ret
neg    %rsi
sbb    %ecx,%ecx
test   %rdi,%rdi
mov    $0x1,%eax
cmove  %ecx,%eax
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @util_timeval_cmp(%struct.timeval* %0, %struct.timeval* %1) {
%3 = icmp ne %struct.timeval* %0, null
%4 = icmp ne %struct.timeval* %1, null
%5 = and i1 %3, %4
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = sext i1 %4 to i32
%8 = select i1 %3, i32 1, i32 %7
br label %26
9: ; preds = %2
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = icmp slt i64 %11, %13
br i1 %14, label %26, label %15
15: ; preds = %9
%16 = icmp sgt i64 %11, %13
br i1 %16, label %26, label %17
17: ; preds = %15
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%21 = load i64, i64* %20
%22 = icmp slt i64 %19, %21
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = icmp sgt i64 %19, %21
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %23, %17, %15, %9, %6
%27 = phi i32 [ %8, %6 ], [ -1, %9 ], [ 1, %15 ], [ -1, %17 ], [ %25, %23 ]
ret i32 %27
}