#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_align(struct timeval *);
int timeval_comp(struct timeval *x, struct timeval *y) {
  timeval_align(x);
  timeval_align(y);
  if (x->tv_sec < y->tv_sec) {
    return -1;
  } else if (x->tv_sec > y->tv_sec) {
    return 1;
  } else if (x->tv_usec < y->tv_usec) {
    return -1;
  } else if (x->tv_usec > y->tv_usec) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<timeval_comp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <timeval_align@plt>
mov    -0x18(%rbp),%rdi
call   1030 <timeval_align@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    1152 <timeval_comp+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <timeval_comp+0xad>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    1172 <timeval_comp+0x62>
movl   $0x1,-0x4(%rbp)
jmp    11bd <timeval_comp+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    1194 <timeval_comp+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <timeval_comp+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    11b6 <timeval_comp+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    11bd <timeval_comp+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_comp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <timeval_align@plt>
mov    %rbx,%rdi
call   1030 <timeval_align@plt>
mov    (%rbx),%rcx
mov    $0xffffffff,%eax
cmp    %rcx,(%r14)
jl     1150 <timeval_comp+0x40>
mov    $0x1,%eax
jg     1150 <timeval_comp+0x40>
mov    0x8(%rbx),%rcx
mov    $0xffffffff,%eax
cmp    %rcx,0x8(%r14)
jl     1150 <timeval_comp+0x40>
setg   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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