#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*/ bubbleSort(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
void fig07_15() {
  int a[10] = {2, 6, 4, 8, 10, 12, 89, 68, 45, 37};
  size_t i;
  puts("Data items in original order");
  for (i = 0; i < 10; ++i) {
    printf("%4d", a[i]);
  }
  bubbleSort(a, 10);
  puts("\nData items in ascending order");
  for (i = 0; i < 10; ++i) {
    printf("%4d", a[i]);
  }
  puts("");
}


x86 assembly (clang, -O0):
<fig07_15>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0xa,-0x38(%rbp)
jae    11a1 <fig07_15+0x61>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1171 <fig07_15+0x31>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1050 <bubbleSort@plt>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0xa,-0x38(%rbp)
jae    11f3 <fig07_15+0xb3>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11c3 <fig07_15+0x83>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig07_15>:
push   %rbx
sub    $0x30,%rsp
mov    0xed4(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xeca(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x59,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x44,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1060 <bubbleSort@plt>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.fig07_15.a = [10 x i32] [i32 2, i32 6, i32 4, i32 8, i32 10, i32 12, i32 89, i32 68, i32 45, i32 37]
@.str = [29 x i8] c"Data items in original order\00"
@.str.1 = [4 x i8] c"%4d\00"
@.str.2 = [31 x i8] c"\0AData items in ascending order\00"
@.str.3 = [1 x i8] zeroinitializer
define void @fig07_15() {
%1 = alloca [10 x i32]
%2 = alloca i64
%3 = bitcast [10 x i32]* %1 to i8*
%4 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %2
br label %5
5: ; preds = %13, %0
%6 = load i64, i64* %2
%7 = icmp ult i64 %6, 10
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i64, i64* %2
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %8
%14 = load i64, i64* %2
%15 = add i64 %14, 1
store i64 %15, i64* %2
br label %5
16: ; preds = %5
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%18 = call i32 @bubbleSort(i32* %17, i32 10)
%19 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %2
br label %20
20: ; preds = %28, %16
%21 = load i64, i64* %2
%22 = icmp ult i64 %21, 10
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i64, i64* %2
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %23
%29 = load i64, i64* %2
%30 = add i64 %29, 1
store i64 %30, i64* %2
br label %20
31: ; preds = %20
%32 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.fig07_15.a = [10 x i32] [i32 2, i32 6, i32 4, i32 8, i32 10, i32 12, i32 89, i32 68, i32 45, i32 37]
@.str = [29 x i8] c"Data items in original order\00"
@.str.1 = [4 x i8] c"%4d\00"
@.str.2 = [31 x i8] c"\0AData items in ascending order\00"
define void @fig07_15() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 6)
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 8)
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 10)
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 12)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 89)
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 68)
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 45)
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 37)
%24 = call i32 @bubbleSort(i32* %4, i32 10)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %8
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %10
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %12
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %14
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %16
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %18
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %20
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %22
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = call i32 @putchar(i32 10)
ret void
}