#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ myerr(char *, char *);
void cat_file(char *path, FILE *out) {
  FILE *f;
  int c;
  if (!(f = fopen(path, "r")))
    myerr("cannot open %s", path);
  while ((c = getc(f)) != EOF)
    fputc(c, out);
  fclose(f);
}


x86 assembly (clang, -O0):
<cat_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    118e <cat_file+0x3e>
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1050 <myerr@plt>
jmp    1193 <cat_file+0x43>
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
je     11bf <cat_file+0x6f>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
jmp    1193 <cat_file+0x43>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117e <cat_file+0x2e>
lea    0xe8c(%rip),%rdi
mov    %r15,%rsi
call   1050 <myerr@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    0x2e5b(%rip),%r15
cmp    (%r15),%eax
je     11b7 <cat_file+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r15),%eax
jne    11a0 <cat_file+0x50>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"cannot open %s\00"
@EOF = global i32 0
define void @cat_file(i8* %0, i32* nocapture %1) {
%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 %7
5: ; preds = %2
%6 = tail call i32 @myerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @getc(i32* %3)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %7, %11
%12 = phi i32 [ %14, %11 ], [ %8, %7 ]
%13 = tail call i32 @fputc(i32 %12, i32* %1)
%14 = tail call i32 @getc(i32* %3)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %11
17: ; preds = %11, %7
%18 = tail call i32 @fclose(i32* %3)
ret void
}