#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(long *, int, int);
int /*<<< orphan*/ clrscr();
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  clrscr();
  long arr[100];
  int n, i, sort_order;
  char *_order[] = {"ascending", "descending"};
  printf("Enter number of elements : ");
  scanf("%d", &n);
  printf("Enter %d integers :\n", n);
  for (i = 0; i < n; i++)
    scanf("%ld", &arr[i]);
  printf("Sort : 1. Ascending\t2. Descending ? ");
  scanf("%d", &sort_order);
  bubble_sort(arr, n, sort_order);
  printf("Sorted list in %s order :\n", _order[sort_order - 1]);
  for (i = 0; i < n; i++)
    printf("%ld\n", arr[i]);
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clrscr@plt>
mov    0x2ca0(%rip),%rax
mov    %rax,-0x350(%rbp)
mov    0x2c9a(%rip),%rax
mov    %rax,-0x348(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
lea    -0x334(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x334(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x338(%rbp)
mov    -0x338(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    120f <main+0xbf>
movslq -0x338(%rbp),%rax
lea    -0x330(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x338(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x338(%rbp)
jmp    11c6 <main+0x76>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0d(%rip),%rdi
lea    -0x33c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x330(%rbp),%rdi
mov    -0x334(%rbp),%esi
mov    -0x33c(%rbp),%edx
call   1070 <bubble_sort@plt>
mov    -0x33c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x350(%rbp,%rax,8),%rsi
ff
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x338(%rbp)
mov    -0x338(%rbp),%eax
cmp    -0x334(%rbp),%eax
jge    12b8 <main+0x168>
movslq -0x338(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rsi
ff
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x338(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x338(%rbp)
jmp    1275 <main+0x125>
mov    $0x0,%al
call   1060 <getch@plt>
xor    %eax,%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x330,%rsp
xor    %eax,%eax
call   1030 <clrscr@plt>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11cf <main+0x7f>
lea    0x10(%rsp),%r15
lea    0xea0(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x8,%r15
cmp    %rax,%rbx
jl     11b0 <main+0x60>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
call   1070 <bubble_sort@plt>
movslq 0xc(%rsp),%rax
lea    0xe86(%rip),%rcx
movslq -0x4(%rcx,%rax,4),%rsi
add    %rcx,%rsi
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    125d <main+0x10d>
lea    0xe5b(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1240 <main+0xf0>
xor    %eax,%eax
call   1060 <getch@plt>
xor    %eax,%eax
add    $0x330,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"ascending\00"
@.str.1 = [11 x i8] c"descending\00"
@__const.main._order = [2 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [28 x i8] c"Enter number of elements : \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [21 x i8] c"Enter %d integers :\0A\00"
@.str.5 = [4 x i8] c"%ld\00"
@.str.6 = [37 x i8] c"Sort : 1. Ascending\092. Descending ? \00"
@.str.7 = [27 x i8] c"Sorted list in %s order :\0A\00"
@.str.8 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i64]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8*]
store i32 0, i32* %1
%7 = call i32 (...) @clrscr()
%8 = bitcast [2 x i8*]* %6 to i8*
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %11)
store i32 0, i32* %4
br label %13
13: ; preds = %22, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 %19
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64* %20)
br label %22
22: ; preds = %17
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %13
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%28 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 0
%29 = load i32, i32* %3
%30 = load i32, i32* %5
%31 = call i32 @bubble_sort(i64* %28, i32 %29, i32 %30)
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %36)
store i32 0, i32* %4
br label %38
38: ; preds = %48, %25
%39 = load i32, i32* %4
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %51
42: ; preds = %38
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 %44
%46 = load i64, i64* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64 %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %38
51: ; preds = %38
%52 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"ascending\00"
@.str.1 = [11 x i8] c"descending\00"
@reltable.main = [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.main to i64)) to i32)]
@.str.2 = [28 x i8] c"Enter number of elements : \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [21 x i8] c"Enter %d integers :\0A\00"
@.str.5 = [4 x i8] c"%ld\00"
@.str.6 = [37 x i8] c"Sort : 1. Ascending\092. Descending ? \00"
@.str.7 = [27 x i8] c"Sorted list in %s order :\0A\00"
@.str.8 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca [100 x i64]
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 (...) @clrscr()
%5 = bitcast [100 x i64]* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %0, %14
%15 = phi i64 [ %18, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds [100 x i64], [100 x i64]* %1, i64 0, i64 %15
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64* %16)
%18 = add nuw nsw i64 %15, 1
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %14, label %22
22: ; preds = %14, %0
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%25 = getelementptr inbounds [100 x i64], [100 x i64]* %1, i64 0, i64 0
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 @bubble_sort(i64* %25, i32 %26, i32 %27)
%29 = load i32, i32* %3
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = shl i64 %31, 2
%33 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.main to i8*), i64 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %2
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %22, %37
%38 = phi i64 [ %42, %37 ], [ 0, %22 ]
%39 = getelementptr inbounds [100 x i64], [100 x i64]* %1, i64 0, i64 %38
%40 = load i64, i64* %39
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i64 %40)
%42 = add nuw nsw i64 %38, 1
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %37, label %46
46: ; preds = %37, %22
%47 = call i32 (...) @getch()
ret i32 0
}