#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*/ clrscr();
int /*<<< orphan*/ createHighScores();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gotoxy(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ waitForAnyKey();
void displayHighScores(void) {
  FILE *fp;
  char str[128];
  int y = 5;
  clrscr();
  if ((fp = fopen("highscores.txt", "r")) == NULL) {
    createHighScores();
    if ((fp = fopen("highscores.txt", "r")) == NULL)
      exit(1);
  }
  gotoxy(10, y++);
  printf("High Scores");
  gotoxy(10, y++);
  printf("Rank\tScore\t\t\tName");
  while (!feof(fp)) {
    gotoxy(10, y++);
    if (fgets(str, 126, fp))
      printf("%s", str);
  }
  fclose(fp);
  gotoxy(10, y++);
  printf("Press any key to continue...");
  waitForAnyKey();
  return;
}


x86 assembly (clang, -O0):
<displayHighScores>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x5,-0x94(%rbp)
mov    $0x0,%al
call   1030 <clrscr@plt>
lea    0xe3d(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1214 <displayHighScores+0x74>
mov    $0x0,%al
call   1090 <createHighScores@plt>
lea    0xe15(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    120f <displayHighScores+0x6f>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1214 <displayHighScores+0x74>
mov    -0x94(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    $0xa,%edi
call   10a0 <gotoxy@plt>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x94(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    $0xa,%edi
call   10a0 <gotoxy@plt>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1284 <displayHighScores+0xe4>
jmp    12d8 <displayHighScores+0x138>
mov    -0x94(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    $0xa,%edi
call   10a0 <gotoxy@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x7e,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12d3 <displayHighScores+0x133>
lea    -0x90(%rbp),%rsi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1266 <displayHighScores+0xc6>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x94(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    $0xa,%edi
call   10a0 <gotoxy@plt>
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <waitForAnyKey@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displayHighScores>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
xor    %eax,%eax
call   1030 <clrscr@plt>
lea    0xe45(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f5 <displayHighScores+0x55>
xor    %eax,%eax
call   1090 <createHighScores@plt>
lea    0xe23(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12cf <displayHighScores+0x12f>
mov    $0xa,%edi
mov    $0x5,%esi
call   10a0 <gotoxy@plt>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
mov    $0x6,%esi
call   10a0 <gotoxy@plt>
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
mov    $0x7,%ebp
test   %eax,%eax
je     1277 <displayHighScores+0xd7>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0xa,%edi
mov    %ebp,%esi
call   10a0 <gotoxy@plt>
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <waitForAnyKey@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x7,%ebp
mov    %rsp,%r14
lea    0xda9(%rip),%r15
jmp    129f <displayHighScores+0xff>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
add    $0x1,%ebp
test   %eax,%eax
jne    1240 <displayHighScores+0xa0>
mov    $0xa,%edi
mov    %ebp,%esi
call   10a0 <gotoxy@plt>
mov    %r14,%rdi
mov    $0x7e,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1290 <displayHighScores+0xf0>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1290 <displayHighScores+0xf0>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"highscores.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"High Scores\00"
@.str.3 = [18 x i8] c"Rank\09Score\09\09\09Name\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [29 x i8] c"Press any key to continue...\00"
define void @displayHighScores() {
%1 = alloca i32*
%2 = alloca [128 x i8]
%3 = alloca i32
store i32 5, i32* %3
%4 = call i32 (...) @clrscr()
%5 = 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))
store i32* %5, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = call i32 (...) @createHighScores()
%9 = 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))
store i32* %9, i32** %1
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %7
br label %14
14: ; preds = %13, %0
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = call i32 @gotoxy(i32 10, i32 %15)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
%21 = call i32 @gotoxy(i32 10, i32 %19)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %39, %14
%24 = load i32*, i32** %1
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %40
28: ; preds = %23
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
%31 = call i32 @gotoxy(i32 10, i32 %29)
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%33 = load i32*, i32** %1
%34 = call i64 @fgets(i8* %32, i32 126, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %28
br label %23
40: ; preds = %23
%41 = load i32*, i32** %1
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
%45 = call i32 @gotoxy(i32 10, i32 %43)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 (...) @waitForAnyKey()
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"highscores.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"High Scores\00"
@.str.3 = [18 x i8] c"Rank\09Score\09\09\09Name\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [29 x i8] c"Press any key to continue...\00"
define void @displayHighScores() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @clrscr()
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = tail call i32 (...) @createHighScores()
%8 = 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))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6, %0
%13 = phi i32* [ %8, %6 ], [ %4, %0 ]
%14 = tail call i32 @gotoxy(i32 10, i32 5)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @gotoxy(i32 10, i32 6)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @feof(i32* %13)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %12, %28
%21 = phi i32 [ %22, %28 ], [ 7, %12 ]
%22 = add nuw nsw i32 %21, 1
%23 = call i32 @gotoxy(i32 10, i32 %21)
%24 = call i64 @fgets(i8* %2, i32 126, i32* %13)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %28
28: ; preds = %26, %20
%29 = call i32 @feof(i32* %13)
%30 = icmp eq i32 %29, 0
br i1 %30, label %20, label %31
31: ; preds = %28, %12
%32 = phi i32 [ 7, %12 ], [ %22, %28 ]
%33 = call i32 @fclose(i32* %13)
%34 = call i32 @gotoxy(i32 10, i32 %32)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 (...) @waitForAnyKey()
ret void
}