#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int iNum, i, j, k, iaArr[10], iTemp;
  printf("\n*************************************************");
  printf("\n*\tPROGRAM TO IMPLEMENT BUBBLE SORT\t*\n");
  printf("*************************************************");
  printf("\nEnter no of elements\n");
  scanf("%d", &iNum);
  printf("\nEnter the elements\n");
  for (i = 0; i < iNum; i++)
    scanf("%d", &iaArr[i]);
  for (i = 0; i < iNum - 1; i++) {
    for (j = 0; j < iNum - i - 1; j++) {
      if (iaArr[j] > iaArr[j + 1]) {
        iTemp = iaArr[j];
        iaArr[j] = iaArr[j + 1];
        iaArr[j + 1] = iTemp;
      }
      printf("\nIteration i=%d, j=%d\n", i, j);
      for (k = 0; k < iNum; k++)
        printf("%d\t", iaArr[k]);
      getchar();
    }
    printf("\nPass %d completed\n", i + 1);
  }
  printf("\nThe Sorted array is \n");
  for (i = 0; i < iNum; i++)
    printf("%d\t", iaArr[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xee6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d1 <main+0xa1>
movslq -0xc(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xeb3(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119c <main+0x6c>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12cf <main+0x19f>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12ad <main+0x17d>
movslq -0x10(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x40(%rbp,%rcx,4),%eax
jle    124d <main+0x11d>
movslq -0x10(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x40(%rbp,%rax,4),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x44(%rbp),%ecx
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1298 <main+0x168>
movslq -0x14(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1268 <main+0x138>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f0 <main+0xc0>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d8 <main+0xa8>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1314 <main+0x1e4>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12e4 <main+0x1b4>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef2(%rip),%rdi
call   1040 <puts@plt>
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xefe(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9a(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    12bf <main+0x16f>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
lea    0xe6b(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11d0 <main+0x80>
cmp    $0x2,%eax
jl     12bf <main+0x16f>
lea    0xe39(%rip),%r14
lea    0xe49(%rip),%rbx
xor    %r12d,%r12d
jmp    1235 <main+0xe5>
nopl   0x0(%rax)
add    $0x1,%r12d
lea    0xe36(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    %ecx,%r12d
jge    12bf <main+0x16f>
mov    %r12d,%r13d
not    %r13d
add    %r13d,%eax
test   %eax,%eax
jle    1210 <main+0xc0>
xor    %edx,%edx
jmp    1268 <main+0x118>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0xc(%rsp),%eax
add    %r13d,%eax
cltq
mov    %rbp,%rdx
cmp    %rax,%rbp
jge    1210 <main+0xc0>
mov    0x10(%rsp,%rdx,4),%eax
mov    0x14(%rsp,%rdx,4),%ecx
lea    0x1(%rdx),%rbp
cmp    %ecx,%eax
jle    1280 <main+0x130>
mov    %ecx,0x10(%rsp,%rdx,4)
mov    %eax,0x10(%rsp,%rbp,4)
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1250 <main+0x100>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%r15,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r15
movslq 0xc(%rsp),%rax
cmp    %rax,%r15
jl     12a0 <main+0x150>
jmp    1250 <main+0x100>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    12fc <main+0x1ac>
lea    0xd74(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     12e0 <main+0x190>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"\0A*************************************************\00"
@.str.1 = [39 x i8] c"\0A*\09PROGRAM TO IMPLEMENT BUBBLE SORT\09*\0A\00"
@.str.2 = [50 x i8] c"*************************************************\00"
@.str.3 = [23 x i8] c"\0AEnter no of elements\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [21 x i8] c"\0AEnter the elements\0A\00"
@.str.6 = [23 x i8] c"\0AIteration i=%d, j=%d\0A\00"
@.str.7 = [4 x i8] c"%d\09\00"
@.str.8 = [20 x i8] c"\0APass %d completed\0A\00"
@.str.9 = [23 x i8] c"\0AThe Sorted array is \0A\00"
@.str.10 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %14
14: ; preds = %23, %0
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %18
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %14
26: ; preds = %14
store i32 0, i32* %3
br label %27
27: ; preds = %95, %26
%28 = load i32, i32* %3
%29 = load i32, i32* %2
%30 = sub nsw i32 %29, 1
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %98
32: ; preds = %27
store i32 0, i32* %4
br label %33
33: ; preds = %88, %32
%34 = load i32, i32* %4
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = sub nsw i32 %35, %36
%38 = sub nsw i32 %37, 1
%39 = icmp slt i32 %34, %38
br i1 %39, label %40, label %91
40: ; preds = %33
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = icmp sgt i32 %44, %49
br i1 %50, label %51, label %69
51: ; preds = %40
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %53
%55 = load i32, i32* %54
store i32 %55, i32* %7
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %62
store i32 %60, i32* %63
%64 = load i32, i32* %7
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %67
store i32 %64, i32* %68
br label %69
69: ; preds = %51, %40
%70 = load i32, i32* %3
%71 = load i32, i32* %4
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %70, i32 %71)
store i32 0, i32* %5
br label %73
73: ; preds = %83, %69
%74 = load i32, i32* %5
%75 = load i32, i32* %2
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %86
77: ; preds = %73
%78 = load i32, i32* %5
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %79
%81 = load i32, i32* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %77
%84 = load i32, i32* %5
%85 = add nsw i32 %84, 1
store i32 %85, i32* %5
br label %73
86: ; preds = %73
%87 = call i32 (...) @getchar()
br label %88
88: ; preds = %86
%89 = load i32, i32* %4
%90 = add nsw i32 %89, 1
store i32 %90, i32* %4
br label %33
91: ; preds = %33
%92 = load i32, i32* %3
%93 = add nsw i32 %92, 1
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %93)
br label %95
95: ; preds = %91
%96 = load i32, i32* %3
%97 = add nsw i32 %96, 1
store i32 %97, i32* %3
br label %27
98: ; preds = %27
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %100
100: ; preds = %110, %98
%101 = load i32, i32* %3
%102 = load i32, i32* %2
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %113
104: ; preds = %100
%105 = load i32, i32* %3
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %106
%108 = load i32, i32* %107
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %104
%111 = load i32, i32* %3
%112 = add nsw i32 %111, 1
store i32 %112, i32* %3
br label %100
113: ; preds = %100
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"\0A*************************************************\00"
@.str.2 = [50 x i8] c"*************************************************\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.6 = [23 x i8] c"\0AIteration i=%d, j=%d\0A\00"
@.str.7 = [4 x i8] c"%d\09\00"
@.str.8 = [20 x i8] c"\0APass %d completed\0A\00"
@str = [38 x i8] c"\0A*\09PROGRAM TO IMPLEMENT BUBBLE SORT\09*\00"
@str.11 = [22 x i8] c"\0AEnter no of elements\00"
@str.12 = [20 x i8] c"\0AEnter the elements\00"
@str.13 = [22 x i8] c"\0AThe Sorted array is \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.11, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %15, label %64
13: ; preds = %15
%14 = icmp sgt i32 %20, 1
br i1 %14, label %23, label %64
15: ; preds = %0, %15
%16 = phi i64 [ %19, %15 ], [ 0, %0 ]
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %13
23: ; preds = %13, %58
%24 = phi i32 [ %61, %58 ], [ %20, %13 ]
%25 = phi i32 [ %59, %58 ], [ 0, %13 ]
%26 = xor i32 %25, -1
%27 = add i32 %24, %26
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %58
29: ; preds = %23, %52
%30 = phi i64 [ %33, %52 ], [ 0, %23 ]
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = add nuw nsw i64 %30, 1
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp sgt i32 %32, %35
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 %35, i32* %31
store i32 %32, i32* %34
br label %38
38: ; preds = %37, %29
%39 = trunc i64 %30 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %25, i32 %39)
%41 = load i32, i32* %1
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %38, %43
%44 = phi i64 [ %48, %43 ], [ 0, %38 ]
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %44, 1
%49 = load i32, i32* %1
%50 = sext i32 %49 to i64
%51 = icmp slt i64 %48, %50
br i1 %51, label %43, label %52
52: ; preds = %43, %38
%53 = call i32 (...) @getchar()
%54 = load i32, i32* %1
%55 = add i32 %54, %26
%56 = sext i32 %55 to i64
%57 = icmp slt i64 %33, %56
br i1 %57, label %29, label %58
58: ; preds = %52, %23
%59 = add nuw nsw i32 %25, 1
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %1
%62 = add nsw i32 %61, -1
%63 = icmp slt i32 %59, %62
br i1 %63, label %23, label %64
64: ; preds = %58, %0, %13
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.13, i64 0, i64 0))
%66 = load i32, i32* %1
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %77
68: ; preds = %64, %68
%69 = phi i64 [ %73, %68 ], [ 0, %64 ]
%70 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %71)
%73 = add nuw nsw i64 %69, 1
%74 = load i32, i32* %1
%75 = sext i32 %74 to i64
%76 = icmp slt i64 %73, %75
br i1 %76, label %68, label %77
77: ; preds = %68, %64
%78 = call i32 @putchar(i32 10)
ret i32 0
}