#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void credits() {
  char ch;
  FILE *fp = fopen("credits.txt", "r");
  if (fp == NULL)
    perror("fopen failed");
  else {
    while ((ch = fgetc(fp)) != EOF) {
      printf("%c", ch);
    }
  }
  fclose(fp);
  printf("Press any key to go back");
  getch();
}


x86 assembly (clang, -O0):
<credits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <credits+0x3b>
lea    0xe7d(%rip),%rdi
call   1080 <perror@plt>
jmp    11dd <credits+0x7d>
jmp    11a0 <credits+0x40>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2e32(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d8 <credits+0x78>
movsbl -0x1(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a0 <credits+0x40>
jmp    11dd <credits+0x7d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getch@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<credits>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e9 <credits+0x79>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e4a(%rip),%r14
cmp    (%r14),%al
je     11c5 <credits+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
jne    11b0 <credits+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <getch@plt>
lea    0xe1e(%rip),%rdi
call   1090 <perror@plt>
jmp    11c5 <credits+0x55>

LLVM IR (-O0):
@.str = [12 x i8] c"credits.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [25 x i8] c"Press any key to go back\00"
define void @credits() {
%1 = alloca i8
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %21
8: ; preds = %0
br label %9
9: ; preds = %16, %8
%10 = load i32*, i32** %2
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %1
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %9
20: ; preds = %9
br label %21
21: ; preds = %20, %6
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 (...) @getch()
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"credits.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@EOF = global i8 0
@.str.4 = [25 x i8] c"Press any key to go back\00"
define void @credits() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %16, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %16
9: ; preds = %3, %9
%10 = phi i8 [ %13, %9 ], [ %4, %3 ]
%11 = sext i8 %10 to i32
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call signext i8 @fgetc(i32* %1)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %9
16: ; preds = %9, %3, %7
%17 = tail call i32 @fclose(i32* %1)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 (...) @getch()
ret void
}