#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 */

/* Variables and functions */
int compare(const void *a1, const void *a2) {
  int i1 = 0;
  int i2 = 0;
  if (a1 == NULL && a1 == NULL)
    return (0);
  if (a1 == NULL)
    return (-1);
  if (a2 == NULL)
    return (1);
  i1 = *(int *)a1;
  i2 = *(int *)a2;
  if (i1 > i2)
    return (1);
  if (i1 < i2)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113c <compare+0x3c>
cmpq   $0x0,-0x10(%rbp)
jne    113c <compare+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <compare+0xb3>
cmpq   $0x0,-0x10(%rbp)
jne    1153 <compare+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <compare+0xb3>
cmpq   $0x0,-0x18(%rbp)
jne    116a <compare+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <compare+0xb3>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1194 <compare+0x94>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <compare+0xb3>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ac <compare+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <compare+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
test   %rdi,%rdi
je     111e <compare+0x1e>
mov    $0x1,%eax
test   %rsi,%rsi
je     111d <compare+0x1d>
mov    (%rsi),%ecx
cmp    %ecx,(%rdi)
jg     111d <compare+0x1d>
setl   %al
movzbl %al,%eax
neg    %eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @compare(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %3
br label %39
14: ; preds = %10, %2
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %3
br label %39
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %3
br label %39
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
store i32 %25, i32* %6
%26 = load i8*, i8** %5
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
store i32 %28, i32* %7
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %22
store i32 1, i32* %3
br label %39
33: ; preds = %22
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 -1, i32* %3
br label %39
38: ; preds = %33
store i32 0, i32* %3
br label %39
39: ; preds = %38, %37, %32, %21, %17, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @compare(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = icmp eq i8* %1, null
br i1 %5, label %15, label %6
6: ; preds = %4
%7 = bitcast i8* %0 to i32*
%8 = load i32, i32* %7
%9 = bitcast i8* %1 to i32*
%10 = load i32, i32* %9
%11 = icmp sgt i32 %8, %10
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = icmp slt i32 %8, %10
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %12, %6, %4, %2
%16 = phi i32 [ 0, %2 ], [ 1, %4 ], [ 1, %6 ], [ %14, %12 ]
ret i32 %16
}