#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 j = 0; j < n - 1; j++) {
    for (int i = 0; i < n - 1 - j; i++) {
      if (arr[i] > arr[i + 1]) {
        exchange(arr, i, i + 1);
      }
    }
  }
  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
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f4 <main+0xc4>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x58(%rbp),%ecx
cmp    %ecx,%eax
jge    11e1 <main+0xb1>
movslq -0x5c(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jle    11ce <main+0x9e>
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x5c(%rbp),%edx
add    $0x1,%edx
call   1050 <exchange@plt>
jmp    11d3 <main+0xa3>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    118d <main+0x5d>
jmp    11e6 <main+0xb6>
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   %r12
push   %rbx
sub    $0x38,%rsp
mov    0xeff(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xd,%esi
call   1030 <ergodic@plt>
xor    %r14d,%r14d
mov    $0xc,%r12d
jmp    118e <main+0x6e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
add    $0xffffffffffffffff,%r12
cmp    $0xc,%r14d
je     11c2 <main+0xa2>
xor    %esi,%esi
jmp    11a8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rsi
cmp    %rbx,%r12
je     1180 <main+0x60>
mov    (%rsp,%rsi,4),%eax
lea    0x1(%rsi),%rbx
cmp    0x4(%rsp,%rsi,4),%eax
jle    11a0 <main+0x80>
lea    0x1(%rsi),%edx
mov    %r15,%rdi
call   1040 <exchange@plt>
jmp    11a0 <main+0x80>
mov    %rsp,%rdi
mov    $0xd,%esi
call   1030 <ergodic@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
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 = %49, %2
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %52
19: ; preds = %14
store i32 0, i32* %9
br label %20
20: ; preds = %45, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = sub nsw i32 %22, 1
%24 = load i32, i32* %8
%25 = sub nsw i32 %23, %24
%26 = icmp slt i32 %21, %25
br i1 %26, label %27, label %48
27: ; preds = %20
%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 = load i32, i32* %9
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = icmp sgt i32 %31, %36
br i1 %37, label %38, label %44
38: ; preds = %27
%39 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%40 = load i32, i32* %9
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
%43 = call i32 @exchange(i32* %39, i32 %40, i32 %42)
br label %44
44: ; preds = %38, %27
br label %45
45: ; preds = %44
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %20
48: ; preds = %20
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %14
52: ; preds = %14
%53 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%54 = load i32, i32* %7
%55 = call i32 @ergodic(i32* %53, i32 %54)
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 = %12, %2
%8 = phi i64 [ 12, %2 ], [ %14, %12 ]
%9 = phi i32 [ 0, %2 ], [ %13, %12 ]
br label %16
10: ; preds = %12
%11 = call i32 @ergodic(i32* %5, i32 13)
ret i32 0
12: ; preds = %28
%13 = add nuw nsw i32 %9, 1
%14 = add nsw i64 %8, -1
%15 = icmp eq i32 %13, 12
br i1 %15, label %10, label %7
16: ; preds = %7, %28
%17 = phi i64 [ 0, %7 ], [ %20, %28 ]
%18 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = add nuw nsw i64 %17, 1
%21 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = icmp sgt i32 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = trunc i64 %20 to i32
%26 = trunc i64 %17 to i32
%27 = call i32 @exchange(i32* %5, i32 %26, i32 %25)
br label %28
28: ; preds = %16, %24
%29 = icmp eq i64 %20, %8
br i1 %29, label %12, label %16
}