#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*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char filename[30];
  scanf("%s", filename);
  FILE *f;
  f = fopen(filename, "r");
  if (f == NULL) {
    printf("ERROR\n");
    return 1;
  }
  char line[100];
  while (fgets(line, 100, f) != NULL)
    printf("%s", line);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ab <main+0x5b>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <main+0xa9>
jmp    11b0 <main+0x60>
lea    -0xa0(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e9 <main+0x99>
lea    -0xa0(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b0 <main+0x60>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
lea    0xe8d(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ee <main+0x8e>
mov    %rax,%r15
lea    0x20(%rsp),%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e2 <main+0x82>
lea    0xe4d(%rip),%r14
lea    0x20(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11ff <main+0x9f>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"ERROR\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i32*
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %25
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32* @fgets(i8* %15, i32 100, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %1
br label %25
25: ; preds = %22, %11
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"r\00"
@str = [6 x i8] c"ERROR\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = call i32* @fopen(i8* %3, 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 %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %19
9: ; preds = %0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32* @fgets(i8* %10, i32 100, i32* %5)
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9, %13
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%15 = call i32* @fgets(i8* %10, i32 100, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %9
%18 = call i32 @fclose(i32* %5)
br label %19
19: ; preds = %17, %7
%20 = phi i32 [ 1, %7 ], [ 0, %17 ]
ret i32 %20
}