#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char ch, file_name[25];
  FILE *fp;
  printf("What file do you want to see yo?\n");
  gets(file_name);
  fp = fopen(file_name, "r");
  if (fp == NULL) {
    perror("This file produced an error yo!.\n");
    exit(EXIT_FAILURE);
  }
  printf("The contents of %s file are yo!:\n", file_name);
  while ((ch = fgetc(fp)) != EOF)
    printf("%c", ch);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cf <main+0x5f>
lea    0xe68(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x20(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2df1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1219 <main+0xa9>
movsbl -0x5(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e1 <main+0x71>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <gets@plt>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1217 <main+0x87>
mov    %rax,%rbx
lea    0xe58(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    0x2e03(%rip),%r14
cmp    (%r14),%al
je     1205 <main+0x75>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%al
jne    11f0 <main+0x60>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde4(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"What file do you want to see yo?\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"This file produced an error yo!.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [34 x i8] c"The contents of %s file are yo!:\0A\00"
@EOF = global i8 0
@.str.4 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [25 x i8]
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %26, %16
%20 = load i32*, i32** %4
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %2
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i8, i8* %2
%28 = sext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %19
30: ; preds = %19
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"This file produced an error yo!.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [34 x i8] c"The contents of %s file are yo!:\0A\00"
@EOF = global i8 0
@str = [33 x i8] c"What file do you want to see yo?\00"
define i32 @main() {
%1 = alloca [25 x i8]
%2 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = call signext i8 @fgetc(i32* %5)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %23, label %16
16: ; preds = %11, %16
%17 = phi i8 [ %20, %16 ], [ %13, %11 ]
%18 = sext i8 %17 to i32
%19 = call i32 @putchar(i32 %18)
%20 = call signext i8 @fgetc(i32* %5)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %23, label %16
23: ; preds = %16, %11
%24 = call i32 @fclose(i32* %5)
ret i32 0
}