#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*/ assert(int);
int tvalcmp(const struct timeval *tv1, const struct timeval *tv2) {
  assert(tv1 && tv2);
  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):
<tvalcmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     113b <tvalcmp+0x2b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    1168 <tvalcmp+0x58>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <tvalcmp+0xc3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    1188 <tvalcmp+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <tvalcmp+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    11aa <tvalcmp+0x9a>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <tvalcmp+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    11cc <tvalcmp+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <tvalcmp+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvalcmp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    (%rbx),%rcx
mov    $0x1,%eax
cmp    %rcx,(%r14)
jg     115b <tvalcmp+0x4b>
mov    $0xffffffff,%eax
jl     115b <tvalcmp+0x4b>
mov    0x8(%rbx),%rcx
mov    $0x1,%eax
cmp    %rcx,0x8(%r14)
jg     115b <tvalcmp+0x4b>
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 @tvalcmp(%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 label %11
11: ; preds = %8, %2
%12 = phi i1 [ false, %2 ], [ %10, %8 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load %struct.timeval*, %struct.timeval** %4
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load %struct.timeval*, %struct.timeval** %5
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp sgt i64 %17, %20
br i1 %21, label %22, label %23
22: ; preds = %11
store i32 1, i32* %3
br label %51
23: ; preds = %11
%24 = load %struct.timeval*, %struct.timeval** %4
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = load %struct.timeval*, %struct.timeval** %5
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = icmp slt i64 %26, %29
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 -1, i32* %3
br label %51
32: ; preds = %23
%33 = load %struct.timeval*, %struct.timeval** %4
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 1
%35 = load i64, i64* %34
%36 = load %struct.timeval*, %struct.timeval** %5
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = icmp sgt i64 %35, %38
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 1, i32* %3
br label %51
41: ; preds = %32
%42 = load %struct.timeval*, %struct.timeval** %4
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %42, i32 0, i32 1
%44 = load i64, i64* %43
%45 = load %struct.timeval*, %struct.timeval** %5
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %45, i32 0, i32 1
%47 = load i64, i64* %46
%48 = icmp slt i64 %44, %47
br i1 %48, label %49, label %50
49: ; preds = %41
store i32 -1, i32* %3
br label %51
50: ; preds = %41
store i32 0, i32* %3
br label %51
51: ; preds = %50, %49, %40, %31, %22
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @tvalcmp(%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
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = icmp sgt i64 %9, %11
br i1 %12, label %24, label %13
13: ; preds = %2
%14 = icmp slt i64 %9, %11
br i1 %14, label %24, label %15
15: ; preds = %13
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%19 = load i64, i64* %18
%20 = icmp sgt i64 %17, %19
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = icmp slt i64 %17, %19
%23 = sext i1 %22 to i32
br label %24
24: ; preds = %21, %15, %13, %2
%25 = phi i32 [ 1, %2 ], [ -1, %13 ], [ 1, %15 ], [ %23, %21 ]
ret i32 %25
}