#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);
void main(int argc, char *argv[]) {
  int in_fd, out_fd, n_chars;
  char buf[4096];
  if (argc != 3) {
    fprintf(stderr, "usage: %s source-file destination\n", *argv);
    exit(1);
  }
  if ((in_fd = open(argv[1], O_RDONLY)) == -1)
    oops("Cannot open", argv[1]);
  if ((out_fd = creat(argv[2], 0644)) == -1)
    oops("Cannot create", 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("Error closing files", "");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     11c2 <main+0x42>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe30(%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    122a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe0a(%rip),%rdi
call   1040 <oops@plt>
jmp    122f <main+0xaf>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1283 <main+0x103>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     127e <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdc4(%rip),%rdi
call   1040 <oops@plt>
jmp    122f <main+0xaf>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12a1 <main+0x121>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb0(%rip),%rdi
call   1040 <oops@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12c3 <main+0x143>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    12d6 <main+0x156>
lea    0xd92(%rip),%rdi
lea    0xd51(%rip),%rsi
call   1040 <oops@plt>
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    12aa <main+0x12a>
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    0xe61(%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    0xe47(%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    0xe30(%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    0xdf7(%rip),%rdi
call   1040 <oops@plt>
mov    %r15d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1286 <main+0x106>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1286 <main+0x106>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcf(%rip),%rdi
lea    0xd8e(%rip),%rsi
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <oops@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd43(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"usage: %s source-file destination\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"Cannot open\00"
@.str.2 = [14 x i8] c"Cannot create\00"
@.str.3 = [15 x i8] c"Write error to\00"
@.str.4 = [16 x i8] c"READ error from\00"
@.str.5 = [20 x i8] c"Error closing files\00"
@.str.6 = [1 x i8] zeroinitializer
define void @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 ([35 x i8], [35 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 ([14 x i8], [14 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 ([20 x i8], [20 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 void
}