#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 /*<<< orphan*/ swap(int *, int *);
void three_sort(int *arr) {
  if (arr[0] > arr[2])
    swap(arr, arr + 2);
  if (arr[0] > arr[1])
    swap(arr, arr + 1);
  if (arr[1] > arr[2])
    swap(arr + 1, arr + 2);
}


x86 assembly (clang, -O0):
<three_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
cmp    0x8(%rcx),%eax
jle    1140 <three_sort+0x30>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x8,%rsi
call   1030 <swap@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
cmp    0x4(%rcx),%eax
jle    1164 <three_sort+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
call   1030 <swap@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
cmp    0x8(%rcx),%eax
jle    118d <three_sort+0x7d>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
add    $0x8,%rsi
call   1030 <swap@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<three_sort>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%eax
lea    0x8(%rdi),%r14
cmp    0x8(%rdi),%eax
jle    1130 <three_sort+0x20>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <swap@plt>
mov    (%rbx),%eax
lea    0x4(%rbx),%r15
mov    0x4(%rbx),%ecx
cmp    %ecx,%eax
jle    1149 <three_sort+0x39>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <swap@plt>
mov    0x4(%rbx),%ecx
cmp    (%r14),%ecx
jle    115e <three_sort+0x4e>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <swap@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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