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

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ PeterSort(int *, int, int, int);
double clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ system(char *);
int main(void) {
  int input[65536];
  long long i = 0;
  long long j;
  double timeTaken;
  clock_t begin, end;
  FILE *fp;
  fp = fopen("file1", "r");
  for (i = 0; i < 65536; i++) {
    fscanf(fp, "%d", &input[i]);
  }
  int upper = input[0];
  int lower = input[0];
  for (j = 0; j < 65536; j++) {
    if (input[j] > upper)
      upper = input[j];
    else if (input[j] < lower)
      lower = input[j];
  }
  begin = clock();
  PeterSort(input, 65536, lower, upper);
  end = clock();
  timeTaken = (double)(end - begin) / CLOCKS_PER_SEC;
  for (i = 0; i < 65536; i++) {
    printf("%d ", input[i]);
  }
  puts("");
  fclose(fp);
  printf("Time taken to perform the sort is %.2lf seconds\n", timeTaken);
  printf("And the clock ticked %ld times.\n", end - begin);
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40050,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x40018(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40040(%rbp)
movq   $0x0,-0x40018(%rbp)
cmpq   $0x10000,-0x40018(%rbp)
jge    1212 <main+0x92>
mov    -0x40040(%rbp),%rdi
mov    -0x40018(%rbp),%rax
lea    -0x40010(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe12(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x40018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40018(%rbp)
jmp    11c2 <main+0x42>
mov    -0x40010(%rbp),%eax
mov    %eax,-0x40044(%rbp)
mov    -0x40010(%rbp),%eax
mov    %eax,-0x40048(%rbp)
movq   $0x0,-0x40020(%rbp)
cmpq   $0x10000,-0x40020(%rbp)
jge    12c8 <main+0x148>
mov    -0x40020(%rbp),%rax
mov    -0x40010(%rbp,%rax,4),%eax
cmp    -0x40044(%rbp),%eax
jle    1279 <main+0xf9>
mov    -0x40020(%rbp),%rax
mov    -0x40010(%rbp,%rax,4),%eax
mov    %eax,-0x40044(%rbp)
jmp    12ac <main+0x12c>
mov    -0x40020(%rbp),%rax
mov    -0x40010(%rbp,%rax,4),%eax
cmp    -0x40048(%rbp),%eax
jge    12a7 <main+0x127>
mov    -0x40020(%rbp),%rax
mov    -0x40010(%rbp,%rax,4),%eax
mov    %eax,-0x40048(%rbp)
jmp    12ac <main+0x12c>
jmp    12b1 <main+0x131>
mov    -0x40020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40020(%rbp)
jmp    1235 <main+0xb5>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x40030(%rbp)
ff
lea    -0x40010(%rbp),%rdi
mov    -0x40048(%rbp),%edx
mov    -0x40044(%rbp),%ecx
mov    $0x10000,%esi
call   1090 <PeterSort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x40038(%rbp)
ff
movsd  -0x40038(%rbp),%xmm0
ff
subsd  -0x40030(%rbp),%xmm0
ff
mov    0x2cce(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40028(%rbp)
ff
movq   $0x0,-0x40018(%rbp)
cmpq   $0x10000,-0x40018(%rbp)
jge    1375 <main+0x1f5>
mov    -0x40018(%rbp),%rax
cvtsi2sdl -0x40010(%rbp,%rax,4),%xmm0
fb ff
lea    0xcb2(%rip),%rdi
call   1070 <printf@plt>
mov    -0x40018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40018(%rbp)
jmp    1331 <main+0x1b1>
lea    0xce4(%rip),%rdi
call   1030 <puts@plt>
mov    -0x40040(%rbp),%rdi
call   1050 <fclose@plt>
movsd  -0x40028(%rbp),%xmm0
ff
lea    0xc73(%rip),%rdi
call   1070 <printf@plt>
movsd  -0x40038(%rbp),%xmm0
ff
subsd  -0x40030(%rbp),%xmm0
ff
lea    0xc88(%rip),%rdi
call   1070 <printf@plt>
lea    0xc9d(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x40050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x40028,%rsp
lea    0xe6c(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
xor    %ebp,%ebp
lea    0xe5c(%rip),%rbx
nopl   0x0(%rax)
lea    (%rsp,%rbp,1),%rdx
add    $0x20,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <fscanf@plt>
add    $0x4,%rbp
cmp    $0x40000,%rbp
jne    11b0 <main+0x30>
mov    0x20(%rsp),%ebx
xor    %eax,%eax
mov    %ebx,%ebp
jmp    11f4 <main+0x74>
nopw   0x0(%rax,%rax,1)
cmp    %ebp,%ecx
cmovg  %ecx,%ebp
cmovg  %edx,%ebx
add    $0x3,%rax
cmp    $0xffff,%rax
je     122a <main+0xaa>
mov    0x24(%rsp,%rax,4),%edx
mov    %edx,%ecx
cmp    %ebx,%edx
jl     1200 <main+0x80>
mov    %ebx,%ecx
cmp    %ebp,%edx
cmovg  %edx,%ebp
mov    0x28(%rsp,%rax,4),%esi
cmovg  %ebx,%ecx
mov    %esi,%edx
cmp    %ecx,%esi
jl     1214 <main+0x94>
mov    %ecx,%edx
cmp    %ebp,%esi
cmovg  %esi,%ebp
cmovg  %ecx,%edx
mov    0x2c(%rsp,%rax,4),%ecx
mov    %ecx,%ebx
cmp    %edx,%ecx
jl     11e0 <main+0x60>
mov    %edx,%ebx
jmp    11e0 <main+0x60>
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x10000,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1090 <PeterSort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2d87(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x18(%rsp)
lea    0xd99(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sdl 0x20(%rsp,%r15,4),%xmm0
mov    %rbx,%rdi
call   1070 <printf@plt>
add    $0x1,%r15
cmp    $0x10000,%r15
jne    1280 <main+0x100>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd39(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1070 <printf@plt>
lea    0xd58(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1070 <printf@plt>
lea    0xd67(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x40028,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [49 x i8] c"Time taken to perform the sort is %.2lf seconds\0A\00"
@.str.6 = [33 x i8] c"And the clock ticked %ld times.\0A\00"
@.str.7 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [65536 x i32]
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %3
%11 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %8
store i64 0, i64* %3
br label %12
12: ; preds = %20, %0
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 65536
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32*, i32** %8
%17 = load i64, i64* %3
%18 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 %17
%19 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %18)
br label %20
20: ; preds = %15
%21 = load i64, i64* %3
%22 = add nsw i64 %21, 1
store i64 %22, i64* %3
br label %12
23: ; preds = %12
%24 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %24
store i32 %25, i32* %9
%26 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %26
store i32 %27, i32* %10
store i64 0, i64* %4
br label %28
28: ; preds = %53, %23
%29 = load i64, i64* %4
%30 = icmp slt i64 %29, 65536
br i1 %30, label %31, label %56
31: ; preds = %28
%32 = load i64, i64* %4
%33 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %9
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i64, i64* %4
%39 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
store i32 %40, i32* %9
br label %52
41: ; preds = %31
%42 = load i64, i64* %4
%43 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = load i64, i64* %4
%49 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
store i32 %50, i32* %10
br label %51
51: ; preds = %47, %41
br label %52
52: ; preds = %51, %37
br label %53
53: ; preds = %52
%54 = load i64, i64* %4
%55 = add nsw i64 %54, 1
store i64 %55, i64* %4
br label %28
56: ; preds = %28
%57 = call double (...) @clock()
store double %57, double* %6
%58 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 0
%59 = load i32, i32* %10
%60 = load i32, i32* %9
%61 = call i32 @PeterSort(i32* %58, i32 65536, i32 %59, i32 %60)
%62 = call double (...) @clock()
store double %62, double* %7
%63 = load double, double* %7
%64 = load double, double* %6
%65 = fsub double %63, %64
%66 = load double, double* @CLOCKS_PER_SEC
%67 = fdiv double %65, %66
store double %67, double* %5
store i64 0, i64* %3
br label %68
68: ; preds = %77, %56
%69 = load i64, i64* %3
%70 = icmp slt i64 %69, 65536
br i1 %70, label %71, label %80
71: ; preds = %68
%72 = load i64, i64* %3
%73 = getelementptr inbounds [65536 x i32], [65536 x i32]* %2, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = sitofp i32 %74 to double
%76 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %75)
br label %77
77: ; preds = %71
%78 = load i64, i64* %3
%79 = add nsw i64 %78, 1
store i64 %79, i64* %3
br label %68
80: ; preds = %68
%81 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%82 = load i32*, i32** %8
%83 = call i32 @fclose(i32* %82)
%84 = load double, double* %5
%85 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), double %84)
%86 = load double, double* %7
%87 = load double, double* %6
%88 = fsub double %86, %87
%89 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), double %88)
%90 = 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 = [6 x i8] c"file1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.3 = [4 x i8] c"%d \00"
@.str.5 = [49 x i8] c"Time taken to perform the sort is %.2lf seconds\0A\00"
@.str.6 = [33 x i8] c"And the clock ticked %ld times.\0A\00"
@.str.7 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca [65536 x i32]
%2 = bitcast [65536 x i32]* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %8, %4 ]
%6 = getelementptr inbounds [65536 x i32], [65536 x i32]* %1, i64 0, i64 %5
%7 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%8 = add nuw nsw i64 %5, 1
%9 = icmp eq i64 %8, 65536
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = getelementptr inbounds [65536 x i32], [65536 x i32]* %1, i64 0, i64 0
%12 = load i32, i32* %11
br label %13
13: ; preds = %13, %10
%14 = phi i64 [ 1, %10 ], [ %40, %13 ]
%15 = phi i32 [ %12, %10 ], [ %39, %13 ]
%16 = phi i32 [ %12, %10 ], [ %38, %13 ]
%17 = getelementptr inbounds [65536 x i32], [65536 x i32]* %1, i64 0, i64 %14
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, %16
%20 = icmp slt i32 %18, %15
%21 = select i1 %20, i32 %18, i32 %15
%22 = select i1 %19, i32 %18, i32 %16
%23 = select i1 %19, i32 %15, i32 %21
%24 = add nuw nsw i64 %14, 1
%25 = getelementptr inbounds [65536 x i32], [65536 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp sgt i32 %26, %22
%28 = icmp slt i32 %26, %23
%29 = select i1 %28, i32 %26, i32 %23
%30 = select i1 %27, i32 %26, i32 %22
%31 = select i1 %27, i32 %23, i32 %29
%32 = add nuw nsw i64 %14, 2
%33 = getelementptr inbounds [65536 x i32], [65536 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp sgt i32 %34, %30
%36 = icmp slt i32 %34, %31
%37 = select i1 %36, i32 %34, i32 %31
%38 = select i1 %35, i32 %34, i32 %30
%39 = select i1 %35, i32 %31, i32 %37
%40 = add nuw nsw i64 %14, 3
%41 = icmp eq i64 %40, 65536
br i1 %41, label %42, label %13
42: ; preds = %13
%43 = call double (...) @clock()
%44 = call i32 @PeterSort(i32* %11, i32 65536, i32 %39, i32 %38)
%45 = call double (...) @clock()
%46 = load double, double* @CLOCKS_PER_SEC
br label %47
47: ; preds = %42, %47
%48 = phi i64 [ 0, %42 ], [ %53, %47 ]
%49 = getelementptr inbounds [65536 x i32], [65536 x i32]* %1, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = sitofp i32 %50 to double
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %51)
%53 = add nuw nsw i64 %48, 1
%54 = icmp eq i64 %53, 65536
br i1 %54, label %55, label %47
55: ; preds = %47
%56 = fsub double %45, %43
%57 = fdiv double %56, %46
%58 = call i32 @putchar(i32 10)
%59 = call i32 @fclose(i32* %3)
%60 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), double %57)
%61 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), double %56)
%62 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}