#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 */
struct document {
  int dummy;
};

/* Variables and functions */
scalar_t__ hv_get_cos(struct document *);
void bubble_sort(struct document **docs, int size) {
  int i, j;
  struct document *temp = ((void *)0);
  for (i = size - 1; i >= 1; i--) {
    for (j = 0; j < i; j++) {
      if (hv_get_cos(docs[j]) < hv_get_cos(docs[j + 1])) {
        temp = docs[j];
        docs[j] = docs[j + 1];
        docs[j + 1] = temp;
      }
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     11f0 <bubble_sort+0xe0>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11dd <bubble_sort+0xcd>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <hv_get_cos@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <hv_get_cos@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    11ca <bubble_sort+0xba>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11cf <bubble_sort+0xbf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <bubble_sort+0x31>
jmp    11e2 <bubble_sort+0xd2>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <bubble_sort+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     118a <bubble_sort+0x7a>
mov    %rdi,%r15
lea    -0x1(%rsi),%r12d
jmp    113e <bubble_sort+0x2e>
nopl   0x0(%rax)
add    $0xffffffffffffffff,%r12
cmp    $0x3,%r13d
mov    (%rsp),%rsi
jl     118a <bubble_sort+0x7a>
mov    %esi,%r13d
lea    -0x1(%r13),%eax
mov    %rax,(%rsp)
xor    %ebp,%ebp
jmp    1158 <bubble_sort+0x48>
nopl   (%rax)
mov    %r14,%rbp
cmp    %r14,%r12
je     1130 <bubble_sort+0x20>
mov    (%r15,%rbp,8),%rdi
call   1030 <hv_get_cos@plt>
mov    %rax,%rbx
lea    0x1(%rbp),%r14
mov    0x8(%r15,%rbp,8),%rdi
call   1030 <hv_get_cos@plt>
cmp    %rax,%rbx
jge    1150 <bubble_sort+0x40>
movdqu (%r15,%rbp,8),%xmm0
pshufd $0x4e,%xmm0,%xmm0
movdqu %xmm0,(%r15,%rbp,8)
jmp    1150 <bubble_sort+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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