#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 main() {
  int arr[100], n, i, j, tmp;
  printf("Enter the length of sequence you want to sort (less than %d): ", 100);
  scanf("%d", &n);
  printf("Enter %d numbers: ", n);
  for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  for (i = 0; i < n; i++) {
    for (j = 1; j < n - i; j++) {
      if (arr[j - 1] > arr[j]) {
        tmp = arr[j];
        arr[j] = arr[j - 1];
        arr[j - 1] = tmp;
      }
    }
  }
  printf("\nThe [bubble] sorted sequence follows:\n");
  for (i = 0; i < n; i++)
    printf("%d ", arr[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef3(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11bd <main+0x9d>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe9b(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1176 <main+0x56>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    12a1 <main+0x181>
movl   $0x1,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
mov    -0x1a4(%rbp),%ecx
sub    -0x1a8(%rbp),%ecx
cmp    %ecx,%eax
jge    1288 <main+0x168>
mov    -0x1ac(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1a0(%rbp,%rax,4),%eax
movslq -0x1ac(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jle    126f <main+0x14f>
movslq -0x1ac(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1ac(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1a0(%rbp,%rax,4),%ecx
movslq -0x1ac(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1b0(%rbp),%ecx
mov    -0x1ac(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %ecx,-0x1a0(%rbp,%rax,4)
jmp    1274 <main+0x154>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11e3 <main+0xc3>
jmp    128d <main+0x16d>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11c7 <main+0xa7>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    12fb <main+0x1db>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    12b9 <main+0x199>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xead(%rip),%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    126e <main+0x12e>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xea4(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%r10
add    $0x4,%r15
cmp    %r10,%rbx
jl     11a0 <main+0x60>
test   %r10d,%r10d
jle    126e <main+0x12e>
xor    %ecx,%ecx
mov    %r10d,%r9d
jmp    11e0 <main+0xa0>
nopl   (%rax)
add    $0x1,%ecx
add    $0xffffffff,%r9d
cmp    %r10d,%ecx
je     126e <main+0x12e>
mov    %r9d,%esi
add    $0xffffffffffffffff,%rsi
and    $0xfffffffffffffffe,%rsi
neg    %rsi
mov    %r10d,%eax
sub    %ecx,%eax
lea    -0x1(%rax),%r8
cmp    $0x2,%eax
jl     11d0 <main+0x90>
mov    0x10(%rsp),%eax
mov    $0x1,%edi
jne    1220 <main+0xe0>
test   $0x1,%r8b
je     11d0 <main+0x90>
mov    0x10(%rsp,%rdi,4),%edx
cmp    %edx,%eax
jle    11d0 <main+0x90>
mov    %eax,0x10(%rsp,%rdi,4)
mov    %edx,0xc(%rsp,%rdi,4)
jmp    11d0 <main+0x90>
nop
mov    $0x1,%edi
jmp    124a <main+0x10a>
nopw   0x0(%rax,%rax,1)
mov    %eax,0x14(%rsp,%rdi,4)
mov    %edx,0x10(%rsp,%rdi,4)
lea    (%rsi,%rdi,1),%rdx
add    $0x2,%rdx
add    $0x2,%rdi
cmp    $0x1,%rdx
je     1207 <main+0xc7>
mov    0x10(%rsp,%rdi,4),%ebx
cmp    %ebx,%eax
jle    1260 <main+0x120>
mov    %eax,0x10(%rsp,%rdi,4)
mov    %ebx,0xc(%rsp,%rdi,4)
jmp    1262 <main+0x122>
nopl   0x0(%rax)
mov    %ebx,%eax
mov    0x14(%rsp,%rdi,4),%edx
cmp    %edx,%eax
jg     1230 <main+0xf0>
mov    %edx,%eax
jmp    1238 <main+0xf8>
lea    0xde4(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    12ac <main+0x16c>
lea    0xdcd(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1290 <main+0x150>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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