#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_values(unsigned long *, unsigned long *);
void bubble_sort(long unsigned *vector, int useless, int lenght) {
  register int i, j;
  for (i = 1; i < lenght; i++)
    for (j = lenght - 1; j >= i; j--)
      if (vector[j - 1] > vector[j])
        swap_values(&vector[j - 1], &vector[j]);
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ba <bubble_sort+0xaa>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11a7 <bubble_sort+0x97>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jbe    1194 <bubble_sort+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <swap_values@plt>
jmp    1199 <bubble_sort+0x89>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <bubble_sort+0x2e>
jmp    11ac <bubble_sort+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <bubble_sort+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%edx
jl     1183 <bubble_sort+0x73>
mov    %edx,%r14d
lea    (%rdi,%r14,8),%r15
add    $0xfffffffffffffff8,%r15
mov    $0x1,%r12d
jmp    1149 <bubble_sort+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r14,%r12
je     1183 <bubble_sort+0x73>
mov    %r15,%rsi
mov    %r14,%r13
jmp    1168 <bubble_sort+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rsi
cmp    %r12,%r13
jle    1140 <bubble_sort+0x30>
add    $0xffffffffffffffff,%r13
lea    -0x8(%rsi),%rbx
mov    -0x8(%rsi),%rax
cmp    (%rsi),%rax
jbe    1160 <bubble_sort+0x50>
mov    %rbx,%rdi
call   1030 <swap_values@plt>
jmp    1160 <bubble_sort+0x50>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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