#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ selectionSortInt(int *, int);
int /*<<< orphan*/ selectionSortReverseInt(int *, int);
int /*<<< orphan*/ testReverseSortedInts(int *, int);
int /*<<< orphan*/ testSortedInts(int *, int);
int main(void) {
  char *filename = "randomInts.txt";
  int values[10000];
  FILE *myfile = fopen(filename, "r");
  if (myfile == NULL) {
    perror("Error opening file");
  } else {
    for (int i = 0; i < 10000; ++i) {
      fscanf(myfile, "%d", &values[i]);
    }
    fclose(myfile);
    selectionSortInt(values, 10000);
    testSortedInts(values, 10000);
    selectionSortReverseInt(values, 10000);
    testReverseSortedInts(values, 10000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x9c58(%rbp)
cmpq   $0x0,-0x9c58(%rbp)
jne    11d3 <main+0x53>
lea    0xe48(%rip),%rdi
call   1090 <perror@plt>
jmp    1279 <main+0xf9>
movl   $0x0,-0x9c5c(%rbp)
cmpl   $0x2710,-0x9c5c(%rbp)
jge    1229 <main+0xa9>
mov    -0x9c58(%rbp),%rdi
movslq -0x9c5c(%rbp),%rax
lea    -0x9c50(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe14(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x9c5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c5c(%rbp)
jmp    11dd <main+0x5d>
mov    -0x9c58(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   1070 <selectionSortInt@plt>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   1060 <testSortedInts@plt>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   10a0 <selectionSortReverseInt@plt>
lea    -0x9c50(%rbp),%rdi
mov    $0x2710,%esi
call   1030 <testReverseSortedInts@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x9c40,%rsp
lea    0xe6d(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     121a <main+0x9a>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe74(%rip),%r14
lea    (%rsp,%rbx,1),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
add    $0x4,%rbx
cmp    $0x9c40,%rbx
jne    11b0 <main+0x30>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1070 <selectionSortInt@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1060 <testSortedInts@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
call   10a0 <selectionSortReverseInt@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1030 <testReverseSortedInts@plt>
xor    %eax,%eax
add    $0x9c40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf0(%rip),%rdi
call   1090 <perror@plt>
jmp    120b <main+0x8b>

LLVM IR (-O0):
@.str = [15 x i8] c"randomInts.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [10000 x i32]
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %36
12: ; preds = %0
store i32 0, i32* %5
br label %13
13: ; preds = %22, %12
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 10000
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %19
%21 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %16
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %13
25: ; preds = %13
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
%28 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%29 = call i32 @selectionSortInt(i32* %28, i32 10000)
%30 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%31 = call i32 @testSortedInts(i32* %30, i32 10000)
%32 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%33 = call i32 @selectionSortReverseInt(i32* %32, i32 10000)
%34 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 0
%35 = call i32 @testReverseSortedInts(i32* %34, i32 10000)
br label %36
36: ; preds = %25, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"randomInts.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [10000 x i32]
%2 = bitcast [10000 x i32]* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %20
7: ; preds = %14
%8 = call i32 @fclose(i32* %3)
%9 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 0
%10 = call i32 @selectionSortInt(i32* %9, i32 10000)
%11 = call i32 @testSortedInts(i32* %9, i32 10000)
%12 = call i32 @selectionSortReverseInt(i32* %9, i32 10000)
%13 = call i32 @testReverseSortedInts(i32* %9, i32 10000)
br label %20
14: ; preds = %0, %14
%15 = phi i64 [ %18, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %15
%17 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%18 = add nuw nsw i64 %15, 1
%19 = icmp eq i64 %18, 10000
br i1 %19, label %7, label %14
20: ; preds = %7, %5
ret i32 0
}