#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ oops(char *, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s source destination\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  int src_fd = open(argv[1], O_RDONLY);
  if (src_fd == -1) {
    oops("Can not open", argv[1]);
  }
  int dst_fd = creat(argv[2], 0644);
  if (dst_fd == -1) {
    oops("Can not create", argv[2]);
  }
  char buf[4096];
  int buf_size;
  while ((buf_size = read(src_fd, buf, 4096)) > 0)
    if (write(dst_fd, buf, buf_size) != buf_size)
      oops("Failed to create", argv[2]);
  if (buf_size == -1)
    oops("Failed to read", argv[1]);
  if (close(src_fd) == -1 || close(dst_fd) == -1)
    oops("Faile to close files.", "");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cd <main+0x4d>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1204 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1f(%rip),%rdi
call   1040 <oops@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1a4,%esi
call   1090 <creat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1237 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdf9(%rip),%rdi
call   1040 <oops@plt>
jmp    123c <main+0xbc>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x1024(%rbp)
cmp    $0x0,%eax
jle    1299 <main+0x119>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1024(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1024(%rbp),%eax
je     1294 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdab(%rip),%rdi
call   1040 <oops@plt>
jmp    123c <main+0xbc>
cmpl   $0xffffffff,-0x1024(%rbp)
jne    12ba <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd96(%rip),%rdi
call   1040 <oops@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12dc <main+0x15c>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    12ef <main+0x16f>
lea    0xd77(%rip),%rdi
lea    0xd33(%rip),%rsi
call   1040 <oops@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    12a2 <main+0x122>
mov    0x8(%r14),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11c7 <main+0x47>
mov    0x8(%r14),%rsi
lea    0xe5c(%rip),%rdi
call   1040 <oops@plt>
mov    0x10(%r14),%rdi
mov    $0x1a4,%esi
call   1090 <creat@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    11ed <main+0x6d>
mov    0x10(%r14),%rsi
lea    0xe43(%rip),%rdi
call   1040 <oops@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1245 <main+0xc5>
mov    %rsp,%rbp
lea    0xe2d(%rip),%r12
jmp    1226 <main+0xa6>
nop
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1245 <main+0xc5>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     1210 <main+0x90>
mov    0x10(%r14),%rsi
mov    %r12,%rdi
call   1040 <oops@plt>
jmp    1210 <main+0x90>
cmp    $0xffffffff,%ebx
jne    125a <main+0xda>
mov    0x8(%r14),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <oops@plt>
mov    %r15d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1274 <main+0xf4>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1287 <main+0x107>
lea    0xddf(%rip),%rdi
lea    0xd9b(%rip),%rsi
call   1040 <oops@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd4b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s source destination\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"Can not open\00"
@.str.2 = [15 x i8] c"Can not create\00"
@.str.3 = [17 x i8] c"Failed to create\00"
@.str.4 = [15 x i8] c"Failed to read\00"
@.str.5 = [22 x i8] c"Faile to close files.\00"
@.str.6 = [1 x i8] zeroinitializer
@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 [4096 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
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 @open(i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @oops(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %20
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @creat(i8* %36, i32 420)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %45
40: ; preds = %33
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @oops(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %40, %33
br label %46
46: ; preds = %63, %45
%47 = load i32, i32* %6
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 4096)
store i32 %49, i32* %9
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %46
%52 = load i32, i32* %7
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%54 = load i32, i32* %9
%55 = call i32 @write(i32 %52, i8* %53, i32 %54)
%56 = load i32, i32* %9
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %63
58: ; preds = %51
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = call i32 @oops(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %58, %51
br label %46
64: ; preds = %46
%65 = load i32, i32* %9
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 @oops(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %67, %64
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %80, label %76
76: ; preds = %72
%77 = load i32, i32* %7
%78 = call i32 @close(i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %76, %72
%81 = call i32 @oops(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
br label %82
82: ; preds = %80, %76
%83 = load i32, i32* @EXIT_SUCCESS
ret i32 %83
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s source destination\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"Can not open\00"
@.str.2 = [15 x i8] c"Can not create\00"
@.str.3 = [17 x i8] c"Failed to create\00"
@.str.4 = [15 x i8] c"Failed to read\00"
@.str.5 = [22 x i8] c"Faile to close files.\00"
@.str.6 = [1 x i8] zeroinitializer
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %11, 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 ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %12
%19 = tail call i32 @oops(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %11
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @creat(i8* %22, i32 420)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %21
%27 = tail call i32 @oops(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %20
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%30 = call i32 @read(i32 %15, i8* %29, i32 4096)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %28, %39
%33 = phi i32 [ %40, %39 ], [ %30, %28 ]
%34 = call i32 @write(i32 %23, i8* %29, i32 %33)
%35 = icmp eq i32 %34, %33
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i8*, i8** %21
%38 = tail call i32 @oops(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %32
%40 = call i32 @read(i32 %15, i8* %29, i32 4096)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %32, label %42
42: ; preds = %39, %28
%43 = phi i32 [ %30, %28 ], [ %40, %39 ]
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %12
%47 = tail call i32 @oops(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %42
%49 = tail call i32 @close(i32 %15)
%50 = icmp eq i32 %49, -1
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = tail call i32 @close(i32 %23)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %51, %48
%55 = tail call i32 @oops(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
%57 = load i32, i32* @EXIT_SUCCESS
ret i32 %57
}