#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;
char *alloca(size_t);
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 = alloca(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    $0x30,%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    11cd <skip_to+0x8d>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jg     11cd <skip_to+0x8d>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <alloca@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    -0x28(%rbp),%rax
je     11c8 <skip_to+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <skip_to+0xa6>
jmp    11cd <skip_to+0x8d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_to>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <ftell@plt>
cmp    %r15,%rax
jge    1187 <skip_to+0x47>
mov    %r15,%rbx
sub    %rax,%rbx
mov    0x2e7e(%rip),%rax
cmp    (%rax),%rbx
jg     1187 <skip_to+0x47>
mov    %rbx,%rdi
call   1050 <alloca@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    %rbx,%rax
jne    11a0 <skip_to+0x60>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <fseek@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
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*
store i32* %0, i32** %4
store i64 %1, i64* %5
%9 = load i32*, i32** %4
%10 = call i64 @ftell(i32* %9)
store i64 %10, i64* %6
%11 = load i64, i64* %5
%12 = load i64, i64* %6
%13 = icmp sgt i64 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %2
%15 = load i64, i64* %5
%16 = load i64, i64* %6
%17 = sub nsw i64 %15, %16
%18 = load i64, i64* @BUFSIZ
%19 = icmp sle i64 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %14
%21 = load i64, i64* %5
%22 = load i64, i64* %6
%23 = sub nsw i64 %21, %22
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = call i8* @alloca(i64 %24)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i64, i64* %7
%28 = load i32*, i32** %4
%29 = call i64 @fread(i8* %26, i64 %27, i32 1, i32* %28)
%30 = load i64, i64* %7
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %20
store i32 -1, i32* %3
br label %39
33: ; preds = %20
br label %34
34: ; preds = %33, %14, %2
%35 = load i32*, i32** %4
%36 = load i64, i64* %5
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %35, i64 %36, i32 %37)
store i32 %38, i32* %3
br label %39
39: ; preds = %34, %32
%40 = load i32, i32* %3
ret i32 %40
}

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 %13
5: ; preds = %2
%6 = sub nsw i64 %1, %3
%7 = load i64, i64* @BUFSIZ
%8 = icmp sgt i64 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i8* @alloca(i64 %6)
%11 = tail call i64 @fread(i8* %10, i64 %6, i32 1, i32* %0)
%12 = icmp eq i64 %11, %6
br i1 %12, label %13, label %16
13: ; preds = %9, %5, %2
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %0, i64 %1, i32 %14)
br label %16
16: ; preds = %9, %13
%17 = phi i32 [ %15, %13 ], [ -1, %9 ]
ret i32 %17
}