#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 */
scalar_t__ is_sorted(int *, size_t);
int /*<<< orphan*/ swap(int *, int /*<<< orphan*/, size_t);
void slow_sort(int arr[], size_t arr_len) {
  if (arr_len == 0)
    return;
  size_t i;
  for (i = 0; i < arr_len; i++) {
    swap(arr, 0, i);
    slow_sort(arr + 1, arr_len - 1);
    if (is_sorted(arr, arr_len))
      return;
    swap(arr, 0, i);
  }
}


x86 assembly (clang, -O0):
<slow_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <slow_sort+0x20>
jmp    11c6 <slow_sort+0x96>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c6 <slow_sort+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
call   1040 <slow_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <is_sorted@plt>
cmp    $0x0,%rax
je     11a6 <slow_sort+0x76>
jmp    11c6 <slow_sort+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1050 <swap@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1158 <slow_sort+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slow_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     118e <slow_sort+0x5e>
mov    %rsi,%r14
mov    %rdi,%r13
lea    0x4(%rdi),%r15
lea    -0x1(%rsi),%r12
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <swap@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <slow_sort@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1030 <is_sorted@plt>
test   %rax,%rax
jne    118e <slow_sort+0x5e>
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <swap@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <slow_sort+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @slow_sort(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %34
9: ; preds = %2
store i64 0, i64* %5
br label %10
10: ; preds = %31, %9
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = load i64, i64* %5
%17 = call i32 @swap(i32* %15, i32 0, i64 %16)
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i64, i64* %4
%21 = sub i64 %20, 1
%22 = load i32*, i32** %3
%23 = load i64, i64* %4
%24 = call i64 @is_sorted(i32* %22, i64 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %14
br label %34
27: ; preds = %14
%28 = load i32*, i32** %3
%29 = load i64, i64* %5
%30 = call i32 @swap(i32* %28, i32 0, i64 %29)
br label %31
31: ; preds = %27
%32 = load i64, i64* %5
%33 = add i64 %32, 1
store i64 %33, i64* %5
br label %10
34: ; preds = %8, %26, %10
ret void
}

LLVM IR (-O2):
define void @slow_sort(i32* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = add i64 %1, -1
br label %7
7: ; preds = %4, %12
%8 = phi i64 [ 0, %4 ], [ %14, %12 ]
%9 = tail call i32 @swap(i32* %0, i32 0, i64 %8)
tail call void @slow_sort(i32* %5, i64 %6)
%10 = tail call i64 @is_sorted(i32* %0, i64 %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = tail call i32 @swap(i32* %0, i32 0, i64 %8)
%14 = add nuw i64 %8, 1
%15 = icmp eq i64 %14, %1
br i1 %15, label %16, label %7
16: ; preds = %12, %7, %2
ret void
}