#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 /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ swap(int *, int *);
int main() {
  int num;
  printf("Enter the number of elements ");
  scanf("%d", &num);
  int arr[num];
  int i;
  printf("Enter the elements ");
  for (i = 0; i < num; i++)
    scanf("%d", &arr[i]);
  int swapped = 1;
  int begin = 0;
  int end = num - 1;
  while (swapped) {
    swapped = 0;
    for (i = begin; i < end; ++i) {
      if (arr[i] > arr[i + 1]) {
        swap(&arr[i], &arr[i + 1]);
        swapped = 1;
      }
    }
    if (!swapped)
      break;
    swapped = 0;
    for (i = end - 1; i >= begin; --i) {
      if (arr[i] > arr[i + 1]) {
        swap(&arr[i], &arr[i + 1]);
        swapped = 1;
      }
    }
    ++begin;
  }
  printf("Sorted array :\n");
  for (i = 0; i < num; i++)
    printf("%d ", arr[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ce <main+0x9e>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe63(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <main+0x69>
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12fb <main+0x1cb>
movl   $0x0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1265 <main+0x135>
mov    -0x30(%rbp),%rcx
movslq -0x1c(%rbp),%rax
mov    (%rcx,%rax,4),%eax
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1252 <main+0x122>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %rsi,%rdi
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
movl   $0x1,-0x20(%rbp)
jmp    1257 <main+0x127>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fc <main+0xcc>
cmpl   $0x0,-0x20(%rbp)
jne    1274 <main+0x144>
jmp    12fb <main+0x1cb>
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     12ed <main+0x1bd>
mov    -0x30(%rbp),%rcx
movslq -0x1c(%rbp),%rax
mov    (%rcx,%rax,4),%eax
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    12da <main+0x1aa>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %rsi,%rdi
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
movl   $0x1,-0x20(%rbp)
jmp    12df <main+0x1af>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1284 <main+0x154>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e5 <main+0xb5>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1343 <main+0x213>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1310 <main+0x1e0>
lea    0xcf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    11dc <main+0x8c>
xor    %r15d,%r15d
lea    0xe64(%rip),%r14
mov    %r13,%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r15
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r15
jl     11c0 <main+0x70>
lea    -0x1(%rax),%r12d
add    $0xfffffffe,%eax
cltq
movslq %r12d,%rcx
mov    %rcx,-0x60(%rbp)
lea    0x4(%r13),%r15
lea    0x1(%rax),%rcx
mov    %rcx,-0x50(%rbp)
mov    %r13,-0x38(%rbp)
mov    %rax,-0x58(%rbp)
lea    0x4(,%rax,4),%rax
add    %r13,%rax
mov    %rax,-0x48(%rbp)
xor    %r13d,%r13d
jmp    1234 <main+0xe4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
add    $0x4,%r15
add    $0xffffffffffffffff,%r12
test   %eax,%eax
je     12ca <main+0x17a>
cmp    -0x60(%rbp),%r13
jge    12ca <main+0x17a>
xor    %eax,%eax
mov    %r12,%r14
mov    %r15,%rbx
jmp    125a <main+0x10a>
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbx
add    $0xffffffffffffffff,%r14
je     1280 <main+0x130>
mov    -0x4(%rbx),%ecx
cmp    (%rbx),%ecx
jle    1250 <main+0x100>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1070 <swap@plt>
mov    $0x1,%eax
jmp    1250 <main+0x100>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %eax,%eax
je     12ca <main+0x17a>
cmp    -0x58(%rbp),%r13
jg     12ca <main+0x17a>
xor    %eax,%eax
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rbx
jmp    12b0 <main+0x160>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
mov    %r14,%rsi
cmp    %r13,%rbx
jle    1220 <main+0xd0>
lea    -0x4(%rsi),%r14
mov    -0x4(%rsi),%ecx
cmp    (%rsi),%ecx
jle    12a0 <main+0x150>
mov    %r14,%rdi
call   1070 <swap@plt>
mov    $0x1,%eax
jmp    12a0 <main+0x150>
lea    0xd68(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%r15
jle    130b <main+0x1bb>
lea    0xd4e(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     12f0 <main+0x1a0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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