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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeab(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    118f <main+0x3f>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120b <main+0xbb>
mov    -0xc(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe35(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b7 <main+0x67>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <selection_sort@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1262 <main+0x112>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    122c <main+0xdc>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jns    11aa <main+0x3a>
neg    %edi
mov    %edi,0xc(%rsp)
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
lea    0xe76(%rip),%rdi
call   1060 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    1213 <main+0xa3>
lea    0xe53(%rip),%r14
lea    0xe49(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11e0 <main+0x70>
lea    0xe18(%rip),%rdi
call   1060 <puts@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
call   1030 <selection_sort@plt>
cmpl   $0x0,0xc(%rsp)
jle    125e <main+0xee>
lea    0xdf1(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1240 <main+0xd0>
mov    %r12,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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