#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  FILE *myfile;
  char buffer[255 + 1];
  if (argc < 2) {
    puts("Missing filename!");
    printf("Here is the format %c\n", 25);
    puts("VIEW filename");
    exit(1);
  }
  if (!(myfile = fopen(argv[1], "r"))) {
    printf("Error opening \"%s\"\n", argv[1]);
    exit(1);
  }
  while (fgets(buffer, 255, myfile))
    printf("%s", buffer);
  fclose(myfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b8 <main+0x58>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7c(%rip),%rdi
mov    $0x19,%esi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fa <main+0x9a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ff <main+0x9f>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1238 <main+0xd8>
lea    -0x120(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ff <main+0x9f>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
cmp    $0x1,%edi
jle    11e9 <main+0x89>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeb8(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121e <main+0xbe>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d2 <main+0x72>
lea    0xea1(%rip),%r14
mov    %rsp,%rbx
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
lea    0xe16(%rip),%rdi
mov    $0x19,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Missing filename!\00"
@.str.1 = [23 x i8] c"Here is the format %c\0A\00"
@.str.2 = [14 x i8] c"VIEW filename\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [20 x i8] c"Error opening \22%s\22\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 25)
%13 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %15
br label %28
28: ; preds = %33, %27
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i64 @fgets(i8* %29, i32 255, i32* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br label %28
36: ; preds = %28
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Missing filename!\00"
@.str.1 = [23 x i8] c"Here is the format %c\0A\00"
@.str.2 = [14 x i8] c"VIEW filename\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [20 x i8] c"Error opening \22%s\22\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 25)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = call i64 @fgets(i8* %4, i32 255, i32* %14)
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %23
19: ; preds = %11
%20 = load i8*, i8** %12
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %16, %23
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%25 = call i64 @fgets(i8* %4, i32 255, i32* %14)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %23
27: ; preds = %23, %16
%28 = call i32 @fclose(i32* %14)
ret i32 0
}