#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 */
long BUFSIZ;
int /*<<< orphan*/ SEEK_SET;
size_t fread(char *, size_t, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int skip_to(FILE *file, long offset) {
  long old_offset;
  old_offset = ftell(file);
  if (offset > old_offset && offset - old_offset <= BUFSIZ) {
    size_t skip_bytes = offset - old_offset;
    char buf[skip_bytes];
    if (fread(buf, skip_bytes, 1, file) != skip_bytes)
      return -1;
  }
  return fseek(file, offset, SEEK_SET);
}


x86 assembly (clang, -O0):
<skip_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    11fc <skip_to+0xcc>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%rax
jg     11fc <skip_to+0xcc>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    -0x28(%rbp),%rax
je     11d4 <skip_to+0xa4>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    11db <skip_to+0xab>
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
test   %eax,%eax
je     11f7 <skip_to+0xc7>
jmp    11f2 <skip_to+0xc2>
jmp    1215 <skip_to+0xe5>
jmp    11fc <skip_to+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_to>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <ftell@plt>
cmp    %r15,%rax
jge    1189 <skip_to+0x59>
mov    %r15,%rbx
sub    %rax,%rbx
mov    0x2e88(%rip),%rax
cmp    (%rax),%rbx
jg     1189 <skip_to+0x59>
mov    %rsp,%r12
mov    %rsp,%rdi
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    %rbx,%rax
mov    %r12,%rsp
jne    11a9 <skip_to+0x79>
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fseek@plt>
mov    $0xffffffff,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i64 0
@SEEK_SET = global i32 0
define i32 @skip_to(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
%11 = load i32*, i32** %4
%12 = call i64 @ftell(i32* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = icmp sgt i64 %13, %14
br i1 %15, label %16, label %40
16: ; preds = %2
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = sub nsw i64 %17, %18
%20 = load i64, i64* @BUFSIZ
%21 = icmp sle i64 %19, %20
br i1 %21, label %22, label %40
22: ; preds = %16
%23 = load i64, i64* %5
%24 = load i64, i64* %6
%25 = sub nsw i64 %23, %24
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %8
%28 = alloca i8, i64 %26
store i64 %26, i64* %9
%29 = load i64, i64* %7
%30 = load i32*, i32** %4
%31 = call i64 @fread(i8* %28, i64 %29, i32 1, i32* %30)
%32 = load i64, i64* %7
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %22
store i32 -1, i32* %3
store i32 1, i32* %10
br label %36
35: ; preds = %22
store i32 0, i32* %10
br label %36
36: ; preds = %35, %34
%37 = load i8*, i8** %8
%38 = load i32, i32* %10
switch i32 %38, label %47 [
i32 0, label %39
i32 1, label %45
]
39: ; preds = %36
br label %40
40: ; preds = %39, %16, %2
%41 = load i32*, i32** %4
%42 = load i64, i64* %5
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @fseek(i32* %41, i64 %42, i32 %43)
store i32 %44, i32* %3
br label %45
45: ; preds = %40, %36
%46 = load i32, i32* %3
ret i32 %46
47: ; preds = %36
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i64 0
@SEEK_SET = global i32 0
define i32 @skip_to(i32* nocapture %0, i64 %1) {
%3 = tail call i64 @ftell(i32* %0)
%4 = icmp slt i64 %3, %1
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = sub nsw i64 %1, %3
%7 = load i64, i64* @BUFSIZ
%8 = icmp sgt i64 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %6
%12 = call i64 @fread(i8* %11, i64 %6, i32 1, i32* %0)
%13 = icmp eq i64 %12, %6
tail call void @llvm.stackrestore(i8* %10)
br i1 %13, label %14, label %17
14: ; preds = %9, %5, %2
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %0, i64 %1, i32 %15)
br label %17
17: ; preds = %9, %14
%18 = phi i32 [ %16, %14 ], [ -1, %9 ]
ret i32 %18
}