#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 array[100], n, c, d, position, swap;
  printf("Enter number of elements\n");
  scanf("%d", &n);
  printf("Enter %d integers\n", n);
  for (c = 0; c < n; c++)
    scanf("%d", &array[c]);
  for (c = 0; c < (n - 1); c++) {
    position = c;
    for (d = c + 1; d < n; d++) {
      if (array[position] > array[d])
        position = d;
    }
    if (position != c) {
      swap = array[c];
      array[c] = array[position];
      array[position] = swap;
    }
  }
  printf("Sorted list in ascending order:\n");
  for (c = 0; c < n; c++)
    printf("%d\n", array[c]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    11b8 <main+0x98>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7b(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1171 <main+0x51>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
mov    -0x1a4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12bc <main+0x19c>
mov    -0x1a8(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    124d <main+0x12d>
movslq -0x1b0(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
movslq -0x1ac(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jle    1234 <main+0x114>
mov    -0x1ac(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
jmp    1239 <main+0x119>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11f4 <main+0xd4>
mov    -0x1b0(%rbp),%eax
cmp    -0x1a8(%rbp),%eax
je     12a3 <main+0x183>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1b4(%rbp)
movslq -0x1b0(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%ecx
movslq -0x1a8(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1b4(%rbp),%ecx
movslq -0x1b0(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
jmp    12a8 <main+0x188>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11c2 <main+0xa2>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    1316 <main+0x1f6>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    12d4 <main+0x1b4>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1a0,%rsp
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    122e <main+0xfe>
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
lea    0xe7c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbx
jl     1190 <main+0x60>
mov    %eax,%eax
cmp    $0x2,%eax
jl     122e <main+0xfe>
lea    -0x1(%rax),%r8d
mov    $0x1,%r10d
xor    %esi,%esi
jmp    11dc <main+0xac>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r10
mov    %r9,%rsi
cmp    %r8,%r9
je     122e <main+0xfe>
lea    0x1(%rsi),%r9
cmp    %rax,%r9
jae    1210 <main+0xe0>
mov    %r10,%rdx
mov    %esi,%ebx
jmp    11fb <main+0xcb>
nopl   0x0(%rax)
add    $0x1,%rdx
mov    %edi,%ebx
cmp    %rdx,%rax
je     1212 <main+0xe2>
movslq %ebx,%rdi
mov    0x10(%rsp,%rdi,4),%ecx
mov    %edx,%edi
cmp    0x10(%rsp,%rdx,4),%ecx
jg     11f0 <main+0xc0>
mov    %ebx,%edi
jmp    11f0 <main+0xc0>
xchg   %ax,%ax
mov    %esi,%edi
mov    %edi,%ecx
cmp    %rcx,%rsi
je     11d0 <main+0xa0>
mov    0x10(%rsp,%rsi,4),%ecx
movslq %edi,%rdx
mov    0x10(%rsp,%rdx,4),%edi
mov    %edi,0x10(%rsp,%rsi,4)
mov    %ecx,0x10(%rsp,%rdx,4)
jmp    11d0 <main+0xa0>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    126c <main+0x13c>
lea    0xdce(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0x120>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"Enter %d integers\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [25 x i8] c"Enter number of elements\00"
@str.5 = [32 x i8] c"Sorted list in ascending order:\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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 = 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 %18, label %58
11: ; preds = %18
%12 = icmp sgt i32 %23, 1
br i1 %12, label %13, label %58
13: ; preds = %11
%14 = add nsw i32 %23, -1
%15 = zext i32 %23 to i64
%16 = zext i32 %14 to i64
%17 = zext i32 %23 to i64
br label %26
18: ; preds = %0, %18
%19 = phi i64 [ %22, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %11
26: ; preds = %13, %55
%27 = phi i64 [ 0, %13 ], [ %29, %55 ]
%28 = phi i64 [ 1, %13 ], [ %56, %55 ]
%29 = add nuw nsw i64 %27, 1
%30 = icmp ult i64 %29, %15
%31 = trunc i64 %27 to i32
br i1 %30, label %32, label %45
32: ; preds = %26, %32
%33 = phi i64 [ %43, %32 ], [ %28, %26 ]
%34 = phi i32 [ %42, %32 ], [ %31, %26 ]
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %33
%39 = load i32, i32* %38
%40 = icmp sgt i32 %37, %39
%41 = trunc i64 %33 to i32
%42 = select i1 %40, i32 %41, i32 %34
%43 = add nuw nsw i64 %33, 1
%44 = icmp eq i64 %43, %17
br i1 %44, label %45, label %32
45: ; preds = %32, %26
%46 = phi i32 [ %31, %26 ], [ %42, %32 ]
%47 = zext i32 %46 to i64
%48 = icmp eq i64 %27, %47
br i1 %48, label %55, label %49
49: ; preds = %45
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %27
%51 = load i32, i32* %50
%52 = sext i32 %46 to i64
%53 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %52
%54 = load i32, i32* %53
store i32 %54, i32* %50
store i32 %51, i32* %53
br label %55
55: ; preds = %45, %49
%56 = add nuw nsw i64 %28, 1
%57 = icmp eq i64 %29, %16
br i1 %57, label %58, label %26
58: ; preds = %55, %0, %11
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%60 = load i32, i32* %2
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %71
62: ; preds = %58, %62
%63 = phi i64 [ %67, %62 ], [ 0, %58 ]
%64 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = add nuw nsw i64 %63, 1
%68 = load i32, i32* %2
%69 = sext i32 %68 to i64
%70 = icmp slt i64 %67, %69
br i1 %70, label %62, label %71
71: ; preds = %62, %58
ret i32 0
}