#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 /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
unsigned int fread(char *, int, unsigned int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int vi_tailOutput(FILE *fp, long offset, long len) {
  char buf[1024];
  if (fseek(fp, offset, SEEK_SET) == -1)
    return -1;
  while (len) {
    unsigned int min = (len > 1024) ? 1024 : len;
    if (fread(buf, 1, min, fp) != min)
      return -1;
    fwrite(buf, 1, min, stdout);
    fflush(stdout);
    len -= min;
  }
  return 0;
}


x86 assembly (clang, -O0):
<vi_tailOutput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1182 <vi_tailOutput+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <vi_tailOutput+0x109>
jmp    1187 <vi_tailOutput+0x47>
cmpq   $0x0,-0x20(%rbp)
je     1242 <vi_tailOutput+0x102>
cmpq   $0x400,-0x20(%rbp)
jle    11b1 <vi_tailOutput+0x71>
mov    $0x400,%eax
mov    %rax,-0x430(%rbp)
jmp    11bc <vi_tailOutput+0x7c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x424(%rbp),%eax
je     11fc <vi_tailOutput+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <vi_tailOutput+0x109>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%edx
mov    0x2dc8(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x424(%rbp),%eax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1187 <vi_tailOutput+0x47>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vi_tailOutput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%rbx
mov    %rdi,%r12
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11cc <vi_tailOutput+0x8c>
test   %rbx,%rbx
je     11c9 <vi_tailOutput+0x89>
mov    %rsp,%r15
mov    0x2e59(%rip),%r13
nop
cmp    $0x400,%rbx
mov    $0x400,%ebp
cmovl  %rbx,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    %ebp,%eax
jne    11cc <vi_tailOutput+0x8c>
mov    0x0(%r13),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1060 <fwrite@plt>
mov    0x0(%r13),%edi
call   1040 <fflush@plt>
mov    %ebp,%eax
sub    %rax,%rbx
jne    1180 <vi_tailOutput+0x40>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stdout = global i32 0
define i32 @vi_tailOutput(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca [1024 x i8]
%9 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%10 = load i32*, i32** %5
%11 = load i64, i64* %6
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @fseek(i32* %10, i64 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %48
16: ; preds = %3
br label %17
17: ; preds = %36, %16
%18 = load i64, i64* %7
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %47
20: ; preds = %17
%21 = load i64, i64* %7
%22 = icmp sgt i64 %21, 1024
br i1 %22, label %23, label %24
23: ; preds = %20
br label %26
24: ; preds = %20
%25 = load i64, i64* %7
br label %26
26: ; preds = %24, %23
%27 = phi i64 [ 1024, %23 ], [ %25, %24 ]
%28 = trunc i64 %27 to i32
store i32 %28, i32* %9
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %9
%31 = load i32*, i32** %5
%32 = call i32 @fread(i8* %29, i32 1, i32 %30, i32* %31)
%33 = load i32, i32* %9
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %26
store i32 -1, i32* %4
br label %48
36: ; preds = %26
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = load i32, i32* %9
%39 = load i32, i32* @stdout
%40 = call i32 @fwrite(i8* %37, i32 1, i32 %38, i32 %39)
%41 = load i32, i32* @stdout
%42 = call i32 @fflush(i32 %41)
%43 = load i32, i32* %9
%44 = zext i32 %43 to i64
%45 = load i64, i64* %7
%46 = sub nsw i64 %45, %44
store i64 %46, i64* %7
br label %17
47: ; preds = %17
store i32 0, i32* %4
br label %48
48: ; preds = %47, %35, %15
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stdout = global i32 0
define i32 @vi_tailOutput(i32* nocapture %0, i64 %1, i64 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %0, i64 %1, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %26, label %9
9: ; preds = %3
%10 = icmp eq i64 %2, 0
br i1 %10, label %26, label %11
11: ; preds = %9, %18
%12 = phi i64 [ %24, %18 ], [ %2, %9 ]
%13 = icmp slt i64 %12, 1024
%14 = select i1 %13, i64 %12, i64 1024
%15 = trunc i64 %14 to i32
%16 = call i32 @fread(i8* %5, i32 1, i32 %15, i32* %0)
%17 = icmp eq i32 %16, %15
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i32, i32* @stdout
%20 = call i32 @fwrite(i8* %5, i32 1, i32 %15, i32 %19)
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = and i64 %14, 4294967295
%24 = sub nsw i64 %12, %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %11
26: ; preds = %18, %11, %9, %3
%27 = phi i32 [ -1, %3 ], [ 0, %9 ], [ 0, %18 ], [ -1, %11 ]
ret i32 %27
}