#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*/ errquit(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ line_separator();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void echo(char *filename) {
  int c;
  FILE *f = fopen(filename, "r");
  if (!f) {
    char buf[300];
    sprintf(buf, "cannot open file '%s'", filename);
    errquit(buf);
  }
  printf(">>> %s\n", filename);
  while ((c = fgetc(f)) != EOF)
    putchar(c);
  fclose(f);
  line_separator();
}


x86 assembly (clang, -O0):
<echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <echo+0x51>
lea    -0x150(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe42(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x150(%rbp),%rdi
call   1090 <errquit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
je     1209 <echo+0x89>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
jmp    11e1 <echo+0x61>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1070 <line_separator@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo>:
push   %r15
push   %r14
push   %rbx
sub    $0x130,%rsp
mov    %rdi,%r14
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <echo+0x40>
lea    0xe58(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   10a0 <sprintf@plt>
mov    %r15,%rdi
call   1090 <errquit@plt>
lea    0xe51(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e0a(%rip),%r14
cmp    (%r14),%eax
je     1204 <echo+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
jne    11f0 <echo+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1070 <line_separator@plt>
add    $0x130,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"cannot open file '%s'\00"
@.str.2 = [8 x i8] c">>> %s\0A\00"
@EOF = global i32 0
define void @echo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [300 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %2
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%15 = call i32 @errquit(i8* %14)
br label %16
16: ; preds = %10, %1
%17 = load i8*, i8** %2
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %24, %16
%20 = load i32*, i32** %4
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %3
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %3
%26 = call i32 @putchar(i32 %25)
br label %19
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
%30 = call i32 (...) @line_separator()
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"cannot open file '%s'\00"
@.str.2 = [8 x i8] c">>> %s\0A\00"
@EOF = global i32 0
define void @echo(i8* %0) {
%2 = alloca [300 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = call i32 @errquit(i8* %6)
br label %9
9: ; preds = %5, %1
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%11 = call i32 @fgetc(i32* %3)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %9, %14
%15 = phi i32 [ %17, %14 ], [ %11, %9 ]
%16 = call i32 @putchar(i32 %15)
%17 = call i32 @fgetc(i32* %3)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %9
%21 = call i32 @fclose(i32* %3)
%22 = call i32 (...) @line_separator()
ret void
}