#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*/ die(char *);
int /*<<< orphan*/ die_file_eof(int /*<<< orphan*/ *);
int fread(char *, size_t, int, int /*<<< orphan*/ *);
size_t seek_section(FILE *fp, size_t cur, size_t tag) {
  size_t n;
  size_t d;
  char dmy[1024];
  if (cur > tag) {
    die("(FONT): backward seeking\n");
  } else if (cur == tag) {
    return tag;
  }
  n = tag - cur;
  while (n) {
    d = n > 1024 ? 1024 : n;
    if (fread(dmy, d, 1, fp) != 1)
      die_file_eof(fp);
    n -= d;
  }
  return tag;
}


x86 assembly (clang, -O0):
<seek_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1166 <seek_section+0x36>
lea    0xea4(%rip),%rdi
call   1050 <die@plt>
jmp    1186 <seek_section+0x56>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1181 <seek_section+0x51>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <seek_section+0xe9>
jmp    1186 <seek_section+0x56>
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1211 <seek_section+0xe1>
cmpq   $0x400,-0x28(%rbp)
jbe    11bc <seek_section+0x8c>
mov    $0x400,%eax
mov    %rax,-0x438(%rbp)
jmp    11c7 <seek_section+0x97>
mov    -0x28(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11fd <seek_section+0xcd>
mov    -0x10(%rbp),%rdi
call   1040 <die_file_eof@plt>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1192 <seek_section+0x62>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seek_section>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rdi,%r12
mov    %rdx,%rbx
sub    %rsi,%rbx
jae    1167 <seek_section+0x37>
mov    %rsi,%r15
lea    0xea8(%rip),%rdi
call   1050 <die@plt>
mov    %r14,%rbx
sub    %r15,%rbx
jne    116b <seek_section+0x3b>
jmp    11a8 <seek_section+0x78>
je     11a8 <seek_section+0x78>
je     11a8 <seek_section+0x78>
mov    %rsp,%r15
jmp    1175 <seek_section+0x45>
sub    %r13,%rbx
je     11a8 <seek_section+0x78>
cmp    $0x400,%rbx
mov    $0x400,%r13d
cmovb  %rbx,%r13
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1170 <seek_section+0x40>
mov    %r12,%rdi
call   1040 <die_file_eof@plt>
jmp    1170 <seek_section+0x40>
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"(FONT): backward seeking\0A\00"
define i64 @seek_section(i32* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [1024 x i8]
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%11 = load i64, i64* %6
%12 = load i64, i64* %7
%13 = icmp ugt i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %23
16: ; preds = %3
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i64, i64* %7
store i64 %21, i64* %4
br label %52
22: ; preds = %16
br label %23
23: ; preds = %22, %14
%24 = load i64, i64* %7
%25 = load i64, i64* %6
%26 = sub i64 %24, %25
store i64 %26, i64* %8
br label %27
27: ; preds = %46, %23
%28 = load i64, i64* %8
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %27
%31 = load i64, i64* %8
%32 = icmp ugt i64 %31, 1024
br i1 %32, label %33, label %34
33: ; preds = %30
br label %36
34: ; preds = %30
%35 = load i64, i64* %8
br label %36
36: ; preds = %34, %33
%37 = phi i64 [ 1024, %33 ], [ %35, %34 ]
store i64 %37, i64* %9
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = load i64, i64* %9
%40 = load i32*, i32** %5
%41 = call i32 @fread(i8* %38, i64 %39, i32 1, i32* %40)
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = load i32*, i32** %5
%45 = call i32 @die_file_eof(i32* %44)
br label %46
46: ; preds = %43, %36
%47 = load i64, i64* %9
%48 = load i64, i64* %8
%49 = sub i64 %48, %47
store i64 %49, i64* %8
br label %27
50: ; preds = %27
%51 = load i64, i64* %7
store i64 %51, i64* %4
br label %52
52: ; preds = %50, %20
%53 = load i64, i64* %4
ret i64 %53
}

LLVM IR (-O2):
@.str = [26 x i8] c"(FONT): backward seeking\0A\00"
define i64 @seek_section(i32* %0, i64 %1, i64 returned %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp ult i64 %2, %1
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = sub i64 %2, %1
%10 = icmp eq i64 %9, 0
br i1 %10, label %29, label %16
11: ; preds = %3
%12 = icmp eq i64 %2, %1
%13 = sub i64 %2, %1
%14 = icmp eq i64 %13, 0
%15 = or i1 %12, %14
br i1 %15, label %29, label %16
16: ; preds = %7, %11
%17 = phi i64 [ %9, %7 ], [ %13, %11 ]
br label %18
18: ; preds = %16, %26
%19 = phi i64 [ %27, %26 ], [ %17, %16 ]
%20 = icmp ult i64 %19, 1024
%21 = select i1 %20, i64 %19, i64 1024
%22 = call i32 @fread(i8* %5, i64 %21, i32 1, i32* %0)
%23 = icmp eq i32 %22, 1
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = tail call i32 @die_file_eof(i32* %0)
br label %26
26: ; preds = %24, %18
%27 = sub i64 %19, %21
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %18
29: ; preds = %26, %7, %11
ret i64 %2
}