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


x86 assembly (clang, -O0):
<cat_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    118a <cat_file+0x3a>
mov    -0x8(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1050 <myerr@plt>
jmp    118f <cat_file+0x3f>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%eax
je     11c0 <cat_file+0x70>
mov    -0x14(%rbp),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
call   1040 <fputc@plt>
jmp    118f <cat_file+0x3f>
mov    -0x10(%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    %rdi,%r14
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117b <cat_file+0x2b>
lea    0xe8f(%rip),%rdi
mov    %r14,%rsi
call   1050 <myerr@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    0x2e5e(%rip),%r14
cmp    (%r14),%eax
je     11b7 <cat_file+0x67>
mov    0x2e42(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%esi
mov    %eax,%edi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r14),%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
@stderr = global i32 0
define void @cat_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 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @myerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %1
br label %12
12: ; preds = %17, %11
%13 = load i32*, i32** %3
%14 = call i32 @getc(i32* %13)
store i32 %14, i32* %4
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %4
%19 = load i32, i32* @stderr
%20 = call i32 @fputc(i32 %18, i32 %19)
br label %12
21: ; preds = %12
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
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
@stderr = global i32 0
define void @cat_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 %6
4: ; preds = %1
%5 = tail call i32 @myerr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @getc(i32* %2)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %17, label %10
10: ; preds = %6, %10
%11 = phi i32 [ %14, %10 ], [ %7, %6 ]
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputc(i32 %11, i32 %12)
%14 = tail call i32 @getc(i32* %2)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %10
17: ; preds = %10, %6
%18 = tail call i32 @fclose(i32* %2)
ret void
}