#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 uint32_t;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void skip(uint32_t dist, FILE *fp) {
  char buffer[256];
  if (fseek(fp, dist + ftell(fp), SEEK_SET)) {
    while (dist > 0) {
      uint32_t len = (dist < sizeof(buffer) ? dist : sizeof(buffer));
      if (fread(buffer, 1, len, fp) < len) {
        perror("fread");
        exit(1);
      }
      dist -= len;
    }
  }
}


x86 assembly (clang, -O0):
<skip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x120(%rbp)
movslq -0x4(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ftell@plt>
mov    -0x128(%rbp),%rsi
mov    -0x120(%rbp),%rdi
add    %rax,%rsi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     124c <skip+0xfc>
jmp    11af <skip+0x5f>
cmpl   $0x0,-0x4(%rbp)
jle    1247 <skip+0xf7>
movslq -0x4(%rbp),%rax
cmp    $0x100,%rax
jae    11d9 <skip+0x89>
movslq -0x4(%rbp),%rax
mov    %rax,-0x130(%rbp)
jmp    11ea <skip+0x9a>
mov    $0x100,%eax
mov    %rax,-0x130(%rbp)
jmp    11ea <skip+0x9a>
mov    -0x130(%rbp),%rax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x114(%rbp),%eax
jge    1234 <skip+0xe4>
lea    0xddb(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x114(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11af <skip+0x5f>
jmp    124c <skip+0xfc>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
movslq %edi,%rbx
mov    %rsi,%rdi
call   1040 <ftell@plt>
lea    (%rax,%rbx,1),%rsi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1050 <fseek@plt>
test   %ebx,%ebx
jle    11b8 <skip+0x68>
test   %rax,%rax
je     11b8 <skip+0x68>
mov    %rsp,%r14
xchg   %ax,%ax
cmp    $0x100,%ebp
mov    $0x100,%ebx
cmovb  %ebp,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    %ebx,%eax
jl     11c6 <skip+0x76>
sub    %ebx,%ebp
jg     1190 <skip+0x40>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"fread\00"
define void @skip(i32 %0, i32* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = sext i32 %0 to i64
%6 = tail call i64 @ftell(i32* %1)
%7 = add nsw i64 %6, %5
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @fseek(i32* %1, i64 %7, i32 %8)
%10 = icmp ne i64 %9, 0
%11 = icmp sgt i32 %0, 0
%12 = and i1 %11, %10
br i1 %12, label %13, label %25
13: ; preds = %2, %22
%14 = phi i32 [ %23, %22 ], [ %0, %2 ]
%15 = icmp ult i32 %14, 256
%16 = select i1 %15, i32 %14, i32 256
%17 = call i32 @fread(i8* %4, i32 1, i32 %16, i32* %1)
%18 = icmp slt i32 %17, %16
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = sub nsw i32 %14, %16
%24 = icmp sgt i32 %23, 0
br i1 %24, label %13, label %25
25: ; preds = %22, %2
ret void
}