#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*/ printf(char *, ...);
int bubblesort(int data[]) {
  int i, j, tmp;
  for (i = 1; i <= 9 - 1; i++) {
    printf("---\n%d-th pass\n", i);
    for (j = 0; j < 9 - i; j++) {
      printf("[%d %d] => ", data[j], data[j + 1]);
      if (data[j] > data[j + 1]) {
        tmp = data[j];
        data[j] = data[j + 1];
        data[j + 1] = tmp;
        printf("[%d %d]\n", data[j], data[j + 1]);
      } else {
        printf("OK\n");
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<bubblesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jg     1240 <bubblesort+0x130>
mov    -0xc(%rbp),%esi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x9,%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    122d <bubblesort+0x11d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    120c <bubblesort+0xfc>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <bubblesort+0x10a>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121f <bubblesort+0x10f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1145 <bubblesort+0x35>
jmp    1232 <bubblesort+0x122>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <bubblesort+0x13>
xor    %eax,%eax
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    %rdi,%rbx
mov    $0x1,%esi
mov    $0x8,%r14d
lea    0xed0(%rip),%rbp
lea    0xede(%rip),%r13
jmp    1160 <bubblesort+0x40>
nopl   0x0(%rax)
mov    0x4(%rsp),%esi
add    $0x1,%esi
add    $0xffffffffffffffff,%r14
cmp    $0x9,%esi
je     11cd <bubblesort+0xad>
lea    0xe99(%rip),%rdi
mov    %esi,0x4(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
xor    %r15d,%r15d
jmp    1190 <bubblesort+0x70>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r12,%r15
cmp    %r12,%r14
je     1150 <bubblesort+0x30>
lea    0x1(%r15),%r12
mov    (%rbx,%r15,4),%esi
mov    0x4(%rbx,%r15,4),%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx,%r15,4),%edx
mov    0x4(%rbx,%r15,4),%esi
cmp    %esi,%edx
jle    1180 <bubblesort+0x60>
mov    %esi,(%rbx,%r15,4)
mov    %edx,0x4(%rbx,%r15,4)
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1188 <bubblesort+0x68>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"---\0A%d-th pass\0A\00"
@.str.1 = [12 x i8] c"[%d %d] => \00"
@.str.2 = [9 x i8] c"[%d %d]\0A\00"
@.str.3 = [4 x i8] c"OK\0A\00"
define i32 @bubblesort(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %3
br label %6
6: ; preds = %83, %1
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 8
br i1 %8, label %9, label %86
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 0, i32* %4
br label %12
12: ; preds = %79, %9
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = sub nsw i32 9, %14
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %82
17: ; preds = %12
%18 = load i32*, i32** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = load i32*, i32** %2
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %23, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %28)
%30 = load i32*, i32** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = load i32*, i32** %2
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %35, i64 %38
%40 = load i32, i32* %39
%41 = icmp sgt i32 %34, %40
br i1 %41, label %42, label %76
42: ; preds = %17
%43 = load i32*, i32** %2
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
store i32 %47, i32* %5
%48 = load i32*, i32** %2
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %48, i64 %51
%53 = load i32, i32* %52
%54 = load i32*, i32** %2
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
%58 = load i32, i32* %5
%59 = load i32*, i32** %2
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %59, i64 %62
store i32 %58, i32* %63
%64 = load i32*, i32** %2
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = load i32*, i32** %2
%70 = load i32, i32* %4
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %69, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %68, i32 %74)
br label %78
76: ; preds = %17
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %78
78: ; preds = %76, %42
br label %79
79: ; preds = %78
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
store i32 %81, i32* %4
br label %12
82: ; preds = %12
br label %83
83: ; preds = %82
%84 = load i32, i32* %3
%85 = add nsw i32 %84, 1
store i32 %85, i32* %3
br label %6
86: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"---\0A%d-th pass\0A\00"
@.str.1 = [12 x i8] c"[%d %d] => \00"
@.str.2 = [9 x i8] c"[%d %d]\0A\00"
@str = [3 x i8] c"OK\00"
define i32 @bubblesort(i32* nocapture %0) {
br label %2
2: ; preds = %23, %1
%3 = phi i64 [ 8, %1 ], [ %25, %23 ]
%4 = phi i32 [ 1, %1 ], [ %24, %23 ]
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %2, %21
%7 = phi i64 [ 0, %2 ], [ %10, %21 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = add nuw nsw i64 %7, 1
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %12)
%14 = load i32, i32* %8
%15 = load i32, i32* %11
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %6
store i32 %15, i32* %8
store i32 %14, i32* %11
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %14)
br label %21
19: ; preds = %6
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %17, %19
%22 = icmp eq i64 %10, %3
br i1 %22, label %23, label %6
23: ; preds = %21
%24 = add nuw nsw i32 %4, 1
%25 = add nsw i64 %3, -1
%26 = icmp eq i32 %24, 9
br i1 %26, label %27, label %2
27: ; preds = %23
ret i32 0
}