#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*/ change(int *, int *);
void bubble_sort(int *p, int n) {
  int i;
  int j;
  for (i = 0; i < n - 1; ++i) {
    for (j = 0; j < n - i - 1; j++) {
      if (*(p + j) > *(p + j + 1))
        change(p + j, p + j + 1);
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
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    11bc <bubble_sort+0xac>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a9 <bubble_sort+0x99>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    0x4(%rcx,%rdx,4),%eax
jle    1196 <bubble_sort+0x86>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
add    $0x4,%rsi
call   1030 <change@plt>
jmp    119b <bubble_sort+0x8b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <bubble_sort+0x2e>
jmp    11ae <bubble_sort+0x9e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <bubble_sort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
cmp    $0x2,%esi
jl     118f <bubble_sort+0x7f>
mov    %esi,%r15d
lea    -0x1(%r15),%r12d
addq   $0x4,(%rsp)
xor    %r13d,%r13d
mov    %r12d,%r14d
jmp    114d <bubble_sort+0x3d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
add    $0xffffffff,%r14d
cmp    %r12d,%r13d
je     118f <bubble_sort+0x7f>
mov    %r14d,%r14d
mov    %r13d,%eax
not    %eax
add    %r15d,%eax
test   %eax,%eax
jle    1140 <bubble_sort+0x30>
mov    %r14,%rbp
mov    (%rsp),%rbx
jmp    117a <bubble_sort+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1140 <bubble_sort+0x30>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1170 <bubble_sort+0x60>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1030 <change@plt>
jmp    1170 <bubble_sort+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bubble_sort(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
%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 %52
12: ; preds = %7
store i32 0, i32* %6
br label %13
13: ; preds = %45, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = sub nsw i32 %15, %16
%18 = sub nsw i32 %17, 1
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %48
20: ; preds = %13
%21 = load i32*, i32** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32*, i32** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* %30
%32 = icmp sgt i32 %25, %31
br i1 %32, label %33, label %44
33: ; preds = %20
%34 = load i32*, i32** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32*, i32** %3
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = getelementptr inbounds i32, i32* %41, i64 1
%43 = call i32 @change(i32* %37, i32* %42)
br label %44
44: ; preds = %33, %20
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %13
48: ; preds = %13
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %7
52: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @bubble_sort(i32* %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %29
5: ; preds = %2, %25
%6 = phi i32 [ %27, %25 ], [ %3, %2 ]
%7 = phi i32 [ %26, %25 ], [ 0, %2 ]
%8 = xor i32 %7, -1
%9 = add i32 %8, %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %5
%12 = zext i32 %6 to i64
br label %13
13: ; preds = %11, %22
%14 = phi i64 [ 0, %11 ], [ %23, %22 ]
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = getelementptr inbounds i32, i32* %15, i64 1
%18 = load i32, i32* %17
%19 = icmp sgt i32 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = tail call i32 @change(i32* %15, i32* %17)
br label %22
22: ; preds = %13, %20
%23 = add nuw nsw i64 %14, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %25, label %13
25: ; preds = %22, %5
%26 = add nuw nsw i32 %7, 1
%27 = add i32 %6, -1
%28 = icmp eq i32 %26, %3
br i1 %28, label %29, label %5
29: ; preds = %25, %2
ret void
}