#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 search_min(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++) {
    int min_index = search_min(arr, i, n);
    exchange(arr, min_index, i);
  }
  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    0xe9f(%rip),%rsi
mov    $0x34,%edx
call   1050 <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    11c0 <main+0x80>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%esi
mov    -0x54(%rbp),%edx
call   1040 <search_min@plt>
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x58(%rbp),%edx
call   1060 <exchange@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1185 <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   %rbx
sub    $0x40,%rsp
mov    0xef5(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xeda(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <ergodic@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x2,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x4,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x5,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x6,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x8,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x9,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0xb,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
mov    $0xd,%edx
call   1040 <search_min@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0xc,%edx
call   1050 <exchange@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <ergodic@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
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 = %27, %2
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = call i32 @search_min(i32* %19, i32 %20, i32 %21)
store i32 %22, i32* %9
%23 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%24 = load i32, i32* %9
%25 = load i32, i32* %8
%26 = call i32 @exchange(i32* %23, i32 %24, i32 %25)
br label %27
27: ; preds = %18
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %14
30: ; preds = %14
%31 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%32 = load i32, i32* %7
%33 = call i32 @ergodic(i32* %31, i32 %32)
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)
%7 = call i32 @search_min(i32* %5, i32 0, i32 13)
%8 = call i32 @exchange(i32* %5, i32 %7, i32 0)
%9 = call i32 @search_min(i32* %5, i32 1, i32 13)
%10 = call i32 @exchange(i32* %5, i32 %9, i32 1)
%11 = call i32 @search_min(i32* %5, i32 2, i32 13)
%12 = call i32 @exchange(i32* %5, i32 %11, i32 2)
%13 = call i32 @search_min(i32* %5, i32 3, i32 13)
%14 = call i32 @exchange(i32* %5, i32 %13, i32 3)
%15 = call i32 @search_min(i32* %5, i32 4, i32 13)
%16 = call i32 @exchange(i32* %5, i32 %15, i32 4)
%17 = call i32 @search_min(i32* %5, i32 5, i32 13)
%18 = call i32 @exchange(i32* %5, i32 %17, i32 5)
%19 = call i32 @search_min(i32* %5, i32 6, i32 13)
%20 = call i32 @exchange(i32* %5, i32 %19, i32 6)
%21 = call i32 @search_min(i32* %5, i32 7, i32 13)
%22 = call i32 @exchange(i32* %5, i32 %21, i32 7)
%23 = call i32 @search_min(i32* %5, i32 8, i32 13)
%24 = call i32 @exchange(i32* %5, i32 %23, i32 8)
%25 = call i32 @search_min(i32* %5, i32 9, i32 13)
%26 = call i32 @exchange(i32* %5, i32 %25, i32 9)
%27 = call i32 @search_min(i32* %5, i32 10, i32 13)
%28 = call i32 @exchange(i32* %5, i32 %27, i32 10)
%29 = call i32 @search_min(i32* %5, i32 11, i32 13)
%30 = call i32 @exchange(i32* %5, i32 %29, i32 11)
%31 = call i32 @search_min(i32* %5, i32 12, i32 13)
%32 = call i32 @exchange(i32* %5, i32 %31, i32 12)
%33 = call i32 @ergodic(i32* %5, i32 13)
ret i32 0
}