#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stderr;
void insert_file(char *filename) {
  FILE *file;
  int c;
  file = fopen(filename, "r");
  if (file == NULL) {
    fprintf(stderr, "Could not find %s.\n", filename);
    exit(1);
  }
  printf("\n");
  while ((c = getc(file)) != EOF) {
    putchar(c);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<insert_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <insert_file+0x4e>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%eax
je     11f2 <insert_file+0x82>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    11ca <insert_file+0x5a>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c3 <insert_file+0x63>
mov    %rax,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    0x2e54(%rip),%r14
cmp    (%r14),%eax
je     11b4 <insert_file+0x54>
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r14),%eax
jne    11a0 <insert_file+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Could not find %s.\0A\00"
@EOF = global i32 0
define void @insert_file(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 %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 @putchar(i32 10)
%10 = tail call i32 @getc(i32* %2)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %19, label %13
13: ; preds = %8, %13
%14 = phi i32 [ %16, %13 ], [ %10, %8 ]
%15 = tail call i32 @putchar(i32 %14)
%16 = tail call i32 @getc(i32* %2)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %13
19: ; preds = %13, %8
%20 = tail call i32 @fclose(i32* %2)
ret void
}