#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*/ fflush(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int cat(char *nam) {
  FILE *fp;
  int c;
  if ((fp = fopen(nam, "rb")) == NULL)
    return -1;
  while ((c = fgetc(fp)) != EOF)
    fputc(c, stdout);
  fclose(fp);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1186 <cat+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <cat+0x8a>
jmp    118b <cat+0x3b>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
je     11bc <cat+0x6c>
mov    -0x1c(%rbp),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1050 <fputc@plt>
jmp    118b <cat+0x3b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c1 <cat+0x71>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e70(%rip),%r14
cmp    (%r14),%eax
je     11a7 <cat+0x57>
mov    0x2e54(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%esi
mov    %eax,%edi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r14),%eax
jne    1190 <cat+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
jmp    11c6 <cat+0x76>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @cat(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %15, label %8
8: ; preds = %4, %8
%9 = phi i32 [ %12, %8 ], [ %5, %4 ]
%10 = load i32, i32* @stdout
%11 = tail call i32 @fputc(i32 %9, i32 %10)
%12 = tail call i32 @fgetc(i32* %2)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %8
15: ; preds = %8, %4
%16 = tail call i32 @fclose(i32* %2)
%17 = load i32, i32* @stdout
%18 = tail call i32 @fflush(i32 %17)
br label %19
19: ; preds = %1, %15
%20 = phi i32 [ 0, %15 ], [ -1, %1 ]
ret i32 %20
}