#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ ftruncate(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, ...);
int /*<<< orphan*/ reverse_and_write(int *, char **, int *, char *, char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ret = 1;
  int line1 = 0, line2 = 0, lineout = 0;
  struct timeval before, after;
  int duration;
  int fd1, fd2, fdout;
  char *file1, *file2, *fileout, *temp_out;
  char *pfile1, *pfile2, *pfileout, *cfile;
  int rsize1, rsize2, *csize;
  int currentFile;
  int flag = PROT_WRITE | PROT_READ;
  char *head;
  int filesize1, filesize2;
  struct stat tempbuf1, tempbuf2;
  if (argc != 4) {
    fprintf(stderr, "usage: %s file1 file2 fout\n", argv[0]);
    goto leave0;
  }
  if ((fd1 = open(argv[1], O_RDWR | O_CREAT)) < 0) {
    perror(argv[1]);
    goto leave0;
  }
  if ((fd2 = open(argv[2], O_RDWR | O_CREAT)) < 0) {
    perror(argv[2]);
    goto leave1;
  }
  fstat(fd1, &tempbuf1);
  fstat(fd2, &tempbuf2);
  filesize1 = tempbuf1.st_size;
  filesize2 = tempbuf2.st_size;
  printf("size1 : %d, size2 : %d", filesize1, filesize2);
  if ((fdout = open(argv[3], O_RDWR | O_CREAT, 0644)) < 0) {
    perror(argv[3]);
    goto leave2;
  }
  write(fdout, NULL, 0);
  ftruncate(fdout, filesize1 + filesize2);
  if ((file1 = mmap(0, filesize1, flag, MAP_SHARED, fd1, 0)) == NULL) {
    perror("mmap error");
    goto leave3;
  }
  if ((file2 = mmap(0, filesize2, flag, MAP_SHARED, fd2, 0)) == NULL) {
    perror("mmap error");
    goto leave4;
  }
  if ((fileout = mmap(0, filesize1 + filesize2, flag, MAP_SHARED, fdout, 0)) ==
      NULL) {
    perror("mmap error");
    goto leave5;
  }
  gettimeofday(&before, NULL);
  pfile1 = file1;
  pfile2 = file2;
  pfileout = fileout;
  rsize1 = filesize1;
  rsize2 = filesize2;
  currentFile = 1;
  head = pfile1;
  while (rsize1 && rsize2) {
    if (currentFile == 1) {
      reverse_and_write(&rsize1, &pfile1, &line1, head, &pfileout);
      currentFile = 2;
      head = pfile2;
    } else if (currentFile == 2) {
      reverse_and_write(&rsize2, &pfile2, &line2, head, &pfileout);
      currentFile = 1;
      head = pfile1;
    }
  }
  exit(0);
  while (rsize1) {
    reverse_and_write(&rsize1, &pfile1, &line1, head, &pfileout);
    head = pfile1;
  }
  while (rsize2) {
    reverse_and_write(&rsize2, &pfile2, &line2, head, &pfileout);
    head = pfile2;
  }
  gettimeofday(&after, NULL);
  lineout = line1 + line2;
  duration = (after.tv_sec - before.tv_sec) * 1000000 +
             (after.tv_usec - before.tv_usec);
  printf("Processing time = %d.%06d sec\n", duration / 1000000,
         duration % 1000000);
  printf("File1 = %d, File2= %d, Total = %d Lines\n", line1, line2, lineout);
  ret = 0;
leave6:
  munmap(fileout, filesize1 + filesize2);
leave5:
  munmap(file2, filesize2);
leave4:
  munmap(file1, filesize1);
leave3:
  close(fdout);
leave2:
  close(fd2);
leave1:
  close(fd1);
leave0:
  return ret;
}


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)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    0x2ddb(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1248 <main+0x78>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc2(%rip),%rsi
call   1090 <fprintf@plt>
jmp    15a3 <main+0x3d3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    1287 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <perror@plt>
jmp    15a3 <main+0x3d3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    12c6 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <perror@plt>
jmp    159b <main+0x3cb>
mov    -0x38(%rbp),%edi
lea    -0xb0(%rbp),%rsi
call   10f0 <fstat@plt>
mov    -0x3c(%rbp),%edi
lea    -0xb8(%rbp),%rsi
call   10f0 <fstat@plt>
mov    -0xb0(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0xb8(%rbp),%eax
mov    %eax,-0xa8(%rbp)
mov    -0xa4(%rbp),%esi
mov    -0xa8(%rbp),%edx
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
mov    0x2cca(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jge    135a <main+0x18a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <perror@plt>
jmp    1593 <main+0x3c3>
mov    -0x40(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <write@plt>
mov    -0x40(%rbp),%edi
mov    -0xa4(%rbp),%esi
add    -0xa8(%rbp),%esi
call   1060 <ftruncate@plt>
mov    -0xa4(%rbp),%esi
mov    -0x98(%rbp),%edx
mov    0x2c51(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    13bf <main+0x1ef>
lea    0xc7e(%rip),%rdi
call   10d0 <perror@plt>
jmp    158b <main+0x3bb>
mov    -0xa8(%rbp),%esi
mov    -0x98(%rbp),%edx
mov    0x2c0e(%rip),%rax
mov    (%rax),%ecx
mov    -0x3c(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1402 <main+0x232>
lea    0xc3b(%rip),%rdi
call   10d0 <perror@plt>
jmp    157c <main+0x3ac>
mov    -0xa4(%rbp),%esi
add    -0xa8(%rbp),%esi
mov    -0x98(%rbp),%edx
mov    0x2bc5(%rip),%rax
mov    (%rax),%ecx
mov    -0x40(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    144b <main+0x27b>
lea    0xbf2(%rip),%rdi
call   10d0 <perror@plt>
jmp    156d <main+0x39d>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0xa4(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0xa8(%rbp),%eax
mov    %eax,-0x88(%rbp)
movl   $0x1,-0x94(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0xa0(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x84(%rbp)
mov    %al,-0xb9(%rbp)
je     14c2 <main+0x2f2>
cmpl   $0x0,-0x88(%rbp)
setne  %al
mov    %al,-0xb9(%rbp)
mov    -0xb9(%rbp),%al
test   $0x1,%al
jne    14d5 <main+0x305>
jmp    1566 <main+0x396>
cmpl   $0x1,-0x94(%rbp)
jne    151b <main+0x34b>
mov    -0xa0(%rbp),%rcx
lea    -0x84(%rbp),%rdi
lea    -0x68(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x78(%rbp),%r8
call   10a0 <reverse_and_write@plt>
movl   $0x2,-0x94(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0xa0(%rbp)
jmp    1561 <main+0x391>
cmpl   $0x2,-0x94(%rbp)
jne    155c <main+0x38c>
mov    -0xa0(%rbp),%rcx
lea    -0x88(%rbp),%rdi
lea    -0x70(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x78(%rbp),%r8
call   10a0 <reverse_and_write@plt>
movl   $0x1,-0x94(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0xa0(%rbp)
jmp    1561 <main+0x391>
jmp    149d <main+0x2cd>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0xa8(%rbp),%esi
call   10b0 <munmap@plt>
mov    -0x48(%rbp),%rdi
mov    -0xa4(%rbp),%esi
call   10b0 <munmap@plt>
mov    -0x40(%rbp),%edi
call   1080 <close@plt>
mov    -0x3c(%rbp),%edi
call   1080 <close@plt>
mov    -0x38(%rbp),%edi
call   1080 <close@plt>
mov    -0x14(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
movl   $0x0,0x3c(%rsp)
movl   $0x0,0x38(%rsp)
cmp    $0x4,%edi
je     1222 <main+0x52>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf7(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8f(%rip),%rax
mov    0x2dc0(%rip),%rcx
mov    (%rcx),%r14d
or     (%rax),%r14d
mov    0x8(%rbx),%rdi
mov    0x2d8f(%rip),%r12
mov    0x2db0(%rip),%r13
mov    0x0(%r13),%esi
or     (%r12),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
jns    1266 <main+0x96>
mov    0x8(%rbx),%rdi
call   10d0 <perror@plt>
jmp    120e <main+0x3e>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
mov    0x0(%r13),%esi
or     (%r12),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
jns    128e <main+0xbe>
mov    0x10(%rbx),%rdi
call   10d0 <perror@plt>
jmp    13e3 <main+0x213>
mov    %eax,%ebp
lea    0x30(%rsp),%rsi
mov    %r15d,%edi
call   10f0 <fstat@plt>
lea    0x28(%rsp),%rsi
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
call   10f0 <fstat@plt>
mov    0x30(%rsp),%ebp
mov    0x28(%rsp),%edx
lea    0xd60(%rip),%rdi
mov    %ebp,%esi
mov    %rdx,0x18(%rsp)
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%rdi
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
jns    12f8 <main+0x128>
mov    0x18(%rbx),%rdi
call   10d0 <perror@plt>
mov    0xc(%rsp),%ebx
jmp    13dc <main+0x20c>
mov    %eax,%r12d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <write@plt>
mov    0x18(%rsp),%rbx
lea    (%rbx,%rbp,1),%esi
mov    %r12d,%edi
mov    %esi,0x34(%rsp)
call   1060 <ftruncate@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbp,0x20(%rsp)
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
jne    1354 <main+0x184>
lea    0xced(%rip),%rdi
call   10d0 <perror@plt>
mov    0xc(%rsp),%ebx
jmp    13d4 <main+0x204>
mov    %rax,%r13
mov    %rbx,%rsi
mov    0x2c7f(%rip),%rbp
mov    0x0(%rbp),%ecx
xor    %edi,%edi
mov    %r14d,%edx
mov    0xc(%rsp),%ebx
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
jne    138b <main+0x1bb>
lea    0xcaf(%rip),%rdi
call   10d0 <perror@plt>
jmp    13c7 <main+0x1f7>
mov    %rax,0x40(%rsp)
mov    0x0(%rbp),%ecx
xor    %edi,%edi
mov    0x34(%rsp),%esi
mov    %r14d,%edx
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
test   %rax,%rax
jne    13f0 <main+0x220>
lea    0xc80(%rip),%rdi
call   10d0 <perror@plt>
mov    0x40(%rsp),%rdi
mov    0x18(%rsp),%rsi
call   10b0 <munmap@plt>
mov    0x20(%rsp),%rsi
mov    %r13,%rdi
call   10b0 <munmap@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    %r15d,%edi
call   1080 <close@plt>
jmp    120e <main+0x3e>
mov    %rax,%rbp
lea    0x60(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    %r13,0x58(%rsp)
mov    0x40(%rsp),%rax
mov    %rax,0x50(%rsp)
mov    %rbp,0x48(%rsp)
mov    0x20(%rsp),%rax
mov    %eax,0x14(%rsp)
mov    0x18(%rsp),%rcx
mov    %ecx,0x10(%rsp)
test   %eax,%eax
je     14a2 <main+0x2d2>
cmpl   $0x0,0x18(%rsp)
je     14a2 <main+0x2d2>
mov    $0x1,%eax
lea    0x58(%rsp),%r12
lea    0x48(%rsp),%rbx
lea    0x50(%rsp),%rbp
lea    0x10(%rsp),%r14
lea    0x38(%rsp),%r15
cmp    $0x1,%eax
jne    1475 <main+0x2a5>
lea    0x14(%rsp),%rdi
mov    %r12,%rsi
lea    0x3c(%rsp),%rdx
mov    %r13,%rcx
mov    %rbx,%r8
call   10a0 <reverse_and_write@plt>
mov    $0x2,%eax
mov    %rbp,%rcx
jmp    1491 <main+0x2c1>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
call   10a0 <reverse_and_write@plt>
mov    $0x1,%eax
mov    %r12,%rcx
cmpl   $0x0,0x14(%rsp)
je     14a2 <main+0x2d2>
mov    (%rcx),%r13
cmpl   $0x0,0x10(%rsp)
jne    144e <main+0x27e>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.stat = type { i32 }
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s file1 file2 fout\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"size1 : %d, size2 : %d\00"
@MAP_SHARED = global i32 0
@.str.2 = [11 x i8] c"mmap error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8*
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32*
%27 = alloca i32
%28 = alloca i32
%29 = alloca i8*
%30 = alloca i32
%31 = alloca i32
%32 = alloca %struct.stat
%33 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%34 = load i32, i32* @PROT_WRITE
%35 = load i32, i32* @PROT_READ
%36 = or i32 %34, %35
store i32 %36, i32* %28
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 4
br i1 %38, label %39, label %45
39: ; preds = %2
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %43)
br label %191
45: ; preds = %2
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = load i32, i32* @O_RDWR
%50 = load i32, i32* @O_CREAT
%51 = or i32 %49, %50
%52 = call i32 (i8*, i32, ...) @open(i8* %48, i32 %51)
store i32 %52, i32* %13
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %45
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 @perror(i8* %57)
br label %191
59: ; preds = %45
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = load i32, i32* @O_RDWR
%64 = load i32, i32* @O_CREAT
%65 = or i32 %63, %64
%66 = call i32 (i8*, i32, ...) @open(i8* %62, i32 %65)
store i32 %66, i32* %14
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %59
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 2
%71 = load i8*, i8** %70
%72 = call i32 @perror(i8* %71)
br label %188
73: ; preds = %59
%74 = load i32, i32* %13
%75 = call i32 @fstat(i32 %74, %struct.stat* %32)
%76 = load i32, i32* %14
%77 = call i32 @fstat(i32 %76, %struct.stat* %33)
%78 = getelementptr inbounds %struct.stat, %struct.stat* %32, i32 0, i32 0
%79 = load i32, i32* %78
store i32 %79, i32* %30
%80 = getelementptr inbounds %struct.stat, %struct.stat* %33, i32 0, i32 0
%81 = load i32, i32* %80
store i32 %81, i32* %31
%82 = load i32, i32* %30
%83 = load i32, i32* %31
%84 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %82, i32 %83)
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 3
%87 = load i8*, i8** %86
%88 = load i32, i32* @O_RDWR
%89 = load i32, i32* @O_CREAT
%90 = or i32 %88, %89
%91 = call i32 (i8*, i32, ...) @open(i8* %87, i32 %90, i32 420)
store i32 %91, i32* %15
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %73
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 3
%96 = load i8*, i8** %95
%97 = call i32 @perror(i8* %96)
br label %185
98: ; preds = %73
%99 = load i32, i32* %15
%100 = call i32 @write(i32 %99, i32* null, i32 0)
%101 = load i32, i32* %15
%102 = load i32, i32* %30
%103 = load i32, i32* %31
%104 = add nsw i32 %102, %103
%105 = call i32 @ftruncate(i32 %101, i32 %104)
%106 = load i32, i32* %30
%107 = load i32, i32* %28
%108 = load i32, i32* @MAP_SHARED
%109 = load i32, i32* %13
%110 = call i8* @mmap(i32 0, i32 %106, i32 %107, i32 %108, i32 %109, i32 0)
store i8* %110, i8** %16
%111 = icmp eq i8* %110, null
br i1 %111, label %112, label %114
112: ; preds = %98
%113 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %182
114: ; preds = %98
%115 = load i32, i32* %31
%116 = load i32, i32* %28
%117 = load i32, i32* @MAP_SHARED
%118 = load i32, i32* %14
%119 = call i8* @mmap(i32 0, i32 %115, i32 %116, i32 %117, i32 %118, i32 0)
store i8* %119, i8** %17
%120 = icmp eq i8* %119, null
br i1 %120, label %121, label %123
121: ; preds = %114
%122 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %178
123: ; preds = %114
%124 = load i32, i32* %30
%125 = load i32, i32* %31
%126 = add nsw i32 %124, %125
%127 = load i32, i32* %28
%128 = load i32, i32* @MAP_SHARED
%129 = load i32, i32* %15
%130 = call i8* @mmap(i32 0, i32 %126, i32 %127, i32 %128, i32 %129, i32 0)
store i8* %130, i8** %18
%131 = icmp eq i8* %130, null
br i1 %131, label %132, label %134
132: ; preds = %123
%133 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %174
134: ; preds = %123
%135 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%136 = load i8*, i8** %16
store i8* %136, i8** %20
%137 = load i8*, i8** %17
store i8* %137, i8** %21
%138 = load i8*, i8** %18
store i8* %138, i8** %22
%139 = load i32, i32* %30
store i32 %139, i32* %24
%140 = load i32, i32* %31
store i32 %140, i32* %25
store i32 1, i32* %27
%141 = load i8*, i8** %20
store i8* %141, i8** %29
br label %142
142: ; preds = %165, %134
%143 = load i32, i32* %24
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %148
145: ; preds = %142
%146 = load i32, i32* %25
%147 = icmp ne i32 %146, 0
br label %148
148: ; preds = %145, %142
%149 = phi i1 [ false, %142 ], [ %147, %145 ]
br i1 %149, label %150, label %166
150: ; preds = %148
%151 = load i32, i32* %27
%152 = icmp eq i32 %151, 1
br i1 %152, label %153, label %157
153: ; preds = %150
%154 = load i8*, i8** %29
%155 = call i32 @reverse_and_write(i32* %24, i8** %20, i32* %7, i8* %154, i8** %22)
store i32 2, i32* %27
%156 = load i8*, i8** %21
store i8* %156, i8** %29
br label %165
157: ; preds = %150
%158 = load i32, i32* %27
%159 = icmp eq i32 %158, 2
br i1 %159, label %160, label %164
160: ; preds = %157
%161 = load i8*, i8** %29
%162 = call i32 @reverse_and_write(i32* %25, i8** %21, i32* %8, i8* %161, i8** %22)
store i32 1, i32* %27
%163 = load i8*, i8** %20
store i8* %163, i8** %29
br label %164
164: ; preds = %160, %157
br label %165
165: ; preds = %164, %153
br label %142
166: ; preds = %148
%167 = call i32 @exit(i32 0)
unreachable
168: ; No predecessors!
%169 = load i8*, i8** %18
%170 = load i32, i32* %30
%171 = load i32, i32* %31
%172 = add nsw i32 %170, %171
%173 = call i32 @munmap(i8* %169, i32 %172)
br label %174
174: ; preds = %168, %132
%175 = load i8*, i8** %17
%176 = load i32, i32* %31
%177 = call i32 @munmap(i8* %175, i32 %176)
br label %178
178: ; preds = %174, %121
%179 = load i8*, i8** %16
%180 = load i32, i32* %30
%181 = call i32 @munmap(i8* %179, i32 %180)
br label %182
182: ; preds = %178, %112
%183 = load i32, i32* %15
%184 = call i32 @close(i32 %183)
br label %185
185: ; preds = %182, %93
%186 = load i32, i32* %14
%187 = call i32 @close(i32 %186)
br label %188
188: ; preds = %185, %68
%189 = load i32, i32* %13
%190 = call i32 @close(i32 %189)
br label %191
191: ; preds = %188, %54, %39
%192 = load i32, i32* %6
ret i32 %192
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.stat = type { i32 }
@PROT_WRITE = global i32 0
@PROT_READ = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s file1 file2 fout\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"size1 : %d, size2 : %d\00"
@MAP_SHARED = global i32 0
@.str.2 = [11 x i8] c"mmap error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca %struct.stat
%13 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%14 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%15 = bitcast %struct.timeval* %5 to i8*
%16 = bitcast i8** %6 to i8*
%17 = bitcast i8** %7 to i8*
%18 = bitcast i8** %8 to i8*
%19 = bitcast i32* %9 to i8*
%20 = bitcast i32* %10 to i8*
%21 = load i32, i32* @PROT_WRITE
%22 = load i32, i32* @PROT_READ
%23 = or i32 %22, %21
%24 = bitcast %struct.stat* %11 to i8*
%25 = bitcast %struct.stat* %12 to i8*
%26 = icmp eq i32 %0, 4
br i1 %26, label %31, label %27
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %125
31: ; preds = %2
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_RDWR
%35 = load i32, i32* @O_CREAT
%36 = or i32 %35, %34
%37 = tail call i32 (i8*, i32, ...) @open(i8* %33, i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i8*, i8** %32
%41 = tail call i32 @perror(i8* %40)
br label %125
42: ; preds = %31
%43 = getelementptr inbounds i8*, i8** %1, i64 2
%44 = load i8*, i8** %43
%45 = load i32, i32* @O_RDWR
%46 = load i32, i32* @O_CREAT
%47 = or i32 %46, %45
%48 = tail call i32 (i8*, i32, ...) @open(i8* %44, i32 %47)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %42
%51 = load i8*, i8** %43
%52 = tail call i32 @perror(i8* %51)
br label %123
53: ; preds = %42
%54 = call i32 @fstat(i32 %37, %struct.stat* %11)
%55 = call i32 @fstat(i32 %48, %struct.stat* %12)
%56 = getelementptr inbounds %struct.stat, %struct.stat* %11, i64 0, i32 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.stat, %struct.stat* %12, i64 0, i32 0
%59 = load i32, i32* %58
%60 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %57, i32 %59)
%61 = getelementptr inbounds i8*, i8** %1, i64 3
%62 = load i8*, i8** %61
%63 = load i32, i32* @O_RDWR
%64 = load i32, i32* @O_CREAT
%65 = or i32 %64, %63
%66 = tail call i32 (i8*, i32, ...) @open(i8* %62, i32 %65, i32 420)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %53
%69 = load i8*, i8** %61
%70 = tail call i32 @perror(i8* %69)
br label %121
71: ; preds = %53
%72 = tail call i32 @write(i32 %66, i32* null, i32 0)
%73 = add nsw i32 %59, %57
%74 = tail call i32 @ftruncate(i32 %66, i32 %73)
%75 = load i32, i32* @MAP_SHARED
%76 = tail call i8* @mmap(i32 0, i32 %57, i32 %23, i32 %75, i32 %37, i32 0)
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %80
78: ; preds = %71
%79 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %119
80: ; preds = %71
%81 = load i32, i32* @MAP_SHARED
%82 = tail call i8* @mmap(i32 0, i32 %59, i32 %23, i32 %81, i32 %48, i32 0)
%83 = icmp eq i8* %82, null
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %117
86: ; preds = %80
%87 = load i32, i32* @MAP_SHARED
%88 = tail call i8* @mmap(i32 0, i32 %73, i32 %23, i32 %87, i32 %66, i32 0)
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %93
90: ; preds = %86
%91 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%92 = tail call i32 @munmap(i8* %82, i32 %59)
br label %117
93: ; preds = %86
%94 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i8* %76, i8** %6
store i8* %82, i8** %7
store i8* %88, i8** %8
store i32 %57, i32* %9
store i32 %59, i32* %10
%95 = icmp ne i32 %57, 0
%96 = icmp ne i32 %59, 0
%97 = and i1 %95, %96
br i1 %97, label %98, label %115
98: ; preds = %93, %106
%99 = phi i32 [ %108, %106 ], [ 1, %93 ]
%100 = phi i8* [ %109, %106 ], [ %76, %93 ]
%101 = icmp eq i32 %99, 1
br i1 %101, label %102, label %104
102: ; preds = %98
%103 = call i32 @reverse_and_write(i32* %9, i8** %6, i32* %3, i8* %100, i8** %8)
br label %106
104: ; preds = %98
%105 = call i32 @reverse_and_write(i32* %10, i8** %7, i32* %4, i8* %100, i8** %8)
br label %106
106: ; preds = %104, %102
%107 = phi i8** [ %7, %102 ], [ %6, %104 ]
%108 = phi i32 [ 2, %102 ], [ 1, %104 ]
%109 = load i8*, i8** %107
%110 = load i32, i32* %9
%111 = icmp ne i32 %110, 0
%112 = load i32, i32* %10
%113 = icmp ne i32 %112, 0
%114 = select i1 %111, i1 %113, i1 false
br i1 %114, label %98, label %115
115: ; preds = %106, %93
%116 = call i32 @exit(i32 0)
unreachable
117: ; preds = %90, %84
%118 = tail call i32 @munmap(i8* %76, i32 %57)
br label %119
119: ; preds = %117, %78
%120 = tail call i32 @close(i32 %66)
br label %121
121: ; preds = %119, %68
%122 = tail call i32 @close(i32 %48)
br label %123
123: ; preds = %121, %50
%124 = tail call i32 @close(i32 %37)
br label %125
125: ; preds = %123, %39, %27
ret i32 1
}