#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 scalar_t__ ssize_t;
typedef scalar_t__ off_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, scalar_t__);
int /*<<< orphan*/ stderr;
int skip(int fd, off_t offset) {
  off_t remain;
  char buffer[512];
  if (lseek(fd, offset, SEEK_SET) >= 0) {
    return 0;
  }
  remain = offset;
  while (remain > 0) {
    ssize_t amount, done;
    amount = (remain < (off_t)sizeof(buffer)) ? remain : (off_t)sizeof(buffer);
    done = read(fd, buffer, amount);
    if (done < 0) {
      perror("Error reading input data");
      return 99;
    } else if (done == 0) {
      fprintf(stderr, "EOF on input file/stream\n");
      return 99;
    } else {
      remain -= done;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<skip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0x0,%rax
jl     117d <skip+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1262 <skip+0x122>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    125b <skip+0x11b>
cmpq   $0x200,-0x18(%rbp)
jge    11ae <skip+0x6e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x238(%rbp)
jmp    11bf <skip+0x7f>
mov    $0x200,%eax
mov    %rax,-0x238(%rbp)
jmp    11bf <skip+0x7f>
mov    -0x238(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x228(%rbp),%rdx
call   1040 <read@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jge    1210 <skip+0xd0>
lea    0xe01(%rip),%rdi
call   1060 <perror@plt>
movl   $0x63,-0x4(%rbp)
jmp    1262 <skip+0x122>
cmpq   $0x0,-0x230(%rbp)
jne    123f <skip+0xff>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x63,-0x4(%rbp)
jmp    1262 <skip+0x122>
mov    -0x230(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1256 <skip+0x116>
jmp    1185 <skip+0x45>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
xor    %r14d,%r14d
test   %rax,%rax
jns    11b6 <skip+0x76>
test   %rbx,%rbx
jle    11b6 <skip+0x76>
mov    %rsp,%r15
cmp    $0x200,%rbx
mov    $0x200,%edx
cmovb  %rbx,%rdx
mov    %ebp,%edi
mov    %r15,%rsi
call   1040 <read@plt>
test   %rax,%rax
js     11c7 <skip+0x87>
je     119b <skip+0x5b>
sub    %rax,%rbx
test   %rbx,%rbx
jg     1170 <skip+0x30>
jmp    11b6 <skip+0x76>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x63,%r14d
mov    %r14d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe32(%rip),%rdi
call   1060 <perror@plt>
jmp    11b0 <skip+0x70>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [25 x i8] c"Error reading input data\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"EOF on input file/stream\0A\00"
define i32 @skip(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca [512 x i8]
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
%10 = load i32, i32* %4
%11 = load i64, i64* %5
%12 = load i32, i32* @SEEK_SET
%13 = call i64 @lseek(i32 %10, i64 %11, i32 %12)
%14 = icmp sge i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %50
16: ; preds = %2
%17 = load i64, i64* %5
store i64 %17, i64* %6
br label %18
18: ; preds = %48, %16
%19 = load i64, i64* %6
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %49
21: ; preds = %18
%22 = load i64, i64* %6
%23 = icmp slt i64 %22, 512
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i64, i64* %6
br label %27
26: ; preds = %21
br label %27
27: ; preds = %26, %24
%28 = phi i64 [ %25, %24 ], [ 512, %26 ]
store i64 %28, i64* %8
%29 = load i32, i32* %4
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%31 = load i64, i64* %8
%32 = call i64 @read(i32 %29, i8* %30, i64 %31)
store i64 %32, i64* %9
%33 = load i64, i64* %9
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 99, i32* %3
br label %50
37: ; preds = %27
%38 = load i64, i64* %9
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 99, i32* %3
br label %50
43: ; preds = %37
%44 = load i64, i64* %9
%45 = load i64, i64* %6
%46 = sub nsw i64 %45, %44
store i64 %46, i64* %6
br label %47
47: ; preds = %43
br label %48
48: ; preds = %47
br label %18
49: ; preds = %18
store i32 0, i32* %3
br label %50
50: ; preds = %49, %40, %35, %15
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [25 x i8] c"Error reading input data\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"EOF on input file/stream\0A\00"
define i32 @skip(i32 %0, i64 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @lseek(i32 %0, i64 %1, i32 %5)
%7 = icmp slt i64 %6, 0
%8 = icmp sgt i64 %1, 0
%9 = and i1 %7, %8
br i1 %9, label %12, label %26
10: ; preds = %20
%11 = icmp sgt i64 %22, 0
br i1 %11, label %12, label %26
12: ; preds = %2, %10
%13 = phi i64 [ %22, %10 ], [ %1, %2 ]
%14 = icmp ult i64 %13, 512
%15 = select i1 %14, i64 %13, i64 512
%16 = call i64 @read(i32 %0, i8* %4, i64 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %26
20: ; preds = %12
%21 = icmp eq i64 %16, 0
%22 = sub nsw i64 %13, %16
br i1 %21, label %23, label %10
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %10, %18, %23, %2
%27 = phi i32 [ 0, %2 ], [ 99, %23 ], [ 99, %18 ], [ 0, %10 ]
ret i32 %27
}