#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*/ printarray(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ swap(int *, int *);
void bubbleSort(int array[], int size) {
  int swapped = 0;
  do {
    swapped = 0;
    int i;
    for (i = 1; i <= size - 1; i++) {
      printarray(array, size);
      if (array[i - 1] > array[i]) {
        swap(&array[i - 1], &array[i]);
        swapped = 1;
      }
      printarray(array, size);
    }
    printf("one round compare is end\n");
  } while (swapped);
}


x86 assembly (clang, -O0):
<bubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11da <bubbleSort+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printarray@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11c0 <bubbleSort+0x90>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printarray@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <bubbleSort+0x24>
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1146 <bubbleSort+0x16>
add    $0x20,%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,%ebp
mov    %rdi,%r14
mov    %esi,%r15d
lea    0x4(%rdi),%rax
mov    %rax,(%rsp)
add    $0xffffffffffffffff,%r15
jmp    1171 <bubbleSort+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
test   %r13d,%r13d
je     11c9 <bubbleSort+0x99>
cmp    $0x2,%ebp
jl     11d8 <bubbleSort+0xa8>
xor    %r13d,%r13d
mov    %r15,%r12
mov    (%rsp),%rbx
jmp    11a4 <bubbleSort+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printarray@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%r12
je     1160 <bubbleSort+0x30>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printarray@plt>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1190 <bubbleSort+0x60>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1050 <swap@plt>
mov    $0x1,%r13d
jmp    1190 <bubbleSort+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe21(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"one round compare is end\0A\00"
define void @bubbleSort(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 0, i32* %5
br label %7
7: ; preds = %49, %2
store i32 0, i32* %5
store i32 1, i32* %6
br label %8
8: ; preds = %44, %7
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = icmp sle i32 %9, %11
br i1 %12, label %13, label %47
13: ; preds = %8
%14 = load i32*, i32** %3
%15 = load i32, i32* %4
%16 = call i32 @printarray(i32* %14, i32 %15)
%17 = load i32*, i32** %3
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %22, %27
br i1 %28, label %29, label %40
29: ; preds = %13
%30 = load i32*, i32** %3
%31 = load i32, i32* %6
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = load i32*, i32** %3
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @swap(i32* %34, i32* %38)
store i32 1, i32* %5
br label %40
40: ; preds = %29, %13
%41 = load i32*, i32** %3
%42 = load i32, i32* %4
%43 = call i32 @printarray(i32* %41, i32 %42)
br label %44
44: ; preds = %40
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %8
47: ; preds = %8
%48 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %49
49: ; preds = %47
%50 = load i32, i32* %5
%51 = icmp ne i32 %50, 0
br i1 %51, label %7, label %52
52: ; preds = %49
ret void
}

LLVM IR (-O2):
@str = [25 x i8] c"one round compare is end\00"
define void @bubbleSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
%4 = zext i32 %1 to i64
br label %5
5: ; preds = %25, %2
br i1 %3, label %8, label %6
6: ; preds = %5
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %28
8: ; preds = %5, %20
%9 = phi i64 [ %23, %20 ], [ 1, %5 ]
%10 = phi i32 [ %21, %20 ], [ 0, %5 ]
%11 = tail call i32 @printarray(i32* %0, i32 %1)
%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 %20
18: ; preds = %8
%19 = tail call i32 @swap(i32* %13, i32* %15)
br label %20
20: ; preds = %18, %8
%21 = phi i32 [ 1, %18 ], [ %10, %8 ]
%22 = tail call i32 @printarray(i32* %0, i32 %1)
%23 = add nuw nsw i64 %9, 1
%24 = icmp eq i64 %23, %4
br i1 %24, label %25, label %8
25: ; preds = %20
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%27 = icmp eq i32 %21, 0
br i1 %27, label %28, label %5
28: ; preds = %25, %6
ret void
}