#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 */
typedef int /*<<< orphan*/ list1;
typedef double clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printArr(int *, int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ selectionSort(int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, double);
int main(void) {
  clock_t start, end;
  double duration1 = 0;
  int list1[] = {15, 11, 9, 8, 7, 5, 3, 2};
  int size = ((int)sizeof(list1) / sizeof(int));
  printArr(list1, size);
  start = clock();
  selectionSort(list1, size);
  end = clock();
  printArr(list1, size);
  duration1 = ((double)end - start) / CLOCKS_PER_SEC;
  printf("time : %f \n\n", duration1);
  FILE *time = fopen("time", "wb");
  char temp[100];
  int i, n, step = 100;
  int a[100000];
  double duration;
  for (n = 0; n <= 100000; n += step) {
    for (i = 0; i < n; i++)
      a[i] = n - i;
    start = clock();
    selectionSort(a, n);
    end = clock();
    duration = ((double)(end - start)) / CLOCKS_PER_SEC;
    sprintf(temp, "time %d : %f\n", n, duration);
    fputs(temp, time);
  }
  fclose(time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61b60,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0xe5f(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe5c(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe59(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe56(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x8,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1080 <printArr@plt>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1070 <selectionSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1080 <printArr@plt>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    0x2dce(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xdf1(%rip),%rdi
call   1050 <printf@plt>
lea    0xdf2(%rip),%rdi
lea    0xdf0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x50(%rbp)
movl   $0x64,-0xcc(%rbp)
movl   $0x0,-0xc8(%rbp)
cmpl   $0x186a0,-0xc8(%rbp)
jg     1348 <main+0x1c8>
movl   $0x0,-0xc4(%rbp)
mov    -0xc4(%rbp),%eax
cmp    -0xc8(%rbp),%eax
jge    12b9 <main+0x139>
mov    -0xc8(%rbp),%ecx
sub    -0xc4(%rbp),%ecx
movslq -0xc4(%rbp),%rax
mov    %ecx,-0x61b50(%rbp,%rax,4)
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1279 <main+0xf9>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x10(%rbp)
lea    -0x61b50(%rbp),%rdi
mov    -0xc8(%rbp),%esi
call   1070 <selectionSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    0x2cf4(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x61b58(%rbp)
ff
lea    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%edx
movsd  -0x61b58(%rbp),%xmm0
ff
lea    0xd19(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0xcc(%rbp),%eax
add    -0xc8(%rbp),%eax
mov    %eax,-0xc8(%rbp)
jmp    125f <main+0xdf>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x61b60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61b28,%rsp
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1080 <printArr@plt>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <selectionSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x8,%esi
call   1080 <printArr@plt>
movsd  0x8(%rsp),%xmm0
subsd  (%rsp),%xmm0
mov    0x2de8(%rip),%rbp
divsd  0x0(%rbp),%xmm0
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
lea    0xe75(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r13
lea    0xa0(%rsp),%r14
lea    0xe5f(%rip),%r15
lea    0x30(%rsp),%r12
movdqa 0xddd(%rip),%xmm5
xor    %ebx,%ebx
jmp    12ab <main+0x12b>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <selectionSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
subsd  (%rsp),%xmm0
divsd  0x0(%rbp),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <fputs@plt>
movdqa 0xd89(%rip),%xmm5
lea    0x64(%rbx),%rax
cmp    $0x1863d,%rbx
mov    %rax,%rbx
jae    1411 <main+0x291>
test   %rbx,%rbx
je     1250 <main+0xd0>
cmp    $0x8,%rbx
jae    12c0 <main+0x140>
xor    %eax,%eax
jmp    13cf <main+0x24f>
nopl   (%rax)
mov    %rbx,%rax
movabs $0x7ffffffffffffff8,%rcx
ff ff 7f
and    %rcx,%rax
lea    -0x8(%rax),%rdx
mov    %rdx,%rcx
shr    $0x3,%rcx
add    $0x1,%rcx
movq   %rbx,%xmm0
pshufd $0x44,%xmm0,%xmm0
test   %rdx,%rdx
je     13f8 <main+0x278>
mov    %rbx,%rsi
and    $0xfffffffffffffff8,%rsi
add    $0xfffffffffffffff8,%rsi
shr    $0x3,%rsi
add    $0x1,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
movdqa 0xcfd(%rip),%xmm1
movdqa 0xce5(%rip),%xmm2
movdqa 0xd0c(%rip),%xmm8
movdqa 0xd14(%rip),%xmm7
movdqa 0xd1c(%rip),%xmm6
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa %xmm0,%xmm3
psubq  %xmm1,%xmm3
movdqa %xmm0,%xmm4
psubq  %xmm2,%xmm4
shufps $0x88,%xmm4,%xmm3
movaps %xmm3,%xmm4
psubd  %xmm5,%xmm4
movaps %xmm3,0xa0(%rsp,%rdx,4)
movdqa %xmm4,0xb0(%rsp,%rdx,4)
movaps %xmm3,%xmm4
psubd  %xmm8,%xmm4
psubd  %xmm7,%xmm3
movdqa %xmm4,0xc0(%rsp,%rdx,4)
movdqa %xmm3,0xd0(%rsp,%rdx,4)
add    $0x10,%rdx
paddq  %xmm6,%xmm1
paddq  %xmm6,%xmm2
add    $0xfffffffffffffffe,%rsi
jne    1340 <main+0x1c0>
test   $0x1,%cl
je     13c6 <main+0x246>
movdqa %xmm0,%xmm3
psubq  %xmm1,%xmm3
psubq  %xmm2,%xmm0
shufps $0x88,%xmm0,%xmm3
movaps %xmm3,0xa0(%rsp,%rdx,4)
psubd  %xmm5,%xmm3
movdqa %xmm3,0xb0(%rsp,%rdx,4)
cmp    %rax,%rbx
je     1250 <main+0xd0>
mov    %ebx,%ecx
sub    %eax,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,0xa0(%rsp,%rax,4)
add    $0x1,%rax
add    $0xffffffff,%ecx
cmp    %rax,%rbx
jne    13e0 <main+0x260>
jmp    1250 <main+0xd0>
xor    %edx,%edx
movdqa 0xc0e(%rip),%xmm1
movdqa 0xbf6(%rip),%xmm2
test   $0x1,%cl
jne    13a1 <main+0x221>
jmp    13c6 <main+0x246>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x61b28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.list1 = [8 x i32] [i32 15, i32 11, i32 9, i32 8, i32 7, i32 5, i32 3, i32 2]
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [13 x i8] c"time : %f \0A\0A\00"
@.str.1 = [5 x i8] c"time\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [14 x i8] c"time %d : %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca [8 x i32]
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [100000 x i32]
%13 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %4
%14 = bitcast [8 x i32]* %5 to i8*
store i32 8, i32* %6
%15 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%16 = load i32, i32* %6
%17 = call i32 @printArr(i32* %15, i32 %16)
%18 = call double (...) @clock()
store double %18, double* %2
%19 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%20 = load i32, i32* %6
%21 = call i32 @selectionSort(i32* %19, i32 %20)
%22 = call double (...) @clock()
store double %22, double* %3
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%24 = load i32, i32* %6
%25 = call i32 @printArr(i32* %23, i32 %24)
%26 = load double, double* %3
%27 = load double, double* %2
%28 = fsub double %26, %27
%29 = load double, double* @CLOCKS_PER_SEC
%30 = fdiv double %28, %29
store double %30, double* %4
%31 = load double, double* %4
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %31)
%33 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %7
store i32 100, i32* %11
store i32 0, i32* %10
br label %34
34: ; preds = %70, %0
%35 = load i32, i32* %10
%36 = icmp sle i32 %35, 100000
br i1 %36, label %37, label %74
37: ; preds = %34
store i32 0, i32* %9
br label %38
38: ; preds = %49, %37
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i32, i32* %10
%44 = load i32, i32* %9
%45 = sub nsw i32 %43, %44
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100000 x i32], [100000 x i32]* %12, i64 0, i64 %47
store i32 %45, i32* %48
br label %49
49: ; preds = %42
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %38
52: ; preds = %38
%53 = call double (...) @clock()
store double %53, double* %2
%54 = getelementptr inbounds [100000 x i32], [100000 x i32]* %12, i64 0, i64 0
%55 = load i32, i32* %10
%56 = call i32 @selectionSort(i32* %54, i32 %55)
%57 = call double (...) @clock()
store double %57, double* %3
%58 = load double, double* %3
%59 = load double, double* %2
%60 = fsub double %58, %59
%61 = load double, double* @CLOCKS_PER_SEC
%62 = fdiv double %60, %61
store double %62, double* %13
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%64 = load i32, i32* %10
%65 = load double, double* %13
%66 = call i32 @sprintf(i8* %63, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %64, double %65)
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%68 = load i32*, i32** %7
%69 = call i32 @fputs(i8* %67, i32* %68)
br label %70
70: ; preds = %52
%71 = load i32, i32* %11
%72 = load i32, i32* %10
%73 = add nsw i32 %72, %71
store i32 %73, i32* %10
br label %34
74: ; preds = %34
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
ret i32 0
}

LLVM IR (-O2):
@__const.main.list1 = [8 x i32] [i32 15, i32 11, i32 9, i32 8, i32 7, i32 5, i32 3, i32 2]
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [13 x i8] c"time : %f \0A\0A\00"
@.str.1 = [5 x i8] c"time\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [14 x i8] c"time %d : %f\0A\00"
define i32 @main() {
%1 = alloca [8 x i32]
%2 = alloca [100 x i8]
%3 = alloca [100000 x i32]
%4 = bitcast [8 x i32]* %1 to i8*
%5 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%6 = call i32 @printArr(i32* %5, i32 8)
%7 = call double (...) @clock()
%8 = call i32 @selectionSort(i32* %5, i32 8)
%9 = call double (...) @clock()
%10 = call i32 @printArr(i32* %5, i32 8)
%11 = fsub double %9, %7
%12 = load double, double* @CLOCKS_PER_SEC
%13 = fdiv double %11, %12
%14 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %13)
%15 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%17 = bitcast [100000 x i32]* %3 to i8*
%18 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 0
br label %19
19: ; preds = %0, %91
%20 = phi i64 [ 0, %0 ], [ %101, %91 ]
%21 = and i64 %20, 9223372036854775800
%22 = add nsw i64 %21, -8
%23 = lshr exact i64 %22, 3
%24 = add nuw nsw i64 %23, 1
%25 = icmp eq i64 %20, 0
br i1 %25, label %91, label %26
26: ; preds = %19
%27 = icmp ult i64 %20, 8
br i1 %27, label %82, label %28
28: ; preds = %26
%29 = and i64 %20, 9223372036854775800
%30 = insertelement <4 x i64> poison, i64 %20, i64 0
%31 = shufflevector <4 x i64> %30, <4 x i64> poison, <4 x i32> zeroinitializer
%32 = insertelement <4 x i64> poison, i64 %20, i64 0
%33 = shufflevector <4 x i64> %32, <4 x i64> poison, <4 x i32> zeroinitializer
%34 = and i64 %24, 1
%35 = icmp eq i64 %22, 0
br i1 %35, label %66, label %36
36: ; preds = %28
%37 = and i64 %24, 4611686018427387902
br label %38
38: ; preds = %38, %36
%39 = phi i64 [ 0, %36 ], [ %62, %38 ]
%40 = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %36 ], [ %63, %38 ]
%41 = phi i64 [ 0, %36 ], [ %64, %38 ]
%42 = add <4 x i64> %40, <i64 4, i64 4, i64 4, i64 4>
%43 = sub nsw <4 x i64> %31, %40
%44 = sub nsw <4 x i64> %33, %42
%45 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 %39
%46 = trunc <4 x i64> %43 to <4 x i32>
%47 = trunc <4 x i64> %44 to <4 x i32>
%48 = bitcast i32* %45 to <4 x i32>*
store <4 x i32> %46, <4 x i32>* %48
%49 = getelementptr inbounds i32, i32* %45, i64 4
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> %47, <4 x i32>* %50
%51 = or i64 %39, 8
%52 = add <4 x i64> %40, <i64 8, i64 8, i64 8, i64 8>
%53 = add <4 x i64> %40, <i64 12, i64 12, i64 12, i64 12>
%54 = sub nsw <4 x i64> %31, %52
%55 = sub nsw <4 x i64> %33, %53
%56 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 %51
%57 = trunc <4 x i64> %54 to <4 x i32>
%58 = trunc <4 x i64> %55 to <4 x i32>
%59 = bitcast i32* %56 to <4 x i32>*
store <4 x i32> %57, <4 x i32>* %59
%60 = getelementptr inbounds i32, i32* %56, i64 4
%61 = bitcast i32* %60 to <4 x i32>*
store <4 x i32> %58, <4 x i32>* %61
%62 = add nuw i64 %39, 16
%63 = add <4 x i64> %40, <i64 16, i64 16, i64 16, i64 16>
%64 = add i64 %41, 2
%65 = icmp eq i64 %64, %37
br i1 %65, label %66, label %38
66: ; preds = %38, %28
%67 = phi i64 [ 0, %28 ], [ %62, %38 ]
%68 = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %28 ], [ %63, %38 ]
%69 = icmp eq i64 %34, 0
br i1 %69, label %80, label %70
70: ; preds = %66
%71 = add <4 x i64> %68, <i64 4, i64 4, i64 4, i64 4>
%72 = sub nsw <4 x i64> %31, %68
%73 = sub nsw <4 x i64> %33, %71
%74 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 %67
%75 = trunc <4 x i64> %72 to <4 x i32>
%76 = trunc <4 x i64> %73 to <4 x i32>
%77 = bitcast i32* %74 to <4 x i32>*
store <4 x i32> %75, <4 x i32>* %77
%78 = getelementptr inbounds i32, i32* %74, i64 4
%79 = bitcast i32* %78 to <4 x i32>*
store <4 x i32> %76, <4 x i32>* %79
br label %80
80: ; preds = %66, %70
%81 = icmp eq i64 %20, %29
br i1 %81, label %91, label %82
82: ; preds = %26, %80
%83 = phi i64 [ 0, %26 ], [ %29, %80 ]
br label %84
84: ; preds = %82, %84
%85 = phi i64 [ %89, %84 ], [ %83, %82 ]
%86 = sub nsw i64 %20, %85
%87 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 %85
%88 = trunc i64 %86 to i32
store i32 %88, i32* %87
%89 = add nuw nsw i64 %85, 1
%90 = icmp eq i64 %89, %20
br i1 %90, label %91, label %84
91: ; preds = %84, %80, %19
%92 = call double (...) @clock()
%93 = trunc i64 %20 to i32
%94 = call i32 @selectionSort(i32* %18, i32 %93)
%95 = call double (...) @clock()
%96 = fsub double %95, %92
%97 = load double, double* @CLOCKS_PER_SEC
%98 = fdiv double %96, %97
%99 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %93, double %98)
%100 = call i32 @fputs(i8* %16, i32* %15)
%101 = add nuw nsw i64 %20, 100
%102 = icmp ult i64 %20, 99901
br i1 %102, label %19, label %103
103: ; preds = %91
%104 = call i32 @fclose(i32* %15)
ret i32 0
}