#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 */
long getSystemTime();
int /*<<< orphan*/ printf(char *, int, long);
int /*<<< orphan*/ swap(int *, int *);
void bubbleSort(int *arr, int size) {
  long start = getSystemTime();
  for (int i = 0; i < size; ++i) {
    for (int j = 0; j < size - i - 1; ++j) {
      if (arr[j] > arr[j + 1]) {
        swap(&arr[j], &arr[j + 1]);
      }
    }
  }
  printf("bubbleSort count %d use time: %ld \n", size,
         (getSystemTime() - start));
}


x86 assembly (clang, -O0):
<bubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getSystemTime@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <bubbleSort+0xb6>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d3 <bubbleSort+0xa3>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11c0 <bubbleSort+0x90>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
jmp    11c5 <bubbleSort+0x95>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1164 <bubbleSort+0x34>
jmp    11d8 <bubbleSort+0xa8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <bubbleSort+0x21>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getSystemTime@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
sub    -0x18(%rbp),%rdx
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubbleSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r15
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <getSystemTime@plt>
mov    %rax,(%rsp)
test   %r12d,%r12d
jle    11af <bubbleSort+0x7f>
add    $0x4,%r15
lea    -0x1(%r12),%r14d
jmp    116d <bubbleSort+0x3d>
nop
add    $0x1,%r13d
add    $0xffffffff,%r14d
cmp    %r12d,%r13d
je     11af <bubbleSort+0x7f>
mov    %r14d,%r14d
mov    %r13d,%eax
not    %eax
add    %r12d,%eax
mov    %r14,%rbp
mov    %r15,%rbx
test   %eax,%eax
jg     119a <bubbleSort+0x6a>
jmp    1160 <bubbleSort+0x30>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1160 <bubbleSort+0x30>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1190 <bubbleSort+0x60>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1050 <swap@plt>
jmp    1190 <bubbleSort+0x60>
xor    %eax,%eax
call   1040 <getSystemTime@plt>
sub    (%rsp),%rax
lea    0xe3f(%rip),%rdi
mov    %r12d,%esi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"bubbleSort count %d use time: %ld \0A\00"
define void @bubbleSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = call i64 (...) @getSystemTime()
store i64 %8, i64* %5
store i32 0, i32* %6
br label %9
9: ; preds = %50, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %53
13: ; preds = %9
store i32 0, i32* %7
br label %14
14: ; preds = %46, %13
%15 = load i32, i32* %7
%16 = load i32, i32* %4
%17 = load i32, i32* %6
%18 = sub nsw i32 %16, %17
%19 = sub nsw i32 %18, 1
%20 = icmp slt i32 %15, %19
br i1 %20, label %21, label %49
21: ; preds = %14
%22 = load i32*, i32** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32*, i32** %3
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
%32 = load i32, i32* %31
%33 = icmp sgt i32 %26, %32
br i1 %33, label %34, label %45
34: ; preds = %21
%35 = load i32*, i32** %3
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32*, i32** %3
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %39, i64 %42
%44 = call i32 @swap(i32* %38, i32* %43)
br label %45
45: ; preds = %34, %21
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %14
49: ; preds = %14
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %9
53: ; preds = %9
%54 = load i32, i32* %4
%55 = call i64 (...) @getSystemTime()
%56 = load i64, i64* %5
%57 = sub nsw i64 %55, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %54, i64 %57)
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"bubbleSort count %d use time: %ld \0A\00"
define void @bubbleSort(i32* %0, i32 %1) {
%3 = tail call i64 (...) @getSystemTime()
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %2, %18
%6 = phi i32 [ %8, %18 ], [ %1, %2 ]
%7 = phi i32 [ %19, %18 ], [ 0, %2 ]
%8 = add i32 %6, -1
%9 = xor i32 %7, -1
%10 = add i32 %9, %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %5
%13 = zext i32 %8 to i64
br label %21
14: ; preds = %18, %2
%15 = tail call i64 (...) @getSystemTime()
%16 = sub nsw i64 %15, %3
%17 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %1, i64 %16)
ret void
18: ; preds = %31, %5
%19 = add nuw nsw i32 %7, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %14, label %5
21: ; preds = %12, %31
%22 = phi i64 [ 0, %12 ], [ %25, %31 ]
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = load i32, i32* %23
%25 = add nuw nsw i64 %22, 1
%26 = getelementptr inbounds i32, i32* %0, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %24, %27
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = tail call i32 @swap(i32* %23, i32* %26)
br label %31
31: ; preds = %21, %29
%32 = icmp eq i64 %25, %13
br i1 %32, label %18, label %21
}