#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
unsigned char *calloc(int, int);
int /*<<< orphan*/ check_chunk(unsigned char *, int);
int /*<<< orphan*/ ckpt_and_exit();
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit_failure();
int /*<<< orphan*/ free(unsigned char *);
int full_read(int, unsigned char *, int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
char *strerror(int);
void check_a_file(char *file, off_t chunk_size, off_t num_chunks) {
  int fd = -1;
  off_t i;
  unsigned char *chunk = NULL;
  off_t calculated_pos;
  off_t actual_pos;
  srand(0);
  chunk = calloc(chunk_size, 1);
  if (chunk == NULL) {
    printf("ERROR: Out of memory!\n");
    exit_failure();
  }
  fd = open(file, O_RDONLY);
  if (fd < 0) {
    printf("ERROR: Failed to open the file '%s' for verification. %d(%s)\n",
           file, errno, strerror(errno));
    exit_failure();
  }
  calculated_pos = 0;
  for (i = 0; i < num_chunks; i++) {
    if ((i % 1024) == 0) {
      if (full_read(fd, chunk, chunk_size) != chunk_size) {
        printf("ERROR: Failed to read file: %d(%s)\n", errno, strerror(errno));
        exit_failure();
      }
      check_chunk(chunk, chunk_size);
    } else {
      lseek(fd, chunk_size, SEEK_CUR);
    }
    calculated_pos += chunk_size;
    actual_pos = lseek(fd, (off_t)0, SEEK_CUR);
    if (i == 0 || i == ((num_chunks >> 1) - (num_chunks >> 2)) ||
        i == (num_chunks >> 1) ||
        i == ((num_chunks >> 1) + (num_chunks >> 2)) || i == (num_chunks - 1)) {
      printf("Checkpointing at %.0lf%% of the file operation.\n",
             i == 0 ? 0 : ((double)i / (double)num_chunks) * 100.0);
      printf("Skipping checkpoint!\n");
      ckpt_and_exit();
    }
    if (actual_pos != calculated_pos) {
      printf("ERROR: lseek() failed %d(%s) to get current position of "
             "reading file. Expected %lld. Got %lld.\n",
             errno, strerror(errno), (long long int)calculated_pos,
             (long long int)actual_pos);
      exit_failure();
    }
  }
  close(fd);
  free(chunk);
}


x86 assembly (clang, -O0):
<check_a_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %edi,%edi
call   1090 <srand@plt>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1219 <check_a_file+0x59>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <exit_failure@plt>
mov    -0x8(%rbp),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1279 <check_a_file+0xb9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <exit_failure@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1450 <check_a_file+0x290>
mov    -0x18(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1305 <check_a_file+0x145>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <full_read@plt>
cmp    -0xc(%rbp),%eax
je     12f4 <check_a_file+0x134>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x3c(%rbp),%esi
mov    %rax,%rdx
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <exit_failure@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <check_chunk@plt>
jmp    1319 <check_a_file+0x159>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
mov    -0xc(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1396 <check_a_file+0x1d6>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    $0x1,%ecx
mov    -0x10(%rbp),%edx
sar    $0x2,%edx
sub    %edx,%ecx
cmp    %ecx,%eax
je     1396 <check_a_file+0x1d6>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    $0x1,%ecx
cmp    %ecx,%eax
je     1396 <check_a_file+0x1d6>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    $0x1,%ecx
mov    -0x10(%rbp),%edx
sar    $0x2,%edx
add    %edx,%ecx
cmp    %ecx,%eax
je     1396 <check_a_file+0x1d6>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    13f4 <check_a_file+0x234>
cmpl   $0x0,-0x18(%rbp)
jne    13ad <check_a_file+0x1ed>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    13cc <check_a_file+0x20c>
cvtsi2sdl -0x18(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xc3d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xca9(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10d0 <ckpt_and_exit@plt>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     143d <check_a_file+0x27d>
mov    0x2bc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
movslq -0x24(%rbp),%rcx
movslq -0x28(%rbp),%r8
lea    0xc99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <exit_failure@plt>
jmp    1442 <check_a_file+0x282>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1287 <check_a_file+0xc7>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_a_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r12
xor    %edi,%edi
call   10a0 <srand@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1216 <check_a_file+0x46>
lea    0xf0e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10c0 <exit_failure@plt>
mov    %rbp,0x10(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   10d0 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
mov    %r14d,0x8(%rsp)
jns    126e <check_a_file+0x9e>
mov    0x2d90(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
call   10f0 <strerror@plt>
lea    0xdbe(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    0x8(%rsp),%r14d
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <exit_failure@plt>
test   %r15d,%r15d
mov    0xc(%rsp),%r12d
jle    1357 <check_a_file+0x187>
mov    %r12d,%edi
mov    0x10(%rsp),%rbp
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <full_read@plt>
cmp    %r14d,%eax
je     12be <check_a_file+0xee>
mov    0x2d35(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10f0 <strerror@plt>
lea    0xda3(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <exit_failure@plt>
movslq %r14d,%rax
mov    %rax,0x18(%rsp)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1060 <check_chunk@plt>
mov    0x2d10(%rip),%rbx
mov    (%rbx),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %eax,%ebp
lea    0xd85(%rip),%rdi
xorpd  %xmm0,%xmm0
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10e0 <ckpt_and_exit@plt>
cmp    %r14d,%ebp
je     1351 <check_a_file+0x181>
mov    0x2cb9(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
call   10f0 <strerror@plt>
movslq %ebp,%r8
lea    0xd77(%rip),%rdi
mov    %r14d,%esi
mov    0x2cb2(%rip),%rbx
mov    0x8(%rsp),%r14d
mov    %rax,%rdx
mov    0x18(%rsp),%rcx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <exit_failure@plt>
cmp    $0x1,%r15d
jne    1377 <check_a_file+0x1a7>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0x10(%rsp),%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    %r15,%rdx
mov    %edx,%eax
shr    %eax
mov    %edx,%ecx
shr    $0x2,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  %xmm0,0x40(%rsp)
mov    0x18(%rsp),%rsi
lea    (%rsi,%rsi,1),%rbp
neg    %edx
lea    -0x1(%rax),%esi
mov    %esi,0x30(%rsp)
sub    %ecx,%esi
mov    %esi,0x34(%rsp)
add    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,0x2c(%rsp)
movsd  0xc47(%rip),%xmm0
xor    %r15d,%r15d
movsd  %xmm0,0x20(%rsp)
mov    %rdx,0x38(%rsp)
jmp    140c <check_a_file+0x23c>
nopl   0x0(%rax)
movsd  0x20(%rsp),%xmm0
addsd  0xc22(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
add    0x18(%rsp),%rbp
mov    0x38(%rsp),%rax
add    %r15d,%eax
add    $0x1,%eax
mov    %r13d,%r15d
cmp    $0xffffffff,%eax
mov    0x8(%rsp),%r14d
mov    0x2be2(%rip),%rbx
je     1357 <check_a_file+0x187>
lea    0x1(%r15),%r13d
test   $0x3ff,%r13d
je     1430 <check_a_file+0x260>
mov    (%rbx),%edx
mov    %r12d,%edi
mov    %r14d,%esi
call   1080 <lseek@plt>
jmp    1489 <check_a_file+0x2b9>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    0x10(%rsp),%r12
mov    %r12,%rsi
mov    %r14d,%edx
call   1050 <full_read@plt>
cmp    %r14d,%eax
je     1479 <check_a_file+0x2a9>
mov    0x2b81(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10f0 <strerror@plt>
lea    0xbef(%rip),%rdi
mov    %ebx,%esi
mov    0x2b80(%rip),%rbx
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <exit_failure@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <check_chunk@plt>
mov    0xc(%rsp),%r12d
mov    (%rbx),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %eax,%r14d
cmp    %r15d,0x34(%rsp)
je     14d0 <check_a_file+0x300>
cmp    %r15d,0x30(%rsp)
je     14d0 <check_a_file+0x300>
cmp    %r15d,0x2c(%rsp)
je     14d0 <check_a_file+0x300>
mov    0x38(%rsp),%rax
add    %r15d,%eax
cmp    $0xfffffffe,%eax
je     14d0 <check_a_file+0x300>
cmp    %r14d,%ebp
je     13d0 <check_a_file+0x200>
jmp    150e <check_a_file+0x33e>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x20(%rsp),%xmm0
divsd  0x40(%rsp),%xmm0
mulsd  0xb24(%rip),%xmm0
lea    0xb87(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xc0a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10e0 <ckpt_and_exit@plt>
cmp    %r14d,%ebp
je     13d0 <check_a_file+0x200>
mov    0x2abb(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10f0 <strerror@plt>
movslq %r14d,%r8
lea    0xb7b(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <exit_failure@plt>
jmp    13d0 <check_a_file+0x200>

LLVM IR (-O0):
@.str = [23 x i8] c"ERROR: Out of memory!\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [62 x i8] c"ERROR: Failed to open the file '%s' for verification. %d(%s)\0A\00"
@errno = global i32 0
@.str.2 = [36 x i8] c"ERROR: Failed to read file: %d(%s)\0A\00"
@SEEK_CUR = global i32 0
@.str.3 = [49 x i8] c"Checkpointing at %.0lf%% of the file operation.\0A\00"
@.str.4 = [22 x i8] c"Skipping checkpoint!\0A\00"
@.str.5 = [96 x i8] c"ERROR: lseek() failed %d(%s) to get current position of reading file. Expected %lld. Got %lld.\0A\00"
define void @check_a_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 -1, i32* %7
store i8* null, i8** %9
%12 = call i32 @srand(i32 0)
%13 = load i32, i32* %5
%14 = call i8* @calloc(i32 %13, i32 1)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (...) @exit_failure()
br label %20
20: ; preds = %17, %3
%21 = load i8*, i8** %4
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = load i32, i32* @errno
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %28, i8* %30)
%32 = call i32 (...) @exit_failure()
br label %33
33: ; preds = %26, %20
store i32 0, i32* %10
store i32 0, i32* %8
br label %34
34: ; preds = %130, %33
%35 = load i32, i32* %8
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %133
38: ; preds = %34
%39 = load i32, i32* %8
%40 = srem i32 %39, 1024
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %38
%43 = load i32, i32* %7
%44 = load i8*, i8** %9
%45 = load i32, i32* %5
%46 = call i32 @full_read(i32 %43, i8* %44, i32 %45)
%47 = load i32, i32* %5
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = load i32, i32* @errno
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %50, i8* %52)
%54 = call i32 (...) @exit_failure()
br label %55
55: ; preds = %49, %42
%56 = load i8*, i8** %9
%57 = load i32, i32* %5
%58 = call i32 @check_chunk(i8* %56, i32 %57)
br label %64
59: ; preds = %38
%60 = load i32, i32* %7
%61 = load i32, i32* %5
%62 = load i32, i32* @SEEK_CUR
%63 = call i32 @lseek(i32 %60, i32 %61, i32 %62)
br label %64
64: ; preds = %59, %55
%65 = load i32, i32* %5
%66 = load i32, i32* %10
%67 = add nsw i32 %66, %65
store i32 %67, i32* %10
%68 = load i32, i32* %7
%69 = load i32, i32* @SEEK_CUR
%70 = call i32 @lseek(i32 %68, i32 0, i32 %69)
store i32 %70, i32* %11
%71 = load i32, i32* %8
%72 = icmp eq i32 %71, 0
br i1 %72, label %99, label %73
73: ; preds = %64
%74 = load i32, i32* %8
%75 = load i32, i32* %6
%76 = ashr i32 %75, 1
%77 = load i32, i32* %6
%78 = ashr i32 %77, 2
%79 = sub nsw i32 %76, %78
%80 = icmp eq i32 %74, %79
br i1 %80, label %99, label %81
81: ; preds = %73
%82 = load i32, i32* %8
%83 = load i32, i32* %6
%84 = ashr i32 %83, 1
%85 = icmp eq i32 %82, %84
br i1 %85, label %99, label %86
86: ; preds = %81
%87 = load i32, i32* %8
%88 = load i32, i32* %6
%89 = ashr i32 %88, 1
%90 = load i32, i32* %6
%91 = ashr i32 %90, 2
%92 = add nsw i32 %89, %91
%93 = icmp eq i32 %87, %92
br i1 %93, label %99, label %94
94: ; preds = %86
%95 = load i32, i32* %8
%96 = load i32, i32* %6
%97 = sub nsw i32 %96, 1
%98 = icmp eq i32 %95, %97
br i1 %98, label %99, label %115
99: ; preds = %94, %86, %81, %73, %64
%100 = load i32, i32* %8
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %99
br label %110
103: ; preds = %99
%104 = load i32, i32* %8
%105 = sitofp i32 %104 to double
%106 = load i32, i32* %6
%107 = sitofp i32 %106 to double
%108 = fdiv double %105, %107
%109 = fmul double %108, 1.000000e+02
br label %110
110: ; preds = %103, %102
%111 = phi double [ 0.000000e+00, %102 ], [ %109, %103 ]
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), double %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%114 = call i32 (...) @ckpt_and_exit()
br label %115
115: ; preds = %110, %94
%116 = load i32, i32* %11
%117 = load i32, i32* %10
%118 = icmp ne i32 %116, %117
br i1 %118, label %119, label %129
119: ; preds = %115
%120 = load i32, i32* @errno
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = load i32, i32* %10
%124 = sext i32 %123 to i64
%125 = load i32, i32* %11
%126 = sext i32 %125 to i64
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.5, i64 0, i64 0), i32 %120, i8* %122, i64 %124, i64 %126)
%128 = call i32 (...) @exit_failure()
br label %129
129: ; preds = %119, %115
br label %130
130: ; preds = %129
%131 = load i32, i32* %8
%132 = add nsw i32 %131, 1
store i32 %132, i32* %8
br label %34
133: ; preds = %34
%134 = load i32, i32* %7
%135 = call i32 @close(i32 %134)
%136 = load i8*, i8** %9
%137 = call i32 @free(i8* %136)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [62 x i8] c"ERROR: Failed to open the file '%s' for verification. %d(%s)\0A\00"
@errno = global i32 0
@.str.2 = [36 x i8] c"ERROR: Failed to read file: %d(%s)\0A\00"
@SEEK_CUR = global i32 0
@.str.3 = [49 x i8] c"Checkpointing at %.0lf%% of the file operation.\0A\00"
@.str.5 = [96 x i8] c"ERROR: lseek() failed %d(%s) to get current position of reading file. Expected %lld. Got %lld.\0A\00"
@str = [21 x i8] c"Skipping checkpoint!\00"
@str.6 = [22 x i8] c"ERROR: Out of memory!\00"
define void @check_a_file(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @srand(i32 0)
%5 = tail call i8* @calloc(i32 %1, i32 1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 (...) @exit_failure()
br label %10
10: ; preds = %7, %3
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %0, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %15, i8* %16)
%18 = tail call i32 (...) @exit_failure()
br label %19
19: ; preds = %14, %10
%20 = icmp sgt i32 %2, 0
br i1 %20, label %21, label %100
21: ; preds = %19
%22 = lshr i32 %2, 1
%23 = lshr i32 %2, 2
%24 = sub nsw i32 %22, %23
%25 = add nuw nsw i32 %22, %23
%26 = add nsw i32 %2, -1
%27 = sitofp i32 %2 to double
%28 = sext i32 %1 to i64
%29 = tail call i32 @full_read(i32 %12, i8* %5, i32 %1)
%30 = icmp eq i32 %29, %1
br i1 %30, label %36, label %31
31: ; preds = %21
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %33)
%35 = tail call i32 (...) @exit_failure()
br label %36
36: ; preds = %21, %31
%37 = tail call i32 @check_chunk(i8* %5, i32 %1)
%38 = load i32, i32* @SEEK_CUR
%39 = tail call i32 @lseek(i32 %12, i32 0, i32 %38)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), double 0.000000e+00)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%42 = tail call i32 (...) @ckpt_and_exit()
%43 = icmp eq i32 %39, %1
br i1 %43, label %50, label %44
44: ; preds = %36
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = sext i32 %39 to i64
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @.str.5, i64 0, i64 0), i32 %45, i8* %46, i64 %28, i64 %47)
%49 = tail call i32 (...) @exit_failure()
br label %50
50: ; preds = %44, %36
%51 = icmp eq i32 %2, 1
br i1 %51, label %100, label %52
52: ; preds = %50, %97
%53 = phi i64 [ %71, %97 ], [ %28, %50 ]
%54 = phi i32 [ %98, %97 ], [ 1, %50 ]
%55 = and i32 %54, 1023
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %67
57: ; preds = %52
%58 = tail call i32 @full_read(i32 %12, i8* %5, i32 %1)
%59 = icmp eq i32 %58, %1
br i1 %59, label %65, label %60
60: ; preds = %57
%61 = load i32, i32* @errno
%62 = tail call i8* @strerror(i32 %61)
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %61, i8* %62)
%64 = tail call i32 (...) @exit_failure()
br label %65
65: ; preds = %60, %57
%66 = tail call i32 @check_chunk(i8* %5, i32 %1)
br label %70
67: ; preds = %52
%68 = load i32, i32* @SEEK_CUR
%69 = tail call i32 @lseek(i32 %12, i32 %1, i32 %68)
br label %70
70: ; preds = %65, %67
%71 = add nsw i64 %53, %28
%72 = load i32, i32* @SEEK_CUR
%73 = tail call i32 @lseek(i32 %12, i32 0, i32 %72)
%74 = icmp eq i32 %54, %24
%75 = icmp eq i32 %54, %22
%76 = or i1 %74, %75
%77 = icmp eq i32 %54, %25
%78 = select i1 %76, i1 true, i1 %77
%79 = icmp eq i32 %54, %26
%80 = select i1 %78, i1 true, i1 %79
br i1 %80, label %81, label %88
81: ; preds = %70
%82 = sitofp i32 %54 to double
%83 = fdiv double %82, %27
%84 = fmul double %83, 1.000000e+02
%85 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), double %84)
%86 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%87 = tail call i32 (...) @ckpt_and_exit()
br label %88
88: ; preds = %70, %81
%89 = trunc i64 %71 to i32
%90 = icmp eq i32 %73, %89
br i1 %90, label %97, label %91
91: ; preds = %88
%92 = load i32, i32* @errno
%93 = tail call i8* @strerror(i32 %92)
%94 = sext i32 %73 to i64
%95 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @.str.5, i64 0, i64 0), i32 %92, i8* %93, i64 %71, i64 %94)
%96 = tail call i32 (...) @exit_failure()
br label %97
97: ; preds = %88, %91
%98 = add nuw nsw i32 %54, 1
%99 = icmp eq i32 %98, %2
br i1 %99, label %100, label %52
100: ; preds = %97, %50, %19
%101 = tail call i32 @close(i32 %12)
%102 = tail call i32 @free(i8* %5)
ret void
}