#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *,
                           char const *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int main(int argc, char *argv[]) {
  FILE *fp;
  const char *input_file = "/etc/fstab";
  int c;
  if ((fp = fopen(input_file, "r")) == NULL) {
    fprintf(stderr, "Err(%d) - %s: %s\n", errno, strerror(errno), input_file);
    exit(EXIT_FAILURE);
  }
  while ((c = getc(fp)) != EOF) {
    putc(c, stdout);
  }
  fclose(fp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fc <main+0x8c>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    %rax,%rcx
mov    -0x20(%rbp),%r8
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1201 <main+0x91>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
je     1232 <main+0xc2>
mov    -0x24(%rbp),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1040 <putc@plt>
jmp    1201 <main+0x91>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe85(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11dd <main+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <getc@plt>
mov    0x2e4a(%rip),%r14
cmp    (%r14),%eax
je     11c7 <main+0x57>
mov    0x2e16(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
mov    %eax,%edi
call   1040 <putc@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r14),%eax
jne    11b0 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df4(%rip),%rax
mov    (%rax),%ebx
mov    0x2de3(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe10(%rip),%rsi
lea    0xdfc(%rip),%r8
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/etc/fstab\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Err(%d) - %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %7
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = load i8*, i8** %7
%18 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %16, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %27, %21
%23 = load i32*, i32** %6
%24 = call i32 @getc(i32* %23)
store i32 %24, i32* %8
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* %8
%29 = load i32, i32* @stdout
%30 = call i32 @putc(i32 %28, i32 %29)
br label %22
31: ; preds = %22
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}

LLVM IR (-O2):
@.str = [11 x i8] c"/etc/fstab\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Err(%d) - %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @getc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %23, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %11, i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %5, %16
%17 = phi i32 [ %20, %16 ], [ %6, %5 ]
%18 = load i32, i32* @stdout
%19 = tail call i32 @putc(i32 %17, i32 %18)
%20 = tail call i32 @getc(i32* %3)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %16
23: ; preds = %16, %5
%24 = tail call i32 @fclose(i32* %3)
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}