#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 BUFSIZ;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int source_file_descriptor, target_file_descriptor;
  int n;
  char buf[BUFSIZ];
  if (argc != 3) {
    perror("Wrong number of arguments");
    return -1;
  }
  if ((source_file_descriptor = open(argv[1], O_RDONLY)) == -1) {
    perror(argv[1]);
    return -1;
  }
  if ((target_file_descriptor = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC,
                                     S_IWUSR | S_IRUSR)) == -1) {
    perror(argv[2]);
    return -1;
  }
  while ((n = read(source_file_descriptor, buf, BUFSIZ)) > 0)
    write(target_file_descriptor, buf, n);
  close(source_file_descriptor);
  close(target_file_descriptor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bb <main+0x6b>
lea    0xe5d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12bf <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ff <main+0xaf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12bf <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    0x2de1(%rip),%rax
or     (%rax),%esi
mov    0x2dd0(%rip),%rax
or     (%rax),%esi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
mov    0x2d86(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1267 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12bf <main+0x16f>
jmp    126c <main+0x11c>
mov    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12a1 <main+0x151>
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
jmp    126c <main+0x11c>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%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    0x2e5b(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x3,%edi
jne    1233 <main+0xe3>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     123c <main+0xec>
mov    %eax,%r14d
mov    0x10(%r15),%rdi
mov    0x2df7(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e2d(%rip),%rax
or     (%rax),%esi
mov    0x2e04(%rip),%rax
mov    0x2de5(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1242 <main+0xf2>
mov    %eax,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <read@plt>
test   %eax,%eax
jle    1212 <main+0xc2>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    11f0 <main+0xa0>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r12d,%edi
call   1040 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc6(%rip),%rdi
jmp    1246 <main+0xf6>
mov    0x8(%r15),%rdi
jmp    1246 <main+0xf6>
mov    0x10(%r15),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    1224 <main+0xd4>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [26 x i8] c"Wrong number of arguments\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = 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 i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %11
br label %66
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 %32
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @perror(i8* %30)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %66
32: ; preds = %20
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_WRONLY
%37 = load i32, i32* @O_CREAT
%38 = or i32 %36, %37
%39 = load i32, i32* @O_TRUNC
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IWUSR
%42 = load i32, i32* @S_IRUSR
%43 = or i32 %41, %42
%44 = call i32 (i8*, i32, ...) @open(i8* %35, i32 %40, i32 %43)
store i32 %44, i32* %7
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %51
46: ; preds = %32
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @perror(i8* %49)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %66
51: ; preds = %32
br label %52
52: ; preds = %57, %51
%53 = load i32, i32* %6
%54 = load i32, i32* @BUFSIZ
%55 = call i32 @read(i32 %53, i8* %15, i32 %54)
store i32 %55, i32* %8
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = load i32, i32* %7
%59 = load i32, i32* %8
%60 = call i32 @write(i32 %58, i8* %15, i32 %59)
br label %52
61: ; preds = %52
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* %7
%65 = call i32 @close(i32 %64)
store i32 0, i32* %3
store i32 1, i32* %11
br label %66
66: ; preds = %61, %46, %27, %18
%67 = load i8*, i8** %9
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [26 x i8] c"Wrong number of arguments\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 3
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %47
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %10
%17 = tail call i32 @perror(i8* %16)
br label %47
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IWUSR
%27 = load i32, i32* @S_IRUSR
%28 = or i32 %27, %26
%29 = tail call i32 (i8*, i32, ...) @open(i8* %20, i32 %25, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %35, label %31
31: ; preds = %18
%32 = load i32, i32* @BUFSIZ
%33 = call i32 @read(i32 %13, i8* %5, i32 %32)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %38, label %44
35: ; preds = %18
%36 = load i8*, i8** %19
%37 = tail call i32 @perror(i8* %36)
br label %47
38: ; preds = %31, %38
%39 = phi i32 [ %42, %38 ], [ %33, %31 ]
%40 = call i32 @write(i32 %29, i8* %5, i32 %39)
%41 = load i32, i32* @BUFSIZ
%42 = call i32 @read(i32 %13, i8* %5, i32 %41)
%43 = icmp sgt i32 %42, 0
br i1 %43, label %38, label %44
44: ; preds = %38, %31
%45 = tail call i32 @close(i32 %13)
%46 = tail call i32 @close(i32 %29)
br label %47
47: ; preds = %44, %35, %15, %7
%48 = phi i32 [ -1, %7 ], [ -1, %15 ], [ -1, %35 ], [ 0, %44 ]
ret i32 %48
}