#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*/ selectionSort(int *, int);
int /*<<< orphan*/ system(char *);
int main() {
  int a[10] = {0}, n = 0, i;
  system("cls");
  printf("\nEnter the number of elemenets: ");
  scanf("%d", &n);
  printf("\nEnter the array:\n");
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  selectionSort(a, n);
  printf("\n\nHere is the sorted array:\n");
  for (i = 0; i < n; i++) {
    printf(" %d", a[i]);
  }
  printf("\n\n");
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
movl   $0x0,-0x34(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <system@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11ea <main+0x9a>
movslq -0x38(%rbp),%rax
lea    -0x30(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7f(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11b5 <main+0x65>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <selectionSort@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    123b <main+0xeb>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    120b <main+0xbb>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe82(%rip),%rdi
call   1040 <system@plt>
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11ed <main+0x9d>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe62(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
add    $0x4,%r15
cmp    %rsi,%rbx
jl     11d0 <main+0x80>
lea    0x10(%rsp),%rdi
call   1060 <selectionSort@plt>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    123c <main+0xec>
lea    0xe14(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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     1220 <main+0xd0>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
lea    0xdda(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cls\00"
@.str.1 = [33 x i8] c"\0AEnter the number of elemenets: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"\0AEnter the array:\0A\00"
@.str.4 = [29 x i8] c"\0A\0AHere is the sorted array:\0A\00"
@.str.5 = [4 x i8] c" %d\00"
@.str.6 = [3 x i8] c"\0A\0A\00"
@.str.7 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [10 x i32]* %2 to i8*
store i32 0, i32* %3
%6 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %10
10: ; preds = %19, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%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.2, i64 0, i64 0), i32* %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %10
22: ; preds = %10
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @selectionSort(i32* %23, i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %27
27: ; preds = %37, %22
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %27
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%42 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
@.str.1 = [33 x i8] c"\0AEnter the number of elemenets: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c" %d\00"
@.str.7 = [6 x i8] c"pause\00"
@str = [18 x i8] c"\0AEnter the array:\00"
@str.8 = [28 x i8] c"\0A\0AHere is the sorted array:\00"
@str.9 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca i32
%3 = bitcast [10 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %0, %11
%12 = phi i64 [ %15, %11 ], [ 0, %0 ]
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %12
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %13)
%15 = add nuw nsw i64 %12, 1
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %11, label %19
19: ; preds = %11, %0
%20 = phi i32 [ %9, %0 ], [ %16, %11 ]
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%22 = call i32 @selectionSort(i32* %21, i32 %20)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %19, %26
%27 = phi i64 [ %31, %26 ], [ 0, %19 ]
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %26, label %35
35: ; preds = %26, %19
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
%37 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}