#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, int);
void bubble_sort(int *array, int size) {
  int i;
  int swapped = 1;
  while (swapped) {
    swapped = 0;
    for (i = 1; i < size; i++) {
      if (array[i - 1] > array[i]) {
        swap(array, i - 1, i);
        swapped = 1;
      }
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119c <bubble_sort+0x8c>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1197 <bubble_sort+0x87>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1184 <bubble_sort+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <swap@plt>
movl   $0x1,-0x14(%rbp)
jmp    1189 <bubble_sort+0x79>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113e <bubble_sort+0x2e>
jmp    1126 <bubble_sort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     1168 <bubble_sort+0x58>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%r15d
xor    %eax,%eax
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    -0x4(%rbx,%rbp,4),%ecx
cmp    (%rbx,%rbp,4),%ecx
jle    114b <bubble_sort+0x3b>
lea    -0x1(%rbp),%esi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <swap@plt>
mov    $0x1,%eax
add    $0x1,%rbp
cmp    %r15,%rbp
jne    1130 <bubble_sort+0x20>
cmp    $0x2,%r14d
jl     1168 <bubble_sort+0x58>
mov    $0x1,%ebp
test   %eax,%eax
mov    $0x0,%eax
jne    1130 <bubble_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @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
store i32 1, i32* %6
br label %7
7: ; preds = %38, %2
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %39
10: ; preds = %7
store i32 0, i32* %6
store i32 1, i32* %5
br label %11
11: ; preds = %35, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %16, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp sgt i32 %21, %26
br i1 %27, label %28, label %34
28: ; preds = %15
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 1
%32 = load i32, i32* %5
%33 = call i32 @swap(i32* %29, i32 %31, i32 %32)
store i32 1, i32* %6
br label %34
34: ; preds = %28, %15
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %11
38: ; preds = %11
br label %7
39: ; preds = %7
ret void
}

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