#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 */

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int get_random(char *, int);
int lseek(int, size_t, int /*<<< orphan*/);
char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ unlink(char *);
int write(int, ...);
int test_large() {
  char *buf;
  int fd, ret;
  size_t i, offset;
  unsigned char ch1, ch2;
  char *filename = "large-file-test.dat";
  buf = malloc(132 * 1024 * 1024);
  if (buf == NULL) {
    printf("Error allocating buffer.\n");
    return (1);
  }
  ret = get_random(buf, 132 * 1024 * 1024);
  if (ret != 132 * 1024 * 1024) {
    printf("Error reading random data.\n");
    return (1);
  }
  fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
  if (fd == -1) {
    printf("Error opening file %s for writing at line %d.\n", filename, 522);
    return (1);
  }
  ret = write(fd, buf, 132 * 1024 * 1024);
  if (ret != 132 * 1024 * 1024) {
    printf("Error writing last byte of the file.");
    return (1);
  }
  close(fd);
  fd = open(filename, O_RDWR);
  if (fd == -1) {
    printf("Error opening file %s for writing at line %d.\n", filename, 536);
    return (1);
  }
  for (i = 0; i < 132 * 1024 * 1024; i++) {
    ret = read(fd, &ch1, 1);
    if (ret != 1) {
      printf("Error reading file %s for writing.", filename);
      return (1);
    }
    ch2 = buf[i];
    if (ch1 != ch2) {
      printf("Unexpected contents: 0x%02x vs 0x%02x", ch1, ch2);
      return (1);
    }
  }
  offset = 128 * 1024 * 1024 - 157;
  for (i = offset; i < offset + 834; i++)
    buf[i] = buf[i] - i;
  ret = lseek(fd, offset, SEEK_SET);
  if (ret != (int)offset) {
    printf("Error seeking file %s for writing.", filename);
    return (1);
  }
  for (i = offset; i < offset + 834; i++) {
    ch1 = buf[i];
    ret = write(fd, &ch1, 1);
    if (ret != 1) {
      printf("Error writing file %s for writing.", filename);
      return (1);
    }
  }
  close(fd);
  fd = open(filename, O_RDWR);
  if (fd == -1) {
    printf("Error opening file %s for writing.", filename);
    return (1);
  }
  for (i = 0; i < 132 * 1024 * 1024; i++) {
    ret = read(fd, &ch1, 1);
    if (ret != 1) {
      printf("Error reading file %s for writing.", filename);
      return (1);
    }
    ch2 = buf[i];
    if (ch1 != ch2) {
      printf("Unexpected contents: 0x%02x vs 0x%02x", ch1, ch2);
      return (1);
    }
  }
  free(buf);
  close(fd);
  unlink(filename);
  return (0);
}


x86 assembly (clang, -O0):
<test_large>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe51(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    $0x8400000,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e6 <test_large+0x46>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x10(%rbp),%rdi
mov    $0x8400000,%esi
call   1050 <get_random@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x8400000,-0x18(%rbp)
je     121e <test_large+0x7e>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x38(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
mov    0x2db5(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1279 <test_large+0xd9>
mov    -0x38(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x20a,%edx
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8400000,%edx
mov    $0x0,%al
call   1060 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x8400000,-0x18(%rbp)
je     12b6 <test_large+0x116>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x38(%rbp),%rdi
mov    0x2d0f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1302 <test_large+0x162>
mov    -0x38(%rbp),%rsi
lea    0xd60(%rip),%rdi
mov    $0x218,%edx
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
movq   $0x0,-0x20(%rbp)
cmpq   $0x8400000,-0x20(%rbp)
08
jae    13aa <test_large+0x20a>
mov    -0x14(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     1354 <test_large+0x1b4>
mov    -0x38(%rbp),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2a(%rbp)
movzbl -0x29(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
cmp    %ecx,%eax
je     1394 <test_large+0x1f4>
movzbl -0x29(%rbp),%esi
movzbl -0x2a(%rbp),%edx
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
jmp    1399 <test_large+0x1f9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    130a <test_large+0x16a>
movq   $0x7ffff63,-0x28(%rbp)
07
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x342,%rcx
cmp    %rcx,%rax
jae    1401 <test_large+0x261>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
sub    -0x20(%rbp),%rax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    13ba <test_large+0x21a>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2bb9(%rip),%rax
mov    (%rax),%edx
call   1080 <lseek@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    %ecx,%eax
je     1446 <test_large+0x2a6>
mov    -0x38(%rbp),%rsi
lea    0xcb4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x342,%rcx
cmp    %rcx,%rax
jae    14c8 <test_large+0x328>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1060 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     14b2 <test_large+0x312>
mov    -0x38(%rbp),%rsi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
jmp    14b7 <test_large+0x317>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    144e <test_large+0x2ae>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x38(%rbp),%rdi
mov    0x2afd(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    150f <test_large+0x36f>
mov    -0x38(%rbp),%rsi
lea    0xc31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
movq   $0x0,-0x20(%rbp)
cmpq   $0x8400000,-0x20(%rbp)
08
jae    15b7 <test_large+0x417>
mov    -0x14(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     1561 <test_large+0x3c1>
mov    -0x38(%rbp),%rsi
lea    0xb50(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2a(%rbp)
movzbl -0x29(%rbp),%eax
movzbl -0x2a(%rbp),%ecx
cmp    %ecx,%eax
je     15a1 <test_large+0x401>
movzbl -0x29(%rbp),%esi
movzbl -0x2a(%rbp),%edx
lea    0xb33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d8 <test_large+0x438>
jmp    15a6 <test_large+0x406>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1517 <test_large+0x377>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x38(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_large>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x8400000,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1428 <test_large+0x278>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x8400000,%esi
call   1060 <get_random@plt>
cmp    $0x8400000,%eax
jne    1431 <test_large+0x281>
mov    0x2de7(%rip),%r15
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    0x2dec(%rip),%rax
or     (%rax),%esi
lea    0xe43(%rip),%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     144f <test_large+0x29f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x8400000,%edx
xor    %eax,%eax
call   1070 <write@plt>
cmp    $0x8400000,%eax
jne    1464 <test_large+0x2b4>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    (%r15),%esi
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1474 <test_large+0x2c4>
mov    %eax,%r12d
xor    %ebp,%ebp
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
cmp    $0x1,%eax
jne    1490 <test_large+0x2e0>
movzbl (%rbx,%rbp,1),%edx
movzbl 0xf(%rsp),%esi
cmp    %dl,%sil
jne    1499 <test_large+0x2e9>
add    $0x1,%rbp
cmp    $0x8400000,%rbp
jne    1270 <test_large+0xc0>
movdqa 0xd50(%rip),%xmm0
mov    $0x7ffff93,%eax
movdqa 0xd52(%rip),%xmm8
movdqa 0xd5a(%rip),%xmm2
movdqa 0xd62(%rip),%xmm3
movdqa 0xd6a(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
movdqu -0x30(%rbx,%rax,1),%xmm5
movdqu -0x20(%rbx,%rax,1),%xmm6
movdqu -0x10(%rbx,%rax,1),%xmm7
movdqu (%rbx,%rax,1),%xmm1
psubb  %xmm0,%xmm5
movdqu %xmm5,-0x30(%rbx,%rax,1)
psubb  %xmm0,%xmm6
psubb  %xmm8,%xmm6
movdqu %xmm6,-0x20(%rbx,%rax,1)
psubb  %xmm0,%xmm7
psubb  %xmm2,%xmm7
movdqu %xmm7,-0x10(%rbx,%rax,1)
psubb  %xmm0,%xmm1
psubb  %xmm3,%xmm1
movdqu %xmm1,(%rbx,%rax,1)
paddb  %xmm4,%xmm0
add    $0x40,%rax
cmp    $0x80002d3,%rax
jne    12e0 <test_large+0x130>
addb   $0x5d,0x80002a3(%rbx)
addb   $0x5c,0x80002a4(%rbx)
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
mov    $0x7ffff63,%ebp
mov    $0x7ffff63,%esi
mov    %r12d,%edi
call   1090 <lseek@plt>
cmp    $0x7ffff63,%eax
jne    14a9 <test_large+0x2f9>
lea    0xf(%rsp),%r14
movzbl (%rbx,%rbp,1),%eax
mov    %al,0xf(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <write@plt>
cmp    $0x1,%eax
jne    14b2 <test_large+0x302>
add    $0x1,%rbp
cmp    $0x80002a5,%rbp
jne    1374 <test_large+0x1c4>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    (%r15),%esi
lea    0xc9a(%rip),%rdi
xor    %eax,%eax
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     14bb <test_large+0x30b>
mov    %eax,%r15d
xor    %ebp,%ebp
lea    0xf(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
cmp    $0x1,%eax
jne    1490 <test_large+0x2e0>
movzbl (%rbx,%rbp,1),%edx
movzbl 0xf(%rsp),%esi
cmp    %dl,%sil
jne    1499 <test_large+0x2e9>
add    $0x1,%rbp
cmp    $0x8400000,%rbp
jne    13d0 <test_large+0x220>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
lea    0xc31(%rip),%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
jmp    1442 <test_large+0x292>
lea    0xd56(%rip),%rdi
jmp    1438 <test_large+0x288>
lea    0xd32(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc0e(%rip),%rdi
lea    0xbf3(%rip),%rsi
mov    $0x20a,%edx
jmp    1487 <test_large+0x2d7>
lea    0xc28(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    143d <test_large+0x28d>
lea    0xbe9(%rip),%rdi
lea    0xbce(%rip),%rsi
mov    $0x218,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    143d <test_large+0x28d>
lea    0xc21(%rip),%rdi
jmp    14c2 <test_large+0x312>
lea    0xc3b(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    143d <test_large+0x28d>
lea    0xc51(%rip),%rdi
jmp    14c2 <test_large+0x312>
lea    0xc6b(%rip),%rdi
jmp    14c2 <test_large+0x312>
lea    0xc85(%rip),%rdi
lea    0xb87(%rip),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    143d <test_large+0x28d>

LLVM IR (-O0):
@.str = [20 x i8] c"large-file-test.dat\00"
@.str.1 = [26 x i8] c"Error allocating buffer.\0A\00"
@.str.2 = [28 x i8] c"Error reading random data.\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [47 x i8] c"Error opening file %s for writing at line %d.\0A\00"
@.str.4 = [37 x i8] c"Error writing last byte of the file.\00"
@.str.5 = [35 x i8] c"Error reading file %s for writing.\00"
@.str.6 = [38 x i8] c"Unexpected contents: 0x%02x vs 0x%02x\00"
@SEEK_SET = global i32 0
@.str.7 = [35 x i8] c"Error seeking file %s for writing.\00"
@.str.8 = [35 x i8] c"Error writing file %s for writing.\00"
@.str.9 = [35 x i8] c"Error opening file %s for writing.\00"
define i32 @test_large() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = call i8* @malloc(i32 138412032)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %193
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = call i32 @get_random(i8* %16, i32 138412032)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 138412032
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %193
22: ; preds = %15
%23 = load i8*, i8** %9
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_CREAT
%26 = or i32 %24, %25
%27 = load i32, i32* @O_TRUNC
%28 = or i32 %26, %27
%29 = call i32 (i8*, i32, ...) @open(i8* %23, i32 %28, i32 384)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = load i8*, i8** %9
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %33, i32 522)
store i32 1, i32* %1
br label %193
35: ; preds = %22
%36 = load i32, i32* %3
%37 = load i8*, i8** %2
%38 = call i32 (i32, ...) @write(i32 %36, i8* %37, i32 138412032)
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 138412032
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %193
43: ; preds = %35
%44 = load i32, i32* %3
%45 = call i32 @close(i32 %44)
%46 = load i8*, i8** %9
%47 = load i32, i32* @O_RDWR
%48 = call i32 (i8*, i32, ...) @open(i8* %46, i32 %47)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = load i8*, i8** %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %52, i32 536)
store i32 1, i32* %1
br label %193
54: ; preds = %43
store i64 0, i64* %5
br label %55
55: ; preds = %83, %54
%56 = load i64, i64* %5
%57 = icmp ult i64 %56, 138412032
br i1 %57, label %58, label %86
58: ; preds = %55
%59 = load i32, i32* %3
%60 = call i32 @read(i32 %59, i8* %7, i32 1)
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 1
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i8*, i8** %9
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %64)
store i32 1, i32* %1
br label %193
66: ; preds = %58
%67 = load i8*, i8** %2
%68 = load i64, i64* %5
%69 = getelementptr inbounds i8, i8* %67, i64 %68
%70 = load i8, i8* %69
store i8 %70, i8* %8
%71 = load i8, i8* %7
%72 = zext i8 %71 to i32
%73 = load i8, i8* %8
%74 = zext i8 %73 to i32
%75 = icmp ne i32 %72, %74
br i1 %75, label %76, label %82
76: ; preds = %66
%77 = load i8, i8* %7
%78 = zext i8 %77 to i32
%79 = load i8, i8* %8
%80 = zext i8 %79 to i32
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %78, i32 %80)
store i32 1, i32* %1
br label %193
82: ; preds = %66
br label %83
83: ; preds = %82
%84 = load i64, i64* %5
%85 = add i64 %84, 1
store i64 %85, i64* %5
br label %55
86: ; preds = %55
store i64 134217571, i64* %6
%87 = load i64, i64* %6
store i64 %87, i64* %5
br label %88
88: ; preds = %105, %86
%89 = load i64, i64* %5
%90 = load i64, i64* %6
%91 = add i64 %90, 834
%92 = icmp ult i64 %89, %91
br i1 %92, label %93, label %108
93: ; preds = %88
%94 = load i8*, i8** %2
%95 = load i64, i64* %5
%96 = getelementptr inbounds i8, i8* %94, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i64
%99 = load i64, i64* %5
%100 = sub i64 %98, %99
%101 = trunc i64 %100 to i8
%102 = load i8*, i8** %2
%103 = load i64, i64* %5
%104 = getelementptr inbounds i8, i8* %102, i64 %103
store i8 %101, i8* %104
br label %105
105: ; preds = %93
%106 = load i64, i64* %5
%107 = add i64 %106, 1
store i64 %107, i64* %5
br label %88
108: ; preds = %88
%109 = load i32, i32* %3
%110 = load i64, i64* %6
%111 = load i32, i32* @SEEK_SET
%112 = call i32 @lseek(i32 %109, i64 %110, i32 %111)
store i32 %112, i32* %4
%113 = load i32, i32* %4
%114 = load i64, i64* %6
%115 = trunc i64 %114 to i32
%116 = icmp ne i32 %113, %115
br i1 %116, label %117, label %120
117: ; preds = %108
%118 = load i8*, i8** %9
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %118)
store i32 1, i32* %1
br label %193
120: ; preds = %108
%121 = load i64, i64* %6
store i64 %121, i64* %5
br label %122
122: ; preds = %140, %120
%123 = load i64, i64* %5
%124 = load i64, i64* %6
%125 = add i64 %124, 834
%126 = icmp ult i64 %123, %125
br i1 %126, label %127, label %143
127: ; preds = %122
%128 = load i8*, i8** %2
%129 = load i64, i64* %5
%130 = getelementptr inbounds i8, i8* %128, i64 %129
%131 = load i8, i8* %130
store i8 %131, i8* %7
%132 = load i32, i32* %3
%133 = call i32 (i32, ...) @write(i32 %132, i8* %7, i32 1)
store i32 %133, i32* %4
%134 = load i32, i32* %4
%135 = icmp ne i32 %134, 1
br i1 %135, label %136, label %139
136: ; preds = %127
%137 = load i8*, i8** %9
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %137)
store i32 1, i32* %1
br label %193
139: ; preds = %127
br label %140
140: ; preds = %139
%141 = load i64, i64* %5
%142 = add i64 %141, 1
store i64 %142, i64* %5
br label %122
143: ; preds = %122
%144 = load i32, i32* %3
%145 = call i32 @close(i32 %144)
%146 = load i8*, i8** %9
%147 = load i32, i32* @O_RDWR
%148 = call i32 (i8*, i32, ...) @open(i8* %146, i32 %147)
store i32 %148, i32* %3
%149 = load i32, i32* %3
%150 = icmp eq i32 %149, -1
br i1 %150, label %151, label %154
151: ; preds = %143
%152 = load i8*, i8** %9
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %152)
store i32 1, i32* %1
br label %193
154: ; preds = %143
store i64 0, i64* %5
br label %155
155: ; preds = %183, %154
%156 = load i64, i64* %5
%157 = icmp ult i64 %156, 138412032
br i1 %157, label %158, label %186
158: ; preds = %155
%159 = load i32, i32* %3
%160 = call i32 @read(i32 %159, i8* %7, i32 1)
store i32 %160, i32* %4
%161 = load i32, i32* %4
%162 = icmp ne i32 %161, 1
br i1 %162, label %163, label %166
163: ; preds = %158
%164 = load i8*, i8** %9
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %164)
store i32 1, i32* %1
br label %193
166: ; preds = %158
%167 = load i8*, i8** %2
%168 = load i64, i64* %5
%169 = getelementptr inbounds i8, i8* %167, i64 %168
%170 = load i8, i8* %169
store i8 %170, i8* %8
%171 = load i8, i8* %7
%172 = zext i8 %171 to i32
%173 = load i8, i8* %8
%174 = zext i8 %173 to i32
%175 = icmp ne i32 %172, %174
br i1 %175, label %176, label %182
176: ; preds = %166
%177 = load i8, i8* %7
%178 = zext i8 %177 to i32
%179 = load i8, i8* %8
%180 = zext i8 %179 to i32
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %178, i32 %180)
store i32 1, i32* %1
br label %193
182: ; preds = %166
br label %183
183: ; preds = %182
%184 = load i64, i64* %5
%185 = add i64 %184, 1
store i64 %185, i64* %5
br label %155
186: ; preds = %155
%187 = load i8*, i8** %2
%188 = call i32 @free(i8* %187)
%189 = load i32, i32* %3
%190 = call i32 @close(i32 %189)
%191 = load i8*, i8** %9
%192 = call i32 @unlink(i8* %191)
store i32 0, i32* %1
br label %193
193: ; preds = %186, %176, %163, %151, %136, %117, %76, %63, %51, %41, %32, %20, %13
%194 = load i32, i32* %1
ret i32 %194
}

LLVM IR (-O2):
@.str = [20 x i8] c"large-file-test.dat\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [47 x i8] c"Error opening file %s for writing at line %d.\0A\00"
@.str.4 = [37 x i8] c"Error writing last byte of the file.\00"
@.str.5 = [35 x i8] c"Error reading file %s for writing.\00"
@.str.6 = [38 x i8] c"Unexpected contents: 0x%02x vs 0x%02x\00"
@SEEK_SET = global i32 0
@.str.7 = [35 x i8] c"Error seeking file %s for writing.\00"
@.str.8 = [35 x i8] c"Error writing file %s for writing.\00"
@.str.9 = [35 x i8] c"Error opening file %s for writing.\00"
@str = [27 x i8] c"Error reading random data.\00"
@str.10 = [25 x i8] c"Error allocating buffer.\00"
define i32 @test_large() {
%1 = alloca i8
%2 = tail call dereferenceable_or_null(138412032) i8* @malloc(i32 138412032)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
br label %136
6: ; preds = %0
%7 = tail call i32 @get_random(i8* %2, i32 138412032)
%8 = icmp eq i32 %7, 138412032
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %136
11: ; preds = %6
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %13, %12
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %16, i32 384)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 522)
br label %136
21: ; preds = %11
%22 = tail call i32 (i32, ...) @write(i32 %17, i8* %2, i32 138412032)
%23 = icmp eq i32 %22, 138412032
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %136
26: ; preds = %21
%27 = tail call i32 @close(i32 %17)
%28 = load i32, i32* @O_RDWR
%29 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %69
31: ; preds = %26
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 536)
br label %136
33: ; preds = %75
%34 = add nuw nsw i64 %70, 1
%35 = icmp eq i64 %34, 138412032
br i1 %35, label %36, label %69
36: ; preds = %33, %36
%37 = phi i64 [ %66, %36 ], [ 0, %33 ]
%38 = phi <16 x i8> [ %67, %36 ], [ <i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112, i8 113, i8 114>, %33 ]
%39 = add nuw nsw i64 %37, 134217571
%40 = getelementptr inbounds i8, i8* %2, i64 %39
%41 = bitcast i8* %40 to <16 x i8>*
%42 = load <16 x i8>, <16 x i8>* %41
%43 = sub <16 x i8> %42, %38
%44 = bitcast i8* %40 to <16 x i8>*
store <16 x i8> %43, <16 x i8>* %44
%45 = add <16 x i8> %38, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%46 = add nuw nsw i64 %37, 134217587
%47 = getelementptr inbounds i8, i8* %2, i64 %46
%48 = bitcast i8* %47 to <16 x i8>*
%49 = load <16 x i8>, <16 x i8>* %48
%50 = sub <16 x i8> %49, %45
%51 = bitcast i8* %47 to <16 x i8>*
store <16 x i8> %50, <16 x i8>* %51
%52 = add <16 x i8> %38, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%53 = add nuw nsw i64 %37, 134217603
%54 = getelementptr inbounds i8, i8* %2, i64 %53
%55 = bitcast i8* %54 to <16 x i8>*
%56 = load <16 x i8>, <16 x i8>* %55
%57 = sub <16 x i8> %56, %52
%58 = bitcast i8* %54 to <16 x i8>*
store <16 x i8> %57, <16 x i8>* %58
%59 = add <16 x i8> %38, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%60 = add nuw nsw i64 %37, 134217619
%61 = getelementptr inbounds i8, i8* %2, i64 %60
%62 = bitcast i8* %61 to <16 x i8>*
%63 = load <16 x i8>, <16 x i8>* %62
%64 = sub <16 x i8> %63, %59
%65 = bitcast i8* %61 to <16 x i8>*
store <16 x i8> %64, <16 x i8>* %65
%66 = add nuw nsw i64 %37, 64
%67 = add <16 x i8> %38, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%68 = icmp eq i64 %66, 832
br i1 %68, label %84, label %36
69: ; preds = %26, %33
%70 = phi i64 [ %34, %33 ], [ 0, %26 ]
%71 = call i32 @read(i32 %29, i8* %1, i32 1)
%72 = icmp eq i32 %71, 1
br i1 %72, label %75, label %73
73: ; preds = %69
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %136
75: ; preds = %69
%76 = getelementptr inbounds i8, i8* %2, i64 %70
%77 = load i8, i8* %76
%78 = load i8, i8* %1
%79 = icmp eq i8 %78, %77
br i1 %79, label %33, label %80
80: ; preds = %75
%81 = zext i8 %77 to i32
%82 = zext i8 %78 to i32
%83 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %82, i32 %81)
br label %136
84: ; preds = %36
%85 = getelementptr inbounds i8, i8* %2, i64 134218403
%86 = load i8, i8* %85
%87 = add i8 %86, 93
store i8 %87, i8* %85
%88 = getelementptr inbounds i8, i8* %2, i64 134218404
%89 = load i8, i8* %88
%90 = add i8 %89, 92
store i8 %90, i8* %88
%91 = load i32, i32* @SEEK_SET
%92 = tail call i32 @lseek(i32 %29, i64 134217571, i32 %91)
%93 = icmp eq i32 %92, 134217571
br i1 %93, label %99, label %94
94: ; preds = %84
%95 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %136
96: ; preds = %99
%97 = add nuw nsw i64 %100, 1
%98 = icmp eq i64 %97, 134218405
br i1 %98, label %107, label %99
99: ; preds = %84, %96
%100 = phi i64 [ %97, %96 ], [ 134217571, %84 ]
%101 = getelementptr inbounds i8, i8* %2, i64 %100
%102 = load i8, i8* %101
store i8 %102, i8* %1
%103 = call i32 (i32, ...) @write(i32 %29, i8* %1, i32 1)
%104 = icmp eq i32 %103, 1
br i1 %104, label %96, label %105
105: ; preds = %99
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %136
107: ; preds = %96
%108 = call i32 @close(i32 %29)
%109 = load i32, i32* @O_RDWR
%110 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %109)
%111 = icmp eq i32 %110, -1
br i1 %111, label %112, label %117
112: ; preds = %107
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %136
114: ; preds = %123
%115 = add nuw nsw i64 %118, 1
%116 = icmp eq i64 %115, 138412032
br i1 %116, label %132, label %117
117: ; preds = %107, %114
%118 = phi i64 [ %115, %114 ], [ 0, %107 ]
%119 = call i32 @read(i32 %110, i8* %1, i32 1)
%120 = icmp eq i32 %119, 1
br i1 %120, label %123, label %121
121: ; preds = %117
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %136
123: ; preds = %117
%124 = getelementptr inbounds i8, i8* %2, i64 %118
%125 = load i8, i8* %124
%126 = load i8, i8* %1
%127 = icmp eq i8 %126, %125
br i1 %127, label %114, label %128
128: ; preds = %123
%129 = zext i8 %125 to i32
%130 = zext i8 %126 to i32
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %130, i32 %129)
br label %136
132: ; preds = %114
%133 = call i32 @free(i8* %2)
%134 = call i32 @close(i32 %110)
%135 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %136
136: ; preds = %132, %128, %121, %112, %105, %94, %80, %73, %31, %24, %19, %9, %4
%137 = phi i32 [ 1, %4 ], [ 1, %9 ], [ 1, %19 ], [ 1, %24 ], [ 1, %31 ], [ 1, %73 ], [ 1, %80 ], [ 1, %94 ], [ 1, %105 ], [ 1, %112 ], [ 1, %121 ], [ 1, %128 ], [ 0, %132 ]
ret i32 %137
}