#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);
int /*<<< orphan*/ swap(int *, int *);
void bubbleSort(int A[], int n) {
  int swapped;
  do {
    swapped = 0;
    int i;
    for (i = 1; i <= n - 1; i++) {
      printarray(A, n);
      if (A[i - 1] > A[i]) {
        swap(&A[i - 1], &A[i]);
        swapped = 1;
      }
      printarray(A, n);
    }
    n = n - 1;
    printf("a round end n=%d\n", 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   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11d3 <bubbleSort+0xa3>
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    11b9 <bubbleSort+0x89>
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    114d <bubbleSort+0x1d>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    113f <bubbleSort+0xf>
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,%r13d
mov    %rdi,%r14
lea    0x4(%rdi),%r12
jmp    1168 <bubbleSort+0x38>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%r13d
lea    0xea5(%rip),%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
test   %r15d,%r15d
je     11bb <bubbleSort+0x8b>
cmp    $0x1,%r13d
jle    11ca <bubbleSort+0x9a>
mov    %r13d,%ebp
add    $0xffffffffffffffff,%rbp
xor    %r15d,%r15d
mov    %r12,%rbx
jmp    1195 <bubbleSort+0x65>
nopl   (%rax)
mov    %r14,%rdi
mov    %r13d,%esi
call   1040 <printarray@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1150 <bubbleSort+0x20>
mov    %r14,%rdi
mov    %r13d,%esi
call   1040 <printarray@plt>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1180 <bubbleSort+0x50>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1050 <swap@plt>
mov    $0x1,%r15d
jmp    1180 <bubbleSort+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%r13d
lea    0xe2b(%rip),%rdi
mov    %r13d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"a round end n=%d\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
br label %7
7: ; preds = %52, %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 = load i32, i32* %4
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %47
%53 = load i32, i32* %5
%54 = icmp ne i32 %53, 0
br i1 %54, label %7, label %55
55: ; preds = %52
ret void
}

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