#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*/ *const);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *const, char *);
int getc(int /*<<< orphan*/ *const);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdout;
extern void catFile(const char *const name) {
  FILE *const fp = fopen(name, "r");
  if (fp != NULL) {
    int c;
    while ((c = getc(fp)) != EOF)
      putchar(c);
    fflush(stdout);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<catFile>:
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)
cmpq   $0x0,-0x10(%rbp)
je     11bf <catFile+0x6f>
jmp    1180 <catFile+0x30>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%eax
je     11a8 <catFile+0x58>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    1180 <catFile+0x30>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catFile>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b1 <catFile+0x61>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e71(%rip),%r14
cmp    (%r14),%eax
je     1194 <catFile+0x44>
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r14),%eax
jne    1180 <catFile+0x30>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@stdout = global i32 0
define void @catFile(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 ne i32* %7, null
br i1 %8, label %9, label %23
9: ; preds = %1
br label %10
10: ; preds = %15, %9
%11 = load i32*, i32** %3
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %4
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %4
%17 = call i32 @putchar(i32 %16)
br label %10
18: ; preds = %10
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %18, %1
ret void
}

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