#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 *nums, int length) {
  int change = 1;
  while (change == 1) {
    change = 0;
    for (int i = 1; i < length; i++) {
      if (nums[i] < nums[i - 1]) {
        swap(&nums[i], &nums[i - 1]);
        change = 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,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11b1 <bubble_sort+0xa1>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ac <bubble_sort+0x9c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1199 <bubble_sort+0x89>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
movl   $0x1,-0x10(%rbp)
jmp    119e <bubble_sort+0x8e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%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     116d <bubble_sort+0x5d>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%r15d
xor    %eax,%eax
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    (%rbx,%rbp,4),%ecx
cmp    -0x4(%rbx,%rbp,4),%ecx
jge    114f <bubble_sort+0x3f>
lea    (%rbx,%rbp,4),%rdi
lea    (%rbx,%rbp,4),%rsi
add    $0xfffffffffffffffc,%rsi
call   1030 <swap@plt>
mov    $0x1,%eax
add    $0x1,%rbp
cmp    %r15,%rbp
jne    1130 <bubble_sort+0x20>
cmp    $0x2,%r14d
jl     116d <bubble_sort+0x5d>
mov    $0x1,%ebp
cmp    $0x1,%eax
mov    $0x0,%eax
je     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* %5
br label %7
7: ; preds = %43, %2
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %44
10: ; preds = %7
store i32 0, i32* %5
store i32 1, i32* %6
br label %11
11: ; preds = %40, %10
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %43
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = load i32*, i32** %3
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %21, i64 %24
%26 = load i32, i32* %25
%27 = icmp slt i32 %20, %26
br i1 %27, label %28, label %39
28: ; preds = %15
%29 = load i32*, i32** %3
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32*, i32** %3
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %33, i64 %36
%38 = call i32 @swap(i32* %32, i32* %37)
store i32 1, i32* %5
br label %39
39: ; preds = %28, %15
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %11
43: ; preds = %11
br label %7
44: ; 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 %26
5: ; preds = %19
%6 = icmp eq i32 %20, 1
%7 = and i1 %3, %6
br i1 %7, label %23, label %26
8: ; preds = %2, %23
%9 = phi i64 [ %24, %23 ], [ 1, %2 ]
%10 = phi i32 [ %25, %23 ], [ 0, %2 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %9
%12 = load i32, i32* %11
%13 = add nsw i64 %9, -1
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = icmp slt i32 %12, %15
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call i32 @swap(i32* %11, i32* %14)
br label %19
19: ; preds = %8, %17
%20 = phi i32 [ 1, %17 ], [ %10, %8 ]
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, %4
br i1 %22, label %5, label %23
23: ; preds = %19, %5
%24 = phi i64 [ %21, %19 ], [ 1, %5 ]
%25 = phi i32 [ %20, %19 ], [ 0, %5 ]
br label %8
26: ; preds = %5, %2
ret void
}