#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fstat(int, struct stat *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int write(int, void *, int);
int main(int argc, char *argv[]) {
  int fd_in, fd_out;
  if (argc != 3) {
    fprintf(stderr, "usage: %s IN_FILE OUT_FILE\n", argv[0]);
    return EXIT_FAILURE;
  }
  if ((fd_in = open(argv[1], O_RDONLY)) == -1) {
    perror("unable to open input file for reading");
    return EXIT_FAILURE;
  }
  struct stat st;
  if (fstat(fd_in, &st) == -1) {
    perror("unable to retrieve information");
    return EXIT_FAILURE;
  }
  if (!S_ISREG(st.st_mode)) {
    fprintf(stderr, "not a regular file: %s\n", argv[1]);
    return EXIT_FAILURE;
  }
  int seek = lseek(fd_in, 0, SEEK_END);
  lseek(fd_in, 0, SEEK_SET);
  void *map;
  if ((map = mmap(NULL, seek, PROT_READ, MAP_PRIVATE, fd_in, 0)) ==
      MAP_FAILED) {
    perror("unable to mmap");
    return EXIT_FAILURE;
  }
  if ((fd_out = open(argv[2], O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) {
    perror("unable to open output file for writing");
    return EXIT_FAILURE;
  }
  if (write(fd_out, map, seek) == -1) {
    perror("error while writing");
    return EXIT_FAILURE;
  }
  munmap(map, seek);
  close(fd_in);
  close(fd_out);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ed <main+0x4d>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    122e <main+0x8e>
lea    0xe04(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1260 <main+0xc0>
lea    0xdf8(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x20(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%eax
jne    129f <main+0xff>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x14(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x24(%rbp),%esi
mov    0x2d1e(%rip),%rax
mov    (%rax),%edx
mov    0x2cbd(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    0x2c98(%rip),%rcx
cmp    (%rcx),%rax
jne    131e <main+0x17e>
lea    0xd71(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2c53(%rip),%rax
mov    (%rax),%esi
mov    0x2cc2(%rip),%rax
or     (%rax),%esi
mov    0x2c79(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1376 <main+0x1d6>
lea    0xd28(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    13ab <main+0x20b>
lea    0xd1a(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13d3 <main+0x233>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2bd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    12bf <main+0x11f>
mov    0x8(%rbx),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1301 <main+0x161>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   10c0 <fstat@plt>
cmp    $0xffffffff,%eax
je     130a <main+0x16a>
mov    (%rsp),%edi
call   1080 <S_ISREG@plt>
test   %eax,%eax
je     12d4 <main+0x134>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%r14d
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    0x2d6c(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r15
mov    0x2d48(%rip),%rax
cmp    (%rax),%r15
je     1313 <main+0x173>
mov    0x2d28(%rip),%rax
mov    0x2d99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2d4a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     131c <main+0x17c>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1325 <main+0x185>
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <munmap@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2ce3(%rip),%rax
jmp    12f4 <main+0x154>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd2e(%rip),%rsi
jmp    12e8 <main+0x148>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd79(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd14(%rip),%rdi
jmp    132c <main+0x18c>
lea    0xd31(%rip),%rdi
jmp    132c <main+0x18c>
lea    0xd5f(%rip),%rdi
jmp    132c <main+0x18c>
lea    0xd65(%rip),%rdi
jmp    132c <main+0x18c>
lea    0xd83(%rip),%rdi
call   10b0 <perror@plt>
jmp    12ed <main+0x14d>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s IN_FILE OUT_FILE\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"unable to open input file for reading\00"
@.str.2 = [31 x i8] c"unable to retrieve information\00"
@.str.3 = [24 x i8] c"not a regular file: %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [15 x i8] c"unable to mmap\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.5 = [39 x i8] c"unable to open output file for writing\00"
@.str.6 = [20 x i8] c"error while writing\00"
@EXIT_SUCCESS = 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 %struct.stat
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %98
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 (i8*, i32, ...) @open(i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %98
30: ; preds = %20
%31 = load i32, i32* %6
%32 = call i32 @fstat(i32 %31, %struct.stat* %8)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %3
br label %98
37: ; preds = %30
%38 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @S_ISREG(i32 %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %98
49: ; preds = %37
%50 = load i32, i32* %6
%51 = load i32, i32* @SEEK_END
%52 = call i32 @lseek(i32 %50, i32 0, i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %6
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %53, i32 0, i32 %54)
%56 = load i32, i32* %9
%57 = load i32, i32* @PROT_READ
%58 = load i32, i32* @MAP_PRIVATE
%59 = load i32, i32* %6
%60 = call i8* @mmap(i32* null, i32 %56, i32 %57, i32 %58, i32 %59, i32 0)
store i8* %60, i8** %10
%61 = load i8*, i8** @MAP_FAILED
%62 = icmp eq i8* %60, %61
br i1 %62, label %63, label %66
63: ; preds = %49
%64 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %3
br label %98
66: ; preds = %49
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = load i32, i32* @O_WRONLY
%71 = load i32, i32* @O_CREAT
%72 = or i32 %70, %71
%73 = load i32, i32* @O_EXCL
%74 = or i32 %72, %73
%75 = call i32 (i8*, i32, ...) @open(i8* %69, i32 %74, i32 420)
store i32 %75, i32* %7
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %66
%78 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%79 = load i32, i32* @EXIT_FAILURE
store i32 %79, i32* %3
br label %98
80: ; preds = %66
%81 = load i32, i32* %7
%82 = load i8*, i8** %10
%83 = load i32, i32* %9
%84 = call i32 @write(i32 %81, i8* %82, i32 %83)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %89
86: ; preds = %80
%87 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%88 = load i32, i32* @EXIT_FAILURE
store i32 %88, i32* %3
br label %98
89: ; preds = %80
%90 = load i8*, i8** %10
%91 = load i32, i32* %9
%92 = call i32 @munmap(i8* %90, i32 %91)
%93 = load i32, i32* %6
%94 = call i32 @close(i32 %93)
%95 = load i32, i32* %7
%96 = call i32 @close(i32 %95)
%97 = load i32, i32* @EXIT_SUCCESS
store i32 %97, i32* %3
br label %98
98: ; preds = %89, %86, %77, %63, %42, %34, %27, %13
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s IN_FILE OUT_FILE\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"unable to open input file for reading\00"
@.str.2 = [31 x i8] c"unable to retrieve information\00"
@.str.3 = [24 x i8] c"not a regular file: %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.4 = [15 x i8] c"unable to mmap\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.5 = [39 x i8] c"unable to open output file for writing\00"
@.str.6 = [20 x i8] c"error while writing\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 3
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
br label %70
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
br label %70
19: ; preds = %10
%20 = bitcast %struct.stat* %3 to i8*
%21 = call i32 @fstat(i32 %14, %struct.stat* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %67
25: ; preds = %19
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%27 = load i32, i32* %26
%28 = tail call i32 @S_ISREG(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %11
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %32)
br label %67
34: ; preds = %25
%35 = load i32, i32* @SEEK_END
%36 = tail call i32 @lseek(i32 %14, i32 0, i32 %35)
%37 = load i32, i32* @SEEK_SET
%38 = tail call i32 @lseek(i32 %14, i32 0, i32 %37)
%39 = load i32, i32* @PROT_READ
%40 = load i32, i32* @MAP_PRIVATE
%41 = tail call i8* @mmap(i32* null, i32 %36, i32 %39, i32 %40, i32 %14, i32 0)
%42 = load i8*, i8** @MAP_FAILED
%43 = icmp eq i8* %41, %42
br i1 %43, label %44, label %46
44: ; preds = %34
%45 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %67
46: ; preds = %34
%47 = getelementptr inbounds i8*, i8** %1, i64 2
%48 = load i8*, i8** %47
%49 = load i32, i32* @O_WRONLY
%50 = load i32, i32* @O_CREAT
%51 = or i32 %50, %49
%52 = load i32, i32* @O_EXCL
%53 = or i32 %51, %52
%54 = tail call i32 (i8*, i32, ...) @open(i8* %48, i32 %53, i32 420)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %46
%57 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
br label %67
58: ; preds = %46
%59 = tail call i32 @write(i32 %54, i8* %41, i32 %36)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %67
63: ; preds = %58
%64 = tail call i32 @munmap(i8* %41, i32 %36)
%65 = tail call i32 @close(i32 %14)
%66 = tail call i32 @close(i32 %54)
br label %67
67: ; preds = %44, %56, %61, %63, %30, %23
%68 = phi i32* [ @EXIT_FAILURE, %23 ], [ @EXIT_FAILURE, %30 ], [ @EXIT_FAILURE, %44 ], [ @EXIT_FAILURE, %56 ], [ @EXIT_FAILURE, %61 ], [ @EXIT_SUCCESS, %63 ]
%69 = load i32, i32* %68
br label %70
70: ; preds = %67, %16, %5
%71 = phi i32 [ %9, %5 ], [ %18, %16 ], [ %69, %67 ]
ret i32 %71
}