#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 /*<<< orphan*/ timeval_adjust_usec(struct timeval *, struct timeval *);
int timeval_cmp(struct timeval *l, struct timeval *r) {
  timeval_adjust_usec(l, r);
  if (l->tv_sec > r->tv_sec) {
    return 1;
  } else if (l->tv_sec < r->tv_sec) {
    return -1;
  } else {
    if (l->tv_usec > r->tv_usec)
      return 1;
    else if (l->tv_usec < r->tv_usec)
      return -1;
    else
      return 0;
  }
}


x86 assembly (clang, -O0):
<timeval_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <timeval_adjust_usec@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    114d <timeval_cmp+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    11b8 <timeval_cmp+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    116d <timeval_cmp+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <timeval_cmp+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    118f <timeval_cmp+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    11b8 <timeval_cmp+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    11b1 <timeval_cmp+0xa1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <timeval_cmp+0xa8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_cmp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <timeval_adjust_usec@plt>
mov    (%rbx),%rcx
mov    $0x1,%eax
cmp    %rcx,(%r14)
jg     114a <timeval_cmp+0x3a>
mov    $0xffffffff,%eax
jl     114a <timeval_cmp+0x3a>
mov    0x8(%rbx),%rcx
mov    $0x1,%eax
cmp    %rcx,0x8(%r14)
jg     114a <timeval_cmp+0x3a>
setl   %al
movzbl %al,%eax
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @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 = load %struct.timeval*, %struct.timeval** %5
%8 = call i32 @timeval_adjust_usec(%struct.timeval* %6, %struct.timeval* %7)
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load %struct.timeval*, %struct.timeval** %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp sgt i64 %11, %14
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %45
17: ; preds = %2
%18 = load %struct.timeval*, %struct.timeval** %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = load %struct.timeval*, %struct.timeval** %5
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = icmp slt i64 %20, %23
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 -1, i32* %3
br label %45
26: ; preds = %17
%27 = load %struct.timeval*, %struct.timeval** %4
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 1
%29 = load i64, i64* %28
%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 = icmp sgt i64 %29, %32
br i1 %33, label %34, label %35
34: ; preds = %26
store i32 1, i32* %3
br label %45
35: ; preds = %26
%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 = load %struct.timeval*, %struct.timeval** %5
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %39, i32 0, i32 1
%41 = load i64, i64* %40
%42 = icmp slt i64 %38, %41
br i1 %42, label %43, label %44
43: ; preds = %35
store i32 -1, i32* %3
br label %45
44: ; preds = %35
store i32 0, i32* %3
br label %45
45: ; preds = %44, %43, %34, %25, %16
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @timeval_cmp(%struct.timeval* %0, %struct.timeval* %1) {
%3 = tail call i32 @timeval_adjust_usec(%struct.timeval* %0, %struct.timeval* %1)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load i64, i64* %6
%8 = icmp sgt i64 %5, %7
br i1 %8, label %20, label %9
9: ; preds = %2
%10 = icmp slt i64 %5, %7
br i1 %10, label %20, label %11
11: ; preds = %9
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%15 = load i64, i64* %14
%16 = icmp sgt i64 %13, %15
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = icmp slt i64 %13, %15
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %17, %11, %9, %2
%21 = phi i32 [ 1, %2 ], [ -1, %9 ], [ 1, %11 ], [ %19, %17 ]
ret i32 %21
}