#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 A[], int n) {
  int i, j;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (A[i] > A[j]) {
        printarray(A, n);
        printf("%d~%d\t", i, j);
        printf("%d~%d\n", A[i], A[j]);
        swap(&A[i], &A[j]);
        printarray(A, n);
        printf("-----------------------\n");
      }
    }
  }
}


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)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    122f <bubblesort+0xff>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121c <bubblesort+0xec>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1209 <bubblesort+0xd9>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printarray@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printarray@plt>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120e <bubblesort+0xde>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <bubblesort+0x30>
jmp    1221 <bubblesort+0xf1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    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
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
cmp    $0x2,%esi
jl     123f <bubblesort+0xff>
mov    %rdi,%r15
mov    0x10(%rsp),%rax
mov    %eax,%ebx
add    $0xffffffff,%eax
mov    %rax,0x18(%rsp)
lea    0x4(%rdi),%rax
mov    %rax,0x8(%rsp)
mov    $0x1,%eax
mov    %rax,(%rsp)
xor    %r12d,%r12d
jmp    11ab <bubblesort+0x6b>
cs nopw 0x0(%rax,%rax,1)
nop
addq   $0x1,(%rsp)
addq   $0x4,0x8(%rsp)
mov    0x20(%rsp),%r12
cmp    0x18(%rsp),%r12
je     123f <bubblesort+0xff>
lea    0x1(%r12),%rax
mov    %rax,0x20(%rsp)
cmp    %rbx,%rax
jae    1190 <bubblesort+0x50>
lea    (%r15,%r12,4),%r13
mov    0x8(%rsp),%rbp
mov    (%rsp),%r14
jmp    11dd <bubblesort+0x9d>
nopl   0x0(%rax)
add    $0x1,%r14
add    $0x4,%rbp
cmp    %r14,%rbx
je     1190 <bubblesort+0x50>
mov    0x0(%r13),%eax
cmp    0x0(%rbp),%eax
jle    11d0 <bubblesort+0x90>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <printarray@plt>
lea    0xe09(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    0x0(%rbp),%edx
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <swap@plt>
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
call   1050 <printarray@plt>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
jmp    11d0 <bubblesort+0x90>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d~%d\09\00"
@.str.1 = [7 x i8] c"%d~%d\0A\00"
@.str.2 = [25 x i8] c"-----------------------\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 = %67, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %70
12: ; preds = %7
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %6
br label %15
15: ; preds = %63, %12
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %66
19: ; preds = %15
%20 = load i32*, i32** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = icmp sgt i32 %24, %29
br i1 %30, label %31, label %62
31: ; preds = %19
%32 = load i32*, i32** %3
%33 = load i32, i32* %4
%34 = call i32 @printarray(i32* %32, i32 %33)
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32*, i32** %3
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32*, i32** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %47)
%49 = load i32*, i32** %3
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32*, i32** %3
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = call i32 @swap(i32* %52, i32* %56)
%58 = load i32*, i32** %3
%59 = load i32, i32* %4
%60 = call i32 @printarray(i32* %58, i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %31, %19
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %15
66: ; preds = %15
br label %67
67: ; preds = %66
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %7
70: ; preds = %7
ret void
}

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