#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 timeval_compare(struct timeval *a, struct timeval *b) {
  if (a->tv_sec > b->tv_sec) {
    return 1;
  } else if (a->tv_sec < b->tv_sec) {
    return -1;
  } else if (a->tv_usec > b->tv_usec) {
    return 1;
  } else if (a->tv_usec < b->tv_usec) {
    return -1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<timeval_compare>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jle    112c <timeval_compare+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1197 <timeval_compare+0x97>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    114c <timeval_compare+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <timeval_compare+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    116e <timeval_compare+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    1197 <timeval_compare+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    1190 <timeval_compare+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <timeval_compare+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_compare>:
mov    (%rsi),%rcx
mov    $0x1,%eax
cmp    %rcx,(%rdi)
jg     112b <timeval_compare+0x2b>
mov    $0xffffffff,%eax
jl     112b <timeval_compare+0x2b>
mov    0x8(%rsi),%rcx
mov    $0x1,%eax
cmp    %rcx,0x8(%rdi)
jg     112b <timeval_compare+0x2b>
setl   %al
movzbl %al,%eax
neg    %eax
ret

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

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