#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 */
struct empNode {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct empNode *AppendLastToFront(struct empNode *);
struct empNode *InsertInOrder(struct empNode *, int, char *);
int /*<<< orphan*/ PrintList(int /*<<< orphan*/ *, struct empNode *);
struct empNode *ReverseList(struct empNode *);
int Sum(struct empNode *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int main() {
  FILE *fin = fopen("employee_list.in", "r");
  int numEmployees;
  fscanf(fin, "%d", &numEmployees);
  struct empNode *head = NULL;
  int i;
  for (i = 0; i < numEmployees; i++) {
    int points;
    char name[50];
    fscanf(fin, "%s", name);
    fscanf(fin, "%d", &points);
    head = InsertInOrder(head, points, name);
  }
  FILE *fout = fopen("employee_list.out", "w");
  fprintf(fout, "Vice President's List:\n");
  PrintList(fout, head);
  fprintf(fout, "\n");
  head = ReverseList(head);
  head = AppendLastToFront(head);
  fprintf(fout, "President's List:\n");
  PrintList(fout, head);
  fprintf(fout, "\n");
  int sum = Sum(head);
  fprintf(fout, "Total Points Earned:\n%d\n\n", sum);
  fprintf(fout, "Average Points Earned:\n%d\n", sum / numEmployees);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1225 <main+0xa5>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1b(%rip),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
lea    -0x60(%rbp),%rdx
call   1080 <InsertInOrder@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cb <main+0x4b>
lea    0xded(%rip),%rdi
lea    0xdf8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <PrintList@plt>
mov    -0x68(%rbp),%rdi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ReverseList@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <AppendLastToFront@plt>
mov    %rax,-0x20(%rbp)
mov    -0x68(%rbp),%rdi
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <PrintList@plt>
mov    -0x68(%rbp),%rdi
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <Sum@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x6c(%rbp),%edx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x6c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe4b(%rip),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe48(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1243 <main+0xa3>
lea    0x10(%rsp),%r12
lea    0xe26(%rip),%r13
lea    0xc(%rsp),%rbp
xor    %ebx,%ebx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xe0c(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1090 <InsertInOrder@plt>
mov    %rax,%rbx
add    $0x1,%r15d
cmp    0x8(%rsp),%r15d
jl     1200 <main+0x60>
jmp    1245 <main+0xa5>
xor    %ebx,%ebx
lea    0xdcd(%rip),%rdi
lea    0xdd8(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xdcb(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <PrintList@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1070 <ReverseList@plt>
mov    %rax,%rdi
call   10c0 <AppendLastToFront@plt>
mov    %rax,%rbx
lea    0xd8c(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <PrintList@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1060 <Sum@plt>
mov    %eax,%ebx
lea    0xd64(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebx,%eax
cltd
idivl  0x8(%rsp)
lea    0xd64(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.empNode = type { i32 }
@.str = [17 x i8] c"employee_list.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [18 x i8] c"employee_list.out\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [24 x i8] c"Vice President's List:\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [19 x i8] c"President's List:\0A\00"
@.str.9 = [26 x i8] c"Total Points Earned:\0A%d\0A\0A\00"
@.str.10 = [27 x i8] c"Average Points Earned:\0A%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.empNode*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = call i32 (i32*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store %struct.empNode* null, %struct.empNode** %4
store i32 0, i32* %5
br label %13
13: ; preds = %27, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i32*, i32** %2
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%20 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %2
%22 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%23 = load %struct.empNode*, %struct.empNode** %4
%24 = load i32, i32* %6
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%26 = call %struct.empNode* @InsertInOrder(%struct.empNode* %23, i32 %24, i8* %25)
store %struct.empNode* %26, %struct.empNode** %4
br label %27
27: ; preds = %17
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %13
30: ; preds = %13
%31 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %31, i32** %8
%32 = load i32*, i32** %8
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%34 = load i32*, i32** %8
%35 = load %struct.empNode*, %struct.empNode** %4
%36 = call i32 @PrintList(i32* %34, %struct.empNode* %35)
%37 = load i32*, i32** %8
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%39 = load %struct.empNode*, %struct.empNode** %4
%40 = call %struct.empNode* @ReverseList(%struct.empNode* %39)
store %struct.empNode* %40, %struct.empNode** %4
%41 = load %struct.empNode*, %struct.empNode** %4
%42 = call %struct.empNode* @AppendLastToFront(%struct.empNode* %41)
store %struct.empNode* %42, %struct.empNode** %4
%43 = load i32*, i32** %8
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%45 = load i32*, i32** %8
%46 = load %struct.empNode*, %struct.empNode** %4
%47 = call i32 @PrintList(i32* %45, %struct.empNode* %46)
%48 = load i32*, i32** %8
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%50 = load %struct.empNode*, %struct.empNode** %4
%51 = call i32 @Sum(%struct.empNode* %50)
store i32 %51, i32* %9
%52 = load i32*, i32** %8
%53 = load i32, i32* %9
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %53)
%55 = load i32*, i32** %8
%56 = load i32, i32* %9
%57 = load i32, i32* %3
%58 = sdiv i32 %56, %57
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
%struct.empNode = type { i32 }
@.str = [17 x i8] c"employee_list.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [18 x i8] c"employee_list.out\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [24 x i8] c"Vice President's List:\0A\00"
@.str.8 = [19 x i8] c"President's List:\0A\00"
@.str.9 = [26 x i8] c"Total Points Earned:\0A%d\0A\0A\00"
@.str.10 = [27 x i8] c"Average Points Earned:\0A%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
br label %12
12: ; preds = %9, %12
%13 = phi %struct.empNode* [ null, %9 ], [ %18, %12 ]
%14 = phi i32 [ 0, %9 ], [ %19, %12 ]
%15 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%16 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = call %struct.empNode* @InsertInOrder(%struct.empNode* %13, i32 %17, i8* %11)
%19 = add nuw nsw i32 %14, 1
%20 = load i32, i32* %1
%21 = icmp slt i32 %19, %20
br i1 %21, label %12, label %22
22: ; preds = %12, %0
%23 = phi %struct.empNode* [ null, %0 ], [ %18, %12 ]
%24 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i64 23, i64 1, i32* %24)
%26 = call i32 @PrintList(i32* %24, %struct.empNode* %23)
%27 = call i32 @fputc(i32 10, i32* %24)
%28 = call %struct.empNode* @ReverseList(%struct.empNode* %23)
%29 = call %struct.empNode* @AppendLastToFront(%struct.empNode* %28)
%30 = call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i64 18, i64 1, i32* %24)
%31 = call i32 @PrintList(i32* %24, %struct.empNode* %29)
%32 = call i32 @fputc(i32 10, i32* %24)
%33 = call i32 @Sum(%struct.empNode* %29)
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %1
%36 = sdiv i32 %33, %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %36)
ret i32 0
}