#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ input_line(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void file_input(char *filename) {
  FILE *input_file = fopen(filename, "r");
  if (!input_file) {
    fprintf(stderr, "%s: ", filename);
    perror("Error opening source file");
    exit(1);
  }
  while (input_line(input_file, filename))
    ;
  fclose(input_file);
}


x86 assembly (clang, -O0):
<file_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ba <file_input+0x5a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11bf <file_input+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <input_line@plt>
cmp    $0x0,%rax
je     11db <file_input+0x7b>
jmp    11bf <file_input+0x5f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_input>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119f <file_input+0x3f>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <input_line@plt>
test   %rax,%rax
jne    1180 <file_input+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"%s: \00"
@.str.2 = [26 x i8] c"Error opening source file\00"
define void @file_input(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
br label %15
15: ; preds = %20, %14
%16 = load i32*, i32** %3
%17 = load i8*, i8** %2
%18 = call i64 @input_line(i32* %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %15
21: ; preds = %15
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"%s: \00"
@.str.2 = [26 x i8] c"Error opening source file\00"
define void @file_input(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1, %9
%10 = tail call i64 @input_line(i32* %2, i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %9
12: ; preds = %9
%13 = tail call i32 @fclose(i32* %2)
ret void
}