#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 system {
  int dummy;
};

/* Variables and functions */
scalar_t__ system_distance(struct system const *, struct system const *);
int cmp_system_distances(const void *_system1, const void *_system2,
                         void *_origin) {
  const struct system *system1 = _system1;
  const struct system *system2 = _system2;
  const struct system *origin = _origin;
  if (system1 == origin)
    return -1;
  else if (system2 == origin)
    return 1;
  else
    return (long)system_distance(origin, system1) -
           (long)system_distance(origin, system2);
}


x86 assembly (clang, -O0):
<cmp_system_distances>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1156 <cmp_system_distances+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <cmp_system_distances+0x8b>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1170 <cmp_system_distances+0x60>
movl   $0x1,-0x4(%rbp)
jmp    119b <cmp_system_distances+0x8b>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <system_distance@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <system_distance@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_system_distances>:
push   %r15
push   %r14
push   %rbx
cmp    %rdx,%rdi
je     1143 <cmp_system_distances+0x33>
mov    %rdx,%rbx
mov    %rsi,%r14
cmp    %rdx,%rsi
je     114b <cmp_system_distances+0x3b>
mov    %rdi,%rsi
mov    %rbx,%rdi
call   1030 <system_distance@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <system_distance@plt>
sub    %eax,%r15d
jmp    1151 <cmp_system_distances+0x41>
mov    $0xffffffff,%r15d
jmp    1151 <cmp_system_distances+0x41>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.system = type { i32 }
define i32 @cmp_system_distances(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.system*
%9 = alloca %struct.system*
%10 = alloca %struct.system*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to %struct.system*
store %struct.system* %12, %struct.system** %8
%13 = load i8*, i8** %6
%14 = bitcast i8* %13 to %struct.system*
store %struct.system* %14, %struct.system** %9
%15 = load i8*, i8** %7
%16 = bitcast i8* %15 to %struct.system*
store %struct.system* %16, %struct.system** %10
%17 = load %struct.system*, %struct.system** %8
%18 = load %struct.system*, %struct.system** %10
%19 = icmp eq %struct.system* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -1, i32* %4
br label %35
21: ; preds = %3
%22 = load %struct.system*, %struct.system** %9
%23 = load %struct.system*, %struct.system** %10
%24 = icmp eq %struct.system* %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 1, i32* %4
br label %35
26: ; preds = %21
%27 = load %struct.system*, %struct.system** %10
%28 = load %struct.system*, %struct.system** %8
%29 = call i64 @system_distance(%struct.system* %27, %struct.system* %28)
%30 = load %struct.system*, %struct.system** %10
%31 = load %struct.system*, %struct.system** %9
%32 = call i64 @system_distance(%struct.system* %30, %struct.system* %31)
%33 = sub nsw i64 %29, %32
%34 = trunc i64 %33 to i32
store i32 %34, i32* %4
br label %35
35: ; preds = %26, %25, %20
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.system = type { i32 }
define i32 @cmp_system_distances(i8* %0, i8* %1, i8* %2) {
%4 = bitcast i8* %0 to %struct.system*
%5 = bitcast i8* %1 to %struct.system*
%6 = bitcast i8* %2 to %struct.system*
%7 = icmp eq i8* %0, %2
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = icmp eq i8* %1, %2
br i1 %9, label %15, label %10
10: ; preds = %8
%11 = tail call i64 @system_distance(%struct.system* %6, %struct.system* %4)
%12 = tail call i64 @system_distance(%struct.system* %6, %struct.system* %5)
%13 = sub nsw i64 %11, %12
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %8, %3, %10
%16 = phi i32 [ %14, %10 ], [ -1, %3 ], [ 1, %8 ]
ret i32 %16
}