#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 */
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
int /*<<< orphan*/ ergodic(int *, int);
int /*<<< orphan*/ exchange(int *, int, int);
int main(int argc, char **argv) {
  int arr[] = {3, 2, 1, 2, 5, 5, 6, 4, 3, 2, 3, 4, 5};
  int n = sizeof(arr) / sizeof(int);
  ergodic(arr, n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (arr[i] < arr[j]) {
        exchange(arr, i, j);
      }
    }
  }
  ergodic(arr, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
movl   $0xd,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1030 <ergodic@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    11df <main+0xaf>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    11cc <main+0x9c>
movslq -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
movslq -0x5c(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jge    11b9 <main+0x89>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    -0x5c(%rbp),%edx
call   1050 <exchange@plt>
jmp    11be <main+0x8e>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1188 <main+0x58>
jmp    11d1 <main+0xa1>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1175 <main+0x45>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1030 <ergodic@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    0xf01(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xee6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeae(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xd,%esi
call   1030 <ergodic@plt>
xor    %r15d,%r15d
jmp    117a <main+0x5a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    $0xd,%r15
je     11b1 <main+0x91>
test   %r15,%r15
je     1170 <main+0x50>
xor    %ebx,%ebx
jmp    1199 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1170 <main+0x50>
mov    (%rsp,%r15,4),%eax
cmp    (%rsp,%rbx,4),%eax
jge    1190 <main+0x70>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1040 <exchange@plt>
jmp    1190 <main+0x70>
mov    %rsp,%rdi
mov    $0xd,%esi
call   1030 <ergodic@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.arr = [13 x i32] [i32 3, i32 2, i32 1, i32 2, i32 5, i32 5, i32 6, i32 4, i32 3, i32 2, i32 3, i32 4, i32 5]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [13 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [13 x i32]* %6 to i8*
store i32 13, i32* %7
%11 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%12 = load i32, i32* %7
%13 = call i32 @ergodic(i32* %11, i32 %12)
store i32 0, i32* %8
br label %14
14: ; preds = %43, %2
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %46
18: ; preds = %14
store i32 0, i32* %9
br label %19
19: ; preds = %39, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %19
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp slt i32 %27, %31
br i1 %32, label %33, label %38
33: ; preds = %23
%34 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = call i32 @exchange(i32* %34, i32 %35, i32 %36)
br label %38
38: ; preds = %33, %23
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %19
42: ; preds = %19
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %14
46: ; preds = %14
%47 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%48 = load i32, i32* %7
%49 = call i32 @ergodic(i32* %47, i32 %48)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [13 x i32] [i32 3, i32 2, i32 1, i32 2, i32 5, i32 5, i32 6, i32 4, i32 3, i32 2, i32 3, i32 4, i32 5]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [13 x i32]
%4 = bitcast [13 x i32]* %3 to i8*
%5 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 0
%6 = call i32 @ergodic(i32* %5, i32 13)
br label %7
7: ; preds = %2, %15
%8 = phi i64 [ 0, %2 ], [ %16, %15 ]
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %8
%12 = trunc i64 %8 to i32
br label %18
13: ; preds = %15
%14 = call i32 @ergodic(i32* %5, i32 13)
ret i32 0
15: ; preds = %27, %7
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, 13
br i1 %17, label %13, label %7
18: ; preds = %10, %27
%19 = phi i64 [ 0, %10 ], [ %28, %27 ]
%20 = load i32, i32* %11
%21 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %19
%22 = load i32, i32* %21
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = trunc i64 %19 to i32
%26 = call i32 @exchange(i32* %5, i32 %12, i32 %25)
br label %27
27: ; preds = %18, %24
%28 = add nuw nsw i64 %19, 1
%29 = icmp eq i64 %28, %8
br i1 %29, label %15, label %18
}