void Array_bubble_sort(int *arr, int len) {
  assert(arr);
  assert(len > 0);
  int i = 0, j = 0;
  for (i = 0; i < len; i++)
    for (j = 0; j < len - i - 1; j++)
      if (arr[j] > arr[j + 1])
        swap(&arr[j], &arr[j + 1]);
}


x86 assembly (clang, -O0):
<Array_bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f9 <Array_bubble_sort+0xd9>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e6 <Array_bubble_sort+0xc6>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11d3 <Array_bubble_sort+0xb3>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x0,%al
call   1040 <swap@plt>
jmp    11d8 <Array_bubble_sort+0xb8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <Array_bubble_sort+0x55>
jmp    11eb <Array_bubble_sort+0xcb>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1162 <Array_bubble_sort+0x42>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Array_bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
test   %r15d,%r15d
setg   %dil
xor    %eax,%eax
call   1030 <assert@plt>
test   %r15d,%r15d
jle    11b1 <Array_bubble_sort+0x91>
add    $0x4,%r14
lea    -0x1(%r15),%r12d
xor    %r13d,%r13d
jmp    116d <Array_bubble_sort+0x4d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
add    $0xffffffff,%r12d
cmp    %r15d,%r13d
je     11b1 <Array_bubble_sort+0x91>
mov    %r12d,%r12d
mov    %r13d,%eax
not    %eax
add    %r15d,%eax
test   %eax,%eax
jle    1160 <Array_bubble_sort+0x40>
mov    %r12,%rbp
mov    %r14,%rbx
jmp    119a <Array_bubble_sort+0x7a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1160 <Array_bubble_sort+0x40>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1190 <Array_bubble_sort+0x70>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <swap@plt>
jmp    1190 <Array_bubble_sort+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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