#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 */
int /*<<< orphan*/ swap(int *, int *);
void bubble_sort(int array[], size_t array_length) {
  for (int ordered_index = array_length - 1; ordered_index > 0;
       --ordered_index) {
    for (int element = 0; element < ordered_index; ++element) {
      if (array[element] < array[element + 1]) {
        swap(array + element, array + element + 1);
      }
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b6 <bubble_sort+0xa6>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <bubble_sort+0x93>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1190 <bubble_sort+0x80>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
add    $0x4,%rsi
call   1030 <swap@plt>
jmp    1195 <bubble_sort+0x85>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <bubble_sort+0x2c>
jmp    11a8 <bubble_sort+0x98>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <bubble_sort+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
add    $0xffffffff,%esi
test   %esi,%esi
jle    1172 <bubble_sort+0x62>
mov    %rdi,%r14
mov    %esi,%r15d
add    $0x4,%r14
jmp    1139 <bubble_sort+0x29>
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r15
test   %r15d,%r15d
jle    1172 <bubble_sort+0x62>
mov    %r14,%rbx
xor    %r12d,%r12d
jmp    1159 <bubble_sort+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbx
cmp    %r12,%r15
je     1130 <bubble_sort+0x20>
mov    -0x4(%rbx),%eax
add    $0x1,%r12
cmp    (%rbx),%eax
jge    1150 <bubble_sort+0x40>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
jmp    1150 <bubble_sort+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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