#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*/ assign_score(char *, int *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ freeArray(char **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quicksort_strs(char **, int);
char **split(char *, char *, int *);
int return_namescore(char *filename) {
  FILE *file;
  file = fopen(filename, "r");
  if (file == NULL) {
    printf("Error file Not Found! \n");
    return -1;
  }
  char line[50000];
  fgets(line, 50000, file);
  int length = 0;
  char **arrofnames = split(line, "\",\"", &length);
  quicksort_strs(arrofnames, length);
  FILE *file_output;
  file_output = fopen("output.txt", "w");
  int i;
  for (i = 0; i < length; i++) {
    fprintf(file_output, "%s\n", arrofnames[i]);
  }
  int score = 0;
  for (i = 0; i < length; i++) {
    assign_score(arrofnames[i], &score, i + 1);
  }
  freeArray(arrofnames, length);
  return score;
}


x86 assembly (clang, -O0):
<return_namescore>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc390,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <return_namescore+0x46>
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <return_namescore+0x183>
lea    -0xc370(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc350,%esi
call   1050 <fgets@plt>
movl   $0x0,-0xc374(%rbp)
lea    -0xc370(%rbp),%rdi
lea    0xe27(%rip),%rsi
lea    -0xc374(%rbp),%rdx
call   1040 <split@plt>
mov    %rax,-0xc380(%rbp)
mov    -0xc380(%rbp),%rdi
mov    -0xc374(%rbp),%esi
call   1070 <quicksort_strs@plt>
lea    0xdff(%rip),%rdi
lea    0xe03(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xc388(%rbp)
movl   $0x0,-0xc38c(%rbp)
mov    -0xc38c(%rbp),%eax
cmp    -0xc374(%rbp),%eax
jge    1287 <return_namescore+0x107>
mov    -0xc388(%rbp),%rdi
mov    -0xc380(%rbp),%rax
movslq -0xc38c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdbd(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0xc38c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc38c(%rbp)
jmp    123c <return_namescore+0xbc>
movl   $0x0,-0xc390(%rbp)
movl   $0x0,-0xc38c(%rbp)
mov    -0xc38c(%rbp),%eax
cmp    -0xc374(%rbp),%eax
jge    12e8 <return_namescore+0x168>
mov    -0xc380(%rbp),%rax
movslq -0xc38c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0xc38c(%rbp),%edx
add    $0x1,%edx
lea    -0xc390(%rbp),%rsi
call   10a0 <assign_score@plt>
mov    -0xc38c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc38c(%rbp)
jmp    129b <return_namescore+0x11b>
mov    -0xc380(%rbp),%rdi
mov    -0xc374(%rbp),%esi
call   1090 <freeArray@plt>
mov    -0xc390(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc390,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<return_namescore>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc368,%rsp
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     125e <return_namescore+0xde>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc350,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
movl   $0x0,0x8(%rsp)
lea    0xe3b(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <split@plt>
mov    %rax,%r14
mov    0x8(%rsp),%esi
mov    %rax,%rdi
call   1070 <quicksort_strs@plt>
lea    0xe1c(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    1271 <return_namescore+0xf1>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe09(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     1210 <return_namescore+0x90>
movl   $0x0,0xc(%rsp)
test   %esi,%esi
jle    1279 <return_namescore+0xf9>
xor    %ebx,%ebx
lea    0xc(%rsp),%r15
mov    (%r14,%rbx,8),%rdi
add    $0x1,%rbx
mov    %r15,%rsi
mov    %ebx,%edx
call   10a0 <assign_score@plt>
movslq 0x8(%rsp),%rsi
cmp    %rsi,%rbx
jl     1240 <return_namescore+0xc0>
jmp    1279 <return_namescore+0xf9>
lea    0xdb2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1285 <return_namescore+0x105>
movl   $0x0,0xc(%rsp)
mov    %r14,%rdi
call   1090 <freeArray@plt>
mov    0xc(%rsp),%eax
add    $0xc368,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Error file Not Found! \0A\00"
@.str.2 = [4 x i8] c"\22,\22\00"
@.str.3 = [11 x i8] c"output.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @return_namescore(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [50000 x i8]
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
17: ; preds = %1
%18 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32 @fgets(i8* %18, i32 50000, i32* %19)
store i32 0, i32* %6
%21 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 0
%22 = call i8** @split(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %6)
store i8** %22, i8*** %7
%23 = load i8**, i8*** %7
%24 = load i32, i32* %6
%25 = call i32 @quicksort_strs(i8** %23, i32 %24)
%26 = 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* %26, i32** %8
store i32 0, i32* %9
br label %27
27: ; preds = %39, %17
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %42
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = load i8**, i8*** %7
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %31
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %27
42: ; preds = %27
store i32 0, i32* %10
store i32 0, i32* %9
br label %43
43: ; preds = %56, %42
%44 = load i32, i32* %9
%45 = load i32, i32* %6
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %59
47: ; preds = %43
%48 = load i8**, i8*** %7
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
%55 = call i32 @assign_score(i8* %52, i32* %10, i32 %54)
br label %56
56: ; preds = %47
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %43
59: ; preds = %43
%60 = load i8**, i8*** %7
%61 = load i32, i32* %6
%62 = call i32 @freeArray(i8** %60, i32 %61)
%63 = load i32, i32* %10
store i32 %63, i32* %2
br label %64
64: ; preds = %59, %15
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"\22,\22\00"
@.str.3 = [11 x i8] c"output.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@str = [23 x i8] c"Error file Not Found! \00"
define i32 @return_namescore(i8* nocapture %0) {
%2 = alloca [50000 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %48
9: ; preds = %1
%10 = getelementptr inbounds [50000 x i8], [50000 x i8]* %2, i64 0, i64 0
%11 = call i32 @fgets(i8* %10, i32 50000, i32* %5)
%12 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%13 = call i8** @split(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = call i32 @quicksort_strs(i8** %13, i32 %14)
%16 = 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))
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %9
%20 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %43
21: ; preds = %9, %21
%22 = phi i64 [ %26, %21 ], [ 0, %9 ]
%23 = getelementptr inbounds i8*, i8** %13, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = add nuw nsw i64 %22, 1
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %21, label %30
30: ; preds = %21
%31 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%32 = icmp sgt i32 %27, 0
br i1 %32, label %33, label %43
33: ; preds = %30, %33
%34 = phi i64 [ %37, %33 ], [ 0, %30 ]
%35 = getelementptr inbounds i8*, i8** %13, i64 %34
%36 = load i8*, i8** %35
%37 = add nuw nsw i64 %34, 1
%38 = trunc i64 %37 to i32
%39 = call i32 @assign_score(i8* %36, i32* %4, i32 %38)
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %37, %41
br i1 %42, label %33, label %43
43: ; preds = %33, %19, %30
%44 = phi i32 [ %27, %30 ], [ %17, %19 ], [ %40, %33 ]
%45 = bitcast i32* %4 to i8*
%46 = call i32 @freeArray(i8** %13, i32 %44)
%47 = load i32, i32* %4
br label %48
48: ; preds = %43, %7
%49 = phi i32 [ -1, %7 ], [ %47, %43 ]
ret i32 %49
}