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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ strlen(char const *);
void read_paper(const char *file_name, const size_t paper_number,
                uint16_t *paper_size, char *paper_storage) {
  FILE *file_spot = NULL;
  int answer = 0;
  uint16_t text_spot = 0;
  uint16_t size = 0;
  int glyph = (char)0;
  assert(file_name != 0);
  assert(strlen(file_name) > 0);
  assert(paper_storage != NULL);
  assert(*paper_size >= 0x1000);
  file_spot = fopen(file_name, "r");
  assert(file_spot != NULL);
  if (file_spot != NULL) {
    answer = fseek(file_spot, (int)paper_number * 0x1000, SEEK_SET);
    if (answer == 0) {
      size = (uint16_t)(fread(paper_storage, 0x1000, 1, file_spot));
      if (size != 0) {
        size = (uint16_t)(size * 0x1000);
      } else {
        answer = fseek(file_spot, (int)paper_number * 0x1000, SEEK_SET);
        assert(answer == 0);
        for (text_spot = 0; text_spot < 0x1000; ++text_spot) {
          glyph = fgetc(file_spot);
          if (glyph == EOF)
            break;
          paper_storage[text_spot] = (char)glyph;
          ++size;
        }
      }
    } else {
      printf("fseek fail PFV");
      size = 0;
    }
    answer = fclose(file_spot);
    assert(answer == 0);
  } else {
    printf("file open fail PFV");
    size = 0;
  }
  *paper_size = size;
}


x86 assembly (clang, -O0):
<read_paper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x1000,(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
je     1368 <read_paper+0x1e8>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
shl    $0xc,%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1333 <read_paper+0x1b3>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1000,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     129c <read_paper+0x11c>
mov    -0x34(%rbp),%eax
shl    $0xc,%eax
mov    %eax,-0x34(%rbp)
jmp    132e <read_paper+0x1ae>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
shl    $0xc,%esi
mov    0x2d28(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x1000,-0x30(%rbp)
jge    1329 <read_paper+0x1a9>
mov    -0x28(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    0x2cf3(%rip),%rcx
cmp    (%rcx),%eax
jne    1302 <read_paper+0x182>
jmp    1329 <read_paper+0x1a9>
mov    -0x38(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12d2 <read_paper+0x152>
jmp    132e <read_paper+0x1ae>
jmp    1346 <read_paper+0x1c6>
lea    0xcc8(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
jmp    137b <read_paper+0x1fb>
lea    0xca2(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_paper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
test   %rax,%rax
setg   %dil
call   1080 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpl   $0x1000,(%r14)
setge  %dil
call   1080 <assert@plt>
lea    0xe1e(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r13
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
test   %r13,%r13
je     1230 <read_paper+0xb0>
shl    $0xc,%r12d
mov    0x2dcd(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %r13,%rdi
mov    %r12d,%esi
call   1090 <fseek@plt>
test   %eax,%eax
je     1243 <read_paper+0xc3>
lea    0xdde(%rip),%rdi
call   1060 <printf@plt>
xor    %ebx,%ebx
jmp    12b3 <read_paper+0x133>
lea    0xdda(%rip),%rdi
call   1060 <printf@plt>
xor    %ebx,%ebx
jmp    12c8 <read_paper+0x148>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %ebx,%ebx
je     1264 <read_paper+0xe4>
shl    $0xc,%ebx
jmp    12b3 <read_paper+0x133>
mov    0x0(%rbp),%edx
mov    %r13,%rdi
mov    %r12d,%esi
call   1090 <fseek@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
xor    %ebx,%ebx
mov    0x2d60(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1070 <fgetc@plt>
cmp    0x0(%rbp),%eax
je     12b3 <read_paper+0x133>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    $0x1000,%rbx
jne    1290 <read_paper+0x110>
mov    $0x1000,%ebx
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
@.str.1 = [15 x i8] c"fseek fail PFV\00"
@.str.2 = [19 x i8] c"file open fail PFV\00"
define void @read_paper(i8* %0, i64 %1, i32* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
store i8* %3, i8** %8
store i32* null, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = icmp sgt i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32*, i32** %7
%28 = load i32, i32* %27
%29 = icmp sge i32 %28, 4096
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i8*, i8** %5
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %33, i32** %9
%34 = load i32*, i32** %9
%35 = icmp ne i32* %34, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32*, i32** %9
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %103
40: ; preds = %4
%41 = load i32*, i32** %9
%42 = load i64, i64* %6
%43 = trunc i64 %42 to i32
%44 = mul nsw i32 %43, 4096
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @fseek(i32* %41, i32 %44, i32 %45)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %94
49: ; preds = %40
%50 = load i8*, i8** %8
%51 = load i32*, i32** %9
%52 = call i64 @fread(i8* %50, i32 4096, i32 1, i32* %51)
%53 = trunc i64 %52 to i32
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = load i32, i32* %12
%58 = mul nsw i32 %57, 4096
store i32 %58, i32* %12
br label %93
59: ; preds = %49
%60 = load i32*, i32** %9
%61 = load i64, i64* %6
%62 = trunc i64 %61 to i32
%63 = mul nsw i32 %62, 4096
%64 = load i32, i32* @SEEK_SET
%65 = call i32 @fseek(i32* %60, i32 %63, i32 %64)
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = icmp eq i32 %66, 0
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
store i32 0, i32* %11
br label %70
70: ; preds = %89, %59
%71 = load i32, i32* %11
%72 = icmp slt i32 %71, 4096
br i1 %72, label %73, label %92
73: ; preds = %70
%74 = load i32*, i32** %9
%75 = call i32 @fgetc(i32* %74)
store i32 %75, i32* %13
%76 = load i32, i32* %13
%77 = load i32, i32* @EOF
%78 = icmp eq i32 %76, %77
br i1 %78, label %79, label %80
79: ; preds = %73
br label %92
80: ; preds = %73
%81 = load i32, i32* %13
%82 = trunc i32 %81 to i8
%83 = load i8*, i8** %8
%84 = load i32, i32* %11
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
store i8 %82, i8* %86
%87 = load i32, i32* %12
%88 = add nsw i32 %87, 1
store i32 %88, i32* %12
br label %89
89: ; preds = %80
%90 = load i32, i32* %11
%91 = add nsw i32 %90, 1
store i32 %91, i32* %11
br label %70
92: ; preds = %79, %70
br label %93
93: ; preds = %92, %56
br label %96
94: ; preds = %40
%95 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %12
br label %96
96: ; preds = %94, %93
%97 = load i32*, i32** %9
%98 = call i32 @fclose(i32* %97)
store i32 %98, i32* %10
%99 = load i32, i32* %10
%100 = icmp eq i32 %99, 0
%101 = zext i1 %100 to i32
%102 = call i32 @assert(i32 %101)
br label %105
103: ; preds = %4
%104 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %12
br label %105
105: ; preds = %103, %96
%106 = load i32, i32* %12
%107 = load i32*, i32** %7
store i32 %106, i32* %107
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@EOF = global i32 0
@.str.1 = [15 x i8] c"fseek fail PFV\00"
@.str.2 = [19 x i8] c"file open fail PFV\00"
define void @read_paper(i8* %0, i64 %1, i32* nocapture %2, i8* %3) {
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = icmp sgt i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ne i8* %3, null
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 4095
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32* %19, null
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
br i1 %20, label %23, label %61
23: ; preds = %4
%24 = trunc i64 %1 to i32
%25 = shl nsw i32 %24, 12
%26 = load i32, i32* @SEEK_SET
%27 = tail call i32 @fseek(i32* %19, i32 %25, i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %51
29: ; preds = %23
%30 = tail call i64 @fread(i8* %3, i32 4096, i32 1, i32* %19)
%31 = trunc i64 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = shl nsw i32 %31, 12
br label %55
35: ; preds = %29
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @fseek(i32* %19, i32 %25, i32 %36)
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = tail call i32 @assert(i32 %39)
br label %41
41: ; preds = %35, %46
%42 = phi i64 [ 0, %35 ], [ %49, %46 ]
%43 = tail call i32 @fgetc(i32* %19)
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %53, label %46
46: ; preds = %41
%47 = trunc i32 %43 to i8
%48 = getelementptr inbounds i8, i8* %3, i64 %42
store i8 %47, i8* %48
%49 = add nuw nsw i64 %42, 1
%50 = icmp eq i64 %49, 4096
br i1 %50, label %55, label %41
51: ; preds = %23
%52 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %55
53: ; preds = %41
%54 = trunc i64 %42 to i32
br label %55
55: ; preds = %46, %53, %33, %51
%56 = phi i32 [ %34, %33 ], [ 0, %51 ], [ %54, %53 ], [ 4096, %46 ]
%57 = tail call i32 @fclose(i32* %19)
%58 = icmp eq i32 %57, 0
%59 = zext i1 %58 to i32
%60 = tail call i32 @assert(i32 %59)
br label %63
61: ; preds = %4
%62 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %61, %55
%64 = phi i32 [ %56, %55 ], [ 0, %61 ]
store i32 %64, i32* %2
ret void
}