#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*/ ssize_t;
typedef int /*<<< orphan*/ oldbuf;
typedef int /*<<< orphan*/ newbuf;
typedef int /*<<< orphan*/ kOldFileData;
typedef int /*<<< orphan*/ kNewFileData;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ errx(int, char *, char const *, ...);
scalar_t__ ftruncate(int const, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, size_t const, int /*<<< orphan*/,
           int /*<<< orphan*/, int const, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ pread(int const, char *, int, int /*<<< orphan*/);
scalar_t__ strcmp(void *, char const *);
int /*<<< orphan*/ strlen(char const *);
size_t sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *, char const *, ...);
int /*<<< orphan*/ write(int const, char const *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  const char kTestFilePath[] = "copy_up_testfile.txt";
  const char kOldFileData[] = "old data\n";
  const char kNewFileData[] = "new data\n";
  const size_t kPageSize = sysconf(_SC_PAGE_SIZE);
  const int fd_rdonly = open(kTestFilePath, O_RDONLY);
  if (fd_rdonly < 0) {
    err(1, "open(%s, O_RDONLY)", kTestFilePath);
  }
  char oldbuf[sizeof(kOldFileData)] = {};
  ssize_t n = pread(fd_rdonly, oldbuf, sizeof(oldbuf), 0);
  if (n < 0) {
    err(1, "initial pread");
  }
  if (n != strlen(kOldFileData)) {
    errx(1, "short initial pread (%ld/%lu bytes)", n, strlen(kOldFileData));
  }
  if (strcmp(oldbuf, kOldFileData) != 0) {
    errx(1, "initial pread returned wrong data: %s", oldbuf);
  }
  void *page = mmap(NULL, kPageSize, PROT_READ, MAP_SHARED, fd_rdonly, 0);
  if (page == MAP_FAILED) {
    err(1, "mmap");
  }
  if (strcmp(page, kOldFileData) != 0) {
    errx(1, "mapping contains wrong initial data: %s", (const char *)page);
  }
  const int fd_rdwr = open(kTestFilePath, O_RDWR);
  if (fd_rdwr < 0) {
    err(1, "open(%s, O_RDWR)", kTestFilePath);
  }
  n = write(fd_rdwr, kNewFileData, strlen(kNewFileData));
  if (n < 0) {
    err(1, "write");
  }
  if (n != strlen(kNewFileData)) {
    errx(1, "short write (%ld/%lu bytes)", n, strlen(kNewFileData));
  }
  if (ftruncate(fd_rdwr, strlen(kNewFileData)) < 0) {
    err(1, "truncate");
  }
  int failed = 0;
  char newbuf[sizeof(kNewFileData)] = {};
  n = pread(fd_rdonly, newbuf, sizeof(newbuf), 0);
  if (n < 0) {
    err(1, "final pread");
  }
  if (n != strlen(kNewFileData)) {
    warnx("short final pread (%ld/%lu bytes)", n, strlen(kNewFileData));
    failed = 1;
  } else if (strcmp(newbuf, kNewFileData) != 0) {
    warnx("final pread returned wrong data: %s", newbuf);
    failed = 1;
  }
  if (strcmp(page, kNewFileData) != 0) {
    warnx("mapping contains wrong final data: %s", (const char *)page);
    failed = 1;
  }
  return failed;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe20(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe1d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe1b(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe16(%rip),%al
mov    %al,-0x1c(%rbp)
mov    0xe0d(%rip),%rax
mov    %rax,-0x3a(%rbp)
mov    0xe0a(%rip),%ax
mov    %ax,-0x32(%rbp)
mov    0xe01(%rip),%rax
mov    %rax,-0x44(%rbp)
mov    0xdfe(%rip),%ax
mov    %ax,-0x3c(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   10d0 <sysconf@plt>
mov    %rax,-0x50(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1275 <main+0xb5>
lea    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
lea    -0x5e(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <memset@plt>
mov    -0x54(%rbp),%edi
lea    -0x5e(%rbp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   10e0 <pread@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    12b8 <main+0xf8>
mov    $0x1,%edi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x88(%rbp)
lea    -0x3a(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
cmp    %ecx,%eax
je     130a <main+0x14a>
movslq -0x64(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x3a(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x90(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
lea    -0x5e(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1338 <main+0x178>
lea    -0x5e(%rbp),%rdx
mov    $0x1,%edi
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
mov    -0x50(%rbp),%rsi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
mov    0x2c9c(%rip),%rax
mov    (%rax),%ecx
mov    -0x54(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    0x2c4b(%rip),%rcx
cmp    (%rcx),%rax
jne    1389 <main+0x1c9>
mov    $0x1,%edi
lea    0xd12(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x70(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     13b7 <main+0x1f7>
mov    -0x70(%rbp),%rdx
mov    $0x1,%edi
lea    0xce9(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
lea    -0x30(%rbp),%rdi
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    13ed <main+0x22d>
lea    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x44(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    143e <main+0x27e>
mov    $0x1,%edi
lea    0xc9b(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0xa0(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xa0(%rbp),%eax
cmp    %ecx,%eax
je     1490 <main+0x2d0>
movslq -0x64(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa8(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    %eax,%esi
call   1080 <ftruncate@plt>
cmp    $0x0,%rax
jge    14cc <main+0x30c>
mov    $0x1,%edi
lea    0xc2f(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
movl   $0x0,-0x78(%rbp)
lea    -0x82(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <memset@plt>
mov    -0x54(%rbp),%edi
lea    -0x82(%rbp),%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
call   10e0 <pread@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    151c <main+0x35c>
mov    $0x1,%edi
lea    0xbe8(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0xb0(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%eax
cmp    %ecx,%eax
je     1575 <main+0x3b5>
movslq -0x64(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
lea    0xba7(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
movl   $0x1,-0x78(%rbp)
jmp    15b0 <main+0x3f0>
lea    -0x82(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     15ab <main+0x3eb>
lea    -0x82(%rbp),%rsi
lea    0xb8e(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
movl   $0x1,-0x78(%rbp)
jmp    15b0 <main+0x3f0>
mov    -0x70(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     15e0 <main+0x420>
mov    -0x70(%rbp),%rsi
lea    0xb7d(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
movl   $0x1,-0x78(%rbp)
mov    -0x78(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps 0xe3f(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movabs $0x7478742e656c69,%rax
mov    %rax,0x4d(%rsp)
movabs $0x6174616420646c6f,%rax
61 74 61
mov    %rax,0x10(%rsp)
movw   $0xa,0x18(%rsp)
movabs $0x617461642077656e,%rax
61 74 61
mov    %rax,(%rsp)
movw   $0xa,0x8(%rsp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
mov    %rax,%rbx
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    0x40(%rsp),%rdi
call   10b0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1243 <main+0x93>
lea    0xdf7(%rip),%rsi
lea    0x40(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
movw   $0x0,0x38(%rsp)
movq   $0x0,0x30(%rsp)
lea    0x30(%rsp),%rsi
mov    %r14d,%edi
mov    $0xa,%edx
xor    %ecx,%ecx
call   10d0 <pread@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1280 <main+0xd0>
lea    0xdc8(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
je     12b3 <main+0x103>
movslq %ebp,%rbp
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
lea    0xda8(%rip),%rsi
mov    $0x1,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <errx@plt>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12df <main+0x12f>
lea    0xda0(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
mov    0x2cf9(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%r15
mov    0x2cad(%rip),%rax
cmp    (%rax),%r15
jne    1323 <main+0x173>
lea    0xd7d(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     134b <main+0x19b>
lea    0xd5d(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%esi
lea    0x40(%rsp),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    137c <main+0x1cc>
lea    0xd56(%rip),%rsi
lea    0x40(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    13ac <main+0x1fc>
lea    0xd32(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebx
je     13db <main+0x22b>
movslq %ebx,%rbx
mov    %rsp,%rdi
call   1040 <strlen@plt>
lea    0xd0e(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <errx@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1080 <ftruncate@plt>
test   %rax,%rax
jns    1404 <main+0x254>
lea    0xcfc(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
movw   $0x0,0x28(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0xa,%edx
xor    %ecx,%ecx
call   10d0 <pread@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1441 <main+0x291>
lea    0xcc8(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <err@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebx
jne    1474 <main+0x2c4>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1499 <main+0x2e9>
lea    0xcc5(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    1492 <main+0x2e2>
movslq %ebx,%rbx
mov    %rsp,%rdi
call   1040 <strlen@plt>
lea    0xc83(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <warnx@plt>
mov    $0x1,%ebx
jmp    149b <main+0x2eb>
xor    %ebx,%ebx
mov    %rsp,%rsi
mov    %r15,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     14c1 <main+0x311>
lea    0xc9d(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <warnx@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.kTestFilePath = [21 x i8] c"copy_up_testfile.txt\00"
@__const.main.kOldFileData = [10 x i8] c"old data\0A\00"
@__const.main.kNewFileData = [10 x i8] c"new data\0A\00"
@_SC_PAGE_SIZE = global i32 0
@O_RDONLY = global i32 0
@.str = [19 x i8] c"open(%s, O_RDONLY)\00"
@.str.1 = [14 x i8] c"initial pread\00"
@.str.2 = [36 x i8] c"short initial pread (%ld/%lu bytes)\00"
@.str.3 = [38 x i8] c"initial pread returned wrong data: %s\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [40 x i8] c"mapping contains wrong initial data: %s\00"
@O_RDWR = global i32 0
@.str.6 = [17 x i8] c"open(%s, O_RDWR)\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [28 x i8] c"short write (%ld/%lu bytes)\00"
@.str.9 = [9 x i8] c"truncate\00"
@.str.10 = [12 x i8] c"final pread\00"
@.str.11 = [34 x i8] c"short final pread (%ld/%lu bytes)\00"
@.str.12 = [36 x i8] c"final pread returned wrong data: %s\00"
@.str.13 = [38 x i8] c"mapping contains wrong final data: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8]
%7 = alloca [10 x i8]
%8 = alloca [10 x i8]
%9 = alloca i64
%10 = alloca i32
%11 = alloca [10 x i8]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [21 x i8]* %6 to i8*
%18 = bitcast [10 x i8]* %7 to i8*
%19 = bitcast [10 x i8]* %8 to i8*
%20 = load i32, i32* @_SC_PAGE_SIZE
%21 = call i64 @sysconf(i32 %20)
store i64 %21, i64* %9
%22 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%29 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %2
%31 = bitcast [10 x i8]* %11 to i8*
%32 = load i32, i32* %10
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%34 = call i32 @pread(i32 %32, i8* %33, i32 10, i32 0)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = load i32, i32* %12
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = icmp ne i32 %40, %42
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i8*
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %47, i32 %49)
br label %51
51: ; preds = %44, %39
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%54 = call i64 @strcmp(i8* %52, i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%58 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %51
%60 = load i64, i64* %9
%61 = load i32, i32* @PROT_READ
%62 = load i32, i32* @MAP_SHARED
%63 = load i32, i32* %10
%64 = call i8* @mmap(i32* null, i64 %60, i32 %61, i32 %62, i32 %63, i32 0)
store i8* %64, i8** %13
%65 = load i8*, i8** %13
%66 = load i8*, i8** @MAP_FAILED
%67 = icmp eq i8* %65, %66
br i1 %67, label %68, label %70
68: ; preds = %59
%69 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68, %59
%71 = load i8*, i8** %13
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%73 = call i64 @strcmp(i8* %71, i8* %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = load i8*, i8** %13
%77 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %75, %70
%79 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%80 = load i32, i32* @O_RDWR
%81 = call i32 @open(i8* %79, i32 %80)
store i32 %81, i32* %14
%82 = load i32, i32* %14
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %78
%85 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%86 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %84, %78
%88 = load i32, i32* %14
%89 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%90 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%91 = call i32 @strlen(i8* %90)
%92 = call i32 @write(i32 %88, i8* %89, i32 %91)
store i32 %92, i32* %12
%93 = load i32, i32* %12
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %87
%96 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %97
97: ; preds = %95, %87
%98 = load i32, i32* %12
%99 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%100 = call i32 @strlen(i8* %99)
%101 = icmp ne i32 %98, %100
br i1 %101, label %102, label %109
102: ; preds = %97
%103 = load i32, i32* %12
%104 = sext i32 %103 to i64
%105 = inttoptr i64 %104 to i8*
%106 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%107 = call i32 @strlen(i8* %106)
%108 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %105, i32 %107)
br label %109
109: ; preds = %102, %97
%110 = load i32, i32* %14
%111 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%112 = call i32 @strlen(i8* %111)
%113 = call i64 @ftruncate(i32 %110, i32 %112)
%114 = icmp slt i64 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %109
%116 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
br label %117
117: ; preds = %115, %109
store i32 0, i32* %15
%118 = bitcast [10 x i8]* %16 to i8*
%119 = load i32, i32* %10
%120 = getelementptr inbounds [10 x i8], [10 x i8]* %16, i64 0, i64 0
%121 = call i32 @pread(i32 %119, i8* %120, i32 10, i32 0)
store i32 %121, i32* %12
%122 = load i32, i32* %12
%123 = icmp slt i32 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %117
%125 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
br label %126
126: ; preds = %124, %117
%127 = load i32, i32* %12
%128 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%129 = call i32 @strlen(i8* %128)
%130 = icmp ne i32 %127, %129
br i1 %130, label %131, label %138
131: ; preds = %126
%132 = load i32, i32* %12
%133 = sext i32 %132 to i64
%134 = inttoptr i64 %133 to i8*
%135 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%136 = call i32 @strlen(i8* %135)
%137 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %134, i32 %136)
store i32 1, i32* %15
br label %147
138: ; preds = %126
%139 = getelementptr inbounds [10 x i8], [10 x i8]* %16, i64 0, i64 0
%140 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%141 = call i64 @strcmp(i8* %139, i8* %140)
%142 = icmp ne i64 %141, 0
br i1 %142, label %143, label %146
143: ; preds = %138
%144 = getelementptr inbounds [10 x i8], [10 x i8]* %16, i64 0, i64 0
%145 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i8* %144)
store i32 1, i32* %15
br label %146
146: ; preds = %143, %138
br label %147
147: ; preds = %146, %131
%148 = load i8*, i8** %13
%149 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%150 = call i64 @strcmp(i8* %148, i8* %149)
%151 = icmp ne i64 %150, 0
br i1 %151, label %152, label %155
152: ; preds = %147
%153 = load i8*, i8** %13
%154 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.13, i64 0, i64 0), i8* %153)
store i32 1, i32* %15
br label %155
155: ; preds = %152, %147
%156 = load i32, i32* %15
ret i32 %156
}

LLVM IR (-O2):
@__const.main.kTestFilePath = [21 x i8] c"copy_up_testfile.txt\00"
@__const.main.kOldFileData = [10 x i8] c"old data\0A\00"
@__const.main.kNewFileData = [10 x i8] c"new data\0A\00"
@_SC_PAGE_SIZE = global i32 0
@O_RDONLY = global i32 0
@.str = [19 x i8] c"open(%s, O_RDONLY)\00"
@.str.1 = [14 x i8] c"initial pread\00"
@.str.2 = [36 x i8] c"short initial pread (%ld/%lu bytes)\00"
@.str.3 = [38 x i8] c"initial pread returned wrong data: %s\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [40 x i8] c"mapping contains wrong initial data: %s\00"
@O_RDWR = global i32 0
@.str.6 = [17 x i8] c"open(%s, O_RDWR)\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [28 x i8] c"short write (%ld/%lu bytes)\00"
@.str.9 = [9 x i8] c"truncate\00"
@.str.10 = [12 x i8] c"final pread\00"
@.str.11 = [34 x i8] c"short final pread (%ld/%lu bytes)\00"
@.str.12 = [36 x i8] c"final pread returned wrong data: %s\00"
@.str.13 = [38 x i8] c"mapping contains wrong final data: %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [21 x i8]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
%7 = alloca [10 x i8]
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @_SC_PAGE_SIZE
%12 = tail call i64 @sysconf(i32 %11)
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %8, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %18
18: ; preds = %16, %2
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%20 = call i32 @pread(i32 %14, i8* %19, i32 10, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = call i32 @strlen(i8* %9)
%26 = icmp eq i32 %20, %25
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = sext i32 %20 to i64
%29 = inttoptr i64 %28 to i8*
%30 = call i32 @strlen(i8* %9)
%31 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %30)
br label %32
32: ; preds = %27, %24
%33 = call i64 @strcmp(i8* %19, i8* %9)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %37
37: ; preds = %35, %32
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @MAP_SHARED
%40 = call i8* @mmap(i32* null, i64 %12, i32 %38, i32 %39, i32 %14, i32 0)
%41 = load i8*, i8** @MAP_FAILED
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
%46 = call i64 @strcmp(i8* %40, i8* %9)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %40)
br label %50
50: ; preds = %48, %45
%51 = load i32, i32* @O_RDWR
%52 = call i32 @open(i8* %8, i32 %51)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %56
56: ; preds = %54, %50
%57 = call i32 @strlen(i8* %10)
%58 = call i32 @write(i32 %52, i8* %10, i32 %57)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = call i32 @strlen(i8* %10)
%64 = icmp eq i32 %58, %63
br i1 %64, label %70, label %65
65: ; preds = %62
%66 = sext i32 %58 to i64
%67 = inttoptr i64 %66 to i8*
%68 = call i32 @strlen(i8* %10)
%69 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %67, i32 %68)
br label %70
70: ; preds = %65, %62
%71 = call i32 @strlen(i8* %10)
%72 = call i64 @ftruncate(i32 %52, i32 %71)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
br label %76
76: ; preds = %74, %70
%77 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%78 = call i32 @pread(i32 %14, i8* %77, i32 10, i32 0)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
br label %82
82: ; preds = %80, %76
%83 = call i32 @strlen(i8* %10)
%84 = icmp eq i32 %78, %83
br i1 %84, label %90, label %85
85: ; preds = %82
%86 = sext i32 %78 to i64
%87 = inttoptr i64 %86 to i8*
%88 = call i32 @strlen(i8* %10)
%89 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %87, i32 %88)
br label %95
90: ; preds = %82
%91 = call i64 @strcmp(i8* %77, i8* %10)
%92 = icmp eq i64 %91, 0
br i1 %92, label %95, label %93
93: ; preds = %90
%94 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i8* %77)
br label %95
95: ; preds = %90, %93, %85
%96 = phi i32 [ 1, %85 ], [ 1, %93 ], [ 0, %90 ]
%97 = call i64 @strcmp(i8* %40, i8* %10)
%98 = icmp eq i64 %97, 0
br i1 %98, label %101, label %99
99: ; preds = %95
%100 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.13, i64 0, i64 0), i8* %40)
br label %101
101: ; preds = %99, %95
%102 = phi i32 [ 1, %99 ], [ %96, %95 ]
ret i32 %102
}