#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 */
size_t EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
scalar_t__ ftello(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
void print_to_eof(FILE *fp, char *file, char *buf, int buflen) {
  size_t read;
  fseeko(fp, ftello(fp) + 1, SEEK_SET);
  do {
    read = fread(buf, sizeof(char), buflen - 1, fp);
    if (EOF == read && ferror(fp)) {
      perror(file);
      exit(-1);
    } else {
      buf[read] = '\0';
      printf("%s", buf);
    }
  } while (!feof(fp));
}


x86 assembly (clang, -O0):
<print_to_eof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ftello@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
call   1080 <fseeko@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jne    1217 <print_to_eof+0x97>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1217 <print_to_eof+0x97>
mov    -0x10(%rbp),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   1060 <printf@plt>
jmp    1238 <print_to_eof+0xb8>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c1 <print_to_eof+0x41>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_to_eof>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,(%rsp)
mov    %rdi,%r13
call   1030 <ftello@plt>
lea    0x1(%rax),%rsi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
call   1080 <fseeko@plt>
add    $0xffffffff,%r15d
mov    0x2e2b(%rip),%r14
lea    0xe3c(%rip),%r12
jmp    11eb <print_to_eof+0x6b>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rbx,%rbp,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1226 <print_to_eof+0xa6>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
mov    %rax,%rbp
cmp    %rax,(%r14)
jne    11d0 <print_to_eof+0x50>
mov    %r13,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11d0 <print_to_eof+0x50>
mov    (%rsp),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@EOF = global i64 0
@.str = [3 x i8] c"%s\00"
define void @print_to_eof(i32* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = load i32*, i32** %5
%12 = call i64 @ftello(i32* %11)
%13 = add nsw i64 %12, 1
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @fseeko(i32* %10, i64 %13, i32 %14)
br label %16
16: ; preds = %40, %4
%17 = load i8*, i8** %7
%18 = load i32, i32* %8
%19 = sub nsw i32 %18, 1
%20 = load i32*, i32** %5
%21 = call i64 @fread(i8* %17, i32 1, i32 %19, i32* %20)
store i64 %21, i64* %9
%22 = load i64, i64* @EOF
%23 = load i64, i64* %9
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %16
%26 = load i32*, i32** %5
%27 = call i64 @ferror(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i32 @perror(i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %25, %16
%34 = load i8*, i8** %7
%35 = load i64, i64* %9
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %7
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %33
br label %40
40: ; preds = %39
%41 = load i32*, i32** %5
%42 = call i32 @feof(i32* %41)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
br i1 %44, label %16, label %45
45: ; preds = %40
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@EOF = global i64 0
@.str = [3 x i8] c"%s\00"
define void @print_to_eof(i32* nocapture %0, i8* nocapture %1, i8* %2, i32 %3) {
%5 = tail call i64 @ftello(i32* %0)
%6 = add nsw i64 %5, 1
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseeko(i32* %0, i64 %6, i32 %7)
%9 = add nsw i32 %3, -1
br label %10
10: ; preds = %20, %4
%11 = tail call i64 @fread(i8* %2, i32 1, i32 %9, i32* %0)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %12, %11
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = tail call i64 @ferror(i32* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = tail call i32 @perror(i8* %1)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %14, %10
%21 = getelementptr inbounds i8, i8* %2, i64 %11
store i8 0, i8* %21
%22 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%23 = tail call i32 @feof(i32* %0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %10, label %25
25: ; preds = %20
ret void
}