#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *fp = fopen("/share/texts/num", "r+");
  assert(fp);
  fseek(fp, 0, SEEK_END);
  long size = ftell(fp);
  assert(size == 5000);
  fseek(fp, 500 * 5, SEEK_SET);
  int i, n;
  for (i = 500; i < 1000; i++) {
    fscanf(fp, "%d", &n);
    assert(n == i + 1);
  }
  fseek(fp, 0, SEEK_SET);
  for (i = 0; i < 500; i++) {
    fprintf(fp, "%4d\n", i + 1 + 1000);
  }
  for (i = 500; i < 1000; i++) {
    fscanf(fp, "%d", &n);
    assert(n == i + 1);
  }
  fseek(fp, 0, SEEK_SET);
  for (i = 0; i < 500; i++) {
    fscanf(fp, "%d", &n);
    assert(n == i + 1 + 1000);
  }
  fclose(fp);
  printf("PASS!!!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe74(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1388,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    $0x9c4,%esi
call   1090 <fseek@plt>
movl   $0x1f4,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    124c <main+0xcc>
mov    -0x10(%rbp),%rdi
lea    0xdf7(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1205 <main+0x85>
mov    -0x10(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1f4,-0x1c(%rbp)
jge    129e <main+0x11e>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
add    $0x3e8,%edx
lea    0xd8c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1267 <main+0xe7>
movl   $0x1f4,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    12ec <main+0x16c>
mov    -0x10(%rbp),%rdi
lea    0xd57(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a5 <main+0x125>
mov    -0x10(%rbp),%rdi
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1f4,-0x1c(%rbp)
jge    1354 <main+0x1d4>
mov    -0x10(%rbp),%rdi
lea    0xcf5(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
add    $0x3e8,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1307 <main+0x187>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xcb8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe6d(%rip),%rdi
lea    0xe77(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1060 <assert@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
xor    %edi,%edi
cmp    $0x1388,%rax
sete   %dil
call   1060 <assert@plt>
mov    0x2dfc(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x9c4,%esi
call   1090 <fseek@plt>
mov    $0x1f5,%ebp
lea    0xe1b(%rip),%r14
lea    0xc(%rsp),%r15
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
xor    %edi,%edi
cmp    0xc(%rsp),%ebp
sete   %dil
call   1060 <assert@plt>
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jne    1200 <main+0x80>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    $0x3e9,%ebp
lea    0xdd5(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x5dd,%ebp
jne    1250 <main+0xd0>
mov    $0x1f5,%ebp
lea    0xda0(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
xor    %edi,%edi
cmp    0xc(%rsp),%ebp
sete   %dil
call   1060 <assert@plt>
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jne    1280 <main+0x100>
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    $0x3e9,%ebp
lea    0xd52(%rip),%r14
lea    0xc(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
xor    %edi,%edi
cmp    0xc(%rsp),%ebp
sete   %dil
call   1060 <assert@plt>
add    $0x1,%ebp
cmp    $0x5dd,%ebp
jne    12d0 <main+0x150>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd15(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/share/texts/num\00"
@.str.1 = [3 x i8] c"r+\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%4d\0A\00"
@.str.4 = [9 x i8] c"PASS!!!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = ptrtoint i32* %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32*, i32** %2
%11 = load i32, i32* @SEEK_END
%12 = call i32 @fseek(i32* %10, i32 0, i32 %11)
%13 = load i32*, i32** %2
%14 = call i64 @ftell(i32* %13)
store i64 %14, i64* %3
%15 = load i64, i64* %3
%16 = icmp eq i64 %15, 5000
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %2
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i32 2500, i32 %20)
store i32 500, i32* %4
br label %22
22: ; preds = %34, %0
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 1000
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i32*, i32** %2
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = icmp eq i32 %28, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
br label %34
34: ; preds = %25
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %22
37: ; preds = %22
%38 = load i32*, i32** %2
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
store i32 0, i32* %4
br label %41
41: ; preds = %50, %37
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 500
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load i32*, i32** %2
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
%48 = add nsw i32 %47, 1000
%49 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %44
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %41
53: ; preds = %41
store i32 500, i32* %4
br label %54
54: ; preds = %66, %53
%55 = load i32, i32* %4
%56 = icmp slt i32 %55, 1000
br i1 %56, label %57, label %69
57: ; preds = %54
%58 = load i32*, i32** %2
%59 = call i32 @fscanf(i32* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%60 = load i32, i32* %5
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
%63 = icmp eq i32 %60, %62
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
br label %66
66: ; preds = %57
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %54
69: ; preds = %54
%70 = load i32*, i32** %2
%71 = load i32, i32* @SEEK_SET
%72 = call i32 @fseek(i32* %70, i32 0, i32 %71)
store i32 0, i32* %4
br label %73
73: ; preds = %86, %69
%74 = load i32, i32* %4
%75 = icmp slt i32 %74, 500
br i1 %75, label %76, label %89
76: ; preds = %73
%77 = load i32*, i32** %2
%78 = call i32 @fscanf(i32* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%79 = load i32, i32* %5
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
%82 = add nsw i32 %81, 1000
%83 = icmp eq i32 %79, %82
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
br label %86
86: ; preds = %76
%87 = load i32, i32* %4
%88 = add nsw i32 %87, 1
store i32 %88, i32* %4
br label %73
89: ; preds = %73
%90 = load i32*, i32** %2
%91 = call i32 @fclose(i32* %90)
%92 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/share/texts/num\00"
@.str.1 = [3 x i8] c"r+\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%4d\0A\00"
@str = [8 x i8] c"PASS!!!\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = ptrtoint i32* %2 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %2, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %2)
%9 = icmp eq i64 %8, 5000
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %2, i32 2500, i32 %12)
%14 = bitcast i32* %1 to i8*
br label %15
15: ; preds = %0, %15
%16 = phi i32 [ 500, %0 ], [ %19, %15 ]
%17 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %18, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = icmp eq i32 %19, 1000
br i1 %23, label %24, label %15
24: ; preds = %15
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %2, i32 0, i32 %25)
br label %27
27: ; preds = %24, %27
%28 = phi i32 [ 0, %24 ], [ %29, %27 ]
%29 = add nuw nsw i32 %28, 1
%30 = add nuw nsw i32 %28, 1001
%31 = call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = icmp eq i32 %29, 500
br i1 %32, label %33, label %27
33: ; preds = %27, %33
%34 = phi i32 [ %37, %33 ], [ 500, %27 ]
%35 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%36 = load i32, i32* %1
%37 = add nuw nsw i32 %34, 1
%38 = icmp eq i32 %36, %37
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = icmp eq i32 %37, 1000
br i1 %41, label %42, label %33
42: ; preds = %33
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @fseek(i32* %2, i32 0, i32 %43)
br label %45
45: ; preds = %42, %45
%46 = phi i32 [ 0, %42 ], [ %49, %45 ]
%47 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%48 = load i32, i32* %1
%49 = add nuw nsw i32 %46, 1
%50 = add nuw nsw i32 %46, 1001
%51 = icmp eq i32 %48, %50
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = icmp eq i32 %49, 500
br i1 %54, label %55, label %45
55: ; preds = %45
%56 = call i32 @fclose(i32* %2)
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}