#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*/ bubble_sort(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, *a;
  printf("Enter no. of elements: ");
  scanf("%d", &n);
  a = (int *)malloc(n * sizeof(int));
  printf("Enter the elements: ");
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  bubble_sort(a, n);
  printf("After Sorting: ");
  for (i = 0; i < n; i++)
    printf(" %d", a[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ca <main+0x8a>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe87(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1195 <main+0x55>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <bubble_sort@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121e <main+0xde>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11eb <main+0xab>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11bd <main+0x7d>
xor    %r12d,%r12d
lea    0xea8(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r12
jl     11a0 <main+0x60>
mov    %r14,%rdi
call   1060 <bubble_sort@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    120c <main+0xcc>
lea    0xe5c(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter no. of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Enter the elements: \00"
@.str.3 = [16 x i8] c"After Sorting: \00"
@.str.4 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%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 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %14
27: ; preds = %14
%28 = load i32*, i32** %4
%29 = load i32, i32* %2
%30 = call i32 @bubble_sort(i32* %28, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %32
32: ; preds = %43, %27
%33 = load i32, i32* %3
%34 = load i32, i32* %2
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i32*, i32** %4
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %32
46: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter no. of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Enter the elements: \00"
@.str.3 = [16 x i8] c"After Sorting: \00"
@.str.4 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 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 = call i32 @bubble_sort(i32* %8, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* %1
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %20, %26
%27 = phi i64 [ %31, %26 ], [ 0, %20 ]
%28 = getelementptr inbounds i32, i32* %8, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %26, label %35
35: ; preds = %26, %20
ret i32 0
}