#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stderr;
int main() {
  int i;
  char *s;
  char buffer[10];
  printf("Enter the name of the file.");
  scanf("%s", s);
  FILE *input = fopen("README.txt", "r");
  if (input == NULL) {
    fprintf(stderr, "Can't open file %s\n", s);
  } else {
    int i;
    while (fgets(buffer, 10, input) != NULL) {
      printf("%s", buffer);
    }
    if (ferror(input)) {
      perror("Error with the file.");
    }
    fclose(input);
  }
  printf("--MAP EXIT: \n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1080 <scanf@plt>
lea    0xe6b(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ed <main+0x6d>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe49(%rip),%rsi
call   1070 <fprintf@plt>
jmp    124d <main+0xcd>
jmp    11f2 <main+0x72>
lea    -0x1a(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0xa,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1225 <main+0xa5>
lea    -0x1a(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f2 <main+0x72>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1244 <main+0xc4>
lea    0xe01(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6e(%rip),%rdi
call   1090 <scanf@plt>
lea    0xe65(%rip),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1239 <main+0xa9>
mov    %rax,%r15
lea    0x6(%rsp),%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1222 <main+0x92>
lea    0xe30(%rip),%r14
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1200 <main+0x70>
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1266 <main+0xd6>
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    124e <main+0xbe>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd3(%rip),%rdi
call   10b0 <perror@plt>
jmp    122f <main+0x9f>

LLVM IR (-O0):
@.str = [28 x i8] c"Enter the name of the file.\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"README.txt\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [20 x i8] c"Can't open file %s\0A\00"
@.str.5 = [21 x i8] c"Error with the file.\00"
@.str.6 = [14 x i8] c"--MAP EXIT: \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %35
17: ; preds = %0
br label %18
18: ; preds = %23, %17
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32* @fgets(i8* %19, i32 10, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %18
26: ; preds = %18
%27 = load i32*, i32** %5
%28 = call i64 @ferror(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %13
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter the name of the file.\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"README.txt\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [20 x i8] c"Can't open file %s\0A\00"
@.str.5 = [21 x i8] c"Error with the file.\00"
@str = [13 x i8] c"--MAP EXIT: \00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* undef)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32* @fgets(i8* %2, i32 10, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %17, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* undef)
br label %24
13: ; preds = %7, %13
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = call i32* @fgets(i8* %2, i32 10, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %7
%18 = call i64 @ferror(i32* %5)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = call i32 @fclose(i32* %5)
br label %24
24: ; preds = %22, %10
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret i32 0
}