#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*/ printChar(char);
int /*<<< orphan*/ printInt(int);
int /*<<< orphan*/ printStr(char *);
void main() {
  int array[10] = {34, 11, 9, 0, 5, 2, 4, 3, 1, 4};
  int lim = 10, i, k, temp;
  printStr("Bubble Sort Algorithm\n");
  printStr("Before sorting:\n");
  for (i = 0; i < lim; i++) {
    printInt(array[i]);
    printChar(' ');
  }
  printChar('\n');
  for (i = 0; i < lim; i++) {
    for (k = 0; k < lim - i - 1; k++) {
      if (array[k] > array[k + 1]) {
        temp = array[k];
        array[k] = array[k + 1];
        array[k + 1] = temp;
      }
    }
  }
  printStr("After sorting:\n");
  for (i = 0; i < lim; i++) {
    printInt(array[i]);
    printChar(' ');
  }
  printChar('\n');
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0xa,-0x34(%rbp)
lea    0xebd(%rip),%rdi
call   1040 <printStr@plt>
lea    0xec8(%rip),%rdi
call   1040 <printStr@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11b4 <main+0x74>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1060 <printChar@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1183 <main+0x43>
mov    $0xa,%edi
call   1060 <printChar@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    125b <main+0x11b>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    -0x38(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1248 <main+0x108>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jle    1235 <main+0xf5>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,4),%ecx
movslq -0x3c(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x40(%rbp),%ecx
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    123a <main+0xfa>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d8 <main+0x98>
jmp    124d <main+0x10d>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11c5 <main+0x85>
lea    0xdee(%rip),%rdi
call   1040 <printStr@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    129f <main+0x15f>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1060 <printChar@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    126e <main+0x12e>
mov    $0xa,%edi
call   1060 <printChar@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xee2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xec7(%rip),%rdi
call   1040 <printStr@plt>
lea    0xed2(%rip),%rdi
call   1040 <printStr@plt>
mov    $0x22,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0xb,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x9,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
xor    %r14d,%r14d
xor    %edi,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x5,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x2,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x4,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x3,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x1,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0x4,%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0xa,%edi
call   1050 <printChar@plt>
mov    $0x9,%eax
jmp    1262 <main+0x132>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0xffffffffffffffff,%rax
cmp    $0xa,%r14
je     1302 <main+0x1d2>
cmp    $0x2,%rax
mov    $0x1,%esi
cmovae %rax,%rsi
mov    $0x9,%edx
sub    %r14,%rdx
cmp    $0x2,%rdx
mov    $0x1,%r8d
cmovae %rdx,%r8
cmp    $0x8,%r14
ja     1250 <main+0x120>
mov    (%rsp),%ebx
cmp    $0x2,%rdx
jae    12b0 <main+0x180>
xor    %edx,%edx
test   $0x1,%r8b
je     1250 <main+0x120>
mov    0x4(%rsp,%rdx,4),%ecx
cmp    %ecx,%ebx
jle    1250 <main+0x120>
mov    %ecx,(%rsp,%rdx,4)
mov    %ebx,0x4(%rsp,%rdx,4)
jmp    1250 <main+0x120>
nopl   (%rax)
and    $0xfffffffffffffffe,%rsi
xor    %edi,%edi
jmp    12d0 <main+0x1a0>
nopl   0x0(%rax,%rax,1)
mov    %ecx,0x4(%rsp,%rdi,4)
mov    %ebx,0x8(%rsp,%rdi,4)
mov    %rdx,%rdi
cmp    %rdx,%rsi
je     1296 <main+0x166>
mov    0x4(%rsp,%rdi,4),%edx
cmp    %edx,%ebx
jle    12f0 <main+0x1c0>
mov    %edx,(%rsp,%rdi,4)
mov    %ebx,0x4(%rsp,%rdi,4)
jmp    12f2 <main+0x1c2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %edx,%ebx
lea    0x2(%rdi),%rdx
mov    0x8(%rsp,%rdi,4),%ecx
cmp    %ecx,%ebx
jg     12c0 <main+0x190>
mov    %ecx,%ebx
jmp    12c8 <main+0x198>
lea    0xd47(%rip),%rdi
call   1040 <printStr@plt>
mov    (%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x4(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x8(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0xc(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x10(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x14(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x18(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x1c(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x20(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    0x24(%rsp),%edi
call   1030 <printInt@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printChar@plt>

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

LLVM IR (-O2):
@__const.main.array = [10 x i32] [i32 34, i32 11, i32 9, i32 0, i32 5, i32 2, i32 4, i32 3, i32 1, i32 4]
@.str = [23 x i8] c"Bubble Sort Algorithm\0A\00"
@.str.1 = [17 x i8] c"Before sorting:\0A\00"
@.str.2 = [16 x i8] c"After sorting:\0A\00"
define void @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @printStr(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @printStr(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%6 = tail call i32 @printInt(i32 34)
%7 = tail call i32 @printChar(i8 signext 32)
%8 = tail call i32 @printInt(i32 11)
%9 = tail call i32 @printChar(i8 signext 32)
%10 = tail call i32 @printInt(i32 9)
%11 = tail call i32 @printChar(i8 signext 32)
%12 = tail call i32 @printInt(i32 0)
%13 = tail call i32 @printChar(i8 signext 32)
%14 = tail call i32 @printInt(i32 5)
%15 = tail call i32 @printChar(i8 signext 32)
%16 = tail call i32 @printInt(i32 2)
%17 = tail call i32 @printChar(i8 signext 32)
%18 = tail call i32 @printInt(i32 4)
%19 = tail call i32 @printChar(i8 signext 32)
%20 = tail call i32 @printInt(i32 3)
%21 = tail call i32 @printChar(i8 signext 32)
%22 = tail call i32 @printInt(i32 1)
%23 = tail call i32 @printChar(i8 signext 32)
%24 = tail call i32 @printInt(i32 4)
%25 = tail call i32 @printChar(i8 signext 32)
%26 = tail call i32 @printChar(i8 signext 10)
br label %27
27: ; preds = %0, %71
%28 = phi i64 [ 0, %0 ], [ %72, %71 ]
%29 = sub nsw i64 9, %28
%30 = call i64 @llvm.umax.i64(i64 %29, i64 1)
%31 = icmp ult i64 %28, 9
br i1 %31, label %32, label %71
32: ; preds = %27
%33 = load i32, i32* %5
%34 = and i64 %30, 1
%35 = icmp ult i64 %29, 2
br i1 %35, label %60, label %36
36: ; preds = %32
%37 = and i64 %30, -2
br label %38
38: ; preds = %56, %36
%39 = phi i32 [ %33, %36 ], [ %57, %56 ]
%40 = phi i64 [ 0, %36 ], [ %50, %56 ]
%41 = phi i64 [ 0, %36 ], [ %58, %56 ]
%42 = or i64 %40, 1
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %39, %44
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %40
store i32 %44, i32* %47
store i32 %39, i32* %43
br label %48
48: ; preds = %38, %46
%49 = phi i32 [ %44, %38 ], [ %39, %46 ]
%50 = add nuw nsw i64 %40, 2
%51 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = icmp sgt i32 %49, %52
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %42
store i32 %52, i32* %55
store i32 %49, i32* %51
br label %56
56: ; preds = %54, %48
%57 = phi i32 [ %52, %48 ], [ %49, %54 ]
%58 = add i64 %41, 2
%59 = icmp eq i64 %58, %37
br i1 %59, label %60, label %38
60: ; preds = %56, %32
%61 = phi i32 [ %33, %32 ], [ %57, %56 ]
%62 = phi i64 [ 0, %32 ], [ %50, %56 ]
%63 = icmp eq i64 %34, 0
br i1 %63, label %71, label %64
64: ; preds = %60
%65 = add nuw nsw i64 %62, 1
%66 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = icmp sgt i32 %61, %67
br i1 %68, label %69, label %71
69: ; preds = %64
%70 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %62
store i32 %67, i32* %70
store i32 %61, i32* %66
br label %71
71: ; preds = %60, %69, %64, %27
%72 = add nuw nsw i64 %28, 1
%73 = icmp eq i64 %72, 10
br i1 %73, label %74, label %27
74: ; preds = %71
%75 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%76 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%77 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%78 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%79 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%80 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%81 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%82 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%83 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%84 = tail call i32 @printStr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%85 = load i32, i32* %5
%86 = tail call i32 @printInt(i32 %85)
%87 = tail call i32 @printChar(i8 signext 32)
%88 = load i32, i32* %83
%89 = tail call i32 @printInt(i32 %88)
%90 = tail call i32 @printChar(i8 signext 32)
%91 = load i32, i32* %82
%92 = tail call i32 @printInt(i32 %91)
%93 = tail call i32 @printChar(i8 signext 32)
%94 = load i32, i32* %81
%95 = tail call i32 @printInt(i32 %94)
%96 = tail call i32 @printChar(i8 signext 32)
%97 = load i32, i32* %80
%98 = tail call i32 @printInt(i32 %97)
%99 = tail call i32 @printChar(i8 signext 32)
%100 = load i32, i32* %79
%101 = tail call i32 @printInt(i32 %100)
%102 = tail call i32 @printChar(i8 signext 32)
%103 = load i32, i32* %78
%104 = tail call i32 @printInt(i32 %103)
%105 = tail call i32 @printChar(i8 signext 32)
%106 = load i32, i32* %77
%107 = tail call i32 @printInt(i32 %106)
%108 = tail call i32 @printChar(i8 signext 32)
%109 = load i32, i32* %76
%110 = tail call i32 @printInt(i32 %109)
%111 = tail call i32 @printChar(i8 signext 32)
%112 = load i32, i32* %75
%113 = tail call i32 @printInt(i32 %112)
%114 = tail call i32 @printChar(i8 signext 32)
%115 = tail call i32 @printChar(i8 signext 10)
ret void
}