#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 int /*<<< orphan*/ file_chars;
typedef int /*<<< orphan*/ burst_read;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int, ...);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char const *argv[]) {
  int success_open = open(argv[1], O_RDONLY);
  int buffer = 4000;
  char file_chars[4000];
  char burst_read[5];
  int read_return = 0;
  int write_return = 0;
  int array_index = 0;
  int bytesRead = 0;
  int i = 0;
  for (i = 0; i < sizeof(file_chars); i++) {
    file_chars[i] = 0;
  }
  for (i = 0; i < sizeof(burst_read); i++) {
    burst_read[i] = 0;
  }
  if (success_open == -1) {
    printf("This is awkward, could not open file (it exists?)\n");
    return -1;
  } else {
    do {
      read_return = read(success_open, burst_read, buffer);
      if (read_return != 0) {
        for (i = 0; i < buffer; i++) {
          file_chars[array_index] = burst_read[i];
          array_index = ++array_index;
        };
      }
      bytesRead = bytesRead + read_return;
    } while (read_return != 0);
    close(success_open);
    success_open = open(argv[2], O_CREAT | O_WRONLY, 0777);
    write_return = write(success_open, file_chars, bytesRead);
    close(success_open);
    printf("DONE\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0xfa0,-0x18(%rbp)
movl   $0x0,-0xfcc(%rbp)
movl   $0x0,-0xfd0(%rbp)
movl   $0x0,-0xfd4(%rbp)
movl   $0x0,-0xfd8(%rbp)
movl   $0x0,-0xfdc(%rbp)
movl   $0x0,-0xfdc(%rbp)
movslq -0xfdc(%rbp),%rax
cmp    $0xfa0,%rax
jae    11fd <main+0xad>
movslq -0xfdc(%rbp),%rax
movb   $0x0,-0xfc0(%rbp,%rax,1)
mov    -0xfdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfdc(%rbp)
jmp    11c7 <main+0x77>
movl   $0x0,-0xfdc(%rbp)
movslq -0xfdc(%rbp),%rax
cmp    $0x5,%rax
jae    123b <main+0xeb>
movslq -0xfdc(%rbp),%rax
movb   $0x0,-0xfc5(%rbp,%rax,1)
mov    -0xfdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfdc(%rbp)
jmp    1207 <main+0xb7>
cmpl   $0xffffffff,-0x14(%rbp)
jne    125d <main+0x10d>
lea    0xdb4(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1370 <main+0x220>
jmp    1262 <main+0x112>
mov    -0x14(%rbp),%edi
lea    -0xfc5(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0xfcc(%rbp)
cmpl   $0x0,-0xfcc(%rbp)
je     12ea <main+0x19a>
movl   $0x0,-0xfdc(%rbp)
mov    -0xfdc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12e5 <main+0x195>
movslq -0xfdc(%rbp),%rax
mov    -0xfc5(%rbp,%rax,1),%cl
movslq -0xfd4(%rbp),%rax
mov    %cl,-0xfc0(%rbp,%rax,1)
mov    -0xfd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfd4(%rbp)
mov    %eax,-0xfd4(%rbp)
mov    -0xfdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfdc(%rbp)
jmp    1291 <main+0x141>
jmp    12ea <main+0x19a>
mov    -0xfd8(%rbp),%eax
add    -0xfcc(%rbp),%eax
mov    %eax,-0xfd8(%rbp)
cmpl   $0x0,-0xfcc(%rbp)
jne    1262 <main+0x112>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
mov    0x2c9f(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xfc0(%rbp),%rsi
mov    -0xfd8(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xfd0(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xccf(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xfb0,%rsp
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rdi
mov    $0xfa0,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,0x8(%rsp)
movb   $0x0,0xc(%rsp)
cmp    $0xffffffff,%r15d
je     1272 <main+0x102>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
mov    $0xfa0,%edx
call   1070 <read@plt>
test   %eax,%eax
je     1225 <main+0xb5>
xor    %ebx,%ebx
lea    0x8(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %eax,%ebx
movslq %ebp,%rbp
lea    (%rsp,%rbp,1),%rdi
add    $0x10,%rdi
mov    $0xfa0,%edx
mov    %r12,%rsi
call   1080 <memcpy@plt>
add    $0xfa0,%rbp
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0xfa0,%edx
call   1070 <read@plt>
test   %eax,%eax
jne    11f0 <main+0x80>
mov    %r15d,%edi
call   1060 <close@plt>
mov    0x10(%r14),%rdi
mov    0x2dc0(%rip),%rax
mov    0x2d89(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %r14d,%r14d
mov    $0x1ff,%edx
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xd90(%rip),%rdi
jmp    127f <main+0x10f>
mov    $0xffffffff,%r14d
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [51 x i8] c"This is awkward, could not open file (it exists?)\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [6 x i8] c"DONE\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 [4000 x i8]
%9 = alloca [5 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 (i8*, i32, ...) @open(i8* %17, i32 %18)
store i32 %19, i32* %6
store i32 4000, i32* %7
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %14
br label %20
20: ; preds = %28, %2
%21 = load i32, i32* %14
%22 = sext i32 %21 to i64
%23 = icmp ult i64 %22, 4000
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i32, i32* %14
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4000 x i8], [4000 x i8]* %8, i64 0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %24
%29 = load i32, i32* %14
%30 = add nsw i32 %29, 1
store i32 %30, i32* %14
br label %20
31: ; preds = %20
store i32 0, i32* %14
br label %32
32: ; preds = %40, %31
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = icmp ult i64 %34, 5
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i32, i32* %14
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %36
%41 = load i32, i32* %14
%42 = add nsw i32 %41, 1
store i32 %42, i32* %14
br label %32
43: ; preds = %32
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %100
48: ; preds = %43
br label %49
49: ; preds = %79, %48
%50 = load i32, i32* %6
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%52 = load i32, i32* %7
%53 = call i32 @read(i32 %50, i8* %51, i32 %52)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %75
56: ; preds = %49
store i32 0, i32* %14
br label %57
57: ; preds = %71, %56
%58 = load i32, i32* %14
%59 = load i32, i32* %7
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %74
61: ; preds = %57
%62 = load i32, i32* %14
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [4000 x i8], [4000 x i8]* %8, i64 0, i64 %67
store i8 %65, i8* %68
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
store i32 %70, i32* %12
br label %71
71: ; preds = %61
%72 = load i32, i32* %14
%73 = add nsw i32 %72, 1
store i32 %73, i32* %14
br label %57
74: ; preds = %57
br label %75
75: ; preds = %74, %49
%76 = load i32, i32* %13
%77 = load i32, i32* %10
%78 = add nsw i32 %76, %77
store i32 %78, i32* %13
br label %79
79: ; preds = %75
%80 = load i32, i32* %10
%81 = icmp ne i32 %80, 0
br i1 %81, label %49, label %82
82: ; preds = %79
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 2
%87 = load i8*, i8** %86
%88 = load i32, i32* @O_CREAT
%89 = load i32, i32* @O_WRONLY
%90 = or i32 %88, %89
%91 = call i32 (i8*, i32, ...) @open(i8* %87, i32 %90, i32 511)
store i32 %91, i32* %6
%92 = load i32, i32* %6
%93 = getelementptr inbounds [4000 x i8], [4000 x i8]* %8, i64 0, i64 0
%94 = load i32, i32* %13
%95 = call i32 @write(i32 %92, i8* %93, i32 %94)
store i32 %95, i32* %11
%96 = load i32, i32* %6
%97 = call i32 @close(i32 %96)
%98 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %99
99: ; preds = %82
store i32 0, i32* %3
br label %100
100: ; preds = %99, %46
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@str = [5 x i8] c"DONE\00"
@str.2 = [50 x i8] c"This is awkward, could not open file (it exists?)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4000 x i8]
%4 = getelementptr inbounds [4000 x i8], [4000 x i8]* %3, i64 0, i64 0
%5 = alloca [5 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 (i8*, i32, ...) @open(i8* %8, i32 %9)
%11 = getelementptr inbounds [4000 x i8], [4000 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%13 = icmp eq i32 %10, -1
br i1 %13, label %39, label %14
14: ; preds = %2
%15 = call i32 @read(i32 %10, i8* %12, i32 4000)
%16 = icmp eq i32 %15, 0
br i1 %16, label %28, label %17
17: ; preds = %14, %17
%18 = phi i32 [ %26, %17 ], [ %15, %14 ]
%19 = phi i32 [ %25, %17 ], [ 0, %14 ]
%20 = phi i64 [ %24, %17 ], [ 0, %14 ]
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr [4000 x i8], [4000 x i8]* %3, i64 0, i64 %22
%24 = add nsw i64 %22, 4000
%25 = add nsw i32 %18, %19
%26 = call i32 @read(i32 %10, i8* %12, i32 4000)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %17
28: ; preds = %17, %14
%29 = phi i32 [ 0, %14 ], [ %25, %17 ]
%30 = tail call i32 @close(i32 %10)
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_CREAT
%34 = load i32, i32* @O_WRONLY
%35 = or i32 %34, %33
%36 = tail call i32 (i8*, i32, ...) @open(i8* %32, i32 %35, i32 511)
%37 = call i32 @write(i32 %36, i8* %11, i32 %29)
%38 = tail call i32 @close(i32 %36)
br label %39
39: ; preds = %2, %28
%40 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %28 ], [ getelementptr inbounds ([50 x i8], [50 x i8]* @str.2, i64 0, i64 0), %2 ]
%41 = phi i32 [ 0, %28 ], [ -1, %2 ]
%42 = tail call i32 @puts(i8* dereferenceable(1) %40)
ret i32 %41
}