#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 */
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, ...);
scalar_t__ read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, unsigned char *, scalar_t__);
int main(int argc, char *argv[]) {
  int iif, oif;
  ssize_t len;
  unsigned char buf[1500];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s source_file destination_file\n", argv[0]);
    exit(1);
  }
  iif = open(argv[1], O_RDONLY);
  if (iif == -1) {
    fprintf(stderr, "Error opening source %s: %m\n", argv[1]);
    exit(1);
  }
  oif = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
  if (oif == -1) {
    fprintf(stderr, "Error opening destination file %s: %m\n", argv[2]);
    exit(1);
  }
  while ((len = read(iif, buf, sizeof(buf))) > 0) {
    write(oif, buf, len);
  }
  if (len < 0) {
    fprintf(stderr, "Error reading file %s: %m\n", argv[1]);
    exit(1);
  }
  close(iif);
  close(oif);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x600,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a9 <main+0x49>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f5 <main+0x95>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe42(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
mov    0x2db9(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    125c <main+0xfc>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1261 <main+0x101>
mov    -0x14(%rbp),%edi
lea    -0x600(%rbp),%rsi
mov    $0x5dc,%edx
call   1050 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jle    129b <main+0x13b>
mov    -0x18(%rbp),%edi
lea    -0x600(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
jmp    1261 <main+0x101>
cmpq   $0x0,-0x20(%rbp)
jge    12cd <main+0x16d>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdae(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x600,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x5e8,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1236 <main+0xd6>
mov    0x8(%r14),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     124b <main+0xeb>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2e0c(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0a(%rip),%rax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0x101>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x5dc,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    1212 <main+0xb2>
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x5dc,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     11f0 <main+0x90>
test   %rax,%rax
js     1277 <main+0x117>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x5e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdb7(%rip),%rsi
jmp    128b <main+0x12b>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdc9(%rip),%rsi
jmp    128b <main+0x12b>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xdd0(%rip),%rsi
jmp    128b <main+0x12b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xde1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s source_file destination_file\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"Error opening source %s: %m\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [39 x i8] c"Error opening destination file %s: %m\0A\00"
@.str.3 = [27 x i8] c"Error reading file %s: %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca [1500 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 %19
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 ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %19
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_WRONLY
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IRUSR
%42 = load i32, i32* @S_IWUSR
%43 = or i32 %41, %42
%44 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %40, i32 %43)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %34
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %34
br label %55
55: ; preds = %60, %54
%56 = load i32, i32* %6
%57 = getelementptr inbounds [1500 x i8], [1500 x i8]* %9, i64 0, i64 0
%58 = call i64 @read(i32 %56, i8* %57, i32 1500)
store i64 %58, i64* %8
%59 = icmp sgt i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = load i32, i32* %7
%62 = getelementptr inbounds [1500 x i8], [1500 x i8]* %9, i64 0, i64 0
%63 = load i64, i64* %8
%64 = call i32 @write(i32 %61, i8* %62, i64 %63)
br label %55
65: ; preds = %55
%66 = load i64, i64* %8
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %65
%76 = load i32, i32* %6
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %7
%79 = call i32 @close(i32 %78)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s source_file destination_file\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [29 x i8] c"Error opening source %s: %m\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [39 x i8] c"Error opening destination file %s: %m\0A\00"
@.str.3 = [27 x i8] c"Error reading file %s: %m\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1500 x i8]
%4 = getelementptr inbounds [1500 x i8], [1500 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 ([40 x i8], [40 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 (i8*, i32, ...) @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %12
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %11
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_WRONLY
%26 = load i32, i32* @O_CREAT
%27 = or i32 %26, %25
%28 = load i32, i32* @S_IRUSR
%29 = load i32, i32* @S_IWUSR
%30 = or i32 %29, %28
%31 = tail call i32 (i8*, i32, ...) @open(i8* %24, i32 %27, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %36, label %33
33: ; preds = %22
%34 = call i64 @read(i32 %15, i8* %4, i32 1500)
%35 = icmp sgt i64 %34, 0
br i1 %35, label %41, label %46
36: ; preds = %22
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %23
%39 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %33, %41
%42 = phi i64 [ %44, %41 ], [ %34, %33 ]
%43 = call i32 @write(i32 %31, i8* %4, i64 %42)
%44 = call i64 @read(i32 %15, i8* %4, i32 1500)
%45 = icmp sgt i64 %44, 0
br i1 %45, label %41, label %46
46: ; preds = %41, %33
%47 = phi i64 [ %34, %33 ], [ %44, %41 ]
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %12
%52 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = tail call i32 @close(i32 %15)
%56 = tail call i32 @close(i32 %31)
ret i32 0
}