#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*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  int ch;
  if ((fp = fopen(argv[1], "r")) == NULL) {
    printf("File Open error!!\n");
    exit(-1);
  }
  while (!feof(fp)) {
    ch = fgetc(fp);
    fputc(ch, stdout);
    if (ferror(fp)) {
      printf("Error detected!!\n");
      clearerr(fp);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11de <main+0x4e>
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    11e3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1201 <main+0x71>
jmp    124b <main+0xbb>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1246 <main+0xb6>
lea    0xddd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <clearerr@plt>
jmp    11e3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
lea    0xe60(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     121d <main+0x8d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11c9 <main+0x39>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e10(%rip),%r15
lea    0xe2b(%rip),%r14
jmp    11ec <main+0x5c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11b9 <main+0x29>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    (%r15),%esi
mov    %eax,%edi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11e0 <main+0x50>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1090 <clearerr@plt>
jmp    11e0 <main+0x50>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"File Open error!!\0A\00"
@stdout = global i32 0
@.str.2 = [18 x i8] c"Error detected!!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %35, %16
%18 = load i32*, i32** %6
%19 = call i32 @feof(i32* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = load i32*, i32** %6
%24 = call i32 @fgetc(i32* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = load i32, i32* @stdout
%27 = call i32 @fputc(i32 %25, i32 %26)
%28 = load i32*, i32** %6
%29 = call i64 @ferror(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32*, i32** %6
%34 = call i32 @clearerr(i32* %33)
br label %35
35: ; preds = %31, %22
br label %17
36: ; preds = %17
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
@str = [17 x i8] c"Error detected!!\00"
@str.3 = [18 x i8] c"File Open error!!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %25
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %7, %22
%14 = tail call i32 @fgetc(i32* %5)
%15 = load i32, i32* @stdout
%16 = tail call i32 @fputc(i32 %14, i32 %15)
%17 = tail call i64 @ferror(i32* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @clearerr(i32* %5)
br label %22
22: ; preds = %19, %13
%23 = tail call i32 @feof(i32* %5)
%24 = icmp eq i32 %23, 0
br i1 %24, label %13, label %25
25: ; preds = %22, %7
%26 = tail call i32 @fclose(i32* %5)
ret i32 0
}