#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_diag_elems(long **, long **, long **, int, int);
void finalize_sort(long A[3][3], long P[3][3], long Q[3][3]) {
  if (A[0][0] > A[1][1]) {
    swap_diag_elems(A, P, Q, 0, 1);
  }
  if (A[1][1] > A[2][2]) {
    swap_diag_elems(A, P, Q, 1, 2);
  }
  if (A[0][0] > A[1][1]) {
    swap_diag_elems(A, P, Q, 0, 1);
  }
}


x86 assembly (clang, -O0):
<finalize_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    0x20(%rcx),%rax
jle    1152 <finalize_sort+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
call   1030 <swap_diag_elems@plt>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    0x40(%rcx),%rax
jle    1184 <finalize_sort+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x1,%ecx
mov    $0x2,%r8d
call   1030 <swap_diag_elems@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    0x20(%rcx),%rax
jle    11b2 <finalize_sort+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
call   1030 <swap_diag_elems@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finalize_sort>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x20(%rdi),%rax
cmp    %rax,(%rdi)
jg     114d <finalize_sort+0x3d>
cmp    0x40(%rbx),%rax
jg     116d <finalize_sort+0x5d>
cmp    %rax,(%rbx)
jle    118f <finalize_sort+0x7f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <swap_diag_elems@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
call   1030 <swap_diag_elems@plt>
mov    0x20(%rbx),%rax
cmp    0x40(%rbx),%rax
jle    112d <finalize_sort+0x1d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
mov    $0x2,%r8d
call   1030 <swap_diag_elems@plt>
mov    0x20(%rbx),%rax
cmp    %rax,(%rbx)
jg     1132 <finalize_sort+0x22>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @finalize_sort([3 x i64]* %0, [3 x i64]* %1, [3 x i64]* %2) {
%4 = alloca [3 x i64]*
%5 = alloca [3 x i64]*
%6 = alloca [3 x i64]*
store [3 x i64]* %0, [3 x i64]** %4
store [3 x i64]* %1, [3 x i64]** %5
store [3 x i64]* %2, [3 x i64]** %6
%7 = load [3 x i64]*, [3 x i64]** %4
%8 = getelementptr inbounds [3 x i64], [3 x i64]* %7, i64 0
%9 = getelementptr inbounds [3 x i64], [3 x i64]* %8, i64 0, i64 0
%10 = load i64, i64* %9
%11 = load [3 x i64]*, [3 x i64]** %4
%12 = getelementptr inbounds [3 x i64], [3 x i64]* %11, i64 1
%13 = getelementptr inbounds [3 x i64], [3 x i64]* %12, i64 0, i64 1
%14 = load i64, i64* %13
%15 = icmp sgt i64 %10, %14
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = load [3 x i64]*, [3 x i64]** %4
%18 = bitcast [3 x i64]* %17 to i64**
%19 = load [3 x i64]*, [3 x i64]** %5
%20 = bitcast [3 x i64]* %19 to i64**
%21 = load [3 x i64]*, [3 x i64]** %6
%22 = bitcast [3 x i64]* %21 to i64**
%23 = call i32 @swap_diag_elems(i64** %18, i64** %20, i64** %22, i32 0, i32 1)
br label %24
24: ; preds = %16, %3
%25 = load [3 x i64]*, [3 x i64]** %4
%26 = getelementptr inbounds [3 x i64], [3 x i64]* %25, i64 1
%27 = getelementptr inbounds [3 x i64], [3 x i64]* %26, i64 0, i64 1
%28 = load i64, i64* %27
%29 = load [3 x i64]*, [3 x i64]** %4
%30 = getelementptr inbounds [3 x i64], [3 x i64]* %29, i64 2
%31 = getelementptr inbounds [3 x i64], [3 x i64]* %30, i64 0, i64 2
%32 = load i64, i64* %31
%33 = icmp sgt i64 %28, %32
br i1 %33, label %34, label %42
34: ; preds = %24
%35 = load [3 x i64]*, [3 x i64]** %4
%36 = bitcast [3 x i64]* %35 to i64**
%37 = load [3 x i64]*, [3 x i64]** %5
%38 = bitcast [3 x i64]* %37 to i64**
%39 = load [3 x i64]*, [3 x i64]** %6
%40 = bitcast [3 x i64]* %39 to i64**
%41 = call i32 @swap_diag_elems(i64** %36, i64** %38, i64** %40, i32 1, i32 2)
br label %42
42: ; preds = %34, %24
%43 = load [3 x i64]*, [3 x i64]** %4
%44 = getelementptr inbounds [3 x i64], [3 x i64]* %43, i64 0
%45 = getelementptr inbounds [3 x i64], [3 x i64]* %44, i64 0, i64 0
%46 = load i64, i64* %45
%47 = load [3 x i64]*, [3 x i64]** %4
%48 = getelementptr inbounds [3 x i64], [3 x i64]* %47, i64 1
%49 = getelementptr inbounds [3 x i64], [3 x i64]* %48, i64 0, i64 1
%50 = load i64, i64* %49
%51 = icmp sgt i64 %46, %50
br i1 %51, label %52, label %60
52: ; preds = %42
%53 = load [3 x i64]*, [3 x i64]** %4
%54 = bitcast [3 x i64]* %53 to i64**
%55 = load [3 x i64]*, [3 x i64]** %5
%56 = bitcast [3 x i64]* %55 to i64**
%57 = load [3 x i64]*, [3 x i64]** %6
%58 = bitcast [3 x i64]* %57 to i64**
%59 = call i32 @swap_diag_elems(i64** %54, i64** %56, i64** %58, i32 0, i32 1)
br label %60
60: ; preds = %52, %42
ret void
}

LLVM IR (-O2):
define void @finalize_sort([3 x i64]* %0, [3 x i64]* %1, [3 x i64]* %2) {
%4 = getelementptr inbounds [3 x i64], [3 x i64]* %0, i64 0, i64 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds [3 x i64], [3 x i64]* %0, i64 1, i64 1
%7 = load i64, i64* %6
%8 = icmp sgt i64 %5, %7
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = bitcast [3 x i64]* %0 to i64**
%11 = bitcast [3 x i64]* %1 to i64**
%12 = bitcast [3 x i64]* %2 to i64**
%13 = tail call i32 @swap_diag_elems(i64** %10, i64** %11, i64** %12, i32 0, i32 1)
%14 = load i64, i64* %6
br label %15
15: ; preds = %9, %3
%16 = phi i64 [ %14, %9 ], [ %7, %3 ]
%17 = getelementptr inbounds [3 x i64], [3 x i64]* %0, i64 2, i64 2
%18 = load i64, i64* %17
%19 = icmp sgt i64 %16, %18
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = bitcast [3 x i64]* %0 to i64**
%22 = bitcast [3 x i64]* %1 to i64**
%23 = bitcast [3 x i64]* %2 to i64**
%24 = tail call i32 @swap_diag_elems(i64** %21, i64** %22, i64** %23, i32 1, i32 2)
%25 = load i64, i64* %6
br label %26
26: ; preds = %20, %15
%27 = phi i64 [ %25, %20 ], [ %16, %15 ]
%28 = load i64, i64* %4
%29 = icmp sgt i64 %28, %27
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = bitcast [3 x i64]* %0 to i64**
%32 = bitcast [3 x i64]* %1 to i64**
%33 = bitcast [3 x i64]* %2 to i64**
%34 = tail call i32 @swap_diag_elems(i64** %31, i64** %32, i64** %33, i32 0, i32 1)
br label %35
35: ; preds = %30, %26
ret void
}