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

/* Variables and functions */
scalar_t__ EOF;
double clock();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort(int *, int);
int main(int argc, char **argv) {
  clock_t begin, end1, end2;
  FILE *source = fopen(argv[1], "r");
  int i = 0;
  int a[100000];
  int x;
  if (source == NULL) {
    printf("Error\n");
    exit(1);
  }
  while (fscanf(source, "%i", &x) != EOF) {
    a[i] = x;
    i++;
  }
  begin = clock();
  int n = sizeof(a) / sizeof(int);
  sort(a, n);
  end1 = clock();
  FILE *target = fopen("output.txt", "w");
  if (target == NULL) {
    printf("Error\n");
    exit(1);
  }
  for (i = 0; i < n; i++) {
    fprintf(target, "%d,\t", a[i]);
  }
  end2 = clock();
  printf("Time taken for the Insertion Sorting is:\t%1.1f\n",
         (double)end1 - begin);
  printf("Time taken for sorting + file writing is:\t%1.2f\n",
         (double)end2 - begin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61ad0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11cb <main+0x5b>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11d0 <main+0x60>
mov    -0x30(%rbp),%rdi
lea    0xe2e(%rip),%rsi
lea    -0x61ac4(%rbp),%rdx
call   1060 <fscanf@plt>
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
je     1216 <main+0xa6>
mov    -0x61ac4(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x61ac0(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d0 <main+0x60>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x186a0,-0x61ac8(%rbp)
lea    -0x61ac0(%rbp),%rdi
mov    -0x61ac8(%rbp),%esi
call   1050 <sort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xdbb(%rip),%rdi
lea    0xdbf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x61ad0(%rbp)
cmpq   $0x0,-0x61ad0(%rbp)
jne    128a <main+0x11a>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x61ac8(%rbp),%eax
jge    12cc <main+0x15c>
mov    -0x61ad0(%rbp),%rdi
movslq -0x34(%rbp),%rax
mov    -0x61ac0(%rbp,%rax,4),%edx
lea    0xd60(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1291 <main+0x121>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
lea    0xd35(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
lea    0xd4d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x61ad0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61aa0,%rsp
mov    0x8(%rsi),%rdi
lea    0xedf(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c0 <main+0x140>
mov    %rax,%r13
lea    0xe4d(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1070 <fscanf@plt>
mov    0x2e21(%rip),%r12
cmp    (%r12),%rax
je     11fe <main+0x7e>
lea    0x20(%rsp),%rbx
lea    0xe27(%rip),%r14
lea    0x4(%rsp),%r15
xchg   %ax,%ax
mov    0x4(%rsp),%eax
mov    %eax,(%rbx)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <fscanf@plt>
add    $0x4,%rbx
cmp    (%r12),%rax
jne    11e0 <main+0x60>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x186a0,%esi
call   1060 <sort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x18(%rsp)
lea    0xdd5(%rip),%rdi
lea    0xdd9(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c0 <main+0x140>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xdc1(%rip),%r14
nop
mov    0x20(%rsp,%rbx,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x186a0,%rbx
jne    1250 <main+0xd0>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
lea    0xd89(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
lea    0xd9f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"Error\0A\00"
@.str.2 = [3 x i8] c"%i\00"
@EOF = global i64 0
@.str.3 = [11 x i8] c"output.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%d,\09\00"
@.str.6 = [48 x i8] c"Time taken for the Insertion Sorting is:\09%1.1f\0A\00"
@.str.7 = [49 x i8] c"Time taken for sorting + file writing is:\09%1.2f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [100000 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %9
store i32 0, i32* %10
%19 = load i32*, i32** %9
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
br label %25
25: ; preds = %30, %24
%26 = load i32*, i32** %9
%27 = call i64 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%28 = load i64, i64* @EOF
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = load i32, i32* %12
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100000 x i32], [100000 x i32]* %11, i64 0, i64 %33
store i32 %31, i32* %34
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %25
37: ; preds = %25
%38 = call double (...) @clock()
store double %38, double* %6
store i32 100000, i32* %13
%39 = getelementptr inbounds [100000 x i32], [100000 x i32]* %11, i64 0, i64 0
%40 = load i32, i32* %13
%41 = call i32 @sort(i32* %39, i32 %40)
%42 = call double (...) @clock()
store double %42, double* %7
%43 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %43, i32** %14
%44 = load i32*, i32** %14
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %49
46: ; preds = %37
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %37
store i32 0, i32* %10
br label %50
50: ; preds = %61, %49
%51 = load i32, i32* %10
%52 = load i32, i32* %13
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %64
54: ; preds = %50
%55 = load i32*, i32** %14
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [100000 x i32], [100000 x i32]* %11, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %54
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %50
64: ; preds = %50
%65 = call double (...) @clock()
store double %65, double* %8
%66 = load double, double* %7
%67 = load double, double* %6
%68 = fsub double %66, %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), double %68)
%70 = load double, double* %8
%71 = load double, double* %6
%72 = fsub double %70, %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), double %72)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%i\00"
@EOF = global i64 0
@.str.3 = [11 x i8] c"output.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%d,\09\00"
@.str.6 = [48 x i8] c"Time taken for the Insertion Sorting is:\09%1.1f\0A\00"
@.str.7 = [49 x i8] c"Time taken for sorting + file writing is:\09%1.2f\0A\00"
@str.8 = [6 x i8] c"Error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100000 x i32]
%4 = alloca i32
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = bitcast [100000 x i32]* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = icmp eq i32* %7, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %26, label %18
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %18
%19 = phi i64 [ %22, %18 ], [ 0, %11 ]
%20 = load i32, i32* %4
%21 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 %19
store i32 %20, i32* %21
%22 = add nuw i64 %19, 1
%23 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %18
26: ; preds = %18, %11
%27 = call double (...) @clock()
%28 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 0
%29 = call i32 @sort(i32* %28, i32 100000)
%30 = call double (...) @clock()
%31 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26, %36
%37 = phi i64 [ %41, %36 ], [ 0, %26 ]
%38 = getelementptr inbounds [100000 x i32], [100000 x i32]* %3, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = add nuw nsw i64 %37, 1
%42 = icmp eq i64 %41, 100000
br i1 %42, label %43, label %36
43: ; preds = %36
%44 = call double (...) @clock()
%45 = fsub double %30, %27
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), double %45)
%47 = fsub double %44, %27
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), double %47)
ret i32 0
}