#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*/ O_RDONLY;
int close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
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) {
  int in_fd, out_fd, n_chars;
  char buf[4096];
  if (argc != 3) {
    fprintf(stderr, "usage:%s source destination\n", *argv);
    exit(1);
  }
  if ((in_fd = open(argv[1], O_RDONLY)) == -1)
    oops("Cann't open", argv[1]);
  if ((out_fd = creat(argv[2], 0644)) == -1)
    oops("Cann't creat", argv[2]);
  while ((n_chars = read(in_fd, buf, 4096)) > 0)
    if (write(out_fd, buf, n_chars) != n_chars)
      oops("Write error to", argv[2]);
  if (n_chars == -1)
    oops("Read error from", argv[1]);
  if (close(in_fd) == -1 || close(out_fd) == -1)
    oops("Close file error", "");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c9 <main+0x49>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ff <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe23(%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)
cmp    $0xffffffff,%eax
jne    1231 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdfd(%rip),%rdi
call   1040 <oops@plt>
jmp    1236 <main+0xb6>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    128a <main+0x10a>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     1285 <main+0x105>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdb6(%rip),%rdi
call   1040 <oops@plt>
jmp    1236 <main+0xb6>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12a8 <main+0x128>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda2(%rip),%rdi
call   1040 <oops@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12ca <main+0x14a>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    12dd <main+0x15d>
lea    0xd84(%rip),%rdi
lea    0xd44(%rip),%rsi
call   1040 <oops@plt>
xor    %eax,%eax
add    $0x1020,%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    129b <main+0x11b>
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    0xe5b(%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    0xe41(%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    0xe29(%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    0xdf0(%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    0xdda(%rip),%rdi
lea    0xd9a(%rip),%rsi
call   1040 <oops@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd52(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"usage:%s source destination\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"Cann't open\00"
@.str.2 = [13 x i8] c"Cann't creat\00"
@.str.3 = [15 x i8] c"Write error to\00"
@.str.4 = [16 x i8] c"Read error from\00"
@.str.5 = [17 x i8] c"Close file error\00"
@.str.6 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
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 ([12 x i8], [12 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 ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %20
%29 = call i32 @read(i32 %15, i8* %4, i32 4096)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %28, %38
%32 = phi i32 [ %39, %38 ], [ %29, %28 ]
%33 = call i32 @write(i32 %23, i8* %4, i32 %32)
%34 = icmp eq i32 %33, %32
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i8*, i8** %21
%37 = tail call i32 @oops(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %31
%39 = call i32 @read(i32 %15, i8* %4, i32 4096)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %31, label %41
41: ; preds = %38, %28
%42 = phi i32 [ %29, %28 ], [ %39, %38 ]
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8*, i8** %12
%46 = tail call i32 @oops(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %41
%48 = tail call i32 @close(i32 %15)
%49 = icmp eq i32 %48, -1
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = tail call i32 @close(i32 %23)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %50, %47
%54 = tail call i32 @oops(i8* getelementptr inbounds ([17 x i8], [17 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 %55
55: ; preds = %53, %50
ret i32 0
}