#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 /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ checkArgc(int);
int createFile(char *, char *);
int getSize(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
char *nameFilter(char *);
int openFile(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setprogname(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd_src, fd_trgt, file_size;
  char *file_name;
  char *addr_src;
  char *addr_trgt;
  setprogname(argv[0]);
  checkArgc(argc);
  int length;
  length = strlen(argv[1]);
  char changeable_name[length];
  strcpy(changeable_name, argv[1]);
  file_name = changeable_name;
  file_name = nameFilter(file_name);
  fd_trgt = createFile(file_name, argv[2]);
  fd_src = openFile(argv[1]);
  file_size = getSize(fd_src);
  char buf[file_size];
  if (write(fd_trgt, buf, file_size) != file_size) {
    perror("Error writing hole-target_file");
    return 1;
  }
  addr_src = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd_src, 0);
  addr_trgt =
      mmap(NULL, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_trgt, 0);
  memcpy(addr_trgt, addr_src, file_size + 1);
  munmap(addr_src, file_size);
  munmap(addr_trgt, file_size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10e0 <setprogname@plt>
mov    -0x8(%rbp),%edi
call   1030 <checkArgc@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <nameFilter@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <createFile@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <openFile@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10f0 <getSize@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1050 <write@plt>
cmp    -0x1c(%rbp),%eax
je     12cf <main+0xff>
lea    0xd49(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1363 <main+0x193>
mov    -0x1c(%rbp),%esi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    0x2ce6(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
mov    0x2cc5(%rip),%rax
or     (%rax),%edx
mov    0x2cd4(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   10b0 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <munmap@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10c0 <munmap@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    (%rsi),%rdi
call   10e0 <setprogname@plt>
mov    %r14d,%edi
call   1030 <checkArgc@plt>
mov    0x8(%r15),%rdi
call   1070 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%r15),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   10a0 <nameFilter@plt>
mov    0x10(%r15),%rsi
mov    %rax,%rdi
call   1090 <createFile@plt>
mov    %eax,%r14d
mov    0x8(%r15),%rdi
call   1060 <openFile@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   10f0 <getSize@plt>
mov    %eax,%ebx
mov    %eax,%eax
mov    %rsp,%rsi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
mov    %r14d,%edi
mov    %ebx,%edx
call   1050 <write@plt>
cmp    %ebx,%eax
jne    12f4 <main+0x124>
mov    0x2d84(%rip),%r13
mov    0x0(%r13),%edx
mov    0x2d49(%rip),%rax
mov    (%rax),%ecx
xor    %r15d,%r15d
xor    %edi,%edi
mov    %ebx,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,%r12
mov    0x2d33(%rip),%rax
mov    (%rax),%edx
or     0x0(%r13),%edx
mov    0x2d3e(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,%r14
mov    %ebx,%edx
add    $0x1,%edx
mov    %rax,%rdi
mov    %r12,%rsi
call   10b0 <memcpy@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   10c0 <munmap@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10c0 <munmap@plt>
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd05(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%r15d
jmp    12e2 <main+0x112>

LLVM IR (-O0):
@.str = [31 x i8] c"Error writing hole-target_file\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
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 i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @setprogname(i8* %19)
%21 = load i32, i32* %4
%22 = call i32 @checkArgc(i32 %21)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %13
%30 = alloca i8, i64 %28
store i64 %28, i64* %14
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %30, i8* %33)
store i8* %30, i8** %9
%35 = load i8*, i8** %9
%36 = call i8* @nameFilter(i8* %35)
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @createFile(i8* %37, i8* %40)
store i32 %41, i32* %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @openFile(i8* %44)
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = call i32 @getSize(i32 %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = zext i32 %48 to i64
%50 = alloca i8, i64 %49
store i64 %49, i64* %15
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = call i32 @write(i32 %51, i8* %50, i32 %52)
%54 = load i32, i32* %8
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %58
56: ; preds = %2
%57 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %16
br label %82
58: ; preds = %2
%59 = load i32, i32* %8
%60 = load i32, i32* @PROT_READ
%61 = load i32, i32* @MAP_PRIVATE
%62 = load i32, i32* %6
%63 = call i8* @mmap(i32* null, i32 %59, i32 %60, i32 %61, i32 %62, i32 0)
store i8* %63, i8** %10
%64 = load i32, i32* %8
%65 = load i32, i32* @PROT_READ
%66 = load i32, i32* @PROT_WRITE
%67 = or i32 %65, %66
%68 = load i32, i32* @MAP_SHARED
%69 = load i32, i32* %7
%70 = call i8* @mmap(i32* null, i32 %64, i32 %67, i32 %68, i32 %69, i32 0)
store i8* %70, i8** %11
%71 = load i8*, i8** %11
%72 = load i8*, i8** %10
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
%75 = call i32 @memcpy(i8* %71, i8* %72, i32 %74)
%76 = load i8*, i8** %10
%77 = load i32, i32* %8
%78 = call i32 @munmap(i8* %76, i32 %77)
%79 = load i8*, i8** %11
%80 = load i32, i32* %8
%81 = call i32 @munmap(i8* %79, i32 %80)
store i32 0, i32* %3
store i32 1, i32* %16
br label %82
82: ; preds = %58, %56
%83 = load i8*, i8** %13
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [31 x i8] c"Error writing hole-target_file\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @setprogname(i8* %3)
%5 = tail call i32 @checkArgc(i32 %0)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @strlen(i8* %7)
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = load i8*, i8** %6
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = call i8* @nameFilter(i8* %10)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @createFile(i8* %13, i8* %15)
%17 = load i8*, i8** %6
%18 = call i32 @openFile(i8* %17)
%19 = call i32 @getSize(i32 %18)
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
%22 = call i32 @write(i32 %16, i8* %21, i32 %19)
%23 = icmp eq i32 %22, %19
br i1 %23, label %26, label %24
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %39
26: ; preds = %2
%27 = load i32, i32* @PROT_READ
%28 = load i32, i32* @MAP_PRIVATE
%29 = call i8* @mmap(i32* null, i32 %19, i32 %27, i32 %28, i32 %18, i32 0)
%30 = load i32, i32* @PROT_READ
%31 = load i32, i32* @PROT_WRITE
%32 = or i32 %31, %30
%33 = load i32, i32* @MAP_SHARED
%34 = call i8* @mmap(i32* null, i32 %19, i32 %32, i32 %33, i32 %16, i32 0)
%35 = add nsw i32 %19, 1
%36 = call i32 @memcpy(i8* %34, i8* %29, i32 %35)
%37 = call i32 @munmap(i8* %29, i32 %19)
%38 = call i32 @munmap(i8* %34, i32 %19)
br label %39
39: ; preds = %26, %24
%40 = phi i32 [ 1, %24 ], [ 0, %26 ]
ret i32 %40
}