#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*/ ibuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ forth_print(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void q_printfile(FILE *outfd, char *fname) {
  FILE *infd;
  char ibuf[2048];
  infd = fopen(fname, "r");
  if (infd == NULL) {
    fprintf(stderr, "ERROR: Couldn't open \"%s\"!\n", fname);
    exit(-1);
  }
  while (fgets(ibuf, sizeof(ibuf), infd) != NULL)
    forth_print(outfd, ibuf);
  fclose(infd);
}


x86 assembly (clang, -O0):
<q_printfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <q_printfile+0x55>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11ba <q_printfile+0x5a>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ee <q_printfile+0x8e>
mov    -0x8(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1080 <forth_print@plt>
jmp    11ba <q_printfile+0x5a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<q_printfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe85(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e7 <q_printfile+0x87>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11d0 <q_printfile+0x70>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <forth_print@plt>
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11b0 <q_printfile+0x50>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"ERROR: Couldn't open \22%s\22!\0A\00"
define void @q_printfile(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [2048 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%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 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32* @fgets(i8* %18, i32 2048, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32*, i32** %3
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%25 = call i32 @forth_print(i32* %23, i8* %24)
br label %17
26: ; preds = %17
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"ERROR: Couldn't open \22%s\22!\0A\00"
define void @q_printfile(i32* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %7, %14
%15 = call i32 @forth_print(i32* %0, i8* %4)
%16 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %14
18: ; preds = %14, %7
%19 = call i32 @fclose(i32* %5)
ret void
}